Lykke Wallet Ethereum Integration

Lykke Wallet Ethereum Integration

Lykke Wallet Ethereum Integration

Mikhail 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. Each transaction must be signed by both parties 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 now available on top of the Ethereum blockchain. In this post you will find some technical details of Ethereum settlement integration. 

Lykke Ethereum Smart Contracts

Ethereum smart contracts used by Lykke are available via the following link

There are two layers of contracts (see the figure 1 below).

1. Multisignature protection layer implemented as Main Exchange Contract which is available for Lykke only

2. Money ownership layer implemented as an abstract Coin Contract which is available for noone but for Main Exchange Contract only. This contract actually owns all client’s funds deposited for trading with Lykke Exchange. There are 3 various types of the Coin Contract:

   a) Ethereum Contract which holds all client’s Ethers deposited for trading

   b) ERC20 adapter contract (to be implemented) which is the owner of all client’s ERC20 tokens deposited for trading

   c) Any arbitrary adapter contract that is not ERC20-compatible

 

Figure 1 — Lykke Trading Wallet Smart Contracts

Main Exchange Contract

Main Exchange contract verifies that any transaction made by Lykke is signed by a client that owns the money. The Main Exchange Contract address does not hold any Ethers or coins on the blockchain. 

Let’s examine CashOut function that Lykke calls when a client wants to withdraw his/her Ethers from the Trading wallet. The smart contract function first checks that the provided signature (“client_sign” parameter) corresponds to the required operation.  

function cashout(uint id, address coinAddress, address client, address to, uint amount, bytes client_sign, bytes params) onlyowner {

 

       //1. Check if the transaction is called more than once

       if (transactions[id])

           throw;

 

       //2. Check client’s signature

       bytes32 hash = sha3(id, coinAddress, client, to, amount);

           

       if (!_checkClientSign(client, hash, client_sign)) {

           throw;                    

       }

 

       //3. Call for cash out

       var coin_contract = Coin(coinAddress);

       coin_contract.cashout(client, to, amount);

 

       //4. Keep the transaction id

       transactions[id] = true;

   }

 

Thus Lykke is not able to make any withdrawals without the client’s signature. The signature is generated by the client with his private key using the Lykke Wallet app on the smartphone side. If the signature is correct the money owner contract is called to send the client’s money.  

Similar logic is implemented for all remaining functions that can spend the client’s money.  

Currently the Main Exchange Contract is deployed on the following address

ETH contract

The ETH contract is deployed at the following address

As one can see, it holds Ethers that belong to Lykke clients. The contract allows to transfer money if it’s called by the Main Exchange Contract.

Refunding Mechanism

The refund function implemented in the Main Exchange Contract allows a client to transfer deposited money to the specified address, if the Exchange is not alive during 30 days. The Exchange should ping the Main Exchange Contract Alive function at least once a month to block refunds. Normally money withdrawal should be confirmed by both the client and the Exchange.

Comments 0