Configuration
ReserveConfig
Each token reserve is configured with risk parameters:Initialization
Available Actions
deposit
deposit
Description: Deposit assets to earn interest and use as collateral.Parameters:Effects:
token(u32): Token ID to depositamount(u128): Amount in token units (e18)
- Deducts
amountfrom wallet - Mints scaled deposit shares (scaled by liquidity index)
- Increases collateral available for borrowing
borrow
borrow
Description: Borrow assets against deposited collateral.Parameters:Checks:
token(u32): Token ID to borrowamount(u128): Amount to borrow
- New total debt must not exceed LTV-adjusted collateral value:
- Credits
amountto wallet - Increases scaled debt (scaled by variable borrow index)
repay
repay
Description: Repay borrowed assets.Parameters:Effects:
token(u32): Token ID to repayamount(u128): Amount to repay (capped to current debt)
- Deducts repayment from wallet
- Reduces scaled debt
withdraw
withdraw
Description: Withdraw deposited assets (with HF check).Parameters:Checks:
token(u32): Token ID to withdrawamount(u128): Amount to withdraw
- Post-withdrawal health factor must remain >= 1.0:
- Credits
amountto wallet - Reduces scaled deposits
set_price
set_price
Description: Update oracle price for a reserve (admin/oracle action).Parameters:Effects:
token(u32): Token IDprice_e18(u128): New price in e18 format
- Updates reserve price immediately
- Used by strategies to sync Lido wstETH price from exchange rate
liquidate
liquidate
Description: Liquidate an undercollateralized position.Parameters:Mechanics:
target_user(u32): User ID to liquidatedebt_token(u32): Token ID of debt to repaycollateral_token(u32): Token ID of collateral to seizerepay_units(u128): Desired repay amount
- Check target HF < 1.0
- Cap repay to
liq_close_factor_bpsof target’s debt - Seize collateral =
repay_value * (1 + liq_bonus_bps) / collateral_price - Protocol fee taken from seized collateral → treasury
- Liquidator receives remaining seized collateral
- Deduct
repay_unitsof debt token - Credit seized collateral (minus protocol fee)
Interest Accrual
On each tick, reserves accrue interest:scaled_debt * variable_borrow_index_ray
User deposits = scaled_deposits * liquidity_index_ray
Health Factor
Health factor determines liquidation eligibility:- HF >= 10,000 (100%): Healthy position
- HF < 10,000: Eligible for liquidation
Auto-Liquidation
Aave V3 has an optional auto-liquidation pass that runs afteron_tick():
- Scans all users
- If HF < 1.0, picks largest debt and largest collateral
- Liquidates up to
liq_close_factor_bps
Usage Examples
Deposit and Borrow
Withdraw with HF Check
Sync Lido wstETH Price
View Methods
view_user
Returns user position:view_market
Returns reserve configs and totals:Protocol-Specific Behavior
Scaled Balances
Internal accounting uses scaled balances to track shares:Liquidation Math
Close Factor
Limits single liquidation to X% of debt (e.g., 50%) to prevent full wipeout on small price moves.Limitations
See Also
- Lido Protocol - wstETH integration
- Protocol Overview - Registry setup
- Source:
source/protocols/aave-v3/src/lib.rs