Skip to content

Commit

Permalink
fix: rpc failure - teahouse (#1119)
Browse files Browse the repository at this point in the history
Co-authored-by: Wade <[email protected]>
  • Loading branch information
daiwanwei and Wade authored Dec 15, 2023
1 parent f65ce53 commit 989eb9d
Showing 1 changed file with 27 additions and 26 deletions.
53 changes: 27 additions & 26 deletions src/adaptors/teahouse-permissionless/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
};


Expand All @@ -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)
Expand All @@ -165,9 +165,8 @@ async function checkVaultSupply(vault: Vault, time: number): Promise<boolean> {
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
Expand Down Expand Up @@ -272,6 +271,8 @@ async function topLvl(_: number): Promise<Pool[]> {
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) {
Expand Down

0 comments on commit 989eb9d

Please sign in to comment.