Gelato connector updated with swap & mint

This commit is contained in:
Samyak Jain 2021-06-10 03:00:34 +05:30
parent 1c6c7bc358
commit 2bd7492e56
4 changed files with 149 additions and 2 deletions

View File

@ -6,7 +6,7 @@ contract Events {
address indexed pool,
uint256 amtA,
uint256 amtB,
uint256 uniAmount,
uint256 mintAmount,
uint256 getId,
uint256 setId
);
@ -15,7 +15,18 @@ contract Events {
address indexed pool,
uint256 amountA,
uint256 amountB,
uint256 uniAmount,
uint256 burnAmount,
uint256 getId,
uint256 setId
);
event LogSwapAndDepositLiquidity(
address indexed pool,
uint256 amtA,
uint256 amtB,
uint256 mintAmount,
bool zeroForOne,
uint swapAmount,
uint256 getId,
uint256 setId
);

View File

@ -4,6 +4,10 @@ pragma experimental ABIEncoderV2;
import { DSMath } from "../../common/math.sol";
import { Basic } from "../../common/basic.sol";
import { IGUniRouter } from "./interface.sol";
abstract contract Helpers is DSMath, Basic {
IGUniRouter public constant gUniRouter = IGUniRouter(0x8CA6fa325bc32f86a12cC4964Edf1f71655007A7);
}

View File

@ -41,6 +41,74 @@ interface ERC20WrapperInterface {
}
interface IGUniRouter {
function rebalanceAndAddLiquidity(
IGUniPool pool,
uint256 amount0In,
uint256 amount1In,
bool zeroForOne,
uint256 swapAmount,
uint160 swapThreshold,
uint256 amount0Min,
uint256 amount1Min,
address receiver
)
external
returns (
uint256 amount0,
uint256 amount1,
uint256 mintAmount
);
function rebalanceAndAddLiquidityETH(
IGUniPool pool,
uint256 amount0In,
uint256 amount1In,
bool zeroForOne,
uint256 swapAmount,
uint160 swapThreshold,
uint256 amount0Min,
uint256 amount1Min,
address receiver
)
external
payable
returns (
uint256 amount0,
uint256 amount1,
uint256 mintAmount
);
function removeLiquidity(
IGUniPool pool,
uint256 burnAmount,
uint256 amount0Min,
uint256 amount1Min,
address receiver
)
external
returns (
uint256 amount0,
uint256 amount1,
uint128 liquidityBurned
);
function removeLiquidityETH(
IGUniPool pool,
uint256 burnAmount,
uint256 amount0Min,
uint256 amount1Min,
address payable receiver
)
external
returns (
uint256 amount0,
uint256 amount1,
uint128 liquidityBurned
);
}
interface TokenInterface {
function approve(address, uint256) external;
function transfer(address, uint) external;

View File

@ -104,6 +104,70 @@ abstract contract UniswapV3Resolver is Events, Helpers {
_eventParam = abi.encode(pool, amount0, amount1, uint256(liquidityBurned), getId, setId);
}
function swapAndDeposit(
address pool,
uint256 amount0In,
uint256 amount1In,
bool zeroForOne,
uint256 swapAmount,
uint160 swapThreshold
) external payable returns (string memory _eventName, bytes memory _eventParam) {
ERC20WrapperInterface poolContract = ERC20WrapperInterface(pool);
IERC20 _token0 = poolContract.token0();
IERC20 _token1 = poolContract.token1();
uint amount0;
uint amount1;
uint mintAmount;
if (address(_token0) == wethAddr) {
_token1.approve(address(gUniRouter), amount1In);
(amount0, amount1, mintAmount) = gUniRouter.rebalanceAndAddLiquidityETH{value: amount0In}(
poolContract,
amount0In,
amount1In,
zeroForOne,
swapAmount,
swapThreshold,
0,
0,
address(this)
);
} else if (address(_token1) == wethAddr) {
_token0.approve(address(gUniRouter), amount0In);
(amount0, amount1, mintAmount) = gUniRouter.rebalanceAndAddLiquidityETH{value: amount1In}(
poolContract,
amount0In,
amount1In,
zeroForOne,
swapAmount,
swapThreshold,
0,
0,
address(this)
);
} else {
_token0.approve(address(gUniRouter), amount0In);
_token1.approve(address(gUniRouter), amount1In);
(amount0, amount1, mintAmount) = gUniRouter.rebalanceAndAddLiquidity(
poolContract,
amount0In,
amount1In,
zeroForOne,
swapAmount,
swapThreshold,
0,
0,
address(this)
);
}
_eventName = "LogSwapAndDepositLiquidity(address,uint256,uint256,uint256,bool,uint256,uint256,uint256)";
_eventParam = abi.encode(pool, amount0, amount1, mintAmount, zeroForOne, swapAmount, getId, setId);
}
}
contract ConnectV2UniswapV3ERC20 is UniswapV3Resolver {