diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a93b7458..8e4b07ea 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,8 +1,8 @@ name: Test on: - pull_request: - types: [opened, synchronize, reopened] + push: + - mpetrun5/add-revert-gas jobs: test: diff --git a/Makefile b/Makefile index 0c6358fb..6fc807c0 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ start-forkedMainnet: test-forked: @echo " > \033[32mTesting contracts... \033[0m " - truffle test --stacktrace testUnderForked/* + npx truffle test --stacktrace testUnderForked/* start-geth: @echo " > \033[32mStarting geth... \033[0m " diff --git a/contracts/handlers/fee/dynamic/TwapERC20NativeFeeHandler.sol b/contracts/handlers/fee/dynamic/TwapERC20NativeFeeHandler.sol index 9f0aeaa2..f5915fe2 100644 --- a/contracts/handlers/fee/dynamic/TwapERC20NativeFeeHandler.sol +++ b/contracts/handlers/fee/dynamic/TwapERC20NativeFeeHandler.sol @@ -15,11 +15,13 @@ contract TwapERC20NativeFeeHandler is TwapNativeTokenFeeHandler { @param bridgeAddress Contract address of previously deployed Bridge. @param feeHandlerRouterAddress Contract address of previously deployed FeeHandlerRouter. @param gasUsed Default gas used for proposal execution in the destination. + @param recoverGas Gas used for an optional call fallback. */ constructor( address bridgeAddress, address feeHandlerRouterAddress, - uint32 gasUsed - ) TwapNativeTokenFeeHandler(bridgeAddress, feeHandlerRouterAddress, gasUsed) { + uint32 gasUsed, + uint32 recoverGas + ) TwapNativeTokenFeeHandler(bridgeAddress, feeHandlerRouterAddress, gasUsed, recoverGas) { } } diff --git a/contracts/handlers/fee/dynamic/TwapFeeHandler.sol b/contracts/handlers/fee/dynamic/TwapFeeHandler.sol index b15d31da..7ed418f2 100644 --- a/contracts/handlers/fee/dynamic/TwapFeeHandler.sol +++ b/contracts/handlers/fee/dynamic/TwapFeeHandler.sol @@ -26,6 +26,7 @@ abstract contract TwapFeeHandler is IFeeHandler, AccessControl { ProtocolFeeType public protocolFeeType; uint32 public _gasUsed; + uint32 public _recoverGas; mapping(uint8 => address) public destinationNativeCoinWrap; mapping(uint8 => Fee) public destinationFee; @@ -43,7 +44,8 @@ abstract contract TwapFeeHandler is IFeeHandler, AccessControl { } event FeeOracleAddressSet(TwapOracle feeOracleAddress); - event FeePropertySet(uint32 gasUsed); + event GasUsedSet(uint32 gasUsed); + event RecoverGasSet(uint32 recoverGas); event GasPriceSet(uint8 destinationDomainID, uint256 gasPrice); event WrapTokenAddressSet(uint8 destinationDomainID, address wrapTokenAddress); @@ -136,16 +138,29 @@ abstract contract TwapFeeHandler is IFeeHandler, AccessControl { } /** - @notice Sets the fee properties. + @notice Sets the recover gas property. + @param recoverGas Gas used for an optional call fallback. + */ + function setRecoverGas(uint32 recoverGas) external onlyAdmin { + _setRecoverGas(recoverGas); + } + + function _setRecoverGas(uint32 recoverGas) internal { + _recoverGas = recoverGas; + emit RecoverGasSet(recoverGas); + } + + /** + @notice Sets the gas used property. @param gasUsed Default gas used for proposal execution in the destination. */ - function setFeeProperties(uint32 gasUsed) external onlyAdmin { - _setFeeProperties(gasUsed); + function setGasUsed(uint32 gasUsed) external onlyAdmin { + _setGasUsed(gasUsed); } - function _setFeeProperties(uint32 gasUsed) internal { + function _setGasUsed(uint32 gasUsed) internal { _gasUsed = gasUsed; - emit FeePropertySet(gasUsed); + emit GasUsedSet(gasUsed); } /** diff --git a/contracts/handlers/fee/dynamic/TwapNativeTokenFeeHandler.sol b/contracts/handlers/fee/dynamic/TwapNativeTokenFeeHandler.sol index 0a5fa34c..5893a3bb 100644 --- a/contracts/handlers/fee/dynamic/TwapNativeTokenFeeHandler.sol +++ b/contracts/handlers/fee/dynamic/TwapNativeTokenFeeHandler.sol @@ -15,13 +15,16 @@ contract TwapNativeTokenFeeHandler is TwapFeeHandler { @param bridgeAddress Contract address of previously deployed Bridge. @param feeHandlerRouterAddress Contract address of previously deployed FeeHandlerRouter. @param gasUsed Default gas used for proposal execution in the destination. + @param recoverGas Gas used for an optional call fallback. */ constructor( address bridgeAddress, address feeHandlerRouterAddress, - uint32 gasUsed + uint32 gasUsed, + uint32 recoverGas ) TwapFeeHandler(bridgeAddress, feeHandlerRouterAddress) { - _setFeeProperties(gasUsed); + _setGasUsed(gasUsed); + _setRecoverGas(recoverGas); } /** @@ -38,6 +41,7 @@ contract TwapNativeTokenFeeHandler is TwapFeeHandler { if (depositData.length > (pointer + 64)) { uint256 gas = abi.decode(depositData[pointer:], (uint256)); maxFee += gas; + maxFee += _recoverGas; } uint256 destinationCoinPrice = twapOracle.getPrice(destinationNativeCoinWrap[destinationDomainID]); if (destinationCoinPrice == 0) revert IncorrectPrice();