ETH Price: $3,768.80 (-13.32%)

Contract

0xE59870870286Aec8e2e10e7A09d15D7113312f94

Overview

ETH Balance

0 ETH

ETH Value

$0.00

More Info

Private Name Tags

Multichain Info

N/A
Transaction Hash
Method
Block
From
To
New Strategy132829712025-10-09 16:03:0240 hrs ago1760025782IN
0xE5987087...113312f94
0 ETH0.000005710.001
New Strategy130521722025-10-06 23:56:234 days ago1759794983IN
0xE5987087...113312f94
0 ETH0.000001370.00099996
New Strategy130517032025-10-06 23:48:344 days ago1759794514IN
0xE5987087...113312f94
0 ETH0.00000570.00099996
New Strategy130516792025-10-06 23:48:104 days ago1759794490IN
0xE5987087...113312f94
0 ETH0.00000570.001
Set Addresses130341002025-10-06 18:55:114 days ago1759776911IN
0xE5987087...113312f94
0 ETH0.000001350.00000026
New Strategy53307762025-07-09 15:06:2793 days ago1752073587IN
0xE5987087...113312f94
0 ETH0.000000020.00000271
New Strategy53307762025-07-09 15:06:2793 days ago1752073587IN
0xE5987087...113312f94
0 ETH0.000000020.00000271
New Strategy53307762025-07-09 15:06:2793 days ago1752073587IN
0xE5987087...113312f94
0 ETH0.000000020.00000271
New Strategy53307762025-07-09 15:06:2793 days ago1752073587IN
0xE5987087...113312f94
0 ETH0.000000020.00000271
New Strategy51715612025-07-07 18:52:5295 days ago1751914372IN
0xE5987087...113312f94
0 ETH0.000000020.00000463
New Strategy51715612025-07-07 18:52:5295 days ago1751914372IN
0xE5987087...113312f94
0 ETH0.000000020.00000463
New Strategy51711652025-07-07 18:46:1695 days ago1751913976IN
0xE5987087...113312f94
0 ETH0.000000010.00000093
New Strategy51711652025-07-07 18:46:1695 days ago1751913976IN
0xE5987087...113312f94
0 ETH0.000000010.00000093
New Strategy51692452025-07-07 18:14:1695 days ago1751912056IN
0xE5987087...113312f94
0 ETH0.000000010.00000026
New Strategy51692452025-07-07 18:14:1695 days ago1751912056IN
0xE5987087...113312f94
0 ETH0.000000010.00000026
New Strategy51692452025-07-07 18:14:1695 days ago1751912056IN
0xE5987087...113312f94
0 ETH0.000000010.00000026
New Strategy51692452025-07-07 18:14:1695 days ago1751912056IN
0xE5987087...113312f94
0 ETH0.000000010.00000026
New Strategy51692452025-07-07 18:14:1695 days ago1751912056IN
0xE5987087...113312f94
0 ETH0.000000010.00000026
New Strategy51692452025-07-07 18:14:1695 days ago1751912056IN
0xE5987087...113312f94
0 ETH0.000000010.00000026
New Strategy47309052025-07-02 16:28:36100 days ago1751473716IN
0xE5987087...113312f94
0 ETH0.000000960.00021551
New Strategy47309052025-07-02 16:28:36100 days ago1751473716IN
0xE5987087...113312f94
0 ETH0.000000960.00021551

Latest 25 internal transactions (View All)

Advanced mode:
Parent Transaction Hash Block From To
132829712025-10-09 16:03:0240 hrs ago1760025782
0xE5987087...113312f94
0 ETH
132829712025-10-09 16:03:0240 hrs ago1760025782
0xE5987087...113312f94
0 ETH
132829712025-10-09 16:03:0240 hrs ago1760025782
0xE5987087...113312f94
0 ETH
132829712025-10-09 16:03:0240 hrs ago1760025782
0xE5987087...113312f94
0 ETH
132829712025-10-09 16:03:0240 hrs ago1760025782
0xE5987087...113312f94
 Contract Creation0 ETH
130517032025-10-06 23:48:344 days ago1759794514
0xE5987087...113312f94
0 ETH
130517032025-10-06 23:48:344 days ago1759794514
0xE5987087...113312f94
0 ETH
130517032025-10-06 23:48:344 days ago1759794514
0xE5987087...113312f94
0 ETH
130517032025-10-06 23:48:344 days ago1759794514
0xE5987087...113312f94
0 ETH
130517032025-10-06 23:48:344 days ago1759794514
0xE5987087...113312f94
 Contract Creation0 ETH
130516792025-10-06 23:48:104 days ago1759794490
0xE5987087...113312f94
0 ETH
130516792025-10-06 23:48:104 days ago1759794490
0xE5987087...113312f94
0 ETH
130516792025-10-06 23:48:104 days ago1759794490
0xE5987087...113312f94
0 ETH
130516792025-10-06 23:48:104 days ago1759794490
0xE5987087...113312f94
0 ETH
130516792025-10-06 23:48:104 days ago1759794490
0xE5987087...113312f94
 Contract Creation0 ETH
53307762025-07-09 15:06:2793 days ago1752073587
0xE5987087...113312f94
0 ETH
53307762025-07-09 15:06:2793 days ago1752073587
0xE5987087...113312f94
0 ETH
53307762025-07-09 15:06:2793 days ago1752073587
0xE5987087...113312f94
0 ETH
53307762025-07-09 15:06:2793 days ago1752073587
0xE5987087...113312f94
0 ETH
53307762025-07-09 15:06:2793 days ago1752073587
0xE5987087...113312f94
 Contract Creation0 ETH
53307762025-07-09 15:06:2793 days ago1752073587
0xE5987087...113312f94
0 ETH
53307762025-07-09 15:06:2793 days ago1752073587
0xE5987087...113312f94
0 ETH
53307762025-07-09 15:06:2793 days ago1752073587
0xE5987087...113312f94
0 ETH
53307762025-07-09 15:06:2793 days ago1752073587
0xE5987087...113312f94
0 ETH
53307762025-07-09 15:06:2793 days ago1752073587
0xE5987087...113312f94
 Contract Creation0 ETH
View All Internal Transactions

Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
StrategyFactory

Compiler Version
v0.8.23+commit.f704f362

Optimization Enabled:
Yes with 1000000 runs

Other Settings:
shanghai EvmVersion, GNU AGPLv3 license
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.18;

import {Strategy} from "./Strategy.sol";
import {IStrategyInterface} from "./interfaces/IStrategyInterface.sol";

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

contract StrategyFactory {
    using EnumerableSet for EnumerableSet.AddressSet;

    event NewStrategy(
        address indexed strategy,
        address indexed asset,
        address indexed lp
    );

    address public immutable emergencyAdmin;

    address public management;
    address public performanceFeeRecipient;
    address public keeper;

    /// @notice Track the deployments asset => lp => strategy
    mapping(address => mapping(address => address)) private _deploymentMapping;
    EnumerableSet.AddressSet private _deployments;

    constructor(
        address _management,
        address _performanceFeeRecipient,
        address _keeper,
        address _emergencyAdmin
    ) {
        management = _management;
        performanceFeeRecipient = _performanceFeeRecipient;
        keeper = _keeper;
        emergencyAdmin = _emergencyAdmin;
    }

    /**
     * @notice Deploys a new Strategy.
     * @param _asset The underlying asset for the strategy to use
     * @param _name The name for the strategy
     * @param _steerLP The Steer LP contract address
     * @param _minAsset Minimum asset amount for any operation (dust threshold)
     * @param _maxSwapValue Maximum value that can be swapped in a single transaction
     * @return The address of the new strategy
     */
    function newStrategy(
        address _asset,
        string calldata _name,
        address _steerLP,
        uint128 _minAsset,
        uint256 _maxSwapValue
    ) external virtual returns (address) {
        require(_deploymentMapping[_asset][_steerLP] == address(0), "!new");

        // tokenized strategies available setters.
        IStrategyInterface _newStrategy = IStrategyInterface(
            address(
                new Strategy(_asset, _name, _steerLP, _minAsset, _maxSwapValue)
            )
        );
        _deployments.add(address(_newStrategy));
        _deploymentMapping[_asset][_steerLP] = address(_newStrategy);

        _newStrategy.setPerformanceFeeRecipient(performanceFeeRecipient);
        _newStrategy.setKeeper(keeper);
        _newStrategy.setPendingManagement(management);
        _newStrategy.setEmergencyAdmin(emergencyAdmin);

        emit NewStrategy(address(_newStrategy), _asset, _steerLP);

        return address(_newStrategy);
    }

    /**
     * @notice Sets the factory addresses
     * @param _management New management address
     * @param _performanceFeeRecipient New performance fee recipient address
     * @param _keeper New keeper address
     */
    function setAddresses(
        address _management,
        address _performanceFeeRecipient,
        address _keeper
    ) external {
        require(msg.sender == management, "!management");
        management = _management;
        performanceFeeRecipient = _performanceFeeRecipient;
        keeper = _keeper;
    }

    function deployments() external view returns (address[] memory) {
        return _deployments.values();
    }

    /**
     * @notice Checks if a strategy was deployed by this factory
     * @param _strategy The strategy address to check
     * @return Whether the strategy was deployed by this factory
     */
    function isDeployedStrategy(
        address _strategy
    ) external view returns (bool) {
        return _deployments.contains(_strategy);
    }

    function getStrategyForAssetLpPair(
        address _asset,
        address _lp
    ) external view returns (address _strategy) {
        return _deploymentMapping[_asset][_lp];
    }
}

File 2 of 43 : Strategy.sol
// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.18;

import {BaseHealthCheck, ERC20} from "@periphery/Bases/HealthCheck/BaseHealthCheck.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {ISushiMultiPositionLiquidityManager} from "./interfaces/steer/ISushiMultiPositionLiquidityManager.sol";
import {IUniswapV3SwapCallback} from "@uniswap-v3-core/interfaces/callback/IUniswapV3SwapCallback.sol";
import {IUniswapV3Pool} from "@uniswap-v3-core/interfaces/IUniswapV3Pool.sol";
import {FullMath} from "@uniswap-v3-core/libraries/FullMath.sol";
import {TickMath} from "@uniswap-v3-core/libraries/TickMath.sol";
import {IAuction} from "./interfaces/IAuction.sol";
import {IMerklDistributor} from "./interfaces/IMerklDistributor.sol";

contract Strategy is BaseHealthCheck, IUniswapV3SwapCallback {
    using SafeERC20 for ERC20;

    /*//////////////////////////////////////////////////////////////
                            CONSTANTS
    //////////////////////////////////////////////////////////////*/

    // Q96 constant (2**96)
    uint256 private constant Q96 = 0x1000000000000000000000000;

    /// @notice The Merkl Distributor contract for claiming rewards
    IMerklDistributor public constant MERKL_DISTRIBUTOR =
        IMerklDistributor(0x3Ef3D8bA38EBe18DB133cEc108f4D14CE00Dd9Ae);

    /*//////////////////////////////////////////////////////////////
                          IMMUTABLE VARIABLES
    //////////////////////////////////////////////////////////////*/

    ISushiMultiPositionLiquidityManager public immutable STEER_LP;
    address private immutable _POOL;
    address private immutable _PAIRED_TOKEN;
    bool private immutable _ASSET_IS_TOKEN_0;

    /*//////////////////////////////////////////////////////////////
                          STATE VARIABLES
    //////////////////////////////////////////////////////////////*/

    /// @notice Flag to enable using auctions for token swaps
    bool public useAuctions;

    /// @notice Address of the auction contract used for token swaps
    address public auction;

    /// @notice Target idle asset in basis points
    uint16 public targetIdleAssetBps;

    /// @notice Buffer for target idle asset in basis points (e.g., 1000 = 10% buffer)
    uint16 public targetIdleBufferBps = 1000; // 10% default

    /// @notice Additional discount applied to paired token valuations in basis points
    uint16 public pairedTokenDiscountBps = 50; // 0.5% default

    /// @notice Maximum acceptable base fee for tends in gwei
    uint8 public maxTendBaseFeeGwei = 100;

    /// @notice Minimum wait time between tends in seconds
    uint24 public minTendWait = 5 minutes;

    /// @notice Timestamp of the last tend
    uint64 public lastTend;

    /// @notice Minimum asset amount for any operation (dust threshold)
    uint128 public minAsset;

    /// @notice The strategy deposit limit
    uint256 public depositLimit = type(uint256).max;

    /// @notice Maximum value that can be swapped in a single transaction (in asset terms)
    uint256 public maxSwapValue;

    /*//////////////////////////////////////////////////////////////
                              STRUCTS
    //////////////////////////////////////////////////////////////*/

    struct SwapCallbackData {
        address tokenToPay;
        uint256 amountToPay;
    }

    constructor(
        address _asset,
        string memory _name,
        address _steerLP,
        uint128 _minAsset,
        uint256 _maxSwapValue
    ) BaseHealthCheck(_asset, _name) {
        require(_steerLP != address(0), "!0");
        STEER_LP = ISushiMultiPositionLiquidityManager(_steerLP);
        _POOL = ISushiMultiPositionLiquidityManager(_steerLP).pool();
        address _token0 = ISushiMultiPositionLiquidityManager(_steerLP)
            .token0();
        address _token1 = ISushiMultiPositionLiquidityManager(_steerLP)
            .token1();
        if (address(asset) == _token0) {
            _ASSET_IS_TOKEN_0 = true;
            _PAIRED_TOKEN = _token1;
        } else {
            require(address(asset) == _token1, "!asset");
            _PAIRED_TOKEN = _token0;
        }

        minAsset = _minAsset;
        maxSwapValue = _maxSwapValue;
    }

    /*//////////////////////////////////////////////////////////////
                         BASE STRATEGY OVERRIDES
    //////////////////////////////////////////////////////////////*/

    // @inheritdoc BaseStrategy
    function _deployFunds(uint256 _amount) internal override {
        // do nothing since a swap is required
    }

    // @inheritdoc BaseStrategy
    function _freeFunds(uint256 _amount) internal override {
        // do nothing since a swap is required
    }

    // @inheritdoc BaseStrategy
    function _harvestAndReport()
        internal
        override
        returns (uint256 _totalAssets)
    {
        // Update fees before calculating total assets
        STEER_LP.poke();
        _totalAssets = estimatedTotalAsset();
    }

    // @inheritdoc BaseStrategy
    function _tend(uint256 _totalIdle) internal override {
        // Update fees before any LP operations
        STEER_LP.poke();

        uint256 _targetIdleAssetBps = uint256(targetIdleAssetBps);
        uint256 _minAsset = uint256(minAsset);

        if (_targetIdleAssetBps > 0) {
            // We have a target idle, check if we need to rebalance
            uint256 targetIdleAmount = _getTargetIdleAmount(
                _targetIdleAssetBps
            );

            if (_totalIdle > targetIdleAmount) {
                // Check if excess is above minAsset threshold
                uint256 excess = _totalIdle - targetIdleAmount;
                if (excess >= _minAsset) {
                    _depositInLp();
                }
            } else if (_totalIdle < targetIdleAmount) {
                // Check if deficit is above minAsset threshold
                uint256 deficit = targetIdleAmount - _totalIdle;
                if (deficit >= _minAsset) {
                    _withdrawFromLp(deficit);
                }
            }
        } else if (_totalIdle >= _minAsset) {
            // No target set, deposit idle assets if above threshold
            _depositInLp();
        }

        lastTend = uint64(block.timestamp);
    }

    // @inheritdoc BaseStrategy
    function _tendTrigger() internal view override returns (bool) {
        // Check if minimum wait time has passed
        if (block.timestamp < uint256(lastTend) + uint256(minTendWait)) {
            return false;
        }

        // Check if base fee is acceptable
        if (block.basefee > uint256(maxTendBaseFeeGwei) * 1 gwei) {
            return false;
        }

        // Get current idle assets
        uint256 idleAsset = asset.balanceOf(address(this));

        // If target idle is set, check if we need to rebalance
        uint256 _targetIdleAssetBps = uint256(targetIdleAssetBps);
        if (_targetIdleAssetBps > 0) {
            uint256 targetIdleAmount = _getTargetIdleAmount(
                _targetIdleAssetBps
            );

            // Calculate bounds using configurable buffer
            uint256 bufferAmount = (targetIdleAmount *
                uint256(targetIdleBufferBps)) / MAX_BPS;
            uint256 upperBound = targetIdleAmount + bufferAmount;
            uint256 lowerBound = targetIdleAmount - bufferAmount;

            // Trigger if we're outside the acceptable range
            // Let _tend handle minAsset checks
            return idleAsset > upperBound || idleAsset < lowerBound;
        }

        // If no target is set, only trigger if we have idle assets above minAsset
        uint256 _minAsset = uint256(minAsset);
        return _minAsset == 0 ? idleAsset > 0 : idleAsset >= _minAsset;
    }

    // @inheritdoc BaseStrategy
    function _emergencyWithdraw(uint256 _amount) internal override {
        _withdrawFromLp(_amount);
    }

    // @inheritdoc BaseStrategy
    // Only return the loose asset balance
    function availableWithdrawLimit(
        address /*_owner*/
    ) public view override returns (uint256) {
        return asset.balanceOf(address(this));
    }

    // @inheritdoc BaseStrategy
    function availableDepositLimit(
        address /* _owner */
    ) public view override returns (uint256) {
        uint256 currentAssets = TokenizedStrategy.totalAssets();
        uint256 _depositLimit = depositLimit;

        if (_depositLimit <= currentAssets) {
            return 0;
        }

        return _depositLimit - currentAssets;
    }

    /*//////////////////////////////////////////////////////////////
                         VIEW FUNCTIONS
    //////////////////////////////////////////////////////////////*/

    /**
     * @notice Estimates the total value of all strategy holdings in asset terms
     * @return Total estimated value including loose tokens and LP positions
     * @dev Sums loose asset balance, paired token value, and LP position value
     *      all denominated in the strategy's primary asset
     */
    function estimatedTotalAsset() public view returns (uint256) {
        uint256 _assetBalance = asset.balanceOf(address(this));
        uint256 _pairedTokenBalance = ERC20(_PAIRED_TOKEN).balanceOf(
            address(this)
        );
        uint256 _pairedTokenBalanceInAsset = _valueOfPairedTokenInAsset(
            _pairedTokenBalance
        );
        uint256 _lpBalanceInAsset = lpValueInAsset();
        return _assetBalance + _pairedTokenBalanceInAsset + _lpBalanceInAsset;
    }

    /**
     * @notice Calculates the total value of the strategy's holdings in the Steer LP,
     *         denominated in the strategy's underlying asset.
     * @dev This function considers the strategy's share of both token0 and token1
     *      in the LP and converts their value to the asset's denomination using the
     *      current pool price.
     * @return valueLpInAssetTerms The total value of LP holdings in terms of the asset.
     */
    function lpValueInAsset()
        public
        view
        returns (uint256 valueLpInAssetTerms)
    {
        uint256 balanceOfLpShares = STEER_LP.balanceOf(address(this));
        if (balanceOfLpShares == 0) return 0;

        uint256 totalLpShares = STEER_LP.totalSupply();
        if (totalLpShares == 0) return 0;

        (uint256 total0InLp, uint256 total1InLp) = STEER_LP.getTotalAmounts();

        uint256 balanceOfToken0InLp = FullMath.mulDiv(
            balanceOfLpShares,
            total0InLp,
            totalLpShares
        );
        uint256 balanceOfToken1InLp = FullMath.mulDiv(
            balanceOfLpShares,
            total1InLp,
            totalLpShares
        );
        uint256 valuePairedTokenInAsset;

        if (_ASSET_IS_TOKEN_0) {
            valuePairedTokenInAsset = _valueOfPairedTokenInAsset(
                balanceOfToken1InLp
            );
            valueLpInAssetTerms = balanceOfToken0InLp + valuePairedTokenInAsset;
        } else {
            valuePairedTokenInAsset = _valueOfPairedTokenInAsset(
                balanceOfToken0InLp
            );
            valueLpInAssetTerms = balanceOfToken1InLp + valuePairedTokenInAsset;
        }
    }

    /**
     * @notice Calculates the value of the paired token in terms of the strategy's asset using current pool price.
     * @param amountOfPairedToken The amount of the paired token
     * @return value The calculated value in terms of the strategy's asset
     */
    function _valueOfPairedTokenInAsset(
        uint256 amountOfPairedToken
    ) internal view returns (uint256 value) {
        if (amountOfPairedToken == 0) return 0;
        return
            _valueOfPairedTokenInAsset(amountOfPairedToken, _getSqrtPriceX96());
    }

    /**
     * @notice Calculates the value of the paired token in terms of the strategy's asset.
     * @param amountOfPairedToken The amount of the paired token
     * @param sqrtPriceX96 The current sqrt price (Q64.96) of the Uniswap V3 pool
     * @return value The calculated value in terms of the strategy's asset
     */
    function _valueOfPairedTokenInAsset(
        uint256 amountOfPairedToken,
        uint160 sqrtPriceX96
    ) internal view returns (uint256 value) {
        if (amountOfPairedToken == 0) return 0;

        // Get raw value without discount
        value = _valueOfPairedTokenInAssetRaw(
            amountOfPairedToken,
            sqrtPriceX96
        );

        // Apply discount for pool fee + additional discount
        uint24 poolFee = IUniswapV3Pool(_POOL).fee(); // e.g., 3000 = 0.3%
        uint256 totalDiscountBps = poolFee /
            100 +
            uint256(pairedTokenDiscountBps); // Convert fee to bps

        // Apply discount: value * (10000 - totalDiscountBps) / 10000
        value = (value * (MAX_BPS - totalDiscountBps)) / MAX_BPS;
    }

    /**
     * @notice Calculates the raw value of the paired token without any discounts.
     * @param amountOfPairedToken The amount of the paired token
     * @param sqrtPriceX96 The current sqrt price (Q64.96) of the Uniswap V3 pool
     * @return value The raw calculated value in terms of the strategy's asset
     */
    function _valueOfPairedTokenInAssetRaw(
        uint256 amountOfPairedToken,
        uint160 sqrtPriceX96
    ) internal view returns (uint256 value) {
        if (_ASSET_IS_TOKEN_0) {
            // Convert token1 to token0: amount1 / price
            // Calculate price ratio first to avoid underflow: (Q96^2 / sqrtPrice) / sqrtPrice
            value = FullMath.mulDiv(
                FullMath.mulDiv(Q96, Q96, sqrtPriceX96),
                amountOfPairedToken,
                sqrtPriceX96
            );
        } else {
            // Convert token0 to token1: amount0 * price
            // Check if we should calculate price first to avoid precision loss
            // Safe check: amount < Q96 / sqrtPrice (avoiding overflow)
            if (amountOfPairedToken < Q96 / sqrtPriceX96) {
                // Calculate price first when amount is small or price is very high
                value = FullMath.mulDiv(
                    FullMath.mulDiv(sqrtPriceX96, sqrtPriceX96, Q96),
                    amountOfPairedToken,
                    Q96
                );
            } else {
                // Standard calculation when amount is large enough
                value = FullMath.mulDiv(
                    FullMath.mulDiv(amountOfPairedToken, sqrtPriceX96, Q96),
                    sqrtPriceX96,
                    Q96
                );
            }
        }
    }

    /**
     * @notice Converts asset value to paired token quantity (inverse of _valueOfPairedTokenInAsset).
     * @param _valueInAssetTerms The value denominated in the strategy's primary asset
     * @param _sqrtPriceX96 The current sqrt price (Q64.96) of the Uniswap V3 pool
     * @return _amountOfPairedToken The corresponding quantity of paired token
     */
    function _assetValueToPairedAmount(
        uint256 _valueInAssetTerms,
        uint160 _sqrtPriceX96
    ) internal view returns (uint256 _amountOfPairedToken) {
        if (_valueInAssetTerms == 0) return 0;
        if (_ASSET_IS_TOKEN_0) {
            // Convert asset value to token1: value * price
            // Check if we should calculate price first to avoid precision loss
            // Safe check: value < Q96 / sqrtPrice (avoiding overflow)
            if (_valueInAssetTerms < Q96 / _sqrtPriceX96) {
                // Calculate price first when value is small
                _amountOfPairedToken = FullMath.mulDiv(
                    FullMath.mulDiv(_sqrtPriceX96, _sqrtPriceX96, Q96),
                    _valueInAssetTerms,
                    Q96
                );
            } else {
                // Standard calculation when value is large enough
                _amountOfPairedToken = FullMath.mulDiv(
                    FullMath.mulDiv(_valueInAssetTerms, _sqrtPriceX96, Q96),
                    _sqrtPriceX96,
                    Q96
                );
            }
        } else {
            // Convert asset value to token0: value / price
            // Calculate price ratio first to avoid underflow
            _amountOfPairedToken = FullMath.mulDiv(
                FullMath.mulDiv(Q96, Q96, _sqrtPriceX96),
                _valueInAssetTerms,
                _sqrtPriceX96
            );
        }
    }

    /*//////////////////////////////////////////////////////////////
                         INTERNAL LOGIC
    //////////////////////////////////////////////////////////////*/

    /**
     * @notice Calculates the amount of the strategy's asset to swap to achieve a balanced
     *         deposit into the Uniswap V3 LP, based on the current LP composition.
     * @dev If the LP is empty, returns 0. Otherwise, it calculates the swap amount
     *      to match the LP's current token value ratio.
     * @param totalDepositValue The total value available for deposit (asset + paired token value in asset terms).
     * @param total0InLp The total amount of token0 in the Uniswap V3 LP.
     * @param total1InLp The total amount of token1 in the Uniswap V3 LP.
     * @param sqrtPriceX96 The current sqrt price (Q64.96) of the Uniswap V3 pool.
     * @return amountToSwap The calculated amount of asset to swap.
     */
    function _calculateAmountToSwapForDeposit(
        uint256 totalDepositValue,
        uint256 total0InLp,
        uint256 total1InLp,
        uint160 sqrtPriceX96
    ) internal view returns (uint256 amountToSwap) {
        if (total0InLp == 0 && total1InLp == 0) return 0;

        uint256 pairedTokenValueInAsset;
        uint256 totalLpValueInAsset;

        if (_ASSET_IS_TOKEN_0) {
            // Convert token1 LP balance to token0 value
            // Calculate price ratio first to avoid underflow
            pairedTokenValueInAsset = FullMath.mulDiv(
                FullMath.mulDiv(Q96, Q96, sqrtPriceX96),
                total1InLp,
                sqrtPriceX96
            );
            totalLpValueInAsset = total0InLp + pairedTokenValueInAsset;
        } else {
            // Convert token0 LP balance to token1 value
            // Check if we should calculate price first to avoid precision loss
            if (total0InLp < Q96 / sqrtPriceX96) {
                // Calculate price first when amount is small
                pairedTokenValueInAsset = FullMath.mulDiv(
                    FullMath.mulDiv(sqrtPriceX96, sqrtPriceX96, Q96),
                    total0InLp,
                    Q96
                );
            } else {
                // Standard calculation when amount is large enough
                pairedTokenValueInAsset = FullMath.mulDiv(
                    FullMath.mulDiv(total0InLp, sqrtPriceX96, Q96),
                    sqrtPriceX96,
                    Q96
                );
            }
            totalLpValueInAsset = total1InLp + pairedTokenValueInAsset;
        }

        if (totalLpValueInAsset == 0) return 0;
        // Calculate swap amount to match LP's token value ratio
        amountToSwap = FullMath.mulDiv(
            totalDepositValue,
            pairedTokenValueInAsset,
            totalLpValueInAsset
        );
    }

    /**
     * @notice Swaps asset for paired token via Uniswap V3 pool.
     * @param amountToSwap The amount of asset to swap
     */
    function _swapAssetForPairedToken(uint256 amountToSwap) internal {
        _performSwap(address(asset), amountToSwap, _ASSET_IS_TOKEN_0);
    }

    /**
     * @notice Swaps paired token for asset via Uniswap V3 pool.
     * @param amountToSwap The amount of paired token to swap
     */
    function _swapPairedTokenForAsset(uint256 amountToSwap) internal {
        _performSwap(_PAIRED_TOKEN, amountToSwap, !_ASSET_IS_TOKEN_0);
    }

    /**
     * @notice Internal helper to perform token swaps via Uniswap V3 pool.
     * @param tokenIn The address of the token being swapped
     * @param amountToSwap The amount of token to swap
     * @param zeroForOne The direction of the swap (true = token0 -> token1, false = token1 -> token0)
     */
    function _performSwap(
        address tokenIn,
        uint256 amountToSwap,
        bool zeroForOne
    ) internal {
        // Apply maxSwapValue limit if not set to max
        uint256 _maxSwapValue = maxSwapValue;
        if (_maxSwapValue != type(uint256).max) {
            uint256 swapValueInAsset;
            if (tokenIn == address(asset)) {
                // Swapping asset, amount is already in asset terms
                swapValueInAsset = amountToSwap;
            } else {
                // Swapping paired token, convert to asset value
                swapValueInAsset = _valueOfPairedTokenInAsset(amountToSwap);
            }

            if (swapValueInAsset > _maxSwapValue) {
                // Reduce swap amount to respect limit
                if (tokenIn == address(asset)) {
                    amountToSwap = _maxSwapValue;
                } else {
                    // Convert maxSwapValue back to paired token amount
                    amountToSwap = _assetValueToPairedAmount(
                        _maxSwapValue,
                        _getSqrtPriceX96()
                    );
                }
            }
        }

        if (amountToSwap == 0) return;

        SwapCallbackData memory callbackData = SwapCallbackData(
            tokenIn,
            amountToSwap
        );
        bytes memory data = abi.encode(callbackData);

        IUniswapV3Pool(_POOL).swap(
            address(this),
            zeroForOne,
            int256(amountToSwap),
            zeroForOne
                ? TickMath.MIN_SQRT_RATIO + 1
                : TickMath.MAX_SQRT_RATIO - 1,
            data
        );
    }

    /**
     * @notice Performs rebalancing swaps to achieve target token allocation for LP deposit.
     * @param currentPairedTokenValueInAsset Current value of paired token holdings in asset terms
     * @param targetPairedTokenValueInAsset Target value of paired token holdings in asset terms
     * @param assetBalance Current asset balance
     * @param pairedTokenBalance Current paired token balance
     * @param sqrtPriceX96 Current pool price
     */
    function _performRebalancingSwap(
        uint256 currentPairedTokenValueInAsset,
        uint256 targetPairedTokenValueInAsset,
        uint256 assetBalance,
        uint256 pairedTokenBalance,
        uint160 sqrtPriceX96
    ) internal {
        uint256 _minAsset = uint256(minAsset);

        if (targetPairedTokenValueInAsset > currentPairedTokenValueInAsset) {
            // Need more paired token
            uint256 assetValueToSwap = targetPairedTokenValueInAsset -
                currentPairedTokenValueInAsset;
            if (assetValueToSwap > assetBalance) {
                assetValueToSwap = assetBalance;
            }

            // Only swap if above minAsset threshold
            if (
                assetValueToSwap > 0 &&
                (_minAsset == 0 || assetValueToSwap >= _minAsset)
            ) {
                _swapAssetForPairedToken(assetValueToSwap);
            }
        } else if (
            currentPairedTokenValueInAsset > targetPairedTokenValueInAsset
        ) {
            // Have excess paired token
            uint256 excessPairedTokenValueInAsset = currentPairedTokenValueInAsset -
                    targetPairedTokenValueInAsset;

            // Only swap if above minAsset threshold
            if (_minAsset == 0 || excessPairedTokenValueInAsset >= _minAsset) {
                uint256 pairedTokenQuantityToSwap = _assetValueToPairedAmount(
                    excessPairedTokenValueInAsset,
                    sqrtPriceX96
                );
                if (pairedTokenQuantityToSwap > pairedTokenBalance) {
                    pairedTokenQuantityToSwap = pairedTokenBalance;
                }
                if (pairedTokenQuantityToSwap > 0) {
                    _swapPairedTokenForAsset(pairedTokenQuantityToSwap);
                }
            }
        }
    }

    /**
     * @notice Deposits balanced tokens into the Steer LP.
     * @param assetForDeposit Amount of asset to deposit
     */
    function _performLpDeposit(uint256 assetForDeposit) internal {
        uint256 pairedTokenBalanceForDeposit = ERC20(_PAIRED_TOKEN).balanceOf(
            address(this)
        );

        asset.forceApprove(address(STEER_LP), assetForDeposit);
        ERC20(_PAIRED_TOKEN).forceApprove(
            address(STEER_LP),
            pairedTokenBalanceForDeposit
        );

        uint256 token0DepositAmount;
        uint256 token1DepositAmount;

        if (_ASSET_IS_TOKEN_0) {
            token0DepositAmount = assetForDeposit;
            token1DepositAmount = pairedTokenBalanceForDeposit;
        } else {
            token0DepositAmount = pairedTokenBalanceForDeposit;
            token1DepositAmount = assetForDeposit;
        }

        STEER_LP.deposit(
            token0DepositAmount,
            token1DepositAmount,
            0,
            0,
            address(this)
        );
    }

    /**
     * @notice Deposits assets into the Steer LP.
     * @dev This function first calculates the optimal amount of the strategy's asset to swap
     *      to achieve a balanced deposit. It then performs the swap (if necessary) and
     *      deposits both the remaining asset and the acquired other token into the Steer LP.
     *      Respects the targetIdleAssetBps to maintain a percentage of assets idle.
     */
    function _depositInLp() internal {
        uint256 assetBalance = asset.balanceOf(address(this));
        uint256 pairedTokenBalance = ERC20(_PAIRED_TOKEN).balanceOf(
            address(this)
        );

        uint256 availableForDeposit = assetBalance;
        uint256 targetIdleAmount;

        // Apply idle asset target
        uint256 _targetIdleAssetBps = uint256(targetIdleAssetBps);
        if (_targetIdleAssetBps > 0) {
            targetIdleAmount = _getTargetIdleAmount(_targetIdleAssetBps);

            // Only deposit if above target idle amount
            if (assetBalance <= targetIdleAmount) return;

            // Calculate amount available for deposit
            availableForDeposit = assetBalance - targetIdleAmount;
        }

        uint160 sqrtPriceX96 = _getSqrtPriceX96();

        uint256 pairedTokenValueInAsset = _valueOfPairedTokenInAsset(
            pairedTokenBalance,
            sqrtPriceX96
        );
        uint256 totalDepositValueInAsset = availableForDeposit +
            pairedTokenValueInAsset;

        if (totalDepositValueInAsset == 0) return;

        (uint256 lpToken0Balance, uint256 lpToken1Balance) = STEER_LP
            .getTotalAmounts();

        if (lpToken0Balance == 0 && lpToken1Balance == 0) return; // do not be first lp

        // Early exit if maxSwapValue = 0 and LP needs both tokens but we can't swap
        if (maxSwapValue == 0) {
            bool lpIsOutOfRange = (lpToken0Balance == 0) ||
                (lpToken1Balance == 0);
            bool weHaveOnlyOneToken = (pairedTokenBalance == 0) ||
                (availableForDeposit == 0);

            if (!lpIsOutOfRange && weHaveOnlyOneToken) {
                return; // LP needs both tokens but we can't swap to get them
            }
        }

        // Calculate target allocation and perform rebalancing swap
        uint256 targetPairedTokenValueInAsset = _calculateAmountToSwapForDeposit(
                totalDepositValueInAsset,
                lpToken0Balance,
                lpToken1Balance,
                sqrtPriceX96
            );

        _performRebalancingSwap(
            pairedTokenValueInAsset,
            targetPairedTokenValueInAsset,
            availableForDeposit,
            pairedTokenBalance,
            sqrtPriceX96
        );

        availableForDeposit = asset.balanceOf(address(this));
        if (availableForDeposit < targetIdleAmount) return;

        _performLpDeposit(availableForDeposit - targetIdleAmount);
    }

    /**
     * @notice Withdraws a specified amount of the strategy's asset from the Steer LP.
     * @dev Calculates the number of LP shares to withdraw based on the desired asset amount.
     *      After withdrawing from the Steer LP, if any "other token" is received,
     *      it is swapped back to the strategy's asset.
     * @param assetToWithdraw The amount of the strategy's asset to withdraw from the LP.
     */
    function _withdrawFromLp(uint256 assetToWithdraw) internal {
        if (assetToWithdraw == 0) return;

        uint256 lpSharesBalance = STEER_LP.balanceOf(address(this));

        uint256 _lpValueInAsset = lpValueInAsset();
        if (_lpValueInAsset == 0) return;

        uint256 sharesToWithdraw;
        if (assetToWithdraw >= _lpValueInAsset) {
            sharesToWithdraw = lpSharesBalance;
        } else {
            sharesToWithdraw = FullMath.mulDiv(
                assetToWithdraw,
                lpSharesBalance,
                _lpValueInAsset
            );
        }

        if (sharesToWithdraw == 0) return;

        STEER_LP.withdraw(sharesToWithdraw, 0, 0, address(this));

        uint256 pairedTokenBalance = ERC20(_PAIRED_TOKEN).balanceOf(
            address(this)
        );

        if (pairedTokenBalance > 0) {
            // Always swap paired tokens after withdrawal to avoid leaving dust
            // We've already committed to the withdrawal operation
            _swapPairedTokenForAsset(pairedTokenBalance);
        }
    }

    /*//////////////////////////////////////////////////////////////
                         UNISWAP V3 CALLBACK
    //////////////////////////////////////////////////////////////*/

    // @inheritdoc IUniswapV3SwapCallback
    function uniswapV3SwapCallback(
        int256 amount0Delta,
        int256 amount1Delta,
        bytes calldata _data
    ) external override {
        require(msg.sender == _POOL, "!caller"); // dev: Only pool can call swap callback

        SwapCallbackData memory callbackData = abi.decode(
            _data,
            (SwapCallbackData)
        );

        uint256 amountPaid = _validateAndGetAmountPaid(
            amount0Delta,
            amount1Delta,
            callbackData.tokenToPay
        );

        require(amountPaid == callbackData.amountToPay, "!amount"); // dev: amount mismatch
        ERC20(callbackData.tokenToPay).safeTransfer(_POOL, amountPaid);
    }

    /**
     * @notice Validates swap callback deltas and returns the amount to be paid
     * @param amount0Delta Amount delta for token0
     * @param amount1Delta Amount delta for token1
     * @param tokenToPay Address of the token being paid
     * @return amountPaid The validated amount to pay
     */
    function _validateAndGetAmountPaid(
        int256 amount0Delta,
        int256 amount1Delta,
        address tokenToPay
    ) internal view returns (uint256 amountPaid) {
        bool isPayingAsset = tokenToPay == address(asset);
        bool isPayingPairedToken = tokenToPay == _PAIRED_TOKEN;

        require(isPayingAsset || isPayingPairedToken, "!token"); // dev: invalid token to pay

        if (_ASSET_IS_TOKEN_0) {
            if (isPayingAsset) {
                require(amount0Delta > 0, "!amount0+"); // dev: paying asset as token0
                require(amount1Delta < 0, "!amount1-"); // dev: paying asset as token0
                amountPaid = uint256(amount0Delta);
            } else {
                require(amount1Delta > 0, "!amount1+"); // dev: paying paired token as token1
                require(amount0Delta < 0, "!amount0-"); // dev: paying paired token as token1
                amountPaid = uint256(amount1Delta);
            }
        } else {
            if (isPayingAsset) {
                require(amount1Delta > 0, "!amount1+"); // dev: paying asset as token1
                require(amount0Delta < 0, "!amount0-"); // dev: paying asset as token1
                amountPaid = uint256(amount1Delta);
            } else {
                require(amount0Delta > 0, "!amount0+"); // dev: paying paired token as token0
                require(amount1Delta < 0, "!amount1-"); // dev: paying paired token as token0
                amountPaid = uint256(amount0Delta);
            }
        }
    }

    function _getTargetIdleAmount(
        uint256 _targetIdleAssetBps
    ) internal view returns (uint256) {
        uint256 totalAssets = TokenizedStrategy.totalAssets();
        return (totalAssets * _targetIdleAssetBps) / MAX_BPS;
    }

    function _getSqrtPriceX96() internal view returns (uint160 sqrtPriceX96) {
        (sqrtPriceX96, , , , , , ) = IUniswapV3Pool(_POOL).slot0();
    }

    /*//////////////////////////////////////////////////////////////
                        MANAGEMENT FUNCTIONS
    //////////////////////////////////////////////////////////////*/

    /**
     * @notice Sets the deposit limit for the strategy
     * @param _depositLimit New deposit limit
     */
    function setDepositLimit(uint256 _depositLimit) external onlyManagement {
        depositLimit = _depositLimit;
    }

    /**
     * @notice Sets the target idle asset percentage in basis points
     * @param _targetIdleAssetBps Target idle asset percentage in basis points (e.g., 500 = 5%)
     */
    function setTargetIdleAssetBps(
        uint16 _targetIdleAssetBps
    ) external onlyManagement {
        require(_targetIdleAssetBps <= MAX_BPS, "!bps"); // dev: Target idle asset cannot exceed 100% (10000 bps)
        targetIdleAssetBps = _targetIdleAssetBps;
    }

    /**
     * @notice Sets the maximum swap value per transaction
     * @param _maxSwapValue Maximum value that can be swapped in a single transaction (in asset terms)
     * @dev Set to type(uint256).max to disable the limit
     */
    function setMaxSwapValue(uint256 _maxSwapValue) external onlyManagement {
        maxSwapValue = _maxSwapValue;
    }

    /**
     * @notice Sets the minimum wait time between tends
     * @param _minTendWait Minimum wait time in seconds
     * @dev Can only be called by management
     */
    function setMinTendWait(uint24 _minTendWait) external onlyManagement {
        minTendWait = _minTendWait;
    }

    /**
     * @notice Sets the maximum acceptable base fee for tends
     * @param _maxTendBaseFeeGwei Maximum base fee in gwei
     * @dev Can only be called by management
     */
    function setMaxTendBaseFee(
        uint8 _maxTendBaseFeeGwei
    ) external onlyManagement {
        maxTendBaseFeeGwei = _maxTendBaseFeeGwei;
    }

    /**
     * @notice Sets the target idle buffer in basis points
     * @param _targetIdleBufferBps Buffer in basis points (e.g., 1000 = 10%)
     * @dev Can only be called by management
     */
    function setTargetIdleBufferBps(
        uint16 _targetIdleBufferBps
    ) external onlyManagement {
        require(_targetIdleBufferBps <= MAX_BPS, "!bps"); // dev: Buffer cannot exceed 100%
        targetIdleBufferBps = _targetIdleBufferBps;
    }

    /**
     * @notice Sets the additional discount for paired token valuations
     * @param _pairedTokenDiscountBps Discount in basis points (e.g., 50 = 0.5%)
     * @dev Can only be called by management
     */
    function setPairedTokenDiscountBps(
        uint16 _pairedTokenDiscountBps
    ) external onlyManagement {
        require(_pairedTokenDiscountBps <= 1000, "!discount"); // dev: Discount cannot exceed 10%
        pairedTokenDiscountBps = _pairedTokenDiscountBps;
    }

    /**
     * @notice Sets the minimum asset amount for any operation (dust threshold)
     * @param _minAsset Minimum amount of assets for any operation
     * @dev Can only be called by management
     */
    function setMinAsset(uint128 _minAsset) external onlyManagement {
        minAsset = _minAsset;
    }

    /**
     * @notice Sets whether to use auctions for token swaps
     * @param _useAuctions New value for useAuctions flag
     * @dev Can only be called by management
     * @dev When enabled, the strategy will attempt to kick auctions during harvest
     * @dev When disabled, the strategy will not use auctions and rewards will accumulate
     */
    function setUseAuctions(bool _useAuctions) external onlyManagement {
        useAuctions = _useAuctions;
    }

    /**
     * @notice Sets the auction contract address
     * @param _auction Address of the auction contract
     * @dev Can only be called by management
     * @dev Verifies the auction contract is compatible with this strategy by:
     *      1. Checking that auction's want matches the strategy's asset
     *      2. Ensuring the auction contract's receiver is this strategy
     */
    function setAuction(address _auction) external onlyManagement {
        if (_auction != address(0)) {
            require(IAuction(_auction).want() == address(asset), "!want"); // dev: Auction want token must match strategy asset
            require(
                IAuction(_auction).receiver() == address(this),
                "!receiver"
            ); // dev: Auction receiver must be this strategy
        }
        auction = _auction;
    }

    /**
     * @notice Manually swaps paired token for asset
     * @param _amount Amount of paired token to swap
     * @dev This function is limited by maxSwapValueset.
            Set maxSwapValue to an appropriate value before swapping
     */
    function manualSwapPairedTokenToAsset(
        uint256 _amount
    ) external onlyManagement {
        require(_amount > 0, "!amount"); // dev: Amount must be greater than 0
        uint256 pairedTokenBalance = ERC20(_PAIRED_TOKEN).balanceOf(
            address(this)
        );
        require(_amount <= pairedTokenBalance, "!balance"); // dev: Insufficient paired token balance

        _swapPairedTokenForAsset(_amount);
    }

    /**
     * @notice Manually withdraws from LP position
     * @param _amount Amount of asset value to withdraw from LP
     * @dev This function will swap excessed paired token limited by maxSwapValue
     *      Set maxSwapValue = 0 if you want to prevent swapping.
     */
    function manualWithdrawFromLp(uint256 _amount) external onlyManagement {
        require(_amount > 0, "!amount"); // dev: Amount must be greater than 0
        _withdrawFromLp(_amount);
    }

    /*//////////////////////////////////////////////////////////////
        AUCTION FUNCTIONS
    //////////////////////////////////////////////////////////////*/

    /**
     * @notice Initiates an auction for a given token
     * @dev Transfers tokens to auction contract and starts auction
     * @param _from The token to be sold in the auction
     * @return The available amount for bidding on in the auction
     */
    function kickAuction(
        address _from
    ) external virtual onlyManagement returns (uint256) {
        (bool _success, uint256 _amount) = _tryKickAuction(auction, _from);
        require(_success, "!kick");
        return _amount;
    }

    /**
     * @notice Attempts to kick an auction for a given token
     * @param _auction The auction contract address
     * @param _from The token to be sold in the auction
     * @return success Whether the auction was successfully started
     * @return amount The amount available for bidding
     */
    function _tryKickAuction(
        address _auction,
        address _from
    ) internal virtual returns (bool, uint256) {
        if (!useAuctions || _auction == address(0)) return (false, 0);
        if (_from == address(asset) || _from == address(STEER_LP))
            return (false, 0);
        if (
            IAuction(_auction).isActive(address(asset)) ||
            IAuction(_auction).available(address(asset)) != 0
        ) return (false, 0);
        uint256 _strategyBalance = ERC20(_from).balanceOf(address(this));
        uint256 _totalBalance = _strategyBalance +
            ERC20(_from).balanceOf(_auction);
        if (_totalBalance == 0) return (false, 0);
        if (_strategyBalance != 0) {
            ERC20(_from).safeTransfer(_auction, _strategyBalance);
        }
        uint256 _amountKicked = IAuction(_auction).kick(_from);
        return (true, _amountKicked);
    }

    /*//////////////////////////////////////////////////////////////
                        REWARDS FUNCTIONS
    //////////////////////////////////////////////////////////////*/

    /**
     * @notice Claims rewards from Merkl distributor
     * @param users Recipients of tokens
     * @param tokens ERC20 tokens being claimed
     * @param amounts Amounts of tokens that will be sent to the corresponding users
     * @param proofs Array of Merkle proofs verifying the claims
     */
    function claim(
        address[] calldata users,
        address[] calldata tokens,
        uint256[] calldata amounts,
        bytes32[][] calldata proofs
    ) external {
        MERKL_DISTRIBUTOR.claim(users, tokens, amounts, proofs);
    }
}

// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.18;

import {IBaseHealthCheck} from "@periphery/Bases/HealthCheck/IBaseHealthCheck.sol";
import {IMerklDistributor} from "./IMerklDistributor.sol";

interface IStrategyInterface is IBaseHealthCheck {
    function lpValueInAsset()
        external
        view
        returns (uint256 valueLpInAssetTerms);

    function STEER_LP() external view returns (address);
    function MERKL_DISTRIBUTOR() external view returns (IMerklDistributor);

    function estimatedTotalAsset() external view returns (uint256);

    function uniswapV3SwapCallback(
        int256 amount0Delta,
        int256 amount1Delta,
        bytes calldata _data
    ) external;

    // Management parameters
    function targetIdleAssetBps() external view returns (uint16);
    function targetIdleBufferBps() external view returns (uint16);
    function pairedTokenDiscountBps() external view returns (uint16);
    function depositLimit() external view returns (uint256);
    function maxSwapValue() external view returns (uint256);
    function minAsset() external view returns (uint128);
    function useAuctions() external view returns (bool);
    function auction() external view returns (address);
    function minTendWait() external view returns (uint24);
    function maxTendBaseFeeGwei() external view returns (uint8);
    function lastTend() external view returns (uint64);

    // Management functions
    function setAuction(address _auction) external;
    function setDepositLimit(uint256 _depositLimit) external;
    function setTargetIdleAssetBps(uint16 _targetIdleAssetBps) external;
    function setTargetIdleBufferBps(uint16 _targetIdleBufferBps) external;
    function setPairedTokenDiscountBps(uint16 _pairedTokenDiscountBps) external;
    function setMinAsset(uint128 _minAsset) external;
    function setMaxSwapValue(uint256 _maxSwapValue) external;
    function setUseAuctions(bool _useAuctions) external;
    function setMinTendWait(uint24 _minTendWait) external;
    function setMaxTendBaseFee(uint8 _maxTendBaseFeeGwei) external;
    function manualSwapPairedTokenToAsset(uint256 _amount) external;
    function manualWithdrawFromLp(uint256 _amount) external;

    // Auction functions
    function kickAuction(address _from) external returns (uint256);
    function claim(
        address[] calldata users,
        address[] calldata tokens,
        uint256[] calldata amounts,
        bytes32[][] calldata proofs
    ) external;
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.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";

/**
 * @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;
 * }
 * ```
 *
 * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
 * and `uint256` (`UintSet`) are supported.
 *
 * [WARNING]
 * ====
 * Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
 * unusable.
 * See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
 *
 * In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an
 * array of EnumerableSet.
 * ====
 */
library 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: 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(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;
    }

    // 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;
    }

    // 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;
    }

    // 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;
    }
}

// SPDX-License-Identifier: AGPL-3.0
pragma solidity >=0.8.18;

import {BaseStrategy, ERC20} from "@tokenized-strategy/BaseStrategy.sol";

/**
 *   @title Base Health Check
 *   @author Yearn.finance
 *   @notice This contract can be inherited by any Yearn
 *   V3 strategy wishing to implement a health check during
 *   the `report` function in order to prevent any unexpected
 *   behavior from being permanently recorded as well as the
 *   `checkHealth` modifier.
 *
 *   A strategist simply needs to inherit this contract. Set
 *   the limit ratios to the desired amounts and then
 *   override `_harvestAndReport()` just as they otherwise
 *  would. If the profit or loss that would be recorded is
 *   outside the acceptable bounds the tx will revert.
 *
 *   The healthcheck does not prevent a strategy from reporting
 *   losses, but rather can make sure manual intervention is
 *   needed before reporting an unexpected loss or profit.
 */
abstract contract BaseHealthCheck is BaseStrategy {
    // Can be used to determine if a healthcheck should be called.
    // Defaults to true;
    bool public doHealthCheck = true;

    uint256 internal constant MAX_BPS = 10_000;

    // Default profit limit to 100%.
    uint16 private _profitLimitRatio = uint16(MAX_BPS);

    // Defaults loss limit to 0.
    uint16 private _lossLimitRatio;

    constructor(
        address _asset,
        string memory _name
    ) BaseStrategy(_asset, _name) {}

    /**
     * @notice Returns the current profit limit ratio.
     * @dev Use a getter function to keep the variable private.
     * @return . The current profit limit ratio.
     */
    function profitLimitRatio() public view returns (uint256) {
        return _profitLimitRatio;
    }

    /**
     * @notice Returns the current loss limit ratio.
     * @dev Use a getter function to keep the variable private.
     * @return . The current loss limit ratio.
     */
    function lossLimitRatio() public view returns (uint256) {
        return _lossLimitRatio;
    }

    /**
     * @notice Set the `profitLimitRatio`.
     * @dev Denominated in basis points. I.E. 1_000 == 10%.
     * @param _newProfitLimitRatio The mew profit limit ratio.
     */
    function setProfitLimitRatio(
        uint256 _newProfitLimitRatio
    ) external onlyManagement {
        _setProfitLimitRatio(_newProfitLimitRatio);
    }

    /**
     * @dev Internally set the profit limit ratio. Denominated
     * in basis points. I.E. 1_000 == 10%.
     * @param _newProfitLimitRatio The mew profit limit ratio.
     */
    function _setProfitLimitRatio(uint256 _newProfitLimitRatio) internal {
        require(_newProfitLimitRatio > 0, "!zero profit");
        require(_newProfitLimitRatio <= type(uint16).max, "!too high");
        _profitLimitRatio = uint16(_newProfitLimitRatio);
    }

    /**
     * @notice Set the `lossLimitRatio`.
     * @dev Denominated in basis points. I.E. 1_000 == 10%.
     * @param _newLossLimitRatio The new loss limit ratio.
     */
    function setLossLimitRatio(
        uint256 _newLossLimitRatio
    ) external onlyManagement {
        _setLossLimitRatio(_newLossLimitRatio);
    }

    /**
     * @dev Internally set the loss limit ratio. Denominated
     * in basis points. I.E. 1_000 == 10%.
     * @param _newLossLimitRatio The new loss limit ratio.
     */
    function _setLossLimitRatio(uint256 _newLossLimitRatio) internal {
        require(_newLossLimitRatio < MAX_BPS, "!loss limit");
        _lossLimitRatio = uint16(_newLossLimitRatio);
    }

    /**
     * @notice Turns the healthcheck on and off.
     * @dev If turned off the next report will auto turn it back on.
     * @param _doHealthCheck Bool if healthCheck should be done.
     */
    function setDoHealthCheck(bool _doHealthCheck) public onlyManagement {
        doHealthCheck = _doHealthCheck;
    }

    /**
     * @notice OVerrides the default {harvestAndReport} to include a healthcheck.
     * @return _totalAssets New totalAssets post report.
     */
    function harvestAndReport()
        external
        override
        onlySelf
        returns (uint256 _totalAssets)
    {
        // Let the strategy report.
        _totalAssets = _harvestAndReport();

        // Run the healthcheck on the amount returned.
        _executeHealthCheck(_totalAssets);
    }

    /**
     * @dev To be called during a report to make sure the profit
     * or loss being recorded is within the acceptable bound.
     *
     * @param _newTotalAssets The amount that will be reported.
     */
    function _executeHealthCheck(uint256 _newTotalAssets) internal virtual {
        if (!doHealthCheck) {
            doHealthCheck = true;
            return;
        }

        // Get the current total assets from the implementation.
        uint256 currentTotalAssets = TokenizedStrategy.totalAssets();

        if (_newTotalAssets > currentTotalAssets) {
            require(
                ((_newTotalAssets - currentTotalAssets) <=
                    (currentTotalAssets * uint256(_profitLimitRatio)) /
                        MAX_BPS),
                "healthCheck"
            );
        } else if (currentTotalAssets > _newTotalAssets) {
            require(
                (currentTotalAssets - _newTotalAssets <=
                    ((currentTotalAssets * uint256(_lossLimitRatio)) /
                        MAX_BPS)),
                "healthCheck"
            );
        }
    }
}

// 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);
    }
}

File 7 of 43 : ISushiMultiPositionLiquidityManager.sol
// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.18;

interface ISushiMultiPositionLiquidityManager {
    event Approval(
        address indexed owner,
        address indexed spender,
        uint256 value
    );
    event Deposit(
        address indexed sender,
        address indexed to,
        uint256 shares,
        uint256 amount0,
        uint256 amount1
    );
    event FeesEarned(uint256 amount0Earned, uint256 amount1Earned);
    event Paused(address account);
    event RoleAdminChanged(
        bytes32 indexed role,
        bytes32 indexed previousAdminRole,
        bytes32 indexed newAdminRole
    );
    event RoleGranted(
        bytes32 indexed role,
        address indexed account,
        address indexed sender
    );
    event RoleRevoked(
        bytes32 indexed role,
        address indexed account,
        address indexed sender
    );
    event Snapshot(
        uint160 sqrtPriceX96,
        uint256 totalAmount0,
        uint256 totalAmount1,
        uint256 totalSupply
    );
    event Transfer(address indexed from, address indexed to, uint256 value);
    event Unpaused(address account);
    event Withdraw(
        address indexed sender,
        address indexed to,
        uint256 shares,
        uint256 amount0,
        uint256 amount1
    );

    struct LiquidityPositions {
        int24[] lowerTick;
        int24[] upperTick;
        uint16[] relativeWeight;
    }

    function DEFAULT_ADMIN_ROLE() external view returns (bytes32);
    function STEER_FRACTION_OF_FEE() external view returns (uint256);
    function TOTAL_FEE() external view returns (uint256);
    function accruedSteerFees0() external view returns (uint256);
    function accruedSteerFees1() external view returns (uint256);
    function accruedStrategistFees0() external view returns (uint256);
    function accruedStrategistFees1() external view returns (uint256);
    function allowance(
        address owner,
        address spender
    ) external view returns (uint256);
    function approve(address spender, uint256 amount) external returns (bool);
    function balanceOf(address account) external view returns (uint256);
    function decimals() external view returns (uint8);
    function decreaseAllowance(
        address spender,
        uint256 subtractedValue
    ) external returns (bool);
    function deposit(
        uint256 amount0Desired,
        uint256 amount1Desired,
        uint256 amount0Min,
        uint256 amount1Min,
        address to
    )
        external
        returns (uint256 shares, uint256 amount0Used, uint256 amount1Used);
    function emergencyBurn(
        int24 tickLower,
        int24 tickUpper,
        uint128 liquidity
    ) external returns (uint256 amount0, uint256 amount1);
    function getPositions()
        external
        view
        returns (int24[] memory, int24[] memory, uint16[] memory);
    function getRoleAdmin(bytes32 role) external view returns (bytes32);
    function getRoleMember(
        bytes32 role,
        uint256 index
    ) external view returns (address);
    function getRoleMemberCount(bytes32 role) external view returns (uint256);
    function getTotalAmounts()
        external
        view
        returns (uint256 total0, uint256 total1);
    function grantRole(bytes32 role, address account) external;
    function hasRole(
        bytes32 role,
        address account
    ) external view returns (bool);
    function increaseAllowance(
        address spender,
        uint256 addedValue
    ) external returns (bool);
    function initialize(
        address _vaultManager,
        address,
        address _steer,
        bytes calldata _params
    ) external;
    function maxTickChange() external view returns (int24);
    function name() external view returns (string memory);
    function pause() external;
    function paused() external view returns (bool);
    function poke() external;
    function pool() external view returns (address);
    function renounceRole(bytes32 role, address account) external;
    function revokeRole(bytes32 role, address account) external;
    function steerCollectFees(
        uint256 amount0,
        uint256 amount1,
        address to
    ) external;
    function strategistCollectFees(
        uint256 amount0,
        uint256 amount1,
        address to
    ) external;
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
    function symbol() external view returns (string memory);
    function tend(
        uint256 totalWeight,
        LiquidityPositions memory newPositions,
        bytes memory timeSensitiveData
    ) external;
    function token0() external view returns (address);
    function token1() external view returns (address);
    function totalSupply() external view returns (uint256);
    function transfer(
        address recipient,
        uint256 amount
    ) external returns (bool);
    function transferFrom(
        address sender,
        address recipient,
        uint256 amount
    ) external returns (bool);
    function twapInterval() external view returns (uint32);
    function uniswapV3MintCallback(
        uint256 amount0,
        uint256 amount1,
        bytes calldata
    ) external;
    function uniswapV3SwapCallback(
        int256 amount0Wanted,
        int256 amount1Wanted,
        bytes calldata
    ) external;
    function unpause() external;
    function withdraw(
        uint256 shares,
        uint256 amount0Min,
        uint256 amount1Min,
        address to
    ) external returns (uint256 amount0, uint256 amount1);
}

// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Callback for IUniswapV3PoolActions#swap
/// @notice Any contract that calls IUniswapV3PoolActions#swap must implement this interface
interface IUniswapV3SwapCallback {
    /// @notice Called to `msg.sender` after executing a swap via IUniswapV3Pool#swap.
    /// @dev In the implementation you must pay the pool tokens owed for the swap.
    /// The caller of this method must be checked to be a UniswapV3Pool deployed by the canonical UniswapV3Factory.
    /// amount0Delta and amount1Delta can both be 0 if no tokens were swapped.
    /// @param amount0Delta The amount of token0 that was sent (negative) or must be received (positive) by the pool by
    /// the end of the swap. If positive, the callback must send that amount of token0 to the pool.
    /// @param amount1Delta The amount of token1 that was sent (negative) or must be received (positive) by the pool by
    /// the end of the swap. If positive, the callback must send that amount of token1 to the pool.
    /// @param data Any data passed through by the caller via the IUniswapV3PoolActions#swap call
    function uniswapV3SwapCallback(
        int256 amount0Delta,
        int256 amount1Delta,
        bytes calldata data
    ) external;
}

File 9 of 43 : IUniswapV3Pool.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

import {IUniswapV3PoolImmutables} from './pool/IUniswapV3PoolImmutables.sol';
import {IUniswapV3PoolState} from './pool/IUniswapV3PoolState.sol';
import {IUniswapV3PoolDerivedState} from './pool/IUniswapV3PoolDerivedState.sol';
import {IUniswapV3PoolActions} from './pool/IUniswapV3PoolActions.sol';
import {IUniswapV3PoolOwnerActions} from './pool/IUniswapV3PoolOwnerActions.sol';
import {IUniswapV3PoolErrors} from './pool/IUniswapV3PoolErrors.sol';
import {IUniswapV3PoolEvents} from './pool/IUniswapV3PoolEvents.sol';

/// @title The interface for a Uniswap V3 Pool
/// @notice A Uniswap pool facilitates swapping and automated market making between any two assets that strictly conform
/// to the ERC20 specification
/// @dev The pool interface is broken up into many smaller pieces
interface IUniswapV3Pool is
    IUniswapV3PoolImmutables,
    IUniswapV3PoolState,
    IUniswapV3PoolDerivedState,
    IUniswapV3PoolActions,
    IUniswapV3PoolOwnerActions,
    IUniswapV3PoolErrors,
    IUniswapV3PoolEvents
{

}

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

/// @title Contains 512-bit math functions
/// @notice Facilitates multiplication and division that can have overflow of an intermediate value without any loss of precision
/// @dev Handles "phantom overflow" i.e., allows multiplication and division where an intermediate value overflows 256 bits
library FullMath {
    /// @notice Calculates floor(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
    /// @param a The multiplicand
    /// @param b The multiplier
    /// @param denominator The divisor
    /// @return result The 256-bit result
    /// @dev Credit to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv
    function mulDiv(
        uint256 a,
        uint256 b,
        uint256 denominator
    ) internal pure returns (uint256 result) {
        unchecked {
            // 512-bit multiply [prod1 prod0] = a * b
            // Compute the product mod 2**256 and mod 2**256 - 1
            // then use the Chinese Remainder Theorem to reconstruct
            // the 512 bit result. The result is stored in two 256
            // variables such that product = prod1 * 2**256 + prod0
            uint256 prod0; // Least significant 256 bits of the product
            uint256 prod1; // Most significant 256 bits of the product
            assembly {
                let mm := mulmod(a, b, not(0))
                prod0 := mul(a, b)
                prod1 := sub(sub(mm, prod0), lt(mm, prod0))
            }

            // Handle non-overflow cases, 256 by 256 division
            if (prod1 == 0) {
                require(denominator > 0);
                assembly {
                    result := div(prod0, denominator)
                }
                return result;
            }

            // Make sure the result is less than 2**256.
            // Also prevents denominator == 0
            require(denominator > prod1);

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

            // Make division exact by subtracting the remainder from [prod1 prod0]
            // Compute remainder using mulmod
            uint256 remainder;
            assembly {
                remainder := mulmod(a, b, denominator)
            }
            // Subtract 256 bit number from 512 bit number
            assembly {
                prod1 := sub(prod1, gt(remainder, prod0))
                prod0 := sub(prod0, remainder)
            }

            // Factor powers of two out of denominator
            // Compute largest power of two divisor of denominator.
            // Always >= 1.
            uint256 twos = (0 - denominator) & denominator;
            // Divide denominator by power of two
            assembly {
                denominator := div(denominator, twos)
            }

            // Divide [prod1 prod0] by the factors of two
            assembly {
                prod0 := div(prod0, twos)
            }
            // Shift in bits from prod1 into prod0. For this we need
            // to flip `twos` such that it is 2**256 / twos.
            // If twos is zero, then it becomes one
            assembly {
                twos := add(div(sub(0, twos), twos), 1)
            }
            prod0 |= prod1 * twos;

            // Invert denominator mod 2**256
            // Now that denominator is an odd number, it has an inverse
            // modulo 2**256 such that denominator * inv = 1 mod 2**256.
            // Compute the inverse by starting with a seed that is correct
            // correct for four bits. That is, denominator * inv = 1 mod 2**4
            uint256 inv = (3 * denominator) ^ 2;
            // Now use 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.
            inv *= 2 - denominator * inv; // inverse mod 2**8
            inv *= 2 - denominator * inv; // inverse mod 2**16
            inv *= 2 - denominator * inv; // inverse mod 2**32
            inv *= 2 - denominator * inv; // inverse mod 2**64
            inv *= 2 - denominator * inv; // inverse mod 2**128
            inv *= 2 - denominator * inv; // inverse mod 2**256

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

    /// @notice Calculates ceil(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
    /// @param a The multiplicand
    /// @param b The multiplier
    /// @param denominator The divisor
    /// @return result The 256-bit result
    function mulDivRoundingUp(
        uint256 a,
        uint256 b,
        uint256 denominator
    ) internal pure returns (uint256 result) {
        unchecked {
            result = mulDiv(a, b, denominator);
            if (mulmod(a, b, denominator) > 0) {
                require(result < type(uint256).max);
                result++;
            }
        }
    }
}

// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;

/// @title Math library for computing sqrt prices from ticks and vice versa
/// @notice Computes sqrt price for ticks of size 1.0001, i.e. sqrt(1.0001^tick) as fixed point Q64.96 numbers. Supports
/// prices between 2**-128 and 2**128
library TickMath {
    error T();
    error R();

    /// @dev The minimum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**-128
    int24 internal constant MIN_TICK = -887272;
    /// @dev The maximum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**128
    int24 internal constant MAX_TICK = -MIN_TICK;

    /// @dev The minimum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MIN_TICK)
    uint160 internal constant MIN_SQRT_RATIO = 4295128739;
    /// @dev The maximum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MAX_TICK)
    uint160 internal constant MAX_SQRT_RATIO = 1461446703485210103287273052203988822378723970342;

    /// @notice Calculates sqrt(1.0001^tick) * 2^96
    /// @dev Throws if |tick| > max tick
    /// @param tick The input tick for the above formula
    /// @return sqrtPriceX96 A Fixed point Q64.96 number representing the sqrt of the ratio of the two assets (token1/token0)
    /// at the given tick
    function getSqrtRatioAtTick(int24 tick) internal pure returns (uint160 sqrtPriceX96) {
        unchecked {
            uint256 absTick = tick < 0 ? uint256(-int256(tick)) : uint256(int256(tick));
            if (absTick > uint256(int256(MAX_TICK))) revert T();

            uint256 ratio = absTick & 0x1 != 0
                ? 0xfffcb933bd6fad37aa2d162d1a594001
                : 0x100000000000000000000000000000000;
            if (absTick & 0x2 != 0) ratio = (ratio * 0xfff97272373d413259a46990580e213a) >> 128;
            if (absTick & 0x4 != 0) ratio = (ratio * 0xfff2e50f5f656932ef12357cf3c7fdcc) >> 128;
            if (absTick & 0x8 != 0) ratio = (ratio * 0xffe5caca7e10e4e61c3624eaa0941cd0) >> 128;
            if (absTick & 0x10 != 0) ratio = (ratio * 0xffcb9843d60f6159c9db58835c926644) >> 128;
            if (absTick & 0x20 != 0) ratio = (ratio * 0xff973b41fa98c081472e6896dfb254c0) >> 128;
            if (absTick & 0x40 != 0) ratio = (ratio * 0xff2ea16466c96a3843ec78b326b52861) >> 128;
            if (absTick & 0x80 != 0) ratio = (ratio * 0xfe5dee046a99a2a811c461f1969c3053) >> 128;
            if (absTick & 0x100 != 0) ratio = (ratio * 0xfcbe86c7900a88aedcffc83b479aa3a4) >> 128;
            if (absTick & 0x200 != 0) ratio = (ratio * 0xf987a7253ac413176f2b074cf7815e54) >> 128;
            if (absTick & 0x400 != 0) ratio = (ratio * 0xf3392b0822b70005940c7a398e4b70f3) >> 128;
            if (absTick & 0x800 != 0) ratio = (ratio * 0xe7159475a2c29b7443b29c7fa6e889d9) >> 128;
            if (absTick & 0x1000 != 0) ratio = (ratio * 0xd097f3bdfd2022b8845ad8f792aa5825) >> 128;
            if (absTick & 0x2000 != 0) ratio = (ratio * 0xa9f746462d870fdf8a65dc1f90e061e5) >> 128;
            if (absTick & 0x4000 != 0) ratio = (ratio * 0x70d869a156d2a1b890bb3df62baf32f7) >> 128;
            if (absTick & 0x8000 != 0) ratio = (ratio * 0x31be135f97d08fd981231505542fcfa6) >> 128;
            if (absTick & 0x10000 != 0) ratio = (ratio * 0x9aa508b5b7a84e1c677de54f3e99bc9) >> 128;
            if (absTick & 0x20000 != 0) ratio = (ratio * 0x5d6af8dedb81196699c329225ee604) >> 128;
            if (absTick & 0x40000 != 0) ratio = (ratio * 0x2216e584f5fa1ea926041bedfe98) >> 128;
            if (absTick & 0x80000 != 0) ratio = (ratio * 0x48a170391f7dc42444e8fa2) >> 128;

            if (tick > 0) ratio = type(uint256).max / ratio;

            // this divides by 1<<32 rounding up to go from a Q128.128 to a Q128.96.
            // we then downcast because we know the result always fits within 160 bits due to our tick input constraint
            // we round up in the division so getTickAtSqrtRatio of the output price is always consistent
            sqrtPriceX96 = uint160((ratio >> 32) + (ratio % (1 << 32) == 0 ? 0 : 1));
        }
    }

    /// @notice Calculates the greatest tick value such that getRatioAtTick(tick) <= ratio
    /// @dev Throws in case sqrtPriceX96 < MIN_SQRT_RATIO, as MIN_SQRT_RATIO is the lowest value getRatioAtTick may
    /// ever return.
    /// @param sqrtPriceX96 The sqrt ratio for which to compute the tick as a Q64.96
    /// @return tick The greatest tick for which the ratio is less than or equal to the input ratio
    function getTickAtSqrtRatio(uint160 sqrtPriceX96) internal pure returns (int24 tick) {
        unchecked {
            // second inequality must be < because the price can never reach the price at the max tick
            if (!(sqrtPriceX96 >= MIN_SQRT_RATIO && sqrtPriceX96 < MAX_SQRT_RATIO)) revert R();
            uint256 ratio = uint256(sqrtPriceX96) << 32;

            uint256 r = ratio;
            uint256 msb = 0;

            assembly {
                let f := shl(7, gt(r, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))
                msb := or(msb, f)
                r := shr(f, r)
            }
            assembly {
                let f := shl(6, gt(r, 0xFFFFFFFFFFFFFFFF))
                msb := or(msb, f)
                r := shr(f, r)
            }
            assembly {
                let f := shl(5, gt(r, 0xFFFFFFFF))
                msb := or(msb, f)
                r := shr(f, r)
            }
            assembly {
                let f := shl(4, gt(r, 0xFFFF))
                msb := or(msb, f)
                r := shr(f, r)
            }
            assembly {
                let f := shl(3, gt(r, 0xFF))
                msb := or(msb, f)
                r := shr(f, r)
            }
            assembly {
                let f := shl(2, gt(r, 0xF))
                msb := or(msb, f)
                r := shr(f, r)
            }
            assembly {
                let f := shl(1, gt(r, 0x3))
                msb := or(msb, f)
                r := shr(f, r)
            }
            assembly {
                let f := gt(r, 0x1)
                msb := or(msb, f)
            }

            if (msb >= 128) r = ratio >> (msb - 127);
            else r = ratio << (127 - msb);

            int256 log_2 = (int256(msb) - 128) << 64;

            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(63, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(62, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(61, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(60, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(59, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(58, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(57, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(56, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(55, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(54, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(53, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(52, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(51, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(50, f))
            }

            int256 log_sqrt10001 = log_2 * 255738958999603826347141; // 128.128 number

            int24 tickLow = int24((log_sqrt10001 - 3402992956809132418596140100660247210) >> 128);
            int24 tickHi = int24((log_sqrt10001 + 291339464771989622907027621153398088495) >> 128);

            tick = tickLow == tickHi ? tickLow : getSqrtRatioAtTick(tickHi) <= sqrtPriceX96 ? tickHi : tickLow;
        }
    }
}

// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.18;

interface IAuction {
    event AuctionDisabled(address indexed from, address indexed to);
    event AuctionEnabled(address indexed from, address indexed to);
    event AuctionKicked(address from, uint256 available);
    event GovernanceTransferred(
        address indexed previousGovernance,
        address indexed newGovernance
    );
    event UpdatePendingGovernance(address indexed newPendingGovernance);
    event UpdatedStartingPrice(uint256 startingPrice);

    struct AuctionInfo {
        uint64 kicked;
        uint64 scaler;
        uint128 initialAvailable;
    }

    function acceptGovernance() external;
    function auctionLength() external view returns (uint256);
    function auctions(address) external view returns (AuctionInfo memory);
    function available(address _from) external view returns (uint256);
    function disable(address _from) external;
    function disable(address _from, uint256 _index) external;
    function enable(address _from) external;
    function enabledAuctions(uint256) external view returns (address);
    function getAllEnabledAuctions() external view returns (address[] memory);
    function getAmountNeeded(address _from) external view returns (uint256);
    function getAmountNeeded(
        address _from,
        uint256 _amountToTake,
        uint256 _timestamp
    ) external view returns (uint256);
    function getAmountNeeded(
        address _from,
        uint256 _amountToTake
    ) external view returns (uint256);
    function governance() external view returns (address);
    function initialize(
        address _want,
        address _receiver,
        address _governance,
        uint256 _auctionLength,
        uint256 _startingPrice
    ) external;
    function isActive(address _from) external view returns (bool);
    function isValidSignature(
        bytes32 _hash,
        bytes calldata signature
    ) external view returns (bytes4);
    function kick(address _from) external returns (uint256 _available);
    function kickable(address _from) external view returns (uint256);
    function kicked(address _from) external view returns (uint256);
    function pendingGovernance() external view returns (address);
    function price(
        address _from,
        uint256 _timestamp
    ) external view returns (uint256);
    function price(address _from) external view returns (uint256);
    function receiver() external view returns (address);
    function setStartingPrice(uint256 _startingPrice) external;
    function settle(address _from) external;
    function startingPrice() external view returns (uint256);
    function sweep(address _token) external;
    function take(address _from) external returns (uint256);
    function take(address _from, uint256 _maxAmount) external returns (uint256);
    function take(
        address _from,
        uint256 _maxAmount,
        address _receiver,
        bytes calldata _data
    ) external returns (uint256);
    function take(
        address _from,
        uint256 _maxAmount,
        address _receiver
    ) external returns (uint256);
    function transferGovernance(address _newGovernance) external;
    function want() external view returns (address);
}

File 13 of 43 : IMerklDistributor.sol
pragma solidity ^0.8.18;

interface IMerklDistributor {
    /// @notice Claims rewards for a given set of users
    /// @dev Anyone may call this function for anyone else, funds go to destination regardless, it's just a question of
    /// who provides the proof and pays the gas: `msg.sender` is used only for addresses that require a trusted operator
    /// @param users Recipient of tokens
    /// @param tokens ERC20 claimed
    /// @param amounts Amount of tokens that will be sent to the corresponding users
    /// @param proofs Array of hashes bridging from a leaf `(hash of user | token | amount)` to the Merkle root
    function claim(
        address[] calldata users,
        address[] calldata tokens,
        uint256[] calldata amounts,
        bytes32[][] calldata proofs
    ) external;
}

// SPDX-License-Identifier: AGPL-3.0
pragma solidity >=0.8.18;

import {IStrategy} from "@tokenized-strategy/interfaces/IStrategy.sol";

interface IBaseHealthCheck is IStrategy {
    function doHealthCheck() external view returns (bool);

    function profitLimitRatio() external view returns (uint256);

    function lossLimitRatio() external view returns (uint256);

    function setProfitLimitRatio(uint256 _newProfitLimitRatio) external;

    function setLossLimitRatio(uint256 _newLossLimitRatio) external;

    function setDoHealthCheck(bool _doHealthCheck) external;
}

File 15 of 43 : Arrays.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.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 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 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)
        }
    }
}

// SPDX-License-Identifier: AGPL-3.0
pragma solidity >=0.8.18;

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

// TokenizedStrategy interface used for internal view delegateCalls.
import {ITokenizedStrategy} from "./interfaces/ITokenizedStrategy.sol";

/**
 * @title YearnV3 Base Strategy
 * @author yearn.finance
 * @notice
 *  BaseStrategy implements all of the required functionality to
 *  seamlessly integrate with the `TokenizedStrategy` implementation contract
 *  allowing anyone to easily build a fully permissionless ERC-4626 compliant
 *  Vault by inheriting this contract and overriding three simple functions.

 *  It utilizes an immutable proxy pattern that allows the BaseStrategy
 *  to remain simple and small. All standard logic is held within the
 *  `TokenizedStrategy` and is reused over any n strategies all using the
 *  `fallback` function to delegatecall the implementation so that strategists
 *  can only be concerned with writing their strategy specific code.
 *
 *  This contract should be inherited and the three main abstract methods
 *  `_deployFunds`, `_freeFunds` and `_harvestAndReport` implemented to adapt
 *  the Strategy to the particular needs it has to generate yield. There are
 *  other optional methods that can be implemented to further customize
 *  the strategy if desired.
 *
 *  All default storage for the strategy is controlled and updated by the
 *  `TokenizedStrategy`. The implementation holds a storage struct that
 *  contains all needed global variables in a manual storage slot. This
 *  means strategists can feel free to implement their own custom storage
 *  variables as they need with no concern of collisions. All global variables
 *  can be viewed within the Strategy by a simple call using the
 *  `TokenizedStrategy` variable. IE: TokenizedStrategy.globalVariable();.
 */
abstract contract BaseStrategy {
    /*//////////////////////////////////////////////////////////////
                            MODIFIERS
    //////////////////////////////////////////////////////////////*/
    /**
     * @dev Used on TokenizedStrategy callback functions to make sure it is post
     * a delegateCall from this address to the TokenizedStrategy.
     */
    modifier onlySelf() {
        _onlySelf();
        _;
    }

    /**
     * @dev Use to assure that the call is coming from the strategies management.
     */
    modifier onlyManagement() {
        TokenizedStrategy.requireManagement(msg.sender);
        _;
    }

    /**
     * @dev Use to assure that the call is coming from either the strategies
     * management or the keeper.
     */
    modifier onlyKeepers() {
        TokenizedStrategy.requireKeeperOrManagement(msg.sender);
        _;
    }

    /**
     * @dev Use to assure that the call is coming from either the strategies
     * management or the emergency admin.
     */
    modifier onlyEmergencyAuthorized() {
        TokenizedStrategy.requireEmergencyAuthorized(msg.sender);
        _;
    }

    /**
     * @dev Require that the msg.sender is this address.
     */
    function _onlySelf() internal view {
        require(msg.sender == address(this), "!self");
    }

    /*//////////////////////////////////////////////////////////////
                            CONSTANTS
    //////////////////////////////////////////////////////////////*/

    /**
     * @dev This is the address of the TokenizedStrategy implementation
     * contract that will be used by all strategies to handle the
     * accounting, logic, storage etc.
     *
     * Any external calls to the that don't hit one of the functions
     * defined in this base or the strategy will end up being forwarded
     * through the fallback function, which will delegateCall this address.
     *
     * This address should be the same for every strategy, never be adjusted
     * and always be checked before any integration with the Strategy.
     */
    address public constant tokenizedStrategyAddress =
        0xD377919FA87120584B21279a491F82D5265A139c;

    /*//////////////////////////////////////////////////////////////
                            IMMUTABLES
    //////////////////////////////////////////////////////////////*/

    /**
     * @dev Underlying asset the Strategy is earning yield on.
     * Stored here for cheap retrievals within the strategy.
     */
    ERC20 internal immutable asset;

    /**
     * @dev This variable is set to address(this) during initialization of each strategy.
     *
     * This can be used to retrieve storage data within the strategy
     * contract as if it were a linked library.
     *
     *       i.e. uint256 totalAssets = TokenizedStrategy.totalAssets()
     *
     * Using address(this) will mean any calls using this variable will lead
     * to a call to itself. Which will hit the fallback function and
     * delegateCall that to the actual TokenizedStrategy.
     */
    ITokenizedStrategy internal immutable TokenizedStrategy;

    /**
     * @notice Used to initialize the strategy on deployment.
     *
     * This will set the `TokenizedStrategy` variable for easy
     * internal view calls to the implementation. As well as
     * initializing the default storage variables based on the
     * parameters and using the deployer for the permissioned roles.
     *
     * @param _asset Address of the underlying asset.
     * @param _name Name the strategy will use.
     */
    constructor(address _asset, string memory _name) {
        asset = ERC20(_asset);

        // Set instance of the implementation for internal use.
        TokenizedStrategy = ITokenizedStrategy(address(this));

        // Initialize the strategy's storage variables.
        _delegateCall(
            abi.encodeCall(
                ITokenizedStrategy.initialize,
                (_asset, _name, msg.sender, msg.sender, msg.sender)
            )
        );

        // Store the tokenizedStrategyAddress at the standard implementation
        // address storage slot so etherscan picks up the interface. This gets
        // stored on initialization and never updated.
        assembly {
            sstore(
                // keccak256('eip1967.proxy.implementation' - 1)
                0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc,
                tokenizedStrategyAddress
            )
        }
    }

    /*//////////////////////////////////////////////////////////////
                NEEDED TO BE OVERRIDDEN BY STRATEGIST
    //////////////////////////////////////////////////////////////*/

    /**
     * @dev Can deploy up to '_amount' of 'asset' in the yield source.
     *
     * This function is called at the end of a {deposit} or {mint}
     * call. Meaning that unless a whitelist is implemented it will
     * be entirely permissionless and thus can be sandwiched or otherwise
     * manipulated.
     *
     * @param _amount The amount of 'asset' that the strategy can attempt
     * to deposit in the yield source.
     */
    function _deployFunds(uint256 _amount) internal virtual;

    /**
     * @dev Should attempt to free the '_amount' of 'asset'.
     *
     * NOTE: The amount of 'asset' that is already loose has already
     * been accounted for.
     *
     * This function is called during {withdraw} and {redeem} calls.
     * Meaning that unless a whitelist is implemented it will be
     * entirely permissionless and thus can be sandwiched or otherwise
     * manipulated.
     *
     * Should not rely on asset.balanceOf(address(this)) calls other than
     * for diff accounting purposes.
     *
     * Any difference between `_amount` and what is actually freed will be
     * counted as a loss and passed on to the withdrawer. This means
     * care should be taken in times of illiquidity. It may be better to revert
     * if withdraws are simply illiquid so not to realize incorrect losses.
     *
     * @param _amount, The amount of 'asset' to be freed.
     */
    function _freeFunds(uint256 _amount) internal virtual;

    /**
     * @dev Internal function to harvest all rewards, redeploy any idle
     * funds and return an accurate accounting of all funds currently
     * held by the Strategy.
     *
     * This should do any needed harvesting, rewards selling, accrual,
     * redepositing etc. to get the most accurate view of current assets.
     *
     * NOTE: All applicable assets including loose assets should be
     * accounted for in this function.
     *
     * Care should be taken when relying on oracles or swap values rather
     * than actual amounts as all Strategy profit/loss accounting will
     * be done based on this returned value.
     *
     * This can still be called post a shutdown, a strategist can check
     * `TokenizedStrategy.isShutdown()` to decide if funds should be
     * redeployed or simply realize any profits/losses.
     *
     * @return _totalAssets A trusted and accurate account for the total
     * amount of 'asset' the strategy currently holds including idle funds.
     */
    function _harvestAndReport()
        internal
        virtual
        returns (uint256 _totalAssets);

    /*//////////////////////////////////////////////////////////////
                    OPTIONAL TO OVERRIDE BY STRATEGIST
    //////////////////////////////////////////////////////////////*/

    /**
     * @dev Optional function for strategist to override that can
     *  be called in between reports.
     *
     * If '_tend' is used tendTrigger() will also need to be overridden.
     *
     * This call can only be called by a permissioned role so may be
     * through protected relays.
     *
     * This can be used to harvest and compound rewards, deposit idle funds,
     * perform needed position maintenance or anything else that doesn't need
     * a full report for.
     *
     *   EX: A strategy that can not deposit funds without getting
     *       sandwiched can use the tend when a certain threshold
     *       of idle to totalAssets has been reached.
     *
     * This will have no effect on PPS of the strategy till report() is called.
     *
     * @param _totalIdle The current amount of idle funds that are available to deploy.
     */
    function _tend(uint256 _totalIdle) internal virtual {}

    /**
     * @dev Optional trigger to override if tend() will be used by the strategy.
     * This must be implemented if the strategy hopes to invoke _tend().
     *
     * @return . Should return true if tend() should be called by keeper or false if not.
     */
    function _tendTrigger() internal view virtual returns (bool) {
        return false;
    }

    /**
     * @notice Returns if tend() should be called by a keeper.
     *
     * @return . Should return true if tend() should be called by keeper or false if not.
     * @return . Calldata for the tend call.
     */
    function tendTrigger() external view virtual returns (bool, bytes memory) {
        return (
            // Return the status of the tend trigger.
            _tendTrigger(),
            // And the needed calldata either way.
            abi.encodeWithSelector(ITokenizedStrategy.tend.selector)
        );
    }

    /**
     * @notice Gets the max amount of `asset` that an address can deposit.
     * @dev Defaults to an unlimited amount for any address. But can
     * be overridden by strategists.
     *
     * This function will be called before any deposit or mints to enforce
     * any limits desired by the strategist. This can be used for either a
     * traditional deposit limit or for implementing a whitelist etc.
     *
     *   EX:
     *      if(isAllowed[_owner]) return super.availableDepositLimit(_owner);
     *
     * This does not need to take into account any conversion rates
     * from shares to assets. But should know that any non max uint256
     * amounts may be converted to shares. So it is recommended to keep
     * custom amounts low enough as not to cause overflow when multiplied
     * by `totalSupply`.
     *
     * @param . The address that is depositing into the strategy.
     * @return . The available amount the `_owner` can deposit in terms of `asset`
     */
    function availableDepositLimit(
        address /*_owner*/
    ) public view virtual returns (uint256) {
        return type(uint256).max;
    }

    /**
     * @notice Gets the max amount of `asset` that can be withdrawn.
     * @dev Defaults to an unlimited amount for any address. But can
     * be overridden by strategists.
     *
     * This function will be called before any withdraw or redeem to enforce
     * any limits desired by the strategist. This can be used for illiquid
     * or sandwichable strategies. It should never be lower than `totalIdle`.
     *
     *   EX:
     *       return TokenIzedStrategy.totalIdle();
     *
     * This does not need to take into account the `_owner`'s share balance
     * or conversion rates from shares to assets.
     *
     * @param . The address that is withdrawing from the strategy.
     * @return . The available amount that can be withdrawn in terms of `asset`
     */
    function availableWithdrawLimit(
        address /*_owner*/
    ) public view virtual returns (uint256) {
        return type(uint256).max;
    }

    /**
     * @dev Optional function for a strategist to override that will
     * allow management to manually withdraw deployed funds from the
     * yield source if a strategy is shutdown.
     *
     * This should attempt to free `_amount`, noting that `_amount` may
     * be more than is currently deployed.
     *
     * NOTE: This will not realize any profits or losses. A separate
     * {report} will be needed in order to record any profit/loss. If
     * a report may need to be called after a shutdown it is important
     * to check if the strategy is shutdown during {_harvestAndReport}
     * so that it does not simply re-deploy all funds that had been freed.
     *
     * EX:
     *   if(freeAsset > 0 && !TokenizedStrategy.isShutdown()) {
     *       depositFunds...
     *    }
     *
     * @param _amount The amount of asset to attempt to free.
     */
    function _emergencyWithdraw(uint256 _amount) internal virtual {}

    /*//////////////////////////////////////////////////////////////
                        TokenizedStrategy HOOKS
    //////////////////////////////////////////////////////////////*/

    /**
     * @notice Can deploy up to '_amount' of 'asset' in yield source.
     * @dev Callback for the TokenizedStrategy to call during a {deposit}
     * or {mint} to tell the strategy it can deploy funds.
     *
     * Since this can only be called after a {deposit} or {mint}
     * delegateCall to the TokenizedStrategy msg.sender == address(this).
     *
     * Unless a whitelist is implemented this will be entirely permissionless
     * and thus can be sandwiched or otherwise manipulated.
     *
     * @param _amount The amount of 'asset' that the strategy can
     * attempt to deposit in the yield source.
     */
    function deployFunds(uint256 _amount) external virtual onlySelf {
        _deployFunds(_amount);
    }

    /**
     * @notice Should attempt to free the '_amount' of 'asset'.
     * @dev Callback for the TokenizedStrategy to call during a withdraw
     * or redeem to free the needed funds to service the withdraw.
     *
     * This can only be called after a 'withdraw' or 'redeem' delegateCall
     * to the TokenizedStrategy so msg.sender == address(this).
     *
     * @param _amount The amount of 'asset' that the strategy should attempt to free up.
     */
    function freeFunds(uint256 _amount) external virtual onlySelf {
        _freeFunds(_amount);
    }

    /**
     * @notice Returns the accurate amount of all funds currently
     * held by the Strategy.
     * @dev Callback for the TokenizedStrategy to call during a report to
     * get an accurate accounting of assets the strategy controls.
     *
     * This can only be called after a report() delegateCall to the
     * TokenizedStrategy so msg.sender == address(this).
     *
     * @return . A trusted and accurate account for the total amount
     * of 'asset' the strategy currently holds including idle funds.
     */
    function harvestAndReport() external virtual onlySelf returns (uint256) {
        return _harvestAndReport();
    }

    /**
     * @notice Will call the internal '_tend' when a keeper tends the strategy.
     * @dev Callback for the TokenizedStrategy to initiate a _tend call in the strategy.
     *
     * This can only be called after a tend() delegateCall to the TokenizedStrategy
     * so msg.sender == address(this).
     *
     * We name the function `tendThis` so that `tend` calls are forwarded to
     * the TokenizedStrategy.

     * @param _totalIdle The amount of current idle funds that can be
     * deployed during the tend
     */
    function tendThis(uint256 _totalIdle) external virtual onlySelf {
        _tend(_totalIdle);
    }

    /**
     * @notice Will call the internal '_emergencyWithdraw' function.
     * @dev Callback for the TokenizedStrategy during an emergency withdraw.
     *
     * This can only be called after a emergencyWithdraw() delegateCall to
     * the TokenizedStrategy so msg.sender == address(this).
     *
     * We name the function `shutdownWithdraw` so that `emergencyWithdraw`
     * calls are forwarded to the TokenizedStrategy.
     *
     * @param _amount The amount of asset to attempt to free.
     */
    function shutdownWithdraw(uint256 _amount) external virtual onlySelf {
        _emergencyWithdraw(_amount);
    }

    /**
     * @dev Function used to delegate call the TokenizedStrategy with
     * certain `_calldata` and return any return values.
     *
     * This is used to setup the initial storage of the strategy, and
     * can be used by strategist to forward any other call to the
     * TokenizedStrategy implementation.
     *
     * @param _calldata The abi encoded calldata to use in delegatecall.
     * @return . The return value if the call was successful in bytes.
     */
    function _delegateCall(
        bytes memory _calldata
    ) internal returns (bytes memory) {
        // Delegate call the tokenized strategy with provided calldata.
        (bool success, bytes memory result) = tokenizedStrategyAddress
            .delegatecall(_calldata);

        // If the call reverted. Return the error.
        if (!success) {
            assembly {
                let ptr := mload(0x40)
                let size := returndatasize()
                returndatacopy(ptr, 0, size)
                revert(ptr, size)
            }
        }

        // Return the result.
        return result;
    }

    /**
     * @dev Execute a function on the TokenizedStrategy and return any value.
     *
     * This fallback function will be executed when any of the standard functions
     * defined in the TokenizedStrategy are called since they wont be defined in
     * this contract.
     *
     * It will delegatecall the TokenizedStrategy implementation with the exact
     * calldata and return any relevant values.
     *
     */
    fallback() external {
        // load our target address
        address _tokenizedStrategyAddress = tokenizedStrategyAddress;
        // Execute external function using delegatecall and return any value.
        assembly {
            // Copy function selector and any arguments.
            calldatacopy(0, 0, calldatasize())
            // Execute function delegatecall.
            let result := delegatecall(
                gas(),
                _tokenizedStrategyAddress,
                0,
                calldatasize(),
                0,
                0
            )
            // Get any return value
            returndatacopy(0, 0, returndatasize())
            // Return any return value or error back to the caller
            switch result
            case 0 {
                revert(0, returndatasize())
            }
            default {
                return(0, returndatasize())
            }
        }
    }
}

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

pragma solidity ^0.8.20;

/**
 * @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) (interfaces/IERC1363.sol)

pragma solidity ^0.8.20;

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: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Pool state that never changes
/// @notice These parameters are fixed for a pool forever, i.e., the methods will always return the same values
interface IUniswapV3PoolImmutables {
    /// @notice The contract that deployed the pool, which must adhere to the IUniswapV3Factory interface
    /// @return The contract address
    function factory() external view returns (address);

    /// @notice The first of the two tokens of the pool, sorted by address
    /// @return The token contract address
    function token0() external view returns (address);

    /// @notice The second of the two tokens of the pool, sorted by address
    /// @return The token contract address
    function token1() external view returns (address);

    /// @notice The pool's fee in hundredths of a bip, i.e. 1e-6
    /// @return The fee
    function fee() external view returns (uint24);

    /// @notice The pool tick spacing
    /// @dev Ticks can only be used at multiples of this value, minimum of 1 and always positive
    /// e.g.: a tickSpacing of 3 means ticks can be initialized every 3rd tick, i.e., ..., -6, -3, 0, 3, 6, ...
    /// This value is an int24 to avoid casting even though it is always positive.
    /// @return The tick spacing
    function tickSpacing() external view returns (int24);

    /// @notice The maximum amount of position liquidity that can use any tick in the range
    /// @dev This parameter is enforced per tick to prevent liquidity from overflowing a uint128 at any point, and
    /// also prevents out-of-range liquidity from being used to prevent adding in-range liquidity to a pool
    /// @return The max amount of liquidity per tick
    function maxLiquidityPerTick() external view returns (uint128);
}

// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Pool state that can change
/// @notice These methods compose the pool's state, and can change with any frequency including multiple times
/// per transaction
interface IUniswapV3PoolState {
    /// @notice The 0th storage slot in the pool stores many values, and is exposed as a single method to save gas
    /// when accessed externally.
    /// @return sqrtPriceX96 The current price of the pool as a sqrt(token1/token0) Q64.96 value
    /// @return tick The current tick of the pool, i.e. according to the last tick transition that was run.
    /// This value may not always be equal to SqrtTickMath.getTickAtSqrtRatio(sqrtPriceX96) if the price is on a tick
    /// boundary.
    /// @return observationIndex The index of the last oracle observation that was written,
    /// @return observationCardinality The current maximum number of observations stored in the pool,
    /// @return observationCardinalityNext The next maximum number of observations, to be updated when the observation.
    /// @return feeProtocol The protocol fee for both tokens of the pool.
    /// Encoded as two 4 bit values, where the protocol fee of token1 is shifted 4 bits and the protocol fee of token0
    /// is the lower 4 bits. Used as the denominator of a fraction of the swap fee, e.g. 4 means 1/4th of the swap fee.
    /// unlocked Whether the pool is currently locked to reentrancy
    function slot0()
        external
        view
        returns (
            uint160 sqrtPriceX96,
            int24 tick,
            uint16 observationIndex,
            uint16 observationCardinality,
            uint16 observationCardinalityNext,
            uint8 feeProtocol,
            bool unlocked
        );

    /// @notice The fee growth as a Q128.128 fees of token0 collected per unit of liquidity for the entire life of the pool
    /// @dev This value can overflow the uint256
    function feeGrowthGlobal0X128() external view returns (uint256);

    /// @notice The fee growth as a Q128.128 fees of token1 collected per unit of liquidity for the entire life of the pool
    /// @dev This value can overflow the uint256
    function feeGrowthGlobal1X128() external view returns (uint256);

    /// @notice The amounts of token0 and token1 that are owed to the protocol
    /// @dev Protocol fees will never exceed uint128 max in either token
    function protocolFees() external view returns (uint128 token0, uint128 token1);

    /// @notice The currently in range liquidity available to the pool
    /// @dev This value has no relationship to the total liquidity across all ticks
    /// @return The liquidity at the current price of the pool
    function liquidity() external view returns (uint128);

    /// @notice Look up information about a specific tick in the pool
    /// @param tick The tick to look up
    /// @return liquidityGross the total amount of position liquidity that uses the pool either as tick lower or
    /// tick upper
    /// @return liquidityNet how much liquidity changes when the pool price crosses the tick,
    /// @return feeGrowthOutside0X128 the fee growth on the other side of the tick from the current tick in token0,
    /// @return feeGrowthOutside1X128 the fee growth on the other side of the tick from the current tick in token1,
    /// @return tickCumulativeOutside the cumulative tick value on the other side of the tick from the current tick
    /// @return secondsPerLiquidityOutsideX128 the seconds spent per liquidity on the other side of the tick from the current tick,
    /// @return secondsOutside the seconds spent on the other side of the tick from the current tick,
    /// @return initialized Set to true if the tick is initialized, i.e. liquidityGross is greater than 0, otherwise equal to false.
    /// Outside values can only be used if the tick is initialized, i.e. if liquidityGross is greater than 0.
    /// In addition, these values are only relative and must be used only in comparison to previous snapshots for
    /// a specific position.
    function ticks(int24 tick)
        external
        view
        returns (
            uint128 liquidityGross,
            int128 liquidityNet,
            uint256 feeGrowthOutside0X128,
            uint256 feeGrowthOutside1X128,
            int56 tickCumulativeOutside,
            uint160 secondsPerLiquidityOutsideX128,
            uint32 secondsOutside,
            bool initialized
        );

    /// @notice Returns 256 packed tick initialized boolean values. See TickBitmap for more information
    function tickBitmap(int16 wordPosition) external view returns (uint256);

    /// @notice Returns the information about a position by the position's key
    /// @param key The position's key is a hash of a preimage composed by the owner, tickLower and tickUpper
    /// @return liquidity The amount of liquidity in the position,
    /// @return feeGrowthInside0LastX128 fee growth of token0 inside the tick range as of the last mint/burn/poke,
    /// @return feeGrowthInside1LastX128 fee growth of token1 inside the tick range as of the last mint/burn/poke,
    /// @return tokensOwed0 the computed amount of token0 owed to the position as of the last mint/burn/poke,
    /// @return tokensOwed1 the computed amount of token1 owed to the position as of the last mint/burn/poke
    function positions(bytes32 key)
        external
        view
        returns (
            uint128 liquidity,
            uint256 feeGrowthInside0LastX128,
            uint256 feeGrowthInside1LastX128,
            uint128 tokensOwed0,
            uint128 tokensOwed1
        );

    /// @notice Returns data about a specific observation index
    /// @param index The element of the observations array to fetch
    /// @dev You most likely want to use #observe() instead of this method to get an observation as of some amount of time
    /// ago, rather than at a specific index in the array.
    /// @return blockTimestamp The timestamp of the observation,
    /// @return tickCumulative the tick multiplied by seconds elapsed for the life of the pool as of the observation timestamp,
    /// @return secondsPerLiquidityCumulativeX128 the seconds per in range liquidity for the life of the pool as of the observation timestamp,
    /// @return initialized whether the observation has been initialized and the values are safe to use
    function observations(uint256 index)
        external
        view
        returns (
            uint32 blockTimestamp,
            int56 tickCumulative,
            uint160 secondsPerLiquidityCumulativeX128,
            bool initialized
        );
}

// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Pool state that is not stored
/// @notice Contains view functions to provide information about the pool that is computed rather than stored on the
/// blockchain. The functions here may have variable gas costs.
interface IUniswapV3PoolDerivedState {
    /// @notice Returns the cumulative tick and liquidity as of each timestamp `secondsAgo` from the current block timestamp
    /// @dev To get a time weighted average tick or liquidity-in-range, you must call this with two values, one representing
    /// the beginning of the period and another for the end of the period. E.g., to get the last hour time-weighted average tick,
    /// you must call it with secondsAgos = [3600, 0].
    /// @dev The time weighted average tick represents the geometric time weighted average price of the pool, in
    /// log base sqrt(1.0001) of token1 / token0. The TickMath library can be used to go from a tick value to a ratio.
    /// @param secondsAgos From how long ago each cumulative tick and liquidity value should be returned
    /// @return tickCumulatives Cumulative tick values as of each `secondsAgos` from the current block timestamp
    /// @return secondsPerLiquidityCumulativeX128s Cumulative seconds per liquidity-in-range value as of each `secondsAgos` from the current block
    /// timestamp
    function observe(uint32[] calldata secondsAgos)
        external
        view
        returns (int56[] memory tickCumulatives, uint160[] memory secondsPerLiquidityCumulativeX128s);

    /// @notice Returns a snapshot of the tick cumulative, seconds per liquidity and seconds inside a tick range
    /// @dev Snapshots must only be compared to other snapshots, taken over a period for which a position existed.
    /// I.e., snapshots cannot be compared if a position is not held for the entire period between when the first
    /// snapshot is taken and the second snapshot is taken.
    /// @param tickLower The lower tick of the range
    /// @param tickUpper The upper tick of the range
    /// @return tickCumulativeInside The snapshot of the tick accumulator for the range
    /// @return secondsPerLiquidityInsideX128 The snapshot of seconds per liquidity for the range
    /// @return secondsInside The snapshot of seconds per liquidity for the range
    function snapshotCumulativesInside(int24 tickLower, int24 tickUpper)
        external
        view
        returns (
            int56 tickCumulativeInside,
            uint160 secondsPerLiquidityInsideX128,
            uint32 secondsInside
        );
}

// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Permissionless pool actions
/// @notice Contains pool methods that can be called by anyone
interface IUniswapV3PoolActions {
    /// @notice Sets the initial price for the pool
    /// @dev Price is represented as a sqrt(amountToken1/amountToken0) Q64.96 value
    /// @param sqrtPriceX96 the initial sqrt price of the pool as a Q64.96
    function initialize(uint160 sqrtPriceX96) external;

    /// @notice Adds liquidity for the given recipient/tickLower/tickUpper position
    /// @dev The caller of this method receives a callback in the form of IUniswapV3MintCallback#uniswapV3MintCallback
    /// in which they must pay any token0 or token1 owed for the liquidity. The amount of token0/token1 due depends
    /// on tickLower, tickUpper, the amount of liquidity, and the current price.
    /// @param recipient The address for which the liquidity will be created
    /// @param tickLower The lower tick of the position in which to add liquidity
    /// @param tickUpper The upper tick of the position in which to add liquidity
    /// @param amount The amount of liquidity to mint
    /// @param data Any data that should be passed through to the callback
    /// @return amount0 The amount of token0 that was paid to mint the given amount of liquidity. Matches the value in the callback
    /// @return amount1 The amount of token1 that was paid to mint the given amount of liquidity. Matches the value in the callback
    function mint(
        address recipient,
        int24 tickLower,
        int24 tickUpper,
        uint128 amount,
        bytes calldata data
    ) external returns (uint256 amount0, uint256 amount1);

    /// @notice Collects tokens owed to a position
    /// @dev Does not recompute fees earned, which must be done either via mint or burn of any amount of liquidity.
    /// Collect must be called by the position owner. To withdraw only token0 or only token1, amount0Requested or
    /// amount1Requested may be set to zero. To withdraw all tokens owed, caller may pass any value greater than the
    /// actual tokens owed, e.g. type(uint128).max. Tokens owed may be from accumulated swap fees or burned liquidity.
    /// @param recipient The address which should receive the fees collected
    /// @param tickLower The lower tick of the position for which to collect fees
    /// @param tickUpper The upper tick of the position for which to collect fees
    /// @param amount0Requested How much token0 should be withdrawn from the fees owed
    /// @param amount1Requested How much token1 should be withdrawn from the fees owed
    /// @return amount0 The amount of fees collected in token0
    /// @return amount1 The amount of fees collected in token1
    function collect(
        address recipient,
        int24 tickLower,
        int24 tickUpper,
        uint128 amount0Requested,
        uint128 amount1Requested
    ) external returns (uint128 amount0, uint128 amount1);

    /// @notice Burn liquidity from the sender and account tokens owed for the liquidity to the position
    /// @dev Can be used to trigger a recalculation of fees owed to a position by calling with an amount of 0
    /// @dev Fees must be collected separately via a call to #collect
    /// @param tickLower The lower tick of the position for which to burn liquidity
    /// @param tickUpper The upper tick of the position for which to burn liquidity
    /// @param amount How much liquidity to burn
    /// @return amount0 The amount of token0 sent to the recipient
    /// @return amount1 The amount of token1 sent to the recipient
    function burn(
        int24 tickLower,
        int24 tickUpper,
        uint128 amount
    ) external returns (uint256 amount0, uint256 amount1);

    /// @notice Swap token0 for token1, or token1 for token0
    /// @dev The caller of this method receives a callback in the form of IUniswapV3SwapCallback#uniswapV3SwapCallback
    /// @param recipient The address to receive the output of the swap
    /// @param zeroForOne The direction of the swap, true for token0 to token1, false for token1 to token0
    /// @param amountSpecified The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative)
    /// @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this
    /// value after the swap. If one for zero, the price cannot be greater than this value after the swap
    /// @param data Any data to be passed through to the callback
    /// @return amount0 The delta of the balance of token0 of the pool, exact when negative, minimum when positive
    /// @return amount1 The delta of the balance of token1 of the pool, exact when negative, minimum when positive
    function swap(
        address recipient,
        bool zeroForOne,
        int256 amountSpecified,
        uint160 sqrtPriceLimitX96,
        bytes calldata data
    ) external returns (int256 amount0, int256 amount1);

    /// @notice Receive token0 and/or token1 and pay it back, plus a fee, in the callback
    /// @dev The caller of this method receives a callback in the form of IUniswapV3FlashCallback#uniswapV3FlashCallback
    /// @dev Can be used to donate underlying tokens pro-rata to currently in-range liquidity providers by calling
    /// with 0 amount{0,1} and sending the donation amount(s) from the callback
    /// @param recipient The address which will receive the token0 and token1 amounts
    /// @param amount0 The amount of token0 to send
    /// @param amount1 The amount of token1 to send
    /// @param data Any data to be passed through to the callback
    function flash(
        address recipient,
        uint256 amount0,
        uint256 amount1,
        bytes calldata data
    ) external;

    /// @notice Increase the maximum number of price and liquidity observations that this pool will store
    /// @dev This method is no-op if the pool already has an observationCardinalityNext greater than or equal to
    /// the input observationCardinalityNext.
    /// @param observationCardinalityNext The desired minimum number of observations for the pool to store
    function increaseObservationCardinalityNext(uint16 observationCardinalityNext) external;
}

// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Permissioned pool actions
/// @notice Contains pool methods that may only be called by the factory owner
interface IUniswapV3PoolOwnerActions {
    /// @notice Set the denominator of the protocol's % share of the fees
    /// @param feeProtocol0 new protocol fee for token0 of the pool
    /// @param feeProtocol1 new protocol fee for token1 of the pool
    function setFeeProtocol(uint8 feeProtocol0, uint8 feeProtocol1) external;

    /// @notice Collect the protocol fee accrued to the pool
    /// @param recipient The address to which collected protocol fees should be sent
    /// @param amount0Requested The maximum amount of token0 to send, can be 0 to collect fees in only token1
    /// @param amount1Requested The maximum amount of token1 to send, can be 0 to collect fees in only token0
    /// @return amount0 The protocol fee collected in token0
    /// @return amount1 The protocol fee collected in token1
    function collectProtocol(
        address recipient,
        uint128 amount0Requested,
        uint128 amount1Requested
    ) external returns (uint128 amount0, uint128 amount1);
}

File 24 of 43 : IUniswapV3PoolErrors.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Errors emitted by a pool
/// @notice Contains all events emitted by the pool
interface IUniswapV3PoolErrors {
    error LOK();
    error TLU();
    error TLM();
    error TUM();
    error AI();
    error M0();
    error M1();
    error AS();
    error IIA();
    error L();
    error F0();
    error F1();
}

File 25 of 43 : IUniswapV3PoolEvents.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Events emitted by a pool
/// @notice Contains all events emitted by the pool
interface IUniswapV3PoolEvents {
    /// @notice Emitted exactly once by a pool when #initialize is first called on the pool
    /// @dev Mint/Burn/Swap cannot be emitted by the pool before Initialize
    /// @param sqrtPriceX96 The initial sqrt price of the pool, as a Q64.96
    /// @param tick The initial tick of the pool, i.e. log base 1.0001 of the starting price of the pool
    event Initialize(uint160 sqrtPriceX96, int24 tick);

    /// @notice Emitted when liquidity is minted for a given position
    /// @param sender The address that minted the liquidity
    /// @param owner The owner of the position and recipient of any minted liquidity
    /// @param tickLower The lower tick of the position
    /// @param tickUpper The upper tick of the position
    /// @param amount The amount of liquidity minted to the position range
    /// @param amount0 How much token0 was required for the minted liquidity
    /// @param amount1 How much token1 was required for the minted liquidity
    event Mint(
        address sender,
        address indexed owner,
        int24 indexed tickLower,
        int24 indexed tickUpper,
        uint128 amount,
        uint256 amount0,
        uint256 amount1
    );

    /// @notice Emitted when fees are collected by the owner of a position
    /// @dev Collect events may be emitted with zero amount0 and amount1 when the caller chooses not to collect fees
    /// @param owner The owner of the position for which fees are collected
    /// @param tickLower The lower tick of the position
    /// @param tickUpper The upper tick of the position
    /// @param amount0 The amount of token0 fees collected
    /// @param amount1 The amount of token1 fees collected
    event Collect(
        address indexed owner,
        address recipient,
        int24 indexed tickLower,
        int24 indexed tickUpper,
        uint128 amount0,
        uint128 amount1
    );

    /// @notice Emitted when a position's liquidity is removed
    /// @dev Does not withdraw any fees earned by the liquidity position, which must be withdrawn via #collect
    /// @param owner The owner of the position for which liquidity is removed
    /// @param tickLower The lower tick of the position
    /// @param tickUpper The upper tick of the position
    /// @param amount The amount of liquidity to remove
    /// @param amount0 The amount of token0 withdrawn
    /// @param amount1 The amount of token1 withdrawn
    event Burn(
        address indexed owner,
        int24 indexed tickLower,
        int24 indexed tickUpper,
        uint128 amount,
        uint256 amount0,
        uint256 amount1
    );

    /// @notice Emitted by the pool for any swaps between token0 and token1
    /// @param sender The address that initiated the swap call, and that received the callback
    /// @param recipient The address that received the output of the swap
    /// @param amount0 The delta of the token0 balance of the pool
    /// @param amount1 The delta of the token1 balance of the pool
    /// @param sqrtPriceX96 The sqrt(price) of the pool after the swap, as a Q64.96
    /// @param liquidity The liquidity of the pool after the swap
    /// @param tick The log base 1.0001 of price of the pool after the swap
    event Swap(
        address indexed sender,
        address indexed recipient,
        int256 amount0,
        int256 amount1,
        uint160 sqrtPriceX96,
        uint128 liquidity,
        int24 tick
    );

    /// @notice Emitted by the pool for any flashes of token0/token1
    /// @param sender The address that initiated the swap call, and that received the callback
    /// @param recipient The address that received the tokens from flash
    /// @param amount0 The amount of token0 that was flashed
    /// @param amount1 The amount of token1 that was flashed
    /// @param paid0 The amount of token0 paid for the flash, which can exceed the amount0 plus the fee
    /// @param paid1 The amount of token1 paid for the flash, which can exceed the amount1 plus the fee
    event Flash(
        address indexed sender,
        address indexed recipient,
        uint256 amount0,
        uint256 amount1,
        uint256 paid0,
        uint256 paid1
    );

    /// @notice Emitted by the pool for increases to the number of observations that can be stored
    /// @dev observationCardinalityNext is not the observation cardinality until an observation is written at the index
    /// just before a mint/swap/burn.
    /// @param observationCardinalityNextOld The previous value of the next observation cardinality
    /// @param observationCardinalityNextNew The updated value of the next observation cardinality
    event IncreaseObservationCardinalityNext(
        uint16 observationCardinalityNextOld,
        uint16 observationCardinalityNextNew
    );

    /// @notice Emitted when the protocol fee is changed by the pool
    /// @param feeProtocol0Old The previous value of the token0 protocol fee
    /// @param feeProtocol1Old The previous value of the token1 protocol fee
    /// @param feeProtocol0New The updated value of the token0 protocol fee
    /// @param feeProtocol1New The updated value of the token1 protocol fee
    event SetFeeProtocol(uint8 feeProtocol0Old, uint8 feeProtocol1Old, uint8 feeProtocol0New, uint8 feeProtocol1New);

    /// @notice Emitted when the collected protocol fees are withdrawn by the factory owner
    /// @param sender The address that collects the protocol fees
    /// @param recipient The address that receives the collected protocol fees
    /// @param amount0 The amount of token0 protocol fees that is withdrawn
    /// @param amount0 The amount of token1 protocol fees that is withdrawn
    event CollectProtocol(address indexed sender, address indexed recipient, uint128 amount0, uint128 amount1);
}

File 26 of 43 : IStrategy.sol
// SPDX-License-Identifier: AGPL-3.0
pragma solidity >=0.8.18;

import {ITokenizedStrategy} from "./ITokenizedStrategy.sol";
import {IBaseStrategy} from "./IBaseStrategy.sol";

interface IStrategy is IBaseStrategy, ITokenizedStrategy {}

// 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
        }
    }
}

File 30 of 43 : 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.3.0) (token/ERC20/ERC20.sol)

pragma solidity ^0.8.20;

import {IERC20} from "./IERC20.sol";
import {IERC20Metadata} from "./extensions/IERC20Metadata.sol";
import {Context} from "../../utils/Context.sol";
import {IERC20Errors} from "../../interfaces/draft-IERC6093.sol";

/**
 * @dev Implementation of the {IERC20} interface.
 *
 * This implementation is agnostic to the way tokens are created. This means
 * that a supply mechanism has to be added in a derived contract using {_mint}.
 *
 * TIP: For a detailed writeup see our guide
 * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
 * to implement supply mechanisms].
 *
 * The default value of {decimals} is 18. To change this, you should override
 * this function so it returns a different value.
 *
 * We have followed general OpenZeppelin Contracts guidelines: functions revert
 * instead returning `false` on failure. This behavior is nonetheless
 * conventional and does not conflict with the expectations of ERC-20
 * applications.
 */
abstract contract ERC20 is Context, IERC20, IERC20Metadata, IERC20Errors {
    mapping(address account => uint256) private _balances;

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

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

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

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

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

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

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

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

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

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

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

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

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to`.
     *
     * This internal function is equivalent to {transfer}, and can be used to
     * e.g. implement automatic token fees, slashing mechanisms, etc.
     *
     * Emits a {Transfer} event.
     *
     * NOTE: This function is not virtual, {_update} should be overridden instead.
     */
    function _transfer(address from, address to, uint256 value) internal {
        if (from == address(0)) {
            revert ERC20InvalidSender(address(0));
        }
        if (to == address(0)) {
            revert ERC20InvalidReceiver(address(0));
        }
        _update(from, to, value);
    }

    /**
     * @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`
     * (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding
     * this function.
     *
     * Emits a {Transfer} event.
     */
    function _update(address from, address to, uint256 value) internal virtual {
        if (from == address(0)) {
            // Overflow check required: The rest of the code assumes that totalSupply never overflows
            _totalSupply += value;
        } else {
            uint256 fromBalance = _balances[from];
            if (fromBalance < value) {
                revert ERC20InsufficientBalance(from, fromBalance, value);
            }
            unchecked {
                // Overflow not possible: value <= fromBalance <= totalSupply.
                _balances[from] = fromBalance - value;
            }
        }

        if (to == address(0)) {
            unchecked {
                // Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.
                _totalSupply -= value;
            }
        } else {
            unchecked {
                // Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.
                _balances[to] += value;
            }
        }

        emit Transfer(from, to, value);
    }

    /**
     * @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).
     * Relies on the `_update` mechanism
     *
     * Emits a {Transfer} event with `from` set to the zero address.
     *
     * NOTE: This function is not virtual, {_update} should be overridden instead.
     */
    function _mint(address account, uint256 value) internal {
        if (account == address(0)) {
            revert ERC20InvalidReceiver(address(0));
        }
        _update(address(0), account, value);
    }

    /**
     * @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.
     * Relies on the `_update` mechanism.
     *
     * Emits a {Transfer} event with `to` set to the zero address.
     *
     * NOTE: This function is not virtual, {_update} should be overridden instead
     */
    function _burn(address account, uint256 value) internal {
        if (account == address(0)) {
            revert ERC20InvalidSender(address(0));
        }
        _update(account, address(0), value);
    }

    /**
     * @dev Sets `value` as the allowance of `spender` over the `owner`'s tokens.
     *
     * This internal function is equivalent to `approve`, and can be used to
     * e.g. set automatic allowances for certain subsystems, etc.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `owner` cannot be the zero address.
     * - `spender` cannot be the zero address.
     *
     * Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.
     */
    function _approve(address owner, address spender, uint256 value) internal {
        _approve(owner, spender, value, true);
    }

    /**
     * @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event.
     *
     * By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by
     * `_spendAllowance` during the `transferFrom` operation set the flag to false. This saves gas by not emitting any
     * `Approval` event during `transferFrom` operations.
     *
     * Anyone who wishes to continue emitting `Approval` events on the`transferFrom` operation can force the flag to
     * true using the following override:
     *
     * ```solidity
     * function _approve(address owner, address spender, uint256 value, bool) internal virtual override {
     *     super._approve(owner, spender, value, true);
     * }
     * ```
     *
     * Requirements are the same as {_approve}.
     */
    function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual {
        if (owner == address(0)) {
            revert ERC20InvalidApprover(address(0));
        }
        if (spender == address(0)) {
            revert ERC20InvalidSpender(address(0));
        }
        _allowances[owner][spender] = value;
        if (emitEvent) {
            emit Approval(owner, spender, value);
        }
    }

    /**
     * @dev Updates `owner`'s allowance for `spender` based on spent `value`.
     *
     * Does not update the allowance value in case of infinite allowance.
     * Revert if not enough allowance is available.
     *
     * Does not emit an {Approval} event.
     */
    function _spendAllowance(address owner, address spender, uint256 value) internal virtual {
        uint256 currentAllowance = allowance(owner, spender);
        if (currentAllowance < type(uint256).max) {
            if (currentAllowance < value) {
                revert ERC20InsufficientAllowance(spender, currentAllowance, value);
            }
            unchecked {
                _approve(owner, spender, currentAllowance - value, false);
            }
        }
    }
}

// SPDX-License-Identifier: AGPL-3.0
pragma solidity >=0.8.18;

import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {IERC4626} from "@openzeppelin/contracts/interfaces/IERC4626.sol";
import {IERC20Permit} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Permit.sol";

// Interface that implements the 4626 standard and the implementation functions
interface ITokenizedStrategy is IERC4626, IERC20Permit {
    /*//////////////////////////////////////////////////////////////
                                 EVENTS
    //////////////////////////////////////////////////////////////*/

    event StrategyShutdown();

    event NewTokenizedStrategy(
        address indexed strategy,
        address indexed asset,
        string apiVersion
    );

    event Reported(
        uint256 profit,
        uint256 loss,
        uint256 protocolFees,
        uint256 performanceFees
    );

    event UpdatePerformanceFeeRecipient(
        address indexed newPerformanceFeeRecipient
    );

    event UpdateKeeper(address indexed newKeeper);

    event UpdatePerformanceFee(uint16 newPerformanceFee);

    event UpdateManagement(address indexed newManagement);

    event UpdateEmergencyAdmin(address indexed newEmergencyAdmin);

    event UpdateProfitMaxUnlockTime(uint256 newProfitMaxUnlockTime);

    event UpdatePendingManagement(address indexed newPendingManagement);

    /*//////////////////////////////////////////////////////////////
                           INITIALIZATION
    //////////////////////////////////////////////////////////////*/

    function initialize(
        address _asset,
        string memory _name,
        address _management,
        address _performanceFeeRecipient,
        address _keeper
    ) external;

    /*//////////////////////////////////////////////////////////////
                    NON-STANDARD 4626 OPTIONS
    //////////////////////////////////////////////////////////////*/

    function withdraw(
        uint256 assets,
        address receiver,
        address owner,
        uint256 maxLoss
    ) external returns (uint256);

    function redeem(
        uint256 shares,
        address receiver,
        address owner,
        uint256 maxLoss
    ) external returns (uint256);

    function maxWithdraw(
        address owner,
        uint256 /*maxLoss*/
    ) external view returns (uint256);

    function maxRedeem(
        address owner,
        uint256 /*maxLoss*/
    ) external view returns (uint256);

    /*//////////////////////////////////////////////////////////////
                        MODIFIER HELPERS
    //////////////////////////////////////////////////////////////*/

    function requireManagement(address _sender) external view;

    function requireKeeperOrManagement(address _sender) external view;

    function requireEmergencyAuthorized(address _sender) external view;

    /*//////////////////////////////////////////////////////////////
                        KEEPERS FUNCTIONS
    //////////////////////////////////////////////////////////////*/

    function tend() external;

    function report() external returns (uint256 _profit, uint256 _loss);

    /*//////////////////////////////////////////////////////////////
                        CONSTANTS
    //////////////////////////////////////////////////////////////*/

    function MAX_FEE() external view returns (uint16);

    function FACTORY() external view returns (address);

    /*//////////////////////////////////////////////////////////////
                            GETTERS
    //////////////////////////////////////////////////////////////*/

    function apiVersion() external view returns (string memory);

    function pricePerShare() external view returns (uint256);

    function management() external view returns (address);

    function pendingManagement() external view returns (address);

    function keeper() external view returns (address);

    function emergencyAdmin() external view returns (address);

    function performanceFee() external view returns (uint16);

    function performanceFeeRecipient() external view returns (address);

    function fullProfitUnlockDate() external view returns (uint256);

    function profitUnlockingRate() external view returns (uint256);

    function profitMaxUnlockTime() external view returns (uint256);

    function lastReport() external view returns (uint256);

    function isShutdown() external view returns (bool);

    function unlockedShares() external view returns (uint256);

    /*//////////////////////////////////////////////////////////////
                            SETTERS
    //////////////////////////////////////////////////////////////*/

    function setPendingManagement(address) external;

    function acceptManagement() external;

    function setKeeper(address _keeper) external;

    function setEmergencyAdmin(address _emergencyAdmin) external;

    function setPerformanceFee(uint16 _performanceFee) external;

    function setPerformanceFeeRecipient(
        address _performanceFeeRecipient
    ) external;

    function setProfitMaxUnlockTime(uint256 _profitMaxUnlockTime) external;

    function setName(string calldata _newName) external;

    function shutdownStrategy() external;

    function emergencyWithdraw(uint256 _amount) external;
}

File 33 of 43 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC20.sol)

pragma solidity ^0.8.20;

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

File 34 of 43 : IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC165.sol)

pragma solidity ^0.8.20;

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

// SPDX-License-Identifier: AGPL-3.0
pragma solidity >=0.8.18;

interface IBaseStrategy {
    function tokenizedStrategyAddress() external view returns (address);

    /*//////////////////////////////////////////////////////////////
                            IMMUTABLE FUNCTIONS
    //////////////////////////////////////////////////////////////*/

    function availableDepositLimit(
        address _owner
    ) external view returns (uint256);

    function availableWithdrawLimit(
        address _owner
    ) external view returns (uint256);

    function deployFunds(uint256 _assets) external;

    function freeFunds(uint256 _amount) external;

    function harvestAndReport() external returns (uint256);

    function tendThis(uint256 _totalIdle) external;

    function shutdownWithdraw(uint256 _amount) external;

    function tendTrigger() external view returns (bool, bytes memory);
}

// 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 37 of 43 : 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) (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.20;

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.0.1) (utils/Context.sol)

pragma solidity ^0.8.20;

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

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

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/draft-IERC6093.sol)
pragma solidity ^0.8.20;

/**
 * @dev Standard ERC-20 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-20 tokens.
 */
interface IERC20Errors {
    /**
     * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     * @param balance Current balance for the interacting account.
     * @param needed Minimum amount required to perform a transfer.
     */
    error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);

    /**
     * @dev Indicates a failure with the token `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     */
    error ERC20InvalidSender(address sender);

    /**
     * @dev Indicates a failure with the token `receiver`. Used in transfers.
     * @param receiver Address to which tokens are being transferred.
     */
    error ERC20InvalidReceiver(address receiver);

    /**
     * @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.
     * @param spender Address that may be allowed to operate on tokens without being their owner.
     * @param allowance Amount of tokens a `spender` is allowed to operate with.
     * @param needed Minimum amount required to perform a transfer.
     */
    error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);

    /**
     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
     * @param approver Address initiating an approval operation.
     */
    error ERC20InvalidApprover(address approver);

    /**
     * @dev Indicates a failure with the `spender` to be approved. Used in approvals.
     * @param spender Address that may be allowed to operate on tokens without being their owner.
     */
    error ERC20InvalidSpender(address spender);
}

/**
 * @dev Standard ERC-721 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-721 tokens.
 */
interface IERC721Errors {
    /**
     * @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in ERC-20.
     * Used in balance queries.
     * @param owner Address of the current owner of a token.
     */
    error ERC721InvalidOwner(address owner);

    /**
     * @dev Indicates a `tokenId` whose `owner` is the zero address.
     * @param tokenId Identifier number of a token.
     */
    error ERC721NonexistentToken(uint256 tokenId);

    /**
     * @dev Indicates an error related to the ownership over a particular token. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     * @param tokenId Identifier number of a token.
     * @param owner Address of the current owner of a token.
     */
    error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);

    /**
     * @dev Indicates a failure with the token `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     */
    error ERC721InvalidSender(address sender);

    /**
     * @dev Indicates a failure with the token `receiver`. Used in transfers.
     * @param receiver Address to which tokens are being transferred.
     */
    error ERC721InvalidReceiver(address receiver);

    /**
     * @dev Indicates a failure with the `operator`’s approval. Used in transfers.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     * @param tokenId Identifier number of a token.
     */
    error ERC721InsufficientApproval(address operator, uint256 tokenId);

    /**
     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
     * @param approver Address initiating an approval operation.
     */
    error ERC721InvalidApprover(address approver);

    /**
     * @dev Indicates a failure with the `operator` to be approved. Used in approvals.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     */
    error ERC721InvalidOperator(address operator);
}

/**
 * @dev Standard ERC-1155 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-1155 tokens.
 */
interface IERC1155Errors {
    /**
     * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     * @param balance Current balance for the interacting account.
     * @param needed Minimum amount required to perform a transfer.
     * @param tokenId Identifier number of a token.
     */
    error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);

    /**
     * @dev Indicates a failure with the token `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     */
    error ERC1155InvalidSender(address sender);

    /**
     * @dev Indicates a failure with the token `receiver`. Used in transfers.
     * @param receiver Address to which tokens are being transferred.
     */
    error ERC1155InvalidReceiver(address receiver);

    /**
     * @dev Indicates a failure with the `operator`’s approval. Used in transfers.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     * @param owner Address of the current owner of a token.
     */
    error ERC1155MissingApprovalForAll(address operator, address owner);

    /**
     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
     * @param approver Address initiating an approval operation.
     */
    error ERC1155InvalidApprover(address approver);

    /**
     * @dev Indicates a failure with the `operator` to be approved. Used in approvals.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     */
    error ERC1155InvalidOperator(address operator);

    /**
     * @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.
     * Used in batch transfers.
     * @param idsLength Length of the array of token identifiers
     * @param valuesLength Length of the array of token amounts
     */
    error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);
}

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

pragma solidity ^0.8.20;

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

/**
 * @dev Interface of the ERC-4626 "Tokenized Vault Standard", as defined in
 * https://eips.ethereum.org/EIPS/eip-4626[ERC-4626].
 */
interface IERC4626 is IERC20, IERC20Metadata {
    event Deposit(address indexed sender, address indexed owner, uint256 assets, uint256 shares);

    event Withdraw(
        address indexed sender,
        address indexed receiver,
        address indexed owner,
        uint256 assets,
        uint256 shares
    );

    /**
     * @dev Returns the address of the underlying token used for the Vault for accounting, depositing, and withdrawing.
     *
     * - MUST be an ERC-20 token contract.
     * - MUST NOT revert.
     */
    function asset() external view returns (address assetTokenAddress);

    /**
     * @dev Returns the total amount of the underlying asset that is “managed” by Vault.
     *
     * - SHOULD include any compounding that occurs from yield.
     * - MUST be inclusive of any fees that are charged against assets in the Vault.
     * - MUST NOT revert.
     */
    function totalAssets() external view returns (uint256 totalManagedAssets);

    /**
     * @dev Returns the amount of shares that the Vault would exchange for the amount of assets provided, in an ideal
     * scenario where all the conditions are met.
     *
     * - MUST NOT be inclusive of any fees that are charged against assets in the Vault.
     * - MUST NOT show any variations depending on the caller.
     * - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange.
     * - MUST NOT revert.
     *
     * NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the
     * “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and
     * from.
     */
    function convertToShares(uint256 assets) external view returns (uint256 shares);

    /**
     * @dev Returns the amount of assets that the Vault would exchange for the amount of shares provided, in an ideal
     * scenario where all the conditions are met.
     *
     * - MUST NOT be inclusive of any fees that are charged against assets in the Vault.
     * - MUST NOT show any variations depending on the caller.
     * - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange.
     * - MUST NOT revert.
     *
     * NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the
     * “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and
     * from.
     */
    function convertToAssets(uint256 shares) external view returns (uint256 assets);

    /**
     * @dev Returns the maximum amount of the underlying asset that can be deposited into the Vault for the receiver,
     * through a deposit call.
     *
     * - MUST return a limited value if receiver is subject to some deposit limit.
     * - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of assets that may be deposited.
     * - MUST NOT revert.
     */
    function maxDeposit(address receiver) external view returns (uint256 maxAssets);

    /**
     * @dev Allows an on-chain or off-chain user to simulate the effects of their deposit at the current block, given
     * current on-chain conditions.
     *
     * - MUST return as close to and no more than the exact amount of Vault shares that would be minted in a deposit
     *   call in the same transaction. I.e. deposit should return the same or more shares as previewDeposit if called
     *   in the same transaction.
     * - MUST NOT account for deposit limits like those returned from maxDeposit and should always act as though the
     *   deposit would be accepted, regardless if the user has enough tokens approved, etc.
     * - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.
     * - MUST NOT revert.
     *
     * NOTE: any unfavorable discrepancy between convertToShares and previewDeposit SHOULD be considered slippage in
     * share price or some other type of condition, meaning the depositor will lose assets by depositing.
     */
    function previewDeposit(uint256 assets) external view returns (uint256 shares);

    /**
     * @dev Mints shares Vault shares to receiver by depositing exactly amount of underlying tokens.
     *
     * - MUST emit the Deposit event.
     * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
     *   deposit execution, and are accounted for during deposit.
     * - MUST revert if all of assets cannot be deposited (due to deposit limit being reached, slippage, the user not
     *   approving enough underlying tokens to the Vault contract, etc).
     *
     * NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token.
     */
    function deposit(uint256 assets, address receiver) external returns (uint256 shares);

    /**
     * @dev Returns the maximum amount of the Vault shares that can be minted for the receiver, through a mint call.
     * - MUST return a limited value if receiver is subject to some mint limit.
     * - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of shares that may be minted.
     * - MUST NOT revert.
     */
    function maxMint(address receiver) external view returns (uint256 maxShares);

    /**
     * @dev Allows an on-chain or off-chain user to simulate the effects of their mint at the current block, given
     * current on-chain conditions.
     *
     * - MUST return as close to and no fewer than the exact amount of assets that would be deposited in a mint call
     *   in the same transaction. I.e. mint should return the same or fewer assets as previewMint if called in the
     *   same transaction.
     * - MUST NOT account for mint limits like those returned from maxMint and should always act as though the mint
     *   would be accepted, regardless if the user has enough tokens approved, etc.
     * - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.
     * - MUST NOT revert.
     *
     * NOTE: any unfavorable discrepancy between convertToAssets and previewMint SHOULD be considered slippage in
     * share price or some other type of condition, meaning the depositor will lose assets by minting.
     */
    function previewMint(uint256 shares) external view returns (uint256 assets);

    /**
     * @dev Mints exactly shares Vault shares to receiver by depositing amount of underlying tokens.
     *
     * - MUST emit the Deposit event.
     * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the mint
     *   execution, and are accounted for during mint.
     * - MUST revert if all of shares cannot be minted (due to deposit limit being reached, slippage, the user not
     *   approving enough underlying tokens to the Vault contract, etc).
     *
     * NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token.
     */
    function mint(uint256 shares, address receiver) external returns (uint256 assets);

    /**
     * @dev Returns the maximum amount of the underlying asset that can be withdrawn from the owner balance in the
     * Vault, through a withdraw call.
     *
     * - MUST return a limited value if owner is subject to some withdrawal limit or timelock.
     * - MUST NOT revert.
     */
    function maxWithdraw(address owner) external view returns (uint256 maxAssets);

    /**
     * @dev Allows an on-chain or off-chain user to simulate the effects of their withdrawal at the current block,
     * given current on-chain conditions.
     *
     * - MUST return as close to and no fewer than the exact amount of Vault shares that would be burned in a withdraw
     *   call in the same transaction. I.e. withdraw should return the same or fewer shares as previewWithdraw if
     *   called
     *   in the same transaction.
     * - MUST NOT account for withdrawal limits like those returned from maxWithdraw and should always act as though
     *   the withdrawal would be accepted, regardless if the user has enough shares, etc.
     * - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.
     * - MUST NOT revert.
     *
     * NOTE: any unfavorable discrepancy between convertToShares and previewWithdraw SHOULD be considered slippage in
     * share price or some other type of condition, meaning the depositor will lose assets by depositing.
     */
    function previewWithdraw(uint256 assets) external view returns (uint256 shares);

    /**
     * @dev Burns shares from owner and sends exactly assets of underlying tokens to receiver.
     *
     * - MUST emit the Withdraw event.
     * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
     *   withdraw execution, and are accounted for during withdraw.
     * - MUST revert if all of assets cannot be withdrawn (due to withdrawal limit being reached, slippage, the owner
     *   not having enough shares, etc).
     *
     * Note that some implementations will require pre-requesting to the Vault before a withdrawal may be performed.
     * Those methods should be performed separately.
     */
    function withdraw(uint256 assets, address receiver, address owner) external returns (uint256 shares);

    /**
     * @dev Returns the maximum amount of Vault shares that can be redeemed from the owner balance in the Vault,
     * through a redeem call.
     *
     * - MUST return a limited value if owner is subject to some withdrawal limit or timelock.
     * - MUST return balanceOf(owner) if owner is not subject to any withdrawal limit or timelock.
     * - MUST NOT revert.
     */
    function maxRedeem(address owner) external view returns (uint256 maxShares);

    /**
     * @dev Allows an on-chain or off-chain user to simulate the effects of their redemption at the current block,
     * given current on-chain conditions.
     *
     * - MUST return as close to and no more than the exact amount of assets that would be withdrawn in a redeem call
     *   in the same transaction. I.e. redeem should return the same or more assets as previewRedeem if called in the
     *   same transaction.
     * - MUST NOT account for redemption limits like those returned from maxRedeem and should always act as though the
     *   redemption would be accepted, regardless if the user has enough shares, etc.
     * - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.
     * - MUST NOT revert.
     *
     * NOTE: any unfavorable discrepancy between convertToAssets and previewRedeem SHOULD be considered slippage in
     * share price or some other type of condition, meaning the depositor will lose assets by redeeming.
     */
    function previewRedeem(uint256 shares) external view returns (uint256 assets);

    /**
     * @dev Burns exactly shares from owner and sends assets of underlying tokens to receiver.
     *
     * - MUST emit the Withdraw event.
     * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
     *   redeem execution, and are accounted for during redeem.
     * - MUST revert if all of shares cannot be redeemed (due to withdrawal limit being reached, slippage, the owner
     *   not having enough shares, etc).
     *
     * NOTE: some implementations will require pre-requesting to the Vault before a withdrawal may be performed.
     * Those methods should be performed separately.
     */
    function redeem(uint256 shares, address receiver, address owner) external returns (uint256 assets);
}

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

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC-20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[ERC-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC-20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 *
 * ==== Security Considerations
 *
 * There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
 * expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
 * considered as an intention to spend the allowance in any specific way. The second is that because permits have
 * built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
 * take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
 * generally recommended is:
 *
 * ```solidity
 * function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
 *     try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
 *     doThing(..., value);
 * }
 *
 * function doThing(..., uint256 value) public {
 *     token.safeTransferFrom(msg.sender, address(this), value);
 *     ...
 * }
 * ```
 *
 * Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
 * `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
 * {SafeERC20-safeTransferFrom}).
 *
 * Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
 * contracts should have entry points that don't rely on permit.
 */
interface IERC20Permit {
    /**
     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
     * given ``owner``'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     *
     * CAUTION: See Security Considerations above.
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

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

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

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

pragma solidity ^0.8.20;

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

Settings
{
  "remappings": [
    "@openzeppelin/=lib/openzeppelin-contracts/",
    "forge-std/=lib/forge-std/src/",
    "@tokenized-strategy/=lib/tokenized-strategy/src/",
    "@periphery/=lib/tokenized-strategy-periphery/src/",
    "@uniswap-v3-core/=lib/uniswap-v3-core/contracts/",
    "@yearn-vaults/=lib/tokenized-strategy-periphery/lib/yearn-vaults-v3/contracts/",
    "createx-forge/=lib/createx-forge/",
    "ds-test/=lib/forge-std/lib/ds-test/src/",
    "erc4626-tests/=lib/tokenized-strategy/lib/erc4626-tests/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/",
    "openzeppelin/=lib/tokenized-strategy/lib/openzeppelin-contracts/contracts/",
    "tokenized-strategy-periphery/=lib/tokenized-strategy-periphery/",
    "tokenized-strategy/=lib/tokenized-strategy/",
    "uniswap-v3-core/=lib/uniswap-v3-core/contracts/",
    "yearn-vaults-v3/=lib/tokenized-strategy-periphery/lib/yearn-vaults-v3/"
  ],
  "optimizer": {
    "enabled": true,
    "runs": 1000000
  },
  "metadata": {
    "useLiteralContent": false,
    "bytecodeHash": "ipfs",
    "appendCBOR": true
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "abi"
      ]
    }
  },
  "evmVersion": "shanghai",
  "viaIR": true
}

Contract Security Audit

Contract ABI

API
[{"inputs":[{"internalType":"address","name":"_management","type":"address"},{"internalType":"address","name":"_performanceFeeRecipient","type":"address"},{"internalType":"address","name":"_keeper","type":"address"},{"internalType":"address","name":"_emergencyAdmin","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"strategy","type":"address"},{"indexed":true,"internalType":"address","name":"asset","type":"address"},{"indexed":true,"internalType":"address","name":"lp","type":"address"}],"name":"NewStrategy","type":"event"},{"inputs":[],"name":"deployments","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"emergencyAdmin","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"},{"internalType":"address","name":"_lp","type":"address"}],"name":"getStrategyForAssetLpPair","outputs":[{"internalType":"address","name":"_strategy","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_strategy","type":"address"}],"name":"isDeployedStrategy","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"keeper","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"management","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_asset","type":"address"},{"internalType":"string","name":"_name","type":"string"},{"internalType":"address","name":"_steerLP","type":"address"},{"internalType":"uint128","name":"_minAsset","type":"uint128"},{"internalType":"uint256","name":"_maxSwapValue","type":"uint256"}],"name":"newStrategy","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"performanceFeeRecipient","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_management","type":"address"},{"internalType":"address","name":"_performanceFeeRecipient","type":"address"},{"internalType":"address","name":"_keeper","type":"address"}],"name":"setAddresses","outputs":[],"stateMutability":"nonpayable","type":"function"}]

60a0346100bd57601f615e1d38819003918201601f19168301916001600160401b038311848410176100c1578084926080946040528339810103126100bd57610047816100d5565b610053602083016100d5565b61006b6060610064604086016100d5565b94016100d5565b9260018060a01b0380928160018060a01b03199516855f5416175f551683600154161760015516906002541617600255608052604051615d3390816100ea82396080518181816103b501526106ab0152f35b5f80fd5b634e487b7160e01b5f52604160045260245ffd5b51906001600160a01b03821682036100bd5756fe608060408181526004918236101562000016575f80fd5b5f925f3560e01c91826308483906146200084e575081630d00442414620007e6578163363bf96414620006cf57816370905dce146200065f5781638144f84314620005e357816388a8d6021462000590578163aced1661146200053c578163d49db09c14620000e6575063ed27f7c9146200008f575f80fd5b34620000e257817ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112620000e25760209073ffffffffffffffffffffffffffffffffffffffff600154169051908152f35b5080fd5b838334620004a95760a07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112620004a957620001236200099a565b9060249182359167ffffffffffffffff95868411620004a95736602385011215620004a9578381013592878411620004a95736868587010111620004a9576200016b620009e2565b94606435986fffffffffffffffffffffffffffffffff8a16809a03620004a95773ffffffffffffffffffffffffffffffffffffffff80931695865f5260209a60038c5284875f20991698895f528c5284875f205416620004e25786519361520f80860194851186861017620004b7578360c095938f958e7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09560a08f998c9a601f9862000aef8d398a528901528260a089015201888701375f8783870101528c8b860152606085015260843560808501520116010301905ff08015620004ad57811695620002598762000a48565b50845f5260038952835f20865f528952835f20877fffffffffffffffffffffffff00000000000000000000000000000000000000008254161790558160015416873b15620004a9578451907f6a5f1aa2000000000000000000000000000000000000000000000000000000008252848201525f818381838c5af180156200049f5762000489575b508160025416873b156200046d578451907f748747e60000000000000000000000000000000000000000000000000000000082528482015288818381838c5af18015620004635790899162000471575b50548216873b156200046d578451907ff629b7900000000000000000000000000000000000000000000000000000000082528482015288818381838c5af1801562000463579089916200044b575b5050863b15620004475790879184519384927f35da33940000000000000000000000000000000000000000000000000000000084527f000000000000000000000000000000000000000000000000000000000000000016908301528183895af180156200043d5785929187916200041c575b50507f7346178ece6372241ea463631930b7671917f47398a07d305f81a4d00eddc10390519580a48152f35b6200042a9192935062000a06565b620004395783908588620003f0565b8480fd5b82513d88823e3d90fd5b8780fd5b620004569062000a06565b6200044757878a6200037e565b85513d8b823e3d90fd5b8880fd5b6200047c9062000a06565b6200044757878a62000330565b6200049691985062000a06565b5f9689620002e0565b85513d5f823e3d90fd5b5f80fd5b83513d5f823e3d90fd5b8b6041897f4e487b71000000000000000000000000000000000000000000000000000000005f52525ffd5b60648c878c8a51927f08c379a0000000000000000000000000000000000000000000000000000000008452828401528201527f216e6577000000000000000000000000000000000000000000000000000000006044820152fd5b8234620004a9575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112620004a95760209073ffffffffffffffffffffffffffffffffffffffff600254169051908152f35b8234620004a9575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112620004a95760209073ffffffffffffffffffffffffffffffffffffffff5f54169051908152f35b8234620004a957807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112620004a957602090620006216200099a565b6200062b620009be565b73ffffffffffffffffffffffffffffffffffffffff8092165f526003845281835f2091165f528352815f2054169051908152f35b8234620004a9575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112620004a9576020905173ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000168152f35b905034620004a95760607ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112620004a9576200070c6200099a565b62000716620009be565b62000720620009e2565b915f549073ffffffffffffffffffffffffffffffffffffffff94858316330362000789577fffffffffffffffffffffffff0000000000000000000000000000000000000000808416838816175f5560018054821686891617905560028054909116868816179055005b60649060208851917f08c379a0000000000000000000000000000000000000000000000000000000008352820152600b60248201527f216d616e6167656d656e740000000000000000000000000000000000000000006044820152fd5b8234620004a95760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112620004a95760209073ffffffffffffffffffffffffffffffffffffffff6200083a6200099a565b165f5260058252805f205415159051908152f35b839034620004a9575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112620004a957825491828252602090828281018095875f527f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19b905f5b8682821062000982575050505003601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01683019467ffffffffffffffff8611848710176200095657508481528185529151818501819052849392840192915f5b8281106200092857505050500390f35b835173ffffffffffffffffffffffffffffffffffffffff168552869550938101939281019260010162000918565b6041907f4e487b71000000000000000000000000000000000000000000000000000000005f525260245ffd5b835485528895509093019260019283019201620008b6565b6004359073ffffffffffffffffffffffffffffffffffffffff82168203620004a957565b6024359073ffffffffffffffffffffffffffffffffffffffff82168203620004a957565b6044359073ffffffffffffffffffffffffffffffffffffffff82168203620004a957565b67ffffffffffffffff811162000a1b57604052565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b805f52600560205260405f2054155f1462000ae9576004546801000000000000000081101562000a1b57600181018060045581101562000abc5781907f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19b0155600454905f52600560205260405f2055600190565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b505f9056fe610140806040523462000265576200520f803803809162000020826200027d565b833960a08183019112620002655762000038620002cd565b6101608051939192916001600160401b03851162000265578261015f8601121562000265578401516200006b81620002fd565b926200007b6040519485620002a9565b8184528282870101116200026557620000bf946200009f9260208501910162000319565b620000a9620002e5565b620000b36200033c565b916101c05193620003e8565b604051614ad990816200073682396080518181816103d301528181611cd4015281816125280152818161336f015281816136bb0152818161384e015281816140ad0152818161416701528181614802015261494f015260a0518181816104ae015281816106410152818161073c015281816108ac01528181610a4001528181610d3001528181610f97015281816112010152818161138b0152818161155e0152818161168401528181611a8401528181611bc801528181611df401528181611f0d015281816122d6015281816128c00152818161320a0152613e63015260c051818181610bda015281816117fe015281816119cc0152818161266401528181612f0001528181613b390152818161425a01526147dc015260e05181818161211901528181613bc901528181613d31015261402b0152610100518181816117310152818161257201528181612fcc0152818161347e01528181613771015281816141b5015261478e01526101205181818161273e0152818161345b015281816136f001528181613ca0015281816144b2015281816145590152818161482e01526149180152f35b5f80fd5b634e487b7160e01b5f52604160045260245ffd5b601f01601f1916610140908101906001600160401b03821190821017620002a357604052565b62000269565b601f909101601f19168101906001600160401b03821190821017620002a357604052565b61014051906001600160a01b03821682036200026557565b61018051906001600160a01b03821682036200026557565b6001600160401b038111620002a357601f01601f191660200190565b5f5b8381106200032b5750505f910152565b81810151838201526020016200031b565b6101a051906001600160801b03821682036200026557565b156200035c57565b60405162461bcd60e51b8152602060048201526002602482015261021360f41b6044820152606490fd5b908160209103126200026557516001600160a01b0381168103620002655790565b6040513d5f823e3d90fd5b15620003ba57565b60405162461bcd60e51b815260206004820152600660248201526508585cdcd95d60d21b6044820152606490fd5b90620003f791949394620005e6565b5f80546001600160e01b03166206407d60e31b1790556001805462012c6463ffffffff199091161790555f196002556001600160a01b03908116926200043f84151562000354565b60c08490526040516316f0115b60e01b8152602092908381600481895afa9081156200059a575f91620005c4575b5060e052604051630dfe168160e01b81528381600481895afa9081156200059a5760049685915f93620005a0575b5060405163d21220a760e01b815297889182905afa9182156200059a57620005259662000520955f9462000564575b505060805181166001600160a01b031690828116820362000527575050600161012081905261010092909252508054600160601b600160e01b03191660609290921b600160601b600160e01b0316919091179055565b600355565b565b6200053592931614620003b2565b6101005260018054600160601b600160e01b03191660609290921b600160601b600160e01b0316919091179055565b62000589929450803d1062000592575b620005808183620002a9565b81019062000386565b915f80620004ca565b503d62000574565b620003a7565b620005bc919350823d84116200059257620005808183620002a9565b915f6200049b565b620005df9150843d86116200059257620005808183620002a9565b5f6200046d565b906200066660e46200066c9360018060a01b0316806080523060a052604051938491634b839d7360e11b6020840152602483015260a060448301526200063c815180928160c48601526020868601910162000319565b3360648301523360848301523360a4830152601f801991011681010360c4810184520182620002a9565b620006ca565b5073d377919fa87120584b21279a491f82d5265a139c7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc55620006b5600160ff195f5416175f55565b620005256227100062ffff00195f5416175f55565b5f809160208151910173d377919fa87120584b21279a491f82d5265a139c5af43d156200072c573d90620006fe82620002fd565b916200070e6040519384620002a9565b82523d5f602084013e5b15620007215790565b6040513d90815f823efd5b6060906200071856fe60806040526004361015610019575b3415612d24575b5f80fd5b5f3560e01c806302f12120146102e357806304bd4629146102de5780630a0f9941146102d9578063139dd2bf146102d45780631d881fc4146102cf5780631f1f5869146102ca578063219461ed146102c55780632828b202146102c05780632c377490146102bb5780632cd68034146102b65780633204fb5b146102b15780633d6cb5751461029857806341db6dbf146102ac57806346aa2f12146102a757806349317f1d146102a25780634a5d09431461029d578063503160d914610298578063525e99da146102935780635bd246481461028e5780635d265d3f146102895780635db2b728146102845780635df31d611461027f5780636718835f1461027a5780636d6987c11461027557806371ee95c01461027057806375c45dce1461026b5780637d969932146102665780637d9f6db514610261578063950b3d731461025c5780639c455fb2146102575780639cfc3c5c146102525780639d7fb70c1461024d578063a1bac55014610248578063a73801f014610243578063ac00ff261461023e578063ae8c2a7014610239578063b8c6f57914610234578063bdc8144b1461022f578063d19a3bb81461022a578063d696860114610225578063e46cd10214610220578063ecf708581461021b578063fa461e3314610216578063fc7f71b6146102115763fde813a80361000e576123cf565b612282565b6120b2565b612077565b612027565b611ec3565b611e77565b611dad565b611b72565b611b30565b611a31565b6119f0565b611982565b6117ad565b611639565b61150b565b611341565b6112ee565b6112ad565b6111ae565b6110fb565b611089565b61104a565b610f44565b610ef4565b610e69565b610cdd565b610ca0565b610ad5565b610c5f565b610b8d565b610b49565b610b0e565b6109f6565b6109af565b610977565b610849565b6107fd565b6107bf565b6106f5565b6105ee565b61045b565b610350565b6102f2565b5f91031261001557565b34610015575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261001557602061032a6124db565b604051908152f35b73ffffffffffffffffffffffffffffffffffffffff81160361001557565b346100155760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100155761038a600435610332565b6040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015260208160248173ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000165afa801561044a57610417915f9161041b575b506040519081529081906020820190565b0390f35b61043d915060203d602011610443575b6104358183612441565b810190612482565b5f610406565b503d61042b565b612491565b61ffff81160361001557565b34610015575f60207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610015576004356104978161044f565b73ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016803b15610015575f602491604051928380927f48e4a6490000000000000000000000000000000000000000000000000000000082523360048301525afa801561044a576105d1575b506103e861ffff821611610573577dffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7fffff00000000000000000000000000000000000000000000000000000000000083549260f01b16911617815580f35b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600960248201527f21646973636f756e7400000000000000000000000000000000000000000000006044820152fd5b6105dc919250612411565b5f905f610516565b8015150361001557565b34610015575f60207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100155760043561062a816105e4565b73ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016803b15610015575f602491604051928380927f48e4a6490000000000000000000000000000000000000000000000000000000082523360048301525afa801561044a576106e2575b5081547fffffffffffffffffffffffffffffffffffffffffffffffffffff00ffffffffff1690151560281b65ff00000000001617815580f35b6106ed919250612411565b5f905f6106a9565b34610015575f60207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100155773ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016803b15610015575f602491604051928380927f48e4a6490000000000000000000000000000000000000000000000000000000082523360048301525afa801561044a576107ae575b5060043560035580f35b6107b89150612411565b5f806107a4565b34610015575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261001557602060ff60015416604051908152f35b34610015575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610015576020604051733ef3d8ba38ebe18db133cec108f4d14ce00dd9ae8152f35b34610015575f60207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610015576004356fffffffffffffffffffffffffffffffff811681036100155773ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016803b15610015575f602491604051928380927f48e4a6490000000000000000000000000000000000000000000000000000000082523360048301525afa801561044a57610964575b507fffffffff00000000000000000000000000000000ffffffffffffffffffffffff7bffffffffffffffffffffffffffffffff0000000000000000000000006001549260601b1691161760015580f35b61096f919250612411565b5f905f610914565b34610015575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261001557602061032a61261d565b34610015575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261001557602060015467ffffffffffffffff60405191831c168152f35b34610015575f60207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100155760043573ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016803b15610015575f602491604051928380927f48e4a6490000000000000000000000000000000000000000000000000000000082523360048301525afa801561044a57610ac0575b5080610ab8610abd9215156127fb565b612eb1565b80f35b610acb919250612411565b5f90610abd610aa8565b346100155760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261001557610b0c61308c565b005b34610015575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610015576020600354604051908152f35b346100155760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261001557610b83600435610332565b602061032a61287d565b34610015575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261001557610bc361308c565b73ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016803b15610015575f80916004604051809481937f181783580000000000000000000000000000000000000000000000000000000083525af1801561044a57610c50575b6020610c476124db565b61032a816131b1565b610c5990612411565b5f610c3d565b34610015575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261001557602061ffff5f5460081c16604051908152f35b34610015575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100155760205f5460f01c604051908152f35b34610015575f60207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261001557600435610d198161044f565b73ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016803b15610015575f602491604051928380927f48e4a6490000000000000000000000000000000000000000000000000000000082523360048301525afa801561044a57610dfa575b50610dab61271061ffff8316111561292e565b7fffff0000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff7dffff0000000000000000000000000000000000000000000000000000000083549260e01b16911617815580f35b610e05919250612411565b5f905f610d98565b91908251928382525f5b848110610e555750507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f845f6020809697860101520116010190565b602081830181015184830182015201610e17565b34610015575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261001557610e9f613300565b604051907f440368a300000000000000000000000000000000000000000000000000000000602083015260048252610ed682612425565b61041760405192839215158352604060208401526040830190610e0d565b34610015575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261001557602062ffffff60015460081c16604051908152f35b62ffffff81160361001557565b34610015575f60207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261001557600435610f8081610f37565b73ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016803b15610015575f602491604051928380927f48e4a6490000000000000000000000000000000000000000000000000000000082523360048301525afa801561044a57611037575b507fffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000ff63ffffff006001549260081b1691161760015580f35b611042919250612411565b5f905f610fff565b34610015575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261001557602060ff5f54166040519015158152f35b34610015575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261001557602061ffff5f5460e01c16604051908152f35b9181601f840112156100155782359167ffffffffffffffff8311610015576020808501948460051b01011161001557565b346100155760807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100155767ffffffffffffffff6004358181116100155761114b9036906004016110ca565b90602435838111610015576111649036906004016110ca565b906044358581116100155761117d9036906004016110ca565b9290916064359687116100155761119b610b0c9736906004016110ca565b969095612a24565b60ff81160361001557565b34610015575f60207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610015576004356111ea816111a3565b73ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016803b15610015575f602491604051928380927f48e4a6490000000000000000000000000000000000000000000000000000000082523360048301525afa801561044a57611299575b5060ff167fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00600154161760015580f35b6112a4919250612411565b5f9060ff611269565b34610015575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261001557602061ffff5f5460181c16604051908152f35b34610015575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261001557602073ffffffffffffffffffffffffffffffffffffffff5f5460301c16604051908152f35b34610015575f60207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100155760043573ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016803b15610015575f602491604051928380927f48e4a6490000000000000000000000000000000000000000000000000000000082523360048301525afa801561044a576114f8575b50801561149a5761ffff80821161143c57610abd91167fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000ff62ffff005f549260081b169116175f55565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600960248201527f21746f6f206869676800000000000000000000000000000000000000000000006044820152fd5b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600c60248201527f217a65726f2070726f66697400000000000000000000000000000000000000006044820152fd5b611503919250612411565b5f905f6113f3565b34610015575f60207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610015576004356115478161044f565b73ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016803b15610015575f602491604051928380927f48e4a6490000000000000000000000000000000000000000000000000000000082523360048301525afa801561044a57611626575b506115d961271061ffff8316111561292e565b7fffffffff0000ffffffffffffffffffffffffffffffffffffffffffffffffffff7bffff000000000000000000000000000000000000000000000000000083549260d01b16911617815580f35b611631919250612411565b5f905f6115c6565b34610015575f60207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100155773ffffffffffffffffffffffffffffffffffffffff906004357f00000000000000000000000000000000000000000000000000000000000000008316803b15610015575f602491604051928380927f48e4a6490000000000000000000000000000000000000000000000000000000082523360048301525afa801561044a57611796575b506020602492936116ff8315156127fb565b604051938480927f70a082310000000000000000000000000000000000000000000000000000000082523060048301527f0000000000000000000000000000000000000000000000000000000000000000165afa91821561044a57610abd92611772918591611777575b50821115612bd3565b613455565b611790915060203d602011610443576104358183612441565b5f611769565b602492506117a390612411565b60205f92506116ed565b346100155760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610015576004356117e761308c565b73ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016803b15610015575f80916004604051809481937f181783580000000000000000000000000000000000000000000000000000000083525af1801561044a57611969575b505f546118779060d01c61ffff165b61ffff1690565b906118af61189a6001546fffffffffffffffffffffffffffffffff9060601c1690565b6fffffffffffffffffffffffffffffffff1690565b91801561195b576118bf90613e20565b908181111561192357906118d291612870565b1015611916575b600180547fffffffffffffffffffffffffffffffffffffffff0000000000000000ffffffff164260201b6bffffffffffffffff0000000016179055005b61191e61411d565b6118d9565b818110611933575b5050506118d9565b61193c91612870565b9081101561194c575b808061192b565b61195590612eb1565b5f611945565b50106118d95761191e61411d565b8061197661197c92612411565b806102e8565b5f611861565b34610015575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261001557602060405173ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000168152f35b34610015575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261001557602061ffff5f5460d01c16604051908152f35b34610015575f60207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261001557600435611a6d816105e4565b73ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016803b15610015575f602491604051928380927f48e4a6490000000000000000000000000000000000000000000000000000000082523360048301525afa801561044a57611b1d575b5060ff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff005f541691151516175f5580f35b611b28919250612411565b5f905f611aec565b34610015575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261001557602060ff5f5460281c166040519015158152f35b34610015575f6020807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261001557600435611baf81610332565b73ffffffffffffffffffffffffffffffffffffffff91827f000000000000000000000000000000000000000000000000000000000000000016803b15610015575f602491604051928380927f48e4a6490000000000000000000000000000000000000000000000000000000082523360048301525afa801561044a57611d9a575b508282169283611c8a575b84610abd847fffffffffffff0000000000000000000000000000000000000000ffffffffffff79ffffffffffffffffffffffffffffffffffffffff0000000000005f549260301b169116175f55565b604051937f1f1fcd510000000000000000000000000000000000000000000000000000000085528285600481845afa90811561044a57611cfb84926004978991611d7d575b5084167f0000000000000000000000000000000000000000000000000000000000000000851614612c4d565b604051958680927ff7260d3e0000000000000000000000000000000000000000000000000000000082525afa90811561044a57610abd94611d47938793611d4e575b5050163014612cb2565b5f80611c3b565b611d6e929350803d10611d76575b611d668183612441565b810190612c38565b905f80611d3d565b503d611d5c565b611d949150843d8611611d7657611d668183612441565b5f611ccf565b611da5919450612411565b5f925f611c30565b34610015575f60207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100155773ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016803b15610015575f602491604051928380927f48e4a6490000000000000000000000000000000000000000000000000000000082523360048301525afa801561044a57611e66575b5060043560025580f35b611e709150612411565b5f80611e5c565b34610015575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261001557602060405173d377919fa87120584b21279a491f82d5265a139c8152f35b34610015575f60207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100155760043573ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016803b15610015575f602491604051928380927f48e4a6490000000000000000000000000000000000000000000000000000000082523360048301525afa801561044a57612014575b50612710811015611fb6577fffffffffffffffffffffffffffffffffffffffffffffffffffffff0000ffffff64ffff00000083549260181b16911617815580f35b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600b60248201527f216c6f7373206c696d69740000000000000000000000000000000000000000006044820152fd5b61201f919250612411565b5f905f611f75565b34610015575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100155760206fffffffffffffffffffffffffffffffff60015460601c16604051908152f35b34610015575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610015576020600254604051908152f35b346100155760607ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100155767ffffffffffffffff6044358181116100155736602382011215610015578060040135828111610015578101366024820111610015577f00000000000000000000000000000000000000000000000000000000000000009073ffffffffffffffffffffffffffffffffffffffff9081831633036122245783604091031261001557604051906040820194828610908611176121f7576121d96121f2926121bf6121b66121d994610b0c99604052602489013561219c81610332565b8085526044602086019a01358a521660243560043561369b565b965187146127fb565b5173ffffffffffffffffffffffffffffffffffffffff1690565b73ffffffffffffffffffffffffffffffffffffffff1690565b61379b565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600760248201527f2163616c6c6572000000000000000000000000000000000000000000000000006044820152fd5b34610015575f60207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610015576004356122be81610332565b73ffffffffffffffffffffffffffffffffffffffff807f00000000000000000000000000000000000000000000000000000000000000001692833b15610015575f602494604051958680927f48e4a6490000000000000000000000000000000000000000000000000000000082523360048301525afa93841561044a5761234f946123be575b505460301c16613817565b901561236057604051908152602090f35b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600560248201527f216b69636b0000000000000000000000000000000000000000000000000000006044820152fd5b6123c89150612411565b5f80612344565b346100155760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100155761240661308c565b610b0c600435612eb1565b67ffffffffffffffff81116121f757604052565b6040810190811067ffffffffffffffff8211176121f757604052565b90601f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0910116810190811067ffffffffffffffff8211176121f757604052565b90816020910312610015575190565b6040513d5f823e3d90fd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b919082018092116124d657565b61249c565b6040517f70a082310000000000000000000000000000000000000000000000000000000080825230600483015260209173ffffffffffffffffffffffffffffffffffffffff9083816024817f000000000000000000000000000000000000000000000000000000000000000086165afa92831561044a5784915f946125e8575b5060405190815230600482015291829060249082907f0000000000000000000000000000000000000000000000000000000000000000165afa92831561044a576125c8936125c3926125b5925f926125cb575b5050612d54565b6125bd61261d565b926124c9565b6124c9565b90565b6125e19250803d10610443576104358183612441565b5f806125ae565b612600919450823d8411610443576104358183612441565b925f61255b565b9190826040910312610015576020825192015190565b604080517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015290602073ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000168184602481845afa93841561044a575f946127dc575b5083156127b55782517f18160ddd0000000000000000000000000000000000000000000000000000000081528281600481855afa92831561044a575f936127bd575b505081156127b557826004918151928380927fc4a7761e0000000000000000000000000000000000000000000000000000000082525afa90811561044a5761273c9383915f915f94612781575b5050906127369186612e08565b93612e08565b7f000000000000000000000000000000000000000000000000000000000000000015612775579061276f6125c892612d54565b906124c9565b61276f6125c892612d54565b6127369394506127a69250803d106127ae575b61279e8183612441565b810190612607565b92915f612729565b503d612794565b505050505f90565b6127d4929350803d10610443576104358183612441565b905f806126dc565b6127f4919450823d8411610443576104358183612441565b925f61269a565b1561280257565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600760248201527f21616d6f756e74000000000000000000000000000000000000000000000000006044820152fd5b906127109182039182116124d657565b919082039182116124d657565b6040517f01e1d11400000000000000000000000000000000000000000000000000000000815260208160048173ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000165afa90811561044a575f9161290f575b5060025490808211156129095781039081116124d65790565b50505f90565b612928915060203d602011610443576104358183612441565b5f6128f0565b1561293557565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600460248201527f21627073000000000000000000000000000000000000000000000000000000006044820152fd5b9190808252602080920192915f5b8281106129af575050505090565b90919293828060019273ffffffffffffffffffffffffffffffffffffffff88356129d881610332565b168152019501939291016129a1565b90918281527f07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff83116100155760209260051b809284830137010190565b9594969390919296733ef3d8ba38ebe18db133cec108f4d14ce00dd9ae96873b15610015579790612ac7612ad79392612a9560409997989699519b8c9a7f71ee95c0000000000000000000000000000000000000000000000000000000008c52608060048d015260848c0191612993565b907ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc98898b84030160248c0152612993565b91868884030160448901526129e7565b92848403016064850152808352602080840193600560208460051b83010195855f935b868510612b2f57505050505050505091815f81819503925af1801561044a57612b205750565b80611976612b2d92612411565b565b919395979092949698507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe082820301845288357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe18436030181121561001557830187810191903567ffffffffffffffff81116100155780871b3603831361001557612bbf899283926001956129e7565b9a0194019501929593918a98979591612afa565b15612bda57565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600860248201527f2162616c616e63650000000000000000000000000000000000000000000000006044820152fd5b9081602091031261001557516125c881610332565b15612c5457565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600560248201527f2177616e740000000000000000000000000000000000000000000000000000006044820152fd5b15612cb957565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600960248201527f21726563656976657200000000000000000000000000000000000000000000006044820152fd5b60405190612b2d82612425565b365f80375f80368173d377919fa87120584b21279a491f82d5265a139c5af43d5f803e15612d50573d5ff35b3d5ffd5b8015612d6c576125c890612d66613b86565b90613c97565b505f90565b1561001557565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8282099082810292838084109303928084039314612ddb576c010000000000000000000000009183831115610015570990828211900360a01b910360601c1790565b50505060601c90565b80156100155778010000000000000000000000000000000000000000000000000490565b90917fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8383099280830292838086109503948086039514612e9e57908291612e51868411612d71565b0981805f0316809204600280826003021880830282030280830282030280830282030280830282030280830282030280920290030293600183805f03040190848311900302920304170290565b50509150612ead821515612d71565b0490565b801561308957604080517f70a082310000000000000000000000000000000000000000000000000000000080825230600483015260209373ffffffffffffffffffffffffffffffffffffffff937f000000000000000000000000000000000000000000000000000000000000000085169390918682602481885afa91821561044a575f9261306a575b50612f4361261d565b90811561306057818110613050575050925b83156130485781517fd331bef700000000000000000000000000000000000000000000000000000000815260048101949094525f6024850181905260448501819052306064860152829185916084918391905af192831561044a57859361302c575b505190815230600482015291829060249082907f0000000000000000000000000000000000000000000000000000000000000000165afa91821561044a575f9261300f575b5050806130065750565b612b2d90613455565b6130259250803d10610443576104358183612441565b5f80612ffc565b61304290823d84116127ae5761279e8183612441565b50612fb7565b505050505050565b9161305a92612e08565b92612f55565b5050505050505050565b613082919250873d8911610443576104358183612441565b905f612f3a565b50565b30330361309557565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600560248201527f2173656c660000000000000000000000000000000000000000000000000000006044820152fd5b90633b9aca00918281029281840414901517156124d657565b818102929181159184041417156124d657565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601260045260245ffd5b1561315357565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600b60248201527f6865616c7468436865636b0000000000000000000000000000000000000000006044820152fd5b6131c36131bf5f5460ff1690565b1590565b6132d1576040517f01e1d11400000000000000000000000000000000000000000000000000000000815260208160048173ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000165afa90811561044a575f916132b2575b508082111561327f5761327861327061325683612b2d95612870565b9261326a6118705f5461ffff9060081c1690565b9061310c565b612710900490565b101561314c565b81811161328b575b5050565b61327861327061329e612b2d9484612870565b9261326a6118705f5461ffff9060181c1690565b6132cb915060203d602011610443576104358183612441565b5f61323a565b50612b2d60017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff005f5416175f55565b60015461332262ffffff8260081c1667ffffffffffffffff8360201c166124c9565b4210612d6c5761333460ff82166130f3565b4811612d6c576040517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152906020826024817f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff165afa91821561044a575f92613434575b505f549061ffff808360d01c16806133ef57505060601c6fffffffffffffffffffffffffffffffff169050806133ea5750151590565b111590565b61341f925061340f9161340461327092613e20565b9460e01c168461310c565b61341981846124c9565b92612870565b90821191821561342e57505090565b10919050565b61344e91925060203d602011610443576104358183612441565b905f6133b4565b612b2d907f000000000000000000000000000000000000000000000000000000000000000015907f0000000000000000000000000000000000000000000000000000000000000000613f03565b156134a957565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600660248201527f21746f6b656e00000000000000000000000000000000000000000000000000006044820152fd5b1561350e57565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600960248201527f21616d6f756e74302b00000000000000000000000000000000000000000000006044820152fd5b1561357357565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600960248201527f21616d6f756e74312d00000000000000000000000000000000000000000000006044820152fd5b156135d857565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600960248201527f21616d6f756e74312b00000000000000000000000000000000000000000000006044820152fd5b1561363d57565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600960248201527f21616d6f756e74302d00000000000000000000000000000000000000000000006044820152fd5b916136ee73ffffffffffffffffffffffffffffffffffffffff80921691807f0000000000000000000000000000000000000000000000000000000000000000168314928391841561376f575b50506134a2565b7f000000000000000000000000000000000000000000000000000000000000000015613746571561372f575f6125c891613729828513613507565b1261356c565b905f6125c8916137408285136135d1565b12613636565b9091901561375e575f6125c8916137408285136135d1565b905f6125c891613729828513613507565b7f0000000000000000000000000000000000000000000000000000000000000000161490505f806136e7565b6040517fa9059cbb00000000000000000000000000000000000000000000000000000000602082015273ffffffffffffffffffffffffffffffffffffffff929092166024830152604480830193909352918152612b2d916137fd606483612441565b61441d565b9081602091031261001557516125c8816105e4565b5f5491929161382a9060281c60ff161590565b8015613b68575b613b605773ffffffffffffffffffffffffffffffffffffffff92837f00000000000000000000000000000000000000000000000000000000000000001693808216908582148015613b35575b613a78576040517f9f8a13d700000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff871660048201526020969185169491908781602481895afa91821561044a5788915f93613b06575b508215613a84575b5050613a78576040517f70a08231000000000000000000000000000000000000000000000000000000008082523060048301529091908783602481875afa92831561044a575f93613a59575b5060405190815273ffffffffffffffffffffffffffffffffffffffff821660048201528781602481875afa801561044a5761397b915f91613a3c575b50836124c9565b15613a2f57926139e5928288955f9794613a1e575b5050506040519485809481937f96c551750000000000000000000000000000000000000000000000000000000083526004830191909173ffffffffffffffffffffffffffffffffffffffff6020820193169052565b03925af192831561044a575f936139ff575b505060019190565b613a16929350803d10610443576104358183612441565b905f806139f7565b613a279261379b565b5f8080613990565b505050505090505f905f90565b613a539150893d8b11610443576104358183612441565b5f613974565b613a71919350883d8a11610443576104358183612441565b915f613938565b5050505090505f905f90565b6040517f10098ad500000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff919091166004820152915081602481885afa90811561044a575f91613ae9575b501515865f6138ec565b613b009150873d8911610443576104358183612441565b5f613adf565b613b27919350823d8411613b2e575b613b1f8183612441565b810190613802565b915f6138e4565b503d613b15565b50807f000000000000000000000000000000000000000000000000000000000000000016821461387d565b505f91508190565b5073ffffffffffffffffffffffffffffffffffffffff811615613831565b6040517f3850c7bd00000000000000000000000000000000000000000000000000000000815260e08160048173ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000165afa90811561044a575f91613bfc575090565b905060e0813d60e011613c7a575b81613c1760e09383612441565b8101031261001557805190613c2b82610332565b60208101518060020b036100155760c081613c4c60406125c894015161044f565b613c59606082015161044f565b613c66608082015161044f565b613c7360a08201516111a3565b01516105e4565b3d9150613c0a565b9081602091031261001557516125c881610f37565b908115612909577f000000000000000000000000000000000000000000000000000000000000000015613dc2579073ffffffffffffffffffffffffffffffffffffffff613cee921690613ce982612de4565b612e08565b6040517fddca3f4300000000000000000000000000000000000000000000000000000000815260208160048173ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000165afa91821561044a5761326a613d8e6125c894613270945f91613d93575b5062ffffff606481613d856118705f5460f01c90565b931604166124c9565b612860565b613db5915060203d602011613dbb575b613dad8183612441565b810190613c82565b5f613d6f565b503d613da3565b73ffffffffffffffffffffffffffffffffffffffff168015613e1b57806c010000000000000000000000000482105f14613e0e5790613e0482613e0993612d78565b612d78565b613cee565b613e0481613e0993612d78565b61311f565b6040517f01e1d11400000000000000000000000000000000000000000000000000000000815260208160048173ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000165afa91821561044a5761271092612ead925f91613ea1575b5061310c565b613eba915060203d602011610443576104358183612441565b5f613e9b565b919360a0936125c8969573ffffffffffffffffffffffffffffffffffffffff80941685521515602085015260408401521660608201528160808201520190610e0d565b906003547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8103614095575b50801561409057613fa092613fcc604093613f67613f4b612d17565b73ffffffffffffffffffffffffffffffffffffffff9092168252565b60208181018581528651925173ffffffffffffffffffffffffffffffffffffffff16918301919091525160408201529485906060820190565b037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08101865285612441565b8015614072576140116401000276a4945b845195869485947f128acb080000000000000000000000000000000000000000000000000000000086523060048701613ec0565b03815f73ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000165af1801561044a5761405a5750565b6132879060403d6040116127ae5761279e8183612441565b61401173fffd8963efd1fc6a506488495d951d5263988d2594613fdd565b505050565b73ffffffffffffffffffffffffffffffffffffffff807f00000000000000000000000000000000000000000000000000000000000000001690841614805f1461410e5781835b116140e7575b50613f2f565b909150156140f7575b5f806140e1565b61410990614103613b86565b906144a9565b6140f0565b8161411884612d54565b6140db565b604080517f70a0823100000000000000000000000000000000000000000000000000000000808252306004830152909160209173ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000081169290918486602481875afa95861561044a575f966143fe575b5081518181523060048201529185836024817f000000000000000000000000000000000000000000000000000000000000000088165afa92831561044a575f936143df575b5086925f976141fe6118705f5461ffff9060d01c1690565b806143b6575b505061420e613b86565b906142198282613c97565b9461422486826124c9565b9586156143a957846004988151998a80927fc4a7761e0000000000000000000000000000000000000000000000000000000082527f0000000000000000000000000000000000000000000000000000000000000000165afa97881561044a575f905f99614387575b50801597888061437f575b614370578b9860035415614319575b506142bf969798996142b992879261454a565b90614634565b5190815230600482015291829060249082905afa91821561044a575f926142fc575b505081811061328757612b2d916142f791612870565b61474b565b6143129250803d10610443576104358183612441565b5f806142e1565b80919a979899509015614368575b841590811561435f575b159081614357575b50614349578a979695985f6142a6565b505050505050505050505050565b90505f614339565b84159150614331565b508515614327565b50505050505050505050505050565b508915614297565b90506143a1919850853d87116127ae5761279e8183612441565b97905f61428c565b5050505050505050505050565b9098506143c4919450613e20565b968781111561306057876143d791612870565b925f80614204565b6143f7919350863d8811610443576104358183612441565b915f6141e6565b614416919650853d8711610443576104358183612441565b945f6141a1565b905f602091828151910182855af115612491575f513d6144a0575073ffffffffffffffffffffffffffffffffffffffff81163b155b6144595750565b60249073ffffffffffffffffffffffffffffffffffffffff604051917f5274afe7000000000000000000000000000000000000000000000000000000008352166004820152fd5b60011415614452565b908115612909577f0000000000000000000000000000000000000000000000000000000000000000156145255773ffffffffffffffffffffffffffffffffffffffff168015613e1b57806c010000000000000000000000000482105f146145185790613e04826125c893612d78565b613e04816125c893612d78565b9073ffffffffffffffffffffffffffffffffffffffff6125c8921690613ce982612de4565b9281158061462c575b6127b5577f0000000000000000000000000000000000000000000000000000000000000000156145c5576145ad919273ffffffffffffffffffffffffffffffffffffffff6145a6921690613ce982612de4565b80926124c9565b905b81156145be576125c892612e08565b5050505f90565b73ffffffffffffffffffffffffffffffffffffffff168015613e1b57806c010000000000000000000000000482105f146146195790613e048261460793612d78565b905b8181018091116124d657906145af565b613e048161462693612d78565b90614609565b508215614553565b909391929361465b61189a6001546fffffffffffffffffffffffffffffffff9060601c1690565b92828211156146bb575061467192939450612870565b918083116146b3575b508115159081614696575b5061468d5750565b612b2d90614912565b8015915081156146a8575b505f614685565b90508110155f6146a1565b91505f61467a565b9293508082116146cd575b5050505050565b6146d691612870565b918015908115614725575b506146ee575b80806146c6565b6146f7916144a9565b9080821161471d575b508061470e575b80806146e7565b61471790613455565b5f614707565b90505f614700565b90508210155f6146e1565b90816060910312610015578051916040602083015192015190565b6040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015273ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000811692602083602481875afa91821561044a576148ab946060945f946148e9575b50838261482c9261482786957f000000000000000000000000000000000000000000000000000000000000000016968780947f000000000000000000000000000000000000000000000000000000000000000016614974565b614974565b7f0000000000000000000000000000000000000000000000000000000000000000156148e457915b6040517f365d0ed7000000000000000000000000000000000000000000000000000000008152600481019390935260248301525f6044830181905260648301819052306084840152919384928391829060a4820190565b03925af1801561044a576148bc5750565b6140909060603d6060116148dd575b6148d58183612441565b810190614730565b503d6148cb565b614854565b839294509061490961482c9260203d602011610443576104358183612441565b949250906147ce565b612b2d907f00000000000000000000000000000000000000000000000000000000000000009073ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016613f03565b6040517f095ea7b300000000000000000000000000000000000000000000000000000000602080830182815273ffffffffffffffffffffffffffffffffffffffff86166024850152604480850197909752958352909491937fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0929091905f906149fe606488612441565b86519082875af15f513d82614a71575b505015614a1c575050505050565b604051602081019590955273ffffffffffffffffffffffffffffffffffffffff1660248501525f604485015260649081018452614a67936137fd91614a619082612441565b8261441d565b5f808080806146c6565b909150614a9b575073ffffffffffffffffffffffffffffffffffffffff83163b15155b5f80614a0e565b600114614a9456fea26469706673582212203e6ef66f56bcae705f9be8b4c39b0a54875e9c739ed8e71e1b10d6f4a363fda564736f6c63430008170033a2646970667358221220dd635445737581e8bf97b8efe2193cd576d48c2e6b2c7d6af6227b699a18642164736f6c63430008170033000000000000000000000000787aba336583f4a1d4f8cbbfdffd49f3a38de665000000000000000000000000be7c7efc1ef3245d37e3157f76a512108d6d7ae6000000000000000000000000283132390ea87d6ecc20255b59ba94329ee17961000000000000000000000000be7c7efc1ef3245d37e3157f76a512108d6d7ae6

Deployed Bytecode

0x608060408181526004918236101562000016575f80fd5b5f925f3560e01c91826308483906146200084e575081630d00442414620007e6578163363bf96414620006cf57816370905dce146200065f5781638144f84314620005e357816388a8d6021462000590578163aced1661146200053c578163d49db09c14620000e6575063ed27f7c9146200008f575f80fd5b34620000e257817ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112620000e25760209073ffffffffffffffffffffffffffffffffffffffff600154169051908152f35b5080fd5b838334620004a95760a07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112620004a957620001236200099a565b9060249182359167ffffffffffffffff95868411620004a95736602385011215620004a9578381013592878411620004a95736868587010111620004a9576200016b620009e2565b94606435986fffffffffffffffffffffffffffffffff8a16809a03620004a95773ffffffffffffffffffffffffffffffffffffffff80931695865f5260209a60038c5284875f20991698895f528c5284875f205416620004e25786519361520f80860194851186861017620004b7578360c095938f958e7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09560a08f998c9a601f9862000aef8d398a528901528260a089015201888701375f8783870101528c8b860152606085015260843560808501520116010301905ff08015620004ad57811695620002598762000a48565b50845f5260038952835f20865f528952835f20877fffffffffffffffffffffffff00000000000000000000000000000000000000008254161790558160015416873b15620004a9578451907f6a5f1aa2000000000000000000000000000000000000000000000000000000008252848201525f818381838c5af180156200049f5762000489575b508160025416873b156200046d578451907f748747e60000000000000000000000000000000000000000000000000000000082528482015288818381838c5af18015620004635790899162000471575b50548216873b156200046d578451907ff629b7900000000000000000000000000000000000000000000000000000000082528482015288818381838c5af1801562000463579089916200044b575b5050863b15620004475790879184519384927f35da33940000000000000000000000000000000000000000000000000000000084527f000000000000000000000000be7c7efc1ef3245d37e3157f76a512108d6d7ae616908301528183895af180156200043d5785929187916200041c575b50507f7346178ece6372241ea463631930b7671917f47398a07d305f81a4d00eddc10390519580a48152f35b6200042a9192935062000a06565b620004395783908588620003f0565b8480fd5b82513d88823e3d90fd5b8780fd5b620004569062000a06565b6200044757878a6200037e565b85513d8b823e3d90fd5b8880fd5b6200047c9062000a06565b6200044757878a62000330565b6200049691985062000a06565b5f9689620002e0565b85513d5f823e3d90fd5b5f80fd5b83513d5f823e3d90fd5b8b6041897f4e487b71000000000000000000000000000000000000000000000000000000005f52525ffd5b60648c878c8a51927f08c379a0000000000000000000000000000000000000000000000000000000008452828401528201527f216e6577000000000000000000000000000000000000000000000000000000006044820152fd5b8234620004a9575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112620004a95760209073ffffffffffffffffffffffffffffffffffffffff600254169051908152f35b8234620004a9575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112620004a95760209073ffffffffffffffffffffffffffffffffffffffff5f54169051908152f35b8234620004a957807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112620004a957602090620006216200099a565b6200062b620009be565b73ffffffffffffffffffffffffffffffffffffffff8092165f526003845281835f2091165f528352815f2054169051908152f35b8234620004a9575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112620004a9576020905173ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000be7c7efc1ef3245d37e3157f76a512108d6d7ae6168152f35b905034620004a95760607ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112620004a9576200070c6200099a565b62000716620009be565b62000720620009e2565b915f549073ffffffffffffffffffffffffffffffffffffffff94858316330362000789577fffffffffffffffffffffffff0000000000000000000000000000000000000000808416838816175f5560018054821686891617905560028054909116868816179055005b60649060208851917f08c379a0000000000000000000000000000000000000000000000000000000008352820152600b60248201527f216d616e6167656d656e740000000000000000000000000000000000000000006044820152fd5b8234620004a95760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112620004a95760209073ffffffffffffffffffffffffffffffffffffffff6200083a6200099a565b165f5260058252805f205415159051908152f35b839034620004a9575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112620004a957825491828252602090828281018095875f527f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19b905f5b8682821062000982575050505003601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01683019467ffffffffffffffff8611848710176200095657508481528185529151818501819052849392840192915f5b8281106200092857505050500390f35b835173ffffffffffffffffffffffffffffffffffffffff168552869550938101939281019260010162000918565b6041907f4e487b71000000000000000000000000000000000000000000000000000000005f525260245ffd5b835485528895509093019260019283019201620008b6565b6004359073ffffffffffffffffffffffffffffffffffffffff82168203620004a957565b6024359073ffffffffffffffffffffffffffffffffffffffff82168203620004a957565b6044359073ffffffffffffffffffffffffffffffffffffffff82168203620004a957565b67ffffffffffffffff811162000a1b57604052565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b805f52600560205260405f2054155f1462000ae9576004546801000000000000000081101562000a1b57600181018060045581101562000abc5781907f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19b0155600454905f52600560205260405f2055600190565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b505f9056fe610140806040523462000265576200520f803803809162000020826200027d565b833960a08183019112620002655762000038620002cd565b6101608051939192916001600160401b03851162000265578261015f8601121562000265578401516200006b81620002fd565b926200007b6040519485620002a9565b8184528282870101116200026557620000bf946200009f9260208501910162000319565b620000a9620002e5565b620000b36200033c565b916101c05193620003e8565b604051614ad990816200073682396080518181816103d301528181611cd4015281816125280152818161336f015281816136bb0152818161384e015281816140ad0152818161416701528181614802015261494f015260a0518181816104ae015281816106410152818161073c015281816108ac01528181610a4001528181610d3001528181610f97015281816112010152818161138b0152818161155e0152818161168401528181611a8401528181611bc801528181611df401528181611f0d015281816122d6015281816128c00152818161320a0152613e63015260c051818181610bda015281816117fe015281816119cc0152818161266401528181612f0001528181613b390152818161425a01526147dc015260e05181818161211901528181613bc901528181613d31015261402b0152610100518181816117310152818161257201528181612fcc0152818161347e01528181613771015281816141b5015261478e01526101205181818161273e0152818161345b015281816136f001528181613ca0015281816144b2015281816145590152818161482e01526149180152f35b5f80fd5b634e487b7160e01b5f52604160045260245ffd5b601f01601f1916610140908101906001600160401b03821190821017620002a357604052565b62000269565b601f909101601f19168101906001600160401b03821190821017620002a357604052565b61014051906001600160a01b03821682036200026557565b61018051906001600160a01b03821682036200026557565b6001600160401b038111620002a357601f01601f191660200190565b5f5b8381106200032b5750505f910152565b81810151838201526020016200031b565b6101a051906001600160801b03821682036200026557565b156200035c57565b60405162461bcd60e51b8152602060048201526002602482015261021360f41b6044820152606490fd5b908160209103126200026557516001600160a01b0381168103620002655790565b6040513d5f823e3d90fd5b15620003ba57565b60405162461bcd60e51b815260206004820152600660248201526508585cdcd95d60d21b6044820152606490fd5b90620003f791949394620005e6565b5f80546001600160e01b03166206407d60e31b1790556001805462012c6463ffffffff199091161790555f196002556001600160a01b03908116926200043f84151562000354565b60c08490526040516316f0115b60e01b8152602092908381600481895afa9081156200059a575f91620005c4575b5060e052604051630dfe168160e01b81528381600481895afa9081156200059a5760049685915f93620005a0575b5060405163d21220a760e01b815297889182905afa9182156200059a57620005259662000520955f9462000564575b505060805181166001600160a01b031690828116820362000527575050600161012081905261010092909252508054600160601b600160e01b03191660609290921b600160601b600160e01b0316919091179055565b600355565b565b6200053592931614620003b2565b6101005260018054600160601b600160e01b03191660609290921b600160601b600160e01b0316919091179055565b62000589929450803d1062000592575b620005808183620002a9565b81019062000386565b915f80620004ca565b503d62000574565b620003a7565b620005bc919350823d84116200059257620005808183620002a9565b915f6200049b565b620005df9150843d86116200059257620005808183620002a9565b5f6200046d565b906200066660e46200066c9360018060a01b0316806080523060a052604051938491634b839d7360e11b6020840152602483015260a060448301526200063c815180928160c48601526020868601910162000319565b3360648301523360848301523360a4830152601f801991011681010360c4810184520182620002a9565b620006ca565b5073d377919fa87120584b21279a491f82d5265a139c7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc55620006b5600160ff195f5416175f55565b620005256227100062ffff00195f5416175f55565b5f809160208151910173d377919fa87120584b21279a491f82d5265a139c5af43d156200072c573d90620006fe82620002fd565b916200070e6040519384620002a9565b82523d5f602084013e5b15620007215790565b6040513d90815f823efd5b6060906200071856fe60806040526004361015610019575b3415612d24575b5f80fd5b5f3560e01c806302f12120146102e357806304bd4629146102de5780630a0f9941146102d9578063139dd2bf146102d45780631d881fc4146102cf5780631f1f5869146102ca578063219461ed146102c55780632828b202146102c05780632c377490146102bb5780632cd68034146102b65780633204fb5b146102b15780633d6cb5751461029857806341db6dbf146102ac57806346aa2f12146102a757806349317f1d146102a25780634a5d09431461029d578063503160d914610298578063525e99da146102935780635bd246481461028e5780635d265d3f146102895780635db2b728146102845780635df31d611461027f5780636718835f1461027a5780636d6987c11461027557806371ee95c01461027057806375c45dce1461026b5780637d969932146102665780637d9f6db514610261578063950b3d731461025c5780639c455fb2146102575780639cfc3c5c146102525780639d7fb70c1461024d578063a1bac55014610248578063a73801f014610243578063ac00ff261461023e578063ae8c2a7014610239578063b8c6f57914610234578063bdc8144b1461022f578063d19a3bb81461022a578063d696860114610225578063e46cd10214610220578063ecf708581461021b578063fa461e3314610216578063fc7f71b6146102115763fde813a80361000e576123cf565b612282565b6120b2565b612077565b612027565b611ec3565b611e77565b611dad565b611b72565b611b30565b611a31565b6119f0565b611982565b6117ad565b611639565b61150b565b611341565b6112ee565b6112ad565b6111ae565b6110fb565b611089565b61104a565b610f44565b610ef4565b610e69565b610cdd565b610ca0565b610ad5565b610c5f565b610b8d565b610b49565b610b0e565b6109f6565b6109af565b610977565b610849565b6107fd565b6107bf565b6106f5565b6105ee565b61045b565b610350565b6102f2565b5f91031261001557565b34610015575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261001557602061032a6124db565b604051908152f35b73ffffffffffffffffffffffffffffffffffffffff81160361001557565b346100155760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100155761038a600435610332565b6040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015260208160248173ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000165afa801561044a57610417915f9161041b575b506040519081529081906020820190565b0390f35b61043d915060203d602011610443575b6104358183612441565b810190612482565b5f610406565b503d61042b565b612491565b61ffff81160361001557565b34610015575f60207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610015576004356104978161044f565b73ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016803b15610015575f602491604051928380927f48e4a6490000000000000000000000000000000000000000000000000000000082523360048301525afa801561044a576105d1575b506103e861ffff821611610573577dffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7fffff00000000000000000000000000000000000000000000000000000000000083549260f01b16911617815580f35b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600960248201527f21646973636f756e7400000000000000000000000000000000000000000000006044820152fd5b6105dc919250612411565b5f905f610516565b8015150361001557565b34610015575f60207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100155760043561062a816105e4565b73ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016803b15610015575f602491604051928380927f48e4a6490000000000000000000000000000000000000000000000000000000082523360048301525afa801561044a576106e2575b5081547fffffffffffffffffffffffffffffffffffffffffffffffffffff00ffffffffff1690151560281b65ff00000000001617815580f35b6106ed919250612411565b5f905f6106a9565b34610015575f60207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100155773ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016803b15610015575f602491604051928380927f48e4a6490000000000000000000000000000000000000000000000000000000082523360048301525afa801561044a576107ae575b5060043560035580f35b6107b89150612411565b5f806107a4565b34610015575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261001557602060ff60015416604051908152f35b34610015575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610015576020604051733ef3d8ba38ebe18db133cec108f4d14ce00dd9ae8152f35b34610015575f60207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610015576004356fffffffffffffffffffffffffffffffff811681036100155773ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016803b15610015575f602491604051928380927f48e4a6490000000000000000000000000000000000000000000000000000000082523360048301525afa801561044a57610964575b507fffffffff00000000000000000000000000000000ffffffffffffffffffffffff7bffffffffffffffffffffffffffffffff0000000000000000000000006001549260601b1691161760015580f35b61096f919250612411565b5f905f610914565b34610015575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261001557602061032a61261d565b34610015575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261001557602060015467ffffffffffffffff60405191831c168152f35b34610015575f60207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100155760043573ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016803b15610015575f602491604051928380927f48e4a6490000000000000000000000000000000000000000000000000000000082523360048301525afa801561044a57610ac0575b5080610ab8610abd9215156127fb565b612eb1565b80f35b610acb919250612411565b5f90610abd610aa8565b346100155760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261001557610b0c61308c565b005b34610015575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610015576020600354604051908152f35b346100155760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261001557610b83600435610332565b602061032a61287d565b34610015575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261001557610bc361308c565b73ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016803b15610015575f80916004604051809481937f181783580000000000000000000000000000000000000000000000000000000083525af1801561044a57610c50575b6020610c476124db565b61032a816131b1565b610c5990612411565b5f610c3d565b34610015575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261001557602061ffff5f5460081c16604051908152f35b34610015575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100155760205f5460f01c604051908152f35b34610015575f60207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261001557600435610d198161044f565b73ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016803b15610015575f602491604051928380927f48e4a6490000000000000000000000000000000000000000000000000000000082523360048301525afa801561044a57610dfa575b50610dab61271061ffff8316111561292e565b7fffff0000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff7dffff0000000000000000000000000000000000000000000000000000000083549260e01b16911617815580f35b610e05919250612411565b5f905f610d98565b91908251928382525f5b848110610e555750507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f845f6020809697860101520116010190565b602081830181015184830182015201610e17565b34610015575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261001557610e9f613300565b604051907f440368a300000000000000000000000000000000000000000000000000000000602083015260048252610ed682612425565b61041760405192839215158352604060208401526040830190610e0d565b34610015575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261001557602062ffffff60015460081c16604051908152f35b62ffffff81160361001557565b34610015575f60207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261001557600435610f8081610f37565b73ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016803b15610015575f602491604051928380927f48e4a6490000000000000000000000000000000000000000000000000000000082523360048301525afa801561044a57611037575b507fffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000ff63ffffff006001549260081b1691161760015580f35b611042919250612411565b5f905f610fff565b34610015575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261001557602060ff5f54166040519015158152f35b34610015575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261001557602061ffff5f5460e01c16604051908152f35b9181601f840112156100155782359167ffffffffffffffff8311610015576020808501948460051b01011161001557565b346100155760807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100155767ffffffffffffffff6004358181116100155761114b9036906004016110ca565b90602435838111610015576111649036906004016110ca565b906044358581116100155761117d9036906004016110ca565b9290916064359687116100155761119b610b0c9736906004016110ca565b969095612a24565b60ff81160361001557565b34610015575f60207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610015576004356111ea816111a3565b73ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016803b15610015575f602491604051928380927f48e4a6490000000000000000000000000000000000000000000000000000000082523360048301525afa801561044a57611299575b5060ff167fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00600154161760015580f35b6112a4919250612411565b5f9060ff611269565b34610015575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261001557602061ffff5f5460181c16604051908152f35b34610015575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261001557602073ffffffffffffffffffffffffffffffffffffffff5f5460301c16604051908152f35b34610015575f60207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100155760043573ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016803b15610015575f602491604051928380927f48e4a6490000000000000000000000000000000000000000000000000000000082523360048301525afa801561044a576114f8575b50801561149a5761ffff80821161143c57610abd91167fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000ff62ffff005f549260081b169116175f55565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600960248201527f21746f6f206869676800000000000000000000000000000000000000000000006044820152fd5b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600c60248201527f217a65726f2070726f66697400000000000000000000000000000000000000006044820152fd5b611503919250612411565b5f905f6113f3565b34610015575f60207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610015576004356115478161044f565b73ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016803b15610015575f602491604051928380927f48e4a6490000000000000000000000000000000000000000000000000000000082523360048301525afa801561044a57611626575b506115d961271061ffff8316111561292e565b7fffffffff0000ffffffffffffffffffffffffffffffffffffffffffffffffffff7bffff000000000000000000000000000000000000000000000000000083549260d01b16911617815580f35b611631919250612411565b5f905f6115c6565b34610015575f60207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100155773ffffffffffffffffffffffffffffffffffffffff906004357f00000000000000000000000000000000000000000000000000000000000000008316803b15610015575f602491604051928380927f48e4a6490000000000000000000000000000000000000000000000000000000082523360048301525afa801561044a57611796575b506020602492936116ff8315156127fb565b604051938480927f70a082310000000000000000000000000000000000000000000000000000000082523060048301527f0000000000000000000000000000000000000000000000000000000000000000165afa91821561044a57610abd92611772918591611777575b50821115612bd3565b613455565b611790915060203d602011610443576104358183612441565b5f611769565b602492506117a390612411565b60205f92506116ed565b346100155760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610015576004356117e761308c565b73ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016803b15610015575f80916004604051809481937f181783580000000000000000000000000000000000000000000000000000000083525af1801561044a57611969575b505f546118779060d01c61ffff165b61ffff1690565b906118af61189a6001546fffffffffffffffffffffffffffffffff9060601c1690565b6fffffffffffffffffffffffffffffffff1690565b91801561195b576118bf90613e20565b908181111561192357906118d291612870565b1015611916575b600180547fffffffffffffffffffffffffffffffffffffffff0000000000000000ffffffff164260201b6bffffffffffffffff0000000016179055005b61191e61411d565b6118d9565b818110611933575b5050506118d9565b61193c91612870565b9081101561194c575b808061192b565b61195590612eb1565b5f611945565b50106118d95761191e61411d565b8061197661197c92612411565b806102e8565b5f611861565b34610015575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261001557602060405173ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000168152f35b34610015575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261001557602061ffff5f5460d01c16604051908152f35b34610015575f60207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261001557600435611a6d816105e4565b73ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016803b15610015575f602491604051928380927f48e4a6490000000000000000000000000000000000000000000000000000000082523360048301525afa801561044a57611b1d575b5060ff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff005f541691151516175f5580f35b611b28919250612411565b5f905f611aec565b34610015575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261001557602060ff5f5460281c166040519015158152f35b34610015575f6020807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261001557600435611baf81610332565b73ffffffffffffffffffffffffffffffffffffffff91827f000000000000000000000000000000000000000000000000000000000000000016803b15610015575f602491604051928380927f48e4a6490000000000000000000000000000000000000000000000000000000082523360048301525afa801561044a57611d9a575b508282169283611c8a575b84610abd847fffffffffffff0000000000000000000000000000000000000000ffffffffffff79ffffffffffffffffffffffffffffffffffffffff0000000000005f549260301b169116175f55565b604051937f1f1fcd510000000000000000000000000000000000000000000000000000000085528285600481845afa90811561044a57611cfb84926004978991611d7d575b5084167f0000000000000000000000000000000000000000000000000000000000000000851614612c4d565b604051958680927ff7260d3e0000000000000000000000000000000000000000000000000000000082525afa90811561044a57610abd94611d47938793611d4e575b5050163014612cb2565b5f80611c3b565b611d6e929350803d10611d76575b611d668183612441565b810190612c38565b905f80611d3d565b503d611d5c565b611d949150843d8611611d7657611d668183612441565b5f611ccf565b611da5919450612411565b5f925f611c30565b34610015575f60207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100155773ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016803b15610015575f602491604051928380927f48e4a6490000000000000000000000000000000000000000000000000000000082523360048301525afa801561044a57611e66575b5060043560025580f35b611e709150612411565b5f80611e5c565b34610015575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261001557602060405173d377919fa87120584b21279a491f82d5265a139c8152f35b34610015575f60207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100155760043573ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016803b15610015575f602491604051928380927f48e4a6490000000000000000000000000000000000000000000000000000000082523360048301525afa801561044a57612014575b50612710811015611fb6577fffffffffffffffffffffffffffffffffffffffffffffffffffffff0000ffffff64ffff00000083549260181b16911617815580f35b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600b60248201527f216c6f7373206c696d69740000000000000000000000000000000000000000006044820152fd5b61201f919250612411565b5f905f611f75565b34610015575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100155760206fffffffffffffffffffffffffffffffff60015460601c16604051908152f35b34610015575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610015576020600254604051908152f35b346100155760607ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100155767ffffffffffffffff6044358181116100155736602382011215610015578060040135828111610015578101366024820111610015577f00000000000000000000000000000000000000000000000000000000000000009073ffffffffffffffffffffffffffffffffffffffff9081831633036122245783604091031261001557604051906040820194828610908611176121f7576121d96121f2926121bf6121b66121d994610b0c99604052602489013561219c81610332565b8085526044602086019a01358a521660243560043561369b565b965187146127fb565b5173ffffffffffffffffffffffffffffffffffffffff1690565b73ffffffffffffffffffffffffffffffffffffffff1690565b61379b565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600760248201527f2163616c6c6572000000000000000000000000000000000000000000000000006044820152fd5b34610015575f60207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610015576004356122be81610332565b73ffffffffffffffffffffffffffffffffffffffff807f00000000000000000000000000000000000000000000000000000000000000001692833b15610015575f602494604051958680927f48e4a6490000000000000000000000000000000000000000000000000000000082523360048301525afa93841561044a5761234f946123be575b505460301c16613817565b901561236057604051908152602090f35b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600560248201527f216b69636b0000000000000000000000000000000000000000000000000000006044820152fd5b6123c89150612411565b5f80612344565b346100155760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100155761240661308c565b610b0c600435612eb1565b67ffffffffffffffff81116121f757604052565b6040810190811067ffffffffffffffff8211176121f757604052565b90601f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0910116810190811067ffffffffffffffff8211176121f757604052565b90816020910312610015575190565b6040513d5f823e3d90fd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b919082018092116124d657565b61249c565b6040517f70a082310000000000000000000000000000000000000000000000000000000080825230600483015260209173ffffffffffffffffffffffffffffffffffffffff9083816024817f000000000000000000000000000000000000000000000000000000000000000086165afa92831561044a5784915f946125e8575b5060405190815230600482015291829060249082907f0000000000000000000000000000000000000000000000000000000000000000165afa92831561044a576125c8936125c3926125b5925f926125cb575b5050612d54565b6125bd61261d565b926124c9565b6124c9565b90565b6125e19250803d10610443576104358183612441565b5f806125ae565b612600919450823d8411610443576104358183612441565b925f61255b565b9190826040910312610015576020825192015190565b604080517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015290602073ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000168184602481845afa93841561044a575f946127dc575b5083156127b55782517f18160ddd0000000000000000000000000000000000000000000000000000000081528281600481855afa92831561044a575f936127bd575b505081156127b557826004918151928380927fc4a7761e0000000000000000000000000000000000000000000000000000000082525afa90811561044a5761273c9383915f915f94612781575b5050906127369186612e08565b93612e08565b7f000000000000000000000000000000000000000000000000000000000000000015612775579061276f6125c892612d54565b906124c9565b61276f6125c892612d54565b6127369394506127a69250803d106127ae575b61279e8183612441565b810190612607565b92915f612729565b503d612794565b505050505f90565b6127d4929350803d10610443576104358183612441565b905f806126dc565b6127f4919450823d8411610443576104358183612441565b925f61269a565b1561280257565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600760248201527f21616d6f756e74000000000000000000000000000000000000000000000000006044820152fd5b906127109182039182116124d657565b919082039182116124d657565b6040517f01e1d11400000000000000000000000000000000000000000000000000000000815260208160048173ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000165afa90811561044a575f9161290f575b5060025490808211156129095781039081116124d65790565b50505f90565b612928915060203d602011610443576104358183612441565b5f6128f0565b1561293557565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600460248201527f21627073000000000000000000000000000000000000000000000000000000006044820152fd5b9190808252602080920192915f5b8281106129af575050505090565b90919293828060019273ffffffffffffffffffffffffffffffffffffffff88356129d881610332565b168152019501939291016129a1565b90918281527f07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff83116100155760209260051b809284830137010190565b9594969390919296733ef3d8ba38ebe18db133cec108f4d14ce00dd9ae96873b15610015579790612ac7612ad79392612a9560409997989699519b8c9a7f71ee95c0000000000000000000000000000000000000000000000000000000008c52608060048d015260848c0191612993565b907ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc98898b84030160248c0152612993565b91868884030160448901526129e7565b92848403016064850152808352602080840193600560208460051b83010195855f935b868510612b2f57505050505050505091815f81819503925af1801561044a57612b205750565b80611976612b2d92612411565b565b919395979092949698507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe082820301845288357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe18436030181121561001557830187810191903567ffffffffffffffff81116100155780871b3603831361001557612bbf899283926001956129e7565b9a0194019501929593918a98979591612afa565b15612bda57565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600860248201527f2162616c616e63650000000000000000000000000000000000000000000000006044820152fd5b9081602091031261001557516125c881610332565b15612c5457565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600560248201527f2177616e740000000000000000000000000000000000000000000000000000006044820152fd5b15612cb957565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600960248201527f21726563656976657200000000000000000000000000000000000000000000006044820152fd5b60405190612b2d82612425565b365f80375f80368173d377919fa87120584b21279a491f82d5265a139c5af43d5f803e15612d50573d5ff35b3d5ffd5b8015612d6c576125c890612d66613b86565b90613c97565b505f90565b1561001557565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8282099082810292838084109303928084039314612ddb576c010000000000000000000000009183831115610015570990828211900360a01b910360601c1790565b50505060601c90565b80156100155778010000000000000000000000000000000000000000000000000490565b90917fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8383099280830292838086109503948086039514612e9e57908291612e51868411612d71565b0981805f0316809204600280826003021880830282030280830282030280830282030280830282030280830282030280920290030293600183805f03040190848311900302920304170290565b50509150612ead821515612d71565b0490565b801561308957604080517f70a082310000000000000000000000000000000000000000000000000000000080825230600483015260209373ffffffffffffffffffffffffffffffffffffffff937f000000000000000000000000000000000000000000000000000000000000000085169390918682602481885afa91821561044a575f9261306a575b50612f4361261d565b90811561306057818110613050575050925b83156130485781517fd331bef700000000000000000000000000000000000000000000000000000000815260048101949094525f6024850181905260448501819052306064860152829185916084918391905af192831561044a57859361302c575b505190815230600482015291829060249082907f0000000000000000000000000000000000000000000000000000000000000000165afa91821561044a575f9261300f575b5050806130065750565b612b2d90613455565b6130259250803d10610443576104358183612441565b5f80612ffc565b61304290823d84116127ae5761279e8183612441565b50612fb7565b505050505050565b9161305a92612e08565b92612f55565b5050505050505050565b613082919250873d8911610443576104358183612441565b905f612f3a565b50565b30330361309557565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600560248201527f2173656c660000000000000000000000000000000000000000000000000000006044820152fd5b90633b9aca00918281029281840414901517156124d657565b818102929181159184041417156124d657565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601260045260245ffd5b1561315357565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600b60248201527f6865616c7468436865636b0000000000000000000000000000000000000000006044820152fd5b6131c36131bf5f5460ff1690565b1590565b6132d1576040517f01e1d11400000000000000000000000000000000000000000000000000000000815260208160048173ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000165afa90811561044a575f916132b2575b508082111561327f5761327861327061325683612b2d95612870565b9261326a6118705f5461ffff9060081c1690565b9061310c565b612710900490565b101561314c565b81811161328b575b5050565b61327861327061329e612b2d9484612870565b9261326a6118705f5461ffff9060181c1690565b6132cb915060203d602011610443576104358183612441565b5f61323a565b50612b2d60017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff005f5416175f55565b60015461332262ffffff8260081c1667ffffffffffffffff8360201c166124c9565b4210612d6c5761333460ff82166130f3565b4811612d6c576040517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152906020826024817f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff165afa91821561044a575f92613434575b505f549061ffff808360d01c16806133ef57505060601c6fffffffffffffffffffffffffffffffff169050806133ea5750151590565b111590565b61341f925061340f9161340461327092613e20565b9460e01c168461310c565b61341981846124c9565b92612870565b90821191821561342e57505090565b10919050565b61344e91925060203d602011610443576104358183612441565b905f6133b4565b612b2d907f000000000000000000000000000000000000000000000000000000000000000015907f0000000000000000000000000000000000000000000000000000000000000000613f03565b156134a957565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600660248201527f21746f6b656e00000000000000000000000000000000000000000000000000006044820152fd5b1561350e57565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600960248201527f21616d6f756e74302b00000000000000000000000000000000000000000000006044820152fd5b1561357357565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600960248201527f21616d6f756e74312d00000000000000000000000000000000000000000000006044820152fd5b156135d857565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600960248201527f21616d6f756e74312b00000000000000000000000000000000000000000000006044820152fd5b1561363d57565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600960248201527f21616d6f756e74302d00000000000000000000000000000000000000000000006044820152fd5b916136ee73ffffffffffffffffffffffffffffffffffffffff80921691807f0000000000000000000000000000000000000000000000000000000000000000168314928391841561376f575b50506134a2565b7f000000000000000000000000000000000000000000000000000000000000000015613746571561372f575f6125c891613729828513613507565b1261356c565b905f6125c8916137408285136135d1565b12613636565b9091901561375e575f6125c8916137408285136135d1565b905f6125c891613729828513613507565b7f0000000000000000000000000000000000000000000000000000000000000000161490505f806136e7565b6040517fa9059cbb00000000000000000000000000000000000000000000000000000000602082015273ffffffffffffffffffffffffffffffffffffffff929092166024830152604480830193909352918152612b2d916137fd606483612441565b61441d565b9081602091031261001557516125c8816105e4565b5f5491929161382a9060281c60ff161590565b8015613b68575b613b605773ffffffffffffffffffffffffffffffffffffffff92837f00000000000000000000000000000000000000000000000000000000000000001693808216908582148015613b35575b613a78576040517f9f8a13d700000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff871660048201526020969185169491908781602481895afa91821561044a5788915f93613b06575b508215613a84575b5050613a78576040517f70a08231000000000000000000000000000000000000000000000000000000008082523060048301529091908783602481875afa92831561044a575f93613a59575b5060405190815273ffffffffffffffffffffffffffffffffffffffff821660048201528781602481875afa801561044a5761397b915f91613a3c575b50836124c9565b15613a2f57926139e5928288955f9794613a1e575b5050506040519485809481937f96c551750000000000000000000000000000000000000000000000000000000083526004830191909173ffffffffffffffffffffffffffffffffffffffff6020820193169052565b03925af192831561044a575f936139ff575b505060019190565b613a16929350803d10610443576104358183612441565b905f806139f7565b613a279261379b565b5f8080613990565b505050505090505f905f90565b613a539150893d8b11610443576104358183612441565b5f613974565b613a71919350883d8a11610443576104358183612441565b915f613938565b5050505090505f905f90565b6040517f10098ad500000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff919091166004820152915081602481885afa90811561044a575f91613ae9575b501515865f6138ec565b613b009150873d8911610443576104358183612441565b5f613adf565b613b27919350823d8411613b2e575b613b1f8183612441565b810190613802565b915f6138e4565b503d613b15565b50807f000000000000000000000000000000000000000000000000000000000000000016821461387d565b505f91508190565b5073ffffffffffffffffffffffffffffffffffffffff811615613831565b6040517f3850c7bd00000000000000000000000000000000000000000000000000000000815260e08160048173ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000165afa90811561044a575f91613bfc575090565b905060e0813d60e011613c7a575b81613c1760e09383612441565b8101031261001557805190613c2b82610332565b60208101518060020b036100155760c081613c4c60406125c894015161044f565b613c59606082015161044f565b613c66608082015161044f565b613c7360a08201516111a3565b01516105e4565b3d9150613c0a565b9081602091031261001557516125c881610f37565b908115612909577f000000000000000000000000000000000000000000000000000000000000000015613dc2579073ffffffffffffffffffffffffffffffffffffffff613cee921690613ce982612de4565b612e08565b6040517fddca3f4300000000000000000000000000000000000000000000000000000000815260208160048173ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000165afa91821561044a5761326a613d8e6125c894613270945f91613d93575b5062ffffff606481613d856118705f5460f01c90565b931604166124c9565b612860565b613db5915060203d602011613dbb575b613dad8183612441565b810190613c82565b5f613d6f565b503d613da3565b73ffffffffffffffffffffffffffffffffffffffff168015613e1b57806c010000000000000000000000000482105f14613e0e5790613e0482613e0993612d78565b612d78565b613cee565b613e0481613e0993612d78565b61311f565b6040517f01e1d11400000000000000000000000000000000000000000000000000000000815260208160048173ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000165afa91821561044a5761271092612ead925f91613ea1575b5061310c565b613eba915060203d602011610443576104358183612441565b5f613e9b565b919360a0936125c8969573ffffffffffffffffffffffffffffffffffffffff80941685521515602085015260408401521660608201528160808201520190610e0d565b906003547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8103614095575b50801561409057613fa092613fcc604093613f67613f4b612d17565b73ffffffffffffffffffffffffffffffffffffffff9092168252565b60208181018581528651925173ffffffffffffffffffffffffffffffffffffffff16918301919091525160408201529485906060820190565b037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08101865285612441565b8015614072576140116401000276a4945b845195869485947f128acb080000000000000000000000000000000000000000000000000000000086523060048701613ec0565b03815f73ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000165af1801561044a5761405a5750565b6132879060403d6040116127ae5761279e8183612441565b61401173fffd8963efd1fc6a506488495d951d5263988d2594613fdd565b505050565b73ffffffffffffffffffffffffffffffffffffffff807f00000000000000000000000000000000000000000000000000000000000000001690841614805f1461410e5781835b116140e7575b50613f2f565b909150156140f7575b5f806140e1565b61410990614103613b86565b906144a9565b6140f0565b8161411884612d54565b6140db565b604080517f70a0823100000000000000000000000000000000000000000000000000000000808252306004830152909160209173ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000081169290918486602481875afa95861561044a575f966143fe575b5081518181523060048201529185836024817f000000000000000000000000000000000000000000000000000000000000000088165afa92831561044a575f936143df575b5086925f976141fe6118705f5461ffff9060d01c1690565b806143b6575b505061420e613b86565b906142198282613c97565b9461422486826124c9565b9586156143a957846004988151998a80927fc4a7761e0000000000000000000000000000000000000000000000000000000082527f0000000000000000000000000000000000000000000000000000000000000000165afa97881561044a575f905f99614387575b50801597888061437f575b614370578b9860035415614319575b506142bf969798996142b992879261454a565b90614634565b5190815230600482015291829060249082905afa91821561044a575f926142fc575b505081811061328757612b2d916142f791612870565b61474b565b6143129250803d10610443576104358183612441565b5f806142e1565b80919a979899509015614368575b841590811561435f575b159081614357575b50614349578a979695985f6142a6565b505050505050505050505050565b90505f614339565b84159150614331565b508515614327565b50505050505050505050505050565b508915614297565b90506143a1919850853d87116127ae5761279e8183612441565b97905f61428c565b5050505050505050505050565b9098506143c4919450613e20565b968781111561306057876143d791612870565b925f80614204565b6143f7919350863d8811610443576104358183612441565b915f6141e6565b614416919650853d8711610443576104358183612441565b945f6141a1565b905f602091828151910182855af115612491575f513d6144a0575073ffffffffffffffffffffffffffffffffffffffff81163b155b6144595750565b60249073ffffffffffffffffffffffffffffffffffffffff604051917f5274afe7000000000000000000000000000000000000000000000000000000008352166004820152fd5b60011415614452565b908115612909577f0000000000000000000000000000000000000000000000000000000000000000156145255773ffffffffffffffffffffffffffffffffffffffff168015613e1b57806c010000000000000000000000000482105f146145185790613e04826125c893612d78565b613e04816125c893612d78565b9073ffffffffffffffffffffffffffffffffffffffff6125c8921690613ce982612de4565b9281158061462c575b6127b5577f0000000000000000000000000000000000000000000000000000000000000000156145c5576145ad919273ffffffffffffffffffffffffffffffffffffffff6145a6921690613ce982612de4565b80926124c9565b905b81156145be576125c892612e08565b5050505f90565b73ffffffffffffffffffffffffffffffffffffffff168015613e1b57806c010000000000000000000000000482105f146146195790613e048261460793612d78565b905b8181018091116124d657906145af565b613e048161462693612d78565b90614609565b508215614553565b909391929361465b61189a6001546fffffffffffffffffffffffffffffffff9060601c1690565b92828211156146bb575061467192939450612870565b918083116146b3575b508115159081614696575b5061468d5750565b612b2d90614912565b8015915081156146a8575b505f614685565b90508110155f6146a1565b91505f61467a565b9293508082116146cd575b5050505050565b6146d691612870565b918015908115614725575b506146ee575b80806146c6565b6146f7916144a9565b9080821161471d575b508061470e575b80806146e7565b61471790613455565b5f614707565b90505f614700565b90508210155f6146e1565b90816060910312610015578051916040602083015192015190565b6040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015273ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000811692602083602481875afa91821561044a576148ab946060945f946148e9575b50838261482c9261482786957f000000000000000000000000000000000000000000000000000000000000000016968780947f000000000000000000000000000000000000000000000000000000000000000016614974565b614974565b7f0000000000000000000000000000000000000000000000000000000000000000156148e457915b6040517f365d0ed7000000000000000000000000000000000000000000000000000000008152600481019390935260248301525f6044830181905260648301819052306084840152919384928391829060a4820190565b03925af1801561044a576148bc5750565b6140909060603d6060116148dd575b6148d58183612441565b810190614730565b503d6148cb565b614854565b839294509061490961482c9260203d602011610443576104358183612441565b949250906147ce565b612b2d907f00000000000000000000000000000000000000000000000000000000000000009073ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016613f03565b6040517f095ea7b300000000000000000000000000000000000000000000000000000000602080830182815273ffffffffffffffffffffffffffffffffffffffff86166024850152604480850197909752958352909491937fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0929091905f906149fe606488612441565b86519082875af15f513d82614a71575b505015614a1c575050505050565b604051602081019590955273ffffffffffffffffffffffffffffffffffffffff1660248501525f604485015260649081018452614a67936137fd91614a619082612441565b8261441d565b5f808080806146c6565b909150614a9b575073ffffffffffffffffffffffffffffffffffffffff83163b15155b5f80614a0e565b600114614a9456fea26469706673582212203e6ef66f56bcae705f9be8b4c39b0a54875e9c739ed8e71e1b10d6f4a363fda564736f6c63430008170033a2646970667358221220dd635445737581e8bf97b8efe2193cd576d48c2e6b2c7d6af6227b699a18642164736f6c63430008170033

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

000000000000000000000000787aba336583f4a1d4f8cbbfdffd49f3a38de665000000000000000000000000be7c7efc1ef3245d37e3157f76a512108d6d7ae6000000000000000000000000283132390ea87d6ecc20255b59ba94329ee17961000000000000000000000000be7c7efc1ef3245d37e3157f76a512108d6d7ae6

-----Decoded View---------------
Arg [0] : _management (address): 0x787aba336583f4A1D4f8cBBFDFFD49f3a38De665
Arg [1] : _performanceFeeRecipient (address): 0xBe7c7efc1ef3245d37E3157F76A512108D6D7aE6
Arg [2] : _keeper (address): 0x283132390eA87D6ecc20255B59Ba94329eE17961
Arg [3] : _emergencyAdmin (address): 0xBe7c7efc1ef3245d37E3157F76A512108D6D7aE6

-----Encoded View---------------
4 Constructor Arguments found :
Arg [0] : 000000000000000000000000787aba336583f4a1d4f8cbbfdffd49f3a38de665
Arg [1] : 000000000000000000000000be7c7efc1ef3245d37e3157f76a512108d6d7ae6
Arg [2] : 000000000000000000000000283132390ea87d6ecc20255b59ba94329ee17961
Arg [3] : 000000000000000000000000be7c7efc1ef3245d37e3157f76a512108d6d7ae6


Deployed Bytecode Sourcemap

264:3491:38:-:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;550:38;264:3491;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;1790:18;264:3491;;;;;;;;;;;;;;;;;;;;;;;;;2002:63;;;;;;;;;;;;;;264:3491;2002:63;;;;;264:3491;2002:63;264:3491;2002:63;;;;264:3491;2002:63;;;;264:3491;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2002:63;;;264:3491;2002:63;;;;;264:3491;;9425:50:19;;;;:::i;:::-;;264:3491:38;;;1790:18;264:3491;;;;;;;;;;;;;;;;;;;;;;;;;2219:64;;;;;264:3491;;2219:64;264:3491;2219:64;;;;;264:3491;;2219:64;;;;;;;;;;;;;264:3491;;;2316:6;264:3491;;2293:30;;;;;264:3491;;2293:30;264:3491;2293:30;;;;;264:3491;2293:30;;;;;;;;;;;;;;;;;264:3491;-1:-1:-1;264:3491:38;;;2333:45;;;;;264:3491;;2333:45;264:3491;2333:45;;;;;264:3491;2333:45;;;;;;;;;;;;;;;;;264:3491;2388:46;;;;;;;264:3491;;;;;2388:46;;;264:3491;2388:46;;2419:14;264:3491;2388:46;;;264:3491;2388:46;;;;;;;;;;;;;;;;264:3491;;;2450:52;264:3491;;2450:52;;;264:3491;;;2388:46;;;;;;;:::i;:::-;264:3491;;2388:46;;;;;;264:3491;;;;2388:46;264:3491;;;;;;;;;2388:46;264:3491;;;2333:45;;;;:::i;:::-;264:3491;;2333:45;;;;;264:3491;;;;;;;;;2333:45;264:3491;;;2293:30;;;;:::i;:::-;264:3491;;2293:30;;;;2219:64;;;;;;:::i;:::-;264:3491;2219:64;;;;;264:3491;;;;;;;;;2219:64;264:3491;;;2002:63;264:3491;;;;;;;;;2002:63;264:3491;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;594:21;264:3491;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;:::i;:::-;;;;;;;3715:18;264:3491;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;473:39;264:3491;;;;;;;;;;;;;;;;;;;:::i;:::-;;;:::i;:::-;;;:::i;:::-;;;;;;;;;;2930:10;:24;264:3491;;;;;;;;;;;;3014:50;264:3491;;;;;;;;;;3074:16;264:3491;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;5006:14:19;264:3491:38;;;;;;5006:26:19;;264:3491:38;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;;264:3491:38;;;;;;;;;;;;;;;;;-1:-1:-1;264:3491:38;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;264:3491:38;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;264:3491:38;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;:::o;:::-;;;;;;;;;;;:::o;:::-;;;;;;;;:::o;:::-;;;;;;;;;;2336:406:19;264:3491:38;-1:-1:-1;264:3491:38;5006:14:19;264:3491:38;;;-1:-1:-1;264:3491:38;;5006:26:19;2415:321;264:3491:38;;;;;;;;;;;5006:14:19;264:3491:38;;;;;;;;;;;;;;;;;;-1:-1:-1;264:3491:38;5006:14:19;264:3491:38;;;-1:-1:-1;264:3491:38;;5006:14:19;2671:11;:::o;264:3491:38:-;;-1:-1:-1;264:3491:38;;;;;-1:-1:-1;264:3491:38;2415:321:19;2713:12;-1:-1:-1;2713:12:19;:::o

Swarm Source

ipfs://dd635445737581e8bf97b8efe2193cd576d48c2e6b2c7d6af6227b699a186421

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

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

Validator Index Block Amount
View All Withdrawals

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

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