Skip to content

Commit

Permalink
fix: use on-chain current time for fillDeadline calc (#45)
Browse files Browse the repository at this point in the history
* fix: use on-chain current time for `fillDeadline` calc

* chore: add changeset
  • Loading branch information
dohaki authored Oct 8, 2024
1 parent a086a2f commit 78e0b66
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/unlucky-cups-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@across-protocol/app-sdk": patch
---

fix `fillDeadline` calculation
36 changes: 25 additions & 11 deletions packages/sdk/src/actions/simulateDepositTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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 =
Expand Down

0 comments on commit 78e0b66

Please sign in to comment.