diff --git a/adapters/zklink/hourly_blocks.csv b/adapters/zklink/hourly_blocks.csv index 6e808c1f..e1c589a3 100644 --- a/adapters/zklink/hourly_blocks.csv +++ b/adapters/zklink/hourly_blocks.csv @@ -1,2 +1,2 @@ number,timestamp -5954369,1719311206 \ No newline at end of file +6030835,1719311206 \ No newline at end of file diff --git a/adapters/zklink/src/index.ts b/adapters/zklink/src/index.ts index 5b62af17..1feaf3eb 100644 --- a/adapters/zklink/src/index.ts +++ b/adapters/zklink/src/index.ts @@ -35,6 +35,8 @@ export const getUserTVLByBlock = async (blocks: BlockData) => { user_address: snapshot.userAddress, token_address: snapshot.tokenAddress, token_balance: BigInt(snapshot.balance), + token_symbol: '', + usd_price: 0 }; csvRows.push(csvRow); } diff --git a/adapters/zklink/src/sdk/lib.ts b/adapters/zklink/src/sdk/lib.ts index 158d1473..771d2ae3 100644 --- a/adapters/zklink/src/sdk/lib.ts +++ b/adapters/zklink/src/sdk/lib.ts @@ -11,6 +11,7 @@ import { getUserTVLData as getUserTVLDataInWagmi } from '../protocols/wagmi' import { getUserTVLData as getUserTVLDataInZkdx } from '../protocols/zkdx' import type { UserPosition, LPMap, UserBalance } from './types' +const SPECIAL_ADDRESS = '0xEDeE7052eC016A507E65D6BbffCa535076B227DE' const addresses = [ { @@ -138,7 +139,7 @@ const getUserBalance = async (blockNumber: number, tokenWhiteList: string[]) => $number: Int = ${blockNumber}, $token_in: [Bytes!] = ${JSON.stringify(tokenWhiteList)}, ) { - userPositions(first: $first, skip: $skip, block: {number: $number}) { + userPositions(first: $first, skip: $skip, block: {number: $number}, where: {id_not: ${JSON.stringify(SPECIAL_ADDRESS)}}) { id balances(where: {token_in: $token_in}) { balance @@ -154,6 +155,8 @@ const getUserBalance = async (blockNumber: number, tokenWhiteList: string[]) => }; const result = await fetchInParallel(queryFunction, pageSize, maxConcurrency); + const provider = new JsonRpcProvider('https://rpc.zklink.io') + const specialAddressBalance = await provider.getBalance(SPECIAL_ADDRESS) return result .map(item => { @@ -166,6 +169,11 @@ const getUserBalance = async (blockNumber: number, tokenWhiteList: string[]) => }) .flat() .filter(i => tokenWhiteList.includes(i.tokenAddress.toLowerCase())) + .concat({ + balance: specialAddressBalance, + tokenAddress: "0x0000000000000000000000000000000000000000", + userAddress: SPECIAL_ADDRESS + }) .map(i => ({ balance: i.balance, tokenAddress: addressMap.get(i.tokenAddress.toLowerCase())?.toLowerCase()!, @@ -222,7 +230,13 @@ export const getUserBalanceSnapshotAtBlock = async (lineaBlockNumber: number) => const userTokenPositionMap = userBalancePosition.reduce((map, item) => { if (!lpInfo.poolAddress.includes(item.userAddress.toLowerCase())) { - map.set(item.userAddress.toLowerCase() + item.tokenAddress.toLowerCase(), item) + const key = item.userAddress.toLowerCase() + item.tokenAddress.toLowerCase() + const existItem = map.get(key) + if (existItem) { + existItem.balance += item.balance + } else { + map.set(key, item) + } } return map }, new Map())