Code Monkey home page Code Monkey logo

Onyx Protocol

The Onyx Protocol is an Ethereum smart contract for supplying or borrowing assets. Through the oToken contracts, accounts on the blockchain supply capital (Ether or ERC-20 tokens) to receive oTokens or borrow assets from the protocol (holding other assets as collateral). The Onyx oToken contracts track these balances and algorithmically set interest rates for borrowers.

Contracts

We detail a few of the core contracts in the Onyx protocol.

OToken, OErc20 and OEther
The Onyx oTokens, which are self-contained borrowing and lending contracts. OToken contains the core logic and OErc20 and OEther add public interfaces for Erc20 tokens and ether, respectively. Each OToken is assigned an interest rate and risk model (see InterestRateModel and Comptroller sections), and allows accounts to *mint* (supply capital), *redeem* (withdraw capital), *borrow* and *repay a borrow*. Each OToken is an ERC-20 compliant token where balances represent ownership of the market.
Comptroller
The risk model contract, which validates permissible user actions and disallows actions if they do not fit certain risk parameters. For instance, the Comptroller enforces that each borrowing user must maintain a sufficient collateral balance across all oTokens.
    Updating the Comptroller
  • Follow the existing naming schema (ControllerGX)
  • Update the scenario runner in scenario/src/Builder/ComptrollerImplBuilder.ts
  • Create unit tests and fork simulations as necessary
  • Call npx saddle deploy Comptroller -n mainnet to deploy to mainnet and generate new ABI
    • The ABI can also be generated by deploying to mainnet in a fork simulation
  • Call node script/comptroller-abi to merge the new Comptroller ABI with the Unitroller ABI
  • Ensure that commit contains new generated Comptroller ABI
InterestRateModel
Contracts which define interest rate models. These models algorithmically determine interest rates based on the current utilization of a given market (that is, how much of the supplied assets are liquid versus borrowed).
Careful Math
Library for safe math operations.
ErrorReporter
Library for tracking error codes and failure conditions.
Exponential
Library for handling fixed-point decimal numbers.
SafeToken
Library for safely handling Erc20 interaction.
WhitePaperInterestRateModel
Initial interest rate model, as defined in the Whitepaper. This contract accepts a base rate and slope parameter in its constructor.

Installation

To run onyx, pull the repository from GitHub and install its dependencies. You will need yarn or npm installed.

git clone https://github.com/onyx-finance/onyx-protocol
cd onyx-protocol
yarn install --lock-file # or `npm install`

REPL

The Onyx Protocol has a simple scenario evaluation tool to test and evaluate scenarios which could occur on the blockchain. This is primarily used for constructing high-level integration tests. The tool also has a REPL to interact with local the Onyx Protocol (similar to truffle console).

yarn repl -n development
yarn repl -n rinkeby

> Read OToken oBAT Address
Command: Read OToken oBAT Address
AddressV<val=0xAD53863b864AE703D31b819d29c14cDA93D7c6a6>

You can read more about the scenario runner in the Scenario Docs on steps for using the repl.

Testing

Jest contract tests are defined under the tests directory. To run the tests run:

yarn test

Integration Specs

There are additional tests under the spec/scenario folder. These are high-level integration tests based on the scenario runner depicted above. The aim of these tests is to be highly literate and have high coverage in the interaction of contracts.

Code Coverage

To run code coverage, run:

yarn coverage

Linting

To lint the code, run:

yarn lint

_© Copyright 2022, Onyx Protocol

Onyx Protocol's Projects

assets icon assets

A comprehensive, up-to-date collection of information about several thousands (!) of crypto tokens.

examples icon examples

Example of liquidation and supply-borrow-repay-redeem mechanism

oip icon oip

Onyx Improvement Proposals Directory

onyx-protocol icon onyx-protocol

Onyx Protocol is a decentralized liquidity protocol that supports digital assets such as Ether, tokens and NFTs.

onyxcoin icon onyxcoin

Chain Token (XCN) Smart Contracts & Audits

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.