Swap Transaction Structure
A swap operation might be involved in 3 transactions:
- Traders submit swap request
- Aggregators match swap request with pool to help traders to complete swap
- Traders cancel swap request
1. Traders submit swap request#
2. Deal-miners match swap request with pool cells#
After traders submit the swap request, Aggregators will help traders to complete the swap. Motivated by the Tip fee claimed in the swap request cell (tip fee currently is 0), aggregators will continually retrieve the swap request cells and the pool cells on chain and then compete to match them off-chain and submit matching transactions. We open sourced a simple aggregators software for basic use. Information on how to deploy it can be found on GitHub. This software is a starting point for you to develop your own solution. You can maximize earnings by identifying and implementing your optimization strategies.
The matching transaction may looks like:
In this transaction, three types of script will be run to verify the tx:
Swap request lock script - rule 1#
Rule 1 - verifity if the actual pay amount and receive amount satisfy the request amount in swap request cell.
Info type script#
Rule 1 - TypeID rules
Rule 2 - If this is a matching transaction, the cell sequence in this tx should follow the rules above.
Rule 3 - Intercept the swap request queue from inputs and outputs, and for each request cell,verifity if the actual pay amount and receive amount satisfy the request amount in swap request cell. And update the sudt_x_reserve and sudt_y_reserve for following verification.
Info lock script#
Rules 1 - Verify if lock.args is consistent with info type
3. Traders can cancel their own swap request#
This transaction leads to another rule of swap request lock script
Swap request lock script - rule 2#
Rule2 - If one of input cell in the transaction use user's lock specified in liquidity request cell args and the corresponding witness is not 0, unlock the request cell directly.