Skip to content

Latest commit

 

History

History
120 lines (97 loc) · 6.32 KB

rip-0015.mediawiki

File metadata and controls

120 lines (97 loc) · 6.32 KB

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

Table of Contents

Abstract

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.

Motivation

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.

Methodology

  • 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

Full Buy Order Sequence

  1. Bob generates asset receipt address bobAssetAddr
  2. Bob creates a transaction with **only** the following vin/vouts
    1. vin: 500x RVN from bobInputUTXOs
    2. vout: 1xNFT to bobAssetAddr
  3. Bob signs the incomplete transaction with SIGHASH_SINGLE | SIGHASH_ANYONECANPAY
  4. Bob announces to alice, via a side-channel (discord, trading site, etc.,) his trade offer.
  5. Alice generates RVN receipt address aliceRVNAddr
  6. Alice generates asset change address if needed aliceAssetChangeAddr
  7. Alice adds the following vin/vouts to the transaction
    1. vin: 1xNFT from aliceInputUTXOs
    2. vout: 500x RVN to aliceRVNAddr
    3. vout: [optional] asset change to aliceAssetChangeAddr
  8. Alice signs the transaction to completion and publishes it
  9. Swap completed upon verification
This proposal suggests combining steps 1-4, as well as 6-10 into a single user-interface step each for both bob and alice. Allowing for 2-step swaps to take place seamleslly with the ravencoin client.

RPC Sequence

The following Sequence works for ravend RPC

Create Buy Order

  1. listunspent - Find an exact UTXO for <quantity></quantity>
  2. createrawtransaction
    1. vin: [{}]
    2. vout: {<dest></dest>:{"transfer":{"<asset></asset>":<quantity></quantity>}}}
  3. signrawtransaction sighash=SINGLE|ANYONECANPAY

Create Sell Order

  1. listmyassets "" true - Find an exact UTXO for <quantity></quantity>
  2. createrawtransaction
    1. vin: [{}]
    2. vout: {<dest></dest>:<quantity></quantity>}
  3. signrawtransaction sighash=SINGLE|ANYONECANPAY

Complete Buy Order

  1. decoderawtransaction <partial_tx></partial_tx>
  2. Add the following to decoded tx
    1. vout: {<dest></dest>:<quantity></quantity>}
    2. vout: {<change_addr></change_addr>:{"transfer":{"<asset></asset>":}}} - If asset change needed
  3. [Jenky] Repeat the following steps until approved by mempool
  4. createrawtransaction <decoded_vin></decoded_vin>, <decoded_vout></decoded_vout>
  5. fundrawtransaction <raw_tx></raw_tx>
  6. combinerawtransaction ["<funded_tx></funded_tx>",]
  7. signrawtransaction <combined_tx></combined_tx>
  8. reduce payout by 0.0001 RVN, repeat

Complete Sell Order

  1. decoderawtransaction <partial_tx></partial_tx>
  2. Add the following to decoded tx
    1. vout: {<dest></dest>:{"transfer":{"<asset></asset>":<quantity></quantity>}}}
  3. createrawtransaction <decoded_vin></decoded_vin>, <decoded_vout></decoded_vout>
  4. fundrawtransaction <raw_tx></raw_tx> {"changePosition": 1}
  5. combinerawtransaction ["<funded_tx></funded_tx>",]
  6. signrawtransaction <combined_tx></combined_tx>
Once the transaction has been signed, it can be presented to the user for verification before submission.

Benefits

  • 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.

Downsides

  • 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

Implementation

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:

  1. Bob builds a Buy Order in the UI specifying the quantity, cost, and payer of fees.
  2. This 'Buy Order' is constructed into a transaction, partially signed, and presented to bob. (Raw, QR, etc.)
  3. Bob either hands the signed tx directly to Alice, or he can simply publicly broadcast it and allow Alice to find it herself.
  4. 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)
  5. Alice approves the swap, finalizing the transaction and publishing it.
There are many additional ways you could expand this functionality above-and-beyone the above behaviour. Some quick suggestions that come to mind:
  • 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.

References