From aa1d2b1a7562df9a90886b7a38daf30ca94201bd Mon Sep 17 00:00:00 2001 From: pradyuman-verma Date: Thu, 12 May 2022 01:02:55 +0530 Subject: [PATCH] fixed arbitrum connector --- contracts/arbitrum/connectors/hop/helpers.sol | 11 +++++++---- contracts/arbitrum/connectors/hop/interface.sol | 2 +- contracts/arbitrum/connectors/hop/main.sol | 12 +++++++----- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/contracts/arbitrum/connectors/hop/helpers.sol b/contracts/arbitrum/connectors/hop/helpers.sol index 9bb2f5f7..632b9488 100644 --- a/contracts/arbitrum/connectors/hop/helpers.sol +++ b/contracts/arbitrum/connectors/hop/helpers.sol @@ -32,13 +32,16 @@ contract Helpers is DSMath, Basic { uint256 destinationDeadline; } - function _swapAndSend(BridgeParams memory params) internal { + function _swapAndSend(BridgeParams memory params, bool isEth) internal { IHopRouter router = IHopRouter(params.router); - TokenInterface tokenContract = TokenInterface(params.token); - approve(tokenContract, params.router, params.amount); + uint256 nativeTokenAmt = isEth ? params.amount : 0; + if (!isEth) { + TokenInterface tokenContract = TokenInterface(params.token); + approve(tokenContract, params.router, params.amount); + } - router.swapAndSend( + router.swapAndSend{ value: nativeTokenAmt }( params.targetChainId, params.recipient, params.amount, diff --git a/contracts/arbitrum/connectors/hop/interface.sol b/contracts/arbitrum/connectors/hop/interface.sol index db68c7ef..591056de 100644 --- a/contracts/arbitrum/connectors/hop/interface.sol +++ b/contracts/arbitrum/connectors/hop/interface.sol @@ -13,5 +13,5 @@ interface IHopRouter { uint256 deadline, uint256 destinationAmountOutMin, uint256 destinationDeadline - ) external; + ) external payable; } diff --git a/contracts/arbitrum/connectors/hop/main.sol b/contracts/arbitrum/connectors/hop/main.sol index aca1aa29..9061f219 100644 --- a/contracts/arbitrum/connectors/hop/main.sol +++ b/contracts/arbitrum/connectors/hop/main.sol @@ -37,24 +37,26 @@ abstract contract Resolver is Helpers { } params.amount = getUint(getId, params.amount); + TokenInterface tokenContract = TokenInterface(params.token); + + if (params.token == wethAddr) { + convertWethToEth(true, tokenContract, params.amount); + params.token = ethAddr; + } bool isEth = params.token == ethAddr; - params.token = params.token == ethAddr ? wethAddr : params.token; - - TokenInterface tokenContract = TokenInterface(params.token); if (isEth) { 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; } - _swapAndSend(params); + _swapAndSend(params, isEth); _eventName = "LogBridge(address,uint256,address,uint256,uint256,uint256,uint256,uint256,uint256,uint256)"; _eventParam = abi.encode(