From 963dedb531e4300600965b5177bf2c3f4d22fe35 Mon Sep 17 00:00:00 2001 From: QCQC Date: Sun, 20 Oct 2024 22:27:55 +0800 Subject: [PATCH] fix: make AAVE strategy's external farm addresses updatable (#136) --- .../earn/strategies/Aave/StrategyAave.sol | 33 ++++++++++++++----- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/contracts/earn/strategies/Aave/StrategyAave.sol b/contracts/earn/strategies/Aave/StrategyAave.sol index 12ec924..68a2687 100644 --- a/contracts/earn/strategies/Aave/StrategyAave.sol +++ b/contracts/earn/strategies/Aave/StrategyAave.sol @@ -21,11 +21,9 @@ contract StrategyAave is BaseStrategy { address public rewardTreasury; uint256 public lastHarvest; - /* ----- Constant Variables ----- */ - - address public constant aavePool = address(0x794a61358D6845594F94dc1DB02A252b5b4814aD); // Aave: Pool V3 - address public constant incentivesController = address(0x929EC64c34a17401F460460D4B9390518E5B473e); // Aave: Incentives V3 - address public constant dataProvider = address(0x69FA688f1Dc47d4B5d8029D5a35FB7a548310654); // Aave: Pool Data Provider V3 + address public aavePool; + address public incentivesController; + address public dataProvider; /* ----- Events ----- */ @@ -37,6 +35,10 @@ contract StrategyAave is BaseStrategy { address _accessManager, address _rewardTreasury ) BaseStrategy(_vault, _accessManager) { + aavePool = address(0x794a61358D6845594F94dc1DB02A252b5b4814aD); // Aave: Pool V3 + incentivesController = address(0x929EC64c34a17401F460460D4B9390518E5B473e); // Aave: Incentives V3 + dataProvider = address(0x69FA688f1Dc47d4B5d8029D5a35FB7a548310654); // Aave: Pool Data Provider V3 + rewardAssets = IAaveV3Incentives(incentivesController).getRewardsList(); (address aToken, , ) = IAaveDataProvider(dataProvider).getReserveTokensAddresses(want); aAssets[0] = aToken; @@ -111,9 +113,7 @@ contract StrategyAave is BaseStrategy { } function _withdrawAll() internal { - if (balanceOfPool() > 0) { - IAavePool(aavePool).withdraw(want, type(uint256).max, address(this)); - } + IAavePool(aavePool).withdraw(want, type(uint256).max, address(this)); } /* ----- Admin Functions ----- */ @@ -139,4 +139,21 @@ contract StrategyAave is BaseStrategy { require(addr != address(0), "StrategyAave: !rewardTreasury"); rewardTreasury = addr; } + + function setAavePool(address _aavePool) external onlyOwner { + _removeAllowances(); // revoke access of the legacy aavePool + aavePool = _aavePool; + _giveAllowances(); // approve the new aavePool + } + + function setIncentivesController(address _incentivesController) external onlyOwner { + incentivesController = _incentivesController; + rewardAssets = IAaveV3Incentives(_incentivesController).getRewardsList(); + } + + function setDataProvider(address _dataProvider) external onlyOwner { + dataProvider = _dataProvider; + (address aToken, , ) = IAaveDataProvider(dataProvider).getReserveTokensAddresses(want); + aAssets[0] = aToken; + } }