Проверенный контрактТочноеGPL-3.0
RocketOvmRebasingPriceMessenger
Адрес0x12759f8df234f8f2cddb3d2ed5604adf9accfc9f
- Баланс
0 ETH
- Транзакций
818
- Компилятор
solc 0.8.18
- Тот же код
ещё 2 контракта
Подробности
- Компилятор
- solc 0.8.18+commit.87f61d96
- Язык
- solidity
- Оптимизация
- Нет
- Версия EVM
- paris
- Лицензия
- GPL-3.0
- Совпадение
- Точноекод создания: да, код в сети: да
- Проверен на Sourcify
- Создан в блоке
- 20 481 949
- Транзакция создания
- 0x71eac173be…86336a3667
7 файлов
- src/RocketOvmRebasingPriceMessenger.solглавный1,96 КБ
- lib/optimism/packages/contracts/contracts/libraries/bridge/ICrossDomainMessenger.sol1,04 КБ
- lib/rocketpool/contracts/interface/RocketStorageInterface.sol2,23 КБ
- lib/rocketpool/contracts/interface/network/RocketNetworkBalancesInterface.sol761 Б
- src/RocketOvmPriceMessenger.sol2,5 КБ
- src/RocketOvmPriceOracle.sol1,69 КБ
- src/interfaces/IWRETH.sol180 Б
src/RocketOvmRebasingPriceMessenger.sol
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.13;
import "@eth-optimism/contracts/libraries/bridge/ICrossDomainMessenger.sol";
import "./interfaces/IWRETH.sol";
import "./RocketOvmPriceOracle.sol";
import "./RocketOvmPriceMessenger.sol";
/// @author Kane Wallmann (Rocket Pool)
/// @notice A wrapper around the price messenger which also executes a rebase on the WRETH token on the OVM L2
contract RocketOvmRebasingPriceMessenger {
// Immutables
ICrossDomainMessenger public immutable ovmL1CrossDomainMessenger;
RocketOvmPriceMessenger public immutable priceMessenger;
address public immutable wrethL2;
/// @notice The most recently submitted rate
uint256 lastRate;
constructor(RocketOvmPriceMessenger _priceMessenger, address _wrethL2, ICrossDomainMessenger _ovmL1CrossDomainMessenger) {
priceMessenger = _priceMessenger;
wrethL2 = _wrethL2;
ovmL1CrossDomainMessenger = _ovmL1CrossDomainMessenger;
}
/// @notice Returns whether the rate has changed since it was last submitted
function rateStale() external view returns (bool) {
return priceMessenger.rate() != lastRate;
}
/// @notice Returns the calculated rETH exchange rate
function rate() public view returns (uint256) {
return priceMessenger.rate();
}
/// @notice Submits the rETH exchange rate and executes a rebase
/// @dev The name `submitRate` is used to make the interface consistent with RocketOvmPriceMessenger
function submitRate() external {
lastRate = priceMessenger.rate();
priceMessenger.submitRate();
rebase();
}
/// @notice Calls rebase on the WRETH token on the OVM L2 via cross domain messenger
function rebase() public {
// Send the cross chain message
ovmL1CrossDomainMessenger.sendMessage(
wrethL2,
abi.encodeWithSelector(IWRETH.rebase.selector),
500000
);
}
}
lib/optimism/packages/contracts/contracts/libraries/bridge/ICrossDomainMessenger.sol
// SPDX-License-Identifier: MIT
pragma solidity >0.5.0 <0.9.0;
/**
* @title ICrossDomainMessenger
*/
interface ICrossDomainMessenger {
/**********
* Events *
**********/
event SentMessage(
address indexed target,
address sender,
bytes message,
uint256 messageNonce,
uint256 gasLimit
);
event RelayedMessage(bytes32 indexed msgHash);
event FailedRelayedMessage(bytes32 indexed msgHash);
/*************
* Variables *
*************/
function xDomainMessageSender() external view returns (address);
/********************
* Public Functions *
********************/
/**
* Sends a cross domain message to the target messenger.
* @param _target Target contract address.
* @param _message Message to send to the target.
* @param _gasLimit Gas limit for the provided message.
*/
function sendMessage(
address _target,
bytes calldata _message,
uint32 _gasLimit
) external;
}
lib/rocketpool/contracts/interface/RocketStorageInterface.sol
pragma solidity >0.5.0 <0.9.0;
// SPDX-License-Identifier: GPL-3.0-only
interface RocketStorageInterface {
// Deploy status
function getDeployedStatus() external view returns (bool);
// Guardian
function getGuardian() external view returns(address);
function setGuardian(address _newAddress) external;
function confirmGuardian() external;
// Getters
function getAddress(bytes32 _key) external view returns (address);
function getUint(bytes32 _key) external view returns (uint);
function getString(bytes32 _key) external view returns (string memory);
function getBytes(bytes32 _key) external view returns (bytes memory);
function getBool(bytes32 _key) external view returns (bool);
function getInt(bytes32 _key) external view returns (int);
function getBytes32(bytes32 _key) external view returns (bytes32);
// Setters
function setAddress(bytes32 _key, address _value) external;
function setUint(bytes32 _key, uint _value) external;
function setString(bytes32 _key, string calldata _value) external;
function setBytes(bytes32 _key, bytes calldata _value) external;
function setBool(bytes32 _key, bool _value) external;
function setInt(bytes32 _key, int _value) external;
function setBytes32(bytes32 _key, bytes32 _value) external;
// Deleters
function deleteAddress(bytes32 _key) external;
function deleteUint(bytes32 _key) external;
function deleteString(bytes32 _key) external;
function deleteBytes(bytes32 _key) external;
function deleteBool(bytes32 _key) external;
function deleteInt(bytes32 _key) external;
function deleteBytes32(bytes32 _key) external;
// Arithmetic
function addUint(bytes32 _key, uint256 _amount) external;
function subUint(bytes32 _key, uint256 _amount) external;
// Protected storage
function getNodeWithdrawalAddress(address _nodeAddress) external view returns (address);
function getNodePendingWithdrawalAddress(address _nodeAddress) external view returns (address);
function setWithdrawalAddress(address _nodeAddress, address _newWithdrawalAddress, bool _confirm) external;
function confirmWithdrawalAddress(address _nodeAddress) external;
}
lib/rocketpool/contracts/interface/network/RocketNetworkBalancesInterface.sol
pragma solidity >0.5.0 <0.9.0;
// SPDX-License-Identifier: GPL-3.0-only
interface RocketNetworkBalancesInterface {
function getBalancesBlock() external view returns (uint256);
function getLatestReportableBlock() external view returns (uint256);
function getTotalETHBalance() external view returns (uint256);
function getStakingETHBalance() external view returns (uint256);
function getTotalRETHSupply() external view returns (uint256);
function getETHUtilizationRate() external view returns (uint256);
function submitBalances(uint256 _block, uint256 _total, uint256 _staking, uint256 _rethSupply) external;
function executeUpdateBalances(uint256 _block, uint256 _totalEth, uint256 _stakingEth, uint256 _rethSupply) external;
}
src/RocketOvmPriceMessenger.sol
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.13;
import "@rocketpool/interface/RocketStorageInterface.sol";
import "@rocketpool/interface/network/RocketNetworkBalancesInterface.sol";
import "@eth-optimism/contracts/libraries/bridge/ICrossDomainMessenger.sol";
import "./RocketOvmPriceOracle.sol";
/// @author Kane Wallmann (Rocket Pool)
/// @notice Retrieves the rETH exchange rate from Rocket Pool and submits it to the oracle contract on OVM
contract RocketOvmPriceMessenger {
// Immutables
ICrossDomainMessenger immutable ovmL1CrossDomainMessenger;
RocketStorageInterface immutable rocketStorage;
RocketOvmPriceOracle immutable rocketL2OvmPriceOracle;
bytes32 immutable rocketNetworkBalancesKey;
/// @notice The most recently submitted rate
uint256 lastRate;
constructor(RocketStorageInterface _rocketStorage, RocketOvmPriceOracle _rocketL2OvmPriceOracle, ICrossDomainMessenger _ovmL1CrossDomainMessenger) {
rocketStorage = _rocketStorage;
rocketL2OvmPriceOracle = _rocketL2OvmPriceOracle;
ovmL1CrossDomainMessenger = _ovmL1CrossDomainMessenger;
// Precompute storage key for RocketNetworkBalances address
rocketNetworkBalancesKey = keccak256(abi.encodePacked("contract.address", "rocketNetworkBalances"));
}
/// @notice Returns whether the rate has changed since it was last submitted
function rateStale() external view returns (bool) {
return rate() != lastRate;
}
/// @notice Returns the calculated rETH exchange rate
function rate() public view returns (uint256) {
// Retrieve the inputs from RocketNetworkBalances and calculate the rate
RocketNetworkBalancesInterface rocketNetworkBalances = RocketNetworkBalancesInterface(rocketStorage.getAddress(rocketNetworkBalancesKey));
uint256 supply = rocketNetworkBalances.getTotalRETHSupply();
if (supply == 0) {
return 0;
}
return 1 ether * rocketNetworkBalances.getTotalETHBalance() / supply;
}
/// @notice Submits the current rETH exchange rate to the OVM cross domain messenger contract
function submitRate() external {
lastRate = rate();
// Send the cross chain message
ovmL1CrossDomainMessenger.sendMessage(
address(rocketL2OvmPriceOracle),
abi.encodeWithSelector(
rocketL2OvmPriceOracle.updateRate.selector,
lastRate
),
500000
);
}
}
src/RocketOvmPriceOracle.sol
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.13;
import "@eth-optimism/contracts/libraries/bridge/ICrossDomainMessenger.sol";
/// @author Kane Wallmann (Rocket Pool)
/// @notice Receives updates from L1 on the canonical rETH exchange rate
contract RocketOvmPriceOracle {
// Events
event RateUpdated(uint256 rate);
// Immutables
ICrossDomainMessenger immutable ovmL2CrossDomainMessenger;
/// @notice The rETH exchange rate in the form of how much ETH 1 rETH is worth
uint256 public rate;
/// @notice The timestamp of the block in which the rate was last updated
uint256 public lastUpdated;
/// @notice Set to the contract on L1 that has permission to update the rate
address public owner;
constructor(address _l2CrossDomainMessenger) {
ovmL2CrossDomainMessenger = ICrossDomainMessenger(_l2CrossDomainMessenger);
owner = msg.sender;
}
/// @notice Hands ownership to the L1 price messenger contract
function setOwner(address _newOwner) external {
require(msg.sender == owner, "Only owner");
owner = _newOwner;
}
/// @notice Called by the messenger contract on L1 to update the exchange rate
function updateRate(uint256 _newRate) external {
// Only calls originating from L1 owner can update the rate
require(
msg.sender == address(ovmL2CrossDomainMessenger)
&& ovmL2CrossDomainMessenger.xDomainMessageSender() == owner,
"Only owner"
);
// Set rate and last updated timestamp
rate = _newRate;
lastUpdated = block.timestamp;
// Emit event
emit RateUpdated(_newRate);
}
}
src/interfaces/IWRETH.sol
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.13;
///@dev Partial interface for WRETH exposing the rebase function
interface IWRETH {
function rebase() external;
}
Настройки компилятораПоказать
{
"metadata": {
"bytecodeHash": "ipfs"
},
"libraries": {},
"optimizer": {
"runs": 10000,
"enabled": false
},
"evmVersion": "paris",
"remappings": [
":@eth-optimism/=lib/optimism/packages/contracts/",
":@rocketpool/=lib/rocketpool/contracts/",
":ds-test/=lib/forge-std/lib/ds-test/src/",
":erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
":forge-std/=lib/forge-std/src/",
":fx-portal/=lib/fx-portal/contracts/",
":openzeppelin-contracts/=lib/openzeppelin-contracts/",
":optimism/=lib/optimism/",
":rocketpool/=lib/rocketpool/",
":v2-testnet-contracts/=lib/v2-testnet-contracts/"
]
}Исходный код и метаданные: Sourcify.
Исходный код принадлежит авторам контракта.