Skip to content

Commit

Permalink
get available tokens in protocol from currencyController contract (De…
Browse files Browse the repository at this point in the history
  • Loading branch information
as472 authored Feb 29, 2024
1 parent eeb95a6 commit fedd320
Showing 1 changed file with 27 additions and 15 deletions.
42 changes: 27 additions & 15 deletions projects/SecuredFinance/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
const config = {
ethereum: { FIL: '0x6a7b717ae5ed65f85ba25403d5063d368239828e'},
arbitrum: {},
avax: { FIL: '0xf3bcb00146d1123dd19974de758f83d01e26d3f1'},
polygon_zkevm: { vault: '0x0896AC8B9e2DC3545392ff65061E5a8a3eD68824' },
}
ethereum: {},
arbitrum: {},
avax: {},
polygon_zkevm: {
tokenVault: '0x0896AC8B9e2DC3545392ff65061E5a8a3eD68824',
currencyController: '0x9E1254292195F241FA2DF1aA51af23796627A74B',
},
};

Object.keys(config).forEach(chain => {
const { vault = '0xB74749b2213916b1dA3b869E41c7c57f1db69393', FIL } = config[chain]
module.exports[chain] = {
tvl: async (_, _b, _cb, { api, }) => {
const bytes = await api.call({ abi: 'function getCollateralCurrencies() view returns (bytes32[])', target: vault })
const tokens = await api.multiCall({ abi: 'function getTokenAddress(bytes32) view returns (address)', calls: bytes, target: vault })
if (FIL) tokens.push(FIL)
return api.sumTokens({ owner: vault, tokens, })
}
}
})
const {
tokenVault = '0xB74749b2213916b1dA3b869E41c7c57f1db69393',
currencyController = '0x7dca6b6BF30cd28ADe83e86e21e82e3F852bF2DC',
} = config[chain];
module.exports[chain] = {
tvl: async (_, _b, _cb, { api }) => {
const bytes = await api.call({
abi: 'function getCurrencies() view returns (bytes32[])',
target: currencyController,
});
const tokens = await api.multiCall({
abi: 'function getTokenAddress(bytes32) view returns (address)',
calls: bytes,
target: tokenVault,
});
return api.sumTokens({ owner: tokenVault, tokens });
},
};
});

0 comments on commit fedd320

Please sign in to comment.