Skip to content

Commit

Permalink
Change aave to aavePool
Browse files Browse the repository at this point in the history
  • Loading branch information
EridianAlpha committed Apr 23, 2024
1 parent d81b099 commit 90d7bf0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 19 deletions.
16 changes: 10 additions & 6 deletions script/HelperConfig.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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"));
Expand All @@ -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"));
Expand All @@ -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);
Expand Down
20 changes: 12 additions & 8 deletions src/AavePM.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}

// ================================================================
Expand Down Expand Up @@ -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));
}
}
10 changes: 5 additions & 5 deletions test/unit/AavePMTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 90d7bf0

Please sign in to comment.