Aave V3 on Arbitrum
TheAaveV3Adapter integrates with the Aave V3 lending pool on Arbitrum One, providing four core operations:
Supply
Deposit assets to earn variable yield. You receive aTokens that represent your position and accrue interest continuously.
Borrow
Borrow assets against your supplied collateral at variable interest rates. Requires sufficient health factor.
Repay
Repay outstanding borrows partially or in full. Pass the maximum uint256 value to repay the entire debt.
Withdraw
Withdraw supplied collateral by burning aTokens. Pass the maximum uint256 value to withdraw everything.
How It Works
Supplying Assets
When you supply an asset to Aave V3:- The agent approves the Aave V3 Pool to pull your tokens
- Calls
pool.supply(asset, amount, onBehalfOf, referralCode) - You receive an equivalent amount of aTokens (e.g., supply USDC and get aUSDC)
- Your aToken balance increases over time as interest accrues
aTokens are rebasing — their balance grows in your wallet automatically. There is no need to claim or harvest yield.
Borrowing Assets
To borrow, you must first supply collateral. The amount you can borrow depends on the loan-to-value (LTV) ratio of your collateral asset.- The agent calls
pool.borrow(asset, amount, interestRateMode, referralCode, onBehalfOf) - Borrowed tokens are transferred to your wallet
- Your debt accrues interest at the variable rate
Repaying Debt
Repaying works in two modes:- Partial repay: specify the exact amount to repay
- Full repay: the agent passes
type(uint256).maxto clear the entire debt including accrued interest
Withdrawing Collateral
Withdrawal burns your aTokens and returns the underlying asset. Withdrawing collateral reduces your health factor, so the agent checks that the withdrawal will not put your position at liquidation risk.Health Factor
The health factor is the single most important metric for lending positions. It represents how safe your position is from liquidation.| Health Factor | Status |
|---|---|
| > 2.0 | Safe — comfortable margin |
| 1.5 - 2.0 | Moderate — consider adding collateral |
| 1.0 - 1.5 | At risk — close to liquidation |
| < 1.0 | Liquidatable — anyone can liquidate |
pool.getUserAccountData(address), which returns:
| Field | Description |
|---|---|
totalCollateralBase | Total collateral value in USD (8 decimals) |
totalDebtBase | Total debt value in USD (8 decimals) |
availableBorrowsBase | Remaining borrowing capacity |
currentLiquidationThreshold | Weighted liquidation threshold |
ltv | Current loan-to-value ratio |
healthFactor | Position health (18 decimals, > 1e18 = safe) |
Liquidation Monitor Contract
For proactive health monitoring at scale, the platform includes a LiquidationMonitor Stylus contract written in Rust. This contract runs on-chain with 10-100x gas savings compared to equivalent Solidity.Dynamic Protocol Registry
The LiquidationMonitor maintains a registry of lending and perp protocols using indexed mappings:- Lending protocols: Aave V3 pools (extensible to Radiant, Compound V3)
- Perp protocols: GMX V2 readers (future)
- Soft-delete pattern: protocols can be deactivated without reindexing
How Scanning Works
- The contract stores a list of tracked account addresses
- A configurable
risk_thresholddefines the health factor warning level - When
scanAccounts()is called, it iterates through tracked accounts and checks each against all registered lending protocols - Accounts below the risk threshold emit an
AccountAtRiskevent with the health factor and timestamp
Events
The contract emits events that the off-chain agent can monitor:| Event | Description |
|---|---|
AccountAtRisk | Fired when a tracked account’s health factor drops below threshold |
AccountAdded | New account added to the monitoring list |
AccountRemoved | Account removed from monitoring |
ThresholdUpdated | Risk threshold changed by the owner |
LendingProtocolAdded | New lending protocol registered |
LendingProtocolRemoved | Lending protocol deactivated |
The LiquidationMonitor is a Stylus contract that compiles to WASM and runs on the Arbitrum Stylus VM. It is not yet deployed to mainnet — see the deployment guide for instructions.
Contract Addresses
| Contract | Address |
|---|---|
| Aave V3 Pool | 0x794a61358D6845594F94dc1DB02A252b5b4814aD |
| Aave V3 Data Provider | 0x69FA688f1Dc47d4B5d8029D5a35FB7a548310654 |
| Aave V3 Oracle | 0xb56c2F0B653B2e0b10C9b928C8580Ac5Df02C7C7 |
Example Prompts
SDK Reference
The lending adapter is in the@arb-agent/adapters package as AaveV3Adapter.
supply(params)
Supplies an asset to earn yield. Accepts SupplyParams:
| Field | Type | Required | Description |
|---|---|---|---|
asset | Address | Yes | Token address to supply |
amount | bigint | Yes | Amount in token decimals |
onBehalfOf | Address | No | Recipient of aTokens (default: sender) |
borrow(params)
Borrows an asset at variable rate. Accepts BorrowParams:
| Field | Type | Required | Description |
|---|---|---|---|
asset | Address | Yes | Token address to borrow |
amount | bigint | Yes | Amount in token decimals |
interestRateMode | number | No | 2 = variable (default) |
onBehalfOf | Address | No | Account to borrow on behalf of |
repay(asset, amount)
Repays a borrow position. Pass 2n ** 256n - 1n to repay the full debt.
withdraw(asset, amount)
Withdraws supplied collateral. Pass 2n ** 256n - 1n to withdraw everything.