Skip to content

Commit

Permalink
Merge branch 'develop' into feature/VEN-1151-VEN-1152
Browse files Browse the repository at this point in the history
  • Loading branch information
GitGuru7 committed Oct 23, 2023
2 parents c88c986 + 02b305c commit 30116c6
Show file tree
Hide file tree
Showing 277 changed files with 34,932 additions and 44,990 deletions.
80 changes: 80 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,83 @@
## [2.1.0](https://github.com/VenusProtocol/isolated-pools/compare/v2.0.0...v2.1.0) (2023-10-19)


### Features

* add deployments of agEUR market ([667ac5f](https://github.com/VenusProtocol/isolated-pools/commit/667ac5feeedf0a7337258389f16110df864948cb))
* add info about the DefaultProxyAdmin used in testnet ([80f7a58](https://github.com/VenusProtocol/isolated-pools/commit/80f7a58f68ab0e949dcb8c5248123bf2ec4d9ba9))
* add reward distributor in agEUR market ([072714d](https://github.com/VenusProtocol/isolated-pools/commit/072714ded3dc712e9ed99748ff6a2da2adb94a02))
* add SnBNB market deployments ([add6956](https://github.com/VenusProtocol/isolated-pools/commit/add695693f9e835835e8e53a83dce81aaddfe29e))
* deploy PSR, RiskFund, Shortfall ([93408b1](https://github.com/VenusProtocol/isolated-pools/commit/93408b18da5a390869aab251354789910416c80e))
* set needed dependency to allow the deployment of SwapRouter ([96a684f](https://github.com/VenusProtocol/isolated-pools/commit/96a684fb80775b82a0ea02c2afc383fb032a7c09))
* ven-1930 force liquidation ([b871eab](https://github.com/VenusProtocol/isolated-pools/commit/b871eabaf65322e54507c7c8e3aae1db3aa9aa66))


### Bug Fixes

* added support for core pool assets in risk fund ([e161438](https://github.com/VenusProtocol/isolated-pools/commit/e1614383fe6a24b098c98ff509ce2f7e84e4e2bc))
* CVP-03 ([ebc9a9b](https://github.com/VenusProtocol/isolated-pools/commit/ebc9a9b043064e6fe4af2ac48fdc24e24eddba58))
* CVP-04 ([f4e8d2b](https://github.com/VenusProtocol/isolated-pools/commit/f4e8d2b5517ad6b104cffcdbe03c9eb2fd94ddbc))
* fixed build ([82166e5](https://github.com/VenusProtocol/isolated-pools/commit/82166e505b87c90d602a1eaff78253fe55376aaa))
* fixed integration tests ([31a4c44](https://github.com/VenusProtocol/isolated-pools/commit/31a4c449a1386f8bb222a3263cc0b39aeec4b85a))
* fixed tests ([635e206](https://github.com/VenusProtocol/isolated-pools/commit/635e2062bb972e5fa1949b2879d657d715b412d5))
* pr comments ([cbd9b18](https://github.com/VenusProtocol/isolated-pools/commit/cbd9b18a99c4e1f92bf9404e88fceb8ebc36d55f))
* redeployed risk fund implementation ([35d7139](https://github.com/VenusProtocol/isolated-pools/commit/35d7139b1de2c29815f5d4c691cb316b3a1a7c0c))
* removed only ([133ccd1](https://github.com/VenusProtocol/isolated-pools/commit/133ccd1dca4c020e6a8c773408ca278aac7e3536))
* resolved conflict ([b712134](https://github.com/VenusProtocol/isolated-pools/commit/b7121344c344a11c2a06eb4a17e53e73d847a7d1))
* use PoolRegistry interface ([761b0e1](https://github.com/VenusProtocol/isolated-pools/commit/761b0e1386ea27db1a410c29be7ad2bc3e5109aa))

## [2.1.0-dev.8](https://github.com/VenusProtocol/isolated-pools/compare/v2.1.0-dev.7...v2.1.0-dev.8) (2023-10-18)


### Features

* ven-1930 force liquidation ([b871eab](https://github.com/VenusProtocol/isolated-pools/commit/b871eabaf65322e54507c7c8e3aae1db3aa9aa66))


### Bug Fixes

* CVP-03 ([ebc9a9b](https://github.com/VenusProtocol/isolated-pools/commit/ebc9a9b043064e6fe4af2ac48fdc24e24eddba58))
* CVP-04 ([f4e8d2b](https://github.com/VenusProtocol/isolated-pools/commit/f4e8d2b5517ad6b104cffcdbe03c9eb2fd94ddbc))
* pr comments ([cbd9b18](https://github.com/VenusProtocol/isolated-pools/commit/cbd9b18a99c4e1f92bf9404e88fceb8ebc36d55f))

## [2.1.0-dev.7](https://github.com/VenusProtocol/isolated-pools/compare/v2.1.0-dev.6...v2.1.0-dev.7) (2023-10-18)


### Bug Fixes

* added support for core pool assets in risk fund ([e161438](https://github.com/VenusProtocol/isolated-pools/commit/e1614383fe6a24b098c98ff509ce2f7e84e4e2bc))
* fixed build ([82166e5](https://github.com/VenusProtocol/isolated-pools/commit/82166e505b87c90d602a1eaff78253fe55376aaa))
* fixed integration tests ([31a4c44](https://github.com/VenusProtocol/isolated-pools/commit/31a4c449a1386f8bb222a3263cc0b39aeec4b85a))
* fixed tests ([635e206](https://github.com/VenusProtocol/isolated-pools/commit/635e2062bb972e5fa1949b2879d657d715b412d5))
* redeployed risk fund implementation ([35d7139](https://github.com/VenusProtocol/isolated-pools/commit/35d7139b1de2c29815f5d4c691cb316b3a1a7c0c))
* removed only ([133ccd1](https://github.com/VenusProtocol/isolated-pools/commit/133ccd1dca4c020e6a8c773408ca278aac7e3536))
* resolved conflict ([b712134](https://github.com/VenusProtocol/isolated-pools/commit/b7121344c344a11c2a06eb4a17e53e73d847a7d1))
* use PoolRegistry interface ([761b0e1](https://github.com/VenusProtocol/isolated-pools/commit/761b0e1386ea27db1a410c29be7ad2bc3e5109aa))

## [2.1.0-dev.6](https://github.com/VenusProtocol/isolated-pools/compare/v2.1.0-dev.5...v2.1.0-dev.6) (2023-10-10)

## [2.1.0-dev.5](https://github.com/VenusProtocol/isolated-pools/compare/v2.1.0-dev.4...v2.1.0-dev.5) (2023-10-10)


### Features

* add info about the DefaultProxyAdmin used in testnet ([80f7a58](https://github.com/VenusProtocol/isolated-pools/commit/80f7a58f68ab0e949dcb8c5248123bf2ec4d9ba9))

## [2.1.0-dev.4](https://github.com/VenusProtocol/isolated-pools/compare/v2.1.0-dev.3...v2.1.0-dev.4) (2023-10-10)


### Features

* add deployments of agEUR market ([667ac5f](https://github.com/VenusProtocol/isolated-pools/commit/667ac5feeedf0a7337258389f16110df864948cb))
* add reward distributor in agEUR market ([072714d](https://github.com/VenusProtocol/isolated-pools/commit/072714ded3dc712e9ed99748ff6a2da2adb94a02))

## [2.1.0-dev.3](https://github.com/VenusProtocol/isolated-pools/compare/v2.1.0-dev.2...v2.1.0-dev.3) (2023-09-29)


### Features

* add SnBNB market deployments ([add6956](https://github.com/VenusProtocol/isolated-pools/commit/add695693f9e835835e8e53a83dce81aaddfe29e))

## [2.1.0-dev.2](https://github.com/VenusProtocol/isolated-pools/compare/v2.1.0-dev.1...v2.1.0-dev.2) (2023-09-18)

## [2.1.0-dev.1](https://github.com/VenusProtocol/isolated-pools/compare/v2.0.1-dev.1...v2.1.0-dev.1) (2023-09-15)
Expand Down
139 changes: 0 additions & 139 deletions Makefile

This file was deleted.

Binary file added audits/078_forcedLiquidations_certik_20231016.pdf
Binary file not shown.
38 changes: 23 additions & 15 deletions contracts/Comptroller.sol
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ contract Comptroller is
/// @notice Emitted when a market is supported
event MarketSupported(VToken vToken);

/// @notice Emitted when forced liquidation is enabled or disabled for a market
event IsForcedLiquidationEnabledUpdated(address indexed vToken, bool enable);

/// @notice Thrown when collateral factor exceeds the upper bound
error InvalidCollateralFactor();

Expand Down Expand Up @@ -462,8 +465,8 @@ contract Comptroller is

uint256 borrowBalance = VToken(vTokenBorrowed).borrowBalanceStored(borrower);

/* Allow accounts to be liquidated if the market is deprecated or it is a forced liquidation */
if (skipLiquidityCheck || isDeprecated(VToken(vTokenBorrowed))) {
/* Allow accounts to be liquidated if it is a forced liquidation */
if (skipLiquidityCheck || isForcedLiquidationEnabled[vTokenBorrowed]) {
if (repayAmount > borrowBalance) {
revert TooMuchRepay();
}
Expand Down Expand Up @@ -983,6 +986,24 @@ contract Comptroller is
_setMaxLoopsLimit(limit);
}

/**
* @notice Enables forced liquidations for a market. If forced liquidation is enabled,
* borrows in the market may be liquidated regardless of the account liquidity
* @param vTokenBorrowed Borrowed vToken
* @param enable Whether to enable forced liquidations
*/
function setForcedLiquidation(address vTokenBorrowed, bool enable) external {
_checkAccessAllowed("setForcedLiquidation(address,bool)");
ensureNonzeroAddress(vTokenBorrowed);

if (!markets[vTokenBorrowed].isListed) {
revert MarketNotListed(vTokenBorrowed);
}

isForcedLiquidationEnabled[vTokenBorrowed] = enable;
emit IsForcedLiquidationEnabledUpdated(vTokenBorrowed, enable);
}

/**
* @notice Determine the current account liquidity with respect to liquidation threshold requirements
* @dev The interface of this function is intentionally kept compatible with Compound and Venus Core
Expand Down Expand Up @@ -1182,19 +1203,6 @@ contract Comptroller is
return _actionPaused[market][action];
}

/**
* @notice Check if a vToken market has been deprecated
* @dev All borrows in a deprecated vToken market can be immediately liquidated
* @param vToken The market to check if deprecated
* @return deprecated True if the given vToken market has been deprecated
*/
function isDeprecated(VToken vToken) public view returns (bool) {
return
markets[address(vToken)].collateralFactorMantissa == 0 &&
actionPaused(address(vToken), Action.BORROW) &&
vToken.reserveFactorMantissa() == MANTISSA_ONE;
}

/**
* @notice Add the market to the borrower's "assets in" for liquidity calculations
* @param vToken The market to enter
Expand Down
5 changes: 4 additions & 1 deletion contracts/ComptrollerStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ contract ComptrollerStorage {
// Used to check if rewards distributor is added
mapping(address => bool) internal rewardsDistributorExists;

/// @notice Flag indicating whether forced liquidation enabled for a market
mapping(address => bool) public isForcedLiquidationEnabled;

uint256 internal constant NO_ERROR = 0;

// closeFactorMantissa must be strictly greater than this value
Expand All @@ -123,5 +126,5 @@ contract ComptrollerStorage {
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[50] private __gap;
uint256[49] private __gap;
}
54 changes: 50 additions & 4 deletions contracts/RiskFund/ReserveHelpers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { SafeERC20Upgradeable } from "@openzeppelin/contracts-upgradeable/token/
import { ensureNonzeroAddress } from "../lib/validators.sol";
import { ComptrollerInterface } from "../ComptrollerInterface.sol";
import { PoolRegistryInterface } from "../Pool/PoolRegistryInterface.sol";
import { VToken } from "../VToken.sol";

contract ReserveHelpers is Ownable2StepUpgradeable {
using SafeERC20Upgradeable for IERC20Upgradeable;
Expand All @@ -16,6 +17,18 @@ contract ReserveHelpers is Ownable2StepUpgradeable {

uint256 private constant ENTERED = 2;

// Address of the core pool's comptroller
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
address public immutable CORE_POOL_COMPTROLLER;

Check warning on line 22 in contracts/RiskFund/ReserveHelpers.sol

View workflow job for this annotation

GitHub Actions / Lint

Variable name must be in mixedCase

// Address of the VBNB
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
address public immutable VBNB;

Check warning on line 26 in contracts/RiskFund/ReserveHelpers.sol

View workflow job for this annotation

GitHub Actions / Lint

Variable name must be in mixedCase

// Address of the native wrapped token
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
address public immutable NATIVE_WRAPPED;

Check warning on line 30 in contracts/RiskFund/ReserveHelpers.sol

View workflow job for this annotation

GitHub Actions / Lint

Variable name must be in mixedCase

// Store the previous state for the asset transferred to ProtocolShareReserve combined(for all pools).
mapping(address => uint256) public assetsReserves;

Expand Down Expand Up @@ -56,6 +69,17 @@ contract ReserveHelpers is Ownable2StepUpgradeable {
status = NOT_ENTERED;
}

/// @custom:oz-upgrades-unsafe-allow constructor
constructor(address corePoolComptroller_, address vbnb_, address nativeWrapped_) {
ensureNonzeroAddress(corePoolComptroller_);
ensureNonzeroAddress(vbnb_);
ensureNonzeroAddress(nativeWrapped_);

CORE_POOL_COMPTROLLER = corePoolComptroller_;
VBNB = vbnb_;
NATIVE_WRAPPED = nativeWrapped_;
}

/**
* @notice A public function to sweep accidental BEP-20 transfers to this contract. Tokens are sent to the address `to`, provided in input
* @param _token The address of the BEP-20 token to sweep
Expand Down Expand Up @@ -102,10 +126,7 @@ contract ReserveHelpers is Ownable2StepUpgradeable {
require(ComptrollerInterface(comptroller).isComptroller(), "ReserveHelpers: Comptroller address invalid");
address poolRegistry_ = poolRegistry;
require(poolRegistry_ != address(0), "ReserveHelpers: Pool Registry address is not set");
require(
PoolRegistryInterface(poolRegistry_).getVTokenForAsset(comptroller, asset) != address(0),
"ReserveHelpers: The pool doesn't support the asset"
);
require(ensureAssetListed(comptroller, asset), "ReserveHelpers: The pool doesn't support the asset");

uint256 currentBalance = IERC20Upgradeable(asset).balanceOf(address(this));
uint256 assetReserve = assetsReserves[asset];
Expand All @@ -119,4 +140,29 @@ contract ReserveHelpers is Ownable2StepUpgradeable {
emit AssetsReservesUpdated(comptroller, asset, balanceDifference);
}
}

function isAssetListedInCore(address tokenAddress) internal view returns (bool isAssetListed) {
VToken[] memory coreMarkets = ComptrollerInterface(CORE_POOL_COMPTROLLER).getAllMarkets();

for (uint256 i; i < coreMarkets.length; ++i) {
isAssetListed = (VBNB == address(coreMarkets[i]))
? (tokenAddress == NATIVE_WRAPPED)
: (coreMarkets[i].underlying() == tokenAddress);

if (isAssetListed) {
break;
}
}
}

/// @notice This function checks for the given asset is listed or not
/// @param comptroller Address of the comptroller
/// @param asset Address of the asset
function ensureAssetListed(address comptroller, address asset) internal view returns (bool) {
if (comptroller == CORE_POOL_COMPTROLLER) {
return isAssetListedInCore(asset);
}

return PoolRegistryInterface(poolRegistry).getVTokenForAsset(comptroller, asset) != address(0);
}
}
Loading

0 comments on commit 30116c6

Please sign in to comment.