The home for Hyperlane core contracts, sdk packages, and other infrastructure
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hyperlane-monorepo/solidity/contracts/igps/gas-oracles/StorageGasOracle.sol

105 lines
3.4 KiB

On chain gas oracles in the IGP (#1765) * Rough implementations of all gas oracles, done with StaticGasOracle & tests * more tests, beef up StorageGasOracle * Tests cleaned up, moved to Foundry test for IGP * rm StaticGasOracle, fix all tests * cleaning up * comment * yarn gas, better comments * Fix sdk test * Fix e2e * Rm LZ stuff * fix router test * Rm MockInterchainGasPaymaster * pr comments * Move to setGasConfigs instead of setGasConfig * fix test * nit * yarn gas * IGP deploy & checker tooling, script to update on-chain StorageGasOracle data (#1794) * Add IGP gas oracle to checker * Checker works * Support different gas oracle contracts in IGP deploy tooling too * Export some types * Build out set-storage-gas-oracle-values * nit * nit * rm comment * Add pricing data * nits * nearly there * haven't tested e2e yet, but added new proxy upgrade logic to set gas oracles in IGP in upgradeAndCall * pr comments * lots * Move away from upgradeAndCall for IGP upgrade, trying to debug annoying dependency issue * Got working, cleaned a little * Add test to ensure a new implementation is deployed * yarn hyperlane * nits * cleaning * Map in description * Dedupe submission type logic * yarn gas * Separate beneficiary in IGP (#1801) * Add IGP gas oracle to checker * Checker works * Support different gas oracle contracts in IGP deploy tooling too * Export some types * Build out set-storage-gas-oracle-values * nit * nit * Add separate beneficiary to IGP * Checker / govern / deploy tooling * nits * Add compare-storage-gas-oracle * successful test upgrade, minor changes * Nits * Fix tests * Performed testne3 upgrade. Need to clean up code, but should probably use this for the mainnet upgrade * nit * update prices * Update gas prices and token exchange rates for mainnet * mainnet upgrade. needs lots of cleaning, but here it is in all its glory * Starting to clean up * more cleanup * Use updated submodules * yarn gas * nit * PR comments * yarn hyperlane * yarn gas
2 years ago
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.8.0;
// ============ Internal Imports ============
import {IGasOracle} from "../../interfaces/IGasOracle.sol";
On chain gas oracles in the IGP (#1765) * Rough implementations of all gas oracles, done with StaticGasOracle & tests * more tests, beef up StorageGasOracle * Tests cleaned up, moved to Foundry test for IGP * rm StaticGasOracle, fix all tests * cleaning up * comment * yarn gas, better comments * Fix sdk test * Fix e2e * Rm LZ stuff * fix router test * Rm MockInterchainGasPaymaster * pr comments * Move to setGasConfigs instead of setGasConfig * fix test * nit * yarn gas * IGP deploy & checker tooling, script to update on-chain StorageGasOracle data (#1794) * Add IGP gas oracle to checker * Checker works * Support different gas oracle contracts in IGP deploy tooling too * Export some types * Build out set-storage-gas-oracle-values * nit * nit * rm comment * Add pricing data * nits * nearly there * haven't tested e2e yet, but added new proxy upgrade logic to set gas oracles in IGP in upgradeAndCall * pr comments * lots * Move away from upgradeAndCall for IGP upgrade, trying to debug annoying dependency issue * Got working, cleaned a little * Add test to ensure a new implementation is deployed * yarn hyperlane * nits * cleaning * Map in description * Dedupe submission type logic * yarn gas * Separate beneficiary in IGP (#1801) * Add IGP gas oracle to checker * Checker works * Support different gas oracle contracts in IGP deploy tooling too * Export some types * Build out set-storage-gas-oracle-values * nit * nit * Add separate beneficiary to IGP * Checker / govern / deploy tooling * nits * Add compare-storage-gas-oracle * successful test upgrade, minor changes * Nits * Fix tests * Performed testne3 upgrade. Need to clean up code, but should probably use this for the mainnet upgrade * nit * update prices * Update gas prices and token exchange rates for mainnet * mainnet upgrade. needs lots of cleaning, but here it is in all its glory * Starting to clean up * more cleanup * Use updated submodules * yarn gas * nit * PR comments * yarn hyperlane * yarn gas
2 years ago
// ============ External Imports ============
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
/**
* @notice A gas oracle that uses data stored within the contract.
* @dev This contract is intended to be owned by an address that will
* update the stored remote gas data.
*/
contract StorageGasOracle is IGasOracle, Ownable {
// ============ Public Storage ============
/// @notice Keyed by remote domain, gas data on that remote domain.
mapping(uint32 => IGasOracle.RemoteGasData) public remoteGasData;
// ============ Events ============
/**
* @notice Emitted when an entry in `remoteGasData` is set.
* @param remoteDomain The remote domain in which the gas data was set for.
* @param tokenExchangeRate The exchange rate of the remote native token quoted in the local native token.
* @param gasPrice The gas price on the remote chain.
*/
event RemoteGasDataSet(
uint32 indexed remoteDomain,
uint128 tokenExchangeRate,
uint128 gasPrice
);
struct RemoteGasDataConfig {
uint32 remoteDomain;
uint128 tokenExchangeRate;
uint128 gasPrice;
}
// ============ External Functions ============
/**
* @notice Returns the stored `remoteGasData` for the `_destinationDomain`.
* @param _destinationDomain The destination domain.
* @return tokenExchangeRate The exchange rate of the remote native token quoted in the local native token.
* @return gasPrice The gas price on the remote chain.
*/
function getExchangeRateAndGasPrice(uint32 _destinationDomain)
external
view
override
returns (uint128 tokenExchangeRate, uint128 gasPrice)
{
// Intentionally allow unset / zero values
IGasOracle.RemoteGasData memory _data = remoteGasData[
_destinationDomain
];
return (_data.tokenExchangeRate, _data.gasPrice);
}
/**
* @notice Sets the remote gas data for many remotes at a time.
* @param _configs The configs to use when setting the remote gas data.
*/
function setRemoteGasDataConfigs(RemoteGasDataConfig[] calldata _configs)
external
onlyOwner
{
uint256 _len = _configs.length;
for (uint256 i = 0; i < _len; i++) {
_setRemoteGasData(_configs[i]);
}
}
/**
* @notice Sets the remote gas data using the values in `_config`.
* @param _config The config to use when setting the remote gas data.
*/
function setRemoteGasData(RemoteGasDataConfig calldata _config)
external
onlyOwner
{
_setRemoteGasData(_config);
}
// ============ Internal functions ============
/**
* @notice Sets the remote gas data using the values in `_config`.
* @param _config The config to use when setting the remote gas data.
*/
function _setRemoteGasData(RemoteGasDataConfig calldata _config) internal {
remoteGasData[_config.remoteDomain] = IGasOracle.RemoteGasData({
tokenExchangeRate: _config.tokenExchangeRate,
gasPrice: _config.gasPrice
});
emit RemoteGasDataSet(
_config.remoteDomain,
_config.tokenExchangeRate,
_config.gasPrice
);
}
}