Skip to main content

TimeLocks

Defines the duration of each stage of a cross-chain swap for both source and destination chains.

Stage Layout

Source Chain:
| finality lock | private withdrawal | public withdrawal | private cancellation | public cancellation |
^deployedAt
Destination Chain:
| finality lock | private withdrawal | public withdrawal | private cancellation |
^deployedAt

Constructor

new TimeLocks(
  srcWithdrawal: bigint,
  srcPublicWithdrawal: bigint,
  srcCancellation: bigint,
  srcPublicCancellation: bigint,
  dstWithdrawal: bigint,
  dstPublicWithdrawal: bigint,
  dstCancellation: bigint,
  deployedAt: bigint
)
Use static factory methods (new, fromDurations, fromBigInt) instead of calling the constructor directly.

Static Properties

DEFAULT_RESCUE_DELAY
bigint
Default rescue delay of 604800 seconds (7 days)
Web3Type
string
Returns “uint256” - the Solidity type for time locks

Static Methods

new

Create TimeLocks with absolute delays from deployedAt.
TimeLocks.new(params: {
  srcWithdrawal: bigint
  srcPublicWithdrawal: bigint
  srcCancellation: bigint
  srcPublicCancellation: bigint
  dstWithdrawal: bigint
  dstPublicWithdrawal: bigint
  dstCancellation: bigint
}): TimeLocks
srcWithdrawal
bigint
required
Source chain: Delay from deployedAt when finality lock ends and private withdrawal starts
srcPublicWithdrawal
bigint
required
Source chain: Delay from deployedAt when private withdrawal ends and public withdrawal starts
srcCancellation
bigint
required
Source chain: Delay from deployedAt when public withdrawal ends and private cancellation starts
srcPublicCancellation
bigint
required
Source chain: Delay from deployedAt when private cancellation ends and public cancellation starts
dstWithdrawal
bigint
required
Destination chain: Delay from deployedAt when finality lock ends and private withdrawal starts
dstPublicWithdrawal
bigint
required
Destination chain: Delay from deployedAt when private withdrawal ends and public withdrawal starts
dstCancellation
bigint
required
Destination chain: Delay from deployedAt when public withdrawal ends and private cancellation starts

fromDurations

Create TimeLocks from stage durations.
TimeLocks.fromDurations(durations: {
  srcFinalityLock: bigint
  srcPrivateWithdrawal: bigint
  srcPublicWithdrawal: bigint
  srcPrivateCancellation: bigint
  dstFinalityLock: bigint
  dstPrivateWithdrawal: bigint
  dstPublicWithdrawal: bigint
}): TimeLocks
srcFinalityLock
bigint
required
Duration of source chain finality lock stage
srcPrivateWithdrawal
bigint
required
Duration of source chain private withdrawal stage
srcPublicWithdrawal
bigint
required
Duration of source chain public withdrawal stage
srcPrivateCancellation
bigint
required
Duration of source chain private cancellation stage
dstFinalityLock
bigint
required
Duration of destination chain finality lock stage
dstPrivateWithdrawal
bigint
required
Duration of destination chain private withdrawal stage
dstPublicWithdrawal
bigint
required
Duration of destination chain public withdrawal stage
Example:
const timeLocks = TimeLocks.fromDurations({
  srcFinalityLock: 300n,      // 5 minutes
  srcPrivateWithdrawal: 600n,  // 10 minutes
  srcPublicWithdrawal: 1800n,  // 30 minutes
  srcPrivateCancellation: 3600n, // 1 hour
  dstFinalityLock: 300n,
  dstPrivateWithdrawal: 600n,
  dstPublicWithdrawal: 1800n
})

fromBigInt

Decode TimeLocks from a packed uint256 value.
TimeLocks.fromBigInt(val: bigint): TimeLocks
val
bigint
required
Packed 256-bit value containing all timelock parameters

Instance Properties

deployedAt
bigint
Timestamp when the escrow was deployed

Instance Methods

build

Encode TimeLocks to a packed uint256 value.
build(): bigint
Returns: 256-bit packed representation of all timelock parameters

setDeployedAt

Set the deployment timestamp.
setDeployedAt(time: bigint): this
time
bigint
required
Unix timestamp of deployment
Returns: This TimeLocks instance (for chaining)

toSrcTimeLocks

Extract source chain time locks.
toSrcTimeLocks(deployedAt?: bigint): SrcTimeLocks
deployedAt
bigint
Optional override for deployment timestamp (defaults to this.deployedAt)
Returns: SrcTimeLocks instance with source chain timelock configuration

toDstTimeLocks

Extract destination chain time locks.
toDstTimeLocks(deployedAt?: bigint): DstTimeLocks
deployedAt
bigint
Optional override for deployment timestamp (defaults to this.deployedAt)
Returns: DstTimeLocks instance with destination chain timelock configuration

SrcTimeLocks

Source chain-specific time lock utilities for checking swap stages.

Stage Enum

enum SrcStage {
  FinalityLock,
  PrivateWithdrawal,
  PublicWithdrawal,
  PrivateCancellation,
  PublicCancellation
}

Static Methods

new

SrcTimeLocks.new(params: {
  deployedAt: bigint
  withdrawal: bigint
  publicWithdrawal: bigint
  cancellation: bigint
  publicCancellation: bigint
}): SrcTimeLocks

Instance Properties

deployedAt
bigint
Escrow deployment timestamp
privateWithdrawal
bigint
Timestamp when private withdrawal starts
publicWithdrawal
bigint
Timestamp when public withdrawal starts
privateCancellation
bigint
Timestamp when private cancellation starts
publicCancellation
bigint
Timestamp when public cancellation starts

Instance Methods

isFinalityLock

Check if the given time is in the finality lock stage.
isFinalityLock(time?: bigint): boolean
time
bigint
Unix timestamp to check (defaults to current time)

isPrivateWithdrawal

Check if the given time is in the private withdrawal stage.
isPrivateWithdrawal(time?: bigint): boolean

isPublicWithdrawal

Check if the given time is in the public withdrawal stage.
isPublicWithdrawal(time?: bigint): boolean

isPrivateCancellation

Check if the given time is in the private cancellation stage.
isPrivateCancellation(time?: bigint): boolean

isPublicCancellation

Check if the given time is in the public cancellation stage.
isPublicCancellation(time?: bigint): boolean

getStage

Get the current stage at a given time.
getStage(time?: bigint): SrcStage
time
bigint
Unix timestamp to check (defaults to current time)
Returns: Current SrcStage

equal

Check if this equals another SrcTimeLocks.
equal(other: SrcTimeLocks): boolean

DstTimeLocks

Destination chain-specific time lock utilities for checking swap stages.

Stage Enum

enum DstStage {
  FinalityLock,
  PrivateWithdrawal,
  PublicWithdrawal,
  PrivateCancellation
}

Static Methods

new

DstTimeLocks.new(params: {
  deployedAt: bigint
  withdrawal: bigint
  publicWithdrawal: bigint
  cancellation: bigint
}): DstTimeLocks

Instance Properties

deployedAt
bigint
Escrow deployment timestamp
privateWithdrawal
bigint
Timestamp when private withdrawal starts
publicWithdrawal
bigint
Timestamp when public withdrawal starts
privateCancellation
bigint
Timestamp when private cancellation starts

Instance Methods

isFinalityLock

Check if the given time is in the finality lock stage.
isFinalityLock(time?: bigint): boolean
time
bigint
Unix timestamp to check (defaults to current time)

isPrivateWithdrawal

Check if the given time is in the private withdrawal stage.
isPrivateWithdrawal(time?: bigint): boolean

isPublicWithdrawal

Check if the given time is in the public withdrawal stage.
isPublicWithdrawal(time?: bigint): boolean

isPrivateCancellation

Check if the given time is in the private cancellation stage.
isPrivateCancellation(time?: bigint): boolean

getStage

Get the current stage at a given time.
getStage(time?: bigint): DstStage
time
bigint
Unix timestamp to check (defaults to current time)
Returns: Current DstStage

equal

Check if this equals another DstTimeLocks.
equal(other: DstTimeLocks): boolean

Build docs developers (and LLMs) love