Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

AaveV3LikeProtectionSuite

Git Source

Inherits: LendingProtectionSuiteBase

Title: AaveV3LikeProtectionSuite

Author: Phylax Systems

Shared ILendingProtectionSuite implementation for Aave v3-compatible lending forks.

This adapter matches the interface and accounting model used by forks such as the local Aave v3 Horizon deployment and SparkLend v1.

Constants

HEALTH_FACTOR_METRIC

bytes32 internal constant HEALTH_FACTOR_METRIC = 0x4845414c54485f464143544f5200000000000000000000000000000000000000

WITHDRAW_CLAIM_CHECK

bytes32 internal constant WITHDRAW_CLAIM_CHECK = "WITHDRAW_CLAIM"

LIQUIDATION_DEBT_CHECK

bytes32 internal constant LIQUIDATION_DEBT_CHECK = "LIQUIDATION_DEBT"

HEALTH_FACTOR_THRESHOLD

uint256 internal constant HEALTH_FACTOR_THRESHOLD = 1e18

HEALTH_FACTOR_THRESHOLD_INT

int256 internal constant HEALTH_FACTOR_THRESHOLD_INT = 1e18

POOL

address internal immutable POOL

ADDRESSES_PROVIDER

address internal immutable ADDRESSES_PROVIDER

Functions

constructor

Creates an Aave v3-like suite bound to a specific pool.

constructor(address pool_, address addressesProvider_) ;

Parameters

NameTypeDescription
pool_addressPool address whose accounting and selectors this suite targets.
addressesProvider_addressThe pool’s ADDRESSES_PROVIDER. Passed in explicitly because assertions are deployed against an empty state where calling the pool would fail.

getMonitoredSelectors

Returns the Aave v3-like pool selectors relevant to the shared lending invariants.

function getMonitoredSelectors() external pure virtual override returns (bytes4[] memory selectors);

decodeOperation

Decodes an Aave v3-like pool call into the shared lending operation model.

function decodeOperation(TriggeredCall calldata triggered)
    external
    view
    virtual
    override
    returns (OperationContext memory operation);

shouldCheckPostOperationSolvency

Filters decoded Aave v3-like operations down to the ones that must preserve solvency.

function shouldCheckPostOperationSolvency(OperationContext calldata operation)
    external
    pure
    override
    returns (bool shouldCheck);

getConsumptionChecks

Returns the bounded-consumption checks implied by the decoded Aave v3-like operation.

function getConsumptionChecks(
    TriggeredCall calldata triggered,
    OperationContext calldata operation,
    PhEvm.ForkId calldata beforeFork,
    PhEvm.ForkId calldata afterFork
) external view override returns (ConsumptionCheck[] memory checks);

getAccountSnapshot

Reads the post-call snapshot needed by the health-factor solvency invariant.

function getAccountSnapshot(address account, PhEvm.ForkId calldata fork)
    external
    view
    virtual
    override
    returns (AccountSnapshot memory snapshot);

getAccountState

Reads aggregate account metrics from Pool.getUserAccountData(...).

function getAccountState(address account, PhEvm.ForkId calldata fork)
    external
    view
    override
    returns (AccountState memory state);

getAccountBalances

Enumerates reserve balances for the account.

function getAccountBalances(address account, PhEvm.ForkId calldata fork)
    external
    view
    override
    returns (AccountBalance[] memory balances);

evaluateSolvency

Evaluates solvency from aggregate account state.

function evaluateSolvency(
    AccountState calldata state,
    AccountBalance[] calldata balances,
    PhEvm.ForkId calldata fork
) external pure override returns (SolvencyState memory solvency);

_getAccountState

Internal helper that reads and normalizes aggregate account data.

function _getAccountState(address account, PhEvm.ForkId memory fork)
    internal
    view
    returns (AccountState memory state);

_getAccountBalances

Internal helper that expands the account into reserve-level balances and values.

function _getAccountBalances(address account, PhEvm.ForkId memory fork)
    internal
    view
    returns (AccountBalance[] memory balances);

_getWithdrawClaimCheck

Builds the withdraw bounded-consumption check from call output and pre-state.

function _getWithdrawClaimCheck(
    TriggeredCall calldata triggered,
    OperationContext calldata operation,
    PhEvm.ForkId calldata beforeFork
) internal view returns (ConsumptionCheck memory check);

_getLiquidationDebtCheck

Builds the liquidation debt-consumption check from actual debt-asset transfers.

function _getLiquidationDebtCheck(
    OperationContext calldata operation,
    PhEvm.ForkId calldata beforeFork,
    PhEvm.ForkId calldata afterFork
) internal view returns (ConsumptionCheck memory check);

_evaluateHealthFactor

Converts aggregate metrics into the common solvency representation.

function _evaluateHealthFactor(AccountState memory state) internal pure returns (SolvencyState memory solvency);

_buildAccountBalance

Builds a single reserve-level balance entry for the account.

function _buildAccountBalance(
    address asset,
    address account,
    uint256 userConfigData,
    address oracle,
    PhEvm.ForkId memory fork
) internal view returns (bool include, AccountBalance memory balance);

_getReserveData

Reads reserve metadata for a single asset at the requested snapshot fork.

function _getReserveData(address asset, PhEvm.ForkId memory fork)
    internal
    view
    returns (AaveV3LikeTypes.ReserveData memory reserveData);

_getUserReserveDebt

Reads the user’s total debt for one reserve from the debt-token balances.

function _getUserReserveDebt(address asset, address account, PhEvm.ForkId memory fork)
    internal
    view
    returns (uint256 debtBalance);

_readOptionalBalance

Reads a token balance when the token address may be unset.

function _readOptionalBalance(address token, address account, PhEvm.ForkId memory fork)
    internal
    view
    returns (uint256 balance);

_valueInBase

Converts an asset-denominated balance into the pool base currency.

function _valueInBase(address oracle, address asset, uint256 balance, PhEvm.ForkId memory fork)
    internal
    view
    returns (uint256);

_isUsingAsCollateral

Returns whether the reserve is enabled as collateral in the user config bitset.

function _isUsingAsCollateral(uint256 userConfigData, uint256 reserveId) internal pure returns (bool);

_toInt256

Safely casts a uint256 metric to int256 for SolvencyState.

function _toInt256(uint256 value) internal pure returns (int256);

Structs

AaveAccountMetrics

Extra aggregate Aave v3-like metrics kept in AccountState.metadata.

struct AaveAccountMetrics {
    uint256 availableBorrowsBase;
    uint256 currentLiquidationThreshold;
    uint256 ltv;
    uint256 healthFactor;
}