ETH Price: $3,326.75 (-1.59%)

Contract

0x95ff25A59Dc9c5A41cF0709dc916041E5dC7fd95
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To

There are no matching entries

Please try again later

View more zero value Internal Transactions in Advanced View mode

Advanced mode:
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
StarknetEthBridge

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 : StarknetEthBridge.sol
/*
  Copyright 2019-2024 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/Addresses.sol";
import "src/solidity/Fees.sol";
import "src/solidity/LegacyBridge.sol";

contract StarknetEthBridge is LegacyBridge {
    using Addresses for address;

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

    function acceptDeposit(
        address, /*token*/
        uint256 amount
    ) internal override returns (uint256) {
        // Make sure msg.value is enough to cover amount. The remaining value is fee.
        require(msg.value >= amount, "INSUFFICIENT_VALUE");
        uint256 fee = msg.value - amount;
        Fees.checkFee(fee);
        // The msg.value was already credited to this contract. Fee will be passed to Starknet.
        require(address(this).balance - fee <= getMaxTotalBalance(ETH), "MAX_BALANCE_EXCEEDED");
        return fee;
    }

    function transferOutFunds(
        address, /*token*/
        uint256 amount,
        address recipient
    ) internal override {
        recipient.performEthTransfer(amount);
    }
}

File 2 of 30 : AccessControl.sol
/*
  Copyright 2019-2024 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-2024 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-2024 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-2024 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-2024 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-2024 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;

// Estimate cost for L1-L2 message handler.
uint256 constant DEPOSIT_FEE_GAS = 20000;
uint256 constant DEPLOYMENT_FEE_GAS = 100000;

// We don't have a solid way to gauge block gas price
// (block.basefee cannot be used).
uint256 constant DEFAULT_WEI_PER_GAS = 5 * 10**9;

abstract contract Fees {
    // Effectively no minimum fee on testnet.
    uint256 immutable MIN_FEE = (block.chainid == 1) ? 10**12 : 1;
    uint256 constant MAX_FEE = 10**16;

    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 checkFee(uint256 feeWei) internal view {
        require(feeWei >= MIN_FEE, "INSUFFICIENT_FEE_VALUE");
        require(feeWei <= MAX_FEE, "FEE_VALUE_TOO_HIGH");
    }
}

File 8 of 30 : Felt252.sol
/*
  Copyright 2019-2024 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-2024 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-2024 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-2024 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-2024 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);

    /**
      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-2024 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-2024 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-2024 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-2024 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-2024 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-2024 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-2024 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-2024 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-2024 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-2024 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-2024 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-2024 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-2024 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-2024 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,
    Fees,
    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.checkFee(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.checkFee(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-2024 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-2024 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-2024 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-2024 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"}]

60e060405246600114620000155760016200001c565b64e8d4a510005b64ffffffffff1660805234801562000032575f80fd5b503060a052600160c0819052620000486200004f565b50620004ff565b336200005c81806200005f565b50565b62000069620001be565b1562000101576001600160a01b0382165f9081527fa5fdb349cc4ffac7e8ce7d3b075149d1bc847367d814e69a9beca89ef02db8b0602052604090205460ff16620000fb5760405162461bcd60e51b815260206004820152601960248201527f524f4c45535f414c52454144595f494e495449414c495a45440000000000000060448201526064015b60405180910390fd5b6200010c565b6200010c826200020f565b6200011662000352565b15620001b3576001600160a01b0381165f9081527f2c11a1f9c63817dbb9f0faa966615764d2db5d6e008269e948a99e0b52181c23602052604090205460ff16620001af5760405162461bcd60e51b815260206004820152602260248201527f53454355524954595f524f4c45535f414c52454144595f494e495449414c495a604482015261115160f21b6064820152608401620000f2565b5050565b620001af81620003a1565b5f8051602062004ddd8339815191525f9081525f8051602062004e1d8339815191526020527fa5fdb349cc4ffac7e8ce7d3b075149d1bc847367d814e69a9beca89ef02db8b15481905b1415905090565b620002295f8051602062004ddd833981519152826200040a565b620002627ed2ead78c620e94b02d0a996e99298c59ddccfa1d8a0149080ac3a20de060685f8051602062004e3d833981519152620004a8565b6200028a5f8051602062004e3d8339815191525f8051602062004ddd833981519152620004a8565b620002a45f8051602062004ddd83398151915280620004a8565b620002de7f023edb77f7c8cc9e38e8afe78954f703aeeda7fffe014eeb6e56ea84e62f6da75f8051602062004e3d833981519152620004a8565b620003187f0128d63adbf6b09002c26caf55c47e2f26635807e3ef1b027218aa74c8d61a3e5f8051602062004e3d833981519152620004a8565b6200005c7f0251e864ca2a080f55bce5da2452e8cfcafdbc951a3e7fff5023d558452ec2285f8051602062004ddd833981519152620004a8565b5f8051602062004dfd8339815191525f9081525f8051602062004e1d8339815191526020527f2c11a1f9c63817dbb9f0faa966615764d2db5d6e008269e948a99e0b52181c2454819062000208565b620003bb5f8051602062004dfd83398151915280620004a8565b620003f57f037693ba312785932d430dccf0f56ffedd0aa7c0f8b6da2cc4530c2717689b965f8051602062004dfd833981519152620004a8565b6200005c5f8051602062004dfd833981519152825b5f8281525f8051602062004e1d833981519152602090815260408083206001600160a01b038516845290915290205460ff16620001af575f8281525f8051602062004e1d833981519152602090815260408083206001600160a01b0385168085529252808320805460ff1916600117905551339285917f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d9190a45050565b5f8281525f8051602062004e1d8339815191526020526040808220600101805490849055905190918391839186917fbd79b86ffe0ab8e8776151514217cd7cacd52c909f66475c3af44e129f0b00ff9190a4505050565b60805160a05160c0516148b36200052a5f395f610ef601525f6110b101525f61333c01526148b35ff3fe608060405260043610610370575f3560e01c80636ffed68b116101c8578063cb1cccce116100fd578063deec9c5a1161009d578063eeb728661161006d578063eeb72866146109ea578063f3fef3a314610a0b578063fa0f73ba14610a2a578063fad8b32a14610a49575f80fd5b8063deec9c5a1461097a578063e2bbb15814610999578063ed9ef16a146109ac578063ee0e6807146109cb575f80fd5b8063d08fb6cb116100d8578063d08fb6cb146108fe578063d12fc1821461091d578063d2b51eea1461093c578063d9fa70911461095b575f80fd5b8063cb1cccce146108a1578063cdd1f70d146108c0578063cf50fd1c146108df575f80fd5b8063a2bdde3d11610168578063af8bc15e11610143578063af8bc15e1461083c578063b5cd0c3c14610850578063be58b18e1461086f578063c1f5eb3a14610882575f80fd5b8063a2bdde3d146107eb578063a6d1d6c61461080a578063ad8b92b414610829575f80fd5b80637fc2ab3e116101a35780637fc2ab3e1461076f5780638101b64c1461078e5780638e5224ff146107ad5780639463629a146107cc575f80fd5b80636ffed68b14610712578063757bd9ab146107315780637d22dbc714610750575f80fd5b806336568abe116102a95780635a5d1bb91161024957806369328dec1161021957806369328dec146106965780636c04d9d5146106b55780636d70f7ae146106d45780636fc97cbf146106f3575f80fd5b80635a5d1bb9146106265780635a72af89146106455780636083e59a1461066457806362a1437614610677575f80fd5b8063439fab9111610284578063439fab91146105b5578063496ae54c146105d45780634baf43da146105f35780634d8b92a514610612575f80fd5b806336568abe146105585780633682a450146105775780633ea053eb14610596575f80fd5b806319534075116103145780632e1a7d4d116102ef5780632e1a7d4d146104b85780632f951985146104d757806330ccebb5146104f657806333eeb14714610546575f80fd5b8063195340751461045857806323205c521461047a578063284b920e14610499575f80fd5b80630e770f231161034f5780630e770f23146103e85780630efe6a8b1461040757806314af98b31461041a5780631789638314610439575f80fd5b8062f714ce146103745780630b3a2d21146103955780630c6f8664146103b4575b5f80fd5b34801561037f575f80fd5b5061039361038e366004613d07565b610a68565b005b3480156103a0575f80fd5b506103936103af366004613d35565b610a7e565b3480156103bf575f80fd5b506103d36103ce366004613d35565b610a98565b60405190151581526020015b60405180910390f35b3480156103f3575f80fd5b50610393610402366004613d35565b610af7565b610393610415366004613d50565b610b0e565b348015610425575f80fd5b50610393610434366004613d35565b610bc6565b348015610444575f80fd5b50610393610453366004613d35565b610c6c565b348015610463575f80fd5b5061046c610c83565b6040519081526020016103df565b348015610485575f80fd5b50610393610494366004613d82565b610c94565b3480156104a4575f80fd5b506103936104b3366004613d35565b610d86565b3480156104c3575f80fd5b506103936104d2366004613dba565b610e8b565b3480156104e2575f80fd5b506103936104f1366004613d35565b610e9d565b348015610501575f80fd5b50610539610510366004613d35565b6001600160a01b03165f9081525f805160206147d4833981519152602052604090205460ff1690565b6040516103df9190613de5565b348015610551575f80fd5b505f6103d3565b348015610563575f80fd5b50610393610572366004613d07565b610edd565b348015610582575f80fd5b50610393610591366004613d35565b610f6e565b3480156105a1575f80fd5b506103936105b0366004613d35565b610f85565b3480156105c0575f80fd5b506103936105cf366004613e0b565b6110ae565b3480156105df575f80fd5b5061046c6105ee366004613d35565b61125a565b3480156105fe575f80fd5b5061046c61060d366004613d35565b61129e565b34801561061d575f80fd5b5061046c6112da565b348015610631575f80fd5b506103d3610640366004613d35565b6112e3565b348015610650575f80fd5b5061039361065f366004613d35565b6112fb565b34801561066f575f80fd5b505f1961046c565b348015610682575f80fd5b50610393610691366004613d35565b61139e565b3480156106a1575f80fd5b506103936106b0366004613e77565b6113b5565b3480156106c0575f80fd5b506103d36106cf366004613d35565b6114a0565b3480156106df575f80fd5b506103d36106ee366004613d35565b6114b8565b3480156106fe575f80fd5b5061039361070d366004613d35565b6114d0565b34801561071d575f80fd5b5061039361072c366004613eb6565b6114e7565b34801561073c575f80fd5b506103d361074b366004613d35565b611635565b34801561075b575f80fd5b5061039361076a366004613eb6565b61164d565b34801561077a575f80fd5b50610393610789366004613dba565b6117a3565b348015610799575f80fd5b506103936107a8366004613d35565b6118c8565b3480156107b8575f80fd5b506103d36107c7366004613d35565b611908565b3480156107d7575f80fd5b506103936107e6366004613d35565b611920565b3480156107f6575f80fd5b506103d3610805366004613d35565b611937565b348015610815575f80fd5b50610393610824366004613d82565b61194f565b610393610837366004613d35565b611a2c565b348015610847575f80fd5b5061046c611a62565b34801561085b575f80fd5b5061039361086a366004613f27565b611a6b565b61039361087d366004613f94565b611b9d565b34801561088d575f80fd5b5061039361089c366004613d35565b611caa565b3480156108ac575f80fd5b506103d36108bb366004613d35565b611da4565b3480156108cb575f80fd5b506103936108da366004613d35565b611dbc565b3480156108ea575f80fd5b506103936108f9366004613f27565b611dd3565b348015610909575f80fd5b506103d3610918366004613d35565b611eea565b348015610928575f80fd5b50610393610937366004613d35565b611f02565b348015610947575f80fd5b50610393610956366004613ff9565b612117565b348015610966575f80fd5b50610393610975366004613d35565b61221d565b348015610985575f80fd5b50610393610994366004613d35565b612234565b6103936109a7366004614023565b61224b565b3480156109b7575f80fd5b506103936109c6366004613d35565b6122f9565b3480156109d6575f80fd5b506103936109e5366004613d35565b612310565b3480156109f5575f80fd5b506109fe612350565b6040516103df9190614065565b348015610a16575f80fd5b50610393610a25366004613ff9565b612370565b348015610a35575f80fd5b50610393610a44366004613d35565b61237b565b348015610a54575f80fd5b50610393610a63366004613d35565b612392565b610a7a610a736123a9565b83836113b5565b5050565b610a955f8051602061483d833981519152826123cb565b50565b6001600160a01b0381165f9081525f805160206147d4833981519152602052604081205460ff166001816003811115610ad357610ad3613dd1565b1480610af057506002816003811115610aee57610aee613dd1565b145b9392505050565b610a955f805160206146fa833981519152826123cb565b82610b1881610a98565b610b5e5760405162461bcd60e51b81526020600482015260126024820152711513d2d15397d393d517d4d154959250d15160721b60448201526064015b60405180910390fd5b604080515f8082526020820190925290610b7886866123ec565b90505f610b96878787865f805160206147b4833981519152876124a3565b9050610bb4878787865f805160206147b48339815191528688612625565b610bbd87611f02565b50505050505050565b610bcf33611635565b610c115760405162461bcd60e51b815260206004820152601360248201527213d3931657d4d150d55492551657d051d15395606a1b6044820152606401610b55565b6001600160a01b0381165f8181525f805160206147d48339815191526020526040808220600401805460ff191660011790555133917fe2deca319add01142d26def2de47e64bf1fdc70e6f90c13a1862a48bdaaa7cfd91a350565b610a955f8051602061471a833981519152826123cb565b5f610c8f61060d6123a9565b905090565b610c9c612738565b6001600160a01b0316636170ff1b610cb261275a565b5f805160206147b4833981519152610ccb88888861277c565b856040518563ffffffff1660e01b8152600401610ceb94939291906140e4565b6020604051808303815f875af1158015610d07573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610d2b9190614113565b50610d378484336127a5565b604080518481526020810183905283916001600160a01b0387169133917f50485fb0face2cfd73784044ab4191986b4a6713f01854414e2331a6bb41837d91015b60405180910390a450505050565b610d9d5f805160206145ec833981519152336127b8565b610de15760405162461bcd60e51b8152602060048201526015602482015274474f5645524e414e43455f41444d494e5f4f4e4c5960581b6044820152606401610b55565b6001600160a01b0381165f8181527f45f38e273862f8834bd2fe7a449988f63de55a7a5b685dea46ccedeb69cf0e266020818152604092839020805460ff191660011790557f45f38e273862f8834bd2fe7a449988f63de55a7a5b685dea46ccedeb69cf0e2780546001600160a01b03191690559151928352917fcfb473e6c03f9a29ddaf990e736fa3de5188a0bd85d684f5b6e164ebfbfff5d291015b60405180910390a15050565b610a95610e966123a9565b82336113b5565b80336001600160a01b03821603610ec65760405162461bcd60e51b8152600401610b559061412a565b610a7a5f8051602061471a833981519152836127ee565b5f805160206145ec83398151915282148015610f1757507f0000000000000000000000000000000000000000000000000000000000000000155b15610f645760405162461bcd60e51b815260206004820181905260248201527f43414e4e4f545f52454e4f554e43455f474f5645524e414e43455f41444d494e6044820152606401610b55565b610a7a828261280a565b610a955f805160206147f4833981519152826123cb565b33610f8e612884565b6001600160a01b031614610fd35760405162461bcd60e51b815260206004820152600c60248201526b27a7262cafa6a0a720a3a2a960a11b6044820152606401610b55565b6001600160a01b0381165f9081525f805160206147d4833981519152602052604081205460ff16600381111561100b5761100b613dd1565b036110485760405162461bcd60e51b815260206004820152600d60248201526c2aa725a727aba72faa27a5a2a760991b6044820152606401610b55565b6001600160a01b0381165f8181525f805160206147d48339815191526020908152604091829020805460ff1916600317905590519182527f86d6e4556eae726303caf49a75add7d92ac713e46db458dab0622aa263fb48e691015b60405180910390a150565b307f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03160361111f5760405162461bcd60e51b81526020600482015260166024820152751112549150d517d0d0531317d11254d0531313d5d15160521b6044820152606401610b55565b5f61112b81602061416e565b90505f611139826020614185565b9050808310156111815760405162461bcd60e51b81526020600482015260136024820152721253925517d110551057d513d3d7d4d3505313606a1b6044820152606401610b55565b5f61118e82848688614198565b81019061119b9190613d35565b9050365f6111ab8582888a614198565b91509150365f6111bd8887818c614198565b90925090506001600160a01b038516156111e7576111dc8583836128a6565b505050505050505050565b6111ef6129e4565b1561123e5780156112395760405162461bcd60e51b8152602060048201526014602482015273554e45585045435445445f494e49545f4441544160601b6044820152606401610b55565b6111dc565b61124882826129fe565b6112528282612b15565b6111dc612b43565b6001600160a01b0381165f9081525f805160206147d4833981519152602052604081206004015460ff1661128f575f19611298565b61129882612b4e565b92915050565b6001600160a01b0381165f9081525f805160206147d4833981519152602052604081206003015480156112d15780610af0565b5f199392505050565b5f610c8f612b6e565b5f6112985f80516020614653833981519152836127b8565b61130433611eea565b6113465760405162461bcd60e51b815260206004820152601360248201527227a7262cafa9a2a1aaa924aa2cafa0a226a4a760691b6044820152606401610b55565b6001600160a01b0381165f8181525f805160206147d48339815191526020526040808220600401805460ff191690555133917f109dee66091b7a145f557f52c55d7beccb6a29011fc705557e2975749474076b91a350565b610a955f8051602061460c833981519152826123cb565b6001600160a01b0381166113ff5760405162461bcd60e51b81526020600482015260116024820152701253959053125117d49150d25412515395607a1b6044820152606401610b55565b61140a838383612b81565b6001600160a01b0383165f9081525f805160206147d4833981519152602052604090206004015460ff1615611443576114438383612e91565b61144e8383836127a5565b826001600160a01b0316816001600160a01b03167f2717ead6b9200dd235aad468c9809ea400fe33ac69b5bfaa6d3e90fc922b63988460405161149391815260200190565b60405180910390a3505050565b5f6112985f80516020614673833981519152836127b8565b5f6112985f805160206147f4833981519152836127b8565b610a955f80516020614673833981519152826123cb565b80336114f1612f00565b5f83815260209190915260409020546001600160a01b0316146115475760405162461bcd60e51b815260206004820152600e60248201526d27a7262cafa222a827a9a4aa27a960911b6044820152606401610b55565b61154f612738565b6001600160a01b0316637a98660b61156561275a565b7f02d757788a8d8d6f21d1cd40bce38a8222d70654214e96ff95d8086e684fbee56115908888612f22565b866040518563ffffffff1660e01b81526004016115b094939291906140e4565b6020604051808303815f875af11580156115cc573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906115f09190614113565b506040805185815260208101849052849133917fea57f52faafe318751f75acb6756cff3f66afc10201ef8f2d504e788985db3f591015b60405180910390a350505050565b5f6112985f805160206146fa833981519152836127b8565b8033611657612f00565b5f83815260209190915260409020546001600160a01b0316146116ad5760405162461bcd60e51b815260206004820152600e60248201526d27a7262cafa222a827a9a4aa27a960911b6044820152606401610b55565b6116b5612738565b6001600160a01b0316636170ff1b6116cb61275a565b7f02d757788a8d8d6f21d1cd40bce38a8222d70654214e96ff95d8086e684fbee56116f68888612f22565b866040518563ffffffff1660e01b815260040161171694939291906140e4565b6020604051808303815f875af1158015611732573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906117569190614113565b506117696117626123a9565b85336127a5565b6040805185815260208101849052849133917fb0b548d5e12b6a60adac4d6dd7610f55134cea4fd145535edc303a48063e0cb49101611627565b6117ac336112e3565b6117ec5760405162461bcd60e51b815260206004820152601160248201527027a7262cafa0a8282fa3a7ab22a92727a960791b6044820152606401610b55565b6117f46129e4565b6118405760405162461bcd60e51b815260206004820152601860248201527f434f4e54524143545f4e4f545f494e495449414c495a454400000000000000006044820152606401610b55565b61184981612fc8565b61188f5760405162461bcd60e51b81526020600482015260176024820152764c325f414444524553535f4f55545f4f465f52414e474560481b6044820152606401610b55565b61189881612fea565b6040518181527f90fc3f39f8e4669d1bf5f9038707949f8af42a973f62988143be0fa7c3997f18906020016110a3565b80336001600160a01b038216036118f15760405162461bcd60e51b8152600401610b559061412a565b610a7a5f8051602061460c833981519152836127ee565b5f6112985f8051602061471a833981519152836127b8565b610a955f805160206145ec833981519152826123cb565b5f6112985f8051602061483d833981519152836127b8565b611957612738565b6001600160a01b0316637a98660b61196d61275a565b5f805160206147b483398151915261198688888861277c565b856040518563ffffffff1660e01b81526004016119a694939291906140e4565b6020604051808303815f875af11580156119c2573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906119e69190614113565b50604080518481526020810183905283916001600160a01b0387169133917f8f3da3ce93acd45e015b069c8f032d37be93dc9efcaaeda368aa9ca74f64c30a9101610d78565b60405162461bcd60e51b815260206004820152600b60248201526a155394d5541413d495115160aa1b6044820152606401610b55565b5f610c8f61300c565b611a73612738565b6001600160a01b0316636170ff1b611a8961275a565b5f805160206146da833981519152611ad78a8a8a60018b8b808060200260200160405190810160405280939291908181526020018383602002808284375f9201919091525061301e92505050565b856040518563ffffffff1660e01b8152600401611af794939291906140e4565b6020604051808303815f875af1158015611b13573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611b379190614113565b50611b438686336127a5565b83866001600160a01b0316336001600160a01b03167fa465a02eedf06ceffd1d99159ad98c5d8fa7f17b870eb22e0bfcec06398a8f7388878787604051611b8d94939291906141bf565b60405180910390a4505050505050565b84611ba781610a98565b611be85760405162461bcd60e51b81526020600482015260126024820152711513d2d15397d393d517d4d154959250d15160721b6044820152606401610b55565b5f611bf387876123ec565b90505f611c458888888888808060200260200160405190810160405280939291908181526020018383602002808284375f920191909152505f805160206146da83398151915292508991506124a39050565b9050611c978888888888808060200260200160405190810160405280939291908181526020018383602002808284375f920191909152505f805160206146da8339815191529250889150899050612625565b611ca088611f02565b5050505050505050565b611cc15f805160206145ec833981519152336127b8565b611d055760405162461bcd60e51b8152602060048201526015602482015274474f5645524e414e43455f41444d494e5f4f4e4c5960581b6044820152606401610b55565b6001600160a01b0381165f8181527f45f38e273862f8834bd2fe7a449988f63de55a7a5b685dea46ccedeb69cf0e266020818152604092839020805460ff191690557f45f38e273862f8834bd2fe7a449988f63de55a7a5b685dea46ccedeb69cf0e2780546001600160a01b03191690559151928352917fd75f94825e770b8b512be8e74759e252ad00e102e38f50cce2f7c6f868a295999101610e7f565b5f6112985f805160206145ec833981519152836127b8565b610a955f80516020614653833981519152826123cb565b611ddb612738565b6001600160a01b0316637a98660b611df161275a565b5f805160206146da833981519152611e3f8a8a8a60018b8b808060200260200160405190810160405280939291908181526020018383602002808284375f9201919091525061301e92505050565b856040518563ffffffff1660e01b8152600401611e5f94939291906140e4565b6020604051808303815f875af1158015611e7b573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611e9f9190614113565b5083866001600160a01b0316336001600160a01b03167f889e470f207032611b2f68dbd2124e3139794f19a6b536c83892fd505760386088878787604051611b8d94939291906141bf565b5f6112985f8051602061460c833981519152836127b8565b6001600160a01b0381165f9081525f805160206147d48339815191526020526040902054819060019060ff166003811115611f3f57611f3f613dd1565b14611f48575050565b6001600160a01b0382165f9081525f805160206147d4833981519152602052604090206001810154611f78612738565b6001600160a01b03166377c7d7a9826040518263ffffffff1660e01b8152600401611fa591815260200190565b602060405180830381865afa158015611fc0573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611fe49190614113565b5f03611ffa57815460ff19166002178255612111565b8160020154421115612111576001600160a01b0384165f9081525f805160206147d483398151915260205260408120805460ff19908116825560018201839055600282018390556003820183905560049091018054909116905561205c612884565b6001600160a01b0316635ab1bd536040518163ffffffff1660e01b8152600401602060405180830381865afa158015612097573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906120bb9190614203565b604051630caca05160e31b81526001600160a01b038781166004830152919250908216906365650288906024015f604051808303815f87803b1580156120ff575f80fd5b505af11580156111dc573d5f803e3d5ffd5b50505050565b612120336112e3565b6121605760405162461bcd60e51b815260206004820152601160248201527027a7262cafa0a8282fa3a7ab22a92727a960791b6044820152606401610b55565b805f036121af5760405162461bcd60e51b815260206004820152601960248201527f494e56414c49445f4d41585f544f54414c5f42414c414e4345000000000000006044820152606401610b55565b816001600160a01b03167fb895637c7d86c9b7b5b747e72195206a3fc21d8df0e019edd2312454ffa733b1826040516121ea91815260200190565b60405180910390a26001600160a01b03919091165f9081525f805160206147d48339815191526020526040902060030155565b610a955f805160206146fa833981519152826127ee565b610a955f80516020614653833981519152826127ee565b604080515f80825260208201909252906122636123a9565b90505f61227082866123ec565b90505f61228e838787875f805160206147b4833981519152876124a3565b90506122ac838787875f805160206147b48339815191528688612625565b6040805187815260208101839052908101839052859033907f5b5dbc6c64043a15d3fe6943a6e443a826b78755edc257b2ec890c022225dbcf9060600160405180910390a3505050505050565b610a955f80516020614673833981519152826127ee565b80336001600160a01b038216036123395760405162461bcd60e51b8152600401610b559061412a565b610a7a5f805160206145ec833981519152836127ee565b606060405180606001604052806021815260200161485d60219139905090565b610a7a8282336113b5565b610a955f8051602061483d833981519152826127ee565b610a955f805160206147f4833981519152826127ee565b5f610c8f60405180606001604052806029815260200161481460299139613269565b6123d48261329c565b6123dd816132bc565b6123e783836132c6565b505050565b5f813410156124325760405162461bcd60e51b8152602060048201526012602482015271494e53554646494349454e545f56414c554560701b6044820152606401610b55565b5f61243d833461421e565b90506124488161333a565b6124546245544861129e565b61245e824761421e565b1115610af05760405162461bcd60e51b815260206004820152601460248201527313505617d09053105390d157d15610d15151115160621b6044820152606401610b55565b5f6124ac61275a565b5f036124ee5760405162461bcd60e51b8152602060048201526011602482015270130c97d094925111d157d393d517d4d155607a1b6044820152606401610b55565b5f861161252c5760405162461bcd60e51b815260206004820152600c60248201526b16915493d7d1115413d4d25560a21b6044820152606401610b55565b61253585612fc8565b61257b5760405162461bcd60e51b81526020600482015260176024820152764c325f414444524553535f4f55545f4f465f52414e474560481b6044820152606401610b55565b5f805160206146da83398151915283145f612594612738565b6001600160a01b0316633e3aa6c5856125ab61275a565b886125b98e8e8e8a8f61301e565b6040518563ffffffff1660e01b81526004016125d793929190614231565b604080518083038185885af11580156125f2573d5f803e3d5ffd5b50505050506040513d601f19601f82011682018060405250810190612617919061424f565b9a9950505050505050505050565b5f805160206147b4833981519152830361268e57604080518781526020810184905290810182905285906001600160a01b0389169033907f5f971bd00bf3ffbca8a6d72cdd4fd92cfd4f62636161921d1e5a64f0b64ccb6d9060600160405180910390a4610bbd565b5f805160206146da83398151915283146126dd5760405162461bcd60e51b815260206004820152601060248201526f2aa725a727aba72fa9a2a622a1aa27a960811b6044820152606401610b55565b84876001600160a01b0316336001600160a01b03167f2203a49c69f1a46c1164f5e4a30643dd77b7c59c0ff9bc433256048365c247f1898887876040516127279493929190614271565b60405180910390a450505050505050565b5f610c8f6040518060600160405280602881526020016145c460289139613269565b5f610c8f6040518060600160405280602781526020016146b360279139613269565b604080515f808252602082019092526060915061279c8585855f8561301e565b95945050505050565b6123e76001600160a01b038216836133ef565b5f9182525f80516020614693833981519152602090815260408084206001600160a01b0393909316845291905290205460ff1690565b6127f78261329c565b612800816132bc565b6123e7838361348f565b6001600160a01b038116331461287a5760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b6064820152608401610b55565b610a7a828261348f565b5f610c8f60405180606001604052806026815260200161473a60269139613269565b6001600160a01b0383163b6128f25760405162461bcd60e51b8152602060048201526012602482015271115250d7d393d517d057d0d3d395149050d560721b6044820152606401610b55565b5f80846001600160a01b031663439fab9160e01b858560405160240161291992919061429c565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b031990941693909317909252905161295791906142ca565b5f60405180830381855af49150503d805f811461298f576040519150601f19603f3d011682016040523d82523d5f602084013e612994565b606091505b50915091508181906129b95760405162461bcd60e51b8152600401610b559190614065565b5080518190156129dc5760405162461bcd60e51b8152600401610b559190614065565b505050505050565b5f806129ee612738565b6001600160a01b03161415905090565b60408114612a425760405162461bcd60e51b8152602060048201526011602482015270494c4c4547414c5f444154415f53495a4560781b6044820152606401610b55565b5f80612a50838501856142e5565b91509150612a67816001600160a01b03163b151590565b612abe5760405162461bcd60e51b815260206004820152602260248201527f494e56414c49445f4d4553534147494e475f434f4e54524143545f4144445245604482015261535360f01b6064820152608401610b55565b6001600160a01b0382163b6121115760405162461bcd60e51b815260206004820181905260248201527f494e56414c49445f4d414e414745525f434f4e54524143545f414444524553536044820152606401610b55565b5f80612b23838501856142e5565b91509150612b3081613501565b612b3982613523565b6121116005613545565b33610a958180613567565b5f612b5882613669565b612b655761129882613694565b61129882613743565b5f610c8f64012a05f200620186a061416e565b612b8961275a565b5f03612bcb5760405162461bcd60e51b8152602060048201526011602482015270130c97d094925111d157d393d517d4d155607a1b6044820152606401610b55565b6001600160a01b0381165f6001612be4608060026143f1565b612bee919061421e565b60408051600580825260c082019092529186169250608086901c915f916020820160a0803683370190505090505f815f81518110612c2e57612c2e6143fc565b6020026020010181815250508381600181518110612c4e57612c4e6143fc565b602002602001018181525050866001600160a01b031681600281518110612c7757612c776143fc565b6020026020010181815250508281600381518110612c9757612c976143fc565b6020026020010181815250508181600481518110612cb757612cb76143fc565b602002602001018181525050612ccb612738565b6001600160a01b0316632c9dd5c0612ce161275a565b836040518363ffffffff1660e01b8152600401612cff929190614410565b6020604051808303815f875af1925050508015612d39575060408051601f3d908101601f19168201909252612d3691810190614113565b60015b611ca057612d45614428565b806308c379a003612e875750612d5961447a565b80612d645750612e89565b60408051600480825260a0820190925290602082016080803683370190505091505f825f81518110612d9857612d986143fc565b6020026020010181815250508482600181518110612db857612db86143fc565b6020026020010181815250508382600281518110612dd857612dd86143fc565b6020026020010181815250508282600381518110612df857612df86143fc565b602002602001018181525050612e0c612738565b6001600160a01b0316632c9dd5c0612e2261275a565b846040518363ffffffff1660e01b8152600401612e40929190614410565b6020604051808303815f875af1158015612e5c573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612e809190614113565b5050610bbd565b505b3d5f803e3d5ffd5b5f612e9b83612b4e565b905081811015612eed5760405162461bcd60e51b815260206004820152601d60248201527f455843454544535f474c4f42414c5f57495448445241575f4c494d49540000006044820152606401610b55565b6123e783612efb848461421e565b613770565b5f610c8f60405180606001604052806029815260200161478b602991396137a1565b604080516003808252608082019092526060915f919060208201848036833701905050905082815f81518110612f5a57612f5a6143fc565b60209081029190910101526001612f73608060026143f1565b612f7d919061421e565b841681600181518110612f9257612f926143fc565b602002602001018181525050608084901c81600281518110612fb657612fb66143fc565b60209081029190910101529392505050565b5f8115801590611298575061129882600167080000000000001160c01b011190565b610a956040518060600160405280602781526020016146b360279139826137d3565b5f610c8f64012a05f200614e2061416e565b60605f8361302d576005613039565b61303960016005614185565b90505f8351826130499190614185565b67ffffffffffffffff81111561306157613061614097565b60405190808252806020026020018201604052801561308a578160200160208202803683370190505b509050876001600160a01b0316815f815181106130a9576130a96143fc565b602002602001018181525050336001600160a01b0316816001815181106130d2576130d26143fc565b60200260200101818152505085816002815181106130f2576130f26143fc565b6020908102919091010152600161310b608060026143f1565b613115919061421e565b87168160038151811061312a5761312a6143fc565b602002602001018181525050608087901c8160048151811061314e5761314e6143fc565b602002602001018181525050841561325e5783518161316e60018561421e565b8151811061317e5761317e6143fc565b6020026020010181815250505f5b845181101561325c576131c58582815181106131aa576131aa6143fc565b6020026020010151600167080000000000001160c01b011190565b6132085760405162461bcd60e51b8152602060048201526014602482015273494e56414c49445f4d4553534147455f4441544160601b6044820152606401610b55565b84818151811061321a5761321a6143fc565b602002602001015182848361322f9190614185565b8151811061323f5761323f6143fc565b60209081029190910101528061325481614503565b91505061318c565b505b979650505050505050565b5f808260405160200161327c91906142ca565b60408051601f198184030181529190528051602090910120549392505050565b5f9081525f80516020614693833981519152602052604090206001015490565b610a958133613821565b6132d082826127b8565b610a7a575f8281525f80516020614693833981519152602090815260408083206001600160a01b0385168085529252808320805460ff1916600117905551339285917f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d9190a45050565b7f00000000000000000000000000000000000000000000000000000000000000008110156133a35760405162461bcd60e51b8152602060048201526016602482015275494e53554646494349454e545f4645455f56414c554560501b6044820152606401610b55565b662386f26fc10000811115610a955760405162461bcd60e51b815260206004820152601260248201527108c8a8abeac8298aa8abea89e9ebe90928e960731b6044820152606401610b55565b805f036133fa575050565b5f826001600160a01b0316826040515f6040518083038185875af1925050503d805f8114613443576040519150601f19603f3d011682016040523d82523d5f602084013e613448565b606091505b50509050806123e75760405162461bcd60e51b815260206004820152601360248201527211551217d514905394d1915497d19052531151606a1b6044820152606401610b55565b61349982826127b8565b15610a7a575f8281525f80516020614693833981519152602090815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b610a956040518060600160405280602881526020016145c46028913982613885565b610a9560405180606001604052806026815260200161473a6026913982613885565b610a956040518060600160405280602b8152602001614760602b9139826138d3565b61356f613905565b156135dc5761358b5f805160206145ec833981519152836127b8565b6135d75760405162461bcd60e51b815260206004820152601960248201527f524f4c45535f414c52454144595f494e495449414c495a4544000000000000006044820152606401610b55565b6135e5565b6135e582613924565b6135ed613a06565b15613660576136095f8051602061460c833981519152826127b8565b610a7a5760405162461bcd60e51b815260206004820152602260248201527f53454355524954595f524f4c45535f414c52454144595f494e495449414c495a604482015261115160f21b6064820152608401610b55565b610a7a81613a1e565b5f613672613a70565b5f61367c84613a92565b81526020019081526020015f20545f14159050919050565b5f8062455447196001600160a01b038416016136b157504761371a565b6040516370a0823160e01b81523060048201526001600160a01b038416906370a0823190602401602060405180830381865afa1580156136f3573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906137179190614113565b90505b5f613723613ade565b90506064613731828461416e565b61373b919061451b565b949350505050565b5f600161374e613a70565b5f61375885613a92565b81526020019081526020015f2054611298919061421e565b61377b600182614185565b613783613a70565b5f61378d85613a92565b815260208101919091526040015f20555050565b5f80826040516020016137b491906142ca565b60408051601f1981840301815291905280516020909101209392505050565b6137dc82613269565b156138175760405162461bcd60e51b815260206004820152600b60248201526a1053149150511657d4d15560aa1b6044820152606401610b55565b610a7a82826138d3565b61382b82826127b8565b610a7a57613843816001600160a01b03166014613b00565b61384e836020613b00565b60405160200161385f92919061453a565b60408051601f198184030181529082905262461bcd60e51b8252610b5591600401614065565b5f61388f83613269565b6001600160a01b0316146138175760405162461bcd60e51b815260206004820152600b60248201526a1053149150511657d4d15560aa1b6044820152606401610b55565b5f826040516020016138e591906142ca565b604051602081830303815290604052805190602001209050818155505050565b5f8061391d5f805160206145ec83398151915261329c565b1415905090565b61393b5f805160206145ec833981519152826132c6565b61395f5f805160206146538339815191525f8051602061471a833981519152613c96565b6139835f8051602061471a8339815191525f805160206145ec833981519152613c96565b61399a5f805160206145ec83398151915280613c96565b6139be5f805160206147f48339815191525f8051602061471a833981519152613c96565b6139e25f8051602061483d8339815191525f8051602061471a833981519152613c96565b610a955f805160206146738339815191525f805160206145ec833981519152613c96565b5f8061391d5f8051602061460c83398151915261329c565b613a355f8051602061460c83398151915280613c96565b613a595f805160206146fa8339815191525f8051602061460c833981519152613c96565b610a955f8051602061460c833981519152826132c6565b5f610c8f60405180606001604052806027815260200161462c602791396137a1565b5f80613aa1620151804261451b565b604080516001600160a01b038616602082015290810182905290915060600160405160208183030381529060405280519060200120915050919050565b5f610c8f6040518060600160405280602b8152602001614760602b9139613269565b60605f613b0e83600261416e565b613b19906002614185565b67ffffffffffffffff811115613b3157613b31614097565b6040519080825280601f01601f191660200182016040528015613b5b576020820181803683370190505b509050600360fc1b815f81518110613b7557613b756143fc565b60200101906001600160f81b03191690815f1a905350600f60fb1b81600181518110613ba357613ba36143fc565b60200101906001600160f81b03191690815f1a9053505f613bc584600261416e565b613bd0906001614185565b90505b6001811115613c47576f181899199a1a9b1b9c1cb0b131b232b360811b85600f1660108110613c0457613c046143fc565b1a60f81b828281518110613c1a57613c1a6143fc565b60200101906001600160f81b03191690815f1a90535060049490941c93613c40816145ae565b9050613bd3565b508315610af05760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610b55565b5f613ca08361329c565b5f8481525f805160206146938339815191526020526040808220600101859055519192508391839186917fbd79b86ffe0ab8e8776151514217cd7cacd52c909f66475c3af44e129f0b00ff9190a4505050565b6001600160a01b0381168114610a95575f80fd5b5f8060408385031215613d18575f80fd5b823591506020830135613d2a81613cf3565b809150509250929050565b5f60208284031215613d45575f80fd5b8135610af081613cf3565b5f805f60608486031215613d62575f80fd5b8335613d6d81613cf3565b95602085013595506040909401359392505050565b5f805f8060808587031215613d95575f80fd5b8435613da081613cf3565b966020860135965060408601359560600135945092505050565b5f60208284031215613dca575f80fd5b5035919050565b634e487b7160e01b5f52602160045260245ffd5b6020810160048310613e0557634e487b7160e01b5f52602160045260245ffd5b91905290565b5f8060208385031215613e1c575f80fd5b823567ffffffffffffffff80821115613e33575f80fd5b818501915085601f830112613e46575f80fd5b813581811115613e54575f80fd5b866020828501011115613e65575f80fd5b60209290920196919550909350505050565b5f805f60608486031215613e89575f80fd5b8335613e9481613cf3565b9250602084013591506040840135613eab81613cf3565b809150509250925092565b5f805f60608486031215613ec8575f80fd5b505081359360208301359350604090920135919050565b5f8083601f840112613eef575f80fd5b50813567ffffffffffffffff811115613f06575f80fd5b6020830191508360208260051b8501011115613f20575f80fd5b9250929050565b5f805f805f8060a08789031215613f3c575f80fd5b8635613f4781613cf3565b95506020870135945060408701359350606087013567ffffffffffffffff811115613f70575f80fd5b613f7c89828a01613edf565b979a9699509497949695608090950135949350505050565b5f805f805f60808688031215613fa8575f80fd5b8535613fb381613cf3565b94506020860135935060408601359250606086013567ffffffffffffffff811115613fdc575f80fd5b613fe888828901613edf565b969995985093965092949392505050565b5f806040838503121561400a575f80fd5b823561401581613cf3565b946020939093013593505050565b5f8060408385031215614034575f80fd5b50508035926020909101359150565b5f5b8381101561405d578181015183820152602001614045565b50505f910152565b602081525f8251806020840152614083816040850160208701614043565b601f01601f19169190910160400192915050565b634e487b7160e01b5f52604160045260245ffd5b5f8151808452602080850194508084015f5b838110156140d9578151875295820195908201906001016140bd565b509495945050505050565b848152836020820152608060408201525f61410260808301856140ab565b905082606083015295945050505050565b5f60208284031215614123575f80fd5b5051919050565b60208082526016908201527521a0a72727aa2fa822a92327a926afa7a72fa9a2a62360511b604082015260600190565b634e487b7160e01b5f52601160045260245ffd5b80820281158282048414176112985761129861415a565b808201808211156112985761129861415a565b5f80858511156141a6575f80fd5b838611156141b2575f80fd5b5050820193919092039150565b84815260606020820181905281018390525f6001600160fb1b038411156141e4575f80fd5b8360051b80866080850137604083019390935250016080019392505050565b5f60208284031215614213575f80fd5b8151610af081613cf3565b818103818111156112985761129861415a565b838152826020820152606060408201525f61279c60608301846140ab565b5f8060408385031215614260575f80fd5b505080516020909101519092909150565b848152608060208201525f61428960808301866140ab565b6040830194909452506060015292915050565b60208152816020820152818360408301375f818301604090810191909152601f909201601f19160101919050565b5f82516142db818460208701614043565b9190910192915050565b5f80604083850312156142f6575f80fd5b823561430181613cf3565b91506020830135613d2a81613cf3565b600181815b8085111561434b57815f19048211156143315761433161415a565b8085161561433e57918102915b93841c9390800290614316565b509250929050565b5f8261436157506001611298565b8161436d57505f611298565b8160018114614383576002811461438d576143a9565b6001915050611298565b60ff84111561439e5761439e61415a565b50506001821b611298565b5060208310610133831016604e8410600b84101617156143cc575081810a611298565b6143d68383614311565b805f19048211156143e9576143e961415a565b029392505050565b5f610af08383614353565b634e487b7160e01b5f52603260045260245ffd5b828152604060208201525f61373b60408301846140ab565b5f60033d111561443e5760045f803e505f5160e01c5b90565b601f8201601f1916810167ffffffffffffffff8111828210171561447357634e487b7160e01b5f52604160045260245ffd5b6040525050565b5f60443d10156144875790565b6040516003193d81016004833e81513d67ffffffffffffffff81602484011181841117156144b757505050505090565b82850191508151818111156144cf5750505050505090565b843d87010160208285010111156144e95750505050505090565b6144f860208286010187614441565b509095945050505050565b5f600182016145145761451461415a565b5060010190565b5f8261453557634e487b7160e01b5f52601260045260245ffd5b500490565b7f416363657373436f6e74726f6c3a206163636f756e742000000000000000000081525f8351614571816017850160208801614043565b7001034b99036b4b9b9b4b733903937b6329607d1b60179184019182015283516145a2816028840160208801614043565b01602801949350505050565b5f816145bc576145bc61415a565b505f19019056fe535441524b4e45545f544f4b454e5f4252494447455f4d4553534147494e475f434f4e545241435403711c9d994faf6055172091cb841fd4831aa743e6f3315163b06a122c841846026bd110619d11cfdfc28e281df893bc24828e89177318e9dbd860cdaedeb6b357495448445241574c5f4c494d49545f494e5452414441595f51554f54415f534c4f545f54414700d2ead78c620e94b02d0a996e99298c59ddccfa1d8a0149080ac3a20de060680251e864ca2a080f55bce5da2452e8cfcafdbc951a3e7fff5023d558452ec22853e43b954ba190a7e49386f1f78b01dcd9f628db23f432fa029a7dfd6d98e8fb535441524b4e45545f544f4b454e5f4252494447455f4c325f544f4b454e5f434f4e5452414354008bce41827dd5484d80312a2e43bc42a896e3fcf75bf84c2b49339168dfa00a037693ba312785932d430dccf0f56ffedd0aa7c0f8b6da2cc4530c2717689b9603e615638e0b79444a70f8c695bf8f2a47033bf1cf95691ec3130f64939cee99535441524b4e45545f544f4b454e5f4252494447455f4d414e414745525f534c4f545f54414757495448445241574c5f4c494d49545f57495448445241575f4c494d49545f5043545f534c4f545f544147535441524b4e45545f544f4b454e5f4252494447455f4445504f5349544f525f41444452455353455301b64b1b3b690b43b9b514fb81377518f4039cd3e4f4914d8a6bdf01d679fb19c59c20aaa96597268f595db30ec21108a505370e3266ed3a6515637f16b8b689023edb77f7c8cc9e38e8afe78954f703aeeda7fffe014eeb6e56ea84e62f6da7535441524b4e45545f45524332305f544f4b454e5f4252494447455f544f4b454e5f414444524553530128d63adbf6b09002c26caf55c47e2f26635807e3ef1b027218aa74c8d61a3e537461726b576172655f537461726b6e65744574684272696467655f322e305f34a2646970667358221220aeb26be5ec3ed9f5d1316e4f3d68426df4beb9913f84a81ad0d5bb8c1be3f07964736f6c6343000814003303711c9d994faf6055172091cb841fd4831aa743e6f3315163b06a122c841846026bd110619d11cfdfc28e281df893bc24828e89177318e9dbd860cdaedeb6b353e43b954ba190a7e49386f1f78b01dcd9f628db23f432fa029a7dfd6d98e8fb03e615638e0b79444a70f8c695bf8f2a47033bf1cf95691ec3130f64939cee99

Deployed Bytecode

0x608060405260043610610370575f3560e01c80636ffed68b116101c8578063cb1cccce116100fd578063deec9c5a1161009d578063eeb728661161006d578063eeb72866146109ea578063f3fef3a314610a0b578063fa0f73ba14610a2a578063fad8b32a14610a49575f80fd5b8063deec9c5a1461097a578063e2bbb15814610999578063ed9ef16a146109ac578063ee0e6807146109cb575f80fd5b8063d08fb6cb116100d8578063d08fb6cb146108fe578063d12fc1821461091d578063d2b51eea1461093c578063d9fa70911461095b575f80fd5b8063cb1cccce146108a1578063cdd1f70d146108c0578063cf50fd1c146108df575f80fd5b8063a2bdde3d11610168578063af8bc15e11610143578063af8bc15e1461083c578063b5cd0c3c14610850578063be58b18e1461086f578063c1f5eb3a14610882575f80fd5b8063a2bdde3d146107eb578063a6d1d6c61461080a578063ad8b92b414610829575f80fd5b80637fc2ab3e116101a35780637fc2ab3e1461076f5780638101b64c1461078e5780638e5224ff146107ad5780639463629a146107cc575f80fd5b80636ffed68b14610712578063757bd9ab146107315780637d22dbc714610750575f80fd5b806336568abe116102a95780635a5d1bb91161024957806369328dec1161021957806369328dec146106965780636c04d9d5146106b55780636d70f7ae146106d45780636fc97cbf146106f3575f80fd5b80635a5d1bb9146106265780635a72af89146106455780636083e59a1461066457806362a1437614610677575f80fd5b8063439fab9111610284578063439fab91146105b5578063496ae54c146105d45780634baf43da146105f35780634d8b92a514610612575f80fd5b806336568abe146105585780633682a450146105775780633ea053eb14610596575f80fd5b806319534075116103145780632e1a7d4d116102ef5780632e1a7d4d146104b85780632f951985146104d757806330ccebb5146104f657806333eeb14714610546575f80fd5b8063195340751461045857806323205c521461047a578063284b920e14610499575f80fd5b80630e770f231161034f5780630e770f23146103e85780630efe6a8b1461040757806314af98b31461041a5780631789638314610439575f80fd5b8062f714ce146103745780630b3a2d21146103955780630c6f8664146103b4575b5f80fd5b34801561037f575f80fd5b5061039361038e366004613d07565b610a68565b005b3480156103a0575f80fd5b506103936103af366004613d35565b610a7e565b3480156103bf575f80fd5b506103d36103ce366004613d35565b610a98565b60405190151581526020015b60405180910390f35b3480156103f3575f80fd5b50610393610402366004613d35565b610af7565b610393610415366004613d50565b610b0e565b348015610425575f80fd5b50610393610434366004613d35565b610bc6565b348015610444575f80fd5b50610393610453366004613d35565b610c6c565b348015610463575f80fd5b5061046c610c83565b6040519081526020016103df565b348015610485575f80fd5b50610393610494366004613d82565b610c94565b3480156104a4575f80fd5b506103936104b3366004613d35565b610d86565b3480156104c3575f80fd5b506103936104d2366004613dba565b610e8b565b3480156104e2575f80fd5b506103936104f1366004613d35565b610e9d565b348015610501575f80fd5b50610539610510366004613d35565b6001600160a01b03165f9081525f805160206147d4833981519152602052604090205460ff1690565b6040516103df9190613de5565b348015610551575f80fd5b505f6103d3565b348015610563575f80fd5b50610393610572366004613d07565b610edd565b348015610582575f80fd5b50610393610591366004613d35565b610f6e565b3480156105a1575f80fd5b506103936105b0366004613d35565b610f85565b3480156105c0575f80fd5b506103936105cf366004613e0b565b6110ae565b3480156105df575f80fd5b5061046c6105ee366004613d35565b61125a565b3480156105fe575f80fd5b5061046c61060d366004613d35565b61129e565b34801561061d575f80fd5b5061046c6112da565b348015610631575f80fd5b506103d3610640366004613d35565b6112e3565b348015610650575f80fd5b5061039361065f366004613d35565b6112fb565b34801561066f575f80fd5b505f1961046c565b348015610682575f80fd5b50610393610691366004613d35565b61139e565b3480156106a1575f80fd5b506103936106b0366004613e77565b6113b5565b3480156106c0575f80fd5b506103d36106cf366004613d35565b6114a0565b3480156106df575f80fd5b506103d36106ee366004613d35565b6114b8565b3480156106fe575f80fd5b5061039361070d366004613d35565b6114d0565b34801561071d575f80fd5b5061039361072c366004613eb6565b6114e7565b34801561073c575f80fd5b506103d361074b366004613d35565b611635565b34801561075b575f80fd5b5061039361076a366004613eb6565b61164d565b34801561077a575f80fd5b50610393610789366004613dba565b6117a3565b348015610799575f80fd5b506103936107a8366004613d35565b6118c8565b3480156107b8575f80fd5b506103d36107c7366004613d35565b611908565b3480156107d7575f80fd5b506103936107e6366004613d35565b611920565b3480156107f6575f80fd5b506103d3610805366004613d35565b611937565b348015610815575f80fd5b50610393610824366004613d82565b61194f565b610393610837366004613d35565b611a2c565b348015610847575f80fd5b5061046c611a62565b34801561085b575f80fd5b5061039361086a366004613f27565b611a6b565b61039361087d366004613f94565b611b9d565b34801561088d575f80fd5b5061039361089c366004613d35565b611caa565b3480156108ac575f80fd5b506103d36108bb366004613d35565b611da4565b3480156108cb575f80fd5b506103936108da366004613d35565b611dbc565b3480156108ea575f80fd5b506103936108f9366004613f27565b611dd3565b348015610909575f80fd5b506103d3610918366004613d35565b611eea565b348015610928575f80fd5b50610393610937366004613d35565b611f02565b348015610947575f80fd5b50610393610956366004613ff9565b612117565b348015610966575f80fd5b50610393610975366004613d35565b61221d565b348015610985575f80fd5b50610393610994366004613d35565b612234565b6103936109a7366004614023565b61224b565b3480156109b7575f80fd5b506103936109c6366004613d35565b6122f9565b3480156109d6575f80fd5b506103936109e5366004613d35565b612310565b3480156109f5575f80fd5b506109fe612350565b6040516103df9190614065565b348015610a16575f80fd5b50610393610a25366004613ff9565b612370565b348015610a35575f80fd5b50610393610a44366004613d35565b61237b565b348015610a54575f80fd5b50610393610a63366004613d35565b612392565b610a7a610a736123a9565b83836113b5565b5050565b610a955f8051602061483d833981519152826123cb565b50565b6001600160a01b0381165f9081525f805160206147d4833981519152602052604081205460ff166001816003811115610ad357610ad3613dd1565b1480610af057506002816003811115610aee57610aee613dd1565b145b9392505050565b610a955f805160206146fa833981519152826123cb565b82610b1881610a98565b610b5e5760405162461bcd60e51b81526020600482015260126024820152711513d2d15397d393d517d4d154959250d15160721b60448201526064015b60405180910390fd5b604080515f8082526020820190925290610b7886866123ec565b90505f610b96878787865f805160206147b4833981519152876124a3565b9050610bb4878787865f805160206147b48339815191528688612625565b610bbd87611f02565b50505050505050565b610bcf33611635565b610c115760405162461bcd60e51b815260206004820152601360248201527213d3931657d4d150d55492551657d051d15395606a1b6044820152606401610b55565b6001600160a01b0381165f8181525f805160206147d48339815191526020526040808220600401805460ff191660011790555133917fe2deca319add01142d26def2de47e64bf1fdc70e6f90c13a1862a48bdaaa7cfd91a350565b610a955f8051602061471a833981519152826123cb565b5f610c8f61060d6123a9565b905090565b610c9c612738565b6001600160a01b0316636170ff1b610cb261275a565b5f805160206147b4833981519152610ccb88888861277c565b856040518563ffffffff1660e01b8152600401610ceb94939291906140e4565b6020604051808303815f875af1158015610d07573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610d2b9190614113565b50610d378484336127a5565b604080518481526020810183905283916001600160a01b0387169133917f50485fb0face2cfd73784044ab4191986b4a6713f01854414e2331a6bb41837d91015b60405180910390a450505050565b610d9d5f805160206145ec833981519152336127b8565b610de15760405162461bcd60e51b8152602060048201526015602482015274474f5645524e414e43455f41444d494e5f4f4e4c5960581b6044820152606401610b55565b6001600160a01b0381165f8181527f45f38e273862f8834bd2fe7a449988f63de55a7a5b685dea46ccedeb69cf0e266020818152604092839020805460ff191660011790557f45f38e273862f8834bd2fe7a449988f63de55a7a5b685dea46ccedeb69cf0e2780546001600160a01b03191690559151928352917fcfb473e6c03f9a29ddaf990e736fa3de5188a0bd85d684f5b6e164ebfbfff5d291015b60405180910390a15050565b610a95610e966123a9565b82336113b5565b80336001600160a01b03821603610ec65760405162461bcd60e51b8152600401610b559061412a565b610a7a5f8051602061471a833981519152836127ee565b5f805160206145ec83398151915282148015610f1757507f0000000000000000000000000000000000000000000000000000000000000001155b15610f645760405162461bcd60e51b815260206004820181905260248201527f43414e4e4f545f52454e4f554e43455f474f5645524e414e43455f41444d494e6044820152606401610b55565b610a7a828261280a565b610a955f805160206147f4833981519152826123cb565b33610f8e612884565b6001600160a01b031614610fd35760405162461bcd60e51b815260206004820152600c60248201526b27a7262cafa6a0a720a3a2a960a11b6044820152606401610b55565b6001600160a01b0381165f9081525f805160206147d4833981519152602052604081205460ff16600381111561100b5761100b613dd1565b036110485760405162461bcd60e51b815260206004820152600d60248201526c2aa725a727aba72faa27a5a2a760991b6044820152606401610b55565b6001600160a01b0381165f8181525f805160206147d48339815191526020908152604091829020805460ff1916600317905590519182527f86d6e4556eae726303caf49a75add7d92ac713e46db458dab0622aa263fb48e691015b60405180910390a150565b307f00000000000000000000000095ff25a59dc9c5a41cf0709dc916041e5dc7fd956001600160a01b03160361111f5760405162461bcd60e51b81526020600482015260166024820152751112549150d517d0d0531317d11254d0531313d5d15160521b6044820152606401610b55565b5f61112b81602061416e565b90505f611139826020614185565b9050808310156111815760405162461bcd60e51b81526020600482015260136024820152721253925517d110551057d513d3d7d4d3505313606a1b6044820152606401610b55565b5f61118e82848688614198565b81019061119b9190613d35565b9050365f6111ab8582888a614198565b91509150365f6111bd8887818c614198565b90925090506001600160a01b038516156111e7576111dc8583836128a6565b505050505050505050565b6111ef6129e4565b1561123e5780156112395760405162461bcd60e51b8152602060048201526014602482015273554e45585045435445445f494e49545f4441544160601b6044820152606401610b55565b6111dc565b61124882826129fe565b6112528282612b15565b6111dc612b43565b6001600160a01b0381165f9081525f805160206147d4833981519152602052604081206004015460ff1661128f575f19611298565b61129882612b4e565b92915050565b6001600160a01b0381165f9081525f805160206147d4833981519152602052604081206003015480156112d15780610af0565b5f199392505050565b5f610c8f612b6e565b5f6112985f80516020614653833981519152836127b8565b61130433611eea565b6113465760405162461bcd60e51b815260206004820152601360248201527227a7262cafa9a2a1aaa924aa2cafa0a226a4a760691b6044820152606401610b55565b6001600160a01b0381165f8181525f805160206147d48339815191526020526040808220600401805460ff191690555133917f109dee66091b7a145f557f52c55d7beccb6a29011fc705557e2975749474076b91a350565b610a955f8051602061460c833981519152826123cb565b6001600160a01b0381166113ff5760405162461bcd60e51b81526020600482015260116024820152701253959053125117d49150d25412515395607a1b6044820152606401610b55565b61140a838383612b81565b6001600160a01b0383165f9081525f805160206147d4833981519152602052604090206004015460ff1615611443576114438383612e91565b61144e8383836127a5565b826001600160a01b0316816001600160a01b03167f2717ead6b9200dd235aad468c9809ea400fe33ac69b5bfaa6d3e90fc922b63988460405161149391815260200190565b60405180910390a3505050565b5f6112985f80516020614673833981519152836127b8565b5f6112985f805160206147f4833981519152836127b8565b610a955f80516020614673833981519152826123cb565b80336114f1612f00565b5f83815260209190915260409020546001600160a01b0316146115475760405162461bcd60e51b815260206004820152600e60248201526d27a7262cafa222a827a9a4aa27a960911b6044820152606401610b55565b61154f612738565b6001600160a01b0316637a98660b61156561275a565b7f02d757788a8d8d6f21d1cd40bce38a8222d70654214e96ff95d8086e684fbee56115908888612f22565b866040518563ffffffff1660e01b81526004016115b094939291906140e4565b6020604051808303815f875af11580156115cc573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906115f09190614113565b506040805185815260208101849052849133917fea57f52faafe318751f75acb6756cff3f66afc10201ef8f2d504e788985db3f591015b60405180910390a350505050565b5f6112985f805160206146fa833981519152836127b8565b8033611657612f00565b5f83815260209190915260409020546001600160a01b0316146116ad5760405162461bcd60e51b815260206004820152600e60248201526d27a7262cafa222a827a9a4aa27a960911b6044820152606401610b55565b6116b5612738565b6001600160a01b0316636170ff1b6116cb61275a565b7f02d757788a8d8d6f21d1cd40bce38a8222d70654214e96ff95d8086e684fbee56116f68888612f22565b866040518563ffffffff1660e01b815260040161171694939291906140e4565b6020604051808303815f875af1158015611732573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906117569190614113565b506117696117626123a9565b85336127a5565b6040805185815260208101849052849133917fb0b548d5e12b6a60adac4d6dd7610f55134cea4fd145535edc303a48063e0cb49101611627565b6117ac336112e3565b6117ec5760405162461bcd60e51b815260206004820152601160248201527027a7262cafa0a8282fa3a7ab22a92727a960791b6044820152606401610b55565b6117f46129e4565b6118405760405162461bcd60e51b815260206004820152601860248201527f434f4e54524143545f4e4f545f494e495449414c495a454400000000000000006044820152606401610b55565b61184981612fc8565b61188f5760405162461bcd60e51b81526020600482015260176024820152764c325f414444524553535f4f55545f4f465f52414e474560481b6044820152606401610b55565b61189881612fea565b6040518181527f90fc3f39f8e4669d1bf5f9038707949f8af42a973f62988143be0fa7c3997f18906020016110a3565b80336001600160a01b038216036118f15760405162461bcd60e51b8152600401610b559061412a565b610a7a5f8051602061460c833981519152836127ee565b5f6112985f8051602061471a833981519152836127b8565b610a955f805160206145ec833981519152826123cb565b5f6112985f8051602061483d833981519152836127b8565b611957612738565b6001600160a01b0316637a98660b61196d61275a565b5f805160206147b483398151915261198688888861277c565b856040518563ffffffff1660e01b81526004016119a694939291906140e4565b6020604051808303815f875af11580156119c2573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906119e69190614113565b50604080518481526020810183905283916001600160a01b0387169133917f8f3da3ce93acd45e015b069c8f032d37be93dc9efcaaeda368aa9ca74f64c30a9101610d78565b60405162461bcd60e51b815260206004820152600b60248201526a155394d5541413d495115160aa1b6044820152606401610b55565b5f610c8f61300c565b611a73612738565b6001600160a01b0316636170ff1b611a8961275a565b5f805160206146da833981519152611ad78a8a8a60018b8b808060200260200160405190810160405280939291908181526020018383602002808284375f9201919091525061301e92505050565b856040518563ffffffff1660e01b8152600401611af794939291906140e4565b6020604051808303815f875af1158015611b13573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611b379190614113565b50611b438686336127a5565b83866001600160a01b0316336001600160a01b03167fa465a02eedf06ceffd1d99159ad98c5d8fa7f17b870eb22e0bfcec06398a8f7388878787604051611b8d94939291906141bf565b60405180910390a4505050505050565b84611ba781610a98565b611be85760405162461bcd60e51b81526020600482015260126024820152711513d2d15397d393d517d4d154959250d15160721b6044820152606401610b55565b5f611bf387876123ec565b90505f611c458888888888808060200260200160405190810160405280939291908181526020018383602002808284375f920191909152505f805160206146da83398151915292508991506124a39050565b9050611c978888888888808060200260200160405190810160405280939291908181526020018383602002808284375f920191909152505f805160206146da8339815191529250889150899050612625565b611ca088611f02565b5050505050505050565b611cc15f805160206145ec833981519152336127b8565b611d055760405162461bcd60e51b8152602060048201526015602482015274474f5645524e414e43455f41444d494e5f4f4e4c5960581b6044820152606401610b55565b6001600160a01b0381165f8181527f45f38e273862f8834bd2fe7a449988f63de55a7a5b685dea46ccedeb69cf0e266020818152604092839020805460ff191690557f45f38e273862f8834bd2fe7a449988f63de55a7a5b685dea46ccedeb69cf0e2780546001600160a01b03191690559151928352917fd75f94825e770b8b512be8e74759e252ad00e102e38f50cce2f7c6f868a295999101610e7f565b5f6112985f805160206145ec833981519152836127b8565b610a955f80516020614653833981519152826123cb565b611ddb612738565b6001600160a01b0316637a98660b611df161275a565b5f805160206146da833981519152611e3f8a8a8a60018b8b808060200260200160405190810160405280939291908181526020018383602002808284375f9201919091525061301e92505050565b856040518563ffffffff1660e01b8152600401611e5f94939291906140e4565b6020604051808303815f875af1158015611e7b573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611e9f9190614113565b5083866001600160a01b0316336001600160a01b03167f889e470f207032611b2f68dbd2124e3139794f19a6b536c83892fd505760386088878787604051611b8d94939291906141bf565b5f6112985f8051602061460c833981519152836127b8565b6001600160a01b0381165f9081525f805160206147d48339815191526020526040902054819060019060ff166003811115611f3f57611f3f613dd1565b14611f48575050565b6001600160a01b0382165f9081525f805160206147d4833981519152602052604090206001810154611f78612738565b6001600160a01b03166377c7d7a9826040518263ffffffff1660e01b8152600401611fa591815260200190565b602060405180830381865afa158015611fc0573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611fe49190614113565b5f03611ffa57815460ff19166002178255612111565b8160020154421115612111576001600160a01b0384165f9081525f805160206147d483398151915260205260408120805460ff19908116825560018201839055600282018390556003820183905560049091018054909116905561205c612884565b6001600160a01b0316635ab1bd536040518163ffffffff1660e01b8152600401602060405180830381865afa158015612097573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906120bb9190614203565b604051630caca05160e31b81526001600160a01b038781166004830152919250908216906365650288906024015f604051808303815f87803b1580156120ff575f80fd5b505af11580156111dc573d5f803e3d5ffd5b50505050565b612120336112e3565b6121605760405162461bcd60e51b815260206004820152601160248201527027a7262cafa0a8282fa3a7ab22a92727a960791b6044820152606401610b55565b805f036121af5760405162461bcd60e51b815260206004820152601960248201527f494e56414c49445f4d41585f544f54414c5f42414c414e4345000000000000006044820152606401610b55565b816001600160a01b03167fb895637c7d86c9b7b5b747e72195206a3fc21d8df0e019edd2312454ffa733b1826040516121ea91815260200190565b60405180910390a26001600160a01b03919091165f9081525f805160206147d48339815191526020526040902060030155565b610a955f805160206146fa833981519152826127ee565b610a955f80516020614653833981519152826127ee565b604080515f80825260208201909252906122636123a9565b90505f61227082866123ec565b90505f61228e838787875f805160206147b4833981519152876124a3565b90506122ac838787875f805160206147b48339815191528688612625565b6040805187815260208101839052908101839052859033907f5b5dbc6c64043a15d3fe6943a6e443a826b78755edc257b2ec890c022225dbcf9060600160405180910390a3505050505050565b610a955f80516020614673833981519152826127ee565b80336001600160a01b038216036123395760405162461bcd60e51b8152600401610b559061412a565b610a7a5f805160206145ec833981519152836127ee565b606060405180606001604052806021815260200161485d60219139905090565b610a7a8282336113b5565b610a955f8051602061483d833981519152826127ee565b610a955f805160206147f4833981519152826127ee565b5f610c8f60405180606001604052806029815260200161481460299139613269565b6123d48261329c565b6123dd816132bc565b6123e783836132c6565b505050565b5f813410156124325760405162461bcd60e51b8152602060048201526012602482015271494e53554646494349454e545f56414c554560701b6044820152606401610b55565b5f61243d833461421e565b90506124488161333a565b6124546245544861129e565b61245e824761421e565b1115610af05760405162461bcd60e51b815260206004820152601460248201527313505617d09053105390d157d15610d15151115160621b6044820152606401610b55565b5f6124ac61275a565b5f036124ee5760405162461bcd60e51b8152602060048201526011602482015270130c97d094925111d157d393d517d4d155607a1b6044820152606401610b55565b5f861161252c5760405162461bcd60e51b815260206004820152600c60248201526b16915493d7d1115413d4d25560a21b6044820152606401610b55565b61253585612fc8565b61257b5760405162461bcd60e51b81526020600482015260176024820152764c325f414444524553535f4f55545f4f465f52414e474560481b6044820152606401610b55565b5f805160206146da83398151915283145f612594612738565b6001600160a01b0316633e3aa6c5856125ab61275a565b886125b98e8e8e8a8f61301e565b6040518563ffffffff1660e01b81526004016125d793929190614231565b604080518083038185885af11580156125f2573d5f803e3d5ffd5b50505050506040513d601f19601f82011682018060405250810190612617919061424f565b9a9950505050505050505050565b5f805160206147b4833981519152830361268e57604080518781526020810184905290810182905285906001600160a01b0389169033907f5f971bd00bf3ffbca8a6d72cdd4fd92cfd4f62636161921d1e5a64f0b64ccb6d9060600160405180910390a4610bbd565b5f805160206146da83398151915283146126dd5760405162461bcd60e51b815260206004820152601060248201526f2aa725a727aba72fa9a2a622a1aa27a960811b6044820152606401610b55565b84876001600160a01b0316336001600160a01b03167f2203a49c69f1a46c1164f5e4a30643dd77b7c59c0ff9bc433256048365c247f1898887876040516127279493929190614271565b60405180910390a450505050505050565b5f610c8f6040518060600160405280602881526020016145c460289139613269565b5f610c8f6040518060600160405280602781526020016146b360279139613269565b604080515f808252602082019092526060915061279c8585855f8561301e565b95945050505050565b6123e76001600160a01b038216836133ef565b5f9182525f80516020614693833981519152602090815260408084206001600160a01b0393909316845291905290205460ff1690565b6127f78261329c565b612800816132bc565b6123e7838361348f565b6001600160a01b038116331461287a5760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b6064820152608401610b55565b610a7a828261348f565b5f610c8f60405180606001604052806026815260200161473a60269139613269565b6001600160a01b0383163b6128f25760405162461bcd60e51b8152602060048201526012602482015271115250d7d393d517d057d0d3d395149050d560721b6044820152606401610b55565b5f80846001600160a01b031663439fab9160e01b858560405160240161291992919061429c565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b031990941693909317909252905161295791906142ca565b5f60405180830381855af49150503d805f811461298f576040519150601f19603f3d011682016040523d82523d5f602084013e612994565b606091505b50915091508181906129b95760405162461bcd60e51b8152600401610b559190614065565b5080518190156129dc5760405162461bcd60e51b8152600401610b559190614065565b505050505050565b5f806129ee612738565b6001600160a01b03161415905090565b60408114612a425760405162461bcd60e51b8152602060048201526011602482015270494c4c4547414c5f444154415f53495a4560781b6044820152606401610b55565b5f80612a50838501856142e5565b91509150612a67816001600160a01b03163b151590565b612abe5760405162461bcd60e51b815260206004820152602260248201527f494e56414c49445f4d4553534147494e475f434f4e54524143545f4144445245604482015261535360f01b6064820152608401610b55565b6001600160a01b0382163b6121115760405162461bcd60e51b815260206004820181905260248201527f494e56414c49445f4d414e414745525f434f4e54524143545f414444524553536044820152606401610b55565b5f80612b23838501856142e5565b91509150612b3081613501565b612b3982613523565b6121116005613545565b33610a958180613567565b5f612b5882613669565b612b655761129882613694565b61129882613743565b5f610c8f64012a05f200620186a061416e565b612b8961275a565b5f03612bcb5760405162461bcd60e51b8152602060048201526011602482015270130c97d094925111d157d393d517d4d155607a1b6044820152606401610b55565b6001600160a01b0381165f6001612be4608060026143f1565b612bee919061421e565b60408051600580825260c082019092529186169250608086901c915f916020820160a0803683370190505090505f815f81518110612c2e57612c2e6143fc565b6020026020010181815250508381600181518110612c4e57612c4e6143fc565b602002602001018181525050866001600160a01b031681600281518110612c7757612c776143fc565b6020026020010181815250508281600381518110612c9757612c976143fc565b6020026020010181815250508181600481518110612cb757612cb76143fc565b602002602001018181525050612ccb612738565b6001600160a01b0316632c9dd5c0612ce161275a565b836040518363ffffffff1660e01b8152600401612cff929190614410565b6020604051808303815f875af1925050508015612d39575060408051601f3d908101601f19168201909252612d3691810190614113565b60015b611ca057612d45614428565b806308c379a003612e875750612d5961447a565b80612d645750612e89565b60408051600480825260a0820190925290602082016080803683370190505091505f825f81518110612d9857612d986143fc565b6020026020010181815250508482600181518110612db857612db86143fc565b6020026020010181815250508382600281518110612dd857612dd86143fc565b6020026020010181815250508282600381518110612df857612df86143fc565b602002602001018181525050612e0c612738565b6001600160a01b0316632c9dd5c0612e2261275a565b846040518363ffffffff1660e01b8152600401612e40929190614410565b6020604051808303815f875af1158015612e5c573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612e809190614113565b5050610bbd565b505b3d5f803e3d5ffd5b5f612e9b83612b4e565b905081811015612eed5760405162461bcd60e51b815260206004820152601d60248201527f455843454544535f474c4f42414c5f57495448445241575f4c494d49540000006044820152606401610b55565b6123e783612efb848461421e565b613770565b5f610c8f60405180606001604052806029815260200161478b602991396137a1565b604080516003808252608082019092526060915f919060208201848036833701905050905082815f81518110612f5a57612f5a6143fc565b60209081029190910101526001612f73608060026143f1565b612f7d919061421e565b841681600181518110612f9257612f926143fc565b602002602001018181525050608084901c81600281518110612fb657612fb66143fc565b60209081029190910101529392505050565b5f8115801590611298575061129882600167080000000000001160c01b011190565b610a956040518060600160405280602781526020016146b360279139826137d3565b5f610c8f64012a05f200614e2061416e565b60605f8361302d576005613039565b61303960016005614185565b90505f8351826130499190614185565b67ffffffffffffffff81111561306157613061614097565b60405190808252806020026020018201604052801561308a578160200160208202803683370190505b509050876001600160a01b0316815f815181106130a9576130a96143fc565b602002602001018181525050336001600160a01b0316816001815181106130d2576130d26143fc565b60200260200101818152505085816002815181106130f2576130f26143fc565b6020908102919091010152600161310b608060026143f1565b613115919061421e565b87168160038151811061312a5761312a6143fc565b602002602001018181525050608087901c8160048151811061314e5761314e6143fc565b602002602001018181525050841561325e5783518161316e60018561421e565b8151811061317e5761317e6143fc565b6020026020010181815250505f5b845181101561325c576131c58582815181106131aa576131aa6143fc565b6020026020010151600167080000000000001160c01b011190565b6132085760405162461bcd60e51b8152602060048201526014602482015273494e56414c49445f4d4553534147455f4441544160601b6044820152606401610b55565b84818151811061321a5761321a6143fc565b602002602001015182848361322f9190614185565b8151811061323f5761323f6143fc565b60209081029190910101528061325481614503565b91505061318c565b505b979650505050505050565b5f808260405160200161327c91906142ca565b60408051601f198184030181529190528051602090910120549392505050565b5f9081525f80516020614693833981519152602052604090206001015490565b610a958133613821565b6132d082826127b8565b610a7a575f8281525f80516020614693833981519152602090815260408083206001600160a01b0385168085529252808320805460ff1916600117905551339285917f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d9190a45050565b7f000000000000000000000000000000000000000000000000000000e8d4a510008110156133a35760405162461bcd60e51b8152602060048201526016602482015275494e53554646494349454e545f4645455f56414c554560501b6044820152606401610b55565b662386f26fc10000811115610a955760405162461bcd60e51b815260206004820152601260248201527108c8a8abeac8298aa8abea89e9ebe90928e960731b6044820152606401610b55565b805f036133fa575050565b5f826001600160a01b0316826040515f6040518083038185875af1925050503d805f8114613443576040519150601f19603f3d011682016040523d82523d5f602084013e613448565b606091505b50509050806123e75760405162461bcd60e51b815260206004820152601360248201527211551217d514905394d1915497d19052531151606a1b6044820152606401610b55565b61349982826127b8565b15610a7a575f8281525f80516020614693833981519152602090815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b610a956040518060600160405280602881526020016145c46028913982613885565b610a9560405180606001604052806026815260200161473a6026913982613885565b610a956040518060600160405280602b8152602001614760602b9139826138d3565b61356f613905565b156135dc5761358b5f805160206145ec833981519152836127b8565b6135d75760405162461bcd60e51b815260206004820152601960248201527f524f4c45535f414c52454144595f494e495449414c495a4544000000000000006044820152606401610b55565b6135e5565b6135e582613924565b6135ed613a06565b15613660576136095f8051602061460c833981519152826127b8565b610a7a5760405162461bcd60e51b815260206004820152602260248201527f53454355524954595f524f4c45535f414c52454144595f494e495449414c495a604482015261115160f21b6064820152608401610b55565b610a7a81613a1e565b5f613672613a70565b5f61367c84613a92565b81526020019081526020015f20545f14159050919050565b5f8062455447196001600160a01b038416016136b157504761371a565b6040516370a0823160e01b81523060048201526001600160a01b038416906370a0823190602401602060405180830381865afa1580156136f3573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906137179190614113565b90505b5f613723613ade565b90506064613731828461416e565b61373b919061451b565b949350505050565b5f600161374e613a70565b5f61375885613a92565b81526020019081526020015f2054611298919061421e565b61377b600182614185565b613783613a70565b5f61378d85613a92565b815260208101919091526040015f20555050565b5f80826040516020016137b491906142ca565b60408051601f1981840301815291905280516020909101209392505050565b6137dc82613269565b156138175760405162461bcd60e51b815260206004820152600b60248201526a1053149150511657d4d15560aa1b6044820152606401610b55565b610a7a82826138d3565b61382b82826127b8565b610a7a57613843816001600160a01b03166014613b00565b61384e836020613b00565b60405160200161385f92919061453a565b60408051601f198184030181529082905262461bcd60e51b8252610b5591600401614065565b5f61388f83613269565b6001600160a01b0316146138175760405162461bcd60e51b815260206004820152600b60248201526a1053149150511657d4d15560aa1b6044820152606401610b55565b5f826040516020016138e591906142ca565b604051602081830303815290604052805190602001209050818155505050565b5f8061391d5f805160206145ec83398151915261329c565b1415905090565b61393b5f805160206145ec833981519152826132c6565b61395f5f805160206146538339815191525f8051602061471a833981519152613c96565b6139835f8051602061471a8339815191525f805160206145ec833981519152613c96565b61399a5f805160206145ec83398151915280613c96565b6139be5f805160206147f48339815191525f8051602061471a833981519152613c96565b6139e25f8051602061483d8339815191525f8051602061471a833981519152613c96565b610a955f805160206146738339815191525f805160206145ec833981519152613c96565b5f8061391d5f8051602061460c83398151915261329c565b613a355f8051602061460c83398151915280613c96565b613a595f805160206146fa8339815191525f8051602061460c833981519152613c96565b610a955f8051602061460c833981519152826132c6565b5f610c8f60405180606001604052806027815260200161462c602791396137a1565b5f80613aa1620151804261451b565b604080516001600160a01b038616602082015290810182905290915060600160405160208183030381529060405280519060200120915050919050565b5f610c8f6040518060600160405280602b8152602001614760602b9139613269565b60605f613b0e83600261416e565b613b19906002614185565b67ffffffffffffffff811115613b3157613b31614097565b6040519080825280601f01601f191660200182016040528015613b5b576020820181803683370190505b509050600360fc1b815f81518110613b7557613b756143fc565b60200101906001600160f81b03191690815f1a905350600f60fb1b81600181518110613ba357613ba36143fc565b60200101906001600160f81b03191690815f1a9053505f613bc584600261416e565b613bd0906001614185565b90505b6001811115613c47576f181899199a1a9b1b9c1cb0b131b232b360811b85600f1660108110613c0457613c046143fc565b1a60f81b828281518110613c1a57613c1a6143fc565b60200101906001600160f81b03191690815f1a90535060049490941c93613c40816145ae565b9050613bd3565b508315610af05760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610b55565b5f613ca08361329c565b5f8481525f805160206146938339815191526020526040808220600101859055519192508391839186917fbd79b86ffe0ab8e8776151514217cd7cacd52c909f66475c3af44e129f0b00ff9190a4505050565b6001600160a01b0381168114610a95575f80fd5b5f8060408385031215613d18575f80fd5b823591506020830135613d2a81613cf3565b809150509250929050565b5f60208284031215613d45575f80fd5b8135610af081613cf3565b5f805f60608486031215613d62575f80fd5b8335613d6d81613cf3565b95602085013595506040909401359392505050565b5f805f8060808587031215613d95575f80fd5b8435613da081613cf3565b966020860135965060408601359560600135945092505050565b5f60208284031215613dca575f80fd5b5035919050565b634e487b7160e01b5f52602160045260245ffd5b6020810160048310613e0557634e487b7160e01b5f52602160045260245ffd5b91905290565b5f8060208385031215613e1c575f80fd5b823567ffffffffffffffff80821115613e33575f80fd5b818501915085601f830112613e46575f80fd5b813581811115613e54575f80fd5b866020828501011115613e65575f80fd5b60209290920196919550909350505050565b5f805f60608486031215613e89575f80fd5b8335613e9481613cf3565b9250602084013591506040840135613eab81613cf3565b809150509250925092565b5f805f60608486031215613ec8575f80fd5b505081359360208301359350604090920135919050565b5f8083601f840112613eef575f80fd5b50813567ffffffffffffffff811115613f06575f80fd5b6020830191508360208260051b8501011115613f20575f80fd5b9250929050565b5f805f805f8060a08789031215613f3c575f80fd5b8635613f4781613cf3565b95506020870135945060408701359350606087013567ffffffffffffffff811115613f70575f80fd5b613f7c89828a01613edf565b979a9699509497949695608090950135949350505050565b5f805f805f60808688031215613fa8575f80fd5b8535613fb381613cf3565b94506020860135935060408601359250606086013567ffffffffffffffff811115613fdc575f80fd5b613fe888828901613edf565b969995985093965092949392505050565b5f806040838503121561400a575f80fd5b823561401581613cf3565b946020939093013593505050565b5f8060408385031215614034575f80fd5b50508035926020909101359150565b5f5b8381101561405d578181015183820152602001614045565b50505f910152565b602081525f8251806020840152614083816040850160208701614043565b601f01601f19169190910160400192915050565b634e487b7160e01b5f52604160045260245ffd5b5f8151808452602080850194508084015f5b838110156140d9578151875295820195908201906001016140bd565b509495945050505050565b848152836020820152608060408201525f61410260808301856140ab565b905082606083015295945050505050565b5f60208284031215614123575f80fd5b5051919050565b60208082526016908201527521a0a72727aa2fa822a92327a926afa7a72fa9a2a62360511b604082015260600190565b634e487b7160e01b5f52601160045260245ffd5b80820281158282048414176112985761129861415a565b808201808211156112985761129861415a565b5f80858511156141a6575f80fd5b838611156141b2575f80fd5b5050820193919092039150565b84815260606020820181905281018390525f6001600160fb1b038411156141e4575f80fd5b8360051b80866080850137604083019390935250016080019392505050565b5f60208284031215614213575f80fd5b8151610af081613cf3565b818103818111156112985761129861415a565b838152826020820152606060408201525f61279c60608301846140ab565b5f8060408385031215614260575f80fd5b505080516020909101519092909150565b848152608060208201525f61428960808301866140ab565b6040830194909452506060015292915050565b60208152816020820152818360408301375f818301604090810191909152601f909201601f19160101919050565b5f82516142db818460208701614043565b9190910192915050565b5f80604083850312156142f6575f80fd5b823561430181613cf3565b91506020830135613d2a81613cf3565b600181815b8085111561434b57815f19048211156143315761433161415a565b8085161561433e57918102915b93841c9390800290614316565b509250929050565b5f8261436157506001611298565b8161436d57505f611298565b8160018114614383576002811461438d576143a9565b6001915050611298565b60ff84111561439e5761439e61415a565b50506001821b611298565b5060208310610133831016604e8410600b84101617156143cc575081810a611298565b6143d68383614311565b805f19048211156143e9576143e961415a565b029392505050565b5f610af08383614353565b634e487b7160e01b5f52603260045260245ffd5b828152604060208201525f61373b60408301846140ab565b5f60033d111561443e5760045f803e505f5160e01c5b90565b601f8201601f1916810167ffffffffffffffff8111828210171561447357634e487b7160e01b5f52604160045260245ffd5b6040525050565b5f60443d10156144875790565b6040516003193d81016004833e81513d67ffffffffffffffff81602484011181841117156144b757505050505090565b82850191508151818111156144cf5750505050505090565b843d87010160208285010111156144e95750505050505090565b6144f860208286010187614441565b509095945050505050565b5f600182016145145761451461415a565b5060010190565b5f8261453557634e487b7160e01b5f52601260045260245ffd5b500490565b7f416363657373436f6e74726f6c3a206163636f756e742000000000000000000081525f8351614571816017850160208801614043565b7001034b99036b4b9b9b4b733903937b6329607d1b60179184019182015283516145a2816028840160208801614043565b01602801949350505050565b5f816145bc576145bc61415a565b505f19019056fe535441524b4e45545f544f4b454e5f4252494447455f4d4553534147494e475f434f4e545241435403711c9d994faf6055172091cb841fd4831aa743e6f3315163b06a122c841846026bd110619d11cfdfc28e281df893bc24828e89177318e9dbd860cdaedeb6b357495448445241574c5f4c494d49545f494e5452414441595f51554f54415f534c4f545f54414700d2ead78c620e94b02d0a996e99298c59ddccfa1d8a0149080ac3a20de060680251e864ca2a080f55bce5da2452e8cfcafdbc951a3e7fff5023d558452ec22853e43b954ba190a7e49386f1f78b01dcd9f628db23f432fa029a7dfd6d98e8fb535441524b4e45545f544f4b454e5f4252494447455f4c325f544f4b454e5f434f4e5452414354008bce41827dd5484d80312a2e43bc42a896e3fcf75bf84c2b49339168dfa00a037693ba312785932d430dccf0f56ffedd0aa7c0f8b6da2cc4530c2717689b9603e615638e0b79444a70f8c695bf8f2a47033bf1cf95691ec3130f64939cee99535441524b4e45545f544f4b454e5f4252494447455f4d414e414745525f534c4f545f54414757495448445241574c5f4c494d49545f57495448445241575f4c494d49545f5043545f534c4f545f544147535441524b4e45545f544f4b454e5f4252494447455f4445504f5349544f525f41444452455353455301b64b1b3b690b43b9b514fb81377518f4039cd3e4f4914d8a6bdf01d679fb19c59c20aaa96597268f595db30ec21108a505370e3266ed3a6515637f16b8b689023edb77f7c8cc9e38e8afe78954f703aeeda7fffe014eeb6e56ea84e62f6da7535441524b4e45545f45524332305f544f4b454e5f4252494447455f544f4b454e5f414444524553530128d63adbf6b09002c26caf55c47e2f26635807e3ef1b027218aa74c8d61a3e537461726b576172655f537461726b6e65744574684272696467655f322e305f34a2646970667358221220aeb26be5ec3ed9f5d1316e4f3d68426df4beb9913f84a81ad0d5bb8c1be3f07964736f6c63430008140033

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

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.