nBook. nDAI (Near DAI) works as a price asset, which can be obtained by locking DAI (ETH erc20 token) using Rainbow Bridge."> nBook. nDAI (Near DAI) works as a price asset, which can be obtained by locking DAI (ETH erc20 token) using Rainbow Bridge."> nBook. nDAI (Near DAI) works as a price asset, which can be obtained by locking DAI (ETH erc20 token) using Rainbow Bridge.">

It is an On-Chain orderbook implemented using Rust. By "On-chain", We mean that the matching engine is implemented as a smart contract on the near blockchain. It allows users to create Limit Orders. Currently, It supports one market nDAI <-> nBook. nDAI (Near DAI) works as a price asset, which can be obtained by locking DAI (ETH erc20 token) using Rainbow Bridge.

Inspiration:

The AMM suffers from impermanent loss which can be a huge problem for liquidity providers. AMM's also suffer from high slippage and arbitrage. We thought it would be nice to implement an On-Chain order book on top of the NEAR protocol as NEAR is scalable and less costly than many other blockchain platforms such as Ethereum, BCH, etc. The NEAR Rainbow bridge is an added advantage as one can easily move assets from ETH to NEAR and vice-versa.

Description:

Smart Contract

The implemented orderbook is fully decentralized. It's written in Rust programming language. In the current implementation, the Price Asset is nDAI, and Order Asset is nBook.

nDAI is a Mintable NEAR token which can be obtained by locking DAI (ETH erc20 token) on the locker contract using Rainbow Bridge. nBook is also a NEAR token.

Currently, the order book supports Limit Orders. The matching engine matches the order based on Ask & Bid price. The order will get instantly filled if there will be a match. The order might be filled partially if there is not enough quantity for the order.

For example:

If user A has created an order to buy 10 nBook. And in the pool, there is an instant match of 5 nBook then, the order will get partially filled and in the future, only the remaining 5 will get matched with new orders.

The smart contract support features like creating limit orders, canceling orders, to get current spread, to get bid, and ask orders. The smart-contract also has Market orders but that is not being used in the current implementation.

Frontend

The frontend is written in React.js. It has two main components:

  1. Orderbook Page 📖

    This page is for creating Limit orders. It displays the user's current balance. Also, one can see all buys & sells orders with the current price.

    From this page, You can go to rainbow bridge page for moving DAI on NEAR.

    https://s3-us-west-2.amazonaws.com/secure.notion-static.com/0c81302d-606a-4c82-8b5f-15b2eaec6f8b/nearbook.png

  2. Rainbow Bridge Page 🌈

    From this page, you can transfer DAI token to NEAR by locking DAI on the Locker contract. You can also use Reward Vault for getting 100 DAI tokens per address if you don't have any DAI. You can click on the NEAR logo on the top left for going back to the Orderbook page.

    https://s3-us-west-2.amazonaws.com/secure.notion-static.com/636c3f36-f2db-4da7-93d7-eef4f7bdd207/rainbow-bridge.png

Both pages have a sign out button for signing out and remove application authorization for automatic signing of the NEAR transaction on the user's behalf.

We have also implemented a Token Vault contract in solidity, which allows the new users to get 100 DAI (Eth erc20) token per address. If your DAI balance is zero and you haven't claimed 100 tokens from that address then, you will see a button to get 100 DAI on the rainbow bridge page.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/d22e550f-13c1-4e5d-ad24-c826b93fbd2b/vault.png

Links:

Working Application: princesinha19.github.io/nearbook