Skip to content

Commit

Permalink
Get block ts by block number on solana
Browse files Browse the repository at this point in the history
  • Loading branch information
vrtnd committed Jan 19, 2024
1 parent 1368bf6 commit 81501c8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/utils/adapter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getLatestBlockNumber } from "./blocks";
import { getLatestBlockNumber, getTimestampBySolanaSlot } from "./blocks";
import { Chain } from "@defillama/sdk/build/general";
import { sql } from "./db";
import { getBridgeID } from "./wrappa/postgres/query";
Expand Down Expand Up @@ -438,6 +438,9 @@ export const runAdapterHistorical = async (
blockTimestamps[i] = block.timestamp;
break;
}
} else if (chain === "solana") {
blockTimestamps[i] = await getTimestampBySolanaSlot(blockNumber);
break;
} else {
blockTimestamps[i] = currentTimestamp;
break;
Expand Down
8 changes: 8 additions & 0 deletions src/utils/blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,11 @@ export async function getBlockByTimestamp(timestamp: number, chain: Chain) {
}
throw new Error(`Could not find block for timestamp ${timestamp} on chain ${chain}`);
}

export async function getTimestampBySolanaSlot(slot: number) {
const { timestamp: latestTimestamp, number } = await getLatestBlock("solana");

const timestamp = latestTimestamp - ((number - slot) * 400) / 1000;

return timestamp;
}

0 comments on commit 81501c8

Please sign in to comment.