minor fix

This commit is contained in:
bhavik-m 2022-02-27 02:28:09 +05:30
parent 7bf7174c7a
commit 6abaee5bf9
2 changed files with 51 additions and 40 deletions

View File

@ -47,6 +47,25 @@ interface IFlashLoan {
) external; ) 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 { interface AaveLendingPoolProviderInterface {
function getLendingPool() external view returns (address); function getLendingPool() external view returns (address);
} }
@ -83,7 +102,3 @@ interface AaveAddressProviderRegistryInterface {
view view
returns (address[] memory); returns (address[] memory);
} }
interface ATokenInterface {
function balanceOf(address _user) external view returns (uint256);
}

View File

@ -149,13 +149,13 @@ contract AaveResolver is Helpers, Events {
} }
function _repay( function _repay(
address[] tokens, address[] memory tokens,
uint256[] amounts, uint256[] memory amounts,
address recepient address recepient
) internal { ) internal {
for (uint256 i = 0; i < tokens.length; i++) { for (uint256 i = 0; i < tokens.length; i++) {
require(_balance(tokens[i]) >= amounts[i], "Repay failed!"); 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, ImportInputData memory inputData,
ImportData memory data ImportData memory data
) internal view returns (ImportData memory) { ) 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._supplyTokens = new address[](inputData.supplyTokens.length);
data.aTokens = new ATokenInterface[](inputData.supplyTokens.length); data.aTokens = new ATokenInterface[](inputData.supplyTokens.length);
@ -281,65 +281,61 @@ contract AaveHelpers is AaveResolver {
address initiator, address initiator,
bytes calldata params bytes calldata params
) external returns (bool) { ) external returns (bool) {
ImportData memory Data; ImportData memory data;
(Data) = abi.decode(params, (ImportData)); (data) = abi.decode(params, (ImportData));
// 1. payback borrowed amount; // 1. payback borrowed amount;
AaveInterface aave = AaveInterface(aaveProvider.getLendingPool()); AaveInterface aave = AaveInterface(aaveProvider.getLendingPool());
_PaybackStable( _PaybackStable(
Data._borrowTokens.length, data._borrowTokens.length,
aave, aave,
Data._borrowTokens, data._borrowTokens,
Data.stableBorrowAmts, data.stableBorrowAmts,
Data.userAccount data.userAccount
); );
_PaybackVariable( _PaybackVariable(
Data._borrowTokens.length, data._borrowTokens.length,
aave, aave,
Data._borrowTokens, data._borrowTokens,
Data.variableBorrowAmts, data.variableBorrowAmts,
Data.userAccount data.userAccount
); );
// 2. transfer atokens to this address; // 2. transfer atokens to this address;
_TransferAtokens( _TransferAtokens(
Data._supplyTokens.length, data._supplyTokens.length,
aave, aave,
Data.aTokens, data.aTokens,
Data.supplyAmts, data.supplyAmts,
Data._supplyTokens, data._supplyTokens,
Data.userAccount data.userAccount
); );
// 3. take debt including flashloan fee; // 3. take debt including flashloan fee;
Data = _includeFee(Data, premiums); data = _includeFee(data, premiums);
if (Data.convertStable) { if (data.convertStable) {
_BorrowVariable( _BorrowVariable(
Data._borrowTokens.length, data._borrowTokens.length,
aave, aave,
Data._borrowTokens, data._borrowTokens,
Data.totalBorrowAmtsFinalAmtsWithFee data.totalBorrowAmtsWithFee
); );
} else { } else {
_BorrowStable( _BorrowStable(
inputData.borrowTokens.length, data._borrowTokens.length,
aave, aave,
Data._borrowTokens, data._borrowTokens,
Data.stableBorrowFinalAmts data.stableBorrowAmts
); );
_BorrowVariable( _BorrowVariable(
inputData.borrowTokens.length, data._borrowTokens.length,
aave, aave,
Data._borrowTokens, data._borrowTokens,
Data.variableBorrowFinalAmtsWithFee data.variableBorrowAmtsWithFee
); );
} }
// 4. repay flashloan with the borrowed assets // 4. repay flashloan with the borrowed assets
_repay( _repay(data._borrowTokens, data.totalBorrowAmtsWithFee, flashloanAddr);
Data._borrowTokens,
Data.totalBorrowAmtsAmtsWithFee,
flashloanAddr
);
} }
} }
@ -365,7 +361,7 @@ contract AaveV3ImportResolver is AaveHelpers {
bytes memory _callData = abi.encode(data); 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[])"; _eventName = "LogAaveV2Import(address,bool,address[],address[],uint256[],uint256[],uint256[])";
_eventParam = abi.encode( _eventParam = abi.encode(