Atomic Swap Online en
Atomic Swap Online en
VERSION 1.0.
February 2019
CONTENTS
1
0.1. Swap.online: Abstract
Swap.online is a peer-to-peer (wallet-to-wallet) non-custodial exchange of different
cryptocurrencies, utility tokens, and soon to be security tokens. Our two main products are a
wallet for storing and exchanging cryptocurrencies without the middlemen and an HTML widget
allowing any crypto-project to implement the same functionality and to accept cryptocurrencies
on their own site. Both of our products work without a server
Swap.online team was the first ever to perform Atomic Swaps with EOS and USDT (Sep, 2018).
We added BTC and ETH blockchains in August 2018. By today LTC, TLOS are also connected
to our global cross-chain network. More than 45 projects are already connected and have
recommended swap.online to their communities.
0.2.1. Over-centralization
Over-centralization plays a large role when conducting both transactions within the same
blockchain and exchanges between different cryptocurrencies. It is so due to the existence of a
single ‘central’ software or a hardware element. Crypto exchanges and wallets use this
over-centralization to speed up the process of exchanges, monitor customer behavior, and
optimize business processes.
The consequence of centralizing such services is that they become exposed to the decisions
made by the authorities of those countries where the service is either registered or deployed.
This was greatly illustrated by the litigations [3] made by the US SEC against numerous (local)
exchanges, and the problems faced by participants of the Chinese [2] crypto exchange market.
Countries that used to be attractive for businesses have become “problematic” in terms of
jurisdiction - for example Singapore[5] and Canada[1].
2
for checking users. In practice, this fact results in significant difficulties with the withdrawal of
funds even for law-abiding users who have provided all of the required documents to these
centralized services. Some inquiries may be delayed for weeks, even months [6], which is
completely unacceptable, considering the volatility of cryptocurrency rates.
The table below (Figure 1) considers some projects in the field of high-tech decentralized
exchanges.
3
are required
Most of our competitors run their decentralized exchanges only on one blockchain. Such
services focus on the exchange of assets based on Ethereum blockchain, and were very
popular during the period of maximum interest in ICO’s with ERC-20 tokens (for example,
EtherDelta, ForkDelta, Kyber Network, 0x, Airswap). But evidently, assets based on other
blockchains can not be exchanged on these services.
Less common are services with proxy tokens (sidechain bridges) like BitShares,
WavesDEX, BinanceDEX. The essence of their decentralization is in an isolated blockchain, the
same as in the examples considered in the previous paragraph. Proxy Token is the link between
the exchangeable and the target currencies. Money and cryptocurrency of the clients get into
such services through affiliate exchanges or special “bridges”. Opgfhgfhfgerators of such
bridges are a limited number of people called “validators”. In this case, the middlemen is not
excluded and can act in their own interest. Well known example of such consequences - is the
rate fluctuation of BitUSD stablecoin, a unit of payment in BitSharesDEX (Figure 2). Like any
stablecoin, its rate must be pegged to one unit of fiat currency (in this case, the US dollar). At
the same time, services that use a proxy token provides such a wide field for manipulations,
allowing the users to lose more than 30% when depositing and withdrawing their money.
4
Figure 2. Rate fluctuation of BitUSD stablecoin - possible evidence of manipulations on the
affiliate service.
The easiest way for a project to access this market is by issuing their own token, and
exchanging it for BTC and USDT directly on their website. An excellent technological solution for
this is Swap.Widget, which will allow to exchange any token with any of the world’s key
blockchains. This way of business tokenization is safe, adaptive, and beneficial for all parties.
In 2017 during the high popularity of classical ICO schemes, the vast majority of these
projects accepted just Ethereum. This is due to a number of reasons, such as: the simplicity of
the technical solution, the convenient interaction of smart contracts executed by the Ethereum
Virtual Machine, the popularity of Ethereum tokens, and the relatively high speed of
transactions. However, those schemes have a number of inevitable flaws:
● A high level of dependance on the rate of Ethereum in a cryptocurrency market that is
highly volatile. Thus, a startup that collected $1 million in Ethereum in May 2018 would
have to reduce its budget in six months by 5 times, which in most cases forces to spend
these funds as soon as they are collected;
● Bitcoin is still the dominant cryptocurrency, recognized in many countries as the most
legitimate mean of circulation;
● For beginners in the Cryptocurrency trade, it is more complicated to purchase Ethereum
than Bitcoin.
● In case of Bitcoin and altcoins simultaneous failure stablecoins become the most
profitable means of payment for both businesses and customers.
5
Note that in this situation Ethereum can be replaced by any other currency, but the point
will remain the same: any program that is tied to only one blockchain and does not include
stablecoins becomes extremely vulnerable.
So in order for projects that have their own token to start accepting payments, there
solution should have the following features:
●Work with different blockchains in addition to the Ethereum network;
●Work with stablecoins and first of all with USDT;
●Quick installation, developability, simple integration with any sort of project.
At the end of November 2017 the idea was formulated of how the payments in Bitcoins
can be accepted in a decentralized mode through atomic exchanges using bitcoin.js. A
decentralized application interacts with the payer through a special type of time-limited
cryptographic payment - HTLC (for more details, see 1.2.2) - which allows the payer to receive
tokens, and the seller (for example, the application team) to receive the payment in
cryptocurrency. Thus , the b2b-implementation of atomic swaps gave the idea which started
Swap.Online.
The end-user solution in this business field of Swap Online is Swap.Widget - an HTML
widget that allows to accept cryptocurrencies. The back-end of Swap.Widget is a javascript
code. It can be built-in to any website and allows to accept payments in both Bitcoins and
USDT, exchanging them for tokens of the project. For the buyer, it is somewhat similar to the
payment gateways of traditional financial systems. Swap.Widget, is a completely decentralized
solution, that does not store assets and is only a mean of interaction between the buyer and the
seller.
So for teams that are issuing tokens, some of the advantages of Swap.Widget are:
● Quick access to exchanges. As of today, projects have to use exchanges that require
them to go through massive and time-consuming verification procedures;
● Low cost solution in comparison with the average price for listing tokens;
● No transaction fees via Swap.Widget;
● No need to trust centralized services with the customers' money and the project’s assets.
For ‘end’ users purchasing tokens, the following benefits of Swap.Widget are important:
● The variety of cryptocurrencies that are accepted. Bitcoin and USDT are already
connected, new blockchains are being tested and will be added soon;
● Accepting stablecoins guarantees a more accurate financial forecast;
6
● Funds go directly to the team, bypassing centralized services. This allows the
requirements for the nature and amount of cash inflows to be as flexible as possible;
● The ability to exchange rare, over-the-counter assets.
HTLC is a smart contract in which the cryptocurrency is locked, and it can only be received
at a predetermined address, by presenting the secret to the corresponding hash within a certain
time period. When creating the contract, only the hash of the secret is known, and the secret
itself is not yet publicly available.
By creating two symmetric HTLC’s on different blockchains, you get a fairly simple atomic
swap mechanism. One smart contract is created by Alice on the Bitcoin network; The
beneficiary of this contract is Bob’s Bitcoin address. Bob creates exactly the same smart
contract on the Ether network, where the beneficiary is Alice’s address. One of the parties holds
the secret, but both parties known the hash of this secret, and with this hash both smart
contracts are created. Which party keeps the secret is not important. The important thing is that
the one who knows the secret creates a contract with an increased time lock frame.
HTLC features - both contracts are symmetrical, the party that has presented the secret is
the first to get the cryptocurrency. For example, Alice presents the secret to Bob's smart contract
which is on the Ether network. The Smart Contract calculates the hash of the secret — and if
everything matches — it sends ETH to Alice's address, pre-wired into the Smart Contract.
Since all operations in blockchain are public, the secret is immediately revealed to Bob. In
Alice's smart contract, bitcoins are locked with the same hash, so after Bob presents the
revealed secret he immediately receives his Bitcoins. It is important to do it in time, while the
7
time lock is valid.
If for some reason Alice does not reveal her secret, Bob can safely take back his Ether after the
expiration of the time lock. At the same time, Alice cannot get Bob’s Ether from a smart contract
by presenting the wrong secret, because it doesn’t match the hash and the smart contract will
not release Ether.
The first stage is “order matching”, the process when to parties agree on an exchange. To
be precise, this is a necessary step that must occur before an atomic swap begins. How this
step is executed differs projects from one another. The protocols for the “handshake” procedure
before starting a swap are completely different - some use centralized services, some sidechain,
others decentralized order-books.
Swap.online, in the first version of its protocol, uses IPFS pubsub, a fully decentralized
messaging protocol. Each order created by the market maker is translated into the message
channels which market takers are subscribed to. It’s like a loud announcement: “I am ready to
change my 10 Bitcoins for your 100 Ethers”.
After subscribing to the message channels, the market taker sees orders as soon as they
are available. In order for a market maker’s order to be visible - he must constantly post
messages about its relevance to the channel, therefore the market maker needs to be always
online in order to make deals. This inconvenience is eliminated by Swap.online professional
trading solution (bot), which can work with orders independently.
But this does not bring any inconvenience, because in any case exchanges with HTLC
protocol requires the transactions to be signed in real time. And the Market Taker can accept the
order at any time.
Once the market taker accepts one of the advertised orders by signing the acceptance
message, both parties start creating the HTLC contracts on their blockchains and complete the
transaction using the protocol described above.
8
Figure 3. Swap.online user sees all the steps of atomic swap.
Since swap.online does not store users' keys or their funds, it is the users full
responsibility to keep a backup copy of their keys. They are warned about this matter. In the first
version of the wallet the backup copy of the keys are downloaded as a .txt file and can be used
both to restore access to the account initially opened on Swap.online and to import it from
another service. As shown in Figure 5, the file with keys contains instructions for opening and
importing accounts in case of an emergency.
One of the features of swap.online wallet is it can quickly create and access an account on
EOS.IO network. The difficulties with registration and creating an account on this blockchain
leads to the fact that users who want to purchase these tokens turn to centralized exchanges.
Swap.online allows even a beginner to do it in a matter of minutes.
9
Figure 5. A backup copy of the keys and instructions for using them: this document is
generated for each user of Swap.online and covers the blockchains of Ethereum, Bitcoin, EOS,
etc.
USD Tether, as one of the most popular and trusted stablecoin has been drawing the
attention of the Cryptocurrency community for a long time already. Being a “replacement” for the
dollar for jurisdictions and situations in which the use of fiat currencies is impossible, he quickly
gained $2 billion in capitalization and became the most popular currency on centralized
exchange services. In addition, the Omni Layer protocol, within which the USDT operates, is a
unique “second layer” solution. By working with Omni Layer, projects are able to release their
own assets into the Bitcoin network.
10
Komodo Platform developers were interested in a decentralized exchange of USDT, but
their solution covered only the ERC-20 version of the USDT, which accounts for about 3% of the
total turnover of this currency. Thus, their solution rather misled the USDT users than made the
exchange easier. In September 2018 Swap Online team presented a solution of atomic swap
with USDT which is a 200-line code. The technical description of this solution is in Appendix 2.
The EOS.IO project, developed by the teams of Graphene, BitShares and SteemIt,
attracted the attention of the cryptocurrency community long before the official release of the
Mainnet, which followed in the summer of 2018. This blockchain (often called EOS by the name
of its token) is used for hosting decentralized applications, which should excel Ethereum. In
commercial terms, the following EOS features are most attractive:
● high network bandwidth;
● no transaction fees;
● High level of developability, due to the use of the C ++ language instead of Solidity;
● system scalability;
● high level of decentralization.
Considering this, the issues of integrating the EOS.IO blockchain and organizing
sustainable interaction with other well-known blockchains will inevitably come up on the agenda
of the world's leading cross-chain projects. Now the storage and exchange of EOS tokens is
carried out through centralized exchanges or services tied only to this blockchain, but atomic
swaps are the most promising solution. Technical details of atomic swaps with EOS are
described in Appendix 3.
11
Swap.Online has been developing Swap.Widget since July 2018.
● The working version of the widget was presented and tested in November 2018;
● Today Swap.Widget can accept payments in USDT and Bitcoin;
● based on the knowledge from swap wiki, a demo service was developed where any
interested project can test the functionality of the swap widget
For example, you can buy the token of online gambling service Funfair (ERC-20: FUN)
directly on the projects website:
https://demo.Swap.online/iframe/?url=https%3A%2F%2Ffunfair.io.
The Swap.Widget button that offers to purchase project’s tokens can be organically integrated
into the functionality of any website. After clicking the button the user can select a
cryptocurrency to buy the tokens with, the amount of tokens to buy, the wallet address from
which the purchase will be paid for; and the current dollar equivalent will be displayed as well.
Thus, the Swap.Widget product is fully ready for USDT and Bitcoin, other blockchains are
under development, an active marketing campaign is in progress.
12
First swaps between Bitcoin and Ethereum were performed on the testnet
https://testnet.swap.online in June 2018. And new blockchains are gradually being integrated
into atomic swaps.
At the time of publication, swap.online exchange capabilities have reached the following
progress:
● Over 110 trade pairs are constantly and reliably operating;
● The first ever atomic swap with the full version of USDT;
● The first ever atomic swap with EOS;
● “Smart order book” - shows only those orders that can be taken with the current balance;
● A constantly evolving trading bot that can place and receive orders, analyze the order
book, etc.
13
3. Swap.online: monetization and legal aspects
The most common functions of such tokens are: to create preferences in trading with the
exchanges that have issued these tokens, the participation of tokens in technological processes
of the exchange, and to cover the service and miners fees with these tokens. In 2018 it became
more common to manipulate the rates of these exchange tokens for example by transactional
mining or occasionally burning these tokens, that would lead to the increase of their price by
reducing their total supply. Lastly, Binance offers to use its tokens for investing into partner
projects.
14
equity-share in a company, despite the assurance made by the tokens issuers. However, the
nature of blockchains -decentralized systems that are resistant to all sorts of scams and abuses
- are great for these purposes. In Swap.online, we are developing a mechanism that will
maximize the potential of the blockchain as an institutional and technological design for
acquiring equity. Here we stick to the following views:
● the acquisition of equity through tokens may be anonymous, but identity proof should
empower the acquirer;
● Purchasing the equity with tokens must be legal and from the purchaser side as well.
This leads to the need to consider different options for interaction, taking into account the
different principles of cryptocurrency regulation;
● The number of SWAP tokens acquired by the user should directly correlate with the
share of equity in the company.
The Bright Law Firm experts gave an explicit negative answer to all three questions:
● Due to the fact that the “token of swap.online project does not give its holder the right to
make decisions, vote, and income expectations” the swap.online token is not a security
in accordance with article 2 of the Securities Market Act;
● Swap.online token can be considered as a virtual currency. In accordance with
paragraph “e” of Part 1 of Article 135 of the VAT Directive, the Swap.online token cannot
be subject to VAT;
● Swap.online service does not create keys for the user itself, does not store them, and
does not enter into legal relations with users. Thus, Swap.online does not provide wallet
services for storing virtual currency in the sense described in Section 10 of Article 3 of
the Money Laundering and Terrorist Financing Prevention Act, and therefore cannot
consider itself bound by the provisions of this Law in the relevant part.
Therefore, we can say with confidence that the acquisition and storage of SWAP tokens, as well
as the use of swap.online as a service, will not involve large legal procedures and will not attract
the interest of tax and financial regulatory authorities.
15
3.5. License proceedings
The controversial and dynamic status of cryptocurrency in the legal field of most countries
of the world poses a complex issue for obtaining licenses for financial and technological start-up
teams. Some projects decide not to obtain legal status in one or another country, that on the one
hand allows to avoid tax and legal difficulties, but on the other - have a negative impact on the
credibility of the project, that in this case exists only in the form of a website.
Swap.online has passed all the registration and licensing procedures. The project is
registered as Swap Online OÜ with the registration number 14477421 at Harju maakond,
Tallinn, Kesklinna linnaosa, Tartu mnt 83-701, 10115, which is officially recorded in Estonian
Register of Economic Activities. The license number FVR 000299 from July 26, 2018 issued by
the Eesti Politsei- ja Piirivalveamet in relation to the “Financial Services” subject of field.
16
Appendix - Technical Details
Appendix 1 . Decentralized order book based on libp2p
TBA
17
Figure 7. Omni Transaction Payload.
Suppose that Alice and Bob are willing to make an inter-blockchain exchange of
cryptocurrencies. Alice wants to exchange the units of any Omni currency, for example USDT
(the given currency has the currency identifier # 31 in the Mainnet, then in the text we will only
talk about this currency of the Omni protocol, since it is the most popular at the moment, but the
algorithm below will work for any currency of the Omni protocol as well) for b units of a
cryptocurrency working on another blockchain. (Omni works on top of the Bitcoin blockchain, of
course, according to the algorithm below it is possible to exchange USDT for Bitcoins, but due to
their work on one and the same blockchain, this exchange can be done in a different, more
efficient way).
Also, suppose, that:
A — blockchain of Bitcoin.
B — the blockchain of the cryptocurrency for which TetherUS is being exchanged.
a — the sum of USDT, which Alice wants to exchange.
b — the sum of the cryptocurrency of the adjoining blockchain B, to which Alice wants to
exchange her a USDT.
That’s how the transaction is created:
1) Bob generates a random value secret.
2) Bob calculates the secretHash by performing the following operation: secretHash =
RIPEMD160 (secret)
3) Bob creates and sends an HTLC transaction sealed by secretHash
4) Bob sends Alice a secretHash value, and a hash of the hrlc transaction he created in
the previous paragraph in order for Alice to make sure that the correct HTLC transaction is
actually present in the B blockchain.
5) Alice received from Bob the secretHash and hash of the HTLC-transaction Bob created,
and is convinced that such a transaction is really present in the B blockchain, and that this is
indeed a HTLC-transaction sealed by the secretHash value.
18
6) using the received secretHash, Alice creates the following transaction and translates it
into the Bitcoin blockchain:
Let us call such a transaction financing_tx. In fact, it is almost an ordinary Bitcoin HTLC
transaction that is used in atomic swap with the only difference that in the amount field, 546
satoshi is the minimum number of Bitcoins that can be at the output of the transaction, below
this value, Bitcoin counts the transaction as dust and does not conduct it.
7) Alice creates a transaction according to the following scheme:
19
Figure 9. Alice creates transaction
Let us call this transaction redeem_tx. Alice creates such a transaction with two inputs: the
first is the input referencing the output of funding_tx, which contains the HTLC script. Alice does
not sign this script, that is, the SigScript field remains completely empty. The second input is the
input referring to any unspent exits of Alice, the main condition is that at this output stage there
are enough Bitcoins to pay the transaction fee, and this entry is signed by Alice with her private
key with the signature type SIGHASH_ALL (that is, she signs the entire transaction except for
SigScript fields on the inputs transaction, which makes this transaction immutable. The outputs
of the same transaction are the elementary Simple Send and a TetherUS from Alice to Bob
(details of what Simple Send, payload is and how it works can be found in another section).
8) Alice sends Bob the redeem_tx created in the previous paragraph and the one she
signed herself.
9) Bob got the redeem_tx sent by Alice, checks it, just looks through the inputs and
outputs, making sure that this is really a transaction that Alice should have created using the
real algorithm. After that, Bob signs the transaction with his private key and provides the secret
value in the SigScript of the corresponding redeem_tx entry.
10) Bob sends the signed redeem_tx transaction to the blockchain, thereby transferring
the TetherUS currency from Alice to himself. Note — before carrying out this step, we still need
to check that Alice’s address has the necessary amount of TetherUS.
11) Alice looks through blockchain A and gets the value secret and uses it in the B
blockchain to transfer the funds using the HTLC transaction Bob created in point 3. The
exchange ends here.
Stating the obvious: naturally the timelock value used by Bob when creating the
HTLC-transaction must be significantly longer than the timelock that Alice uses, since her HTLC
transaction should be spent earlier than the HTLC created by Bob. This is necessary so that
Bob cannot manage to spend both HTLC.
20
Appendix 3. Atomic Swaps on EOS: Technical Details
EOS uses a WebAssembly virtual machine to run smart contracts. The “eosio.token” is
smart contract that enables different tokens including SYS tokens. Users will need to create an
account to interact with EOS smart contracts. The Swap Online team prepared scripts and
instruction for this, which can be found here. Users can also use the “Register” button on the
Swap.online website and pay in BTC for account creation. The user also has the function to
interact with EOS smart contracts though the EOS endpoint via eosjs library that is imported at
Swap.online. It is also possible to interact with the special contract for atomic swaps in order to
exchange BTC to EOS using the Swap.online orderbook.
When the user agrees to make a peer-to-peer atomic swap with the owner of EOS
tokens, then they have to prefund the HTLC Bitcoin script. Then the owner of EOS will be
notified and will send funds to the swap smart contract. In order to withdraw the EOS funds from
the smart contracts, the user will have to reveal their secret from the HTLC script in the same
transaction. Then the owner of EOS will notified and will withdraw the BTC using the given
secret.
Every swap in the smart contract has a period of time when users can withdraw the funds
and reveal their secret. That period is twice as less as the period of HTLC to ensure that the
EOS owner will have enough time to withdraw their Bitcoins from the HTLC.
If you will not reveal your secret during this period of time, then the EOS owner will be
able to get a refund and the opposing user’s reputation on Swap.online will be decreased. If the
EOS owner will not create a swap when they prefunded the HTLC script, then their reputation
will be decreased.
The smart contract has actions that mutate the state of a contract. Single transactions
can have multiple actions. The swap contract has the create, deposit, refund, withdraw and
refund actions. When the EOS owner creates swap they send two actions in a single
transaction: create and deposit. The swap contract immediately sees that it received EOS token
and creates an open swap that is available for withdraw by revealing the secret key. When the
user withdraws funds from the swap, they send a withdraw action with their secret key in the
argument. When the EOS owner wants to get a refund after the safe period of time, they send a
refund action. The code of the smart contract account has the permission to transfer funds to the
user.
21
Disclaimer
22
References
23