Join 94,651 users already on read.cash

Introducing Group Tokens for Bitcoin Cash - Part 2/N - Atomic Swap Examples

7 195 exc
Avatar for bitcoincashautist
Written by   177
1 year ago
Topics: Bitcoincash, BCH

Group Tokenization is a Bitcoin Cash improvement proposal (CHIP) designed to natively support alternative currencies without impeding on the utility of native currency (BCH). It achieves this with an optional dual-currency output system, where the balancing equation for the native currency is unchanged and some consensus level logic is only added to enforce the balance of other currencies. In effect, the other currency can be used the same way as BCH and so benefit from Script, SPV, and SIGHASH ops. while giving back to BCH by creating marginal demand for BCH with every token UTXO and every token transaction created thus staying faithful to design precepts from the Bitcoin whitepaper.

That's what Group Tokenization is, but I imagined this series as a way to show what could be done with them. Today we'll look into atomic swaps.

The notation is simple, stuff in [] describes a transaction output:

[BCH satoshi amount, Group ID, Group amount or authority flags]

Atomic Swaps with Group Tokenization

Group tokenization allows multiple token and BCH TXOs in a single transaction which enables any two parties to perform an atomic swap using existing Bitcoin Cash transaction signing features (SIGHASH).

If trading parties already discovered each other through some communication channel they can agree in advance on all outputs then each sign their inputs using SIGHASH_ALL and construct a transaction like the below.

Atomic Swap Transaction
    In
        [101000] // BCH signed by Bob
        [   546, Token A, 50000000] // Token A signed by Alice
    Out
        [100000] // BCH to Alice's address
        [   546, Token A, 50000000] // Token A to Bob's address
    Fee    1000

This is the simplest example, and a coordinator could help with connecting interested parties and constructing the TXes. This also allows for multi-token and multi-party trades, too. The below can be done in the same way, as long as everyone can coordinate and agree on outputs in advance.

Multi-token and multi-party Atomic Swap Transaction
    In
        [ 10000] // BCH signed by Alice
        [500000] // BCH signed by Bob
        [ 20000] // BCH signed by Carol
        [   546, Token A, 20000000] // Token A signed by Alice
        [   546, Token C, 10000000] // Token C signed by Carol
    Out
        [107908] // BCH to Alice's address (Trade 1 & BCH change)
        [117908] // BCH to Carol's address (Trade 1 & BCH change)
        [299000] // Bob's change (Trade 1)
        [   546, Token A,  2000000] // Token A to Bob's address (Trade 1)
        [   546, Token C,  1000000] // Token C to Bob's address (Trade 1)
        [   546, Token A,  4000000] // Token A to Carol's address (Trade 2)
        [   546, Token C,  2000000] // Token C to Alice's address (Trade 2)
        [   546, Token A, 14000000] // Alice's token change (Trade 1 & 2)
        [   546, Token C,  7000000] // Carol's token change (Trade 1 & 2)
    Fee    3000 // All participants agree to split the fee

Here Bob is buying two tokens at the same time and is paying 1/3 of the transaction fee. Alice and Carol are trading with Bob (Trade 1) and with each other (Trade 2) at the same time. Alice and Carol each pay for their share of the fee and for the creation of additional token UTXOs. This transaction could be made more compact by merging BCH and token UTXOs into group UTXOs storing both the BCH and tokens. The outputs would then look like this:

    Out
        [299546, Token A,  2000000] // Bob's address
        [   546, Token C,  1000000] // Bob's address
        [108454, Token C,  2000000] // Alice's address
        [   546, Token A, 14000000] // Alice's address
        [118454, Token A,  4000000] // Carol's address
        [   546, Token C,  7000000] // Carol's address

The above also demonstrates how BCH can freely flow in/out from Group outputs.

Another possibility is to create a blind offer by crafting a partial transaction and signing an input using SIGHASH_SINGLE. Suppose Bob wants to buy a token and wants to post a bid offer. He will prepare a partial transaction like below and publish it to some public message board.

Blind Offer Atomic Swap Partial Transaction
    In
        [100000] // BCH signed by Bob
    Out
        [   546, Token T, 30000000] // Token T to Bob's address

Then, someone sees that offer and decides to take it. He will complete the transaction by adding his token to the inputs, and creating an output to take the BCH offered.

Blind Offer Atomic Swap Completed Transaction
    In
        [100000] // BCH signed by Bob
        [   546, Token T, 30000000] // Token T signed by Taker
    Out
        [   546, Token T, 30000000] // Token T to Bob's address
        [ 99000] // BCH to Taker's address
    Fee
           1000

The Taker then posts the transaction and with that the trade is completed. Should Bob change his mind, he can pull the offer by spending the input. Miners benefit from the fee either-way, whether the exchange took place or it was cancelled.

Blind Offer Atomic Swap Offer Cancellation Transaction
    In
        [100000] // BCH signed by Bob
    Out
        [ 99000] // BCH to Bob's address
    Fee
           1000 // Miners earn the fee even on cancelled trades :)

In the blind offer scenario, a coordinator is not needed. One could even post it in physical form by posting a QR code on a bulletin board, and the buyer could take it by scanning and paying.

Other posts in the series

Introducing Group Tokens for Bitcoin Cash - Part 1/N - Stablecoin Example

Introducing Group Tokens for Bitcoin Cash - Part 2/N - Atomic Swap Examples (this)

Introducing Group Tokens for Bitcoin Cash - Part 3/N - CoinJoin

Introducing Group Tokens for Bitcoin Cash - Part 4/N - Non-fungible Tokens (NFTs)

7
$ 16.71
$ 13.56 from @TheRandomRewarder
$ 2.00 from @ErdoganTalk
$ 0.50 from @inf
+ 3
Avatar for bitcoincashautist
Written by   177
1 year ago
Topics: Bitcoincash, BCH
Enjoyed this article?  Earn Bitcoin Cash by sharing it! Explain
...and you will also help the author collect more tips.

Comments

sir do you know magic All your articles fascinate people. I think you know magic😍 You are real boss In this read cash Site ❣️

$ 0.00
1 year ago

Sir you are My ideal 🥰 i love your Every article 🥰You gives us valuable information❣️

$ 0.00
1 year ago

It's Mind-boggling article 🥰 Sir i am your new family members ❣️

$ 0.00
1 year ago

Nice article bro keep it up

$ 0.00
1 year ago

Will do, thanks!

$ 0.00
1 year ago

Until now, I haven't understood about this, I'm serious

$ 0.00
1 year ago

Hey it's ok, this is a more technical series. Maybe this will be easier to follow: https://read.cash/@bitcoincashautist/we-want-first-class-tokens-on-bch-part-3n-native-group-tokens-faq-659ae5c1

$ 0.00
1 year ago