Merge branch 'protocol-2.5-fixes' into feat/remove-iscontract-check

This commit is contained in:
The3D 2021-07-19 02:55:22 +02:00
commit 341cf26890
38 changed files with 354 additions and 722 deletions

View File

@ -33,7 +33,6 @@ contract ATokensAndRatesHelper is Ownable {
uint256 reserveFactor; uint256 reserveFactor;
uint256 borrowCap; uint256 borrowCap;
uint256 supplyCap; uint256 supplyCap;
uint256 exposureCap;
bool stableBorrowingEnabled; bool stableBorrowingEnabled;
bool borrowingEnabled; bool borrowingEnabled;
} }
@ -74,8 +73,7 @@ contract ATokensAndRatesHelper is Ownable {
inputParams[i].asset, inputParams[i].asset,
inputParams[i].baseLTV, inputParams[i].baseLTV,
inputParams[i].liquidationThreshold, inputParams[i].liquidationThreshold,
inputParams[i].liquidationBonus, inputParams[i].liquidationBonus
inputParams[i].exposureCap
); );
if (inputParams[i].borrowingEnabled) { if (inputParams[i].borrowingEnabled) {

View File

@ -366,9 +366,9 @@ interface ILendingPool {
/** /**
* @dev Returns the user account data across all the reserves * @dev Returns the user account data across all the reserves
* @param user The address of the user * @param user The address of the user
* @return totalCollateralETH the total collateral in ETH of the user * @return totalCollateralBase the total collateral of the user in the base currency used by the price feed
* @return totalDebtETH the total debt in ETH of the user * @return totalDebtBase the total debt of the user in the base currency used by the price feed
* @return availableBorrowsETH the borrowing power left of the user * @return availableBorrowsBase the borrowing power left of the user in the base currency used by the price feed
* @return currentLiquidationThreshold the liquidation threshold of the user * @return currentLiquidationThreshold the liquidation threshold of the user
* @return ltv the loan to value of the user * @return ltv the loan to value of the user
* @return healthFactor the current health factor of the user * @return healthFactor the current health factor of the user
@ -377,9 +377,9 @@ interface ILendingPool {
external external
view view
returns ( returns (
uint256 totalCollateralETH, uint256 totalCollateralBase,
uint256 totalDebtETH, uint256 totalDebtBase,
uint256 availableBorrowsETH, uint256 availableBorrowsBase,
uint256 currentLiquidationThreshold, uint256 currentLiquidationThreshold,
uint256 ltv, uint256 ltv,
uint256 healthFactor uint256 healthFactor

View File

@ -159,13 +159,6 @@ interface ILendingPoolConfigurator {
**/ **/
event SupplyCapChanged(address indexed asset, uint256 supplyCap); event SupplyCapChanged(address indexed asset, uint256 supplyCap);
/**
* @dev Emitted when the exposure cap of a reserve is updated
* @param asset The address of the underlying asset of the reserve
* @param exposureCap The new exposure cap
**/
event ExposureCapChanged(address indexed asset, uint256 exposureCap);
/** /**
* @dev Emitted when the reserve decimals are updated * @dev Emitted when the reserve decimals are updated
* @param asset The address of the underlying asset of the reserve * @param asset The address of the underlying asset of the reserve
@ -301,15 +294,13 @@ interface ILendingPoolConfigurator {
* @param ltv The loan to value of the asset when used as collateral * @param ltv The loan to value of the asset when used as collateral
* @param liquidationThreshold The threshold at which loans using this asset as collateral will be considered undercollateralized * @param liquidationThreshold The threshold at which loans using this asset as collateral will be considered undercollateralized
* @param liquidationBonus The bonus liquidators receive to liquidate this asset. The values is always above 100%. A value of 105% * @param liquidationBonus The bonus liquidators receive to liquidate this asset. The values is always above 100%. A value of 105%
* @param exposureCap The exposure cap for the collateral reserve. If cap is reached, effective LTV = 0
* means the liquidator will receive a 5% bonus * means the liquidator will receive a 5% bonus
**/ **/
function configureReserveAsCollateral( function configureReserveAsCollateral(
address asset, address asset,
uint256 ltv, uint256 ltv,
uint256 liquidationThreshold, uint256 liquidationThreshold,
uint256 liquidationBonus, uint256 liquidationBonus
uint256 exposureCap
) external; ) external;
/** /**
@ -392,13 +383,6 @@ interface ILendingPoolConfigurator {
**/ **/
function setSupplyCap(address asset, uint256 supplyCap) external; function setSupplyCap(address asset, uint256 supplyCap) external;
/**
* @dev Updates the exposure cap of a reserve
* @param asset The address of the underlying asset of the reserve
* @param exposureCap The new exposure of the reserve
**/
function setExposureCap(address asset, uint256 exposureCap) external;
/** /**
* @dev Registers a new admin with rights on risk related configurations * @dev Registers a new admin with rights on risk related configurations
* @param admin The address of the admin to register * @param admin The address of the admin to register

View File

@ -18,29 +18,34 @@ import {SafeERC20} from '../dependencies/openzeppelin/contracts/SafeERC20.sol';
contract AaveOracle is IPriceOracleGetter, Ownable { contract AaveOracle is IPriceOracleGetter, Ownable {
using SafeERC20 for IERC20; using SafeERC20 for IERC20;
event WethSet(address indexed weth); event BaseCurrencySet(address indexed baseCurrency, uint256 baseCurrencyUnit);
event AssetSourceUpdated(address indexed asset, address indexed source); event AssetSourceUpdated(address indexed asset, address indexed source);
event FallbackOracleUpdated(address indexed fallbackOracle); event FallbackOracleUpdated(address indexed fallbackOracle);
mapping(address => IChainlinkAggregator) private assetsSources; mapping(address => IChainlinkAggregator) private assetsSources;
IPriceOracleGetter private _fallbackOracle; IPriceOracleGetter private _fallbackOracle;
address public immutable WETH; address public immutable BASE_CURRENCY;
uint256 public immutable BASE_CURRENCY_UNIT;
/// @notice Constructor /// @notice Constructor
/// @param assets The addresses of the assets /// @param assets The addresses of the assets
/// @param sources The address of the source of each asset /// @param sources The address of the source of each asset
/// @param fallbackOracle The address of the fallback oracle to use if the data of an /// @param fallbackOracle The address of the fallback oracle to use if the data of an
/// aggregator is not consistent /// aggregator is not consistent
/// @param baseCurrency the base currency used for the price quotes. If USD is used, base currency is 0x0
/// @param baseCurrencyUnit the unit of the base currency
constructor( constructor(
address[] memory assets, address[] memory assets,
address[] memory sources, address[] memory sources,
address fallbackOracle, address fallbackOracle,
address weth address baseCurrency,
uint256 baseCurrencyUnit
) public { ) public {
_setFallbackOracle(fallbackOracle); _setFallbackOracle(fallbackOracle);
_setAssetsSources(assets, sources); _setAssetsSources(assets, sources);
WETH = weth; BASE_CURRENCY = baseCurrency;
emit WethSet(weth); BASE_CURRENCY_UNIT = baseCurrencyUnit;
emit BaseCurrencySet(baseCurrency, baseCurrencyUnit);
} }
/// @notice External function called by the Aave governance to set or replace sources of assets /// @notice External function called by the Aave governance to set or replace sources of assets
@ -83,8 +88,8 @@ contract AaveOracle is IPriceOracleGetter, Ownable {
function getAssetPrice(address asset) public view override returns (uint256) { function getAssetPrice(address asset) public view override returns (uint256) {
IChainlinkAggregator source = assetsSources[asset]; IChainlinkAggregator source = assetsSources[asset];
if (asset == WETH) { if (asset == BASE_CURRENCY) {
return 1 ether; return BASE_CURRENCY_UNIT;
} else if (address(source) == address(0)) { } else if (address(source) == address(0)) {
return _fallbackOracle.getAssetPrice(asset); return _fallbackOracle.getAssetPrice(asset);
} else { } else {

View File

@ -98,11 +98,10 @@ contract AaveProtocolDataProvider {
view view
returns ( returns (
uint256 borrowCap, uint256 borrowCap,
uint256 supplyCap, uint256 supplyCap
uint256 exposureCap
) )
{ {
(borrowCap, supplyCap, exposureCap) = ILendingPool(ADDRESSES_PROVIDER.getLendingPool()) (borrowCap, supplyCap) = ILendingPool(ADDRESSES_PROVIDER.getLendingPool())
.getConfiguration(asset) .getConfiguration(asset)
.getCapsMemory(); .getCapsMemory();
} }

View File

@ -114,7 +114,7 @@ contract UiPoolDataProvider is IUiPoolDataProvider {
reserveData.decimals, reserveData.decimals,
reserveData.reserveFactor reserveData.reserveFactor
) = baseData.configuration.getParamsMemory(); ) = baseData.configuration.getParamsMemory();
(reserveData.borrowCap, reserveData.supplyCap, reserveData.exposureCap) = baseData (reserveData.borrowCap, reserveData.supplyCap) = baseData
.configuration .configuration
.getCapsMemory(); .getCapsMemory();
( (

View File

@ -17,7 +17,6 @@ interface IUiPoolDataProvider {
uint256 reserveFactor; uint256 reserveFactor;
uint256 borrowCap; uint256 borrowCap;
uint256 supplyCap; uint256 supplyCap;
uint256 exposureCap;
bool usageAsCollateralEnabled; bool usageAsCollateralEnabled;
bool borrowingEnabled; bool borrowingEnabled;
bool stableBorrowRateEnabled; bool stableBorrowRateEnabled;

View File

@ -278,9 +278,8 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
if (useAsCollateral) { if (useAsCollateral) {
emit ReserveUsedAsCollateralEnabled(asset, msg.sender); emit ReserveUsedAsCollateralEnabled(asset, msg.sender);
} else { } else {
ValidationLogic.validateHFAndExposureCap( ValidationLogic.validateHFAndLtv(
asset, asset,
userBalance,
msg.sender, msg.sender,
_reserves, _reserves,
_usersConfig[msg.sender], _usersConfig[msg.sender],
@ -474,17 +473,17 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
view view
override override
returns ( returns (
uint256 totalCollateralETH, uint256 totalCollateralBase,
uint256 totalDebtETH, uint256 totalDebtBase,
uint256 availableBorrowsETH, uint256 availableBorrowsBase,
uint256 currentLiquidationThreshold, uint256 currentLiquidationThreshold,
uint256 ltv, uint256 ltv,
uint256 healthFactor uint256 healthFactor
) )
{ {
( (
totalCollateralETH, totalCollateralBase,
totalDebtETH, totalDebtBase,
ltv, ltv,
currentLiquidationThreshold, currentLiquidationThreshold,
healthFactor, healthFactor,
@ -498,9 +497,9 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
_addressesProvider.getPriceOracle() _addressesProvider.getPriceOracle()
); );
availableBorrowsETH = GenericLogic.calculateAvailableBorrowsETH( availableBorrowsBase = GenericLogic.calculateAvailableBorrows(
totalCollateralETH, totalCollateralBase,
totalDebtETH, totalDebtBase,
ltv ltv
); );
} }
@ -620,9 +619,8 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
if (fromConfig.isUsingAsCollateral(reserveId)) { if (fromConfig.isUsingAsCollateral(reserveId)) {
if (fromConfig.isBorrowingAny()) { if (fromConfig.isBorrowingAny()) {
ValidationLogic.validateHFAndExposureCap( ValidationLogic.validateHFAndLtv(
asset, asset,
amount,
from, from,
_reserves, _reserves,
_usersConfig[from], _usersConfig[from],
@ -864,9 +862,8 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
if (userConfig.isUsingAsCollateral(reserve.id)) { if (userConfig.isUsingAsCollateral(reserve.id)) {
if (userConfig.isBorrowingAny()) { if (userConfig.isBorrowingAny()) {
ValidationLogic.validateHFAndExposureCap( ValidationLogic.validateHFAndLtv(
asset, asset,
0,
msg.sender, msg.sender,
_reserves, _reserves,
userConfig, userConfig,

View File

@ -296,8 +296,7 @@ contract LendingPoolConfigurator is VersionedInitializable, ILendingPoolConfigur
address asset, address asset,
uint256 ltv, uint256 ltv,
uint256 liquidationThreshold, uint256 liquidationThreshold,
uint256 liquidationBonus, uint256 liquidationBonus
uint256 exposureCap
) external override onlyRiskOrPoolAdmins { ) external override onlyRiskOrPoolAdmins {
DataTypes.ReserveConfigurationMap memory currentConfig = _pool.getConfiguration(asset); DataTypes.ReserveConfigurationMap memory currentConfig = _pool.getConfiguration(asset);
@ -331,7 +330,6 @@ contract LendingPoolConfigurator is VersionedInitializable, ILendingPoolConfigur
currentConfig.setLtv(ltv); currentConfig.setLtv(ltv);
currentConfig.setLiquidationThreshold(liquidationThreshold); currentConfig.setLiquidationThreshold(liquidationThreshold);
currentConfig.setLiquidationBonus(liquidationBonus); currentConfig.setLiquidationBonus(liquidationBonus);
currentConfig.setExposureCap(exposureCap);
_pool.setConfiguration(asset, currentConfig.data); _pool.setConfiguration(asset, currentConfig.data);
@ -458,21 +456,6 @@ contract LendingPoolConfigurator is VersionedInitializable, ILendingPoolConfigur
emit SupplyCapChanged(asset, supplyCap); emit SupplyCapChanged(asset, supplyCap);
} }
///@inheritdoc ILendingPoolConfigurator
function setExposureCap(address asset, uint256 exposureCap)
external
override
onlyRiskOrPoolAdmins
{
DataTypes.ReserveConfigurationMap memory currentConfig = _pool.getConfiguration(asset);
currentConfig.setExposureCap(exposureCap);
_pool.setConfiguration(asset, currentConfig.data);
emit ExposureCapChanged(asset, exposureCap);
}
///@inheritdoc ILendingPoolConfigurator ///@inheritdoc ILendingPoolConfigurator
function setReserveInterestRateStrategyAddress(address asset, address rateStrategyAddress) function setReserveInterestRateStrategyAddress(address asset, address rateStrategyAddress)
external external

View File

@ -22,7 +22,6 @@ library ReserveConfiguration {
uint256 constant RESERVE_FACTOR_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000FFFFFFFFFFFFFFFF; // prettier-ignore uint256 constant RESERVE_FACTOR_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000FFFFFFFFFFFFFFFF; // prettier-ignore
uint256 constant BORROW_CAP_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000FFFFFFFFFFFFFFFFFFFF; // prettier-ignore uint256 constant BORROW_CAP_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000FFFFFFFFFFFFFFFFFFFF; // prettier-ignore
uint256 constant SUPPLY_CAP_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFF000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFF; // prettier-ignore uint256 constant SUPPLY_CAP_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFF000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFF; // prettier-ignore
uint256 constant EXPOSURE_CAP_MASK = 0xFFFFFFFFFFFFFFFFF000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF; // prettier-ignore
/// @dev For the LTV, the start bit is 0 (up to 15), hence no bitshifting is needed /// @dev For the LTV, the start bit is 0 (up to 15), hence no bitshifting is needed
uint256 constant LIQUIDATION_THRESHOLD_START_BIT_POSITION = 16; uint256 constant LIQUIDATION_THRESHOLD_START_BIT_POSITION = 16;
@ -37,7 +36,6 @@ library ReserveConfiguration {
uint256 constant RESERVE_FACTOR_START_BIT_POSITION = 64; uint256 constant RESERVE_FACTOR_START_BIT_POSITION = 64;
uint256 constant BORROW_CAP_START_BIT_POSITION = 80; uint256 constant BORROW_CAP_START_BIT_POSITION = 80;
uint256 constant SUPPLY_CAP_START_BIT_POSITION = 116; uint256 constant SUPPLY_CAP_START_BIT_POSITION = 116;
uint256 constant EXPOSURE_CAP_START_BIT_POSITION = 152;
uint256 constant MAX_VALID_LTV = 65535; uint256 constant MAX_VALID_LTV = 65535;
uint256 constant MAX_VALID_LIQUIDATION_THRESHOLD = 65535; uint256 constant MAX_VALID_LIQUIDATION_THRESHOLD = 65535;
@ -46,7 +44,6 @@ library ReserveConfiguration {
uint256 constant MAX_VALID_RESERVE_FACTOR = 65535; uint256 constant MAX_VALID_RESERVE_FACTOR = 65535;
uint256 constant MAX_VALID_BORROW_CAP = 68719476735; uint256 constant MAX_VALID_BORROW_CAP = 68719476735;
uint256 constant MAX_VALID_SUPPLY_CAP = 68719476735; uint256 constant MAX_VALID_SUPPLY_CAP = 68719476735;
uint256 constant MAX_VALID_EXPOSURE_CAP = 68719476735;
/** /**
* @dev Sets the Loan to Value of the reserve * @dev Sets the Loan to Value of the reserve
@ -386,33 +383,6 @@ library ReserveConfiguration {
return (self.data & ~SUPPLY_CAP_MASK) >> SUPPLY_CAP_START_BIT_POSITION; return (self.data & ~SUPPLY_CAP_MASK) >> SUPPLY_CAP_START_BIT_POSITION;
} }
/**
* @dev Sets the exposure cap of the reserve
* @param self The reserve configuration
* @param exposureCap The exposure cap
**/
function setExposureCap(DataTypes.ReserveConfigurationMap memory self, uint256 exposureCap)
internal
pure
{
require(exposureCap <= MAX_VALID_EXPOSURE_CAP, Errors.RC_INVALID_EXPOSURE_CAP);
self.data = (self.data & EXPOSURE_CAP_MASK) | (exposureCap << EXPOSURE_CAP_START_BIT_POSITION);
}
/**
* @dev Gets the exposure cap of the reserve
* @param self The reserve configuration
* @return The exposure cap
**/
function getExposureCap(DataTypes.ReserveConfigurationMap storage self)
internal
view
returns (uint256)
{
return (self.data & ~EXPOSURE_CAP_MASK) >> EXPOSURE_CAP_START_BIT_POSITION;
}
/** /**
* @dev Gets the configuration flags of the reserve * @dev Gets the configuration flags of the reserve
* @param self The reserve configuration * @param self The reserve configuration
@ -476,7 +446,6 @@ library ReserveConfiguration {
internal internal
view view
returns ( returns (
uint256,
uint256, uint256,
uint256 uint256
) )
@ -485,8 +454,7 @@ library ReserveConfiguration {
return ( return (
(dataLocal & ~BORROW_CAP_MASK) >> BORROW_CAP_START_BIT_POSITION, (dataLocal & ~BORROW_CAP_MASK) >> BORROW_CAP_START_BIT_POSITION,
(dataLocal & ~SUPPLY_CAP_MASK) >> SUPPLY_CAP_START_BIT_POSITION, (dataLocal & ~SUPPLY_CAP_MASK) >> SUPPLY_CAP_START_BIT_POSITION
(dataLocal & ~EXPOSURE_CAP_MASK) >> EXPOSURE_CAP_START_BIT_POSITION
); );
} }
@ -524,15 +492,13 @@ library ReserveConfiguration {
internal internal
pure pure
returns ( returns (
uint256,
uint256, uint256,
uint256 uint256
) )
{ {
return ( return (
(self.data & ~BORROW_CAP_MASK) >> BORROW_CAP_START_BIT_POSITION, (self.data & ~BORROW_CAP_MASK) >> BORROW_CAP_START_BIT_POSITION,
(self.data & ~SUPPLY_CAP_MASK) >> SUPPLY_CAP_START_BIT_POSITION, (self.data & ~SUPPLY_CAP_MASK) >> SUPPLY_CAP_START_BIT_POSITION
(self.data & ~EXPOSURE_CAP_MASK) >> EXPOSURE_CAP_START_BIT_POSITION
); );
} }
@ -586,17 +552,4 @@ library ReserveConfiguration {
{ {
return (self.data & ~BORROW_CAP_MASK) >> BORROW_CAP_START_BIT_POSITION; return (self.data & ~BORROW_CAP_MASK) >> BORROW_CAP_START_BIT_POSITION;
} }
/**
* @dev Gets the exposure cap of the reserve from a memory object
* @param self The reserve configuration
* @return The exposure cap
**/
function getExposureCapMemory(DataTypes.ReserveConfigurationMap memory self)
internal
pure
returns (uint256)
{
return (self.data & ~EXPOSURE_CAP_MASK) >> EXPOSURE_CAP_START_BIT_POSITION;
}
} }

View File

@ -112,8 +112,7 @@ library Errors {
string public constant RL_ATOKEN_SUPPLY_NOT_ZERO = '88'; string public constant RL_ATOKEN_SUPPLY_NOT_ZERO = '88';
string public constant RL_STABLE_DEBT_NOT_ZERO = '89'; string public constant RL_STABLE_DEBT_NOT_ZERO = '89';
string public constant RL_VARIABLE_DEBT_SUPPLY_NOT_ZERO = '90'; string public constant RL_VARIABLE_DEBT_SUPPLY_NOT_ZERO = '90';
string public constant RC_INVALID_EXPOSURE_CAP = '92'; string public constant VL_LTV_VALIDATION_FAILED = '93';
string public constant VL_COLLATERAL_EXPOSURE_CAP_EXCEEDED = '93';
string public constant VL_SAME_BLOCK_BORROW_REPAY = '94'; string public constant VL_SAME_BLOCK_BORROW_REPAY = '94';
string public constant LPC_FLASHLOAN_PREMIUMS_MISMATCH = '95'; string public constant LPC_FLASHLOAN_PREMIUMS_MISMATCH = '95';
string public constant LPC_FLASHLOAN_PREMIUM_INVALID = '96'; string public constant LPC_FLASHLOAN_PREMIUM_INVALID = '96';

View File

@ -32,42 +32,36 @@ library GenericLogic {
uint256 assetPrice; uint256 assetPrice;
uint256 assetUnit; uint256 assetUnit;
uint256 userBalance; uint256 userBalance;
uint256 userBalanceETH; uint256 userBalanceInBaseCurrency;
uint256 userDebt; uint256 userDebt;
uint256 userStableDebt; uint256 userStableDebt;
uint256 userDebtETH; uint256 userDebtInBaseCurrency;
uint256 decimals; uint256 decimals;
uint256 ltv; uint256 ltv;
uint256 liquidationThreshold; uint256 liquidationThreshold;
uint256 i; uint256 i;
uint256 healthFactor; uint256 healthFactor;
uint256 totalCollateralInETH; uint256 totalCollateralInBaseCurrency;
uint256 totalDebtInETH; uint256 totalDebtInBaseCurrency;
uint256 avgLtv; uint256 avgLtv;
uint256 avgUncappedLtv;
uint256 avgLiquidationThreshold; uint256 avgLiquidationThreshold;
uint256 reservesLength;
uint256 normalizedIncome; uint256 normalizedIncome;
uint256 normalizedDebt; uint256 normalizedDebt;
uint256 exposureCap;
uint256 aTokenSupply;
bool healthFactorBelowThreshold;
address currentReserveAddress; address currentReserveAddress;
bool usageAsCollateralEnabled; bool hasZeroLtvCollateral;
bool userUsesReserveAsCollateral;
bool exposureCapCrossed;
} }
/** /**
* @dev Calculates the user data across the reserves. * @dev Calculates the user data across the reserves.
* this includes the total liquidity/collateral/borrow balances in ETH, * this includes the total liquidity/collateral/borrow balances in the base currency used by the price feed,
* the average Loan To Value, the average Liquidation Ratio, and the Health factor. * the average Loan To Value, the average Liquidation Ratio, and the Health factor.
* @param user The address of the user * @param user The address of the user
* @param reservesData Data of all the reserves * @param reservesData Data of all the reserves
* @param userConfig The configuration of the user * @param userConfig The configuration of the user
* @param reserves The list of the available reserves * @param reserves The list of the available reserves
* @param oracle The price oracle address * @param oracle The price oracle address
* @return The total collateral and total debt of the user in ETH, the avg ltv, liquidation threshold, the HF and the uncapped avg ltv (without exposure ceiling) * @return The total collateral and total debt of the user in the base currency used by the price feed,
* the avg ltv, liquidation threshold, the HF and the uncapped avg ltv
**/ **/
function calculateUserAccountData( function calculateUserAccountData(
address user, address user,
@ -85,13 +79,13 @@ library GenericLogic {
uint256, uint256,
uint256, uint256,
uint256, uint256,
uint256 bool
) )
{ {
CalculateUserAccountDataVars memory vars; CalculateUserAccountDataVars memory vars;
if (userConfig.isEmpty()) { if (userConfig.isEmpty()) {
return (0, 0, 0, 0, uint256(-1), 0); return (0, 0, 0, 0, uint256(-1), false);
} }
for (vars.i = 0; vars.i < reservesCount; vars.i++) { for (vars.i = 0; vars.i < reservesCount; vars.i++) {
if (!userConfig.isUsingAsCollateralOrBorrowing(vars.i)) { if (!userConfig.isUsingAsCollateralOrBorrowing(vars.i)) {
@ -107,40 +101,25 @@ library GenericLogic {
(vars.ltv, vars.liquidationThreshold, , vars.decimals, ) = currentReserve (vars.ltv, vars.liquidationThreshold, , vars.decimals, ) = currentReserve
.configuration .configuration
.getParams(); .getParams();
vars.exposureCap = currentReserve.configuration.getExposureCap();
vars.assetUnit = 10**vars.decimals; vars.assetUnit = 10**vars.decimals;
vars.assetPrice = IPriceOracleGetter(oracle).getAssetPrice(vars.currentReserveAddress); vars.assetPrice = IPriceOracleGetter(oracle).getAssetPrice(vars.currentReserveAddress);
if (vars.liquidationThreshold != 0 && userConfig.isUsingAsCollateral(vars.i)) { if (vars.liquidationThreshold != 0 && userConfig.isUsingAsCollateral(vars.i)) {
vars.normalizedIncome = currentReserve.getNormalizedIncome(); vars.normalizedIncome = currentReserve.getNormalizedIncome();
vars.userBalance = IScaledBalanceToken(currentReserve.aTokenAddress).scaledBalanceOf(user);
vars.userBalance = vars.userBalance.rayMul(vars.normalizedIncome);
if (vars.exposureCap != 0) { vars.userBalanceInBaseCurrency = vars.assetPrice.mul(vars.userBalance).div(vars.assetUnit);
(vars.userBalance, vars.aTokenSupply) = IScaledBalanceToken(currentReserve.aTokenAddress) vars.totalCollateralInBaseCurrency = vars.totalCollateralInBaseCurrency.add(
.getScaledUserBalanceAndSupply(user); vars.userBalanceInBaseCurrency
vars.userBalance = vars.userBalance.rayMul(vars.normalizedIncome);
vars.aTokenSupply = vars.aTokenSupply.rayMul(vars.normalizedIncome);
} else {
vars.userBalance = IScaledBalanceToken(currentReserve.aTokenAddress).scaledBalanceOf(
user
);
vars.userBalance = vars.userBalance.rayMul(vars.normalizedIncome);
vars.aTokenSupply = 0;
}
vars.userBalanceETH = vars.assetPrice.mul(vars.userBalance).div(vars.assetUnit);
vars.totalCollateralInETH = vars.totalCollateralInETH.add(vars.userBalanceETH);
vars.exposureCapCrossed =
vars.exposureCap != 0 &&
vars.aTokenSupply.div(10**vars.decimals) > vars.exposureCap;
vars.avgLtv = vars.avgLtv.add(
vars.exposureCapCrossed ? 0 : vars.userBalanceETH.mul(vars.ltv)
); );
vars.avgUncappedLtv = vars.avgUncappedLtv.add(vars.userBalanceETH.mul(vars.ltv));
vars.avgLtv = vars.avgLtv.add(vars.userBalanceInBaseCurrency.mul(vars.ltv));
vars.hasZeroLtvCollateral = vars.hasZeroLtvCollateral || vars.ltv == 0;
vars.avgLiquidationThreshold = vars.avgLiquidationThreshold.add( vars.avgLiquidationThreshold = vars.avgLiquidationThreshold.add(
vars.userBalanceETH.mul(vars.liquidationThreshold) vars.userBalanceInBaseCurrency.mul(vars.liquidationThreshold)
); );
} }
@ -154,73 +133,77 @@ library GenericLogic {
vars.userDebt = vars.userDebt.rayMul(vars.normalizedDebt); vars.userDebt = vars.userDebt.rayMul(vars.normalizedDebt);
} }
vars.userDebt = vars.userDebt.add(vars.userStableDebt); vars.userDebt = vars.userDebt.add(vars.userStableDebt);
vars.userDebtETH = vars.assetPrice.mul(vars.userDebt).div(vars.assetUnit); vars.userDebtInBaseCurrency = vars.assetPrice.mul(vars.userDebt).div(vars.assetUnit);
vars.totalDebtInETH = vars.totalDebtInETH.add(vars.userDebtETH); vars.totalDebtInBaseCurrency = vars.totalDebtInBaseCurrency.add(
vars.userDebtInBaseCurrency
);
} }
} }
vars.avgLtv = vars.totalCollateralInETH > 0 ? vars.avgLtv.div(vars.totalCollateralInETH) : 0; vars.avgLtv = vars.totalCollateralInBaseCurrency > 0
vars.avgUncappedLtv = vars.totalCollateralInETH > 0 ? vars.avgLtv.div(vars.totalCollateralInBaseCurrency)
? vars.avgUncappedLtv.div(vars.totalCollateralInETH)
: 0; : 0;
vars.avgLiquidationThreshold = vars.totalCollateralInETH > 0 vars.avgLiquidationThreshold = vars.totalCollateralInBaseCurrency > 0
? vars.avgLiquidationThreshold.div(vars.totalCollateralInETH) ? vars.avgLiquidationThreshold.div(vars.totalCollateralInBaseCurrency)
: 0; : 0;
vars.healthFactor = calculateHealthFactorFromBalances( vars.healthFactor = calculateHealthFactorFromBalances(
vars.totalCollateralInETH, vars.totalCollateralInBaseCurrency,
vars.totalDebtInETH, vars.totalDebtInBaseCurrency,
vars.avgLiquidationThreshold vars.avgLiquidationThreshold
); );
return ( return (
vars.totalCollateralInETH, vars.totalCollateralInBaseCurrency,
vars.totalDebtInETH, vars.totalDebtInBaseCurrency,
vars.avgLtv, vars.avgLtv,
vars.avgLiquidationThreshold, vars.avgLiquidationThreshold,
vars.healthFactor, vars.healthFactor,
vars.avgUncappedLtv vars.hasZeroLtvCollateral
); );
} }
/** /**
* @dev Calculates the health factor from the corresponding balances * @dev Calculates the health factor from the corresponding balances
* @param totalCollateralInETH The total collateral in ETH * @param totalCollateralInBaseCurrency The total collateral in the base currency used by the price feed
* @param totalDebtInETH The total debt in ETH * @param totalDebtInBaseCurrency The total debt in the base currency used by the price feed
* @param liquidationThreshold The avg liquidation threshold * @param liquidationThreshold The avg liquidation threshold
* @return The health factor calculated from the balances provided * @return The health factor calculated from the balances provided
**/ **/
function calculateHealthFactorFromBalances( function calculateHealthFactorFromBalances(
uint256 totalCollateralInETH, uint256 totalCollateralInBaseCurrency,
uint256 totalDebtInETH, uint256 totalDebtInBaseCurrency,
uint256 liquidationThreshold uint256 liquidationThreshold
) internal pure returns (uint256) { ) internal pure returns (uint256) {
if (totalDebtInETH == 0) return uint256(-1); if (totalDebtInBaseCurrency == 0) return uint256(-1);
return (totalCollateralInETH.percentMul(liquidationThreshold)).wadDiv(totalDebtInETH); return
(totalCollateralInBaseCurrency.percentMul(liquidationThreshold)).wadDiv(
totalDebtInBaseCurrency
);
} }
/** /**
* @dev Calculates the equivalent amount in ETH that an user can borrow, depending on the available collateral and the * @dev Calculates the maximum amount that can be borrowed depending on the available collateral, the total debt and the
* average Loan To Value * average Loan To Value
* @param totalCollateralInETH The total collateral in ETH * @param totalCollateralInBaseCurrency The total collateral in the base currency used by the price feed
* @param totalDebtInETH The total borrow balance * @param totalDebtInBaseCurrency The total borrow balance in the base currency used by the price feed
* @param ltv The average loan to value * @param ltv The average loan to value
* @return the amount available to borrow in ETH for the user * @return the amount available to borrow in the base currency of the used by the price feed
**/ **/
function calculateAvailableBorrowsETH( function calculateAvailableBorrows(
uint256 totalCollateralInETH, uint256 totalCollateralInBaseCurrency,
uint256 totalDebtInETH, uint256 totalDebtInBaseCurrency,
uint256 ltv uint256 ltv
) internal pure returns (uint256) { ) internal pure returns (uint256) {
uint256 availableBorrowsETH = totalCollateralInETH.percentMul(ltv); uint256 availableBorrowsInBaseCurrency = totalCollateralInBaseCurrency.percentMul(ltv);
if (availableBorrowsETH < totalDebtInETH) { if (availableBorrowsInBaseCurrency < totalDebtInBaseCurrency) {
return 0; return 0;
} }
availableBorrowsETH = availableBorrowsETH.sub(totalDebtInETH); availableBorrowsInBaseCurrency = availableBorrowsInBaseCurrency.sub(totalDebtInBaseCurrency);
return availableBorrowsETH; return availableBorrowsInBaseCurrency;
} }
/** /**
@ -249,7 +232,7 @@ library GenericLogic {
uint256, uint256,
uint256, uint256,
uint256, uint256,
uint256 bool
) )
{ {
return return

View File

@ -218,7 +218,7 @@ library ReserveLogic {
); );
} }
struct MintToTreasuryLocalVars { struct AccrueToTreasuryLocalVars {
uint256 prevTotalStableDebt; uint256 prevTotalStableDebt;
uint256 prevTotalVariableDebt; uint256 prevTotalVariableDebt;
uint256 currTotalVariableDebt; uint256 currTotalVariableDebt;
@ -240,7 +240,7 @@ library ReserveLogic {
DataTypes.ReserveData storage reserve, DataTypes.ReserveData storage reserve,
DataTypes.ReserveCache memory reserveCache DataTypes.ReserveCache memory reserveCache
) internal { ) internal {
MintToTreasuryLocalVars memory vars; AccrueToTreasuryLocalVars memory vars;
vars.reserveFactor = reserveCache.reserveConfiguration.getReserveFactorMemory(); vars.reserveFactor = reserveCache.reserveConfiguration.getReserveFactorMemory();

View File

@ -92,16 +92,16 @@ library ValidationLogic {
struct ValidateBorrowLocalVars { struct ValidateBorrowLocalVars {
uint256 currentLtv; uint256 currentLtv;
uint256 currentLiquidationThreshold; uint256 currentLiquidationThreshold;
uint256 amountOfCollateralNeededETH; uint256 collateralNeededInBaseCurrency;
uint256 userCollateralBalanceETH; uint256 userCollateralInBaseCurrency;
uint256 userBorrowBalanceETH; uint256 userDebtInBaseCurrency;
uint256 availableLiquidity; uint256 availableLiquidity;
uint256 healthFactor; uint256 healthFactor;
uint256 totalDebt; uint256 totalDebt;
uint256 totalSupplyVariableDebt; uint256 totalSupplyVariableDebt;
uint256 reserveDecimals; uint256 reserveDecimals;
uint256 borrowCap; uint256 borrowCap;
uint256 amountInETH; uint256 amountInBaseCurrency;
bool isActive; bool isActive;
bool isFrozen; bool isFrozen;
bool isPaused; bool isPaused;
@ -181,8 +181,8 @@ library ValidationLogic {
} }
( (
vars.userCollateralBalanceETH, vars.userCollateralInBaseCurrency,
vars.userBorrowBalanceETH, vars.userDebtInBaseCurrency,
vars.currentLtv, vars.currentLtv,
vars.currentLiquidationThreshold, vars.currentLiquidationThreshold,
vars.healthFactor, vars.healthFactor,
@ -196,23 +196,23 @@ library ValidationLogic {
oracle oracle
); );
require(vars.userCollateralBalanceETH > 0, Errors.VL_COLLATERAL_BALANCE_IS_0); require(vars.userCollateralInBaseCurrency > 0, Errors.VL_COLLATERAL_BALANCE_IS_0);
require( require(
vars.healthFactor > GenericLogic.HEALTH_FACTOR_LIQUIDATION_THRESHOLD, vars.healthFactor > GenericLogic.HEALTH_FACTOR_LIQUIDATION_THRESHOLD,
Errors.VL_HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD Errors.VL_HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD
); );
vars.amountInETH = IPriceOracleGetter(oracle).getAssetPrice(asset); vars.amountInBaseCurrency = IPriceOracleGetter(oracle).getAssetPrice(asset);
vars.amountInETH = vars.amountInETH.mul(amount).div(10**vars.reserveDecimals); vars.amountInBaseCurrency = vars.amountInBaseCurrency.mul(amount).div(10**vars.reserveDecimals);
//add the current already borrowed amount to the amount requested to calculate the total collateral needed. //add the current already borrowed amount to the amount requested to calculate the total collateral needed.
vars.amountOfCollateralNeededETH = vars.userBorrowBalanceETH.add(vars.amountInETH).percentDiv( vars.collateralNeededInBaseCurrency = vars.userDebtInBaseCurrency.add(vars.amountInBaseCurrency).percentDiv(
vars.currentLtv vars.currentLtv
); //LTV is calculated in percentage ); //LTV is calculated in percentage
require( require(
vars.amountOfCollateralNeededETH <= vars.userCollateralBalanceETH, vars.collateralNeededInBaseCurrency <= vars.userCollateralInBaseCurrency,
Errors.VL_COLLATERAL_CANNOT_COVER_NEW_BORROW Errors.VL_COLLATERAL_CANNOT_COVER_NEW_BORROW
); );
@ -504,19 +504,17 @@ library ValidationLogic {
return (uint256(Errors.CollateralManagerErrors.NO_ERROR), Errors.LPCM_NO_ERRORS); return (uint256(Errors.CollateralManagerErrors.NO_ERROR), Errors.LPCM_NO_ERRORS);
} }
struct validateHFAndExposureCapLocalVars { struct validateHFAndLtvLocalVars {
uint256 healthFactor; uint256 healthFactor;
uint256 ltv; uint256 assetLtv;
uint256 uncappedLtv;
uint256 exposureCap;
uint256 reserveDecimals; uint256 reserveDecimals;
uint256 totalSupplyAtoken; uint256 totalSupplyAtoken;
bool hasZeroLtvCollateral;
} }
/** /**
* @dev Validates the health factor of a user and the exposure cap for the asset being withdrawn * @dev Validates the health factor of a user and the ltv of the asset being withdrawn
* @param asset The asset for which the exposure cap will be validated * @param asset The asset for which the ltv will be validated
* @param expCapOffset The offset to consider on the total atoken supply of asset when validating the exposure cap
* @param from The user from which the aTokens are being transferred * @param from The user from which the aTokens are being transferred
* @param reservesData The state of all the reserves * @param reservesData The state of all the reserves
* @param userConfig The state of the user for the specific reserve * @param userConfig The state of the user for the specific reserve
@ -524,9 +522,8 @@ library ValidationLogic {
* @param reservesCount The number of available reserves * @param reservesCount The number of available reserves
* @param oracle The price oracle * @param oracle The price oracle
*/ */
function validateHFAndExposureCap( function validateHFAndLtv(
address asset, address asset,
uint256 expCapOffset,
address from, address from,
mapping(address => DataTypes.ReserveData) storage reservesData, mapping(address => DataTypes.ReserveData) storage reservesData,
DataTypes.UserConfigurationMap storage userConfig, DataTypes.UserConfigurationMap storage userConfig,
@ -534,9 +531,9 @@ library ValidationLogic {
uint256 reservesCount, uint256 reservesCount,
address oracle address oracle
) external view { ) external view {
validateHFAndExposureCapLocalVars memory vars; validateHFAndLtvLocalVars memory vars;
DataTypes.ReserveData memory reserve = reservesData[asset]; DataTypes.ReserveData memory reserve = reservesData[asset];
(, , vars.ltv, , vars.healthFactor, vars.uncappedLtv) = GenericLogic.calculateUserAccountData( (, , , , vars.healthFactor, vars.hasZeroLtvCollateral) = GenericLogic.calculateUserAccountData(
from, from,
reservesData, reservesData,
userConfig, userConfig,
@ -550,18 +547,9 @@ library ValidationLogic {
Errors.VL_HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD Errors.VL_HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD
); );
vars.exposureCap = reserve.configuration.getExposureCapMemory(); vars.assetLtv = reserve.configuration.getLtvMemory();
if (vars.exposureCap != 0) { require(vars.assetLtv == 0 || !vars.hasZeroLtvCollateral, Errors.VL_LTV_VALIDATION_FAILED);
if (vars.ltv < vars.uncappedLtv) {
vars.totalSupplyAtoken = IERC20(reserve.aTokenAddress).totalSupply();
(, , , vars.reserveDecimals, ) = reserve.configuration.getParamsMemory();
bool isAssetCapped =
vars.totalSupplyAtoken.sub(expCapOffset).div(10**vars.reserveDecimals) >=
vars.exposureCap;
require(isAssetCapped, Errors.VL_COLLATERAL_EXPOSURE_CAP_EXCEEDED);
}
}
} }
/** /**

View File

@ -43,7 +43,6 @@ library DataTypes {
//bit 64-79: reserve factor //bit 64-79: reserve factor
//bit 80-115 borrow cap, borrowCap == 0 => disabled //bit 80-115 borrow cap, borrowCap == 0 => disabled
//bit 116-151 supply cap, supplyCap == 0 => disabled //bit 116-151 supply cap, supplyCap == 0 => disabled
//bit 152-185 exposure cap, exposureCap == 0 => disabled
uint256 data; uint256 data;
} }

View File

@ -17,7 +17,6 @@ export const MAX_UINT_AMOUNT =
'115792089237316195423570985008687907853269984665640564039457584007913129639935'; '115792089237316195423570985008687907853269984665640564039457584007913129639935';
export const MAX_BORROW_CAP = '68719476735'; export const MAX_BORROW_CAP = '68719476735';
export const MAX_SUPPLY_CAP = '68719476735'; export const MAX_SUPPLY_CAP = '68719476735';
export const MAX_EXPOSURE_CAP = '68719476735';
export const ONE_YEAR = '31536000'; export const ONE_YEAR = '31536000';
export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'; export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
export const ONE_ADDRESS = '0x0000000000000000000000000000000000000001'; export const ONE_ADDRESS = '0x0000000000000000000000000000000000000001';

View File

@ -1,4 +1,4 @@
import { Contract } from 'ethers'; import { BigNumberish, Contract } from 'ethers';
import { DRE } from './misc-utils'; import { DRE } from './misc-utils';
import { import {
tEthereumAddress, tEthereumAddress,
@ -188,8 +188,8 @@ export const deployAaveLibraries = async (
return { return {
['__$de8c0cf1a7d7c36c802af9a64fb9d86036$__']: validationLogic.address, ['__$de8c0cf1a7d7c36c802af9a64fb9d86036$__']: validationLogic.address,
['__$22cd43a9dda9ce44e9b92ba393b88fb9ac$__']: reserveLogic.address, ['__$22cd43a9dda9ce44e9b92ba393b88fb9ac$__']: reserveLogic.address,
["__$52a8a86ab43135662ff256bbc95497e8e3$__"]: genericLogic.address, ['__$52a8a86ab43135662ff256bbc95497e8e3$__']: genericLogic.address,
} };
}; };
export const deployLendingPool = async (verify?: boolean) => { export const deployLendingPool = async (verify?: boolean) => {
@ -224,7 +224,7 @@ export const deployMockAggregator = async (price: tStringTokenSmallUnits, verify
); );
export const deployAaveOracle = async ( export const deployAaveOracle = async (
args: [tEthereumAddress[], tEthereumAddress[], tEthereumAddress, tEthereumAddress], args: [tEthereumAddress[], tEthereumAddress[], tEthereumAddress, tEthereumAddress, string],
verify?: boolean verify?: boolean
) => ) =>
withSaveAndVerify( withSaveAndVerify(

View File

@ -285,7 +285,6 @@ export const configureReservesByHelper = async (
reserveFactor: BigNumberish; reserveFactor: BigNumberish;
borrowCap: BigNumberish; borrowCap: BigNumberish;
supplyCap: BigNumberish; supplyCap: BigNumberish;
exposureCap: BigNumberish;
stableBorrowingEnabled: boolean; stableBorrowingEnabled: boolean;
borrowingEnabled: boolean; borrowingEnabled: boolean;
}[] = []; }[] = [];
@ -299,7 +298,6 @@ export const configureReservesByHelper = async (
reserveFactor, reserveFactor,
borrowCap, borrowCap,
supplyCap, supplyCap,
exposureCap,
stableBorrowRateEnabled, stableBorrowRateEnabled,
borrowingEnabled, borrowingEnabled,
}, },
@ -336,7 +334,6 @@ export const configureReservesByHelper = async (
reserveFactor, reserveFactor,
borrowCap, borrowCap,
supplyCap, supplyCap,
exposureCap,
stableBorrowingEnabled: stableBorrowRateEnabled, stableBorrowingEnabled: stableBorrowRateEnabled,
borrowingEnabled: borrowingEnabled, borrowingEnabled: borrowingEnabled,
}); });

View File

@ -187,8 +187,7 @@ export enum ProtocolErrors {
RL_ATOKEN_SUPPLY_NOT_ZERO = '88', RL_ATOKEN_SUPPLY_NOT_ZERO = '88',
RL_STABLE_DEBT_NOT_ZERO = '89', RL_STABLE_DEBT_NOT_ZERO = '89',
RL_VARIABLE_DEBT_SUPPLY_NOT_ZERO = '90', RL_VARIABLE_DEBT_SUPPLY_NOT_ZERO = '90',
RC_INVALID_EXPOSURE_CAP = '92', VL_LTV_VALIDATION_FAILED = '93',
VL_COLLATERAL_EXPOSURE_CAP_EXCEEDED = '93',
VL_SAME_BLOCK_BORROW_REPAY = '94', VL_SAME_BLOCK_BORROW_REPAY = '94',
LPC_FLASHLOAN_PREMIUMS_MISMATCH = '95', LPC_FLASHLOAN_PREMIUMS_MISMATCH = '95',
LPC_FLASHLOAN_PREMIUM_INVALID = '96', LPC_FLASHLOAN_PREMIUM_INVALID = '96',
@ -402,7 +401,6 @@ export interface IReserveCollateralParams {
baseLTVAsCollateral: string; baseLTVAsCollateral: string;
liquidationThreshold: string; liquidationThreshold: string;
liquidationBonus: string; liquidationBonus: string;
exposureCap: string;
} }
export interface IMarketRates { export interface IMarketRates {
borrowRate: string; borrowRate: string;

View File

@ -24,7 +24,7 @@ export const strategyBUSD: IReserveParams = {
reserveFactor: '1000', reserveFactor: '1000',
borrowCap: '0', borrowCap: '0',
supplyCap: '0', supplyCap: '0',
exposureCap: '0',
}; };
export const strategyDAI: IReserveParams = { export const strategyDAI: IReserveParams = {
@ -39,7 +39,7 @@ export const strategyDAI: IReserveParams = {
reserveFactor: '1000', reserveFactor: '1000',
borrowCap: '0', borrowCap: '0',
supplyCap: '0', supplyCap: '0',
exposureCap: '0',
}; };
export const strategySUSD: IReserveParams = { export const strategySUSD: IReserveParams = {
@ -54,7 +54,7 @@ export const strategySUSD: IReserveParams = {
reserveFactor: '2000', reserveFactor: '2000',
borrowCap: '0', borrowCap: '0',
supplyCap: '0', supplyCap: '0',
exposureCap: '0',
}; };
export const strategyTUSD: IReserveParams = { export const strategyTUSD: IReserveParams = {
@ -69,7 +69,7 @@ export const strategyTUSD: IReserveParams = {
reserveFactor: '1000', reserveFactor: '1000',
borrowCap: '0', borrowCap: '0',
supplyCap: '0', supplyCap: '0',
exposureCap: '0',
}; };
export const strategyUSDC: IReserveParams = { export const strategyUSDC: IReserveParams = {
@ -84,7 +84,7 @@ export const strategyUSDC: IReserveParams = {
reserveFactor: '1000', reserveFactor: '1000',
borrowCap: '0', borrowCap: '0',
supplyCap: '0', supplyCap: '0',
exposureCap: '0',
}; };
export const strategyUSDT: IReserveParams = { export const strategyUSDT: IReserveParams = {
@ -99,7 +99,7 @@ export const strategyUSDT: IReserveParams = {
reserveFactor: '1000', reserveFactor: '1000',
borrowCap: '0', borrowCap: '0',
supplyCap: '0', supplyCap: '0',
exposureCap: '0',
}; };
export const strategyAAVE: IReserveParams = { export const strategyAAVE: IReserveParams = {
@ -114,7 +114,7 @@ export const strategyAAVE: IReserveParams = {
reserveFactor: '0', reserveFactor: '0',
borrowCap: '0', borrowCap: '0',
supplyCap: '0', supplyCap: '0',
exposureCap: '0',
}; };
export const strategyBAT: IReserveParams = { export const strategyBAT: IReserveParams = {
@ -129,7 +129,7 @@ export const strategyBAT: IReserveParams = {
reserveFactor: '2000', reserveFactor: '2000',
borrowCap: '0', borrowCap: '0',
supplyCap: '0', supplyCap: '0',
exposureCap: '0',
}; };
export const strategyENJ: IReserveParams = { export const strategyENJ: IReserveParams = {
@ -144,7 +144,7 @@ export const strategyENJ: IReserveParams = {
reserveFactor: '2000', reserveFactor: '2000',
borrowCap: '0', borrowCap: '0',
supplyCap: '0', supplyCap: '0',
exposureCap: '0',
}; };
export const strategyWETH: IReserveParams = { export const strategyWETH: IReserveParams = {
@ -159,7 +159,7 @@ export const strategyWETH: IReserveParams = {
reserveFactor: '1000', reserveFactor: '1000',
borrowCap: '0', borrowCap: '0',
supplyCap: '0', supplyCap: '0',
exposureCap: '0',
}; };
export const strategyKNC: IReserveParams = { export const strategyKNC: IReserveParams = {
@ -174,7 +174,7 @@ export const strategyKNC: IReserveParams = {
reserveFactor: '2000', reserveFactor: '2000',
borrowCap: '0', borrowCap: '0',
supplyCap: '0', supplyCap: '0',
exposureCap: '0',
}; };
export const strategyLINK: IReserveParams = { export const strategyLINK: IReserveParams = {
@ -189,7 +189,7 @@ export const strategyLINK: IReserveParams = {
reserveFactor: '2000', reserveFactor: '2000',
borrowCap: '0', borrowCap: '0',
supplyCap: '0', supplyCap: '0',
exposureCap: '0',
}; };
export const strategyMANA: IReserveParams = { export const strategyMANA: IReserveParams = {
@ -204,7 +204,7 @@ export const strategyMANA: IReserveParams = {
reserveFactor: '3500', reserveFactor: '3500',
borrowCap: '0', borrowCap: '0',
supplyCap: '0', supplyCap: '0',
exposureCap: '0',
}; };
export const strategyMKR: IReserveParams = { export const strategyMKR: IReserveParams = {
@ -219,7 +219,7 @@ export const strategyMKR: IReserveParams = {
reserveFactor: '2000', reserveFactor: '2000',
borrowCap: '0', borrowCap: '0',
supplyCap: '0', supplyCap: '0',
exposureCap: '0',
}; };
export const strategyREN: IReserveParams = { export const strategyREN: IReserveParams = {
@ -234,7 +234,7 @@ export const strategyREN: IReserveParams = {
reserveFactor: '2000', reserveFactor: '2000',
borrowCap: '0', borrowCap: '0',
supplyCap: '0', supplyCap: '0',
exposureCap: '0',
}; };
export const strategySNX: IReserveParams = { export const strategySNX: IReserveParams = {
@ -249,7 +249,7 @@ export const strategySNX: IReserveParams = {
reserveFactor: '3500', reserveFactor: '3500',
borrowCap: '0', borrowCap: '0',
supplyCap: '0', supplyCap: '0',
exposureCap: '0',
}; };
// Invalid borrow rates in params currently, replaced with snx params // Invalid borrow rates in params currently, replaced with snx params
@ -265,7 +265,7 @@ export const strategyUNI: IReserveParams = {
reserveFactor: '2000', reserveFactor: '2000',
borrowCap: '0', borrowCap: '0',
supplyCap: '0', supplyCap: '0',
exposureCap: '0',
}; };
export const strategyWBTC: IReserveParams = { export const strategyWBTC: IReserveParams = {
@ -280,7 +280,7 @@ export const strategyWBTC: IReserveParams = {
reserveFactor: '2000', reserveFactor: '2000',
borrowCap: '0', borrowCap: '0',
supplyCap: '0', supplyCap: '0',
exposureCap: '0',
}; };
export const strategyYFI: IReserveParams = { export const strategyYFI: IReserveParams = {
@ -295,7 +295,7 @@ export const strategyYFI: IReserveParams = {
reserveFactor: '2000', reserveFactor: '2000',
borrowCap: '0', borrowCap: '0',
supplyCap: '0', supplyCap: '0',
exposureCap: '0',
}; };
export const strategyZRX: IReserveParams = { export const strategyZRX: IReserveParams = {
@ -310,7 +310,7 @@ export const strategyZRX: IReserveParams = {
reserveFactor: '2000', reserveFactor: '2000',
borrowCap: '0', borrowCap: '0',
supplyCap: '0', supplyCap: '0',
exposureCap: '0',
}; };
export const strategyXSUSHI: IReserveParams = { export const strategyXSUSHI: IReserveParams = {
@ -325,5 +325,5 @@ export const strategyXSUSHI: IReserveParams = {
reserveFactor: '3500', reserveFactor: '3500',
borrowCap: '0', borrowCap: '0',
supplyCap: '0', supplyCap: '0',
exposureCap: '0',
}; };

View File

@ -13,7 +13,7 @@ export const strategyWETH: IReserveParams = {
reserveFactor: '1000', reserveFactor: '1000',
borrowCap: '0', borrowCap: '0',
supplyCap: '0', supplyCap: '0',
exposureCap: '0',
}; };
export const strategyWBTC: IReserveParams = { export const strategyWBTC: IReserveParams = {
@ -28,7 +28,7 @@ export const strategyWBTC: IReserveParams = {
reserveFactor: '2000', reserveFactor: '2000',
borrowCap: '0', borrowCap: '0',
supplyCap: '0', supplyCap: '0',
exposureCap: '0',
}; };
export const strategyDAI: IReserveParams = { export const strategyDAI: IReserveParams = {
@ -43,7 +43,7 @@ export const strategyDAI: IReserveParams = {
reserveFactor: '1000', reserveFactor: '1000',
borrowCap: '0', borrowCap: '0',
supplyCap: '0', supplyCap: '0',
exposureCap: '0',
}; };
export const strategyUSDC: IReserveParams = { export const strategyUSDC: IReserveParams = {
@ -58,7 +58,7 @@ export const strategyUSDC: IReserveParams = {
reserveFactor: '1000', reserveFactor: '1000',
borrowCap: '0', borrowCap: '0',
supplyCap: '0', supplyCap: '0',
exposureCap: '0',
}; };
export const strategyUSDT: IReserveParams = { export const strategyUSDT: IReserveParams = {
@ -73,7 +73,7 @@ export const strategyUSDT: IReserveParams = {
reserveFactor: '1000', reserveFactor: '1000',
borrowCap: '0', borrowCap: '0',
supplyCap: '0', supplyCap: '0',
exposureCap: '0',
}; };
export const strategyDAIWETH: IReserveParams = { export const strategyDAIWETH: IReserveParams = {
@ -88,7 +88,7 @@ export const strategyDAIWETH: IReserveParams = {
reserveFactor: '1000', reserveFactor: '1000',
borrowCap: '0', borrowCap: '0',
supplyCap: '0', supplyCap: '0',
exposureCap: '0',
}; };
export const strategyWBTCWETH: IReserveParams = { export const strategyWBTCWETH: IReserveParams = {
@ -103,7 +103,7 @@ export const strategyWBTCWETH: IReserveParams = {
reserveFactor: '1500', reserveFactor: '1500',
borrowCap: '0', borrowCap: '0',
supplyCap: '0', supplyCap: '0',
exposureCap: '0',
}; };
export const strategyAAVEWETH: IReserveParams = { export const strategyAAVEWETH: IReserveParams = {
@ -118,7 +118,7 @@ export const strategyAAVEWETH: IReserveParams = {
reserveFactor: '500', reserveFactor: '500',
borrowCap: '0', borrowCap: '0',
supplyCap: '0', supplyCap: '0',
exposureCap: '0',
}; };
export const strategyBATWETH: IReserveParams = { export const strategyBATWETH: IReserveParams = {
@ -133,7 +133,7 @@ export const strategyBATWETH: IReserveParams = {
reserveFactor: '1500', reserveFactor: '1500',
borrowCap: '0', borrowCap: '0',
supplyCap: '0', supplyCap: '0',
exposureCap: '0',
}; };
export const strategyDAIUSDC: IReserveParams = { export const strategyDAIUSDC: IReserveParams = {
@ -148,7 +148,7 @@ export const strategyDAIUSDC: IReserveParams = {
reserveFactor: '1000', reserveFactor: '1000',
borrowCap: '0', borrowCap: '0',
supplyCap: '0', supplyCap: '0',
exposureCap: '0',
}; };
export const strategyCRVWETH: IReserveParams = { export const strategyCRVWETH: IReserveParams = {
@ -163,7 +163,7 @@ export const strategyCRVWETH: IReserveParams = {
reserveFactor: '1500', reserveFactor: '1500',
borrowCap: '0', borrowCap: '0',
supplyCap: '0', supplyCap: '0',
exposureCap: '0',
}; };
export const strategyLINKWETH: IReserveParams = { export const strategyLINKWETH: IReserveParams = {
@ -178,7 +178,7 @@ export const strategyLINKWETH: IReserveParams = {
reserveFactor: '1500', reserveFactor: '1500',
borrowCap: '0', borrowCap: '0',
supplyCap: '0', supplyCap: '0',
exposureCap: '0',
}; };
export const strategyMKRWETH: IReserveParams = { export const strategyMKRWETH: IReserveParams = {
@ -193,7 +193,7 @@ export const strategyMKRWETH: IReserveParams = {
reserveFactor: '1500', reserveFactor: '1500',
borrowCap: '0', borrowCap: '0',
supplyCap: '0', supplyCap: '0',
exposureCap: '0',
}; };
export const strategyRENWETH: IReserveParams = { export const strategyRENWETH: IReserveParams = {
@ -208,7 +208,7 @@ export const strategyRENWETH: IReserveParams = {
reserveFactor: '1500', reserveFactor: '1500',
borrowCap: '0', borrowCap: '0',
supplyCap: '0', supplyCap: '0',
exposureCap: '0',
}; };
export const strategySNXWETH: IReserveParams = { export const strategySNXWETH: IReserveParams = {
@ -223,7 +223,7 @@ export const strategySNXWETH: IReserveParams = {
reserveFactor: '2000', reserveFactor: '2000',
borrowCap: '0', borrowCap: '0',
supplyCap: '0', supplyCap: '0',
exposureCap: '0',
}; };
export const strategyUNIWETH: IReserveParams = { export const strategyUNIWETH: IReserveParams = {
@ -238,7 +238,7 @@ export const strategyUNIWETH: IReserveParams = {
reserveFactor: '1500', reserveFactor: '1500',
borrowCap: '0', borrowCap: '0',
supplyCap: '0', supplyCap: '0',
exposureCap: '0',
}; };
export const strategyUSDCWETH: IReserveParams = { export const strategyUSDCWETH: IReserveParams = {
@ -253,7 +253,7 @@ export const strategyUSDCWETH: IReserveParams = {
reserveFactor: '1000', reserveFactor: '1000',
borrowCap: '0', borrowCap: '0',
supplyCap: '0', supplyCap: '0',
exposureCap: '0',
}; };
export const strategyWBTCUSDC: IReserveParams = { export const strategyWBTCUSDC: IReserveParams = {
@ -268,7 +268,7 @@ export const strategyWBTCUSDC: IReserveParams = {
reserveFactor: '1500', reserveFactor: '1500',
borrowCap: '0', borrowCap: '0',
supplyCap: '0', supplyCap: '0',
exposureCap: '0',
}; };
export const strategyYFIWETH: IReserveParams = { export const strategyYFIWETH: IReserveParams = {
@ -283,7 +283,7 @@ export const strategyYFIWETH: IReserveParams = {
reserveFactor: '1500', reserveFactor: '1500',
borrowCap: '0', borrowCap: '0',
supplyCap: '0', supplyCap: '0',
exposureCap: '0',
}; };
export const strategyBALWETH: IReserveParams = { export const strategyBALWETH: IReserveParams = {
@ -298,5 +298,5 @@ export const strategyBALWETH: IReserveParams = {
reserveFactor: '1500', reserveFactor: '1500',
borrowCap: '0', borrowCap: '0',
supplyCap: '0', supplyCap: '0',
exposureCap: '0',
}; };

View File

@ -22,7 +22,7 @@ export const strategyDAI: IReserveParams = {
reserveFactor: '1000', reserveFactor: '1000',
borrowCap: '0', borrowCap: '0',
supplyCap: '0', supplyCap: '0',
exposureCap: '0',
}; };
export const strategyUSDC: IReserveParams = { export const strategyUSDC: IReserveParams = {
@ -37,7 +37,7 @@ export const strategyUSDC: IReserveParams = {
reserveFactor: '1000', reserveFactor: '1000',
borrowCap: '0', borrowCap: '0',
supplyCap: '0', supplyCap: '0',
exposureCap: '0',
}; };
export const strategyUSDT: IReserveParams = { export const strategyUSDT: IReserveParams = {
@ -52,7 +52,7 @@ export const strategyUSDT: IReserveParams = {
reserveFactor: '1000', reserveFactor: '1000',
borrowCap: '0', borrowCap: '0',
supplyCap: '0', supplyCap: '0',
exposureCap: '0',
}; };
export const strategyWETH: IReserveParams = { export const strategyWETH: IReserveParams = {
@ -67,7 +67,7 @@ export const strategyWETH: IReserveParams = {
reserveFactor: '1000', reserveFactor: '1000',
borrowCap: '0', borrowCap: '0',
supplyCap: '0', supplyCap: '0',
exposureCap: '0',
}; };
export const strategyWBTC: IReserveParams = { export const strategyWBTC: IReserveParams = {
@ -82,7 +82,7 @@ export const strategyWBTC: IReserveParams = {
reserveFactor: '2000', reserveFactor: '2000',
borrowCap: '0', borrowCap: '0',
supplyCap: '0', supplyCap: '0',
exposureCap: '0',
}; };
export const strategyMATIC: IReserveParams = { export const strategyMATIC: IReserveParams = {
@ -96,7 +96,7 @@ export const strategyMATIC: IReserveParams = {
aTokenImpl: eContractid.AToken, aTokenImpl: eContractid.AToken,
borrowCap: '0', borrowCap: '0',
supplyCap: '0', supplyCap: '0',
exposureCap: '0',
reserveFactor: '2000', reserveFactor: '2000',
}; };
@ -111,6 +111,6 @@ export const strategyAAVE: IReserveParams = {
aTokenImpl: eContractid.AToken, aTokenImpl: eContractid.AToken,
borrowCap: '0', borrowCap: '0',
supplyCap: '0', supplyCap: '0',
exposureCap: '0',
reserveFactor: '0', reserveFactor: '0',
}; };

View File

@ -100,9 +100,9 @@ contract LendingPoolHarnessForVariableDebtToken is ILendingPool {
view view
override override
returns ( returns (
uint256 totalCollateralETH, uint256 totalCollateralBase,
uint256 totalDebtETH, uint256 totalDebtBase,
uint256 availableBorrowsETH, uint256 availableBorrowsBase,
uint256 currentLiquidationThreshold, uint256 currentLiquidationThreshold,
uint256 ltv, uint256 ltv,
uint256 healthFactor uint256 healthFactor

View File

@ -18,6 +18,7 @@ import {
getLendingPoolAddressesProvider, getLendingPoolAddressesProvider,
getPairsTokenAggregator, getPairsTokenAggregator,
} from '../../helpers/contracts-getters'; } from '../../helpers/contracts-getters';
import { ethers } from 'ethers';
task('dev:deploy-oracles', 'Deploy oracles for dev enviroment') task('dev:deploy-oracles', 'Deploy oracles for dev enviroment')
.addFlag('verify', 'Verify contracts at Etherscan') .addFlag('verify', 'Verify contracts at Etherscan')
@ -58,7 +59,13 @@ task('dev:deploy-oracles', 'Deploy oracles for dev enviroment')
); );
await deployAaveOracle( await deployAaveOracle(
[tokens, aggregators, fallbackOracle.address, await getWethAddress(poolConfig)], [
tokens,
aggregators,
fallbackOracle.address,
await getWethAddress(poolConfig),
ethers.constants.WeiPerEther.toString(),
],
verify verify
); );
await waitForTx(await addressesProvider.setPriceOracle(fallbackOracle.address)); await waitForTx(await addressesProvider.setPriceOracle(fallbackOracle.address));

View File

@ -18,6 +18,7 @@ import {
getPairsTokenAggregator, getPairsTokenAggregator,
} from '../../helpers/contracts-getters'; } from '../../helpers/contracts-getters';
import { AaveOracle, LendingRateOracle } from '../../types'; import { AaveOracle, LendingRateOracle } from '../../types';
import { ethers } from 'ethers';
task('full:deploy-oracles', 'Deploy oracles for dev enviroment') task('full:deploy-oracles', 'Deploy oracles for dev enviroment')
.addFlag('verify', 'Verify contracts at Etherscan') .addFlag('verify', 'Verify contracts at Etherscan')
@ -55,7 +56,13 @@ task('full:deploy-oracles', 'Deploy oracles for dev enviroment')
aaveOracle = await await getAaveOracle(aaveOracleAddress); aaveOracle = await await getAaveOracle(aaveOracleAddress);
} else { } else {
aaveOracle = await deployAaveOracle( aaveOracle = await deployAaveOracle(
[tokens, aggregators, fallbackOracleAddress, await getWethAddress(poolConfig)], [
tokens,
aggregators,
fallbackOracleAddress,
await getWethAddress(poolConfig),
ethers.constants.WeiPerEther.toString(),
],
verify verify
); );
await waitForTx(await aaveOracle.setAssetSources(tokens, aggregators)); await waitForTx(await aaveOracle.setAssetSources(tokens, aggregators));

View File

@ -30,7 +30,7 @@ import {
authorizeWETHGateway, authorizeWETHGateway,
} from '../../helpers/contracts-deployments'; } from '../../helpers/contracts-deployments';
import { eEthereumNetwork } from '../../helpers/types'; import { eEthereumNetwork } from '../../helpers/types';
import { Signer } from 'ethers'; import { ethers, Signer } from 'ethers';
import { TokenContractId, eContractid, tEthereumAddress, AavePools } from '../../helpers/types'; import { TokenContractId, eContractid, tEthereumAddress, AavePools } from '../../helpers/types';
import { MintableERC20 } from '../../types/MintableERC20'; import { MintableERC20 } from '../../types/MintableERC20';
import { import {
@ -215,7 +215,13 @@ const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => {
const [tokens, aggregators] = getPairsTokenAggregator(allTokenAddresses, allAggregatorsAddresses); const [tokens, aggregators] = getPairsTokenAggregator(allTokenAddresses, allAggregatorsAddresses);
await deployAaveOracle([tokens, aggregators, fallbackOracle.address, mockTokens.WETH.address]); await deployAaveOracle([
tokens,
aggregators,
fallbackOracle.address,
mockTokens.WETH.address,
ethers.constants.WeiPerEther.toString(),
]);
await waitForTx(await addressesProvider.setPriceOracle(fallbackOracle.address)); await waitForTx(await addressesProvider.setPriceOracle(fallbackOracle.address));
const lendingRateOracle = await deployLendingRateOracle(); const lendingRateOracle = await deployLendingRateOracle();
@ -243,12 +249,8 @@ const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => {
const config = loadPoolConfig(ConfigNames.Aave); const config = loadPoolConfig(ConfigNames.Aave);
const { const { ATokenNamePrefix, StableDebtTokenNamePrefix, VariableDebtTokenNamePrefix, SymbolPrefix } =
ATokenNamePrefix, config;
StableDebtTokenNamePrefix,
VariableDebtTokenNamePrefix,
SymbolPrefix,
} = config;
const treasuryAddress = await getTreasuryAddress(config); const treasuryAddress = await getTreasuryAddress(config);
await initReservesByHelper( await initReservesByHelper(

View File

@ -229,7 +229,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive, isActive,
isFrozen, isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address); } = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps( const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address weth.address
); );
const isPaused = await helpersContract.getPaused(weth.address); const isPaused = await helpersContract.getPaused(weth.address);
@ -246,7 +246,6 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor); expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor);
expect(borrowCap).to.be.equal(strategyWETH.borrowCap); expect(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap); expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
}); });
it('Unpauses the ETH reserve by pool admin ', async () => { it('Unpauses the ETH reserve by pool admin ', async () => {
@ -264,7 +263,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive, isActive,
isFrozen, isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address); } = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps( const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address weth.address
); );
const isPaused = await helpersContract.getPaused(weth.address); const isPaused = await helpersContract.getPaused(weth.address);
@ -281,7 +280,6 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor); expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor);
expect(borrowCap).to.be.equal(strategyWETH.borrowCap); expect(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap); expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
}); });
it('Pauses the ETH reserve by emergency admin', async () => { it('Pauses the ETH reserve by emergency admin', async () => {
const { configurator, weth, helpersContract, addressesProvider, users, emergencyAdmin } = const { configurator, weth, helpersContract, addressesProvider, users, emergencyAdmin } =
@ -298,7 +296,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive, isActive,
isFrozen, isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address); } = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps( const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address weth.address
); );
const isPaused = await helpersContract.getPaused(weth.address); const isPaused = await helpersContract.getPaused(weth.address);
@ -315,7 +313,6 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor); expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor);
expect(borrowCap).to.be.equal(strategyWETH.borrowCap); expect(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap); expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
}); });
it('Unpauses the ETH reserve by emergency admin ', async () => { it('Unpauses the ETH reserve by emergency admin ', async () => {
@ -333,7 +330,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive, isActive,
isFrozen, isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address); } = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps( const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address weth.address
); );
const isPaused = await helpersContract.getPaused(weth.address); const isPaused = await helpersContract.getPaused(weth.address);
@ -350,7 +347,6 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor); expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor);
expect(borrowCap).to.be.equal(strategyWETH.borrowCap); expect(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap); expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
}); });
it('Check the only admin or emergency admin can pauseReserve ', async () => { it('Check the only admin or emergency admin can pauseReserve ', async () => {
@ -384,7 +380,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive, isActive,
isFrozen, isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address); } = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps( const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address weth.address
); );
const isPaused = await helpersContract.getPaused(weth.address); const isPaused = await helpersContract.getPaused(weth.address);
@ -401,7 +397,6 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor); expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor);
expect(borrowCap).to.be.equal(strategyWETH.borrowCap); expect(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap); expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
}); });
it('Unfreezes the ETH reserve by Pool admin', async () => { it('Unfreezes the ETH reserve by Pool admin', async () => {
@ -419,7 +414,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive, isActive,
isFrozen, isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address); } = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps( const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address weth.address
); );
const isPaused = await helpersContract.getPaused(weth.address); const isPaused = await helpersContract.getPaused(weth.address);
@ -436,8 +431,8 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor); expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor);
expect(borrowCap).to.be.equal(strategyWETH.borrowCap); expect(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap); expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
}); });
it('Freezes the ETH reserve by Risk Admin', async () => { it('Freezes the ETH reserve by Risk Admin', async () => {
const { configurator, weth, helpersContract, riskAdmin } = testEnv; const { configurator, weth, helpersContract, riskAdmin } = testEnv;
await configurator.connect(riskAdmin.signer).freezeReserve(weth.address); await configurator.connect(riskAdmin.signer).freezeReserve(weth.address);
@ -452,7 +447,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive, isActive,
isFrozen, isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address); } = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps( const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address weth.address
); );
const isPaused = await helpersContract.getPaused(weth.address); const isPaused = await helpersContract.getPaused(weth.address);
@ -469,7 +464,6 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor); expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor);
expect(borrowCap).to.be.equal(strategyWETH.borrowCap); expect(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap); expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
}); });
it('Unfreezes the ETH reserve by Risk admin', async () => { it('Unfreezes the ETH reserve by Risk admin', async () => {
@ -487,7 +481,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive, isActive,
isFrozen, isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address); } = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps( const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address weth.address
); );
const isPaused = await helpersContract.getPaused(weth.address); const isPaused = await helpersContract.getPaused(weth.address);
@ -504,7 +498,6 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor); expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor);
expect(borrowCap).to.be.equal(strategyWETH.borrowCap); expect(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap); expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
}); });
it('Check the onlyRiskOrPoolAdmins on freezeReserve ', async () => { it('Check the onlyRiskOrPoolAdmins on freezeReserve ', async () => {
@ -537,7 +530,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive, isActive,
isFrozen, isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address); } = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps( const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address weth.address
); );
const isPaused = await helpersContract.getPaused(weth.address); const isPaused = await helpersContract.getPaused(weth.address);
@ -554,7 +547,6 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor); expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor);
expect(borrowCap).to.be.equal(strategyWETH.borrowCap); expect(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap); expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
}); });
it('Activates the ETH reserve for borrowing via pool admin', async () => { it('Activates the ETH reserve for borrowing via pool admin', async () => {
@ -573,7 +565,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive, isActive,
isFrozen, isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address); } = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps( const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address weth.address
); );
const isPaused = await helpersContract.getPaused(weth.address); const isPaused = await helpersContract.getPaused(weth.address);
@ -590,7 +582,6 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor); expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor);
expect(borrowCap).to.be.equal(strategyWETH.borrowCap); expect(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap); expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
expect(variableBorrowIndex.toString()).to.be.equal(RAY); expect(variableBorrowIndex.toString()).to.be.equal(RAY);
}); });
@ -609,7 +600,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive, isActive,
isFrozen, isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address); } = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps( const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address weth.address
); );
const isPaused = await helpersContract.getPaused(weth.address); const isPaused = await helpersContract.getPaused(weth.address);
@ -626,7 +617,6 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor); expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor);
expect(borrowCap).to.be.equal(strategyWETH.borrowCap); expect(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap); expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
}); });
it('Activates the ETH reserve for borrowing via risk admin', async () => { it('Activates the ETH reserve for borrowing via risk admin', async () => {
@ -645,7 +635,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive, isActive,
isFrozen, isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address); } = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps( const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address weth.address
); );
const isPaused = await helpersContract.getPaused(weth.address); const isPaused = await helpersContract.getPaused(weth.address);
@ -662,7 +652,6 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor); expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor);
expect(borrowCap).to.be.equal(strategyWETH.borrowCap); expect(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap); expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
expect(variableBorrowIndex.toString()).to.be.equal(RAY); expect(variableBorrowIndex.toString()).to.be.equal(RAY);
}); });
@ -688,7 +677,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
it('Deactivates the ETH reserve as collateral via pool admin', async () => { it('Deactivates the ETH reserve as collateral via pool admin', async () => {
const { configurator, helpersContract, weth } = testEnv; const { configurator, helpersContract, weth } = testEnv;
await configurator.configureReserveAsCollateral(weth.address, 0, 0, 0, 0); await configurator.configureReserveAsCollateral(weth.address, 0, 0, 0);
const { const {
decimals, decimals,
@ -701,7 +690,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive, isActive,
isFrozen, isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address); } = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps( const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address weth.address
); );
const isPaused = await helpersContract.getPaused(weth.address); const isPaused = await helpersContract.getPaused(weth.address);
@ -718,12 +707,11 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor); expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor);
expect(borrowCap).to.be.equal(strategyWETH.borrowCap); expect(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap); expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
}); });
it('Activates the ETH reserve as collateral via pool admin', async () => { it('Activates the ETH reserve as collateral via pool admin', async () => {
const { configurator, helpersContract, weth } = testEnv; const { configurator, helpersContract, weth } = testEnv;
await configurator.configureReserveAsCollateral(weth.address, '8000', '8250', '10500', '0'); await configurator.configureReserveAsCollateral(weth.address, '8000', '8250', '10500');
const { const {
decimals, decimals,
@ -736,7 +724,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive, isActive,
isFrozen, isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address); } = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps( const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address weth.address
); );
const isPaused = await helpersContract.getPaused(weth.address); const isPaused = await helpersContract.getPaused(weth.address);
@ -753,13 +741,13 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor); expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor);
expect(borrowCap).to.be.equal(strategyWETH.borrowCap); expect(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap); expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
}); });
it('Deactivates the ETH reserve as collateral via risk admin', async () => { it('Deactivates the ETH reserve as collateral via risk admin', async () => {
const { configurator, helpersContract, weth, riskAdmin } = testEnv; const { configurator, helpersContract, weth, riskAdmin } = testEnv;
await configurator await configurator
.connect(riskAdmin.signer) .connect(riskAdmin.signer)
.configureReserveAsCollateral(weth.address, 0, 0, 0, 0); .configureReserveAsCollateral(weth.address, 0, 0, 0);
const { const {
decimals, decimals,
@ -772,7 +760,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive, isActive,
isFrozen, isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address); } = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps( const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address weth.address
); );
const isPaused = await helpersContract.getPaused(weth.address); const isPaused = await helpersContract.getPaused(weth.address);
@ -789,14 +777,13 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor); expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor);
expect(borrowCap).to.be.equal(strategyWETH.borrowCap); expect(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap); expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
}); });
it('Activates the ETH reserve as collateral via risk admin', async () => { it('Activates the ETH reserve as collateral via risk admin', async () => {
const { configurator, helpersContract, weth, riskAdmin } = testEnv; const { configurator, helpersContract, weth, riskAdmin } = testEnv;
await configurator await configurator
.connect(riskAdmin.signer) .connect(riskAdmin.signer)
.configureReserveAsCollateral(weth.address, '8000', '8250', '10500', '0'); .configureReserveAsCollateral(weth.address, '8000', '8250', '10500');
const { const {
decimals, decimals,
@ -809,7 +796,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive, isActive,
isFrozen, isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address); } = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps( const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address weth.address
); );
const isPaused = await helpersContract.getPaused(weth.address); const isPaused = await helpersContract.getPaused(weth.address);
@ -826,7 +813,6 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor); expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor);
expect(borrowCap).to.be.equal(strategyWETH.borrowCap); expect(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap); expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
}); });
it('Check the onlyRiskOrPoolAdmin on configureReserveAsCollateral ', async () => { it('Check the onlyRiskOrPoolAdmin on configureReserveAsCollateral ', async () => {
@ -834,7 +820,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
await expect( await expect(
configurator configurator
.connect(emergencyAdmin.signer) .connect(emergencyAdmin.signer)
.configureReserveAsCollateral(weth.address, '7500', '8000', '10500', '0'), .configureReserveAsCollateral(weth.address, '7500', '8000', '10500'),
CALLER_NOT_POOL_ADMIN CALLER_NOT_POOL_ADMIN
).to.be.revertedWith(LPC_CALLER_NOT_RISK_OR_POOL_ADMIN); ).to.be.revertedWith(LPC_CALLER_NOT_RISK_OR_POOL_ADMIN);
}); });
@ -853,7 +839,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive, isActive,
isFrozen, isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address); } = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps( const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address weth.address
); );
const isPaused = await helpersContract.getPaused(weth.address); const isPaused = await helpersContract.getPaused(weth.address);
@ -870,7 +856,6 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor); expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor);
expect(borrowCap).to.be.equal(strategyWETH.borrowCap); expect(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap); expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
}); });
it('Enables stable borrow rate on the ETH reserve via pool admin', async () => { it('Enables stable borrow rate on the ETH reserve via pool admin', async () => {
@ -887,7 +872,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive, isActive,
isFrozen, isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address); } = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps( const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address weth.address
); );
const isPaused = await helpersContract.getPaused(weth.address); const isPaused = await helpersContract.getPaused(weth.address);
@ -904,8 +889,8 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor); expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor);
expect(borrowCap).to.be.equal(strategyWETH.borrowCap); expect(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap); expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
}); });
it('Disable stable borrow rate on the ETH reserve risk admin', async () => { it('Disable stable borrow rate on the ETH reserve risk admin', async () => {
const { configurator, helpersContract, weth, riskAdmin } = testEnv; const { configurator, helpersContract, weth, riskAdmin } = testEnv;
await configurator.connect(riskAdmin.signer).disableReserveStableRate(weth.address); await configurator.connect(riskAdmin.signer).disableReserveStableRate(weth.address);
@ -920,7 +905,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive, isActive,
isFrozen, isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address); } = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps( const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address weth.address
); );
const isPaused = await helpersContract.getPaused(weth.address); const isPaused = await helpersContract.getPaused(weth.address);
@ -937,7 +922,6 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor); expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor);
expect(borrowCap).to.be.equal(strategyWETH.borrowCap); expect(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap); expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
}); });
it('Enables stable borrow rate on the ETH reserve risk admin', async () => { it('Enables stable borrow rate on the ETH reserve risk admin', async () => {
@ -954,7 +938,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive, isActive,
isFrozen, isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address); } = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps( const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address weth.address
); );
const isPaused = await helpersContract.getPaused(weth.address); const isPaused = await helpersContract.getPaused(weth.address);
@ -971,7 +955,6 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor); expect(reserveFactor).to.be.equal(strategyWETH.reserveFactor);
expect(borrowCap).to.be.equal(strategyWETH.borrowCap); expect(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap); expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
}); });
it('Check the onlyRiskOrPoolAdmin on disableReserveStableRate', async () => { it('Check the onlyRiskOrPoolAdmin on disableReserveStableRate', async () => {
@ -1012,13 +995,6 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
CALLER_NOT_POOL_ADMIN CALLER_NOT_POOL_ADMIN
).to.be.revertedWith(LPC_CALLER_NOT_RISK_OR_POOL_ADMIN); ).to.be.revertedWith(LPC_CALLER_NOT_RISK_OR_POOL_ADMIN);
}); });
it('Check the onlyRiskOrPoolAdmin on setExposureCap', async () => {
const { configurator, users, weth, emergencyAdmin } = testEnv;
await expect(
configurator.connect(emergencyAdmin.signer).setExposureCap(weth.address, '3000000000'),
CALLER_NOT_POOL_ADMIN
).to.be.revertedWith(LPC_CALLER_NOT_RISK_OR_POOL_ADMIN);
});
it('Changes the reserve factor of WETH via pool admin', async () => { it('Changes the reserve factor of WETH via pool admin', async () => {
const { configurator, helpersContract, weth } = testEnv; const { configurator, helpersContract, weth } = testEnv;
@ -1034,7 +1010,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive, isActive,
isFrozen, isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address); } = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps( const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address weth.address
); );
const isPaused = await helpersContract.getPaused(weth.address); const isPaused = await helpersContract.getPaused(weth.address);
@ -1050,7 +1026,6 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(stableBorrowRateEnabled).to.be.equal(strategyWETH.stableBorrowRateEnabled); expect(stableBorrowRateEnabled).to.be.equal(strategyWETH.stableBorrowRateEnabled);
expect(borrowCap).to.be.equal(strategyWETH.borrowCap); expect(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap); expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
expect(reserveFactor).to.be.equal(1000); expect(reserveFactor).to.be.equal(1000);
}); });
it('Changes the reserve factor of WETH risk admin', async () => { it('Changes the reserve factor of WETH risk admin', async () => {
@ -1067,7 +1042,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive, isActive,
isFrozen, isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address); } = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps( const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address weth.address
); );
const isPaused = await helpersContract.getPaused(weth.address); const isPaused = await helpersContract.getPaused(weth.address);
@ -1083,9 +1058,9 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(stableBorrowRateEnabled).to.be.equal(strategyWETH.stableBorrowRateEnabled); expect(stableBorrowRateEnabled).to.be.equal(strategyWETH.stableBorrowRateEnabled);
expect(borrowCap).to.be.equal(strategyWETH.borrowCap); expect(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap); expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
expect(reserveFactor).to.be.equal(1000); expect(reserveFactor).to.be.equal(1000);
}); });
it('Changes the reserve factor of WETH risk admin', async () => { it('Changes the reserve factor of WETH risk admin', async () => {
const { configurator, helpersContract, weth, riskAdmin } = testEnv; const { configurator, helpersContract, weth, riskAdmin } = testEnv;
await configurator.connect(riskAdmin.signer).setReserveFactor(weth.address, '1000'); await configurator.connect(riskAdmin.signer).setReserveFactor(weth.address, '1000');
@ -1146,7 +1121,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive, isActive,
isFrozen, isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address); } = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps( const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address weth.address
); );
const isPaused = await helpersContract.getPaused(weth.address); const isPaused = await helpersContract.getPaused(weth.address);
@ -1163,8 +1138,9 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(1000); expect(reserveFactor).to.be.equal(1000);
expect(borrowCap).to.be.equal('3000000'); expect(borrowCap).to.be.equal('3000000');
expect(supplyCap).to.be.equal(strategyWETH.supplyCap); expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
}); });
it('Changes the borrow Cap of WETH risk admin', async () => { it('Changes the borrow Cap of WETH risk admin', async () => {
const { configurator, helpersContract, weth, riskAdmin } = testEnv; const { configurator, helpersContract, weth, riskAdmin } = testEnv;
await configurator.connect(riskAdmin.signer).setBorrowCap(weth.address, '3000000'); await configurator.connect(riskAdmin.signer).setBorrowCap(weth.address, '3000000');
@ -1179,7 +1155,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive, isActive,
isFrozen, isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address); } = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps( const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address weth.address
); );
const isPaused = await helpersContract.getPaused(weth.address); const isPaused = await helpersContract.getPaused(weth.address);
@ -1196,7 +1172,6 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(1000); expect(reserveFactor).to.be.equal(1000);
expect(borrowCap).to.be.equal('3000000'); expect(borrowCap).to.be.equal('3000000');
expect(supplyCap).to.be.equal(strategyWETH.supplyCap); expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
}); });
it('Changes the supply Cap of WETH via pool admin', async () => { it('Changes the supply Cap of WETH via pool admin', async () => {
@ -1213,7 +1188,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive, isActive,
isFrozen, isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address); } = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps( const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address weth.address
); );
const isPaused = await helpersContract.getPaused(weth.address); const isPaused = await helpersContract.getPaused(weth.address);
@ -1230,8 +1205,8 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(1000); expect(reserveFactor).to.be.equal(1000);
expect(borrowCap).to.be.equal('3000000'); expect(borrowCap).to.be.equal('3000000');
expect(supplyCap).to.be.equal('3000000'); expect(supplyCap).to.be.equal('3000000');
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
}); });
it('Changes the supply Cap of WETH via risk admin', async () => { it('Changes the supply Cap of WETH via risk admin', async () => {
const { configurator, helpersContract, weth, riskAdmin } = testEnv; const { configurator, helpersContract, weth, riskAdmin } = testEnv;
await configurator.connect(riskAdmin.signer).setSupplyCap(weth.address, '3000000'); await configurator.connect(riskAdmin.signer).setSupplyCap(weth.address, '3000000');
@ -1246,7 +1221,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive, isActive,
isFrozen, isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address); } = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps( const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address weth.address
); );
const isPaused = await helpersContract.getPaused(weth.address); const isPaused = await helpersContract.getPaused(weth.address);
@ -1263,74 +1238,8 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(1000); expect(reserveFactor).to.be.equal(1000);
expect(borrowCap).to.be.equal('3000000'); expect(borrowCap).to.be.equal('3000000');
expect(supplyCap).to.be.equal('3000000'); expect(supplyCap).to.be.equal('3000000');
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
});
it('Changes the exposure Cap of WETH via pool admin', async () => {
const { configurator, helpersContract, weth } = testEnv;
await configurator.setExposureCap(weth.address, '3000000');
const {
decimals,
ltv,
liquidationBonus,
liquidationThreshold,
reserveFactor,
stableBorrowRateEnabled,
borrowingEnabled,
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
weth.address
);
const isPaused = await helpersContract.getPaused(weth.address);
expect(borrowingEnabled).to.be.equal(true);
expect(isActive).to.be.equal(true);
expect(isPaused).to.be.equal(false);
expect(isFrozen).to.be.equal(false);
expect(decimals).to.be.equal(strategyWETH.reserveDecimals);
expect(ltv).to.be.equal(strategyWETH.baseLTVAsCollateral);
expect(liquidationThreshold).to.be.equal(strategyWETH.liquidationThreshold);
expect(liquidationBonus).to.be.equal(strategyWETH.liquidationBonus);
expect(stableBorrowRateEnabled).to.be.equal(strategyWETH.stableBorrowRateEnabled);
expect(reserveFactor).to.be.equal(1000);
expect(borrowCap).to.be.equal('3000000');
expect(supplyCap).to.be.equal('3000000');
expect(exposureCap).to.be.equal('3000000');
});
it('Changes the exposure Cap of WETH via risk admin', async () => {
const { configurator, helpersContract, weth, riskAdmin } = testEnv;
await configurator.connect(riskAdmin.signer).setExposureCap(weth.address, '3000000');
const {
decimals,
ltv,
liquidationBonus,
liquidationThreshold,
reserveFactor,
stableBorrowRateEnabled,
borrowingEnabled,
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
weth.address
);
const isPaused = await helpersContract.getPaused(weth.address);
expect(borrowingEnabled).to.be.equal(true);
expect(isActive).to.be.equal(true);
expect(isPaused).to.be.equal(false);
expect(isFrozen).to.be.equal(false);
expect(decimals).to.be.equal(strategyWETH.reserveDecimals);
expect(ltv).to.be.equal(strategyWETH.baseLTVAsCollateral);
expect(liquidationThreshold).to.be.equal(strategyWETH.liquidationThreshold);
expect(liquidationBonus).to.be.equal(strategyWETH.liquidationBonus);
expect(stableBorrowRateEnabled).to.be.equal(strategyWETH.stableBorrowRateEnabled);
expect(reserveFactor).to.be.equal(1000);
expect(borrowCap).to.be.equal('3000000');
expect(supplyCap).to.be.equal('3000000');
expect(exposureCap).to.be.equal('3000000');
}); });
it('Changes the supply Cap of WETH via risk admin', async () => { it('Changes the supply Cap of WETH via risk admin', async () => {
const { configurator, helpersContract, weth, riskAdmin } = testEnv; const { configurator, helpersContract, weth, riskAdmin } = testEnv;
await configurator.connect(riskAdmin.signer).setSupplyCap(weth.address, '3000000'); await configurator.connect(riskAdmin.signer).setSupplyCap(weth.address, '3000000');

View File

@ -1,276 +0,0 @@
import { TestEnv, makeSuite } from './helpers/make-suite';
import {
APPROVAL_AMOUNT_LENDING_POOL,
MAX_UINT_AMOUNT,
RAY,
MAX_EXPOSURE_CAP,
MOCK_CHAINLINK_AGGREGATORS_PRICES,
} from '../../helpers/constants';
import { ProtocolErrors } from '../../helpers/types';
import { MintableERC20, WETH9, WETH9Mocked } from '../../types';
import { parseEther } from '@ethersproject/units';
import { BigNumber } from '@ethersproject/bignumber';
import { strategyDAI } from '../../markets/amm/reservesConfigs';
import { strategyUSDC } from '../../markets/amm/reservesConfigs';
import { ethers } from 'ethers';
const { expect } = require('chai');
makeSuite('Exposure Cap', (testEnv: TestEnv) => {
const {
VL_COLLATERAL_EXPOSURE_CAP_EXCEEDED,
RC_INVALID_EXPOSURE_CAP,
VL_COLLATERAL_CANNOT_COVER_NEW_BORROW,
} = ProtocolErrors;
const daiPrice = Number(MOCK_CHAINLINK_AGGREGATORS_PRICES.DAI);
const usdcPrice = Number(MOCK_CHAINLINK_AGGREGATORS_PRICES.USDC);
const daiLTV = Number(strategyDAI.baseLTVAsCollateral);
const usdcLTV = Number(strategyUSDC.baseLTVAsCollateral);
const unitParse = async (token: WETH9Mocked | MintableERC20, nb: string) =>
BigNumber.from(nb).mul(BigNumber.from('10').pow((await token.decimals()) - 3));
it('Reserves should initially have exposure cap disabled (exposureCap = 0)', async () => {
const {
weth,
pool,
dai,
usdc,
deployer,
helpersContract,
users: [user1],
} = testEnv;
const mintedAmount = parseEther('1000000000');
// minting for main user
await dai.mint(mintedAmount);
await weth.mint(mintedAmount);
await usdc.mint(mintedAmount);
// minting for lp user
await dai.connect(user1.signer).mint(mintedAmount);
await weth.connect(user1.signer).mint(mintedAmount);
await usdc.connect(user1.signer).mint(mintedAmount);
await dai.approve(pool.address, MAX_UINT_AMOUNT);
await weth.approve(pool.address, MAX_UINT_AMOUNT);
await usdc.approve(pool.address, MAX_UINT_AMOUNT);
await dai.connect(user1.signer).approve(pool.address, MAX_UINT_AMOUNT);
await weth.connect(user1.signer).approve(pool.address, MAX_UINT_AMOUNT);
await usdc.connect(user1.signer).approve(pool.address, MAX_UINT_AMOUNT);
await pool.deposit(weth.address, mintedAmount, deployer.address, 0);
let usdcExposureCap = (await helpersContract.getReserveCaps(usdc.address)).exposureCap;
let daiExposureCap = (await helpersContract.getReserveCaps(dai.address)).exposureCap;
expect(usdcExposureCap).to.be.equal('0');
expect(daiExposureCap).to.be.equal('0');
});
it('Deposit 10 Dai, 10 USDC, LTV for both should increase', async () => {
const {
pool,
dai,
usdc,
users: [user1],
} = testEnv;
const suppliedAmount = 10;
const precisionSuppliedAmount = (suppliedAmount * 1000).toString();
// user 1 deposit more dai and usdc to be able to borrow
let { ltv } = await pool.getUserAccountData(user1.address);
expect(ltv.toString()).to.be.equal('0');
await pool
.connect(user1.signer)
.deposit(dai.address, await unitParse(dai, precisionSuppliedAmount), user1.address, 0);
ltv = (await pool.getUserAccountData(user1.address)).ltv;
expect(ltv).to.be.equal(daiLTV);
await pool
.connect(user1.signer)
.deposit(usdc.address, await unitParse(usdc, precisionSuppliedAmount), user1.address, 0);
ltv = (await pool.getUserAccountData(user1.address)).ltv;
expect(Number(ltv)).to.be.equal(
Math.floor((daiLTV * daiPrice + usdcLTV * usdcPrice) / (daiPrice + usdcPrice))
);
});
it('Sets the exposure cap for DAI to 10 Units', async () => {
const {
configurator,
dai,
helpersContract,
users: [],
} = testEnv;
const newExposureCap = 10;
await configurator.setExposureCap(dai.address, newExposureCap);
const daiExposureCap = (await helpersContract.getReserveCaps(dai.address)).exposureCap;
expect(daiExposureCap).to.be.equal(newExposureCap);
});
it('should succeed to deposit 10 dai but dai ltv drops to 0', async () => {
const {
pool,
dai,
users: [user1],
} = testEnv;
const suppliedAmount = 10;
const precisionSuppliedAmount = (suppliedAmount * 1000).toString();
await pool
.connect(user1.signer)
.deposit(dai.address, await unitParse(dai, precisionSuppliedAmount), user1.address, 0);
let ltv = (await pool.getUserAccountData(user1.address)).ltv;
expect(ltv).to.be.equal(Math.floor((usdcLTV * usdcPrice) / (usdcPrice + 2 * daiPrice)));
});
it('should succeed to deposit 1 dai but avg ltv decreases', async () => {
const {
pool,
dai,
users: [user1],
} = testEnv;
const suppliedAmount = 1;
const precisionSuppliedAmount = (suppliedAmount * 1000).toString();
let ltv = (await pool.getUserAccountData(user1.address)).ltv;
await pool
.connect(user1.signer)
.deposit(dai.address, await unitParse(dai, precisionSuppliedAmount), user1.address, 0);
expect(ltv.toNumber()).to.be.gt((await pool.getUserAccountData(user1.address)).ltv.toNumber());
});
it('should succeed to deposit 1 usdc and ltv should increase', async () => {
const {
usdc,
pool,
users: [user1],
} = testEnv;
const suppliedAmount = 1;
const precisionSuppliedAmount = (suppliedAmount * 1000).toString();
let ltv = (await pool.getUserAccountData(user1.address)).ltv;
await pool
.connect(user1.signer)
.deposit(usdc.address, await unitParse(usdc, precisionSuppliedAmount), user1.address, 0);
expect(ltv.toNumber()).to.be.lt((await pool.getUserAccountData(user1.address)).ltv.toNumber());
});
it('Should not be able to borrow 15 USD of weth', async () => {
const {
pool,
weth,
users: [user1],
} = testEnv;
const precisionBorrowedUsdAmount = 15 * 1000;
const precisionBorrowedEthAmount = ethers.BigNumber.from(precisionBorrowedUsdAmount)
.mul(daiPrice)
.div(parseEther('1.0'))
.toString();
const borrowedAmount = await unitParse(weth, precisionBorrowedEthAmount);
await expect(
pool.connect(user1.signer).borrow(weth.address, borrowedAmount, 1, 0, user1.address)
).to.be.revertedWith(VL_COLLATERAL_CANNOT_COVER_NEW_BORROW);
});
it('should be able to borrow 15 USD of weth after dai exposure cap raised to 100', async () => {
const {
pool,
dai,
weth,
configurator,
helpersContract,
users: [user1],
} = testEnv;
const newExposureCap = 100;
await configurator.setExposureCap(dai.address, newExposureCap);
const daiExposureCap = (await helpersContract.getReserveCaps(dai.address)).exposureCap;
expect(daiExposureCap).to.be.equal(newExposureCap);
const precisionBorrowedUsdAmount = 15 * 1000;
const precisionBorrowedEthAmount = ethers.BigNumber.from(precisionBorrowedUsdAmount)
.mul(daiPrice)
.div(parseEther('1.0'))
.toString();
const borrowedAmount = await unitParse(weth, precisionBorrowedEthAmount);
pool.connect(user1.signer).borrow(weth.address, borrowedAmount, 1, 0, user1.address);
});
it('should not be able to withdraw 5 dai, transfer 5 aDai after cap decrease of usdc back to 10 (capped)', async () => {
const {
pool,
dai,
usdc,
aDai,
configurator,
helpersContract,
users: [user1, , , receiver],
} = testEnv;
const newExposureCap = 10;
await configurator.setExposureCap(usdc.address, newExposureCap);
const usdcExposureCap = (await helpersContract.getReserveCaps(usdc.address)).exposureCap;
expect(usdcExposureCap).to.be.equal(newExposureCap);
const precisionWithdrawnAmount = (5 * 1000).toString();
const withdrawnAmount = await unitParse(dai, precisionWithdrawnAmount);
await expect(
pool.connect(user1.signer).withdraw(dai.address, withdrawnAmount, user1.address)
).to.be.revertedWith(VL_COLLATERAL_EXPOSURE_CAP_EXCEEDED);
await expect(
aDai.connect(user1.signer).transfer(receiver.address, withdrawnAmount)
).to.be.revertedWith(VL_COLLATERAL_EXPOSURE_CAP_EXCEEDED);
});
it('should be able to withdraw 5 usdc and transfer 5 aUsdc', async () => {
const {
usdc,
pool,
aUsdc,
users: [user1, , , receiver],
} = testEnv;
const precisionWithdrawnAmount = (5 * 1000).toString();
const withdrawnAmount = await unitParse(usdc, precisionWithdrawnAmount);
await pool.connect(user1.signer).withdraw(usdc.address, withdrawnAmount, user1.address);
await aUsdc.connect(user1.signer).transfer(receiver.address, withdrawnAmount);
});
it('should be able to withdraw 5 dai, transfer 5 aDai after repaying weth Debt', async () => {
const {
pool,
dai,
weth,
aDai,
users: [user1, , , receiver],
} = testEnv;
const precisionWithdrawnAmount = (5 * 1000).toString();
const withdrawnAmount = await unitParse(dai, precisionWithdrawnAmount);
await (
await pool.connect(user1.signer).repay(weth.address, MAX_UINT_AMOUNT, 1, user1.address)
).wait();
pool.connect(user1.signer).withdraw(dai.address, withdrawnAmount, user1.address);
aDai.connect(user1.signer).transfer(receiver.address, withdrawnAmount);
});
it('Should fail to set the exposure cap for usdc and DAI to max cap + 1 Units', async () => {
const { configurator, usdc, dai } = testEnv;
const newCap = Number(MAX_EXPOSURE_CAP) + 1;
await expect(configurator.setExposureCap(usdc.address, newCap)).to.be.revertedWith(
RC_INVALID_EXPOSURE_CAP
);
await expect(configurator.setExposureCap(dai.address, newCap)).to.be.revertedWith(
RC_INVALID_EXPOSURE_CAP
);
});
});

View File

@ -55,7 +55,7 @@ makeSuite('LendingPool liquidation - liquidator receiving aToken', (testEnv) =>
const amountDAIToBorrow = await convertToCurrencyDecimals( const amountDAIToBorrow = await convertToCurrencyDecimals(
dai.address, dai.address,
new BigNumber(userGlobalData.availableBorrowsETH.toString()) new BigNumber(userGlobalData.availableBorrowsBase.toString())
.div(daiPrice.toString()) .div(daiPrice.toString())
.multipliedBy(0.95) .multipliedBy(0.95)
.toFixed(0) .toFixed(0)
@ -269,7 +269,7 @@ makeSuite('LendingPool liquidation - liquidator receiving aToken', (testEnv) =>
const amountUSDCToBorrow = await convertToCurrencyDecimals( const amountUSDCToBorrow = await convertToCurrencyDecimals(
usdc.address, usdc.address,
new BigNumber(userGlobalData.availableBorrowsETH.toString()) new BigNumber(userGlobalData.availableBorrowsBase.toString())
.div(usdcPrice.toString()) .div(usdcPrice.toString())
.multipliedBy(0.9502) .multipliedBy(0.9502)
.toFixed(0) .toFixed(0)

View File

@ -83,7 +83,7 @@ makeSuite('LendingPool liquidation - liquidator receiving the underlying asset',
const amountDAIToBorrow = await convertToCurrencyDecimals( const amountDAIToBorrow = await convertToCurrencyDecimals(
dai.address, dai.address,
new BigNumber(userGlobalData.availableBorrowsETH.toString()) new BigNumber(userGlobalData.availableBorrowsBase.toString())
.div(daiPrice.toString()) .div(daiPrice.toString())
.multipliedBy(0.95) .multipliedBy(0.95)
.toFixed(0) .toFixed(0)
@ -267,7 +267,7 @@ makeSuite('LendingPool liquidation - liquidator receiving the underlying asset',
const amountUSDCToBorrow = await convertToCurrencyDecimals( const amountUSDCToBorrow = await convertToCurrencyDecimals(
usdc.address, usdc.address,
new BigNumber(userGlobalData.availableBorrowsETH.toString()) new BigNumber(userGlobalData.availableBorrowsBase.toString())
.div(usdcPrice.toString()) .div(usdcPrice.toString())
.multipliedBy(0.9502) .multipliedBy(0.9502)
.toFixed(0) .toFixed(0)

View File

@ -0,0 +1,102 @@
import { TestEnv, makeSuite } from './helpers/make-suite';
import {
MAX_UINT_AMOUNT,
} from '../../helpers/constants';
import { ProtocolErrors } from '../../helpers/types';
import { convertToCurrencyDecimals } from '../../helpers/contracts-helpers';
const { expect } = require('chai');
makeSuite('LTV validation tests', (testEnv: TestEnv) => {
const {
VL_LTV_VALIDATION_FAILED,
} = ProtocolErrors;
it('User 1 deposits 10 Dai, 10 USDC, user 2 deposits 1 WETH', async () => {
const {
pool,
dai,
usdc,
weth,
users: [user1, user2],
} = testEnv;
const daiAmount = await convertToCurrencyDecimals(dai.address, '10');
const usdcAmount = await convertToCurrencyDecimals(usdc.address, '10');
const wethAmount = await convertToCurrencyDecimals(weth.address, '1');
await dai.connect(user1.signer).approve(pool.address, MAX_UINT_AMOUNT);
await usdc.connect(user1.signer).approve(pool.address, MAX_UINT_AMOUNT);
await weth.connect(user2.signer).approve(pool.address, MAX_UINT_AMOUNT);
await dai.connect(user1.signer).mint(daiAmount);
await usdc.connect(user1.signer).mint(usdcAmount);
await weth.connect(user2.signer).mint(wethAmount);
await pool.connect(user1.signer).deposit(dai.address, daiAmount, user1.address, 0);
await pool.connect(user1.signer).deposit(usdc.address, usdcAmount, user1.address, 0);
await pool.connect(user2.signer).deposit(weth.address, wethAmount, user2.address, 0);
});
it('Sets the ltv of DAI to 0', async () => {
const {
configurator,
dai,
helpersContract,
users: [],
} = testEnv;
await configurator.configureReserveAsCollateral(dai.address, 0, 8000, 10500);
const ltv = (await helpersContract.getReserveConfigurationData(dai.address)).ltv;
expect(ltv).to.be.equal(0);
});
it('Borrows 0.01 weth', async () => {
const {
pool,
weth,
users: [user1],
} = testEnv;
const borrowedAmount = await convertToCurrencyDecimals(weth.address, "0.01");
pool.connect(user1.signer).borrow(weth.address, borrowedAmount, 1, 0, user1.address);
});
it('Tries to withdraw USDC (revert expected)', async () => {
const {
pool,
usdc,
users: [user1],
} = testEnv;
const withdrawnAmount = await convertToCurrencyDecimals(usdc.address, "1");
await expect(
pool.connect(user1.signer).withdraw(usdc.address, withdrawnAmount, user1.address)
).to.be.revertedWith(VL_LTV_VALIDATION_FAILED);
});
it('Withdraws DAI', async () => {
const {
pool,
dai,
aDai,
users: [user1],
} = testEnv;
const aDaiBalanceBefore = await aDai.balanceOf(user1.address);
const withdrawnAmount = await convertToCurrencyDecimals(dai.address, "1");
await pool.connect(user1.signer).withdraw(dai.address, withdrawnAmount, user1.address);
const aDaiBalanceAfter = await aDai.balanceOf(user1.address);
expect(aDaiBalanceAfter.toString()).to.be.bignumber.equal(aDaiBalanceBefore.sub(withdrawnAmount));
});
});

View File

@ -224,7 +224,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => {
const amountUSDCToBorrow = await convertToCurrencyDecimals( const amountUSDCToBorrow = await convertToCurrencyDecimals(
usdc.address, usdc.address,
new BigNumber(userGlobalData.availableBorrowsETH.toString()) new BigNumber(userGlobalData.availableBorrowsBase.toString())
.div(usdcPrice.toString()) .div(usdcPrice.toString())
.multipliedBy(0.9502) .multipliedBy(0.9502)
.toFixed(0) .toFixed(0)

View File

@ -224,7 +224,7 @@ makeSuite('Pause One Reserve', (testEnv: TestEnv) => {
const amountUSDCToBorrow = await convertToCurrencyDecimals( const amountUSDCToBorrow = await convertToCurrencyDecimals(
usdc.address, usdc.address,
new BigNumber(userGlobalData.availableBorrowsETH.toString()) new BigNumber(userGlobalData.availableBorrowsBase.toString())
.div(usdcPrice.toString()) .div(usdcPrice.toString())
.multipliedBy(0.9502) .multipliedBy(0.9502)
.toFixed(0) .toFixed(0)

View File

@ -61,7 +61,7 @@ makeSuite('Uniswap adapters', (testEnv: TestEnv) => {
const amountDAIToBorrow = await convertToCurrencyDecimals( const amountDAIToBorrow = await convertToCurrencyDecimals(
dai.address, dai.address,
new BigNumber(userGlobalDataBefore.availableBorrowsETH.toString()) new BigNumber(userGlobalDataBefore.availableBorrowsBase.toString())
.div(daiPrice.toString()) .div(daiPrice.toString())
.multipliedBy(0.95) .multipliedBy(0.95)
.toFixed(0) .toFixed(0)
@ -128,7 +128,7 @@ makeSuite('Uniswap adapters', (testEnv: TestEnv) => {
const amountDAIToBorrow = await convertToCurrencyDecimals( const amountDAIToBorrow = await convertToCurrencyDecimals(
dai.address, dai.address,
new BigNumber(userGlobalDataBefore.availableBorrowsETH.toString()) new BigNumber(userGlobalDataBefore.availableBorrowsBase.toString())
.div(daiPrice.toString()) .div(daiPrice.toString())
.multipliedBy(0.8) .multipliedBy(0.8)
.toFixed(0) .toFixed(0)
@ -141,7 +141,7 @@ makeSuite('Uniswap adapters', (testEnv: TestEnv) => {
const userGlobalDataBefore2 = await pool.getUserAccountData(borrower.address); const userGlobalDataBefore2 = await pool.getUserAccountData(borrower.address);
const amountWETHToBorrow = new BigNumber(userGlobalDataBefore2.availableBorrowsETH.toString()) const amountWETHToBorrow = new BigNumber(userGlobalDataBefore2.availableBorrowsBase.toString())
.multipliedBy(0.8) .multipliedBy(0.8)
.toFixed(0); .toFixed(0);

View File

@ -29,7 +29,7 @@ import {
deployFlashLiquidationAdapter, deployFlashLiquidationAdapter,
authorizeWETHGateway, authorizeWETHGateway,
} from '../../helpers/contracts-deployments'; } from '../../helpers/contracts-deployments';
import { Signer } from 'ethers'; import { ethers, Signer } from 'ethers';
import { TokenContractId, eContractid, tEthereumAddress, AavePools } from '../../helpers/types'; import { TokenContractId, eContractid, tEthereumAddress, AavePools } from '../../helpers/types';
import { MintableERC20 } from '../../types/MintableERC20'; import { MintableERC20 } from '../../types/MintableERC20';
import { import {
@ -212,7 +212,7 @@ const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => {
const [tokens, aggregators] = getPairsTokenAggregator(allTokenAddresses, allAggregatorsAddresses); const [tokens, aggregators] = getPairsTokenAggregator(allTokenAddresses, allAggregatorsAddresses);
await deployAaveOracle([tokens, aggregators, fallbackOracle.address, mockTokens.WETH.address]); await deployAaveOracle([tokens, aggregators, fallbackOracle.address, mockTokens.WETH.address, ethers.constants.WeiPerEther.toString()]);
await waitForTx(await addressesProvider.setPriceOracle(fallbackOracle.address)); await waitForTx(await addressesProvider.setPriceOracle(fallbackOracle.address));
const lendingRateOracle = await deployLendingRateOracle(); const lendingRateOracle = await deployLendingRateOracle();

View File

@ -55,7 +55,7 @@ makeSuite('LendingPool liquidation - liquidator receiving aToken', (testEnv) =>
const amountDAIToBorrow = await convertToCurrencyDecimals( const amountDAIToBorrow = await convertToCurrencyDecimals(
dai.address, dai.address,
new BigNumber(userGlobalData.availableBorrowsETH.toString()) new BigNumber(userGlobalData.availableBorrowsBase.toString())
.div(daiPrice.toString()) .div(daiPrice.toString())
.multipliedBy(0.95) .multipliedBy(0.95)
.toFixed(0) .toFixed(0)
@ -269,7 +269,7 @@ makeSuite('LendingPool liquidation - liquidator receiving aToken', (testEnv) =>
const amountUSDCToBorrow = await convertToCurrencyDecimals( const amountUSDCToBorrow = await convertToCurrencyDecimals(
usdc.address, usdc.address,
new BigNumber(userGlobalData.availableBorrowsETH.toString()) new BigNumber(userGlobalData.availableBorrowsBase.toString())
.div(usdcPrice.toString()) .div(usdcPrice.toString())
.multipliedBy(0.9502) .multipliedBy(0.9502)
.toFixed(0) .toFixed(0)

View File

@ -83,7 +83,7 @@ makeSuite('LendingPool liquidation - liquidator receiving the underlying asset',
const amountDAIToBorrow = await convertToCurrencyDecimals( const amountDAIToBorrow = await convertToCurrencyDecimals(
dai.address, dai.address,
new BigNumber(userGlobalData.availableBorrowsETH.toString()) new BigNumber(userGlobalData.availableBorrowsBase.toString())
.div(daiPrice.toString()) .div(daiPrice.toString())
.multipliedBy(0.95) .multipliedBy(0.95)
.toFixed(0) .toFixed(0)
@ -267,7 +267,7 @@ makeSuite('LendingPool liquidation - liquidator receiving the underlying asset',
const amountUSDCToBorrow = await convertToCurrencyDecimals( const amountUSDCToBorrow = await convertToCurrencyDecimals(
usdc.address, usdc.address,
new BigNumber(userGlobalData.availableBorrowsETH.toString()) new BigNumber(userGlobalData.availableBorrowsBase.toString())
.div(usdcPrice.toString()) .div(usdcPrice.toString())
.multipliedBy(0.9502) .multipliedBy(0.9502)
.toFixed(0) .toFixed(0)

View File

@ -224,7 +224,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => {
const amountUSDCToBorrow = await convertToCurrencyDecimals( const amountUSDCToBorrow = await convertToCurrencyDecimals(
usdc.address, usdc.address,
new BigNumber(userGlobalData.availableBorrowsETH.toString()) new BigNumber(userGlobalData.availableBorrowsBase.toString())
.div(usdcPrice.toString()) .div(usdcPrice.toString())
.multipliedBy(0.9502) .multipliedBy(0.9502)
.toFixed(0) .toFixed(0)