S Price: $0.068231 (+2.13%)
Gas: 55 Gwei

Contract

0xcDF6378643f0b32442Eb558E1732343337a9DF36

Overview

S Balance

Sonic LogoSonic LogoSonic Logo0 S

S Value

$0.00

More Info

Private Name Tags

Multichain Info

No addresses found
Transaction Hash
Block
From
To

There are no matching entries

Please try again later

View more zero value Internal Transactions in Advanced View mode

Advanced mode:
Cross-Chain Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
Factory

Compiler Version
v0.8.28+commit.7893614a

Optimization Enabled:
Yes with 200 runs

Other Settings:
cancun EvmVersion
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;

import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {ReentrancyGuardUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol";
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import {Controllable} from "./base/Controllable.sol";
import {IControllable} from "../interfaces/IControllable.sol";
import {CommonLib} from "./libs/CommonLib.sol";
import {FactoryLib} from "./libs/FactoryLib.sol";
import {FactoryNamingLib} from "./libs/FactoryNamingLib.sol";
import {DeployerLib} from "./libs/DeployerLib.sol";
import {VaultStatusLib} from "./libs/VaultStatusLib.sol";
import {IFactory} from "../interfaces/IFactory.sol";
import {IPlatform} from "../interfaces/IPlatform.sol";
import {IVault} from "../interfaces/IVault.sol";
import {IVaultProxy} from "../interfaces/IVaultProxy.sol";
import {IStrategy} from "../interfaces/IStrategy.sol";
import {IStrategyProxy} from "../interfaces/IStrategyProxy.sol";
import {IVaultManager} from "../interfaces/IVaultManager.sol";
import {IStrategyLogic} from "../interfaces/IStrategyLogic.sol";

/// @notice Platform factory assembling vaults. Stores vault settings, strategy logic, farms.
///         Provides the opportunity to upgrade vaults and strategies.
/// Changelog:
///   2.0.0: BREAKING CHANGES
///          * Removed `setVaultConfig` from IFactory; added `setVaultImplementation`
///          * Removed `setStrategyLogicConfig` from IFactory; added `setStrategyImplementation`
///   1.3.1: setStrategyImplementation added to interface
///   1.3.0: vault can be built only by admin; setVaultImplementation, setStrategyImplementation;
///          remove setAliasName, getAliasName, whatToBuild; remove RVault and RMVault support
///   1.2.0: reduced factory size. moved upgradeStrategyProxy, upgradeVaultProxy logic to FactoryLib
///   1.1.0: getDeploymentKey fix for not farming strategies, strategyAvailableInitParams
/// @author Alien Deployer (https://github.com/a17)
/// @author Jude (https://github.com/iammrjude)
/// @author JodsMigel (https://github.com/JodsMigel)
/// @author HCrypto7 (https://github.com/hcrypto7)
contract Factory is Controllable, ReentrancyGuardUpgradeable, IFactory {
    using SafeERC20 for IERC20;
    using EnumerableSet for EnumerableSet.Bytes32Set;

    //region ----- Constants -----

    /// @inheritdoc IControllable
    string public constant VERSION = "2.0.0";

    uint internal constant _WEEK = 60 * 60 * 24 * 7;

    uint internal constant _PERMIT_PER_WEEK = 1;

    // keccak256(abi.encode(uint256(keccak256("erc7201:stability.Factory")) - 1)) & ~bytes32(uint256(0xff));
    bytes32 private constant FACTORY_STORAGE_LOCATION =
        0x94b53192a2415b53b438d03f0efa946204c0118192627e3d5ed4ba034c9a0300;

    //endregion -- Constants -----

    //region ----- Data types -----

    struct DeployVaultAndStrategyVars {
        VaultConfig vaultConfig;
        bytes32 strategyIdHash;
        address platform;
        address[] assets;
        string[] assetsSymbols;
        string name;
        string specificName;
        string symbol;
        bytes32 deploymentKey;
        uint vaultManagerTokenId;
    }

    //endregion -- Data types -----

    //region ----- Init -----

    function initialize(address platform_) public initializer {
        __Controllable_init(platform_);
        __ReentrancyGuard_init();
    }

    //endregion -- Init -----

    //region ----- Restricted actions -----

    /// @inheritdoc IFactory
    function setVaultImplementation(string memory vaultType, address implementation) external onlyOperator {
        FactoryStorage storage $ = _getStorage();
        if (FactoryLib.setVaultImplementation($, vaultType, implementation)) {
            _requireGovernanceOrMultisig();
        }
    }

    /// @inheritdoc IFactory
    function setStrategyImplementation(string memory strategyId, address implementation) external onlyOperator {
        FactoryStorage storage $ = _getStorage();
        if (FactoryLib.setStrategyImplementation($, platform(), strategyId, implementation)) {
            _requireGovernanceOrMultisig();
        }
    }

    /// @inheritdoc IFactory
    function setVaultStatus(address[] memory vaults, uint[] memory statuses) external onlyGovernanceOrMultisig {
        FactoryStorage storage $ = _getStorage();
        uint len = vaults.length;
        for (uint i; i < len; ++i) {
            $.vaultStatus[vaults[i]] = statuses[i];
            emit VaultStatus(vaults[i], statuses[i]);
        }
    }

    /// @inheritdoc IFactory
    function addFarms(Farm[] memory farms_) external onlyOperator {
        FactoryStorage storage $ = _getStorage();
        uint len = farms_.length;
        // nosemgrep
        for (uint i = 0; i < len; ++i) {
            $.farms.push(farms_[i]);
        }
        emit NewFarm(farms_);
    }

    /// @inheritdoc IFactory
    function updateFarm(uint id, Farm memory farm_) external onlyOperator {
        FactoryStorage storage $ = _getStorage();
        $.farms[id] = farm_;
        emit UpdateFarm(id, farm_);
    }

    /// @inheritdoc IFactory
    function setStrategyAvailableInitParams(
        string memory id,
        StrategyAvailableInitParams memory initParams
    ) external onlyOperator {
        FactoryStorage storage $ = _getStorage();
        bytes32 idHash = keccak256(abi.encodePacked(id));
        $.strategyAvailableInitParams[idHash] = initParams;
        emit SetStrategyAvailableInitParams(id, initParams.initAddresses, initParams.initNums, initParams.initTicks);
    }

    /// @inheritdoc IFactory
    //slither-disable-next-line cyclomatic-complexity reentrancy-benign
    function deployVaultAndStrategy(
        string memory vaultType,
        string memory strategyId,
        address[] memory vaultInitAddresses,
        uint[] memory vaultInitNums,
        address[] memory strategyInitAddresses,
        uint[] memory strategyInitNums,
        int24[] memory strategyInitTicks
    ) external onlyOperator returns (address vault, address strategy) {
        FactoryStorage storage $ = _getStorage();
        //slither-disable-next-line uninitialized-local
        DeployVaultAndStrategyVars memory vars;
        vars.vaultConfig = $.vaultConfig[keccak256(abi.encodePacked(vaultType))];
        if (vars.vaultConfig.implementation == address(0)) {
            revert VaultImplementationIsNotAvailable();
        }
        vars.strategyIdHash = keccak256(bytes(strategyId));
        vars.platform = platform();

        StrategyLogicConfig storage config = $.strategyLogicConfig[vars.strategyIdHash];
        if (config.implementation == address(0)) {
            revert StrategyImplementationIsNotAvailable();
        }

        {
            IVaultProxy vaultProxy = IVaultProxy(DeployerLib.deployVaultProxy());
            vaultProxy.initProxy(vaultType);
            IStrategyProxy strategyProxy = IStrategyProxy(DeployerLib.deployStrategyProxy());
            strategyProxy.initStrategyProxy(strategyId);
            vault = address(vaultProxy);
            strategy = address(strategyProxy);
        }

        {
            uint addressesLength = strategyInitAddresses.length;
            address[] memory initStrategyAddresses = new address[](2 + addressesLength);
            initStrategyAddresses[0] = vars.platform;
            initStrategyAddresses[1] = vault;
            // nosemgrep
            for (uint i = 2; i < 2 + addressesLength; ++i) {
                initStrategyAddresses[i] = strategyInitAddresses[i - 2];
            }

            IStrategy(strategy).initialize(initStrategyAddresses, strategyInitNums, strategyInitTicks);

            // 3 addresses for not using exchangeAsset and other addresses in unique deployment key
            vars.deploymentKey = getDeploymentKey(
                vaultType,
                strategyId,
                vaultInitAddresses,
                vaultInitNums,
                strategyInitAddresses,
                strategyInitNums,
                strategyInitTicks
            );
            if ($.deploymentKey[vars.deploymentKey] != address(0)) {
                revert SuchVaultAlreadyDeployed(vars.deploymentKey);
            }
        }

        (, vars.assets, vars.assetsSymbols, vars.specificName, vars.symbol) =
            getStrategyData(vaultType, strategy, vaultInitAddresses.length > 0 ? vaultInitAddresses[0] : address(0));
        vars.name = FactoryLib.getName(
            vaultType, strategyId, CommonLib.implode(vars.assetsSymbols, "-"), vars.specificName, vaultInitAddresses
        );

        vars.vaultManagerTokenId = IVaultManager(IPlatform(vars.platform).vaultManager()).mint(msg.sender, vault);

        IVault(vault)
            .initialize(
                IVault.VaultInitializationData({
                    platform: vars.platform,
                    strategy: strategy,
                    name: vars.name,
                    symbol: vars.symbol,
                    tokenId: vars.vaultManagerTokenId,
                    vaultInitAddresses: vaultInitAddresses,
                    vaultInitNums: vaultInitNums
                })
            );

        $.deployedVaults.push(vault);
        $.vaultStatus[vault] = VaultStatusLib.ACTIVE;
        $.isStrategy[strategy] = true;
        $.deploymentKey[vars.deploymentKey] = vault;

        emit VaultAndStrategy(
            msg.sender,
            vaultType,
            strategyId,
            vault,
            strategy,
            vars.name,
            vars.symbol,
            vars.assets,
            vars.deploymentKey,
            vars.vaultManagerTokenId
        );
    }

    //endregion -- Restricted actions ----

    //region ----- User actions -----

    /// @inheritdoc IFactory
    function upgradeVaultProxy(address vault) external nonReentrant {
        FactoryStorage storage $ = _getStorage();
        if ($.vaultStatus[vault] != VaultStatusLib.ACTIVE) {
            revert NotActiveVault();
        }
        FactoryLib.upgradeVaultProxy($, vault);
    }

    /// @inheritdoc IFactory
    function upgradeStrategyProxy(address strategyProxy) external nonReentrant {
        FactoryStorage storage $ = _getStorage();
        if (!$.isStrategy[strategyProxy]) {
            revert NotStrategy();
        }
        FactoryLib.upgradeStrategyProxy($, strategyProxy);
    }

    //endregion -- User actions ----

    //region ----- View functions -----

    /// @inheritdoc IFactory
    //slither-disable-next-line calls-loop
    function vaultTypes()
        external
        view
        returns (
            string[] memory vaultType,
            address[] memory implementation,
            bool[] memory deployAllowed,
            bool[] memory upgradeAllowed,
            uint[] memory buildingPrice,
            bytes32[] memory extra
        )
    {
        FactoryStorage storage $ = _getStorage();
        bytes32[] memory hashes = $.vaultTypeHashes.values();
        uint len = hashes.length;
        vaultType = new string[](len);
        implementation = new address[](len);
        deployAllowed = new bool[](len);
        upgradeAllowed = new bool[](len);
        buildingPrice = new uint[](len);
        extra = new bytes32[](len);
        // nosemgrep
        for (uint i; i < len; ++i) {
            VaultConfig memory config = $.vaultConfig[hashes[i]];
            vaultType[i] = config.vaultType;
            implementation[i] = config.implementation;
            deployAllowed[i] = config.deployAllowed;
            upgradeAllowed[i] = config.upgradeAllowed;
            buildingPrice[i] = config.buildingPrice;
            extra[i] = IVault(config.implementation).extra();
        }
    }

    /// @inheritdoc IFactory
    //slither-disable-next-line calls-loop
    function strategies()
        external
        view
        returns (
            string[] memory id,
            bool[] memory deployAllowed,
            bool[] memory upgradeAllowed,
            bool[] memory farming,
            uint[] memory tokenId,
            string[] memory tokenURI,
            bytes32[] memory extra
        )
    {
        FactoryStorage storage $ = _getStorage();
        bytes32[] memory hashes = $.strategyLogicIdHashes.values();
        uint len = hashes.length;
        id = new string[](len);
        deployAllowed = new bool[](len);
        upgradeAllowed = new bool[](len);
        farming = new bool[](len);
        tokenId = new uint[](len);
        tokenURI = new string[](len);
        extra = new bytes32[](len);
        IStrategyLogic strategyLogicNft = IStrategyLogic(IPlatform(platform()).strategyLogic());
        // nosemgrep
        for (uint i; i < len; ++i) {
            StrategyLogicConfig memory config = $.strategyLogicConfig[hashes[i]];
            id[i] = config.id;
            deployAllowed[i] = config.deployAllowed;
            upgradeAllowed[i] = config.upgradeAllowed;
            farming[i] = config.farming;
            tokenId[i] = config.tokenId;
            tokenURI[i] = strategyLogicNft.tokenURI(config.tokenId);
            extra[i] = IStrategy(config.implementation).extra();
        }
    }

    /// @inheritdoc IFactory
    function deployedVaultsLength() external view returns (uint) {
        FactoryStorage storage $ = _getStorage();
        return $.deployedVaults.length;
    }

    /// @inheritdoc IFactory
    function deployedVaults() external view returns (address[] memory) {
        FactoryStorage storage $ = _getStorage();
        return $.deployedVaults;
    }

    /// @inheritdoc IFactory
    function deployedVault(uint id) external view returns (address) {
        FactoryStorage storage $ = _getStorage();
        return $.deployedVaults[id];
    }

    /// @inheritdoc IFactory
    function farmsLength() external view returns (uint) {
        FactoryStorage storage $ = _getStorage();
        return $.farms.length;
    }

    /// @inheritdoc IFactory
    function farms() external view returns (Farm[] memory) {
        FactoryStorage storage $ = _getStorage();
        return $.farms;
    }

    /// @inheritdoc IFactory
    function strategyLogicIdHashes() external view returns (bytes32[] memory) {
        FactoryStorage storage $ = _getStorage();
        return $.strategyLogicIdHashes.values();
    }

    /// @inheritdoc IFactory
    function farm(uint id) external view returns (Farm memory) {
        FactoryStorage storage $ = _getStorage();
        return $.farms[id];
    }

    /// @inheritdoc IFactory
    function getStrategyData(
        string memory vaultType,
        address strategyAddress,
        address bbAsset
    )
        public
        view
        returns (
            string memory strategyId,
            address[] memory assets,
            string[] memory assetsSymbols,
            string memory specificName,
            string memory vaultSymbol
        )
    {
        //slither-disable-next-line unused-return
        return FactoryNamingLib.getStrategyData(vaultType, strategyAddress, bbAsset, platform());
    }

    /// @inheritdoc IFactory
    function getExchangeAssetIndex(address[] memory assets) external view returns (uint) {
        //slither-disable-next-line unused-return
        return FactoryLib.getExchangeAssetIndex(platform(), assets);
    }

    /// @inheritdoc IFactory
    function getDeploymentKey(
        string memory vaultType,
        string memory strategyId,
        address[] memory initVaultAddresses,
        uint[] memory initVaultNums,
        address[] memory initStrategyAddresses,
        uint[] memory initStrategyNums,
        int24[] memory initStrategyTicks
    ) public pure returns (bytes32) {
        //slither-disable-next-line unused-return
        return FactoryLib.getDeploymentKey(
            vaultType,
            strategyId,
            initVaultAddresses,
            initVaultNums,
            initStrategyAddresses,
            initStrategyNums,
            initStrategyTicks,
            [1, 0, 1, 1, 0]
        );
    }

    /// @inheritdoc IFactory
    function deploymentKey(bytes32 deploymentKey_) external view returns (address) {
        FactoryStorage storage $ = _getStorage();
        return $.deploymentKey[deploymentKey_];
    }

    /// @inheritdoc IFactory
    function strategyLogicConfig(bytes32 idHash) external view returns (StrategyLogicConfig memory config) {
        FactoryStorage storage $ = _getStorage();
        config = $.strategyLogicConfig[idHash];
    }

    /// @inheritdoc IFactory
    function vaultConfig(bytes32 typeHash)
        external
        view
        returns (
            string memory vaultType,
            address implementation,
            bool deployAllowed,
            bool upgradeAllowed,
            uint buildingPrice
        )
    {
        FactoryStorage storage $ = _getStorage();
        VaultConfig memory vaultConfig_ = $.vaultConfig[typeHash];
        (vaultType, implementation, deployAllowed, upgradeAllowed, buildingPrice) = (
            vaultConfig_.vaultType,
            vaultConfig_.implementation,
            vaultConfig_.deployAllowed,
            vaultConfig_.upgradeAllowed,
            vaultConfig_.buildingPrice
        );
    }

    /// @inheritdoc IFactory
    function vaultStatus(address vault) external view returns (uint status) {
        FactoryStorage storage $ = _getStorage();
        status = $.vaultStatus[vault];
    }

    /// @inheritdoc IFactory
    function isStrategy(address address_) external view returns (bool) {
        return _getStorage().isStrategy[address_];
    }

    /// @inheritdoc IFactory
    function strategyAvailableInitParams(bytes32 idHash) external view returns (StrategyAvailableInitParams memory) {
        FactoryStorage storage $ = _getStorage();
        return $.strategyAvailableInitParams[idHash];
    }

    //endregion -- View functions -----

    //region ----- Internal logic -----

    function _getStorage() private pure returns (FactoryStorage storage $) {
        //slither-disable-next-line assembly
        assembly {
            $.slot := FACTORY_STORAGE_LOCATION
        }
    }

    //endregion -- Internal logic -----
}

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

pragma solidity ^0.8.20;

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

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

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

    /**
     * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeTransfer(IERC20 token, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeCall(token.transfer, (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.encodeCall(token.transferFrom, (from, to, value)));
    }

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

    /**
     * @dev Variant of {safeTransferFrom} that returns a bool instead of reverting if the operation is not successful.
     */
    function trySafeTransferFrom(IERC20 token, address from, address to, uint256 value) internal returns (bool) {
        return _callOptionalReturnBool(token, abi.encodeCall(token.transferFrom, (from, to, 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.
     *
     * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
     * smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
     * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
     * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
     */
    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 oldAllowance = token.allowance(address(this), spender);
        forceApprove(token, spender, oldAllowance + value);
    }

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

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

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

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

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

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

    /**
     * @dev 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 {_callOptionalReturnBool} that reverts if call fails to meet the requirements.
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        uint256 returnSize;
        uint256 returnValue;
        assembly ("memory-safe") {
            let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
            // bubble errors
            if iszero(success) {
                let ptr := mload(0x40)
                returndatacopy(ptr, 0, returndatasize())
                revert(ptr, returndatasize())
            }
            returnSize := returndatasize()
            returnValue := mload(0)
        }

        if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 1) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @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 silently catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
        bool success;
        uint256 returnSize;
        uint256 returnValue;
        assembly ("memory-safe") {
            success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
            returnSize := returndatasize()
            returnValue := mload(0)
        }
        return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1);
    }
}

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

pragma solidity >=0.4.16;

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

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

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

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

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

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

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

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

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

pragma solidity ^0.8.20;
import {Initializable} from "../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 EIP-1153 (transient storage) is available on the chain you're deploying at,
 * consider using {ReentrancyGuardTransient} instead.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
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;

    /// @custom:storage-location erc7201:openzeppelin.storage.ReentrancyGuard
    struct ReentrancyGuardStorage {
        uint256 _status;
    }

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

    function _getReentrancyGuardStorage() private pure returns (ReentrancyGuardStorage storage $) {
        assembly {
            $.slot := ReentrancyGuardStorageLocation
        }
    }

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

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

    function __ReentrancyGuard_init_unchained() internal onlyInitializing {
        ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
        $._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 {
        ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
        // On the first call to nonReentrant, _status will be NOT_ENTERED
        if ($._status == ENTERED) {
            revert ReentrancyGuardReentrantCall();
        }

        // Any calls to nonReentrant after this point will fail
        $._status = ENTERED;
    }

    function _nonReentrantAfter() private {
        ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
        // 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) {
        ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
        return $._status == ENTERED;
    }
}

File 5 of 48 : EnumerableSet.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (utils/structs/EnumerableSet.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.

pragma solidity ^0.8.20;

import {Arrays} from "../Arrays.sol";
import {Math} from "../math/Math.sol";

/**
 * @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.
 * - Set can be cleared (all elements removed) in O(n).
 *
 * ```solidity
 * contract Example {
 *     // Add the library methods
 *     using EnumerableSet for EnumerableSet.AddressSet;
 *
 *     // Declare a set state variable
 *     EnumerableSet.AddressSet private mySet;
 * }
 * ```
 *
 * The following types are supported:
 *
 * - `bytes32` (`Bytes32Set`) since v3.3.0
 * - `address` (`AddressSet`) since v3.3.0
 * - `uint256` (`UintSet`) since v3.3.0
 * - `string` (`StringSet`) since v5.4.0
 * - `bytes` (`BytesSet`) since v5.4.0
 *
 * [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 EnumerableSet {
    // 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 is the index of the value in the `values` array plus 1.
        // Position 0 is used to mean a value is not in the set.
        mapping(bytes32 value => uint256) _positions;
    }

    /**
     * @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._positions[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 cache the value's position to prevent multiple reads from the same storage slot
        uint256 position = set._positions[value];

        if (position != 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 valueIndex = position - 1;
            uint256 lastIndex = set._values.length - 1;

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

                // Move the lastValue to the index where the value to delete is
                set._values[valueIndex] = lastValue;
                // Update the tracked position of the lastValue (that was just moved)
                set._positions[lastValue] = position;
            }

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

            // Delete the tracked position for the deleted slot
            delete set._positions[value];

            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Removes all the values from a set. O(n).
     *
     * WARNING: This function has an unbounded cost that scales with set size. Developers should keep in mind that
     * using it may render the function uncallable if the set grows to the point where clearing it consumes too much
     * gas to fit in a block.
     */
    function _clear(Set storage set) private {
        uint256 len = _length(set);
        for (uint256 i = 0; i < len; ++i) {
            delete set._positions[set._values[i]];
        }
        Arrays.unsafeSetLength(set._values, 0);
    }

    /**
     * @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._positions[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;
    }

    /**
     * @dev Return a slice of the 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, uint256 start, uint256 end) private view returns (bytes32[] memory) {
        unchecked {
            end = Math.min(end, _length(set));
            start = Math.min(start, end);

            uint256 len = end - start;
            bytes32[] memory result = new bytes32[](len);
            for (uint256 i = 0; i < len; ++i) {
                result[i] = Arrays.unsafeAccess(set._values, start + i).value;
            }
            return result;
        }
    }

    // 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 Removes all the values from a set. O(n).
     *
     * WARNING: Developers should keep in mind that this function has an unbounded cost and using it may render the
     * function uncallable if the set grows to the point where clearing it consumes too much gas to fit in a block.
     */
    function clear(Bytes32Set storage set) internal {
        _clear(set._inner);
    }

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

        assembly ("memory-safe") {
            result := store
        }

        return result;
    }

    /**
     * @dev Return a slice of the 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, uint256 start, uint256 end) internal view returns (bytes32[] memory) {
        bytes32[] memory store = _values(set._inner, start, end);
        bytes32[] memory result;

        assembly ("memory-safe") {
            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 Removes all the values from a set. O(n).
     *
     * WARNING: Developers should keep in mind that this function has an unbounded cost and using it may render the
     * function uncallable if the set grows to the point where clearing it consumes too much gas to fit in a block.
     */
    function clear(AddressSet storage set) internal {
        _clear(set._inner);
    }

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

        assembly ("memory-safe") {
            result := store
        }

        return result;
    }

    /**
     * @dev Return a slice of the 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, uint256 start, uint256 end) internal view returns (address[] memory) {
        bytes32[] memory store = _values(set._inner, start, end);
        address[] memory result;

        assembly ("memory-safe") {
            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 Removes all the values from a set. O(n).
     *
     * WARNING: Developers should keep in mind that this function has an unbounded cost and using it may render the
     * function uncallable if the set grows to the point where clearing it consumes too much gas to fit in a block.
     */
    function clear(UintSet storage set) internal {
        _clear(set._inner);
    }

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

        assembly ("memory-safe") {
            result := store
        }

        return result;
    }

    /**
     * @dev Return a slice of the 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, uint256 start, uint256 end) internal view returns (uint256[] memory) {
        bytes32[] memory store = _values(set._inner, start, end);
        uint256[] memory result;

        assembly ("memory-safe") {
            result := store
        }

        return result;
    }

    struct StringSet {
        // Storage of set values
        string[] _values;
        // Position is the index of the value in the `values` array plus 1.
        // Position 0 is used to mean a value is not in the set.
        mapping(string value => uint256) _positions;
    }

    /**
     * @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(StringSet storage set, string memory value) internal 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._positions[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(StringSet storage set, string memory value) internal returns (bool) {
        // We cache the value's position to prevent multiple reads from the same storage slot
        uint256 position = set._positions[value];

        if (position != 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 valueIndex = position - 1;
            uint256 lastIndex = set._values.length - 1;

            if (valueIndex != lastIndex) {
                string memory lastValue = set._values[lastIndex];

                // Move the lastValue to the index where the value to delete is
                set._values[valueIndex] = lastValue;
                // Update the tracked position of the lastValue (that was just moved)
                set._positions[lastValue] = position;
            }

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

            // Delete the tracked position for the deleted slot
            delete set._positions[value];

            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Removes all the values from a set. O(n).
     *
     * WARNING: Developers should keep in mind that this function has an unbounded cost and using it may render the
     * function uncallable if the set grows to the point where clearing it consumes too much gas to fit in a block.
     */
    function clear(StringSet storage set) internal {
        uint256 len = length(set);
        for (uint256 i = 0; i < len; ++i) {
            delete set._positions[set._values[i]];
        }
        Arrays.unsafeSetLength(set._values, 0);
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(StringSet storage set, string memory value) internal view returns (bool) {
        return set._positions[value] != 0;
    }

    /**
     * @dev Returns the number of values on the set. O(1).
     */
    function length(StringSet storage set) internal 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(StringSet storage set, uint256 index) internal view returns (string memory) {
        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(StringSet storage set) internal view returns (string[] memory) {
        return set._values;
    }

    /**
     * @dev Return a slice of the 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(StringSet storage set, uint256 start, uint256 end) internal view returns (string[] memory) {
        unchecked {
            end = Math.min(end, length(set));
            start = Math.min(start, end);

            uint256 len = end - start;
            string[] memory result = new string[](len);
            for (uint256 i = 0; i < len; ++i) {
                result[i] = Arrays.unsafeAccess(set._values, start + i).value;
            }
            return result;
        }
    }

    struct BytesSet {
        // Storage of set values
        bytes[] _values;
        // Position is the index of the value in the `values` array plus 1.
        // Position 0 is used to mean a value is not in the set.
        mapping(bytes value => uint256) _positions;
    }

    /**
     * @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(BytesSet storage set, bytes memory value) internal 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._positions[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(BytesSet storage set, bytes memory value) internal returns (bool) {
        // We cache the value's position to prevent multiple reads from the same storage slot
        uint256 position = set._positions[value];

        if (position != 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 valueIndex = position - 1;
            uint256 lastIndex = set._values.length - 1;

            if (valueIndex != lastIndex) {
                bytes memory lastValue = set._values[lastIndex];

                // Move the lastValue to the index where the value to delete is
                set._values[valueIndex] = lastValue;
                // Update the tracked position of the lastValue (that was just moved)
                set._positions[lastValue] = position;
            }

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

            // Delete the tracked position for the deleted slot
            delete set._positions[value];

            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Removes all the values from a set. O(n).
     *
     * WARNING: Developers should keep in mind that this function has an unbounded cost and using it may render the
     * function uncallable if the set grows to the point where clearing it consumes too much gas to fit in a block.
     */
    function clear(BytesSet storage set) internal {
        uint256 len = length(set);
        for (uint256 i = 0; i < len; ++i) {
            delete set._positions[set._values[i]];
        }
        Arrays.unsafeSetLength(set._values, 0);
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(BytesSet storage set, bytes memory value) internal view returns (bool) {
        return set._positions[value] != 0;
    }

    /**
     * @dev Returns the number of values on the set. O(1).
     */
    function length(BytesSet storage set) internal 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(BytesSet storage set, uint256 index) internal view returns (bytes memory) {
        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(BytesSet storage set) internal view returns (bytes[] memory) {
        return set._values;
    }

    /**
     * @dev Return a slice of the 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(BytesSet storage set, uint256 start, uint256 end) internal view returns (bytes[] memory) {
        unchecked {
            end = Math.min(end, length(set));
            start = Math.min(start, end);

            uint256 len = end - start;
            bytes[] memory result = new bytes[](len);
            for (uint256 i = 0; i < len; ++i) {
                result[i] = Arrays.unsafeAccess(set._values, start + i).value;
            }
            return result;
        }
    }
}

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

import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import {SlotsLib} from "../libs/SlotsLib.sol";
import {IControllable} from "../../interfaces/IControllable.sol";
import {IPlatform} from "../../interfaces/IPlatform.sol";

/// @dev Base core contract.
///      It store an immutable platform proxy address in the storage and provides access control to inherited contracts.
/// @author Alien Deployer (https://github.com/a17)
/// @author 0xhokugava (https://github.com/0xhokugava)
abstract contract Controllable is Initializable, IControllable, ERC165 {
    using SlotsLib for bytes32;

    string public constant CONTROLLABLE_VERSION = "1.0.1";
    bytes32 internal constant _PLATFORM_SLOT = bytes32(uint(keccak256("eip1967.controllable.platform")) - 1);
    bytes32 internal constant _CREATED_BLOCK_SLOT = bytes32(uint(keccak256("eip1967.controllable.created_block")) - 1);

    /// @dev Prevent implementation init
    constructor() {
        _disableInitializers();
    }

    /// @notice Initialize contract after setup it as proxy implementation
    ///         Save block.timestamp in the "created" variable
    /// @dev Use it only once after first logic setup
    /// @param platform_ Platform address
    //slither-disable-next-line naming-convention
    function __Controllable_init(address platform_) internal onlyInitializing {
        require(platform_ != address(0) && IPlatform(platform_).multisig() != address(0), IncorrectZeroArgument());
        SlotsLib.set(_PLATFORM_SLOT, platform_); // syntax for forge coverage
        _CREATED_BLOCK_SLOT.set(block.number);
        emit ContractInitialized(platform_, block.timestamp, block.number);
    }

    modifier onlyGovernance() {
        _requireGovernance();
        _;
    }

    modifier onlyMultisig() {
        _requireMultisig();
        _;
    }

    modifier onlyGovernanceOrMultisig() {
        _requireGovernanceOrMultisig();
        _;
    }

    modifier onlyOperator() {
        _requireOperator();
        _;
    }

    modifier onlyFactory() {
        _requireFactory();
        _;
    }

    // ************* SETTERS/GETTERS *******************

    /// @inheritdoc IControllable
    function platform() public view override returns (address) {
        return _PLATFORM_SLOT.getAddress();
    }

    /// @inheritdoc IControllable
    function createdBlock() external view override returns (uint) {
        return _CREATED_BLOCK_SLOT.getUint();
    }

    /// @inheritdoc IERC165
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IControllable).interfaceId || super.supportsInterface(interfaceId);
    }

    function _requireGovernance() internal view {
        require(IPlatform(platform()).governance() == msg.sender, NotGovernance());
    }

    function _requireMultisig() internal view {
        require(IPlatform(platform()).multisig() == msg.sender, NotMultisig());
    }

    function _requireGovernanceOrMultisig() internal view {
        IPlatform _platform = IPlatform(platform());
        require(
            _platform.governance() == msg.sender || _platform.multisig() == msg.sender, NotGovernanceAndNotMultisig()
        );
    }

    function _requireOperator() internal view {
        require(IPlatform(platform()).isOperator(msg.sender), NotOperator());
    }

    function _requireFactory() internal view {
        require(IPlatform(platform()).factory() == msg.sender, NotFactory());
    }
}

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

/// @dev Base core interface implemented by most platform contracts.
///      Inherited contracts store an immutable Platform proxy address in the storage,
///      which provides authorization capabilities and infrastructure contract addresses.
/// @author Alien Deployer (https://github.com/a17)
/// @author JodsMigel (https://github.com/JodsMigel)
/// @author dvpublic (https://github.com/dvpublic)
interface IControllable {
    //region ----- Custom Errors -----
    error IncorrectZeroArgument();
    error IncorrectMsgSender();
    error NotGovernance();
    error NotMultisig();
    error NotGovernanceAndNotMultisig();
    error NotOperator();
    error NotFactory();
    error NotPlatform();
    error NotVault();
    error IncorrectArrayLength();
    error AlreadyExist();
    error NotExist();
    error NotTheOwner();
    error ETHTransferFailed();
    error IncorrectInitParams();
    error InsufficientBalance();
    error IncorrectBalance();
    error IncorrectLtv(uint ltv);
    error TooLowValue(uint value);
    error IncorrectAssetsList(address[] assets_, address[] expectedAssets_);
    //endregion -- Custom Errors -----

    event ContractInitialized(address platform, uint ts, uint block);

    /// @notice Stability Platform main contract address
    function platform() external view returns (address);

    /// @notice Version of contract implementation
    /// @dev SemVer scheme MAJOR.MINOR.PATCH
    //slither-disable-next-line naming-convention
    function VERSION() external view returns (string memory);

    /// @notice Block number when contract was initialized
    function createdBlock() external view returns (uint);
}

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

import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
import {ConstantsLib} from "./ConstantsLib.sol";

library CommonLib {
    function filterAddresses(
        address[] memory addresses,
        address addressToRemove
    ) external pure returns (address[] memory filteredAddresses) {
        uint len = addresses.length;
        uint newLen;
        // nosemgrep
        for (uint i; i < len; ++i) {
            if (addresses[i] != addressToRemove) {
                ++newLen;
            }
        }
        filteredAddresses = new address[](newLen);
        uint k;
        // nosemgrep
        for (uint i; i < len; ++i) {
            if (addresses[i] != addressToRemove) {
                filteredAddresses[k] = addresses[i];
                ++k;
            }
        }
    }

    function formatUsdAmount(uint amount) external pure returns (string memory formattedPrice) {
        uint dollars = amount / 10 ** 18;
        string memory priceStr;
        if (dollars >= 1000) {
            uint kDollars = dollars / 1000;
            uint kDollarsFraction = (dollars - kDollars * 1000) / 10;
            string memory delimiter = ".";
            if (kDollarsFraction < 10) {
                delimiter = ".0";
            }
            priceStr = string.concat(Strings.toString(kDollars), delimiter, Strings.toString(kDollarsFraction), "k");
        } else if (dollars >= 100) {
            priceStr = Strings.toString(dollars);
        } else {
            uint dollarsFraction = (amount - dollars * 10 ** 18) / 10 ** 14;
            if (dollarsFraction > 0) {
                string memory dollarsFractionDelimiter = ".";
                if (dollarsFraction < 10) {
                    dollarsFractionDelimiter = ".000";
                } else if (dollarsFraction < 100) {
                    dollarsFractionDelimiter = ".00";
                } else if (dollarsFraction < 1000) {
                    dollarsFractionDelimiter = ".0";
                }
                priceStr = string.concat(
                    Strings.toString(dollars), dollarsFractionDelimiter, Strings.toString(dollarsFraction)
                );
            } else {
                priceStr = Strings.toString(dollars);
            }
        }

        formattedPrice = string.concat("$", priceStr);
    }

    function formatApr(uint apr) external pure returns (string memory formattedApr) {
        uint aprInt = apr * 100 / ConstantsLib.DENOMINATOR;
        uint aprFraction = (apr - aprInt * ConstantsLib.DENOMINATOR / 100) / 10;
        string memory delimiter = ".";
        if (aprFraction < 10) {
            delimiter = ".0";
        }
        formattedApr = string.concat(Strings.toString(aprInt), delimiter, Strings.toString(aprFraction), "%");
    }

    function formatAprInt(int apr) external pure returns (string memory formattedApr) {
        int aprInt = apr * 100 / int(ConstantsLib.DENOMINATOR);
        int aprFraction = (apr - aprInt * int(ConstantsLib.DENOMINATOR) / 100) / 10;
        string memory delimiter = ".";
        if (aprFraction < 10 || aprFraction > -10) {
            delimiter = ".0";
        }
        formattedApr = string.concat(i2s2(aprInt), delimiter, i2s(aprFraction), "%");
    }

    function implodeSymbols(
        address[] memory assets,
        string memory delimiter
    ) external view returns (string memory outString) {
        return implode(getSymbols(assets), delimiter);
    }

    function implode(string[] memory strings, string memory delimiter) public pure returns (string memory outString) {
        uint len = strings.length;
        if (len == 0) {
            return "";
        }
        outString = strings[0];
        // nosemgrep
        for (uint i = 1; i < len; ++i) {
            outString = string.concat(outString, delimiter, strings[i]);
        }
        return outString;
    }

    function getSymbols(address[] memory assets) public view returns (string[] memory symbols) {
        uint len = assets.length;
        symbols = new string[](len);
        // nosemgrep
        for (uint i; i < len; ++i) {
            symbols[i] = IERC20Metadata(assets[i]).symbol();
        }
    }

    function bytesToBytes32(bytes memory b) external pure returns (bytes32 out) {
        // nosemgrep
        for (uint i; i < b.length; ++i) {
            out |= bytes32(b[i] & 0xFF) >> (i * 8);
        }
        // return out;
    }

    function bToHex(bytes memory buffer) external pure returns (string memory) {
        // Fixed buffer size for hexadecimal convertion
        bytes memory converted = new bytes(buffer.length * 2);
        bytes memory _base = "0123456789abcdef";
        uint baseLength = _base.length;
        // nosemgrep
        for (uint i; i < buffer.length; ++i) {
            converted[i * 2] = _base[uint8(buffer[i]) / baseLength];
            converted[i * 2 + 1] = _base[uint8(buffer[i]) % baseLength];
        }
        return string(abi.encodePacked(converted));
    }

    function shortId(string memory id) external pure returns (string memory) {
        uint words = 1;
        bytes memory idBytes = bytes(id);
        uint idBytesLength = idBytes.length;
        // nosemgrep
        for (uint i; i < idBytesLength; ++i) {
            if (keccak256(bytes(abi.encodePacked(idBytes[i]))) == keccak256(bytes(" "))) {
                ++words;
            }
        }
        bytes memory _shortId = new bytes(words);
        uint k = 1;
        _shortId[0] = idBytes[0];
        // nosemgrep
        for (uint i = 1; i < idBytesLength; ++i) {
            if (keccak256(bytes(abi.encodePacked(idBytes[i]))) == keccak256(bytes(" "))) {
                if (keccak256(bytes(abi.encodePacked(idBytes[i + 1]))) == keccak256(bytes("0"))) {
                    _shortId[k] = idBytes[i + 3];
                } else {
                    _shortId[k] = idBytes[i + 1];
                }
                ++k;
            }
        }
        return string(abi.encodePacked(_shortId));
    }

    function eq(string memory a, string memory b) external pure returns (bool) {
        return keccak256(bytes(a)) == keccak256(bytes(b));
    }

    function u2s(uint num) external pure returns (string memory) {
        return Strings.toString(num);
    }

    function i2s(int num) public pure returns (string memory) {
        return Strings.toString(num > 0 ? uint(num) : uint(-num));
    }

    function i2s2(int num) public pure returns (string memory) {
        if (num >= 0) {
            return Strings.toString(uint(num));
        }
        return string.concat("-", Strings.toString(uint(-num)));
    }
}

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

import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import {IPlatform} from "../../interfaces/IPlatform.sol";
import {ISwapper} from "../../interfaces/ISwapper.sol";
import {IFactory} from "../../interfaces/IFactory.sol";
import {IVaultProxy} from "../../interfaces/IVaultProxy.sol";
import {IStrategyProxy} from "../../interfaces/IStrategyProxy.sol";
import {StrategyDeveloperLib} from "../../strategies/libs/StrategyDeveloperLib.sol";
import {IStrategyLogic} from "../../interfaces/IStrategyLogic.sol";
import {IFarmingStrategy} from "../../interfaces/IFarmingStrategy.sol";

library FactoryLib {
    using SafeERC20 for IERC20;
    using EnumerableSet for EnumerableSet.Bytes32Set;

    struct GetVaultInitParamsVariantsVars {
        string[] vaultTypes;
        uint total;
        uint totalVaultInitAddresses;
        uint totalVaultInitNums;
        uint len;
    }

    function getExchangeAssetIndex(
        address platform,
        address[] memory assets
    ) external view returns (uint exchangeAssetIndex) {
        address targetExchangeAsset = IPlatform(platform).targetExchangeAsset();
        uint len = assets.length;
        // nosemgrep
        for (uint i; i < len; ++i) {
            if (assets[i] == targetExchangeAsset) {
                return i;
            }
        }

        exchangeAssetIndex = type(uint).max;
        uint minRoutes = type(uint).max;
        ISwapper swapper = ISwapper(IPlatform(platform).swapper());
        // nosemgrep
        for (uint i; i < len; ++i) {
            //slither-disable-next-line unused-return
            (ISwapper.PoolData[] memory route,) = swapper.buildRoute(assets[i], targetExchangeAsset);
            // nosemgrep
            uint routeLength = route.length;
            if (routeLength < minRoutes) {
                minRoutes = routeLength;
                exchangeAssetIndex = i;
            }
        }
        if (exchangeAssetIndex == type(uint).max) {
            revert ISwapper.NoRouteFound();
        }
        if (exchangeAssetIndex > type(uint).max) revert ISwapper.NoRoutesForAssets();
    }

    function getName(
        string memory, /*vaultType*/
        string memory id,
        string memory symbols,
        string memory specificName,
        address[] memory /*vaultInitAddresses*/
    ) public pure returns (string memory name) {
        name = string.concat("Stability ", symbols, " ", id);
        if (keccak256(bytes(specificName)) != keccak256(bytes(""))) {
            name = string.concat(name, " ", specificName);
        }
    }

    function getDeploymentKey(
        string memory vaultType,
        string memory strategyId,
        address[] memory initVaultAddresses,
        uint[] memory initVaultNums,
        address[] memory initStrategyAddresses,
        uint[] memory initStrategyNums,
        int24[] memory initStrategyTicks,
        uint8[5] memory usedValuesForKey
    ) public pure returns (bytes32) {
        uint key = uint(keccak256(abi.encodePacked(vaultType)));
        unchecked {
            key += uint(keccak256(abi.encodePacked(strategyId)));
        }

        uint i;
        uint len;

        // process initVaultAddresses
        len = initVaultAddresses.length;
        if (len > usedValuesForKey[0]) {
            len = usedValuesForKey[0];
        }
        for (; i < len; ++i) {
            unchecked {
                key += uint(uint160(initVaultAddresses[i]));
            }
        }

        // process initVaultNums
        len = initVaultNums.length;
        if (len > usedValuesForKey[1]) {
            len = usedValuesForKey[1];
        }
        for (i = 0; i < len; ++i) {
            unchecked {
                key += initVaultNums[i];
            }
        }

        // process initStrategyAddresses
        len = initStrategyAddresses.length;
        if (len > usedValuesForKey[2]) {
            len = usedValuesForKey[2];
        }
        for (i = 0; i < len; ++i) {
            unchecked {
                key += uint(uint160(initStrategyAddresses[i]));
            }
        }

        // process initStrategyNums
        len = initStrategyNums.length;
        if (len > usedValuesForKey[3]) {
            len = usedValuesForKey[3];
        }
        for (i = 0; i < len; ++i) {
            unchecked {
                key += initStrategyNums[i];
            }
        }

        // process initStrategyTicks
        len = initStrategyTicks.length;
        if (len > usedValuesForKey[4]) {
            len = usedValuesForKey[4];
        }
        for (i = 0; i < len; ++i) {
            unchecked {
                key += initStrategyTicks[i] >= 0 ? uint(int(initStrategyTicks[i])) : uint(-int(initStrategyTicks[i]));
            }
        }

        return bytes32(key);
    }

    function setVaultImplementation(
        IFactory.FactoryStorage storage $,
        string memory vaultType,
        address implementation
    ) external returns (bool needGovOrMultisigAccess) {
        bytes32 typeHash = keccak256(abi.encodePacked(vaultType));
        $.vaultConfig[typeHash] = IFactory.VaultConfig({
            vaultType: vaultType,
            implementation: implementation,
            deployAllowed: true,
            upgradeAllowed: true,
            buildingPrice: 0
        });
        bool newVaultType = $.vaultTypeHashes.add(typeHash);
        if (!newVaultType) {
            needGovOrMultisigAccess = true;
        }
        emit IFactory.VaultConfigChanged(vaultType, implementation, true, true, newVaultType);
    }

    function setStrategyImplementation(
        IFactory.FactoryStorage storage $,
        address platform,
        string memory strategyId,
        address implementation
    ) external returns (bool needGovOrMultisigAccess) {
        bytes32 strategyIdHash = keccak256(bytes(strategyId));
        IFactory.StrategyLogicConfig storage oldConfig = $.strategyLogicConfig[strategyIdHash];
        uint tokenId;
        bool farming;
        if (oldConfig.implementation == address(0)) {
            address developer = StrategyDeveloperLib.getDeveloper(strategyId);
            if (developer == address(0)) {
                developer = IPlatform(platform).multisig();
            }
            tokenId = IStrategyLogic(IPlatform(platform).strategyLogic()).mint(developer, strategyId);
            farming = IERC165(implementation).supportsInterface(type(IFarmingStrategy).interfaceId);
        } else {
            tokenId = oldConfig.tokenId;
            farming = oldConfig.farming;
        }
        $.strategyLogicConfig[strategyIdHash] = IFactory.StrategyLogicConfig({
            id: strategyId,
            tokenId: tokenId,
            implementation: implementation,
            deployAllowed: true,
            upgradeAllowed: true,
            farming: farming
        });
        bool newStrategy = $.strategyLogicIdHashes.add(strategyIdHash);
        needGovOrMultisigAccess = !newStrategy;
        emit IFactory.StrategyLogicConfigChanged(strategyId, implementation, true, true, newStrategy);
    }

    function upgradeVaultProxy(IFactory.FactoryStorage storage $, address vault) external {
        IVaultProxy proxy = IVaultProxy(vault);
        bytes32 vaultTypeHash = proxy.vaultTypeHash();
        address oldImplementation = proxy.implementation();
        IFactory.VaultConfig memory tempVaultConfig = $.vaultConfig[vaultTypeHash];
        address newImplementation = tempVaultConfig.implementation;
        if (oldImplementation == newImplementation) {
            revert IFactory.AlreadyLastVersion(vaultTypeHash);
        }
        proxy.upgrade();
        emit IFactory.VaultProxyUpgraded(vault, oldImplementation, newImplementation);
    }

    function upgradeStrategyProxy(IFactory.FactoryStorage storage $, address strategyProxy) external {
        IStrategyProxy proxy = IStrategyProxy(strategyProxy);
        bytes32 idHash = proxy.strategyImplementationLogicIdHash();
        IFactory.StrategyLogicConfig storage config = $.strategyLogicConfig[idHash];
        address oldImplementation = proxy.implementation();
        address newImplementation = config.implementation;
        if (!config.upgradeAllowed) {
            revert IFactory.UpgradeDenied(idHash);
        }
        if (oldImplementation == newImplementation) {
            revert IFactory.AlreadyLastVersion(idHash);
        }
        proxy.upgrade();
        emit IFactory.StrategyProxyUpgraded(strategyProxy, oldImplementation, newImplementation);
    }
}

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

import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {CommonLib} from "./CommonLib.sol";
import {IStrategy} from "../../interfaces/IStrategy.sol";

library FactoryNamingLib {
    function getStrategyData(
        string memory vaultType,
        address strategyAddress,
        address bbAsset,
        address
    )
        public
        view
        returns (
            string memory strategyId,
            address[] memory assets,
            string[] memory assetsSymbols,
            string memory specificName,
            string memory vaultSymbol
        )
    {
        strategyId = IStrategy(strategyAddress).strategyLogicId();
        assets = IStrategy(strategyAddress).assets();

        // Determine the length of the assets array
        uint assetsLength = assets.length;

        // Initialize assetsSymbols based on the length of assets
        assetsSymbols = new string[](assetsLength);

        for (uint i = 0; i < assetsLength; ++i) {
            // Use a ternary operator to determine the symbol to use
            string memory symbol =
                assets.length == 1 ? CommonLib.getSymbols(assets)[0] : IERC20Metadata(assets[i]).symbol();
            assetsSymbols[i] = symbol;
        }
        bool showSpecificInSymbol;
        (specificName, showSpecificInSymbol) = IStrategy(strategyAddress).getSpecificName();

        string memory bbAssetSymbol = bbAsset == address(0) ? "" : IERC20Metadata(bbAsset).symbol();

        vaultSymbol = _getShortSymbol(
            vaultType,
            strategyId,
            CommonLib.implode(assetsSymbols, ""),
            showSpecificInSymbol ? specificName : "",
            bbAssetSymbol
        );
    }

    function _getShortSymbol(
        string memory vaultType,
        string memory strategyLogicId,
        string memory symbols,
        string memory specificName,
        string memory bbAssetSymbol
    ) internal pure returns (string memory) {
        bytes memory vaultTypeBytes = bytes(vaultType);
        string memory prefix = "v";
        if (vaultTypeBytes[0] == "C") {
            prefix = "C";
        }
        string memory bbAssetStr = bytes(bbAssetSymbol).length > 0 ? string.concat("-", bbAssetSymbol) : "";
        return string.concat(
            prefix,
            "-",
            symbols,
            bbAssetStr,
            "-",
            CommonLib.shortId(strategyLogicId),
            bytes(specificName).length > 0 ? CommonLib.shortId(specificName) : ""
        );
    }
}

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

import {VaultProxy} from "../proxy/VaultProxy.sol";
import {StrategyProxy} from "../proxy/StrategyProxy.sol";

library DeployerLib {
    function deployVaultProxy() external returns (address) {
        return address(new VaultProxy());
    }

    function deployStrategyProxy() external returns (address) {
        return address(new StrategyProxy());
    }
}

File 12 of 48 : VaultStatusLib.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

library VaultStatusLib {
    uint internal constant NOT_EXIST = 0;
    uint internal constant ACTIVE = 1;
    uint internal constant DEPRECATED = 2;
    uint internal constant EMERGENCY_EXIT = 3;
    uint internal constant DISABLED = 4;
    uint internal constant DEPOSITS_UNAVAILABLE = 5;
    uint internal constant RECOVERY = 6;
}

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

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

/// @notice Creating vaults, upgrading vaults and strategies, vault list, farms and strategy logics management
/// @author Alien Deployer (https://github.com/a17)
/// @author Jude (https://github.com/iammrjude)
/// @author JodsMigel (https://github.com/JodsMigel)
/// @author HCrypto7 (https://github.com/hcrypto7)
interface IFactory {
    //region ----- Custom Errors -----

    error VaultImplementationIsNotAvailable();
    error StrategyImplementationIsNotAvailable();
    error YouDontHaveEnoughTokens(uint userBalance, uint requireBalance, address payToken);
    error SuchVaultAlreadyDeployed(bytes32 key);
    error NotActiveVault();
    error UpgradeDenied(bytes32 _hash);
    error AlreadyLastVersion(bytes32 _hash);
    error NotStrategy();

    //endregion ----- Custom Errors -----

    //region ----- Events -----

    event VaultAndStrategy(
        address indexed deployer,
        string vaultType,
        string strategyId,
        address vault,
        address strategy,
        string name,
        string symbol,
        address[] assets,
        bytes32 deploymentKey,
        uint vaultManagerTokenId
    );
    event StrategyProxyUpgraded(address proxy, address oldImplementation, address newImplementation);
    event VaultProxyUpgraded(address proxy, address oldImplementation, address newImplementation);
    event VaultConfigChanged(
        string type_, address implementation, bool deployAllowed, bool upgradeAllowed, bool newVaultType
    );
    event StrategyLogicConfigChanged(
        string id, address implementation, bool deployAllowed, bool upgradeAllowed, bool newStrategy
    );
    event VaultStatus(address indexed vault, uint newStatus);
    event NewFarm(Farm[] farms);
    event UpdateFarm(uint id, Farm farm);
    event SetStrategyAvailableInitParams(string id, address[] initAddresses, uint[] initNums, int24[] initTicks);
    event AliasNameChanged(address indexed operator, address indexed tokenAddress, string newAliasName);

    //endregion -- Events -----

    //region ----- Data types -----

    /// @custom:storage-location erc7201:stability.Factory
    struct FactoryStorage {
        /// @inheritdoc IFactory
        mapping(bytes32 typeHash => VaultConfig) vaultConfig;
        /// @inheritdoc IFactory
        mapping(bytes32 idHash => StrategyLogicConfig) strategyLogicConfig;
        /// @inheritdoc IFactory
        mapping(bytes32 deploymentKey => address vaultProxy) deploymentKey;
        /// @inheritdoc IFactory
        mapping(address vault => uint status) vaultStatus;
        /// @inheritdoc IFactory
        mapping(address address_ => bool isStrategy_) isStrategy;
        EnumerableSet.Bytes32Set vaultTypeHashes;
        EnumerableSet.Bytes32Set strategyLogicIdHashes;
        mapping(uint => mapping(uint => uint)) __deprecated1;
        address[] deployedVaults;
        Farm[] farms;
        /// @inheritdoc IFactory
        mapping(bytes32 idHash => StrategyAvailableInitParams) strategyAvailableInitParams;
        mapping(address tokenAddress => string aliasName) aliasNames;
    }

    struct VaultConfig {
        string vaultType;
        address implementation;
        bool deployAllowed;
        bool upgradeAllowed;
        uint buildingPrice;
    }

    struct StrategyLogicConfig {
        string id;
        address implementation;
        bool deployAllowed;
        bool upgradeAllowed;
        bool farming;
        uint tokenId;
    }

    struct Farm {
        uint status;
        address pool;
        string strategyLogicId;
        address[] rewardAssets;
        address[] addresses;
        uint[] nums;
        int24[] ticks;
    }

    struct StrategyAvailableInitParams {
        address[] initAddresses;
        uint[] initNums;
        int24[] initTicks;
    }

    //endregion -- Data types -----

    //region ----- View functions -----

    /// @notice All vaults deployed by the factory
    /// @return Vault proxy addresses
    function deployedVaults() external view returns (address[] memory);

    /// @notice Total vaults deployed
    function deployedVaultsLength() external view returns (uint);

    /// @notice Get vault by VaultManager tokenId
    /// @param id Vault array index. Same as tokenId of VaultManager NFT
    /// @return Address of VaultProxy
    function deployedVault(uint id) external view returns (address);

    /// @notice All farms known by the factory in current network
    function farms() external view returns (Farm[] memory);

    /// @notice Total farms known by the factory in current network
    function farmsLength() external view returns (uint);

    /// @notice Farm data by farm index
    /// @param id Index of farm
    function farm(uint id) external view returns (Farm memory);

    /// @notice Strategy logic settings
    /// @param idHash keccak256 hash of strategy logic string ID
    /// @return config Strategy logic settings
    function strategyLogicConfig(bytes32 idHash) external view returns (StrategyLogicConfig memory config);

    /// @notice All known strategies
    /// @return Array of keccak256 hashes of strategy logic string ID
    function strategyLogicIdHashes() external view returns (bytes32[] memory);

    // todo remove, use new function without calculating vault symbol on the fly for not initialized vaults
    // factory required that special functionally only internally, not for interface
    function getStrategyData(
        string memory vaultType,
        address strategyAddress,
        address
    )
        external
        view
        returns (
            string memory strategyId,
            address[] memory assets,
            string[] memory assetsSymbols,
            string memory specificName,
            string memory vaultSymbol
        );

    /// @dev Get best asset of assets to be strategy exchange asset
    function getExchangeAssetIndex(address[] memory assets) external view returns (uint);

    /// @notice Deployment key of created vault
    /// @param deploymentKey_ Hash of concatenated unique vault and strategy initialization parameters
    /// @return Address of deployed vault
    function deploymentKey(bytes32 deploymentKey_) external view returns (address);

    /// @notice Calculating deployment key based on unique vault and strategy initialization parameters
    /// @param vaultType Vault type string
    /// @param strategyId Strategy logic Id string
    /// @param vaultInitAddresses Vault initialization addresses for deployVaultAndStrategy method
    /// @param vaultInitNums Vault initialization uint numbers for deployVaultAndStrategy method
    /// @param strategyInitAddresses Strategy initialization addresses for deployVaultAndStrategy method
    /// @param strategyInitNums Strategy initialization uint numbers for deployVaultAndStrategy method
    /// @param strategyInitTicks Strategy initialization int24 ticks for deployVaultAndStrategy method
    function getDeploymentKey(
        string memory vaultType,
        string memory strategyId,
        address[] memory vaultInitAddresses,
        uint[] memory vaultInitNums,
        address[] memory strategyInitAddresses,
        uint[] memory strategyInitNums,
        int24[] memory strategyInitTicks
    ) external view returns (bytes32);

    /// @notice Governance and multisig can set a vault status other than Active - the default status.
    /// HardWorker only works with active vaults.
    /// @return status Constant from VaultStatusLib
    function vaultStatus(address vault) external view returns (uint status);

    /// @notice Check that strategy proxy deployed by the Factory
    /// @param address_ Address of contract
    /// @return This address is our strategy proxy
    function isStrategy(address address_) external view returns (bool);

    /// @notice Data on all factory strategies.
    /// The output values are matched by index in the arrays.
    /// @return id Strategy logic ID strings
    /// @return deployAllowed New vaults can be deployed
    /// @return upgradeAllowed Strategy can be upgraded
    /// @return farming It is farming strategy (earns farming/gauge rewards)
    /// @return tokenId Token ID of StrategyLogic NFT
    /// @return tokenURI StrategyLogic NFT tokenId metadata and on-chain image
    /// @return extra Strategy color, background color and other extra data
    function strategies()
        external
        view
        returns (
            string[] memory id,
            bool[] memory deployAllowed,
            bool[] memory upgradeAllowed,
            bool[] memory farming,
            uint[] memory tokenId,
            string[] memory tokenURI,
            bytes32[] memory extra
        );

    /// @notice Get config of vault type
    /// @param typeHash Keccak256 hash of vault type string
    /// @return vaultType Vault type string
    /// @return implementation Vault implementation address
    /// @return deployAllowed New vaults can be deployed
    /// @return upgradeAllowed Vaults can be upgraded
    /// @return buildingPrice Price of building new vault
    function vaultConfig(bytes32 typeHash)
        external
        view
        returns (
            string memory vaultType,
            address implementation,
            bool deployAllowed,
            bool upgradeAllowed,
            uint buildingPrice
        );

    /// @notice Data on all factory vault types
    /// The output values are matched by index in the arrays.
    /// @return vaultType Vault type string
    /// @return implementation Address of vault implemented logic
    /// @return deployAllowed New vaults can be deployed
    /// @return upgradeAllowed Vaults can be upgraded
    /// @return buildingPrice  Price of building new vault
    /// @return extra Vault type color, background color and other extra data
    function vaultTypes()
        external
        view
        returns (
            string[] memory vaultType,
            address[] memory implementation,
            bool[] memory deployAllowed,
            bool[] memory upgradeAllowed,
            uint[] memory buildingPrice,
            bytes32[] memory extra
        );

    /// @notice Initialization strategy params store
    function strategyAvailableInitParams(bytes32 idHash) external view returns (StrategyAvailableInitParams memory);

    //endregion -- View functions -----

    //region ----- Write functions -----

    /// @notice Main method of the Factory - new vault creation by user.
    /// @param vaultType Vault type ID string
    /// @param strategyId Strategy logic ID string
    /// Different types of vaults and strategies have different lengths of input arrays.
    /// @param vaultInitAddresses Addresses for vault initialization
    /// @param vaultInitNums Numbers for vault initialization
    /// @param strategyInitAddresses Addresses for strategy initialization
    /// @param strategyInitNums Numbers for strategy initialization
    /// @param strategyInitTicks Ticks for strategy initialization
    /// @return vault Deployed VaultProxy address
    /// @return strategy Deployed StrategyProxy address
    function deployVaultAndStrategy(
        string memory vaultType,
        string memory strategyId,
        address[] memory vaultInitAddresses,
        uint[] memory vaultInitNums,
        address[] memory strategyInitAddresses,
        uint[] memory strategyInitNums,
        int24[] memory strategyInitTicks
    ) external returns (address vault, address strategy);

    /// @notice Upgrade vault proxy. Can be called by any address.
    /// @param vault Address of vault proxy for upgrade
    function upgradeVaultProxy(address vault) external;

    /// @notice Upgrade strategy proxy. Can be called by any address.
    /// @param strategy Address of strategy proxy for upgrade
    function upgradeStrategyProxy(address strategy) external;

    /// @notice Add farm to factory
    /// @param farms_ Settings and data required to work with the farm.
    function addFarms(Farm[] memory farms_) external;

    /// @notice Update farm
    /// @param id Farm index
    /// @param farm_ Settings and data required to work with the farm.
    function updateFarm(uint id, Farm memory farm_) external;

    /// @notice Initial addition or change of vault type implementation
    /// Operator can add new vault type. Governance or multisig can change existing vault type config.
    /// @param vaultType Vault type string ID (Compounding, etc)
    /// @param implementation Address of vault implementation
    function setVaultImplementation(string memory vaultType, address implementation) external;

    /// @notice Governance and multisig can set a vault status other than Active - the default status.
    /// @param vaults Addresses of vault proxy
    /// @param statuses New vault statuses. Constant from VaultStatusLib
    function setVaultStatus(address[] memory vaults, uint[] memory statuses) external;

    /// @notice Initial addition or change of strategy available init params
    /// @param id Strategy ID string
    /// @param initParams Init params variations that will be parsed by strategy
    function setStrategyAvailableInitParams(string memory id, StrategyAvailableInitParams memory initParams) external;

    /// @notice Set new implementation of the strategy
    /// @dev Initial addition or change of strategy logic implementation.
    /// Operator can add new strategy logic. Governance or multisig can change existing logic config.
    /// @param strategyId Strategy logic ID string
    /// @param implementation Address of strategy implementation
    function setStrategyImplementation(string memory strategyId, address implementation) external;

    //endregion -- Write functions -----
}

File 14 of 48 : IPlatform.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;

/// @notice Interface of the main contract and entry point to the platform.
/// @author Alien Deployer (https://github.com/a17)
/// @author Jude (https://github.com/iammrjude)
/// @author JodsMigel (https://github.com/JodsMigel)
/// @author ruby (https://github.com/alexandersazonof)
interface IPlatform {
    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                       CUSTOM ERRORS                        */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    error AlreadyAnnounced();
    error SameVersion();
    error NoNewVersion();
    error UpgradeTimerIsNotOver(uint TimerTimestamp);
    error IncorrectFee(uint minFee, uint maxFee);
    error TokenAlreadyExistsInSet(address token);
    error AggregatorNotExists(address dexAggRouter);

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                           EVENTS                           */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    event PlatformVersion(string version);
    event UpgradeAnnounce(
        string oldVersion, string newVersion, address[] proxies, address[] newImplementations, uint timelock
    );
    event CancelUpgrade(string oldVersion, string newVersion);
    event ProxyUpgraded(
        address indexed proxy, address implementation, string oldContractVersion, string newContractVersion
    );
    event Addresses(
        address multisig_,
        address factory_,
        address priceReader_,
        address swapper_,
        address,
        address vaultManager_,
        address strategyLogic_,
        address,
        address hardWorker,
        address rebalancer,
        address zap,
        address bridge
    );
    event OperatorAdded(address operator);
    event OperatorRemoved(address operator);
    event FeesChanged(uint fee, uint, uint, uint);
    event NewAmmAdapter(string id, address proxy);
    event EcosystemRevenueReceiver(address receiver);
    event AddDexAggregator(address router);
    event RemoveDexAggregator(address router);
    event MinTvlForFreeHardWorkChanged(uint oldValue, uint newValue);
    event CustomVaultFee(address vault, uint platformFee);
    event Rebalancer(address rebalancer_);
    event Bridge(address bridge_);
    event RevenueRouter(address revenueRouter_);
    event MetaVaultFactory(address metaVaultFactory);
    event VaultPriceOracle(address vaultPriceOracle_);
    event Recovery(address recovery_);

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                         DATA TYPES                         */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    struct PlatformUpgrade {
        string newVersion;
        address[] proxies;
        address[] newImplementations;
    }

    struct PlatformSettings {
        uint fee;
    }

    struct AmmAdapter {
        string id;
        address proxy;
    }

    struct SetupAddresses {
        address factory;
        address priceReader;
        address swapper;
        address vaultManager;
        address strategyLogic;
        address targetExchangeAsset;
        address hardWorker;
        address zap;
        address revenueRouter;
        address metaVaultFactory;
        address vaultPriceOracle;
    }
    // recovery is not configured by default, use setupRecovery function

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                      VIEW FUNCTIONS                        */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @notice Platform version in CalVer scheme: YY.MM.MINOR-tag. Updates on core contract upgrades.
    function platformVersion() external view returns (string memory);

    /// @notice Time delay for proxy upgrades of core contracts and changing important platform settings by multisig
    //slither-disable-next-line naming-convention
    function TIME_LOCK() external view returns (uint);

    /// @notice DAO governance
    function governance() external view returns (address);

    /// @notice Core team multi signature wallet. Development and operations fund
    function multisig() external view returns (address);

    /// @notice Receiver of ecosystem revenue
    function ecosystemRevenueReceiver() external view returns (address);

    /// @dev The best asset in a network for swaps between strategy assets and farms rewards assets
    ///      The target exchange asset is used for finding the best strategy's exchange asset.
    ///      Rhe fewer routes needed to swap to the target exchange asset, the better.
    function targetExchangeAsset() external view returns (address);

    /// @notice Platform factory assembling vaults. Stores settings, strategy logic, farms.
    /// Provides the opportunity to upgrade vaults and strategies.
    /// @return Address of Factory proxy
    function factory() external view returns (address);

    /// @notice The holders of these NFT receive a share of the vault revenue
    /// @return Address of VaultManager proxy
    function vaultManager() external view returns (address);

    /// @notice The holders of these tokens receive a share of the revenue received in all vaults using this strategy logic.
    function strategyLogic() external view returns (address);

    /// @notice Combining oracle and DeX spot prices
    /// @return Address of PriceReader proxy
    function priceReader() external view returns (address);

    /// @notice On-chain price quoter and swapper
    /// @return Address of Swapper proxy
    function swapper() external view returns (address);

    /// @notice HardWork resolver and caller
    /// @return Address of HardWorker proxy
    function hardWorker() external view returns (address);

    /// @notice Rebalance resolver
    /// @return Address of Rebalancer proxy
    function rebalancer() external view returns (address);

    /// @notice ZAP feature
    /// @return Address of Zap proxy
    function zap() external view returns (address);

    /// @notice Platform revenue distributor
    /// @return Address of the revenue distributor proxy
    function revenueRouter() external view returns (address);

    /// @notice Factory of MetaVaults
    /// @return Address of the MetaVault factory
    function metaVaultFactory() external view returns (address);

    /// @notice vaultPriceOracle
    /// @return Address of the vault price oracle
    function vaultPriceOracle() external view returns (address);

    /// @notice Contract for redeeming recovery tokens
    /// @return Address of the recovery contract
    function recovery() external view returns (address);

    /// @notice This function provides the timestamp of the platform upgrade timelock.
    /// @dev This function is an external view function, meaning it doesn't modify the state.
    /// @return uint representing the timestamp of the platform upgrade timelock.
    function platformUpgradeTimelock() external view returns (uint);

    /// @notice Pending platform upgrade data
    function pendingPlatformUpgrade() external view returns (PlatformUpgrade memory);

    /// @notice Get platform revenue fee settings
    /// @return fee Revenue fee % (between MIN_FEE - MAX_FEE) with DENOMINATOR precision.
    function getFees() external view returns (uint fee, uint, uint, uint);

    /// @notice Get custom vault platform fee
    /// @return fee revenue fee % with DENOMINATOR precision
    function getCustomVaultFee(address vault) external view returns (uint fee);

    /// @notice Platform settings
    function getPlatformSettings() external view returns (PlatformSettings memory);

    /// @notice AMM adapters of the platform
    function getAmmAdapters() external view returns (string[] memory id, address[] memory proxy);

    /// @notice Get AMM adapter data by hash
    /// @param ammAdapterIdHash Keccak256 hash of adapter ID string
    /// @return ID string and proxy address of AMM adapter
    function ammAdapter(bytes32 ammAdapterIdHash) external view returns (AmmAdapter memory);

    /// @notice Check address for existance in operators list
    /// @param operator Address
    /// @return True if this address is Stability Operator
    function isOperator(address operator) external view returns (bool);

    /// @notice Allowed DeX aggregators
    /// @return Addresses of DeX aggregator rounters
    function dexAggregators() external view returns (address[] memory);

    /// @notice DeX aggregator router address is allowed to be used in the platform
    /// @param dexAggRouter Address of DeX aggreagator router
    /// @return Can be used
    function isAllowedDexAggregatorRouter(address dexAggRouter) external view returns (bool);

    /// @notice Show minimum TVL for compensate if vault has not enough ETH
    /// @return Minimum TVL for compensate.
    function minTvlForFreeHardWork() external view returns (uint);

    /// @notice Front-end platform viewer
    /// @return platformAddresses Platform core addresses
    ///        platformAddresses[0] factory
    ///        platformAddresses[1] vaultManager
    ///        platformAddresses[2] strategyLogic
    ///        platformAddresses[3] deprecated
    ///        platformAddresses[4] deprecated
    ///        platformAddresses[5] governance
    ///        platformAddresses[6] multisig
    ///        platformAddresses[7] zap
    ///        platformAddresses[8] bridge
    /// @return bcAssets Blue chip token addresses
    /// @return dexAggregators_ DeX aggregators allowed to be used entire the platform
    /// @return vaultType Vault type ID strings
    /// @return vaultExtra Vault color, background color and other extra data. Index of vault same as in previous array.
    /// @return vaultBulldingPrice Price of creating new vault in buildingPayPerVaultToken. Index of vault same as in previous array.
    /// @return strategyId Strategy logic ID strings
    /// @return isFarmingStrategy True if strategy is farming strategy. Index of strategy same as in previous array.
    /// @return strategyTokenURI StrategyLogic NFT tokenId metadata and on-chain image. Index of strategy same as in previous array.
    /// @return strategyExtra Strategy color, background color and other extra data. Index of strategy same as in previous array.
    function getData()
        external
        view
        returns (
            address[] memory platformAddresses,
            address[] memory bcAssets,
            address[] memory dexAggregators_,
            string[] memory vaultType,
            bytes32[] memory vaultExtra,
            uint[] memory vaultBulldingPrice,
            string[] memory strategyId,
            bool[] memory isFarmingStrategy,
            string[] memory strategyTokenURI,
            bytes32[] memory strategyExtra
        );

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                      WRITE FUNCTIONS                       */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @notice Add platform operator.
    /// Only governance and multisig can add operator.
    /// @param operator Address of new operator
    function addOperator(address operator) external;

    /// @notice Remove platform operator.
    /// Only governance and multisig can remove operator.
    /// @param operator Address of operator to remove
    function removeOperator(address operator) external;

    /// @notice Announce upgrade of platform proxies implementations
    /// Only governance and multisig can announce platform upgrades.
    /// @param newVersion New platform version. Version must be changed when upgrading.
    /// @param proxies Addresses of core contract proxies
    /// @param newImplementations New implementation for proxy. Index of proxy same as in previous array.
    function announcePlatformUpgrade(
        string memory newVersion,
        address[] memory proxies,
        address[] memory newImplementations
    ) external;

    /// @notice Upgrade platform
    /// Only operator (multisig is operator too) can execute pending platform upgrade
    function upgrade() external;

    /// @notice Cancel pending platform upgrade
    /// Only operator (multisig is operator too) can execute pending platform upgrade
    function cancelUpgrade() external;

    /// @notice Register AMM adapter in platform
    /// @param id AMM adapter ID string from AmmAdapterIdLib
    /// @param proxy Address of AMM adapter proxy
    function addAmmAdapter(string memory id, address proxy) external;

    /// @notice Allow DeX aggregator routers to be used in the platform
    /// @param dexAggRouter Addresses of DeX aggreagator routers
    function addDexAggregators(address[] memory dexAggRouter) external;

    /// @notice Remove allowed DeX aggregator router from the platform
    /// @param dexAggRouter Address of DeX aggreagator router
    function removeDexAggregator(address dexAggRouter) external;

    /// @notice Update new minimum TVL for compensate.
    /// @param value New minimum TVL for compensate.
    function setMinTvlForFreeHardWork(uint value) external;

    /// @notice Set custom platform fee for vault
    /// @param vault Vault address
    /// @param platformFee Custom platform fee
    function setCustomVaultFee(address vault, uint platformFee) external;

    /// @notice Set vault price oracle
    /// @param vaultPriceOracle_ Address of the vault price oracle
    function setupVaultPriceOracle(address vaultPriceOracle_) external;

    /// @notice Set recovery contract
    /// @param recovery_ Address of the recovery contract
    function setupRecovery(address recovery_) external;
}

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

import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import {IStrategy} from "./IStrategy.sol";
import {IStabilityVault} from "./IStabilityVault.sol";

/// @notice Vault core interface.
/// Derived implementations can be effective for building tokenized vaults with single or multiple underlying liquidity mining position.
/// Fungible, static non-fungible and actively re-balancing liquidity is supported, as well as single token liquidity provided to lending protocols.
/// Vaults can be used for active concentrated liquidity management and market making.
/// @author Jude (https://github.com/iammrjude)
/// @author JodsMigel (https://github.com/JodsMigel)
interface IVault is IERC165, IStabilityVault {
    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                       CUSTOM ERRORS                        */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    error NotEnoughBalanceToPay();
    error FuseTrigger();
    error ExceedSlippageExactAsset(address asset, uint mintToUser, uint minToMint);
    error NotEnoughAmountToInitSupply(uint mintAmount, uint initialShares);
    error StrategyZeroDeposit();

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                           EVENTS                           */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    event HardWorkGas(uint gasUsed, uint gasCost, bool compensated);
    event DoHardWorkOnDepositChanged(bool oldValue, bool newValue);
    event MintFees(
        uint vaultManagerReceiverFee,
        uint strategyLogicReceiverFee,
        uint ecosystemRevenueReceiverFee,
        uint multisigReceiverFee
    );

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                         DATA TYPES                         */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @custom:storage-location erc7201:stability.VaultBase
    struct VaultBaseStorage {
        /// @dev Prevents manipulations with deposit and withdraw in short time.
        ///      For simplification we are setup new withdraw request on each deposit/transfer.
        mapping(address msgSender => uint blockNumber) withdrawRequests;
        /// @inheritdoc IVault
        IStrategy strategy;
        /// @inheritdoc IVault
        uint maxSupply;
        /// @inheritdoc IVault
        uint tokenId;
        /// @inheritdoc IVault
        bool doHardWorkOnDeposit;
        /// @dev Immutable vault type ID
        string _type;
        /// @dev Changed ERC20 name
        string changedName;
        /// @dev Changed ERC20 symbol
        string changedSymbol;
        /// @inheritdoc IStabilityVault
        bool lastBlockDefenseDisabled;
    }

    /// @title Vault Initialization Data
    /// @notice Data structure containing parameters for initializing a new vault.
    /// @dev This struct is commonly used as a parameter for the `initialize` function in vault contracts.
    /// @param platform Platform address providing access control, infrastructure addresses, fee settings, and upgrade capability.
    /// @param strategy Immutable strategy proxy used by the vault.
    /// @param name ERC20 name for the vault token.
    /// @param symbol ERC20 symbol for the vault token.
    /// @param tokenId NFT ID associated with the VaultManager.
    /// @param vaultInitAddresses Array of addresses used during vault initialization.
    /// @param vaultInitNums Array of uint values corresponding to initialization parameters.
    struct VaultInitializationData {
        address platform;
        address strategy;
        string name;
        string symbol;
        uint tokenId;
        address[] vaultInitAddresses;
        uint[] vaultInitNums;
    }

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                       VIEW FUNCTIONS                       */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @return uniqueInitAddresses Return required unique init addresses
    /// @return uniqueInitNums Return required unique init nums
    function getUniqueInitParamLength() external view returns (uint uniqueInitAddresses, uint uniqueInitNums);

    /// @notice Vault type extra data
    /// @return Vault type color, background color and other extra data
    function extra() external view returns (bytes32);

    /// @notice Immutable strategy proxy used by the vault
    /// @return Linked strategy
    function strategy() external view returns (IStrategy);

    /// @notice Max supply of shares in the vault.
    /// Since the starting share price is $1, this ceiling can be considered as an approximate TVL limit.
    /// @return Max total supply of vault
    function maxSupply() external view returns (uint);

    /// @dev VaultManager token ID. This tokenId earn feeVaultManager provided by Platform.
    function tokenId() external view returns (uint);

    /// @dev Trigger doHardwork on invest action. Enabled by default.
    function doHardWorkOnDeposit() external view returns (bool);

    /// @notice All available data on the latest declared APR (annual percentage rate)
    /// @return totalApr Total APR of investing money to vault. 18 decimals: 1e18 - +100% per year.
    /// @return strategyApr Strategy investmnt APR declared on last HardWork.
    /// @return assetsWithApr Assets with underlying APR
    /// @return assetsAprs Underlying APR of asset
    function getApr()
        external
        view
        returns (uint totalApr, uint strategyApr, address[] memory assetsWithApr, uint[] memory assetsAprs);

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                      WRITE FUNCTIONS                       */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @notice Write version of previewDepositAssets
    /// @param assets_ Assets suitable for vault strategy. Can be strategy assets, underlying asset or specific set of assets depending on strategy logic.
    /// @param amountsMax Available amounts of assets_ that user wants to invest in vault
    /// @return amountsConsumed Amounts of strategy assets that can be deposited by providing amountsMax
    /// @return sharesOut Amount of vault shares that will be minted
    /// @return valueOut Liquidity value or underlying token amount that will be received by the strategy
    function previewDepositAssetsWrite(
        address[] memory assets_,
        uint[] memory amountsMax
    ) external returns (uint[] memory amountsConsumed, uint sharesOut, uint valueOut);

    /// @dev Mint fee shares callback
    /// @param revenueAssets Assets returned by _claimRevenue function that was earned during HardWork
    /// @param revenueAmounts Assets amounts returned from _claimRevenue function that was earned during HardWork
    /// Only strategy can call this
    function hardWorkMintFeeCallback(address[] memory revenueAssets, uint[] memory revenueAmounts) external;

    /// @dev Setting of vault capacity
    /// @param maxShares If totalSupply() exceeds this value, deposits will not be possible
    function setMaxSupply(uint maxShares) external;

    /// @dev If activated will call doHardWork on strategy on some deposit actions
    /// @param value HardWork on deposit is enabled
    function setDoHardWorkOnDeposit(bool value) external;

    /// @notice Initialization function for the vault.
    /// @dev This function is usually called by the Factory during the creation of a new vault.
    /// @param vaultInitializationData Data structure containing parameters for vault initialization.
    function initialize(VaultInitializationData memory vaultInitializationData) external;

    /// @dev Calling the strategy HardWork by operator with optional compensation for spent gas from the vault balance
    function doHardWork() external;
}

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

/// @dev Interface of proxy contract for a vault implementation
interface IVaultProxy {
    //region ----- Custom Errors -----
    error ProxyForbidden();
    //endregion -- Custom Errors -----

    /// @notice Initialize vault proxy by Factory
    /// @param type_ Vault type ID string
    function initProxy(string memory type_) external;

    /// @notice Upgrade vault implementation if available and allowed
    /// Anyone can execute vault upgrade
    function upgrade() external;

    /// @notice Current vault implementation
    /// @return Address of vault implementation contract
    function implementation() external view returns (address);

    /// @notice Vault type hash
    /// @return keccan256 hash of vault type ID string
    function vaultTypeHash() external view returns (bytes32);
}

File 17 of 48 : IStrategy.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;

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

/// @dev Core interface of strategy logic
interface IStrategy is IERC165 {
    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                           EVENTS                           */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    event HardWork(
        uint apr, uint compoundApr, uint earned, uint tvl, uint duration, uint sharePrice, uint[] assetPrices
    );
    event StrategyProtocols(string[]);
    event SpecificName(string);

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                       CUSTOM ERRORS                        */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    error NotReadyForHardWork();

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                         DATA TYPES                         */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @custom:storage-location erc7201:stability.StrategyBase
    struct StrategyBaseStorage {
        /// @inheritdoc IStrategy
        address vault;
        /// @inheritdoc IStrategy
        uint total;
        /// @inheritdoc IStrategy
        uint lastHardWork;
        /// @inheritdoc IStrategy
        uint lastApr;
        /// @inheritdoc IStrategy
        uint lastAprCompound;
        /// @inheritdoc IStrategy
        address[] _assets;
        /// @inheritdoc IStrategy
        address _underlying;
        string _id;
        uint _exchangeAssetIndex;
        uint customPriceImpactTolerance;
        /// @inheritdoc IStrategy
        uint fuseOn;
        /// @inheritdoc IStrategy
        string[] protocols;
        string specific;
    }

    enum FuseMode {
        FUSE_OFF_0,
        /// @notice Fuse mode is on (emergency stop was called).
        /// All assets were transferred from the underlying pool to the strategy balance, no deposits are allowed.
        FUSE_ON_1
    }

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                       VIEW FUNCTIONS                       */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Strategy logic string ID
    function strategyLogicId() external view returns (string memory);

    /// @dev Extra data
    /// @return 0-2 bytes - strategy color
    ///         3-5 bytes - strategy background color
    ///         6-31 bytes - free
    function extra() external view returns (bytes32);

    /// @dev Types of vault that supported by strategy implementation
    /// @return types Vault type ID strings
    function supportedVaultTypes() external view returns (string[] memory types);

    /// @dev Linked vault address
    function vault() external view returns (address);

    /// @dev Final assets that strategy invests
    function assets() external view returns (address[] memory);

    /// @notice Final assets and amounts that strategy manages
    function assetsAmounts() external view returns (address[] memory assets_, uint[] memory amounts_);

    /// @notice Priced invested assets proportions
    /// @return proportions Proportions of assets with 18 decimals. Min is 0, max is 1e18.
    function getAssetsProportions() external view returns (uint[] memory proportions);

    /// @notice Underlying token address
    /// @dev Can be used for liquidity farming strategies where AMM has fungible liquidity token (Solidly forks, etc),
    ///      for concentrated liquidity tokenized vaults (Gamma, G-UNI etc) and for other needs.
    /// @return Address of underlying token or zero address if no underlying in strategy
    function underlying() external view returns (address);

    /// @dev Balance of liquidity token or liquidity value
    function total() external view returns (uint);

    /// @dev Last HardWork time
    /// @return Timestamp
    function lastHardWork() external view returns (uint);

    /// @dev Last APR of earned USD amount registered by HardWork
    ///      ONLY FOR OFF-CHAIN USE.
    ///      Not trusted asset price can be manipulated.
    /// @return APR with 5 decimals. 100_000 - 100% APR, 9_955 - 9.96% APR.
    function lastApr() external view returns (uint);

    /// @dev Last APR of compounded assets registered by HardWork.
    ///      Can be used on-chain.
    /// @return APR with 5 decimals. 100_000 - 100% APR, 9_955 - 9.96% APR.
    function lastAprCompound() external view returns (uint);

    /// @notice Calculation of consumed amounts and liquidity/underlying value for provided strategy assets and amounts.
    /// @param assets_ Strategy assets or part of them, if necessary
    /// @param amountsMax Amounts of specified assets available for investing
    /// @return amountsConsumed Cosumed amounts of assets when investing
    /// @return value Liquidity value or underlying token amount minted when investing
    function previewDepositAssets(
        address[] memory assets_,
        uint[] memory amountsMax
    ) external view returns (uint[] memory amountsConsumed, uint value);

    /// @notice Write version of previewDepositAssets
    /// @param assets_ Strategy assets or part of them, if necessary
    /// @param amountsMax Amounts of specified assets available for investing
    /// @return amountsConsumed Cosumed amounts of assets when investing
    /// @return value Liquidity value or underlying token amount minted when investing
    function previewDepositAssetsWrite(
        address[] memory assets_,
        uint[] memory amountsMax
    ) external returns (uint[] memory amountsConsumed, uint value);

    /// @notice All strategy revenue (pool fees, farm rewards etc) that not claimed by strategy yet
    /// @return assets_ Revenue assets
    /// @return amounts Amounts. Index of asset same as in previous array.
    function getRevenue() external view returns (address[] memory assets_, uint[] memory amounts);

    /// @notice Optional specific name of investing strategy, underyling type, setup variation etc
    /// @return name Empty string or specific name
    /// @return showInVaultSymbol Show specific in linked vault symbol
    function getSpecificName() external view returns (string memory name, bool showInVaultSymbol);

    /// @notice Variants pf strategy initializations with description of money making mechanic.
    /// As example, if strategy need farm, then number of variations is number of available farms.
    /// If CAMM strategy have set of available widths (tick ranges), then number of variations is number of available farms.
    /// If both example conditions are met then total number or variations = total farms * total widths.
    /// @param platform_ Need this param because method called when strategy implementation is not initialized
    /// @return variants Descriptions of the strategy for making money
    /// @return addresses Init strategy addresses. Indexes for each variants depends of copmpared arrays lengths.
    /// @return nums Init strategy numbers. Indexes for each variants depends of copmpared arrays lengths.
    /// @return ticks Init strategy ticks. Indexes for each variants depends of copmpared arrays lengths.
    function initVariants(address platform_)
        external
        view
        returns (string[] memory variants, address[] memory addresses, uint[] memory nums, int24[] memory ticks);

    /// @notice How does the strategy make money?
    /// @return Description in free form
    function description() external view returns (string memory);

    /// @notice Is HardWork on vault deposits can be enabled
    function isHardWorkOnDepositAllowed() external view returns (bool);

    /// @notice Is HardWork can be executed
    function isReadyForHardWork() external view returns (bool);

    /// @notice Strategy not need to process revenue on HardWorks
    function autoCompoundingByUnderlyingProtocol() external view returns (bool);

    /// @notice Custom price impact tolerance instead default need for specific cases where liquidity in pools is low
    function customPriceImpactTolerance() external view returns (uint);

    /// @notice Total amount of assets available in the lending protocol for withdraw
    /// It's normal situation when user is not able to withdraw all
    /// because there are not enough reserves available in the protocol right now
    /// @dev This function is replaced by more flexible maxWithdrawAssets(uint mode) function.
    function maxWithdrawAssets() external view returns (uint[] memory amounts);

    /// @notice Total amount of assets available in the lending protocol for withdraw
    /// It's normal situation when user is not able to withdraw all
    /// because there are not enough reserves available in the protocol right now
    /// @param mode 0 - Return amount that can be withdrawn in assets
    ///             1 - Return amount that can be withdrawn in underlying
    /// @return amounts Empty array (zero length) is returned if all available amount can be withdrawn
    function maxWithdrawAssets(uint mode) external view returns (uint[] memory amounts);

    /// @notice Underlying pool TVL in the terms of USD
    function poolTvl() external view returns (uint tvlUsd);

    /// @notice return FUSE_ON_1 if emergency was called and all actives were transferred to the vault
    function fuseMode() external view returns (uint);

    /// @notice Maximum amounts of assets that can be deposited into the strategy
    /// @return amounts Empty array (zero length) is returned if there are no limits on deposits
    function maxDepositAssets() external view returns (uint[] memory amounts);

    /// @notice Show strategy protocols
    function protocols() external view returns (string[] memory);

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                      WRITE FUNCTIONS                       */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev A single universal initializer for all strategy implementations.
    /// @param addresses All addresses that strategy requires for initialization. Min array length is 2.
    ///        addresses[0]: platform (required)
    ///        addresses[1]: vault (required)
    ///        addresses[2]: initStrategyAddresses[0] (optional)
    ///        addresses[3]: initStrategyAddresses[1] (optional)
    ///        addresses[n]: initStrategyAddresses[n - 2] (optional)
    /// @param nums All uint values that strategy requires for initialization. Min array length is 0.
    /// @param ticks All int24 values that strategy requires for initialization. Min array length is 0.
    function initialize(address[] memory addresses, uint[] memory nums, int24[] memory ticks) external;

    /// @notice Invest strategy assets. Amounts of assets must be already on strategy contract balance.
    /// Only vault can call this.
    /// @param amounts Amounts of strategy assets
    /// @return value Liquidity value or underlying token amount
    function depositAssets(uint[] memory amounts) external returns (uint value);

    /// @notice Invest underlying asset. Asset must be already on strategy contract balance.
    /// Only vault can call this.
    /// @param amount Amount of underlying asset to invest
    /// @return amountsConsumed Consumed amounts of invested assets
    function depositUnderlying(uint amount) external returns (uint[] memory amountsConsumed);

    /// @dev For specified amount of shares and assets_, withdraw strategy assets from farm/pool/staking and send to receiver if possible
    /// Only vault can call this.
    /// @param assets_ Here we give the user a choice of assets to withdraw if strategy support it
    /// @param value Part of strategy total value to withdraw
    /// @param receiver User address
    /// @return amountsOut Amounts of assets sent to user
    function withdrawAssets(
        address[] memory assets_,
        uint value,
        address receiver
    ) external returns (uint[] memory amountsOut);

    /// @notice Wothdraw underlying invested and send to receiver
    /// Only vault can call this.
    /// @param amount Amount of underlying asset to withdraw
    /// @param receiver User of vault which withdraw underlying from the vault
    function withdrawUnderlying(uint amount, address receiver) external;

    /// @dev For specified amount of shares, transfer strategy assets from contract balance and send to receiver if possible
    /// This method is called by vault w/o underlying on triggered fuse mode.
    /// Only vault can call this.
    /// @param amount Amount of liquidity value that user withdraw
    /// @param totalAmount Total amount of strategy liquidity
    /// @param receiver User of vault which withdraw assets
    /// @return amountsOut Amounts of strategy assets sent to user
    function transferAssets(uint amount, uint totalAmount, address receiver) external returns (uint[] memory amountsOut);

    /// @notice Execute HardWork
    /// During HardWork strategy claiming revenue and processing it.
    /// Only vault can call this.
    function doHardWork() external;

    /// @notice Emergency stop investing by strategy, withdraw liquidity without rewards.
    /// This action triggers FUSE mode.
    /// Only governance or multisig can call this.
    function emergencyStopInvesting() external;

    /// @notice Custom price impact tolerance instead default need for specific cases where low liquidity in pools
    /// @param priceImpactTolerance Tolerance percent with 100_000 DENOMINATOR. 4_000 == 4%
    function setCustomPriceImpactTolerance(uint priceImpactTolerance) external;

    /// @notice Set custom strategy protocols
    /// @param protocols_ Row format is: defi_organization_id:protocol_id from Stability Library.
    function setProtocols(string[] calldata protocols_) external;

    /// @notice Set custom specific name
    function setSpecificName(string memory specific) external;
}

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

/// @dev Interface of proxy contract for a strategy implementation
interface IStrategyProxy {
    /// @notice Initialize strategy proxy by Factory
    /// @param id Strategy logic ID string
    function initStrategyProxy(string memory id) external;

    /// @notice Upgrade strategy implementation if available and allowed
    /// Anyone can execute strategy upgrade
    function upgrade() external;

    /// @notice Current strategy implementation
    /// @return Address of strategy implementation contract
    function implementation() external view returns (address);

    /// @notice Strategy logic hash
    /// @return keccan256 hash of strategy logic ID string
    function strategyImplementationLogicIdHash() external view returns (bytes32);
}

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

import {IERC721Metadata} from "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol";

/// @notice The vaults are assembled at the factory by users through UI.
///         Deployment rights of a vault are tokenized in VaultManager NFT.
///         The holders of these tokens receive a share of the vault revenue and can manage vault if possible.
/// @dev Rewards transfers to token owner or revenue receiver address managed by token owner.
/// @author Alien Deployer (https://github.com/a17)
/// @author Jude (https://github.com/iammrjude)
/// @author JodsMigel (https://github.com/JodsMigel)
interface IVaultManager is IERC721Metadata {
    //region ----- Events -----
    event ChangeVaultParams(uint tokenId, address[] addresses, uint[] nums);
    event SetRevenueReceiver(uint tokenId, address receiver);
    //endregion -- Events -----

    struct VaultData {
        // vault
        uint tokenId;
        address vault;
        string vaultType;
        string name;
        string symbol;
        string[] assetsSymbols;
        string[] rewardAssetsSymbols;
        uint sharePrice;
        uint tvl;
        uint totalApr;
        bytes32 vaultExtra;
        // strategy
        uint strategyTokenId;
        string strategyId;
        string strategySpecific;
        uint strategyApr;
        bytes32 strategyExtra;
    }

    //region ----- View functions -----

    /// @notice Vault address managed by token
    /// @param tokenId ID of NFT. Starts from 0 and increments on mints.
    /// @return vault Address of vault proxy
    function tokenVault(uint tokenId) external view returns (address vault);

    /// @notice Receiver of token owner's platform revenue share
    /// @param tokenId ID of NFT
    /// @return receiver Address of vault manager fees receiver
    function getRevenueReceiver(uint tokenId) external view returns (address receiver);

    /// @notice All vaults data.
    /// DEPRECATED: use IFrontend.vaults
    /// The output values are matched by index in the arrays.
    /// @param vaultAddress Vault addresses
    /// @param name Vault name
    /// @param symbol Vault symbol
    /// @param vaultType Vault type ID string
    /// @param strategyId Strategy logic ID string
    /// @param sharePrice Current vault share price in USD. 18 decimals
    /// @param tvl Current vault TVL in USD. 18 decimals
    /// @param totalApr Last total vault APR. Denominator is 100_00.
    /// @param strategyApr Last strategy APR. Denominator is 100_00.
    /// @param strategySpecific Strategy specific name
    function vaults()
        external
        view
        returns (
            address[] memory vaultAddress,
            string[] memory name,
            string[] memory symbol,
            string[] memory vaultType,
            string[] memory strategyId,
            uint[] memory sharePrice,
            uint[] memory tvl,
            uint[] memory totalApr,
            uint[] memory strategyApr,
            string[] memory strategySpecific
        );

    /// @notice All deployed vault addresses
    /// @return vaultAddress Addresses of vault proxy
    function vaultAddresses() external view returns (address[] memory vaultAddress);

    /// @notice Vault extended info getter
    /// @param vault Address of vault proxy
    /// @return strategy
    /// @return strategyAssets
    /// @return underlying
    /// @return assetsWithApr Deprecated
    /// @return assetsAprs Deprecated
    /// @return lastHardWork Last HardWork time
    function vaultInfo(address vault)
        external
        view
        returns (
            address strategy,
            address[] memory strategyAssets,
            address underlying,
            address[] memory assetsWithApr,
            uint[] memory assetsAprs,
            uint lastHardWork
        );

    //endregion -- View functions -----

    //region ----- Write functions -----

    /// @notice Changing managed vault init parameters by Vault Manager (owner of VaultManager NFT)
    /// @param tokenId ID of VaultManager NFT
    /// @param addresses Vault init addresses. Must contain also not changeable init addresses
    /// @param nums Vault init numbers. Must contant also not changeable init numbers
    function changeVaultParams(uint tokenId, address[] memory addresses, uint[] memory nums) external;

    /// @notice Minting of new token on deploying vault by Factory
    /// Only Factory can call this.
    /// @param to User which creates vault
    /// @param vault Address of vault proxy
    /// @return tokenId Minted token ID
    function mint(address to, address vault) external returns (uint tokenId);

    /// @notice Owner of token can change revenue reciever of platform fee share
    /// @param tokenId Owned token ID
    /// @param receiver New revenue receiver address
    function setRevenueReceiver(uint tokenId, address receiver) external;

    //endregion -- Write functions -----
}

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

import {IERC721Metadata} from "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol";

/// @dev Interface of developed strategy logic NFT
/// @author Alien Deployer (https://github.com/a17)
/// @author Jude (https://github.com/iammrjude)
/// @author JodsMigel (https://github.com/JodsMigel)
interface IStrategyLogic is IERC721Metadata {
    //region ----- Events -----
    event SetRevenueReceiver(uint tokenId, address receiver);
    //endregion -- Events -----

    struct StrategyData {
        uint strategyTokenId;
        string strategyId;
        bytes32 strategyExtra;
    }

    /// @notice Minting of new developed strategy by the factory
    /// @dev Parameters from StrategyDeveloperLib, StrategyIdLib.
    /// Only factory can call it.
    /// @param to Strategy developer address
    /// @param strategyLogicId Strategy logic ID string
    /// @return tokenId Minted token ID
    function mint(address to, string memory strategyLogicId) external returns (uint tokenId);

    /// @notice Owner of token can change address for receiving strategy logic revenue share
    /// Only owner of token can call it.
    /// @param tokenId Owned token ID
    /// @param receiver Address for receiving revenue
    function setRevenueReceiver(uint tokenId, address receiver) external;

    /// @notice Token ID to strategy logic ID map
    /// @param tokenId Owned token ID
    /// @return strategyLogicId Strategy logic ID string
    function tokenStrategyLogic(uint tokenId) external view returns (string memory strategyLogicId);

    /// @notice Current revenue reciever for token
    /// @param tokenId Token ID
    /// @return receiver Address for receiving revenue
    function getRevenueReceiver(uint tokenId) external view returns (address receiver);
}

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

pragma solidity >=0.6.2;

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

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

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

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

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

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

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

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (proxy/utils/Initializable.sol)

pragma solidity ^0.8.20;

/**
 * @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 Storage of the initializable contract.
     *
     * It's implemented on a custom ERC-7201 namespace to reduce the risk of storage collisions
     * when using with upgradeable contracts.
     *
     * @custom:storage-location erc7201:openzeppelin.storage.Initializable
     */
    struct InitializableStorage {
        /**
         * @dev Indicates that the contract has been initialized.
         */
        uint64 _initialized;
        /**
         * @dev Indicates that the contract is in the process of being initialized.
         */
        bool _initializing;
    }

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Initializable")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant INITIALIZABLE_STORAGE = 0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00;

    /**
     * @dev The contract is already initialized.
     */
    error InvalidInitialization();

    /**
     * @dev The contract is not initializing.
     */
    error NotInitializing();

    /**
     * @dev Triggered when the contract has been initialized or reinitialized.
     */
    event Initialized(uint64 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 in the context of a constructor an `initializer` may be invoked any
     * number of times. This behavior in the constructor can be useful during testing and is not expected to be used in
     * production.
     *
     * Emits an {Initialized} event.
     */
    modifier initializer() {
        // solhint-disable-next-line var-name-mixedcase
        InitializableStorage storage $ = _getInitializableStorage();

        // Cache values to avoid duplicated sloads
        bool isTopLevelCall = !$._initializing;
        uint64 initialized = $._initialized;

        // Allowed calls:
        // - initialSetup: the contract is not in the initializing state and no previous version was
        //                 initialized
        // - construction: the contract is initialized at version 1 (no reinitialization) and the
        //                 current contract is just being deployed
        bool initialSetup = initialized == 0 && isTopLevelCall;
        bool construction = initialized == 1 && address(this).code.length == 0;

        if (!initialSetup && !construction) {
            revert InvalidInitialization();
        }
        $._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 2**64 - 1 will prevent any future reinitialization.
     *
     * Emits an {Initialized} event.
     */
    modifier reinitializer(uint64 version) {
        // solhint-disable-next-line var-name-mixedcase
        InitializableStorage storage $ = _getInitializableStorage();

        if ($._initializing || $._initialized >= version) {
            revert InvalidInitialization();
        }
        $._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() {
        _checkInitializing();
        _;
    }

    /**
     * @dev Reverts if the contract is not in an initializing state. See {onlyInitializing}.
     */
    function _checkInitializing() internal view virtual {
        if (!_isInitializing()) {
            revert NotInitializing();
        }
    }

    /**
     * @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 {
        // solhint-disable-next-line var-name-mixedcase
        InitializableStorage storage $ = _getInitializableStorage();

        if ($._initializing) {
            revert InvalidInitialization();
        }
        if ($._initialized != type(uint64).max) {
            $._initialized = type(uint64).max;
            emit Initialized(type(uint64).max);
        }
    }

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

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

    /**
     * @dev Pointer to storage slot. Allows integrators to override it with a custom storage location.
     *
     * NOTE: Consider following the ERC-7201 formula to derive storage locations.
     */
    function _initializableStorageSlot() internal pure virtual returns (bytes32) {
        return INITIALIZABLE_STORAGE;
    }

    /**
     * @dev Returns a pointer to the storage namespace.
     */
    // solhint-disable-next-line var-name-mixedcase
    function _getInitializableStorage() private pure returns (InitializableStorage storage $) {
        bytes32 slot = _initializableStorageSlot();
        assembly {
            $.slot := slot
        }
    }
}

File 23 of 48 : Arrays.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (utils/Arrays.sol)
// This file was procedurally generated from scripts/generate/templates/Arrays.js.

pragma solidity ^0.8.20;

import {Comparators} from "./Comparators.sol";
import {SlotDerivation} from "./SlotDerivation.sol";
import {StorageSlot} from "./StorageSlot.sol";
import {Math} from "./math/Math.sol";

/**
 * @dev Collection of functions related to array types.
 */
library Arrays {
    using SlotDerivation for bytes32;
    using StorageSlot for bytes32;

    /**
     * @dev Sort an array of uint256 (in memory) following the provided comparator function.
     *
     * This function does the sorting "in place", meaning that it overrides the input. The object is returned for
     * convenience, but that returned value can be discarded safely if the caller has a memory pointer to the array.
     *
     * NOTE: this function's cost is `O(n · log(n))` in average and `O(n²)` in the worst case, with n the length of the
     * array. Using it in view functions that are executed through `eth_call` is safe, but one should be very careful
     * when executing this as part of a transaction. If the array being sorted is too large, the sort operation may
     * consume more gas than is available in a block, leading to potential DoS.
     *
     * IMPORTANT: Consider memory side-effects when using custom comparator functions that access memory in an unsafe way.
     */
    function sort(
        uint256[] memory array,
        function(uint256, uint256) pure returns (bool) comp
    ) internal pure returns (uint256[] memory) {
        _quickSort(_begin(array), _end(array), comp);
        return array;
    }

    /**
     * @dev Variant of {sort} that sorts an array of uint256 in increasing order.
     */
    function sort(uint256[] memory array) internal pure returns (uint256[] memory) {
        sort(array, Comparators.lt);
        return array;
    }

    /**
     * @dev Sort an array of address (in memory) following the provided comparator function.
     *
     * This function does the sorting "in place", meaning that it overrides the input. The object is returned for
     * convenience, but that returned value can be discarded safely if the caller has a memory pointer to the array.
     *
     * NOTE: this function's cost is `O(n · log(n))` in average and `O(n²)` in the worst case, with n the length of the
     * array. Using it in view functions that are executed through `eth_call` is safe, but one should be very careful
     * when executing this as part of a transaction. If the array being sorted is too large, the sort operation may
     * consume more gas than is available in a block, leading to potential DoS.
     *
     * IMPORTANT: Consider memory side-effects when using custom comparator functions that access memory in an unsafe way.
     */
    function sort(
        address[] memory array,
        function(address, address) pure returns (bool) comp
    ) internal pure returns (address[] memory) {
        sort(_castToUint256Array(array), _castToUint256Comp(comp));
        return array;
    }

    /**
     * @dev Variant of {sort} that sorts an array of address in increasing order.
     */
    function sort(address[] memory array) internal pure returns (address[] memory) {
        sort(_castToUint256Array(array), Comparators.lt);
        return array;
    }

    /**
     * @dev Sort an array of bytes32 (in memory) following the provided comparator function.
     *
     * This function does the sorting "in place", meaning that it overrides the input. The object is returned for
     * convenience, but that returned value can be discarded safely if the caller has a memory pointer to the array.
     *
     * NOTE: this function's cost is `O(n · log(n))` in average and `O(n²)` in the worst case, with n the length of the
     * array. Using it in view functions that are executed through `eth_call` is safe, but one should be very careful
     * when executing this as part of a transaction. If the array being sorted is too large, the sort operation may
     * consume more gas than is available in a block, leading to potential DoS.
     *
     * IMPORTANT: Consider memory side-effects when using custom comparator functions that access memory in an unsafe way.
     */
    function sort(
        bytes32[] memory array,
        function(bytes32, bytes32) pure returns (bool) comp
    ) internal pure returns (bytes32[] memory) {
        sort(_castToUint256Array(array), _castToUint256Comp(comp));
        return array;
    }

    /**
     * @dev Variant of {sort} that sorts an array of bytes32 in increasing order.
     */
    function sort(bytes32[] memory array) internal pure returns (bytes32[] memory) {
        sort(_castToUint256Array(array), Comparators.lt);
        return array;
    }

    /**
     * @dev Performs a quick sort of a segment of memory. The segment sorted starts at `begin` (inclusive), and stops
     * at end (exclusive). Sorting follows the `comp` comparator.
     *
     * Invariant: `begin <= end`. This is the case when initially called by {sort} and is preserved in subcalls.
     *
     * IMPORTANT: Memory locations between `begin` and `end` are not validated/zeroed. This function should
     * be used only if the limits are within a memory array.
     */
    function _quickSort(uint256 begin, uint256 end, function(uint256, uint256) pure returns (bool) comp) private pure {
        unchecked {
            if (end - begin < 0x40) return;

            // Use first element as pivot
            uint256 pivot = _mload(begin);
            // Position where the pivot should be at the end of the loop
            uint256 pos = begin;

            for (uint256 it = begin + 0x20; it < end; it += 0x20) {
                if (comp(_mload(it), pivot)) {
                    // If the value stored at the iterator's position comes before the pivot, we increment the
                    // position of the pivot and move the value there.
                    pos += 0x20;
                    _swap(pos, it);
                }
            }

            _swap(begin, pos); // Swap pivot into place
            _quickSort(begin, pos, comp); // Sort the left side of the pivot
            _quickSort(pos + 0x20, end, comp); // Sort the right side of the pivot
        }
    }

    /**
     * @dev Pointer to the memory location of the first element of `array`.
     */
    function _begin(uint256[] memory array) private pure returns (uint256 ptr) {
        assembly ("memory-safe") {
            ptr := add(array, 0x20)
        }
    }

    /**
     * @dev Pointer to the memory location of the first memory word (32bytes) after `array`. This is the memory word
     * that comes just after the last element of the array.
     */
    function _end(uint256[] memory array) private pure returns (uint256 ptr) {
        unchecked {
            return _begin(array) + array.length * 0x20;
        }
    }

    /**
     * @dev Load memory word (as a uint256) at location `ptr`.
     */
    function _mload(uint256 ptr) private pure returns (uint256 value) {
        assembly {
            value := mload(ptr)
        }
    }

    /**
     * @dev Swaps the elements memory location `ptr1` and `ptr2`.
     */
    function _swap(uint256 ptr1, uint256 ptr2) private pure {
        assembly {
            let value1 := mload(ptr1)
            let value2 := mload(ptr2)
            mstore(ptr1, value2)
            mstore(ptr2, value1)
        }
    }

    /// @dev Helper: low level cast address memory array to uint256 memory array
    function _castToUint256Array(address[] memory input) private pure returns (uint256[] memory output) {
        assembly {
            output := input
        }
    }

    /// @dev Helper: low level cast bytes32 memory array to uint256 memory array
    function _castToUint256Array(bytes32[] memory input) private pure returns (uint256[] memory output) {
        assembly {
            output := input
        }
    }

    /// @dev Helper: low level cast address comp function to uint256 comp function
    function _castToUint256Comp(
        function(address, address) pure returns (bool) input
    ) private pure returns (function(uint256, uint256) pure returns (bool) output) {
        assembly {
            output := input
        }
    }

    /// @dev Helper: low level cast bytes32 comp function to uint256 comp function
    function _castToUint256Comp(
        function(bytes32, bytes32) pure returns (bool) input
    ) private pure returns (function(uint256, uint256) pure returns (bool) output) {
        assembly {
            output := input
        }
    }

    /**
     * @dev Searches a sorted `array` and returns the first index that contains
     * a value greater or equal to `element`. If no such index exists (i.e. all
     * values in the array are strictly less than `element`), the array length is
     * returned. Time complexity O(log n).
     *
     * NOTE: The `array` is expected to be sorted in ascending order, and to
     * contain no repeated elements.
     *
     * IMPORTANT: Deprecated. This implementation behaves as {lowerBound} but lacks
     * support for repeated elements in the array. The {lowerBound} function should
     * be used instead.
     */
    function findUpperBound(uint256[] storage array, uint256 element) internal view returns (uint256) {
        uint256 low = 0;
        uint256 high = array.length;

        if (high == 0) {
            return 0;
        }

        while (low < high) {
            uint256 mid = Math.average(low, high);

            // Note that mid will always be strictly less than high (i.e. it will be a valid array index)
            // because Math.average rounds towards zero (it does integer division with truncation).
            if (unsafeAccess(array, mid).value > element) {
                high = mid;
            } else {
                low = mid + 1;
            }
        }

        // At this point `low` is the exclusive upper bound. We will return the inclusive upper bound.
        if (low > 0 && unsafeAccess(array, low - 1).value == element) {
            return low - 1;
        } else {
            return low;
        }
    }

    /**
     * @dev Searches an `array` sorted in ascending order and returns the first
     * index that contains a value greater or equal than `element`. If no such index
     * exists (i.e. all values in the array are strictly less than `element`), the array
     * length is returned. Time complexity O(log n).
     *
     * See C++'s https://en.cppreference.com/w/cpp/algorithm/lower_bound[lower_bound].
     */
    function lowerBound(uint256[] storage array, uint256 element) internal view returns (uint256) {
        uint256 low = 0;
        uint256 high = array.length;

        if (high == 0) {
            return 0;
        }

        while (low < high) {
            uint256 mid = Math.average(low, high);

            // Note that mid will always be strictly less than high (i.e. it will be a valid array index)
            // because Math.average rounds towards zero (it does integer division with truncation).
            if (unsafeAccess(array, mid).value < element) {
                // this cannot overflow because mid < high
                unchecked {
                    low = mid + 1;
                }
            } else {
                high = mid;
            }
        }

        return low;
    }

    /**
     * @dev Searches an `array` sorted in ascending order and returns the first
     * index that contains a value strictly greater than `element`. If no such index
     * exists (i.e. all values in the array are strictly less than `element`), the array
     * length is returned. Time complexity O(log n).
     *
     * See C++'s https://en.cppreference.com/w/cpp/algorithm/upper_bound[upper_bound].
     */
    function upperBound(uint256[] storage array, uint256 element) internal view returns (uint256) {
        uint256 low = 0;
        uint256 high = array.length;

        if (high == 0) {
            return 0;
        }

        while (low < high) {
            uint256 mid = Math.average(low, high);

            // Note that mid will always be strictly less than high (i.e. it will be a valid array index)
            // because Math.average rounds towards zero (it does integer division with truncation).
            if (unsafeAccess(array, mid).value > element) {
                high = mid;
            } else {
                // this cannot overflow because mid < high
                unchecked {
                    low = mid + 1;
                }
            }
        }

        return low;
    }

    /**
     * @dev Same as {lowerBound}, but with an array in memory.
     */
    function lowerBoundMemory(uint256[] memory array, uint256 element) internal pure returns (uint256) {
        uint256 low = 0;
        uint256 high = array.length;

        if (high == 0) {
            return 0;
        }

        while (low < high) {
            uint256 mid = Math.average(low, high);

            // Note that mid will always be strictly less than high (i.e. it will be a valid array index)
            // because Math.average rounds towards zero (it does integer division with truncation).
            if (unsafeMemoryAccess(array, mid) < element) {
                // this cannot overflow because mid < high
                unchecked {
                    low = mid + 1;
                }
            } else {
                high = mid;
            }
        }

        return low;
    }

    /**
     * @dev Same as {upperBound}, but with an array in memory.
     */
    function upperBoundMemory(uint256[] memory array, uint256 element) internal pure returns (uint256) {
        uint256 low = 0;
        uint256 high = array.length;

        if (high == 0) {
            return 0;
        }

        while (low < high) {
            uint256 mid = Math.average(low, high);

            // Note that mid will always be strictly less than high (i.e. it will be a valid array index)
            // because Math.average rounds towards zero (it does integer division with truncation).
            if (unsafeMemoryAccess(array, mid) > element) {
                high = mid;
            } else {
                // this cannot overflow because mid < high
                unchecked {
                    low = mid + 1;
                }
            }
        }

        return low;
    }

    /**
     * @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
     *
     * WARNING: Only use if you are certain `pos` is lower than the array length.
     */
    function unsafeAccess(address[] storage arr, uint256 pos) internal pure returns (StorageSlot.AddressSlot storage) {
        bytes32 slot;
        assembly ("memory-safe") {
            slot := arr.slot
        }
        return slot.deriveArray().offset(pos).getAddressSlot();
    }

    /**
     * @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
     *
     * WARNING: Only use if you are certain `pos` is lower than the array length.
     */
    function unsafeAccess(bytes32[] storage arr, uint256 pos) internal pure returns (StorageSlot.Bytes32Slot storage) {
        bytes32 slot;
        assembly ("memory-safe") {
            slot := arr.slot
        }
        return slot.deriveArray().offset(pos).getBytes32Slot();
    }

    /**
     * @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
     *
     * WARNING: Only use if you are certain `pos` is lower than the array length.
     */
    function unsafeAccess(uint256[] storage arr, uint256 pos) internal pure returns (StorageSlot.Uint256Slot storage) {
        bytes32 slot;
        assembly ("memory-safe") {
            slot := arr.slot
        }
        return slot.deriveArray().offset(pos).getUint256Slot();
    }

    /**
     * @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
     *
     * WARNING: Only use if you are certain `pos` is lower than the array length.
     */
    function unsafeAccess(bytes[] storage arr, uint256 pos) internal pure returns (StorageSlot.BytesSlot storage) {
        bytes32 slot;
        assembly ("memory-safe") {
            slot := arr.slot
        }
        return slot.deriveArray().offset(pos).getBytesSlot();
    }

    /**
     * @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
     *
     * WARNING: Only use if you are certain `pos` is lower than the array length.
     */
    function unsafeAccess(string[] storage arr, uint256 pos) internal pure returns (StorageSlot.StringSlot storage) {
        bytes32 slot;
        assembly ("memory-safe") {
            slot := arr.slot
        }
        return slot.deriveArray().offset(pos).getStringSlot();
    }

    /**
     * @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
     *
     * WARNING: Only use if you are certain `pos` is lower than the array length.
     */
    function unsafeMemoryAccess(address[] memory arr, uint256 pos) internal pure returns (address res) {
        assembly {
            res := mload(add(add(arr, 0x20), mul(pos, 0x20)))
        }
    }

    /**
     * @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
     *
     * WARNING: Only use if you are certain `pos` is lower than the array length.
     */
    function unsafeMemoryAccess(bytes32[] memory arr, uint256 pos) internal pure returns (bytes32 res) {
        assembly {
            res := mload(add(add(arr, 0x20), mul(pos, 0x20)))
        }
    }

    /**
     * @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
     *
     * WARNING: Only use if you are certain `pos` is lower than the array length.
     */
    function unsafeMemoryAccess(uint256[] memory arr, uint256 pos) internal pure returns (uint256 res) {
        assembly {
            res := mload(add(add(arr, 0x20), mul(pos, 0x20)))
        }
    }

    /**
     * @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
     *
     * WARNING: Only use if you are certain `pos` is lower than the array length.
     */
    function unsafeMemoryAccess(bytes[] memory arr, uint256 pos) internal pure returns (bytes memory res) {
        assembly {
            res := mload(add(add(arr, 0x20), mul(pos, 0x20)))
        }
    }

    /**
     * @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
     *
     * WARNING: Only use if you are certain `pos` is lower than the array length.
     */
    function unsafeMemoryAccess(string[] memory arr, uint256 pos) internal pure returns (string memory res) {
        assembly {
            res := mload(add(add(arr, 0x20), mul(pos, 0x20)))
        }
    }

    /**
     * @dev Helper to set the length of a dynamic array. Directly writing to `.length` is forbidden.
     *
     * WARNING: this does not clear elements if length is reduced, of initialize elements if length is increased.
     */
    function unsafeSetLength(address[] storage array, uint256 len) internal {
        assembly ("memory-safe") {
            sstore(array.slot, len)
        }
    }

    /**
     * @dev Helper to set the length of a dynamic array. Directly writing to `.length` is forbidden.
     *
     * WARNING: this does not clear elements if length is reduced, of initialize elements if length is increased.
     */
    function unsafeSetLength(bytes32[] storage array, uint256 len) internal {
        assembly ("memory-safe") {
            sstore(array.slot, len)
        }
    }

    /**
     * @dev Helper to set the length of a dynamic array. Directly writing to `.length` is forbidden.
     *
     * WARNING: this does not clear elements if length is reduced, of initialize elements if length is increased.
     */
    function unsafeSetLength(uint256[] storage array, uint256 len) internal {
        assembly ("memory-safe") {
            sstore(array.slot, len)
        }
    }

    /**
     * @dev Helper to set the length of a dynamic array. Directly writing to `.length` is forbidden.
     *
     * WARNING: this does not clear elements if length is reduced, of initialize elements if length is increased.
     */
    function unsafeSetLength(bytes[] storage array, uint256 len) internal {
        assembly ("memory-safe") {
            sstore(array.slot, len)
        }
    }

    /**
     * @dev Helper to set the length of a dynamic array. Directly writing to `.length` is forbidden.
     *
     * WARNING: this does not clear elements if length is reduced, of initialize elements if length is increased.
     */
    function unsafeSetLength(string[] storage array, uint256 len) internal {
        assembly ("memory-safe") {
            sstore(array.slot, len)
        }
    }
}

File 24 of 48 : Math.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/math/Math.sol)

pragma solidity ^0.8.20;

import {Panic} from "../Panic.sol";
import {SafeCast} from "./SafeCast.sol";

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library Math {
    enum Rounding {
        Floor, // Toward negative infinity
        Ceil, // Toward positive infinity
        Trunc, // Toward zero
        Expand // Away from zero
    }

    /**
     * @dev Return the 512-bit addition of two uint256.
     *
     * The result is stored in two 256 variables such that sum = high * 2²⁵⁶ + low.
     */
    function add512(uint256 a, uint256 b) internal pure returns (uint256 high, uint256 low) {
        assembly ("memory-safe") {
            low := add(a, b)
            high := lt(low, a)
        }
    }

    /**
     * @dev Return the 512-bit multiplication of two uint256.
     *
     * The result is stored in two 256 variables such that product = high * 2²⁵⁶ + low.
     */
    function mul512(uint256 a, uint256 b) internal pure returns (uint256 high, uint256 low) {
        // 512-bit multiply [high low] = x * y. Compute the product mod 2²⁵⁶ and mod 2²⁵⁶ - 1, then use
        // the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
        // variables such that product = high * 2²⁵⁶ + low.
        assembly ("memory-safe") {
            let mm := mulmod(a, b, not(0))
            low := mul(a, b)
            high := sub(sub(mm, low), lt(mm, low))
        }
    }

    /**
     * @dev Returns the addition of two unsigned integers, with a success flag (no overflow).
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
        unchecked {
            uint256 c = a + b;
            success = c >= a;
            result = c * SafeCast.toUint(success);
        }
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, with a success flag (no overflow).
     */
    function trySub(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
        unchecked {
            uint256 c = a - b;
            success = c <= a;
            result = c * SafeCast.toUint(success);
        }
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, with a success flag (no overflow).
     */
    function tryMul(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
        unchecked {
            uint256 c = a * b;
            assembly ("memory-safe") {
                // Only true when the multiplication doesn't overflow
                // (c / a == b) || (a == 0)
                success := or(eq(div(c, a), b), iszero(a))
            }
            // equivalent to: success ? c : 0
            result = c * SafeCast.toUint(success);
        }
    }

    /**
     * @dev Returns the division of two unsigned integers, with a success flag (no division by zero).
     */
    function tryDiv(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
        unchecked {
            success = b > 0;
            assembly ("memory-safe") {
                // The `DIV` opcode returns zero when the denominator is 0.
                result := div(a, b)
            }
        }
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers, with a success flag (no division by zero).
     */
    function tryMod(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
        unchecked {
            success = b > 0;
            assembly ("memory-safe") {
                // The `MOD` opcode returns zero when the denominator is 0.
                result := mod(a, b)
            }
        }
    }

    /**
     * @dev Unsigned saturating addition, bounds to `2²⁵⁶ - 1` instead of overflowing.
     */
    function saturatingAdd(uint256 a, uint256 b) internal pure returns (uint256) {
        (bool success, uint256 result) = tryAdd(a, b);
        return ternary(success, result, type(uint256).max);
    }

    /**
     * @dev Unsigned saturating subtraction, bounds to zero instead of overflowing.
     */
    function saturatingSub(uint256 a, uint256 b) internal pure returns (uint256) {
        (, uint256 result) = trySub(a, b);
        return result;
    }

    /**
     * @dev Unsigned saturating multiplication, bounds to `2²⁵⁶ - 1` instead of overflowing.
     */
    function saturatingMul(uint256 a, uint256 b) internal pure returns (uint256) {
        (bool success, uint256 result) = tryMul(a, b);
        return ternary(success, result, type(uint256).max);
    }

    /**
     * @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.
     *
     * IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.
     * However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute
     * one branch when needed, making this function more expensive.
     */
    function ternary(bool condition, uint256 a, uint256 b) internal pure returns (uint256) {
        unchecked {
            // branchless ternary works because:
            // b ^ (a ^ b) == a
            // b ^ 0 == b
            return b ^ ((a ^ b) * SafeCast.toUint(condition));
        }
    }

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

    /**
     * @dev Returns the smallest of two numbers.
     */
    function min(uint256 a, uint256 b) internal pure returns (uint256) {
        return ternary(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 towards infinity instead
     * of rounding towards zero.
     */
    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
        if (b == 0) {
            // Guarantee the same behavior as in a regular Solidity division.
            Panic.panic(Panic.DIVISION_BY_ZERO);
        }

        // The following calculation ensures accurate ceiling division without overflow.
        // Since a is non-zero, (a - 1) / b will not overflow.
        // The largest possible result occurs when (a - 1) / b is type(uint256).max,
        // but the largest value we can obtain is type(uint256).max - 1, which happens
        // when a = type(uint256).max and b = 1.
        unchecked {
            return SafeCast.toUint(a > 0) * ((a - 1) / b + 1);
        }
    }

    /**
     * @dev Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or
     * denominator == 0.
     *
     * 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 {
            (uint256 high, uint256 low) = mul512(x, y);

            // Handle non-overflow cases, 256 by 256 division.
            if (high == 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 low / denominator;
            }

            // Make sure the result is less than 2²⁵⁶. Also prevents denominator == 0.
            if (denominator <= high) {
                Panic.panic(ternary(denominator == 0, Panic.DIVISION_BY_ZERO, Panic.UNDER_OVERFLOW));
            }

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

            // Make division exact by subtracting the remainder from [high low].
            uint256 remainder;
            assembly ("memory-safe") {
                // Compute remainder using mulmod.
                remainder := mulmod(x, y, denominator)

                // Subtract 256 bit number from 512 bit number.
                high := sub(high, gt(remainder, low))
                low := sub(low, 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.

            uint256 twos = denominator & (0 - denominator);
            assembly ("memory-safe") {
                // Divide denominator by twos.
                denominator := div(denominator, twos)

                // Divide [high low] by twos.
                low := div(low, twos)

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

            // Shift in bits from high into low.
            low |= high * twos;

            // Invert denominator mod 2²⁵⁶. Now that denominator is an odd number, it has an inverse modulo 2²⁵⁶ such
            // that denominator * inv ≡ 1 mod 2²⁵⁶. Compute the inverse by starting with a seed that is correct for
            // four bits. That is, denominator * inv ≡ 1 mod 2⁴.
            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⁸
            inverse *= 2 - denominator * inverse; // inverse mod 2¹⁶
            inverse *= 2 - denominator * inverse; // inverse mod 2³²
            inverse *= 2 - denominator * inverse; // inverse mod 2⁶⁴
            inverse *= 2 - denominator * inverse; // inverse mod 2¹²⁸
            inverse *= 2 - denominator * inverse; // inverse mod 2²⁵⁶

            // 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²⁵⁶. Since the preconditions guarantee that the outcome is
            // less than 2²⁵⁶, this is the final result. We don't need to compute the high bits of the result and high
            // is no longer required.
            result = low * inverse;
            return result;
        }
    }

    /**
     * @dev 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) {
        return mulDiv(x, y, denominator) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0);
    }

    /**
     * @dev Calculates floor(x * y >> n) with full precision. Throws if result overflows a uint256.
     */
    function mulShr(uint256 x, uint256 y, uint8 n) internal pure returns (uint256 result) {
        unchecked {
            (uint256 high, uint256 low) = mul512(x, y);
            if (high >= 1 << n) {
                Panic.panic(Panic.UNDER_OVERFLOW);
            }
            return (high << (256 - n)) | (low >> n);
        }
    }

    /**
     * @dev Calculates x * y >> n with full precision, following the selected rounding direction.
     */
    function mulShr(uint256 x, uint256 y, uint8 n, Rounding rounding) internal pure returns (uint256) {
        return mulShr(x, y, n) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, 1 << n) > 0);
    }

    /**
     * @dev Calculate the modular multiplicative inverse of a number in Z/nZ.
     *
     * If n is a prime, then Z/nZ is a field. In that case all elements are inversible, except 0.
     * If n is not a prime, then Z/nZ is not a field, and some elements might not be inversible.
     *
     * If the input value is not inversible, 0 is returned.
     *
     * NOTE: If you know for sure that n is (big) a prime, it may be cheaper to use Fermat's little theorem and get the
     * inverse using `Math.modExp(a, n - 2, n)`. See {invModPrime}.
     */
    function invMod(uint256 a, uint256 n) internal pure returns (uint256) {
        unchecked {
            if (n == 0) return 0;

            // The inverse modulo is calculated using the Extended Euclidean Algorithm (iterative version)
            // Used to compute integers x and y such that: ax + ny = gcd(a, n).
            // When the gcd is 1, then the inverse of a modulo n exists and it's x.
            // ax + ny = 1
            // ax = 1 + (-y)n
            // ax ≡ 1 (mod n) # x is the inverse of a modulo n

            // If the remainder is 0 the gcd is n right away.
            uint256 remainder = a % n;
            uint256 gcd = n;

            // Therefore the initial coefficients are:
            // ax + ny = gcd(a, n) = n
            // 0a + 1n = n
            int256 x = 0;
            int256 y = 1;

            while (remainder != 0) {
                uint256 quotient = gcd / remainder;

                (gcd, remainder) = (
                    // The old remainder is the next gcd to try.
                    remainder,
                    // Compute the next remainder.
                    // Can't overflow given that (a % gcd) * (gcd // (a % gcd)) <= gcd
                    // where gcd is at most n (capped to type(uint256).max)
                    gcd - remainder * quotient
                );

                (x, y) = (
                    // Increment the coefficient of a.
                    y,
                    // Decrement the coefficient of n.
                    // Can overflow, but the result is casted to uint256 so that the
                    // next value of y is "wrapped around" to a value between 0 and n - 1.
                    x - y * int256(quotient)
                );
            }

            if (gcd != 1) return 0; // No inverse exists.
            return ternary(x < 0, n - uint256(-x), uint256(x)); // Wrap the result if it's negative.
        }
    }

    /**
     * @dev Variant of {invMod}. More efficient, but only works if `p` is known to be a prime greater than `2`.
     *
     * From https://en.wikipedia.org/wiki/Fermat%27s_little_theorem[Fermat's little theorem], we know that if p is
     * prime, then `a**(p-1) ≡ 1 mod p`. As a consequence, we have `a * a**(p-2) ≡ 1 mod p`, which means that
     * `a**(p-2)` is the modular multiplicative inverse of a in Fp.
     *
     * NOTE: this function does NOT check that `p` is a prime greater than `2`.
     */
    function invModPrime(uint256 a, uint256 p) internal view returns (uint256) {
        unchecked {
            return Math.modExp(a, p - 2, p);
        }
    }

    /**
     * @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m)
     *
     * Requirements:
     * - modulus can't be zero
     * - underlying staticcall to precompile must succeed
     *
     * IMPORTANT: The result is only valid if the underlying call succeeds. When using this function, make
     * sure the chain you're using it on supports the precompiled contract for modular exponentiation
     * at address 0x05 as specified in https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise,
     * the underlying function will succeed given the lack of a revert, but the result may be incorrectly
     * interpreted as 0.
     */
    function modExp(uint256 b, uint256 e, uint256 m) internal view returns (uint256) {
        (bool success, uint256 result) = tryModExp(b, e, m);
        if (!success) {
            Panic.panic(Panic.DIVISION_BY_ZERO);
        }
        return result;
    }

    /**
     * @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m).
     * It includes a success flag indicating if the operation succeeded. Operation will be marked as failed if trying
     * to operate modulo 0 or if the underlying precompile reverted.
     *
     * IMPORTANT: The result is only valid if the success flag is true. When using this function, make sure the chain
     * you're using it on supports the precompiled contract for modular exponentiation at address 0x05 as specified in
     * https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise, the underlying function will succeed given the lack
     * of a revert, but the result may be incorrectly interpreted as 0.
     */
    function tryModExp(uint256 b, uint256 e, uint256 m) internal view returns (bool success, uint256 result) {
        if (m == 0) return (false, 0);
        assembly ("memory-safe") {
            let ptr := mload(0x40)
            // | Offset    | Content    | Content (Hex)                                                      |
            // |-----------|------------|--------------------------------------------------------------------|
            // | 0x00:0x1f | size of b  | 0x0000000000000000000000000000000000000000000000000000000000000020 |
            // | 0x20:0x3f | size of e  | 0x0000000000000000000000000000000000000000000000000000000000000020 |
            // | 0x40:0x5f | size of m  | 0x0000000000000000000000000000000000000000000000000000000000000020 |
            // | 0x60:0x7f | value of b | 0x<.............................................................b> |
            // | 0x80:0x9f | value of e | 0x<.............................................................e> |
            // | 0xa0:0xbf | value of m | 0x<.............................................................m> |
            mstore(ptr, 0x20)
            mstore(add(ptr, 0x20), 0x20)
            mstore(add(ptr, 0x40), 0x20)
            mstore(add(ptr, 0x60), b)
            mstore(add(ptr, 0x80), e)
            mstore(add(ptr, 0xa0), m)

            // Given the result < m, it's guaranteed to fit in 32 bytes,
            // so we can use the memory scratch space located at offset 0.
            success := staticcall(gas(), 0x05, ptr, 0xc0, 0x00, 0x20)
            result := mload(0x00)
        }
    }

    /**
     * @dev Variant of {modExp} that supports inputs of arbitrary length.
     */
    function modExp(bytes memory b, bytes memory e, bytes memory m) internal view returns (bytes memory) {
        (bool success, bytes memory result) = tryModExp(b, e, m);
        if (!success) {
            Panic.panic(Panic.DIVISION_BY_ZERO);
        }
        return result;
    }

    /**
     * @dev Variant of {tryModExp} that supports inputs of arbitrary length.
     */
    function tryModExp(
        bytes memory b,
        bytes memory e,
        bytes memory m
    ) internal view returns (bool success, bytes memory result) {
        if (_zeroBytes(m)) return (false, new bytes(0));

        uint256 mLen = m.length;

        // Encode call args in result and move the free memory pointer
        result = abi.encodePacked(b.length, e.length, mLen, b, e, m);

        assembly ("memory-safe") {
            let dataPtr := add(result, 0x20)
            // Write result on top of args to avoid allocating extra memory.
            success := staticcall(gas(), 0x05, dataPtr, mload(result), dataPtr, mLen)
            // Overwrite the length.
            // result.length > returndatasize() is guaranteed because returndatasize() == m.length
            mstore(result, mLen)
            // Set the memory pointer after the returned data.
            mstore(0x40, add(dataPtr, mLen))
        }
    }

    /**
     * @dev Returns whether the provided byte array is zero.
     */
    function _zeroBytes(bytes memory byteArray) private pure returns (bool) {
        for (uint256 i = 0; i < byteArray.length; ++i) {
            if (byteArray[i] != 0) {
                return false;
            }
        }
        return true;
    }

    /**
     * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded
     * towards zero.
     *
     * This method is based on Newton's method for computing square roots; the algorithm is restricted to only
     * using integer operations.
     */
    function sqrt(uint256 a) internal pure returns (uint256) {
        unchecked {
            // Take care of easy edge cases when a == 0 or a == 1
            if (a <= 1) {
                return a;
            }

            // In this function, we use Newton's method to get a root of `f(x) := x² - a`. It involves building a
            // sequence x_n that converges toward sqrt(a). For each iteration x_n, we also define the error between
            // the current value as `ε_n = | x_n - sqrt(a) |`.
            //
            // For our first estimation, we consider `e` the smallest power of 2 which is bigger than the square root
            // of the target. (i.e. `2**(e-1) ≤ sqrt(a) < 2**e`). We know that `e ≤ 128` because `(2¹²⁸)² = 2²⁵⁶` is
            // bigger than any uint256.
            //
            // By noticing that
            // `2**(e-1) ≤ sqrt(a) < 2**e → (2**(e-1))² ≤ a < (2**e)² → 2**(2*e-2) ≤ a < 2**(2*e)`
            // we can deduce that `e - 1` is `log2(a) / 2`. We can thus compute `x_n = 2**(e-1)` using a method similar
            // to the msb function.
            uint256 aa = a;
            uint256 xn = 1;

            if (aa >= (1 << 128)) {
                aa >>= 128;
                xn <<= 64;
            }
            if (aa >= (1 << 64)) {
                aa >>= 64;
                xn <<= 32;
            }
            if (aa >= (1 << 32)) {
                aa >>= 32;
                xn <<= 16;
            }
            if (aa >= (1 << 16)) {
                aa >>= 16;
                xn <<= 8;
            }
            if (aa >= (1 << 8)) {
                aa >>= 8;
                xn <<= 4;
            }
            if (aa >= (1 << 4)) {
                aa >>= 4;
                xn <<= 2;
            }
            if (aa >= (1 << 2)) {
                xn <<= 1;
            }

            // We now have x_n such that `x_n = 2**(e-1) ≤ sqrt(a) < 2**e = 2 * x_n`. This implies ε_n ≤ 2**(e-1).
            //
            // We can refine our estimation by noticing that the middle of that interval minimizes the error.
            // If we move x_n to equal 2**(e-1) + 2**(e-2), then we reduce the error to ε_n ≤ 2**(e-2).
            // This is going to be our x_0 (and ε_0)
            xn = (3 * xn) >> 1; // ε_0 := | x_0 - sqrt(a) | ≤ 2**(e-2)

            // From here, Newton's method give us:
            // x_{n+1} = (x_n + a / x_n) / 2
            //
            // One should note that:
            // x_{n+1}² - a = ((x_n + a / x_n) / 2)² - a
            //              = ((x_n² + a) / (2 * x_n))² - a
            //              = (x_n⁴ + 2 * a * x_n² + a²) / (4 * x_n²) - a
            //              = (x_n⁴ + 2 * a * x_n² + a² - 4 * a * x_n²) / (4 * x_n²)
            //              = (x_n⁴ - 2 * a * x_n² + a²) / (4 * x_n²)
            //              = (x_n² - a)² / (2 * x_n)²
            //              = ((x_n² - a) / (2 * x_n))²
            //              ≥ 0
            // Which proves that for all n ≥ 1, sqrt(a) ≤ x_n
            //
            // This gives us the proof of quadratic convergence of the sequence:
            // ε_{n+1} = | x_{n+1} - sqrt(a) |
            //         = | (x_n + a / x_n) / 2 - sqrt(a) |
            //         = | (x_n² + a - 2*x_n*sqrt(a)) / (2 * x_n) |
            //         = | (x_n - sqrt(a))² / (2 * x_n) |
            //         = | ε_n² / (2 * x_n) |
            //         = ε_n² / | (2 * x_n) |
            //
            // For the first iteration, we have a special case where x_0 is known:
            // ε_1 = ε_0² / | (2 * x_0) |
            //     ≤ (2**(e-2))² / (2 * (2**(e-1) + 2**(e-2)))
            //     ≤ 2**(2*e-4) / (3 * 2**(e-1))
            //     ≤ 2**(e-3) / 3
            //     ≤ 2**(e-3-log2(3))
            //     ≤ 2**(e-4.5)
            //
            // For the following iterations, we use the fact that, 2**(e-1) ≤ sqrt(a) ≤ x_n:
            // ε_{n+1} = ε_n² / | (2 * x_n) |
            //         ≤ (2**(e-k))² / (2 * 2**(e-1))
            //         ≤ 2**(2*e-2*k) / 2**e
            //         ≤ 2**(e-2*k)
            xn = (xn + a / xn) >> 1; // ε_1 := | x_1 - sqrt(a) | ≤ 2**(e-4.5)  -- special case, see above
            xn = (xn + a / xn) >> 1; // ε_2 := | x_2 - sqrt(a) | ≤ 2**(e-9)    -- general case with k = 4.5
            xn = (xn + a / xn) >> 1; // ε_3 := | x_3 - sqrt(a) | ≤ 2**(e-18)   -- general case with k = 9
            xn = (xn + a / xn) >> 1; // ε_4 := | x_4 - sqrt(a) | ≤ 2**(e-36)   -- general case with k = 18
            xn = (xn + a / xn) >> 1; // ε_5 := | x_5 - sqrt(a) | ≤ 2**(e-72)   -- general case with k = 36
            xn = (xn + a / xn) >> 1; // ε_6 := | x_6 - sqrt(a) | ≤ 2**(e-144)  -- general case with k = 72

            // Because e ≤ 128 (as discussed during the first estimation phase), we know have reached a precision
            // ε_6 ≤ 2**(e-144) < 1. Given we're operating on integers, then we can ensure that xn is now either
            // sqrt(a) or sqrt(a) + 1.
            return xn - SafeCast.toUint(xn > a / xn);
        }
    }

    /**
     * @dev 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 + SafeCast.toUint(unsignedRoundsUp(rounding) && result * result < a);
        }
    }

    /**
     * @dev Return the log in base 2 of a positive value rounded towards zero.
     * Returns 0 if given 0.
     */
    function log2(uint256 x) internal pure returns (uint256 r) {
        // If value has upper 128 bits set, log2 result is at least 128
        r = SafeCast.toUint(x > 0xffffffffffffffffffffffffffffffff) << 7;
        // If upper 64 bits of 128-bit half set, add 64 to result
        r |= SafeCast.toUint((x >> r) > 0xffffffffffffffff) << 6;
        // If upper 32 bits of 64-bit half set, add 32 to result
        r |= SafeCast.toUint((x >> r) > 0xffffffff) << 5;
        // If upper 16 bits of 32-bit half set, add 16 to result
        r |= SafeCast.toUint((x >> r) > 0xffff) << 4;
        // If upper 8 bits of 16-bit half set, add 8 to result
        r |= SafeCast.toUint((x >> r) > 0xff) << 3;
        // If upper 4 bits of 8-bit half set, add 4 to result
        r |= SafeCast.toUint((x >> r) > 0xf) << 2;

        // Shifts value right by the current result and use it as an index into this lookup table:
        //
        // | x (4 bits) |  index  | table[index] = MSB position |
        // |------------|---------|-----------------------------|
        // |    0000    |    0    |        table[0] = 0         |
        // |    0001    |    1    |        table[1] = 0         |
        // |    0010    |    2    |        table[2] = 1         |
        // |    0011    |    3    |        table[3] = 1         |
        // |    0100    |    4    |        table[4] = 2         |
        // |    0101    |    5    |        table[5] = 2         |
        // |    0110    |    6    |        table[6] = 2         |
        // |    0111    |    7    |        table[7] = 2         |
        // |    1000    |    8    |        table[8] = 3         |
        // |    1001    |    9    |        table[9] = 3         |
        // |    1010    |   10    |        table[10] = 3        |
        // |    1011    |   11    |        table[11] = 3        |
        // |    1100    |   12    |        table[12] = 3        |
        // |    1101    |   13    |        table[13] = 3        |
        // |    1110    |   14    |        table[14] = 3        |
        // |    1111    |   15    |        table[15] = 3        |
        //
        // The lookup table is represented as a 32-byte value with the MSB positions for 0-15 in the last 16 bytes.
        assembly ("memory-safe") {
            r := or(r, byte(shr(r, x), 0x0000010102020202030303030303030300000000000000000000000000000000))
        }
    }

    /**
     * @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 + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << result < value);
        }
    }

    /**
     * @dev Return the log in base 10 of a positive value rounded towards zero.
     * 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 + SafeCast.toUint(unsignedRoundsUp(rounding) && 10 ** result < value);
        }
    }

    /**
     * @dev Return the log in base 256 of a positive value rounded towards zero.
     * 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 x) internal pure returns (uint256 r) {
        // If value has upper 128 bits set, log2 result is at least 128
        r = SafeCast.toUint(x > 0xffffffffffffffffffffffffffffffff) << 7;
        // If upper 64 bits of 128-bit half set, add 64 to result
        r |= SafeCast.toUint((x >> r) > 0xffffffffffffffff) << 6;
        // If upper 32 bits of 64-bit half set, add 32 to result
        r |= SafeCast.toUint((x >> r) > 0xffffffff) << 5;
        // If upper 16 bits of 32-bit half set, add 16 to result
        r |= SafeCast.toUint((x >> r) > 0xffff) << 4;
        // Add 1 if upper 8 bits of 16-bit half set, and divide accumulated result by 8
        return (r >> 3) | SafeCast.toUint((x >> r) > 0xff);
    }

    /**
     * @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 + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << (result << 3) < value);
        }
    }

    /**
     * @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
     */
    function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
        return uint8(rounding) % 2 == 1;
    }
}

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

pragma solidity ^0.8.20;

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

/**
 * @dev Implementation of the {IERC165} interface.
 *
 * Contracts that want to implement ERC-165 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);
 * }
 * ```
 */
abstract contract ERC165 is IERC165 {
    /// @inheritdoc IERC165
    function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
        return interfaceId == type(IERC165).interfaceId;
    }
}

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

pragma solidity >=0.4.16;

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

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

/// @title Minimal library for setting / getting slot variables (used in upgradable proxy contracts)
library SlotsLib {
    /// @dev Gets a slot as an address
    function getAddress(bytes32 slot) internal view returns (address result) {
        assembly {
            result := sload(slot)
        }
    }

    /// @dev Gets a slot as uint256
    function getUint(bytes32 slot) internal view returns (uint result) {
        assembly {
            result := sload(slot)
        }
    }

    /// @dev Sets a slot with address
    /// @notice Check address for 0 at the setter
    function set(bytes32 slot, address value) internal {
        assembly {
            sstore(slot, value)
        }
    }

    /// @dev Sets a slot with uint
    function set(bytes32 slot, uint value) internal {
        assembly {
            sstore(slot, value)
        }
    }
}

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

pragma solidity >=0.6.2;

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

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

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

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

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

pragma solidity ^0.8.20;

import {Math} from "./math/Math.sol";
import {SafeCast} from "./math/SafeCast.sol";
import {SignedMath} from "./math/SignedMath.sol";

/**
 * @dev String operations.
 */
library Strings {
    using SafeCast for *;

    bytes16 private constant HEX_DIGITS = "0123456789abcdef";
    uint8 private constant ADDRESS_LENGTH = 20;
    uint256 private constant SPECIAL_CHARS_LOOKUP =
        (1 << 0x08) | // backspace
            (1 << 0x09) | // tab
            (1 << 0x0a) | // newline
            (1 << 0x0c) | // form feed
            (1 << 0x0d) | // carriage return
            (1 << 0x22) | // double quote
            (1 << 0x5c); // backslash

    /**
     * @dev The `value` string doesn't fit in the specified `length`.
     */
    error StringsInsufficientHexLength(uint256 value, uint256 length);

    /**
     * @dev The string being parsed contains characters that are not in scope of the given base.
     */
    error StringsInvalidChar();

    /**
     * @dev The string being parsed is not a properly formatted address.
     */
    error StringsInvalidAddressFormat();

    /**
     * @dev Converts a `uint256` to its ASCII `string` decimal representation.
     */
    function toString(uint256 value) internal pure returns (string memory) {
        unchecked {
            uint256 length = Math.log10(value) + 1;
            string memory buffer = new string(length);
            uint256 ptr;
            assembly ("memory-safe") {
                ptr := add(add(buffer, 0x20), length)
            }
            while (true) {
                ptr--;
                assembly ("memory-safe") {
                    mstore8(ptr, byte(mod(value, 10), HEX_DIGITS))
                }
                value /= 10;
                if (value == 0) break;
            }
            return buffer;
        }
    }

    /**
     * @dev Converts a `int256` to its ASCII `string` decimal representation.
     */
    function toStringSigned(int256 value) internal pure returns (string memory) {
        return string.concat(value < 0 ? "-" : "", toString(SignedMath.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, Math.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) {
        uint256 localValue = value;
        bytes memory buffer = new bytes(2 * length + 2);
        buffer[0] = "0";
        buffer[1] = "x";
        for (uint256 i = 2 * length + 1; i > 1; --i) {
            buffer[i] = HEX_DIGITS[localValue & 0xf];
            localValue >>= 4;
        }
        if (localValue != 0) {
            revert StringsInsufficientHexLength(value, length);
        }
        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 Converts an `address` with fixed length of 20 bytes to its checksummed ASCII `string` hexadecimal
     * representation, according to EIP-55.
     */
    function toChecksumHexString(address addr) internal pure returns (string memory) {
        bytes memory buffer = bytes(toHexString(addr));

        // hash the hex part of buffer (skip length + 2 bytes, length 40)
        uint256 hashValue;
        assembly ("memory-safe") {
            hashValue := shr(96, keccak256(add(buffer, 0x22), 40))
        }

        for (uint256 i = 41; i > 1; --i) {
            // possible values for buffer[i] are 48 (0) to 57 (9) and 97 (a) to 102 (f)
            if (hashValue & 0xf > 7 && uint8(buffer[i]) > 96) {
                // case shift by xoring with 0x20
                buffer[i] ^= 0x20;
            }
            hashValue >>= 4;
        }
        return string(buffer);
    }

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

    /**
     * @dev Parse a decimal string and returns the value as a `uint256`.
     *
     * Requirements:
     * - The string must be formatted as `[0-9]*`
     * - The result must fit into an `uint256` type
     */
    function parseUint(string memory input) internal pure returns (uint256) {
        return parseUint(input, 0, bytes(input).length);
    }

    /**
     * @dev Variant of {parseUint-string} that parses a substring of `input` located between position `begin` (included) and
     * `end` (excluded).
     *
     * Requirements:
     * - The substring must be formatted as `[0-9]*`
     * - The result must fit into an `uint256` type
     */
    function parseUint(string memory input, uint256 begin, uint256 end) internal pure returns (uint256) {
        (bool success, uint256 value) = tryParseUint(input, begin, end);
        if (!success) revert StringsInvalidChar();
        return value;
    }

    /**
     * @dev Variant of {parseUint-string} that returns false if the parsing fails because of an invalid character.
     *
     * NOTE: This function will revert if the result does not fit in a `uint256`.
     */
    function tryParseUint(string memory input) internal pure returns (bool success, uint256 value) {
        return _tryParseUintUncheckedBounds(input, 0, bytes(input).length);
    }

    /**
     * @dev Variant of {parseUint-string-uint256-uint256} that returns false if the parsing fails because of an invalid
     * character.
     *
     * NOTE: This function will revert if the result does not fit in a `uint256`.
     */
    function tryParseUint(
        string memory input,
        uint256 begin,
        uint256 end
    ) internal pure returns (bool success, uint256 value) {
        if (end > bytes(input).length || begin > end) return (false, 0);
        return _tryParseUintUncheckedBounds(input, begin, end);
    }

    /**
     * @dev Implementation of {tryParseUint-string-uint256-uint256} that does not check bounds. Caller should make sure that
     * `begin <= end <= input.length`. Other inputs would result in undefined behavior.
     */
    function _tryParseUintUncheckedBounds(
        string memory input,
        uint256 begin,
        uint256 end
    ) private pure returns (bool success, uint256 value) {
        bytes memory buffer = bytes(input);

        uint256 result = 0;
        for (uint256 i = begin; i < end; ++i) {
            uint8 chr = _tryParseChr(bytes1(_unsafeReadBytesOffset(buffer, i)));
            if (chr > 9) return (false, 0);
            result *= 10;
            result += chr;
        }
        return (true, result);
    }

    /**
     * @dev Parse a decimal string and returns the value as a `int256`.
     *
     * Requirements:
     * - The string must be formatted as `[-+]?[0-9]*`
     * - The result must fit in an `int256` type.
     */
    function parseInt(string memory input) internal pure returns (int256) {
        return parseInt(input, 0, bytes(input).length);
    }

    /**
     * @dev Variant of {parseInt-string} that parses a substring of `input` located between position `begin` (included) and
     * `end` (excluded).
     *
     * Requirements:
     * - The substring must be formatted as `[-+]?[0-9]*`
     * - The result must fit in an `int256` type.
     */
    function parseInt(string memory input, uint256 begin, uint256 end) internal pure returns (int256) {
        (bool success, int256 value) = tryParseInt(input, begin, end);
        if (!success) revert StringsInvalidChar();
        return value;
    }

    /**
     * @dev Variant of {parseInt-string} that returns false if the parsing fails because of an invalid character or if
     * the result does not fit in a `int256`.
     *
     * NOTE: This function will revert if the absolute value of the result does not fit in a `uint256`.
     */
    function tryParseInt(string memory input) internal pure returns (bool success, int256 value) {
        return _tryParseIntUncheckedBounds(input, 0, bytes(input).length);
    }

    uint256 private constant ABS_MIN_INT256 = 2 ** 255;

    /**
     * @dev Variant of {parseInt-string-uint256-uint256} that returns false if the parsing fails because of an invalid
     * character or if the result does not fit in a `int256`.
     *
     * NOTE: This function will revert if the absolute value of the result does not fit in a `uint256`.
     */
    function tryParseInt(
        string memory input,
        uint256 begin,
        uint256 end
    ) internal pure returns (bool success, int256 value) {
        if (end > bytes(input).length || begin > end) return (false, 0);
        return _tryParseIntUncheckedBounds(input, begin, end);
    }

    /**
     * @dev Implementation of {tryParseInt-string-uint256-uint256} that does not check bounds. Caller should make sure that
     * `begin <= end <= input.length`. Other inputs would result in undefined behavior.
     */
    function _tryParseIntUncheckedBounds(
        string memory input,
        uint256 begin,
        uint256 end
    ) private pure returns (bool success, int256 value) {
        bytes memory buffer = bytes(input);

        // Check presence of a negative sign.
        bytes1 sign = begin == end ? bytes1(0) : bytes1(_unsafeReadBytesOffset(buffer, begin)); // don't do out-of-bound (possibly unsafe) read if sub-string is empty
        bool positiveSign = sign == bytes1("+");
        bool negativeSign = sign == bytes1("-");
        uint256 offset = (positiveSign || negativeSign).toUint();

        (bool absSuccess, uint256 absValue) = tryParseUint(input, begin + offset, end);

        if (absSuccess && absValue < ABS_MIN_INT256) {
            return (true, negativeSign ? -int256(absValue) : int256(absValue));
        } else if (absSuccess && negativeSign && absValue == ABS_MIN_INT256) {
            return (true, type(int256).min);
        } else return (false, 0);
    }

    /**
     * @dev Parse a hexadecimal string (with or without "0x" prefix), and returns the value as a `uint256`.
     *
     * Requirements:
     * - The string must be formatted as `(0x)?[0-9a-fA-F]*`
     * - The result must fit in an `uint256` type.
     */
    function parseHexUint(string memory input) internal pure returns (uint256) {
        return parseHexUint(input, 0, bytes(input).length);
    }

    /**
     * @dev Variant of {parseHexUint-string} that parses a substring of `input` located between position `begin` (included) and
     * `end` (excluded).
     *
     * Requirements:
     * - The substring must be formatted as `(0x)?[0-9a-fA-F]*`
     * - The result must fit in an `uint256` type.
     */
    function parseHexUint(string memory input, uint256 begin, uint256 end) internal pure returns (uint256) {
        (bool success, uint256 value) = tryParseHexUint(input, begin, end);
        if (!success) revert StringsInvalidChar();
        return value;
    }

    /**
     * @dev Variant of {parseHexUint-string} that returns false if the parsing fails because of an invalid character.
     *
     * NOTE: This function will revert if the result does not fit in a `uint256`.
     */
    function tryParseHexUint(string memory input) internal pure returns (bool success, uint256 value) {
        return _tryParseHexUintUncheckedBounds(input, 0, bytes(input).length);
    }

    /**
     * @dev Variant of {parseHexUint-string-uint256-uint256} that returns false if the parsing fails because of an
     * invalid character.
     *
     * NOTE: This function will revert if the result does not fit in a `uint256`.
     */
    function tryParseHexUint(
        string memory input,
        uint256 begin,
        uint256 end
    ) internal pure returns (bool success, uint256 value) {
        if (end > bytes(input).length || begin > end) return (false, 0);
        return _tryParseHexUintUncheckedBounds(input, begin, end);
    }

    /**
     * @dev Implementation of {tryParseHexUint-string-uint256-uint256} that does not check bounds. Caller should make sure that
     * `begin <= end <= input.length`. Other inputs would result in undefined behavior.
     */
    function _tryParseHexUintUncheckedBounds(
        string memory input,
        uint256 begin,
        uint256 end
    ) private pure returns (bool success, uint256 value) {
        bytes memory buffer = bytes(input);

        // skip 0x prefix if present
        bool hasPrefix = (end > begin + 1) && bytes2(_unsafeReadBytesOffset(buffer, begin)) == bytes2("0x"); // don't do out-of-bound (possibly unsafe) read if sub-string is empty
        uint256 offset = hasPrefix.toUint() * 2;

        uint256 result = 0;
        for (uint256 i = begin + offset; i < end; ++i) {
            uint8 chr = _tryParseChr(bytes1(_unsafeReadBytesOffset(buffer, i)));
            if (chr > 15) return (false, 0);
            result *= 16;
            unchecked {
                // Multiplying by 16 is equivalent to a shift of 4 bits (with additional overflow check).
                // This guarantees that adding a value < 16 will not cause an overflow, hence the unchecked.
                result += chr;
            }
        }
        return (true, result);
    }

    /**
     * @dev Parse a hexadecimal string (with or without "0x" prefix), and returns the value as an `address`.
     *
     * Requirements:
     * - The string must be formatted as `(0x)?[0-9a-fA-F]{40}`
     */
    function parseAddress(string memory input) internal pure returns (address) {
        return parseAddress(input, 0, bytes(input).length);
    }

    /**
     * @dev Variant of {parseAddress-string} that parses a substring of `input` located between position `begin` (included) and
     * `end` (excluded).
     *
     * Requirements:
     * - The substring must be formatted as `(0x)?[0-9a-fA-F]{40}`
     */
    function parseAddress(string memory input, uint256 begin, uint256 end) internal pure returns (address) {
        (bool success, address value) = tryParseAddress(input, begin, end);
        if (!success) revert StringsInvalidAddressFormat();
        return value;
    }

    /**
     * @dev Variant of {parseAddress-string} that returns false if the parsing fails because the input is not a properly
     * formatted address. See {parseAddress-string} requirements.
     */
    function tryParseAddress(string memory input) internal pure returns (bool success, address value) {
        return tryParseAddress(input, 0, bytes(input).length);
    }

    /**
     * @dev Variant of {parseAddress-string-uint256-uint256} that returns false if the parsing fails because input is not a properly
     * formatted address. See {parseAddress-string-uint256-uint256} requirements.
     */
    function tryParseAddress(
        string memory input,
        uint256 begin,
        uint256 end
    ) internal pure returns (bool success, address value) {
        if (end > bytes(input).length || begin > end) return (false, address(0));

        bool hasPrefix = (end > begin + 1) && bytes2(_unsafeReadBytesOffset(bytes(input), begin)) == bytes2("0x"); // don't do out-of-bound (possibly unsafe) read if sub-string is empty
        uint256 expectedLength = 40 + hasPrefix.toUint() * 2;

        // check that input is the correct length
        if (end - begin == expectedLength) {
            // length guarantees that this does not overflow, and value is at most type(uint160).max
            (bool s, uint256 v) = _tryParseHexUintUncheckedBounds(input, begin, end);
            return (s, address(uint160(v)));
        } else {
            return (false, address(0));
        }
    }

    function _tryParseChr(bytes1 chr) private pure returns (uint8) {
        uint8 value = uint8(chr);

        // Try to parse `chr`:
        // - Case 1: [0-9]
        // - Case 2: [a-f]
        // - Case 3: [A-F]
        // - otherwise not supported
        unchecked {
            if (value > 47 && value < 58) value -= 48;
            else if (value > 96 && value < 103) value -= 87;
            else if (value > 64 && value < 71) value -= 55;
            else return type(uint8).max;
        }

        return value;
    }

    /**
     * @dev Escape special characters in JSON strings. This can be useful to prevent JSON injection in NFT metadata.
     *
     * WARNING: This function should only be used in double quoted JSON strings. Single quotes are not escaped.
     *
     * NOTE: This function escapes all unicode characters, and not just the ones in ranges defined in section 2.5 of
     * RFC-4627 (U+0000 to U+001F, U+0022 and U+005C). ECMAScript's `JSON.parse` does recover escaped unicode
     * characters that are not in this range, but other tooling may provide different results.
     */
    function escapeJSON(string memory input) internal pure returns (string memory) {
        bytes memory buffer = bytes(input);
        bytes memory output = new bytes(2 * buffer.length); // worst case scenario
        uint256 outputLength = 0;

        for (uint256 i; i < buffer.length; ++i) {
            bytes1 char = bytes1(_unsafeReadBytesOffset(buffer, i));
            if (((SPECIAL_CHARS_LOOKUP & (1 << uint8(char))) != 0)) {
                output[outputLength++] = "\\";
                if (char == 0x08) output[outputLength++] = "b";
                else if (char == 0x09) output[outputLength++] = "t";
                else if (char == 0x0a) output[outputLength++] = "n";
                else if (char == 0x0c) output[outputLength++] = "f";
                else if (char == 0x0d) output[outputLength++] = "r";
                else if (char == 0x5c) output[outputLength++] = "\\";
                else if (char == 0x22) {
                    // solhint-disable-next-line quotes
                    output[outputLength++] = '"';
                }
            } else {
                output[outputLength++] = char;
            }
        }
        // write the actual length and deallocate unused memory
        assembly ("memory-safe") {
            mstore(output, outputLength)
            mstore(0x40, add(output, shl(5, shr(5, add(outputLength, 63)))))
        }

        return string(output);
    }

    /**
     * @dev Reads a bytes32 from a bytes array without bounds checking.
     *
     * NOTE: making this function internal would mean it could be used with memory unsafe offset, and marking the
     * assembly block as such would prevent some optimizations.
     */
    function _unsafeReadBytesOffset(bytes memory buffer, uint256 offset) private pure returns (bytes32 value) {
        // This is not memory safe in the general case, but all calls to this private function are within bounds.
        assembly ("memory-safe") {
            value := mload(add(add(buffer, 0x20), offset))
        }
    }
}

File 30 of 48 : ConstantsLib.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

library ConstantsLib {
    uint internal constant DENOMINATOR = 100_000;
    address internal constant DEAD_ADDRESS = 0xdEad000000000000000000000000000000000000;
}

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

/// @notice On-chain price quoter and swapper by predefined routes
/// @author Alien Deployer (https://github.com/a17)
/// @author Jude (https://github.com/iammrjude)
/// @author JodsMigel (https://github.com/JodsMigel)
/// @author 0xhokugava (https://github.com/0xhokugava)
interface ISwapper {
    event Swap(address indexed tokenIn, address indexed tokenOut, uint amount);
    event PoolAdded(PoolData poolData, bool assetAdded);
    event PoolRemoved(address token);
    event BlueChipAdded(PoolData poolData);
    event ThresholdChanged(address[] tokenIn, uint[] thresholdAmount);
    event BlueChipPoolRemoved(address tokenIn, address tokenOut);

    //region ----- Custom Errors -----
    error UnknownAMMAdapter();
    error LessThenThreshold(uint minimumAmount);
    error NoRouteFound();
    error NoRoutesForAssets();
    //endregion -- Custom Errors -----

    struct PoolData {
        address pool;
        address ammAdapter;
        address tokenIn;
        address tokenOut;
    }

    struct AddPoolData {
        address pool;
        string ammAdapterId;
        address tokenIn;
        address tokenOut;
    }

    /// @notice All assets in pools added to Swapper
    /// @return Addresses of assets
    function assets() external view returns (address[] memory);

    /// @notice All blue chip assets in blue chip pools added to Swapper
    /// @return Addresses of blue chip assets
    function bcAssets() external view returns (address[] memory);

    /// @notice All assets in Swapper
    /// @return Addresses of assets and blue chip assets
    function allAssets() external view returns (address[] memory);

    /// @notice Add pools with largest TVL
    /// @param pools Largest pools with AMM adapter addresses
    /// @param rewrite Rewrite pool for tokenIn
    function addPools(PoolData[] memory pools, bool rewrite) external;

    /// @notice Add pools with largest TVL
    /// @param pools Largest pools with AMM adapter ID string
    /// @param rewrite Rewrite pool for tokenIn
    function addPools(AddPoolData[] memory pools, bool rewrite) external;

    /// @notice Add largest pools with the most popular tokens on the current network
    /// @param pools_ PoolData array with pool, tokens and AMM adapter address
    /// @param rewrite Change exist pool records
    function addBlueChipsPools(PoolData[] memory pools_, bool rewrite) external;

    /// @notice Add largest pools with the most popular tokens on the current network
    /// @param pools_ AddPoolData array with pool, tokens and AMM adapter string ID
    /// @param rewrite Change exist pool records
    function addBlueChipsPools(AddPoolData[] memory pools_, bool rewrite) external;

    /// @notice Retrieves pool data for a specified token swap in Blue Chip Pools.
    /// @dev This function provides information about the pool associated with the specified input and output tokens.
    /// @param tokenIn The input token address.
    /// @param tokenOut The output token address.
    /// @return poolData The data structure containing information about the Blue Chip Pool.
    /// @custom:opcodes view
    function blueChipsPools(address tokenIn, address tokenOut) external view returns (PoolData memory poolData);

    /// @notice Set swap threshold for token
    /// @dev Prevents dust swap.
    /// @param tokenIn Swap input token
    /// @param thresholdAmount Minimum amount of token for executing swap
    function setThresholds(address[] memory tokenIn, uint[] memory thresholdAmount) external;

    /// @notice Swap threshold for token
    /// @param token Swap input token
    /// @return threshold_ Minimum amount of token for executing swap
    function threshold(address token) external view returns (uint threshold_);

    /// @notice Price of given tokenIn against tokenOut
    /// @param tokenIn Swap input token
    /// @param tokenOut Swap output token
    /// @param amount Amount of tokenIn. If provide zero then amount is 1.0.
    /// @return Amount of tokenOut with decimals of tokenOut
    function getPrice(address tokenIn, address tokenOut, uint amount) external view returns (uint);

    /// @notice Return price the first poolData.tokenIn against the last poolData.tokenOut in decimals of tokenOut.
    /// @param route Array of pool address, swapper address tokenIn, tokenOut
    /// @param amount Amount of tokenIn. If provide zero then amount is 1.0.
    function getPriceForRoute(PoolData[] memory route, uint amount) external view returns (uint);

    /// @notice Check possibility of swap tokenIn for tokenOut
    /// @param tokenIn Swap input token
    /// @param tokenOut Swap output token
    /// @return Swap route exists
    function isRouteExist(address tokenIn, address tokenOut) external view returns (bool);

    /// @notice Build route for swap. No reverts inside.
    /// @param tokenIn Swap input token
    /// @param tokenOut Swap output token
    /// @return route Array of pools for swap tokenIn to tokenOut. Zero length indicate an error.
    /// @return errorMessage Possible reason why the route was not found. Empty for success routes.
    function buildRoute(
        address tokenIn,
        address tokenOut
    ) external view returns (PoolData[] memory route, string memory errorMessage);

    /// @notice Sell tokenIn for tokenOut
    /// @dev Assume approve on this contract exist
    /// @param tokenIn Swap input token
    /// @param tokenOut Swap output token
    /// @param amount Amount of tokenIn for swap.
    /// @param priceImpactTolerance Price impact tolerance. Must include fees at least. Denominator is 100_000.
    function swap(address tokenIn, address tokenOut, uint amount, uint priceImpactTolerance) external;

    /// @notice Swap by predefined route
    /// @param route Array of pool address, swapper address tokenIn, tokenOut.
    /// TokenIn from first item will be swaped to tokenOut of last .
    /// @param amount Amount of first item tokenIn.
    /// @param priceImpactTolerance Price impact tolerance. Must include fees at least. Denominator is 100_000.
    function swapWithRoute(PoolData[] memory route, uint amount, uint priceImpactTolerance) external;
}

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

import {StrategyIdLib} from "./StrategyIdLib.sol";
import {CommonLib} from "../../core/libs/CommonLib.sol";

/// @dev Strategy developer addresses used when strategy implementation was deployed at a network.
///      StrategyLogic NFT is minted to the address of a strategy developer.
library StrategyDeveloperLib {
    function getDeveloper(string memory strategyId) internal pure returns (address) {
        if (CommonLib.eq(strategyId, StrategyIdLib.GAMMA_QUICKSWAP_MERKL_FARM)) {
            return 0x88888887C3ebD4a33E34a15Db4254C74C75E5D4A;
        }
        if (CommonLib.eq(strategyId, StrategyIdLib.QUICKSWAP_STATIC_MERKL_FARM)) {
            return 0x88888887C3ebD4a33E34a15Db4254C74C75E5D4A;
        }
        if (CommonLib.eq(strategyId, StrategyIdLib.COMPOUND_FARM)) {
            return 0x88888887C3ebD4a33E34a15Db4254C74C75E5D4A;
        }
        if (CommonLib.eq(strategyId, StrategyIdLib.DEFIEDGE_QUICKSWAP_MERKL_FARM)) {
            return 0x88888887C3ebD4a33E34a15Db4254C74C75E5D4A;
        }
        if (CommonLib.eq(strategyId, StrategyIdLib.ICHI_QUICKSWAP_MERKL_FARM)) {
            return 0x4f86e6d7FE4D7cd2C1E08f4108C8E5f0Ca2553a3;
        }
        if (CommonLib.eq(strategyId, StrategyIdLib.ICHI_RETRO_MERKL_FARM)) {
            return 0x88888887C3ebD4a33E34a15Db4254C74C75E5D4A;
        }
        if (CommonLib.eq(strategyId, StrategyIdLib.GAMMA_RETRO_MERKL_FARM)) {
            return 0x88888887C3ebD4a33E34a15Db4254C74C75E5D4A;
        }
        if (CommonLib.eq(strategyId, StrategyIdLib.GAMMA_UNISWAPV3_MERKL_FARM)) {
            return 0x88888887C3ebD4a33E34a15Db4254C74C75E5D4A;
        }
        if (CommonLib.eq(strategyId, StrategyIdLib.CURVE_CONVEX_FARM)) {
            return 0x88888887C3ebD4a33E34a15Db4254C74C75E5D4A;
        }
        if (CommonLib.eq(strategyId, StrategyIdLib.YEARN)) {
            return 0x88888887C3ebD4a33E34a15Db4254C74C75E5D4A;
        }
        if (CommonLib.eq(strategyId, StrategyIdLib.STEER_QUICKSWAP_MERKL_FARM)) {
            return 0xDa1A2a4A3fE9702b4FB0ddA13F702fc2395E2534;
        }
        if (CommonLib.eq(strategyId, StrategyIdLib.TRIDENT_PEARL_FARM)) {
            return 0x88888887C3ebD4a33E34a15Db4254C74C75E5D4A;
        }
        if (CommonLib.eq(strategyId, StrategyIdLib.BEETS_STABLE_FARM)) {
            return 0x88888887C3ebD4a33E34a15Db4254C74C75E5D4A;
        }
        if (CommonLib.eq(strategyId, StrategyIdLib.BEETS_WEIGHTED_FARM)) {
            return 0x88888887C3ebD4a33E34a15Db4254C74C75E5D4A;
        }
        if (CommonLib.eq(strategyId, StrategyIdLib.EQUALIZER_FARM)) {
            return 0x88888887C3ebD4a33E34a15Db4254C74C75E5D4A;
        }
        if (CommonLib.eq(strategyId, StrategyIdLib.ICHI_SWAPX_FARM)) {
            return 0x88888887C3ebD4a33E34a15Db4254C74C75E5D4A;
        }
        if (CommonLib.eq(strategyId, StrategyIdLib.SWAPX_FARM)) {
            return 0x88888887C3ebD4a33E34a15Db4254C74C75E5D4A;
        }
        if (CommonLib.eq(strategyId, StrategyIdLib.SILO_FARM)) {
            return 0xa12C4Bbe4D6eD65285f05328Bca4462Bf4808E53;
        }
        if (CommonLib.eq(strategyId, StrategyIdLib.ALM_SHADOW_FARM)) {
            return 0x88888887C3ebD4a33E34a15Db4254C74C75E5D4A;
        }
        if (CommonLib.eq(strategyId, StrategyIdLib.SILO_LEVERAGE)) {
            return 0x88888887C3ebD4a33E34a15Db4254C74C75E5D4A;
        }
        if (CommonLib.eq(strategyId, StrategyIdLib.SILO_ADVANCED_LEVERAGE)) {
            return 0x88888887C3ebD4a33E34a15Db4254C74C75E5D4A;
        }
        if (CommonLib.eq(strategyId, StrategyIdLib.GAMMA_EQUALIZER_FARM)) {
            return 0x9485879Ea033f6b2Cc1A5Cfd1C2c2bB2e7303C68;
        }
        if (CommonLib.eq(strategyId, StrategyIdLib.ICHI_EQUALIZER_FARM)) {
            return 0x9485879Ea033f6b2Cc1A5Cfd1C2c2bB2e7303C68;
        }
        if (CommonLib.eq(strategyId, StrategyIdLib.AAVE)) {
            return 0x9485879Ea033f6b2Cc1A5Cfd1C2c2bB2e7303C68;
        }
        if (CommonLib.eq(strategyId, StrategyIdLib.EULER_MERKL_FARM)) {
            return 0x9485879Ea033f6b2Cc1A5Cfd1C2c2bB2e7303C68;
        }
        if (CommonLib.eq(strategyId, StrategyIdLib.SILO)) {
            return 0xa12C4Bbe4D6eD65285f05328Bca4462Bf4808E53;
        }
        if (CommonLib.eq(strategyId, StrategyIdLib.EULER)) {
            return 0xcd18A818f2eC5C21EEF6771183eD5641B15da247;
        }
        if (CommonLib.eq(strategyId, StrategyIdLib.SILO_MANAGED_FARM)) {
            return 0xcd18A818f2eC5C21EEF6771183eD5641B15da247;
        }
        if (CommonLib.eq(strategyId, StrategyIdLib.SILO_ALMF_FARM)) {
            return 0xcd18A818f2eC5C21EEF6771183eD5641B15da247;
        }
        if (CommonLib.eq(strategyId, StrategyIdLib.AAVE_MERKL_FARM)) {
            return 0xcd18A818f2eC5C21EEF6771183eD5641B15da247;
        }
        if (CommonLib.eq(strategyId, StrategyIdLib.COMPOUND_V2)) {
            return 0xcd18A818f2eC5C21EEF6771183eD5641B15da247;
        }
        if (CommonLib.eq(strategyId, StrategyIdLib.SILO_MANAGED_MERKL_FARM)) {
            return 0xcd18A818f2eC5C21EEF6771183eD5641B15da247;
        }
        if (CommonLib.eq(strategyId, StrategyIdLib.SILO_MERKL_FARM)) {
            return 0xcd18A818f2eC5C21EEF6771183eD5641B15da247;
        }
        return address(0);
    }
}

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

/// @dev Mostly this interface need for front-end and tests for interacting with farming strategies
/// @author JodsMigel (https://github.com/JodsMigel)
interface IFarmingStrategy {
    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                           EVENTS                           */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    event RewardsClaimed(uint[] amounts);

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                           ERRORS                           */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    error BadFarm();
    error IncorrectStrategyId();

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                         DATA TYPES                         */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @custom:storage-location erc7201:stability.FarmingStrategyBase
    struct FarmingStrategyBaseStorage {
        /// @inheritdoc IFarmingStrategy
        uint farmId;
        address[] _rewardAssets;
        uint[] _rewardsOnBalance;
    }

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                       VIEW FUNCTIONS                       */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @notice Index of the farm used by initialized strategy
    function farmId() external view returns (uint);

    /// @notice Strategy can earn money on farm now
    /// Some strategies can continue work and earn pool fees after ending of farm rewards.
    function canFarm() external view returns (bool);

    /// @notice Mechanics of receiving farming rewards
    function farmMechanics() external view returns (string memory);

    /// @notice Farming reward assets for claim and liquidate
    /// @return Addresses of farm reward ERC20 tokens
    function farmingAssets() external view returns (address[] memory);

    /// @notice Address of pool for staking asset/underlying
    function stakingPool() external view returns (address);

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                      WRITE FUNCTIONS                       */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @notice Update strategy farming reward assets from Factory
    /// Only operator can call this
    function refreshFarmingAssets() external;
}

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

import {UpgradeableProxy} from "../../core/base/UpgradeableProxy.sol";
import {IControllable} from "../../interfaces/IControllable.sol";
import {IPlatform} from "../../interfaces/IPlatform.sol";
import {IFactory} from "../../interfaces/IFactory.sol";
import {IVaultProxy} from "../../interfaces/IVaultProxy.sol";

/// @title EIP1967 Upgradeable proxy implementation for built by factory vaults
/// @author Alien Deployer (https://github.com/a17)
contract VaultProxy is UpgradeableProxy, IVaultProxy {
    /// @dev Vault type ID
    bytes32 private constant _TYPE_SLOT = bytes32(uint(keccak256("eip1967.vaultProxy.type")) - 1);

    /// @inheritdoc IVaultProxy
    function initProxy(string memory type_) external {
        bytes32 typeHash = keccak256(abi.encodePacked(type_));
        //slither-disable-next-line unused-return
        (, address vaultImplementation,,,) = IFactory(msg.sender).vaultConfig(typeHash);
        _init(vaultImplementation);
        bytes32 slot = _TYPE_SLOT;
        //slither-disable-next-line assembly
        assembly {
            sstore(slot, typeHash)
        }
    }

    /// @inheritdoc IVaultProxy
    function upgrade() external {
        if (msg.sender != IPlatform(IControllable(address(this)).platform()).factory()) {
            revert ProxyForbidden();
        }
        bytes32 typeHash;
        bytes32 slot = _TYPE_SLOT;
        //slither-disable-next-line assembly
        assembly {
            typeHash := sload(slot)
        }
        //slither-disable-next-line unused-return
        (, address vaultImplementation,,,) = IFactory(msg.sender).vaultConfig(typeHash);
        _upgradeTo(vaultImplementation);
    }

    /// @inheritdoc IVaultProxy
    function implementation() external view returns (address) {
        return _implementation();
    }

    /// @inheritdoc IVaultProxy
    function vaultTypeHash() external view returns (bytes32) {
        bytes32 typeHash;
        bytes32 slot = _TYPE_SLOT;
        //slither-disable-next-line assembly
        assembly {
            typeHash := sload(slot)
        }
        return typeHash;
    }
}

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

import {UpgradeableProxy} from "../../core/base/UpgradeableProxy.sol";
import {IControllable} from "../../interfaces/IControllable.sol";
import {IPlatform} from "../../interfaces/IPlatform.sol";
import {IFactory} from "../../interfaces/IFactory.sol";
import {IStrategyProxy} from "../../interfaces/IStrategyProxy.sol";

/// @title EIP1967 Upgradeable proxy implementation for built by Factory strategies.
/// @author Alien Deployer (https://github.com/a17)
/// @author JodsMigel (https://github.com/JodsMigel)
/// @author Jude (https://github.com/iammrjude)
contract StrategyProxy is UpgradeableProxy, IStrategyProxy {
    /// @dev Strategy logic id
    bytes32 private constant _ID_SLOT = bytes32(uint(keccak256("eip1967.strategyProxy.id")) - 1);

    /// @inheritdoc IStrategyProxy
    function initStrategyProxy(string memory id) external {
        bytes32 strategyIdHash = keccak256(abi.encodePacked(id));
        //slither-disable-next-line unused-return
        IFactory.StrategyLogicConfig memory strategyConfig = IFactory(msg.sender).strategyLogicConfig(strategyIdHash);
        address strategyImplementation = strategyConfig.implementation;
        _init(strategyImplementation);
        bytes32 slot = _ID_SLOT;
        //slither-disable-next-line assembly
        assembly {
            sstore(slot, strategyIdHash)
        }
    }

    /// @inheritdoc IStrategyProxy
    function upgrade() external {
        if (IPlatform(IControllable(address(this)).platform()).factory() != msg.sender) {
            revert IControllable.NotFactory();
        }
        bytes32 strategyIdHash;
        bytes32 slot = _ID_SLOT;
        //slither-disable-next-line assembly
        assembly {
            strategyIdHash := sload(slot)
        }
        //slither-disable-next-line unused-return
        IFactory.StrategyLogicConfig memory strategyConfig = IFactory(msg.sender).strategyLogicConfig(strategyIdHash);
        address strategyImplementation = strategyConfig.implementation;
        _upgradeTo(strategyImplementation);
    }

    /// @inheritdoc IStrategyProxy
    function implementation() external view returns (address) {
        return _implementation();
    }

    /// @inheritdoc IStrategyProxy
    function strategyImplementationLogicIdHash() external view returns (bytes32) {
        bytes32 idHash;
        bytes32 slot = _ID_SLOT;
        //slither-disable-next-line assembly
        assembly {
            idHash := sload(slot)
        }
        return idHash;
    }
}

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

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

/// @notice Base interface of Stability Vault
interface IStabilityVault is IERC20, IERC20Metadata {
    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                       CUSTOM ERRORS                        */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    error WaitAFewBlocks();
    error ExceedSlippage(uint mintToUser, uint minToMint);
    error ExceedMaxSupply(uint maxSupply);
    error NotSupported();

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                           EVENTS                           */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    event DepositAssets(address indexed account, address[] assets, uint[] amounts, uint mintAmount);
    event WithdrawAssets(
        address indexed sender, address indexed owner, address[] assets, uint sharesAmount, uint[] amountsOut
    );
    event MaxSupply(uint maxShares);
    event VaultName(string newName);
    event VaultSymbol(string newSymbol);
    event LastBlockDefenseDisabled(bool isDisabled);

    //region --------------------------------------- View functions
    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                       VIEW FUNCTIONS                       */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @notice Underlying assets
    function assets() external view returns (address[] memory);

    /// @notice Immutable vault type ID
    function vaultType() external view returns (string memory);

    /// @dev Calculation of consumed amounts, shares amount and liquidity/underlying value for provided available amounts of strategy assets
    /// @param assets_ Assets suitable for vault strategy. Can be strategy assets, underlying asset or specific set of assets depending on strategy logic.
    /// @param amountsMax Available amounts of assets_ that user wants to invest in vault
    /// @return amountsConsumed Amounts of strategy assets that can be deposited by providing amountsMax
    /// @return sharesOut Amount of vault shares that will be minted
    /// @return valueOut Liquidity value or underlying token amount that will be received by the strategy
    function previewDepositAssets(
        address[] memory assets_,
        uint[] memory amountsMax
    ) external view returns (uint[] memory amountsConsumed, uint sharesOut, uint valueOut);

    /// @dev USD price of share with 18 decimals.
    ///      Not trusted vault share price can be manipulated, used only OFF-CHAIN.
    /// @return price_ Price of 1e18 shares with 18 decimals precision
    /// @return trusted True means oracle price, false means AMM spot price
    function price() external view returns (uint price_, bool trusted);

    /// @dev USD price of assets managed by strategy with 18 decimals
    ///      Not trusted vault share price can be manipulated, used only OFF-CHAIN.
    /// @return tvl_ Total USD value of final assets in vault
    /// @return trusted True means TVL calculated based only on oracle prices, false means AMM spot price was used.
    function tvl() external view returns (uint tvl_, bool trusted);

    /// @dev Minimum 6 blocks between deposit and withdraw check disabled
    function lastBlockDefenseDisabled() external view returns (bool);

    /// @return amount Maximum amount that can be withdrawn from the vault for the given account.
    /// This is max amount that can be passed to `withdraw` function.
    /// The implementation should take into account IStrategy.maxWithdrawAssets
    /// @dev It's alias of IStabilityVault.maxWithdraw(account, 0) for backwords compatibility.
    function maxWithdraw(address account) external view returns (uint amount);

    /// @return amount Maximum amount that can be withdrawn from the vault for the given account.
    /// This is max amount that can be passed to `withdraw` function.
    /// The implementation should take into account IStrategy.maxWithdrawAssets
    /// @param mode 0 - Return amount that can be withdrawn in assets
    ///             1 - Return amount that can be withdrawn in underlying
    function maxWithdraw(address account, uint mode) external view returns (uint amount);

    /// @return maxAmounts Maximum amounts that can be deposited to the vault for the given account.
    /// This is max amounts of {assets} that can be passed to `depositAssets` function as {amountsMax}.
    /// The implementation should take into account IStrategy.maxDepositAssets
    /// Return type(uint).max if there is no limit for the asset.
    function maxDeposit(address account) external view returns (uint[] memory maxAmounts);
    //endregion --------------------------------------- View functions

    //region --------------------------------------- Write functions
    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                      WRITE FUNCTIONS                       */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Deposit final assets (pool assets) to the strategy and minting of vault shares.
    ///      If the strategy interacts with a pool or farms through an underlying token, then it will be minted.
    ///      Emits a {DepositAssets} event with consumed amounts.
    /// @param assets_ Assets suitable for the strategy. Can be strategy assets, underlying asset or specific set of assets depending on strategy logic.
    /// @param amountsMax Available amounts of assets_ that user wants to invest in vault
    /// @param minSharesOut Slippage tolerance. Minimal shares amount which must be received by user.
    /// @param receiver Receiver of deposit. If receiver is zero address, receiver is msg.sender.
    function depositAssets(
        address[] memory assets_,
        uint[] memory amountsMax,
        uint minSharesOut,
        address receiver
    ) external;

    /// @dev Burning shares of vault and obtaining strategy assets.
    /// @param assets_ Assets suitable for the strategy. Can be strategy assets, underlying asset or specific set of assets depending on strategy logic.
    /// @param amountShares Shares amount for burning
    /// @param minAssetAmountsOut Slippage tolerance. Minimal amounts of strategy assets that user must receive.
    /// @return Amount of assets for withdraw. It's related to assets_ one-by-one.
    function withdrawAssets(
        address[] memory assets_,
        uint amountShares,
        uint[] memory minAssetAmountsOut
    ) external returns (uint[] memory);

    /// @dev Burning shares of vault and obtaining strategy assets.
    /// @param assets_ Assets suitable for the strategy. Can be strategy assets, underlying asset or specific set of assets depending on strategy logic.
    /// @param amountShares Shares amount for burning
    /// @param minAssetAmountsOut Slippage tolerance. Minimal amounts of strategy assets that user must receive.
    /// @param receiver Receiver of assets
    /// @param owner Owner of vault shares
    /// @return Amount of assets for withdraw. It's related to assets_ one-by-one.
    function withdrawAssets(
        address[] memory assets_,
        uint amountShares,
        uint[] memory minAssetAmountsOut,
        address receiver,
        address owner
    ) external returns (uint[] memory);

    /// @dev Changing ERC20 name of vault
    function setName(string calldata newName) external;

    /// @dev Changing ERC20 symbol of vault
    function setSymbol(string calldata newSymbol) external;

    /// @dev Enable or disable last block check
    function setLastBlockDefenseDisabled(bool isDisabled) external;
    //endregion --------------------------------------- Write functions
}

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

pragma solidity >=0.6.2;

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

/**
 * @title ERC-721 Non-Fungible Token Standard, optional metadata extension
 * @dev See https://eips.ethereum.org/EIPS/eip-721
 */
interface IERC721Metadata is IERC721 {
    /**
     * @dev Returns the token collection name.
     */
    function name() external view returns (string memory);

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

    /**
     * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
     */
    function tokenURI(uint256 tokenId) external view returns (string memory);
}

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

pragma solidity >=0.4.16;

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

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

pragma solidity >=0.4.16;

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

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

pragma solidity ^0.8.20;

/**
 * @dev Provides a set of functions to compare values.
 *
 * _Available since v5.1._
 */
library Comparators {
    function lt(uint256 a, uint256 b) internal pure returns (bool) {
        return a < b;
    }

    function gt(uint256 a, uint256 b) internal pure returns (bool) {
        return a > b;
    }
}

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

pragma solidity ^0.8.20;

/**
 * @dev Library for computing storage (and transient storage) locations from namespaces and deriving slots
 * corresponding to standard patterns. The derivation method for array and mapping matches the storage layout used by
 * the solidity language / compiler.
 *
 * See https://docs.soliditylang.org/en/v0.8.20/internals/layout_in_storage.html#mappings-and-dynamic-arrays[Solidity docs for mappings and dynamic arrays.].
 *
 * Example usage:
 * ```solidity
 * contract Example {
 *     // Add the library methods
 *     using StorageSlot for bytes32;
 *     using SlotDerivation for bytes32;
 *
 *     // Declare a namespace
 *     string private constant _NAMESPACE = "<namespace>"; // eg. OpenZeppelin.Slot
 *
 *     function setValueInNamespace(uint256 key, address newValue) internal {
 *         _NAMESPACE.erc7201Slot().deriveMapping(key).getAddressSlot().value = newValue;
 *     }
 *
 *     function getValueInNamespace(uint256 key) internal view returns (address) {
 *         return _NAMESPACE.erc7201Slot().deriveMapping(key).getAddressSlot().value;
 *     }
 * }
 * ```
 *
 * TIP: Consider using this library along with {StorageSlot}.
 *
 * NOTE: This library provides a way to manipulate storage locations in a non-standard way. Tooling for checking
 * upgrade safety will ignore the slots accessed through this library.
 *
 * _Available since v5.1._
 */
library SlotDerivation {
    /**
     * @dev Derive an ERC-7201 slot from a string (namespace).
     */
    function erc7201Slot(string memory namespace) internal pure returns (bytes32 slot) {
        assembly ("memory-safe") {
            mstore(0x00, sub(keccak256(add(namespace, 0x20), mload(namespace)), 1))
            slot := and(keccak256(0x00, 0x20), not(0xff))
        }
    }

    /**
     * @dev Add an offset to a slot to get the n-th element of a structure or an array.
     */
    function offset(bytes32 slot, uint256 pos) internal pure returns (bytes32 result) {
        unchecked {
            return bytes32(uint256(slot) + pos);
        }
    }

    /**
     * @dev Derive the location of the first element in an array from the slot where the length is stored.
     */
    function deriveArray(bytes32 slot) internal pure returns (bytes32 result) {
        assembly ("memory-safe") {
            mstore(0x00, slot)
            result := keccak256(0x00, 0x20)
        }
    }

    /**
     * @dev Derive the location of a mapping element from the key.
     */
    function deriveMapping(bytes32 slot, address key) internal pure returns (bytes32 result) {
        assembly ("memory-safe") {
            mstore(0x00, and(key, shr(96, not(0))))
            mstore(0x20, slot)
            result := keccak256(0x00, 0x40)
        }
    }

    /**
     * @dev Derive the location of a mapping element from the key.
     */
    function deriveMapping(bytes32 slot, bool key) internal pure returns (bytes32 result) {
        assembly ("memory-safe") {
            mstore(0x00, iszero(iszero(key)))
            mstore(0x20, slot)
            result := keccak256(0x00, 0x40)
        }
    }

    /**
     * @dev Derive the location of a mapping element from the key.
     */
    function deriveMapping(bytes32 slot, bytes32 key) internal pure returns (bytes32 result) {
        assembly ("memory-safe") {
            mstore(0x00, key)
            mstore(0x20, slot)
            result := keccak256(0x00, 0x40)
        }
    }

    /**
     * @dev Derive the location of a mapping element from the key.
     */
    function deriveMapping(bytes32 slot, uint256 key) internal pure returns (bytes32 result) {
        assembly ("memory-safe") {
            mstore(0x00, key)
            mstore(0x20, slot)
            result := keccak256(0x00, 0x40)
        }
    }

    /**
     * @dev Derive the location of a mapping element from the key.
     */
    function deriveMapping(bytes32 slot, int256 key) internal pure returns (bytes32 result) {
        assembly ("memory-safe") {
            mstore(0x00, key)
            mstore(0x20, slot)
            result := keccak256(0x00, 0x40)
        }
    }

    /**
     * @dev Derive the location of a mapping element from the key.
     */
    function deriveMapping(bytes32 slot, string memory key) internal pure returns (bytes32 result) {
        assembly ("memory-safe") {
            let length := mload(key)
            let begin := add(key, 0x20)
            let end := add(begin, length)
            let cache := mload(end)
            mstore(end, slot)
            result := keccak256(begin, add(length, 0x20))
            mstore(end, cache)
        }
    }

    /**
     * @dev Derive the location of a mapping element from the key.
     */
    function deriveMapping(bytes32 slot, bytes memory key) internal pure returns (bytes32 result) {
        assembly ("memory-safe") {
            let length := mload(key)
            let begin := add(key, 0x20)
            let end := add(begin, length)
            let cache := mload(end)
            mstore(end, slot)
            result := keccak256(begin, add(length, 0x20))
            mstore(end, cache)
        }
    }
}

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

pragma solidity ^0.8.20;

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

    struct BooleanSlot {
        bool value;
    }

    struct Bytes32Slot {
        bytes32 value;
    }

    struct Uint256Slot {
        uint256 value;
    }

    struct Int256Slot {
        int256 value;
    }

    struct StringSlot {
        string value;
    }

    struct BytesSlot {
        bytes value;
    }

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

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

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

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

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

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

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

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

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

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

pragma solidity ^0.8.20;

/**
 * @dev Helper library for emitting standardized panic codes.
 *
 * ```solidity
 * contract Example {
 *      using Panic for uint256;
 *
 *      // Use any of the declared internal constants
 *      function foo() { Panic.GENERIC.panic(); }
 *
 *      // Alternatively
 *      function foo() { Panic.panic(Panic.GENERIC); }
 * }
 * ```
 *
 * Follows the list from https://github.com/ethereum/solidity/blob/v0.8.24/libsolutil/ErrorCodes.h[libsolutil].
 *
 * _Available since v5.1._
 */
// slither-disable-next-line unused-state
library Panic {
    /// @dev generic / unspecified error
    uint256 internal constant GENERIC = 0x00;
    /// @dev used by the assert() builtin
    uint256 internal constant ASSERT = 0x01;
    /// @dev arithmetic underflow or overflow
    uint256 internal constant UNDER_OVERFLOW = 0x11;
    /// @dev division or modulo by zero
    uint256 internal constant DIVISION_BY_ZERO = 0x12;
    /// @dev enum conversion error
    uint256 internal constant ENUM_CONVERSION_ERROR = 0x21;
    /// @dev invalid encoding in storage
    uint256 internal constant STORAGE_ENCODING_ERROR = 0x22;
    /// @dev empty array pop
    uint256 internal constant EMPTY_ARRAY_POP = 0x31;
    /// @dev array out of bounds access
    uint256 internal constant ARRAY_OUT_OF_BOUNDS = 0x32;
    /// @dev resource error (too large allocation or too large array)
    uint256 internal constant RESOURCE_ERROR = 0x41;
    /// @dev calling invalid internal function
    uint256 internal constant INVALID_INTERNAL_FUNCTION = 0x51;

    /// @dev Reverts with a panic code. Recommended to use with
    /// the internal constants with predefined codes.
    function panic(uint256 code) internal pure {
        assembly ("memory-safe") {
            mstore(0x00, 0x4e487b71)
            mstore(0x20, code)
            revert(0x1c, 0x24)
        }
    }
}

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

pragma solidity ^0.8.20;

/**
 * @dev Wrappers over Solidity's uintXX/intXX/bool 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.
 */
library SafeCast {
    /**
     * @dev Value doesn't fit in an uint of `bits` size.
     */
    error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);

    /**
     * @dev An int value doesn't fit in an uint of `bits` size.
     */
    error SafeCastOverflowedIntToUint(int256 value);

    /**
     * @dev Value doesn't fit in an int of `bits` size.
     */
    error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);

    /**
     * @dev An uint value doesn't fit in an int of `bits` size.
     */
    error SafeCastOverflowedUintToInt(uint256 value);

    /**
     * @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
     */
    function toUint248(uint256 value) internal pure returns (uint248) {
        if (value > type(uint248).max) {
            revert SafeCastOverflowedUintDowncast(248, value);
        }
        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
     */
    function toUint240(uint256 value) internal pure returns (uint240) {
        if (value > type(uint240).max) {
            revert SafeCastOverflowedUintDowncast(240, value);
        }
        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
     */
    function toUint232(uint256 value) internal pure returns (uint232) {
        if (value > type(uint232).max) {
            revert SafeCastOverflowedUintDowncast(232, value);
        }
        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
     */
    function toUint224(uint256 value) internal pure returns (uint224) {
        if (value > type(uint224).max) {
            revert SafeCastOverflowedUintDowncast(224, value);
        }
        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
     */
    function toUint216(uint256 value) internal pure returns (uint216) {
        if (value > type(uint216).max) {
            revert SafeCastOverflowedUintDowncast(216, value);
        }
        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
     */
    function toUint208(uint256 value) internal pure returns (uint208) {
        if (value > type(uint208).max) {
            revert SafeCastOverflowedUintDowncast(208, value);
        }
        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
     */
    function toUint200(uint256 value) internal pure returns (uint200) {
        if (value > type(uint200).max) {
            revert SafeCastOverflowedUintDowncast(200, value);
        }
        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
     */
    function toUint192(uint256 value) internal pure returns (uint192) {
        if (value > type(uint192).max) {
            revert SafeCastOverflowedUintDowncast(192, value);
        }
        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
     */
    function toUint184(uint256 value) internal pure returns (uint184) {
        if (value > type(uint184).max) {
            revert SafeCastOverflowedUintDowncast(184, value);
        }
        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
     */
    function toUint176(uint256 value) internal pure returns (uint176) {
        if (value > type(uint176).max) {
            revert SafeCastOverflowedUintDowncast(176, value);
        }
        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
     */
    function toUint168(uint256 value) internal pure returns (uint168) {
        if (value > type(uint168).max) {
            revert SafeCastOverflowedUintDowncast(168, value);
        }
        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
     */
    function toUint160(uint256 value) internal pure returns (uint160) {
        if (value > type(uint160).max) {
            revert SafeCastOverflowedUintDowncast(160, value);
        }
        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
     */
    function toUint152(uint256 value) internal pure returns (uint152) {
        if (value > type(uint152).max) {
            revert SafeCastOverflowedUintDowncast(152, value);
        }
        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
     */
    function toUint144(uint256 value) internal pure returns (uint144) {
        if (value > type(uint144).max) {
            revert SafeCastOverflowedUintDowncast(144, value);
        }
        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
     */
    function toUint136(uint256 value) internal pure returns (uint136) {
        if (value > type(uint136).max) {
            revert SafeCastOverflowedUintDowncast(136, value);
        }
        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
     */
    function toUint128(uint256 value) internal pure returns (uint128) {
        if (value > type(uint128).max) {
            revert SafeCastOverflowedUintDowncast(128, value);
        }
        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
     */
    function toUint120(uint256 value) internal pure returns (uint120) {
        if (value > type(uint120).max) {
            revert SafeCastOverflowedUintDowncast(120, value);
        }
        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
     */
    function toUint112(uint256 value) internal pure returns (uint112) {
        if (value > type(uint112).max) {
            revert SafeCastOverflowedUintDowncast(112, value);
        }
        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
     */
    function toUint104(uint256 value) internal pure returns (uint104) {
        if (value > type(uint104).max) {
            revert SafeCastOverflowedUintDowncast(104, value);
        }
        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
     */
    function toUint96(uint256 value) internal pure returns (uint96) {
        if (value > type(uint96).max) {
            revert SafeCastOverflowedUintDowncast(96, value);
        }
        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
     */
    function toUint88(uint256 value) internal pure returns (uint88) {
        if (value > type(uint88).max) {
            revert SafeCastOverflowedUintDowncast(88, value);
        }
        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
     */
    function toUint80(uint256 value) internal pure returns (uint80) {
        if (value > type(uint80).max) {
            revert SafeCastOverflowedUintDowncast(80, value);
        }
        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
     */
    function toUint72(uint256 value) internal pure returns (uint72) {
        if (value > type(uint72).max) {
            revert SafeCastOverflowedUintDowncast(72, value);
        }
        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
     */
    function toUint64(uint256 value) internal pure returns (uint64) {
        if (value > type(uint64).max) {
            revert SafeCastOverflowedUintDowncast(64, value);
        }
        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
     */
    function toUint56(uint256 value) internal pure returns (uint56) {
        if (value > type(uint56).max) {
            revert SafeCastOverflowedUintDowncast(56, value);
        }
        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
     */
    function toUint48(uint256 value) internal pure returns (uint48) {
        if (value > type(uint48).max) {
            revert SafeCastOverflowedUintDowncast(48, value);
        }
        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
     */
    function toUint40(uint256 value) internal pure returns (uint40) {
        if (value > type(uint40).max) {
            revert SafeCastOverflowedUintDowncast(40, value);
        }
        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
     */
    function toUint32(uint256 value) internal pure returns (uint32) {
        if (value > type(uint32).max) {
            revert SafeCastOverflowedUintDowncast(32, value);
        }
        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
     */
    function toUint24(uint256 value) internal pure returns (uint24) {
        if (value > type(uint24).max) {
            revert SafeCastOverflowedUintDowncast(24, value);
        }
        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
     */
    function toUint16(uint256 value) internal pure returns (uint16) {
        if (value > type(uint16).max) {
            revert SafeCastOverflowedUintDowncast(16, value);
        }
        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
     */
    function toUint8(uint256 value) internal pure returns (uint8) {
        if (value > type(uint8).max) {
            revert SafeCastOverflowedUintDowncast(8, value);
        }
        return uint8(value);
    }

    /**
     * @dev Converts a signed int256 into an unsigned uint256.
     *
     * Requirements:
     *
     * - input must be greater than or equal to 0.
     */
    function toUint256(int256 value) internal pure returns (uint256) {
        if (value < 0) {
            revert SafeCastOverflowedIntToUint(value);
        }
        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
     */
    function toInt248(int256 value) internal pure returns (int248 downcasted) {
        downcasted = int248(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(248, value);
        }
    }

    /**
     * @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
     */
    function toInt240(int256 value) internal pure returns (int240 downcasted) {
        downcasted = int240(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(240, value);
        }
    }

    /**
     * @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
     */
    function toInt232(int256 value) internal pure returns (int232 downcasted) {
        downcasted = int232(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(232, value);
        }
    }

    /**
     * @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
     */
    function toInt224(int256 value) internal pure returns (int224 downcasted) {
        downcasted = int224(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(224, value);
        }
    }

    /**
     * @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
     */
    function toInt216(int256 value) internal pure returns (int216 downcasted) {
        downcasted = int216(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(216, value);
        }
    }

    /**
     * @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
     */
    function toInt208(int256 value) internal pure returns (int208 downcasted) {
        downcasted = int208(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(208, value);
        }
    }

    /**
     * @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
     */
    function toInt200(int256 value) internal pure returns (int200 downcasted) {
        downcasted = int200(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(200, value);
        }
    }

    /**
     * @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
     */
    function toInt192(int256 value) internal pure returns (int192 downcasted) {
        downcasted = int192(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(192, value);
        }
    }

    /**
     * @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
     */
    function toInt184(int256 value) internal pure returns (int184 downcasted) {
        downcasted = int184(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(184, value);
        }
    }

    /**
     * @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
     */
    function toInt176(int256 value) internal pure returns (int176 downcasted) {
        downcasted = int176(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(176, value);
        }
    }

    /**
     * @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
     */
    function toInt168(int256 value) internal pure returns (int168 downcasted) {
        downcasted = int168(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(168, value);
        }
    }

    /**
     * @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
     */
    function toInt160(int256 value) internal pure returns (int160 downcasted) {
        downcasted = int160(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(160, value);
        }
    }

    /**
     * @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
     */
    function toInt152(int256 value) internal pure returns (int152 downcasted) {
        downcasted = int152(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(152, value);
        }
    }

    /**
     * @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
     */
    function toInt144(int256 value) internal pure returns (int144 downcasted) {
        downcasted = int144(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(144, value);
        }
    }

    /**
     * @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
     */
    function toInt136(int256 value) internal pure returns (int136 downcasted) {
        downcasted = int136(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(136, value);
        }
    }

    /**
     * @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
     */
    function toInt128(int256 value) internal pure returns (int128 downcasted) {
        downcasted = int128(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(128, value);
        }
    }

    /**
     * @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
     */
    function toInt120(int256 value) internal pure returns (int120 downcasted) {
        downcasted = int120(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(120, value);
        }
    }

    /**
     * @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
     */
    function toInt112(int256 value) internal pure returns (int112 downcasted) {
        downcasted = int112(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(112, value);
        }
    }

    /**
     * @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
     */
    function toInt104(int256 value) internal pure returns (int104 downcasted) {
        downcasted = int104(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(104, value);
        }
    }

    /**
     * @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
     */
    function toInt96(int256 value) internal pure returns (int96 downcasted) {
        downcasted = int96(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(96, value);
        }
    }

    /**
     * @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
     */
    function toInt88(int256 value) internal pure returns (int88 downcasted) {
        downcasted = int88(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(88, value);
        }
    }

    /**
     * @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
     */
    function toInt80(int256 value) internal pure returns (int80 downcasted) {
        downcasted = int80(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(80, value);
        }
    }

    /**
     * @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
     */
    function toInt72(int256 value) internal pure returns (int72 downcasted) {
        downcasted = int72(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(72, value);
        }
    }

    /**
     * @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
     */
    function toInt64(int256 value) internal pure returns (int64 downcasted) {
        downcasted = int64(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(64, value);
        }
    }

    /**
     * @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
     */
    function toInt56(int256 value) internal pure returns (int56 downcasted) {
        downcasted = int56(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(56, value);
        }
    }

    /**
     * @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
     */
    function toInt48(int256 value) internal pure returns (int48 downcasted) {
        downcasted = int48(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(48, value);
        }
    }

    /**
     * @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
     */
    function toInt40(int256 value) internal pure returns (int40 downcasted) {
        downcasted = int40(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(40, value);
        }
    }

    /**
     * @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
     */
    function toInt32(int256 value) internal pure returns (int32 downcasted) {
        downcasted = int32(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(32, value);
        }
    }

    /**
     * @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
     */
    function toInt24(int256 value) internal pure returns (int24 downcasted) {
        downcasted = int24(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(24, value);
        }
    }

    /**
     * @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
     */
    function toInt16(int256 value) internal pure returns (int16 downcasted) {
        downcasted = int16(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(16, value);
        }
    }

    /**
     * @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
     */
    function toInt8(int256 value) internal pure returns (int8 downcasted) {
        downcasted = int8(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(8, value);
        }
    }

    /**
     * @dev Converts an unsigned uint256 into a signed int256.
     *
     * Requirements:
     *
     * - input must be less than or equal to maxInt256.
     */
    function toInt256(uint256 value) internal pure returns (int256) {
        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
        if (value > uint256(type(int256).max)) {
            revert SafeCastOverflowedUintToInt(value);
        }
        return int256(value);
    }

    /**
     * @dev Cast a boolean (false or true) to a uint256 (0 or 1) with no jump.
     */
    function toUint(bool b) internal pure returns (uint256 u) {
        assembly ("memory-safe") {
            u := iszero(iszero(b))
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SignedMath.sol)

pragma solidity ^0.8.20;

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

/**
 * @dev Standard signed math utilities missing in the Solidity language.
 */
library SignedMath {
    /**
     * @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.
     *
     * IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.
     * However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute
     * one branch when needed, making this function more expensive.
     */
    function ternary(bool condition, int256 a, int256 b) internal pure returns (int256) {
        unchecked {
            // branchless ternary works because:
            // b ^ (a ^ b) == a
            // b ^ 0 == b
            return b ^ ((a ^ b) * int256(SafeCast.toUint(condition)));
        }
    }

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

    /**
     * @dev Returns the smallest of two signed numbers.
     */
    function min(int256 a, int256 b) internal pure returns (int256) {
        return ternary(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 {
            // Formula from the "Bit Twiddling Hacks" by Sean Eron Anderson.
            // Since `n` is a signed integer, the generated bytecode will use the SAR opcode to perform the right shift,
            // taking advantage of the most significant (or "sign" bit) in two's complement representation.
            // This opcode adds new most significant bits set to the value of the previous most significant bit. As a result,
            // the mask will either be `bytes32(0)` (if n is positive) or `~bytes32(0)` (if n is negative).
            int256 mask = n >> 255;

            // A `bytes32(0)` mask leaves the input unchanged, while a `~bytes32(0)` mask complements it.
            return uint256((n + mask) ^ mask);
        }
    }
}

File 46 of 48 : StrategyIdLib.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

library StrategyIdLib {
    string internal constant DEV = "Dev Alpha DeepSpaceSwap Farm";
    string internal constant QUICKSWAPV3_STATIC_FARM = "QuickSwapV3 Static Farm";
    string internal constant GAMMA_QUICKSWAP_MERKL_FARM = "Gamma QuickSwap Merkl Farm";
    string internal constant GAMMA_RETRO_MERKL_FARM = "Gamma Retro Merkl Farm";
    string internal constant GAMMA_UNISWAPV3_MERKL_FARM = "Gamma UniswapV3 Merkl Farm";
    string internal constant COMPOUND_FARM = "Compound Farm";
    string internal constant DEFIEDGE_QUICKSWAP_MERKL_FARM = "DefiEdge QuickSwap Merkl Farm";
    string internal constant STEER_QUICKSWAP_MERKL_FARM = "Steer QuickSwap Merkl Farm";
    string internal constant ICHI_QUICKSWAP_MERKL_FARM = "Ichi QuickSwap Merkl Farm";
    string internal constant ICHI_RETRO_MERKL_FARM = "Ichi Retro Merkl Farm";
    string internal constant QUICKSWAP_STATIC_MERKL_FARM = "QuickSwap Static Merkl Farm";
    string internal constant CURVE_CONVEX_FARM = "Curve Convex Farm";
    string internal constant YEARN = "Yearn";
    string internal constant TRIDENT_PEARL_FARM = "Trident Pearl Farm";
    string internal constant BEETS_STABLE_FARM = "Beets Stable Farm";
    string internal constant BEETS_WEIGHTED_FARM = "Beets Weighted Farm";
    string internal constant EQUALIZER_FARM = "Equalizer Farm";
    string internal constant ICHI_SWAPX_FARM = "Ichi SwapX Farm";
    string internal constant SWAPX_FARM = "SwapX Farm";
    string internal constant SILO_FARM = "Silo Farm";
    string internal constant ALM_SHADOW_FARM = "ALM Shadow Farm";
    string internal constant SILO_LEVERAGE = "Silo Leverage";
    string internal constant SILO_ADVANCED_LEVERAGE = "Silo Advanced Leverage";
    string internal constant GAMMA_EQUALIZER_FARM = "Gamma Equalizer Farm";
    string internal constant ICHI_EQUALIZER_FARM = "Ichi Equalizer Farm";
    string internal constant EULER_MERKL_FARM = "Euler Merkl Farm";
    string internal constant SILO = "Silo";
    string internal constant AAVE = "Aave";
    string internal constant EULER = "Euler"; // https://euler.finance/
    string internal constant SILO_MANAGED_FARM = "Silo Managed Farm";
    string internal constant SILO_ALMF_FARM = "Silo Advanced Leverage Merkl Farm";
    string internal constant AAVE_MERKL_FARM = "Aave Merkl Farm";
    string internal constant COMPOUND_V2 = "Compound V2";
    string internal constant SILO_MANAGED_MERKL_FARM = "Silo Managed Merkl Farm";
    string internal constant SILO_MERKL_FARM = "Silo Merkl Farm"; // SiMerklF
}

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

/// @title Simple ERC-1967 upgradeable proxy implementation
abstract contract UpgradeableProxy {
    error ImplementationIsNotContract();

    /// @dev This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is
    bytes32 private constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;

    /// @dev Emitted when the implementation is upgraded.
    event Upgraded(address indexed implementation);

    constructor() {
        assert(_IMPLEMENTATION_SLOT == bytes32(uint(keccak256("eip1967.proxy.implementation")) - 1));
    }

    /// @dev Post deploy initialisation for compatability with EIP-1167 factory
    function _init(address logic) internal {
        require(_implementation() == address(0), "Already inited");
        _setImplementation(logic);
    }

    /// @dev Returns the current implementation address.
    function _implementation() internal view virtual returns (address impl) {
        bytes32 slot = _IMPLEMENTATION_SLOT;
        // solhint-disable-next-line no-inline-assembly
        //slither-disable-next-line assembly
        assembly {
            impl := sload(slot)
        }
    }

    /// @dev Upgrades the proxy to a new implementation.
    function _upgradeTo(address newImplementation) internal virtual {
        _setImplementation(newImplementation);
        emit Upgraded(newImplementation);
    }

    /// @dev Stores a new address in the EIP1967 implementation slot.
    function _setImplementation(address newImplementation) private {
        if (newImplementation.code.length == 0) revert ImplementationIsNotContract();
        bytes32 slot = _IMPLEMENTATION_SLOT;
        //slither-disable-next-line assembly
        assembly {
            sstore(slot, newImplementation)
        }
    }

    /**
     * @dev Delegates the current call to `implementation`.
     *
     * This function does not return to its internal call site, it will return directly to the external caller.
     */
    function _delegate(address implementation) internal virtual {
        //slither-disable-next-line assembly
        assembly {
            // Copy msg.data. We take full control of memory in this inline assembly
            // block because it will not return to Solidity code. We overwrite the
            // Solidity scratch pad at memory position 0.
            calldatacopy(0, 0, calldatasize())

            // Call the implementation.
            // out and outsize are 0 because we don't know the size yet.
            let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0)

            // Copy the returned data.
            returndatacopy(0, 0, returndatasize())

            switch result
            // delegatecall returns 0 on error.
            case 0 { revert(0, returndatasize()) }
            default { return(0, returndatasize()) }
        }
    }

    /**
     * @dev Delegates the current call to the address returned by `_implementation()`.
     *
     * This function does not return to its internal call site, it will return directly to the external caller.
     */
    function _fallback() internal virtual {
        _delegate(_implementation());
    }

    /// @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if no other
    /// function in the contract matches the call data.
    //slither-disable-next-line locked-ether
    fallback() external payable virtual {
        _fallback();
    }

    /// @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if call data
    /// is empty.
    //slither-disable-next-line locked-ether
    receive() external payable virtual {
        _fallback();
    }
}

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

pragma solidity >=0.6.2;

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

/**
 * @dev Required interface of an ERC-721 compliant contract.
 */
interface IERC721 is IERC165 {
    /**
     * @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 ERC-721 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 ERC-721
     * 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 address zero.
     *
     * 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);
}

Settings
{
  "remappings": [
    "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
    "@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
    "@solady/=lib/solady/src/",
    "ds-test/=lib/forge-std/lib/ds-test/src/",
    "erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
    "forge-std/=lib/forge-std/src/",
    "openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
    "openzeppelin/=lib/openzeppelin-contracts-upgradeable/contracts/",
    "solady/=lib/solady/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/"
  ],
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "metadata": {
    "useLiteralContent": false,
    "bytecodeHash": "ipfs",
    "appendCBOR": true
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "evmVersion": "cancun",
  "viaIR": false,
  "libraries": {
    "src/core/Factory.sol": {
      "CommonLib": "0x00d737941f0f5f629d85c12426a1a9e4ea056759",
      "DeployerLib": "0x83a2764961ec7ce166fac7c8f4fd371ea45cb2d3",
      "FactoryLib": "0xd9695208188b9bfa05061ec99a978ec68ccae7b8",
      "FactoryNamingLib": "0x240bfa20cca1e995be47c0c0253a27e72ca8295d"
    }
  }
}

Contract Security Audit

Contract ABI

API
[{"inputs":[],"name":"AlreadyExist","type":"error"},{"inputs":[{"internalType":"bytes32","name":"_hash","type":"bytes32"}],"name":"AlreadyLastVersion","type":"error"},{"inputs":[],"name":"ETHTransferFailed","type":"error"},{"inputs":[],"name":"IncorrectArrayLength","type":"error"},{"inputs":[{"internalType":"address[]","name":"assets_","type":"address[]"},{"internalType":"address[]","name":"expectedAssets_","type":"address[]"}],"name":"IncorrectAssetsList","type":"error"},{"inputs":[],"name":"IncorrectBalance","type":"error"},{"inputs":[],"name":"IncorrectInitParams","type":"error"},{"inputs":[{"internalType":"uint256","name":"ltv","type":"uint256"}],"name":"IncorrectLtv","type":"error"},{"inputs":[],"name":"IncorrectMsgSender","type":"error"},{"inputs":[],"name":"IncorrectZeroArgument","type":"error"},{"inputs":[],"name":"InsufficientBalance","type":"error"},{"inputs":[],"name":"InvalidInitialization","type":"error"},{"inputs":[],"name":"NotActiveVault","type":"error"},{"inputs":[],"name":"NotExist","type":"error"},{"inputs":[],"name":"NotFactory","type":"error"},{"inputs":[],"name":"NotGovernance","type":"error"},{"inputs":[],"name":"NotGovernanceAndNotMultisig","type":"error"},{"inputs":[],"name":"NotInitializing","type":"error"},{"inputs":[],"name":"NotMultisig","type":"error"},{"inputs":[],"name":"NotOperator","type":"error"},{"inputs":[],"name":"NotPlatform","type":"error"},{"inputs":[],"name":"NotStrategy","type":"error"},{"inputs":[],"name":"NotTheOwner","type":"error"},{"inputs":[],"name":"NotVault","type":"error"},{"inputs":[],"name":"ReentrancyGuardReentrantCall","type":"error"},{"inputs":[],"name":"StrategyImplementationIsNotAvailable","type":"error"},{"inputs":[{"internalType":"bytes32","name":"key","type":"bytes32"}],"name":"SuchVaultAlreadyDeployed","type":"error"},{"inputs":[{"internalType":"uint256","name":"value","type":"uint256"}],"name":"TooLowValue","type":"error"},{"inputs":[{"internalType":"bytes32","name":"_hash","type":"bytes32"}],"name":"UpgradeDenied","type":"error"},{"inputs":[],"name":"VaultImplementationIsNotAvailable","type":"error"},{"inputs":[{"internalType":"uint256","name":"userBalance","type":"uint256"},{"internalType":"uint256","name":"requireBalance","type":"uint256"},{"internalType":"address","name":"payToken","type":"address"}],"name":"YouDontHaveEnoughTokens","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":true,"internalType":"address","name":"tokenAddress","type":"address"},{"indexed":false,"internalType":"string","name":"newAliasName","type":"string"}],"name":"AliasNameChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"platform","type":"address"},{"indexed":false,"internalType":"uint256","name":"ts","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"block","type":"uint256"}],"name":"ContractInitialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"version","type":"uint64"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"components":[{"internalType":"uint256","name":"status","type":"uint256"},{"internalType":"address","name":"pool","type":"address"},{"internalType":"string","name":"strategyLogicId","type":"string"},{"internalType":"address[]","name":"rewardAssets","type":"address[]"},{"internalType":"address[]","name":"addresses","type":"address[]"},{"internalType":"uint256[]","name":"nums","type":"uint256[]"},{"internalType":"int24[]","name":"ticks","type":"int24[]"}],"indexed":false,"internalType":"struct IFactory.Farm[]","name":"farms","type":"tuple[]"}],"name":"NewFarm","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"id","type":"string"},{"indexed":false,"internalType":"address[]","name":"initAddresses","type":"address[]"},{"indexed":false,"internalType":"uint256[]","name":"initNums","type":"uint256[]"},{"indexed":false,"internalType":"int24[]","name":"initTicks","type":"int24[]"}],"name":"SetStrategyAvailableInitParams","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"id","type":"string"},{"indexed":false,"internalType":"address","name":"implementation","type":"address"},{"indexed":false,"internalType":"bool","name":"deployAllowed","type":"bool"},{"indexed":false,"internalType":"bool","name":"upgradeAllowed","type":"bool"},{"indexed":false,"internalType":"bool","name":"newStrategy","type":"bool"}],"name":"StrategyLogicConfigChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"proxy","type":"address"},{"indexed":false,"internalType":"address","name":"oldImplementation","type":"address"},{"indexed":false,"internalType":"address","name":"newImplementation","type":"address"}],"name":"StrategyProxyUpgraded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"id","type":"uint256"},{"components":[{"internalType":"uint256","name":"status","type":"uint256"},{"internalType":"address","name":"pool","type":"address"},{"internalType":"string","name":"strategyLogicId","type":"string"},{"internalType":"address[]","name":"rewardAssets","type":"address[]"},{"internalType":"address[]","name":"addresses","type":"address[]"},{"internalType":"uint256[]","name":"nums","type":"uint256[]"},{"internalType":"int24[]","name":"ticks","type":"int24[]"}],"indexed":false,"internalType":"struct IFactory.Farm","name":"farm","type":"tuple"}],"name":"UpdateFarm","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"deployer","type":"address"},{"indexed":false,"internalType":"string","name":"vaultType","type":"string"},{"indexed":false,"internalType":"string","name":"strategyId","type":"string"},{"indexed":false,"internalType":"address","name":"vault","type":"address"},{"indexed":false,"internalType":"address","name":"strategy","type":"address"},{"indexed":false,"internalType":"string","name":"name","type":"string"},{"indexed":false,"internalType":"string","name":"symbol","type":"string"},{"indexed":false,"internalType":"address[]","name":"assets","type":"address[]"},{"indexed":false,"internalType":"bytes32","name":"deploymentKey","type":"bytes32"},{"indexed":false,"internalType":"uint256","name":"vaultManagerTokenId","type":"uint256"}],"name":"VaultAndStrategy","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"type_","type":"string"},{"indexed":false,"internalType":"address","name":"implementation","type":"address"},{"indexed":false,"internalType":"bool","name":"deployAllowed","type":"bool"},{"indexed":false,"internalType":"bool","name":"upgradeAllowed","type":"bool"},{"indexed":false,"internalType":"bool","name":"newVaultType","type":"bool"}],"name":"VaultConfigChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"proxy","type":"address"},{"indexed":false,"internalType":"address","name":"oldImplementation","type":"address"},{"indexed":false,"internalType":"address","name":"newImplementation","type":"address"}],"name":"VaultProxyUpgraded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"vault","type":"address"},{"indexed":false,"internalType":"uint256","name":"newStatus","type":"uint256"}],"name":"VaultStatus","type":"event"},{"inputs":[],"name":"CONTROLLABLE_VERSION","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"VERSION","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"status","type":"uint256"},{"internalType":"address","name":"pool","type":"address"},{"internalType":"string","name":"strategyLogicId","type":"string"},{"internalType":"address[]","name":"rewardAssets","type":"address[]"},{"internalType":"address[]","name":"addresses","type":"address[]"},{"internalType":"uint256[]","name":"nums","type":"uint256[]"},{"internalType":"int24[]","name":"ticks","type":"int24[]"}],"internalType":"struct IFactory.Farm[]","name":"farms_","type":"tuple[]"}],"name":"addFarms","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"createdBlock","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"vaultType","type":"string"},{"internalType":"string","name":"strategyId","type":"string"},{"internalType":"address[]","name":"vaultInitAddresses","type":"address[]"},{"internalType":"uint256[]","name":"vaultInitNums","type":"uint256[]"},{"internalType":"address[]","name":"strategyInitAddresses","type":"address[]"},{"internalType":"uint256[]","name":"strategyInitNums","type":"uint256[]"},{"internalType":"int24[]","name":"strategyInitTicks","type":"int24[]"}],"name":"deployVaultAndStrategy","outputs":[{"internalType":"address","name":"vault","type":"address"},{"internalType":"address","name":"strategy","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"name":"deployedVault","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"deployedVaults","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"deployedVaultsLength","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"deploymentKey_","type":"bytes32"}],"name":"deploymentKey","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"name":"farm","outputs":[{"components":[{"internalType":"uint256","name":"status","type":"uint256"},{"internalType":"address","name":"pool","type":"address"},{"internalType":"string","name":"strategyLogicId","type":"string"},{"internalType":"address[]","name":"rewardAssets","type":"address[]"},{"internalType":"address[]","name":"addresses","type":"address[]"},{"internalType":"uint256[]","name":"nums","type":"uint256[]"},{"internalType":"int24[]","name":"ticks","type":"int24[]"}],"internalType":"struct IFactory.Farm","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"farms","outputs":[{"components":[{"internalType":"uint256","name":"status","type":"uint256"},{"internalType":"address","name":"pool","type":"address"},{"internalType":"string","name":"strategyLogicId","type":"string"},{"internalType":"address[]","name":"rewardAssets","type":"address[]"},{"internalType":"address[]","name":"addresses","type":"address[]"},{"internalType":"uint256[]","name":"nums","type":"uint256[]"},{"internalType":"int24[]","name":"ticks","type":"int24[]"}],"internalType":"struct IFactory.Farm[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"farmsLength","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"vaultType","type":"string"},{"internalType":"string","name":"strategyId","type":"string"},{"internalType":"address[]","name":"initVaultAddresses","type":"address[]"},{"internalType":"uint256[]","name":"initVaultNums","type":"uint256[]"},{"internalType":"address[]","name":"initStrategyAddresses","type":"address[]"},{"internalType":"uint256[]","name":"initStrategyNums","type":"uint256[]"},{"internalType":"int24[]","name":"initStrategyTicks","type":"int24[]"}],"name":"getDeploymentKey","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address[]","name":"assets","type":"address[]"}],"name":"getExchangeAssetIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"vaultType","type":"string"},{"internalType":"address","name":"strategyAddress","type":"address"},{"internalType":"address","name":"bbAsset","type":"address"}],"name":"getStrategyData","outputs":[{"internalType":"string","name":"strategyId","type":"string"},{"internalType":"address[]","name":"assets","type":"address[]"},{"internalType":"string[]","name":"assetsSymbols","type":"string[]"},{"internalType":"string","name":"specificName","type":"string"},{"internalType":"string","name":"vaultSymbol","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"platform_","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"address_","type":"address"}],"name":"isStrategy","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"platform","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"id","type":"string"},{"components":[{"internalType":"address[]","name":"initAddresses","type":"address[]"},{"internalType":"uint256[]","name":"initNums","type":"uint256[]"},{"internalType":"int24[]","name":"initTicks","type":"int24[]"}],"internalType":"struct IFactory.StrategyAvailableInitParams","name":"initParams","type":"tuple"}],"name":"setStrategyAvailableInitParams","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"strategyId","type":"string"},{"internalType":"address","name":"implementation","type":"address"}],"name":"setStrategyImplementation","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"vaultType","type":"string"},{"internalType":"address","name":"implementation","type":"address"}],"name":"setVaultImplementation","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"vaults","type":"address[]"},{"internalType":"uint256[]","name":"statuses","type":"uint256[]"}],"name":"setVaultStatus","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"strategies","outputs":[{"internalType":"string[]","name":"id","type":"string[]"},{"internalType":"bool[]","name":"deployAllowed","type":"bool[]"},{"internalType":"bool[]","name":"upgradeAllowed","type":"bool[]"},{"internalType":"bool[]","name":"farming","type":"bool[]"},{"internalType":"uint256[]","name":"tokenId","type":"uint256[]"},{"internalType":"string[]","name":"tokenURI","type":"string[]"},{"internalType":"bytes32[]","name":"extra","type":"bytes32[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"idHash","type":"bytes32"}],"name":"strategyAvailableInitParams","outputs":[{"components":[{"internalType":"address[]","name":"initAddresses","type":"address[]"},{"internalType":"uint256[]","name":"initNums","type":"uint256[]"},{"internalType":"int24[]","name":"initTicks","type":"int24[]"}],"internalType":"struct IFactory.StrategyAvailableInitParams","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"idHash","type":"bytes32"}],"name":"strategyLogicConfig","outputs":[{"components":[{"internalType":"string","name":"id","type":"string"},{"internalType":"address","name":"implementation","type":"address"},{"internalType":"bool","name":"deployAllowed","type":"bool"},{"internalType":"bool","name":"upgradeAllowed","type":"bool"},{"internalType":"bool","name":"farming","type":"bool"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"internalType":"struct IFactory.StrategyLogicConfig","name":"config","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"strategyLogicIdHashes","outputs":[{"internalType":"bytes32[]","name":"","type":"bytes32[]"}],"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":"uint256","name":"id","type":"uint256"},{"components":[{"internalType":"uint256","name":"status","type":"uint256"},{"internalType":"address","name":"pool","type":"address"},{"internalType":"string","name":"strategyLogicId","type":"string"},{"internalType":"address[]","name":"rewardAssets","type":"address[]"},{"internalType":"address[]","name":"addresses","type":"address[]"},{"internalType":"uint256[]","name":"nums","type":"uint256[]"},{"internalType":"int24[]","name":"ticks","type":"int24[]"}],"internalType":"struct IFactory.Farm","name":"farm_","type":"tuple"}],"name":"updateFarm","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"strategyProxy","type":"address"}],"name":"upgradeStrategyProxy","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"vault","type":"address"}],"name":"upgradeVaultProxy","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"typeHash","type":"bytes32"}],"name":"vaultConfig","outputs":[{"internalType":"string","name":"vaultType","type":"string"},{"internalType":"address","name":"implementation","type":"address"},{"internalType":"bool","name":"deployAllowed","type":"bool"},{"internalType":"bool","name":"upgradeAllowed","type":"bool"},{"internalType":"uint256","name":"buildingPrice","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"vault","type":"address"}],"name":"vaultStatus","outputs":[{"internalType":"uint256","name":"status","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"vaultTypes","outputs":[{"internalType":"string[]","name":"vaultType","type":"string[]"},{"internalType":"address[]","name":"implementation","type":"address[]"},{"internalType":"bool[]","name":"deployAllowed","type":"bool[]"},{"internalType":"bool[]","name":"upgradeAllowed","type":"bool[]"},{"internalType":"uint256[]","name":"buildingPrice","type":"uint256[]"},{"internalType":"bytes32[]","name":"extra","type":"bytes32[]"}],"stateMutability":"view","type":"function"}]

6080604052348015600e575f5ffd5b5060156019565b60c9565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00805468010000000000000000900460ff161560685760405163f92ee8a960e01b815260040160405180910390fd5b80546001600160401b039081161460c65780546001600160401b0319166001600160401b0390811782556040519081527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a15b50565b6149d4806100d65f395ff3fe608060405234801561000f575f5ffd5b50600436106101f2575f3560e01c806389ec7a4111610114578063d6f51d62116100a9578063dd7ff3db11610079578063dd7ff3db14610491578063e967f16b146104c4578063f378d1d4146104d7578063f583734e146104df578063ffa1ad7414610503575f5ffd5b8063d6f51d621461043d578063d9f9027f14610450578063db22d7a01461046b578063dcc805181461047e575f5ffd5b8063b2d96884116100e4578063b2d96884146103e2578063c4d66de8146103f7578063c56ebcd61461040a578063d0cf00541461042a575f5ffd5b806389ec7a411461036b578063936725ec1461037e5780639ad87ce4146103af578063b1b1402a146103cf575f5ffd5b80634bde38c81161018a5780636c2713a31161015a5780636c2713a31461031d5780637031c482146103305780637d474fa314610343578063871fd68214610356575f5ffd5b80634bde38c8146102b7578063538a85a1146102d7578063582a4d37146102f757806358a2ab1c1461030a575f5ffd5b80632e8ebaae116101c55780632e8ebaae1461026d57806336abf3dc146102805780633adc774e1461029a5780634593144c146102af575f5ffd5b806301ffc9a7146101f65780630d9c8bcd1461021e5780630f038dcd1461023457806314e4380c14610249575b5f5ffd5b6102096102043660046133a0565b610527565b60405190151581526020015b60405180910390f35b61022661055d565b604051908152602001610215565b61023c610571565b6040516102159190613401565b61025c610257366004613413565b610590565b604051610215959493929190613458565b61020961027b3660046134bb565b6106c3565b6102886106f0565b6040516102159695949392919061359b565b6102ad6102a83660046134bb565b610b30565b005b610226610c1a565b6102bf610c52565b6040516001600160a01b039091168152602001610215565b6102ea6102e5366004613413565b610c81565b60405161021591906136ef565b6102ad610305366004613a62565b610f5c565b610226610318366004613aa5565b611086565b6102ad61032b366004613bd5565b61113f565b6102ad61033e366004613cbf565b611229565b6102bf610351366004613413565b611329565b61035e611350565b6040516102159190613d18565b6102bf610379366004613413565b6115f5565b6103a260405180604001604052806005815260200164312e302e3160d81b81525081565b6040516102159190613d7b565b6103c26103bd366004613413565b611631565b6040516102159190613d8d565b6102ad6103dd366004613de3565b61178a565b6103ea611832565b6040516102159190613e31565b6102ad6104053660046134bb565b61189b565b61041d610418366004613413565b61199a565b6040516102159190613e43565b6102266104383660046134bb565b611ada565b6102ad61044b366004613de3565b611b05565b610458611b54565b6040516102159796959493929190613eaa565b610226610479366004613f40565b6120de565b6102ad61048c3660046134bb565b61215e565b6104a461049f366004613aa5565b6121f3565b604080516001600160a01b03938416815292909116602083015201610215565b6102ad6104d2366004613f79565b612bd2565b610226612d17565b6104f26104ed366004614028565b612d2b565b604051610215959493929190614087565b6103a2604051806040016040528060058152602001640322e302e360dc1b81525081565b5f6001600160e01b03198216630f1ec81f60e41b148061055757506301ffc9a760e01b6001600160e01b03198316145b92915050565b5f5f610567612dcc565b600a015492915050565b60605f61057c612dcc565b905061058a81600701612df0565b91505090565b60605f5f5f5f5f61059f612dcc565b90505f815f015f8981526020019081526020015f206040518060a00160405290815f820180546105ce906140e7565b80601f01602080910402602001604051908101604052809291908181526020018280546105fa906140e7565b80156106455780601f1061061c57610100808354040283529160200191610645565b820191905f5260205f20905b81548152906001019060200180831161062857829003601f168201915b505050918352505060018201546001600160a01b03811660208084019190915260ff600160a01b830481161515604080860191909152600160a81b90930416151560608085019190915260029094015460809384015284519085015191850151938501519490920151919c909b509199509197509095509350505050565b5f6106cc612dcc565b6001600160a01b039092165f90815260049290920160205250604090205460ff1690565b6060806060806060805f610702612dcc565b90505f61071182600501612df0565b8051909150806001600160401b0381111561072e5761072e613701565b60405190808252806020026020018201604052801561076157816020015b606081526020019060019003908161074c5790505b509850806001600160401b0381111561077c5761077c613701565b6040519080825280602002602001820160405280156107a5578160200160208202803683370190505b509750806001600160401b038111156107c0576107c0613701565b6040519080825280602002602001820160405280156107e9578160200160208202803683370190505b509650806001600160401b0381111561080457610804613701565b60405190808252806020026020018201604052801561082d578160200160208202803683370190505b509550806001600160401b0381111561084857610848613701565b604051908082528060200260200182016040528015610871578160200160208202803683370190505b509450806001600160401b0381111561088c5761088c613701565b6040519080825280602002602001820160405280156108b5578160200160208202803683370190505b5093505f5b81811015610b24575f845f015f8584815181106108d9576108d961411f565b602002602001015181526020019081526020015f206040518060a00160405290815f82018054610908906140e7565b80601f0160208091040260200160405190810160405280929190818152602001828054610934906140e7565b801561097f5780601f106109565761010080835404028352916020019161097f565b820191905f5260205f20905b81548152906001019060200180831161096257829003601f168201915b505050918352505060018201546001600160a01b038116602083015260ff600160a01b8204811615156040840152600160a81b909104161515606082015260029091015460809091015280518c51919250908c90849081106109e3576109e361411f565b602002602001018190525080602001518a8381518110610a0557610a0561411f565b60200260200101906001600160a01b031690816001600160a01b0316815250508060400151898381518110610a3c57610a3c61411f565b6020026020010190151590811515815250508060600151888381518110610a6557610a6561411f565b6020026020010190151590811515815250508060800151878381518110610a8e57610a8e61411f565b60200260200101818152505080602001516001600160a01b031663190024e06040518163ffffffff1660e01b8152600401602060405180830381865afa158015610ada573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610afe9190614133565b868381518110610b1057610b1061411f565b6020908102919091010152506001016108ba565b50505050909192939495565b610b38612e03565b5f610b41612dcc565b6001600160a01b0383165f908152600382016020526040902054909150600114610b7e57604051630d7abd6f60e31b815260040160405180910390fd5b604051637817605360e01b8152600481018290526001600160a01b038316602482015273d9695208188b9bfa05061ec99a978ec68ccae7b8906378176053906044015b5f6040518083038186803b158015610bd7575f5ffd5b505af4158015610be9573d5f5f3e3d5ffd5b5050505050610c1760017f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f0055565b50565b5f610c4d610c4960017f812a673dfca07956350df10f8a654925f561d7a0da09bdbe79e653939a14d9f161415e565b5490565b905090565b5f610c4d610c4960017faa116a42804728f23983458454b6eb9c6ddf3011db9f9addaf3cd7508d85b0d661415e565b610cc86040518060e001604052805f81526020015f6001600160a01b0316815260200160608152602001606081526020016060815260200160608152602001606081525090565b5f610cd1612dcc565b905080600b018381548110610ce857610ce861411f565b905f5260205f2090600702016040518060e00160405290815f8201548152602001600182015f9054906101000a90046001600160a01b03166001600160a01b03166001600160a01b03168152602001600282018054610d46906140e7565b80601f0160208091040260200160405190810160405280929190818152602001828054610d72906140e7565b8015610dbd5780601f10610d9457610100808354040283529160200191610dbd565b820191905f5260205f20905b815481529060010190602001808311610da057829003601f168201915b5050505050815260200160038201805480602002602001604051908101604052809291908181526020018280548015610e1d57602002820191905f5260205f20905b81546001600160a01b03168152600190910190602001808311610dff575b5050505050815260200160048201805480602002602001604051908101604052809291908181526020018280548015610e7d57602002820191905f5260205f20905b81546001600160a01b03168152600190910190602001808311610e5f575b5050505050815260200160058201805480602002602001604051908101604052809291908181526020018280548015610ed357602002820191905f5260205f20905b815481526020019060010190808311610ebf575b5050505050815260200160068201805480602002602001604051908101604052809291908181526020018280548015610f4b57602002820191905f5260205f20905f905b825461010083900a900460020b8152602060058301819004938401936001036003909301929092029101808411610f175790505b505050505081525050915050919050565b610f64612e73565b5f610f6d612dcc565b90508181600b018481548110610f8557610f8561411f565b5f918252602091829020835160079290920201908155908201516001820180546001600160a01b0319166001600160a01b0390921691909117905560408201516002820190610fd490826141b5565b5060608201518051610ff091600384019160209091019061324d565b506080820151805161100c91600484019160209091019061324d565b5060a082015180516110289160058401916020909101906132b0565b5060c082015180516110449160068401916020909101906132e9565b509050507f4e8499c72391533d62e187d3f07fc288fbc1742c8e094f36b5e23b836bb29e89838360405161107992919061426f565b60405180910390a1505050565b6040805160a08101825260018082525f602083018190528284018290526060830191909152608082018190529151636c309d4f60e11b815273d9695208188b9bfa05061ec99a978ec68ccae7b89163d8613a9e916110f4918c918c918c918c918c918c918c916004016142b2565b602060405180830381865af415801561110f573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906111339190614133565b98975050505050505050565b611147612e73565b5f611150612dcc565b90505f836040516020016111649190614377565b60408051601f1981840301815291815281516020928301205f818152600c860184529190912085518051929450869391926111a2928492019061324d565b5060208281015180516111bb92600185019201906132b0565b50604082015180516111d79160028401916020909101906132e9565b509050507fba197f5223035cb2b7a0f09844df05667b65b529665865bd98232748de75970b84845f01518560200151866040015160405161121b949392919061438d565b60405180910390a150505050565b611231612f02565b5f61123a612dcc565b83519091505f5b818110156113225783818151811061125b5761125b61411f565b6020026020010151836003015f87848151811061127a5761127a61411f565b60200260200101516001600160a01b03166001600160a01b031681526020019081526020015f20819055508481815181106112b7576112b761411f565b60200260200101516001600160a01b03167fd518071c0dca755922e3df4b2f1457ed64340814d52371e060a067edd0a9578a8583815181106112fb576112fb61411f565b602002602001015160405161131291815260200190565b60405180910390a2600101611241565b5050505050565b5f5f611333612dcc565b5f938452600201602052505060409020546001600160a01b031690565b60605f61135b612dcc565b600b81018054604080516020808402820181019092528281529394505f9084015b828210156115eb575f8481526020908190206040805160e081018252600786029092018054835260018101546001600160a01b031693830193909352600283018054929392918401916113ce906140e7565b80601f01602080910402602001604051908101604052809291908181526020018280546113fa906140e7565b80156114455780601f1061141c57610100808354040283529160200191611445565b820191905f5260205f20905b81548152906001019060200180831161142857829003601f168201915b50505050508152602001600382018054806020026020016040519081016040528092919081815260200182805480156114a557602002820191905f5260205f20905b81546001600160a01b03168152600190910190602001808311611487575b505050505081526020016004820180548060200260200160405190810160405280929190818152602001828054801561150557602002820191905f5260205f20905b81546001600160a01b031681526001909101906020018083116114e7575b505050505081526020016005820180548060200260200160405190810160405280929190818152602001828054801561155b57602002820191905f5260205f20905b815481526020019060010190808311611547575b50505050508152602001600682018054806020026020016040519081016040528092919081815260200182805480156115d357602002820191905f5260205f20905f905b825461010083900a900460020b815260206005830181900493840193600103600390930192909202910180841161159f5790505b5050505050815250508152602001906001019061137c565b5050505091505090565b5f5f6115ff612dcc565b905080600a0183815481106116165761161661411f565b5f918252602090912001546001600160a01b03169392505050565b61165560405180606001604052806060815260200160608152602001606081525090565b5f61165e612dcc565b5f848152600c82016020908152604091829020825181546080938102820184019094526060810184815294955093909284928491908401828280156116ca57602002820191905f5260205f20905b81546001600160a01b031681526001909101906020018083116116ac575b505050505081526020016001820180548060200260200160405190810160405280929190818152602001828054801561172057602002820191905f5260205f20905b81548152602001906001019080831161170c575b5050505050815260200160028201805480602002602001604051908101604052809291908181526020018280548015610f4b575f918252602091829020805460020b8452908202830192909160039101808411610f17579050505050505081525050915050919050565b611792612e73565b5f61179b612dcc565b905073d9695208188b9bfa05061ec99a978ec68ccae7b8637171c5ac826117c0610c52565b86866040518563ffffffff1660e01b81526004016117e194939291906143e4565b602060405180830381865af41580156117fc573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906118209190614426565b1561182d5761182d612f02565b505050565b60605f61183d612dcc565b600a810180546040805160208084028201810190925282815293945083018282801561189057602002820191905f5260205f20905b81546001600160a01b03168152600190910190602001808311611872575b505050505091505090565b5f6118a4613019565b805490915060ff600160401b82041615906001600160401b03165f811580156118ca5750825b90505f826001600160401b031660011480156118e55750303b155b9050811580156118f3575080155b156119115760405163f92ee8a960e01b815260040160405180910390fd5b845467ffffffffffffffff19166001178555831561193b57845460ff60401b1916600160401b1785555b61194486613041565b61194c61319e565b831561199257845460ff60401b19168555604051600181527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a15b505050505050565b6040805160c08101825260608082525f6020830181905292820183905281018290526080810182905260a08101829052906119d3612dcc565b9050806001015f8481526020019081526020015f206040518060c00160405290815f82018054611a02906140e7565b80601f0160208091040260200160405190810160405280929190818152602001828054611a2e906140e7565b8015611a795780601f10611a5057610100808354040283529160200191611a79565b820191905f5260205f20905b815481529060010190602001808311611a5c57829003601f168201915b505050918352505060018201546001600160a01b038116602083015260ff600160a01b8204811615156040840152600160a81b8204811615156060840152600160b01b909104161515608082015260029091015460a0909101529392505050565b5f5f611ae4612dcc565b6001600160a01b039093165f90815260039093016020525050604090205490565b611b0d612e73565b5f611b16612dcc565b604051637fea851b60e01b815290915073d9695208188b9bfa05061ec99a978ec68ccae7b890637fea851b906117e190849087908790600401614445565b60608060608060608060605f611b68612dcc565b90505f611b7782600701612df0565b8051909150806001600160401b03811115611b9457611b94613701565b604051908082528060200260200182016040528015611bc757816020015b6060815260200190600190039081611bb25790505b509950806001600160401b03811115611be257611be2613701565b604051908082528060200260200182016040528015611c0b578160200160208202803683370190505b509850806001600160401b03811115611c2657611c26613701565b604051908082528060200260200182016040528015611c4f578160200160208202803683370190505b509750806001600160401b03811115611c6a57611c6a613701565b604051908082528060200260200182016040528015611c93578160200160208202803683370190505b509650806001600160401b03811115611cae57611cae613701565b604051908082528060200260200182016040528015611cd7578160200160208202803683370190505b509550806001600160401b03811115611cf257611cf2613701565b604051908082528060200260200182016040528015611d2557816020015b6060815260200190600190039081611d105790505b509450806001600160401b03811115611d4057611d40613701565b604051908082528060200260200182016040528015611d69578160200160208202803683370190505b5093505f611d75610c52565b6001600160a01b031663878571d76040518163ffffffff1660e01b8152600401602060405180830381865afa158015611db0573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611dd49190614475565b90505f5b828110156120d0575f856001015f868481518110611df857611df861411f565b602002602001015181526020019081526020015f206040518060c00160405290815f82018054611e27906140e7565b80601f0160208091040260200160405190810160405280929190818152602001828054611e53906140e7565b8015611e9e5780601f10611e7557610100808354040283529160200191611e9e565b820191905f5260205f20905b815481529060010190602001808311611e8157829003601f168201915b505050918352505060018201546001600160a01b038116602083015260ff600160a01b8204811615156040840152600160a81b8204811615156060840152600160b01b909104161515608082015260029091015460a09091015280518e51919250908e9084908110611f1257611f1261411f565b602002602001018190525080604001518c8381518110611f3457611f3461411f565b60200260200101901515908115158152505080606001518b8381518110611f5d57611f5d61411f565b60200260200101901515908115158152505080608001518a8381518110611f8657611f8661411f565b6020026020010190151590811515815250508060a00151898381518110611faf57611faf61411f565b602090810291909101015260a081015160405163c87b56dd60e01b815260048101919091526001600160a01b0384169063c87b56dd906024015f60405180830381865afa158015612002573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f1916820160405261202991908101906144dd565b88838151811061203b5761203b61411f565b602002602001018190525080602001516001600160a01b031663190024e06040518163ffffffff1660e01b8152600401602060405180830381865afa158015612086573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906120aa9190614133565b8783815181106120bc576120bc61411f565b602090810291909101015250600101611dd8565b505050505090919293949596565b5f73d9695208188b9bfa05061ec99a978ec68ccae7b863e551e36a612101610c52565b846040518363ffffffff1660e01b815260040161211f92919061450e565b602060405180830381865af415801561213a573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906105579190614133565b612166612e03565b5f61216f612dcc565b6001600160a01b0383165f90815260048201602052604090205490915060ff166121ac576040516359935c8f60e11b815260040160405180910390fd5b604051630a1cb54360e41b8152600481018290526001600160a01b038316602482015273d9695208188b9bfa05061ec99a978ec68ccae7b89063a1cb543090604401610bc1565b5f5f6121fd612e73565b5f612206612dcc565b905061228c604080516101e08101909152606061014082019081525f610160830181905261018083018190526101a083018190526101c0830152819081526020015f81526020015f6001600160a01b0316815260200160608152602001606081526020016060815260200160608152602001606081526020015f81526020015f81525090565b815f015f8c6040516020016122a19190614377565b6040516020818303038152906040528051906020012081526020019081526020015f206040518060a00160405290815f820180546122de906140e7565b80601f016020809104026020016040519081016040528092919081815260200182805461230a906140e7565b80156123555780601f1061232c57610100808354040283529160200191612355565b820191905f5260205f20905b81548152906001019060200180831161233857829003601f168201915b505050918352505060018201546001600160a01b0380821660208085019190915260ff600160a01b8404811615156040860152600160a81b909304909216151560608401526002909301546080909201919091528284529190910151166123cf57604051634b94d18160e11b815260040160405180910390fd5b89516020808c0191909120908201526123e6610c52565b6001600160a01b039081166040808401919091526020808401515f90815260018087019092529190912090810154909116612434576040516303022b7560e11b815260040160405180910390fd5b5f7383a2764961ec7ce166fac7c8f4fd371ea45cb2d363500937666040518163ffffffff1660e01b8152600401602060405180830381865af415801561247c573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906124a09190614475565b9050806001600160a01b031663cc316e998e6040518263ffffffff1660e01b81526004016124ce9190613d7b565b5f604051808303815f87803b1580156124e5575f5ffd5b505af11580156124f7573d5f5f3e3d5ffd5b505050505f7383a2764961ec7ce166fac7c8f4fd371ea45cb2d363bcea050b6040518163ffffffff1660e01b8152600401602060405180830381865af4158015612543573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906125679190614475565b9050806001600160a01b031663670855198e6040518263ffffffff1660e01b81526004016125959190613d7b565b5f604051808303815f87803b1580156125ac575f5ffd5b505af11580156125be573d5f5f3e3d5ffd5b50508b519398509196505f91506125d89050826002614531565b6001600160401b038111156125ef576125ef613701565b604051908082528060200260200182016040528015612618578160200160208202803683370190505b5090508360400151815f815181106126325761263261411f565b60200260200101906001600160a01b031690816001600160a01b03168152505086816001815181106126665761266661411f565b6001600160a01b039092166020928302919091019091015260025b61268c836002614531565b8110156126e9578a61269f60028361415e565b815181106126af576126af61411f565b60200260200101518282815181106126c9576126c961411f565b6001600160a01b0390921660209283029190910190910152600101612681565b50604051630835ffd760e31b81526001600160a01b038716906341affeb89061271a9084908d908d90600401614544565b5f604051808303815f87803b158015612731575f5ffd5b505af1158015612743573d5f5f3e3d5ffd5b505050506127568e8e8e8e8e8e8e611086565b61010085018190525f9081526002860160205260409020546001600160a01b0316156127a75783610100015160405163db7e59bd60e01b815260040161279e91815260200190565b60405180910390fd5b50506127db8c855f8d51116127bc575f612d2b565b8c5f815181106127ce576127ce61411f565b6020026020010151612d2b565b60e087015260c08601526080850181905260608501919091526040516303bf572560e31b815273d9695208188b9bfa05061ec99a978ec68ccae7b8925063d0d34fa4918f918f917300d737941f0f5f629d85c12426a1a9e4ea05675991631dfab9289161284a91600401614586565b5f60405180830381865af4158015612864573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f1916820160405261288b91908101906144dd565b8660c001518f6040518663ffffffff1660e01b81526004016128b1959493929190614604565b5f60405180830381865af41580156128cb573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f191682016040526128f291908101906144dd565b8260a0018190525081604001516001600160a01b0316638a4adf246040518163ffffffff1660e01b8152600401602060405180830381865afa15801561293a573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061295e9190614475565b60405163ee1fe2ad60e01b81523360048201526001600160a01b038781166024830152919091169063ee1fe2ad906044016020604051808303815f875af11580156129ab573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906129cf9190614133565b61012083019081526040805160e08082018352828601516001600160a01b039081168352888116602084015260a080880151848601529187015160608401529351608083015281018d905260c081018c9052905163a50c8dd160e01b81529187169163a50c8dd191612a4391600401614664565b5f604051808303815f87803b158015612a5a575f5ffd5b505af1158015612a6c573d5f5f3e3d5ffd5b5050505082600a0185908060018154018082558091505060019003905f5260205f20015f9091909190916101000a8154816001600160a01b0302191690836001600160a01b031602179055506001836003015f876001600160a01b03166001600160a01b031681526020019081526020015f20819055506001836004015f866001600160a01b03166001600160a01b031681526020019081526020015f205f6101000a81548160ff02191690831515021790555084836002015f84610100015181526020019081526020015f205f6101000a8154816001600160a01b0302191690836001600160a01b03160217905550336001600160a01b03167fe16a12ed0c6ee928f7ee5c5799175c728255adae06a81e8bec85c9d909af61338d8d88888760a001518860e0015189606001518a61010001518b6101200151604051612bbb99989796959493929190614710565b60405180910390a250505097509795505050505050565b612bda612e73565b5f612be3612dcc565b82519091505f5b81811015612ce75782600b01848281518110612c0857612c0861411f565b6020908102919091018101518254600180820185555f9485529383902082516007909202019081559181015192820180546001600160a01b0319166001600160a01b039094169390931790925560408201516002820190612c6990826141b5565b5060608201518051612c8591600384019160209091019061324d565b5060808201518051612ca191600484019160209091019061324d565b5060a08201518051612cbd9160058401916020909101906132b0565b5060c08201518051612cd99160068401916020909101906132e9565b505050806001019050612bea565b507fad29862e9f0d865f275139a684250d15b3351b00a75fdfae159b837289c19bf5836040516110799190613d18565b5f5f612d21612dcc565b600b015492915050565b606080606080606073240bfa20cca1e995be47c0c0253a27e72ca8295d63046bcb50898989612d58610c52565b6040518563ffffffff1660e01b8152600401612d7794939291906147a3565b5f60405180830381865af4158015612d91573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f19168201604052612db891908101906148c0565b939c929b5090995097509095509350505050565b7f94b53192a2415b53b438d03f0efa946204c0118192627e3d5ed4ba034c9a030090565b60605f612dfc836131ae565b9392505050565b7f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00805460011901612e4757604051633ee5aeb560e01b815260040160405180910390fd5b60029055565b60017f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f0055565b612e7b610c52565b6040516336b87bd760e11b81523360048201526001600160a01b039190911690636d70f7ae90602401602060405180830381865afa158015612ebf573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612ee39190614426565b612f0057604051631f0853c160e21b815260040160405180910390fd5b565b5f612f0b610c52565b9050336001600160a01b0316816001600160a01b0316635aa6e6756040518163ffffffff1660e01b8152600401602060405180830381865afa158015612f53573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612f779190614475565b6001600160a01b03161480612ffc5750336001600160a01b0316816001600160a01b0316634783c35b6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612fcd573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612ff19190614475565b6001600160a01b0316145b610c17576040516354299b6f60e01b815260040160405180910390fd5b5f807ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00610557565b613049613207565b6001600160a01b038116158015906130d257505f6001600160a01b0316816001600160a01b0316634783c35b6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156130a2573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906130c69190614475565b6001600160a01b031614155b6130ef576040516371c42ac360e01b815260040160405180910390fd5b61312261311d60017faa116a42804728f23983458454b6eb9c6ddf3011db9f9addaf3cd7508d85b0d661415e565b829055565b6131544361315160017f812a673dfca07956350df10f8a654925f561d7a0da09bdbe79e653939a14d9f161415e565b55565b604080516001600160a01b0383168152426020820152438183015290517f1a2dd071001ebf6e03174e3df5b305795a4ad5d41d8fdb9ba41dbbe2367134269181900360600190a150565b6131a6613207565b612f0061322c565b6060815f018054806020026020016040519081016040528092919081815260200182805480156131fb57602002820191905f5260205f20905b8154815260200190600101908083116131e7575b50505050509050919050565b61320f613234565b612f0057604051631afcd79f60e31b815260040160405180910390fd5b612e4d613207565b5f61323d613019565b54600160401b900460ff16919050565b828054828255905f5260205f209081019282156132a0579160200282015b828111156132a057825182546001600160a01b0319166001600160a01b0390911617825560209092019160019091019061326b565b506132ac92915061338c565b5090565b828054828255905f5260205f209081019282156132a0579160200282015b828111156132a05782518255916020019190600101906132ce565b828054828255905f5260205f2090600901600a900481019282156132a0579160200282015f5b8382111561335457835183826101000a81548162ffffff021916908360020b62ffffff160217905550926020019260030160208160020104928301926001030261330f565b80156133835782816101000a81549062ffffff0219169055600301602081600201049283019260010302613354565b50506132ac9291505b5b808211156132ac575f815560010161338d565b5f602082840312156133b0575f5ffd5b81356001600160e01b031981168114612dfc575f5ffd5b5f8151808452602084019350602083015f5b828110156133f75781518652602095860195909101906001016133d9565b5093949350505050565b602081525f612dfc60208301846133c7565b5f60208284031215613423575f5ffd5b5035919050565b5f81518084528060208401602086015e5f602082860101526020601f19601f83011685010191505092915050565b60a081525f61346a60a083018861342a565b6001600160a01b039690961660208301525092151560408401529015156060830152608090910152919050565b6001600160a01b0381168114610c17575f5ffd5b80356134b681613497565b919050565b5f602082840312156134cb575f5ffd5b8135612dfc81613497565b5f82825180855260208501945060208160051b830101602085015f5b8381101561352457601f1985840301885261350e83835161342a565b60209889019890935091909101906001016134f2565b50909695505050505050565b5f8151808452602084019350602083015f5b828110156133f75781516001600160a01b0316865260209586019590910190600101613542565b5f8151808452602084019350602083015f5b828110156133f7578151151586526020958601959091019060010161357b565b60c081525f6135ad60c08301896134d6565b82810360208401526135bf8189613530565b905082810360408401526135d38188613569565b905082810360608401526135e78187613569565b905082810360808401526135fb81866133c7565b905082810360a084015261360f81856133c7565b9998505050505050505050565b5f8151808452602084019350602083015f5b828110156133f757815160020b86526020958601959091019060010161362e565b8051825260018060a01b0360208201511660208301525f604082015160e0604085015261367f60e085018261342a565b9050606083015184820360608601526136988282613530565b915050608083015184820360808601526136b28282613530565b91505060a083015184820360a08601526136cc82826133c7565b91505060c083015184820360c08601526136e6828261361c565b95945050505050565b602081525f612dfc602083018461364f565b634e487b7160e01b5f52604160045260245ffd5b60405160e081016001600160401b038111828210171561373757613737613701565b60405290565b604051606081016001600160401b038111828210171561373757613737613701565b604051601f8201601f191681016001600160401b038111828210171561378757613787613701565b604052919050565b5f6001600160401b038211156137a7576137a7613701565b50601f01601f191660200190565b5f82601f8301126137c4575f5ffd5b81356137d76137d28261378f565b61375f565b8181528460208386010111156137eb575f5ffd5b816020850160208301375f918101602001919091529392505050565b5f6001600160401b0382111561381f5761381f613701565b5060051b60200190565b5f82601f830112613838575f5ffd5b81356138466137d282613807565b8082825260208201915060208360051b860101925085831115613867575f5ffd5b602085015b8381101561388d57803561387f81613497565b83526020928301920161386c565b5095945050505050565b5f82601f8301126138a6575f5ffd5b81356138b46137d282613807565b8082825260208201915060208360051b8601019250858311156138d5575f5ffd5b602085015b8381101561388d5780358352602092830192016138da565b5f82601f830112613901575f5ffd5b813561390f6137d282613807565b8082825260208201915060208360051b860101925085831115613930575f5ffd5b602085015b8381101561388d5780358060020b811461394d575f5ffd5b835260209283019201613935565b5f60e0828403121561396b575f5ffd5b613973613715565b823581529050613985602083016134ab565b602082015260408201356001600160401b038111156139a2575f5ffd5b6139ae848285016137b5565b60408301525060608201356001600160401b038111156139cc575f5ffd5b6139d884828501613829565b60608301525060808201356001600160401b038111156139f6575f5ffd5b613a0284828501613829565b60808301525060a08201356001600160401b03811115613a20575f5ffd5b613a2c84828501613897565b60a08301525060c08201356001600160401b03811115613a4a575f5ffd5b613a56848285016138f2565b60c08301525092915050565b5f5f60408385031215613a73575f5ffd5b8235915060208301356001600160401b03811115613a8f575f5ffd5b613a9b8582860161395b565b9150509250929050565b5f5f5f5f5f5f5f60e0888a031215613abb575f5ffd5b87356001600160401b03811115613ad0575f5ffd5b613adc8a828b016137b5565b97505060208801356001600160401b03811115613af7575f5ffd5b613b038a828b016137b5565b96505060408801356001600160401b03811115613b1e575f5ffd5b613b2a8a828b01613829565b95505060608801356001600160401b03811115613b45575f5ffd5b613b518a828b01613897565b94505060808801356001600160401b03811115613b6c575f5ffd5b613b788a828b01613829565b93505060a08801356001600160401b03811115613b93575f5ffd5b613b9f8a828b01613897565b92505060c08801356001600160401b03811115613bba575f5ffd5b613bc68a828b016138f2565b91505092959891949750929550565b5f5f60408385031215613be6575f5ffd5b82356001600160401b03811115613bfb575f5ffd5b613c07858286016137b5565b92505060208301356001600160401b03811115613c22575f5ffd5b830160608186031215613c33575f5ffd5b613c3b61373d565b81356001600160401b03811115613c50575f5ffd5b613c5c87828501613829565b82525060208201356001600160401b03811115613c77575f5ffd5b613c8387828501613897565b60208301525060408201356001600160401b03811115613ca1575f5ffd5b613cad878285016138f2565b60408301525080925050509250929050565b5f5f60408385031215613cd0575f5ffd5b82356001600160401b03811115613ce5575f5ffd5b613cf185828601613829565b92505060208301356001600160401b03811115613d0c575f5ffd5b613a9b85828601613897565b5f602082016020835280845180835260408501915060408160051b8601019250602086015f5b82811015613d6f57603f19878603018452613d5a85835161364f565b94506020938401939190910190600101613d3e565b50929695505050505050565b602081525f612dfc602083018461342a565b602081525f825160606020840152613da86080840182613530565b90506020840151601f19848303016040850152613dc582826133c7565b9150506040840151601f198483030160608501526136e6828261361c565b5f5f60408385031215613df4575f5ffd5b82356001600160401b03811115613e09575f5ffd5b613e15858286016137b5565b9250506020830135613e2681613497565b809150509250929050565b602081525f612dfc6020830184613530565b602081525f825160c06020840152613e5e60e084018261342a565b905060018060a01b0360208501511660408401526040840151151560608401526060840151151560808401526080840151151560a084015260a084015160c08401528091505092915050565b60e081525f613ebc60e083018a6134d6565b8281036020840152613ece818a613569565b90508281036040840152613ee28189613569565b90508281036060840152613ef68188613569565b90508281036080840152613f0a81876133c7565b905082810360a0840152613f1e81866134d6565b905082810360c0840152613f3281856133c7565b9a9950505050505050505050565b5f60208284031215613f50575f5ffd5b81356001600160401b03811115613f65575f5ffd5b613f7184828501613829565b949350505050565b5f60208284031215613f89575f5ffd5b81356001600160401b03811115613f9e575f5ffd5b8201601f81018413613fae575f5ffd5b8035613fbc6137d282613807565b8082825260208201915060208360051b850101925086831115613fdd575f5ffd5b602084015b8381101561401d5780356001600160401b03811115613fff575f5ffd5b61400e8960208389010161395b565b84525060209283019201613fe2565b509695505050505050565b5f5f5f6060848603121561403a575f5ffd5b83356001600160401b0381111561404f575f5ffd5b61405b868287016137b5565b935050602084013561406c81613497565b9150604084013561407c81613497565b809150509250925092565b60a081525f61409960a083018861342a565b82810360208401526140ab8188613530565b905082810360408401526140bf81876134d6565b905082810360608401526140d3818661342a565b90508281036080840152611133818561342a565b600181811c908216806140fb57607f821691505b60208210810361411957634e487b7160e01b5f52602260045260245ffd5b50919050565b634e487b7160e01b5f52603260045260245ffd5b5f60208284031215614143575f5ffd5b5051919050565b634e487b7160e01b5f52601160045260245ffd5b818103818111156105575761055761414a565b601f82111561182d57805f5260205f20601f840160051c810160208510156141965750805b601f840160051c820191505b81811015611322575f81556001016141a2565b81516001600160401b038111156141ce576141ce613701565b6141e2816141dc84546140e7565b84614171565b6020601f821160018114614214575f83156141fd5750848201515b5f19600385901b1c1916600184901b178455611322565b5f84815260208120601f198516915b828110156142435787850151825560209485019460019092019101614223565b508482101561426057868401515f19600387901b60f8161c191681555b50505050600190811b01905550565b828152604060208201525f613f71604083018461364f565b805f5b60058110156142ac57815160ff1684526020938401939091019060010161428a565b50505050565b61018081525f6142c661018083018b61342a565b82810360208401526142d8818b61342a565b905082810360408401526142ec818a613530565b9050828103606084015261430081896133c7565b905082810360808401526143148188613530565b905082810360a084015261432881876133c7565b83810360c0850152855180825260208088019350909101905f5b8181101561436357835160020b835260209384019390920191600101614342565b5050809250505061360f60e0830184614287565b5f82518060208501845e5f920191825250919050565b608081525f61439f608083018761342a565b82810360208401526143b18187613530565b905082810360408401526143c581866133c7565b905082810360608401526143d9818561361c565b979650505050505050565b8481526001600160a01b03841660208201526080604082018190525f9061440d9083018561342a565b905060018060a01b038316606083015295945050505050565b5f60208284031215614436575f5ffd5b81518015158114612dfc575f5ffd5b838152606060208201525f61445d606083018561342a565b905060018060a01b0383166040830152949350505050565b5f60208284031215614485575f5ffd5b8151612dfc81613497565b5f82601f83011261449f575f5ffd5b81516144ad6137d28261378f565b8181528460208386010111156144c1575f5ffd5b8160208501602083015e5f918101602001919091529392505050565b5f602082840312156144ed575f5ffd5b81516001600160401b03811115614502575f5ffd5b613f7184828501614490565b6001600160a01b03831681526040602082018190525f90613f7190830184613530565b808201808211156105575761055761414a565b606081525f6145566060830186613530565b828103602084015261456881866133c7565b9050828103604084015261457c818561361c565b9695505050505050565b5f604082016040835280845180835260608501915060608160051b8601019250602086015f5b828110156145dd57605f198786030184526145c885835161342a565b945060209384019391909101906001016145ac565b50505050828103602084015260018152602d60f81b60208201526040810191505092915050565b60a081525f61461660a083018861342a565b8281036020840152614628818861342a565b9050828103604084015261463c818761342a565b90508281036060840152614650818661342a565b905082810360808401526111338185613530565b602080825282516001600160a01b0316828201528201515f9061469260408401826001600160a01b03169052565b50604083015160e060608401526146ad61010084018261342a565b90506060840151601f198483030160808501526146ca828261342a565b915050608084015160a084015260a0840151601f198483030160c08501526146f28282613530565b91505060c0840151601f198483030160e08501526136e682826133c7565b61012081525f61472461012083018c61342a565b8281036020840152614736818c61342a565b6001600160a01b038b811660408601528a16606085015283810360808501529050614761818961342a565b905082810360a0840152614775818861342a565b905082810360c08401526147898187613530565b60e084019590955250506101000152979650505050505050565b608081525f6147b5608083018761342a565b6001600160a01b0395861660208401529385166040830152509216606090920191909152919050565b5f82601f8301126147ed575f5ffd5b81516147fb6137d282613807565b8082825260208201915060208360051b86010192508583111561481c575f5ffd5b602085015b8381101561388d57805161483481613497565b835260209283019201614821565b5f82601f830112614851575f5ffd5b815161485f6137d282613807565b8082825260208201915060208360051b860101925085831115614880575f5ffd5b602085015b8381101561388d5780516001600160401b038111156148a2575f5ffd5b6148b1886020838a0101614490565b84525060209283019201614885565b5f5f5f5f5f60a086880312156148d4575f5ffd5b85516001600160401b038111156148e9575f5ffd5b6148f588828901614490565b95505060208601516001600160401b03811115614910575f5ffd5b61491c888289016147de565b94505060408601516001600160401b03811115614937575f5ffd5b61494388828901614842565b93505060608601516001600160401b0381111561495e575f5ffd5b61496a88828901614490565b92505060808601516001600160401b03811115614985575f5ffd5b61499188828901614490565b915050929550929590935056fea2646970667358221220ada1742af5a68adced2ae839a4964c01955929d95afd137b723a7b6ae11309cd64736f6c634300081c0033

Deployed Bytecode

0x608060405234801561000f575f5ffd5b50600436106101f2575f3560e01c806389ec7a4111610114578063d6f51d62116100a9578063dd7ff3db11610079578063dd7ff3db14610491578063e967f16b146104c4578063f378d1d4146104d7578063f583734e146104df578063ffa1ad7414610503575f5ffd5b8063d6f51d621461043d578063d9f9027f14610450578063db22d7a01461046b578063dcc805181461047e575f5ffd5b8063b2d96884116100e4578063b2d96884146103e2578063c4d66de8146103f7578063c56ebcd61461040a578063d0cf00541461042a575f5ffd5b806389ec7a411461036b578063936725ec1461037e5780639ad87ce4146103af578063b1b1402a146103cf575f5ffd5b80634bde38c81161018a5780636c2713a31161015a5780636c2713a31461031d5780637031c482146103305780637d474fa314610343578063871fd68214610356575f5ffd5b80634bde38c8146102b7578063538a85a1146102d7578063582a4d37146102f757806358a2ab1c1461030a575f5ffd5b80632e8ebaae116101c55780632e8ebaae1461026d57806336abf3dc146102805780633adc774e1461029a5780634593144c146102af575f5ffd5b806301ffc9a7146101f65780630d9c8bcd1461021e5780630f038dcd1461023457806314e4380c14610249575b5f5ffd5b6102096102043660046133a0565b610527565b60405190151581526020015b60405180910390f35b61022661055d565b604051908152602001610215565b61023c610571565b6040516102159190613401565b61025c610257366004613413565b610590565b604051610215959493929190613458565b61020961027b3660046134bb565b6106c3565b6102886106f0565b6040516102159695949392919061359b565b6102ad6102a83660046134bb565b610b30565b005b610226610c1a565b6102bf610c52565b6040516001600160a01b039091168152602001610215565b6102ea6102e5366004613413565b610c81565b60405161021591906136ef565b6102ad610305366004613a62565b610f5c565b610226610318366004613aa5565b611086565b6102ad61032b366004613bd5565b61113f565b6102ad61033e366004613cbf565b611229565b6102bf610351366004613413565b611329565b61035e611350565b6040516102159190613d18565b6102bf610379366004613413565b6115f5565b6103a260405180604001604052806005815260200164312e302e3160d81b81525081565b6040516102159190613d7b565b6103c26103bd366004613413565b611631565b6040516102159190613d8d565b6102ad6103dd366004613de3565b61178a565b6103ea611832565b6040516102159190613e31565b6102ad6104053660046134bb565b61189b565b61041d610418366004613413565b61199a565b6040516102159190613e43565b6102266104383660046134bb565b611ada565b6102ad61044b366004613de3565b611b05565b610458611b54565b6040516102159796959493929190613eaa565b610226610479366004613f40565b6120de565b6102ad61048c3660046134bb565b61215e565b6104a461049f366004613aa5565b6121f3565b604080516001600160a01b03938416815292909116602083015201610215565b6102ad6104d2366004613f79565b612bd2565b610226612d17565b6104f26104ed366004614028565b612d2b565b604051610215959493929190614087565b6103a2604051806040016040528060058152602001640322e302e360dc1b81525081565b5f6001600160e01b03198216630f1ec81f60e41b148061055757506301ffc9a760e01b6001600160e01b03198316145b92915050565b5f5f610567612dcc565b600a015492915050565b60605f61057c612dcc565b905061058a81600701612df0565b91505090565b60605f5f5f5f5f61059f612dcc565b90505f815f015f8981526020019081526020015f206040518060a00160405290815f820180546105ce906140e7565b80601f01602080910402602001604051908101604052809291908181526020018280546105fa906140e7565b80156106455780601f1061061c57610100808354040283529160200191610645565b820191905f5260205f20905b81548152906001019060200180831161062857829003601f168201915b505050918352505060018201546001600160a01b03811660208084019190915260ff600160a01b830481161515604080860191909152600160a81b90930416151560608085019190915260029094015460809384015284519085015191850151938501519490920151919c909b509199509197509095509350505050565b5f6106cc612dcc565b6001600160a01b039092165f90815260049290920160205250604090205460ff1690565b6060806060806060805f610702612dcc565b90505f61071182600501612df0565b8051909150806001600160401b0381111561072e5761072e613701565b60405190808252806020026020018201604052801561076157816020015b606081526020019060019003908161074c5790505b509850806001600160401b0381111561077c5761077c613701565b6040519080825280602002602001820160405280156107a5578160200160208202803683370190505b509750806001600160401b038111156107c0576107c0613701565b6040519080825280602002602001820160405280156107e9578160200160208202803683370190505b509650806001600160401b0381111561080457610804613701565b60405190808252806020026020018201604052801561082d578160200160208202803683370190505b509550806001600160401b0381111561084857610848613701565b604051908082528060200260200182016040528015610871578160200160208202803683370190505b509450806001600160401b0381111561088c5761088c613701565b6040519080825280602002602001820160405280156108b5578160200160208202803683370190505b5093505f5b81811015610b24575f845f015f8584815181106108d9576108d961411f565b602002602001015181526020019081526020015f206040518060a00160405290815f82018054610908906140e7565b80601f0160208091040260200160405190810160405280929190818152602001828054610934906140e7565b801561097f5780601f106109565761010080835404028352916020019161097f565b820191905f5260205f20905b81548152906001019060200180831161096257829003601f168201915b505050918352505060018201546001600160a01b038116602083015260ff600160a01b8204811615156040840152600160a81b909104161515606082015260029091015460809091015280518c51919250908c90849081106109e3576109e361411f565b602002602001018190525080602001518a8381518110610a0557610a0561411f565b60200260200101906001600160a01b031690816001600160a01b0316815250508060400151898381518110610a3c57610a3c61411f565b6020026020010190151590811515815250508060600151888381518110610a6557610a6561411f565b6020026020010190151590811515815250508060800151878381518110610a8e57610a8e61411f565b60200260200101818152505080602001516001600160a01b031663190024e06040518163ffffffff1660e01b8152600401602060405180830381865afa158015610ada573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610afe9190614133565b868381518110610b1057610b1061411f565b6020908102919091010152506001016108ba565b50505050909192939495565b610b38612e03565b5f610b41612dcc565b6001600160a01b0383165f908152600382016020526040902054909150600114610b7e57604051630d7abd6f60e31b815260040160405180910390fd5b604051637817605360e01b8152600481018290526001600160a01b038316602482015273d9695208188b9bfa05061ec99a978ec68ccae7b8906378176053906044015b5f6040518083038186803b158015610bd7575f5ffd5b505af4158015610be9573d5f5f3e3d5ffd5b5050505050610c1760017f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f0055565b50565b5f610c4d610c4960017f812a673dfca07956350df10f8a654925f561d7a0da09bdbe79e653939a14d9f161415e565b5490565b905090565b5f610c4d610c4960017faa116a42804728f23983458454b6eb9c6ddf3011db9f9addaf3cd7508d85b0d661415e565b610cc86040518060e001604052805f81526020015f6001600160a01b0316815260200160608152602001606081526020016060815260200160608152602001606081525090565b5f610cd1612dcc565b905080600b018381548110610ce857610ce861411f565b905f5260205f2090600702016040518060e00160405290815f8201548152602001600182015f9054906101000a90046001600160a01b03166001600160a01b03166001600160a01b03168152602001600282018054610d46906140e7565b80601f0160208091040260200160405190810160405280929190818152602001828054610d72906140e7565b8015610dbd5780601f10610d9457610100808354040283529160200191610dbd565b820191905f5260205f20905b815481529060010190602001808311610da057829003601f168201915b5050505050815260200160038201805480602002602001604051908101604052809291908181526020018280548015610e1d57602002820191905f5260205f20905b81546001600160a01b03168152600190910190602001808311610dff575b5050505050815260200160048201805480602002602001604051908101604052809291908181526020018280548015610e7d57602002820191905f5260205f20905b81546001600160a01b03168152600190910190602001808311610e5f575b5050505050815260200160058201805480602002602001604051908101604052809291908181526020018280548015610ed357602002820191905f5260205f20905b815481526020019060010190808311610ebf575b5050505050815260200160068201805480602002602001604051908101604052809291908181526020018280548015610f4b57602002820191905f5260205f20905f905b825461010083900a900460020b8152602060058301819004938401936001036003909301929092029101808411610f175790505b505050505081525050915050919050565b610f64612e73565b5f610f6d612dcc565b90508181600b018481548110610f8557610f8561411f565b5f918252602091829020835160079290920201908155908201516001820180546001600160a01b0319166001600160a01b0390921691909117905560408201516002820190610fd490826141b5565b5060608201518051610ff091600384019160209091019061324d565b506080820151805161100c91600484019160209091019061324d565b5060a082015180516110289160058401916020909101906132b0565b5060c082015180516110449160068401916020909101906132e9565b509050507f4e8499c72391533d62e187d3f07fc288fbc1742c8e094f36b5e23b836bb29e89838360405161107992919061426f565b60405180910390a1505050565b6040805160a08101825260018082525f602083018190528284018290526060830191909152608082018190529151636c309d4f60e11b815273d9695208188b9bfa05061ec99a978ec68ccae7b89163d8613a9e916110f4918c918c918c918c918c918c918c916004016142b2565b602060405180830381865af415801561110f573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906111339190614133565b98975050505050505050565b611147612e73565b5f611150612dcc565b90505f836040516020016111649190614377565b60408051601f1981840301815291815281516020928301205f818152600c860184529190912085518051929450869391926111a2928492019061324d565b5060208281015180516111bb92600185019201906132b0565b50604082015180516111d79160028401916020909101906132e9565b509050507fba197f5223035cb2b7a0f09844df05667b65b529665865bd98232748de75970b84845f01518560200151866040015160405161121b949392919061438d565b60405180910390a150505050565b611231612f02565b5f61123a612dcc565b83519091505f5b818110156113225783818151811061125b5761125b61411f565b6020026020010151836003015f87848151811061127a5761127a61411f565b60200260200101516001600160a01b03166001600160a01b031681526020019081526020015f20819055508481815181106112b7576112b761411f565b60200260200101516001600160a01b03167fd518071c0dca755922e3df4b2f1457ed64340814d52371e060a067edd0a9578a8583815181106112fb576112fb61411f565b602002602001015160405161131291815260200190565b60405180910390a2600101611241565b5050505050565b5f5f611333612dcc565b5f938452600201602052505060409020546001600160a01b031690565b60605f61135b612dcc565b600b81018054604080516020808402820181019092528281529394505f9084015b828210156115eb575f8481526020908190206040805160e081018252600786029092018054835260018101546001600160a01b031693830193909352600283018054929392918401916113ce906140e7565b80601f01602080910402602001604051908101604052809291908181526020018280546113fa906140e7565b80156114455780601f1061141c57610100808354040283529160200191611445565b820191905f5260205f20905b81548152906001019060200180831161142857829003601f168201915b50505050508152602001600382018054806020026020016040519081016040528092919081815260200182805480156114a557602002820191905f5260205f20905b81546001600160a01b03168152600190910190602001808311611487575b505050505081526020016004820180548060200260200160405190810160405280929190818152602001828054801561150557602002820191905f5260205f20905b81546001600160a01b031681526001909101906020018083116114e7575b505050505081526020016005820180548060200260200160405190810160405280929190818152602001828054801561155b57602002820191905f5260205f20905b815481526020019060010190808311611547575b50505050508152602001600682018054806020026020016040519081016040528092919081815260200182805480156115d357602002820191905f5260205f20905f905b825461010083900a900460020b815260206005830181900493840193600103600390930192909202910180841161159f5790505b5050505050815250508152602001906001019061137c565b5050505091505090565b5f5f6115ff612dcc565b905080600a0183815481106116165761161661411f565b5f918252602090912001546001600160a01b03169392505050565b61165560405180606001604052806060815260200160608152602001606081525090565b5f61165e612dcc565b5f848152600c82016020908152604091829020825181546080938102820184019094526060810184815294955093909284928491908401828280156116ca57602002820191905f5260205f20905b81546001600160a01b031681526001909101906020018083116116ac575b505050505081526020016001820180548060200260200160405190810160405280929190818152602001828054801561172057602002820191905f5260205f20905b81548152602001906001019080831161170c575b5050505050815260200160028201805480602002602001604051908101604052809291908181526020018280548015610f4b575f918252602091829020805460020b8452908202830192909160039101808411610f17579050505050505081525050915050919050565b611792612e73565b5f61179b612dcc565b905073d9695208188b9bfa05061ec99a978ec68ccae7b8637171c5ac826117c0610c52565b86866040518563ffffffff1660e01b81526004016117e194939291906143e4565b602060405180830381865af41580156117fc573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906118209190614426565b1561182d5761182d612f02565b505050565b60605f61183d612dcc565b600a810180546040805160208084028201810190925282815293945083018282801561189057602002820191905f5260205f20905b81546001600160a01b03168152600190910190602001808311611872575b505050505091505090565b5f6118a4613019565b805490915060ff600160401b82041615906001600160401b03165f811580156118ca5750825b90505f826001600160401b031660011480156118e55750303b155b9050811580156118f3575080155b156119115760405163f92ee8a960e01b815260040160405180910390fd5b845467ffffffffffffffff19166001178555831561193b57845460ff60401b1916600160401b1785555b61194486613041565b61194c61319e565b831561199257845460ff60401b19168555604051600181527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a15b505050505050565b6040805160c08101825260608082525f6020830181905292820183905281018290526080810182905260a08101829052906119d3612dcc565b9050806001015f8481526020019081526020015f206040518060c00160405290815f82018054611a02906140e7565b80601f0160208091040260200160405190810160405280929190818152602001828054611a2e906140e7565b8015611a795780601f10611a5057610100808354040283529160200191611a79565b820191905f5260205f20905b815481529060010190602001808311611a5c57829003601f168201915b505050918352505060018201546001600160a01b038116602083015260ff600160a01b8204811615156040840152600160a81b8204811615156060840152600160b01b909104161515608082015260029091015460a0909101529392505050565b5f5f611ae4612dcc565b6001600160a01b039093165f90815260039093016020525050604090205490565b611b0d612e73565b5f611b16612dcc565b604051637fea851b60e01b815290915073d9695208188b9bfa05061ec99a978ec68ccae7b890637fea851b906117e190849087908790600401614445565b60608060608060608060605f611b68612dcc565b90505f611b7782600701612df0565b8051909150806001600160401b03811115611b9457611b94613701565b604051908082528060200260200182016040528015611bc757816020015b6060815260200190600190039081611bb25790505b509950806001600160401b03811115611be257611be2613701565b604051908082528060200260200182016040528015611c0b578160200160208202803683370190505b509850806001600160401b03811115611c2657611c26613701565b604051908082528060200260200182016040528015611c4f578160200160208202803683370190505b509750806001600160401b03811115611c6a57611c6a613701565b604051908082528060200260200182016040528015611c93578160200160208202803683370190505b509650806001600160401b03811115611cae57611cae613701565b604051908082528060200260200182016040528015611cd7578160200160208202803683370190505b509550806001600160401b03811115611cf257611cf2613701565b604051908082528060200260200182016040528015611d2557816020015b6060815260200190600190039081611d105790505b509450806001600160401b03811115611d4057611d40613701565b604051908082528060200260200182016040528015611d69578160200160208202803683370190505b5093505f611d75610c52565b6001600160a01b031663878571d76040518163ffffffff1660e01b8152600401602060405180830381865afa158015611db0573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611dd49190614475565b90505f5b828110156120d0575f856001015f868481518110611df857611df861411f565b602002602001015181526020019081526020015f206040518060c00160405290815f82018054611e27906140e7565b80601f0160208091040260200160405190810160405280929190818152602001828054611e53906140e7565b8015611e9e5780601f10611e7557610100808354040283529160200191611e9e565b820191905f5260205f20905b815481529060010190602001808311611e8157829003601f168201915b505050918352505060018201546001600160a01b038116602083015260ff600160a01b8204811615156040840152600160a81b8204811615156060840152600160b01b909104161515608082015260029091015460a09091015280518e51919250908e9084908110611f1257611f1261411f565b602002602001018190525080604001518c8381518110611f3457611f3461411f565b60200260200101901515908115158152505080606001518b8381518110611f5d57611f5d61411f565b60200260200101901515908115158152505080608001518a8381518110611f8657611f8661411f565b6020026020010190151590811515815250508060a00151898381518110611faf57611faf61411f565b602090810291909101015260a081015160405163c87b56dd60e01b815260048101919091526001600160a01b0384169063c87b56dd906024015f60405180830381865afa158015612002573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f1916820160405261202991908101906144dd565b88838151811061203b5761203b61411f565b602002602001018190525080602001516001600160a01b031663190024e06040518163ffffffff1660e01b8152600401602060405180830381865afa158015612086573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906120aa9190614133565b8783815181106120bc576120bc61411f565b602090810291909101015250600101611dd8565b505050505090919293949596565b5f73d9695208188b9bfa05061ec99a978ec68ccae7b863e551e36a612101610c52565b846040518363ffffffff1660e01b815260040161211f92919061450e565b602060405180830381865af415801561213a573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906105579190614133565b612166612e03565b5f61216f612dcc565b6001600160a01b0383165f90815260048201602052604090205490915060ff166121ac576040516359935c8f60e11b815260040160405180910390fd5b604051630a1cb54360e41b8152600481018290526001600160a01b038316602482015273d9695208188b9bfa05061ec99a978ec68ccae7b89063a1cb543090604401610bc1565b5f5f6121fd612e73565b5f612206612dcc565b905061228c604080516101e08101909152606061014082019081525f610160830181905261018083018190526101a083018190526101c0830152819081526020015f81526020015f6001600160a01b0316815260200160608152602001606081526020016060815260200160608152602001606081526020015f81526020015f81525090565b815f015f8c6040516020016122a19190614377565b6040516020818303038152906040528051906020012081526020019081526020015f206040518060a00160405290815f820180546122de906140e7565b80601f016020809104026020016040519081016040528092919081815260200182805461230a906140e7565b80156123555780601f1061232c57610100808354040283529160200191612355565b820191905f5260205f20905b81548152906001019060200180831161233857829003601f168201915b505050918352505060018201546001600160a01b0380821660208085019190915260ff600160a01b8404811615156040860152600160a81b909304909216151560608401526002909301546080909201919091528284529190910151166123cf57604051634b94d18160e11b815260040160405180910390fd5b89516020808c0191909120908201526123e6610c52565b6001600160a01b039081166040808401919091526020808401515f90815260018087019092529190912090810154909116612434576040516303022b7560e11b815260040160405180910390fd5b5f7383a2764961ec7ce166fac7c8f4fd371ea45cb2d363500937666040518163ffffffff1660e01b8152600401602060405180830381865af415801561247c573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906124a09190614475565b9050806001600160a01b031663cc316e998e6040518263ffffffff1660e01b81526004016124ce9190613d7b565b5f604051808303815f87803b1580156124e5575f5ffd5b505af11580156124f7573d5f5f3e3d5ffd5b505050505f7383a2764961ec7ce166fac7c8f4fd371ea45cb2d363bcea050b6040518163ffffffff1660e01b8152600401602060405180830381865af4158015612543573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906125679190614475565b9050806001600160a01b031663670855198e6040518263ffffffff1660e01b81526004016125959190613d7b565b5f604051808303815f87803b1580156125ac575f5ffd5b505af11580156125be573d5f5f3e3d5ffd5b50508b519398509196505f91506125d89050826002614531565b6001600160401b038111156125ef576125ef613701565b604051908082528060200260200182016040528015612618578160200160208202803683370190505b5090508360400151815f815181106126325761263261411f565b60200260200101906001600160a01b031690816001600160a01b03168152505086816001815181106126665761266661411f565b6001600160a01b039092166020928302919091019091015260025b61268c836002614531565b8110156126e9578a61269f60028361415e565b815181106126af576126af61411f565b60200260200101518282815181106126c9576126c961411f565b6001600160a01b0390921660209283029190910190910152600101612681565b50604051630835ffd760e31b81526001600160a01b038716906341affeb89061271a9084908d908d90600401614544565b5f604051808303815f87803b158015612731575f5ffd5b505af1158015612743573d5f5f3e3d5ffd5b505050506127568e8e8e8e8e8e8e611086565b61010085018190525f9081526002860160205260409020546001600160a01b0316156127a75783610100015160405163db7e59bd60e01b815260040161279e91815260200190565b60405180910390fd5b50506127db8c855f8d51116127bc575f612d2b565b8c5f815181106127ce576127ce61411f565b6020026020010151612d2b565b60e087015260c08601526080850181905260608501919091526040516303bf572560e31b815273d9695208188b9bfa05061ec99a978ec68ccae7b8925063d0d34fa4918f918f917300d737941f0f5f629d85c12426a1a9e4ea05675991631dfab9289161284a91600401614586565b5f60405180830381865af4158015612864573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f1916820160405261288b91908101906144dd565b8660c001518f6040518663ffffffff1660e01b81526004016128b1959493929190614604565b5f60405180830381865af41580156128cb573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f191682016040526128f291908101906144dd565b8260a0018190525081604001516001600160a01b0316638a4adf246040518163ffffffff1660e01b8152600401602060405180830381865afa15801561293a573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061295e9190614475565b60405163ee1fe2ad60e01b81523360048201526001600160a01b038781166024830152919091169063ee1fe2ad906044016020604051808303815f875af11580156129ab573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906129cf9190614133565b61012083019081526040805160e08082018352828601516001600160a01b039081168352888116602084015260a080880151848601529187015160608401529351608083015281018d905260c081018c9052905163a50c8dd160e01b81529187169163a50c8dd191612a4391600401614664565b5f604051808303815f87803b158015612a5a575f5ffd5b505af1158015612a6c573d5f5f3e3d5ffd5b5050505082600a0185908060018154018082558091505060019003905f5260205f20015f9091909190916101000a8154816001600160a01b0302191690836001600160a01b031602179055506001836003015f876001600160a01b03166001600160a01b031681526020019081526020015f20819055506001836004015f866001600160a01b03166001600160a01b031681526020019081526020015f205f6101000a81548160ff02191690831515021790555084836002015f84610100015181526020019081526020015f205f6101000a8154816001600160a01b0302191690836001600160a01b03160217905550336001600160a01b03167fe16a12ed0c6ee928f7ee5c5799175c728255adae06a81e8bec85c9d909af61338d8d88888760a001518860e0015189606001518a61010001518b6101200151604051612bbb99989796959493929190614710565b60405180910390a250505097509795505050505050565b612bda612e73565b5f612be3612dcc565b82519091505f5b81811015612ce75782600b01848281518110612c0857612c0861411f565b6020908102919091018101518254600180820185555f9485529383902082516007909202019081559181015192820180546001600160a01b0319166001600160a01b039094169390931790925560408201516002820190612c6990826141b5565b5060608201518051612c8591600384019160209091019061324d565b5060808201518051612ca191600484019160209091019061324d565b5060a08201518051612cbd9160058401916020909101906132b0565b5060c08201518051612cd99160068401916020909101906132e9565b505050806001019050612bea565b507fad29862e9f0d865f275139a684250d15b3351b00a75fdfae159b837289c19bf5836040516110799190613d18565b5f5f612d21612dcc565b600b015492915050565b606080606080606073240bfa20cca1e995be47c0c0253a27e72ca8295d63046bcb50898989612d58610c52565b6040518563ffffffff1660e01b8152600401612d7794939291906147a3565b5f60405180830381865af4158015612d91573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f19168201604052612db891908101906148c0565b939c929b5090995097509095509350505050565b7f94b53192a2415b53b438d03f0efa946204c0118192627e3d5ed4ba034c9a030090565b60605f612dfc836131ae565b9392505050565b7f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00805460011901612e4757604051633ee5aeb560e01b815260040160405180910390fd5b60029055565b60017f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f0055565b612e7b610c52565b6040516336b87bd760e11b81523360048201526001600160a01b039190911690636d70f7ae90602401602060405180830381865afa158015612ebf573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612ee39190614426565b612f0057604051631f0853c160e21b815260040160405180910390fd5b565b5f612f0b610c52565b9050336001600160a01b0316816001600160a01b0316635aa6e6756040518163ffffffff1660e01b8152600401602060405180830381865afa158015612f53573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612f779190614475565b6001600160a01b03161480612ffc5750336001600160a01b0316816001600160a01b0316634783c35b6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612fcd573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612ff19190614475565b6001600160a01b0316145b610c17576040516354299b6f60e01b815260040160405180910390fd5b5f807ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00610557565b613049613207565b6001600160a01b038116158015906130d257505f6001600160a01b0316816001600160a01b0316634783c35b6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156130a2573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906130c69190614475565b6001600160a01b031614155b6130ef576040516371c42ac360e01b815260040160405180910390fd5b61312261311d60017faa116a42804728f23983458454b6eb9c6ddf3011db9f9addaf3cd7508d85b0d661415e565b829055565b6131544361315160017f812a673dfca07956350df10f8a654925f561d7a0da09bdbe79e653939a14d9f161415e565b55565b604080516001600160a01b0383168152426020820152438183015290517f1a2dd071001ebf6e03174e3df5b305795a4ad5d41d8fdb9ba41dbbe2367134269181900360600190a150565b6131a6613207565b612f0061322c565b6060815f018054806020026020016040519081016040528092919081815260200182805480156131fb57602002820191905f5260205f20905b8154815260200190600101908083116131e7575b50505050509050919050565b61320f613234565b612f0057604051631afcd79f60e31b815260040160405180910390fd5b612e4d613207565b5f61323d613019565b54600160401b900460ff16919050565b828054828255905f5260205f209081019282156132a0579160200282015b828111156132a057825182546001600160a01b0319166001600160a01b0390911617825560209092019160019091019061326b565b506132ac92915061338c565b5090565b828054828255905f5260205f209081019282156132a0579160200282015b828111156132a05782518255916020019190600101906132ce565b828054828255905f5260205f2090600901600a900481019282156132a0579160200282015f5b8382111561335457835183826101000a81548162ffffff021916908360020b62ffffff160217905550926020019260030160208160020104928301926001030261330f565b80156133835782816101000a81549062ffffff0219169055600301602081600201049283019260010302613354565b50506132ac9291505b5b808211156132ac575f815560010161338d565b5f602082840312156133b0575f5ffd5b81356001600160e01b031981168114612dfc575f5ffd5b5f8151808452602084019350602083015f5b828110156133f75781518652602095860195909101906001016133d9565b5093949350505050565b602081525f612dfc60208301846133c7565b5f60208284031215613423575f5ffd5b5035919050565b5f81518084528060208401602086015e5f602082860101526020601f19601f83011685010191505092915050565b60a081525f61346a60a083018861342a565b6001600160a01b039690961660208301525092151560408401529015156060830152608090910152919050565b6001600160a01b0381168114610c17575f5ffd5b80356134b681613497565b919050565b5f602082840312156134cb575f5ffd5b8135612dfc81613497565b5f82825180855260208501945060208160051b830101602085015f5b8381101561352457601f1985840301885261350e83835161342a565b60209889019890935091909101906001016134f2565b50909695505050505050565b5f8151808452602084019350602083015f5b828110156133f75781516001600160a01b0316865260209586019590910190600101613542565b5f8151808452602084019350602083015f5b828110156133f7578151151586526020958601959091019060010161357b565b60c081525f6135ad60c08301896134d6565b82810360208401526135bf8189613530565b905082810360408401526135d38188613569565b905082810360608401526135e78187613569565b905082810360808401526135fb81866133c7565b905082810360a084015261360f81856133c7565b9998505050505050505050565b5f8151808452602084019350602083015f5b828110156133f757815160020b86526020958601959091019060010161362e565b8051825260018060a01b0360208201511660208301525f604082015160e0604085015261367f60e085018261342a565b9050606083015184820360608601526136988282613530565b915050608083015184820360808601526136b28282613530565b91505060a083015184820360a08601526136cc82826133c7565b91505060c083015184820360c08601526136e6828261361c565b95945050505050565b602081525f612dfc602083018461364f565b634e487b7160e01b5f52604160045260245ffd5b60405160e081016001600160401b038111828210171561373757613737613701565b60405290565b604051606081016001600160401b038111828210171561373757613737613701565b604051601f8201601f191681016001600160401b038111828210171561378757613787613701565b604052919050565b5f6001600160401b038211156137a7576137a7613701565b50601f01601f191660200190565b5f82601f8301126137c4575f5ffd5b81356137d76137d28261378f565b61375f565b8181528460208386010111156137eb575f5ffd5b816020850160208301375f918101602001919091529392505050565b5f6001600160401b0382111561381f5761381f613701565b5060051b60200190565b5f82601f830112613838575f5ffd5b81356138466137d282613807565b8082825260208201915060208360051b860101925085831115613867575f5ffd5b602085015b8381101561388d57803561387f81613497565b83526020928301920161386c565b5095945050505050565b5f82601f8301126138a6575f5ffd5b81356138b46137d282613807565b8082825260208201915060208360051b8601019250858311156138d5575f5ffd5b602085015b8381101561388d5780358352602092830192016138da565b5f82601f830112613901575f5ffd5b813561390f6137d282613807565b8082825260208201915060208360051b860101925085831115613930575f5ffd5b602085015b8381101561388d5780358060020b811461394d575f5ffd5b835260209283019201613935565b5f60e0828403121561396b575f5ffd5b613973613715565b823581529050613985602083016134ab565b602082015260408201356001600160401b038111156139a2575f5ffd5b6139ae848285016137b5565b60408301525060608201356001600160401b038111156139cc575f5ffd5b6139d884828501613829565b60608301525060808201356001600160401b038111156139f6575f5ffd5b613a0284828501613829565b60808301525060a08201356001600160401b03811115613a20575f5ffd5b613a2c84828501613897565b60a08301525060c08201356001600160401b03811115613a4a575f5ffd5b613a56848285016138f2565b60c08301525092915050565b5f5f60408385031215613a73575f5ffd5b8235915060208301356001600160401b03811115613a8f575f5ffd5b613a9b8582860161395b565b9150509250929050565b5f5f5f5f5f5f5f60e0888a031215613abb575f5ffd5b87356001600160401b03811115613ad0575f5ffd5b613adc8a828b016137b5565b97505060208801356001600160401b03811115613af7575f5ffd5b613b038a828b016137b5565b96505060408801356001600160401b03811115613b1e575f5ffd5b613b2a8a828b01613829565b95505060608801356001600160401b03811115613b45575f5ffd5b613b518a828b01613897565b94505060808801356001600160401b03811115613b6c575f5ffd5b613b788a828b01613829565b93505060a08801356001600160401b03811115613b93575f5ffd5b613b9f8a828b01613897565b92505060c08801356001600160401b03811115613bba575f5ffd5b613bc68a828b016138f2565b91505092959891949750929550565b5f5f60408385031215613be6575f5ffd5b82356001600160401b03811115613bfb575f5ffd5b613c07858286016137b5565b92505060208301356001600160401b03811115613c22575f5ffd5b830160608186031215613c33575f5ffd5b613c3b61373d565b81356001600160401b03811115613c50575f5ffd5b613c5c87828501613829565b82525060208201356001600160401b03811115613c77575f5ffd5b613c8387828501613897565b60208301525060408201356001600160401b03811115613ca1575f5ffd5b613cad878285016138f2565b60408301525080925050509250929050565b5f5f60408385031215613cd0575f5ffd5b82356001600160401b03811115613ce5575f5ffd5b613cf185828601613829565b92505060208301356001600160401b03811115613d0c575f5ffd5b613a9b85828601613897565b5f602082016020835280845180835260408501915060408160051b8601019250602086015f5b82811015613d6f57603f19878603018452613d5a85835161364f565b94506020938401939190910190600101613d3e565b50929695505050505050565b602081525f612dfc602083018461342a565b602081525f825160606020840152613da86080840182613530565b90506020840151601f19848303016040850152613dc582826133c7565b9150506040840151601f198483030160608501526136e6828261361c565b5f5f60408385031215613df4575f5ffd5b82356001600160401b03811115613e09575f5ffd5b613e15858286016137b5565b9250506020830135613e2681613497565b809150509250929050565b602081525f612dfc6020830184613530565b602081525f825160c06020840152613e5e60e084018261342a565b905060018060a01b0360208501511660408401526040840151151560608401526060840151151560808401526080840151151560a084015260a084015160c08401528091505092915050565b60e081525f613ebc60e083018a6134d6565b8281036020840152613ece818a613569565b90508281036040840152613ee28189613569565b90508281036060840152613ef68188613569565b90508281036080840152613f0a81876133c7565b905082810360a0840152613f1e81866134d6565b905082810360c0840152613f3281856133c7565b9a9950505050505050505050565b5f60208284031215613f50575f5ffd5b81356001600160401b03811115613f65575f5ffd5b613f7184828501613829565b949350505050565b5f60208284031215613f89575f5ffd5b81356001600160401b03811115613f9e575f5ffd5b8201601f81018413613fae575f5ffd5b8035613fbc6137d282613807565b8082825260208201915060208360051b850101925086831115613fdd575f5ffd5b602084015b8381101561401d5780356001600160401b03811115613fff575f5ffd5b61400e8960208389010161395b565b84525060209283019201613fe2565b509695505050505050565b5f5f5f6060848603121561403a575f5ffd5b83356001600160401b0381111561404f575f5ffd5b61405b868287016137b5565b935050602084013561406c81613497565b9150604084013561407c81613497565b809150509250925092565b60a081525f61409960a083018861342a565b82810360208401526140ab8188613530565b905082810360408401526140bf81876134d6565b905082810360608401526140d3818661342a565b90508281036080840152611133818561342a565b600181811c908216806140fb57607f821691505b60208210810361411957634e487b7160e01b5f52602260045260245ffd5b50919050565b634e487b7160e01b5f52603260045260245ffd5b5f60208284031215614143575f5ffd5b5051919050565b634e487b7160e01b5f52601160045260245ffd5b818103818111156105575761055761414a565b601f82111561182d57805f5260205f20601f840160051c810160208510156141965750805b601f840160051c820191505b81811015611322575f81556001016141a2565b81516001600160401b038111156141ce576141ce613701565b6141e2816141dc84546140e7565b84614171565b6020601f821160018114614214575f83156141fd5750848201515b5f19600385901b1c1916600184901b178455611322565b5f84815260208120601f198516915b828110156142435787850151825560209485019460019092019101614223565b508482101561426057868401515f19600387901b60f8161c191681555b50505050600190811b01905550565b828152604060208201525f613f71604083018461364f565b805f5b60058110156142ac57815160ff1684526020938401939091019060010161428a565b50505050565b61018081525f6142c661018083018b61342a565b82810360208401526142d8818b61342a565b905082810360408401526142ec818a613530565b9050828103606084015261430081896133c7565b905082810360808401526143148188613530565b905082810360a084015261432881876133c7565b83810360c0850152855180825260208088019350909101905f5b8181101561436357835160020b835260209384019390920191600101614342565b5050809250505061360f60e0830184614287565b5f82518060208501845e5f920191825250919050565b608081525f61439f608083018761342a565b82810360208401526143b18187613530565b905082810360408401526143c581866133c7565b905082810360608401526143d9818561361c565b979650505050505050565b8481526001600160a01b03841660208201526080604082018190525f9061440d9083018561342a565b905060018060a01b038316606083015295945050505050565b5f60208284031215614436575f5ffd5b81518015158114612dfc575f5ffd5b838152606060208201525f61445d606083018561342a565b905060018060a01b0383166040830152949350505050565b5f60208284031215614485575f5ffd5b8151612dfc81613497565b5f82601f83011261449f575f5ffd5b81516144ad6137d28261378f565b8181528460208386010111156144c1575f5ffd5b8160208501602083015e5f918101602001919091529392505050565b5f602082840312156144ed575f5ffd5b81516001600160401b03811115614502575f5ffd5b613f7184828501614490565b6001600160a01b03831681526040602082018190525f90613f7190830184613530565b808201808211156105575761055761414a565b606081525f6145566060830186613530565b828103602084015261456881866133c7565b9050828103604084015261457c818561361c565b9695505050505050565b5f604082016040835280845180835260608501915060608160051b8601019250602086015f5b828110156145dd57605f198786030184526145c885835161342a565b945060209384019391909101906001016145ac565b50505050828103602084015260018152602d60f81b60208201526040810191505092915050565b60a081525f61461660a083018861342a565b8281036020840152614628818861342a565b9050828103604084015261463c818761342a565b90508281036060840152614650818661342a565b905082810360808401526111338185613530565b602080825282516001600160a01b0316828201528201515f9061469260408401826001600160a01b03169052565b50604083015160e060608401526146ad61010084018261342a565b90506060840151601f198483030160808501526146ca828261342a565b915050608084015160a084015260a0840151601f198483030160c08501526146f28282613530565b91505060c0840151601f198483030160e08501526136e682826133c7565b61012081525f61472461012083018c61342a565b8281036020840152614736818c61342a565b6001600160a01b038b811660408601528a16606085015283810360808501529050614761818961342a565b905082810360a0840152614775818861342a565b905082810360c08401526147898187613530565b60e084019590955250506101000152979650505050505050565b608081525f6147b5608083018761342a565b6001600160a01b0395861660208401529385166040830152509216606090920191909152919050565b5f82601f8301126147ed575f5ffd5b81516147fb6137d282613807565b8082825260208201915060208360051b86010192508583111561481c575f5ffd5b602085015b8381101561388d57805161483481613497565b835260209283019201614821565b5f82601f830112614851575f5ffd5b815161485f6137d282613807565b8082825260208201915060208360051b860101925085831115614880575f5ffd5b602085015b8381101561388d5780516001600160401b038111156148a2575f5ffd5b6148b1886020838a0101614490565b84525060209283019201614885565b5f5f5f5f5f60a086880312156148d4575f5ffd5b85516001600160401b038111156148e9575f5ffd5b6148f588828901614490565b95505060208601516001600160401b03811115614910575f5ffd5b61491c888289016147de565b94505060408601516001600160401b03811115614937575f5ffd5b61494388828901614842565b93505060608601516001600160401b0381111561495e575f5ffd5b61496a88828901614490565b92505060808601516001600160401b03811115614985575f5ffd5b61499188828901614490565b915050929550929590935056fea2646970667358221220ada1742af5a68adced2ae839a4964c01955929d95afd137b723a7b6ae11309cd64736f6c634300081c0033

Block Transaction Gas Used Reward
view all blocks ##produced##

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

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading

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