Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Everclear (connext) : bridge : fix timeout #209

Merged
merged 4 commits into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion adapters/connext/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node dist/index.js",
"dev": "ts-node src/index.ts",
"dev": "ts-node src/dev.ts",
"compile": "tsc",
"watch": "tsc -w",
"clear": "rm -rf dist"
Expand Down
50 changes: 50 additions & 0 deletions adapters/connext/src/dev.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { createPublicClient, formatUnits, http, parseAbi, parseUnits } from "viem";
import { getUserTVLByBlock } from "./utils";
import { linea } from "viem/chains";
import { getLpAccountBalanceAtBlock } from "./utils/subgraph";
import { getCompositeBalances } from "./utils/assets";

const users = ['0xc82c7d826b1ed0b2a4e9a2be72b445416f901fd1', '0xdd507fecd5de6f5398060cc0404cb133f9048c3a'];

const blocks = [5081800, 5082887, 5084087, 6055026];

const logUserEntry = async (user: string) => {
const ret: Record<number, any> = {}
const composite: Record<number, any> = {}
for (const block of blocks) {
const results = await getLpAccountBalanceAtBlock(block, undefined, user);
composite[block] = (await getCompositeBalances(results)).map(r => {
return {
latestTransferBlock: r.block,
account: r.account.id,
tokens: r.underlyingTokens.join(', '),
amount: r.underlyingBalances.join(', '),
}
})

ret[block] = results.map(r => {
return {
latestTransferBlock: r.block,
account: r.account.id,
tokens: r.token.id,
amount: r.amount
}
})
}
console.log('tvl for', user, ':')
console.log(ret)
console.log('\ncomposite for', user, ':')
console.log(composite)
}

const dev = async () => {
for (const user of users) {
await logUserEntry(user)
}
}
dev();

// 5081800, 1717289323
// 5082887, 1717297198
// 5084087, 1717300798
// 5085287, 1717304398
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
2 changes: 1 addition & 1 deletion adapters/connext/src/utils/getUserTvlByBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export const getUserTVLByBlock = async (blocks: BlockData): Promise<OutputDataSc
composite.forEach(({ account, underlyingBalances, underlyingTokens }) => {
results.push(...underlyingBalances.map((b, i) => {
const formatted: OutputDataSchemaRow = {
timestamp: blockTimestamp,
block_number: blockNumber,
timestamp: blockTimestamp,
user_address: account.id,
token_address: underlyingTokens[i],
token_balance: BigInt(b),
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
Loading
Loading