From 5e7d39fa7ae72bca165a5d86510a38443ef57cd6 Mon Sep 17 00:00:00 2001 From: domenicodev Date: Thu, 21 Dec 2023 10:08:22 +0100 Subject: [PATCH] fix: fixed submit deadline and transfers on sell and buy functions --- evm/src/integral/IntegralSwapAdapter.sol | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/evm/src/integral/IntegralSwapAdapter.sol b/evm/src/integral/IntegralSwapAdapter.sol index fdae3ba..c35d6f9 100644 --- a/evm/src/integral/IntegralSwapAdapter.sol +++ b/evm/src/integral/IntegralSwapAdapter.sol @@ -4,8 +4,8 @@ pragma solidity ^0.8.13; import {IERC20, ISwapAdapter} from "src/interfaces/ISwapAdapter.sol"; /// @dev Integral submitted deadline of 3600 seconds (1 hour) to Paraswap, but it is not strictly necessary to be this long -/// as the contract allows less durations, we use 1000 seconds (15 minutes) as deadline -uint32 constant SWAP_DEADLINE_SEC = 1000; +/// as the contract allows less durations, we use 1000 seconds (15 minutes) as a deadline +uint256 constant SWAP_DEADLINE_SEC = 1000; /// @title Integral Swap Adapter contract IntegralSwapAdapter is ISwapAdapter { @@ -85,9 +85,11 @@ contract IntegralSwapAdapter is ISwapAdapter { uint256 limitMax1 ) = relayer.getPoolState(address(sellToken), address(buyToken)); - limits = new uint256[](2); + limits = new uint256[](4); limits[0] = limitMax0; limits[1] = limitMax1; + limits[2] = limitMin0; + limits[3] = limitMin1; } /// @inheritdoc ISwapAdapter @@ -182,12 +184,16 @@ contract IntegralSwapAdapter is ISwapAdapter { if (amountOut == 0) { revert Unavailable("AmountOut is zero!"); } + + IERC20(sellToken).transferFrom(msg.sender, address(this), amount); + IERC20(sellToken).approve(address(relayer), amount); + relayer.sell(ITwapRelayer.SellParams({ tokenIn: sellToken, tokenOut: buyToken, wrapUnwrap: false, to: swapper, - submitDeadline: SWAP_DEADLINE_SEC, + submitDeadline: uint32(block.timestamp + SWAP_DEADLINE_SEC), amountIn: amount, amountOutMin: amountOut })); @@ -211,12 +217,16 @@ contract IntegralSwapAdapter is ISwapAdapter { if (amountIn == 0) { revert Unavailable("AmountIn is zero!"); } + + IERC20(sellToken).transferFrom(msg.sender, address(this), amountIn); + IERC20(sellToken).approve(address(relayer), amountIn); + relayer.buy(ITwapRelayer.BuyParams({ tokenIn: sellToken, tokenOut: buyToken, wrapUnwrap: false, to: swapper, - submitDeadline: SWAP_DEADLINE_SEC, + submitDeadline: uint32(block.timestamp + SWAP_DEADLINE_SEC), amountInMax: amountIn, amountOut: amountBought }));