From 497704ce69056ba34b0a0804176c3242396b22ac Mon Sep 17 00:00:00 2001 From: Venson Date: Wed, 7 Aug 2024 16:42:20 +0800 Subject: [PATCH] optimize for shallow pool --- projects/teahouse-v3/abi.js | 19 ++++++++++++++----- projects/teahouse-v3/index.js | 29 +++++++++++++++++++++-------- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/projects/teahouse-v3/abi.js b/projects/teahouse-v3/abi.js index f286f9420cd6..798f7ec2aa79 100644 --- a/projects/teahouse-v3/abi.js +++ b/projects/teahouse-v3/abi.js @@ -1,6 +1,7 @@ module.exports = { + assetToken0: "function assetToken0() view returns (address)", assetToken1: "function assetToken1() view returns (address)", - estimatedValueIntoken1: "function estimatedValueInToken1() view returns (uint256 value1)", + vaultAllUnderlyingAssets: "function vaultAllUnderlyingAssets() view returns (uint256 amount0, uint256 amount1)", getAssets: "function getAssets() view returns (address[])", getAssetsBalance: "function getAssetsBalance() view returns (uint256[])", assetType: "function assetType(address) external returns (uint8)", @@ -13,11 +14,19 @@ module.exports = { outputs: [{ name: "address", type: "felt" }], customType: "address", }, - estimated_value_in_token0: { + asset_token1: { type: "function", state_mutability: "view", - name: "estimated_value_in_token0", + name: "asset_token1", inputs: [], - outputs: [{ name: "value", type: "Uint256" }], + outputs: [{ name: "address", type: "felt" }], + customType: "address", + }, + vault_all_underlying_assets: { + type: "function", + state_mutability: "view", + name: "vault_all_underlying_assets", + inputs: [], + outputs: [{ name: "amount", "type": "(core::integer::u256, core::integer::u256)" }], }, -}; +}; \ No newline at end of file diff --git a/projects/teahouse-v3/index.js b/projects/teahouse-v3/index.js index df331983caf0..f90a68739d48 100644 --- a/projects/teahouse-v3/index.js +++ b/projects/teahouse-v3/index.js @@ -45,19 +45,25 @@ chains.forEach((chain) => { tvl: async (api) => { const vaults = await getVaultContractsAddress(chain); - // EVM pair vault - let tokens = await api.multiCall({ + let tokens0 = await api.multiCall({ + abi: abi.assetToken0, + calls: vaults.pair, + }); + let tokens1 = await api.multiCall({ abi: abi.assetToken1, calls: vaults.pair, }); let bals = await api.multiCall({ - abi: abi.estimatedValueIntoken1, + abi: abi.vaultAllUnderlyingAssets, calls: vaults.pair, }); - api.addTokens(tokens, bals); + let bals0 = bals.map(innerArray => innerArray[0]); + let bals1 = bals.map(innerArray => innerArray[1]); + api.addTokens(tokens0, bals0); + api.addTokens(tokens1, bals1); // EVM portfolio vault - tokens = await api.multiCall({ abi: abi.getAssets, calls: vaults.port }); + let tokens = await api.multiCall({ abi: abi.getAssets, calls: vaults.port }); bals = await api.multiCall({ abi: abi.getAssetsBalance, calls: vaults.port }); let assetTypes = await Promise.all(tokens.map( async (tokenArr, index) => @@ -88,15 +94,22 @@ chains.forEach((chain) => { api.addTokens(tokens, bals); // Starknet pair vault - tokens = await starknet.multiCall({ + tokens0 = await starknet.multiCall({ abi: abi.asset_token0, calls: vaults.starknetPair, }); + tokens1 = await starknet.multiCall({ + abi: abi.asset_token1, + calls: vaults.starknetPair, + }); bals = await starknet.multiCall({ - abi: abi.estimated_value_in_token0, + abi: abi.vault_all_underlying_assets, calls: vaults.starknetPair, }); - api.addTokens(tokens, bals); + bals0 = bals.map(innerArray => innerArray.amount['0']); + bals1 = bals.map(innerArray => innerArray.amount['1']); + api.addTokens(tokens0, bals0); + api.addTokens(tokens1, bals1); return api.getBalances(); },