Add permit amount parameter to correctly execute permit call

This commit is contained in:
Gerardo Nardelli 2020-11-06 12:12:08 -03:00
parent 20bbae88d3
commit 1faffa2c39
4 changed files with 602 additions and 596 deletions

View File

@ -27,6 +27,7 @@ contract BaseUniswapAdapter {
enum LeftoverAction {DEPOSIT, TRANSFER} enum LeftoverAction {DEPOSIT, TRANSFER}
struct PermitParams { struct PermitParams {
uint256[] amount;
uint256[] deadline; uint256[] deadline;
uint8[] v; uint8[] v;
bytes32[] r; bytes32[] r;
@ -34,6 +35,7 @@ contract BaseUniswapAdapter {
} }
struct PermitSignature { struct PermitSignature {
uint256 amount;
uint256 deadline; uint256 deadline;
uint8 v; uint8 v;
bytes32 r; bytes32 r;
@ -269,7 +271,7 @@ contract BaseUniswapAdapter {
IERC20WithPermit(reserveAToken).permit( IERC20WithPermit(reserveAToken).permit(
user, user,
address(this), address(this),
amount, permitSignature.amount,
permitSignature.deadline, permitSignature.deadline,
permitSignature.v, permitSignature.v,
permitSignature.r, permitSignature.r,

View File

@ -43,6 +43,7 @@ contract UniswapLiquiditySwapAdapter is BaseUniswapAdapter, IFlashLoanReceiver {
* address[] assetToSwapToList List of the addresses of the reserve to be swapped to and deposited * address[] assetToSwapToList List of the addresses of the reserve to be swapped to and deposited
* uint256[] minAmountsToReceive List of min amounts to be received from the swap * uint256[] minAmountsToReceive List of min amounts to be received from the swap
* bool[] swapAllBalance Flag indicating if all the user balance should be swapped * bool[] swapAllBalance Flag indicating if all the user balance should be swapped
* uint256[] permitAmount List of amounts for the permit signature
* uint256[] deadline List of deadlines for the permit signature * uint256[] deadline List of deadlines for the permit signature
* uint8[] v List of v param for the permit signature * uint8[] v List of v param for the permit signature
* bytes32[] r List of r param for the permit signature * bytes32[] r List of r param for the permit signature
@ -63,6 +64,7 @@ contract UniswapLiquiditySwapAdapter is BaseUniswapAdapter, IFlashLoanReceiver {
assets.length == decodedParams.assetToSwapToList.length assets.length == decodedParams.assetToSwapToList.length
&& assets.length == decodedParams.minAmountsToReceive.length && assets.length == decodedParams.minAmountsToReceive.length
&& assets.length == decodedParams.swapAllBalance.length && assets.length == decodedParams.swapAllBalance.length
&& assets.length == decodedParams.permitParams.amount.length
&& assets.length == decodedParams.permitParams.deadline.length && assets.length == decodedParams.permitParams.deadline.length
&& assets.length == decodedParams.permitParams.v.length && assets.length == decodedParams.permitParams.v.length
&& assets.length == decodedParams.permitParams.r.length && assets.length == decodedParams.permitParams.r.length
@ -80,6 +82,7 @@ contract UniswapLiquiditySwapAdapter is BaseUniswapAdapter, IFlashLoanReceiver {
decodedParams.minAmountsToReceive[i], decodedParams.minAmountsToReceive[i],
decodedParams.swapAllBalance[i], decodedParams.swapAllBalance[i],
PermitSignature( PermitSignature(
decodedParams.permitParams.amount[i],
decodedParams.permitParams.deadline[i], decodedParams.permitParams.deadline[i],
decodedParams.permitParams.v[i], decodedParams.permitParams.v[i],
decodedParams.permitParams.r[i], decodedParams.permitParams.r[i],
@ -101,10 +104,11 @@ contract UniswapLiquiditySwapAdapter is BaseUniswapAdapter, IFlashLoanReceiver {
* @param amountToSwapList List of amounts to be swapped. If the amount exceeds the balance, the total balance is used for the swap * @param amountToSwapList List of amounts to be swapped. If the amount exceeds the balance, the total balance is used for the swap
* @param minAmountsToReceive List of min amounts to be received from the swap * @param minAmountsToReceive List of min amounts to be received from the swap
* @param permitParams List of struct containing the permit signatures * @param permitParams List of struct containing the permit signatures
* uint256[] deadline List of deadlines for the permit signature * uint256 permitAmount Amount for the permit signature
* uint8[] v List of v param for the permit signature * uint256 deadline Deadline for the permit signature
* bytes32[] r List of r param for the permit signature * uint8 v param for the permit signature
* bytes32[] s List of s param for the permit signature * bytes32 r param for the permit signature
* bytes32 s param for the permit signature
*/ */
function swapAndDeposit( function swapAndDeposit(
address[] calldata assetToSwapFromList, address[] calldata assetToSwapFromList,
@ -203,6 +207,7 @@ contract UniswapLiquiditySwapAdapter is BaseUniswapAdapter, IFlashLoanReceiver {
* address[] assetToSwapToList List of the addresses of the reserve to be swapped to and deposited * address[] assetToSwapToList List of the addresses of the reserve to be swapped to and deposited
* uint256[] minAmountsToReceive List of min amounts to be received from the swap * uint256[] minAmountsToReceive List of min amounts to be received from the swap
* bool[] swapAllBalance Flag indicating if all the user balance should be swapped * bool[] swapAllBalance Flag indicating if all the user balance should be swapped
* uint256[] permitAmount List of amounts for the permit signature
* uint256[] deadline List of deadlines for the permit signature * uint256[] deadline List of deadlines for the permit signature
* uint8[] v List of v param for the permit signature * uint8[] v List of v param for the permit signature
* bytes32[] r List of r param for the permit signature * bytes32[] r List of r param for the permit signature
@ -214,13 +219,14 @@ contract UniswapLiquiditySwapAdapter is BaseUniswapAdapter, IFlashLoanReceiver {
address[] memory assetToSwapToList, address[] memory assetToSwapToList,
uint256[] memory minAmountsToReceive, uint256[] memory minAmountsToReceive,
bool[] memory swapAllBalance, bool[] memory swapAllBalance,
uint256[] memory permitAmount,
uint256[] memory deadline, uint256[] memory deadline,
uint8[] memory v, uint8[] memory v,
bytes32[] memory r, bytes32[] memory r,
bytes32[] memory s bytes32[] memory s
) = abi.decode(params, (address[], uint256[], bool[], uint256[], uint8[], bytes32[], bytes32[])); ) = abi.decode(params, (address[], uint256[], bool[], uint256[], uint256[], uint8[], bytes32[], bytes32[]));
return SwapParams(assetToSwapToList, minAmountsToReceive, swapAllBalance, PermitParams(deadline, v, r, s)); return SwapParams(assetToSwapToList, minAmountsToReceive, swapAllBalance, PermitParams(permitAmount, deadline, v, r, s));
} }
/** /**

View File

@ -47,6 +47,7 @@ contract UniswapRepayAdapter is BaseUniswapAdapter, IFlashLoanReceiver {
* (1) Direct transfer to user * (1) Direct transfer to user
* uint256[] repayAmounts List of amounts of debt to be repaid * uint256[] repayAmounts List of amounts of debt to be repaid
* uint256[] rateModes List of the rate modes of the debt to be repaid * uint256[] rateModes List of the rate modes of the debt to be repaid
* uint256[] permitAmount List of amounts for the permit signature
* uint256[] deadline List of deadlines for the permit signature * uint256[] deadline List of deadlines for the permit signature
* uint8[] v List of v param for the permit signature * uint8[] v List of v param for the permit signature
* bytes32[] r List of r param for the permit signature * bytes32[] r List of r param for the permit signature
@ -67,6 +68,7 @@ contract UniswapRepayAdapter is BaseUniswapAdapter, IFlashLoanReceiver {
assets.length == decodedParams.assetToSwapToList.length assets.length == decodedParams.assetToSwapToList.length
&& assets.length == decodedParams.repayAmounts.length && assets.length == decodedParams.repayAmounts.length
&& assets.length == decodedParams.rateModes.length && assets.length == decodedParams.rateModes.length
&& assets.length == decodedParams.permitParams.amount.length
&& assets.length == decodedParams.permitParams.deadline.length && assets.length == decodedParams.permitParams.deadline.length
&& assets.length == decodedParams.permitParams.v.length && assets.length == decodedParams.permitParams.v.length
&& assets.length == decodedParams.permitParams.r.length && assets.length == decodedParams.permitParams.r.length
@ -84,6 +86,7 @@ contract UniswapRepayAdapter is BaseUniswapAdapter, IFlashLoanReceiver {
decodedParams.leftOverAction, decodedParams.leftOverAction,
premiums[i], premiums[i],
PermitSignature( PermitSignature(
decodedParams.permitParams.amount[i],
decodedParams.permitParams.deadline[i], decodedParams.permitParams.deadline[i],
decodedParams.permitParams.v[i], decodedParams.permitParams.v[i],
decodedParams.permitParams.r[i], decodedParams.permitParams.r[i],
@ -141,6 +144,7 @@ contract UniswapRepayAdapter is BaseUniswapAdapter, IFlashLoanReceiver {
* (1) Direct transfer to user * (1) Direct transfer to user
* uint256[] repayAmounts List of amounts of debt to be repaid * uint256[] repayAmounts List of amounts of debt to be repaid
* uint256[] rateModes List of the rate modes of the debt to be repaid * uint256[] rateModes List of the rate modes of the debt to be repaid
* uint256[] permitAmount List of amounts for the permit signature
* uint256[] deadline List of deadlines for the permit signature * uint256[] deadline List of deadlines for the permit signature
* uint8[] v List of v param for the permit signature * uint8[] v List of v param for the permit signature
* bytes32[] r List of r param for the permit signature * bytes32[] r List of r param for the permit signature
@ -153,11 +157,12 @@ contract UniswapRepayAdapter is BaseUniswapAdapter, IFlashLoanReceiver {
LeftoverAction leftOverAction, LeftoverAction leftOverAction,
uint256[] memory repayAmounts, uint256[] memory repayAmounts,
uint256[] memory rateModes, uint256[] memory rateModes,
uint256[] memory permitAmount,
uint256[] memory deadline, uint256[] memory deadline,
uint8[] memory v, uint8[] memory v,
bytes32[] memory r, bytes32[] memory r,
bytes32[] memory s bytes32[] memory s
) = abi.decode(params, (address[], LeftoverAction, uint256[], uint256[], uint256[], uint8[], bytes32[], bytes32[])); ) = abi.decode(params, (address[], LeftoverAction, uint256[], uint256[], uint256[], uint256[], uint8[], bytes32[], bytes32[]));
return RepayParams( return RepayParams(
assetToSwapToList, assetToSwapToList,
@ -165,6 +170,7 @@ contract UniswapRepayAdapter is BaseUniswapAdapter, IFlashLoanReceiver {
repayAmounts, repayAmounts,
rateModes, rateModes,
PermitParams( PermitParams(
permitAmount,
deadline, deadline,
v, v,
r, r,

File diff suppressed because it is too large Load Diff