false
true
0

Contract Address Details

0x571f96605921f76a24cF1388C2CaF126b15b09f7

Contract Name
TokenMediator
Creator
0xf71cba–f75eac at 0xae1971–05b428
Balance
0 tPLS
Tokens
Fetching tokens...
Transactions
Fetching transactions...
Transfers
Fetching transfers...
Gas Used
Fetching gas used...
Last Balance Update
26048724
Warning! Contract bytecode has been changed and doesn't match the verified one. Therefore, interaction with this smart contract may be risky.
Contract name:
TokenMediator




Optimization enabled
false
Compiler version
v0.8.28+commit.7893614a




EVM Version




Verified at
2026-11-19T13:51:07.474429Z

Constructor Arguments

0000000000000000000000005897d3de91d59fb691e3887d6ffbba072384293a000000000000000000000000571f96605921f76a24cf1388c2caf126b15b09f700000000000000000000000000000000000000000000000000000000000000000000000000000000000000002436b1826a4879e90b565638147fe1c5c24364e5
              

src/hardened/mediator/TokenMediator.sol

// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import {IFlowLimiter} from "../IFlowLimiter.sol";
import {IAMB} from "../IAMB.sol";
import {ITokenMediator} from "./ITokenMediator.sol";
import {IBurnableMintableERC677Token} from "./IBurnableMintableERC677Token.sol";
import {IERC20Receiver} from "./IERC20Receiver.sol";
import {TokenFactory} from "./TokenFactory.sol";
import {MediatorPayloads, IMediatorHandlers, COPY_NAME_CONNECTOR, COPY_SYMBOL_PREFIX} from "./MediatorPayloads.sol";
import {ExactGasCall} from "./ExactGasCall.sol";

/// @title TokenMediator
/// @notice Moves tokens across the message bridge, with the interface of the OmniBridge multi-token mediator
/// (`omni/omnibridge`, `BasicOmnibridge`, `HomeOmnibridge`) and without its owner, proxy, limits and registration.
/// @dev The mediator is the target of the message bridge on each chain, and it trusts one account only: the mediator on
/// the other chain, reached through the bridge from the other chain.
///
/// A token is native on the chain where it exists. Relaying a native token locks it here and mints a bridged copy on
/// the other chain. Relaying a bridged copy burns it and unlocks the native token on the other chain. Neither side
/// needs pre-loaded funds. A bridged copy is deployed on first use at a computed address (see `TokenFactory`), so no
/// registration exists. Until the first return trip, every message for a native token carries its name, symbol and
/// decimals, so the messages of one token can execute in any order. A return trip proves the copy exists, and then
/// the mediator sends the short form.
///
/// Accounting. `mediatorBalance(token)` is the amount of a native token that the mediator owes to the other chain:
/// what it locked, less what it released, counted from the amount it received (balance before and after a pull). A
/// token that arrives by a plain transfer is in no record, and nothing pays it out. A fee on transfer token bridges
/// the amount that arrived. The balance of the mediator covers `mediatorBalance` for each native token.
///
/// Rebasing tokens are not supported. A token whose balance changes with no transfer (a rebase, an interest bearing
/// token, a token with a negative rebase) can leave the record above the real balance, and then releases fail. The
/// mediator has no function to correct a record, because it has no owner.
///
/// Delivery of a release. The message bridge delivers a message only when the handler succeeds: a handler that
/// reverts leaves the message undelivered, and anyone can deliver it again. The rule at every call that the mediator
/// makes during a release is the same: not enough gas reverts the whole delivery (it can run again with more gas); a
/// callee that says no is recorded and the delivery completes. So a handler does not revert on a token or a limiter
/// that refuses the recipient: it tries the recipient once, and when the recipient cannot take the tokens it emits
/// `ReleaseFailed` and stops. That release is final: there is no claim, no retry and no payee but the recipient. A
/// fallback payee belongs in a router, as an option. A token or a limiter that fails after it used up all the gas that
/// it got is read as a lack of gas, not as a refusal, and the delivery reverts. A token that burns all the gas of
/// every transfer therefore keeps its release undelivered until it stops doing that.
///
/// A failed release and the books. The other chain burned its copies, or locked its native tokens, when it sent the
/// message, so the failed release leaves nothing owed. For a native token, the record falls by the value of every
/// release, paid or failed, and the failed amount stays in the balance of the mediator, owed to nobody. The balance
/// then exceeds the record by the stuck amount, as for a token that arrives by a plain transfer. For a bridged copy, a
/// failed release mints nothing. Only an invalid recipient (the zero address) can make a mint fail, and a sender cannot
/// name it, so the case needs a forged message. Then the native tokens stay locked on the other chain. A transfer
/// attempt gets the gas that is left, less `TRANSFER_GAS_RESERVE`, so a token that burns all its gas still leaves
/// enough gas to tell that case apart and revert.
///
/// Gas. The mediator has no gas rules and no defaults. The message bridge gives a handler all the gas that the executor
/// brings, and an executor that brings too little only loses its own transaction. The one gas number is the gas of the
/// callback: a sender of a relay with a call states `callbackGas`, the message carries it, and the handler on the other
/// chain calls `onTokenBridged` with exactly that gas (see `ExactGasCall`). The gas guarantee is the same for every
/// receiver contract: the mediator knows no router.
///
/// Divergences from OmniBridge. The handlers also check `messageSourceChainId`. `deploy` takes the native token.
/// Tokens are not registered by an owner. There are no limits, no failed message fix and no claim of stray tokens.
/// The mediator charges no fee. A relay with a call states the gas of the callback, so `relayTokensAndCall` takes a
/// `callbackGas` argument, the three `...AndCall` handlers take it after `data`, and the ERC-677 data of a call carries
/// it after the receiver. The relay with a call and no gas argument of OmniBridge does not exist here.
contract TokenMediator is ITokenMediator, IMediatorHandlers, ReentrancyGuard {
    using SafeERC20 for IERC20;

    /// @notice The terms at deployment.
    /// @param bridge The message bridge on this chain.
    /// @param remoteMediator The mediator on the other chain. It is the only account whose messages the mediator
    /// accepts. With deployment from the same account and the same nonce on both chains, it has the address of this
    /// mediator.
    /// @param flowLimiter The flow limiter. Zero means no limiter from the start. Nothing can set one later.
    /// @param tokenFactory The factory that deploys the bridged copies, deployed before the mediator with the predicted
    /// address of this mediator as its `mediator`. Its `homeChainName` is the name of the other chain, for example
    /// `Ethereum`, which a bridged copy takes in its name; it cannot be empty and it cannot change.
    struct MediatorTerms {
        address bridge;
        address remoteMediator;
        address flowLimiter;
        address tokenFactory;
    }

    /// @dev Whether the delivery calls `onTokenBridged` on the account that received the tokens.
    enum CallMode {
        Plain,
        WithCall
    }

    /// @dev Whether a token is native to this chain or a bridged copy of a token of the other chain.
    enum Side {
        Native,
        Bridged
    }

    /// @dev What a handler delivers. `callbackGas` is the gas of the callback, zero for a plain delivery.
    struct Delivery {
        address recipient;
        uint256 value;
        bytes data;
        CallMode mode;
        uint256 callbackGas;
    }

    /// @notice The gas that a release keeps back when it calls a native token. Each transfer attempt gets the gas
    /// that is left, less this reserve. The reserve pays for what runs after the attempt: the check that tells a lack
    /// of gas from a refusal, and the event of a failed release. The figure comes from the gas report of
    /// `TokenMediatorHostileGas` and has a margin: see `docs/hardened-build-contract.md`.
    uint256 public constant TRANSFER_GAS_RESERVE = 60_000;

    /// @notice The gas that the mediator keeps for itself after the callback: the event of a failed callback and the
    /// return to the bridge. A delivery must have the gas of the callback, its 63/64 share and this reserve.
    uint256 public constant CALLBACK_GAS_RESERVE = 10_000;

    /// @notice The text between the name of a native token and the name of its home chain, in the name of a bridged
    /// copy. The copy of `Wrapped Ether` from Ethereum is `Wrapped Ether from Ethereum`.
    string public constant NAME_CONNECTOR = COPY_NAME_CONNECTOR;
    /// @notice The prefix that a bridged copy adds to the symbol of its native token, with no separator. The copy of
    /// `WETH` is `zWETH`.
    string public constant SYMBOL_PREFIX = COPY_SYMBOL_PREFIX;

    /// @notice The caller of a handler is not the message bridge.
    error NotBridge(address caller);
    /// @notice The message bridge passes a message from an account that is not the mediator on the other chain.
    error WrongRemoteMediator(address expected, address actual);
    /// @notice The message bridge passes a message from a chain that is not the other chain.
    error WrongSourceChain(bytes32 expected, bytes32 actual);
    /// @notice A constructor argument is zero.
    error ZeroValue(string name);
    /// @notice The token factory of the terms names another mediator.
    error FactoryOfAnotherMediator(address mediator);
    /// @notice A relay with a call states no gas for the callback. There is no default.
    error ZeroCallbackGas();
    /// @notice The ERC-677 data is longer than a receiver and shorter than a receiver and the callback gas.
    error MalformedTransferData(uint256 length);
    /// @notice A token, the copy or the flow limiter failed after it used up the gas that it got during a release. The
    /// delivery reverts, so it can run again with more gas.
    error ReleaseOutOfGas(address token);
    /// @notice Only the flow limiter may detach itself. After a detach nobody can.
    error NotFlowLimiter(address caller);
    /// @notice The receiver on the other chain is the zero address, or the mediator on the other chain.
    error InvalidReceiver(address receiver);
    /// @notice The amount to bridge is zero.
    error ZeroAmount();
    /// @notice The token took more from the mediator than the sender named. The token is not supported.
    error ReceivedMoreThanSent(uint256 received, uint256 sent);
    /// @notice A token reports a transfer that the balance of the mediator does not show.
    error UnbackedTransfer(address token, uint256 value, uint256 unaccounted);
    /// @notice A token has neither a name nor a symbol, so the other chain could not name its copy.
    error NoTokenName(address token);
    /// @notice A release arrived while the mediator pulls tokens from a sender.
    error HandlerDuringTransfer();
    /// @notice The record of a native token holds less than a release asks for.
    error InsufficientMediatorBalance(address token, uint256 balance, uint256 value);
    /// @notice The other chain sent a short form message for a token whose copy does not exist here.
    error UnknownBridgedToken(address nativeToken);
    /// @notice The record of a native token would pass the width of the record.
    error MediatorBalanceOverflow(address token);

    /// @notice Emitted when a sender starts a transfer, with the amount that arrived.
    event TokensBridgingInitiated(
        address indexed token, address indexed sender, uint256 value, bytes32 indexed messageId
    );
    /// @notice Emitted when a delivery pays the recipient of the message.
    event TokensBridged(address indexed token, address indexed recipient, uint256 value, bytes32 indexed messageId);
    /// @notice Emitted when the mediator deploys the bridged copy of a native token.
    event NewTokenRegistered(address indexed nativeToken, address indexed bridgedToken);
    /// @notice Emitted when the recipient could not receive a release, or the flow limiter refused it. The release is
    /// final: nothing was paid, and nothing can pay it later.
    event ReleaseFailed(address indexed token, address indexed recipient, uint256 value, bytes32 indexed messageId);
    /// @notice Emitted when the `onTokenBridged` call on a recipient fails with the gas that the message gave it. The
    /// tokens stay with the recipient.
    event CallbackFailed(address indexed token, address indexed recipient, bytes32 indexed messageId);
    /// @notice Emitted when the flow limiter detaches itself. The mediator never calls it again.
    event FlowLimiterDetached(address indexed limiter);

    /// @notice The message bridge on this chain.
    IAMB public immutable bridgeContract;
    /// @notice The mediator on the other chain.
    address public immutable mediatorContractOnOtherSide;
    /// @notice The identifier of the other chain, read from the bridge at deployment.
    uint256 public immutable remoteChainId;
    /// @notice The factory that deploys the bridged copies. It is deployed before the mediator and names it.
    TokenFactory public immutable tokenFactory;
    /// @notice The flow limiter that every relay and release must pass. Zero means none. Only the limiter can detach
    /// itself, and nothing can set it.
    IFlowLimiter public flowLimiter;

    /// @notice The bridged copy of a native token of the other chain, or zero when it is not deployed.
    mapping(address nativeToken => address) public bridgedTokenAddress;
    /// @notice The native token of the other chain that a bridged copy stands for, or zero for any other token.
    mapping(address bridgedToken => address) public nativeTokenAddress;

    /// @dev The record of each native token (`MediatorPayloads.NativeRecord`: balance, registered, deploy acknowledged),
    /// in one storage slot each.
    mapping(address token => MediatorPayloads.NativeRecord) private _native;
    /// @dev True while `_pullAndBridge` pulls tokens. A token that calls `onTokenTransfer` during the pull gets true
    /// and no relay, and a release during the pull is refused (the pull measures a balance difference).
    bool private _pulling;

    /// @param terms The terms at deployment. See `MediatorTerms`. The identifier of the other chain is not a term: the
    /// constructor reads it once from `destinationChainId()` of the bridge, so the two cannot disagree.
    /// The factory is a term: it must have code, name this mediator, and carry a home chain name.
    constructor(MediatorTerms memory terms) {
        if (terms.bridge.code.length == 0) revert ZeroValue("bridge");
        if (terms.remoteMediator == address(0)) revert ZeroValue("remoteMediator");
        if (terms.tokenFactory.code.length == 0) revert ZeroValue("tokenFactory");
        TokenFactory factory = TokenFactory(terms.tokenFactory);
        if (factory.mediator() != address(this)) revert FactoryOfAnotherMediator(factory.mediator());
        if (bytes(factory.homeChainName()).length == 0) revert ZeroValue("remoteChainName");
        uint256 remoteChainId_ = IAMB(terms.bridge).destinationChainId();
        if (remoteChainId_ == 0) revert ZeroValue("remoteChainId");

        bridgeContract = IAMB(terms.bridge);
        mediatorContractOnOtherSide = terms.remoteMediator;
        remoteChainId = remoteChainId_;
        tokenFactory = factory;
        flowLimiter = IFlowLimiter(terms.flowLimiter);
    }

    /// @dev The caller must be the message bridge, passing a message from the mediator on the other chain.
    modifier onlyRemoteMediator() {
        _requireRemoteMediator();
        _;
    }

    // ---------------------------------------------------------------------------------------------------------
    // Sending
    // ---------------------------------------------------------------------------------------------------------

    /// @notice Relays tokens of the caller to `receiver` on the other chain. The caller approves the mediator first.
    /// A release that `receiver` cannot take is final: see `ReleaseFailed`.
    function relayTokens(address token, address receiver, uint256 value) external nonReentrant {
        _pullAndBridge(MediatorPayloads.Relay(token, receiver, "", false, 0), value);
    }

    /// @notice Relays tokens of the caller to the caller on the other chain.
    function relayTokens(address token, uint256 value) external nonReentrant {
        _pullAndBridge(MediatorPayloads.Relay(token, msg.sender, "", false, 0), value);
    }

    /// @notice Relays tokens to `receiver` and calls `onTokenBridged(token, value, data)` on it with exactly
    /// `callbackGas`, even when `data` is empty, as OmniBridge calls. New: the gas of the callback is the sender's, and
    /// there is no default.
    /// @dev On the other chain, a delivery that cannot give the callback `callbackGas` (63/64 rule included) reverts and
    /// can run again with more gas. A callback that fails with that gas emits `CallbackFailed`, and the tokens stay
    /// with `receiver`. A `callbackGas` of zero reverts with `ZeroCallbackGas`.
    /// @param callbackGas The gas that `onTokenBridged` gets on the other chain.
    function relayTokensAndCall(
        address token,
        address receiver,
        uint256 value,
        bytes calldata data,
        uint256 callbackGas
    ) external nonReentrant {
        _pullAndBridge(MediatorPayloads.Relay(token, receiver, data, true, callbackGas), value);
    }

    /// @notice The transfer callback of a token with `transferAndCall`. The token has moved `value` to the mediator
    /// already. `data` shorter than 20 bytes means the receiver is `from`, with no callback. `data` of exactly 20 bytes
    /// is the receiver on the other chain, with no callback. Longer `data` is the receiver, then one 32 byte word with
    /// the gas of the callback, then the bytes passed to `onTokenBridged` (they may be empty). `data` between 21 and 51
    /// bytes reverts with `MalformedTransferData`.
    /// @dev A token that calls this function while `relayTokens` pulls from a sender gets true and no relay.
    /// The call is refused when the balance of the mediator does not show the transfer, so a token cannot report
    /// tokens that it did not move.
    /// @return Always true.
    function onTokenTransfer(address from, uint256 value, bytes memory data) external returns (bool) {
        if (_pulling) return true;
        _acceptTransfer(msg.sender, from, value, data);
        return true;
    }

    // ---------------------------------------------------------------------------------------------------------
    // Receiving
    // ---------------------------------------------------------------------------------------------------------

    /// @notice Releases a native token of this chain.
    function handleNativeTokens(address token, address recipient, uint256 value) external onlyRemoteMediator {
        _handleNative(token, Delivery(recipient, value, "", CallMode.Plain, 0));
    }

    /// @notice Releases a native token and calls the recipient with `callbackGas`.
    function handleNativeTokensAndCall(
        address token,
        address recipient,
        uint256 value,
        bytes memory data,
        uint256 callbackGas
    ) external onlyRemoteMediator {
        _handleNative(token, Delivery(recipient, value, data, CallMode.WithCall, callbackGas));
    }

    /// @notice Mints the bridged copy of a native token of the other chain. The copy must exist.
    function handleBridgedTokens(address token, address recipient, uint256 value) external onlyRemoteMediator {
        _handleBridged(token, Delivery(recipient, value, "", CallMode.Plain, 0));
    }

    /// @notice Mints the bridged copy and calls the recipient with `callbackGas`.
    function handleBridgedTokensAndCall(
        address token,
        address recipient,
        uint256 value,
        bytes memory data,
        uint256 callbackGas
    ) external onlyRemoteMediator {
        _handleBridged(token, Delivery(recipient, value, data, CallMode.WithCall, callbackGas));
    }

    /// @notice Deploys the bridged copy when it does not exist, then mints it. The first message for a token. It needs
    /// no gas number: the executor brings the gas of the deployment.
    function deployAndHandleBridgedTokens(
        address token,
        string calldata name,
        string calldata symbol,
        uint8 decimals,
        address recipient,
        uint256 value
    ) external onlyRemoteMediator {
        address copy = _copyOrDeploy(token, name, symbol, decimals);
        _receive(Side.Bridged, copy, Delivery(recipient, value, "", CallMode.Plain, 0));
    }

    /// @notice Deploys the bridged copy when it does not exist, mints it and calls the recipient with `callbackGas`.
    function deployAndHandleBridgedTokensAndCall(
        address token,
        string calldata name,
        string calldata symbol,
        uint8 decimals,
        address recipient,
        uint256 value,
        bytes calldata data,
        uint256 callbackGas
    ) external onlyRemoteMediator {
        address copy = _copyOrDeploy(token, name, symbol, decimals);
        _receive(Side.Bridged, copy, Delivery(recipient, value, data, CallMode.WithCall, callbackGas));
    }

    // ---------------------------------------------------------------------------------------------------------
    // The flow limiter
    // ---------------------------------------------------------------------------------------------------------

    /// @notice Detaches the flow limiter for good. Only the limiter itself may call it, so its own rules decide when.
    /// Nothing can attach a limiter again.
    function detachFlowLimiter() external {
        IFlowLimiter limiter = flowLimiter;
        if (msg.sender != address(limiter)) revert NotFlowLimiter(msg.sender);
        flowLimiter = IFlowLimiter(address(0));
        emit FlowLimiterDetached(address(limiter));
    }

    // ---------------------------------------------------------------------------------------------------------
    // Views
    // ---------------------------------------------------------------------------------------------------------

    /// @notice The amount of a native token that the mediator owes to the other chain. It is not `balanceOf`.
    function mediatorBalance(address token) external view returns (uint256) {
        return _native[token].balance;
    }

    /// @notice Whether the token was relayed as a native token, or is a bridged copy.
    function isTokenRegistered(address token) public view returns (bool) {
        return _native[token].registered || nativeTokenAddress[token] != address(0);
    }

    /// @notice Whether the token is native to this chain and was relayed at least once.
    function isRegisteredAsNativeToken(address token) external view returns (bool) {
        return _native[token].registered;
    }

    /// @notice Whether the other chain proved that the bridged copy of a native token exists. From then on the
    /// mediator sends the short form message.
    function isBridgedTokenDeployAcknowledged(address token) external view returns (bool) {
        return _native[token].deployAcknowledged;
    }

    /// @notice The interface version of OmniBridge that this interface follows.
    function getBridgeInterfacesVersion() external pure returns (uint64 major, uint64 minor, uint64 patch) {
        return (3, 3, 0);
    }

    /// @notice The bridge mode of the OmniBridge multi-token mediator: `bytes4(keccak256("multi-erc-to-erc-amb"))`.
    function getBridgeMode() external pure returns (bytes4) {
        return 0xb1516c26;
    }

    // ---------------------------------------------------------------------------------------------------------
    // Sending, internal
    // ---------------------------------------------------------------------------------------------------------

    /// @dev Pulls the tokens, measures what arrived, and bridges that amount. The measure makes a fee on transfer
    /// token bridge what the mediator received.
    function _pullAndBridge(MediatorPayloads.Relay memory relay, uint256 value) private {
        IERC20 token = IERC20(relay.token);
        uint256 balanceBefore = token.balanceOf(address(this));
        _pulling = true;
        token.safeTransferFrom(msg.sender, address(this), value);
        _pulling = false;
        uint256 received = token.balanceOf(address(this)) - balanceBefore;
        if (received > value) revert ReceivedMoreThanSent(received, value);
        _bridge(relay, msg.sender, received);
    }

    /// @dev The ERC-677 entry: the tokens are here already. It requires that the balance shows them.
    function _acceptTransfer(address token, address from, uint256 value, bytes memory data) private nonReentrant {
        uint256 accounted = _native[token].balance;
        uint256 balance = IERC20(token).balanceOf(address(this));
        if (balance < accounted + value) {
            revert UnbackedTransfer(token, value, balance > accounted ? balance - accounted : 0);
        }
        _bridge(MediatorPayloads.readTransferData(token, from, data), from, value);
    }

    /// @dev Asks the limiter, locks or burns, and sends the message (`MediatorPayloads.send`, in the storage of this
    /// mediator). The message asks the bridge for no gas.
    function _bridge(MediatorPayloads.Relay memory relay, address from, uint256 value) private {
        MediatorPayloads.send(
            _native, nativeTokenAddress, bridgeContract, mediatorContractOnOtherSide, flowLimiter, relay, from, value
        );
    }

    // ---------------------------------------------------------------------------------------------------------
    // Receiving, internal
    // ---------------------------------------------------------------------------------------------------------

    /// @dev The call must come from the message bridge, for a message that the mediator on the other chain sent from
    /// the other chain. OmniBridge checks the first two. The third is new: it keeps a message from another chain that
    /// the same bridge serves from reaching the handlers.
    function _requireRemoteMediator() private view {
        IAMB bridge = bridgeContract;
        if (msg.sender != address(bridge)) revert NotBridge(msg.sender);
        address sender = bridge.messageSender();
        if (sender != mediatorContractOnOtherSide) revert WrongRemoteMediator(mediatorContractOnOtherSide, sender);
        bytes32 sourceChain = bridge.messageSourceChainId();
        if (sourceChain != bytes32(remoteChainId)) revert WrongSourceChain(bytes32(remoteChainId), sourceChain);
    }

    function _handleNative(address token, Delivery memory delivery) private {
        MediatorPayloads.NativeRecord memory record = _native[token];
        if (!record.deployAcknowledged) {
            record.deployAcknowledged = true;
            _native[token] = record;
        }
        _receive(Side.Native, token, delivery);
    }

    function _handleBridged(address nativeToken, Delivery memory delivery) private {
        address copy = bridgedTokenAddress[nativeToken];
        if (copy == address(0)) revert UnknownBridgedToken(nativeToken);
        _receive(Side.Bridged, copy, delivery);
    }

    /// @dev The bridged copy of `nativeToken`. It deploys the copy when it does not exist
    /// (`MediatorPayloads.copyOrDeploy`). A copy that exists keeps its name, so a later message with other metadata
    /// changes nothing.
    function _copyOrDeploy(address nativeToken, string calldata name, string calldata symbol, uint8 decimals)
        private
        returns (address)
    {
        return MediatorPayloads.copyOrDeploy(
            bridgedTokenAddress, nativeTokenAddress, tokenFactory, remoteChainId, nativeToken, name, symbol, decimals
        );
    }

    /// @dev Pays a delivery and calls the account that received the tokens, when the message asks for a call.
    function _receive(Side side, address token, Delivery memory delivery) private {
        if (_pulling) revert HandlerDuringTransfer();
        bytes32 messageId = bridgeContract.messageId();
        if (side == Side.Native) {
            uint256 held = _native[token].balance;
            if (held < delivery.value) revert InsufficientMediatorBalance(token, held, delivery.value);
            // The record falls by every release, paid or failed: the other chain burned the copies already.
            _native[token].balance = uint240(held - delivery.value);
        }
        if (!_pay(side, token, delivery, messageId)) return;
        emit TokensBridged(token, delivery.recipient, delivery.value, messageId);
        if (delivery.mode == CallMode.WithCall) _callback(delivery.recipient, token, delivery, messageId);
    }

    /// @dev Tries the recipient once. When the recipient cannot take the release, or the flow limiter refuses it, it
    /// emits `ReleaseFailed` and stops. It never reverts on a refusal, so a refusal cannot hold the message back. It
    /// reverts on a lack of gas, so an executor cannot turn a lack of gas into a refusal. The mediator pays no account
    /// but the recipient.
    /// @return paid Whether the recipient received the tokens.
    function _pay(Side side, address token, Delivery memory delivery, bytes32 messageId) private returns (bool paid) {
        bool allowed = _limiterAllows(token, delivery.recipient, delivery.value, messageId);
        if (allowed && _tryRelease(side, token, delivery.recipient, delivery.value)) return true;
        emit ReleaseFailed(token, delivery.recipient, delivery.value, messageId);
        return false;
    }

    /// @dev Asks the flow limiter about a release. A revert answers false. A failure that used up the gas reverts the
    /// delivery with `ReleaseOutOfGas`.
    function _limiterAllows(address token, address recipient, uint256 value, bytes32 messageId) private returns (bool) {
        IFlowLimiter limiter = flowLimiter;
        if (address(limiter) == address(0)) return true;
        uint256 gasBefore = gasleft();
        try limiter.checkWithdrawal(token, recipient, value, messageId) {
            return true;
        } catch {
            _revertIfOutOfGas(token, gasBefore, 0);
            return false;
        }
    }

    /// @dev Moves a release to `to`. A bridged copy is minted. A native token is transferred, within the reserve. The
    /// record of a native token already fell in `_receive`.
    /// @return Whether `to` received the tokens.
    function _tryRelease(Side side, address token, address to, uint256 value) private returns (bool) {
        if (side == Side.Native) return _transferWithinReserve(IERC20(token), to, value);
        uint256 gasBefore = gasleft();
        try IBurnableMintableERC677Token(token).mint(to, value) returns (bool minted) {
            return minted;
        } catch {
            _revertIfOutOfGas(token, gasBefore, 0);
            return false;
        }
    }

    /// @dev A transfer that cannot take the gas that the handler needs afterwards. The call gets the gas that is left,
    /// less `TRANSFER_GAS_RESERVE`, and fails when the token needs more. It reads the answer as `SafeERC20` does: the
    /// token must return true, or return nothing and have code. It reads 32 bytes of the answer at most, so a token
    /// cannot spend the reserve on a large answer. A gas left that is not above the reserve, and a failed call that
    /// used up its gas, revert the delivery with `ReleaseOutOfGas`.
    function _transferWithinReserve(IERC20 token, address to, uint256 value) private returns (bool success) {
        uint256 available = gasleft();
        if (available <= TRANSFER_GAS_RESERVE) revert ReleaseOutOfGas(address(token));
        uint256 gasCap = available - TRANSFER_GAS_RESERVE;
        bytes4 selector = IERC20.transfer.selector;
        assembly ("memory-safe") {
            let freePointer := mload(0x40)
            mstore(0x00, selector)
            mstore(0x04, and(to, shr(96, not(0))))
            mstore(0x24, value)
            success := call(gasCap, token, 0, 0x00, 0x44, 0x00, 0x20)
            if iszero(and(success, eq(mload(0x00), 1))) {
                success := and(success, and(iszero(returndatasize()), gt(extcodesize(token), 0)))
            }
            mstore(0x40, freePointer)
        }
        if (!success) _revertIfOutOfGas(address(token), available, TRANSFER_GAS_RESERVE);
    }

    /// @dev Tells a lack of gas from a refusal, after a call that failed. A call that runs out of gas leaves the caller
    /// one 64th of the gas before the call, or the part that the caller held back (`reserve`), whichever is larger.
    /// A call that refused with gas to spare leaves more. So a gas left at or below `gasBefore / 64 + reserve` reverts
    /// with `ReleaseOutOfGas`: the callee used up what it got, and more gas may change the outcome.
    function _revertIfOutOfGas(address token, uint256 gasBefore, uint256 reserve) private view {
        if (gasleft() <= gasBefore / 64 + reserve) revert ReleaseOutOfGas(token);
    }

    /// @dev Calls `onTokenBridged` on the account that received the tokens, as OmniBridge does: only a contract is
    /// called. The call gets exactly the gas of the message (`ExactGasCall`): not enough gas reverts the delivery, and a
    /// callback that fails with its gas emits `CallbackFailed` and changes nothing else.
    function _callback(address receiver, address token, Delivery memory delivery, bytes32 messageId) private {
        if (receiver.code.length == 0) return;
        bytes memory callData =
            abi.encodeWithSelector(IERC20Receiver.onTokenBridged.selector, token, delivery.value, delivery.data);
        if (!ExactGasCall.callWithExactGas(receiver, delivery.callbackGas, CALLBACK_GAS_RESERVE, callData, 0)) {
            emit CallbackFailed(token, receiver, messageId);
        }
    }
}
        

lib/openzeppelin-contracts/contracts/interfaces/IERC20Metadata.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC20Metadata.sol)

pragma solidity >=0.6.2;

import {IERC20Metadata} from "../token/ERC20/extensions/IERC20Metadata.sol";
          

lib/openzeppelin-contracts/contracts/utils/StorageSlot.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.

pragma solidity ^0.8.20;

/**
 * @dev Library for reading and writing primitive types to specific storage slots.
 *
 * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
 * This library helps with reading and writing to such slots without the need for inline assembly.
 *
 * The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
 *
 * Example usage to set ERC-1967 implementation slot:
 * ```solidity
 * contract ERC1967 {
 *     // Define the slot. Alternatively, use the SlotDerivation library to derive the slot.
 *     bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
 *
 *     function _getImplementation() internal view returns (address) {
 *         return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
 *     }
 *
 *     function _setImplementation(address newImplementation) internal {
 *         require(newImplementation.code.length > 0);
 *         StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
 *     }
 * }
 * ```
 *
 * TIP: Consider using this library along with {SlotDerivation}.
 */
library StorageSlot {
    struct AddressSlot {
        address value;
    }

    struct BooleanSlot {
        bool value;
    }

    struct Bytes32Slot {
        bytes32 value;
    }

    struct Uint256Slot {
        uint256 value;
    }

    struct Int256Slot {
        int256 value;
    }

    struct StringSlot {
        string value;
    }

    struct BytesSlot {
        bytes value;
    }

    /**
     * @dev Returns an `AddressSlot` with member `value` located at `slot`.
     */
    function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
        assembly ("memory-safe") {
            r.slot := slot
        }
    }

    /**
     * @dev Returns a `BooleanSlot` with member `value` located at `slot`.
     */
    function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
        assembly ("memory-safe") {
            r.slot := slot
        }
    }

    /**
     * @dev Returns a `Bytes32Slot` with member `value` located at `slot`.
     */
    function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
        assembly ("memory-safe") {
            r.slot := slot
        }
    }

    /**
     * @dev Returns a `Uint256Slot` with member `value` located at `slot`.
     */
    function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
        assembly ("memory-safe") {
            r.slot := slot
        }
    }

    /**
     * @dev Returns a `Int256Slot` with member `value` located at `slot`.
     */
    function getInt256Slot(bytes32 slot) internal pure returns (Int256Slot storage r) {
        assembly ("memory-safe") {
            r.slot := slot
        }
    }

    /**
     * @dev Returns a `StringSlot` with member `value` located at `slot`.
     */
    function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
        assembly ("memory-safe") {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `StringSlot` representation of the string storage pointer `store`.
     */
    function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
        assembly ("memory-safe") {
            r.slot := store.slot
        }
    }

    /**
     * @dev Returns a `BytesSlot` with member `value` located at `slot`.
     */
    function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
        assembly ("memory-safe") {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
     */
    function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
        assembly ("memory-safe") {
            r.slot := store.slot
        }
    }
}
          

lib/openzeppelin-contracts/contracts/utils/Context.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)

pragma solidity ^0.8.20;

/**
 * @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 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) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}
          

src/hardened/IAMB.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

/// @title IAMB
/// @notice The Arbitrary Message Bridge interface, as OmniBridge defines it (`omni/omnibridge`,
/// `contracts/interfaces/IAMB.sol`). `MessageBridge` implements it and adds `executeMessage`. The mediator codes
/// against this interface only and never calls `executeMessage`.
/// @dev `UserRequestForSignature` and `RelayedMessage` stay in the interface for compatibility. A bridge without
/// validators never emits them.
interface IAMB {
    /// @notice Emitted by every send. `encodedData` is the Arbitrary Message Bridge message encoding.
    event UserRequestForAffirmation(bytes32 indexed messageId, bytes encodedData);
    /// @notice Never emitted by a bridge without validators.
    event UserRequestForSignature(bytes32 indexed messageId, bytes encodedData);
    /// @notice Emitted on every execution of a message. `MessageBridge` emits it only for a delivery that succeeded: a
    /// delivery whose call fails reverts. So `status` is always true there.
    event AffirmationCompleted(
        address indexed sender, address indexed executor, bytes32 indexed messageId, bool status
    );
    /// @notice Never emitted by a bridge without validators.
    event RelayedMessage(address indexed sender, address indexed executor, bytes32 indexed messageId, bool status);

    /// @notice The sender of the message on the other chain. Set only during the call to the target.
    function messageSender() external view returns (address);

    /// @notice The ceiling of the gas that a message may ask for. `MessageBridge` reads no gas from a message and answers
    /// the width of the gas field.
    function maxGasPerTx() external view returns (uint256);

    /// @notice The source transaction hash of the message. Set only during the call to the target.
    function transactionHash() external view returns (bytes32);

    /// @notice The identifier of the message. Set only during the call to the target.
    function messageId() external view returns (bytes32);

    /// @notice The identifier of the chain that sent the message. Set only during the call to the target.
    function messageSourceChainId() external view returns (bytes32);

    /// @notice Whether the call to the target of a message succeeded. On `MessageBridge`: whether the message was
    /// delivered.
    function messageCallStatus(bytes32 _messageId) external view returns (bool);

    /// @notice The hash of the data of a message whose call failed. Always zero on `MessageBridge`, where a failed call
    /// reverts the delivery.
    function failedMessageDataHash(bytes32 _messageId) external view returns (bytes32);

    /// @notice The target of a message whose call failed.
    function failedMessageReceiver(bytes32 _messageId) external view returns (address);

    /// @notice The sender of a message whose call failed.
    function failedMessageSender(bytes32 _messageId) external view returns (address);

    /// @notice Sends a message to `_contract` on the other chain.
    /// @param _contract The target on the other chain.
    /// @param _data The call data.
    /// @param _gas The gas that the call to the target gets. `MessageBridge` ignores it: the target gets all the gas of
    /// the delivery.
    /// @return The message identifier.
    function requireToPassMessage(address _contract, bytes calldata _data, uint256 _gas) external returns (bytes32);

    /// @notice The same as `requireToPassMessage`. This bridge has no separate manual lane.
    function requireToConfirmMessage(address _contract, bytes calldata _data, uint256 _gas) external returns (bytes32);

    /// @notice The identifier of this chain.
    function sourceChainId() external view returns (uint256);

    /// @notice The identifier of the other chain.
    function destinationChainId() external view returns (uint256);
}
          

lib/openzeppelin-contracts/contracts/utils/ReentrancyGuard.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.5.0) (utils/ReentrancyGuard.sol)

pragma solidity ^0.8.20;

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

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If EIP-1153 (transient storage) is available on the chain you're deploying at,
 * consider using {ReentrancyGuardTransient} instead.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 *
 * IMPORTANT: Deprecated. This storage-based reentrancy guard will be removed and replaced
 * by the {ReentrancyGuardTransient} variant in v6.0.
 *
 * @custom:stateless
 */
abstract contract ReentrancyGuard {
    using StorageSlot for bytes32;

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.ReentrancyGuard")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant REENTRANCY_GUARD_STORAGE =
        0x9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00;

    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant NOT_ENTERED = 1;
    uint256 private constant ENTERED = 2;

    /**
     * @dev Unauthorized reentrant call.
     */
    error ReentrancyGuardReentrantCall();

    constructor() {
        _reentrancyGuardStorageSlot().getUint256Slot().value = NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        _nonReentrantBefore();
        _;
        _nonReentrantAfter();
    }

    /**
     * @dev A `view` only version of {nonReentrant}. Use to block view functions
     * from being called, preventing reading from inconsistent contract state.
     *
     * CAUTION: This is a "view" modifier and does not change the reentrancy
     * status. Use it only on view functions. For payable or non-payable functions,
     * use the standard {nonReentrant} modifier instead.
     */
    modifier nonReentrantView() {
        _nonReentrantBeforeView();
        _;
    }

    function _nonReentrantBeforeView() private view {
        if (_reentrancyGuardEntered()) {
            revert ReentrancyGuardReentrantCall();
        }
    }

    function _nonReentrantBefore() private {
        // On the first call to nonReentrant, _status will be NOT_ENTERED
        _nonReentrantBeforeView();

        // Any calls to nonReentrant after this point will fail
        _reentrancyGuardStorageSlot().getUint256Slot().value = ENTERED;
    }

    function _nonReentrantAfter() private {
        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _reentrancyGuardStorageSlot().getUint256Slot().value = NOT_ENTERED;
    }

    /**
     * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
     * `nonReentrant` function in the call stack.
     */
    function _reentrancyGuardEntered() internal view returns (bool) {
        return _reentrancyGuardStorageSlot().getUint256Slot().value == ENTERED;
    }

    function _reentrancyGuardStorageSlot() internal pure virtual returns (bytes32) {
        return REENTRANCY_GUARD_STORAGE;
    }
}
          

src/hardened/mediator/IERC20Receiver.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

/// @title IERC20Receiver
/// @notice The callback that a `...AndCall` delivery makes on the recipient (OmniBridge `IERC20Receiver`).
interface IERC20Receiver {
    /// @param token The token that the recipient received on this chain.
    /// @param value The amount that the recipient received.
    /// @param data The data that the sender passed through the bridge.
    function onTokenBridged(address token, uint256 value, bytes calldata data) external;
}
          

src/hardened/mediator/BridgedToken.sol

// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {IERC20Permit} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Permit.sol";
import {IERC677} from "./IERC677.sol";
import {IBurnableMintableERC677Token} from "./IBurnableMintableERC677Token.sol";
import {ITokenParameters} from "./ITokenParameters.sol";

/// @title BridgedToken
/// @notice The copy of a native token on the chain that the native token does not live on. It is an ERC-20 with the
/// transfer callback of ERC-677 (`transferAndCall`), the allowance helpers of OmniBridge, and `permit`.
/// @dev The mediator is the only account that can mint and burn. The token has no owner and no upgrade path. The
/// constructor takes no arguments: it reads name, symbol, decimals and mediator from the factory that deploys it
/// (`ITokenParameters`), so the address of a copy depends on the home chain and the native token only. The permit
/// domain uses the token name and the version `"1"`, as OmniBridge does. The permit code is written here and not taken
/// from the OpenZeppelin extension, because that extension imports a library that needs the `mcopy` instruction, which
/// the Shanghai target of this repository does not have.
contract BridgedToken is ERC20, IERC20Permit, IBurnableMintableERC677Token {
    /// @notice Only the mediator may call the function.
    error NotMediator(address caller);
    /// @notice The receiver of `transferAndCall` is a contract and its `onTokenTransfer` call failed.
    error TransferCallFailed(address receiver);
    /// @notice The permit deadline has passed.
    error PermitExpired(uint256 deadline);
    /// @notice The permit signature does not come from the owner.
    error PermitSignerInvalid(address signer, address owner);

    bytes32 private constant DOMAIN_TYPEHASH =
        keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");
    bytes32 private constant PERMIT_TYPEHASH =
        keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
    bytes32 private constant VERSION_HASH = keccak256("1");
    /// @dev The upper bound of `s` that rejects the malleable twin of a signature.
    uint256 private constant HALF_CURVE_ORDER = 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0;

    mapping(address owner => uint256) public nonces;

    /// @notice The mediator, as OmniBridge names the bridge contract of a bridged token.
    address public immutable bridgeContract;
    uint8 private immutable _tokenDecimals;

    constructor() ERC20(_nameFromFactory(), _symbolFromFactory()) {
        (,, uint8 tokenDecimals, address mediator) = ITokenParameters(msg.sender).parameters();
        _tokenDecimals = tokenDecimals;
        bridgeContract = mediator;
    }

    modifier onlyMediator() {
        if (msg.sender != bridgeContract) revert NotMediator(msg.sender);
        _;
    }

    /// @inheritdoc ERC20
    function decimals() public view override returns (uint8) {
        return _tokenDecimals;
    }

    /// @inheritdoc IERC20Permit
    function DOMAIN_SEPARATOR() public view returns (bytes32) {
        return
            keccak256(abi.encode(DOMAIN_TYPEHASH, keccak256(bytes(name())), VERSION_HASH, block.chainid, address(this)));
    }

    /// @inheritdoc IERC20Permit
    function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s)
        external
    {
        if (block.timestamp > deadline) revert PermitExpired(deadline);
        bytes32 structHash = keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, value, nonces[owner]++, deadline));
        bytes32 digest = keccak256(abi.encodePacked("\x19\x01", DOMAIN_SEPARATOR(), structHash));
        address signer = uint256(s) > HALF_CURVE_ORDER ? address(0) : ecrecover(digest, v, r, s);
        if (signer == address(0) || signer != owner) revert PermitSignerInvalid(signer, owner);
        _approve(owner, spender, value);
    }

    /// @notice Mints tokens. Only the mediator may call it.
    function mint(address to, uint256 amount) external onlyMediator returns (bool) {
        _mint(to, amount);
        return true;
    }

    /// @notice Burns tokens of the caller. Only the mediator may call it, and it burns its own balance.
    function burn(uint256 value) external onlyMediator {
        _burn(msg.sender, value);
    }

    /// @inheritdoc IERC677
    /// @dev Moves the tokens, emits the data event, and then calls `onTokenTransfer(sender, value, data)` on a
    /// receiver that has code. A receiver whose call fails undoes the transfer.
    function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool) {
        _transfer(msg.sender, to, value);
        emit Transfer(msg.sender, to, value, data);
        if (to.code.length == 0) return true;
        (bool ok,) = to.call(abi.encodeWithSignature("onTokenTransfer(address,uint256,bytes)", msg.sender, value, data));
        if (!ok) revert TransferCallFailed(to);
        return true;
    }

    /// @inheritdoc IERC677
    function increaseAllowance(address spender, uint256 addedValue) external returns (bool) {
        _approve(msg.sender, spender, allowance(msg.sender, spender) + addedValue);
        return true;
    }

    /// @inheritdoc IERC677
    function decreaseAllowance(address spender, uint256 subtractedValue) external returns (bool) {
        uint256 current = allowance(msg.sender, spender);
        if (subtractedValue > current) revert ERC20InsufficientAllowance(spender, current, subtractedValue);
        _approve(msg.sender, spender, current - subtractedValue);
        return true;
    }

    function _nameFromFactory() private view returns (string memory name) {
        (name,,,) = ITokenParameters(msg.sender).parameters();
    }

    function _symbolFromFactory() private view returns (string memory symbol) {
        (, symbol,,) = ITokenParameters(msg.sender).parameters();
    }
}
          

src/hardened/mediator/IBurnableMintableERC677Token.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

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

/// @title IBurnableMintableERC677Token
/// @notice The bridged token interface of OmniBridge without `claimTokens`, which is an owner function.
interface IBurnableMintableERC677Token is IERC677 {
    /// @notice Mints tokens. Only the mediator may call it.
    function mint(address to, uint256 amount) external returns (bool);

    /// @notice Burns tokens of the caller. Only the mediator may call it.
    function burn(uint256 value) external;
}
          

src/hardened/mediator/ITokenParameters.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

/// @title ITokenParameters
/// @notice The factory exposes the parameters of the token that it is deploying. The token reads them in its
/// constructor. So the creation code of a bridged token has no arguments, and its address depends on the factory and
/// the salt only.
interface ITokenParameters {
    /// @return name The token name.
    /// @return symbol The token symbol.
    /// @return decimals The token decimals.
    /// @return mediator The mediator that may mint and burn the token.
    function parameters()
        external
        view
        returns (string memory name, string memory symbol, uint8 decimals, address mediator);
}
          

src/hardened/mediator/TokenReader.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

/// @title TokenReader
/// @notice Reads the name, the symbol and the decimals of a token that may not follow the standard. It tries the lower
/// case selector, then the upper case selector, and it reads a string or a `bytes32`. This is the reader of
/// OmniBridge (`contracts/libraries/TokenReader.sol`), ported to the current compiler.
library TokenReader {
    /// @notice A token returns a value from `decimals()` that does not fit in a byte.
    /// @param token The token.
    /// @param value The value that the token returned.
    error DecimalsOutOfRange(address token, uint256 value);

    bytes4 private constant NAME = 0x06fdde03;
    bytes4 private constant NAME_UPPER = 0xa3f4df7e;
    bytes4 private constant SYMBOL = 0x95d89b41;
    bytes4 private constant SYMBOL_UPPER = 0xf76f8d78;
    bytes4 private constant DECIMALS = 0x313ce567;
    bytes4 private constant DECIMALS_UPPER = 0x2e0f2625;

    function readName(address token) internal view returns (string memory) {
        return _readString(token, NAME, NAME_UPPER);
    }

    function readSymbol(address token) internal view returns (string memory) {
        return _readString(token, SYMBOL, SYMBOL_UPPER);
    }

    /// @dev A token with no readable decimals has zero decimals: the call fails, or it returns less than one word.
    /// Amounts are integers everywhere, so the decimals are metadata for the copy only, and a missing value costs a
    /// holder nothing but the display. A value above 255 is another case: no byte can state it, and a silent zero
    /// would give the copy the wrong metadata for good, so it reverts.
    /// @return The decimals, or zero when the token has no readable decimals.
    function readDecimals(address token) internal view returns (uint8) {
        (bool ok, bytes memory data) = token.staticcall(abi.encodeWithSelector(DECIMALS));
        if (!ok) (ok, data) = token.staticcall(abi.encodeWithSelector(DECIMALS_UPPER));
        if (!ok || data.length < 32) return 0;
        uint256 value = abi.decode(data, (uint256));
        if (value > type(uint8).max) revert DecimalsOutOfRange(token, value);
        return uint8(value);
    }

    function _readString(address token, bytes4 selector, bytes4 upperSelector) private view returns (string memory) {
        (bool ok, bytes memory data) = token.staticcall(abi.encodeWithSelector(selector));
        if (!ok) (ok, data) = token.staticcall(abi.encodeWithSelector(upperSelector));
        if (!ok) return "";
        return _toString(data);
    }

    function _toString(bytes memory returned) private pure returns (string memory) {
        if (returned.length > 32) return abi.decode(returned, (string));
        if (returned.length < 32) return "";
        bytes32 packed = abi.decode(returned, (bytes32));
        uint256 length;
        while (length < 32 && packed[length] != 0) length++;
        bytes memory result = new bytes(length);
        for (uint256 i = 0; i < length; i++) {
            result[i] = packed[i];
        }
        return string(result);
    }
}
          

lib/openzeppelin-contracts/contracts/interfaces/draft-IERC6093.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.5.0) (interfaces/draft-IERC6093.sol)

pragma solidity >=0.8.4;

/**
 * @dev Standard ERC-20 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-20 tokens.
 */
interface IERC20Errors {
    /**
     * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     * @param balance Current balance for the interacting account.
     * @param needed Minimum amount required to perform a transfer.
     */
    error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);

    /**
     * @dev Indicates a failure with the token `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     */
    error ERC20InvalidSender(address sender);

    /**
     * @dev Indicates a failure with the token `receiver`. Used in transfers.
     * @param receiver Address to which tokens are being transferred.
     */
    error ERC20InvalidReceiver(address receiver);

    /**
     * @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.
     * @param spender Address that may be allowed to operate on tokens without being their owner.
     * @param allowance Amount of tokens a `spender` is allowed to operate with.
     * @param needed Minimum amount required to perform a transfer.
     */
    error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);

    /**
     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
     * @param approver Address initiating an approval operation.
     */
    error ERC20InvalidApprover(address approver);

    /**
     * @dev Indicates a failure with the `spender` to be approved. Used in approvals.
     * @param spender Address that may be allowed to operate on tokens without being their owner.
     */
    error ERC20InvalidSpender(address spender);
}

/**
 * @dev Standard ERC-721 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-721 tokens.
 */
interface IERC721Errors {
    /**
     * @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in ERC-721.
     * Used in balance queries.
     * @param owner Address of the current owner of a token.
     */
    error ERC721InvalidOwner(address owner);

    /**
     * @dev Indicates a `tokenId` whose `owner` is the zero address.
     * @param tokenId Identifier number of a token.
     */
    error ERC721NonexistentToken(uint256 tokenId);

    /**
     * @dev Indicates an error related to the ownership over a particular token. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     * @param tokenId Identifier number of a token.
     * @param owner Address of the current owner of a token.
     */
    error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);

    /**
     * @dev Indicates a failure with the token `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     */
    error ERC721InvalidSender(address sender);

    /**
     * @dev Indicates a failure with the token `receiver`. Used in transfers.
     * @param receiver Address to which tokens are being transferred.
     */
    error ERC721InvalidReceiver(address receiver);

    /**
     * @dev Indicates a failure with the `operator`’s approval. Used in transfers.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     * @param tokenId Identifier number of a token.
     */
    error ERC721InsufficientApproval(address operator, uint256 tokenId);

    /**
     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
     * @param approver Address initiating an approval operation.
     */
    error ERC721InvalidApprover(address approver);

    /**
     * @dev Indicates a failure with the `operator` to be approved. Used in approvals.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     */
    error ERC721InvalidOperator(address operator);
}

/**
 * @dev Standard ERC-1155 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-1155 tokens.
 */
interface IERC1155Errors {
    /**
     * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     * @param balance Current balance for the interacting account.
     * @param needed Minimum amount required to perform a transfer.
     * @param tokenId Identifier number of a token.
     */
    error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);

    /**
     * @dev Indicates a failure with the token `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     */
    error ERC1155InvalidSender(address sender);

    /**
     * @dev Indicates a failure with the token `receiver`. Used in transfers.
     * @param receiver Address to which tokens are being transferred.
     */
    error ERC1155InvalidReceiver(address receiver);

    /**
     * @dev Indicates a failure with the `operator`’s approval. Used in transfers.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     * @param owner Address of the current owner of a token.
     */
    error ERC1155MissingApprovalForAll(address operator, address owner);

    /**
     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
     * @param approver Address initiating an approval operation.
     */
    error ERC1155InvalidApprover(address approver);

    /**
     * @dev Indicates a failure with the `operator` to be approved. Used in approvals.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     */
    error ERC1155InvalidOperator(address operator);

    /**
     * @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.
     * Used in batch transfers.
     * @param idsLength Length of the array of token identifiers
     * @param valuesLength Length of the array of token amounts
     */
    error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);
}
          

src/hardened/mediator/ExactGasCall.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

/// @title ExactGasCall
/// @notice A call that gets exactly the gas that a sender stated, or none at all. The rule is the same wherever a
/// sender states a gas number for a call (the callback of the mediator, the follow-up call of a router): not enough gas
/// reverts the whole delivery, so it can run again with more gas; a callee that fails with the gas it was promised is
/// a recorded failure, and the delivery completes.
/// @dev Two checks, one on each side of the call.
/// (a) Before the call. The EVM forwards at most 63/64 of the gas left, so the call can receive `gasAmount` only when
/// `gasleft() >= gasAmount + gasAmount / 63`. The caller adds `reserve`, the gas that it needs after the call. Less
/// gas reverts with `InsufficientGas`.
/// (b) After a failed call. A few operations run between check (a) and the call (the address access, the memory of
/// the arguments), so the callee may still have received a little less than `gasAmount`. When it did, and failed,
/// the gas left is below `gasAmount / 63`: with the full amount forwarded it is at least that much. So a failed call
/// that leaves less than `gasAmount / 63` reverts with `CallOutOfGas`. A failed call that leaves more ran with the
/// gas that it was promised.
/// The call copies no return data, so a callee cannot spend the gas of the caller with a large answer or a large
/// error.
library ExactGasCall {
    /// @notice The gas left cannot give the call its gas under the 63/64 rule, plus the reserve of the caller.
    error InsufficientGas(uint256 available, uint256 required);
    /// @notice The call failed after it received less than its gas. The delivery can run again with more gas.
    error CallOutOfGas(uint256 gasAmount);

    /// @notice Calls `target` with exactly `gasAmount`, no native value, and the bytes of `data` from `start` on.
    /// @param target The callee.
    /// @param gasAmount The gas that the callee gets.
    /// @param reserve The gas that the caller needs after the call. Check (a) adds it.
    /// @param data The memory that holds the call data.
    /// @param start The offset of the call data in `data`. The call data runs to the end of `data`.
    /// @return success Whether the call succeeded.
    function callWithExactGas(address target, uint256 gasAmount, uint256 reserve, bytes memory data, uint256 start)
        internal
        returns (bool success)
    {
        uint256 required = gasAmount + gasAmount / 63 + reserve;
        uint256 available = gasleft();
        if (available < required) revert InsufficientGas(available, required);
        uint256 length = data.length - start;
        assembly ("memory-safe") {
            success := call(gasAmount, target, 0, add(add(data, 32), start), length, 0, 0)
        }
        if (!success && gasleft() < gasAmount / 63) revert CallOutOfGas(gasAmount);
    }
}
          

lib/openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.7.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.20;

import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";
import {IERC20Metadata} from "../../../interfaces/IERC20Metadata.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC-20 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 {
    /**
     * @dev An operation with an ERC-20 token failed.
     */
    error SafeERC20FailedOperation(address token);

    /**
     * @dev Indicates a failed `decreaseAllowance` request.
     */
    error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);

    /**
     * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeTransfer(IERC20 token, address to, uint256 value) internal {
        if (!_safeTransfer(token, to, value, true)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
     * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
     */
    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
        if (!_safeTransferFrom(token, from, to, value, true)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Variant of {safeTransfer} that returns a bool instead of reverting if the operation is not successful.
     */
    function trySafeTransfer(IERC20 token, address to, uint256 value) internal returns (bool) {
        return _safeTransfer(token, to, value, false);
    }

    /**
     * @dev Variant of {safeTransferFrom} that returns a bool instead of reverting if the operation is not successful.
     */
    function trySafeTransferFrom(IERC20 token, address from, address to, uint256 value) internal returns (bool) {
        return _safeTransferFrom(token, from, to, value, false);
    }

    /**
     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     *
     * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
     * smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
     * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
     * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
     */
    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 oldAllowance = token.allowance(address(this), spender);
        forceApprove(token, spender, oldAllowance + value);
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
     * value, non-reverting calls are assumed to be successful.
     *
     * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
     * smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
     * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
     * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
     */
    function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
        unchecked {
            uint256 currentAllowance = token.allowance(address(this), spender);
            if (currentAllowance < requestedDecrease) {
                revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
            }
            forceApprove(token, spender, currentAllowance - requestedDecrease);
        }
    }

    /**
     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
     * to be set to zero before setting it to a non-zero value, such as USDT.
     *
     * NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function
     * only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being
     * set here.
     */
    function forceApprove(IERC20 token, address spender, uint256 value) internal {
        if (!_safeApprove(token, spender, value, false)) {
            if (!_safeApprove(token, spender, 0, true)) revert SafeERC20FailedOperation(address(token));
            if (!_safeApprove(token, spender, value, true)) revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no
     * code. This can be used to implement an {ERC721}-like safe transfer that relies on {ERC1363} checks when
     * targeting contracts.
     *
     * Reverts if the returned value is other than `true`.
     */
    function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
        if (to.code.length == 0) {
            safeTransfer(token, to, value);
        } else if (!token.transferAndCall(to, value, data)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target
     * has no code. This can be used to implement an {ERC721}-like safe transfer that relies on {ERC1363} checks when
     * targeting contracts.
     *
     * Reverts if the returned value is other than `true`.
     */
    function transferFromAndCallRelaxed(
        IERC1363 token,
        address from,
        address to,
        uint256 value,
        bytes memory data
    ) internal {
        if (to.code.length == 0) {
            safeTransferFrom(token, from, to, value);
        } else if (!token.transferFromAndCall(from, to, value, data)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no
     * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
     * targeting contracts.
     *
     * NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.
     * Oppositely, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}
     * once without retrying, and relies on the returned value to be true.
     *
     * Reverts if the returned value is other than `true`.
     */
    function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
        if (to.code.length == 0) {
            forceApprove(token, to, value);
        } else if (!token.approveAndCall(to, value, data)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /// @dev Attempts to fetch the token decimals. A return value of false indicates that the attempt failed in some way.
    function tryGetDecimals(IERC20 token) internal view returns (bool success, uint8 decimals) {
        bytes4 selector = IERC20Metadata.decimals.selector;
        assembly ("memory-safe") {
            mstore(0x00, selector)
            success := staticcall(gas(), token, 0x00, 4, 0x00, 0x20)
            success := and(and(success, gt(returndatasize(), 0x1f)), lt(mload(0x00), 0x100))
            decimals := mul(success, mload(0x00))
        }
    }

    /**
     * @dev Imitates a Solidity `token.transfer(to, value)` call, 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 to The recipient of the tokens
     * @param value The amount of token to transfer
     * @param bubble Behavior switch if the transfer call reverts: bubble the revert reason or return a false boolean.
     */
    function _safeTransfer(IERC20 token, address to, uint256 value, bool bubble) private returns (bool success) {
        bytes4 selector = IERC20.transfer.selector;

        assembly ("memory-safe") {
            let fmp := mload(0x40)
            mstore(0x00, selector)
            mstore(0x04, and(to, shr(96, not(0))))
            mstore(0x24, value)
            success := call(gas(), token, 0, 0x00, 0x44, 0x00, 0x20)
            // if call success and return is true, all is good.
            // otherwise (not success or return is not true), we need to perform further checks
            if iszero(and(success, eq(mload(0x00), 1))) {
                // if the call was a failure and bubble is enabled, bubble the error
                if and(iszero(success), bubble) {
                    returndatacopy(fmp, 0x00, returndatasize())
                    revert(fmp, returndatasize())
                }
                // if the return value is not true, then the call is only successful if:
                // - the token address has code
                // - the returndata is empty
                success := and(success, and(iszero(returndatasize()), gt(extcodesize(token), 0)))
            }
            mstore(0x40, fmp)
        }
    }

    /**
     * @dev Imitates a Solidity `token.transferFrom(from, to, value)` call, 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 from The sender of the tokens
     * @param to The recipient of the tokens
     * @param value The amount of token to transfer
     * @param bubble Behavior switch if the transfer call reverts: bubble the revert reason or return a false boolean.
     */
    function _safeTransferFrom(
        IERC20 token,
        address from,
        address to,
        uint256 value,
        bool bubble
    ) private returns (bool success) {
        bytes4 selector = IERC20.transferFrom.selector;

        assembly ("memory-safe") {
            let fmp := mload(0x40)
            mstore(0x00, selector)
            mstore(0x04, and(from, shr(96, not(0))))
            mstore(0x24, and(to, shr(96, not(0))))
            mstore(0x44, value)
            success := call(gas(), token, 0, 0x00, 0x64, 0x00, 0x20)
            // if call success and return is true, all is good.
            // otherwise (not success or return is not true), we need to perform further checks
            if iszero(and(success, eq(mload(0x00), 1))) {
                // if the call was a failure and bubble is enabled, bubble the error
                if and(iszero(success), bubble) {
                    returndatacopy(fmp, 0x00, returndatasize())
                    revert(fmp, returndatasize())
                }
                // if the return value is not true, then the call is only successful if:
                // - the token address has code
                // - the returndata is empty
                success := and(success, and(iszero(returndatasize()), gt(extcodesize(token), 0)))
            }
            mstore(0x40, fmp)
            mstore(0x60, 0)
        }
    }

    /**
     * @dev Imitates a Solidity `token.approve(spender, value)` call, 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 spender The spender of the tokens
     * @param value The amount of token to approve
     * @param bubble Behavior switch if the approve call reverts: bubble the revert reason or return a false boolean.
     */
    function _safeApprove(IERC20 token, address spender, uint256 value, bool bubble) private returns (bool success) {
        bytes4 selector = IERC20.approve.selector;

        assembly ("memory-safe") {
            let fmp := mload(0x40)
            mstore(0x00, selector)
            mstore(0x04, and(spender, shr(96, not(0))))
            mstore(0x24, value)
            success := call(gas(), token, 0, 0x00, 0x44, 0x00, 0x20)
            // if call success and return is true, all is good.
            // otherwise (not success or return is not true), we need to perform further checks
            if iszero(and(success, eq(mload(0x00), 1))) {
                // if the call was a failure and bubble is enabled, bubble the error
                if and(iszero(success), bubble) {
                    returndatacopy(fmp, 0x00, returndatasize())
                    revert(fmp, returndatasize())
                }
                // if the return value is not true, then the call is only successful if:
                // - the token address has code
                // - the returndata is empty
                success := and(success, and(iszero(returndatasize()), gt(extcodesize(token), 0)))
            }
            mstore(0x40, fmp)
        }
    }
}
          

src/hardened/mediator/ITokenMediator.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

import {IOmnibridge} from "./IOmnibridge.sol";
import {IAMB} from "../IAMB.sol";

/// @title ITokenMediator
/// @notice The functions of `TokenMediator` that the routers call. `relayTokens` is the OmniBridge function.
/// `relayTokensAndCall` takes one more argument than in OmniBridge: the gas of the callback, which the sender states
/// because there is no default.
interface ITokenMediator is IOmnibridge {
    /// @notice Relays tokens of the caller to `receiver` and calls `onTokenBridged` on it on the other chain with exactly
    /// `callbackGas`. Zero reverts.
    /// @param callbackGas The gas of the callback on the other chain. The delivery reverts when it cannot give that
    /// gas, and records `CallbackFailed` when the callback fails with it.
    function relayTokensAndCall(address token, address receiver, uint256 value, bytes calldata data, uint256 callbackGas)
        external;

    function bridgeContract() external view returns (IAMB);
}
          

src/hardened/mediator/IERC677.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

/// @title IERC677
/// @notice A token that calls the receiver after a transfer (`transferAndCall`), with the allowance helpers of
/// OmniBridge (`omni/omnibridge`, `contracts/interfaces/IERC677.sol`).
interface IERC677 is IERC20 {
    /// @notice Emitted by `transferAndCall` in addition to the standard `Transfer`.
    event Transfer(address indexed from, address indexed to, uint256 value, bytes data);

    /// @notice Moves tokens, then calls `onTokenTransfer(msg.sender, value, data)` on `to` when `to` is a contract.
    function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);

    /// @notice Raises the allowance of `spender`.
    function increaseAllowance(address spender, uint256 addedValue) external returns (bool);

    /// @notice Lowers the allowance of `spender`.
    function decreaseAllowance(address spender, uint256 subtractedValue) external returns (bool);
}
          

lib/openzeppelin-contracts/contracts/interfaces/IERC165.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC165.sol)

pragma solidity >=0.4.16;

import {IERC165} from "../utils/introspection/IERC165.sol";
          

src/hardened/IFlowLimiter.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

/// @title IFlowLimiter
/// @notice A rule set that the vault asks before it books a deposit or pays a withdrawal. A limiter that reverts
/// refuses the call, and the whole transaction is undone. A limiter holds no tokens and no approval, so it cannot move
/// funds. It may change its own state, for example to record usage.
interface IFlowLimiter {
    /// @notice Checks a deposit, or reverts. The vault calls it after it measures the received amount.
    /// @param token The local token.
    /// @param depositor The sender of the deposit.
    /// @param amount The amount that the vault bridges.
    function checkDeposit(address token, address depositor, uint256 amount) external;

    /// @notice Checks a withdrawal, or reverts. The vault calls it after every proof check and before it marks the
    /// nonce claimed, so a refused withdrawal stays claimable.
    /// @param token The local token that the vault would pay.
    /// @param recipient The recipient of the payout.
    /// @param amount The amount that the vault would pay.
    /// @param nonce The nonce of the deposit on the other chain.
    function checkWithdrawal(address token, address recipient, uint256 amount, bytes32 nonce) external;
}
          

src/hardened/mediator/IOmnibridge.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

/// @title IOmnibridge
/// @notice The one function of the OmniBridge mediator that the routers of OmniBridge call.
interface IOmnibridge {
    function relayTokens(address token, address receiver, uint256 value) external;
}
          

lib/openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Permit.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.5.0) (token/ERC20/extensions/IERC20Permit.sol)

pragma solidity >=0.4.16;

/**
 * @dev Interface of the ERC-20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[ERC-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC-20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 *
 * ==== Security Considerations
 *
 * There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
 * expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
 * considered as an intention to spend the allowance in any specific way. The second is that because permits have
 * built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
 * take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
 * generally recommended is:
 *
 * ```solidity
 * function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
 *     try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
 *     doThing(..., value);
 * }
 *
 * function doThing(..., uint256 value) public {
 *     token.safeTransferFrom(msg.sender, address(this), value);
 *     ...
 * }
 * ```
 *
 * Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
 * `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
 * {SafeERC20-safeTransferFrom}).
 *
 * Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
 * contracts should have entry points that don't rely on permit.
 */
interface IERC20Permit {
    /**
     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
     * given ``owner``'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also applies here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     *
     * CAUTION: See Security Considerations above.
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

    /**
     * @dev Returns the current nonce for `owner`. This value must be
     * included whenever a signature is generated for {permit}.
     *
     * Every successful call to {permit} increases ``owner``'s nonce by one. This
     * prevents a signature from being used multiple times.
     */
    function nonces(address owner) external view returns (uint256);

    /**
     * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view returns (bytes32);
}
          

lib/openzeppelin-contracts/contracts/utils/introspection/IERC165.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (utils/introspection/IERC165.sol)

pragma solidity >=0.4.16;

/**
 * @dev Interface of the ERC-165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[ERC].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
          

lib/openzeppelin-contracts/contracts/interfaces/IERC1363.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC1363.sol)

pragma solidity >=0.6.2;

import {IERC20} from "./IERC20.sol";
import {IERC165} from "./IERC165.sol";

/**
 * @title IERC1363
 * @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].
 *
 * Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract
 * after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.
 */
interface IERC1363 is IERC20, IERC165 {
    /*
     * Note: the ERC-165 identifier for this interface is 0xb0202a11.
     * 0xb0202a11 ===
     *   bytes4(keccak256('transferAndCall(address,uint256)')) ^
     *   bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
     *   bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
     *   bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^
     *   bytes4(keccak256('approveAndCall(address,uint256)')) ^
     *   bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
     */

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferAndCall(address to, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @param data Additional data with no specified format, sent in call to `to`.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param from The address which you want to send tokens from.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferFromAndCall(address from, address to, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param from The address which you want to send tokens from.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @param data Additional data with no specified format, sent in call to `to`.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
     * @param spender The address which will spend the funds.
     * @param value The amount of tokens to be spent.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function approveAndCall(address spender, uint256 value) external returns (bool);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
     * @param spender The address which will spend the funds.
     * @param value The amount of tokens to be spent.
     * @param data Additional data with no specified format, sent in call to `spender`.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}
          

lib/openzeppelin-contracts/contracts/interfaces/IERC20.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC20.sol)

pragma solidity >=0.4.16;

import {IERC20} from "../token/ERC20/IERC20.sol";
          

src/hardened/mediator/TokenFactory.sol

// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

import {BridgedToken} from "./BridgedToken.sol";
import {ITokenParameters} from "./ITokenParameters.sol";

/// @title TokenFactory
/// @notice Deploys the bridged copies of native tokens at addresses that can be computed. Only the mediator may call
/// `deploy`. The factory has no owner and no token image to change: every copy has the same code.
/// @dev The address of a copy is `CREATE2(factory, salt, creationCode)` with `salt = keccak256(abi.encode(homeChainId,
/// nativeToken))`. The creation code has no arguments, so the name, the symbol and the decimals do not change the
/// address. The factory holds them in storage during the deployment, and the token reads them in its constructor.
contract TokenFactory is ITokenParameters {
    /// @notice Only the mediator may deploy.
    error NotMediator(address caller);
    /// @notice The name of the home chain is longer than 32 bytes, so it does not fit in one immutable word.
    error HomeChainNameTooLong(uint256 length);

    /// @dev What the token constructor reads while a deployment runs.
    struct Parameters {
        string name;
        string symbol;
        uint8 decimals;
    }

    /// @notice The only account that may call `deploy`, and the only account that may mint and burn the copies.
    address public immutable mediator;

    /// @dev The name of the chain where the native tokens of this factory live, left aligned in one word, and its
    /// length. Both are immutable: they are part of the code, not of the storage.
    bytes32 private immutable _homeChainNameWord;
    uint256 private immutable _homeChainNameLength;

    Parameters private _pending;

    /// @param mediator_ The mediator that owns the factory.
    /// @param homeChainName_ The name of the other chain, where the native tokens live. At most 32 bytes.
    constructor(address mediator_, string memory homeChainName_) {
        uint256 length = bytes(homeChainName_).length;
        if (length > 32) revert HomeChainNameTooLong(length);
        mediator = mediator_;
        _homeChainNameWord = bytes32(bytes(homeChainName_));
        _homeChainNameLength = length;
    }

    /// @notice The name of the chain where the native tokens of this factory live. The mediator adds it to the name of
    /// each copy. It is set in the constructor and nothing changes it.
    function homeChainName() external view returns (string memory) {
        bytes memory name = abi.encodePacked(_homeChainNameWord);
        uint256 length = _homeChainNameLength;
        assembly ("memory-safe") {
            mstore(name, length)
        }
        return string(name);
    }

    /// @notice Deploys the copy of `nativeToken`. It reverts when the copy exists.
    /// @dev This is the OmniBridge signature `deploy(string,string,uint8,uint256)` with one more argument. A
    /// deterministic address needs the native token, and OmniBridge does not pass it. Its `chainId` argument is the
    /// chain of the permit domain. Here `chainId` is the home chain of the native token, which is the other half of
    /// the salt. The token reads `block.chainid` for its own permit domain.
    /// @param name The name of the copy.
    /// @param symbol The symbol of the copy.
    /// @param decimals The decimals of the copy.
    /// @param chainId The home chain of the native token.
    /// @param nativeToken The native token, on the home chain.
    /// @return token The address of the copy.
    function deploy(string calldata name, string calldata symbol, uint8 decimals, uint256 chainId, address nativeToken)
        external
        returns (address token)
    {
        if (msg.sender != mediator) revert NotMediator(msg.sender);
        _pending = Parameters(name, symbol, decimals);
        token = address(new BridgedToken{salt: _salt(chainId, nativeToken)}());
        delete _pending;
    }

    /// @notice The address where the copy of `nativeToken` is, or will be, deployed.
    /// @param chainId The home chain of the native token.
    /// @param nativeToken The native token, on the home chain.
    function predictAddress(uint256 chainId, address nativeToken) external view returns (address) {
        bytes32 hash = keccak256(
            abi.encodePacked(
                bytes1(0xff), address(this), _salt(chainId, nativeToken), keccak256(type(BridgedToken).creationCode)
            )
        );
        return address(uint160(uint256(hash)));
    }

    /// @inheritdoc ITokenParameters
    function parameters() external view returns (string memory, string memory, uint8, address) {
        return (_pending.name, _pending.symbol, _pending.decimals, mediator);
    }

    function _salt(uint256 chainId, address nativeToken) private pure returns (bytes32) {
        return keccak256(abi.encode(chainId, nativeToken));
    }
}
          

lib/openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity >=0.6.2;

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

/**
 * @dev Interface for the optional metadata functions from the ERC-20 standard.
 */
interface IERC20Metadata is IERC20 {
    /**
     * @dev Returns the name of the token.
     */
    function name() external view returns (string memory);

    /**
     * @dev Returns the symbol of the token.
     */
    function symbol() external view returns (string memory);

    /**
     * @dev Returns the decimals places of the token.
     */
    function decimals() external view returns (uint8);
}
          

lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.5.0) (token/ERC20/ERC20.sol)

pragma solidity ^0.8.20;

import {IERC20} from "./IERC20.sol";
import {IERC20Metadata} from "./extensions/IERC20Metadata.sol";
import {Context} from "../../utils/Context.sol";
import {IERC20Errors} from "../../interfaces/draft-IERC6093.sol";

/**
 * @dev Implementation of the {IERC20} interface.
 *
 * This implementation is agnostic to the way tokens are created. This means
 * that a supply mechanism has to be added in a derived contract using {_mint}.
 *
 * TIP: For a detailed writeup see our guide
 * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
 * to implement supply mechanisms].
 *
 * The default value of {decimals} is 18. To change this, you should override
 * this function so it returns a different value.
 *
 * We have followed general OpenZeppelin Contracts guidelines: functions revert
 * instead returning `false` on failure. This behavior is nonetheless
 * conventional and does not conflict with the expectations of ERC-20
 * applications.
 */
abstract contract ERC20 is Context, IERC20, IERC20Metadata, IERC20Errors {
    mapping(address account => uint256) private _balances;

    mapping(address account => mapping(address spender => uint256)) private _allowances;

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

    /**
     * @dev Sets the values for {name} and {symbol}.
     *
     * Both values are immutable: they can only be set once during construction.
     */
    constructor(string memory name_, string memory symbol_) {
        _name = name_;
        _symbol = symbol_;
    }

    /**
     * @dev Returns the name of the token.
     */
    function name() public view virtual returns (string memory) {
        return _name;
    }

    /**
     * @dev Returns the symbol of the token, usually a shorter version of the
     * name.
     */
    function symbol() public view virtual returns (string memory) {
        return _symbol;
    }

    /**
     * @dev Returns the number of decimals used to get its user representation.
     * For example, if `decimals` equals `2`, a balance of `505` tokens should
     * be displayed to a user as `5.05` (`505 / 10 ** 2`).
     *
     * Tokens usually opt for a value of 18, imitating the relationship between
     * Ether and Wei. This is the default value returned by this function, unless
     * it's overridden.
     *
     * NOTE: This information is only used for _display_ purposes: it in
     * no way affects any of the arithmetic of the contract, including
     * {IERC20-balanceOf} and {IERC20-transfer}.
     */
    function decimals() public view virtual returns (uint8) {
        return 18;
    }

    /// @inheritdoc IERC20
    function totalSupply() public view virtual returns (uint256) {
        return _totalSupply;
    }

    /// @inheritdoc IERC20
    function balanceOf(address account) public view virtual returns (uint256) {
        return _balances[account];
    }

    /**
     * @dev See {IERC20-transfer}.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - the caller must have a balance of at least `value`.
     */
    function transfer(address to, uint256 value) public virtual returns (bool) {
        address owner = _msgSender();
        _transfer(owner, to, value);
        return true;
    }

    /// @inheritdoc IERC20
    function allowance(address owner, address spender) public view virtual returns (uint256) {
        return _allowances[owner][spender];
    }

    /**
     * @dev See {IERC20-approve}.
     *
     * NOTE: If `value` is the maximum `uint256`, the allowance is not updated on
     * `transferFrom`. This is semantically equivalent to an infinite approval.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function approve(address spender, uint256 value) public virtual returns (bool) {
        address owner = _msgSender();
        _approve(owner, spender, value);
        return true;
    }

    /**
     * @dev See {IERC20-transferFrom}.
     *
     * Skips emitting an {Approval} event indicating an allowance update. This is not
     * required by the ERC. See {xref-ERC20-_approve-address-address-uint256-bool-}[_approve].
     *
     * NOTE: Does not update the allowance if the current allowance
     * is the maximum `uint256`.
     *
     * Requirements:
     *
     * - `from` and `to` cannot be the zero address.
     * - `from` must have a balance of at least `value`.
     * - the caller must have allowance for ``from``'s tokens of at least
     * `value`.
     */
    function transferFrom(address from, address to, uint256 value) public virtual returns (bool) {
        address spender = _msgSender();
        _spendAllowance(from, spender, value);
        _transfer(from, to, value);
        return true;
    }

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to`.
     *
     * This internal function is equivalent to {transfer}, and can be used to
     * e.g. implement automatic token fees, slashing mechanisms, etc.
     *
     * Emits a {Transfer} event.
     *
     * NOTE: This function is not virtual, {_update} should be overridden instead.
     */
    function _transfer(address from, address to, uint256 value) internal {
        if (from == address(0)) {
            revert ERC20InvalidSender(address(0));
        }
        if (to == address(0)) {
            revert ERC20InvalidReceiver(address(0));
        }
        _update(from, to, value);
    }

    /**
     * @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`
     * (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding
     * this function.
     *
     * Emits a {Transfer} event.
     */
    function _update(address from, address to, uint256 value) internal virtual {
        if (from == address(0)) {
            // Overflow check required: The rest of the code assumes that totalSupply never overflows
            _totalSupply += value;
        } else {
            uint256 fromBalance = _balances[from];
            if (fromBalance < value) {
                revert ERC20InsufficientBalance(from, fromBalance, value);
            }
            unchecked {
                // Overflow not possible: value <= fromBalance <= totalSupply.
                _balances[from] = fromBalance - value;
            }
        }

        if (to == address(0)) {
            unchecked {
                // Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.
                _totalSupply -= value;
            }
        } else {
            unchecked {
                // Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.
                _balances[to] += value;
            }
        }

        emit Transfer(from, to, value);
    }

    /**
     * @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).
     * Relies on the `_update` mechanism
     *
     * Emits a {Transfer} event with `from` set to the zero address.
     *
     * NOTE: This function is not virtual, {_update} should be overridden instead.
     */
    function _mint(address account, uint256 value) internal {
        if (account == address(0)) {
            revert ERC20InvalidReceiver(address(0));
        }
        _update(address(0), account, value);
    }

    /**
     * @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.
     * Relies on the `_update` mechanism.
     *
     * Emits a {Transfer} event with `to` set to the zero address.
     *
     * NOTE: This function is not virtual, {_update} should be overridden instead
     */
    function _burn(address account, uint256 value) internal {
        if (account == address(0)) {
            revert ERC20InvalidSender(address(0));
        }
        _update(account, address(0), value);
    }

    /**
     * @dev Sets `value` as the allowance of `spender` over the `owner`'s tokens.
     *
     * This internal function is equivalent to `approve`, and can be used to
     * e.g. set automatic allowances for certain subsystems, etc.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `owner` cannot be the zero address.
     * - `spender` cannot be the zero address.
     *
     * Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.
     */
    function _approve(address owner, address spender, uint256 value) internal {
        _approve(owner, spender, value, true);
    }

    /**
     * @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event.
     *
     * By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by
     * `_spendAllowance` during the `transferFrom` operation sets the flag to false. This saves gas by not emitting any
     * `Approval` event during `transferFrom` operations.
     *
     * Anyone who wishes to continue emitting `Approval` events on the `transferFrom` operation can force the flag to
     * true using the following override:
     *
     * ```solidity
     * function _approve(address owner, address spender, uint256 value, bool) internal virtual override {
     *     super._approve(owner, spender, value, true);
     * }
     * ```
     *
     * Requirements are the same as {_approve}.
     */
    function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual {
        if (owner == address(0)) {
            revert ERC20InvalidApprover(address(0));
        }
        if (spender == address(0)) {
            revert ERC20InvalidSpender(address(0));
        }
        _allowances[owner][spender] = value;
        if (emitEvent) {
            emit Approval(owner, spender, value);
        }
    }

    /**
     * @dev Updates `owner`'s allowance for `spender` based on spent `value`.
     *
     * Does not update the allowance value in case of infinite allowance.
     * Revert if not enough allowance is available.
     *
     * Does not emit an {Approval} event.
     */
    function _spendAllowance(address owner, address spender, uint256 value) internal virtual {
        uint256 currentAllowance = allowance(owner, spender);
        if (currentAllowance < type(uint256).max) {
            if (currentAllowance < value) {
                revert ERC20InsufficientAllowance(spender, currentAllowance, value);
            }
            unchecked {
                _approve(owner, spender, currentAllowance - value, false);
            }
        }
    }
}
          

lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/IERC20.sol)

pragma solidity >=0.4.16;

/**
 * @dev Interface of the ERC-20 standard as defined in the ERC.
 */
interface IERC20 {
    /**
     * @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);

    /**
     * @dev Returns the value of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

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

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

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

src/hardened/mediator/MediatorPayloads.sol

// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

import {TokenReader} from "./TokenReader.sol";
import {TokenFactory} from "./TokenFactory.sol";
import {IBurnableMintableERC677Token} from "./IBurnableMintableERC677Token.sol";
import {IFlowLimiter} from "../IFlowLimiter.sol";
import {IAMB} from "../IAMB.sol";

/// @dev The name and the symbol rule of a bridged copy, one copy for this library and the public constants of
/// `TokenMediator` (`NAME_CONNECTOR`, `SYMBOL_PREFIX`).
string constant COPY_NAME_CONNECTOR = " from ";
string constant COPY_SYMBOL_PREFIX = "z";

/// @title IMediatorHandlers
/// @notice The handlers of `TokenMediator` that a message of the other mediator calls. `TokenMediator` implements this
/// interface, so the selectors that `MediatorPayloads` encodes are checked against the mediator by the compiler.
interface IMediatorHandlers {
    function handleNativeTokens(address token, address recipient, uint256 value) external;

    function handleNativeTokensAndCall(
        address token,
        address recipient,
        uint256 value,
        bytes memory data,
        uint256 callbackGas
    ) external;

    function handleBridgedTokens(address token, address recipient, uint256 value) external;

    function handleBridgedTokensAndCall(
        address token,
        address recipient,
        uint256 value,
        bytes memory data,
        uint256 callbackGas
    ) external;

    function deployAndHandleBridgedTokens(
        address token,
        string memory name,
        string memory symbol,
        uint8 decimals,
        address recipient,
        uint256 value
    ) external;

    function deployAndHandleBridgedTokensAndCall(
        address token,
        string memory name,
        string memory symbol,
        uint8 decimals,
        address recipient,
        uint256 value,
        bytes memory data,
        uint256 callbackGas
    ) external;
}

/// @title MediatorPayloads
/// @notice The messages that `TokenMediator` sends to the mediator on the other chain, and the reading of the ERC-677
/// data of a transfer. It reads the name, the symbol and the decimals of a native token for its first message
/// (`TokenReader`).
/// @dev An external library, linked into `TokenMediator`, so that the creation of the mediator stays under the
/// per-transaction gas cap of EIP-7825 (16,777,216). It has no owner and no storage, and its address is fixed in the
/// bytecode of the mediator, so the mediator stays immutable. On the sending side it builds every message; on the
/// receiving side only the first message of a token calls it, to deploy the copy (`copyOrDeploy`). A relay with a call
/// always carries `callbackGas` after `data`.
library MediatorPayloads {
    /// @notice The record of a native token in `TokenMediator`, in one storage slot.
    /// @param balance What the mediator owes to the other chain in this token.
    /// @param registered The token was relayed at least once.
    /// @param deployAcknowledged The other chain proved that the bridged copy exists, by sending tokens back.
    struct NativeRecord {
        uint240 balance;
        bool registered;
        bool deployAcknowledged;
    }

    /// @notice What the sender asks for in one relay. `callbackGas` is the gas of the callback, zero for a plain relay.
    struct Relay {
        address token;
        address receiver;
        bytes data;
        bool withCall;
        uint256 callbackGas;
    }

    /// @notice The same errors as those of `TokenMediator`, with the same signatures.
    error InvalidReceiver(address receiver);
    error ZeroAmount();
    error ZeroCallbackGas();
    error MediatorBalanceOverflow(address token);
    /// @notice A token has neither a name nor a symbol, so the other chain could not name its copy. The same error as
    /// `TokenMediator.NoTokenName`.
    error NoTokenName(address token);
    /// @notice The ERC-677 data is longer than a receiver and shorter than a receiver and the callback gas. The same error
    /// as `TokenMediator.MalformedTransferData`.
    error MalformedTransferData(uint256 length);

    /// @notice Emitted when the mediator deploys the bridged copy of a native token. The same event as
    /// `TokenMediator.NewTokenRegistered`; the library runs in the mediator, so the mediator emits it.
    event NewTokenRegistered(address indexed nativeToken, address indexed bridgedToken);
    /// @notice The same event as `TokenMediator.TokensBridgingInitiated`, emitted by the mediator.
    event TokensBridgingInitiated(
        address indexed token, address indexed sender, uint256 value, bytes32 indexed messageId
    );

    /// @dev The length of the receiver at the start of the ERC-677 data.
    uint256 internal constant RECEIVER_LENGTH = 20;
    /// @dev Where the callback data starts in the ERC-677 data: after the receiver and the callback gas word.
    uint256 internal constant CALL_DATA_START = 52;

    /// @notice The sending side of `TokenMediator`, after the tokens arrived: checks the receiver, the amount and the
    /// callback gas, asks the flow limiter, locks a native token (or burns a bridged copy), and sends the message to the
    /// mediator on the other chain. The message asks the bridge for no gas.
    /// @dev Runs with DELEGATECALL in the storage of the mediator: the record of the native tokens and the map of the
    /// bridged copies are `storage` arguments. The mediator passes its bridge, its twin and its limiter.
    function send(
        mapping(address => NativeRecord) storage native,
        mapping(address => address) storage nativeTokenAddress,
        IAMB bridge,
        address remoteMediator,
        IFlowLimiter limiter,
        Relay memory relay,
        address from,
        uint256 value
    ) external {
        if (relay.receiver == address(0) || relay.receiver == remoteMediator) {
            revert InvalidReceiver(relay.receiver);
        }
        if (value == 0) revert ZeroAmount();
        if (relay.withCall && relay.callbackGas == 0) revert ZeroCallbackGas();
        if (address(limiter) != address(0)) limiter.checkDeposit(relay.token, from, value);

        address nativeToken = nativeTokenAddress[relay.token];
        bytes memory payload = nativeToken == address(0)
            ? _lockAndEncode(native, relay, value)
            : _burnAndEncode(relay, nativeToken, value);
        bytes32 messageId = bridge.requireToPassMessage(remoteMediator, payload, 0);
        emit TokensBridgingInitiated(relay.token, from, value, messageId);
    }

    /// @dev A native token: records the lock and builds the message that mints, or unlocks, on the other chain. Until
    /// the other chain proves that the copy exists, it is the first message form, which carries the name, the symbol and
    /// the decimals; then the short form, which without a call is the OmniBridge payload, byte for byte.
    function _lockAndEncode(mapping(address => NativeRecord) storage native, Relay memory relay, uint256 value)
        private
        returns (bytes memory)
    {
        NativeRecord memory record = native[relay.token];
        uint256 newBalance = record.balance + value;
        if (newBalance > type(uint240).max) revert MediatorBalanceOverflow(relay.token);
        native[relay.token] = NativeRecord(uint240(newBalance), true, record.deployAcknowledged);

        if (record.deployAcknowledged) {
            if (relay.withCall) {
                return abi.encodeCall(
                    IMediatorHandlers.handleBridgedTokensAndCall,
                    (relay.token, relay.receiver, value, relay.data, relay.callbackGas)
                );
            }
            return abi.encodeCall(IMediatorHandlers.handleBridgedTokens, (relay.token, relay.receiver, value));
        }
        (string memory name, string memory symbol, uint8 decimals) = readMetadata(relay.token);
        if (relay.withCall) {
            return abi.encodeCall(
                IMediatorHandlers.deployAndHandleBridgedTokensAndCall,
                (relay.token, name, symbol, decimals, relay.receiver, value, relay.data, relay.callbackGas)
            );
        }
        return abi.encodeCall(
            IMediatorHandlers.deployAndHandleBridgedTokens, (relay.token, name, symbol, decimals, relay.receiver, value)
        );
    }

    /// @dev A bridged copy: burns it and builds the message that unlocks `nativeToken` on the other chain.
    function _burnAndEncode(Relay memory relay, address nativeToken, uint256 value) private returns (bytes memory) {
        IBurnableMintableERC677Token(relay.token).burn(value);
        if (relay.withCall) {
            return abi.encodeCall(
                IMediatorHandlers.handleNativeTokensAndCall,
                (nativeToken, relay.receiver, value, relay.data, relay.callbackGas)
            );
        }
        return abi.encodeCall(IMediatorHandlers.handleNativeTokens, (nativeToken, relay.receiver, value));
    }

    /// @notice Reads the ERC-677 data of a transfer of `token`: nothing (the receiver is `from`, no call), a receiver (no
    /// call), or a receiver, one 32 byte word with the gas of the callback, and the bytes passed to `onTokenBridged`
    /// (they may be empty). Data between 21 and 51 bytes reverts with `MalformedTransferData`.
    function readTransferData(address token, address from, bytes memory data)
        external
        pure
        returns (Relay memory relay)
    {
        relay.token = token;
        if (data.length < RECEIVER_LENGTH) {
            relay.receiver = from;
            return relay;
        }
        relay.receiver = address(bytes20(data));
        if (data.length == RECEIVER_LENGTH) return relay;
        if (data.length < CALL_DATA_START) revert MalformedTransferData(data.length);
        uint256 callbackGas;
        assembly ("memory-safe") {
            callbackGas := mload(add(data, add(32, RECEIVER_LENGTH)))
        }
        bytes memory callData = new bytes(data.length - CALL_DATA_START);
        for (uint256 i = 0; i < callData.length; i++) {
            callData[i] = data[i + CALL_DATA_START];
        }
        relay.data = callData;
        relay.withCall = true;
        relay.callbackGas = callbackGas;
    }

    /// @notice The bridged copy of `nativeToken`, on the receiving side of a first message. It deploys the copy when it does
    /// not exist and records it in the two mappings of the mediator. A copy that exists keeps its name, so a later message
    /// with other metadata changes nothing.
    /// @dev Runs with DELEGATECALL in the storage of the mediator: the mappings are `storage` arguments.
    function copyOrDeploy(
        mapping(address => address) storage bridgedTokenAddress,
        mapping(address => address) storage nativeTokenAddress,
        TokenFactory factory,
        uint256 homeChainId,
        address nativeToken,
        string calldata name,
        string calldata symbol,
        uint8 decimals
    ) external returns (address copy) {
        copy = bridgedTokenAddress[nativeToken];
        if (copy != address(0)) return copy;
        if (bytes(name).length == 0 && bytes(symbol).length == 0) revert NoTokenName(nativeToken);
        string memory baseName = bytes(name).length == 0 ? symbol : name;
        string memory baseSymbol = bytes(symbol).length == 0 ? name : symbol;
        copy = factory.deploy(
            string.concat(baseName, COPY_NAME_CONNECTOR, factory.homeChainName()),
            string.concat(COPY_SYMBOL_PREFIX, baseSymbol),
            decimals,
            homeChainId,
            nativeToken
        );
        bridgedTokenAddress[nativeToken] = copy;
        nativeTokenAddress[copy] = nativeToken;
        emit NewTokenRegistered(nativeToken, copy);
    }

    /// @dev The name, the symbol and the decimals of a native token for its first message. A token with neither a name
    /// nor a symbol is refused.
    function readMetadata(address token)
        internal
        view
        returns (string memory name, string memory symbol, uint8 decimals)
    {
        name = TokenReader.readName(token);
        symbol = TokenReader.readSymbol(token);
        if (bytes(name).length == 0 && bytes(symbol).length == 0) revert NoTokenName(token);
        decimals = TokenReader.readDecimals(token);
    }
}
          

Compiler Settings

{"viaIR":false,"remappings":["@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/","forge-std/=lib/forge-std/src/","erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/","halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/","openzeppelin-contracts/=lib/openzeppelin-contracts/"],"outputSelection":{"*":{"*":["abi","evm.bytecode","evm.deployedBytecode"]}},"optimizer":{"runs":200,"enabled":true},"metadata":{"useLiteralContent":false,"bytecodeHash":"none","appendCBOR":false},"libraries":{"src/hardened/mediator/MediatorPayloads.sol":{"MediatorPayloads":"0x1e68160762061624bb5fa31d589a8f31c3e44bc5"}},"evmVersion":"shanghai"}
              

Contract ABI

[{"type":"constructor","stateMutability":"nonpayable","inputs":[{"type":"tuple","name":"terms","internalType":"struct TokenMediator.MediatorTerms","components":[{"type":"address","name":"bridge","internalType":"address"},{"type":"address","name":"remoteMediator","internalType":"address"},{"type":"address","name":"flowLimiter","internalType":"address"},{"type":"address","name":"tokenFactory","internalType":"address"}]}]},{"type":"error","name":"CallOutOfGas","inputs":[{"type":"uint256","name":"gasAmount","internalType":"uint256"}]},{"type":"error","name":"FactoryOfAnotherMediator","inputs":[{"type":"address","name":"mediator","internalType":"address"}]},{"type":"error","name":"HandlerDuringTransfer","inputs":[]},{"type":"error","name":"InsufficientGas","inputs":[{"type":"uint256","name":"available","internalType":"uint256"},{"type":"uint256","name":"required","internalType":"uint256"}]},{"type":"error","name":"InsufficientMediatorBalance","inputs":[{"type":"address","name":"token","internalType":"address"},{"type":"uint256","name":"balance","internalType":"uint256"},{"type":"uint256","name":"value","internalType":"uint256"}]},{"type":"error","name":"InvalidReceiver","inputs":[{"type":"address","name":"receiver","internalType":"address"}]},{"type":"error","name":"MalformedTransferData","inputs":[{"type":"uint256","name":"length","internalType":"uint256"}]},{"type":"error","name":"MediatorBalanceOverflow","inputs":[{"type":"address","name":"token","internalType":"address"}]},{"type":"error","name":"NoTokenName","inputs":[{"type":"address","name":"token","internalType":"address"}]},{"type":"error","name":"NotBridge","inputs":[{"type":"address","name":"caller","internalType":"address"}]},{"type":"error","name":"NotFlowLimiter","inputs":[{"type":"address","name":"caller","internalType":"address"}]},{"type":"error","name":"ReceivedMoreThanSent","inputs":[{"type":"uint256","name":"received","internalType":"uint256"},{"type":"uint256","name":"sent","internalType":"uint256"}]},{"type":"error","name":"ReentrancyGuardReentrantCall","inputs":[]},{"type":"error","name":"ReleaseOutOfGas","inputs":[{"type":"address","name":"token","internalType":"address"}]},{"type":"error","name":"SafeERC20FailedOperation","inputs":[{"type":"address","name":"token","internalType":"address"}]},{"type":"error","name":"UnbackedTransfer","inputs":[{"type":"address","name":"token","internalType":"address"},{"type":"uint256","name":"value","internalType":"uint256"},{"type":"uint256","name":"unaccounted","internalType":"uint256"}]},{"type":"error","name":"UnknownBridgedToken","inputs":[{"type":"address","name":"nativeToken","internalType":"address"}]},{"type":"error","name":"WrongRemoteMediator","inputs":[{"type":"address","name":"expected","internalType":"address"},{"type":"address","name":"actual","internalType":"address"}]},{"type":"error","name":"WrongSourceChain","inputs":[{"type":"bytes32","name":"expected","internalType":"bytes32"},{"type":"bytes32","name":"actual","internalType":"bytes32"}]},{"type":"error","name":"ZeroAmount","inputs":[]},{"type":"error","name":"ZeroCallbackGas","inputs":[]},{"type":"error","name":"ZeroValue","inputs":[{"type":"string","name":"name","internalType":"string"}]},{"type":"event","name":"CallbackFailed","inputs":[{"type":"address","name":"token","internalType":"address","indexed":true},{"type":"address","name":"recipient","internalType":"address","indexed":true},{"type":"bytes32","name":"messageId","internalType":"bytes32","indexed":true}],"anonymous":false},{"type":"event","name":"FlowLimiterDetached","inputs":[{"type":"address","name":"limiter","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"NewTokenRegistered","inputs":[{"type":"address","name":"nativeToken","internalType":"address","indexed":true},{"type":"address","name":"bridgedToken","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"ReleaseFailed","inputs":[{"type":"address","name":"token","internalType":"address","indexed":true},{"type":"address","name":"recipient","internalType":"address","indexed":true},{"type":"uint256","name":"value","internalType":"uint256","indexed":false},{"type":"bytes32","name":"messageId","internalType":"bytes32","indexed":true}],"anonymous":false},{"type":"event","name":"TokensBridged","inputs":[{"type":"address","name":"token","internalType":"address","indexed":true},{"type":"address","name":"recipient","internalType":"address","indexed":true},{"type":"uint256","name":"value","internalType":"uint256","indexed":false},{"type":"bytes32","name":"messageId","internalType":"bytes32","indexed":true}],"anonymous":false},{"type":"event","name":"TokensBridgingInitiated","inputs":[{"type":"address","name":"token","internalType":"address","indexed":true},{"type":"address","name":"sender","internalType":"address","indexed":true},{"type":"uint256","name":"value","internalType":"uint256","indexed":false},{"type":"bytes32","name":"messageId","internalType":"bytes32","indexed":true}],"anonymous":false},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"CALLBACK_GAS_RESERVE","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"string","name":"","internalType":"string"}],"name":"NAME_CONNECTOR","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"string","name":"","internalType":"string"}],"name":"SYMBOL_PREFIX","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"TRANSFER_GAS_RESERVE","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract IAMB"}],"name":"bridgeContract","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"bridgedTokenAddress","inputs":[{"type":"address","name":"nativeToken","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"deployAndHandleBridgedTokens","inputs":[{"type":"address","name":"token","internalType":"address"},{"type":"string","name":"name","internalType":"string"},{"type":"string","name":"symbol","internalType":"string"},{"type":"uint8","name":"decimals","internalType":"uint8"},{"type":"address","name":"recipient","internalType":"address"},{"type":"uint256","name":"value","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"deployAndHandleBridgedTokensAndCall","inputs":[{"type":"address","name":"token","internalType":"address"},{"type":"string","name":"name","internalType":"string"},{"type":"string","name":"symbol","internalType":"string"},{"type":"uint8","name":"decimals","internalType":"uint8"},{"type":"address","name":"recipient","internalType":"address"},{"type":"uint256","name":"value","internalType":"uint256"},{"type":"bytes","name":"data","internalType":"bytes"},{"type":"uint256","name":"callbackGas","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"detachFlowLimiter","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract IFlowLimiter"}],"name":"flowLimiter","inputs":[]},{"type":"function","stateMutability":"pure","outputs":[{"type":"uint64","name":"major","internalType":"uint64"},{"type":"uint64","name":"minor","internalType":"uint64"},{"type":"uint64","name":"patch","internalType":"uint64"}],"name":"getBridgeInterfacesVersion","inputs":[]},{"type":"function","stateMutability":"pure","outputs":[{"type":"bytes4","name":"","internalType":"bytes4"}],"name":"getBridgeMode","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"handleBridgedTokens","inputs":[{"type":"address","name":"token","internalType":"address"},{"type":"address","name":"recipient","internalType":"address"},{"type":"uint256","name":"value","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"handleBridgedTokensAndCall","inputs":[{"type":"address","name":"token","internalType":"address"},{"type":"address","name":"recipient","internalType":"address"},{"type":"uint256","name":"value","internalType":"uint256"},{"type":"bytes","name":"data","internalType":"bytes"},{"type":"uint256","name":"callbackGas","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"handleNativeTokens","inputs":[{"type":"address","name":"token","internalType":"address"},{"type":"address","name":"recipient","internalType":"address"},{"type":"uint256","name":"value","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"handleNativeTokensAndCall","inputs":[{"type":"address","name":"token","internalType":"address"},{"type":"address","name":"recipient","internalType":"address"},{"type":"uint256","name":"value","internalType":"uint256"},{"type":"bytes","name":"data","internalType":"bytes"},{"type":"uint256","name":"callbackGas","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"isBridgedTokenDeployAcknowledged","inputs":[{"type":"address","name":"token","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"isRegisteredAsNativeToken","inputs":[{"type":"address","name":"token","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"isTokenRegistered","inputs":[{"type":"address","name":"token","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"mediatorBalance","inputs":[{"type":"address","name":"token","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"mediatorContractOnOtherSide","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"nativeTokenAddress","inputs":[{"type":"address","name":"bridgedToken","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"onTokenTransfer","inputs":[{"type":"address","name":"from","internalType":"address"},{"type":"uint256","name":"value","internalType":"uint256"},{"type":"bytes","name":"data","internalType":"bytes"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"relayTokens","inputs":[{"type":"address","name":"token","internalType":"address"},{"type":"uint256","name":"value","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"relayTokens","inputs":[{"type":"address","name":"token","internalType":"address"},{"type":"address","name":"receiver","internalType":"address"},{"type":"uint256","name":"value","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"relayTokensAndCall","inputs":[{"type":"address","name":"token","internalType":"address"},{"type":"address","name":"receiver","internalType":"address"},{"type":"uint256","name":"value","internalType":"uint256"},{"type":"bytes","name":"data","internalType":"bytes"},{"type":"uint256","name":"callbackGas","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"remoteChainId","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract TokenFactory"}],"name":"tokenFactory","inputs":[]}]
              

Contract Creation Code

0x610100604052348015610010575f5ffd5b5060405161275338038061275383398101604081905261002f91610428565b60017f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f005580516001600160a01b03163b5f0361009c5760405163046c82ad60e41b815260206004820152600660248201526562726964676560d01b60448201526064015b60405180910390fd5b60208101516001600160a01b03166100e85760405163046c82ad60e41b815260206004820152600e60248201526d3932b6b7ba32a6b2b234b0ba37b960911b6044820152606401610093565b80606001516001600160a01b03163b5f036101355760405163046c82ad60e41b815260206004820152600c60248201526b746f6b656e466163746f727960a01b6044820152606401610093565b5f81606001519050306001600160a01b0316816001600160a01b0316636d0501f66040518163ffffffff1660e01b8152600401602060405180830381865afa158015610183573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906101a791906104a4565b6001600160a01b03161461023a57806001600160a01b0316636d0501f66040518163ffffffff1660e01b8152600401602060405180830381865afa1580156101f1573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061021591906104a4565b604051633a8df63960e21b81526001600160a01b039091166004820152602401610093565b806001600160a01b031663d820ce8b6040518163ffffffff1660e01b81526004015f60405180830381865afa158015610275573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f1916820160405261029c91908101906104c4565b515f036102de5760405163046c82ad60e41b815260206004820152600f60248201526e72656d6f7465436861696e4e616d6560881b6044820152606401610093565b5f825f01516001600160a01b031663b07506116040518163ffffffff1660e01b8152600401602060405180830381865afa15801561031e573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610342919061056b565b9050805f036103845760405163046c82ad60e41b815260206004820152600d60248201526c1c995b5bdd1950da185a5b9259609a1b6044820152606401610093565b82516001600160a01b039081166080526020840151811660a05260c09190915290811660e0526040909101515f80546001600160a01b03191691909216179055610582565b634e487b7160e01b5f52604160045260245ffd5b604051601f8201601f191681016001600160401b0381118282101715610405576104056103c9565b604052919050565b80516001600160a01b0381168114610423575f5ffd5b919050565b5f6080828403128015610439575f5ffd5b50604051608081016001600160401b038111828210171561045c5761045c6103c9565b6040526104688361040d565b81526104766020840161040d565b60208201526104876040840161040d565b60408201526104986060840161040d565b60608201529392505050565b5f602082840312156104b4575f5ffd5b6104bd8261040d565b9392505050565b5f602082840312156104d4575f5ffd5b81516001600160401b038111156104e9575f5ffd5b8201601f810184136104f9575f5ffd5b80516001600160401b03811115610512576105126103c9565b610525601f8201601f19166020016103dd565b818152856020838501011115610539575f5ffd5b5f5b828110156105575760208185018101518383018201520161053b565b505f91810160200191909152949350505050565b5f6020828403121561057b575f5ffd5b5051919050565b60805160a05160c05160e0516121586105fb5f395f81816104900152610ea901525f81816104b701528181610ce901528181610d1d0152610ecb01525f818161035a01528181610c0101528181610c4f015261139901525f818161044401528181610b5201528181610f70015261137701526121585ff3fe608060405234801561000f575f5ffd5b50600436106101bb575f3560e01c8063871c0760116100f3578063c2173d4311610093578063e77772fe1161006e578063e77772fe1461048b578063e9518196146104b2578063f248fbcf146104d9578063f43589fd146104ec575f5ffd5b8063c2173d431461040d578063cd5965831461043f578063d0d9975a14610466575f5ffd5b80639d613974116100ce5780639d613974146103ad578063a4c0ed36146103b5578063ad58bdd1146103c8578063ae813e9f146103db575f5ffd5b8063871c076014610355578063922341341461037c5780639cb7595a1461038f575f5ffd5b80632d70061f1161015e578063555d284811610139578063555d2848146102e557806361c04f84146102f7578063631c2bb81461031f578063845a7e161461034c575f5ffd5b80632d70061f1461028757806333a2fd29146102c7578063437764df146102d0575f5ffd5b806326aa101f1161019957806326aa101f1461022b578063272255bb1461024e5780632ae87cdd146102615780632cc90da514610274575f5ffd5b806301e4f53a146101bf578063125e4cfb146101d4578063194153d3146101e7575b5f5ffd5b6101d26101cd366004611907565b6104ff565b005b6101d26101e2366004611931565b610573565b6102186101f536600461196f565b6001600160a01b03165f908152600360205260409020546001600160f01b031690565b6040519081526020015b60405180910390f35b61023e61023936600461196f565b6105d8565b6040519015158152602001610222565b6101d261025c366004611931565b610623565b6101d261026f3660046119de565b610683565b6101d2610282366004611a8b565b610701565b6102af61029536600461196f565b60016020525f90815260409020546001600160a01b031681565b6040516001600160a01b039091168152602001610222565b61021861271081565b6040516358a8b61360e11b8152602001610222565b5f546102af906001600160a01b031681565b6102af61030536600461196f565b60026020525f90815260409020546001600160a01b031681565b61033f604051806040016040528060018152602001603d60f91b81525081565b6040516102229190611bbb565b61021861ea6081565b6102af7f000000000000000000000000000000000000000000000000000000000000000081565b6101d261038a366004611bcd565b610798565b60408051600380825260208201525f91810191909152606001610222565b6101d2610835565b61023e6103c3366004611d26565b6108aa565b6101d26103d6366004611931565b6108d6565b61023e6103e936600461196f565b6001600160a01b03165f90815260036020526040902054600160f81b900460ff1690565b61023e61041b36600461196f565b6001600160a01b03165f90815260036020526040902054600160f01b900460ff1690565b6102af7f000000000000000000000000000000000000000000000000000000000000000081565b61033f60405180604001604052806006815260200165010333937b6960d51b81525081565b6102af7f000000000000000000000000000000000000000000000000000000000000000081565b6102187f000000000000000000000000000000000000000000000000000000000000000081565b6101d26104e7366004611d7a565b610946565b6101d26104fa366004611d7a565b61099e565b6105076109ef565b6105596040518060a00160405280846001600160a01b03168152602001336001600160a01b0316815260200160405180602001604052805f81525081526020015f151581526020015f81525082610a0a565b61056f60015f5160206121385f395f51905f5255565b5050565b61057b610b50565b6105d3836040518060a00160405280856001600160a01b0316815260200184815260200160405180602001604052805f81525081526020015f60018111156105c5576105c5611de8565b81526020015f815250610d50565b505050565b6001600160a01b0381165f90815260036020526040812054600160f01b900460ff168061061d57506001600160a01b038281165f908152600260205260409020541615155b92915050565b61062b610b50565b6105d3836040518060a00160405280856001600160a01b0316815260200184815260200160405180602001604052805f81525081526020015f600181111561067557610675611de8565b81526020015f815250610d9f565b61068b610b50565b5f61069a898989898989610e72565b90506106f66001826040518060a00160405280876001600160a01b0316815260200186815260200160405180602001604052805f81525081526020015f60018111156106e8576106e8611de8565b81526020015f815250610f49565b505050505050505050565b610709610b50565b5f6107188c8c8c8c8c8c610e72565b905061078a6001826040518060a001604052808a6001600160a01b0316815260200189815260200188888080601f0160208091040260200160405190810160405280939291908181526020018383808284375f9201919091525050509082525060200160018152602001869052610f49565b505050505050505050505050565b6107a06109ef565b6108176040518060a00160405280886001600160a01b03168152602001876001600160a01b0316815260200185858080601f0160208091040260200160405190810160405280939291908181526020018383808284375f920191909152505050908252506001602082015260400183905285610a0a565b61082d60015f5160206121385f395f51905f5255565b505050505050565b5f546001600160a01b031633811461086757604051630a9e172560e11b81523360048201526024015b60405180910390fd5b5f80546001600160a01b03191681556040516001600160a01b038316917f3f470988d5908fe18d1ef712a2aaea40f5beee6037de03d63857a91049e52ee591a250565b6004545f9060ff16156108bf575060016108cf565b6108cb33858585611154565b5060015b9392505050565b6108de6109ef565b6109306040518060a00160405280856001600160a01b03168152602001846001600160a01b0316815260200160405180602001604052805f81525081526020015f151581526020015f81525082610a0a565b6105d360015f5160206121385f395f51905f5255565b61094e610b50565b610997856040518060a00160405280876001600160a01b0316815260200186815260200185815260200160018081111561098a5761098a611de8565b8152602001849052610d50565b5050505050565b6109a6610b50565b610997856040518060a00160405280876001600160a01b031681526020018681526020018581526020016001808111156109e2576109e2611de8565b8152602001849052610d9f565b6109f76112d9565b60025f5160206121385f395f51905f5255565b81516040516370a0823160e01b81523060048201525f906001600160a01b038316906370a0823190602401602060405180830381865afa158015610a50573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610a749190611dfc565b6004805460ff191660011790559050610a986001600160a01b03831633308661130a565b6004805460ff191681556040516370a0823160e01b815230918101919091525f9082906001600160a01b038516906370a0823190602401602060405180830381865afa158015610aea573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610b0e9190611dfc565b610b189190611e27565b905083811115610b45576040516359542aa560e01b8152600481018290526024810185905260440161085e565b610997853383611340565b7f0000000000000000000000000000000000000000000000000000000000000000336001600160a01b03821614610b9c57604051637c8da0cf60e11b815233600482015260240161085e565b5f816001600160a01b031663d67bdd256040518163ffffffff1660e01b8152600401602060405180830381865afa158015610bd9573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610bfd9190611e3a565b90507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316816001600160a01b031614610c845760405163453324b160e01b81526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000811660048301528216602482015260440161085e565b5f826001600160a01b0316639e307dff6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610cc1573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610ce59190611dfc565b90507f000000000000000000000000000000000000000000000000000000000000000081146105d35760405163344de78960e01b81527f000000000000000000000000000000000000000000000000000000000000000060048201526024810182905260440161085e565b6001600160a01b038083165f908152600160205260409020541680610d93576040516317b01ef760e21b81526001600160a01b038416600482015260240161085e565b6105d360018284610f49565b6001600160a01b0382165f90815260036020908152604091829020825160608101845290546001600160f01b038116825260ff600160f01b82048116151593830193909352600160f81b9004909116151591810182905290610e6757600160408083019182526001600160a01b0385165f90815260036020908152919020835181549285015193511515600160f81b026001600160f81b03941515600160f01b026001600160f81b03199094166001600160f01b039092169190911792909217929092161790555b6105d35f8484610f49565b604051631cf605af60e01b81525f90731e68160762061624bb5fa31d589a8f31c3e44bc590631cf605af90610eff906001906002907f0000000000000000000000000000000000000000000000000000000000000000907f0000000000000000000000000000000000000000000000000000000000000000908e908e908e908e908e908e90600401611e7d565b602060405180830381865af4158015610f1a573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610f3e9190611e3a565b979650505050505050565b60045460ff1615610f6d5760405163e065483960e01b815260040160405180910390fd5b5f7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663669f618b6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610fca573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610fee9190611dfc565b90505f84600181111561100357611003611de8565b036110b8576001600160a01b0383165f90815260036020908152604090912054908301516001600160f01b03909116908110156110725760208301516040516314bd39c360e21b81526001600160a01b038616600482015260248101839052604481019190915260640161085e565b60208301516110819082611e27565b6001600160a01b0385165f90815260036020526040902080546001600160f01b0319166001600160f01b0392909216919091179055505b6110c484848484611402565b6110ce5750505050565b80825f01516001600160a01b0316846001600160a01b03167f9afd47907e25028cdaca89d193518c302bbb128617d5a992c5abd45815526593856020015160405161111b91815260200190565b60405180910390a460018260600151600181111561113b5761113b611de8565b0361114e57815161114e908484846114a5565b50505050565b61115c6109ef565b6001600160a01b0384165f818152600360205260408082205490516370a0823160e01b81523060048201526001600160f01b0390911692906370a0823190602401602060405180830381865afa1580156111b8573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906111dc9190611dfc565b90506111e88483611eec565b81101561123a5785848383116111fe575f611208565b6112088484611e27565b604051633b12021b60e11b81526001600160a01b0390931660048401526024830191909152604482015260640161085e565b6040516307d73aa560e21b81526112c190731e68160762061624bb5fa31d589a8f31c3e44bc590631f5cea9490611279908a908a908990600401611eff565b5f60405180830381865af4158015611293573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f191682016040526112ba9190810190611f42565b8686611340565b505061114e60015f5160206121385f395f51905f5255565b5f5160206121385f395f51905f525460020361130857604051633ee5aeb560e01b815260040160405180910390fd5b565b61131884848484600161156f565b61114e57604051635274afe760e01b81526001600160a01b038516600482015260240161085e565b5f54604051630be7c76f60e21b8152731e68160762061624bb5fa31d589a8f31c3e44bc591632f9f1dbc916113d1916003916002917f0000000000000000000000000000000000000000000000000000000000000000917f0000000000000000000000000000000000000000000000000000000000000000916001600160a01b0316908b908b908b90600401612028565b5f6040518083038186803b1580156113e7575f5ffd5b505af41580156113f9573d5f5f3e3d5ffd5b50505050505050565b5f5f61141785855f01518660200151866115dc565b905080801561143457506114348686865f01518760200151611688565b1561144357600191505061149d565b82845f01516001600160a01b0316866001600160a01b03167f04b4e838f4c10490214da7937cb04250becb61b51da413f46d95246977a3787a876020015160405161149091815260200190565b60405180910390a45f9150505b949350505050565b6001600160a01b0384163b1561114e575f63db7af85460e01b84846020015185604001516040516024016114db939291906120d9565b604051602081830303815290604052906001600160e01b0319166020820180516001600160e01b0383818316178352505050509050611523858460800151612710845f611744565b6109975781856001600160a01b0316856001600160a01b03167f2eb7259b4568934933383bd30d9c0c8eac044d768edc289619560b33c94375c960405160405180910390a45050505050565b6040516323b872dd60e01b5f8181526001600160a01b038781166004528616602452604485905291602083606481808c5af1925060015f511483166115cb5783831516156115bf573d5f823e3d81fd5b5f883b113d1516831692505b604052505f60605295945050505050565b5f80546001600160a01b0316806115f757600191505061149d565b5f5a60405163013d7df360e01b81526001600160a01b038981166004830152888116602483015260448201889052606482018790529192509083169063013d7df3906084015f604051808303815f87803b158015611653575f5ffd5b505af1925050508015611664575060015b61167d5761167387825f6117fa565b5f9250505061149d565b60019250505061149d565b5f8085600181111561169c5761169c611de8565b036116b3576116ac84848461183a565b905061149d565b5f5a6040516340c10f1960e01b81526001600160a01b03868116600483015260248201869052919250908616906340c10f19906044016020604051808303815f875af1925050508015611723575060408051601f3d908101601f19168201909252611720918101906120ff565b60015b61173b5761173285825f6117fa565b5f91505061149d565b915061149d9050565b5f8084611752603f88612118565b61175c9088611eec565b6117669190611eec565b90505f5a905081811015611797576040516323e228cb60e01b8152600481018290526024810183905260440161085e565b5f8486516117a59190611e27565b90505f5f828760208a01015f8d8df19350831580156117cd57506117ca603f89612118565b5a105b156117ee57604051634de8e2d960e01b81526004810189905260240161085e565b50505095945050505050565b80611806604084612118565b6118109190611eec565b5a116105d357604051632bd9ca7960e11b81526001600160a01b038416600482015260240161085e565b5f5f5a905061ea60811161186c57604051632bd9ca7960e11b81526001600160a01b038616600482015260240161085e565b5f61187961ea6083611e27565b60405163a9059cbb60e01b5f8181526001600160a01b038916600452602488905292935091602090604481808c88f1945060015f511485166118c1575f883b113d1516851694505b604052836118d6576118d6878461ea606117fa565b5050509392505050565b6001600160a01b03811681146118f4575f5ffd5b50565b8035611902816118e0565b919050565b5f5f60408385031215611918575f5ffd5b8235611923816118e0565b946020939093013593505050565b5f5f5f60608486031215611943575f5ffd5b833561194e816118e0565b9250602084013561195e816118e0565b929592945050506040919091013590565b5f6020828403121561197f575f5ffd5b81356108cf816118e0565b5f5f83601f84011261199a575f5ffd5b5081356001600160401b038111156119b0575f5ffd5b6020830191508360208285010111156119c7575f5ffd5b9250929050565b803560ff81168114611902575f5ffd5b5f5f5f5f5f5f5f5f60c0898b0312156119f5575f5ffd5b8835611a00816118e0565b975060208901356001600160401b03811115611a1a575f5ffd5b611a268b828c0161198a565b90985096505060408901356001600160401b03811115611a44575f5ffd5b611a508b828c0161198a565b9096509450611a63905060608a016119ce565b92506080890135611a73816118e0565b979a969950949793969295919450919260a001359150565b5f5f5f5f5f5f5f5f5f5f5f6101008c8e031215611aa6575f5ffd5b611aaf8c6118f7565b9a5060208c01356001600160401b03811115611ac9575f5ffd5b611ad58e828f0161198a565b909b5099505060408c01356001600160401b03811115611af3575f5ffd5b611aff8e828f0161198a565b9099509750611b12905060608d016119ce565b9550611b2060808d016118f7565b945060a08c0135935060c08c01356001600160401b03811115611b41575f5ffd5b611b4d8e828f0161198a565b9c9f9b9e50999c989b979a969995989497959660e090950135949350505050565b5f5b83811015611b88578181015183820152602001611b70565b50505f910152565b5f8151808452611ba7816020860160208601611b6e565b601f01601f19169290920160200192915050565b602081525f6108cf6020830184611b90565b5f5f5f5f5f5f60a08789031215611be2575f5ffd5b8635611bed816118e0565b95506020870135611bfd816118e0565b94506040870135935060608701356001600160401b03811115611c1e575f5ffd5b611c2a89828a0161198a565b979a9699509497949695608090950135949350505050565b634e487b7160e01b5f52604160045260245ffd5b60405160a081016001600160401b0381118282101715611c7857611c78611c42565b60405290565b604051601f8201601f191681016001600160401b0381118282101715611ca657611ca6611c42565b604052919050565b5f6001600160401b03821115611cc657611cc6611c42565b50601f01601f191660200190565b5f82601f830112611ce3575f5ffd5b8135611cf6611cf182611cae565b611c7e565b818152846020838601011115611d0a575f5ffd5b816020850160208301375f918101602001919091529392505050565b5f5f5f60608486031215611d38575f5ffd5b8335611d43816118e0565b92506020840135915060408401356001600160401b03811115611d64575f5ffd5b611d7086828701611cd4565b9150509250925092565b5f5f5f5f5f60a08688031215611d8e575f5ffd5b8535611d99816118e0565b94506020860135611da9816118e0565b93506040860135925060608601356001600160401b03811115611dca575f5ffd5b611dd688828901611cd4565b95989497509295608001359392505050565b634e487b7160e01b5f52602160045260245ffd5b5f60208284031215611e0c575f5ffd5b5051919050565b634e487b7160e01b5f52601160045260245ffd5b8181038181111561061d5761061d611e13565b5f60208284031215611e4a575f5ffd5b81516108cf816118e0565b81835281816020850137505f828201602090810191909152601f909101601f19169091010190565b8a8152602081018a90526001600160a01b038981166040830152606082018990528716608082015261010060a082018190525f90611ebe9083018789611e55565b82810360c0840152611ed1818688611e55565b91505060ff831660e08301529b9a5050505050505050505050565b8082018082111561061d5761061d611e13565b6001600160a01b038481168252831660208201526060604082018190525f90611f2a90830184611b90565b95945050505050565b80518015158114611902575f5ffd5b5f60208284031215611f52575f5ffd5b81516001600160401b03811115611f67575f5ffd5b820160a08185031215611f78575f5ffd5b611f80611c56565b8151611f8b816118e0565b81526020820151611f9b816118e0565b602082015260408201516001600160401b03811115611fb8575f5ffd5b8201601f81018613611fc8575f5ffd5b8051611fd6611cf182611cae565b818152876020838501011115611fea575f5ffd5b611ffb826020830160208601611b6e565b60408401525061200f905060608301611f33565b6060820152608091820151918101919091529392505050565b88815260208082018990526001600160a01b038881166040808501919091528882166060850152878216608085015261010060a08086018290528851841691860191909152928701519091166101208401528501516101408301919091525f906120966101a0840182611b90565b6060870151151561016085015260808701516101808501526001600160a01b03861660c085015291506120c69050565b8260e08301529998505050505050505050565b60018060a01b0384168152826020820152606060408201525f611f2a6060830184611b90565b5f6020828403121561210f575f5ffd5b6108cf82611f33565b5f8261213257634e487b7160e01b5f52601260045260245ffd5b50049056fe9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f000000000000000000000000005897d3de91d59fb691e3887d6ffbba072384293a000000000000000000000000571f96605921f76a24cf1388c2caf126b15b09f700000000000000000000000000000000000000000000000000000000000000000000000000000000000000002436b1826a4879e90b565638147fe1c5c24364e5

Deployed ByteCode

0x608060405234801561000f575f5ffd5b50600436106101bb575f3560e01c8063871c0760116100f3578063c2173d4311610093578063e77772fe1161006e578063e77772fe1461048b578063e9518196146104b2578063f248fbcf146104d9578063f43589fd146104ec575f5ffd5b8063c2173d431461040d578063cd5965831461043f578063d0d9975a14610466575f5ffd5b80639d613974116100ce5780639d613974146103ad578063a4c0ed36146103b5578063ad58bdd1146103c8578063ae813e9f146103db575f5ffd5b8063871c076014610355578063922341341461037c5780639cb7595a1461038f575f5ffd5b80632d70061f1161015e578063555d284811610139578063555d2848146102e557806361c04f84146102f7578063631c2bb81461031f578063845a7e161461034c575f5ffd5b80632d70061f1461028757806333a2fd29146102c7578063437764df146102d0575f5ffd5b806326aa101f1161019957806326aa101f1461022b578063272255bb1461024e5780632ae87cdd146102615780632cc90da514610274575f5ffd5b806301e4f53a146101bf578063125e4cfb146101d4578063194153d3146101e7575b5f5ffd5b6101d26101cd366004611907565b6104ff565b005b6101d26101e2366004611931565b610573565b6102186101f536600461196f565b6001600160a01b03165f908152600360205260409020546001600160f01b031690565b6040519081526020015b60405180910390f35b61023e61023936600461196f565b6105d8565b6040519015158152602001610222565b6101d261025c366004611931565b610623565b6101d261026f3660046119de565b610683565b6101d2610282366004611a8b565b610701565b6102af61029536600461196f565b60016020525f90815260409020546001600160a01b031681565b6040516001600160a01b039091168152602001610222565b61021861271081565b6040516358a8b61360e11b8152602001610222565b5f546102af906001600160a01b031681565b6102af61030536600461196f565b60026020525f90815260409020546001600160a01b031681565b61033f604051806040016040528060018152602001603d60f91b81525081565b6040516102229190611bbb565b61021861ea6081565b6102af7f000000000000000000000000571f96605921f76a24cf1388c2caf126b15b09f781565b6101d261038a366004611bcd565b610798565b60408051600380825260208201525f91810191909152606001610222565b6101d2610835565b61023e6103c3366004611d26565b6108aa565b6101d26103d6366004611931565b6108d6565b61023e6103e936600461196f565b6001600160a01b03165f90815260036020526040902054600160f81b900460ff1690565b61023e61041b36600461196f565b6001600160a01b03165f90815260036020526040902054600160f01b900460ff1690565b6102af7f0000000000000000000000005897d3de91d59fb691e3887d6ffbba072384293a81565b61033f60405180604001604052806006815260200165010333937b6960d51b81525081565b6102af7f0000000000000000000000002436b1826a4879e90b565638147fe1c5c24364e581565b6102187f0000000000000000000000000000000000000000000000000000000000aa36a781565b6101d26104e7366004611d7a565b610946565b6101d26104fa366004611d7a565b61099e565b6105076109ef565b6105596040518060a00160405280846001600160a01b03168152602001336001600160a01b0316815260200160405180602001604052805f81525081526020015f151581526020015f81525082610a0a565b61056f60015f5160206121385f395f51905f5255565b5050565b61057b610b50565b6105d3836040518060a00160405280856001600160a01b0316815260200184815260200160405180602001604052805f81525081526020015f60018111156105c5576105c5611de8565b81526020015f815250610d50565b505050565b6001600160a01b0381165f90815260036020526040812054600160f01b900460ff168061061d57506001600160a01b038281165f908152600260205260409020541615155b92915050565b61062b610b50565b6105d3836040518060a00160405280856001600160a01b0316815260200184815260200160405180602001604052805f81525081526020015f600181111561067557610675611de8565b81526020015f815250610d9f565b61068b610b50565b5f61069a898989898989610e72565b90506106f66001826040518060a00160405280876001600160a01b0316815260200186815260200160405180602001604052805f81525081526020015f60018111156106e8576106e8611de8565b81526020015f815250610f49565b505050505050505050565b610709610b50565b5f6107188c8c8c8c8c8c610e72565b905061078a6001826040518060a001604052808a6001600160a01b0316815260200189815260200188888080601f0160208091040260200160405190810160405280939291908181526020018383808284375f9201919091525050509082525060200160018152602001869052610f49565b505050505050505050505050565b6107a06109ef565b6108176040518060a00160405280886001600160a01b03168152602001876001600160a01b0316815260200185858080601f0160208091040260200160405190810160405280939291908181526020018383808284375f920191909152505050908252506001602082015260400183905285610a0a565b61082d60015f5160206121385f395f51905f5255565b505050505050565b5f546001600160a01b031633811461086757604051630a9e172560e11b81523360048201526024015b60405180910390fd5b5f80546001600160a01b03191681556040516001600160a01b038316917f3f470988d5908fe18d1ef712a2aaea40f5beee6037de03d63857a91049e52ee591a250565b6004545f9060ff16156108bf575060016108cf565b6108cb33858585611154565b5060015b9392505050565b6108de6109ef565b6109306040518060a00160405280856001600160a01b03168152602001846001600160a01b0316815260200160405180602001604052805f81525081526020015f151581526020015f81525082610a0a565b6105d360015f5160206121385f395f51905f5255565b61094e610b50565b610997856040518060a00160405280876001600160a01b0316815260200186815260200185815260200160018081111561098a5761098a611de8565b8152602001849052610d50565b5050505050565b6109a6610b50565b610997856040518060a00160405280876001600160a01b031681526020018681526020018581526020016001808111156109e2576109e2611de8565b8152602001849052610d9f565b6109f76112d9565b60025f5160206121385f395f51905f5255565b81516040516370a0823160e01b81523060048201525f906001600160a01b038316906370a0823190602401602060405180830381865afa158015610a50573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610a749190611dfc565b6004805460ff191660011790559050610a986001600160a01b03831633308661130a565b6004805460ff191681556040516370a0823160e01b815230918101919091525f9082906001600160a01b038516906370a0823190602401602060405180830381865afa158015610aea573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610b0e9190611dfc565b610b189190611e27565b905083811115610b45576040516359542aa560e01b8152600481018290526024810185905260440161085e565b610997853383611340565b7f0000000000000000000000005897d3de91d59fb691e3887d6ffbba072384293a336001600160a01b03821614610b9c57604051637c8da0cf60e11b815233600482015260240161085e565b5f816001600160a01b031663d67bdd256040518163ffffffff1660e01b8152600401602060405180830381865afa158015610bd9573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610bfd9190611e3a565b90507f000000000000000000000000571f96605921f76a24cf1388c2caf126b15b09f76001600160a01b0316816001600160a01b031614610c845760405163453324b160e01b81526001600160a01b037f000000000000000000000000571f96605921f76a24cf1388c2caf126b15b09f7811660048301528216602482015260440161085e565b5f826001600160a01b0316639e307dff6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610cc1573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610ce59190611dfc565b90507f0000000000000000000000000000000000000000000000000000000000aa36a781146105d35760405163344de78960e01b81527f0000000000000000000000000000000000000000000000000000000000aa36a760048201526024810182905260440161085e565b6001600160a01b038083165f908152600160205260409020541680610d93576040516317b01ef760e21b81526001600160a01b038416600482015260240161085e565b6105d360018284610f49565b6001600160a01b0382165f90815260036020908152604091829020825160608101845290546001600160f01b038116825260ff600160f01b82048116151593830193909352600160f81b9004909116151591810182905290610e6757600160408083019182526001600160a01b0385165f90815260036020908152919020835181549285015193511515600160f81b026001600160f81b03941515600160f01b026001600160f81b03199094166001600160f01b039092169190911792909217929092161790555b6105d35f8484610f49565b604051631cf605af60e01b81525f90731e68160762061624bb5fa31d589a8f31c3e44bc590631cf605af90610eff906001906002907f0000000000000000000000002436b1826a4879e90b565638147fe1c5c24364e5907f0000000000000000000000000000000000000000000000000000000000aa36a7908e908e908e908e908e908e90600401611e7d565b602060405180830381865af4158015610f1a573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610f3e9190611e3a565b979650505050505050565b60045460ff1615610f6d5760405163e065483960e01b815260040160405180910390fd5b5f7f0000000000000000000000005897d3de91d59fb691e3887d6ffbba072384293a6001600160a01b031663669f618b6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610fca573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610fee9190611dfc565b90505f84600181111561100357611003611de8565b036110b8576001600160a01b0383165f90815260036020908152604090912054908301516001600160f01b03909116908110156110725760208301516040516314bd39c360e21b81526001600160a01b038616600482015260248101839052604481019190915260640161085e565b60208301516110819082611e27565b6001600160a01b0385165f90815260036020526040902080546001600160f01b0319166001600160f01b0392909216919091179055505b6110c484848484611402565b6110ce5750505050565b80825f01516001600160a01b0316846001600160a01b03167f9afd47907e25028cdaca89d193518c302bbb128617d5a992c5abd45815526593856020015160405161111b91815260200190565b60405180910390a460018260600151600181111561113b5761113b611de8565b0361114e57815161114e908484846114a5565b50505050565b61115c6109ef565b6001600160a01b0384165f818152600360205260408082205490516370a0823160e01b81523060048201526001600160f01b0390911692906370a0823190602401602060405180830381865afa1580156111b8573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906111dc9190611dfc565b90506111e88483611eec565b81101561123a5785848383116111fe575f611208565b6112088484611e27565b604051633b12021b60e11b81526001600160a01b0390931660048401526024830191909152604482015260640161085e565b6040516307d73aa560e21b81526112c190731e68160762061624bb5fa31d589a8f31c3e44bc590631f5cea9490611279908a908a908990600401611eff565b5f60405180830381865af4158015611293573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f191682016040526112ba9190810190611f42565b8686611340565b505061114e60015f5160206121385f395f51905f5255565b5f5160206121385f395f51905f525460020361130857604051633ee5aeb560e01b815260040160405180910390fd5b565b61131884848484600161156f565b61114e57604051635274afe760e01b81526001600160a01b038516600482015260240161085e565b5f54604051630be7c76f60e21b8152731e68160762061624bb5fa31d589a8f31c3e44bc591632f9f1dbc916113d1916003916002917f0000000000000000000000005897d3de91d59fb691e3887d6ffbba072384293a917f000000000000000000000000571f96605921f76a24cf1388c2caf126b15b09f7916001600160a01b0316908b908b908b90600401612028565b5f6040518083038186803b1580156113e7575f5ffd5b505af41580156113f9573d5f5f3e3d5ffd5b50505050505050565b5f5f61141785855f01518660200151866115dc565b905080801561143457506114348686865f01518760200151611688565b1561144357600191505061149d565b82845f01516001600160a01b0316866001600160a01b03167f04b4e838f4c10490214da7937cb04250becb61b51da413f46d95246977a3787a876020015160405161149091815260200190565b60405180910390a45f9150505b949350505050565b6001600160a01b0384163b1561114e575f63db7af85460e01b84846020015185604001516040516024016114db939291906120d9565b604051602081830303815290604052906001600160e01b0319166020820180516001600160e01b0383818316178352505050509050611523858460800151612710845f611744565b6109975781856001600160a01b0316856001600160a01b03167f2eb7259b4568934933383bd30d9c0c8eac044d768edc289619560b33c94375c960405160405180910390a45050505050565b6040516323b872dd60e01b5f8181526001600160a01b038781166004528616602452604485905291602083606481808c5af1925060015f511483166115cb5783831516156115bf573d5f823e3d81fd5b5f883b113d1516831692505b604052505f60605295945050505050565b5f80546001600160a01b0316806115f757600191505061149d565b5f5a60405163013d7df360e01b81526001600160a01b038981166004830152888116602483015260448201889052606482018790529192509083169063013d7df3906084015f604051808303815f87803b158015611653575f5ffd5b505af1925050508015611664575060015b61167d5761167387825f6117fa565b5f9250505061149d565b60019250505061149d565b5f8085600181111561169c5761169c611de8565b036116b3576116ac84848461183a565b905061149d565b5f5a6040516340c10f1960e01b81526001600160a01b03868116600483015260248201869052919250908616906340c10f19906044016020604051808303815f875af1925050508015611723575060408051601f3d908101601f19168201909252611720918101906120ff565b60015b61173b5761173285825f6117fa565b5f91505061149d565b915061149d9050565b5f8084611752603f88612118565b61175c9088611eec565b6117669190611eec565b90505f5a905081811015611797576040516323e228cb60e01b8152600481018290526024810183905260440161085e565b5f8486516117a59190611e27565b90505f5f828760208a01015f8d8df19350831580156117cd57506117ca603f89612118565b5a105b156117ee57604051634de8e2d960e01b81526004810189905260240161085e565b50505095945050505050565b80611806604084612118565b6118109190611eec565b5a116105d357604051632bd9ca7960e11b81526001600160a01b038416600482015260240161085e565b5f5f5a905061ea60811161186c57604051632bd9ca7960e11b81526001600160a01b038616600482015260240161085e565b5f61187961ea6083611e27565b60405163a9059cbb60e01b5f8181526001600160a01b038916600452602488905292935091602090604481808c88f1945060015f511485166118c1575f883b113d1516851694505b604052836118d6576118d6878461ea606117fa565b5050509392505050565b6001600160a01b03811681146118f4575f5ffd5b50565b8035611902816118e0565b919050565b5f5f60408385031215611918575f5ffd5b8235611923816118e0565b946020939093013593505050565b5f5f5f60608486031215611943575f5ffd5b833561194e816118e0565b9250602084013561195e816118e0565b929592945050506040919091013590565b5f6020828403121561197f575f5ffd5b81356108cf816118e0565b5f5f83601f84011261199a575f5ffd5b5081356001600160401b038111156119b0575f5ffd5b6020830191508360208285010111156119c7575f5ffd5b9250929050565b803560ff81168114611902575f5ffd5b5f5f5f5f5f5f5f5f60c0898b0312156119f5575f5ffd5b8835611a00816118e0565b975060208901356001600160401b03811115611a1a575f5ffd5b611a268b828c0161198a565b90985096505060408901356001600160401b03811115611a44575f5ffd5b611a508b828c0161198a565b9096509450611a63905060608a016119ce565b92506080890135611a73816118e0565b979a969950949793969295919450919260a001359150565b5f5f5f5f5f5f5f5f5f5f5f6101008c8e031215611aa6575f5ffd5b611aaf8c6118f7565b9a5060208c01356001600160401b03811115611ac9575f5ffd5b611ad58e828f0161198a565b909b5099505060408c01356001600160401b03811115611af3575f5ffd5b611aff8e828f0161198a565b9099509750611b12905060608d016119ce565b9550611b2060808d016118f7565b945060a08c0135935060c08c01356001600160401b03811115611b41575f5ffd5b611b4d8e828f0161198a565b9c9f9b9e50999c989b979a969995989497959660e090950135949350505050565b5f5b83811015611b88578181015183820152602001611b70565b50505f910152565b5f8151808452611ba7816020860160208601611b6e565b601f01601f19169290920160200192915050565b602081525f6108cf6020830184611b90565b5f5f5f5f5f5f60a08789031215611be2575f5ffd5b8635611bed816118e0565b95506020870135611bfd816118e0565b94506040870135935060608701356001600160401b03811115611c1e575f5ffd5b611c2a89828a0161198a565b979a9699509497949695608090950135949350505050565b634e487b7160e01b5f52604160045260245ffd5b60405160a081016001600160401b0381118282101715611c7857611c78611c42565b60405290565b604051601f8201601f191681016001600160401b0381118282101715611ca657611ca6611c42565b604052919050565b5f6001600160401b03821115611cc657611cc6611c42565b50601f01601f191660200190565b5f82601f830112611ce3575f5ffd5b8135611cf6611cf182611cae565b611c7e565b818152846020838601011115611d0a575f5ffd5b816020850160208301375f918101602001919091529392505050565b5f5f5f60608486031215611d38575f5ffd5b8335611d43816118e0565b92506020840135915060408401356001600160401b03811115611d64575f5ffd5b611d7086828701611cd4565b9150509250925092565b5f5f5f5f5f60a08688031215611d8e575f5ffd5b8535611d99816118e0565b94506020860135611da9816118e0565b93506040860135925060608601356001600160401b03811115611dca575f5ffd5b611dd688828901611cd4565b95989497509295608001359392505050565b634e487b7160e01b5f52602160045260245ffd5b5f60208284031215611e0c575f5ffd5b5051919050565b634e487b7160e01b5f52601160045260245ffd5b8181038181111561061d5761061d611e13565b5f60208284031215611e4a575f5ffd5b81516108cf816118e0565b81835281816020850137505f828201602090810191909152601f909101601f19169091010190565b8a8152602081018a90526001600160a01b038981166040830152606082018990528716608082015261010060a082018190525f90611ebe9083018789611e55565b82810360c0840152611ed1818688611e55565b91505060ff831660e08301529b9a5050505050505050505050565b8082018082111561061d5761061d611e13565b6001600160a01b038481168252831660208201526060604082018190525f90611f2a90830184611b90565b95945050505050565b80518015158114611902575f5ffd5b5f60208284031215611f52575f5ffd5b81516001600160401b03811115611f67575f5ffd5b820160a08185031215611f78575f5ffd5b611f80611c56565b8151611f8b816118e0565b81526020820151611f9b816118e0565b602082015260408201516001600160401b03811115611fb8575f5ffd5b8201601f81018613611fc8575f5ffd5b8051611fd6611cf182611cae565b818152876020838501011115611fea575f5ffd5b611ffb826020830160208601611b6e565b60408401525061200f905060608301611f33565b6060820152608091820151918101919091529392505050565b88815260208082018990526001600160a01b038881166040808501919091528882166060850152878216608085015261010060a08086018290528851841691860191909152928701519091166101208401528501516101408301919091525f906120966101a0840182611b90565b6060870151151561016085015260808701516101808501526001600160a01b03861660c085015291506120c69050565b8260e08301529998505050505050505050565b60018060a01b0384168152826020820152606060408201525f611f2a6060830184611b90565b5f6020828403121561210f575f5ffd5b6108cf82611f33565b5f8261213257634e487b7160e01b5f52601260045260245ffd5b50049056fe9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00