S Price: $0.736951 (+1.29%)

Contract

0x452F378DB86F6ef98731CDEB8344D8c171B6968C

Overview

S Balance

Sonic LogoSonic LogoSonic Logo0 S

S Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To

There are no matching entries

> 10 Internal Transactions found.

Latest 25 internal transactions (View All)

Parent Transaction Hash Block From To
102919262025-02-26 12:25:0624 hrs ago1740572706
0x452F378D...171B6968C
 Contract Creation0 S
102919242025-02-26 12:25:0524 hrs ago1740572705
0x452F378D...171B6968C
 Contract Creation0 S
102919242025-02-26 12:25:0524 hrs ago1740572705
0x452F378D...171B6968C
 Contract Creation0 S
102919242025-02-26 12:25:0524 hrs ago1740572705
0x452F378D...171B6968C
 Contract Creation0 S
102919222025-02-26 12:25:0424 hrs ago1740572704
0x452F378D...171B6968C
 Contract Creation0 S
102919222025-02-26 12:25:0424 hrs ago1740572704
0x452F378D...171B6968C
 Contract Creation0 S
102919112025-02-26 12:25:0024 hrs ago1740572700
0x452F378D...171B6968C
 Contract Creation0 S
102919112025-02-26 12:25:0024 hrs ago1740572700
0x452F378D...171B6968C
 Contract Creation0 S
102919112025-02-26 12:25:0024 hrs ago1740572700
0x452F378D...171B6968C
 Contract Creation0 S
102919092025-02-26 12:24:5924 hrs ago1740572699
0x452F378D...171B6968C
 Contract Creation0 S
102919092025-02-26 12:24:5924 hrs ago1740572699
0x452F378D...171B6968C
 Contract Creation0 S
102919092025-02-26 12:24:5924 hrs ago1740572699
0x452F378D...171B6968C
 Contract Creation0 S
102919062025-02-26 12:24:5824 hrs ago1740572698
0x452F378D...171B6968C
 Contract Creation0 S
102919062025-02-26 12:24:5824 hrs ago1740572698
0x452F378D...171B6968C
 Contract Creation0 S
102919062025-02-26 12:24:5824 hrs ago1740572698
0x452F378D...171B6968C
 Contract Creation0 S
102919062025-02-26 12:24:5824 hrs ago1740572698
0x452F378D...171B6968C
 Contract Creation0 S
102919062025-02-26 12:24:5824 hrs ago1740572698
0x452F378D...171B6968C
 Contract Creation0 S
102919062025-02-26 12:24:5824 hrs ago1740572698
0x452F378D...171B6968C
 Contract Creation0 S
102919042025-02-26 12:24:5724 hrs ago1740572697
0x452F378D...171B6968C
 Contract Creation0 S
102919042025-02-26 12:24:5724 hrs ago1740572697
0x452F378D...171B6968C
 Contract Creation0 S
102919042025-02-26 12:24:5724 hrs ago1740572697
0x452F378D...171B6968C
 Contract Creation0 S
102919042025-02-26 12:24:5724 hrs ago1740572697
0x452F378D...171B6968C
 Contract Creation0 S
102919042025-02-26 12:24:5724 hrs ago1740572697
0x452F378D...171B6968C
 Contract Creation0 S
102919042025-02-26 12:24:5724 hrs ago1740572697
0x452F378D...171B6968C
 Contract Creation0 S
102919042025-02-26 12:24:5724 hrs ago1740572697
0x452F378D...171B6968C
 Contract Creation0 S
View All Internal Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
ClGaugeFactory

Compiler Version
v0.8.28+commit.7893614a

Optimization Enabled:
Yes with 333 runs

Other Settings:
cancun EvmVersion
File 1 of 54 : ClGaugeFactory.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;

import {BeaconProxy} from "@openzeppelin/contracts/proxy/beacon/BeaconProxy.sol";

import {Errors} from "contracts/libraries/Errors.sol";

import {IVoter} from "contracts/interfaces/IVoter.sol";
import {IClGaugeFactory} from "contracts/CL/gauge/interfaces/IClGaugeFactory.sol";
import {GaugeV3} from "contracts/CL/gauge/GaugeV3.sol";

/// @title Canonical CL gauge factory
/// @notice Deploys CL gauges
contract ClGaugeFactory is IClGaugeFactory {
    /// @inheritdoc IClGaugeFactory
    address public voter;

    /// @inheritdoc IClGaugeFactory
    address public feeCollector;

    /// @inheritdoc IClGaugeFactory
    address public nfpManager;

    address public implementation;

    /// @inheritdoc IClGaugeFactory
    mapping(address => address) public override getGauge;

    constructor(address _nfpManager, address _voter, address _feeCollector) {
        nfpManager = _nfpManager;
        voter = _voter;
        feeCollector = _feeCollector;
    }

    /// @inheritdoc IClGaugeFactory
    function createGauge(address pool) external override returns (address gauge) {
        require(msg.sender == voter, Errors.NOT_AUTHORIZED(msg.sender));
        require(getGauge[pool] == address(0), Errors.GAUGE_EXISTS(pool));

        if (implementation == address(0)) {
            require(IVoter(voter).shadow() != address(0), Errors.NOT_INIT());
            implementation = address(new GaugeV3(voter, feeCollector));
            emit Upgraded(implementation);
        }

        gauge = address(
            new BeaconProxy(address(this), abi.encodeWithSelector(GaugeV3.initialize.selector, nfpManager, pool))
        );

        getGauge[pool] = gauge;
        emit GaugeCreated(pool, gauge);
    }

    function setNfpManager(address _nfpManager) external {
        /// @dev authorize voter instead of accessHub since this is handled as part of voter.setNfpManager
        require(msg.sender == voter, Errors.NOT_AUTHORIZED(msg.sender));

        emit NfpManagerChanged(_nfpManager, nfpManager);

        nfpManager = _nfpManager;
    }

    function setVoter(address _voter) external {
        require(msg.sender == IVoter(voter).accessHub(), Errors.NOT_AUTHORIZED(msg.sender));

        emit VoterChanged(_voter, voter);

        voter = _voter;
    }

    function setFeeCollector(address _feeCollector) external {
        require(msg.sender == IVoter(voter).accessHub(), Errors.NOT_AUTHORIZED(msg.sender));

        emit FeeCollectorChanged(_feeCollector, feeCollector);

        feeCollector = _feeCollector;
    }

    function setImplementation(address _newImplementation) external {
        require(msg.sender == IVoter(voter).accessHub(), Errors.NOT_AUTHORIZED(msg.sender));
        if (_newImplementation != implementation) {
            implementation = _newImplementation;
            emit Upgraded(_newImplementation);
        }
    }
}

File 2 of 54 : BeaconProxy.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (proxy/beacon/BeaconProxy.sol)

pragma solidity ^0.8.20;

import {IBeacon} from "./IBeacon.sol";
import {Proxy} from "../Proxy.sol";
import {ERC1967Utils} from "../ERC1967/ERC1967Utils.sol";

/**
 * @dev This contract implements a proxy that gets the implementation address for each call from an {UpgradeableBeacon}.
 *
 * The beacon address can only be set once during construction, and cannot be changed afterwards. It is stored in an
 * immutable variable to avoid unnecessary storage reads, and also in the beacon storage slot specified by
 * https://eips.ethereum.org/EIPS/eip-1967[ERC-1967] so that it can be accessed externally.
 *
 * CAUTION: Since the beacon address can never be changed, you must ensure that you either control the beacon, or trust
 * the beacon to not upgrade the implementation maliciously.
 *
 * IMPORTANT: Do not use the implementation logic to modify the beacon storage slot. Doing so would leave the proxy in
 * an inconsistent state where the beacon storage slot does not match the beacon address.
 */
contract BeaconProxy is Proxy {
    // An immutable address for the beacon to avoid unnecessary SLOADs before each delegate call.
    address private immutable _beacon;

    /**
     * @dev Initializes the proxy with `beacon`.
     *
     * If `data` is nonempty, it's used as data in a delegate call to the implementation returned by the beacon. This
     * will typically be an encoded function call, and allows initializing the storage of the proxy like a Solidity
     * constructor.
     *
     * Requirements:
     *
     * - `beacon` must be a contract with the interface {IBeacon}.
     * - If `data` is empty, `msg.value` must be zero.
     */
    constructor(address beacon, bytes memory data) payable {
        ERC1967Utils.upgradeBeaconToAndCall(beacon, data);
        _beacon = beacon;
    }

    /**
     * @dev Returns the current implementation address of the associated beacon.
     */
    function _implementation() internal view virtual override returns (address) {
        return IBeacon(_getBeacon()).implementation();
    }

    /**
     * @dev Returns the beacon.
     */
    function _getBeacon() internal view virtual returns (address) {
        return _beacon;
    }
}

File 3 of 54 : Errors.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

/// @title Central Errors Library
/// @notice Contains all custom errors used across the protocol
/// @dev Centralized error definitions to prevent redundancy
library Errors {
    /*//////////////////////////////////////////////////////////////
                                VOTER ERRORS
    //////////////////////////////////////////////////////////////*/

    /// @notice Thrown when attempting to interact with an already active gauge
    /// @param gauge The address of the gauge
    error ACTIVE_GAUGE(address gauge);

    /// @notice Thrown when attempting to interact with an inactive gauge
    /// @param gauge The address of the gauge
    error GAUGE_INACTIVE(address gauge);

    /// @notice Thrown when attempting to whitelist an already whitelisted token
    /// @param token The address of the token
    error ALREADY_WHITELISTED(address token);

    /// @notice Thrown when caller is not authorized to perform an action
    /// @param caller The address of the unauthorized caller
    error NOT_AUTHORIZED(address caller);

    /// @notice Thrown when token is not whitelisted
    /// @param token The address of the non-whitelisted token
    error NOT_WHITELISTED(address token);

    /// @notice Thrown when both tokens in a pair are not whitelisted
    error BOTH_NOT_WHITELISTED();

    /// @notice Thrown when address is not a valid pool
    /// @param pool The invalid pool address
    error NOT_POOL(address pool);

    /// @notice Thrown when pool is not seeded in PoolUpdater
    /// @param pool The invalid pool address
    error NOT_SEEDED(address pool);

    /// @notice Thrown when contract is not initialized
    error NOT_INIT();

    /// @notice Thrown when array lengths don't match
    error LENGTH_MISMATCH();

    /// @notice Thrown when pool doesn't have an associated gauge
    /// @param pool The address of the pool
    error NO_GAUGE(address pool);

    /// @notice Thrown when rewards are already distributed for a period
    /// @param gauge The gauge address
    /// @param period The distribution period
    error ALREADY_DISTRIBUTED(address gauge, uint256 period);

    /// @notice Thrown when attempting to vote with zero amount
    /// @param pool The pool address
    error ZERO_VOTE(address pool);

    /// @notice Thrown when ratio exceeds maximum allowed
    /// @param _xRatio The excessive ratio value
    error RATIO_TOO_HIGH(uint256 _xRatio);

    /// @notice Thrown when vote operation fails
    error VOTE_UNSUCCESSFUL();

    /*//////////////////////////////////////////////////////////////
                            GAUGE V3 ERRORS
    //////////////////////////////////////////////////////////////*/

    /// @notice Thrown when the pool already has a gauge
    /// @param pool The address of the pool
    error GAUGE_EXISTS(address pool);

    /// @notice Thrown when caller is not the voter
    /// @param caller The address of the invalid caller
    error NOT_VOTER(address caller);

    /// @notice Thrown when amount is not greater than zero
    /// @param amt The invalid amount
    error NOT_GT_ZERO(uint256 amt);

    /// @notice Thrown when attempting to claim future rewards
    error CANT_CLAIM_FUTURE();

    /// @notice Throw when gauge can't determine if using secondsInRange from the pool is safe
    error NEED_TEAM_TO_UPDATE();

    /*//////////////////////////////////////////////////////////////
                            GAUGE ERRORS
    //////////////////////////////////////////////////////////////*/

    /// @notice Thrown when amount is zero
    error ZERO_AMOUNT();

    /// @notice Thrown when stake notification fails
    error CANT_NOTIFY_STAKE();

    /// @notice Thrown when reward amount is too high
    error REWARD_TOO_HIGH();

    /// @notice Thrown when amount exceeds remaining balance
    /// @param amount The requested amount
    /// @param remaining The remaining balance
    error NOT_GREATER_THAN_REMAINING(uint256 amount, uint256 remaining);

    /// @notice Thrown when token operation fails
    /// @param token The address of the problematic token
    error TOKEN_ERROR(address token);

    /// @notice Thrown when an address is not an NfpManager
    error NOT_NFP_MANAGER(address nfpManager);

    /*//////////////////////////////////////////////////////////////
                        FEE DISTRIBUTOR ERRORS
    //////////////////////////////////////////////////////////////*/

    /// @notice Thrown when period is not finalized
    /// @param period The unfinalized period
    error NOT_FINALIZED(uint256 period);

    /// @notice Thrown when the destination of a redirect is not a feeDistributor
    /// @param destination Destination of the redirect
    error NOT_FEE_DISTRIBUTOR(address destination);

    /// @notice Thrown when the destination of a redirect's pool/pair has completely different tokens
    error DIFFERENT_DESTINATION_TOKENS();

    /*//////////////////////////////////////////////////////////////
                            PAIR ERRORS
    //////////////////////////////////////////////////////////////*/

    /// @notice Thrown when ratio is unstable
    error UNSTABLE_RATIO();

    /// @notice Thrown when safe transfer fails
    error SAFE_TRANSFER_FAILED();

    /// @notice Thrown on arithmetic overflow
    error OVERFLOW();

    /// @notice Thrown when skim operation is disabled
    error SKIM_DISABLED();

    /// @notice Thrown when insufficient liquidity is minted
    error INSUFFICIENT_LIQUIDITY_MINTED();

    /// @notice Thrown when insufficient liquidity is burned
    error INSUFFICIENT_LIQUIDITY_BURNED();

    /// @notice Thrown when output amount is insufficient
    error INSUFFICIENT_OUTPUT_AMOUNT();

    /// @notice Thrown when input amount is insufficient
    error INSUFFICIENT_INPUT_AMOUNT();

    /// @notice Generic insufficient liquidity error
    error INSUFFICIENT_LIQUIDITY();

    /// @notice Invalid transfer error
    error INVALID_TRANSFER();

    /// @notice K value error in AMM
    error K();

    /*//////////////////////////////////////////////////////////////
                        PAIR FACTORY ERRORS
    //////////////////////////////////////////////////////////////*/

    /// @notice Thrown when fee is too high
    error FEE_TOO_HIGH();

    /// @notice Thrown when fee is zero
    error ZERO_FEE();

    /// @notice Thrown when token assortment is invalid
    error INVALID_ASSORTMENT();

    /// @notice Thrown when address is zero
    error ZERO_ADDRESS();

    /// @notice Thrown when pair already exists
    error PAIR_EXISTS();

    /// @notice Thrown when fee split is invalid
    error INVALID_FEE_SPLIT();

    /*//////////////////////////////////////////////////////////////
                    FEE RECIPIENT FACTORY ERRORS
    //////////////////////////////////////////////////////////////*/

    /// @notice Thrown when treasury fee is invalid
    error INVALID_TREASURY_FEE();

    /*//////////////////////////////////////////////////////////////
                            ROUTER ERRORS
    //////////////////////////////////////////////////////////////*/

    /// @notice Thrown when deadline has expired
    error EXPIRED();

    /// @notice Thrown when tokens are identical
    error IDENTICAL();

    /// @notice Thrown when amount is insufficient
    error INSUFFICIENT_AMOUNT();

    /// @notice Thrown when path is invalid
    error INVALID_PATH();

    /// @notice Thrown when token B amount is insufficient
    error INSUFFICIENT_B_AMOUNT();

    /// @notice Thrown when token A amount is insufficient
    error INSUFFICIENT_A_AMOUNT();

    /// @notice Thrown when input amount is excessive
    error EXCESSIVE_INPUT_AMOUNT();

    /// @notice Thrown when ETH transfer fails
    error ETH_TRANSFER_FAILED();

    /// @notice Thrown when reserves are invalid
    error INVALID_RESERVES();

    /*//////////////////////////////////////////////////////////////
                            MINTER ERRORS
    //////////////////////////////////////////////////////////////*/

    /// @notice Thrown when epoch 0 has already started
    error STARTED();

    /// @notice Thrown when emissions haven't started
    error EMISSIONS_NOT_STARTED();

    /// @notice Thrown when deviation is too high
    error TOO_HIGH();

    /// @notice Thrown when no value change detected
    error NO_CHANGE();

    /// @notice Thrown when updating emissions in same period
    error SAME_PERIOD();

    /// @notice Thrown when contract setup is invalid
    error INVALID_CONTRACT();

    /// @notice Thrown when legacy factory doesn't have feeSplitWhenNoGauge on
    error FEE_SPLIT_WHEN_NO_GAUGE_IS_OFF();

    /*//////////////////////////////////////////////////////////////
                        ACCESS HUB ERRORS
    //////////////////////////////////////////////////////////////*/

    /// @notice Thrown when addresses are identical
    error SAME_ADDRESS();

    /// @notice Thrown when caller is not timelock
    /// @param caller The invalid caller address
    error NOT_TIMELOCK(address caller);

    /// @notice Thrown when manual execution fails
    /// @param reason The failure reason
    error MANUAL_EXECUTION_FAILURE(bytes reason);

    /// @notice Thrown when kick operation is forbidden
    /// @param target The target address
    error KICK_FORBIDDEN(address target);

    /*//////////////////////////////////////////////////////////////
                        VOTE MODULE ERRORS
    //////////////////////////////////////////////////////////////*/

    /// @notice Thrown when caller is not xShadow
    error NOT_XSHADOW();

    /// @notice Thrown when cooldown period is still active
    error COOLDOWN_ACTIVE();

    /// @notice Thrown when caller is not vote module
    error NOT_VOTEMODULE();

    /// @notice Thrown when caller is unauthorized
    error UNAUTHORIZED();

    /// @notice Thrown when caller is not access hub
    error NOT_ACCESSHUB();

    /// @notice Thrown when address is invalid
    error INVALID_ADDRESS();

    /*//////////////////////////////////////////////////////////////
                        LAUNCHER PLUGIN ERRORS
    //////////////////////////////////////////////////////////////*/

    /// @notice Thrown when caller is not authority
    error NOT_AUTHORITY();

    /// @notice Thrown when already an authority
    error ALREADY_AUTHORITY();

    /// @notice Thrown when caller is not operator
    error NOT_OPERATOR();

    /// @notice Thrown when already an operator
    error ALREADY_OPERATOR();

    /// @notice Thrown when pool is not enabled
    /// @param pool The disabled pool address
    error NOT_ENABLED(address pool);

    /// @notice Thrown when fee distributor is missing
    error NO_FEEDIST();

    /// @notice Thrown when already enabled
    error ENABLED();

    /// @notice Thrown when take value is invalid
    error INVALID_TAKE();

    /*//////////////////////////////////////////////////////////////
                            X33 ERRORS
    //////////////////////////////////////////////////////////////*/

    /// @notice Thrown when value is zero
    error ZERO();

    /// @notice Thrown when amount is insufficient
    error NOT_ENOUGH();

    /// @notice Thrown when value doesn't conform to scale
    /// @param value The non-conforming value
    error NOT_CONFORMED_TO_SCALE(uint256 value);

    /// @notice Thrown when contract is locked
    error LOCKED();

    /// @notice Thrown when rebase is in progress
    error REBASE_IN_PROGRESS();

    /// @notice Thrown when aggregator reverts
    /// @param reason The revert reason
    error AGGREGATOR_REVERTED(bytes reason);

    /// @notice Thrown when output amount is too low
    /// @param amount The insufficient amount
    error AMOUNT_OUT_TOO_LOW(uint256 amount);

    /// @notice Thrown when aggregator is not whitelisted
    /// @param aggregator The non-whitelisted aggregator address
    error AGGREGATOR_NOT_WHITELISTED(address aggregator);

    /// @notice Thrown when token is forbidden
    /// @param token The forbidden token address
    error FORBIDDEN_TOKEN(address token);

    /*//////////////////////////////////////////////////////////////
                            XSHADOW ERRORS
    //////////////////////////////////////////////////////////////*/

    /// @notice Thrown when caller is not minter
    error NOT_MINTER();

    /// @notice Thrown when no vest exists
    error NO_VEST();

    /// @notice Thrown when already exempt
    error ALREADY_EXEMPT();

    /// @notice Thrown when not exempt
    error NOT_EXEMPT();

    /// @notice Thrown when rescue operation is not allowed
    error CANT_RESCUE();

    /// @notice Thrown when array lengths mismatch
    error ARRAY_LENGTHS();

    /// @notice Thrown when vesting periods overlap
    error VEST_OVERLAP();

    /*//////////////////////////////////////////////////////////////
                            V3 FACTORY ERRORS
    //////////////////////////////////////////////////////////////*/

    /// @notice Thrown when tokens are identical
    error IDENTICAL_TOKENS();

    /// @notice Thrown when fee is too large
    error FEE_TOO_LARGE();

    /// @notice Address zero error
    error ADDRESS_ZERO();

    /// @notice Fee zero error
    error F0();

    /// @notice Thrown when value is out of bounds
    /// @param value The out of bounds value
    error OOB(uint8 value);

    /*//////////////////////////////////////////////////////////////
                            POOL UPDATER ERRORS
    //////////////////////////////////////////////////////////////*/
    /// @notice Thrown when seeding for a pool fails
    error TRANSFER_FROM_FOR_SEEDING_FAILED(address token, uint256 amount);

    /// @notice Thrown when seeding for a pool fails
    error SEEDING_FAILED();

    /// @notice Thrown when updatePools is called too early
    error TOO_EARLY();

    /// @notice Thrown when a callback is called when an update isn't running
    error NOT_RUNNING();

    /// @notice Thrown when updatePools didn't perform any updates
    error NO_UPDATES();
}

File 4 of 54 : IVoter.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;
pragma abicoder v2;

interface IVoter {
    event GaugeCreated(address indexed gauge, address creator, address feeDistributor, address indexed pool);

    event GaugeKilled(address indexed gauge);

    event GaugeRevived(address indexed gauge);

    event Voted(address indexed owner, uint256 weight, address indexed pool);

    event Abstained(address indexed owner, uint256 weight);

    event Deposit(address indexed lp, address indexed gauge, address indexed owner, uint256 amount);

    event Withdraw(address indexed lp, address indexed gauge, address indexed owner, uint256 amount);

    event NotifyReward(address indexed sender, address indexed reward, uint256 amount);

    event DistributeReward(address indexed sender, address indexed gauge, uint256 amount);

    event EmissionsRatio(address indexed caller, uint256 oldRatio, uint256 newRatio);

    event NewGovernor(address indexed sender, address indexed governor);

    event Whitelisted(address indexed whitelister, address indexed token);

    event WhitelistRevoked(address indexed forbidder, address indexed token, bool status);

    event MainTickSpacingChanged(address indexed token0, address indexed token1, int24 indexed newMainTickSpacing);

    event Poke(address indexed user);

    event EmissionsRedirected(address indexed sourceGauge, address indexed destinationGauge);

    struct InitializationParams {
        address shadow;
        address legacyFactory;
        address gauges;
        address feeDistributorFactory;
        address minter;
        address msig;
        address xShadow;
        address clFactory;
        address clGaugeFactory;
        address nfpManager;
        address feeRecipientFactory;
        address voteModule;
        address launcherPlugin;
        address poolUpdater;
    }

    function initialize(InitializationParams memory inputs) external;

    /// @notice denominator basis
    function BASIS() external view returns (uint256);

    /// @notice ratio of xShadow emissions globally
    function xRatio() external view returns (uint256);

    /// @notice xShadow contract address
    function xShadow() external view returns (address);

    /// @notice legacy factory address (uni-v2/stableswap)
    function legacyFactory() external view returns (address);

    /// @notice concentrated liquidity factory
    function clFactory() external view returns (address);

    /// @notice gauge factory for CL
    function clGaugeFactory() external view returns (address);

    /// @notice pool updater for CL
    function poolUpdater() external view returns (address);

    /// @notice legacy fee recipient factory
    function feeRecipientFactory() external view returns (address);

    /// @notice peripheral NFPManager contract
    function nfpManager() external view returns (address);

    /// @notice returns the address of the current governor
    /// @return _governor address of the governor
    function governor() external view returns (address _governor);

    /// @notice the address of the vote module
    /// @return _voteModule the vote module contract address
    function voteModule() external view returns (address _voteModule);

    /// @notice address of the central access Hub
    function accessHub() external view returns (address);

    /// @notice the address of the shadow launcher plugin to enable third party launchers
    /// @return _launcherPlugin the address of the plugin
    function launcherPlugin() external view returns (address _launcherPlugin);

    /// @notice distributes emissions from the minter to the voter
    /// @param amount the amount of tokens to notify
    function notifyRewardAmount(uint256 amount) external;

    /// @notice distributes the emissions for a specific gauge
    /// @param _gauge the gauge address
    function distribute(address _gauge) external;

    /// @notice returns the address of the gauge factory
    /// @param _gaugeFactory gauge factory address
    function gaugeFactory() external view returns (address _gaugeFactory);

    /// @notice returns the address of the feeDistributor factory
    /// @return _feeDistributorFactory feeDist factory address
    function feeDistributorFactory() external view returns (address _feeDistributorFactory);

    /// @notice returns the address of the minter contract
    /// @return _minter address of the minter
    function minter() external view returns (address _minter);

    /// @notice check if the gauge is active for governance use
    /// @param _gauge address of the gauge
    /// @return _trueOrFalse if the gauge is alive
    function isAlive(address _gauge) external view returns (bool _trueOrFalse);

    /// @notice allows the token to be paired with other whitelisted assets to participate in governance
    /// @param _token the address of the token
    function whitelist(address _token) external;

    /// @notice effectively disqualifies a token from governance
    /// @param _token the address of the token
    function revokeWhitelist(address _token) external;

    /// @notice returns if the address is a gauge
    /// @param gauge address of the gauge
    /// @return _trueOrFalse boolean if the address is a gauge
    function isGauge(address gauge) external view returns (bool _trueOrFalse);

    /// @notice disable a gauge from governance
    /// @param _gauge address of the gauge
    function killGauge(address _gauge) external;

    /// @notice re-activate a dead gauge
    /// @param _gauge address of the gauge
    function reviveGauge(address _gauge) external;

    /// @notice re-cast a tokenID's votes
    /// @param owner address of the owner
    function poke(address owner) external;

    /// @notice sets the main destinationGauge of a token pairing
    /// @param tokenA address of tokenA
    /// @param tokenB address of tokenB
    /// @param destinationGauge the main gauge to set to
    function redirectEmissions(address tokenA, address tokenB, address destinationGauge) external;

    /// @notice returns if the address is a fee distributor
    /// @param _feeDistributor address of the feeDist
    /// @return _trueOrFalse if the address is a fee distributor
    function isFeeDistributor(address _feeDistributor) external view returns (bool _trueOrFalse);

    /// @notice returns the address of the emission's token
    /// @return _shadow emissions token contract address
    function shadow() external view returns (address _shadow);

    /// @notice returns the address of the pool's gauge, if any
    /// @param _pool pool address
    /// @return _gauge gauge address
    function gaugeForPool(address _pool) external view returns (address _gauge);

    /// @notice returns the address of the pool's feeDistributor, if any
    /// @param _gauge address of the gauge
    /// @return _feeDistributor address of the pool's feedist
    function feeDistributorForGauge(address _gauge) external view returns (address _feeDistributor);

    /// @notice returns the gauge address of a CL pool
    /// @param tokenA address of token A in the pair
    /// @param tokenB address of token B in the pair
    /// @param tickSpacing tickspacing of the pool
    /// @return gauge address of the gauge
    function gaugeForClPool(address tokenA, address tokenB, int24 tickSpacing) external view returns (address gauge);

    /// @notice returns the array of all tickspacings for the tokenA/tokenB combination
    /// @param tokenA address of token A in the pair
    /// @param tokenB address of token B in the pair
    /// @return _ts array of all the tickspacings
    function tickSpacingsForPair(address tokenA, address tokenB) external view returns (int24[] memory _ts);

    /// @notice returns the destination of a gauge redirect
    /// @param gauge address of gauge
    function gaugeRedirect(address gauge) external view returns (address);

    /// @notice returns the block.timestamp divided by 1 week in seconds
    /// @return period the period used for gauges
    function getPeriod() external view returns (uint256 period);

    /// @notice cast a vote to direct emissions to gauges and earn incentives
    /// @param owner address of the owner
    /// @param _pools the list of pools to vote on
    /// @param _weights an arbitrary weight per pool which will be normalized to 100% regardless of numerical inputs
    function vote(address owner, address[] calldata _pools, uint256[] calldata _weights) external;

    /// @notice reset the vote of an address
    /// @param owner address of the owner
    function reset(address owner) external;

    /// @notice set the governor address
    /// @param _governor the new governor address
    function setGovernor(address _governor) external;

    /// @notice recover stuck emissions
    /// @param _gauge the gauge address
    /// @param _period the period
    function stuckEmissionsRecovery(address _gauge, uint256 _period) external;

    /// @notice creates a legacy gauge for the pool
    /// @param _pool pool's address
    /// @return _gauge address of the new gauge
    function createGauge(address _pool) external returns (address _gauge);

    /// @notice create a concentrated liquidity gauge
    /// @param tokenA the address of tokenA
    /// @param tokenB the address of tokenB
    /// @param tickSpacing the tickspacing of the pool
    /// @return _clGauge address of the new gauge
    function createCLGauge(address tokenA, address tokenB, int24 tickSpacing) external returns (address _clGauge);

    /// @notice claim concentrated liquidity gauge rewards for specific NFP token ids
    /// @param _gauges array of gauges
    /// @param _tokens two dimensional array for the tokens to claim
    /// @param _nfpTokenIds two dimensional array for the NFPs
    function claimClGaugeRewards(
        address[] calldata _gauges,
        address[][] calldata _tokens,
        uint256[][] calldata _nfpTokenIds
    ) external;

    /// @notice claim arbitrary rewards from specific feeDists
    /// @param owner address of the owner
    /// @param _feeDistributors address of the feeDists
    /// @param _tokens two dimensional array for the tokens to claim
    function claimIncentives(address owner, address[] calldata _feeDistributors, address[][] calldata _tokens)
        external;

    /// @notice claim arbitrary rewards from specific feeDists and break up legacy pairs
    /// @param owner address of the owner
    /// @param _feeDistributors address of the feeDists
    /// @param _tokens two dimensional array for the tokens to claim
    function claimLegacyIncentives(address owner, address[] calldata _feeDistributors, address[][] calldata _tokens)
        external;

    /// @notice claim arbitrary rewards from specific gauges
    /// @param _gauges address of the gauges
    /// @param _tokens two dimensional array for the tokens to claim
    function claimRewards(address[] calldata _gauges, address[][] calldata _tokens) external;

    /// @notice claim arbitrary rewards from specific legacy gauges, and exit to shadow
    /// @param _gauges address of the gauges
    /// @param _tokens two dimensional array for the tokens to claim
    function claimLegacyRewardsAndExit(address[] calldata _gauges, address[][] calldata _tokens) external;

    /// @notice claim arbitrary rewards from specific cl gauges, and exit to shadow
    /// @param _gauges address of the gauges
    /// @param _tokens two dimensional array for the tokens to claim
    /// @param _nfpTokenIds two dimensional array for the nfp to claim
    function claimClGaugeRewardsAndExit(
        address[] memory _gauges,
        address[][] memory _tokens,
        uint256[][] memory _nfpTokenIds
    ) external;

    /// @notice distribute emissions to a gauge for a specific period
    /// @param _gauge address of the gauge
    /// @param _period value of the period
    function distributeForPeriod(address _gauge, uint256 _period) external;

    /// @notice attempt distribution of emissions to all gauges
    function distributeAll() external;

    /// @notice distribute emissions to gauges by index
    /// @param startIndex start of the loop
    /// @param endIndex end of the loop
    function batchDistributeByIndex(uint256 startIndex, uint256 endIndex) external;

    /// @notice lets governance update lastDistro period for a gauge
    /// @dev should only be used if distribute() is running out of gas
    /// @dev gaugePeriodDistributed will stop double claiming
    /// @param _gauge gauge to update
    /// @param _period period to update to
    function updateLastDistro(address _gauge, uint256 _period) external;

    /// @notice returns the votes cast for a tokenID
    /// @param owner address of the owner
    /// @return votes an array of votes casted
    /// @return weights an array of the weights casted per pool
    function getVotes(address owner, uint256 period)
        external
        view
        returns (address[] memory votes, uint256[] memory weights);

    /// @notice returns an array of all the pools
    /// @return _pools the array of pools
    function getAllPools() external view returns (address[] memory _pools);

    /// @notice returns the length of pools
    function getPoolsLength() external view returns (uint256);

    /// @notice returns the pool at index
    function getPool(uint256 index) external view returns (address);

    /// @notice returns an array of all the gauges
    /// @return _gauges the array of gauges
    function getAllGauges() external view returns (address[] memory _gauges);

    /// @notice returns the length of gauges
    function getGaugesLength() external view returns (uint256);

    /// @notice returns the gauge at index
    function getGauge(uint256 index) external view returns (address);

    /// @notice returns an array of all the feeDists
    /// @return _feeDistributors the array of feeDists
    function getAllFeeDistributors() external view returns (address[] memory _feeDistributors);

    /// @notice sets the xShadowRatio default
    function setGlobalRatio(uint256 _xRatio) external;

    /// @notice whether the token is whitelisted in governance
    function isWhitelisted(address _token) external view returns (bool _tf);

    /// @notice function for removing malicious or stuffed tokens
    function removeFeeDistributorReward(address _feeDist, address _token) external;

    /// @notice returns the total votes for a pool in a specific period
    /// @param pool the pool address to check
    /// @param period the period to check
    /// @return votes the total votes for the pool in that period
    function poolTotalVotesPerPeriod(address pool, uint256 period) external view returns (uint256 votes);

    /// @notice returns the pool address for a given gauge
    /// @param gauge address of the gauge
    /// @return pool address of the pool
    function poolForGauge(address gauge) external view returns (address pool);

    /// @notice returns the pool address for a given feeDistributor
    /// @param feeDistributor address of the feeDistributor
    /// @return pool address of the pool
    function poolForFeeDistributor(address feeDistributor) external view returns (address pool);

    /// @notice returns the voting power used by a voter for a period
    /// @param user address of the user
    /// @param period the period to check
    function userVotingPowerPerPeriod(address user, uint256 period) external view returns (uint256 votingPower);

    /// @notice returns the total votes for a specific period
    /// @param period the period to check
    /// @return weight the total votes for that period
    function totalVotesPerPeriod(uint256 period) external view returns (uint256 weight);

    /// @notice returns the total rewards allocated for a specific period
    /// @param period the period to check
    /// @return amount the total rewards for that period
    function totalRewardPerPeriod(uint256 period) external view returns (uint256 amount);

    /// @notice returns the last distribution period for a gauge
    /// @param _gauge address of the gauge
    /// @return period the last period distributions occurred
    function lastDistro(address _gauge) external view returns (uint256 period);

    /// @notice returns if the gauge is a Cl gauge
    /// @param gauge the gauge to check
    function isClGauge(address gauge) external view returns (bool);

    /// @notice returns if the gauge is a legacy gauge
    /// @param gauge the gauge to check
    function isLegacyGauge(address gauge) external view returns (bool);

    /// @notice sets a new NFP manager
    function setNfpManager(address _nfpManager) external;
}

File 5 of 54 : IClGaugeFactory.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;

/// @title The interface for the CL gauge Factory
/// @notice Deploys CL gauges
interface IClGaugeFactory {
    /// @dev Emitted when the implementation returned by the beacon is changed.
    event Upgraded(address indexed implementation);

    /// @notice Emitted when a gauge is created
    /// @param pool The address of the pool
    /// @param pool The address of the created gauge
    event GaugeCreated(address indexed pool, address gauge);

    /// @notice Emitted when the NFP Manager is changed
    /// @param newNfpManager The address of the new NFP Manager
    /// @param oldNfpManager The address of the old NFP Manager
    event NfpManagerChanged(address indexed newNfpManager, address indexed oldNfpManager);

    /// @notice Emitted when the Fee Collector is changed
    /// @param newFeeCollector The address of the new NFP Manager
    /// @param oldFeeCollector The address of the old NFP Manager
    event FeeCollectorChanged(address indexed newFeeCollector, address indexed oldFeeCollector);

    /// @notice Emitted when the Voter is changed
    /// @param newVoter The address of the new NFP Manager
    /// @param oldVoter The address of the old NFP Manager
    event VoterChanged(address indexed newVoter, address indexed oldVoter);

    /// @notice Returns the NFP Manager address
    function nfpManager() external view returns (address);

    /// @notice Set new NFP Manager
    function setNfpManager(address _nfpManager) external;

    /// @notice Returns Voter
    function voter() external view returns (address);

    /// @notice Returns the gauge address for a given pool, or address 0 if it does not exist
    /// @param pool The pool address
    /// @return gauge The gauge address
    function getGauge(address pool) external view returns (address gauge);

    /// @notice Returns the address of the fee collector contract
    /// @dev Fee collector decides where the protocol fees go (fee distributor, treasury, etc.)
    function feeCollector() external view returns (address);

    /// @notice Creates a gauge for the given pool
    /// @param pool One of the desired gauge
    /// @return gauge The address of the newly created gauge
    function createGauge(address pool) external returns (address gauge);
}

File 6 of 54 : GaugeV3.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import {IGaugeV3} from "contracts/CL/gauge/interfaces/IGaugeV3.sol";
import {IPoolUpdater} from "contracts/CL/gauge/interfaces/IPoolUpdater.sol";
import {INonfungiblePositionManager} from "contracts/CL/periphery/interfaces/INonfungiblePositionManager.sol";
import {IFeeCollector} from "contracts/CL/gauge/interfaces/IFeeCollector.sol";
import {FullMath} from "contracts/CL/core/libraries/FullMath.sol";

import {IShadowV3Pool, IShadowV3PoolState, IShadowV3PoolErrors} from "contracts/CL/core/interfaces/IShadowV3Pool.sol";

import {GaugeV3Storage} from "contracts/CL/gauge/libraries/GaugeV3Storage.sol";
import {Observation} from "contracts/CL/core/libraries/PoolStorage.sol";
import {
    PoolStorageOld,
    PositionCheckpoint,
    TickInfo,
    PeriodInfo,
    Slot0,
    RewardInfo
} from "contracts/CL/core/libraries/PoolStorageOld.sol";
import {Oracle} from "contracts/CL/core/libraries/Oracle.sol";
import {FixedPoint32} from "contracts/CL/core/libraries/FixedPoint32.sol";
import {FixedPoint96} from "contracts/CL/core/libraries/FixedPoint96.sol";

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

import {IVoter} from "contracts/interfaces/IVoter.sol";
import {IXShadow} from "contracts/interfaces/IXShadow.sol";
import {Errors} from "contracts/libraries/Errors.sol";

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

contract GaugeV3 is IGaugeV3, Initializable {
    using SafeERC20 for IERC20;
    using EnumerableSet for EnumerableSet.AddressSet;

    uint256 internal constant PRECISION = 10 ** 18;

    address public immutable voter;
    address public immutable shadow;
    address public immutable xShadow;

    IFeeCollector public immutable feeCollector;

    /// @dev Mutually exclusive reentrancy protection into the pool to/from a method. This method also prevents entrance
    /// @dev to a function before the Gauge is initialized.
    modifier lock() {
        GaugeV3Storage.GaugeV3State storage $ = GaugeV3Storage.getStorage();

        require($._unlocked, IShadowV3PoolErrors.LOK());
        $._unlocked = false;
        _;
        $._unlocked = true;
    }

    /// @dev pushes fees from the pool to fee distributor on notify rewards
    modifier pushFees() {
        feeCollector.collectProtocolFees(address(GaugeV3Storage.getStorage().pool));
        _;
    }

    modifier pullData() {
        updatePool();
        _;
    }

    constructor(address _voter, address _feeCollector) {
        _disableInitializers();

        voter = _voter;
        feeCollector = IFeeCollector(_feeCollector);

        (address _shadow, address _xShadow) = (IVoter(_voter).shadow(), IVoter(_voter).xShadow());
        shadow = _shadow;
        xShadow = _xShadow;
    }

    function initialize(address _nfpManager, address _pool) external initializer {
        GaugeV3Storage.GaugeV3State storage $ = GaugeV3Storage.getStorage();

        $._unlocked = true;

        $.firstPeriod = block.timestamp / 1 weeks;

        $.pool = IShadowV3Pool(_pool);

        $.nfpManager = _nfpManager;
        $.nfpManagers.add(_nfpManager);
        $.rewards.add(shadow);
        $.rewards.add(xShadow);

        // increase pool oracle cardinality to ensure we have enough observation for 5 minutes after period flips
        (,,, uint16 observationCardinality,,,) = IShadowV3Pool(_pool).slot0();
        if (observationCardinality < 300) {
            IShadowV3Pool(_pool).increaseObservationCardinalityNext(300);
            observationCardinality = 300;
        }

        $.lastCardinality = observationCardinality;
        $.cachedPoolLastPeriod = _getPeriod();
    }

    /// @inheritdoc IGaugeV3
    function updatePool() public {
        GaugeV3Storage.GaugeV3State storage $ = GaugeV3Storage.getStorage();

        uint256 _lastCardinality = $.lastCardinality;

        // increase cardinality if needed
        if ($.lastCardinality < 1 hours) {
            IShadowV3Pool _pool = $.pool;

            (,,, _lastCardinality,,,) = _pool.slot0();

            _lastCardinality += 10;
            _pool.increaseObservationCardinalityNext(uint16(_lastCardinality));
            $.lastCardinality = _lastCardinality;
        }

        uint256 period = _getPeriod();
        uint256 lastPeriod = $.cachedPoolLastPeriod;
        if (lastPeriod != period) {
            IShadowV3Pool _pool = $.pool;

            if (_pool.lastPeriod() != period) {
                address _poolUpdater = IVoter(voter).poolUpdater();
                IPoolUpdater(_poolUpdater).updatePool(address(_pool));
                require(_pool.lastPeriod() == period, Errors.NO_UPDATES());
            }

            ($.usePoolData[lastPeriod], $.periodEndSecondsPerLiquidityCumulativeX128[lastPeriod]) =
                _findLastObservation(lastPeriod);
            $.periodEndVerion[lastPeriod]++;
            $.cachedPoolLastPeriod = period;
        }
    }

    function _findLastObservation(uint256 period) public view returns (bool usePoolData, uint160 endPeriodSPLX128) {
        GaugeV3Storage.GaugeV3State storage $ = GaugeV3Storage.getStorage();

        uint32 targetTimestamp = uint32((period + 1) * 1 weeks - 2); // target timestamp is 2 seconds before period flip
        uint32 currentTimestamp = uint32(block.timestamp);

        IShadowV3Pool _pool = $.pool;

        uint256 cardinality;
        uint256 observationIndex;
        (,, observationIndex, cardinality,,,) = _pool.slot0();

        Observation memory beforeOrAt;
        Observation memory atOrAfter;

        unchecked {
            /// @dev oldest observation
            uint256 l = (observationIndex + 1) % cardinality;
            /// @dev newest observation
            uint256 r = l + cardinality - 1;
            uint256 i;

            for (uint256 loop = 0; loop < 32; loop++) {
                // at most 16 loops since there can be no more than uint16 indexes
                if (loop > 16) {
                    revert Errors.NEED_TEAM_TO_UPDATE();
                }

                i = (l + r) / 2;

                (beforeOrAt.blockTimestamp,, beforeOrAt.secondsPerLiquidityCumulativeX128, beforeOrAt.initialized) =
                    _pool.observations(i % cardinality);

                /// @dev we've landed on an uninitialized tick, keep searching higher (more recently)
                if (!beforeOrAt.initialized) {
                    l = i + 1;
                    continue;
                }

                (atOrAfter.blockTimestamp,, atOrAfter.secondsPerLiquidityCumulativeX128, atOrAfter.initialized) =
                    _pool.observations((i + 1) % cardinality);

                bool targetAtOrAfter = lte(currentTimestamp, beforeOrAt.blockTimestamp, targetTimestamp);

                /// @dev check if we've found the answer!
                if (targetAtOrAfter && lte(currentTimestamp, targetTimestamp, atOrAfter.blockTimestamp)) break;

                if (!targetAtOrAfter) r = i - 1;
                else l = i + 1;
            }

            /// @dev check if there is a repeat observation
            (uint256 secondAfter,,,) = _pool.observations((i + 2) % cardinality);

            if (atOrAfter.blockTimestamp == secondAfter) {
                return (false, atOrAfter.secondsPerLiquidityCumulativeX128);
            } else {
                return (true, atOrAfter.secondsPerLiquidityCumulativeX128);
            }
        }
    }

    /// @notice comparator for 32-bit timestamps
    /// @dev safe for 0 or 1 overflows, a and b _must_ be chronologically before or equal to time
    /// @param time A timestamp truncated to 32 bits
    /// @param a A comparison timestamp from which to determine the relative position of `time`
    /// @param b From which to determine the relative position of `time`
    /// @return Whether `a` is chronologically <= `b`
    function lte(uint32 time, uint32 a, uint32 b) private pure returns (bool) {
        unchecked {
            /// @dev if there hasn't been overflow, no need to adjust
            if (a <= time && b <= time) return a <= b;

            uint256 aAdjusted = a > time ? a : a + 2 ** 32;
            uint256 bAdjusted = b > time ? b : b + 2 ** 32;

            return aAdjusted <= bAdjusted;
        }
    }

    function _getPeriod() internal view returns (uint256) {
        return block.timestamp / 1 weeks;
    }

    ////////////////////
    // View Functions //
    ////////////////////

    /// @inheritdoc IGaugeV3
    function pool() external view returns (address) {
        return address(GaugeV3Storage.getStorage().pool);
    }

    /// @inheritdoc IGaugeV3
    function firstPeriod() external view returns (uint256) {
        return GaugeV3Storage.getStorage().firstPeriod;
    }

    /// @inheritdoc IGaugeV3
    function nfpManager() external view returns (address) {
        return GaugeV3Storage.getStorage().nfpManager;
    }

    /// @inheritdoc IGaugeV3
    /// @dev period => token => total supply
    function tokenTotalSupplyByPeriod(uint256 period, address token) external view returns (uint256) {
        return GaugeV3Storage.getStorage().tokenTotalSupplyByPeriod[period][token];
    }

    /// @inheritdoc IGaugeV3
    /// @dev period => position hash => reward token => amount
    function periodClaimedAmount(uint256 period, bytes32 _positionHash, address rewardToken)
        external
        view
        returns (uint256)
    {
        return GaugeV3Storage.getStorage().periodClaimedAmount[period][_positionHash][rewardToken];
    }

    /// @dev token => position hash => period
    /// @inheritdoc IGaugeV3
    function lastClaimByToken(address token, bytes32 _positionHash) external view returns (uint256) {
        return GaugeV3Storage.getStorage().lastClaimByToken[token][_positionHash];
    }

    /// @inheritdoc IGaugeV3
    function syncNfpManager() external {
        GaugeV3Storage.GaugeV3State storage $ = GaugeV3Storage.getStorage();

        address voterNfpManager = IVoter(voter).nfpManager();

        if (voterNfpManager != address($.nfpManager)) {
            emit NfpManagerChanged(voterNfpManager, address($.nfpManager));

            $.nfpManager = voterNfpManager;
            $.nfpManagers.add(voterNfpManager);
        }
    }

    /// @inheritdoc IGaugeV3
    function getNfpManagers() external view returns (address[] memory) {
        return GaugeV3Storage.getStorage().nfpManagers.values();
    }

    /// @inheritdoc IGaugeV3
    function left(address token) external view override returns (uint256) {
        uint256 period = block.timestamp / 1 weeks;
        uint256 remainingTime = ((period + 1) * 1 weeks) - block.timestamp;
        return (GaugeV3Storage.getStorage().tokenTotalSupplyByPeriod[period][token] * remainingTime) / 1 weeks;
    }

    /// @inheritdoc IGaugeV3
    function rewardRate(address token) external view returns (uint256) {
        uint256 period = block.timestamp / 1 weeks;
        return (GaugeV3Storage.getStorage().tokenTotalSupplyByPeriod[period][token] / 1 weeks);
    }

    /// @inheritdoc IGaugeV3
    function getRewardTokens() external view override returns (address[] memory) {
        return GaugeV3Storage.getStorage().rewards.values();
    }

    /// @inheritdoc IGaugeV3
    function positionHash(address owner, uint256 index, int24 tickLower, int24 tickUpper)
        public
        pure
        returns (bytes32)
    {
        return keccak256(abi.encodePacked(owner, index, tickLower, tickUpper));
    }

    ////////////////////
    // Notify Rewards //
    ////////////////////

    /// @inheritdoc IGaugeV3
    function notifyRewardAmount(address token, uint256 amount) external override pushFees lock pullData {
        GaugeV3Storage.GaugeV3State storage $ = GaugeV3Storage.getStorage();

        require(amount > 0, Errors.NOT_GT_ZERO(amount));
        require(isWhitelisted(token), Errors.NOT_WHITELISTED(token));
        IShadowV3Pool($.pool)._advancePeriod();
        uint256 period = block.timestamp / 1 weeks;
        if (!$.rewards.contains(token)) {
            $.rewards.add(token);
        }

        uint256 balanceBefore = IERC20(token).balanceOf(address(this));
        IERC20(token).safeTransferFrom(msg.sender, address(this), amount);
        uint256 balanceAfter = IERC20(token).balanceOf(address(this));

        amount = balanceAfter - balanceBefore;
        $.tokenTotalSupplyByPeriod[period][token] += amount;
        emit NotifyReward(msg.sender, token, amount, period);
    }

    /// @inheritdoc IGaugeV3
    function notifyRewardAmountForPeriod(address token, uint256 amount, uint256 period) external lock pullData {
        require(amount > 0, Errors.NOT_GT_ZERO(amount));
        require(isWhitelisted(token), Errors.NOT_WHITELISTED(token));
        uint256 balanceBefore = IERC20(token).balanceOf(address(this));
        IERC20(token).safeTransferFrom(msg.sender, address(this), amount);
        uint256 balanceAfter = IERC20(token).balanceOf(address(this));

        amount = balanceAfter - balanceBefore;
        GaugeV3Storage.getStorage().tokenTotalSupplyByPeriod[period][token] += amount;

        emit NotifyReward(msg.sender, token, amount, period);
    }

    /// @inheritdoc IGaugeV3
    function earned(address token, uint256 tokenId) external view returns (uint256 reward) {
        GaugeV3Storage.GaugeV3State storage $ = GaugeV3Storage.getStorage();

        INonfungiblePositionManager _nfpManager = INonfungiblePositionManager($.nfpManager);
        (,,, int24 tickLower, int24 tickUpper,,,,,) = _nfpManager.positions(tokenId);

        bytes32 _positionHash = positionHash(address(_nfpManager), tokenId, tickLower, tickUpper);

        uint256 lastClaim = Math.max($.lastClaimByToken[token][_positionHash], $.firstPeriod);
        uint256 currentPeriod = block.timestamp / 1 weeks;
        for (uint256 period = lastClaim; period <= currentPeriod; ++period) {
            reward += periodEarned(period, token, address(_nfpManager), tokenId, tickLower, tickUpper);
        }
    }

    /// @inheritdoc IGaugeV3
    function periodEarned(uint256 period, address token, uint256 tokenId) public view override returns (uint256) {
        INonfungiblePositionManager _nfpManager = INonfungiblePositionManager(GaugeV3Storage.getStorage().nfpManager);
        (,,, int24 tickLower, int24 tickUpper,,,,,) = _nfpManager.positions(tokenId);

        return periodEarned(period, token, address(_nfpManager), tokenId, tickLower, tickUpper);
    }

    /// @inheritdoc IGaugeV3
    function periodEarned(uint256 period, address token, address owner, uint256 index, int24 tickLower, int24 tickUpper)
        public
        view
        returns (uint256 amount)
    {
        (bool success, bytes memory data) = address(this).staticcall(
            abi.encodeCall(this.cachePeriodEarned, (period, token, owner, index, tickLower, tickUpper, false))
        );

        if (!success) {
            return 0;
        }

        return abi.decode(data, (uint256));
    }

    /// @inheritdoc IGaugeV3
    /// @dev used by getReward() and saves gas by saving states
    function cachePeriodEarned(
        uint256 period,
        address token,
        address owner,
        uint256 index,
        int24 tickLower,
        int24 tickUpper,
        bool caching
    ) public override returns (uint256 amount) {
        GaugeV3Storage.GaugeV3State storage $ = GaugeV3Storage.getStorage();

        uint256 periodSecondsInsideX96;

        bytes32 _positionHash = positionHash(owner, index, tickLower, tickUpper);

        /// @dev get seconds from pool if not already written into storage
        uint256 amountsWrittenVersion = $.periodAmountsWrittenVersion[period][_positionHash];
        uint256 periodEndVerion = $.periodEndVerion[period];
        if (amountsWrittenVersion < periodEndVerion || amountsWrittenVersion == 0) {
            // if before deadline, read from pool
            if ($.usePoolData[period] || block.timestamp < ((period + 1) * 1 weeks - 1)) {
                (bool success, bytes memory data) = address($.pool).staticcall(
                    abi.encodeCall(
                        IShadowV3PoolState.positionPeriodSecondsInRange, (period, owner, index, tickLower, tickUpper)
                    )
                );

                if (!success) {
                    return 0;
                }

                (periodSecondsInsideX96) = abi.decode(data, (uint256));
            }
            // read from storage otherwise
            else {
                // return 0 if periodEndSecondsPerLiquidityCumulativeX128 isn't updated yet
                if ($.periodEndSecondsPerLiquidityCumulativeX128[period] == 0) {
                    return 0;
                }

                periodSecondsInsideX96 = _positionPeriodSecondsInRange(period, _positionHash, tickLower, tickUpper);
            }

            if (period < block.timestamp / 1 weeks && caching) {
                $.periodAmountsWrittenVersion[period][_positionHash] = periodEndVerion;
                $.periodNfpSecondsX96[period][_positionHash] = periodSecondsInsideX96;
            }
        } else {
            periodSecondsInsideX96 = $.periodNfpSecondsX96[period][_positionHash];
        }

        amount = FullMath.mulDiv($.tokenTotalSupplyByPeriod[period][token], periodSecondsInsideX96, 1 weeks << 96);

        uint256 claimed = $.periodClaimedAmount[period][_positionHash][token];
        if (amount >= claimed) {
            amount -= claimed;
        } else {
            amount = 0;
        }

        return amount;
    }

    /// @notice Get the period seconds in range of a specific position
    /// @return periodSecondsInsideX96 seconds the position was not in range for the period
    function _positionPeriodSecondsInRange(uint256 period, bytes32 _positionHash, int24 tickLower, int24 tickUpper)
        internal
        view
        returns (uint256 periodSecondsInsideX96)
    {
        PoolStorageOld.PoolState storage $ = PoolStorageOld.getStorage();
        IShadowV3Pool _pool = GaugeV3Storage.getStorage().pool;

        {
            uint256 currentPeriod = _getPeriod();
            if (period > currentPeriod) revert Errors.CANT_CLAIM_FUTURE();
        }

        uint256 liquidity;
        /// @dev get checkpoint at period, or last checkpoint before the period
        {
            PositionCheckpoint[] storage checkpoints = $.positionCheckpoints[_positionHash];
            uint256 checkpointPeriod;
            (checkpointPeriod, liquidity) = _getCheckpoint(checkpoints, period);

            /// @dev Return 0s if checkpointPeriod is 0
            if (checkpointPeriod == 0) {
                return 0;
            }
        }

        bytes32 readSlot;
        bytes32[] memory slots = new bytes32[](1);
        bytes32[] memory readResult;

        // int160 secondsPerLiquidityPeriodStartX128 =
        //     $.positions[_positionHash].periodRewardInfo[period].secondsPerLiquidityPeriodStartX128;
        RewardInfo storage rewardInfo = $.positions[_positionHash].periodRewardInfo[period];
        assembly ("memory-safe") {
            readSlot := add(rewardInfo.slot, 1) // secondsPerLiquidityPeriodStartX128 is in slot 1 of the struct
        }
        slots[0] = readSlot;
        readResult = _pool.readStorage(slots);
        readSlot = readResult[0]; // using readSlot as scratch space

        int160 secondsPerLiquidityPeriodStartX128;
        assembly ("memory-safe") {
            // shift according to struct layout
            secondsPerLiquidityPeriodStartX128 := shr(96, shl(88, readSlot))
        }

        uint160 secondsPerLiquidityInsideX128 = _periodCumulativesInside(uint32(period), tickLower, tickUpper);

        /// @dev underflow will be protected by sanity check
        secondsPerLiquidityInsideX128 =
            uint160(int160(secondsPerLiquidityInsideX128) - secondsPerLiquidityPeriodStartX128);

        // int256 secondsDebtX96 = rewardInfo.secondsDebtX96;
        assembly ("memory-safe") {
            readSlot := rewardInfo.slot // secondsDebtX96 is in slot 0 of the struct
        }
        slots[0] = readSlot;
        readResult = _pool.readStorage(slots);
        int256 secondsDebtX96 = int256(uint256(readResult[0]));

        /// @dev addDelta checks for under and overflows
        periodSecondsInsideX96 = FullMath.mulDiv(liquidity, secondsPerLiquidityInsideX128, FixedPoint32.Q32);

        /// @dev Need to check if secondsDebtX96>periodSecondsInsideX96, since rounding can cause underflows
        if (secondsDebtX96 < 0 || periodSecondsInsideX96 > uint256(secondsDebtX96)) {
            periodSecondsInsideX96 = secondsDebtX96 < 0
                ? periodSecondsInsideX96 + uint256(-secondsDebtX96)
                : periodSecondsInsideX96 - uint256(secondsDebtX96);
        } else {
            periodSecondsInsideX96 = 0;
        }

        /// @dev sanity
        if (periodSecondsInsideX96 > 1 weeks * FixedPoint96.Q96) {
            periodSecondsInsideX96 = 0;
        }
    }

    function _getCheckpoint(PositionCheckpoint[] storage checkpoints, uint256 period)
        internal
        view
        returns (uint256 checkpointPeriod, uint256 liquidity)
    {
        IShadowV3Pool _pool = GaugeV3Storage.getStorage().pool;

        bytes32 readSlot;
        bytes32[] memory slots = new bytes32[](1);
        bytes32[] memory readResult;
        uint256 checkpointIndex;

        assembly ("memory-safe") {
            readSlot := checkpoints.slot // length slot is the same as the pointer
        }
        bytes32 checkpoints0Slot = keccak256(abi.encode(readSlot));

        {
            // uint256 checkpointLength = checkpoints.length;
            slots[0] = readSlot;
            readResult = _pool.readStorage(slots);
            uint256 checkpointLength = uint256(readResult[0]);

            /// @dev return 0 if length is 0
            if (checkpointLength == 0) {
                return (0, 0);
            }

            // checkpointPeriod = checkpoints[0].period;
            assembly ("memory-safe") {
                readSlot := checkpoints0Slot // period is in slot 0 of the struct
            }
            slots[0] = readSlot;
            readResult = _pool.readStorage(slots);

            checkpointPeriod = uint256(readResult[0]);

            /// @dev return 0 if first checkpoint happened after period
            if (checkpointPeriod > period) {
                return (0, 0);
            }

            checkpointIndex = checkpointLength - 1;

            // checkpointPeriod = checkpoints[checkpointIndex].period;
            assembly ("memory-safe") {
                readSlot := add(checkpoints0Slot, mul(checkpointIndex, 2)) // period is in slot 0 of the struct
            }
            slots[0] = readSlot;
            readResult = _pool.readStorage(slots);

            checkpointPeriod = uint256(readResult[0]);
        }

        /// @dev Find relevant checkpoint if latest checkpoint isn't before period of interest
        if (checkpointPeriod > period) {
            uint256 lower = 0;
            uint256 upper = checkpointIndex;
            bool foundEarly;
            while (upper > lower) {
                /// @dev ceil, avoiding overflow
                uint256 center = upper - (upper - lower) / 2;
                // checkpointPeriod = checkpoints[center].period;
                assembly ("memory-safe") {
                    readSlot := add(checkpoints0Slot, mul(center, 2)) // period is in slot 0 of the struct
                }
                slots[0] = readSlot;
                readResult = _pool.readStorage(slots);
                checkpointPeriod = uint256(readResult[0]);

                if (checkpointPeriod == period) {
                    checkpointIndex = center;
                    foundEarly = true;
                    break;
                    // return (checkpointIndex, checkpointPeriod);
                } else if (checkpointPeriod < period) {
                    lower = center;
                } else {
                    upper = center - 1;
                }
            }

            if (!foundEarly) {
                checkpointIndex = lower;
            }
        }

        // checkpointPeriod = checkpoints[checkpointIndex].period;
        assembly ("memory-safe") {
            readSlot := add(checkpoints0Slot, mul(checkpointIndex, 2)) // period is in slot 0 of the struct
        }
        slots[0] = readSlot;
        readResult = _pool.readStorage(slots);
        checkpointPeriod = uint256(readResult[0]);

        // liquidity = checkpoints[checkpointIndex].liquidity;
        assembly ("memory-safe") {
            readSlot := add(add(checkpoints0Slot, mul(checkpointIndex, 2)), 1) // liquidity is in slot 1 of the struct
        }
        slots[0] = readSlot;
        readResult = _pool.readStorage(slots);
        liquidity = uint256(readResult[0]);

        return (checkpointPeriod, liquidity);
    }

    /// @notice Returns the seconds per liquidity and seconds inside a tick range for a period
    /// @dev This does not ensure the range is a valid range
    /// @param period The timestamp of the period
    /// @param tickLower The lower tick of the range
    /// @param tickUpper The upper tick of the range
    /// @return secondsPerLiquidityInsideX128 The snapshot of seconds per liquidity for the range
    function _periodCumulativesInside(uint32 period, int24 tickLower, int24 tickUpper)
        internal
        view
        returns (uint160 secondsPerLiquidityInsideX128)
    {
        PoolStorageOld.PoolState storage $ = PoolStorageOld.getStorage();
        IShadowV3Pool _pool = GaugeV3Storage.getStorage().pool;

        Oracle.SnapShot memory snapshot;

        bytes32 readSlot;
        bytes32[] memory slots = new bytes32[](1);
        bytes32[] memory readResult;

        {
            // int24 startTick = $.periods[period].startTick;
            // uint256 previousPeriod = $.periods[period].previousPeriod;
            int24 startTick;
            uint256 previousPeriod;
            {
                PeriodInfo storage periodInfo = $.periods[period];
                assembly ("memory-safe") {
                    readSlot := periodInfo.slot
                }
                slots[0] = readSlot;
                readResult = _pool.readStorage(slots);
                readSlot = readResult[0]; // using readSlot as scratch space

                assembly ("memory-safe") {
                    // shift read result according to struct offsets
                    startTick := shr(232, shl(200, readSlot))
                    previousPeriod := shr(224, shl(224, readSlot))
                }
            }

            // snapshot.secondsPerLiquidityOutsideLowerX128 =
            //     uint160($._ticks[tickLower].periodSecondsPerLiquidityOutsideX128[period]);
            {
                mapping(uint256 => uint256) storage splOutsideX128 =
                    $._ticks[tickLower].periodSecondsPerLiquidityOutsideX128;
                assembly ("memory-safe") {
                    readSlot := splOutsideX128.slot
                }
                readSlot = keccak256(abi.encode(period, readSlot));
                slots[0] = readSlot;
                readResult = _pool.readStorage(slots);
                snapshot.secondsPerLiquidityOutsideLowerX128 = uint160(uint256(readResult[0]));
            }

            if (tickLower <= startTick && snapshot.secondsPerLiquidityOutsideLowerX128 == 0) {
                // snapshot.secondsPerLiquidityOutsideLowerX128 =
                //     $.periods[previousPeriod].endSecondsPerLiquidityPeriodX128;
                PeriodInfo storage periodInfo = $.periods[previousPeriod];
                assembly ("memory-safe") {
                    readSlot := periodInfo.slot
                }
                slots[0] = readSlot;
                readResult = _pool.readStorage(slots);
                readSlot = readResult[0]; // using readSlot as scratch space

                assembly ("memory-safe") {
                    // shift read result according to struct offsets
                    readSlot := shr(96, shl(16, readSlot))
                }
                snapshot.secondsPerLiquidityOutsideLowerX128 = uint160(uint256(readSlot));
            }

            // snapshot.secondsPerLiquidityOutsideUpperX128 =
            //     uint160($._ticks[tickUpper].periodSecondsPerLiquidityOutsideX128[period]);
            {
                mapping(uint256 => uint256) storage splOutsideX128 =
                    $._ticks[tickUpper].periodSecondsPerLiquidityOutsideX128;
                assembly ("memory-safe") {
                    readSlot := splOutsideX128.slot
                }
                readSlot = keccak256(abi.encode(period, readSlot));
                slots[0] = readSlot;
                readResult = _pool.readStorage(slots);
                snapshot.secondsPerLiquidityOutsideUpperX128 = uint160(uint256(readResult[0]));
            }

            if (tickUpper <= startTick && snapshot.secondsPerLiquidityOutsideUpperX128 == 0) {
                // snapshot.secondsPerLiquidityOutsideUpperX128 =
                //     $.periods[previousPeriod].endSecondsPerLiquidityPeriodX128;
                PeriodInfo storage periodInfo = $.periods[previousPeriod];
                assembly ("memory-safe") {
                    readSlot := periodInfo.slot
                }
                slots[0] = readSlot;
                readResult = _pool.readStorage(slots);
                readSlot = readResult[0]; // using readSlot as scratch space

                assembly ("memory-safe") {
                    // shift read result according to struct offsets
                    readSlot := shr(96, shl(16, readSlot))
                }
                snapshot.secondsPerLiquidityOutsideUpperX128 = uint160(uint256(readSlot));
            }
        }

        /// @dev use period's last tick, this function will only be called after a period is finalized
        // int24 lastTick = $.periods[period].lastTick;
        PeriodInfo storage periodInfoForLastTick = $.periods[period];
        assembly ("memory-safe") {
            readSlot := periodInfoForLastTick.slot
        }
        slots[0] = readSlot;
        readResult = _pool.readStorage(slots);
        readSlot = readResult[0]; // using readSlot as scratch space

        int24 lastTick;
        assembly ("memory-safe") {
            // shift read result according to struct offsets
            lastTick := shr(232, shl(176, readSlot))
        }

        unchecked {
            if (lastTick < tickLower) {
                return snapshot.secondsPerLiquidityOutsideLowerX128 - snapshot.secondsPerLiquidityOutsideUpperX128;
            } else if (lastTick < tickUpper) {
                /// @dev use endSecondsPerLiquidityPeriodX128, this function can only be called when a period is finalized
                return GaugeV3Storage.getStorage().periodEndSecondsPerLiquidityCumulativeX128[period]
                    - snapshot.secondsPerLiquidityOutsideLowerX128 - snapshot.secondsPerLiquidityOutsideUpperX128;
            } else {
                return snapshot.secondsPerLiquidityOutsideUpperX128 - snapshot.secondsPerLiquidityOutsideLowerX128;
            }
        }
    }

    /// @inheritdoc IGaugeV3
    function getPeriodReward(uint256 period, address[] calldata tokens, uint256 tokenId, address receiver)
        external
        override
    {
        getNfpPeriodReward(address(GaugeV3Storage.getStorage().nfpManager), period, tokens, tokenId, receiver);
    }

    /// @inheritdoc IGaugeV3
    function getNfpPeriodReward(
        address __nfpManager,
        uint256 period,
        address[] calldata tokens,
        uint256 tokenId,
        address receiver
    ) public override lock pullData {
        GaugeV3Storage.GaugeV3State storage $ = GaugeV3Storage.getStorage();

        require(period <= block.timestamp / 1 weeks, Errors.CANT_CLAIM_FUTURE());
        require($.nfpManagers.contains(__nfpManager), Errors.NOT_NFP_MANAGER(__nfpManager));

        INonfungiblePositionManager _nfpManager = INonfungiblePositionManager(__nfpManager);

        /// @dev stack-too-deep
        {
            address owner = _nfpManager.ownerOf(tokenId);
            address operator = _nfpManager.getApproved(tokenId);

            /// @dev check if owner, operator, or approved for all
            require(
                msg.sender == owner || msg.sender == operator || _nfpManager.isApprovedForAll(owner, msg.sender),
                Errors.NOT_AUTHORIZED(msg.sender)
            );
        }

        (,,, int24 tickLower, int24 tickUpper,,,,,) = _nfpManager.positions(tokenId);

        bytes32 _positionHash = positionHash(address(_nfpManager), tokenId, tickLower, tickUpper);

        for (uint256 i = 0; i < tokens.length; ++i) {
            if (period < block.timestamp / 1 weeks) {
                $.lastClaimByToken[tokens[i]][_positionHash] = period;
            }

            _getReward(period, tokens[i], address(_nfpManager), tokenId, tickLower, tickUpper, _positionHash, receiver);
        }
    }

    /// @inheritdoc IGaugeV3
    function getPeriodReward(
        uint256 period,
        address[] calldata tokens,
        address owner,
        uint256 index,
        int24 tickLower,
        int24 tickUpper,
        address receiver
    ) external override lock pullData {
        /// @dev ensure only the owner can call
        require(msg.sender == owner, Errors.NOT_AUTHORIZED(msg.sender));
        bytes32 _positionHash = positionHash(owner, index, tickLower, tickUpper);

        for (uint256 i = 0; i < tokens.length; ++i) {
            if (period < block.timestamp / 1 weeks) {
                GaugeV3Storage.getStorage().lastClaimByToken[tokens[i]][_positionHash] = period;
            }

            _getReward(period, tokens[i], owner, index, tickLower, tickUpper, _positionHash, receiver);
        }
    }

    /// @inheritdoc IGaugeV3
    /// @dev validation is handled in the getReward function
    function getReward(uint256[] calldata tokenIds, address[] memory tokens) external {
        uint256 length = tokenIds.length;

        for (uint256 i = 0; i < length; ++i) {
            getReward(tokenIds[i], tokens);
        }
    }

    /// @inheritdoc IGaugeV3
    function getReward(uint256 tokenId, address[] memory tokens) public lock pullData {
        INonfungiblePositionManager _nfpManager = INonfungiblePositionManager(GaugeV3Storage.getStorage().nfpManager);
        address owner = _nfpManager.ownerOf(tokenId);
        address operator = _nfpManager.getApproved(tokenId);
        /// @dev check if owner, operator, or approved for all
        require(
            msg.sender == owner || msg.sender == operator || _nfpManager.isApprovedForAll(owner, msg.sender),
            Errors.NOT_AUTHORIZED(msg.sender)
        );

        (,,, int24 tickLower, int24 tickUpper,,,,,) = _nfpManager.positions(tokenId);

        _getAllRewards(address(_nfpManager), tokenId, tickLower, tickUpper, tokens, msg.sender);
    }

    /// @inheritdoc IGaugeV3
    function getRewardForOwner(uint256 tokenId, address[] memory tokens) external lock pullData {
        GaugeV3Storage.GaugeV3State storage $ = GaugeV3Storage.getStorage();

        INonfungiblePositionManager _nfpManager =
            msg.sender == voter ? INonfungiblePositionManager($.nfpManager) : INonfungiblePositionManager(msg.sender);

        require(msg.sender == voter || $.nfpManagers.contains(msg.sender), Errors.NOT_AUTHORIZED(msg.sender));

        address owner = _nfpManager.ownerOf(tokenId);

        (,,, int24 tickLower, int24 tickUpper,,,,,) = _nfpManager.positions(tokenId);

        _getAllRewards(address(_nfpManager), tokenId, tickLower, tickUpper, tokens, owner);
    }

    /// @inheritdoc IGaugeV3
    /// @dev this requires auth checks to be done a the Voter/NFPManager level
    /// since this is meant to send xShadow the back to msg.sender and exits it for the user
    function getXShadowRewardForOwner(uint256 tokenId) external lock pullData {
        GaugeV3Storage.GaugeV3State storage $ = GaugeV3Storage.getStorage();

        INonfungiblePositionManager _nfpManager =
            msg.sender == voter ? INonfungiblePositionManager($.nfpManager) : INonfungiblePositionManager(msg.sender);

        require(msg.sender == voter || $.nfpManagers.contains(msg.sender), Errors.NOT_AUTHORIZED(msg.sender));

        (,,, int24 tickLower, int24 tickUpper,,,,,) = _nfpManager.positions(tokenId);
        address[] memory tokens = new address[](1);
        tokens[0] = xShadow;

        /// @dev send xShadow to this address for exiting
        _getAllRewards(address(_nfpManager), tokenId, tickLower, tickUpper, tokens, msg.sender);
    }

    function getReward(
        address owner,
        uint256 index,
        int24 tickLower,
        int24 tickUpper,
        address[] memory tokens,
        address receiver
    ) external lock pullData {
        require(msg.sender == owner, Errors.NOT_AUTHORIZED(msg.sender));
        _getAllRewards(owner, index, tickLower, tickUpper, tokens, receiver);
    }

    function _getAllRewards(
        address owner,
        uint256 index,
        int24 tickLower,
        int24 tickUpper,
        address[] memory tokens,
        address receiver
    ) internal {
        GaugeV3Storage.GaugeV3State storage $ = GaugeV3Storage.getStorage();

        bytes32 _positionHash = positionHash(owner, index, tickLower, tickUpper);
        uint256 currentPeriod = block.timestamp / 1 weeks;
        uint256 lastClaim;
        for (uint256 i = 0; i < tokens.length; ++i) {
            lastClaim = Math.max($.lastClaimByToken[tokens[i]][_positionHash], $.firstPeriod);
            for (uint256 period = lastClaim; period <= currentPeriod; ++period) {
                _getReward(period, tokens[i], owner, index, tickLower, tickUpper, _positionHash, receiver);
            }
            $.lastClaimByToken[tokens[i]][_positionHash] = currentPeriod - 1;
        }
    }

    function _getReward(
        uint256 period,
        address token,
        address owner,
        uint256 index,
        int24 tickLower,
        int24 tickUpper,
        bytes32 _positionHash,
        address receiver
    ) internal {
        uint256 _reward = cachePeriodEarned(period, token, owner, index, tickLower, tickUpper, true);

        if (_reward > 0) {
            GaugeV3Storage.getStorage().periodClaimedAmount[period][_positionHash][token] += _reward;

            IERC20(token).safeTransfer(receiver, _reward);
            emit ClaimRewards(period, _positionHash, receiver, token, _reward);
        }
    }

    /// @dev return directly from the voter
    function isWhitelisted(address token) public view returns (bool) {
        return IVoter(voter).isWhitelisted(token);
    }

    /// @dev use the enumerable set to fetch reward validation
    function isGaugeReward(address token) public view returns (bool) {
        return GaugeV3Storage.getStorage().rewards.contains(token);
    }

    /// @dev used when the oracle data is already overwritten
    /// shouldn't happen unless the team took too long to call distribute()
    function updatePeriodData(uint256 period, uint160 periodEndSecondsPerLiquidityCumulativeX128) external {
        require(msg.sender == IVoter(voter).accessHub(), Errors.NOT_ACCESSHUB());

        GaugeV3Storage.GaugeV3State storage $ = GaugeV3Storage.getStorage();

        $.periodEndSecondsPerLiquidityCumulativeX128[period] = periodEndSecondsPerLiquidityCumulativeX128;
        $.periodEndVerion[period]++;
        $.cachedPoolLastPeriod = period + 1;
    }
}

File 7 of 54 : IBeacon.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/beacon/IBeacon.sol)

pragma solidity ^0.8.20;

/**
 * @dev This is the interface that {BeaconProxy} expects of its beacon.
 */
interface IBeacon {
    /**
     * @dev Must return an address that can be used as a delegate call target.
     *
     * {UpgradeableBeacon} will check that this address is a contract.
     */
    function implementation() external view returns (address);
}

File 8 of 54 : Proxy.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/Proxy.sol)

pragma solidity ^0.8.20;

/**
 * @dev This abstract contract provides a fallback function that delegates all calls to another contract using the EVM
 * instruction `delegatecall`. We refer to the second contract as the _implementation_ behind the proxy, and it has to
 * be specified by overriding the virtual {_implementation} function.
 *
 * Additionally, delegation to the implementation can be triggered manually through the {_fallback} function, or to a
 * different contract through the {_delegate} function.
 *
 * The success and return data of the delegated call will be returned back to the caller of the proxy.
 */
abstract contract Proxy {
    /**
     * @dev Delegates the current call to `implementation`.
     *
     * This function does not return to its internal call site, it will return directly to the external caller.
     */
    function _delegate(address implementation) internal virtual {
        assembly {
            // Copy msg.data. We take full control of memory in this inline assembly
            // block because it will not return to Solidity code. We overwrite the
            // Solidity scratch pad at memory position 0.
            calldatacopy(0, 0, calldatasize())

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

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

            switch result
            // delegatecall returns 0 on error.
            case 0 {
                revert(0, returndatasize())
            }
            default {
                return(0, returndatasize())
            }
        }
    }

    /**
     * @dev This is a virtual function that should be overridden so it returns the address to which the fallback
     * function and {_fallback} should delegate.
     */
    function _implementation() internal view virtual returns (address);

    /**
     * @dev Delegates the current call to the address returned by `_implementation()`.
     *
     * This function does not return to its internal call site, it will return directly to the external caller.
     */
    function _fallback() internal virtual {
        _delegate(_implementation());
    }

    /**
     * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if no other
     * function in the contract matches the call data.
     */
    fallback() external payable virtual {
        _fallback();
    }
}

File 9 of 54 : ERC1967Utils.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (proxy/ERC1967/ERC1967Utils.sol)

pragma solidity ^0.8.21;

import {IBeacon} from "../beacon/IBeacon.sol";
import {IERC1967} from "../../interfaces/IERC1967.sol";
import {Address} from "../../utils/Address.sol";
import {StorageSlot} from "../../utils/StorageSlot.sol";

/**
 * @dev This library provides getters and event emitting update functions for
 * https://eips.ethereum.org/EIPS/eip-1967[ERC-1967] slots.
 */
library ERC1967Utils {
    /**
     * @dev Storage slot with the address of the current implementation.
     * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1.
     */
    // solhint-disable-next-line private-vars-leading-underscore
    bytes32 internal constant IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;

    /**
     * @dev The `implementation` of the proxy is invalid.
     */
    error ERC1967InvalidImplementation(address implementation);

    /**
     * @dev The `admin` of the proxy is invalid.
     */
    error ERC1967InvalidAdmin(address admin);

    /**
     * @dev The `beacon` of the proxy is invalid.
     */
    error ERC1967InvalidBeacon(address beacon);

    /**
     * @dev An upgrade function sees `msg.value > 0` that may be lost.
     */
    error ERC1967NonPayable();

    /**
     * @dev Returns the current implementation address.
     */
    function getImplementation() internal view returns (address) {
        return StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value;
    }

    /**
     * @dev Stores a new address in the ERC-1967 implementation slot.
     */
    function _setImplementation(address newImplementation) private {
        if (newImplementation.code.length == 0) {
            revert ERC1967InvalidImplementation(newImplementation);
        }
        StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value = newImplementation;
    }

    /**
     * @dev Performs implementation upgrade with additional setup call if data is nonempty.
     * This function is payable only if the setup call is performed, otherwise `msg.value` is rejected
     * to avoid stuck value in the contract.
     *
     * Emits an {IERC1967-Upgraded} event.
     */
    function upgradeToAndCall(address newImplementation, bytes memory data) internal {
        _setImplementation(newImplementation);
        emit IERC1967.Upgraded(newImplementation);

        if (data.length > 0) {
            Address.functionDelegateCall(newImplementation, data);
        } else {
            _checkNonPayable();
        }
    }

    /**
     * @dev Storage slot with the admin of the contract.
     * This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1.
     */
    // solhint-disable-next-line private-vars-leading-underscore
    bytes32 internal constant ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;

    /**
     * @dev Returns the current admin.
     *
     * TIP: To get this value clients can read directly from the storage slot shown below (specified by ERC-1967) using
     * the https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call.
     * `0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103`
     */
    function getAdmin() internal view returns (address) {
        return StorageSlot.getAddressSlot(ADMIN_SLOT).value;
    }

    /**
     * @dev Stores a new address in the ERC-1967 admin slot.
     */
    function _setAdmin(address newAdmin) private {
        if (newAdmin == address(0)) {
            revert ERC1967InvalidAdmin(address(0));
        }
        StorageSlot.getAddressSlot(ADMIN_SLOT).value = newAdmin;
    }

    /**
     * @dev Changes the admin of the proxy.
     *
     * Emits an {IERC1967-AdminChanged} event.
     */
    function changeAdmin(address newAdmin) internal {
        emit IERC1967.AdminChanged(getAdmin(), newAdmin);
        _setAdmin(newAdmin);
    }

    /**
     * @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.
     * This is the keccak-256 hash of "eip1967.proxy.beacon" subtracted by 1.
     */
    // solhint-disable-next-line private-vars-leading-underscore
    bytes32 internal constant BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;

    /**
     * @dev Returns the current beacon.
     */
    function getBeacon() internal view returns (address) {
        return StorageSlot.getAddressSlot(BEACON_SLOT).value;
    }

    /**
     * @dev Stores a new beacon in the ERC-1967 beacon slot.
     */
    function _setBeacon(address newBeacon) private {
        if (newBeacon.code.length == 0) {
            revert ERC1967InvalidBeacon(newBeacon);
        }

        StorageSlot.getAddressSlot(BEACON_SLOT).value = newBeacon;

        address beaconImplementation = IBeacon(newBeacon).implementation();
        if (beaconImplementation.code.length == 0) {
            revert ERC1967InvalidImplementation(beaconImplementation);
        }
    }

    /**
     * @dev Change the beacon and trigger a setup call if data is nonempty.
     * This function is payable only if the setup call is performed, otherwise `msg.value` is rejected
     * to avoid stuck value in the contract.
     *
     * Emits an {IERC1967-BeaconUpgraded} event.
     *
     * CAUTION: Invoking this function has no effect on an instance of {BeaconProxy} since v5, since
     * it uses an immutable beacon without looking at the value of the ERC-1967 beacon slot for
     * efficiency.
     */
    function upgradeBeaconToAndCall(address newBeacon, bytes memory data) internal {
        _setBeacon(newBeacon);
        emit IERC1967.BeaconUpgraded(newBeacon);

        if (data.length > 0) {
            Address.functionDelegateCall(IBeacon(newBeacon).implementation(), data);
        } else {
            _checkNonPayable();
        }
    }

    /**
     * @dev Reverts if `msg.value` is not zero. It can be used to avoid `msg.value` stuck in the contract
     * if an upgrade doesn't perform an initialization call.
     */
    function _checkNonPayable() private {
        if (msg.value > 0) {
            revert ERC1967NonPayable();
        }
    }
}

File 10 of 54 : IGaugeV3.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

interface IGaugeV3 {
    /// @notice Emitted when the NFP Manager is changed
    /// @param newNfpManager The address of the new NFP Manager
    /// @param oldNfpManager The address of the old NFP Manager
    event NfpManagerChanged(address indexed newNfpManager, address indexed oldNfpManager);

    /// @notice Emitted when a reward notification is made.
    /// @param from The address from which the reward is notified.
    /// @param reward The address of the reward token.
    /// @param amount The amount of rewards notified.
    /// @param period The period for which the rewards are notified.
    event NotifyReward(address indexed from, address indexed reward, uint256 amount, uint256 period);

    /// @notice Emitted when a bribe is made.
    /// @param from The address from which the bribe is made.
    /// @param reward The address of the reward token.
    /// @param amount The amount of tokens bribed.
    /// @param period The period for which the bribe is made.
    event Bribe(address indexed from, address indexed reward, uint256 amount, uint256 period);

    /// @notice Emitted when rewards are claimed.
    /// @param period The period for which the rewards are claimed.
    /// @param _positionHash The identifier of the NFP for which rewards are claimed.
    /// @param receiver The address of the receiver of the claimed rewards.
    /// @param reward The address of the reward token.
    /// @param amount The amount of rewards claimed.
    event ClaimRewards(uint256 period, bytes32 _positionHash, address receiver, address reward, uint256 amount);

    /// @notice Emitted when a new reward token was pushed to the rewards array
    event RewardAdded(address reward);

    /// @notice Emitted when a reward token was removed from the rewards array
    event RewardRemoved(address reward);

    /// @notice Returns the NFP Manager
    function nfpManager() external view returns (address);

    /// @notice updates pool data after period flip
    function updatePool() external;

    /// @notice Syncs NFP Manager from the voter
    function syncNfpManager() external;

    /// @notice returns an array of all nfpManagers in this gauge
    function getNfpManagers() external view returns (address[] memory);

    /// @notice returns the pool of this gauge
    function pool() external view returns (address);

    /// @notice Retrieves the value of the firstPeriod variable.
    /// @return The value of the firstPeriod variable.
    function firstPeriod() external returns (uint256);

    /// @notice Retrieves the total supply of a specific token for a given period.
    /// @param period The period for which to retrieve the total supply.
    /// @param token The address of the token for which to retrieve the total supply.
    /// @return The total supply of the specified token for the given period.
    function tokenTotalSupplyByPeriod(uint256 period, address token) external view returns (uint256);

    /// @notice Retrieves the getTokenTotalSupplyByPeriod of the current period.
    /// @dev included to support voter's left() check during distribute().
    /// @param token The address of the token for which to retrieve the remaining amount.
    /// @return The amount of tokens left to distribute in this period.
    function left(address token) external view returns (uint256);

    /// @notice Retrieves the reward rate for a specific reward address.
    /// @dev this method returns the base rate without boost
    /// @param token The address of the reward for which to retrieve the reward rate.
    /// @return The reward rate for the specified reward address.
    function rewardRate(address token) external view returns (uint256);

    /// @notice Retrieves the claimed amount for a specific period, position hash, and user address.
    /// @param period The period for which to retrieve the claimed amount.
    /// @param _positionHash The identifier of the NFP for which to retrieve the claimed amount.
    /// @param reward The address of the token for the claimed amount.
    /// @return The claimed amount for the specified period, token ID, and user address.
    function periodClaimedAmount(uint256 period, bytes32 _positionHash, address reward)
        external
        view
        returns (uint256);

    /// @notice Retrieves the last claimed period for a specific token, token ID combination.
    /// @param token The address of the reward token for which to retrieve the last claimed period.
    /// @param _positionHash The identifier of the NFP for which to retrieve the last claimed period.
    /// @return The last claimed period for the specified token and token ID.
    function lastClaimByToken(address token, bytes32 _positionHash) external view returns (uint256);

    /// @notice Checks if a given address is a valid reward.
    /// @param reward The address to check.
    /// @return A boolean indicating whether the address is a valid reward.
    function isGaugeReward(address reward) external view returns (bool);

    /// @notice Returns an array of reward token addresses.
    /// @return An array of reward token addresses.
    function getRewardTokens() external view returns (address[] memory);

    /// @notice Returns the hash used to store positions in a mapping
    /// @param owner The address of the position owner
    /// @param index The index of the position
    /// @param tickLower The lower tick boundary of the position
    /// @param tickUpper The upper tick boundary of the position
    /// @return _hash The hash used to store positions in a mapping
    function positionHash(address owner, uint256 index, int24 tickLower, int24 tickUpper)
        external
        pure
        returns (bytes32);

    /*
    /// @notice Retrieves the liquidity and boosted liquidity for a specific NFP.
    /// @param tokenId The identifier of the NFP.
    /// @return liquidity The liquidity of the position token.
    function positionInfo(
        uint256 tokenId
    ) external view returns (uint128 liquidity);
    */

    /// @notice Returns the amount of rewards earned for an NFP.
    /// @param token The address of the token for which to retrieve the earned rewards.
    /// @param tokenId The identifier of the specific NFP for which to retrieve the earned rewards.
    /// @return reward The amount of rewards earned for the specified NFP and tokens.
    function earned(address token, uint256 tokenId) external view returns (uint256 reward);

    /// @notice Returns the amount of rewards earned during a period for an NFP.
    /// @param period The period for which to retrieve the earned rewards.
    /// @param token The address of the token for which to retrieve the earned rewards.
    /// @param tokenId The identifier of the specific NFP for which to retrieve the earned rewards.
    /// @return reward The amount of rewards earned for the specified NFP and tokens.
    function periodEarned(uint256 period, address token, uint256 tokenId) external view returns (uint256);

    /// @notice Retrieves the earned rewards for a specific period, token, owner, index, tickLower, and tickUpper.
    /// @param period The period for which to retrieve the earned rewards.
    /// @param token The address of the token for which to retrieve the earned rewards.
    /// @param owner The address of the owner for which to retrieve the earned rewards.
    /// @param index The index for which to retrieve the earned rewards.
    /// @param tickLower The tick lower bound for which to retrieve the earned rewards.
    /// @param tickUpper The tick upper bound for which to retrieve the earned rewards.
    /// @return The earned rewards for the specified period, token, owner, index, tickLower, and tickUpper.
    function periodEarned(uint256 period, address token, address owner, uint256 index, int24 tickLower, int24 tickUpper)
        external
        view
        returns (uint256);

    /// @notice Retrieves the earned rewards for a specific period, token, owner, index, tickLower, and tickUpper.
    /// @dev used by getReward() and saves gas by saving states
    /// @param period The period for which to retrieve the earned rewards.
    /// @param token The address of the token for which to retrieve the earned rewards.
    /// @param owner The address of the owner for which to retrieve the earned rewards.
    /// @param index The index for which to retrieve the earned rewards.
    /// @param tickLower The tick lower bound for which to retrieve the earned rewards.
    /// @param tickUpper The tick upper bound for which to retrieve the earned rewards.
    /// @param caching Whether to cache the results or not.
    /// @return The earned rewards for the specified period, token, owner, index, tickLower, and tickUpper.
    function cachePeriodEarned(
        uint256 period,
        address token,
        address owner,
        uint256 index,
        int24 tickLower,
        int24 tickUpper,
        bool caching
    ) external returns (uint256);

    /// @notice Notifies the contract about the amount of rewards to be distributed for a specific token.
    /// @param token The address of the token for which to notify the reward amount.
    /// @param amount The amount of rewards to be distributed.
    function notifyRewardAmount(address token, uint256 amount) external;

    /// @notice Retrieves the reward amount for a specific period, NFP, and token addresses.
    /// @param period The period for which to retrieve the reward amount.
    /// @param tokens The addresses of the tokens for which to retrieve the reward amount.
    /// @param tokenId The identifier of the specific NFP for which to retrieve the reward amount.
    /// @param receiver The address of the receiver of the reward amount.
    function getPeriodReward(uint256 period, address[] calldata tokens, uint256 tokenId, address receiver) external;

    /// @notice Retrieves the reward amount for a specific NFP Manager, period, NFP, and token addresses.
    /// @param __nfpManager The NFP Manager.
    /// @param period The period for which to retrieve the reward amount.
    /// @param tokens The addresses of the tokens for which to retrieve the reward amount.
    /// @param tokenId The identifier of the specific NFP for which to retrieve the reward amount.
    /// @param receiver The address of the receiver of the reward amount.
    function getNfpPeriodReward(
        address __nfpManager,
        uint256 period,
        address[] calldata tokens,
        uint256 tokenId,
        address receiver
    ) external;

    /// @notice Retrieves the rewards for a specific period, set of tokens, owner, index, tickLower, tickUpper, and receiver.
    /// @param period The period for which to retrieve the rewards.
    /// @param tokens An array of token addresses for which to retrieve the rewards.
    /// @param owner The address of the owner for which to retrieve the rewards.
    /// @param index The index for which to retrieve the rewards.
    /// @param tickLower The tick lower bound for which to retrieve the rewards.
    /// @param tickUpper The tick upper bound for which to retrieve the rewards.
    /// @param receiver The address of the receiver of the rewards.
    function getPeriodReward(
        uint256 period,
        address[] calldata tokens,
        address owner,
        uint256 index,
        int24 tickLower,
        int24 tickUpper,
        address receiver
    ) external;

    /// @notice retrieves rewards based on an NFP id and an array of tokens
    function getReward(uint256 tokenId, address[] memory tokens) external;
    /// @notice retrieves rewards based on an array of NFP ids and an array of tokens
    function getReward(uint256[] calldata tokenIds, address[] memory tokens) external;
    /// @notice get reward for an owner of an NFP
    function getRewardForOwner(uint256 tokenId, address[] memory tokens) external;
    /// @notice get xShadow reward for an owner of an NFP
    function getXShadowRewardForOwner(uint256 tokenId) external;

    /// @notice Notifies rewards for periods greater than current period
    /// @dev does not push fees
    /// @dev requires reward token to be whitelisted
    function notifyRewardAmountForPeriod(address token, uint256 amount, uint256 period) external;
}

File 11 of 54 : IPoolUpdater.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import {IVoter} from "contracts/interfaces/IVoter.sol";
import {INonfungiblePositionManager} from "contracts/CL/periphery/interfaces/INonfungiblePositionManager.sol";

interface IPoolUpdater {
    struct SeedData {
        address pool;
        address token0;
        address token1;
        uint256 amount0;
        uint256 amount1;
    }

    ////////////////////
    // View Functions //
    ////////////////////

    function voter() external view returns (IVoter);

    function nfpManager() external view returns (INonfungiblePositionManager);

    function isSeeded(address pool) external view returns (bool);

    function findMissing() external view returns (address[] memory _missingTokens);

    function findNotUpdated() external view returns (address[] memory pools);

    function poolToNfp(address clPool) external view returns (uint256);

    function getAllGauges() external view returns (address[] memory);

    function getGauge(uint256 index) external view returns (address);

    function getGaugeLength() external view returns (uint256);

    function getAllClPools() external view returns (address[] memory);

    function getClPool(uint256 index) external view returns (address);

    function getClPoolsLength() external view returns (uint256);

    //////////////////////
    // Seed and Updates //
    //////////////////////

    function updateRecords() external;

    function seed(uint256 start, uint256 end) external returns (SeedData[] memory failedSeeds);
    function seed(address pool) external;

    function seed(address pool, bool revertOnFailure) external returns (bool success, SeedData memory seedData);

    function updatePools(uint256 start, uint256 end, bool _updateRecords, bool force)
        external
        returns (uint256[] memory, address[] memory);

    function updatePool(address _pool) external;

    ///////////////
    // Callbacks //
    ///////////////

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

    function onERC721Received(address operator, address from, uint256 tokenId, bytes calldata data)
        external
        pure
        returns (bytes4 retval);

    ///////////////////////
    // AccessHub Actions //
    ///////////////////////

    function sweep(address _token) external;

    function execute(address _target, bytes calldata _payload) external returns (bytes memory _returndata);
}

File 12 of 54 : INonfungiblePositionManager.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;
pragma abicoder v2;

import {IPoolInitializer} from './IPoolInitializer.sol';
import {IPeripheryPayments} from './IPeripheryPayments.sol';
import {IPeripheryImmutableState} from './IPeripheryImmutableState.sol';
import {PoolAddress} from '../libraries/PoolAddress.sol';

import {IERC721} from '@openzeppelin/contracts/token/ERC721/IERC721.sol';
import {IERC721Metadata} from '@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol';
import {IERC721Enumerable} from '@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol';

import {IPeripheryErrors} from './IPeripheryErrors.sol';

/// @title Non-fungible token for positions
/// @notice Wraps Uniswap V3 positions in a non-fungible token interface which allows for them to be transferred
/// and authorized.
interface INonfungiblePositionManager is
    IPeripheryErrors,
    IPoolInitializer,
    IPeripheryPayments,
    IPeripheryImmutableState,
    IERC721,
    IERC721Metadata,
    IERC721Enumerable
{
    /// @notice Emitted when liquidity is increased for a position NFT
    /// @dev Also emitted when a token is minted
    /// @param tokenId The ID of the token for which liquidity was increased
    /// @param liquidity The amount by which liquidity for the NFT position was increased
    /// @param amount0 The amount of token0 that was paid for the increase in liquidity
    /// @param amount1 The amount of token1 that was paid for the increase in liquidity
    event IncreaseLiquidity(uint256 indexed tokenId, uint128 liquidity, uint256 amount0, uint256 amount1);
    /// @notice Emitted when liquidity is decreased for a position NFT
    /// @param tokenId The ID of the token for which liquidity was decreased
    /// @param liquidity The amount by which liquidity for the NFT position was decreased
    /// @param amount0 The amount of token0 that was accounted for the decrease in liquidity
    /// @param amount1 The amount of token1 that was accounted for the decrease in liquidity
    event DecreaseLiquidity(uint256 indexed tokenId, uint128 liquidity, uint256 amount0, uint256 amount1);
    /// @notice Emitted when tokens are collected for a position NFT
    /// @dev The amounts reported may not be exactly equivalent to the amounts transferred, due to rounding behavior
    /// @param tokenId The ID of the token for which underlying tokens were collected
    /// @param recipient The address of the account that received the collected tokens
    /// @param amount0 The amount of token0 owed to the position that was collected
    /// @param amount1 The amount of token1 owed to the position that was collected
    event Collect(uint256 indexed tokenId, address recipient, uint256 amount0, uint256 amount1);

    /// @notice Returns the position information associated with a given token ID.
    /// @dev Throws if the token ID is not valid.
    /// @param tokenId The ID of the token that represents the position
    /// @return token0 The address of the token0 for a specific pool
    /// @return token1 The address of the token1 for a specific pool
    /// @return tickSpacing The tickSpacing the pool
    /// @return tickLower The lower end of the tick range for the position
    /// @return tickUpper The higher end of the tick range for the position
    /// @return liquidity The liquidity of the position
    /// @return feeGrowthInside0LastX128 The fee growth of token0 as of the last action on the individual position
    /// @return feeGrowthInside1LastX128 The fee growth of token1 as of the last action on the individual position
    /// @return tokensOwed0 The uncollected amount of token0 owed to the position as of the last computation
    /// @return tokensOwed1 The uncollected amount of token1 owed to the position as of the last computation
    function positions(
        uint256 tokenId
    )
        external
        view
        returns (
            address token0,
            address token1,
            int24 tickSpacing,
            int24 tickLower,
            int24 tickUpper,
            uint128 liquidity,
            uint256 feeGrowthInside0LastX128,
            uint256 feeGrowthInside1LastX128,
            uint128 tokensOwed0,
            uint128 tokensOwed1
        );

    struct MintParams {
        address token0;
        address token1;
        int24 tickSpacing;
        int24 tickLower;
        int24 tickUpper;
        uint256 amount0Desired;
        uint256 amount1Desired;
        uint256 amount0Min;
        uint256 amount1Min;
        address recipient;
        uint256 deadline;
    }

    /// @notice Creates a new position wrapped in a NFT
    /// @dev Call this when the pool does exist and is initialized. Note that if the pool is created but not initialized
    /// a method does not exist, i.e. the pool is assumed to be initialized.
    /// @param params The params necessary to mint a position, encoded as `MintParams` in calldata
    /// @return tokenId The ID of the token that represents the minted position
    /// @return liquidity The amount of liquidity for this position
    /// @return amount0 The amount of token0
    /// @return amount1 The amount of token1
    function mint(
        MintParams calldata params
    ) external payable returns (uint256 tokenId, uint128 liquidity, uint256 amount0, uint256 amount1);

    struct IncreaseLiquidityParams {
        uint256 tokenId;
        uint256 amount0Desired;
        uint256 amount1Desired;
        uint256 amount0Min;
        uint256 amount1Min;
        uint256 deadline;
    }

    /// @notice Increases the amount of liquidity in a position, with tokens paid by the `msg.sender`
    /// @param params tokenId The ID of the token for which liquidity is being increased,
    /// amount0Desired The desired amount of token0 to be spent,
    /// amount1Desired The desired amount of token1 to be spent,
    /// amount0Min The minimum amount of token0 to spend, which serves as a slippage check,
    /// amount1Min The minimum amount of token1 to spend, which serves as a slippage check,
    /// deadline The time by which the transaction must be included to effect the change
    /// @return liquidity The new liquidity amount as a result of the increase
    /// @return amount0 The amount of token0 to acheive resulting liquidity
    /// @return amount1 The amount of token1 to acheive resulting liquidity
    function increaseLiquidity(
        IncreaseLiquidityParams calldata params
    ) external payable returns (uint128 liquidity, uint256 amount0, uint256 amount1);

    struct DecreaseLiquidityParams {
        uint256 tokenId;
        uint128 liquidity;
        uint256 amount0Min;
        uint256 amount1Min;
        uint256 deadline;
    }

    /// @notice Decreases the amount of liquidity in a position and accounts it to the position
    /// @param params tokenId The ID of the token for which liquidity is being decreased,
    /// amount The amount by which liquidity will be decreased,
    /// amount0Min The minimum amount of token0 that should be accounted for the burned liquidity,
    /// amount1Min The minimum amount of token1 that should be accounted for the burned liquidity,
    /// deadline The time by which the transaction must be included to effect the change
    /// @return amount0 The amount of token0 accounted to the position's tokens owed
    /// @return amount1 The amount of token1 accounted to the position's tokens owed
    function decreaseLiquidity(
        DecreaseLiquidityParams calldata params
    ) external payable returns (uint256 amount0, uint256 amount1);

    struct CollectParams {
        uint256 tokenId;
        address recipient;
        uint128 amount0Max;
        uint128 amount1Max;
    }

    /// @notice Collects up to a maximum amount of fees owed to a specific position to the recipient
    /// @param params tokenId The ID of the NFT for which tokens are being collected,
    /// recipient The account that should receive the tokens,
    /// amount0Max The maximum amount of token0 to collect,
    /// amount1Max The maximum amount of token1 to collect
    /// @return amount0 The amount of fees collected in token0
    /// @return amount1 The amount of fees collected in token1
    function collect(CollectParams calldata params) external payable returns (uint256 amount0, uint256 amount1);

    /// @notice Burns a token ID, which deletes it from the NFT contract. The token must have 0 liquidity and all tokens
    /// must be collected first.
    /// @param tokenId The ID of the token that is being burned
    function burn(uint256 tokenId) external payable;

    /// @notice Claims gauge rewards from liquidity incentives for a specific tokenId
    /// @param tokenId The ID of the token to claim rewards from
    /// @param tokens an array of reward tokens to claim
    function getReward(uint256 tokenId, address[] calldata tokens) external;
}

File 13 of 54 : IFeeCollector.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;

import {IShadowV3Pool} from "../../core/interfaces/IShadowV3Pool.sol";

interface IFeeCollector {
    /// @notice Emitted when the treasury address is changed.
    /// @param oldTreasury The previous treasury address.
    /// @param newTreasury The new treasury address.
    event TreasuryChanged(address oldTreasury, address newTreasury);

    /// @notice Emitted when the treasury fees value is changed.
    /// @param oldTreasuryFees The previous value of the treasury fees.
    /// @param newTreasuryFees The new value of the treasury fees.
    event TreasuryFeesChanged(uint256 oldTreasuryFees, uint256 newTreasuryFees);

    /// @notice Emitted when protocol fees are collected from a pool and distributed to the fee distributor and treasury.
    /// @param pool The address of the pool from which the fees were collected.
    /// @param feeDistAmount0 The amount of fee tokens (token 0) distributed to the fee distributor.
    /// @param feeDistAmount1 The amount of fee tokens (token 1) distributed to the fee distributor.
    /// @param treasuryAmount0 The amount of fee tokens (token 0) allocated to the treasury.
    /// @param treasuryAmount1 The amount of fee tokens (token 1) allocated to the treasury.
    event FeesCollected(
        address pool, uint256 feeDistAmount0, uint256 feeDistAmount1, uint256 treasuryAmount0, uint256 treasuryAmount1
    );

    /// @notice Returns the treasury address.
    function treasury() external returns (address);

    /// @notice Returns the treasury fees ratio.
    function treasuryFees() external returns (uint256);

    /// @notice Sets the treasury address to a new value.
    /// @param newTreasury The new address to set as the treasury.
    function setTreasury(address newTreasury) external;

    /// @notice Sets the value of treasury fees to a new amount.
    /// @param _treasuryFees The new amount of treasury fees to be set.
    function setTreasuryFees(uint256 _treasuryFees) external;

    /// @notice Collects protocol fees from a specified pool and distributes them to the fee distributor and treasury.
    /// @param pool The pool from which to collect the protocol fees.
    function collectProtocolFees(address pool) external;
}

File 14 of 54 : FullMath.sol
// 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++;
            }
        }
    }
}

File 15 of 54 : IShadowV3Pool.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

import {IShadowV3PoolImmutables} from "./pool/IShadowV3PoolImmutables.sol";
import {IShadowV3PoolState} from "./pool/IShadowV3PoolState.sol";
import {IShadowV3PoolDerivedState} from "./pool/IShadowV3PoolDerivedState.sol";
import {IShadowV3PoolActions} from "./pool/IShadowV3PoolActions.sol";
import {IShadowV3PoolOwnerActions} from "./pool/IShadowV3PoolOwnerActions.sol";
import {IShadowV3PoolErrors} from "./pool/IShadowV3PoolErrors.sol";
import {IShadowV3PoolEvents} from "./pool/IShadowV3PoolEvents.sol";

/// @title The interface for a Shadow V3 Pool
/// @notice A Shadow 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 IShadowV3Pool is
    IShadowV3PoolImmutables,
    IShadowV3PoolState,
    IShadowV3PoolDerivedState,
    IShadowV3PoolActions,
    IShadowV3PoolOwnerActions,
    IShadowV3PoolErrors,
    IShadowV3PoolEvents
{
    /// @notice if a new period, advance on interaction
    function _advancePeriod() external;

    /// @notice Get the index of the last period in the pool
    /// @return The index of the last period
    function lastPeriod() external view returns (uint256);

    /// @notice allows reading arbitrary storage slots
    function readStorage(bytes32[] calldata slots) external view returns (bytes32[] memory returnData);
}

File 16 of 54 : GaugeV3Storage.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;

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

import {IShadowV3Pool} from "contracts/CL/core/interfaces/IShadowV3Pool.sol";

library GaugeV3Storage {
    using EnumerableSet for EnumerableSet.AddressSet;

    /// @dev keccak256(abi.encode(uint256(keccak256("gaugeV3.storage")) - 1)) & ~bytes32(uint256(0xff));
    bytes32 public constant GAUGEV3_STORAGE_LOCATION =
        0xddab91076ea92d6a766cefd001b0cf5f73830986b100aa9c6fa6286e6b0a7300;

    /// @custom꞉storage‑location erc7201꞉gaugeV3.storage
    struct GaugeV3State {
        bool _unlocked;
        uint256 firstPeriod;
        IShadowV3Pool pool;
        /// @inheritdoc IGaugeV3
        address nfpManager;
        EnumerableSet.AddressSet nfpManagers;
        /// @inheritdoc IGaugeV3
        mapping(uint256 period => mapping(address token => uint256)) tokenTotalSupplyByPeriod;
        mapping(uint256 period => mapping(bytes32 positionHash => uint256)) periodAmountsWrittenVersion;
        mapping(uint256 period => mapping(bytes32 positionHash => uint256)) periodNfpSecondsX96;
        /// @inheritdoc IGaugeV3
        mapping(uint256 period => mapping(bytes32 positionHash => mapping(address rewardToken => uint256)))
            periodClaimedAmount;
        /// @inheritdoc IGaugeV3
        mapping(address token => mapping(bytes32 positionHash => uint256 period)) lastClaimByToken;
        mapping(uint256 period => uint160) periodEndSecondsPerLiquidityCumulativeX128;
        mapping(uint256 period => bool) usePoolData;
        mapping(uint256 period => uint256) periodEndVerion;
        EnumerableSet.AddressSet rewards;
        uint256 lastCardinality;
        uint256 cachedPoolLastPeriod;
    }

    /// @dev Return state storage struct for reading and writing
    function getStorage() internal pure returns (GaugeV3State storage $) {
        assembly {
            $.slot := GAUGEV3_STORAGE_LOCATION
        }
    }
}

File 17 of 54 : PoolStorage.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;

struct Slot0 {
    /// @dev the current price
    uint160 sqrtPriceX96;
    /// @dev the current tick
    int24 tick;
    /// @dev the most-recently updated index of the observations array
    uint16 observationIndex;
    /// @dev the current maximum number of observations that are being stored
    uint16 observationCardinality;
    /// @dev the next maximum number of observations to store, triggered in observations.write
    uint16 observationCardinalityNext;
    /// @dev the current protocol fee as a percentage of the swap fee taken on withdrawal
    /// @dev represented as an integer denominator (1/x)%
    uint24 feeProtocol;
    /// @dev whether the pool is locked
    bool unlocked;
}

struct Observation {
    /// @dev the block timestamp of the observation
    uint32 blockTimestamp;
    /// @dev the tick accumulator, i.e. tick * time elapsed since the pool was first initialized
    int56 tickCumulative;
    /// @dev the seconds per liquidity, i.e. seconds elapsed / max(1, liquidity) since the pool was first initialized
    uint160 secondsPerLiquidityCumulativeX128;
    /// @dev whether or not the observation is initialized
    bool initialized;
}

struct RewardInfo {
    /// @dev used to account for changes in the deposit amount
    int256 secondsDebtX96;
    /// @dev used to check if starting seconds have already been written
    bool initialized;
    /// @dev used to account for changes in secondsPerLiquidity
    int160 secondsPerLiquidityPeriodStartX128;
}

/// @dev info stored for each user's position
struct PositionInfo {
    /// @dev the amount of liquidity owned by this position
    uint128 liquidity;
    /// @dev fee growth per unit of liquidity as of the last update to liquidity or fees owed
    uint256 feeGrowthInside0LastX128;
    uint256 feeGrowthInside1LastX128;
    /// @dev the fees owed to the position owner in token0/token1
    uint128 tokensOwed0;
    uint128 tokensOwed1;
    mapping(uint256 => RewardInfo) periodRewardInfo;
}

/// @dev info stored for each initialized individual tick
struct TickInfo {
    /// @dev the total position liquidity that references this tick
    uint128 liquidityGross;
    /// @dev amount of net liquidity added (subtracted) when tick is crossed from left to right (right to left),
    int128 liquidityNet;
    /// @dev fee growth per unit of liquidity on the _other_ side of this tick (relative to the current tick)
    /// @dev only has relative meaning, not absolute — the value depends on when the tick is initialized
    uint256 feeGrowthOutside0X128;
    uint256 feeGrowthOutside1X128;
    /// @dev the cumulative tick value on the other side of the tick
    int56 tickCumulativeOutside;
    /// @dev the seconds per unit of liquidity on the _other_ side of this tick (relative to the current tick)
    /// @dev only has relative meaning, not absolute — the value depends on when the tick is initialized
    uint160 secondsPerLiquidityOutsideX128;
    /// @dev the seconds spent on the other side of the tick (relative to the current tick)
    /// @dev only has relative meaning, not absolute — the value depends on when the tick is initialized
    uint32 secondsOutside;
    /// @dev true iff the tick is initialized, i.e. the value is exactly equivalent to the expression liquidityGross != 0
    /// @dev these 8 bits are set to prevent fresh sstores when crossing newly initialized ticks
    bool initialized;
    /// @dev secondsPerLiquidityOutsideX128 separated into periods, placed here to preserve struct slots
    mapping(uint256 => uint256) periodSecondsPerLiquidityOutsideX128;
}

/// @dev info stored for each period
struct PeriodInfo {
    uint32 previousPeriod;
    int24 startTick;
    int24 lastTick;
    uint160 endSecondsPerLiquidityPeriodX128;
}

/// @dev accumulated protocol fees in token0/token1 units
struct ProtocolFees {
    uint128 token0;
    uint128 token1;
}

/// @dev Position period and liquidity
struct PositionCheckpoint {
    uint256 period;
    uint256 liquidity;
}

library PoolStorage {
    /// @dev keccak256(abi.encode(uint256(keccak256("pool.storage")) - 1)) & ~bytes32(uint256(0xff));
    bytes32 public constant POOL_STORAGE_LOCATION = 0xf047b0c59244a0faf8e48cb6b6fde518e6717176152b6dd953628cd9dccb2800;

    /// @custom꞉storage‑location erc7201꞉pool.storage
    struct PoolState {
        Slot0 slot0;
        uint24 fee;
        uint256 feeGrowthGlobal0X128;
        uint256 feeGrowthGlobal1X128;
        uint256 grossFeeGrowthGlobal0X128;
        uint256 grossFeeGrowthGlobal1X128;
        ProtocolFees protocolFees;
        uint128 liquidity;
        mapping(int24 => TickInfo) _ticks;
        mapping(int16 => uint256) tickBitmap;
        mapping(bytes32 => PositionInfo) positions;
        Observation[65535] observations;
        mapping(uint256 => PeriodInfo) periods;
        uint256 lastPeriod;
        mapping(bytes32 => PositionCheckpoint[]) positionCheckpoints;
        bool initialized;
        address nfpManager;
    }

    /// @dev Return state storage struct for reading and writing
    function getStorage() internal pure returns (PoolState storage $) {
        assembly {
            $.slot := POOL_STORAGE_LOCATION
        }
    }
}

File 18 of 54 : PoolStorageOld.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.26;

struct Slot0 {
    /// @dev the current price
    uint160 sqrtPriceX96;
    /// @dev the current tick
    int24 tick;
    /// @dev the most-recently updated index of the observations array
    uint16 observationIndex;
    /// @dev the current maximum number of observations that are being stored
    uint16 observationCardinality;
    /// @dev the next maximum number of observations to store, triggered in observations.write
    uint16 observationCardinalityNext;
    /// @dev the current protocol fee as a percentage of the swap fee taken on withdrawal
    /// @dev represented as an integer denominator (1/x)%
    uint8 feeProtocol;
    /// @dev whether the pool is locked
    bool unlocked;
}

struct Observation {
    /// @dev the block timestamp of the observation
    uint32 blockTimestamp;
    /// @dev the tick accumulator, i.e. tick * time elapsed since the pool was first initialized
    int56 tickCumulative;
    /// @dev the seconds per liquidity, i.e. seconds elapsed / max(1, liquidity) since the pool was first initialized
    uint160 secondsPerLiquidityCumulativeX128;
    /// @dev whether or not the observation is initialized
    bool initialized;
}

struct RewardInfo {
    /// @dev used to account for changes in the deposit amount
    int256 secondsDebtX96;
    /// @dev used to check if starting seconds have already been written
    bool initialized;
    /// @dev used to account for changes in secondsPerLiquidity
    int160 secondsPerLiquidityPeriodStartX128;
}

/// @dev info stored for each user's position
struct PositionInfo {
    /// @dev the amount of liquidity owned by this position
    uint128 liquidity;
    /// @dev fee growth per unit of liquidity as of the last update to liquidity or fees owed
    uint256 feeGrowthInside0LastX128;
    uint256 feeGrowthInside1LastX128;
    /// @dev the fees owed to the position owner in token0/token1
    uint128 tokensOwed0;
    uint128 tokensOwed1;
    mapping(uint256 => RewardInfo) periodRewardInfo;
}

/// @dev info stored for each initialized individual tick
struct TickInfo {
    /// @dev the total position liquidity that references this tick
    uint128 liquidityGross;
    /// @dev amount of net liquidity added (subtracted) when tick is crossed from left to right (right to left),
    int128 liquidityNet;
    /// @dev fee growth per unit of liquidity on the _other_ side of this tick (relative to the current tick)
    /// @dev only has relative meaning, not absolute — the value depends on when the tick is initialized
    uint256 feeGrowthOutside0X128;
    uint256 feeGrowthOutside1X128;
    /// @dev the cumulative tick value on the other side of the tick
    int56 tickCumulativeOutside;
    /// @dev the seconds per unit of liquidity on the _other_ side of this tick (relative to the current tick)
    /// @dev only has relative meaning, not absolute — the value depends on when the tick is initialized
    uint160 secondsPerLiquidityOutsideX128;
    /// @dev the seconds spent on the other side of the tick (relative to the current tick)
    /// @dev only has relative meaning, not absolute — the value depends on when the tick is initialized
    uint32 secondsOutside;
    /// @dev true iff the tick is initialized, i.e. the value is exactly equivalent to the expression liquidityGross != 0
    /// @dev these 8 bits are set to prevent fresh sstores when crossing newly initialized ticks
    bool initialized;
    /// @dev secondsPerLiquidityOutsideX128 separated into periods, placed here to preserve struct slots
    mapping(uint256 => uint256) periodSecondsPerLiquidityOutsideX128;
}

/// @dev info stored for each period
struct PeriodInfo {
    uint32 previousPeriod;
    int24 startTick;
    int24 lastTick;
    uint160 endSecondsPerLiquidityPeriodX128;
}

/// @dev accumulated protocol fees in token0/token1 units
struct ProtocolFees {
    uint128 token0;
    uint128 token1;
}

/// @dev Position period and liquidity
struct PositionCheckpoint {
    uint256 period;
    uint256 liquidity;
}

library PoolStorageOld {
    /// @dev keccak256(abi.encode(uint256(keccak256("pool.storage")) - 1)) & ~bytes32(uint256(0xff));
    bytes32 public constant POOL_STORAGE_LOCATION = 0xf047b0c59244a0faf8e48cb6b6fde518e6717176152b6dd953628cd9dccb2800;

    /// @custom꞉storage‑location erc7201꞉pool.storage
    struct PoolState {
        Slot0 slot0;
        uint24 fee;
        uint256 feeGrowthGlobal0X128;
        uint256 feeGrowthGlobal1X128;
        ProtocolFees protocolFees;
        uint128 liquidity;
        mapping(int24 => TickInfo) _ticks;
        mapping(int16 => uint256) tickBitmap;
        mapping(bytes32 => PositionInfo) positions;
        Observation[65535] observations;
        mapping(uint256 => PeriodInfo) periods;
        uint256 lastPeriod;
        mapping(bytes32 => PositionCheckpoint[]) positionCheckpoints;
        bool initialized;
        address nfpManager;
    }

    /// @dev Return state storage struct for reading and writing
    function getStorage() internal pure returns (PoolState storage $) {
        assembly {
            $.slot := POOL_STORAGE_LOCATION
        }
    }

    function readStorage(bytes32 pointer) internal view returns (bytes32) {}
}

File 19 of 54 : Oracle.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;

import {PoolStorage, Observation, TickInfo, Slot0} from './PoolStorage.sol';

/// @title Oracle
/// @notice Provides price and liquidity data useful for a wide variety of system designs
/// @dev Instances of stored oracle data, "observations", are collected in the oracle array
/// Every pool is initialized with an oracle array length of 1. Anyone can pay the SSTOREs to increase the
/// maximum length of the oracle array. New slots will be added when the array is fully populated.
/// Observations are overwritten when the full length of the oracle array is populated.
/// The most recent observation is available, independent of the length of the oracle array, by passing 0 to observe()
library Oracle {
    error I();
    error OLD();

    /// @notice Transforms a previous observation into a new observation, given the passage of time and the current tick and liquidity values
    /// @dev blockTimestamp _must_ be chronologically equal to or greater than last.blockTimestamp, safe for 0 or 1 overflows
    /// @param last The specified observation to be transformed
    /// @param blockTimestamp The timestamp of the new observation
    /// @param tick The active tick at the time of the new observation
    /// @param liquidity The total in-range liquidity at the time of the new observation
    /// @return Observation The newly populated observation
    function transform(
        Observation memory last,
        uint32 blockTimestamp,
        int24 tick,
        uint128 liquidity
    ) private pure returns (Observation memory) {
        unchecked {
            uint32 delta = blockTimestamp - last.blockTimestamp;
            return
                Observation({
                    blockTimestamp: blockTimestamp,
                    tickCumulative: last.tickCumulative + int56(tick) * int56(uint56(delta)),
                    secondsPerLiquidityCumulativeX128: last.secondsPerLiquidityCumulativeX128 +
                        ((uint160(delta) << 128) / (liquidity > 0 ? liquidity : 1)),
                    initialized: true
                });
        }
    }

    /// @notice Initialize the oracle array by writing the first slot. Called once for the lifecycle of the observations array
    /// @param self The stored oracle array
    /// @param time The time of the oracle initialization, via block.timestamp truncated to uint32
    /// @return cardinality The number of populated elements in the oracle array
    /// @return cardinalityNext The new length of the oracle array, independent of population
    function initialize(
        Observation[65535] storage self,
        uint32 time
    ) internal returns (uint16 cardinality, uint16 cardinalityNext) {
        self[0] = Observation({
            blockTimestamp: time,
            tickCumulative: 0,
            secondsPerLiquidityCumulativeX128: 0,
            initialized: true
        });
        return (1, 1);
    }

    /// @notice Writes an oracle observation to the array
    /// @dev Writable at most once per block. Index represents the most recently written element. cardinality and index must be tracked externally.
    /// If the index is at the end of the allowable array length (according to cardinality), and the next cardinality
    /// is greater than the current one, cardinality may be increased. This restriction is created to preserve ordering.
    /// @param self The stored oracle array
    /// @param index The index of the observation that was most recently written to the observations array
    /// @param blockTimestamp The timestamp of the new observation
    /// @param tick The active tick at the time of the new observation
    /// @param liquidity The total in-range liquidity at the time of the new observation
    /// @param cardinality The number of populated elements in the oracle array
    /// @param cardinalityNext The new length of the oracle array, independent of population
    /// @return indexUpdated The new index of the most recently written element in the oracle array
    /// @return cardinalityUpdated The new cardinality of the oracle array
    function write(
        Observation[65535] storage self,
        uint16 index,
        uint32 blockTimestamp,
        int24 tick,
        uint128 liquidity,
        uint16 cardinality,
        uint16 cardinalityNext
    ) internal returns (uint16 indexUpdated, uint16 cardinalityUpdated) {
        unchecked {
            Observation memory last = self[index];

            /// @dev early return if we've already written an observation this block
            if (last.blockTimestamp == blockTimestamp) return (index, cardinality);

            /// @dev if the conditions are right, we can bump the cardinality
            if (cardinalityNext > cardinality && index == (cardinality - 1)) {
                cardinalityUpdated = cardinalityNext;
            } else {
                cardinalityUpdated = cardinality;
            }

            indexUpdated = (index + 1) % cardinalityUpdated;
            self[indexUpdated] = transform(last, blockTimestamp, tick, liquidity);
        }
    }

    /// @notice Prepares the oracle array to store up to `next` observations
    /// @param self The stored oracle array
    /// @param current The current next cardinality of the oracle array
    /// @param next The proposed next cardinality which will be populated in the oracle array
    /// @return next The next cardinality which will be populated in the oracle array
    function grow(Observation[65535] storage self, uint16 current, uint16 next) internal returns (uint16) {
        unchecked {
            if (current <= 0) revert I();
            /// @dev no-op if the passed next value isn't greater than the current next value
            if (next <= current) return current;
            /// @dev store in each slot to prevent fresh SSTOREs in swaps
            /// @dev this data will not be used because the initialized boolean is still false
            for (uint16 i = current; i < next; i++) self[i].blockTimestamp = 1;
            return next;
        }
    }

    /// @notice comparator for 32-bit timestamps
    /// @dev safe for 0 or 1 overflows, a and b _must_ be chronologically before or equal to time
    /// @param time A timestamp truncated to 32 bits
    /// @param a A comparison timestamp from which to determine the relative position of `time`
    /// @param b From which to determine the relative position of `time`
    /// @return Whether `a` is chronologically <= `b`
    function lte(uint32 time, uint32 a, uint32 b) private pure returns (bool) {
        unchecked {
            /// @dev if there hasn't been overflow, no need to adjust
            if (a <= time && b <= time) return a <= b;

            uint256 aAdjusted = a > time ? a : a + 2 ** 32;
            uint256 bAdjusted = b > time ? b : b + 2 ** 32;

            return aAdjusted <= bAdjusted;
        }
    }

    /// @notice Fetches the observations beforeOrAt and atOrAfter a target, i.e. where [beforeOrAt, atOrAfter] is satisfied.
    /// The result may be the same observation, or adjacent observations.
    /// @dev The answer must be contained in the array, used when the target is located within the stored observation
    /// boundaries: older than the most recent observation and younger, or the same age as, the oldest observation
    /// @param self The stored oracle array
    /// @param time The current block.timestamp
    /// @param target The timestamp at which the reserved observation should be for
    /// @param index The index of the observation that was most recently written to the observations array
    /// @param cardinality The number of populated elements in the oracle array
    /// @return beforeOrAt The observation recorded before, or at, the target
    /// @return atOrAfter The observation recorded at, or after, the target
    function binarySearch(
        Observation[65535] storage self,
        uint32 time,
        uint32 target,
        uint16 index,
        uint16 cardinality
    ) private view returns (Observation memory beforeOrAt, Observation memory atOrAfter) {
        unchecked {
            /// @dev oldest observation
            uint256 l = (index + 1) % cardinality; 
            /// @dev newest observation
            uint256 r = l + cardinality - 1; 
            uint256 i;
            while (true) {
                i = (l + r) / 2;

                beforeOrAt = self[i % cardinality];

                /// @dev we've landed on an uninitialized tick, keep searching higher (more recently)
                if (!beforeOrAt.initialized) {
                    l = i + 1;
                    continue;
                }

                atOrAfter = self[(i + 1) % cardinality];

                bool targetAtOrAfter = lte(time, beforeOrAt.blockTimestamp, target);

                /// @dev check if we've found the answer!
                if (targetAtOrAfter && lte(time, target, atOrAfter.blockTimestamp)) break;

                if (!targetAtOrAfter) r = i - 1;
                else l = i + 1;
            }
        }
    }

    /// @notice Fetches the observations beforeOrAt and atOrAfter a given target, i.e. where [beforeOrAt, atOrAfter] is satisfied
    /// @dev Assumes there is at least 1 initialized observation.
    /// Used by observeSingle() to compute the counterfactual accumulator values as of a given block timestamp.
    /// @param self The stored oracle array
    /// @param time The current block.timestamp
    /// @param target The timestamp at which the reserved observation should be for
    /// @param tick The active tick at the time of the returned or simulated observation
    /// @param index The index of the observation that was most recently written to the observations array
    /// @param liquidity The total pool liquidity at the time of the call
    /// @param cardinality The number of populated elements in the oracle array
    /// @return beforeOrAt The observation which occurred at, or before, the given timestamp
    /// @return atOrAfter The observation which occurred at, or after, the given timestamp
    function getSurroundingObservations(
        Observation[65535] storage self,
        uint32 time,
        uint32 target,
        int24 tick,
        uint16 index,
        uint128 liquidity,
        uint16 cardinality
    ) private view returns (Observation memory beforeOrAt, Observation memory atOrAfter) {
        unchecked {
            /// @dev optimistically set before to the newest observation
            beforeOrAt = self[index];

            /// @dev if the target is chronologically at or after the newest observation, we can early return
            if (lte(time, beforeOrAt.blockTimestamp, target)) {
                if (beforeOrAt.blockTimestamp == target) {
                    /// @dev if newest observation equals target, we're in the same block, so we can ignore atOrAfter
                    return (beforeOrAt, atOrAfter);
                } else {
                    /// @dev otherwise, we need to transform
                    return (beforeOrAt, transform(beforeOrAt, target, tick, liquidity));
                }
            }

            /// @dev now, set before to the oldest observation
            beforeOrAt = self[(index + 1) % cardinality];
            if (!beforeOrAt.initialized) beforeOrAt = self[0];

            /// @dev ensure that the target is chronologically at or after the oldest observation
            if (!lte(time, beforeOrAt.blockTimestamp, target)) revert OLD();

            /// @dev if we've reached this point, we have to binary search
            return binarySearch(self, time, target, index, cardinality);
        }
    }

    /// @dev Reverts if an observation at or before the desired observation timestamp does not exist.
    /// 0 may be passed as `secondsAgo' to return the current cumulative values.
    /// If called with a timestamp falling between two observations, returns the counterfactual accumulator values
    /// at exactly the timestamp between the two observations.
    /// @param self The stored oracle array
    /// @param time The current block timestamp
    /// @param secondsAgo The amount of time to look back, in seconds, at which point to return an observation
    /// @param tick The current tick
    /// @param index The index of the observation that was most recently written to the observations array
    /// @param liquidity The current in-range pool liquidity
    /// @param cardinality The number of populated elements in the oracle array
    /// @return tickCumulative The tick * time elapsed since the pool was first initialized, as of `secondsAgo`
    /// @return secondsPerLiquidityCumulativeX128 The time elapsed / max(1, liquidity) since the pool was first initialized, as of `secondsAgo`
    function observeSingle(
        Observation[65535] storage self,
        uint32 time,
        uint32 secondsAgo,
        int24 tick,
        uint16 index,
        uint128 liquidity,
        uint16 cardinality
    ) internal view returns (int56 tickCumulative, uint160 secondsPerLiquidityCumulativeX128) {
        unchecked {
            if (secondsAgo == 0) {
                Observation memory last = self[index];
                if (last.blockTimestamp != time) last = transform(last, time, tick, liquidity);
                return (last.tickCumulative, last.secondsPerLiquidityCumulativeX128);
            }

            uint32 target = time - secondsAgo;

            (Observation memory beforeOrAt, Observation memory atOrAfter) = getSurroundingObservations(
                self,
                time,
                target,
                tick,
                index,
                liquidity,
                cardinality
            );

            if (target == beforeOrAt.blockTimestamp) {
                /// @dev we're at the left boundary
                return (beforeOrAt.tickCumulative, beforeOrAt.secondsPerLiquidityCumulativeX128);
            } else if (target == atOrAfter.blockTimestamp) {
                /// @dev we're at the right boundary
                return (atOrAfter.tickCumulative, atOrAfter.secondsPerLiquidityCumulativeX128);
            } else {
                /// @dev we're in the middle
                uint32 observationTimeDelta = atOrAfter.blockTimestamp - beforeOrAt.blockTimestamp;
                uint32 targetDelta = target - beforeOrAt.blockTimestamp;
                return (
                    beforeOrAt.tickCumulative +
                        ((atOrAfter.tickCumulative - beforeOrAt.tickCumulative) / int56(uint56(observationTimeDelta))) *
                        int56(uint56(targetDelta)),
                    beforeOrAt.secondsPerLiquidityCumulativeX128 +
                        uint160(
                            (uint256(
                                atOrAfter.secondsPerLiquidityCumulativeX128 -
                                    beforeOrAt.secondsPerLiquidityCumulativeX128
                            ) * targetDelta) / observationTimeDelta
                        )
                );
            }
        }
    }

    /// @notice Returns the accumulator values as of each time seconds ago from the given time in the array of `secondsAgos`
    /// @dev Reverts if `secondsAgos` > oldest observation
    /// @param self The stored oracle array
    /// @param time The current block.timestamp
    /// @param secondsAgos Each amount of time to look back, in seconds, at which point to return an observation
    /// @param tick The current tick
    /// @param index The index of the observation that was most recently written to the observations array
    /// @param liquidity The current in-range pool liquidity
    /// @param cardinality The number of populated elements in the oracle array
    /// @return tickCumulatives The tick * time elapsed since the pool was first initialized, as of each `secondsAgo`
    /// @return secondsPerLiquidityCumulativeX128s The cumulative seconds / max(1, liquidity) since the pool was first initialized, as of each `secondsAgo`
    function observe(
        Observation[65535] storage self,
        uint32 time,
        uint32[] memory secondsAgos,
        int24 tick,
        uint16 index,
        uint128 liquidity,
        uint16 cardinality
    ) internal view returns (int56[] memory tickCumulatives, uint160[] memory secondsPerLiquidityCumulativeX128s) {
        unchecked {
            if (cardinality <= 0) revert I();

            tickCumulatives = new int56[](secondsAgos.length);
            secondsPerLiquidityCumulativeX128s = new uint160[](secondsAgos.length);
            for (uint256 i = 0; i < secondsAgos.length; i++) {
                (tickCumulatives[i], secondsPerLiquidityCumulativeX128s[i]) = observeSingle(
                    self,
                    time,
                    secondsAgos[i],
                    tick,
                    index,
                    liquidity,
                    cardinality
                );
            }
        }
    }

    function newPeriod(
        Observation[65535] storage self,
        uint16 index,
        uint256 period
    ) external returns (uint160 secondsPerLiquidityCumulativeX128) {
        Observation memory last = self[index];
        PoolStorage.PoolState storage $ = PoolStorage.getStorage();

        unchecked {
            uint32 delta = uint32(period) * 1 weeks - 1 - last.blockTimestamp;

            secondsPerLiquidityCumulativeX128 =
                last.secondsPerLiquidityCumulativeX128 +
                ((uint160(delta) << 128) / ($.liquidity > 0 ? $.liquidity : 1));

            self[index] = Observation({
                blockTimestamp: uint32(period) * 1 weeks - 1,
                tickCumulative: last.tickCumulative + int56($.slot0.tick) * int56(uint56(delta)),
                secondsPerLiquidityCumulativeX128: secondsPerLiquidityCumulativeX128,
                initialized: last.initialized
            });
        }
    }

    struct SnapShot {
        int56 tickCumulativeLower;
        int56 tickCumulativeUpper;
        uint160 secondsPerLiquidityOutsideLowerX128;
        uint160 secondsPerLiquidityOutsideUpperX128;
        uint32 secondsOutsideLower;
        uint32 secondsOutsideUpper;
    }

    struct SnapshotCumulativesInsideCache {
        uint32 time;
        int56 tickCumulative;
        uint160 secondsPerLiquidityCumulativeX128;
    }

    /// @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. Boosted data is only valid if it's within the same period
    /// @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,
        uint32 _blockTimestamp
    ) external view returns (int56 tickCumulativeInside, uint160 secondsPerLiquidityInsideX128, uint32 secondsInside) {
        PoolStorage.PoolState storage $ = PoolStorage.getStorage();

        TickInfo storage lower = $._ticks[tickLower];
        TickInfo storage upper = $._ticks[tickUpper];

        SnapShot memory snapshot;

        bool initializedLower;
        (
            snapshot.tickCumulativeLower,
            snapshot.secondsPerLiquidityOutsideLowerX128,
            snapshot.secondsOutsideLower,
            initializedLower
        ) = (
            lower.tickCumulativeOutside,
            lower.secondsPerLiquidityOutsideX128,
            lower.secondsOutside,
            lower.initialized
        );
        require(initializedLower);

        bool initializedUpper;
        (
            snapshot.tickCumulativeUpper,
            snapshot.secondsPerLiquidityOutsideUpperX128,
            snapshot.secondsOutsideUpper,
            initializedUpper
        ) = (
            upper.tickCumulativeOutside,
            upper.secondsPerLiquidityOutsideX128,
            upper.secondsOutside,
            upper.initialized
        );
        require(initializedUpper);

        Slot0 memory _slot0 = $.slot0;

        unchecked {
            if (_slot0.tick < tickLower) {
                return (
                    snapshot.tickCumulativeLower - snapshot.tickCumulativeUpper,
                    snapshot.secondsPerLiquidityOutsideLowerX128 - snapshot.secondsPerLiquidityOutsideUpperX128,
                    snapshot.secondsOutsideLower - snapshot.secondsOutsideUpper
                );
            } else if (_slot0.tick < tickUpper) {
                SnapshotCumulativesInsideCache memory cache;
                cache.time = _blockTimestamp;
                (cache.tickCumulative, cache.secondsPerLiquidityCumulativeX128) = observeSingle(
                    $.observations,
                    cache.time,
                    0,
                    _slot0.tick,
                    _slot0.observationIndex,
                    $.liquidity,
                    _slot0.observationCardinality
                );
                return (
                    cache.tickCumulative - snapshot.tickCumulativeLower - snapshot.tickCumulativeUpper,
                    cache.secondsPerLiquidityCumulativeX128 -
                        snapshot.secondsPerLiquidityOutsideLowerX128 -
                        snapshot.secondsPerLiquidityOutsideUpperX128,
                    cache.time - snapshot.secondsOutsideLower - snapshot.secondsOutsideUpper
                );
            } else {
                return (
                    snapshot.tickCumulativeUpper - snapshot.tickCumulativeLower,
                    snapshot.secondsPerLiquidityOutsideUpperX128 - snapshot.secondsPerLiquidityOutsideLowerX128,
                    snapshot.secondsOutsideUpper - snapshot.secondsOutsideLower
                );
            }
        }
    }

    /// @notice Returns the seconds per liquidity and seconds inside a tick range for a period
    /// @dev This does not ensure the range is a valid range
    /// @param period The timestamp of the period
    /// @param tickLower The lower tick of the range
    /// @param tickUpper The upper tick of the range
    /// @return secondsPerLiquidityInsideX128 The snapshot of seconds per liquidity for the range
    function periodCumulativesInside(
        uint32 period,
        int24 tickLower,
        int24 tickUpper,
        uint32 _blockTimestamp
    ) external view returns (uint160 secondsPerLiquidityInsideX128) {
        PoolStorage.PoolState storage $ = PoolStorage.getStorage();

        TickInfo storage lower = $._ticks[tickLower];
        TickInfo storage upper = $._ticks[tickUpper];

        SnapShot memory snapshot;

        {
            int24 startTick = $.periods[period].startTick;
            uint256 previousPeriod = $.periods[period].previousPeriod;

            snapshot.secondsPerLiquidityOutsideLowerX128 = uint160(lower.periodSecondsPerLiquidityOutsideX128[period]);

            if (tickLower <= startTick && snapshot.secondsPerLiquidityOutsideLowerX128 == 0) {
                snapshot.secondsPerLiquidityOutsideLowerX128 = $
                    .periods[previousPeriod]
                    .endSecondsPerLiquidityPeriodX128;
            }

            snapshot.secondsPerLiquidityOutsideUpperX128 = uint160(upper.periodSecondsPerLiquidityOutsideX128[period]);
            if (tickUpper <= startTick && snapshot.secondsPerLiquidityOutsideUpperX128 == 0) {
                snapshot.secondsPerLiquidityOutsideUpperX128 = $
                    .periods[previousPeriod]
                    .endSecondsPerLiquidityPeriodX128;
            }
        }

        int24 lastTick;
        uint256 currentPeriod = $.lastPeriod;
        {
            /// @dev if period is already finalized, use period's last tick, if not, use current tick
            if (currentPeriod > period) {
                lastTick = $.periods[period].lastTick;
            } else {
                lastTick = $.slot0.tick;
            }
        }

        unchecked {
            if (lastTick < tickLower) {
                return snapshot.secondsPerLiquidityOutsideLowerX128 - snapshot.secondsPerLiquidityOutsideUpperX128;
            } else if (lastTick < tickUpper) {
                SnapshotCumulativesInsideCache memory cache;
                /// @dev if period's on-going, observeSingle, if finalized, use endSecondsPerLiquidityPeriodX128
                if (currentPeriod <= period) {
                    cache.time = _blockTimestamp;
                    /// @dev limit to the end of period
                    if (cache.time >= currentPeriod * 1 weeks + 1 weeks) {
                        cache.time = uint32(currentPeriod * 1 weeks + 1 weeks - 1);
                    }

                    Slot0 memory _slot0 = $.slot0;

                    (, cache.secondsPerLiquidityCumulativeX128) = observeSingle(
                        $.observations,
                        cache.time,
                        0,
                        _slot0.tick,
                        _slot0.observationIndex,
                        $.liquidity,
                        _slot0.observationCardinality
                    );
                } else {
                    cache.secondsPerLiquidityCumulativeX128 = $.periods[period].endSecondsPerLiquidityPeriodX128;
                }
                return
                    cache.secondsPerLiquidityCumulativeX128 -
                    snapshot.secondsPerLiquidityOutsideLowerX128 -
                    snapshot.secondsPerLiquidityOutsideUpperX128;
            } else {
                return snapshot.secondsPerLiquidityOutsideUpperX128 - snapshot.secondsPerLiquidityOutsideLowerX128;
            }
        }
    }
}

File 20 of 54 : FixedPoint32.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.4.0;

/// @title FixedPoint32
/// @notice A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format)
library FixedPoint32 {
    uint8 internal constant RESOLUTION = 32;
    uint256 internal constant Q32 = 0x100000000;
}

File 21 of 54 : FixedPoint96.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.4.0;

/// @title FixedPoint96
/// @notice A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format)
/// @dev Used in SqrtPriceMath.sol
library FixedPoint96 {
    uint8 internal constant RESOLUTION = 96;
    uint256 internal constant Q96 = 0x1000000000000000000000000;
}

File 22 of 54 : SafeERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.20;

import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";
import {Address} from "../../../utils/Address.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 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 23 of 54 : Math.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.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 Returns the addition of two unsigned integers, with an success flag (no overflow).
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
        unchecked {
            uint256 c = a + b;
            if (c < a) return (false, 0);
            return (true, c);
        }
    }

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

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

    /**
     * @dev Returns the division of two unsigned integers, with a success flag (no division by zero).
     */
    function tryDiv(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, 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 {
            if (b == 0) return (false, 0);
            return (true, a % b);
        }
    }

    /**
     * @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 {
            // 512-bit multiply [prod1 prod0] = 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 = prod1 * 2²⁵⁶ + prod0.
            uint256 prod0 = x * y; // Least significant 256 bits of the product
            uint256 prod1; // Most significant 256 bits of the product
            assembly {
                let mm := mulmod(x, y, not(0))
                prod1 := sub(sub(mm, prod0), lt(mm, prod0))
            }

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

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

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

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

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

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

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

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

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

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

            // Invert denominator mod 2²⁵⁶. 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 prod1
            // is no longer required.
            result = prod0 * 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 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 value) internal pure returns (uint256) {
        uint256 result = 0;
        uint256 exp;
        unchecked {
            exp = 128 * SafeCast.toUint(value > (1 << 128) - 1);
            value >>= exp;
            result += exp;

            exp = 64 * SafeCast.toUint(value > (1 << 64) - 1);
            value >>= exp;
            result += exp;

            exp = 32 * SafeCast.toUint(value > (1 << 32) - 1);
            value >>= exp;
            result += exp;

            exp = 16 * SafeCast.toUint(value > (1 << 16) - 1);
            value >>= exp;
            result += exp;

            exp = 8 * SafeCast.toUint(value > (1 << 8) - 1);
            value >>= exp;
            result += exp;

            exp = 4 * SafeCast.toUint(value > (1 << 4) - 1);
            value >>= exp;
            result += exp;

            exp = 2 * SafeCast.toUint(value > (1 << 2) - 1);
            value >>= exp;
            result += exp;

            result += SafeCast.toUint(value > 1);
        }
        return result;
    }

    /**
     * @dev Return the log in base 2, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log2(value);
            return result + 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 value) internal pure returns (uint256) {
        uint256 result = 0;
        uint256 isGt;
        unchecked {
            isGt = SafeCast.toUint(value > (1 << 128) - 1);
            value >>= isGt * 128;
            result += isGt * 16;

            isGt = SafeCast.toUint(value > (1 << 64) - 1);
            value >>= isGt * 64;
            result += isGt * 8;

            isGt = SafeCast.toUint(value > (1 << 32) - 1);
            value >>= isGt * 32;
            result += isGt * 4;

            isGt = SafeCast.toUint(value > (1 << 16) - 1);
            value >>= isGt * 16;
            result += isGt * 2;

            result += SafeCast.toUint(value > (1 << 8) - 1);
        }
        return result;
    }

    /**
     * @dev Return the log in base 256, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log256(value);
            return result + 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;
    }
}

File 24 of 54 : IXShadow.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;

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

interface IXShadow is IERC20 {
    struct VestPosition {
        /// @dev amount of xShadow
        uint256 amount;
        /// @dev start unix timestamp
        uint256 start;
        /// @dev start + MAX_VEST (end timestamp)
        uint256 maxEnd;
        /// @dev vest identifier (starting from 0)
        uint256 vestID;
    }

    event CancelVesting(address indexed user, uint256 indexed vestId, uint256 amount);
    event ExitVesting(address indexed user, uint256 indexed vestId, uint256 amount);
    event InstantExit(address indexed user, uint256);

    event NewSlashingPenalty(uint256 penalty);

    event NewVest(address indexed user, uint256 indexed vestId, uint256 indexed amount);
    event NewVestingTimes(uint256 min, uint256 max);

    event Converted(address indexed user, uint256);

    event Exemption(address indexed candidate, bool status, bool success);

    event XShadowRedeemed(address indexed user, uint256);

    event NewOperator(address indexed o, address indexed n);

    event Rebase(address indexed caller, uint256 amount);

    event NewRebaseThreshold(uint256 threshold);

    /// @notice returns info on a user's vests
    function vestInfo(address user, uint256)
        external
        view
        returns (uint256 amount, uint256 start, uint256 maxEnd, uint256 vestID);

    /// @notice address of the shadow token
    function SHADOW() external view returns (IERC20);

    /// @notice address of the voter
    function VOTER() external view returns (IVoter);

    function MINTER() external view returns (address);

    function ACCESS_HUB() external view returns (address);

    /// @notice address of the operator
    function operator() external view returns (address);

    /// @notice address of the VoteModule
    function VOTE_MODULE() external view returns (address);

    /// @notice max slashing amount
    function SLASHING_PENALTY() external view returns (uint256);

    /// @notice denominator
    function BASIS() external view returns (uint256);

    /// @notice the minimum vesting length
    function MIN_VEST() external view returns (uint256);

    /// @notice the maximum vesting length
    function MAX_VEST() external view returns (uint256);

    function shadow() external view returns (address);

    /// @notice the last period rebases were distributed
    function lastDistributedPeriod() external view returns (uint256);

    /// @notice amount of pvp rebase penalties accumulated pending to be distributed
    function pendingRebase() external view returns (uint256);

    /// @notice dust threshold before a rebase can happen
    function rebaseThreshold() external view returns (uint256);

    /// @notice pauses the contract
    function pause() external;

    /// @notice unpauses the contract
    function unpause() external;

    /**
     *
     */
    // General use functions
    /**
     *
     */

    /// @dev mints xShadows for each shadow.
    function convertEmissionsToken(uint256 _amount) external;

    /// @notice function called by the minter to send the rebases once a week
    function rebase() external;
    /**
     * @dev exit instantly with a penalty
     * @param _amount amount of xShadows to exit
     */
    function exit(uint256 _amount) external returns (uint256 _exitedAmount);

    /// @dev vesting xShadows --> emissionToken functionality
    function createVest(uint256 _amount) external;

    /// @dev handles all situations regarding exiting vests
    function exitVest(uint256 _vestID) external;

    /**
     *
     */
    // Permissioned functions, timelock/operator gated
    /**
     *
     */

    /// @dev allows the operator to redeem collected xShadows
    function operatorRedeem(uint256 _amount) external;

    /// @dev allows rescue of any non-stake token
    function rescueTrappedTokens(address[] calldata _tokens, uint256[] calldata _amounts) external;

    /// @notice migrates the operator to another contract
    function migrateOperator(address _operator) external;

    /// @notice set exemption status for an address
    function setExemption(address[] calldata _exemptee, bool[] calldata _exempt) external;

    function setExemptionTo(address[] calldata _exemptee, bool[] calldata _exempt) external;

    /// @notice set dust threshold before a rebase can happen
    function setRebaseThreshold(uint256 _newThreshold) external;

    /**
     *
     */
    // Getter functions
    /**
     *
     */

    /// @notice returns the amount of SHADOW within the contract
    function getBalanceResiding() external view returns (uint256);
    /// @notice returns the total number of individual vests the user has
    function usersTotalVests(address _who) external view returns (uint256 _numOfVests);

    /// @notice whether the address is exempt
    /// @param _who who to check
    /// @return _exempt whether it's exempt
    function isExempt(address _who) external view returns (bool _exempt);

    /// @notice returns the vest info for a user
    /// @param _who who to check
    /// @param _vestID vest ID to check
    /// @return VestPosition vest info
    function getVestInfo(address _who, uint256 _vestID) external view returns (VestPosition memory);
}

File 25 of 54 : Initializable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/utils/Initializable.sol)

pragma solidity ^0.8.20;

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

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

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

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

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

    /**
     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
     * `onlyInitializing` functions can be used to initialize parent contracts.
     *
     * Similar to `reinitializer(1)`, except that in the context of a constructor an `initializer` may be invoked any
     * number of times. This behavior in the constructor can be useful during testing and is not expected to be used in
     * production.
     *
     * Emits an {Initialized} event.
     */
    modifier initializer() {
        // solhint-disable-next-line var-name-mixedcase
        InitializableStorage storage $ = _getInitializableStorage();

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

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

        if (!initialSetup && !construction) {
            revert InvalidInitialization();
        }
        $._initialized = 1;
        if (isTopLevelCall) {
            $._initializing = true;
        }
        _;
        if (isTopLevelCall) {
            $._initializing = false;
            emit Initialized(1);
        }
    }

    /**
     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
     * used to initialize parent contracts.
     *
     * A reinitializer may be used after the original initialization step. This is essential to configure modules that
     * are added through upgrades and that require initialization.
     *
     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
     * cannot be nested. If one is invoked in the context of another, execution will revert.
     *
     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
     * a contract, executing them in the right order is up to the developer or operator.
     *
     * WARNING: Setting the version to 2**64 - 1 will prevent any future reinitialization.
     *
     * Emits an {Initialized} event.
     */
    modifier reinitializer(uint64 version) {
        // solhint-disable-next-line var-name-mixedcase
        InitializableStorage storage $ = _getInitializableStorage();

        if ($._initializing || $._initialized >= version) {
            revert InvalidInitialization();
        }
        $._initialized = version;
        $._initializing = true;
        _;
        $._initializing = false;
        emit Initialized(version);
    }

    /**
     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
     * {initializer} and {reinitializer} modifiers, directly or indirectly.
     */
    modifier onlyInitializing() {
        _checkInitializing();
        _;
    }

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

    /**
     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called
     * through proxies.
     *
     * Emits an {Initialized} event the first time it is successfully executed.
     */
    function _disableInitializers() internal virtual {
        // solhint-disable-next-line var-name-mixedcase
        InitializableStorage storage $ = _getInitializableStorage();

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

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

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

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

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

pragma solidity ^0.8.20;

/**
 * @dev Library for managing
 * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
 * types.
 *
 * Sets have the following properties:
 *
 * - Elements are added, removed, and checked for existence in constant time
 * (O(1)).
 * - Elements are enumerated in O(n). No guarantees are made on the ordering.
 *
 * ```solidity
 * contract Example {
 *     // Add the library methods
 *     using EnumerableSet for EnumerableSet.AddressSet;
 *
 *     // Declare a set state variable
 *     EnumerableSet.AddressSet private mySet;
 * }
 * ```
 *
 * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
 * and `uint256` (`UintSet`) are supported.
 *
 * [WARNING]
 * ====
 * Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
 * unusable.
 * See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
 *
 * In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an
 * array of EnumerableSet.
 * ====
 */
library 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 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 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 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 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;
    }
}

File 27 of 54 : IERC1967.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC1967.sol)

pragma solidity ^0.8.20;

/**
 * @dev ERC-1967: Proxy Storage Slots. This interface contains the events defined in the ERC.
 */
interface IERC1967 {
    /**
     * @dev Emitted when the implementation is upgraded.
     */
    event Upgraded(address indexed implementation);

    /**
     * @dev Emitted when the admin account has changed.
     */
    event AdminChanged(address previousAdmin, address newAdmin);

    /**
     * @dev Emitted when the beacon is changed.
     */
    event BeaconUpgraded(address indexed beacon);
}

File 28 of 54 : Address.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Address.sol)

pragma solidity ^0.8.20;

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

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev There's no code at `target` (it is not a contract).
     */
    error AddressEmptyCode(address target);

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

        (bool success, ) = recipient.call{value: amount}("");
        if (!success) {
            revert Errors.FailedCall();
        }
    }

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

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        if (address(this).balance < value) {
            revert Errors.InsufficientBalance(address(this).balance, value);
        }
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

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

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

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
     * was not a contract or bubbling up the revert reason (falling back to {Errors.FailedCall}) in case
     * of an unsuccessful call.
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata
    ) internal view returns (bytes memory) {
        if (!success) {
            _revert(returndata);
        } else {
            // only check if target is a contract if the call was successful and the return data is empty
            // otherwise we already know that it was a contract
            if (returndata.length == 0 && target.code.length == 0) {
                revert AddressEmptyCode(target);
            }
            return returndata;
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
     * revert reason or with a default {Errors.FailedCall} error.
     */
    function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
        if (!success) {
            _revert(returndata);
        } else {
            return returndata;
        }
    }

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

File 29 of 54 : StorageSlot.sol
// 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 54 : IPoolInitializer.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;
pragma abicoder v2;

/// @title Creates and initializes V3 Pools
/// @notice Provides a method for creating and initializing a pool, if necessary, for bundling with other methods that
/// require the pool to exist.
interface IPoolInitializer {
    /// @notice Creates a new pool if it does not exist, then initializes if not initialized
    /// @dev This method can be bundled with others via IMulticall for the first action (e.g. mint) performed against a pool
    /// @param token0 The contract address of token0 of the pool
    /// @param token1 The contract address of token1 of the pool
    /// @param tickSpacing The tickSpacing of the v3 pool for the specified token pair
    /// @param sqrtPriceX96 The initial square root price of the pool as a Q64.96 value
    /// @return pool Returns the pool address based on the pair of tokens and fee, will return the newly created pool address if necessary
    function createAndInitializePoolIfNecessary(
        address token0,
        address token1,
        int24 tickSpacing,
        uint160 sqrtPriceX96
    ) external payable returns (address pool);
}

File 31 of 54 : IPeripheryPayments.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;

/// @title Periphery Payments
/// @notice Functions to ease deposits and withdrawals of ETH
interface IPeripheryPayments {
    /// @notice Unwraps the contract's WETH9 balance and sends it to recipient as ETH.
    /// @dev The amountMinimum parameter prevents malicious contracts from stealing WETH9 from users.
    /// @param amountMinimum The minimum amount of WETH9 to unwrap
    /// @param recipient The address receiving ETH
    function unwrapWETH9(uint256 amountMinimum, address recipient) external payable;

    /// @notice Refunds any ETH balance held by this contract to the `msg.sender`
    /// @dev Useful for bundling with mint or increase liquidity that uses ether, or exact output swaps
    /// that use ether for the input amount
    function refundETH() external payable;

    /// @notice Transfers the full amount of a token held by this contract to recipient
    /// @dev The amountMinimum parameter prevents malicious contracts from stealing the token from users
    /// @param token The contract address of the token which will be transferred to `recipient`
    /// @param amountMinimum The minimum amount of token required for a transfer
    /// @param recipient The destination address of the token
    function sweepToken(
        address token,
        uint256 amountMinimum,
        address recipient
    ) external payable;
}

File 32 of 54 : IPeripheryImmutableState.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Immutable state
/// @notice Functions that return immutable state of the router
interface IPeripheryImmutableState {
    /// @return Returns the address of the Uniswap V3 deployer
    function deployer() external view returns (address);

    /// @return Returns the address of WETH9
    function WETH9() external view returns (address);
}

File 33 of 54 : PoolAddress.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Provides functions for deriving a pool address from the deployer, tokens, and the fee
library PoolAddress {
    bytes32 internal constant POOL_INIT_CODE_HASH = 0x892f127ed4b26ca352056c8fb54585a3268f76f97fdd84d5836ef4bda8d8c685;

    /// @notice The identifying key of the pool
    struct PoolKey {
        address token0;
        address token1;
        int24 tickSpacing;
    }

    /// @notice Returns PoolKey: the ordered tokens with the matched fee levels
    /// @param tokenA The first token of a pool, unsorted
    /// @param tokenB The second token of a pool, unsorted
    /// @param tickSpacing The tickSpacing of the pool
    /// @return Poolkey The pool details with ordered token0 and token1 assignments
    function getPoolKey(address tokenA, address tokenB, int24 tickSpacing) internal pure returns (PoolKey memory) {
        if (tokenA > tokenB) (tokenA, tokenB) = (tokenB, tokenA);
        return PoolKey({token0: tokenA, token1: tokenB, tickSpacing: tickSpacing});
    }

    /// @notice Deterministically computes the pool address given the deployer and PoolKey
    /// @param deployer The Uniswap V3 deployer contract address
    /// @param key The PoolKey
    /// @return pool The contract address of the V3 pool
    function computeAddress(address deployer, PoolKey memory key) internal pure returns (address pool) {
        require(key.token0 < key.token1, "!TokenOrder");
        pool = address(
            uint160(
                uint256(
                    keccak256(
                        abi.encodePacked(
                            hex'ff',
                            deployer,
                            keccak256(abi.encode(key.token0, key.token1, key.tickSpacing)),
                            POOL_INIT_CODE_HASH
                        )
                    )
                )
            )
        );
    }
}

File 34 of 54 : IERC721.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC721/IERC721.sol)

pragma solidity ^0.8.20;

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

/**
 * @dev Required interface of an ERC-721 compliant contract.
 */
interface IERC721 is IERC165 {
    /**
     * @dev Emitted when `tokenId` token is transferred from `from` to `to`.
     */
    event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);

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

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

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

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

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

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

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

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

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

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

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

File 35 of 54 : IERC721Metadata.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/extensions/IERC721Metadata.sol)

pragma solidity ^0.8.20;

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

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

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

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

File 36 of 54 : IERC721Enumerable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/extensions/IERC721Enumerable.sol)

pragma solidity ^0.8.20;

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

/**
 * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
 * @dev See https://eips.ethereum.org/EIPS/eip-721
 */
interface IERC721Enumerable is IERC721 {
    /**
     * @dev Returns the total amount of tokens stored by the contract.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns a token ID owned by `owner` at a given `index` of its token list.
     * Use along with {balanceOf} to enumerate all of ``owner``'s tokens.
     */
    function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256);

    /**
     * @dev Returns a token ID at a given `index` of all the tokens stored by the contract.
     * Use along with {totalSupply} to enumerate all tokens.
     */
    function tokenByIndex(uint256 index) external view returns (uint256);
}

File 37 of 54 : IPeripheryErrors.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Errors emitted by the NonFungiblePositionManager
/// @notice Contains all events emitted by the NfpManager
interface IPeripheryErrors {
    error InvalidTokenId(uint256 tokenId);
    error CheckSlippage();
    error NotCleared();
}

File 38 of 54 : IShadowV3PoolImmutables.sol
// 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 IShadowV3PoolImmutables {
    /// @notice The contract that deployed the pool, which must adhere to the IShadowV3Factory 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);
}

File 39 of 54 : IShadowV3PoolState.sol
// 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 IShadowV3PoolState {
    /// @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,
            uint24 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 Get the accumulated fee growth for the first token in the pool before protocol fees
    /// @dev This value can overflow the uint256
    function grossFeeGrowthGlobal0X128() external view returns (uint256);

    /// @notice Get the accumulated fee growth for the second token in the pool before protocol fees
    /// @dev This value can overflow the uint256
    function grossFeeGrowthGlobal1X128() 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
        );

    /// @notice get the period seconds in range of a specific position
    /// @param period the period number
    /// @param owner owner address
    /// @param index position index
    /// @param tickLower lower bound of range
    /// @param tickUpper upper bound of range
    /// @return periodSecondsInsideX96 seconds the position was not in range for the period
    function positionPeriodSecondsInRange(
        uint256 period,
        address owner,
        uint256 index,
        int24 tickLower,
        int24 tickUpper
    ) external view returns (uint256 periodSecondsInsideX96);
}

File 40 of 54 : IShadowV3PoolDerivedState.sol
// 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 IShadowV3PoolDerivedState {
    /// @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);
}

File 41 of 54 : IShadowV3PoolActions.sol
// 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 IShadowV3PoolActions {
    /// @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 index The index 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,
        uint256 index,
        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 index The index of the position to be 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,
        uint256 index,
        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 index The index for which the liquidity will be burned
    /// @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(
        uint256 index,
        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;
}

File 42 of 54 : IShadowV3PoolOwnerActions.sol
// 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 IShadowV3PoolOwnerActions {
    /// @notice Set the denominator of the protocol's % share of the fees
    function setFeeProtocol() 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);

    function setFee(uint24 _fee) external;
}

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

/// @title Errors emitted by a pool
/// @notice Contains all custom errors that can be emitted by the pool
interface IShadowV3PoolErrors {
    /*//////////////////////////////////////////////////////////////
                            POOL ERRORS
    //////////////////////////////////////////////////////////////*/

    /// @notice Thrown when the pool is locked during a swap or mint/burn operation
    error LOK(); // Locked

    /// @notice Thrown when tick lower is greater than upper in position management
    error TLU(); // Tick Lower > Upper

    /// @notice Thrown when tick lower is less than minimum allowed
    error TLM(); // Tick Lower < Min

    /// @notice Thrown when tick upper is greater than maximum allowed
    error TUM(); // Tick Upper > Max

    /// @notice Thrown when the pool is already initialized
    error AI(); // Already Initialized

    /// @notice Thrown when the first margin value is zero
    error M0(); // Mint token 0 error

    /// @notice Thrown when the second margin value is zero
    error M1(); // Mint token1 error

    /// @notice Thrown when amount specified is invalid
    error AS(); // Amount Specified Invalid

    /// @notice Thrown when input amount is insufficient
    error IIA(); // Insufficient Input Amount

    /// @notice Thrown when pool lacks sufficient liquidity for operation
    error L(); // Insufficient Liquidity

    /// @notice Thrown when the first fee value is zero
    error F0(); // Fee0 issue or Fee = 0

    /// @notice Thrown when the second fee value is zero
    error F1(); // Fee1 issue

    /// @notice Thrown when square price limit is invalid
    error SPL(); // Square Price Limit Invalid
}

File 44 of 54 : IShadowV3PoolEvents.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 IShadowV3PoolEvents {
    /// @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 45 of 54 : IERC20.sol
// 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);
}

File 46 of 54 : IERC1363.sol
// 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);
}

File 47 of 54 : Panic.sol
// 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 48 of 54 : 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))
        }
    }
}

File 49 of 54 : Pausable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Pausable.sol)

pragma solidity ^0.8.20;

import {Context} from "../utils/Context.sol";

/**
 * @dev Contract module which allows children to implement an emergency stop
 * mechanism that can be triggered by an authorized account.
 *
 * This module is used through inheritance. It will make available the
 * modifiers `whenNotPaused` and `whenPaused`, which can be applied to
 * the functions of your contract. Note that they will not be pausable by
 * simply including this module, only once the modifiers are put in place.
 */
abstract contract Pausable is Context {
    bool private _paused;

    /**
     * @dev Emitted when the pause is triggered by `account`.
     */
    event Paused(address account);

    /**
     * @dev Emitted when the pause is lifted by `account`.
     */
    event Unpaused(address account);

    /**
     * @dev The operation failed because the contract is paused.
     */
    error EnforcedPause();

    /**
     * @dev The operation failed because the contract is not paused.
     */
    error ExpectedPause();

    /**
     * @dev Initializes the contract in unpaused state.
     */
    constructor() {
        _paused = false;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is not paused.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    modifier whenNotPaused() {
        _requireNotPaused();
        _;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is paused.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    modifier whenPaused() {
        _requirePaused();
        _;
    }

    /**
     * @dev Returns true if the contract is paused, and false otherwise.
     */
    function paused() public view virtual returns (bool) {
        return _paused;
    }

    /**
     * @dev Throws if the contract is paused.
     */
    function _requireNotPaused() internal view virtual {
        if (paused()) {
            revert EnforcedPause();
        }
    }

    /**
     * @dev Throws if the contract is not paused.
     */
    function _requirePaused() internal view virtual {
        if (!paused()) {
            revert ExpectedPause();
        }
    }

    /**
     * @dev Triggers stopped state.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    function _pause() internal virtual whenNotPaused {
        _paused = true;
        emit Paused(_msgSender());
    }

    /**
     * @dev Returns to normal state.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    function _unpause() internal virtual whenPaused {
        _paused = false;
        emit Unpaused(_msgSender());
    }
}

File 50 of 54 : Errors.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Errors.sol)

pragma solidity ^0.8.20;

/**
 * @dev Collection of common custom errors used in multiple contracts
 *
 * IMPORTANT: Backwards compatibility is not guaranteed in future versions of the library.
 * It is recommended to avoid relying on the error API for critical functionality.
 *
 * _Available since v5.1._
 */
library Errors {
    /**
     * @dev The ETH balance of the account is not enough to perform the operation.
     */
    error InsufficientBalance(uint256 balance, uint256 needed);

    /**
     * @dev A call to an address target failed. The target may have reverted.
     */
    error FailedCall();

    /**
     * @dev The deployment failed.
     */
    error FailedDeployment();

    /**
     * @dev A necessary precompile is missing.
     */
    error MissingPrecompile(address);
}

File 51 of 54 : IERC165.sol
// 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);
}

File 52 of 54 : 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 53 of 54 : 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";

File 54 of 54 : Context.sol
// 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;
    }
}

Settings
{
  "remappings": [
    "@layerzerolabs/=node_modules/@layerzerolabs/",
    "@layerzerolabs/lz-evm-protocol-v2/=node_modules/@layerzerolabs/lz-evm-protocol-v2/",
    "@openzeppelin-contracts-upgradeable/=dependencies/@openzeppelin-contracts-upgradeable-5.1.0/",
    "@openzeppelin-contracts/contracts/=dependencies/@openzeppelin-contracts-5.1.0/",
    "@openzeppelin/contracts/=dependencies/@openzeppelin-contracts-5.1.0/",
    "erc4626-tests/=dependencies/erc4626-property-tests-1.0/",
    "forge-std/=dependencies/forge-std-1.9.4/src/",
    "permit2/=lib/permit2/",
    "@axelar-network/=node_modules/@axelar-network/",
    "@chainlink/=node_modules/@chainlink/",
    "@eth-optimism/=node_modules/@eth-optimism/",
    "@openzeppelin-3.4.2/=node_modules/@openzeppelin-3.4.2/",
    "@openzeppelin-contracts-5.1.0/=dependencies/@openzeppelin-contracts-5.1.0/",
    "@openzeppelin-contracts-upgradeable-5.1.0/=dependencies/@openzeppelin-contracts-upgradeable-5.1.0/",
    "@uniswap/=node_modules/@uniswap/",
    "base64-sol/=node_modules/base64-sol/",
    "erc4626-property-tests-1.0/=dependencies/erc4626-property-tests-1.0/",
    "eth-gas-reporter/=node_modules/eth-gas-reporter/",
    "forge-std-1.9.4/=dependencies/forge-std-1.9.4/src/",
    "hardhat-deploy/=node_modules/hardhat-deploy/",
    "hardhat/=node_modules/hardhat/",
    "solidity-bytes-utils/=node_modules/solidity-bytes-utils/",
    "solmate/=node_modules/solmate/"
  ],
  "optimizer": {
    "enabled": true,
    "runs": 333
  },
  "metadata": {
    "useLiteralContent": false,
    "bytecodeHash": "ipfs",
    "appendCBOR": true
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "evmVersion": "cancun",
  "viaIR": false,
  "libraries": {
    "contracts/libraries/VoterGovernanceActions.sol": {
      "VoterGovernanceActions": "0x07A1539155758C975a6099aBc15d1B66a227dBDB"
    },
    "contracts/libraries/VoterRewardClaimers.sol": {
      "VoterRewardClaimers": "0x6D1E0D075A013bD5080Be66A717A322F39eACC87"
    }
  }
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"address","name":"_nfpManager","type":"address"},{"internalType":"address","name":"_voter","type":"address"},{"internalType":"address","name":"_feeCollector","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"pool","type":"address"}],"name":"GAUGE_EXISTS","type":"error"},{"inputs":[{"internalType":"address","name":"caller","type":"address"}],"name":"NOT_AUTHORIZED","type":"error"},{"inputs":[],"name":"NOT_INIT","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newFeeCollector","type":"address"},{"indexed":true,"internalType":"address","name":"oldFeeCollector","type":"address"}],"name":"FeeCollectorChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"pool","type":"address"},{"indexed":false,"internalType":"address","name":"gauge","type":"address"}],"name":"GaugeCreated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newNfpManager","type":"address"},{"indexed":true,"internalType":"address","name":"oldNfpManager","type":"address"}],"name":"NfpManagerChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"implementation","type":"address"}],"name":"Upgraded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newVoter","type":"address"},{"indexed":true,"internalType":"address","name":"oldVoter","type":"address"}],"name":"VoterChanged","type":"event"},{"inputs":[{"internalType":"address","name":"pool","type":"address"}],"name":"createGauge","outputs":[{"internalType":"address","name":"gauge","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"feeCollector","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"getGauge","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"implementation","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nfpManager","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_feeCollector","type":"address"}],"name":"setFeeCollector","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_newImplementation","type":"address"}],"name":"setImplementation","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_nfpManager","type":"address"}],"name":"setNfpManager","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_voter","type":"address"}],"name":"setVoter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"voter","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}]

6080604052348015600e575f5ffd5b50604051615fff380380615fff833981016040819052602b916085565b600280546001600160a01b039485166001600160a01b0319918216179091555f8054938516938216939093179092556001805491909316911617905560be565b80516001600160a01b03811681146080575f5ffd5b919050565b5f5f5f606084860312156096575f5ffd5b609d84606b565b925060a960208501606b565b915060b560408501606b565b90509250925092565b615f34806100cb5f395ff3fe608060405234801561000f575f5ffd5b506004361061009b575f3560e01c8063a42dce8011610063578063a42dce801461011b578063a5f4301e1461012e578063b1c6f0e914610141578063c415b95c14610169578063d784d4261461017c575f5ffd5b8063320e68401461009f57806346c96aac146100b45780634bc2a657146100e25780635c60da1b146100f557806398bbc3c714610108575b5f5ffd5b6100b26100ad366004610811565b61018f565b005b5f546100c6906001600160a01b031681565b6040516001600160a01b03909116815260200160405180910390f35b6100b26100f0366004610811565b610229565b6003546100c6906001600160a01b031681565b6002546100c6906001600160a01b031681565b6100b2610129366004610811565b61032d565b6100c661013c366004610811565b610433565b6100c661014f366004610811565b60046020525f90815260409020546001600160a01b031681565b6001546100c6906001600160a01b031681565b6100b261018a366004610811565b6106da565b5f5433906001600160a01b031681146101cc57604051632bc10c3360e01b81526001600160a01b0390911660048201526024015b60405180910390fd5b506002546040516001600160a01b03918216918316907f91b28bee5dc86f5ce41c22a3057286afb3358d566c69a2a3bb4294bdb754c560905f90a3600280546001600160a01b0319166001600160a01b0392909216919091179055565b5f5f9054906101000a90046001600160a01b03166001600160a01b031663e7589b396040518163ffffffff1660e01b8152600401602060405180830381865afa158015610278573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061029c9190610833565b33906001600160a01b031681146102d257604051632bc10c3360e01b81526001600160a01b0390911660048201526024016101c3565b505f80546040516001600160a01b0391821692918416917fcdd5998a5de8d7c793ad6455c4ee5a5498fe1c7e483acb0efd9974d1fa816f2d91a35f80546001600160a01b0319166001600160a01b0392909216919091179055565b5f5f9054906101000a90046001600160a01b03166001600160a01b031663e7589b396040518163ffffffff1660e01b8152600401602060405180830381865afa15801561037c573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906103a09190610833565b33906001600160a01b031681146103d657604051632bc10c3360e01b81526001600160a01b0390911660048201526024016101c3565b506001546040516001600160a01b03918216918316907f649c5e3d0ed183894196148e193af316452b0037e77d2ff0fef23b7dc722bed0905f90a3600180546001600160a01b0319166001600160a01b0392909216919091179055565b5f805433906001600160a01b0316811461046c57604051632bc10c3360e01b81526001600160a01b0390911660048201526024016101c3565b506001600160a01b038281165f90815260046020526040902054839116156104b35760405163e0ad9f6b60e01b81526001600160a01b0390911660048201526024016101c3565b506003546001600160a01b03166105f1575f805460408051632b18028f60e21b815290516001600160a01b039092169163ac600a3c916004808201926020929091908290030181865afa15801561050c573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906105309190610833565b6001600160a01b031603610557576040516359b186bf60e11b815260040160405180910390fd5b5f546001546040516001600160a01b039283169290911690610578906107e3565b6001600160a01b03928316815291166020820152604001604051809103905ff0801580156105a8573d5f5f3e3d5ffd5b50600380546001600160a01b0319166001600160a01b039290921691821790556040517fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b905f90a25b600254604080516001600160a01b03928316602482015291841660448084019190915281518084039091018152606490920181526020820180516001600160e01b031663485cc95560e01b1790525130919061064c906107f0565b61065792919061084e565b604051809103905ff080158015610670573d5f5f3e3d5ffd5b506001600160a01b038381165f8181526004602090815260409182902080546001600160a01b03191694861694851790559051928352929350917fbc0aff029cf899fe358381e295caa21dd2e8c1a6607e2b9e6c7ec915db15bd53910160405180910390a2919050565b5f5f9054906101000a90046001600160a01b03166001600160a01b031663e7589b396040518163ffffffff1660e01b8152600401602060405180830381865afa158015610729573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061074d9190610833565b33906001600160a01b0316811461078357604051632bc10c3360e01b81526001600160a01b0390911660048201526024016101c3565b506003546001600160a01b038281169116146107e057600380546001600160a01b0319166001600160a01b0383169081179091556040517fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b905f90a25b50565b6150f48061089483390190565b6105778061598883390190565b6001600160a01b03811681146107e0575f5ffd5b5f60208284031215610821575f5ffd5b813561082c816107fd565b9392505050565b5f60208284031215610843575f5ffd5b815161082c816107fd565b6001600160a01b0383168152604060208201525f82518060408401528060208501606085015e5f606082850101526060601f19601f830116840101915050939250505056fe610100604052348015610010575f5ffd5b506040516150f43803806150f483398101604081905261002f916101f9565b61003761012c565b6001600160a01b03808316608081905290821660e05260408051632b18028f60e21b815290515f928392909163ac600a3c916004808201926020929091908290030181865afa15801561008c573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906100b0919061022a565b846001600160a01b0316634256f5e76040518163ffffffff1660e01b8152600401602060405180830381865afa1580156100ec573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610110919061022a565b6001600160a01b0391821660a0521660c0525061024a92505050565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00805468010000000000000000900460ff161561017c5760405163f92ee8a960e01b815260040160405180910390fd5b80546001600160401b03908116146101db5780546001600160401b0319166001600160401b0390811782556040519081527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a15b50565b80516001600160a01b03811681146101f4575f5ffd5b919050565b5f5f6040838503121561020a575f5ffd5b610213836101de565b9150610221602084016101de565b90509250929050565b5f6020828403121561023a575f5ffd5b610243826101de565b9392505050565b60805160a05160c05160e051614e236102d15f395f81816104e80152611cf701525f81816102ec01528181610eab015261263801525f81816104690152610e7d01525f81816103130152818161067801528181610bb5015281816110f9015281816113c301528181611413015281816124c70152818161251701526128650152614e235ff3fe608060405234801561000f575f5ffd5b5060043610610213575f3560e01c8063a7852afa1161011f578063c64cef64116100a9578063e3161ddd11610079578063e3161ddd146105da578063e92a9fa9146105e2578063eb6ebc2714610636578063f515740e14610649578063f5f8d36514610651575f5ffd5b8063c64cef6414610546578063c6cee75814610559578063c7deeca61461056c578063e102dac41461057f575f5ffd5b8063b66503cf116100ef578063b66503cf146104bd578063be171c5e146104d0578063c415b95c146104e3578063c4e3a63b1461050a578063c4f59f9b14610531575f5ffd5b8063a7852afa1461043e578063aa89d99b14610451578063ac600a3c14610464578063b5caf3861461048b575f5ffd5b8063485cc955116101a05780639096a35d116101705780639096a35d146103c257806398bbc3c7146103d557806399bcc052146104055780639a32421a14610418578063a23057561461042b575f5ffd5b8063485cc9551461033557806362da4afd146103485780637af618331461035b5780638ed6a18c146103af575f5ffd5b806329b2f637116101e657806329b2f6371461029e5780633af32abf146102b15780633e491d47146102d45780634256f5e7146102e757806346c96aac1461030e575f5ffd5b8063160b194b1461021757806316f0115b146102215780631b9e88b11461026a578063221ca18c1461027d575b5f5ffd5b61021f610664565b005b7fddab91076ea92d6a766cefd001b0cf5f73830986b100aa9c6fa6286e6b0a7302546001600160a01b03165b6040516001600160a01b0390911681526020015b60405180910390f35b61021f610278366004614327565b61077c565b61029061028b366004614359565b6109c2565b604051908152602001610261565b61021f6102ac3660046143c3565b610a2a565b6102c46102bf366004614359565b610b94565b6040519015158152602001610261565b6102906102e236600461445f565b610c26565b61024d7f000000000000000000000000000000000000000000000000000000000000000081565b61024d7f000000000000000000000000000000000000000000000000000000000000000081565b61021f610343366004614489565b610d50565b6102906103563660046144c0565b61100e565b61029061036936600461445f565b6001600160a01b03919091165f9081527fddab91076ea92d6a766cefd001b0cf5f73830986b100aa9c6fa6286e6b0a730a60209081526040808320938352929052205490565b61021f6103bd3660046144f5565b6110b7565b61021f6103d036600461455b565b6110f7565b7fddab91076ea92d6a766cefd001b0cf5f73830986b100aa9c6fa6286e6b0a7303546001600160a01b031661024d565b610290610413366004614359565b61124e565b61021f610426366004614659565b6112e9565b6102906104393660046146c2565b61131e565b61021f61044c366004614712565b611372565b61021f61045f366004614756565b61157d565b61024d7f000000000000000000000000000000000000000000000000000000000000000081565b61049e6104993660046147cd565b61191c565b6040805192151583526001600160a01b03909116602083015201610261565b61021f6104cb36600461445f565b611ced565b6102906104de3660046147f1565b61206a565b61024d7f000000000000000000000000000000000000000000000000000000000000000081565b7fddab91076ea92d6a766cefd001b0cf5f73830986b100aa9c6fa6286e6b0a730154610290565b610539612383565b6040516102619190614870565b6102c4610554366004614359565b6123b3565b61021f6105673660046148bb565b6123de565b61021f61057a3660046147cd565b612476565b61029061058d36600461493a565b5f9283527fddab91076ea92d6a766cefd001b0cf5f73830986b100aa9c6fa6286e6b0a7309602090815260408085209385529281528284206001600160a01b039290921684525290205490565b61021f6126ab565b6102906105f036600461455b565b5f9182527fddab91076ea92d6a766cefd001b0cf5f73830986b100aa9c6fa6286e6b0a7306602090815260408084206001600160a01b0393909316845291905290205490565b610290610644366004614970565b612a3b565b610539612b30565b61021f61065f366004614712565b612b5b565b5f5f516020614dce5f395f51905f5290505f7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166398bbc3c76040518163ffffffff1660e01b8152600401602060405180830381865afa1580156106d2573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906106f691906149ce565b60038301549091506001600160a01b038083169116146107785760038201546040516001600160a01b03918216918316907f91b28bee5dc86f5ce41c22a3057286afb3358d566c69a2a3bb4294bdb754c560905f90a36003820180546001600160a01b0319166001600160a01b0383161790556107766004830182612dce565b505b5050565b5f516020614dce5f395f51905f52805460ff166107ac576040516350dfbc4360e11b815260040160405180910390fd5b805460ff191681556107bc6126ab565b82806107e757604051631f61a80560e21b81526004016107de91815260200190565b60405180910390fd5b506107f184610b94565b849061081c57604051630b7b234960e01b81526001600160a01b0390911660048201526024016107de565b506040516370a0823160e01b81523060048201525f906001600160a01b038616906370a0823190602401602060405180830381865afa158015610861573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061088591906149e9565b905061089c6001600160a01b038616333087612de2565b6040516370a0823160e01b81523060048201525f906001600160a01b038716906370a0823190602401602060405180830381865afa1580156108e0573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061090491906149e9565b90506109108282614a14565b5f8581527fddab91076ea92d6a766cefd001b0cf5f73830986b100aa9c6fa6286e6b0a7306602090815260408083206001600160a01b038b168452909152812080549297508792909190610965908490614a27565b909155505060408051868152602081018690526001600160a01b0388169133917f52977ea98a2220a03ee9ba5cb003ada08d394ea10155483c95dc2dc77a7eb24b910160405180910390a35050805460ff19166001179055505050565b5f806109d162093a8042614a4e565b5f8181527fddab91076ea92d6a766cefd001b0cf5f73830986b100aa9c6fa6286e6b0a7306602090815260408083206001600160a01b0388168452909152902054909150610a239062093a8090614a4e565b9392505050565b5f516020614dce5f395f51905f52805460ff16610a5a576040516350dfbc4360e11b815260040160405180910390fd5b805460ff19168155610a6a6126ab565b336001600160a01b0387168114610aa057604051632bc10c3360e01b81526001600160a01b0390911660048201526024016107de565b505f610aae8787878761131e565b90505f5b88811015610b7d57610ac762093a8042614a4e565b8b1015610b3f578a7fddab91076ea92d6a766cefd001b0cf5f73830986b100aa9c6fa6286e6b0a730a5f8c8c85818110610b0357610b03614a6d565b9050602002016020810190610b189190614359565b6001600160a01b0316815260208082019290925260409081015f9081208682529092529020555b610b758b8b8b84818110610b5557610b55614a6d565b9050602002016020810190610b6a9190614359565b8a8a8a8a888b612e49565b600101610ab2565b5050805460ff191660011790555050505050505050565b604051633af32abf60e01b81526001600160a01b0382811660048301525f917f000000000000000000000000000000000000000000000000000000000000000090911690633af32abf90602401602060405180830381865afa158015610bfc573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610c209190614a81565b92915050565b5f805f516020614dce5f395f51905f52600381015460405163133f757160e31b8152600481018690529192506001600160a01b0316905f90819083906399fbab889060240161014060405180830381865afa158015610c87573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610cab9190614ac0565b5050505050945094505050505f610cc48488858561131e565b6001600160a01b0389165f908152600a87016020908152604080832084845290915281205460018801549293509091610cfd9190612f37565b90505f610d0d62093a8042614a4e565b9050815b818111610d4257610d26818c898d8a8a612a3b565b610d30908a614a27565b9850610d3b81614b75565b9050610d11565b505050505050505092915050565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a008054600160401b810460ff16159067ffffffffffffffff165f81158015610d955750825b90505f8267ffffffffffffffff166001148015610db15750303b155b905081158015610dbf575080155b15610ddd5760405163f92ee8a960e01b815260040160405180910390fd5b845467ffffffffffffffff191660011785558315610e0757845460ff60401b1916600160401b1785555b5f516020614dce5f395f51905f52805460ff19166001178155610e2d62093a8042614a4e565b60018201556002810180546001600160a01b03808a166001600160a01b031992831617909255600383018054928b1692909116919091179055610e736004820189612dce565b50610ea1600e82017f0000000000000000000000000000000000000000000000000000000000000000612dce565b50610ecf600e82017f0000000000000000000000000000000000000000000000000000000000000000612dce565b505f876001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e060405180830381865afa158015610f0d573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610f319190614b9e565b505050935050505061012c8161ffff161015610fa3576040516332148f6760e01b815261012c60048201526001600160a01b038916906332148f67906024015f604051808303815f87803b158015610f87575f5ffd5b505af1158015610f99573d5f5f3e3d5ffd5b5050505061012c90505b61ffff81166010830155610fb5612f46565b82601101819055505050831561100557845460ff60401b19168555604051600181527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a15b50505050505050565b5f805f516020614dce5f395f51905f526003015460405163133f757160e31b8152600481018590526001600160a01b0390911691505f90819083906399fbab889060240161014060405180830381865afa15801561106e573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906110929190614ac0565b5050505050945094505050506110ac878785888686612a3b565b979650505050505050565b7fddab91076ea92d6a766cefd001b0cf5f73830986b100aa9c6fa6286e6b0a7303546110f0906001600160a01b0316868686868661157d565b5050505050565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663e7589b396040518163ffffffff1660e01b8152600401602060405180830381865afa158015611153573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061117791906149ce565b6001600160a01b0316336001600160a01b0316146111a85760405163eb41813b60e01b815260040160405180910390fd5b5f8281527fddab91076ea92d6a766cefd001b0cf5f73830986b100aa9c6fa6286e6b0a730b6020908152604080832080546001600160a01b0319166001600160a01b0386161790557fddab91076ea92d6a766cefd001b0cf5f73830986b100aa9c6fa6286e6b0a730d909152812080545f516020614dce5f395f51905f529290919061123383614b75565b909155506112449050836001614a27565b6011909101555050565b5f8061125d62093a8042614a4e565b90505f4261126c836001614a27565b6112799062093a80614c22565b6112839190614a14565b5f8381527fddab91076ea92d6a766cefd001b0cf5f73830986b100aa9c6fa6286e6b0a7306602090815260408083206001600160a01b038916845290915290205490915062093a80906112d7908390614c22565b6112e19190614a4e565b949350505050565b815f5b818110156110f05761131685858381811061130957611309614a6d565b9050602002013584612b5b565b6001016112ec565b6040805160609590951b6bffffffffffffffffffffffff1916602080870191909152603486019490945260e892831b6054860152911b60578401528051603a818503018152605a9093019052815191012090565b5f516020614dce5f395f51905f52805460ff166113a2576040516350dfbc4360e11b815260040160405180910390fd5b805460ff191681556113b26126ab565b5f516020614dce5f395f51905f525f7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031633146113f75733611406565b60038201546001600160a01b03165b9050336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016148061144757506114476004830133612f54565b339061147257604051632bc10c3360e01b81526001600160a01b0390911660048201526024016107de565b506040516331a9108f60e11b8152600481018690525f906001600160a01b03831690636352211e90602401602060405180830381865afa1580156114b8573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906114dc91906149ce565b90505f5f836001600160a01b03166399fbab88896040518263ffffffff1660e01b815260040161150e91815260200190565b61014060405180830381865afa15801561152a573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061154e9190614ac0565b505050505094509450505050611568848984848b88612f75565b5050835460ff19166001179093555050505050565b5f516020614dce5f395f51905f52805460ff166115ad576040516350dfbc4360e11b815260040160405180910390fd5b805460ff191681556115bd6126ab565b5f516020614dce5f395f51905f526115d862093a8042614a4e565b8711156115f85760405163f21ef34360e01b815260040160405180910390fd5b6116056004820189612f54565b889061163057604051632300a4b360e01b81526001600160a01b0390911660048201526024016107de565b506040516331a9108f60e11b81526004810185905288905f906001600160a01b03831690636352211e90602401602060405180830381865afa158015611678573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061169c91906149ce565b60405163020604bf60e21b8152600481018890529091505f906001600160a01b0384169063081812fc90602401602060405180830381865afa1580156116e4573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061170891906149ce565b9050336001600160a01b03831614806117295750336001600160a01b038216145b8061179d575060405163e985e9c560e01b81526001600160a01b03838116600483015233602483015284169063e985e9c590604401602060405180830381865afa158015611779573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061179d9190614a81565b33906117c857604051632bc10c3360e01b81526001600160a01b0390911660048201526024016107de565b505060405163133f757160e31b8152600481018790525f915081906001600160a01b038416906399fbab889060240161014060405180830381865afa158015611813573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906118379190614ac0565b5050505050945094505050505f6118508489858561131e565b90505f5b898110156119025761186962093a8042614a4e565b8c10156118c4578b86600a015f8d8d8581811061188857611888614a6d565b905060200201602081019061189d9190614359565b6001600160a01b0316815260208082019290925260409081015f9081208682529092529020555b6118fa8c8c8c848181106118da576118da614a6d565b90506020020160208101906118ef9190614359565b878c8888888f612e49565b600101611854565b5050845460ff191660011790945550505050505050505050565b5f805f516020614dce5f395f51905f5281600261193a866001614a27565b6119479062093a80614c22565b6119519190614a14565b600283015460408051633850c7bd60e01b8152905192935042926001600160a01b03909216915f9182918491633850c7bd9160048083019260e09291908290030181865afa1580156119a5573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906119c99190614b9e565b5050604080516080810182525f80825260208201819052918101829052606081019190915261ffff92831697509190921694509250611a06915050565b604080516080810182525f808252602082018190529181018290526060810182905290846001850181611a3b57611a3b614a3a565b0690505f19858201015f805b6020811015611c1a576010811115611a7257604051631d3fd47b60e21b815260040160405180910390fd5b6002848401049150886001600160a01b031663252c09d7898481611a9857611a98614a3a565b066040518263ffffffff1660e01b8152600401611ab791815260200190565b608060405180830381865afa158015611ad2573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611af69190614c39565b151560608a018190526001600160a01b0390911660408a015263ffffffff909216885250611b2957816001019350611c12565b886001600160a01b031663252c09d7898460010181611b4a57611b4a614a3a565b066040518263ffffffff1660e01b8152600401611b6991815260200190565b608060405180830381865afa158015611b84573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611ba89190614c39565b151560608901526001600160a01b031660408801525063ffffffff16855285515f90611bd6908c908e6130b5565b9050808015611bee5750611bee8b8d885f01516130b5565b15611bf95750611c1a565b80611c0957600183039350611c10565b8260010194505b505b600101611a47565b505f886001600160a01b031663252c09d7898460020181611c3d57611c3d614a3a565b066040518263ffffffff1660e01b8152600401611c5c91815260200190565b608060405180830381865afa158015611c77573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611c9b9190614c39565b50505063ffffffff16905080855f015163ffffffff1603611cd1575f85604001519d509d50505050505050505050505050915091565b600185604001519d509d50505050505050505050505050915091565b6001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016632a54db015f516020614dce5f395f51905f526002015460405160e083901b7fffffffff000000000000000000000000000000000000000000000000000000001681526001600160a01b0390911660048201526024015f604051808303815f87803b158015611d84575f5ffd5b505af1158015611d96573d5f5f3e3d5ffd5b505050505f611daf5f516020614dce5f395f51905f5290565b805490915060ff16611dd4576040516350dfbc4360e11b815260040160405180910390fd5b805460ff19168155611de46126ab565b5f516020614dce5f395f51905f528280611e1457604051631f61a80560e21b81526004016107de91815260200190565b50611e1e84610b94565b8490611e4957604051630b7b234960e01b81526001600160a01b0390911660048201526024016107de565b50806002015f9054906101000a90046001600160a01b03166001600160a01b031663c2e0f9b26040518163ffffffff1660e01b81526004015f604051808303815f87803b158015611e98575f5ffd5b505af1158015611eaa573d5f5f3e3d5ffd5b505050505f62093a8042611ebe9190614a4e565b9050611ecd600e830186612f54565b611ee057611ede600e830186612dce565b505b6040516370a0823160e01b81523060048201525f906001600160a01b038716906370a0823190602401602060405180830381865afa158015611f24573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611f4891906149e9565b9050611f5f6001600160a01b038716333088612de2565b6040516370a0823160e01b81523060048201525f906001600160a01b038816906370a0823190602401602060405180830381865afa158015611fa3573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611fc791906149e9565b9050611fd38282614a14565b5f84815260068601602090815260408083206001600160a01b038c16845290915281208054929850889290919061200b908490614a27565b909155505060408051878152602081018590526001600160a01b0389169133917f52977ea98a2220a03ee9ba5cb003ada08d394ea10155483c95dc2dc77a7eb24b910160405180910390a35050825460ff191660011790925550505050565b5f5f516020614dce5f395f51905f5281806120878989898961131e565b5f8c815260078501602090815260408083208484528252808320548f8452600d88019092529091205491925090808210806120c0575081155b156122ab575f8d8152600c8601602052604090205460ff1680612104575060016120ea8e82614a27565b6120f79062093a80614c22565b6121019190614a14565b42105b15612219575f5f866002015f9054906101000a90046001600160a01b03166001600160a01b03168f8e8e8e8e6040516024016121719594939291909485526001600160a01b039390931660208501526040840191909152600290810b60608401520b608082015260a00190565b60408051601f198184030181529181526020820180516001600160e01b0316634c8c7ddb60e11b179052516121a69190614c98565b5f60405180830381855afa9150503d805f81146121de576040519150601f19603f3d011682016040523d82523d5f602084013e6121e3565b606091505b5091509150816121fc575f9750505050505050506110ac565b8080602001905181019061221091906149e9565b95505050612254565b5f8d8152600b860160205260408120546001600160a01b03169003612245575f955050505050506110ac565b6122518d848b8b613175565b93505b61226162093a8042614a4e565b8d10801561226c5750865b156122a6575f8d8152600786016020908152604080832086845282528083208490558f835260088801825280832086845290915290208490555b6122c9565b5f8d8152600886016020908152604080832086845290915290205493505b61230d856006015f8f81526020019081526020015f205f8e6001600160a01b03166001600160a01b031681526020019081526020015f20548561127560671b613488565b95505f856009015f8f81526020019081526020015f205f8581526020019081526020015f205f8e6001600160a01b03166001600160a01b031681526020019081526020015f2054905080871061236e576123678188614a14565b9650612372565b5f96505b505050505050979650505050505050565b60606123ae7fddab91076ea92d6a766cefd001b0cf5f73830986b100aa9c6fa6286e6b0a730e613532565b905090565b5f610c207fddab91076ea92d6a766cefd001b0cf5f73830986b100aa9c6fa6286e6b0a730e83612f54565b5f516020614dce5f395f51905f52805460ff1661240e576040516350dfbc4360e11b815260040160405180910390fd5b805460ff1916815561241e6126ab565b336001600160a01b038816811461245457604051632bc10c3360e01b81526001600160a01b0390911660048201526024016107de565b50612463878787878787612f75565b805460ff19166001179055505050505050565b5f516020614dce5f395f51905f52805460ff166124a6576040516350dfbc4360e11b815260040160405180910390fd5b805460ff191681556124b66126ab565b5f516020614dce5f395f51905f525f7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031633146124fb573361250a565b60038201546001600160a01b03165b9050336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016148061254b575061254b6004830133612f54565b339061257657604051632bc10c3360e01b81526001600160a01b0390911660048201526024016107de565b5060405163133f757160e31b8152600481018590525f9081906001600160a01b038416906399fbab889060240161014060405180830381865afa1580156125bf573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906125e39190614ac0565b5050505050945094505050505f600167ffffffffffffffff81111561260a5761260a61457e565b604051908082528060200260200182016040528015612633578160200160208202803683370190505b5090507f0000000000000000000000000000000000000000000000000000000000000000815f8151811061266957612669614a6d565b60200260200101906001600160a01b031690816001600160a01b031681525050612697848885858533612f75565b5050835460ff191660011790935550505050565b7fddab91076ea92d6a766cefd001b0cf5f73830986b100aa9c6fa6286e6b0a7310545f516020614dce5f395f51905f5290610e108110156127d357600282015460408051633850c7bd60e01b815290516001600160a01b03909216918291633850c7bd9160048083019260e09291908290030181865afa158015612731573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906127559190614b9e565b50505061ffff16945061276f9250600a9150849050614a27565b6040516332148f6760e01b815261ffff821660048201529092506001600160a01b038216906332148f67906024015f604051808303815f87803b1580156127b4575f5ffd5b505af11580156127c6573d5f5f3e3d5ffd5b5050505060108301829055505b5f6127dc612f46565b6011840154909150808214612a35576002840154604080516369a077c560e11b815290516001600160a01b03909216918491839163d340ef8a916004808201926020929091908290030181865afa158015612839573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061285d91906149e9565b146129be575f7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316637dc688596040518163ffffffff1660e01b8152600401602060405180830381865afa1580156128bf573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906128e391906149ce565b604051637b46c54f60e01b81526001600160a01b03848116600483015291925090821690637b46c54f906024015f604051808303815f87803b158015612927575f5ffd5b505af1158015612939573d5f5f3e3d5ffd5b5050505083826001600160a01b031663d340ef8a6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561297a573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061299e91906149e9565b146129bc5760405163013b9f2360e31b815260040160405180910390fd5b505b6129c78261191c565b5f848152600c880160209081526040808320600b8b01835281842080546001600160a01b0319166001600160a01b039690961695909517909455835460ff191694151594909417909255600d8801909152908120805491612a2783614b75565b909155505050601184018290555b50505050565b60408051602481018890526001600160a01b0387811660448301528616606482015260848101859052600284810b60a483015283900b60c48201525f60e48083018290528351808403909101815261010490920183526020820180516001600160e01b0316635f0b8e2f60e11b1790529151829182913091612abc91614c98565b5f60405180830381855afa9150503d805f8114612af4576040519150601f19603f3d011682016040523d82523d5f602084013e612af9565b606091505b509150915081612b0d575f92505050612b26565b80806020019051810190612b2191906149e9565b925050505b9695505050505050565b60606123ae7fddab91076ea92d6a766cefd001b0cf5f73830986b100aa9c6fa6286e6b0a7304613532565b5f516020614dce5f395f51905f52805460ff16612b8b576040516350dfbc4360e11b815260040160405180910390fd5b805460ff19168155612b9b6126ab565b5f5f516020614dce5f395f51905f52600301546040516331a9108f60e11b8152600481018690526001600160a01b0390911691505f908290636352211e90602401602060405180830381865afa158015612bf7573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612c1b91906149ce565b60405163020604bf60e21b8152600481018790529091505f906001600160a01b0384169063081812fc90602401602060405180830381865afa158015612c63573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612c8791906149ce565b9050336001600160a01b0383161480612ca85750336001600160a01b038216145b80612d1c575060405163e985e9c560e01b81526001600160a01b03838116600483015233602483015284169063e985e9c590604401602060405180830381865afa158015612cf8573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612d1c9190614a81565b3390612d4757604051632bc10c3360e01b81526001600160a01b0390911660048201526024016107de565b5060405163133f757160e31b8152600481018790525f9081906001600160a01b038616906399fbab889060240161014060405180830381865afa158015612d90573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612db49190614ac0565b505050505094509450505050611568858984848b33612f75565b5f610a23836001600160a01b03841661353e565b6040516001600160a01b038481166024830152838116604483015260648201839052612a359186918216906323b872dd906084015b604051602081830303815290604052915060e01b6020820180516001600160e01b03838183161783525050505061358a565b5f612e5a898989898989600161206a565b90508015612f2c575f8981527fddab91076ea92d6a766cefd001b0cf5f73830986b100aa9c6fa6286e6b0a73096020908152604080832086845282528083206001600160a01b038c16845290915281208054839290612eba908490614a27565b90915550612ed490506001600160a01b03891683836135f6565b604080518a8152602081018590526001600160a01b03848116828401528a1660608201526080810183905290517fc8c7ebd754a625a8677ab2031c7674259be1e8c1a7f3521cbf5edbca8f48099c9181900360a00190a15b505050505050505050565b5f828218828411028218610a23565b5f6123ae62093a8042614a4e565b6001600160a01b0381165f9081526001830160205260408120541515610a23565b5f516020614dce5f395f51905f525f612f908888888861131e565b90505f612fa062093a8042614a4e565b90505f805b86518110156130a85761300985600a015f898481518110612fc857612fc8614a6d565b60200260200101516001600160a01b03166001600160a01b031681526020019081526020015f205f8681526020019081526020015f20548660010154612f37565b9150815b83811161304d5761303d8189848151811061302a5761302a614a6d565b60200260200101518e8e8e8e8b8e612e49565b61304681614b75565b905061300d565b50613059600184614a14565b85600a015f89848151811061307057613070614a6d565b6020908102919091018101516001600160a01b031682528181019290925260409081015f908120888252909252902055600101612fa5565b5050505050505050505050565b5f8363ffffffff168363ffffffff16111580156130de57508363ffffffff168263ffffffff1611155b156130fa578163ffffffff168363ffffffff1611159050610a23565b5f8463ffffffff168463ffffffff1611613121578363ffffffff1664010000000001613129565b8363ffffffff165b64ffffffffff1690505f8563ffffffff168463ffffffff1611613159578363ffffffff1664010000000001613161565b8363ffffffff165b64ffffffffff169091111595945050505050565b7fddab91076ea92d6a766cefd001b0cf5f73830986b100aa9c6fa6286e6b0a7302545f907ff047b0c59244a0faf8e48cb6b6fde518e6717176152b6dd953628cd9dccb2800906001600160a01b0316826131cd612f46565b9050808811156131f05760405163f21ef34360e01b815260040160405180910390fd5b505f8681526201000a8301602052604081208161320d828b613627565b935090505f819003613226575f955050505050506112e1565b50506040805160018082528183019092525f91829190602080830190803683375050505f8a815260088701602090815260408083208e8452600401909152812082516001820195509293506060929091859185919061328757613287614a6d565b602090810291909101015260405163e57c0ca960e01b81526001600160a01b0387169063e57c0ca9906132be908690600401614cae565b5f60405180830381865afa1580156132d8573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f191682016040526132ff9190810190614ce5565b9150815f8151811061331357613313614a6d565b602002602001015193505f8460581b60601c90505f6133338e8d8d613ba1565b905061333f8282614d6c565b905082955085855f8151811061335757613357614a6d565b602090810291909101015260405163e57c0ca960e01b81526001600160a01b0389169063e57c0ca99061338e908890600401614cae565b5f60405180830381865afa1580156133a8573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f191682016040526133cf9190810190614ce5565b93505f845f815181106133e4576133e4614a6d565b60200260200101515f1c905061340988836001600160a01b0316640100000000613488565b9a505f8112806134185750808b115b1561344d575f81126134335761342e818c614a14565b613446565b61343c81614db3565b613446908c614a27565b9a50613451565b5f9a505b61346b6c0100000000000000000000000062093a80614c22565b8b1115613476575f9a505b50505050505050505050949350505050565b5f80805f19858709858702925082811083820303915050805f036134bc575f84116134b1575f5ffd5b508290049050610a23565b8084116134c7575f5ffd5b5f848688095f868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010186841190950394909402919094039290920491909117919091029150509392505050565b60605f610a23836142b7565b5f81815260018301602052604081205461358357508154600181810184555f848152602080822090930184905584548482528286019093526040902091909155610c20565b505f610c20565b5f5f60205f8451602086015f885af1806135a9576040513d5f823e3d81fd5b50505f513d915081156135c05780600114156135cd565b6001600160a01b0384163b155b15612a3557604051635274afe760e01b81526001600160a01b03851660048201526024016107de565b6040516001600160a01b0383811660248301526044820183905261077691859182169063a9059cbb90606401612e17565b7fddab91076ea92d6a766cefd001b0cf5f73830986b100aa9c6fa6286e6b0a7302546040805160018082528183019092525f9283926001600160a01b039091169183918291906020808301908036833701905050905060605f8893505f8460405160200161369791815260200190565b60405160208183030381529060405280519060200120905084845f815181106136c2576136c2614a6d565b602090810291909101015260405163e57c0ca960e01b81526001600160a01b0387169063e57c0ca9906136f9908790600401614cae565b5f60405180830381865afa158015613713573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f1916820160405261373a9190810190614ce5565b92505f835f8151811061374f5761374f614a6d565b60200260200101515f1c9050805f03613774575f5f9850985050505050505050613b9a565b81955085855f8151811061378a5761378a614a6d565b602090810291909101015260405163e57c0ca960e01b81526001600160a01b0388169063e57c0ca9906137c1908890600401614cae565b5f60405180830381865afa1580156137db573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f191682016040526138029190810190614ce5565b9350835f8151811061381657613816614a6d565b60200260200101515f1c98508989111561383c575f5f9850985050505050505050613b9a565b613847600182614a14565b9250600283028201955085855f8151811061386457613864614a6d565b602090810291909101015260405163e57c0ca960e01b81526001600160a01b0388169063e57c0ca99061389b908890600401614cae565b5f60405180830381865afa1580156138b5573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f191682016040526138dc9190810190614ce5565b9350835f815181106138f0576138f0614a6d565b60200260200101515f1c98505088881115613a2a575f82815b82821115613a1d575f600261391e8585614a14565b6139289190614a4e565b6139329084614a14565b9050600281028501985088885f8151811061394f5761394f614a6d565b602090810291909101015260405163e57c0ca960e01b81526001600160a01b038b169063e57c0ca990613986908b90600401614cae565b5f60405180830381865afa1580156139a0573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f191682016040526139c79190810190614ce5565b9650865f815181106139db576139db614a6d565b60200260200101515f1c9b508c8c036139f957945060019050613a1d565b8c8c1015613a0957809350613a17565b613a14600182614a14565b92505b50613909565b80613a26578294505b5050505b600282028101945084845f81518110613a4557613a45614a6d565b602090810291909101015260405163e57c0ca960e01b81526001600160a01b0387169063e57c0ca990613a7c908790600401614cae565b5f60405180830381865afa158015613a96573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f19168201604052613abd9190810190614ce5565b9250825f81518110613ad157613ad1614a6d565b60200260200101515f1c9750600160028302820101945084845f81518110613afb57613afb614a6d565b602090810291909101015260405163e57c0ca960e01b81526001600160a01b0387169063e57c0ca990613b32908790600401614cae565b5f60405180830381865afa158015613b4c573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f19168201604052613b739190810190614ce5565b9250825f81518110613b8757613b87614a6d565b60200260200101515f1c96505050505050505b9250929050565b7fddab91076ea92d6a766cefd001b0cf5f73830986b100aa9c6fa6286e6b0a7302546040805160c0810182525f8082526020808301829052828401829052606083018290526080830182905260a083018290528351600180825281860190955291947ff047b0c59244a0faf8e48cb6b6fde518e6717176152b6dd953628cd9dccb2800946001600160a01b0390911693928692839290828101908036833701905050905060605f5f5f8862010008015f8e63ffffffff1681526020019081526020015f20905080955085855f81518110613c7d57613c7d614a6d565b602090810291909101015260405163e57c0ca960e01b81526001600160a01b0389169063e57c0ca990613cb4908890600401614cae565b5f60405180830381865afa158015613cce573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f19168201604052613cf59190810190614ce5565b9350835f81518110613d0957613d09614a6d565b60209081029190910181015160028e900b5f90815260068c01835260409081902090516004909101985062ffffff82841c16955063ffffffff9091169350879250613d69918f9184910163ffffffff929092168252602082015260400190565b60405160208183030381529060405280519060200120955085855f81518110613d9457613d94614a6d565b602090810291909101015260405163e57c0ca960e01b81526001600160a01b0389169063e57c0ca990613dcb908890600401614cae565b5f60405180830381865afa158015613de5573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f19168201604052613e0c9190810190614ce5565b9350835f81518110613e2057613e20614a6d565b60209081029190910101516001600160a01b0316604088015250600282810b908c900b13801590613e5c575060408601516001600160a01b0316155b15613f38575f81815262010008890160205260408120855190965086918291879190613e8a57613e8a614a6d565b602090810291909101015260405163e57c0ca960e01b81526001600160a01b0389169063e57c0ca990613ec1908890600401614cae565b5f60405180830381865afa158015613edb573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f19168201604052613f029190810190614ce5565b9350835f81518110613f1657613f16614a6d565b602090810291909101015160501c6001600160a01b0316604088018190529550505b60028a900b5f9081526006890160209081526040918290209151600490920196508691613f7a918f9184910163ffffffff929092168252602082015260400190565b60405160208183030381529060405280519060200120955085855f81518110613fa557613fa5614a6d565b602090810291909101015260405163e57c0ca960e01b81526001600160a01b0389169063e57c0ca990613fdc908890600401614cae565b5f60405180830381865afa158015613ff6573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f1916820160405261401d9190810190614ce5565b9350835f8151811061403157614031614a6d565b60209081029190910101516001600160a01b0316606088015250600282810b908b900b1380159061406d575060608601516001600160a01b0316155b15614149575f8181526201000889016020526040812085519096508691829187919061409b5761409b614a6d565b602090810291909101015260405163e57c0ca960e01b81526001600160a01b0389169063e57c0ca9906140d2908890600401614cae565b5f60405180830381865afa1580156140ec573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f191682016040526141139190810190614ce5565b9350835f8151811061412757614127614a6d565b602090810291909101015160501c6001600160a01b0316606088018190529550505b505063ffffffff8a165f9081526201000887016020526040812083519094508491829185919061417b5761417b614a6d565b602090810291909101015260405163e57c0ca960e01b81526001600160a01b0387169063e57c0ca9906141b2908690600401614cae565b5f60405180830381865afa1580156141cc573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f191682016040526141f39190810190614ce5565b9150815f8151811061420757614207614a6d565b602002602001015193505f8460b01b60e81c90508a60020b8160020b121561424357856060015186604001510398505050505050505050610a23565b8960020b8160020b121561429d57606086015160408701515f516020614dce5f395f51905f5263ffffffff8f165f908152600b9190910160205260409020546001600160a01b031603039850610a23975050505050505050565b856040015186606001510398505050505050505050610a23565b6060815f0180548060200260200160405190810160405280929190818152602001828054801561430457602002820191905f5260205f20905b8154815260200190600101908083116142f0575b50505050509050919050565b6001600160a01b0381168114614324575f5ffd5b50565b5f5f5f60608486031215614339575f5ffd5b833561434481614310565b95602085013595506040909401359392505050565b5f60208284031215614369575f5ffd5b8135610a2381614310565b5f5f83601f840112614384575f5ffd5b50813567ffffffffffffffff81111561439b575f5ffd5b6020830191508360208260051b8501011115613b9a575f5ffd5b8060020b8114614324575f5ffd5b5f5f5f5f5f5f5f5f60e0898b0312156143da575f5ffd5b88359750602089013567ffffffffffffffff8111156143f7575f5ffd5b6144038b828c01614374565b909850965050604089013561441781614310565b945060608901359350608089013561442e816143b5565b925060a089013561443e816143b5565b915060c089013561444e81614310565b809150509295985092959890939650565b5f5f60408385031215614470575f5ffd5b823561447b81614310565b946020939093013593505050565b5f5f6040838503121561449a575f5ffd5b82356144a581614310565b915060208301356144b581614310565b809150509250929050565b5f5f5f606084860312156144d2575f5ffd5b8335925060208401356144e481614310565b929592945050506040919091013590565b5f5f5f5f5f60808688031215614509575f5ffd5b85359450602086013567ffffffffffffffff811115614526575f5ffd5b61453288828901614374565b90955093505060408601359150606086013561454d81614310565b809150509295509295909350565b5f5f6040838503121561456c575f5ffd5b8235915060208301356144b581614310565b634e487b7160e01b5f52604160045260245ffd5b604051601f8201601f1916810167ffffffffffffffff811182821017156145bb576145bb61457e565b604052919050565b5f67ffffffffffffffff8211156145dc576145dc61457e565b5060051b60200190565b5f82601f8301126145f5575f5ffd5b8135614608614603826145c3565b614592565b8082825260208201915060208360051b860101925085831115614629575f5ffd5b602085015b8381101561464f57803561464181614310565b83526020928301920161462e565b5095945050505050565b5f5f5f6040848603121561466b575f5ffd5b833567ffffffffffffffff811115614681575f5ffd5b61468d86828701614374565b909450925050602084013567ffffffffffffffff8111156146ac575f5ffd5b6146b8868287016145e6565b9150509250925092565b5f5f5f5f608085870312156146d5575f5ffd5b84356146e081614310565b93506020850135925060408501356146f7816143b5565b91506060850135614707816143b5565b939692955090935050565b5f5f60408385031215614723575f5ffd5b82359150602083013567ffffffffffffffff811115614740575f5ffd5b61474c858286016145e6565b9150509250929050565b5f5f5f5f5f5f60a0878903121561476b575f5ffd5b863561477681614310565b955060208701359450604087013567ffffffffffffffff811115614798575f5ffd5b6147a489828a01614374565b9095509350506060870135915060808701356147bf81614310565b809150509295509295509295565b5f602082840312156147dd575f5ffd5b5035919050565b8015158114614324575f5ffd5b5f5f5f5f5f5f5f60e0888a031215614807575f5ffd5b87359650602088013561481981614310565b9550604088013561482981614310565b9450606088013593506080880135614840816143b5565b925060a0880135614850816143b5565b915060c0880135614860816147e4565b8091505092959891949750929550565b602080825282518282018190525f918401906040840190835b818110156148b05783516001600160a01b0316835260209384019390920191600101614889565b509095945050505050565b5f5f5f5f5f5f60c087890312156148d0575f5ffd5b86356148db81614310565b95506020870135945060408701356148f2816143b5565b93506060870135614902816143b5565b9250608087013567ffffffffffffffff81111561491d575f5ffd5b61492989828a016145e6565b92505060a08701356147bf81614310565b5f5f5f6060848603121561494c575f5ffd5b8335925060208401359150604084013561496581614310565b809150509250925092565b5f5f5f5f5f5f60c08789031215614985575f5ffd5b86359550602087013561499781614310565b945060408701356149a781614310565b93506060870135925060808701356149be816143b5565b915060a08701356147bf816143b5565b5f602082840312156149de575f5ffd5b8151610a2381614310565b5f602082840312156149f9575f5ffd5b5051919050565b634e487b7160e01b5f52601160045260245ffd5b81810381811115610c2057610c20614a00565b80820180821115610c2057610c20614a00565b634e487b7160e01b5f52601260045260245ffd5b5f82614a6857634e487b7160e01b5f52601260045260245ffd5b500490565b634e487b7160e01b5f52603260045260245ffd5b5f60208284031215614a91575f5ffd5b8151610a23816147e4565b80516fffffffffffffffffffffffffffffffff81168114614abb575f5ffd5b919050565b5f5f5f5f5f5f5f5f5f5f6101408b8d031215614ada575f5ffd5b8a51614ae581614310565b60208c0151909a50614af681614310565b60408c0151909950614b07816143b5565b60608c0151909850614b18816143b5565b60808c0151909750614b29816143b5565b9550614b3760a08c01614a9c565b60c08c015160e08d015191965094509250614b556101008c01614a9c565b9150614b646101208c01614a9c565b90509295989b9194979a5092959850565b5f60018201614b8657614b86614a00565b5060010190565b805161ffff81168114614abb575f5ffd5b5f5f5f5f5f5f5f60e0888a031215614bb4575f5ffd5b8751614bbf81614310565b6020890151909750614bd0816143b5565b9550614bde60408901614b8d565b9450614bec60608901614b8d565b9350614bfa60808901614b8d565b925060a088015162ffffff81168114614c11575f5ffd5b60c0890151909250614860816147e4565b8082028115828204841417610c2057610c20614a00565b5f5f5f5f60808587031215614c4c575f5ffd5b845163ffffffff81168114614c5f575f5ffd5b8094505060208501518060060b8114614c76575f5ffd5b6040860151909350614c8781614310565b6060860151909250614707816147e4565b5f82518060208501845e5f920191825250919050565b602080825282518282018190525f918401906040840190835b818110156148b0578351835260209384019390920191600101614cc7565b5f60208284031215614cf5575f5ffd5b815167ffffffffffffffff811115614d0b575f5ffd5b8201601f81018413614d1b575f5ffd5b8051614d29614603826145c3565b8082825260208201915060208360051b850101925086831115614d4a575f5ffd5b6020840193505b82841015612b26578351825260209384019390910190614d51565b601382810b9082900b03737fffffffffffffffffffffffffffffffffffffff198112737fffffffffffffffffffffffffffffffffffffff82131715610c2057610c20614a00565b5f600160ff1b8201614dc757614dc7614a00565b505f039056feddab91076ea92d6a766cefd001b0cf5f73830986b100aa9c6fa6286e6b0a7300a26469706673582212205e8a7cbc28c3831f07312a3c3c6bcd492c3abbb73d47787fedb02ed8e30c402164736f6c634300081c003360a060405260405161057738038061057783398101604081905261002291610354565b61002c828261003e565b506001600160a01b0316608052610445565b610047826100fb565b6040516001600160a01b038316907f1cf3b03a6cf19fa2baba4df148e9dcabedea7f8a5c07840e207e5c089be95d3e905f90a28051156100ef576100ea826001600160a01b0316635c60da1b6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156100c0573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906100e49190610416565b82610209565b505050565b6100f761027c565b5050565b806001600160a01b03163b5f0361013557604051631933b43b60e21b81526001600160a01b03821660048201526024015b60405180910390fd5b807fa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d5080546001600160a01b0319166001600160a01b0392831617905560408051635c60da1b60e01b815290515f92841691635c60da1b9160048083019260209291908290030181865afa1580156101ae573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906101d29190610416565b9050806001600160a01b03163b5f036100f757604051634c9c8ce360e01b81526001600160a01b038216600482015260240161012c565b60605f5f846001600160a01b031684604051610225919061042f565b5f60405180830381855af49150503d805f811461025d576040519150601f19603f3d011682016040523d82523d5f602084013e610262565b606091505b50909250905061027385838361029d565b95945050505050565b341561029b5760405163b398979f60e01b815260040160405180910390fd5b565b6060826102b2576102ad826102fc565b6102f5565b81511580156102c957506001600160a01b0384163b155b156102f257604051639996b31560e01b81526001600160a01b038516600482015260240161012c565b50805b9392505050565b80511561030c5780518082602001fd5b60405163d6bda27560e01b815260040160405180910390fd5b80516001600160a01b038116811461033b575f5ffd5b919050565b634e487b7160e01b5f52604160045260245ffd5b5f5f60408385031215610365575f5ffd5b61036e83610325565b60208401519092506001600160401b03811115610389575f5ffd5b8301601f81018513610399575f5ffd5b80516001600160401b038111156103b2576103b2610340565b604051601f8201601f19908116603f011681016001600160401b03811182821017156103e0576103e0610340565b6040528181528282016020018710156103f7575f5ffd5b8160208401602083015e5f602083830101528093505050509250929050565b5f60208284031215610426575f5ffd5b6102f582610325565b5f82518060208501845e5f920191825250919050565b60805161011b61045c5f395f601d015261011b5ff3fe6080604052600a600c565b005b60186014601a565b609d565b565b5f7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316635c60da1b6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156076573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906098919060ba565b905090565b365f5f375f5f365f845af43d5f5f3e80801560b6573d5ff35b3d5ffd5b5f6020828403121560c9575f5ffd5b81516001600160a01b038116811460de575f5ffd5b939250505056fea26469706673582212204d9471f2016d028d1d1f4816bb78c0f5049d528195c75b1745670d8620fd2b0c64736f6c634300081c0033a264697066735822122002c3ea8cec6f8de8364561e9fb19ca414cf8ea119da426a1315ad3f8269914f264736f6c634300081c003300000000000000000000000012e66c8f215ddd5d48d150c8f46ad0c6fb0f44060000000000000000000000009f59398d0a397b2eeb8a6123a6c7295cb0b0062d000000000000000000000000949e7b2f3f66eae761a9397346ddbd719f046c0e

Deployed Bytecode

0x608060405234801561000f575f5ffd5b506004361061009b575f3560e01c8063a42dce8011610063578063a42dce801461011b578063a5f4301e1461012e578063b1c6f0e914610141578063c415b95c14610169578063d784d4261461017c575f5ffd5b8063320e68401461009f57806346c96aac146100b45780634bc2a657146100e25780635c60da1b146100f557806398bbc3c714610108575b5f5ffd5b6100b26100ad366004610811565b61018f565b005b5f546100c6906001600160a01b031681565b6040516001600160a01b03909116815260200160405180910390f35b6100b26100f0366004610811565b610229565b6003546100c6906001600160a01b031681565b6002546100c6906001600160a01b031681565b6100b2610129366004610811565b61032d565b6100c661013c366004610811565b610433565b6100c661014f366004610811565b60046020525f90815260409020546001600160a01b031681565b6001546100c6906001600160a01b031681565b6100b261018a366004610811565b6106da565b5f5433906001600160a01b031681146101cc57604051632bc10c3360e01b81526001600160a01b0390911660048201526024015b60405180910390fd5b506002546040516001600160a01b03918216918316907f91b28bee5dc86f5ce41c22a3057286afb3358d566c69a2a3bb4294bdb754c560905f90a3600280546001600160a01b0319166001600160a01b0392909216919091179055565b5f5f9054906101000a90046001600160a01b03166001600160a01b031663e7589b396040518163ffffffff1660e01b8152600401602060405180830381865afa158015610278573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061029c9190610833565b33906001600160a01b031681146102d257604051632bc10c3360e01b81526001600160a01b0390911660048201526024016101c3565b505f80546040516001600160a01b0391821692918416917fcdd5998a5de8d7c793ad6455c4ee5a5498fe1c7e483acb0efd9974d1fa816f2d91a35f80546001600160a01b0319166001600160a01b0392909216919091179055565b5f5f9054906101000a90046001600160a01b03166001600160a01b031663e7589b396040518163ffffffff1660e01b8152600401602060405180830381865afa15801561037c573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906103a09190610833565b33906001600160a01b031681146103d657604051632bc10c3360e01b81526001600160a01b0390911660048201526024016101c3565b506001546040516001600160a01b03918216918316907f649c5e3d0ed183894196148e193af316452b0037e77d2ff0fef23b7dc722bed0905f90a3600180546001600160a01b0319166001600160a01b0392909216919091179055565b5f805433906001600160a01b0316811461046c57604051632bc10c3360e01b81526001600160a01b0390911660048201526024016101c3565b506001600160a01b038281165f90815260046020526040902054839116156104b35760405163e0ad9f6b60e01b81526001600160a01b0390911660048201526024016101c3565b506003546001600160a01b03166105f1575f805460408051632b18028f60e21b815290516001600160a01b039092169163ac600a3c916004808201926020929091908290030181865afa15801561050c573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906105309190610833565b6001600160a01b031603610557576040516359b186bf60e11b815260040160405180910390fd5b5f546001546040516001600160a01b039283169290911690610578906107e3565b6001600160a01b03928316815291166020820152604001604051809103905ff0801580156105a8573d5f5f3e3d5ffd5b50600380546001600160a01b0319166001600160a01b039290921691821790556040517fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b905f90a25b600254604080516001600160a01b03928316602482015291841660448084019190915281518084039091018152606490920181526020820180516001600160e01b031663485cc95560e01b1790525130919061064c906107f0565b61065792919061084e565b604051809103905ff080158015610670573d5f5f3e3d5ffd5b506001600160a01b038381165f8181526004602090815260409182902080546001600160a01b03191694861694851790559051928352929350917fbc0aff029cf899fe358381e295caa21dd2e8c1a6607e2b9e6c7ec915db15bd53910160405180910390a2919050565b5f5f9054906101000a90046001600160a01b03166001600160a01b031663e7589b396040518163ffffffff1660e01b8152600401602060405180830381865afa158015610729573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061074d9190610833565b33906001600160a01b0316811461078357604051632bc10c3360e01b81526001600160a01b0390911660048201526024016101c3565b506003546001600160a01b038281169116146107e057600380546001600160a01b0319166001600160a01b0383169081179091556040517fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b905f90a25b50565b6150f48061089483390190565b6105778061598883390190565b6001600160a01b03811681146107e0575f5ffd5b5f60208284031215610821575f5ffd5b813561082c816107fd565b9392505050565b5f60208284031215610843575f5ffd5b815161082c816107fd565b6001600160a01b0383168152604060208201525f82518060408401528060208501606085015e5f606082850101526060601f19601f830116840101915050939250505056fe610100604052348015610010575f5ffd5b506040516150f43803806150f483398101604081905261002f916101f9565b61003761012c565b6001600160a01b03808316608081905290821660e05260408051632b18028f60e21b815290515f928392909163ac600a3c916004808201926020929091908290030181865afa15801561008c573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906100b0919061022a565b846001600160a01b0316634256f5e76040518163ffffffff1660e01b8152600401602060405180830381865afa1580156100ec573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610110919061022a565b6001600160a01b0391821660a0521660c0525061024a92505050565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00805468010000000000000000900460ff161561017c5760405163f92ee8a960e01b815260040160405180910390fd5b80546001600160401b03908116146101db5780546001600160401b0319166001600160401b0390811782556040519081527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a15b50565b80516001600160a01b03811681146101f4575f5ffd5b919050565b5f5f6040838503121561020a575f5ffd5b610213836101de565b9150610221602084016101de565b90509250929050565b5f6020828403121561023a575f5ffd5b610243826101de565b9392505050565b60805160a05160c05160e051614e236102d15f395f81816104e80152611cf701525f81816102ec01528181610eab015261263801525f81816104690152610e7d01525f81816103130152818161067801528181610bb5015281816110f9015281816113c301528181611413015281816124c70152818161251701526128650152614e235ff3fe608060405234801561000f575f5ffd5b5060043610610213575f3560e01c8063a7852afa1161011f578063c64cef64116100a9578063e3161ddd11610079578063e3161ddd146105da578063e92a9fa9146105e2578063eb6ebc2714610636578063f515740e14610649578063f5f8d36514610651575f5ffd5b8063c64cef6414610546578063c6cee75814610559578063c7deeca61461056c578063e102dac41461057f575f5ffd5b8063b66503cf116100ef578063b66503cf146104bd578063be171c5e146104d0578063c415b95c146104e3578063c4e3a63b1461050a578063c4f59f9b14610531575f5ffd5b8063a7852afa1461043e578063aa89d99b14610451578063ac600a3c14610464578063b5caf3861461048b575f5ffd5b8063485cc955116101a05780639096a35d116101705780639096a35d146103c257806398bbc3c7146103d557806399bcc052146104055780639a32421a14610418578063a23057561461042b575f5ffd5b8063485cc9551461033557806362da4afd146103485780637af618331461035b5780638ed6a18c146103af575f5ffd5b806329b2f637116101e657806329b2f6371461029e5780633af32abf146102b15780633e491d47146102d45780634256f5e7146102e757806346c96aac1461030e575f5ffd5b8063160b194b1461021757806316f0115b146102215780631b9e88b11461026a578063221ca18c1461027d575b5f5ffd5b61021f610664565b005b7fddab91076ea92d6a766cefd001b0cf5f73830986b100aa9c6fa6286e6b0a7302546001600160a01b03165b6040516001600160a01b0390911681526020015b60405180910390f35b61021f610278366004614327565b61077c565b61029061028b366004614359565b6109c2565b604051908152602001610261565b61021f6102ac3660046143c3565b610a2a565b6102c46102bf366004614359565b610b94565b6040519015158152602001610261565b6102906102e236600461445f565b610c26565b61024d7f000000000000000000000000000000000000000000000000000000000000000081565b61024d7f000000000000000000000000000000000000000000000000000000000000000081565b61021f610343366004614489565b610d50565b6102906103563660046144c0565b61100e565b61029061036936600461445f565b6001600160a01b03919091165f9081527fddab91076ea92d6a766cefd001b0cf5f73830986b100aa9c6fa6286e6b0a730a60209081526040808320938352929052205490565b61021f6103bd3660046144f5565b6110b7565b61021f6103d036600461455b565b6110f7565b7fddab91076ea92d6a766cefd001b0cf5f73830986b100aa9c6fa6286e6b0a7303546001600160a01b031661024d565b610290610413366004614359565b61124e565b61021f610426366004614659565b6112e9565b6102906104393660046146c2565b61131e565b61021f61044c366004614712565b611372565b61021f61045f366004614756565b61157d565b61024d7f000000000000000000000000000000000000000000000000000000000000000081565b61049e6104993660046147cd565b61191c565b6040805192151583526001600160a01b03909116602083015201610261565b61021f6104cb36600461445f565b611ced565b6102906104de3660046147f1565b61206a565b61024d7f000000000000000000000000000000000000000000000000000000000000000081565b7fddab91076ea92d6a766cefd001b0cf5f73830986b100aa9c6fa6286e6b0a730154610290565b610539612383565b6040516102619190614870565b6102c4610554366004614359565b6123b3565b61021f6105673660046148bb565b6123de565b61021f61057a3660046147cd565b612476565b61029061058d36600461493a565b5f9283527fddab91076ea92d6a766cefd001b0cf5f73830986b100aa9c6fa6286e6b0a7309602090815260408085209385529281528284206001600160a01b039290921684525290205490565b61021f6126ab565b6102906105f036600461455b565b5f9182527fddab91076ea92d6a766cefd001b0cf5f73830986b100aa9c6fa6286e6b0a7306602090815260408084206001600160a01b0393909316845291905290205490565b610290610644366004614970565b612a3b565b610539612b30565b61021f61065f366004614712565b612b5b565b5f5f516020614dce5f395f51905f5290505f7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166398bbc3c76040518163ffffffff1660e01b8152600401602060405180830381865afa1580156106d2573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906106f691906149ce565b60038301549091506001600160a01b038083169116146107785760038201546040516001600160a01b03918216918316907f91b28bee5dc86f5ce41c22a3057286afb3358d566c69a2a3bb4294bdb754c560905f90a36003820180546001600160a01b0319166001600160a01b0383161790556107766004830182612dce565b505b5050565b5f516020614dce5f395f51905f52805460ff166107ac576040516350dfbc4360e11b815260040160405180910390fd5b805460ff191681556107bc6126ab565b82806107e757604051631f61a80560e21b81526004016107de91815260200190565b60405180910390fd5b506107f184610b94565b849061081c57604051630b7b234960e01b81526001600160a01b0390911660048201526024016107de565b506040516370a0823160e01b81523060048201525f906001600160a01b038616906370a0823190602401602060405180830381865afa158015610861573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061088591906149e9565b905061089c6001600160a01b038616333087612de2565b6040516370a0823160e01b81523060048201525f906001600160a01b038716906370a0823190602401602060405180830381865afa1580156108e0573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061090491906149e9565b90506109108282614a14565b5f8581527fddab91076ea92d6a766cefd001b0cf5f73830986b100aa9c6fa6286e6b0a7306602090815260408083206001600160a01b038b168452909152812080549297508792909190610965908490614a27565b909155505060408051868152602081018690526001600160a01b0388169133917f52977ea98a2220a03ee9ba5cb003ada08d394ea10155483c95dc2dc77a7eb24b910160405180910390a35050805460ff19166001179055505050565b5f806109d162093a8042614a4e565b5f8181527fddab91076ea92d6a766cefd001b0cf5f73830986b100aa9c6fa6286e6b0a7306602090815260408083206001600160a01b0388168452909152902054909150610a239062093a8090614a4e565b9392505050565b5f516020614dce5f395f51905f52805460ff16610a5a576040516350dfbc4360e11b815260040160405180910390fd5b805460ff19168155610a6a6126ab565b336001600160a01b0387168114610aa057604051632bc10c3360e01b81526001600160a01b0390911660048201526024016107de565b505f610aae8787878761131e565b90505f5b88811015610b7d57610ac762093a8042614a4e565b8b1015610b3f578a7fddab91076ea92d6a766cefd001b0cf5f73830986b100aa9c6fa6286e6b0a730a5f8c8c85818110610b0357610b03614a6d565b9050602002016020810190610b189190614359565b6001600160a01b0316815260208082019290925260409081015f9081208682529092529020555b610b758b8b8b84818110610b5557610b55614a6d565b9050602002016020810190610b6a9190614359565b8a8a8a8a888b612e49565b600101610ab2565b5050805460ff191660011790555050505050505050565b604051633af32abf60e01b81526001600160a01b0382811660048301525f917f000000000000000000000000000000000000000000000000000000000000000090911690633af32abf90602401602060405180830381865afa158015610bfc573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610c209190614a81565b92915050565b5f805f516020614dce5f395f51905f52600381015460405163133f757160e31b8152600481018690529192506001600160a01b0316905f90819083906399fbab889060240161014060405180830381865afa158015610c87573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610cab9190614ac0565b5050505050945094505050505f610cc48488858561131e565b6001600160a01b0389165f908152600a87016020908152604080832084845290915281205460018801549293509091610cfd9190612f37565b90505f610d0d62093a8042614a4e565b9050815b818111610d4257610d26818c898d8a8a612a3b565b610d30908a614a27565b9850610d3b81614b75565b9050610d11565b505050505050505092915050565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a008054600160401b810460ff16159067ffffffffffffffff165f81158015610d955750825b90505f8267ffffffffffffffff166001148015610db15750303b155b905081158015610dbf575080155b15610ddd5760405163f92ee8a960e01b815260040160405180910390fd5b845467ffffffffffffffff191660011785558315610e0757845460ff60401b1916600160401b1785555b5f516020614dce5f395f51905f52805460ff19166001178155610e2d62093a8042614a4e565b60018201556002810180546001600160a01b03808a166001600160a01b031992831617909255600383018054928b1692909116919091179055610e736004820189612dce565b50610ea1600e82017f0000000000000000000000000000000000000000000000000000000000000000612dce565b50610ecf600e82017f0000000000000000000000000000000000000000000000000000000000000000612dce565b505f876001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e060405180830381865afa158015610f0d573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610f319190614b9e565b505050935050505061012c8161ffff161015610fa3576040516332148f6760e01b815261012c60048201526001600160a01b038916906332148f67906024015f604051808303815f87803b158015610f87575f5ffd5b505af1158015610f99573d5f5f3e3d5ffd5b5050505061012c90505b61ffff81166010830155610fb5612f46565b82601101819055505050831561100557845460ff60401b19168555604051600181527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a15b50505050505050565b5f805f516020614dce5f395f51905f526003015460405163133f757160e31b8152600481018590526001600160a01b0390911691505f90819083906399fbab889060240161014060405180830381865afa15801561106e573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906110929190614ac0565b5050505050945094505050506110ac878785888686612a3b565b979650505050505050565b7fddab91076ea92d6a766cefd001b0cf5f73830986b100aa9c6fa6286e6b0a7303546110f0906001600160a01b0316868686868661157d565b5050505050565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663e7589b396040518163ffffffff1660e01b8152600401602060405180830381865afa158015611153573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061117791906149ce565b6001600160a01b0316336001600160a01b0316146111a85760405163eb41813b60e01b815260040160405180910390fd5b5f8281527fddab91076ea92d6a766cefd001b0cf5f73830986b100aa9c6fa6286e6b0a730b6020908152604080832080546001600160a01b0319166001600160a01b0386161790557fddab91076ea92d6a766cefd001b0cf5f73830986b100aa9c6fa6286e6b0a730d909152812080545f516020614dce5f395f51905f529290919061123383614b75565b909155506112449050836001614a27565b6011909101555050565b5f8061125d62093a8042614a4e565b90505f4261126c836001614a27565b6112799062093a80614c22565b6112839190614a14565b5f8381527fddab91076ea92d6a766cefd001b0cf5f73830986b100aa9c6fa6286e6b0a7306602090815260408083206001600160a01b038916845290915290205490915062093a80906112d7908390614c22565b6112e19190614a4e565b949350505050565b815f5b818110156110f05761131685858381811061130957611309614a6d565b9050602002013584612b5b565b6001016112ec565b6040805160609590951b6bffffffffffffffffffffffff1916602080870191909152603486019490945260e892831b6054860152911b60578401528051603a818503018152605a9093019052815191012090565b5f516020614dce5f395f51905f52805460ff166113a2576040516350dfbc4360e11b815260040160405180910390fd5b805460ff191681556113b26126ab565b5f516020614dce5f395f51905f525f7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031633146113f75733611406565b60038201546001600160a01b03165b9050336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016148061144757506114476004830133612f54565b339061147257604051632bc10c3360e01b81526001600160a01b0390911660048201526024016107de565b506040516331a9108f60e11b8152600481018690525f906001600160a01b03831690636352211e90602401602060405180830381865afa1580156114b8573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906114dc91906149ce565b90505f5f836001600160a01b03166399fbab88896040518263ffffffff1660e01b815260040161150e91815260200190565b61014060405180830381865afa15801561152a573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061154e9190614ac0565b505050505094509450505050611568848984848b88612f75565b5050835460ff19166001179093555050505050565b5f516020614dce5f395f51905f52805460ff166115ad576040516350dfbc4360e11b815260040160405180910390fd5b805460ff191681556115bd6126ab565b5f516020614dce5f395f51905f526115d862093a8042614a4e565b8711156115f85760405163f21ef34360e01b815260040160405180910390fd5b6116056004820189612f54565b889061163057604051632300a4b360e01b81526001600160a01b0390911660048201526024016107de565b506040516331a9108f60e11b81526004810185905288905f906001600160a01b03831690636352211e90602401602060405180830381865afa158015611678573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061169c91906149ce565b60405163020604bf60e21b8152600481018890529091505f906001600160a01b0384169063081812fc90602401602060405180830381865afa1580156116e4573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061170891906149ce565b9050336001600160a01b03831614806117295750336001600160a01b038216145b8061179d575060405163e985e9c560e01b81526001600160a01b03838116600483015233602483015284169063e985e9c590604401602060405180830381865afa158015611779573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061179d9190614a81565b33906117c857604051632bc10c3360e01b81526001600160a01b0390911660048201526024016107de565b505060405163133f757160e31b8152600481018790525f915081906001600160a01b038416906399fbab889060240161014060405180830381865afa158015611813573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906118379190614ac0565b5050505050945094505050505f6118508489858561131e565b90505f5b898110156119025761186962093a8042614a4e565b8c10156118c4578b86600a015f8d8d8581811061188857611888614a6d565b905060200201602081019061189d9190614359565b6001600160a01b0316815260208082019290925260409081015f9081208682529092529020555b6118fa8c8c8c848181106118da576118da614a6d565b90506020020160208101906118ef9190614359565b878c8888888f612e49565b600101611854565b5050845460ff191660011790945550505050505050505050565b5f805f516020614dce5f395f51905f5281600261193a866001614a27565b6119479062093a80614c22565b6119519190614a14565b600283015460408051633850c7bd60e01b8152905192935042926001600160a01b03909216915f9182918491633850c7bd9160048083019260e09291908290030181865afa1580156119a5573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906119c99190614b9e565b5050604080516080810182525f80825260208201819052918101829052606081019190915261ffff92831697509190921694509250611a06915050565b604080516080810182525f808252602082018190529181018290526060810182905290846001850181611a3b57611a3b614a3a565b0690505f19858201015f805b6020811015611c1a576010811115611a7257604051631d3fd47b60e21b815260040160405180910390fd5b6002848401049150886001600160a01b031663252c09d7898481611a9857611a98614a3a565b066040518263ffffffff1660e01b8152600401611ab791815260200190565b608060405180830381865afa158015611ad2573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611af69190614c39565b151560608a018190526001600160a01b0390911660408a015263ffffffff909216885250611b2957816001019350611c12565b886001600160a01b031663252c09d7898460010181611b4a57611b4a614a3a565b066040518263ffffffff1660e01b8152600401611b6991815260200190565b608060405180830381865afa158015611b84573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611ba89190614c39565b151560608901526001600160a01b031660408801525063ffffffff16855285515f90611bd6908c908e6130b5565b9050808015611bee5750611bee8b8d885f01516130b5565b15611bf95750611c1a565b80611c0957600183039350611c10565b8260010194505b505b600101611a47565b505f886001600160a01b031663252c09d7898460020181611c3d57611c3d614a3a565b066040518263ffffffff1660e01b8152600401611c5c91815260200190565b608060405180830381865afa158015611c77573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611c9b9190614c39565b50505063ffffffff16905080855f015163ffffffff1603611cd1575f85604001519d509d50505050505050505050505050915091565b600185604001519d509d50505050505050505050505050915091565b6001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016632a54db015f516020614dce5f395f51905f526002015460405160e083901b7fffffffff000000000000000000000000000000000000000000000000000000001681526001600160a01b0390911660048201526024015f604051808303815f87803b158015611d84575f5ffd5b505af1158015611d96573d5f5f3e3d5ffd5b505050505f611daf5f516020614dce5f395f51905f5290565b805490915060ff16611dd4576040516350dfbc4360e11b815260040160405180910390fd5b805460ff19168155611de46126ab565b5f516020614dce5f395f51905f528280611e1457604051631f61a80560e21b81526004016107de91815260200190565b50611e1e84610b94565b8490611e4957604051630b7b234960e01b81526001600160a01b0390911660048201526024016107de565b50806002015f9054906101000a90046001600160a01b03166001600160a01b031663c2e0f9b26040518163ffffffff1660e01b81526004015f604051808303815f87803b158015611e98575f5ffd5b505af1158015611eaa573d5f5f3e3d5ffd5b505050505f62093a8042611ebe9190614a4e565b9050611ecd600e830186612f54565b611ee057611ede600e830186612dce565b505b6040516370a0823160e01b81523060048201525f906001600160a01b038716906370a0823190602401602060405180830381865afa158015611f24573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611f4891906149e9565b9050611f5f6001600160a01b038716333088612de2565b6040516370a0823160e01b81523060048201525f906001600160a01b038816906370a0823190602401602060405180830381865afa158015611fa3573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611fc791906149e9565b9050611fd38282614a14565b5f84815260068601602090815260408083206001600160a01b038c16845290915281208054929850889290919061200b908490614a27565b909155505060408051878152602081018590526001600160a01b0389169133917f52977ea98a2220a03ee9ba5cb003ada08d394ea10155483c95dc2dc77a7eb24b910160405180910390a35050825460ff191660011790925550505050565b5f5f516020614dce5f395f51905f5281806120878989898961131e565b5f8c815260078501602090815260408083208484528252808320548f8452600d88019092529091205491925090808210806120c0575081155b156122ab575f8d8152600c8601602052604090205460ff1680612104575060016120ea8e82614a27565b6120f79062093a80614c22565b6121019190614a14565b42105b15612219575f5f866002015f9054906101000a90046001600160a01b03166001600160a01b03168f8e8e8e8e6040516024016121719594939291909485526001600160a01b039390931660208501526040840191909152600290810b60608401520b608082015260a00190565b60408051601f198184030181529181526020820180516001600160e01b0316634c8c7ddb60e11b179052516121a69190614c98565b5f60405180830381855afa9150503d805f81146121de576040519150601f19603f3d011682016040523d82523d5f602084013e6121e3565b606091505b5091509150816121fc575f9750505050505050506110ac565b8080602001905181019061221091906149e9565b95505050612254565b5f8d8152600b860160205260408120546001600160a01b03169003612245575f955050505050506110ac565b6122518d848b8b613175565b93505b61226162093a8042614a4e565b8d10801561226c5750865b156122a6575f8d8152600786016020908152604080832086845282528083208490558f835260088801825280832086845290915290208490555b6122c9565b5f8d8152600886016020908152604080832086845290915290205493505b61230d856006015f8f81526020019081526020015f205f8e6001600160a01b03166001600160a01b031681526020019081526020015f20548561127560671b613488565b95505f856009015f8f81526020019081526020015f205f8581526020019081526020015f205f8e6001600160a01b03166001600160a01b031681526020019081526020015f2054905080871061236e576123678188614a14565b9650612372565b5f96505b505050505050979650505050505050565b60606123ae7fddab91076ea92d6a766cefd001b0cf5f73830986b100aa9c6fa6286e6b0a730e613532565b905090565b5f610c207fddab91076ea92d6a766cefd001b0cf5f73830986b100aa9c6fa6286e6b0a730e83612f54565b5f516020614dce5f395f51905f52805460ff1661240e576040516350dfbc4360e11b815260040160405180910390fd5b805460ff1916815561241e6126ab565b336001600160a01b038816811461245457604051632bc10c3360e01b81526001600160a01b0390911660048201526024016107de565b50612463878787878787612f75565b805460ff19166001179055505050505050565b5f516020614dce5f395f51905f52805460ff166124a6576040516350dfbc4360e11b815260040160405180910390fd5b805460ff191681556124b66126ab565b5f516020614dce5f395f51905f525f7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031633146124fb573361250a565b60038201546001600160a01b03165b9050336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016148061254b575061254b6004830133612f54565b339061257657604051632bc10c3360e01b81526001600160a01b0390911660048201526024016107de565b5060405163133f757160e31b8152600481018590525f9081906001600160a01b038416906399fbab889060240161014060405180830381865afa1580156125bf573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906125e39190614ac0565b5050505050945094505050505f600167ffffffffffffffff81111561260a5761260a61457e565b604051908082528060200260200182016040528015612633578160200160208202803683370190505b5090507f0000000000000000000000000000000000000000000000000000000000000000815f8151811061266957612669614a6d565b60200260200101906001600160a01b031690816001600160a01b031681525050612697848885858533612f75565b5050835460ff191660011790935550505050565b7fddab91076ea92d6a766cefd001b0cf5f73830986b100aa9c6fa6286e6b0a7310545f516020614dce5f395f51905f5290610e108110156127d357600282015460408051633850c7bd60e01b815290516001600160a01b03909216918291633850c7bd9160048083019260e09291908290030181865afa158015612731573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906127559190614b9e565b50505061ffff16945061276f9250600a9150849050614a27565b6040516332148f6760e01b815261ffff821660048201529092506001600160a01b038216906332148f67906024015f604051808303815f87803b1580156127b4575f5ffd5b505af11580156127c6573d5f5f3e3d5ffd5b5050505060108301829055505b5f6127dc612f46565b6011840154909150808214612a35576002840154604080516369a077c560e11b815290516001600160a01b03909216918491839163d340ef8a916004808201926020929091908290030181865afa158015612839573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061285d91906149e9565b146129be575f7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316637dc688596040518163ffffffff1660e01b8152600401602060405180830381865afa1580156128bf573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906128e391906149ce565b604051637b46c54f60e01b81526001600160a01b03848116600483015291925090821690637b46c54f906024015f604051808303815f87803b158015612927575f5ffd5b505af1158015612939573d5f5f3e3d5ffd5b5050505083826001600160a01b031663d340ef8a6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561297a573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061299e91906149e9565b146129bc5760405163013b9f2360e31b815260040160405180910390fd5b505b6129c78261191c565b5f848152600c880160209081526040808320600b8b01835281842080546001600160a01b0319166001600160a01b039690961695909517909455835460ff191694151594909417909255600d8801909152908120805491612a2783614b75565b909155505050601184018290555b50505050565b60408051602481018890526001600160a01b0387811660448301528616606482015260848101859052600284810b60a483015283900b60c48201525f60e48083018290528351808403909101815261010490920183526020820180516001600160e01b0316635f0b8e2f60e11b1790529151829182913091612abc91614c98565b5f60405180830381855afa9150503d805f8114612af4576040519150601f19603f3d011682016040523d82523d5f602084013e612af9565b606091505b509150915081612b0d575f92505050612b26565b80806020019051810190612b2191906149e9565b925050505b9695505050505050565b60606123ae7fddab91076ea92d6a766cefd001b0cf5f73830986b100aa9c6fa6286e6b0a7304613532565b5f516020614dce5f395f51905f52805460ff16612b8b576040516350dfbc4360e11b815260040160405180910390fd5b805460ff19168155612b9b6126ab565b5f5f516020614dce5f395f51905f52600301546040516331a9108f60e11b8152600481018690526001600160a01b0390911691505f908290636352211e90602401602060405180830381865afa158015612bf7573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612c1b91906149ce565b60405163020604bf60e21b8152600481018790529091505f906001600160a01b0384169063081812fc90602401602060405180830381865afa158015612c63573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612c8791906149ce565b9050336001600160a01b0383161480612ca85750336001600160a01b038216145b80612d1c575060405163e985e9c560e01b81526001600160a01b03838116600483015233602483015284169063e985e9c590604401602060405180830381865afa158015612cf8573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612d1c9190614a81565b3390612d4757604051632bc10c3360e01b81526001600160a01b0390911660048201526024016107de565b5060405163133f757160e31b8152600481018790525f9081906001600160a01b038616906399fbab889060240161014060405180830381865afa158015612d90573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612db49190614ac0565b505050505094509450505050611568858984848b33612f75565b5f610a23836001600160a01b03841661353e565b6040516001600160a01b038481166024830152838116604483015260648201839052612a359186918216906323b872dd906084015b604051602081830303815290604052915060e01b6020820180516001600160e01b03838183161783525050505061358a565b5f612e5a898989898989600161206a565b90508015612f2c575f8981527fddab91076ea92d6a766cefd001b0cf5f73830986b100aa9c6fa6286e6b0a73096020908152604080832086845282528083206001600160a01b038c16845290915281208054839290612eba908490614a27565b90915550612ed490506001600160a01b03891683836135f6565b604080518a8152602081018590526001600160a01b03848116828401528a1660608201526080810183905290517fc8c7ebd754a625a8677ab2031c7674259be1e8c1a7f3521cbf5edbca8f48099c9181900360a00190a15b505050505050505050565b5f828218828411028218610a23565b5f6123ae62093a8042614a4e565b6001600160a01b0381165f9081526001830160205260408120541515610a23565b5f516020614dce5f395f51905f525f612f908888888861131e565b90505f612fa062093a8042614a4e565b90505f805b86518110156130a85761300985600a015f898481518110612fc857612fc8614a6d565b60200260200101516001600160a01b03166001600160a01b031681526020019081526020015f205f8681526020019081526020015f20548660010154612f37565b9150815b83811161304d5761303d8189848151811061302a5761302a614a6d565b60200260200101518e8e8e8e8b8e612e49565b61304681614b75565b905061300d565b50613059600184614a14565b85600a015f89848151811061307057613070614a6d565b6020908102919091018101516001600160a01b031682528181019290925260409081015f908120888252909252902055600101612fa5565b5050505050505050505050565b5f8363ffffffff168363ffffffff16111580156130de57508363ffffffff168263ffffffff1611155b156130fa578163ffffffff168363ffffffff1611159050610a23565b5f8463ffffffff168463ffffffff1611613121578363ffffffff1664010000000001613129565b8363ffffffff165b64ffffffffff1690505f8563ffffffff168463ffffffff1611613159578363ffffffff1664010000000001613161565b8363ffffffff165b64ffffffffff169091111595945050505050565b7fddab91076ea92d6a766cefd001b0cf5f73830986b100aa9c6fa6286e6b0a7302545f907ff047b0c59244a0faf8e48cb6b6fde518e6717176152b6dd953628cd9dccb2800906001600160a01b0316826131cd612f46565b9050808811156131f05760405163f21ef34360e01b815260040160405180910390fd5b505f8681526201000a8301602052604081208161320d828b613627565b935090505f819003613226575f955050505050506112e1565b50506040805160018082528183019092525f91829190602080830190803683375050505f8a815260088701602090815260408083208e8452600401909152812082516001820195509293506060929091859185919061328757613287614a6d565b602090810291909101015260405163e57c0ca960e01b81526001600160a01b0387169063e57c0ca9906132be908690600401614cae565b5f60405180830381865afa1580156132d8573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f191682016040526132ff9190810190614ce5565b9150815f8151811061331357613313614a6d565b602002602001015193505f8460581b60601c90505f6133338e8d8d613ba1565b905061333f8282614d6c565b905082955085855f8151811061335757613357614a6d565b602090810291909101015260405163e57c0ca960e01b81526001600160a01b0389169063e57c0ca99061338e908890600401614cae565b5f60405180830381865afa1580156133a8573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f191682016040526133cf9190810190614ce5565b93505f845f815181106133e4576133e4614a6d565b60200260200101515f1c905061340988836001600160a01b0316640100000000613488565b9a505f8112806134185750808b115b1561344d575f81126134335761342e818c614a14565b613446565b61343c81614db3565b613446908c614a27565b9a50613451565b5f9a505b61346b6c0100000000000000000000000062093a80614c22565b8b1115613476575f9a505b50505050505050505050949350505050565b5f80805f19858709858702925082811083820303915050805f036134bc575f84116134b1575f5ffd5b508290049050610a23565b8084116134c7575f5ffd5b5f848688095f868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010186841190950394909402919094039290920491909117919091029150509392505050565b60605f610a23836142b7565b5f81815260018301602052604081205461358357508154600181810184555f848152602080822090930184905584548482528286019093526040902091909155610c20565b505f610c20565b5f5f60205f8451602086015f885af1806135a9576040513d5f823e3d81fd5b50505f513d915081156135c05780600114156135cd565b6001600160a01b0384163b155b15612a3557604051635274afe760e01b81526001600160a01b03851660048201526024016107de565b6040516001600160a01b0383811660248301526044820183905261077691859182169063a9059cbb90606401612e17565b7fddab91076ea92d6a766cefd001b0cf5f73830986b100aa9c6fa6286e6b0a7302546040805160018082528183019092525f9283926001600160a01b039091169183918291906020808301908036833701905050905060605f8893505f8460405160200161369791815260200190565b60405160208183030381529060405280519060200120905084845f815181106136c2576136c2614a6d565b602090810291909101015260405163e57c0ca960e01b81526001600160a01b0387169063e57c0ca9906136f9908790600401614cae565b5f60405180830381865afa158015613713573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f1916820160405261373a9190810190614ce5565b92505f835f8151811061374f5761374f614a6d565b60200260200101515f1c9050805f03613774575f5f9850985050505050505050613b9a565b81955085855f8151811061378a5761378a614a6d565b602090810291909101015260405163e57c0ca960e01b81526001600160a01b0388169063e57c0ca9906137c1908890600401614cae565b5f60405180830381865afa1580156137db573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f191682016040526138029190810190614ce5565b9350835f8151811061381657613816614a6d565b60200260200101515f1c98508989111561383c575f5f9850985050505050505050613b9a565b613847600182614a14565b9250600283028201955085855f8151811061386457613864614a6d565b602090810291909101015260405163e57c0ca960e01b81526001600160a01b0388169063e57c0ca99061389b908890600401614cae565b5f60405180830381865afa1580156138b5573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f191682016040526138dc9190810190614ce5565b9350835f815181106138f0576138f0614a6d565b60200260200101515f1c98505088881115613a2a575f82815b82821115613a1d575f600261391e8585614a14565b6139289190614a4e565b6139329084614a14565b9050600281028501985088885f8151811061394f5761394f614a6d565b602090810291909101015260405163e57c0ca960e01b81526001600160a01b038b169063e57c0ca990613986908b90600401614cae565b5f60405180830381865afa1580156139a0573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f191682016040526139c79190810190614ce5565b9650865f815181106139db576139db614a6d565b60200260200101515f1c9b508c8c036139f957945060019050613a1d565b8c8c1015613a0957809350613a17565b613a14600182614a14565b92505b50613909565b80613a26578294505b5050505b600282028101945084845f81518110613a4557613a45614a6d565b602090810291909101015260405163e57c0ca960e01b81526001600160a01b0387169063e57c0ca990613a7c908790600401614cae565b5f60405180830381865afa158015613a96573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f19168201604052613abd9190810190614ce5565b9250825f81518110613ad157613ad1614a6d565b60200260200101515f1c9750600160028302820101945084845f81518110613afb57613afb614a6d565b602090810291909101015260405163e57c0ca960e01b81526001600160a01b0387169063e57c0ca990613b32908790600401614cae565b5f60405180830381865afa158015613b4c573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f19168201604052613b739190810190614ce5565b9250825f81518110613b8757613b87614a6d565b60200260200101515f1c96505050505050505b9250929050565b7fddab91076ea92d6a766cefd001b0cf5f73830986b100aa9c6fa6286e6b0a7302546040805160c0810182525f8082526020808301829052828401829052606083018290526080830182905260a083018290528351600180825281860190955291947ff047b0c59244a0faf8e48cb6b6fde518e6717176152b6dd953628cd9dccb2800946001600160a01b0390911693928692839290828101908036833701905050905060605f5f5f8862010008015f8e63ffffffff1681526020019081526020015f20905080955085855f81518110613c7d57613c7d614a6d565b602090810291909101015260405163e57c0ca960e01b81526001600160a01b0389169063e57c0ca990613cb4908890600401614cae565b5f60405180830381865afa158015613cce573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f19168201604052613cf59190810190614ce5565b9350835f81518110613d0957613d09614a6d565b60209081029190910181015160028e900b5f90815260068c01835260409081902090516004909101985062ffffff82841c16955063ffffffff9091169350879250613d69918f9184910163ffffffff929092168252602082015260400190565b60405160208183030381529060405280519060200120955085855f81518110613d9457613d94614a6d565b602090810291909101015260405163e57c0ca960e01b81526001600160a01b0389169063e57c0ca990613dcb908890600401614cae565b5f60405180830381865afa158015613de5573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f19168201604052613e0c9190810190614ce5565b9350835f81518110613e2057613e20614a6d565b60209081029190910101516001600160a01b0316604088015250600282810b908c900b13801590613e5c575060408601516001600160a01b0316155b15613f38575f81815262010008890160205260408120855190965086918291879190613e8a57613e8a614a6d565b602090810291909101015260405163e57c0ca960e01b81526001600160a01b0389169063e57c0ca990613ec1908890600401614cae565b5f60405180830381865afa158015613edb573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f19168201604052613f029190810190614ce5565b9350835f81518110613f1657613f16614a6d565b602090810291909101015160501c6001600160a01b0316604088018190529550505b60028a900b5f9081526006890160209081526040918290209151600490920196508691613f7a918f9184910163ffffffff929092168252602082015260400190565b60405160208183030381529060405280519060200120955085855f81518110613fa557613fa5614a6d565b602090810291909101015260405163e57c0ca960e01b81526001600160a01b0389169063e57c0ca990613fdc908890600401614cae565b5f60405180830381865afa158015613ff6573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f1916820160405261401d9190810190614ce5565b9350835f8151811061403157614031614a6d565b60209081029190910101516001600160a01b0316606088015250600282810b908b900b1380159061406d575060608601516001600160a01b0316155b15614149575f8181526201000889016020526040812085519096508691829187919061409b5761409b614a6d565b602090810291909101015260405163e57c0ca960e01b81526001600160a01b0389169063e57c0ca9906140d2908890600401614cae565b5f60405180830381865afa1580156140ec573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f191682016040526141139190810190614ce5565b9350835f8151811061412757614127614a6d565b602090810291909101015160501c6001600160a01b0316606088018190529550505b505063ffffffff8a165f9081526201000887016020526040812083519094508491829185919061417b5761417b614a6d565b602090810291909101015260405163e57c0ca960e01b81526001600160a01b0387169063e57c0ca9906141b2908690600401614cae565b5f60405180830381865afa1580156141cc573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f191682016040526141f39190810190614ce5565b9150815f8151811061420757614207614a6d565b602002602001015193505f8460b01b60e81c90508a60020b8160020b121561424357856060015186604001510398505050505050505050610a23565b8960020b8160020b121561429d57606086015160408701515f516020614dce5f395f51905f5263ffffffff8f165f908152600b9190910160205260409020546001600160a01b031603039850610a23975050505050505050565b856040015186606001510398505050505050505050610a23565b6060815f0180548060200260200160405190810160405280929190818152602001828054801561430457602002820191905f5260205f20905b8154815260200190600101908083116142f0575b50505050509050919050565b6001600160a01b0381168114614324575f5ffd5b50565b5f5f5f60608486031215614339575f5ffd5b833561434481614310565b95602085013595506040909401359392505050565b5f60208284031215614369575f5ffd5b8135610a2381614310565b5f5f83601f840112614384575f5ffd5b50813567ffffffffffffffff81111561439b575f5ffd5b6020830191508360208260051b8501011115613b9a575f5ffd5b8060020b8114614324575f5ffd5b5f5f5f5f5f5f5f5f60e0898b0312156143da575f5ffd5b88359750602089013567ffffffffffffffff8111156143f7575f5ffd5b6144038b828c01614374565b909850965050604089013561441781614310565b945060608901359350608089013561442e816143b5565b925060a089013561443e816143b5565b915060c089013561444e81614310565b809150509295985092959890939650565b5f5f60408385031215614470575f5ffd5b823561447b81614310565b946020939093013593505050565b5f5f6040838503121561449a575f5ffd5b82356144a581614310565b915060208301356144b581614310565b809150509250929050565b5f5f5f606084860312156144d2575f5ffd5b8335925060208401356144e481614310565b929592945050506040919091013590565b5f5f5f5f5f60808688031215614509575f5ffd5b85359450602086013567ffffffffffffffff811115614526575f5ffd5b61453288828901614374565b90955093505060408601359150606086013561454d81614310565b809150509295509295909350565b5f5f6040838503121561456c575f5ffd5b8235915060208301356144b581614310565b634e487b7160e01b5f52604160045260245ffd5b604051601f8201601f1916810167ffffffffffffffff811182821017156145bb576145bb61457e565b604052919050565b5f67ffffffffffffffff8211156145dc576145dc61457e565b5060051b60200190565b5f82601f8301126145f5575f5ffd5b8135614608614603826145c3565b614592565b8082825260208201915060208360051b860101925085831115614629575f5ffd5b602085015b8381101561464f57803561464181614310565b83526020928301920161462e565b5095945050505050565b5f5f5f6040848603121561466b575f5ffd5b833567ffffffffffffffff811115614681575f5ffd5b61468d86828701614374565b909450925050602084013567ffffffffffffffff8111156146ac575f5ffd5b6146b8868287016145e6565b9150509250925092565b5f5f5f5f608085870312156146d5575f5ffd5b84356146e081614310565b93506020850135925060408501356146f7816143b5565b91506060850135614707816143b5565b939692955090935050565b5f5f60408385031215614723575f5ffd5b82359150602083013567ffffffffffffffff811115614740575f5ffd5b61474c858286016145e6565b9150509250929050565b5f5f5f5f5f5f60a0878903121561476b575f5ffd5b863561477681614310565b955060208701359450604087013567ffffffffffffffff811115614798575f5ffd5b6147a489828a01614374565b9095509350506060870135915060808701356147bf81614310565b809150509295509295509295565b5f602082840312156147dd575f5ffd5b5035919050565b8015158114614324575f5ffd5b5f5f5f5f5f5f5f60e0888a031215614807575f5ffd5b87359650602088013561481981614310565b9550604088013561482981614310565b9450606088013593506080880135614840816143b5565b925060a0880135614850816143b5565b915060c0880135614860816147e4565b8091505092959891949750929550565b602080825282518282018190525f918401906040840190835b818110156148b05783516001600160a01b0316835260209384019390920191600101614889565b509095945050505050565b5f5f5f5f5f5f60c087890312156148d0575f5ffd5b86356148db81614310565b95506020870135945060408701356148f2816143b5565b93506060870135614902816143b5565b9250608087013567ffffffffffffffff81111561491d575f5ffd5b61492989828a016145e6565b92505060a08701356147bf81614310565b5f5f5f6060848603121561494c575f5ffd5b8335925060208401359150604084013561496581614310565b809150509250925092565b5f5f5f5f5f5f60c08789031215614985575f5ffd5b86359550602087013561499781614310565b945060408701356149a781614310565b93506060870135925060808701356149be816143b5565b915060a08701356147bf816143b5565b5f602082840312156149de575f5ffd5b8151610a2381614310565b5f602082840312156149f9575f5ffd5b5051919050565b634e487b7160e01b5f52601160045260245ffd5b81810381811115610c2057610c20614a00565b80820180821115610c2057610c20614a00565b634e487b7160e01b5f52601260045260245ffd5b5f82614a6857634e487b7160e01b5f52601260045260245ffd5b500490565b634e487b7160e01b5f52603260045260245ffd5b5f60208284031215614a91575f5ffd5b8151610a23816147e4565b80516fffffffffffffffffffffffffffffffff81168114614abb575f5ffd5b919050565b5f5f5f5f5f5f5f5f5f5f6101408b8d031215614ada575f5ffd5b8a51614ae581614310565b60208c0151909a50614af681614310565b60408c0151909950614b07816143b5565b60608c0151909850614b18816143b5565b60808c0151909750614b29816143b5565b9550614b3760a08c01614a9c565b60c08c015160e08d015191965094509250614b556101008c01614a9c565b9150614b646101208c01614a9c565b90509295989b9194979a5092959850565b5f60018201614b8657614b86614a00565b5060010190565b805161ffff81168114614abb575f5ffd5b5f5f5f5f5f5f5f60e0888a031215614bb4575f5ffd5b8751614bbf81614310565b6020890151909750614bd0816143b5565b9550614bde60408901614b8d565b9450614bec60608901614b8d565b9350614bfa60808901614b8d565b925060a088015162ffffff81168114614c11575f5ffd5b60c0890151909250614860816147e4565b8082028115828204841417610c2057610c20614a00565b5f5f5f5f60808587031215614c4c575f5ffd5b845163ffffffff81168114614c5f575f5ffd5b8094505060208501518060060b8114614c76575f5ffd5b6040860151909350614c8781614310565b6060860151909250614707816147e4565b5f82518060208501845e5f920191825250919050565b602080825282518282018190525f918401906040840190835b818110156148b0578351835260209384019390920191600101614cc7565b5f60208284031215614cf5575f5ffd5b815167ffffffffffffffff811115614d0b575f5ffd5b8201601f81018413614d1b575f5ffd5b8051614d29614603826145c3565b8082825260208201915060208360051b850101925086831115614d4a575f5ffd5b6020840193505b82841015612b26578351825260209384019390910190614d51565b601382810b9082900b03737fffffffffffffffffffffffffffffffffffffff198112737fffffffffffffffffffffffffffffffffffffff82131715610c2057610c20614a00565b5f600160ff1b8201614dc757614dc7614a00565b505f039056feddab91076ea92d6a766cefd001b0cf5f73830986b100aa9c6fa6286e6b0a7300a26469706673582212205e8a7cbc28c3831f07312a3c3c6bcd492c3abbb73d47787fedb02ed8e30c402164736f6c634300081c003360a060405260405161057738038061057783398101604081905261002291610354565b61002c828261003e565b506001600160a01b0316608052610445565b610047826100fb565b6040516001600160a01b038316907f1cf3b03a6cf19fa2baba4df148e9dcabedea7f8a5c07840e207e5c089be95d3e905f90a28051156100ef576100ea826001600160a01b0316635c60da1b6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156100c0573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906100e49190610416565b82610209565b505050565b6100f761027c565b5050565b806001600160a01b03163b5f0361013557604051631933b43b60e21b81526001600160a01b03821660048201526024015b60405180910390fd5b807fa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d5080546001600160a01b0319166001600160a01b0392831617905560408051635c60da1b60e01b815290515f92841691635c60da1b9160048083019260209291908290030181865afa1580156101ae573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906101d29190610416565b9050806001600160a01b03163b5f036100f757604051634c9c8ce360e01b81526001600160a01b038216600482015260240161012c565b60605f5f846001600160a01b031684604051610225919061042f565b5f60405180830381855af49150503d805f811461025d576040519150601f19603f3d011682016040523d82523d5f602084013e610262565b606091505b50909250905061027385838361029d565b95945050505050565b341561029b5760405163b398979f60e01b815260040160405180910390fd5b565b6060826102b2576102ad826102fc565b6102f5565b81511580156102c957506001600160a01b0384163b155b156102f257604051639996b31560e01b81526001600160a01b038516600482015260240161012c565b50805b9392505050565b80511561030c5780518082602001fd5b60405163d6bda27560e01b815260040160405180910390fd5b80516001600160a01b038116811461033b575f5ffd5b919050565b634e487b7160e01b5f52604160045260245ffd5b5f5f60408385031215610365575f5ffd5b61036e83610325565b60208401519092506001600160401b03811115610389575f5ffd5b8301601f81018513610399575f5ffd5b80516001600160401b038111156103b2576103b2610340565b604051601f8201601f19908116603f011681016001600160401b03811182821017156103e0576103e0610340565b6040528181528282016020018710156103f7575f5ffd5b8160208401602083015e5f602083830101528093505050509250929050565b5f60208284031215610426575f5ffd5b6102f582610325565b5f82518060208501845e5f920191825250919050565b60805161011b61045c5f395f601d015261011b5ff3fe6080604052600a600c565b005b60186014601a565b609d565b565b5f7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316635c60da1b6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156076573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906098919060ba565b905090565b365f5f375f5f365f845af43d5f5f3e80801560b6573d5ff35b3d5ffd5b5f6020828403121560c9575f5ffd5b81516001600160a01b038116811460de575f5ffd5b939250505056fea26469706673582212204d9471f2016d028d1d1f4816bb78c0f5049d528195c75b1745670d8620fd2b0c64736f6c634300081c0033a264697066735822122002c3ea8cec6f8de8364561e9fb19ca414cf8ea119da426a1315ad3f8269914f264736f6c634300081c0033

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

00000000000000000000000012e66c8f215ddd5d48d150c8f46ad0c6fb0f44060000000000000000000000009f59398d0a397b2eeb8a6123a6c7295cb0b0062d000000000000000000000000949e7b2f3f66eae761a9397346ddbd719f046c0e

-----Decoded View---------------
Arg [0] : _nfpManager (address): 0x12E66C8F215DdD5d48d150c8f46aD0c6fB0F4406
Arg [1] : _voter (address): 0x9F59398D0a397b2EEB8a6123a6c7295cB0b0062D
Arg [2] : _feeCollector (address): 0x949E7B2F3F66EAe761a9397346dDbd719F046c0e

-----Encoded View---------------
3 Constructor Arguments found :
Arg [0] : 00000000000000000000000012e66c8f215ddd5d48d150c8f46ad0c6fb0f4406
Arg [1] : 0000000000000000000000009f59398d0a397b2eeb8a6123a6c7295cb0b0062d
Arg [2] : 000000000000000000000000949e7b2f3f66eae761a9397346ddbd719f046c0e


Block Transaction Gas Used Reward
view all blocks produced

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

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
[ 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.