GasOracle

Git Source

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 as tx.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

NameTypeDescription
domainuint32Domain 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

NameTypeDescription
domainuint32Domain of chain to get gas data for

Returns

NameTypeDescription
gasPriceuint256Gas price for the chain (in Wei per gas unit)
dataPriceuint256Calldata price (in Wei per byte of content)
execBufferuint256Tx fee safety buffer for message execution (in Wei)
amortAttCostuint256Amortized cost for attestation submission (in Wei)
etherPriceuint256Ratio of Chain's Ether Price / Mainnet Ether Price (in BWAD)
markupuint256Markup 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

NameTypeDescription
destination_uint32
paddedRequestuint256Padded encoded message execution request on destination chain
contentLengthuint256The length of the message content

Returns

NameTypeDescription
paddedTipsuint256Padded 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);