Skip to content

Commit

Permalink
fix: block number mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
xsteadybcgo committed Jun 25, 2024
1 parent 83bbe4d commit 4a8c2cc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 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
3207030,1719141967
5954369,1719311206
22 changes: 18 additions & 4 deletions adapters/zklink/src/sdk/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ const getLPInfo = async (blockNumber: number): Promise<{ lpMap: LPMap, poolAddre
return { lpMap, poolAddress }
}

export const getUserBalanceSnapshotAtBlock = async (blockNumber: number) => {
export const getUserBalanceSnapshotAtBlock = async (lineaBlockNumber: number) => {
const blockNumber = Number(await mapLineaBlockToNovaBlock(lineaBlockNumber))
const [userBalancePosition, lpInfo] = await Promise.all(
[
getUserBalance(blockNumber, tokenWhiteList),
Expand All @@ -238,8 +239,21 @@ export const getUserBalanceSnapshotAtBlock = async (blockNumber: number) => {
return userTokenPositionMap.values()
}

export const getTimestampAtBlock = async (blockNumber: number) => {
const provider = new JsonRpcProvider('https://rpc.zklink.io')
export const mapLineaBlockToNovaBlock = async (blockNumber: number) => {
const provider = new JsonRpcProvider('https://rpc.linea.build')
const block = await provider.getBlock(blockNumber)
return Number(block?.timestamp);
const query = `query BlockInfo($timestamp_lte: BigInt = ${block?.timestamp}) {
blocks(
where: {timestamp_lte: $timestamp_lte}
first: 1
orderBy: timestamp
orderDirection: desc
) {
number
timestamp
}
}
`
const { data } = await fetchGraphQLData<{ data: { blocks: { number: string }[] } }>('https://graph.zklink.io/subgraphs/name/nova-blocks', query)
return data.blocks[0].number
};

0 comments on commit 4a8c2cc

Please sign in to comment.