S Price: $0.53134 (-10.99%)

Contract

0xFd47534C90adD3728dfE8Af8e318461C8038d626

Overview

S Balance

Sonic LogoSonic LogoSonic Logo0 S

S Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To

There are no matching entries

Please try again later

Parent Transaction Hash Block From To
View All Internal Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
CarbonController

Compiler Version
v0.8.19+commit.7dd6d404

Optimization Enabled:
Yes with 2000 runs

Other Settings:
paris EvmVersion, None license
File 1 of 39 : CarbonController.sol
// SPDX-License-Identifier: SEE LICENSE IN LICENSE
pragma solidity 0.8.19;
import { ReentrancyGuardUpgradeable } from "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";
import { IVersioned } from "../utility/interfaces/IVersioned.sol";
import { Pairs, Pair } from "./Pairs.sol";
import { Token } from "../token/Token.sol";
import { Strategies, Strategy, TradeAction, Order, TradeTokens } from "./Strategies.sol";
import { Upgradeable } from "../utility/Upgradeable.sol";
import { IVoucher } from "../voucher/interfaces/IVoucher.sol";
import { ICarbonController } from "./interfaces/ICarbonController.sol";
import { Utils, AccessDenied } from "../utility/Utils.sol";
import { OnlyProxyDelegate } from "../utility/OnlyProxyDelegate.sol";
import { MAX_GAP } from "../utility/Constants.sol";

/**
 * @dev Carbon Controller contract
 */
contract CarbonController is
    ICarbonController,
    Pairs,
    Strategies,
    Upgradeable,
    ReentrancyGuardUpgradeable,
    OnlyProxyDelegate,
    Utils
{
    // the fees manager role is required to withdraw fees
    bytes32 private constant ROLE_FEES_MANAGER = keccak256("ROLE_FEES_MANAGER");

    uint16 private constant CONTROLLER_TYPE = 1;

    // deprecated parent storage vars
    bool private _deprecated;
    uint256[49] private __deprecated;

    // the voucher contract
    IVoucher private immutable _voucher;

    // upgrade forward-compatibility storage gap
    uint256[MAX_GAP] private __gap;

    error IdenticalAddresses();
    error UnnecessaryNativeTokenReceived();
    error InsufficientNativeTokenReceived();
    error DeadlineExpired();

    /**
     * @dev used to set immutable state variables and initialize the implementation
     */
    constructor(IVoucher initVoucher, address proxy) OnlyProxyDelegate(proxy) {
        _validAddress(address(initVoucher));

        _voucher = initVoucher;
        initialize();
    }

    /**
     * @dev fully initializes the contract and its parents
     */
    function initialize() public initializer {
        __CarbonController_init();
    }

    // solhint-disable func-name-mixedcase

    /**
     * @dev initializes the contract and its parents
     */
    function __CarbonController_init() internal onlyInitializing {
        __Pairs_init();
        __Strategies_init();
        __Upgradeable_init();
        __ReentrancyGuard_init();

        __CarbonController_init_unchained();
    }

    /**
     * @dev performs contract-specific initialization
     */
    function __CarbonController_init_unchained() internal onlyInitializing {
        // set up administrative roles
        _setRoleAdmin(ROLE_FEES_MANAGER, ROLE_ADMIN);
    }

    // solhint-enable func-name-mixedcase

    /**
     * @inheritdoc Upgradeable
     */
    function version() public pure virtual override(IVersioned, Upgradeable) returns (uint16) {
        return 6;
    }

    /**
     * @dev returns the fees manager role
     */
    function roleFeesManager() external pure returns (bytes32) {
        return ROLE_FEES_MANAGER;
    }

    /**
     * @inheritdoc ICarbonController
     */
    function controllerType() external pure virtual returns (uint16) {
        return CONTROLLER_TYPE;
    }

    /**
     * @inheritdoc ICarbonController
     */
    function tradingFeePPM() external view returns (uint32) {
        return _tradingFeePPM;
    }

    /**
     * @inheritdoc ICarbonController
     */
    function pairTradingFeePPM(Token token0, Token token1) external view returns (uint32) {
        Pair memory _pair = _pair(token0, token1);
        return _getPairTradingFeePPM(_pair.id);
    }

    /**
     * @dev sets the trading fee (in units of PPM)
     *
     * requirements:
     *
     * - the caller must be the admin of the contract
     */
    function setTradingFeePPM(uint32 newTradingFeePPM) external onlyAdmin validFee(newTradingFeePPM) {
        _setTradingFeePPM(newTradingFeePPM);
    }

    /**
     * @dev sets the custom trading fee for a given pair (in units of PPM)
     *
     * requirements:
     *
     * - the caller must be the admin of the contract
     */
    function setPairTradingFeePPM(
        Token token0,
        Token token1,
        uint32 newPairTradingFeePPM
    ) external onlyAdmin validFee(newPairTradingFeePPM) {
        Pair memory _pair = _pair(token0, token1);
        _setPairTradingFeePPM(_pair, newPairTradingFeePPM);
    }

    /**
     * @inheritdoc ICarbonController
     */
    function createPair(Token token0, Token token1) external nonReentrant onlyProxyDelegate returns (Pair memory) {
        _validateInputTokens(token0, token1);
        return _createPair(token0, token1);
    }

    /**
     * @inheritdoc ICarbonController
     */
    function pairs() external view returns (Token[2][] memory) {
        return _pairs();
    }

    /**
     * @inheritdoc ICarbonController
     */
    function pair(Token token0, Token token1) external view returns (Pair memory) {
        _validateInputTokens(token0, token1);
        return _pair(token0, token1);
    }

    // solhint-disable var-name-mixedcase

    /**
     * @inheritdoc ICarbonController
     */
    function createStrategy(
        Token token0,
        Token token1,
        Order[2] calldata orders
    ) external payable nonReentrant onlyProxyDelegate returns (uint256) {
        _validateInputTokens(token0, token1);

        // don't allow unnecessary eth
        if (msg.value > 0 && !token0.isNative() && !token1.isNative()) {
            revert UnnecessaryNativeTokenReceived();
        }

        // revert if any of the orders is invalid
        _validateOrders(orders);

        // create the pair if it does not exist
        Pair memory strategyPair;
        if (!_pairExists(token0, token1)) {
            strategyPair = _createPair(token0, token1);
        } else {
            strategyPair = _pair(token0, token1);
        }

        Token[2] memory tokens = [token0, token1];
        return _createStrategy(_voucher, tokens, orders, strategyPair, msg.sender, msg.value);
    }

    /**
     * @inheritdoc ICarbonController
     */
    function updateStrategy(
        uint256 strategyId,
        Order[2] calldata currentOrders,
        Order[2] calldata newOrders
    ) external payable nonReentrant onlyProxyDelegate {
        Pair memory strategyPair = _pairById(_pairIdByStrategyId(strategyId));

        // only the owner of the strategy is allowed to delete it
        if (msg.sender != _voucher.ownerOf(strategyId)) {
            revert AccessDenied();
        }

        // don't allow unnecessary eth
        if (msg.value > 0 && !strategyPair.tokens[0].isNative() && !strategyPair.tokens[1].isNative()) {
            revert UnnecessaryNativeTokenReceived();
        }

        // revert if any of the orders is invalid
        _validateOrders(newOrders);

        // perform update
        _updateStrategy(strategyId, currentOrders, newOrders, strategyPair, msg.sender, msg.value);
    }

    // solhint-enable var-name-mixedcase

    /**
     * @inheritdoc ICarbonController
     */
    function deleteStrategy(uint256 strategyId) external nonReentrant onlyProxyDelegate {
        // find strategy, reverts if none
        Pair memory strategyPair = _pairById(_pairIdByStrategyId(strategyId));

        // only the owner of the strategy is allowed to delete it
        if (msg.sender != _voucher.ownerOf(strategyId)) {
            revert AccessDenied();
        }

        // delete strategy
        _deleteStrategy(strategyId, _voucher, strategyPair);
    }

    /**
     * @inheritdoc ICarbonController
     */
    function strategy(uint256 id) external view returns (Strategy memory) {
        Pair memory strategyPair = _pairById(_pairIdByStrategyId(id));
        return _strategy(id, _voucher, strategyPair);
    }

    /**
     * @inheritdoc ICarbonController
     */
    function strategiesByPair(
        Token token0,
        Token token1,
        uint256 startIndex,
        uint256 endIndex
    ) external view returns (Strategy[] memory) {
        _validateInputTokens(token0, token1);

        Pair memory strategyPair = _pair(token0, token1);
        return _strategiesByPair(strategyPair, startIndex, endIndex, _voucher);
    }

    /**
     * @inheritdoc ICarbonController
     */
    function strategiesByPairCount(Token token0, Token token1) external view returns (uint256) {
        _validateInputTokens(token0, token1);

        Pair memory strategyPair = _pair(token0, token1);
        return _strategiesByPairCount(strategyPair);
    }

    /**
     * @inheritdoc ICarbonController
     */
    function tradeBySourceAmount(
        Token sourceToken,
        Token targetToken,
        TradeAction[] calldata tradeActions,
        uint256 deadline,
        uint128 minReturn
    ) external payable nonReentrant onlyProxyDelegate returns (uint128) {
        _validateTradeParams(sourceToken, targetToken, deadline, msg.value, minReturn);
        Pair memory _pair = _pair(sourceToken, targetToken);
        TradeParams memory params = TradeParams({
            trader: msg.sender,
            tokens: TradeTokens({ source: sourceToken, target: targetToken }),
            byTargetAmount: false,
            constraint: minReturn,
            txValue: msg.value,
            pair: _pair,
            sourceAmount: 0,
            targetAmount: 0
        });
        _trade(tradeActions, params);
        return params.targetAmount;
    }

    /**
     * @inheritdoc ICarbonController
     */
    function tradeByTargetAmount(
        Token sourceToken,
        Token targetToken,
        TradeAction[] calldata tradeActions,
        uint256 deadline,
        uint128 maxInput
    ) external payable nonReentrant onlyProxyDelegate returns (uint128) {
        _validateTradeParams(sourceToken, targetToken, deadline, msg.value, maxInput);

        if (sourceToken.isNative()) {
            // tx's value should at least match the maxInput
            if (msg.value < maxInput) {
                revert InsufficientNativeTokenReceived();
            }
        }

        Pair memory _pair = _pair(sourceToken, targetToken);
        TradeParams memory params = TradeParams({
            trader: msg.sender,
            tokens: TradeTokens({ source: sourceToken, target: targetToken }),
            byTargetAmount: true,
            constraint: maxInput,
            txValue: msg.value,
            pair: _pair,
            sourceAmount: 0,
            targetAmount: 0
        });
        _trade(tradeActions, params);
        return params.sourceAmount;
    }

    /**
     * @inheritdoc ICarbonController
     */
    function calculateTradeSourceAmount(
        Token sourceToken,
        Token targetToken,
        TradeAction[] calldata tradeActions
    ) external view returns (uint128) {
        _validateInputTokens(sourceToken, targetToken);
        Pair memory strategyPair = _pair(sourceToken, targetToken);
        TradeTokens memory tokens = TradeTokens({ source: sourceToken, target: targetToken });
        SourceAndTargetAmounts memory amounts = _tradeSourceAndTargetAmounts(tokens, tradeActions, strategyPair, true);
        return amounts.sourceAmount;
    }

    /**
     * @inheritdoc ICarbonController
     */
    function calculateTradeTargetAmount(
        Token sourceToken,
        Token targetToken,
        TradeAction[] calldata tradeActions
    ) external view returns (uint128) {
        _validateInputTokens(sourceToken, targetToken);
        Pair memory strategyPair = _pair(sourceToken, targetToken);
        TradeTokens memory tokens = TradeTokens({ source: sourceToken, target: targetToken });
        SourceAndTargetAmounts memory amounts = _tradeSourceAndTargetAmounts(tokens, tradeActions, strategyPair, false);
        return amounts.targetAmount;
    }

    /**
     * @inheritdoc ICarbonController
     */
    function accumulatedFees(Token token) external view validAddress(Token.unwrap(token)) returns (uint256) {
        return _accumulatedFees[token];
    }

    /**
     * @inheritdoc ICarbonController
     */
    function withdrawFees(
        Token token,
        uint256 amount,
        address recipient
    )
        external
        onlyRoleMember(ROLE_FEES_MANAGER)
        validAddress(recipient)
        validAddress(Token.unwrap(token))
        greaterThanZero(amount)
        nonReentrant
        returns (uint256)
    {
        return _withdrawFees(msg.sender, amount, token, recipient);
    }

    /**
     * @dev validates both tokens are valid addresses and unique
     */
    function _validateInputTokens(
        Token token0,
        Token token1
    ) private pure validAddress(Token.unwrap(token0)) validAddress(Token.unwrap(token1)) {
        if (token0 == token1) {
            revert IdenticalAddresses();
        }
    }

    /**
     * performs all necessary validations on the trade parameters
     */
    function _validateTradeParams(
        Token sourceToken,
        Token targetToken,
        uint256 deadline,
        uint256 value,
        uint128 constraint
    ) private view {
        // revert if deadline has passed
        if (deadline < block.timestamp) {
            revert DeadlineExpired();
        }

        // validate minReturn / maxInput
        _greaterThanZero(constraint);

        // make sure source and target tokens are valid
        _validateInputTokens(sourceToken, targetToken);

        // there shouldn't be any native token sent unless the source token is the native token
        if (value > 0 && !sourceToken.isNative()) {
            revert UnnecessaryNativeTokenReceived();
        }
    }
}

File 2 of 39 : AccessControlEnumerableUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (access/AccessControlEnumerable.sol)

pragma solidity ^0.8.0;

import "./IAccessControlEnumerableUpgradeable.sol";
import "./AccessControlUpgradeable.sol";
import "../utils/structs/EnumerableSetUpgradeable.sol";
import "../proxy/utils/Initializable.sol";

/**
 * @dev Extension of {AccessControl} that allows enumerating the members of each role.
 */
abstract contract AccessControlEnumerableUpgradeable is Initializable, IAccessControlEnumerableUpgradeable, AccessControlUpgradeable {
    function __AccessControlEnumerable_init() internal onlyInitializing {
    }

    function __AccessControlEnumerable_init_unchained() internal onlyInitializing {
    }
    using EnumerableSetUpgradeable for EnumerableSetUpgradeable.AddressSet;

    mapping(bytes32 => EnumerableSetUpgradeable.AddressSet) private _roleMembers;

    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IAccessControlEnumerableUpgradeable).interfaceId || super.supportsInterface(interfaceId);
    }

    /**
     * @dev Returns one of the accounts that have `role`. `index` must be a
     * value between 0 and {getRoleMemberCount}, non-inclusive.
     *
     * Role bearers are not sorted in any particular way, and their ordering may
     * change at any point.
     *
     * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure
     * you perform all queries on the same block. See the following
     * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]
     * for more information.
     */
    function getRoleMember(bytes32 role, uint256 index) public view virtual override returns (address) {
        return _roleMembers[role].at(index);
    }

    /**
     * @dev Returns the number of accounts that have `role`. Can be used
     * together with {getRoleMember} to enumerate all bearers of a role.
     */
    function getRoleMemberCount(bytes32 role) public view virtual override returns (uint256) {
        return _roleMembers[role].length();
    }

    /**
     * @dev Overload {_grantRole} to track enumerable memberships
     */
    function _grantRole(bytes32 role, address account) internal virtual override {
        super._grantRole(role, account);
        _roleMembers[role].add(account);
    }

    /**
     * @dev Overload {_revokeRole} to track enumerable memberships
     */
    function _revokeRole(bytes32 role, address account) internal virtual override {
        super._revokeRole(role, account);
        _roleMembers[role].remove(account);
    }

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[49] private __gap;
}

File 3 of 39 : AccessControlUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/AccessControl.sol)

pragma solidity ^0.8.0;

import "./IAccessControlUpgradeable.sol";
import "../utils/ContextUpgradeable.sol";
import "../utils/StringsUpgradeable.sol";
import "../utils/introspection/ERC165Upgradeable.sol";
import "../proxy/utils/Initializable.sol";

/**
 * @dev Contract module that allows children 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:
 *
 * ```solidity
 * 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}:
 *
 * ```solidity
 * 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. We recommend using {AccessControlDefaultAdminRules}
 * to enforce additional security measures for this role.
 */
abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable, IAccessControlUpgradeable, ERC165Upgradeable {
    function __AccessControl_init() internal onlyInitializing {
    }

    function __AccessControl_init_unchained() internal onlyInitializing {
    }
    struct RoleData {
        mapping(address => bool) members;
        bytes32 adminRole;
    }

    mapping(bytes32 => RoleData) private _roles;

    bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;

    /**
     * @dev 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);
        _;
    }

    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IAccessControlUpgradeable).interfaceId || super.supportsInterface(interfaceId);
    }

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

    /**
     * @dev 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 virtual {
        _checkRole(role, _msgSender());
    }

    /**
     * @dev 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 virtual {
        if (!hasRole(role, account)) {
            revert(
                string(
                    abi.encodePacked(
                        "AccessControl: account ",
                        StringsUpgradeable.toHexString(account),
                        " is missing role ",
                        StringsUpgradeable.toHexString(uint256(role), 32)
                    )
                )
            );
        }
    }

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

    /**
     * @dev 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) public virtual override onlyRole(getRoleAdmin(role)) {
        _grantRole(role, account);
    }

    /**
     * @dev 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) public virtual override onlyRole(getRoleAdmin(role)) {
        _revokeRole(role, account);
    }

    /**
     * @dev 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) public virtual override {
        require(account == _msgSender(), "AccessControl: can only renounce roles for self");

        _revokeRole(role, account);
    }

    /**
     * @dev 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]
     * ====
     * 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 virtual {
        _grantRole(role, account);
    }

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

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

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

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[49] private __gap;
}

File 4 of 39 : IAccessControlEnumerableUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControlEnumerable.sol)

pragma solidity ^0.8.0;

import "./IAccessControlUpgradeable.sol";

/**
 * @dev External interface of AccessControlEnumerable declared to support ERC165 detection.
 */
interface IAccessControlEnumerableUpgradeable is IAccessControlUpgradeable {
    /**
     * @dev Returns one of the accounts that have `role`. `index` must be a
     * value between 0 and {getRoleMemberCount}, non-inclusive.
     *
     * Role bearers are not sorted in any particular way, and their ordering may
     * change at any point.
     *
     * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure
     * you perform all queries on the same block. See the following
     * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]
     * for more information.
     */
    function getRoleMember(bytes32 role, uint256 index) external view returns (address);

    /**
     * @dev Returns the number of accounts that have `role`. Can be used
     * together with {getRoleMember} to enumerate all bearers of a role.
     */
    function getRoleMemberCount(bytes32 role) external view returns (uint256);
}

File 5 of 39 : IAccessControlUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)

pragma solidity ^0.8.0;

/**
 * @dev External interface of AccessControl declared to support ERC165 detection.
 */
interface IAccessControlUpgradeable {
    /**
     * @dev 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);

    /**
     * @dev 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);

    /**
     * @dev 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);

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) external view returns (bool);

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {AccessControl-_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) external view returns (bytes32);

    /**
     * @dev 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.
     */
    function grantRole(bytes32 role, address account) external;

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

    /**
     * @dev 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 granted `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `account`.
     */
    function renounceRole(bytes32 role, address account) external;
}

File 6 of 39 : Initializable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol)

pragma solidity ^0.8.2;

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

/**
 * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
 * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
 * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
 * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
 *
 * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
 * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
 * case an upgrade adds a module that needs to be initialized.
 *
 * For example:
 *
 * [.hljs-theme-light.nopadding]
 * ```solidity
 * contract MyToken is ERC20Upgradeable {
 *     function initialize() initializer public {
 *         __ERC20_init("MyToken", "MTK");
 *     }
 * }
 *
 * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
 *     function initializeV2() reinitializer(2) public {
 *         __ERC20Permit_init("MyToken");
 *     }
 * }
 * ```
 *
 * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
 * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
 *
 * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
 * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
 *
 * [CAUTION]
 * ====
 * Avoid leaving a contract uninitialized.
 *
 * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
 * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
 * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * /// @custom:oz-upgrades-unsafe-allow constructor
 * constructor() {
 *     _disableInitializers();
 * }
 * ```
 * ====
 */
abstract contract Initializable {
    /**
     * @dev Indicates that the contract has been initialized.
     * @custom:oz-retyped-from bool
     */
    uint8 private _initialized;

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

    /**
     * @dev Triggered when the contract has been initialized or reinitialized.
     */
    event Initialized(uint8 version);

    /**
     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
     * `onlyInitializing` functions can be used to initialize parent contracts.
     *
     * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a
     * constructor.
     *
     * Emits an {Initialized} event.
     */
    modifier initializer() {
        bool isTopLevelCall = !_initializing;
        require(
            (isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),
            "Initializable: contract is already initialized"
        );
        _initialized = 1;
        if (isTopLevelCall) {
            _initializing = true;
        }
        _;
        if (isTopLevelCall) {
            _initializing = false;
            emit Initialized(1);
        }
    }

    /**
     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
     * used to initialize parent contracts.
     *
     * A reinitializer may be used after the original initialization step. This is essential to configure modules that
     * are added through upgrades and that require initialization.
     *
     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
     * cannot be nested. If one is invoked in the context of another, execution will revert.
     *
     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
     * a contract, executing them in the right order is up to the developer or operator.
     *
     * WARNING: setting the version to 255 will prevent any future reinitialization.
     *
     * Emits an {Initialized} event.
     */
    modifier reinitializer(uint8 version) {
        require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
        _initialized = version;
        _initializing = true;
        _;
        _initializing = false;
        emit Initialized(version);
    }

    /**
     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
     * {initializer} and {reinitializer} modifiers, directly or indirectly.
     */
    modifier onlyInitializing() {
        require(_initializing, "Initializable: contract is not initializing");
        _;
    }

    /**
     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called
     * through proxies.
     *
     * Emits an {Initialized} event the first time it is successfully executed.
     */
    function _disableInitializers() internal virtual {
        require(!_initializing, "Initializable: contract is initializing");
        if (_initialized != type(uint8).max) {
            _initialized = type(uint8).max;
            emit Initialized(type(uint8).max);
        }
    }

    /**
     * @dev Returns the highest version that has been initialized. See {reinitializer}.
     */
    function _getInitializedVersion() internal view returns (uint8) {
        return _initialized;
    }

    /**
     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
     */
    function _isInitializing() internal view returns (bool) {
        return _initializing;
    }
}

File 7 of 39 : ReentrancyGuardUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol)

pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol";

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuardUpgradeable is Initializable {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

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

    uint256 private _status;

    function __ReentrancyGuard_init() internal onlyInitializing {
        __ReentrancyGuard_init_unchained();
    }

    function __ReentrancyGuard_init_unchained() internal onlyInitializing {
        _status = _NOT_ENTERED;
    }

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

    function _nonReentrantBefore() private {
        // On the first call to nonReentrant, _status will be _NOT_ENTERED
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

        // Any calls to nonReentrant after this point will fail
        _status = _ENTERED;
    }

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

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

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[49] private __gap;
}

File 8 of 39 : IERC721Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC721/IERC721.sol)

pragma solidity ^0.8.0;

import "../../utils/introspection/IERC165Upgradeable.sol";

/**
 * @dev Required interface of an ERC721 compliant contract.
 */
interface IERC721Upgradeable is IERC165Upgradeable {
    /**
     * @dev Emitted when `tokenId` token is transferred from `from` to `to`.
     */
    event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
     */
    event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
     */
    event ApprovalForAll(address indexed owner, address indexed operator, bool approved);

    /**
     * @dev Returns the number of tokens in ``owner``'s account.
     */
    function balanceOf(address owner) external view returns (uint256 balance);

    /**
     * @dev Returns the owner of the `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function ownerOf(uint256 tokenId) external view returns (address owner);

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
     * are aware of the ERC721 protocol to prevent tokens from being forever locked.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must have been allowed to move this token by either {approve} or {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(address from, address to, uint256 tokenId) external;

    /**
     * @dev Transfers `tokenId` token from `from` to `to`.
     *
     * WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721
     * or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
     * understand this adds an external call which potentially creates a reentrancy vulnerability.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 tokenId) external;

    /**
     * @dev Gives permission to `to` to transfer `tokenId` token to another account.
     * The approval is cleared when the token is transferred.
     *
     * Only a single account can be approved at a time, so approving the zero address clears previous approvals.
     *
     * Requirements:
     *
     * - The caller must own the token or be an approved operator.
     * - `tokenId` must exist.
     *
     * Emits an {Approval} event.
     */
    function approve(address to, uint256 tokenId) external;

    /**
     * @dev Approve or remove `operator` as an operator for the caller.
     * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
     *
     * Requirements:
     *
     * - The `operator` cannot be the caller.
     *
     * Emits an {ApprovalForAll} event.
     */
    function setApprovalForAll(address operator, bool approved) external;

    /**
     * @dev Returns the account approved for `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function getApproved(uint256 tokenId) external view returns (address operator);

    /**
     * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
     *
     * See {setApprovalForAll}
     */
    function isApprovedForAll(address owner, address operator) external view returns (bool);
}

File 9 of 39 : AddressUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @dev Collection of functions related to the address type
 */
library AddressUpgradeable {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     *
     * Furthermore, `isContract` will also return true if the target contract within
     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
     * which only has an effect at the end of a transaction.
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 0;
    }

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

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

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

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

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

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

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

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

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

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
     *
     * _Available since v4.8._
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        if (success) {
            if (returndata.length == 0) {
                // only check isContract if the call was successful and the return data is empty
                // otherwise we already know that it was a contract
                require(isContract(target), "Address: call to non-contract");
            }
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason or using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    function _revert(bytes memory returndata, string memory errorMessage) private pure {
        // Look for revert reason and bubble it up if present
        if (returndata.length > 0) {
            // The easiest way to bubble the revert reason is using memory via assembly
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert(errorMessage);
        }
    }
}

File 10 of 39 : ContextUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol";

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

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

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

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[50] private __gap;
}

File 11 of 39 : StringsUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Strings.sol)

pragma solidity ^0.8.0;

import "./math/MathUpgradeable.sol";
import "./math/SignedMathUpgradeable.sol";

/**
 * @dev String operations.
 */
library StringsUpgradeable {
    bytes16 private constant _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) {
        unchecked {
            uint256 length = MathUpgradeable.log10(value) + 1;
            string memory buffer = new string(length);
            uint256 ptr;
            /// @solidity memory-safe-assembly
            assembly {
                ptr := add(buffer, add(32, length))
            }
            while (true) {
                ptr--;
                /// @solidity memory-safe-assembly
                assembly {
                    mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
                }
                value /= 10;
                if (value == 0) break;
            }
            return buffer;
        }
    }

    /**
     * @dev Converts a `int256` to its ASCII `string` decimal representation.
     */
    function toString(int256 value) internal pure returns (string memory) {
        return string(abi.encodePacked(value < 0 ? "-" : "", toString(SignedMathUpgradeable.abs(value))));
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        unchecked {
            return toHexString(value, MathUpgradeable.log256(value) + 1);
        }
    }

    /**
     * @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] = _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);
    }

    /**
     * @dev Returns true if the two strings are equal.
     */
    function equal(string memory a, string memory b) internal pure returns (bool) {
        return keccak256(bytes(a)) == keccak256(bytes(b));
    }
}

File 12 of 39 : ERC165Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)

pragma solidity ^0.8.0;

import "./IERC165Upgradeable.sol";
import "../../proxy/utils/Initializable.sol";

/**
 * @dev Implementation of the {IERC165} interface.
 *
 * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
 * for the additional interface id that will be supported. For example:
 *
 * ```solidity
 * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
 *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
 * }
 * ```
 *
 * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
 */
abstract contract ERC165Upgradeable is Initializable, IERC165Upgradeable {
    function __ERC165_init() internal onlyInitializing {
    }

    function __ERC165_init_unchained() internal onlyInitializing {
    }
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IERC165Upgradeable).interfaceId;
    }

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[50] private __gap;
}

File 13 of 39 : IERC165Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)

pragma solidity ^0.8.0;

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

File 14 of 39 : MathUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/Math.sol)

pragma solidity ^0.8.0;

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library MathUpgradeable {
    enum Rounding {
        Down, // Toward negative infinity
        Up, // Toward infinity
        Zero // Toward zero
    }

    /**
     * @dev Returns the largest of two numbers.
     */
    function max(uint256 a, uint256 b) internal pure returns (uint256) {
        return a > b ? a : b;
    }

    /**
     * @dev Returns the smallest of two numbers.
     */
    function min(uint256 a, uint256 b) internal pure returns (uint256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two numbers. The result is rounded towards
     * zero.
     */
    function average(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b) / 2 can overflow.
        return (a & b) + (a ^ b) / 2;
    }

    /**
     * @dev Returns the ceiling of the division of two numbers.
     *
     * This differs from standard division with `/` in that it rounds up instead
     * of rounding down.
     */
    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b - 1) / b can overflow on addition, so we distribute.
        return a == 0 ? 0 : (a - 1) / b + 1;
    }

    /**
     * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
     * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
     * with further edits by Uniswap Labs also under MIT license.
     */
    function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
        unchecked {
            // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
            // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
            // variables such that product = prod1 * 2^256 + prod0.
            uint256 prod0; // Least significant 256 bits of the product
            uint256 prod1; // Most significant 256 bits of the product
            assembly {
                let mm := mulmod(x, y, not(0))
                prod0 := mul(x, y)
                prod1 := sub(sub(mm, prod0), lt(mm, prod0))
            }

            // Handle non-overflow cases, 256 by 256 division.
            if (prod1 == 0) {
                // Solidity will revert if denominator == 0, unlike the div opcode on its own.
                // The surrounding unchecked block does not change this fact.
                // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
                return prod0 / denominator;
            }

            // Make sure the result is less than 2^256. Also prevents denominator == 0.
            require(denominator > prod1, "Math: mulDiv overflow");

            ///////////////////////////////////////////////
            // 512 by 256 division.
            ///////////////////////////////////////////////

            // Make division exact by subtracting the remainder from [prod1 prod0].
            uint256 remainder;
            assembly {
                // Compute remainder using mulmod.
                remainder := mulmod(x, y, denominator)

                // Subtract 256 bit number from 512 bit number.
                prod1 := sub(prod1, gt(remainder, prod0))
                prod0 := sub(prod0, remainder)
            }

            // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
            // See https://cs.stackexchange.com/q/138556/92363.

            // Does not overflow because the denominator cannot be zero at this stage in the function.
            uint256 twos = denominator & (~denominator + 1);
            assembly {
                // Divide denominator by twos.
                denominator := div(denominator, twos)

                // Divide [prod1 prod0] by twos.
                prod0 := div(prod0, twos)

                // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
                twos := add(div(sub(0, twos), twos), 1)
            }

            // Shift in bits from prod1 into prod0.
            prod0 |= prod1 * twos;

            // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
            // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
            // four bits. That is, denominator * inv = 1 mod 2^4.
            uint256 inverse = (3 * denominator) ^ 2;

            // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
            // in modular arithmetic, doubling the correct bits in each step.
            inverse *= 2 - denominator * inverse; // inverse mod 2^8
            inverse *= 2 - denominator * inverse; // inverse mod 2^16
            inverse *= 2 - denominator * inverse; // inverse mod 2^32
            inverse *= 2 - denominator * inverse; // inverse mod 2^64
            inverse *= 2 - denominator * inverse; // inverse mod 2^128
            inverse *= 2 - denominator * inverse; // inverse mod 2^256

            // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
            // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
            // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
            // is no longer required.
            result = prod0 * inverse;
            return result;
        }
    }

    /**
     * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
     */
    function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
        uint256 result = mulDiv(x, y, denominator);
        if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
            result += 1;
        }
        return result;
    }

    /**
     * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
     *
     * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
     */
    function sqrt(uint256 a) internal pure returns (uint256) {
        if (a == 0) {
            return 0;
        }

        // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
        //
        // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
        // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
        //
        // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
        // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
        // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
        //
        // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
        uint256 result = 1 << (log2(a) >> 1);

        // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
        // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
        // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
        // into the expected uint128 result.
        unchecked {
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            return min(result, a / result);
        }
    }

    /**
     * @notice Calculates sqrt(a), following the selected rounding direction.
     */
    function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = sqrt(a);
            return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 2, rounded down, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 128;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 64;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 32;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 16;
            }
            if (value >> 8 > 0) {
                value >>= 8;
                result += 8;
            }
            if (value >> 4 > 0) {
                value >>= 4;
                result += 4;
            }
            if (value >> 2 > 0) {
                value >>= 2;
                result += 2;
            }
            if (value >> 1 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 2, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log2(value);
            return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 10, rounded down, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >= 10 ** 64) {
                value /= 10 ** 64;
                result += 64;
            }
            if (value >= 10 ** 32) {
                value /= 10 ** 32;
                result += 32;
            }
            if (value >= 10 ** 16) {
                value /= 10 ** 16;
                result += 16;
            }
            if (value >= 10 ** 8) {
                value /= 10 ** 8;
                result += 8;
            }
            if (value >= 10 ** 4) {
                value /= 10 ** 4;
                result += 4;
            }
            if (value >= 10 ** 2) {
                value /= 10 ** 2;
                result += 2;
            }
            if (value >= 10 ** 1) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log10(value);
            return result + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 256, rounded down, of a positive value.
     * Returns 0 if given 0.
     *
     * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
     */
    function log256(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 16;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 8;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 4;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 2;
            }
            if (value >> 8 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 256, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log256(value);
            return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0);
        }
    }
}

File 15 of 39 : SignedMathUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SignedMath.sol)

pragma solidity ^0.8.0;

/**
 * @dev Standard signed math utilities missing in the Solidity language.
 */
library SignedMathUpgradeable {
    /**
     * @dev Returns the largest of two signed numbers.
     */
    function max(int256 a, int256 b) internal pure returns (int256) {
        return a > b ? a : b;
    }

    /**
     * @dev Returns the smallest of two signed numbers.
     */
    function min(int256 a, int256 b) internal pure returns (int256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two signed numbers without overflow.
     * The result is rounded towards zero.
     */
    function average(int256 a, int256 b) internal pure returns (int256) {
        // Formula from the book "Hacker's Delight"
        int256 x = (a & b) + ((a ^ b) >> 1);
        return x + (int256(uint256(x) >> 255) & (a ^ b));
    }

    /**
     * @dev Returns the absolute unsigned value of a signed value.
     */
    function abs(int256 n) internal pure returns (uint256) {
        unchecked {
            // must be unchecked in order to support `n = type(int256).min`
            return uint256(n >= 0 ? n : -n);
        }
    }
}

File 16 of 39 : EnumerableSetUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/structs/EnumerableSet.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.

pragma solidity ^0.8.0;

/**
 * @dev Library for managing
 * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
 * types.
 *
 * Sets have the following properties:
 *
 * - Elements are added, removed, and checked for existence in constant time
 * (O(1)).
 * - Elements are enumerated in O(n). No guarantees are made on the ordering.
 *
 * ```solidity
 * contract Example {
 *     // Add the library methods
 *     using EnumerableSet for EnumerableSet.AddressSet;
 *
 *     // Declare a set state variable
 *     EnumerableSet.AddressSet private mySet;
 * }
 * ```
 *
 * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
 * and `uint256` (`UintSet`) are supported.
 *
 * [WARNING]
 * ====
 * Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
 * unusable.
 * See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
 *
 * In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an
 * array of EnumerableSet.
 * ====
 */
library EnumerableSetUpgradeable {
    // To implement this library for multiple types with as little code
    // repetition as possible, we write it in terms of a generic Set type with
    // bytes32 values.
    // The Set implementation uses private functions, and user-facing
    // implementations (such as AddressSet) are just wrappers around the
    // underlying Set.
    // This means that we can only create new EnumerableSets for types that fit
    // in bytes32.

    struct Set {
        // Storage of set values
        bytes32[] _values;
        // Position of the value in the `values` array, plus 1 because index 0
        // means a value is not in the set.
        mapping(bytes32 => uint256) _indexes;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function _add(Set storage set, bytes32 value) private returns (bool) {
        if (!_contains(set, value)) {
            set._values.push(value);
            // The value is stored at length-1, but we add 1 to all indexes
            // and use 0 as a sentinel value
            set._indexes[value] = set._values.length;
            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function _remove(Set storage set, bytes32 value) private returns (bool) {
        // We read and store the value's index to prevent multiple reads from the same storage slot
        uint256 valueIndex = set._indexes[value];

        if (valueIndex != 0) {
            // Equivalent to contains(set, value)
            // To delete an element from the _values array in O(1), we swap the element to delete with the last one in
            // the array, and then remove the last element (sometimes called as 'swap and pop').
            // This modifies the order of the array, as noted in {at}.

            uint256 toDeleteIndex = valueIndex - 1;
            uint256 lastIndex = set._values.length - 1;

            if (lastIndex != toDeleteIndex) {
                bytes32 lastValue = set._values[lastIndex];

                // Move the last value to the index where the value to delete is
                set._values[toDeleteIndex] = lastValue;
                // Update the index for the moved value
                set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex
            }

            // Delete the slot where the moved value was stored
            set._values.pop();

            // Delete the index for the deleted slot
            delete set._indexes[value];

            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function _contains(Set storage set, bytes32 value) private view returns (bool) {
        return set._indexes[value] != 0;
    }

    /**
     * @dev Returns the number of values on the set. O(1).
     */
    function _length(Set storage set) private view returns (uint256) {
        return set._values.length;
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function _at(Set storage set, uint256 index) private view returns (bytes32) {
        return set._values[index];
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function _values(Set storage set) private view returns (bytes32[] memory) {
        return set._values;
    }

    // Bytes32Set

    struct Bytes32Set {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _add(set._inner, value);
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _remove(set._inner, value);
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
        return _contains(set._inner, value);
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(Bytes32Set storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
        return _at(set._inner, index);
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
        bytes32[] memory store = _values(set._inner);
        bytes32[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }

    // AddressSet

    struct AddressSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(AddressSet storage set, address value) internal returns (bool) {
        return _add(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(AddressSet storage set, address value) internal returns (bool) {
        return _remove(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(AddressSet storage set, address value) internal view returns (bool) {
        return _contains(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(AddressSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(AddressSet storage set, uint256 index) internal view returns (address) {
        return address(uint160(uint256(_at(set._inner, index))));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(AddressSet storage set) internal view returns (address[] memory) {
        bytes32[] memory store = _values(set._inner);
        address[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }

    // UintSet

    struct UintSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(UintSet storage set, uint256 value) internal returns (bool) {
        return _add(set._inner, bytes32(value));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(UintSet storage set, uint256 value) internal returns (bool) {
        return _remove(set._inner, bytes32(value));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(UintSet storage set, uint256 value) internal view returns (bool) {
        return _contains(set._inner, bytes32(value));
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(UintSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(UintSet storage set, uint256 index) internal view returns (uint256) {
        return uint256(_at(set._inner, index));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(UintSet storage set) internal view returns (uint256[] memory) {
        bytes32[] memory store = _values(set._inner);
        uint256[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }
}

File 17 of 39 : ERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/ERC20.sol)

pragma solidity ^0.8.0;

import "./IERC20.sol";
import "./extensions/IERC20Metadata.sol";
import "../../utils/Context.sol";

/**
 * @dev Implementation of the {IERC20} interface.
 *
 * This implementation is agnostic to the way tokens are created. This means
 * that a supply mechanism has to be added in a derived contract using {_mint}.
 * For a generic mechanism see {ERC20PresetMinterPauser}.
 *
 * TIP: For a detailed writeup see our guide
 * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
 * to implement supply mechanisms].
 *
 * The default value of {decimals} is 18. To change this, you should override
 * this function so it returns a different value.
 *
 * We have followed general OpenZeppelin Contracts guidelines: functions revert
 * instead returning `false` on failure. This behavior is nonetheless
 * conventional and does not conflict with the expectations of ERC20
 * applications.
 *
 * Additionally, an {Approval} event is emitted on calls to {transferFrom}.
 * This allows applications to reconstruct the allowance for all accounts just
 * by listening to said events. Other implementations of the EIP may not emit
 * these events, as it isn't required by the specification.
 *
 * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
 * functions have been added to mitigate the well-known issues around setting
 * allowances. See {IERC20-approve}.
 */
contract ERC20 is Context, IERC20, IERC20Metadata {
    mapping(address => uint256) private _balances;

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

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

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

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

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

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

    /**
     * @dev See {IERC20-totalSupply}.
     */
    function totalSupply() public view virtual override returns (uint256) {
        return _totalSupply;
    }

    /**
     * @dev See {IERC20-balanceOf}.
     */
    function balanceOf(address account) public view virtual override returns (uint256) {
        return _balances[account];
    }

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

    /**
     * @dev See {IERC20-allowance}.
     */
    function allowance(address owner, address spender) public view virtual override returns (uint256) {
        return _allowances[owner][spender];
    }

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

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

    /**
     * @dev Atomically increases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
        address owner = _msgSender();
        _approve(owner, spender, allowance(owner, spender) + addedValue);
        return true;
    }

    /**
     * @dev Atomically decreases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `spender` must have allowance for the caller of at least
     * `subtractedValue`.
     */
    function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
        address owner = _msgSender();
        uint256 currentAllowance = allowance(owner, spender);
        require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
        unchecked {
            _approve(owner, spender, currentAllowance - subtractedValue);
        }

        return true;
    }

    /**
     * @dev Moves `amount` of tokens from `from` to `to`.
     *
     * This internal function is equivalent to {transfer}, and can be used to
     * e.g. implement automatic token fees, slashing mechanisms, etc.
     *
     * Emits a {Transfer} event.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `from` must have a balance of at least `amount`.
     */
    function _transfer(address from, address to, uint256 amount) internal virtual {
        require(from != address(0), "ERC20: transfer from the zero address");
        require(to != address(0), "ERC20: transfer to the zero address");

        _beforeTokenTransfer(from, to, amount);

        uint256 fromBalance = _balances[from];
        require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
        unchecked {
            _balances[from] = fromBalance - amount;
            // Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by
            // decrementing then incrementing.
            _balances[to] += amount;
        }

        emit Transfer(from, to, amount);

        _afterTokenTransfer(from, to, amount);
    }

    /** @dev Creates `amount` tokens and assigns them to `account`, increasing
     * the total supply.
     *
     * Emits a {Transfer} event with `from` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     */
    function _mint(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: mint to the zero address");

        _beforeTokenTransfer(address(0), account, amount);

        _totalSupply += amount;
        unchecked {
            // Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above.
            _balances[account] += amount;
        }
        emit Transfer(address(0), account, amount);

        _afterTokenTransfer(address(0), account, amount);
    }

    /**
     * @dev Destroys `amount` tokens from `account`, reducing the
     * total supply.
     *
     * Emits a {Transfer} event with `to` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     * - `account` must have at least `amount` tokens.
     */
    function _burn(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: burn from the zero address");

        _beforeTokenTransfer(account, address(0), amount);

        uint256 accountBalance = _balances[account];
        require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
        unchecked {
            _balances[account] = accountBalance - amount;
            // Overflow not possible: amount <= accountBalance <= totalSupply.
            _totalSupply -= amount;
        }

        emit Transfer(account, address(0), amount);

        _afterTokenTransfer(account, address(0), amount);
    }

    /**
     * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
     *
     * This internal function is equivalent to `approve`, and can be used to
     * e.g. set automatic allowances for certain subsystems, etc.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `owner` cannot be the zero address.
     * - `spender` cannot be the zero address.
     */
    function _approve(address owner, address spender, uint256 amount) internal virtual {
        require(owner != address(0), "ERC20: approve from the zero address");
        require(spender != address(0), "ERC20: approve to the zero address");

        _allowances[owner][spender] = amount;
        emit Approval(owner, spender, amount);
    }

    /**
     * @dev Updates `owner` s allowance for `spender` based on spent `amount`.
     *
     * Does not update the allowance amount in case of infinite allowance.
     * Revert if not enough allowance is available.
     *
     * Might emit an {Approval} event.
     */
    function _spendAllowance(address owner, address spender, uint256 amount) internal virtual {
        uint256 currentAllowance = allowance(owner, spender);
        if (currentAllowance != type(uint256).max) {
            require(currentAllowance >= amount, "ERC20: insufficient allowance");
            unchecked {
                _approve(owner, spender, currentAllowance - amount);
            }
        }
    }

    /**
     * @dev Hook that is called before any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * will be transferred to `to`.
     * - when `from` is zero, `amount` tokens will be minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens will be burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual {}

    /**
     * @dev Hook that is called after any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * has been transferred to `to`.
     * - when `from` is zero, `amount` tokens have been minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens have been burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _afterTokenTransfer(address from, address to, uint256 amount) internal virtual {}
}

File 18 of 39 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

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

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

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

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

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

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

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

File 19 of 39 : IERC20Metadata.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";

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

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

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

File 20 of 39 : IERC20Permit.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/IERC20Permit.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 */
interface IERC20Permit {
    /**
     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
     * given ``owner``'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

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

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

File 21 of 39 : SafeERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";
import "../extensions/IERC20Permit.sol";
import "../../../utils/Address.sol";

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

    /**
     * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeTransfer(IERC20 token, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    /**
     * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
     * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
     */
    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

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

    /**
     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 oldAllowance = token.allowance(address(this), spender);
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));
        }
    }

    /**
     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful. Compatible with tokens that require the approval to be set to
     * 0 before setting it to a non-zero value.
     */
    function forceApprove(IERC20 token, address spender, uint256 value) internal {
        bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);

        if (!_callOptionalReturnBool(token, approvalCall)) {
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));
            _callOptionalReturn(token, approvalCall);
        }
    }

    /**
     * @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
     * Revert on invalid signature.
     */
    function safePermit(
        IERC20Permit token,
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal {
        uint256 nonceBefore = token.nonces(owner);
        token.permit(owner, spender, value, deadline, v, r, s);
        uint256 nonceAfter = token.nonces(owner);
        require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
    }

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

        bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
        require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     *
     * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
        // and not revert is the subcall reverts.

        (bool success, bytes memory returndata) = address(token).call(data);
        return
            success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token));
    }
}

File 22 of 39 : Address.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     *
     * Furthermore, `isContract` will also return true if the target contract within
     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
     * which only has an effect at the end of a transaction.
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 0;
    }

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

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

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

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

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

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

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

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

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

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
     *
     * _Available since v4.8._
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        if (success) {
            if (returndata.length == 0) {
                // only check isContract if the call was successful and the return data is empty
                // otherwise we already know that it was a contract
                require(isContract(target), "Address: call to non-contract");
            }
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason or using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    function _revert(bytes memory returndata, string memory errorMessage) private pure {
        // Look for revert reason and bubble it up if present
        if (returndata.length > 0) {
            // The easiest way to bubble the revert reason is using memory via assembly
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert(errorMessage);
        }
    }
}

File 23 of 39 : Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;

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

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

File 24 of 39 : Math.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/Math.sol)

pragma solidity ^0.8.0;

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library Math {
    enum Rounding {
        Down, // Toward negative infinity
        Up, // Toward infinity
        Zero // Toward zero
    }

    /**
     * @dev Returns the largest of two numbers.
     */
    function max(uint256 a, uint256 b) internal pure returns (uint256) {
        return a > b ? a : b;
    }

    /**
     * @dev Returns the smallest of two numbers.
     */
    function min(uint256 a, uint256 b) internal pure returns (uint256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two numbers. The result is rounded towards
     * zero.
     */
    function average(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b) / 2 can overflow.
        return (a & b) + (a ^ b) / 2;
    }

    /**
     * @dev Returns the ceiling of the division of two numbers.
     *
     * This differs from standard division with `/` in that it rounds up instead
     * of rounding down.
     */
    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b - 1) / b can overflow on addition, so we distribute.
        return a == 0 ? 0 : (a - 1) / b + 1;
    }

    /**
     * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
     * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
     * with further edits by Uniswap Labs also under MIT license.
     */
    function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
        unchecked {
            // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
            // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
            // variables such that product = prod1 * 2^256 + prod0.
            uint256 prod0; // Least significant 256 bits of the product
            uint256 prod1; // Most significant 256 bits of the product
            assembly {
                let mm := mulmod(x, y, not(0))
                prod0 := mul(x, y)
                prod1 := sub(sub(mm, prod0), lt(mm, prod0))
            }

            // Handle non-overflow cases, 256 by 256 division.
            if (prod1 == 0) {
                // Solidity will revert if denominator == 0, unlike the div opcode on its own.
                // The surrounding unchecked block does not change this fact.
                // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
                return prod0 / denominator;
            }

            // Make sure the result is less than 2^256. Also prevents denominator == 0.
            require(denominator > prod1, "Math: mulDiv overflow");

            ///////////////////////////////////////////////
            // 512 by 256 division.
            ///////////////////////////////////////////////

            // Make division exact by subtracting the remainder from [prod1 prod0].
            uint256 remainder;
            assembly {
                // Compute remainder using mulmod.
                remainder := mulmod(x, y, denominator)

                // Subtract 256 bit number from 512 bit number.
                prod1 := sub(prod1, gt(remainder, prod0))
                prod0 := sub(prod0, remainder)
            }

            // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
            // See https://cs.stackexchange.com/q/138556/92363.

            // Does not overflow because the denominator cannot be zero at this stage in the function.
            uint256 twos = denominator & (~denominator + 1);
            assembly {
                // Divide denominator by twos.
                denominator := div(denominator, twos)

                // Divide [prod1 prod0] by twos.
                prod0 := div(prod0, twos)

                // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
                twos := add(div(sub(0, twos), twos), 1)
            }

            // Shift in bits from prod1 into prod0.
            prod0 |= prod1 * twos;

            // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
            // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
            // four bits. That is, denominator * inv = 1 mod 2^4.
            uint256 inverse = (3 * denominator) ^ 2;

            // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
            // in modular arithmetic, doubling the correct bits in each step.
            inverse *= 2 - denominator * inverse; // inverse mod 2^8
            inverse *= 2 - denominator * inverse; // inverse mod 2^16
            inverse *= 2 - denominator * inverse; // inverse mod 2^32
            inverse *= 2 - denominator * inverse; // inverse mod 2^64
            inverse *= 2 - denominator * inverse; // inverse mod 2^128
            inverse *= 2 - denominator * inverse; // inverse mod 2^256

            // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
            // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
            // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
            // is no longer required.
            result = prod0 * inverse;
            return result;
        }
    }

    /**
     * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
     */
    function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
        uint256 result = mulDiv(x, y, denominator);
        if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
            result += 1;
        }
        return result;
    }

    /**
     * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
     *
     * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
     */
    function sqrt(uint256 a) internal pure returns (uint256) {
        if (a == 0) {
            return 0;
        }

        // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
        //
        // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
        // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
        //
        // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
        // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
        // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
        //
        // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
        uint256 result = 1 << (log2(a) >> 1);

        // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
        // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
        // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
        // into the expected uint128 result.
        unchecked {
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            return min(result, a / result);
        }
    }

    /**
     * @notice Calculates sqrt(a), following the selected rounding direction.
     */
    function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = sqrt(a);
            return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 2, rounded down, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 128;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 64;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 32;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 16;
            }
            if (value >> 8 > 0) {
                value >>= 8;
                result += 8;
            }
            if (value >> 4 > 0) {
                value >>= 4;
                result += 4;
            }
            if (value >> 2 > 0) {
                value >>= 2;
                result += 2;
            }
            if (value >> 1 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 2, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log2(value);
            return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 10, rounded down, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >= 10 ** 64) {
                value /= 10 ** 64;
                result += 64;
            }
            if (value >= 10 ** 32) {
                value /= 10 ** 32;
                result += 32;
            }
            if (value >= 10 ** 16) {
                value /= 10 ** 16;
                result += 16;
            }
            if (value >= 10 ** 8) {
                value /= 10 ** 8;
                result += 8;
            }
            if (value >= 10 ** 4) {
                value /= 10 ** 4;
                result += 4;
            }
            if (value >= 10 ** 2) {
                value /= 10 ** 2;
                result += 2;
            }
            if (value >= 10 ** 1) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log10(value);
            return result + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 256, rounded down, of a positive value.
     * Returns 0 if given 0.
     *
     * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
     */
    function log256(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 16;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 8;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 4;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 2;
            }
            if (value >> 8 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 256, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log256(value);
            return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0);
        }
    }
}

File 25 of 39 : SafeCast.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.

pragma solidity ^0.8.0;

/**
 * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow
 * checks.
 *
 * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
 * easily result in undesired exploitation or bugs, since developers usually
 * assume that overflows raise errors. `SafeCast` restores this intuition by
 * reverting the transaction when such an operation overflows.
 *
 * Using this library instead of the unchecked operations eliminates an entire
 * class of bugs, so it's recommended to use it always.
 *
 * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing
 * all math on `uint256` and `int256` and then downcasting.
 */
library SafeCast {
    /**
     * @dev Returns the downcasted uint248 from uint256, reverting on
     * overflow (when the input is greater than largest uint248).
     *
     * Counterpart to Solidity's `uint248` operator.
     *
     * Requirements:
     *
     * - input must fit into 248 bits
     *
     * _Available since v4.7._
     */
    function toUint248(uint256 value) internal pure returns (uint248) {
        require(value <= type(uint248).max, "SafeCast: value doesn't fit in 248 bits");
        return uint248(value);
    }

    /**
     * @dev Returns the downcasted uint240 from uint256, reverting on
     * overflow (when the input is greater than largest uint240).
     *
     * Counterpart to Solidity's `uint240` operator.
     *
     * Requirements:
     *
     * - input must fit into 240 bits
     *
     * _Available since v4.7._
     */
    function toUint240(uint256 value) internal pure returns (uint240) {
        require(value <= type(uint240).max, "SafeCast: value doesn't fit in 240 bits");
        return uint240(value);
    }

    /**
     * @dev Returns the downcasted uint232 from uint256, reverting on
     * overflow (when the input is greater than largest uint232).
     *
     * Counterpart to Solidity's `uint232` operator.
     *
     * Requirements:
     *
     * - input must fit into 232 bits
     *
     * _Available since v4.7._
     */
    function toUint232(uint256 value) internal pure returns (uint232) {
        require(value <= type(uint232).max, "SafeCast: value doesn't fit in 232 bits");
        return uint232(value);
    }

    /**
     * @dev Returns the downcasted uint224 from uint256, reverting on
     * overflow (when the input is greater than largest uint224).
     *
     * Counterpart to Solidity's `uint224` operator.
     *
     * Requirements:
     *
     * - input must fit into 224 bits
     *
     * _Available since v4.2._
     */
    function toUint224(uint256 value) internal pure returns (uint224) {
        require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits");
        return uint224(value);
    }

    /**
     * @dev Returns the downcasted uint216 from uint256, reverting on
     * overflow (when the input is greater than largest uint216).
     *
     * Counterpart to Solidity's `uint216` operator.
     *
     * Requirements:
     *
     * - input must fit into 216 bits
     *
     * _Available since v4.7._
     */
    function toUint216(uint256 value) internal pure returns (uint216) {
        require(value <= type(uint216).max, "SafeCast: value doesn't fit in 216 bits");
        return uint216(value);
    }

    /**
     * @dev Returns the downcasted uint208 from uint256, reverting on
     * overflow (when the input is greater than largest uint208).
     *
     * Counterpart to Solidity's `uint208` operator.
     *
     * Requirements:
     *
     * - input must fit into 208 bits
     *
     * _Available since v4.7._
     */
    function toUint208(uint256 value) internal pure returns (uint208) {
        require(value <= type(uint208).max, "SafeCast: value doesn't fit in 208 bits");
        return uint208(value);
    }

    /**
     * @dev Returns the downcasted uint200 from uint256, reverting on
     * overflow (when the input is greater than largest uint200).
     *
     * Counterpart to Solidity's `uint200` operator.
     *
     * Requirements:
     *
     * - input must fit into 200 bits
     *
     * _Available since v4.7._
     */
    function toUint200(uint256 value) internal pure returns (uint200) {
        require(value <= type(uint200).max, "SafeCast: value doesn't fit in 200 bits");
        return uint200(value);
    }

    /**
     * @dev Returns the downcasted uint192 from uint256, reverting on
     * overflow (when the input is greater than largest uint192).
     *
     * Counterpart to Solidity's `uint192` operator.
     *
     * Requirements:
     *
     * - input must fit into 192 bits
     *
     * _Available since v4.7._
     */
    function toUint192(uint256 value) internal pure returns (uint192) {
        require(value <= type(uint192).max, "SafeCast: value doesn't fit in 192 bits");
        return uint192(value);
    }

    /**
     * @dev Returns the downcasted uint184 from uint256, reverting on
     * overflow (when the input is greater than largest uint184).
     *
     * Counterpart to Solidity's `uint184` operator.
     *
     * Requirements:
     *
     * - input must fit into 184 bits
     *
     * _Available since v4.7._
     */
    function toUint184(uint256 value) internal pure returns (uint184) {
        require(value <= type(uint184).max, "SafeCast: value doesn't fit in 184 bits");
        return uint184(value);
    }

    /**
     * @dev Returns the downcasted uint176 from uint256, reverting on
     * overflow (when the input is greater than largest uint176).
     *
     * Counterpart to Solidity's `uint176` operator.
     *
     * Requirements:
     *
     * - input must fit into 176 bits
     *
     * _Available since v4.7._
     */
    function toUint176(uint256 value) internal pure returns (uint176) {
        require(value <= type(uint176).max, "SafeCast: value doesn't fit in 176 bits");
        return uint176(value);
    }

    /**
     * @dev Returns the downcasted uint168 from uint256, reverting on
     * overflow (when the input is greater than largest uint168).
     *
     * Counterpart to Solidity's `uint168` operator.
     *
     * Requirements:
     *
     * - input must fit into 168 bits
     *
     * _Available since v4.7._
     */
    function toUint168(uint256 value) internal pure returns (uint168) {
        require(value <= type(uint168).max, "SafeCast: value doesn't fit in 168 bits");
        return uint168(value);
    }

    /**
     * @dev Returns the downcasted uint160 from uint256, reverting on
     * overflow (when the input is greater than largest uint160).
     *
     * Counterpart to Solidity's `uint160` operator.
     *
     * Requirements:
     *
     * - input must fit into 160 bits
     *
     * _Available since v4.7._
     */
    function toUint160(uint256 value) internal pure returns (uint160) {
        require(value <= type(uint160).max, "SafeCast: value doesn't fit in 160 bits");
        return uint160(value);
    }

    /**
     * @dev Returns the downcasted uint152 from uint256, reverting on
     * overflow (when the input is greater than largest uint152).
     *
     * Counterpart to Solidity's `uint152` operator.
     *
     * Requirements:
     *
     * - input must fit into 152 bits
     *
     * _Available since v4.7._
     */
    function toUint152(uint256 value) internal pure returns (uint152) {
        require(value <= type(uint152).max, "SafeCast: value doesn't fit in 152 bits");
        return uint152(value);
    }

    /**
     * @dev Returns the downcasted uint144 from uint256, reverting on
     * overflow (when the input is greater than largest uint144).
     *
     * Counterpart to Solidity's `uint144` operator.
     *
     * Requirements:
     *
     * - input must fit into 144 bits
     *
     * _Available since v4.7._
     */
    function toUint144(uint256 value) internal pure returns (uint144) {
        require(value <= type(uint144).max, "SafeCast: value doesn't fit in 144 bits");
        return uint144(value);
    }

    /**
     * @dev Returns the downcasted uint136 from uint256, reverting on
     * overflow (when the input is greater than largest uint136).
     *
     * Counterpart to Solidity's `uint136` operator.
     *
     * Requirements:
     *
     * - input must fit into 136 bits
     *
     * _Available since v4.7._
     */
    function toUint136(uint256 value) internal pure returns (uint136) {
        require(value <= type(uint136).max, "SafeCast: value doesn't fit in 136 bits");
        return uint136(value);
    }

    /**
     * @dev Returns the downcasted uint128 from uint256, reverting on
     * overflow (when the input is greater than largest uint128).
     *
     * Counterpart to Solidity's `uint128` operator.
     *
     * Requirements:
     *
     * - input must fit into 128 bits
     *
     * _Available since v2.5._
     */
    function toUint128(uint256 value) internal pure returns (uint128) {
        require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits");
        return uint128(value);
    }

    /**
     * @dev Returns the downcasted uint120 from uint256, reverting on
     * overflow (when the input is greater than largest uint120).
     *
     * Counterpart to Solidity's `uint120` operator.
     *
     * Requirements:
     *
     * - input must fit into 120 bits
     *
     * _Available since v4.7._
     */
    function toUint120(uint256 value) internal pure returns (uint120) {
        require(value <= type(uint120).max, "SafeCast: value doesn't fit in 120 bits");
        return uint120(value);
    }

    /**
     * @dev Returns the downcasted uint112 from uint256, reverting on
     * overflow (when the input is greater than largest uint112).
     *
     * Counterpart to Solidity's `uint112` operator.
     *
     * Requirements:
     *
     * - input must fit into 112 bits
     *
     * _Available since v4.7._
     */
    function toUint112(uint256 value) internal pure returns (uint112) {
        require(value <= type(uint112).max, "SafeCast: value doesn't fit in 112 bits");
        return uint112(value);
    }

    /**
     * @dev Returns the downcasted uint104 from uint256, reverting on
     * overflow (when the input is greater than largest uint104).
     *
     * Counterpart to Solidity's `uint104` operator.
     *
     * Requirements:
     *
     * - input must fit into 104 bits
     *
     * _Available since v4.7._
     */
    function toUint104(uint256 value) internal pure returns (uint104) {
        require(value <= type(uint104).max, "SafeCast: value doesn't fit in 104 bits");
        return uint104(value);
    }

    /**
     * @dev Returns the downcasted uint96 from uint256, reverting on
     * overflow (when the input is greater than largest uint96).
     *
     * Counterpart to Solidity's `uint96` operator.
     *
     * Requirements:
     *
     * - input must fit into 96 bits
     *
     * _Available since v4.2._
     */
    function toUint96(uint256 value) internal pure returns (uint96) {
        require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits");
        return uint96(value);
    }

    /**
     * @dev Returns the downcasted uint88 from uint256, reverting on
     * overflow (when the input is greater than largest uint88).
     *
     * Counterpart to Solidity's `uint88` operator.
     *
     * Requirements:
     *
     * - input must fit into 88 bits
     *
     * _Available since v4.7._
     */
    function toUint88(uint256 value) internal pure returns (uint88) {
        require(value <= type(uint88).max, "SafeCast: value doesn't fit in 88 bits");
        return uint88(value);
    }

    /**
     * @dev Returns the downcasted uint80 from uint256, reverting on
     * overflow (when the input is greater than largest uint80).
     *
     * Counterpart to Solidity's `uint80` operator.
     *
     * Requirements:
     *
     * - input must fit into 80 bits
     *
     * _Available since v4.7._
     */
    function toUint80(uint256 value) internal pure returns (uint80) {
        require(value <= type(uint80).max, "SafeCast: value doesn't fit in 80 bits");
        return uint80(value);
    }

    /**
     * @dev Returns the downcasted uint72 from uint256, reverting on
     * overflow (when the input is greater than largest uint72).
     *
     * Counterpart to Solidity's `uint72` operator.
     *
     * Requirements:
     *
     * - input must fit into 72 bits
     *
     * _Available since v4.7._
     */
    function toUint72(uint256 value) internal pure returns (uint72) {
        require(value <= type(uint72).max, "SafeCast: value doesn't fit in 72 bits");
        return uint72(value);
    }

    /**
     * @dev Returns the downcasted uint64 from uint256, reverting on
     * overflow (when the input is greater than largest uint64).
     *
     * Counterpart to Solidity's `uint64` operator.
     *
     * Requirements:
     *
     * - input must fit into 64 bits
     *
     * _Available since v2.5._
     */
    function toUint64(uint256 value) internal pure returns (uint64) {
        require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits");
        return uint64(value);
    }

    /**
     * @dev Returns the downcasted uint56 from uint256, reverting on
     * overflow (when the input is greater than largest uint56).
     *
     * Counterpart to Solidity's `uint56` operator.
     *
     * Requirements:
     *
     * - input must fit into 56 bits
     *
     * _Available since v4.7._
     */
    function toUint56(uint256 value) internal pure returns (uint56) {
        require(value <= type(uint56).max, "SafeCast: value doesn't fit in 56 bits");
        return uint56(value);
    }

    /**
     * @dev Returns the downcasted uint48 from uint256, reverting on
     * overflow (when the input is greater than largest uint48).
     *
     * Counterpart to Solidity's `uint48` operator.
     *
     * Requirements:
     *
     * - input must fit into 48 bits
     *
     * _Available since v4.7._
     */
    function toUint48(uint256 value) internal pure returns (uint48) {
        require(value <= type(uint48).max, "SafeCast: value doesn't fit in 48 bits");
        return uint48(value);
    }

    /**
     * @dev Returns the downcasted uint40 from uint256, reverting on
     * overflow (when the input is greater than largest uint40).
     *
     * Counterpart to Solidity's `uint40` operator.
     *
     * Requirements:
     *
     * - input must fit into 40 bits
     *
     * _Available since v4.7._
     */
    function toUint40(uint256 value) internal pure returns (uint40) {
        require(value <= type(uint40).max, "SafeCast: value doesn't fit in 40 bits");
        return uint40(value);
    }

    /**
     * @dev Returns the downcasted uint32 from uint256, reverting on
     * overflow (when the input is greater than largest uint32).
     *
     * Counterpart to Solidity's `uint32` operator.
     *
     * Requirements:
     *
     * - input must fit into 32 bits
     *
     * _Available since v2.5._
     */
    function toUint32(uint256 value) internal pure returns (uint32) {
        require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits");
        return uint32(value);
    }

    /**
     * @dev Returns the downcasted uint24 from uint256, reverting on
     * overflow (when the input is greater than largest uint24).
     *
     * Counterpart to Solidity's `uint24` operator.
     *
     * Requirements:
     *
     * - input must fit into 24 bits
     *
     * _Available since v4.7._
     */
    function toUint24(uint256 value) internal pure returns (uint24) {
        require(value <= type(uint24).max, "SafeCast: value doesn't fit in 24 bits");
        return uint24(value);
    }

    /**
     * @dev Returns the downcasted uint16 from uint256, reverting on
     * overflow (when the input is greater than largest uint16).
     *
     * Counterpart to Solidity's `uint16` operator.
     *
     * Requirements:
     *
     * - input must fit into 16 bits
     *
     * _Available since v2.5._
     */
    function toUint16(uint256 value) internal pure returns (uint16) {
        require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits");
        return uint16(value);
    }

    /**
     * @dev Returns the downcasted uint8 from uint256, reverting on
     * overflow (when the input is greater than largest uint8).
     *
     * Counterpart to Solidity's `uint8` operator.
     *
     * Requirements:
     *
     * - input must fit into 8 bits
     *
     * _Available since v2.5._
     */
    function toUint8(uint256 value) internal pure returns (uint8) {
        require(value <= type(uint8).max, "SafeCast: value doesn't fit in 8 bits");
        return uint8(value);
    }

    /**
     * @dev Converts a signed int256 into an unsigned uint256.
     *
     * Requirements:
     *
     * - input must be greater than or equal to 0.
     *
     * _Available since v3.0._
     */
    function toUint256(int256 value) internal pure returns (uint256) {
        require(value >= 0, "SafeCast: value must be positive");
        return uint256(value);
    }

    /**
     * @dev Returns the downcasted int248 from int256, reverting on
     * overflow (when the input is less than smallest int248 or
     * greater than largest int248).
     *
     * Counterpart to Solidity's `int248` operator.
     *
     * Requirements:
     *
     * - input must fit into 248 bits
     *
     * _Available since v4.7._
     */
    function toInt248(int256 value) internal pure returns (int248 downcasted) {
        downcasted = int248(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 248 bits");
    }

    /**
     * @dev Returns the downcasted int240 from int256, reverting on
     * overflow (when the input is less than smallest int240 or
     * greater than largest int240).
     *
     * Counterpart to Solidity's `int240` operator.
     *
     * Requirements:
     *
     * - input must fit into 240 bits
     *
     * _Available since v4.7._
     */
    function toInt240(int256 value) internal pure returns (int240 downcasted) {
        downcasted = int240(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 240 bits");
    }

    /**
     * @dev Returns the downcasted int232 from int256, reverting on
     * overflow (when the input is less than smallest int232 or
     * greater than largest int232).
     *
     * Counterpart to Solidity's `int232` operator.
     *
     * Requirements:
     *
     * - input must fit into 232 bits
     *
     * _Available since v4.7._
     */
    function toInt232(int256 value) internal pure returns (int232 downcasted) {
        downcasted = int232(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 232 bits");
    }

    /**
     * @dev Returns the downcasted int224 from int256, reverting on
     * overflow (when the input is less than smallest int224 or
     * greater than largest int224).
     *
     * Counterpart to Solidity's `int224` operator.
     *
     * Requirements:
     *
     * - input must fit into 224 bits
     *
     * _Available since v4.7._
     */
    function toInt224(int256 value) internal pure returns (int224 downcasted) {
        downcasted = int224(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 224 bits");
    }

    /**
     * @dev Returns the downcasted int216 from int256, reverting on
     * overflow (when the input is less than smallest int216 or
     * greater than largest int216).
     *
     * Counterpart to Solidity's `int216` operator.
     *
     * Requirements:
     *
     * - input must fit into 216 bits
     *
     * _Available since v4.7._
     */
    function toInt216(int256 value) internal pure returns (int216 downcasted) {
        downcasted = int216(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 216 bits");
    }

    /**
     * @dev Returns the downcasted int208 from int256, reverting on
     * overflow (when the input is less than smallest int208 or
     * greater than largest int208).
     *
     * Counterpart to Solidity's `int208` operator.
     *
     * Requirements:
     *
     * - input must fit into 208 bits
     *
     * _Available since v4.7._
     */
    function toInt208(int256 value) internal pure returns (int208 downcasted) {
        downcasted = int208(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 208 bits");
    }

    /**
     * @dev Returns the downcasted int200 from int256, reverting on
     * overflow (when the input is less than smallest int200 or
     * greater than largest int200).
     *
     * Counterpart to Solidity's `int200` operator.
     *
     * Requirements:
     *
     * - input must fit into 200 bits
     *
     * _Available since v4.7._
     */
    function toInt200(int256 value) internal pure returns (int200 downcasted) {
        downcasted = int200(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 200 bits");
    }

    /**
     * @dev Returns the downcasted int192 from int256, reverting on
     * overflow (when the input is less than smallest int192 or
     * greater than largest int192).
     *
     * Counterpart to Solidity's `int192` operator.
     *
     * Requirements:
     *
     * - input must fit into 192 bits
     *
     * _Available since v4.7._
     */
    function toInt192(int256 value) internal pure returns (int192 downcasted) {
        downcasted = int192(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 192 bits");
    }

    /**
     * @dev Returns the downcasted int184 from int256, reverting on
     * overflow (when the input is less than smallest int184 or
     * greater than largest int184).
     *
     * Counterpart to Solidity's `int184` operator.
     *
     * Requirements:
     *
     * - input must fit into 184 bits
     *
     * _Available since v4.7._
     */
    function toInt184(int256 value) internal pure returns (int184 downcasted) {
        downcasted = int184(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 184 bits");
    }

    /**
     * @dev Returns the downcasted int176 from int256, reverting on
     * overflow (when the input is less than smallest int176 or
     * greater than largest int176).
     *
     * Counterpart to Solidity's `int176` operator.
     *
     * Requirements:
     *
     * - input must fit into 176 bits
     *
     * _Available since v4.7._
     */
    function toInt176(int256 value) internal pure returns (int176 downcasted) {
        downcasted = int176(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 176 bits");
    }

    /**
     * @dev Returns the downcasted int168 from int256, reverting on
     * overflow (when the input is less than smallest int168 or
     * greater than largest int168).
     *
     * Counterpart to Solidity's `int168` operator.
     *
     * Requirements:
     *
     * - input must fit into 168 bits
     *
     * _Available since v4.7._
     */
    function toInt168(int256 value) internal pure returns (int168 downcasted) {
        downcasted = int168(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 168 bits");
    }

    /**
     * @dev Returns the downcasted int160 from int256, reverting on
     * overflow (when the input is less than smallest int160 or
     * greater than largest int160).
     *
     * Counterpart to Solidity's `int160` operator.
     *
     * Requirements:
     *
     * - input must fit into 160 bits
     *
     * _Available since v4.7._
     */
    function toInt160(int256 value) internal pure returns (int160 downcasted) {
        downcasted = int160(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 160 bits");
    }

    /**
     * @dev Returns the downcasted int152 from int256, reverting on
     * overflow (when the input is less than smallest int152 or
     * greater than largest int152).
     *
     * Counterpart to Solidity's `int152` operator.
     *
     * Requirements:
     *
     * - input must fit into 152 bits
     *
     * _Available since v4.7._
     */
    function toInt152(int256 value) internal pure returns (int152 downcasted) {
        downcasted = int152(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 152 bits");
    }

    /**
     * @dev Returns the downcasted int144 from int256, reverting on
     * overflow (when the input is less than smallest int144 or
     * greater than largest int144).
     *
     * Counterpart to Solidity's `int144` operator.
     *
     * Requirements:
     *
     * - input must fit into 144 bits
     *
     * _Available since v4.7._
     */
    function toInt144(int256 value) internal pure returns (int144 downcasted) {
        downcasted = int144(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 144 bits");
    }

    /**
     * @dev Returns the downcasted int136 from int256, reverting on
     * overflow (when the input is less than smallest int136 or
     * greater than largest int136).
     *
     * Counterpart to Solidity's `int136` operator.
     *
     * Requirements:
     *
     * - input must fit into 136 bits
     *
     * _Available since v4.7._
     */
    function toInt136(int256 value) internal pure returns (int136 downcasted) {
        downcasted = int136(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 136 bits");
    }

    /**
     * @dev Returns the downcasted int128 from int256, reverting on
     * overflow (when the input is less than smallest int128 or
     * greater than largest int128).
     *
     * Counterpart to Solidity's `int128` operator.
     *
     * Requirements:
     *
     * - input must fit into 128 bits
     *
     * _Available since v3.1._
     */
    function toInt128(int256 value) internal pure returns (int128 downcasted) {
        downcasted = int128(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 128 bits");
    }

    /**
     * @dev Returns the downcasted int120 from int256, reverting on
     * overflow (when the input is less than smallest int120 or
     * greater than largest int120).
     *
     * Counterpart to Solidity's `int120` operator.
     *
     * Requirements:
     *
     * - input must fit into 120 bits
     *
     * _Available since v4.7._
     */
    function toInt120(int256 value) internal pure returns (int120 downcasted) {
        downcasted = int120(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 120 bits");
    }

    /**
     * @dev Returns the downcasted int112 from int256, reverting on
     * overflow (when the input is less than smallest int112 or
     * greater than largest int112).
     *
     * Counterpart to Solidity's `int112` operator.
     *
     * Requirements:
     *
     * - input must fit into 112 bits
     *
     * _Available since v4.7._
     */
    function toInt112(int256 value) internal pure returns (int112 downcasted) {
        downcasted = int112(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 112 bits");
    }

    /**
     * @dev Returns the downcasted int104 from int256, reverting on
     * overflow (when the input is less than smallest int104 or
     * greater than largest int104).
     *
     * Counterpart to Solidity's `int104` operator.
     *
     * Requirements:
     *
     * - input must fit into 104 bits
     *
     * _Available since v4.7._
     */
    function toInt104(int256 value) internal pure returns (int104 downcasted) {
        downcasted = int104(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 104 bits");
    }

    /**
     * @dev Returns the downcasted int96 from int256, reverting on
     * overflow (when the input is less than smallest int96 or
     * greater than largest int96).
     *
     * Counterpart to Solidity's `int96` operator.
     *
     * Requirements:
     *
     * - input must fit into 96 bits
     *
     * _Available since v4.7._
     */
    function toInt96(int256 value) internal pure returns (int96 downcasted) {
        downcasted = int96(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 96 bits");
    }

    /**
     * @dev Returns the downcasted int88 from int256, reverting on
     * overflow (when the input is less than smallest int88 or
     * greater than largest int88).
     *
     * Counterpart to Solidity's `int88` operator.
     *
     * Requirements:
     *
     * - input must fit into 88 bits
     *
     * _Available since v4.7._
     */
    function toInt88(int256 value) internal pure returns (int88 downcasted) {
        downcasted = int88(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 88 bits");
    }

    /**
     * @dev Returns the downcasted int80 from int256, reverting on
     * overflow (when the input is less than smallest int80 or
     * greater than largest int80).
     *
     * Counterpart to Solidity's `int80` operator.
     *
     * Requirements:
     *
     * - input must fit into 80 bits
     *
     * _Available since v4.7._
     */
    function toInt80(int256 value) internal pure returns (int80 downcasted) {
        downcasted = int80(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 80 bits");
    }

    /**
     * @dev Returns the downcasted int72 from int256, reverting on
     * overflow (when the input is less than smallest int72 or
     * greater than largest int72).
     *
     * Counterpart to Solidity's `int72` operator.
     *
     * Requirements:
     *
     * - input must fit into 72 bits
     *
     * _Available since v4.7._
     */
    function toInt72(int256 value) internal pure returns (int72 downcasted) {
        downcasted = int72(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 72 bits");
    }

    /**
     * @dev Returns the downcasted int64 from int256, reverting on
     * overflow (when the input is less than smallest int64 or
     * greater than largest int64).
     *
     * Counterpart to Solidity's `int64` operator.
     *
     * Requirements:
     *
     * - input must fit into 64 bits
     *
     * _Available since v3.1._
     */
    function toInt64(int256 value) internal pure returns (int64 downcasted) {
        downcasted = int64(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 64 bits");
    }

    /**
     * @dev Returns the downcasted int56 from int256, reverting on
     * overflow (when the input is less than smallest int56 or
     * greater than largest int56).
     *
     * Counterpart to Solidity's `int56` operator.
     *
     * Requirements:
     *
     * - input must fit into 56 bits
     *
     * _Available since v4.7._
     */
    function toInt56(int256 value) internal pure returns (int56 downcasted) {
        downcasted = int56(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 56 bits");
    }

    /**
     * @dev Returns the downcasted int48 from int256, reverting on
     * overflow (when the input is less than smallest int48 or
     * greater than largest int48).
     *
     * Counterpart to Solidity's `int48` operator.
     *
     * Requirements:
     *
     * - input must fit into 48 bits
     *
     * _Available since v4.7._
     */
    function toInt48(int256 value) internal pure returns (int48 downcasted) {
        downcasted = int48(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 48 bits");
    }

    /**
     * @dev Returns the downcasted int40 from int256, reverting on
     * overflow (when the input is less than smallest int40 or
     * greater than largest int40).
     *
     * Counterpart to Solidity's `int40` operator.
     *
     * Requirements:
     *
     * - input must fit into 40 bits
     *
     * _Available since v4.7._
     */
    function toInt40(int256 value) internal pure returns (int40 downcasted) {
        downcasted = int40(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 40 bits");
    }

    /**
     * @dev Returns the downcasted int32 from int256, reverting on
     * overflow (when the input is less than smallest int32 or
     * greater than largest int32).
     *
     * Counterpart to Solidity's `int32` operator.
     *
     * Requirements:
     *
     * - input must fit into 32 bits
     *
     * _Available since v3.1._
     */
    function toInt32(int256 value) internal pure returns (int32 downcasted) {
        downcasted = int32(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 32 bits");
    }

    /**
     * @dev Returns the downcasted int24 from int256, reverting on
     * overflow (when the input is less than smallest int24 or
     * greater than largest int24).
     *
     * Counterpart to Solidity's `int24` operator.
     *
     * Requirements:
     *
     * - input must fit into 24 bits
     *
     * _Available since v4.7._
     */
    function toInt24(int256 value) internal pure returns (int24 downcasted) {
        downcasted = int24(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 24 bits");
    }

    /**
     * @dev Returns the downcasted int16 from int256, reverting on
     * overflow (when the input is less than smallest int16 or
     * greater than largest int16).
     *
     * Counterpart to Solidity's `int16` operator.
     *
     * Requirements:
     *
     * - input must fit into 16 bits
     *
     * _Available since v3.1._
     */
    function toInt16(int256 value) internal pure returns (int16 downcasted) {
        downcasted = int16(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 16 bits");
    }

    /**
     * @dev Returns the downcasted int8 from int256, reverting on
     * overflow (when the input is less than smallest int8 or
     * greater than largest int8).
     *
     * Counterpart to Solidity's `int8` operator.
     *
     * Requirements:
     *
     * - input must fit into 8 bits
     *
     * _Available since v3.1._
     */
    function toInt8(int256 value) internal pure returns (int8 downcasted) {
        downcasted = int8(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 8 bits");
    }

    /**
     * @dev Converts an unsigned uint256 into a signed int256.
     *
     * Requirements:
     *
     * - input must be less than or equal to maxInt256.
     *
     * _Available since v3.0._
     */
    function toInt256(uint256 value) internal pure returns (int256) {
        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
        require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256");
        return int256(value);
    }
}

File 26 of 39 : SafeMath.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/SafeMath.sol)

pragma solidity ^0.8.0;

// CAUTION
// This version of SafeMath should only be used with Solidity 0.8 or later,
// because it relies on the compiler's built in overflow checks.

/**
 * @dev Wrappers over Solidity's arithmetic operations.
 *
 * NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler
 * now has built in overflow checking.
 */
library SafeMath {
    /**
     * @dev Returns the addition of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            uint256 c = a + b;
            if (c < a) return (false, 0);
            return (true, c);
        }
    }

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

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

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

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

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

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

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

    /**
     * @dev Returns the integer division of two unsigned integers, reverting on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator.
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b) internal pure returns (uint256) {
        return a / b;
    }

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

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

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

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

File 27 of 39 : Pairs.sol
// SPDX-License-Identifier: SEE LICENSE IN LICENSE
pragma solidity 0.8.19;
import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import { Token } from "../token/Token.sol";
import { MAX_GAP } from "../utility/Constants.sol";

struct Pair {
    uint128 id;
    Token[2] tokens;
}

abstract contract Pairs is Initializable {
    error PairAlreadyExists();
    error PairDoesNotExist();

    // unique incremental id representing a pair
    uint128 private _lastPairId;

    // mapping of pairs of tokens to their pair id, tokens are sorted at any order
    mapping(Token => mapping(Token => uint128)) private _pairIds;

    // mapping between a pairId to its Pair object
    mapping(uint128 => Token[2]) private _pairsStorage;

    // upgrade forward-compatibility storage gap
    uint256[MAX_GAP - 3] private __gap;

    /**
     * @dev triggered when a new pair is created
     */
    event PairCreated(uint128 indexed pairId, Token indexed token0, Token indexed token1);

    // solhint-disable func-name-mixedcase

    /**
     * @dev initializes the contract and its parents
     */
    function __Pairs_init() internal onlyInitializing {
        __Pairs_init_unchained();
    }

    /**
     * @dev performs contract-specific initialization
     */
    function __Pairs_init_unchained() internal onlyInitializing {}

    // solhint-enable func-name-mixedcase

    /**
     * @dev generates and stores a new pair, tokens are assumed unique and valid
     */
    function _createPair(Token token0, Token token1) internal returns (Pair memory) {
        // validate pair existence
        if (_pairExists(token0, token1)) {
            revert PairAlreadyExists();
        }

        // sort tokens
        Token[2] memory sortedTokens = _sortTokens(token0, token1);

        // increment pair id
        uint128 id = _lastPairId + 1;
        _lastPairId = id;

        // store pair
        _pairsStorage[id] = sortedTokens;
        _pairIds[sortedTokens[0]][sortedTokens[1]] = id;

        emit PairCreated(id, sortedTokens[0], sortedTokens[1]);
        return Pair({ id: id, tokens: sortedTokens });
    }

    /**
     * @dev return a pair matching the given tokens
     */
    function _pair(Token token0, Token token1) internal view returns (Pair memory) {
        // validate pair existence
        if (!_pairExists(token0, token1)) {
            revert PairDoesNotExist();
        }

        // sort tokens
        Token[2] memory sortedTokens = _sortTokens(token0, token1);

        // return pair
        uint128 id = _pairIds[sortedTokens[0]][sortedTokens[1]];
        return Pair({ id: id, tokens: sortedTokens });
    }

    function _pairById(uint128 pairId) internal view returns (Pair memory) {
        Token[2] memory tokens = _pairsStorage[pairId];
        if (Token.unwrap(tokens[0]) == address(0)) {
            revert PairDoesNotExist();
        }
        return Pair({ id: pairId, tokens: tokens });
    }

    /**
     * @dev check for the existence of a pair (pair id's are sequential integers starting at 1)
     */
    function _pairExists(Token token0, Token token1) internal view returns (bool) {
        // sort tokens
        Token[2] memory sortedTokens = _sortTokens(token0, token1);

        if (_pairIds[sortedTokens[0]][sortedTokens[1]] == 0) {
            return false;
        }
        return true;
    }

    /**
     * @dev returns a list of all supported pairs
     */
    function _pairs() internal view returns (Token[2][] memory) {
        uint128 length = _lastPairId;
        Token[2][] memory list = new Token[2][](length);
        for (uint128 i = 0; i < length; i++) {
            list[i] = _pairsStorage[i + 1];
        }

        return list;
    }

    /**
     * returns the given tokens sorted by address value, smaller first
     */
    function _sortTokens(Token token0, Token token1) private pure returns (Token[2] memory) {
        return Token.unwrap(token0) < Token.unwrap(token1) ? [token0, token1] : [token1, token0];
    }
}

File 28 of 39 : Strategies.sol
// SPDX-License-Identifier: SEE LICENSE IN LICENSE
pragma solidity 0.8.19;
import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import { EnumerableSetUpgradeable } from "@openzeppelin/contracts-upgradeable/utils/structs/EnumerableSetUpgradeable.sol";
import { Math } from "@openzeppelin/contracts/utils/math/Math.sol";
import { SafeMath } from "@openzeppelin/contracts/utils/math/SafeMath.sol";
import { SafeCast } from "@openzeppelin/contracts/utils/math/SafeCast.sol";
import { Address } from "@openzeppelin/contracts/utils/Address.sol";
import { MathEx } from "../utility/MathEx.sol";
import { InvalidIndices } from "../utility/Utils.sol";
import { Token } from "../token/Token.sol";
import { Pair } from "./Pairs.sol";
import { IVoucher } from "../voucher/interfaces/IVoucher.sol";
import { PPM_RESOLUTION } from "../utility/Constants.sol";
import { MAX_GAP } from "../utility/Constants.sol";

/**
 * @dev:
 *
 * a strategy consists of two orders:
 * - order 0 sells `y0` units of token 0 at a marginal rate `M0` ranging between `L0` and `H0`
 * - order 1 sells `y1` units of token 1 at a marginal rate `M1` ranging between `L1` and `H1`
 *
 * rate symbols:
 * - `L0` indicates the lowest value of one wei of token 0 in units of token 1
 * - `H0` indicates the highest value of one wei of token 0 in units of token 1
 * - `M0` indicates the marginal value of one wei of token 0 in units of token 1
 * - `L1` indicates the lowest value of one wei of token 1 in units of token 0
 * - `H1` indicates the highest value of one wei of token 1 in units of token 0
 * - `M1` indicates the marginal value of one wei of token 1 in units of token 0
 *
 * the term "one wei" serves here as a simplification of "an amount tending to zero",
 * hence the rate values above are all theoretical.
 * moreover, since trade calculation is based on the square roots of the rates,
 * an order doesn't actually hold the rate values, but a modified version of them.
 * for each rate `r`, the order maintains:
 * - mantissa: the value of the 48 most significant bits of `floor(sqrt(r) * 2 ^ 48)`
 * - exponent: the number of the remaining (least significant) bits, limited up to 48
 * this allows for rates between ~12.6e-28 and ~7.92e+28, at an average resolution of ~2.81e+14.
 * it also ensures that every rate value `r` is supported if and only if `1 / r` is supported.
 * however, it also yields a certain degree of accuracy loss as soon as the order is created.
 *
 * encoding / decoding scheme:
 * - `b(x) = bit-length of x`
 * - `c(x) = max(b(x) - 48, 0)`
 * - `f(x) = floor(sqrt(x) * (1 << 48))`
 * - `g(x) = f(x) >> c(f(x)) << c(f(x))`
 * - `e(x) = (x >> c(x)) | (c(x) << 48)`
 * - `d(x) = (x & ((1 << 48) - 1)) << (x >> 48)`
 *
 * let the following denote:
 * - `L = g(lowest rate)`
 * - `H = g(highest rate)`
 * - `M = g(marginal rate)`
 *
 * then the order maintains:
 * - `y = current liquidity`
 * - `z = current liquidity * (H - L) / (M - L)`
 * - `A = e(H - L)`
 * - `B = e(L)`
 *
 * and the order reflects:
 * - `L = d(B)`
 * - `H = d(B + A)`
 * - `M = d(B + A * y / z)`
 *
 * upon trading on a given order in a given strategy:
 * - the value of `y` in the given order decreases
 * - the value of `y` in the other order increases
 * - the value of `z` in the other order may increase
 * - the values of all other parameters remain unchanged
 *
 * given a source amount `x`, the expected target amount is:
 * - theoretical formula: `M ^ 2 * x * y / (M * (M - L) * x + y)`
 * - implemented formula: `x * (A * y + B * z) ^ 2 / (A * x * (A * y + B * z) + z ^ 2)`
 *
 * given a target amount `x`, the required source amount is:
 * - theoretical formula: `x * y / (M * (L - M) * x + M ^ 2 * y)`
 * - implemented formula: `x * z ^ 2 / ((A * y + B * z) * (A * y + B * z - A * x))`
 *
 * fee scheme:
 * +-------------------+---------------------------------+---------------------------------+
 * | trade function    | trader transfers to contract    | contract transfers to trader    |
 * +-------------------+---------------------------------+---------------------------------+
 * | bySourceAmount(x) | trader transfers to contract: x | p = expectedTargetAmount(x)     |
 * |                   |                                 | q = p * (100 - fee%) / 100      |
 * |                   |                                 | contract transfers to trader: q |
 * |                   |                                 | contract retains as fee: p - q  |
 * +-------------------+---------------------------------+---------------------------------+
 * | byTargetAmount(x) | p = requiredSourceAmount(x)     | contract transfers to trader: x |
 * |                   | q = p * 100 / (100 - fee%)      |                                 |
 * |                   | trader transfers to contract: q |                                 |
 * |                   | contract retains as fee: q - p  |                                 |
 * +-------------------+---------------------------------+---------------------------------+
 */

// solhint-disable var-name-mixedcase
struct Order {
    uint128 y;
    uint128 z;
    uint64 A;
    uint64 B;
}
// solhint-enable var-name-mixedcase

struct TradeTokens {
    Token source;
    Token target;
}

struct Strategy {
    uint256 id;
    address owner;
    Token[2] tokens;
    Order[2] orders;
}

struct TradeAction {
    uint256 strategyId;
    uint128 amount;
}

// strategy update reasons
uint8 constant STRATEGY_UPDATE_REASON_EDIT = 0;
uint8 constant STRATEGY_UPDATE_REASON_TRADE = 1;

abstract contract Strategies is Initializable {
    using EnumerableSetUpgradeable for EnumerableSetUpgradeable.UintSet;
    using Address for address payable;
    using SafeCast for uint256;

    error NativeAmountMismatch();
    error BalanceMismatch();
    error GreaterThanMaxInput();
    error LowerThanMinReturn();
    error InsufficientCapacity();
    error InsufficientLiquidity();
    error InvalidRate();
    error InvalidTradeActionStrategyId();
    error InvalidTradeActionAmount();
    error OrderDisabled();
    error OutDated();

    struct SourceAndTargetAmounts {
        uint128 sourceAmount;
        uint128 targetAmount;
    }

    struct TradeParams {
        address trader;
        TradeTokens tokens;
        bool byTargetAmount;
        uint128 constraint;
        uint256 txValue;
        Pair pair;
        uint128 sourceAmount;
        uint128 targetAmount;
    }

    uint256 private constant ONE = 1 << 48;

    uint256 private constant ORDERS_INVERTED_FLAG = 1 << 255;

    uint32 private constant DEFAULT_TRADING_FEE_PPM = 4000; // 0.4%

    // total number of strategies
    uint128 private _strategyCounter;

    // the global trading fee (in units of PPM)
    uint32 internal _tradingFeePPM;

    // mapping between a strategy to its packed orders
    mapping(uint256 => uint256[3]) private _packedOrdersByStrategyId;

    // mapping between a pair id to its strategies ids
    mapping(uint128 => EnumerableSetUpgradeable.UintSet) private _strategyIdsByPairIdStorage;

    // accumulated fees per token
    mapping(Token => uint256) internal _accumulatedFees;

    // mapping between a pair id to its custom trading fee (in units of PPM)
    mapping(uint128 pairId => uint32 fee) internal _customTradingFeePPM;

    // upgrade forward-compatibility storage gap
    uint256[MAX_GAP - 5] private __gap;

    /**
     * @dev triggered when the network fee is updated
     */
    event TradingFeePPMUpdated(uint32 prevFeePPM, uint32 newFeePPM);

    /**
     * @dev triggered when the custom trading fee for a given pair is updated
     */
    event PairTradingFeePPMUpdated(Token indexed token0, Token indexed token1, uint32 prevFeePPM, uint32 newFeePPM);

    /**
     * @dev triggered when a strategy is created
     */
    event StrategyCreated(
        uint256 id,
        address indexed owner,
        Token indexed token0,
        Token indexed token1,
        Order order0,
        Order order1
    );

    /**
     * @dev triggered when a strategy is deleted
     */
    event StrategyDeleted(
        uint256 id,
        address indexed owner,
        Token indexed token0,
        Token indexed token1,
        Order order0,
        Order order1
    );

    /**
     * @dev triggered when a strategy is updated
     */
    event StrategyUpdated(
        uint256 indexed id,
        Token indexed token0,
        Token indexed token1,
        Order order0,
        Order order1,
        uint8 reason
    );

    /**
     * @dev triggered when tokens are traded
     */
    event TokensTraded(
        address indexed trader,
        Token indexed sourceToken,
        Token indexed targetToken,
        uint256 sourceAmount,
        uint256 targetAmount,
        uint128 tradingFeeAmount,
        bool byTargetAmount
    );

    /**
     * @dev triggered when fees are withdrawn
     */
    event FeesWithdrawn(Token indexed token, address indexed recipient, uint256 indexed amount, address sender);

    // solhint-disable func-name-mixedcase
    /**
     * @dev initializes the contract and its parents
     */
    function __Strategies_init() internal onlyInitializing {
        __Strategies_init_unchained();
    }

    /**
     * @dev performs contract-specific initialization
     */
    function __Strategies_init_unchained() internal onlyInitializing {
        _setTradingFeePPM(DEFAULT_TRADING_FEE_PPM);
    }

    // solhint-enable func-name-mixedcase

    /**
     * @dev creates a new strategy
     */
    function _createStrategy(
        IVoucher voucher,
        Token[2] memory tokens,
        Order[2] calldata orders,
        Pair memory pair,
        address owner,
        uint256 value
    ) internal returns (uint256) {
        // transfer funds
        _validateDepositAndRefundExcessNativeToken(tokens[0], owner, orders[0].y, value, true);
        _validateDepositAndRefundExcessNativeToken(tokens[1], owner, orders[1].y, value, true);

        // store id
        uint128 counter = _strategyCounter + 1;
        _strategyCounter = counter;
        uint256 id = _strategyId(pair.id, counter);
        _strategyIdsByPairIdStorage[pair.id].add(id);

        // store orders
        bool ordersInverted = tokens[0] == pair.tokens[1];
        _packedOrdersByStrategyId[id] = _packOrders(orders, ordersInverted);

        // mint voucher
        voucher.mint(owner, id);

        // emit event
        emit StrategyCreated({
            id: id,
            owner: owner,
            token0: tokens[0],
            token1: tokens[1],
            order0: orders[0],
            order1: orders[1]
        });

        return id;
    }

    /**
     * @dev updates an existing strategy
     */
    function _updateStrategy(
        uint256 strategyId,
        Order[2] calldata currentOrders,
        Order[2] calldata newOrders,
        Pair memory pair,
        address owner,
        uint256 value
    ) internal {
        // prepare storage variable
        uint256[3] storage packedOrders = _packedOrdersByStrategyId[strategyId];
        uint256[3] memory packedOrdersMemory = packedOrders;
        (Order[2] memory orders, bool ordersInverted) = _unpackOrders(packedOrdersMemory);

        // revert if the strategy mutated since this tx was sent
        if (!_equalStrategyOrders(currentOrders, orders)) {
            revert OutDated();
        }

        // store new values if necessary
        uint256[3] memory newPackedOrders = _packOrders(newOrders, ordersInverted);
        if (packedOrdersMemory[0] != newPackedOrders[0]) {
            packedOrders[0] = newPackedOrders[0];
        }
        if (packedOrdersMemory[1] != newPackedOrders[1]) {
            packedOrders[1] = newPackedOrders[1];
        }
        if (packedOrdersMemory[2] != newPackedOrders[2]) {
            packedOrders[2] = newPackedOrders[2];
        }

        // deposit and withdraw
        Token[2] memory sortedTokens = _sortStrategyTokens(pair, ordersInverted);
        for (uint256 i = 0; i < 2; i = uncheckedInc(i)) {
            Token token = sortedTokens[i];
            if (newOrders[i].y < orders[i].y) {
                // liquidity decreased - withdraw the difference
                uint128 delta = orders[i].y - newOrders[i].y;
                _withdrawFunds(token, payable(owner), delta);
            } else if (newOrders[i].y > orders[i].y) {
                // liquidity increased - deposit the difference
                uint128 delta = newOrders[i].y - orders[i].y;
                _validateDepositAndRefundExcessNativeToken(token, owner, delta, value, true);
            }

            // refund native token when there's no deposit in the order
            // note that deposit handles refunds internally
            if (value > 0 && token.isNative() && newOrders[i].y <= orders[i].y) {
                payable(address(owner)).sendValue(value);
            }
        }

        // emit event
        emit StrategyUpdated({
            id: strategyId,
            token0: sortedTokens[0],
            token1: sortedTokens[1],
            order0: newOrders[0],
            order1: newOrders[1],
            reason: STRATEGY_UPDATE_REASON_EDIT
        });
    }

    /**
     * @dev deletes a strategy
     */
    function _deleteStrategy(uint256 strategyId, IVoucher voucher, Pair memory pair) internal {
        Strategy memory strategy = _strategy(strategyId, voucher, pair);

        // burn the voucher nft token
        voucher.burn(strategy.id);

        // clear storage
        delete _packedOrdersByStrategyId[strategy.id];
        _strategyIdsByPairIdStorage[pair.id].remove(strategy.id);

        // withdraw funds
        _withdrawFunds(strategy.tokens[0], payable(strategy.owner), strategy.orders[0].y);
        _withdrawFunds(strategy.tokens[1], payable(strategy.owner), strategy.orders[1].y);

        // emit event
        emit StrategyDeleted({
            id: strategy.id,
            owner: strategy.owner,
            token0: strategy.tokens[0],
            token1: strategy.tokens[1],
            order0: strategy.orders[0],
            order1: strategy.orders[1]
        });
    }

    /**
     * @dev perform trade, update affected strategies
     *
     * requirements:
     *
     * - the caller must have approved the source token
     */
    function _trade(TradeAction[] calldata tradeActions, TradeParams memory params) internal {
        bool isTargetToken0 = params.tokens.target == params.pair.tokens[0];

        // process trade actions
        for (uint256 i = 0; i < tradeActions.length; i = uncheckedInc(i)) {
            // prepare variables
            uint128 amount = tradeActions[i].amount;
            uint256 strategyId = tradeActions[i].strategyId;
            uint256[3] storage packedOrders = _packedOrdersByStrategyId[strategyId];
            uint256[3] memory packedOrdersMemory = packedOrders;
            (Order[2] memory orders, bool ordersInverted) = _unpackOrders(packedOrdersMemory);

            _validateTradeParams(params.pair.id, strategyId, amount);

            (Order memory targetOrder, Order memory sourceOrder) = isTargetToken0 == ordersInverted
                ? (orders[1], orders[0])
                : (orders[0], orders[1]);

            // calculate the orders new values
            (uint128 sourceAmount, uint128 targetAmount) = _singleTradeActionSourceAndTargetAmounts(
                targetOrder,
                amount,
                params.byTargetAmount
            );

            // handled specifically for a custom error message
            if (targetOrder.y < targetAmount) {
                revert InsufficientLiquidity();
            }

            // update the orders with the new values
            // safe since it's checked above
            unchecked {
                targetOrder.y -= targetAmount;
            }

            sourceOrder.y += sourceAmount;
            if (sourceOrder.z < sourceOrder.y) {
                sourceOrder.z = sourceOrder.y;
            }

            // store new values if necessary
            uint256[3] memory newPackedOrders = _packOrders(orders, ordersInverted);

            // both y values are in slot 0, so it has definitely changed
            packedOrders[0] = newPackedOrders[0];

            // one of the z values is in slot 1, so it has possibly changed
            if (packedOrdersMemory[1] != newPackedOrders[1]) {
                packedOrders[1] = newPackedOrders[1];
            }

            // the other z value has possibly changed only if the first one hasn't
            if (packedOrdersMemory[2] != newPackedOrders[2]) {
                packedOrders[2] = newPackedOrders[2];
            }

            // emit update event
            emit StrategyUpdated({
                id: strategyId,
                token0: params.pair.tokens[ordersInverted ? 1 : 0],
                token1: params.pair.tokens[ordersInverted ? 0 : 1],
                order0: orders[0],
                order1: orders[1],
                reason: STRATEGY_UPDATE_REASON_TRADE
            });

            params.sourceAmount += sourceAmount;
            params.targetAmount += targetAmount;
        }

        // apply trading fee
        uint128 tradingFeeAmount;
        if (params.byTargetAmount) {
            uint128 amountIncludingFee = _addFee(params.sourceAmount, params.pair.id);
            tradingFeeAmount = amountIncludingFee - params.sourceAmount;
            params.sourceAmount = amountIncludingFee;
            if (params.sourceAmount > params.constraint) {
                revert GreaterThanMaxInput();
            }
            _accumulatedFees[params.tokens.source] += tradingFeeAmount;
        } else {
            uint128 amountExcludingFee = _subtractFee(params.targetAmount, params.pair.id);
            tradingFeeAmount = params.targetAmount - amountExcludingFee;
            params.targetAmount = amountExcludingFee;
            if (params.targetAmount < params.constraint) {
                revert LowerThanMinReturn();
            }
            _accumulatedFees[params.tokens.target] += tradingFeeAmount;
        }

        // transfer funds
        _validateDepositAndRefundExcessNativeToken(
            params.tokens.source,
            params.trader,
            params.sourceAmount,
            params.txValue,
            false
        );
        _withdrawFunds(params.tokens.target, payable(params.trader), params.targetAmount);

        // tokens traded successfully, emit event
        emit TokensTraded({
            trader: params.trader,
            sourceToken: params.tokens.source,
            targetToken: params.tokens.target,
            sourceAmount: params.sourceAmount,
            targetAmount: params.targetAmount,
            tradingFeeAmount: tradingFeeAmount,
            byTargetAmount: params.byTargetAmount
        });
    }

    /**
     * @dev calculates the required amount plus fee
     */
    function _addFee(uint128 amount, uint128 pairId) private view returns (uint128) {
        uint32 tradingFeePPM = _getPairTradingFeePPM(pairId);
        // divide the input amount by `1 - fee`
        return MathEx.mulDivC(amount, PPM_RESOLUTION, PPM_RESOLUTION - tradingFeePPM).toUint128();
    }

    /**
     * @dev calculates the expected amount minus fee
     */
    function _subtractFee(uint128 amount, uint128 pairId) private view returns (uint128) {
        uint32 tradingFeePPM = _getPairTradingFeePPM(pairId);
        // multiply the input amount by `1 - fee`
        return MathEx.mulDivF(amount, PPM_RESOLUTION - tradingFeePPM, PPM_RESOLUTION).toUint128();
    }

    /**
     * @dev get the custom trading fee ppm for a given pair (returns default trading fee if not set for pair)
     */
    function _getPairTradingFeePPM(uint128 pairId) internal view returns (uint32) {
        uint32 customTradingFeePPM = _customTradingFeePPM[pairId];
        return customTradingFeePPM == 0 ? _tradingFeePPM : customTradingFeePPM;
    }

    /**
     * @dev calculates and returns the total source and target amounts of a trade, including fees
     */
    function _tradeSourceAndTargetAmounts(
        TradeTokens memory tokens,
        TradeAction[] calldata tradeActions,
        Pair memory pair,
        bool byTargetAmount
    ) internal view returns (SourceAndTargetAmounts memory totals) {
        bool isTargetToken0 = tokens.target == pair.tokens[0];

        // process trade actions
        for (uint256 i = 0; i < tradeActions.length; i = uncheckedInc(i)) {
            // prepare variables
            uint128 amount = tradeActions[i].amount;
            uint256 strategyId = tradeActions[i].strategyId;
            uint256[3] memory packedOrdersMemory = _packedOrdersByStrategyId[strategyId];
            (Order[2] memory orders, bool ordersInverted) = _unpackOrders(packedOrdersMemory);

            _validateTradeParams(pair.id, strategyId, amount);

            Order memory targetOrder = isTargetToken0 == ordersInverted ? orders[1] : orders[0];

            // calculate the orders new values
            (uint128 sourceAmount, uint128 targetAmount) = _singleTradeActionSourceAndTargetAmounts(
                targetOrder,
                amount,
                byTargetAmount
            );

            // update totals
            totals.sourceAmount += sourceAmount;
            totals.targetAmount += targetAmount;
        }

        // apply trading fee
        if (byTargetAmount) {
            totals.sourceAmount = _addFee(totals.sourceAmount, pair.id);
        } else {
            totals.targetAmount = _subtractFee(totals.targetAmount, pair.id);
        }
    }

    /**
     * @dev returns stored strategies of a pair
     */
    function _strategiesByPair(
        Pair memory pair,
        uint256 startIndex,
        uint256 endIndex,
        IVoucher voucher
    ) internal view returns (Strategy[] memory) {
        EnumerableSetUpgradeable.UintSet storage strategyIds = _strategyIdsByPairIdStorage[pair.id];
        uint256 allLength = strategyIds.length();

        // when the endIndex is 0 or out of bound, set the endIndex to the last value possible
        if (endIndex == 0 || endIndex > allLength) {
            endIndex = allLength;
        }

        // revert when startIndex is out of bound
        if (startIndex > endIndex) {
            revert InvalidIndices();
        }

        // populate the result
        uint256 resultLength = endIndex - startIndex;
        Strategy[] memory result = new Strategy[](resultLength);
        for (uint256 i = 0; i < resultLength; i = uncheckedInc(i)) {
            uint256 strategyId = strategyIds.at(startIndex + i);
            result[i] = _strategy(strategyId, voucher, pair);
        }

        return result;
    }

    /**
     * @dev returns the count of stored strategies of a pair
     */
    function _strategiesByPairCount(Pair memory pair) internal view returns (uint256) {
        EnumerableSetUpgradeable.UintSet storage strategyIds = _strategyIdsByPairIdStorage[pair.id];
        return strategyIds.length();
    }

    /**
     @dev returns a strategy object matching the provided id.
     */
    function _strategy(uint256 id, IVoucher voucher, Pair memory pair) internal view returns (Strategy memory) {
        // fetch data
        address _owner = voucher.ownerOf(id);
        uint256[3] memory packedOrdersMemory = _packedOrdersByStrategyId[id];
        (Order[2] memory orders, bool ordersInverted) = _unpackOrders(packedOrdersMemory);

        // handle sorting
        Token[2] memory sortedTokens = _sortStrategyTokens(pair, ordersInverted);

        return Strategy({ id: id, owner: _owner, tokens: sortedTokens, orders: orders });
    }

    /**
     * @dev validates deposit amounts, refunds excess native tokens sent
     */
    function _validateDepositAndRefundExcessNativeToken(
        Token token,
        address owner,
        uint256 depositAmount,
        uint256 txValue,
        bool validateDepositAmount
    ) private {
        if (token.isNative()) {
            if (txValue < depositAmount) {
                revert NativeAmountMismatch();
            }

            // refund the owner for the remaining native token amount
            if (txValue > depositAmount) {
                payable(address(owner)).sendValue(txValue - depositAmount);
            }
        } else if (depositAmount > 0) {
            if (validateDepositAmount) {
                uint256 prevBalance = token.balanceOf(address(this));
                token.safeTransferFrom(owner, address(this), depositAmount);
                uint256 newBalance = token.balanceOf(address(this));
                if (newBalance - prevBalance != depositAmount) {
                    revert BalanceMismatch();
                }
            } else {
                token.safeTransferFrom(owner, address(this), depositAmount);
            }
        }
    }

    function _validateTradeParams(uint128 pairId, uint256 strategyId, uint128 tradeAmount) private pure {
        // make sure the strategy id matches the pair id
        if (_pairIdByStrategyId(strategyId) != pairId) {
            revert InvalidTradeActionStrategyId();
        }

        // make sure the trade amount is nonzero
        if (tradeAmount == 0) {
            revert InvalidTradeActionAmount();
        }
    }

    /**
     * @dev sets the trading fee (in units of PPM)
     */
    function _setTradingFeePPM(uint32 newTradingFeePPM) internal {
        uint32 prevTradingFeePPM = _tradingFeePPM;
        if (prevTradingFeePPM == newTradingFeePPM) {
            return;
        }

        _tradingFeePPM = newTradingFeePPM;

        emit TradingFeePPMUpdated({ prevFeePPM: prevTradingFeePPM, newFeePPM: newTradingFeePPM });
    }

    /**
     * @dev sets the custom trading fee for a given pair (in units of PPM)
     */
    function _setPairTradingFeePPM(Pair memory pair, uint32 newCustomTradingFeePPM) internal {
        uint32 prevCustomTradingFeePPM = _customTradingFeePPM[pair.id];
        if (prevCustomTradingFeePPM == newCustomTradingFeePPM) {
            return;
        }

        _customTradingFeePPM[pair.id] = newCustomTradingFeePPM;

        emit PairTradingFeePPMUpdated({
            token0: pair.tokens[0],
            token1: pair.tokens[1],
            prevFeePPM: prevCustomTradingFeePPM,
            newFeePPM: newCustomTradingFeePPM
        });
    }

    /**
     * returns true if the provided orders are equal, false otherwise
     */
    function _equalStrategyOrders(Order[2] memory orders0, Order[2] memory orders1) internal pure returns (bool) {
        uint256 i;
        for (i = 0; i < 2; i = uncheckedInc(i)) {
            if (
                orders0[i].y != orders1[i].y ||
                orders0[i].z != orders1[i].z ||
                orders0[i].A != orders1[i].A ||
                orders0[i].B != orders1[i].B
            ) {
                return false;
            }
        }
        return true;
    }

    // solhint-disable var-name-mixedcase

    /**
     * @dev returns:
     *
     *      x * (A * y + B * z) ^ 2
     * ---------------------------------
     *  A * x * (A * y + B * z) + z ^ 2
     *
     */
    function _calculateTradeTargetAmount(
        uint256 x, // < 2 ^ 128
        uint256 y, // < 2 ^ 128
        uint256 z, // < 2 ^ 128
        uint256 A, // < 2 ^ 96
        uint256 B /// < 2 ^ 96
    ) private pure returns (uint256) {
        if (A == 0) {
            if (B == 0) {
                revert OrderDisabled();
            }
            return MathEx.mulDivF(x, B * B, ONE * ONE);
        }

        uint256 temp1;
        uint256 temp2;
        unchecked {
            temp1 = z * ONE; // < 2 ^ 176
            temp2 = y * A + z * B; // < 2 ^ 225
        }
        uint256 temp3 = temp2 * x;

        uint256 factor1 = MathEx.minFactor(temp1, temp1);
        uint256 factor2 = MathEx.minFactor(temp3, A);
        uint256 factor = Math.max(factor1, factor2);

        uint256 temp4 = MathEx.mulDivC(temp1, temp1, factor);
        uint256 temp5 = MathEx.mulDivC(temp3, A, factor);

        (bool safe, uint256 sum) = SafeMath.tryAdd(temp4, temp5);
        if (safe) {
            return MathEx.mulDivF(temp2, temp3 / factor, sum);
        }
        return temp2 / (A + MathEx.mulDivC(temp1, temp1, temp3));
    }

    /**
     * @dev returns:
     *
     *                  x * z ^ 2
     * -------------------------------------------
     *  (A * y + B * z) * (A * y + B * z - A * x)
     *
     */
    function _calculateTradeSourceAmount(
        uint256 x, // < 2 ^ 128
        uint256 y, // < 2 ^ 128
        uint256 z, // < 2 ^ 128
        uint256 A, // < 2 ^ 96
        uint256 B /// < 2 ^ 96
    ) private pure returns (uint256) {
        if (A == 0) {
            if (B == 0) {
                revert OrderDisabled();
            }
            return MathEx.mulDivC(x, ONE * ONE, B * B);
        }

        uint256 temp1;
        uint256 temp2;
        unchecked {
            temp1 = z * ONE; // < 2 ^ 176
            temp2 = y * A + z * B; // < 2 ^ 225
        }
        uint256 temp3 = temp2 - x * A;

        uint256 factor1 = MathEx.minFactor(temp1, temp1);
        uint256 factor2 = MathEx.minFactor(temp2, temp3);
        uint256 factor = Math.max(factor1, factor2);

        uint256 temp4 = MathEx.mulDivC(temp1, temp1, factor);
        uint256 temp5 = MathEx.mulDivF(temp2, temp3, factor);
        return MathEx.mulDivC(x, temp4, temp5);
    }

    // solhint-enable var-name-mixedcase

    /**
     * @dev pack 2 orders into a 3 slot uint256 data structure
     */
    function _packOrders(Order[2] memory orders, bool ordersInverted) private pure returns (uint256[3] memory values) {
        values = [
            uint256((uint256(orders[0].y) << 0) | (uint256(orders[1].y) << 128)),
            uint256((uint256(orders[0].z) << 0) | (uint256(orders[0].A) << 128) | (uint256(orders[0].B) << 192)),
            uint256(
                (uint256(orders[1].z) << 0) |
                    (uint256(orders[1].A) << 128) |
                    (uint256(orders[1].B) << 192) |
                    (ordersInverted ? ORDERS_INVERTED_FLAG : 0)
            )
        ];
    }

    /**
     * @dev unpack 2 stored orders into an array of Order types
     */
    function _unpackOrders(
        uint256[3] memory values
    ) private pure returns (Order[2] memory orders, bool ordersInverted) {
        orders = [
            Order({
                y: uint128(values[0] >> 0),
                z: uint128(values[1] >> 0),
                A: uint64(values[1] >> 128),
                B: uint64(values[1] >> 192)
            }),
            Order({
                y: uint128(values[0] >> 128),
                z: uint128(values[2] >> 0),
                A: uint64(values[2] >> 128),
                B: uint64((values[2] << 1) >> 193)
            })
        ];
        ordersInverted = values[2] >= ORDERS_INVERTED_FLAG;
    }

    /**
     * @dev expand a given rate
     */
    function _expandRate(uint256 rate) internal pure returns (uint256) {
        // safe because no `+` or `-` or `*`
        unchecked {
            return (rate % ONE) << (rate / ONE);
        }
    }

    /**
     * @dev validates a given rate
     */
    function _validRate(uint256 rate) internal pure returns (bool) {
        // safe because no `+` or `-` or `*`
        unchecked {
            return (ONE >> (rate / ONE)) > 0;
        }
    }

    /**
     * @dev returns the source and target amounts of a single trade action
     */
    function _singleTradeActionSourceAndTargetAmounts(
        Order memory order,
        uint128 amount,
        bool byTargetAmount
    ) internal pure returns (uint128 sourceAmount, uint128 targetAmount) {
        uint256 y = uint256(order.y);
        uint256 z = uint256(order.z);
        uint256 a = _expandRate(uint256(order.A));
        uint256 b = _expandRate(uint256(order.B));
        if (byTargetAmount) {
            sourceAmount = _calculateTradeSourceAmount(amount, y, z, a, b).toUint128();
            targetAmount = amount;
        } else {
            sourceAmount = amount;
            targetAmount = _calculateTradeTargetAmount(amount, y, z, a, b).toUint128();
        }
    }

    /**
     * revert if any of the orders is invalid
     */
    function _validateOrders(Order[2] calldata orders) internal pure {
        for (uint256 i = 0; i < 2; i = uncheckedInc(i)) {
            if (orders[i].z < orders[i].y) {
                revert InsufficientCapacity();
            }
            if (!_validRate(orders[i].A)) {
                revert InvalidRate();
            }
            if (!_validRate(orders[i].B)) {
                revert InvalidRate();
            }
        }
    }

    /**
     * returns the strategyId for a given pairId and a given strategyIndex
     */
    function _strategyId(uint128 pairId, uint128 strategyIndex) internal pure returns (uint256) {
        return (uint256(pairId) << 128) | strategyIndex;
    }

    /**
     * returns the pairId associated with a given strategyId
     */
    function _pairIdByStrategyId(uint256 strategyId) internal pure returns (uint128) {
        return uint128(strategyId >> 128);
    }

    function _withdrawFees(address sender, uint256 amount, Token token, address recipient) internal returns (uint256) {
        uint256 accumulatedAmount = _accumulatedFees[token];
        if (accumulatedAmount == 0) {
            return 0;
        }
        if (amount > accumulatedAmount) {
            amount = accumulatedAmount;
        }

        _accumulatedFees[token] = accumulatedAmount - amount;
        _withdrawFunds(token, payable(recipient), amount);
        emit FeesWithdrawn(token, recipient, amount, sender);
        return amount;
    }

    /**
     * returns tokens sorted accordingly to a strategy orders inversion
     */
    function _sortStrategyTokens(Pair memory pair, bool ordersInverted) private pure returns (Token[2] memory) {
        return ordersInverted ? [pair.tokens[1], pair.tokens[0]] : pair.tokens;
    }

    /**
     * sends erc20 or native token to the provided target
     */
    function _withdrawFunds(Token token, address payable target, uint256 amount) private {
        if (amount == 0) {
            return;
        }

        if (token.isNative()) {
            // using a regular transfer here would revert due to exceeding the 2300 gas limit which is why we're using
            // call instead (via sendValue), which the 2300 gas limit does not apply for
            target.sendValue(amount);
        } else {
            token.safeTransfer(target, amount);
        }
    }

    function uncheckedInc(uint256 i) private pure returns (uint256 j) {
        unchecked {
            j = i + 1;
        }
    }
}

File 29 of 39 : ICarbonController.sol
// SPDX-License-Identifier: SEE LICENSE IN LICENSE
pragma solidity ^0.8.0;

import { IUpgradeable } from "../../utility/interfaces/IUpgradeable.sol";
import { Pair } from "../Pairs.sol";
import { Token } from "../../token/Token.sol";
import { Strategy, TradeAction, Order } from "../Strategies.sol";

/**
 * @dev Carbon Controller interface
 */
interface ICarbonController is IUpgradeable {
    /**
     * @dev returns the type of the controller
     */
    function controllerType() external pure returns (uint16);

    /**
     * @dev returns the trading fee (in units of PPM)
     */
    function tradingFeePPM() external view returns (uint32);

    /**
     * @dev returns the trading fee for a given pair (in units of PPM)
     */
    function pairTradingFeePPM(Token token0, Token token1) external view returns (uint32);

    /**
     * @dev creates a new pair of provided token0 and token1
     */
    function createPair(Token token0, Token token1) external returns (Pair memory);

    /**
     * @dev returns a pair's metadata matching the provided token0 and token1
     */
    function pair(Token token0, Token token1) external view returns (Pair memory);

    /**
     * @dev returns a list of all supported pairs
     */
    function pairs() external view returns (Token[2][] memory);

    // solhint-disable var-name-mixedcase
    /**
     * @dev creates a new strategy, returns the strategy's id
     *
     * requirements:
     *
     * - the caller must have approved the tokens with assigned liquidity in the order, if any
     */
    function createStrategy(Token token0, Token token1, Order[2] calldata orders) external payable returns (uint256);

    /**
     * @dev updates an existing strategy
     *
     * notes:
     * - currentOrders should reflect the orders values at the time of sending the tx
     * this prevents cases in which the strategy was updated due to a trade between
     * the time the transaction was sent and the time it was mined, thus, giving more
     * control to the strategy owner.
     * - reduced liquidity is refunded to the owner
     * - increased liquidity is deposited
     * - excess native token is returned to the sender if any
     * - the sorting of orders is expected to equal the sorting upon creation
     *
     * requirements:
     *
     * - the caller must have approved the tokens with increased liquidity, if any
     */
    function updateStrategy(
        uint256 strategyId,
        Order[2] calldata currentOrders,
        Order[2] calldata newOrders
    ) external payable;

    // solhint-enable var-name-mixedcase

    /**
     * @dev deletes a strategy matching the provided id
     *
     * notes:
     *
     * - 100% of liquidity is withdrawn and sent to the owner
     *
     * requirements:
     *
     * - the caller must be the owner of the NFT voucher
     */
    function deleteStrategy(uint256 strategyId) external;

    /**
     * @dev returns a strategy matching the provided id,
     * note tokens and orders are returned sorted as provided upon creation
     */
    function strategy(uint256 id) external view returns (Strategy memory);

    /**
     * @dev returns strategies belonging to a specific pair
     * note that for the full list of strategies pass 0 to both startIndex and endIndex
     */
    function strategiesByPair(
        Token token0,
        Token token1,
        uint256 startIndex,
        uint256 endIndex
    ) external view returns (Strategy[] memory);

    /**
     * @dev returns the count of strategies belonging to a specific pair
     */
    function strategiesByPairCount(Token token0, Token token1) external view returns (uint256);

    /**
     * @dev performs a trade by specifying a fixed source amount
     *
     * notes:
     *
     * - excess native token is returned to the sender if any
     *
     * requirements:
     *
     * - the caller must have approved the source token
     */
    function tradeBySourceAmount(
        Token sourceToken,
        Token targetToken,
        TradeAction[] calldata tradeActions,
        uint256 deadline,
        uint128 minReturn
    ) external payable returns (uint128);

    /**
     * @dev performs a trade by specifying a fixed target amount
     *
     * notes:
     *
     * - excess native token is returned to the sender if any
     *
     * requirements:
     *
     * - the caller must have approved the source token
     */
    function tradeByTargetAmount(
        Token sourceToken,
        Token targetToken,
        TradeAction[] calldata tradeActions,
        uint256 deadline,
        uint128 maxInput
    ) external payable returns (uint128);

    /**
     * @dev returns the source amount required when trading by target amount
     */
    function calculateTradeSourceAmount(
        Token sourceToken,
        Token targetToken,
        TradeAction[] calldata tradeActions
    ) external view returns (uint128);

    /**
     * @dev returns the target amount expected when trading by source amount
     */
    function calculateTradeTargetAmount(
        Token sourceToken,
        Token targetToken,
        TradeAction[] calldata tradeActions
    ) external view returns (uint128);

    /**
     * @dev returns the amount of fees accumulated for the specified token
     */
    function accumulatedFees(Token token) external view returns (uint256);

    /**
     * @dev transfers the accumulated fees to the specified recipient
     *
     * notes:
     * `amount` is capped to the available amount
     * returns the amount withdrawn
     */
    function withdrawFees(Token token, uint256 amount, address recipient) external returns (uint256);
}

File 30 of 39 : Token.sol
// SPDX-License-Identifier: SEE LICENSE IN LICENSE
pragma solidity 0.8.19;

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

/**
 * @dev This type implements ERC20 and SafeERC20 utilities for both the native token and for ERC20 tokens
 */
type Token is address;
using SafeERC20 for IERC20;
using Address for address payable;

// the address that represents the native token reserve
address constant NATIVE_TOKEN_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;

// the symbol that represents the native token
string constant NATIVE_TOKEN_SYMBOL = "ETH";

// the decimals for the native token
uint8 constant NATIVE_TOKEN_DECIMALS = 18;

// the token representing the native token
Token constant NATIVE_TOKEN = Token.wrap(NATIVE_TOKEN_ADDRESS);

using {
    equal as ==,
    notEqual as !=,
    isNative,
    symbol,
    decimals,
    balanceOf,
    allowance,
    safeTransfer,
    safeTransferFrom,
    safeApprove,
    forceApprove,
    safeIncreaseAllowance,
    unsafeTransfer,
    toIERC20
} for Token global;

/* solhint-disable func-visibility */

function equal(Token a, Token b) pure returns (bool) {
    return Token.unwrap(a) == Token.unwrap(b);
}

function notEqual(Token a, Token b) pure returns (bool) {
    return Token.unwrap(a) != Token.unwrap(b);
}

/**
 * @dev returns whether the provided token represents an ERC20 or the native token reserve
 */
function isNative(Token token) pure returns (bool) {
    return token == NATIVE_TOKEN;
}

/**
 * @dev returns the symbol of the native token/ERC20 token
 */
function symbol(Token token) view returns (string memory) {
    if (isNative(token)) {
        return NATIVE_TOKEN_SYMBOL;
    }
    return toERC20(token).symbol();
}

/**
 * @dev returns the decimals of the native token/ERC20 token
 */
function decimals(Token token) view returns (uint8) {
    if (isNative(token)) {
        return NATIVE_TOKEN_DECIMALS;
    }
    return toERC20(token).decimals();
}

/**
 * @dev returns the balance of the native token/ERC20 token
 */
function balanceOf(Token token, address account) view returns (uint256) {
    if (isNative(token)) {
        return account.balance;
    }
    return toIERC20(token).balanceOf(account);
}

/**
 * @dev returns the allowance of an `owner` to a `spender`
 */
function allowance(Token token, address owner, address spender) view returns (uint256) {
    if (isNative(token)) {
        return 0;
    }
    return toIERC20(token).allowance(owner, spender);
}

/**
 * @dev transfers a specific amount of the native token/ERC20 token
 */
function safeTransfer(Token token, address to, uint256 amount) {
    if (amount == 0) {
        return;
    }
    if (isNative(token)) {
        payable(to).transfer(amount);
    } else {
        toIERC20(token).safeTransfer(to, amount);
    }
}

/**
 * @dev transfers a specific amount of the native token/ERC20 token from a specific holder using the allowance mechanism
 *
 * note that the function does not perform any action if the native token is provided
 */
function safeTransferFrom(Token token, address from, address to, uint256 amount) {
    if (amount == 0 || isNative(token)) {
        return;
    }
    toIERC20(token).safeTransferFrom(from, to, amount);
}

/**
 * @dev approves a specific amount of the native token/ERC20 token from a specific holder
 *
 * note that the function does not perform any action if the native token is provided
 */
function safeApprove(Token token, address spender, uint256 amount) {
    if (isNative(token)) {
        return;
    }
    toIERC20(token).safeApprove(spender, amount);
}

/**
 * @dev force approves a specific amount of the native token/ERC20 token from a specific holder
 *
 * note that the function does not perform any action if the native token is provided
 */
function forceApprove(Token token, address spender, uint256 amount) {
    if (isNative(token)) {
        return;
    }

    toIERC20(token).forceApprove(spender, amount);
}

/**
 * @dev atomically increases the allowance granted to `spender` by the caller.
 *
 * note that the function does not perform any action if the native token is provided
 */
function safeIncreaseAllowance(Token token, address spender, uint256 amount) {
    if (isNative(token)) {
        return;
    }
    toIERC20(token).safeIncreaseAllowance(spender, amount);
}

/**
 * @dev transfers a specific amount of the native token/ERC20 token
 * @dev forwards all available gas if sending native token
 */
function unsafeTransfer(Token token, address to, uint256 amount) {
    if (amount == 0) {
        return;
    }

    if (isNative(token)) {
        payable(to).sendValue(amount);
    } else {
        toIERC20(token).safeTransfer(to, amount);
    }
}

/**
 * @dev utility function that converts a token to an IERC20
 */
function toIERC20(Token token) pure returns (IERC20) {
    return IERC20(Token.unwrap(token));
}

/**
 * @dev utility function that converts a token to an ERC20
 */
function toERC20(Token token) pure returns (ERC20) {
    return ERC20(Token.unwrap(token));
}

/* solhint-disable func-visibility */

File 31 of 39 : Constants.sol
// SPDX-License-Identifier: SEE LICENSE IN LICENSE
pragma solidity 0.8.19;

uint32 constant PPM_RESOLUTION = 1_000_000;

uint32 constant MAX_GAP = 50;

File 32 of 39 : Fraction.sol
// SPDX-License-Identifier: SEE LICENSE IN LICENSE
pragma solidity 0.8.19;

struct Fraction {
    uint256 n;
    uint256 d;
}

File 33 of 39 : MathEx.sol
// SPDX-License-Identifier: SEE LICENSE IN LICENSE
pragma solidity 0.8.19;

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

uint256 constant ONE = 0x80000000000000000000000000000000;
uint256 constant LN2 = 0x58b90bfbe8e7bcd5e4f1d9cc01f97b57;

/**
 * @dev this library provides a set of complex math operations
 */
library MathEx {
    error Overflow();

    /**
     * @dev returns the largest integer smaller than or equal to `x * y / z`
     */
    function mulDivF(uint256 x, uint256 y, uint256 z) internal pure returns (uint256) {
        // safe because no `+` or `-` or `*`
        unchecked {
            (uint256 xyhi, uint256 xylo) = _mul512(x, y);

            // if `x * y < 2 ^ 256`
            if (xyhi == 0) {
                return xylo / z;
            }

            // assert `x * y / z < 2 ^ 256`
            if (xyhi >= z) {
                revert Overflow();
            }

            uint256 m = _mulMod(x, y, z); // `m = x * y % z`
            (uint256 nhi, uint256 nlo) = _sub512(xyhi, xylo, m); // `n = x * y - m` hence `n / z = floor(x * y / z)`

            // if `n < 2 ^ 256`
            if (nhi == 0) {
                return nlo / z;
            }

            uint256 p = _unsafeSub(0, z) & z; // `p` is the largest power of 2 which `z` is divisible by
            uint256 q = _div512(nhi, nlo, p); // `n` is divisible by `p` because `n` is divisible by `z` and `z` is divisible by `p`
            uint256 r = _inv256(z / p); // `z / p = 1 mod 2` hence `inverse(z / p) = 1 mod 2 ^ 256`
            return _unsafeMul(q, r); // `q * r = (n / p) * inverse(z / p) = n / z`
        }
    }

    /**
     * @dev returns the smallest integer larger than or equal to `x * y / z`
     */
    function mulDivC(uint256 x, uint256 y, uint256 z) internal pure returns (uint256) {
        uint256 w = mulDivF(x, y, z);
        if (_mulMod(x, y, z) > 0) {
            if (w >= type(uint256).max) {
                revert Overflow();
            }
            unchecked {
                // safe because `w < type(uint256).max`
                return w + 1;
            }
        }
        return w;
    }

    /**
     * @dev returns the smallest integer `z` such that `x * y / z <= 2 ^ 256 - 1`
     */
    function minFactor(uint256 x, uint256 y) internal pure returns (uint256) {
        (uint256 hi, uint256 lo) = _mul512(x, y);
        unchecked {
            // safe because:
            // - if `x < 2 ^ 256 - 1` or `y < 2 ^ 256 - 1`
            //   then `hi < 2 ^ 256 - 2`
            //   hence neither `hi + 1` nor `hi + 2` overflows
            // - if `x = 2 ^ 256 - 1` and `y = 2 ^ 256 - 1`
            //   then `hi = 2 ^ 256 - 2 = ~lo`
            //   hence `hi + 1`, which does not overflow, is computed
            return hi > ~lo ? hi + 2 : hi + 1;
        }

        /* reasoning:
        |
        |   general:
        |   - find the smallest integer `z` such that `x * y / z <= 2 ^ 256 - 1`
        |   - the value of `x * y` is represented via `2 ^ 256 * hi + lo`
        |   - the expression `~lo` is equivalent to `2 ^ 256 - 1 - lo`
        |   
        |   symbols:
        |   - let `H` denote `hi`
        |   - let `L` denote `lo`
        |   - let `N` denote `2 ^ 256 - 1`
        |   
        |   inference:
        |   `x * y / z <= 2 ^ 256 - 1`     <-->
        |   `x * y / (2 ^ 256 - 1) <= z`   <-->
        |   `((N + 1) * H + L) / N <= z`   <-->
        |   `(N * H + H + L) / N <= z`     <-->
        |   `H + (H + L) / N <= z`
        |   
        |   inference:
        |   `0 <= H <= N && 0 <= L <= N`   <-->
        |   `0 <= H + L <= N + N`          <-->
        |   `0 <= H + L <= N * 2`          <-->
        |   `0 <= (H + L) / N <= 2`
        |   
        |   inference:
        |   - `0 = (H + L) / N` --> `H + L = 0` --> `x * y = 0` --> `z = 1 = H + 1`
        |   - `0 < (H + L) / N <= 1` --> `H + (H + L) / N <= H + 1` --> `z = H + 1`
        |   - `1 < (H + L) / N <= 2` --> `H + (H + L) / N <= H + 2` --> `z = H + 2`
        |   
        |   implementation:
        |   - if `hi > ~lo`:
        |     `~L < H <= N`                         <-->
        |     `N - L < H <= N`                      <-->
        |     `N < H + L <= N + L`                  <-->
        |     `1 < (H + L) / N <= 2`                <-->
        |     `H + 1 < H + (H + L) / N <= H + 2`    <-->
        |     `z = H + 2`
        |   - if `hi <= ~lo`:
        |     `H <= ~L`                             <-->
        |     `H <= N - L`                          <-->
        |     `H + L <= N`                          <-->
        |     `(H + L) / N <= 1`                    <-->
        |     `H + (H + L) / N <= H + 1`            <-->
        |     `z = H + 1`
        |
        */
    }

    /**
     * @dev returns `2 ^ f` by calculating `e ^ (f * ln(2))`, where `e` is Euler's number:
     * - Rewrite the input as a sum of binary exponents and a single residual r, as small as possible
     * - The exponentiation of each binary exponent is given (pre-calculated)
     * - The exponentiation of r is calculated via Taylor series for e^x, where x = r
     * - The exponentiation of the input is calculated by multiplying the intermediate results above
     * - For example: e^5.521692859 = e^(4 + 1 + 0.5 + 0.021692859) = e^4 * e^1 * e^0.5 * e^0.021692859
     */
    function exp2(Fraction memory f) internal pure returns (Fraction memory) {
        uint256 x = MathEx.mulDivF(LN2, f.n, f.d);
        uint256 y;
        uint256 z;
        uint256 n;

        if (x >= (ONE << 4)) {
            revert Overflow();
        }

        unchecked {
            z = y = x % (ONE >> 3); // get the input modulo 2^(-3)
            z = (z * y) / ONE;
            n += z * 0x10e1b3be415a0000; // add y^02 * (20! / 02!)
            z = (z * y) / ONE;
            n += z * 0x05a0913f6b1e0000; // add y^03 * (20! / 03!)
            z = (z * y) / ONE;
            n += z * 0x0168244fdac78000; // add y^04 * (20! / 04!)
            z = (z * y) / ONE;
            n += z * 0x004807432bc18000; // add y^05 * (20! / 05!)
            z = (z * y) / ONE;
            n += z * 0x000c0135dca04000; // add y^06 * (20! / 06!)
            z = (z * y) / ONE;
            n += z * 0x0001b707b1cdc000; // add y^07 * (20! / 07!)
            z = (z * y) / ONE;
            n += z * 0x000036e0f639b800; // add y^08 * (20! / 08!)
            z = (z * y) / ONE;
            n += z * 0x00000618fee9f800; // add y^09 * (20! / 09!)
            z = (z * y) / ONE;
            n += z * 0x0000009c197dcc00; // add y^10 * (20! / 10!)
            z = (z * y) / ONE;
            n += z * 0x0000000e30dce400; // add y^11 * (20! / 11!)
            z = (z * y) / ONE;
            n += z * 0x000000012ebd1300; // add y^12 * (20! / 12!)
            z = (z * y) / ONE;
            n += z * 0x0000000017499f00; // add y^13 * (20! / 13!)
            z = (z * y) / ONE;
            n += z * 0x0000000001a9d480; // add y^14 * (20! / 14!)
            z = (z * y) / ONE;
            n += z * 0x00000000001c6380; // add y^15 * (20! / 15!)
            z = (z * y) / ONE;
            n += z * 0x000000000001c638; // add y^16 * (20! / 16!)
            z = (z * y) / ONE;
            n += z * 0x0000000000001ab8; // add y^17 * (20! / 17!)
            z = (z * y) / ONE;
            n += z * 0x000000000000017c; // add y^18 * (20! / 18!)
            z = (z * y) / ONE;
            n += z * 0x0000000000000014; // add y^19 * (20! / 19!)
            z = (z * y) / ONE;
            n += z * 0x0000000000000001; // add y^20 * (20! / 20!)
            n = n / 0x21c3677c82b40000 + y + ONE; // divide by 20! and then add y^1 / 1! + y^0 / 0!

            if ((x & (ONE >> 3)) != 0)
                n = (n * 0x1c3d6a24ed82218787d624d3e5eba95f9) / 0x18ebef9eac820ae8682b9793ac6d1e776; // multiply by e^(2^-3)
            if ((x & (ONE >> 2)) != 0)
                n = (n * 0x18ebef9eac820ae8682b9793ac6d1e778) / 0x1368b2fc6f9609fe7aceb46aa619baed4; // multiply by e^(2^-2)
            if ((x & (ONE >> 1)) != 0)
                n = (n * 0x1368b2fc6f9609fe7aceb46aa619baed5) / 0x0bc5ab1b16779be3575bd8f0520a9f21f; // multiply by e^(2^-1)
            if ((x & (ONE << 0)) != 0)
                n = (n * 0x0bc5ab1b16779be3575bd8f0520a9f21e) / 0x0454aaa8efe072e7f6ddbab84b40a55c9; // multiply by e^(2^+0)
            if ((x & (ONE << 1)) != 0)
                n = (n * 0x0454aaa8efe072e7f6ddbab84b40a55c5) / 0x00960aadc109e7a3bf4578099615711ea; // multiply by e^(2^+1)
            if ((x & (ONE << 2)) != 0)
                n = (n * 0x00960aadc109e7a3bf4578099615711d7) / 0x0002bf84208204f5977f9a8cf01fdce3d; // multiply by e^(2^+2)
            if ((x & (ONE << 3)) != 0)
                n = (n * 0x0002bf84208204f5977f9a8cf01fdc307) / 0x0000003c6ab775dd0b95b4cbee7e65d11; // multiply by e^(2^+3)
        }

        return Fraction({ n: n, d: ONE });
    }

    /**
     * @dev returns the value of `x * y`
     */
    function _mul512(uint256 x, uint256 y) private pure returns (uint256, uint256) {
        uint256 p = _mulModMax(x, y);
        uint256 q = _unsafeMul(x, y);
        if (p >= q) {
            unchecked {
                // safe because `p >= q`
                return (p - q, q);
            }
        }
        unchecked {
            // safe because `p < q` hence `_unsafeSub(p, q) > 0`
            return (_unsafeSub(p, q) - 1, q);
        }
    }

    /**
     * @dev returns the value of `x - y`
     */
    function _sub512(uint256 xhi, uint256 xlo, uint256 y) private pure returns (uint256, uint256) {
        if (xlo >= y) {
            unchecked {
                // safe because `xlo >= y`
                return (xhi, xlo - y);
            }
        }
        return (xhi - 1, _unsafeSub(xlo, y));
    }

    /**
     * @dev returns the value of `x / pow2n`, given that `x` is divisible by `pow2n`
     */
    function _div512(uint256 xhi, uint256 xlo, uint256 pow2n) private pure returns (uint256) {
        // safe because no `+` or `-` or `*`
        unchecked {
            uint256 pow2nInv = _unsafeAdd(_unsafeSub(0, pow2n) / pow2n, 1); // `1 << (256 - n)`
            return _unsafeMul(xhi, pow2nInv) | (xlo / pow2n); // `(xhi << (256 - n)) | (xlo >> n)`
        }
    }

    /**
     * @dev returns the inverse of `d` modulo `2 ^ 256`, given that `d` is congruent to `1` modulo `2`
     */
    function _inv256(uint256 d) private pure returns (uint256) {
        // approximate the root of `f(x) = 1 / x - d` using the newton–raphson convergence method
        uint256 x = 1;
        unchecked {
            // safe because `i < 8`
            for (uint256 i = 0; i < 8; i++) {
                x = _unsafeMul(x, _unsafeSub(2, _unsafeMul(x, d))); // `x = x * (2 - x * d) mod 2 ^ 256`
            }
        }
        return x;
    }

    /**
     * @dev returns `(x + y) % 2 ^ 256`
     */
    function _unsafeAdd(uint256 x, uint256 y) private pure returns (uint256) {
        unchecked {
            return x + y;
        }
    }

    /**
     * @dev returns `(x - y) % 2 ^ 256`
     */
    function _unsafeSub(uint256 x, uint256 y) private pure returns (uint256) {
        unchecked {
            return x - y;
        }
    }

    /**
     * @dev returns `(x * y) % 2 ^ 256`
     */
    function _unsafeMul(uint256 x, uint256 y) private pure returns (uint256) {
        unchecked {
            return x * y;
        }
    }

    /**
     * @dev returns `x * y % (2 ^ 256 - 1)`
     */
    function _mulModMax(uint256 x, uint256 y) private pure returns (uint256) {
        return mulmod(x, y, type(uint256).max);
    }

    /**
     * @dev returns `x * y % z`
     */
    function _mulMod(uint256 x, uint256 y, uint256 z) private pure returns (uint256) {
        return mulmod(x, y, z);
    }
}

File 34 of 39 : OnlyProxyDelegate.sol
// SPDX-License-Identifier: SEE LICENSE IN LICENSE
pragma solidity 0.8.19;

/**
 * @dev restrict delegation
 */
abstract contract OnlyProxyDelegate {
    address private immutable _proxy;

    error UnknownDelegator();

    constructor(address proxy) {
        _proxy = proxy;
    }

    modifier onlyProxyDelegate() {
        _onlyProxyDelegate();

        _;
    }

    function _onlyProxyDelegate() internal view {
        if (address(this) != _proxy) {
            revert UnknownDelegator();
        }
    }
}

File 35 of 39 : Upgradeable.sol
// SPDX-License-Identifier: SEE LICENSE IN LICENSE
pragma solidity 0.8.19;

import { AccessControlEnumerableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/AccessControlEnumerableUpgradeable.sol";

import { IUpgradeable } from "./interfaces/IUpgradeable.sol";

import { AccessDenied } from "./Utils.sol";

import { MAX_GAP } from "./Constants.sol";

/**
 * @dev this contract provides common utilities for upgradeable contracts
 *
 * note that we're using the Transparent Upgradeable Proxy pattern and *not* the Universal Upgradeable Proxy Standard
 * (UUPS) pattern, therefore initializing the implementation contracts is not necessary or required
 */
abstract contract Upgradeable is IUpgradeable, AccessControlEnumerableUpgradeable {
    error AlreadyInitialized();

    // the admin role is used to allow a non-proxy admin to perform additional initialization/setup during contract
    // upgrades
    bytes32 internal constant ROLE_ADMIN = keccak256("ROLE_ADMIN");

    uint16 internal _initializations;

    // upgrade forward-compatibility storage gap
    uint256[MAX_GAP - 1] private __gap;

    // solhint-disable func-name-mixedcase

    /**
     * @dev initializes the contract and its parents
     */
    function __Upgradeable_init() internal onlyInitializing {
        __AccessControl_init();

        __Upgradeable_init_unchained();
    }

    /**
     * @dev performs contract-specific initialization
     */
    function __Upgradeable_init_unchained() internal onlyInitializing {
        _initializations = version();

        // set up administrative roles
        _setRoleAdmin(ROLE_ADMIN, ROLE_ADMIN);

        // allow the deployer to initially be the admin of the contract
        _setupRole(ROLE_ADMIN, msg.sender);
    }

    // solhint-enable func-name-mixedcase

    modifier onlyAdmin() {
        _hasRole(ROLE_ADMIN, msg.sender);

        _;
    }

    modifier onlyRoleMember(bytes32 role) {
        _hasRole(role, msg.sender);

        _;
    }

    function version() public view virtual override returns (uint16);

    /**
     * @dev returns the admin role
     */
    function roleAdmin() external pure returns (bytes32) {
        return ROLE_ADMIN;
    }

    /**
     * @dev performs post-upgrade initialization
     *
     * requirements:
     *
     * - this must and can be called only once per-upgrade
     */
    function postUpgrade(bool checkVersion, bytes calldata data) external {
        uint16 initializations = _initializations + 1;
        uint16 _version = version();
        if (checkVersion && initializations != _version) {
            revert AlreadyInitialized();
        } else if (!checkVersion) {
            initializations = _version;
        }

        _initializations = initializations;

        _postUpgrade(data);
    }

    /**
     * @dev an optional post-upgrade callback that can be implemented by child contracts
     */
    function _postUpgrade(bytes calldata /* data */) internal virtual {}

    function _hasRole(bytes32 role, address account) internal view {
        if (!hasRole(role, account)) {
            revert AccessDenied();
        }
    }
}

File 36 of 39 : Utils.sol
// SPDX-License-Identifier: SEE LICENSE IN LICENSE
pragma solidity 0.8.19;

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

import { PPM_RESOLUTION } from "./Constants.sol";

error AccessDenied();
error InvalidAddress();
error InvalidFee();
error ZeroValue();
error InvalidIndices();
error InsufficientNativeTokenSent();

/**
 * @dev common utilities
 */
abstract contract Utils {
    using Address for address payable;

    // verifies that a value is greater than zero
    modifier greaterThanZero(uint256 value) {
        _greaterThanZero(value);

        _;
    }

    // error message binary size optimization
    function _greaterThanZero(uint256 value) internal pure {
        if (value == 0) {
            revert ZeroValue();
        }
    }

    // validates an address - currently only checks that it isn't null
    modifier validAddress(address addr) {
        _validAddress(addr);

        _;
    }

    // error message binary size optimization
    function _validAddress(address addr) internal pure {
        if (addr == address(0)) {
            revert InvalidAddress();
        }
    }

    // ensures that the fee is valid
    modifier validFee(uint32 fee) {
        _validFee(fee);

        _;
    }

    // error message binary size optimization
    function _validFee(uint32 fee) internal pure {
        if (fee > PPM_RESOLUTION) {
            revert InvalidFee();
        }
    }
}

File 37 of 39 : IUpgradeable.sol
// SPDX-License-Identifier: SEE LICENSE IN LICENSE
pragma solidity ^0.8.0;

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

import { IAccessControlEnumerableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/IAccessControlEnumerableUpgradeable.sol";

/**
 * @dev this is the common interface for upgradeable contracts
 */
interface IUpgradeable is IAccessControlEnumerableUpgradeable, IVersioned {

}

File 38 of 39 : IVersioned.sol
// SPDX-License-Identifier: SEE LICENSE IN LICENSE
pragma solidity ^0.8.0;

/**
 * @dev an interface for a versioned contract
 */
interface IVersioned {
    function version() external view returns (uint16);
}

File 39 of 39 : IVoucher.sol
// SPDX-License-Identifier: SEE LICENSE IN LICENSE
pragma solidity ^0.8.0;

import { IERC721Upgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC721/IERC721Upgradeable.sol";

import { IUpgradeable } from "../../utility/interfaces/IUpgradeable.sol";

/**
 * @dev Voucher interface
 */
interface IVoucher is IUpgradeable, IERC721Upgradeable {
    error ControllerAlreadySet();
    error OnlyController();

    /**
     * @dev returns the controller address
     */
    function controller() external view returns (address);
    
    /**
     * @dev creates a new voucher token for the given strategyId, transfers it to the owner
     *
     * requirements:
     *
     * - the caller must be the controller address
     *
     */
    function mint(address owner, uint256 strategyId) external;

    /**
     * @dev destroys the voucher token for the given strategyId
     *
     * requirements:
     *
     * - the caller must be the controller address
     *
     */
    function burn(uint256 strategyId) external;

    /**
     * @dev returns a list of tokenIds belonging to the given owner
     * note that for the full list of tokenIds pass 0 to both startIndex and endIndex
     */
    function tokensByOwner(
        address owner,
        uint256 startIndex,
        uint256 endIndex
    ) external view returns (uint256[] memory);
}

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

Contract Security Audit

Contract ABI

API
[{"inputs":[{"internalType":"contract IVoucher","name":"initVoucher","type":"address"},{"internalType":"address","name":"proxy","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AccessDenied","type":"error"},{"inputs":[],"name":"AlreadyInitialized","type":"error"},{"inputs":[],"name":"BalanceMismatch","type":"error"},{"inputs":[],"name":"DeadlineExpired","type":"error"},{"inputs":[],"name":"GreaterThanMaxInput","type":"error"},{"inputs":[],"name":"IdenticalAddresses","type":"error"},{"inputs":[],"name":"InsufficientCapacity","type":"error"},{"inputs":[],"name":"InsufficientLiquidity","type":"error"},{"inputs":[],"name":"InsufficientNativeTokenReceived","type":"error"},{"inputs":[],"name":"InvalidAddress","type":"error"},{"inputs":[],"name":"InvalidFee","type":"error"},{"inputs":[],"name":"InvalidIndices","type":"error"},{"inputs":[],"name":"InvalidRate","type":"error"},{"inputs":[],"name":"InvalidTradeActionAmount","type":"error"},{"inputs":[],"name":"InvalidTradeActionStrategyId","type":"error"},{"inputs":[],"name":"LowerThanMinReturn","type":"error"},{"inputs":[],"name":"NativeAmountMismatch","type":"error"},{"inputs":[],"name":"OrderDisabled","type":"error"},{"inputs":[],"name":"OutDated","type":"error"},{"inputs":[],"name":"Overflow","type":"error"},{"inputs":[],"name":"PairAlreadyExists","type":"error"},{"inputs":[],"name":"PairDoesNotExist","type":"error"},{"inputs":[],"name":"UnknownDelegator","type":"error"},{"inputs":[],"name":"UnnecessaryNativeTokenReceived","type":"error"},{"inputs":[],"name":"ZeroValue","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"Token","name":"token","type":"address"},{"indexed":true,"internalType":"address","name":"recipient","type":"address"},{"indexed":true,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"address","name":"sender","type":"address"}],"name":"FeesWithdrawn","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint128","name":"pairId","type":"uint128"},{"indexed":true,"internalType":"Token","name":"token0","type":"address"},{"indexed":true,"internalType":"Token","name":"token1","type":"address"}],"name":"PairCreated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"Token","name":"token0","type":"address"},{"indexed":true,"internalType":"Token","name":"token1","type":"address"},{"indexed":false,"internalType":"uint32","name":"prevFeePPM","type":"uint32"},{"indexed":false,"internalType":"uint32","name":"newFeePPM","type":"uint32"}],"name":"PairTradingFeePPMUpdated","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":"id","type":"uint256"},{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"Token","name":"token0","type":"address"},{"indexed":true,"internalType":"Token","name":"token1","type":"address"},{"components":[{"internalType":"uint128","name":"y","type":"uint128"},{"internalType":"uint128","name":"z","type":"uint128"},{"internalType":"uint64","name":"A","type":"uint64"},{"internalType":"uint64","name":"B","type":"uint64"}],"indexed":false,"internalType":"struct Order","name":"order0","type":"tuple"},{"components":[{"internalType":"uint128","name":"y","type":"uint128"},{"internalType":"uint128","name":"z","type":"uint128"},{"internalType":"uint64","name":"A","type":"uint64"},{"internalType":"uint64","name":"B","type":"uint64"}],"indexed":false,"internalType":"struct Order","name":"order1","type":"tuple"}],"name":"StrategyCreated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"Token","name":"token0","type":"address"},{"indexed":true,"internalType":"Token","name":"token1","type":"address"},{"components":[{"internalType":"uint128","name":"y","type":"uint128"},{"internalType":"uint128","name":"z","type":"uint128"},{"internalType":"uint64","name":"A","type":"uint64"},{"internalType":"uint64","name":"B","type":"uint64"}],"indexed":false,"internalType":"struct Order","name":"order0","type":"tuple"},{"components":[{"internalType":"uint128","name":"y","type":"uint128"},{"internalType":"uint128","name":"z","type":"uint128"},{"internalType":"uint64","name":"A","type":"uint64"},{"internalType":"uint64","name":"B","type":"uint64"}],"indexed":false,"internalType":"struct Order","name":"order1","type":"tuple"}],"name":"StrategyDeleted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":true,"internalType":"Token","name":"token0","type":"address"},{"indexed":true,"internalType":"Token","name":"token1","type":"address"},{"components":[{"internalType":"uint128","name":"y","type":"uint128"},{"internalType":"uint128","name":"z","type":"uint128"},{"internalType":"uint64","name":"A","type":"uint64"},{"internalType":"uint64","name":"B","type":"uint64"}],"indexed":false,"internalType":"struct Order","name":"order0","type":"tuple"},{"components":[{"internalType":"uint128","name":"y","type":"uint128"},{"internalType":"uint128","name":"z","type":"uint128"},{"internalType":"uint64","name":"A","type":"uint64"},{"internalType":"uint64","name":"B","type":"uint64"}],"indexed":false,"internalType":"struct Order","name":"order1","type":"tuple"},{"indexed":false,"internalType":"uint8","name":"reason","type":"uint8"}],"name":"StrategyUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"trader","type":"address"},{"indexed":true,"internalType":"Token","name":"sourceToken","type":"address"},{"indexed":true,"internalType":"Token","name":"targetToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"sourceAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"targetAmount","type":"uint256"},{"indexed":false,"internalType":"uint128","name":"tradingFeeAmount","type":"uint128"},{"indexed":false,"internalType":"bool","name":"byTargetAmount","type":"bool"}],"name":"TokensTraded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint32","name":"prevFeePPM","type":"uint32"},{"indexed":false,"internalType":"uint32","name":"newFeePPM","type":"uint32"}],"name":"TradingFeePPMUpdated","type":"event"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"Token","name":"token","type":"address"}],"name":"accumulatedFees","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"Token","name":"sourceToken","type":"address"},{"internalType":"Token","name":"targetToken","type":"address"},{"components":[{"internalType":"uint256","name":"strategyId","type":"uint256"},{"internalType":"uint128","name":"amount","type":"uint128"}],"internalType":"struct TradeAction[]","name":"tradeActions","type":"tuple[]"}],"name":"calculateTradeSourceAmount","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"Token","name":"sourceToken","type":"address"},{"internalType":"Token","name":"targetToken","type":"address"},{"components":[{"internalType":"uint256","name":"strategyId","type":"uint256"},{"internalType":"uint128","name":"amount","type":"uint128"}],"internalType":"struct TradeAction[]","name":"tradeActions","type":"tuple[]"}],"name":"calculateTradeTargetAmount","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"controllerType","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"Token","name":"token0","type":"address"},{"internalType":"Token","name":"token1","type":"address"}],"name":"createPair","outputs":[{"components":[{"internalType":"uint128","name":"id","type":"uint128"},{"internalType":"Token[2]","name":"tokens","type":"address[2]"}],"internalType":"struct Pair","name":"","type":"tuple"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"Token","name":"token0","type":"address"},{"internalType":"Token","name":"token1","type":"address"},{"components":[{"internalType":"uint128","name":"y","type":"uint128"},{"internalType":"uint128","name":"z","type":"uint128"},{"internalType":"uint64","name":"A","type":"uint64"},{"internalType":"uint64","name":"B","type":"uint64"}],"internalType":"struct Order[2]","name":"orders","type":"tuple[2]"}],"name":"createStrategy","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"strategyId","type":"uint256"}],"name":"deleteStrategy","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getRoleMember","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleMemberCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"Token","name":"token0","type":"address"},{"internalType":"Token","name":"token1","type":"address"}],"name":"pair","outputs":[{"components":[{"internalType":"uint128","name":"id","type":"uint128"},{"internalType":"Token[2]","name":"tokens","type":"address[2]"}],"internalType":"struct Pair","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"Token","name":"token0","type":"address"},{"internalType":"Token","name":"token1","type":"address"}],"name":"pairTradingFeePPM","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pairs","outputs":[{"internalType":"Token[2][]","name":"","type":"address[2][]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bool","name":"checkVersion","type":"bool"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"postUpgrade","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":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"roleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"roleFeesManager","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"Token","name":"token0","type":"address"},{"internalType":"Token","name":"token1","type":"address"},{"internalType":"uint32","name":"newPairTradingFeePPM","type":"uint32"}],"name":"setPairTradingFeePPM","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"newTradingFeePPM","type":"uint32"}],"name":"setTradingFeePPM","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"Token","name":"token0","type":"address"},{"internalType":"Token","name":"token1","type":"address"},{"internalType":"uint256","name":"startIndex","type":"uint256"},{"internalType":"uint256","name":"endIndex","type":"uint256"}],"name":"strategiesByPair","outputs":[{"components":[{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"Token[2]","name":"tokens","type":"address[2]"},{"components":[{"internalType":"uint128","name":"y","type":"uint128"},{"internalType":"uint128","name":"z","type":"uint128"},{"internalType":"uint64","name":"A","type":"uint64"},{"internalType":"uint64","name":"B","type":"uint64"}],"internalType":"struct Order[2]","name":"orders","type":"tuple[2]"}],"internalType":"struct Strategy[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"Token","name":"token0","type":"address"},{"internalType":"Token","name":"token1","type":"address"}],"name":"strategiesByPairCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"name":"strategy","outputs":[{"components":[{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"Token[2]","name":"tokens","type":"address[2]"},{"components":[{"internalType":"uint128","name":"y","type":"uint128"},{"internalType":"uint128","name":"z","type":"uint128"},{"internalType":"uint64","name":"A","type":"uint64"},{"internalType":"uint64","name":"B","type":"uint64"}],"internalType":"struct Order[2]","name":"orders","type":"tuple[2]"}],"internalType":"struct Strategy","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"Token","name":"sourceToken","type":"address"},{"internalType":"Token","name":"targetToken","type":"address"},{"components":[{"internalType":"uint256","name":"strategyId","type":"uint256"},{"internalType":"uint128","name":"amount","type":"uint128"}],"internalType":"struct TradeAction[]","name":"tradeActions","type":"tuple[]"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint128","name":"minReturn","type":"uint128"}],"name":"tradeBySourceAmount","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"Token","name":"sourceToken","type":"address"},{"internalType":"Token","name":"targetToken","type":"address"},{"components":[{"internalType":"uint256","name":"strategyId","type":"uint256"},{"internalType":"uint128","name":"amount","type":"uint128"}],"internalType":"struct TradeAction[]","name":"tradeActions","type":"tuple[]"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint128","name":"maxInput","type":"uint128"}],"name":"tradeByTargetAmount","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"tradingFeePPM","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"strategyId","type":"uint256"},{"components":[{"internalType":"uint128","name":"y","type":"uint128"},{"internalType":"uint128","name":"z","type":"uint128"},{"internalType":"uint64","name":"A","type":"uint64"},{"internalType":"uint64","name":"B","type":"uint64"}],"internalType":"struct Order[2]","name":"currentOrders","type":"tuple[2]"},{"components":[{"internalType":"uint128","name":"y","type":"uint128"},{"internalType":"uint128","name":"z","type":"uint128"},{"internalType":"uint64","name":"A","type":"uint64"},{"internalType":"uint64","name":"B","type":"uint64"}],"internalType":"struct Order[2]","name":"newOrders","type":"tuple[2]"}],"name":"updateStrategy","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"version","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"Token","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"recipient","type":"address"}],"name":"withdrawFees","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"}]

60c06040523480156200001157600080fd5b50604051620064c5380380620064c583398101604081905262000034916200087d565b6001600160a01b0381166080526200004c826200006b565b6001600160a01b03821660a0526200006362000096565b5050620008bc565b6001600160a01b038116620000935760405163e6c4247b60e01b815260040160405180910390fd5b50565b600054610100900460ff1615808015620000b75750600054600160ff909116105b80620000d35750303b158015620000d3575060005460ff166001145b6200013c5760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b60648201526084015b60405180910390fd5b6000805460ff19166001179055801562000160576000805461ff0019166101001790555b6200016a620001b3565b801562000093576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a150565b600054610100900460ff166200020f5760405162461bcd60e51b815260206004820152602b6024820152600080516020620064a583398151915260448201526a6e697469616c697a696e6760a81b606482015260840162000133565b6200021962000243565b62000223620002a9565b6200022d6200030f565b620002376200037f565b62000241620003e5565b565b600054610100900460ff166200029f5760405162461bcd60e51b815260206004820152602b6024820152600080516020620064a583398151915260448201526a6e697469616c697a696e6760a81b606482015260840162000133565b620002416200047c565b600054610100900460ff16620003055760405162461bcd60e51b815260206004820152602b6024820152600080516020620064a583398151915260448201526a6e697469616c697a696e6760a81b606482015260840162000133565b62000241620004d8565b600054610100900460ff166200036b5760405162461bcd60e51b815260206004820152602b6024820152600080516020620064a583398151915260448201526a6e697469616c697a696e6760a81b606482015260840162000133565b620003756200047c565b6200024162000541565b600054610100900460ff16620003db5760405162461bcd60e51b815260206004820152602b6024820152600080516020620064a583398151915260448201526a6e697469616c697a696e6760a81b606482015260840162000133565b62000241620005e2565b600054610100900460ff16620004415760405162461bcd60e51b815260206004820152602b6024820152600080516020620064a583398151915260448201526a6e697469616c697a696e6760a81b606482015260840162000133565b620002417f24a843cae781765d8cdc3bca1cc42497522c0508f4e621c2ca36ceea2fda7b166000805160206200648583398151915262000646565b600054610100900460ff16620002415760405162461bcd60e51b815260206004820152602b6024820152600080516020620064a583398151915260448201526a6e697469616c697a696e6760a81b606482015260840162000133565b600054610100900460ff16620005345760405162461bcd60e51b815260206004820152602b6024820152600080516020620064a583398151915260448201526a6e697469616c697a696e6760a81b606482015260840162000133565b62000241610fa062000691565b600054610100900460ff166200059d5760405162461bcd60e51b815260206004820152602b6024820152600080516020620064a583398151915260448201526a6e697469616c697a696e6760a81b606482015260840162000133565b61012d805461ffff19166006179055620005c7600080516020620064858339815191528062000646565b62000241600080516020620064858339815191523362000716565b600054610100900460ff166200063e5760405162461bcd60e51b815260206004820152602b6024820152600080516020620064a583398151915260448201526a6e697469616c697a696e6760a81b606482015260840162000133565b600161015f55565b600082815260c96020526040808220600101805490849055905190918391839186917fbd79b86ffe0ab8e8776151514217cd7cacd52c909f66475c3af44e129f0b00ff9190a4505050565b60655463ffffffff600160801b90910481169082168103620006b1575050565b6065805463ffffffff60801b1916600160801b63ffffffff8581169182029290921790925560408051918416825260208201929092527f66db0986e1156e2e747795714bf0301c7e1c695c149a738cb01bcf5cfead8465910160405180910390a15050565b62000722828262000726565b5050565b62000732828262000751565b600082815260fb602052604090206200074c9082620007f5565b505050565b600082815260c9602090815260408083206001600160a01b038516845290915290205460ff166200072257600082815260c9602090815260408083206001600160a01b03851684529091529020805460ff19166001179055620007b13390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b60006200080c836001600160a01b03841662000815565b90505b92915050565b60008181526001830160205260408120546200085e575081546001818101845560008481526020808220909301849055845484825282860190935260409020919091556200080f565b5060006200080f565b6001600160a01b03811681146200009357600080fd5b600080604083850312156200089157600080fd5b82516200089e8162000867565b6020840151909250620008b18162000867565b809150509250929050565b60805160a051615b8062000905600039600081816108b401528181610d2101528181610dcb01528181610ec6015281816111be0152611218015260006113710152615b806000f3fe6080604052600436106102195760003560e01c806393867fb51161011d578063d547741f116100b0578063f2bda26d1161007f578063f74dad8111610064578063f74dad811461069a578063fcf66664146106c7578063ffb0a4a0146106e757600080fd5b8063f2bda26d14610667578063f727473a1461068757600080fd5b8063d547741f146105e5578063debcf1fe14610605578063f06f8acd14610625578063f1c5e0141461065457600080fd5b8063ba0a868b116100ec578063ba0a868b14610543578063bc88d7e414610578578063c9c65396146105a5578063ca15c873146105c557600080fd5b806393867fb5146104c75780639ba372c2146104fa578063a217fddf1461051a578063b76040cd1461052f57600080fd5b806336568abe116101b05780638129fc1c1161017f578063873020371161016457806387302037146104295780639010d07c1461044957806391d148541461048157600080fd5b80638129fc1c146103e75780638672d545146103fc57600080fd5b806336568abe1461036457806354fd4d501461038457806355817d1d146103a757806369a4dea7146103c757600080fd5b80632ab2fad1116101ec5780632ab2fad1146102d15780632c40de1b146102f15780632f2ff15d14610324578063322cf8441461034457600080fd5b806301ffc9a71461021e578063102ee9ba1461025357806321589fa11461027e578063248a9ca314610293575b600080fd5b34801561022a57600080fd5b5061023e610239366004614ff4565b610709565b60405190151581526020015b60405180910390f35b6102666102613660046150ac565b610765565b6040516001600160801b03909116815260200161024a565b61029161028c36600461513f565b610877565b005b34801561029f57600080fd5b506102c36102ae36600461517f565b600090815260c9602052604090206001015490565b60405190815260200161024a565b3480156102dd57600080fd5b506102666102ec366004615198565b6109e3565b3480156102fd57600080fd5b507f24a843cae781765d8cdc3bca1cc42497522c0508f4e621c2ca36ceea2fda7b166102c3565b34801561033057600080fd5b5061029161033f3660046151fd565b610a3d565b34801561035057600080fd5b506102c361035f36600461522d565b610a62565b34801561037057600080fd5b5061029161037f3660046151fd565b610a85565b34801561039057600080fd5b5060065b60405161ffff909116815260200161024a565b3480156103b357600080fd5b506102916103c236600461526f565b610b16565b3480156103d357600080fd5b506102916103e23660046152ad565b610b69565b3480156103f357600080fd5b50610291610ba6565b34801561040857600080fd5b5061041c61041736600461522d565b610cc6565b60405161024a91906152f4565b34801561043557600080fd5b5061029161044436600461517f565b610ce9565b34801561045557600080fd5b50610469610464366004615318565b610dfc565b6040516001600160a01b03909116815260200161024a565b34801561048d57600080fd5b5061023e61049c3660046151fd565b600091825260c9602090815260408084206001600160a01b0393909316845291905290205460ff1690565b3480156104d357600080fd5b507f2172861495e7b85edac73e3cd5fbb42dd675baadf627720e687bcfdaca0250966102c3565b34801561050657600080fd5b506102c361051536600461533a565b610e14565b34801561052657600080fd5b506102c3600081565b34801561053b57600080fd5b506001610394565b34801561054f57600080fd5b5061056361055e36600461522d565b610e8b565b60405163ffffffff909116815260200161024a565b34801561058457600080fd5b5061059861059336600461517f565b610ea7565b60405161024a919061541e565b3480156105b157600080fd5b5061041c6105c036600461522d565b610eeb565b3480156105d157600080fd5b506102c36105e036600461517f565b610f24565b3480156105f157600080fd5b506102916106003660046151fd565b610f3b565b34801561061157600080fd5b5061029161062036600461543b565b610f60565b34801561063157600080fd5b50606554700100000000000000000000000000000000900463ffffffff16610563565b6102666106623660046150ac565b610fe6565b34801561067357600080fd5b50610266610682366004615198565b611094565b6102c36106953660046154c0565b6110ea565b3480156106a657600080fd5b506106ba6106b5366004615500565b6111f6565b60405161024a9190615546565b3480156106d357600080fd5b506102c36106e2366004615595565b61123c565b3480156106f357600080fd5b506106fc611265565b60405161024a91906155b2565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f5a05180f00000000000000000000000000000000000000000000000000000000148061075f575061075f82611274565b92915050565b600061076f61130b565b610777611366565b61078487878534866113ca565b610796876001600160a01b031661145d565b156107de57816001600160801b03163410156107de576040517f7038b89900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60006107ea8888611484565b6040805161010081018252338152815180830183526001600160a01b038c811682528b166020828101919091528201526001918101919091526001600160801b038516606082015234608082015260a08101829052600060c0820181905260e082015290915061085b878783611528565b60c0015191505061086d600161015f55565b9695505050505050565b61087f61130b565b610887611366565b600061089b6108968560801c90565b611aed565b6040516331a9108f60e11b8152600481018690529091507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690636352211e90602401602060405180830381865afa158015610903573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061092791906155ff565b6001600160a01b0316336001600160a01b03161461095857604051634ca8886760e01b815260040160405180910390fd5b600034118015610984575060208101516109829060005b60200201516001600160a01b031661145d565b155b801561099d5750602081015161099b90600161096f565b155b156109bb57604051631334bf4f60e11b815260040160405180910390fd5b6109c482611bc5565b6109d2848484843334611d51565b506109de600161015f55565b505050565b60006109ef8585612169565b60006109fb8686611484565b604080518082019091526001600160a01b038089168252871660208201529091506000610a2b82878786856121c8565b6020015193505050505b949350505050565b600082815260c96020526040902060010154610a588161238c565b6109de8383612396565b6000610a6e8383612169565b6000610a7a8484611484565b9050610a35816123b8565b6001600160a01b0381163314610b085760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c66000000000000000000000000000000000060648201526084015b60405180910390fd5b610b1282826123da565b5050565b610b407f2172861495e7b85edac73e3cd5fbb42dd675baadf627720e687bcfdaca025096336123fc565b80610b4a8161243f565b6000610b568585611484565b9050610b628184612482565b5050505050565b610b937f2172861495e7b85edac73e3cd5fbb42dd675baadf627720e687bcfdaca025096336123fc565b80610b9d8161243f565b610b128261256b565b600054610100900460ff1615808015610bc65750600054600160ff909116105b80610be05750303b158015610be0575060005460ff166001145b610c525760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201527f647920696e697469616c697a65640000000000000000000000000000000000006064820152608401610aff565b6000805460ff191660011790558015610c75576000805461ff0019166101001790555b610c7d612621565b8015610cc3576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b50565b610cce614e6f565b610cd88383612169565b610ce28383611484565b9392505050565b610cf161130b565b610cf9611366565b6000610d086108968360801c90565b6040516331a9108f60e11b8152600481018490529091507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690636352211e90602401602060405180830381865afa158015610d70573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d9491906155ff565b6001600160a01b0316336001600160a01b031614610dc557604051634ca8886760e01b815260040160405180910390fd5b610df0827f0000000000000000000000000000000000000000000000000000000000000000836126b4565b50610cc3600161015f55565b600082815260fb60205260408120610ce29083612873565b60007f24a843cae781765d8cdc3bca1cc42497522c0508f4e621c2ca36ceea2fda7b16610e4181336123fc565b82610e4b8161287f565b85610e558161287f565b85610e5f816128bf565b610e6761130b565b610e7333888a896128f9565b9450610e80600161015f55565b505050509392505050565b600080610e988484611484565b9050610a3581600001516129ad565b610eaf614e97565b6000610ebe6108968460801c90565b9050610ce2837f0000000000000000000000000000000000000000000000000000000000000000836129fc565b610ef3614e6f565b610efb61130b565b610f03611366565b610f0d8383612169565b610f178383612afd565b905061075f600161015f55565b600081815260fb6020526040812061075f90612c5f565b600082815260c96020526040902060010154610f568161238c565b6109de83836123da565b61012d54600090610f769061ffff166001615648565b90506006848015610f8f57508061ffff168261ffff1614155b15610fc6576040517f0dc149f000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b84610fcf578091505b61012d805461ffff191661ffff8416179055610b62565b6000610ff061130b565b610ff8611366565b61100587878534866113ca565b60006110118888611484565b6040805161010081018252338152815180830183526001600160a01b038c811682528b1660208281019190915282015260009181018290526001600160801b038616606082015234608082015260a0810183905260c0810182905260e0810191909152909150611082878783611528565b60e0015191505061086d600161015f55565b60006110a08585612169565b60006110ac8686611484565b604080518082019091526001600160a01b0380891682528716602082015290915060006110dd8287878660016121c8565b5198975050505050505050565b60006110f461130b565b6110fc611366565b6111068484612169565b6000341180156111255750611123846001600160a01b031661145d565b155b8015611140575061113e836001600160a01b031661145d565b155b1561115e57604051631334bf4f60e11b815260040160405180910390fd5b61116782611bc5565b61116f614e6f565b6111798585612c69565b61118e576111878585612afd565b905061119b565b6111988585611484565b90505b604080518082019091526001600160a01b038087168252851660208201526111e77f00000000000000000000000000000000000000000000000000000000000000008286853334612ccc565b92505050610ce2600161015f55565b60606112028585612169565b600061120e8686611484565b905061086d8185857f0000000000000000000000000000000000000000000000000000000000000000612ef9565b6000816112488161287f565b50506001600160a01b031660009081526068602052604090205490565b606061126f61303e565b905090565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f7965db0b00000000000000000000000000000000000000000000000000000000148061075f57507f01ffc9a7000000000000000000000000000000000000000000000000000000007fffffffff0000000000000000000000000000000000000000000000000000000083161461075f565b600261015f540361135e5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610aff565b600261015f55565b306001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146113c8576040517fd0c8bfe500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b565b42831015611404576040517f1ab7da6b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611416816001600160801b03166128bf565b6114208585612169565b60008211801561143f575061143d856001600160a01b031661145d565b155b15610b6257604051631334bf4f60e11b815260040160405180910390fd5b60006001600160a01b03821673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee1461075f565b61148c614e6f565b6114968383612c69565b6114cc576040517fc5fc4bf400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60006114d8848461315d565b80516001600160a01b039081166000908152603460209081526040808320828601519094168352928152908290205482518084019093526001600160801b03168252810191909152949350505050565b60006115678260200151602001518360a00151602001516000600281106115515761155161561c565b60200201516001600160a01b0390811691161490565b905060005b838110156118635760008585838181106115885761158861561c565b90506040020160200160208101906115a09190615663565b905060008686848181106115b6576115b661561c565b60409081029290920135600081815260666020528381208451606081019586905292955093909250839060039082845b8154815260200190600101908083116115e6575050505050905060008061160c836131c3565b915091506116238960a001516000015186886132b7565b6000808215158a15151461163d5783516020850151611645565b602084015184515b9150915060008061165b848b8f6040015161334e565b91509150806001600160801b031684600001516001600160801b031610156116af576040517fbb55fd2700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b83518190036001600160801b031684528251829084906116d090839061567e565b6001600160801b03908116909152845160208601519082169116101590506117035782516001600160801b031660208401525b600061170f878761342a565b80518a55602080820151908a01519192501461173057602081015160018a01555b604080820151908901511461174a57604081015160028a01555b8d60a00151602001518661175f576001611762565b60005b60ff16600281106117755761177561561c565b60200201516001600160a01b03168e60a00151602001518761179857600061179b565b60015b60ff16600281106117ae576117ae61561c565b60200201516001600160a01b03168b7f720da23a5c920b1d8827ec83c4d3c4d90d9419eadb0036b88cb4c2ffa91aef7d8a600060200201518b6001602002015160016040516117ff9392919061569e565b60405180910390a4828e60c001818151611819919061567e565b6001600160801b031690525060e08e01805183919061183990839061567e565b6001600160801b031690525061185c9a508b995061355898505050505050505050565b905061156c565b5060008260400151156119315760006118888460c001518560a001516000015161355e565b90508360c001518161189a919061573c565b6001600160801b0380831660c087018190526060870151929450911610156118ee576040517f0699263d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b602080850151516001600160a01b0316600090815260689091526040812080546001600160801b038516929061192590849061575c565b909155506119ef915050565b60006119498460e001518560a0015160000151613595565b9050808460e0015161195b919061573c565b6001600160801b0380831660e087018190526060870151929450911611156119af576040517ff602de8f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6020808501518101516001600160a01b0316600090815260689091526040812080546001600160801b03851692906119e890849061575c565b9091555050505b611a1a83602001516000015184600001518560c001516001600160801b0316866080015160006135cf565b611a3e83602001516020015184600001518560e001516001600160801b03166136f7565b8260200151602001516001600160a01b03168360200151600001516001600160a01b031684600001516001600160a01b03167f95f3b01351225fea0e69a46f68b164c9dea10284f12cd4a907ce66510ab7af6a8660c001518760e00151868960400151604051611ad694939291906001600160801b039485168152928416602084015292166040820152901515606082015260800190565b60405180910390a45050505050565b600161015f55565b611af5614e6f565b6001600160801b0382166000908152603560205260408082208151808301928390529160029082845b81546001600160a01b03168152600190910190602001808311611b1e575050505050905060006001600160a01b031681600060028110611b6057611b6061561c565b60200201516001600160a01b031603611ba5576040517fc5fc4bf400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b604080518082019091526001600160801b03909316835260208301525090565b60005b6002811015610b1257818160028110611be357611be361561c565b608002016000016020810190611bf99190615663565b6001600160801b0316828260028110611c1457611c1461561c565b608002016020016020810190611c2a9190615663565b6001600160801b03161015611c6b576040517f5cef583a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611cb2828260028110611c8057611c8061561c565b608002016040016020810190611c969190615787565b67ffffffffffffffff166601000000000000908190041c151590565b611ce8576040517f6a43f8d100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611d13828260028110611cfd57611cfd61561c565b608002016060016020810190611c969190615787565b611d49576040517f6a43f8d100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600101611bc8565b60008681526066602052604080822081516060810192839052909291839060039082845b815481526020019060010190808311611d755750505050509050600080611d9b836131c3565b604080518082019091529193509150611deb908a60026000835b82821015611de157611dd2608083028501368190038101906157b8565b81526020019060010190611db5565b5050505083613742565b611e21576040517f811cb74a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60408051808201909152600090611e6e908a600284835b82821015611e6457611e55608083028501368190038101906157b8565b81526020019060010190611e38565b505050508361342a565b8051855191925014611e7f57805185555b6020808201519085015114611e9957602081015160018601555b6040808201519085015114611eb357604081015160028601555b6000611ebf89846138a1565b905060005b6002811015612101576000828260028110611ee157611ee161561c565b60200201519050858260028110611efa57611efa61561c565b6020020151516001600160801b03168c8360028110611f1b57611f1b61561c565b608002016000016020810190611f319190615663565b6001600160801b03161015611fa85760008c8360028110611f5457611f5461561c565b608002016000016020810190611f6a9190615663565b878460028110611f7c57611f7c61561c565b602002015151611f8c919061573c565b9050611fa2828c836001600160801b03166136f7565b50612067565b858260028110611fba57611fba61561c565b6020020151516001600160801b03168c8360028110611fdb57611fdb61561c565b608002016000016020810190611ff19190615663565b6001600160801b031611156120675760008683600281106120145761201461561c565b6020020151518d846002811061202c5761202c61561c565b6080020160000160208101906120429190615663565b61204c919061573c565b9050612065828c836001600160801b03168d60016135cf565b505b6000891180156120845750612084816001600160a01b031661145d565b80156120e0575085826002811061209d5761209d61561c565b6020020151516001600160801b03168c83600281106120be576120be61561c565b6080020160000160208101906120d49190615663565b6001600160801b031611155b156120f8576120f86001600160a01b038b168a613924565b50600101611ec4565b50602081015181516040516001600160a01b0392831692909116908e907f720da23a5c920b1d8827ec83c4d3c4d90d9419eadb0036b88cb4c2ffa91aef7d90612153908f9060808201906000906158a2565b60405180910390a4505050505050505050505050565b816121738161287f565b8161217d8161287f565b6001600160a01b03808516908416036121c2576040517fbd969eb000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b50505050565b604080518082019091526000808252602082015260006121fd876020015185602001516000600281106115515761155161561c565b905060005b8581101561233c57600087878381811061221e5761221e61561c565b90506040020160200160208101906122369190615663565b9050600088888481811061224c5761224c61561c565b60409081029290920135600081815260666020528381208451606081019586905292955090939192509060039082845b81548152602001906001019080831161227c57505050505090506000806122a2836131c3565b915091506122b58a6000015185876132b7565b6000811515881515146122c95782516122cf565b60208301515b90506000806122df83898e61334e565b91509150818b6000018181516122f5919061567e565b6001600160801b031690525060208b01805182919061231590839061567e565b6001600160801b0316905250612335975088965061355895505050505050565b9050612202565b5082156123615781518451612351919061355e565b6001600160801b03168252612382565b61237382602001518560000151613595565b6001600160801b031660208301525b5095945050505050565b610cc38133613a3d565b6123a08282613ab2565b600082815260fb602052604090206109de9082613b54565b80516001600160801b03166000908152606760205260408120610ce281612c5f565b6123e48282613b69565b600082815260fb602052604090206109de9082613bec565b600082815260c9602090815260408083206001600160a01b038516845290915290205460ff16610b1257604051634ca8886760e01b815260040160405180910390fd5b620f424063ffffffff82161115610cc3576040517f58d620b300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b81516001600160801b031660009081526069602052604090205463ffffffff90811690821681036124b257505050565b82516001600160801b03166000908152606960209081526040822080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000001663ffffffff861617905580850151908101516001600160a01b03169160200201516001600160a01b03167f831434d05f3ad5f63be733ea463b2933c70d2162697fd200a22b5d56f5c454b6838560405161255e92919063ffffffff92831681529116602082015260400190565b60405180910390a3505050565b60655463ffffffff70010000000000000000000000000000000090910481169082168103612597575050565b606580547fffffffffffffffffffffffff00000000ffffffffffffffffffffffffffffffff1670010000000000000000000000000000000063ffffffff8581169182029290921790925560408051918416825260208201929092527f66db0986e1156e2e747795714bf0301c7e1c695c149a738cb01bcf5cfead8465910160405180910390a15050565b600054610100900460ff1661268c5760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b6064820152608401610aff565b612694613c01565b61269c613c74565b6126a4613ce7565b6126ac613d62565b6113c8613dd5565b60006126c18484846129fc565b80516040517f42966c680000000000000000000000000000000000000000000000000000000081529192506001600160a01b038516916342966c689161270d9160040190815260200190565b600060405180830381600087803b15801561272757600080fd5b505af115801561273b573d6000803e3d6000fd5b5050825160009081526066602052604081208181556001810182905560020155506127639050565b805182516001600160801b0316600090815260676020526040902061278791613e8a565b50604081015151602082015160608301516127b592919060005b6020020151516001600160801b03166136f7565b60408101516020908101519082015160608301516127d692919060016127a1565b604081015160208101516001600160a01b031690600060200201516001600160a01b031682602001516001600160a01b03167f4d5b6e0627ea711d8e9312b6ba56f50e0b51d41816fd6fd38643495ac81d38b6846000015185606001516000600281106128455761284561561c565b6020020151606087015160016020020151604051612865939291906158be565b60405180910390a450505050565b6000610ce28383613e96565b6001600160a01b038116610cc3576040517fe6c4247b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b80600003610cc3576040517f7c946ed700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b038216600090815260686020526040812054808203612923576000915050610a35565b8085111561292f578094505b6129398582615955565b6001600160a01b03851660009081526068602052604090205561295d8484876136f7565b6040516001600160a01b0387811682528691818616918716907f2f4e8fcae66f01952d258445c03f43cf56d3ce389e017ecd2afa8a79e77175889060200160405180910390a45092949350505050565b6001600160801b03811660009081526069602052604081205463ffffffff1680156129d85780610ce2565b5050606554700100000000000000000000000000000000900463ffffffff16919050565b612a04614e97565b6040516331a9108f60e11b8152600481018590526000906001600160a01b03851690636352211e90602401602060405180830381865afa158015612a4c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612a7091906155ff565b600086815260666020526040808220815160608101928390529394509192919060039082845b815481526020019060010190808311612a965750505050509050600080612abc836131c3565b915091506000612acc87836138a1565b604080516080810182528b81526001600160a01b039097166020880152860152505060608301525090509392505050565b612b05614e6f565b612b0f8383612c69565b15612b46576040517fc9bb25eb00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000612b52848461315d565b603354909150600090612b6f906001600160801b0316600161567e565b603380546fffffffffffffffffffffffffffffffff19166001600160801b0383169081179091556000908152603560205260409020909150612bb390836002614ec3565b5081516001600160a01b039081166000908152603460209081526040808320828701805186168552925280832080546fffffffffffffffffffffffffffffffff19166001600160801b0387169081179091559151865191519085169491909116927f6365c594f5448f79c1cc1e6f661bdbf1d16f2e8f85747e13f8e80f1fd168b7c391a46040518060400160405280826001600160801b03168152602001838152509250505092915050565b600061075f825490565b600080612c76848461315d565b80516001600160a01b039081166000908152603460209081526040808320828601519094168352929052908120549192506001600160801b039091169003612cc257600091505061075f565b5060019392505050565b8451600090612d00908487845b608002016000016020810190612cef9190615663565b6001600160801b03168560016135cf565b6020860151612d129084876001612cd9565b606554600090612d2c906001600160801b0316600161567e565b606580546001600160801b0383166fffffffffffffffffffffffffffffffff199182168117909255875192935060009260801b161786516001600160801b03166000908152606760205260409020909150612d879082613ec0565b5087516020870151600091612d9d916001611551565b60408051808201909152909150612deb908960026000835b82821015612de157612dd2608083028501368190038101906157b8565b81526020019060010190612db5565b505050508261342a565b6000838152606660205260409020612e04916003614f2f565b506040517f40c10f190000000000000000000000000000000000000000000000000000000081526001600160a01b038781166004830152602482018490528b16906340c10f1990604401600060405180830381600087803b158015612e6857600080fd5b505af1158015612e7c573d6000803e3d6000fd5b5050505088600160028110612e9357612e9361561c565b602002015189516040516001600160a01b0392831692918216918916907fff24554f8ccfe540435cfc8854831f8dcf1cf2068708cfaf46e8b52a4ccc4c8d90612ee49087908e906080820190615968565b60405180910390a45098975050505050505050565b83516001600160801b03166000908152606760205260408120606091612f1e82612c5f565b9050841580612f2c57508085115b15612f35578094505b84861115612f6f576040517f2cd4dad300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000612f7b8787615955565b905060008167ffffffffffffffff811115612f9857612f986157a2565b604051908082528060200260200182016040528015612fd157816020015b612fbe614e97565b815260200190600190039081612fb65790505b50905060005b82811015613031576000612ff5612fee838c61575c565b8790612873565b905061300281898d6129fc565b8383815181106130145761301461561c565b60200260200101819052505061302a8160010190565b9050612fd7565b5098975050505050505050565b6033546060906001600160801b031660008167ffffffffffffffff811115613068576130686157a2565b6040519080825280602002602001820160405280156130a157816020015b61308e614f5d565b8152602001906001900390816130865790505b50905060005b826001600160801b0316816001600160801b0316101561315657603560006130d083600161567e565b6001600160801b03168152602081019190915260409081016000208151808301928390529160029082845b81546001600160a01b031681526001909101906020018083116130fb57505050505082826001600160801b0316815181106131385761313861561c565b6020026020010181905250808061314e9061598a565b9150506130a7565b5092915050565b613165614f5d565b816001600160a01b0316836001600160a01b0316106131a157604080518082019091526001600160a01b03808416825284166020820152610ce2565b50604080518082019091526001600160a01b0392831681529116602082015290565b6131cb614f7b565b6040805160c0808201835284516001600160801b0390811683850190815260208088018051841660608701528051608090811c67ffffffffffffffff1681880152905190941c60a0860152908452845180840186528751841c8152878601519092168282015260009490840192908201908760026020020151901c67ffffffffffffffff16815260200160c160018860026003811061326c5761326c61561c565b6020020151901b901c67ffffffffffffffff169052905291507f8000000000000000000000000000000000000000000000000000000000000000836002602002015110159050915091565b826001600160801b03166132cb8360801c90565b6001600160801b03161461330b576040517fb7b067f900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b806001600160801b03166000036109de576040517feb1a139600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600080600085600001516001600160801b03169050600086602001516001600160801b0316905060006133a1886040015167ffffffffffffffff1665ffffffffffff811666010000000000009091041b90565b905060006133cf896060015167ffffffffffffffff1665ffffffffffff811666010000000000009091041b90565b905086156133ff576133f56133f0896001600160801b031686868686613ecc565b613fcb565b955087945061341e565b87955061341b6133f0896001600160801b03168686868661404e565b94505b50505050935093915050565b613432614fc1565b604080516060808201835260208681015151875151608091821b6fffffffffffffffffffffffffffffffff19166001600160801b03918216178552885193840151848701519484015160c09190911b7fffffffffffffffff000000000000000000000000000000000000000000000000169490921b77ffffffffffffffff00000000000000000000000000000000169116179190911790820152908101836134db5760006134fd565b7f80000000000000000000000000000000000000000000000000000000000000005b60c086600160200201516060015167ffffffffffffffff16901b608087600160200201516040015167ffffffffffffffff16901b60008860016020020151602001516001600160801b0316901b171717815250905092915050565b60010190565b60008061356a836129ad565b9050610a356133f06001600160801b038616620f424061358a85826159b0565b63ffffffff1661418d565b6000806135a1836129ad565b9050610a356133f06001600160801b0386166135c084620f42406159b0565b63ffffffff16620f42406141f5565b6135e1856001600160a01b031661145d565b1561364a5782821015613620576040517f677606af00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b82821115613645576136456136358484615955565b6001600160a01b03861690613924565b610b62565b8215610b625780156136e257600061366b6001600160a01b038716306142e9565b90506136826001600160a01b038716863087614390565b60006136976001600160a01b038816306142e9565b9050846136a48383615955565b146136db576040517fca3e0a6800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5050610b62565b610b626001600160a01b038616853086614390565b8060000361370457505050565b613716836001600160a01b031661145d565b1561372e576109de6001600160a01b03831682613924565b6109de6001600160a01b03841683836143ba565b6000805b6002811015612cc2578281600281106137615761376161561c565b6020020151516001600160801b03168482600281106137825761378261561c565b6020020151516001600160801b03161415806137e457508281600281106137ab576137ab61561c565b6020020151602001516001600160801b03168482600281106137cf576137cf61561c565b6020020151602001516001600160801b031614155b8061383757508281600281106137fc576137fc61561c565b60200201516040015167ffffffffffffffff168482600281106138215761382161561c565b60200201516040015167ffffffffffffffff1614155b8061388a575082816002811061384f5761384f61561c565b60200201516060015167ffffffffffffffff168482600281106138745761387461561c565b60200201516060015167ffffffffffffffff1614155b1561389957600091505061075f565b600101613746565b6138a9614f5d565b816138b8578260200151610ce2565b604051806040016040528084602001516001600281106138da576138da61561c565b60200201516001600160a01b03166001600160a01b03168152602001846020015160006002811061390d5761390d61561c565b60200201516001600160a01b031690529392505050565b804710156139745760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a20696e73756666696369656e742062616c616e63650000006044820152606401610aff565b6000826001600160a01b03168260405160006040518083038185875af1925050503d80600081146139c1576040519150601f19603f3d011682016040523d82523d6000602084013e6139c6565b606091505b50509050806109de5760405162461bcd60e51b815260206004820152603a60248201527f416464726573733a20756e61626c6520746f2073656e642076616c75652c207260448201527f6563697069656e74206d617920686176652072657665727465640000000000006064820152608401610aff565b600082815260c9602090815260408083206001600160a01b038516845290915290205460ff16610b1257613a708161441f565b613a7b836020614431565b604051602001613a8c929190615a07565b60408051601f198184030181529082905262461bcd60e51b8252610aff91600401615a88565b600082815260c9602090815260408083206001600160a01b038516845290915290205460ff16610b1257600082815260c9602090815260408083206001600160a01b03851684529091529020805460ff19166001179055613b103390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000610ce2836001600160a01b03841661465a565b600082815260c9602090815260408083206001600160a01b038516845290915290205460ff1615610b1257600082815260c9602090815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b6000610ce2836001600160a01b0384166146a9565b600054610100900460ff16613c6c5760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b6064820152608401610aff565b6113c861479c565b600054610100900460ff16613cdf5760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b6064820152608401610aff565b6113c8614807565b600054610100900460ff16613d525760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b6064820152608401610aff565b613d5a61479c565b6113c861487d565b600054610100900460ff16613dcd5760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b6064820152608401610aff565b6113c861494b565b600054610100900460ff16613e405760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b6064820152608401610aff565b6113c87f24a843cae781765d8cdc3bca1cc42497522c0508f4e621c2ca36ceea2fda7b167f2172861495e7b85edac73e3cd5fbb42dd675baadf627720e687bcfdaca0250966149b6565b6000610ce283836146a9565b6000826000018281548110613ead57613ead61561c565b9060005260206000200154905092915050565b6000610ce2838361465a565b600082600003613f3b5781600003613f10576040517f4e305c4b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b613f3486613f25660100000000000080615abb565b613f2f8580615abb565b61418d565b9050613fc2565b66010000000000008402858402838602016000613f58868a615abb565b613f629083615955565b90506000613f708485614a01565b90506000613f7e8484614a01565b90506000613f8c8383614a30565b90506000613f9b87888461418d565b90506000613faa8787856141f5565b9050613fb78e838361418d565b985050505050505050505b95945050505050565b60006001600160801b0382111561404a5760405162461bcd60e51b815260206004820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203160448201527f32382062697473000000000000000000000000000000000000000000000000006064820152608401610aff565b5090565b6000826000036140b65781600003614092576040517f4e305c4b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b613f34866140a08480615abb565b6140b1660100000000000080615abb565b6141f5565b660100000000000084028584028386020160006140d38983615abb565b905060006140e18485614a01565b905060006140ef8389614a01565b905060006140fd8383614a30565b9050600061410c87888461418d565b9050600061411b868c8561418d565b905060008061412a8484614a46565b9150915081156141595761414889614142878b615ad2565b836141f5565b9a5050505050505050505050613fc2565b6141648a8b8a61418d565b61416e908e61575c565b614178908a615ad2565b9a505050505050505050505095945050505050565b60008061419b8585856141f5565b905060006141aa868686614a6f565b1115610a355760001981106141eb576040517f35278d1200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001019050610ce2565b60008060006142048686614a8a565b91509150816000036142295783818161421f5761421f6159cd565b0492505050610ce2565b838210614262576040517f35278d1200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600061426f878787614a6f565b905060008061427f858585614ac3565b91509150816000036142a75786818161429a5761429a6159cd565b0495505050505050610ce2565b60008781038816906142ba848484614af3565b905060006142d6838b816142d0576142d06159cd565b04614b30565b919091029b9a5050505050505050505050565b60006142f48361145d565b1561430a57506001600160a01b0381163161075f565b826040517f70a082310000000000000000000000000000000000000000000000000000000081526001600160a01b03848116600483015291909116906370a0823190602401602060405180830381865afa15801561436c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ce29190615af4565b8015806143a157506143a18461145d565b6121c2576121c26001600160a01b038516848484614b51565b806000036143c757505050565b6143d08361145d565b1561440b576040516001600160a01b0383169082156108fc029083906000818181858888f193505050501580156121c2573d6000803e3d6000fd5b6109de6001600160a01b0384168383614c02565b606061075f6001600160a01b03831660145b60606000614440836002615abb565b61444b90600261575c565b67ffffffffffffffff811115614463576144636157a2565b6040519080825280601f01601f19166020018201604052801561448d576020820181803683370190505b5090507f3000000000000000000000000000000000000000000000000000000000000000816000815181106144c4576144c461561c565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053507f7800000000000000000000000000000000000000000000000000000000000000816001815181106145275761452761561c565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053506000614563846002615abb565b61456e90600161575c565b90505b600181111561460b577f303132333435363738396162636465660000000000000000000000000000000085600f16601081106145af576145af61561c565b1a60f81b8282815181106145c5576145c561561c565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535060049490941c9361460481615b0d565b9050614571565b508315610ce25760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610aff565b60008181526001830160205260408120546146a15750815460018181018455600084815260208082209093018490558454848252828601909352604090209190915561075f565b50600061075f565b600081815260018301602052604081205480156147925760006146cd600183615955565b85549091506000906146e190600190615955565b90508181146147465760008660000182815481106147015761470161561c565b90600052602060002001549050808760000184815481106147245761472461561c565b6000918252602080832090910192909255918252600188019052604090208390555b855486908061475757614757615b24565b60019003818190600052602060002001600090559055856001016000868152602001908152602001600020600090556001935050505061075f565b600091505061075f565b600054610100900460ff166113c85760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b6064820152608401610aff565b600054610100900460ff166148725760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b6064820152608401610aff565b6113c8610fa061256b565b600054610100900460ff166148e85760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b6064820152608401610aff565b61012d805461ffff191660061790556149217f2172861495e7b85edac73e3cd5fbb42dd675baadf627720e687bcfdaca025096806149b6565b6113c87f2172861495e7b85edac73e3cd5fbb42dd675baadf627720e687bcfdaca02509633614c4b565b600054610100900460ff16611ae55760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b6064820152608401610aff565b600082815260c96020526040808220600101805490849055905190918391839186917fbd79b86ffe0ab8e8776151514217cd7cacd52c909f66475c3af44e129f0b00ff9190a4505050565b6000806000614a108585614a8a565b9150915080198211614a255781600101613fc2565b506002019392505050565b6000818311614a3f5781610ce2565b5090919050565b60008083830184811015614a61576000809250925050614a68565b6001925090505b9250929050565b60008180614a7f57614a7f6159cd565b838509949350505050565b6000806000614a998585614c55565b9050848402808210614ab2579081900392509050614a68565b600181830303969095509350505050565b600080828410614ad95750839050818303614aeb565b614ae4600186615955565b9150508183035b935093915050565b600080614b118380830381614b0a57614b0a6159cd565b0460010190565b9050828481614b2257614b226159cd565b048186021795945050505050565b60006001815b60088110156131565783820260020382029150600101614b36565b6040516001600160a01b03808516602483015283166044820152606481018290526121c29085907f23b872dd00000000000000000000000000000000000000000000000000000000906084015b60408051601f198184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff0000000000000000000000000000000000000000000000000000000090931692909217909152614c64565b6040516001600160a01b0383166024820152604481018290526109de9084907fa9059cbb0000000000000000000000000000000000000000000000000000000090606401614b9e565b610b128282612396565b60006000198284099392505050565b6000614cb9826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316614d4c9092919063ffffffff16565b9050805160001480614cda575080806020019051810190614cda9190615b3a565b6109de5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f742073756363656564000000000000000000000000000000000000000000006064820152608401610aff565b6060610a35848460008585600080866001600160a01b03168587604051614d739190615b57565b60006040518083038185875af1925050503d8060008114614db0576040519150601f19603f3d011682016040523d82523d6000602084013e614db5565b606091505b5091509150614dc687838387614dd1565b979650505050505050565b60608315614e40578251600003614e39576001600160a01b0385163b614e395760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610aff565b5081610a35565b610a358383815115614e555781518083602001fd5b8060405162461bcd60e51b8152600401610aff9190615a88565b604051806040016040528060006001600160801b03168152602001614e92614f5d565b905290565b6040805160808101825260008082526020820152908101614eb6614f5d565b8152602001614e92614f7b565b8260028101928215614f23579160200282015b82811115614f2357825182547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b03909116178255602090920191600190910190614ed6565b5061404a929150614fdf565b8260038101928215614f23579160200282015b82811115614f23578251825591602001919060010190614f42565b60405180604001604052806002906020820280368337509192915050565b60405180604001604052806002905b604080516080810182526000808252602080830182905292820181905260608201528252600019909201910181614f8a5790505090565b60405180606001604052806003906020820280368337509192915050565b5b8082111561404a5760008155600101614fe0565b60006020828403121561500657600080fd5b81357fffffffff0000000000000000000000000000000000000000000000000000000081168114610ce257600080fd5b6001600160a01b0381168114610cc357600080fd5b60008083601f84011261505d57600080fd5b50813567ffffffffffffffff81111561507557600080fd5b6020830191508360208260061b8501011115614a6857600080fd5b80356001600160801b03811681146150a757600080fd5b919050565b60008060008060008060a087890312156150c557600080fd5b86356150d081615036565b955060208701356150e081615036565b9450604087013567ffffffffffffffff8111156150fc57600080fd5b61510889828a0161504b565b9095509350506060870135915061512160808801615090565b90509295509295509295565b80610100810183101561075f57600080fd5b6000806000610220848603121561515557600080fd5b83359250615166856020860161512d565b915061517685610120860161512d565b90509250925092565b60006020828403121561519157600080fd5b5035919050565b600080600080606085870312156151ae57600080fd5b84356151b981615036565b935060208501356151c981615036565b9250604085013567ffffffffffffffff8111156151e557600080fd5b6151f18782880161504b565b95989497509550505050565b6000806040838503121561521057600080fd5b82359150602083013561522281615036565b809150509250929050565b6000806040838503121561524057600080fd5b823561524b81615036565b9150602083013561522281615036565b803563ffffffff811681146150a757600080fd5b60008060006060848603121561528457600080fd5b833561528f81615036565b9250602084013561529f81615036565b91506151766040850161525b565b6000602082840312156152bf57600080fd5b610ce28261525b565b8060005b60028110156121c25781516001600160a01b03168452602093840193909101906001016152cc565b81516001600160801b031681526020808301516060830191613156908401826152c8565b6000806040838503121561532b57600080fd5b50508035926020909101359150565b60008060006060848603121561534f57600080fd5b833561535a81615036565b925060208401359150604084013561537181615036565b809150509250925092565b8051825260206001600160a01b0381830151168184015260408201516153a560408501826152c8565b506060820151608080850160005b6002811015615415576154058285516001600160801b0380825116835280602083015116602084015250604081015167ffffffffffffffff808216604085015280606084015116606085015250505050565b92840192908201906001016153b3565b50505050505050565b610180810161075f828461537c565b8015158114610cc357600080fd5b60008060006040848603121561545057600080fd5b833561545b8161542d565b9250602084013567ffffffffffffffff8082111561547857600080fd5b818601915086601f83011261548c57600080fd5b81358181111561549b57600080fd5b8760208285010111156154ad57600080fd5b6020830194508093505050509250925092565b600080600061014084860312156154d657600080fd5b83356154e181615036565b925060208401356154f181615036565b9150615176856040860161512d565b6000806000806080858703121561551657600080fd5b843561552181615036565b9350602085013561553181615036565b93969395505050506040820135916060013590565b6020808252825182820181905260009190848201906040850190845b818110156155895761557583855161537c565b928401926101809290920191600101615562565b50909695505050505050565b6000602082840312156155a757600080fd5b8135610ce281615036565b602080825282518282018190526000919060409081850190868401855b828110156155f2576155e28483516152c8565b92840192908501906001016155cf565b5091979650505050505050565b60006020828403121561561157600080fd5b8151610ce281615036565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b61ffff81811683821601908082111561315657613156615632565b60006020828403121561567557600080fd5b610ce282615090565b6001600160801b0381811683821601908082111561315657613156615632565b61012081016156eb82866001600160801b0380825116835280602083015116602084015250604081015167ffffffffffffffff808216604085015280606084015116606085015250505050565b83516001600160801b03908116608084015260208501511660a0830152604084015167ffffffffffffffff90811660c084015260608501511660e08301525b60ff8316610100830152949350505050565b6001600160801b0382811682821603908082111561315657613156615632565b8082018082111561075f5761075f615632565b803567ffffffffffffffff811681146150a757600080fd5b60006020828403121561579957600080fd5b610ce28261576f565b634e487b7160e01b600052604160045260246000fd5b6000608082840312156157ca57600080fd5b6040516080810181811067ffffffffffffffff821117156157fb57634e487b7160e01b600052604160045260246000fd5b60405261580783615090565b815261581560208401615090565b60208201526158266040840161576f565b60408201526158376060840161576f565b60608201529392505050565b6001600160801b038061585583615090565b1683528061586560208401615090565b166020840152506158786040820161576f565b67ffffffffffffffff8082166040850152806158966060850161576f565b16606085015250505050565b61012081016158b18286615843565b61572a6080830185615843565b838152610120810161591160208301856001600160801b0380825116835280602083015116602084015250604081015167ffffffffffffffff808216604085015280606084015116606085015250505050565b82516001600160801b0390811660a084015260208401511660c0830152604083015167ffffffffffffffff90811660e0840152606084015116610100830152610a35565b8181038181111561075f5761075f615632565b838152610120810161597d6020830185615843565b610a3560a0830184615843565b60006001600160801b038083168181036159a6576159a6615632565b6001019392505050565b63ffffffff82811682821603908082111561315657613156615632565b634e487b7160e01b600052601260045260246000fd5b60005b838110156159fe5781810151838201526020016159e6565b50506000910152565b7f416363657373436f6e74726f6c3a206163636f756e7420000000000000000000815260008351615a3f8160178501602088016159e3565b7f206973206d697373696e6720726f6c65200000000000000000000000000000006017918401918201528351615a7c8160288401602088016159e3565b01602801949350505050565b6020815260008251806020840152615aa78160408501602087016159e3565b601f01601f19169190910160400192915050565b808202811582820484141761075f5761075f615632565b600082615aef57634e487b7160e01b600052601260045260246000fd5b500490565b600060208284031215615b0657600080fd5b5051919050565b600081615b1c57615b1c615632565b506000190190565b634e487b7160e01b600052603160045260246000fd5b600060208284031215615b4c57600080fd5b8151610ce28161542d565b60008251615b698184602087016159e3565b919091019291505056fea164736f6c6343000813000a2172861495e7b85edac73e3cd5fbb42dd675baadf627720e687bcfdaca025096496e697469616c697a61626c653a20636f6e7472616374206973206e6f742069000000000000000000000000248594be9be605905b8912cf575f03fe42d8905400000000000000000000000010fa549e70ede76c258c0808b289e4ac3c9ab2e2

Deployed Bytecode

0x6080604052600436106102195760003560e01c806393867fb51161011d578063d547741f116100b0578063f2bda26d1161007f578063f74dad8111610064578063f74dad811461069a578063fcf66664146106c7578063ffb0a4a0146106e757600080fd5b8063f2bda26d14610667578063f727473a1461068757600080fd5b8063d547741f146105e5578063debcf1fe14610605578063f06f8acd14610625578063f1c5e0141461065457600080fd5b8063ba0a868b116100ec578063ba0a868b14610543578063bc88d7e414610578578063c9c65396146105a5578063ca15c873146105c557600080fd5b806393867fb5146104c75780639ba372c2146104fa578063a217fddf1461051a578063b76040cd1461052f57600080fd5b806336568abe116101b05780638129fc1c1161017f578063873020371161016457806387302037146104295780639010d07c1461044957806391d148541461048157600080fd5b80638129fc1c146103e75780638672d545146103fc57600080fd5b806336568abe1461036457806354fd4d501461038457806355817d1d146103a757806369a4dea7146103c757600080fd5b80632ab2fad1116101ec5780632ab2fad1146102d15780632c40de1b146102f15780632f2ff15d14610324578063322cf8441461034457600080fd5b806301ffc9a71461021e578063102ee9ba1461025357806321589fa11461027e578063248a9ca314610293575b600080fd5b34801561022a57600080fd5b5061023e610239366004614ff4565b610709565b60405190151581526020015b60405180910390f35b6102666102613660046150ac565b610765565b6040516001600160801b03909116815260200161024a565b61029161028c36600461513f565b610877565b005b34801561029f57600080fd5b506102c36102ae36600461517f565b600090815260c9602052604090206001015490565b60405190815260200161024a565b3480156102dd57600080fd5b506102666102ec366004615198565b6109e3565b3480156102fd57600080fd5b507f24a843cae781765d8cdc3bca1cc42497522c0508f4e621c2ca36ceea2fda7b166102c3565b34801561033057600080fd5b5061029161033f3660046151fd565b610a3d565b34801561035057600080fd5b506102c361035f36600461522d565b610a62565b34801561037057600080fd5b5061029161037f3660046151fd565b610a85565b34801561039057600080fd5b5060065b60405161ffff909116815260200161024a565b3480156103b357600080fd5b506102916103c236600461526f565b610b16565b3480156103d357600080fd5b506102916103e23660046152ad565b610b69565b3480156103f357600080fd5b50610291610ba6565b34801561040857600080fd5b5061041c61041736600461522d565b610cc6565b60405161024a91906152f4565b34801561043557600080fd5b5061029161044436600461517f565b610ce9565b34801561045557600080fd5b50610469610464366004615318565b610dfc565b6040516001600160a01b03909116815260200161024a565b34801561048d57600080fd5b5061023e61049c3660046151fd565b600091825260c9602090815260408084206001600160a01b0393909316845291905290205460ff1690565b3480156104d357600080fd5b507f2172861495e7b85edac73e3cd5fbb42dd675baadf627720e687bcfdaca0250966102c3565b34801561050657600080fd5b506102c361051536600461533a565b610e14565b34801561052657600080fd5b506102c3600081565b34801561053b57600080fd5b506001610394565b34801561054f57600080fd5b5061056361055e36600461522d565b610e8b565b60405163ffffffff909116815260200161024a565b34801561058457600080fd5b5061059861059336600461517f565b610ea7565b60405161024a919061541e565b3480156105b157600080fd5b5061041c6105c036600461522d565b610eeb565b3480156105d157600080fd5b506102c36105e036600461517f565b610f24565b3480156105f157600080fd5b506102916106003660046151fd565b610f3b565b34801561061157600080fd5b5061029161062036600461543b565b610f60565b34801561063157600080fd5b50606554700100000000000000000000000000000000900463ffffffff16610563565b6102666106623660046150ac565b610fe6565b34801561067357600080fd5b50610266610682366004615198565b611094565b6102c36106953660046154c0565b6110ea565b3480156106a657600080fd5b506106ba6106b5366004615500565b6111f6565b60405161024a9190615546565b3480156106d357600080fd5b506102c36106e2366004615595565b61123c565b3480156106f357600080fd5b506106fc611265565b60405161024a91906155b2565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f5a05180f00000000000000000000000000000000000000000000000000000000148061075f575061075f82611274565b92915050565b600061076f61130b565b610777611366565b61078487878534866113ca565b610796876001600160a01b031661145d565b156107de57816001600160801b03163410156107de576040517f7038b89900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60006107ea8888611484565b6040805161010081018252338152815180830183526001600160a01b038c811682528b166020828101919091528201526001918101919091526001600160801b038516606082015234608082015260a08101829052600060c0820181905260e082015290915061085b878783611528565b60c0015191505061086d600161015f55565b9695505050505050565b61087f61130b565b610887611366565b600061089b6108968560801c90565b611aed565b6040516331a9108f60e11b8152600481018690529091507f000000000000000000000000248594be9be605905b8912cf575f03fe42d890546001600160a01b031690636352211e90602401602060405180830381865afa158015610903573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061092791906155ff565b6001600160a01b0316336001600160a01b03161461095857604051634ca8886760e01b815260040160405180910390fd5b600034118015610984575060208101516109829060005b60200201516001600160a01b031661145d565b155b801561099d5750602081015161099b90600161096f565b155b156109bb57604051631334bf4f60e11b815260040160405180910390fd5b6109c482611bc5565b6109d2848484843334611d51565b506109de600161015f55565b505050565b60006109ef8585612169565b60006109fb8686611484565b604080518082019091526001600160a01b038089168252871660208201529091506000610a2b82878786856121c8565b6020015193505050505b949350505050565b600082815260c96020526040902060010154610a588161238c565b6109de8383612396565b6000610a6e8383612169565b6000610a7a8484611484565b9050610a35816123b8565b6001600160a01b0381163314610b085760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c66000000000000000000000000000000000060648201526084015b60405180910390fd5b610b1282826123da565b5050565b610b407f2172861495e7b85edac73e3cd5fbb42dd675baadf627720e687bcfdaca025096336123fc565b80610b4a8161243f565b6000610b568585611484565b9050610b628184612482565b5050505050565b610b937f2172861495e7b85edac73e3cd5fbb42dd675baadf627720e687bcfdaca025096336123fc565b80610b9d8161243f565b610b128261256b565b600054610100900460ff1615808015610bc65750600054600160ff909116105b80610be05750303b158015610be0575060005460ff166001145b610c525760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201527f647920696e697469616c697a65640000000000000000000000000000000000006064820152608401610aff565b6000805460ff191660011790558015610c75576000805461ff0019166101001790555b610c7d612621565b8015610cc3576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b50565b610cce614e6f565b610cd88383612169565b610ce28383611484565b9392505050565b610cf161130b565b610cf9611366565b6000610d086108968360801c90565b6040516331a9108f60e11b8152600481018490529091507f000000000000000000000000248594be9be605905b8912cf575f03fe42d890546001600160a01b031690636352211e90602401602060405180830381865afa158015610d70573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d9491906155ff565b6001600160a01b0316336001600160a01b031614610dc557604051634ca8886760e01b815260040160405180910390fd5b610df0827f000000000000000000000000248594be9be605905b8912cf575f03fe42d89054836126b4565b50610cc3600161015f55565b600082815260fb60205260408120610ce29083612873565b60007f24a843cae781765d8cdc3bca1cc42497522c0508f4e621c2ca36ceea2fda7b16610e4181336123fc565b82610e4b8161287f565b85610e558161287f565b85610e5f816128bf565b610e6761130b565b610e7333888a896128f9565b9450610e80600161015f55565b505050509392505050565b600080610e988484611484565b9050610a3581600001516129ad565b610eaf614e97565b6000610ebe6108968460801c90565b9050610ce2837f000000000000000000000000248594be9be605905b8912cf575f03fe42d89054836129fc565b610ef3614e6f565b610efb61130b565b610f03611366565b610f0d8383612169565b610f178383612afd565b905061075f600161015f55565b600081815260fb6020526040812061075f90612c5f565b600082815260c96020526040902060010154610f568161238c565b6109de83836123da565b61012d54600090610f769061ffff166001615648565b90506006848015610f8f57508061ffff168261ffff1614155b15610fc6576040517f0dc149f000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b84610fcf578091505b61012d805461ffff191661ffff8416179055610b62565b6000610ff061130b565b610ff8611366565b61100587878534866113ca565b60006110118888611484565b6040805161010081018252338152815180830183526001600160a01b038c811682528b1660208281019190915282015260009181018290526001600160801b038616606082015234608082015260a0810183905260c0810182905260e0810191909152909150611082878783611528565b60e0015191505061086d600161015f55565b60006110a08585612169565b60006110ac8686611484565b604080518082019091526001600160a01b0380891682528716602082015290915060006110dd8287878660016121c8565b5198975050505050505050565b60006110f461130b565b6110fc611366565b6111068484612169565b6000341180156111255750611123846001600160a01b031661145d565b155b8015611140575061113e836001600160a01b031661145d565b155b1561115e57604051631334bf4f60e11b815260040160405180910390fd5b61116782611bc5565b61116f614e6f565b6111798585612c69565b61118e576111878585612afd565b905061119b565b6111988585611484565b90505b604080518082019091526001600160a01b038087168252851660208201526111e77f000000000000000000000000248594be9be605905b8912cf575f03fe42d890548286853334612ccc565b92505050610ce2600161015f55565b60606112028585612169565b600061120e8686611484565b905061086d8185857f000000000000000000000000248594be9be605905b8912cf575f03fe42d89054612ef9565b6000816112488161287f565b50506001600160a01b031660009081526068602052604090205490565b606061126f61303e565b905090565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f7965db0b00000000000000000000000000000000000000000000000000000000148061075f57507f01ffc9a7000000000000000000000000000000000000000000000000000000007fffffffff0000000000000000000000000000000000000000000000000000000083161461075f565b600261015f540361135e5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610aff565b600261015f55565b306001600160a01b037f00000000000000000000000010fa549e70ede76c258c0808b289e4ac3c9ab2e216146113c8576040517fd0c8bfe500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b565b42831015611404576040517f1ab7da6b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611416816001600160801b03166128bf565b6114208585612169565b60008211801561143f575061143d856001600160a01b031661145d565b155b15610b6257604051631334bf4f60e11b815260040160405180910390fd5b60006001600160a01b03821673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee1461075f565b61148c614e6f565b6114968383612c69565b6114cc576040517fc5fc4bf400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60006114d8848461315d565b80516001600160a01b039081166000908152603460209081526040808320828601519094168352928152908290205482518084019093526001600160801b03168252810191909152949350505050565b60006115678260200151602001518360a00151602001516000600281106115515761155161561c565b60200201516001600160a01b0390811691161490565b905060005b838110156118635760008585838181106115885761158861561c565b90506040020160200160208101906115a09190615663565b905060008686848181106115b6576115b661561c565b60409081029290920135600081815260666020528381208451606081019586905292955093909250839060039082845b8154815260200190600101908083116115e6575050505050905060008061160c836131c3565b915091506116238960a001516000015186886132b7565b6000808215158a15151461163d5783516020850151611645565b602084015184515b9150915060008061165b848b8f6040015161334e565b91509150806001600160801b031684600001516001600160801b031610156116af576040517fbb55fd2700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b83518190036001600160801b031684528251829084906116d090839061567e565b6001600160801b03908116909152845160208601519082169116101590506117035782516001600160801b031660208401525b600061170f878761342a565b80518a55602080820151908a01519192501461173057602081015160018a01555b604080820151908901511461174a57604081015160028a01555b8d60a00151602001518661175f576001611762565b60005b60ff16600281106117755761177561561c565b60200201516001600160a01b03168e60a00151602001518761179857600061179b565b60015b60ff16600281106117ae576117ae61561c565b60200201516001600160a01b03168b7f720da23a5c920b1d8827ec83c4d3c4d90d9419eadb0036b88cb4c2ffa91aef7d8a600060200201518b6001602002015160016040516117ff9392919061569e565b60405180910390a4828e60c001818151611819919061567e565b6001600160801b031690525060e08e01805183919061183990839061567e565b6001600160801b031690525061185c9a508b995061355898505050505050505050565b905061156c565b5060008260400151156119315760006118888460c001518560a001516000015161355e565b90508360c001518161189a919061573c565b6001600160801b0380831660c087018190526060870151929450911610156118ee576040517f0699263d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b602080850151516001600160a01b0316600090815260689091526040812080546001600160801b038516929061192590849061575c565b909155506119ef915050565b60006119498460e001518560a0015160000151613595565b9050808460e0015161195b919061573c565b6001600160801b0380831660e087018190526060870151929450911611156119af576040517ff602de8f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6020808501518101516001600160a01b0316600090815260689091526040812080546001600160801b03851692906119e890849061575c565b9091555050505b611a1a83602001516000015184600001518560c001516001600160801b0316866080015160006135cf565b611a3e83602001516020015184600001518560e001516001600160801b03166136f7565b8260200151602001516001600160a01b03168360200151600001516001600160a01b031684600001516001600160a01b03167f95f3b01351225fea0e69a46f68b164c9dea10284f12cd4a907ce66510ab7af6a8660c001518760e00151868960400151604051611ad694939291906001600160801b039485168152928416602084015292166040820152901515606082015260800190565b60405180910390a45050505050565b600161015f55565b611af5614e6f565b6001600160801b0382166000908152603560205260408082208151808301928390529160029082845b81546001600160a01b03168152600190910190602001808311611b1e575050505050905060006001600160a01b031681600060028110611b6057611b6061561c565b60200201516001600160a01b031603611ba5576040517fc5fc4bf400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b604080518082019091526001600160801b03909316835260208301525090565b60005b6002811015610b1257818160028110611be357611be361561c565b608002016000016020810190611bf99190615663565b6001600160801b0316828260028110611c1457611c1461561c565b608002016020016020810190611c2a9190615663565b6001600160801b03161015611c6b576040517f5cef583a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611cb2828260028110611c8057611c8061561c565b608002016040016020810190611c969190615787565b67ffffffffffffffff166601000000000000908190041c151590565b611ce8576040517f6a43f8d100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611d13828260028110611cfd57611cfd61561c565b608002016060016020810190611c969190615787565b611d49576040517f6a43f8d100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600101611bc8565b60008681526066602052604080822081516060810192839052909291839060039082845b815481526020019060010190808311611d755750505050509050600080611d9b836131c3565b604080518082019091529193509150611deb908a60026000835b82821015611de157611dd2608083028501368190038101906157b8565b81526020019060010190611db5565b5050505083613742565b611e21576040517f811cb74a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60408051808201909152600090611e6e908a600284835b82821015611e6457611e55608083028501368190038101906157b8565b81526020019060010190611e38565b505050508361342a565b8051855191925014611e7f57805185555b6020808201519085015114611e9957602081015160018601555b6040808201519085015114611eb357604081015160028601555b6000611ebf89846138a1565b905060005b6002811015612101576000828260028110611ee157611ee161561c565b60200201519050858260028110611efa57611efa61561c565b6020020151516001600160801b03168c8360028110611f1b57611f1b61561c565b608002016000016020810190611f319190615663565b6001600160801b03161015611fa85760008c8360028110611f5457611f5461561c565b608002016000016020810190611f6a9190615663565b878460028110611f7c57611f7c61561c565b602002015151611f8c919061573c565b9050611fa2828c836001600160801b03166136f7565b50612067565b858260028110611fba57611fba61561c565b6020020151516001600160801b03168c8360028110611fdb57611fdb61561c565b608002016000016020810190611ff19190615663565b6001600160801b031611156120675760008683600281106120145761201461561c565b6020020151518d846002811061202c5761202c61561c565b6080020160000160208101906120429190615663565b61204c919061573c565b9050612065828c836001600160801b03168d60016135cf565b505b6000891180156120845750612084816001600160a01b031661145d565b80156120e0575085826002811061209d5761209d61561c565b6020020151516001600160801b03168c83600281106120be576120be61561c565b6080020160000160208101906120d49190615663565b6001600160801b031611155b156120f8576120f86001600160a01b038b168a613924565b50600101611ec4565b50602081015181516040516001600160a01b0392831692909116908e907f720da23a5c920b1d8827ec83c4d3c4d90d9419eadb0036b88cb4c2ffa91aef7d90612153908f9060808201906000906158a2565b60405180910390a4505050505050505050505050565b816121738161287f565b8161217d8161287f565b6001600160a01b03808516908416036121c2576040517fbd969eb000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b50505050565b604080518082019091526000808252602082015260006121fd876020015185602001516000600281106115515761155161561c565b905060005b8581101561233c57600087878381811061221e5761221e61561c565b90506040020160200160208101906122369190615663565b9050600088888481811061224c5761224c61561c565b60409081029290920135600081815260666020528381208451606081019586905292955090939192509060039082845b81548152602001906001019080831161227c57505050505090506000806122a2836131c3565b915091506122b58a6000015185876132b7565b6000811515881515146122c95782516122cf565b60208301515b90506000806122df83898e61334e565b91509150818b6000018181516122f5919061567e565b6001600160801b031690525060208b01805182919061231590839061567e565b6001600160801b0316905250612335975088965061355895505050505050565b9050612202565b5082156123615781518451612351919061355e565b6001600160801b03168252612382565b61237382602001518560000151613595565b6001600160801b031660208301525b5095945050505050565b610cc38133613a3d565b6123a08282613ab2565b600082815260fb602052604090206109de9082613b54565b80516001600160801b03166000908152606760205260408120610ce281612c5f565b6123e48282613b69565b600082815260fb602052604090206109de9082613bec565b600082815260c9602090815260408083206001600160a01b038516845290915290205460ff16610b1257604051634ca8886760e01b815260040160405180910390fd5b620f424063ffffffff82161115610cc3576040517f58d620b300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b81516001600160801b031660009081526069602052604090205463ffffffff90811690821681036124b257505050565b82516001600160801b03166000908152606960209081526040822080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000001663ffffffff861617905580850151908101516001600160a01b03169160200201516001600160a01b03167f831434d05f3ad5f63be733ea463b2933c70d2162697fd200a22b5d56f5c454b6838560405161255e92919063ffffffff92831681529116602082015260400190565b60405180910390a3505050565b60655463ffffffff70010000000000000000000000000000000090910481169082168103612597575050565b606580547fffffffffffffffffffffffff00000000ffffffffffffffffffffffffffffffff1670010000000000000000000000000000000063ffffffff8581169182029290921790925560408051918416825260208201929092527f66db0986e1156e2e747795714bf0301c7e1c695c149a738cb01bcf5cfead8465910160405180910390a15050565b600054610100900460ff1661268c5760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b6064820152608401610aff565b612694613c01565b61269c613c74565b6126a4613ce7565b6126ac613d62565b6113c8613dd5565b60006126c18484846129fc565b80516040517f42966c680000000000000000000000000000000000000000000000000000000081529192506001600160a01b038516916342966c689161270d9160040190815260200190565b600060405180830381600087803b15801561272757600080fd5b505af115801561273b573d6000803e3d6000fd5b5050825160009081526066602052604081208181556001810182905560020155506127639050565b805182516001600160801b0316600090815260676020526040902061278791613e8a565b50604081015151602082015160608301516127b592919060005b6020020151516001600160801b03166136f7565b60408101516020908101519082015160608301516127d692919060016127a1565b604081015160208101516001600160a01b031690600060200201516001600160a01b031682602001516001600160a01b03167f4d5b6e0627ea711d8e9312b6ba56f50e0b51d41816fd6fd38643495ac81d38b6846000015185606001516000600281106128455761284561561c565b6020020151606087015160016020020151604051612865939291906158be565b60405180910390a450505050565b6000610ce28383613e96565b6001600160a01b038116610cc3576040517fe6c4247b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b80600003610cc3576040517f7c946ed700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b038216600090815260686020526040812054808203612923576000915050610a35565b8085111561292f578094505b6129398582615955565b6001600160a01b03851660009081526068602052604090205561295d8484876136f7565b6040516001600160a01b0387811682528691818616918716907f2f4e8fcae66f01952d258445c03f43cf56d3ce389e017ecd2afa8a79e77175889060200160405180910390a45092949350505050565b6001600160801b03811660009081526069602052604081205463ffffffff1680156129d85780610ce2565b5050606554700100000000000000000000000000000000900463ffffffff16919050565b612a04614e97565b6040516331a9108f60e11b8152600481018590526000906001600160a01b03851690636352211e90602401602060405180830381865afa158015612a4c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612a7091906155ff565b600086815260666020526040808220815160608101928390529394509192919060039082845b815481526020019060010190808311612a965750505050509050600080612abc836131c3565b915091506000612acc87836138a1565b604080516080810182528b81526001600160a01b039097166020880152860152505060608301525090509392505050565b612b05614e6f565b612b0f8383612c69565b15612b46576040517fc9bb25eb00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000612b52848461315d565b603354909150600090612b6f906001600160801b0316600161567e565b603380546fffffffffffffffffffffffffffffffff19166001600160801b0383169081179091556000908152603560205260409020909150612bb390836002614ec3565b5081516001600160a01b039081166000908152603460209081526040808320828701805186168552925280832080546fffffffffffffffffffffffffffffffff19166001600160801b0387169081179091559151865191519085169491909116927f6365c594f5448f79c1cc1e6f661bdbf1d16f2e8f85747e13f8e80f1fd168b7c391a46040518060400160405280826001600160801b03168152602001838152509250505092915050565b600061075f825490565b600080612c76848461315d565b80516001600160a01b039081166000908152603460209081526040808320828601519094168352929052908120549192506001600160801b039091169003612cc257600091505061075f565b5060019392505050565b8451600090612d00908487845b608002016000016020810190612cef9190615663565b6001600160801b03168560016135cf565b6020860151612d129084876001612cd9565b606554600090612d2c906001600160801b0316600161567e565b606580546001600160801b0383166fffffffffffffffffffffffffffffffff199182168117909255875192935060009260801b161786516001600160801b03166000908152606760205260409020909150612d879082613ec0565b5087516020870151600091612d9d916001611551565b60408051808201909152909150612deb908960026000835b82821015612de157612dd2608083028501368190038101906157b8565b81526020019060010190612db5565b505050508261342a565b6000838152606660205260409020612e04916003614f2f565b506040517f40c10f190000000000000000000000000000000000000000000000000000000081526001600160a01b038781166004830152602482018490528b16906340c10f1990604401600060405180830381600087803b158015612e6857600080fd5b505af1158015612e7c573d6000803e3d6000fd5b5050505088600160028110612e9357612e9361561c565b602002015189516040516001600160a01b0392831692918216918916907fff24554f8ccfe540435cfc8854831f8dcf1cf2068708cfaf46e8b52a4ccc4c8d90612ee49087908e906080820190615968565b60405180910390a45098975050505050505050565b83516001600160801b03166000908152606760205260408120606091612f1e82612c5f565b9050841580612f2c57508085115b15612f35578094505b84861115612f6f576040517f2cd4dad300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000612f7b8787615955565b905060008167ffffffffffffffff811115612f9857612f986157a2565b604051908082528060200260200182016040528015612fd157816020015b612fbe614e97565b815260200190600190039081612fb65790505b50905060005b82811015613031576000612ff5612fee838c61575c565b8790612873565b905061300281898d6129fc565b8383815181106130145761301461561c565b60200260200101819052505061302a8160010190565b9050612fd7565b5098975050505050505050565b6033546060906001600160801b031660008167ffffffffffffffff811115613068576130686157a2565b6040519080825280602002602001820160405280156130a157816020015b61308e614f5d565b8152602001906001900390816130865790505b50905060005b826001600160801b0316816001600160801b0316101561315657603560006130d083600161567e565b6001600160801b03168152602081019190915260409081016000208151808301928390529160029082845b81546001600160a01b031681526001909101906020018083116130fb57505050505082826001600160801b0316815181106131385761313861561c565b6020026020010181905250808061314e9061598a565b9150506130a7565b5092915050565b613165614f5d565b816001600160a01b0316836001600160a01b0316106131a157604080518082019091526001600160a01b03808416825284166020820152610ce2565b50604080518082019091526001600160a01b0392831681529116602082015290565b6131cb614f7b565b6040805160c0808201835284516001600160801b0390811683850190815260208088018051841660608701528051608090811c67ffffffffffffffff1681880152905190941c60a0860152908452845180840186528751841c8152878601519092168282015260009490840192908201908760026020020151901c67ffffffffffffffff16815260200160c160018860026003811061326c5761326c61561c565b6020020151901b901c67ffffffffffffffff169052905291507f8000000000000000000000000000000000000000000000000000000000000000836002602002015110159050915091565b826001600160801b03166132cb8360801c90565b6001600160801b03161461330b576040517fb7b067f900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b806001600160801b03166000036109de576040517feb1a139600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600080600085600001516001600160801b03169050600086602001516001600160801b0316905060006133a1886040015167ffffffffffffffff1665ffffffffffff811666010000000000009091041b90565b905060006133cf896060015167ffffffffffffffff1665ffffffffffff811666010000000000009091041b90565b905086156133ff576133f56133f0896001600160801b031686868686613ecc565b613fcb565b955087945061341e565b87955061341b6133f0896001600160801b03168686868661404e565b94505b50505050935093915050565b613432614fc1565b604080516060808201835260208681015151875151608091821b6fffffffffffffffffffffffffffffffff19166001600160801b03918216178552885193840151848701519484015160c09190911b7fffffffffffffffff000000000000000000000000000000000000000000000000169490921b77ffffffffffffffff00000000000000000000000000000000169116179190911790820152908101836134db5760006134fd565b7f80000000000000000000000000000000000000000000000000000000000000005b60c086600160200201516060015167ffffffffffffffff16901b608087600160200201516040015167ffffffffffffffff16901b60008860016020020151602001516001600160801b0316901b171717815250905092915050565b60010190565b60008061356a836129ad565b9050610a356133f06001600160801b038616620f424061358a85826159b0565b63ffffffff1661418d565b6000806135a1836129ad565b9050610a356133f06001600160801b0386166135c084620f42406159b0565b63ffffffff16620f42406141f5565b6135e1856001600160a01b031661145d565b1561364a5782821015613620576040517f677606af00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b82821115613645576136456136358484615955565b6001600160a01b03861690613924565b610b62565b8215610b625780156136e257600061366b6001600160a01b038716306142e9565b90506136826001600160a01b038716863087614390565b60006136976001600160a01b038816306142e9565b9050846136a48383615955565b146136db576040517fca3e0a6800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5050610b62565b610b626001600160a01b038616853086614390565b8060000361370457505050565b613716836001600160a01b031661145d565b1561372e576109de6001600160a01b03831682613924565b6109de6001600160a01b03841683836143ba565b6000805b6002811015612cc2578281600281106137615761376161561c565b6020020151516001600160801b03168482600281106137825761378261561c565b6020020151516001600160801b03161415806137e457508281600281106137ab576137ab61561c565b6020020151602001516001600160801b03168482600281106137cf576137cf61561c565b6020020151602001516001600160801b031614155b8061383757508281600281106137fc576137fc61561c565b60200201516040015167ffffffffffffffff168482600281106138215761382161561c565b60200201516040015167ffffffffffffffff1614155b8061388a575082816002811061384f5761384f61561c565b60200201516060015167ffffffffffffffff168482600281106138745761387461561c565b60200201516060015167ffffffffffffffff1614155b1561389957600091505061075f565b600101613746565b6138a9614f5d565b816138b8578260200151610ce2565b604051806040016040528084602001516001600281106138da576138da61561c565b60200201516001600160a01b03166001600160a01b03168152602001846020015160006002811061390d5761390d61561c565b60200201516001600160a01b031690529392505050565b804710156139745760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a20696e73756666696369656e742062616c616e63650000006044820152606401610aff565b6000826001600160a01b03168260405160006040518083038185875af1925050503d80600081146139c1576040519150601f19603f3d011682016040523d82523d6000602084013e6139c6565b606091505b50509050806109de5760405162461bcd60e51b815260206004820152603a60248201527f416464726573733a20756e61626c6520746f2073656e642076616c75652c207260448201527f6563697069656e74206d617920686176652072657665727465640000000000006064820152608401610aff565b600082815260c9602090815260408083206001600160a01b038516845290915290205460ff16610b1257613a708161441f565b613a7b836020614431565b604051602001613a8c929190615a07565b60408051601f198184030181529082905262461bcd60e51b8252610aff91600401615a88565b600082815260c9602090815260408083206001600160a01b038516845290915290205460ff16610b1257600082815260c9602090815260408083206001600160a01b03851684529091529020805460ff19166001179055613b103390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000610ce2836001600160a01b03841661465a565b600082815260c9602090815260408083206001600160a01b038516845290915290205460ff1615610b1257600082815260c9602090815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b6000610ce2836001600160a01b0384166146a9565b600054610100900460ff16613c6c5760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b6064820152608401610aff565b6113c861479c565b600054610100900460ff16613cdf5760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b6064820152608401610aff565b6113c8614807565b600054610100900460ff16613d525760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b6064820152608401610aff565b613d5a61479c565b6113c861487d565b600054610100900460ff16613dcd5760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b6064820152608401610aff565b6113c861494b565b600054610100900460ff16613e405760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b6064820152608401610aff565b6113c87f24a843cae781765d8cdc3bca1cc42497522c0508f4e621c2ca36ceea2fda7b167f2172861495e7b85edac73e3cd5fbb42dd675baadf627720e687bcfdaca0250966149b6565b6000610ce283836146a9565b6000826000018281548110613ead57613ead61561c565b9060005260206000200154905092915050565b6000610ce2838361465a565b600082600003613f3b5781600003613f10576040517f4e305c4b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b613f3486613f25660100000000000080615abb565b613f2f8580615abb565b61418d565b9050613fc2565b66010000000000008402858402838602016000613f58868a615abb565b613f629083615955565b90506000613f708485614a01565b90506000613f7e8484614a01565b90506000613f8c8383614a30565b90506000613f9b87888461418d565b90506000613faa8787856141f5565b9050613fb78e838361418d565b985050505050505050505b95945050505050565b60006001600160801b0382111561404a5760405162461bcd60e51b815260206004820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203160448201527f32382062697473000000000000000000000000000000000000000000000000006064820152608401610aff565b5090565b6000826000036140b65781600003614092576040517f4e305c4b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b613f34866140a08480615abb565b6140b1660100000000000080615abb565b6141f5565b660100000000000084028584028386020160006140d38983615abb565b905060006140e18485614a01565b905060006140ef8389614a01565b905060006140fd8383614a30565b9050600061410c87888461418d565b9050600061411b868c8561418d565b905060008061412a8484614a46565b9150915081156141595761414889614142878b615ad2565b836141f5565b9a5050505050505050505050613fc2565b6141648a8b8a61418d565b61416e908e61575c565b614178908a615ad2565b9a505050505050505050505095945050505050565b60008061419b8585856141f5565b905060006141aa868686614a6f565b1115610a355760001981106141eb576040517f35278d1200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001019050610ce2565b60008060006142048686614a8a565b91509150816000036142295783818161421f5761421f6159cd565b0492505050610ce2565b838210614262576040517f35278d1200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600061426f878787614a6f565b905060008061427f858585614ac3565b91509150816000036142a75786818161429a5761429a6159cd565b0495505050505050610ce2565b60008781038816906142ba848484614af3565b905060006142d6838b816142d0576142d06159cd565b04614b30565b919091029b9a5050505050505050505050565b60006142f48361145d565b1561430a57506001600160a01b0381163161075f565b826040517f70a082310000000000000000000000000000000000000000000000000000000081526001600160a01b03848116600483015291909116906370a0823190602401602060405180830381865afa15801561436c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ce29190615af4565b8015806143a157506143a18461145d565b6121c2576121c26001600160a01b038516848484614b51565b806000036143c757505050565b6143d08361145d565b1561440b576040516001600160a01b0383169082156108fc029083906000818181858888f193505050501580156121c2573d6000803e3d6000fd5b6109de6001600160a01b0384168383614c02565b606061075f6001600160a01b03831660145b60606000614440836002615abb565b61444b90600261575c565b67ffffffffffffffff811115614463576144636157a2565b6040519080825280601f01601f19166020018201604052801561448d576020820181803683370190505b5090507f3000000000000000000000000000000000000000000000000000000000000000816000815181106144c4576144c461561c565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053507f7800000000000000000000000000000000000000000000000000000000000000816001815181106145275761452761561c565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053506000614563846002615abb565b61456e90600161575c565b90505b600181111561460b577f303132333435363738396162636465660000000000000000000000000000000085600f16601081106145af576145af61561c565b1a60f81b8282815181106145c5576145c561561c565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535060049490941c9361460481615b0d565b9050614571565b508315610ce25760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610aff565b60008181526001830160205260408120546146a15750815460018181018455600084815260208082209093018490558454848252828601909352604090209190915561075f565b50600061075f565b600081815260018301602052604081205480156147925760006146cd600183615955565b85549091506000906146e190600190615955565b90508181146147465760008660000182815481106147015761470161561c565b90600052602060002001549050808760000184815481106147245761472461561c565b6000918252602080832090910192909255918252600188019052604090208390555b855486908061475757614757615b24565b60019003818190600052602060002001600090559055856001016000868152602001908152602001600020600090556001935050505061075f565b600091505061075f565b600054610100900460ff166113c85760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b6064820152608401610aff565b600054610100900460ff166148725760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b6064820152608401610aff565b6113c8610fa061256b565b600054610100900460ff166148e85760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b6064820152608401610aff565b61012d805461ffff191660061790556149217f2172861495e7b85edac73e3cd5fbb42dd675baadf627720e687bcfdaca025096806149b6565b6113c87f2172861495e7b85edac73e3cd5fbb42dd675baadf627720e687bcfdaca02509633614c4b565b600054610100900460ff16611ae55760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b6064820152608401610aff565b600082815260c96020526040808220600101805490849055905190918391839186917fbd79b86ffe0ab8e8776151514217cd7cacd52c909f66475c3af44e129f0b00ff9190a4505050565b6000806000614a108585614a8a565b9150915080198211614a255781600101613fc2565b506002019392505050565b6000818311614a3f5781610ce2565b5090919050565b60008083830184811015614a61576000809250925050614a68565b6001925090505b9250929050565b60008180614a7f57614a7f6159cd565b838509949350505050565b6000806000614a998585614c55565b9050848402808210614ab2579081900392509050614a68565b600181830303969095509350505050565b600080828410614ad95750839050818303614aeb565b614ae4600186615955565b9150508183035b935093915050565b600080614b118380830381614b0a57614b0a6159cd565b0460010190565b9050828481614b2257614b226159cd565b048186021795945050505050565b60006001815b60088110156131565783820260020382029150600101614b36565b6040516001600160a01b03808516602483015283166044820152606481018290526121c29085907f23b872dd00000000000000000000000000000000000000000000000000000000906084015b60408051601f198184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff0000000000000000000000000000000000000000000000000000000090931692909217909152614c64565b6040516001600160a01b0383166024820152604481018290526109de9084907fa9059cbb0000000000000000000000000000000000000000000000000000000090606401614b9e565b610b128282612396565b60006000198284099392505050565b6000614cb9826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316614d4c9092919063ffffffff16565b9050805160001480614cda575080806020019051810190614cda9190615b3a565b6109de5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f742073756363656564000000000000000000000000000000000000000000006064820152608401610aff565b6060610a35848460008585600080866001600160a01b03168587604051614d739190615b57565b60006040518083038185875af1925050503d8060008114614db0576040519150601f19603f3d011682016040523d82523d6000602084013e614db5565b606091505b5091509150614dc687838387614dd1565b979650505050505050565b60608315614e40578251600003614e39576001600160a01b0385163b614e395760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610aff565b5081610a35565b610a358383815115614e555781518083602001fd5b8060405162461bcd60e51b8152600401610aff9190615a88565b604051806040016040528060006001600160801b03168152602001614e92614f5d565b905290565b6040805160808101825260008082526020820152908101614eb6614f5d565b8152602001614e92614f7b565b8260028101928215614f23579160200282015b82811115614f2357825182547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b03909116178255602090920191600190910190614ed6565b5061404a929150614fdf565b8260038101928215614f23579160200282015b82811115614f23578251825591602001919060010190614f42565b60405180604001604052806002906020820280368337509192915050565b60405180604001604052806002905b604080516080810182526000808252602080830182905292820181905260608201528252600019909201910181614f8a5790505090565b60405180606001604052806003906020820280368337509192915050565b5b8082111561404a5760008155600101614fe0565b60006020828403121561500657600080fd5b81357fffffffff0000000000000000000000000000000000000000000000000000000081168114610ce257600080fd5b6001600160a01b0381168114610cc357600080fd5b60008083601f84011261505d57600080fd5b50813567ffffffffffffffff81111561507557600080fd5b6020830191508360208260061b8501011115614a6857600080fd5b80356001600160801b03811681146150a757600080fd5b919050565b60008060008060008060a087890312156150c557600080fd5b86356150d081615036565b955060208701356150e081615036565b9450604087013567ffffffffffffffff8111156150fc57600080fd5b61510889828a0161504b565b9095509350506060870135915061512160808801615090565b90509295509295509295565b80610100810183101561075f57600080fd5b6000806000610220848603121561515557600080fd5b83359250615166856020860161512d565b915061517685610120860161512d565b90509250925092565b60006020828403121561519157600080fd5b5035919050565b600080600080606085870312156151ae57600080fd5b84356151b981615036565b935060208501356151c981615036565b9250604085013567ffffffffffffffff8111156151e557600080fd5b6151f18782880161504b565b95989497509550505050565b6000806040838503121561521057600080fd5b82359150602083013561522281615036565b809150509250929050565b6000806040838503121561524057600080fd5b823561524b81615036565b9150602083013561522281615036565b803563ffffffff811681146150a757600080fd5b60008060006060848603121561528457600080fd5b833561528f81615036565b9250602084013561529f81615036565b91506151766040850161525b565b6000602082840312156152bf57600080fd5b610ce28261525b565b8060005b60028110156121c25781516001600160a01b03168452602093840193909101906001016152cc565b81516001600160801b031681526020808301516060830191613156908401826152c8565b6000806040838503121561532b57600080fd5b50508035926020909101359150565b60008060006060848603121561534f57600080fd5b833561535a81615036565b925060208401359150604084013561537181615036565b809150509250925092565b8051825260206001600160a01b0381830151168184015260408201516153a560408501826152c8565b506060820151608080850160005b6002811015615415576154058285516001600160801b0380825116835280602083015116602084015250604081015167ffffffffffffffff808216604085015280606084015116606085015250505050565b92840192908201906001016153b3565b50505050505050565b610180810161075f828461537c565b8015158114610cc357600080fd5b60008060006040848603121561545057600080fd5b833561545b8161542d565b9250602084013567ffffffffffffffff8082111561547857600080fd5b818601915086601f83011261548c57600080fd5b81358181111561549b57600080fd5b8760208285010111156154ad57600080fd5b6020830194508093505050509250925092565b600080600061014084860312156154d657600080fd5b83356154e181615036565b925060208401356154f181615036565b9150615176856040860161512d565b6000806000806080858703121561551657600080fd5b843561552181615036565b9350602085013561553181615036565b93969395505050506040820135916060013590565b6020808252825182820181905260009190848201906040850190845b818110156155895761557583855161537c565b928401926101809290920191600101615562565b50909695505050505050565b6000602082840312156155a757600080fd5b8135610ce281615036565b602080825282518282018190526000919060409081850190868401855b828110156155f2576155e28483516152c8565b92840192908501906001016155cf565b5091979650505050505050565b60006020828403121561561157600080fd5b8151610ce281615036565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b61ffff81811683821601908082111561315657613156615632565b60006020828403121561567557600080fd5b610ce282615090565b6001600160801b0381811683821601908082111561315657613156615632565b61012081016156eb82866001600160801b0380825116835280602083015116602084015250604081015167ffffffffffffffff808216604085015280606084015116606085015250505050565b83516001600160801b03908116608084015260208501511660a0830152604084015167ffffffffffffffff90811660c084015260608501511660e08301525b60ff8316610100830152949350505050565b6001600160801b0382811682821603908082111561315657613156615632565b8082018082111561075f5761075f615632565b803567ffffffffffffffff811681146150a757600080fd5b60006020828403121561579957600080fd5b610ce28261576f565b634e487b7160e01b600052604160045260246000fd5b6000608082840312156157ca57600080fd5b6040516080810181811067ffffffffffffffff821117156157fb57634e487b7160e01b600052604160045260246000fd5b60405261580783615090565b815261581560208401615090565b60208201526158266040840161576f565b60408201526158376060840161576f565b60608201529392505050565b6001600160801b038061585583615090565b1683528061586560208401615090565b166020840152506158786040820161576f565b67ffffffffffffffff8082166040850152806158966060850161576f565b16606085015250505050565b61012081016158b18286615843565b61572a6080830185615843565b838152610120810161591160208301856001600160801b0380825116835280602083015116602084015250604081015167ffffffffffffffff808216604085015280606084015116606085015250505050565b82516001600160801b0390811660a084015260208401511660c0830152604083015167ffffffffffffffff90811660e0840152606084015116610100830152610a35565b8181038181111561075f5761075f615632565b838152610120810161597d6020830185615843565b610a3560a0830184615843565b60006001600160801b038083168181036159a6576159a6615632565b6001019392505050565b63ffffffff82811682821603908082111561315657613156615632565b634e487b7160e01b600052601260045260246000fd5b60005b838110156159fe5781810151838201526020016159e6565b50506000910152565b7f416363657373436f6e74726f6c3a206163636f756e7420000000000000000000815260008351615a3f8160178501602088016159e3565b7f206973206d697373696e6720726f6c65200000000000000000000000000000006017918401918201528351615a7c8160288401602088016159e3565b01602801949350505050565b6020815260008251806020840152615aa78160408501602087016159e3565b601f01601f19169190910160400192915050565b808202811582820484141761075f5761075f615632565b600082615aef57634e487b7160e01b600052601260045260246000fd5b500490565b600060208284031215615b0657600080fd5b5051919050565b600081615b1c57615b1c615632565b506000190190565b634e487b7160e01b600052603160045260246000fd5b600060208284031215615b4c57600080fd5b8151610ce28161542d565b60008251615b698184602087016159e3565b919091019291505056fea164736f6c6343000813000a

Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)

000000000000000000000000248594be9be605905b8912cf575f03fe42d8905400000000000000000000000010fa549e70ede76c258c0808b289e4ac3c9ab2e2

-----Decoded View---------------
Arg [0] : initVoucher (address): 0x248594Be9BE605905B8912cf575f03fE42d89054
Arg [1] : proxy (address): 0x10Fa549E70Ede76C258c0808b289e4Ac3c9ab2e2

-----Encoded View---------------
2 Constructor Arguments found :
Arg [0] : 000000000000000000000000248594be9be605905b8912cf575f03fe42d89054
Arg [1] : 00000000000000000000000010fa549e70ede76c258c0808b289e4ac3c9ab2e2


Block Transaction 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

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.