Today, we are thrilled to kick-start a new editorial series, Switcheo Discovery, where we dive into the technology behind Switcheo and why it is important to you. With this first post, we will bring you through how Atomic Swaps works on Switcheo Exchange.

• • •

Atomic Swap is a feature on Switcheo Exchange which allows users to trade across two different blockchains (e.g. cross-chain between ETH and NEO).

Switcheo’s implementation of cross-chain trading through Atomic Swaps is particularly noteworthy as these trades are simple to execute but do not require a trusted 3rd-party at all.

In fact, DEXs often do not support cross-chain trades as smart contracts are always isolated within a single blockchain! Those that do would rely on
“proxy tokens” which still require the user to trust the token gateway.

Let us take a closer look at how Atomic Swaps work on Switcheo such that trading remains user-friendly and non-custodial.

What is Atomic Swap exactly?

Atomic Swaps, a method to perform cross-chain trading, allows transfers between two assets from different blockchains directly from wallet to wallet. For instance, exchanging ERC20 tokens to BTC.

Without Atomic Swaps, users may often face the risk of fraud and theft when conducting transfers of tokens between two different blockchains.

Consider the following example:

Alice wants to trade 20 ETH in return for 1 BTC, and the counterparty, Bob, wants to receive 20 ETH in return for 1 BTC. Alice will have to choose between one of two options:

  1. Alice first sends Bob 20 ETH and trusts that Bob will send her 1 BTC back.
  2. Alice and Bob both have to trust a third-party dealer (e.g. a centralized exchange) to be the custodian of their funds to facilitate the swap.

In the first option, Alice risks losing her money if Bob does not honor his end of the deal. In the second option, Alice and Bob both risk losing their money if the third-party dealer decides to walk away and not assist with the swap.

Using Atomic Swap, both of these risks can be avoided.

The following steps will illustrate how an Atomic swap is typically conducted:

                                                              ***

Step 1

Alice chooses a secret password (e.g: gtMcn7XGlIbq). She hashes the password using a one-way hash to generate the following hash:

0f128d401958b1b30ad0d10406f47f9489321017b4614e6cb993fc63913c5454

Alice sends an ETH blockchain transaction with the instructions, “Lock 20 ETH from my account for Bob, with the following password hash:

0f128d401958b1b30ad0d10406f47f9489321017b4614e6cb993fc63913c5454

Step 2

After waiting for Alice’s transaction to appear on the blockchain, Bob sends a BTC transaction using the same password hash, the instruction reads as “Lock 1 BTC from my account for Alice, with the following password hash:

0f128d401958b1b30ad0d10406f47f9489321017b4614e6cb993fc63913c5454

Step 3

Alice sees that Bob has initiated a transaction, and claims her 1 BTC, using the secret password (gtMcn7XGlIbq) known only to her. Alice claims the BTC with the blockchain transaction: “Claim 1 BTC from Bob, the secret password is (gtMcn7XGlIbq) for the password hash:

0f128d401958b1b30ad0d10406f47f9489321017b4614e6cb993fc63913c5454

The password is verified on the Bitcoin blockchain to match the password hash, and the funds are transferred to Alice.

Step 4

Bob sees the secret password (gtMcn7XGlIbq) from Alice’s blockchain transaction. He can then make the claim of 20 ETH from Alice by sending a blockchain transaction with the following instructions: “Claim 20 ETH from Alice, the secret password is (gtMcn7XGlIbq) for the password hash:

0f128d401958b1b30ad0d10406f47f9489321017b4614e6cb993fc63913c5454

The password is verified on the ETH blockchain to match the password hash, and the funds are transferred to Bob.

                                                                   ***

As you can see from the steps above, an Atomic Swap can be a cumbersome process because there is a need to find a counterparty. After which, both parties (the person who initiates the cross-chain trade and the counterparty) will have to closely monitor the blockchain and send their transactions at the appropriate times.

On Switcheo Exchange, these steps are simplified for you.

How Atomic Swap is done on Switcheo Exchange

Even though performing an Atomic Swap transaction requires two parties, there is no need to search for a counterparty on Switcheo Exchange. This is because we provide an algorithmic market maker to automatically be the counterparty for all user trades on the Atomic Swap markets.

Referring back to the example used above, the algorithmic market maker is represented by Alice, while Bob represents a Switcheo User.

If the trading pair NEO / ETH is selected, the user will specify how many NEO he would like to trade, and Switcheo’s algorithmic market maker will determine the amount of ETH that should be used to match the trade. The proposed ETH amount is then shown to the user, and the user can confirm the order if the amount is acceptable.

Algorithmic Market Maker Pricing Calculations

To decide on how much ETH should be asked for or given for an amount of NEO, Switcheo uses the Constant Product market making formula:

NEO_To_Give = NEO_Balance — (NEO_Balance * ETH_Balance) / (ETH_Balance + ETH_Received)

For example, if the algorithmic market maker has 100 ETH and 1746 NEO, and if a user wants to buy NEO using 1 ETH:

NEO_To_Give = 1746 — (1746 *100) / (100 + 1) = 17.287 NEO

As the algorithmic market maker allocates more NEO to users, the formula will result in less NEO being given for a similar amount of ETH, resulting in the price of NEO rising against ETH.

On the other hand, if the algorithmic market maker gives more ETH to users, then the price of ETH will increase against NEO. This provides fair pricing for users by allowing the price to be determined by the relative market demand of each asset.

What does it mean to select the option, “Skip Waiting”?

You will notice there is an option labeled “Skip Waiting” when trading on our atomic swap markets.

The reason for this is because when an order is submitted, Switcheo Exchange will send the first Atomic Swap transaction (see step 1 above) to promise funds to the user. While this transaction is immediately sent, it takes some time for it to appear on blockchain explorers.

By choosing to Skip Waiting, the user trusts that Switcheo has confirmed that this transaction was sent, and proceeds to send their Atomic Swap transaction (see step 2 above). Once this is done, Switcheo automatically completes the Atomic Swap transaction for the user by performing step (3) and step (4) at the appropriate times.

• • •

We hope that you have now gained a deeper understanding of how the atomic swap markets work on our trading platform!

Check out these Atomic Swap markets on Switcheo Exchange today!

SWTH/ETH | NEO/ETH | EOS/NEO | EOS/ETH | SDUSD/DAI

• • •

For more information on Switcheo: