Skip to content

Swaps and SeqDEX

Live on testnet For developers Simplifies the whitepaper, Principles 5 and 7

SeqDEX is the exchange layer of Sequentia: an order book and a set of settlement methods in which no component ever takes custody of a user’s funds. Settlement is always one of three things: an atomic transaction, a pair of hashed-timelock contracts, or a covenant spend enforced by consensus.

The pieces

Piece What it does Holds funds or keys?
Relay (seqobd) Stores signed offers, serves the book over REST and WebSocket, matches crossing orders, carries encrypted messages between the two parties No
Covenant orders An order that rests on the chain itself: one output whose script enforces the price The chain enforces it
Settler (seqob-settler) Settles two resting covenant orders against each other No: it has no keys
Cross-chain engine Runs swaps between an asset on Sequentia and BTC on Bitcoin No
Your wallet Signs. The site has no wallet of its own Yes, yours

The site drives everything through the wallet you connect: the web wallet in another tab, Ambra on a phone paired by QR code, the Ambra browser extension, or your own node through sequentia-connect. Each one asks you before anything is signed.

Two kinds of order

Signed intents. An order is a signed statement of price, size and expiry. It names no specific coins and is not a pre-signed transaction. When it crosses with another, the two parties settle directly, peer to peer, with the relay passing end-to-end-encrypted messages it cannot read.

Covenant orders. The maker funds one taproot output whose script enforces the price. Anyone can fill it, in whole or in part, while the maker is offline, and whatever is left re-rests automatically. The maker’s coins come back through a reclaim path once the order’s time has run out.

Because the wallets write an encrypted note of each order into its funding transaction, an order can be rebuilt from the recovery phrase alone on another device.

How each kind of trade settles

TradeMethodWaits for
Asset for asset, on SequentiaOne atomic transaction that pays both sides or neitherOne Sequentia block
Asset for BTC, on-chainA pair of hashed-timelock contracts, one on each chainBitcoin confirmations
Asset for BTC, over LightningLightning payments on both sides, or Lightning on one and on-chain on the otherSeconds Experimental
Confidential A blinded atomic swap, Sequentia only One Sequentia block

A trade is reported as final once its block is certified and its Bitcoin anchor is buried, and is shown as undone if its block leaves the chain.

What anchoring contributes

Between unrelated chains, a hashed-timelock swap needs long timeouts on both sides, to survive either chain reorganising alone. Sequentia reorganises only when Bitcoin does, so the two legs share one reorganisation risk and the timeouts can be short. See Bitcoin anchoring.

Coming: release on proof of a Bitcoin payment

Coming Written and tested on a development branch. Not merged, not active on the testnet. The wallets and SeqDEX use hashed-timelock swaps today.

The gap it closes

Anchoring ensures that if a bitcoin payment is reorganised out of Bitcoin, the Sequentia side of the swap is reorganised out with it. What it cannot decide alone is what happens next: the Sequentia transaction returns to the waiting pool and can be mined again, while a dishonest buyer could double-spend the bitcoin instead of letting the payment be mined again.

The rule

A Sequentia output can be locked so that it opens only for a spender who proves that a given Bitcoin payment is in Bitcoin’s chain: an output paying a named script at least a named amount, in a Bitcoin block within the heights the lock names. Every validating node checks the proof against the chain’s own Bitcoin anchors.

  • The claim is valid only in a block whose anchor chain contains the payment. If the payment leaves Bitcoin’s history, the claim leaves Sequentia’s with it and can never be mined again.
  • If the payment is mined again in another Bitcoin block, anyone can attach a fresh proof to the same claim.
  • A refund path opens for the seller if the payment does not arrive in time.

What changes for a swap

The bitcoin side becomes an ordinary payment. No hash lock, no secret, no script a Bitcoin wallet has to support: the buyer can pay from any wallet.

Hashed-timelock swap (today) Payment-proof swap (coming)
Bitcoin side A special contract output A plain payment to an address
Buyer’s Bitcoin wallet must support The contract Nothing
Safety after a Bitcoin reorganisation Relies on the buyer not double-spending Enforced by consensus
Sequentia side Hash lock and timeout Proof check and refund path
SpecificationThe three opcodes

The rule is implemented as three tapscript opcodes that read two kinds of record a spender places in an input’s witness.

Opcode Byte Reads
OP_INSPECTBTCPAYMENT 0xe5 A payment proof: a Bitcoin transaction, the block it is in, and the merkle paths from the transaction and from the block’s coinbase to the block’s merkle root
OP_INSPECTBTCTX 0xe6 An output, an input or the payment id of the proven Bitcoin transaction
OP_CHECKANCHORHEIGHTVERIFY 0xe7 An anchor floor: a Bitcoin height the chain’s anchor must have reached

The division of work mirrors OP_CHECKLOCKTIMEVERIFY: the script compares the record with constants written in the script, and the node compares the record with the block and its anchors, outside the script. This keeps every script a pure function of the transaction and its spent outputs, which matters because script results are cached and checked in parallel.

A payment proof is valid in a block only if headers it carries link its Bitcoin block to an anchor that block or one of its ancestors recorded. The records are covered by the block’s witness commitment but by no signature, so anyone can replace a proof with a fresher one without invalidating the claim.

The opcodes occupy bytes that are OP_SUCCESS today, so the change only tightens the rules. It is height-gated, and on the running testnet it will activate at an announced height with a coordinated upgrade of every node. It also depends on a signing rule for the committee.

Specification: bitcoin-payment-proof.md on the feature/bitcoin-payment-proof branch.

Specification 11What a user will see

In a wallet’s default mode, buying an asset with bitcoin is a payment with a wait, and selling one is choosing an amount. No protocol, lock or proof is named.

A buyer’s wallet waits for a number of Bitcoin blocks on top of the seller’s lock before paying, scaled to the price: none for small amounts, up to five blocks for one bitcoin or more. This is the buyer’s own policy, not something the rule’s safety depends on.

Hash-locked swaps over Lightning are unaffected: they settle without waiting for a Bitcoin confirmation.

The same rule would also serve resting sell orders filled by a plain payment, token sales for bitcoin, and loans repaid in bitcoin. None of those is built.

Building on SeqDEX

  • Read the market. The relay serves each pair’s book and its trade log over REST and WebSocket. The web wallet and the site show the same numbers because they read the same log.
  • Connect a wallet. A site talks to the user’s wallet through the window.sequentia provider, documented in PROVIDER.md. The same protocol is spoken by the extension and by sequentia-connect.
  • Provide liquidity. The repository includes a quoting daemon for market makers, forked from the TDEX stack, for same-chain swaps.

Read further