Skip to content

Commit

Permalink
Add revert gas to origin chain fee calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
mpetrun5 committed Oct 16, 2024
1 parent ddac879 commit c8e30df
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Test

on:
pull_request:
types: [opened, synchronize, reopened]
push:
- mpetrun5/add-revert-gas

jobs:
test:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down
6 changes: 4 additions & 2 deletions contracts/handlers/fee/dynamic/TwapERC20NativeFeeHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
}
}
27 changes: 21 additions & 6 deletions contracts/handlers/fee/dynamic/TwapFeeHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down Expand Up @@ -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);
}

/**
Expand Down
8 changes: 6 additions & 2 deletions contracts/handlers/fee/dynamic/TwapNativeTokenFeeHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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();
Expand Down

0 comments on commit c8e30df

Please sign in to comment.