Certora / nirn

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Nirn/Indexed Earn: A Compositional, Permissionless, Extensible Yield Aggregator

Nirn is a permissionless yield aggregator that optimizes interest rates for lenders across several lending protocols. The central idea is to allocate capital among multiple lending protocols in whatever ratios result in the greatest net interest rate.

Conceptually, Nirn is similar to Yearn's iTokens, Rari's yield pools and Idle Finance; however, it has a number of key distinctions:

Each Nirn vault can split its capital among several lending markets, and does not use permissioned rebalancer accounts to determine how it is split. Instead, optimal allocations can be calculated off-chain by anyone and suggested to the vault contract, which then verifies that the suggested rebalance would increase the vault's net interest rate. This both prevents any reliance on the developers of Indexed and ensures that if a better allocation of capital is possible, anyone can make the vault use it.

Whitepaper available here (current version V1.0, updated 4th August 2021).

Testing

Set Up (Important)

This repository exclusively executes test against forks of mainnet Ethereum. In order to run the tests, you will need to add an API key for an RPC provider with archive capabilities.

Alchemy offers this as part of their free tier, so it is recommended that you create an account with them.

You can do so here.

Once you have your API key, create a .env file with the following line:

ALCHEMY_API_KEY="YOUR_API_KEY_HERE"

If you use a provider other than Alchemy, you will need to modify hardhat.config.ts to use a different RPC url.

Important Note: The first time you run tests, they will take quite a while to run. This is not an error - hardhat simply has to request a lot of data from the archive node in order to run the tests against a mainnet fork. Subsequent tests will be much faster because the data will be cached.

Running Tests

The first time you run tests, you must run yarn compile first, otherwise the test script will fail because the typechain/ directory will not exist and typescript will throw an error.

Run all tests

yarn test

Run specific test

yarn test ./test/test_file_path

Because this repository has tests for (almost) every specific token for each supported protocol, it is usually better to run tests individually.

Compile contracts and typescript interfaces

yarn compile

Compiles artifacts into artifacts/ and generates typechain interfaces in typechain/

Run solhint

yarn lint

Smart Contracts

Adapter Registry

The adapter registry records all protocol and token adapters. It is used by vaults to validate that token adapters are approved, used by protocol adapters to register token adapters they have deployed, and can be used for other meta queries both off-chain and on-chain.

Protocol Adapters

Protocol adapters are used to map out all of a protocol's lending markets, determine which are still active, deploy token adapters for each market and record them in a global registry.

Currently supports:

  • Aave V1
  • Aave V2
  • Compound
  • Cream
  • Iron Bank
  • Fulcrum (bzx)

Upcoming support:

  • DyDx
  • Rari Fuse

Token Adapters

Because lending protocols are all different, a single contract can not interact with them all directly without prior knowledge of which protocols to support. Token adapters allow vaults to interact with all of Nirn's supported protocols by creating a standard interface which abstracts all of the specific behavior needed to use them. This makes Nirn modular and future-proof: if new protocols are introduced with different interfaces, this system can support them if new adapters are added.

In addition to basic interactions with lending protocols, token adapters are responsible for handling any secondary rewards which accrue to depositors, such as COMP or stkAAVE.

Read more about token adapters

About


Languages

Language:Solidity 51.9%Language:TypeScript 47.1%Language:JavaScript 0.9%Language:Shell 0.0%