From 6abaee5bf92afe931b279e2bb1a3f7edb3efc123 Mon Sep 17 00:00:00 2001 From: bhavik-m Date: Sun, 27 Feb 2022 02:28:09 +0530 Subject: [PATCH] minor fix --- .../connectors/aave/v3-import/interface.sol | 23 +++++-- .../connectors/aave/v3-import/main.sol | 68 +++++++++---------- 2 files changed, 51 insertions(+), 40 deletions(-) diff --git a/contracts/mainnet/connectors/aave/v3-import/interface.sol b/contracts/mainnet/connectors/aave/v3-import/interface.sol index e0775894..7bef374b 100644 --- a/contracts/mainnet/connectors/aave/v3-import/interface.sol +++ b/contracts/mainnet/connectors/aave/v3-import/interface.sol @@ -47,6 +47,25 @@ interface IFlashLoan { ) external; } +interface ATokenInterface { + function scaledBalanceOf(address _user) external view returns (uint256); + + function isTransferAllowed(address _user, uint256 _amount) + external + view + returns (bool); + + function balanceOf(address _user) external view returns (uint256); + + function transferFrom( + address, + address, + uint256 + ) external returns (bool); + + function allowance(address, address) external returns (uint256); +} + interface AaveLendingPoolProviderInterface { function getLendingPool() external view returns (address); } @@ -83,7 +102,3 @@ interface AaveAddressProviderRegistryInterface { view returns (address[] memory); } - -interface ATokenInterface { - function balanceOf(address _user) external view returns (uint256); -} diff --git a/contracts/mainnet/connectors/aave/v3-import/main.sol b/contracts/mainnet/connectors/aave/v3-import/main.sol index de125b4d..b4dc4849 100644 --- a/contracts/mainnet/connectors/aave/v3-import/main.sol +++ b/contracts/mainnet/connectors/aave/v3-import/main.sol @@ -149,13 +149,13 @@ contract AaveResolver is Helpers, Events { } function _repay( - address[] tokens, - uint256[] amounts, + address[] memory tokens, + uint256[] memory amounts, address recepient ) internal { for (uint256 i = 0; i < tokens.length; i++) { require(_balance(tokens[i]) >= amounts[i], "Repay failed!"); - TokenInterface(tokens[i]).Transfer(recepient, amounts[i]); + TokenInterface(tokens[i]).transfer(recepient, amounts[i]); } } } @@ -236,7 +236,7 @@ contract AaveHelpers is AaveResolver { ImportInputData memory inputData, ImportData memory data ) internal view returns (ImportData memory) { - data.supplyAmts = new uint256[](inputData.supplyAssets.length); + data.supplyAmts = new uint256[](inputData.supplyTokens.length); data._supplyTokens = new address[](inputData.supplyTokens.length); data.aTokens = new ATokenInterface[](inputData.supplyTokens.length); @@ -281,65 +281,61 @@ contract AaveHelpers is AaveResolver { address initiator, bytes calldata params ) external returns (bool) { - ImportData memory Data; - (Data) = abi.decode(params, (ImportData)); + ImportData memory data; + (data) = abi.decode(params, (ImportData)); // 1. payback borrowed amount; AaveInterface aave = AaveInterface(aaveProvider.getLendingPool()); _PaybackStable( - Data._borrowTokens.length, + data._borrowTokens.length, aave, - Data._borrowTokens, - Data.stableBorrowAmts, - Data.userAccount + data._borrowTokens, + data.stableBorrowAmts, + data.userAccount ); _PaybackVariable( - Data._borrowTokens.length, + data._borrowTokens.length, aave, - Data._borrowTokens, - Data.variableBorrowAmts, - Data.userAccount + data._borrowTokens, + data.variableBorrowAmts, + data.userAccount ); // 2. transfer atokens to this address; _TransferAtokens( - Data._supplyTokens.length, + data._supplyTokens.length, aave, - Data.aTokens, - Data.supplyAmts, - Data._supplyTokens, - Data.userAccount + data.aTokens, + data.supplyAmts, + data._supplyTokens, + data.userAccount ); // 3. take debt including flashloan fee; - Data = _includeFee(Data, premiums); + data = _includeFee(data, premiums); - if (Data.convertStable) { + if (data.convertStable) { _BorrowVariable( - Data._borrowTokens.length, + data._borrowTokens.length, aave, - Data._borrowTokens, - Data.totalBorrowAmtsFinalAmtsWithFee + data._borrowTokens, + data.totalBorrowAmtsWithFee ); } else { _BorrowStable( - inputData.borrowTokens.length, + data._borrowTokens.length, aave, - Data._borrowTokens, - Data.stableBorrowFinalAmts + data._borrowTokens, + data.stableBorrowAmts ); _BorrowVariable( - inputData.borrowTokens.length, + data._borrowTokens.length, aave, - Data._borrowTokens, - Data.variableBorrowFinalAmtsWithFee + data._borrowTokens, + data.variableBorrowAmtsWithFee ); } // 4. repay flashloan with the borrowed assets - _repay( - Data._borrowTokens, - Data.totalBorrowAmtsAmtsWithFee, - flashloanAddr - ); + _repay(data._borrowTokens, data.totalBorrowAmtsWithFee, flashloanAddr); } } @@ -365,7 +361,7 @@ contract AaveV3ImportResolver is AaveHelpers { bytes memory _callData = abi.encode(data); - flashborrow(data._borrowTokens, data.totalBorrowAmts, 5, _calldata); + flashBorrow(data._borrowTokens, data.totalBorrowAmts, 5, _callData); _eventName = "LogAaveV2Import(address,bool,address[],address[],uint256[],uint256[],uint256[])"; _eventParam = abi.encode(