The Venus Protocol is an Binance Smart Chain smart contract for supplying or borrowing assets. Through the vToken contracts, accounts on the blockchain supply capital (BNB or BEP-20 tokens) to receive vTokens or borrow assets from the protocol (holding other assets as collateral). The protocol will also enable the minting of VAI, which is the first synthetic stablecoin on Venus that aims to be pegged to 1 USD. VAI is minted by the same collateral that is supplied to the protocol. The Venus vToken contracts track these balances and algorithmically set interest rates for borrowers.
Before getting started with this repo, please read:
Interested in contributing? Please checkout our contributing guidelines
We detail a few of the core contracts in the Venus protocol.
- VToken, VBep20 and VBNB
- The Venus vTokens, which are self-contained borrowing and lending contracts. VToken contains the core logic and VBep20, VBUSD, VSXP and VBNB add public interfaces for Bep20 tokens and bnb, respectively. Each VToken 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 VToken is an BEP-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 vTokens.
- XVS
- The Venus Governance Token (XVS). Holders of this token have the ability to govern the protocol via the governor contract.
- SXP
- The Venus Governance Token (SXP). Holders of this token have the ability to govern the protocol via the governor contract.
- Governor Alpha
- The administrator of the Venus timelock contract. Holders of XVS(SXP) token may create and vote on proposals which will be queued into the Venus timelock and then have effects on Venus vToken and Comptroller contracts. This contract may be replaced in the future with a beta version.
- 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 Bep20 interaction.
- WhitePaperInterestRateModel
- Initial interest rate model, as defined in the Whitepaper. This contract accepts a base rate and slope parameter in its constructor.
Documentation is autogenerated using solidity-docgen.
They can be generated by running yarn docgen
To run venus, pull the repository from GitHub and install its dependencies. You will need yarn or npm installed.
git clone https://github.com/VenusProtocol/venus-protocol
cd venus-protocol
yarn install --lock-file # or `npm install`
-
Solidity smart contracts in venus-protocol use
solc
version 0.5.16 -
To install solidity compiler
solc
, follow the instructions listed here:- clone
homebrew-ethereum
project that provides homebrew formulae forsolc
:
git clone git@github.com:ethereum/homebrew-ethereum.git
- change to project directory
cd homebrew-ethereum
- checkout the commit hash for version 0.5.16
git checkout 5df4d76a780813a0ad625619572afb358d46c1d4
- Install compiler version 0.5.16 by executing command
brew install solidity@5
- Verify the installed solidity version
solc --version
- the command should print the console log:
solc, the solidity compiler commandline interface Version: 0.5.16+commit.9c3226ce.Darwin.appleclang
- clone
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.
The Venus Protocol has a number of formal verification specifications, powered by Certik. The Certik Verification evaluates smart contracts for vulnerabilities and certifies their behavior with respect to a custom function specification.
Contract tests are defined under the tests directory. To run the tests run:
yarn test
- To run fork tests add
FORK_MAINNET=true
andBSC_ARCHIVE_NODE_URL
in the.env
file.
To run code coverage, run:
npx hardhat coverage
npx hardhat deploy
- This command will execute all the deployment scripts in
./deploy
directory - It will skip only deployment scripts which implement askip
condition - Here is example of a skip condition: - Skipping deployment script onbsctestnet
networkfunc.skip = async (hre: HardhatRuntimeEnvironment) => hre.network.name !== "bsctestnet";
- The default network will be
hardhat
- Deployment to another network: - Make sure the desired network is configured in
hardhat.config.ts
- AddMNEMONIC
variable in.env
file - Execute deploy command by adding--network <network_name>
in the deploy command above - E.g.npx hardhat deploy --network bsctestnet
- Execution of single or custom set of scripts is possible, if:
- In the deployment scripts you have added
tags
for example: -func.tags = ["MockTokens"];
- Once this is done, adding
--tags "<tag_name>,<tag_name>..."
to the deployment command will execute only the scripts containing the tags.
- In the deployment scripts you have added
In order to verify the source code of already deployed contracts, run:
npx hardhat etherscan-verify --network <network_name>
Make sure you have added ETHERSCAN_API_KEY
in .env
file.
To lint the code, run:
yarn lint
To format the code, run: yarn prettier
npx hardhat accounts
npx hardhat compile
npx hardhat clean
npx hardhat test
npx hardhat node
npx hardhat help
REPORT_GAS=true npx hardhat test
npx hardhat coverage
TS_NODE_FILES=true npx ts-node scripts/deploy.ts
npx eslint '**/*.{js,ts}'
npx eslint '**/*.{js,ts}' --fix
npx prettier '**/*.{json,sol,md}' --check
npx prettier '**/*.{json,sol,md}' --write
npx solhint 'contracts/**/*.sol'
npx solhint 'contracts/**/*.sol' --fix
MNEMONIC="<>" BSC_API_KEY="<>" npx hardhat run ./script/hardhat/deploy.ts --network testnet
For any concerns with the protocol, open an issue or visit us on Telegram to discuss.
For security concerns, please contact the administrators of our telegram chat.
© Copyright 2021, Venus Protocol