creation_sourcecode: {{
    "language": "Solidity",
    "sources": {
      "contracts/upgradeable_contracts/modules/gas_limit/SelectorTokenGasLimitManager.sol": {
        "content": "pragma solidity 0.7.5;\n\nimport \"../../../interfaces/IAMB.sol\";\nimport \"../OwnableModule.sol\";\nimport \"../../BasicOmnibridge.sol\";\n\n/**\n * @title SelectorTokenGasLimitManager\n * @dev Multi token mediator functionality for managing request gas limits.\n */\ncontract SelectorTokenGasLimitManager is OwnableModule {\n    IAMB public immutable bridge;\n\n    uint256 internal defaultGasLimit;\n    mapping(bytes4 => uint256) internal selectorGasLimit;\n    mapping(bytes4 => mapping(address => uint256)) internal selectorTokenGasLimit;\n\n    constructor(\n        IAMB _bridge,\n        address _owner,\n        uint256 _gasLimit\n    ) OwnableModule(_owner) {\n        require(_gasLimit <= _bridge.maxGasPerTx());\n        bridge = _bridge;\n        defaultGasLimit = _gasLimit;\n    }\n\n    /**\n     * @dev Tells the module interface version that this contract supports.\n     * @return major value of the version\n     * @return minor value of the version\n     * @return patch value of the version\n     */\n    function getModuleInterfacesVersion()\n        external\n        pure\n        returns (\n            uint64 major,\n            uint64 minor,\n            uint64 patch\n        )\n    {\n        return (1, 0, 0);\n    }\n\n    /**\n     * @dev Throws if provided gas limit is greater then the maximum allowed gas limit in the AMB contract.\n     * @param _gasLimit gas limit value to check.\n     */\n    modifier validGasLimit(uint256 _gasLimit) {\n        require(_gasLimit <= bridge.maxGasPerTx());\n        _;\n    }\n\n    /**\n     * @dev Throws if one of the provided gas limits is greater then the maximum allowed gas limit in the AMB contract.\n     * @param _length expected length of the _gasLimits array.\n     * @param _gasLimits array of gas limit values to check, should contain exactly _length elements.\n     */\n    modifier validGasLimits(uint256 _length, uint256[] calldata _gasLimits) {\n        require(_gasLimits.length == _length);\n        uint256 maxGasLimit = bridge.maxGasPerTx();\n        for (uint256 i = 0; i < _length; i++) {\n            require(_gasLimits[i] <= maxGasLimit);\n        }\n        _;\n    }\n\n    /**\n     * @dev Sets the default gas limit to be used in the message execution by the AMB bridge on the other network.\n     * This value can't exceed the parameter maxGasPerTx defined on the AMB bridge.\n     * Only the owner can call this method.\n     * @param _gasLimit the gas limit for the message execution.\n     */\n    function setRequestGasLimit(uint256 _gasLimit) external onlyOwner validGasLimit(_gasLimit) {\n        defaultGasLimit = _gasLimit;\n    }\n\n    /**\n     * @dev Sets the selector-specific gas limit to be used in the message execution by the AMB bridge on the other network.\n     * This value can't exceed the parameter maxGasPerTx defined on the AMB bridge.\n     * Only the owner can call this method.\n     * @param _selector method selector of the outgoing message payload.\n     * @param _gasLimit the gas limit for the message execution.\n     */\n    function setRequestGasLimit(bytes4 _selector, uint256 _gasLimit) external onlyOwner validGasLimit(_gasLimit) {\n        selectorGasLimit[_selector] = _gasLimit;\n    }\n\n    /**\n     * @dev Sets the token-specific gas limit to be used in the message execution by the AMB bridge on the other network.\n     * This value can't exceed the parameter maxGasPerTx defined on the AMB bridge.\n     * Only the owner can call this method.\n     * @param _selector method selector of the outgoing message payload.\n     * @param _token address of the native token that is used in the first argument of handleBridgedTokens/handleNativeTokens.\n     * @param _gasLimit the gas limit for the message execution.\n     */\n    function setRequestGasLimit(\n        bytes4 _selector,\n        address _token,\n        uint256 _gasLimit\n    ) external onlyOwner validGasLimit(_gasLimit) {\n        selectorTokenGasLimit[_selector][_token] = _gasLimit;\n    }\n\n    /**\n     * @dev Tells the default gas limit to be used in the message execution by the AMB bridge on the other network.\n     * @return the gas limit for the message execution.\n     */\n    function requestGasLimit() public view returns (uint256) {\n        return defaultGasLimit;\n    }\n\n    /**\n     * @dev Tells the selector-specific gas limit to be used in the message execution by the AMB bridge on the other network.\n     * @param _selector method selector for the passed message.\n     * @return the gas limit for the message execution.\n     */\n    function requestGasLimit(bytes4 _selector) public view returns (uint256) {\n        return selectorGasLimit[_selector];\n    }\n\n    /**\n     * @dev Tells the token-specific gas limit to be used in the message execution by the AMB bridge on the other network.\n     * @param _selector method selector for the passed message.\n     * @param _token address of the native token that is used in the first argument of handleBridgedTokens/handleNativeTokens.\n     * @return the gas limit for the message execution.\n     */\n    function requestGasLimit(bytes4 _selector, address _token) public view returns (uint256) {\n        return selectorTokenGasLimit[_selector][_token];\n    }\n\n    /**\n     * @dev Tells the gas limit to use for the message execution by the AMB bridge on the other network.\n     * @param _data calldata to be used on the other side of the bridge, when execution a message.\n     * @return the gas limit for the message execution.\n     */\n    function requestGasLimit(bytes memory _data) external view returns (uint256) {\n        bytes4 selector;\n        address token;\n        assembly {\n            // first 4 bytes of _data contain the selector of the function to be called on the other side of the bridge.\n            // mload(add(_data, 4)) loads selector to the 28-31 bytes of the word.\n            // shl(28 * 8, x) then used to correct the padding of the selector, putting it to 0-3 bytes of the word.\n            selector := shl(224, mload(add(_data, 4)))\n            // handleBridgedTokens/handleNativeTokens/... passes bridged token address as the first parameter.\n            // it is located in the 4-35 bytes of the calldata.\n            // 36 = bytes length padding (32) + selector length (4)\n            token := mload(add(_data, 36))\n        }\n        uint256 gasLimit = selectorTokenGasLimit[selector][token];\n        if (gasLimit == 0) {\n            gasLimit = selectorGasLimit[selector];\n            if (gasLimit == 0) {\n                gasLimit = defaultGasLimit;\n            }\n        }\n        return gasLimit;\n    }\n\n    /**\n     * @dev Sets the default values for different Omnibridge selectors.\n     * @param _gasLimits array with 7 gas limits for the following selectors of the outgoing messages:\n     * - deployAndHandleBridgedTokens, deployAndHandleBridgedTokensAndCall\n     * - handleBridgedTokens, handleBridgedTokensAndCall\n     * - handleNativeTokens, handleNativeTokensAndCall\n     * - fixFailedMessage\n     * Only the owner can call this method.\n     */\n    function setCommonRequestGasLimits(uint256[] calldata _gasLimits) external onlyOwner validGasLimits(7, _gasLimits) {\n        require(_gasLimits[1] >= _gasLimits[0]);\n        require(_gasLimits[3] >= _gasLimits[2]);\n        require(_gasLimits[5] >= _gasLimits[4]);\n        require(_gasLimits[0] >= _gasLimits[2]);\n        require(_gasLimits[1] >= _gasLimits[3]);\n        selectorGasLimit[BasicOmnibridge.deployAndHandleBridgedTokens.selector] = _gasLimits[0];\n        selectorGasLimit[BasicOmnibridge.deployAndHandleBridgedTokensAndCall.selector] = _gasLimits[1];\n        selectorGasLimit[BasicOmnibridge.handleBridgedTokens.selector] = _gasLimits[2];\n        selectorGasLimit[BasicOmnibridge.handleBridgedTokensAndCall.selector] = _gasLimits[3];\n        selectorGasLimit[BasicOmnibridge.handleNativeTokens.selector] = _gasLimits[4];\n        selectorGasLimit[BasicOmnibridge.handleNativeTokensAndCall.selector] = _gasLimits[5];\n        selectorGasLimit[FailedMessagesProcessor.fixFailedMessage.selector] = _gasLimits[6];\n    }\n\n    /**\n     * @dev Sets the request gas limits for some specific token bridged from Foreign side of the bridge.\n     * @param _token address of the native token contract on the Foreign side.\n     * @param _gasLimits array with 2 gas limits for the following selectors of the outgoing messages:\n     * - handleNativeTokens, handleNativeTokensAndCall\n     * Only the owner can call this method.\n     */\n    function setBridgedTokenRequestGasLimits(address _token, uint256[] calldata _gasLimits)\n        external\n        onlyOwner\n        validGasLimits(2, _gasLimits)\n    {\n        require(_gasLimits[1] >= _gasLimits[0]);\n        selectorTokenGasLimit[BasicOmnibridge.handleNativeTokens.selector][_token] = _gasLimits[0];\n        selectorTokenGasLimit[BasicOmnibridge.handleNativeTokensAndCall.selector][_token] = _gasLimits[1];\n    }\n\n    /**\n     * @dev Sets the request gas limits for some specific token native to the Home side of the bridge.\n     * @param _token address of the native token contract on the Home side.\n     * @param _gasLimits array with 4 gas limits for the following selectors of the outgoing messages:\n     * - deployAndHandleBridgedTokens, deployAndHandleBridgedTokensAndCall\n     * - handleBridgedTokens, handleBridgedTokensAndCall\n     * Only the owner can call this method.\n     */\n    function setNativeTokenRequestGasLimits(address _token, uint256[] calldata _gasLimits)\n        external\n        onlyOwner\n        validGasLimits(4, _gasLimits)\n    {\n        require(_gasLimits[1] >= _gasLimits[0]);\n        require(_gasLimits[3] >= _gasLimits[2]);\n        require(_gasLimits[0] >= _gasLimits[2]);\n        require(_gasLimits[1] >= _gasLimits[3]);\n        selectorTokenGasLimit[BasicOmnibridge.deployAndHandleBridgedTokens.selector][_token] = _gasLimits[0];\n        selectorTokenGasLimit[BasicOmnibridge.deployAndHandleBridgedTokensAndCall.selector][_token] = _gasLimits[1];\n        selectorTokenGasLimit[BasicOmnibridge.handleBridgedTokens.selector][_token] = _gasLimits[2];\n        selectorTokenGasLimit[BasicOmnibridge.handleBridgedTokensAndCall.selector][_token] = _gasLimits[3];\n    }\n}\n"
      },
      "contracts/interfaces/IAMB.sol": {
        "content": "pragma solidity 0.7.5;\n\ninterface IAMB {\n    event UserRequestForAffirmation(bytes32 indexed messageId, bytes encodedData);\n    event UserRequestForSignature(bytes32 indexed messageId, bytes encodedData);\n    event AffirmationCompleted(\n        address indexed sender,\n        address indexed executor,\n        bytes32 indexed messageId,\n        bool status\n    );\n    event RelayedMessage(address indexed sender, address indexed executor, bytes32 indexed messageId, bool status);\n\n    function messageSender() external view returns (address);\n\n    function maxGasPerTx() external view returns (uint256);\n\n    function transactionHash() external view returns (bytes32);\n\n    function messageId() external view returns (bytes32);\n\n    function messageSourceChainId() external view returns (bytes32);\n\n    function messageCallStatus(bytes32 _messageId) external view returns (bool);\n\n    function failedMessageDataHash(bytes32 _messageId) external view returns (bytes32);\n\n    function failedMessageReceiver(bytes32 _messageId) external view returns (address);\n\n    function failedMessageSender(bytes32 _messageId) external view returns (address);\n\n    function requireToPassMessage(\n        address _contract,\n        bytes calldata _data,\n        uint256 _gas\n    ) external returns (bytes32);\n\n    function requireToConfirmMessage(\n        address _contract,\n        bytes calldata _data,\n        uint256 _gas\n    ) external returns (bytes32);\n\n    function sourceChainId() external view returns (uint256);\n\n    function destinationChainId() external view returns (uint256);\n}\n"
      },
      "contracts/upgradeable_contracts/BasicOmnibridge.sol": {
        "content": "pragma solidity 0.7.5;\n\nimport \"@openzeppelin/contracts/math/SafeMath.sol\";\nimport \"./Initializable.sol\";\nimport \"./Upgradeable.sol\";\nimport \"./Claimable.sol\";\nimport \"./components/bridged/BridgedTokensRegistry.sol\";\nimport \"./components/native/NativeTokensRegistry.sol\";\nimport \"./components/native/MediatorBalanceStorage.sol\";\nimport \"./components/common/TokensRelayer.sol\";\nimport \"./components/common/OmnibridgeInfo.sol\";\nimport \"./components/common/TokensBridgeLimits.sol\";\nimport \"./components/common/FailedMessagesProcessor.sol\";\nimport \"./modules/factory/TokenFactoryConnector.sol\";\nimport \"../interfaces/IBurnableMintableERC677Token.sol\";\nimport \"../interfaces/IERC20Metadata.sol\";\nimport \"../interfaces/IERC20Receiver.sol\";\nimport \"../libraries/TokenReader.sol\";\nimport \"../libraries/SafeMint.sol\";\n\n/**\n * @title BasicOmnibridge\n * @dev Common functionality for multi-token mediator intended to work on top of AMB bridge.\n */\nabstract contract BasicOmnibridge is\n    Initializable,\n    Upgradeable,\n    Claimable,\n    OmnibridgeInfo,\n    TokensRelayer,\n    FailedMessagesProcessor,\n    BridgedTokensRegistry,\n    NativeTokensRegistry,\n    MediatorBalanceStorage,\n    TokenFactoryConnector,\n    TokensBridgeLimits\n{\n    using SafeERC20 for IERC677;\n    using SafeMint for IBurnableMintableERC677Token;\n    using SafeMath for uint256;\n\n    // Workaround for storing variable up-to-32 bytes suffix\n    uint256 private immutable SUFFIX_SIZE;\n    bytes32 private immutable SUFFIX;\n\n    // Since contract is intended to be deployed under EternalStorageProxy, only constant and immutable variables can be set here\n    constructor(string memory _suffix) {\n        require(bytes(_suffix).length <= 32);\n        bytes32 suffix;\n        assembly {\n            suffix := mload(add(_suffix, 32))\n        }\n        SUFFIX = suffix;\n        SUFFIX_SIZE = bytes(_suffix).length;\n    }\n\n    /**\n     * @dev Handles the bridged tokens for the first time, includes deployment of new TokenProxy contract.\n     * Checks that the value is inside the execution limits and invokes the Mint or Unlock accordingly.\n     * @param _token address of the native ERC20/ERC677 token on the other side.\n     * @param _name name of the native token, name suffix will be appended, if empty, symbol will be used instead.\n     * @param _symbol symbol of the bridged token, if empty, name will be used instead.\n     * @param _decimals decimals of the bridge foreign token.\n     * @param _recipient address that will receive the tokens.\n     * @param _value amount of tokens to be received.\n     */\n    function deployAndHandleBridgedTokens(\n        address _token,\n        string calldata _name,\n        string calldata _symbol,\n        uint8 _decimals,\n        address _recipient,\n        uint256 _value\n    ) external onlyMediator {\n        address bridgedToken = _getBridgedTokenOrDeploy(_token, _name, _symbol, _decimals);\n\n        _handleTokens(bridgedToken, false, _recipient, _value);\n    }\n\n    /**\n     * @dev Handles the bridged tokens for the first time, includes deployment of new TokenProxy contract.\n     * Executes a callback on the receiver.\n     * Checks that the value is inside the execution limits and invokes the Mint accordingly.\n     * @param _token address of the native ERC20/ERC677 token on the other side.\n     * @param _name name of the native token, name suffix will be appended, if empty, symbol will be used instead.\n     * @param _symbol symbol of the bridged token, if empty, name will be used instead.\n     * @param _decimals decimals of the bridge foreign token.\n     * @param _recipient address that will receive the tokens.\n     * @param _value amount of tokens to be received.\n     * @param _data additional data passed from the other chain.\n     */\n    function deployAndHandleBridgedTokensAndCall(\n        address _token,\n        string calldata _name,\n        string calldata _symbol,\n        uint8 _decimals,\n        address _recipient,\n        uint256 _value,\n        bytes calldata _data\n    ) external onlyMediator {\n        address bridgedToken = _getBridgedTokenOrDeploy(_token, _name, _symbol, _decimals);\n\n        _handleTokens(bridgedToken, false, _recipient, _value);\n\n        _receiverCallback(_recipient, bridgedToken, _value, _data);\n    }\n\n    /**\n     * @dev Handles the bridged tokens for the already registered token pair.\n     * Checks that the value is inside the execution limits and invokes the Mint accordingly.\n     * @param _token address of the native ERC20/ERC677 token on the other side.\n     * @param _recipient address that will receive the tokens.\n     * @param _value amount of tokens to be received.\n     */\n    function handleBridgedTokens(\n        address _token,\n        address _recipient,\n        uint256 _value\n    ) external onlyMediator {\n        address token = bridgedTokenAddress(_token);\n\n        require(isTokenRegistered(token));\n\n        _handleTokens(token, false, _recipient, _value);\n    }\n\n    /**\n     * @dev Handles the bridged tokens for the already registered token pair.\n     * Checks that the value is inside the execution limits and invokes the Unlock accordingly.\n     * Executes a callback on the receiver.\n     * @param _token address of the native ERC20/ERC677 token on the other side.\n     * @param _recipient address that will receive the tokens.\n     * @param _value amount of tokens to be received.\n     * @param _data additional transfer data passed from the other side.\n     */\n    function handleBridgedTokensAndCall(\n        address _token,\n        address _recipient,\n        uint256 _value,\n        bytes memory _data\n    ) external onlyMediator {\n        address token = bridgedTokenAddress(_token);\n\n        require(isTokenRegistered(token));\n\n        _handleTokens(token, false, _recipient, _value);\n\n        _receiverCallback(_recipient, token, _value, _data);\n    }\n\n    /**\n     * @dev Handles the bridged tokens that are native to this chain.\n     * Checks that the value is inside the execution limits and invokes the Unlock accordingly.\n     * @param _token native ERC20 token.\n     * @param _recipient address that will receive the tokens.\n     * @param _value amount of tokens to be received.\n     */\n    function handleNativeTokens(\n        address _token,\n        address _recipient,\n        uint256 _value\n    ) external onlyMediator {\n        _ackBridgedTokenDeploy(_token);\n\n        _handleTokens(_token, true, _recipient, _value);\n    }\n\n    /**\n     * @dev Handles the bridged tokens that are native to this chain.\n     * Checks that the value is inside the execution limits and invokes the Unlock accordingly.\n     * Executes a callback on the receiver.\n     * @param _token native ERC20 token.\n     * @param _recipient address that will receive the tokens.\n     * @param _value amount of tokens to be received.\n     * @param _data additional transfer data passed from the other side.\n     */\n    function handleNativeTokensAndCall(\n        address _token,\n        address _recipient,\n        uint256 _value,\n        bytes memory _data\n    ) external onlyMediator {\n        _ackBridgedTokenDeploy(_token);\n\n        _handleTokens(_token, true, _recipient, _value);\n\n        _receiverCallback(_recipient, _token, _value, _data);\n    }\n\n    /**\n     * @dev Checks if a given token is a bridged token that is native to this side of the bridge.\n     * @param _token address of token contract.\n     * @return message id of the send message.\n     */\n    function isRegisteredAsNativeToken(address _token) public view returns (bool) {\n        return isTokenRegistered(_token) && nativeTokenAddress(_token) == address(0);\n    }\n\n    /**\n     * @dev Unlock back the amount of tokens that were bridged to the other network but failed.\n     * @param _token address that bridged token contract.\n     * @param _recipient address that will receive the tokens.\n     * @param _value amount of tokens to be received.\n     */\n    function executeActionOnFixedTokens(\n        address _token,\n        address _recipient,\n        uint256 _value\n    ) internal override {\n        _releaseTokens(nativeTokenAddress(_token) == address(0), _token, _recipient, _value, _value);\n    }\n\n    /**\n     * @dev Allows to pre-set the bridged token contract for not-yet bridged token.\n     * Only the owner can call this method.\n     * @param _nativeToken address of the token contract on the other side that was not yet bridged.\n     * @param _bridgedToken address of the bridged token contract.\n     */\n    function setCustomTokenAddressPair(address _nativeToken, address _bridgedToken) external onlyOwner {\n        require(!isTokenRegistered(_bridgedToken));\n        require(nativeTokenAddress(_bridgedToken) == address(0));\n        require(bridgedTokenAddress(_nativeToken) == address(0));\n        // Unfortunately, there is no simple way to verify that the _nativeToken address\n        // does not belong to the bridged token on the other side,\n        // since information about bridged tokens addresses is not transferred back.\n        // Therefore, owner account calling this function SHOULD manually verify on the other side of the bridge that\n        // nativeTokenAddress(_nativeToken) == address(0) && isTokenRegistered(_nativeToken) == false.\n\n        IBurnableMintableERC677Token(_bridgedToken).safeMint(address(this), 1);\n        IBurnableMintableERC677Token(_bridgedToken).burn(1);\n\n        _setTokenAddressPair(_nativeToken, _bridgedToken);\n    }\n\n    /**\n     * @dev Allows to send to the other network the amount of locked tokens that can be forced into the contract\n     * without the invocation of the required methods. (e. g. regular transfer without a call to onTokenTransfer)\n     * @param _token address of the token contract.\n     * Before calling this method, it must be carefully investigated how imbalance happened\n     * in order to avoid an attempt to steal the funds from a token with double addresses\n     * (e.g. TUSD is accessible at both 0x8dd5fbCe2F6a956C3022bA3663759011Dd51e73E and 0x0000000000085d4780B73119b644AE5ecd22b376)\n     * @param _receiver the address that will receive the tokens on the other network.\n     */\n    function fixMediatorBalance(address _token, address _receiver)\n        external\n        onlyIfUpgradeabilityOwner\n        validAddress(_receiver)\n    {\n        require(isRegisteredAsNativeToken(_token));\n\n        uint256 diff = _unaccountedBalance(_token);\n        require(diff > 0);\n        uint256 available = maxAvailablePerTx(_token);\n        require(available > 0);\n        if (diff > available) {\n            diff = available;\n        }\n        addTotalSpentPerDay(_token, getCurrentDay(), diff);\n\n        bytes memory data = _prepareMessage(address(0), _token, _receiver, diff, new bytes(0));\n        bytes32 _messageId = _passMessage(data, true);\n        _recordBridgeOperation(_messageId, _token, _receiver, diff);\n    }\n\n    /**\n     * @dev Claims stuck tokens. Only unsupported tokens can be claimed.\n     * When dealing with already supported tokens, fixMediatorBalance can be used instead.\n     * @param _token address of claimed token, address(0) for native\n     * @param _to address of tokens receiver\n     */\n    function claimTokens(address _token, address _to) external onlyIfUpgradeabilityOwner {\n        // Only unregistered tokens and native coins are allowed to be claimed with the use of this function\n        require(_token == address(0) || !isTokenRegistered(_token));\n        claimValues(_token, _to);\n    }\n\n    /**\n     * @dev Withdraws erc20 tokens or native coins from the bridged token contract.\n     * Only the proxy owner is allowed to call this method.\n     * @param _bridgedToken address of the bridged token contract.\n     * @param _token address of the claimed token or address(0) for native coins.\n     * @param _to address of the tokens/coins receiver.\n     */\n    function claimTokensFromTokenContract(\n        address _bridgedToken,\n        address _token,\n        address _to\n    ) external onlyIfUpgradeabilityOwner {\n        IBurnableMintableERC677Token(_bridgedToken).claimTokens(_token, _to);\n    }\n\n    /**\n     * @dev Internal function for recording bridge operation for further usage.\n     * Recorded information is used for fixing failed requests on the other side.\n     * @param _messageId id of the sent message.\n     * @param _token bridged token address.\n     * @param _sender address of the tokens sender.\n     * @param _value bridged value.\n     */\n    function _recordBridgeOperation(\n        bytes32 _messageId,\n        address _token,\n        address _sender,\n        uint256 _value\n    ) internal {\n        setMessageToken(_messageId, _token);\n        setMessageRecipient(_messageId, _sender);\n        setMessageValue(_messageId, _value);\n\n        emit TokensBridgingInitiated(_token, _sender, _value, _messageId);\n    }\n\n    /**\n     * @dev Constructs the message to be sent to the other side. Burns/locks bridged amount of tokens.\n     * @param _nativeToken address of the native token contract.\n     * @param _token bridged token address.\n     * @param _receiver address of the tokens receiver on the other side.\n     * @param _value bridged value.\n     * @param _data additional transfer data passed from the other side.\n     */\n    function _prepareMessage(\n        address _nativeToken,\n        address _token,\n        address _receiver,\n        uint256 _value,\n        bytes memory _data\n    ) internal returns (bytes memory) {\n        bool withData = _data.length > 0 || msg.sig == this.relayTokensAndCall.selector;\n\n        // process token is native with respect to this side of the bridge\n        if (_nativeToken == address(0)) {\n            _setMediatorBalance(_token, mediatorBalance(_token).add(_value));\n\n            // process token which bridged alternative was already ACKed to be deployed\n            if (isBridgedTokenDeployAcknowledged(_token)) {\n                return\n                    withData\n                        ? abi.encodeWithSelector(\n                            this.handleBridgedTokensAndCall.selector,\n                            _token,\n                            _receiver,\n                            _value,\n                            _data\n                        )\n                        : abi.encodeWithSelector(this.handleBridgedTokens.selector, _token, _receiver, _value);\n            }\n\n            uint8 decimals = TokenReader.readDecimals(_token);\n            string memory name = TokenReader.readName(_token);\n            string memory symbol = TokenReader.readSymbol(_token);\n\n            require(bytes(name).length > 0 || bytes(symbol).length > 0);\n\n            return\n                withData\n                    ? abi.encodeWithSelector(\n                        this.deployAndHandleBridgedTokensAndCall.selector,\n                        _token,\n                        name,\n                        symbol,\n                        decimals,\n                        _receiver,\n                        _value,\n                        _data\n                    )\n                    : abi.encodeWithSelector(\n                        this.deployAndHandleBridgedTokens.selector,\n                        _token,\n                        name,\n                        symbol,\n                        decimals,\n                        _receiver,\n                        _value\n                    );\n        }\n\n        // process already known token that is bridged from other chain\n        IBurnableMintableERC677Token(_token).burn(_value);\n        return\n            withData\n                ? abi.encodeWithSelector(\n                    this.handleNativeTokensAndCall.selector,\n                    _nativeToken,\n                    _receiver,\n                    _value,\n                    _data\n                )\n                : abi.encodeWithSelector(this.handleNativeTokens.selector, _nativeToken, _receiver, _value);\n    }\n\n    /**\n     * @dev Internal function for getting minter proxy address.\n     * @param _token address of the token to mint.\n     * @return address of the minter contract that should be used for calling mint(address,uint256)\n     */\n    function _getMinterFor(address _token) internal pure virtual returns (IBurnableMintableERC677Token) {\n        return IBurnableMintableERC677Token(_token);\n    }\n\n    /**\n     * Internal function for unlocking some amount of tokens.\n     * @param _isNative true, if token is native w.r.t. to this side of the bridge.\n     * @param _token address of the token contract.\n     * @param _recipient address of the tokens receiver.\n     * @param _value amount of tokens to unlock.\n     * @param _balanceChange amount of balance to subtract from the mediator balance.\n     */\n    function _releaseTokens(\n        bool _isNative,\n        address _token,\n        address _recipient,\n        uint256 _value,\n        uint256 _balanceChange\n    ) internal virtual {\n        if (_isNative) {\n            IERC677(_token).safeTransfer(_recipient, _value);\n            _setMediatorBalance(_token, mediatorBalance(_token).sub(_balanceChange));\n        } else {\n            _getMinterFor(_token).safeMint(_recipient, _value);\n        }\n    }\n\n    /**\n     * Internal function for getting address of the bridged token. Deploys new token if necessary.\n     * @param _token address of the token contract on the other side of the bridge.\n     * @param _name name of the native token, name suffix will be appended, if empty, symbol will be used instead.\n     * @param _symbol symbol of the bridged token, if empty, name will be used instead.\n     * @param _decimals decimals of the bridge foreign token.\n     */\n    function _getBridgedTokenOrDeploy(\n        address _token,\n        string calldata _name,\n        string calldata _symbol,\n        uint8 _decimals\n    ) internal returns (address) {\n        address bridgedToken = bridgedTokenAddress(_token);\n        if (bridgedToken == address(0)) {\n            string memory name = _name;\n            string memory symbol = _symbol;\n\n            require(bytes(name).length > 0 || bytes(symbol).length > 0);\n            if (bytes(name).length == 0) {\n                name = symbol;\n            } else if (bytes(symbol).length == 0) {\n                symbol = name;\n            }\n            name = _transformName(name);\n            address _feeAddr =  transferFeeAddress();\n            uint256 _feeAmount = transferFeeAmount();\n\n            bridgedToken = tokenFactory().deploy(name, symbol, _decimals, bridgeContract().sourceChainId(), _feeAddr, _feeAmount);\n            _setTokenAddressPair(_token, bridgedToken);\n            _initializeTokenBridgeLimits(bridgedToken, _decimals);\n        } else if (!isTokenRegistered(bridgedToken)) {\n            require(IERC20Metadata(bridgedToken).decimals() == _decimals);\n            _initializeTokenBridgeLimits(bridgedToken, _decimals);\n        }\n        return bridgedToken;\n    }\n\n    /**\n     * Notifies receiving contract about the completed bridging operation.\n     * @param _recipient address of the tokens receiver.\n     * @param _token address of the bridged token.\n     * @param _value amount of tokens transferred.\n     * @param _data additional data passed to the callback.\n     */\n    function _receiverCallback(\n        address _recipient,\n        address _token,\n        uint256 _value,\n        bytes memory _data\n    ) internal {\n        if (Address.isContract(_recipient)) {\n            _recipient.call(abi.encodeWithSelector(IERC20Receiver.onTokenBridged.selector, _token, _value, _data));\n        }\n    }\n\n    /**\n     * @dev Internal function for transforming the bridged token name. Appends a side-specific suffix.\n     * @param _name bridged token from the other side.\n     * @return token name for this side of the bridge.\n     */\n    function _transformName(string memory _name) internal view returns (string memory) {\n        string memory result = string(abi.encodePacked(_name, SUFFIX));\n        uint256 size = SUFFIX_SIZE;\n        assembly {\n            mstore(result, add(mload(_name), size))\n        }\n        return result;\n    }\n\n    /**\n     * @dev Internal function for counting excess balance which is not tracked within the bridge.\n     * Represents the amount of forced tokens on this contract.\n     * @param _token address of the token contract.\n     * @return amount of excess tokens.\n     */\n    function _unaccountedBalance(address _token) internal view virtual returns (uint256) {\n        return IERC677(_token).balanceOf(address(this)).sub(mediatorBalance(_token));\n    }\n\n    function _handleTokens(\n        address _token,\n        bool _isNative,\n        address _recipient,\n        uint256 _value\n    ) internal virtual;\n}\n"
      },
      "contracts/upgradeable_contracts/modules/OwnableModule.sol": {
        "content": "pragma solidity 0.7.5;\n\nimport \"@openzeppelin/contracts/utils/Address.sol\";\n\n/**\n * @title OwnableModule\n * @dev Common functionality for multi-token extension non-upgradeable module.\n */\ncontract OwnableModule {\n    address public owner;\n\n    /**\n     * @dev Initializes this contract.\n     * @param _owner address of the owner that is allowed to perform additional actions on the particular module.\n     */\n    constructor(address _owner) {\n        owner = _owner;\n    }\n\n    /**\n     * @dev Throws if sender is not the owner of this contract.\n     */\n    modifier onlyOwner {\n        require(msg.sender == owner);\n        _;\n    }\n\n    /**\n     * @dev Changes the owner of this contract.\n     * @param _newOwner address of the new owner.\n     */\n    function transferOwnership(address _newOwner) external onlyOwner {\n        owner = _newOwner;\n    }\n}\n"
      },
      "contracts/upgradeable_contracts/Initializable.sol": {
        "content": "pragma solidity 0.7.5;\n\nimport \"../upgradeability/EternalStorage.sol\";\n\ncontract Initializable is EternalStorage {\n    bytes32 internal constant INITIALIZED = 0x0a6f646cd611241d8073675e00d1a1ff700fbf1b53fcf473de56d1e6e4b714ba; // keccak256(abi.encodePacked(\"isInitialized\"))\n\n    function setInitialize() internal {\n        boolStorage[INITIALIZED] = true;\n    }\n\n    function isInitialized() public view returns (bool) {\n        return boolStorage[INITIALIZED];\n    }\n}\n"
      },
      "contracts/upgradeable_contracts/Upgradeable.sol": {
        "content": "pragma solidity 0.7.5;\n\nimport \"../interfaces/IUpgradeabilityOwnerStorage.sol\";\n\ncontract Upgradeable {\n    /**\n     * @dev Throws if called by any account other than the upgradeability owner.\n     */\n    modifier onlyIfUpgradeabilityOwner() {\n        _onlyIfUpgradeabilityOwner();\n        _;\n    }\n\n    /**\n     * @dev Internal function for reducing onlyIfUpgradeabilityOwner modifier bytecode overhead.\n     */\n    function _onlyIfUpgradeabilityOwner() internal view {\n        require(msg.sender == IUpgradeabilityOwnerStorage(address(this)).upgradeabilityOwner());\n    }\n}\n"
      },
      "contracts/upgradeable_contracts/Claimable.sol": {
        "content": "pragma solidity 0.7.5;\n\nimport \"@openzeppelin/contracts/token/ERC20/SafeERC20.sol\";\nimport \"../libraries/AddressHelper.sol\";\n\n/**\n * @title Claimable\n * @dev Implementation of the claiming utils that can be useful for withdrawing accidentally sent tokens that are not used in bridge operations.\n */\ncontract Claimable {\n    using SafeERC20 for IERC20;\n\n    /**\n     * Throws if a given address is equal to address(0)\n     */\n    modifier validAddress(address _to) {\n        require(_to != address(0));\n        _;\n    }\n\n    /**\n     * @dev Withdraws the erc20 tokens or native coins from this contract.\n     * Caller should additionally check that the claimed token is not a part of bridge operations (i.e. that token != erc20token()).\n     * @param _token address of the claimed token or address(0) for native coins.\n     * @param _to address of the tokens/coins receiver.\n     */\n    function claimValues(address _token, address _to) internal validAddress(_to) {\n        if (_token == address(0)) {\n            claimNativeCoins(_to);\n        } else {\n            claimErc20Tokens(_token, _to);\n        }\n    }\n\n    /**\n     * @dev Internal function for withdrawing all native coins from the contract.\n     * @param _to address of the coins receiver.\n     */\n    function claimNativeCoins(address _to) internal {\n        uint256 value = address(this).balance;\n        AddressHelper.safeSendValue(payable(_to), value);\n    }\n\n    /**\n     * @dev Internal function for withdrawing all tokens of some particular ERC20 contract from this contract.\n     * @param _token address of the claimed ERC20 token.\n     * @param _to address of the tokens receiver.\n     */\n    function claimErc20Tokens(address _token, address _to) internal {\n        IERC20 token = IERC20(_token);\n        uint256 balance = token.balanceOf(address(this));\n        token.safeTransfer(_to, balance);\n    }\n}\n"
      },
      "contracts/interfaces/IBurnableMintableERC677Token.sol": {
        "content": "pragma solidity 0.7.5;\n\nimport \"./IERC677.sol\";\n\ninterface IBurnableMintableERC677Token is IERC677 {\n    function mint(address _to, uint256 _amount) external returns (bool);\n\n    function burn(uint256 _value) external;\n\n    function claimTokens(address _token, address _to) external;\n}\n"
      },
      "contracts/interfaces/IERC20Metadata.sol": {
        "content": "pragma solidity 0.7.5;\n\ninterface IERC20Metadata {\n    function name() external view returns (string memory);\n\n    function symbol() external view returns (string memory);\n\n    function decimals() external view returns (uint8);\n}\n"
      },
      "contracts/interfaces/IERC20Receiver.sol": {
        "content": "pragma solidity 0.7.5;\n\ninterface IERC20Receiver {\n    function onTokenBridged(\n        address token,\n        uint256 value,\n        bytes calldata data\n    ) external;\n}\n"
      },
      "contracts/libraries/TokenReader.sol": {
        "content": "pragma solidity 0.7.5;\n\n// solhint-disable\ninterface ITokenDetails {\n    function name() external view;\n    function NAME() external view;\n    function symbol() external view;\n    function SYMBOL() external view;\n    function decimals() external view;\n    function DECIMALS() external view;\n}\n// solhint-enable\n\n/**\n * @title TokenReader\n * @dev Helper methods for reading name/symbol/decimals parameters from ERC20 token contracts.\n */\nlibrary TokenReader {\n    /**\n     * @dev Reads the name property of the provided token.\n     * Either name() or NAME() method is used.\n     * Both, string and bytes32 types are supported.\n     * @param _token address of the token contract.\n     * @return token name as a string or an empty string if none of the methods succeeded.\n     */\n    function readName(address _token) internal view returns (string memory) {\n        (bool status, bytes memory data) = _token.staticcall(abi.encodeWithSelector(ITokenDetails.name.selector));\n        if (!status) {\n            (status, data) = _token.staticcall(abi.encodeWithSelector(ITokenDetails.NAME.selector));\n            if (!status) {\n                return \"\";\n            }\n        }\n        return _convertToString(data);\n    }\n\n    /**\n     * @dev Reads the symbol property of the provided token.\n     * Either symbol() or SYMBOL() method is used.\n     * Both, string and bytes32 types are supported.\n     * @param _token address of the token contract.\n     * @return token symbol as a string or an empty string if none of the methods succeeded.\n     */\n    function readSymbol(address _token) internal view returns (string memory) {\n        (bool status, bytes memory data) = _token.staticcall(abi.encodeWithSelector(ITokenDetails.symbol.selector));\n        if (!status) {\n            (status, data) = _token.staticcall(abi.encodeWithSelector(ITokenDetails.SYMBOL.selector));\n            if (!status) {\n                return \"\";\n            }\n        }\n        return _convertToString(data);\n    }\n\n    /**\n     * @dev Reads the decimals property of the provided token.\n     * Either decimals() or DECIMALS() method is used.\n     * @param _token address of the token contract.\n     * @return token decimals or 0 if none of the methods succeeded.\n     */\n    function readDecimals(address _token) internal view returns (uint8) {\n        (bool status, bytes memory data) = _token.staticcall(abi.encodeWithSelector(ITokenDetails.decimals.selector));\n        if (!status) {\n            (status, data) = _token.staticcall(abi.encodeWithSelector(ITokenDetails.DECIMALS.selector));\n            if (!status) {\n                return 0;\n            }\n        }\n        return abi.decode(data, (uint8));\n    }\n\n    /**\n     * @dev Internal function for converting returned value of name()/symbol() from bytes32/string to string.\n     * @param returnData data returned by the token contract.\n     * @return string with value obtained from returnData.\n     */\n    function _convertToString(bytes memory returnData) private pure returns (string memory) {\n        if (returnData.length > 32) {\n            return abi.decode(returnData, (string));\n        } else if (returnData.length == 32) {\n            bytes32 data = abi.decode(returnData, (bytes32));\n            string memory res = new string(32);\n            assembly {\n                let len := 0\n                mstore(add(res, 32), data) // save value in result string\n\n                // solhint-disable\n                for { } gt(data, 0) { len := add(len, 1) } { // until string is empty\n                    data := shl(8, data) // shift left by one symbol\n                }\n                // solhint-enable\n                mstore(res, len) // save result string length\n            }\n            return res;\n        } else {\n            return \"\";\n        }\n    }\n}\n"
      },
      "contracts/libraries/SafeMint.sol": {
        "content": "pragma solidity 0.7.5;\n\nimport \"../interfaces/IBurnableMintableERC677Token.sol\";\n\n/**\n * @title SafeMint\n * @dev Wrapper around the mint() function in all mintable tokens that verifies the return value.\n */\nlibrary SafeMint {\n    /**\n     * @dev Wrapper around IBurnableMintableERC677Token.mint() that verifies that output value is true.\n     * @param _token token contract.\n     * @param _to address of the tokens receiver.\n     * @param _value amount of tokens to mint.\n     */\n    function safeMint(\n        IBurnableMintableERC677Token _token,\n        address _to,\n        uint256 _value\n    ) internal {\n        require(_token.mint(_to, _value));\n    }\n}\n"
      },
      "contracts/upgradeable_contracts/components/bridged/BridgedTokensRegistry.sol": {
        "content": "pragma solidity 0.7.5;\n\nimport \"../../../upgradeability/EternalStorage.sol\";\n\n/**\n * @title BridgedTokensRegistry\n * @dev Functionality for keeping track of registered bridged token pairs.\n */\ncontract BridgedTokensRegistry is EternalStorage {\n    event NewTokenRegistered(address indexed nativeToken, address indexed bridgedToken);\n\n    /**\n     * @dev Retrieves address of the bridged token contract associated with a specific native token contract on the other side.\n     * @param _nativeToken address of the native token contract on the other side.\n     * @return address of the deployed bridged token contract.\n     */\n    function bridgedTokenAddress(address _nativeToken) public view returns (address) {\n        return addressStorage[keccak256(abi.encodePacked(\"homeTokenAddress\", _nativeToken))];\n    }\n\n    /**\n     * @dev Retrieves address of the native token contract associated with a specific bridged token contract.\n     * @param _bridgedToken address of the created bridged token contract on this side.\n     * @return address of the native token contract on the other side of the bridge.\n     */\n    function nativeTokenAddress(address _bridgedToken) public view returns (address) {\n        return addressStorage[keccak256(abi.encodePacked(\"foreignTokenAddress\", _bridgedToken))];\n    }\n\n    /**\n     * @dev Internal function for updating a pair of addresses for the bridged token.\n     * @param _nativeToken address of the native token contract on the other side.\n     * @param _bridgedToken address of the created bridged token contract on this side.\n     */\n    function _setTokenAddressPair(address _nativeToken, address _bridgedToken) internal {\n        addressStorage[keccak256(abi.encodePacked(\"homeTokenAddress\", _nativeToken))] = _bridgedToken;\n        addressStorage[keccak256(abi.encodePacked(\"foreignTokenAddress\", _bridgedToken))] = _nativeToken;\n\n        emit NewTokenRegistered(_nativeToken, _bridgedToken);\n    }\n}\n"
      },
      "contracts/upgradeable_contracts/components/native/NativeTokensRegistry.sol": {
        "content": "pragma solidity 0.7.5;\n\nimport \"../../../upgradeability/EternalStorage.sol\";\n\n/**\n * @title NativeTokensRegistry\n * @dev Functionality for keeping track of registered native tokens.\n */\ncontract NativeTokensRegistry is EternalStorage {\n    /**\n     * @dev Checks if for a given native token, the deployment of its bridged alternative was already acknowledged.\n     * @param _token address of native token contract.\n     * @return true, if bridged token was already deployed.\n     */\n    function isBridgedTokenDeployAcknowledged(address _token) public view returns (bool) {\n        return boolStorage[keccak256(abi.encodePacked(\"ackDeploy\", _token))];\n    }\n\n    /**\n     * @dev Acknowledges the deployment of bridged token contract on the other side.\n     * @param _token address of native token contract.\n     */\n    function _ackBridgedTokenDeploy(address _token) internal {\n        if (!boolStorage[keccak256(abi.encodePacked(\"ackDeploy\", _token))]) {\n            boolStorage[keccak256(abi.encodePacked(\"ackDeploy\", _token))] = true;\n        }\n    }\n}\n"
      },
      "contracts/upgradeable_contracts/components/native/MediatorBalanceStorage.sol": {
        "content": "pragma solidity 0.7.5;\n\nimport \"@openzeppelin/contracts/math/SafeMath.sol\";\nimport \"../../../upgradeability/EternalStorage.sol\";\n\n/**\n * @title MediatorBalanceStorage\n * @dev Functionality for storing expected mediator balance for native tokens.\n */\ncontract MediatorBalanceStorage is EternalStorage {\n    /**\n     * @dev Tells the expected token balance of the contract.\n     * @param _token address of token contract.\n     * @return the current tracked token balance of the contract.\n     */\n    function mediatorBalance(address _token) public view returns (uint256) {\n        return uintStorage[keccak256(abi.encodePacked(\"mediatorBalance\", _token))];\n    }\n\n    /**\n     * @dev Updates expected token balance of the contract.\n     * @param _token address of token contract.\n     * @param _balance the new token balance of the contract.\n     */\n    function _setMediatorBalance(address _token, uint256 _balance) internal {\n        uintStorage[keccak256(abi.encodePacked(\"mediatorBalance\", _token))] = _balance;\n    }\n}\n"
      },
      "contracts/upgradeable_contracts/components/common/TokensRelayer.sol": {
        "content": "pragma solidity 0.7.5;\n\nimport \"@openzeppelin/contracts/math/SafeMath.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/SafeERC20.sol\";\nimport \"../../../interfaces/IERC677.sol\";\nimport \"../../../libraries/Bytes.sol\";\nimport \"../../ReentrancyGuard.sol\";\nimport \"../../BasicAMBMediator.sol\";\nimport \"./TransferNativeFeeStorage.sol\";\n/**\n * @title TokensRelayer\n * @dev Functionality for bridging multiple tokens to the other side of the bridge.\n */\nabstract contract TokensRelayer is BasicAMBMediator, ReentrancyGuard, TransferNativeFeeStorage {\n    using SafeMath for uint256;\n    using SafeERC20 for IERC677;\n\n    /**\n     * @dev ERC677 transfer callback function.\n     * @param _from address of tokens sender.\n     * @param _value amount of transferred tokens.\n     * @param _data additional transfer data, can be used for passing alternative receiver address.\n     */\n    function onTokenTransfer(\n        address _from,\n        uint256 _value,\n        bytes memory _data\n    ) external returns (bool) {\n        if (!lock()) {\n            bytes memory data = new bytes(0);\n            address receiver = _from;\n            if (_data.length >= 20) {\n                receiver = Bytes.bytesToAddress(_data);\n                if (_data.length > 20) {\n                    assembly {\n                        let size := sub(mload(_data), 20)\n                        data := add(_data, 20)\n                        mstore(data, size)\n                    }\n                }\n            }\n            bridgeSpecificActionsOnTokenTransfer(msg.sender, _from, receiver, _value, data);\n        }\n        return true;\n    }\n\n    /**\n     * @dev Initiate the bridge operation for some amount of tokens from msg.sender.\n     * The user should first call Approve method of the ERC677 token.\n     * @param token bridged token contract address.\n     * @param _receiver address that will receive the native tokens on the other network.\n     * @param _value amount of tokens to be transferred to the other network.\n     */\n    function relayTokens(\n        IERC677 token,\n        address _receiver,\n        uint256 _value\n    ) external payable {\n        _relayTokens(token, _receiver, _value, new bytes(0));\n    }\n\n    /**\n     * @dev Initiate the bridge operation for some amount of tokens from msg.sender to msg.sender on the other side.\n     * The user should first call Approve method of the ERC677 token.\n     * @param token bridged token contract address.\n     * @param _value amount of tokens to be transferred to the other network.\n     */\n    function relayTokens(IERC677 token, uint256 _value) external payable {\n        _relayTokens(token, msg.sender, _value, new bytes(0));\n    }\n\n    /**\n     * @dev Initiate the bridge operation for some amount of tokens from msg.sender.\n     * The user should first call Approve method of the ERC677 token.\n     * @param token bridged token contract address.\n     * @param _receiver address that will receive the native tokens on the other network.\n     * @param _value amount of tokens to be transferred to the other network.\n     * @param _data additional transfer data to be used on the other side.\n     */\n    function relayTokensAndCall(\n        IERC677 token,\n        address _receiver,\n        uint256 _value,\n        bytes memory _data\n    ) external payable {\n        _relayTokens(token, _receiver, _value, _data);\n    }\n\n    /**\n     * @dev Validates that the token amount is inside the limits, calls transferFrom to transfer the tokens to the contract\n     * and invokes the method to burn/lock the tokens and unlock/mint the tokens on the other network.\n     * The user should first call Approve method of the ERC677 token.\n     * @param token bridge token contract address.\n     * @param _receiver address that will receive the native tokens on the other network.\n     * @param _value amount of tokens to be transferred to the other network.\n     * @param _data additional transfer data to be used on the other side.\n     */\n    function _relayTokens(\n        IERC677 token,\n        address _receiver,\n        uint256 _value,\n        bytes memory _data\n    ) internal {\n        // This lock is to prevent calling passMessage twice if a ERC677 token is used.\n        // When transferFrom is called, after the transfer, the ERC677 token will call onTokenTransfer from this contract\n        // which will call passMessage.\n        require(!lock());\n\n        uint256 balanceBefore = token.balanceOf(address(this));\n        setLock(true);\n\n        uint256 feeAmount = transferFeeAmount();\n        require(msg.value >= feeAmount);\n        address payable feeAddress = payable(transferFeeAddress());\n        require(feeAddress.send(feeAmount));\n        if (msg.value > feeAmount) {\n            require(msg.sender.send(msg.value-feeAmount));            \n        }\n\n        token.safeTransferFrom(msg.sender, address(this), _value);\n\n        setLock(false);\n        uint256 balanceDiff = token.balanceOf(address(this)).sub(balanceBefore);\n        require(balanceDiff <= _value);\n        bridgeSpecificActionsOnTokenTransfer(address(token), msg.sender, _receiver, balanceDiff, _data);\n    }\n\n    function bridgeSpecificActionsOnTokenTransfer(\n        address _token,\n        address _from,\n        address _receiver,\n        uint256 _value,\n        bytes memory _data\n    ) internal virtual;\n}"
      },
      "contracts/upgradeable_contracts/components/common/OmnibridgeInfo.sol": {
        "content": "pragma solidity 0.7.5;\n\nimport \"../../VersionableBridge.sol\";\n\n/**\n * @title OmnibridgeInfo\n * @dev Functionality for versioning Omnibridge mediator.\n */\ncontract OmnibridgeInfo is VersionableBridge {\n    event TokensBridgingInitiated(\n        address indexed token,\n        address indexed sender,\n        uint256 value,\n        bytes32 indexed messageId\n    );\n    event TokensBridged(address indexed token, address indexed recipient, uint256 value, bytes32 indexed messageId);\n\n    /**\n     * @dev Tells the bridge interface version that this contract supports.\n     * @return major value of the version\n     * @return minor value of the version\n     * @return patch value of the version\n     */\n    function getBridgeInterfacesVersion()\n        external\n        pure\n        override\n        returns (\n            uint64 major,\n            uint64 minor,\n            uint64 patch\n        )\n    {\n        return (3, 3, 0);\n    }\n\n    /**\n     * @dev Tells the bridge mode that this contract supports.\n     * @return _data 4 bytes representing the bridge mode\n     */\n    function getBridgeMode() external pure override returns (bytes4 _data) {\n        return 0xb1516c26; // bytes4(keccak256(abi.encodePacked(\"multi-erc-to-erc-amb\")))\n    }\n}\n"
      },
      "contracts/upgradeable_contracts/components/common/TokensBridgeLimits.sol": {
        "content": "pragma solidity 0.7.5;\n\nimport \"@openzeppelin/contracts/math/SafeMath.sol\";\nimport \"../../../upgradeability/EternalStorage.sol\";\nimport \"../../Ownable.sol\";\n\n/**\n * @title TokensBridgeLimits\n * @dev Functionality for keeping track of bridging limits for multiple tokens.\n */\ncontract TokensBridgeLimits is EternalStorage, Ownable {\n    using SafeMath for uint256;\n\n    // token == 0x00..00 represents default limits (assuming decimals == 18) for all newly created tokens\n    event DailyLimitChanged(address indexed token, uint256 newLimit);\n    event ExecutionDailyLimitChanged(address indexed token, uint256 newLimit);\n\n    /**\n     * @dev Checks if specified token was already bridged at least once.\n     * @param _token address of the token contract.\n     * @return true, if token address is address(0) or token was already bridged.\n     */\n    function isTokenRegistered(address _token) public view returns (bool) {\n        return minPerTx(_token) > 0;\n    }\n\n    /**\n     * @dev Retrieves the total spent amount for particular token during specific day.\n     * @param _token address of the token contract.\n     * @param _day day number for which spent amount if requested.\n     * @return amount of tokens sent through the bridge to the other side.\n     */\n    function totalSpentPerDay(address _token, uint256 _day) public view returns (uint256) {\n        return uintStorage[keccak256(abi.encodePacked(\"totalSpentPerDay\", _token, _day))];\n    }\n\n    /**\n     * @dev Retrieves the total executed amount for particular token during specific day.\n     * @param _token address of the token contract.\n     * @param _day day number for which spent amount if requested.\n     * @return amount of tokens received from the bridge from the other side.\n     */\n    function totalExecutedPerDay(address _token, uint256 _day) public view returns (uint256) {\n        return uintStorage[keccak256(abi.encodePacked(\"totalExecutedPerDay\", _token, _day))];\n    }\n\n    /**\n     * @dev Retrieves current daily limit for a particular token contract.\n     * @param _token address of the token contract.\n     * @return daily limit on tokens that can be sent through the bridge per day.\n     */\n    function dailyLimit(address _token) public view returns (uint256) {\n        return uintStorage[keccak256(abi.encodePacked(\"dailyLimit\", _token))];\n    }\n\n    /**\n     * @dev Retrieves current execution daily limit for a particular token contract.\n     * @param _token address of the token contract.\n     * @return daily limit on tokens that can be received from the bridge on the other side per day.\n     */\n    function executionDailyLimit(address _token) public view returns (uint256) {\n        return uintStorage[keccak256(abi.encodePacked(\"executionDailyLimit\", _token))];\n    }\n\n    /**\n     * @dev Retrieves current maximum amount of tokens per one transfer for a particular token contract.\n     * @param _token address of the token contract.\n     * @return maximum amount on tokens that can be sent through the bridge in one transfer.\n     */\n    function maxPerTx(address _token) public view returns (uint256) {\n        return uintStorage[keccak256(abi.encodePacked(\"maxPerTx\", _token))];\n    }\n\n    /**\n     * @dev Retrieves current maximum execution amount of tokens per one transfer for a particular token contract.\n     * @param _token address of the token contract.\n     * @return maximum amount on tokens that can received from the bridge on the other side in one transaction.\n     */\n    function executionMaxPerTx(address _token) public view returns (uint256) {\n        return uintStorage[keccak256(abi.encodePacked(\"executionMaxPerTx\", _token))];\n    }\n\n    /**\n     * @dev Retrieves current minimum amount of tokens per one transfer for a particular token contract.\n     * @param _token address of the token contract.\n     * @return minimum amount on tokens that can be sent through the bridge in one transfer.\n     */\n    function minPerTx(address _token) public view returns (uint256) {\n        return uintStorage[keccak256(abi.encodePacked(\"minPerTx\", _token))];\n    }\n\n    /**\n     * @dev Checks that bridged amount of tokens conforms to the configured limits.\n     * @param _token address of the token contract.\n     * @param _amount amount of bridge tokens.\n     * @return true, if specified amount can be bridged.\n     */\n    function withinLimit(address _token, uint256 _amount) public view returns (bool) {\n        uint256 nextLimit = totalSpentPerDay(_token, getCurrentDay()).add(_amount);\n        return\n            dailyLimit(address(0)) > 0 &&\n            dailyLimit(_token) >= nextLimit &&\n            _amount <= maxPerTx(_token) &&\n            _amount >= minPerTx(_token);\n    }\n\n    /**\n     * @dev Checks that bridged amount of tokens conforms to the configured execution limits.\n     * @param _token address of the token contract.\n     * @param _amount amount of bridge tokens.\n     * @return true, if specified amount can be processed and executed.\n     */\n    function withinExecutionLimit(address _token, uint256 _amount) public view returns (bool) {\n        uint256 nextLimit = totalExecutedPerDay(_token, getCurrentDay()).add(_amount);\n        return\n            executionDailyLimit(address(0)) > 0 &&\n            executionDailyLimit(_token) >= nextLimit &&\n            _amount <= executionMaxPerTx(_token);\n    }\n\n    /**\n     * @dev Returns current day number.\n     * @return day number.\n     */\n    function getCurrentDay() public view returns (uint256) {\n        // solhint-disable-next-line not-rely-on-time\n        return block.timestamp / 1 days;\n    }\n\n    /**\n     * @dev Updates daily limit for the particular token. Only owner can call this method.\n     * @param _token address of the token contract, or address(0) for configuring the efault limit.\n     * @param _dailyLimit daily allowed amount of bridged tokens, should be greater than maxPerTx.\n     * 0 value is also allowed, will stop the bridge operations in outgoing direction.\n     */\n    function setDailyLimit(address _token, uint256 _dailyLimit) external onlyOwner {\n        require(isTokenRegistered(_token));\n        require(_dailyLimit > maxPerTx(_token) || _dailyLimit == 0);\n        uintStorage[keccak256(abi.encodePacked(\"dailyLimit\", _token))] = _dailyLimit;\n        emit DailyLimitChanged(_token, _dailyLimit);\n    }\n\n    /**\n     * @dev Updates execution daily limit for the particular token. Only owner can call this method.\n     * @param _token address of the token contract, or address(0) for configuring the default limit.\n     * @param _dailyLimit daily allowed amount of executed tokens, should be greater than executionMaxPerTx.\n     * 0 value is also allowed, will stop the bridge operations in incoming direction.\n     */\n    function setExecutionDailyLimit(address _token, uint256 _dailyLimit) external onlyOwner {\n        require(isTokenRegistered(_token));\n        require(_dailyLimit > executionMaxPerTx(_token) || _dailyLimit == 0);\n        uintStorage[keccak256(abi.encodePacked(\"executionDailyLimit\", _token))] = _dailyLimit;\n        emit ExecutionDailyLimitChanged(_token, _dailyLimit);\n    }\n\n    /**\n     * @dev Updates execution maximum per transaction for the particular token. Only owner can call this method.\n     * @param _token address of the token contract, or address(0) for configuring the default limit.\n     * @param _maxPerTx maximum amount of executed tokens per one transaction, should be less than executionDailyLimit.\n     * 0 value is also allowed, will stop the bridge operations in incoming direction.\n     */\n    function setExecutionMaxPerTx(address _token, uint256 _maxPerTx) external onlyOwner {\n        require(isTokenRegistered(_token));\n        require(_maxPerTx == 0 || (_maxPerTx > 0 && _maxPerTx < executionDailyLimit(_token)));\n        uintStorage[keccak256(abi.encodePacked(\"executionMaxPerTx\", _token))] = _maxPerTx;\n    }\n\n    /**\n     * @dev Updates maximum per transaction for the particular token. Only owner can call this method.\n     * @param _token address of the token contract, or address(0) for configuring the default limit.\n     * @param _maxPerTx maximum amount of tokens per one transaction, should be less than dailyLimit, greater than minPerTx.\n     * 0 value is also allowed, will stop the bridge operations in outgoing direction.\n     */\n    function setMaxPerTx(address _token, uint256 _maxPerTx) external onlyOwner {\n        require(isTokenRegistered(_token));\n        require(_maxPerTx == 0 || (_maxPerTx > minPerTx(_token) && _maxPerTx < dailyLimit(_token)));\n        uintStorage[keccak256(abi.encodePacked(\"maxPerTx\", _token))] = _maxPerTx;\n    }\n\n    /**\n     * @dev Updates minimum per transaction for the particular token. Only owner can call this method.\n     * @param _token address of the token contract, or address(0) for configuring the default limit.\n     * @param _minPerTx minimum amount of tokens per one transaction, should be less than maxPerTx and dailyLimit.\n     */\n    function setMinPerTx(address _token, uint256 _minPerTx) external onlyOwner {\n        require(isTokenRegistered(_token));\n        require(_minPerTx > 0 && _minPerTx < dailyLimit(_token) && _minPerTx < maxPerTx(_token));\n        uintStorage[keccak256(abi.encodePacked(\"minPerTx\", _token))] = _minPerTx;\n    }\n\n    /**\n     * @dev Retrieves maximum available bridge amount per one transaction taking into account maxPerTx() and dailyLimit() parameters.\n     * @param _token address of the token contract, or address(0) for the default limit.\n     * @return minimum of maxPerTx parameter and remaining daily quota.\n     */\n    function maxAvailablePerTx(address _token) public view returns (uint256) {\n        uint256 _maxPerTx = maxPerTx(_token);\n        uint256 _dailyLimit = dailyLimit(_token);\n        uint256 _spent = totalSpentPerDay(_token, getCurrentDay());\n        uint256 _remainingOutOfDaily = _dailyLimit > _spent ? _dailyLimit - _spent : 0;\n        return _maxPerTx < _remainingOutOfDaily ? _maxPerTx : _remainingOutOfDaily;\n    }\n\n    /**\n     * @dev Internal function for adding spent amount for some token.\n     * @param _token address of the token contract.\n     * @param _day day number, when tokens are processed.\n     * @param _value amount of bridge tokens.\n     */\n    function addTotalSpentPerDay(\n        address _token,\n        uint256 _day,\n        uint256 _value\n    ) internal {\n        uintStorage[keccak256(abi.encodePacked(\"totalSpentPerDay\", _token, _day))] = totalSpentPerDay(_token, _day).add(\n            _value\n        );\n    }\n\n    /**\n     * @dev Internal function for adding executed amount for some token.\n     * @param _token address of the token contract.\n     * @param _day day number, when tokens are processed.\n     * @param _value amount of bridge tokens.\n     */\n    function addTotalExecutedPerDay(\n        address _token,\n        uint256 _day,\n        uint256 _value\n    ) internal {\n        uintStorage[keccak256(abi.encodePacked(\"totalExecutedPerDay\", _token, _day))] = totalExecutedPerDay(\n            _token,\n            _day\n        )\n            .add(_value);\n    }\n\n    /**\n     * @dev Internal function for initializing limits for some token.\n     * @param _token address of the token contract.\n     * @param _limits [ 0 = dailyLimit, 1 = maxPerTx, 2 = minPerTx ].\n     */\n    function _setLimits(address _token, uint256[3] memory _limits) internal {\n        require(\n            _limits[2] > 0 && // minPerTx > 0\n                _limits[1] > _limits[2] && // maxPerTx > minPerTx\n                _limits[0] > _limits[1] // dailyLimit > maxPerTx\n        );\n\n        uintStorage[keccak256(abi.encodePacked(\"dailyLimit\", _token))] = _limits[0];\n        uintStorage[keccak256(abi.encodePacked(\"maxPerTx\", _token))] = _limits[1];\n        uintStorage[keccak256(abi.encodePacked(\"minPerTx\", _token))] = _limits[2];\n\n        emit DailyLimitChanged(_token, _limits[0]);\n    }\n\n    /**\n     * @dev Internal function for initializing execution limits for some token.\n     * @param _token address of the token contract.\n     * @param _limits [ 0 = executionDailyLimit, 1 = executionMaxPerTx ].\n     */\n    function _setExecutionLimits(address _token, uint256[2] memory _limits) internal {\n        require(_limits[1] < _limits[0]); // foreignMaxPerTx < foreignDailyLimit\n\n        uintStorage[keccak256(abi.encodePacked(\"executionDailyLimit\", _token))] = _limits[0];\n        uintStorage[keccak256(abi.encodePacked(\"executionMaxPerTx\", _token))] = _limits[1];\n\n        emit ExecutionDailyLimitChanged(_token, _limits[0]);\n    }\n\n    /**\n     * @dev Internal function for initializing limits for some token relative to its decimals parameter.\n     * @param _token address of the token contract.\n     * @param _decimals token decimals parameter.\n     */\n    function _initializeTokenBridgeLimits(address _token, uint256 _decimals) internal {\n        uint256 factor;\n        if (_decimals < 18) {\n            factor = 10**(18 - _decimals);\n\n            uint256 _minPerTx = minPerTx(address(0)).div(factor);\n            uint256 _maxPerTx = maxPerTx(address(0)).div(factor);\n            uint256 _dailyLimit = dailyLimit(address(0)).div(factor);\n            uint256 _executionMaxPerTx = executionMaxPerTx(address(0)).div(factor);\n            uint256 _executionDailyLimit = executionDailyLimit(address(0)).div(factor);\n\n            // such situation can happen when calculated limits relative to the token decimals are too low\n            // e.g. minPerTx(address(0)) == 10 ** 14, _decimals == 3. _minPerTx happens to be 0, which is not allowed.\n            // in this case, limits are raised to the default values\n            if (_minPerTx == 0) {\n                // Numbers 1, 100, 10000 are chosen in a semi-random way,\n                // so that any token with small decimals can still be bridged in some amounts.\n                // It is possible to override limits for the particular token later if needed.\n                _minPerTx = 1;\n                if (_maxPerTx <= _minPerTx) {\n                    _maxPerTx = 100;\n                    _executionMaxPerTx = 100;\n                    if (_dailyLimit <= _maxPerTx || _executionDailyLimit <= _executionMaxPerTx) {\n                        _dailyLimit = 10000;\n                        _executionDailyLimit = 10000;\n                    }\n                }\n            }\n            _setLimits(_token, [_dailyLimit, _maxPerTx, _minPerTx]);\n            _setExecutionLimits(_token, [_executionDailyLimit, _executionMaxPerTx]);\n        } else {\n            factor = 10**(_decimals - 18);\n            _setLimits(\n                _token,\n                [dailyLimit(address(0)).mul(factor), maxPerTx(address(0)).mul(factor), minPerTx(address(0)).mul(factor)]\n            );\n            _setExecutionLimits(\n                _token,\n                [executionDailyLimit(address(0)).mul(factor), executionMaxPerTx(address(0)).mul(factor)]\n            );\n        }\n    }\n}\n"
      },
      "contracts/upgradeable_contracts/components/common/FailedMessagesProcessor.sol": {
        "content": "pragma solidity 0.7.5;\n\nimport \"../../BasicAMBMediator.sol\";\nimport \"./BridgeOperationsStorage.sol\";\n\n/**\n * @title FailedMessagesProcessor\n * @dev Functionality for fixing failed bridging operations.\n */\nabstract contract FailedMessagesProcessor is BasicAMBMediator, BridgeOperationsStorage {\n    event FailedMessageFixed(bytes32 indexed messageId, address token, address recipient, uint256 value);\n\n    /**\n     * @dev Method to be called when a bridged message execution failed. It will generate a new message requesting to\n     * fix/roll back the transferred assets on the other network.\n     * @param _messageId id of the message which execution failed.\n     */\n    function requestFailedMessageFix(bytes32 _messageId) external {\n        IAMB bridge = bridgeContract();\n        require(!bridge.messageCallStatus(_messageId));\n        require(bridge.failedMessageReceiver(_messageId) == address(this));\n        require(bridge.failedMessageSender(_messageId) == mediatorContractOnOtherSide());\n\n        bytes4 methodSelector = this.fixFailedMessage.selector;\n        bytes memory data = abi.encodeWithSelector(methodSelector, _messageId);\n        _passMessage(data, true);\n    }\n\n    /**\n     * @dev Handles the request to fix transferred assets which bridged message execution failed on the other network.\n     * It uses the information stored by passMessage method when the assets were initially transferred\n     * @param _messageId id of the message which execution failed on the other network.\n     */\n    function fixFailedMessage(bytes32 _messageId) public onlyMediator {\n        require(!messageFixed(_messageId));\n\n        address token = messageToken(_messageId);\n        address recipient = messageRecipient(_messageId);\n        uint256 value = messageValue(_messageId);\n        setMessageFixed(_messageId);\n        executeActionOnFixedTokens(token, recipient, value);\n        emit FailedMessageFixed(_messageId, token, recipient, value);\n    }\n\n    /**\n     * @dev Tells if a message sent to the AMB bridge has been fixed.\n     * @return bool indicating the status of the message.\n     */\n    function messageFixed(bytes32 _messageId) public view returns (bool) {\n        return boolStorage[keccak256(abi.encodePacked(\"messageFixed\", _messageId))];\n    }\n\n    /**\n     * @dev Sets that the message sent to the AMB bridge has been fixed.\n     * @param _messageId of the message sent to the bridge.\n     */\n    function setMessageFixed(bytes32 _messageId) internal {\n        boolStorage[keccak256(abi.encodePacked(\"messageFixed\", _messageId))] = true;\n    }\n\n    function executeActionOnFixedTokens(\n        address _token,\n        address _recipient,\n        uint256 _value\n    ) internal virtual;\n}\n"
      },
      "contracts/upgradeable_contracts/modules/factory/TokenFactoryConnector.sol": {
        "content": "pragma solidity 0.7.5;\n\nimport \"@openzeppelin/contracts/utils/Address.sol\";\nimport \"../../Ownable.sol\";\nimport \"./TokenFactory.sol\";\n\n/**\n * @title TokenFactoryConnector\n * @dev Connectivity functionality for working with TokenFactory contract.\n */\ncontract TokenFactoryConnector is Ownable {\n    bytes32 internal constant TOKEN_FACTORY_CONTRACT =\n        0x269c5905f777ee6391c7a361d17039a7d62f52ba9fffeb98c5ade342705731a3; // keccak256(abi.encodePacked(\"tokenFactoryContract\"))\n\n    /**\n     * @dev Updates an address of the used TokenFactory contract used for creating new tokens.\n     * @param _tokenFactory address of TokenFactory contract.\n     */\n    function setTokenFactory(address _tokenFactory) external onlyOwner {\n        _setTokenFactory(_tokenFactory);\n    }\n\n    /**\n     * @dev Retrieves an address of the token factory contract.\n     * @return address of the TokenFactory contract.\n     */\n    function tokenFactory() public view returns (TokenFactory) {\n        return TokenFactory(addressStorage[TOKEN_FACTORY_CONTRACT]);\n    }\n\n    /**\n     * @dev Internal function for updating an address of the token factory contract.\n     * @param _tokenFactory address of the deployed TokenFactory contract.\n     */\n    function _setTokenFactory(address _tokenFactory) internal {\n        require(Address.isContract(_tokenFactory));\n        addressStorage[TOKEN_FACTORY_CONTRACT] = _tokenFactory;\n    }\n}\n"
      },
      "@openzeppelin/contracts/math/SafeMath.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.7.0;\n\n/**\n * @dev Wrappers over Solidity's arithmetic operations with added overflow\n * checks.\n *\n * Arithmetic operations in Solidity wrap on overflow. This can easily result\n * in bugs, because programmers usually assume that an overflow raises an\n * error, which is the standard behavior in high level programming languages.\n * `SafeMath` restores this intuition by reverting the transaction when an\n * operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n */\nlibrary SafeMath {\n    /**\n     * @dev Returns the addition of two unsigned integers, reverting on\n     * overflow.\n     *\n     * Counterpart to Solidity's `+` operator.\n     *\n     * Requirements:\n     *\n     * - Addition cannot overflow.\n     */\n    function add(uint256 a, uint256 b) internal pure returns (uint256) {\n        uint256 c = a + b;\n        require(c >= a, \"SafeMath: addition overflow\");\n\n        return c;\n    }\n\n    /**\n     * @dev Returns the subtraction of two unsigned integers, reverting on\n     * overflow (when the result is negative).\n     *\n     * Counterpart to Solidity's `-` operator.\n     *\n     * Requirements:\n     *\n     * - Subtraction cannot overflow.\n     */\n    function sub(uint256 a, uint256 b) internal pure returns (uint256) {\n        return sub(a, b, \"SafeMath: subtraction overflow\");\n    }\n\n    /**\n     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on\n     * overflow (when the result is negative).\n     *\n     * Counterpart to Solidity's `-` operator.\n     *\n     * Requirements:\n     *\n     * - Subtraction cannot overflow.\n     */\n    function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\n        require(b <= a, errorMessage);\n        uint256 c = a - b;\n\n        return c;\n    }\n\n    /**\n     * @dev Returns the multiplication of two unsigned integers, reverting on\n     * overflow.\n     *\n     * Counterpart to Solidity's `*` operator.\n     *\n     * Requirements:\n     *\n     * - Multiplication cannot overflow.\n     */\n    function mul(uint256 a, uint256 b) internal pure returns (uint256) {\n        // Gas optimization: this is cheaper than requiring 'a' not being zero, but the\n        // benefit is lost if 'b' is also tested.\n        // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522\n        if (a == 0) {\n            return 0;\n        }\n\n        uint256 c = a * b;\n        require(c / a == b, \"SafeMath: multiplication overflow\");\n\n        return c;\n    }\n\n    /**\n     * @dev Returns the integer division of two unsigned integers. Reverts on\n     * division by zero. The result is rounded towards zero.\n     *\n     * Counterpart to Solidity's `/` operator. Note: this function uses a\n     * `revert` opcode (which leaves remaining gas untouched) while Solidity\n     * uses an invalid opcode to revert (consuming all remaining gas).\n     *\n     * Requirements:\n     *\n     * - The divisor cannot be zero.\n     */\n    function div(uint256 a, uint256 b) internal pure returns (uint256) {\n        return div(a, b, \"SafeMath: division by zero\");\n    }\n\n    /**\n     * @dev Returns the integer division of two unsigned integers. Reverts with custom message on\n     * division by zero. The result is rounded towards zero.\n     *\n     * Counterpart to Solidity's `/` operator. Note: this function uses a\n     * `revert` opcode (which leaves remaining gas untouched) while Solidity\n     * uses an invalid opcode to revert (consuming all remaining gas).\n     *\n     * Requirements:\n     *\n     * - The divisor cannot be zero.\n     */\n    function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\n        require(b > 0, errorMessage);\n        uint256 c = a / b;\n        // assert(a == b * c + a % b); // There is no case in which this doesn't hold\n\n        return c;\n    }\n\n    /**\n     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\n     * Reverts when dividing by zero.\n     *\n     * Counterpart to Solidity's `%` operator. This function uses a `revert`\n     * opcode (which leaves remaining gas untouched) while Solidity uses an\n     * invalid opcode to revert (consuming all remaining gas).\n     *\n     * Requirements:\n     *\n     * - The divisor cannot be zero.\n     */\n    function mod(uint256 a, uint256 b) internal pure returns (uint256) {\n        return mod(a, b, \"SafeMath: modulo by zero\");\n    }\n\n    /**\n     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\n     * Reverts with custom message when dividing by zero.\n     *\n     * Counterpart to Solidity's `%` operator. This function uses a `revert`\n     * opcode (which leaves remaining gas untouched) while Solidity uses an\n     * invalid opcode to revert (consuming all remaining gas).\n     *\n     * Requirements:\n     *\n     * - The divisor cannot be zero.\n     */\n    function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\n        require(b != 0, errorMessage);\n        return a % b;\n    }\n}\n"
      },
      "contracts/upgradeability/EternalStorage.sol": {
        "content": "pragma solidity 0.7.5;\n\n/**\n * @title EternalStorage\n * @dev This contract holds all the necessary state variables to carry out the storage of any contract.\n */\ncontract EternalStorage {\n    mapping(bytes32 => uint256) internal uintStorage;\n    mapping(bytes32 => string) internal stringStorage;\n    mapping(bytes32 => address) internal addressStorage;\n    mapping(bytes32 => bytes) internal bytesStorage;\n    mapping(bytes32 => bool) internal boolStorage;\n    mapping(bytes32 => int256) internal intStorage;\n}\n"
      },
      "contracts/interfaces/IUpgradeabilityOwnerStorage.sol": {
        "content": "pragma solidity 0.7.5;\n\ninterface IUpgradeabilityOwnerStorage {\n    function upgradeabilityOwner() external view returns (address);\n}\n"
      },
      "contracts/libraries/AddressHelper.sol": {
        "content": "pragma solidity 0.7.5;\n\nimport \"../upgradeable_contracts/Sacrifice.sol\";\n\n/**\n * @title AddressHelper\n * @dev Helper methods for Address type.\n */\nlibrary AddressHelper {\n    /**\n     * @dev Try to send native tokens to the address. If it fails, it will force the transfer by creating a selfdestruct contract\n     * @param _receiver address that will receive the native tokens\n     * @param _value the amount of native tokens to send\n     */\n    function safeSendValue(address payable _receiver, uint256 _value) internal {\n        if (!(_receiver).send(_value)) {\n            new Sacrifice{ value: _value }(_receiver);\n        }\n    }\n}\n"
      },
      "@openzeppelin/contracts/token/ERC20/SafeERC20.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.7.0;\n\nimport \"./IERC20.sol\";\nimport \"../../math/SafeMath.sol\";\nimport \"../../utils/Address.sol\";\n\n/**\n * @title SafeERC20\n * @dev Wrappers around ERC20 operations that throw on failure (when the token\n * contract returns false). Tokens that return no value (and instead revert or\n * throw on failure) are also supported, non-reverting calls are assumed to be\n * successful.\n * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,\n * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.\n */\nlibrary SafeERC20 {\n    using SafeMath for uint256;\n    using Address for address;\n\n    function safeTransfer(IERC20 token, address to, uint256 value) internal {\n        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));\n    }\n\n    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {\n        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));\n    }\n\n    /**\n     * @dev Deprecated. This function has issues similar to the ones found in\n     * {IERC20-approve}, and its usage is discouraged.\n     *\n     * Whenever possible, use {safeIncreaseAllowance} and\n     * {safeDecreaseAllowance} instead.\n     */\n    function safeApprove(IERC20 token, address spender, uint256 value) internal {\n        // safeApprove should only be called when setting an initial allowance,\n        // or when resetting it to zero. To increase and decrease it, use\n        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'\n        // solhint-disable-next-line max-line-length\n        require((value == 0) || (token.allowance(address(this), spender) == 0),\n            \"SafeERC20: approve from non-zero to non-zero allowance\"\n        );\n        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));\n    }\n\n    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {\n        uint256 newAllowance = token.allowance(address(this), spender).add(value);\n        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));\n    }\n\n    function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {\n        uint256 newAllowance = token.allowance(address(this), spender).sub(value, \"SafeERC20: decreased allowance below zero\");\n        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));\n    }\n\n    /**\n     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement\n     * on the return value: the return value is optional (but if data is returned, it must not be false).\n     * @param token The token targeted by the call.\n     * @param data The call data (encoded using abi.encode or one of its variants).\n     */\n    function _callOptionalReturn(IERC20 token, bytes memory data) private {\n        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since\n        // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that\n        // the target address contains contract code and also asserts for success in the low-level call.\n\n        bytes memory returndata = address(token).functionCall(data, \"SafeERC20: low-level call failed\");\n        if (returndata.length > 0) { // Return data is optional\n            // solhint-disable-next-line max-line-length\n            require(abi.decode(returndata, (bool)), \"SafeERC20: ERC20 operation did not succeed\");\n        }\n    }\n}\n"
      },
      "contracts/upgradeable_contracts/Sacrifice.sol": {
        "content": "pragma solidity 0.7.5;\n\ncontract Sacrifice {\n    constructor(address payable _recipient) payable {\n        selfdestruct(_recipient);\n    }\n}\n"
      },
      "@openzeppelin/contracts/utils/Address.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.7.0;\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary Address {\n    /**\n     * @dev Returns true if `account` is a contract.\n     *\n     * [IMPORTANT]\n     * ====\n     * It is unsafe to assume that an address for which this function returns\n     * false is an externally-owned account (EOA) and not a contract.\n     *\n     * Among others, `isContract` will return false for the following\n     * types of addresses:\n     *\n     *  - an externally-owned account\n     *  - a contract in construction\n     *  - an address where a contract will be created\n     *  - an address where a contract lived, but was destroyed\n     * ====\n     */\n    function isContract(address account) internal view returns (bool) {\n        // According to EIP-1052, 0x0 is the value returned for not-yet created accounts\n        // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned\n        // for accounts without code, i.e. `keccak256('')`\n        bytes32 codehash;\n        bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;\n        // solhint-disable-next-line no-inline-assembly\n        assembly { codehash := extcodehash(account) }\n        return (codehash != accountHash && codehash != 0x0);\n    }\n\n    /**\n     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n     * `recipient`, forwarding all available gas and reverting on errors.\n     *\n     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n     * of certain opcodes, possibly making contracts go over the 2300 gas limit\n     * imposed by `transfer`, making them unable to receive funds via\n     * `transfer`. {sendValue} removes this limitation.\n     *\n     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n     *\n     * IMPORTANT: because control is transferred to `recipient`, care must be\n     * taken to not create reentrancy vulnerabilities. Consider using\n     * {ReentrancyGuard} or the\n     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n     */\n    function sendValue(address payable recipient, uint256 amount) internal {\n        require(address(this).balance >= amount, \"Address: insufficient balance\");\n\n        // solhint-disable-next-line avoid-low-level-calls, avoid-call-value\n        (bool success, ) = recipient.call{ value: amount }(\"\");\n        require(success, \"Address: unable to send value, recipient may have reverted\");\n    }\n\n    /**\n     * @dev Performs a Solidity function call using a low level `call`. A\n     * plain`call` is an unsafe replacement for a function call: use this\n     * function instead.\n     *\n     * If `target` reverts with a revert reason, it is bubbled up by this\n     * function (like regular Solidity function calls).\n     *\n     * Returns the raw returned data. To convert to the expected return value,\n     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n     *\n     * Requirements:\n     *\n     * - `target` must be a contract.\n     * - calling `target` with `data` must not revert.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n      return functionCall(target, data, \"Address: low-level call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n     * `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {\n        return _functionCallWithValue(target, data, 0, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but also transferring `value` wei to `target`.\n     *\n     * Requirements:\n     *\n     * - the calling contract must have an ETH balance of at least `value`.\n     * - the called Solidity function must be `payable`.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n     * with `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {\n        require(address(this).balance >= value, \"Address: insufficient balance for call\");\n        return _functionCallWithValue(target, data, value, errorMessage);\n    }\n\n    function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {\n        require(isContract(target), \"Address: call to non-contract\");\n\n        // solhint-disable-next-line avoid-low-level-calls\n        (bool success, bytes memory returndata) = target.call{ value: weiValue }(data);\n        if (success) {\n            return returndata;\n        } else {\n            // Look for revert reason and bubble it up if present\n            if (returndata.length > 0) {\n                // The easiest way to bubble the revert reason is using memory via assembly\n\n                // solhint-disable-next-line no-inline-assembly\n                assembly {\n                    let returndata_size := mload(returndata)\n                    revert(add(32, returndata), returndata_size)\n                }\n            } else {\n                revert(errorMessage);\n            }\n        }\n    }\n}\n"
      },
      "@openzeppelin/contracts/token/ERC20/IERC20.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.7.0;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IERC20 {\n    /**\n     * @dev Returns the amount of tokens in existence.\n     */\n    function totalSupply() external view returns (uint256);\n\n    /**\n     * @dev Returns the amount of tokens owned by `account`.\n     */\n    function balanceOf(address account) external view returns (uint256);\n\n    /**\n     * @dev Moves `amount` tokens from the caller's account to `recipient`.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transfer(address recipient, uint256 amount) external returns (bool);\n\n    /**\n     * @dev Returns the remaining number of tokens that `spender` will be\n     * allowed to spend on behalf of `owner` through {transferFrom}. This is\n     * zero by default.\n     *\n     * This value changes when {approve} or {transferFrom} are called.\n     */\n    function allowance(address owner, address spender) external view returns (uint256);\n\n    /**\n     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * IMPORTANT: Beware that changing an allowance with this method brings the risk\n     * that someone may use both the old and the new allowance by unfortunate\n     * transaction ordering. One possible solution to mitigate this race\n     * condition is to first reduce the spender's allowance to 0 and set the\n     * desired value afterwards:\n     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n     *\n     * Emits an {Approval} event.\n     */\n    function approve(address spender, uint256 amount) external returns (bool);\n\n    /**\n     * @dev Moves `amount` tokens from `sender` to `recipient` using the\n     * allowance mechanism. `amount` is then deducted from the caller's\n     * allowance.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);\n\n    /**\n     * @dev Emitted when `value` tokens are moved from one account (`from`) to\n     * another (`to`).\n     *\n     * Note that `value` may be zero.\n     */\n    event Transfer(address indexed from, address indexed to, uint256 value);\n\n    /**\n     * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n     * a call to {approve}. `value` is the new allowance.\n     */\n    event Approval(address indexed owner, address indexed spender, uint256 value);\n}\n"
      },
      "contracts/interfaces/IERC677.sol": {
        "content": "pragma solidity 0.7.5;\n\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\n\ninterface IERC677 is IERC20 {\n    event Transfer(address indexed from, address indexed to, uint256 value, bytes data);\n\n    function transferAndCall(\n        address to,\n        uint256 value,\n        bytes calldata data\n    ) external returns (bool);\n\n    function increaseAllowance(address spender, uint256 addedValue) external returns (bool);\n\n    function decreaseAllowance(address spender, uint256 subtractedValue) external returns (bool);\n}\n"
      },
      "contracts/libraries/Bytes.sol": {
        "content": "pragma solidity 0.7.5;\n\n/**\n * @title Bytes\n * @dev Helper methods to transform bytes to other solidity types.\n */\nlibrary Bytes {\n    /**\n     * @dev Truncate bytes array if its size is more than 20 bytes.\n     * NOTE: This function does not perform any checks on the received parameter.\n     * Make sure that the _bytes argument has a correct length, not less than 20 bytes.\n     * A case when _bytes has length less than 20 will lead to the undefined behaviour,\n     * since assembly will read data from memory that is not related to the _bytes argument.\n     * @param _bytes to be converted to address type\n     * @return addr address included in the firsts 20 bytes of the bytes array in parameter.\n     */\n    function bytesToAddress(bytes memory _bytes) internal pure returns (address addr) {\n        assembly {\n            addr := mload(add(_bytes, 20))\n        }\n    }\n}\n"
      },
      "contracts/upgradeable_contracts/ReentrancyGuard.sol": {
        "content": "pragma solidity 0.7.5;\n\ncontract ReentrancyGuard {\n    function lock() internal view returns (bool res) {\n        assembly {\n            // Even though this is not the same as boolStorage[keccak256(abi.encodePacked(\"lock\"))],\n            // since solidity mapping introduces another level of addressing, such slot change is safe\n            // for temporary variables which are cleared at the end of the call execution.\n            res := sload(0x6168652c307c1e813ca11cfb3a601f1cf3b22452021a5052d8b05f1f1f8a3e92) // keccak256(abi.encodePacked(\"lock\"))\n        }\n    }\n\n    function setLock(bool _lock) internal {\n        assembly {\n            // Even though this is not the same as boolStorage[keccak256(abi.encodePacked(\"lock\"))],\n            // since solidity mapping introduces another level of addressing, such slot change is safe\n            // for temporary variables which are cleared at the end of the call execution.\n            sstore(0x6168652c307c1e813ca11cfb3a601f1cf3b22452021a5052d8b05f1f1f8a3e92, _lock) // keccak256(abi.encodePacked(\"lock\"))\n        }\n    }\n}\n"
      },
      "contracts/upgradeable_contracts/BasicAMBMediator.sol": {
        "content": "pragma solidity 0.7.5;\n\nimport \"./Ownable.sol\";\nimport \"../interfaces/IAMB.sol\";\nimport \"@openzeppelin/contracts/utils/Address.sol\";\n\n/**\n * @title BasicAMBMediator\n * @dev Basic storage and methods needed by mediators to interact with AMB bridge.\n */\nabstract contract BasicAMBMediator is Ownable {\n    bytes32 internal constant BRIDGE_CONTRACT = 0x811bbb11e8899da471f0e69a3ed55090fc90215227fc5fb1cb0d6e962ea7b74f; // keccak256(abi.encodePacked(\"bridgeContract\"))\n    bytes32 internal constant MEDIATOR_CONTRACT = 0x98aa806e31e94a687a31c65769cb99670064dd7f5a87526da075c5fb4eab9880; // keccak256(abi.encodePacked(\"mediatorContract\"))\n\n    /**\n     * @dev Throws if caller on the other side is not an associated mediator.\n     */\n    modifier onlyMediator {\n        _onlyMediator();\n        _;\n    }\n\n    /**\n     * @dev Internal function for reducing onlyMediator modifier bytecode overhead.\n     */\n    function _onlyMediator() internal view {\n        IAMB bridge = bridgeContract();\n        require(msg.sender == address(bridge));\n        require(bridge.messageSender() == mediatorContractOnOtherSide());\n    }\n\n    /**\n     * @dev Sets the AMB bridge contract address. Only the owner can call this method.\n     * @param _bridgeContract the address of the bridge contract.\n     */\n    function setBridgeContract(address _bridgeContract) external onlyOwner {\n        _setBridgeContract(_bridgeContract);\n    }\n\n    /**\n     * @dev Sets the mediator contract address from the other network. Only the owner can call this method.\n     * @param _mediatorContract the address of the mediator contract.\n     */\n    function setMediatorContractOnOtherSide(address _mediatorContract) external onlyOwner {\n        _setMediatorContractOnOtherSide(_mediatorContract);\n    }\n\n    /**\n     * @dev Get the AMB interface for the bridge contract address\n     * @return AMB interface for the bridge contract address\n     */\n    function bridgeContract() public view returns (IAMB) {\n        return IAMB(addressStorage[BRIDGE_CONTRACT]);\n    }\n\n    /**\n     * @dev Tells the mediator contract address from the other network.\n     * @return the address of the mediator contract.\n     */\n    function mediatorContractOnOtherSide() public view virtual returns (address) {\n        return addressStorage[MEDIATOR_CONTRACT];\n    }\n\n    /**\n     * @dev Stores a valid AMB bridge contract address.\n     * @param _bridgeContract the address of the bridge contract.\n     */\n    function _setBridgeContract(address _bridgeContract) internal {\n        require(Address.isContract(_bridgeContract));\n        addressStorage[BRIDGE_CONTRACT] = _bridgeContract;\n    }\n\n    /**\n     * @dev Stores the mediator contract address from the other network.\n     * @param _mediatorContract the address of the mediator contract.\n     */\n    function _setMediatorContractOnOtherSide(address _mediatorContract) internal {\n        addressStorage[MEDIATOR_CONTRACT] = _mediatorContract;\n    }\n\n    /**\n     * @dev Tells the id of the message originated on the other network.\n     * @return the id of the message originated on the other network.\n     */\n    function messageId() internal view returns (bytes32) {\n        return bridgeContract().messageId();\n    }\n\n    /**\n     * @dev Tells the maximum gas limit that a message can use on its execution by the AMB bridge on the other network.\n     * @return the maximum gas limit value.\n     */\n    function maxGasPerTx() internal view returns (uint256) {\n        return bridgeContract().maxGasPerTx();\n    }\n\n    function _passMessage(bytes memory _data, bool _useOracleLane) internal virtual returns (bytes32);\n}\n"
      },
      "contracts/upgradeable_contracts/components/common/TransferNativeFeeStorage.sol": {
        "content": "pragma solidity 0.7.5;\n\nimport \"../../../upgradeability/EternalStorage.sol\";\nimport \"../../Ownable.sol\";\n\ncontract TransferNativeFeeStorage is EternalStorage, Ownable {\n    bytes32 internal constant FEE_AMOUNT = 0xb57b57c32f08d35b1d0aba8906aabd78c13ea6500a303931d95fe3b883d1266c; // keccak256(abi.encodePacked(\"feeAmount\"))\n    bytes32 internal constant FEE_ADDRESS = 0x33088bb68c831fb409e4920e632ee8cc604af2428f8685e4b78713caabeec6ef; // keccak256(abi.encodePacked(\"feeAddress\"))\n\n\n    function transferFeeAmount() public view returns (uint256) {\n        return uintStorage[FEE_AMOUNT];\n    }\n\n    function setTransferFeeAmount(uint256 _feeAmount) external onlyOwner {\n        _setTransferFeeAmount(_feeAmount);\n    }\n\n    function _setTransferFeeAmount(uint256 _feeAmount) internal {\n        require(_feeAmount > 0);\n        uintStorage[FEE_AMOUNT] = _feeAmount;\n    }\n\n    function transferFeeAddress() public view returns (address) {\n        return addressStorage[FEE_ADDRESS];\n    }\n\n    function setTransferFeeAddress(address _feeAddress) external onlyOwner {\n        _setTransferFeeAddress(_feeAddress);\n    }\n\n    function _setTransferFeeAddress(address _feeAddress) internal {\n        require(_feeAddress != address(0));\n        addressStorage[FEE_ADDRESS] = _feeAddress;\n    }\n\n\n}\n"
      },
      "contracts/upgradeable_contracts/Ownable.sol": {
        "content": "pragma solidity 0.7.5;\n\nimport \"../upgradeability/EternalStorage.sol\";\nimport \"../interfaces/IUpgradeabilityOwnerStorage.sol\";\n\n/**\n * @title Ownable\n * @dev This contract has an owner address providing basic authorization control\n */\ncontract Ownable is EternalStorage {\n    bytes4 internal constant UPGRADEABILITY_OWNER = 0x6fde8202; // upgradeabilityOwner()\n\n    /**\n     * @dev Event to show ownership has been transferred\n     * @param previousOwner representing the address of the previous owner\n     * @param newOwner representing the address of the new owner\n     */\n    event OwnershipTransferred(address previousOwner, address newOwner);\n\n    /**\n     * @dev Throws if called by any account other than the owner.\n     */\n    modifier onlyOwner() {\n        _onlyOwner();\n        _;\n    }\n\n    /**\n     * @dev Internal function for reducing onlyOwner modifier bytecode overhead.\n     */\n    function _onlyOwner() internal view {\n        require(msg.sender == owner());\n    }\n\n    /**\n     * @dev Throws if called through proxy by any account other than contract itself or an upgradeability owner.\n     */\n    modifier onlyRelevantSender() {\n        (bool isProxy, bytes memory returnData) =\n            address(this).staticcall(abi.encodeWithSelector(UPGRADEABILITY_OWNER));\n        require(\n            !isProxy || // covers usage without calling through storage proxy\n                (returnData.length == 32 && msg.sender == abi.decode(returnData, (address))) || // covers usage through regular proxy calls\n                msg.sender == address(this) // covers calls through upgradeAndCall proxy method\n        );\n        _;\n    }\n\n    bytes32 internal constant OWNER = 0x02016836a56b71f0d02689e69e326f4f4c1b9057164ef592671cf0d37c8040c0; // keccak256(abi.encodePacked(\"owner\"))\n\n    /**\n     * @dev Tells the address of the owner\n     * @return the address of the owner\n     */\n    function owner() public view returns (address) {\n        return addressStorage[OWNER];\n    }\n\n    /**\n     * @dev Allows the current owner to transfer control of the contract to a newOwner.\n     * @param newOwner the address to transfer ownership to.\n     */\n    function transferOwnership(address newOwner) external onlyOwner {\n        _setOwner(newOwner);\n    }\n\n    /**\n     * @dev Sets a new owner address\n     */\n    function _setOwner(address newOwner) internal {\n        require(newOwner != address(0));\n        emit OwnershipTransferred(owner(), newOwner);\n        addressStorage[OWNER] = newOwner;\n    }\n}\n"
      },
      "contracts/upgradeable_contracts/VersionableBridge.sol": {
        "content": "pragma solidity 0.7.5;\n\ninterface VersionableBridge {\n    function getBridgeInterfacesVersion()\n        external\n        pure\n        returns (\n            uint64 major,\n            uint64 minor,\n            uint64 patch\n        );\n\n    function getBridgeMode() external pure returns (bytes4);\n}\n"
      },
      "contracts/upgradeable_contracts/components/common/BridgeOperationsStorage.sol": {
        "content": "pragma solidity 0.7.5;\n\nimport \"../../../upgradeability/EternalStorage.sol\";\n\n/**\n * @title BridgeOperationsStorage\n * @dev Functionality for storing processed bridged operations.\n */\nabstract contract BridgeOperationsStorage is EternalStorage {\n    /**\n     * @dev Stores the bridged token of a message sent to the AMB bridge.\n     * @param _messageId of the message sent to the bridge.\n     * @param _token bridged token address.\n     */\n    function setMessageToken(bytes32 _messageId, address _token) internal {\n        addressStorage[keccak256(abi.encodePacked(\"messageToken\", _messageId))] = _token;\n    }\n\n    /**\n     * @dev Tells the bridged token address of a message sent to the AMB bridge.\n     * @return address of a token contract.\n     */\n    function messageToken(bytes32 _messageId) internal view returns (address) {\n        return addressStorage[keccak256(abi.encodePacked(\"messageToken\", _messageId))];\n    }\n\n    /**\n     * @dev Stores the value of a message sent to the AMB bridge.\n     * @param _messageId of the message sent to the bridge.\n     * @param _value amount of tokens bridged.\n     */\n    function setMessageValue(bytes32 _messageId, uint256 _value) internal {\n        uintStorage[keccak256(abi.encodePacked(\"messageValue\", _messageId))] = _value;\n    }\n\n    /**\n     * @dev Tells the amount of tokens of a message sent to the AMB bridge.\n     * @return value representing amount of tokens.\n     */\n    function messageValue(bytes32 _messageId) internal view returns (uint256) {\n        return uintStorage[keccak256(abi.encodePacked(\"messageValue\", _messageId))];\n    }\n\n    /**\n     * @dev Stores the receiver of a message sent to the AMB bridge.\n     * @param _messageId of the message sent to the bridge.\n     * @param _recipient receiver of the tokens bridged.\n     */\n    function setMessageRecipient(bytes32 _messageId, address _recipient) internal {\n        addressStorage[keccak256(abi.encodePacked(\"messageRecipient\", _messageId))] = _recipient;\n    }\n\n    /**\n     * @dev Tells the receiver of a message sent to the AMB bridge.\n     * @return address of the receiver.\n     */\n    function messageRecipient(bytes32 _messageId) internal view returns (address) {\n        return addressStorage[keccak256(abi.encodePacked(\"messageRecipient\", _messageId))];\n    }\n}\n"
      },
      "contracts/upgradeable_contracts/modules/factory/TokenFactory.sol": {
        "content": "pragma solidity 0.7.5;\n\nimport \"./TokenProxy.sol\";\nimport \"../OwnableModule.sol\";\n\n/**\n * @title TokenFactory\n * @dev Factory contract for deployment of new TokenProxy contracts.\n */\ncontract TokenFactory is OwnableModule {\n    address public tokenImage;\n\n    /**\n     * @dev Initializes this contract\n     * @param _owner of this factory contract.\n     * @param _tokenImage address of the token image contract that should be used for creation of new tokens.\n     */\n    constructor(address _owner, address _tokenImage) OwnableModule(_owner) {\n        tokenImage = _tokenImage;\n    }\n\n    /**\n     * @dev Tells the module interface version that this contract supports.\n     * @return major value of the version\n     * @return minor value of the version\n     * @return patch value of the version\n     */\n    function getModuleInterfacesVersion()\n        external\n        pure\n        returns (\n            uint64 major,\n            uint64 minor,\n            uint64 patch\n        )\n    {\n        return (1, 0, 0);\n    }\n\n    /**\n     * @dev Updates the address of the used token image contract.\n     * Only owner can call this method.\n     * @param _tokenImage address of the new token image used for further deployments.\n     */\n    function setTokenImage(address _tokenImage) external onlyOwner {\n        require(Address.isContract(_tokenImage));\n        tokenImage = _tokenImage;\n    }\n\n    /**\n     * @dev Deploys a new TokenProxy contract, using saved token image contract as a template.\n     * @param _name deployed token name.\n     * @param _symbol deployed token symbol.\n     * @param _decimals deployed token decimals.\n     * @param _chainId chain id of the current environment.\n     * @return address of a newly created contract.\n     */\n    function deploy(\n        string calldata _name,\n        string calldata _symbol,\n        uint8 _decimals,\n        uint256 _chainId,\n        address _feeAddr,\n        uint256 _feeAmount\n    ) external returns (address) {\n        return address(new TokenProxy(tokenImage, _name, _symbol, _decimals, _chainId, msg.sender, _feeAddr, _feeAmount));\n    }\n}\n"
      },
      "contracts/upgradeable_contracts/modules/factory/TokenProxy.sol": {
        "content": "pragma solidity 0.7.5;\n\nimport \"../../../upgradeability/Proxy.sol\";\n\ninterface IPermittableTokenVersion {\n    function version() external pure returns (string memory);\n}\n\n/**\n * @title TokenProxy\n * @dev Helps to reduces the size of the deployed bytecode for automatically created tokens, by using a proxy contract.\n */\ncontract TokenProxy is Proxy {\n    // storage layout is copied from PermittableToken.sol\n    string internal name;\n    string internal symbol;\n    uint8 internal decimals;\n    mapping(address => uint256) internal balances;\n    uint256 internal totalSupply;\n    mapping(address => mapping(address => uint256)) internal allowed;\n    address internal owner;\n    bool internal mintingFinished;\n    address internal bridgeContractAddr;\n    address internal bridgeFeeAddr;\n    uint256 internal bridgeFeeAmount;\n    // string public constant version = \"1\";\n    bytes32 internal DOMAIN_SEPARATOR;\n\n    // bytes32 public constant PERMIT_TYPEHASH = 0xea2aa0a1be11a07ed86d755c93467f4f82362b452371d1ba94d1715123511acb;\n    mapping(address => uint256) internal nonces;\n    mapping(address => mapping(address => uint256)) internal expirations;\n\n    /**\n     * @dev Creates a non-upgradeable token proxy for PermitableToken.sol, initializes its eternalStorage.\n     * @param _tokenImage address of the token image used for mirroring all functions.\n     * @param _name token name.\n     * @param _symbol token symbol.\n     * @param _decimals token decimals.\n     * @param _chainId chain id for current network.\n     * @param _owner address of the owner for this contract.\n     */\n    constructor(\n        address _tokenImage,\n        string memory _name,\n        string memory _symbol,\n        uint8 _decimals,\n        uint256 _chainId,\n        address _owner,\n        address _feeAddr,\n        uint256 _feeAmount\n    ) {\n        string memory version = IPermittableTokenVersion(_tokenImage).version();\n        assembly {\n            // EIP 1967\n            // bytes32(uint256(keccak256('eip1967.proxy.implementation')) - 1)\n            sstore(0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc, _tokenImage)\n        }\n        name = _name;\n        symbol = _symbol;\n        decimals = _decimals;\n        owner = _owner; // _owner == HomeOmnibridge/ForeignOmnibridge mediator\n        bridgeContractAddr = _owner;\n        bridgeFeeAddr = _feeAddr;\n        bridgeFeeAmount = _feeAmount;\n\n        DOMAIN_SEPARATOR = keccak256(\n            abi.encode(\n                keccak256(\"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)\"),\n                keccak256(bytes(_name)),\n                keccak256(bytes(version)),\n                _chainId,\n                address(this)\n            )\n        );\n    }\n\n    /**\n     * @dev Retrieves the implementation contract address, mirrored token image.\n     * @return impl token image address.\n     */\n    function implementation() public view override returns (address impl) {\n        assembly {\n            impl := sload(0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc)\n        }\n    }\n\n    /**\n     * @dev Tells the current version of the token proxy interfaces.\n     */\n    function getTokenProxyInterfacesVersion()\n        external\n        pure\n        returns (\n            uint64 major,\n            uint64 minor,\n            uint64 patch\n        )\n    {\n        return (1, 0, 0);\n    }\n}\n"
      },
      "contracts/upgradeability/Proxy.sol": {
        "content": "pragma solidity 0.7.5;\n\n/**\n * @title Proxy\n * @dev Gives the possibility to delegate any call to a foreign implementation.\n */\nabstract contract Proxy {\n    /**\n     * @dev Tells the address of the implementation where every call will be delegated.\n     * @return address of the implementation to which it will be delegated\n     */\n    function implementation() public view virtual returns (address);\n\n    /**\n     * @dev Fallback function allowing to perform a delegatecall to the given implementation.\n     * This function will return whatever the implementation call returns\n     */\n    fallback() external payable {\n        // solhint-disable-previous-line no-complex-fallback\n        address _impl = implementation();\n        require(_impl != address(0));\n        assembly {\n            /*\n                0x40 is the \"free memory slot\", meaning a pointer to next slot of empty memory. mload(0x40)\n                loads the data in the free memory slot, so `ptr` is a pointer to the next slot of empty\n                memory. It's needed because we're going to write the return data of delegatecall to the\n                free memory slot.\n            */\n            let ptr := mload(0x40)\n            /*\n                `calldatacopy` is copy calldatasize bytes from calldata\n                First argument is the destination to which data is copied(ptr)\n                Second argument specifies the start position of the copied data.\n                    Since calldata is sort of its own unique location in memory,\n                    0 doesn't refer to 0 in memory or 0 in storage - it just refers to the zeroth byte of calldata.\n                    That's always going to be the zeroth byte of the function selector.\n                Third argument, calldatasize, specifies how much data will be copied.\n                    calldata is naturally calldatasize bytes long (same thing as msg.data.length)\n            */\n            calldatacopy(ptr, 0, calldatasize())\n            /*\n                delegatecall params explained:\n                gas: the amount of gas to provide for the call. `gas` is an Opcode that gives\n                    us the amount of gas still available to execution\n\n                _impl: address of the contract to delegate to\n\n                ptr: to pass copied data\n\n                calldatasize: loads the size of `bytes memory data`, same as msg.data.length\n\n                0, 0: These are for the `out` and `outsize` params. Because the output could be dynamic,\n                        these are set to 0, 0 so the output data will not be written to memory. The output\n                        data will be read using `returndatasize` and `returdatacopy` instead.\n\n                result: This will be 0 if the call fails and 1 if it succeeds\n            */\n            let result := delegatecall(gas(), _impl, ptr, calldatasize(), 0, 0)\n            /*\n\n            */\n            /*\n                ptr current points to the value stored at 0x40,\n                because we assigned it like ptr := mload(0x40).\n                Because we use 0x40 as a free memory pointer,\n                we want to make sure that the next time we want to allocate memory,\n                we aren't overwriting anything important.\n                So, by adding ptr and returndatasize,\n                we get a memory location beyond the end of the data we will be copying to ptr.\n                We place this in at 0x40, and any reads from 0x40 will now read from free memory\n            */\n            mstore(0x40, add(ptr, returndatasize()))\n            /*\n                `returndatacopy` is an Opcode that copies the last return data to a slot. `ptr` is the\n                    slot it will copy to, 0 means copy from the beginning of the return data, and size is\n                    the amount of data to copy.\n                `returndatasize` is an Opcode that gives us the size of the last return data. In this case, that is the size of the data returned from delegatecall\n            */\n            returndatacopy(ptr, 0, returndatasize())\n\n            /*\n                if `result` is 0, revert.\n                if `result` is 1, return `size` amount of data from `ptr`. This is the data that was\n                copied to `ptr` from the delegatecall return data\n            */\n            switch result\n                case 0 {\n                    revert(ptr, returndatasize())\n                }\n                default {\n                    return(ptr, returndatasize())\n                }\n        }\n    }\n}\n"
      }
    },
    "settings": {
      "optimizer": {
        "enabled": true,
        "runs": 200
      },
      "outputSelection": {
        "*": {
          "*": [
            "evm.bytecode",
            "evm.deployedBytecode",
            "devdoc",
            "userdoc",
            "metadata",
            "abi"
          ]
        }
      },
      "libraries": {}
    }
  }}