LendingBaseAssertion
Inherits: Assertion
Title: LendingBaseAssertion
Author: Phylax Systems
Generic lending operation-safety assertion for lending protocols.
Inherit this together with a concrete ILendingProtectionSuite implementation. The base
contract handles one decode pass per triggered call, then enforces both:
- any bounded-consumption checks returned by the suite
- post-operation solvency for risk-increasing operations
Functions
_suite
Returns the protocol-specific lending suite that powers this assertion.
Concrete assertions typically inherit both this base contract and a suite contract, then
return ILendingProtectionSuite(address(this)). Returning a different contract is also
valid if the assertion delegates protocol logic elsewhere.
function _suite() internal view virtual returns (ILendingProtectionSuite);
Returns
| Name | Type | Description |
|---|---|---|
<none> | ILendingProtectionSuite | suite The suite used to decode operations and evaluate solvency. |
triggers
Registers one generic lending operation-safety check for every monitored selector.
This is the only trigger wiring most lending assertions need to implement. The suite
decides which selectors matter through getMonitoredSelectors(), and this base maps all
of them to assertOperationSafety().
function triggers() external view virtual override;
assertOperationSafety
Enforces the shared lending operation-safety invariants for a successful call.
Assertion authors should usually point Credible at this selector. The method resolves the triggering adopter frame, decodes the protocol operation once, enforces any bounded- consumption checks returned by the suite, and then enforces post-operation solvency when the suite marks the operation as risk-increasing.
function assertOperationSafety() external view;
assertPostOperationSolvency
Backwards-compatible alias for the legacy solvency-only entrypoint name.
Older bundles may still reference this selector directly. It now runs the full generic lending operation-safety pipeline rather than only the solvency portion.
function assertPostOperationSolvency() external view;
_assertOperationSafety
Internal implementation shared by the public lending assertion entrypoints.
Runs all shared lending checks exposed by the suite against the triggered adopter call.
function _assertOperationSafety() internal view;
_assertConsumptionChecks
Enforces the suite-provided bounded-consumption checks for the triggered operation.
Suites may return zero, one, or many bounds depending on the operation kind. Each bound
is enforced as consumed <= availableBefore, where both values must already be expressed
in the same protocol-defined units.
function _assertConsumptionChecks(
ILendingProtectionSuite suite,
ILendingProtectionSuite.TriggeredCall memory triggered,
ILendingProtectionSuite.OperationContext memory operation,
PhEvm.ForkId memory beforeFork,
PhEvm.ForkId memory afterFork
) internal view;
Parameters
| Name | Type | Description |
|---|---|---|
suite | ILendingProtectionSuite | The protocol-specific lending suite. |
triggered | ILendingProtectionSuite.TriggeredCall | The exact adopter frame that caused the assertion to run. |
operation | ILendingProtectionSuite.OperationContext | The decoded lending operation. |
beforeFork | PhEvm.ForkId | The pre-call snapshot fork. |
afterFork | PhEvm.ForkId | The post-call snapshot fork. |
_assertPostOperationSolvency
Enforces post-operation solvency for risk-increasing operations.
Operations that do not increase debt or reduce effective collateral are skipped. This is the original shared lending invariant, now run as one stage of the broader operation-safety pipeline.
function _assertPostOperationSolvency(
ILendingProtectionSuite suite,
ILendingProtectionSuite.TriggeredCall memory triggered,
ILendingProtectionSuite.OperationContext memory operation,
PhEvm.ForkId memory afterFork
) internal view;
Parameters
| Name | Type | Description |
|---|---|---|
suite | ILendingProtectionSuite | The protocol-specific lending suite. |
triggered | ILendingProtectionSuite.TriggeredCall | The exact adopter frame that caused the assertion to run. |
operation | ILendingProtectionSuite.OperationContext | The decoded lending operation. |
afterFork | PhEvm.ForkId | The post-call snapshot fork used for the solvency read. |
_resolveTriggeredCall
Resolves the exact adopter frame that caused the current assertion execution.
Credible exposes the selector and call identifiers in ph.context(), but the suite also
needs raw calldata and caller information for correct protocol decoding. This helper
reconstructs that frame from getAllCallInputs(...) and packages it into
ILendingProtectionSuite.TriggeredCall.
function _resolveTriggeredCall() internal view returns (ILendingProtectionSuite.TriggeredCall memory triggered);
Returns
| Name | Type | Description |
|---|---|---|
triggered | ILendingProtectionSuite.TriggeredCall | Caller-aware information about the adopter call being checked. |
Errors
LendingTriggeredCallNotFound
error LendingTriggeredCallNotFound(bytes4 selector, uint256 callStart);
LendingOperationAccountMissing
error LendingOperationAccountMissing(bytes4 selector);
LendingConsumptionCheckViolated
error LendingConsumptionCheckViolated(
address account,
bytes4 selector,
ILendingProtectionSuite.OperationKind kind,
bytes32 checkName,
address asset,
uint256 consumed,
uint256 availableBefore
);
LendingPostOperationSolvencyViolated
error LendingPostOperationSolvencyViolated(
address account,
bytes4 selector,
ILendingProtectionSuite.OperationKind kind,
bytes32 metricName,
int256 metric,
int256 threshold
);