diff --git a/adapters/zklink/hourly_blocks.csv b/adapters/zklink/hourly_blocks.csv index 696bc8f6..6e808c1f 100644 --- a/adapters/zklink/hourly_blocks.csv +++ b/adapters/zklink/hourly_blocks.csv @@ -1,2 +1,2 @@ number,timestamp -3207030,1719141967 \ No newline at end of file +5954369,1719311206 \ No newline at end of file diff --git a/adapters/zklink/src/sdk/lib.ts b/adapters/zklink/src/sdk/lib.ts index 1ce883ae..158d1473 100644 --- a/adapters/zklink/src/sdk/lib.ts +++ b/adapters/zklink/src/sdk/lib.ts @@ -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), @@ -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 };