Address Details
contract

0xAD96a2E125F6c071B4BE9bd00177BA46D1F2c9d2

Contract Name
BridgeRouter
Creator
0x60f78e–600437 at 0xb301a4–b3059b
Balance
0 CELO ( )
Locked CELO Balance
0.00 CELO
Voting CELO Balance
0.00 CELO
Pending Unlocked Gold
0.00 CELO
Tokens
Fetching tokens...
Transactions
0 Transactions
Transfers
0 Transfers
Gas Used
Fetching gas used...
Last Balance Update
24742536
This contract has been verified via Sourcify. View contract in Sourcify repository
Contract name:
BridgeRouter




Optimization enabled
true
Compiler version
v0.7.6+commit.7338295f




Optimization runs
999999
EVM Version
istanbul




Verified at
2022-05-05T13:51:32.773595Z

contracts/bridge/BridgeRouter.sol

// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;

// ============ Internal Imports ============
import {TokenRegistry} from "./TokenRegistry.sol";
import {Router} from "../Router.sol";
import {XAppConnectionClient} from "../XAppConnectionClient.sol";
import {IBridgeToken} from "../../interfaces/bridge/IBridgeToken.sol";
import {BridgeMessage} from "./BridgeMessage.sol";
// ============ External Imports ============
import {Home} from "@celo-org/optics-sol/contracts/Home.sol";
import {Version0} from "@celo-org/optics-sol/contracts/Version0.sol";
import {TypeCasts} from "@celo-org/optics-sol/contracts/XAppConnectionManager.sol";
import {TypedMemView} from "@summa-tx/memview-sol/contracts/TypedMemView.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";

/**
 * @title BridgeRouter
 */
contract BridgeRouter is Version0, Router, TokenRegistry {
    // ============ Libraries ============

    using TypedMemView for bytes;
    using TypedMemView for bytes29;
    using BridgeMessage for bytes29;
    using SafeERC20 for IERC20;

    // ============ Constants ============

    // 5 bps (0.05%) hardcoded fast liquidity fee. Can be changed by contract upgrade
    uint256 public constant PRE_FILL_FEE_NUMERATOR = 9995;
    uint256 public constant PRE_FILL_FEE_DENOMINATOR = 10000;

    // ============ Public Storage ============

    // token transfer prefill ID => LP that pre-filled message to provide fast liquidity
    mapping(bytes32 => address) public liquidityProvider;

    // ============ Upgrade Gap ============

    // gap for upgrade safety
    uint256[49] private __GAP;

    // ======== Events =========

    /**
     * @notice emitted when tokens are sent from this domain to another domain
     * @param token the address of the token contract
     * @param from the address sending tokens
     * @param toDomain the domain of the chain the tokens are being sent to
     * @param toId the bytes32 address of the recipient of the tokens
     * @param amount the amount of tokens sent
     */
    event Send(
        address indexed token,
        address indexed from,
        uint32 indexed toDomain,
        bytes32 toId,
        uint256 amount
    );

    // ======== Initializer ========

    function initialize(address _tokenBeacon, address _xAppConnectionManager)
        public
        initializer
    {
        __TokenRegistry_initialize(_tokenBeacon);
        __XAppConnectionClient_initialize(_xAppConnectionManager);
    }

    // ======== External: Handle =========

    /**
     * @notice Handles an incoming message
     * @param _origin The origin domain
     * @param _sender The sender address
     * @param _message The message
     */
    function handle(
        uint32 _origin,
        bytes32 _sender,
        bytes memory _message
    ) external override onlyReplica onlyRemoteRouter(_origin, _sender) {
        // parse tokenId and action from message
        bytes29 _msg = _message.ref(0).mustBeMessage();
        bytes29 _tokenId = _msg.tokenId();
        bytes29 _action = _msg.action();
        // handle message based on the intended action
        if (_action.isTransfer()) {
            _handleTransfer(_tokenId, _action);
        } else if (_action.isDetails()) {
            _handleDetails(_tokenId, _action);
        } else if (_action.isRequestDetails()) {
            _handleRequestDetails(_origin, _sender, _tokenId);
        } else {
            require(false, "!valid action");
        }
    }

    // ======== External: Request Token Details =========

    /**
     * @notice Request updated token metadata from another chain
     * @dev This is only owner to prevent abuse and spam. Requesting details
     *  should be done automatically on token instantiation
     * @param _domain The domain where that token is native
     * @param _id The token id on that domain
     */
    function requestDetails(uint32 _domain, bytes32 _id) external onlyOwner {
        bytes29 _tokenId = BridgeMessage.formatTokenId(_domain, _id);
        _requestDetails(_tokenId);
    }

    // ======== External: Send Token =========

    /**
     * @notice Send tokens to a recipient on a remote chain
     * @param _token The token address
     * @param _amount The token amount
     * @param _destination The destination domain
     * @param _recipient The recipient address
     */
    function send(
        address _token,
        uint256 _amount,
        uint32 _destination,
        bytes32 _recipient
    ) external {
        require(_amount > 0, "!amnt");
        require(_recipient != bytes32(0), "!recip");
        // get remote BridgeRouter address; revert if not found
        bytes32 _remote = _mustHaveRemote(_destination);
        // remove tokens from circulation on this chain
        IERC20 _bridgeToken = IERC20(_token);
        if (_isLocalOrigin(_bridgeToken)) {
            // if the token originates on this chain, hold the tokens in escrow
            // in the Router
            _bridgeToken.safeTransferFrom(msg.sender, address(this), _amount);
        } else {
            // if the token originates on a remote chain, burn the
            // representation tokens on this chain
            _downcast(_bridgeToken).burn(msg.sender, _amount);
        }
        // format Transfer Tokens action
        bytes29 _action = BridgeMessage.formatTransfer(_recipient, _amount);
        // send message to remote chain via Optics
        Home(xAppConnectionManager.home()).dispatch(
            _destination,
            _remote,
            BridgeMessage.formatMessage(_formatTokenId(_token), _action)
        );
        // emit Send event to record token sender
        emit Send(
            address(_bridgeToken),
            msg.sender,
            _destination,
            _recipient,
            _amount
        );
    }

    // ======== External: Fast Liquidity =========

    /**
     * @notice Allows a liquidity provider to give an
     * end user fast liquidity by pre-filling an
     * incoming transfer message.
     * Transfers tokens from the liquidity provider to the end recipient, minus the LP fee;
     * Records the liquidity provider, who receives
     * the full token amount when the transfer message is handled.
     * @dev fast liquidity can only be provided for ONE token transfer
     * with the same (recipient, amount) at a time.
     * in the case that multiple token transfers with the same (recipient, amount)
     * @param _message The incoming transfer message to pre-fill
     */
    function preFill(bytes calldata _message) external {
        // parse tokenId and action from message
        bytes29 _msg = _message.ref(0).mustBeMessage();
        bytes29 _tokenId = _msg.tokenId().mustBeTokenId();
        bytes29 _action = _msg.action().mustBeTransfer();
        // calculate prefill ID
        bytes32 _id = _preFillId(_tokenId, _action);
        // require that transfer has not already been pre-filled
        require(liquidityProvider[_id] == address(0), "!unfilled");
        // record liquidity provider
        liquidityProvider[_id] = msg.sender;
        // transfer tokens from liquidity provider to token recipient
        IERC20 _token = _mustHaveToken(_tokenId);
        _token.safeTransferFrom(
            msg.sender,
            _action.evmRecipient(),
            _applyPreFillFee(_action.amnt())
        );
    }

    // ======== External: Custom Tokens =========

    /**
     * @notice Enroll a custom token. This allows projects to work with
     * governance to specify a custom representation.
     * @dev This is done by inserting the custom representation into the token
     * lookup tables. It is permissioned to the owner (governance) and can
     * potentially break token representations. It must be used with extreme
     * caution.
     * After the token is inserted, new mint instructions will be sent to the
     * custom token. The default representation (and old custom representations)
     * may still be burnt. Until all users have explicitly called migrate, both
     * representations will continue to exist.
     * The custom representation MUST be trusted, and MUST allow the router to
     * both mint AND burn tokens at will.
     * @param _id the canonical ID of the Token to enroll, as a byte vector
     * @param _custom the address of the custom implementation to use.
     */
    function enrollCustom(
        uint32 _domain,
        bytes32 _id,
        address _custom
    ) external onlyOwner {
        // Sanity check. Ensures that human error doesn't cause an
        // unpermissioned contract to be enrolled.
        IBridgeToken(_custom).mint(address(this), 1);
        IBridgeToken(_custom).burn(address(this), 1);
        // update mappings with custom token
        bytes29 _tokenId = BridgeMessage.formatTokenId(_domain, _id);
        representationToCanonical[_custom].domain = _tokenId.domain();
        representationToCanonical[_custom].id = _tokenId.id();
        bytes32 _idHash = _tokenId.keccak();
        canonicalToRepresentation[_idHash] = _custom;
    }

    /**
     * @notice Migrate all tokens in a previous representation to the latest
     * custom representation. This works by looking up local mappings and then
     * burning old tokens and minting new tokens.
     * @dev This is explicitly opt-in to allow dapps to decide when and how to
     * upgrade to the new representation.
     * @param _oldRepr The address of the old token to migrate
     */
    function migrate(address _oldRepr) external {
        // get the token ID for the old token contract
        TokenId memory _id = representationToCanonical[_oldRepr];
        require(_id.domain != 0, "!repr");
        // ensure that new token & old token are different
        IBridgeToken _old = IBridgeToken(_oldRepr);
        IBridgeToken _new = _representationForCanonical(_id);
        require(_new != _old, "!different");
        // burn the old tokens & mint the new ones
        uint256 _bal = _old.balanceOf(msg.sender);
        _old.burn(msg.sender, _bal);
        _new.mint(msg.sender, _bal);
    }

    // ============ Internal: Send / UpdateDetails ============

    /**
     * @notice Given a tokenAddress, format the tokenId
     * identifier for the message.
     * @param _token The token address
     * @param _tokenId The bytes-encoded tokenId
     */
    function _formatTokenId(address _token)
        internal
        view
        returns (bytes29 _tokenId)
    {
        TokenId memory _tokId = _tokenIdFor(_token);
        _tokenId = BridgeMessage.formatTokenId(_tokId.domain, _tokId.id);
    }

    // ============ Internal: Handle ============

    /**
     * @notice Handles an incoming Transfer message.
     *
     * If the token is of local origin, the amount is sent from escrow.
     * Otherwise, a representation token is minted.
     *
     * @param _tokenId The token ID
     * @param _action The action
     */
    function _handleTransfer(bytes29 _tokenId, bytes29 _action) internal {
        // get the token contract for the given tokenId on this chain;
        // (if the token is of remote origin and there is
        // no existing representation token contract, the TokenRegistry will
        // deploy a new one)
        IERC20 _token = _ensureToken(_tokenId);
        address _recipient = _action.evmRecipient();
        // If an LP has prefilled this token transfer,
        // send the tokens to the LP instead of the recipient
        bytes32 _id = _preFillId(_tokenId, _action);
        address _lp = liquidityProvider[_id];
        if (_lp != address(0)) {
            _recipient = _lp;
            delete liquidityProvider[_id];
        }
        // send the tokens into circulation on this chain
        if (_isLocalOrigin(_token)) {
            // if the token is of local origin, the tokens have been held in
            // escrow in this contract
            // while they have been circulating on remote chains;
            // transfer the tokens to the recipient
            _token.safeTransfer(_recipient, _action.amnt());
        } else {
            // if the token is of remote origin, mint the tokens to the
            // recipient on this chain
            _downcast(_token).mint(_recipient, _action.amnt());
        }
    }

    /**
     * @notice Handles an incoming Details message.
     * @param _tokenId The token ID
     * @param _action The action
     */
    function _handleDetails(bytes29 _tokenId, bytes29 _action) internal {
        // get the token contract deployed on this chain
        // revert if no token contract exists
        IERC20 _token = _mustHaveToken(_tokenId);
        // require that the token is of remote origin
        // (otherwise, the BridgeRouter did not deploy the token contract,
        // and therefore cannot update its metadata)
        require(!_isLocalOrigin(_token), "!remote origin");
        // update the token metadata
        _downcast(_token).setDetails(
            TypeCasts.coerceString(_action.name()),
            TypeCasts.coerceString(_action.symbol()),
            _action.decimals()
        );
    }

    /**
     * @notice Handles an incoming RequestDetails message by sending an
     *         UpdateDetails message to the remote chain
     * @dev The origin and remote are pre-checked by the handle function
     *      `onlyRemoteRouter` modifier and can be used without additional check
     * @param _messageOrigin The domain from which the message arrived
     * @param _messageRemoteRouter The remote router that sent the message
     * @param _tokenId The token ID
     */
    function _handleRequestDetails(
        uint32 _messageOrigin,
        bytes32 _messageRemoteRouter,
        bytes29 _tokenId
    ) internal {
        // get token & ensure is of local origin
        address _token = _tokenId.evmId();
        require(_isLocalOrigin(_token), "!local origin");
        IBridgeToken _bridgeToken = IBridgeToken(_token);
        // format Update Details message
        bytes29 _updateDetailsAction = BridgeMessage.formatDetails(
            TypeCasts.coerceBytes32(_bridgeToken.name()),
            TypeCasts.coerceBytes32(_bridgeToken.symbol()),
            _bridgeToken.decimals()
        );
        // send message to remote chain via Optics
        Home(xAppConnectionManager.home()).dispatch(
            _messageOrigin,
            _messageRemoteRouter,
            BridgeMessage.formatMessage(_tokenId, _updateDetailsAction)
        );
    }

    // ============ Internal: Transfer ============

    function _ensureToken(bytes29 _tokenId) internal returns (IERC20) {
        address _local = _getTokenAddress(_tokenId);
        if (_local == address(0)) {
            // Representation does not exist yet;
            // deploy representation contract
            _local = _deployToken(_tokenId);
            // message the origin domain
            // to request the token details
            _requestDetails(_tokenId);
        }
        return IERC20(_local);
    }

    // ============ Internal: Request Details ============

    /**
     * @notice Handles an incoming Details message.
     * @param _tokenId The token ID
     */
    function _requestDetails(bytes29 _tokenId) internal {
        uint32 _destination = _tokenId.domain();
        // get remote BridgeRouter address; revert if not found
        bytes32 _remote = remotes[_destination];
        if (_remote == bytes32(0)) {
            return;
        }
        // format Request Details message
        bytes29 _action = BridgeMessage.formatRequestDetails();
        // send message to remote chain via Optics
        Home(xAppConnectionManager.home()).dispatch(
            _destination,
            _remote,
            BridgeMessage.formatMessage(_tokenId, _action)
        );
    }

    // ============ Internal: Fast Liquidity ============

    /**
     * @notice Calculate the token amount after
     * taking a 5 bps (0.05%) liquidity provider fee
     * @param _amnt The token amount before the fee is taken
     * @return _amtAfterFee The token amount after the fee is taken
     */
    function _applyPreFillFee(uint256 _amnt)
        internal
        pure
        returns (uint256 _amtAfterFee)
    {
        // overflow only possible if (2**256 / 9995) tokens sent once
        // in which case, probably not a real token
        _amtAfterFee =
            (_amnt * PRE_FILL_FEE_NUMERATOR) /
            PRE_FILL_FEE_DENOMINATOR;
    }

    /**
     * @notice get the prefillId used to identify
     * fast liquidity provision for incoming token send messages
     * @dev used to identify a token/transfer pair in the prefill LP mapping.
     * NOTE: This approach has a weakness: a user can receive >1 batch of tokens of
     * the same size, but only 1 will be eligible for fast liquidity. The
     * other may only be filled at regular speed. This is because the messages
     * will have identical `tokenId` and `action` fields. This seems fine,
     * tbqh. A delay of a few hours on a corner case is acceptable in v1.
     * @param _tokenId The token ID
     * @param _action The action
     */
    function _preFillId(bytes29 _tokenId, bytes29 _action)
        internal
        view
        returns (bytes32)
    {
        bytes29[] memory _views = new bytes29[](2);
        _views[0] = _tokenId;
        _views[1] = _action;
        return TypedMemView.joinKeccak(_views);
    }

    /**
     * @dev explicit override for compiler inheritance
     * @dev explicit override for compiler inheritance
     * @return domain of chain on which the contract is deployed
     */
    function _localDomain()
        internal
        view
        override(TokenRegistry, XAppConnectionClient)
        returns (uint32)
    {
        return XAppConnectionClient._localDomain();
    }
}
        

/_celo-org/optics-sol/contracts/Common.sol

// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;

// ============ Internal Imports ============
import {Message} from "../libs/Message.sol";
// ============ External Imports ============
import {ECDSA} from "@openzeppelin/contracts/cryptography/ECDSA.sol";
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/Initializable.sol";

/**
 * @title Common
 * @author Celo Labs Inc.
 * @notice Shared utilities between Home and Replica.
 */
abstract contract Common is Initializable {
    // ============ Enums ============

    // States:
    //   0 - UnInitialized - before initialize function is called
    //   note: the contract is initialized at deploy time, so it should never be in this state
    //   1 - Active - as long as the contract has not become fraudulent
    //   2 - Failed - after a valid fraud proof has been submitted;
    //   contract will no longer accept updates or new messages
    enum States {
        UnInitialized,
        Active,
        Failed
    }

    // ============ Immutable Variables ============

    // Domain of chain on which the contract is deployed
    uint32 public immutable localDomain;

    // ============ Public Variables ============

    // Address of bonded Updater
    address public updater;
    // Current state of contract
    States public state;
    // The latest root that has been signed by the Updater
    bytes32 public committedRoot;

    // ============ Upgrade Gap ============

    // gap for upgrade safety
    uint256[47] private __GAP;

    // ============ Events ============

    /**
     * @notice Emitted when update is made on Home
     * or unconfirmed update root is submitted on Replica
     * @param homeDomain Domain of home contract
     * @param oldRoot Old merkle root
     * @param newRoot New merkle root
     * @param signature Updater's signature on `oldRoot` and `newRoot`
     */
    event Update(
        uint32 indexed homeDomain,
        bytes32 indexed oldRoot,
        bytes32 indexed newRoot,
        bytes signature
    );

    /**
     * @notice Emitted when proof of a double update is submitted,
     * which sets the contract to FAILED state
     * @param oldRoot Old root shared between two conflicting updates
     * @param newRoot Array containing two conflicting new roots
     * @param signature Signature on `oldRoot` and `newRoot`[0]
     * @param signature2 Signature on `oldRoot` and `newRoot`[1]
     */
    event DoubleUpdate(
        bytes32 oldRoot,
        bytes32[2] newRoot,
        bytes signature,
        bytes signature2
    );

    // ============ Modifiers ============

    /**
     * @notice Ensures that contract state != FAILED when the function is called
     */
    modifier notFailed() {
        require(state != States.Failed, "failed state");
        _;
    }

    // ============ Constructor ============

    constructor(uint32 _localDomain) {
        localDomain = _localDomain;
    }

    // ============ Initializer ============

    function __Common_initialize(address _updater) internal initializer {
        updater = _updater;
        state = States.Active;
    }

    // ============ External Functions ============

    /**
     * @notice Called by external agent. Checks that signatures on two sets of
     * roots are valid and that the new roots conflict with each other. If both
     * cases hold true, the contract is failed and a `DoubleUpdate` event is
     * emitted.
     * @dev When `fail()` is called on Home, updater is slashed.
     * @param _oldRoot Old root shared between two conflicting updates
     * @param _newRoot Array containing two conflicting new roots
     * @param _signature Signature on `_oldRoot` and `_newRoot`[0]
     * @param _signature2 Signature on `_oldRoot` and `_newRoot`[1]
     */
    function doubleUpdate(
        bytes32 _oldRoot,
        bytes32[2] calldata _newRoot,
        bytes calldata _signature,
        bytes calldata _signature2
    ) external notFailed {
        if (
            Common._isUpdaterSignature(_oldRoot, _newRoot[0], _signature) &&
            Common._isUpdaterSignature(_oldRoot, _newRoot[1], _signature2) &&
            _newRoot[0] != _newRoot[1]
        ) {
            _fail();
            emit DoubleUpdate(_oldRoot, _newRoot, _signature, _signature2);
        }
    }

    // ============ Public Functions ============

    /**
     * @notice Hash of Home domain concatenated with "OPTICS"
     */
    function homeDomainHash() public view virtual returns (bytes32);

    // ============ Internal Functions ============

    /**
     * @notice Hash of Home domain concatenated with "OPTICS"
     * @param _homeDomain the Home domain to hash
     */
    function _homeDomainHash(uint32 _homeDomain)
        internal
        pure
        returns (bytes32)
    {
        return keccak256(abi.encodePacked(_homeDomain, "OPTICS"));
    }

    /**
     * @notice Set contract state to FAILED
     * @dev Called when a valid fraud proof is submitted
     */
    function _setFailed() internal {
        state = States.Failed;
    }

    /**
     * @notice Moves the contract into failed state
     * @dev Called when fraud is proven
     * (Double Update is submitted on Home or Replica,
     * or Improper Update is submitted on Home)
     */
    function _fail() internal virtual;

    /**
     * @notice Checks that signature was signed by Updater
     * @param _oldRoot Old merkle root
     * @param _newRoot New merkle root
     * @param _signature Signature on `_oldRoot` and `_newRoot`
     * @return TRUE iff signature is valid signed by updater
     **/
    function _isUpdaterSignature(
        bytes32 _oldRoot,
        bytes32 _newRoot,
        bytes memory _signature
    ) internal view returns (bool) {
        bytes32 _digest = keccak256(
            abi.encodePacked(homeDomainHash(), _oldRoot, _newRoot)
        );
        _digest = ECDSA.toEthSignedMessageHash(_digest);
        return (ECDSA.recover(_digest, _signature) == updater);
    }
}
          

/_celo-org/optics-sol/contracts/Home.sol

// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;

// ============ Internal Imports ============
import {Version0} from "./Version0.sol";
import {Common} from "./Common.sol";
import {QueueLib} from "../libs/Queue.sol";
import {MerkleLib} from "../libs/Merkle.sol";
import {Message} from "../libs/Message.sol";
import {MerkleTreeManager} from "./Merkle.sol";
import {QueueManager} from "./Queue.sol";
import {IUpdaterManager} from "../interfaces/IUpdaterManager.sol";
// ============ External Imports ============
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";

/**
 * @title Home
 * @author Celo Labs Inc.
 * @notice Accepts messages to be dispatched to remote chains,
 * constructs a Merkle tree of the messages,
 * and accepts signatures from a bonded Updater
 * which notarize the Merkle tree roots.
 * Accepts submissions of fraudulent signatures
 * by the Updater and slashes the Updater in this case.
 */
contract Home is
    Version0,
    QueueManager,
    MerkleTreeManager,
    Common,
    OwnableUpgradeable
{
    // ============ Libraries ============

    using QueueLib for QueueLib.Queue;
    using MerkleLib for MerkleLib.Tree;

    // ============ Constants ============

    // Maximum bytes per message = 2 KiB
    // (somewhat arbitrarily set to begin)
    uint256 public constant MAX_MESSAGE_BODY_BYTES = 2 * 2**10;

    // ============ Public Storage Variables ============

    // domain => next available nonce for the domain
    mapping(uint32 => uint32) public nonces;
    // contract responsible for Updater bonding, slashing and rotation
    IUpdaterManager public updaterManager;

    // ============ Upgrade Gap ============

    // gap for upgrade safety
    uint256[48] private __GAP;

    // ============ Events ============

    /**
     * @notice Emitted when a new message is dispatched via Optics
     * @param leafIndex Index of message's leaf in merkle tree
     * @param destinationAndNonce Destination and destination-specific
     * nonce combined in single field ((destination << 32) & nonce)
     * @param messageHash Hash of message; the leaf inserted to the Merkle tree for the message
     * @param committedRoot the latest notarized root submitted in the last signed Update
     * @param message Raw bytes of message
     */
    event Dispatch(
        bytes32 indexed messageHash,
        uint256 indexed leafIndex,
        uint64 indexed destinationAndNonce,
        bytes32 committedRoot,
        bytes message
    );

    /**
     * @notice Emitted when proof of an improper update is submitted,
     * which sets the contract to FAILED state
     * @param oldRoot Old root of the improper update
     * @param newRoot New root of the improper update
     * @param signature Signature on `oldRoot` and `newRoot
     */
    event ImproperUpdate(bytes32 oldRoot, bytes32 newRoot, bytes signature);

    /**
     * @notice Emitted when the Updater is slashed
     * (should be paired with ImproperUpdater or DoubleUpdate event)
     * @param updater The address of the updater
     * @param reporter The address of the entity that reported the updater misbehavior
     */
    event UpdaterSlashed(address indexed updater, address indexed reporter);

    /**
     * @notice Emitted when Updater is rotated by the UpdaterManager
     * @param updater The address of the new updater
     */
    event NewUpdater(address updater);

    /**
     * @notice Emitted when the UpdaterManager contract is changed
     * @param updaterManager The address of the new updaterManager
     */
    event NewUpdaterManager(address updaterManager);

    // ============ Constructor ============

    constructor(uint32 _localDomain) Common(_localDomain) {} // solhint-disable-line no-empty-blocks

    // ============ Initializer ============

    function initialize(IUpdaterManager _updaterManager) public initializer {
        // initialize owner & queue
        __Ownable_init();
        __QueueManager_initialize();
        // set Updater Manager contract and initialize Updater
        _setUpdaterManager(_updaterManager);
        address _updater = updaterManager.updater();
        __Common_initialize(_updater);
        emit NewUpdater(_updater);
    }

    // ============ Modifiers ============

    /**
     * @notice Ensures that function is called by the UpdaterManager contract
     */
    modifier onlyUpdaterManager() {
        require(msg.sender == address(updaterManager), "!updaterManager");
        _;
    }

    // ============ External: Updater & UpdaterManager Configuration  ============

    /**
     * @notice Set a new Updater
     * @param _updater the new Updater
     */
    function setUpdater(address _updater) external onlyUpdaterManager {
        _setUpdater(_updater);
    }

    /**
     * @notice Set a new UpdaterManager contract
     * @dev Home(s) will initially be initialized using a trusted UpdaterManager contract;
     * we will progressively decentralize by swapping the trusted contract with a new implementation
     * that implements Updater bonding & slashing, and rules for Updater selection & rotation
     * @param _updaterManager the new UpdaterManager contract
     */
    function setUpdaterManager(address _updaterManager) external onlyOwner {
        _setUpdaterManager(IUpdaterManager(_updaterManager));
    }

    // ============ External Functions  ============

    /**
     * @notice Dispatch the message it to the destination domain & recipient
     * @dev Format the message, insert its hash into Merkle tree,
     * enqueue the new Merkle root, and emit `Dispatch` event with message information.
     * @param _destinationDomain Domain of destination chain
     * @param _recipientAddress Address of recipient on destination chain as bytes32
     * @param _messageBody Raw bytes content of message
     */
    function dispatch(
        uint32 _destinationDomain,
        bytes32 _recipientAddress,
        bytes memory _messageBody
    ) external notFailed {
        require(_messageBody.length <= MAX_MESSAGE_BODY_BYTES, "msg too long");
        // get the next nonce for the destination domain, then increment it
        uint32 _nonce = nonces[_destinationDomain];
        nonces[_destinationDomain] = _nonce + 1;
        // format the message into packed bytes
        bytes memory _message = Message.formatMessage(
            localDomain,
            bytes32(uint256(uint160(msg.sender))),
            _nonce,
            _destinationDomain,
            _recipientAddress,
            _messageBody
        );
        // insert the hashed message into the Merkle tree
        bytes32 _messageHash = keccak256(_message);
        tree.insert(_messageHash);
        // enqueue the new Merkle root after inserting the message
        queue.enqueue(root());
        // Emit Dispatch event with message information
        // note: leafIndex is count() - 1 since new leaf has already been inserted
        emit Dispatch(
            _messageHash,
            count() - 1,
            _destinationAndNonce(_destinationDomain, _nonce),
            committedRoot,
            _message
        );
    }

    /**
     * @notice Submit a signature from the Updater "notarizing" a root,
     * which updates the Home contract's `committedRoot`,
     * and publishes the signature which will be relayed to Replica contracts
     * @dev emits Update event
     * @dev If _newRoot is not contained in the queue,
     * the Update is a fraudulent Improper Update, so
     * the Updater is slashed & Home is set to FAILED state
     * @param _committedRoot Current updated merkle root which the update is building off of
     * @param _newRoot New merkle root to update the contract state to
     * @param _signature Updater signature on `_committedRoot` and `_newRoot`
     */
    function update(
        bytes32 _committedRoot,
        bytes32 _newRoot,
        bytes memory _signature
    ) external notFailed {
        // check that the update is not fraudulent;
        // if fraud is detected, Updater is slashed & Home is set to FAILED state
        if (improperUpdate(_committedRoot, _newRoot, _signature)) return;
        // clear all of the intermediate roots contained in this update from the queue
        while (true) {
            bytes32 _next = queue.dequeue();
            if (_next == _newRoot) break;
        }
        // update the Home state with the latest signed root & emit event
        committedRoot = _newRoot;
        emit Update(localDomain, _committedRoot, _newRoot, _signature);
    }

    /**
     * @notice Suggest an update for the Updater to sign and submit.
     * @dev If queue is empty, null bytes returned for both
     * (No update is necessary because no messages have been dispatched since the last update)
     * @return _committedRoot Latest root signed by the Updater
     * @return _new Latest enqueued Merkle root
     */
    function suggestUpdate()
        external
        view
        returns (bytes32 _committedRoot, bytes32 _new)
    {
        if (queue.length() != 0) {
            _committedRoot = committedRoot;
            _new = queue.lastItem();
        }
    }

    // ============ Public Functions  ============

    /**
     * @notice Hash of Home domain concatenated with "OPTICS"
     */
    function homeDomainHash() public view override returns (bytes32) {
        return _homeDomainHash(localDomain);
    }

    /**
     * @notice Check if an Update is an Improper Update;
     * if so, slash the Updater and set the contract to FAILED state.
     *
     * An Improper Update is an update building off of the Home's `committedRoot`
     * for which the `_newRoot` does not currently exist in the Home's queue.
     * This would mean that message(s) that were not truly
     * dispatched on Home were falsely included in the signed root.
     *
     * An Improper Update will only be accepted as valid by the Replica
     * If an Improper Update is attempted on Home,
     * the Updater will be slashed immediately.
     * If an Improper Update is submitted to the Replica,
     * it should be relayed to the Home contract using this function
     * in order to slash the Updater with an Improper Update.
     *
     * An Improper Update submitted to the Replica is only valid
     * while the `_oldRoot` is still equal to the `committedRoot` on Home;
     * if the `committedRoot` on Home has already been updated with a valid Update,
     * then the Updater should be slashed with a Double Update.
     * @dev Reverts (and doesn't slash updater) if signature is invalid or
     * update not current
     * @param _oldRoot Old merkle tree root (should equal home's committedRoot)
     * @param _newRoot New merkle tree root
     * @param _signature Updater signature on `_oldRoot` and `_newRoot`
     * @return TRUE if update was an Improper Update (implying Updater was slashed)
     */
    function improperUpdate(
        bytes32 _oldRoot,
        bytes32 _newRoot,
        bytes memory _signature
    ) public notFailed returns (bool) {
        require(
            _isUpdaterSignature(_oldRoot, _newRoot, _signature),
            "!updater sig"
        );
        require(_oldRoot == committedRoot, "not a current update");
        // if the _newRoot is not currently contained in the queue,
        // slash the Updater and set the contract to FAILED state
        if (!queue.contains(_newRoot)) {
            _fail();
            emit ImproperUpdate(_oldRoot, _newRoot, _signature);
            return true;
        }
        // if the _newRoot is contained in the queue,
        // this is not an improper update
        return false;
    }

    // ============ Internal Functions  ============

    /**
     * @notice Set the UpdaterManager
     * @param _updaterManager Address of the UpdaterManager
     */
    function _setUpdaterManager(IUpdaterManager _updaterManager) internal {
        require(
            Address.isContract(address(_updaterManager)),
            "!contract updaterManager"
        );
        updaterManager = IUpdaterManager(_updaterManager);
        emit NewUpdaterManager(address(_updaterManager));
    }

    /**
     * @notice Set the Updater
     * @param _updater Address of the Updater
     */
    function _setUpdater(address _updater) internal {
        updater = _updater;
        emit NewUpdater(_updater);
    }

    /**
     * @notice Slash the Updater and set contract state to FAILED
     * @dev Called when fraud is proven (Improper Update or Double Update)
     */
    function _fail() internal override {
        // set contract to FAILED
        _setFailed();
        // slash Updater
        updaterManager.slashUpdater(msg.sender);
        emit UpdaterSlashed(updater, msg.sender);
    }

    /**
     * @notice Internal utility function that combines
     * `_destination` and `_nonce`.
     * @dev Both destination and nonce should be less than 2^32 - 1
     * @param _destination Domain of destination chain
     * @param _nonce Current nonce for given destination chain
     * @return Returns (`_destination` << 32) & `_nonce`
     */
    function _destinationAndNonce(uint32 _destination, uint32 _nonce)
        internal
        pure
        returns (uint64)
    {
        return (uint64(_destination) << 32) | _nonce;
    }
}
          

/_celo-org/optics-sol/contracts/Merkle.sol

// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;

// ============ Internal Imports ============
import {MerkleLib} from "../libs/Merkle.sol";

/**
 * @title MerkleTreeManager
 * @author Celo Labs Inc.
 * @notice Contains a Merkle tree instance and
 * exposes view functions for the tree.
 */
contract MerkleTreeManager {
    // ============ Libraries ============

    using MerkleLib for MerkleLib.Tree;
    MerkleLib.Tree public tree;

    // ============ Upgrade Gap ============

    // gap for upgrade safety
    uint256[49] private __GAP;

    // ============ Public Functions ============

    /**
     * @notice Calculates and returns tree's current root
     */
    function root() public view returns (bytes32) {
        return tree.root();
    }

    /**
     * @notice Returns the number of inserted leaves in the tree (current index)
     */
    function count() public view returns (uint256) {
        return tree.count;
    }
}
          

/_celo-org/optics-sol/contracts/Queue.sol

// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;

// ============ Internal Imports ============
import {QueueLib} from "../libs/Queue.sol";
// ============ External Imports ============
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/Initializable.sol";

/**
 * @title QueueManager
 * @author Celo Labs Inc.
 * @notice Contains a queue instance and
 * exposes view functions for the queue.
 **/
contract QueueManager is Initializable {
    // ============ Libraries ============

    using QueueLib for QueueLib.Queue;
    QueueLib.Queue internal queue;

    // ============ Upgrade Gap ============

    // gap for upgrade safety
    uint256[49] private __GAP;

    // ============ Initializer ============

    function __QueueManager_initialize() internal initializer {
        queue.initialize();
    }

    // ============ Public Functions ============

    /**
     * @notice Returns number of elements in queue
     */
    function queueLength() external view returns (uint256) {
        return queue.length();
    }

    /**
     * @notice Returns TRUE iff `_item` is in the queue
     */
    function queueContains(bytes32 _item) external view returns (bool) {
        return queue.contains(_item);
    }

    /**
     * @notice Returns last item enqueued to the queue
     */
    function queueEnd() external view returns (bytes32) {
        return queue.lastItem();
    }
}
          

/_celo-org/optics-sol/contracts/Replica.sol

// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;

// ============ Internal Imports ============
import {Version0} from "./Version0.sol";
import {Common} from "./Common.sol";
import {MerkleLib} from "../libs/Merkle.sol";
import {Message} from "../libs/Message.sol";
import {IMessageRecipient} from "../interfaces/IMessageRecipient.sol";
// ============ External Imports ============
import {TypedMemView} from "@summa-tx/memview-sol/contracts/TypedMemView.sol";

/**
 * @title Replica
 * @author Celo Labs Inc.
 * @notice Track root updates on Home,
 * prove and dispatch messages to end recipients.
 */
contract Replica is Version0, Common {
    // ============ Libraries ============

    using MerkleLib for MerkleLib.Tree;
    using TypedMemView for bytes;
    using TypedMemView for bytes29;
    using Message for bytes29;

    // ============ Enums ============

    // Status of Message:
    //   0 - None - message has not been proven or processed
    //   1 - Proven - message inclusion proof has been validated
    //   2 - Processed - message has been dispatched to recipient
    enum MessageStatus {
        None,
        Proven,
        Processed
    }

    // ============ Immutables ============

    // Minimum gas for message processing
    uint256 public immutable PROCESS_GAS;
    // Reserved gas (to ensure tx completes in case message processing runs out)
    uint256 public immutable RESERVE_GAS;

    // ============ Public Storage ============

    // Domain of home chain
    uint32 public remoteDomain;
    // Number of seconds to wait before root becomes confirmable
    uint256 public optimisticSeconds;
    // re-entrancy guard
    uint8 private entered;
    // Mapping of roots to allowable confirmation times
    mapping(bytes32 => uint256) public confirmAt;
    // Mapping of message leaves to MessageStatus
    mapping(bytes32 => MessageStatus) public messages;

    // ============ Upgrade Gap ============

    // gap for upgrade safety
    uint256[44] private __GAP;

    // ============ Events ============

    /**
     * @notice Emitted when message is processed
     * @param messageHash Hash of message that failed to process
     * @param success TRUE if the call was executed successfully, FALSE if the call reverted
     * @param returnData the return data from the external call
     */
    event Process(
        bytes32 indexed messageHash,
        bool indexed success,
        bytes indexed returnData
    );

    // ============ Constructor ============

    // solhint-disable-next-line no-empty-blocks
    constructor(
        uint32 _localDomain,
        uint256 _processGas,
        uint256 _reserveGas
    ) Common(_localDomain) {
        require(_processGas >= 850_000, "!process gas");
        require(_reserveGas >= 15_000, "!reserve gas");
        PROCESS_GAS = _processGas;
        RESERVE_GAS = _reserveGas;
    }

    // ============ Initializer ============

    function initialize(
        uint32 _remoteDomain,
        address _updater,
        bytes32 _committedRoot,
        uint256 _optimisticSeconds
    ) public initializer {
        __Common_initialize(_updater);
        entered = 1;
        remoteDomain = _remoteDomain;
        committedRoot = _committedRoot;
        confirmAt[_committedRoot] = 1;
        optimisticSeconds = _optimisticSeconds;
    }

    // ============ External Functions ============

    /**
     * @notice Called by external agent. Submits the signed update's new root,
     * marks root's allowable confirmation time, and emits an `Update` event.
     * @dev Reverts if update doesn't build off latest committedRoot
     * or if signature is invalid.
     * @param _oldRoot Old merkle root
     * @param _newRoot New merkle root
     * @param _signature Updater's signature on `_oldRoot` and `_newRoot`
     */
    function update(
        bytes32 _oldRoot,
        bytes32 _newRoot,
        bytes memory _signature
    ) external notFailed {
        // ensure that update is building off the last submitted root
        require(_oldRoot == committedRoot, "not current update");
        // validate updater signature
        require(
            _isUpdaterSignature(_oldRoot, _newRoot, _signature),
            "!updater sig"
        );
        // Hook for future use
        _beforeUpdate();
        // set the new root's confirmation timer
        confirmAt[_newRoot] = block.timestamp + optimisticSeconds;
        // update committedRoot
        committedRoot = _newRoot;
        emit Update(remoteDomain, _oldRoot, _newRoot, _signature);
    }

    /**
     * @notice First attempts to prove the validity of provided formatted
     * `message`. If the message is successfully proven, then tries to process
     * message.
     * @dev Reverts if `prove` call returns false
     * @param _message Formatted message (refer to Common.sol Message library)
     * @param _proof Merkle proof of inclusion for message's leaf
     * @param _index Index of leaf in home's merkle tree
     */
    function proveAndProcess(
        bytes memory _message,
        bytes32[32] calldata _proof,
        uint256 _index
    ) external {
        require(prove(keccak256(_message), _proof, _index), "!prove");
        process(_message);
    }

    /**
     * @notice Given formatted message, attempts to dispatch
     * message payload to end recipient.
     * @dev Recipient must implement a `handle` method (refer to IMessageRecipient.sol)
     * Reverts if formatted message's destination domain is not the Replica's domain,
     * if message has not been proven,
     * or if not enough gas is provided for the dispatch transaction.
     * @param _message Formatted message
     * @return _success TRUE iff dispatch transaction succeeded
     */
    function process(bytes memory _message) public returns (bool _success) {
        bytes29 _m = _message.ref(0);
        // ensure message was meant for this domain
        require(_m.destination() == localDomain, "!destination");
        // ensure message has been proven
        bytes32 _messageHash = _m.keccak();
        require(messages[_messageHash] == MessageStatus.Proven, "!proven");
        // check re-entrancy guard
        require(entered == 1, "!reentrant");
        entered = 0;
        // update message status as processed
        messages[_messageHash] = MessageStatus.Processed;
        // A call running out of gas TYPICALLY errors the whole tx. We want to
        // a) ensure the call has a sufficient amount of gas to make a
        //    meaningful state change.
        // b) ensure that if the subcall runs out of gas, that the tx as a whole
        //    does not revert (i.e. we still mark the message processed)
        // To do this, we require that we have enough gas to process
        // and still return. We then delegate only the minimum processing gas.
        require(gasleft() >= PROCESS_GAS + RESERVE_GAS, "!gas");
        // get the message recipient
        address _recipient = _m.recipientAddress();
        // set up for assembly call
        uint256 _toCopy;
        uint256 _maxCopy = 256;
        uint256 _gas = PROCESS_GAS;
        // allocate memory for returndata
        bytes memory _returnData = new bytes(_maxCopy);
        bytes memory _calldata = abi.encodeWithSignature(
            "handle(uint32,bytes32,bytes)",
            _m.origin(),
            _m.sender(),
            _m.body().clone()
        );
        // dispatch message to recipient
        // by assembly calling "handle" function
        // we call via assembly to avoid memcopying a very large returndata
        // returned by a malicious contract
        assembly {
            _success := call(
                _gas, // gas
                _recipient, // recipient
                0, // ether value
                add(_calldata, 0x20), // inloc
                mload(_calldata), // inlen
                0, // outloc
                0 // outlen
            )
            // limit our copy to 256 bytes
            _toCopy := returndatasize()
            if gt(_toCopy, _maxCopy) {
                _toCopy := _maxCopy
            }
            // Store the length of the copied bytes
            mstore(_returnData, _toCopy)
            // copy the bytes from returndata[0:_toCopy]
            returndatacopy(add(_returnData, 0x20), 0, _toCopy)
        }
        // emit process results
        emit Process(_messageHash, _success, _returnData);
        // reset re-entrancy guard
        entered = 1;
    }

    // ============ Public Functions ============

    /**
     * @notice Check that the root has been submitted
     * and that the optimistic timeout period has expired,
     * meaning the root can be processed
     * @param _root the Merkle root, submitted in an update, to check
     * @return TRUE iff root has been submitted & timeout has expired
     */
    function acceptableRoot(bytes32 _root) public view returns (bool) {
        uint256 _time = confirmAt[_root];
        if (_time == 0) {
            return false;
        }
        return block.timestamp >= _time;
    }

    /**
     * @notice Attempts to prove the validity of message given its leaf, the
     * merkle proof of inclusion for the leaf, and the index of the leaf.
     * @dev Reverts if message's MessageStatus != None (i.e. if message was
     * already proven or processed)
     * @dev For convenience, we allow proving against any previous root.
     * This means that witnesses never need to be updated for the new root
     * @param _leaf Leaf of message to prove
     * @param _proof Merkle proof of inclusion for leaf
     * @param _index Index of leaf in home's merkle tree
     * @return Returns true if proof was valid and `prove` call succeeded
     **/
    function prove(
        bytes32 _leaf,
        bytes32[32] calldata _proof,
        uint256 _index
    ) public returns (bool) {
        // ensure that message has not been proven or processed
        require(messages[_leaf] == MessageStatus.None, "!MessageStatus.None");
        // calculate the expected root based on the proof
        bytes32 _calculatedRoot = MerkleLib.branchRoot(_leaf, _proof, _index);
        // if the root is valid, change status to Proven
        if (acceptableRoot(_calculatedRoot)) {
            messages[_leaf] = MessageStatus.Proven;
            return true;
        }
        return false;
    }

    /**
     * @notice Hash of Home domain concatenated with "OPTICS"
     */
    function homeDomainHash() public view override returns (bytes32) {
        return _homeDomainHash(remoteDomain);
    }

    // ============ Internal Functions ============

    /**
     * @notice Moves the contract into failed state
     * @dev Called when a Double Update is submitted
     */
    function _fail() internal override {
        _setFailed();
    }

    /// @notice Hook for potential future use
    // solhint-disable-next-line no-empty-blocks
    function _beforeUpdate() internal {}
}
          

/_celo-org/optics-sol/contracts/Version0.sol

// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;

/**
 * @title Version0
 * @notice Version getter for contracts
 **/
contract Version0 {
    uint8 public constant VERSION = 0;
}
          

/_celo-org/optics-sol/contracts/XAppConnectionManager.sol

// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;

// ============ Internal Imports ============
import {Home} from "./Home.sol";
import {Replica} from "./Replica.sol";
import {TypeCasts} from "../libs/TypeCasts.sol";
// ============ External Imports ============
import {ECDSA} from "@openzeppelin/contracts/cryptography/ECDSA.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";

/**
 * @title XAppConnectionManager
 * @author Celo Labs Inc.
 * @notice Manages a registry of local Replica contracts
 * for remote Home domains. Accepts Watcher signatures
 * to un-enroll Replicas attached to fraudulent remote Homes
 */
contract XAppConnectionManager is Ownable {
    // ============ Public Storage ============

    // Home contract
    Home public home;
    // local Replica address => remote Home domain
    mapping(address => uint32) public replicaToDomain;
    // remote Home domain => local Replica address
    mapping(uint32 => address) public domainToReplica;
    // watcher address => replica remote domain => has/doesn't have permission
    mapping(address => mapping(uint32 => bool)) private watcherPermissions;

    // ============ Events ============

    /**
     * @notice Emitted when a new Replica is enrolled / added
     * @param domain the remote domain of the Home contract for the Replica
     * @param replica the address of the Replica
     */
    event ReplicaEnrolled(uint32 indexed domain, address replica);

    /**
     * @notice Emitted when a new Replica is un-enrolled / removed
     * @param domain the remote domain of the Home contract for the Replica
     * @param replica the address of the Replica
     */
    event ReplicaUnenrolled(uint32 indexed domain, address replica);

    /**
     * @notice Emitted when Watcher permissions are changed
     * @param domain the remote domain of the Home contract for the Replica
     * @param watcher the address of the Watcher
     * @param access TRUE if the Watcher was given permissions, FALSE if permissions were removed
     */
    event WatcherPermissionSet(
        uint32 indexed domain,
        address watcher,
        bool access
    );

    // ============ Modifiers ============

    modifier onlyReplica() {
        require(isReplica(msg.sender), "!replica");
        _;
    }

    // ============ Constructor ============

    // solhint-disable-next-line no-empty-blocks
    constructor() Ownable() {}

    // ============ External Functions ============

    /**
     * @notice Un-Enroll a replica contract
     * in the case that fraud was detected on the Home
     * @dev in the future, if fraud occurs on the Home contract,
     * the Watcher will submit their signature directly to the Home
     * and it can be relayed to all remote chains to un-enroll the Replicas
     * @param _domain the remote domain of the Home contract for the Replica
     * @param _updater the address of the Updater for the Home contract (also stored on Replica)
     * @param _signature signature of watcher on (domain, replica address, updater address)
     */
    function unenrollReplica(
        uint32 _domain,
        bytes32 _updater,
        bytes memory _signature
    ) external {
        // ensure that the replica is currently set
        address _replica = domainToReplica[_domain];
        require(_replica != address(0), "!replica exists");
        // ensure that the signature is on the proper updater
        require(
            Replica(_replica).updater() == TypeCasts.bytes32ToAddress(_updater),
            "!current updater"
        );
        // get the watcher address from the signature
        // and ensure that the watcher has permission to un-enroll this replica
        address _watcher = _recoverWatcherFromSig(
            _domain,
            TypeCasts.addressToBytes32(_replica),
            _updater,
            _signature
        );
        require(watcherPermissions[_watcher][_domain], "!valid watcher");
        // remove the replica from mappings
        _unenrollReplica(_replica);
    }

    /**
     * @notice Set the address of the local Home contract
     * @param _home the address of the local Home contract
     */
    function setHome(address _home) external onlyOwner {
        home = Home(_home);
    }

    /**
     * @notice Allow Owner to enroll Replica contract
     * @param _replica the address of the Replica
     * @param _domain the remote domain of the Home contract for the Replica
     */
    function ownerEnrollReplica(address _replica, uint32 _domain)
        external
        onlyOwner
    {
        // un-enroll any existing replica
        _unenrollReplica(_replica);
        // add replica and domain to two-way mapping
        replicaToDomain[_replica] = _domain;
        domainToReplica[_domain] = _replica;
        emit ReplicaEnrolled(_domain, _replica);
    }

    /**
     * @notice Allow Owner to un-enroll Replica contract
     * @param _replica the address of the Replica
     */
    function ownerUnenrollReplica(address _replica) external onlyOwner {
        _unenrollReplica(_replica);
    }

    /**
     * @notice Allow Owner to set Watcher permissions for a Replica
     * @param _watcher the address of the Watcher
     * @param _domain the remote domain of the Home contract for the Replica
     * @param _access TRUE to give the Watcher permissions, FALSE to remove permissions
     */
    function setWatcherPermission(
        address _watcher,
        uint32 _domain,
        bool _access
    ) external onlyOwner {
        watcherPermissions[_watcher][_domain] = _access;
        emit WatcherPermissionSet(_domain, _watcher, _access);
    }

    /**
     * @notice Query local domain from Home
     * @return local domain
     */
    function localDomain() external view returns (uint32) {
        return home.localDomain();
    }

    /**
     * @notice Get access permissions for the watcher on the domain
     * @param _watcher the address of the watcher
     * @param _domain the domain to check for watcher permissions
     * @return TRUE iff _watcher has permission to un-enroll replicas on _domain
     */
    function watcherPermission(address _watcher, uint32 _domain)
        external
        view
        returns (bool)
    {
        return watcherPermissions[_watcher][_domain];
    }

    // ============ Public Functions ============

    /**
     * @notice Check whether _replica is enrolled
     * @param _replica the replica to check for enrollment
     * @return TRUE iff _replica is enrolled
     */
    function isReplica(address _replica) public view returns (bool) {
        return replicaToDomain[_replica] != 0;
    }

    // ============ Internal Functions ============

    /**
     * @notice Remove the replica from the two-way mappings
     * @param _replica replica to un-enroll
     */
    function _unenrollReplica(address _replica) internal {
        uint32 _currentDomain = replicaToDomain[_replica];
        domainToReplica[_currentDomain] = address(0);
        replicaToDomain[_replica] = 0;
        emit ReplicaUnenrolled(_currentDomain, _replica);
    }

    /**
     * @notice Get the Watcher address from the provided signature
     * @return address of watcher that signed
     */
    function _recoverWatcherFromSig(
        uint32 _domain,
        bytes32 _replica,
        bytes32 _updater,
        bytes memory _signature
    ) internal view returns (address) {
        bytes32 _homeDomainHash = Replica(TypeCasts.bytes32ToAddress(_replica))
            .homeDomainHash();
        bytes32 _digest = keccak256(
            abi.encodePacked(_homeDomainHash, _domain, _updater)
        );
        _digest = ECDSA.toEthSignedMessageHash(_digest);
        return ECDSA.recover(_digest, _signature);
    }
}
          

/_celo-org/optics-sol/contracts/upgrade/UpgradeBeaconProxy.sol

// SPDX-License-Identifier: MIT
pragma solidity >=0.6.11;

// ============ External Imports ============
import {Address} from "@openzeppelin/contracts/utils/Address.sol";

/**
 * @title UpgradeBeaconProxy
 * @notice
 * Proxy contract which delegates all logic, including initialization,
 * to an implementation contract.
 * The implementation contract is stored within an Upgrade Beacon contract;
 * the implementation contract can be changed by performing an upgrade on the Upgrade Beacon contract.
 * The Upgrade Beacon contract for this Proxy is immutably specified at deployment.
 * @dev This implementation combines the gas savings of keeping the UpgradeBeacon address outside of contract storage
 * found in 0age's implementation:
 * https://github.com/dharma-eng/dharma-smart-wallet/blob/master/contracts/proxies/smart-wallet/UpgradeBeaconProxyV1.sol
 * With the added safety checks that the UpgradeBeacon and implementation are contracts at time of deployment
 * found in OpenZeppelin's implementation:
 * https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/proxy/beacon/BeaconProxy.sol
 */
contract UpgradeBeaconProxy {
    // ============ Immutables ============

    // Upgrade Beacon address is immutable (therefore not kept in contract storage)
    address private immutable upgradeBeacon;

    // ============ Constructor ============

    /**
     * @notice Validate that the Upgrade Beacon is a contract, then set its
     * address immutably within this contract.
     * Validate that the implementation is also a contract,
     * Then call the initialization function defined at the implementation.
     * The deployment will revert and pass along the
     * revert reason if the initialization function reverts.
     * @param _upgradeBeacon Address of the Upgrade Beacon to be stored immutably in the contract
     * @param _initializationCalldata Calldata supplied when calling the initialization function
     */
    constructor(address _upgradeBeacon, bytes memory _initializationCalldata)
        payable
    {
        // Validate the Upgrade Beacon is a contract
        require(Address.isContract(_upgradeBeacon), "beacon !contract");
        // set the Upgrade Beacon
        upgradeBeacon = _upgradeBeacon;
        // Validate the implementation is a contract
        address _implementation = _getImplementation(_upgradeBeacon);
        require(
            Address.isContract(_implementation),
            "beacon implementation !contract"
        );
        // Call the initialization function on the implementation
        if (_initializationCalldata.length > 0) {
            _initialize(_implementation, _initializationCalldata);
        }
    }

    // ============ External Functions ============

    /**
     * @notice Forwards all calls with data to _fallback()
     * No public functions are declared on the contract, so all calls hit fallback
     */
    fallback() external payable {
        _fallback();
    }

    /**
     * @notice Forwards all calls with no data to _fallback()
     */
    receive() external payable {
        _fallback();
    }

    // ============ Private Functions ============

    /**
     * @notice Call the initialization function on the implementation
     * Used at deployment to initialize the proxy
     * based on the logic for initialization defined at the implementation
     * @param _implementation - Contract to which the initalization is delegated
     * @param _initializationCalldata - Calldata supplied when calling the initialization function
     */
    function _initialize(
        address _implementation,
        bytes memory _initializationCalldata
    ) private {
        // Delegatecall into the implementation, supplying initialization calldata.
        (bool _ok, ) = _implementation.delegatecall(_initializationCalldata);
        // Revert and include revert data if delegatecall to implementation reverts.
        if (!_ok) {
            assembly {
                returndatacopy(0, 0, returndatasize())
                revert(0, returndatasize())
            }
        }
    }

    /**
     * @notice Delegates function calls to the implementation contract returned by the Upgrade Beacon
     */
    function _fallback() private {
        _delegate(_getImplementation());
    }

    /**
     * @notice Delegate function execution to the implementation contract
     * @dev This is a low level function that doesn't return to its internal
     * call site. It will return whatever is returned by the implementation to the
     * external caller, reverting and returning the revert data if implementation
     * reverts.
     * @param _implementation - Address to which the function execution is delegated
     */
    function _delegate(address _implementation) private {
        assembly {
            // Copy msg.data. We take full control of memory in this inline assembly
            // block because it will not return to Solidity code. We overwrite the
            // Solidity scratch pad at memory position 0.
            calldatacopy(0, 0, calldatasize())
            // Delegatecall to the implementation, supplying calldata and gas.
            // Out and outsize are set to zero - instead, use the return buffer.
            let result := delegatecall(
                gas(),
                _implementation,
                0,
                calldatasize(),
                0,
                0
            )
            // Copy the returned data from the return buffer.
            returndatacopy(0, 0, returndatasize())
            switch result
            // Delegatecall returns 0 on error.
            case 0 {
                revert(0, returndatasize())
            }
            default {
                return(0, returndatasize())
            }
        }
    }

    /**
     * @notice Call the Upgrade Beacon to get the current implementation contract address
     * @return _implementation Address of the current implementation.
     */
    function _getImplementation()
        private
        view
        returns (address _implementation)
    {
        _implementation = _getImplementation(upgradeBeacon);
    }

    /**
     * @notice Call the Upgrade Beacon to get the current implementation contract address
     * @dev _upgradeBeacon is passed as a parameter so that
     * we can also use this function in the constructor,
     * where we can't access immutable variables.
     * @param _upgradeBeacon Address of the UpgradeBeacon storing the current implementation
     * @return _implementation Address of the current implementation.
     */
    function _getImplementation(address _upgradeBeacon)
        private
        view
        returns (address _implementation)
    {
        // Get the current implementation address from the upgrade beacon.
        (bool _ok, bytes memory _returnData) = _upgradeBeacon.staticcall("");
        // Revert and pass along revert message if call to upgrade beacon reverts.
        require(_ok, string(_returnData));
        // Set the implementation to the address returned from the upgrade beacon.
        _implementation = abi.decode(_returnData, (address));
    }
}
          

/_celo-org/optics-sol/interfaces/IMessageRecipient.sol

// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;

interface IMessageRecipient {
    function handle(
        uint32 _origin,
        bytes32 _sender,
        bytes memory _message
    ) external;
}
          

/_celo-org/optics-sol/interfaces/IUpdaterManager.sol

// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;

interface IUpdaterManager {
    function slashUpdater(address payable _reporter) external;

    function updater() external view returns (address);
}
          

/_celo-org/optics-sol/libs/Merkle.sol

// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;

// work based on eth2 deposit contract, which is used under CC0-1.0

/**
 * @title MerkleLib
 * @author Celo Labs Inc.
 * @notice An incremental merkle tree modeled on the eth2 deposit contract.
 **/
library MerkleLib {
    uint256 internal constant TREE_DEPTH = 32;
    uint256 internal constant MAX_LEAVES = 2**TREE_DEPTH - 1;

    /**
     * @notice Struct representing incremental merkle tree. Contains current
     * branch and the number of inserted leaves in the tree.
     **/
    struct Tree {
        bytes32[TREE_DEPTH] branch;
        uint256 count;
    }

    /**
     * @notice Inserts `_node` into merkle tree
     * @dev Reverts if tree is full
     * @param _node Element to insert into tree
     **/
    function insert(Tree storage _tree, bytes32 _node) internal {
        require(_tree.count < MAX_LEAVES, "merkle tree full");

        _tree.count += 1;
        uint256 size = _tree.count;
        for (uint256 i = 0; i < TREE_DEPTH; i++) {
            if ((size & 1) == 1) {
                _tree.branch[i] = _node;
                return;
            }
            _node = keccak256(abi.encodePacked(_tree.branch[i], _node));
            size /= 2;
        }
        // As the loop should always end prematurely with the `return` statement,
        // this code should be unreachable. We assert `false` just to be safe.
        assert(false);
    }

    /**
     * @notice Calculates and returns`_tree`'s current root given array of zero
     * hashes
     * @param _zeroes Array of zero hashes
     * @return _current Calculated root of `_tree`
     **/
    function rootWithCtx(Tree storage _tree, bytes32[TREE_DEPTH] memory _zeroes)
        internal
        view
        returns (bytes32 _current)
    {
        uint256 _index = _tree.count;

        for (uint256 i = 0; i < TREE_DEPTH; i++) {
            uint256 _ithBit = (_index >> i) & 0x01;
            bytes32 _next = _tree.branch[i];
            if (_ithBit == 1) {
                _current = keccak256(abi.encodePacked(_next, _current));
            } else {
                _current = keccak256(abi.encodePacked(_current, _zeroes[i]));
            }
        }
    }

    /// @notice Calculates and returns`_tree`'s current root
    function root(Tree storage _tree) internal view returns (bytes32) {
        return rootWithCtx(_tree, zeroHashes());
    }

    /// @notice Returns array of TREE_DEPTH zero hashes
    /// @return _zeroes Array of TREE_DEPTH zero hashes
    function zeroHashes()
        internal
        pure
        returns (bytes32[TREE_DEPTH] memory _zeroes)
    {
        _zeroes[0] = Z_0;
        _zeroes[1] = Z_1;
        _zeroes[2] = Z_2;
        _zeroes[3] = Z_3;
        _zeroes[4] = Z_4;
        _zeroes[5] = Z_5;
        _zeroes[6] = Z_6;
        _zeroes[7] = Z_7;
        _zeroes[8] = Z_8;
        _zeroes[9] = Z_9;
        _zeroes[10] = Z_10;
        _zeroes[11] = Z_11;
        _zeroes[12] = Z_12;
        _zeroes[13] = Z_13;
        _zeroes[14] = Z_14;
        _zeroes[15] = Z_15;
        _zeroes[16] = Z_16;
        _zeroes[17] = Z_17;
        _zeroes[18] = Z_18;
        _zeroes[19] = Z_19;
        _zeroes[20] = Z_20;
        _zeroes[21] = Z_21;
        _zeroes[22] = Z_22;
        _zeroes[23] = Z_23;
        _zeroes[24] = Z_24;
        _zeroes[25] = Z_25;
        _zeroes[26] = Z_26;
        _zeroes[27] = Z_27;
        _zeroes[28] = Z_28;
        _zeroes[29] = Z_29;
        _zeroes[30] = Z_30;
        _zeroes[31] = Z_31;
    }

    /**
     * @notice Calculates and returns the merkle root for the given leaf
     * `_item`, a merkle branch, and the index of `_item` in the tree.
     * @param _item Merkle leaf
     * @param _branch Merkle proof
     * @param _index Index of `_item` in tree
     * @return _current Calculated merkle root
     **/
    function branchRoot(
        bytes32 _item,
        bytes32[TREE_DEPTH] memory _branch,
        uint256 _index
    ) internal pure returns (bytes32 _current) {
        _current = _item;

        for (uint256 i = 0; i < TREE_DEPTH; i++) {
            uint256 _ithBit = (_index >> i) & 0x01;
            bytes32 _next = _branch[i];
            if (_ithBit == 1) {
                _current = keccak256(abi.encodePacked(_next, _current));
            } else {
                _current = keccak256(abi.encodePacked(_current, _next));
            }
        }
    }

    // keccak256 zero hashes
    bytes32 internal constant Z_0 =
        hex"0000000000000000000000000000000000000000000000000000000000000000";
    bytes32 internal constant Z_1 =
        hex"ad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5";
    bytes32 internal constant Z_2 =
        hex"b4c11951957c6f8f642c4af61cd6b24640fec6dc7fc607ee8206a99e92410d30";
    bytes32 internal constant Z_3 =
        hex"21ddb9a356815c3fac1026b6dec5df3124afbadb485c9ba5a3e3398a04b7ba85";
    bytes32 internal constant Z_4 =
        hex"e58769b32a1beaf1ea27375a44095a0d1fb664ce2dd358e7fcbfb78c26a19344";
    bytes32 internal constant Z_5 =
        hex"0eb01ebfc9ed27500cd4dfc979272d1f0913cc9f66540d7e8005811109e1cf2d";
    bytes32 internal constant Z_6 =
        hex"887c22bd8750d34016ac3c66b5ff102dacdd73f6b014e710b51e8022af9a1968";
    bytes32 internal constant Z_7 =
        hex"ffd70157e48063fc33c97a050f7f640233bf646cc98d9524c6b92bcf3ab56f83";
    bytes32 internal constant Z_8 =
        hex"9867cc5f7f196b93bae1e27e6320742445d290f2263827498b54fec539f756af";
    bytes32 internal constant Z_9 =
        hex"cefad4e508c098b9a7e1d8feb19955fb02ba9675585078710969d3440f5054e0";
    bytes32 internal constant Z_10 =
        hex"f9dc3e7fe016e050eff260334f18a5d4fe391d82092319f5964f2e2eb7c1c3a5";
    bytes32 internal constant Z_11 =
        hex"f8b13a49e282f609c317a833fb8d976d11517c571d1221a265d25af778ecf892";
    bytes32 internal constant Z_12 =
        hex"3490c6ceeb450aecdc82e28293031d10c7d73bf85e57bf041a97360aa2c5d99c";
    bytes32 internal constant Z_13 =
        hex"c1df82d9c4b87413eae2ef048f94b4d3554cea73d92b0f7af96e0271c691e2bb";
    bytes32 internal constant Z_14 =
        hex"5c67add7c6caf302256adedf7ab114da0acfe870d449a3a489f781d659e8becc";
    bytes32 internal constant Z_15 =
        hex"da7bce9f4e8618b6bd2f4132ce798cdc7a60e7e1460a7299e3c6342a579626d2";
    bytes32 internal constant Z_16 =
        hex"2733e50f526ec2fa19a22b31e8ed50f23cd1fdf94c9154ed3a7609a2f1ff981f";
    bytes32 internal constant Z_17 =
        hex"e1d3b5c807b281e4683cc6d6315cf95b9ade8641defcb32372f1c126e398ef7a";
    bytes32 internal constant Z_18 =
        hex"5a2dce0a8a7f68bb74560f8f71837c2c2ebbcbf7fffb42ae1896f13f7c7479a0";
    bytes32 internal constant Z_19 =
        hex"b46a28b6f55540f89444f63de0378e3d121be09e06cc9ded1c20e65876d36aa0";
    bytes32 internal constant Z_20 =
        hex"c65e9645644786b620e2dd2ad648ddfcbf4a7e5b1a3a4ecfe7f64667a3f0b7e2";
    bytes32 internal constant Z_21 =
        hex"f4418588ed35a2458cffeb39b93d26f18d2ab13bdce6aee58e7b99359ec2dfd9";
    bytes32 internal constant Z_22 =
        hex"5a9c16dc00d6ef18b7933a6f8dc65ccb55667138776f7dea101070dc8796e377";
    bytes32 internal constant Z_23 =
        hex"4df84f40ae0c8229d0d6069e5c8f39a7c299677a09d367fc7b05e3bc380ee652";
    bytes32 internal constant Z_24 =
        hex"cdc72595f74c7b1043d0e1ffbab734648c838dfb0527d971b602bc216c9619ef";
    bytes32 internal constant Z_25 =
        hex"0abf5ac974a1ed57f4050aa510dd9c74f508277b39d7973bb2dfccc5eeb0618d";
    bytes32 internal constant Z_26 =
        hex"b8cd74046ff337f0a7bf2c8e03e10f642c1886798d71806ab1e888d9e5ee87d0";
    bytes32 internal constant Z_27 =
        hex"838c5655cb21c6cb83313b5a631175dff4963772cce9108188b34ac87c81c41e";
    bytes32 internal constant Z_28 =
        hex"662ee4dd2dd7b2bc707961b1e646c4047669dcb6584f0d8d770daf5d7e7deb2e";
    bytes32 internal constant Z_29 =
        hex"388ab20e2573d171a88108e79d820e98f26c0b84aa8b2f4aa4968dbb818ea322";
    bytes32 internal constant Z_30 =
        hex"93237c50ba75ee485f4c22adf2f741400bdf8d6a9cc7df7ecae576221665d735";
    bytes32 internal constant Z_31 =
        hex"8448818bb4ae4562849e949e17ac16e0be16688e156b5cf15e098c627c0056a9";
}
          

/_celo-org/optics-sol/libs/Message.sol

// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;

import "@summa-tx/memview-sol/contracts/TypedMemView.sol";

import {
    TypeCasts
} from "./TypeCasts.sol";

/**
 * @title Message Library
 * @author Celo Labs Inc.
 * @notice Library for formatted messages used by Home and Replica.
 **/
library Message {
    using TypedMemView for bytes;
    using TypedMemView for bytes29;

    // Number of bytes in formatted message before `body` field
    uint256 internal constant PREFIX_LENGTH = 76;

    /**
     * @notice Returns formatted (packed) message with provided fields
     * @param _originDomain Domain of home chain
     * @param _sender Address of sender as bytes32
     * @param _nonce Destination-specific nonce
     * @param _destinationDomain Domain of destination chain
     * @param _recipient Address of recipient on destination chain as bytes32
     * @param _messageBody Raw bytes of message body
     * @return Formatted message
     **/
    function formatMessage(
        uint32 _originDomain,
        bytes32 _sender,
        uint32 _nonce,
        uint32 _destinationDomain,
        bytes32 _recipient,
        bytes memory _messageBody
    ) internal pure returns (bytes memory) {
        return
            abi.encodePacked(
                _originDomain,
                _sender,
                _nonce,
                _destinationDomain,
                _recipient,
                _messageBody
            );
    }

    /**
     * @notice Returns leaf of formatted message with provided fields.
     * @param _origin Domain of home chain
     * @param _sender Address of sender as bytes32
     * @param _nonce Destination-specific nonce number
     * @param _destination Domain of destination chain
     * @param _recipient Address of recipient on destination chain as bytes32
     * @param _body Raw bytes of message body
     * @return Leaf (hash) of formatted message
     **/
    function messageHash(
        uint32 _origin,
        bytes32 _sender,
        uint32 _nonce,
        uint32 _destination,
        bytes32 _recipient,
        bytes memory _body
    ) internal pure returns (bytes32) {
        return
            keccak256(
                formatMessage(
                    _origin,
                    _sender,
                    _nonce,
                    _destination,
                    _recipient,
                    _body
                )
            );
    }

    /// @notice Returns message's origin field
    function origin(bytes29 _message) internal pure returns (uint32) {
        return uint32(_message.indexUint(0, 4));
    }

    /// @notice Returns message's sender field
    function sender(bytes29 _message) internal pure returns (bytes32) {
        return _message.index(4, 32);
    }

    /// @notice Returns message's nonce field
    function nonce(bytes29 _message) internal pure returns (uint32) {
        return uint32(_message.indexUint(36, 4));
    }

    /// @notice Returns message's destination field
    function destination(bytes29 _message) internal pure returns (uint32) {
        return uint32(_message.indexUint(40, 4));
    }

    /// @notice Returns message's recipient field as bytes32
    function recipient(bytes29 _message) internal pure returns (bytes32) {
        return _message.index(44, 32);
    }

    /// @notice Returns message's recipient field as an address
    function recipientAddress(bytes29 _message)
        internal
        pure
        returns (address)
    {
        return TypeCasts.bytes32ToAddress(recipient(_message));
    }

    /// @notice Returns message's body field as bytes29 (refer to TypedMemView library for details on bytes29 type)
    function body(bytes29 _message) internal pure returns (bytes29) {
        return _message.slice(PREFIX_LENGTH, _message.len() - PREFIX_LENGTH, 0);
    }

    function leaf(bytes29 _message) internal view returns (bytes32) {
        return messageHash(origin(_message), sender(_message), nonce(_message), destination(_message), recipient(_message), TypedMemView.clone(body(_message)));
    }
}
          

/_celo-org/optics-sol/libs/Queue.sol

// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;

/**
 * @title QueueLib
 * @author Celo Labs Inc.
 * @notice Library containing queue struct and operations for queue used by
 * Home and Replica.
 **/
library QueueLib {
    /**
     * @notice Queue struct
     * @dev Internally keeps track of the `first` and `last` elements through
     * indices and a mapping of indices to enqueued elements.
     **/
    struct Queue {
        uint128 first;
        uint128 last;
        mapping(uint256 => bytes32) queue;
    }

    /**
     * @notice Initializes the queue
     * @dev Empty state denoted by _q.first > q._last. Queue initialized
     * with _q.first = 1 and _q.last = 0.
     **/
    function initialize(Queue storage _q) internal {
        if (_q.first == 0) {
            _q.first = 1;
        }
    }

    /**
     * @notice Enqueues a single new element
     * @param _item New element to be enqueued
     * @return _last Index of newly enqueued element
     **/
    function enqueue(Queue storage _q, bytes32 _item)
        internal
        returns (uint128 _last)
    {
        _last = _q.last + 1;
        _q.last = _last;
        if (_item != bytes32(0)) {
            // saves gas if we're queueing 0
            _q.queue[_last] = _item;
        }
    }

    /**
     * @notice Dequeues element at front of queue
     * @dev Removes dequeued element from storage
     * @return _item Dequeued element
     **/
    function dequeue(Queue storage _q) internal returns (bytes32 _item) {
        uint128 _last = _q.last;
        uint128 _first = _q.first;
        require(_length(_last, _first) != 0, "Empty");
        _item = _q.queue[_first];
        if (_item != bytes32(0)) {
            // saves gas if we're dequeuing 0
            delete _q.queue[_first];
        }
        _q.first = _first + 1;
    }

    /**
     * @notice Batch enqueues several elements
     * @param _items Array of elements to be enqueued
     * @return _last Index of last enqueued element
     **/
    function enqueue(Queue storage _q, bytes32[] memory _items)
        internal
        returns (uint128 _last)
    {
        _last = _q.last;
        for (uint256 i = 0; i < _items.length; i += 1) {
            _last += 1;
            bytes32 _item = _items[i];
            if (_item != bytes32(0)) {
                _q.queue[_last] = _item;
            }
        }
        _q.last = _last;
    }

    /**
     * @notice Batch dequeues `_number` elements
     * @dev Reverts if `_number` > queue length
     * @param _number Number of elements to dequeue
     * @return Array of dequeued elements
     **/
    function dequeue(Queue storage _q, uint256 _number)
        internal
        returns (bytes32[] memory)
    {
        uint128 _last = _q.last;
        uint128 _first = _q.first;
        // Cannot underflow unless state is corrupted
        require(_length(_last, _first) >= _number, "Insufficient");

        bytes32[] memory _items = new bytes32[](_number);

        for (uint256 i = 0; i < _number; i++) {
            _items[i] = _q.queue[_first];
            delete _q.queue[_first];
            _first++;
        }
        _q.first = _first;
        return _items;
    }

    /**
     * @notice Returns true if `_item` is in the queue and false if otherwise
     * @dev Linearly scans from _q.first to _q.last looking for `_item`
     * @param _item Item being searched for in queue
     * @return True if `_item` currently exists in queue, false if otherwise
     **/
    function contains(Queue storage _q, bytes32 _item)
        internal
        view
        returns (bool)
    {
        for (uint256 i = _q.first; i <= _q.last; i++) {
            if (_q.queue[i] == _item) {
                return true;
            }
        }
        return false;
    }

    /// @notice Returns last item in queue
    /// @dev Returns bytes32(0) if queue empty
    function lastItem(Queue storage _q) internal view returns (bytes32) {
        return _q.queue[_q.last];
    }

    /// @notice Returns element at front of queue without removing element
    /// @dev Reverts if queue is empty
    function peek(Queue storage _q) internal view returns (bytes32 _item) {
        require(!isEmpty(_q), "Empty");
        _item = _q.queue[_q.first];
    }

    /// @notice Returns true if queue is empty and false if otherwise
    function isEmpty(Queue storage _q) internal view returns (bool) {
        return _q.last < _q.first;
    }

    /// @notice Returns number of elements in queue
    function length(Queue storage _q) internal view returns (uint256) {
        uint128 _last = _q.last;
        uint128 _first = _q.first;
        // Cannot underflow unless state is corrupted
        return _length(_last, _first);
    }

    /// @notice Returns number of elements between `_last` and `_first` (used internally)
    function _length(uint128 _last, uint128 _first)
        internal
        pure
        returns (uint256)
    {
        return uint256(_last + 1 - _first);
    }
}
          

/_celo-org/optics-sol/libs/TypeCasts.sol

// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;

import "@summa-tx/memview-sol/contracts/TypedMemView.sol";

library TypeCasts {
    using TypedMemView for bytes;
    using TypedMemView for bytes29;

    function coerceBytes32(string memory _s)
        internal
        pure
        returns (bytes32 _b)
    {
        _b = bytes(_s).ref(0).index(0, uint8(bytes(_s).length));
    }

    // treat it as a null-terminated string of max 32 bytes
    function coerceString(bytes32 _buf)
        internal
        pure
        returns (string memory _newStr)
    {
        uint8 _slen = 0;
        while (_slen < 32 && _buf[_slen] != 0) {
            _slen++;
        }

        // solhint-disable-next-line no-inline-assembly
        assembly {
            _newStr := mload(0x40)
            mstore(0x40, add(_newStr, 0x40)) // may end up with extra
            mstore(_newStr, _slen)
            mstore(add(_newStr, 0x20), _buf)
        }
    }

    // alignment preserving cast
    function addressToBytes32(address _addr) internal pure returns (bytes32) {
        return bytes32(uint256(uint160(_addr)));
    }

    // alignment preserving cast
    function bytes32ToAddress(bytes32 _buf) internal pure returns (address) {
        return address(uint160(uint256(_buf)));
    }
}
          

/_openzeppelin/contracts/access/Ownable.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "../utils/Context.sol";
/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor () internal {
        address msgSender = _msgSender();
        _owner = msgSender;
        emit OwnershipTransferred(address(0), msgSender);
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
        _;
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions anymore. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby removing any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        emit OwnershipTransferred(_owner, address(0));
        _owner = address(0);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        emit OwnershipTransferred(_owner, newOwner);
        _owner = newOwner;
    }
}
          

/_openzeppelin/contracts/cryptography/ECDSA.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

/**
 * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
 *
 * These functions can be used to verify that a message was signed by the holder
 * of the private keys of a given address.
 */
library ECDSA {
    /**
     * @dev Returns the address that signed a hashed message (`hash`) with
     * `signature`. This address can then be used for verification purposes.
     *
     * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
     * this function rejects them by requiring the `s` value to be in the lower
     * half order, and the `v` value to be either 27 or 28.
     *
     * IMPORTANT: `hash` _must_ be the result of a hash operation for the
     * verification to be secure: it is possible to craft signatures that
     * recover to arbitrary addresses for non-hashed data. A safe way to ensure
     * this is by receiving a hash of the original message (which may otherwise
     * be too long), and then calling {toEthSignedMessageHash} on it.
     */
    function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
        // Check the signature length
        if (signature.length != 65) {
            revert("ECDSA: invalid signature length");
        }

        // Divide the signature in r, s and v variables
        bytes32 r;
        bytes32 s;
        uint8 v;

        // ecrecover takes the signature parameters, and the only way to get them
        // currently is to use assembly.
        // solhint-disable-next-line no-inline-assembly
        assembly {
            r := mload(add(signature, 0x20))
            s := mload(add(signature, 0x40))
            v := byte(0, mload(add(signature, 0x60)))
        }

        return recover(hash, v, r, s);
    }

    /**
     * @dev Overload of {ECDSA-recover-bytes32-bytes-} that receives the `v`,
     * `r` and `s` signature fields separately.
     */
    function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {
        // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
        // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
        // the valid range for s in (281): 0 < s < secp256k1n ÷ 2 + 1, and for v in (282): v ∈ {27, 28}. Most
        // signatures from current libraries generate a unique signature with an s-value in the lower half order.
        //
        // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
        // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
        // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
        // these malleable signatures as well.
        require(uint256(s) <= 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0, "ECDSA: invalid signature 's' value");
        require(v == 27 || v == 28, "ECDSA: invalid signature 'v' value");

        // If the signature is valid (and not malleable), return the signer address
        address signer = ecrecover(hash, v, r, s);
        require(signer != address(0), "ECDSA: invalid signature");

        return signer;
    }

    /**
     * @dev Returns an Ethereum Signed Message, created from a `hash`. This
     * replicates the behavior of the
     * https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign[`eth_sign`]
     * JSON-RPC method.
     *
     * See {recover}.
     */
    function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) {
        // 32 is the length in bytes of hash,
        // enforced by the type signature above
        return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash));
    }
}
          

/_openzeppelin/contracts/math/SafeMath.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

/**
 * @dev Wrappers over Solidity's arithmetic operations with added overflow
 * checks.
 *
 * Arithmetic operations in Solidity wrap on overflow. This can easily result
 * in bugs, because programmers usually assume that an overflow raises an
 * error, which is the standard behavior in high level programming languages.
 * `SafeMath` restores this intuition by reverting the transaction when an
 * operation overflows.
 *
 * Using this library instead of the unchecked operations eliminates an entire
 * class of bugs, so it's recommended to use it always.
 */
library SafeMath {
    /**
     * @dev Returns the addition of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        uint256 c = a + b;
        if (c < a) return (false, 0);
        return (true, c);
    }

    /**
     * @dev Returns the substraction of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        if (b > a) return (false, 0);
        return (true, a - b);
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
        // benefit is lost if 'b' is also tested.
        // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
        if (a == 0) return (true, 0);
        uint256 c = a * b;
        if (c / a != b) return (false, 0);
        return (true, c);
    }

    /**
     * @dev Returns the division of two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        if (b == 0) return (false, 0);
        return (true, a / b);
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        if (b == 0) return (false, 0);
        return (true, a % b);
    }

    /**
     * @dev Returns the addition of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `+` operator.
     *
     * Requirements:
     *
     * - Addition cannot overflow.
     */
    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        uint256 c = a + b;
        require(c >= a, "SafeMath: addition overflow");
        return c;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting on
     * overflow (when the result is negative).
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b) internal pure returns (uint256) {
        require(b <= a, "SafeMath: subtraction overflow");
        return a - b;
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `*` operator.
     *
     * Requirements:
     *
     * - Multiplication cannot overflow.
     */
    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        if (a == 0) return 0;
        uint256 c = a * b;
        require(c / a == b, "SafeMath: multiplication overflow");
        return c;
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b) internal pure returns (uint256) {
        require(b > 0, "SafeMath: division by zero");
        return a / b;
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting when dividing by zero.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b) internal pure returns (uint256) {
        require(b > 0, "SafeMath: modulo by zero");
        return a % b;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
     * overflow (when the result is negative).
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {trySub}.
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        require(b <= a, errorMessage);
        return a - b;
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting with custom message on
     * division by zero. The result is rounded towards zero.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryDiv}.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        require(b > 0, errorMessage);
        return a / b;
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting with custom message when dividing by zero.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryMod}.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        require(b > 0, errorMessage);
        return a % b;
    }
}
          

/_openzeppelin/contracts/token/ERC20/IERC20.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the amount of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves `amount` tokens from the caller's account to `recipient`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address recipient, uint256 amount) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `sender` to `recipient` using the
     * allowance mechanism. `amount` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);

    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);
}
          

/_openzeppelin/contracts/token/ERC20/SafeERC20.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "./IERC20.sol";
import "../../math/SafeMath.sol";
import "../../utils/Address.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    using SafeMath for uint256;
    using Address for address;

    function safeTransfer(IERC20 token, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

    /**
     * @dev Deprecated. This function has issues similar to the ones found in
     * {IERC20-approve}, and its usage is discouraged.
     *
     * Whenever possible, use {safeIncreaseAllowance} and
     * {safeDecreaseAllowance} instead.
     */
    function safeApprove(IERC20 token, address spender, uint256 value) internal {
        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero. To increase and decrease it, use
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
        // solhint-disable-next-line max-line-length
        require((value == 0) || (token.allowance(address(this), spender) == 0),
            "SafeERC20: approve from non-zero to non-zero allowance"
        );
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
    }

    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 newAllowance = token.allowance(address(this), spender).add(value);
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

    function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero");
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
        if (returndata.length > 0) { // Return data is optional
            // solhint-disable-next-line max-line-length
            require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
        }
    }
}
          

/_openzeppelin/contracts/utils/Address.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.6.2 <0.8.0;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize, which returns 0 for contracts in
        // construction, since the code is only stored at the end of the
        // constructor execution.

        uint256 size;
        // solhint-disable-next-line no-inline-assembly
        assembly { size := extcodesize(account) }
        return size > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        // solhint-disable-next-line avoid-low-level-calls, avoid-call-value
        (bool success, ) = recipient.call{ value: amount }("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain`call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
      return functionCall(target, data, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        require(isContract(target), "Address: call to non-contract");

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) = target.call{ value: value }(data);
        return _verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) {
        require(isContract(target), "Address: static call to non-contract");

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) = target.staticcall(data);
        return _verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
        require(isContract(target), "Address: delegate call to non-contract");

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return _verifyCallResult(success, returndata, errorMessage);
    }

    function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) {
        if (success) {
            return returndata;
        } else {
            // Look for revert reason and bubble it up if present
            if (returndata.length > 0) {
                // The easiest way to bubble the revert reason is using memory via assembly

                // solhint-disable-next-line no-inline-assembly
                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}
          

/_openzeppelin/contracts/utils/Context.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

/*
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with GSN meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address payable) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes memory) {
        this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
        return msg.data;
    }
}
          

/_openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "../utils/ContextUpgradeable.sol";
import "../proxy/Initializable.sol";
/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {
    address private _owner;

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    function __Ownable_init() internal initializer {
        __Context_init_unchained();
        __Ownable_init_unchained();
    }

    function __Ownable_init_unchained() internal initializer {
        address msgSender = _msgSender();
        _owner = msgSender;
        emit OwnershipTransferred(address(0), msgSender);
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
        _;
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions anymore. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby removing any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        emit OwnershipTransferred(_owner, address(0));
        _owner = address(0);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        emit OwnershipTransferred(_owner, newOwner);
        _owner = newOwner;
    }
    uint256[49] private __gap;
}
          

/_openzeppelin/contracts-upgradeable/proxy/Initializable.sol

// SPDX-License-Identifier: MIT

// solhint-disable-next-line compiler-version
pragma solidity >=0.4.24 <0.8.0;

import "../utils/AddressUpgradeable.sol";

/**
 * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
 * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an
 * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
 * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
 *
 * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
 * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}.
 *
 * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
 * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
 */
abstract contract Initializable {

    /**
     * @dev Indicates that the contract has been initialized.
     */
    bool private _initialized;

    /**
     * @dev Indicates that the contract is in the process of being initialized.
     */
    bool private _initializing;

    /**
     * @dev Modifier to protect an initializer function from being invoked twice.
     */
    modifier initializer() {
        require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized");

        bool isTopLevelCall = !_initializing;
        if (isTopLevelCall) {
            _initializing = true;
            _initialized = true;
        }

        _;

        if (isTopLevelCall) {
            _initializing = false;
        }
    }

    /// @dev Returns true if and only if the function is running in the constructor
    function _isConstructor() private view returns (bool) {
        return !AddressUpgradeable.isContract(address(this));
    }
}
          

/_openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.6.2 <0.8.0;

/**
 * @dev Collection of functions related to the address type
 */
library AddressUpgradeable {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize, which returns 0 for contracts in
        // construction, since the code is only stored at the end of the
        // constructor execution.

        uint256 size;
        // solhint-disable-next-line no-inline-assembly
        assembly { size := extcodesize(account) }
        return size > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        // solhint-disable-next-line avoid-low-level-calls, avoid-call-value
        (bool success, ) = recipient.call{ value: amount }("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain`call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
      return functionCall(target, data, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        require(isContract(target), "Address: call to non-contract");

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) = target.call{ value: value }(data);
        return _verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) {
        require(isContract(target), "Address: static call to non-contract");

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) = target.staticcall(data);
        return _verifyCallResult(success, returndata, errorMessage);
    }

    function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) {
        if (success) {
            return returndata;
        } else {
            // Look for revert reason and bubble it up if present
            if (returndata.length > 0) {
                // The easiest way to bubble the revert reason is using memory via assembly

                // solhint-disable-next-line no-inline-assembly
                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}
          

/_openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;
import "../proxy/Initializable.sol";

/*
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with GSN meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract ContextUpgradeable is Initializable {
    function __Context_init() internal initializer {
        __Context_init_unchained();
    }

    function __Context_init_unchained() internal initializer {
    }
    function _msgSender() internal view virtual returns (address payable) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes memory) {
        this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
        return msg.data;
    }
    uint256[50] private __gap;
}
          

/_summa-tx/memview-sol/contracts/SafeMath.sol

// SPDX-License-Identifier: MIT
pragma solidity >=0.5.10;

/*
The MIT License (MIT)

Copyright (c) 2016 Smart Contract Solutions, Inc.

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/


/**
 * @title SafeMath
 * @dev Math operations with safety checks that throw on error
 */
library SafeMath {

    /**
     * @dev Multiplies two numbers, throws on overflow.
     */
    function mul(uint256 _a, uint256 _b) internal pure returns (uint256 c) {
        // Gas optimization: this is cheaper than asserting 'a' not being zero, but the
        // benefit is lost if 'b' is also tested.
        // See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
        if (_a == 0) {
            return 0;
        }

        c = _a * _b;
        require(c / _a == _b, "Overflow during multiplication.");
        return c;
    }

    /**
     * @dev Integer division of two numbers, truncating the quotient.
     */
    function div(uint256 _a, uint256 _b) internal pure returns (uint256) {
        // assert(_b > 0); // Solidity automatically throws when dividing by 0
        // uint256 c = _a / _b;
        // assert(_a == _b * c + _a % _b); // There is no case in which this doesn't hold
        return _a / _b;
    }

    /**
     * @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
     */
    function sub(uint256 _a, uint256 _b) internal pure returns (uint256) {
        require(_b <= _a, "Underflow during subtraction.");
        return _a - _b;
    }

    /**
     * @dev Adds two numbers, throws on overflow.
     */
    function add(uint256 _a, uint256 _b) internal pure returns (uint256 c) {
        c = _a + _b;
        require(c >= _a, "Overflow during addition.");
        return c;
    }
}
          

/_summa-tx/memview-sol/contracts/TypedMemView.sol

// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.5.10;

import {SafeMath} from "./SafeMath.sol";

library TypedMemView {
    using SafeMath for uint256;

    // Why does this exist?
    // the solidity `bytes memory` type has a few weaknesses.
    // 1. You can't index ranges effectively
    // 2. You can't slice without copying
    // 3. The underlying data may represent any type
    // 4. Solidity never deallocates memory, and memory costs grow
    //    superlinearly

    // By using a memory view instead of a `bytes memory` we get the following
    // advantages:
    // 1. Slices are done on the stack, by manipulating the pointer
    // 2. We can index arbitrary ranges and quickly convert them to stack types
    // 3. We can insert type info into the pointer, and typecheck at runtime

    // This makes `TypedMemView` a useful tool for efficient zero-copy
    // algorithms.

    // Why bytes29?
    // We want to avoid confusion between views, digests, and other common
    // types so we chose a large and uncommonly used odd number of bytes
    //
    // Note that while bytes are left-aligned in a word, integers and addresses
    // are right-aligned. This means when working in assembly we have to
    // account for the 3 unused bytes on the righthand side
    //
    // First 5 bytes are a type flag.
    // - ff_ffff_fffe is reserved for unknown type.
    // - ff_ffff_ffff is reserved for invalid types/errors.
    // next 12 are memory address
    // next 12 are len
    // bottom 3 bytes are empty

    // Assumptions:
    // - non-modification of memory.
    // - No Solidity updates
    // - - wrt free mem point
    // - - wrt bytes representation in memory
    // - - wrt memory addressing in general

    // Usage:
    // - create type constants
    // - use `assertType` for runtime type assertions
    // - - unfortunately we can't do this at compile time yet :(
    // - recommended: implement modifiers that perform type checking
    // - - e.g.
    // - - `uint40 constant MY_TYPE = 3;`
    // - - ` modifer onlyMyType(bytes29 myView) { myView.assertType(MY_TYPE); }`
    // - instantiate a typed view from a bytearray using `ref`
    // - use `index` to inspect the contents of the view
    // - use `slice` to create smaller views into the same memory
    // - - `slice` can increase the offset
    // - - `slice can decrease the length`
    // - - must specify the output type of `slice`
    // - - `slice` will return a null view if you try to overrun
    // - - make sure to explicitly check for this with `notNull` or `assertType`
    // - use `equal` for typed comparisons.


    // The null view
    bytes29 public constant NULL = hex"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff";
    uint256 constant LOW_12_MASK = 0xffffffffffffffffffffffff;
    uint8 constant TWELVE_BYTES = 96;

    /**
     * @notice      Returns the encoded hex character that represents the lower 4 bits of the argument.
     * @param _b    The byte
     * @return      char - The encoded hex character
     */
    function nibbleHex(uint8 _b) internal pure returns (uint8 char) {
        // This can probably be done more efficiently, but it's only in error
        // paths, so we don't really care :)
        uint8 _nibble = _b | 0xf0; // set top 4, keep bottom 4
        if (_nibble == 0xf0) {return 0x30;} // 0
        if (_nibble == 0xf1) {return 0x31;} // 1
        if (_nibble == 0xf2) {return 0x32;} // 2
        if (_nibble == 0xf3) {return 0x33;} // 3
        if (_nibble == 0xf4) {return 0x34;} // 4
        if (_nibble == 0xf5) {return 0x35;} // 5
        if (_nibble == 0xf6) {return 0x36;} // 6
        if (_nibble == 0xf7) {return 0x37;} // 7
        if (_nibble == 0xf8) {return 0x38;} // 8
        if (_nibble == 0xf9) {return 0x39;} // 9
        if (_nibble == 0xfa) {return 0x61;} // a
        if (_nibble == 0xfb) {return 0x62;} // b
        if (_nibble == 0xfc) {return 0x63;} // c
        if (_nibble == 0xfd) {return 0x64;} // d
        if (_nibble == 0xfe) {return 0x65;} // e
        if (_nibble == 0xff) {return 0x66;} // f
    }

    /**
     * @notice      Returns a uint16 containing the hex-encoded byte.
     * @param _b    The byte
     * @return      encoded - The hex-encoded byte
     */
    function byteHex(uint8 _b) internal pure returns (uint16 encoded) {
        encoded |= nibbleHex(_b >> 4); // top 4 bits
        encoded <<= 8;
        encoded |= nibbleHex(_b); // lower 4 bits
    }

    /**
     * @notice      Encodes the uint256 to hex. `first` contains the encoded top 16 bytes.
     *              `second` contains the encoded lower 16 bytes.
     *
     * @param _b    The 32 bytes as uint256
     * @return      first - The top 16 bytes
     * @return      second - The bottom 16 bytes
     */
    function encodeHex(uint256 _b) internal pure returns (uint256 first, uint256 second) {
        for (uint8 i = 31; i > 15; i -= 1) {
            uint8 _byte = uint8(_b >> (i * 8));
            first |= byteHex(_byte);
            if (i != 16) {
                first <<= 16;
            }
        }

        // abusing underflow here =_=
        for (uint8 i = 15; i < 255 ; i -= 1) {
            uint8 _byte = uint8(_b >> (i * 8));
            second |= byteHex(_byte);
            if (i != 0) {
                second <<= 16;
            }
        }
    }

    /**
     * @notice          Changes the endianness of a uint256.
     * @dev             https://graphics.stanford.edu/~seander/bithacks.html#ReverseParallel
     * @param _b        The unsigned integer to reverse
     * @return          v - The reversed value
     */
    function reverseUint256(uint256 _b) internal pure returns (uint256 v) {
        v = _b;

        // swap bytes
        v = ((v >> 8) & 0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF) |
            ((v & 0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF) << 8);
        // swap 2-byte long pairs
        v = ((v >> 16) & 0x0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF) |
            ((v & 0x0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF) << 16);
        // swap 4-byte long pairs
        v = ((v >> 32) & 0x00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF) |
            ((v & 0x00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF) << 32);
        // swap 8-byte long pairs
        v = ((v >> 64) & 0x0000000000000000FFFFFFFFFFFFFFFF0000000000000000FFFFFFFFFFFFFFFF) |
            ((v & 0x0000000000000000FFFFFFFFFFFFFFFF0000000000000000FFFFFFFFFFFFFFFF) << 64);
        // swap 16-byte long pairs
        v = (v >> 128) | (v << 128);
    }

    /**
     * @notice      Create a mask with the highest `_len` bits set.
     * @param _len  The length
     * @return      mask - The mask
     */
    function leftMask(uint8 _len) private pure returns (uint256 mask) {
        // ugly. redo without assembly?
        assembly {
            // solium-disable-previous-line security/no-inline-assembly
            mask := sar(
                sub(_len, 1),
                0x8000000000000000000000000000000000000000000000000000000000000000
            )
        }
    }

    /**
     * @notice      Return the null view.
     * @return      bytes29 - The null view
     */
    function nullView() internal pure returns (bytes29) {
        return NULL;
    }

    /**
     * @notice      Check if the view is null.
     * @return      bool - True if the view is null
     */
    function isNull(bytes29 memView) internal pure returns (bool) {
        return memView == NULL;
    }

    /**
     * @notice      Check if the view is not null.
     * @return      bool - True if the view is not null
     */
    function notNull(bytes29 memView) internal pure returns (bool) {
        return !isNull(memView);
    }

    /**
     * @notice          Check if the view is of a valid type and points to a valid location
     *                  in memory.
     * @dev             We perform this check by examining solidity's unallocated memory
     *                  pointer and ensuring that the view's upper bound is less than that.
     * @param memView   The view
     * @return          ret - True if the view is valid
     */
    function isValid(bytes29 memView) internal pure returns (bool ret) {
        if (typeOf(memView) == 0xffffffffff) {return false;}
        uint256 _end = end(memView);
        assembly {
            // solium-disable-previous-line security/no-inline-assembly
            ret := not(gt(_end, mload(0x40)))
        }
    }

    /**
     * @notice          Require that a typed memory view be valid.
     * @dev             Returns the view for easy chaining.
     * @param memView   The view
     * @return          bytes29 - The validated view
     */
    function assertValid(bytes29 memView) internal pure returns (bytes29) {
        require(isValid(memView), "Validity assertion failed");
        return memView;
    }

    /**
     * @notice          Return true if the memview is of the expected type. Otherwise false.
     * @param memView   The view
     * @param _expected The expected type
     * @return          bool - True if the memview is of the expected type
     */
    function isType(bytes29 memView, uint40 _expected) internal pure returns (bool) {
        return typeOf(memView) == _expected;
    }

    /**
     * @notice          Require that a typed memory view has a specific type.
     * @dev             Returns the view for easy chaining.
     * @param memView   The view
     * @param _expected The expected type
     * @return          bytes29 - The view with validated type
     */
    function assertType(bytes29 memView, uint40 _expected) internal pure returns (bytes29) {
        if (!isType(memView, _expected)) {
            (, uint256 g) = encodeHex(uint256(typeOf(memView)));
            (, uint256 e) = encodeHex(uint256(_expected));
            string memory err = string(
                abi.encodePacked(
                    "Type assertion failed. Got 0x",
                    uint80(g),
                    ". Expected 0x",
                    uint80(e)
                )
            );
            revert(err);
        }
        return memView;
    }

    /**
     * @notice          Return an identical view with a different type.
     * @param memView   The view
     * @param _newType  The new type
     * @return          newView - The new view with the specified type
     */
    function castTo(bytes29 memView, uint40 _newType) internal pure returns (bytes29 newView) {
        // then | in the new type
        assembly {
            // solium-disable-previous-line security/no-inline-assembly
            // shift off the top 5 bytes
            newView := or(newView, shr(40, shl(40, memView)))
            newView := or(newView, shl(216, _newType))
        }
    }

    /**
     * @notice          Unsafe raw pointer construction. This should generally not be called
     *                  directly. Prefer `ref` wherever possible.
     * @dev             Unsafe raw pointer construction. This should generally not be called
     *                  directly. Prefer `ref` wherever possible.
     * @param _type     The type
     * @param _loc      The memory address
     * @param _len      The length
     * @return          newView - The new view with the specified type, location and length
     */
    function unsafeBuildUnchecked(uint256 _type, uint256 _loc, uint256 _len) private pure returns (bytes29 newView) {
        assembly {
            // solium-disable-previous-line security/no-inline-assembly
            newView := shl(96, or(newView, _type)) // insert type
            newView := shl(96, or(newView, _loc))  // insert loc
            newView := shl(24, or(newView, _len))  // empty bottom 3 bytes
        }
    }

    /**
     * @notice          Instantiate a new memory view. This should generally not be called
     *                  directly. Prefer `ref` wherever possible.
     * @dev             Instantiate a new memory view. This should generally not be called
     *                  directly. Prefer `ref` wherever possible.
     * @param _type     The type
     * @param _loc      The memory address
     * @param _len      The length
     * @return          newView - The new view with the specified type, location and length
     */
    function build(uint256 _type, uint256 _loc, uint256 _len) internal pure returns (bytes29 newView) {
        uint256 _end = _loc.add(_len);
        assembly {
            // solium-disable-previous-line security/no-inline-assembly
            if gt(_end, mload(0x40)) {
                _end := 0
            }
        }
        if (_end == 0) {
            return NULL;
        }
        newView = unsafeBuildUnchecked(_type, _loc, _len);
    }

    /**
     * @notice          Instantiate a memory view from a byte array.
     * @dev             Note that due to Solidity memory representation, it is not possible to
     *                  implement a deref, as the `bytes` type stores its len in memory.
     * @param arr       The byte array
     * @param newType   The type
     * @return          bytes29 - The memory view
     */
    function ref(bytes memory arr, uint40 newType) internal pure returns (bytes29) {
        uint256 _len = arr.length;

        uint256 _loc;
        assembly {
            // solium-disable-previous-line security/no-inline-assembly
            _loc := add(arr, 0x20)  // our view is of the data, not the struct
        }

        return build(newType, _loc, _len);
    }

    /**
     * @notice          Return the associated type information.
     * @param memView   The memory view
     * @return          _type - The type associated with the view
     */
    function typeOf(bytes29 memView) internal pure returns (uint40 _type) {
        assembly {
            // solium-disable-previous-line security/no-inline-assembly
            // 216 == 256 - 40
            _type := shr(216, memView) // shift out lower 24 bytes
        }
    }

    /**
     * @notice          Optimized type comparison. Checks that the 5-byte type flag is equal.
     * @param left      The first view
     * @param right     The second view
     * @return          bool - True if the 5-byte type flag is equal
     */
    function sameType(bytes29 left, bytes29 right) internal pure returns (bool) {
        return (left ^ right) >> (2 * TWELVE_BYTES) == 0;
    }

    /**
     * @notice          Return the memory address of the underlying bytes.
     * @param memView   The view
     * @return          _loc - The memory address
     */
    function loc(bytes29 memView) internal pure returns (uint96 _loc) {
        uint256 _mask = LOW_12_MASK;  // assembly can't use globals
        assembly {
            // solium-disable-previous-line security/no-inline-assembly
            // 120 bits = 12 bytes (the encoded loc) + 3 bytes (empty low space)
            _loc := and(shr(120, memView), _mask)
        }
    }

    /**
     * @notice          The number of memory words this memory view occupies, rounded up.
     * @param memView   The view
     * @return          uint256 - The number of memory words
     */
    function words(bytes29 memView) internal pure returns (uint256) {
        return uint256(len(memView)).add(32) / 32;
    }

    /**
     * @notice          The in-memory footprint of a fresh copy of the view.
     * @param memView   The view
     * @return          uint256 - The in-memory footprint of a fresh copy of the view.
     */
    function footprint(bytes29 memView) internal pure returns (uint256) {
        return words(memView) * 32;
    }

    /**
     * @notice          The number of bytes of the view.
     * @param memView   The view
     * @return          _len - The length of the view
     */
    function len(bytes29 memView) internal pure returns (uint96 _len) {
        uint256 _mask = LOW_12_MASK;  // assembly can't use globals
        assembly {
            // solium-disable-previous-line security/no-inline-assembly
            _len := and(shr(24, memView), _mask)
        }
    }

    /**
     * @notice          Returns the endpoint of `memView`.
     * @param memView   The view
     * @return          uint256 - The endpoint of `memView`
     */
    function end(bytes29 memView) internal pure returns (uint256) {
        return loc(memView) + len(memView);
    }

    /**
     * @notice          Safe slicing without memory modification.
     * @param memView   The view
     * @param _index    The start index
     * @param _len      The length
     * @param newType   The new type
     * @return          bytes29 - The new view
     */
    function slice(bytes29 memView, uint256 _index, uint256 _len, uint40 newType) internal pure returns (bytes29) {
        uint256 _loc = loc(memView);

        // Ensure it doesn't overrun the view
        if (_loc.add(_index).add(_len) > end(memView)) {
            return NULL;
        }

        _loc = _loc.add(_index);
        return build(newType, _loc, _len);
    }

    /**
     * @notice          Shortcut to `slice`. Gets a view representing the first `_len` bytes.
     * @param memView   The view
     * @param _len      The length
     * @param newType   The new type
     * @return          bytes29 - The new view
     */
    function prefix(bytes29 memView, uint256 _len, uint40 newType) internal pure returns (bytes29) {
        return slice(memView, 0, _len, newType);
    }

    /**
     * @notice          Shortcut to `slice`. Gets a view representing the last `_len` byte.
     * @param memView   The view
     * @param _len      The length
     * @param newType   The new type
     * @return          bytes29 - The new view
     */
    function postfix(bytes29 memView, uint256 _len, uint40 newType) internal pure returns (bytes29) {
        return slice(memView, uint256(len(memView)).sub(_len), _len, newType);
    }

    /**
     * @notice          Construct an error message for an indexing overrun.
     * @param _loc      The memory address
     * @param _len      The length
     * @param _index    The index
     * @param _slice    The slice where the overrun occurred
     * @return          err - The err
     */
    function indexErrOverrun(
        uint256 _loc,
        uint256 _len,
        uint256 _index,
        uint256 _slice
    ) internal pure returns (string memory err) {
        (, uint256 a) = encodeHex(_loc);
        (, uint256 b) = encodeHex(_len);
        (, uint256 c) = encodeHex(_index);
        (, uint256 d) = encodeHex(_slice);
        err = string(
            abi.encodePacked(
                "TypedMemView/index - Overran the view. Slice is at 0x",
                uint48(a),
                " with length 0x",
                uint48(b),
                ". Attempted to index at offset 0x",
                uint48(c),
                " with length 0x",
                uint48(d),
                "."
            )
        );
    }

    /**
     * @notice          Load up to 32 bytes from the view onto the stack.
     * @dev             Returns a bytes32 with only the `_bytes` highest bytes set.
     *                  This can be immediately cast to a smaller fixed-length byte array.
     *                  To automatically cast to an integer, use `indexUint`.
     * @param memView   The view
     * @param _index    The index
     * @param _bytes    The bytes
     * @return          result - The 32 byte result
     */
    function index(bytes29 memView, uint256 _index, uint8 _bytes) internal pure returns (bytes32 result) {
        if (_bytes == 0) {return bytes32(0);}
        if (_index.add(_bytes) > len(memView)) {
            revert(indexErrOverrun(loc(memView), len(memView), _index, uint256(_bytes)));
        }
        require(_bytes <= 32, "TypedMemView/index - Attempted to index more than 32 bytes");

        uint8 bitLength = _bytes * 8;
        uint256 _loc = loc(memView);
        uint256 _mask = leftMask(bitLength);
        assembly {
            // solium-disable-previous-line security/no-inline-assembly
            result := and(mload(add(_loc, _index)), _mask)
        }
    }

    /**
     * @notice          Parse an unsigned integer from the view at `_index`.
     * @dev             Requires that the view have >= `_bytes` bytes following that index.
     * @param memView   The view
     * @param _index    The index
     * @param _bytes    The bytes
     * @return          result - The unsigned integer
     */
    function indexUint(bytes29 memView, uint256 _index, uint8 _bytes) internal pure returns (uint256 result) {
        return uint256(index(memView, _index, _bytes)) >> ((32 - _bytes) * 8);
    }

    /**
     * @notice          Parse an unsigned integer from LE bytes.
     * @param memView   The view
     * @param _index    The index
     * @param _bytes    The bytes
     * @return          result - The unsigned integer
     */
    function indexLEUint(bytes29 memView, uint256 _index, uint8 _bytes) internal pure returns (uint256 result) {
        return reverseUint256(uint256(index(memView, _index, _bytes)));
    }

    /**
     * @notice          Parse an address from the view at `_index`. Requires that the view have >= 20 bytes
     *                  following that index.
     * @param memView   The view
     * @param _index    The index
     * @return          address - The address
     */
    function indexAddress(bytes29 memView, uint256 _index) internal pure returns (address) {
        return address(uint160(indexUint(memView, _index, 20)));
    }

    /**
     * @notice          Return the keccak256 hash of the underlying memory
     * @param memView   The view
     * @return          digest - The keccak256 hash of the underlying memory
     */
    function keccak(bytes29 memView) internal pure returns (bytes32 digest) {
        uint256 _loc = loc(memView);
        uint256 _len = len(memView);
        assembly {
            // solium-disable-previous-line security/no-inline-assembly
            digest := keccak256(_loc, _len)
        }
    }

    /**
     * @notice          Return the sha2 digest of the underlying memory.
     * @dev             We explicitly deallocate memory afterwards.
     * @param memView   The view
     * @return          digest - The sha2 hash of the underlying memory
     */
    function sha2(bytes29 memView) internal view returns (bytes32 digest) {
        uint256 _loc = loc(memView);
        uint256 _len = len(memView);
        assembly {
            // solium-disable-previous-line security/no-inline-assembly
            let ptr := mload(0x40)
            pop(staticcall(gas(), 2, _loc, _len, ptr, 0x20)) // sha2 #1
            digest := mload(ptr)
        }
    }

    /**
     * @notice          Implements bitcoin's hash160 (rmd160(sha2()))
     * @param memView   The pre-image
     * @return          digest - the Digest
     */
    function hash160(bytes29 memView) internal view returns (bytes20 digest) {
        uint256 _loc = loc(memView);
        uint256 _len = len(memView);
        assembly {
            // solium-disable-previous-line security/no-inline-assembly
            let ptr := mload(0x40)
            pop(staticcall(gas(), 2, _loc, _len, ptr, 0x20)) // sha2
            pop(staticcall(gas(), 3, ptr, 0x20, ptr, 0x20)) // rmd160
            digest := mload(add(ptr, 0xc)) // return value is 0-prefixed.
        }
    }

    /**
     * @notice          Implements bitcoin's hash256 (double sha2)
     * @param memView   A view of the preimage
     * @return          digest - the Digest
     */
    function hash256(bytes29 memView) internal view returns (bytes32 digest) {
        uint256 _loc = loc(memView);
        uint256 _len = len(memView);
        assembly {
            // solium-disable-previous-line security/no-inline-assembly
            let ptr := mload(0x40)
            pop(staticcall(gas(), 2, _loc, _len, ptr, 0x20)) // sha2 #1
            pop(staticcall(gas(), 2, ptr, 0x20, ptr, 0x20)) // sha2 #2
            digest := mload(ptr)
        }
    }

    /**
     * @notice          Return true if the underlying memory is equal. Else false.
     * @param left      The first view
     * @param right     The second view
     * @return          bool - True if the underlying memory is equal
     */
    function untypedEqual(bytes29 left, bytes29 right) internal pure returns (bool) {
        return (loc(left) == loc(right) && len(left) == len(right)) || keccak(left) == keccak(right);
    }

    /**
     * @notice          Return false if the underlying memory is equal. Else true.
     * @param left      The first view
     * @param right     The second view
     * @return          bool - False if the underlying memory is equal
     */
    function untypedNotEqual(bytes29 left, bytes29 right) internal pure returns (bool) {
        return !untypedEqual(left, right);
    }

    /**
     * @notice          Compares type equality.
     * @dev             Shortcuts if the pointers are identical, otherwise compares type and digest.
     * @param left      The first view
     * @param right     The second view
     * @return          bool - True if the types are the same
     */
    function equal(bytes29 left, bytes29 right) internal pure returns (bool) {
        return left == right || (typeOf(left) == typeOf(right) && keccak(left) == keccak(right));
    }

    /**
     * @notice          Compares type inequality.
     * @dev             Shortcuts if the pointers are identical, otherwise compares type and digest.
     * @param left      The first view
     * @param right     The second view
     * @return          bool - True if the types are not the same
     */
    function notEqual(bytes29 left, bytes29 right) internal pure returns (bool) {
        return !equal(left, right);
    }

    /**
     * @notice          Copy the view to a location, return an unsafe memory reference
     * @dev             Super Dangerous direct memory access.
     *
     *                  This reference can be overwritten if anything else modifies memory (!!!).
     *                  As such it MUST be consumed IMMEDIATELY.
     *                  This function is private to prevent unsafe usage by callers.
     * @param memView   The view
     * @param _newLoc   The new location
     * @return          written - the unsafe memory reference
     */
    function unsafeCopyTo(bytes29 memView, uint256 _newLoc) private view returns (bytes29 written) {
        require(notNull(memView), "TypedMemView/copyTo - Null pointer deref");
        require(isValid(memView), "TypedMemView/copyTo - Invalid pointer deref");
        uint256 _len = len(memView);
        uint256 _oldLoc = loc(memView);

        uint256 ptr;
        assembly {
            // solium-disable-previous-line security/no-inline-assembly
            ptr := mload(0x40)
            // revert if we're writing in occupied memory
            if gt(ptr, _newLoc) {
                revert(0x60, 0x20) // empty revert message
            }

            // use the identity precompile to copy
            // guaranteed not to fail, so pop the success
            pop(staticcall(gas(), 4, _oldLoc, _len, _newLoc, _len))
        }

        written = unsafeBuildUnchecked(typeOf(memView), _newLoc, _len);
    }

    /**
     * @notice          Copies the referenced memory to a new loc in memory, returning a `bytes` pointing to
     *                  the new memory
     * @dev             Shortcuts if the pointers are identical, otherwise compares type and digest.
     * @param memView   The view
     * @return          ret - The view pointing to the new memory
     */
    function clone(bytes29 memView) internal view returns (bytes memory ret) {
        uint256 ptr;
        uint256 _len = len(memView);
        assembly {
            // solium-disable-previous-line security/no-inline-assembly
            ptr := mload(0x40) // load unused memory pointer
            ret := ptr
        }
        unsafeCopyTo(memView, ptr + 0x20);
        assembly {
            // solium-disable-previous-line security/no-inline-assembly
            mstore(0x40, add(add(ptr, _len), 0x20)) // write new unused pointer
            mstore(ptr, _len) // write len of new array (in bytes)
        }
    }

    /**
     * @notice          Join the views in memory, return an unsafe reference to the memory.
     * @dev             Super Dangerous direct memory access.
     *
     *                  This reference can be overwritten if anything else modifies memory (!!!).
     *                  As such it MUST be consumed IMMEDIATELY.
     *                  This function is private to prevent unsafe usage by callers.
     * @param memViews  The views
     * @return          unsafeView - The conjoined view pointing to the new memory
     */
    function unsafeJoin(bytes29[] memory memViews, uint256 _location) private view returns (bytes29 unsafeView) {
        assembly {
            // solium-disable-previous-line security/no-inline-assembly
            let ptr := mload(0x40)
            // revert if we're writing in occupied memory
            if gt(ptr, _location) {
                revert(0x60, 0x20) // empty revert message
            }
        }

        uint256 _offset = 0;
        for (uint256 i = 0; i < memViews.length; i ++) {
            bytes29 memView = memViews[i];
            unsafeCopyTo(memView, _location + _offset);
            _offset += len(memView);
        }
        unsafeView = unsafeBuildUnchecked(0, _location, _offset);
    }

    /**
     * @notice          Produce the keccak256 digest of the concatenated contents of multiple views.
     * @param memViews  The views
     * @return          bytes32 - The keccak256 digest
     */
    function joinKeccak(bytes29[] memory memViews) internal view returns (bytes32) {
        uint256 ptr;
        assembly {
            // solium-disable-previous-line security/no-inline-assembly
            ptr := mload(0x40) // load unused memory pointer
        }
        return keccak(unsafeJoin(memViews, ptr));
    }

    /**
     * @notice          Produce the sha256 digest of the concatenated contents of multiple views.
     * @param memViews  The views
     * @return          bytes32 - The sha256 digest
     */
    function joinSha2(bytes29[] memory memViews) internal view returns (bytes32) {
        uint256 ptr;
        assembly {
            // solium-disable-previous-line security/no-inline-assembly
            ptr := mload(0x40) // load unused memory pointer
        }
        return sha2(unsafeJoin(memViews, ptr));
    }

    /**
     * @notice          copies all views, joins them into a new bytearray.
     * @param memViews  The views
     * @return          ret - The new byte array
     */
    function join(bytes29[] memory memViews) internal view returns (bytes memory ret) {
        uint256 ptr;
        assembly {
            // solium-disable-previous-line security/no-inline-assembly
            ptr := mload(0x40) // load unused memory pointer
        }

        bytes29 _newView = unsafeJoin(memViews, ptr + 0x20);
        uint256 _written = len(_newView);
        uint256 _footprint = footprint(_newView);

        assembly {
            // solium-disable-previous-line security/no-inline-assembly
            // store the legnth
            mstore(ptr, _written)
            // new pointer is old + 0x20 + the footprint of the body
            mstore(0x40, add(add(ptr, _footprint), 0x20))
            ret := ptr
        }
    }
}
          

/contracts/Router.sol

// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;

// ============ Internal Imports ============
import {XAppConnectionClient} from "./XAppConnectionClient.sol";
// ============ External Imports ============
import {IMessageRecipient} from "@celo-org/optics-sol/interfaces/IMessageRecipient.sol";

abstract contract Router is XAppConnectionClient, IMessageRecipient {
    // ============ Mutable Storage ============

    mapping(uint32 => bytes32) public remotes;
    uint256[49] private __GAP; // gap for upgrade safety

    // ============ Modifiers ============

    /**
     * @notice Only accept messages from a remote Router contract
     * @param _origin The domain the message is coming from
     * @param _router The address the message is coming from
     */
    modifier onlyRemoteRouter(uint32 _origin, bytes32 _router) {
        require(_isRemoteRouter(_origin, _router), "!remote router");
        _;
    }

    // ============ External functions ============

    /**
     * @notice Register the address of a Router contract for the same xApp on a remote chain
     * @param _domain The domain of the remote xApp Router
     * @param _router The address of the remote xApp Router
     */
    function enrollRemoteRouter(uint32 _domain, bytes32 _router)
        external
        onlyOwner
    {
        remotes[_domain] = _router;
    }

    // ============ Virtual functions ============

    function handle(
        uint32 _origin,
        bytes32 _sender,
        bytes memory _message
    ) external virtual override;

    // ============ Internal functions ============
    /**
     * @notice Return true if the given domain / router is the address of a remote xApp Router
     * @param _domain The domain of the potential remote xApp Router
     * @param _router The address of the potential remote xApp Router
     */
    function _isRemoteRouter(uint32 _domain, bytes32 _router)
        internal
        view
        returns (bool)
    {
        return remotes[_domain] == _router;
    }

    /**
     * @notice Assert that the given domain has a xApp Router registered and return its address
     * @param _domain The domain of the chain for which to get the xApp Router
     * @return _remote The address of the remote xApp Router on _domain
     */
    function _mustHaveRemote(uint32 _domain)
        internal
        view
        returns (bytes32 _remote)
    {
        _remote = remotes[_domain];
        require(_remote != bytes32(0), "!remote");
    }
}
          

/contracts/XAppConnectionClient.sol

// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;

// ============ External Imports ============
import {Home} from "@celo-org/optics-sol/contracts/Home.sol";
import {XAppConnectionManager} from "@celo-org/optics-sol/contracts/XAppConnectionManager.sol";
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";

abstract contract XAppConnectionClient is OwnableUpgradeable {
    // ============ Mutable Storage ============

    XAppConnectionManager public xAppConnectionManager;
    uint256[49] private __GAP; // gap for upgrade safety

    // ============ Modifiers ============

    /**
     * @notice Only accept messages from an Optics Replica contract
     */
    modifier onlyReplica() {
        require(_isReplica(msg.sender), "!replica");
        _;
    }

    // ======== Initializer =========

    function __XAppConnectionClient_initialize(address _xAppConnectionManager)
        internal
        initializer
    {
        xAppConnectionManager = XAppConnectionManager(_xAppConnectionManager);
        __Ownable_init();
    }

    // ============ External functions ============

    /**
     * @notice Modify the contract the xApp uses to validate Replica contracts
     * @param _xAppConnectionManager The address of the xAppConnectionManager contract
     */
    function setXAppConnectionManager(address _xAppConnectionManager)
        external
        onlyOwner
    {
        xAppConnectionManager = XAppConnectionManager(_xAppConnectionManager);
    }

    // ============ Internal functions ============

    /**
     * @notice Get the local Home contract from the xAppConnectionManager
     * @return The local Home contract
     */
    function _home() internal view returns (Home) {
        return xAppConnectionManager.home();
    }

    /**
     * @notice Determine whether _potentialReplcia is an enrolled Replica from the xAppConnectionManager
     * @return True if _potentialReplica is an enrolled Replica
     */
    function _isReplica(address _potentialReplica)
        internal
        view
        returns (bool)
    {
        return xAppConnectionManager.isReplica(_potentialReplica);
    }

    /**
     * @notice Get the local domain from the xAppConnectionManager
     * @return The local domain
     */
    function _localDomain() internal view virtual returns (uint32) {
        return xAppConnectionManager.localDomain();
    }
}
          

/contracts/bridge/BridgeMessage.sol

// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;

// ============ External Imports ============
import {TypedMemView} from "@summa-tx/memview-sol/contracts/TypedMemView.sol";

library BridgeMessage {
    // ============ Libraries ============

    using TypedMemView for bytes;
    using TypedMemView for bytes29;

    // ============ Enums ============

    // WARNING: do NOT re-write the numbers / order
    // of message types in an upgrade;
    // will cause in-flight messages to be mis-interpreted
    enum Types {
        Invalid, // 0
        TokenId, // 1
        Message, // 2
        Transfer, // 3
        Details, // 4
        RequestDetails // 5
    }

    // ============ Constants ============

    uint256 private constant TOKEN_ID_LEN = 36; // 4 bytes domain + 32 bytes id
    uint256 private constant IDENTIFIER_LEN = 1;
    uint256 private constant TRANSFER_LEN = 65; // 1 byte identifier + 32 bytes recipient + 32 bytes amount
    uint256 private constant DETAILS_LEN = 66; // 1 byte identifier + 32 bytes name + 32 bytes symbol + 1 byte decimals
    uint256 private constant REQUEST_DETAILS_LEN = 1; // 1 byte identifier

    // ============ Modifiers ============

    /**
     * @notice Asserts a message is of type `_t`
     * @param _view The message
     * @param _t The expected type
     */
    modifier typeAssert(bytes29 _view, Types _t) {
        _view.assertType(uint40(_t));
        _;
    }

    // ============ Internal Functions ============

    /**
     * @notice Checks that Action is valid type
     * @param _action The action
     * @return TRUE if action is valid
     */
    function isValidAction(bytes29 _action) internal pure returns (bool) {
        return
            isDetails(_action) ||
            isRequestDetails(_action) ||
            isTransfer(_action);
    }

    /**
     * @notice Checks that view is a valid message length
     * @param _view The bytes string
     * @return TRUE if message is valid
     */
    function isValidMessageLength(bytes29 _view) internal pure returns (bool) {
        uint256 _len = _view.len();
        return
            _len == TOKEN_ID_LEN + TRANSFER_LEN ||
            _len == TOKEN_ID_LEN + DETAILS_LEN ||
            _len == TOKEN_ID_LEN + REQUEST_DETAILS_LEN;
    }

    /**
     * @notice Formats an action message
     * @param _tokenId The token ID
     * @param _action The action
     * @return The formatted message
     */
    function formatMessage(bytes29 _tokenId, bytes29 _action)
        internal
        view
        typeAssert(_tokenId, Types.TokenId)
        returns (bytes memory)
    {
        require(isValidAction(_action), "!action");
        bytes29[] memory _views = new bytes29[](2);
        _views[0] = _tokenId;
        _views[1] = _action;
        return TypedMemView.join(_views);
    }

    /**
     * @notice Returns the type of the message
     * @param _view The message
     * @return The type of the message
     */
    function messageType(bytes29 _view) internal pure returns (Types) {
        return Types(uint8(_view.typeOf()));
    }

    /**
     * @notice Checks that the message is of type Transfer
     * @param _action The message
     * @return True if the message is of type Transfer
     */
    function isTransfer(bytes29 _action) internal pure returns (bool) {
        return
            actionType(_action) == uint8(Types.Transfer) &&
            messageType(_action) == Types.Transfer;
    }

    /**
     * @notice Checks that the message is of type Details
     * @param _action The message
     * @return True if the message is of type Details
     */
    function isDetails(bytes29 _action) internal pure returns (bool) {
        return
            actionType(_action) == uint8(Types.Details) &&
            messageType(_action) == Types.Details;
    }

    /**
     * @notice Checks that the message is of type Details
     * @param _action The message
     * @return True if the message is of type Details
     */
    function isRequestDetails(bytes29 _action) internal pure returns (bool) {
        return
            actionType(_action) == uint8(Types.RequestDetails) &&
            messageType(_action) == Types.RequestDetails;
    }

    /**
     * @notice Formats Transfer
     * @param _to The recipient address as bytes32
     * @param _amnt The transfer amount
     * @return
     */
    function formatTransfer(bytes32 _to, uint256 _amnt)
        internal
        pure
        returns (bytes29)
    {
        return
            mustBeTransfer(abi.encodePacked(Types.Transfer, _to, _amnt).ref(0));
    }

    /**
     * @notice Formats Details
     * @param _name The name
     * @param _symbol The symbol
     * @param _decimals The decimals
     * @return The Details message
     */
    function formatDetails(
        bytes32 _name,
        bytes32 _symbol,
        uint8 _decimals
    ) internal pure returns (bytes29) {
        return
            mustBeDetails(
                abi.encodePacked(Types.Details, _name, _symbol, _decimals).ref(
                    0
                )
            );
    }

    /**
     * @notice Formats Request Details
     * @return The Request Details message
     */
    function formatRequestDetails() internal pure returns (bytes29) {
        return
            mustBeRequestDetails(abi.encodePacked(Types.RequestDetails).ref(0));
    }

    /**
     * @notice Formats the Token ID
     * @param _domain The domain
     * @param _id The ID
     * @return The formatted Token ID
     */
    function formatTokenId(uint32 _domain, bytes32 _id)
        internal
        pure
        returns (bytes29)
    {
        return mustBeTokenId(abi.encodePacked(_domain, _id).ref(0));
    }

    /**
     * @notice Retrieves the domain from a TokenID
     * @param _tokenId The message
     * @return The domain
     */
    function domain(bytes29 _tokenId)
        internal
        pure
        typeAssert(_tokenId, Types.TokenId)
        returns (uint32)
    {
        return uint32(_tokenId.indexUint(0, 4));
    }

    /**
     * @notice Retrieves the ID from a TokenID
     * @param _tokenId The message
     * @return The ID
     */
    function id(bytes29 _tokenId)
        internal
        pure
        typeAssert(_tokenId, Types.TokenId)
        returns (bytes32)
    {
        // before = 4 bytes domain
        return _tokenId.index(4, 32);
    }

    /**
     * @notice Retrieves the EVM ID
     * @param _tokenId The message
     * @return The EVM ID
     */
    function evmId(bytes29 _tokenId)
        internal
        pure
        typeAssert(_tokenId, Types.TokenId)
        returns (address)
    {
        // before = 4 bytes domain + 12 bytes empty to trim for address
        return _tokenId.indexAddress(16);
    }

    /**
     * @notice Retrieves the action identifier from message
     * @param _message The action
     * @return The message type
     */
    function msgType(bytes29 _message) internal pure returns (uint8) {
        return uint8(_message.indexUint(TOKEN_ID_LEN, 1));
    }

    /**
     * @notice Retrieves the identifier from action
     * @param _action The action
     * @return The action type
     */
    function actionType(bytes29 _action) internal pure returns (uint8) {
        return uint8(_action.indexUint(0, 1));
    }

    /**
     * @notice Retrieves the recipient from a Transfer
     * @param _transferAction The message
     * @return The recipient address as bytes32
     */
    function recipient(bytes29 _transferAction)
        internal
        pure
        typeAssert(_transferAction, Types.Transfer)
        returns (bytes32)
    {
        // before = 1 byte identifier
        return _transferAction.index(1, 32);
    }

    /**
     * @notice Retrieves the EVM Recipient from a Transfer
     * @param _transferAction The message
     * @return The EVM Recipient
     */
    function evmRecipient(bytes29 _transferAction)
        internal
        pure
        typeAssert(_transferAction, Types.Transfer)
        returns (address)
    {
        // before = 1 byte identifier + 12 bytes empty to trim for address
        return _transferAction.indexAddress(13);
    }

    /**
     * @notice Retrieves the amount from a Transfer
     * @param _transferAction The message
     * @return The amount
     */
    function amnt(bytes29 _transferAction)
        internal
        pure
        typeAssert(_transferAction, Types.Transfer)
        returns (uint256)
    {
        // before = 1 byte identifier + 32 bytes ID
        return _transferAction.indexUint(33, 32);
    }

    /**
     * @notice Retrieves the name from Details
     * @param _detailsAction The message
     * @return The name
     */
    function name(bytes29 _detailsAction)
        internal
        pure
        typeAssert(_detailsAction, Types.Details)
        returns (bytes32)
    {
        // before = 1 byte identifier
        return _detailsAction.index(1, 32);
    }

    /**
     * @notice Retrieves the symbol from Details
     * @param _detailsAction The message
     * @return The symbol
     */
    function symbol(bytes29 _detailsAction)
        internal
        pure
        typeAssert(_detailsAction, Types.Details)
        returns (bytes32)
    {
        // before = 1 byte identifier + 32 bytes name
        return _detailsAction.index(33, 32);
    }

    /**
     * @notice Retrieves the decimals from Details
     * @param _detailsAction The message
     * @return The decimals
     */
    function decimals(bytes29 _detailsAction)
        internal
        pure
        typeAssert(_detailsAction, Types.Details)
        returns (uint8)
    {
        // before = 1 byte identifier + 32 bytes name + 32 bytes symbol
        return uint8(_detailsAction.indexUint(65, 1));
    }

    /**
     * @notice Retrieves the token ID from a Message
     * @param _message The message
     * @return The ID
     */
    function tokenId(bytes29 _message)
        internal
        pure
        typeAssert(_message, Types.Message)
        returns (bytes29)
    {
        return _message.slice(0, TOKEN_ID_LEN, uint40(Types.TokenId));
    }

    /**
     * @notice Retrieves the action data from a Message
     * @param _message The message
     * @return The action
     */
    function action(bytes29 _message)
        internal
        pure
        typeAssert(_message, Types.Message)
        returns (bytes29)
    {
        uint256 _actionLen = _message.len() - TOKEN_ID_LEN;
        uint40 _type = uint40(msgType(_message));
        return _message.slice(TOKEN_ID_LEN, _actionLen, _type);
    }

    /**
     * @notice Converts to a Transfer
     * @param _action The message
     * @return The newly typed message
     */
    function tryAsTransfer(bytes29 _action) internal pure returns (bytes29) {
        if (_action.len() == TRANSFER_LEN) {
            return _action.castTo(uint40(Types.Transfer));
        }
        return TypedMemView.nullView();
    }

    /**
     * @notice Converts to a Details
     * @param _action The message
     * @return The newly typed message
     */
    function tryAsDetails(bytes29 _action) internal pure returns (bytes29) {
        if (_action.len() == DETAILS_LEN) {
            return _action.castTo(uint40(Types.Details));
        }
        return TypedMemView.nullView();
    }

    /**
     * @notice Converts to a Details
     * @param _action The message
     * @return The newly typed message
     */
    function tryAsRequestDetails(bytes29 _action)
        internal
        pure
        returns (bytes29)
    {
        if (_action.len() == REQUEST_DETAILS_LEN) {
            return _action.castTo(uint40(Types.RequestDetails));
        }
        return TypedMemView.nullView();
    }

    /**
     * @notice Converts to a TokenID
     * @param _tokenId The message
     * @return The newly typed message
     */
    function tryAsTokenId(bytes29 _tokenId) internal pure returns (bytes29) {
        if (_tokenId.len() == TOKEN_ID_LEN) {
            return _tokenId.castTo(uint40(Types.TokenId));
        }
        return TypedMemView.nullView();
    }

    /**
     * @notice Converts to a Message
     * @param _message The message
     * @return The newly typed message
     */
    function tryAsMessage(bytes29 _message) internal pure returns (bytes29) {
        if (isValidMessageLength(_message)) {
            return _message.castTo(uint40(Types.Message));
        }
        return TypedMemView.nullView();
    }

    /**
     * @notice Asserts that the message is of type Transfer
     * @param _view The message
     * @return The message
     */
    function mustBeTransfer(bytes29 _view) internal pure returns (bytes29) {
        return tryAsTransfer(_view).assertValid();
    }

    /**
     * @notice Asserts that the message is of type Details
     * @param _view The message
     * @return The message
     */
    function mustBeDetails(bytes29 _view) internal pure returns (bytes29) {
        return tryAsDetails(_view).assertValid();
    }

    /**
     * @notice Asserts that the message is of type Details
     * @param _view The message
     * @return The message
     */
    function mustBeRequestDetails(bytes29 _view)
        internal
        pure
        returns (bytes29)
    {
        return tryAsRequestDetails(_view).assertValid();
    }

    /**
     * @notice Asserts that the message is of type TokenID
     * @param _view The message
     * @return The message
     */
    function mustBeTokenId(bytes29 _view) internal pure returns (bytes29) {
        return tryAsTokenId(_view).assertValid();
    }

    /**
     * @notice Asserts that the message is of type Message
     * @param _view The message
     * @return The message
     */
    function mustBeMessage(bytes29 _view) internal pure returns (bytes29) {
        return tryAsMessage(_view).assertValid();
    }
}
          

/contracts/bridge/Encoding.sol

// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;

library Encoding {
    // ============ Constants ============

    bytes private constant NIBBLE_LOOKUP = "0123456789abcdef";

    // ============ Internal Functions ============

    /**
     * @notice Encode a uint32 in its DECIMAL representation, with leading
     * zeroes.
     * @param _num The number to encode
     * @return _encoded The encoded number, suitable for use in abi.
     * encodePacked
     */
    function decimalUint32(uint32 _num)
        internal
        pure
        returns (uint80 _encoded)
    {
        uint80 ASCII_0 = 0x30;
        // all over/underflows are impossible
        // this will ALWAYS produce 10 decimal characters
        for (uint8 i = 0; i < 10; i += 1) {
            _encoded |= ((_num % 10) + ASCII_0) << (i * 8);
            _num = _num / 10;
        }
    }

    /**
     * @notice Encodes the uint256 to hex. `first` contains the encoded top 16 bytes.
     * `second` contains the encoded lower 16 bytes.
     * @param _bytes The 32 bytes as uint256
     * @return _firstHalf The top 16 bytes
     * @return _secondHalf The bottom 16 bytes
     */
    function encodeHex(uint256 _bytes)
        internal
        pure
        returns (uint256 _firstHalf, uint256 _secondHalf)
    {
        for (uint8 i = 31; i > 15; i -= 1) {
            uint8 _b = uint8(_bytes >> (i * 8));
            _firstHalf |= _byteHex(_b);
            if (i != 16) {
                _firstHalf <<= 16;
            }
        }
        // abusing underflow here =_=
        for (uint8 i = 15; i < 255; i -= 1) {
            uint8 _b = uint8(_bytes >> (i * 8));
            _secondHalf |= _byteHex(_b);
            if (i != 0) {
                _secondHalf <<= 16;
            }
        }
    }

    /**
     * @notice Returns the encoded hex character that represents the lower 4 bits of the argument.
     * @param _byte The byte
     * @return _char The encoded hex character
     */
    function _nibbleHex(uint8 _byte) private pure returns (uint8 _char) {
        uint8 _nibble = _byte & 0x0f; // keep bottom 4, 0 top 4
        _char = uint8(NIBBLE_LOOKUP[_nibble]);
    }

    /**
     * @notice Returns a uint16 containing the hex-encoded byte.
     * @param _byte The byte
     * @return _encoded The hex-encoded byte
     */
    function _byteHex(uint8 _byte) private pure returns (uint16 _encoded) {
        _encoded |= _nibbleHex(_byte >> 4); // top 4 bits
        _encoded <<= 8;
        _encoded |= _nibbleHex(_byte); // lower 4 bits
    }
}
          

/contracts/bridge/TokenRegistry.sol

// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;

// ============ Internal Imports ============
import {BridgeMessage} from "./BridgeMessage.sol";
import {Encoding} from "./Encoding.sol";
import {IBridgeToken} from "../../interfaces/bridge/IBridgeToken.sol";
import {XAppConnectionClient} from "../XAppConnectionClient.sol";
// ============ External Imports ============
import {TypeCasts} from "@celo-org/optics-sol/contracts/XAppConnectionManager.sol";
import {UpgradeBeaconProxy} from "@celo-org/optics-sol/contracts/upgrade/UpgradeBeaconProxy.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {TypedMemView} from "@summa-tx/memview-sol/contracts/TypedMemView.sol";
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/Initializable.sol";

/**
 * @title TokenRegistry
 * @notice manages a registry of token contracts on this chain
 * -
 * We sort token types as "representation token" or "locally originating token".
 * Locally originating - a token contract that was originally deployed on the local chain
 * Representation (repr) - a token that was originally deployed on some other chain
 * -
 * When the router handles an incoming message, it determines whether the
 * transfer is for an asset of local origin. If not, it checks for an existing
 * representation contract. If no such representation exists, it deploys a new
 * representation contract. It then stores the relationship in the
 * "reprToCanonical" and "canonicalToRepr" mappings to ensure we can always
 * perform a lookup in either direction
 * Note that locally originating tokens should NEVER be represented in these lookup tables.
 */
abstract contract TokenRegistry is Initializable {
    // ============ Libraries ============

    using TypedMemView for bytes;
    using TypedMemView for bytes29;
    using BridgeMessage for bytes29;

    // ============ Structs ============

    // Tokens are identified by a TokenId:
    // domain - 4 byte chain ID of the chain from which the token originates
    // id - 32 byte identifier of the token address on the origin chain, in that chain's address format
    struct TokenId {
        uint32 domain;
        bytes32 id;
    }

    // ============ Public Storage ============

    // UpgradeBeacon from which new token proxies will get their implementation
    address public tokenBeacon;
    // local representation token address => token ID
    mapping(address => TokenId) public representationToCanonical;
    // hash of the tightly-packed TokenId => local representation token address
    // If the token is of local origin, this MUST map to address(0).
    mapping(bytes32 => address) public canonicalToRepresentation;

    // ============ Events ============

    event TokenDeployed(
        uint32 indexed domain,
        bytes32 indexed id,
        address indexed representation
    );

    // ======== Initializer =========

    /**
     * @notice Initialize the TokenRegistry with UpgradeBeaconController and
     * XappConnectionManager.
     * @dev This method deploys two new contracts, and may be expensive to call.
     * @param _tokenBeacon The address of the upgrade beacon for bridge token
     * proxies
     */
    function __TokenRegistry_initialize(address _tokenBeacon)
        internal
        initializer
    {
        tokenBeacon = _tokenBeacon;
    }

    // ======== External: Token Lookup Convenience =========

    /**
     * @notice Looks up the canonical identifier for a local representation.
     * @dev If no such canonical ID is known, this instead returns (0, bytes32(0))
     * @param _local The local address of the representation
     */
    function getCanonicalAddress(address _local)
        external
        view
        returns (uint32 _domain, bytes32 _id)
    {
        TokenId memory _canonical = representationToCanonical[_local];
        _domain = _canonical.domain;
        _id = _canonical.id;
    }

    /**
     * @notice Looks up the local address corresponding to a domain/id pair.
     * @dev If the token is local, it will return the local address.
     * If the token is non-local and no local representation exists, this
     * will return `address(0)`.
     * @param _domain the domain of the canonical version.
     * @param _id the identifier of the canonical version in its domain.
     * @return _token the local address of the token contract
     */
    function getLocalAddress(uint32 _domain, address _id)
        external
        view
        returns (address _token)
    {
        _token = getLocalAddress(_domain, TypeCasts.addressToBytes32(_id));
    }

    // ======== Public: Token Lookup Convenience =========

    /**
     * @notice Looks up the local address corresponding to a domain/id pair.
     * @dev If the token is local, it will return the local address.
     * If the token is non-local and no local representation exists, this
     * will return `address(0)`.
     * @param _domain the domain of the canonical version.
     * @param _id the identifier of the canonical version in its domain.
     * @return _token the local address of the token contract
     */
    function getLocalAddress(uint32 _domain, bytes32 _id)
        public
        view
        returns (address _token)
    {
        _token = _getTokenAddress(BridgeMessage.formatTokenId(_domain, _id));
    }

    // ======== Internal Functions =========

    function _localDomain() internal view virtual returns (uint32);

    /**
     * @notice Get default name and details for a token
     * Sets name to "optics.[domain].[id]"
     * and symbol to
     * @param _tokenId the tokenId for the token
     */
    function _defaultDetails(bytes29 _tokenId)
        internal
        pure
        returns (string memory _name, string memory _symbol)
    {
        // get the first and second half of the token ID
        (, uint256 _secondHalfId) = Encoding.encodeHex(uint256(_tokenId.id()));
        // encode the default token name: "[decimal domain].[hex 4 bytes of ID]"
        _name = string(
            abi.encodePacked(
                Encoding.decimalUint32(_tokenId.domain()), // 10
                ".", // 1
                uint32(_secondHalfId) // 4
            )
        );
        // allocate the memory for a new 32-byte string
        _symbol = new string(10 + 1 + 4);
        assembly {
            mstore(add(_symbol, 0x20), mload(add(_name, 0x20)))
        }
    }

    /**
     * @notice Deploy and initialize a new token contract
     * @dev Each token contract is a proxy which
     * points to the token upgrade beacon
     * @return _token the address of the token contract
     */
    function _deployToken(bytes29 _tokenId) internal returns (address _token) {
        // deploy and initialize the token contract
        _token = address(new UpgradeBeaconProxy(tokenBeacon, ""));
        // initialize the token separately from the
        IBridgeToken(_token).initialize();
        // set the default token name & symbol
        string memory _name;
        string memory _symbol;
        (_name, _symbol) = _defaultDetails(_tokenId);
        IBridgeToken(_token).setDetails(_name, _symbol, 18);
        // store token in mappings
        representationToCanonical[_token].domain = _tokenId.domain();
        representationToCanonical[_token].id = _tokenId.id();
        canonicalToRepresentation[_tokenId.keccak()] = _token;
        // emit event upon deploying new token
        emit TokenDeployed(_tokenId.domain(), _tokenId.id(), _token);
    }

    /**
     * @notice Get the local token address
     * for the canonical token represented by tokenID
     * Returns address(0) if canonical token is of remote origin
     * and no representation token has been deployed locally
     * @param _tokenId the token id of the canonical token
     * @return _local the local token address
     */
    function _getTokenAddress(bytes29 _tokenId)
        internal
        view
        returns (address _local)
    {
        if (_tokenId.domain() == _localDomain()) {
            // Token is of local origin
            _local = _tokenId.evmId();
        } else {
            // Token is a representation of a token of remote origin
            _local = canonicalToRepresentation[_tokenId.keccak()];
        }
    }

    /**
     * @notice Return the local token contract for the
     * canonical tokenId; revert if there is no local token
     * @param _tokenId the token id of the canonical token
     * @return the IERC20 token contract
     */
    function _mustHaveToken(bytes29 _tokenId) internal view returns (IERC20) {
        address _local = _getTokenAddress(_tokenId);
        require(_local != address(0), "!token");
        return IERC20(_local);
    }

    /**
     * @notice Return tokenId for a local token address
     * @param _token local token address (representation or canonical)
     * @return _id local token address (representation or canonical)
     */
    function _tokenIdFor(address _token)
        internal
        view
        returns (TokenId memory _id)
    {
        _id = representationToCanonical[_token];
        if (_id.domain == 0) {
            _id.domain = _localDomain();
            _id.id = TypeCasts.addressToBytes32(_token);
        }
    }

    /**
     * @notice Determine if token is of local origin
     * @return TRUE if token is locally originating
     */
    function _isLocalOrigin(IERC20 _token) internal view returns (bool) {
        return _isLocalOrigin(address(_token));
    }

    /**
     * @notice Determine if token is of local origin
     * @return TRUE if token is locally originating
     */
    function _isLocalOrigin(address _token) internal view returns (bool) {
        // If the contract WAS deployed by the TokenRegistry,
        // it will be stored in this mapping.
        // If so, it IS NOT of local origin
        if (representationToCanonical[_token].domain != 0) {
            return false;
        }
        // If the contract WAS NOT deployed by the TokenRegistry,
        // and the contract exists, then it IS of local origin
        // Return true if code exists at _addr
        uint256 _codeSize;
        // solhint-disable-next-line no-inline-assembly
        assembly {
            _codeSize := extcodesize(_token)
        }
        return _codeSize != 0;
    }

    /**
     * @notice Get the local representation contract for a canonical token
     * @dev Returns contract with null address if tokenId has no representation
     * @param _tokenId the tokenId of the canonical token
     * @return representation token contract
     */
    function _representationForCanonical(bytes29 _tokenId)
        internal
        view
        returns (IBridgeToken)
    {
        return IBridgeToken(canonicalToRepresentation[_tokenId.keccak()]);
    }

    /**
     * @notice Get the local representation contract for a canonical token
     * @dev Returns contract with null address if tokenId has no representation
     * @param _tokenId the tokenId of the canonical token
     * @return representation token contract
     */
    function _representationForCanonical(TokenId memory _tokenId)
        internal
        view
        returns (IBridgeToken)
    {
        return _representationForCanonical(_serializeId(_tokenId));
    }

    /**
     * @notice downcast an IERC20 to an IBridgeToken
     * @dev Unsafe. Please know what you're doing
     * @param _token the IERC20 contract
     * @return the IBridgeToken contract
     */
    function _downcast(IERC20 _token) internal pure returns (IBridgeToken) {
        return IBridgeToken(address(_token));
    }

    /**
     * @notice serialize a TokenId struct into a bytes view
     * @param _id the tokenId
     * @return serialized bytes of tokenId
     */
    function _serializeId(TokenId memory _id) internal pure returns (bytes29) {
        return BridgeMessage.formatTokenId(_id.domain, _id.id);
    }
}
          

/interfaces/bridge/IBridgeToken.sol

// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;

interface IBridgeToken {
    function initialize() external;

    function name() external returns (string memory);

    function balanceOf(address _account) external view returns (uint256);

    function symbol() external view returns (string memory);

    function decimals() external view returns (uint8);

    function burn(address _from, uint256 _amnt) external;

    function mint(address _to, uint256 _amnt) external;

    function setDetails(
        string calldata _name,
        string calldata _symbol,
        uint8 _decimals
    ) external;
}
          

Contract ABI

[{"type":"event","name":"OwnershipTransferred","inputs":[{"type":"address","name":"previousOwner","internalType":"address","indexed":true},{"type":"address","name":"newOwner","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"Send","inputs":[{"type":"address","name":"token","internalType":"address","indexed":true},{"type":"address","name":"from","internalType":"address","indexed":true},{"type":"uint32","name":"toDomain","internalType":"uint32","indexed":true},{"type":"bytes32","name":"toId","internalType":"bytes32","indexed":false},{"type":"uint256","name":"amount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"TokenDeployed","inputs":[{"type":"uint32","name":"domain","internalType":"uint32","indexed":true},{"type":"bytes32","name":"id","internalType":"bytes32","indexed":true},{"type":"address","name":"representation","internalType":"address","indexed":true}],"anonymous":false},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"PRE_FILL_FEE_DENOMINATOR","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"PRE_FILL_FEE_NUMERATOR","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint8","name":"","internalType":"uint8"}],"name":"VERSION","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"canonicalToRepresentation","inputs":[{"type":"bytes32","name":"","internalType":"bytes32"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"enrollCustom","inputs":[{"type":"uint32","name":"_domain","internalType":"uint32"},{"type":"bytes32","name":"_id","internalType":"bytes32"},{"type":"address","name":"_custom","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"enrollRemoteRouter","inputs":[{"type":"uint32","name":"_domain","internalType":"uint32"},{"type":"bytes32","name":"_router","internalType":"bytes32"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint32","name":"_domain","internalType":"uint32"},{"type":"bytes32","name":"_id","internalType":"bytes32"}],"name":"getCanonicalAddress","inputs":[{"type":"address","name":"_local","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"_token","internalType":"address"}],"name":"getLocalAddress","inputs":[{"type":"uint32","name":"_domain","internalType":"uint32"},{"type":"bytes32","name":"_id","internalType":"bytes32"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"_token","internalType":"address"}],"name":"getLocalAddress","inputs":[{"type":"uint32","name":"_domain","internalType":"uint32"},{"type":"address","name":"_id","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"handle","inputs":[{"type":"uint32","name":"_origin","internalType":"uint32"},{"type":"bytes32","name":"_sender","internalType":"bytes32"},{"type":"bytes","name":"_message","internalType":"bytes"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"initialize","inputs":[{"type":"address","name":"_tokenBeacon","internalType":"address"},{"type":"address","name":"_xAppConnectionManager","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"liquidityProvider","inputs":[{"type":"bytes32","name":"","internalType":"bytes32"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"migrate","inputs":[{"type":"address","name":"_oldRepr","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"owner","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"preFill","inputs":[{"type":"bytes","name":"_message","internalType":"bytes"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"remotes","inputs":[{"type":"uint32","name":"","internalType":"uint32"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"renounceOwnership","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint32","name":"domain","internalType":"uint32"},{"type":"bytes32","name":"id","internalType":"bytes32"}],"name":"representationToCanonical","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"requestDetails","inputs":[{"type":"uint32","name":"_domain","internalType":"uint32"},{"type":"bytes32","name":"_id","internalType":"bytes32"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"send","inputs":[{"type":"address","name":"_token","internalType":"address"},{"type":"uint256","name":"_amount","internalType":"uint256"},{"type":"uint32","name":"_destination","internalType":"uint32"},{"type":"bytes32","name":"_recipient","internalType":"bytes32"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setXAppConnectionManager","inputs":[{"type":"address","name":"_xAppConnectionManager","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"tokenBeacon","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"transferOwnership","inputs":[{"type":"address","name":"newOwner","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract XAppConnectionManager"}],"name":"xAppConnectionManager","inputs":[]}]
              

Contract Creation Code

0x608060405234801561001057600080fd5b50615fd880620000216000396000f3fe60806040523480156200001157600080fd5b5060043610620001c05760003560e01c80636eb3d5fe11620000f9578063cbcacfee1162000099578063d82d0531116200006f578063d82d05311462000628578063f2fde38b146200066a578063ffa1ad7414620006a057620001c0565b8063cbcacfee14620005b2578063ccf5a77c14620005e8578063ce5494bb14620005f257620001c0565b80638da5cb5b11620000cf5780638da5cb5b1462000550578063b49c53a7146200055a578063c3a7a023146200058657620001c0565b80636eb3d5fe1462000516578063715018a6146200052057806383bbb806146200052a57620001c0565b8063485cc9551162000165578063589b3c64116200013b578063589b3c6414620004585780636256878714620004845780636cdccfb814620004fa57620001c0565b8063485cc955146200033c578063546d573d146200037a57806356d5d475146200039a57620001c0565b806328b1aea0116200019b57806328b1aea014620002b45780633339df9614620002fc57806341bdc8b5146200030657620001c0565b806303e418c214620001c55780631cabf08f146200021b5780631ecf6f9f146200026b575b600080fd5b620001fb60048036036020811015620001dd57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16620006c0565b6040805163ffffffff909316835260208301919091528051918290030190f35b62000269600480360360808110156200023357600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135169060208101359063ffffffff6040820135169060600135620006e2565b005b6200028b600480360360208110156200028357600080fd5b503562000aa6565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b6200026960048036036060811015620002cc57600080fd5b50803563ffffffff16906020810135906040013573ffffffffffffffffffffffffffffffffffffffff1662000ace565b6200028b62000e0a565b62000269600480360360208110156200031e57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff1662000e26565b62000269600480360360408110156200035457600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135811691602001351662000f1a565b6200028b600480360360208110156200039257600080fd5b50356200104e565b6200026960048036036060811015620003b257600080fd5b63ffffffff82351691602081013591810190606081016040820135640100000000811115620003e057600080fd5b820183602082011115620003f357600080fd5b803590602001918460018302840111640100000000831117156200041657600080fd5b91908080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525092955062001076945050505050565b6200028b600480360360408110156200047057600080fd5b5063ffffffff81351690602001356200133a565b62000269600480360360208110156200049c57600080fd5b810190602081018135640100000000811115620004b857600080fd5b820183602082011115620004cb57600080fd5b80359060200191846001830284011164010000000083111715620004ee57600080fd5b50909250905062001359565b62000504620015d9565b60408051918252519081900360200190f35b62000504620015df565b62000269620015e5565b62000504600480360360208110156200054257600080fd5b503563ffffffff1662001701565b6200028b62001713565b62000269600480360360408110156200057257600080fd5b5063ffffffff81351690602001356200172f565b62000269600480360360408110156200059e57600080fd5b5063ffffffff8135169060200135620017f5565b620001fb60048036036020811015620005ca57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16620018bd565b6200028b62001908565b62000269600480360360208110156200060a57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff1662001924565b6200028b600480360360408110156200064057600080fd5b50803563ffffffff16906020013573ffffffffffffffffffffffffffffffffffffffff1662001c44565b62000269600480360360208110156200068257600080fd5b503573ffffffffffffffffffffffffffffffffffffffff1662001c5c565b620006aa62001e05565b6040805160ff9092168252519081900360200190f35b60ca602052600090815260409020805460019091015463ffffffff9091169082565b600083116200075257604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600560248201527f21616d6e74000000000000000000000000000000000000000000000000000000604482015290519081900360640190fd5b80620007bf57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600660248201527f2172656369700000000000000000000000000000000000000000000000000000604482015290519081900360640190fd5b6000620007cc8362001e0a565b905084620007da8162001e92565b156200080a576200080473ffffffffffffffffffffffffffffffffffffffff821633308862001ea5565b620008a0565b620008158162001f42565b73ffffffffffffffffffffffffffffffffffffffff16639dc29fac33876040518363ffffffff1660e01b8152600401808373ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050600060405180830381600087803b1580156200088657600080fd5b505af11580156200089b573d6000803e3d6000fd5b505050505b6000620008ae848762001f45565b9050606560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16639fa92f9d6040518163ffffffff1660e01b815260040160206040518083038186803b1580156200091957600080fd5b505afa1580156200092e573d6000803e3d6000fd5b505050506040513d60208110156200094557600080fd5b505173ffffffffffffffffffffffffffffffffffffffff1663fa31de0186856200097a620009738c62001fa6565b8662001fca565b6040518463ffffffff1660e01b8152600401808463ffffffff16815260200183815260200180602001828103825283818151815260200191508051906020019080838360005b83811015620009da578181015183820152602001620009c0565b50505050905090810190601f16801562000a085780820380516001836020036101000a031916815260200191505b50945050505050600060405180830381600087803b15801562000a2a57600080fd5b505af115801562000a3f573d6000803e3d6000fd5b505060408051878152602081018a9052815163ffffffff8a16945033935073ffffffffffffffffffffffffffffffffffffffff8716927fcf20fd9072af09cee97ee48e835f72e237cebf880d75143434214e57d6496d60928290030190a450505050505050565b60cb6020526000908152604090205473ffffffffffffffffffffffffffffffffffffffff1681565b62000ad862002116565b73ffffffffffffffffffffffffffffffffffffffff1662000af862001713565b73ffffffffffffffffffffffffffffffffffffffff161462000b7b57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b604080517f40c10f1900000000000000000000000000000000000000000000000000000000815230600482015260016024820152905173ffffffffffffffffffffffffffffffffffffffff8316916340c10f1991604480830192600092919082900301818387803b15801562000bf057600080fd5b505af115801562000c05573d6000803e3d6000fd5b5050604080517f9dc29fac00000000000000000000000000000000000000000000000000000000815230600482015260016024820152905173ffffffffffffffffffffffffffffffffffffffff85169350639dc29fac9250604480830192600092919082900301818387803b15801562000c7e57600080fd5b505af115801562000c93573d6000803e3d6000fd5b50505050600062000ca584846200211a565b905062000cd47fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000082166200216c565b73ffffffffffffffffffffffffffffffffffffffff8316600090815260ca6020526040902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000001663ffffffff9290921691909117905562000d597fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000008216620021b8565b73ffffffffffffffffffffffffffffffffffffffff8316600090815260ca602052604081206001019190915562000db27fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000008316620021fa565b600090815260cb6020526040902080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff949094169390931790925550505050565b60655473ffffffffffffffffffffffffffffffffffffffff1681565b62000e3062002116565b73ffffffffffffffffffffffffffffffffffffffff1662000e5062001713565b73ffffffffffffffffffffffffffffffffffffffff161462000ed357604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b606580547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b600054610100900460ff168062000f36575062000f366200223d565b8062000f45575060005460ff16155b62000f9c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602e81526020018062005e89602e913960400191505060405180910390fd5b600054610100900460ff161580156200100357600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff909116610100171660011790555b6200100e8362002250565b6200101982620023ad565b80156200104957600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff1690555b505050565b60cc6020526000908152604090205473ffffffffffffffffffffffffffffffffffffffff1681565b620010813362002513565b620010ed57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600860248201527f217265706c696361000000000000000000000000000000000000000000000000604482015290519081900360640190fd5b8282620010fb8282620025bf565b6200116757604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600e60248201527f2172656d6f746520726f75746572000000000000000000000000000000000000604482015290519081900360640190fd5b6000620011a1620011798583620025db565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000001662002601565b90506000620011d27fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000083166200263a565b90506000620012037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000084166200267e565b9050620012327fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000821662002714565b156200124a5762001244828262002750565b62001330565b620012777fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000821662002937565b1562001289576200124482826200295a565b620012b67fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000821662002bc0565b15620012c9576200124488888462002be3565b604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600d60248201527f2176616c696420616374696f6e00000000000000000000000000000000000000604482015290519081900360640190fd5b5050505050505050565b6000620013526200134c84846200211a565b62003049565b9392505050565b6000620013a562001179600085858080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152509293925050620025db9050565b9050600062001402620013da7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000084166200263a565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000001662003128565b905060006200145f620014377fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000085166200267e565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000001662003139565b905060006200146f83836200314a565b600081815260cc602052604090205490915073ffffffffffffffffffffffffffffffffffffffff16156200150457604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600960248201527f21756e66696c6c65640000000000000000000000000000000000000000000000604482015290519081900360640190fd5b600081815260cc6020526040812080547fffffffffffffffffffffffff000000000000000000000000000000000000000016331790556200154584620031eb565b9050620015d033620015797fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000086166200327e565b620015b0620015aa7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000008816620032be565b62003300565b73ffffffffffffffffffffffffffffffffffffffff851692919062001ea5565b50505050505050565b61270b81565b61271081565b620015ef62002116565b73ffffffffffffffffffffffffffffffffffffffff166200160f62001713565b73ffffffffffffffffffffffffffffffffffffffff16146200169257604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b60335460405160009173ffffffffffffffffffffffffffffffffffffffff16907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3603380547fffffffffffffffffffffffff0000000000000000000000000000000000000000169055565b60976020526000908152604090205481565b60335473ffffffffffffffffffffffffffffffffffffffff1690565b6200173962002116565b73ffffffffffffffffffffffffffffffffffffffff166200175962001713565b73ffffffffffffffffffffffffffffffffffffffff1614620017dc57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b63ffffffff909116600090815260976020526040902055565b620017ff62002116565b73ffffffffffffffffffffffffffffffffffffffff166200181f62001713565b73ffffffffffffffffffffffffffffffffffffffff1614620018a257604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6000620018b083836200211a565b9050620010498162003312565b73ffffffffffffffffffffffffffffffffffffffff16600090815260ca60209081526040918290208251808401909352805463ffffffff168084526001909101549290910182905291565b60c95473ffffffffffffffffffffffffffffffffffffffff1681565b73ffffffffffffffffffffffffffffffffffffffff8116600090815260ca60209081526040918290208251808401909352805463ffffffff1680845260019091015491830191909152620019d957604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600560248201527f2172657072000000000000000000000000000000000000000000000000000000604482015290519081900360640190fd5b816000620019e783620034fe565b90508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16141562001a8557604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600a60248201527f21646966666572656e7400000000000000000000000000000000000000000000604482015290519081900360640190fd5b60008273ffffffffffffffffffffffffffffffffffffffff166370a08231336040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b15801562001aef57600080fd5b505afa15801562001b04573d6000803e3d6000fd5b505050506040513d602081101562001b1b57600080fd5b5051604080517f9dc29fac00000000000000000000000000000000000000000000000000000000815233600482015260248101839052905191925073ffffffffffffffffffffffffffffffffffffffff851691639dc29fac9160448082019260009290919082900301818387803b15801562001b9657600080fd5b505af115801562001bab573d6000803e3d6000fd5b5050604080517f40c10f1900000000000000000000000000000000000000000000000000000000815233600482015260248101859052905173ffffffffffffffffffffffffffffffffffffffff861693506340c10f199250604480830192600092919082900301818387803b15801562001c2457600080fd5b505af115801562001c39573d6000803e3d6000fd5b505050505050505050565b6000620013528362001c568462003515565b6200133a565b62001c6662002116565b73ffffffffffffffffffffffffffffffffffffffff1662001c8662001713565b73ffffffffffffffffffffffffffffffffffffffff161462001d0957604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff811662001d77576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602681526020018062005e1c6026913960400191505060405180910390fd5b60335460405173ffffffffffffffffffffffffffffffffffffffff8084169216907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a3603380547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b600081565b63ffffffff81166000908152609760205260409020548062001e8d57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600760248201527f2172656d6f746500000000000000000000000000000000000000000000000000604482015290519081900360640190fd5b919050565b600062001e9f826200352e565b92915050565b6040805173ffffffffffffffffffffffffffffffffffffffff80861660248301528416604482015260648082018490528251808303909101815260849091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f23b872dd0000000000000000000000000000000000000000000000000000000017905262001f3c90859062003570565b50505050565b90565b60006200135262001fa06000600386866040516020018084600581111562001f6957fe5b60f81b81526001018381526020018281526020019350505050604051602081830303815290604052620025db90919063ffffffff16565b62003139565b60008062001fb4836200364e565b905062001352816000015182602001516200211a565b606082600162001fff815b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000841690620036ce565b506200200b846200385a565b6200207757604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600760248201527f21616374696f6e00000000000000000000000000000000000000000000000000604482015290519081900360640190fd5b6040805160028082526060820183526000926020830190803683370190505090508581600081518110620020a757fe5b602002602001019062ffffff1916908162ffffff1916815250508481600181518110620020d057fe5b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000909216602092830291909101909101526200210c816200388b565b9695505050505050565b3390565b6000620013526200216660008585604051602001808363ffffffff1660e01b815260040182815260200192505050604051602081830303815290604052620025db90919063ffffffff16565b62003128565b60008160016200217c8162001fd5565b50620021ae7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000851660006004620038e1565b92505b5050919050565b6000816001620021c88162001fd5565b50620021ae7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000085166004602062003904565b600080620022088362003a87565b6bffffffffffffffffffffffff1690506000620022258462003a9b565b6bffffffffffffffffffffffff169091209392505050565b60006200224a3062003aaf565b15905090565b600054610100900460ff16806200226c57506200226c6200223d565b806200227b575060005460ff16155b620022d2576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602e81526020018062005e89602e913960400191505060405180910390fd5b600054610100900460ff161580156200233957600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff909116610100171660011790555b60c980547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff84161790558015620023a957600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff1690555b5050565b600054610100900460ff1680620023c95750620023c96200223d565b80620023d8575060005460ff16155b6200242f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602e81526020018062005e89602e913960400191505060405180910390fd5b600054610100900460ff161580156200249657600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff909116610100171660011790555b606580547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff8416179055620024e062003ab5565b8015620023a957600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff1690555050565b606554604080517f5190bc5300000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff848116600483015291516000939290921691635190bc5391602480820192602092909190829003018186803b1580156200258b57600080fd5b505afa158015620025a0573d6000803e3d6000fd5b505050506040513d6020811015620025b757600080fd5b505192915050565b63ffffffff919091166000908152609760205260409020541490565b815160009060208401620025f864ffffffffff8516828462003be4565b95945050505050565b600062001e9f620026128362003c41565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000001662003c8f565b60008160026200264a8162001fd5565b50620021ae7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000851660006024600162003d0c565b60008160026200268e8162001fd5565b5060006024620026c07fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000871662003a9b565b6bffffffffffffffffffffffff160390506000620026de8662003da0565b60ff1690506200210c7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000087166024848462003d0c565b60006003620027238362003dd3565b60ff1614801562001e9f575060035b6200273d8362003e05565b60058111156200274957fe5b1492915050565b60006200275d8362003e43565b905060006200278e7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000084166200327e565b905060006200279e85856200314a565b600081815260cc602052604090205490915073ffffffffffffffffffffffffffffffffffffffff1680156200280557600082815260cc6020526040902080547fffffffffffffffffffffffff00000000000000000000000000000000000000001690559150815b620028108462001e92565b156200286d576200286783620028487fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000008816620032be565b73ffffffffffffffffffffffffffffffffffffffff8716919062003e87565b6200292f565b620028788462001f42565b73ffffffffffffffffffffffffffffffffffffffff166340c10f1984620028c17fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000008916620032be565b6040518363ffffffff1660e01b8152600401808373ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050600060405180830381600087803b1580156200291557600080fd5b505af11580156200292a573d6000803e3d6000fd5b505050505b505050505050565b60006004620029468362003dd3565b60ff1614801562001e9f5750600462002732565b60006200296783620031eb565b9050620029748162001e92565b15620029e157604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600e60248201527f2172656d6f7465206f726967696e000000000000000000000000000000000000604482015290519081900360640190fd5b620029ec8162001f42565b73ffffffffffffffffffffffffffffffffffffffff1663654935f462002a3e62002a387fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000861662003f16565b62003f58565b62002a6f62002a387fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000871662003fcf565b62002a9c7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000871662004011565b6040518463ffffffff1660e01b81526004018080602001806020018460ff168152602001838103835286818151815260200191508051906020019080838360005b8381101562002af757818101518382015260200162002add565b50505050905090810190601f16801562002b255780820380516001836020036101000a031916815260200191505b50838103825285518152855160209182019187019080838360005b8381101562002b5a57818101518382015260200162002b40565b50505050905090810190601f16801562002b885780820380516001836020036101000a031916815260200191505b5095505050505050600060405180830381600087803b15801562002bab57600080fd5b505af1158015620015d0573d6000803e3d6000fd5b6000600562002bcf8362003dd3565b60ff1614801562001e9f5750600562002732565b600062002c127fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000831662004053565b905062002c1f816200352e565b62002c8b57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600d60248201527f216c6f63616c206f726967696e00000000000000000000000000000000000000604482015290519081900360640190fd5b6000819050600062002ed762002dfc8373ffffffffffffffffffffffffffffffffffffffff166306fdde036040518163ffffffff1660e01b8152600401600060405180830381600087803b15801562002ce357600080fd5b505af115801562002cf8573d6000803e3d6000fd5b505050506040513d6000823e601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0168201604052602081101562002d4057600080fd5b810190808051604051939291908464010000000082111562002d6157600080fd5b90830190602082018581111562002d7757600080fd5b825164010000000081118282018810171562002d9257600080fd5b82525081516020918201929091019080838360005b8381101562002dc157818101518382015260200162002da7565b50505050905090810190601f16801562002def5780820380516001836020036101000a031916815260200191505b5060405250505062004093565b62002e5c8473ffffffffffffffffffffffffffffffffffffffff166395d89b416040518163ffffffff1660e01b815260040160006040518083038186803b15801562002e4757600080fd5b505afa15801562002cf8573d6000803e3d6000fd5b8473ffffffffffffffffffffffffffffffffffffffff1663313ce5676040518163ffffffff1660e01b815260040160206040518083038186803b15801562002ea357600080fd5b505afa15801562002eb8573d6000803e3d6000fd5b505050506040513d602081101562002ecf57600080fd5b5051620040dd565b9050606560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16639fa92f9d6040518163ffffffff1660e01b815260040160206040518083038186803b15801562002f4257600080fd5b505afa15801562002f57573d6000803e3d6000fd5b505050506040513d602081101562002f6e57600080fd5b505173ffffffffffffffffffffffffffffffffffffffff1663fa31de01878762002f99888662001fca565b6040518463ffffffff1660e01b8152600401808463ffffffff16815260200183815260200180602001828103825283818151815260200191508051906020019080838360005b8381101562002ff957818101518382015260200162002fdf565b50505050905090810190601f168015620030275780820380516001836020036101000a031916815260200191505b50945050505050600060405180830381600087803b1580156200291557600080fd5b6000620030556200414c565b63ffffffff16620030887fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000084166200216c565b63ffffffff161415620030ca57620030c27fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000831662004053565b905062001e8d565b60cb6000620030fb7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000008516620021fa565b815260208101919091526040016000205473ffffffffffffffffffffffffffffffffffffffff1692915050565b600062001e9f62002612836200415d565b600062001e9f6200261283620041af565b6040805160028082526060820183526000928392919060208301908036833701905050905083816000815181106200317e57fe5b602002602001019062ffffff1916908162ffffff1916815250508281600181518110620031a757fe5b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000090921660209283029190910190910152620031e38162004201565b949350505050565b600080620031f98362003049565b905073ffffffffffffffffffffffffffffffffffffffff811662001e9f57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600660248201527f21746f6b656e0000000000000000000000000000000000000000000000000000604482015290519081900360640190fd5b60008160036200328e8162001fd5565b50620021ae7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000008516600d6200421d565b6000816003620032ce8162001fd5565b50620021ae7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000851660216020620038e1565b600061271061270b83025b0492915050565b6000620033417fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000083166200216c565b63ffffffff81166000908152609760205260409020549091508062003368575050620034fb565b6000620033746200422d565b9050606560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16639fa92f9d6040518163ffffffff1660e01b815260040160206040518083038186803b158015620033df57600080fd5b505afa158015620033f4573d6000803e3d6000fd5b505050506040513d60208110156200340b57600080fd5b505173ffffffffffffffffffffffffffffffffffffffff1663fa31de01848462003436888662001fca565b6040518463ffffffff1660e01b8152600401808463ffffffff16815260200183815260200180602001828103825283818151815260200191508051906020019080838360005b83811015620034965781810151838201526020016200347c565b50505050905090810190601f168015620034c45780820380516001836020036101000a031916815260200191505b50945050505050600060405180830381600087803b158015620034e657600080fd5b505af115801562001330573d6000803e3d6000fd5b50565b600062001e9f6200350f836200427e565b62004294565b73ffffffffffffffffffffffffffffffffffffffff1690565b73ffffffffffffffffffffffffffffffffffffffff8116600090815260ca602052604081205463ffffffff1615620035695750600062001e8d565b503b151590565b6000620035d4826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c65648152508573ffffffffffffffffffffffffffffffffffffffff16620042c69092919063ffffffff16565b8051909150156200104957808060200190516020811015620035f557600080fd5b505162001049576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602a81526020018062005ef1602a913960400191505060405180910390fd5b620036586200586b565b5073ffffffffffffffffffffffffffffffffffffffff8116600090815260ca60209081526040918290208251808401909352805463ffffffff168084526001909101549183019190915262001e8d57620036b16200414c565b63ffffffff168152620036c48262003515565b6020820152919050565b6000620036dc8383620042d7565b62003853576000620036ff620036f285620042fb565b64ffffffffff1662004301565b9150506000620037168464ffffffffff1662004301565b604080517f5479706520617373657274696f6e206661696c65642e20476f742030780000006020808301919091527fffffffffffffffffffff0000000000000000000000000000000000000000000060b088811b8216603d8501527f2e20457870656374656420307800000000000000000000000000000000000000604785015285901b1660548301528251603e818403018152605e8301938490527f08c379a000000000000000000000000000000000000000000000000000000000909352606282018181528351608284015283519496509294508493839260a2019185019080838360005b8381101562003817578181015183820152602001620037fd565b50505050905090810190601f168015620038455780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b5090919050565b6000620038678262002937565b80620038795750620038798262002bc0565b8062001e9f575062001e9f8262002714565b6040516060906000620038a28460208401620043df565b90506000620038b18262003a9b565b6bffffffffffffffffffffffff1690506000620038ce8362004461565b9184525082016020016040525092915050565b60008160200360080260ff16620038fa85858562003904565b901c949350505050565b600060ff8216620039185750600062001352565b620039238462003a9b565b6bffffffffffffffffffffffff16620039408460ff851662004477565b1115620039eb5762003988620039568562003a87565b6bffffffffffffffffffffffff166200396f8662003a9b565b6bffffffffffffffffffffffff16858560ff16620044ea565b6040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181815283516024840152835190928392604490910191908501908083836000831562003817578181015183820152602001620037fd565b60208260ff16111562003a4a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252603a81526020018062005eb7603a913960400191505060405180910390fd5b60088202600062003a5b8662003a87565b6bffffffffffffffffffffffff169050600062003a78836200464f565b91909501511695945050505050565b60781c6bffffffffffffffffffffffff1690565b60181c6bffffffffffffffffffffffff1690565b3b151590565b600054610100900460ff168062003ad1575062003ad16200223d565b8062003ae0575060005460ff16155b62003b37576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602e81526020018062005e89602e913960400191505060405180910390fd5b600054610100900460ff1615801562003b9e57600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff909116610100171660011790555b62003ba862004698565b62003bb2620047b2565b8015620034fb57600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff16905550565b60008062003bf3848462004477565b905060405181111562003c04575060005b8062003c34577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000091505062001352565b620025f88585856200494c565b600062003c4e826200495f565b1562003c8557620030c260025b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000841690620049bf565b62001e9f620049e5565b600062003c9c8262004a09565b62003d0857604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601960248201527f56616c696469747920617373657274696f6e206661696c656400000000000000604482015290519081900360640190fd5b5090565b60008062003d1a8662003a87565b6bffffffffffffffffffffffff16905062003d358662004a4c565b62003d4d8562003d46848962004477565b9062004477565b111562003d7e577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000915050620031e3565b62003d8a818662004477565b90506200210c8364ffffffffff16828662003be4565b600062001e9f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000831660246001620038e1565b600062001e9f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000008316826001620038e1565b600062003e347fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000008316620042fb565b60ff16600581111562001e9f57fe5b60008062003e518362003049565b905073ffffffffffffffffffffffffffffffffffffffff811662001e9f5762003e7a8362004a7a565b905062001e9f8362003312565b6040805173ffffffffffffffffffffffffffffffffffffffff8416602482015260448082018490528251808303909101815260649091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fa9059cbb000000000000000000000000000000000000000000000000000000001790526200104990849062003570565b600081600462003f268162001fd5565b50620021ae7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000085166001602062003904565b606060005b60208160ff1610801562003fa55750828160ff166020811062003f7c57fe5b1a60f81b7fff000000000000000000000000000000000000000000000000000000000000001615155b1562003fb45760010162003f5d565b60405191506040820160405280825282602083015250919050565b600081600462003fdf8162001fd5565b50620021ae7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000085166021602062003904565b6000816004620040218162001fd5565b50620021ae7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000851660416001620038e1565b6000816001620040638162001fd5565b50620021ae7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000851660106200421d565b600062001e9f60008351620040b3600086620025db90919063ffffffff16565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000016919062003904565b6000620031e36200414660006004878787604051602001808560058111156200410257fe5b60f81b81526001018481526020018381526020018260ff1660f81b8152600101945050505050604051602081830303815290604052620025db90919063ffffffff16565b62004e87565b60006200415862004e98565b905090565b600060246200418e7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000841662003a9b565b6bffffffffffffffffffffffff16141562003c8557620030c2600162003c5b565b60006041620041e07fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000841662003a9b565b6bffffffffffffffffffffffff16141562003c8557620030c2600362003c5b565b60405160009062001352620042178483620043df565b620021fa565b60006200135283836014620038e1565b6000620041586200427860006005604051602001808260058111156200424f57fe5b60f81b8152600101915050604051602081830303815290604052620025db90919063ffffffff16565b62004f37565b600062001e9f826000015183602001516200211a565b600060cb81620030fb7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000008516620021fa565b6060620031e3848460008562004f48565b60008164ffffffffff16620042ec84620042fb565b64ffffffffff16149392505050565b60d81c90565b600080601f5b600f8160ff1611156200436e5760ff600882021684901c62004329816200510d565b61ffff16841793508160ff166010146200434557601084901b93505b507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0162004307565b50600f5b60ff8160ff161015620043d95760ff600882021684901c62004394816200510d565b61ffff16831792508160ff16600014620043b057601083901b92505b507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0162004372565b50915091565b600060405182811115620043f35760206060fd5b506000805b8451811015620044525760008582815181106200441157fe5b60200260200101519050620044298184870162005141565b50620044358162003a9b565b6bffffffffffffffffffffffff16929092019150600101620043f8565b50620031e3600084836200494c565b60006200446e826200527e565b60200292915050565b8181018281101562001e9f57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601960248201527f4f766572666c6f7720647572696e67206164646974696f6e2e00000000000000604482015290519081900360640190fd5b60606000620044f98662004301565b9150506000620045098662004301565b9150506000620045198662004301565b9150506000620045298662004301565b91505083838383604051602001808062005f6e603591397fffffffffffff000000000000000000000000000000000000000000000000000060d087811b821660358401527f2077697468206c656e6774682030780000000000000000000000000000000000603b84015286901b16604a820152605001602162005e6882397fffffffffffff000000000000000000000000000000000000000000000000000060d094851b811660218301527f2077697468206c656e677468203078000000000000000000000000000000000060278301529290931b9091166036830152507f2e00000000000000000000000000000000000000000000000000000000000000603c82015260408051601d818403018152603d90920190529b9a5050505050505050505050565b7f80000000000000000000000000000000000000000000000000000000000000007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9091011d90565b600054610100900460ff1680620046b45750620046b46200223d565b80620046c3575060005460ff16155b6200471a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602e81526020018062005e89602e913960400191505060405180910390fd5b600054610100900460ff1615801562003bb257600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff909116610100171660011790558015620034fb57600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff16905550565b600054610100900460ff1680620047ce5750620047ce6200223d565b80620047dd575060005460ff16155b62004834576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602e81526020018062005e89602e913960400191505060405180910390fd5b600054610100900460ff161580156200489b57600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff909116610100171660011790555b6000620048a762002116565b603380547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff8316908117909155604051919250906000907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908290a3508015620034fb57600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff16905550565b606092831b9190911790911b1760181b90565b6000806200498f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000841662003a9b565b6bffffffffffffffffffffffff1690506065811480620049af5750606681145b8062001352575060251492915050565b60d81b7affffffffffffffffffffffffffffffffffffffffffffffffffffff9091161790565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000090565b600062004a1682620042fb565b64ffffffffff1664ffffffffff141562004a335750600062001e8d565b600062004a408362004a4c565b60405110199392505050565b600062004a598262003a9b565b62004a648362003a87565b016bffffffffffffffffffffffff169050919050565b60c95460405160009173ffffffffffffffffffffffffffffffffffffffff169062004aa59062005882565b73ffffffffffffffffffffffffffffffffffffffff909116815260406020820181905260008183018190529051918290036060019190f08015801562004aef573d6000803e3d6000fd5b5090508073ffffffffffffffffffffffffffffffffffffffff16638129fc1c6040518163ffffffff1660e01b8152600401600060405180830381600087803b15801562004b3b57600080fd5b505af115801562004b50573d6000803e3d6000fd5b5050505060608062004b6284620052b0565b80925081935050508273ffffffffffffffffffffffffffffffffffffffff1663654935f4838360126040518463ffffffff1660e01b8152600401808060200180602001848152602001838103835286818151815260200191508051906020019080838360005b8381101562004be257818101518382015260200162004bc8565b50505050905090810190601f16801562004c105780820380516001836020036101000a031916815260200191505b50838103825285518152855160209182019187019080838360005b8381101562004c4557818101518382015260200162004c2b565b50505050905090810190601f16801562004c735780820380516001836020036101000a031916815260200191505b5095505050505050600060405180830381600087803b15801562004c9657600080fd5b505af115801562004cab573d6000803e3d6000fd5b5050505062004cc08462ffffff19166200216c565b73ffffffffffffffffffffffffffffffffffffffff8416600090815260ca6020526040902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000001663ffffffff9290921691909117905562004d457fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000008516620021b8565b73ffffffffffffffffffffffffffffffffffffffff8416600090815260ca6020526040812060010191909155839060cb9062004da37fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000008816620021fa565b8152602081019190915260400160002080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff928316179055831662004e217fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000008616620021b8565b62004e4e7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000087166200216c565b63ffffffff167f84d5e3618bf276f3d29a931646fdd996b398a3efa3cf6bceefc1fe7f0304059f60405160405180910390a45050919050565b600062001e9f6200261283620053ca565b606554604080517f8d3638f4000000000000000000000000000000000000000000000000000000008152905160009273ffffffffffffffffffffffffffffffffffffffff1691638d3638f4916004808301926020929190829003018186803b15801562004f0457600080fd5b505afa15801562004f19573d6000803e3d6000fd5b505050506040513d602081101562004f3057600080fd5b5051905090565b600062001e9f62002612836200541c565b60608247101562004fa5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602681526020018062005e426026913960400191505060405180910390fd5b62004fb08562003aaf565b6200501c57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015290519081900360640190fd5b6000808673ffffffffffffffffffffffffffffffffffffffff1685876040518082805190602001908083835b602083106200508757805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0909201916020918201910162005048565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d8060008114620050eb576040519150601f19603f3d011682016040523d82523d6000602084013e620050f0565b606091505b5091509150620051028282866200546e565b979650505050505050565b60006200512160048360ff16901c620054f3565b60ff161760081b62ffff00166200513882620054f3565b60ff1617919050565b60006200514e836200567f565b620051a5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602881526020018062005f1b6028913960400191505060405180910390fd5b620051b08362004a09565b62005207576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602b81526020018062005f43602b913960400191505060405180910390fd5b6000620052148462003a9b565b6bffffffffffffffffffffffff1690506000620052318562003a87565b6bffffffffffffffffffffffff1690506000604051905084811115620052575760206060fd5b8285848460045afa506200210c6200526f87620042fb565b64ffffffffff1686856200494c565b60006020620052a86020620052938562003a9b565b6bffffffffffffffffffffffff169062004477565b816200330b57fe5b6060806000620052ec620052e67fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000008616620021b8565b62005693565b9150506200530a620053048562ffffff19166200216c565b6200576b565b6040805160b09290921b7fffffffffffffffffffff000000000000000000000000000000000000000000001660208301527f2e00000000000000000000000000000000000000000000000000000000000000602a83015260e083901b7fffffffff0000000000000000000000000000000000000000000000000000000016602b8301528051808303600f9081018252602f8401818152606f85019093529095509091604f0181803683370190505091506020830151602083015250915091565b60006042620053fb7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000841662003a9b565b6bffffffffffffffffffffffff16141562003c8557620030c2600462003c5b565b600060016200544d7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000841662003a9b565b6bffffffffffffffffffffffff16141562003c8557620030c2600562003c5b565b606083156200547f57508162001352565b825115620054905782518084602001fd5b6040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181815284516024840152845185939192839260440191908501908083836000831562003817578181015183820152602001620037fd565b600060f08083179060ff821614156200551157603091505062001e8d565b8060ff1660f114156200552957603191505062001e8d565b8060ff1660f214156200554157603291505062001e8d565b8060ff1660f314156200555957603391505062001e8d565b8060ff1660f414156200557157603491505062001e8d565b8060ff1660f514156200558957603591505062001e8d565b8060ff1660f61415620055a157603691505062001e8d565b8060ff1660f71415620055b957603791505062001e8d565b8060ff1660f81415620055d157603891505062001e8d565b8060ff1660f91415620055e957603991505062001e8d565b8060ff1660fa14156200560157606191505062001e8d565b8060ff1660fb14156200561957606291505062001e8d565b8060ff1660fc14156200563157606391505062001e8d565b8060ff1660fd14156200564957606491505062001e8d565b8060ff1660fe14156200566157606591505062001e8d565b8060ff1660ff14156200567957606691505062001e8d565b50919050565b60006200568c82620057c6565b1592915050565b600080601f5b600f8160ff161115620057005760ff600882021684901c620056bb81620057ee565b61ffff16841793508160ff16601014620056d757601084901b93505b507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0162005699565b50600f5b60ff8160ff161015620043d95760ff600882021684901c6200572681620057ee565b61ffff16831792508160ff166000146200574257601083901b92505b507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0162005704565b60006030815b600a8160ff161015620021b15760ff600882021682600a63ffffffff87160663ffffffff160169ffffffffffffffffffff16901b83179250600a8463ffffffff1681620057ba57fe5b04935060010162005771565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000009081161490565b60006200580260048360ff16901c62005814565b60ff161760081b62ffff001662005138825b6040805180820190915260108082527f30313233343536373839616263646566000000000000000000000000000000006020830152600091600f841691829081106200585c57fe5b016020015160f81c9392505050565b604080518082019091526000808252602082015290565b61058b80620058918339019056fe60a060405260405161058b38038061058b8339818101604052604081101561002657600080fd5b81516020830180516040519294929383019291908464010000000082111561004d57600080fd5b90830190602082018581111561006257600080fd5b825164010000000081118282018810171561007c57600080fd5b82525081516020918201929091019080838360005b838110156100a9578181015183820152602001610091565b50505050905090810190601f1680156100d65780820380516001836020036101000a031916815260200191505b506040525050506100f0826101d060201b6100291760201c565b610134576040805162461bcd60e51b815260206004820152601060248201526f18995858dbdb880858dbdb9d1c9858dd60821b604482015290519081900360640190fd5b6001600160601b0319606083901b166080526000610151836101d6565b9050610166816101d060201b6100291760201c565b6101b7576040805162461bcd60e51b815260206004820152601f60248201527f626561636f6e20696d706c656d656e746174696f6e2021636f6e747261637400604482015290519081900360640190fd5b8151156101c8576101c881836102d6565b50505061038f565b3b151590565b604051600090819081906001600160a01b0385169082818181855afa9150503d8060008114610221576040519150601f19603f3d011682016040523d82523d6000602084013e610226565b606091505b50915091508181906102b65760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b8381101561027b578181015183820152602001610263565b50505050905090810190601f1680156102a85780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b508080602001905160208110156102cc57600080fd5b5051949350505050565b6000826001600160a01b0316826040518082805190602001908083835b602083106103125780518252601f1990920191602091820191016102f3565b6001836020036101000a038019825116818451168082178552505050505050905001915050600060405180830381855af49150503d8060008114610372576040519150601f19603f3d011682016040523d82523d6000602084013e610377565b606091505b505090508061038a573d6000803e3d6000fd5b505050565b60805160601c6101e06103ab60003980603652506101e06000f3fe60806040523661001357610011610017565b005b6100115b61002761002261002f565b61005f565b565b3b151590565b600061005a7f0000000000000000000000000000000000000000000000000000000000000000610083565b905090565b3660008037600080366000845af43d6000803e80801561007e573d6000f35b3d6000fd5b6040516000908190819073ffffffffffffffffffffffffffffffffffffffff85169082818181855afa9150503d80600081146100db576040519150601f19603f3d011682016040523d82523d6000602084013e6100e0565b606091505b509150915081819061018a576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b8381101561014f578181015183820152602001610137565b50505050905090810190601f16801561017c5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b508080602001905160208110156101a057600080fd5b505194935050505056fea2646970667358221220acaa13070c5929df67757f0af9d23c2ae2dfb97f784ab2d6361279077a730bf864736f6c634300070600334f776e61626c653a206e6577206f776e657220697320746865207a65726f2061646472657373416464726573733a20696e73756666696369656e742062616c616e636520666f722063616c6c2e20417474656d7074656420746f20696e646578206174206f6666736574203078496e697469616c697a61626c653a20636f6e747261637420697320616c726561647920696e697469616c697a656454797065644d656d566965772f696e646578202d20417474656d7074656420746f20696e646578206d6f7265207468616e2033322062797465735361666545524332303a204552433230206f7065726174696f6e20646964206e6f74207375636365656454797065644d656d566965772f636f7079546f202d204e756c6c20706f696e74657220646572656654797065644d656d566965772f636f7079546f202d20496e76616c696420706f696e74657220646572656654797065644d656d566965772f696e646578202d204f76657272616e2074686520766965772e20536c696365206973206174203078a2646970667358221220928d4620561113529e45756c66724a43670262220948f4f50d23517cb064924364736f6c63430007060033

Deployed ByteCode

0x60806040523480156200001157600080fd5b5060043610620001c05760003560e01c80636eb3d5fe11620000f9578063cbcacfee1162000099578063d82d0531116200006f578063d82d05311462000628578063f2fde38b146200066a578063ffa1ad7414620006a057620001c0565b8063cbcacfee14620005b2578063ccf5a77c14620005e8578063ce5494bb14620005f257620001c0565b80638da5cb5b11620000cf5780638da5cb5b1462000550578063b49c53a7146200055a578063c3a7a023146200058657620001c0565b80636eb3d5fe1462000516578063715018a6146200052057806383bbb806146200052a57620001c0565b8063485cc9551162000165578063589b3c64116200013b578063589b3c6414620004585780636256878714620004845780636cdccfb814620004fa57620001c0565b8063485cc955146200033c578063546d573d146200037a57806356d5d475146200039a57620001c0565b806328b1aea0116200019b57806328b1aea014620002b45780633339df9614620002fc57806341bdc8b5146200030657620001c0565b806303e418c214620001c55780631cabf08f146200021b5780631ecf6f9f146200026b575b600080fd5b620001fb60048036036020811015620001dd57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16620006c0565b6040805163ffffffff909316835260208301919091528051918290030190f35b62000269600480360360808110156200023357600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135169060208101359063ffffffff6040820135169060600135620006e2565b005b6200028b600480360360208110156200028357600080fd5b503562000aa6565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b6200026960048036036060811015620002cc57600080fd5b50803563ffffffff16906020810135906040013573ffffffffffffffffffffffffffffffffffffffff1662000ace565b6200028b62000e0a565b62000269600480360360208110156200031e57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff1662000e26565b62000269600480360360408110156200035457600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135811691602001351662000f1a565b6200028b600480360360208110156200039257600080fd5b50356200104e565b6200026960048036036060811015620003b257600080fd5b63ffffffff82351691602081013591810190606081016040820135640100000000811115620003e057600080fd5b820183602082011115620003f357600080fd5b803590602001918460018302840111640100000000831117156200041657600080fd5b91908080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525092955062001076945050505050565b6200028b600480360360408110156200047057600080fd5b5063ffffffff81351690602001356200133a565b62000269600480360360208110156200049c57600080fd5b810190602081018135640100000000811115620004b857600080fd5b820183602082011115620004cb57600080fd5b80359060200191846001830284011164010000000083111715620004ee57600080fd5b50909250905062001359565b62000504620015d9565b60408051918252519081900360200190f35b62000504620015df565b62000269620015e5565b62000504600480360360208110156200054257600080fd5b503563ffffffff1662001701565b6200028b62001713565b62000269600480360360408110156200057257600080fd5b5063ffffffff81351690602001356200172f565b62000269600480360360408110156200059e57600080fd5b5063ffffffff8135169060200135620017f5565b620001fb60048036036020811015620005ca57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16620018bd565b6200028b62001908565b62000269600480360360208110156200060a57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff1662001924565b6200028b600480360360408110156200064057600080fd5b50803563ffffffff16906020013573ffffffffffffffffffffffffffffffffffffffff1662001c44565b62000269600480360360208110156200068257600080fd5b503573ffffffffffffffffffffffffffffffffffffffff1662001c5c565b620006aa62001e05565b6040805160ff9092168252519081900360200190f35b60ca602052600090815260409020805460019091015463ffffffff9091169082565b600083116200075257604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600560248201527f21616d6e74000000000000000000000000000000000000000000000000000000604482015290519081900360640190fd5b80620007bf57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600660248201527f2172656369700000000000000000000000000000000000000000000000000000604482015290519081900360640190fd5b6000620007cc8362001e0a565b905084620007da8162001e92565b156200080a576200080473ffffffffffffffffffffffffffffffffffffffff821633308862001ea5565b620008a0565b620008158162001f42565b73ffffffffffffffffffffffffffffffffffffffff16639dc29fac33876040518363ffffffff1660e01b8152600401808373ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050600060405180830381600087803b1580156200088657600080fd5b505af11580156200089b573d6000803e3d6000fd5b505050505b6000620008ae848762001f45565b9050606560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16639fa92f9d6040518163ffffffff1660e01b815260040160206040518083038186803b1580156200091957600080fd5b505afa1580156200092e573d6000803e3d6000fd5b505050506040513d60208110156200094557600080fd5b505173ffffffffffffffffffffffffffffffffffffffff1663fa31de0186856200097a620009738c62001fa6565b8662001fca565b6040518463ffffffff1660e01b8152600401808463ffffffff16815260200183815260200180602001828103825283818151815260200191508051906020019080838360005b83811015620009da578181015183820152602001620009c0565b50505050905090810190601f16801562000a085780820380516001836020036101000a031916815260200191505b50945050505050600060405180830381600087803b15801562000a2a57600080fd5b505af115801562000a3f573d6000803e3d6000fd5b505060408051878152602081018a9052815163ffffffff8a16945033935073ffffffffffffffffffffffffffffffffffffffff8716927fcf20fd9072af09cee97ee48e835f72e237cebf880d75143434214e57d6496d60928290030190a450505050505050565b60cb6020526000908152604090205473ffffffffffffffffffffffffffffffffffffffff1681565b62000ad862002116565b73ffffffffffffffffffffffffffffffffffffffff1662000af862001713565b73ffffffffffffffffffffffffffffffffffffffff161462000b7b57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b604080517f40c10f1900000000000000000000000000000000000000000000000000000000815230600482015260016024820152905173ffffffffffffffffffffffffffffffffffffffff8316916340c10f1991604480830192600092919082900301818387803b15801562000bf057600080fd5b505af115801562000c05573d6000803e3d6000fd5b5050604080517f9dc29fac00000000000000000000000000000000000000000000000000000000815230600482015260016024820152905173ffffffffffffffffffffffffffffffffffffffff85169350639dc29fac9250604480830192600092919082900301818387803b15801562000c7e57600080fd5b505af115801562000c93573d6000803e3d6000fd5b50505050600062000ca584846200211a565b905062000cd47fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000082166200216c565b73ffffffffffffffffffffffffffffffffffffffff8316600090815260ca6020526040902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000001663ffffffff9290921691909117905562000d597fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000008216620021b8565b73ffffffffffffffffffffffffffffffffffffffff8316600090815260ca602052604081206001019190915562000db27fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000008316620021fa565b600090815260cb6020526040902080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff949094169390931790925550505050565b60655473ffffffffffffffffffffffffffffffffffffffff1681565b62000e3062002116565b73ffffffffffffffffffffffffffffffffffffffff1662000e5062001713565b73ffffffffffffffffffffffffffffffffffffffff161462000ed357604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b606580547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b600054610100900460ff168062000f36575062000f366200223d565b8062000f45575060005460ff16155b62000f9c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602e81526020018062005e89602e913960400191505060405180910390fd5b600054610100900460ff161580156200100357600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff909116610100171660011790555b6200100e8362002250565b6200101982620023ad565b80156200104957600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff1690555b505050565b60cc6020526000908152604090205473ffffffffffffffffffffffffffffffffffffffff1681565b620010813362002513565b620010ed57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600860248201527f217265706c696361000000000000000000000000000000000000000000000000604482015290519081900360640190fd5b8282620010fb8282620025bf565b6200116757604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600e60248201527f2172656d6f746520726f75746572000000000000000000000000000000000000604482015290519081900360640190fd5b6000620011a1620011798583620025db565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000001662002601565b90506000620011d27fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000083166200263a565b90506000620012037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000084166200267e565b9050620012327fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000821662002714565b156200124a5762001244828262002750565b62001330565b620012777fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000821662002937565b1562001289576200124482826200295a565b620012b67fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000821662002bc0565b15620012c9576200124488888462002be3565b604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600d60248201527f2176616c696420616374696f6e00000000000000000000000000000000000000604482015290519081900360640190fd5b5050505050505050565b6000620013526200134c84846200211a565b62003049565b9392505050565b6000620013a562001179600085858080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152509293925050620025db9050565b9050600062001402620013da7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000084166200263a565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000001662003128565b905060006200145f620014377fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000085166200267e565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000001662003139565b905060006200146f83836200314a565b600081815260cc602052604090205490915073ffffffffffffffffffffffffffffffffffffffff16156200150457604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600960248201527f21756e66696c6c65640000000000000000000000000000000000000000000000604482015290519081900360640190fd5b600081815260cc6020526040812080547fffffffffffffffffffffffff000000000000000000000000000000000000000016331790556200154584620031eb565b9050620015d033620015797fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000086166200327e565b620015b0620015aa7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000008816620032be565b62003300565b73ffffffffffffffffffffffffffffffffffffffff851692919062001ea5565b50505050505050565b61270b81565b61271081565b620015ef62002116565b73ffffffffffffffffffffffffffffffffffffffff166200160f62001713565b73ffffffffffffffffffffffffffffffffffffffff16146200169257604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b60335460405160009173ffffffffffffffffffffffffffffffffffffffff16907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3603380547fffffffffffffffffffffffff0000000000000000000000000000000000000000169055565b60976020526000908152604090205481565b60335473ffffffffffffffffffffffffffffffffffffffff1690565b6200173962002116565b73ffffffffffffffffffffffffffffffffffffffff166200175962001713565b73ffffffffffffffffffffffffffffffffffffffff1614620017dc57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b63ffffffff909116600090815260976020526040902055565b620017ff62002116565b73ffffffffffffffffffffffffffffffffffffffff166200181f62001713565b73ffffffffffffffffffffffffffffffffffffffff1614620018a257604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6000620018b083836200211a565b9050620010498162003312565b73ffffffffffffffffffffffffffffffffffffffff16600090815260ca60209081526040918290208251808401909352805463ffffffff168084526001909101549290910182905291565b60c95473ffffffffffffffffffffffffffffffffffffffff1681565b73ffffffffffffffffffffffffffffffffffffffff8116600090815260ca60209081526040918290208251808401909352805463ffffffff1680845260019091015491830191909152620019d957604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600560248201527f2172657072000000000000000000000000000000000000000000000000000000604482015290519081900360640190fd5b816000620019e783620034fe565b90508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16141562001a8557604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600a60248201527f21646966666572656e7400000000000000000000000000000000000000000000604482015290519081900360640190fd5b60008273ffffffffffffffffffffffffffffffffffffffff166370a08231336040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060206040518083038186803b15801562001aef57600080fd5b505afa15801562001b04573d6000803e3d6000fd5b505050506040513d602081101562001b1b57600080fd5b5051604080517f9dc29fac00000000000000000000000000000000000000000000000000000000815233600482015260248101839052905191925073ffffffffffffffffffffffffffffffffffffffff851691639dc29fac9160448082019260009290919082900301818387803b15801562001b9657600080fd5b505af115801562001bab573d6000803e3d6000fd5b5050604080517f40c10f1900000000000000000000000000000000000000000000000000000000815233600482015260248101859052905173ffffffffffffffffffffffffffffffffffffffff861693506340c10f199250604480830192600092919082900301818387803b15801562001c2457600080fd5b505af115801562001c39573d6000803e3d6000fd5b505050505050505050565b6000620013528362001c568462003515565b6200133a565b62001c6662002116565b73ffffffffffffffffffffffffffffffffffffffff1662001c8662001713565b73ffffffffffffffffffffffffffffffffffffffff161462001d0957604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b73ffffffffffffffffffffffffffffffffffffffff811662001d77576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602681526020018062005e1c6026913960400191505060405180910390fd5b60335460405173ffffffffffffffffffffffffffffffffffffffff8084169216907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a3603380547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b600081565b63ffffffff81166000908152609760205260409020548062001e8d57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600760248201527f2172656d6f746500000000000000000000000000000000000000000000000000604482015290519081900360640190fd5b919050565b600062001e9f826200352e565b92915050565b6040805173ffffffffffffffffffffffffffffffffffffffff80861660248301528416604482015260648082018490528251808303909101815260849091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f23b872dd0000000000000000000000000000000000000000000000000000000017905262001f3c90859062003570565b50505050565b90565b60006200135262001fa06000600386866040516020018084600581111562001f6957fe5b60f81b81526001018381526020018281526020019350505050604051602081830303815290604052620025db90919063ffffffff16565b62003139565b60008062001fb4836200364e565b905062001352816000015182602001516200211a565b606082600162001fff815b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000841690620036ce565b506200200b846200385a565b6200207757604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600760248201527f21616374696f6e00000000000000000000000000000000000000000000000000604482015290519081900360640190fd5b6040805160028082526060820183526000926020830190803683370190505090508581600081518110620020a757fe5b602002602001019062ffffff1916908162ffffff1916815250508481600181518110620020d057fe5b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000909216602092830291909101909101526200210c816200388b565b9695505050505050565b3390565b6000620013526200216660008585604051602001808363ffffffff1660e01b815260040182815260200192505050604051602081830303815290604052620025db90919063ffffffff16565b62003128565b60008160016200217c8162001fd5565b50620021ae7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000851660006004620038e1565b92505b5050919050565b6000816001620021c88162001fd5565b50620021ae7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000085166004602062003904565b600080620022088362003a87565b6bffffffffffffffffffffffff1690506000620022258462003a9b565b6bffffffffffffffffffffffff169091209392505050565b60006200224a3062003aaf565b15905090565b600054610100900460ff16806200226c57506200226c6200223d565b806200227b575060005460ff16155b620022d2576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602e81526020018062005e89602e913960400191505060405180910390fd5b600054610100900460ff161580156200233957600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff909116610100171660011790555b60c980547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff84161790558015620023a957600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff1690555b5050565b600054610100900460ff1680620023c95750620023c96200223d565b80620023d8575060005460ff16155b6200242f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602e81526020018062005e89602e913960400191505060405180910390fd5b600054610100900460ff161580156200249657600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff909116610100171660011790555b606580547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff8416179055620024e062003ab5565b8015620023a957600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff1690555050565b606554604080517f5190bc5300000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff848116600483015291516000939290921691635190bc5391602480820192602092909190829003018186803b1580156200258b57600080fd5b505afa158015620025a0573d6000803e3d6000fd5b505050506040513d6020811015620025b757600080fd5b505192915050565b63ffffffff919091166000908152609760205260409020541490565b815160009060208401620025f864ffffffffff8516828462003be4565b95945050505050565b600062001e9f620026128362003c41565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000001662003c8f565b60008160026200264a8162001fd5565b50620021ae7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000851660006024600162003d0c565b60008160026200268e8162001fd5565b5060006024620026c07fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000871662003a9b565b6bffffffffffffffffffffffff160390506000620026de8662003da0565b60ff1690506200210c7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000087166024848462003d0c565b60006003620027238362003dd3565b60ff1614801562001e9f575060035b6200273d8362003e05565b60058111156200274957fe5b1492915050565b60006200275d8362003e43565b905060006200278e7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000084166200327e565b905060006200279e85856200314a565b600081815260cc602052604090205490915073ffffffffffffffffffffffffffffffffffffffff1680156200280557600082815260cc6020526040902080547fffffffffffffffffffffffff00000000000000000000000000000000000000001690559150815b620028108462001e92565b156200286d576200286783620028487fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000008816620032be565b73ffffffffffffffffffffffffffffffffffffffff8716919062003e87565b6200292f565b620028788462001f42565b73ffffffffffffffffffffffffffffffffffffffff166340c10f1984620028c17fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000008916620032be565b6040518363ffffffff1660e01b8152600401808373ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050600060405180830381600087803b1580156200291557600080fd5b505af11580156200292a573d6000803e3d6000fd5b505050505b505050505050565b60006004620029468362003dd3565b60ff1614801562001e9f5750600462002732565b60006200296783620031eb565b9050620029748162001e92565b15620029e157604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600e60248201527f2172656d6f7465206f726967696e000000000000000000000000000000000000604482015290519081900360640190fd5b620029ec8162001f42565b73ffffffffffffffffffffffffffffffffffffffff1663654935f462002a3e62002a387fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000861662003f16565b62003f58565b62002a6f62002a387fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000871662003fcf565b62002a9c7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000871662004011565b6040518463ffffffff1660e01b81526004018080602001806020018460ff168152602001838103835286818151815260200191508051906020019080838360005b8381101562002af757818101518382015260200162002add565b50505050905090810190601f16801562002b255780820380516001836020036101000a031916815260200191505b50838103825285518152855160209182019187019080838360005b8381101562002b5a57818101518382015260200162002b40565b50505050905090810190601f16801562002b885780820380516001836020036101000a031916815260200191505b5095505050505050600060405180830381600087803b15801562002bab57600080fd5b505af1158015620015d0573d6000803e3d6000fd5b6000600562002bcf8362003dd3565b60ff1614801562001e9f5750600562002732565b600062002c127fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000831662004053565b905062002c1f816200352e565b62002c8b57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600d60248201527f216c6f63616c206f726967696e00000000000000000000000000000000000000604482015290519081900360640190fd5b6000819050600062002ed762002dfc8373ffffffffffffffffffffffffffffffffffffffff166306fdde036040518163ffffffff1660e01b8152600401600060405180830381600087803b15801562002ce357600080fd5b505af115801562002cf8573d6000803e3d6000fd5b505050506040513d6000823e601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0168201604052602081101562002d4057600080fd5b810190808051604051939291908464010000000082111562002d6157600080fd5b90830190602082018581111562002d7757600080fd5b825164010000000081118282018810171562002d9257600080fd5b82525081516020918201929091019080838360005b8381101562002dc157818101518382015260200162002da7565b50505050905090810190601f16801562002def5780820380516001836020036101000a031916815260200191505b5060405250505062004093565b62002e5c8473ffffffffffffffffffffffffffffffffffffffff166395d89b416040518163ffffffff1660e01b815260040160006040518083038186803b15801562002e4757600080fd5b505afa15801562002cf8573d6000803e3d6000fd5b8473ffffffffffffffffffffffffffffffffffffffff1663313ce5676040518163ffffffff1660e01b815260040160206040518083038186803b15801562002ea357600080fd5b505afa15801562002eb8573d6000803e3d6000fd5b505050506040513d602081101562002ecf57600080fd5b5051620040dd565b9050606560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16639fa92f9d6040518163ffffffff1660e01b815260040160206040518083038186803b15801562002f4257600080fd5b505afa15801562002f57573d6000803e3d6000fd5b505050506040513d602081101562002f6e57600080fd5b505173ffffffffffffffffffffffffffffffffffffffff1663fa31de01878762002f99888662001fca565b6040518463ffffffff1660e01b8152600401808463ffffffff16815260200183815260200180602001828103825283818151815260200191508051906020019080838360005b8381101562002ff957818101518382015260200162002fdf565b50505050905090810190601f168015620030275780820380516001836020036101000a031916815260200191505b50945050505050600060405180830381600087803b1580156200291557600080fd5b6000620030556200414c565b63ffffffff16620030887fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000084166200216c565b63ffffffff161415620030ca57620030c27fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000831662004053565b905062001e8d565b60cb6000620030fb7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000008516620021fa565b815260208101919091526040016000205473ffffffffffffffffffffffffffffffffffffffff1692915050565b600062001e9f62002612836200415d565b600062001e9f6200261283620041af565b6040805160028082526060820183526000928392919060208301908036833701905050905083816000815181106200317e57fe5b602002602001019062ffffff1916908162ffffff1916815250508281600181518110620031a757fe5b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000090921660209283029190910190910152620031e38162004201565b949350505050565b600080620031f98362003049565b905073ffffffffffffffffffffffffffffffffffffffff811662001e9f57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600660248201527f21746f6b656e0000000000000000000000000000000000000000000000000000604482015290519081900360640190fd5b60008160036200328e8162001fd5565b50620021ae7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000008516600d6200421d565b6000816003620032ce8162001fd5565b50620021ae7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000851660216020620038e1565b600061271061270b83025b0492915050565b6000620033417fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000083166200216c565b63ffffffff81166000908152609760205260409020549091508062003368575050620034fb565b6000620033746200422d565b9050606560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16639fa92f9d6040518163ffffffff1660e01b815260040160206040518083038186803b158015620033df57600080fd5b505afa158015620033f4573d6000803e3d6000fd5b505050506040513d60208110156200340b57600080fd5b505173ffffffffffffffffffffffffffffffffffffffff1663fa31de01848462003436888662001fca565b6040518463ffffffff1660e01b8152600401808463ffffffff16815260200183815260200180602001828103825283818151815260200191508051906020019080838360005b83811015620034965781810151838201526020016200347c565b50505050905090810190601f168015620034c45780820380516001836020036101000a031916815260200191505b50945050505050600060405180830381600087803b158015620034e657600080fd5b505af115801562001330573d6000803e3d6000fd5b50565b600062001e9f6200350f836200427e565b62004294565b73ffffffffffffffffffffffffffffffffffffffff1690565b73ffffffffffffffffffffffffffffffffffffffff8116600090815260ca602052604081205463ffffffff1615620035695750600062001e8d565b503b151590565b6000620035d4826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c65648152508573ffffffffffffffffffffffffffffffffffffffff16620042c69092919063ffffffff16565b8051909150156200104957808060200190516020811015620035f557600080fd5b505162001049576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602a81526020018062005ef1602a913960400191505060405180910390fd5b620036586200586b565b5073ffffffffffffffffffffffffffffffffffffffff8116600090815260ca60209081526040918290208251808401909352805463ffffffff168084526001909101549183019190915262001e8d57620036b16200414c565b63ffffffff168152620036c48262003515565b6020820152919050565b6000620036dc8383620042d7565b62003853576000620036ff620036f285620042fb565b64ffffffffff1662004301565b9150506000620037168464ffffffffff1662004301565b604080517f5479706520617373657274696f6e206661696c65642e20476f742030780000006020808301919091527fffffffffffffffffffff0000000000000000000000000000000000000000000060b088811b8216603d8501527f2e20457870656374656420307800000000000000000000000000000000000000604785015285901b1660548301528251603e818403018152605e8301938490527f08c379a000000000000000000000000000000000000000000000000000000000909352606282018181528351608284015283519496509294508493839260a2019185019080838360005b8381101562003817578181015183820152602001620037fd565b50505050905090810190601f168015620038455780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b5090919050565b6000620038678262002937565b80620038795750620038798262002bc0565b8062001e9f575062001e9f8262002714565b6040516060906000620038a28460208401620043df565b90506000620038b18262003a9b565b6bffffffffffffffffffffffff1690506000620038ce8362004461565b9184525082016020016040525092915050565b60008160200360080260ff16620038fa85858562003904565b901c949350505050565b600060ff8216620039185750600062001352565b620039238462003a9b565b6bffffffffffffffffffffffff16620039408460ff851662004477565b1115620039eb5762003988620039568562003a87565b6bffffffffffffffffffffffff166200396f8662003a9b565b6bffffffffffffffffffffffff16858560ff16620044ea565b6040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181815283516024840152835190928392604490910191908501908083836000831562003817578181015183820152602001620037fd565b60208260ff16111562003a4a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252603a81526020018062005eb7603a913960400191505060405180910390fd5b60088202600062003a5b8662003a87565b6bffffffffffffffffffffffff169050600062003a78836200464f565b91909501511695945050505050565b60781c6bffffffffffffffffffffffff1690565b60181c6bffffffffffffffffffffffff1690565b3b151590565b600054610100900460ff168062003ad1575062003ad16200223d565b8062003ae0575060005460ff16155b62003b37576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602e81526020018062005e89602e913960400191505060405180910390fd5b600054610100900460ff1615801562003b9e57600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff909116610100171660011790555b62003ba862004698565b62003bb2620047b2565b8015620034fb57600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff16905550565b60008062003bf3848462004477565b905060405181111562003c04575060005b8062003c34577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000091505062001352565b620025f88585856200494c565b600062003c4e826200495f565b1562003c8557620030c260025b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000841690620049bf565b62001e9f620049e5565b600062003c9c8262004a09565b62003d0857604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601960248201527f56616c696469747920617373657274696f6e206661696c656400000000000000604482015290519081900360640190fd5b5090565b60008062003d1a8662003a87565b6bffffffffffffffffffffffff16905062003d358662004a4c565b62003d4d8562003d46848962004477565b9062004477565b111562003d7e577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000915050620031e3565b62003d8a818662004477565b90506200210c8364ffffffffff16828662003be4565b600062001e9f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000831660246001620038e1565b600062001e9f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000008316826001620038e1565b600062003e347fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000008316620042fb565b60ff16600581111562001e9f57fe5b60008062003e518362003049565b905073ffffffffffffffffffffffffffffffffffffffff811662001e9f5762003e7a8362004a7a565b905062001e9f8362003312565b6040805173ffffffffffffffffffffffffffffffffffffffff8416602482015260448082018490528251808303909101815260649091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fa9059cbb000000000000000000000000000000000000000000000000000000001790526200104990849062003570565b600081600462003f268162001fd5565b50620021ae7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000085166001602062003904565b606060005b60208160ff1610801562003fa55750828160ff166020811062003f7c57fe5b1a60f81b7fff000000000000000000000000000000000000000000000000000000000000001615155b1562003fb45760010162003f5d565b60405191506040820160405280825282602083015250919050565b600081600462003fdf8162001fd5565b50620021ae7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000085166021602062003904565b6000816004620040218162001fd5565b50620021ae7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000851660416001620038e1565b6000816001620040638162001fd5565b50620021ae7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000851660106200421d565b600062001e9f60008351620040b3600086620025db90919063ffffffff16565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000016919062003904565b6000620031e36200414660006004878787604051602001808560058111156200410257fe5b60f81b81526001018481526020018381526020018260ff1660f81b8152600101945050505050604051602081830303815290604052620025db90919063ffffffff16565b62004e87565b60006200415862004e98565b905090565b600060246200418e7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000841662003a9b565b6bffffffffffffffffffffffff16141562003c8557620030c2600162003c5b565b60006041620041e07fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000841662003a9b565b6bffffffffffffffffffffffff16141562003c8557620030c2600362003c5b565b60405160009062001352620042178483620043df565b620021fa565b60006200135283836014620038e1565b6000620041586200427860006005604051602001808260058111156200424f57fe5b60f81b8152600101915050604051602081830303815290604052620025db90919063ffffffff16565b62004f37565b600062001e9f826000015183602001516200211a565b600060cb81620030fb7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000008516620021fa565b6060620031e3848460008562004f48565b60008164ffffffffff16620042ec84620042fb565b64ffffffffff16149392505050565b60d81c90565b600080601f5b600f8160ff1611156200436e5760ff600882021684901c62004329816200510d565b61ffff16841793508160ff166010146200434557601084901b93505b507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0162004307565b50600f5b60ff8160ff161015620043d95760ff600882021684901c62004394816200510d565b61ffff16831792508160ff16600014620043b057601083901b92505b507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0162004372565b50915091565b600060405182811115620043f35760206060fd5b506000805b8451811015620044525760008582815181106200441157fe5b60200260200101519050620044298184870162005141565b50620044358162003a9b565b6bffffffffffffffffffffffff16929092019150600101620043f8565b50620031e3600084836200494c565b60006200446e826200527e565b60200292915050565b8181018281101562001e9f57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601960248201527f4f766572666c6f7720647572696e67206164646974696f6e2e00000000000000604482015290519081900360640190fd5b60606000620044f98662004301565b9150506000620045098662004301565b9150506000620045198662004301565b9150506000620045298662004301565b91505083838383604051602001808062005f6e603591397fffffffffffff000000000000000000000000000000000000000000000000000060d087811b821660358401527f2077697468206c656e6774682030780000000000000000000000000000000000603b84015286901b16604a820152605001602162005e6882397fffffffffffff000000000000000000000000000000000000000000000000000060d094851b811660218301527f2077697468206c656e677468203078000000000000000000000000000000000060278301529290931b9091166036830152507f2e00000000000000000000000000000000000000000000000000000000000000603c82015260408051601d818403018152603d90920190529b9a5050505050505050505050565b7f80000000000000000000000000000000000000000000000000000000000000007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9091011d90565b600054610100900460ff1680620046b45750620046b46200223d565b80620046c3575060005460ff16155b6200471a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602e81526020018062005e89602e913960400191505060405180910390fd5b600054610100900460ff1615801562003bb257600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff909116610100171660011790558015620034fb57600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff16905550565b600054610100900460ff1680620047ce5750620047ce6200223d565b80620047dd575060005460ff16155b62004834576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602e81526020018062005e89602e913960400191505060405180910390fd5b600054610100900460ff161580156200489b57600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff909116610100171660011790555b6000620048a762002116565b603380547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff8316908117909155604051919250906000907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908290a3508015620034fb57600080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff16905550565b606092831b9190911790911b1760181b90565b6000806200498f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000841662003a9b565b6bffffffffffffffffffffffff1690506065811480620049af5750606681145b8062001352575060251492915050565b60d81b7affffffffffffffffffffffffffffffffffffffffffffffffffffff9091161790565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000090565b600062004a1682620042fb565b64ffffffffff1664ffffffffff141562004a335750600062001e8d565b600062004a408362004a4c565b60405110199392505050565b600062004a598262003a9b565b62004a648362003a87565b016bffffffffffffffffffffffff169050919050565b60c95460405160009173ffffffffffffffffffffffffffffffffffffffff169062004aa59062005882565b73ffffffffffffffffffffffffffffffffffffffff909116815260406020820181905260008183018190529051918290036060019190f08015801562004aef573d6000803e3d6000fd5b5090508073ffffffffffffffffffffffffffffffffffffffff16638129fc1c6040518163ffffffff1660e01b8152600401600060405180830381600087803b15801562004b3b57600080fd5b505af115801562004b50573d6000803e3d6000fd5b5050505060608062004b6284620052b0565b80925081935050508273ffffffffffffffffffffffffffffffffffffffff1663654935f4838360126040518463ffffffff1660e01b8152600401808060200180602001848152602001838103835286818151815260200191508051906020019080838360005b8381101562004be257818101518382015260200162004bc8565b50505050905090810190601f16801562004c105780820380516001836020036101000a031916815260200191505b50838103825285518152855160209182019187019080838360005b8381101562004c4557818101518382015260200162004c2b565b50505050905090810190601f16801562004c735780820380516001836020036101000a031916815260200191505b5095505050505050600060405180830381600087803b15801562004c9657600080fd5b505af115801562004cab573d6000803e3d6000fd5b5050505062004cc08462ffffff19166200216c565b73ffffffffffffffffffffffffffffffffffffffff8416600090815260ca6020526040902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000001663ffffffff9290921691909117905562004d457fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000008516620021b8565b73ffffffffffffffffffffffffffffffffffffffff8416600090815260ca6020526040812060010191909155839060cb9062004da37fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000008816620021fa565b8152602081019190915260400160002080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff928316179055831662004e217fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000008616620021b8565b62004e4e7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000087166200216c565b63ffffffff167f84d5e3618bf276f3d29a931646fdd996b398a3efa3cf6bceefc1fe7f0304059f60405160405180910390a45050919050565b600062001e9f6200261283620053ca565b606554604080517f8d3638f4000000000000000000000000000000000000000000000000000000008152905160009273ffffffffffffffffffffffffffffffffffffffff1691638d3638f4916004808301926020929190829003018186803b15801562004f0457600080fd5b505afa15801562004f19573d6000803e3d6000fd5b505050506040513d602081101562004f3057600080fd5b5051905090565b600062001e9f62002612836200541c565b60608247101562004fa5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602681526020018062005e426026913960400191505060405180910390fd5b62004fb08562003aaf565b6200501c57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015290519081900360640190fd5b6000808673ffffffffffffffffffffffffffffffffffffffff1685876040518082805190602001908083835b602083106200508757805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0909201916020918201910162005048565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d8060008114620050eb576040519150601f19603f3d011682016040523d82523d6000602084013e620050f0565b606091505b5091509150620051028282866200546e565b979650505050505050565b60006200512160048360ff16901c620054f3565b60ff161760081b62ffff00166200513882620054f3565b60ff1617919050565b60006200514e836200567f565b620051a5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602881526020018062005f1b6028913960400191505060405180910390fd5b620051b08362004a09565b62005207576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602b81526020018062005f43602b913960400191505060405180910390fd5b6000620052148462003a9b565b6bffffffffffffffffffffffff1690506000620052318562003a87565b6bffffffffffffffffffffffff1690506000604051905084811115620052575760206060fd5b8285848460045afa506200210c6200526f87620042fb565b64ffffffffff1686856200494c565b60006020620052a86020620052938562003a9b565b6bffffffffffffffffffffffff169062004477565b816200330b57fe5b6060806000620052ec620052e67fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000008616620021b8565b62005693565b9150506200530a620053048562ffffff19166200216c565b6200576b565b6040805160b09290921b7fffffffffffffffffffff000000000000000000000000000000000000000000001660208301527f2e00000000000000000000000000000000000000000000000000000000000000602a83015260e083901b7fffffffff0000000000000000000000000000000000000000000000000000000016602b8301528051808303600f9081018252602f8401818152606f85019093529095509091604f0181803683370190505091506020830151602083015250915091565b60006042620053fb7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000841662003a9b565b6bffffffffffffffffffffffff16141562003c8557620030c2600462003c5b565b600060016200544d7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000841662003a9b565b6bffffffffffffffffffffffff16141562003c8557620030c2600562003c5b565b606083156200547f57508162001352565b825115620054905782518084602001fd5b6040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181815284516024840152845185939192839260440191908501908083836000831562003817578181015183820152602001620037fd565b600060f08083179060ff821614156200551157603091505062001e8d565b8060ff1660f114156200552957603191505062001e8d565b8060ff1660f214156200554157603291505062001e8d565b8060ff1660f314156200555957603391505062001e8d565b8060ff1660f414156200557157603491505062001e8d565b8060ff1660f514156200558957603591505062001e8d565b8060ff1660f61415620055a157603691505062001e8d565b8060ff1660f71415620055b957603791505062001e8d565b8060ff1660f81415620055d157603891505062001e8d565b8060ff1660f91415620055e957603991505062001e8d565b8060ff1660fa14156200560157606191505062001e8d565b8060ff1660fb14156200561957606291505062001e8d565b8060ff1660fc14156200563157606391505062001e8d565b8060ff1660fd14156200564957606491505062001e8d565b8060ff1660fe14156200566157606591505062001e8d565b8060ff1660ff14156200567957606691505062001e8d565b50919050565b60006200568c82620057c6565b1592915050565b600080601f5b600f8160ff161115620057005760ff600882021684901c620056bb81620057ee565b61ffff16841793508160ff16601014620056d757601084901b93505b507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0162005699565b50600f5b60ff8160ff161015620043d95760ff600882021684901c6200572681620057ee565b61ffff16831792508160ff166000146200574257601083901b92505b507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0162005704565b60006030815b600a8160ff161015620021b15760ff600882021682600a63ffffffff87160663ffffffff160169ffffffffffffffffffff16901b83179250600a8463ffffffff1681620057ba57fe5b04935060010162005771565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000009081161490565b60006200580260048360ff16901c62005814565b60ff161760081b62ffff001662005138825b6040805180820190915260108082527f30313233343536373839616263646566000000000000000000000000000000006020830152600091600f841691829081106200585c57fe5b016020015160f81c9392505050565b604080518082019091526000808252602082015290565b61058b80620058918339019056fe60a060405260405161058b38038061058b8339818101604052604081101561002657600080fd5b81516020830180516040519294929383019291908464010000000082111561004d57600080fd5b90830190602082018581111561006257600080fd5b825164010000000081118282018810171561007c57600080fd5b82525081516020918201929091019080838360005b838110156100a9578181015183820152602001610091565b50505050905090810190601f1680156100d65780820380516001836020036101000a031916815260200191505b506040525050506100f0826101d060201b6100291760201c565b610134576040805162461bcd60e51b815260206004820152601060248201526f18995858dbdb880858dbdb9d1c9858dd60821b604482015290519081900360640190fd5b6001600160601b0319606083901b166080526000610151836101d6565b9050610166816101d060201b6100291760201c565b6101b7576040805162461bcd60e51b815260206004820152601f60248201527f626561636f6e20696d706c656d656e746174696f6e2021636f6e747261637400604482015290519081900360640190fd5b8151156101c8576101c881836102d6565b50505061038f565b3b151590565b604051600090819081906001600160a01b0385169082818181855afa9150503d8060008114610221576040519150601f19603f3d011682016040523d82523d6000602084013e610226565b606091505b50915091508181906102b65760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b8381101561027b578181015183820152602001610263565b50505050905090810190601f1680156102a85780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b508080602001905160208110156102cc57600080fd5b5051949350505050565b6000826001600160a01b0316826040518082805190602001908083835b602083106103125780518252601f1990920191602091820191016102f3565b6001836020036101000a038019825116818451168082178552505050505050905001915050600060405180830381855af49150503d8060008114610372576040519150601f19603f3d011682016040523d82523d6000602084013e610377565b606091505b505090508061038a573d6000803e3d6000fd5b505050565b60805160601c6101e06103ab60003980603652506101e06000f3fe60806040523661001357610011610017565b005b6100115b61002761002261002f565b61005f565b565b3b151590565b600061005a7f0000000000000000000000000000000000000000000000000000000000000000610083565b905090565b3660008037600080366000845af43d6000803e80801561007e573d6000f35b3d6000fd5b6040516000908190819073ffffffffffffffffffffffffffffffffffffffff85169082818181855afa9150503d80600081146100db576040519150601f19603f3d011682016040523d82523d6000602084013e6100e0565b606091505b509150915081819061018a576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825283818151815260200191508051906020019080838360005b8381101561014f578181015183820152602001610137565b50505050905090810190601f16801561017c5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b508080602001905160208110156101a057600080fd5b505194935050505056fea2646970667358221220acaa13070c5929df67757f0af9d23c2ae2dfb97f784ab2d6361279077a730bf864736f6c634300070600334f776e61626c653a206e6577206f776e657220697320746865207a65726f2061646472657373416464726573733a20696e73756666696369656e742062616c616e636520666f722063616c6c2e20417474656d7074656420746f20696e646578206174206f6666736574203078496e697469616c697a61626c653a20636f6e747261637420697320616c726561647920696e697469616c697a656454797065644d656d566965772f696e646578202d20417474656d7074656420746f20696e646578206d6f7265207468616e2033322062797465735361666545524332303a204552433230206f7065726174696f6e20646964206e6f74207375636365656454797065644d656d566965772f636f7079546f202d204e756c6c20706f696e74657220646572656654797065644d656d566965772f636f7079546f202d20496e76616c696420706f696e74657220646572656654797065644d656d566965772f696e646578202d204f76657272616e2074686520766965772e20536c696365206973206174203078a2646970667358221220928d4620561113529e45756c66724a43670262220948f4f50d23517cb064924364736f6c63430007060033