BlueStone - Lending Protocol on Nervos

Project and Justification

BlueStone is an on-chain lending platform, in which lenders deposit tokens in a small contract to earn interests and borrowers use their token assets as collateral and borrow from the contract. Borrow interest is a function of pool utilization and deposit interest is a function of borrow interest, liquidity utilization.

Team and Background

The Bluestone team has already developed a fixed-rate lending protocol on Ethereum. Lenders could deposit tokens into the protocol with fixed terms and earn interests after term matures. Borrowers, however, get fixed-rate term loans secured by collaterals. We have deployed an alpha version of the protocol to the Rinkeby test-net. Check out the alpha version and landing page.

We will be focus on building a money market protocol on Nervos as it’s more early stage. We understand the difference between the development on Nervos and Ethereum, but with the knowledge we learned about blockchain and the experience we gained building BlueStone, we have the expertise to build a lending platform on Nervos as well.

Technical Design

Smart Contract

DATA STRUCTURES

  1. Liquidity Pools: a liquidity pool for each token, which contains

    • total_supply_amount
    • total_borrow_amount
    • global_supply_cir: global supply cumulative interest rate (CIR)
    • global_borrow_cir
    • last_action_time: the time of last action that changes the supply/borrow amounts or CIRs
  2. Accounts: an account for each user address, which contains

    • info: store some information for each token, which contains
      • supply_amount
      • supply_cir: user deposit CIR
      • borrow amount
      • borrow_cir: user borrow CIR
      • collateral_token
      • collateral_amount

    All data structures will be stored in a state cell.

CORE FUNCTIONS

  • AddCollateral()

  • Borrow()

  • LiquidateLoan()

  • Repay()

  • Supply()

  • Withdraw()

    All the above functions may change the utilization of a token pool, so they will always update global_deposit_cir, global_borrow_cir and last_action_time and relative variables of the user account data structure.

OTHER ADMIN FUNCTIONS

Web Client

UI to interact with our contract. We can follow our current product design and use ckb-sdk-js to interact with CKB.

Price Oracle

We need token price in CKB/USD from external sources in order to calculate collateral ratio in smart contract.

Liquidating Bot

Liquidating bot helps liquidators to get loan records that can be liquidated, and liquidate the specified record according to the filter set by the users.

Monitoring

Monitor the status of the contract, price oracle and other components, and alert us on certain conditions, e.g. pool liquidity is not sufficient or pool utilization is too high.

1 Like

@lu0ty Do you ever think about what kind of oracle for price feed is ideal for your lending protocol?

1 Like

Based on the market value of the project and the current volatility, is the operation of this mortgage possible?

if we want to use mortgage as collateral, the major issue is more about the oracle.
aka, whom can we trust to put the mortgage’s price on chain.

since the infra for nervos is not there yet(other defi, stablecoin, dex), we will need to use off-chain price (centralized exchange) and feed it to nervos chain. and we will add special check before we update price so that it won’t get manipulated.

1 Like

It is safer for you to add double check because even offline oracle has ever made some artificial mistake, like chainlink just sending wrong gold price to Synthetix .

yes. of course. using off-chain price oracle doesn’t mean we will just take price from off-chain source. for example, we can do this : when a contract function calls priceOracle.getPrice()` and the price has not been fetched in the last 2 hours, we will fetch the new price. If the new price changes by more than 1% and is in bound (boundary set by admin, to protect against price manipulation), we update the price.

1 Like

Yeah I think that it is a very hard question for whole DeFi field.
artificial <–ideal oracle -->Decentralized