Atomex: cross-chain atomic swaps on practice

Introducing a multi-crypto desktop wallet with built-in hybrid exchange

Baking Bad
Sep 25, 2019 · 5 min read
Image for post
Image for post

A thorny developing process is starting to bear its first fruits: Atomex has been finally released in the mainnet. Our team has made up an exciting journey from the pure atomic swap protocol to the fully-fledged application, and now we can say “Yes, it works!”.
We want to thank all the early testers for their feedback, it is very important for us!

The idea behind

Our goal is to create a product for crypto enthusiasts, for those who believe in ideas behind the blockchain technology and who is paranoid in a good sense.

If TCP/IP is a protocol used to transfer information on the Internet, the blockchain is the same for e-money and other classes of assets. However, there is still an interchain gap which leads to an inconvenient value separation.
The atomic swap protocol which we will examine a little further effectively closes that gap in a trustless way, relying on an essentially simple idea. Banks or another trusted third-parties are being replaced by a smart contract, and this is one of the few cases when it can be done with just the data available on-chain (without oracles or other off-chain data providers).

Image for post
Image for post

Atomic swap basics

Before we move on to the practical part, let’s dive a bit into the protocol details. Let’s say Alice wants to buy some ETH for XTZ and Bob has agreed to make a deal. There are two possible outcomes, either the transaction will take place or will be canceled.

  1. Alice locks XTZ
    Alice generates a random bytes sequence — the secret, calculates its hash and sends her XTZ to a special smart contract together with the hash, a lock_time_a value, and Bob’s XTZ address_b
    These XTZ can only be redeemed by the owner of theaddress_b if he knows the secret, and it has to be done before the lock_time_a, afterward, Alice can get these funds back.
  2. Bob locks ETH
    When Alice’s transaction is confirmed Bob sends his ETH to a special smart contract together with the same hash, lock_time_b, and Alice’s ETH addreess_a
    These ETH can only be redeemed by the owner of theaddress_a if she knows the secret, and it has to be done before the lock_time_b, afterward, Bob can get these funds back.

Requirement: lock_time_b < lock_time_a
To prevent the case when Alice first makes a refund and then redeems Bob’s funds.

Image for post
Image for post
Simplified scheme of an XTZ/ETH swap (success case)
  1. Alice redeems ETH
    Alice sends the secret to the contract in Ethereum blockchain and receives Bob’s ETH in return.
    The secret is revealed now and Bob can spend the locked XTZ.
  2. Bob redeems XTZ
    Bob sends the secretto the contract in Tezos blockchain and receives Alice’s XTZ in return.

We will not consider the cases when something goes wrong during the initialization phase (they are rather trivial) but will examine the case when Alice doesn’t redeem Bob’s ETH for some reason, i.e. secret is not revealed and lock_time_b has passed.

Image for post
Image for post
Simplified scheme of an XTZ/ETH swap (refund case)
  1. Bob refunds ETH
    Bob sends hash to the smart contract in Ethereum blockchain and gets his ETH back.
    He cannot spend Alice’s XTZ since secret is not revealed.
  2. Alice refunds XTZ
    Alice waits until lock_time_a, then sends the hash to the contract in Tezos blockchain and gets her XTZ back.
    She cannot spend Bob’s ETH because lock_time_b has already passed.

That’s enough theory

Time to see Atomex in action! We’ll start from a multi-crypto setup with some XTZ and ETH on our balance. With regard to the above scheme we are Bob, and our counterparty is Alice.

Choose the “Conversion” tab and set the ETH amount we want to exchange for XTZ. Check the deal terms and then press “Convert”.

Image for post
Image for post
Step 0. The user creates a new conversion

A new сonversion appears in the table with the status “In Progress”.
Actually, that’s all we need to make an atomic swap through Atomex wallet. But let’s follow the internal process spawned by our actions.

First, check out recent operations for the Atomex smart contract in the Tezos blockchain:

Image for post
Image for post
Step 1. Alice locks XTZ

This is a transaction sent by Alice, these locked funds are going to be ours in the end. Mind the hash field passed via parameters.

Once the XTZ transaction is confirmed, Bob sends an ETH transaction. We can see that it contains the same hash :

Image for post
Image for post
Step 2. Bob locks ETH

Another contract invocation from Alice’s side. She receives our ETH in exchange for secret and Bob picks it up:

Image for post
Image for post
Step 3. Alice redeems ETH

Finally, Bob unlocks XTZ using the collected secret :

Image for post
Image for post
Step 4. Bob redeems XTZ

The status of our conversion changes to “Completed”, everything is ok.

Side notes

All the internal actions you saw are performed by the Atomex wallet in the background process so it’s necessary to keep it online until the swap is done. In our example of an XTZ/ETH conversion, it takes only 8 minutes for the whole thing, however, it depends on the particular blockchain confirmation time.

We are currently working on making different order types available. As soon as the Atomex swaps market will be consistent enough it will be possible to place limit orders through the Atomex app.

Check out our tutorial.

Any feedback is highly appreciated, if you have a feature request or a bug report please welcome to our Telegram chat. And don’t forget to follow us on Twitter!

Cheers!

Originally published at https://baking-bad.org on September 25, 2019, where you can find full version of the article.

Image for post
Image for post

Get Best Software Deals Directly In Your Inbox

Image for post
Image for post

Coinmonks

Coinmonks is a non-profit Crypto educational publication.

By Coinmonks

A newsletter that brings you week's best crypto and blockchain stories and trending news directly in your inbox, by CoinCodeCap.com Take a look

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

Baking Bad

Written by

Baking-bad.org, Audit & Rating of Tezos bakers. Active Tezos tools contributor. Author of better-call.dev, Pytezos, Netezos, TzKT.io, atomex.me

Coinmonks

Coinmonks

Coinmonks is a non-profit Crypto educational publication. Follow us on Twitter @coinmonks Our other project — https://coincodecap.com

Baking Bad

Written by

Baking-bad.org, Audit & Rating of Tezos bakers. Active Tezos tools contributor. Author of better-call.dev, Pytezos, Netezos, TzKT.io, atomex.me

Coinmonks

Coinmonks

Coinmonks is a non-profit Crypto educational publication. Follow us on Twitter @coinmonks Our other project — https://coincodecap.com

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store