// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.7.6; pragma abicoder v2; import "./interfaces/IMirrorgateRouter.sol"; import "./interfaces/IMirrorgateEthVault.sol"; contract RouterETH { address public immutable mirrorgateEthVault; IMirrorgateRouter public immutable mirrorgateRouter; uint16 public immutable poolId; constructor(address _mirrorgateEthVault, address _mirrorgateRouter, uint16 _poolId){ require(_mirrorgateEthVault != address(0x0), "RouterETH: _mirrorgateEthVault cant be 0x0"); require(_mirrorgateRouter != address(0x0), "RouterETH: _mirrorgateRouter cant be 0x0"); mirrorgateEthVault = _mirrorgateEthVault; mirrorgateRouter = IMirrorgateRouter(_mirrorgateRouter); poolId = _poolId; } function addLiquidityETH() external payable { require(msg.value > 0, "Mirrorgate: msg.value is 0"); uint256 amountLD = msg.value; // wrap the ETH into WETH IMirrorgateEthVault(mirrorgateEthVault).deposit{value: amountLD}(); IMirrorgateEthVault(mirrorgateEthVault).approve(address(mirrorgateRouter), amountLD); // addLiquidity using the WETH that was just wrapped, // and mint the LP token to the msg.sender mirrorgateRouter.addLiquidity( poolId, amountLD, msg.sender ); } // compose mirrorgate to swap ETH on the source to ETH on the destination function swapETH( uint16 _dstChainId, // destination mirrorgate chainId address payable _refundAddress, // refund additional messageFee to this address bytes calldata _toAddress, // the receiver of the destination ETH uint256 _amountLD, // the amount, in Local Decimals, to be swapped uint256 _minAmountLD // the minimum amount accepted out on destination ) external payable { require(msg.value > _amountLD, "Mirrorgate: msg.value must be > _amountLD"); // wrap the ETH into WETH IMirrorgateEthVault(mirrorgateEthVault).deposit{value: _amountLD}(); IMirrorgateEthVault(mirrorgateEthVault).approve(address(mirrorgateRouter), _amountLD); // messageFee is the remainder of the msg.value after wrap uint256 messageFee = msg.value - _amountLD; // compose a mirrorgate swap() using the WETH that was just wrapped mirrorgateRouter.swap{value: messageFee}( _dstChainId, // destination mirrorgate chainId poolId, // WETH mirrorgate poolId on source poolId, // WETH mirrorgate poolId on destination _refundAddress, // message refund address if overpaid _amountLD, // the amount in Local Decimals to swap() _minAmountLD, // the minimum amount swap()er would allow to get out (ie: slippage) IMirrorgateRouter.lzTxObj(0, 0, "0x"), _toAddress, // address on destination to send to bytes("") // empty payload, since sending to EOA ); } // this contract needs to accept ETH receive() external payable {} }