diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a1614dea..a93b7458 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,9 +1,8 @@ name: Test on: - push: - branches: - - mpetrun5/add-revert-gas + pull_request: + types: [opened, synchronize, reopened] jobs: test: diff --git a/contracts/handlers/fee/dynamic/TwapNativeTokenFeeHandler.sol b/contracts/handlers/fee/dynamic/TwapNativeTokenFeeHandler.sol index 5893a3bb..73d0ebf7 100644 --- a/contracts/handlers/fee/dynamic/TwapNativeTokenFeeHandler.sol +++ b/contracts/handlers/fee/dynamic/TwapNativeTokenFeeHandler.sol @@ -41,7 +41,7 @@ contract TwapNativeTokenFeeHandler is TwapFeeHandler { if (depositData.length > (pointer + 64)) { uint256 gas = abi.decode(depositData[pointer:], (uint256)); maxFee += gas; - maxFee += _recoverGas; + maxFee += uint256(_recoverGas); } uint256 destinationCoinPrice = twapOracle.getPrice(destinationNativeCoinWrap[destinationDomainID]); if (destinationCoinPrice == 0) revert IncorrectPrice(); diff --git a/testUnderForked/collectFeeERC20EVM.js b/testUnderForked/collectFeeERC20EVM.js index c61dbcd9..208bf582 100644 --- a/testUnderForked/collectFeeERC20EVM.js +++ b/testUnderForked/collectFeeERC20EVM.js @@ -222,7 +222,7 @@ contract("TwapNativeTokenFeeHandler - [collectFee]", async (accounts) => { const fee = Ethers.BigNumber.from(expectedFee.toString()).div(2); const errorValues = await Helpers.expectToRevertWithCustomError( - BridgeInstance.deposit( + BridgeInstance.deposit.call( destinationDomainID, resourceID, depositData, @@ -243,7 +243,7 @@ contract("TwapNativeTokenFeeHandler - [collectFee]", async (accounts) => { await TwapOracleInstance.setPrice(MATIC_ADDRESS, 0); await Helpers.expectToRevertWithCustomError( - BridgeInstance.deposit( + BridgeInstance.deposit.call( destinationDomainID, resourceID, depositData, diff --git a/testUnderForked/optionalContractCall/calculateFeeERC20EVM.js b/testUnderForked/optionalContractCall/calculateFeeERC20EVM.js index 74dc0398..a1b7b454 100644 --- a/testUnderForked/optionalContractCall/calculateFeeERC20EVM.js +++ b/testUnderForked/optionalContractCall/calculateFeeERC20EVM.js @@ -49,6 +49,7 @@ contract("TwapFeeHandler - [calculateFee]", async (accounts) => { const higherExecutionGasAmount = 30000000; const lowerExecutionGasAmount = 3000000; const feeData = "0x"; + const feePercentage = 1000; // 10% let UniswapFactoryInstance; let TwapOracleInstance; @@ -176,4 +177,57 @@ contract("TwapFeeHandler - [calculateFee]", async (accounts) => { expect(higherExecutionGasAmountRes.fee.toNumber()).to.be.gt(lowerExecutionGasAmountRes.fee.toNumber()) }); + + it("[percentage protocol fee] should calculate in recover gas for tx cost", async () => { + const mintableERC20Iface = new Ethers.utils.Interface(["function mint(address to, uint256 amount)"]); + const actions = [{ + nativeValue: 0, + callTo: ERC20MintableInstance.address, + approveTo: Ethers.constants.AddressZero, + tokenSend: Ethers.constants.AddressZero, + tokenReceive: Ethers.constants.AddressZero, + data: mintableERC20Iface.encodeFunctionData("mint", [recipientAddress, "20"]), + }] + const message = Helpers.createMessageCallData( + transactionId, + actions, + recipientAddress + ); + + const depositData = Helpers.createOptionalContractCallDepositData( + transferredAmount, + Ethers.constants.AddressZero, + higherExecutionGasAmount, + message + ); + + await DynamicFeeHandlerInstance.setGasPrice( + destinationDomainID, + gasPrice, // Polygon gas price is 200 Gwei + ProtocolFeeType.Percentage, + feePercentage + ); + + const feeInDestinationToken = gasPrice * gasUsed; + const resWithoutRecoverGas = await FeeHandlerRouterInstance.calculateFee.call( + sender, + originDomainID, + destinationDomainID, + resourceID, + depositData, + "0x00" + ); + + await DynamicFeeHandlerInstance.setRecoverGas(gasUsed); + + const resWithRecoverGas = await FeeHandlerRouterInstance.calculateFee.call( + sender, + originDomainID, + destinationDomainID, + resourceID, + depositData, + "0x00" + ); + expect(resWithRecoverGas.fee.toNumber()).to.be.gt(resWithoutRecoverGas.fee.toNumber()); + }); });