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 borrowCap;
uint256 supplyCap;
uint256 exposureCap;
bool stableBorrowingEnabled;
bool borrowingEnabled;
}
@ -74,8 +73,7 @@ contract ATokensAndRatesHelper is Ownable {
inputParams[i].asset,
inputParams[i].baseLTV,
inputParams[i].liquidationThreshold,
inputParams[i].liquidationBonus,
inputParams[i].exposureCap
inputParams[i].liquidationBonus
);
if (inputParams[i].borrowingEnabled) {

View File

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

View File

@ -159,13 +159,6 @@ interface ILendingPoolConfigurator {
**/
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
* @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 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 exposureCap The exposure cap for the collateral reserve. If cap is reached, effective LTV = 0
* means the liquidator will receive a 5% bonus
**/
function configureReserveAsCollateral(
address asset,
uint256 ltv,
uint256 liquidationThreshold,
uint256 liquidationBonus,
uint256 exposureCap
uint256 liquidationBonus
) external;
/**
@ -392,13 +383,6 @@ interface ILendingPoolConfigurator {
**/
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
* @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 {
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 FallbackOracleUpdated(address indexed fallbackOracle);
mapping(address => IChainlinkAggregator) private assetsSources;
IPriceOracleGetter private _fallbackOracle;
address public immutable WETH;
address public immutable BASE_CURRENCY;
uint256 public immutable BASE_CURRENCY_UNIT;
/// @notice Constructor
/// @param assets The addresses of the assets
/// @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
/// 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(
address[] memory assets,
address[] memory sources,
address fallbackOracle,
address weth
address baseCurrency,
uint256 baseCurrencyUnit
) public {
_setFallbackOracle(fallbackOracle);
_setAssetsSources(assets, sources);
WETH = weth;
emit WethSet(weth);
BASE_CURRENCY = baseCurrency;
BASE_CURRENCY_UNIT = baseCurrencyUnit;
emit BaseCurrencySet(baseCurrency, baseCurrencyUnit);
}
/// @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) {
IChainlinkAggregator source = assetsSources[asset];
if (asset == WETH) {
return 1 ether;
if (asset == BASE_CURRENCY) {
return BASE_CURRENCY_UNIT;
} else if (address(source) == address(0)) {
return _fallbackOracle.getAssetPrice(asset);
} else {

View File

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

View File

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

View File

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

View File

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

View File

@ -296,8 +296,7 @@ contract LendingPoolConfigurator is VersionedInitializable, ILendingPoolConfigur
address asset,
uint256 ltv,
uint256 liquidationThreshold,
uint256 liquidationBonus,
uint256 exposureCap
uint256 liquidationBonus
) external override onlyRiskOrPoolAdmins {
DataTypes.ReserveConfigurationMap memory currentConfig = _pool.getConfiguration(asset);
@ -331,7 +330,6 @@ contract LendingPoolConfigurator is VersionedInitializable, ILendingPoolConfigur
currentConfig.setLtv(ltv);
currentConfig.setLiquidationThreshold(liquidationThreshold);
currentConfig.setLiquidationBonus(liquidationBonus);
currentConfig.setExposureCap(exposureCap);
_pool.setConfiguration(asset, currentConfig.data);
@ -458,21 +456,6 @@ contract LendingPoolConfigurator is VersionedInitializable, ILendingPoolConfigur
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
function setReserveInterestRateStrategyAddress(address asset, address rateStrategyAddress)
external

View File

@ -22,7 +22,6 @@ library ReserveConfiguration {
uint256 constant RESERVE_FACTOR_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000FFFFFFFFFFFFFFFF; // prettier-ignore
uint256 constant BORROW_CAP_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000FFFFFFFFFFFFFFFFFFFF; // 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
uint256 constant LIQUIDATION_THRESHOLD_START_BIT_POSITION = 16;
@ -37,7 +36,6 @@ library ReserveConfiguration {
uint256 constant RESERVE_FACTOR_START_BIT_POSITION = 64;
uint256 constant BORROW_CAP_START_BIT_POSITION = 80;
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_LIQUIDATION_THRESHOLD = 65535;
@ -46,7 +44,6 @@ library ReserveConfiguration {
uint256 constant MAX_VALID_RESERVE_FACTOR = 65535;
uint256 constant MAX_VALID_BORROW_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
@ -386,33 +383,6 @@ library ReserveConfiguration {
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
* @param self The reserve configuration
@ -476,7 +446,6 @@ library ReserveConfiguration {
internal
view
returns (
uint256,
uint256,
uint256
)
@ -485,8 +454,7 @@ library ReserveConfiguration {
return (
(dataLocal & ~BORROW_CAP_MASK) >> BORROW_CAP_START_BIT_POSITION,
(dataLocal & ~SUPPLY_CAP_MASK) >> SUPPLY_CAP_START_BIT_POSITION,
(dataLocal & ~EXPOSURE_CAP_MASK) >> EXPOSURE_CAP_START_BIT_POSITION
(dataLocal & ~SUPPLY_CAP_MASK) >> SUPPLY_CAP_START_BIT_POSITION
);
}
@ -524,15 +492,13 @@ library ReserveConfiguration {
internal
pure
returns (
uint256,
uint256,
uint256
)
{
return (
(self.data & ~BORROW_CAP_MASK) >> BORROW_CAP_START_BIT_POSITION,
(self.data & ~SUPPLY_CAP_MASK) >> SUPPLY_CAP_START_BIT_POSITION,
(self.data & ~EXPOSURE_CAP_MASK) >> EXPOSURE_CAP_START_BIT_POSITION
(self.data & ~SUPPLY_CAP_MASK) >> SUPPLY_CAP_START_BIT_POSITION
);
}
@ -586,17 +552,4 @@ library ReserveConfiguration {
{
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_STABLE_DEBT_NOT_ZERO = '89';
string public constant RL_VARIABLE_DEBT_SUPPLY_NOT_ZERO = '90';
string public constant RC_INVALID_EXPOSURE_CAP = '92';
string public constant VL_COLLATERAL_EXPOSURE_CAP_EXCEEDED = '93';
string public constant VL_LTV_VALIDATION_FAILED = '93';
string public constant VL_SAME_BLOCK_BORROW_REPAY = '94';
string public constant LPC_FLASHLOAN_PREMIUMS_MISMATCH = '95';
string public constant LPC_FLASHLOAN_PREMIUM_INVALID = '96';

View File

@ -32,42 +32,36 @@ library GenericLogic {
uint256 assetPrice;
uint256 assetUnit;
uint256 userBalance;
uint256 userBalanceETH;
uint256 userBalanceInBaseCurrency;
uint256 userDebt;
uint256 userStableDebt;
uint256 userDebtETH;
uint256 userDebtInBaseCurrency;
uint256 decimals;
uint256 ltv;
uint256 liquidationThreshold;
uint256 i;
uint256 healthFactor;
uint256 totalCollateralInETH;
uint256 totalDebtInETH;
uint256 totalCollateralInBaseCurrency;
uint256 totalDebtInBaseCurrency;
uint256 avgLtv;
uint256 avgUncappedLtv;
uint256 avgLiquidationThreshold;
uint256 reservesLength;
uint256 normalizedIncome;
uint256 normalizedDebt;
uint256 exposureCap;
uint256 aTokenSupply;
bool healthFactorBelowThreshold;
address currentReserveAddress;
bool usageAsCollateralEnabled;
bool userUsesReserveAsCollateral;
bool exposureCapCrossed;
bool hasZeroLtvCollateral;
}
/**
* @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.
* @param user The address of the user
* @param reservesData Data of all the reserves
* @param userConfig The configuration of the user
* @param reserves The list of the available reserves
* @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(
address user,
@ -85,13 +79,13 @@ library GenericLogic {
uint256,
uint256,
uint256,
uint256
bool
)
{
CalculateUserAccountDataVars memory vars;
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++) {
if (!userConfig.isUsingAsCollateralOrBorrowing(vars.i)) {
@ -107,40 +101,25 @@ library GenericLogic {
(vars.ltv, vars.liquidationThreshold, , vars.decimals, ) = currentReserve
.configuration
.getParams();
vars.exposureCap = currentReserve.configuration.getExposureCap();
vars.assetUnit = 10**vars.decimals;
vars.assetPrice = IPriceOracleGetter(oracle).getAssetPrice(vars.currentReserveAddress);
if (vars.liquidationThreshold != 0 && userConfig.isUsingAsCollateral(vars.i)) {
vars.normalizedIncome = currentReserve.getNormalizedIncome();
vars.userBalance = IScaledBalanceToken(currentReserve.aTokenAddress).scaledBalanceOf(user);
vars.userBalance = vars.userBalance.rayMul(vars.normalizedIncome);
if (vars.exposureCap != 0) {
(vars.userBalance, vars.aTokenSupply) = IScaledBalanceToken(currentReserve.aTokenAddress)
.getScaledUserBalanceAndSupply(user);
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.userBalanceInBaseCurrency = vars.assetPrice.mul(vars.userBalance).div(vars.assetUnit);
vars.totalCollateralInBaseCurrency = vars.totalCollateralInBaseCurrency.add(
vars.userBalanceInBaseCurrency
);
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.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.add(vars.userStableDebt);
vars.userDebtETH = vars.assetPrice.mul(vars.userDebt).div(vars.assetUnit);
vars.totalDebtInETH = vars.totalDebtInETH.add(vars.userDebtETH);
vars.userDebtInBaseCurrency = vars.assetPrice.mul(vars.userDebt).div(vars.assetUnit);
vars.totalDebtInBaseCurrency = vars.totalDebtInBaseCurrency.add(
vars.userDebtInBaseCurrency
);
}
}
vars.avgLtv = vars.totalCollateralInETH > 0 ? vars.avgLtv.div(vars.totalCollateralInETH) : 0;
vars.avgUncappedLtv = vars.totalCollateralInETH > 0
? vars.avgUncappedLtv.div(vars.totalCollateralInETH)
vars.avgLtv = vars.totalCollateralInBaseCurrency > 0
? vars.avgLtv.div(vars.totalCollateralInBaseCurrency)
: 0;
vars.avgLiquidationThreshold = vars.totalCollateralInETH > 0
? vars.avgLiquidationThreshold.div(vars.totalCollateralInETH)
vars.avgLiquidationThreshold = vars.totalCollateralInBaseCurrency > 0
? vars.avgLiquidationThreshold.div(vars.totalCollateralInBaseCurrency)
: 0;
vars.healthFactor = calculateHealthFactorFromBalances(
vars.totalCollateralInETH,
vars.totalDebtInETH,
vars.totalCollateralInBaseCurrency,
vars.totalDebtInBaseCurrency,
vars.avgLiquidationThreshold
);
return (
vars.totalCollateralInETH,
vars.totalDebtInETH,
vars.totalCollateralInBaseCurrency,
vars.totalDebtInBaseCurrency,
vars.avgLtv,
vars.avgLiquidationThreshold,
vars.healthFactor,
vars.avgUncappedLtv
vars.hasZeroLtvCollateral
);
}
/**
* @dev Calculates the health factor from the corresponding balances
* @param totalCollateralInETH The total collateral in ETH
* @param totalDebtInETH The total debt in ETH
* @param totalCollateralInBaseCurrency The total collateral in the base currency used by the price feed
* @param totalDebtInBaseCurrency The total debt in the base currency used by the price feed
* @param liquidationThreshold The avg liquidation threshold
* @return The health factor calculated from the balances provided
**/
function calculateHealthFactorFromBalances(
uint256 totalCollateralInETH,
uint256 totalDebtInETH,
uint256 totalCollateralInBaseCurrency,
uint256 totalDebtInBaseCurrency,
uint256 liquidationThreshold
) 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
* @param totalCollateralInETH The total collateral in ETH
* @param totalDebtInETH The total borrow balance
* @param totalCollateralInBaseCurrency The total collateral in the base currency used by the price feed
* @param totalDebtInBaseCurrency The total borrow balance in the base currency used by the price feed
* @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(
uint256 totalCollateralInETH,
uint256 totalDebtInETH,
function calculateAvailableBorrows(
uint256 totalCollateralInBaseCurrency,
uint256 totalDebtInBaseCurrency,
uint256 ltv
) internal pure returns (uint256) {
uint256 availableBorrowsETH = totalCollateralInETH.percentMul(ltv);
uint256 availableBorrowsInBaseCurrency = totalCollateralInBaseCurrency.percentMul(ltv);
if (availableBorrowsETH < totalDebtInETH) {
if (availableBorrowsInBaseCurrency < totalDebtInBaseCurrency) {
return 0;
}
availableBorrowsETH = availableBorrowsETH.sub(totalDebtInETH);
return availableBorrowsETH;
availableBorrowsInBaseCurrency = availableBorrowsInBaseCurrency.sub(totalDebtInBaseCurrency);
return availableBorrowsInBaseCurrency;
}
/**
@ -249,7 +232,7 @@ library GenericLogic {
uint256,
uint256,
uint256,
uint256
bool
)
{
return

View File

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

View File

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

View File

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

View File

@ -17,7 +17,6 @@ export const MAX_UINT_AMOUNT =
'115792089237316195423570985008687907853269984665640564039457584007913129639935';
export const MAX_BORROW_CAP = '68719476735';
export const MAX_SUPPLY_CAP = '68719476735';
export const MAX_EXPOSURE_CAP = '68719476735';
export const ONE_YEAR = '31536000';
export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
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 {
tEthereumAddress,
@ -188,8 +188,8 @@ export const deployAaveLibraries = async (
return {
['__$de8c0cf1a7d7c36c802af9a64fb9d86036$__']: validationLogic.address,
['__$22cd43a9dda9ce44e9b92ba393b88fb9ac$__']: reserveLogic.address,
["__$52a8a86ab43135662ff256bbc95497e8e3$__"]: genericLogic.address,
}
['__$52a8a86ab43135662ff256bbc95497e8e3$__']: genericLogic.address,
};
};
export const deployLendingPool = async (verify?: boolean) => {
@ -224,7 +224,7 @@ export const deployMockAggregator = async (price: tStringTokenSmallUnits, verify
);
export const deployAaveOracle = async (
args: [tEthereumAddress[], tEthereumAddress[], tEthereumAddress, tEthereumAddress],
args: [tEthereumAddress[], tEthereumAddress[], tEthereumAddress, tEthereumAddress, string],
verify?: boolean
) =>
withSaveAndVerify(

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -30,7 +30,7 @@ import {
authorizeWETHGateway,
} from '../../helpers/contracts-deployments';
import { eEthereumNetwork } from '../../helpers/types';
import { Signer } from 'ethers';
import { ethers, Signer } from 'ethers';
import { TokenContractId, eContractid, tEthereumAddress, AavePools } from '../../helpers/types';
import { MintableERC20 } from '../../types/MintableERC20';
import {
@ -215,7 +215,13 @@ const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => {
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));
const lendingRateOracle = await deployLendingRateOracle();
@ -243,12 +249,8 @@ const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => {
const config = loadPoolConfig(ConfigNames.Aave);
const {
ATokenNamePrefix,
StableDebtTokenNamePrefix,
VariableDebtTokenNamePrefix,
SymbolPrefix,
} = config;
const { ATokenNamePrefix, StableDebtTokenNamePrefix, VariableDebtTokenNamePrefix, SymbolPrefix } =
config;
const treasuryAddress = await getTreasuryAddress(config);
await initReservesByHelper(

View File

@ -229,7 +229,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
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(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
});
it('Unpauses the ETH reserve by pool admin ', async () => {
@ -264,7 +263,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
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(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
});
it('Pauses the ETH reserve by emergency admin', async () => {
const { configurator, weth, helpersContract, addressesProvider, users, emergencyAdmin } =
@ -298,7 +296,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
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(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
});
it('Unpauses the ETH reserve by emergency admin ', async () => {
@ -333,7 +330,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
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(borrowCap).to.be.equal(strategyWETH.borrowCap);
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 () => {
@ -384,7 +380,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
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(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
});
it('Unfreezes the ETH reserve by Pool admin', async () => {
@ -419,7 +414,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
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(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
});
it('Freezes the ETH reserve by Risk Admin', async () => {
const { configurator, weth, helpersContract, riskAdmin } = testEnv;
await configurator.connect(riskAdmin.signer).freezeReserve(weth.address);
@ -452,7 +447,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
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(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
});
it('Unfreezes the ETH reserve by Risk admin', async () => {
@ -487,7 +481,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
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(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
});
it('Check the onlyRiskOrPoolAdmins on freezeReserve ', async () => {
@ -537,7 +530,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
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(borrowCap).to.be.equal(strategyWETH.borrowCap);
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 () => {
@ -573,7 +565,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
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(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
expect(variableBorrowIndex.toString()).to.be.equal(RAY);
});
@ -609,7 +600,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
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(borrowCap).to.be.equal(strategyWETH.borrowCap);
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 () => {
@ -645,7 +635,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
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(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
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 () => {
const { configurator, helpersContract, weth } = testEnv;
await configurator.configureReserveAsCollateral(weth.address, 0, 0, 0, 0);
await configurator.configureReserveAsCollateral(weth.address, 0, 0, 0);
const {
decimals,
@ -701,7 +690,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
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(borrowCap).to.be.equal(strategyWETH.borrowCap);
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 () => {
const { configurator, helpersContract, weth } = testEnv;
await configurator.configureReserveAsCollateral(weth.address, '8000', '8250', '10500', '0');
await configurator.configureReserveAsCollateral(weth.address, '8000', '8250', '10500');
const {
decimals,
@ -736,7 +724,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
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(borrowCap).to.be.equal(strategyWETH.borrowCap);
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 () => {
const { configurator, helpersContract, weth, riskAdmin } = testEnv;
await configurator
.connect(riskAdmin.signer)
.configureReserveAsCollateral(weth.address, 0, 0, 0, 0);
.configureReserveAsCollateral(weth.address, 0, 0, 0);
const {
decimals,
@ -772,7 +760,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
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(borrowCap).to.be.equal(strategyWETH.borrowCap);
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 () => {
const { configurator, helpersContract, weth, riskAdmin } = testEnv;
await configurator
.connect(riskAdmin.signer)
.configureReserveAsCollateral(weth.address, '8000', '8250', '10500', '0');
.configureReserveAsCollateral(weth.address, '8000', '8250', '10500');
const {
decimals,
@ -809,7 +796,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
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(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
});
it('Check the onlyRiskOrPoolAdmin on configureReserveAsCollateral ', async () => {
@ -834,7 +820,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
await expect(
configurator
.connect(emergencyAdmin.signer)
.configureReserveAsCollateral(weth.address, '7500', '8000', '10500', '0'),
.configureReserveAsCollateral(weth.address, '7500', '8000', '10500'),
CALLER_NOT_POOL_ADMIN
).to.be.revertedWith(LPC_CALLER_NOT_RISK_OR_POOL_ADMIN);
});
@ -853,7 +839,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
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(borrowCap).to.be.equal(strategyWETH.borrowCap);
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 () => {
@ -887,7 +872,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
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(borrowCap).to.be.equal(strategyWETH.borrowCap);
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 () => {
const { configurator, helpersContract, weth, riskAdmin } = testEnv;
await configurator.connect(riskAdmin.signer).disableReserveStableRate(weth.address);
@ -920,7 +905,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
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(borrowCap).to.be.equal(strategyWETH.borrowCap);
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 () => {
@ -954,7 +938,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
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(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
});
it('Check the onlyRiskOrPoolAdmin on disableReserveStableRate', async () => {
@ -1012,13 +995,6 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
CALLER_NOT_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 () => {
const { configurator, helpersContract, weth } = testEnv;
@ -1034,7 +1010,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
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(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
expect(reserveFactor).to.be.equal(1000);
});
it('Changes the reserve factor of WETH risk admin', async () => {
@ -1067,7 +1042,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
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(borrowCap).to.be.equal(strategyWETH.borrowCap);
expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
expect(reserveFactor).to.be.equal(1000);
});
it('Changes the reserve factor of WETH risk admin', async () => {
const { configurator, helpersContract, weth, riskAdmin } = testEnv;
await configurator.connect(riskAdmin.signer).setReserveFactor(weth.address, '1000');
@ -1146,7 +1121,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address
);
const isPaused = await helpersContract.getPaused(weth.address);
@ -1163,8 +1138,9 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(1000);
expect(borrowCap).to.be.equal('3000000');
expect(supplyCap).to.be.equal(strategyWETH.supplyCap);
expect(exposureCap).to.be.equal(strategyWETH.exposureCap);
});
it('Changes the borrow Cap of WETH risk admin', async () => {
const { configurator, helpersContract, weth, riskAdmin } = testEnv;
await configurator.connect(riskAdmin.signer).setBorrowCap(weth.address, '3000000');
@ -1179,7 +1155,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address
);
const isPaused = await helpersContract.getPaused(weth.address);
@ -1196,7 +1172,6 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(1000);
expect(borrowCap).to.be.equal('3000000');
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 () => {
@ -1213,7 +1188,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address
);
const isPaused = await helpersContract.getPaused(weth.address);
@ -1230,8 +1205,8 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(1000);
expect(borrowCap).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 () => {
const { configurator, helpersContract, weth, riskAdmin } = testEnv;
await configurator.connect(riskAdmin.signer).setSupplyCap(weth.address, '3000000');
@ -1246,7 +1221,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
isActive,
isFrozen,
} = await helpersContract.getReserveConfigurationData(weth.address);
const { borrowCap, supplyCap, exposureCap } = await helpersContract.getReserveCaps(
const { borrowCap, supplyCap } = await helpersContract.getReserveCaps(
weth.address
);
const isPaused = await helpersContract.getPaused(weth.address);
@ -1263,74 +1238,8 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
expect(reserveFactor).to.be.equal(1000);
expect(borrowCap).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 () => {
const { configurator, helpersContract, weth, riskAdmin } = testEnv;
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(
dai.address,
new BigNumber(userGlobalData.availableBorrowsETH.toString())
new BigNumber(userGlobalData.availableBorrowsBase.toString())
.div(daiPrice.toString())
.multipliedBy(0.95)
.toFixed(0)
@ -269,7 +269,7 @@ makeSuite('LendingPool liquidation - liquidator receiving aToken', (testEnv) =>
const amountUSDCToBorrow = await convertToCurrencyDecimals(
usdc.address,
new BigNumber(userGlobalData.availableBorrowsETH.toString())
new BigNumber(userGlobalData.availableBorrowsBase.toString())
.div(usdcPrice.toString())
.multipliedBy(0.9502)
.toFixed(0)

View File

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

View File

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

View File

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

View File

@ -29,7 +29,7 @@ import {
deployFlashLiquidationAdapter,
authorizeWETHGateway,
} from '../../helpers/contracts-deployments';
import { Signer } from 'ethers';
import { ethers, Signer } from 'ethers';
import { TokenContractId, eContractid, tEthereumAddress, AavePools } from '../../helpers/types';
import { MintableERC20 } from '../../types/MintableERC20';
import {
@ -212,7 +212,7 @@ const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => {
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));
const lendingRateOracle = await deployLendingRateOracle();

View File

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

View File

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

View File

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