Skip to content

Commit

Permalink
Use different default periods for modules
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiTimesChi committed Dec 27, 2023
1 parent 686e00a commit 29943be
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
29 changes: 18 additions & 11 deletions packages/sdk-router/src/module/synapseModuleSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ import invariant from 'tiny-invariant'
import { BigintIsh } from '../constants'
import { BridgeQuote, BridgeRoute, FeeConfig } from './types'
import { SynapseModule } from './synapseModule'
import {
ONE_WEEK,
TEN_MINUTES,
applyOptionalDeadline,
} from '../utils/deadlines'
import { applyOptionalDeadline } from '../utils/deadlines'

export abstract class SynapseModuleSet {
abstract readonly bridgeModuleName: string
Expand Down Expand Up @@ -123,17 +119,29 @@ export abstract class SynapseModuleSet {
feeConfig: FeeConfig
}>

/**
* Returns the default deadline periods for this bridge module.
*
* @returns The default deadline periods.
*/
abstract getDefaultPeriods(): {
originPeriod: number
destPeriod: number
}

/**
* Finalizes the bridge route by getting fee data and setting default deadlines.
*
* @param destChainId - The ID of the destination chain.
* @param bridgeRoute - Bridge route to finalize.
* @param deadline - The deadline to use on the origin chain (default 10 mins).
* @param originDeadline - The deadline to use on the origin chain (default depends on the module).
* @param destDeadline - The deadline to use on the destination chain (default depends on the module).
* @returns The finalized quote with fee data and deadlines.
*/
async finalizeBridgeRoute(
bridgeRoute: BridgeRoute,
deadline?: BigNumber
originDeadline?: BigNumber,
destDeadline?: BigNumber
): Promise<BridgeQuote> {
// Check that route is supported on both chains
const originModule = this.getExistingModule(bridgeRoute.originChainId)
Expand All @@ -143,10 +151,9 @@ export abstract class SynapseModuleSet {
'Invalid bridge module name'
)
const { originQuery, destQuery } = bridgeRoute
// Set origin deadline to 10 mins if not provided
originQuery.deadline = applyOptionalDeadline(deadline, TEN_MINUTES)
// Destination deadline is always 1 week
destQuery.deadline = applyOptionalDeadline(undefined, ONE_WEEK)
const { originPeriod, destPeriod } = this.getDefaultPeriods()
originQuery.deadline = applyOptionalDeadline(originDeadline, originPeriod)
destQuery.deadline = applyOptionalDeadline(destDeadline, destPeriod)
const { feeAmount, feeConfig } = await this.getFeeData(bridgeRoute)
return {
feeAmount,
Expand Down
15 changes: 15 additions & 0 deletions packages/sdk-router/src/router/routerSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
SynapseModuleSet,
} from '../module'
import { hasComplexBridgeAction } from '../module/query'
import { ONE_WEEK, TEN_MINUTES } from '../utils/deadlines'

export type ChainProvider = {
chainId: number
Expand Down Expand Up @@ -159,4 +160,18 @@ export abstract class RouterSet extends SynapseModuleSet {
hasComplexBridgeAction(bridgeRoute.destQuery)
)
}

/**
* @inheritdoc SynapseModuleSet.getDefaultPeriods
*/
getDefaultPeriods(): {
originPeriod: number
destPeriod: number
} {
// Use the same default periods for SynapseBridge and SynapseCCTP modules
return {
originPeriod: TEN_MINUTES,
destPeriod: ONE_WEEK,
}
}
}

0 comments on commit 29943be

Please sign in to comment.