Skip to content

Commit

Permalink
fix: pool info timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
LayneHaber committed Jun 8, 2024
1 parent 28864bc commit 2fa5d57
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
16 changes: 4 additions & 12 deletions adapters/connext/src/utils/assets.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -37,18 +37,10 @@ const CONNEXT_ABI = [
]

export const getCompositeBalances = async (amms: LpAccountBalanceHourly[]): Promise<CompositeBalanceHourly[]> => {
// get lp token balances
const poolInfo = new Map<string, PoolInformation>();

// 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() });
Expand Down
9 changes: 8 additions & 1 deletion adapters/connext/src/utils/cartographer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ type PoolInformationResponse = {
pool_token_decimals: [number, number];
}

export const poolInfo = new Map<string, PoolInformation>();

export const getPoolInformationFromLpToken = async (lpToken: string, chainId: number): Promise<PoolInformation> => {
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);
Expand All @@ -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;
};


Expand Down
3 changes: 1 addition & 2 deletions adapters/connext/src/utils/subgraph.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit 2fa5d57

Please sign in to comment.