folder Filed in Development

How the Swap.online dApp orderbook works above the IPFSpubsub

Have a look: the secrets of how we use IPFSpubsub for the order matching
Vladislav Sopov comment 0 Comments

This post is also available in: Русский (Russian)

Order – is a public announcement about the fact that user is ready to exchange cryptocurrency X for the cryptocurrency Y.

Orderbook – is the effective lists of orders used by users to find each other and exchange cryptocurrencies promptly.

On both centralized and semi-decentralized exchanges (e.g. IDEX) orderbook is stored on the basic server. Thus, the server owner is responsible for the matching between buyers and sellers, similarly to the owners of torrent-trackers.

So, the decentralized orderbook addresses the elimination of the administrator’s influence on the exchange processes and on online order matching.
We have solved this problem via the ipfs pubsub library means.

So, how does it work?

  1. We launch the ipfs library and ipfs-pub-sub-room (https://github.com/ipfs-shipyard/ipfs-pubsub-room#use )
  2. We set external public signal server to find the first peer in network (https://github.com/swaponline/swap.react/blob/master/config/mainnet/ipfs.js )
  3. User comes and gets connected to some other users. Imagine, they are in the same chat room. This information is shown in the bottom of the page.
4. User sends the order via the interface.

      5.The order is formed and sent through the libp2p library here (https://github.com/swaponline/swap.core/blob/master/src/swap.orders/SwapOrders.js#L317 ).

6. Every message is signed by the private key from the Ethereum network and then checked through web3.ecrecover (https://github.com/swaponline/swap.core/blob/master/src/swap.room/SwapRoom.js#L174)
7. Swap.online dApp receives the avaliable orders and shows it to the users.

8. Moreover, this orderbook is analyzed during the exchange via the simplified interface, where the user enters only the sum for exchange and gets the request with the most profitable order

Full range of messages transferred via the IPFS system:

  • ready
  • user online
  • user offline
  • new orders
  • new order
  • remove order
  • hide orders
  • show orders
  • accept request
  • decline request
  • request swap
  • new order request
  • accept swap request
  • request partial fulfilment
  • accept partial fulfilment
  • decline partial fulfilment
  • new partial fulfilment request

and some messages inside the swap.

how it works