97 lines
3.3 KiB
TypeScript
97 lines
3.3 KiB
TypeScript
/**
|
|
* Aave v3: Pool discovery using PoolAddressesProvider
|
|
*
|
|
* This example demonstrates how to discover the Aave Pool address
|
|
* using the PoolAddressesProvider service discovery pattern.
|
|
* This is the recommended way to get the Pool address in production.
|
|
*/
|
|
|
|
import { createRpcClient } from '../../src/utils/chain-config.js';
|
|
import { getAavePoolAddressesProvider } from '../../src/utils/addresses.js';
|
|
|
|
const CHAIN_ID = 1; // Mainnet
|
|
|
|
// PoolAddressesProvider ABI
|
|
const ADDRESSES_PROVIDER_ABI = [
|
|
{
|
|
name: 'getPool',
|
|
type: 'function',
|
|
stateMutability: 'view',
|
|
inputs: [],
|
|
outputs: [{ name: '', type: 'address' }],
|
|
},
|
|
{
|
|
name: 'getPoolDataProvider',
|
|
type: 'function',
|
|
stateMutability: 'view',
|
|
inputs: [],
|
|
outputs: [{ name: '', type: 'address' }],
|
|
},
|
|
{
|
|
name: 'getPriceOracle',
|
|
type: 'function',
|
|
stateMutability: 'view',
|
|
inputs: [],
|
|
outputs: [{ name: '', type: 'address' }],
|
|
},
|
|
] as const;
|
|
|
|
async function discoverPool() {
|
|
const publicClient = createRpcClient(CHAIN_ID);
|
|
const addressesProvider = getAavePoolAddressesProvider(CHAIN_ID);
|
|
|
|
console.log('Discovering Aave v3 Pool addresses...');
|
|
console.log(`Chain ID: ${CHAIN_ID}`);
|
|
console.log(`PoolAddressesProvider: ${addressesProvider}\n`);
|
|
|
|
// Get Pool address
|
|
const poolAddress = await publicClient.readContract({
|
|
address: addressesProvider,
|
|
abi: ADDRESSES_PROVIDER_ABI,
|
|
functionName: 'getPool',
|
|
});
|
|
|
|
console.log(`✅ Pool: ${poolAddress}`);
|
|
|
|
// Get PoolDataProvider address (for querying reserves, user data, etc.)
|
|
try {
|
|
const dataProviderAddress = await publicClient.readContract({
|
|
address: addressesProvider,
|
|
abi: ADDRESSES_PROVIDER_ABI,
|
|
functionName: 'getPoolDataProvider',
|
|
});
|
|
console.log(`✅ PoolDataProvider: ${dataProviderAddress}`);
|
|
} catch (error) {
|
|
console.log('⚠️ PoolDataProvider not available (may be using different method)');
|
|
}
|
|
|
|
// Get PriceOracle address
|
|
try {
|
|
const priceOracleAddress = await publicClient.readContract({
|
|
address: addressesProvider,
|
|
abi: ADDRESSES_PROVIDER_ABI,
|
|
functionName: 'getPriceOracle',
|
|
});
|
|
console.log(`✅ PriceOracle: ${priceOracleAddress}`);
|
|
} catch (error) {
|
|
console.log('⚠️ PriceOracle not available (may be using different method)');
|
|
}
|
|
|
|
console.log('\n✅ Pool discovery completed!');
|
|
console.log('\nUse the Pool address for all Aave v3 operations:');
|
|
console.log(` - supply(address asset, uint256 amount, address onBehalfOf, uint16 referralCode)`);
|
|
console.log(` - withdraw(address asset, uint256 amount, address to)`);
|
|
console.log(` - borrow(address asset, uint256 amount, uint256 interestRateMode, uint16 referralCode, address onBehalfOf)`);
|
|
console.log(` - repay(address asset, uint256 amount, uint256 rateMode, address onBehalfOf)`);
|
|
console.log(` - flashLoanSimple(address receiverAddress, address asset, uint256 amount, bytes params, uint16 referralCode)`);
|
|
console.log(` - flashLoan(address receiverAddress, address[] assets, uint256[] amounts, uint256[] modes, address onBehalfOf, bytes params, uint16 referralCode)`);
|
|
}
|
|
|
|
// Run if executed directly
|
|
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
discoverPool().catch(console.error);
|
|
}
|
|
|
|
export { discoverPool };
|
|
|