Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: sdk deadlines #1221

Merged
merged 3 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions packages/sdk-router/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ import {
SynapseCCTPRouterQuery,
SynapseRouterQuery,
} from './utils/types'
import { TEN_MINUTES, ONE_WEEK, calculateDeadline } from './utils/deadlines'
import { SynapseCCTPRouter } from './SynapseCCTPRouter'
const ONE_WEEK_DEADLINE = BigNumber.from(Math.floor(Date.now() / 1000) + 604800) // one week in the future
const TEN_MIN_DEADLINE = BigNumber.from(Math.floor(Date.now() / 1000) + 600) // ten minutes in the future

type SynapseRouters = {
[key: number]: SynapseRouter
Expand Down Expand Up @@ -311,7 +310,7 @@ class SynapseSDK {
} else {
formattedOriginQuery = { ...(originQuery as SynapseRouterQuery) }
}
formattedOriginQuery.deadline = deadline ?? TEN_MIN_DEADLINE
formattedOriginQuery.deadline = deadline ?? calculateDeadline(TEN_MINUTES)

let isSwap = false
if ((destQuery as SynapseCCTPRouterQuery).routerAdapter) {
Expand All @@ -320,7 +319,7 @@ class SynapseSDK {
} else {
formattedDestQuery = { ...(destQuery as SynapseRouterQuery) }
}
formattedDestQuery.deadline = ONE_WEEK_DEADLINE
formattedDestQuery.deadline = calculateDeadline(ONE_WEEK)

let feeAmount!: BigNumber
let feeConfig!: FeeConfig
Expand Down Expand Up @@ -670,7 +669,7 @@ class SynapseSDK {
}

const query = { ...(rawQuery as SynapseRouterQuery) }
query.deadline = deadline ?? TEN_MIN_DEADLINE
query.deadline = deadline ?? calculateDeadline(TEN_MINUTES)
const maxAmountOut = query.minAmountOut

return {
Expand Down
9 changes: 9 additions & 0 deletions packages/sdk-router/src/utils/deadlines.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { BigNumber } from '@ethersproject/bignumber'

// Default periods for deadlines on origin and destination chains respectively, in seconds
export const TEN_MINUTES = 10 * 60
export const ONE_WEEK = 7 * 24 * 60 * 60

export const calculateDeadline = (seconds: number) => {
return BigNumber.from(Math.floor(Date.now() / 1000) + seconds)
}
Loading