creation_sourcecode: {{
    "language": "Solidity",
    "sources": {
      "@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\nimport './pool/IUniswapV3PoolImmutables.sol';\nimport './pool/IUniswapV3PoolState.sol';\nimport './pool/IUniswapV3PoolDerivedState.sol';\nimport './pool/IUniswapV3PoolActions.sol';\nimport './pool/IUniswapV3PoolOwnerActions.sol';\nimport './pool/IUniswapV3PoolEvents.sol';\n\n/// @title The interface for a Uniswap V3 Pool\n/// @notice A Uniswap pool facilitates swapping and automated market making between any two assets that strictly conform\n/// to the ERC20 specification\n/// @dev The pool interface is broken up into many smaller pieces\ninterface IUniswapV3Pool is\n    IUniswapV3PoolImmutables,\n    IUniswapV3PoolState,\n    IUniswapV3PoolDerivedState,\n    IUniswapV3PoolActions,\n    IUniswapV3PoolOwnerActions,\n    IUniswapV3PoolEvents\n{\n\n}\n"
      },
      "@uniswap/v3-core/contracts/interfaces/pool/IUniswapV3PoolActions.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\n/// @title Permissionless pool actions\n/// @notice Contains pool methods that can be called by anyone\ninterface IUniswapV3PoolActions {\n    /// @notice Sets the initial price for the pool\n    /// @dev Price is represented as a sqrt(amountToken1/amountToken0) Q64.96 value\n    /// @param sqrtPriceX96 the initial sqrt price of the pool as a Q64.96\n    function initialize(uint160 sqrtPriceX96) external;\n\n    /// @notice Adds liquidity for the given recipient/tickLower/tickUpper position\n    /// @dev The caller of this method receives a callback in the form of IUniswapV3MintCallback#uniswapV3MintCallback\n    /// in which they must pay any token0 or token1 owed for the liquidity. The amount of token0/token1 due depends\n    /// on tickLower, tickUpper, the amount of liquidity, and the current price.\n    /// @param recipient The address for which the liquidity will be created\n    /// @param tickLower The lower tick of the position in which to add liquidity\n    /// @param tickUpper The upper tick of the position in which to add liquidity\n    /// @param amount The amount of liquidity to mint\n    /// @param data Any data that should be passed through to the callback\n    /// @return amount0 The amount of token0 that was paid to mint the given amount of liquidity. Matches the value in the callback\n    /// @return amount1 The amount of token1 that was paid to mint the given amount of liquidity. Matches the value in the callback\n    function mint(\n        address recipient,\n        int24 tickLower,\n        int24 tickUpper,\n        uint128 amount,\n        bytes calldata data\n    ) external returns (uint256 amount0, uint256 amount1);\n\n    /// @notice Collects tokens owed to a position\n    /// @dev Does not recompute fees earned, which must be done either via mint or burn of any amount of liquidity.\n    /// Collect must be called by the position owner. To withdraw only token0 or only token1, amount0Requested or\n    /// amount1Requested may be set to zero. To withdraw all tokens owed, caller may pass any value greater than the\n    /// actual tokens owed, e.g. type(uint128).max. Tokens owed may be from accumulated swap fees or burned liquidity.\n    /// @param recipient The address which should receive the fees collected\n    /// @param tickLower The lower tick of the position for which to collect fees\n    /// @param tickUpper The upper tick of the position for which to collect fees\n    /// @param amount0Requested How much token0 should be withdrawn from the fees owed\n    /// @param amount1Requested How much token1 should be withdrawn from the fees owed\n    /// @return amount0 The amount of fees collected in token0\n    /// @return amount1 The amount of fees collected in token1\n    function collect(\n        address recipient,\n        int24 tickLower,\n        int24 tickUpper,\n        uint128 amount0Requested,\n        uint128 amount1Requested\n    ) external returns (uint128 amount0, uint128 amount1);\n\n    /// @notice Burn liquidity from the sender and account tokens owed for the liquidity to the position\n    /// @dev Can be used to trigger a recalculation of fees owed to a position by calling with an amount of 0\n    /// @dev Fees must be collected separately via a call to #collect\n    /// @param tickLower The lower tick of the position for which to burn liquidity\n    /// @param tickUpper The upper tick of the position for which to burn liquidity\n    /// @param amount How much liquidity to burn\n    /// @return amount0 The amount of token0 sent to the recipient\n    /// @return amount1 The amount of token1 sent to the recipient\n    function burn(\n        int24 tickLower,\n        int24 tickUpper,\n        uint128 amount\n    ) external returns (uint256 amount0, uint256 amount1);\n\n    /// @notice Swap token0 for token1, or token1 for token0\n    /// @dev The caller of this method receives a callback in the form of IUniswapV3SwapCallback#uniswapV3SwapCallback\n    /// @param recipient The address to receive the output of the swap\n    /// @param zeroForOne The direction of the swap, true for token0 to token1, false for token1 to token0\n    /// @param amountSpecified The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative)\n    /// @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this\n    /// value after the swap. If one for zero, the price cannot be greater than this value after the swap\n    /// @param data Any data to be passed through to the callback\n    /// @return amount0 The delta of the balance of token0 of the pool, exact when negative, minimum when positive\n    /// @return amount1 The delta of the balance of token1 of the pool, exact when negative, minimum when positive\n    function swap(\n        address recipient,\n        bool zeroForOne,\n        int256 amountSpecified,\n        uint160 sqrtPriceLimitX96,\n        bytes calldata data\n    ) external returns (int256 amount0, int256 amount1);\n\n    /// @notice Receive token0 and/or token1 and pay it back, plus a fee, in the callback\n    /// @dev The caller of this method receives a callback in the form of IUniswapV3FlashCallback#uniswapV3FlashCallback\n    /// @dev Can be used to donate underlying tokens pro-rata to currently in-range liquidity providers by calling\n    /// with 0 amount{0,1} and sending the donation amount(s) from the callback\n    /// @param recipient The address which will receive the token0 and token1 amounts\n    /// @param amount0 The amount of token0 to send\n    /// @param amount1 The amount of token1 to send\n    /// @param data Any data to be passed through to the callback\n    function flash(\n        address recipient,\n        uint256 amount0,\n        uint256 amount1,\n        bytes calldata data\n    ) external;\n\n    /// @notice Increase the maximum number of price and liquidity observations that this pool will store\n    /// @dev This method is no-op if the pool already has an observationCardinalityNext greater than or equal to\n    /// the input observationCardinalityNext.\n    /// @param observationCardinalityNext The desired minimum number of observations for the pool to store\n    function increaseObservationCardinalityNext(uint16 observationCardinalityNext) external;\n}\n"
      },
      "@uniswap/v3-core/contracts/interfaces/pool/IUniswapV3PoolDerivedState.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\n/// @title Pool state that is not stored\n/// @notice Contains view functions to provide information about the pool that is computed rather than stored on the\n/// blockchain. The functions here may have variable gas costs.\ninterface IUniswapV3PoolDerivedState {\n    /// @notice Returns the cumulative tick and liquidity as of each timestamp `secondsAgo` from the current block timestamp\n    /// @dev To get a time weighted average tick or liquidity-in-range, you must call this with two values, one representing\n    /// the beginning of the period and another for the end of the period. E.g., to get the last hour time-weighted average tick,\n    /// you must call it with secondsAgos = [3600, 0].\n    /// @dev The time weighted average tick represents the geometric time weighted average price of the pool, in\n    /// log base sqrt(1.0001) of token1 / token0. The TickMath library can be used to go from a tick value to a ratio.\n    /// @param secondsAgos From how long ago each cumulative tick and liquidity value should be returned\n    /// @return tickCumulatives Cumulative tick values as of each `secondsAgos` from the current block timestamp\n    /// @return secondsPerLiquidityCumulativeX128s Cumulative seconds per liquidity-in-range value as of each `secondsAgos` from the current block\n    /// timestamp\n    function observe(uint32[] calldata secondsAgos)\n        external\n        view\n        returns (int56[] memory tickCumulatives, uint160[] memory secondsPerLiquidityCumulativeX128s);\n\n    /// @notice Returns a snapshot of the tick cumulative, seconds per liquidity and seconds inside a tick range\n    /// @dev Snapshots must only be compared to other snapshots, taken over a period for which a position existed.\n    /// I.e., snapshots cannot be compared if a position is not held for the entire period between when the first\n    /// snapshot is taken and the second snapshot is taken.\n    /// @param tickLower The lower tick of the range\n    /// @param tickUpper The upper tick of the range\n    /// @return tickCumulativeInside The snapshot of the tick accumulator for the range\n    /// @return secondsPerLiquidityInsideX128 The snapshot of seconds per liquidity for the range\n    /// @return secondsInside The snapshot of seconds per liquidity for the range\n    function snapshotCumulativesInside(int24 tickLower, int24 tickUpper)\n        external\n        view\n        returns (\n            int56 tickCumulativeInside,\n            uint160 secondsPerLiquidityInsideX128,\n            uint32 secondsInside\n        );\n}\n"
      },
      "@uniswap/v3-core/contracts/interfaces/pool/IUniswapV3PoolEvents.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\n/// @title Events emitted by a pool\n/// @notice Contains all events emitted by the pool\ninterface IUniswapV3PoolEvents {\n    /// @notice Emitted exactly once by a pool when #initialize is first called on the pool\n    /// @dev Mint/Burn/Swap cannot be emitted by the pool before Initialize\n    /// @param sqrtPriceX96 The initial sqrt price of the pool, as a Q64.96\n    /// @param tick The initial tick of the pool, i.e. log base 1.0001 of the starting price of the pool\n    event Initialize(uint160 sqrtPriceX96, int24 tick);\n\n    /// @notice Emitted when liquidity is minted for a given position\n    /// @param sender The address that minted the liquidity\n    /// @param owner The owner of the position and recipient of any minted liquidity\n    /// @param tickLower The lower tick of the position\n    /// @param tickUpper The upper tick of the position\n    /// @param amount The amount of liquidity minted to the position range\n    /// @param amount0 How much token0 was required for the minted liquidity\n    /// @param amount1 How much token1 was required for the minted liquidity\n    event Mint(\n        address sender,\n        address indexed owner,\n        int24 indexed tickLower,\n        int24 indexed tickUpper,\n        uint128 amount,\n        uint256 amount0,\n        uint256 amount1\n    );\n\n    /// @notice Emitted when fees are collected by the owner of a position\n    /// @dev Collect events may be emitted with zero amount0 and amount1 when the caller chooses not to collect fees\n    /// @param owner The owner of the position for which fees are collected\n    /// @param tickLower The lower tick of the position\n    /// @param tickUpper The upper tick of the position\n    /// @param amount0 The amount of token0 fees collected\n    /// @param amount1 The amount of token1 fees collected\n    event Collect(\n        address indexed owner,\n        address recipient,\n        int24 indexed tickLower,\n        int24 indexed tickUpper,\n        uint128 amount0,\n        uint128 amount1\n    );\n\n    /// @notice Emitted when a position's liquidity is removed\n    /// @dev Does not withdraw any fees earned by the liquidity position, which must be withdrawn via #collect\n    /// @param owner The owner of the position for which liquidity is removed\n    /// @param tickLower The lower tick of the position\n    /// @param tickUpper The upper tick of the position\n    /// @param amount The amount of liquidity to remove\n    /// @param amount0 The amount of token0 withdrawn\n    /// @param amount1 The amount of token1 withdrawn\n    event Burn(\n        address indexed owner,\n        int24 indexed tickLower,\n        int24 indexed tickUpper,\n        uint128 amount,\n        uint256 amount0,\n        uint256 amount1\n    );\n\n    /// @notice Emitted by the pool for any swaps between token0 and token1\n    /// @param sender The address that initiated the swap call, and that received the callback\n    /// @param recipient The address that received the output of the swap\n    /// @param amount0 The delta of the token0 balance of the pool\n    /// @param amount1 The delta of the token1 balance of the pool\n    /// @param sqrtPriceX96 The sqrt(price) of the pool after the swap, as a Q64.96\n    /// @param liquidity The liquidity of the pool after the swap\n    /// @param tick The log base 1.0001 of price of the pool after the swap\n    event Swap(\n        address indexed sender,\n        address indexed recipient,\n        int256 amount0,\n        int256 amount1,\n        uint160 sqrtPriceX96,\n        uint128 liquidity,\n        int24 tick\n    );\n\n    /// @notice Emitted by the pool for any flashes of token0/token1\n    /// @param sender The address that initiated the swap call, and that received the callback\n    /// @param recipient The address that received the tokens from flash\n    /// @param amount0 The amount of token0 that was flashed\n    /// @param amount1 The amount of token1 that was flashed\n    /// @param paid0 The amount of token0 paid for the flash, which can exceed the amount0 plus the fee\n    /// @param paid1 The amount of token1 paid for the flash, which can exceed the amount1 plus the fee\n    event Flash(\n        address indexed sender,\n        address indexed recipient,\n        uint256 amount0,\n        uint256 amount1,\n        uint256 paid0,\n        uint256 paid1\n    );\n\n    /// @notice Emitted by the pool for increases to the number of observations that can be stored\n    /// @dev observationCardinalityNext is not the observation cardinality until an observation is written at the index\n    /// just before a mint/swap/burn.\n    /// @param observationCardinalityNextOld The previous value of the next observation cardinality\n    /// @param observationCardinalityNextNew The updated value of the next observation cardinality\n    event IncreaseObservationCardinalityNext(\n        uint16 observationCardinalityNextOld,\n        uint16 observationCardinalityNextNew\n    );\n\n    /// @notice Emitted when the protocol fee is changed by the pool\n    /// @param feeProtocol0Old The previous value of the token0 protocol fee\n    /// @param feeProtocol1Old The previous value of the token1 protocol fee\n    /// @param feeProtocol0New The updated value of the token0 protocol fee\n    /// @param feeProtocol1New The updated value of the token1 protocol fee\n    event SetFeeProtocol(uint8 feeProtocol0Old, uint8 feeProtocol1Old, uint8 feeProtocol0New, uint8 feeProtocol1New);\n\n    /// @notice Emitted when the collected protocol fees are withdrawn by the factory owner\n    /// @param sender The address that collects the protocol fees\n    /// @param recipient The address that receives the collected protocol fees\n    /// @param amount0 The amount of token0 protocol fees that is withdrawn\n    /// @param amount0 The amount of token1 protocol fees that is withdrawn\n    event CollectProtocol(address indexed sender, address indexed recipient, uint128 amount0, uint128 amount1);\n}\n"
      },
      "@uniswap/v3-core/contracts/interfaces/pool/IUniswapV3PoolImmutables.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\n/// @title Pool state that never changes\n/// @notice These parameters are fixed for a pool forever, i.e., the methods will always return the same values\ninterface IUniswapV3PoolImmutables {\n    /// @notice The contract that deployed the pool, which must adhere to the IUniswapV3Factory interface\n    /// @return The contract address\n    function factory() external view returns (address);\n\n    /// @notice The first of the two tokens of the pool, sorted by address\n    /// @return The token contract address\n    function token0() external view returns (address);\n\n    /// @notice The second of the two tokens of the pool, sorted by address\n    /// @return The token contract address\n    function token1() external view returns (address);\n\n    /// @notice The pool's fee in hundredths of a bip, i.e. 1e-6\n    /// @return The fee\n    function fee() external view returns (uint24);\n\n    /// @notice The pool tick spacing\n    /// @dev Ticks can only be used at multiples of this value, minimum of 1 and always positive\n    /// e.g.: a tickSpacing of 3 means ticks can be initialized every 3rd tick, i.e., ..., -6, -3, 0, 3, 6, ...\n    /// This value is an int24 to avoid casting even though it is always positive.\n    /// @return The tick spacing\n    function tickSpacing() external view returns (int24);\n\n    /// @notice The maximum amount of position liquidity that can use any tick in the range\n    /// @dev This parameter is enforced per tick to prevent liquidity from overflowing a uint128 at any point, and\n    /// also prevents out-of-range liquidity from being used to prevent adding in-range liquidity to a pool\n    /// @return The max amount of liquidity per tick\n    function maxLiquidityPerTick() external view returns (uint128);\n}\n"
      },
      "@uniswap/v3-core/contracts/interfaces/pool/IUniswapV3PoolOwnerActions.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\n/// @title Permissioned pool actions\n/// @notice Contains pool methods that may only be called by the factory owner\ninterface IUniswapV3PoolOwnerActions {\n    /// @notice Set the denominator of the protocol's % share of the fees\n    /// @param feeProtocol0 new protocol fee for token0 of the pool\n    /// @param feeProtocol1 new protocol fee for token1 of the pool\n    function setFeeProtocol(uint8 feeProtocol0, uint8 feeProtocol1) external;\n\n    /// @notice Collect the protocol fee accrued to the pool\n    /// @param recipient The address to which collected protocol fees should be sent\n    /// @param amount0Requested The maximum amount of token0 to send, can be 0 to collect fees in only token1\n    /// @param amount1Requested The maximum amount of token1 to send, can be 0 to collect fees in only token0\n    /// @return amount0 The protocol fee collected in token0\n    /// @return amount1 The protocol fee collected in token1\n    function collectProtocol(\n        address recipient,\n        uint128 amount0Requested,\n        uint128 amount1Requested\n    ) external returns (uint128 amount0, uint128 amount1);\n}\n"
      },
      "@uniswap/v3-core/contracts/interfaces/pool/IUniswapV3PoolState.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\n/// @title Pool state that can change\n/// @notice These methods compose the pool's state, and can change with any frequency including multiple times\n/// per transaction\ninterface IUniswapV3PoolState {\n    /// @notice The 0th storage slot in the pool stores many values, and is exposed as a single method to save gas\n    /// when accessed externally.\n    /// @return sqrtPriceX96 The current price of the pool as a sqrt(token1/token0) Q64.96 value\n    /// tick The current tick of the pool, i.e. according to the last tick transition that was run.\n    /// This value may not always be equal to SqrtTickMath.getTickAtSqrtRatio(sqrtPriceX96) if the price is on a tick\n    /// boundary.\n    /// observationIndex The index of the last oracle observation that was written,\n    /// observationCardinality The current maximum number of observations stored in the pool,\n    /// observationCardinalityNext The next maximum number of observations, to be updated when the observation.\n    /// feeProtocol The protocol fee for both tokens of the pool.\n    /// Encoded as two 4 bit values, where the protocol fee of token1 is shifted 4 bits and the protocol fee of token0\n    /// 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.\n    /// unlocked Whether the pool is currently locked to reentrancy\n    function slot0()\n        external\n        view\n        returns (\n            uint160 sqrtPriceX96,\n            int24 tick,\n            uint16 observationIndex,\n            uint16 observationCardinality,\n            uint16 observationCardinalityNext,\n            uint8 feeProtocol,\n            bool unlocked\n        );\n\n    /// @notice The fee growth as a Q128.128 fees of token0 collected per unit of liquidity for the entire life of the pool\n    /// @dev This value can overflow the uint256\n    function feeGrowthGlobal0X128() external view returns (uint256);\n\n    /// @notice The fee growth as a Q128.128 fees of token1 collected per unit of liquidity for the entire life of the pool\n    /// @dev This value can overflow the uint256\n    function feeGrowthGlobal1X128() external view returns (uint256);\n\n    /// @notice The amounts of token0 and token1 that are owed to the protocol\n    /// @dev Protocol fees will never exceed uint128 max in either token\n    function protocolFees() external view returns (uint128 token0, uint128 token1);\n\n    /// @notice The currently in range liquidity available to the pool\n    /// @dev This value has no relationship to the total liquidity across all ticks\n    function liquidity() external view returns (uint128);\n\n    /// @notice Look up information about a specific tick in the pool\n    /// @param tick The tick to look up\n    /// @return liquidityGross the total amount of position liquidity that uses the pool either as tick lower or\n    /// tick upper,\n    /// liquidityNet how much liquidity changes when the pool price crosses the tick,\n    /// feeGrowthOutside0X128 the fee growth on the other side of the tick from the current tick in token0,\n    /// feeGrowthOutside1X128 the fee growth on the other side of the tick from the current tick in token1,\n    /// tickCumulativeOutside the cumulative tick value on the other side of the tick from the current tick\n    /// secondsPerLiquidityOutsideX128 the seconds spent per liquidity on the other side of the tick from the current tick,\n    /// secondsOutside the seconds spent on the other side of the tick from the current tick,\n    /// initialized Set to true if the tick is initialized, i.e. liquidityGross is greater than 0, otherwise equal to false.\n    /// Outside values can only be used if the tick is initialized, i.e. if liquidityGross is greater than 0.\n    /// In addition, these values are only relative and must be used only in comparison to previous snapshots for\n    /// a specific position.\n    function ticks(int24 tick)\n        external\n        view\n        returns (\n            uint128 liquidityGross,\n            int128 liquidityNet,\n            uint256 feeGrowthOutside0X128,\n            uint256 feeGrowthOutside1X128,\n            int56 tickCumulativeOutside,\n            uint160 secondsPerLiquidityOutsideX128,\n            uint32 secondsOutside,\n            bool initialized\n        );\n\n    /// @notice Returns 256 packed tick initialized boolean values. See TickBitmap for more information\n    function tickBitmap(int16 wordPosition) external view returns (uint256);\n\n    /// @notice Returns the information about a position by the position's key\n    /// @param key The position's key is a hash of a preimage composed by the owner, tickLower and tickUpper\n    /// @return _liquidity The amount of liquidity in the position,\n    /// Returns feeGrowthInside0LastX128 fee growth of token0 inside the tick range as of the last mint/burn/poke,\n    /// Returns feeGrowthInside1LastX128 fee growth of token1 inside the tick range as of the last mint/burn/poke,\n    /// Returns tokensOwed0 the computed amount of token0 owed to the position as of the last mint/burn/poke,\n    /// Returns tokensOwed1 the computed amount of token1 owed to the position as of the last mint/burn/poke\n    function positions(bytes32 key)\n        external\n        view\n        returns (\n            uint128 _liquidity,\n            uint256 feeGrowthInside0LastX128,\n            uint256 feeGrowthInside1LastX128,\n            uint128 tokensOwed0,\n            uint128 tokensOwed1\n        );\n\n    /// @notice Returns data about a specific observation index\n    /// @param index The element of the observations array to fetch\n    /// @dev You most likely want to use #observe() instead of this method to get an observation as of some amount of time\n    /// ago, rather than at a specific index in the array.\n    /// @return blockTimestamp The timestamp of the observation,\n    /// Returns tickCumulative the tick multiplied by seconds elapsed for the life of the pool as of the observation timestamp,\n    /// Returns secondsPerLiquidityCumulativeX128 the seconds per in range liquidity for the life of the pool as of the observation timestamp,\n    /// Returns initialized whether the observation has been initialized and the values are safe to use\n    function observations(uint256 index)\n        external\n        view\n        returns (\n            uint32 blockTimestamp,\n            int56 tickCumulative,\n            uint160 secondsPerLiquidityCumulativeX128,\n            bool initialized\n        );\n}\n"
      },
      "@uniswap/v3-core/contracts/libraries/FullMath.sol": {
        "content": "// SPDX-License-Identifier: MIT\npragma solidity >=0.4.0 <0.8.0;\n\n/// @title Contains 512-bit math functions\n/// @notice Facilitates multiplication and division that can have overflow of an intermediate value without any loss of precision\n/// @dev Handles \"phantom overflow\" i.e., allows multiplication and division where an intermediate value overflows 256 bits\nlibrary FullMath {\n    /// @notice Calculates floor(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0\n    /// @param a The multiplicand\n    /// @param b The multiplier\n    /// @param denominator The divisor\n    /// @return result The 256-bit result\n    /// @dev Credit to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv\n    function mulDiv(\n        uint256 a,\n        uint256 b,\n        uint256 denominator\n    ) internal pure returns (uint256 result) {\n        // 512-bit multiply [prod1 prod0] = a * b\n        // Compute the product mod 2**256 and mod 2**256 - 1\n        // then use the Chinese Remainder Theorem to reconstruct\n        // the 512 bit result. The result is stored in two 256\n        // variables such that product = prod1 * 2**256 + prod0\n        uint256 prod0; // Least significant 256 bits of the product\n        uint256 prod1; // Most significant 256 bits of the product\n        assembly {\n            let mm := mulmod(a, b, not(0))\n            prod0 := mul(a, b)\n            prod1 := sub(sub(mm, prod0), lt(mm, prod0))\n        }\n\n        // Handle non-overflow cases, 256 by 256 division\n        if (prod1 == 0) {\n            require(denominator > 0);\n            assembly {\n                result := div(prod0, denominator)\n            }\n            return result;\n        }\n\n        // Make sure the result is less than 2**256.\n        // Also prevents denominator == 0\n        require(denominator > prod1);\n\n        ///////////////////////////////////////////////\n        // 512 by 256 division.\n        ///////////////////////////////////////////////\n\n        // Make division exact by subtracting the remainder from [prod1 prod0]\n        // Compute remainder using mulmod\n        uint256 remainder;\n        assembly {\n            remainder := mulmod(a, b, denominator)\n        }\n        // Subtract 256 bit number from 512 bit number\n        assembly {\n            prod1 := sub(prod1, gt(remainder, prod0))\n            prod0 := sub(prod0, remainder)\n        }\n\n        // Factor powers of two out of denominator\n        // Compute largest power of two divisor of denominator.\n        // Always >= 1.\n        uint256 twos = -denominator & denominator;\n        // Divide denominator by power of two\n        assembly {\n            denominator := div(denominator, twos)\n        }\n\n        // Divide [prod1 prod0] by the factors of two\n        assembly {\n            prod0 := div(prod0, twos)\n        }\n        // Shift in bits from prod1 into prod0. For this we need\n        // to flip `twos` such that it is 2**256 / twos.\n        // If twos is zero, then it becomes one\n        assembly {\n            twos := add(div(sub(0, twos), twos), 1)\n        }\n        prod0 |= prod1 * twos;\n\n        // Invert denominator mod 2**256\n        // Now that denominator is an odd number, it has an inverse\n        // modulo 2**256 such that denominator * inv = 1 mod 2**256.\n        // Compute the inverse by starting with a seed that is correct\n        // correct for four bits. That is, denominator * inv = 1 mod 2**4\n        uint256 inv = (3 * denominator) ^ 2;\n        // Now use Newton-Raphson iteration to improve the precision.\n        // Thanks to Hensel's lifting lemma, this also works in modular\n        // arithmetic, doubling the correct bits in each step.\n        inv *= 2 - denominator * inv; // inverse mod 2**8\n        inv *= 2 - denominator * inv; // inverse mod 2**16\n        inv *= 2 - denominator * inv; // inverse mod 2**32\n        inv *= 2 - denominator * inv; // inverse mod 2**64\n        inv *= 2 - denominator * inv; // inverse mod 2**128\n        inv *= 2 - denominator * inv; // inverse mod 2**256\n\n        // Because the division is now exact we can divide by multiplying\n        // with the modular inverse of denominator. This will give us the\n        // correct result modulo 2**256. Since the precoditions guarantee\n        // that the outcome is less than 2**256, this is the final result.\n        // We don't need to compute the high bits of the result and prod1\n        // is no longer required.\n        result = prod0 * inv;\n        return result;\n    }\n\n    /// @notice Calculates ceil(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0\n    /// @param a The multiplicand\n    /// @param b The multiplier\n    /// @param denominator The divisor\n    /// @return result The 256-bit result\n    function mulDivRoundingUp(\n        uint256 a,\n        uint256 b,\n        uint256 denominator\n    ) internal pure returns (uint256 result) {\n        result = mulDiv(a, b, denominator);\n        if (mulmod(a, b, denominator) > 0) {\n            require(result < type(uint256).max);\n            result++;\n        }\n    }\n}\n"
      },
      "@uniswap/v3-core/contracts/libraries/SafeCast.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\n/// @title Safe casting methods\n/// @notice Contains methods for safely casting between types\nlibrary SafeCast {\n    /// @notice Cast a uint256 to a uint160, revert on overflow\n    /// @param y The uint256 to be downcasted\n    /// @return z The downcasted integer, now type uint160\n    function toUint160(uint256 y) internal pure returns (uint160 z) {\n        require((z = uint160(y)) == y);\n    }\n\n    /// @notice Cast a int256 to a int128, revert on overflow or underflow\n    /// @param y The int256 to be downcasted\n    /// @return z The downcasted integer, now type int128\n    function toInt128(int256 y) internal pure returns (int128 z) {\n        require((z = int128(y)) == y);\n    }\n\n    /// @notice Cast a uint256 to a int256, revert on overflow\n    /// @param y The uint256 to be casted\n    /// @return z The casted integer, now type int256\n    function toInt256(uint256 y) internal pure returns (int256 z) {\n        require(y < 2**255);\n        z = int256(y);\n    }\n}\n"
      },
      "@uniswap/v3-core/contracts/libraries/TickMath.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0 <0.8.0;\n\n/// @title Math library for computing sqrt prices from ticks and vice versa\n/// @notice Computes sqrt price for ticks of size 1.0001, i.e. sqrt(1.0001^tick) as fixed point Q64.96 numbers. Supports\n/// prices between 2**-128 and 2**128\nlibrary TickMath {\n    /// @dev The minimum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**-128\n    int24 internal constant MIN_TICK = -887272;\n    /// @dev The maximum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**128\n    int24 internal constant MAX_TICK = -MIN_TICK;\n\n    /// @dev The minimum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MIN_TICK)\n    uint160 internal constant MIN_SQRT_RATIO = 4295128739;\n    /// @dev The maximum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MAX_TICK)\n    uint160 internal constant MAX_SQRT_RATIO = 1461446703485210103287273052203988822378723970342;\n\n    /// @notice Calculates sqrt(1.0001^tick) * 2^96\n    /// @dev Throws if |tick| > max tick\n    /// @param tick The input tick for the above formula\n    /// @return sqrtPriceX96 A Fixed point Q64.96 number representing the sqrt of the ratio of the two assets (token1/token0)\n    /// at the given tick\n    function getSqrtRatioAtTick(int24 tick) internal pure returns (uint160 sqrtPriceX96) {\n        uint256 absTick = tick < 0 ? uint256(-int256(tick)) : uint256(int256(tick));\n        require(absTick <= uint256(MAX_TICK), 'T');\n\n        uint256 ratio = absTick & 0x1 != 0 ? 0xfffcb933bd6fad37aa2d162d1a594001 : 0x100000000000000000000000000000000;\n        if (absTick & 0x2 != 0) ratio = (ratio * 0xfff97272373d413259a46990580e213a) >> 128;\n        if (absTick & 0x4 != 0) ratio = (ratio * 0xfff2e50f5f656932ef12357cf3c7fdcc) >> 128;\n        if (absTick & 0x8 != 0) ratio = (ratio * 0xffe5caca7e10e4e61c3624eaa0941cd0) >> 128;\n        if (absTick & 0x10 != 0) ratio = (ratio * 0xffcb9843d60f6159c9db58835c926644) >> 128;\n        if (absTick & 0x20 != 0) ratio = (ratio * 0xff973b41fa98c081472e6896dfb254c0) >> 128;\n        if (absTick & 0x40 != 0) ratio = (ratio * 0xff2ea16466c96a3843ec78b326b52861) >> 128;\n        if (absTick & 0x80 != 0) ratio = (ratio * 0xfe5dee046a99a2a811c461f1969c3053) >> 128;\n        if (absTick & 0x100 != 0) ratio = (ratio * 0xfcbe86c7900a88aedcffc83b479aa3a4) >> 128;\n        if (absTick & 0x200 != 0) ratio = (ratio * 0xf987a7253ac413176f2b074cf7815e54) >> 128;\n        if (absTick & 0x400 != 0) ratio = (ratio * 0xf3392b0822b70005940c7a398e4b70f3) >> 128;\n        if (absTick & 0x800 != 0) ratio = (ratio * 0xe7159475a2c29b7443b29c7fa6e889d9) >> 128;\n        if (absTick & 0x1000 != 0) ratio = (ratio * 0xd097f3bdfd2022b8845ad8f792aa5825) >> 128;\n        if (absTick & 0x2000 != 0) ratio = (ratio * 0xa9f746462d870fdf8a65dc1f90e061e5) >> 128;\n        if (absTick & 0x4000 != 0) ratio = (ratio * 0x70d869a156d2a1b890bb3df62baf32f7) >> 128;\n        if (absTick & 0x8000 != 0) ratio = (ratio * 0x31be135f97d08fd981231505542fcfa6) >> 128;\n        if (absTick & 0x10000 != 0) ratio = (ratio * 0x9aa508b5b7a84e1c677de54f3e99bc9) >> 128;\n        if (absTick & 0x20000 != 0) ratio = (ratio * 0x5d6af8dedb81196699c329225ee604) >> 128;\n        if (absTick & 0x40000 != 0) ratio = (ratio * 0x2216e584f5fa1ea926041bedfe98) >> 128;\n        if (absTick & 0x80000 != 0) ratio = (ratio * 0x48a170391f7dc42444e8fa2) >> 128;\n\n        if (tick > 0) ratio = type(uint256).max / ratio;\n\n        // this divides by 1<<32 rounding up to go from a Q128.128 to a Q128.96.\n        // we then downcast because we know the result always fits within 160 bits due to our tick input constraint\n        // we round up in the division so getTickAtSqrtRatio of the output price is always consistent\n        sqrtPriceX96 = uint160((ratio >> 32) + (ratio % (1 << 32) == 0 ? 0 : 1));\n    }\n\n    /// @notice Calculates the greatest tick value such that getRatioAtTick(tick) <= ratio\n    /// @dev Throws in case sqrtPriceX96 < MIN_SQRT_RATIO, as MIN_SQRT_RATIO is the lowest value getRatioAtTick may\n    /// ever return.\n    /// @param sqrtPriceX96 The sqrt ratio for which to compute the tick as a Q64.96\n    /// @return tick The greatest tick for which the ratio is less than or equal to the input ratio\n    function getTickAtSqrtRatio(uint160 sqrtPriceX96) internal pure returns (int24 tick) {\n        // second inequality must be < because the price can never reach the price at the max tick\n        require(sqrtPriceX96 >= MIN_SQRT_RATIO && sqrtPriceX96 < MAX_SQRT_RATIO, 'R');\n        uint256 ratio = uint256(sqrtPriceX96) << 32;\n\n        uint256 r = ratio;\n        uint256 msb = 0;\n\n        assembly {\n            let f := shl(7, gt(r, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))\n            msb := or(msb, f)\n            r := shr(f, r)\n        }\n        assembly {\n            let f := shl(6, gt(r, 0xFFFFFFFFFFFFFFFF))\n            msb := or(msb, f)\n            r := shr(f, r)\n        }\n        assembly {\n            let f := shl(5, gt(r, 0xFFFFFFFF))\n            msb := or(msb, f)\n            r := shr(f, r)\n        }\n        assembly {\n            let f := shl(4, gt(r, 0xFFFF))\n            msb := or(msb, f)\n            r := shr(f, r)\n        }\n        assembly {\n            let f := shl(3, gt(r, 0xFF))\n            msb := or(msb, f)\n            r := shr(f, r)\n        }\n        assembly {\n            let f := shl(2, gt(r, 0xF))\n            msb := or(msb, f)\n            r := shr(f, r)\n        }\n        assembly {\n            let f := shl(1, gt(r, 0x3))\n            msb := or(msb, f)\n            r := shr(f, r)\n        }\n        assembly {\n            let f := gt(r, 0x1)\n            msb := or(msb, f)\n        }\n\n        if (msb >= 128) r = ratio >> (msb - 127);\n        else r = ratio << (127 - msb);\n\n        int256 log_2 = (int256(msb) - 128) << 64;\n\n        assembly {\n            r := shr(127, mul(r, r))\n            let f := shr(128, r)\n            log_2 := or(log_2, shl(63, f))\n            r := shr(f, r)\n        }\n        assembly {\n            r := shr(127, mul(r, r))\n            let f := shr(128, r)\n            log_2 := or(log_2, shl(62, f))\n            r := shr(f, r)\n        }\n        assembly {\n            r := shr(127, mul(r, r))\n            let f := shr(128, r)\n            log_2 := or(log_2, shl(61, f))\n            r := shr(f, r)\n        }\n        assembly {\n            r := shr(127, mul(r, r))\n            let f := shr(128, r)\n            log_2 := or(log_2, shl(60, f))\n            r := shr(f, r)\n        }\n        assembly {\n            r := shr(127, mul(r, r))\n            let f := shr(128, r)\n            log_2 := or(log_2, shl(59, f))\n            r := shr(f, r)\n        }\n        assembly {\n            r := shr(127, mul(r, r))\n            let f := shr(128, r)\n            log_2 := or(log_2, shl(58, f))\n            r := shr(f, r)\n        }\n        assembly {\n            r := shr(127, mul(r, r))\n            let f := shr(128, r)\n            log_2 := or(log_2, shl(57, f))\n            r := shr(f, r)\n        }\n        assembly {\n            r := shr(127, mul(r, r))\n            let f := shr(128, r)\n            log_2 := or(log_2, shl(56, f))\n            r := shr(f, r)\n        }\n        assembly {\n            r := shr(127, mul(r, r))\n            let f := shr(128, r)\n            log_2 := or(log_2, shl(55, f))\n            r := shr(f, r)\n        }\n        assembly {\n            r := shr(127, mul(r, r))\n            let f := shr(128, r)\n            log_2 := or(log_2, shl(54, f))\n            r := shr(f, r)\n        }\n        assembly {\n            r := shr(127, mul(r, r))\n            let f := shr(128, r)\n            log_2 := or(log_2, shl(53, f))\n            r := shr(f, r)\n        }\n        assembly {\n            r := shr(127, mul(r, r))\n            let f := shr(128, r)\n            log_2 := or(log_2, shl(52, f))\n            r := shr(f, r)\n        }\n        assembly {\n            r := shr(127, mul(r, r))\n            let f := shr(128, r)\n            log_2 := or(log_2, shl(51, f))\n            r := shr(f, r)\n        }\n        assembly {\n            r := shr(127, mul(r, r))\n            let f := shr(128, r)\n            log_2 := or(log_2, shl(50, f))\n        }\n\n        int256 log_sqrt10001 = log_2 * 255738958999603826347141; // 128.128 number\n\n        int24 tickLow = int24((log_sqrt10001 - 3402992956809132418596140100660247210) >> 128);\n        int24 tickHi = int24((log_sqrt10001 + 291339464771989622907027621153398088495) >> 128);\n\n        tick = tickLow == tickHi ? tickLow : getSqrtRatioAtTick(tickHi) <= sqrtPriceX96 ? tickHi : tickLow;\n    }\n}\n"
      },
      "@uniswap/v3-periphery/contracts/libraries/PositionKey.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\nlibrary PositionKey {\n    /// @dev Returns the key of the position in the core library\n    function compute(\n        address owner,\n        int24 tickLower,\n        int24 tickUpper\n    ) internal pure returns (bytes32) {\n        return keccak256(abi.encodePacked(owner, tickLower, tickUpper));\n    }\n}\n"
      },
      "contracts/_interfaces/external/IAlphaProVault.sol": {
        "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// solhint-disable-next-line compiler-version\npragma solidity ^0.7.6;\n\nimport { IUniswapV3Pool } from \"@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol\";\n\n/// @notice Interface for the Charm's AlphaProVault\ninterface IAlphaProVault {\n    function deposit(\n        uint256,\n        uint256,\n        uint256,\n        uint256,\n        address\n    ) external returns (uint256, uint256, uint256);\n\n    function withdraw(\n        uint256,\n        uint256,\n        uint256,\n        address\n    ) external returns (uint256, uint256);\n\n    function getTotalAmounts() external view returns (uint256, uint256);\n\n    function getBalance0() external view returns (uint256);\n\n    function getBalance1() external view returns (uint256);\n\n    function rebalance() external;\n\n    function checkCanRebalance() external view;\n\n    // manager functions\n    function sweep(address token, uint256 amount, address to) external;\n\n    function setBaseThreshold(int24 _baseThreshold) external;\n\n    function setLimitThreshold(int24 _limitThreshold) external;\n\n    function setFullRangeWeight(uint24 _fullRangeWeight) external;\n\n    function setPeriod(uint32 _period) external;\n\n    function setMinTickMove(int24 _minTickMove) external;\n\n    function setMaxTwapDeviation(int24 _maxTwapDeviation) external;\n\n    function setTwapDuration(uint32 _twapDuration) external;\n\n    function setMaxTotalSupply(uint256 _maxTotalSupply) external;\n\n    function emergencyBurn(int24 tickLower, int24 tickUpper, uint128 liquidity) external;\n\n    function setManager(address _manager) external;\n\n    function setRebalanceDelegate(address _rebalanceDelegate) external;\n\n    function setManagerFee(uint24 _pendingManagerFee) external;\n\n    function acceptManager() external;\n\n    // state variables\n    function token0() external view returns (address);\n\n    function token1() external view returns (address);\n\n    function getTwap() external view returns (int24);\n\n    function fullLower() external view returns (int24);\n\n    function fullUpper() external view returns (int24);\n\n    function baseLower() external view returns (int24);\n\n    function baseUpper() external view returns (int24);\n\n    function limitLower() external view returns (int24);\n\n    function limitUpper() external view returns (int24);\n\n    function pool() external view returns (IUniswapV3Pool);\n\n    function protocolFee() external view returns (uint24);\n\n    function managerFee() external view returns (uint24);\n\n    function manager() external view returns (address);\n\n    function pendingManager() external view returns (address);\n\n    function rebalanceDelegate() external view returns (address);\n\n    function maxTotalSupply() external view returns (uint256);\n\n    function fullRangeWeight() external view returns (uint24);\n\n    function period() external view returns (uint32);\n\n    function minTickMove() external view returns (int24);\n\n    function maxTwapDeviation() external view returns (int24);\n\n    function twapDuration() external view returns (uint32);\n\n    function tickSpacing() external view returns (int24);\n\n    function accruedProtocolFees0() external view returns (uint256);\n\n    function accruedProtocolFees1() external view returns (uint256);\n\n    function accruedManagerFees0() external view returns (uint256);\n\n    function accruedManagerFees1() external view returns (uint256);\n\n    function lastTimestamp() external view returns (uint256);\n\n    function lastTick() external view returns (int24);\n\n    function baseThreshold() external view returns (int24);\n\n    function limitThreshold() external view returns (int24);\n\n    function pendingManagerFee() external view returns (uint24);\n}\n"
      },
      "contracts/_interfaces/external/IAmpleforthOracle.sol": {
        "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// solhint-disable-next-line compiler-version\ninterface IAmpleforthOracle {\n    // solhint-disable-next-line func-name-mixedcase\n    function DECIMALS() external returns (uint8);\n    function getData() external returns (uint256, bool);\n}\n"
      },
      "contracts/_interfaces/external/IChainlinkOracle.sol": {
        "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// solhint-disable-next-line compiler-version\ninterface IChainlinkOracle {\n    function decimals() external view returns (uint8);\n\n    function latestRoundData()\n        external\n        view\n        returns (\n            uint80 roundId,\n            int256 answer,\n            uint256 startedAt,\n            uint256 updatedAt,\n            uint80 answeredInRound\n        );\n}\n"
      },
      "contracts/_interfaces/external/IWAMPL.sol": {
        "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// solhint-disable-next-line compiler-version\npragma solidity ^0.7.6;\n\ninterface IWAMPL {\n    function wrapperToUnderlying(uint256 wamples) external view returns (uint256);\n}\n"
      },
      "contracts/WethWamplManager.sol": {
        "content": "// SPDX-License-Identifier: BUSL-1.1\n// solhint-disable-next-line compiler-version\npragma solidity ^0.7.6;\npragma abicoder v2;\n\nimport { FullMath } from \"@uniswap/v3-core/contracts/libraries/FullMath.sol\";\nimport { TickMath } from \"@uniswap/v3-core/contracts/libraries/TickMath.sol\";\nimport { PositionKey } from \"@uniswap/v3-periphery/contracts/libraries/PositionKey.sol\";\nimport { SafeCast } from \"@uniswap/v3-core/contracts/libraries/SafeCast.sol\";\n\nimport { IAlphaProVault } from \"./_interfaces/external/IAlphaProVault.sol\";\nimport { IChainlinkOracle } from \"./_interfaces/external/IChainlinkOracle.sol\";\nimport { IAmpleforthOracle } from \"./_interfaces/external/IAmpleforthOracle.sol\";\nimport { IWAMPL } from \"./_interfaces/external/IWAMPL.sol\";\nimport { IUniswapV3Pool } from \"@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol\";\n\n/// @title WethWamplManager\n/// @notice This contract is a programmatic manager for the WETH-WAMPL Charm AlphaProVault.\ncontract WethWamplManager {\n    /// @dev Constants for AMPL and WAMPL units and supply limits.\n    uint256 public constant ONE_AMPL = 1e9;\n    uint256 public constant ONE_WAMPL = 1e18;\n\n    /// @dev Decimals.\n    uint256 public constant DECIMALS = 18;\n    uint256 public constant ONE = (10 ** DECIMALS);\n\n    /// @dev At all times active liquidity percentage is no lower than 5%.\n    uint256 public constant MIN_ACTIVE_LIQ_PERC = ONE / 20; // 5%\n\n    /// @dev We bound the deviation factor to 100.0.\n    uint256 public constant MAX_DEVIATION = 100 * ONE; // 100.0\n\n    /// @dev Oracle constants.\n    uint256 public constant CL_ORACLE_STALENESS_THRESHOLD_SEC = 3600 * 24; // 1 day\n\n    //-------------------------------------------------------------------------\n    // Storage\n\n    /// @notice The WETH-WAMPL charm alpha vault.\n    IAlphaProVault public immutable VAULT;\n\n    /// @notice The underlying WETH-WAMPL univ3 pool.\n    IUniswapV3Pool public immutable POOL;\n\n    /// @notice The vault's token0, the WETH token.\n    address public immutable WETH;\n\n    /// @notice The vault's token1, the WAMPL token.\n    IWAMPL public immutable WAMPL;\n\n    /// @notice The cpi oracle which returns AMPL's price target in USD.\n    IAmpleforthOracle public cpiOracle;\n\n    /// @notice The chainlink oracle which returns ETH's current USD price.\n    IChainlinkOracle public ethOracle;\n\n    /// @notice The contract owner.\n    address public owner;\n\n    //-------------------------------------------------------------------------\n    // Active percentage calculation parameters\n    //\n    // The deviation factor (or deviation) is defined as the ratio between\n    // AMPL's current market price and its target price.\n    // The deviation is 1.0, when AMPL is at the target.\n    //\n    // The active liquidity percentage (a value between 5% to 100%)\n    // is computed based on pair-wise linear function, defined by the contract owner.\n    //\n    // If the current deviation is below the deviation cutoff, function f1 is used\n    // else function f2 is used. Both f1 and f2 are defined by the owner.\n    // They are lines, with 2 {x,y} coordinates. The x coordinates are deviation factors,\n    // and y coordinates are active liquidity percentages.\n    //\n    // Both deviation and active liquidity percentage and represented internally\n    // as a fixed-point number with {DECIMALS} places.\n    //\n    /// @notice The deviation cutoff which determines if either f1 or f2 is used\n    ///         to compute the active liquidity percentage.\n    uint256 public deviationCutoff;\n\n    /// @notice A data structure to define a geometric Line with two points.\n    struct Line {\n        // x-coordinate of the first point.\n        uint256 x1;\n        // y-coordinate of the first point.\n        uint256 y1;\n        // x-coordinate of the second point.\n        uint256 x2;\n        // y-coordinate of the second point.\n        uint256 y2;\n    }\n\n    /// @notice Active percentage calculation function for when deviation is below the cutoff.\n    Line public activeLiqPercFn1;\n\n    /// @notice Active percentage calculation function for when deviation is above the cutoff.\n    Line public activeLiqPercFn2;\n\n    /// @notice The recorded active liquidity percentage at the time of the last successful rebalance operation.\n    uint256 public lastActiveLiqPerc;\n\n    /// @notice The delta between the current and last recorded active liquidity percentage values\n    ///         outside which a rebalance is executed forcefully.\n    uint256 public tolerableActiveLiqPercDelta;\n\n    //-------------------------------------------------------------------------\n    // Limit range parameters\n    //\n    // Based on the deviation, the manager selectively updates the vault's limit threshold values.\n    //\n    // If the deviation is above the cutoff and the vault is WAMPL heavy,\n    // Or if the deviation is below the cutoff and the vault is WETH heavy,\n    // vault chooses a narrow limit range.\n    // Otherwise, the vault uses a wide limit range.\n    //\n    // This strategy attempts to reduce IL using knowledge about the behavior of AMPL.\n    // Put simply, The vault tries NOT to sell AMPL below the cutoff or buy AMPL above the cutoff.\n\n    /// @notice The narrow limit range, in univ3 ticks.\n    int24 public limitThresholdNarrow;\n\n    /// @notice The default wide limit range, in univ3 ticks.\n    int24 public limitThresholdWide;\n\n    //--------------------------------------------------------------------------\n    // Modifiers\n\n    modifier onlyOwner() {\n        // solhint-disable-next-line custom-errors\n        require(msg.sender == owner, \"Unauthorized caller\");\n        _;\n    }\n\n    //-----------------------------------------------------------------------------\n    // Constructor and Initializer\n\n    /// @notice Constructor initializes the contract with provided addresses.\n    /// @param vault_ Address of the AlphaProVault contract.\n    /// @param cpiOracle_ Address of the Ampleforth CPI oracle contract.\n    /// @param ethOracle_ Address of the Chainlink ETH price oracle contract.\n    constructor(\n        IAlphaProVault vault_,\n        IAmpleforthOracle cpiOracle_,\n        IChainlinkOracle ethOracle_\n    ) {\n        owner = msg.sender;\n\n        VAULT = vault_;\n        POOL = vault_.pool();\n        WETH = vault_.token0();\n        WAMPL = IWAMPL(vault_.token1());\n\n        cpiOracle = cpiOracle_;\n        ethOracle = ethOracle_;\n\n        deviationCutoff = (ONE * 105) / 100; // 1.05\n        activeLiqPercFn1 = Line({\n            x1: (ONE * 3) / 4, // 0.75\n            y1: ONE / 10, // 10%\n            x2: (ONE * 105) / 100, // 1.05\n            y2: ONE // 100%\n        });\n        activeLiqPercFn2 = Line({\n            x1: (ONE * 120) / 100, // 1.2\n            y1: ONE, // 100%\n            x2: ONE * 2, // 2.0\n            y2: ONE / 4 // 25%\n        });\n        lastActiveLiqPerc = ONE; // 100%\n        tolerableActiveLiqPercDelta = ONE / 10; // 10%\n\n        limitThresholdNarrow = 3200; // [-27.4%, 37.7%]\n        limitThresholdWide = 887200; // ~Inf\n    }\n\n    //--------------------------------------------------------------------------\n    // Owner only methods\n\n    /// @notice Updates the owner role.\n    function transferOwnership(address owner_) external onlyOwner {\n        owner = owner_;\n    }\n\n    /// @notice Updates the ampleforth cpi oracle.\n    function setCpiOracle(IAmpleforthOracle cpiOracle_) external onlyOwner {\n        cpiOracle = cpiOracle_;\n    }\n\n    /// @notice Updates the chainlink eth usd price oracle.\n    function setEthOracle(IChainlinkOracle ethOracle_) external onlyOwner {\n        ethOracle = ethOracle_;\n    }\n\n    /// @notice Updates the active liquidity percentage calculation parameters.\n    function setActivePercParams(\n        uint256 deviationCutoff_,\n        uint256 tolerableActiveLiqPercDelta_,\n        Line memory activeLiqPercFn1_,\n        Line memory activeLiqPercFn2_\n    ) external onlyOwner {\n        deviationCutoff = deviationCutoff_;\n        tolerableActiveLiqPercDelta = tolerableActiveLiqPercDelta_;\n        activeLiqPercFn1 = activeLiqPercFn1_;\n        activeLiqPercFn2 = activeLiqPercFn2_;\n    }\n\n    /// @notice Updates the vault's liquidity range parameters.\n    function setLiquidityRanges(\n        int24 baseThreshold,\n        uint24 fullRangeWeight,\n        int24 limitThresholdNarrow_,\n        int24 limitThresholdWide_\n    ) external onlyOwner {\n        // Update the base and full range parameters on the vault\n        VAULT.setBaseThreshold(baseThreshold);\n        VAULT.setFullRangeWeight(fullRangeWeight);\n\n        // Update the limit range parameters on the manager\n        limitThresholdNarrow = limitThresholdNarrow_;\n        limitThresholdWide = limitThresholdWide_;\n        VAULT.setLimitThreshold(limitThresholdWide_);\n    }\n\n    /// @notice Forwards the given calldata to the vault.\n    /// @param callData The calldata to pass to the vault.\n    /// @return The data returned by the vault method call.\n    function execOnVault(\n        bytes calldata callData\n    ) external onlyOwner returns (bytes memory) {\n        // solhint-disable-next-line avoid-low-level-calls\n        (bool success, bytes memory r) = address(VAULT).call(callData);\n        // solhint-disable-next-line custom-errors\n        require(success, \"Vault call failed\");\n        return r;\n    }\n\n    //--------------------------------------------------------------------------\n    // External write methods\n\n    /// @notice Executes vault rebalance.\n    function rebalance() public {\n        uint256 deviation = computeDeviationFactor();\n        uint256 activeLiqPerc = computeActiveLiqPerc(deviation);\n\n        // Update limit range.\n        inNarrowLimitRange(deviation)\n            ? VAULT.setLimitThreshold(limitThresholdNarrow)\n            : VAULT.setLimitThreshold(limitThresholdWide);\n\n        // Execute rebalance.\n        // NOTE: the vault.rebalance() will revert if enough time has not elapsed.\n        // We thus override with a force rebalance.\n        // https://learn.charm.fi/charm/technical-references/core/alphaprovault#rebalance\n        uint256 activeLiqPercDelta = activeLiqPerc > lastActiveLiqPerc\n            ? (activeLiqPerc - lastActiveLiqPerc)\n            : (lastActiveLiqPerc - activeLiqPerc);\n        activeLiqPercDelta > tolerableActiveLiqPercDelta\n            ? _execForceRebalance()\n            : VAULT.rebalance();\n\n        // Trim position after rebalance.\n        _trimLiquidity(activeLiqPerc);\n\n        // Update the active liquidity percentage\n        lastActiveLiqPerc = activeLiqPerc;\n    }\n\n    /// @notice Computes the deviation between AMPL's market price and target.\n    /// @return The computed deviation factor.\n    function computeDeviationFactor() public returns (uint256) {\n        (uint256 ethUSDPrice, bool ethPriceValid) = getEthUSDPrice();\n        uint256 marketPrice = getAmplUSDPrice(ethUSDPrice);\n        (uint256 targetPrice, bool targetPriceValid) = _getAmpleforthOracleData(\n            cpiOracle\n        );\n        uint256 deviation = (ethPriceValid && targetPriceValid)\n            ? FullMath.mulDiv(marketPrice, ONE, targetPrice)\n            : 0;\n        return (deviation > MAX_DEVIATION) ? MAX_DEVIATION : deviation;\n    }\n\n    //-----------------------------------------------------------------------------\n    // External Public view methods\n\n    /// @notice Computes active liquidity percentage based on the provided deviation factor.\n    /// @return The computed active liquidity percentage.\n    function computeActiveLiqPerc(uint256 deviation) public view returns (uint256) {\n        return\n            (deviation <= deviationCutoff)\n                ? _computeActiveLiqPerc(activeLiqPercFn1, deviation)\n                : _computeActiveLiqPerc(activeLiqPercFn2, deviation);\n    }\n\n    /// @notice Checks if the vault is in the narrow limit range based on the current deviation factor.\n    function inNarrowLimitRange(uint256 deviation) public view returns (bool) {\n        int24 _marketPrice = VAULT.getTwap();\n        int24 _limitLower = VAULT.limitLower();\n        int24 _limitUpper = VAULT.limitUpper();\n        int24 _limitPrice = (_limitLower + _limitUpper) / 2;\n        // The limit range has more WAMPL than WETH if `_marketPrice >= _limitPrice`,\n        // so the vault looks to sell WAMPL.\n        // NOTE: This assumes that in the underlying univ3 pool\n        // token0 is WETH and token1 is WAMPL.\n        bool isWamplAsk = (_marketPrice >= _limitPrice);\n        return ((deviation >= deviationCutoff && isWamplAsk) ||\n            (deviation <= deviationCutoff && !isWamplAsk));\n    }\n\n    /// @notice Computes the AMPL price in USD.\n    /// @param ethUSDPrice The ETH price in USD.\n    /// @return The computed AMPL price in USD.\n    function getAmplUSDPrice(uint256 ethUSDPrice) public view returns (uint256) {\n        return\n            FullMath.mulDiv(\n                getWamplUSDPrice(ethUSDPrice),\n                ONE_AMPL,\n                WAMPL.wrapperToUnderlying(ONE_WAMPL) // #AMPL per WAMPL\n            );\n    }\n\n    /// @notice Computes the WAMPL price in USD based on ETH price.\n    /// @param ethUSDPrice The ETH price in USD.\n    /// @return The computed WAMPL price in USD.\n    function getWamplUSDPrice(uint256 ethUSDPrice) public view returns (uint256) {\n        // We first get the WETH-WAMPL price from the pool and then convert that\n        // to a USD price using the given ETH-USD price.\n        uint160 sqrtPriceX96 = TickMath.getSqrtRatioAtTick(VAULT.getTwap());\n        uint256 ratioX192 = uint256(sqrtPriceX96) * sqrtPriceX96;\n        // NOTE: Since both weth and wampl have 18 decimals,\n        // we don't adjust the `wamplPerWeth`.\n        uint256 wamplPerWeth = FullMath.mulDiv(ONE, ratioX192, (1 << 192));\n        return FullMath.mulDiv(ethUSDPrice, ONE, wamplPerWeth);\n    }\n\n    /// @notice Fetches the current ETH price in USD from the Chainlink oracle.\n    /// @return The ETH price in USD and its validity.\n    function getEthUSDPrice() public view returns (uint256, bool) {\n        return _getCLOracleData(ethOracle);\n    }\n\n    /// @return Number of decimals representing 1.0.\n    function decimals() external pure returns (uint8) {\n        return uint8(DECIMALS);\n    }\n\n    //-----------------------------------------------------------------------------\n    // Private methods\n\n    /// @dev Trims the vault's current liquidity based on the active liquidity percentage.\n    ///      To be invoked right after a rebalance operation, as it assumes that all of the vault's\n    ///      liquidity has been deployed before trimming.\n    function _trimLiquidity(uint256 activePerc) private {\n        int24 _fullLower = VAULT.fullLower();\n        int24 _fullUpper = VAULT.fullUpper();\n\n        int24 _baseLower = VAULT.baseLower();\n        int24 _baseUpper = VAULT.baseUpper();\n\n        (uint128 fullLiquidity, , , , ) = _position(_fullLower, _fullUpper);\n        (uint128 baseLiquidity, , , , ) = _position(_baseLower, _baseUpper);\n\n        // Calculated baseLiquidityToBurn, baseLiquidityToBurn will be lesser than fullLiquidity, baseLiquidity\n        // Thus, there's no risk of overflow.\n        uint128 fullLiquidityToBurn = uint128(\n            FullMath.mulDiv(uint256(fullLiquidity), ONE - activePerc, ONE)\n        );\n        uint128 baseLiquidityToBurn = uint128(\n            FullMath.mulDiv(uint256(baseLiquidity), ONE - activePerc, ONE)\n        );\n\n        // docs: https://learn.charm.fi/charm/technical-references/core/alphaprovault#emergencyburn\n        VAULT.emergencyBurn(_fullLower, _fullUpper, fullLiquidityToBurn);\n        VAULT.emergencyBurn(_baseLower, _baseUpper, baseLiquidityToBurn);\n        // NOTE: Limit liquidity remains unchanged here.\n    }\n\n    /// @dev Fetches most recent report from the given ampleforth oracle contract.\n    ///      The returned report is a fixed point number with {DECIMALS} places.\n    function _getAmpleforthOracleData(\n        IAmpleforthOracle oracle\n    ) private returns (uint256, bool) {\n        (uint256 p, bool valid) = oracle.getData();\n        return (FullMath.mulDiv(p, ONE, 10 ** oracle.DECIMALS()), valid);\n    }\n\n    /// @dev A low-level method, which interacts directly with the vault and executes\n    ///      a rebalance even when enough time hasn't elapsed since the last rebalance.\n    function _execForceRebalance() private {\n        uint32 _period = VAULT.period();\n        VAULT.setPeriod(0);\n        VAULT.rebalance();\n        VAULT.setPeriod(_period);\n    }\n\n    /// @dev Wrapper around `IUniswapV3Pool.positions()`.\n    function _position(\n        int24 tickLower,\n        int24 tickUpper\n    ) private view returns (uint128, uint256, uint256, uint128, uint128) {\n        bytes32 positionKey = PositionKey.compute(address(VAULT), tickLower, tickUpper);\n        return POOL.positions(positionKey);\n    }\n\n    /// @dev Fetches most recent report from the given chain link oracle contract.\n    ///      The data is considered invalid if the latest report is stale.\n    ///      The returned report is a fixed point number with {DECIMALS} places.\n    function _getCLOracleData(\n        IChainlinkOracle oracle\n    ) private view returns (uint256, bool) {\n        (, int256 p, , uint256 updatedAt, ) = oracle.latestRoundData();\n        uint256 price = FullMath.mulDiv(uint256(p), ONE, 10 ** oracle.decimals());\n        return (\n            price,\n            (block.timestamp - updatedAt) <= CL_ORACLE_STALENESS_THRESHOLD_SEC\n        );\n    }\n\n    /// @dev We compute activeLiqPerc value given a linear fn and deviation.\n    function _computeActiveLiqPerc(\n        Line memory fn,\n        uint256 deviation\n    ) private pure returns (uint256) {\n        deviation = (deviation > MAX_DEVIATION) ? MAX_DEVIATION : deviation;\n        int256 dlY = SafeCast.toInt256(fn.y2) - SafeCast.toInt256(fn.y1);\n        int256 dlX = SafeCast.toInt256(fn.x2) - SafeCast.toInt256(fn.x1);\n        int256 activeLiqPerc = SafeCast.toInt256(fn.y2) +\n            (((SafeCast.toInt256(deviation) - SafeCast.toInt256(fn.x2)) * dlY) / dlX);\n        activeLiqPerc = (activeLiqPerc < int256(MIN_ACTIVE_LIQ_PERC))\n            ? int256(MIN_ACTIVE_LIQ_PERC)\n            : activeLiqPerc;\n        activeLiqPerc = (activeLiqPerc > int256(ONE)) ? int256(ONE) : activeLiqPerc;\n        // Casting from int256 to uint256 here is safe as activeLiqPerc >= 0.\n        return uint256(activeLiqPerc);\n    }\n}\n"
      }
    },
    "settings": {
      "optimizer": {
        "enabled": true,
        "runs": 750
      },
      "outputSelection": {
        "*": {
          "*": [
            "evm.bytecode",
            "evm.deployedBytecode",
            "devdoc",
            "userdoc",
            "metadata",
            "abi"
          ]
        }
      },
      "libraries": {}
    }
  }}