Skip to content

Commit 058e02b

Browse files
committed
fix: allow passing of optimistic timestamp from outside
1 parent ac67b39 commit 058e02b

File tree

4 files changed

+30
-14
lines changed

4 files changed

+30
-14
lines changed

.gitignore

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1+
!.yarn/patches
2+
!.yarn/plugins
3+
!.yarn/releases
4+
!.yarn/sdks
5+
!.yarn/versions
6+
.DS_Store
7+
.env
18
.history/
29
.idea/
3-
node_modules/
4-
cache/
5-
build/
6-
typechain/
10+
.pnp.*
11+
.yarn/*
712
artifacts/
8-
keys/*
13+
build/
14+
cache/
915
coverage*
10-
.env
11-
.DS_Store
16+
keys/*
17+
node_modules/
18+
typechain/
1219

1320
/.env.local
1421
/logs/*.json

src/config/env.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const envConfigMapping: Record<keyof ConfigSchema, string | string[]> = {
1616
minBalance: "MIN_BALANCE",
1717
oneInchApiKey: "ONE_INCH_API_KEY",
1818
optimistic: "OPTIMISTIC",
19+
optimisticTimestamp: "OPTIMISTIC_TIMESTAMP",
1920
outDir: "OUT_DIR",
2021
outEndpoint: "OUT_ENDPOINT",
2122
outHeaders: "OUT_HEADERS",

src/config/schema.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ export const ConfigSchema = z.object({
7070
* Enable optimistic liquidations
7171
*/
7272
optimistic: booleanLike.pipe(z.boolean().optional()),
73+
/**
74+
* Optimistic timestamp to pass from external runner, in ms
75+
*/
76+
optimisticTimestamp: z.number().int().positive().nullish(),
7377
/**
7478
* Override redstone gateways
7579
*/

src/services/RedstoneServiceV3.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,17 @@ export class RedstoneServiceV3 {
101101
// Also, when forking anvil->anvil (when running on testnets) block.timestamp can be in future because min ts for block is 1 seconds,
102102
// and scripts can take dozens of blocks (hundreds for faucet). So we take min value;
103103
const nowMs = new Date().getTime();
104-
const redstoneIntervalMs = 60_000;
105-
const anvilTsMs =
106-
redstoneIntervalMs *
107-
Math.floor((Number(block.timestamp) * 1000) / redstoneIntervalMs);
108-
const fromNowTsMs =
109-
redstoneIntervalMs * Math.floor(nowMs / redstoneIntervalMs - 1);
110-
this.#optimisticTimestamp = Math.min(anvilTsMs, fromNowTsMs);
104+
if (this.config.optimisticTimestamp) {
105+
this.#optimisticTimestamp = this.config.optimisticTimestamp;
106+
} else {
107+
const redstoneIntervalMs = 60_000;
108+
const anvilTsMs =
109+
redstoneIntervalMs *
110+
Math.floor((Number(block.timestamp) * 1000) / redstoneIntervalMs);
111+
const fromNowTsMs =
112+
redstoneIntervalMs * Math.floor(nowMs / redstoneIntervalMs - 1);
113+
this.#optimisticTimestamp = Math.min(anvilTsMs, fromNowTsMs);
114+
}
111115
const deltaS = Math.floor((nowMs - this.#optimisticTimestamp) / 1000);
112116
this.logger.info(
113117
{ tag: "timing" },

0 commit comments

Comments
 (0)