Skip to content

Commit

Permalink
aavev3
Browse files Browse the repository at this point in the history
  • Loading branch information
mantasfam committed Jul 20, 2023
1 parent 691dfa6 commit aed153a
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 1,530 deletions.
File renamed without changes.
56 changes: 2 additions & 54 deletions src/factory/providers/arbitrum/aavev3/index.ts
Original file line number Diff line number Diff line change
@@ -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<Partial<ITvlReturn>> {
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 };
}
Expand Down
24 changes: 24 additions & 0 deletions src/factory/providers/ethereum/aavev3/index.ts
Original file line number Diff line number Diff line change
@@ -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<Partial<ITvlReturn>> {
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 };
Loading

0 comments on commit aed153a

Please sign in to comment.