@somnia-chain/markets-sdk


@somnia-chain/markets-sdk / index / ExchangeBridge

Interface: ExchangeBridge

Defined in: packages/sdk/src/unified/bridge.ts:127

The bridge, reached as exchange.bridge: plan and execute transfers between the exchange's own chains through the account's executors.

Methods

plan()

plan(params): BridgeTransfer

Defined in: packages/sdk/src/unified/bridge.ts:133

Plan a transfer between two configured chains — pure, nothing sent. Throws NotConfiguredError when either chain is not one of the exchange's, InvalidInputError when the token has no route between them.

Parameters

params

ExchangeBridgeParams

Returns

BridgeTransfer


transfer()

transfer(params, options?): Promise<ExchangeBridgeResult>

Defined in: packages/sdk/src/unified/bridge.ts:163

Plan and execute: the origin legs go through the origin chain's executor (a safe packs approval and bridge into one transaction), then delivery of that one message is awaited on the destination engine's socket.

Details

The message id comes from the origin receipt: the origin Mailbox's Dispatch whose sender is the origin router and whose destination is the target chain, paired with the DispatchId after it. The wait resolves only on the destination Mailbox's ProcessId for that id, and reads the router's ReceivedTransferRemote from the same transaction. A delivery to the same recipient from another message does not count. The wait also asks the destination Mailbox delivered(messageId), so a message that landed before the watch opened still resolves. That read only covers the window before the watch: when it fails, the watch or the timeout decides.

Gotchas

  • Throws NotConfiguredError - a chain outside the exchange, or no executor for the origin chain.
  • Throws SignerRequiredError - the exchange has no account to bridge for.
  • Throws InvalidInputError - the token has no route between the two chains, the amount is not positive, or the executor refused the call list.
  • Throws BridgeLiquidityError - a native route's destination router holds less than the amount. Nothing was sent.
  • Throws RpcError - operation names the step. getBalance: the destination router's balance read failed, and nothing was sent. transferRemote: the origin transaction was sent and mined as reverted. bridge message id: the origin transaction was mined, but its receipt holds no single Mailbox dispatch from the origin router to the destination. The funds may be in flight. watch bridge delivery: the destination watch failed after the origin leg was mined, and the funds may be in flight; or the delivery transaction holds no ReceivedTransferRemote from the router. waitForTransactionReceipt: the message was processed, but the delivery receipt read failed. Any other operation comes from the executor's send, and the transaction may have been sent.
  • Throws ContractRevertError - an origin leg reverted, in simulation or on chain.
  • Resolves with delivered: false and the messageId when the message was not processed within the timeout, or when the exchange closes after this call started. The transfer may still land. It is not undone.

Parameters

params

ExchangeBridgeParams

options?

ExchangeBridgeTransferOptions

Returns

Promise<ExchangeBridgeResult>