From fedd320632123110c6b420a5ad60c1379532c693 Mon Sep 17 00:00:00 2001 From: Arpit Singh Date: Thu, 29 Feb 2024 20:08:13 +0530 Subject: [PATCH] get available tokens in protocol from currencyController contract (#9120) --- projects/SecuredFinance/index.js | 42 ++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/projects/SecuredFinance/index.js b/projects/SecuredFinance/index.js index e7895b04f4e..1daa4296a04 100644 --- a/projects/SecuredFinance/index.js +++ b/projects/SecuredFinance/index.js @@ -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 }); + }, + }; +});