From f30ccaa0fee725cdd7d5e9b9a8c42f41f9a94456 Mon Sep 17 00:00:00 2001 From: Apeguru Date: Thu, 10 Oct 2024 17:50:43 +0700 Subject: [PATCH 1/2] fix: Reduce amount of user wallets with amount greated than 0 --- adapters/lynex/src/index.ts | 2 +- adapters/lynex/src/sdk/config.ts | 5 ++++- adapters/lynex/src/sdk/lensDetails.ts | 2 +- adapters/lynex/src/sdk/subgraphDetails.ts | 4 ++-- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/adapters/lynex/src/index.ts b/adapters/lynex/src/index.ts index 12aae4ce..bfd33d1d 100644 --- a/adapters/lynex/src/index.ts +++ b/adapters/lynex/src/index.ts @@ -155,7 +155,7 @@ export const getUserStakedTVLByBlock = async ({ tokenBalanceMap[user_address] = tokenBalanceMap[user_address] ?? {}; tokenBalanceMap[user_address][token0Address] = BigNumber( tokenBalanceMap[user_address][token0Address] ?? 0 - ).plus(userVote.result.amount.toString()); + ).plus(userVote.result.amount?.toString() ?? '0'); } } diff --git a/adapters/lynex/src/sdk/config.ts b/adapters/lynex/src/sdk/config.ts index 1f5dc64f..2c92dc01 100644 --- a/adapters/lynex/src/sdk/config.ts +++ b/adapters/lynex/src/sdk/config.ts @@ -10,7 +10,10 @@ export const V3_SUBGRAPH_URL = export const client = createPublicClient({ chain: linea, - transport: http("https://rpc.linea.build"), + transport: http("https://rpc.linea.build", { + retryCount: 5, + timeout: 60_000, + }), }); export const PROBLEM_POOLS = { diff --git a/adapters/lynex/src/sdk/lensDetails.ts b/adapters/lynex/src/sdk/lensDetails.ts index acab8592..e1e79bd7 100644 --- a/adapters/lynex/src/sdk/lensDetails.ts +++ b/adapters/lynex/src/sdk/lensDetails.ts @@ -85,7 +85,7 @@ export const fetchUserPools = async ( blockNumber )) as any; const delay = (ms: number | undefined) => new Promise(resolve => setTimeout(resolve, ms)) - await delay(100) + await delay(10000) return res.map((r: any) => { if (r.status !== 'success') { throw new Error("RPC call error. Status: " + r.status); diff --git a/adapters/lynex/src/sdk/subgraphDetails.ts b/adapters/lynex/src/sdk/subgraphDetails.ts index a0e76c95..3fa7a706 100644 --- a/adapters/lynex/src/sdk/subgraphDetails.ts +++ b/adapters/lynex/src/sdk/subgraphDetails.ts @@ -19,7 +19,7 @@ export const getUserAddresses = async ( while (fetchNext) { let query = ` query UserQuery { - users(${blockQuery} first:1000,skip:${skip}) { + users(${blockQuery} first:1000,skip:${skip}, where:{liquidityPositions_: {amount_gt: 0}}) { id liquidityPositions { id @@ -50,7 +50,7 @@ export const getUserAddresses = async ( headers: { "Content-Type": "application/json" }, }); let data = await response.json(); - let userStakes = data.data.users; + let userStakes = data.data?.users ?? []; for (let i = 0; i < userStakes.length; i++) { let userStake = userStakes[i]; let transformedUserStake: UserStake = { From 86f35f71155c7d80d194b88120e5f22674ff2000 Mon Sep 17 00:00:00 2001 From: Apeguru Date: Thu, 24 Oct 2024 12:00:44 +0700 Subject: [PATCH 2/2] fix: Delay in proper place --- adapters/lynex/src/index.ts | 5 ++++- adapters/lynex/src/sdk/lensDetails.ts | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/adapters/lynex/src/index.ts b/adapters/lynex/src/index.ts index bfd33d1d..2f3fd61b 100644 --- a/adapters/lynex/src/index.ts +++ b/adapters/lynex/src/index.ts @@ -91,7 +91,7 @@ export const getUserStakedTVLByBlock = async ({ let userPoolFetch = []; let userVotesFetch = []; - const batchSize = 400; + const batchSize = 100; let position = 0; let userFetchResult: any = []; let userVotesResult: any = []; @@ -112,6 +112,9 @@ export const getUserStakedTVLByBlock = async ({ ...(await Promise.all(userVotesFetch)), ]; userVotesFetch = []; + console.timeEnd("Batch"); + const delay = (ms: number) => new Promise(resolve => setTimeout(resolve, ms)) + await delay(60000) } position++; } diff --git a/adapters/lynex/src/sdk/lensDetails.ts b/adapters/lynex/src/sdk/lensDetails.ts index e1e79bd7..d0aab9af 100644 --- a/adapters/lynex/src/sdk/lensDetails.ts +++ b/adapters/lynex/src/sdk/lensDetails.ts @@ -85,7 +85,7 @@ export const fetchUserPools = async ( blockNumber )) as any; const delay = (ms: number | undefined) => new Promise(resolve => setTimeout(resolve, ms)) - await delay(10000) + await delay(3000) return res.map((r: any) => { if (r.status !== 'success') { throw new Error("RPC call error. Status: " + r.status);