From b029164c3aa0053c159022519ff7ad402c00c3c7 Mon Sep 17 00:00:00 2001 From: doomsower <12031673+doomsower@users.noreply.github.com> Date: Mon, 22 Jul 2024 13:08:56 -0500 Subject: [PATCH] fix: bring back historical timestamp --- src/services/RedstoneServiceV3.ts | 46 +++++++++++++++---------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/services/RedstoneServiceV3.ts b/src/services/RedstoneServiceV3.ts index cf51b31..67d9888 100644 --- a/src/services/RedstoneServiceV3.ts +++ b/src/services/RedstoneServiceV3.ts @@ -70,28 +70,28 @@ export class RedstoneServiceV3 { public async launch(): Promise { 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( @@ -246,7 +246,7 @@ export class RedstoneServiceV3 { const dataPayload = await new DataServiceWrapper({ dataServiceId, - dataFeeds: [dataFeedId], + dataPackagesIds: [dataFeedId], uniqueSignersCount, historicalTimestamp: CACHE_BLOCKLIST.has(dataFeedId) ? undefined