It's a crypto index fund, which integrates 1inch to zap in into sushiswap pool
This project can save LP's time to zap in.
When it comes to provide liquidity to AMM like sushiswap, you need 2 steps:
This project provide 1-click transaction to do those 2 steps.
In the future, I would integrate more protocols for this 1-click zap-in function.
Actually it's pretty simple, just put 1inch swap function + sushiswap provide liquidity
function in a single function. That's it.
function _zapIn(
uint256 amount,
bytes calldata oneInchData
) internal override returns (uint256) {
SafeERC20.safeApprove(
weth,
oneInchAggregatorAddress,
Math.mulDiv(amount, 1, 2)
);
// TODO(david): should return those token left after addLiquidityETH
back to user
// recurring error: "Error: VM Exception while processing transaction: reverted with reason string '1inch failed to swap'"
(bool succ, bytes memory data) = address(oneInchAggregatorAddress).call(
oneInchData
);
require(succ, "1inch failed to swap");
// (uint256 dpxReturnedAmount, uint256 gasLeft) = abi.decode(data, (uint256, uint256));
uint256 dpxReturnedAmount = dpxToken.balanceOf(address(this));
SafeERC20.safeApprove(dpxToken, sushiSwapRouterAddress, dpxReturnedAmount);
weth.withdraw(Math.mulDiv(amount, 1, 2));
// deadline means current time + 5 minutes;
uint256 deadline = block.timestamp + 300;
(uint amountToken, uint amountETH, uint liquidity) = IUniswapV2Router01(
sushiSwapRouterAddress
).addLiquidityETH{value: address(this).balance}(
address(dpxToken),
dpxReturnedAmount,
Math.mulDiv(dpxReturnedAmount, 95, 100),
Math.mulDiv(address(this).balance, 95, 100),
address(this),
deadline
);
IERC20(sushiSwapDpxLpTokenAddress).approve(
address(sushiSwapMiniChef),
liquidity
);
sushiSwapMiniChef.deposit(pid, liquidity, address(this));
return liquidity;
}
``