Settlement of spot order trades on Spark-Miden-v1 is achieved through the use of partially fillable swap notes (SWAPp). SWAPp notes have the following characteristics:
- Can function as a regular SWAP note (as defined in the Miden-base repository).
- Allow a user wallet to partially consume them, as long as the consuming wallet has the necessary SWAPp add-on procedures.
- Are reclaimable by the creator.
Partial consumption means that a user who does not have sufficient liquidity to completely fill the SWAPp note can still execute their trade at the specified ratio of requested to offered tokens in the SWAPp note.
When partially filling a SWAPp note with liquidity L, the remaining liquidity L1 in the SWAPp note is added to the new outputted SWAPp note.
The process of partially filling a SWAPp note can continue N times until the liquidity in the SWAPp note is completely exhausted.
In the context of Miden, when describing the stack, capitalized words represent four stack elements. Four stack elements are referred to as words.
Inputs: [REQUESTED_ASSET, SWAP_TAG, SWAP_COUNT, creator_id]
The payback recipient is the RECIPIENT digest of the P2ID note.
The RECIPIENT digest is defined as:
hash(hash(hash(serial_num, [0; 4]), script_hash), input_hash)
The REQUESTED_ASSET is defined as:
[faucet_id, 0, 0, amount]
The SWAPp note is reclaimable by the initial creator of the SWAPp note. After each partial consumption of the SWAPp note, the sender of the note changes. However, since the PAYBACK_RECIPIENT input of the SWAPp note does not change, we can compute the PAYBACK_RECIPIENT hash inside the SWAPp note using the account ID of the currently executing account. If the PAYBACK_RECIPIENT hash matches the SWAPp note input for the PAYBACK_RECIPIENT, this means that the currently executing account is the initial creator.
This is achieved by calling the account::get_id procedure and then computing the PAYBACK_RECIPIENT digest inside the note.
When partially consuming a SWAPp note, two notes are outputted:
- A P2ID note with the requested asset for the SWAPp note creator.
- A new SWAPp note with L1 liquidity of the asset being sold.
cargo test --test mock_integration
cargo masm-fmt "src/**/*.masm"
cargo install masm-formatter
cargo build --release
./target/release/cli init
./target/release/cli/setup
./target/release/cli query <BTC/ETH tag>
./target/release/cli query <ETH/BTC tag>
./target/release/cli login
./target/release/cli order <loggedInId> <faucet_id_0> 5 <faucet_id_1> 5