mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
feat: added drop reserve main capability
This commit is contained in:
parent
7da7c1a9ce
commit
9c7458242b
|
@ -396,6 +396,8 @@ interface ILendingPool {
|
||||||
address interestRateStrategyAddress
|
address interestRateStrategyAddress
|
||||||
) external;
|
) external;
|
||||||
|
|
||||||
|
function dropReserve(address reserve) external;
|
||||||
|
|
||||||
function setReserveInterestRateStrategyAddress(address reserve, address rateStrategyAddress)
|
function setReserveInterestRateStrategyAddress(address reserve, address rateStrategyAddress)
|
||||||
external;
|
external;
|
||||||
|
|
||||||
|
|
|
@ -665,15 +665,29 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Returns the list of the initialized reserves
|
* @dev Returns the list of the initialized reserves, does not contain dropped reserves
|
||||||
**/
|
**/
|
||||||
function getReservesList() external view override returns (address[] memory) {
|
function getReservesList() external view override returns (address[] memory) {
|
||||||
address[] memory _activeReserves = new address[](_reservesCount);
|
uint256 reserveListCount = _reservesCount;
|
||||||
|
uint256 droppedReservesCount = 0;
|
||||||
|
address[] memory reserves = new address[](reserveListCount);
|
||||||
|
|
||||||
for (uint256 i = 0; i < _reservesCount; i++) {
|
for (uint256 i = 0; i < reserveListCount; i++) {
|
||||||
_activeReserves[i] = _reservesList[i];
|
if (_reservesList[i] != address(0)) {
|
||||||
|
reserves[i - droppedReservesCount] = _reservesList[i];
|
||||||
|
} else {
|
||||||
|
droppedReservesCount++;
|
||||||
}
|
}
|
||||||
return _activeReserves;
|
}
|
||||||
|
|
||||||
|
if (droppedReservesCount == 0) return reserves;
|
||||||
|
|
||||||
|
address[] memory undroppedReserves = new address[](reserveListCount - droppedReservesCount);
|
||||||
|
for (uint256 i = 0; i < reserveListCount - droppedReservesCount; i++) {
|
||||||
|
undroppedReserves[i] = reserves[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return undroppedReserves;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -783,6 +797,16 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
|
||||||
_addReserveToList(asset);
|
_addReserveToList(asset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Drop a reserve
|
||||||
|
* - Only callable by the LendingPoolConfigurator contract
|
||||||
|
* @param asset The address of the underlying asset of the reserve
|
||||||
|
**/
|
||||||
|
function dropReserve(address asset) external override onlyLendingPoolConfigurator {
|
||||||
|
_reserves[asset].dropReserve();
|
||||||
|
_removeReserveFromList(asset);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Updates the address of the interest rate strategy contract
|
* @dev Updates the address of the interest rate strategy contract
|
||||||
* - Only callable by the LendingPoolConfigurator contract
|
* - Only callable by the LendingPoolConfigurator contract
|
||||||
|
@ -1067,7 +1091,7 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
|
||||||
return paybackAmount;
|
return paybackAmount;
|
||||||
}
|
}
|
||||||
|
|
||||||
function _addReserveToList(address asset) internal {
|
function _addReserveToList(address asset) internal returns (uint8) {
|
||||||
uint256 reservesCount = _reservesCount;
|
uint256 reservesCount = _reservesCount;
|
||||||
|
|
||||||
require(reservesCount < _maxNumberOfReserves, Errors.LP_NO_MORE_RESERVES_ALLOWED);
|
require(reservesCount < _maxNumberOfReserves, Errors.LP_NO_MORE_RESERVES_ALLOWED);
|
||||||
|
@ -1075,10 +1099,18 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage
|
||||||
bool reserveAlreadyAdded = _reserves[asset].id != 0 || _reservesList[0] == asset;
|
bool reserveAlreadyAdded = _reserves[asset].id != 0 || _reservesList[0] == asset;
|
||||||
|
|
||||||
if (!reserveAlreadyAdded) {
|
if (!reserveAlreadyAdded) {
|
||||||
_reserves[asset].id = uint8(reservesCount);
|
for (uint8 i = 0; i <= reservesCount; i++) {
|
||||||
_reservesList[reservesCount] = asset;
|
if (_reservesList[i] == address(0)) {
|
||||||
|
_reserves[asset].id = i;
|
||||||
|
_reservesList[i] = asset;
|
||||||
_reservesCount = reservesCount + 1;
|
_reservesCount = reservesCount + 1;
|
||||||
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function _removeReserveFromList(address asset) internal {
|
||||||
|
_reservesList[_reserves[asset].id] = address(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -161,6 +161,10 @@ contract LendingPoolConfigurator is VersionedInitializable, ILendingPoolConfigur
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function dropReserve(address asset) external onlyPoolAdmin {
|
||||||
|
pool.dropReserve(asset);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Updates the aToken implementation for the reserve
|
* @dev Updates the aToken implementation for the reserve
|
||||||
**/
|
**/
|
||||||
|
|
|
@ -109,6 +109,9 @@ library Errors {
|
||||||
string public constant LPC_CALLER_NOT_EMERGENCY_OR_POOL_ADMIN = '85';
|
string public constant LPC_CALLER_NOT_EMERGENCY_OR_POOL_ADMIN = '85';
|
||||||
string public constant VL_RESERVE_PAUSED = '86';
|
string public constant VL_RESERVE_PAUSED = '86';
|
||||||
string public constant LPC_CALLER_NOT_RISK_OR_POOL_ADMIN = '87';
|
string public constant LPC_CALLER_NOT_RISK_OR_POOL_ADMIN = '87';
|
||||||
|
string public constant RL_ATOKEN_SUPPLY_NOT_NULL = '88';
|
||||||
|
string public constant RL_STABLE_DEBT_NOT_NULL = '89';
|
||||||
|
string public constant RL_VARIABLE_DEBT_SUPPLY_NOT_NULL = '90';
|
||||||
|
|
||||||
enum CollateralManagerErrors {
|
enum CollateralManagerErrors {
|
||||||
NO_ERROR,
|
NO_ERROR,
|
||||||
|
|
|
@ -178,6 +178,23 @@ library ReserveLogic {
|
||||||
reserve.interestRateStrategyAddress = interestRateStrategyAddress;
|
reserve.interestRateStrategyAddress = interestRateStrategyAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev drop a reserve
|
||||||
|
* @param reserve The reserve object
|
||||||
|
**/
|
||||||
|
function dropReserve(DataTypes.ReserveData storage reserve) external {
|
||||||
|
require(IERC20(reserve.aTokenAddress).totalSupply() == 0, Errors.RL_ATOKEN_SUPPLY_NOT_NULL);
|
||||||
|
require(
|
||||||
|
IERC20(reserve.stableDebtTokenAddress).totalSupply() == 0,
|
||||||
|
Errors.RL_STABLE_DEBT_NOT_NULL
|
||||||
|
);
|
||||||
|
require(
|
||||||
|
IERC20(reserve.variableDebtTokenAddress).totalSupply() == 0,
|
||||||
|
Errors.RL_VARIABLE_DEBT_SUPPLY_NOT_NULL
|
||||||
|
);
|
||||||
|
reserve.id = type(uint8).max;
|
||||||
|
}
|
||||||
|
|
||||||
struct UpdateInterestRatesLocalVars {
|
struct UpdateInterestRatesLocalVars {
|
||||||
address stableDebtTokenAddress;
|
address stableDebtTokenAddress;
|
||||||
uint256 availableLiquidity;
|
uint256 availableLiquidity;
|
||||||
|
|
|
@ -119,7 +119,7 @@ library ValidationLogic {
|
||||||
mapping(uint256 => address) storage reserves,
|
mapping(uint256 => address) storage reserves,
|
||||||
uint256 reservesCount,
|
uint256 reservesCount,
|
||||||
address oracle
|
address oracle
|
||||||
) internal view {
|
) external view {
|
||||||
ValidateBorrowLocalVars memory vars;
|
ValidateBorrowLocalVars memory vars;
|
||||||
|
|
||||||
(
|
(
|
||||||
|
|
|
@ -267,6 +267,7 @@ const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => {
|
||||||
);
|
);
|
||||||
|
|
||||||
await configureReservesByHelper(reservesParams, allReservesAddresses, testHelpers, admin);
|
await configureReservesByHelper(reservesParams, allReservesAddresses, testHelpers, admin);
|
||||||
|
lendingPoolConfiguratorProxy.dropReserve(mockTokens.KNC.address);
|
||||||
|
|
||||||
const collateralManager = await deployLendingPoolCollateralManager();
|
const collateralManager = await deployLendingPoolCollateralManager();
|
||||||
await waitForTx(
|
await waitForTx(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user