Skip to content

Commit

Permalink
fix: bring back historical timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
doomsower committed Jul 22, 2024
1 parent edf7cf3 commit b029164
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions src/services/RedstoneServiceV3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,28 +70,28 @@ export class RedstoneServiceV3 {
public async launch(): Promise<void> {
this.liquidationPreviewUpdates = this.liquidationPreviewUpdates.bind(this);

// if (this.config.optimistic) {
// const block = await this.client.pub.getBlock({
// blockNumber: this.client.anvilForkBlock,
// });
// if (!block) {
// throw new Error(`cannot get latest block`);
// }
// // https://github.com/redstone-finance/redstone-oracles-monorepo/blob/c7569a8eb7da1d3ad6209dfcf59c7ca508ea947b/packages/sdk/src/request-data-packages.ts#L82
// // we round the timestamp to full minutes for being compatible with
// // oracle-nodes, which usually work with rounded 10s and 60s intervals
// //
// // Also, when forking anvil->anvil (when running on testnets) block.timestamp can be in future because min ts for block is 1 seconds,
// // and scripts can take dozens of blocks (hundreds for faucet). So we take min value;
// const now = new Date().getTime();
// const anvilTs = 10 * Math.floor(Number(block.timestamp) / 10) * 1000;
// const fromNowTs = 60_000 * Math.floor(now / 60_000 - 60_000);
// this.#optimisticTimestamp = Math.min(anvilTs, fromNowTs);
// const delta = Math.ceil((now - this.#optimisticTimestamp) / 1000);
// this.log.info(
// `will use optimistic timestamp: ${this.#optimisticTimestamp} (delta: ${delta}s)`,
// );
// }
if (this.config.optimistic) {
const block = await this.client.pub.getBlock({
blockNumber: this.client.anvilForkBlock,
});
if (!block) {
throw new Error("cannot get latest block");
}
// https://github.com/redstone-finance/redstone-oracles-monorepo/blob/c7569a8eb7da1d3ad6209dfcf59c7ca508ea947b/packages/sdk/src/request-data-packages.ts#L82
// we round the timestamp to full minutes for being compatible with
// oracle-nodes, which usually work with rounded 10s and 60s intervals
//
// Also, when forking anvil->anvil (when running on testnets) block.timestamp can be in future because min ts for block is 1 seconds,
// and scripts can take dozens of blocks (hundreds for faucet). So we take min value;
const now = new Date().getTime();
const anvilTs = 10 * Math.floor(Number(block.timestamp) / 10) * 1000;
const fromNowTs = 10_000 * Math.floor(now / 10_000 - 10_000);
this.#optimisticTimestamp = Math.min(anvilTs, fromNowTs);
const delta = Math.ceil((now - this.#optimisticTimestamp) / 1000);
this.log.info(
`will use optimistic timestamp: ${this.#optimisticTimestamp} (delta: ${delta}s)`,
);
}
}

public async updatesForTokens(
Expand Down Expand Up @@ -246,7 +246,7 @@ export class RedstoneServiceV3 {

const dataPayload = await new DataServiceWrapper({
dataServiceId,
dataFeeds: [dataFeedId],
dataPackagesIds: [dataFeedId],
uniqueSignersCount,
historicalTimestamp: CACHE_BLOCKLIST.has(dataFeedId)
? undefined
Expand Down

0 comments on commit b029164

Please sign in to comment.