Skip to content

Commit

Permalink
Merge pull request #515 from VenusProtocol/develop
Browse files Browse the repository at this point in the history
New release
  • Loading branch information
chechu authored Sep 10, 2024
2 parents c21d5b2 + 528fc04 commit 2f90c55
Show file tree
Hide file tree
Showing 234 changed files with 82,707 additions and 309,253 deletions.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ DEPLOYER_PRIVATE_KEY=
#ARCHIVE_NODE_arbitrumsepolia=https://sepolia-rollup.arbitrum.io/rpc
#ARCHIVE_NODE_xlayertestnet=https://rpc.ankr.com/xlayer_testnet/<YOUR_KEY_HERE>
#ARCHIVE_NODE_xlayermainnet=https://rpc.ankr.com/xlayer<YOUR_KEY_HERE>
#ARCHIVE_NODE_zksyncsepolia=https://zksync-sepolia.g.alchemy.com/v2/<YOUR_KEY_HERE>
#ARCHIVE_NODE_zksyncmainnet=https://open-platform.nodereal.io/<YOUR_KEY_HERE>/zksync
#ARCHIVE_NODE_opsepolia="https://sepolia.optimism.io"
#ARCHIVE_NODE_opmainnet="https://opt-mainnet.nodereal.io/v1/<YOUR_KEY_HERE>"


ETHERSCAN_API_KEY=
Expand Down
2 changes: 1 addition & 1 deletion .eslinttsconfigrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"extends": "./tsconfig.json",
"include": ["./typechain", "./deploy", "./tests", "./script", "./scenario", "saddle.config.js", "docgen-templates", "commitlint.config.js"]
"include": ["./typechain", "./deploy", "./tests", "./script", "./scenario", "saddle.config.js", "docgen-templates", "commitlint.config.js", "./hardhat.config.zksync.ts"]
}
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,14 @@ jobs:

- name: Export deployments
run: |
for NETWORK in bsctestnet bscmainnet ethereum sepolia opbnbtestnet opbnbmainnet arbitrumsepolia arbitrumone xlayertestnet xlayermainnet; do
for NETWORK in bsctestnet bscmainnet ethereum sepolia opbnbtestnet opbnbmainnet arbitrumsepolia arbitrumone xlayertestnet xlayermainnet opsepolia opmainnet; do
EXPORT=true yarn hardhat export --network ${NETWORK} --export ./deployments/${NETWORK}.json
jq -M '{name, chainId, addresses: .contracts | map_values(.address)}' ./deployments/${NETWORK}.json > ./deployments/${NETWORK}_addresses.json
done
for NETWORK in zksyncsepolia zksyncmainnet; do
EXPORT=true yarn hardhat export --network ${NETWORK} --export ./deployments/${NETWORK}.json --config hardhat.config.zksync.ts
jq -M '{name, chainId, addresses: .contracts | map_values(.address)}' ./deployments/${NETWORK}.json > ./deployments/${NETWORK}_addresses.json
done
yarn prettier
- uses: stefanzweifel/git-auto-commit-action@v5
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ junit.xml
# hardhat
typechain
artifacts
artifacts-zk
cache
cache-zk

# OZ
.openzeppelin/
Expand Down
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
**/.coverage_cache
**/.coverage_contracts
**/artifacts
**/artifacts-zk
**/build
**/cache
**/cache-zk
**/coverage
**/dist
**/node_modules
Expand Down
244 changes: 244 additions & 0 deletions CHANGELOG.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Venus Protocol

The Venus Protocol is a BNB Chain collection of 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 and suppliers.
The Venus Protocol is a BNB Chain collection of smart contracts 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 and suppliers.

Before getting started with this repo, please read:

Expand Down Expand Up @@ -58,7 +58,7 @@ We detail a few of the core contracts in the Venus protocol.

### Documentation

- Public documentation site: https://docs.venus.io, including autogernated documentation, guides, addresses of the deployment contracts and more content.
- Public documentation site: https://docs.venus.io, including autogenerated documentation, guides, addresses of the deployment contracts and more content.
- Documentation autogenerated using [solidity-docgen](https://github.com/OpenZeppelin/solidity-docgen).
- To generate the documentation from the natspec comments embedded in the contracts, use `yarn docgen`

Expand Down
Binary file added audits/099_unlistMarkets_certik_20240409.pdf
Binary file not shown.
Binary file added audits/102_unlistMarkets_fairyproof_20240328.pdf
Binary file not shown.
Binary file added audits/112_VBNBAdmin_certik_20240717.pdf
Binary file not shown.
10 changes: 10 additions & 0 deletions contracts/Admin/VBNBAdmin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ contract VBNBAdmin is ReentrancyGuardUpgradeable, AccessControlledV8, VBNBAdminS
emit ReservesReduced(reduceAmount);
}

/**
* @notice Sets the interest rate model of the vBNB contract
* @param newInterestRateModel Address of the new interest rate model
* @custom:access Controlled by ACM
*/
function setInterestRateModel(address newInterestRateModel) public returns (uint256) {
_checkAccessAllowed("setInterestRateModel(address)");
return vBNB._setInterestRateModel(newInterestRateModel);
}

/**
* @notice Wraps BNB into WBNB
*/
Expand Down
2 changes: 2 additions & 0 deletions contracts/Admin/VBNBAdminStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ interface VTokenInterface {
function _acceptAdmin() external returns (uint);

function comptroller() external returns (address);

function _setInterestRateModel(address newInterestRateModel) external returns (uint);
}

interface IWBNB is IERC20Upgradeable {
Expand Down
2 changes: 1 addition & 1 deletion contracts/Comptroller/ComptrollerStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ contract ComptrollerV3Storage is ComptrollerV2Storage {
/// @notice The borrowCapGuardian can set borrowCaps to any number for any market. Lowering the borrow cap could disable borrowing on the given market.
address public borrowCapGuardian;

/// @notice Borrow caps enforced by borrowAllowed for each vToken address. Defaults to zero which corresponds to unlimited borrowing.
/// @notice Borrow caps enforced by borrowAllowed for each vToken address.
mapping(address => uint256) public borrowCaps;
}

Expand Down
59 changes: 58 additions & 1 deletion contracts/Comptroller/Diamond/facets/MarketFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ contract MarketFacet is IMarketFacet, FacetBase {
/// @notice Emitted when the borrowing or redeeming delegate rights are updated for an account
event DelegateUpdated(address indexed approver, address indexed delegate, bool approved);

/// @notice Emitted when an admin unlists a market
event MarketUnlisted(address indexed vToken);

/// @notice Indicator that this is a Comptroller contract (for inspection)
function isComptroller() public pure returns (bool) {
return true;
Expand All @@ -33,7 +36,25 @@ contract MarketFacet is IMarketFacet, FacetBase {
* @return A dynamic list with the assets the account has entered
*/
function getAssetsIn(address account) external view returns (VToken[] memory) {
return accountAssets[account];
uint256 len;
VToken[] memory _accountAssets = accountAssets[account];
uint256 _accountAssetsLength = _accountAssets.length;

VToken[] memory assetsIn = new VToken[](_accountAssetsLength);

for (uint256 i; i < _accountAssetsLength; ++i) {
Market memory market = markets[address(_accountAssets[i])];
if (market.isListed) {
assetsIn[len] = _accountAssets[i];
++len;
}
}

assembly {
mstore(assetsIn, len)
}

return assetsIn;
}

/**
Expand Down Expand Up @@ -112,6 +133,42 @@ contract MarketFacet is IMarketFacet, FacetBase {
return results;
}

/**
* @notice Unlist a market by setting isListed to false
* @dev Checks if market actions are paused and borrowCap/supplyCap/CF are set to 0
* @param market The address of the market (vToken) to unlist
* @return uint256 0=success, otherwise a failure. (See enum Error for details)
*/
function unlistMarket(address market) external returns (uint256) {
ensureAllowed("unlistMarket(address)");

Market storage _market = markets[market];

if (!_market.isListed) {
return fail(Error.MARKET_NOT_LISTED, FailureInfo.UNLIST_MARKET_NOT_LISTED);
}

require(actionPaused(market, Action.BORROW), "borrow action is not paused");
require(actionPaused(market, Action.MINT), "mint action is not paused");
require(actionPaused(market, Action.REDEEM), "redeem action is not paused");
require(actionPaused(market, Action.REPAY), "repay action is not paused");
require(actionPaused(market, Action.ENTER_MARKET), "enter market action is not paused");
require(actionPaused(market, Action.LIQUIDATE), "liquidate action is not paused");
require(actionPaused(market, Action.SEIZE), "seize action is not paused");
require(actionPaused(market, Action.TRANSFER), "transfer action is not paused");
require(actionPaused(market, Action.EXIT_MARKET), "exit market action is not paused");

require(borrowCaps[market] == 0, "borrow cap is not 0");
require(supplyCaps[market] == 0, "supply cap is not 0");

require(_market.collateralFactorMantissa == 0, "collateral factor is not 0");

_market.isListed = false;
emit MarketUnlisted(market);

return uint256(Error.NO_ERROR);
}

/**
* @notice Removes asset from sender's account liquidity calculation
* @dev Sender must not have an outstanding borrow balance in the asset,
Expand Down
12 changes: 5 additions & 7 deletions contracts/Comptroller/Diamond/facets/PolicyFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,11 @@ contract PolicyFacet is IPolicyFacet, XVSRewardsHelper {
// Pausing is a very serious situation - we revert to sound the alarms
checkProtocolPauseState();
checkActionPauseState(vToken, Action.BORROW);

ensureListed(markets[vToken]);

uint256 borrowCap = borrowCaps[vToken];
require(borrowCap != 0, "market borrow cap is 0");

if (!markets[vToken].accountMembership[borrower]) {
// only vTokens may call borrowAllowed if borrower not in market
require(msg.sender == vToken, "sender must be vToken");
Expand All @@ -128,12 +130,8 @@ contract PolicyFacet is IPolicyFacet, XVSRewardsHelper {
return uint256(Error.PRICE_ERROR);
}

uint256 borrowCap = borrowCaps[vToken];
// Borrow cap of 0 corresponds to unlimited borrowing
if (borrowCap != 0) {
uint256 nextTotalBorrows = add_(VToken(vToken).totalBorrows(), borrowAmount);
require(nextTotalBorrows < borrowCap, "market borrow cap reached");
}
uint256 nextTotalBorrows = add_(VToken(vToken).totalBorrows(), borrowAmount);
require(nextTotalBorrows <= borrowCap, "market borrow cap reached");

(Error err, , uint256 shortfall) = getHypotheticalAccountLiquidityInternal(
borrower,
Expand Down
4 changes: 2 additions & 2 deletions contracts/Comptroller/Diamond/facets/SetterFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,9 @@ contract SetterFacet is ISetterFacet, FacetBase {

/**
* @notice Set the given borrow caps for the given vToken market Borrowing that brings total borrows to or above borrow cap will revert
* @dev Allows a privileged role to set the borrowing cap for a vToken market. A borrow cap of 0 corresponds to unlimited borrowing
* @dev Allows a privileged role to set the borrowing cap for a vToken market. A borrow cap of 0 corresponds to Borrow not allowed
* @param vTokens The addresses of the markets (tokens) to change the borrow caps for
* @param newBorrowCaps The new borrow cap values in underlying to be set. A value of 0 corresponds to unlimited borrowing
* @param newBorrowCaps The new borrow cap values in underlying to be set. A value of 0 corresponds to Borrow not allowed
*/
function _setMarketBorrowCaps(VToken[] calldata vTokens, uint256[] calldata newBorrowCaps) external {
ensureAllowed("_setMarketBorrowCaps(address[],uint256[])");
Expand Down
2 changes: 2 additions & 0 deletions contracts/Comptroller/Diamond/interfaces/IMarketFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ interface IMarketFacet {
function getAllMarkets() external view returns (VToken[] memory);

function updateDelegate(address delegate, bool allowBorrows) external;

function unlistMarket(address market) external returns (uint256);
}
34 changes: 34 additions & 0 deletions contracts/InterestRateModels/InterestRateModelV8.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
pragma solidity 0.8.25;

/**
* @title Venus's InterestRateModelV8 Interface
* @author Venus
*/
abstract contract InterestRateModelV8 {
/// @notice Indicator that this is an InterestRateModel contract (for inspection)
bool public constant isInterestRateModel = true;

/**
* @notice Calculates the current borrow interest rate per block
* @param cash The total amount of cash the market has
* @param borrows The total amount of borrows the market has outstanding
* @param reserves The total amnount of reserves the market has
* @return The borrow rate per block (as a percentage, and scaled by 1e18)
*/
function getBorrowRate(uint256 cash, uint256 borrows, uint256 reserves) external view virtual returns (uint256);

/**
* @notice Calculates the current supply interest rate per block
* @param cash The total amount of cash the market has
* @param borrows The total amount of borrows the market has outstanding
* @param reserves The total amnount of reserves the market has
* @param reserveFactorMantissa The current reserve factor the market has
* @return The supply rate per block (as a percentage, and scaled by 1e18)
*/
function getSupplyRate(
uint256 cash,
uint256 borrows,
uint256 reserves,
uint256 reserveFactorMantissa
) external view virtual returns (uint256);
}
Loading

0 comments on commit 2f90c55

Please sign in to comment.