Skip to content

Commit

Permalink
optimize for shallow pool
Browse files Browse the repository at this point in the history
  • Loading branch information
Venson committed Aug 7, 2024
1 parent 11dad58 commit 497704c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
19 changes: 14 additions & 5 deletions projects/teahouse-v3/abi.js
Original file line number Diff line number Diff line change
@@ -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)",
Expand All @@ -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)" }],
},
};
};
29 changes: 21 additions & 8 deletions projects/teahouse-v3/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down Expand Up @@ -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();
},
Expand Down

0 comments on commit 497704c

Please sign in to comment.