From 77fab5d3bbe709bee7ba3b69499bed572d7915ab Mon Sep 17 00:00:00 2001 From: The3D Date: Fri, 26 Feb 2021 18:17:10 +0100 Subject: [PATCH] Added encoded parameter to reserve initialization --- contracts/interfaces/IInitializableAToken.sol | 3 +- .../interfaces/IInitializableDebtToken.sol | 3 +- .../interfaces/ILendingPoolConfigurator.sol | 3 + .../lendingpool/LendingPoolConfigurator.sol | 167 +++++++++--------- contracts/protocol/tokenization/AToken.sol | 3 +- .../protocol/tokenization/StableDebtToken.sol | 3 +- .../tokenization/VariableDebtToken.sol | 3 +- 7 files changed, 98 insertions(+), 87 deletions(-) diff --git a/contracts/interfaces/IInitializableAToken.sol b/contracts/interfaces/IInitializableAToken.sol index 9cffe6ce..599fe6bb 100644 --- a/contracts/interfaces/IInitializableAToken.sol +++ b/contracts/interfaces/IInitializableAToken.sol @@ -27,6 +27,7 @@ interface IInitializableAToken { IAaveIncentivesController incentivesController, uint8 aTokenDecimals, string calldata aTokenName, - string calldata aTokenSymbol + string calldata aTokenSymbol, + bytes calldata params ) external; } diff --git a/contracts/interfaces/IInitializableDebtToken.sol b/contracts/interfaces/IInitializableDebtToken.sol index 0a85c968..e310b108 100644 --- a/contracts/interfaces/IInitializableDebtToken.sol +++ b/contracts/interfaces/IInitializableDebtToken.sol @@ -25,6 +25,7 @@ interface IInitializableDebtToken { IAaveIncentivesController incentivesController, uint8 debtTokenDecimals, string memory debtTokenName, - string memory debtTokenSymbol + string memory debtTokenSymbol, + bytes calldata params ) external; } diff --git a/contracts/interfaces/ILendingPoolConfigurator.sol b/contracts/interfaces/ILendingPoolConfigurator.sol index 8981db6c..7554f2a8 100644 --- a/contracts/interfaces/ILendingPoolConfigurator.sol +++ b/contracts/interfaces/ILendingPoolConfigurator.sol @@ -19,6 +19,7 @@ interface ILendingPoolConfigurator { string variableDebtTokenSymbol; string stableDebtTokenName; string stableDebtTokenSymbol; + bytes params; } struct UpdateATokenInput { @@ -28,6 +29,7 @@ interface ILendingPoolConfigurator { string name; string symbol; address implementation; + bytes params; } struct UpdateDebtTokenInput { @@ -36,6 +38,7 @@ interface ILendingPoolConfigurator { string name; string symbol; address implementation; + bytes params; } /** diff --git a/contracts/protocol/lendingpool/LendingPoolConfigurator.sol b/contracts/protocol/lendingpool/LendingPoolConfigurator.sol index b9811311..49451d92 100644 --- a/contracts/protocol/lendingpool/LendingPoolConfigurator.sol +++ b/contracts/protocol/lendingpool/LendingPoolConfigurator.sol @@ -60,183 +60,186 @@ contract LendingPoolConfigurator is VersionedInitializable, ILendingPoolConfigur /** * @dev Initializes reserves in batch **/ - function batchInitReserve(InitReserveInput[] calldata inputParams) external onlyPoolAdmin { + function batchInitReserve(InitReserveInput[] calldata input) external onlyPoolAdmin { ILendingPool cachedPool = pool; - for (uint256 i = 0; i < inputParams.length; i++) { - _initReserve(cachedPool, inputParams[i]); + for (uint256 i = 0; i < input.length; i++) { + _initReserve(cachedPool, input[i]); } } - function _initReserve(ILendingPool pool, InitReserveInput calldata inputParams) internal { + function _initReserve(ILendingPool pool, InitReserveInput calldata input) internal { address aTokenProxyAddress = _initTokenWithProxy( - inputParams.aTokenImpl, + input.aTokenImpl, abi.encodeWithSelector( IInitializableAToken.initialize.selector, pool, - inputParams.treasury, - inputParams.underlyingAsset, - IAaveIncentivesController(inputParams.incentivesController), - inputParams.underlyingAssetDecimals, - inputParams.aTokenName, - inputParams.aTokenSymbol + input.treasury, + input.underlyingAsset, + IAaveIncentivesController(input.incentivesController), + input.underlyingAssetDecimals, + input.aTokenName, + input.aTokenSymbol, + input.params ) ); address stableDebtTokenProxyAddress = _initTokenWithProxy( - inputParams.stableDebtTokenImpl, + input.stableDebtTokenImpl, abi.encodeWithSelector( IInitializableDebtToken.initialize.selector, pool, - inputParams.underlyingAsset, - IAaveIncentivesController(inputParams.incentivesController), - inputParams.underlyingAssetDecimals, - inputParams.stableDebtTokenName, - inputParams.stableDebtTokenSymbol + input.underlyingAsset, + IAaveIncentivesController(input.incentivesController), + input.underlyingAssetDecimals, + input.stableDebtTokenName, + input.stableDebtTokenSymbol, + input.params ) ); address variableDebtTokenProxyAddress = _initTokenWithProxy( - inputParams.variableDebtTokenImpl, + input.variableDebtTokenImpl, abi.encodeWithSelector( IInitializableDebtToken.initialize.selector, pool, - inputParams.underlyingAsset, - IAaveIncentivesController(inputParams.incentivesController), - inputParams.underlyingAssetDecimals, - inputParams.variableDebtTokenName, - inputParams.variableDebtTokenSymbol + input.underlyingAsset, + IAaveIncentivesController(input.incentivesController), + input.underlyingAssetDecimals, + input.variableDebtTokenName, + input.variableDebtTokenSymbol, + input.params ) ); pool.initReserve( - inputParams.underlyingAsset, + input.underlyingAsset, aTokenProxyAddress, stableDebtTokenProxyAddress, variableDebtTokenProxyAddress, - inputParams.interestRateStrategyAddress + input.interestRateStrategyAddress ); DataTypes.ReserveConfigurationMap memory currentConfig = - pool.getConfiguration(inputParams.underlyingAsset); + pool.getConfiguration(input.underlyingAsset); - currentConfig.setDecimals(inputParams.underlyingAssetDecimals); + currentConfig.setDecimals(input.underlyingAssetDecimals); currentConfig.setActive(true); currentConfig.setFrozen(false); - pool.setConfiguration(inputParams.underlyingAsset, currentConfig.data); + pool.setConfiguration(input.underlyingAsset, currentConfig.data); emit ReserveInitialized( - inputParams.underlyingAsset, + input.underlyingAsset, aTokenProxyAddress, stableDebtTokenProxyAddress, variableDebtTokenProxyAddress, - inputParams.interestRateStrategyAddress + input.interestRateStrategyAddress ); } /** * @dev Updates the aToken implementation for the reserve **/ - function updateAToken(UpdateATokenInput calldata inputParams) external onlyPoolAdmin { + function updateAToken(UpdateATokenInput calldata input) external onlyPoolAdmin { ILendingPool cachedPool = pool; - DataTypes.ReserveData memory reserveData = cachedPool.getReserveData(inputParams.asset); + DataTypes.ReserveData memory reserveData = cachedPool.getReserveData(input.asset); - DataTypes.ReserveConfigurationMap memory configuration = - cachedPool.getConfiguration(inputParams.asset); + (, , , uint256 decimals, ) = cachedPool.getConfiguration(input.asset).getParamsMemory(); - (, , , uint256 decimals, ) = configuration.getParamsMemory(); + bytes memory encodedCall = abi.encodeWithSelector( + IInitializableAToken.initialize.selector, + cachedPool, + input.treasury, + input.asset, + input.incentivesController, + decimals, + input.name, + input.symbol, + input.params + ); _upgradeTokenImplementation( reserveData.aTokenAddress, - inputParams.implementation, - abi.encodeWithSelector( - IInitializableAToken.initialize.selector, - cachedPool, - inputParams.treasury, - inputParams.asset, - inputParams.incentivesController, - decimals, - inputParams.name, - inputParams.symbol - ) + input.implementation, + encodedCall ); - emit ATokenUpgraded(inputParams.asset, reserveData.aTokenAddress, inputParams.implementation); + emit ATokenUpgraded(input.asset, reserveData.aTokenAddress, input.implementation); } /** * @dev Updates the stable debt token implementation for the reserve **/ - function updateStableDebtToken(UpdateDebtTokenInput calldata inputParams) external onlyPoolAdmin { + function updateStableDebtToken(UpdateDebtTokenInput calldata input) external onlyPoolAdmin { ILendingPool cachedPool = pool; - DataTypes.ReserveData memory reserveData = cachedPool.getReserveData(inputParams.asset); + DataTypes.ReserveData memory reserveData = cachedPool.getReserveData(input.asset); + + (, , , uint256 decimals, ) = cachedPool.getConfiguration(input.asset).getParamsMemory(); - DataTypes.ReserveConfigurationMap memory configuration = - cachedPool.getConfiguration(inputParams.asset); - - (, , , uint256 decimals, ) = configuration.getParamsMemory(); + bytes memory encodedCall = abi.encodeWithSelector( + IInitializableDebtToken.initialize.selector, + cachedPool, + input.asset, + input.incentivesController, + decimals, + input.name, + input.symbol, + input.params + ); _upgradeTokenImplementation( reserveData.stableDebtTokenAddress, - inputParams.implementation, - abi.encodeWithSelector( - IInitializableDebtToken.initialize.selector, - cachedPool, - inputParams.asset, - inputParams.incentivesController, - decimals, - inputParams.name, - inputParams.symbol - ) + input.implementation, + encodedCall ); emit StableDebtTokenUpgraded( - inputParams.asset, + input.asset, reserveData.stableDebtTokenAddress, - inputParams.implementation + input.implementation ); } /** * @dev Updates the variable debt token implementation for the asset **/ - function updateVariableDebtToken(UpdateDebtTokenInput calldata inputParams) + function updateVariableDebtToken(UpdateDebtTokenInput calldata input) external onlyPoolAdmin { ILendingPool cachedPool = pool; - DataTypes.ReserveData memory reserveData = cachedPool.getReserveData(inputParams.asset); + DataTypes.ReserveData memory reserveData = cachedPool.getReserveData(input.asset); - DataTypes.ReserveConfigurationMap memory configuration = - cachedPool.getConfiguration(inputParams.asset); + (, , , uint256 decimals, ) = cachedPool.getConfiguration(input.asset).getParamsMemory(); - (, , , uint256 decimals, ) = configuration.getParamsMemory(); + bytes memory encodedCall = abi.encodeWithSelector( + IInitializableDebtToken.initialize.selector, + cachedPool, + input.asset, + input.incentivesController, + decimals, + input.name, + input.symbol, + input.params + ); _upgradeTokenImplementation( reserveData.variableDebtTokenAddress, - inputParams.implementation, - abi.encodeWithSelector( - IInitializableDebtToken.initialize.selector, - cachedPool, - inputParams.asset, - inputParams.incentivesController, - decimals, - inputParams.name, - inputParams.symbol - ) + input.implementation, + encodedCall ); emit VariableDebtTokenUpgraded( - inputParams.asset, + input.asset, reserveData.variableDebtTokenAddress, - inputParams.implementation + input.implementation ); } diff --git a/contracts/protocol/tokenization/AToken.sol b/contracts/protocol/tokenization/AToken.sol index 1a47ebf4..f1cfc33a 100644 --- a/contracts/protocol/tokenization/AToken.sol +++ b/contracts/protocol/tokenization/AToken.sol @@ -68,7 +68,8 @@ contract AToken is IAaveIncentivesController incentivesController, uint8 aTokenDecimals, string calldata aTokenName, - string calldata aTokenSymbol + string calldata aTokenSymbol, + bytes calldata params ) external override initializer { uint256 chainId; diff --git a/contracts/protocol/tokenization/StableDebtToken.sol b/contracts/protocol/tokenization/StableDebtToken.sol index f52c4931..3f8a5bfd 100644 --- a/contracts/protocol/tokenization/StableDebtToken.sol +++ b/contracts/protocol/tokenization/StableDebtToken.sol @@ -44,7 +44,8 @@ contract StableDebtToken is IStableDebtToken, DebtTokenBase { IAaveIncentivesController incentivesController, uint8 debtTokenDecimals, string memory debtTokenName, - string memory debtTokenSymbol + string memory debtTokenSymbol, + bytes calldata params ) public override initializer { _setName(debtTokenName); _setSymbol(debtTokenSymbol); diff --git a/contracts/protocol/tokenization/VariableDebtToken.sol b/contracts/protocol/tokenization/VariableDebtToken.sol index 60a47e12..157c703a 100644 --- a/contracts/protocol/tokenization/VariableDebtToken.sol +++ b/contracts/protocol/tokenization/VariableDebtToken.sol @@ -38,7 +38,8 @@ contract VariableDebtToken is DebtTokenBase, IVariableDebtToken { IAaveIncentivesController incentivesController, uint8 debtTokenDecimals, string memory debtTokenName, - string memory debtTokenSymbol + string memory debtTokenSymbol, + bytes calldata params ) public override initializer { _setName(debtTokenName); _setSymbol(debtTokenSymbol);