From 989eb9d649b0dff351268132494bf80ae8695251 Mon Sep 17 00:00:00 2001 From: daiwanwei <93238466+daiwanwei@users.noreply.github.com> Date: Fri, 15 Dec 2023 16:59:18 +0800 Subject: [PATCH] fix: rpc failure - teahouse (#1119) Co-authored-by: Wade --- src/adaptors/teahouse-permissionless/utils.ts | 53 ++++++++++--------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/src/adaptors/teahouse-permissionless/utils.ts b/src/adaptors/teahouse-permissionless/utils.ts index 9313b1331a..e542bfa456 100644 --- a/src/adaptors/teahouse-permissionless/utils.ts +++ b/src/adaptors/teahouse-permissionless/utils.ts @@ -103,26 +103,28 @@ function updateRpcUrl(sdk: any, chain: string, chainId: number, rpcUrl: string) sdk.api.config.setProvider(chain, provider); } -async function makeMulticall(abi: any, addresses: string[], chain: string, params = null, options) { +async function makeCall(abi: any, address: string, chain: string, params = null, options) { const block = options.block || `latest`; - const data = await sdk.api.abi.multiCall({ + console.log(`block: ${block}`, `chain: ${chain}`, `address: ${address}`, `params: ${params}`); + console.log(`abi: ${JSON.stringify(abi)}`); + const data = await sdk.api.abi.call({ abi, - calls: addresses.map((address) => ({ - target: address, - params, - })), chain, block + target: address, + params, + // calls: addresses.map((address) => ({ + // target: address, + // params, + // })), + chain, block }); - let outputByArray = [] - let outputByAddress = {} - for (let i = 0; i < data.output.length; i++) { - const key = addresses[i].toLowerCase(); - outputByArray.push(data.output[i].output); - outputByAddress[key] = data.output[i].output; - } - return { - outputByArray: outputByArray, - outputByAddress: outputByAddress - }; + // let outputByArray = [] + // let outputByAddress = {} + // for (let i = 0; i < data.output.length; i++) { + // const key = addresses[i].toLowerCase(); + // outputByArray.push(data.output[i].output); + // outputByAddress[key] = data.output[i].output; + // } + return data.output }; @@ -134,15 +136,13 @@ async function getLiquidityData(vault: Vault, block?: number): Promise<{ const estimatedFnABI = TEAHOUSE_VAULT_V3_ABI.find( (el) => el.name === estimatedFn ) - const [tvl] = (await makeMulticall( - estimatedFnABI, [vault.address], chain, null, {block: block})) - .outputByArray + const tvl = (await makeCall( + estimatedFnABI, vault.address, chain, null, {block: block})) const supplyFnABI = TEAHOUSE_VAULT_V3_ABI.find( (el) => el.name === `totalSupply` ) - const [shareSupply] = (await makeMulticall( - supplyFnABI, [vault.address], chain, null, {block: block})) - .outputByArray + const shareSupply = (await makeCall( + supplyFnABI, vault.address, chain, null, {block: block})) return { tvl: new bn(tvl || 0), shareSupply: new bn(shareSupply || 0) @@ -165,9 +165,8 @@ async function checkVaultSupply(vault: Vault, time: number): Promise { const supplyFnABI = TEAHOUSE_VAULT_V3_ABI.find( (el) => el.name === `totalSupply` ) - const [shareSupply] = (await makeMulticall( - supplyFnABI, [vault.address], vault.chain, null, {block: block})) - .outputByArray + const shareSupply = (await makeCall( + supplyFnABI, vault.address, vault.chain, null, {block: block})) const supply = new bn(shareSupply || 0) if (supply?.gt(0)) return true return false @@ -272,6 +271,8 @@ async function topLvl(_: number): Promise { const vaults = await getVaultData(vaultType) const interval = 24 * 60 * 60 updateRpcUrl(sdk, 'arbitrum', 42161, "https://rpc.ankr.com/arbitrum") + updateRpcUrl(sdk, 'boba', 288, "https://lightning-replica.boba.network/") + updateRpcUrl(sdk, 'mantle', 5000, "https://rpc.mantle.xyz/") const pools = [] for (let vault of vaults) {