Skip to content

Commit

Permalink
Merge pull request delta-hq#241 from xsteadybcgo/main
Browse files Browse the repository at this point in the history
zklink: others: fix tx fee receiver balance
  • Loading branch information
0xroll authored Jun 27, 2024
2 parents be7f7a6 + b26e8c2 commit a87e2fb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion adapters/zklink/hourly_blocks.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
number,timestamp
5954369,1719311206
6030835,1719311206
2 changes: 2 additions & 0 deletions adapters/zklink/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
18 changes: 16 additions & 2 deletions adapters/zklink/src/sdk/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
{
Expand Down Expand Up @@ -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
Expand All @@ -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 => {
Expand All @@ -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()!,
Expand Down Expand Up @@ -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<string, { balance: bigint; tokenAddress: string; userAddress: string; }>())
Expand Down

0 comments on commit a87e2fb

Please sign in to comment.