Luxgate’s orderbook moved to Smart Contracts — Learn more about the latest technical updates

LUXCORE
Luxcore
Published in
4 min readSep 25, 2019

During the last month, we have made significant improvements to LuxGate by migrating all of the orderbooks over via LUX SmartContract. The global order book will now be secured by our SmartContract system in order to maximize control by the Luxcore chain itself and reduce possible points of failure.

Now, let’s take a deeper look at the specifications and technicalities of the Luxcore global order book and SmartContract system.

How it should be used

The mechanism solely plays the role of global bids and asks table and works regardless of the atomic swap LuxGate mechanism.

Expected scenario:

  1. Bob intends to trade 2 LUX for 1 BTC. He initiates a transaction by sending LUX to an instance of the smart contract: <addressA> => place(0, 2.0, 1.0, <addressB>). This method requires Bob to pay additional LUX as a deposit. Current amount is 10 LUX, it is used for testing purposes and not a final value. 0 stands for type of order (sell). It’s needed for stopping “spam” transactions and also creates an incentive to announce the order fulfilment by takemethod.
  2. Alice wants to see available orders and trade some BTC for some LUX. To see the list of open orders she has to read the contract logs from the block of SC deployment to the latest one. After accumulating the logs she gets the list of orders that may be processed.

    $ ./luxd getmarket LUX/BTC { “sell”: [ { “owner”: <addressB>, “price”: 1.0, “quantity”: 2.0 } ], “buy”: [ … ] }
  3. For instance, she has chosen to start an atomic swap with Bob’s order (that has address <addressB>). Then she sends in the network an order matching to Bob’s (via LuxGate p2p protocol). If Bob is still online, he receives the message. The participants perform atomic swap over the P2P protocol. This procedure is partially off-chain.
  4. After the swap, Bob wants to return the deposited LUX coins sent by place SC method. He sents a transaction to the contract <addressB> => take(<orderId>). The contract checks if Bob has some deposit in its storage. If he does, the coins will be sent back to him.
  5. After the coins have been returned to Bob another person fetches logs of the contract and considers Bob’s order as finished.

Terms:

  • addressA — An address with UTXOs with the total value is equal or greater than order placing deposit and gas for evaluating call transaction
  • addressB — An address that is not equal to addressA and should be used for retrieving the deposit back.

The implementation of global order book over SC VM allows easily reach consensus about the current state of the order book and accelerates the process of integration of new functionality into it.

Technical notes

It’s impossible to call both the methods using the same sender address. The input address of place call mustn’t equal to transaction sender address. The passed as argument address must equal to further take sender address.

API prototype

addmarket

addmarket “trade_pair” “smart_contract_address”

Add market to list of known markets. The smart contract must be deployed in blockchain.

This operation does not send any transactions and spend coins. Before placing orders on a market you must add it using this method.

Note: This method will likely be removed in mainnet because all markets will be deployed and presented in the list by default.

Arguments:

  1. trade_pair (string, required) The name market will be called
  2. smart_contract_address (string, required) Address of corresponding smart contract in LUX blockchain3. deployment_block (string, optional) Deployment block of the contract.

Result is empty

Examples: addmarket LUX/BTC 835fca3e63b00c93520e2788c225c17e325e33c6 45143

getmarket

getmarket “trade_pair”

List bids and asks in the specified market.

You must add the market using addmarket before calling this method.

Arguments:

  1. trade_pair (string, required) Market name

Result:

{ “sell”: [ { “owner”: (string) Address of the owner, plays the role of order id “price”: (numeric) Price value “quantity”: (numeric) Quantity value } ],
“buy”: [ … ]
}

Examples:

getmarket LUX/BTC

placeordertomarket

placeordertomarket “trade_pair” “order_type” “amount” “price” “refund_address”

Places new order on specified market

You must add the market using addmarket before calling this method.

Arguments:

  1. trade_pair (string, required) Market name
  2. order_type (string, required) Type of the order (“buy” or “sell”)3. amount (string, required) Amount of base coins to trade. E.g. for “LUX/BTC” pair, amount is the number of LUX to trade
  3. price (string, required) Price of 1 base coin in quote coins. E.g. for “LUX/BTC” pair, price is the amount of BTC for 1 LUX
  4. refund_address (string, required) LUX address that will be used to return deposit

Result:

[ { “txid” : (string) The transaction id. “sender” : (string) LUX address of the sender. “hash160” : (string) ripemd-160 hash of the sender. “refund_address” : (string) ripemd-160 hash of the refund address. } ]

Examples: placeordertomarket LUX/BTC sell 5.0 0.000051000 LMBx3NRbsPVL3iAbgh67nJQ8oziY9ZXYtf

takeorderfrommarket

takeorderfrommarket “trade_pair” “refund_address”

Refund previously placed order to the specified market

You must add the market using addmarket before calling this method.

Arguments:

  1. trade_pair (string, required) Market name
  2. refund_address (string, required) Address used in creation of the order

Result:

[ { “txid” : (string) The transaction id. “sender” : (string) LUX address of the sender. “hash160” : (string) ripemd-160 hash of the sender. } ]

Examples: takeorderfrommarket LUX/BTC LVoer5HSxqvnoBBWgfhGneN3g3d4TzXLtN

--

--