diff --git a/src/factory/providers/arbitrum/aavev3/abi/aaveErc20Abi.json b/src/constants/abi/aaveErc20Abi.json similarity index 100% rename from src/factory/providers/arbitrum/aavev3/abi/aaveErc20Abi.json rename to src/constants/abi/aaveErc20Abi.json diff --git a/src/factory/providers/arbitrum/aavev3/abi/poolDataProviderV3Abi.json b/src/constants/abi/poolDataProviderV3Abi.json similarity index 100% rename from src/factory/providers/arbitrum/aavev3/abi/poolDataProviderV3Abi.json rename to src/constants/abi/poolDataProviderV3Abi.json diff --git a/src/factory/providers/arbitrum/aavev3/index.ts b/src/factory/providers/arbitrum/aavev3/index.ts index 6fd34870..21a8057f 100644 --- a/src/factory/providers/arbitrum/aavev3/index.ts +++ b/src/factory/providers/arbitrum/aavev3/index.ts @@ -1,75 +1,23 @@ -import util from '../../../../util/blockchainUtil'; import formatter from '../../../../util/formatter'; -import POOL_DATA_PROVIDER_V3_ABI from './abi/poolDataProviderV3Abi.json'; -import AAVE_ERC20_ABI from './abi/aaveErc20Abi.json'; import { ITvlParams, ITvlReturn } from '../../../../interfaces/ITvl'; +import aaveV3 from '../../../../util/calculators/aaveV3'; const START_BLOCK = 11700000; const POOL_DATA_PROVIDER_V3 = '0x69fa688f1dc47d4b5d8029d5a35fb7a548310654'; -async function getAddresses(poolDataProviderV3, block, chain, web3) { - const aaveTokenMarketData = await util.executeCall( - poolDataProviderV3, - POOL_DATA_PROVIDER_V3_ABI, - 'getAllATokens', - [], - block, - chain, - web3, - ); - - const aaveTokenAddresses = []; - aaveTokenMarketData.map((aaveTokensData) => { - if (aaveTokensData) { - aaveTokenAddresses.push( - typeof aaveTokensData == 'string' - ? aaveTokensData.substring(aaveTokensData.indexOf(',') + 1) - : aaveTokensData.tokenAddress, - ); - } - }); - - const underlyingAddressesData = await util.executeCallOfMultiTargets( - aaveTokenAddresses, - AAVE_ERC20_ABI, - 'UNDERLYING_ASSET_ADDRESS', - [], - block, - chain, - web3, - ); - - const reserveTokenAddresses = underlyingAddressesData.map( - (reserveData) => reserveData, - ); - - return [aaveTokenAddresses, reserveTokenAddresses]; -} - async function tvl(params: ITvlParams): Promise> { const { block, chain, provider, web3 } = params; if (block < START_BLOCK) { return {}; } - const balances = {}; - - const [aaveTokens, reserveTokens] = await getAddresses( + const balances = await aaveV3.getTvl( POOL_DATA_PROVIDER_V3, block, chain, web3, ); - const balanceResults = await util.getTokenBalancesOfHolders( - aaveTokens, - reserveTokens, - block, - chain, - web3, - ); - - formatter.sumMultiBalanceOf(balances, balanceResults); formatter.convertBalancesToFixed(balances); return { balances }; } diff --git a/src/factory/providers/ethereum/aavev3/index.ts b/src/factory/providers/ethereum/aavev3/index.ts new file mode 100644 index 00000000..c4b377c4 --- /dev/null +++ b/src/factory/providers/ethereum/aavev3/index.ts @@ -0,0 +1,24 @@ +import formatter from '../../../../util/formatter'; +import { ITvlParams, ITvlReturn } from '../../../../interfaces/ITvl'; +import aaveV3 from '../../../../util/calculators/aaveV3'; + +const START_BLOCK = 16291078; +const POOL_DATA_PROVIDER_V3 = '0x7B4EB56E7CD4b454BA8ff71E4518426369a138a3'; + +async function tvl(params: ITvlParams): Promise> { + const { block, chain, provider, web3 } = params; + if (block < START_BLOCK) { + return {}; + } + + const balances = await aaveV3.getTvl( + POOL_DATA_PROVIDER_V3, + block, + chain, + web3, + ); + + formatter.convertBalancesToFixed(balances); + return { balances }; +} +export { tvl }; diff --git a/src/factory/providers/optimism/aavev3/abi/aaveErc20Abi.json b/src/factory/providers/optimism/aavev3/abi/aaveErc20Abi.json deleted file mode 100644 index c318f72d..00000000 --- a/src/factory/providers/optimism/aavev3/abi/aaveErc20Abi.json +++ /dev/null @@ -1,907 +0,0 @@ -[ - { - "inputs": [ - { - "internalType": "contract IPool", - "name": "pool", - "type": "address" - } - ], - "stateMutability": "nonpayable", - "type": "constructor" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "owner", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "spender", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "value", - "type": "uint256" - } - ], - "name": "Approval", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "from", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "value", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "index", - "type": "uint256" - } - ], - "name": "BalanceTransfer", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "from", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "target", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "value", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "balanceIncrease", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "index", - "type": "uint256" - } - ], - "name": "Burn", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "underlyingAsset", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "pool", - "type": "address" - }, - { - "indexed": false, - "internalType": "address", - "name": "treasury", - "type": "address" - }, - { - "indexed": false, - "internalType": "address", - "name": "incentivesController", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint8", - "name": "aTokenDecimals", - "type": "uint8" - }, - { - "indexed": false, - "internalType": "string", - "name": "aTokenName", - "type": "string" - }, - { - "indexed": false, - "internalType": "string", - "name": "aTokenSymbol", - "type": "string" - }, - { - "indexed": false, - "internalType": "bytes", - "name": "params", - "type": "bytes" - } - ], - "name": "Initialized", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "caller", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "onBehalfOf", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "value", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "balanceIncrease", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "index", - "type": "uint256" - } - ], - "name": "Mint", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "from", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "value", - "type": "uint256" - } - ], - "name": "Transfer", - "type": "event" - }, - { - "inputs": [], - "name": "ATOKEN_REVISION", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "DOMAIN_SEPARATOR", - "outputs": [ - { - "internalType": "bytes32", - "name": "", - "type": "bytes32" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "EIP712_REVISION", - "outputs": [ - { - "internalType": "bytes", - "name": "", - "type": "bytes" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "PERMIT_TYPEHASH", - "outputs": [ - { - "internalType": "bytes32", - "name": "", - "type": "bytes32" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "POOL", - "outputs": [ - { - "internalType": "contract IPool", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "RESERVE_TREASURY_ADDRESS", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "UNDERLYING_ASSET_ADDRESS", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "owner", - "type": "address" - }, - { - "internalType": "address", - "name": "spender", - "type": "address" - } - ], - "name": "allowance", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "spender", - "type": "address" - }, - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - } - ], - "name": "approve", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "user", - "type": "address" - } - ], - "name": "balanceOf", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "from", - "type": "address" - }, - { - "internalType": "address", - "name": "receiverOfUnderlying", - "type": "address" - }, - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "index", - "type": "uint256" - } - ], - "name": "burn", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "decimals", - "outputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "spender", - "type": "address" - }, - { - "internalType": "uint256", - "name": "subtractedValue", - "type": "uint256" - } - ], - "name": "decreaseAllowance", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "getIncentivesController", - "outputs": [ - { - "internalType": "contract IAaveIncentivesController", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "user", - "type": "address" - } - ], - "name": "getPreviousIndex", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "user", - "type": "address" - } - ], - "name": "getScaledUserBalanceAndSupply", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "user", - "type": "address" - }, - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - } - ], - "name": "handleRepayment", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "spender", - "type": "address" - }, - { - "internalType": "uint256", - "name": "addedValue", - "type": "uint256" - } - ], - "name": "increaseAllowance", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "contract IPool", - "name": "initializingPool", - "type": "address" - }, - { - "internalType": "address", - "name": "treasury", - "type": "address" - }, - { - "internalType": "address", - "name": "underlyingAsset", - "type": "address" - }, - { - "internalType": "contract IAaveIncentivesController", - "name": "incentivesController", - "type": "address" - }, - { - "internalType": "uint8", - "name": "aTokenDecimals", - "type": "uint8" - }, - { - "internalType": "string", - "name": "aTokenName", - "type": "string" - }, - { - "internalType": "string", - "name": "aTokenSymbol", - "type": "string" - }, - { - "internalType": "bytes", - "name": "params", - "type": "bytes" - } - ], - "name": "initialize", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "caller", - "type": "address" - }, - { - "internalType": "address", - "name": "onBehalfOf", - "type": "address" - }, - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "index", - "type": "uint256" - } - ], - "name": "mint", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "index", - "type": "uint256" - } - ], - "name": "mintToTreasury", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "name", - "outputs": [ - { - "internalType": "string", - "name": "", - "type": "string" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "owner", - "type": "address" - } - ], - "name": "nonces", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "owner", - "type": "address" - }, - { - "internalType": "address", - "name": "spender", - "type": "address" - }, - { - "internalType": "uint256", - "name": "value", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "deadline", - "type": "uint256" - }, - { - "internalType": "uint8", - "name": "v", - "type": "uint8" - }, - { - "internalType": "bytes32", - "name": "r", - "type": "bytes32" - }, - { - "internalType": "bytes32", - "name": "s", - "type": "bytes32" - } - ], - "name": "permit", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "token", - "type": "address" - }, - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - } - ], - "name": "rescueTokens", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "user", - "type": "address" - } - ], - "name": "scaledBalanceOf", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "scaledTotalSupply", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "contract IAaveIncentivesController", - "name": "controller", - "type": "address" - } - ], - "name": "setIncentivesController", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "symbol", - "outputs": [ - { - "internalType": "string", - "name": "", - "type": "string" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "totalSupply", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "recipient", - "type": "address" - }, - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - } - ], - "name": "transfer", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "sender", - "type": "address" - }, - { - "internalType": "address", - "name": "recipient", - "type": "address" - }, - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - } - ], - "name": "transferFrom", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "from", - "type": "address" - }, - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "value", - "type": "uint256" - } - ], - "name": "transferOnLiquidation", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "target", - "type": "address" - }, - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - } - ], - "name": "transferUnderlyingTo", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - } -] \ No newline at end of file diff --git a/src/factory/providers/optimism/aavev3/abi/poolDataProviderV3Abi.json b/src/factory/providers/optimism/aavev3/abi/poolDataProviderV3Abi.json deleted file mode 100644 index e06f8e48..00000000 --- a/src/factory/providers/optimism/aavev3/abi/poolDataProviderV3Abi.json +++ /dev/null @@ -1,515 +0,0 @@ -[ - { - "inputs": [ - { - "internalType": "contract IPoolAddressesProvider", - "name": "addressesProvider", - "type": "address" - } - ], - "stateMutability": "nonpayable", - "type": "constructor" - }, - { - "inputs": [], - "name": "ADDRESSES_PROVIDER", - "outputs": [ - { - "internalType": "contract IPoolAddressesProvider", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "asset", - "type": "address" - } - ], - "name": "getATokenTotalSupply", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "getAllATokens", - "outputs": [ - { - "components": [ - { - "internalType": "string", - "name": "symbol", - "type": "string" - }, - { - "internalType": "address", - "name": "tokenAddress", - "type": "address" - } - ], - "internalType": "struct AaveProtocolDataProvider.TokenData[]", - "name": "", - "type": "tuple[]" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "getAllReservesTokens", - "outputs": [ - { - "components": [ - { - "internalType": "string", - "name": "symbol", - "type": "string" - }, - { - "internalType": "address", - "name": "tokenAddress", - "type": "address" - } - ], - "internalType": "struct AaveProtocolDataProvider.TokenData[]", - "name": "", - "type": "tuple[]" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "asset", - "type": "address" - } - ], - "name": "getDebtCeiling", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "getDebtCeilingDecimals", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "pure", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "asset", - "type": "address" - } - ], - "name": "getInterestRateStrategyAddress", - "outputs": [ - { - "internalType": "address", - "name": "irStrategyAddress", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "asset", - "type": "address" - } - ], - "name": "getLiquidationProtocolFee", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "asset", - "type": "address" - } - ], - "name": "getPaused", - "outputs": [ - { - "internalType": "bool", - "name": "isPaused", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "asset", - "type": "address" - } - ], - "name": "getReserveCaps", - "outputs": [ - { - "internalType": "uint256", - "name": "borrowCap", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "supplyCap", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "asset", - "type": "address" - } - ], - "name": "getReserveConfigurationData", - "outputs": [ - { - "internalType": "uint256", - "name": "decimals", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "ltv", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "liquidationThreshold", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "liquidationBonus", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "reserveFactor", - "type": "uint256" - }, - { - "internalType": "bool", - "name": "usageAsCollateralEnabled", - "type": "bool" - }, - { - "internalType": "bool", - "name": "borrowingEnabled", - "type": "bool" - }, - { - "internalType": "bool", - "name": "stableBorrowRateEnabled", - "type": "bool" - }, - { - "internalType": "bool", - "name": "isActive", - "type": "bool" - }, - { - "internalType": "bool", - "name": "isFrozen", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "asset", - "type": "address" - } - ], - "name": "getReserveData", - "outputs": [ - { - "internalType": "uint256", - "name": "unbacked", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "accruedToTreasuryScaled", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "totalAToken", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "totalStableDebt", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "totalVariableDebt", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "liquidityRate", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "variableBorrowRate", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "stableBorrowRate", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "averageStableBorrowRate", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "liquidityIndex", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "variableBorrowIndex", - "type": "uint256" - }, - { - "internalType": "uint40", - "name": "lastUpdateTimestamp", - "type": "uint40" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "asset", - "type": "address" - } - ], - "name": "getReserveEModeCategory", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "asset", - "type": "address" - } - ], - "name": "getReserveTokensAddresses", - "outputs": [ - { - "internalType": "address", - "name": "aTokenAddress", - "type": "address" - }, - { - "internalType": "address", - "name": "stableDebtTokenAddress", - "type": "address" - }, - { - "internalType": "address", - "name": "variableDebtTokenAddress", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "asset", - "type": "address" - } - ], - "name": "getSiloedBorrowing", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "asset", - "type": "address" - } - ], - "name": "getTotalDebt", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "asset", - "type": "address" - } - ], - "name": "getUnbackedMintCap", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "asset", - "type": "address" - }, - { - "internalType": "address", - "name": "user", - "type": "address" - } - ], - "name": "getUserReserveData", - "outputs": [ - { - "internalType": "uint256", - "name": "currentATokenBalance", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "currentStableDebt", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "currentVariableDebt", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "principalStableDebt", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "scaledVariableDebt", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "stableBorrowRate", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "liquidityRate", - "type": "uint256" - }, - { - "internalType": "uint40", - "name": "stableRateLastUpdated", - "type": "uint40" - }, - { - "internalType": "bool", - "name": "usageAsCollateralEnabled", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - } -] \ No newline at end of file diff --git a/src/factory/providers/optimism/aavev3/index.ts b/src/factory/providers/optimism/aavev3/index.ts index 2da7475e..36f8aa9b 100644 --- a/src/factory/providers/optimism/aavev3/index.ts +++ b/src/factory/providers/optimism/aavev3/index.ts @@ -1,75 +1,23 @@ -import util from '../../../../util/blockchainUtil'; import formatter from '../../../../util/formatter'; -import POOL_DATA_PROVIDER_V3_ABI from './abi/poolDataProviderV3Abi.json'; -import AAVE_ERC20_ABI from './abi/aaveErc20Abi.json'; import { ITvlParams, ITvlReturn } from '../../../../interfaces/ITvl'; +import aaveV3 from '../../../../util/calculators/aaveV3'; const START_BLOCK = 4365499; const POOL_DATA_PROVIDER_V3 = '0x69FA688f1Dc47d4B5d8029D5a35FB7a548310654'; -async function getAddresses(poolDataProviderV3, block, chain, web3) { - const aaveTokenMarketData = await util.executeCall( - poolDataProviderV3, - POOL_DATA_PROVIDER_V3_ABI, - 'getAllATokens', - [], - block, - chain, - web3, - ); - - const aaveTokenAddresses = []; - aaveTokenMarketData.map((aaveTokensData) => { - if (aaveTokensData) { - aaveTokenAddresses.push( - typeof aaveTokensData == 'string' - ? aaveTokensData.substring(aaveTokensData.indexOf(',') + 1) - : aaveTokensData.tokenAddress, - ); - } - }); - - const underlyingAddressesData = await util.executeCallOfMultiTargets( - aaveTokenAddresses, - AAVE_ERC20_ABI, - 'UNDERLYING_ASSET_ADDRESS', - [], - block, - chain, - web3, - ); - - const reserveTokenAddresses = underlyingAddressesData.map( - (reserveData) => reserveData, - ); - - return [aaveTokenAddresses, reserveTokenAddresses]; -} - async function tvl(params: ITvlParams): Promise> { const { block, chain, provider, web3 } = params; if (block < START_BLOCK) { return {}; } - const balances = {}; - - const [aaveTokens, reserveTokens] = await getAddresses( + const balances = await aaveV3.getTvl( POOL_DATA_PROVIDER_V3, block, chain, web3, ); - const balanceResults = await util.getTokenBalancesOfHolders( - aaveTokens, - reserveTokens, - block, - chain, - web3, - ); - - formatter.sumMultiBalanceOf(balances, balanceResults); formatter.convertBalancesToFixed(balances); return { balances }; } diff --git a/src/factory/providers/polygon/aavev3/index.ts b/src/factory/providers/polygon/aavev3/index.ts new file mode 100644 index 00000000..7c5d3784 --- /dev/null +++ b/src/factory/providers/polygon/aavev3/index.ts @@ -0,0 +1,24 @@ +import formatter from '../../../../util/formatter'; +import { ITvlParams, ITvlReturn } from '../../../../interfaces/ITvl'; +import aaveV3 from '../../../../util/calculators/aaveV3'; + +const START_BLOCK = 25824401; +const POOL_DATA_PROVIDER_V3 = '0x69FA688f1Dc47d4B5d8029D5a35FB7a548310654'; + +async function tvl(params: ITvlParams): Promise> { + const { block, chain, provider, web3 } = params; + if (block < START_BLOCK) { + return {}; + } + + const balances = await aaveV3.getTvl( + POOL_DATA_PROVIDER_V3, + block, + chain, + web3, + ); + + formatter.convertBalancesToFixed(balances); + return { balances }; +} +export { tvl }; diff --git a/src/util/calculators/aavev3.ts b/src/util/calculators/aavev3.ts new file mode 100644 index 00000000..2670f576 --- /dev/null +++ b/src/util/calculators/aavev3.ts @@ -0,0 +1,74 @@ +import util from '../../util/blockchainUtil'; +import formatter from '../../util/formatter'; +import POOL_DATA_PROVIDER_V3_ABI from '../../constants/abi/poolDataProviderV3Abi.json'; +import AAVE_ERC20_ABI from '../../constants/abi/aaveErc20Abi.json'; +import Web3 from 'web3'; +import { IBalances } from '../../interfaces/ITvl'; + +async function getAddresses(poolDataProviderV3, block, chain, web3) { + const aaveTokenMarketData = await util.executeCall( + poolDataProviderV3, + POOL_DATA_PROVIDER_V3_ABI, + 'getAllATokens', + [], + block, + chain, + web3, + ); + + const aaveTokenAddresses = []; + aaveTokenMarketData.map((aaveTokensData) => { + if (aaveTokensData) { + aaveTokenAddresses.push( + typeof aaveTokensData == 'string' + ? aaveTokensData.substring(aaveTokensData.indexOf(',') + 1) + : aaveTokensData.tokenAddress, + ); + } + }); + + const underlyingAddressesData = await util.executeCallOfMultiTargets( + aaveTokenAddresses, + AAVE_ERC20_ABI, + 'UNDERLYING_ASSET_ADDRESS', + [], + block, + chain, + web3, + ); + + const reserveTokenAddresses = underlyingAddressesData.map( + (reserveData) => reserveData, + ); + + return [aaveTokenAddresses, reserveTokenAddresses]; +} + +async function getTvl( + poolDataProvider: string, + block: number, + chain: string, + web3: Web3, +): Promise { + const balances = {}; + + const [aaveTokens, reserveTokens] = await getAddresses( + poolDataProvider, + block, + chain, + web3, + ); + + const balanceResults = await util.getTokenBalancesOfHolders( + aaveTokens, + reserveTokens, + block, + chain, + web3, + ); + + formatter.sumMultiBalanceOf(balances, balanceResults); + return balances; +} + +export default { getTvl };