UNPKG

@contractjs/aave-v3

Version:

A TypeScript utility library for Aave V3 contracts.

87 lines 3.15 kB
import { AbiFunction } from "ox"; import { normalizeChainToChainId } from "./utils"; import { POOL_ADDRESSES, PRICE_ORACLE_ADDRESSES, WRAPPED_TOKEN_GATEWAY_ADDRESSES } from "./constants/addresses"; export const supplyERC20Calldata = (asset, amount, onBehalfOf, referralCode) => { const supply = AbiFunction.from([ "function supply(address asset, uint256 amount, address onBehalfOf, uint16 referralCode)", ]); return AbiFunction.encodeData(supply, [ asset, amount, onBehalfOf, referralCode, ]); }; export const withdrawERC20Calldata = (asset, amount, to) => { const withdraw = AbiFunction.from([ "function withdraw(address asset, uint256 amount, address to)", ]); return AbiFunction.encodeData(withdraw, [ asset, amount, to, ]); }; export const supplyETHCalldata = (poolAddress, onBehalfOf, referralCode) => { const depositETH = AbiFunction.from([ "function depositETH(address pool, address onBehalfOf, uint16 referralCode)", ]); return AbiFunction.encodeData(depositETH, [ poolAddress, onBehalfOf, referralCode, ]); }; export const withdrawETHCalldata = (poolAddress, amount, to) => { const withdrawETH = AbiFunction.from([ "function withdrawETH(address pool, uint256 amount, address to)", ]); return AbiFunction.encodeData(withdrawETH, [ poolAddress, amount, to, ]); }; export const getReserveDataCalldata = (asset) => { const getReserveData = AbiFunction.from([ "function getReserveData(address asset)", ]); return AbiFunction.encodeData(getReserveData, [asset]); }; export const getAssetPriceCalldata = (asset) => { const getAssetPrice = AbiFunction.from([ "function getAssetPrice(address asset)", ]); return AbiFunction.encodeData(getAssetPrice, [asset]); }; /** * Retrieves the AAVE V3 Pool contract address for a given chain. * Throws an error if the chain is not supported. * @param chain - The chain identifier (e.g., 'base', 8453, or a viem Chain object). * @returns The AAVE V3 Pool contract address for the specified chain. */ export const poolAddressOn = (chain) => { let chainId = normalizeChainToChainId(chain); const address = POOL_ADDRESSES[chainId]; if (!address) { throw new Error(`[Pool Utility] Pool address not configured for chain: "${chain}".`); } return address; }; export const wrappedTokenGatewayAddressOn = (chain) => { let chainId = normalizeChainToChainId(chain); const address = WRAPPED_TOKEN_GATEWAY_ADDRESSES[chainId]; if (!address) { throw new Error(`[WrappedTokenGateway Utility] WrappedTokenGateway address not configured for chain: "${chain}".`); } return address; }; export const priceOracleAddressOn = (chain) => { let chainId = normalizeChainToChainId(chain); const address = PRICE_ORACLE_ADDRESSES[chainId]; if (!address) { throw new Error(`[PriceOracle Utility] PriceOracle address not configured for chain: "${chain}".`); } return address; }; //# sourceMappingURL=aaveV3Utils.js.map