diff --git a/adapters/connext/src/utils/assets.ts b/adapters/connext/src/utils/assets.ts index 300b5664..bae33991 100644 --- a/adapters/connext/src/utils/assets.ts +++ b/adapters/connext/src/utils/assets.ts @@ -1,6 +1,6 @@ import { createPublicClient, http, parseUnits } from "viem"; import { linea } from "viem/chains"; -import { PoolInformation, getPoolInformationFromLpToken } from "./cartographer"; +import { getPoolInformationFromLpToken, poolInfo } from "./cartographer"; import { LINEA_CHAIN_ID, CONNEXT_LINEA_ADDRESS } from "./subgraph"; import { LpAccountBalanceHourly, RouterEventResponse } from "./types"; @@ -37,18 +37,10 @@ const CONNEXT_ABI = [ ] export const getCompositeBalances = async (amms: LpAccountBalanceHourly[]): Promise => { - // get lp token balances - const poolInfo = new Map(); - // get pool info - await Promise.all(amms.map(async d => { - const poolId = d.token.id.toLowerCase(); - if (poolInfo.has(poolId)) { - return; - } - const pool = await getPoolInformationFromLpToken(d.token.id, LINEA_CHAIN_ID); - poolInfo.set(poolId, pool); - })); + for (const amm of amms) { + await getPoolInformationFromLpToken(amm.token.id, LINEA_CHAIN_ID) + } // get contract interface const client = createPublicClient({ chain: linea, transport: http() }); diff --git a/adapters/connext/src/utils/cartographer.ts b/adapters/connext/src/utils/cartographer.ts index b57a363e..62c522d6 100644 --- a/adapters/connext/src/utils/cartographer.ts +++ b/adapters/connext/src/utils/cartographer.ts @@ -20,7 +20,12 @@ type PoolInformationResponse = { pool_token_decimals: [number, number]; } +export const poolInfo = new Map(); + export const getPoolInformationFromLpToken = async (lpToken: string, chainId: number): Promise => { + if (poolInfo.has(lpToken.toLowerCase())) { + return poolInfo.get(lpToken.toLowerCase())!; + } const url = `${MAINNET_CARTOGRAPHER_URL}/stableswap_pools?lp_token=eq.${lpToken.toLowerCase()}&domain=eq.${chainIdToDomain(chainId)}`; const response = await fetch(url); @@ -29,13 +34,15 @@ export const getPoolInformationFromLpToken = async (lpToken: string, chainId: nu throw new Error(`More than one pool found for lpToken/chain: ${lpToken}/${chainId}`) } const { key, lp_token, pooled_tokens, pool_token_decimals, domain } = data[0]; - return { + const ret = { key, lpToken: lp_token, pooledTokens: pooled_tokens, pooledTokenDecimals: pool_token_decimals, chainId: domainToChainId(+domain) } + poolInfo.set(lpToken.toLowerCase(), ret); + return ret; }; diff --git a/adapters/connext/src/utils/subgraph.ts b/adapters/connext/src/utils/subgraph.ts index 4a6aae77..bf7ed83a 100644 --- a/adapters/connext/src/utils/subgraph.ts +++ b/adapters/connext/src/utils/subgraph.ts @@ -1,7 +1,6 @@ -import { PoolInformation, getPoolInformationFromLpToken } from "./cartographer"; import { LpAccountBalanceHourly, SubgraphResult } from "./types"; import { linea } from "viem/chains"; -import { createPublicClient, http, parseUnits } from "viem"; +import { createPublicClient, http } from "viem"; export const CONNEXT_SUBGRAPH_QUERY_URL = "https://api.goldsky.com/api/public/project_clssc64y57n5r010yeoly05up/subgraphs/connext/stableswap-analytics-linea-0.0.1/gn"; export const LINEA_CHAIN_ID = 59144;