diff --git a/script/HelperConfig.s.sol b/script/HelperConfig.s.sol index b41ddfa..9df11be 100644 --- a/script/HelperConfig.s.sol +++ b/script/HelperConfig.s.sol @@ -10,7 +10,8 @@ contract HelperConfig is Script { // Added to remove this whole contract from coverage report. function test() public {} - address public aaveAddress; + address public aavePoolAddress; + address public aaveOracleAddress; address public uniswapV3RouterAddress; address public uniswapV3WstETHETHPoolAddress; uint24 public uniswapV3WstETHETHPoolFee; @@ -34,7 +35,8 @@ contract HelperConfig is Script { if (chainId == 1) { // Mainnet - aaveAddress = vm.envAddress("MAINNET_ADDRESS_AAVE"); + aavePoolAddress = vm.envAddress("MAINNET_ADDRESS_AAVE_POOL"); + aaveOracleAddress = vm.envAddress("MAINNET_ADDRESS_AAVE_ORACLE"); uniswapV3RouterAddress = vm.envAddress("MAINNET_ADDRESS_UNISWAP_V3_ROUTER"); uniswapV3WstETHETHPoolAddress = vm.envAddress("MAINNET_ADDRESS_UNISWAP_V3_WSTETH_ETH_POOL"); uniswapV3WstETHETHPoolFee = uint24(vm.envUint("MAINNET_FEE_UNISWAP_V3_WSTETH_ETH_POOL")); @@ -46,7 +48,8 @@ contract HelperConfig is Script { awstETHAddress = vm.envAddress("MAINNET_ADDRESS_AWSTETH"); } else if (chainId == 8453) { // Base - aaveAddress = vm.envAddress("BASE_ADDRESS_AAVE"); + aavePoolAddress = vm.envAddress("BASE_ADDRESS_AAVE_POOL"); + aaveOracleAddress = vm.envAddress("BASE_ADDRESS_AAVE_ORACLE"); uniswapV3RouterAddress = vm.envAddress("BASE_ADDRESS_UNISWAP_V3_ROUTER"); uniswapV3WstETHETHPoolAddress = vm.envAddress("BASE_ADDRESS_UNISWAP_V3_WSTETH_ETH_POOL"); uniswapV3WstETHETHPoolFee = uint24(vm.envUint("BASE_FEE_UNISWAP_V3_WSTETH_ETH_POOL")); @@ -67,9 +70,10 @@ contract HelperConfig is Script { getChainVariables(); // Contract addresses - IAavePM.ContractAddress[] memory contractAddresses = new IAavePM.ContractAddress[](2); - contractAddresses[0] = IAavePM.ContractAddress("aave", aaveAddress); - contractAddresses[1] = IAavePM.ContractAddress("uniswapV3Router", uniswapV3RouterAddress); + IAavePM.ContractAddress[] memory contractAddresses = new IAavePM.ContractAddress[](3); + contractAddresses[0] = IAavePM.ContractAddress("aavePool", aavePoolAddress); + contractAddresses[1] = IAavePM.ContractAddress("aaveOracle", aaveOracleAddress); + contractAddresses[2] = IAavePM.ContractAddress("uniswapV3Router", uniswapV3RouterAddress); // Token addresses IAavePM.TokenAddress[] memory tokenAddresses = new IAavePM.TokenAddress[](4); diff --git a/src/AavePM.sol b/src/AavePM.sol index 7fe911a..5994ef9 100644 --- a/src/AavePM.sol +++ b/src/AavePM.sol @@ -230,24 +230,28 @@ contract AavePM is IAavePM, Initializable, AccessControlUpgradeable, UUPSUpgrade /// @notice Deposit all wstETH into Aave. /// @dev Caller must have `MANAGER_ROLE`. function aaveSupplyWstETH() public onlyRole(MANAGER_ROLE) { + address aavePoolAddress = s_contractAddresses["aavePool"]; + // Takes all wstETH in the contract and deposits it into Aave - TransferHelper.safeApprove( - s_tokenAddresses["wstETH"], address(s_contractAddresses["aave"]), getContractBalance("wstETH") - ); - IPool(s_contractAddresses["aave"]).deposit( - s_tokenAddresses["wstETH"], getContractBalance("wstETH"), address(this), 0 - ); + TransferHelper.safeApprove(s_tokenAddresses["wstETH"], aavePoolAddress, getContractBalance("wstETH")); + IPool(aavePoolAddress).deposit(s_tokenAddresses["wstETH"], getContractBalance("wstETH"), address(this), 0); } /// @notice Borrow USDC from Aave. /// @dev Caller must have `MANAGER_ROLE`. /// @param borrowAmount The amount of USDC to borrow. 8 decimal places to the cent. function aaveBorrowUSDC(uint256 borrowAmount) public onlyRole(MANAGER_ROLE) { - IPool(s_contractAddresses["aave"]).borrow(s_tokenAddresses["USDC"], borrowAmount, 2, 0, address(this)); + IPool(s_contractAddresses["aavePool"]).borrow(s_tokenAddresses["USDC"], borrowAmount, 2, 0, address(this)); } + /// @notice Repay Aave debt. + /// @dev Caller must have `MANAGER_ROLE`. + /// // TODO: Implement function. function aaveRepay() public onlyRole(MANAGER_ROLE) {} + /// @notice Withdraw all wstETH from Aave. + /// @dev Caller must have `MANAGER_ROLE`. + /// // TODO: Implement function. function aaveWithdraw() public onlyRole(MANAGER_ROLE) {} // ================================================================ @@ -441,6 +445,6 @@ contract AavePM is IAavePM, Initializable, AccessControlUpgradeable, UUPSUpgrade ) { (totalCollateralBase, totalDebtBase, availableBorrowsBase, currentLiquidationThreshold, ltv, healthFactor) = - IPool(s_contractAddresses["aave"]).getUserAccountData(address(this)); + IPool(s_contractAddresses["aavePool"]).getUserAccountData(address(this)); } } diff --git a/test/unit/AavePMTest.t.sol b/test/unit/AavePMTest.t.sol index b4fcc5a..4df9388 100644 --- a/test/unit/AavePMTest.t.sol +++ b/test/unit/AavePMTest.t.sol @@ -185,14 +185,14 @@ contract AavePMUpdateTests is AavePMTestSetup { vm.expectRevert(encodedRevert_AccessControlUnauthorizedAccount_Owner); vm.prank(attacker1); - aavePM.updateContractAddress("aave", newContractAddress); + aavePM.updateContractAddress("aavePool", newContractAddress); vm.expectEmit(); - emit IAavePM.ContractAddressUpdated("aave", aavePM.getContractAddress("aave"), newContractAddress); + emit IAavePM.ContractAddressUpdated("aavePool", aavePM.getContractAddress("aavePool"), newContractAddress); vm.prank(owner1); - aavePM.updateContractAddress("aave", newContractAddress); - assertEq(aavePM.getContractAddress("aave"), newContractAddress); + aavePM.updateContractAddress("aavePool", newContractAddress); + assertEq(aavePM.getContractAddress("aavePool"), newContractAddress); } function test_UpdateTokenAddress() public { @@ -521,7 +521,7 @@ contract AavePMGetterTests is AavePMTestSetup { } function test_GetAave() public { - assertEq(aavePM.getContractAddress("aave"), s_contractAddresses["aave"]); + assertEq(aavePM.getContractAddress("aavePool"), s_contractAddresses["aavePool"]); } function test_GetUniswapV3Router() public {