Skill — Copyable reference implementation. Use as-is or customize. See Skills Philosophy.
Planned Implementation
Supply & Borrow
Flash Loans
User Position
Resources
Related
- ethers-provider — RPC connection
- multicall — Batch reserve queries
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Lending, borrowing, and flash loans with Aave V3
import { AaveV3 } from './AaveV3.js';
const aave = AaveV3({
provider,
pool: AAVE_POOL_ADDRESS,
});
// Supply collateral
await aave.supply({
asset: USDC,
amount: parseUnits('1000', 6),
onBehalfOf: userAddress,
signer,
});
// Borrow
await aave.borrow({
asset: WETH,
amount: parseEther('0.5'),
interestRateMode: 2, // Variable
onBehalfOf: userAddress,
signer,
});
// Execute flash loan
await aave.flashLoan({
receiverAddress: MY_CONTRACT,
assets: [USDC, DAI],
amounts: [parseUnits('100000', 6), parseUnits('100000', 18)],
modes: [0, 0], // 0 = no debt, 1 = stable, 2 = variable
params: encodedCalldata,
signer,
});
// Get user account data
const position = await aave.getUserAccountData(userAddress);
console.log('Total collateral:', position.totalCollateralBase);
console.log('Total debt:', position.totalDebtBase);
console.log('Health factor:', position.healthFactor);
Was this page helpful?
