Venus Protocol contracts are divided in three repositories:
There are 2 categories of isolated pools contracts:
- Risk Management
Pool contracts can be divided into 4 categories:
Configuration contracts are used to deploy, configure, and manage pools.
The Comptroller contract is the central contract for each lending pool. It contains functionality central to borrowing activity in the pool like supplying and borrowing assets and liquidations. Configuration values for the pool such as the liquidation incentive, close factor, and collateral factor can also be set and retrieved from the comptroller. Account liquidity and positions can also be retrieved from the comptroller.
Isolated Pools use additional contracts such as lenses, rewards, ect.
To make querying pool data easier, Isolated Pools contains a lens that queries and formats pool data. These calls can be gas intensive so as a general rule of thumb this contract should not be used in transactions.
Lending comes with the inherent risk that borrows will not be able to repay their loan, which is a threat to the protocol's insolvency. Venus mitigates this risk with a RiskFund. A percentage of protocol revenues is transferred to the RiskFund as it is accrued. When bad debt is detected, this fund can be auctioned off and used to cover the bad debt.
Venus Protocol implements secondary, primary and pivot oracles to create a validation and fallback strategy that avoids creating a single point of a failure by relying on a single source for prices. The ResilientOracle contract is responsible for fetching and validating prices for a given vToken and managing which oracles are used for a particular vToken.
The TWAP (Time Weighted Average Price) Oracle is mainly used as a [pivot oracle] for validation but can also be used as a primary source if a token isn't supported by the primary and secondary oracles.
Venus Protocol contracts can be grouped as follows:
At the heart of the Core Pool is the comptroller. The latest version is Comptroller. Previous versions are also kept in the repo. The comptroller is responsible for listing markets, managing user's positions in markets, liquidations, and emitting rewards. It contains setters and getters for market configuration variables such as collateral factor, close factor, and liquidation incentive. Lending actions can be be paused globally or per market from the comptroller.
Each market gets deployed with an interest rate model. The JumpRateModel uses a linear curve to determine interest rates based on supply and demand of the asset until it reaches the kink after which there is a sharp increase in rates.
Another interest rate model that can be deployed with markets is the WhitePaperInterestRateModel. It is similar to the JumpRateModel except it doesn't include a kink. Instead it contains a fixed base rate.
XVS is an important token in the Venus ecosystem because it powers Venus governance. The XVS token contract defines a lockable BEP20 token with additional methods that enable voting and vote delegation. To vote, a user must first lock their XVS in the vault. The XVSVesting controlled XVS emissions when converting VRT to XVS. The time period to convert VRT to XVS has expired.
VAI is the Venus stable coin that can be minted against collateral. Users who mint VAI are charged a fee based on the outstanding supply and price of VAI to keep its value pegged at $1. The VAIController controls the amount of VAI a user is allowed to mint which is determined by the collateral a user has provided and their liquidity.
When a user supplies a token to the protocol, vTokens are minted to represent their supply. The VToken contract contains methods that support lending activities for the asset including lending, borrowing and liquidating
There are three main Governance contracts:
The core logic for governance proposals is in the GovernorBraveDelegate contract. It enables submitting proposals, moving proposals through time-gated stages, canceling and executing proposals as well as voting logic. The voting threshold as well as timelocks are set on this contract.
To enhance security of the protocol, Venus Protocol uses the AccessControlManager to grant accounts access to call specific functions on contracts. This contract is responsible for granting and revoking those permissions. It also provides a getter to check if an address is allowed to call a specific function.
Timelock Once a proposal has succeeded its execution is managed by the Timelock contract. The Timelock can place the proposal in a queue for execution and execute the proposal. It also enables canceling the proposal.