mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
code improvements
This commit is contained in:
parent
cf9c8855c3
commit
b0d9dbe2a7
|
@ -24,14 +24,6 @@ contract BaseUniswapAdapter {
|
||||||
using PercentageMath for uint256;
|
using PercentageMath for uint256;
|
||||||
using SafeERC20 for IERC20;
|
using SafeERC20 for IERC20;
|
||||||
|
|
||||||
struct PermitParams {
|
|
||||||
uint256[] amount;
|
|
||||||
uint256[] deadline;
|
|
||||||
uint8[] v;
|
|
||||||
bytes32[] r;
|
|
||||||
bytes32[] s;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct PermitSignature {
|
struct PermitSignature {
|
||||||
uint256 amount;
|
uint256 amount;
|
||||||
uint256 deadline;
|
uint256 deadline;
|
||||||
|
@ -267,8 +259,7 @@ contract BaseUniswapAdapter {
|
||||||
* @return whether or not permit should be called
|
* @return whether or not permit should be called
|
||||||
*/
|
*/
|
||||||
function _usePermit(PermitSignature memory signature) internal pure returns (bool) {
|
function _usePermit(PermitSignature memory signature) internal pure returns (bool) {
|
||||||
return !(uint256(signature.deadline) == uint256(signature.v) &&
|
return !(uint256(signature.deadline) == uint256(signature.v) && uint256(signature.deadline) == 0);
|
||||||
uint256(signature.deadline) == 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -15,6 +15,14 @@ import {IERC20} from '../dependencies/openzeppelin/contracts/IERC20.sol';
|
||||||
**/
|
**/
|
||||||
contract UniswapLiquiditySwapAdapter is BaseUniswapAdapter, IFlashLoanReceiver {
|
contract UniswapLiquiditySwapAdapter is BaseUniswapAdapter, IFlashLoanReceiver {
|
||||||
|
|
||||||
|
struct PermitParams {
|
||||||
|
uint256[] amount;
|
||||||
|
uint256[] deadline;
|
||||||
|
uint8[] v;
|
||||||
|
bytes32[] r;
|
||||||
|
bytes32[] s;
|
||||||
|
}
|
||||||
|
|
||||||
struct SwapParams {
|
struct SwapParams {
|
||||||
address[] assetToSwapToList;
|
address[] assetToSwapToList;
|
||||||
uint256[] minAmountsToReceive;
|
uint256[] minAmountsToReceive;
|
||||||
|
@ -191,14 +199,10 @@ contract UniswapLiquiditySwapAdapter is BaseUniswapAdapter, IFlashLoanReceiver {
|
||||||
uint256 flashLoanDebt = amount.add(premium);
|
uint256 flashLoanDebt = amount.add(premium);
|
||||||
uint256 amountToPull = swapAllBalance ? aTokenInitiatorBalance : flashLoanDebt;
|
uint256 amountToPull = swapAllBalance ? aTokenInitiatorBalance : flashLoanDebt;
|
||||||
|
|
||||||
_pullATokenAndRepayFlashLoan(
|
_pullAToken(assetFrom, aToken, initiator, amountToPull, permitSignature);
|
||||||
assetFrom,
|
|
||||||
aToken,
|
// Repay flashloan
|
||||||
initiator,
|
IERC20(assetFrom).approve(address(POOL), flashLoanDebt);
|
||||||
amountToPull,
|
|
||||||
flashLoanDebt,
|
|
||||||
permitSignature
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -228,27 +232,4 @@ contract UniswapLiquiditySwapAdapter is BaseUniswapAdapter, IFlashLoanReceiver {
|
||||||
|
|
||||||
return SwapParams(assetToSwapToList, minAmountsToReceive, swapAllBalance, PermitParams(permitAmount, deadline, v, r, s));
|
return SwapParams(assetToSwapToList, minAmountsToReceive, swapAllBalance, PermitParams(permitAmount, deadline, v, r, s));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @dev Pull the ATokens from the user and use them to repay the flashloan
|
|
||||||
* @param reserve address of the asset
|
|
||||||
* @param reserveAToken address of the aToken of the reserve
|
|
||||||
* @param user address
|
|
||||||
* @param amountToPull amount to be pulled from the user
|
|
||||||
* @param flashLoanDebt need to be repaid
|
|
||||||
* @param permitSignature struct containing the permit signature
|
|
||||||
*/
|
|
||||||
function _pullATokenAndRepayFlashLoan(
|
|
||||||
address reserve,
|
|
||||||
address reserveAToken,
|
|
||||||
address user,
|
|
||||||
uint256 amountToPull,
|
|
||||||
uint256 flashLoanDebt,
|
|
||||||
PermitSignature memory permitSignature
|
|
||||||
) internal {
|
|
||||||
_pullAToken(reserve, reserveAToken, user, amountToPull, permitSignature);
|
|
||||||
|
|
||||||
// Repay flashloan
|
|
||||||
IERC20(reserve).approve(address(POOL), flashLoanDebt);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user