AaveClient
The AaveClient provides direct access to Aave V3 on Base. It handles supply, borrowing, repayment, position tracking, and yield monitoring — all through the AgentAccount smart wallet.
AaveClient uses AgentAccount.executeBatch() for atomic multi-step operations. If any step fails, the entire transaction reverts.
Constructor
import { AaveClient } from '@agether/sdk';
const aave = new AaveClient({
privateKey: process.env.AGENT_PRIVATE_KEY!,
rpcUrl: 'https://base-rpc.publicnode.com',
agentId: '42',
chainId: 8453,
});
Configuration
| Parameter | Type | Required | Description |
|---|
privateKey | string | Yes | Agent wallet private key |
rpcUrl | string | Yes | Base RPC endpoint |
agentId | string | No | ERC-8004 agent ID |
chainId | number | No | Chain ID (default: 8453) |
Key Contracts
| Contract | Address (Base) |
|---|
| Aave Pool | 0xA238Dd80C259a72e81d7e4664a9801593F98d1c5 |
| USDC | 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 |
| WETH | 0x4200000000000000000000000000000000000006 |
Supply Operations
supply(token, amount)
Supply tokens into Aave V3 to earn yield and/or use as collateral.
await aave.supply('USDC', '100'); // Supply $100 USDC
await aave.supply('WETH', '0.1'); // Supply 0.1 WETH
withdraw(token, amount)
Withdraw supplied tokens. Use "all" for full withdrawal.
await aave.withdraw('USDC', '50'); // Withdraw $50
await aave.withdraw('USDC', 'all'); // Withdraw everything
Withdrawing collateral reduces your Health Factor. If it drops below 1.0, your position can be liquidated.
Borrowing Operations
borrow(token, amount)
Borrow tokens against supplied collateral.
await aave.borrow('USDC', '50'); // Borrow $50 USDC
await aave.borrow('WETH', '0.01'); // Borrow 0.01 WETH
repay(token, amount)
Repay borrowed tokens. Use "all" for full repayment.
await aave.repay('USDC', '25'); // Repay $25
await aave.repay('USDC', 'all'); // Repay all USDC debt
Position Management
getAccountData()
Returns the complete Aave account overview.
const data = await aave.getAccountData();
console.log('Total collateral:', data.totalCollateralUsd);
console.log('Total debt:', data.totalDebtUsd);
console.log('Health factor:', data.healthFactor);
console.log('LTV:', data.currentLtv);
console.log('Liquidation threshold:', data.liquidationThreshold);
Returns:
totalCollateralUsd — total supplied value in USD
totalDebtUsd — total borrowed value in USD
healthFactor — global health factor (> 1.0 = safe)
currentLtv — current loan-to-value ratio
liquidationThreshold — liquidation threshold percentage
positions[] — per-asset supply and borrow details
getReserves()
List all available Aave V3 reserves with rates and configuration.
const reserves = await aave.getReserves();
for (const r of reserves) {
console.log(`${r.symbol}: supply ${r.supplyApy}% | borrow ${r.borrowApy}%`);
}
setCollateral(token, enabled)
Enable or disable a supplied asset as collateral.
await aave.setCollateral('WETH', true); // Enable as collateral
await aave.setCollateral('USDC', false); // Disable as collateral
Yield Tracking
getYieldStatus()
Track earned yield by scanning on-chain events via Blockscout. No database needed.
const yields = await aave.getYieldStatus();
for (const y of yields) {
console.log(`${y.token}: supplied ${y.netDeposited}, current ${y.currentBalance}`);
console.log(` Earned yield: $${y.earnedYield}`);
}
How it works:
- Scans aToken mint/burn events from Blockscout
- Calculates
netDeposited (deposits minus withdrawals)
- Compares with
currentBalance (on-chain aToken balance)
- Difference = earned yield
Supported Assets (Base)
| Token | Supply | Borrow | As Collateral |
|---|
| USDC | ✅ | ✅ | ✅ |
| WETH | ✅ | ✅ | ✅ |
| cbETH | ✅ | ✅ | ✅ |
| wstETH | ✅ | ❌ | ✅ |
| cbBTC | ✅ | ✅ | ✅ |
| EURC | ✅ | ✅ | ✅ |
Complete Example
import { AaveClient } from '@agether/sdk';
async function main() {
const aave = new AaveClient({
privateKey: process.env.AGENT_PRIVATE_KEY!,
rpcUrl: 'https://base-rpc.publicnode.com',
agentId: '29151',
});
// Supply USDC to earn yield
await aave.supply('USDC', '100');
// Borrow WETH against USDC collateral
await aave.borrow('WETH', '0.01');
// Check position
const data = await aave.getAccountData();
console.log('Health Factor:', data.healthFactor);
// Track earned yield
const yields = await aave.getYieldStatus();
console.log('Earned:', yields[0].earnedYield);
// Repay and withdraw
await aave.repay('WETH', 'all');
await aave.withdraw('USDC', 'all');
}