Protocol Lending
Protocol Lending is the feature that enables protocols and developers to leverage liquidity in Iron Bank without direct collateralization.
Overview
Protocol Lending allows protocols and developers to borrow assets without direct collateralization. The liquidity comes from the shared markets where users supply and borrow. That is, the same Interest Rate Model, Utilization Rate and Borrow APY apply to a Protocol Lending user. For more information about market stats, visit Iron Bank Markets.
Currently, the Protocol Lending feature is by permission only. The Iron Bank team reviews borrower's contracts and protocol model to come up with a risk assessment report, and the report is made public to the Iron Bank community. As mentioned, the Protocol Lending user borrows from the shared markets where normal users supply. Therefore, it is necessary to evaluate the Protocol Lending risk from all perspectives.
The Protocol Lending feature is called a "Credit Loan" as a dev shorthand.
Risk Assessment
Besides contract security, the Iron Bank team also reviews the protocol model to evaluate and confirm the following:
The borrower is a contract
The destination of fund is deterministic
Iron Bank is senior debt
To elaborate, the borrower must be a contract deployed on the chain of which it wishes to borrow, the borrowed funds go to where the contract predefines without exception, and Iron Bank must be the top priority for the contract to repay before the funds are distributed or utilized for other purposes. This is how we review the Protocol Lending requests, and also how we ensure the funds come back to Iron Bank eventually.
For risk assessment example, visit Alpha Homora Risk Assessment (Optimism).
Credit Limit
By having a credit limit, a Protocol Lending user can borrow to the limit from the designated market. It is decided by the Iron Bank team, depending on the risk assessment report.
A credit limit is set for a designated market. Meaning, a Protocol Lending user may not borrow more than their limit and they may only borrow predetermined tokens. For now, the Iron Bank team decides these settings depending on the risk assessment report.
Credit limit can be adjusted anytime by the admin multisig with a 2-hour timelock. If credit limit is decreased to the level lower than current borrowing, it would not affect the current borrowing but prevent Protocol Lending users from borrowing more than the new limit.
In times of emergency, the guardian can reduce the credit limit of any Protocol Lending address to $1 for a specific account without timelock, preventing the account from borrowing further.
Installation
Protocol Lending is an advanced concept aimed at protocol developers. You must have a good understanding of EVM, programming, and smart contracts to be able to proceed.
Installation and Setup
Install Brownie & Ganache-CLI, if you haven't already.
Sign up for Infura and generate an API key. Store it in the
WEB3_INFURA_PROJECT_ID
environment variable.
Optional Use
network-config.yaml
provided in the repo. NOTE: This will replace your network config globally
3. Sign up for Etherscan and generate an API key. This is required for fetching source codes of the mainnet contracts we will be interacting with. Store the API key in the ETHERSCAN_TOKEN
environment variable.
Optional Use
.env
fileMake a copy of
.env.example
Add the values for
ETHERSCAN_TOKEN
orOPSCAN_TOKEN
according to the network you are going to develop on.
4. Download the mix.
Basic Use
To perform a simple credit loan in a development environment:
1. Run scripts/setup_playground.py
to create an officer for our credit borrower and launch the console. This automatically launches Ganache on a forked mainnet.
2. Deploy the CreditBorrower.sol
contract.
3. Set the borrower to the newly deployed contract. We must do this because we only approved borrower contract that has been reviewed.
4. Borrow some DAI from Iron Bank.
5. Now we are ready to put our borrower into work!
Implementing Credit Loan Logic
contracts/CreditBorrower.sol
is where you implement your own logic for credit loans. In particular:
Fill in a way to calculate the total balance of the asset that are able to be repaid via
CreditBorrower.totalBalance()
Unwind enough of your position to payback debt via
CreditBorrower.askForRepay()
The destination of fund should be deterministic.
Iron Bank should be senior debt.
Decentralized oracle should be used to evaluate assets that are not the borrowed token.
All operations and roles will be reviewed by Iron Bank.
See the Iron Bank documentation on Credit Limit Assessment for more information.
Testing
To run the tests:
See the Brownie documentation for more detailed information on testing your project.
Debugging Failed Transactions
Use the --interactive
flag to open a console immediatly after each failing test:
Within the console, transaction data is available in the history
container:
Examine the TransactionReceipt
for the failed test to determine what went wrong. For example, to view a traceback:
To view a tree map of how the transaction executed:
See the Brownie documentation for more detailed information on debugging failed transactions.
Deployment
You should write your own deployment script and verify it on Etherscan. Submit the contract address to Iron Bank for review.
Resources
Iron Bank Credit Limit Assessment documentation
Iron Bank Discord channel
Brownie Gitter channel
Last updated