RIP: 15 Title: User-Friendly Atomic Swap Process Author: Ben Abraham Comments-Summary: No comments yet Comments-URI: https://github.com/RavenProject/rips Status: Draft Type: Process Created: 2021-05-11
This RIP proposes a user-friendly methodology for performing on-chain atomic swaps in a user-friendly and verifiable manner. Allowing users to announce their desire to purchase or sell an asset for a predefined amount, and allowing A counterparty to complete that transaction.
With the ever-growing population of content creators on the ravencoin network, and ethereum fees at an all-time high, it's imperative to be able to provide the community with a fast, trusted, well-integrated means of asset trading, where both parties can recieve their output in a single transaction.
This effectively creates one-time-use publishable buy/sell orders for assets.
- Bob has 500RVN in his wallet. (known as bobInputUTXOs)
- Alice has 1xNFT asset in her wallet. (known as aliceInputUTXOs)
- Bob wants to purchase alice's NFT for a price that he determines
- Bob generates asset receipt address bobAssetAddr
- Bob creates a transaction with **only** the following vin/vouts
- vin: 500x RVN from bobInputUTXOs
- vout: 1xNFT to bobAssetAddr
- Bob signs the incomplete transaction with SIGHASH_SINGLE | SIGHASH_ANYONECANPAY
- Bob announces to alice, via a side-channel (discord, trading site, etc.,) his trade offer.
- Alice generates RVN receipt address aliceRVNAddr
- Alice generates asset change address if needed aliceAssetChangeAddr
- Alice adds the following vin/vouts to the transaction
- vin: 1xNFT from aliceInputUTXOs
- vout: 500x RVN to aliceRVNAddr
- vout: [optional] asset change to aliceAssetChangeAddr
- Alice signs the transaction to completion and publishes it
- Swap completed upon verification
The following Sequence works for ravend RPC
- listunspent - Find an exact UTXO for <quantity></quantity>
- createrawtransaction
- vin: [{}]
- vout: {<dest></dest>:{"transfer":{"<asset></asset>":<quantity></quantity>}}}
- signrawtransaction sighash=SINGLE|ANYONECANPAY
- listmyassets "" true - Find an exact UTXO for <quantity></quantity>
- createrawtransaction
- vin: [{}]
- vout: {<dest></dest>:<quantity></quantity>}
- signrawtransaction sighash=SINGLE|ANYONECANPAY
- decoderawtransaction <partial_tx></partial_tx>
- Add the following to decoded tx
- vout: {<dest></dest>:<quantity></quantity>}
- vout: {<change_addr></change_addr>:{"transfer":{"<asset></asset>":}}} - If asset change needed
- [Jenky] Repeat the following steps until approved by mempool
- createrawtransaction <decoded_vin></decoded_vin>, <decoded_vout></decoded_vout>
- fundrawtransaction <raw_tx></raw_tx>
- combinerawtransaction ["<funded_tx></funded_tx>",]
- signrawtransaction <combined_tx></combined_tx>
- reduce payout by 0.0001 RVN, repeat
- decoderawtransaction <partial_tx></partial_tx>
- Add the following to decoded tx
- vout: {<dest></dest>:{"transfer":{"<asset></asset>":<quantity></quantity>}}}
- createrawtransaction <decoded_vin></decoded_vin>, <decoded_vout></decoded_vout>
- fundrawtransaction <raw_tx></raw_tx> {"changePosition": 1}
- combinerawtransaction ["<funded_tx></funded_tx>",]
- signrawtransaction <combined_tx></combined_tx>
- Trustless, immediate asset trades would offer huge ability to content creators, allowing them to independently distribute their works withouht fear of a third party interfereing.
- Many ways this can be well-integrated into the client, making it very easy to make swaps.
- Simple basic instant transactions, no complex time-locking
- Partially signed transactions could be cleanly interpreted and displayed to the user, for easy understanding
- Greatly reduced effort when buying from a marketplace website, and no trust risk.
- The party creating the order must only have one vin and one vout, which means they cannot make change for thsemselves in the transaction. This can be handled by "prepping" a market order via transferring a set number of RVN to yourself to combine multiple UTXO's into a single (or to make change)
- Because you have to compile a list of UTXOs to broadcast in your request, those UTXOs might end up spent by the time the swap is attempted to be fulfilled. This can mitigated by having the client lock UTXO's when we it knows a swap has been setup.
- Canceling a market order can be done by invalidating the signed UTXO, ie: explicitly using the UTXO in a transfer-to-self transaction
Currently this process is fully implemented in a python script as a proof-of-concept.
From a UX point-of-view, ideally the process would look something like this:
- Bob builds a Buy Order in the UI specifying the quantity, cost, and payer of fees.
- This 'Buy Order' is constructed into a transaction, partially signed, and presented to bob. (Raw, QR, etc.)
- Bob either hands the signed tx directly to Alice, or he can simply publicly broadcast it and allow Alice to find it herself.
- Alice recieves the part-signed tx, the software decodes it and displays a simple explanation of what the swap looks like. (ie: 500RVN for 1xNFT)
- Alice approves the swap, finalizing the transaction and publishing it.
- Notification to both parties upon completion
- RPC commands to create/view/complete orders would greatly ease adoption.
- Swaps could be published in-client in some manner, allowing for a seamless market within the client.
- A seperate swaps section in the UI just for creating and monitoring previously created swaps.
- Assets marketplace websites could easily generate Sell Orders that users could very easily purchase in a single click with the use of protocol urls.