ChainBlock.sol
28 lines · sha256 58890fc25b2f7abfb0f989204bf2595d074f827f3a43b6469a1936413473f0c8 · Raw
| 1 | // SPDX-License-Identifier: MIT |
| 2 | pragma solidity ^0.8.26; |
| 3 | |
| 4 | /// @dev Arbitrum Nitro precompile. On an Orbit chain, `block.number` returns the PARENT chain block, |
| 5 | /// `ArbSys(0x64).arbBlockNumber()` returns the L2 block. |
| 6 | interface IArbSys { |
| 7 | function arbBlockNumber() external view returns (uint256); |
| 8 | } |
| 9 | |
| 10 | /// @title ChainBlock |
| 11 | /// @notice Single source of the protocol block number. Every "block" in the KIBBLE docs (eras, power per block, |
| 12 | /// TWAP window, preorder end, empty block) is an Elysium L2 block. |
| 13 | /// @dev Elysium (99901) and Elysium testnet (99801) are Arbitrum Orbit chains: `block.number` there is the |
| 14 | /// HyperEVM (parent) block number, so we read ArbSys. Any other chain (local forge tests) uses `block.number`. |
| 15 | /// Raw `block.number` must not be used anywhere else in the protocol. |
| 16 | library ChainBlock { |
| 17 | address internal constant ARB_SYS = address(100); |
| 18 | uint256 internal constant ELYSIUM = 99901; |
| 19 | uint256 internal constant ELYSIUM_TESTNET = 99801; |
| 20 | |
| 21 | function number() internal view returns (uint256) { |
| 22 | if (block.chainid == ELYSIUM || block.chainid == ELYSIUM_TESTNET) { |
| 23 | return IArbSys(ARB_SYS).arbBlockNumber(); |
| 24 | } |
| 25 | return block.number; |
| 26 | } |
| 27 | } |
| 28 |