Get started
Lykke is Integrating Ethereum
Lykke is Integrating Ethereum

Lykke is Integrating Ethereum

By Mihail Nikulin, Lykke co-founder and CTO

Lykke is a semi-centralized exchange. This means that the exchange does not take possession of the traded coins (Ethereum tokens, Ethers, Bitcoins or colored coins), but needs to be trusted to match trades correctly. Lykke has a centralized matching engine and decentralized coins settlement. Matched trades are settled on the blockchain in the atomic way. Each atomic transaction must be signed by both parites and the exchange. Still to be able to trade, one should deposit his coins to Lykke exchange. Depositing coins is not equal to trusting coins. How can it be? Lykke uses multisignatures mechanism to hold client's funds. Lykke exchange can not spend any coins without a client's private key. Even if the exchange is compromised and the Lykke key is stolen, the client will not lose his coins. The second key is required to spend deposited coins. Lykke exchange also provides a refund mechanism to guarantee funds recovery in case of emergency.

Mentioned features are coming soon on top of the Ethereum blochchain. In this post you will find conceptual details of Ethereum settlement integration described. Ethereum-Bitcoin swap transactions to provide crosschain atomic exchange will be covered in further posts.

Standard Ethereum Token Contract

Unlike Bitcoin Сolored Сoins that are literally stored in the Bitcoin addresses, Ethereum tokens are just records in a single variable of an Ethereum smart contract.

A standard Ethereum token contract provides the following functions:

  • Issuing tokens when a smart contract is created. Initially all tokens are attributed to the contract creator.

  • Transfer function can be called by anyone who is recorded as a token owner (initially this could be the contract creator only). Transfer function updates two records in the internal contract ledger — subtracts the balance of the one who calls the transfer function and adds the same amount to recipient of the transfer specified by the caller. -

  • A standard token contract notifies those who subscribe for contract events about any internal token transfers.

  • Anyone on the net is able to read internal balances of the contract.

Ultimately a standard token contract on Ethereum blockchain is both a coin holders ledger and an interface (set of rules and functions) that allows to update internal contract ledger records in a proper way.

Figure 1 — Standard tokens contract

Extended Ethereum Token Contract

We would need to extend a standard token contract to provide the following functions:

  • Unlimited tokens issuance by the contract creator. One can make a deposit of fiat money to an issuer bank account so that the issuer would need to generate the corresponding amount of coins for the client.

  • Multisignature ledger for the balances controlled by both Exchange and client (see more about bitcoin multisignature wallets used by Lykke).

  • A client needs to be able to cash in/out multisignature deposit ledger.

Figure 2 — Extended tokens contract

As a result an extended token contract will have two ledgers:

  • The first ledger is the the ledger of private balances controlled by clients.

  • The second one is the ledger of balances reflecting coins deposited into the Exchange. Deposited coins are controlled by both Exchange and client.

To make a transfer of the deposited tokens from one address to another, the Main Exchange contract will be used. Only the Main Exchange contract can call the transfer function. The Main Exchange contract checks the confirmations of the parties before calling such transfers.

Figure 3 - Main Exchange contract

Only Lykke Exchange will be able to call the swap function to be sure that Lykke Exchange’s internal balances are synchronized with balances in the contract ledgers. Parties of a swap confirm each swap in the following way:

  • Exchange matches the parties’ orders and provides them with transaction parameters.

  • Each client calculates a hash of transaction parameters and sign the hash. Signatures are sent to Exchange.

  • Exchange sends two signatures into the Main Exchange Contract as parameters of the swap function.

  • Main Exchange Contract calculates the hash of the transaction and checks provided signatures.

If signatures are valid, the Main Exchange Contract calls the Transfer function of Extended tokens contracts.

An additional contract will be needed to deposit Ethers.

Figure 4 — Swaps with Ethers

It works in the same way as Extended Tokens Contract, but for the Ethers. It does not have the issuance function. But it has the deposit function.

Figure 5 — Ether Deposit Contract

Refunding Mechanism

An interesting feature of an Ethers Deposit Contract is the refund function. The refund function transfers one’s deposited Ethers into the specified address, if the Exchange is not alive during 30 days. The Exchange should call the Alive function at least once a month to block refunds. Normally ethers withdrawal should be confirmed by both client and Exchange.

Further Extensions

The proposed approach allows to create proxy contracts for holding other tokens issued on the Ethereum blockchain. For each type of token an adaptor proxy contract will be required to bridge the Main Exchange Contract interface with the arbitrary token contract interface.

Comments 0