From 78e0b669b2340cae121a50fd5b509336579af589 Mon Sep 17 00:00:00 2001 From: Dong-Ha Kim Date: Tue, 8 Oct 2024 15:55:56 +0200 Subject: [PATCH] fix: use on-chain current time for `fillDeadline` calc (#45) * fix: use on-chain current time for `fillDeadline` calc * chore: add changeset --- .changeset/unlucky-cups-serve.md | 5 +++ packages/sdk/src/actions/simulateDepositTx.ts | 36 +++++++++++++------ 2 files changed, 30 insertions(+), 11 deletions(-) create mode 100644 .changeset/unlucky-cups-serve.md diff --git a/.changeset/unlucky-cups-serve.md b/.changeset/unlucky-cups-serve.md new file mode 100644 index 0000000..4296dab --- /dev/null +++ b/.changeset/unlucky-cups-serve.md @@ -0,0 +1,5 @@ +--- +"@across-protocol/app-sdk": patch +--- + +fix `fillDeadline` calculation diff --git a/packages/sdk/src/actions/simulateDepositTx.ts b/packages/sdk/src/actions/simulateDepositTx.ts index 49e58ad..ebbe7c8 100644 --- a/packages/sdk/src/actions/simulateDepositTx.ts +++ b/packages/sdk/src/actions/simulateDepositTx.ts @@ -6,11 +6,7 @@ import { zeroAddress, } from "viem"; import { Quote } from "./getQuote"; -import { - getCurrentTimeSeconds, - getIntegratorDataSuffix, - LoggerT, -} from "../utils"; +import { getIntegratorDataSuffix, LoggerT } from "../utils"; import { spokePoolAbi } from "../abis/SpokePool"; export type SimulateDepositTxParams = { @@ -62,12 +58,30 @@ export async function simulateDepositTx(params: SimulateDepositTxParams) { let fillDeadline = _fillDeadline; if (!fillDeadline) { - const fillDeadlineBuffer = await publicClient.readContract({ - address: spokePoolAddress, - abi: spokePoolAbi, - functionName: "fillDeadlineBuffer", - }); - fillDeadline = getCurrentTimeSeconds() - 60 + fillDeadlineBuffer; + const [fillDeadlineBufferResult, getCurrentTimeResult] = + await publicClient.multicall({ + contracts: [ + { + address: spokePoolAddress, + abi: spokePoolAbi, + functionName: "fillDeadlineBuffer", + }, + { + address: spokePoolAddress, + abi: spokePoolAbi, + functionName: "getCurrentTime", + }, + ], + }); + if (fillDeadlineBufferResult.error || getCurrentTimeResult.error) { + const error = + fillDeadlineBufferResult.error || getCurrentTimeResult.error; + throw new Error( + `Failed to fetch 'fillDeadlineBuffer' or 'getCurrentTime': ${error}`, + ); + } + fillDeadline = + Number(getCurrentTimeResult.result) + fillDeadlineBufferResult.result; } const useExclusiveRelayer =