From e9ccd751bcd91f186f0079bddd91babf0bbeea0d Mon Sep 17 00:00:00 2001 From: pradyuman-verma Date: Fri, 27 May 2022 23:48:07 +0530 Subject: [PATCH] fixed native token transfer bug: mainnet --- contracts/mainnet/connectors/hop/helpers.sol | 11 +++++++---- contracts/mainnet/connectors/hop/interface.sol | 2 +- contracts/mainnet/connectors/hop/main.sol | 16 +++++++++------- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/contracts/mainnet/connectors/hop/helpers.sol b/contracts/mainnet/connectors/hop/helpers.sol index 9b8b099c..6a0c6ed9 100644 --- a/contracts/mainnet/connectors/hop/helpers.sol +++ b/contracts/mainnet/connectors/hop/helpers.sol @@ -26,13 +26,16 @@ contract Helpers is DSMath, Basic { uint256 destinationDeadline; } - function _sendToL2(BridgeParams memory params) internal { + function _sendToL2(BridgeParams memory params, bool isNative) internal { IHopRouter router = IHopRouter(params.router); - TokenInterface tokenContract = TokenInterface(params.token); - approve(tokenContract, params.router, params.amount); + uint256 nativeTokenAmt = isNative ? params.amount : 0; + if (!isNative) { + TokenInterface tokenContract = TokenInterface(params.token); + approve(tokenContract, params.router, params.amount); + } - router.sendToL2( + router.sendToL2{ value: nativeTokenAmt }( params.targetChainId, params.recipient, params.amount, diff --git a/contracts/mainnet/connectors/hop/interface.sol b/contracts/mainnet/connectors/hop/interface.sol index 09b8997a..d38c7518 100644 --- a/contracts/mainnet/connectors/hop/interface.sol +++ b/contracts/mainnet/connectors/hop/interface.sol @@ -12,5 +12,5 @@ interface IHopRouter { uint256 deadline, address relayer, uint256 relayerFee - ) external; + ) external payable; } diff --git a/contracts/mainnet/connectors/hop/main.sol b/contracts/mainnet/connectors/hop/main.sol index 32481914..3a907da4 100644 --- a/contracts/mainnet/connectors/hop/main.sol +++ b/contracts/mainnet/connectors/hop/main.sol @@ -26,24 +26,26 @@ abstract contract Resolver is Helpers { returns (string memory _eventName, bytes memory _eventParam) { params.amount = getUint(getId, params.amount); - - bool isEth = params.token == ethAddr; - params.token = params.token == ethAddr ? wethAddr : params.token; - TokenInterface tokenContract = TokenInterface(params.token); - if (isEth) { + if (params.token == wethAddr) { + convertWethToEth(true, tokenContract, params.amount); + params.token = ethAddr; + } + + bool isNative = params.token == ethAddr; + + if (isNative) { params.amount = params.amount == uint256(-1) ? address(this).balance : params.amount; - convertEthToWeth(isEth, tokenContract, params.amount); } else { params.amount = params.amount == uint256(-1) ? tokenContract.balanceOf(address(this)) : params.amount; } - _sendToL2(params); + _sendToL2(params, isNative); _eventName = "LogBridge(address,uint256,address,uint256,uint256,uint256,uint256)"; _eventParam = abi.encode(