fixed native token transfer bug: mainnet

This commit is contained in:
pradyuman-verma 2022-05-27 23:48:07 +05:30
parent 15040444a0
commit e9ccd751bc
No known key found for this signature in database
GPG Key ID: E36FD6BC8923221F
3 changed files with 17 additions and 12 deletions

View File

@ -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,

View File

@ -12,5 +12,5 @@ interface IHopRouter {
uint256 deadline,
address relayer,
uint256 relayerFee
) external;
) external payable;
}

View File

@ -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(