// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import {ConfirmedOwner} from "../../shared/access/ConfirmedOwner.sol"; import {CrossDomainOwnableInterface} from "./interfaces/CrossDomainOwnableInterface.sol"; /** * @title The CrossDomainOwnable contract * @notice A contract with helpers for cross-domain contract ownership. */ contract CrossDomainOwnable is CrossDomainOwnableInterface, ConfirmedOwner { address internal s_l1Owner; address internal s_l1PendingOwner; constructor(address newl1Owner) ConfirmedOwner(msg.sender) { _setL1Owner(newl1Owner); } /** * @notice transfer ownership of this account to a new L1 owner * @param to new L1 owner that will be allowed to call the forward fn */ function transferL1Ownership(address to) public virtual override onlyL1Owner { _transferL1Ownership(to); } /** * @notice accept ownership of this account to a new L1 owner */ function acceptL1Ownership() public virtual override onlyProposedL1Owner { _setL1Owner(s_l1PendingOwner); } /** * @notice Get the current owner */ function l1Owner() public view override returns (address) { return s_l1Owner; } /** * @notice validate, transfer ownership, and emit relevant events */ function _transferL1Ownership(address to) internal { // solhint-disable-next-line gas-custom-errors require(to != msg.sender, "Cannot transfer to self"); s_l1PendingOwner = to; emit L1OwnershipTransferRequested(s_l1Owner, to); } /** * @notice set ownership, emit relevant events. Used in acceptOwnership() */ function _setL1Owner(address to) internal { address oldOwner = s_l1Owner; s_l1Owner = to; s_l1PendingOwner = address(0); emit L1OwnershipTransferred(oldOwner, to); } /** * @notice Reverts if called by anyone other than the L1 owner. */ modifier onlyL1Owner() virtual { // solhint-disable-next-line gas-custom-errors require(msg.sender == s_l1Owner, "Only callable by L1 owner"); _; } /** * @notice Reverts if called by anyone other than the L1 owner. */ modifier onlyProposedL1Owner() virtual { // solhint-disable-next-line gas-custom-errors require(msg.sender == s_l1PendingOwner, "Only callable by proposed L1 owner"); _; } }