diff --git a/ethereum/contracts/bridge/Bridge.sol b/ethereum/contracts/bridge/Bridge.sol index 2466180f6..f9841e117 100644 --- a/ethereum/contracts/bridge/Bridge.sol +++ b/ethereum/contracts/bridge/Bridge.sol @@ -250,11 +250,6 @@ contract Bridge is BridgeGovernance { nativeFee *= multiplier; } - // mint wrapped asset - if(transfer.tokenChain != chainId()) { - TokenImplementation(address(transferToken)).mint(address(this), nativeAmount); - } - // transfer fee to arbiter if(nativeFee > 0) { require(nativeFee <= nativeAmount, "fee higher than transferred amount"); @@ -264,7 +259,12 @@ contract Bridge is BridgeGovernance { payable(msg.sender).transfer(nativeFee); } else { - SafeERC20.safeTransfer(transferToken, msg.sender, nativeFee); + if(transfer.tokenChain != chainId()) { + // mint wrapped asset + TokenImplementation(address(transferToken)).mint(msg.sender, nativeFee); + }else{ + SafeERC20.safeTransfer(transferToken, msg.sender, nativeFee); + } } } @@ -277,7 +277,12 @@ contract Bridge is BridgeGovernance { payable(transferRecipient).transfer(transferAmount); } else { - SafeERC20.safeTransfer(transferToken, transferRecipient, transferAmount); + if(transfer.tokenChain != chainId()) { + // mint wrapped asset + TokenImplementation(address(transferToken)).mint(transferRecipient, transferAmount); + }else{ + SafeERC20.safeTransfer(transferToken, transferRecipient, transferAmount); + } } } diff --git a/ethereum/test/bridge.js b/ethereum/test/bridge.js index b79c79a9a..81f522fa6 100644 --- a/ethereum/test/bridge.js +++ b/ethereum/test/bridge.js @@ -436,9 +436,10 @@ contract("Bridge", function () { assert.equal(bridgeBalanceAfter.toString(10), "0"); }) - it("should mint bridged assets wrappers on transfer from another chain", async function() { + it("should mint bridged assets wrappers on transfer from another chain and handle fees correctly", async function() { const accounts = await web3.eth.getAccounts(); const amount = "1000000000000000000"; + const fee = "1000000000000000"; const initialized = new web3.eth.Contract(BridgeImplementationFullABI, TokenBridge.address); @@ -462,7 +463,7 @@ contract("Bridge", function () { // receiving chain web3.eth.abi.encodeParameter("uint16", testChainId).substring(2 + (64 - 4)) + // fee - "0000000000000000000000000000000000000000000000000000000000000000"; + web3.eth.abi.encodeParameter("uint256", new BigNumber(fee).div(1e10).toString()).substring(2); const vm = await signAndEncodeVM( 0, @@ -480,15 +481,23 @@ contract("Bridge", function () { await initialized.methods.completeTransfer("0x" + vm).send({ value : 0, - from : accounts[0], + from : accounts[1], gasLimit : 2000000 }); const accountBalanceAfter = await wrappedAsset.methods.balanceOf(accounts[0]).call(); + const senderBalanceAfter = await wrappedAsset.methods.balanceOf(accounts[1]).call(); const totalSupplyAfter = await wrappedAsset.methods.totalSupply().call(); - assert.equal(accountBalanceAfter.toString(10), amount); + assert.equal(accountBalanceAfter.toString(10), new BigNumber(amount).minus(fee).toString(10)); + assert.equal(senderBalanceAfter.toString(10), fee); assert.equal(totalSupplyAfter.toString(10), amount); + + await wrappedAsset.methods.transfer(accounts[0], fee).send({ + value : 0, + from : accounts[1], + gasLimit : 2000000 + }); }) it("should burn bridged assets wrappers on transfer to another chain", async function() {