// SPDX-License-Identifier: MIT pragma solidity ^0.8.24; import {SystemInit} from "./System.sol"; /// Genesis contract at 0x..b001. Locks native coin for withdrawal to BNB Chain and owns the shared withdrawal nonce. /// Every Withdrawal event (kinds 0, 1, 2) is emitted from this address. contract SystemBridge is SystemInit { address public dollar; address public slabs; uint256 public withdrawalCount; // last nonce used; nonces start at 1 event Withdrawal(uint256 indexed nonce, uint8 kind, address token, uint256 amountOrId, address indexed to); error NotAuthorized(); error ZeroAmount(); error ZeroAddress(); function initialize(address dollar_, address slabs_) external initializer { if (dollar_ == address(0) || slabs_ == address(0)) revert ZeroAddress(); dollar = dollar_; slabs = slabs_; } modifier onlyAssets() { if (msg.sender != dollar && msg.sender != slabs) revert NotAuthorized(); _; } /// Locks msg.value of native coin in this contract and emits a kind 0 withdrawal. function withdrawGas(address to) external payable whenInitialized returns (uint256 nonce) { if (msg.value == 0) revert ZeroAmount(); if (to == address(0)) revert ZeroAddress(); nonce = ++withdrawalCount; emit Withdrawal(nonce, 0, address(0), msg.value, to); } /// Reserves the next shared withdrawal nonce. Only the dollar and slab contracts. function nextNonce() external onlyAssets returns (uint256) { return ++withdrawalCount; } /// Reserves the next nonce and emits the Withdrawal event from the bridge. Only the dollar and slab contracts. function recordWithdrawal(uint8 kind, address token, uint256 amountOrId, address to) external onlyAssets returns (uint256 nonce) { nonce = ++withdrawalCount; emit Withdrawal(nonce, kind, token, amountOrId, to); } }