Skip to content

Commit

Permalink
feat(contracts/core): add fee oracle v2 (#1952)
Browse files Browse the repository at this point in the history
Add FeeOracleV2 contract.

- fee oracle v2 uses explicit data & exec gas prices per chain
- add version() view on fee oracles


issue: #1951
  • Loading branch information
kevinhalliday authored Sep 27, 2024
1 parent 85c737f commit 7013787
Show file tree
Hide file tree
Showing 10 changed files with 675 additions and 16 deletions.
2 changes: 1 addition & 1 deletion contracts/bindings/admin.go

Large diffs are not rendered by default.

35 changes: 33 additions & 2 deletions contracts/bindings/feeoraclev1.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contracts/bindings/omniportal.go

Large diffs are not rendered by default.

32 changes: 20 additions & 12 deletions contracts/core/.gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Admin_Test:test_pause_unpause() (gas: 25569229)
Admin_Test:test_pause_unpause_xcall() (gas: 25523261)
Admin_Test:test_pause_unpause_xsubmit() (gas: 25523012)
Admin_Test:test_upgrade() (gas: 29383460)
Admin_Test:test_pause_unpause() (gas: 25588380)
Admin_Test:test_pause_unpause_xcall() (gas: 25542344)
Admin_Test:test_pause_unpause_xsubmit() (gas: 25542095)
Admin_Test:test_upgrade() (gas: 29402611)
AllocPredeploys_Test:test_num_allocs() (gas: 1180997376)
AllocPredeploys_Test:test_predeploys() (gas: 1180932760)
AllocPredeploys_Test:test_preinstalls() (gas: 1181568893)
Expand All @@ -13,22 +13,30 @@ FeeOracleV1_Test:test_setGasPrice() (gas: 40996)
FeeOracleV1_Test:test_setManager() (gas: 45845)
FeeOracleV1_Test:test_setProtocolFee() (gas: 31442)
FeeOracleV1_Test:test_setToNativeRate() (gas: 41049)
FeeOracleV2_Test:test_bulkSetFeeParams() (gas: 218007)
FeeOracleV2_Test:test_feeFor() (gas: 111934)
FeeOracleV2_Test:test_setBaseGasLimit() (gas: 32261)
FeeOracleV2_Test:test_setDataGasPrice() (gas: 43312)
FeeOracleV2_Test:test_setExecGasPrice() (gas: 43184)
FeeOracleV2_Test:test_setManager() (gas: 45827)
FeeOracleV2_Test:test_setProtocolFee() (gas: 31508)
FeeOracleV2_Test:test_setToNativeRate() (gas: 43377)
InitializableHelper_Test:test_disableInitalizers() (gas: 181686)
InitializableHelper_Test:test_getInitialized() (gas: 178023)
OmniBridgeL1_Test:test_bridge() (gas: 252053)
OmniBridgeL1_Test:test_bridge() (gas: 252291)
OmniBridgeL1_Test:test_pauseAll() (gas: 49368)
OmniBridgeL1_Test:test_pauseBridging() (gas: 59554)
OmniBridgeL1_Test:test_pauseBridging() (gas: 59588)
OmniBridgeL1_Test:test_pauseWithdraws() (gas: 48975)
OmniBridgeL1_Test:test_withdraw() (gas: 1382984)
OmniBridgeNative_Test:test_bridge() (gas: 190132)
OmniBridgeNative_Test:test_bridge() (gas: 190336)
OmniBridgeNative_Test:test_claim() (gas: 287756)
OmniBridgeNative_Test:test_pauseAll() (gas: 52904)
OmniBridgeNative_Test:test_pauseBridging() (gas: 44449)
OmniBridgeNative_Test:test_pauseWithdraws() (gas: 61348)
OmniBridgeNative_Test:test_withdraw() (gas: 279800)
OmniGasPump_Test:testFuzz_quote(uint32) (runs: 256, μ: 63806, ~: 63857)
OmniGasPump_Test:test_fillUp() (gas: 230967)
OmniGasPump_Test:test_pause() (gas: 62701)
OmniGasPump_Test:testFuzz_quote(uint32) (runs: 256, μ: 63875, ~: 63925)
OmniGasPump_Test:test_fillUp() (gas: 231273)
OmniGasPump_Test:test_pause() (gas: 62735)
OmniGasPump_Test:test_setMaxSwap() (gas: 34749)
OmniGasPump_Test:test_setOmniGasStation() (gas: 36697)
OmniGasPump_Test:test_setOracle() (gas: 34992)
Expand Down Expand Up @@ -103,11 +111,11 @@ XAppUpgradeable_Test:test_omniChainId() (gas: 16703)
XAppUpgradeable_Test:test_setDefaultConfLevel() (gas: 16678)
XAppUpgradeable_Test:test_setOmniPortal() (gas: 17189)
XAppUpgradeable_Test:test_storageSlots() (gas: 102679)
XAppUpgradeable_Test:test_xcall() (gas: 166896)
XAppUpgradeable_Test:test_xcall() (gas: 167168)
XAppUpgradeable_Test:test_xrecv() (gas: 70749)
XApp_Test:test_isXCall() (gas: 148924)
XApp_Test:test_omniChainId() (gas: 16681)
XApp_Test:test_setDefaultConfLevel() (gas: 16523)
XApp_Test:test_setOmniPortal() (gas: 17090)
XApp_Test:test_xcall() (gas: 166412)
XApp_Test:test_xcall() (gas: 166684)
XApp_Test:test_xrecv() (gas: 70714)
5 changes: 5 additions & 0 deletions contracts/core/src/interfaces/IFeeOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ interface IFeeOracle {
* @param gasLimit Execution gas limit, enforced on destination chain
*/
function feeFor(uint64 destChainId, bytes calldata data, uint64 gasLimit) external view returns (uint256);

/**
* @notice Returns the version of the fee oracle
*/
function version() external view returns (uint64);
}
90 changes: 90 additions & 0 deletions contracts/core/src/interfaces/IFeeOracleV2.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.12;

import { IFeeOracle } from "./IFeeOracle.sol";
import { IConversionRateOracle } from "./IConversionRateOracle.sol";

/**
* @title IFeeOracleV2
* @notice Extends IFeeOracle with FeeOracleV2 methods
*/
interface IFeeOracleV2 is IFeeOracle, IConversionRateOracle {
/// @notice Emitted when fee parameters for a chain are set.
event FeeParamsSet(uint64 chainId, uint256 execGasPrice, uint256 dataGasPrice, uint256 toNativeRate);

/// @notice Emitted when the base gas limit is set.
event BaseGasLimitSet(uint64 baseGasLimit);

/// @notice Emitted when the base protocol fee is set.
event ProtocolFeeSet(uint256 protocolFee);

/// @notice Emitted when the gas price for a destination chain is set.
event ExecGasPriceSet(uint64 chainId, uint256 gasPrice);

/// @notice Emitted when the data gas price for a destination chain is set.
event DataGasPriceSet(uint64 chainId, uint256 gasPrice);

/// @notice Emitted when the to-native conversion rate for a destination chain is set.
event ToNativeRateSet(uint64 chainId, uint256 toNativeRate);

/// @notice Emitted when the manager is changed.
event ManagerSet(address manager);

/**
* @notice Fee parameters for a specific chain.
* @custom:field chainId The chain ID.
* @custom:field execGasPrice The execution gas price on that chain (denominated in chains native token).
* @custom:field dataGasPrice The data gas price on that chain (denominated in chains native token).
* ex. for Optimism, dataGasPrice is Ethereum L1's blob gas price.
* @custom:field toNativeRate The conversion rate from the chains native token to this chain's
* native token. Rate is numerator over CONVERSION_RATE_DENOM.
*/
struct FeeParams {
uint64 chainId;
uint256 execGasPrice;
uint256 dataGasPrice;
uint256 toNativeRate;
}

/// @notice Returns the fee parameters for a destination chain.
function feeParams(uint64 chainId) external view returns (FeeParams memory);

/// @notice Returns the execution gas price for a destination chain.
function execGasPrice(uint64 chainId) external view returns (uint256);

/// @notice Returns the data gas price for a destination chain.
function dataGasPrice(uint64 chainId) external view returns (uint256);

/// @notice Returns the to-native conversion rate for a destination chain.
function toNativeRate(uint64 chainId) external view returns (uint256);

/// @notice Returns the manager's address.
function manager() external view returns (address);

/// @notice Returns the protocol fee.
function protocolFee() external view returns (uint256);

/// @notice Returns the base gas limit.
function baseGasLimit() external view returns (uint64);

/// @notice Set the fee parameters for a list of destination chains.
function bulkSetFeeParams(FeeParams[] calldata params) external;

/// @notice Set the execution gas price for a destination chain.
function setExecGasPrice(uint64 chainId, uint256 execGasPrice) external;

/// @notice Set the data gas price for a destination chain.
function setDataGasPrice(uint64 chainId, uint256 dataGasPrice) external;

/// @notice Set the to native conversion rate for a destination chain.
function setToNativeRate(uint64 chainId, uint256 toNativeRate) external;

/// @notice Set the base gas limit for each xmsg.
function setBaseGasLimit(uint64 gasLimit) external;

/// @notice Set the base protocol fee for each xmsg.
function setProtocolFee(uint256 fee) external;

/// @notice Set the manager admin account.
function setManager(address manager) external;
}
5 changes: 5 additions & 0 deletions contracts/core/src/xchain/FeeOracleV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ contract FeeOracleV1 is IFeeOracle, IFeeOracleV1, OwnableUpgradeable {
_bulkSetFeeParams(params);
}

/// @inheritdoc IFeeOracle
function version() external pure override returns (uint64) {
return 1;
}

/// @inheritdoc IFeeOracle
function feeFor(uint64 destChainId, bytes calldata data, uint64 gasLimit) external view returns (uint256) {
IFeeOracleV1.ChainFeeParams storage execP = _feeParams[destChainId];
Expand Down
Loading

0 comments on commit 7013787

Please sign in to comment.