ETH Price: $3,489.35 (+3.66%)
Gas: 3 Gwei

Contract

0x7f2a18900A978D4390a3640e34739BB697777A71
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
Value
0x60c06040190063162024-01-14 16:27:59168 days ago1705249679IN
 Create: StarknetERC20Bridge
0 ETH0.1370985930.09307298

View more zero value Internal Transactions in Advanced View mode

Advanced mode:
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
StarknetERC20Bridge

Compiler Version
v0.8.20+commit.a1b79de6

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion, Apache-2.0 license
File 1 of 30 : StarknetERC20Bridge.sol
/*
  Copyright 2019-2023 StarkWare Industries Ltd.

  Licensed under the Apache License, Version 2.0 (the "License").
  You may not use this file except in compliance with the License.
  You may obtain a copy of the License at

  https://www.starkware.co/open-source-license/

  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions
  and limitations under the License.
*/
// SPDX-License-Identifier: Apache-2.0.
pragma solidity ^0.8.20;

import "src/solidity/LegacyBridge.sol";

contract StarknetERC20Bridge is LegacyBridge {
    function identify() external pure override returns (string memory) {
        return "StarkWare_StarknetERC20Bridge_2.0_4";
    }
}

File 2 of 30 : AccessControl.sol
/*
  Copyright 2019-2023 StarkWare Industries Ltd.

  Licensed under the Apache License, Version 2.0 (the "License").
  You may not use this file except in compliance with the License.
  You may obtain a copy of the License at

  https://www.starkware.co/open-source-license/

  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions
  and limitations under the License.
*/
// SPDX-License-Identifier: MIT
// Based on OpenZeppelin Contract (access/AccessControl.sol)
// StarkWare modification (storage slot, change to library).

pragma solidity ^0.8.0;

import "third_party/open_zeppelin/utils/Strings.sol";

/*
  Library module that allows using contracts to implement role-based access
  control mechanisms. This is a lightweight version that doesn't allow enumerating role
  members except through off-chain means by accessing the contract event logs. Some
  applications may benefit from on-chain enumerability, for those cases see
  {AccessControlEnumerable}.
 
  Roles are referred to by their `bytes32` identifier. These should be exposed
  in the external API and be unique. The best way to achieve this is by
  using `public constant` hash digests:
 
  ```
  bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
  ```
 
  Roles can be used to represent a set of permissions. To restrict access to a
  function call, use {hasRole}:
 
  ```
  function foo() public {
      require(hasRole(MY_ROLE, msg.sender));
      ...
  }
  ```
 
  Roles can be granted and revoked dynamically via the {grantRole} and
  {revokeRole} functions. Each role has an associated admin role, and only
  accounts that have a role's admin role can call {grantRole} and {revokeRole}.
 
  By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
  that only accounts with this role will be able to grant or revoke other
  roles. More complex role relationships can be created by using
  {_setRoleAdmin}.
 
  WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
  grant and revoke this role. Extra precautions should be taken to secure
  accounts that have been granted it.
 
  OpenZeppelin implementation changed as following:
  1. Converted to library.
  2. Storage valiable {_roles} moved outside of linear storage,
     to avoid potential storage conflicts or corruption.
  3. Removed ERC165 support.
*/
library AccessControl {
    /*
      Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
     
      `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
      {RoleAdminChanged} not being emitted signaling this.
     
      Available since v3.1.
    */
    event RoleAdminChanged(
        bytes32 indexed role,
        bytes32 indexed previousAdminRole,
        bytes32 indexed newAdminRole
    );

    /*
      Emitted when `account` is granted `role`.
     
      `sender` is the account that originated the contract call, an admin role
      bearer except when using {AccessControl-_setupRole}.
    */
    event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);

    /*
      Emitted when `account` is revoked `role`.
     
      `sender` is the account that originated the contract call:
        - if using `revokeRole`, it is the admin role bearer
        - if using `renounceRole`, it is the role bearer (i.e. `account`).
    */
    event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);

    struct RoleData {
        mapping(address => bool) members;
        bytes32 adminRole;
    }

    // Context interface functions.
    function _msgSender() internal view returns (address) {
        return msg.sender;
    }

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

    // The storage variable `_roles` is located away from the contract linear area (low storage addresses)
    // to prevent potential collision/corruption in upgrade scenario.
    // Slot = Web3.keccak(text="AccesControl_Storage_Slot").
    bytes32 constant rolesSlot = 0x53e43b954ba190a7e49386f1f78b01dcd9f628db23f432fa029a7dfd6d98e8fb;

    function _roles() private pure returns (mapping(bytes32 => RoleData) storage roles) {
        assembly {
            roles.slot := rolesSlot
        }
    }

    bytes32 constant DEFAULT_ADMIN_ROLE = 0x00;

    /*
      Modifier that checks that an account has a specific role. Reverts
      with a standardized message including the required role.
      
      The format of the revert reason is given by the following regular expression:
      
      /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
      
      Available since v4.1.
    */
    modifier onlyRole(bytes32 role) {
        _checkRole(role);
        _;
    }

    /*
      Returns `true` if `account` has been granted `role`.
    */
    function hasRole(bytes32 role, address account) internal view returns (bool) {
        return _roles()[role].members[account];
    }

    /*
      Revert with a standard message if `_msgSender()` is missing `role`.
      Overriding this function changes the behavior of the {onlyRole} modifier.
     
      Format of the revert message is described in {_checkRole}.
     
      Available since v4.6.
    */
    function _checkRole(bytes32 role) internal view {
        _checkRole(role, _msgSender());
    }

    /*
      Revert with a standard message if `account` is missing `role`.
     
      The format of the revert reason is given by the following regular expression:
     
       /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/.
    */
    function _checkRole(bytes32 role, address account) internal view {
        if (!hasRole(role, account)) {
            revert(
                string(
                    abi.encodePacked(
                        "AccessControl: account ",
                        Strings.toHexString(uint160(account), 20),
                        " is missing role ",
                        Strings.toHexString(uint256(role), 32)
                    )
                )
            );
        }
    }

    /*
      Returns the admin role that controls `role`. See {grantRole} and
      {revokeRole}.
     
      To change a role's admin, use {_setRoleAdmin}.
    */
    function getRoleAdmin(bytes32 role) internal view returns (bytes32) {
        return _roles()[role].adminRole;
    }

    /*
      Grants `role` to `account`.
     
      If `account` had not been already granted `role`, emits a {RoleGranted}
      event.
     
      Requirements:
     
      - the caller must have ``role``'s admin role.
     
      May emit a {RoleGranted} event.
    */
    function grantRole(bytes32 role, address account) internal onlyRole(getRoleAdmin(role)) {
        _grantRole(role, account);
    }

    /*
      Revokes `role` from `account`.
     
      If `account` had been granted `role`, emits a {RoleRevoked} event.
     
      Requirements:
     
      - the caller must have ``role``'s admin role.
     
      * May emit a {RoleRevoked} event.
    */
    function revokeRole(bytes32 role, address account) internal onlyRole(getRoleAdmin(role)) {
        _revokeRole(role, account);
    }

    /*
      Revokes `role` from the calling account.
     
      Roles are often managed via {grantRole} and {revokeRole}: this function's
      purpose is to provide a mechanism for accounts to lose their privileges
      if they are compromised (such as when a trusted device is misplaced).
     
      If the calling account had been revoked `role`, emits a {RoleRevoked}
      event.
     
      Requirements:
     
      - the caller must be `account`.
     
      May emit a {RoleRevoked} event.
    */
    function renounceRole(bytes32 role, address account) internal {
        require(account == _msgSender(), "AccessControl: can only renounce roles for self");

        _revokeRole(role, account);
    }

    /*
      Grants `role` to `account`.
     
      If `account` had not been already granted `role`, emits a {RoleGranted}
      event. Note that unlike {grantRole}, this function doesn't perform any
      checks on the calling account.
     
      May emit a {RoleGranted} event.
     
      [WARNING]virtual
      ====
      This function should only be called from the constructor when setting
      up the initial roles for the system.
     
      Using this function in any other way is effectively circumventing the admin
      system imposed by {AccessControl}.
      ====
     
      NOTE: This function is deprecated in favor of {_grantRole}.
    */
    function _setupRole(bytes32 role, address account) internal {
        _grantRole(role, account);
    }

    /*
      Sets `adminRole` as ``role``'s admin role.
     
      Emits a {RoleAdminChanged} event.
    */
    function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal {
        bytes32 previousAdminRole = getRoleAdmin(role);
        _roles()[role].adminRole = adminRole;
        emit RoleAdminChanged(role, previousAdminRole, adminRole);
    }

    /*
      Grants `role` to `account`.
     
      Internal function without access restriction.
     
      May emit a {RoleGranted} event.
    */
    function _grantRole(bytes32 role, address account) internal {
        if (!hasRole(role, account)) {
            _roles()[role].members[account] = true;
            emit RoleGranted(role, account, _msgSender());
        }
    }

    /*
      Revokes `role` from `account`.
     
      Internal function without access restriction.
     
      May emit a {RoleRevoked} event.
    */
    function _revokeRole(bytes32 role, address account) internal {
        if (hasRole(role, account)) {
            _roles()[role].members[account] = false;
            emit RoleRevoked(role, account, _msgSender());
        }
    }
}

File 3 of 30 : Addresses.sol
/*
  Copyright 2019-2023 StarkWare Industries Ltd.

  Licensed under the Apache License, Version 2.0 (the "License").
  You may not use this file except in compliance with the License.
  You may obtain a copy of the License at

  https://www.starkware.co/open-source-license/

  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions
  and limitations under the License.
*/
// SPDX-License-Identifier: Apache-2.0.
pragma solidity ^0.8.0;

/*
  Common Utility Libraries.
  I. Addresses (extending address).
*/
library Addresses {
    /*
      Note: isContract function has some known limitation.
      See https://github.com/OpenZeppelin/
      openzeppelin-contracts/blob/master/contracts/utils/Address.sol.
    */
    function isContract(address account) internal view returns (bool) {
        uint256 size;
        assembly {
            size := extcodesize(account)
        }
        return size > 0;
    }

    function performEthTransfer(address recipient, uint256 amount) internal {
        if (amount == 0) return;
        (bool success, ) = recipient.call{value: amount}(""); // NOLINT: low-level-calls.
        require(success, "ETH_TRANSFER_FAILED");
    }

    /*
      Safe wrapper around ERC20/ERC721 calls.
      This is required because many deployed ERC20 contracts don't return a value.
      See https://github.com/ethereum/solidity/issues/4116.
    */
    function safeTokenContractCall(address tokenAddress, bytes memory callData) internal {
        require(isContract(tokenAddress), "BAD_TOKEN_ADDRESS");
        // NOLINTNEXTLINE: low-level-calls.
        (bool success, bytes memory returndata) = tokenAddress.call(callData);
        require(success, string(returndata));

        if (returndata.length > 0) {
            require(abi.decode(returndata, (bool)), "TOKEN_OPERATION_FAILED");
        }
    }
}

File 4 of 30 : BlockDirectCall.sol
/*
  Copyright 2019-2023 StarkWare Industries Ltd.

  Licensed under the Apache License, Version 2.0 (the "License").
  You may not use this file except in compliance with the License.
  You may obtain a copy of the License at

  https://www.starkware.co/open-source-license/

  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions
  and limitations under the License.
*/
// SPDX-License-Identifier: Apache-2.0.
pragma solidity ^0.8.0;

/*
  This contract provides means to block direct call of an external function.
  A derived contract (e.g. MainDispatcherBase) should decorate sensitive functions with the
  notCalledDirectly modifier, thereby preventing it from being called directly, and allowing only
  calling using delegate_call.
*/
abstract contract BlockDirectCall {
    address immutable this_;

    constructor() {
        this_ = address(this);
    }

    modifier notCalledDirectly() {
        require(this_ != address(this), "DIRECT_CALL_DISALLOWED");
        _;
    }
}

File 5 of 30 : CairoConstants.sol
/*
  Copyright 2019-2023 StarkWare Industries Ltd.

  Licensed under the Apache License, Version 2.0 (the "License").
  You may not use this file except in compliance with the License.
  You may obtain a copy of the License at

  https://www.starkware.co/open-source-license/

  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions
  and limitations under the License.
*/
// SPDX-License-Identifier: Apache-2.0.
pragma solidity ^0.8.0;

library CairoConstants {
    uint256 public constant FIELD_PRIME =
        0x800000000000011000000000000000000000000000000000000000000000001;
}

File 6 of 30 : ContractInitializer.sol
/*
  Copyright 2019-2023 StarkWare Industries Ltd.

  Licensed under the Apache License, Version 2.0 (the "License").
  You may not use this file except in compliance with the License.
  You may obtain a copy of the License at

  https://www.starkware.co/open-source-license/

  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions
  and limitations under the License.
*/
// SPDX-License-Identifier: Apache-2.0.
pragma solidity ^0.8.0;

/**
  Interface for contract initialization.
  The functions it exposes are the app specific parts of the contract initialization,
  and are called by the ProxySupport contract that implement the generic part of behind-proxy
  initialization.
*/
abstract contract ContractInitializer {
    /*
      The number of sub-contracts that the proxied contract consists of.
    */
    function numOfSubContracts() internal pure virtual returns (uint256);

    /*
      Indicates if the proxied contract has already been initialized.
      Used to prevent re-init.
    */
    function isInitialized() internal view virtual returns (bool);

    /*
      Validates the init data that is passed into the proxied contract.
    */
    function validateInitData(bytes calldata data) internal view virtual;

    /*
      For a proxied contract that consists of sub-contracts, this function processes
      the sub-contract addresses, e.g. validates them, stores them etc.
    */
    function processSubContractAddresses(bytes calldata subContractAddresses) internal virtual;

    /*
      This function applies the logic of initializing the proxied contract state,
      e.g. setting root values etc.
    */
    function initializeContractState(bytes calldata data) internal virtual;
}

File 7 of 30 : Fees.sol
/*
  Copyright 2019-2023 StarkWare Industries Ltd.

  Licensed under the Apache License, Version 2.0 (the "License").
  You may not use this file except in compliance with the License.
  You may obtain a copy of the License at

  https://www.starkware.co/open-source-license/

  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions
  and limitations under the License.
*/
// SPDX-License-Identifier: Apache-2.0.
pragma solidity ^0.8.0;

uint256 constant DEPOSIT_FEE_GAS = 20000;
uint256 constant DEPLOYMENT_FEE_GAS = 100000;
uint256 constant DEFAULT_WEI_PER_GAS = 5 * 10**9;
uint256 constant MIN_FEE = 10**12;
uint256 constant MAX_FEE = 10**16;

library Fees {
    function estimateDepositFee() internal pure returns (uint256) {
        return DEPOSIT_FEE_GAS * DEFAULT_WEI_PER_GAS;
    }

    function estimateEnrollmentFee() internal pure returns (uint256) {
        return DEPLOYMENT_FEE_GAS * DEFAULT_WEI_PER_GAS;
    }

    function checkDepositFee(uint256 feeWei) internal pure {
        checkFee(feeWei, estimateDepositFee());
    }

    function checkEnrollmentFee(uint256 feeWei) internal pure {
        checkFee(feeWei, estimateEnrollmentFee());
    }

    function checkFee(
        uint256 feeWei,
        uint256 /* feeEstimate */
    ) internal pure {
        require(feeWei >= MIN_FEE, "INSUFFICIENT_FEE_VALUE");
        require(feeWei <= MAX_FEE, "FEE_VALUE_TOO_HIGH");
    }
}

File 8 of 30 : Felt252.sol
/*
  Copyright 2019-2023 StarkWare Industries Ltd.

  Licensed under the Apache License, Version 2.0 (the "License").
  You may not use this file except in compliance with the License.
  You may obtain a copy of the License at

  https://www.starkware.co/open-source-license/

  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions
  and limitations under the License.
*/
// SPDX-License-Identifier: Apache-2.0.
pragma solidity ^0.8.0;

import "starkware/cairo/eth/CairoConstants.sol";

/**
 * @dev String to felt functions.
 *
 * These functions convert string to felt (felt252) uint value.
 * The felt value is the Starknet short string representation.
 *
 * As felt value is bound by the field prime, it limits the length of the represented string.
 * For felt252 the limit is 31 characters.
 *
 * `safeToFelt()` converts to felt as many as 31 characters of the string.
 * i.e. for a long string: safeToFelt(string) == toFelt(string[:31]).
 *
 * When `toFelt()` accepts a long string - it fails and the call revert.
 */
library Felt252 {
    uint256 constant MAX_SHORT_STRING_LENGTH = 31;

    /**
      Convert a string to felt uint value.
      Reverts if the string is longer than 31 characters.
     */
    function toFelt(string memory shortString) internal pure returns (uint256) {
        uint256 length = strlen(shortString);
        return strToFelt(shortString, length);
    }

    /**
      Safely convert a string to felt uint value.
      For a string up to 31 characters, behaves identically ot `toFelt`.
      For longer strings, it returns the felt representation of the first 31 characters.
     */
    function safeToFelt(string memory string_) internal pure returns (uint256) {
        uint256 len = min(MAX_SHORT_STRING_LENGTH, strlen(string_));
        return strToFelt(string_, len);
    }

    function strToFelt(string memory string_, uint256 length) private pure returns (uint256) {
        require(length <= MAX_SHORT_STRING_LENGTH, "STRING_TOO_LONG");
        uint256 asUint;

        // As we process only short strings (<=31 chars),
        // we can look no further than the first 32 bytes of the string.
        // We convert first 32 bytes of the string to a uint.
        assembly {
            asUint := mload(add(string_, 32))
        }

        // We shift left the unused bits, so we don't get lsb zero padding.
        // The shift is 8 bits for every unused characters (of the looked at 32 bytes).
        uint256 felt252 = asUint >> (8 * (32 - length));
        return felt252;
    }

    /**
      Returns string length.
     */
    function strlen(string memory string_) private pure returns (uint256) {
        bytes memory bytes_;
        assembly {
            bytes_ := string_
        }
        return bytes_.length;
    }

    function min(uint256 a, uint256 b) private pure returns (uint256) {
        return a < b ? a : b;
    }
}

library UintFelt252 {
    function isValidL2Address(uint256 l2Address) internal pure returns (bool) {
        return (l2Address != 0 && isFelt(l2Address));
    }

    function isFelt(uint256 maybeFelt) internal pure returns (bool) {
        return (maybeFelt < CairoConstants.FIELD_PRIME);
    }
}

File 9 of 30 : IERC20.sol
/*
  Copyright 2019-2023 StarkWare Industries Ltd.

  Licensed under the Apache License, Version 2.0 (the "License").
  You may not use this file except in compliance with the License.
  You may obtain a copy of the License at

  https://www.starkware.co/open-source-license/

  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions
  and limitations under the License.
*/
// SPDX-License-Identifier: Apache-2.0.
pragma solidity ^0.8.0;

/**
  Interface of the ERC20 standard as defined in the EIP. Does not include
  the optional functions; to access them see {ERC20Detailed}.
*/
interface IERC20 {
    function totalSupply() external view returns (uint256);

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

    function transfer(address recipient, uint256 amount) external returns (bool);

    function allowance(address owner, address spender) external view returns (uint256);

    function approve(address spender, uint256 amount) external returns (bool);

    function transferFrom(
        address sender,
        address recipient,
        uint256 amount
    ) external returns (bool);

    event Transfer(address indexed from, address indexed to, uint256 value);

    event Approval(address indexed owner, address indexed spender, uint256 value);
}

File 10 of 30 : IERC20Metadata.sol
/*
  Copyright 2019-2023 StarkWare Industries Ltd.

  Licensed under the Apache License, Version 2.0 (the "License").
  You may not use this file except in compliance with the License.
  You may obtain a copy of the License at

  https://www.starkware.co/open-source-license/

  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions
  and limitations under the License.
*/
// SPDX-License-Identifier: Apache-2.0.
pragma solidity ^0.8.0;

import "./IERC20.sol";

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

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

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

File 11 of 30 : IStarkgateBridge.sol
/*
  Copyright 2019-2023 StarkWare Industries Ltd.

  Licensed under the Apache License, Version 2.0 (the "License").
  You may not use this file except in compliance with the License.
  You may obtain a copy of the License at

  https://www.starkware.co/open-source-license/

  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions
  and limitations under the License.
*/
// SPDX-License-Identifier: Apache-2.0.
pragma solidity ^0.8.0;

interface IStarkgateBridge {
    /**
       Enrolls a token in the Starknet Token Bridge system.
    */
    function enrollToken(address token) external payable;

    /**
      Deactivates token bridging.
      Deactivated token does not accept deposits.
     */
    function deactivate(address token) external;
}

File 12 of 30 : IStarkgateManager.sol
/*
  Copyright 2019-2023 StarkWare Industries Ltd.

  Licensed under the Apache License, Version 2.0 (the "License").
  You may not use this file except in compliance with the License.
  You may obtain a copy of the License at

  https://www.starkware.co/open-source-license/

  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions
  and limitations under the License.
*/
// SPDX-License-Identifier: Apache-2.0.
pragma solidity ^0.8.0;

interface IStarkgateManager {
    /**
      Returns the address of the Starkgate Registry contract.
    */
    function getRegistry() external view returns (address);

    // TODO: refactor the doc.
    /**
      Adds an existing bridge to the Starkgate system for a specific token.
     */
    function addExistingBridge(address token, address bridge) external;

    /**
      Deactivates bridging of a specific token.
      A deactivated token is blocked for deposits and cannot be re-deployed.     
      */
    function deactivateToken(address token) external;

    /**
      Block a specific token from being used in the StarkGate.
      A blocked token cannot be deployed.
      */
    function blockToken(address token) external;

    /**
      Enrolls a token bridge for a specific token.
     */
    function enrollTokenBridge(address token) external payable;
}

File 13 of 30 : IStarkgateRegistry.sol
/*
  Copyright 2019-2023 StarkWare Industries Ltd.

  Licensed under the Apache License, Version 2.0 (the "License").
  You may not use this file except in compliance with the License.
  You may obtain a copy of the License at

  https://www.starkware.co/open-source-license/

  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions
  and limitations under the License.
*/
// SPDX-License-Identifier: Apache-2.0.
pragma solidity ^0.8.0;

interface IStarkgateRegistry {
    /**
      Returns the bridge that handles the given token.
    */
    function getBridge(address token) external view returns (address);

    /**
      Add a mapping between a token and the bridge handling it.
    */
    function enlistToken(address token, address bridge) external;

    /**
      Block a specific token from being used in the StarkGate.
      A blocked token cannot be deployed.
      */
    function blockToken(address token) external;

    /**
      Retrieves a list of bridge addresses that have facilitated withdrawals 
      for the specified token.
     */
    function getWithdrawalBridges(address token) external view returns (address[] memory bridges);

    /**
      Using this function a bridge removes enlisting of its token from the registry.
      The bridge must implement `isServicingToken(address token)` (see `IStarkgateService`).
     */
    function selfRemove(address token) external;
}

File 14 of 30 : IStarkgateService.sol
/*
  Copyright 2019-2023 StarkWare Industries Ltd.

  Licensed under the Apache License, Version 2.0 (the "License").
  You may not use this file except in compliance with the License.
  You may obtain a copy of the License at

  https://www.starkware.co/open-source-license/

  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions
  and limitations under the License.
*/
// SPDX-License-Identifier: Apache-2.0.
pragma solidity ^0.8.0;

interface IStarkgateService {
    /**
    Checks whether the calling contract is providing a service for the specified token.
    Returns True if the calling contract is providing a service for the token, otherwise false.
   */
    function isServicingToken(address token) external view returns (bool);
}

File 15 of 30 : IStarknetMessaging.sol
/*
  Copyright 2019-2023 StarkWare Industries Ltd.

  Licensed under the Apache License, Version 2.0 (the "License").
  You may not use this file except in compliance with the License.
  You may obtain a copy of the License at

  https://www.starkware.co/open-source-license/

  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions
  and limitations under the License.
*/
// SPDX-License-Identifier: Apache-2.0.
pragma solidity ^0.8.0;

import "starkware/starknet/solidity/IStarknetMessagingEvents.sol";

interface IStarknetMessaging is IStarknetMessagingEvents {
    /**
      Returns the max fee (in Wei) that StarkNet will accept per single message.
    */
    function getMaxL1MsgFee() external pure returns (uint256);

    /**
      Returns the msg_fee + 1 for the message with the given 'msgHash',
      or 0 if no message with such a hash is pending.
    */
    function l1ToL2Messages(bytes32 msgHash) external view returns (uint256);

    /**
      Sends a message to an L2 contract.
      This function is payable, the payed amount is the message fee.

      Returns the hash of the message and the nonce of the message.
    */
    function sendMessageToL2(
        uint256 toAddress,
        uint256 selector,
        uint256[] calldata payload
    ) external payable returns (bytes32, uint256);

    /**
      Consumes a message that was sent from an L2 contract.

      Returns the hash of the message.
    */
    function consumeMessageFromL2(uint256 fromAddress, uint256[] calldata payload)
        external
        returns (bytes32);

    /**
      Starts the cancellation of an L1 to L2 message.
      A message can be canceled messageCancellationDelay() seconds after this function is called.

      Note: This function may only be called for a message that is currently pending and the caller
      must be the sender of the that message.
    */
    function startL1ToL2MessageCancellation(
        uint256 toAddress,
        uint256 selector,
        uint256[] calldata payload,
        uint256 nonce
    ) external returns (bytes32);

    /**
      Cancels an L1 to L2 message, this function should be called at least
      messageCancellationDelay() seconds after the call to startL1ToL2MessageCancellation().
      A message may only be cancelled by its sender.
      If the message is missing, the call will revert.

      Note that the message fee is not refunded.
    */
    function cancelL1ToL2Message(
        uint256 toAddress,
        uint256 selector,
        uint256[] calldata payload,
        uint256 nonce
    ) external returns (bytes32);
}

File 16 of 30 : IStarknetMessagingEvents.sol
/*
  Copyright 2019-2023 StarkWare Industries Ltd.

  Licensed under the Apache License, Version 2.0 (the "License").
  You may not use this file except in compliance with the License.
  You may obtain a copy of the License at

  https://www.starkware.co/open-source-license/

  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions
  and limitations under the License.
*/
// SPDX-License-Identifier: Apache-2.0.
pragma solidity ^0.8.0;

interface IStarknetMessagingEvents {
    // This event needs to be compatible with the one defined in Output.sol.
    event LogMessageToL1(uint256 indexed fromAddress, address indexed toAddress, uint256[] payload);

    // An event that is raised when a message is sent from L1 to L2.
    event LogMessageToL2(
        address indexed fromAddress,
        uint256 indexed toAddress,
        uint256 indexed selector,
        uint256[] payload,
        uint256 nonce,
        uint256 fee
    );

    // An event that is raised when a message from L2 to L1 is consumed.
    event ConsumedMessageToL1(
        uint256 indexed fromAddress,
        address indexed toAddress,
        uint256[] payload
    );

    // An event that is raised when a message from L1 to L2 is consumed.
    event ConsumedMessageToL2(
        address indexed fromAddress,
        uint256 indexed toAddress,
        uint256 indexed selector,
        uint256[] payload,
        uint256 nonce
    );

    // An event that is raised when a message from L1 to L2 Cancellation is started.
    event MessageToL2CancellationStarted(
        address indexed fromAddress,
        uint256 indexed toAddress,
        uint256 indexed selector,
        uint256[] payload,
        uint256 nonce
    );

    // An event that is raised when a message from L1 to L2 is canceled.
    event MessageToL2Canceled(
        address indexed fromAddress,
        uint256 indexed toAddress,
        uint256 indexed selector,
        uint256[] payload,
        uint256 nonce
    );
}

File 17 of 30 : Identity.sol
/*
  Copyright 2019-2023 StarkWare Industries Ltd.

  Licensed under the Apache License, Version 2.0 (the "License").
  You may not use this file except in compliance with the License.
  You may obtain a copy of the License at

  https://www.starkware.co/open-source-license/

  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions
  and limitations under the License.
*/
// SPDX-License-Identifier: Apache-2.0.
pragma solidity ^0.8.0;

interface Identity {
    /*
      Allows a caller to ensure that the provided address is of the expected type and version.
    */
    function identify() external pure returns (string memory);
}

File 18 of 30 : LegacyBridge.sol
/*
  Copyright 2019-2023 StarkWare Industries Ltd.

  Licensed under the Apache License, Version 2.0 (the "License").
  You may not use this file except in compliance with the License.
  You may obtain a copy of the License at

  https://www.starkware.co/open-source-license/

  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions
  and limitations under the License.
*/
// SPDX-License-Identifier: Apache-2.0.
pragma solidity ^0.8.20;

import "src/solidity/StarknetTokenBridge.sol";
import "starkware/solidity/components/OverrideLegacyProxyGovernance.sol";
import "starkware/solidity/libraries/NamedStorage.sol";

/*
  Common implementation for the Upgraded legacy bridges, contains all the legacy relevant
  code except for the handling of Eth transfers (vs. ERC20).
*/
abstract contract LegacyBridge is StarknetTokenBridge, OverrideLegacyProxyGovernance {
    /* Legacy events */
    event LogDepositCancelRequest(
        address indexed sender,
        uint256 amount,
        uint256 indexed l2Recipient,
        uint256 nonce
    );
    event LogDepositReclaimed(
        address indexed sender,
        uint256 amount,
        uint256 indexed l2Recipient,
        uint256 nonce
    );
    event LogDeposit(
        address indexed sender,
        uint256 amount,
        uint256 indexed l2Recipient,
        uint256 nonce,
        uint256 fee
    );

    function bridgedToken() internal view returns (address) {
        return NamedStorage.getAddressValue(BRIDGED_TOKEN_TAG);
    }

    function depositors() internal pure returns (mapping(uint256 => address) storage) {
        return NamedStorage.uintToAddressMapping(DEPOSITOR_ADDRESSES_TAG);
    }

    modifier onlyDepositor(uint256 nonce) {
        require(depositors()[nonce] == msg.sender, "ONLY_DEPOSITOR");
        _;
    }

    /*
      Upgraded legacy bridge does not support token enrollment.
    */
    function enrollToken(
        address /*token*/
    ) external payable virtual override {
        revert("UNSUPPORTED");
    }

    /// Support Legacy ABI.
    /*
      Deposit, using the old version ABI.
      Note - The actual L1-L2 message sent to the l2-bridge is of the new format.
    */
    function deposit(uint256 amount, uint256 l2Recipient) external payable {
        uint256[] memory noMessage = new uint256[](0);
        address token = bridgedToken();
        uint256 fee = acceptDeposit(token, amount);
        uint256 nonce = sendDepositMessage(
            token,
            amount,
            l2Recipient,
            noMessage,
            HANDLE_TOKEN_DEPOSIT_SELECTOR,
            fee
        );
        emitDepositEvent(
            token,
            amount,
            l2Recipient,
            noMessage,
            HANDLE_TOKEN_DEPOSIT_SELECTOR,
            nonce,
            fee
        );
        // Emits a deposit event of the old ABI, emitted in addition to the new one.
        emit LogDeposit(msg.sender, amount, l2Recipient, nonce, fee);
    }

    function maxTotalBalance() external view returns (uint256) {
        return getMaxTotalBalance(bridgedToken());
    }

    function withdraw(uint256 amount, address recipient) external {
        withdraw(bridgedToken(), amount, recipient);
    }

    function withdraw(uint256 amount) external {
        withdraw(bridgedToken(), amount, msg.sender);
    }

    /*
      This comsume message override the base implementation from StarknetTokenBridge,
      and supports withdraw of both the new format and the legacy format.
    */
    function consumeMessage(
        address token,
        uint256 amount,
        address recipient
    ) internal virtual override {
        require(l2TokenBridge() != 0, "L2_BRIDGE_NOT_SET");
        uint256 u_recipient = uint256(uint160(recipient));
        uint256 amount_low = amount & (UINT256_PART_SIZE - 1);
        uint256 amount_high = amount >> UINT256_PART_SIZE_BITS;

        // Compose the new format of L2-L1 consumption.
        uint256[] memory payload = new uint256[](5);
        payload[0] = TRANSFER_FROM_STARKNET;
        payload[1] = u_recipient;
        payload[2] = uint256(uint160(token));
        payload[3] = amount_low;
        payload[4] = amount_high;
        // Contain failure of comsumption (e.g. no message to consume).
        try messagingContract().consumeMessageFromL2(l2TokenBridge(), payload) {} catch Error(
            string memory
        ) {
            // Upon failure with the new format,
            // compose the old format,
            // in case the withdrawal was initiated on a bridge with an older version.
            payload = new uint256[](4);
            payload[0] = TRANSFER_FROM_STARKNET;
            payload[1] = u_recipient;
            payload[2] = amount_low;
            payload[3] = amount_high;
            messagingContract().consumeMessageFromL2(l2TokenBridge(), payload);
        }
    }

    // The old version of depositCancelRequest (renamed to avoid confusion).
    // Supports cancellation of deposits that were made before the L1 bridge was upgraded.
    function legacyDepositCancelRequest(
        uint256 amount,
        uint256 l2Recipient,
        uint256 nonce
    ) external onlyDepositor(nonce) {
        messagingContract().startL1ToL2MessageCancellation(
            l2TokenBridge(),
            HANDLE_DEPOSIT_SELECTOR,
            legacyDepositMessagePayload(amount, l2Recipient),
            nonce
        );
        emit LogDepositCancelRequest(msg.sender, amount, l2Recipient, nonce);
    }

    // The old version of depositReclaim (renamed to avoid confusion).
    // Supports reclaim of deposits that were made before the L1 bridge was upgraded.
    function legacyDepositReclaim(
        uint256 amount,
        uint256 l2Recipient,
        uint256 nonce
    ) external onlyDepositor(nonce) {
        messagingContract().cancelL1ToL2Message(
            l2TokenBridge(),
            HANDLE_DEPOSIT_SELECTOR,
            legacyDepositMessagePayload(amount, l2Recipient),
            nonce
        );

        transferOutFunds(bridgedToken(), amount, msg.sender);
        emit LogDepositReclaimed(msg.sender, amount, l2Recipient, nonce);
    }

    // Construct the deposit l1-l2 message payload of the older version.
    // (renamed to avoid confusion).
    function legacyDepositMessagePayload(uint256 amount, uint256 l2Recipient)
        private
        pure
        returns (uint256[] memory)
    {
        uint256[] memory payload = new uint256[](3);
        payload[0] = l2Recipient;
        payload[1] = amount & (UINT256_PART_SIZE - 1);
        payload[2] = amount >> UINT256_PART_SIZE_BITS;
        return payload;
    }
}

File 19 of 30 : NamedStorage.sol
/*
  Copyright 2019-2023 StarkWare Industries Ltd.

  Licensed under the Apache License, Version 2.0 (the "License").
  You may not use this file except in compliance with the License.
  You may obtain a copy of the License at

  https://www.starkware.co/open-source-license/

  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions
  and limitations under the License.
*/
// SPDX-License-Identifier: Apache-2.0.
pragma solidity ^0.8.0;

/*
  Library to provide basic storage, in storage location out of the low linear address space.

  New types of storage variables should be added here upon need.
*/
library NamedStorage {
    function bytes32ToBoolMapping(string memory tag_)
        internal
        pure
        returns (mapping(bytes32 => bool) storage randomVariable)
    {
        bytes32 location = keccak256(abi.encodePacked(tag_));
        assembly {
            randomVariable.slot := location
        }
    }

    function bytes32ToUint256Mapping(string memory tag_)
        internal
        pure
        returns (mapping(bytes32 => uint256) storage randomVariable)
    {
        bytes32 location = keccak256(abi.encodePacked(tag_));
        assembly {
            randomVariable.slot := location
        }
    }

    function addressToUint256Mapping(string memory tag_)
        internal
        pure
        returns (mapping(address => uint256) storage randomVariable)
    {
        bytes32 location = keccak256(abi.encodePacked(tag_));
        assembly {
            randomVariable.slot := location
        }
    }

    function bytes32ToAddressMapping(string memory tag_)
        internal
        pure
        returns (mapping(bytes32 => address) storage randomVariable)
    {
        bytes32 location = keccak256(abi.encodePacked(tag_));
        assembly {
            randomVariable.slot := location
        }
    }

    function uintToAddressMapping(string memory tag_)
        internal
        pure
        returns (mapping(uint256 => address) storage randomVariable)
    {
        bytes32 location = keccak256(abi.encodePacked(tag_));
        assembly {
            randomVariable.slot := location
        }
    }

    function addressToAddressMapping(string memory tag_)
        internal
        pure
        returns (mapping(address => address) storage randomVariable)
    {
        bytes32 location = keccak256(abi.encodePacked(tag_));
        assembly {
            randomVariable.slot := location
        }
    }

    function addressToAddressListMapping(string memory tag_)
        internal
        pure
        returns (mapping(address => address[]) storage randomVariable)
    {
        bytes32 location = keccak256(abi.encodePacked(tag_));
        assembly {
            randomVariable.slot := location
        }
    }

    function addressToBoolMapping(string memory tag_)
        internal
        pure
        returns (mapping(address => bool) storage randomVariable)
    {
        bytes32 location = keccak256(abi.encodePacked(tag_));
        assembly {
            randomVariable.slot := location
        }
    }

    function getUintValue(string memory tag_) internal view returns (uint256 retVal) {
        bytes32 slot = keccak256(abi.encodePacked(tag_));
        assembly {
            retVal := sload(slot)
        }
    }

    function setUintValue(string memory tag_, uint256 value) internal {
        bytes32 slot = keccak256(abi.encodePacked(tag_));
        assembly {
            sstore(slot, value)
        }
    }

    function setUintValueOnce(string memory tag_, uint256 value) internal {
        require(getUintValue(tag_) == 0, "ALREADY_SET");
        setUintValue(tag_, value);
    }

    function getAddressValue(string memory tag_) internal view returns (address retVal) {
        bytes32 slot = keccak256(abi.encodePacked(tag_));
        assembly {
            retVal := sload(slot)
        }
    }

    function setAddressValue(string memory tag_, address value) internal {
        bytes32 slot = keccak256(abi.encodePacked(tag_));
        assembly {
            sstore(slot, value)
        }
    }

    function setAddressValueOnce(string memory tag_, address value) internal {
        require(getAddressValue(tag_) == address(0x0), "ALREADY_SET");
        setAddressValue(tag_, value);
    }

    function getBoolValue(string memory tag_) internal view returns (bool retVal) {
        bytes32 slot = keccak256(abi.encodePacked(tag_));
        assembly {
            retVal := sload(slot)
        }
    }

    function setBoolValue(string memory tag_, bool value) internal {
        bytes32 slot = keccak256(abi.encodePacked(tag_));
        assembly {
            sstore(slot, value)
        }
    }
}

File 20 of 30 : OverrideLegacyProxyGovernance.sol
/*
  Copyright 2019-2023 StarkWare Industries Ltd.

  Licensed under the Apache License, Version 2.0 (the "License").
  You may not use this file except in compliance with the License.
  You may obtain a copy of the License at

  https://www.starkware.co/open-source-license/

  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions
  and limitations under the License.
*/
// SPDX-License-Identifier: Apache-2.0.
pragma solidity ^0.8.0;

import "starkware/solidity/libraries/RolesLib.sol";

struct GovernanceInfoStruct {
    mapping(address => bool) effectiveGovernors;
    address candidateGovernor;
    bool initialized;
}

// PROXY_GOVERNANCE_TAG = "StarkEx.Proxy.2019.GovernorsInformation"
// LEGACY_PROXY_GOVERNOR_SLOT = Web3.solidityKeccak(["string", "uint256"], [PROXY_GOVERNANCE_TAG, 0]) .
bytes32 constant LEGACY_PROXY_GOVERNOR_SLOT = 0x45f38e273862f8834bd2fe7a449988f63de55a7a5b685dea46ccedeb69cf0e26;

/**
  This contract allows the governance admin (which is the top of the `Roles` heirarchy),
  to override the proxy governance.
*/
abstract contract OverrideLegacyProxyGovernance {
    event LogNewGovernorAccepted(address acceptedGovernor);
    event LogRemovedGovernor(address removedGovernor);

    modifier GovernanceAdminOnly() {
        require(
            AccessControl.hasRole(GOVERNANCE_ADMIN, AccessControl._msgSender()),
            "GOVERNANCE_ADMIN_ONLY"
        );
        _;
    }

    function legacyProxyGovInfo() private pure returns (GovernanceInfoStruct storage gov) {
        bytes32 location = LEGACY_PROXY_GOVERNOR_SLOT;
        assembly {
            gov.slot := location
        }
    }

    /*
      Assigns `account` as proxy governor and clears pending govneror candidate.
    */
    function assignLegacyProxyGovernor(address account) external GovernanceAdminOnly {
        GovernanceInfoStruct storage legacyProxyGov = legacyProxyGovInfo();
        legacyProxyGov.effectiveGovernors[account] = true;
        delete legacyProxyGov.candidateGovernor;
        emit LogNewGovernorAccepted(account);
    }

    /*
      Removes `account` from proxy governor role and clears pending govneror candidate.
    */
    function removeLegacyProxyGovernor(address account) external GovernanceAdminOnly {
        GovernanceInfoStruct storage legacyProxyGov = legacyProxyGovInfo();
        legacyProxyGov.effectiveGovernors[account] = false;
        delete legacyProxyGov.candidateGovernor;
        emit LogRemovedGovernor(account);
    }
}

File 21 of 30 : ProxySupport.sol
/*
  Copyright 2019-2023 StarkWare Industries Ltd.

  Licensed under the Apache License, Version 2.0 (the "License").
  You may not use this file except in compliance with the License.
  You may obtain a copy of the License at

  https://www.starkware.co/open-source-license/

  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions
  and limitations under the License.
*/
// SPDX-License-Identifier: Apache-2.0.
pragma solidity ^0.8.0;

import "starkware/solidity/components/Roles.sol";
import "starkware/solidity/libraries/RolesLib.sol";
import "starkware/solidity/libraries/Addresses.sol";
import "starkware/solidity/interfaces/BlockDirectCall.sol";
import "starkware/solidity/interfaces/ContractInitializer.sol";

/**
  This contract contains the code commonly needed for a contract to be deployed behind
  an upgradability proxy.
  It perform the required semantics of the proxy pattern,
  but in a generic manner.
*/
abstract contract ProxySupport is BlockDirectCall, ContractInitializer, Roles(true) {
    using Addresses for address;

    // The two function below (isFrozen & initialize) needed to bind to the Proxy.
    function isFrozen() external view virtual returns (bool) {
        return false;
    }

    /*
      The initialize() function serves as an alternative constructor for a proxied deployment.

      Flow and notes:
      1. This function cannot be called directly on the deployed contract, but only via
         delegate call.
      2. If an EIC is provided - init is passed onto EIC and the standard init flow is skipped.
         This true for both first intialization or a later one.
      3. The data passed to this function is as follows:
         [sub_contracts addresses, eic address, initData].

         When calling on an initialized contract (no EIC scenario), initData.length must be 0.
    */
    function initialize(bytes calldata data) external notCalledDirectly {
        uint256 eicOffset = 32 * numOfSubContracts();
        uint256 expectedBaseSize = eicOffset + 32;
        require(data.length >= expectedBaseSize, "INIT_DATA_TOO_SMALL");
        address eicAddress = abi.decode(data[eicOffset:expectedBaseSize], (address));

        bytes calldata subContractAddresses = data[:eicOffset];

        processSubContractAddresses(subContractAddresses);

        bytes calldata initData = data[expectedBaseSize:];

        // EIC Provided - Pass initData to EIC and the skip standard init flow.
        if (eicAddress != address(0x0)) {
            callExternalInitializer(eicAddress, initData);
            return;
        }

        if (isInitialized()) {
            require(initData.length == 0, "UNEXPECTED_INIT_DATA");
        } else {
            // Contract was not initialized yet.
            validateInitData(initData);
            initializeContractState(initData);
            RolesLib.initialize();
        }
    }

    function callExternalInitializer(address externalInitializerAddr, bytes calldata eicData)
        private
    {
        require(externalInitializerAddr.isContract(), "EIC_NOT_A_CONTRACT");

        // NOLINTNEXTLINE: low-level-calls, controlled-delegatecall.
        (bool success, bytes memory returndata) = externalInitializerAddr.delegatecall(
            abi.encodeWithSelector(this.initialize.selector, eicData)
        );
        require(success, string(returndata));
        require(returndata.length == 0, string(returndata));
    }
}

File 22 of 30 : Roles.sol
/*
  Copyright 2019-2023 StarkWare Industries Ltd.

  Licensed under the Apache License, Version 2.0 (the "License").
  You may not use this file except in compliance with the License.
  You may obtain a copy of the License at

  https://www.starkware.co/open-source-license/

  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions
  and limitations under the License.
*/
// SPDX-License-Identifier: Apache-2.0.
pragma solidity ^0.8.0;

import "starkware/solidity/libraries/RolesLib.sol";

abstract contract Roles {
    // This flag dermine if the GOVERNANCE_ADMIN role can be renounced.
    bool immutable fullyRenouncable;

    constructor(bool renounceable) {
        fullyRenouncable = renounceable;
        RolesLib.initialize();
    }

    // MODIFIERS.
    modifier onlyAppGovernor() {
        require(isAppGovernor(AccessControl._msgSender()), "ONLY_APP_GOVERNOR");
        _;
    }

    modifier onlyOperator() {
        require(isOperator(AccessControl._msgSender()), "ONLY_OPERATOR");
        _;
    }

    modifier onlySecurityAdmin() {
        require(isSecurityAdmin(AccessControl._msgSender()), "ONLY_SECURITY_ADMIN");
        _;
    }

    modifier onlySecurityAgent() {
        require(isSecurityAgent(AccessControl._msgSender()), "ONLY_SECURITY_AGENT");
        _;
    }

    modifier onlyTokenAdmin() {
        require(isTokenAdmin(AccessControl._msgSender()), "ONLY_TOKEN_ADMIN");
        _;
    }

    modifier onlyUpgradeGovernor() {
        require(isUpgradeGovernor(AccessControl._msgSender()), "ONLY_UPGRADE_GOVERNOR");
        _;
    }

    modifier notSelf(address account) {
        require(account != AccessControl._msgSender(), "CANNOT_PERFORM_ON_SELF");
        _;
    }

    // Is holding role.
    function isAppGovernor(address account) public view returns (bool) {
        return AccessControl.hasRole(APP_GOVERNOR, account);
    }

    function isAppRoleAdmin(address account) public view returns (bool) {
        return AccessControl.hasRole(APP_ROLE_ADMIN, account);
    }

    function isGovernanceAdmin(address account) public view returns (bool) {
        return AccessControl.hasRole(GOVERNANCE_ADMIN, account);
    }

    function isOperator(address account) public view returns (bool) {
        return AccessControl.hasRole(OPERATOR, account);
    }

    function isSecurityAdmin(address account) public view returns (bool) {
        return AccessControl.hasRole(SECURITY_ADMIN, account);
    }

    function isSecurityAgent(address account) public view returns (bool) {
        return AccessControl.hasRole(SECURITY_AGENT, account);
    }

    function isTokenAdmin(address account) public view returns (bool) {
        return AccessControl.hasRole(TOKEN_ADMIN, account);
    }

    function isUpgradeGovernor(address account) public view returns (bool) {
        return AccessControl.hasRole(UPGRADE_GOVERNOR, account);
    }

    // Register Role.
    function registerAppGovernor(address account) external {
        AccessControl.grantRole(APP_GOVERNOR, account);
    }

    function registerAppRoleAdmin(address account) external {
        AccessControl.grantRole(APP_ROLE_ADMIN, account);
    }

    function registerGovernanceAdmin(address account) external {
        AccessControl.grantRole(GOVERNANCE_ADMIN, account);
    }

    function registerOperator(address account) external {
        AccessControl.grantRole(OPERATOR, account);
    }

    function registerSecurityAdmin(address account) external {
        AccessControl.grantRole(SECURITY_ADMIN, account);
    }

    function registerSecurityAgent(address account) external {
        AccessControl.grantRole(SECURITY_AGENT, account);
    }

    function registerTokenAdmin(address account) external {
        AccessControl.grantRole(TOKEN_ADMIN, account);
    }

    function registerUpgradeGovernor(address account) external {
        AccessControl.grantRole(UPGRADE_GOVERNOR, account);
    }

    // Revoke Role.
    function revokeAppGovernor(address account) external {
        AccessControl.revokeRole(APP_GOVERNOR, account);
    }

    function revokeAppRoleAdmin(address account) external notSelf(account) {
        AccessControl.revokeRole(APP_ROLE_ADMIN, account);
    }

    function revokeGovernanceAdmin(address account) external notSelf(account) {
        AccessControl.revokeRole(GOVERNANCE_ADMIN, account);
    }

    function revokeOperator(address account) external {
        AccessControl.revokeRole(OPERATOR, account);
    }

    function revokeSecurityAdmin(address account) external notSelf(account) {
        AccessControl.revokeRole(SECURITY_ADMIN, account);
    }

    function revokeSecurityAgent(address account) external {
        AccessControl.revokeRole(SECURITY_AGENT, account);
    }

    function revokeTokenAdmin(address account) external {
        AccessControl.revokeRole(TOKEN_ADMIN, account);
    }

    function revokeUpgradeGovernor(address account) external {
        AccessControl.revokeRole(UPGRADE_GOVERNOR, account);
    }

    // Renounce Role.
    function renounceRole(bytes32 role, address account) external {
        if (role == GOVERNANCE_ADMIN && !fullyRenouncable) {
            revert("CANNOT_RENOUNCE_GOVERNANCE_ADMIN");
        }
        AccessControl.renounceRole(role, account);
    }
}

File 23 of 30 : RolesLib.sol
/*
  Copyright 2019-2023 StarkWare Industries Ltd.

  Licensed under the Apache License, Version 2.0 (the "License").
  You may not use this file except in compliance with the License.
  You may obtain a copy of the License at

  https://www.starkware.co/open-source-license/

  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions
  and limitations under the License.
*/
// SPDX-License-Identifier: Apache-2.0.
pragma solidity ^0.8.0;

import "starkware/solidity/libraries/AccessControl.sol";

// int.from_bytes(Web3.keccak(text="ROLE_APP_GOVERNOR"), "big") & MASK_250 .
bytes32 constant APP_GOVERNOR = bytes32(
    uint256(0xd2ead78c620e94b02d0a996e99298c59ddccfa1d8a0149080ac3a20de06068)
);

// int.from_bytes(Web3.keccak(text="ROLE_APP_ROLE_ADMIN"), "big") & MASK_250 .
bytes32 constant APP_ROLE_ADMIN = bytes32(
    uint256(0x03e615638e0b79444a70f8c695bf8f2a47033bf1cf95691ec3130f64939cee99)
);

// int.from_bytes(Web3.keccak(text="ROLE_GOVERNANCE_ADMIN"), "big") & MASK_250 .
bytes32 constant GOVERNANCE_ADMIN = bytes32(
    uint256(0x03711c9d994faf6055172091cb841fd4831aa743e6f3315163b06a122c841846)
);

// int.from_bytes(Web3.keccak(text="ROLE_OPERATOR"), "big") & MASK_250 .
bytes32 constant OPERATOR = bytes32(
    uint256(0x023edb77f7c8cc9e38e8afe78954f703aeeda7fffe014eeb6e56ea84e62f6da7)
);

// int.from_bytes(Web3.keccak(text="ROLE_SECURITY_ADMIN"), "big") & MASK_250 .
bytes32 constant SECURITY_ADMIN = bytes32(
    uint256(0x026bd110619d11cfdfc28e281df893bc24828e89177318e9dbd860cdaedeb6b3)
);

// int.from_bytes(Web3.keccak(text="ROLE_SECURITY_AGENT"), "big") & MASK_250 .
bytes32 constant SECURITY_AGENT = bytes32(
    uint256(0x037693ba312785932d430dccf0f56ffedd0aa7c0f8b6da2cc4530c2717689b96)
);

// int.from_bytes(Web3.keccak(text="ROLE_TOKEN_ADMIN"), "big") & MASK_250 .
bytes32 constant TOKEN_ADMIN = bytes32(
    uint256(0x0128d63adbf6b09002c26caf55c47e2f26635807e3ef1b027218aa74c8d61a3e)
);

// int.from_bytes(Web3.keccak(text="ROLE_UPGRADE_GOVERNOR"), "big") & MASK_250 .
bytes32 constant UPGRADE_GOVERNOR = bytes32(
    uint256(0x0251e864ca2a080f55bce5da2452e8cfcafdbc951a3e7fff5023d558452ec228)
);

/*
  Role                |   Role Admin
  ----------------------------------------
  GOVERNANCE_ADMIN    |   GOVERNANCE_ADMIN
  UPGRADE_GOVERNOR    |   GOVERNANCE_ADMIN
  APP_ROLE_ADMIN      |   GOVERNANCE_ADMIN
  APP_GOVERNOR        |   APP_ROLE_ADMIN
  OPERATOR            |   APP_ROLE_ADMIN
  TOKEN_ADMIN         |   APP_ROLE_ADMIN
  SECURITY_ADMIN      |   SECURITY_ADMIN
  SECURITY_AGENT      |   SECURITY_ADMIN .
*/
library RolesLib {
    // INITIALIZERS.
    function governanceRolesInitialized() internal view returns (bool) {
        return AccessControl.getRoleAdmin(GOVERNANCE_ADMIN) != bytes32(0x00);
    }

    function securityRolesInitialized() internal view returns (bool) {
        return AccessControl.getRoleAdmin(SECURITY_ADMIN) != bytes32(0x00);
    }

    function initialize() internal {
        address provisional = AccessControl._msgSender();
        initialize(provisional, provisional);
    }

    function initialize(address provisionalGovernor, address provisionalSecAdmin) internal {
        if (governanceRolesInitialized()) {
            // Support Proxied contract initialization.
            // In case the Proxy already initialized the roles,
            // init will succeed IFF the provisionalGovernor is already `GovernanceAdmin`.
            require(
                AccessControl.hasRole(GOVERNANCE_ADMIN, provisionalGovernor),
                "ROLES_ALREADY_INITIALIZED"
            );
        } else {
            initGovernanceRoles(provisionalGovernor);
        }

        if (securityRolesInitialized()) {
            // If SecurityAdmin initialized,
            // then provisionalSecAdmin must already be a `SecurityAdmin`.
            // If it's not initilized - initialize it.
            require(
                AccessControl.hasRole(SECURITY_ADMIN, provisionalSecAdmin),
                "SECURITY_ROLES_ALREADY_INITIALIZED"
            );
        } else {
            initSecurityRoles(provisionalSecAdmin);
        }
    }

    function initSecurityRoles(address provisionalSecAdmin) private {
        AccessControl._setRoleAdmin(SECURITY_ADMIN, SECURITY_ADMIN);
        AccessControl._setRoleAdmin(SECURITY_AGENT, SECURITY_ADMIN);
        AccessControl._grantRole(SECURITY_ADMIN, provisionalSecAdmin);
    }

    function initGovernanceRoles(address provisionalGovernor) private {
        AccessControl._grantRole(GOVERNANCE_ADMIN, provisionalGovernor);
        AccessControl._setRoleAdmin(APP_GOVERNOR, APP_ROLE_ADMIN);
        AccessControl._setRoleAdmin(APP_ROLE_ADMIN, GOVERNANCE_ADMIN);
        AccessControl._setRoleAdmin(GOVERNANCE_ADMIN, GOVERNANCE_ADMIN);
        AccessControl._setRoleAdmin(OPERATOR, APP_ROLE_ADMIN);
        AccessControl._setRoleAdmin(TOKEN_ADMIN, APP_ROLE_ADMIN);
        AccessControl._setRoleAdmin(UPGRADE_GOVERNOR, GOVERNANCE_ADMIN);
    }
}

File 24 of 30 : StarkgateConstants.sol
/*
  Copyright 2019-2023 StarkWare Industries Ltd.

  Licensed under the Apache License, Version 2.0 (the "License").
  You may not use this file except in compliance with the License.
  You may obtain a copy of the License at

  https://www.starkware.co/open-source-license/

  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions
  and limitations under the License.
*/
// SPDX-License-Identifier: Apache-2.0.
pragma solidity ^0.8.20;

// Starknet L1 handler selectors.
uint256 constant HANDLE_DEPOSIT_SELECTOR = 1285101517810983806491589552491143496277809242732141897358598292095611420389;
uint256 constant HANDLE_TOKEN_DEPOSIT_SELECTOR = 774397379524139446221206168840917193112228400237242521560346153613428128537;

uint256 constant HANDLE_DEPOSIT_WITH_MESSAGE_SELECTOR = 247015267890530308727663503380700973440961674638638362173641612402089762826;

uint256 constant HANDLE_TOKEN_DEPLOYMENT_SELECTOR = 1737780302748468118210503507461757847859991634169290761669750067796330642876;

uint256 constant TRANSFER_FROM_STARKNET = 0;
uint256 constant UINT256_PART_SIZE_BITS = 128;
uint256 constant UINT256_PART_SIZE = 2**UINT256_PART_SIZE_BITS;
uint256 constant MAX_PENDING_DURATION = 5 days;
address constant BLOCKED_TOKEN = address(0x1);

// Cairo felt252 value (short string) of 'ETH'
address constant ETH = address(0x455448);

File 25 of 30 : StarkgateManager.sol
/*
  Copyright 2019-2023 StarkWare Industries Ltd.

  Licensed under the Apache License, Version 2.0 (the "License").
  You may not use this file except in compliance with the License.
  You may obtain a copy of the License at

  https://www.starkware.co/open-source-license/

  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions
  and limitations under the License.
*/
// SPDX-License-Identifier: Apache-2.0.
pragma solidity ^0.8.20;

import "starkware/solidity/components/Roles.sol";
import "starkware/solidity/interfaces/Identity.sol";
import "starkware/solidity/interfaces/ProxySupport.sol";
import "starkware/solidity/libraries/Addresses.sol";
import "starkware/solidity/libraries/NamedStorage.sol";
import "src/solidity/IStarkgateBridge.sol";
import "src/solidity/IStarkgateManager.sol";
import "src/solidity/IStarkgateRegistry.sol";
import "src/solidity/StarkgateConstants.sol";

contract StarkgateManager is Identity, IStarkgateManager, ProxySupport {
    using Addresses for address;
    // Named storage slot tags.
    string internal constant REGISTRY_TAG = "STARKGATE_MANAGER_REGISTRY_SLOT_TAG";
    string internal constant BRIDGE_TAG = "STARKGATE_MANAGER_BRIDGE_SLOT_TAG";
    event TokenEnrolled(address indexed token, address indexed sender);
    event ExistingBridgeAdded(address indexed token, address indexed bridge);
    event TokenDeactivated(address indexed token, address indexed sender);
    event TokenBlocked(address indexed token, address indexed sender);

    function getRegistry() external view returns (address) {
        return registry();
    }

    // Storage Getters.
    // TODO : add doc.
    function registry() internal view returns (address) {
        return NamedStorage.getAddressValue(REGISTRY_TAG);
    }

    function bridge() internal view returns (address) {
        return NamedStorage.getAddressValue(BRIDGE_TAG);
    }

    // Storage Setters.
    function setRegistry(address contract_) internal {
        NamedStorage.setAddressValueOnce(REGISTRY_TAG, contract_);
    }

    function setBridge(address contract_) internal {
        NamedStorage.setAddressValueOnce(BRIDGE_TAG, contract_);
    }

    function identify() external pure override returns (string memory) {
        return "StarkWare_StarkgateManager_2.0_1";
    }

    /*
      Initializes the contract.
    */
    function initializeContractState(bytes calldata data) internal override {
        (address registry_, address bridge_) = abi.decode(data, (address, address));
        setRegistry(registry_);
        setBridge(bridge_);
    }

    function isInitialized() internal view override returns (bool) {
        return registry() != address(0);
    }

    function numOfSubContracts() internal pure override returns (uint256) {
        return 0;
    }

    /*
      No processing needed, as there are no sub-contracts to this contract.
    */
    function processSubContractAddresses(bytes calldata subContractAddresses) internal override {}

    function validateInitData(bytes calldata data) internal view virtual override {
        require(data.length == 64, "ILLEGAL_DATA_SIZE");
        (address registry_, address bridge_) = abi.decode(data, (address, address));
        require(registry_.isContract(), "INVALID_REGISTRY_CONTRACT_ADDRESS");
        require(bridge_.isContract(), "INVALID_BRIDGE_CONTRACT_ADDRESS");
    }

    function addExistingBridge(address token, address bridge_) external onlyTokenAdmin {
        require(bridge() != bridge_, "CANNOT_ADD_MAIN_MULTI_BRIDGE_AS_EXISTING");
        IStarkgateRegistry(registry()).enlistToken(token, bridge_);
        emit ExistingBridgeAdded(token, bridge_);
    }

    /**
      Deactivates bridging of a specific token.
      A deactivated token is blocked for deposits and cannot be re-deployed.
      Note: Only serviced tokens can be deactivated. In order to block an unserviced tokens
      see 'blockToken'.
    */
    function deactivateToken(address token) external onlyTokenAdmin {
        IStarkgateRegistry registryContract = IStarkgateRegistry(registry());
        address current_bridge = registryContract.getBridge(token);

        require(current_bridge != address(0), "TOKEN_NOT_ENROLLED");
        if (current_bridge == BLOCKED_TOKEN) {
            string memory revertMsg = registryContract.getWithdrawalBridges(token).length == 0
                ? "TOKEN_ALREADY_BLOCKED"
                : "TOKEN_ALREADY_DEACTIVATED";
            revert(revertMsg);
        }
        emit TokenDeactivated(token, msg.sender);
        registryContract.blockToken(token);
        if (current_bridge == bridge()) {
            IStarkgateBridge(bridge()).deactivate(token);
        }
    }

    /**
      Block token from being bridged.
      A blocked token cannot be deployed.
      Note: Only an unserviced token can be blocked. In order to deactivate a serviced tokens
        see 'deactivateToken'.
    */
    function blockToken(address token) external onlyTokenAdmin {
        IStarkgateRegistry registryContract = IStarkgateRegistry(registry());
        address current_bridge = registryContract.getBridge(token);
        if (current_bridge == address(0)) {
            emit TokenBlocked(token, msg.sender);
            registryContract.blockToken(token);
        } else if (current_bridge == BLOCKED_TOKEN) {
            string memory revertMsg = registryContract.getWithdrawalBridges(token).length == 0
                ? "TOKEN_ALREADY_BLOCKED"
                : "CANNOT_BLOCK_DEACTIVATED_TOKEN";
            revert(revertMsg);
        } else {
            revert("CANNOT_BLOCK_TOKEN_IN_SERVICE");
        }
    }

    function enrollTokenBridge(address token) external payable {
        IStarkgateRegistry registryContract = IStarkgateRegistry(registry());
        require(registryContract.getBridge(token) != BLOCKED_TOKEN, "CANNOT_DEPLOY_BRIDGE");
        emit TokenEnrolled(token, msg.sender);
        registryContract.enlistToken(token, bridge());
        IStarkgateBridge(bridge()).enrollToken{value: msg.value}(token);
    }
}

File 26 of 30 : StarknetTokenBridge.sol
/*
  Copyright 2019-2023 StarkWare Industries Ltd.

  Licensed under the Apache License, Version 2.0 (the "License").
  You may not use this file except in compliance with the License.
  You may obtain a copy of the License at

  https://www.starkware.co/open-source-license/

  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions
  and limitations under the License.
*/
// SPDX-License-Identifier: Apache-2.0.
pragma solidity ^0.8.20;

import "starkware/solidity/interfaces/Identity.sol";
import "starkware/solidity/interfaces/ProxySupport.sol";
import "starkware/solidity/libraries/Addresses.sol";
import "starkware/solidity/libraries/NamedStorage.sol";
import "starkware/solidity/libraries/Transfers.sol";
import "starkware/solidity/tokens/ERC20/IERC20.sol";
import "starkware/solidity/tokens/ERC20/IERC20Metadata.sol";
import "starkware/starknet/solidity/IStarknetMessaging.sol";
import "src/solidity/Fees.sol";
import "src/solidity/IStarkgateBridge.sol";
import "src/solidity/IStarkgateManager.sol";
import "src/solidity/IStarkgateRegistry.sol";
import "src/solidity/IStarkgateService.sol";
import "src/solidity/StarkgateConstants.sol";
import "src/solidity/StarkgateManager.sol";
import "src/solidity/StarknetTokenStorage.sol";
import "src/solidity/WithdrawalLimit.sol";
import "src/solidity/utils/Felt252.sol";

contract StarknetTokenBridge is
    IStarkgateBridge,
    IStarkgateService,
    Identity,
    StarknetTokenStorage,
    ProxySupport
{
    using Addresses for address;
    using Felt252 for string;
    using UintFelt252 for uint256;

    event TokenEnrollmentInitiated(address token, bytes32 deploymentMsgHash);
    event TokenDeactivated(address token);

    event DepositWithMessage(
        address indexed sender,
        address indexed token,
        uint256 amount,
        uint256 indexed l2Recipient,
        uint256[] message,
        uint256 nonce,
        uint256 fee
    );
    event DepositWithMessageCancelRequest(
        address indexed sender,
        address indexed token,
        uint256 amount,
        uint256 indexed l2Recipient,
        uint256[] message,
        uint256 nonce
    );
    event DepositWithMessageReclaimed(
        address indexed sender,
        address indexed token,
        uint256 amount,
        uint256 indexed l2Recipient,
        uint256[] message,
        uint256 nonce
    );
    event Withdrawal(address indexed recipient, address indexed token, uint256 amount);
    event SetL2TokenBridge(uint256 value);
    event SetMaxTotalBalance(address indexed token, uint256 value);
    event Deposit(
        address indexed sender,
        address indexed token,
        uint256 amount,
        uint256 indexed l2Recipient,
        uint256 nonce,
        uint256 fee
    );
    event DepositCancelRequest(
        address indexed sender,
        address indexed token,
        uint256 amount,
        uint256 indexed l2Recipient,
        uint256 nonce
    );
    event DepositReclaimed(
        address indexed sender,
        address indexed token,
        uint256 amount,
        uint256 indexed l2Recipient,
        uint256 nonce
    );
    event WithdrawalLimitEnabled(address indexed sender, address indexed token);
    event WithdrawalLimitDisabled(address indexed sender, address indexed token);
    uint256 constant N_DEPOSIT_PAYLOAD_ARGS = 5;
    uint256 constant DEPOSIT_MESSAGE_FIXED_SIZE = 1;

    function identify() external pure virtual returns (string memory) {
        return "StarkWare_StarknetTokenBridge_2.0_4";
    }

    function validateInitData(bytes calldata data) internal view virtual override {
        require(data.length == 64, "ILLEGAL_DATA_SIZE");
        (address manager_, address messagingContract_) = abi.decode(data, (address, address));
        require(messagingContract_.isContract(), "INVALID_MESSAGING_CONTRACT_ADDRESS");
        require(manager_.isContract(), "INVALID_MANAGER_CONTRACT_ADDRESS");
    }

    /*
      Gets the addresses of bridgedToken & messagingContract from the ProxySupport initialize(),
      and sets the storage slot accordingly.
    */
    function initializeContractState(bytes calldata data) internal override {
        (address manager_, address messagingContract_) = abi.decode(data, (address, address));
        messagingContract(messagingContract_);
        setManager(manager_);
        WithdrawalLimit.setWithdrawLimitPct(WithdrawalLimit.DEFAULT_WITHDRAW_LIMIT_PCT);
    }

    function isInitialized() internal view virtual override returns (bool) {
        return address(messagingContract()) != address(0);
    }

    /*
      No processing needed, as there are no sub-contracts to this contract.
    */
    function processSubContractAddresses(bytes calldata subContractAddresses) internal override {}

    function numOfSubContracts() internal pure override returns (uint256) {
        return 0;
    }

    modifier onlyManager() {
        require(manager() == msg.sender, "ONLY_MANAGER");
        _;
    }

    modifier skipUnlessPending(address token) {
        if (tokenSettings()[token].tokenStatus != TokenStatus.Pending) return;
        _;
    }

    modifier onlyServicingToken(address token) {
        require(isServicingToken(token), "TOKEN_NOT_SERVICED");
        _;
    }

    function estimateDepositFeeWei() external pure returns (uint256) {
        return Fees.estimateDepositFee();
    }

    function estimateEnrollmentFeeWei() external pure returns (uint256) {
        return Fees.estimateEnrollmentFee();
    }

    // Virtual functions.
    function acceptDeposit(address token, uint256 amount) internal virtual returns (uint256) {
        Fees.checkDepositFee(msg.value);
        uint256 currentBalance = IERC20(token).balanceOf(address(this));
        require(currentBalance + amount <= getMaxTotalBalance(token), "MAX_BALANCE_EXCEEDED");
        Transfers.transferIn(token, msg.sender, amount);
        return msg.value;
    }

    function transferOutFunds(
        address token,
        uint256 amount,
        address recipient
    ) internal virtual {
        Transfers.transferOut(token, recipient, amount);
    }

    /**
        Initiates the enrollment of a token into the system.
        This function is used to initiate the enrollment process of a token.
        The token is marked as 'Pending' because the success of the deployment is uncertain at this stage.
        The deployment message's existence is checked, indicating that deployment has been attempted.
        The success of the deployment is determined at a later stage during the application's lifecycle.
        Only the manager, who initiates the deployment, can call this function.

        @param token The address of the token contract to be enrolled.
        No return value, but it updates the token's status to 'Pending' and records the deployment message and expiration time.
        Emits a `TokenEnrollmentInitiated` event when the enrollment is initiated.
        Throws an error if the sender is not the manager or if the deployment message does not exist.
     */
    function enrollToken(address token) external payable virtual onlyManager {
        require(
            tokenSettings()[token].tokenStatus == TokenStatus.Unknown,
            "TOKEN_ALREADY_ENROLLED"
        );
        // send message.
        bytes32 deploymentMsgHash = sendDeployMessage(token);

        require(
            messagingContract().l1ToL2Messages(deploymentMsgHash) > 0,
            "DEPLOYMENT_MESSAGE_NOT_EXIST"
        );
        tokenSettings()[token].tokenStatus = TokenStatus.Pending;
        tokenSettings()[token].deploymentMsgHash = deploymentMsgHash;
        tokenSettings()[token].pendingDeploymentExpiration = block.timestamp + MAX_PENDING_DURATION;
        emit TokenEnrollmentInitiated(token, deploymentMsgHash);
    }

    function getStatus(address token) external view returns (TokenStatus) {
        return tokenSettings()[token].tokenStatus;
    }

    function isServicingToken(address token) public view returns (bool) {
        TokenStatus status = tokenSettings()[token].tokenStatus;
        return (status == TokenStatus.Pending || status == TokenStatus.Active);
    }

    /**
        Returns the remaining amount of withdrawal allowed for this day.
        If the daily allowance was not yet set, it is calculated and returned.
        If the withdraw limit is not enabled for that token - the uint256.max is returned.
     */
    function getRemainingIntradayAllowance(address token) external view returns (uint256) {
        return
            tokenSettings()[token].withdrawalLimitApplied
                ? WithdrawalLimit.getRemainingIntradayAllowance(token)
                : type(uint256).max;
    }

    /**
        Deactivates a token in the system.
        This function is used to deactivate a token that was previously enrolled.
        Only the manager, who initiated the enrollment, can call this function.

        @param token The address of the token contract to be deactivated.
        No return value, but it updates the token's status to 'Deactivated'.
        Emits a `TokenDeactivated` event when the deactivation is successful.
        Throws an error if the token is not enrolled or if the sender is not the manager.

     */
    function deactivate(address token) external virtual onlyManager {
        require(tokenSettings()[token].tokenStatus != TokenStatus.Unknown, "UNKNOWN_TOKEN");
        tokenSettings()[token].tokenStatus = TokenStatus.Deactivated;
        emit TokenDeactivated(token);
    }

    /**
        Checks token deployment status.
        Relies on Starknet clearing L1-L2 message upon successful completion of deployment.
        Processing: Check the l1-l2 deployment message. Set status to `active` If consumed.
        If not consumed after the expected duration, it returns the status to unknown.
     */
    function checkDeploymentStatus(address token) public skipUnlessPending(token) {
        TokenSettings storage settings = tokenSettings()[token];
        bytes32 msgHash = settings.deploymentMsgHash;

        if (messagingContract().l1ToL2Messages(msgHash) == 0) {
            settings.tokenStatus = TokenStatus.Active;
        } else if (block.timestamp > settings.pendingDeploymentExpiration) {
            delete tokenSettings()[token];
            address registry = IStarkgateManager(manager()).getRegistry();
            IStarkgateRegistry(registry).selfRemove(token);
        }
    }

    function depositWithMessage(
        address token,
        uint256 amount,
        uint256 l2Recipient,
        uint256[] calldata message
    ) external payable onlyServicingToken(token) {
        uint256 fee = acceptDeposit(token, amount);
        uint256 nonce = sendDepositMessage(
            token,
            amount,
            l2Recipient,
            message,
            HANDLE_DEPOSIT_WITH_MESSAGE_SELECTOR,
            fee
        );
        emitDepositEvent(
            token,
            amount,
            l2Recipient,
            message,
            HANDLE_DEPOSIT_WITH_MESSAGE_SELECTOR,
            nonce,
            fee
        );

        // Piggy-back the deposit tx to check and update the status of token bridge deployment.
        checkDeploymentStatus(token);
    }

    function deposit(
        address token,
        uint256 amount,
        uint256 l2Recipient
    ) external payable onlyServicingToken(token) {
        uint256[] memory noMessage = new uint256[](0);
        uint256 fee = acceptDeposit(token, amount);
        uint256 nonce = sendDepositMessage(
            token,
            amount,
            l2Recipient,
            noMessage,
            HANDLE_TOKEN_DEPOSIT_SELECTOR,
            fee
        );
        emitDepositEvent(
            token,
            amount,
            l2Recipient,
            noMessage,
            HANDLE_TOKEN_DEPOSIT_SELECTOR,
            nonce,
            fee
        );

        // Piggy-back the deposit tx to check and update the status of token bridge deployment.
        checkDeploymentStatus(token);
    }

    function emitDepositEvent(
        address token,
        uint256 amount,
        uint256 l2Recipient,
        uint256[] memory message,
        uint256 selector,
        uint256 nonce,
        uint256 fee
    ) internal {
        if (selector == HANDLE_TOKEN_DEPOSIT_SELECTOR) {
            emit Deposit(msg.sender, token, amount, l2Recipient, nonce, fee);
        } else {
            require(selector == HANDLE_DEPOSIT_WITH_MESSAGE_SELECTOR, "UNKNOWN_SELECTOR");
            emit DepositWithMessage(msg.sender, token, amount, l2Recipient, message, nonce, fee);
        }
    }

    function setL2TokenBridge(uint256 l2TokenBridge_) external onlyAppGovernor {
        require(isInitialized(), "CONTRACT_NOT_INITIALIZED");
        require(l2TokenBridge_.isValidL2Address(), "L2_ADDRESS_OUT_OF_RANGE");
        l2TokenBridge(l2TokenBridge_);
        emit SetL2TokenBridge(l2TokenBridge_);
    }

    /**
        Set withdrawal limit for a token.
     */
    function enableWithdrawalLimit(address token) external onlySecurityAgent {
        tokenSettings()[token].withdrawalLimitApplied = true;
        emit WithdrawalLimitEnabled(msg.sender, token);
    }

    /**
        Unset withdrawal limit for a token.
     */
    function disableWithdrawalLimit(address token) external onlySecurityAdmin {
        tokenSettings()[token].withdrawalLimitApplied = false;
        emit WithdrawalLimitDisabled(msg.sender, token);
    }

    /**
       Set the maximum allowed balance of the bridge.
       Note: It is possible to set a lower value than the current total balance.
       In this case, deposits will not be possible, until enough withdrawls are done, such that the
       total balance is below the limit.
     */
    function setMaxTotalBalance(address token, uint256 maxTotalBalance_) external onlyAppGovernor {
        require(maxTotalBalance_ != 0, "INVALID_MAX_TOTAL_BALANCE");
        emit SetMaxTotalBalance(token, maxTotalBalance_);
        tokenSettings()[token].maxTotalBalance = maxTotalBalance_;
    }

    // Returns the maximal allowed balance of the bridge
    // If the value is 0, it means that there is no limit.
    function getMaxTotalBalance(address token) public view returns (uint256) {
        uint256 maxTotalBalance = tokenSettings()[token].maxTotalBalance;
        return maxTotalBalance == 0 ? type(uint256).max : maxTotalBalance;
    }

    // The max depsoit limitation is deprecated.
    // For Backward compatibility, we return maxUint256, which means no limitation.
    function maxDeposit() external pure returns (uint256) {
        return type(uint256).max;
    }

    function deployMessagePayload(address token) private view returns (uint256[] memory) {
        IERC20Metadata erc20 = IERC20Metadata(token);
        uint256[] memory payload = new uint256[](4);
        payload[0] = uint256(uint160(token));
        payload[1] = erc20.name().safeToFelt();
        payload[2] = erc20.symbol().safeToFelt();
        payload[3] = uint256(erc20.decimals());
        return payload;
    }

    function depositMessagePayload(
        address token,
        uint256 amount,
        uint256 l2Recipient,
        bool withMessage,
        uint256[] memory message
    ) private view returns (uint256[] memory) {
        uint256 MESSAGE_OFFSET = withMessage
            ? N_DEPOSIT_PAYLOAD_ARGS + DEPOSIT_MESSAGE_FIXED_SIZE
            : N_DEPOSIT_PAYLOAD_ARGS;
        uint256[] memory payload = new uint256[](MESSAGE_OFFSET + message.length);
        payload[0] = uint256(uint160(token));
        payload[1] = uint256(uint160(msg.sender));
        payload[2] = l2Recipient;
        payload[3] = amount & (UINT256_PART_SIZE - 1);
        payload[4] = amount >> UINT256_PART_SIZE_BITS;
        if (withMessage) {
            payload[MESSAGE_OFFSET - 1] = message.length;
            for (uint256 i = 0; i < message.length; i++) {
                require(message[i].isFelt(), "INVALID_MESSAGE_DATA");
                payload[i + MESSAGE_OFFSET] = message[i];
            }
        }
        return payload;
    }

    function depositMessagePayload(
        address token,
        uint256 amount,
        uint256 l2Recipient
    ) private view returns (uint256[] memory) {
        uint256[] memory noMessage = new uint256[](0);
        return
            depositMessagePayload(
                token,
                amount,
                l2Recipient,
                false, /*without message*/
                noMessage
            );
    }

    function sendDeployMessage(address token) internal returns (bytes32) {
        require(l2TokenBridge() != 0, "L2_BRIDGE_NOT_SET");
        Fees.checkEnrollmentFee(msg.value);

        (bytes32 deploymentMsgHash, ) = messagingContract().sendMessageToL2{value: msg.value}(
            l2TokenBridge(),
            HANDLE_TOKEN_DEPLOYMENT_SELECTOR,
            deployMessagePayload(token)
        );
        return deploymentMsgHash;
    }

    function sendDepositMessage(
        address token,
        uint256 amount,
        uint256 l2Recipient,
        uint256[] memory message,
        uint256 selector,
        uint256 fee
    ) internal returns (uint256) {
        require(l2TokenBridge() != 0, "L2_BRIDGE_NOT_SET");
        require(amount > 0, "ZERO_DEPOSIT");
        require(l2Recipient.isValidL2Address(), "L2_ADDRESS_OUT_OF_RANGE");

        bool isWithMsg = selector == HANDLE_DEPOSIT_WITH_MESSAGE_SELECTOR;
        (, uint256 nonce) = messagingContract().sendMessageToL2{value: fee}(
            l2TokenBridge(),
            selector,
            depositMessagePayload(token, amount, l2Recipient, isWithMsg, message)
        );

        // The function exclusively supports two specific selectors, and any attempt to use an unknown
        // selector will result in a transaction failure.
        return nonce;
    }

    function consumeMessage(
        address token,
        uint256 amount,
        address recipient
    ) internal virtual {
        require(l2TokenBridge() != 0, "L2_BRIDGE_NOT_SET");
        uint256[] memory payload = new uint256[](5);
        payload[0] = TRANSFER_FROM_STARKNET;
        payload[1] = uint256(uint160(recipient));
        payload[2] = uint256(uint160(token));
        payload[3] = amount & (UINT256_PART_SIZE - 1);
        payload[4] = amount >> UINT256_PART_SIZE_BITS;
        messagingContract().consumeMessageFromL2(l2TokenBridge(), payload);
    }

    function withdraw(
        address token,
        uint256 amount,
        address recipient
    ) public {
        // Make sure we don't accidentally burn funds.
        require(recipient != address(0x0), "INVALID_RECIPIENT");

        // The call to consumeMessage will succeed only if a matching L2->L1 message
        // exists and is ready for consumption.
        consumeMessage(token, amount, recipient);
        // Check if the withdrawal limit is enabled for that token.
        if (tokenSettings()[token].withdrawalLimitApplied) {
            // If the withdrawal limit is enabled, consume the quota.
            WithdrawalLimit.consumeWithdrawQuota(token, amount);
        }
        transferOutFunds(token, amount, recipient);
        emit Withdrawal(recipient, token, amount);
    }

    function withdraw(address token, uint256 amount) external {
        withdraw(token, amount, msg.sender);
    }

    /*
      A deposit cancellation requires two steps:
      1. The depositor should send a depositCancelRequest request with deposit details & nonce.
      2. After a predetermined time (cancellation delay), the depositor can claim back the funds by
         calling depositReclaim (using the same arguments).

      Note: As long as the depositReclaim was not performed, the deposit may be processed, even if
            the cancellation delay time has already passed. Only the depositor is allowed to cancel
            a deposit, and only before depositReclaim was performed.
    */
    function depositCancelRequest(
        address token,
        uint256 amount,
        uint256 l2Recipient,
        uint256 nonce
    ) external {
        messagingContract().startL1ToL2MessageCancellation(
            l2TokenBridge(),
            HANDLE_TOKEN_DEPOSIT_SELECTOR,
            depositMessagePayload(token, amount, l2Recipient),
            nonce
        );

        emit DepositCancelRequest(msg.sender, token, amount, l2Recipient, nonce);
    }

    /*
        See: depositCancelRequest docstring.
    */
    function depositWithMessageCancelRequest(
        address token,
        uint256 amount,
        uint256 l2Recipient,
        uint256[] calldata message,
        uint256 nonce
    ) external {
        messagingContract().startL1ToL2MessageCancellation(
            l2TokenBridge(),
            HANDLE_DEPOSIT_WITH_MESSAGE_SELECTOR,
            depositMessagePayload(
                token,
                amount,
                l2Recipient,
                true, /*with message*/
                message
            ),
            nonce
        );

        emit DepositWithMessageCancelRequest(
            msg.sender,
            token,
            amount,
            l2Recipient,
            message,
            nonce
        );
    }

    function depositWithMessageReclaim(
        address token,
        uint256 amount,
        uint256 l2Recipient,
        uint256[] calldata message,
        uint256 nonce
    ) external {
        messagingContract().cancelL1ToL2Message(
            l2TokenBridge(),
            HANDLE_DEPOSIT_WITH_MESSAGE_SELECTOR,
            depositMessagePayload(
                token,
                amount,
                l2Recipient,
                true, /*with message*/
                message
            ),
            nonce
        );

        transferOutFunds(token, amount, msg.sender);
        emit DepositWithMessageReclaimed(msg.sender, token, amount, l2Recipient, message, nonce);
    }

    function depositReclaim(
        address token,
        uint256 amount,
        uint256 l2Recipient,
        uint256 nonce
    ) external {
        messagingContract().cancelL1ToL2Message(
            l2TokenBridge(),
            HANDLE_TOKEN_DEPOSIT_SELECTOR,
            depositMessagePayload(token, amount, l2Recipient),
            nonce
        );

        transferOutFunds(token, amount, msg.sender);
        emit DepositReclaimed(msg.sender, token, amount, l2Recipient, nonce);
    }
}

File 27 of 30 : StarknetTokenStorage.sol
/*
  Copyright 2019-2023 StarkWare Industries Ltd.

  Licensed under the Apache License, Version 2.0 (the "License").
  You may not use this file except in compliance with the License.
  You may obtain a copy of the License at

  https://www.starkware.co/open-source-license/

  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions
  and limitations under the License.
*/
// SPDX-License-Identifier: Apache-2.0.
pragma solidity ^0.8.20;

import "starkware/solidity/libraries/NamedStorage.sol";
import "starkware/starknet/solidity/IStarknetMessaging.sol";

abstract contract StarknetTokenStorage {
    // Named storage slot tags.
    string internal constant BRIDGED_TOKEN_TAG = "STARKNET_ERC20_TOKEN_BRIDGE_TOKEN_ADDRESS";
    string internal constant L2_BRIDGE_TAG = "STARKNET_TOKEN_BRIDGE_L2_TOKEN_CONTRACT";
    string internal constant MANAGER_TAG = "STARKNET_TOKEN_BRIDGE_MANAGER_SLOT_TAG";
    string internal constant MESSAGING_CONTRACT_TAG = "STARKNET_TOKEN_BRIDGE_MESSAGING_CONTRACT";
    string internal constant DEPOSITOR_ADDRESSES_TAG = "STARKNET_TOKEN_BRIDGE_DEPOSITOR_ADDRESSES";

    enum TokenStatus {
        Unknown,
        Pending,
        Active,
        Deactivated
    }

    struct TokenSettings {
        TokenStatus tokenStatus;
        bytes32 deploymentMsgHash;
        uint256 pendingDeploymentExpiration;
        uint256 maxTotalBalance;
        bool withdrawalLimitApplied;
    }

    // Slot = Web3.keccak(text="TokenSettings_Storage_Slot").
    bytes32 constant tokenSettingsSlot =
        0xc59c20aaa96597268f595db30ec21108a505370e3266ed3a6515637f16b8b689;

    function tokenSettings()
        internal
        pure
        returns (mapping(address => TokenSettings) storage _tokenSettings)
    {
        assembly {
            _tokenSettings.slot := tokenSettingsSlot
        }
    }

    // Storage Getters.
    function manager() internal view returns (address) {
        return NamedStorage.getAddressValue(MANAGER_TAG);
    }

    function l2TokenBridge() internal view returns (uint256) {
        return NamedStorage.getUintValue(L2_BRIDGE_TAG);
    }

    function messagingContract() internal view returns (IStarknetMessaging) {
        return IStarknetMessaging(NamedStorage.getAddressValue(MESSAGING_CONTRACT_TAG));
    }

    // Storage Setters.
    function setManager(address contract_) internal {
        NamedStorage.setAddressValueOnce(MANAGER_TAG, contract_);
    }

    function l2TokenBridge(uint256 value) internal {
        NamedStorage.setUintValueOnce(L2_BRIDGE_TAG, value);
    }

    function messagingContract(address contract_) internal {
        NamedStorage.setAddressValueOnce(MESSAGING_CONTRACT_TAG, contract_);
    }
}

File 28 of 30 : Strings.sol
/*
  Copyright 2019-2023 StarkWare Industries Ltd.

  Licensed under the Apache License, Version 2.0 (the "License").
  You may not use this file except in compliance with the License.
  You may obtain a copy of the License at

  https://www.starkware.co/open-source-license/

  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions
  and limitations under the License.
*/
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/Strings.sol)

pragma solidity ^0.8.0;

/**
 * @dev String operations.
 */
library Strings {
    bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";
    uint8 private constant _ADDRESS_LENGTH = 20;

    /**
     * @dev Converts a `uint256` to its ASCII `string` decimal representation.
     */
    function toString(uint256 value) internal pure returns (string memory) {
        // Inspired by OraclizeAPI's implementation - MIT licence
        // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol

        if (value == 0) {
            return "0";
        }
        uint256 temp = value;
        uint256 digits;
        while (temp != 0) {
            digits++;
            temp /= 10;
        }
        bytes memory buffer = new bytes(digits);
        while (value != 0) {
            digits -= 1;
            buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
            value /= 10;
        }
        return string(buffer);
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        if (value == 0) {
            return "0x00";
        }
        uint256 temp = value;
        uint256 length = 0;
        while (temp != 0) {
            length++;
            temp >>= 8;
        }
        return toHexString(value, length);
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
     */
    function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
        bytes memory buffer = new bytes(2 * length + 2);
        buffer[0] = "0";
        buffer[1] = "x";
        for (uint256 i = 2 * length + 1; i > 1; --i) {
            buffer[i] = _HEX_SYMBOLS[value & 0xf];
            value >>= 4;
        }
        require(value == 0, "Strings: hex length insufficient");
        return string(buffer);
    }

    /**
     * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
     */
    function toHexString(address addr) internal pure returns (string memory) {
        return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
    }
}

File 29 of 30 : Transfers.sol
/*
  Copyright 2019-2023 StarkWare Industries Ltd.

  Licensed under the Apache License, Version 2.0 (the "License").
  You may not use this file except in compliance with the License.
  You may obtain a copy of the License at

  https://www.starkware.co/open-source-license/

  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions
  and limitations under the License.
*/
// SPDX-License-Identifier: Apache-2.0.
pragma solidity ^0.8.0;

import "starkware/solidity/libraries/Addresses.sol";
import "starkware/solidity/tokens/ERC20/IERC20.sol";

library Transfers {
    using Addresses for address;

    /*
      Transfers funds from sender to this contract.
    */
    function transferIn(
        address token,
        address sender,
        uint256 amount
    ) internal {
        if (amount == 0) return;
        IERC20 erc20Token = IERC20(token);
        uint256 balanceBefore = erc20Token.balanceOf(address(this));
        uint256 expectedAfter = balanceBefore + amount;
        require(expectedAfter >= balanceBefore, "OVERFLOW");

        bytes memory callData = abi.encodeWithSelector(
            erc20Token.transferFrom.selector,
            sender,
            address(this),
            amount
        );
        token.safeTokenContractCall(callData);

        uint256 balanceAfter = erc20Token.balanceOf(address(this));
        require(balanceAfter == expectedAfter, "INCORRECT_AMOUNT_TRANSFERRED");
    }

    /*
      Transfers funds from this contract to recipient.
    */
    function transferOut(
        address token,
        address recipient,
        uint256 amount
    ) internal {
        // Make sure we don't accidentally burn funds.
        require(recipient != address(0x0), "INVALID_RECIPIENT");
        if (amount == 0) return;
        IERC20 erc20Token = IERC20(token);
        uint256 balanceBefore = erc20Token.balanceOf(address(this));
        uint256 expectedAfter = balanceBefore - amount;
        require(expectedAfter <= balanceBefore, "UNDERFLOW");

        bytes memory callData = abi.encodeWithSelector(
            erc20Token.transfer.selector,
            recipient,
            amount
        );
        token.safeTokenContractCall(callData);

        uint256 balanceAfter = erc20Token.balanceOf(address(this));
        require(balanceAfter == expectedAfter, "INCORRECT_AMOUNT_TRANSFERRED");
    }
}

File 30 of 30 : WithdrawalLimit.sol
/*
  Copyright 2019-2023 StarkWare Industries Ltd.

  Licensed under the Apache License, Version 2.0 (the "License").
  You may not use this file except in compliance with the License.
  You may obtain a copy of the License at

  https://www.starkware.co/open-source-license/

  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions
  and limitations under the License.
*/
// SPDX-License-Identifier: Apache-2.0.
pragma solidity ^0.8.0;

import "starkware/solidity/libraries/NamedStorage.sol";
import "starkware/solidity/tokens/ERC20/IERC20.sol";
import "src/solidity/StarkgateConstants.sol";

/**
    A library to provide withdrawal limit functionality.
 */
library WithdrawalLimit {
    uint256 constant DEFAULT_WITHDRAW_LIMIT_PCT = 5;
    string internal constant WITHDRAW_LIMIT_PCT_TAG = "WITHDRAWL_LIMIT_WITHDRAW_LIMIT_PCT_SLOT_TAG";
    string internal constant INTRADAY_QUOTA_TAG = "WITHDRAWL_LIMIT_INTRADAY_QUOTA_SLOT_TAG";

    function getWithdrawLimitPct() internal view returns (uint256) {
        return NamedStorage.getUintValue(WITHDRAW_LIMIT_PCT_TAG);
    }

    function setWithdrawLimitPct(uint256 value) internal {
        NamedStorage.setUintValue(WITHDRAW_LIMIT_PCT_TAG, value);
    }

    // Returns the key for the intraday allowance mapping.
    function withdrawQuotaKey(address token) internal view returns (bytes32) {
        uint256 day = block.timestamp / 86400;
        return keccak256(abi.encode(token, day));
    }

    /**
        Calculates the intraday allowance for a given token.
        The allowance is calculated as a percentage of the current balance.
     */
    function calculateIntradayAllowance(address token) internal view returns (uint256) {
        uint256 currentBalance;
        // If the token is Eth and not an ERC20 - calculate balance accordingly.
        if (token == ETH) {
            currentBalance = address(this).balance;
        } else {
            currentBalance = IERC20(token).balanceOf(address(this));
        }
        uint256 withdrawLimitPct = getWithdrawLimitPct();
        return (currentBalance * withdrawLimitPct) / 100;
    }

    /**
        Returns the intraday quota mapping.
     */
    function intradayQuota() internal pure returns (mapping(bytes32 => uint256) storage) {
        return NamedStorage.bytes32ToUint256Mapping(INTRADAY_QUOTA_TAG);
    }

    // The offset is used to distinguish between an unset value and a value of 0.
    uint256 constant OFFSET = 1;

    function isWithdrawQuotaInitialized(address token) private view returns (bool) {
        return intradayQuota()[withdrawQuotaKey(token)] != 0;
    }

    function getIntradayQuota(address token) internal view returns (uint256) {
        return intradayQuota()[withdrawQuotaKey(token)] - OFFSET;
    }

    function setIntradayQuota(address token, uint256 value) private {
        intradayQuota()[withdrawQuotaKey(token)] = value + OFFSET;
    }

    /**
        Returns the remaining amount of withdrawal allowed for this day.
        If the daily allowance was not yet set, it is calculated and returned.
     */
    function getRemainingIntradayAllowance(address token) internal view returns (uint256) {
        if (!isWithdrawQuotaInitialized(token)) {
            return calculateIntradayAllowance(token);
        }
        return getIntradayQuota(token);
    }

    /**
        Consumes the intraday allowance for a given token.
        If the allowance was not yet calculated, it is calculated and consumed.
     */
    function consumeWithdrawQuota(address token, uint256 amount) internal {
        uint256 intradayAllowance = getRemainingIntradayAllowance(token);
        require(intradayAllowance >= amount, "EXCEEDS_GLOBAL_WITHDRAW_LIMIT");
        setIntradayQuota(token, intradayAllowance - amount);
    }
}

Settings
{
  "metadata": {
    "useLiteralContent": true
  },
  "libraries": {},
  "remappings": [],
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  }
}

Contract Security Audit

Contract ABI

[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"l2Recipient","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"nonce","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"fee","type":"uint256"}],"name":"Deposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"l2Recipient","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"nonce","type":"uint256"}],"name":"DepositCancelRequest","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"l2Recipient","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"nonce","type":"uint256"}],"name":"DepositReclaimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"l2Recipient","type":"uint256"},{"indexed":false,"internalType":"uint256[]","name":"message","type":"uint256[]"},{"indexed":false,"internalType":"uint256","name":"nonce","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"fee","type":"uint256"}],"name":"DepositWithMessage","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"l2Recipient","type":"uint256"},{"indexed":false,"internalType":"uint256[]","name":"message","type":"uint256[]"},{"indexed":false,"internalType":"uint256","name":"nonce","type":"uint256"}],"name":"DepositWithMessageCancelRequest","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"l2Recipient","type":"uint256"},{"indexed":false,"internalType":"uint256[]","name":"message","type":"uint256[]"},{"indexed":false,"internalType":"uint256","name":"nonce","type":"uint256"}],"name":"DepositWithMessageReclaimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"l2Recipient","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"nonce","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"fee","type":"uint256"}],"name":"LogDeposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"l2Recipient","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"nonce","type":"uint256"}],"name":"LogDepositCancelRequest","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"l2Recipient","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"nonce","type":"uint256"}],"name":"LogDepositReclaimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"acceptedGovernor","type":"address"}],"name":"LogNewGovernorAccepted","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"removedGovernor","type":"address"}],"name":"LogRemovedGovernor","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"SetL2TokenBridge","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"SetMaxTotalBalance","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"token","type":"address"}],"name":"TokenDeactivated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"bytes32","name":"deploymentMsgHash","type":"bytes32"}],"name":"TokenEnrollmentInitiated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"recipient","type":"address"},{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Withdrawal","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"address","name":"token","type":"address"}],"name":"WithdrawalLimitDisabled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"address","name":"token","type":"address"}],"name":"WithdrawalLimitEnabled","type":"event"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"assignLegacyProxyGovernor","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"checkDeploymentStatus","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"deactivate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"l2Recipient","type":"uint256"}],"name":"deposit","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"l2Recipient","type":"uint256"}],"name":"deposit","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"l2Recipient","type":"uint256"},{"internalType":"uint256","name":"nonce","type":"uint256"}],"name":"depositCancelRequest","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"l2Recipient","type":"uint256"},{"internalType":"uint256","name":"nonce","type":"uint256"}],"name":"depositReclaim","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"l2Recipient","type":"uint256"},{"internalType":"uint256[]","name":"message","type":"uint256[]"}],"name":"depositWithMessage","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"l2Recipient","type":"uint256"},{"internalType":"uint256[]","name":"message","type":"uint256[]"},{"internalType":"uint256","name":"nonce","type":"uint256"}],"name":"depositWithMessageCancelRequest","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"l2Recipient","type":"uint256"},{"internalType":"uint256[]","name":"message","type":"uint256[]"},{"internalType":"uint256","name":"nonce","type":"uint256"}],"name":"depositWithMessageReclaim","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"disableWithdrawalLimit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"enableWithdrawalLimit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"enrollToken","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"estimateDepositFeeWei","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"estimateEnrollmentFeeWei","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"getMaxTotalBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"getRemainingIntradayAllowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"getStatus","outputs":[{"internalType":"enum StarknetTokenStorage.TokenStatus","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"identify","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes","name":"data","type":"bytes"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"isAppGovernor","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"isAppRoleAdmin","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isFrozen","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"isGovernanceAdmin","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"isOperator","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"isSecurityAdmin","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"isSecurityAgent","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"isServicingToken","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"isTokenAdmin","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"isUpgradeGovernor","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"l2Recipient","type":"uint256"},{"internalType":"uint256","name":"nonce","type":"uint256"}],"name":"legacyDepositCancelRequest","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"l2Recipient","type":"uint256"},{"internalType":"uint256","name":"nonce","type":"uint256"}],"name":"legacyDepositReclaim","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"maxDeposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"maxTotalBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"registerAppGovernor","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"registerAppRoleAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"registerGovernanceAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"registerOperator","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"registerSecurityAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"registerSecurityAgent","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"registerTokenAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"registerUpgradeGovernor","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"removeLegacyProxyGovernor","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"revokeAppGovernor","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"revokeAppRoleAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"revokeGovernanceAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"revokeOperator","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"revokeSecurityAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"revokeSecurityAgent","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"revokeTokenAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"revokeUpgradeGovernor","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"l2TokenBridge_","type":"uint256"}],"name":"setL2TokenBridge","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"maxTotalBalance_","type":"uint256"}],"name":"setMaxTotalBalance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"recipient","type":"address"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"recipient","type":"address"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"}]

60c060405234801562000010575f80fd5b5030608052600160a0819052620000266200002d565b50620004dd565b336200003a81806200003d565b50565b620000476200019c565b15620000df576001600160a01b0382165f9081527fa5fdb349cc4ffac7e8ce7d3b075149d1bc847367d814e69a9beca89ef02db8b0602052604090205460ff16620000d95760405162461bcd60e51b815260206004820152601960248201527f524f4c45535f414c52454144595f494e495449414c495a45440000000000000060448201526064015b60405180910390fd5b620000ea565b620000ea82620001ed565b620000f462000330565b1562000191576001600160a01b0381165f9081527f2c11a1f9c63817dbb9f0faa966615764d2db5d6e008269e948a99e0b52181c23602052604090205460ff166200018d5760405162461bcd60e51b815260206004820152602260248201527f53454355524954595f524f4c45535f414c52454144595f494e495449414c495a604482015261115160f21b6064820152608401620000d0565b5050565b6200018d816200037f565b5f805160206200518f8339815191525f9081525f80516020620051cf8339815191526020527fa5fdb349cc4ffac7e8ce7d3b075149d1bc847367d814e69a9beca89ef02db8b15481905b1415905090565b620002075f805160206200518f83398151915282620003e8565b620002407ed2ead78c620e94b02d0a996e99298c59ddccfa1d8a0149080ac3a20de060685f80516020620051ef83398151915262000486565b620002685f80516020620051ef8339815191525f805160206200518f83398151915262000486565b620002825f805160206200518f8339815191528062000486565b620002bc7f023edb77f7c8cc9e38e8afe78954f703aeeda7fffe014eeb6e56ea84e62f6da75f80516020620051ef83398151915262000486565b620002f67f0128d63adbf6b09002c26caf55c47e2f26635807e3ef1b027218aa74c8d61a3e5f80516020620051ef83398151915262000486565b6200003a7f0251e864ca2a080f55bce5da2452e8cfcafdbc951a3e7fff5023d558452ec2285f805160206200518f83398151915262000486565b5f80516020620051af8339815191525f9081525f80516020620051cf8339815191526020527f2c11a1f9c63817dbb9f0faa966615764d2db5d6e008269e948a99e0b52181c24548190620001e6565b620003995f80516020620051af8339815191528062000486565b620003d37f037693ba312785932d430dccf0f56ffedd0aa7c0f8b6da2cc4530c2717689b965f80516020620051af83398151915262000486565b6200003a5f80516020620051af833981519152825b5f8281525f80516020620051cf833981519152602090815260408083206001600160a01b038516845290915290205460ff166200018d575f8281525f80516020620051cf833981519152602090815260408083206001600160a01b0385168085529252808320805460ff1916600117905551339285917f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d9190a45050565b5f8281525f80516020620051cf8339815191526020526040808220600101805490849055905190918391839186917fbd79b86ffe0ab8e8776151514217cd7cacd52c909f66475c3af44e129f0b00ff9190a4505050565b60805160a051614c90620004ff5f395f610ef601525f6110b10152614c905ff3fe608060405260043610610370575f3560e01c80636ffed68b116101c8578063cb1cccce116100fd578063deec9c5a1161009d578063eeb728661161006d578063eeb72866146109ea578063f3fef3a314610a0b578063fa0f73ba14610a2a578063fad8b32a14610a49575f80fd5b8063deec9c5a1461097a578063e2bbb15814610999578063ed9ef16a146109ac578063ee0e6807146109cb575f80fd5b8063d08fb6cb116100d8578063d08fb6cb146108fe578063d12fc1821461091d578063d2b51eea1461093c578063d9fa70911461095b575f80fd5b8063cb1cccce146108a1578063cdd1f70d146108c0578063cf50fd1c146108df575f80fd5b8063a2bdde3d11610168578063af8bc15e11610143578063af8bc15e1461083c578063b5cd0c3c14610850578063be58b18e1461086f578063c1f5eb3a14610882575f80fd5b8063a2bdde3d146107eb578063a6d1d6c61461080a578063ad8b92b414610829575f80fd5b80637fc2ab3e116101a35780637fc2ab3e1461076f5780638101b64c1461078e5780638e5224ff146107ad5780639463629a146107cc575f80fd5b80636ffed68b14610712578063757bd9ab146107315780637d22dbc714610750575f80fd5b806336568abe116102a95780635a5d1bb91161024957806369328dec1161021957806369328dec146106965780636c04d9d5146106b55780636d70f7ae146106d45780636fc97cbf146106f3575f80fd5b80635a5d1bb9146106265780635a72af89146106455780636083e59a1461066457806362a1437614610677575f80fd5b8063439fab9111610284578063439fab91146105b5578063496ae54c146105d45780634baf43da146105f35780634d8b92a514610612575f80fd5b806336568abe146105585780633682a450146105775780633ea053eb14610596575f80fd5b806319534075116103145780632e1a7d4d116102ef5780632e1a7d4d146104b85780632f951985146104d757806330ccebb5146104f657806333eeb14714610546575f80fd5b8063195340751461045857806323205c521461047a578063284b920e14610499575f80fd5b80630e770f231161034f5780630e770f23146103e85780630efe6a8b1461040757806314af98b31461041a5780631789638314610439575f80fd5b8062f714ce146103745780630b3a2d21146103955780630c6f8664146103b4575b5f80fd5b34801561037f575f80fd5b5061039361038e3660046140c3565b610a68565b005b3480156103a0575f80fd5b506103936103af3660046140f1565b610a7e565b3480156103bf575f80fd5b506103d36103ce3660046140f1565b610a98565b60405190151581526020015b60405180910390f35b3480156103f3575f80fd5b506103936104023660046140f1565b610af7565b61039361041536600461410c565b610b0e565b348015610425575f80fd5b506103936104343660046140f1565b610bc6565b348015610444575f80fd5b506103936104533660046140f1565b610c6c565b348015610463575f80fd5b5061046c610c83565b6040519081526020016103df565b348015610485575f80fd5b5061039361049436600461413e565b610c94565b3480156104a4575f80fd5b506103936104b33660046140f1565b610d86565b3480156104c3575f80fd5b506103936104d2366004614176565b610e8b565b3480156104e2575f80fd5b506103936104f13660046140f1565b610e9d565b348015610501575f80fd5b506105396105103660046140f1565b6001600160a01b03165f9081525f80516020614bd2833981519152602052604090205460ff1690565b6040516103df91906141a1565b348015610551575f80fd5b505f6103d3565b348015610563575f80fd5b506103936105723660046140c3565b610edd565b348015610582575f80fd5b506103936105913660046140f1565b610f6e565b3480156105a1575f80fd5b506103936105b03660046140f1565b610f85565b3480156105c0575f80fd5b506103936105cf3660046141c7565b6110ae565b3480156105df575f80fd5b5061046c6105ee3660046140f1565b61125a565b3480156105fe575f80fd5b5061046c61060d3660046140f1565b61129e565b34801561061d575f80fd5b5061046c6112da565b348015610631575f80fd5b506103d36106403660046140f1565b6112e3565b348015610650575f80fd5b5061039361065f3660046140f1565b6112fb565b34801561066f575f80fd5b505f1961046c565b348015610682575f80fd5b506103936106913660046140f1565b61139e565b3480156106a1575f80fd5b506103936106b0366004614233565b6113b5565b3480156106c0575f80fd5b506103d36106cf3660046140f1565b6114a0565b3480156106df575f80fd5b506103d36106ee3660046140f1565b6114b8565b3480156106fe575f80fd5b5061039361070d3660046140f1565b6114d0565b34801561071d575f80fd5b5061039361072c366004614272565b6114e7565b34801561073c575f80fd5b506103d361074b3660046140f1565b611635565b34801561075b575f80fd5b5061039361076a366004614272565b61164d565b34801561077a575f80fd5b50610393610789366004614176565b6117a3565b348015610799575f80fd5b506103936107a83660046140f1565b6118c8565b3480156107b8575f80fd5b506103d36107c73660046140f1565b611908565b3480156107d7575f80fd5b506103936107e63660046140f1565b611920565b3480156107f6575f80fd5b506103d36108053660046140f1565b611937565b348015610815575f80fd5b5061039361082436600461413e565b61194f565b6103936108373660046140f1565b611a2c565b348015610847575f80fd5b5061046c611a62565b34801561085b575f80fd5b5061039361086a3660046142e3565b611a6b565b61039361087d366004614350565b611b9d565b34801561088d575f80fd5b5061039361089c3660046140f1565b611caa565b3480156108ac575f80fd5b506103d36108bb3660046140f1565b611da4565b3480156108cb575f80fd5b506103936108da3660046140f1565b611dbc565b3480156108ea575f80fd5b506103936108f93660046142e3565b611dd3565b348015610909575f80fd5b506103d36109183660046140f1565b611eea565b348015610928575f80fd5b506103936109373660046140f1565b611f02565b348015610947575f80fd5b506103936109563660046143b5565b612117565b348015610966575f80fd5b506103936109753660046140f1565b61221d565b348015610985575f80fd5b506103936109943660046140f1565b612234565b6103936109a73660046143df565b61224b565b3480156109b7575f80fd5b506103936109c63660046140f1565b6122f9565b3480156109d6575f80fd5b506103936109e53660046140f1565b612310565b3480156109f5575f80fd5b506109fe612350565b6040516103df9190614421565b348015610a16575f80fd5b50610393610a253660046143b5565b612370565b348015610a35575f80fd5b50610393610a443660046140f1565b61237b565b348015610a54575f80fd5b50610393610a633660046140f1565b612392565b610a7a610a736123a9565b83836113b5565b5050565b610a955f80516020614c3b833981519152826123cb565b50565b6001600160a01b0381165f9081525f80516020614bd2833981519152602052604081205460ff166001816003811115610ad357610ad361418d565b1480610af057506002816003811115610aee57610aee61418d565b145b9392505050565b610a955f80516020614ad5833981519152826123cb565b82610b1881610a98565b610b5e5760405162461bcd60e51b81526020600482015260126024820152711513d2d15397d393d517d4d154959250d15160721b60448201526064015b60405180910390fd5b604080515f8082526020820190925290610b7886866123ec565b90505f610b96878787865f80516020614bb2833981519152876124cc565b9050610bb4878787865f80516020614bb2833981519152868861264e565b610bbd87611f02565b50505050505050565b610bcf33611635565b610c115760405162461bcd60e51b815260206004820152601360248201527213d3931657d4d150d55492551657d051d15395606a1b6044820152606401610b55565b6001600160a01b0381165f8181525f80516020614bd28339815191526020526040808220600401805460ff191660011790555133917fe2deca319add01142d26def2de47e64bf1fdc70e6f90c13a1862a48bdaaa7cfd91a350565b610a955f80516020614af5833981519152826123cb565b5f610c8f61060d6123a9565b905090565b610c9c612761565b6001600160a01b0316636170ff1b610cb2612783565b5f80516020614bb2833981519152610ccb8888886127a5565b856040518563ffffffff1660e01b8152600401610ceb94939291906144a0565b6020604051808303815f875af1158015610d07573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610d2b91906144cf565b50610d378484336127ce565b604080518481526020810183905283916001600160a01b0387169133917f50485fb0face2cfd73784044ab4191986b4a6713f01854414e2331a6bb41837d91015b60405180910390a450505050565b610d9d5f805160206149c7833981519152336127d9565b610de15760405162461bcd60e51b8152602060048201526015602482015274474f5645524e414e43455f41444d494e5f4f4e4c5960581b6044820152606401610b55565b6001600160a01b0381165f8181527f45f38e273862f8834bd2fe7a449988f63de55a7a5b685dea46ccedeb69cf0e266020818152604092839020805460ff191660011790557f45f38e273862f8834bd2fe7a449988f63de55a7a5b685dea46ccedeb69cf0e2780546001600160a01b03191690559151928352917fcfb473e6c03f9a29ddaf990e736fa3de5188a0bd85d684f5b6e164ebfbfff5d291015b60405180910390a15050565b610a95610e966123a9565b82336113b5565b80336001600160a01b03821603610ec65760405162461bcd60e51b8152600401610b55906144e6565b610a7a5f80516020614af58339815191528361280f565b5f805160206149c783398151915282148015610f1757507f0000000000000000000000000000000000000000000000000000000000000000155b15610f645760405162461bcd60e51b815260206004820181905260248201527f43414e4e4f545f52454e4f554e43455f474f5645524e414e43455f41444d494e6044820152606401610b55565b610a7a828261282b565b610a955f80516020614bf2833981519152826123cb565b33610f8e6128a5565b6001600160a01b031614610fd35760405162461bcd60e51b815260206004820152600c60248201526b27a7262cafa6a0a720a3a2a960a11b6044820152606401610b55565b6001600160a01b0381165f9081525f80516020614bd2833981519152602052604081205460ff16600381111561100b5761100b61418d565b036110485760405162461bcd60e51b815260206004820152600d60248201526c2aa725a727aba72faa27a5a2a760991b6044820152606401610b55565b6001600160a01b0381165f8181525f80516020614bd28339815191526020908152604091829020805460ff1916600317905590519182527f86d6e4556eae726303caf49a75add7d92ac713e46db458dab0622aa263fb48e691015b60405180910390a150565b307f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03160361111f5760405162461bcd60e51b81526020600482015260166024820152751112549150d517d0d0531317d11254d0531313d5d15160521b6044820152606401610b55565b5f61112b81602061452a565b90505f611139826020614541565b9050808310156111815760405162461bcd60e51b81526020600482015260136024820152721253925517d110551057d513d3d7d4d3505313606a1b6044820152606401610b55565b5f61118e82848688614554565b81019061119b91906140f1565b9050365f6111ab8582888a614554565b91509150365f6111bd8887818c614554565b90925090506001600160a01b038516156111e7576111dc8583836128c7565b505050505050505050565b6111ef612a05565b1561123e5780156112395760405162461bcd60e51b8152602060048201526014602482015273554e45585045435445445f494e49545f4441544160601b6044820152606401610b55565b6111dc565b6112488282612a1f565b6112528282612b36565b6111dc612b64565b6001600160a01b0381165f9081525f80516020614bd2833981519152602052604081206004015460ff1661128f575f19611298565b61129882612b6f565b92915050565b6001600160a01b0381165f9081525f80516020614bd2833981519152602052604081206003015480156112d15780610af0565b5f199392505050565b5f610c8f612b8f565b5f6112985f80516020614a2e833981519152836127d9565b61130433611eea565b6113465760405162461bcd60e51b815260206004820152601360248201527227a7262cafa9a2a1aaa924aa2cafa0a226a4a760691b6044820152606401610b55565b6001600160a01b0381165f8181525f80516020614bd28339815191526020526040808220600401805460ff191690555133917f109dee66091b7a145f557f52c55d7beccb6a29011fc705557e2975749474076b91a350565b610a955f805160206149e7833981519152826123cb565b6001600160a01b0381166113ff5760405162461bcd60e51b81526020600482015260116024820152701253959053125117d49150d25412515395607a1b6044820152606401610b55565b61140a838383612ba2565b6001600160a01b0383165f9081525f80516020614bd2833981519152602052604090206004015460ff1615611443576114438383612eb2565b61144e8383836127ce565b826001600160a01b0316816001600160a01b03167f2717ead6b9200dd235aad468c9809ea400fe33ac69b5bfaa6d3e90fc922b63988460405161149391815260200190565b60405180910390a3505050565b5f6112985f80516020614a4e833981519152836127d9565b5f6112985f80516020614bf2833981519152836127d9565b610a955f80516020614a4e833981519152826123cb565b80336114f1612f21565b5f83815260209190915260409020546001600160a01b0316146115475760405162461bcd60e51b815260206004820152600e60248201526d27a7262cafa222a827a9a4aa27a960911b6044820152606401610b55565b61154f612761565b6001600160a01b0316637a98660b611565612783565b7f02d757788a8d8d6f21d1cd40bce38a8222d70654214e96ff95d8086e684fbee56115908888612f43565b866040518563ffffffff1660e01b81526004016115b094939291906144a0565b6020604051808303815f875af11580156115cc573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906115f091906144cf565b506040805185815260208101849052849133917fea57f52faafe318751f75acb6756cff3f66afc10201ef8f2d504e788985db3f591015b60405180910390a350505050565b5f6112985f80516020614ad5833981519152836127d9565b8033611657612f21565b5f83815260209190915260409020546001600160a01b0316146116ad5760405162461bcd60e51b815260206004820152600e60248201526d27a7262cafa222a827a9a4aa27a960911b6044820152606401610b55565b6116b5612761565b6001600160a01b0316636170ff1b6116cb612783565b7f02d757788a8d8d6f21d1cd40bce38a8222d70654214e96ff95d8086e684fbee56116f68888612f43565b866040518563ffffffff1660e01b815260040161171694939291906144a0565b6020604051808303815f875af1158015611732573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061175691906144cf565b506117696117626123a9565b85336127ce565b6040805185815260208101849052849133917fb0b548d5e12b6a60adac4d6dd7610f55134cea4fd145535edc303a48063e0cb49101611627565b6117ac336112e3565b6117ec5760405162461bcd60e51b815260206004820152601160248201527027a7262cafa0a8282fa3a7ab22a92727a960791b6044820152606401610b55565b6117f4612a05565b6118405760405162461bcd60e51b815260206004820152601860248201527f434f4e54524143545f4e4f545f494e495449414c495a454400000000000000006044820152606401610b55565b61184981612fe9565b61188f5760405162461bcd60e51b81526020600482015260176024820152764c325f414444524553535f4f55545f4f465f52414e474560481b6044820152606401610b55565b6118988161300b565b6040518181527f90fc3f39f8e4669d1bf5f9038707949f8af42a973f62988143be0fa7c3997f18906020016110a3565b80336001600160a01b038216036118f15760405162461bcd60e51b8152600401610b55906144e6565b610a7a5f805160206149e78339815191528361280f565b5f6112985f80516020614af5833981519152836127d9565b610a955f805160206149c7833981519152826123cb565b5f6112985f80516020614c3b833981519152836127d9565b611957612761565b6001600160a01b0316637a98660b61196d612783565b5f80516020614bb28339815191526119868888886127a5565b856040518563ffffffff1660e01b81526004016119a694939291906144a0565b6020604051808303815f875af11580156119c2573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906119e691906144cf565b50604080518481526020810183905283916001600160a01b0387169133917f8f3da3ce93acd45e015b069c8f032d37be93dc9efcaaeda368aa9ca74f64c30a9101610d78565b60405162461bcd60e51b815260206004820152600b60248201526a155394d5541413d495115160aa1b6044820152606401610b55565b5f610c8f61302d565b611a73612761565b6001600160a01b0316636170ff1b611a89612783565b5f80516020614ab5833981519152611ad78a8a8a60018b8b808060200260200160405190810160405280939291908181526020018383602002808284375f9201919091525061303f92505050565b856040518563ffffffff1660e01b8152600401611af794939291906144a0565b6020604051808303815f875af1158015611b13573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611b3791906144cf565b50611b438686336127ce565b83866001600160a01b0316336001600160a01b03167fa465a02eedf06ceffd1d99159ad98c5d8fa7f17b870eb22e0bfcec06398a8f7388878787604051611b8d949392919061457b565b60405180910390a4505050505050565b84611ba781610a98565b611be85760405162461bcd60e51b81526020600482015260126024820152711513d2d15397d393d517d4d154959250d15160721b6044820152606401610b55565b5f611bf387876123ec565b90505f611c458888888888808060200260200160405190810160405280939291908181526020018383602002808284375f920191909152505f80516020614ab583398151915292508991506124cc9050565b9050611c978888888888808060200260200160405190810160405280939291908181526020018383602002808284375f920191909152505f80516020614ab5833981519152925088915089905061264e565b611ca088611f02565b5050505050505050565b611cc15f805160206149c7833981519152336127d9565b611d055760405162461bcd60e51b8152602060048201526015602482015274474f5645524e414e43455f41444d494e5f4f4e4c5960581b6044820152606401610b55565b6001600160a01b0381165f8181527f45f38e273862f8834bd2fe7a449988f63de55a7a5b685dea46ccedeb69cf0e266020818152604092839020805460ff191690557f45f38e273862f8834bd2fe7a449988f63de55a7a5b685dea46ccedeb69cf0e2780546001600160a01b03191690559151928352917fd75f94825e770b8b512be8e74759e252ad00e102e38f50cce2f7c6f868a295999101610e7f565b5f6112985f805160206149c7833981519152836127d9565b610a955f80516020614a2e833981519152826123cb565b611ddb612761565b6001600160a01b0316637a98660b611df1612783565b5f80516020614ab5833981519152611e3f8a8a8a60018b8b808060200260200160405190810160405280939291908181526020018383602002808284375f9201919091525061303f92505050565b856040518563ffffffff1660e01b8152600401611e5f94939291906144a0565b6020604051808303815f875af1158015611e7b573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611e9f91906144cf565b5083866001600160a01b0316336001600160a01b03167f889e470f207032611b2f68dbd2124e3139794f19a6b536c83892fd505760386088878787604051611b8d949392919061457b565b5f6112985f805160206149e7833981519152836127d9565b6001600160a01b0381165f9081525f80516020614bd28339815191526020526040902054819060019060ff166003811115611f3f57611f3f61418d565b14611f48575050565b6001600160a01b0382165f9081525f80516020614bd2833981519152602052604090206001810154611f78612761565b6001600160a01b03166377c7d7a9826040518263ffffffff1660e01b8152600401611fa591815260200190565b602060405180830381865afa158015611fc0573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611fe491906144cf565b5f03611ffa57815460ff19166002178255612111565b8160020154421115612111576001600160a01b0384165f9081525f80516020614bd283398151915260205260408120805460ff19908116825560018201839055600282018390556003820183905560049091018054909116905561205c6128a5565b6001600160a01b0316635ab1bd536040518163ffffffff1660e01b8152600401602060405180830381865afa158015612097573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906120bb91906145bf565b604051630caca05160e31b81526001600160a01b038781166004830152919250908216906365650288906024015f604051808303815f87803b1580156120ff575f80fd5b505af11580156111dc573d5f803e3d5ffd5b50505050565b612120336112e3565b6121605760405162461bcd60e51b815260206004820152601160248201527027a7262cafa0a8282fa3a7ab22a92727a960791b6044820152606401610b55565b805f036121af5760405162461bcd60e51b815260206004820152601960248201527f494e56414c49445f4d41585f544f54414c5f42414c414e4345000000000000006044820152606401610b55565b816001600160a01b03167fb895637c7d86c9b7b5b747e72195206a3fc21d8df0e019edd2312454ffa733b1826040516121ea91815260200190565b60405180910390a26001600160a01b03919091165f9081525f80516020614bd28339815191526020526040902060030155565b610a955f80516020614ad58339815191528261280f565b610a955f80516020614a2e8339815191528261280f565b604080515f80825260208201909252906122636123a9565b90505f61227082866123ec565b90505f61228e838787875f80516020614bb2833981519152876124cc565b90506122ac838787875f80516020614bb2833981519152868861264e565b6040805187815260208101839052908101839052859033907f5b5dbc6c64043a15d3fe6943a6e443a826b78755edc257b2ec890c022225dbcf9060600160405180910390a3505050505050565b610a955f80516020614a4e8339815191528261280f565b80336001600160a01b038216036123395760405162461bcd60e51b8152600401610b55906144e6565b610a7a5f805160206149c78339815191528361280f565b6060604051806060016040528060238152602001614b8f60239139905090565b610a7a8282336113b5565b610a955f80516020614c3b8339815191528261280f565b610a955f80516020614bf28339815191528261280f565b5f610c8f604051806060016040528060298152602001614c126029913961328a565b6123d4826132bd565b6123dd816132dd565b6123e783836132e7565b505050565b5f6123f63461335b565b6040516370a0823160e01b81523060048201525f906001600160a01b038516906370a0823190602401602060405180830381865afa15801561243a573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061245e91906144cf565b90506124698461129e565b6124738483614541565b11156124b85760405162461bcd60e51b815260206004820152601460248201527313505617d09053105390d157d15610d15151115160621b6044820152606401610b55565b6124c384338561336c565b50349392505050565b5f6124d5612783565b5f036125175760405162461bcd60e51b8152602060048201526011602482015270130c97d094925111d157d393d517d4d155607a1b6044820152606401610b55565b5f86116125555760405162461bcd60e51b815260206004820152600c60248201526b16915493d7d1115413d4d25560a21b6044820152606401610b55565b61255e85612fe9565b6125a45760405162461bcd60e51b81526020600482015260176024820152764c325f414444524553535f4f55545f4f465f52414e474560481b6044820152606401610b55565b5f80516020614ab583398151915283145f6125bd612761565b6001600160a01b0316633e3aa6c5856125d4612783565b886125e28e8e8e8a8f61303f565b6040518563ffffffff1660e01b8152600401612600939291906145da565b604080518083038185885af115801561261b573d5f803e3d5ffd5b50505050506040513d601f19601f8201168201806040525081019061264091906145f8565b9a9950505050505050505050565b5f80516020614bb283398151915283036126b757604080518781526020810184905290810182905285906001600160a01b0389169033907f5f971bd00bf3ffbca8a6d72cdd4fd92cfd4f62636161921d1e5a64f0b64ccb6d9060600160405180910390a4610bbd565b5f80516020614ab583398151915283146127065760405162461bcd60e51b815260206004820152601060248201526f2aa725a727aba72fa9a2a622a1aa27a960811b6044820152606401610b55565b84876001600160a01b0316336001600160a01b03167f2203a49c69f1a46c1164f5e4a30643dd77b7c59c0ff9bc433256048365c247f189888787604051612750949392919061461a565b60405180910390a450505050505050565b5f610c8f60405180606001604052806028815260200161499f6028913961328a565b5f610c8f604051806060016040528060278152602001614a8e6027913961328a565b604080515f80825260208201909252606091506127c58585855f8561303f565b95945050505050565b6123e783828461355a565b5f9182525f80516020614a6e833981519152602090815260408084206001600160a01b0393909316845291905290205460ff1690565b612818826132bd565b612821816132dd565b6123e78383613691565b6001600160a01b038116331461289b5760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b6064820152608401610b55565b610a7a8282613691565b5f610c8f604051806060016040528060268152602001614b156026913961328a565b6001600160a01b0383163b6129135760405162461bcd60e51b8152602060048201526012602482015271115250d7d393d517d057d0d3d395149050d560721b6044820152606401610b55565b5f80846001600160a01b031663439fab9160e01b858560405160240161293a929190614645565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b03199094169390931790925290516129789190614673565b5f60405180830381855af49150503d805f81146129b0576040519150601f19603f3d011682016040523d82523d5f602084013e6129b5565b606091505b50915091508181906129da5760405162461bcd60e51b8152600401610b559190614421565b5080518190156129fd5760405162461bcd60e51b8152600401610b559190614421565b505050505050565b5f80612a0f612761565b6001600160a01b03161415905090565b60408114612a635760405162461bcd60e51b8152602060048201526011602482015270494c4c4547414c5f444154415f53495a4560781b6044820152606401610b55565b5f80612a718385018561468e565b91509150612a88816001600160a01b03163b151590565b612adf5760405162461bcd60e51b815260206004820152602260248201527f494e56414c49445f4d4553534147494e475f434f4e54524143545f4144445245604482015261535360f01b6064820152608401610b55565b6001600160a01b0382163b6121115760405162461bcd60e51b815260206004820181905260248201527f494e56414c49445f4d414e414745525f434f4e54524143545f414444524553536044820152606401610b55565b5f80612b448385018561468e565b91509150612b5181613703565b612b5a82613725565b6121116005613747565b33610a958180613769565b5f612b798261386b565b612b865761129882613896565b61129882613945565b5f610c8f64012a05f200620186a061452a565b612baa612783565b5f03612bec5760405162461bcd60e51b8152602060048201526011602482015270130c97d094925111d157d393d517d4d155607a1b6044820152606401610b55565b6001600160a01b0381165f6001612c056080600261479a565b612c0f91906147a5565b60408051600580825260c082019092529186169250608086901c915f916020820160a0803683370190505090505f815f81518110612c4f57612c4f6147b8565b6020026020010181815250508381600181518110612c6f57612c6f6147b8565b602002602001018181525050866001600160a01b031681600281518110612c9857612c986147b8565b6020026020010181815250508281600381518110612cb857612cb86147b8565b6020026020010181815250508181600481518110612cd857612cd86147b8565b602002602001018181525050612cec612761565b6001600160a01b0316632c9dd5c0612d02612783565b836040518363ffffffff1660e01b8152600401612d209291906147cc565b6020604051808303815f875af1925050508015612d5a575060408051601f3d908101601f19168201909252612d57918101906144cf565b60015b611ca057612d666147e4565b806308c379a003612ea85750612d7a614836565b80612d855750612eaa565b60408051600480825260a0820190925290602082016080803683370190505091505f825f81518110612db957612db96147b8565b6020026020010181815250508482600181518110612dd957612dd96147b8565b6020026020010181815250508382600281518110612df957612df96147b8565b6020026020010181815250508282600381518110612e1957612e196147b8565b602002602001018181525050612e2d612761565b6001600160a01b0316632c9dd5c0612e43612783565b846040518363ffffffff1660e01b8152600401612e619291906147cc565b6020604051808303815f875af1158015612e7d573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612ea191906144cf565b5050610bbd565b505b3d5f803e3d5ffd5b5f612ebc83612b6f565b905081811015612f0e5760405162461bcd60e51b815260206004820152601d60248201527f455843454544535f474c4f42414c5f57495448445241575f4c494d49540000006044820152606401610b55565b6123e783612f1c84846147a5565b613972565b5f610c8f604051806060016040528060298152602001614b66602991396139a3565b604080516003808252608082019092526060915f919060208201848036833701905050905082815f81518110612f7b57612f7b6147b8565b60209081029190910101526001612f946080600261479a565b612f9e91906147a5565b841681600181518110612fb357612fb36147b8565b602002602001018181525050608084901c81600281518110612fd757612fd76147b8565b60209081029190910101529392505050565b5f8115801590611298575061129882600167080000000000001160c01b011190565b610a95604051806060016040528060278152602001614a8e60279139826139d5565b5f610c8f64012a05f200614e2061452a565b60605f8361304e57600561305a565b61305a60016005614541565b90505f83518261306a9190614541565b67ffffffffffffffff81111561308257613082614453565b6040519080825280602002602001820160405280156130ab578160200160208202803683370190505b509050876001600160a01b0316815f815181106130ca576130ca6147b8565b602002602001018181525050336001600160a01b0316816001815181106130f3576130f36147b8565b6020026020010181815250508581600281518110613113576131136147b8565b6020908102919091010152600161312c6080600261479a565b61313691906147a5565b87168160038151811061314b5761314b6147b8565b602002602001018181525050608087901c8160048151811061316f5761316f6147b8565b602002602001018181525050841561327f5783518161318f6001856147a5565b8151811061319f5761319f6147b8565b6020026020010181815250505f5b845181101561327d576131e68582815181106131cb576131cb6147b8565b6020026020010151600167080000000000001160c01b011190565b6132295760405162461bcd60e51b8152602060048201526014602482015273494e56414c49445f4d4553534147455f4441544160601b6044820152606401610b55565b84818151811061323b5761323b6147b8565b60200260200101518284836132509190614541565b81518110613260576132606147b8565b602090810291909101015280613275816148bf565b9150506131ad565b505b979650505050505050565b5f808260405160200161329d9190614673565b60408051601f198184030181529190528051602090910120549392505050565b5f9081525f80516020614a6e833981519152602052604090206001015490565b610a958133613a23565b6132f182826127d9565b610a7a575f8281525f80516020614a6e833981519152602090815260408083206001600160a01b0385168085529252808320805460ff1916600117905551339285917f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d9190a45050565b610a958161336761302d565b613a87565b805f0361337857505050565b6040516370a0823160e01b815230600482015283905f906001600160a01b038316906370a0823190602401602060405180830381865afa1580156133be573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906133e291906144cf565b90505f6133ef8483614541565b90508181101561342c5760405162461bcd60e51b81526020600482015260086024820152674f564552464c4f5760c01b6044820152606401610b55565b6040516001600160a01b0386166024820152306044820152606481018590525f906323b872dd60e01b906084015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b03199093169290921790915290506134a16001600160a01b03881682613b21565b6040516370a0823160e01b81523060048201525f906001600160a01b038616906370a0823190602401602060405180830381865afa1580156134e5573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061350991906144cf565b9050828114611ca05760405162461bcd60e51b815260206004820152601c60248201527f494e434f52524543545f414d4f554e545f5452414e53464552524544000000006044820152606401610b55565b6001600160a01b0382166135a45760405162461bcd60e51b81526020600482015260116024820152701253959053125117d49150d25412515395607a1b6044820152606401610b55565b805f036135b057505050565b6040516370a0823160e01b815230600482015283905f906001600160a01b038316906370a0823190602401602060405180830381865afa1580156135f6573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061361a91906144cf565b90505f61362784836147a5565b9050818111156136655760405162461bcd60e51b8152602060048201526009602482015268554e444552464c4f5760b81b6044820152606401610b55565b6040516001600160a01b0386166024820152604481018590525f9063a9059cbb60e01b9060640161345a565b61369b82826127d9565b15610a7a575f8281525f80516020614a6e833981519152602090815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b610a9560405180606001604052806028815260200161499f6028913982613c41565b610a95604051806060016040528060268152602001614b156026913982613c41565b610a956040518060600160405280602b8152602001614b3b602b913982613c8f565b613771613cc1565b156137de5761378d5f805160206149c7833981519152836127d9565b6137d95760405162461bcd60e51b815260206004820152601960248201527f524f4c45535f414c52454144595f494e495449414c495a4544000000000000006044820152606401610b55565b6137e7565b6137e782613ce0565b6137ef613dc2565b156138625761380b5f805160206149e7833981519152826127d9565b610a7a5760405162461bcd60e51b815260206004820152602260248201527f53454355524954595f524f4c45535f414c52454144595f494e495449414c495a604482015261115160f21b6064820152608401610b55565b610a7a81613dda565b5f613874613e2c565b5f61387e84613e4e565b81526020019081526020015f20545f14159050919050565b5f8062455447196001600160a01b038416016138b357504761391c565b6040516370a0823160e01b81523060048201526001600160a01b038416906370a0823190602401602060405180830381865afa1580156138f5573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061391991906144cf565b90505b5f613925613e9a565b90506064613933828461452a565b61393d91906148d7565b949350505050565b5f6001613950613e2c565b5f61395a85613e4e565b81526020019081526020015f205461129891906147a5565b61397d600182614541565b613985613e2c565b5f61398f85613e4e565b815260208101919091526040015f20555050565b5f80826040516020016139b69190614673565b60408051601f1981840301815291905280516020909101209392505050565b6139de8261328a565b15613a195760405162461bcd60e51b815260206004820152600b60248201526a1053149150511657d4d15560aa1b6044820152606401610b55565b610a7a8282613c8f565b613a2d82826127d9565b610a7a57613a45816001600160a01b03166014613ebc565b613a50836020613ebc565b604051602001613a619291906148f6565b60408051601f198184030181529082905262461bcd60e51b8252610b5591600401614421565b64e8d4a51000821015613ad55760405162461bcd60e51b8152602060048201526016602482015275494e53554646494349454e545f4645455f56414c554560501b6044820152606401610b55565b662386f26fc10000821115610a7a5760405162461bcd60e51b815260206004820152601260248201527108c8a8abeac8298aa8abea89e9ebe90928e960731b6044820152606401610b55565b813b613b635760405162461bcd60e51b81526020600482015260116024820152704241445f544f4b454e5f4144445245535360781b6044820152606401610b55565b5f80836001600160a01b031683604051613b7d9190614673565b5f604051808303815f865af19150503d805f8114613bb6576040519150601f19603f3d011682016040523d82523d5f602084013e613bbb565b606091505b5091509150818190613be05760405162461bcd60e51b8152600401610b559190614421565b508051156121115780806020019051810190613bfc919061496a565b6121115760405162461bcd60e51b81526020600482015260166024820152751513d2d15397d3d4115490551253d397d1905253115160521b6044820152606401610b55565b5f613c4b8361328a565b6001600160a01b031614613a195760405162461bcd60e51b815260206004820152600b60248201526a1053149150511657d4d15560aa1b6044820152606401610b55565b5f82604051602001613ca19190614673565b604051602081830303815290604052805190602001209050818155505050565b5f80613cd95f805160206149c78339815191526132bd565b1415905090565b613cf75f805160206149c7833981519152826132e7565b613d1b5f80516020614a2e8339815191525f80516020614af5833981519152614052565b613d3f5f80516020614af58339815191525f805160206149c7833981519152614052565b613d565f805160206149c783398151915280614052565b613d7a5f80516020614bf28339815191525f80516020614af5833981519152614052565b613d9e5f80516020614c3b8339815191525f80516020614af5833981519152614052565b610a955f80516020614a4e8339815191525f805160206149c7833981519152614052565b5f80613cd95f805160206149e78339815191526132bd565b613df15f805160206149e783398151915280614052565b613e155f80516020614ad58339815191525f805160206149e7833981519152614052565b610a955f805160206149e7833981519152826132e7565b5f610c8f604051806060016040528060278152602001614a07602791396139a3565b5f80613e5d62015180426148d7565b604080516001600160a01b038616602082015290810182905290915060600160405160208183030381529060405280519060200120915050919050565b5f610c8f6040518060600160405280602b8152602001614b3b602b913961328a565b60605f613eca83600261452a565b613ed5906002614541565b67ffffffffffffffff811115613eed57613eed614453565b6040519080825280601f01601f191660200182016040528015613f17576020820181803683370190505b509050600360fc1b815f81518110613f3157613f316147b8565b60200101906001600160f81b03191690815f1a905350600f60fb1b81600181518110613f5f57613f5f6147b8565b60200101906001600160f81b03191690815f1a9053505f613f8184600261452a565b613f8c906001614541565b90505b6001811115614003576f181899199a1a9b1b9c1cb0b131b232b360811b85600f1660108110613fc057613fc06147b8565b1a60f81b828281518110613fd657613fd66147b8565b60200101906001600160f81b03191690815f1a90535060049490941c93613ffc81614989565b9050613f8f565b508315610af05760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610b55565b5f61405c836132bd565b5f8481525f80516020614a6e8339815191526020526040808220600101859055519192508391839186917fbd79b86ffe0ab8e8776151514217cd7cacd52c909f66475c3af44e129f0b00ff9190a4505050565b6001600160a01b0381168114610a95575f80fd5b5f80604083850312156140d4575f80fd5b8235915060208301356140e6816140af565b809150509250929050565b5f60208284031215614101575f80fd5b8135610af0816140af565b5f805f6060848603121561411e575f80fd5b8335614129816140af565b95602085013595506040909401359392505050565b5f805f8060808587031215614151575f80fd5b843561415c816140af565b966020860135965060408601359560600135945092505050565b5f60208284031215614186575f80fd5b5035919050565b634e487b7160e01b5f52602160045260245ffd5b60208101600483106141c157634e487b7160e01b5f52602160045260245ffd5b91905290565b5f80602083850312156141d8575f80fd5b823567ffffffffffffffff808211156141ef575f80fd5b818501915085601f830112614202575f80fd5b813581811115614210575f80fd5b866020828501011115614221575f80fd5b60209290920196919550909350505050565b5f805f60608486031215614245575f80fd5b8335614250816140af565b9250602084013591506040840135614267816140af565b809150509250925092565b5f805f60608486031215614284575f80fd5b505081359360208301359350604090920135919050565b5f8083601f8401126142ab575f80fd5b50813567ffffffffffffffff8111156142c2575f80fd5b6020830191508360208260051b85010111156142dc575f80fd5b9250929050565b5f805f805f8060a087890312156142f8575f80fd5b8635614303816140af565b95506020870135945060408701359350606087013567ffffffffffffffff81111561432c575f80fd5b61433889828a0161429b565b979a9699509497949695608090950135949350505050565b5f805f805f60808688031215614364575f80fd5b853561436f816140af565b94506020860135935060408601359250606086013567ffffffffffffffff811115614398575f80fd5b6143a48882890161429b565b969995985093965092949392505050565b5f80604083850312156143c6575f80fd5b82356143d1816140af565b946020939093013593505050565b5f80604083850312156143f0575f80fd5b50508035926020909101359150565b5f5b83811015614419578181015183820152602001614401565b50505f910152565b602081525f825180602084015261443f8160408501602087016143ff565b601f01601f19169190910160400192915050565b634e487b7160e01b5f52604160045260245ffd5b5f8151808452602080850194508084015f5b8381101561449557815187529582019590820190600101614479565b509495945050505050565b848152836020820152608060408201525f6144be6080830185614467565b905082606083015295945050505050565b5f602082840312156144df575f80fd5b5051919050565b60208082526016908201527521a0a72727aa2fa822a92327a926afa7a72fa9a2a62360511b604082015260600190565b634e487b7160e01b5f52601160045260245ffd5b808202811582820484141761129857611298614516565b8082018082111561129857611298614516565b5f8085851115614562575f80fd5b8386111561456e575f80fd5b5050820193919092039150565b84815260606020820181905281018390525f6001600160fb1b038411156145a0575f80fd5b8360051b80866080850137604083019390935250016080019392505050565b5f602082840312156145cf575f80fd5b8151610af0816140af565b838152826020820152606060408201525f6127c56060830184614467565b5f8060408385031215614609575f80fd5b505080516020909101519092909150565b848152608060208201525f6146326080830186614467565b6040830194909452506060015292915050565b60208152816020820152818360408301375f818301604090810191909152601f909201601f19160101919050565b5f82516146848184602087016143ff565b9190910192915050565b5f806040838503121561469f575f80fd5b82356146aa816140af565b915060208301356140e6816140af565b600181815b808511156146f457815f19048211156146da576146da614516565b808516156146e757918102915b93841c93908002906146bf565b509250929050565b5f8261470a57506001611298565b8161471657505f611298565b816001811461472c576002811461473657614752565b6001915050611298565b60ff84111561474757614747614516565b50506001821b611298565b5060208310610133831016604e8410600b8410161715614775575081810a611298565b61477f83836146ba565b805f190482111561479257614792614516565b029392505050565b5f610af083836146fc565b8181038181111561129857611298614516565b634e487b7160e01b5f52603260045260245ffd5b828152604060208201525f61393d6040830184614467565b5f60033d11156147fa5760045f803e505f5160e01c5b90565b601f8201601f1916810167ffffffffffffffff8111828210171561482f57634e487b7160e01b5f52604160045260245ffd5b6040525050565b5f60443d10156148435790565b6040516003193d81016004833e81513d67ffffffffffffffff816024840111818411171561487357505050505090565b828501915081518181111561488b5750505050505090565b843d87010160208285010111156148a55750505050505090565b6148b4602082860101876147fd565b509095945050505050565b5f600182016148d0576148d0614516565b5060010190565b5f826148f157634e487b7160e01b5f52601260045260245ffd5b500490565b7f416363657373436f6e74726f6c3a206163636f756e742000000000000000000081525f835161492d8160178501602088016143ff565b7001034b99036b4b9b9b4b733903937b6329607d1b601791840191820152835161495e8160288401602088016143ff565b01602801949350505050565b5f6020828403121561497a575f80fd5b81518015158114610af0575f80fd5b5f8161499757614997614516565b505f19019056fe535441524b4e45545f544f4b454e5f4252494447455f4d4553534147494e475f434f4e545241435403711c9d994faf6055172091cb841fd4831aa743e6f3315163b06a122c841846026bd110619d11cfdfc28e281df893bc24828e89177318e9dbd860cdaedeb6b357495448445241574c5f4c494d49545f494e5452414441595f51554f54415f534c4f545f54414700d2ead78c620e94b02d0a996e99298c59ddccfa1d8a0149080ac3a20de060680251e864ca2a080f55bce5da2452e8cfcafdbc951a3e7fff5023d558452ec22853e43b954ba190a7e49386f1f78b01dcd9f628db23f432fa029a7dfd6d98e8fb535441524b4e45545f544f4b454e5f4252494447455f4c325f544f4b454e5f434f4e5452414354008bce41827dd5484d80312a2e43bc42a896e3fcf75bf84c2b49339168dfa00a037693ba312785932d430dccf0f56ffedd0aa7c0f8b6da2cc4530c2717689b9603e615638e0b79444a70f8c695bf8f2a47033bf1cf95691ec3130f64939cee99535441524b4e45545f544f4b454e5f4252494447455f4d414e414745525f534c4f545f54414757495448445241574c5f4c494d49545f57495448445241575f4c494d49545f5043545f534c4f545f544147535441524b4e45545f544f4b454e5f4252494447455f4445504f5349544f525f414444524553534553537461726b576172655f537461726b6e657445524332304272696467655f322e305f3401b64b1b3b690b43b9b514fb81377518f4039cd3e4f4914d8a6bdf01d679fb19c59c20aaa96597268f595db30ec21108a505370e3266ed3a6515637f16b8b689023edb77f7c8cc9e38e8afe78954f703aeeda7fffe014eeb6e56ea84e62f6da7535441524b4e45545f45524332305f544f4b454e5f4252494447455f544f4b454e5f414444524553530128d63adbf6b09002c26caf55c47e2f26635807e3ef1b027218aa74c8d61a3ea2646970667358221220421356d19636ba7734e9ccb3a21e35206c6553d21d77f2aa75ba1cf4f8bfd14c64736f6c6343000814003303711c9d994faf6055172091cb841fd4831aa743e6f3315163b06a122c841846026bd110619d11cfdfc28e281df893bc24828e89177318e9dbd860cdaedeb6b353e43b954ba190a7e49386f1f78b01dcd9f628db23f432fa029a7dfd6d98e8fb03e615638e0b79444a70f8c695bf8f2a47033bf1cf95691ec3130f64939cee99

Deployed Bytecode

0x608060405260043610610370575f3560e01c80636ffed68b116101c8578063cb1cccce116100fd578063deec9c5a1161009d578063eeb728661161006d578063eeb72866146109ea578063f3fef3a314610a0b578063fa0f73ba14610a2a578063fad8b32a14610a49575f80fd5b8063deec9c5a1461097a578063e2bbb15814610999578063ed9ef16a146109ac578063ee0e6807146109cb575f80fd5b8063d08fb6cb116100d8578063d08fb6cb146108fe578063d12fc1821461091d578063d2b51eea1461093c578063d9fa70911461095b575f80fd5b8063cb1cccce146108a1578063cdd1f70d146108c0578063cf50fd1c146108df575f80fd5b8063a2bdde3d11610168578063af8bc15e11610143578063af8bc15e1461083c578063b5cd0c3c14610850578063be58b18e1461086f578063c1f5eb3a14610882575f80fd5b8063a2bdde3d146107eb578063a6d1d6c61461080a578063ad8b92b414610829575f80fd5b80637fc2ab3e116101a35780637fc2ab3e1461076f5780638101b64c1461078e5780638e5224ff146107ad5780639463629a146107cc575f80fd5b80636ffed68b14610712578063757bd9ab146107315780637d22dbc714610750575f80fd5b806336568abe116102a95780635a5d1bb91161024957806369328dec1161021957806369328dec146106965780636c04d9d5146106b55780636d70f7ae146106d45780636fc97cbf146106f3575f80fd5b80635a5d1bb9146106265780635a72af89146106455780636083e59a1461066457806362a1437614610677575f80fd5b8063439fab9111610284578063439fab91146105b5578063496ae54c146105d45780634baf43da146105f35780634d8b92a514610612575f80fd5b806336568abe146105585780633682a450146105775780633ea053eb14610596575f80fd5b806319534075116103145780632e1a7d4d116102ef5780632e1a7d4d146104b85780632f951985146104d757806330ccebb5146104f657806333eeb14714610546575f80fd5b8063195340751461045857806323205c521461047a578063284b920e14610499575f80fd5b80630e770f231161034f5780630e770f23146103e85780630efe6a8b1461040757806314af98b31461041a5780631789638314610439575f80fd5b8062f714ce146103745780630b3a2d21146103955780630c6f8664146103b4575b5f80fd5b34801561037f575f80fd5b5061039361038e3660046140c3565b610a68565b005b3480156103a0575f80fd5b506103936103af3660046140f1565b610a7e565b3480156103bf575f80fd5b506103d36103ce3660046140f1565b610a98565b60405190151581526020015b60405180910390f35b3480156103f3575f80fd5b506103936104023660046140f1565b610af7565b61039361041536600461410c565b610b0e565b348015610425575f80fd5b506103936104343660046140f1565b610bc6565b348015610444575f80fd5b506103936104533660046140f1565b610c6c565b348015610463575f80fd5b5061046c610c83565b6040519081526020016103df565b348015610485575f80fd5b5061039361049436600461413e565b610c94565b3480156104a4575f80fd5b506103936104b33660046140f1565b610d86565b3480156104c3575f80fd5b506103936104d2366004614176565b610e8b565b3480156104e2575f80fd5b506103936104f13660046140f1565b610e9d565b348015610501575f80fd5b506105396105103660046140f1565b6001600160a01b03165f9081525f80516020614bd2833981519152602052604090205460ff1690565b6040516103df91906141a1565b348015610551575f80fd5b505f6103d3565b348015610563575f80fd5b506103936105723660046140c3565b610edd565b348015610582575f80fd5b506103936105913660046140f1565b610f6e565b3480156105a1575f80fd5b506103936105b03660046140f1565b610f85565b3480156105c0575f80fd5b506103936105cf3660046141c7565b6110ae565b3480156105df575f80fd5b5061046c6105ee3660046140f1565b61125a565b3480156105fe575f80fd5b5061046c61060d3660046140f1565b61129e565b34801561061d575f80fd5b5061046c6112da565b348015610631575f80fd5b506103d36106403660046140f1565b6112e3565b348015610650575f80fd5b5061039361065f3660046140f1565b6112fb565b34801561066f575f80fd5b505f1961046c565b348015610682575f80fd5b506103936106913660046140f1565b61139e565b3480156106a1575f80fd5b506103936106b0366004614233565b6113b5565b3480156106c0575f80fd5b506103d36106cf3660046140f1565b6114a0565b3480156106df575f80fd5b506103d36106ee3660046140f1565b6114b8565b3480156106fe575f80fd5b5061039361070d3660046140f1565b6114d0565b34801561071d575f80fd5b5061039361072c366004614272565b6114e7565b34801561073c575f80fd5b506103d361074b3660046140f1565b611635565b34801561075b575f80fd5b5061039361076a366004614272565b61164d565b34801561077a575f80fd5b50610393610789366004614176565b6117a3565b348015610799575f80fd5b506103936107a83660046140f1565b6118c8565b3480156107b8575f80fd5b506103d36107c73660046140f1565b611908565b3480156107d7575f80fd5b506103936107e63660046140f1565b611920565b3480156107f6575f80fd5b506103d36108053660046140f1565b611937565b348015610815575f80fd5b5061039361082436600461413e565b61194f565b6103936108373660046140f1565b611a2c565b348015610847575f80fd5b5061046c611a62565b34801561085b575f80fd5b5061039361086a3660046142e3565b611a6b565b61039361087d366004614350565b611b9d565b34801561088d575f80fd5b5061039361089c3660046140f1565b611caa565b3480156108ac575f80fd5b506103d36108bb3660046140f1565b611da4565b3480156108cb575f80fd5b506103936108da3660046140f1565b611dbc565b3480156108ea575f80fd5b506103936108f93660046142e3565b611dd3565b348015610909575f80fd5b506103d36109183660046140f1565b611eea565b348015610928575f80fd5b506103936109373660046140f1565b611f02565b348015610947575f80fd5b506103936109563660046143b5565b612117565b348015610966575f80fd5b506103936109753660046140f1565b61221d565b348015610985575f80fd5b506103936109943660046140f1565b612234565b6103936109a73660046143df565b61224b565b3480156109b7575f80fd5b506103936109c63660046140f1565b6122f9565b3480156109d6575f80fd5b506103936109e53660046140f1565b612310565b3480156109f5575f80fd5b506109fe612350565b6040516103df9190614421565b348015610a16575f80fd5b50610393610a253660046143b5565b612370565b348015610a35575f80fd5b50610393610a443660046140f1565b61237b565b348015610a54575f80fd5b50610393610a633660046140f1565b612392565b610a7a610a736123a9565b83836113b5565b5050565b610a955f80516020614c3b833981519152826123cb565b50565b6001600160a01b0381165f9081525f80516020614bd2833981519152602052604081205460ff166001816003811115610ad357610ad361418d565b1480610af057506002816003811115610aee57610aee61418d565b145b9392505050565b610a955f80516020614ad5833981519152826123cb565b82610b1881610a98565b610b5e5760405162461bcd60e51b81526020600482015260126024820152711513d2d15397d393d517d4d154959250d15160721b60448201526064015b60405180910390fd5b604080515f8082526020820190925290610b7886866123ec565b90505f610b96878787865f80516020614bb2833981519152876124cc565b9050610bb4878787865f80516020614bb2833981519152868861264e565b610bbd87611f02565b50505050505050565b610bcf33611635565b610c115760405162461bcd60e51b815260206004820152601360248201527213d3931657d4d150d55492551657d051d15395606a1b6044820152606401610b55565b6001600160a01b0381165f8181525f80516020614bd28339815191526020526040808220600401805460ff191660011790555133917fe2deca319add01142d26def2de47e64bf1fdc70e6f90c13a1862a48bdaaa7cfd91a350565b610a955f80516020614af5833981519152826123cb565b5f610c8f61060d6123a9565b905090565b610c9c612761565b6001600160a01b0316636170ff1b610cb2612783565b5f80516020614bb2833981519152610ccb8888886127a5565b856040518563ffffffff1660e01b8152600401610ceb94939291906144a0565b6020604051808303815f875af1158015610d07573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610d2b91906144cf565b50610d378484336127ce565b604080518481526020810183905283916001600160a01b0387169133917f50485fb0face2cfd73784044ab4191986b4a6713f01854414e2331a6bb41837d91015b60405180910390a450505050565b610d9d5f805160206149c7833981519152336127d9565b610de15760405162461bcd60e51b8152602060048201526015602482015274474f5645524e414e43455f41444d494e5f4f4e4c5960581b6044820152606401610b55565b6001600160a01b0381165f8181527f45f38e273862f8834bd2fe7a449988f63de55a7a5b685dea46ccedeb69cf0e266020818152604092839020805460ff191660011790557f45f38e273862f8834bd2fe7a449988f63de55a7a5b685dea46ccedeb69cf0e2780546001600160a01b03191690559151928352917fcfb473e6c03f9a29ddaf990e736fa3de5188a0bd85d684f5b6e164ebfbfff5d291015b60405180910390a15050565b610a95610e966123a9565b82336113b5565b80336001600160a01b03821603610ec65760405162461bcd60e51b8152600401610b55906144e6565b610a7a5f80516020614af58339815191528361280f565b5f805160206149c783398151915282148015610f1757507f0000000000000000000000000000000000000000000000000000000000000001155b15610f645760405162461bcd60e51b815260206004820181905260248201527f43414e4e4f545f52454e4f554e43455f474f5645524e414e43455f41444d494e6044820152606401610b55565b610a7a828261282b565b610a955f80516020614bf2833981519152826123cb565b33610f8e6128a5565b6001600160a01b031614610fd35760405162461bcd60e51b815260206004820152600c60248201526b27a7262cafa6a0a720a3a2a960a11b6044820152606401610b55565b6001600160a01b0381165f9081525f80516020614bd2833981519152602052604081205460ff16600381111561100b5761100b61418d565b036110485760405162461bcd60e51b815260206004820152600d60248201526c2aa725a727aba72faa27a5a2a760991b6044820152606401610b55565b6001600160a01b0381165f8181525f80516020614bd28339815191526020908152604091829020805460ff1916600317905590519182527f86d6e4556eae726303caf49a75add7d92ac713e46db458dab0622aa263fb48e691015b60405180910390a150565b307f0000000000000000000000007f2a18900a978d4390a3640e34739bb697777a716001600160a01b03160361111f5760405162461bcd60e51b81526020600482015260166024820152751112549150d517d0d0531317d11254d0531313d5d15160521b6044820152606401610b55565b5f61112b81602061452a565b90505f611139826020614541565b9050808310156111815760405162461bcd60e51b81526020600482015260136024820152721253925517d110551057d513d3d7d4d3505313606a1b6044820152606401610b55565b5f61118e82848688614554565b81019061119b91906140f1565b9050365f6111ab8582888a614554565b91509150365f6111bd8887818c614554565b90925090506001600160a01b038516156111e7576111dc8583836128c7565b505050505050505050565b6111ef612a05565b1561123e5780156112395760405162461bcd60e51b8152602060048201526014602482015273554e45585045435445445f494e49545f4441544160601b6044820152606401610b55565b6111dc565b6112488282612a1f565b6112528282612b36565b6111dc612b64565b6001600160a01b0381165f9081525f80516020614bd2833981519152602052604081206004015460ff1661128f575f19611298565b61129882612b6f565b92915050565b6001600160a01b0381165f9081525f80516020614bd2833981519152602052604081206003015480156112d15780610af0565b5f199392505050565b5f610c8f612b8f565b5f6112985f80516020614a2e833981519152836127d9565b61130433611eea565b6113465760405162461bcd60e51b815260206004820152601360248201527227a7262cafa9a2a1aaa924aa2cafa0a226a4a760691b6044820152606401610b55565b6001600160a01b0381165f8181525f80516020614bd28339815191526020526040808220600401805460ff191690555133917f109dee66091b7a145f557f52c55d7beccb6a29011fc705557e2975749474076b91a350565b610a955f805160206149e7833981519152826123cb565b6001600160a01b0381166113ff5760405162461bcd60e51b81526020600482015260116024820152701253959053125117d49150d25412515395607a1b6044820152606401610b55565b61140a838383612ba2565b6001600160a01b0383165f9081525f80516020614bd2833981519152602052604090206004015460ff1615611443576114438383612eb2565b61144e8383836127ce565b826001600160a01b0316816001600160a01b03167f2717ead6b9200dd235aad468c9809ea400fe33ac69b5bfaa6d3e90fc922b63988460405161149391815260200190565b60405180910390a3505050565b5f6112985f80516020614a4e833981519152836127d9565b5f6112985f80516020614bf2833981519152836127d9565b610a955f80516020614a4e833981519152826123cb565b80336114f1612f21565b5f83815260209190915260409020546001600160a01b0316146115475760405162461bcd60e51b815260206004820152600e60248201526d27a7262cafa222a827a9a4aa27a960911b6044820152606401610b55565b61154f612761565b6001600160a01b0316637a98660b611565612783565b7f02d757788a8d8d6f21d1cd40bce38a8222d70654214e96ff95d8086e684fbee56115908888612f43565b866040518563ffffffff1660e01b81526004016115b094939291906144a0565b6020604051808303815f875af11580156115cc573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906115f091906144cf565b506040805185815260208101849052849133917fea57f52faafe318751f75acb6756cff3f66afc10201ef8f2d504e788985db3f591015b60405180910390a350505050565b5f6112985f80516020614ad5833981519152836127d9565b8033611657612f21565b5f83815260209190915260409020546001600160a01b0316146116ad5760405162461bcd60e51b815260206004820152600e60248201526d27a7262cafa222a827a9a4aa27a960911b6044820152606401610b55565b6116b5612761565b6001600160a01b0316636170ff1b6116cb612783565b7f02d757788a8d8d6f21d1cd40bce38a8222d70654214e96ff95d8086e684fbee56116f68888612f43565b866040518563ffffffff1660e01b815260040161171694939291906144a0565b6020604051808303815f875af1158015611732573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061175691906144cf565b506117696117626123a9565b85336127ce565b6040805185815260208101849052849133917fb0b548d5e12b6a60adac4d6dd7610f55134cea4fd145535edc303a48063e0cb49101611627565b6117ac336112e3565b6117ec5760405162461bcd60e51b815260206004820152601160248201527027a7262cafa0a8282fa3a7ab22a92727a960791b6044820152606401610b55565b6117f4612a05565b6118405760405162461bcd60e51b815260206004820152601860248201527f434f4e54524143545f4e4f545f494e495449414c495a454400000000000000006044820152606401610b55565b61184981612fe9565b61188f5760405162461bcd60e51b81526020600482015260176024820152764c325f414444524553535f4f55545f4f465f52414e474560481b6044820152606401610b55565b6118988161300b565b6040518181527f90fc3f39f8e4669d1bf5f9038707949f8af42a973f62988143be0fa7c3997f18906020016110a3565b80336001600160a01b038216036118f15760405162461bcd60e51b8152600401610b55906144e6565b610a7a5f805160206149e78339815191528361280f565b5f6112985f80516020614af5833981519152836127d9565b610a955f805160206149c7833981519152826123cb565b5f6112985f80516020614c3b833981519152836127d9565b611957612761565b6001600160a01b0316637a98660b61196d612783565b5f80516020614bb28339815191526119868888886127a5565b856040518563ffffffff1660e01b81526004016119a694939291906144a0565b6020604051808303815f875af11580156119c2573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906119e691906144cf565b50604080518481526020810183905283916001600160a01b0387169133917f8f3da3ce93acd45e015b069c8f032d37be93dc9efcaaeda368aa9ca74f64c30a9101610d78565b60405162461bcd60e51b815260206004820152600b60248201526a155394d5541413d495115160aa1b6044820152606401610b55565b5f610c8f61302d565b611a73612761565b6001600160a01b0316636170ff1b611a89612783565b5f80516020614ab5833981519152611ad78a8a8a60018b8b808060200260200160405190810160405280939291908181526020018383602002808284375f9201919091525061303f92505050565b856040518563ffffffff1660e01b8152600401611af794939291906144a0565b6020604051808303815f875af1158015611b13573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611b3791906144cf565b50611b438686336127ce565b83866001600160a01b0316336001600160a01b03167fa465a02eedf06ceffd1d99159ad98c5d8fa7f17b870eb22e0bfcec06398a8f7388878787604051611b8d949392919061457b565b60405180910390a4505050505050565b84611ba781610a98565b611be85760405162461bcd60e51b81526020600482015260126024820152711513d2d15397d393d517d4d154959250d15160721b6044820152606401610b55565b5f611bf387876123ec565b90505f611c458888888888808060200260200160405190810160405280939291908181526020018383602002808284375f920191909152505f80516020614ab583398151915292508991506124cc9050565b9050611c978888888888808060200260200160405190810160405280939291908181526020018383602002808284375f920191909152505f80516020614ab5833981519152925088915089905061264e565b611ca088611f02565b5050505050505050565b611cc15f805160206149c7833981519152336127d9565b611d055760405162461bcd60e51b8152602060048201526015602482015274474f5645524e414e43455f41444d494e5f4f4e4c5960581b6044820152606401610b55565b6001600160a01b0381165f8181527f45f38e273862f8834bd2fe7a449988f63de55a7a5b685dea46ccedeb69cf0e266020818152604092839020805460ff191690557f45f38e273862f8834bd2fe7a449988f63de55a7a5b685dea46ccedeb69cf0e2780546001600160a01b03191690559151928352917fd75f94825e770b8b512be8e74759e252ad00e102e38f50cce2f7c6f868a295999101610e7f565b5f6112985f805160206149c7833981519152836127d9565b610a955f80516020614a2e833981519152826123cb565b611ddb612761565b6001600160a01b0316637a98660b611df1612783565b5f80516020614ab5833981519152611e3f8a8a8a60018b8b808060200260200160405190810160405280939291908181526020018383602002808284375f9201919091525061303f92505050565b856040518563ffffffff1660e01b8152600401611e5f94939291906144a0565b6020604051808303815f875af1158015611e7b573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611e9f91906144cf565b5083866001600160a01b0316336001600160a01b03167f889e470f207032611b2f68dbd2124e3139794f19a6b536c83892fd505760386088878787604051611b8d949392919061457b565b5f6112985f805160206149e7833981519152836127d9565b6001600160a01b0381165f9081525f80516020614bd28339815191526020526040902054819060019060ff166003811115611f3f57611f3f61418d565b14611f48575050565b6001600160a01b0382165f9081525f80516020614bd2833981519152602052604090206001810154611f78612761565b6001600160a01b03166377c7d7a9826040518263ffffffff1660e01b8152600401611fa591815260200190565b602060405180830381865afa158015611fc0573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611fe491906144cf565b5f03611ffa57815460ff19166002178255612111565b8160020154421115612111576001600160a01b0384165f9081525f80516020614bd283398151915260205260408120805460ff19908116825560018201839055600282018390556003820183905560049091018054909116905561205c6128a5565b6001600160a01b0316635ab1bd536040518163ffffffff1660e01b8152600401602060405180830381865afa158015612097573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906120bb91906145bf565b604051630caca05160e31b81526001600160a01b038781166004830152919250908216906365650288906024015f604051808303815f87803b1580156120ff575f80fd5b505af11580156111dc573d5f803e3d5ffd5b50505050565b612120336112e3565b6121605760405162461bcd60e51b815260206004820152601160248201527027a7262cafa0a8282fa3a7ab22a92727a960791b6044820152606401610b55565b805f036121af5760405162461bcd60e51b815260206004820152601960248201527f494e56414c49445f4d41585f544f54414c5f42414c414e4345000000000000006044820152606401610b55565b816001600160a01b03167fb895637c7d86c9b7b5b747e72195206a3fc21d8df0e019edd2312454ffa733b1826040516121ea91815260200190565b60405180910390a26001600160a01b03919091165f9081525f80516020614bd28339815191526020526040902060030155565b610a955f80516020614ad58339815191528261280f565b610a955f80516020614a2e8339815191528261280f565b604080515f80825260208201909252906122636123a9565b90505f61227082866123ec565b90505f61228e838787875f80516020614bb2833981519152876124cc565b90506122ac838787875f80516020614bb2833981519152868861264e565b6040805187815260208101839052908101839052859033907f5b5dbc6c64043a15d3fe6943a6e443a826b78755edc257b2ec890c022225dbcf9060600160405180910390a3505050505050565b610a955f80516020614a4e8339815191528261280f565b80336001600160a01b038216036123395760405162461bcd60e51b8152600401610b55906144e6565b610a7a5f805160206149c78339815191528361280f565b6060604051806060016040528060238152602001614b8f60239139905090565b610a7a8282336113b5565b610a955f80516020614c3b8339815191528261280f565b610a955f80516020614bf28339815191528261280f565b5f610c8f604051806060016040528060298152602001614c126029913961328a565b6123d4826132bd565b6123dd816132dd565b6123e783836132e7565b505050565b5f6123f63461335b565b6040516370a0823160e01b81523060048201525f906001600160a01b038516906370a0823190602401602060405180830381865afa15801561243a573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061245e91906144cf565b90506124698461129e565b6124738483614541565b11156124b85760405162461bcd60e51b815260206004820152601460248201527313505617d09053105390d157d15610d15151115160621b6044820152606401610b55565b6124c384338561336c565b50349392505050565b5f6124d5612783565b5f036125175760405162461bcd60e51b8152602060048201526011602482015270130c97d094925111d157d393d517d4d155607a1b6044820152606401610b55565b5f86116125555760405162461bcd60e51b815260206004820152600c60248201526b16915493d7d1115413d4d25560a21b6044820152606401610b55565b61255e85612fe9565b6125a45760405162461bcd60e51b81526020600482015260176024820152764c325f414444524553535f4f55545f4f465f52414e474560481b6044820152606401610b55565b5f80516020614ab583398151915283145f6125bd612761565b6001600160a01b0316633e3aa6c5856125d4612783565b886125e28e8e8e8a8f61303f565b6040518563ffffffff1660e01b8152600401612600939291906145da565b604080518083038185885af115801561261b573d5f803e3d5ffd5b50505050506040513d601f19601f8201168201806040525081019061264091906145f8565b9a9950505050505050505050565b5f80516020614bb283398151915283036126b757604080518781526020810184905290810182905285906001600160a01b0389169033907f5f971bd00bf3ffbca8a6d72cdd4fd92cfd4f62636161921d1e5a64f0b64ccb6d9060600160405180910390a4610bbd565b5f80516020614ab583398151915283146127065760405162461bcd60e51b815260206004820152601060248201526f2aa725a727aba72fa9a2a622a1aa27a960811b6044820152606401610b55565b84876001600160a01b0316336001600160a01b03167f2203a49c69f1a46c1164f5e4a30643dd77b7c59c0ff9bc433256048365c247f189888787604051612750949392919061461a565b60405180910390a450505050505050565b5f610c8f60405180606001604052806028815260200161499f6028913961328a565b5f610c8f604051806060016040528060278152602001614a8e6027913961328a565b604080515f80825260208201909252606091506127c58585855f8561303f565b95945050505050565b6123e783828461355a565b5f9182525f80516020614a6e833981519152602090815260408084206001600160a01b0393909316845291905290205460ff1690565b612818826132bd565b612821816132dd565b6123e78383613691565b6001600160a01b038116331461289b5760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b6064820152608401610b55565b610a7a8282613691565b5f610c8f604051806060016040528060268152602001614b156026913961328a565b6001600160a01b0383163b6129135760405162461bcd60e51b8152602060048201526012602482015271115250d7d393d517d057d0d3d395149050d560721b6044820152606401610b55565b5f80846001600160a01b031663439fab9160e01b858560405160240161293a929190614645565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b03199094169390931790925290516129789190614673565b5f60405180830381855af49150503d805f81146129b0576040519150601f19603f3d011682016040523d82523d5f602084013e6129b5565b606091505b50915091508181906129da5760405162461bcd60e51b8152600401610b559190614421565b5080518190156129fd5760405162461bcd60e51b8152600401610b559190614421565b505050505050565b5f80612a0f612761565b6001600160a01b03161415905090565b60408114612a635760405162461bcd60e51b8152602060048201526011602482015270494c4c4547414c5f444154415f53495a4560781b6044820152606401610b55565b5f80612a718385018561468e565b91509150612a88816001600160a01b03163b151590565b612adf5760405162461bcd60e51b815260206004820152602260248201527f494e56414c49445f4d4553534147494e475f434f4e54524143545f4144445245604482015261535360f01b6064820152608401610b55565b6001600160a01b0382163b6121115760405162461bcd60e51b815260206004820181905260248201527f494e56414c49445f4d414e414745525f434f4e54524143545f414444524553536044820152606401610b55565b5f80612b448385018561468e565b91509150612b5181613703565b612b5a82613725565b6121116005613747565b33610a958180613769565b5f612b798261386b565b612b865761129882613896565b61129882613945565b5f610c8f64012a05f200620186a061452a565b612baa612783565b5f03612bec5760405162461bcd60e51b8152602060048201526011602482015270130c97d094925111d157d393d517d4d155607a1b6044820152606401610b55565b6001600160a01b0381165f6001612c056080600261479a565b612c0f91906147a5565b60408051600580825260c082019092529186169250608086901c915f916020820160a0803683370190505090505f815f81518110612c4f57612c4f6147b8565b6020026020010181815250508381600181518110612c6f57612c6f6147b8565b602002602001018181525050866001600160a01b031681600281518110612c9857612c986147b8565b6020026020010181815250508281600381518110612cb857612cb86147b8565b6020026020010181815250508181600481518110612cd857612cd86147b8565b602002602001018181525050612cec612761565b6001600160a01b0316632c9dd5c0612d02612783565b836040518363ffffffff1660e01b8152600401612d209291906147cc565b6020604051808303815f875af1925050508015612d5a575060408051601f3d908101601f19168201909252612d57918101906144cf565b60015b611ca057612d666147e4565b806308c379a003612ea85750612d7a614836565b80612d855750612eaa565b60408051600480825260a0820190925290602082016080803683370190505091505f825f81518110612db957612db96147b8565b6020026020010181815250508482600181518110612dd957612dd96147b8565b6020026020010181815250508382600281518110612df957612df96147b8565b6020026020010181815250508282600381518110612e1957612e196147b8565b602002602001018181525050612e2d612761565b6001600160a01b0316632c9dd5c0612e43612783565b846040518363ffffffff1660e01b8152600401612e619291906147cc565b6020604051808303815f875af1158015612e7d573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612ea191906144cf565b5050610bbd565b505b3d5f803e3d5ffd5b5f612ebc83612b6f565b905081811015612f0e5760405162461bcd60e51b815260206004820152601d60248201527f455843454544535f474c4f42414c5f57495448445241575f4c494d49540000006044820152606401610b55565b6123e783612f1c84846147a5565b613972565b5f610c8f604051806060016040528060298152602001614b66602991396139a3565b604080516003808252608082019092526060915f919060208201848036833701905050905082815f81518110612f7b57612f7b6147b8565b60209081029190910101526001612f946080600261479a565b612f9e91906147a5565b841681600181518110612fb357612fb36147b8565b602002602001018181525050608084901c81600281518110612fd757612fd76147b8565b60209081029190910101529392505050565b5f8115801590611298575061129882600167080000000000001160c01b011190565b610a95604051806060016040528060278152602001614a8e60279139826139d5565b5f610c8f64012a05f200614e2061452a565b60605f8361304e57600561305a565b61305a60016005614541565b90505f83518261306a9190614541565b67ffffffffffffffff81111561308257613082614453565b6040519080825280602002602001820160405280156130ab578160200160208202803683370190505b509050876001600160a01b0316815f815181106130ca576130ca6147b8565b602002602001018181525050336001600160a01b0316816001815181106130f3576130f36147b8565b6020026020010181815250508581600281518110613113576131136147b8565b6020908102919091010152600161312c6080600261479a565b61313691906147a5565b87168160038151811061314b5761314b6147b8565b602002602001018181525050608087901c8160048151811061316f5761316f6147b8565b602002602001018181525050841561327f5783518161318f6001856147a5565b8151811061319f5761319f6147b8565b6020026020010181815250505f5b845181101561327d576131e68582815181106131cb576131cb6147b8565b6020026020010151600167080000000000001160c01b011190565b6132295760405162461bcd60e51b8152602060048201526014602482015273494e56414c49445f4d4553534147455f4441544160601b6044820152606401610b55565b84818151811061323b5761323b6147b8565b60200260200101518284836132509190614541565b81518110613260576132606147b8565b602090810291909101015280613275816148bf565b9150506131ad565b505b979650505050505050565b5f808260405160200161329d9190614673565b60408051601f198184030181529190528051602090910120549392505050565b5f9081525f80516020614a6e833981519152602052604090206001015490565b610a958133613a23565b6132f182826127d9565b610a7a575f8281525f80516020614a6e833981519152602090815260408083206001600160a01b0385168085529252808320805460ff1916600117905551339285917f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d9190a45050565b610a958161336761302d565b613a87565b805f0361337857505050565b6040516370a0823160e01b815230600482015283905f906001600160a01b038316906370a0823190602401602060405180830381865afa1580156133be573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906133e291906144cf565b90505f6133ef8483614541565b90508181101561342c5760405162461bcd60e51b81526020600482015260086024820152674f564552464c4f5760c01b6044820152606401610b55565b6040516001600160a01b0386166024820152306044820152606481018590525f906323b872dd60e01b906084015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b03199093169290921790915290506134a16001600160a01b03881682613b21565b6040516370a0823160e01b81523060048201525f906001600160a01b038616906370a0823190602401602060405180830381865afa1580156134e5573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061350991906144cf565b9050828114611ca05760405162461bcd60e51b815260206004820152601c60248201527f494e434f52524543545f414d4f554e545f5452414e53464552524544000000006044820152606401610b55565b6001600160a01b0382166135a45760405162461bcd60e51b81526020600482015260116024820152701253959053125117d49150d25412515395607a1b6044820152606401610b55565b805f036135b057505050565b6040516370a0823160e01b815230600482015283905f906001600160a01b038316906370a0823190602401602060405180830381865afa1580156135f6573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061361a91906144cf565b90505f61362784836147a5565b9050818111156136655760405162461bcd60e51b8152602060048201526009602482015268554e444552464c4f5760b81b6044820152606401610b55565b6040516001600160a01b0386166024820152604481018590525f9063a9059cbb60e01b9060640161345a565b61369b82826127d9565b15610a7a575f8281525f80516020614a6e833981519152602090815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b610a9560405180606001604052806028815260200161499f6028913982613c41565b610a95604051806060016040528060268152602001614b156026913982613c41565b610a956040518060600160405280602b8152602001614b3b602b913982613c8f565b613771613cc1565b156137de5761378d5f805160206149c7833981519152836127d9565b6137d95760405162461bcd60e51b815260206004820152601960248201527f524f4c45535f414c52454144595f494e495449414c495a4544000000000000006044820152606401610b55565b6137e7565b6137e782613ce0565b6137ef613dc2565b156138625761380b5f805160206149e7833981519152826127d9565b610a7a5760405162461bcd60e51b815260206004820152602260248201527f53454355524954595f524f4c45535f414c52454144595f494e495449414c495a604482015261115160f21b6064820152608401610b55565b610a7a81613dda565b5f613874613e2c565b5f61387e84613e4e565b81526020019081526020015f20545f14159050919050565b5f8062455447196001600160a01b038416016138b357504761391c565b6040516370a0823160e01b81523060048201526001600160a01b038416906370a0823190602401602060405180830381865afa1580156138f5573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061391991906144cf565b90505b5f613925613e9a565b90506064613933828461452a565b61393d91906148d7565b949350505050565b5f6001613950613e2c565b5f61395a85613e4e565b81526020019081526020015f205461129891906147a5565b61397d600182614541565b613985613e2c565b5f61398f85613e4e565b815260208101919091526040015f20555050565b5f80826040516020016139b69190614673565b60408051601f1981840301815291905280516020909101209392505050565b6139de8261328a565b15613a195760405162461bcd60e51b815260206004820152600b60248201526a1053149150511657d4d15560aa1b6044820152606401610b55565b610a7a8282613c8f565b613a2d82826127d9565b610a7a57613a45816001600160a01b03166014613ebc565b613a50836020613ebc565b604051602001613a619291906148f6565b60408051601f198184030181529082905262461bcd60e51b8252610b5591600401614421565b64e8d4a51000821015613ad55760405162461bcd60e51b8152602060048201526016602482015275494e53554646494349454e545f4645455f56414c554560501b6044820152606401610b55565b662386f26fc10000821115610a7a5760405162461bcd60e51b815260206004820152601260248201527108c8a8abeac8298aa8abea89e9ebe90928e960731b6044820152606401610b55565b813b613b635760405162461bcd60e51b81526020600482015260116024820152704241445f544f4b454e5f4144445245535360781b6044820152606401610b55565b5f80836001600160a01b031683604051613b7d9190614673565b5f604051808303815f865af19150503d805f8114613bb6576040519150601f19603f3d011682016040523d82523d5f602084013e613bbb565b606091505b5091509150818190613be05760405162461bcd60e51b8152600401610b559190614421565b508051156121115780806020019051810190613bfc919061496a565b6121115760405162461bcd60e51b81526020600482015260166024820152751513d2d15397d3d4115490551253d397d1905253115160521b6044820152606401610b55565b5f613c4b8361328a565b6001600160a01b031614613a195760405162461bcd60e51b815260206004820152600b60248201526a1053149150511657d4d15560aa1b6044820152606401610b55565b5f82604051602001613ca19190614673565b604051602081830303815290604052805190602001209050818155505050565b5f80613cd95f805160206149c78339815191526132bd565b1415905090565b613cf75f805160206149c7833981519152826132e7565b613d1b5f80516020614a2e8339815191525f80516020614af5833981519152614052565b613d3f5f80516020614af58339815191525f805160206149c7833981519152614052565b613d565f805160206149c783398151915280614052565b613d7a5f80516020614bf28339815191525f80516020614af5833981519152614052565b613d9e5f80516020614c3b8339815191525f80516020614af5833981519152614052565b610a955f80516020614a4e8339815191525f805160206149c7833981519152614052565b5f80613cd95f805160206149e78339815191526132bd565b613df15f805160206149e783398151915280614052565b613e155f80516020614ad58339815191525f805160206149e7833981519152614052565b610a955f805160206149e7833981519152826132e7565b5f610c8f604051806060016040528060278152602001614a07602791396139a3565b5f80613e5d62015180426148d7565b604080516001600160a01b038616602082015290810182905290915060600160405160208183030381529060405280519060200120915050919050565b5f610c8f6040518060600160405280602b8152602001614b3b602b913961328a565b60605f613eca83600261452a565b613ed5906002614541565b67ffffffffffffffff811115613eed57613eed614453565b6040519080825280601f01601f191660200182016040528015613f17576020820181803683370190505b509050600360fc1b815f81518110613f3157613f316147b8565b60200101906001600160f81b03191690815f1a905350600f60fb1b81600181518110613f5f57613f5f6147b8565b60200101906001600160f81b03191690815f1a9053505f613f8184600261452a565b613f8c906001614541565b90505b6001811115614003576f181899199a1a9b1b9c1cb0b131b232b360811b85600f1660108110613fc057613fc06147b8565b1a60f81b828281518110613fd657613fd66147b8565b60200101906001600160f81b03191690815f1a90535060049490941c93613ffc81614989565b9050613f8f565b508315610af05760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610b55565b5f61405c836132bd565b5f8481525f80516020614a6e8339815191526020526040808220600101859055519192508391839186917fbd79b86ffe0ab8e8776151514217cd7cacd52c909f66475c3af44e129f0b00ff9190a4505050565b6001600160a01b0381168114610a95575f80fd5b5f80604083850312156140d4575f80fd5b8235915060208301356140e6816140af565b809150509250929050565b5f60208284031215614101575f80fd5b8135610af0816140af565b5f805f6060848603121561411e575f80fd5b8335614129816140af565b95602085013595506040909401359392505050565b5f805f8060808587031215614151575f80fd5b843561415c816140af565b966020860135965060408601359560600135945092505050565b5f60208284031215614186575f80fd5b5035919050565b634e487b7160e01b5f52602160045260245ffd5b60208101600483106141c157634e487b7160e01b5f52602160045260245ffd5b91905290565b5f80602083850312156141d8575f80fd5b823567ffffffffffffffff808211156141ef575f80fd5b818501915085601f830112614202575f80fd5b813581811115614210575f80fd5b866020828501011115614221575f80fd5b60209290920196919550909350505050565b5f805f60608486031215614245575f80fd5b8335614250816140af565b9250602084013591506040840135614267816140af565b809150509250925092565b5f805f60608486031215614284575f80fd5b505081359360208301359350604090920135919050565b5f8083601f8401126142ab575f80fd5b50813567ffffffffffffffff8111156142c2575f80fd5b6020830191508360208260051b85010111156142dc575f80fd5b9250929050565b5f805f805f8060a087890312156142f8575f80fd5b8635614303816140af565b95506020870135945060408701359350606087013567ffffffffffffffff81111561432c575f80fd5b61433889828a0161429b565b979a9699509497949695608090950135949350505050565b5f805f805f60808688031215614364575f80fd5b853561436f816140af565b94506020860135935060408601359250606086013567ffffffffffffffff811115614398575f80fd5b6143a48882890161429b565b969995985093965092949392505050565b5f80604083850312156143c6575f80fd5b82356143d1816140af565b946020939093013593505050565b5f80604083850312156143f0575f80fd5b50508035926020909101359150565b5f5b83811015614419578181015183820152602001614401565b50505f910152565b602081525f825180602084015261443f8160408501602087016143ff565b601f01601f19169190910160400192915050565b634e487b7160e01b5f52604160045260245ffd5b5f8151808452602080850194508084015f5b8381101561449557815187529582019590820190600101614479565b509495945050505050565b848152836020820152608060408201525f6144be6080830185614467565b905082606083015295945050505050565b5f602082840312156144df575f80fd5b5051919050565b60208082526016908201527521a0a72727aa2fa822a92327a926afa7a72fa9a2a62360511b604082015260600190565b634e487b7160e01b5f52601160045260245ffd5b808202811582820484141761129857611298614516565b8082018082111561129857611298614516565b5f8085851115614562575f80fd5b8386111561456e575f80fd5b5050820193919092039150565b84815260606020820181905281018390525f6001600160fb1b038411156145a0575f80fd5b8360051b80866080850137604083019390935250016080019392505050565b5f602082840312156145cf575f80fd5b8151610af0816140af565b838152826020820152606060408201525f6127c56060830184614467565b5f8060408385031215614609575f80fd5b505080516020909101519092909150565b848152608060208201525f6146326080830186614467565b6040830194909452506060015292915050565b60208152816020820152818360408301375f818301604090810191909152601f909201601f19160101919050565b5f82516146848184602087016143ff565b9190910192915050565b5f806040838503121561469f575f80fd5b82356146aa816140af565b915060208301356140e6816140af565b600181815b808511156146f457815f19048211156146da576146da614516565b808516156146e757918102915b93841c93908002906146bf565b509250929050565b5f8261470a57506001611298565b8161471657505f611298565b816001811461472c576002811461473657614752565b6001915050611298565b60ff84111561474757614747614516565b50506001821b611298565b5060208310610133831016604e8410600b8410161715614775575081810a611298565b61477f83836146ba565b805f190482111561479257614792614516565b029392505050565b5f610af083836146fc565b8181038181111561129857611298614516565b634e487b7160e01b5f52603260045260245ffd5b828152604060208201525f61393d6040830184614467565b5f60033d11156147fa5760045f803e505f5160e01c5b90565b601f8201601f1916810167ffffffffffffffff8111828210171561482f57634e487b7160e01b5f52604160045260245ffd5b6040525050565b5f60443d10156148435790565b6040516003193d81016004833e81513d67ffffffffffffffff816024840111818411171561487357505050505090565b828501915081518181111561488b5750505050505090565b843d87010160208285010111156148a55750505050505090565b6148b4602082860101876147fd565b509095945050505050565b5f600182016148d0576148d0614516565b5060010190565b5f826148f157634e487b7160e01b5f52601260045260245ffd5b500490565b7f416363657373436f6e74726f6c3a206163636f756e742000000000000000000081525f835161492d8160178501602088016143ff565b7001034b99036b4b9b9b4b733903937b6329607d1b601791840191820152835161495e8160288401602088016143ff565b01602801949350505050565b5f6020828403121561497a575f80fd5b81518015158114610af0575f80fd5b5f8161499757614997614516565b505f19019056fe535441524b4e45545f544f4b454e5f4252494447455f4d4553534147494e475f434f4e545241435403711c9d994faf6055172091cb841fd4831aa743e6f3315163b06a122c841846026bd110619d11cfdfc28e281df893bc24828e89177318e9dbd860cdaedeb6b357495448445241574c5f4c494d49545f494e5452414441595f51554f54415f534c4f545f54414700d2ead78c620e94b02d0a996e99298c59ddccfa1d8a0149080ac3a20de060680251e864ca2a080f55bce5da2452e8cfcafdbc951a3e7fff5023d558452ec22853e43b954ba190a7e49386f1f78b01dcd9f628db23f432fa029a7dfd6d98e8fb535441524b4e45545f544f4b454e5f4252494447455f4c325f544f4b454e5f434f4e5452414354008bce41827dd5484d80312a2e43bc42a896e3fcf75bf84c2b49339168dfa00a037693ba312785932d430dccf0f56ffedd0aa7c0f8b6da2cc4530c2717689b9603e615638e0b79444a70f8c695bf8f2a47033bf1cf95691ec3130f64939cee99535441524b4e45545f544f4b454e5f4252494447455f4d414e414745525f534c4f545f54414757495448445241574c5f4c494d49545f57495448445241575f4c494d49545f5043545f534c4f545f544147535441524b4e45545f544f4b454e5f4252494447455f4445504f5349544f525f414444524553534553537461726b576172655f537461726b6e657445524332304272696467655f322e305f3401b64b1b3b690b43b9b514fb81377518f4039cd3e4f4914d8a6bdf01d679fb19c59c20aaa96597268f595db30ec21108a505370e3266ed3a6515637f16b8b689023edb77f7c8cc9e38e8afe78954f703aeeda7fffe014eeb6e56ea84e62f6da7535441524b4e45545f45524332305f544f4b454e5f4252494447455f544f4b454e5f414444524553530128d63adbf6b09002c26caf55c47e2f26635807e3ef1b027218aa74c8d61a3ea2646970667358221220421356d19636ba7734e9ccb3a21e35206c6553d21d77f2aa75ba1cf4f8bfd14c64736f6c63430008140033

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading
[ Download: CSV Export  ]

A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.