From 21d081a0f5ba8f5bd326931d5173042c1b532424 Mon Sep 17 00:00:00 2001 From: "abner.huang" Date: Tue, 17 Dec 2024 21:00:08 +0800 Subject: [PATCH 1/2] update satoshi protocol vault assets --- projects/satoshi-protocol/index.js | 65 ++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 3 deletions(-) diff --git a/projects/satoshi-protocol/index.js b/projects/satoshi-protocol/index.js index 1206ea125c..5f21125717 100644 --- a/projects/satoshi-protocol/index.js +++ b/projects/satoshi-protocol/index.js @@ -6,9 +6,12 @@ const AssetConfigSettingEventABI = "event AssetConfigSetting(address asset,uint2 function createExports({ troveList, nymInformation, // { address, fromBlock } + aaveStrategyVaults, // { address, asset, aToken }[] + pellStrategyVaults, // { address, asset }[] }) { return { - tvl: async (api) => { + tvl: async (api,_a,_b,chain) => { + const chainKey = chain.storedKey; const tokens = []; const owners = []; if(troveList) { @@ -25,7 +28,50 @@ function createExports({ }) } - return sumTokens2({ api, tokensAndOwners2: [tokens, owners] }) + let otherAssets = []; // { key, amount }[] + if(aaveStrategyVaults) { + for(let index = 0; index < aaveStrategyVaults.length; index++) { + const { address: vault, aToken, asset } = aaveStrategyVaults[index]; + const assetAmount = await api.call({ + abi: "erc20:balanceOf", + target: aToken, + params: [vault], + }); + otherAssets.push({ + key: `${chainKey}:${asset}`, + amount: assetAmount, + }); + } + } + + if(pellStrategyVaults) { + for (let index = 0; index < pellStrategyVaults.length; index++) { + const { address: vault, asset } = pellStrategyVaults[index]; + const pellStrategy = await api.call({ + abi: "function pellStrategy() external view returns (address)", + target: vault, + }); + const assetAmount = await api.call({ + abi: "function userUnderlyingView(address) external view returns (uint256)", + target: pellStrategy, + params: [vault], + }); + otherAssets.push({ + key: `${chainKey}:${asset}`, + amount: assetAmount, + }); + } + } + + const result = await sumTokens2({ api, tokensAndOwners2: [tokens, owners] }) + otherAssets.forEach(({ key, amount }) => { + if(result[key]) { + result[key] = (BigInt(result[key]) + BigInt(amount)).toString(); + } else { + result[key] = amount; + } + }); + return result; }, } } @@ -71,7 +117,20 @@ module.exports = { nymInformation: { address: '0x7253493c3259137431a120752e410b38d0c715C2', fromBlock: 4614620, - } + }, + aaveStrategyVaults: [ + { + address: '0x713dD0E14376a6d34D0Fde2783dca52c9fD852bA', + aToken: '0xd6890176e8d912142AC489e8B5D8D93F8dE74D60', // aBOBWBTC + asset: '0x03C7054BCB39f7b2e5B2c7AcB37583e32D70Cfa3', // BOB WBTC + } + ], + pellStrategyVaults: [ + { + address: '0x04485140d6618be431D8841de4365510717df4fd', + asset: '0x03C7054BCB39f7b2e5B2c7AcB37583e32D70Cfa3', // BOB WBTC + } + ], }), bsquared: createExports({ troveList: [ From cfb210ee4755ab1813de87d2d400321b882dc0d2 Mon Sep 17 00:00:00 2001 From: g1nt0ki <99907941+g1nt0ki@users.noreply.github.com> Date: Thu, 19 Dec 2024 17:50:16 +0100 Subject: [PATCH 2/2] code refactor --- projects/satoshi-protocol/index.js | 63 ++++++++++-------------------- 1 file changed, 20 insertions(+), 43 deletions(-) diff --git a/projects/satoshi-protocol/index.js b/projects/satoshi-protocol/index.js index 5f21125717..f5300078d6 100644 --- a/projects/satoshi-protocol/index.js +++ b/projects/satoshi-protocol/index.js @@ -10,17 +10,16 @@ function createExports({ pellStrategyVaults, // { address, asset }[] }) { return { - tvl: async (api,_a,_b,chain) => { - const chainKey = chain.storedKey; + tvl: async (api) => { const tokens = []; const owners = []; - if(troveList) { + if (troveList) { owners.push(...troveList); const collaterals = await getCollateralsFromTrove(api, troveList); tokens.push(...collaterals); } - if(nymInformation) { + if (nymInformation) { const assetList = await getAssetListFromNymContract(api, nymInformation.address, nymInformation.fromBlock); assetList.forEach(asset => { owners.push(nymInformation.address); @@ -28,50 +27,28 @@ function createExports({ }) } - let otherAssets = []; // { key, amount }[] - if(aaveStrategyVaults) { - for(let index = 0; index < aaveStrategyVaults.length; index++) { + if (aaveStrategyVaults) { + const calls = [] + const tokens = [] + for (let index = 0; index < aaveStrategyVaults.length; index++) { const { address: vault, aToken, asset } = aaveStrategyVaults[index]; - const assetAmount = await api.call({ - abi: "erc20:balanceOf", - target: aToken, - params: [vault], - }); - otherAssets.push({ - key: `${chainKey}:${asset}`, - amount: assetAmount, - }); + tokens.push(asset) + calls.push({ target: aToken, params: vault }) } + const bals = await api.multiCall({ abi: 'erc20:balanceOf', calls }) + api.add(tokens, bals) } - if(pellStrategyVaults) { - for (let index = 0; index < pellStrategyVaults.length; index++) { - const { address: vault, asset } = pellStrategyVaults[index]; - const pellStrategy = await api.call({ - abi: "function pellStrategy() external view returns (address)", - target: vault, - }); - const assetAmount = await api.call({ - abi: "function userUnderlyingView(address) external view returns (uint256)", - target: pellStrategy, - params: [vault], - }); - otherAssets.push({ - key: `${chainKey}:${asset}`, - amount: assetAmount, - }); - } + if (pellStrategyVaults) { + const vaults = pellStrategyVaults.map(i => i.address) + const tokens = pellStrategyVaults.map(i => i.asset) + const strategies = await api.multiCall({ abi: 'address:pellStrategy', calls: vaults }) + const calls2 = strategies.map((v, i) => ({ target: v, params: vaults[i] })) + const bals = await api.multiCall({ abi: "function userUnderlyingView(address) external view returns (uint256)", calls: calls2 }) + api.add(tokens, bals) } - const result = await sumTokens2({ api, tokensAndOwners2: [tokens, owners] }) - otherAssets.forEach(({ key, amount }) => { - if(result[key]) { - result[key] = (BigInt(result[key]) + BigInt(amount)).toString(); - } else { - result[key] = amount; - } - }); - return result; + return sumTokens2({ api, tokensAndOwners2: [tokens, owners] }) }, } } @@ -82,7 +59,7 @@ async function getCollateralsFromTrove(api, troveList) { } async function getAssetListFromNymContract(api, nymContractAddress, fromBlock) { - const logs = await getLogs({api, target: nymContractAddress, fromBlock, eventAbi: AssetConfigSettingEventABI, onlyArgs: true}); + const logs = await getLogs({ api, target: nymContractAddress, fromBlock, eventAbi: AssetConfigSettingEventABI, onlyArgs: true }); const assetList = logs.map(item => item.asset); return assetList; }