GasDataLib
Library for encoding and decoding GasData and ChainGas structs.
GasData
GasData
is a struct to store the "basic information about gas prices", that could
be later used to approximate the cost of a message execution, and thus derive the
minimal tip values for sending a message to the chain.
GasData
is supposed to be cached byGasOracle
contract, allowing to store the approximates instead of the exact values, and thus save on storage costs.- For instance, if
GasOracle
only updates the values on +- 10% change, having an 0.4% error on the approximates would be acceptable.GasData
is supposed to be included in the Origin's state, which are synced across chains using Agent-signed snapshots and attestations.
GasData stack layout (from highest bits to lowest)
Position | Field | Type | Bytes | Description |
---|---|---|---|---|
(012..010] | gasPrice | uint16 | 2 | Gas price for the chain (in Wei per gas unit) |
(010..008] | dataPrice | uint16 | 2 | Calldata price (in Wei per byte of content) |
(008..006] | execBuffer | uint16 | 2 | Tx fee safety buffer for message execution (in Wei) |
(006..004] | amortAttCost | uint16 | 2 | Amortized cost for attestation submission (in Wei) |
(004..002] | etherPrice | uint16 | 2 | Chain's Ether Price / Mainnet Ether Price (in BWAD) |
(002..000] | markup | uint16 | 2 | Markup for the message execution (in BWAD) |
See Number.sol for more details on
Number
type and BWAD (binary WAD) math.
ChainGas stack layout (from highest bits to lowest)
Position | Field | Type | Bytes | Description |
---|---|---|---|---|
(016..004] | gasData | uint96 | 12 | Chain's gas data |
(004..000] | domain | uint32 | 4 | Chain's domain |
State Variables
SHIFT_GAS_PRICE
Amount of bits to shift to gasPrice field
uint96 private constant SHIFT_GAS_PRICE = 10 * 8;
SHIFT_DATA_PRICE
Amount of bits to shift to dataPrice field
uint96 private constant SHIFT_DATA_PRICE = 8 * 8;
SHIFT_EXEC_BUFFER
Amount of bits to shift to execBuffer field
uint96 private constant SHIFT_EXEC_BUFFER = 6 * 8;
SHIFT_AMORT_ATT_COST
Amount of bits to shift to amortAttCost field
uint96 private constant SHIFT_AMORT_ATT_COST = 4 * 8;
SHIFT_ETHER_PRICE
Amount of bits to shift to etherPrice field
uint96 private constant SHIFT_ETHER_PRICE = 2 * 8;
SHIFT_GAS_DATA
Amount of bits to shift to gasData field
uint128 private constant SHIFT_GAS_DATA = 4 * 8;
Functions
encodeGasData
Returns an encoded GasData struct with the given fields.
function encodeGasData(
Number gasPrice_,
Number dataPrice_,
Number execBuffer_,
Number amortAttCost_,
Number etherPrice_,
Number markup_
) internal pure returns (GasData);
Parameters
Name | Type | Description |
---|---|---|
gasPrice_ | Number | Gas price for the chain (in Wei per gas unit) |
dataPrice_ | Number | Calldata price (in Wei per byte of content) |
execBuffer_ | Number | Tx fee safety buffer for message execution (in Wei) |
amortAttCost_ | Number | Amortized cost for attestation submission (in Wei) |
etherPrice_ | Number | Ratio of Chain's Ether Price / Mainnet Ether Price (in BWAD) |
markup_ | Number | Markup for the message execution (in BWAD) |
wrapGasData
Wraps padded uint256 value into GasData struct.
function wrapGasData(uint256 paddedGasData) internal pure returns (GasData);
gasPrice
Returns the gas price, in Wei per gas unit.
function gasPrice(GasData data) internal pure returns (Number);
dataPrice
Returns the calldata price, in Wei per byte of content.
function dataPrice(GasData data) internal pure returns (Number);
execBuffer
Returns the tx fee safety buffer for message execution, in Wei.
function execBuffer(GasData data) internal pure returns (Number);
amortAttCost
Returns the amortized cost for attestation submission, in Wei.
function amortAttCost(GasData data) internal pure returns (Number);
etherPrice
Returns the ratio of Chain's Ether Price / Mainnet Ether Price, in BWAD math.
function etherPrice(GasData data) internal pure returns (Number);
markup
Returns the markup for the message execution, in BWAD math.
function markup(GasData data) internal pure returns (Number);
encodeChainGas
Returns an encoded ChainGas struct with the given fields.
function encodeChainGas(GasData gasData_, uint32 domain_) internal pure returns (ChainGas);
Parameters
Name | Type | Description |
---|---|---|
gasData_ | GasData | Chain's gas data |
domain_ | uint32 | Chain's domain |
wrapChainGas
Wraps padded uint256 value into ChainGas struct.
function wrapChainGas(uint256 paddedChainGas) internal pure returns (ChainGas);
gasData
Returns the chain's gas data.
function gasData(ChainGas data) internal pure returns (GasData);
domain
Returns the chain's domain.
function domain(ChainGas data) internal pure returns (uint32);
snapGasHash
Returns the hash for the list of ChainGas structs.
function snapGasHash(ChainGas[] memory snapGas) internal pure returns (bytes32 snapGasHash_);