Skip to main content
The swap contract locks a deposit within Arkade until another party pays the program the funder named. One party, the funder, locks the deposit. Any other party unlocks it by paying receiveProgram at least wantAmount. The contract comes in two programs, one for each thing that payment can deliver: Copy the contract without changes. A change to the code, or to the order of the functions, changes the address.
@arkade-os/swap and the reference solver don’t use this contract yet. They use the contract that Asset Swaps describes. The reference solver can’t fill a deposit at an address derived from the source below, so swap with the client in Exchange Assets until this contract ships.

Source

swap_want_asset.ark
swap_want_btc.ark
An offer published with noExit: true has no exit leaf. Delete the exit function and the exitDelay parameter to compile that contract. It derives a different address. The funder then has no path to take the deposit back.

Constructor

The locked amount is not a parameter. The contract does not inspect what the deposit holds, so either program can lock BTC, an asset, or an asset for an asset.

Functions

covenant
Anyone unlocks the deposit by paying receiveProgram. No signature is needed.
  • The output at the deposit’s index must pay receiveProgram.
  • That output must carry at least wantAmount of the named asset, or at least wantAmount sats.
  • The deposit must hold less than wantAmount, so it cannot be its own payment.
  • Several deposits can be unlocked in one transaction: output i pays the receiveProgram of input i. One output cannot unlock two deposits.
  • Nothing else is checked. The contract does not say where the deposit goes.
  • There is no deadline.
tapscript
The funder takes the deposit back alone, after exitDelay.
  • funderKey signs. The destination is free.
  • It is the funder’s only way to recover the deposit.
There is no cancel path. Until someone pays receiveProgram, the funder’s only way back is exit.

Fund the Swap

The funder builds the address with their own funderKey, then locks coins there. A direct send to the address is a different output. It is not this locked deposit.

Unlock

The paying party spends the deposit with fulfill and brings its own coins in the same transaction. Input i is the locked deposit, and output i pays its receiveProgram. With one deposit, i is 0.

Exit

The funder spends the deposit with exit once exitDelay has passed, to any address they sign for. Function arguments: funderSig, the funder’s signature for funderKey.