mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
Merge branch 'master' into feat/uniswap-adapter-flashloan
# Conflicts: # helpers/contracts-deployments.ts # helpers/contracts-getters.ts
This commit is contained in:
commit
e7183536b3
|
@ -14,17 +14,13 @@ usePlugin('@nomiclabs/buidler-etherscan');
|
||||||
usePlugin('buidler-gas-reporter');
|
usePlugin('buidler-gas-reporter');
|
||||||
|
|
||||||
const SKIP_LOAD = process.env.SKIP_LOAD === 'true';
|
const SKIP_LOAD = process.env.SKIP_LOAD === 'true';
|
||||||
const DEFAULT_BLOCK_GAS_LIMIT = 12000000;
|
const DEFAULT_BLOCK_GAS_LIMIT = 12450000;
|
||||||
const DEFAULT_GAS_PRICE = 10;
|
const DEFAULT_GAS_PRICE = 10;
|
||||||
const HARDFORK = 'istanbul';
|
const HARDFORK = 'istanbul';
|
||||||
const INFURA_KEY = process.env.INFURA_KEY || '';
|
const INFURA_KEY = process.env.INFURA_KEY || '';
|
||||||
const ETHERSCAN_KEY = process.env.ETHERSCAN_KEY || '';
|
const ETHERSCAN_KEY = process.env.ETHERSCAN_KEY || '';
|
||||||
const MNEMONIC_PATH = "m/44'/60'/0'/0";
|
const MNEMONIC_PATH = "m/44'/60'/0'/0";
|
||||||
const MNEMONICS: {[network: string]: string} = {
|
const MNEMONIC = process.env.MNEMONIC || '';
|
||||||
[eEthereumNetwork.kovan]: process.env.MNEMONIC || '',
|
|
||||||
[eEthereumNetwork.ropsten]: process.env.MNEMONIC || '',
|
|
||||||
[eEthereumNetwork.main]: process.env.MNEMONIC || '',
|
|
||||||
};
|
|
||||||
|
|
||||||
// Prevent to load scripts before compilation and typechain
|
// Prevent to load scripts before compilation and typechain
|
||||||
if (!SKIP_LOAD) {
|
if (!SKIP_LOAD) {
|
||||||
|
@ -44,7 +40,7 @@ const getCommonNetworkConfig = (networkName: eEthereumNetwork, networkId: number
|
||||||
gasMultiplier: DEFAULT_GAS_PRICE,
|
gasMultiplier: DEFAULT_GAS_PRICE,
|
||||||
chainId: networkId,
|
chainId: networkId,
|
||||||
accounts: {
|
accounts: {
|
||||||
mnemonic: MNEMONICS[networkName],
|
mnemonic: MNEMONIC,
|
||||||
path: MNEMONIC_PATH,
|
path: MNEMONIC_PATH,
|
||||||
initialIndex: 0,
|
initialIndex: 0,
|
||||||
count: 20,
|
count: 20,
|
||||||
|
|
|
@ -56,7 +56,7 @@ contract LendingPoolAddressesProviderRegistry is Ownable, ILendingPoolAddressesP
|
||||||
* @param provider the pool address to be registered
|
* @param provider the pool address to be registered
|
||||||
**/
|
**/
|
||||||
function registerAddressesProvider(address provider, uint256 id) external override onlyOwner {
|
function registerAddressesProvider(address provider, uint256 id) external override onlyOwner {
|
||||||
require(id != 0, Errors.INVALID_ADDRESSES_PROVIDER_ID);
|
require(id != 0, Errors.LPAPR_INVALID_ADDRESSES_PROVIDER_ID);
|
||||||
|
|
||||||
_addressesProviders[provider] = id;
|
_addressesProviders[provider] = id;
|
||||||
_addToAddressesProvidersList(provider);
|
_addToAddressesProvidersList(provider);
|
||||||
|
@ -68,7 +68,7 @@ contract LendingPoolAddressesProviderRegistry is Ownable, ILendingPoolAddressesP
|
||||||
* @param provider the pool address to be unregistered
|
* @param provider the pool address to be unregistered
|
||||||
**/
|
**/
|
||||||
function unregisterAddressesProvider(address provider) external override onlyOwner {
|
function unregisterAddressesProvider(address provider) external override onlyOwner {
|
||||||
require(_addressesProviders[provider] > 0, Errors.PROVIDER_NOT_REGISTERED);
|
require(_addressesProviders[provider] > 0, Errors.LPAPR_PROVIDER_NOT_REGISTERED);
|
||||||
_addressesProviders[provider] = 0;
|
_addressesProviders[provider] = 0;
|
||||||
emit AddressesProviderUnregistered(provider);
|
emit AddressesProviderUnregistered(provider);
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,11 +33,11 @@ interface ILendingPool {
|
||||||
event Withdraw(address indexed reserve, address indexed user, address indexed to, uint256 amount);
|
event Withdraw(address indexed reserve, address indexed user, address indexed to, uint256 amount);
|
||||||
|
|
||||||
event BorrowAllowanceDelegated(
|
event BorrowAllowanceDelegated(
|
||||||
address indexed asset,
|
|
||||||
address indexed fromUser,
|
address indexed fromUser,
|
||||||
address indexed toUser,
|
address indexed toUser,
|
||||||
uint256 interestRateMode,
|
address[] assets,
|
||||||
uint256 amount
|
uint256[] interestRateModes,
|
||||||
|
uint256[] amounts
|
||||||
);
|
);
|
||||||
/**
|
/**
|
||||||
* @dev emitted on borrow
|
* @dev emitted on borrow
|
||||||
|
@ -196,17 +196,17 @@ interface ILendingPool {
|
||||||
) external;
|
) external;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Sets allowance to borrow on a certain type of debt asset for a certain user address
|
* @dev Sets allowance to borrow on a certain type of debt assets for a certain user address
|
||||||
* @param asset The underlying asset of the debt token
|
* @param assets The underlying asset of each debt token
|
||||||
* @param user The user to give allowance to
|
* @param user The user to give allowance to
|
||||||
* @param interestRateMode Type of debt: 1 for stable, 2 for variable
|
* @param interestRateModes Types of debt: 1 for stable, 2 for variable
|
||||||
* @param amount Allowance amount to borrow
|
* @param amounts Allowance amounts to borrow
|
||||||
**/
|
**/
|
||||||
function delegateBorrowAllowance(
|
function delegateBorrowAllowance(
|
||||||
address asset,
|
address[] calldata assets,
|
||||||
address user,
|
address user,
|
||||||
uint256 interestRateMode,
|
uint256[] calldata interestRateModes,
|
||||||
uint256 amount
|
uint256[] calldata amounts
|
||||||
) external;
|
) external;
|
||||||
|
|
||||||
function getBorrowAllowance(
|
function getBorrowAllowance(
|
||||||
|
|
|
@ -52,7 +52,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
|
||||||
function _onlyLendingPoolConfigurator() internal view {
|
function _onlyLendingPoolConfigurator() internal view {
|
||||||
require(
|
require(
|
||||||
_addressesProvider.getLendingPoolConfigurator() == msg.sender,
|
_addressesProvider.getLendingPoolConfigurator() == msg.sender,
|
||||||
Errors.CALLER_NOT_LENDING_POOL_CONFIGURATOR
|
Errors.LP_CALLER_NOT_LENDING_POOL_CONFIGURATOR
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
|
||||||
* - The contract must not be paused.
|
* - The contract must not be paused.
|
||||||
*/
|
*/
|
||||||
function _whenNotPaused() internal view {
|
function _whenNotPaused() internal view {
|
||||||
require(!_paused, Errors.IS_PAUSED);
|
require(!_paused, Errors.P_IS_PAUSED);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getRevision() internal override pure returns (uint256) {
|
function getRevision() internal override pure returns (uint256) {
|
||||||
|
@ -183,23 +183,32 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Sets allowance to borrow on a certain type of debt asset for a certain user address
|
* @dev Sets allowance to borrow on a certain type of debt assets for a certain user address
|
||||||
* @param asset The underlying asset of the debt token
|
* @param assets The underlying asset of each debt token
|
||||||
* @param user The user to give allowance to
|
* @param user The user to give allowance to
|
||||||
* @param interestRateMode Type of debt: 1 for stable, 2 for variable
|
* @param interestRateModes Types of debt: 1 for stable, 2 for variable
|
||||||
* @param amount Allowance amount to borrow
|
* @param amounts Allowance amounts to borrow
|
||||||
**/
|
**/
|
||||||
function delegateBorrowAllowance(
|
function delegateBorrowAllowance(
|
||||||
address asset,
|
address[] calldata assets,
|
||||||
address user,
|
address user,
|
||||||
uint256 interestRateMode,
|
uint256[] calldata interestRateModes,
|
||||||
uint256 amount
|
uint256[] calldata amounts
|
||||||
) external override {
|
) external override {
|
||||||
_whenNotPaused();
|
_whenNotPaused();
|
||||||
address debtToken = _reserves[asset].getDebtTokenAddress(interestRateMode);
|
|
||||||
|
|
||||||
_borrowAllowance[debtToken][msg.sender][user] = amount;
|
uint256 countAssets = assets.length;
|
||||||
emit BorrowAllowanceDelegated(asset, msg.sender, user, interestRateMode, amount);
|
require(
|
||||||
|
countAssets == interestRateModes.length && countAssets == amounts.length,
|
||||||
|
Errors.LP_INCONSISTENT_PARAMS_LENGTH
|
||||||
|
);
|
||||||
|
|
||||||
|
for (uint256 i = 0; i < countAssets; i++) {
|
||||||
|
address debtToken = _reserves[assets[i]].getDebtTokenAddress(interestRateModes[i]);
|
||||||
|
_borrowAllowance[debtToken][msg.sender][user] = amounts[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
emit BorrowAllowanceDelegated(msg.sender, user, assets, interestRateModes, amounts);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -227,7 +236,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
|
||||||
_borrowAllowance[debtToken][onBehalfOf][msg
|
_borrowAllowance[debtToken][onBehalfOf][msg
|
||||||
.sender] = _borrowAllowance[debtToken][onBehalfOf][msg.sender].sub(
|
.sender] = _borrowAllowance[debtToken][onBehalfOf][msg.sender].sub(
|
||||||
amount,
|
amount,
|
||||||
Errors.BORROW_ALLOWANCE_ARE_NOT_ENOUGH
|
Errors.LP_BORROW_ALLOWANCE_ARE_NOT_ENOUGH
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
_executeBorrow(
|
_executeBorrow(
|
||||||
|
@ -402,7 +411,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
|
||||||
usageRatio >= REBALANCE_UP_USAGE_RATIO_THRESHOLD &&
|
usageRatio >= REBALANCE_UP_USAGE_RATIO_THRESHOLD &&
|
||||||
currentLiquidityRate <=
|
currentLiquidityRate <=
|
||||||
maxVariableBorrowRate.percentMul(REBALANCE_UP_LIQUIDITY_RATE_THRESHOLD),
|
maxVariableBorrowRate.percentMul(REBALANCE_UP_LIQUIDITY_RATE_THRESHOLD),
|
||||||
Errors.INTEREST_RATE_REBALANCE_CONDITIONS_NOT_MET
|
Errors.LP_INTEREST_RATE_REBALANCE_CONDITIONS_NOT_MET
|
||||||
);
|
);
|
||||||
|
|
||||||
reserve.updateState();
|
reserve.updateState();
|
||||||
|
@ -477,7 +486,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
|
||||||
receiveAToken
|
receiveAToken
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
require(success, Errors.LIQUIDATION_CALL_FAILED);
|
require(success, Errors.LP_LIQUIDATION_CALL_FAILED);
|
||||||
|
|
||||||
(uint256 returnCode, string memory returnMessage) = abi.decode(result, (uint256, string));
|
(uint256 returnCode, string memory returnMessage) = abi.decode(result, (uint256, string));
|
||||||
|
|
||||||
|
@ -543,7 +552,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
|
||||||
//execute action of the receiver
|
//execute action of the receiver
|
||||||
require(
|
require(
|
||||||
vars.receiver.executeOperation(assets, amounts, premiums, msg.sender, params),
|
vars.receiver.executeOperation(assets, amounts, premiums, msg.sender, params),
|
||||||
Errors.INVALID_FLASH_LOAN_EXECUTOR_RETURN
|
Errors.LP_INVALID_FLASH_LOAN_EXECUTOR_RETURN
|
||||||
);
|
);
|
||||||
|
|
||||||
for (vars.i = 0; vars.i < assets.length; vars.i++) {
|
for (vars.i = 0; vars.i < assets.length; vars.i++) {
|
||||||
|
@ -577,7 +586,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
|
||||||
|
|
||||||
_borrowAllowance[vars.debtToken][onBehalfOf][msg.sender] = _borrowAllowance[vars
|
_borrowAllowance[vars.debtToken][onBehalfOf][msg.sender] = _borrowAllowance[vars
|
||||||
.debtToken][onBehalfOf][msg.sender]
|
.debtToken][onBehalfOf][msg.sender]
|
||||||
.sub(vars.currentAmount, Errors.BORROW_ALLOWANCE_ARE_NOT_ENOUGH);
|
.sub(vars.currentAmount, Errors.LP_BORROW_ALLOWANCE_ARE_NOT_ENOUGH);
|
||||||
}
|
}
|
||||||
|
|
||||||
//if the user didn't choose to return the funds, the system checks if there
|
//if the user didn't choose to return the funds, the system checks if there
|
||||||
|
@ -698,7 +707,13 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
|
||||||
* @param asset the address of the reserve
|
* @param asset the address of the reserve
|
||||||
* @return the reserve normalized income
|
* @return the reserve normalized income
|
||||||
*/
|
*/
|
||||||
function getReserveNormalizedIncome(address asset) external virtual override view returns (uint256) {
|
function getReserveNormalizedIncome(address asset)
|
||||||
|
external
|
||||||
|
virtual
|
||||||
|
override
|
||||||
|
view
|
||||||
|
returns (uint256)
|
||||||
|
{
|
||||||
return _reserves[asset].getNormalizedIncome();
|
return _reserves[asset].getNormalizedIncome();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -761,7 +776,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
|
||||||
) external override {
|
) external override {
|
||||||
_whenNotPaused();
|
_whenNotPaused();
|
||||||
|
|
||||||
require(msg.sender == _reserves[asset].aTokenAddress, Errors.CALLER_MUST_BE_AN_ATOKEN);
|
require(msg.sender == _reserves[asset].aTokenAddress, Errors.LP_CALLER_MUST_BE_AN_ATOKEN);
|
||||||
|
|
||||||
ValidationLogic.validateTransfer(
|
ValidationLogic.validateTransfer(
|
||||||
from,
|
from,
|
||||||
|
@ -954,7 +969,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
|
||||||
function _addReserveToList(address asset) internal {
|
function _addReserveToList(address asset) internal {
|
||||||
uint256 reservesCount = _reservesCount;
|
uint256 reservesCount = _reservesCount;
|
||||||
|
|
||||||
require(reservesCount < MAX_NUMBER_RESERVES, Errors.NO_MORE_RESERVES_ALLOWED);
|
require(reservesCount < MAX_NUMBER_RESERVES, Errors.LP_NO_MORE_RESERVES_ALLOWED);
|
||||||
|
|
||||||
bool reserveAlreadyAdded = _reserves[asset].id != 0 || _reservesList[0] == asset;
|
bool reserveAlreadyAdded = _reserves[asset].id != 0 || _reservesList[0] == asset;
|
||||||
|
|
||||||
|
|
|
@ -185,7 +185,7 @@ contract LendingPoolCollateralManager is VersionedInitializable, LendingPoolStor
|
||||||
if (currentAvailableCollateral < vars.maxCollateralToLiquidate) {
|
if (currentAvailableCollateral < vars.maxCollateralToLiquidate) {
|
||||||
return (
|
return (
|
||||||
uint256(Errors.CollateralManagerErrors.NOT_ENOUGH_LIQUIDITY),
|
uint256(Errors.CollateralManagerErrors.NOT_ENOUGH_LIQUIDITY),
|
||||||
Errors.NOT_ENOUGH_LIQUIDITY_TO_LIQUIDATE
|
Errors.LPCM_NOT_ENOUGH_LIQUIDITY_TO_LIQUIDATE
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -263,7 +263,7 @@ contract LendingPoolCollateralManager is VersionedInitializable, LendingPoolStor
|
||||||
receiveAToken
|
receiveAToken
|
||||||
);
|
);
|
||||||
|
|
||||||
return (uint256(Errors.CollateralManagerErrors.NO_ERROR), Errors.NO_ERRORS);
|
return (uint256(Errors.CollateralManagerErrors.NO_ERROR), Errors.LPCM_NO_ERRORS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -196,7 +196,7 @@ contract LendingPoolConfigurator is VersionedInitializable {
|
||||||
* @dev only the lending pool manager can call functions affected by this modifier
|
* @dev only the lending pool manager can call functions affected by this modifier
|
||||||
**/
|
**/
|
||||||
modifier onlyAaveAdmin {
|
modifier onlyAaveAdmin {
|
||||||
require(addressesProvider.getAaveAdmin() == msg.sender, Errors.CALLER_NOT_AAVE_ADMIN);
|
require(addressesProvider.getAaveAdmin() == msg.sender, Errors.LPC_CALLER_NOT_AAVE_ADMIN);
|
||||||
_;
|
_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,23 +230,23 @@ contract LendingPoolConfigurator is VersionedInitializable {
|
||||||
|
|
||||||
require(
|
require(
|
||||||
address(pool) == ITokenConfiguration(aTokenImpl).POOL(),
|
address(pool) == ITokenConfiguration(aTokenImpl).POOL(),
|
||||||
Errors.INVALID_ATOKEN_POOL_ADDRESS
|
Errors.LPC_INVALID_ATOKEN_POOL_ADDRESS
|
||||||
);
|
);
|
||||||
require(
|
require(
|
||||||
address(pool) == ITokenConfiguration(stableDebtTokenImpl).POOL(),
|
address(pool) == ITokenConfiguration(stableDebtTokenImpl).POOL(),
|
||||||
Errors.INVALID_STABLE_DEBT_TOKEN_POOL_ADDRESS
|
Errors.LPC_INVALID_STABLE_DEBT_TOKEN_POOL_ADDRESS
|
||||||
);
|
);
|
||||||
require(
|
require(
|
||||||
address(pool) == ITokenConfiguration(variableDebtTokenImpl).POOL(),
|
address(pool) == ITokenConfiguration(variableDebtTokenImpl).POOL(),
|
||||||
Errors.INVALID_VARIABLE_DEBT_TOKEN_POOL_ADDRESS
|
Errors.LPC_INVALID_VARIABLE_DEBT_TOKEN_POOL_ADDRESS
|
||||||
);
|
);
|
||||||
require(
|
require(
|
||||||
asset == ITokenConfiguration(stableDebtTokenImpl).UNDERLYING_ASSET_ADDRESS(),
|
asset == ITokenConfiguration(stableDebtTokenImpl).UNDERLYING_ASSET_ADDRESS(),
|
||||||
Errors.INVALID_STABLE_DEBT_TOKEN_UNDERLYING_ADDRESS
|
Errors.LPC_INVALID_STABLE_DEBT_TOKEN_UNDERLYING_ADDRESS
|
||||||
);
|
);
|
||||||
require(
|
require(
|
||||||
asset == ITokenConfiguration(variableDebtTokenImpl).UNDERLYING_ASSET_ADDRESS(),
|
asset == ITokenConfiguration(variableDebtTokenImpl).UNDERLYING_ASSET_ADDRESS(),
|
||||||
Errors.INVALID_VARIABLE_DEBT_TOKEN_UNDERLYING_ADDRESS
|
Errors.LPC_INVALID_VARIABLE_DEBT_TOKEN_UNDERLYING_ADDRESS
|
||||||
);
|
);
|
||||||
|
|
||||||
address aTokenProxyAddress = _initTokenWithProxy(aTokenImpl, underlyingAssetDecimals);
|
address aTokenProxyAddress = _initTokenWithProxy(aTokenImpl, underlyingAssetDecimals);
|
||||||
|
@ -449,7 +449,7 @@ contract LendingPoolConfigurator is VersionedInitializable {
|
||||||
|
|
||||||
require(
|
require(
|
||||||
availableLiquidity == 0 && reserveData.currentLiquidityRate == 0,
|
availableLiquidity == 0 && reserveData.currentLiquidityRate == 0,
|
||||||
Errors.RESERVE_LIQUIDITY_NOT_0
|
Errors.LPC_RESERVE_LIQUIDITY_NOT_0
|
||||||
);
|
);
|
||||||
|
|
||||||
ReserveConfiguration.Map memory currentConfig = pool.getConfiguration(asset);
|
ReserveConfiguration.Map memory currentConfig = pool.getConfiguration(asset);
|
||||||
|
|
|
@ -55,7 +55,7 @@ library ReserveConfiguration {
|
||||||
* @param ltv the new ltv
|
* @param ltv the new ltv
|
||||||
**/
|
**/
|
||||||
function setLtv(ReserveConfiguration.Map memory self, uint256 ltv) internal pure {
|
function setLtv(ReserveConfiguration.Map memory self, uint256 ltv) internal pure {
|
||||||
require(ltv <= MAX_VALID_LTV, Errors.INVALID_LTV);
|
require(ltv <= MAX_VALID_LTV, Errors.RC_INVALID_LTV);
|
||||||
|
|
||||||
self.data = (self.data & LTV_MASK) | ltv;
|
self.data = (self.data & LTV_MASK) | ltv;
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,7 @@ library ReserveConfiguration {
|
||||||
internal
|
internal
|
||||||
pure
|
pure
|
||||||
{
|
{
|
||||||
require(threshold <= MAX_VALID_LIQUIDATION_THRESHOLD, Errors.INVALID_LIQ_THRESHOLD);
|
require(threshold <= MAX_VALID_LIQUIDATION_THRESHOLD, Errors.RC_INVALID_LIQ_THRESHOLD);
|
||||||
|
|
||||||
self.data =
|
self.data =
|
||||||
(self.data & LIQUIDATION_THRESHOLD_MASK) |
|
(self.data & LIQUIDATION_THRESHOLD_MASK) |
|
||||||
|
@ -104,7 +104,7 @@ library ReserveConfiguration {
|
||||||
* @param bonus the new liquidation bonus
|
* @param bonus the new liquidation bonus
|
||||||
**/
|
**/
|
||||||
function setLiquidationBonus(ReserveConfiguration.Map memory self, uint256 bonus) internal pure {
|
function setLiquidationBonus(ReserveConfiguration.Map memory self, uint256 bonus) internal pure {
|
||||||
require(bonus <= MAX_VALID_LIQUIDATION_BONUS, Errors.INVALID_LIQ_BONUS);
|
require(bonus <= MAX_VALID_LIQUIDATION_BONUS, Errors.RC_INVALID_LIQ_BONUS);
|
||||||
|
|
||||||
self.data =
|
self.data =
|
||||||
(self.data & LIQUIDATION_BONUS_MASK) |
|
(self.data & LIQUIDATION_BONUS_MASK) |
|
||||||
|
@ -130,7 +130,7 @@ library ReserveConfiguration {
|
||||||
* @param decimals the decimals
|
* @param decimals the decimals
|
||||||
**/
|
**/
|
||||||
function setDecimals(ReserveConfiguration.Map memory self, uint256 decimals) internal pure {
|
function setDecimals(ReserveConfiguration.Map memory self, uint256 decimals) internal pure {
|
||||||
require(decimals <= MAX_VALID_DECIMALS, Errors.INVALID_DECIMALS);
|
require(decimals <= MAX_VALID_DECIMALS, Errors.RC_INVALID_DECIMALS);
|
||||||
|
|
||||||
self.data = (self.data & DECIMALS_MASK) | (decimals << RESERVE_DECIMALS_START_BIT_POSITION);
|
self.data = (self.data & DECIMALS_MASK) | (decimals << RESERVE_DECIMALS_START_BIT_POSITION);
|
||||||
}
|
}
|
||||||
|
@ -240,7 +240,7 @@ library ReserveConfiguration {
|
||||||
internal
|
internal
|
||||||
pure
|
pure
|
||||||
{
|
{
|
||||||
require(reserveFactor <= MAX_VALID_RESERVE_FACTOR, Errors.INVALID_RESERVE_FACTOR);
|
require(reserveFactor <= MAX_VALID_RESERVE_FACTOR, Errors.RC_INVALID_RESERVE_FACTOR);
|
||||||
|
|
||||||
self.data =
|
self.data =
|
||||||
(self.data & RESERVE_FACTOR_MASK) |
|
(self.data & RESERVE_FACTOR_MASK) |
|
||||||
|
|
|
@ -5,98 +5,92 @@ pragma solidity ^0.6.8;
|
||||||
* @title Errors library
|
* @title Errors library
|
||||||
* @author Aave
|
* @author Aave
|
||||||
* @notice Implements error messages.
|
* @notice Implements error messages.
|
||||||
|
* @dev Error messages prefix glossary:
|
||||||
|
* - VL = ValidationLogic
|
||||||
|
* - MATH = Math libraries
|
||||||
|
* - AT = aToken or DebtTokens
|
||||||
|
* - LP = LendingPool
|
||||||
|
* - LPAPR = LendingPoolAddressesProviderRegistry
|
||||||
|
* - LPC = LendingPoolConfiguration
|
||||||
|
* - RL = ReserveLogic
|
||||||
|
* - LPCM = LendingPoolCollateralManager
|
||||||
|
* - P = Pausable
|
||||||
*/
|
*/
|
||||||
library Errors {
|
library Errors {
|
||||||
// require error messages - ValidationLogic
|
string public constant VL_AMOUNT_NOT_GREATER_THAN_0 = '1'; // 'Amount must be greater than 0'
|
||||||
string public constant AMOUNT_NOT_GREATER_THAN_0 = '1'; // 'Amount must be greater than 0'
|
string public constant VL_NO_ACTIVE_RESERVE = '2'; // 'Action requires an active reserve'
|
||||||
string public constant NO_ACTIVE_RESERVE = '2'; // 'Action requires an active reserve'
|
string public constant VL_NO_UNFREEZED_RESERVE = '3'; // 'Action requires an unfreezed reserve'
|
||||||
string public constant NO_UNFREEZED_RESERVE = '3'; // 'Action requires an unfreezed reserve'
|
string public constant VL_CURRENT_AVAILABLE_LIQUIDITY_NOT_ENOUGH = '4'; // 'The current liquidity is not enough'
|
||||||
string public constant CURRENT_AVAILABLE_LIQUIDITY_NOT_ENOUGH = '4'; // 'The current liquidity is not enough'
|
string public constant VL_NOT_ENOUGH_AVAILABLE_USER_BALANCE = '5'; // 'User cannot withdraw more than the available balance'
|
||||||
string public constant NOT_ENOUGH_AVAILABLE_USER_BALANCE = '5'; // 'User cannot withdraw more than the available balance'
|
string public constant VL_TRANSFER_NOT_ALLOWED = '6'; // 'Transfer cannot be allowed.'
|
||||||
string public constant TRANSFER_NOT_ALLOWED = '6'; // 'Transfer cannot be allowed.'
|
string public constant VL_BORROWING_NOT_ENABLED = '7'; // 'Borrowing is not enabled'
|
||||||
string public constant BORROWING_NOT_ENABLED = '7'; // 'Borrowing is not enabled'
|
string public constant VL_INVALID_INTEREST_RATE_MODE_SELECTED = '8'; // 'Invalid interest rate mode selected'
|
||||||
string public constant INVALID_INTEREST_RATE_MODE_SELECTED = '8'; // 'Invalid interest rate mode selected'
|
string public constant VL_COLLATERAL_BALANCE_IS_0 = '9'; // 'The collateral balance is 0'
|
||||||
string public constant COLLATERAL_BALANCE_IS_0 = '9'; // 'The collateral balance is 0'
|
string public constant VL_HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD = '10'; // 'Health factor is lesser than the liquidation threshold'
|
||||||
string public constant HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD = '10'; // 'Health factor is lesser than the liquidation threshold'
|
string public constant VL_COLLATERAL_CANNOT_COVER_NEW_BORROW = '11'; // 'There is not enough collateral to cover a new borrow'
|
||||||
string public constant COLLATERAL_CANNOT_COVER_NEW_BORROW = '11'; // 'There is not enough collateral to cover a new borrow'
|
string public constant VL_STABLE_BORROWING_NOT_ENABLED = '12'; // stable borrowing not enabled
|
||||||
string public constant STABLE_BORROWING_NOT_ENABLED = '12'; // stable borrowing not enabled
|
string public constant VL_CALLATERAL_SAME_AS_BORROWING_CURRENCY = '13'; // collateral is (mostly) the same currency that is being borrowed
|
||||||
string public constant CALLATERAL_SAME_AS_BORROWING_CURRENCY = '13'; // collateral is (mostly) the same currency that is being borrowed
|
string public constant VL_AMOUNT_BIGGER_THAN_MAX_LOAN_SIZE_STABLE = '14'; // 'The requested amount is greater than the max loan size in stable rate mode
|
||||||
string public constant AMOUNT_BIGGER_THAN_MAX_LOAN_SIZE_STABLE = '14'; // 'The requested amount is greater than the max loan size in stable rate mode
|
string public constant VL_NO_DEBT_OF_SELECTED_TYPE = '15'; // 'for repayment of stable debt, the user needs to have stable debt, otherwise, he needs to have variable debt'
|
||||||
string public constant NO_DEBT_OF_SELECTED_TYPE = '15'; // 'for repayment of stable debt, the user needs to have stable debt, otherwise, he needs to have variable debt'
|
string public constant VL_NO_EXPLICIT_AMOUNT_TO_REPAY_ON_BEHALF = '16'; // 'To repay on behalf of an user an explicit amount to repay is needed'
|
||||||
string public constant NO_EXPLICIT_AMOUNT_TO_REPAY_ON_BEHALF = '16'; // 'To repay on behalf of an user an explicit amount to repay is needed'
|
string public constant VL_NO_STABLE_RATE_LOAN_IN_RESERVE = '17'; // 'User does not have a stable rate loan in progress on this reserve'
|
||||||
string public constant NO_STABLE_RATE_LOAN_IN_RESERVE = '17'; // 'User does not have a stable rate loan in progress on this reserve'
|
string public constant VL_NO_VARIABLE_RATE_LOAN_IN_RESERVE = '18'; // 'User does not have a variable rate loan in progress on this reserve'
|
||||||
string public constant NO_VARIABLE_RATE_LOAN_IN_RESERVE = '18'; // 'User does not have a variable rate loan in progress on this reserve'
|
string public constant VL_UNDERLYING_BALANCE_NOT_GREATER_THAN_0 = '19'; // 'The underlying balance needs to be greater than 0'
|
||||||
string public constant UNDERLYING_BALANCE_NOT_GREATER_THAN_0 = '19'; // 'The underlying balance needs to be greater than 0'
|
string public constant VL_DEPOSIT_ALREADY_IN_USE = '20'; // 'User deposit is already being used as collateral'
|
||||||
string public constant DEPOSIT_ALREADY_IN_USE = '20'; // 'User deposit is already being used as collateral'
|
string public constant LP_NOT_ENOUGH_STABLE_BORROW_BALANCE = '21'; // 'User does not have any stable rate loan for this reserve'
|
||||||
|
string public constant LP_INTEREST_RATE_REBALANCE_CONDITIONS_NOT_MET = '22'; // 'Interest rate rebalance conditions were not met'
|
||||||
// require error messages - LendingPool
|
string public constant LP_LIQUIDATION_CALL_FAILED = '23'; // 'Liquidation call failed'
|
||||||
string public constant NOT_ENOUGH_STABLE_BORROW_BALANCE = '21'; // 'User does not have any stable rate loan for this reserve'
|
string public constant LP_NOT_ENOUGH_LIQUIDITY_TO_BORROW = '24'; // 'There is not enough liquidity available to borrow'
|
||||||
string public constant INTEREST_RATE_REBALANCE_CONDITIONS_NOT_MET = '22'; // 'Interest rate rebalance conditions were not met'
|
string public constant LP_REQUESTED_AMOUNT_TOO_SMALL = '25'; // 'The requested amount is too small for a FlashLoan.'
|
||||||
string public constant LIQUIDATION_CALL_FAILED = '23'; // 'Liquidation call failed'
|
string public constant LP_INCONSISTENT_PROTOCOL_ACTUAL_BALANCE = '26'; // 'The actual balance of the protocol is inconsistent'
|
||||||
string public constant NOT_ENOUGH_LIQUIDITY_TO_BORROW = '24'; // 'There is not enough liquidity available to borrow'
|
string public constant LP_CALLER_NOT_LENDING_POOL_CONFIGURATOR = '27'; // 'The actual balance of the protocol is inconsistent'
|
||||||
string public constant REQUESTED_AMOUNT_TOO_SMALL = '25'; // 'The requested amount is too small for a FlashLoan.'
|
string public constant LP_INCONSISTENT_FLASHLOAN_PARAMS = '28';
|
||||||
string public constant INCONSISTENT_PROTOCOL_ACTUAL_BALANCE = '26'; // 'The actual balance of the protocol is inconsistent'
|
string public constant AT_CALLER_MUST_BE_LENDING_POOL = '29'; // 'The caller of this function must be a lending pool'
|
||||||
string public constant CALLER_NOT_LENDING_POOL_CONFIGURATOR = '27'; // 'The actual balance of the protocol is inconsistent'
|
string public constant AT_CANNOT_GIVE_ALLVWANCE_TO_HIMSELF = '30'; // 'User cannot give allowance to himself'
|
||||||
string public constant INVALID_FLASHLOAN_MODE = '43'; //Invalid flashloan mode selected
|
string public constant AT_TRANSFER_AMOUNT_NOT_GT_0 = '31'; // 'Transferred amount needs to be greater than zero'
|
||||||
string public constant BORROW_ALLOWANCE_ARE_NOT_ENOUGH = '54'; // User borrows on behalf, but allowance are too small
|
string public constant RL_RESERVE_ALREADY_INITIALIZED = '32'; // 'Reserve has already been initialized'
|
||||||
string public constant REENTRANCY_NOT_ALLOWED = '57';
|
string public constant LPC_CALLER_NOT_AAVE_ADMIN = '33'; // 'The caller must be the aave admin'
|
||||||
string public constant FAILED_REPAY_WITH_COLLATERAL = '53';
|
string public constant LPC_RESERVE_LIQUIDITY_NOT_0 = '34'; // 'The liquidity of the reserve needs to be 0'
|
||||||
string public constant FAILED_COLLATERAL_SWAP = '55';
|
string public constant LPC_INVALID_ATOKEN_POOL_ADDRESS = '35'; // 'The liquidity of the reserve needs to be 0'
|
||||||
string public constant INVALID_EQUAL_ASSETS_TO_SWAP = '56';
|
string public constant LPC_INVALID_STABLE_DEBT_TOKEN_POOL_ADDRESS = '36'; // 'The liquidity of the reserve needs to be 0'
|
||||||
string public constant NO_MORE_RESERVES_ALLOWED = '59';
|
string public constant LPC_INVALID_VARIABLE_DEBT_TOKEN_POOL_ADDRESS = '37'; // 'The liquidity of the reserve needs to be 0'
|
||||||
string public constant INVALID_FLASH_LOAN_EXECUTOR_RETURN = '60';
|
string public constant LPC_INVALID_STABLE_DEBT_TOKEN_UNDERLYING_ADDRESS = '38'; // 'The liquidity of the reserve needs to be 0'
|
||||||
string public constant INCONSISTENT_FLASHLOAN_PARAMS = '69';
|
string public constant LPC_INVALID_VARIABLE_DEBT_TOKEN_UNDERLYING_ADDRESS = '39'; // 'The liquidity of the reserve needs to be 0'
|
||||||
string public constant CALLER_MUST_BE_AN_ATOKEN = '76';
|
string public constant LPC_INVALID_ADDRESSES_PROVIDER_ID = '40'; // 'The liquidity of the reserve needs to be 0'
|
||||||
|
string public constant LPAPR_PROVIDER_NOT_REGISTERED = '41'; // 'Provider is not registered'
|
||||||
// require error messages - aToken - DebtTokens
|
string public constant LPCM_HEALTH_FACTOR_NOT_BELOW_THRESHOLD = '42'; // 'Health factor is not below the threshold'
|
||||||
string public constant CALLER_MUST_BE_LENDING_POOL = '28'; // 'The caller of this function must be a lending pool'
|
string public constant LPCM_COLLATERAL_CANNOT_BE_LIQUIDATED = '43'; // 'The collateral chosen cannot be liquidated'
|
||||||
string public constant CANNOT_GIVE_ALLOWANCE_TO_HIMSELF = '30'; // 'User cannot give allowance to himself'
|
string public constant LPCM_SPECIFIED_CURRENCY_NOT_BORROWED_BY_USER = '44'; // 'User did not borrow the specified currency'
|
||||||
string public constant TRANSFER_AMOUNT_NOT_GT_0 = '31'; // 'Transferred amount needs to be greater than zero'
|
string public constant LPCM_NOT_ENOUGH_LIQUIDITY_TO_LIQUIDATE = '45'; // "There isn't enough liquidity available to liquidate"
|
||||||
string public constant INVALID_MINT_AMOUNT = '61'; //invalid amount to mint
|
string public constant LPCM_NO_ERRORS = '46'; // 'No errors'
|
||||||
string public constant INVALID_BURN_AMOUNT = '62'; //invalid amount to burn
|
string public constant LP_INVALID_FLASHLOAN_MODE = '47'; //Invalid flashloan mode selected
|
||||||
|
string public constant MATH_MULTIPLICATION_OVERFLOW = '48';
|
||||||
// require error messages - ReserveLogic
|
string public constant MATH_ADDITION_OVERFLOW = '49';
|
||||||
string public constant RESERVE_ALREADY_INITIALIZED = '34'; // 'Reserve has already been initialized'
|
string public constant MATH_DIVISION_BY_ZERO = '50';
|
||||||
string public constant LIQUIDITY_INDEX_OVERFLOW = '47'; // Liquidity index overflows uint128
|
string public constant RL_LIQUIDITY_INDEX_OVERFLOW = '51'; // Liquidity index overflows uint128
|
||||||
string public constant VARIABLE_BORROW_INDEX_OVERFLOW = '48'; // Variable borrow index overflows uint128
|
string public constant RL_VARIABLE_BORROW_INDEX_OVERFLOW = '52'; // Variable borrow index overflows uint128
|
||||||
string public constant LIQUIDITY_RATE_OVERFLOW = '49'; // Liquidity rate overflows uint128
|
string public constant RL_LIQUIDITY_RATE_OVERFLOW = '53'; // Liquidity rate overflows uint128
|
||||||
string public constant VARIABLE_BORROW_RATE_OVERFLOW = '50'; // Variable borrow rate overflows uint128
|
string public constant RL_VARIABLE_BORROW_RATE_OVERFLOW = '54'; // Variable borrow rate overflows uint128
|
||||||
string public constant STABLE_BORROW_RATE_OVERFLOW = '51'; // Stable borrow rate overflows uint128
|
string public constant RL_STABLE_BORROW_RATE_OVERFLOW = '55'; // Stable borrow rate overflows uint128
|
||||||
|
string public constant AT_INVALID_MINT_AMOUNT = '56'; //invalid amount to mint
|
||||||
//require error messages - LendingPoolConfiguration
|
string public constant LP_FAILED_REPAY_WITH_COLLATERAL = '57';
|
||||||
string public constant CALLER_NOT_AAVE_ADMIN = '35'; // 'The caller must be the aave admin'
|
string public constant AT_INVALID_BURN_AMOUNT = '58'; //invalid amount to burn
|
||||||
string public constant RESERVE_LIQUIDITY_NOT_0 = '36'; // 'The liquidity of the reserve needs to be 0'
|
string public constant LP_BORROW_ALLOWANCE_ARE_NOT_ENOUGH = '59'; // User borrows on behalf, but allowance are too small
|
||||||
string public constant INVALID_ATOKEN_POOL_ADDRESS = '63'; // the lending pool in the aToken implementation is not configured correctly
|
string public constant LP_FAILED_COLLATERAL_SWAP = '60';
|
||||||
string public constant INVALID_STABLE_DEBT_TOKEN_POOL_ADDRESS = '64'; // the lending pool in the stable debt token implementation is not configured correctly
|
string public constant LP_INVALID_EQUAL_ASSETS_TO_SWAP = '61';
|
||||||
string public constant INVALID_VARIABLE_DEBT_TOKEN_POOL_ADDRESS = '65'; // the lending pool in the variable debt token implementation is not configured correctly
|
string public constant LP_REENTRANCY_NOT_ALLOWED = '62';
|
||||||
string public constant INVALID_STABLE_DEBT_TOKEN_UNDERLYING_ADDRESS = '66'; // the underlying asset in the stable debt token implementation is not configured correctly
|
string public constant LP_CALLER_MUST_BE_AN_ATOKEN = '63';
|
||||||
string public constant INVALID_VARIABLE_DEBT_TOKEN_UNDERLYING_ADDRESS = '67'; // the underlying asset in the variable debt token implementation is not configured correctly
|
string public constant P_IS_PAUSED = '64'; // 'Pool is paused'
|
||||||
|
string public constant LP_NO_MORE_RESERVES_ALLOWED = '65';
|
||||||
//require error messages - LendingPoolAddressesProviderRegistry
|
string public constant LP_INVALID_FLASH_LOAN_EXECUTOR_RETURN = '66';
|
||||||
string public constant PROVIDER_NOT_REGISTERED = '37'; // 'Provider is not registered'
|
string public constant RC_INVALID_LTV = '67';
|
||||||
string public constant INVALID_ADDRESSES_PROVIDER_ID = '68'; // the addresses provider id needs to be greater than 0
|
string public constant RC_INVALID_LIQ_THRESHOLD = '68';
|
||||||
|
string public constant RC_INVALID_LIQ_BONUS = '69';
|
||||||
//return error messages - LendingPoolCollateralManager
|
string public constant RC_INVALID_DECIMALS = '70';
|
||||||
string public constant HEALTH_FACTOR_NOT_BELOW_THRESHOLD = '38'; // 'Health factor is not below the threshold'
|
string public constant RC_INVALID_RESERVE_FACTOR = '71';
|
||||||
string public constant COLLATERAL_CANNOT_BE_LIQUIDATED = '39'; // 'The collateral chosen cannot be liquidated'
|
string public constant LPAPR_INVALID_ADDRESSES_PROVIDER_ID = '72';
|
||||||
string public constant SPECIFIED_CURRENCY_NOT_BORROWED_BY_USER = '40'; // 'User did not borrow the specified currency'
|
string public constant VL_INCONSISTENT_FLASHLOAN_PARAMS = '73';
|
||||||
string public constant NOT_ENOUGH_LIQUIDITY_TO_LIQUIDATE = '41'; // "There isn't enough liquidity available to liquidate"
|
string public constant LP_INCONSISTENT_PARAMS_LENGTH = '74';
|
||||||
string public constant NO_ERRORS = '42'; // 'No errors'
|
|
||||||
|
|
||||||
//require error messages - Math libraries
|
|
||||||
string public constant MULTIPLICATION_OVERFLOW = '44';
|
|
||||||
string public constant ADDITION_OVERFLOW = '45';
|
|
||||||
string public constant DIVISION_BY_ZERO = '46';
|
|
||||||
|
|
||||||
// pausable error message
|
|
||||||
string public constant IS_PAUSED = '58'; // 'Pool is paused'
|
|
||||||
|
|
||||||
// Reserve configuration
|
|
||||||
string public constant INVALID_LTV = '70';
|
|
||||||
string public constant INVALID_LIQ_THRESHOLD = '71';
|
|
||||||
string public constant INVALID_LIQ_BONUS = '72';
|
|
||||||
string public constant INVALID_DECIMALS = '73';
|
|
||||||
string public constant INVALID_RESERVE_FACTOR = '74';
|
|
||||||
|
|
||||||
enum CollateralManagerErrors {
|
enum CollateralManagerErrors {
|
||||||
NO_ERROR,
|
NO_ERROR,
|
||||||
|
|
|
@ -133,7 +133,7 @@ library ReserveLogic {
|
||||||
require(
|
require(
|
||||||
ReserveLogic.InterestRateMode.STABLE == ReserveLogic.InterestRateMode(interestRateMode) ||
|
ReserveLogic.InterestRateMode.STABLE == ReserveLogic.InterestRateMode(interestRateMode) ||
|
||||||
ReserveLogic.InterestRateMode.VARIABLE == ReserveLogic.InterestRateMode(interestRateMode),
|
ReserveLogic.InterestRateMode.VARIABLE == ReserveLogic.InterestRateMode(interestRateMode),
|
||||||
Errors.INVALID_INTEREST_RATE_MODE_SELECTED
|
Errors.VL_INVALID_INTEREST_RATE_MODE_SELECTED
|
||||||
);
|
);
|
||||||
return
|
return
|
||||||
ReserveLogic.InterestRateMode.STABLE == ReserveLogic.InterestRateMode(interestRateMode)
|
ReserveLogic.InterestRateMode.STABLE == ReserveLogic.InterestRateMode(interestRateMode)
|
||||||
|
@ -188,7 +188,7 @@ library ReserveLogic {
|
||||||
uint256 result = amountToLiquidityRatio.add(WadRayMath.ray());
|
uint256 result = amountToLiquidityRatio.add(WadRayMath.ray());
|
||||||
|
|
||||||
result = result.rayMul(reserve.liquidityIndex);
|
result = result.rayMul(reserve.liquidityIndex);
|
||||||
require(result < (1 << 128), Errors.LIQUIDITY_INDEX_OVERFLOW);
|
require(result < (1 << 128), Errors.RL_LIQUIDITY_INDEX_OVERFLOW);
|
||||||
|
|
||||||
reserve.liquidityIndex = uint128(result);
|
reserve.liquidityIndex = uint128(result);
|
||||||
}
|
}
|
||||||
|
@ -206,7 +206,7 @@ library ReserveLogic {
|
||||||
address variableDebtTokenAddress,
|
address variableDebtTokenAddress,
|
||||||
address interestRateStrategyAddress
|
address interestRateStrategyAddress
|
||||||
) external {
|
) external {
|
||||||
require(reserve.aTokenAddress == address(0), Errors.RESERVE_ALREADY_INITIALIZED);
|
require(reserve.aTokenAddress == address(0), Errors.RL_RESERVE_ALREADY_INITIALIZED);
|
||||||
if (reserve.liquidityIndex == 0) {
|
if (reserve.liquidityIndex == 0) {
|
||||||
//if the reserve has not been initialized yet
|
//if the reserve has not been initialized yet
|
||||||
reserve.liquidityIndex = uint128(WadRayMath.ray());
|
reserve.liquidityIndex = uint128(WadRayMath.ray());
|
||||||
|
@ -395,7 +395,7 @@ library ReserveLogic {
|
||||||
timestamp
|
timestamp
|
||||||
);
|
);
|
||||||
newLiquidityIndex = cumulatedLiquidityInterest.rayMul(liquidityIndex);
|
newLiquidityIndex = cumulatedLiquidityInterest.rayMul(liquidityIndex);
|
||||||
require(newLiquidityIndex < (1 << 128), Errors.LIQUIDITY_INDEX_OVERFLOW);
|
require(newLiquidityIndex < (1 << 128), Errors.RL_LIQUIDITY_INDEX_OVERFLOW);
|
||||||
|
|
||||||
reserve.liquidityIndex = uint128(newLiquidityIndex);
|
reserve.liquidityIndex = uint128(newLiquidityIndex);
|
||||||
|
|
||||||
|
@ -407,7 +407,7 @@ library ReserveLogic {
|
||||||
timestamp
|
timestamp
|
||||||
);
|
);
|
||||||
newVariableBorrowIndex = cumulatedVariableBorrowInterest.rayMul(variableBorrowIndex);
|
newVariableBorrowIndex = cumulatedVariableBorrowInterest.rayMul(variableBorrowIndex);
|
||||||
require(newVariableBorrowIndex < (1 << 128), Errors.VARIABLE_BORROW_INDEX_OVERFLOW);
|
require(newVariableBorrowIndex < (1 << 128), Errors.RL_VARIABLE_BORROW_INDEX_OVERFLOW);
|
||||||
reserve.variableBorrowIndex = uint128(newVariableBorrowIndex);
|
reserve.variableBorrowIndex = uint128(newVariableBorrowIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,12 +33,12 @@ library ValidationLogic {
|
||||||
* @param reserve the reserve state on which the user is depositing
|
* @param reserve the reserve state on which the user is depositing
|
||||||
* @param amount the amount to be deposited
|
* @param amount the amount to be deposited
|
||||||
*/
|
*/
|
||||||
function validateDeposit(ReserveLogic.ReserveData storage reserve, uint256 amount) internal view {
|
function validateDeposit(ReserveLogic.ReserveData storage reserve, uint256 amount) external view {
|
||||||
(bool isActive, bool isFreezed, , ) = reserve.configuration.getFlags();
|
(bool isActive, bool isFreezed, , ) = reserve.configuration.getFlags();
|
||||||
|
|
||||||
require(amount > 0, Errors.AMOUNT_NOT_GREATER_THAN_0);
|
require(amount > 0, Errors.VL_AMOUNT_NOT_GREATER_THAN_0);
|
||||||
require(isActive, Errors.NO_ACTIVE_RESERVE);
|
require(isActive, Errors.VL_NO_ACTIVE_RESERVE);
|
||||||
require(!isFreezed, Errors.NO_UNFREEZED_RESERVE);
|
require(!isFreezed, Errors.VL_NO_UNFREEZED_RESERVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -61,10 +61,10 @@ library ValidationLogic {
|
||||||
mapping(uint256 => address) storage reserves,
|
mapping(uint256 => address) storage reserves,
|
||||||
uint256 reservesCount,
|
uint256 reservesCount,
|
||||||
address oracle
|
address oracle
|
||||||
) internal view {
|
) external view {
|
||||||
require(amount > 0, Errors.AMOUNT_NOT_GREATER_THAN_0);
|
require(amount > 0, Errors.VL_AMOUNT_NOT_GREATER_THAN_0);
|
||||||
|
|
||||||
require(amount <= userBalance, Errors.NOT_ENOUGH_AVAILABLE_USER_BALANCE);
|
require(amount <= userBalance, Errors.VL_NOT_ENOUGH_AVAILABLE_USER_BALANCE);
|
||||||
|
|
||||||
require(
|
require(
|
||||||
GenericLogic.balanceDecreaseAllowed(
|
GenericLogic.balanceDecreaseAllowed(
|
||||||
|
@ -77,7 +77,7 @@ library ValidationLogic {
|
||||||
reservesCount,
|
reservesCount,
|
||||||
oracle
|
oracle
|
||||||
),
|
),
|
||||||
Errors.TRANSFER_NOT_ALLOWED
|
Errors.VL_TRANSFER_NOT_ALLOWED
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,16 +140,16 @@ library ValidationLogic {
|
||||||
vars.stableRateBorrowingEnabled
|
vars.stableRateBorrowingEnabled
|
||||||
) = reserve.configuration.getFlags();
|
) = reserve.configuration.getFlags();
|
||||||
|
|
||||||
require(vars.isActive, Errors.NO_ACTIVE_RESERVE);
|
require(vars.isActive, Errors.VL_NO_ACTIVE_RESERVE);
|
||||||
require(!vars.isFreezed, Errors.NO_UNFREEZED_RESERVE);
|
require(!vars.isFreezed, Errors.VL_NO_UNFREEZED_RESERVE);
|
||||||
|
|
||||||
require(vars.borrowingEnabled, Errors.BORROWING_NOT_ENABLED);
|
require(vars.borrowingEnabled, Errors.VL_BORROWING_NOT_ENABLED);
|
||||||
|
|
||||||
//validate interest rate mode
|
//validate interest rate mode
|
||||||
require(
|
require(
|
||||||
uint256(ReserveLogic.InterestRateMode.VARIABLE) == interestRateMode ||
|
uint256(ReserveLogic.InterestRateMode.VARIABLE) == interestRateMode ||
|
||||||
uint256(ReserveLogic.InterestRateMode.STABLE) == interestRateMode,
|
uint256(ReserveLogic.InterestRateMode.STABLE) == interestRateMode,
|
||||||
Errors.INVALID_INTEREST_RATE_MODE_SELECTED
|
Errors.VL_INVALID_INTEREST_RATE_MODE_SELECTED
|
||||||
);
|
);
|
||||||
|
|
||||||
(
|
(
|
||||||
|
@ -167,11 +167,11 @@ library ValidationLogic {
|
||||||
oracle
|
oracle
|
||||||
);
|
);
|
||||||
|
|
||||||
require(vars.userCollateralBalanceETH > 0, Errors.COLLATERAL_BALANCE_IS_0);
|
require(vars.userCollateralBalanceETH > 0, Errors.VL_COLLATERAL_BALANCE_IS_0);
|
||||||
|
|
||||||
require(
|
require(
|
||||||
vars.healthFactor > GenericLogic.HEALTH_FACTOR_LIQUIDATION_THRESHOLD,
|
vars.healthFactor > GenericLogic.HEALTH_FACTOR_LIQUIDATION_THRESHOLD,
|
||||||
Errors.HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD
|
Errors.VL_HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD
|
||||||
);
|
);
|
||||||
|
|
||||||
//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.
|
||||||
|
@ -181,7 +181,7 @@ library ValidationLogic {
|
||||||
|
|
||||||
require(
|
require(
|
||||||
vars.amountOfCollateralNeededETH <= vars.userCollateralBalanceETH,
|
vars.amountOfCollateralNeededETH <= vars.userCollateralBalanceETH,
|
||||||
Errors.COLLATERAL_CANNOT_COVER_NEW_BORROW
|
Errors.VL_COLLATERAL_CANNOT_COVER_NEW_BORROW
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -196,13 +196,13 @@ library ValidationLogic {
|
||||||
if (vars.rateMode == ReserveLogic.InterestRateMode.STABLE) {
|
if (vars.rateMode == ReserveLogic.InterestRateMode.STABLE) {
|
||||||
//check if the borrow mode is stable and if stable rate borrowing is enabled on this reserve
|
//check if the borrow mode is stable and if stable rate borrowing is enabled on this reserve
|
||||||
|
|
||||||
require(vars.stableRateBorrowingEnabled, Errors.STABLE_BORROWING_NOT_ENABLED);
|
require(vars.stableRateBorrowingEnabled, Errors.VL_STABLE_BORROWING_NOT_ENABLED);
|
||||||
|
|
||||||
require(
|
require(
|
||||||
!userConfig.isUsingAsCollateral(reserve.id) ||
|
!userConfig.isUsingAsCollateral(reserve.id) ||
|
||||||
reserve.configuration.getLtv() == 0 ||
|
reserve.configuration.getLtv() == 0 ||
|
||||||
amount > IERC20(reserve.aTokenAddress).balanceOf(userAddress),
|
amount > IERC20(reserve.aTokenAddress).balanceOf(userAddress),
|
||||||
Errors.CALLATERAL_SAME_AS_BORROWING_CURRENCY
|
Errors.VL_CALLATERAL_SAME_AS_BORROWING_CURRENCY
|
||||||
);
|
);
|
||||||
|
|
||||||
vars.availableLiquidity = IERC20(asset).balanceOf(reserve.aTokenAddress);
|
vars.availableLiquidity = IERC20(asset).balanceOf(reserve.aTokenAddress);
|
||||||
|
@ -211,7 +211,7 @@ library ValidationLogic {
|
||||||
//available liquidity
|
//available liquidity
|
||||||
uint256 maxLoanSizeStable = vars.availableLiquidity.percentMul(maxStableLoanPercent);
|
uint256 maxLoanSizeStable = vars.availableLiquidity.percentMul(maxStableLoanPercent);
|
||||||
|
|
||||||
require(amount <= maxLoanSizeStable, Errors.AMOUNT_BIGGER_THAN_MAX_LOAN_SIZE_STABLE);
|
require(amount <= maxLoanSizeStable, Errors.VL_AMOUNT_BIGGER_THAN_MAX_LOAN_SIZE_STABLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,21 +233,21 @@ library ValidationLogic {
|
||||||
) external view {
|
) external view {
|
||||||
bool isActive = reserve.configuration.getActive();
|
bool isActive = reserve.configuration.getActive();
|
||||||
|
|
||||||
require(isActive, Errors.NO_ACTIVE_RESERVE);
|
require(isActive, Errors.VL_NO_ACTIVE_RESERVE);
|
||||||
|
|
||||||
require(amountSent > 0, Errors.AMOUNT_NOT_GREATER_THAN_0);
|
require(amountSent > 0, Errors.VL_AMOUNT_NOT_GREATER_THAN_0);
|
||||||
|
|
||||||
require(
|
require(
|
||||||
(stableDebt > 0 &&
|
(stableDebt > 0 &&
|
||||||
ReserveLogic.InterestRateMode(rateMode) == ReserveLogic.InterestRateMode.STABLE) ||
|
ReserveLogic.InterestRateMode(rateMode) == ReserveLogic.InterestRateMode.STABLE) ||
|
||||||
(variableDebt > 0 &&
|
(variableDebt > 0 &&
|
||||||
ReserveLogic.InterestRateMode(rateMode) == ReserveLogic.InterestRateMode.VARIABLE),
|
ReserveLogic.InterestRateMode(rateMode) == ReserveLogic.InterestRateMode.VARIABLE),
|
||||||
Errors.NO_DEBT_OF_SELECTED_TYPE
|
Errors.VL_NO_DEBT_OF_SELECTED_TYPE
|
||||||
);
|
);
|
||||||
|
|
||||||
require(
|
require(
|
||||||
amountSent != uint256(-1) || msg.sender == onBehalfOf,
|
amountSent != uint256(-1) || msg.sender == onBehalfOf,
|
||||||
Errors.NO_EXPLICIT_AMOUNT_TO_REPAY_ON_BEHALF
|
Errors.VL_NO_EXPLICIT_AMOUNT_TO_REPAY_ON_BEHALF
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,13 +268,13 @@ library ValidationLogic {
|
||||||
) external view {
|
) external view {
|
||||||
(bool isActive, bool isFreezed, , bool stableRateEnabled) = reserve.configuration.getFlags();
|
(bool isActive, bool isFreezed, , bool stableRateEnabled) = reserve.configuration.getFlags();
|
||||||
|
|
||||||
require(isActive, Errors.NO_ACTIVE_RESERVE);
|
require(isActive, Errors.VL_NO_ACTIVE_RESERVE);
|
||||||
require(!isFreezed, Errors.NO_UNFREEZED_RESERVE);
|
require(!isFreezed, Errors.VL_NO_UNFREEZED_RESERVE);
|
||||||
|
|
||||||
if (currentRateMode == ReserveLogic.InterestRateMode.STABLE) {
|
if (currentRateMode == ReserveLogic.InterestRateMode.STABLE) {
|
||||||
require(stableDebt > 0, Errors.NO_STABLE_RATE_LOAN_IN_RESERVE);
|
require(stableDebt > 0, Errors.VL_NO_STABLE_RATE_LOAN_IN_RESERVE);
|
||||||
} else if (currentRateMode == ReserveLogic.InterestRateMode.VARIABLE) {
|
} else if (currentRateMode == ReserveLogic.InterestRateMode.VARIABLE) {
|
||||||
require(variableDebt > 0, Errors.NO_VARIABLE_RATE_LOAN_IN_RESERVE);
|
require(variableDebt > 0, Errors.VL_NO_VARIABLE_RATE_LOAN_IN_RESERVE);
|
||||||
/**
|
/**
|
||||||
* user wants to swap to stable, before swapping we need to ensure that
|
* user wants to swap to stable, before swapping we need to ensure that
|
||||||
* 1. stable borrow rate is enabled on the reserve
|
* 1. stable borrow rate is enabled on the reserve
|
||||||
|
@ -282,16 +282,16 @@ library ValidationLogic {
|
||||||
* more collateral than he is borrowing, artificially lowering
|
* more collateral than he is borrowing, artificially lowering
|
||||||
* the interest rate, borrowing at variable, and switching to stable
|
* the interest rate, borrowing at variable, and switching to stable
|
||||||
**/
|
**/
|
||||||
require(stableRateEnabled, Errors.STABLE_BORROWING_NOT_ENABLED);
|
require(stableRateEnabled, Errors.VL_STABLE_BORROWING_NOT_ENABLED);
|
||||||
|
|
||||||
require(
|
require(
|
||||||
!userConfig.isUsingAsCollateral(reserve.id) ||
|
!userConfig.isUsingAsCollateral(reserve.id) ||
|
||||||
reserve.configuration.getLtv() == 0 ||
|
reserve.configuration.getLtv() == 0 ||
|
||||||
stableDebt.add(variableDebt) > IERC20(reserve.aTokenAddress).balanceOf(msg.sender),
|
stableDebt.add(variableDebt) > IERC20(reserve.aTokenAddress).balanceOf(msg.sender),
|
||||||
Errors.CALLATERAL_SAME_AS_BORROWING_CURRENCY
|
Errors.VL_CALLATERAL_SAME_AS_BORROWING_CURRENCY
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
revert(Errors.INVALID_INTEREST_RATE_MODE_SELECTED);
|
revert(Errors.VL_INVALID_INTEREST_RATE_MODE_SELECTED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -315,7 +315,7 @@ library ValidationLogic {
|
||||||
) external view {
|
) external view {
|
||||||
uint256 underlyingBalance = IERC20(reserve.aTokenAddress).balanceOf(msg.sender);
|
uint256 underlyingBalance = IERC20(reserve.aTokenAddress).balanceOf(msg.sender);
|
||||||
|
|
||||||
require(underlyingBalance > 0, Errors.UNDERLYING_BALANCE_NOT_GREATER_THAN_0);
|
require(underlyingBalance > 0, Errors.VL_UNDERLYING_BALANCE_NOT_GREATER_THAN_0);
|
||||||
|
|
||||||
require(
|
require(
|
||||||
GenericLogic.balanceDecreaseAllowed(
|
GenericLogic.balanceDecreaseAllowed(
|
||||||
|
@ -328,7 +328,7 @@ library ValidationLogic {
|
||||||
reservesCount,
|
reservesCount,
|
||||||
oracle
|
oracle
|
||||||
),
|
),
|
||||||
Errors.DEPOSIT_ALREADY_IN_USE
|
Errors.VL_DEPOSIT_ALREADY_IN_USE
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -338,7 +338,7 @@ library ValidationLogic {
|
||||||
* @param amounts the amounts for each asset being borrowed
|
* @param amounts the amounts for each asset being borrowed
|
||||||
**/
|
**/
|
||||||
function validateFlashloan(address[] memory assets, uint256[] memory amounts) internal pure {
|
function validateFlashloan(address[] memory assets, uint256[] memory amounts) internal pure {
|
||||||
require(assets.length == amounts.length, Errors.INCONSISTENT_FLASHLOAN_PARAMS);
|
require(assets.length == amounts.length, Errors.VL_INCONSISTENT_FLASHLOAN_PARAMS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -361,13 +361,16 @@ library ValidationLogic {
|
||||||
if (
|
if (
|
||||||
!collateralReserve.configuration.getActive() || !principalReserve.configuration.getActive()
|
!collateralReserve.configuration.getActive() || !principalReserve.configuration.getActive()
|
||||||
) {
|
) {
|
||||||
return (uint256(Errors.CollateralManagerErrors.NO_ACTIVE_RESERVE), Errors.NO_ACTIVE_RESERVE);
|
return (
|
||||||
|
uint256(Errors.CollateralManagerErrors.NO_ACTIVE_RESERVE),
|
||||||
|
Errors.VL_NO_ACTIVE_RESERVE
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (userHealthFactor >= GenericLogic.HEALTH_FACTOR_LIQUIDATION_THRESHOLD) {
|
if (userHealthFactor >= GenericLogic.HEALTH_FACTOR_LIQUIDATION_THRESHOLD) {
|
||||||
return (
|
return (
|
||||||
uint256(Errors.CollateralManagerErrors.HEALTH_FACTOR_ABOVE_THRESHOLD),
|
uint256(Errors.CollateralManagerErrors.HEALTH_FACTOR_ABOVE_THRESHOLD),
|
||||||
Errors.HEALTH_FACTOR_NOT_BELOW_THRESHOLD
|
Errors.LPCM_HEALTH_FACTOR_NOT_BELOW_THRESHOLD
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -378,18 +381,18 @@ library ValidationLogic {
|
||||||
if (!isCollateralEnabled) {
|
if (!isCollateralEnabled) {
|
||||||
return (
|
return (
|
||||||
uint256(Errors.CollateralManagerErrors.COLLATERAL_CANNOT_BE_LIQUIDATED),
|
uint256(Errors.CollateralManagerErrors.COLLATERAL_CANNOT_BE_LIQUIDATED),
|
||||||
Errors.COLLATERAL_CANNOT_BE_LIQUIDATED
|
Errors.LPCM_COLLATERAL_CANNOT_BE_LIQUIDATED
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (userStableDebt == 0 && userVariableDebt == 0) {
|
if (userStableDebt == 0 && userVariableDebt == 0) {
|
||||||
return (
|
return (
|
||||||
uint256(Errors.CollateralManagerErrors.CURRRENCY_NOT_BORROWED),
|
uint256(Errors.CollateralManagerErrors.CURRRENCY_NOT_BORROWED),
|
||||||
Errors.SPECIFIED_CURRENCY_NOT_BORROWED_BY_USER
|
Errors.LPCM_SPECIFIED_CURRENCY_NOT_BORROWED_BY_USER
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (uint256(Errors.CollateralManagerErrors.NO_ERROR), Errors.NO_ERRORS);
|
return (uint256(Errors.CollateralManagerErrors.NO_ERROR), Errors.LPCM_NO_ERRORS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -419,7 +422,7 @@ library ValidationLogic {
|
||||||
|
|
||||||
require(
|
require(
|
||||||
healthFactor >= GenericLogic.HEALTH_FACTOR_LIQUIDATION_THRESHOLD,
|
healthFactor >= GenericLogic.HEALTH_FACTOR_LIQUIDATION_THRESHOLD,
|
||||||
Errors.TRANSFER_NOT_ALLOWED
|
Errors.VL_TRANSFER_NOT_ALLOWED
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ library PercentageMath {
|
||||||
|
|
||||||
require(
|
require(
|
||||||
value <= (type(uint256).max - HALF_PERCENT) / percentage,
|
value <= (type(uint256).max - HALF_PERCENT) / percentage,
|
||||||
Errors.MULTIPLICATION_OVERFLOW
|
Errors.MATH_MULTIPLICATION_OVERFLOW
|
||||||
);
|
);
|
||||||
|
|
||||||
return (value * percentage + HALF_PERCENT) / PERCENTAGE_FACTOR;
|
return (value * percentage + HALF_PERCENT) / PERCENTAGE_FACTOR;
|
||||||
|
@ -41,12 +41,12 @@ library PercentageMath {
|
||||||
* @return the value divided the percentage
|
* @return the value divided the percentage
|
||||||
**/
|
**/
|
||||||
function percentDiv(uint256 value, uint256 percentage) internal pure returns (uint256) {
|
function percentDiv(uint256 value, uint256 percentage) internal pure returns (uint256) {
|
||||||
require(percentage != 0, Errors.DIVISION_BY_ZERO);
|
require(percentage != 0, Errors.MATH_DIVISION_BY_ZERO);
|
||||||
uint256 halfPercentage = percentage / 2;
|
uint256 halfPercentage = percentage / 2;
|
||||||
|
|
||||||
require(
|
require(
|
||||||
value <= (type(uint256).max - halfPercentage) / PERCENTAGE_FACTOR,
|
value <= (type(uint256).max - halfPercentage) / PERCENTAGE_FACTOR,
|
||||||
Errors.MULTIPLICATION_OVERFLOW
|
Errors.MATH_MULTIPLICATION_OVERFLOW
|
||||||
);
|
);
|
||||||
|
|
||||||
return (value * PERCENTAGE_FACTOR + halfPercentage) / percentage;
|
return (value * PERCENTAGE_FACTOR + halfPercentage) / percentage;
|
||||||
|
|
|
@ -58,7 +58,7 @@ library WadRayMath {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
require(a <= (type(uint256).max - halfWAD) / b, Errors.MULTIPLICATION_OVERFLOW);
|
require(a <= (type(uint256).max - halfWAD) / b, Errors.MATH_MULTIPLICATION_OVERFLOW);
|
||||||
|
|
||||||
return (a * b + halfWAD) / WAD;
|
return (a * b + halfWAD) / WAD;
|
||||||
}
|
}
|
||||||
|
@ -70,10 +70,10 @@ library WadRayMath {
|
||||||
* @return the result of a/b, in wad
|
* @return the result of a/b, in wad
|
||||||
**/
|
**/
|
||||||
function wadDiv(uint256 a, uint256 b) internal pure returns (uint256) {
|
function wadDiv(uint256 a, uint256 b) internal pure returns (uint256) {
|
||||||
require(b != 0, Errors.DIVISION_BY_ZERO);
|
require(b != 0, Errors.MATH_DIVISION_BY_ZERO);
|
||||||
uint256 halfB = b / 2;
|
uint256 halfB = b / 2;
|
||||||
|
|
||||||
require(a <= (type(uint256).max - halfB) / WAD, Errors.MULTIPLICATION_OVERFLOW);
|
require(a <= (type(uint256).max - halfB) / WAD, Errors.MATH_MULTIPLICATION_OVERFLOW);
|
||||||
|
|
||||||
return (a * WAD + halfB) / b;
|
return (a * WAD + halfB) / b;
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ library WadRayMath {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
require(a <= (type(uint256).max - halfRAY) / b, Errors.MULTIPLICATION_OVERFLOW);
|
require(a <= (type(uint256).max - halfRAY) / b, Errors.MATH_MULTIPLICATION_OVERFLOW);
|
||||||
|
|
||||||
return (a * b + halfRAY) / RAY;
|
return (a * b + halfRAY) / RAY;
|
||||||
}
|
}
|
||||||
|
@ -101,10 +101,10 @@ library WadRayMath {
|
||||||
* @return the result of a/b, in ray
|
* @return the result of a/b, in ray
|
||||||
**/
|
**/
|
||||||
function rayDiv(uint256 a, uint256 b) internal pure returns (uint256) {
|
function rayDiv(uint256 a, uint256 b) internal pure returns (uint256) {
|
||||||
require(b != 0, Errors.DIVISION_BY_ZERO);
|
require(b != 0, Errors.MATH_DIVISION_BY_ZERO);
|
||||||
uint256 halfB = b / 2;
|
uint256 halfB = b / 2;
|
||||||
|
|
||||||
require(a <= (type(uint256).max - halfB) / RAY, Errors.MULTIPLICATION_OVERFLOW);
|
require(a <= (type(uint256).max - halfB) / RAY, Errors.MATH_MULTIPLICATION_OVERFLOW);
|
||||||
|
|
||||||
return (a * RAY + halfB) / b;
|
return (a * RAY + halfB) / b;
|
||||||
}
|
}
|
||||||
|
@ -117,7 +117,7 @@ library WadRayMath {
|
||||||
function rayToWad(uint256 a) internal pure returns (uint256) {
|
function rayToWad(uint256 a) internal pure returns (uint256) {
|
||||||
uint256 halfRatio = WAD_RAY_RATIO / 2;
|
uint256 halfRatio = WAD_RAY_RATIO / 2;
|
||||||
uint256 result = halfRatio + a;
|
uint256 result = halfRatio + a;
|
||||||
require(result >= halfRatio, Errors.ADDITION_OVERFLOW);
|
require(result >= halfRatio, Errors.MATH_ADDITION_OVERFLOW);
|
||||||
|
|
||||||
return result / WAD_RAY_RATIO;
|
return result / WAD_RAY_RATIO;
|
||||||
}
|
}
|
||||||
|
@ -129,7 +129,7 @@ library WadRayMath {
|
||||||
**/
|
**/
|
||||||
function wadToRay(uint256 a) internal pure returns (uint256) {
|
function wadToRay(uint256 a) internal pure returns (uint256) {
|
||||||
uint256 result = a * WAD_RAY_RATIO;
|
uint256 result = a * WAD_RAY_RATIO;
|
||||||
require(result / WAD_RAY_RATIO == a, Errors.MULTIPLICATION_OVERFLOW);
|
require(result / WAD_RAY_RATIO == a, Errors.MATH_MULTIPLICATION_OVERFLOW);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ contract AToken is VersionedInitializable, IncentivizedERC20, IAToken {
|
||||||
bytes32 public DOMAIN_SEPARATOR;
|
bytes32 public DOMAIN_SEPARATOR;
|
||||||
|
|
||||||
modifier onlyLendingPool {
|
modifier onlyLendingPool {
|
||||||
require(_msgSender() == address(POOL), Errors.CALLER_MUST_BE_LENDING_POOL);
|
require(_msgSender() == address(POOL), Errors.AT_CALLER_MUST_BE_LENDING_POOL);
|
||||||
_;
|
_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ contract AToken is VersionedInitializable, IncentivizedERC20, IAToken {
|
||||||
uint256 index
|
uint256 index
|
||||||
) external override onlyLendingPool {
|
) external override onlyLendingPool {
|
||||||
uint256 amountScaled = amount.rayDiv(index);
|
uint256 amountScaled = amount.rayDiv(index);
|
||||||
require(amountScaled != 0, Errors.INVALID_BURN_AMOUNT);
|
require(amountScaled != 0, Errors.AT_INVALID_BURN_AMOUNT);
|
||||||
_burn(user, amountScaled);
|
_burn(user, amountScaled);
|
||||||
|
|
||||||
//transfers the underlying to the target
|
//transfers the underlying to the target
|
||||||
|
@ -127,7 +127,7 @@ contract AToken is VersionedInitializable, IncentivizedERC20, IAToken {
|
||||||
uint256 previousBalance = super.balanceOf(user);
|
uint256 previousBalance = super.balanceOf(user);
|
||||||
|
|
||||||
uint256 amountScaled = amount.rayDiv(index);
|
uint256 amountScaled = amount.rayDiv(index);
|
||||||
require(amountScaled != 0, Errors.INVALID_MINT_AMOUNT);
|
require(amountScaled != 0, Errors.AT_INVALID_MINT_AMOUNT);
|
||||||
_mint(user, amountScaled);
|
_mint(user, amountScaled);
|
||||||
|
|
||||||
//transfer event to track balances
|
//transfer event to track balances
|
||||||
|
|
|
@ -60,7 +60,7 @@ contract VariableDebtToken is DebtTokenBase, IVariableDebtToken {
|
||||||
) external override onlyLendingPool returns (bool) {
|
) external override onlyLendingPool returns (bool) {
|
||||||
uint256 previousBalance = super.balanceOf(user);
|
uint256 previousBalance = super.balanceOf(user);
|
||||||
uint256 amountScaled = amount.rayDiv(index);
|
uint256 amountScaled = amount.rayDiv(index);
|
||||||
require(amountScaled != 0, Errors.INVALID_MINT_AMOUNT);
|
require(amountScaled != 0, Errors.AT_INVALID_MINT_AMOUNT);
|
||||||
|
|
||||||
_mint(user, amountScaled);
|
_mint(user, amountScaled);
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ contract VariableDebtToken is DebtTokenBase, IVariableDebtToken {
|
||||||
uint256 index
|
uint256 index
|
||||||
) external override onlyLendingPool {
|
) external override onlyLendingPool {
|
||||||
uint256 amountScaled = amount.rayDiv(index);
|
uint256 amountScaled = amount.rayDiv(index);
|
||||||
require(amountScaled != 0, Errors.INVALID_BURN_AMOUNT);
|
require(amountScaled != 0, Errors.AT_INVALID_BURN_AMOUNT);
|
||||||
|
|
||||||
_burn(user, amountScaled);
|
_burn(user, amountScaled);
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ abstract contract DebtTokenBase is IncentivizedERC20, VersionedInitializable {
|
||||||
* @dev Only lending pool can call functions marked by this modifier
|
* @dev Only lending pool can call functions marked by this modifier
|
||||||
**/
|
**/
|
||||||
modifier onlyLendingPool {
|
modifier onlyLendingPool {
|
||||||
require(_msgSender() == address(POOL), Errors.CALLER_MUST_BE_LENDING_POOL);
|
require(_msgSender() == address(POOL), Errors.AT_CALLER_MUST_BE_LENDING_POOL);
|
||||||
_;
|
_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -198,7 +198,7 @@
|
||||||
},
|
},
|
||||||
"ATokensAndRatesHelper": {
|
"ATokensAndRatesHelper": {
|
||||||
"buidlerevm": {
|
"buidlerevm": {
|
||||||
"address": "0x06bA8d8af0dF898D0712DffFb0f862cC51AF45c2",
|
"address": "0x920d847fE49E54C19047ba8bc236C45A8068Bca7",
|
||||||
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
|
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -266,4 +266,4 @@
|
||||||
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
|
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -33,7 +33,10 @@ import {
|
||||||
LendingRateOracleFactory,
|
LendingRateOracleFactory,
|
||||||
MintableErc20Factory,
|
MintableErc20Factory,
|
||||||
MockAggregatorFactory,
|
MockAggregatorFactory,
|
||||||
|
MockATokenFactory,
|
||||||
MockFlashLoanReceiverFactory,
|
MockFlashLoanReceiverFactory,
|
||||||
|
MockStableDebtTokenFactory,
|
||||||
|
MockVariableDebtTokenFactory,
|
||||||
MockUniswapV2Router02Factory,
|
MockUniswapV2Router02Factory,
|
||||||
PriceOracleFactory,
|
PriceOracleFactory,
|
||||||
ReserveLogicFactory,
|
ReserveLogicFactory,
|
||||||
|
@ -45,6 +48,8 @@ import {
|
||||||
} from '../types';
|
} from '../types';
|
||||||
import {withSaveAndVerify, registerContractInJsonDb, linkBytecode} from './contracts-helpers';
|
import {withSaveAndVerify, registerContractInJsonDb, linkBytecode} from './contracts-helpers';
|
||||||
import {StableAndVariableTokensHelperFactory} from '../types/StableAndVariableTokensHelperFactory';
|
import {StableAndVariableTokensHelperFactory} from '../types/StableAndVariableTokensHelperFactory';
|
||||||
|
import {MockStableDebtToken} from '../types/MockStableDebtToken';
|
||||||
|
import {MockVariableDebtToken} from '../types/MockVariableDebtToken';
|
||||||
|
|
||||||
export const deployLendingPoolAddressesProvider = async (verify?: boolean) =>
|
export const deployLendingPoolAddressesProvider = async (verify?: boolean) =>
|
||||||
withSaveAndVerify(
|
withSaveAndVerify(
|
||||||
|
@ -143,7 +148,6 @@ export const deployAaveLibraries = async (
|
||||||
return {
|
return {
|
||||||
['__$5201a97c05ba6aa659e2f36a933dd51801$__']: validationLogic.address,
|
['__$5201a97c05ba6aa659e2f36a933dd51801$__']: validationLogic.address,
|
||||||
['__$d3b4366daeb9cadc7528af6145b50b2183$__']: reserveLogic.address,
|
['__$d3b4366daeb9cadc7528af6145b50b2183$__']: reserveLogic.address,
|
||||||
['__$4c26be947d349222af871a3168b3fe584b$__']: genericLogic.address,
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -378,6 +382,39 @@ export const deployATokensAndRatesHelper = async (
|
||||||
verify
|
verify
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const deployMockStableDebtToken = async (
|
||||||
|
args: [tEthereumAddress, tEthereumAddress, string, string, tEthereumAddress],
|
||||||
|
verify?: boolean
|
||||||
|
) =>
|
||||||
|
withSaveAndVerify(
|
||||||
|
await new MockStableDebtTokenFactory(await getFirstSigner()).deploy(...args),
|
||||||
|
eContractid.ATokensAndRatesHelper,
|
||||||
|
args,
|
||||||
|
verify
|
||||||
|
);
|
||||||
|
|
||||||
|
export const deployMockVariableDebtToken = async (
|
||||||
|
args: [tEthereumAddress, tEthereumAddress, string, string, tEthereumAddress],
|
||||||
|
verify?: boolean
|
||||||
|
) =>
|
||||||
|
withSaveAndVerify(
|
||||||
|
await new MockVariableDebtTokenFactory(await getFirstSigner()).deploy(...args),
|
||||||
|
eContractid.ATokensAndRatesHelper,
|
||||||
|
args,
|
||||||
|
verify
|
||||||
|
);
|
||||||
|
|
||||||
|
export const deployMockAToken = async (
|
||||||
|
args: [tEthereumAddress, tEthereumAddress, tEthereumAddress, string, string, tEthereumAddress],
|
||||||
|
verify?: boolean
|
||||||
|
) =>
|
||||||
|
withSaveAndVerify(
|
||||||
|
await new MockATokenFactory(await getFirstSigner()).deploy(...args),
|
||||||
|
eContractid.ATokensAndRatesHelper,
|
||||||
|
args,
|
||||||
|
verify
|
||||||
|
);
|
||||||
|
|
||||||
export const deployMockUniswapRouter = async (verify?: boolean) =>
|
export const deployMockUniswapRouter = async (verify?: boolean) =>
|
||||||
withSaveAndVerify(
|
withSaveAndVerify(
|
||||||
await new MockUniswapV2Router02Factory(await getFirstSigner()).deploy(),
|
await new MockUniswapV2Router02Factory(await getFirstSigner()).deploy(),
|
||||||
|
|
|
@ -10,7 +10,10 @@ import {
|
||||||
LendingPoolFactory,
|
LendingPoolFactory,
|
||||||
LendingRateOracleFactory,
|
LendingRateOracleFactory,
|
||||||
MintableErc20Factory,
|
MintableErc20Factory,
|
||||||
|
MockATokenFactory,
|
||||||
MockFlashLoanReceiverFactory,
|
MockFlashLoanReceiverFactory,
|
||||||
|
MockStableDebtTokenFactory,
|
||||||
|
MockVariableDebtTokenFactory,
|
||||||
MockUniswapV2Router02Factory,
|
MockUniswapV2Router02Factory,
|
||||||
PriceOracleFactory,
|
PriceOracleFactory,
|
||||||
ReserveLogicFactory,
|
ReserveLogicFactory,
|
||||||
|
@ -226,6 +229,26 @@ export const getATokensAndRatesHelper = async (address?: tEthereumAddress) =>
|
||||||
await getFirstSigner()
|
await getFirstSigner()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const getMockAToken = async (address?: tEthereumAddress) =>
|
||||||
|
await MockATokenFactory.connect(
|
||||||
|
address || (await getDb().get(`${eContractid.MockAToken}.${BRE.network.name}`).value()).address,
|
||||||
|
await getFirstSigner()
|
||||||
|
);
|
||||||
|
|
||||||
|
export const getMockVariableDebtToken = async (address?: tEthereumAddress) =>
|
||||||
|
await MockVariableDebtTokenFactory.connect(
|
||||||
|
address ||
|
||||||
|
(await getDb().get(`${eContractid.MockVariableDebtToken}.${BRE.network.name}`).value())
|
||||||
|
.address,
|
||||||
|
await getFirstSigner()
|
||||||
|
);
|
||||||
|
export const getMockStableDebtToken = async (address?: tEthereumAddress) =>
|
||||||
|
await MockStableDebtTokenFactory.connect(
|
||||||
|
address ||
|
||||||
|
(await getDb().get(`${eContractid.MockStableDebtToken}.${BRE.network.name}`).value()).address,
|
||||||
|
await getFirstSigner()
|
||||||
|
);
|
||||||
|
|
||||||
export const getMockUniswapRouter = async (address?: tEthereumAddress) =>
|
export const getMockUniswapRouter = async (address?: tEthereumAddress) =>
|
||||||
await MockUniswapV2Router02Factory.connect(
|
await MockUniswapV2Router02Factory.connect(
|
||||||
address ||
|
address ||
|
||||||
|
|
149
helpers/types.ts
149
helpers/types.ts
|
@ -62,72 +62,91 @@ export enum eContractid {
|
||||||
UniswapRepayAdapter = 'UniswapRepayAdapter',
|
UniswapRepayAdapter = 'UniswapRepayAdapter',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Error messages prefix glossary:
|
||||||
|
* - VL = ValidationLogic
|
||||||
|
* - MATH = Math libraries
|
||||||
|
* - AT = aToken or DebtTokens
|
||||||
|
* - LP = LendingPool
|
||||||
|
* - LPAPR = LendingPoolAddressesProviderRegistry
|
||||||
|
* - LPC = LendingPoolConfiguration
|
||||||
|
* - RL = ReserveLogic
|
||||||
|
* - LPCM = LendingPoolCollateralManager
|
||||||
|
* - P = Pausable
|
||||||
|
*/
|
||||||
export enum ProtocolErrors {
|
export enum ProtocolErrors {
|
||||||
// require error messages - ValidationLogic
|
VL_AMOUNT_NOT_GREATER_THAN_0 = '1', // 'Amount must be greater than 0'
|
||||||
AMOUNT_NOT_GREATER_THAN_0 = '1', // 'Amount must be greater than 0'
|
VL_NO_ACTIVE_RESERVE = '2', // 'Action requires an active reserve'
|
||||||
NO_ACTIVE_RESERVE = '2', // 'Action requires an active reserve'
|
VL_NO_UNFREEZED_RESERVE = '3', // 'Action requires an unfreezed reserve'
|
||||||
NO_UNFREEZED_RESERVE = '3', // 'Action requires an unfreezed reserve'
|
VL_CURRENT_AVAILABLE_LIQUIDITY_NOT_ENOUGH = '4', // 'The current liquidity is not enough'
|
||||||
CURRENT_AVAILABLE_LIQUIDITY_NOT_ENOUGH = '4', // 'The current liquidity is not enough'
|
VL_NOT_ENOUGH_AVAILABLE_USER_BALANCE = '5', // 'User cannot withdraw more than the available balance'
|
||||||
NOT_ENOUGH_AVAILABLE_USER_BALANCE = '5', // 'User cannot withdraw more than the available balance'
|
VL_TRANSFER_NOT_ALLOWED = '6', // 'Transfer cannot be allowed.'
|
||||||
TRANSFER_NOT_ALLOWED = '6', // 'Transfer cannot be allowed.'
|
VL_BORROWING_NOT_ENABLED = '7', // 'Borrowing is not enabled'
|
||||||
BORROWING_NOT_ENABLED = '7', // 'Borrowing is not enabled'
|
VL_INVALID_INTEREST_RATE_MODE_SELECTED = '8', // 'Invalid interest rate mode selected'
|
||||||
INVALID_INTEREST_RATE_MODE_SELECTED = '8', // 'Invalid interest rate mode selected'
|
VL_COLLATERAL_BALANCE_IS_0 = '9', // 'The collateral balance is 0'
|
||||||
COLLATERAL_BALANCE_IS_0 = '9', // 'The collateral balance is 0'
|
VL_HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD = '10', // 'Health factor is lesser than the liquidation threshold'
|
||||||
HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD = '10', // 'Health factor is lesser than the liquidation threshold'
|
VL_COLLATERAL_CANNOT_COVER_NEW_BORROW = '11', // 'There is not enough collateral to cover a new borrow'
|
||||||
COLLATERAL_CANNOT_COVER_NEW_BORROW = '11', // 'There is not enough collateral to cover a new borrow'
|
VL_STABLE_BORROWING_NOT_ENABLED = '12', // stable borrowing not enabled
|
||||||
STABLE_BORROWING_NOT_ENABLED = '12', // stable borrowing not enabled
|
VL_CALLATERAL_SAME_AS_BORROWING_CURRENCY = '13', // collateral is (mostly) the same currency that is being borrowed
|
||||||
CALLATERAL_SAME_AS_BORROWING_CURRENCY = '13', // collateral is (mostly) the same currency that is being borrowed
|
VL_AMOUNT_BIGGER_THAN_MAX_LOAN_SIZE_STABLE = '14', // 'The requested amount is greater than the max loan size in stable rate mode
|
||||||
AMOUNT_BIGGER_THAN_MAX_LOAN_SIZE_STABLE = '14', // 'The requested amount is greater than the max loan size in stable rate mode
|
VL_NO_DEBT_OF_SELECTED_TYPE = '15', // 'for repayment of stable debt, the user needs to have stable debt, otherwise, he needs to have variable debt'
|
||||||
NO_DEBT_OF_SELECTED_TYPE = '15', // 'for repayment of stable debt, the user needs to have stable debt, otherwise, he needs to have variable debt'
|
VL_NO_EXPLICIT_AMOUNT_TO_REPAY_ON_BEHALF = '16', // 'To repay on behalf of an user an explicit amount to repay is needed'
|
||||||
NO_EXPLICIT_AMOUNT_TO_REPAY_ON_BEHALF = '16', // 'To repay on behalf of an user an explicit amount to repay is needed'
|
VL_NO_STABLE_RATE_LOAN_IN_RESERVE = '17', // 'User does not have a stable rate loan in progress on this reserve'
|
||||||
NO_STABLE_RATE_LOAN_IN_RESERVE = '17', // 'User does not have a stable rate loan in progress on this reserve'
|
VL_NO_VARIABLE_RATE_LOAN_IN_RESERVE = '18', // 'User does not have a variable rate loan in progress on this reserve'
|
||||||
NO_VARIABLE_RATE_LOAN_IN_RESERVE = '18', // 'User does not have a variable rate loan in progress on this reserve'
|
VL_UNDERLYING_BALANCE_NOT_GREATER_THAN_0 = '19', // 'The underlying balance needs to be greater than 0'
|
||||||
UNDERLYING_BALANCE_NOT_GREATER_THAN_0 = '19', // 'The underlying balance needs to be greater than 0'
|
VL_DEPOSIT_ALREADY_IN_USE = '20', // 'User deposit is already being used as collateral'
|
||||||
DEPOSIT_ALREADY_IN_USE = '20', // 'User deposit is already being used as collateral'
|
LP_NOT_ENOUGH_STABLE_BORROW_BALANCE = '21', // 'User does not have any stable rate loan for this reserve'
|
||||||
INVALID_EQUAL_ASSETS_TO_SWAP = '56', // User can't use same reserve as destination of liquidity swap
|
LP_INTEREST_RATE_REBALANCE_CONDITIONS_NOT_MET = '22', // 'Interest rate rebalance conditions were not met'
|
||||||
|
LP_LIQUIDATION_CALL_FAILED = '23', // 'Liquidation call failed'
|
||||||
// require error messages - LendingPool
|
LP_NOT_ENOUGH_LIQUIDITY_TO_BORROW = '24', // 'There is not enough liquidity available to borrow'
|
||||||
NOT_ENOUGH_STABLE_BORROW_BALANCE = '21', // 'User does not have any stable rate loan for this reserve'
|
LP_REQUESTED_AMOUNT_TOO_SMALL = '25', // 'The requested amount is too small for a FlashLoan.'
|
||||||
INTEREST_RATE_REBALANCE_CONDITIONS_NOT_MET = '22', // 'Interest rate rebalance conditions were not met'
|
LP_INCONSISTENT_PROTOCOL_ACTUAL_BALANCE = '26', // 'The actual balance of the protocol is inconsistent'
|
||||||
LIQUIDATION_CALL_FAILED = '23', // 'Liquidation call failed'
|
LP_CALLER_NOT_LENDING_POOL_CONFIGURATOR = '27', // 'The actual balance of the protocol is inconsistent'
|
||||||
NOT_ENOUGH_LIQUIDITY_TO_BORROW = '24', // 'There is not enough liquidity available to borrow'
|
LP_INCONSISTENT_FLASHLOAN_PARAMS = '28',
|
||||||
REQUESTED_AMOUNT_TOO_SMALL = '25', // 'The requested amount is too small for a FlashLoan.'
|
AT_CALLER_MUST_BE_LENDING_POOL = '29', // 'The caller of this function must be a lending pool'
|
||||||
INCONSISTENT_PROTOCOL_ACTUAL_BALANCE = '26', // 'The actual balance of the protocol is inconsistent'
|
AT_CANNOT_GIVE_ALLVWANCE_TO_HIMSELF = '30', // 'User cannot give allowance to himself'
|
||||||
CALLER_NOT_LENDING_POOL_CONFIGURATOR = '27', // 'The actual balance of the protocol is inconsistent'
|
AT_TRANSFER_AMOUNT_NOT_GT_0 = '31', // 'Transferred amount needs to be greater than zero'
|
||||||
BORROW_ALLOWANCE_ARE_NOT_ENOUGH = '54', // User borrows on behalf, but allowance are too small
|
RL_RESERVE_ALREADY_INITIALIZED = '32', // 'Reserve has already been initialized'
|
||||||
INVALID_FLASH_LOAN_EXECUTOR_RETURN = '60', // The flash loan received returned 0 (EOA)
|
LPC_CALLER_NOT_AAVE_ADMIN = '33', // 'The caller must be the aave admin'
|
||||||
|
LPC_RESERVE_LIQUIDITY_NOT_0 = '34', // 'The liquidity of the reserve needs to be 0'
|
||||||
// require error messages - aToken
|
LPC_INVALID_ATOKEN_POOL_ADDRESS = '35', // 'The liquidity of the reserve needs to be 0'
|
||||||
CALLER_MUST_BE_LENDING_POOL = '28', // 'The caller of this function must be a lending pool'
|
LPC_INVALID_STABLE_DEBT_TOKEN_POOL_ADDRESS = '36', // 'The liquidity of the reserve needs to be 0'
|
||||||
CANNOT_GIVE_ALLOWANCE_TO_HIMSELF = '30', // 'User cannot give allowance to himself'
|
LPC_INVALID_VARIABLE_DEBT_TOKEN_POOL_ADDRESS = '37', // 'The liquidity of the reserve needs to be 0'
|
||||||
TRANSFER_AMOUNT_NOT_GT_0 = '31', // 'Transferred amount needs to be greater than zero'
|
LPC_INVALID_STABLE_DEBT_TOKEN_UNDERLYING_ADDRESS = '38', // 'The liquidity of the reserve needs to be 0'
|
||||||
|
LPC_INVALID_VARIABLE_DEBT_TOKEN_UNDERLYING_ADDRESS = '39', // 'The liquidity of the reserve needs to be 0'
|
||||||
// require error messages - ReserveLogic
|
LPC_INVALID_ADDRESSES_PROVIDER_ID = '40', // 'The liquidity of the reserve needs to be 0'
|
||||||
RESERVE_ALREADY_INITIALIZED = '34', // 'Reserve has already been initialized'
|
LPAPR_PROVIDER_NOT_REGISTERED = '41', // 'Provider is not registered'
|
||||||
|
LPCM_HEALTH_FACTOR_NOT_BELOW_THRESHOLD = '42', // 'Health factor is not below the threshold'
|
||||||
//require error messages - LendingPoolConfiguration
|
LPCM_COLLATERAL_CANNOT_BE_LIQUIDATED = '43', // 'The collateral chosen cannot be liquidated'
|
||||||
CALLER_NOT_AAVE_ADMIN = '35', // 'The caller must be the aave admin'
|
LPCM_SPECIFIED_CURRENCY_NOT_BORROWED_BY_USER = '44', // 'User did not borrow the specified currency'
|
||||||
RESERVE_LIQUIDITY_NOT_0 = '36', // 'The liquidity of the reserve needs to be 0'
|
LPCM_NOT_ENOUGH_LIQUIDITY_TO_LIQUIDATE = '45', // "There isn't enough liquidity available to liquidate"
|
||||||
|
LPCM_NO_ERRORS = '46', // 'No errors'
|
||||||
//require error messages - LendingPoolAddressesProviderRegistry
|
LP_INVALID_FLASHLOAN_MODE = '47', //Invalid flashloan mode selected
|
||||||
PROVIDER_NOT_REGISTERED = '37', // 'Provider is not registered'
|
MATH_MULTIPLICATION_OVERFLOW = '48',
|
||||||
INVALID_ADDRESSES_PROVIDER_ID = '68',
|
MATH_ADDITION_OVERFLOW = '49',
|
||||||
|
MATH_DIVISION_BY_ZERO = '50',
|
||||||
//return error messages - LendingPoolCollateralManager
|
RL_LIQUIDITY_INDEX_OVERFLOW = '51', // Liquidity index overflows uint128
|
||||||
HEALTH_FACTOR_NOT_BELOW_THRESHOLD = '38', // 'Health factor is not below the threshold'
|
RL_VARIABLE_BORROW_INDEX_OVERFLOW = '52', // Variable borrow index overflows uint128
|
||||||
COLLATERAL_CANNOT_BE_LIQUIDATED = '39', // 'The collateral chosen cannot be liquidated'
|
RL_LIQUIDITY_RATE_OVERFLOW = '53', // Liquidity rate overflows uint128
|
||||||
SPECIFIED_CURRENCY_NOT_BORROWED_BY_USER = '40', // 'User did not borrow the specified currency'
|
RL_VARIABLE_BORROW_RATE_OVERFLOW = '54', // Variable borrow rate overflows uint128
|
||||||
NOT_ENOUGH_LIQUIDITY_TO_LIQUIDATE = '41', // "There isn't enough liquidity available to liquidate"
|
RL_STABLE_BORROW_RATE_OVERFLOW = '55', // Stable borrow rate overflows uint128
|
||||||
NO_ERRORS = '42', // 'No errors'
|
AT_INVALID_MINT_AMOUNT = '56', //invalid amount to mint
|
||||||
INVALID_FLASHLOAN_MODE = '43', //Invalid flashloan mode
|
LP_FAILED_REPAY_WITH_COLLATERAL = '57',
|
||||||
|
AT_INVALID_BURN_AMOUNT = '58', //invalid amount to burn
|
||||||
IS_PAUSED = '58', // Pool is paused
|
LP_BORROW_ALLOWANCE_ARE_NOT_ENOUGH = '59', // User borrows on behalf, but allowance are too small
|
||||||
|
LP_FAILED_COLLATERAL_SWAP = '60',
|
||||||
INVALID_LTV = '70',
|
LP_INVALID_EQUAL_ASSETS_TO_SWAP = '61',
|
||||||
INVALID_LIQ_THRESHOLD = '71',
|
LP_REENTRANCY_NOT_ALLOWED = '62',
|
||||||
INVALID_LIQ_BONUS = '72',
|
LP_CALLER_MUST_BE_AN_ATOKEN = '63',
|
||||||
INVALID_DECIMALS = '73',
|
P_IS_PAUSED = '64', // 'Pool is paused'
|
||||||
INVALID_RESERVE_FACTOR = '74',
|
LP_NO_MORE_RESERVES_ALLOWED = '65',
|
||||||
|
LP_INVALID_FLASH_LOAN_EXECUTOR_RETURN = '66',
|
||||||
|
RC_INVALID_LTV = '67',
|
||||||
|
RC_INVALID_LIQ_THRESHOLD = '68',
|
||||||
|
RC_INVALID_LIQ_BONUS = '69',
|
||||||
|
RC_INVALID_DECIMALS = '70',
|
||||||
|
RC_INVALID_RESERVE_FACTOR = '71',
|
||||||
|
LPAPR_INVALID_ADDRESSES_PROVIDER_ID = '72',
|
||||||
|
|
||||||
// old
|
// old
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
pragma solidity ^0.6.8;
|
pragma solidity ^0.6.8;
|
||||||
pragma experimental ABIEncoderV2;
|
pragma experimental ABIEncoderV2;
|
||||||
|
|
||||||
import {ReserveConfiguration} from '../../contracts/libraries/configuration/ReserveConfiguration.sol';
|
import {
|
||||||
|
ReserveConfiguration
|
||||||
|
} from '../../contracts/libraries/configuration/ReserveConfiguration.sol';
|
||||||
import {UserConfiguration} from '../../contracts/libraries/configuration/UserConfiguration.sol';
|
import {UserConfiguration} from '../../contracts/libraries/configuration/UserConfiguration.sol';
|
||||||
import {ReserveLogic} from '../../contracts/libraries/logic/ReserveLogic.sol';
|
import {ReserveLogic} from '../../contracts/libraries/logic/ReserveLogic.sol';
|
||||||
import {ILendingPool} from '../../contracts/interfaces/ILendingPool.sol';
|
import {ILendingPool} from '../../contracts/interfaces/ILendingPool.sol';
|
||||||
|
@ -12,7 +14,6 @@ Certora: Harness that delegates calls to the original LendingPool.
|
||||||
Used for the verification of the VariableDebtToken contract.
|
Used for the verification of the VariableDebtToken contract.
|
||||||
*/
|
*/
|
||||||
contract LendingPoolHarnessForVariableDebtToken is ILendingPool {
|
contract LendingPoolHarnessForVariableDebtToken is ILendingPool {
|
||||||
|
|
||||||
LendingPool private originalPool;
|
LendingPool private originalPool;
|
||||||
|
|
||||||
function deposit(
|
function deposit(
|
||||||
|
@ -91,26 +92,36 @@ contract LendingPoolHarnessForVariableDebtToken is ILendingPool {
|
||||||
return originalPool.getReservesList();
|
return originalPool.getReservesList();
|
||||||
}
|
}
|
||||||
|
|
||||||
function getReserveData(address asset) external override view returns (ReserveLogic.ReserveData memory) {
|
function getReserveData(address asset)
|
||||||
|
external
|
||||||
|
override
|
||||||
|
view
|
||||||
|
returns (ReserveLogic.ReserveData memory)
|
||||||
|
{
|
||||||
return originalPool.getReserveData(asset);
|
return originalPool.getReserveData(asset);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getUserConfiguration(address user) external override view returns (UserConfiguration.Map memory) {
|
function getUserConfiguration(address user)
|
||||||
|
external
|
||||||
|
override
|
||||||
|
view
|
||||||
|
returns (UserConfiguration.Map memory)
|
||||||
|
{
|
||||||
return originalPool.getUserConfiguration(user);
|
return originalPool.getUserConfiguration(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getUserAccountData(address user)
|
function getUserAccountData(address user)
|
||||||
external
|
external
|
||||||
override
|
override
|
||||||
view
|
view
|
||||||
returns (
|
returns (
|
||||||
uint256 totalCollateralETH,
|
uint256 totalCollateralETH,
|
||||||
uint256 totalBorrowsETH,
|
uint256 totalBorrowsETH,
|
||||||
uint256 availableBorrowsETH,
|
uint256 availableBorrowsETH,
|
||||||
uint256 currentLiquidationThreshold,
|
uint256 currentLiquidationThreshold,
|
||||||
uint256 ltv,
|
uint256 ltv,
|
||||||
uint256 healthFactor
|
uint256 healthFactor
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return originalPool.getUserAccountData(user);
|
return originalPool.getUserAccountData(user);
|
||||||
}
|
}
|
||||||
|
@ -122,12 +133,18 @@ contract LendingPoolHarnessForVariableDebtToken is ILendingPool {
|
||||||
address variableDebtAddress,
|
address variableDebtAddress,
|
||||||
address interestRateStrategyAddress
|
address interestRateStrategyAddress
|
||||||
) external override {
|
) external override {
|
||||||
originalPool.initReserve(asset, aTokenAddress, stableDebtAddress, variableDebtAddress, interestRateStrategyAddress);
|
originalPool.initReserve(
|
||||||
|
asset,
|
||||||
|
aTokenAddress,
|
||||||
|
stableDebtAddress,
|
||||||
|
variableDebtAddress,
|
||||||
|
interestRateStrategyAddress
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setReserveInterestRateStrategyAddress(address asset, address rateStrategyAddress)
|
function setReserveInterestRateStrategyAddress(address asset, address rateStrategyAddress)
|
||||||
external
|
external
|
||||||
override
|
override
|
||||||
{
|
{
|
||||||
originalPool.setReserveInterestRateStrategyAddress(asset, rateStrategyAddress);
|
originalPool.setReserveInterestRateStrategyAddress(asset, rateStrategyAddress);
|
||||||
}
|
}
|
||||||
|
@ -137,10 +154,10 @@ contract LendingPoolHarnessForVariableDebtToken is ILendingPool {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getConfiguration(address asset)
|
function getConfiguration(address asset)
|
||||||
external
|
external
|
||||||
override
|
override
|
||||||
view
|
view
|
||||||
returns (ReserveConfiguration.Map memory)
|
returns (ReserveConfiguration.Map memory)
|
||||||
{
|
{
|
||||||
return originalPool.getConfiguration(asset);
|
return originalPool.getConfiguration(asset);
|
||||||
}
|
}
|
||||||
|
@ -155,10 +172,10 @@ contract LendingPoolHarnessForVariableDebtToken is ILendingPool {
|
||||||
mapping(uint256 => uint256) private reserveNormalizedVariableDebt;
|
mapping(uint256 => uint256) private reserveNormalizedVariableDebt;
|
||||||
|
|
||||||
function getReserveNormalizedVariableDebt(address asset)
|
function getReserveNormalizedVariableDebt(address asset)
|
||||||
external
|
external
|
||||||
override
|
override
|
||||||
view
|
view
|
||||||
returns (uint256)
|
returns (uint256)
|
||||||
{
|
{
|
||||||
require(reserveNormalizedVariableDebt[block.timestamp] == 1e27);
|
require(reserveNormalizedVariableDebt[block.timestamp] == 1e27);
|
||||||
return reserveNormalizedVariableDebt[block.timestamp];
|
return reserveNormalizedVariableDebt[block.timestamp];
|
||||||
|
@ -194,5 +211,4 @@ contract LendingPoolHarnessForVariableDebtToken is ILendingPool {
|
||||||
) external override {
|
) external override {
|
||||||
originalPool.finalizeTransfer(asset, from, to, amount, balanceFromAfter, balanceToBefore);
|
originalPool.finalizeTransfer(asset, from, to, amount, balanceFromAfter, balanceToBefore);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,25 +4,23 @@ import {StableDebtToken} from '../../contracts/tokenization/StableDebtToken.sol'
|
||||||
import {IncentivizedERC20} from '../../contracts/tokenization/IncentivizedERC20.sol';
|
import {IncentivizedERC20} from '../../contracts/tokenization/IncentivizedERC20.sol';
|
||||||
|
|
||||||
contract StableDebtTokenHarness is StableDebtToken {
|
contract StableDebtTokenHarness is StableDebtToken {
|
||||||
|
constructor(
|
||||||
|
address pool,
|
||||||
|
address underlyingAsset,
|
||||||
|
string memory name,
|
||||||
|
string memory symbol,
|
||||||
|
address incentivesController
|
||||||
|
) public StableDebtToken(pool, underlyingAsset, name, symbol, incentivesController) {}
|
||||||
|
|
||||||
constructor(
|
function balanceOf(address account) public override view returns (uint256) {
|
||||||
address pool,
|
return IncentivizedERC20.balanceOf(account);
|
||||||
address underlyingAsset,
|
}
|
||||||
string memory name,
|
|
||||||
string memory symbol,
|
|
||||||
address incentivesController
|
|
||||||
) public StableDebtToken(pool, underlyingAsset, name, symbol, incentivesController) {}
|
|
||||||
|
|
||||||
function balanceOf(address account) public override view returns (uint256) {
|
function _calcTotalSupply(uint256 avgRate) internal override view returns (uint256) {
|
||||||
return IncentivizedERC20.balanceOf(account);
|
return IncentivizedERC20.totalSupply();
|
||||||
}
|
}
|
||||||
|
|
||||||
function _calcTotalSupply(uint256 avgRate) internal override view returns (uint256) {
|
function getIncentivesController() public view returns (address) {
|
||||||
return IncentivizedERC20.totalSupply();
|
return address(_incentivesController);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
function getIncentivesController() public view returns (address) {
|
|
||||||
return address(_incentivesController);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -7,71 +7,50 @@ import {UserConfiguration} from '../../contracts/libraries/configuration/UserCon
|
||||||
A wrapper contract for calling functions from the library UserConfiguration.
|
A wrapper contract for calling functions from the library UserConfiguration.
|
||||||
*/
|
*/
|
||||||
contract UserConfigurationHarness {
|
contract UserConfigurationHarness {
|
||||||
|
UserConfiguration.Map internal usersConfig;
|
||||||
|
|
||||||
UserConfiguration.Map internal usersConfig;
|
function setBorrowing(
|
||||||
|
address user,
|
||||||
|
uint256 reserveIndex,
|
||||||
|
bool borrowing
|
||||||
|
) public {
|
||||||
|
UserConfiguration.setBorrowing(usersConfig, reserveIndex, borrowing);
|
||||||
|
}
|
||||||
|
|
||||||
function setBorrowing(
|
function setUsingAsCollateral(
|
||||||
address user,
|
address user,
|
||||||
uint256 reserveIndex,
|
uint256 reserveIndex,
|
||||||
bool borrowing
|
bool _usingAsCollateral
|
||||||
) public {
|
) public {
|
||||||
UserConfiguration.setBorrowing(usersConfig, reserveIndex, borrowing);
|
UserConfiguration.setUsingAsCollateral(usersConfig, reserveIndex, _usingAsCollateral);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setUsingAsCollateral(
|
function isUsingAsCollateralOrBorrowing(address user, uint256 reserveIndex)
|
||||||
address user,
|
public
|
||||||
uint256 reserveIndex,
|
|
||||||
bool _usingAsCollateral
|
|
||||||
) public {
|
|
||||||
UserConfiguration.setUsingAsCollateral(usersConfig, reserveIndex, _usingAsCollateral);
|
|
||||||
}
|
|
||||||
|
|
||||||
function isUsingAsCollateralOrBorrowing(
|
|
||||||
address user,
|
|
||||||
uint256 reserveIndex)
|
|
||||||
public
|
|
||||||
view
|
view
|
||||||
returns (bool) {
|
returns (bool)
|
||||||
return UserConfiguration.isUsingAsCollateralOrBorrowing(usersConfig, reserveIndex);
|
{
|
||||||
}
|
return UserConfiguration.isUsingAsCollateralOrBorrowing(usersConfig, reserveIndex);
|
||||||
|
}
|
||||||
|
|
||||||
function isBorrowing(
|
function isBorrowing(address user, uint256 reserveIndex) public view returns (bool) {
|
||||||
address user,
|
return UserConfiguration.isBorrowing(usersConfig, reserveIndex);
|
||||||
uint256 reserveIndex)
|
}
|
||||||
public
|
|
||||||
view
|
|
||||||
returns (bool) {
|
|
||||||
return UserConfiguration.isBorrowing(usersConfig, reserveIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
function isUsingAsCollateral(
|
function isUsingAsCollateral(address user, uint256 reserveIndex) public view returns (bool) {
|
||||||
address user,
|
return UserConfiguration.isUsingAsCollateral(usersConfig, reserveIndex);
|
||||||
uint256 reserveIndex)
|
}
|
||||||
public
|
|
||||||
view
|
|
||||||
returns (bool) {
|
|
||||||
return UserConfiguration.isUsingAsCollateral(usersConfig, reserveIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
function isBorrowingAny(
|
function isBorrowingAny(address user) public view returns (bool) {
|
||||||
address user)
|
return UserConfiguration.isBorrowingAny(usersConfig);
|
||||||
public
|
}
|
||||||
view
|
|
||||||
returns (bool) {
|
|
||||||
return UserConfiguration.isBorrowingAny(usersConfig);
|
|
||||||
}
|
|
||||||
|
|
||||||
function isEmpty(
|
function isEmpty(address user) public view returns (bool) {
|
||||||
address user)
|
return UserConfiguration.isEmpty(usersConfig);
|
||||||
public
|
}
|
||||||
view
|
|
||||||
returns (bool) {
|
/*
|
||||||
return UserConfiguration.isEmpty(usersConfig);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Mimics the original constructor of the contract.
|
Mimics the original constructor of the contract.
|
||||||
*/
|
*/
|
||||||
function init_state() public { }
|
function init_state() public {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,10 +19,10 @@ makeSuite('AddressesProviderRegistry', (testEnv: TestEnv) => {
|
||||||
|
|
||||||
it('tries to register an addresses provider with id 0', async () => {
|
it('tries to register an addresses provider with id 0', async () => {
|
||||||
const {users, registry} = testEnv;
|
const {users, registry} = testEnv;
|
||||||
const {INVALID_ADDRESSES_PROVIDER_ID} = ProtocolErrors;
|
const {LPAPR_INVALID_ADDRESSES_PROVIDER_ID} = ProtocolErrors;
|
||||||
|
|
||||||
await expect(registry.registerAddressesProvider(users[2].address, '0')).to.be.revertedWith(
|
await expect(registry.registerAddressesProvider(users[2].address, '0')).to.be.revertedWith(
|
||||||
INVALID_ADDRESSES_PROVIDER_ID
|
LPAPR_INVALID_ADDRESSES_PROVIDER_ID
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -62,22 +62,22 @@ makeSuite('AddressesProviderRegistry', (testEnv: TestEnv) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Tries to remove a unregistered addressesProvider', async () => {
|
it('Tries to remove a unregistered addressesProvider', async () => {
|
||||||
const {PROVIDER_NOT_REGISTERED} = ProtocolErrors;
|
const {LPAPR_PROVIDER_NOT_REGISTERED} = ProtocolErrors;
|
||||||
|
|
||||||
const {users, registry} = testEnv;
|
const {users, registry} = testEnv;
|
||||||
|
|
||||||
await expect(registry.unregisterAddressesProvider(users[2].address)).to.be.revertedWith(
|
await expect(registry.unregisterAddressesProvider(users[2].address)).to.be.revertedWith(
|
||||||
PROVIDER_NOT_REGISTERED
|
LPAPR_PROVIDER_NOT_REGISTERED
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Tries to remove a unregistered addressesProvider', async () => {
|
it('Tries to remove a unregistered addressesProvider', async () => {
|
||||||
const {PROVIDER_NOT_REGISTERED} = ProtocolErrors;
|
const {LPAPR_PROVIDER_NOT_REGISTERED} = ProtocolErrors;
|
||||||
|
|
||||||
const {users, registry} = testEnv;
|
const {users, registry} = testEnv;
|
||||||
|
|
||||||
await expect(registry.unregisterAddressesProvider(users[2].address)).to.be.revertedWith(
|
await expect(registry.unregisterAddressesProvider(users[2].address)).to.be.revertedWith(
|
||||||
PROVIDER_NOT_REGISTERED
|
LPAPR_PROVIDER_NOT_REGISTERED
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -3,19 +3,19 @@ import {makeSuite, TestEnv} from './helpers/make-suite';
|
||||||
import {ProtocolErrors} from '../helpers/types';
|
import {ProtocolErrors} from '../helpers/types';
|
||||||
|
|
||||||
makeSuite('AToken: Modifiers', (testEnv: TestEnv) => {
|
makeSuite('AToken: Modifiers', (testEnv: TestEnv) => {
|
||||||
const {CALLER_MUST_BE_LENDING_POOL} = ProtocolErrors;
|
const {AT_CALLER_MUST_BE_LENDING_POOL} = ProtocolErrors;
|
||||||
|
|
||||||
it('Tries to invoke mint not being the LendingPool', async () => {
|
it('Tries to invoke mint not being the LendingPool', async () => {
|
||||||
const {deployer, aDai} = testEnv;
|
const {deployer, aDai} = testEnv;
|
||||||
await expect(aDai.mint(deployer.address, '1', '1')).to.be.revertedWith(
|
await expect(aDai.mint(deployer.address, '1', '1')).to.be.revertedWith(
|
||||||
CALLER_MUST_BE_LENDING_POOL
|
AT_CALLER_MUST_BE_LENDING_POOL
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Tries to invoke burn not being the LendingPool', async () => {
|
it('Tries to invoke burn not being the LendingPool', async () => {
|
||||||
const {deployer, aDai} = testEnv;
|
const {deployer, aDai} = testEnv;
|
||||||
await expect(aDai.burn(deployer.address, deployer.address, '1', '1')).to.be.revertedWith(
|
await expect(aDai.burn(deployer.address, deployer.address, '1', '1')).to.be.revertedWith(
|
||||||
CALLER_MUST_BE_LENDING_POOL
|
AT_CALLER_MUST_BE_LENDING_POOL
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -23,13 +23,13 @@ makeSuite('AToken: Modifiers', (testEnv: TestEnv) => {
|
||||||
const {deployer, users, aDai} = testEnv;
|
const {deployer, users, aDai} = testEnv;
|
||||||
await expect(
|
await expect(
|
||||||
aDai.transferOnLiquidation(deployer.address, users[0].address, '1')
|
aDai.transferOnLiquidation(deployer.address, users[0].address, '1')
|
||||||
).to.be.revertedWith(CALLER_MUST_BE_LENDING_POOL);
|
).to.be.revertedWith(AT_CALLER_MUST_BE_LENDING_POOL);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Tries to invoke transferUnderlyingTo not being the LendingPool', async () => {
|
it('Tries to invoke transferUnderlyingTo not being the LendingPool', async () => {
|
||||||
const {deployer, users, aDai} = testEnv;
|
const {deployer, users, aDai} = testEnv;
|
||||||
await expect(aDai.transferUnderlyingTo(deployer.address, '1')).to.be.revertedWith(
|
await expect(aDai.transferUnderlyingTo(deployer.address, '1')).to.be.revertedWith(
|
||||||
CALLER_MUST_BE_LENDING_POOL
|
AT_CALLER_MUST_BE_LENDING_POOL
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -14,10 +14,7 @@ makeSuite('AToken: Transfer', (testEnv: TestEnv) => {
|
||||||
const {
|
const {
|
||||||
INVALID_FROM_BALANCE_AFTER_TRANSFER,
|
INVALID_FROM_BALANCE_AFTER_TRANSFER,
|
||||||
INVALID_TO_BALANCE_AFTER_TRANSFER,
|
INVALID_TO_BALANCE_AFTER_TRANSFER,
|
||||||
// ZERO_COLLATERAL,
|
VL_TRANSFER_NOT_ALLOWED,
|
||||||
COLLATERAL_BALANCE_IS_0,
|
|
||||||
TRANSFER_NOT_ALLOWED,
|
|
||||||
IS_PAUSED,
|
|
||||||
} = ProtocolErrors;
|
} = ProtocolErrors;
|
||||||
|
|
||||||
it('User 0 deposits 1000 DAI, transfers to user 1', async () => {
|
it('User 0 deposits 1000 DAI, transfers to user 1', async () => {
|
||||||
|
@ -86,8 +83,8 @@ makeSuite('AToken: Transfer', (testEnv: TestEnv) => {
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
aDai.connect(users[1].signer).transfer(users[0].address, aDAItoTransfer),
|
aDai.connect(users[1].signer).transfer(users[0].address, aDAItoTransfer),
|
||||||
TRANSFER_NOT_ALLOWED
|
VL_TRANSFER_NOT_ALLOWED
|
||||||
).to.be.revertedWith(TRANSFER_NOT_ALLOWED);
|
).to.be.revertedWith(VL_TRANSFER_NOT_ALLOWED);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('User 1 tries to transfer a small amount of DAI used as collateral back to user 0', async () => {
|
it('User 1 tries to transfer a small amount of DAI used as collateral back to user 0', async () => {
|
||||||
|
|
|
@ -11,13 +11,13 @@ const {expect} = require('chai');
|
||||||
|
|
||||||
makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
|
makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
|
||||||
const {
|
const {
|
||||||
CALLER_NOT_AAVE_ADMIN,
|
LPC_CALLER_NOT_AAVE_ADMIN,
|
||||||
RESERVE_LIQUIDITY_NOT_0,
|
LPC_RESERVE_LIQUIDITY_NOT_0,
|
||||||
INVALID_LTV,
|
RC_INVALID_LTV,
|
||||||
INVALID_LIQ_THRESHOLD,
|
RC_INVALID_LIQ_THRESHOLD,
|
||||||
INVALID_LIQ_BONUS,
|
RC_INVALID_LIQ_BONUS,
|
||||||
INVALID_DECIMALS,
|
RC_INVALID_DECIMALS,
|
||||||
INVALID_RESERVE_FACTOR,
|
RC_INVALID_RESERVE_FACTOR,
|
||||||
} = ProtocolErrors;
|
} = ProtocolErrors;
|
||||||
|
|
||||||
it('Reverts trying to set an invalid LTV', async () => {
|
it('Reverts trying to set an invalid LTV', async () => {
|
||||||
|
@ -25,7 +25,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
|
||||||
|
|
||||||
const invalidLtv = 65536;
|
const invalidLtv = 65536;
|
||||||
|
|
||||||
await expect(configurator.setLtv(weth.address, invalidLtv)).to.be.revertedWith(INVALID_LTV);
|
await expect(configurator.setLtv(weth.address, invalidLtv)).to.be.revertedWith(RC_INVALID_LTV);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Reverts trying to set an invalid liquidation threshold', async () => {
|
it('Reverts trying to set an invalid liquidation threshold', async () => {
|
||||||
|
@ -35,7 +35,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
configurator.setLiquidationThreshold(weth.address, invalidLiqThreshold)
|
configurator.setLiquidationThreshold(weth.address, invalidLiqThreshold)
|
||||||
).to.be.revertedWith(INVALID_LIQ_THRESHOLD);
|
).to.be.revertedWith(RC_INVALID_LIQ_THRESHOLD);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Reverts trying to set an invalid liquidation bonus', async () => {
|
it('Reverts trying to set an invalid liquidation bonus', async () => {
|
||||||
|
@ -45,7 +45,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
configurator.setLiquidationBonus(weth.address, invalidLiqBonus)
|
configurator.setLiquidationBonus(weth.address, invalidLiqBonus)
|
||||||
).to.be.revertedWith(INVALID_LIQ_BONUS);
|
).to.be.revertedWith(RC_INVALID_LIQ_BONUS);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Reverts trying to set an invalid reserve decimals', async () => {
|
it('Reverts trying to set an invalid reserve decimals', async () => {
|
||||||
|
@ -54,7 +54,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
|
||||||
const invalidDecimals = 256;
|
const invalidDecimals = 256;
|
||||||
|
|
||||||
await expect(configurator.setReserveDecimals(weth.address, invalidDecimals)).to.be.revertedWith(
|
await expect(configurator.setReserveDecimals(weth.address, invalidDecimals)).to.be.revertedWith(
|
||||||
INVALID_DECIMALS
|
RC_INVALID_DECIMALS
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
configurator.setReserveFactor(weth.address, invalidReserveFactor)
|
configurator.setReserveFactor(weth.address, invalidReserveFactor)
|
||||||
).to.be.revertedWith(INVALID_RESERVE_FACTOR);
|
).to.be.revertedWith(RC_INVALID_RESERVE_FACTOR);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Deactivates the ETH reserve', async () => {
|
it('Deactivates the ETH reserve', async () => {
|
||||||
|
@ -87,16 +87,16 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
|
||||||
const {configurator, users, weth} = testEnv;
|
const {configurator, users, weth} = testEnv;
|
||||||
await expect(
|
await expect(
|
||||||
configurator.connect(users[2].signer).deactivateReserve(weth.address),
|
configurator.connect(users[2].signer).deactivateReserve(weth.address),
|
||||||
CALLER_NOT_AAVE_ADMIN
|
LPC_CALLER_NOT_AAVE_ADMIN
|
||||||
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
|
).to.be.revertedWith(LPC_CALLER_NOT_AAVE_ADMIN);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Check the onlyAaveAdmin on activateReserve ', async () => {
|
it('Check the onlyAaveAdmin on activateReserve ', async () => {
|
||||||
const {configurator, users, weth} = testEnv;
|
const {configurator, users, weth} = testEnv;
|
||||||
await expect(
|
await expect(
|
||||||
configurator.connect(users[2].signer).activateReserve(weth.address),
|
configurator.connect(users[2].signer).activateReserve(weth.address),
|
||||||
CALLER_NOT_AAVE_ADMIN
|
LPC_CALLER_NOT_AAVE_ADMIN
|
||||||
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
|
).to.be.revertedWith(LPC_CALLER_NOT_AAVE_ADMIN);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Freezes the ETH reserve', async () => {
|
it('Freezes the ETH reserve', async () => {
|
||||||
|
@ -156,16 +156,16 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
|
||||||
const {configurator, users, weth} = testEnv;
|
const {configurator, users, weth} = testEnv;
|
||||||
await expect(
|
await expect(
|
||||||
configurator.connect(users[2].signer).freezeReserve(weth.address),
|
configurator.connect(users[2].signer).freezeReserve(weth.address),
|
||||||
CALLER_NOT_AAVE_ADMIN
|
LPC_CALLER_NOT_AAVE_ADMIN
|
||||||
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
|
).to.be.revertedWith(LPC_CALLER_NOT_AAVE_ADMIN);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Check the onlyAaveAdmin on unfreezeReserve ', async () => {
|
it('Check the onlyAaveAdmin on unfreezeReserve ', async () => {
|
||||||
const {configurator, users, weth} = testEnv;
|
const {configurator, users, weth} = testEnv;
|
||||||
await expect(
|
await expect(
|
||||||
configurator.connect(users[2].signer).unfreezeReserve(weth.address),
|
configurator.connect(users[2].signer).unfreezeReserve(weth.address),
|
||||||
CALLER_NOT_AAVE_ADMIN
|
LPC_CALLER_NOT_AAVE_ADMIN
|
||||||
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
|
).to.be.revertedWith(LPC_CALLER_NOT_AAVE_ADMIN);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Deactivates the ETH reserve for borrowing', async () => {
|
it('Deactivates the ETH reserve for borrowing', async () => {
|
||||||
|
@ -228,16 +228,16 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
|
||||||
const {configurator, users, weth} = testEnv;
|
const {configurator, users, weth} = testEnv;
|
||||||
await expect(
|
await expect(
|
||||||
configurator.connect(users[2].signer).disableBorrowingOnReserve(weth.address),
|
configurator.connect(users[2].signer).disableBorrowingOnReserve(weth.address),
|
||||||
CALLER_NOT_AAVE_ADMIN
|
LPC_CALLER_NOT_AAVE_ADMIN
|
||||||
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
|
).to.be.revertedWith(LPC_CALLER_NOT_AAVE_ADMIN);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Check the onlyAaveAdmin on enableBorrowingOnReserve ', async () => {
|
it('Check the onlyAaveAdmin on enableBorrowingOnReserve ', async () => {
|
||||||
const {configurator, users, weth} = testEnv;
|
const {configurator, users, weth} = testEnv;
|
||||||
await expect(
|
await expect(
|
||||||
configurator.connect(users[2].signer).enableBorrowingOnReserve(weth.address, true),
|
configurator.connect(users[2].signer).enableBorrowingOnReserve(weth.address, true),
|
||||||
CALLER_NOT_AAVE_ADMIN
|
LPC_CALLER_NOT_AAVE_ADMIN
|
||||||
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
|
).to.be.revertedWith(LPC_CALLER_NOT_AAVE_ADMIN);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Deactivates the ETH reserve as collateral', async () => {
|
it('Deactivates the ETH reserve as collateral', async () => {
|
||||||
|
@ -297,8 +297,8 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
|
||||||
const {configurator, users, weth} = testEnv;
|
const {configurator, users, weth} = testEnv;
|
||||||
await expect(
|
await expect(
|
||||||
configurator.connect(users[2].signer).disableReserveAsCollateral(weth.address),
|
configurator.connect(users[2].signer).disableReserveAsCollateral(weth.address),
|
||||||
CALLER_NOT_AAVE_ADMIN
|
LPC_CALLER_NOT_AAVE_ADMIN
|
||||||
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
|
).to.be.revertedWith(LPC_CALLER_NOT_AAVE_ADMIN);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Check the onlyAaveAdmin on enableReserveAsCollateral ', async () => {
|
it('Check the onlyAaveAdmin on enableReserveAsCollateral ', async () => {
|
||||||
|
@ -307,8 +307,8 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
|
||||||
configurator
|
configurator
|
||||||
.connect(users[2].signer)
|
.connect(users[2].signer)
|
||||||
.enableReserveAsCollateral(weth.address, '75', '80', '105'),
|
.enableReserveAsCollateral(weth.address, '75', '80', '105'),
|
||||||
CALLER_NOT_AAVE_ADMIN
|
LPC_CALLER_NOT_AAVE_ADMIN
|
||||||
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
|
).to.be.revertedWith(LPC_CALLER_NOT_AAVE_ADMIN);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Disable stable borrow rate on the ETH reserve', async () => {
|
it('Disable stable borrow rate on the ETH reserve', async () => {
|
||||||
|
@ -367,16 +367,16 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
|
||||||
const {configurator, users, weth} = testEnv;
|
const {configurator, users, weth} = testEnv;
|
||||||
await expect(
|
await expect(
|
||||||
configurator.connect(users[2].signer).disableReserveStableRate(weth.address),
|
configurator.connect(users[2].signer).disableReserveStableRate(weth.address),
|
||||||
CALLER_NOT_AAVE_ADMIN
|
LPC_CALLER_NOT_AAVE_ADMIN
|
||||||
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
|
).to.be.revertedWith(LPC_CALLER_NOT_AAVE_ADMIN);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Check the onlyAaveAdmin on enableReserveStableRate', async () => {
|
it('Check the onlyAaveAdmin on enableReserveStableRate', async () => {
|
||||||
const {configurator, users, weth} = testEnv;
|
const {configurator, users, weth} = testEnv;
|
||||||
await expect(
|
await expect(
|
||||||
configurator.connect(users[2].signer).enableReserveStableRate(weth.address),
|
configurator.connect(users[2].signer).enableReserveStableRate(weth.address),
|
||||||
CALLER_NOT_AAVE_ADMIN
|
LPC_CALLER_NOT_AAVE_ADMIN
|
||||||
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
|
).to.be.revertedWith(LPC_CALLER_NOT_AAVE_ADMIN);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Changes LTV of the reserve', async () => {
|
it('Changes LTV of the reserve', async () => {
|
||||||
|
@ -409,8 +409,8 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
|
||||||
const {configurator, users, weth} = testEnv;
|
const {configurator, users, weth} = testEnv;
|
||||||
await expect(
|
await expect(
|
||||||
configurator.connect(users[2].signer).setLtv(weth.address, '75'),
|
configurator.connect(users[2].signer).setLtv(weth.address, '75'),
|
||||||
CALLER_NOT_AAVE_ADMIN
|
LPC_CALLER_NOT_AAVE_ADMIN
|
||||||
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
|
).to.be.revertedWith(LPC_CALLER_NOT_AAVE_ADMIN);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Changes the reserve factor of the reserve', async () => {
|
it('Changes the reserve factor of the reserve', async () => {
|
||||||
|
@ -443,8 +443,8 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
|
||||||
const {configurator, users, weth} = testEnv;
|
const {configurator, users, weth} = testEnv;
|
||||||
await expect(
|
await expect(
|
||||||
configurator.connect(users[2].signer).setReserveFactor(weth.address, '2000'),
|
configurator.connect(users[2].signer).setReserveFactor(weth.address, '2000'),
|
||||||
CALLER_NOT_AAVE_ADMIN
|
LPC_CALLER_NOT_AAVE_ADMIN
|
||||||
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
|
).to.be.revertedWith(LPC_CALLER_NOT_AAVE_ADMIN);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Changes liquidation threshold of the reserve', async () => {
|
it('Changes liquidation threshold of the reserve', async () => {
|
||||||
|
@ -477,8 +477,8 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
|
||||||
const {configurator, users, weth} = testEnv;
|
const {configurator, users, weth} = testEnv;
|
||||||
await expect(
|
await expect(
|
||||||
configurator.connect(users[2].signer).setLiquidationThreshold(weth.address, '80'),
|
configurator.connect(users[2].signer).setLiquidationThreshold(weth.address, '80'),
|
||||||
CALLER_NOT_AAVE_ADMIN
|
LPC_CALLER_NOT_AAVE_ADMIN
|
||||||
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
|
).to.be.revertedWith(LPC_CALLER_NOT_AAVE_ADMIN);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Changes liquidation bonus of the reserve', async () => {
|
it('Changes liquidation bonus of the reserve', async () => {
|
||||||
|
@ -511,24 +511,24 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
|
||||||
const {configurator, users, weth} = testEnv;
|
const {configurator, users, weth} = testEnv;
|
||||||
await expect(
|
await expect(
|
||||||
configurator.connect(users[2].signer).setLiquidationBonus(weth.address, '80'),
|
configurator.connect(users[2].signer).setLiquidationBonus(weth.address, '80'),
|
||||||
CALLER_NOT_AAVE_ADMIN
|
LPC_CALLER_NOT_AAVE_ADMIN
|
||||||
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
|
).to.be.revertedWith(LPC_CALLER_NOT_AAVE_ADMIN);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Check the onlyAaveAdmin on setReserveDecimals', async () => {
|
it('Check the onlyAaveAdmin on setReserveDecimals', async () => {
|
||||||
const {configurator, users, weth} = testEnv;
|
const {configurator, users, weth} = testEnv;
|
||||||
await expect(
|
await expect(
|
||||||
configurator.connect(users[2].signer).setReserveDecimals(weth.address, '80'),
|
configurator.connect(users[2].signer).setReserveDecimals(weth.address, '80'),
|
||||||
CALLER_NOT_AAVE_ADMIN
|
LPC_CALLER_NOT_AAVE_ADMIN
|
||||||
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
|
).to.be.revertedWith(LPC_CALLER_NOT_AAVE_ADMIN);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Check the onlyAaveAdmin on setLiquidationBonus', async () => {
|
it('Check the onlyAaveAdmin on setLiquidationBonus', async () => {
|
||||||
const {configurator, users, weth} = testEnv;
|
const {configurator, users, weth} = testEnv;
|
||||||
await expect(
|
await expect(
|
||||||
configurator.connect(users[2].signer).setLiquidationBonus(weth.address, '80'),
|
configurator.connect(users[2].signer).setLiquidationBonus(weth.address, '80'),
|
||||||
CALLER_NOT_AAVE_ADMIN
|
LPC_CALLER_NOT_AAVE_ADMIN
|
||||||
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
|
).to.be.revertedWith(LPC_CALLER_NOT_AAVE_ADMIN);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Reverts when trying to disable the DAI reserve with liquidity on it', async () => {
|
it('Reverts when trying to disable the DAI reserve with liquidity on it', async () => {
|
||||||
|
@ -545,7 +545,7 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => {
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
configurator.deactivateReserve(dai.address),
|
configurator.deactivateReserve(dai.address),
|
||||||
RESERVE_LIQUIDITY_NOT_0
|
LPC_RESERVE_LIQUIDITY_NOT_0
|
||||||
).to.be.revertedWith(RESERVE_LIQUIDITY_NOT_0);
|
).to.be.revertedWith(LPC_RESERVE_LIQUIDITY_NOT_0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -8,21 +8,23 @@ import {MockFlashLoanReceiver} from '../types/MockFlashLoanReceiver';
|
||||||
import {ProtocolErrors, eContractid} from '../helpers/types';
|
import {ProtocolErrors, eContractid} from '../helpers/types';
|
||||||
import {VariableDebtToken} from '../types/VariableDebtToken';
|
import {VariableDebtToken} from '../types/VariableDebtToken';
|
||||||
import {StableDebtToken} from '../types/StableDebtToken';
|
import {StableDebtToken} from '../types/StableDebtToken';
|
||||||
import {getMockFlashLoanReceiver} from '../helpers/contracts-getters';
|
import {
|
||||||
|
getMockFlashLoanReceiver,
|
||||||
|
getStableDebtToken,
|
||||||
|
getVariableDebtToken,
|
||||||
|
} from '../helpers/contracts-getters';
|
||||||
|
|
||||||
const {expect} = require('chai');
|
const {expect} = require('chai');
|
||||||
|
|
||||||
makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
|
makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
|
||||||
let _mockFlashLoanReceiver = {} as MockFlashLoanReceiver;
|
let _mockFlashLoanReceiver = {} as MockFlashLoanReceiver;
|
||||||
const {
|
const {
|
||||||
COLLATERAL_BALANCE_IS_0,
|
VL_COLLATERAL_BALANCE_IS_0,
|
||||||
REQUESTED_AMOUNT_TOO_SMALL,
|
|
||||||
TRANSFER_AMOUNT_EXCEEDS_BALANCE,
|
TRANSFER_AMOUNT_EXCEEDS_BALANCE,
|
||||||
INVALID_FLASHLOAN_MODE,
|
LP_INVALID_FLASHLOAN_MODE,
|
||||||
SAFEERC20_LOWLEVEL_CALL,
|
SAFEERC20_LOWLEVEL_CALL,
|
||||||
IS_PAUSED,
|
LP_INVALID_FLASH_LOAN_EXECUTOR_RETURN,
|
||||||
INVALID_FLASH_LOAN_EXECUTOR_RETURN,
|
LP_BORROW_ALLOWANCE_ARE_NOT_ENOUGH,
|
||||||
BORROW_ALLOWANCE_ARE_NOT_ENOUGH,
|
|
||||||
} = ProtocolErrors;
|
} = ProtocolErrors;
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
|
@ -136,7 +138,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
|
||||||
'0x10',
|
'0x10',
|
||||||
'0'
|
'0'
|
||||||
)
|
)
|
||||||
).to.be.revertedWith(INVALID_FLASH_LOAN_EXECUTOR_RETURN);
|
).to.be.revertedWith(LP_INVALID_FLASH_LOAN_EXECUTOR_RETURN);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Takes a WETH flashloan with an invalid mode. (revert expected)', async () => {
|
it('Takes a WETH flashloan with an invalid mode. (revert expected)', async () => {
|
||||||
|
@ -190,10 +192,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
|
||||||
weth.address
|
weth.address
|
||||||
);
|
);
|
||||||
|
|
||||||
const wethDebtToken = await getContract<VariableDebtToken>(
|
const wethDebtToken = await getVariableDebtToken(variableDebtTokenAddress);
|
||||||
eContractid.VariableDebtToken,
|
|
||||||
variableDebtTokenAddress
|
|
||||||
);
|
|
||||||
|
|
||||||
const callerDebt = await wethDebtToken.balanceOf(caller.address);
|
const callerDebt = await wethDebtToken.balanceOf(caller.address);
|
||||||
|
|
||||||
|
@ -307,7 +306,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
|
||||||
'0x10',
|
'0x10',
|
||||||
'0'
|
'0'
|
||||||
)
|
)
|
||||||
).to.be.revertedWith(COLLATERAL_BALANCE_IS_0);
|
).to.be.revertedWith(VL_COLLATERAL_BALANCE_IS_0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Caller deposits 5 WETH as collateral, Takes a USDC flashloan with mode = 2, does not return the funds. A loan for caller is created', async () => {
|
it('Caller deposits 5 WETH as collateral, Takes a USDC flashloan with mode = 2, does not return the funds. A loan for caller is created', async () => {
|
||||||
|
@ -342,10 +341,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
|
||||||
usdc.address
|
usdc.address
|
||||||
);
|
);
|
||||||
|
|
||||||
const usdcDebtToken = await getContract<VariableDebtToken>(
|
const usdcDebtToken = await getVariableDebtToken(variableDebtTokenAddress);
|
||||||
eContractid.VariableDebtToken,
|
|
||||||
variableDebtTokenAddress
|
|
||||||
);
|
|
||||||
|
|
||||||
const callerDebt = await usdcDebtToken.balanceOf(caller.address);
|
const callerDebt = await usdcDebtToken.balanceOf(caller.address);
|
||||||
|
|
||||||
|
@ -407,10 +403,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
|
||||||
|
|
||||||
const {stableDebtTokenAddress} = await helpersContract.getReserveTokensAddresses(weth.address);
|
const {stableDebtTokenAddress} = await helpersContract.getReserveTokensAddresses(weth.address);
|
||||||
|
|
||||||
const wethDebtToken = await getContract<StableDebtToken>(
|
const wethDebtToken = await getStableDebtToken(stableDebtTokenAddress);
|
||||||
eContractid.VariableDebtToken,
|
|
||||||
stableDebtTokenAddress
|
|
||||||
);
|
|
||||||
|
|
||||||
const callerDebt = await wethDebtToken.balanceOf(caller.address);
|
const callerDebt = await wethDebtToken.balanceOf(caller.address);
|
||||||
|
|
||||||
|
@ -450,7 +443,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
|
||||||
'0x10',
|
'0x10',
|
||||||
'0'
|
'0'
|
||||||
)
|
)
|
||||||
).to.be.revertedWith(BORROW_ALLOWANCE_ARE_NOT_ENOUGH);
|
).to.be.revertedWith(LP_BORROW_ALLOWANCE_ARE_NOT_ENOUGH);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Caller takes a WETH flashloan with mode = 1 onBehalfOf user with allowance. A loan for onBehalfOf is creatd.', async () => {
|
it('Caller takes a WETH flashloan with mode = 1 onBehalfOf user with allowance. A loan for onBehalfOf is creatd.', async () => {
|
||||||
|
@ -464,7 +457,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
|
||||||
// Deposited for onBehalfOf user already, delegate borrow allowance
|
// Deposited for onBehalfOf user already, delegate borrow allowance
|
||||||
await pool
|
await pool
|
||||||
.connect(onBehalfOf.signer)
|
.connect(onBehalfOf.signer)
|
||||||
.delegateBorrowAllowance(weth.address, caller.address, 1, flashAmount);
|
.delegateBorrowAllowance([weth.address], caller.address, [1], [flashAmount]);
|
||||||
|
|
||||||
await _mockFlashLoanReceiver.setFailExecutionTransfer(true);
|
await _mockFlashLoanReceiver.setFailExecutionTransfer(true);
|
||||||
|
|
||||||
|
@ -482,10 +475,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => {
|
||||||
|
|
||||||
const {stableDebtTokenAddress} = await helpersContract.getReserveTokensAddresses(weth.address);
|
const {stableDebtTokenAddress} = await helpersContract.getReserveTokensAddresses(weth.address);
|
||||||
|
|
||||||
const wethDebtToken = await getContract<StableDebtToken>(
|
const wethDebtToken = await getStableDebtToken(stableDebtTokenAddress);
|
||||||
eContractid.VariableDebtToken,
|
|
||||||
stableDebtTokenAddress
|
|
||||||
);
|
|
||||||
|
|
||||||
const onBehalfOfDebt = await wethDebtToken.balanceOf(onBehalfOf.address);
|
const onBehalfOfDebt = await wethDebtToken.balanceOf(onBehalfOf.address);
|
||||||
|
|
||||||
|
|
|
@ -277,9 +277,9 @@ export const withdraw = async (
|
||||||
};
|
};
|
||||||
|
|
||||||
export const delegateBorrowAllowance = async (
|
export const delegateBorrowAllowance = async (
|
||||||
reserveSymbol: string,
|
reserveSymbols: string[],
|
||||||
amount: string,
|
amounts: string[],
|
||||||
interestRateMode: string,
|
interestRateModes: string[],
|
||||||
user: SignerWithAddress,
|
user: SignerWithAddress,
|
||||||
receiver: tEthereumAddress,
|
receiver: tEthereumAddress,
|
||||||
expectedResult: string,
|
expectedResult: string,
|
||||||
|
@ -288,20 +288,32 @@ export const delegateBorrowAllowance = async (
|
||||||
) => {
|
) => {
|
||||||
const {pool} = testEnv;
|
const {pool} = testEnv;
|
||||||
|
|
||||||
const reserve = await getReserveAddressFromSymbol(reserveSymbol);
|
const reserves: tEthereumAddress[] = [];
|
||||||
const amountToDelegate = await convertToCurrencyDecimals(reserve, amount);
|
const amountsToDelegate: tEthereumAddress[] = [];
|
||||||
|
for (const reserveSymbol of reserveSymbols) {
|
||||||
|
const newLength = reserves.push(await getReserveAddressFromSymbol(reserveSymbol));
|
||||||
|
amountsToDelegate.push(
|
||||||
|
await (
|
||||||
|
await convertToCurrencyDecimals(reserves[newLength - 1], amounts[newLength - 1])
|
||||||
|
).toString()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const delegateAllowancePromise = pool
|
const delegateAllowancePromise = pool
|
||||||
.connect(user.signer)
|
.connect(user.signer)
|
||||||
.delegateBorrowAllowance(reserve, receiver, interestRateMode, amountToDelegate.toString());
|
.delegateBorrowAllowance(reserves, receiver, interestRateModes, amountsToDelegate);
|
||||||
if (expectedResult === 'revert') {
|
if (expectedResult === 'revert') {
|
||||||
await expect(delegateAllowancePromise, revertMessage).to.be.reverted;
|
await expect(delegateAllowancePromise, revertMessage).to.be.reverted;
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
await delegateAllowancePromise;
|
await delegateAllowancePromise;
|
||||||
expect(
|
for (const [i, reserve] of reserves.entries()) {
|
||||||
(await pool.getBorrowAllowance(user.address, receiver, reserve, interestRateMode)).toString()
|
expect(
|
||||||
).to.be.equal(amountToDelegate.toString(), 'borrowAllowance are set incorrectly');
|
(
|
||||||
|
await pool.getBorrowAllowance(user.address, receiver, reserve, interestRateModes[i])
|
||||||
|
).toString()
|
||||||
|
).to.be.equal(amountsToDelegate[i], 'borrowAllowance are set incorrectly');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -121,9 +121,9 @@ const executeAction = async (action: Action, users: SignerWithAddress[], testEnv
|
||||||
}
|
}
|
||||||
|
|
||||||
await delegateBorrowAllowance(
|
await delegateBorrowAllowance(
|
||||||
reserve,
|
[reserve],
|
||||||
amount,
|
[amount],
|
||||||
rateMode,
|
[rateMode],
|
||||||
user,
|
user,
|
||||||
toUser,
|
toUser,
|
||||||
expected,
|
expected,
|
||||||
|
|
|
@ -17,11 +17,11 @@ const {expect} = chai;
|
||||||
|
|
||||||
makeSuite('LendingPool liquidation - liquidator receiving aToken', (testEnv) => {
|
makeSuite('LendingPool liquidation - liquidator receiving aToken', (testEnv) => {
|
||||||
const {
|
const {
|
||||||
HEALTH_FACTOR_NOT_BELOW_THRESHOLD,
|
LPCM_HEALTH_FACTOR_NOT_BELOW_THRESHOLD,
|
||||||
INVALID_HF,
|
INVALID_HF,
|
||||||
SPECIFIED_CURRENCY_NOT_BORROWED_BY_USER,
|
LPCM_SPECIFIED_CURRENCY_NOT_BORROWED_BY_USER,
|
||||||
COLLATERAL_CANNOT_BE_LIQUIDATED,
|
LPCM_COLLATERAL_CANNOT_BE_LIQUIDATED,
|
||||||
IS_PAUSED,
|
P_IS_PAUSED,
|
||||||
} = ProtocolErrors;
|
} = ProtocolErrors;
|
||||||
|
|
||||||
it('LIQUIDATION - Deposits WETH, borrows DAI/Check liquidation fails because health factor is above 1', async () => {
|
it('LIQUIDATION - Deposits WETH, borrows DAI/Check liquidation fails because health factor is above 1', async () => {
|
||||||
|
@ -80,7 +80,7 @@ makeSuite('LendingPool liquidation - liquidator receiving aToken', (testEnv) =>
|
||||||
//someone tries to liquidate user 2
|
//someone tries to liquidate user 2
|
||||||
await expect(
|
await expect(
|
||||||
pool.liquidationCall(weth.address, dai.address, borrower.address, 1, true)
|
pool.liquidationCall(weth.address, dai.address, borrower.address, 1, true)
|
||||||
).to.be.revertedWith(HEALTH_FACTOR_NOT_BELOW_THRESHOLD);
|
).to.be.revertedWith(LPCM_HEALTH_FACTOR_NOT_BELOW_THRESHOLD);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('LIQUIDATION - Drop the health factor below 1', async () => {
|
it('LIQUIDATION - Drop the health factor below 1', async () => {
|
||||||
|
@ -105,7 +105,7 @@ makeSuite('LendingPool liquidation - liquidator receiving aToken', (testEnv) =>
|
||||||
//user 2 tries to borrow
|
//user 2 tries to borrow
|
||||||
await expect(
|
await expect(
|
||||||
pool.liquidationCall(weth.address, weth.address, borrower.address, oneEther.toString(), true)
|
pool.liquidationCall(weth.address, weth.address, borrower.address, oneEther.toString(), true)
|
||||||
).revertedWith(SPECIFIED_CURRENCY_NOT_BORROWED_BY_USER);
|
).revertedWith(LPCM_SPECIFIED_CURRENCY_NOT_BORROWED_BY_USER);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('LIQUIDATION - Tries to liquidate a different collateral than the borrower collateral', async () => {
|
it('LIQUIDATION - Tries to liquidate a different collateral than the borrower collateral', async () => {
|
||||||
|
@ -114,7 +114,7 @@ makeSuite('LendingPool liquidation - liquidator receiving aToken', (testEnv) =>
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
pool.liquidationCall(dai.address, dai.address, borrower.address, oneEther.toString(), true)
|
pool.liquidationCall(dai.address, dai.address, borrower.address, oneEther.toString(), true)
|
||||||
).revertedWith(COLLATERAL_CANNOT_BE_LIQUIDATED);
|
).revertedWith(LPCM_COLLATERAL_CANNOT_BE_LIQUIDATED);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('LIQUIDATION - Liquidates the borrow', async () => {
|
it('LIQUIDATION - Liquidates the borrow', async () => {
|
||||||
|
|
|
@ -13,8 +13,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => {
|
||||||
let _mockFlashLoanReceiver = {} as MockFlashLoanReceiver;
|
let _mockFlashLoanReceiver = {} as MockFlashLoanReceiver;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
IS_PAUSED,
|
P_IS_PAUSED,
|
||||||
TRANSFER_NOT_ALLOWED,
|
|
||||||
INVALID_FROM_BALANCE_AFTER_TRANSFER,
|
INVALID_FROM_BALANCE_AFTER_TRANSFER,
|
||||||
INVALID_TO_BALANCE_AFTER_TRANSFER,
|
INVALID_TO_BALANCE_AFTER_TRANSFER,
|
||||||
} = ProtocolErrors;
|
} = ProtocolErrors;
|
||||||
|
@ -45,7 +44,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => {
|
||||||
// User 0 tries the transfer to User 1
|
// User 0 tries the transfer to User 1
|
||||||
await expect(
|
await expect(
|
||||||
aDai.connect(users[0].signer).transfer(users[1].address, amountDAItoDeposit)
|
aDai.connect(users[0].signer).transfer(users[1].address, amountDAItoDeposit)
|
||||||
).to.revertedWith(IS_PAUSED);
|
).to.revertedWith(P_IS_PAUSED);
|
||||||
|
|
||||||
const pausedFromBalance = await aDai.balanceOf(users[0].address);
|
const pausedFromBalance = await aDai.balanceOf(users[0].address);
|
||||||
const pausedToBalance = await aDai.balanceOf(users[1].address);
|
const pausedToBalance = await aDai.balanceOf(users[1].address);
|
||||||
|
@ -92,7 +91,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => {
|
||||||
await configurator.setPoolPause(true);
|
await configurator.setPoolPause(true);
|
||||||
await expect(
|
await expect(
|
||||||
pool.connect(users[0].signer).deposit(dai.address, amountDAItoDeposit, users[0].address, '0')
|
pool.connect(users[0].signer).deposit(dai.address, amountDAItoDeposit, users[0].address, '0')
|
||||||
).to.revertedWith(IS_PAUSED);
|
).to.revertedWith(P_IS_PAUSED);
|
||||||
|
|
||||||
// Configurator unpauses the pool
|
// Configurator unpauses the pool
|
||||||
await configurator.setPoolPause(false);
|
await configurator.setPoolPause(false);
|
||||||
|
@ -117,7 +116,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => {
|
||||||
// user tries to burn
|
// user tries to burn
|
||||||
await expect(
|
await expect(
|
||||||
pool.connect(users[0].signer).withdraw(dai.address, amountDAItoDeposit, users[0].address)
|
pool.connect(users[0].signer).withdraw(dai.address, amountDAItoDeposit, users[0].address)
|
||||||
).to.revertedWith(IS_PAUSED);
|
).to.revertedWith(P_IS_PAUSED);
|
||||||
|
|
||||||
// Configurator unpauses the pool
|
// Configurator unpauses the pool
|
||||||
await configurator.setPoolPause(false);
|
await configurator.setPoolPause(false);
|
||||||
|
@ -133,8 +132,8 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => {
|
||||||
|
|
||||||
// Try to execute liquidation
|
// Try to execute liquidation
|
||||||
await expect(
|
await expect(
|
||||||
pool.connect(user.signer).delegateBorrowAllowance(dai.address, toUser.address, '1', '1')
|
pool.connect(user.signer).delegateBorrowAllowance([dai.address], toUser.address, ['1'], ['1'])
|
||||||
).revertedWith(IS_PAUSED);
|
).revertedWith(P_IS_PAUSED);
|
||||||
|
|
||||||
// Unpause the pool
|
// Unpause the pool
|
||||||
await configurator.setPoolPause(false);
|
await configurator.setPoolPause(false);
|
||||||
|
@ -150,7 +149,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => {
|
||||||
// Try to execute liquidation
|
// Try to execute liquidation
|
||||||
await expect(
|
await expect(
|
||||||
pool.connect(user.signer).borrow(dai.address, '1', '1', '0', user.address)
|
pool.connect(user.signer).borrow(dai.address, '1', '1', '0', user.address)
|
||||||
).revertedWith(IS_PAUSED);
|
).revertedWith(P_IS_PAUSED);
|
||||||
|
|
||||||
// Unpause the pool
|
// Unpause the pool
|
||||||
await configurator.setPoolPause(false);
|
await configurator.setPoolPause(false);
|
||||||
|
@ -165,7 +164,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => {
|
||||||
|
|
||||||
// Try to execute liquidation
|
// Try to execute liquidation
|
||||||
await expect(pool.connect(user.signer).repay(dai.address, '1', '1', user.address)).revertedWith(
|
await expect(pool.connect(user.signer).repay(dai.address, '1', '1', user.address)).revertedWith(
|
||||||
IS_PAUSED
|
P_IS_PAUSED
|
||||||
);
|
);
|
||||||
|
|
||||||
// Unpause the pool
|
// Unpause the pool
|
||||||
|
@ -196,7 +195,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => {
|
||||||
'0x10',
|
'0x10',
|
||||||
'0'
|
'0'
|
||||||
)
|
)
|
||||||
).revertedWith(IS_PAUSED);
|
).revertedWith(P_IS_PAUSED);
|
||||||
|
|
||||||
// Unpause pool
|
// Unpause pool
|
||||||
await configurator.setPoolPause(false);
|
await configurator.setPoolPause(false);
|
||||||
|
@ -277,7 +276,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => {
|
||||||
// Do liquidation
|
// Do liquidation
|
||||||
expect(
|
expect(
|
||||||
pool.liquidationCall(weth.address, usdc.address, borrower.address, amountToLiquidate, true)
|
pool.liquidationCall(weth.address, usdc.address, borrower.address, amountToLiquidate, true)
|
||||||
).revertedWith(IS_PAUSED);
|
).revertedWith(P_IS_PAUSED);
|
||||||
|
|
||||||
// Unpause pool
|
// Unpause pool
|
||||||
await configurator.setPoolPause(false);
|
await configurator.setPoolPause(false);
|
||||||
|
@ -306,7 +305,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => {
|
||||||
// Try to repay
|
// Try to repay
|
||||||
await expect(
|
await expect(
|
||||||
pool.connect(user.signer).swapBorrowRateMode(usdc.address, RateMode.Stable)
|
pool.connect(user.signer).swapBorrowRateMode(usdc.address, RateMode.Stable)
|
||||||
).revertedWith(IS_PAUSED);
|
).revertedWith(P_IS_PAUSED);
|
||||||
|
|
||||||
// Unpause pool
|
// Unpause pool
|
||||||
await configurator.setPoolPause(false);
|
await configurator.setPoolPause(false);
|
||||||
|
@ -320,7 +319,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => {
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
pool.connect(user.signer).rebalanceStableBorrowRate(dai.address, user.address)
|
pool.connect(user.signer).rebalanceStableBorrowRate(dai.address, user.address)
|
||||||
).revertedWith(IS_PAUSED);
|
).revertedWith(P_IS_PAUSED);
|
||||||
|
|
||||||
// Unpause pool
|
// Unpause pool
|
||||||
await configurator.setPoolPause(false);
|
await configurator.setPoolPause(false);
|
||||||
|
@ -340,7 +339,7 @@ makeSuite('Pausable Pool', (testEnv: TestEnv) => {
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
pool.connect(user.signer).setUserUseReserveAsCollateral(weth.address, false)
|
pool.connect(user.signer).setUserUseReserveAsCollateral(weth.address, false)
|
||||||
).revertedWith(IS_PAUSED);
|
).revertedWith(P_IS_PAUSED);
|
||||||
|
|
||||||
// Unpause pool
|
// Unpause pool
|
||||||
await configurator.setPoolPause(false);
|
await configurator.setPoolPause(false);
|
||||||
|
|
|
@ -3,9 +3,10 @@ import {makeSuite, TestEnv} from './helpers/make-suite';
|
||||||
import {ProtocolErrors, eContractid} from '../helpers/types';
|
import {ProtocolErrors, eContractid} from '../helpers/types';
|
||||||
import {getContract} from '../helpers/contracts-helpers';
|
import {getContract} from '../helpers/contracts-helpers';
|
||||||
import {StableDebtToken} from '../types/StableDebtToken';
|
import {StableDebtToken} from '../types/StableDebtToken';
|
||||||
|
import {getStableDebtToken} from '../helpers/contracts-getters';
|
||||||
|
|
||||||
makeSuite('Stable debt token tests', (testEnv: TestEnv) => {
|
makeSuite('Stable debt token tests', (testEnv: TestEnv) => {
|
||||||
const {CALLER_MUST_BE_LENDING_POOL} = ProtocolErrors;
|
const {AT_CALLER_MUST_BE_LENDING_POOL} = ProtocolErrors;
|
||||||
|
|
||||||
it('Tries to invoke mint not being the LendingPool', async () => {
|
it('Tries to invoke mint not being the LendingPool', async () => {
|
||||||
const {deployer, pool, dai, helpersContract} = testEnv;
|
const {deployer, pool, dai, helpersContract} = testEnv;
|
||||||
|
@ -13,13 +14,10 @@ makeSuite('Stable debt token tests', (testEnv: TestEnv) => {
|
||||||
const daiStableDebtTokenAddress = (await helpersContract.getReserveTokensAddresses(dai.address))
|
const daiStableDebtTokenAddress = (await helpersContract.getReserveTokensAddresses(dai.address))
|
||||||
.stableDebtTokenAddress;
|
.stableDebtTokenAddress;
|
||||||
|
|
||||||
const stableDebtContract = await getContract<StableDebtToken>(
|
const stableDebtContract = await getStableDebtToken(daiStableDebtTokenAddress);
|
||||||
eContractid.StableDebtToken,
|
|
||||||
daiStableDebtTokenAddress
|
|
||||||
);
|
|
||||||
|
|
||||||
await expect(stableDebtContract.mint(deployer.address, '1', '1')).to.be.revertedWith(
|
await expect(stableDebtContract.mint(deployer.address, '1', '1')).to.be.revertedWith(
|
||||||
CALLER_MUST_BE_LENDING_POOL
|
AT_CALLER_MUST_BE_LENDING_POOL
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -29,16 +27,13 @@ makeSuite('Stable debt token tests', (testEnv: TestEnv) => {
|
||||||
const daiStableDebtTokenAddress = (await helpersContract.getReserveTokensAddresses(dai.address))
|
const daiStableDebtTokenAddress = (await helpersContract.getReserveTokensAddresses(dai.address))
|
||||||
.stableDebtTokenAddress;
|
.stableDebtTokenAddress;
|
||||||
|
|
||||||
const stableDebtContract = await getContract<StableDebtToken>(
|
const stableDebtContract = await getStableDebtToken(daiStableDebtTokenAddress);
|
||||||
eContractid.StableDebtToken,
|
|
||||||
daiStableDebtTokenAddress
|
|
||||||
);
|
|
||||||
|
|
||||||
const name = await stableDebtContract.name();
|
const name = await stableDebtContract.name();
|
||||||
|
|
||||||
expect(name).to.be.equal('Aave stable debt bearing DAI');
|
expect(name).to.be.equal('Aave stable debt bearing DAI');
|
||||||
await expect(stableDebtContract.burn(deployer.address, '1')).to.be.revertedWith(
|
await expect(stableDebtContract.burn(deployer.address, '1')).to.be.revertedWith(
|
||||||
CALLER_MUST_BE_LENDING_POOL
|
AT_CALLER_MUST_BE_LENDING_POOL
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -6,17 +6,27 @@ import {MockAToken} from '../types/MockAToken';
|
||||||
import {MockStableDebtToken} from '../types/MockStableDebtToken';
|
import {MockStableDebtToken} from '../types/MockStableDebtToken';
|
||||||
import {MockVariableDebtToken} from '../types/MockVariableDebtToken';
|
import {MockVariableDebtToken} from '../types/MockVariableDebtToken';
|
||||||
import {ZERO_ADDRESS} from '../helpers/constants';
|
import {ZERO_ADDRESS} from '../helpers/constants';
|
||||||
import {getAToken} from '../helpers/contracts-getters';
|
import {
|
||||||
|
getAToken,
|
||||||
|
getMockStableDebtToken,
|
||||||
|
getMockVariableDebtToken,
|
||||||
|
getVariableDebtToken,
|
||||||
|
} from '../helpers/contracts-getters';
|
||||||
|
import {
|
||||||
|
deployMockAToken,
|
||||||
|
deployMockStableDebtToken,
|
||||||
|
deployMockVariableDebtToken,
|
||||||
|
} from '../helpers/contracts-deployments';
|
||||||
|
|
||||||
makeSuite('Upgradeability', (testEnv: TestEnv) => {
|
makeSuite('Upgradeability', (testEnv: TestEnv) => {
|
||||||
const {CALLER_NOT_AAVE_ADMIN} = ProtocolErrors;
|
const {LPC_CALLER_NOT_AAVE_ADMIN} = ProtocolErrors;
|
||||||
let newATokenAddress: string;
|
let newATokenAddress: string;
|
||||||
let newStableTokenAddress: string;
|
let newStableTokenAddress: string;
|
||||||
let newVariableTokenAddress: string;
|
let newVariableTokenAddress: string;
|
||||||
|
|
||||||
before('deploying instances', async () => {
|
before('deploying instances', async () => {
|
||||||
const {dai, pool} = testEnv;
|
const {dai, pool} = testEnv;
|
||||||
const aTokenInstance = await deployContract<MockAToken>(eContractid.MockAToken, [
|
const aTokenInstance = await deployMockAToken([
|
||||||
pool.address,
|
pool.address,
|
||||||
dai.address,
|
dai.address,
|
||||||
ZERO_ADDRESS,
|
ZERO_ADDRESS,
|
||||||
|
@ -25,27 +35,21 @@ makeSuite('Upgradeability', (testEnv: TestEnv) => {
|
||||||
ZERO_ADDRESS,
|
ZERO_ADDRESS,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const stableDebtTokenInstance = await deployContract<MockStableDebtToken>(
|
const stableDebtTokenInstance = await deployMockStableDebtToken([
|
||||||
eContractid.MockStableDebtToken,
|
pool.address,
|
||||||
[
|
dai.address,
|
||||||
pool.address,
|
'Aave stable debt bearing DAI updated',
|
||||||
dai.address,
|
'stableDebtDAI',
|
||||||
'Aave stable debt bearing DAI updated',
|
ZERO_ADDRESS,
|
||||||
'stableDebtDAI',
|
]);
|
||||||
ZERO_ADDRESS,
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
const variableDebtTokenInstance = await deployContract<MockVariableDebtToken>(
|
const variableDebtTokenInstance = await deployMockVariableDebtToken([
|
||||||
eContractid.MockVariableDebtToken,
|
pool.address,
|
||||||
[
|
dai.address,
|
||||||
pool.address,
|
'Aave variable debt bearing DAI updated',
|
||||||
dai.address,
|
'variableDebtDAI',
|
||||||
'Aave variable debt bearing DAI updated',
|
ZERO_ADDRESS,
|
||||||
'variableDebtDAI',
|
]);
|
||||||
ZERO_ADDRESS,
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
newATokenAddress = aTokenInstance.address;
|
newATokenAddress = aTokenInstance.address;
|
||||||
newVariableTokenAddress = variableDebtTokenInstance.address;
|
newVariableTokenAddress = variableDebtTokenInstance.address;
|
||||||
|
@ -57,7 +61,7 @@ makeSuite('Upgradeability', (testEnv: TestEnv) => {
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
configurator.connect(users[1].signer).updateAToken(dai.address, newATokenAddress)
|
configurator.connect(users[1].signer).updateAToken(dai.address, newATokenAddress)
|
||||||
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
|
).to.be.revertedWith(LPC_CALLER_NOT_AAVE_ADMIN);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Upgrades the DAI Atoken implementation ', async () => {
|
it('Upgrades the DAI Atoken implementation ', async () => {
|
||||||
|
@ -79,7 +83,7 @@ makeSuite('Upgradeability', (testEnv: TestEnv) => {
|
||||||
configurator
|
configurator
|
||||||
.connect(users[1].signer)
|
.connect(users[1].signer)
|
||||||
.updateStableDebtToken(dai.address, newStableTokenAddress)
|
.updateStableDebtToken(dai.address, newStableTokenAddress)
|
||||||
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
|
).to.be.revertedWith(LPC_CALLER_NOT_AAVE_ADMIN);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Upgrades the DAI stable debt token implementation ', async () => {
|
it('Upgrades the DAI stable debt token implementation ', async () => {
|
||||||
|
@ -91,10 +95,7 @@ makeSuite('Upgradeability', (testEnv: TestEnv) => {
|
||||||
|
|
||||||
const {stableDebtTokenAddress} = await helpersContract.getReserveTokensAddresses(dai.address);
|
const {stableDebtTokenAddress} = await helpersContract.getReserveTokensAddresses(dai.address);
|
||||||
|
|
||||||
const debtToken = await getContract<MockStableDebtToken>(
|
const debtToken = await getMockStableDebtToken(stableDebtTokenAddress);
|
||||||
eContractid.MockStableDebtToken,
|
|
||||||
stableDebtTokenAddress
|
|
||||||
);
|
|
||||||
|
|
||||||
const tokenName = await debtToken.name();
|
const tokenName = await debtToken.name();
|
||||||
|
|
||||||
|
@ -108,7 +109,7 @@ makeSuite('Upgradeability', (testEnv: TestEnv) => {
|
||||||
configurator
|
configurator
|
||||||
.connect(users[1].signer)
|
.connect(users[1].signer)
|
||||||
.updateVariableDebtToken(dai.address, newVariableTokenAddress)
|
.updateVariableDebtToken(dai.address, newVariableTokenAddress)
|
||||||
).to.be.revertedWith(CALLER_NOT_AAVE_ADMIN);
|
).to.be.revertedWith(LPC_CALLER_NOT_AAVE_ADMIN);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Upgrades the DAI variable debt token implementation ', async () => {
|
it('Upgrades the DAI variable debt token implementation ', async () => {
|
||||||
|
@ -120,10 +121,7 @@ makeSuite('Upgradeability', (testEnv: TestEnv) => {
|
||||||
|
|
||||||
const {variableDebtTokenAddress} = await helpersContract.getReserveTokensAddresses(dai.address);
|
const {variableDebtTokenAddress} = await helpersContract.getReserveTokensAddresses(dai.address);
|
||||||
|
|
||||||
const debtToken = await getContract<MockStableDebtToken>(
|
const debtToken = await getMockVariableDebtToken(variableDebtTokenAddress);
|
||||||
eContractid.MockStableDebtToken,
|
|
||||||
variableDebtTokenAddress
|
|
||||||
);
|
|
||||||
|
|
||||||
const tokenName = await debtToken.name();
|
const tokenName = await debtToken.name();
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
import {expect} from 'chai';
|
import {expect} from 'chai';
|
||||||
import {makeSuite, TestEnv} from './helpers/make-suite';
|
import {makeSuite, TestEnv} from './helpers/make-suite';
|
||||||
import {ProtocolErrors, TokenContractId, eContractid} from '../helpers/types';
|
import {ProtocolErrors, TokenContractId, eContractid} from '../helpers/types';
|
||||||
import {getContract} from '../helpers/contracts-helpers';
|
import {getVariableDebtToken} from '../helpers/contracts-getters';
|
||||||
import {VariableDebtToken} from '../types/VariableDebtToken';
|
|
||||||
|
|
||||||
makeSuite('Variable debt token tests', (testEnv: TestEnv) => {
|
makeSuite('Variable debt token tests', (testEnv: TestEnv) => {
|
||||||
const {CALLER_MUST_BE_LENDING_POOL} = ProtocolErrors;
|
const {AT_CALLER_MUST_BE_LENDING_POOL} = ProtocolErrors;
|
||||||
|
|
||||||
it('Tries to invoke mint not being the LendingPool', async () => {
|
it('Tries to invoke mint not being the LendingPool', async () => {
|
||||||
const {deployer, pool, dai, helpersContract} = testEnv;
|
const {deployer, pool, dai, helpersContract} = testEnv;
|
||||||
|
@ -14,13 +13,10 @@ makeSuite('Variable debt token tests', (testEnv: TestEnv) => {
|
||||||
await helpersContract.getReserveTokensAddresses(dai.address)
|
await helpersContract.getReserveTokensAddresses(dai.address)
|
||||||
).variableDebtTokenAddress;
|
).variableDebtTokenAddress;
|
||||||
|
|
||||||
const variableDebtContract = await getContract<VariableDebtToken>(
|
const variableDebtContract = await getVariableDebtToken(daiVariableDebtTokenAddress);
|
||||||
eContractid.VariableDebtToken,
|
|
||||||
daiVariableDebtTokenAddress
|
|
||||||
);
|
|
||||||
|
|
||||||
await expect(variableDebtContract.mint(deployer.address, '1', '1')).to.be.revertedWith(
|
await expect(variableDebtContract.mint(deployer.address, '1', '1')).to.be.revertedWith(
|
||||||
CALLER_MUST_BE_LENDING_POOL
|
AT_CALLER_MUST_BE_LENDING_POOL
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -31,13 +27,10 @@ makeSuite('Variable debt token tests', (testEnv: TestEnv) => {
|
||||||
await helpersContract.getReserveTokensAddresses(dai.address)
|
await helpersContract.getReserveTokensAddresses(dai.address)
|
||||||
).variableDebtTokenAddress;
|
).variableDebtTokenAddress;
|
||||||
|
|
||||||
const variableDebtContract = await getContract<VariableDebtToken>(
|
const variableDebtContract = await getVariableDebtToken(daiVariableDebtTokenAddress);
|
||||||
eContractid.VariableDebtToken,
|
|
||||||
daiVariableDebtTokenAddress
|
|
||||||
);
|
|
||||||
|
|
||||||
await expect(variableDebtContract.burn(deployer.address, '1', '1')).to.be.revertedWith(
|
await expect(variableDebtContract.burn(deployer.address, '1', '1')).to.be.revertedWith(
|
||||||
CALLER_MUST_BE_LENDING_POOL
|
AT_CALLER_MUST_BE_LENDING_POOL
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user