By using the routers of both of the DEX, you'll use their swapping functions in a single contract called in one function.
NOTE: The router addresses should already be approved on the tokens you want to swap
function multiSwap(uint256 deadline, uint256 amountOutMinUniswap)
external
payable {
uint256 amountOutMinBancor = 1;
uint256 amountOutMinSushiSwap = 1;
_tradeOnBancor(msg.value, amountOutMinBancor);
_tradeOnSushi(IERC20(BNT).balanceOf(address(this)), amountOutMinSushiSwap, deadline);
_tradeOnUniswap(IERC20(INJ).balanceOf(address(this)), amountOutMinUniswap, deadline);
}
This is how the transaction will be executed for three swaps, every swap will have its own function which will handle the swap on that DEX for you
This is how the trade function will look like
function _tradeOnUniswap(uint256 amountIn, uint256 amountOutMin,
uint256 deadline) private {
address tokenIn = INJ;
address tokenOut = DAI;
uint24 fee = 3000;
address recipient = msg.sender;
uint160 sqrtPriceLimitX96 = 0;
ISwapRouter.ExactInputSingleParams memory params = ISwapRouter.ExactInputSingleParams(
tokenIn,
tokenOut,
fee,
recipient,
deadline,
amountIn,
amountOutMin,
sqrtPriceLimitX96
);
uniswapRouter.exactInputSingle(params);
uniswapRouter.refundETH();
// refund leftover ETH to user
(bool success,) = msg.sender.call{ value: address(this).balance }("");
require(success, "refund failed");
}