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.
Source
swap_want_asset.ark
swap_want_btc.ark
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
wantAmountof the named asset, or at leastwantAmountsats. - The deposit must hold less than
wantAmount, so it cannot be its own payment. - Several deposits can be unlocked in one transaction: output
ipays thereceiveProgramof inputi. 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.funderKeysigns. The destination is free.- It is the funder’s only way to recover the deposit.
Fund the Swap
The funder builds the address with their ownfunderKey, 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 withfulfill 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 withexit once exitDelay has passed, to any address they sign for.
Function arguments: funderSig, the funder’s signature for funderKey.