GasOracle
Inherits: MessagingBase, GasOracleEvents, InterfaceGasOracle
GasOracle
contract is responsible for tracking the gas data for both local and remote chains.
Local gas data tracking
GasOracle
is using the available tools such astx.gasprice
to track the time-averaged values for different "gas statistics" (to be implemented in the future).- These values are cached, so that the reported values are only changed when a big enough change is detected.
- In the MVP version the gas data is set manually by the owner of the contract.
- The reported values are included in Origin's State, whenever a new message is sent.
This leads to cached "chain gas data" being included in the Guard and Notary snapshots.
Remote gas data tracking
- To track gas data for the remote chains, GasOracle relies on the Notaries to pass the gas data alongside their attestations.
- As the gas data is cached, this leads to a storage write only when the gas data for the remote chain changes significantly.
- GasOracle is in charge of enforcing the optimistic periods for the gas data it gets from
Destination
. - The optimistic period is smaller when the "gas statistics" are increasing, and bigger when they are decreasing.
Reason for that is that the decrease of the gas price leads to lower execution/delivery tips, and we want the Executors to be protected against that.
State Variables
destination
address public immutable destination;
GAS_DATA_INCREASED_OPTIMISTIC_PERIOD
uint256 public constant GAS_DATA_INCREASED_OPTIMISTIC_PERIOD = 5 minutes;
GAS_DATA_DECREASED_OPTIMISTIC_PERIOD
uint256 public constant GAS_DATA_DECREASED_OPTIMISTIC_PERIOD = 1 hours;
_gasData
mapping(uint32 => GasData) internal _gasData;
summitTipWei
uint256 public summitTipWei;
Functions
constructor
constructor(uint32 synapseDomain_, address destination_) MessagingBase("0.0.3", synapseDomain_);
initialize
Initializes GasOracle contract:
- msg.sender is set as contract owner
function initialize() external initializer;
setGasData
MVP function to set the gas data for the given domain.
function setGasData(
uint32 domain,
uint256 gasPrice,
uint256 dataPrice,
uint256 execBuffer,
uint256 amortAttCost,
uint256 etherPrice,
uint256 markup
) external onlyOwner;
setSummitTip
MVP function to set the summit tip.
function setSummitTip(uint256 summitTipWei_) external onlyOwner;
updateGasData
Fetches the latest gas data for the chain from Destination
contract,
and uses it to update the oracle values for the requested chain.
function updateGasData(uint32 domain) external;
Parameters
Name | Type | Description |
---|---|---|
domain | uint32 | Domain to update the gas data for |
getDecodedGasData
Returns the gas data for the given domain, in the decoded format.
function getDecodedGasData(uint32 domain)
external
view
returns (
uint256 gasPrice,
uint256 dataPrice,
uint256 execBuffer,
uint256 amortAttCost,
uint256 etherPrice,
uint256 markup
);
Parameters
Name | Type | Description |
---|---|---|
domain | uint32 | Domain of chain to get gas data for |
Returns
Name | Type | Description |
---|---|---|
gasPrice | uint256 | Gas price for the chain (in Wei per gas unit) |
dataPrice | uint256 | Calldata price (in Wei per byte of content) |
execBuffer | uint256 | Tx fee safety buffer for message execution (in Wei) |
amortAttCost | uint256 | Amortized cost for attestation submission (in Wei) |
etherPrice | uint256 | Ratio of Chain's Ether Price / Mainnet Ether Price (in BWAD) |
markup | uint256 | Markup for the message execution (in BWAD) |
getGasData
Returns the gas data for the local chain.
function getGasData() external view returns (uint256 paddedGasData);
getMinimumTips
Returns the minimum tips for sending a message to a given destination.
function getMinimumTips(uint32 destination_, uint256 paddedRequest, uint256 contentLength)
external
view
returns (uint256 paddedTips);
Parameters
Name | Type | Description |
---|---|---|
destination_ | uint32 | |
paddedRequest | uint256 | Padded encoded message execution request on destination chain |
contentLength | uint256 | The length of the message content |
Returns
Name | Type | Description |
---|---|---|
paddedTips | uint256 | Padded encoded minimum tips information |
_setGasData
Sets the gas data for the given domain, and emits a corresponding event.
function _setGasData(uint32 domain, GasData updatedGasData) internal;
_fetchGasData
Returns the updated gas data for the given domain by
optimistically consuming the data from the Destination
contract.
function _fetchGasData(uint32 domain) internal view returns (bool wasUpdated, GasData updatedGasData);
_updateGasParameter
Returns the updated value for the gas parameter, given the maturity of the incoming data.
function _updateGasParameter(Number current, Number incoming, uint256 dataMaturity)
internal
pure
returns (Number updatedParameter);