From 4a4073f1a9ac3e617ff5be5ef09d0ec574cb709d Mon Sep 17 00:00:00 2001 From: emilio Date: Tue, 18 Aug 2020 02:16:46 +0200 Subject: [PATCH] Added function to update stable/variable debt tokens --- .../lendingpool/LendingPoolConfigurator.sol | 107 ++++++++++++++++-- tests.log | 0 2 files changed, 100 insertions(+), 7 deletions(-) create mode 100644 tests.log diff --git a/contracts/lendingpool/LendingPoolConfigurator.sol b/contracts/lendingpool/LendingPoolConfigurator.sol index a13e9f4c..8182681c 100644 --- a/contracts/lendingpool/LendingPoolConfigurator.sol +++ b/contracts/lendingpool/LendingPoolConfigurator.sol @@ -141,6 +141,32 @@ contract LendingPoolConfigurator is VersionedInitializable { **/ event ReserveInterestRateStrategyChanged(address _reserve, address _strategy); + + /** + * @dev emitted when an aToken implementation is upgraded + * @param _reserve the address of the reserve + * @param _proxy the aToken proxy address + * @param _implementation the new aToken implementation + **/ + event ATokenUpgraded(address _reserve, address _proxy, address _implementation); + + /** + * @dev emitted when the implementation of a stable debt token is upgraded + * @param _reserve the address of the reserve + * @param _proxy the stable debt token proxy address + * @param _implementation the new aToken implementation + **/ + event StableDebtTokenUpgraded(address _reserve, address _proxy, address _implementation); + + /** + * @dev emitted when the implementation of a variable debt token is upgraded + * @param _reserve the address of the reserve + * @param _proxy the variable debt token proxy address + * @param _implementation the new aToken implementation + **/ + event VariableDebtTokenUpgraded(address _reserve, address _proxy, address _implementation); + + LendingPoolAddressesProvider public poolAddressesProvider; LendingPool public pool; @@ -240,18 +266,64 @@ contract LendingPoolConfigurator is VersionedInitializable { (uint256 decimals, , , , , , , , , ) = pool.getReserveConfigurationData(_reserve); - InitializableAdminUpgradeabilityProxy aTokenProxy = InitializableAdminUpgradeabilityProxy( - payable(aTokenAddress) - ); - - bytes memory params = abi.encodeWithSignature( - 'initialize(uint8,string,string)', + _upgradeImplementation( + aTokenAddress, + _implementation, uint8(decimals), IERC20Detailed(_implementation).name(), IERC20Detailed(_implementation).symbol() ); - aTokenProxy.upgradeToAndCall(_implementation, params); + emit ATokenUpgraded(_reserve, aTokenAddress, _implementation); + } + + /** + * @dev updates the stable debt token implementation for the _reserve + * @param _reserve the address of the reserve to be updated + * @param _implementation the address of the new aToken implementation + **/ + function updateStableDebtToken(address _reserve, address _implementation) + external + onlyLendingPoolManager + { + (, address stableDebtToken, ) = pool.getReserveTokensAddresses(_reserve); + + (uint256 decimals, , , , , , , , , ) = pool.getReserveConfigurationData(_reserve); + + _upgradeImplementation( + stableDebtToken, + _implementation, + uint8(decimals), + IERC20Detailed(_implementation).name(), + IERC20Detailed(_implementation).symbol() + ); + + emit StableDebtTokenUpgraded(_reserve, stableDebtToken, _implementation); + + } + + /** + * @dev updates the variable debt token implementation for the _reserve + * @param _reserve the address of the reserve to be updated + * @param _implementation the address of the new aToken implementation + **/ + function updateVariableDebtToken(address _reserve, address _implementation) + external + onlyLendingPoolManager + { + (, , address variableDebtToken) = pool.getReserveTokensAddresses(_reserve); + + (uint256 decimals, , , , , , , , , ) = pool.getReserveConfigurationData(_reserve); + + _upgradeImplementation( + variableDebtToken, + _implementation, + uint8(decimals), + IERC20Detailed(_implementation).name(), + IERC20Detailed(_implementation).symbol() + ); + + emit VariableDebtTokenUpgraded(_reserve, variableDebtToken, _implementation); } /** @@ -529,4 +601,25 @@ contract LendingPoolConfigurator is VersionedInitializable { return address(proxy); } + + function _upgradeImplementation( + address _proxy, + address _implementation, + uint8 _decimals, + string memory _name, + string memory _symbol + ) internal returns (address) { + InitializableAdminUpgradeabilityProxy proxy = InitializableAdminUpgradeabilityProxy( + payable(_proxy) + ); + + bytes memory params = abi.encodeWithSignature( + 'initialize(uint8,string,string)', + _decimals, + _name, + _symbol + ); + + proxy.upgradeToAndCall(_implementation, params); + } } diff --git a/tests.log b/tests.log new file mode 100644 index 00000000..e69de29b