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.
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.
- 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
-
Updating the Comptroller
- 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.
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`
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.
Jest contract tests are defined under the tests directory. To run the tests run:
yarn test
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.
To run code coverage, run:
yarn coverage
To lint the code, run:
yarn lint
_© Copyright 2022, Onyx Protocol