ETH Price: $3,457.36 (+4.60%)

Contract

0x2Eb89D4dA0B47fCCC9B4B1ee7cA56e1565D1Bbb0
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

More Info

Private Name Tags

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
Close First Elig...235130312025-10-05 17:22:1133 days ago1759684931IN
0x2Eb89D4d...565D1Bbb0
0 ETH0.000090310.12813071
Close First Elig...235129182025-10-05 16:59:3533 days ago1759683575IN
0x2Eb89D4d...565D1Bbb0
0 ETH0.000136130.19315295
Close First Elig...235128492025-10-05 16:45:4733 days ago1759682747IN
0x2Eb89D4d...565D1Bbb0
0 ETH0.000096650.13732467
Close First Elig...235128012025-10-05 16:36:1133 days ago1759682171IN
0x2Eb89D4d...565D1Bbb0
0 ETH0.000715181.01456458
Close First Elig...235127792025-10-05 16:31:4733 days ago1759681907IN
0x2Eb89D4d...565D1Bbb0
0 ETH0.000094160.13378694
Open If Threshol...235127702025-10-05 16:29:5933 days ago1759681799IN
0x2Eb89D4d...565D1Bbb0
0 ETH0.000003990.11707915
Close First Elig...235126372025-10-05 16:03:2333 days ago1759680203IN
0x2Eb89D4d...565D1Bbb0
0 ETH0.000085360.12288571
Close First Elig...235125762025-10-05 15:51:1133 days ago1759679471IN
0x2Eb89D4d...565D1Bbb0
0 ETH0.000826841.18845316
Close First Elig...235124412025-10-05 15:23:3533 days ago1759677815IN
0x2Eb89D4d...565D1Bbb0
0 ETH0.000839051.2246916
Close First Elig...235124402025-10-05 15:23:2333 days ago1759677803IN
0x2Eb89D4d...565D1Bbb0
0 ETH0.000822261.20018261
Close First Elig...235123432025-10-05 15:03:4733 days ago1759676627IN
0x2Eb89D4d...565D1Bbb0
0 ETH0.000086470.12603659
Close First Elig...235120462025-10-05 14:03:5933 days ago1759673039IN
0x2Eb89D4d...565D1Bbb0
0 ETH0.000090150.13325059
Close First Elig...235119012025-10-05 13:34:5933 days ago1759671299IN
0x2Eb89D4d...565D1Bbb0
0 ETH0.000084480.12677437
Close First Elig...235118752025-10-05 13:29:4733 days ago1759670987IN
0x2Eb89D4d...565D1Bbb0
0 ETH0.000082710.12568626
Close First Elig...235117742025-10-05 13:09:3533 days ago1759669775IN
0x2Eb89D4d...565D1Bbb0
0 ETH0.000078140.11876142
Close First Elig...235112812025-10-05 11:30:5933 days ago1759663859IN
0x2Eb89D4d...565D1Bbb0
0 ETH0.000073410.12012164
Open If Threshol...235110072025-10-05 10:36:1133 days ago1759660571IN
0x2Eb89D4d...565D1Bbb0
0 ETH0.000038341.12377343
Open If Threshol...235108262025-10-05 9:59:4733 days ago1759658387IN
0x2Eb89D4d...565D1Bbb0
0 ETH0.000038781.13667419
Open If Threshol...235107022025-10-05 9:34:5933 days ago1759656899IN
0x2Eb89D4d...565D1Bbb0
0 ETH0.000005020.14713109
Close First Elig...235102622025-10-05 8:06:2333 days ago1759651583IN
0x2Eb89D4d...565D1Bbb0
0 ETH0.000088730.21872533
Close First Elig...235037752025-10-04 10:19:4734 days ago1759573187IN
0x2Eb89D4d...565D1Bbb0
0 ETH0.000042621.49480759
Set Min Weth To ...235006642025-10-03 23:53:4734 days ago1759535627IN
0x2Eb89D4d...565D1Bbb0
0 ETH0.000004550.14250497
Set Min Position...235006592025-10-03 23:52:4734 days ago1759535567IN
0x2Eb89D4d...565D1Bbb0
0 ETH0.000004320.14456609
Transfer235006312025-10-03 23:47:1134 days ago1759535231IN
0x2Eb89D4d...565D1Bbb0
0.26 ETH0.000057341.00512577
Set Eth Sender A...235006242025-10-03 23:45:4734 days ago1759535147IN
0x2Eb89D4d...565D1Bbb0
0 ETH0.000008320.17372278
View all transactions

Latest 25 internal transactions (View All)

Advanced mode:
Parent Transaction Hash Method Block
From
To
Deposit237489972025-11-07 17:52:112 hrs ago1762537931
0x2Eb89D4d...565D1Bbb0
0.08230243 ETH
Transfer237489972025-11-07 17:52:112 hrs ago1762537931
0x2Eb89D4d...565D1Bbb0
0.08230243 ETH
Deposit237480252025-11-07 14:36:116 hrs ago1762526171
0x2Eb89D4d...565D1Bbb0
0.04092009 ETH
Transfer237480252025-11-07 14:36:116 hrs ago1762526171
0x2Eb89D4d...565D1Bbb0
0.04092009 ETH
Deposit237478622025-11-07 14:03:236 hrs ago1762524203
0x2Eb89D4d...565D1Bbb0
0.06940026 ETH
Transfer237478622025-11-07 14:03:236 hrs ago1762524203
0x2Eb89D4d...565D1Bbb0
0.06940026 ETH
Deposit237453552025-11-07 5:37:5915 hrs ago1762493879
0x2Eb89D4d...565D1Bbb0
0.02570455 ETH
Transfer237453552025-11-07 5:37:5915 hrs ago1762493879
0x2Eb89D4d...565D1Bbb0
0.02570455 ETH
Deposit237439902025-11-07 1:02:3519 hrs ago1762477355
0x2Eb89D4d...565D1Bbb0
0.00763082 ETH
Transfer237439902025-11-07 1:02:3519 hrs ago1762477355
0x2Eb89D4d...565D1Bbb0
0.00763082 ETH
Deposit237435212025-11-06 23:28:3521 hrs ago1762471715
0x2Eb89D4d...565D1Bbb0
0.017556 ETH
Transfer237435212025-11-06 23:28:3521 hrs ago1762471715
0x2Eb89D4d...565D1Bbb0
0.017556 ETH
Deposit237425292025-11-06 20:08:4724 hrs ago1762459727
0x2Eb89D4d...565D1Bbb0
0.02314298 ETH
Transfer237425292025-11-06 20:08:4724 hrs ago1762459727
0x2Eb89D4d...565D1Bbb0
0.02314298 ETH
Deposit237416222025-11-06 17:06:4727 hrs ago1762448807
0x2Eb89D4d...565D1Bbb0
0.10133318 ETH
Transfer237416222025-11-06 17:06:4727 hrs ago1762448807
0x2Eb89D4d...565D1Bbb0
0.10133318 ETH
Deposit237400632025-11-06 11:52:3532 hrs ago1762429955
0x2Eb89D4d...565D1Bbb0
0.03387508 ETH
Transfer237400632025-11-06 11:52:3532 hrs ago1762429955
0x2Eb89D4d...565D1Bbb0
0.03387508 ETH
Deposit237374652025-11-06 3:09:2341 hrs ago1762398563
0x2Eb89D4d...565D1Bbb0
0.021546 ETH
Transfer237374652025-11-06 3:09:2341 hrs ago1762398563
0x2Eb89D4d...565D1Bbb0
0.021546 ETH
Deposit237360272025-11-05 22:18:5946 hrs ago1762381139
0x2Eb89D4d...565D1Bbb0
0.06307214 ETH
Transfer237360272025-11-05 22:18:5946 hrs ago1762381139
0x2Eb89D4d...565D1Bbb0
0.06307214 ETH
Deposit237355362025-11-05 20:39:592 days ago1762375199
0x2Eb89D4d...565D1Bbb0
0.01596 ETH
Transfer237355362025-11-05 20:39:592 days ago1762375199
0x2Eb89D4d...565D1Bbb0
0.01596 ETH
Swap Exact Token...237343792025-11-05 16:47:112 days ago1762361231
0x2Eb89D4d...565D1Bbb0
2.99816139 ETH
View All Internal Transactions
Loading...
Loading
Cross-Chain Transactions

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
Treasury

Compiler Version
v0.8.28+commit.7893614a

Optimization Enabled:
Yes with 200 runs

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

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {IUniswapV4Router04} from "./interfaces/IUniswapV4Router04.sol";
import {Currency} from "@uniswap/v4-periphery/lib/v4-core/src/types/Currency.sol";
import {PoolKey} from "@uniswap/v4-periphery/lib/v4-core/src/types/PoolKey.sol";
import {IHooks} from "@uniswap/v4-periphery/lib/v4-core/src/interfaces/IHooks.sol";
import {IWETH9} from "./interfaces/IWETH9.sol";
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";

interface IStrategyToken is IERC20 {
    function burn(uint256 amount) external;
}

contract Treasury is Ownable, ReentrancyGuard {
    using SafeERC20 for IERC20;

    uint256 public constant BPS = 10_000;
    uint256 public constant devSliceParts = 2; // split of fee that will go to the devWallet
    uint256 public constant stratSliceParts = 8; // split of fee that will be invested into PNKSTR
    uint256 public constant TOTAL_PARTS = 10; // sanity check - parts must sum to 10
    uint256 public constant PROCESS_PROBE_BPS = 50; // micro-probe size
    uint256 public constant MIN_PROBE_ABS = 1e15; // 0.001 token (18 decimals)

    IStrategyToken public immutable STRPNK; // our token
    IERC20 public constant WETH =
        IERC20(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2); // WETH/ETH
    IERC20 public constant PNKSTR =
        IERC20(0xc50673EDb3A7b94E8CAD8a7d4E0cD68864E33eDF); // Punk Strategy
    address payable private constant DEV =
        payable(0xA926C8d1F5Df9E34E3aB01FB06884fD18CD5E867); // dev wallet address
    address public constant POOL_MANAGER =
        0x000000000004444c5dc75cB358380D2e3dE08A90; // canonical V4 PoolManager

    uint256 public min_position_weth = 0.1 ether;
    uint256 public constant MAX_POSITION_WETH = 10 ether; // maximum amount of WETH per position - larger means more price impact per trade
    uint256 public constant TARGET_PROFIT_OUT_BPS = 10_530; // profit target to close $PNKSTR position - 30%
    uint256 public minWethToOpen = 0.25 ether; // do not buy $PNKSTR until treasury accumulates this amount
    uint256 public constant MAX_OPEN_POSITIONS = 20; // max number of open positions before consolidating - this is implemented to keep loops bounded to avoid gas exhaustion
    uint256 public constant MAX_CONSOLIDATIONS = 3; // number of positions that can be consolidated when opening new ones - safety mechanism to avoid gas exhaustion, should not ever hit the cap unless treasury is allowed to accumulate significant ETH before open position is called
    uint256 public caller_bounty_bps = 50; // reward paid to caller of process/open/close functions (0.5%)
    uint256 public constant MAX_BOUNTY_WETH = 0.05 ether; // guard for maximum bounty paid
    uint256 public constant minProcessingSTRPNK = 5_000_000e18; // minimum amount of STRPNK in treasury before processFees() can be called
    uint256 public constant processSlippageBps = 8_800; // tolerable slippage when processing fees
    uint256 public constant swapDeadlineSeconds = 120; // timeout for swaps/transfers in seconds

    // lifetime stats
    uint256 public totalOpenedPositions;
    uint256 public totalClosedPositions;
    uint256 public cumulativeWethCost; // sum of costWeth for all opened positions
    uint256 public cumulativeWethProceeds; // sum of WETH received when closing
    uint256 public sumOpenCostWeth; // live total cost of open positions

    struct Position {
        uint256 amountPNKSTR;
        uint256 costWeth;
        bool open;
    }

    // V4 Uniswap
    struct V4Route {
        address router; // Uniswap v4 router
        address hook; // pool hook address
        uint24 fee; // lp fee (0-10000) - we use no fee on LP because of tax collected at hook
        int24 tickSpacing; // spacing - 60
        bool frozen;
    }

    mapping(address => V4Route) public v4Routes; //token -> route
    mapping(address => bool) public ethSenderAllowed;
    event EthSenderAllowed(address indexed a, bool allowed);

    Position[] public positions;
    uint256[] public openIds;
    mapping(uint256 => uint256) public idx;

    event Processed(
        uint256 STRPNKIn,
        uint256 WETHOut,
        uint256 devWethSent,
        address caller,
        uint256 bounty
    );
    event Opened(uint256 id, uint256 amountPNKSTR, uint256 costWeth);
    event Closed(
        uint256 id,
        uint256 proceedsWeth,
        uint256 burned,
        address caller,
        uint256 bounty
    );
    event Consolidated(
        uint256 idKept,
        uint256 idMerged,
        uint256 newPNKSTRAmount,
        uint256 newCost
    );
    event OpenAttempt(
        uint256 wethBalance,
        uint256 wethUsed,
        uint256 positionsOpened,
        address caller,
        uint256 bounty
    );

    event V4RouteSet(
        address indexed token,
        address router,
        address hook,
        uint24 fee,
        int24 spacing
    );
    event V4RouteFrozen(address indexed token);
    event V4RouteDeleted(address indexed token);
    event CallerBountyUpdated(uint256 bps);

    event MinWethToOpenUpdated(uint256 newValue);
    event MinPositionWethUpdated(uint256 newValue);

    error PMOnly();
    error NoEligiblePositions();

    constructor(address strategyToken) Ownable(msg.sender) {
        require(strategyToken != address(0), "addr=0");
        STRPNK = IStrategyToken(strategyToken);
    }

    function setEthSenderAllowed(address a, bool allowed) external onlyOwner {
        ethSenderAllowed[a] = allowed;
        emit EthSenderAllowed(a, allowed);
    }

    function setBountyBps(uint256 newBps) external onlyOwner {
        require(newBps < BPS, "bps>BPS");
        require(newBps >= 50, "bps<50");
        caller_bounty_bps = newBps;
        emit CallerBountyUpdated(newBps);
    }

    // V4 Uniswap Router Admin functions
    function setV4Route(
        address token,
        address router_,
        address hook_,
        uint24 fee_,
        int24 spacing_
    ) external onlyOwner {
        require(token != address(0), "token=0");
        require(router_ != address(0), "v4 router=0");
        require(hook_ != address(0), "v4 hook=0");

        V4Route storage route = v4Routes[token];
        require(!route.frozen, "frozen");

        route.router = router_;
        route.hook = hook_;
        route.fee = fee_;
        route.tickSpacing = spacing_;
        route.frozen = false;

        ethSenderAllowed[router_] = true;
        ethSenderAllowed[hook_] = true;

        emit V4RouteSet(token, router_, hook_, fee_, spacing_);
    }

    function freezeV4Route(address token) external onlyOwner {
        V4Route storage route = v4Routes[token];
        require(!route.frozen, "already");
        route.frozen = true;
        emit V4RouteFrozen(token);
    }

    // admin failsafe to clear out a bad route so it can be recreated during deployment
    function deleteV4Route(address token) external onlyOwner {
        delete v4Routes[token];
        emit V4RouteDeleted(token);
    }

    function setMinWethToOpen(uint256 newMin) external onlyOwner {
        require(newMin >= 0.01 ether, "min too low");
        require(newMin <= 10 ether, "min too high");
        require(newMin >= min_position_weth, "min below position floor");
        minWethToOpen = newMin;
        emit MinWethToOpenUpdated(newMin);
    }

    function setMinPositionWeth(uint256 newMin) external onlyOwner {
        require(newMin <= MAX_POSITION_WETH, "min too high");
        require(newMin >= 0.01 ether, "min too low");
        min_position_weth = newMin;
        emit MinPositionWethUpdated(newMin);
    }

    // auto-wrap all ETH received from the hook into WETH
    receive() external payable {
        address s = msg.sender;
        if (s != POOL_MANAGER && s != address(WETH) && !ethSenderAllowed[s])
            revert PMOnly();
        // If it's coming from WETH.withdraw, do not re-wrap.
        if (s != address(WETH) && msg.value > 0) {
            IWETH9(address(WETH)).deposit{value: msg.value}();
        }
    }

    // salvage raw ETH forced into the account by selfdestruct
    function wrapStuckETH() external {
        _autoWrap();
    }

    function _autoWrap() internal {
        uint256 bal = address(this).balance;
        if (bal > 0) {
            IWETH9(address(WETH)).deposit{value: bal}();
        }
    }

    // Getter for all managed positions
    function getPosition(
        uint256 id
    )
        external
        view
        returns (uint256 amountPNKSTR, uint256 costWeth, bool open)
    {
        Position storage p = positions[id];
        return (p.amountPNKSTR, p.costWeth, p.open);
    }

    // Getter for all open managed positions
    function getOpenPositions()
        external
        view
        returns (
            uint256[] memory ids,
            uint256[] memory amountPNKSTR,
            uint256[] memory costWeth
        )
    {
        uint256 n = openIds.length;
        ids = new uint256[](n);
        amountPNKSTR = new uint256[](n);
        costWeth = new uint256[](n);
        for (uint256 i; i < n; ++i) {
            uint256 id = openIds[i];
            ids[i] = id;
            Position storage p = positions[id];
            amountPNKSTR[i] = p.amountPNKSTR;
            costWeth[i] = p.costWeth;
        }
    }

    // Core Flows
    /// Anyone can process accrued fees if the treasury has accrued enough
    function processFees() external nonReentrant {
        uint256 amt = STRPNK.balanceOf(address(this));
        require(amt >= minProcessingSTRPNK, "amt too low");

        uint256 gotW = _v4SellFeesWithProbe(address(STRPNK), amt); // returns WETH
        require(gotW > 0, "no WETH");

        // reward bounty to caller
        uint256 bounty = _calcBounty(gotW);
        if (bounty > 0) {
            WETH.safeTransfer(msg.sender, bounty);
            gotW -= bounty;
        }

        // split WETH between dev and PNKSTR
        uint256 devWeth = Math.mulDiv(gotW, devSliceParts, TOTAL_PARTS);

        if (devWeth > 0) {
            WETH.safeTransfer(DEV, devWeth);
        }
        emit Processed(amt, gotW + bounty, devWeth, msg.sender, bounty);
    }

    /// Anyone can open positions if the treasury has accumulated enough WETH - chunked open - enforces cap
    function openIfThreshold() external nonReentrant {
        _autoWrap();

        uint256 wethBal = WETH.balanceOf(address(this));
        require(wethBal >= minWethToOpen, "below threshold");

        // pay bounty up front
        uint256 bounty = _calcBounty(wethBal);
        uint256 planned = wethBal - bounty;

        require(planned >= min_position_weth, "insufficient for min position");

        if (bounty > 0) {
            WETH.safeTransfer(msg.sender, bounty);
        }

        // open positions
        (uint256 used, uint256 opened) = _openWithWeth(planned);
        emit OpenAttempt(wethBal, used, opened, msg.sender, bounty);
    }

    /// @notice Close first eligible position found - this will need to be called repeatedly if multiple positions are eligible to be closed at the same time
    function closeFirstEligible() external nonReentrant {
        uint256 n = openIds.length;
        if (n == 0) revert NoEligiblePositions();

        uint256[] memory candidates = _selectCheapestOpenIndices();
        uint256 m = candidates.length;
        if (m == 0) revert NoEligiblePositions();

        for (uint256 i = 0; i < m; i++) {
            uint256 openIndex = candidates[i];
            uint256 id = openIds[openIndex];
            Position storage p = positions[id];
            if (!p.open || p.amountPNKSTR == 0) continue;

            // profit threshold: min proceeds required to close
            // required WETH >= costWeth * targetProfitBps / BPS
            uint256 minOutForTarget = Math.mulDiv(
                p.costWeth,
                TARGET_PROFIT_OUT_BPS,
                BPS
            );

            // best-effort sell: router will revert if threshold cannot be met
            (bool ok, uint256 gotW) = _v4SellForWeth(
                address(PNKSTR),
                p.amountPNKSTR,
                minOutForTarget
            );
            if (!ok) {
                // position could not be closed
                continue;
            }

            // success: finalize close
            p.open = false;
            _removeOpenIdByIndex(openIndex);

            totalClosedPositions += 1;
            cumulativeWethProceeds += gotW;
            sumOpenCostWeth -= p.costWeth;

            // reward bounty
            uint256 bounty = _calcBounty(gotW);
            if (bounty > 0) {
                WETH.safeTransfer(msg.sender, bounty);
                gotW -= bounty;
            }

            // buy and burn STRPNK
            uint256 bought = _v4BuyWithWeth(address(STRPNK), gotW, 0);
            require(bought > 0, "no STRPNK");

            // burn everything we bought
            STRPNK.burn(bought);
            emit Closed(id, gotW + bounty, bought, msg.sender, bounty);
            return; // close only one position per function call
        }
        revert NoEligiblePositions();
    }

    // open position with consolidation helper
    function _openWithWeth(
        uint256 wethAmount
    ) internal returns (uint256 used, uint256 opened) {
        uint256 remaining = wethAmount;
        uint256 consolidations = 0;

        while (remaining >= min_position_weth) {
            // check capacity and free slot if possible
            if (openIds.length >= MAX_OPEN_POSITIONS) {
                // safety - bound the function to avoid gas exhaustion
                if (consolidations >= MAX_CONSOLIDATIONS) break;
                _consolidatePositions();
                consolidations++;
                // if consolidation failed, stop
                if (openIds.length >= MAX_OPEN_POSITIONS) break;
            }

            // size chunk appropriately
            uint256 chunk = remaining > MAX_POSITION_WETH
                ? MAX_POSITION_WETH
                : remaining;

            // price agnostic swap WETH -> PNKSTR (v4)
            uint256 got = _v4BuyWithWeth(address(PNKSTR), chunk, 0);

            // record position
            uint256 id = positions.length;
            positions.push(
                Position({amountPNKSTR: got, costWeth: chunk, open: true})
            );
            idx[id] = openIds.length;
            openIds.push(id);

            totalOpenedPositions += 1;
            cumulativeWethCost += chunk;
            sumOpenCostWeth += chunk;

            emit Opened(id, got, chunk);

            opened += 1;
            used += chunk;
            remaining -= chunk;
        }
    }

    /// @dev Merge the worst cost basis with best cost basis to narrow dispersion.
    function _consolidatePositions() internal {
        if (openIds.length < 2) return;

        bool haveMin = false;
        bool haveMax = false;

        uint256 minPrice;
        uint256 maxPrice;
        uint256 minId;
        uint256 maxId;

        for (uint256 i = 0; i < openIds.length; i++) {
            uint256 id = openIds[i];
            Position storage p = positions[id];
            if (!p.open || p.amountPNKSTR == 0) continue;

            uint256 up = Math.mulDiv(p.costWeth, 1e18, p.amountPNKSTR);
            if (!haveMin || up < minPrice) {
                haveMin = true;
                minPrice = up;
                minId = id;
            }
            if (!haveMax || up > maxPrice) {
                haveMax = true;
                maxPrice = up;
                maxId = id;
            }
        }

        if (!haveMin || !haveMax || minId == maxId) return;

        // merge higher price into lower
        Position storage a = positions[minId];
        Position storage b = positions[maxId];

        a.amountPNKSTR += b.amountPNKSTR;
        a.costWeth += b.costWeth;

        b.open = false;
        _removeOpenId(maxId);

        emit Consolidated(minId, maxId, a.amountPNKSTR, a.costWeth);
    }

    // internal helpers

    function _removeOpenId(uint256 id) internal {
        uint256 i = idx[id];
        _removeOpenIdByIndex(i);
    }

    function _removeOpenIdByIndex(uint256 i) internal {
        uint256 last = openIds[openIds.length - 1];
        uint256 id = openIds[i];
        openIds[i] = last;
        idx[last] = i;
        openIds.pop();
        delete idx[id];
    }

    // allowances and utility functions

    // catches wrong address passed early and reverts
    function _requireContract(address a, string memory what) private view {
        require(a.code.length > 0, what);
    }

    function _approveExact(
        address token,
        address spender,
        uint256 amount
    ) internal {
        _requireContract(token, "approve: token !contract");
        _requireContract(spender, "approve: spender !contract");
        IERC20 t = IERC20(token);
        uint256 curr = t.allowance(address(this), spender);
        if (curr < amount) {
            // zero-first pattern for USDT-like tokens
            t.forceApprove(spender, 0);
            t.forceApprove(spender, amount);
        }
    }

    function _calcBounty(uint256 baseWETH) internal view returns (uint256) {
        uint256 bounty = Math.mulDiv(baseWETH, caller_bounty_bps, BPS);
        if (bounty > MAX_BOUNTY_WETH) return MAX_BOUNTY_WETH;
        if (bounty > baseWETH) return baseWETH;
        return bounty;
    }

    function positionsCount() external view returns (uint256) {
        return positions.length;
    }

    function openCount() external view returns (uint256) {
        return openIds.length;
    }

    // V4 Uniswap Helpers
    function _v4Key(address token) internal view returns (PoolKey memory key) {
        V4Route storage route = v4Routes[token];
        require(route.frozen, "route not frozen");
        require(
            route.router != address(0) &&
                route.hook != address(0) &&
                route.tickSpacing != 0,
            "v4 incomplete"
        );
        key = PoolKey({
            currency0: Currency.wrap(address(0)), // ETH
            currency1: Currency.wrap(token), // ERC20 side
            fee: route.fee,
            tickSpacing: route.tickSpacing,
            hooks: IHooks(route.hook)
        });
        // extra sanity: ensure we set ETH first
        require(Currency.unwrap(key.currency0) == address(0), "bad key order");
    }

    function _v4BuyWithWeth(
        address token, // ERC20 being bought
        uint256 wethIn,
        uint256 minOutToken
    ) internal returns (uint256 gotToken) {
        V4Route storage route = v4Routes[token];
        require(
            route.router != address(0) &&
                route.hook != address(0) &&
                route.tickSpacing != 0,
            "v4 incomplete"
        );

        // unwrap WETH to native ETH
        IWETH9(address(WETH)).withdraw(wethIn);

        PoolKey memory key = _v4Key(token);
        int256 out = IUniswapV4Router04(route.router).swapExactTokensForTokens{
            value: wethIn
        }(
            wethIn,
            minOutToken,
            true, // exact input
            key,
            "",
            address(this),
            block.timestamp + swapDeadlineSeconds
        );
        require(out > 0, "v4: amountOut<=0");
        gotToken = uint256(out);
    }

    function _v4SellForWeth(
        address token, // ERC20 being sold
        uint256 tokenIn,
        uint256 minOutWeth
    ) internal returns (bool ok, uint256 gotWeth) {
        V4Route storage route = v4Routes[token];
        require(
            route.router != address(0) &&
                route.hook != address(0) &&
                route.tickSpacing != 0,
            "v4 incomplete"
        );

        PoolKey memory key = _v4Key(token);

        // best effort to support price target without Oracle lookup - if router reverts, catch and return (false, 0)
        _approveExact(token, route.router, tokenIn);
        try
            IUniswapV4Router04(route.router).swapExactTokensForTokens(
                tokenIn,
                minOutWeth,
                true, // exact input
                key,
                "",
                address(this),
                block.timestamp + swapDeadlineSeconds
            )
        returns (int256 out) {
            if (out <= 0) {
                return (false, 0);
            }
            uint256 ethOut = uint256(out);

            return (true, ethOut);
        } catch {
            return (false, 0);
        }
    }

    // STRPNK -> WETH fee processing without an oracle
    // sell a tiny probe chunk with minOut = 0 to learn an effective rate.
    // apply processSlippageBps to that rate and sell the remainder with amountOutMin
    // fees are generally taken in ETH so this may never run
    function _v4SellFeesWithProbe(
        address token,
        uint256 amt
    ) internal returns (uint256 gotWeth) {
        // route must be configured
        V4Route storage route = v4Routes[token];
        require(
            route.router != address(0) &&
                route.hook != address(0) &&
                route.tickSpacing != 0,
            "v4 incomplete"
        );

        // if whole amount is small, just swap once
        if (amt <= MIN_PROBE_ABS) {
            (bool okSmall, uint256 gotSmall) = _v4SellForWeth(token, amt, 0);
            require(okSmall, "probe-only swap failed");
            return gotSmall;
        }

        uint256 probeIn = Math.mulDiv(amt, PROCESS_PROBE_BPS, BPS);
        if (probeIn == 0) probeIn = MIN_PROBE_ABS;

        if (probeIn >= amt) {
            (bool okSingle, uint256 gotSingle) = _v4SellForWeth(token, amt, 0);
            require(okSingle, "single swap failed");
            return gotSingle;
        }

        (bool okProbe, uint256 outProbe) = _v4SellForWeth(token, probeIn, 0);
        require(okProbe && outProbe > 0, "probe=0");

        uint256 rate = Math.mulDiv(outProbe, 1e18, probeIn);

        uint256 restIn = amt - probeIn;
        uint256 expectedRest = Math.mulDiv(restIn, rate, 1e18);
        uint256 minRest = Math.mulDiv(expectedRest, processSlippageBps, BPS);

        (bool okRest, uint256 outRest) = _v4SellForWeth(token, restIn, minRest);
        require(okRest, "rest swap slippage");

        gotWeth = outProbe + outRest;
    }

    /// @dev Return up to the 3 cheapest open positions by unit cost (WETH per PNKSTR).
    ///      The values returned are indices into `openIds` (not position ids).
    function _selectCheapestOpenIndices()
        internal
        view
        returns (uint256[] memory chosen)
    {
        uint256 INF = type(uint256).max;

        // Track the 3 cheapest (price, openId Indices). INF = unset.
        uint256 p1 = INF;
        uint256 i1 = INF;
        uint256 p2 = INF;
        uint256 i2 = INF;
        uint256 p3 = INF;
        uint256 i3 = INF;

        uint256 n = openIds.length;
        for (uint256 i = 0; i < n; i++) {
            uint256 id = openIds[i];
            Position storage p = positions[id];
            if (!p.open || p.amountPNKSTR == 0) continue;

            // unit cost = WETH per PNKSTR (scaled 1e18)
            uint256 up = Math.mulDiv(p.costWeth, 1e18, p.amountPNKSTR);

            // Insert into top-3 (ascending). Single-pass.
            if (up < p1) {
                // shift down
                p3 = p2;
                i3 = i2;
                p2 = p1;
                i2 = i1;
                p1 = up;
                i1 = i;
            } else if (up < p2) {
                p3 = p2;
                i3 = i2;
                p2 = up;
                i2 = i;
            } else if (up < p3) {
                p3 = up;
                i3 = i;
            }
        }

        // Count how many valid picks we actually have (<= k)
        uint256 m;
        if (i1 != INF) m++;
        if (i2 != INF) m++;
        if (i3 != INF) m++;
        if (m == 0) return new uint256[](0);

        chosen = new uint256[](m);
        uint256 j;
        if (i1 != INF) chosen[j++] = i1;
        if (i2 != INF) chosen[j++] = i2;
        if (i3 != INF) chosen[j++] = i3;
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)

pragma solidity ^0.8.20;

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

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * The initial owner is set to the address provided by the deployer. This can
 * later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    /**
     * @dev The caller account is not authorized to perform an operation.
     */
    error OwnableUnauthorizedAccount(address account);

    /**
     * @dev The owner is not a valid owner account. (eg. `address(0)`)
     */
    error OwnableInvalidOwner(address owner);

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the address provided by the deployer as the initial owner.
     */
    constructor(address initialOwner) {
        if (initialOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(initialOwner);
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        if (owner() != _msgSender()) {
            revert OwnableUnauthorizedAccount(_msgSender());
        }
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby disabling any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        if (newOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}

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

pragma solidity >=0.6.2;

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

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

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

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

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

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

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

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

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

pragma solidity >=0.4.16;

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

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

pragma solidity >=0.4.16;

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

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

pragma solidity >=0.4.16;

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

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

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

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

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

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

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

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

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

pragma solidity ^0.8.20;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     *
     * This is a variant of {_callOptionalReturnBool} that reverts if call fails to meet the requirements.
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        uint256 returnSize;
        uint256 returnValue;
        assembly ("memory-safe") {
            let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
            // bubble errors
            if iszero(success) {
                let ptr := mload(0x40)
                returndatacopy(ptr, 0, returndatasize())
                revert(ptr, returndatasize())
            }
            returnSize := returndatasize()
            returnValue := mload(0)
        }

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

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     *
     * This is a variant of {_callOptionalReturn} that silently catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
        bool success;
        uint256 returnSize;
        uint256 returnValue;
        assembly ("memory-safe") {
            success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
            returnSize := returndatasize()
            returnValue := mload(0)
        }
        return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1);
    }
}

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

pragma solidity ^0.8.20;

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

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

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

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

pragma solidity >=0.4.16;

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

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

pragma solidity ^0.8.20;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    /**
     * @dev Returns the ceiling of the division of two numbers.
     *
     * This differs from standard division with `/` in that it rounds towards infinity instead
     * of rounding towards zero.
     */
    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
        if (b == 0) {
            // Guarantee the same behavior as in a regular Solidity division.
            Panic.panic(Panic.DIVISION_BY_ZERO);
        }

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

    /**
     * @dev Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or
     * denominator == 0.
     *
     * Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by
     * Uniswap Labs also under MIT license.
     */
    function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
        unchecked {
            (uint256 high, uint256 low) = mul512(x, y);

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

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

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

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

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

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

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

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

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

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

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

            // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also
            // works in modular arithmetic, doubling the correct bits in each step.
            inverse *= 2 - denominator * inverse; // inverse mod 2⁸
            inverse *= 2 - denominator * inverse; // inverse mod 2¹⁶
            inverse *= 2 - denominator * inverse; // inverse mod 2³²
            inverse *= 2 - denominator * inverse; // inverse mod 2⁶⁴
            inverse *= 2 - denominator * inverse; // inverse mod 2¹²⁸
            inverse *= 2 - denominator * inverse; // inverse mod 2²⁵⁶

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        uint256 mLen = m.length;

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

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

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

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

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

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

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

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

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

    /**
     * @dev Calculates sqrt(a), following the selected rounding direction.
     */
    function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = sqrt(a);
            return result + SafeCast.toUint(unsignedRoundsUp(rounding) && result * result < a);
        }
    }

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

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

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

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

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

    /**
     * @dev Return the log in base 256 of a positive value rounded towards zero.
     * Returns 0 if given 0.
     *
     * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
     */
    function log256(uint256 x) internal pure returns (uint256 r) {
        // If value has upper 128 bits set, log2 result is at least 128
        r = SafeCast.toUint(x > 0xffffffffffffffffffffffffffffffff) << 7;
        // If upper 64 bits of 128-bit half set, add 64 to result
        r |= SafeCast.toUint((x >> r) > 0xffffffffffffffff) << 6;
        // If upper 32 bits of 64-bit half set, add 32 to result
        r |= SafeCast.toUint((x >> r) > 0xffffffff) << 5;
        // If upper 16 bits of 32-bit half set, add 16 to result
        r |= SafeCast.toUint((x >> r) > 0xffff) << 4;
        // Add 1 if upper 8 bits of 16-bit half set, and divide accumulated result by 8
        return (r >> 3) | SafeCast.toUint((x >> r) > 0xff);
    }

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

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

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

pragma solidity ^0.8.20;

/**
 * @dev Wrappers over Solidity's uintXX/intXX/bool casting operators with added overflow
 * checks.
 *
 * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
 * easily result in undesired exploitation or bugs, since developers usually
 * assume that overflows raise errors. `SafeCast` restores this intuition by
 * reverting the transaction when such an operation overflows.
 *
 * Using this library instead of the unchecked operations eliminates an entire
 * class of bugs, so it's recommended to use it always.
 */
library SafeCast {
    /**
     * @dev Value doesn't fit in an uint of `bits` size.
     */
    error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);

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

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

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

    /**
     * @dev Returns the downcasted uint248 from uint256, reverting on
     * overflow (when the input is greater than largest uint248).
     *
     * Counterpart to Solidity's `uint248` operator.
     *
     * Requirements:
     *
     * - input must fit into 248 bits
     */
    function toUint248(uint256 value) internal pure returns (uint248) {
        if (value > type(uint248).max) {
            revert SafeCastOverflowedUintDowncast(248, value);
        }
        return uint248(value);
    }

    /**
     * @dev Returns the downcasted uint240 from uint256, reverting on
     * overflow (when the input is greater than largest uint240).
     *
     * Counterpart to Solidity's `uint240` operator.
     *
     * Requirements:
     *
     * - input must fit into 240 bits
     */
    function toUint240(uint256 value) internal pure returns (uint240) {
        if (value > type(uint240).max) {
            revert SafeCastOverflowedUintDowncast(240, value);
        }
        return uint240(value);
    }

    /**
     * @dev Returns the downcasted uint232 from uint256, reverting on
     * overflow (when the input is greater than largest uint232).
     *
     * Counterpart to Solidity's `uint232` operator.
     *
     * Requirements:
     *
     * - input must fit into 232 bits
     */
    function toUint232(uint256 value) internal pure returns (uint232) {
        if (value > type(uint232).max) {
            revert SafeCastOverflowedUintDowncast(232, value);
        }
        return uint232(value);
    }

    /**
     * @dev Returns the downcasted uint224 from uint256, reverting on
     * overflow (when the input is greater than largest uint224).
     *
     * Counterpart to Solidity's `uint224` operator.
     *
     * Requirements:
     *
     * - input must fit into 224 bits
     */
    function toUint224(uint256 value) internal pure returns (uint224) {
        if (value > type(uint224).max) {
            revert SafeCastOverflowedUintDowncast(224, value);
        }
        return uint224(value);
    }

    /**
     * @dev Returns the downcasted uint216 from uint256, reverting on
     * overflow (when the input is greater than largest uint216).
     *
     * Counterpart to Solidity's `uint216` operator.
     *
     * Requirements:
     *
     * - input must fit into 216 bits
     */
    function toUint216(uint256 value) internal pure returns (uint216) {
        if (value > type(uint216).max) {
            revert SafeCastOverflowedUintDowncast(216, value);
        }
        return uint216(value);
    }

    /**
     * @dev Returns the downcasted uint208 from uint256, reverting on
     * overflow (when the input is greater than largest uint208).
     *
     * Counterpart to Solidity's `uint208` operator.
     *
     * Requirements:
     *
     * - input must fit into 208 bits
     */
    function toUint208(uint256 value) internal pure returns (uint208) {
        if (value > type(uint208).max) {
            revert SafeCastOverflowedUintDowncast(208, value);
        }
        return uint208(value);
    }

    /**
     * @dev Returns the downcasted uint200 from uint256, reverting on
     * overflow (when the input is greater than largest uint200).
     *
     * Counterpart to Solidity's `uint200` operator.
     *
     * Requirements:
     *
     * - input must fit into 200 bits
     */
    function toUint200(uint256 value) internal pure returns (uint200) {
        if (value > type(uint200).max) {
            revert SafeCastOverflowedUintDowncast(200, value);
        }
        return uint200(value);
    }

    /**
     * @dev Returns the downcasted uint192 from uint256, reverting on
     * overflow (when the input is greater than largest uint192).
     *
     * Counterpart to Solidity's `uint192` operator.
     *
     * Requirements:
     *
     * - input must fit into 192 bits
     */
    function toUint192(uint256 value) internal pure returns (uint192) {
        if (value > type(uint192).max) {
            revert SafeCastOverflowedUintDowncast(192, value);
        }
        return uint192(value);
    }

    /**
     * @dev Returns the downcasted uint184 from uint256, reverting on
     * overflow (when the input is greater than largest uint184).
     *
     * Counterpart to Solidity's `uint184` operator.
     *
     * Requirements:
     *
     * - input must fit into 184 bits
     */
    function toUint184(uint256 value) internal pure returns (uint184) {
        if (value > type(uint184).max) {
            revert SafeCastOverflowedUintDowncast(184, value);
        }
        return uint184(value);
    }

    /**
     * @dev Returns the downcasted uint176 from uint256, reverting on
     * overflow (when the input is greater than largest uint176).
     *
     * Counterpart to Solidity's `uint176` operator.
     *
     * Requirements:
     *
     * - input must fit into 176 bits
     */
    function toUint176(uint256 value) internal pure returns (uint176) {
        if (value > type(uint176).max) {
            revert SafeCastOverflowedUintDowncast(176, value);
        }
        return uint176(value);
    }

    /**
     * @dev Returns the downcasted uint168 from uint256, reverting on
     * overflow (when the input is greater than largest uint168).
     *
     * Counterpart to Solidity's `uint168` operator.
     *
     * Requirements:
     *
     * - input must fit into 168 bits
     */
    function toUint168(uint256 value) internal pure returns (uint168) {
        if (value > type(uint168).max) {
            revert SafeCastOverflowedUintDowncast(168, value);
        }
        return uint168(value);
    }

    /**
     * @dev Returns the downcasted uint160 from uint256, reverting on
     * overflow (when the input is greater than largest uint160).
     *
     * Counterpart to Solidity's `uint160` operator.
     *
     * Requirements:
     *
     * - input must fit into 160 bits
     */
    function toUint160(uint256 value) internal pure returns (uint160) {
        if (value > type(uint160).max) {
            revert SafeCastOverflowedUintDowncast(160, value);
        }
        return uint160(value);
    }

    /**
     * @dev Returns the downcasted uint152 from uint256, reverting on
     * overflow (when the input is greater than largest uint152).
     *
     * Counterpart to Solidity's `uint152` operator.
     *
     * Requirements:
     *
     * - input must fit into 152 bits
     */
    function toUint152(uint256 value) internal pure returns (uint152) {
        if (value > type(uint152).max) {
            revert SafeCastOverflowedUintDowncast(152, value);
        }
        return uint152(value);
    }

    /**
     * @dev Returns the downcasted uint144 from uint256, reverting on
     * overflow (when the input is greater than largest uint144).
     *
     * Counterpart to Solidity's `uint144` operator.
     *
     * Requirements:
     *
     * - input must fit into 144 bits
     */
    function toUint144(uint256 value) internal pure returns (uint144) {
        if (value > type(uint144).max) {
            revert SafeCastOverflowedUintDowncast(144, value);
        }
        return uint144(value);
    }

    /**
     * @dev Returns the downcasted uint136 from uint256, reverting on
     * overflow (when the input is greater than largest uint136).
     *
     * Counterpart to Solidity's `uint136` operator.
     *
     * Requirements:
     *
     * - input must fit into 136 bits
     */
    function toUint136(uint256 value) internal pure returns (uint136) {
        if (value > type(uint136).max) {
            revert SafeCastOverflowedUintDowncast(136, value);
        }
        return uint136(value);
    }

    /**
     * @dev Returns the downcasted uint128 from uint256, reverting on
     * overflow (when the input is greater than largest uint128).
     *
     * Counterpart to Solidity's `uint128` operator.
     *
     * Requirements:
     *
     * - input must fit into 128 bits
     */
    function toUint128(uint256 value) internal pure returns (uint128) {
        if (value > type(uint128).max) {
            revert SafeCastOverflowedUintDowncast(128, value);
        }
        return uint128(value);
    }

    /**
     * @dev Returns the downcasted uint120 from uint256, reverting on
     * overflow (when the input is greater than largest uint120).
     *
     * Counterpart to Solidity's `uint120` operator.
     *
     * Requirements:
     *
     * - input must fit into 120 bits
     */
    function toUint120(uint256 value) internal pure returns (uint120) {
        if (value > type(uint120).max) {
            revert SafeCastOverflowedUintDowncast(120, value);
        }
        return uint120(value);
    }

    /**
     * @dev Returns the downcasted uint112 from uint256, reverting on
     * overflow (when the input is greater than largest uint112).
     *
     * Counterpart to Solidity's `uint112` operator.
     *
     * Requirements:
     *
     * - input must fit into 112 bits
     */
    function toUint112(uint256 value) internal pure returns (uint112) {
        if (value > type(uint112).max) {
            revert SafeCastOverflowedUintDowncast(112, value);
        }
        return uint112(value);
    }

    /**
     * @dev Returns the downcasted uint104 from uint256, reverting on
     * overflow (when the input is greater than largest uint104).
     *
     * Counterpart to Solidity's `uint104` operator.
     *
     * Requirements:
     *
     * - input must fit into 104 bits
     */
    function toUint104(uint256 value) internal pure returns (uint104) {
        if (value > type(uint104).max) {
            revert SafeCastOverflowedUintDowncast(104, value);
        }
        return uint104(value);
    }

    /**
     * @dev Returns the downcasted uint96 from uint256, reverting on
     * overflow (when the input is greater than largest uint96).
     *
     * Counterpart to Solidity's `uint96` operator.
     *
     * Requirements:
     *
     * - input must fit into 96 bits
     */
    function toUint96(uint256 value) internal pure returns (uint96) {
        if (value > type(uint96).max) {
            revert SafeCastOverflowedUintDowncast(96, value);
        }
        return uint96(value);
    }

    /**
     * @dev Returns the downcasted uint88 from uint256, reverting on
     * overflow (when the input is greater than largest uint88).
     *
     * Counterpart to Solidity's `uint88` operator.
     *
     * Requirements:
     *
     * - input must fit into 88 bits
     */
    function toUint88(uint256 value) internal pure returns (uint88) {
        if (value > type(uint88).max) {
            revert SafeCastOverflowedUintDowncast(88, value);
        }
        return uint88(value);
    }

    /**
     * @dev Returns the downcasted uint80 from uint256, reverting on
     * overflow (when the input is greater than largest uint80).
     *
     * Counterpart to Solidity's `uint80` operator.
     *
     * Requirements:
     *
     * - input must fit into 80 bits
     */
    function toUint80(uint256 value) internal pure returns (uint80) {
        if (value > type(uint80).max) {
            revert SafeCastOverflowedUintDowncast(80, value);
        }
        return uint80(value);
    }

    /**
     * @dev Returns the downcasted uint72 from uint256, reverting on
     * overflow (when the input is greater than largest uint72).
     *
     * Counterpart to Solidity's `uint72` operator.
     *
     * Requirements:
     *
     * - input must fit into 72 bits
     */
    function toUint72(uint256 value) internal pure returns (uint72) {
        if (value > type(uint72).max) {
            revert SafeCastOverflowedUintDowncast(72, value);
        }
        return uint72(value);
    }

    /**
     * @dev Returns the downcasted uint64 from uint256, reverting on
     * overflow (when the input is greater than largest uint64).
     *
     * Counterpart to Solidity's `uint64` operator.
     *
     * Requirements:
     *
     * - input must fit into 64 bits
     */
    function toUint64(uint256 value) internal pure returns (uint64) {
        if (value > type(uint64).max) {
            revert SafeCastOverflowedUintDowncast(64, value);
        }
        return uint64(value);
    }

    /**
     * @dev Returns the downcasted uint56 from uint256, reverting on
     * overflow (when the input is greater than largest uint56).
     *
     * Counterpart to Solidity's `uint56` operator.
     *
     * Requirements:
     *
     * - input must fit into 56 bits
     */
    function toUint56(uint256 value) internal pure returns (uint56) {
        if (value > type(uint56).max) {
            revert SafeCastOverflowedUintDowncast(56, value);
        }
        return uint56(value);
    }

    /**
     * @dev Returns the downcasted uint48 from uint256, reverting on
     * overflow (when the input is greater than largest uint48).
     *
     * Counterpart to Solidity's `uint48` operator.
     *
     * Requirements:
     *
     * - input must fit into 48 bits
     */
    function toUint48(uint256 value) internal pure returns (uint48) {
        if (value > type(uint48).max) {
            revert SafeCastOverflowedUintDowncast(48, value);
        }
        return uint48(value);
    }

    /**
     * @dev Returns the downcasted uint40 from uint256, reverting on
     * overflow (when the input is greater than largest uint40).
     *
     * Counterpart to Solidity's `uint40` operator.
     *
     * Requirements:
     *
     * - input must fit into 40 bits
     */
    function toUint40(uint256 value) internal pure returns (uint40) {
        if (value > type(uint40).max) {
            revert SafeCastOverflowedUintDowncast(40, value);
        }
        return uint40(value);
    }

    /**
     * @dev Returns the downcasted uint32 from uint256, reverting on
     * overflow (when the input is greater than largest uint32).
     *
     * Counterpart to Solidity's `uint32` operator.
     *
     * Requirements:
     *
     * - input must fit into 32 bits
     */
    function toUint32(uint256 value) internal pure returns (uint32) {
        if (value > type(uint32).max) {
            revert SafeCastOverflowedUintDowncast(32, value);
        }
        return uint32(value);
    }

    /**
     * @dev Returns the downcasted uint24 from uint256, reverting on
     * overflow (when the input is greater than largest uint24).
     *
     * Counterpart to Solidity's `uint24` operator.
     *
     * Requirements:
     *
     * - input must fit into 24 bits
     */
    function toUint24(uint256 value) internal pure returns (uint24) {
        if (value > type(uint24).max) {
            revert SafeCastOverflowedUintDowncast(24, value);
        }
        return uint24(value);
    }

    /**
     * @dev Returns the downcasted uint16 from uint256, reverting on
     * overflow (when the input is greater than largest uint16).
     *
     * Counterpart to Solidity's `uint16` operator.
     *
     * Requirements:
     *
     * - input must fit into 16 bits
     */
    function toUint16(uint256 value) internal pure returns (uint16) {
        if (value > type(uint16).max) {
            revert SafeCastOverflowedUintDowncast(16, value);
        }
        return uint16(value);
    }

    /**
     * @dev Returns the downcasted uint8 from uint256, reverting on
     * overflow (when the input is greater than largest uint8).
     *
     * Counterpart to Solidity's `uint8` operator.
     *
     * Requirements:
     *
     * - input must fit into 8 bits
     */
    function toUint8(uint256 value) internal pure returns (uint8) {
        if (value > type(uint8).max) {
            revert SafeCastOverflowedUintDowncast(8, value);
        }
        return uint8(value);
    }

    /**
     * @dev Converts a signed int256 into an unsigned uint256.
     *
     * Requirements:
     *
     * - input must be greater than or equal to 0.
     */
    function toUint256(int256 value) internal pure returns (uint256) {
        if (value < 0) {
            revert SafeCastOverflowedIntToUint(value);
        }
        return uint256(value);
    }

    /**
     * @dev Returns the downcasted int248 from int256, reverting on
     * overflow (when the input is less than smallest int248 or
     * greater than largest int248).
     *
     * Counterpart to Solidity's `int248` operator.
     *
     * Requirements:
     *
     * - input must fit into 248 bits
     */
    function toInt248(int256 value) internal pure returns (int248 downcasted) {
        downcasted = int248(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(248, value);
        }
    }

    /**
     * @dev Returns the downcasted int240 from int256, reverting on
     * overflow (when the input is less than smallest int240 or
     * greater than largest int240).
     *
     * Counterpart to Solidity's `int240` operator.
     *
     * Requirements:
     *
     * - input must fit into 240 bits
     */
    function toInt240(int256 value) internal pure returns (int240 downcasted) {
        downcasted = int240(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(240, value);
        }
    }

    /**
     * @dev Returns the downcasted int232 from int256, reverting on
     * overflow (when the input is less than smallest int232 or
     * greater than largest int232).
     *
     * Counterpart to Solidity's `int232` operator.
     *
     * Requirements:
     *
     * - input must fit into 232 bits
     */
    function toInt232(int256 value) internal pure returns (int232 downcasted) {
        downcasted = int232(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(232, value);
        }
    }

    /**
     * @dev Returns the downcasted int224 from int256, reverting on
     * overflow (when the input is less than smallest int224 or
     * greater than largest int224).
     *
     * Counterpart to Solidity's `int224` operator.
     *
     * Requirements:
     *
     * - input must fit into 224 bits
     */
    function toInt224(int256 value) internal pure returns (int224 downcasted) {
        downcasted = int224(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(224, value);
        }
    }

    /**
     * @dev Returns the downcasted int216 from int256, reverting on
     * overflow (when the input is less than smallest int216 or
     * greater than largest int216).
     *
     * Counterpart to Solidity's `int216` operator.
     *
     * Requirements:
     *
     * - input must fit into 216 bits
     */
    function toInt216(int256 value) internal pure returns (int216 downcasted) {
        downcasted = int216(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(216, value);
        }
    }

    /**
     * @dev Returns the downcasted int208 from int256, reverting on
     * overflow (when the input is less than smallest int208 or
     * greater than largest int208).
     *
     * Counterpart to Solidity's `int208` operator.
     *
     * Requirements:
     *
     * - input must fit into 208 bits
     */
    function toInt208(int256 value) internal pure returns (int208 downcasted) {
        downcasted = int208(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(208, value);
        }
    }

    /**
     * @dev Returns the downcasted int200 from int256, reverting on
     * overflow (when the input is less than smallest int200 or
     * greater than largest int200).
     *
     * Counterpart to Solidity's `int200` operator.
     *
     * Requirements:
     *
     * - input must fit into 200 bits
     */
    function toInt200(int256 value) internal pure returns (int200 downcasted) {
        downcasted = int200(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(200, value);
        }
    }

    /**
     * @dev Returns the downcasted int192 from int256, reverting on
     * overflow (when the input is less than smallest int192 or
     * greater than largest int192).
     *
     * Counterpart to Solidity's `int192` operator.
     *
     * Requirements:
     *
     * - input must fit into 192 bits
     */
    function toInt192(int256 value) internal pure returns (int192 downcasted) {
        downcasted = int192(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(192, value);
        }
    }

    /**
     * @dev Returns the downcasted int184 from int256, reverting on
     * overflow (when the input is less than smallest int184 or
     * greater than largest int184).
     *
     * Counterpart to Solidity's `int184` operator.
     *
     * Requirements:
     *
     * - input must fit into 184 bits
     */
    function toInt184(int256 value) internal pure returns (int184 downcasted) {
        downcasted = int184(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(184, value);
        }
    }

    /**
     * @dev Returns the downcasted int176 from int256, reverting on
     * overflow (when the input is less than smallest int176 or
     * greater than largest int176).
     *
     * Counterpart to Solidity's `int176` operator.
     *
     * Requirements:
     *
     * - input must fit into 176 bits
     */
    function toInt176(int256 value) internal pure returns (int176 downcasted) {
        downcasted = int176(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(176, value);
        }
    }

    /**
     * @dev Returns the downcasted int168 from int256, reverting on
     * overflow (when the input is less than smallest int168 or
     * greater than largest int168).
     *
     * Counterpart to Solidity's `int168` operator.
     *
     * Requirements:
     *
     * - input must fit into 168 bits
     */
    function toInt168(int256 value) internal pure returns (int168 downcasted) {
        downcasted = int168(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(168, value);
        }
    }

    /**
     * @dev Returns the downcasted int160 from int256, reverting on
     * overflow (when the input is less than smallest int160 or
     * greater than largest int160).
     *
     * Counterpart to Solidity's `int160` operator.
     *
     * Requirements:
     *
     * - input must fit into 160 bits
     */
    function toInt160(int256 value) internal pure returns (int160 downcasted) {
        downcasted = int160(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(160, value);
        }
    }

    /**
     * @dev Returns the downcasted int152 from int256, reverting on
     * overflow (when the input is less than smallest int152 or
     * greater than largest int152).
     *
     * Counterpart to Solidity's `int152` operator.
     *
     * Requirements:
     *
     * - input must fit into 152 bits
     */
    function toInt152(int256 value) internal pure returns (int152 downcasted) {
        downcasted = int152(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(152, value);
        }
    }

    /**
     * @dev Returns the downcasted int144 from int256, reverting on
     * overflow (when the input is less than smallest int144 or
     * greater than largest int144).
     *
     * Counterpart to Solidity's `int144` operator.
     *
     * Requirements:
     *
     * - input must fit into 144 bits
     */
    function toInt144(int256 value) internal pure returns (int144 downcasted) {
        downcasted = int144(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(144, value);
        }
    }

    /**
     * @dev Returns the downcasted int136 from int256, reverting on
     * overflow (when the input is less than smallest int136 or
     * greater than largest int136).
     *
     * Counterpart to Solidity's `int136` operator.
     *
     * Requirements:
     *
     * - input must fit into 136 bits
     */
    function toInt136(int256 value) internal pure returns (int136 downcasted) {
        downcasted = int136(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(136, value);
        }
    }

    /**
     * @dev Returns the downcasted int128 from int256, reverting on
     * overflow (when the input is less than smallest int128 or
     * greater than largest int128).
     *
     * Counterpart to Solidity's `int128` operator.
     *
     * Requirements:
     *
     * - input must fit into 128 bits
     */
    function toInt128(int256 value) internal pure returns (int128 downcasted) {
        downcasted = int128(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(128, value);
        }
    }

    /**
     * @dev Returns the downcasted int120 from int256, reverting on
     * overflow (when the input is less than smallest int120 or
     * greater than largest int120).
     *
     * Counterpart to Solidity's `int120` operator.
     *
     * Requirements:
     *
     * - input must fit into 120 bits
     */
    function toInt120(int256 value) internal pure returns (int120 downcasted) {
        downcasted = int120(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(120, value);
        }
    }

    /**
     * @dev Returns the downcasted int112 from int256, reverting on
     * overflow (when the input is less than smallest int112 or
     * greater than largest int112).
     *
     * Counterpart to Solidity's `int112` operator.
     *
     * Requirements:
     *
     * - input must fit into 112 bits
     */
    function toInt112(int256 value) internal pure returns (int112 downcasted) {
        downcasted = int112(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(112, value);
        }
    }

    /**
     * @dev Returns the downcasted int104 from int256, reverting on
     * overflow (when the input is less than smallest int104 or
     * greater than largest int104).
     *
     * Counterpart to Solidity's `int104` operator.
     *
     * Requirements:
     *
     * - input must fit into 104 bits
     */
    function toInt104(int256 value) internal pure returns (int104 downcasted) {
        downcasted = int104(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(104, value);
        }
    }

    /**
     * @dev Returns the downcasted int96 from int256, reverting on
     * overflow (when the input is less than smallest int96 or
     * greater than largest int96).
     *
     * Counterpart to Solidity's `int96` operator.
     *
     * Requirements:
     *
     * - input must fit into 96 bits
     */
    function toInt96(int256 value) internal pure returns (int96 downcasted) {
        downcasted = int96(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(96, value);
        }
    }

    /**
     * @dev Returns the downcasted int88 from int256, reverting on
     * overflow (when the input is less than smallest int88 or
     * greater than largest int88).
     *
     * Counterpart to Solidity's `int88` operator.
     *
     * Requirements:
     *
     * - input must fit into 88 bits
     */
    function toInt88(int256 value) internal pure returns (int88 downcasted) {
        downcasted = int88(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(88, value);
        }
    }

    /**
     * @dev Returns the downcasted int80 from int256, reverting on
     * overflow (when the input is less than smallest int80 or
     * greater than largest int80).
     *
     * Counterpart to Solidity's `int80` operator.
     *
     * Requirements:
     *
     * - input must fit into 80 bits
     */
    function toInt80(int256 value) internal pure returns (int80 downcasted) {
        downcasted = int80(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(80, value);
        }
    }

    /**
     * @dev Returns the downcasted int72 from int256, reverting on
     * overflow (when the input is less than smallest int72 or
     * greater than largest int72).
     *
     * Counterpart to Solidity's `int72` operator.
     *
     * Requirements:
     *
     * - input must fit into 72 bits
     */
    function toInt72(int256 value) internal pure returns (int72 downcasted) {
        downcasted = int72(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(72, value);
        }
    }

    /**
     * @dev Returns the downcasted int64 from int256, reverting on
     * overflow (when the input is less than smallest int64 or
     * greater than largest int64).
     *
     * Counterpart to Solidity's `int64` operator.
     *
     * Requirements:
     *
     * - input must fit into 64 bits
     */
    function toInt64(int256 value) internal pure returns (int64 downcasted) {
        downcasted = int64(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(64, value);
        }
    }

    /**
     * @dev Returns the downcasted int56 from int256, reverting on
     * overflow (when the input is less than smallest int56 or
     * greater than largest int56).
     *
     * Counterpart to Solidity's `int56` operator.
     *
     * Requirements:
     *
     * - input must fit into 56 bits
     */
    function toInt56(int256 value) internal pure returns (int56 downcasted) {
        downcasted = int56(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(56, value);
        }
    }

    /**
     * @dev Returns the downcasted int48 from int256, reverting on
     * overflow (when the input is less than smallest int48 or
     * greater than largest int48).
     *
     * Counterpart to Solidity's `int48` operator.
     *
     * Requirements:
     *
     * - input must fit into 48 bits
     */
    function toInt48(int256 value) internal pure returns (int48 downcasted) {
        downcasted = int48(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(48, value);
        }
    }

    /**
     * @dev Returns the downcasted int40 from int256, reverting on
     * overflow (when the input is less than smallest int40 or
     * greater than largest int40).
     *
     * Counterpart to Solidity's `int40` operator.
     *
     * Requirements:
     *
     * - input must fit into 40 bits
     */
    function toInt40(int256 value) internal pure returns (int40 downcasted) {
        downcasted = int40(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(40, value);
        }
    }

    /**
     * @dev Returns the downcasted int32 from int256, reverting on
     * overflow (when the input is less than smallest int32 or
     * greater than largest int32).
     *
     * Counterpart to Solidity's `int32` operator.
     *
     * Requirements:
     *
     * - input must fit into 32 bits
     */
    function toInt32(int256 value) internal pure returns (int32 downcasted) {
        downcasted = int32(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(32, value);
        }
    }

    /**
     * @dev Returns the downcasted int24 from int256, reverting on
     * overflow (when the input is less than smallest int24 or
     * greater than largest int24).
     *
     * Counterpart to Solidity's `int24` operator.
     *
     * Requirements:
     *
     * - input must fit into 24 bits
     */
    function toInt24(int256 value) internal pure returns (int24 downcasted) {
        downcasted = int24(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(24, value);
        }
    }

    /**
     * @dev Returns the downcasted int16 from int256, reverting on
     * overflow (when the input is less than smallest int16 or
     * greater than largest int16).
     *
     * Counterpart to Solidity's `int16` operator.
     *
     * Requirements:
     *
     * - input must fit into 16 bits
     */
    function toInt16(int256 value) internal pure returns (int16 downcasted) {
        downcasted = int16(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(16, value);
        }
    }

    /**
     * @dev Returns the downcasted int8 from int256, reverting on
     * overflow (when the input is less than smallest int8 or
     * greater than largest int8).
     *
     * Counterpart to Solidity's `int8` operator.
     *
     * Requirements:
     *
     * - input must fit into 8 bits
     */
    function toInt8(int256 value) internal pure returns (int8 downcasted) {
        downcasted = int8(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(8, value);
        }
    }

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

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/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)
        }
    }
}

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

pragma solidity ^0.8.20;

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

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

    uint256 private _status;

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

    constructor() {
        _status = NOT_ENTERED;
    }

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

    function _nonReentrantBefore() private {
        // On the first call to nonReentrant, _status will be NOT_ENTERED
        if (_status == ENTERED) {
            revert ReentrancyGuardReentrantCall();
        }

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

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

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

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

/// @title Minimal ERC20 interface for Uniswap
/// @notice Contains a subset of the full ERC20 interface that is used in Uniswap V3
interface IERC20Minimal {
    /// @notice Returns an account's balance in the token
    /// @param account The account for which to look up the number of tokens it has, i.e. its balance
    /// @return The number of tokens held by the account
    function balanceOf(address account) external view returns (uint256);

    /// @notice Transfers the amount of token from the `msg.sender` to the recipient
    /// @param recipient The account that will receive the amount transferred
    /// @param amount The number of tokens to send from the sender to the recipient
    /// @return Returns true for a successful transfer, false for an unsuccessful transfer
    function transfer(address recipient, uint256 amount) external returns (bool);

    /// @notice Returns the current allowance given to a spender by an owner
    /// @param owner The account of the token owner
    /// @param spender The account of the token spender
    /// @return The current allowance granted by `owner` to `spender`
    function allowance(address owner, address spender) external view returns (uint256);

    /// @notice Sets the allowance of a spender from the `msg.sender` to the value `amount`
    /// @param spender The account which will be allowed to spend a given amount of the owners tokens
    /// @param amount The amount of tokens allowed to be used by `spender`
    /// @return Returns true for a successful approval, false for unsuccessful
    function approve(address spender, uint256 amount) external returns (bool);

    /// @notice Transfers `amount` tokens from `sender` to `recipient` up to the allowance given to the `msg.sender`
    /// @param sender The account from which the transfer will be initiated
    /// @param recipient The recipient of the transfer
    /// @param amount The amount of the transfer
    /// @return Returns true for a successful transfer, false for unsuccessful
    function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);

    /// @notice Event emitted when tokens are transferred from one address to another, either via `#transfer` or `#transferFrom`.
    /// @param from The account from which the tokens were sent, i.e. the balance decreased
    /// @param to The account to which the tokens were sent, i.e. the balance increased
    /// @param value The amount of tokens that were transferred
    event Transfer(address indexed from, address indexed to, uint256 value);

    /// @notice Event emitted when the approval amount for the spender of a given owner's tokens changes.
    /// @param owner The account that approved spending of its tokens
    /// @param spender The account for which the spending allowance was modified
    /// @param value The new allowance from the owner to the spender
    event Approval(address indexed owner, address indexed spender, uint256 value);
}

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

import {PoolKey} from "../types/PoolKey.sol";
import {BalanceDelta} from "../types/BalanceDelta.sol";
import {ModifyLiquidityParams, SwapParams} from "../types/PoolOperation.sol";
import {BeforeSwapDelta} from "../types/BeforeSwapDelta.sol";

/// @notice V4 decides whether to invoke specific hooks by inspecting the least significant bits
/// of the address that the hooks contract is deployed to.
/// For example, a hooks contract deployed to address: 0x0000000000000000000000000000000000002400
/// has the lowest bits '10 0100 0000 0000' which would cause the 'before initialize' and 'after add liquidity' hooks to be used.
/// See the Hooks library for the full spec.
/// @dev Should only be callable by the v4 PoolManager.
interface IHooks {
    /// @notice The hook called before the state of a pool is initialized
    /// @param sender The initial msg.sender for the initialize call
    /// @param key The key for the pool being initialized
    /// @param sqrtPriceX96 The sqrt(price) of the pool as a Q64.96
    /// @return bytes4 The function selector for the hook
    function beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96) external returns (bytes4);

    /// @notice The hook called after the state of a pool is initialized
    /// @param sender The initial msg.sender for the initialize call
    /// @param key The key for the pool being initialized
    /// @param sqrtPriceX96 The sqrt(price) of the pool as a Q64.96
    /// @param tick The current tick after the state of a pool is initialized
    /// @return bytes4 The function selector for the hook
    function afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)
        external
        returns (bytes4);

    /// @notice The hook called before liquidity is added
    /// @param sender The initial msg.sender for the add liquidity call
    /// @param key The key for the pool
    /// @param params The parameters for adding liquidity
    /// @param hookData Arbitrary data handed into the PoolManager by the liquidity provider to be passed on to the hook
    /// @return bytes4 The function selector for the hook
    function beforeAddLiquidity(
        address sender,
        PoolKey calldata key,
        ModifyLiquidityParams calldata params,
        bytes calldata hookData
    ) external returns (bytes4);

    /// @notice The hook called after liquidity is added
    /// @param sender The initial msg.sender for the add liquidity call
    /// @param key The key for the pool
    /// @param params The parameters for adding liquidity
    /// @param delta The caller's balance delta after adding liquidity; the sum of principal delta, fees accrued, and hook delta
    /// @param feesAccrued The fees accrued since the last time fees were collected from this position
    /// @param hookData Arbitrary data handed into the PoolManager by the liquidity provider to be passed on to the hook
    /// @return bytes4 The function selector for the hook
    /// @return BalanceDelta The hook's delta in token0 and token1. Positive: the hook is owed/took currency, negative: the hook owes/sent currency
    function afterAddLiquidity(
        address sender,
        PoolKey calldata key,
        ModifyLiquidityParams calldata params,
        BalanceDelta delta,
        BalanceDelta feesAccrued,
        bytes calldata hookData
    ) external returns (bytes4, BalanceDelta);

    /// @notice The hook called before liquidity is removed
    /// @param sender The initial msg.sender for the remove liquidity call
    /// @param key The key for the pool
    /// @param params The parameters for removing liquidity
    /// @param hookData Arbitrary data handed into the PoolManager by the liquidity provider to be be passed on to the hook
    /// @return bytes4 The function selector for the hook
    function beforeRemoveLiquidity(
        address sender,
        PoolKey calldata key,
        ModifyLiquidityParams calldata params,
        bytes calldata hookData
    ) external returns (bytes4);

    /// @notice The hook called after liquidity is removed
    /// @param sender The initial msg.sender for the remove liquidity call
    /// @param key The key for the pool
    /// @param params The parameters for removing liquidity
    /// @param delta The caller's balance delta after removing liquidity; the sum of principal delta, fees accrued, and hook delta
    /// @param feesAccrued The fees accrued since the last time fees were collected from this position
    /// @param hookData Arbitrary data handed into the PoolManager by the liquidity provider to be be passed on to the hook
    /// @return bytes4 The function selector for the hook
    /// @return BalanceDelta The hook's delta in token0 and token1. Positive: the hook is owed/took currency, negative: the hook owes/sent currency
    function afterRemoveLiquidity(
        address sender,
        PoolKey calldata key,
        ModifyLiquidityParams calldata params,
        BalanceDelta delta,
        BalanceDelta feesAccrued,
        bytes calldata hookData
    ) external returns (bytes4, BalanceDelta);

    /// @notice The hook called before a swap
    /// @param sender The initial msg.sender for the swap call
    /// @param key The key for the pool
    /// @param params The parameters for the swap
    /// @param hookData Arbitrary data handed into the PoolManager by the swapper to be be passed on to the hook
    /// @return bytes4 The function selector for the hook
    /// @return BeforeSwapDelta The hook's delta in specified and unspecified currencies. Positive: the hook is owed/took currency, negative: the hook owes/sent currency
    /// @return uint24 Optionally override the lp fee, only used if three conditions are met: 1. the Pool has a dynamic fee, 2. the value's 2nd highest bit is set (23rd bit, 0x400000), and 3. the value is less than or equal to the maximum fee (1 million)
    function beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)
        external
        returns (bytes4, BeforeSwapDelta, uint24);

    /// @notice The hook called after a swap
    /// @param sender The initial msg.sender for the swap call
    /// @param key The key for the pool
    /// @param params The parameters for the swap
    /// @param delta The amount owed to the caller (positive) or owed to the pool (negative)
    /// @param hookData Arbitrary data handed into the PoolManager by the swapper to be be passed on to the hook
    /// @return bytes4 The function selector for the hook
    /// @return int128 The hook's delta in unspecified currency. Positive: the hook is owed/took currency, negative: the hook owes/sent currency
    function afterSwap(
        address sender,
        PoolKey calldata key,
        SwapParams calldata params,
        BalanceDelta delta,
        bytes calldata hookData
    ) external returns (bytes4, int128);

    /// @notice The hook called before donate
    /// @param sender The initial msg.sender for the donate call
    /// @param key The key for the pool
    /// @param amount0 The amount of token0 being donated
    /// @param amount1 The amount of token1 being donated
    /// @param hookData Arbitrary data handed into the PoolManager by the donor to be be passed on to the hook
    /// @return bytes4 The function selector for the hook
    function beforeDonate(
        address sender,
        PoolKey calldata key,
        uint256 amount0,
        uint256 amount1,
        bytes calldata hookData
    ) external returns (bytes4);

    /// @notice The hook called after donate
    /// @param sender The initial msg.sender for the donate call
    /// @param key The key for the pool
    /// @param amount0 The amount of token0 being donated
    /// @param amount1 The amount of token1 being donated
    /// @param hookData Arbitrary data handed into the PoolManager by the donor to be be passed on to the hook
    /// @return bytes4 The function selector for the hook
    function afterDonate(
        address sender,
        PoolKey calldata key,
        uint256 amount0,
        uint256 amount1,
        bytes calldata hookData
    ) external returns (bytes4);
}

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

/// @title Library for reverting with custom errors efficiently
/// @notice Contains functions for reverting with custom errors with different argument types efficiently
/// @dev To use this library, declare `using CustomRevert for bytes4;` and replace `revert CustomError()` with
/// `CustomError.selector.revertWith()`
/// @dev The functions may tamper with the free memory pointer but it is fine since the call context is exited immediately
library CustomRevert {
    /// @dev ERC-7751 error for wrapping bubbled up reverts
    error WrappedError(address target, bytes4 selector, bytes reason, bytes details);

    /// @dev Reverts with the selector of a custom error in the scratch space
    function revertWith(bytes4 selector) internal pure {
        assembly ("memory-safe") {
            mstore(0, selector)
            revert(0, 0x04)
        }
    }

    /// @dev Reverts with a custom error with an address argument in the scratch space
    function revertWith(bytes4 selector, address addr) internal pure {
        assembly ("memory-safe") {
            mstore(0, selector)
            mstore(0x04, and(addr, 0xffffffffffffffffffffffffffffffffffffffff))
            revert(0, 0x24)
        }
    }

    /// @dev Reverts with a custom error with an int24 argument in the scratch space
    function revertWith(bytes4 selector, int24 value) internal pure {
        assembly ("memory-safe") {
            mstore(0, selector)
            mstore(0x04, signextend(2, value))
            revert(0, 0x24)
        }
    }

    /// @dev Reverts with a custom error with a uint160 argument in the scratch space
    function revertWith(bytes4 selector, uint160 value) internal pure {
        assembly ("memory-safe") {
            mstore(0, selector)
            mstore(0x04, and(value, 0xffffffffffffffffffffffffffffffffffffffff))
            revert(0, 0x24)
        }
    }

    /// @dev Reverts with a custom error with two int24 arguments
    function revertWith(bytes4 selector, int24 value1, int24 value2) internal pure {
        assembly ("memory-safe") {
            let fmp := mload(0x40)
            mstore(fmp, selector)
            mstore(add(fmp, 0x04), signextend(2, value1))
            mstore(add(fmp, 0x24), signextend(2, value2))
            revert(fmp, 0x44)
        }
    }

    /// @dev Reverts with a custom error with two uint160 arguments
    function revertWith(bytes4 selector, uint160 value1, uint160 value2) internal pure {
        assembly ("memory-safe") {
            let fmp := mload(0x40)
            mstore(fmp, selector)
            mstore(add(fmp, 0x04), and(value1, 0xffffffffffffffffffffffffffffffffffffffff))
            mstore(add(fmp, 0x24), and(value2, 0xffffffffffffffffffffffffffffffffffffffff))
            revert(fmp, 0x44)
        }
    }

    /// @dev Reverts with a custom error with two address arguments
    function revertWith(bytes4 selector, address value1, address value2) internal pure {
        assembly ("memory-safe") {
            let fmp := mload(0x40)
            mstore(fmp, selector)
            mstore(add(fmp, 0x04), and(value1, 0xffffffffffffffffffffffffffffffffffffffff))
            mstore(add(fmp, 0x24), and(value2, 0xffffffffffffffffffffffffffffffffffffffff))
            revert(fmp, 0x44)
        }
    }

    /// @notice bubble up the revert message returned by a call and revert with a wrapped ERC-7751 error
    /// @dev this method can be vulnerable to revert data bombs
    function bubbleUpAndRevertWith(
        address revertingContract,
        bytes4 revertingFunctionSelector,
        bytes4 additionalContext
    ) internal pure {
        bytes4 wrappedErrorSelector = WrappedError.selector;
        assembly ("memory-safe") {
            // Ensure the size of the revert data is a multiple of 32 bytes
            let encodedDataSize := mul(div(add(returndatasize(), 31), 32), 32)

            let fmp := mload(0x40)

            // Encode wrapped error selector, address, function selector, offset, additional context, size, revert reason
            mstore(fmp, wrappedErrorSelector)
            mstore(add(fmp, 0x04), and(revertingContract, 0xffffffffffffffffffffffffffffffffffffffff))
            mstore(
                add(fmp, 0x24),
                and(revertingFunctionSelector, 0xffffffff00000000000000000000000000000000000000000000000000000000)
            )
            // offset revert reason
            mstore(add(fmp, 0x44), 0x80)
            // offset additional context
            mstore(add(fmp, 0x64), add(0xa0, encodedDataSize))
            // size revert reason
            mstore(add(fmp, 0x84), returndatasize())
            // revert reason
            returndatacopy(add(fmp, 0xa4), 0, returndatasize())
            // size additional context
            mstore(add(fmp, add(0xa4, encodedDataSize)), 0x04)
            // additional context
            mstore(
                add(fmp, add(0xc4, encodedDataSize)),
                and(additionalContext, 0xffffffff00000000000000000000000000000000000000000000000000000000)
            )
            revert(fmp, add(0xe4, encodedDataSize))
        }
    }
}

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

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

/// @title Safe casting methods
/// @notice Contains methods for safely casting between types
library SafeCast {
    using CustomRevert for bytes4;

    error SafeCastOverflow();

    /// @notice Cast a uint256 to a uint160, revert on overflow
    /// @param x The uint256 to be downcasted
    /// @return y The downcasted integer, now type uint160
    function toUint160(uint256 x) internal pure returns (uint160 y) {
        y = uint160(x);
        if (y != x) SafeCastOverflow.selector.revertWith();
    }

    /// @notice Cast a uint256 to a uint128, revert on overflow
    /// @param x The uint256 to be downcasted
    /// @return y The downcasted integer, now type uint128
    function toUint128(uint256 x) internal pure returns (uint128 y) {
        y = uint128(x);
        if (x != y) SafeCastOverflow.selector.revertWith();
    }

    /// @notice Cast a int128 to a uint128, revert on overflow or underflow
    /// @param x The int128 to be casted
    /// @return y The casted integer, now type uint128
    function toUint128(int128 x) internal pure returns (uint128 y) {
        if (x < 0) SafeCastOverflow.selector.revertWith();
        y = uint128(x);
    }

    /// @notice Cast a int256 to a int128, revert on overflow or underflow
    /// @param x The int256 to be downcasted
    /// @return y The downcasted integer, now type int128
    function toInt128(int256 x) internal pure returns (int128 y) {
        y = int128(x);
        if (y != x) SafeCastOverflow.selector.revertWith();
    }

    /// @notice Cast a uint256 to a int256, revert on overflow
    /// @param x The uint256 to be casted
    /// @return y The casted integer, now type int256
    function toInt256(uint256 x) internal pure returns (int256 y) {
        y = int256(x);
        if (y < 0) SafeCastOverflow.selector.revertWith();
    }

    /// @notice Cast a uint256 to a int128, revert on overflow
    /// @param x The uint256 to be downcasted
    /// @return The downcasted integer, now type int128
    function toInt128(uint256 x) internal pure returns (int128) {
        if (x >= 1 << 127) SafeCastOverflow.selector.revertWith();
        return int128(int256(x));
    }
}

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

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

/// @dev Two `int128` values packed into a single `int256` where the upper 128 bits represent the amount0
/// and the lower 128 bits represent the amount1.
type BalanceDelta is int256;

using {add as +, sub as -, eq as ==, neq as !=} for BalanceDelta global;
using BalanceDeltaLibrary for BalanceDelta global;
using SafeCast for int256;

function toBalanceDelta(int128 _amount0, int128 _amount1) pure returns (BalanceDelta balanceDelta) {
    assembly ("memory-safe") {
        balanceDelta := or(shl(128, _amount0), and(sub(shl(128, 1), 1), _amount1))
    }
}

function add(BalanceDelta a, BalanceDelta b) pure returns (BalanceDelta) {
    int256 res0;
    int256 res1;
    assembly ("memory-safe") {
        let a0 := sar(128, a)
        let a1 := signextend(15, a)
        let b0 := sar(128, b)
        let b1 := signextend(15, b)
        res0 := add(a0, b0)
        res1 := add(a1, b1)
    }
    return toBalanceDelta(res0.toInt128(), res1.toInt128());
}

function sub(BalanceDelta a, BalanceDelta b) pure returns (BalanceDelta) {
    int256 res0;
    int256 res1;
    assembly ("memory-safe") {
        let a0 := sar(128, a)
        let a1 := signextend(15, a)
        let b0 := sar(128, b)
        let b1 := signextend(15, b)
        res0 := sub(a0, b0)
        res1 := sub(a1, b1)
    }
    return toBalanceDelta(res0.toInt128(), res1.toInt128());
}

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

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

/// @notice Library for getting the amount0 and amount1 deltas from the BalanceDelta type
library BalanceDeltaLibrary {
    /// @notice A BalanceDelta of 0
    BalanceDelta public constant ZERO_DELTA = BalanceDelta.wrap(0);

    function amount0(BalanceDelta balanceDelta) internal pure returns (int128 _amount0) {
        assembly ("memory-safe") {
            _amount0 := sar(128, balanceDelta)
        }
    }

    function amount1(BalanceDelta balanceDelta) internal pure returns (int128 _amount1) {
        assembly ("memory-safe") {
            _amount1 := signextend(15, balanceDelta)
        }
    }
}

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

// Return type of the beforeSwap hook.
// Upper 128 bits is the delta in specified tokens. Lower 128 bits is delta in unspecified tokens (to match the afterSwap hook)
type BeforeSwapDelta is int256;

// Creates a BeforeSwapDelta from specified and unspecified
function toBeforeSwapDelta(int128 deltaSpecified, int128 deltaUnspecified)
    pure
    returns (BeforeSwapDelta beforeSwapDelta)
{
    assembly ("memory-safe") {
        beforeSwapDelta := or(shl(128, deltaSpecified), and(sub(shl(128, 1), 1), deltaUnspecified))
    }
}

/// @notice Library for getting the specified and unspecified deltas from the BeforeSwapDelta type
library BeforeSwapDeltaLibrary {
    /// @notice A BeforeSwapDelta of 0
    BeforeSwapDelta public constant ZERO_DELTA = BeforeSwapDelta.wrap(0);

    /// extracts int128 from the upper 128 bits of the BeforeSwapDelta
    /// returned by beforeSwap
    function getSpecifiedDelta(BeforeSwapDelta delta) internal pure returns (int128 deltaSpecified) {
        assembly ("memory-safe") {
            deltaSpecified := sar(128, delta)
        }
    }

    /// extracts int128 from the lower 128 bits of the BeforeSwapDelta
    /// returned by beforeSwap and afterSwap
    function getUnspecifiedDelta(BeforeSwapDelta delta) internal pure returns (int128 deltaUnspecified) {
        assembly ("memory-safe") {
            deltaUnspecified := signextend(15, delta)
        }
    }
}

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

import {IERC20Minimal} from "../interfaces/external/IERC20Minimal.sol";
import {CustomRevert} from "../libraries/CustomRevert.sol";

type Currency is address;

using {greaterThan as >, lessThan as <, greaterThanOrEqualTo as >=, equals as ==} for Currency global;
using CurrencyLibrary for Currency global;

function equals(Currency currency, Currency other) pure returns (bool) {
    return Currency.unwrap(currency) == Currency.unwrap(other);
}

function greaterThan(Currency currency, Currency other) pure returns (bool) {
    return Currency.unwrap(currency) > Currency.unwrap(other);
}

function lessThan(Currency currency, Currency other) pure returns (bool) {
    return Currency.unwrap(currency) < Currency.unwrap(other);
}

function greaterThanOrEqualTo(Currency currency, Currency other) pure returns (bool) {
    return Currency.unwrap(currency) >= Currency.unwrap(other);
}

/// @title CurrencyLibrary
/// @dev This library allows for transferring and holding native tokens and ERC20 tokens
library CurrencyLibrary {
    /// @notice Additional context for ERC-7751 wrapped error when a native transfer fails
    error NativeTransferFailed();

    /// @notice Additional context for ERC-7751 wrapped error when an ERC20 transfer fails
    error ERC20TransferFailed();

    /// @notice A constant to represent the native currency
    Currency public constant ADDRESS_ZERO = Currency.wrap(address(0));

    function transfer(Currency currency, address to, uint256 amount) internal {
        // altered from https://github.com/transmissions11/solmate/blob/44a9963d4c78111f77caa0e65d677b8b46d6f2e6/src/utils/SafeTransferLib.sol
        // modified custom error selectors

        bool success;
        if (currency.isAddressZero()) {
            assembly ("memory-safe") {
                // Transfer the ETH and revert if it fails.
                success := call(gas(), to, amount, 0, 0, 0, 0)
            }
            // revert with NativeTransferFailed, containing the bubbled up error as an argument
            if (!success) {
                CustomRevert.bubbleUpAndRevertWith(to, bytes4(0), NativeTransferFailed.selector);
            }
        } else {
            assembly ("memory-safe") {
                // Get a pointer to some free memory.
                let fmp := mload(0x40)

                // Write the abi-encoded calldata into memory, beginning with the function selector.
                mstore(fmp, 0xa9059cbb00000000000000000000000000000000000000000000000000000000)
                mstore(add(fmp, 4), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "to" argument.
                mstore(add(fmp, 36), amount) // Append the "amount" argument. Masking not required as it's a full 32 byte type.

                success :=
                    and(
                        // Set success to whether the call reverted, if not we check it either
                        // returned exactly 1 (can't just be non-zero data), or had no return data.
                        or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),
                        // We use 68 because the length of our calldata totals up like so: 4 + 32 * 2.
                        // We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
                        // Counterintuitively, this call must be positioned second to the or() call in the
                        // surrounding and() call or else returndatasize() will be zero during the computation.
                        call(gas(), currency, 0, fmp, 68, 0, 32)
                    )

                // Now clean the memory we used
                mstore(fmp, 0) // 4 byte `selector` and 28 bytes of `to` were stored here
                mstore(add(fmp, 0x20), 0) // 4 bytes of `to` and 28 bytes of `amount` were stored here
                mstore(add(fmp, 0x40), 0) // 4 bytes of `amount` were stored here
            }
            // revert with ERC20TransferFailed, containing the bubbled up error as an argument
            if (!success) {
                CustomRevert.bubbleUpAndRevertWith(
                    Currency.unwrap(currency), IERC20Minimal.transfer.selector, ERC20TransferFailed.selector
                );
            }
        }
    }

    function balanceOfSelf(Currency currency) internal view returns (uint256) {
        if (currency.isAddressZero()) {
            return address(this).balance;
        } else {
            return IERC20Minimal(Currency.unwrap(currency)).balanceOf(address(this));
        }
    }

    function balanceOf(Currency currency, address owner) internal view returns (uint256) {
        if (currency.isAddressZero()) {
            return owner.balance;
        } else {
            return IERC20Minimal(Currency.unwrap(currency)).balanceOf(owner);
        }
    }

    function isAddressZero(Currency currency) internal pure returns (bool) {
        return Currency.unwrap(currency) == Currency.unwrap(ADDRESS_ZERO);
    }

    function toId(Currency currency) internal pure returns (uint256) {
        return uint160(Currency.unwrap(currency));
    }

    // If the upper 12 bytes are non-zero, they will be zero-ed out
    // Therefore, fromId() and toId() are not inverses of each other
    function fromId(uint256 id) internal pure returns (Currency) {
        return Currency.wrap(address(uint160(id)));
    }
}

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

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

type PoolId is bytes32;

/// @notice Library for computing the ID of a pool
library PoolIdLibrary {
    /// @notice Returns value equal to keccak256(abi.encode(poolKey))
    function toId(PoolKey memory poolKey) internal pure returns (PoolId poolId) {
        assembly ("memory-safe") {
            // 0xa0 represents the total size of the poolKey struct (5 slots of 32 bytes)
            poolId := keccak256(poolKey, 0xa0)
        }
    }
}

File 22 of 25 : PoolKey.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {Currency} from "./Currency.sol";
import {IHooks} from "../interfaces/IHooks.sol";
import {PoolIdLibrary} from "./PoolId.sol";

using PoolIdLibrary for PoolKey global;

/// @notice Returns the key for identifying a pool
struct PoolKey {
    /// @notice The lower currency of the pool, sorted numerically
    Currency currency0;
    /// @notice The higher currency of the pool, sorted numerically
    Currency currency1;
    /// @notice The pool LP fee, capped at 1_000_000. If the highest bit is 1, the pool has a dynamic fee and must be exactly equal to 0x800000
    uint24 fee;
    /// @notice Ticks that involve positions must be a multiple of tick spacing
    int24 tickSpacing;
    /// @notice The hooks of the pool
    IHooks hooks;
}

File 23 of 25 : PoolOperation.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

import {PoolKey} from "../types/PoolKey.sol";
import {BalanceDelta} from "../types/BalanceDelta.sol";

/// @notice Parameter struct for `ModifyLiquidity` pool operations
struct ModifyLiquidityParams {
    // the lower and upper tick of the position
    int24 tickLower;
    int24 tickUpper;
    // how to modify the liquidity
    int256 liquidityDelta;
    // a value to set if you want unique liquidity positions at the same range
    bytes32 salt;
}

/// @notice Parameter struct for `Swap` pool operations
struct SwapParams {
    /// Whether to swap token0 for token1 or vice versa
    bool zeroForOne;
    /// The desired input amount if negative (exactIn), or the desired output amount if positive (exactOut)
    int256 amountSpecified;
    /// The sqrt price at which, if reached, the swap will stop executing
    uint160 sqrtPriceLimitX96;
}

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

import {PoolKey} from "@uniswap/v4-periphery/lib/v4-core/src/types/PoolKey.sol";

/**
 * Minimal interface for the Router04 *shape* used by PNKSTR.
 * Matches the call you saw in their contract:
 *   swapExactTokensForTokens{value: amountIn}(...)
 */
interface IUniswapV4Router04 {
    function swapExactTokensForTokens(
        uint256 amountIn,
        uint256 amountOutMin,
        bool exactInput,
        PoolKey calldata key,
        bytes calldata hookData,
        address recipient,
        uint256 deadline
    ) external payable returns (int256 amountOut);
}

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

interface IWETH9 {
    function deposit() external payable;

    function withdraw(uint256) external;
}

Settings
{
  "evmVersion": "cancun",
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "remappings": [
    "project/:@openzeppelin/contracts/=npm/@openzeppelin/[email protected]/",
    "project/:@openzeppelin/contracts/=npm/@openzeppelin/[email protected]/",
    "project/:@openzeppelin/contracts/=npm/@openzeppelin/[email protected]/",
    "project/:@openzeppelin/contracts/=npm/@openzeppelin/[email protected]/",
    "project/:@openzeppelin/contracts/=npm/@openzeppelin/[email protected]/",
    "project/:@uniswap/v4-periphery/=npm/@uniswap/[email protected]/",
    "project/:@uniswap/v4-periphery/=npm/@uniswap/[email protected]/",
    "project/:@uniswap/v4-periphery/=npm/@uniswap/[email protected]/",
    "project/:@uniswap/v4-periphery/=npm/@uniswap/[email protected]/"
  ]
}

Contract Security Audit

Contract ABI

API
[{"inputs":[{"internalType":"address","name":"strategyToken","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"NoEligiblePositions","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"OwnableInvalidOwner","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"OwnableUnauthorizedAccount","type":"error"},{"inputs":[],"name":"PMOnly","type":"error"},{"inputs":[],"name":"ReentrancyGuardReentrantCall","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"bps","type":"uint256"}],"name":"CallerBountyUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"proceedsWeth","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"burned","type":"uint256"},{"indexed":false,"internalType":"address","name":"caller","type":"address"},{"indexed":false,"internalType":"uint256","name":"bounty","type":"uint256"}],"name":"Closed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"idKept","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"idMerged","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newPNKSTRAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newCost","type":"uint256"}],"name":"Consolidated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"a","type":"address"},{"indexed":false,"internalType":"bool","name":"allowed","type":"bool"}],"name":"EthSenderAllowed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"newValue","type":"uint256"}],"name":"MinPositionWethUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"newValue","type":"uint256"}],"name":"MinWethToOpenUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"wethBalance","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"wethUsed","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"positionsOpened","type":"uint256"},{"indexed":false,"internalType":"address","name":"caller","type":"address"},{"indexed":false,"internalType":"uint256","name":"bounty","type":"uint256"}],"name":"OpenAttempt","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountPNKSTR","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"costWeth","type":"uint256"}],"name":"Opened","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"STRPNKIn","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"WETHOut","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"devWethSent","type":"uint256"},{"indexed":false,"internalType":"address","name":"caller","type":"address"},{"indexed":false,"internalType":"uint256","name":"bounty","type":"uint256"}],"name":"Processed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"token","type":"address"}],"name":"V4RouteDeleted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"token","type":"address"}],"name":"V4RouteFrozen","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"address","name":"router","type":"address"},{"indexed":false,"internalType":"address","name":"hook","type":"address"},{"indexed":false,"internalType":"uint24","name":"fee","type":"uint24"},{"indexed":false,"internalType":"int24","name":"spacing","type":"int24"}],"name":"V4RouteSet","type":"event"},{"inputs":[],"name":"BPS","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_BOUNTY_WETH","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_CONSOLIDATIONS","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_OPEN_POSITIONS","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_POSITION_WETH","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MIN_PROBE_ABS","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PNKSTR","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"POOL_MANAGER","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PROCESS_PROBE_BPS","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"STRPNK","outputs":[{"internalType":"contract IStrategyToken","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"TARGET_PROFIT_OUT_BPS","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"TOTAL_PARTS","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"WETH","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"caller_bounty_bps","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"closeFirstEligible","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"cumulativeWethCost","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"cumulativeWethProceeds","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"deleteV4Route","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"devSliceParts","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"ethSenderAllowed","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"freezeV4Route","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getOpenPositions","outputs":[{"internalType":"uint256[]","name":"ids","type":"uint256[]"},{"internalType":"uint256[]","name":"amountPNKSTR","type":"uint256[]"},{"internalType":"uint256[]","name":"costWeth","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"name":"getPosition","outputs":[{"internalType":"uint256","name":"amountPNKSTR","type":"uint256"},{"internalType":"uint256","name":"costWeth","type":"uint256"},{"internalType":"bool","name":"open","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"idx","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"minProcessingSTRPNK","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"minWethToOpen","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"min_position_weth","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"openCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"openIds","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"openIfThreshold","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"positions","outputs":[{"internalType":"uint256","name":"amountPNKSTR","type":"uint256"},{"internalType":"uint256","name":"costWeth","type":"uint256"},{"internalType":"bool","name":"open","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"positionsCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"processFees","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"processSlippageBps","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newBps","type":"uint256"}],"name":"setBountyBps","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"a","type":"address"},{"internalType":"bool","name":"allowed","type":"bool"}],"name":"setEthSenderAllowed","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newMin","type":"uint256"}],"name":"setMinPositionWeth","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newMin","type":"uint256"}],"name":"setMinWethToOpen","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"router_","type":"address"},{"internalType":"address","name":"hook_","type":"address"},{"internalType":"uint24","name":"fee_","type":"uint24"},{"internalType":"int24","name":"spacing_","type":"int24"}],"name":"setV4Route","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"stratSliceParts","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"sumOpenCostWeth","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"swapDeadlineSeconds","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalClosedPositions","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalOpenedPositions","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"v4Routes","outputs":[{"internalType":"address","name":"router","type":"address"},{"internalType":"address","name":"hook","type":"address"},{"internalType":"uint24","name":"fee","type":"uint24"},{"internalType":"int24","name":"tickSpacing","type":"int24"},{"internalType":"bool","name":"frozen","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"wrapStuckETH","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]

60a060405267016345785d8a00006002556703782dace9d90000600355603260045534801561002c575f5ffd5b5060405161316638038061316683398101604081905261004b9161011e565b338061007157604051631e4fbdf760e01b81525f60048201526024015b60405180910390fd5b61007a816100cf565b50600180556001600160a01b0381166100be5760405162461bcd60e51b81526020600482015260066024820152650616464723d360d41b6044820152606401610068565b6001600160a01b031660805261014b565b5f80546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b5f6020828403121561012e575f5ffd5b81516001600160a01b0381168114610144575f5ffd5b9392505050565b608051612fe761017f5f395f818161046c01528181611289015281816113020152818161140601526114c80152612fe75ff3fe6080604052600436106102a7575f3560e01c806399fbab881161016f578063cd0de4cd116100d8578063eb02c30111610092578063f54244b41161006d578063f54244b414610936578063f595b97314610951578063f9f3542214610970578063fbb3dc7514610985575f5ffd5b8063eb02c301146108e3578063ec94d52e14610902578063f2fde38b14610917575f5ffd5b8063cd0de4cd14610864578063cd76f49914610878578063cfaf380e14610892578063d9247cd9146108a6578063ddf99af6146108ba578063e8d86bbf146108ce575f5ffd5b8063aeadb8e011610129578063aeadb8e0146107d7578063af61a41a146107eb578063b9a7fe981461080a578063ba69ebed1461081e578063c34c0bda14610832578063c5ddd0a914610850575f5ffd5b806399fbab88146106eb5780639b02972e146107275780639fabb39014610746578063a233638014610784578063a298311e14610798578063ad5c4648146107b7575f5ffd5b806351ce503311610211578063768ca3e1116101cb578063768ca3e1146105b757806387a0ca0c146105d657806388c7670a146106015780638da5cb5b14610616578063949de8d21461063257806396b7f2e3146106d7575f5ffd5b806351ce50331461051c5780635ba0d79c146105305780635dca718014610545578063615b75941461056c57806362308e8514610581578063715018a6146105a3575f5ffd5b8063241c5ee011610262578063241c5ee01461045b578063249d39e9146104a65780633a467d1c146104bb5780633ef3ac18146104da5780633f8555ea146104f4578063444d760014610508575f5ffd5b8062f35313146103b25780630fbac333146103da57806310ef68ac146103fd57806313a1bfc9146104125780631559026f1461042757806319d759551461043c575f5ffd5b366103ae57336e04444c5dc75cb358380d2e3de08a9081148015906102e257506001600160a01b0381165f516020612f925f395f51905f5214155b801561030657506001600160a01b0381165f908152600b602052604090205460ff16155b156103245760405163807af73360e01b815260040160405180910390fd5b6001600160a01b0381165f516020612f925f395f51905f521480159061034957505f34115b156103ac575f516020612f925f395f51905f526001600160a01b031663d0e30db0346040518263ffffffff1660e01b81526004015f604051808303818588803b158015610394575f5ffd5b505af11580156103a6573d5f5f3e3d5ffd5b50505050505b005b5f5ffd5b3480156103bd575f5ffd5b506103c761292281565b6040519081526020015b60405180910390f35b3480156103e5575f5ffd5b506103ee6109a4565b6040516103d193929190612c85565b348015610408575f5ffd5b506103c760095481565b34801561041d575f5ffd5b506103c760025481565b348015610432575f5ffd5b506103c760055481565b348015610447575f5ffd5b506103ac610456366004612cd8565b610b3c565b348015610466575f5ffd5b5061048e7f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b0390911681526020016103d1565b3480156104b1575f5ffd5b506103c761271081565b3480156104c6575f5ffd5b506103ac6104d5366004612d11565b610ba2565b3480156104e5575f5ffd5b506103c766038d7ea4c6800081565b3480156104ff575f5ffd5b506103c7600a81565b348015610513575f5ffd5b506103c7607881565b348015610527575f5ffd5b506103c7601481565b34801561053b575f5ffd5b506103c760075481565b348015610550575f5ffd5b5061048e73c50673edb3a7b94e8cad8a7d4e0cd68864e33edf81565b348015610577575f5ffd5b506103c761226081565b34801561058c575f5ffd5b5061048e6e04444c5dc75cb358380d2e3de08a9081565b3480156105ae575f5ffd5b506103ac610cc9565b3480156105c2575f5ffd5b506103ac6105d1366004612d28565b610cdc565b3480156105e1575f5ffd5b506103c76105f0366004612d11565b600e6020525f908152604090205481565b34801561060c575f5ffd5b506103c760045481565b348015610621575f5ffd5b505f546001600160a01b031661048e565b34801561063d575f5ffd5b5061069561064c366004612d28565b600a6020525f9081526040902080546001909101546001600160a01b0391821691811690600160a01b810462ffffff1690600160b81b810460020b90600160d01b900460ff1685565b604080516001600160a01b03968716815295909416602086015262ffffff9092169284019290925260029190910b60608301521515608082015260a0016103d1565b3480156106e2575f5ffd5b506103ac610d8d565b3480156106f6575f5ffd5b5061070a610705366004612d11565b610f34565b6040805193845260208401929092521515908201526060016103d1565b348015610732575f5ffd5b506103ac610741366004612d28565b610f68565b348015610751575f5ffd5b50610774610760366004612d28565b600b6020525f908152604090205460ff1681565b60405190151581526020016103d1565b34801561078f575f5ffd5b506103c7600381565b3480156107a3575f5ffd5b506103ac6107b2366004612d11565b610fcf565b3480156107c2575f5ffd5b5061048e5f516020612f925f395f51905f5281565b3480156107e2575f5ffd5b50600c546103c7565b3480156107f6575f5ffd5b506103c7610805366004612d11565b611098565b348015610815575f5ffd5b506103ac6110b7565b348015610829575f5ffd5b506103ac6113e7565b34801561083d575f5ffd5b506103c76a0422ca8b0a00a42500000081565b34801561085b575f5ffd5b506103c7603281565b34801561086f575f5ffd5b506103c7600281565b348015610883575f5ffd5b506103c766b1a2bc2ec5000081565b34801561089d575f5ffd5b50600d546103c7565b3480156108b1575f5ffd5b506103ac6115f6565b3480156108c5575f5ffd5b506103c7600881565b3480156108d9575f5ffd5b506103c760065481565b3480156108ee575f5ffd5b5061070a6108fd366004612d11565b6115fe565b34801561090d575f5ffd5b506103c760035481565b348015610922575f5ffd5b506103ac610931366004612d28565b611641565b348015610941575f5ffd5b506103c7678ac7230489e8000081565b34801561095c575f5ffd5b506103ac61096b366004612d41565b61167e565b34801561097b575f5ffd5b506103c760085481565b348015610990575f5ffd5b506103ac61099f366004612d11565b611890565b600d54606090819081908067ffffffffffffffff8111156109c7576109c7612db5565b6040519080825280602002602001820160405280156109f0578160200160208202803683370190505b5093508067ffffffffffffffff811115610a0c57610a0c612db5565b604051908082528060200260200182016040528015610a35578160200160208202803683370190505b5092508067ffffffffffffffff811115610a5157610a51612db5565b604051908082528060200260200182016040528015610a7a578160200160208202803683370190505b5091505f5b81811015610b35575f600d8281548110610a9b57610a9b612dc9565b905f5260205f200154905080868381518110610ab957610ab9612dc9565b6020026020010181815250505f600c8281548110610ad957610ad9612dc9565b905f5260205f2090600302019050805f0154868481518110610afd57610afd612dc9565b6020026020010181815250508060010154858481518110610b2057610b20612dc9565b60209081029190910101525050600101610a7f565b5050909192565b610b44611942565b6001600160a01b0382165f818152600b6020908152604091829020805460ff191685151590811790915591519182527fabc93e42824fd1d6f09c9abfa5aa067aac665027da96f412c594856750e7e045910160405180910390a25050565b610baa611942565b662386f26fc10000811015610bf45760405162461bcd60e51b815260206004820152600b60248201526a6d696e20746f6f206c6f7760a81b60448201526064015b60405180910390fd5b678ac7230489e80000811115610c3b5760405162461bcd60e51b815260206004820152600c60248201526b0dad2dc40e8dede40d0d2ced60a31b6044820152606401610beb565b600254811015610c8d5760405162461bcd60e51b815260206004820152601860248201527f6d696e2062656c6f7720706f736974696f6e20666c6f6f7200000000000000006044820152606401610beb565b60038190556040518181527faa2583f0ff0c25906950058f3c748635818c29948f7dd754bacc9af690c94a75906020015b60405180910390a150565b610cd1611942565b610cda5f61196e565b565b610ce4611942565b6001600160a01b0381165f908152600a602052604090206001810154600160d01b900460ff1615610d415760405162461bcd60e51b8152602060048201526007602482015266616c726561647960c81b6044820152606401610beb565b60018101805460ff60d01b1916600160d01b1790556040516001600160a01b038316907f76a63ed6be0e7e5400976be818191690f4309065532eda351a4580635acd03bb905f90a25050565b610d956119bd565b610d9d6119e7565b6040516370a0823160e01b81523060048201525f905f516020612f925f395f51905f52906370a0823190602401602060405180830381865afa158015610de5573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610e099190612ddd565b9050600354811015610e4f5760405162461bcd60e51b815260206004820152600f60248201526e18995b1bddc81d1a1c995cda1bdb19608a1b6044820152606401610beb565b5f610e5982611a4e565b90505f610e668284612e08565b9050600254811015610eba5760405162461bcd60e51b815260206004820152601d60248201527f696e73756666696369656e7420666f72206d696e20706f736974696f6e0000006044820152606401610beb565b8115610ed857610ed85f516020612f925f395f51905f523384611a94565b5f5f610ee383611af8565b915091507f1968ef02d550af2f309a2f43c743e3265ae8b1ad47e5289cd7c5cb90673bcf808583833388604051610f1e959493929190612e1b565b60405180910390a15050505050610cda60018055565b600c8181548110610f43575f80fd5b5f91825260209091206003909102018054600182015460029092015490925060ff1683565b610f70611942565b6001600160a01b0381165f818152600a602052604080822080546001600160a01b031916815560010180546001600160d81b0319169055517f7ee6152501a65cd87c33683c9c1822102a1ae61addff223a2a93b80bf7ae677c9190a250565b610fd7611942565b678ac7230489e8000081111561101e5760405162461bcd60e51b815260206004820152600c60248201526b0dad2dc40e8dede40d0d2ced60a31b6044820152606401610beb565b662386f26fc100008110156110635760405162461bcd60e51b815260206004820152600b60248201526a6d696e20746f6f206c6f7760a81b6044820152606401610beb565b60028190556040518181527f56dbd8c2753f9fcd08972f2a2d7467cfba516e93d83f8ecb6f564b3b348d8f0a90602001610cbe565b600d81815481106110a7575f80fd5b5f91825260209091200154905081565b6110bf6119bd565b600d545f8190036110e3576040516367d8225160e01b815260040160405180910390fd5b5f6110ec611d34565b80519091505f819003611112576040516367d8225160e01b815260040160405180910390fd5b5f5b818110156113c4575f83828151811061112f5761112f612dc9565b602002602001015190505f600d828154811061114d5761114d612dc9565b905f5260205f20015490505f600c828154811061116c5761116c612dc9565b5f9182526020909120600390910201600281015490915060ff16158061119157508054155b1561119e575050506113bc565b5f6111b28260010154612922612710611f72565b90505f5f6111d873c50673edb3a7b94e8cad8a7d4e0cd68864e33edf855f015485612023565b91509150816111ec575050505050506113bc565b60028401805460ff191690556112018661216d565b600160065f8282546112139190612e47565b925050819055508060085f82825461122b9190612e47565b90915550506001840154600980545f90611246908490612e08565b909155505f905061125682611a4e565b90508015611283576112765f516020612f925f395f51905f523383611a94565b6112808183612e08565b91505b5f6112af7f0000000000000000000000000000000000000000000000000000000000000000845f612228565b90505f81116112ec5760405162461bcd60e51b81526020600482015260096024820152686e6f20535452504e4b60b81b6044820152606401610beb565b604051630852cd8d60e31b8152600481018290527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906342966c68906024015f604051808303815f87803b15801561134b575f5ffd5b505af115801561135d573d5f5f3e3d5ffd5b505050507fb0bfa2d57fd0aa3b59950d00e0c1795d7928f2c973cb6b770e1cd1b60f245c0e87838561138f9190612e47565b8333866040516113a3959493929190612e1b565b60405180910390a15050505050505050505050506113de565b600101611114565b506040516367d8225160e01b815260040160405180910390fd5b610cda60018055565b6113ef6119bd565b6040516370a0823160e01b81523060048201525f907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906370a0823190602401602060405180830381865afa158015611453573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906114779190612ddd565b90506a0422ca8b0a00a4250000008110156114c25760405162461bcd60e51b815260206004820152600b60248201526a616d7420746f6f206c6f7760a81b6044820152606401610beb565b5f6114ed7f0000000000000000000000000000000000000000000000000000000000000000836123d0565b90505f81116115285760405162461bcd60e51b81526020600482015260076024820152660dcde40ae8aa8960cb1b6044820152606401610beb565b5f61153282611a4e565b9050801561155f576115525f516020612f925f395f51905f523383611a94565b61155c8183612e08565b91505b5f61156d836002600a611f72565b905080156115a1576115a15f516020612f925f395f51905f5273a926c8d1f5df9e34e3ab01fb06884fd18cd5e86783611a94565b7f67d2ae7de84e8de40faa2335e3cc00bfbf890cffb70141f2b4a4d481defbd5da846115cd8486612e47565b8333866040516115e1959493929190612e1b565b60405180910390a150505050610cda60018055565b610cda6119e7565b5f5f5f5f600c858154811061161557611615612dc9565b5f918252602090912060039091020180546001820154600290920154909791965060ff16945092505050565b611649611942565b6001600160a01b03811661167257604051631e4fbdf760e01b81525f6004820152602401610beb565b61167b8161196e565b50565b611686611942565b6001600160a01b0385166116c65760405162461bcd60e51b81526020600482015260076024820152660746f6b656e3d360cc1b6044820152606401610beb565b6001600160a01b03841661170a5760405162461bcd60e51b815260206004820152600b60248201526a0763420726f757465723d360ac1b6044820152606401610beb565b6001600160a01b03831661174c5760405162461bcd60e51b81526020600482015260096024820152680763420686f6f6b3d360bc1b6044820152606401610beb565b6001600160a01b0385165f908152600a602052604090206001810154600160d01b900460ff16156117a85760405162461bcd60e51b8152602060048201526006602482015265333937bd32b760d11b6044820152606401610beb565b80546001600160a01b0319166001600160a01b038681169182178355600180840180548884166001600160b81b03199091168117600160a01b62ffffff8a81169182029290921763ffffffff60b81b1916600160b81b928a169290920260ff60d01b1916919091179092555f858152600b60209081526040808320805460ff199081168817909155848452928190208054909316909517909155835195865285015290830152600284900b60608301528716907f55acffbb5f13cac24c24fa3db22818d2b9cf1e26c6a0a492b84987d5b0267b039060800160405180910390a2505050505050565b611898611942565b61271081106118d35760405162461bcd60e51b81526020600482015260076024820152666270733e42505360c81b6044820152606401610beb565b603281101561190d5760405162461bcd60e51b815260206004820152600660248201526506270733c35360d41b6044820152606401610beb565b60048190556040518181527f7f261ba22feddec716b01f75cac5eea74c541d8bb71719189a6c2eafa29564f690602001610cbe565b5f546001600160a01b03163314610cda5760405163118cdaa760e01b8152336004820152602401610beb565b5f80546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6002600154036119e057604051633ee5aeb560e01b815260040160405180910390fd5b6002600155565b47801561167b575f516020612f925f395f51905f526001600160a01b031663d0e30db0826040518263ffffffff1660e01b81526004015f604051808303818588803b158015611a34575f5ffd5b505af1158015611a46573d5f5f3e3d5ffd5b505050505050565b5f5f611a5f83600454612710611f72565b905066b1a2bc2ec50000811115611a7f575066b1a2bc2ec5000092915050565b82811115611a8e575090919050565b92915050565b6040516001600160a01b03838116602483015260448201839052611af391859182169063a9059cbb906064015b604051602081830303815290604052915060e01b6020820180516001600160e01b038381831617835250505050612640565b505050565b5f8082815b6002548210611d2d57600d54601411611b3d576003811015611d2d57611b216126b2565b80611b2b81612e5a565b9150506014600d805490501015611d2d575b5f678ac7230489e800008311611b535782611b5d565b678ac7230489e800005b90505f611b7f73c50673edb3a7b94e8cad8a7d4e0cd68864e33edf835f612228565b600c8054604080516060810182528481526020808201888152600183850181815281870188555f97885293517fdf6966c971051c3d54ec59162606531493a51404a002842f56009d7e5cf4a8c7600388029081019190915591517fdf6966c971051c3d54ec59162606531493a51404a002842f56009d7e5cf4a8c883015592517fdf6966c971051c3d54ec59162606531493a51404a002842f56009d7e5cf4a8c9909101805460ff1916911515919091179055600d8054858752600e90925292852081905580820183559184527fd7b6990105719101dabeb77144f2a3385c8033acd3af97e9423a695e81ad1eb5909101829055600580549495509193909290611c8a908490612e47565b925050819055508260075f828254611ca29190612e47565b925050819055508260095f828254611cba9190612e47565b909155505060408051828152602081018490529081018490527f1235c671a6b39ea1918628853eceb400b8413f8cdb8ca6110e250065affa20d39060600160405180910390a1611d0b600187612e47565b9550611d178388612e47565b9650611d238386612e08565b9450505050611afd565b5050915091565b600d546060905f19908190819081908190819081905f5b81811015611e25575f600d8281548110611d6757611d67612dc9565b905f5260205f20015490505f600c8281548110611d8657611d86612dc9565b5f9182526020909120600390910201600281015490915060ff161580611dab57508054155b15611db7575050611e1d565b5f611dd28260010154670de0b6b3a7640000845f0154611f72565b90508a811015611df15799929892979296929550919350879189611e19565b88811015611e0a57889650879550809850839750611e19565b86811015611e19578096508395505b5050505b600101611d4b565b505f888714611e3c5780611e3881612e5a565b9150505b888514611e515780611e4d81612e5a565b9150505b888314611e665780611e6281612e5a565b9150505b805f03611e89575050604080515f81526020810190915298975050505050505050565b8067ffffffffffffffff811115611ea257611ea2612db5565b604051908082528060200260200182016040528015611ecb578160200160208202803683370190505b5099505f898814611f0157878b82611ee281612e5a565b935081518110611ef457611ef4612dc9565b6020026020010181815250505b898614611f3357858b82611f1481612e5a565b935081518110611f2657611f26612dc9565b6020026020010181815250505b898414611f6557838b82611f4681612e5a565b935081518110611f5857611f58612dc9565b6020026020010181815250505b5050505050505050505090565b5f5f5f611f7f86866128a2565b91509150815f03611fa357838181611f9957611f99612e72565b049250505061201c565b818411611fba57611fba60038515026011186128be565b5f848688095f868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010185841190960395909502919093039390930492909217029150505b9392505050565b6001600160a01b038084165f908152600a60205260408120805491928392161580159061205c575060018101546001600160a01b031615155b801561207557506001810154600160b81b900460020b15155b6120915760405162461bcd60e51b8152600401610beb90612e86565b5f61209b876128cf565b82549091506120b59088906001600160a01b031688612a0a565b81546001600160a01b031663b1a0d5718787600185306120d6607842612e47565b6040518763ffffffff1660e01b81526004016120f796959493929190612ead565b6020604051808303815f875af1925050508015612131575060408051601f3d908101601f1916820190925261212e91810190612ddd565b60015b612142575f5f935093505050612165565b5f8113612157575f5f94509450505050612165565b600194509250612165915050565b935093915050565b600d80545f919061218090600190612e08565b8154811061219057612190612dc9565b905f5260205f20015490505f600d83815481106121af576121af612dc9565b905f5260205f200154905081600d84815481106121ce576121ce612dc9565b5f918252602080832090910192909255838152600e90915260409020839055600d8054806121fe576121fe612f48565b5f828152602080822083015f19908101839055909201909255918152600e90915260408120555050565b6001600160a01b038084165f908152600a602052604081208054919290911615801590612261575060018101546001600160a01b031615155b801561227a57506001810154600160b81b900460020b15155b6122965760405162461bcd60e51b8152600401610beb90612e86565b604051632e1a7d4d60e01b8152600481018590525f516020612f925f395f51905f5290632e1a7d4d906024015f604051808303815f87803b1580156122d9575f5ffd5b505af11580156122eb573d5f5f3e3d5ffd5b505050505f6122f9866128cf565b82549091505f906001600160a01b031663b1a0d57187808860018730612320607842612e47565b6040518863ffffffff1660e01b815260040161234196959493929190612ead565b60206040518083038185885af115801561235d573d5f5f3e3d5ffd5b50505050506040513d601f19601f820116820180604052508101906123829190612ddd565b90505f81136123c65760405162461bcd60e51b815260206004820152601060248201526f076343a20616d6f756e744f75743c3d360841b6044820152606401610beb565b9695505050505050565b6001600160a01b038083165f908152600a602052604081208054919290911615801590612409575060018101546001600160a01b031615155b801561242257506001810154600160b81b900460020b15155b61243e5760405162461bcd60e51b8152600401610beb90612e86565b66038d7ea4c6800083116124ad575f5f61245986865f612023565b91509150816124a35760405162461bcd60e51b81526020600482015260166024820152751c1c9bd8994b5bdb9b1e481cddd85c0819985a5b195960521b6044820152606401610beb565b9250611a8e915050565b5f6124bc846032612710611f72565b9050805f036124cf575066038d7ea4c680005b838110612534575f5f6124e387875f612023565b91509150816125295760405162461bcd60e51b81526020600482015260126024820152711cda5b99db19481cddd85c0819985a5b195960721b6044820152606401610beb565b9350611a8e92505050565b5f5f61254187845f612023565b9150915081801561255157505f81115b6125875760405162461bcd60e51b8152602060048201526007602482015266070726f62653d360cc1b6044820152606401610beb565b5f61259b82670de0b6b3a764000086611f72565b90505f6125a88589612e08565b90505f6125be8284670de0b6b3a7640000611f72565b90505f6125d082612260612710611f72565b90505f5f6125df8d8685612023565b91509150816126255760405162461bcd60e51b815260206004820152601260248201527172657374207377617020736c69707061676560701b6044820152606401610beb565b61262f8188612e47565b9d9c50505050505050505050505050565b5f5f60205f8451602086015f885af18061265f576040513d5f823e3d81fd5b50505f513d91508115612676578060011415612683565b6001600160a01b0384163b155b156126ac57604051635274afe760e01b81526001600160a01b0385166004820152602401610beb565b50505050565b600d54600211156126bf57565b5f8080808080805b600d54811015612796575f600d82815481106126e5576126e5612dc9565b905f5260205f20015490505f600c828154811061270457612704612dc9565b5f9182526020909120600390910201600281015490915060ff16158061272957508054155b1561273557505061278e565b5f6127508260010154670de0b6b3a7640000845f0154611f72565b905089158061275e57508781105b1561276e57600199508097508295505b88158061277a57508681115b1561278a57600198508096508294505b5050505b6001016126c7565b508515806127a2575084155b806127ac57508082145b156127b957505050505050565b5f600c83815481106127cd576127cd612dc9565b905f5260205f20906003020190505f600c83815481106127ef576127ef612dc9565b905f5260205f2090600302019050805f0154825f015f8282546128129190612e47565b925050819055508060010154826001015f8282546128309190612e47565b909155505060028101805460ff1916905561284a83612b33565b8154600183015460408051878152602081018790529081019290925260608201527f23f618f6bbd9b457f1a83bce4b7223d6d20941fbacd6bec07cb19e93574d69d59060800160405180910390a15050505050505050565b5f805f1983850993909202808410938190039390930393915050565b634e487b715f52806020526024601cfd5b6040805160a0810182525f808252602082018190529181018290526060810182905260808101919091526001600160a01b0382165f908152600a602052604090206001810154600160d01b900460ff1661295e5760405162461bcd60e51b815260206004820152601060248201526f3937baba32903737ba10333937bd32b760811b6044820152606401610beb565b80546001600160a01b031615801590612983575060018101546001600160a01b031615155b801561299c57506001810154600160b81b900460020b15155b6129b85760405162461bcd60e51b8152600401610beb90612e86565b6040805160a0810182525f81526001600160a01b03948516602082015260019290920154600160a01b810462ffffff1691830191909152600160b81b810460020b606083015290921660808301525090565b612a49836040518060400160405280601881526020017f617070726f76653a20746f6b656e2021636f6e74726163740000000000000000815250612b4e565b612a88826040518060400160405280601a81526020017f617070726f76653a207370656e6465722021636f6e7472616374000000000000815250612b4e565b604051636eb1769f60e11b81523060048201526001600160a01b03838116602483015284915f9183169063dd62ed3e90604401602060405180830381865afa158015612ad6573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612afa9190612ddd565b905082811015612b2c57612b186001600160a01b038316855f612b77565b612b2c6001600160a01b0383168585612b77565b5050505050565b5f818152600e6020526040902054612b4a8161216d565b5050565b806001600160a01b0383163b611af35760405162461bcd60e51b8152600401610beb9190612f5c565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663095ea7b360e01b179052612bc88482612c06565b6126ac576040516001600160a01b0384811660248301525f6044830152612bfc91869182169063095ea7b390606401611ac1565b6126ac8482612640565b5f5f5f5f60205f8651602088015f8a5af192503d91505f5190508280156123c657508115612c3757806001146123c6565b50505050506001600160a01b03163b151590565b5f8151808452602084019350602083015f5b82811015612c7b578151865260209586019590910190600101612c5d565b5093949350505050565b606081525f612c976060830186612c4b565b8281036020840152612ca98186612c4b565b905082810360408401526123c68185612c4b565b80356001600160a01b0381168114612cd3575f5ffd5b919050565b5f5f60408385031215612ce9575f5ffd5b612cf283612cbd565b915060208301358015158114612d06575f5ffd5b809150509250929050565b5f60208284031215612d21575f5ffd5b5035919050565b5f60208284031215612d38575f5ffd5b61201c82612cbd565b5f5f5f5f5f60a08688031215612d55575f5ffd5b612d5e86612cbd565b9450612d6c60208701612cbd565b9350612d7a60408701612cbd565b9250606086013562ffffff81168114612d91575f5ffd5b91506080860135600281900b8114612da7575f5ffd5b809150509295509295909350565b634e487b7160e01b5f52604160045260245ffd5b634e487b7160e01b5f52603260045260245ffd5b5f60208284031215612ded575f5ffd5b5051919050565b634e487b7160e01b5f52601160045260245ffd5b81810381811115611a8e57611a8e612df4565b948552602085019390935260408401919091526001600160a01b03166060830152608082015260a00190565b80820180821115611a8e57611a8e612df4565b5f60018201612e6b57612e6b612df4565b5060010190565b634e487b7160e01b5f52601260045260245ffd5b6020808252600d908201526c763420696e636f6d706c65746560981b604082015260600190565b868152856020820152841515604082015260018060a01b03845116606082015260018060a01b03602085015116608082015262ffffff60408501511660a0820152606084015160020b60c082015260018060a01b0360808501511660e08201526101606101008201525f612f2861016083015f815260200190565b6001600160a01b0394909416610120830152506101400152949350505050565b634e487b7160e01b5f52603160045260245ffd5b602081525f82518060208401528060208501604085015e5f604082850101526040601f19601f8301168401019150509291505056fe000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2a2646970667358221220989b9d35f861785059a975926944dd29408af5757c913c29b59986eaf95ed5e564736f6c634300081c003300000000000000000000000024b5664083b89ae7c2b7a4a6efea472a6d47314c

Deployed Bytecode

0x6080604052600436106102a7575f3560e01c806399fbab881161016f578063cd0de4cd116100d8578063eb02c30111610092578063f54244b41161006d578063f54244b414610936578063f595b97314610951578063f9f3542214610970578063fbb3dc7514610985575f5ffd5b8063eb02c301146108e3578063ec94d52e14610902578063f2fde38b14610917575f5ffd5b8063cd0de4cd14610864578063cd76f49914610878578063cfaf380e14610892578063d9247cd9146108a6578063ddf99af6146108ba578063e8d86bbf146108ce575f5ffd5b8063aeadb8e011610129578063aeadb8e0146107d7578063af61a41a146107eb578063b9a7fe981461080a578063ba69ebed1461081e578063c34c0bda14610832578063c5ddd0a914610850575f5ffd5b806399fbab88146106eb5780639b02972e146107275780639fabb39014610746578063a233638014610784578063a298311e14610798578063ad5c4648146107b7575f5ffd5b806351ce503311610211578063768ca3e1116101cb578063768ca3e1146105b757806387a0ca0c146105d657806388c7670a146106015780638da5cb5b14610616578063949de8d21461063257806396b7f2e3146106d7575f5ffd5b806351ce50331461051c5780635ba0d79c146105305780635dca718014610545578063615b75941461056c57806362308e8514610581578063715018a6146105a3575f5ffd5b8063241c5ee011610262578063241c5ee01461045b578063249d39e9146104a65780633a467d1c146104bb5780633ef3ac18146104da5780633f8555ea146104f4578063444d760014610508575f5ffd5b8062f35313146103b25780630fbac333146103da57806310ef68ac146103fd57806313a1bfc9146104125780631559026f1461042757806319d759551461043c575f5ffd5b366103ae57336e04444c5dc75cb358380d2e3de08a9081148015906102e257506001600160a01b0381165f516020612f925f395f51905f5214155b801561030657506001600160a01b0381165f908152600b602052604090205460ff16155b156103245760405163807af73360e01b815260040160405180910390fd5b6001600160a01b0381165f516020612f925f395f51905f521480159061034957505f34115b156103ac575f516020612f925f395f51905f526001600160a01b031663d0e30db0346040518263ffffffff1660e01b81526004015f604051808303818588803b158015610394575f5ffd5b505af11580156103a6573d5f5f3e3d5ffd5b50505050505b005b5f5ffd5b3480156103bd575f5ffd5b506103c761292281565b6040519081526020015b60405180910390f35b3480156103e5575f5ffd5b506103ee6109a4565b6040516103d193929190612c85565b348015610408575f5ffd5b506103c760095481565b34801561041d575f5ffd5b506103c760025481565b348015610432575f5ffd5b506103c760055481565b348015610447575f5ffd5b506103ac610456366004612cd8565b610b3c565b348015610466575f5ffd5b5061048e7f00000000000000000000000024b5664083b89ae7c2b7a4a6efea472a6d47314c81565b6040516001600160a01b0390911681526020016103d1565b3480156104b1575f5ffd5b506103c761271081565b3480156104c6575f5ffd5b506103ac6104d5366004612d11565b610ba2565b3480156104e5575f5ffd5b506103c766038d7ea4c6800081565b3480156104ff575f5ffd5b506103c7600a81565b348015610513575f5ffd5b506103c7607881565b348015610527575f5ffd5b506103c7601481565b34801561053b575f5ffd5b506103c760075481565b348015610550575f5ffd5b5061048e73c50673edb3a7b94e8cad8a7d4e0cd68864e33edf81565b348015610577575f5ffd5b506103c761226081565b34801561058c575f5ffd5b5061048e6e04444c5dc75cb358380d2e3de08a9081565b3480156105ae575f5ffd5b506103ac610cc9565b3480156105c2575f5ffd5b506103ac6105d1366004612d28565b610cdc565b3480156105e1575f5ffd5b506103c76105f0366004612d11565b600e6020525f908152604090205481565b34801561060c575f5ffd5b506103c760045481565b348015610621575f5ffd5b505f546001600160a01b031661048e565b34801561063d575f5ffd5b5061069561064c366004612d28565b600a6020525f9081526040902080546001909101546001600160a01b0391821691811690600160a01b810462ffffff1690600160b81b810460020b90600160d01b900460ff1685565b604080516001600160a01b03968716815295909416602086015262ffffff9092169284019290925260029190910b60608301521515608082015260a0016103d1565b3480156106e2575f5ffd5b506103ac610d8d565b3480156106f6575f5ffd5b5061070a610705366004612d11565b610f34565b6040805193845260208401929092521515908201526060016103d1565b348015610732575f5ffd5b506103ac610741366004612d28565b610f68565b348015610751575f5ffd5b50610774610760366004612d28565b600b6020525f908152604090205460ff1681565b60405190151581526020016103d1565b34801561078f575f5ffd5b506103c7600381565b3480156107a3575f5ffd5b506103ac6107b2366004612d11565b610fcf565b3480156107c2575f5ffd5b5061048e5f516020612f925f395f51905f5281565b3480156107e2575f5ffd5b50600c546103c7565b3480156107f6575f5ffd5b506103c7610805366004612d11565b611098565b348015610815575f5ffd5b506103ac6110b7565b348015610829575f5ffd5b506103ac6113e7565b34801561083d575f5ffd5b506103c76a0422ca8b0a00a42500000081565b34801561085b575f5ffd5b506103c7603281565b34801561086f575f5ffd5b506103c7600281565b348015610883575f5ffd5b506103c766b1a2bc2ec5000081565b34801561089d575f5ffd5b50600d546103c7565b3480156108b1575f5ffd5b506103ac6115f6565b3480156108c5575f5ffd5b506103c7600881565b3480156108d9575f5ffd5b506103c760065481565b3480156108ee575f5ffd5b5061070a6108fd366004612d11565b6115fe565b34801561090d575f5ffd5b506103c760035481565b348015610922575f5ffd5b506103ac610931366004612d28565b611641565b348015610941575f5ffd5b506103c7678ac7230489e8000081565b34801561095c575f5ffd5b506103ac61096b366004612d41565b61167e565b34801561097b575f5ffd5b506103c760085481565b348015610990575f5ffd5b506103ac61099f366004612d11565b611890565b600d54606090819081908067ffffffffffffffff8111156109c7576109c7612db5565b6040519080825280602002602001820160405280156109f0578160200160208202803683370190505b5093508067ffffffffffffffff811115610a0c57610a0c612db5565b604051908082528060200260200182016040528015610a35578160200160208202803683370190505b5092508067ffffffffffffffff811115610a5157610a51612db5565b604051908082528060200260200182016040528015610a7a578160200160208202803683370190505b5091505f5b81811015610b35575f600d8281548110610a9b57610a9b612dc9565b905f5260205f200154905080868381518110610ab957610ab9612dc9565b6020026020010181815250505f600c8281548110610ad957610ad9612dc9565b905f5260205f2090600302019050805f0154868481518110610afd57610afd612dc9565b6020026020010181815250508060010154858481518110610b2057610b20612dc9565b60209081029190910101525050600101610a7f565b5050909192565b610b44611942565b6001600160a01b0382165f818152600b6020908152604091829020805460ff191685151590811790915591519182527fabc93e42824fd1d6f09c9abfa5aa067aac665027da96f412c594856750e7e045910160405180910390a25050565b610baa611942565b662386f26fc10000811015610bf45760405162461bcd60e51b815260206004820152600b60248201526a6d696e20746f6f206c6f7760a81b60448201526064015b60405180910390fd5b678ac7230489e80000811115610c3b5760405162461bcd60e51b815260206004820152600c60248201526b0dad2dc40e8dede40d0d2ced60a31b6044820152606401610beb565b600254811015610c8d5760405162461bcd60e51b815260206004820152601860248201527f6d696e2062656c6f7720706f736974696f6e20666c6f6f7200000000000000006044820152606401610beb565b60038190556040518181527faa2583f0ff0c25906950058f3c748635818c29948f7dd754bacc9af690c94a75906020015b60405180910390a150565b610cd1611942565b610cda5f61196e565b565b610ce4611942565b6001600160a01b0381165f908152600a602052604090206001810154600160d01b900460ff1615610d415760405162461bcd60e51b8152602060048201526007602482015266616c726561647960c81b6044820152606401610beb565b60018101805460ff60d01b1916600160d01b1790556040516001600160a01b038316907f76a63ed6be0e7e5400976be818191690f4309065532eda351a4580635acd03bb905f90a25050565b610d956119bd565b610d9d6119e7565b6040516370a0823160e01b81523060048201525f905f516020612f925f395f51905f52906370a0823190602401602060405180830381865afa158015610de5573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610e099190612ddd565b9050600354811015610e4f5760405162461bcd60e51b815260206004820152600f60248201526e18995b1bddc81d1a1c995cda1bdb19608a1b6044820152606401610beb565b5f610e5982611a4e565b90505f610e668284612e08565b9050600254811015610eba5760405162461bcd60e51b815260206004820152601d60248201527f696e73756666696369656e7420666f72206d696e20706f736974696f6e0000006044820152606401610beb565b8115610ed857610ed85f516020612f925f395f51905f523384611a94565b5f5f610ee383611af8565b915091507f1968ef02d550af2f309a2f43c743e3265ae8b1ad47e5289cd7c5cb90673bcf808583833388604051610f1e959493929190612e1b565b60405180910390a15050505050610cda60018055565b600c8181548110610f43575f80fd5b5f91825260209091206003909102018054600182015460029092015490925060ff1683565b610f70611942565b6001600160a01b0381165f818152600a602052604080822080546001600160a01b031916815560010180546001600160d81b0319169055517f7ee6152501a65cd87c33683c9c1822102a1ae61addff223a2a93b80bf7ae677c9190a250565b610fd7611942565b678ac7230489e8000081111561101e5760405162461bcd60e51b815260206004820152600c60248201526b0dad2dc40e8dede40d0d2ced60a31b6044820152606401610beb565b662386f26fc100008110156110635760405162461bcd60e51b815260206004820152600b60248201526a6d696e20746f6f206c6f7760a81b6044820152606401610beb565b60028190556040518181527f56dbd8c2753f9fcd08972f2a2d7467cfba516e93d83f8ecb6f564b3b348d8f0a90602001610cbe565b600d81815481106110a7575f80fd5b5f91825260209091200154905081565b6110bf6119bd565b600d545f8190036110e3576040516367d8225160e01b815260040160405180910390fd5b5f6110ec611d34565b80519091505f819003611112576040516367d8225160e01b815260040160405180910390fd5b5f5b818110156113c4575f83828151811061112f5761112f612dc9565b602002602001015190505f600d828154811061114d5761114d612dc9565b905f5260205f20015490505f600c828154811061116c5761116c612dc9565b5f9182526020909120600390910201600281015490915060ff16158061119157508054155b1561119e575050506113bc565b5f6111b28260010154612922612710611f72565b90505f5f6111d873c50673edb3a7b94e8cad8a7d4e0cd68864e33edf855f015485612023565b91509150816111ec575050505050506113bc565b60028401805460ff191690556112018661216d565b600160065f8282546112139190612e47565b925050819055508060085f82825461122b9190612e47565b90915550506001840154600980545f90611246908490612e08565b909155505f905061125682611a4e565b90508015611283576112765f516020612f925f395f51905f523383611a94565b6112808183612e08565b91505b5f6112af7f00000000000000000000000024b5664083b89ae7c2b7a4a6efea472a6d47314c845f612228565b90505f81116112ec5760405162461bcd60e51b81526020600482015260096024820152686e6f20535452504e4b60b81b6044820152606401610beb565b604051630852cd8d60e31b8152600481018290527f00000000000000000000000024b5664083b89ae7c2b7a4a6efea472a6d47314c6001600160a01b0316906342966c68906024015f604051808303815f87803b15801561134b575f5ffd5b505af115801561135d573d5f5f3e3d5ffd5b505050507fb0bfa2d57fd0aa3b59950d00e0c1795d7928f2c973cb6b770e1cd1b60f245c0e87838561138f9190612e47565b8333866040516113a3959493929190612e1b565b60405180910390a15050505050505050505050506113de565b600101611114565b506040516367d8225160e01b815260040160405180910390fd5b610cda60018055565b6113ef6119bd565b6040516370a0823160e01b81523060048201525f907f00000000000000000000000024b5664083b89ae7c2b7a4a6efea472a6d47314c6001600160a01b0316906370a0823190602401602060405180830381865afa158015611453573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906114779190612ddd565b90506a0422ca8b0a00a4250000008110156114c25760405162461bcd60e51b815260206004820152600b60248201526a616d7420746f6f206c6f7760a81b6044820152606401610beb565b5f6114ed7f00000000000000000000000024b5664083b89ae7c2b7a4a6efea472a6d47314c836123d0565b90505f81116115285760405162461bcd60e51b81526020600482015260076024820152660dcde40ae8aa8960cb1b6044820152606401610beb565b5f61153282611a4e565b9050801561155f576115525f516020612f925f395f51905f523383611a94565b61155c8183612e08565b91505b5f61156d836002600a611f72565b905080156115a1576115a15f516020612f925f395f51905f5273a926c8d1f5df9e34e3ab01fb06884fd18cd5e86783611a94565b7f67d2ae7de84e8de40faa2335e3cc00bfbf890cffb70141f2b4a4d481defbd5da846115cd8486612e47565b8333866040516115e1959493929190612e1b565b60405180910390a150505050610cda60018055565b610cda6119e7565b5f5f5f5f600c858154811061161557611615612dc9565b5f918252602090912060039091020180546001820154600290920154909791965060ff16945092505050565b611649611942565b6001600160a01b03811661167257604051631e4fbdf760e01b81525f6004820152602401610beb565b61167b8161196e565b50565b611686611942565b6001600160a01b0385166116c65760405162461bcd60e51b81526020600482015260076024820152660746f6b656e3d360cc1b6044820152606401610beb565b6001600160a01b03841661170a5760405162461bcd60e51b815260206004820152600b60248201526a0763420726f757465723d360ac1b6044820152606401610beb565b6001600160a01b03831661174c5760405162461bcd60e51b81526020600482015260096024820152680763420686f6f6b3d360bc1b6044820152606401610beb565b6001600160a01b0385165f908152600a602052604090206001810154600160d01b900460ff16156117a85760405162461bcd60e51b8152602060048201526006602482015265333937bd32b760d11b6044820152606401610beb565b80546001600160a01b0319166001600160a01b038681169182178355600180840180548884166001600160b81b03199091168117600160a01b62ffffff8a81169182029290921763ffffffff60b81b1916600160b81b928a169290920260ff60d01b1916919091179092555f858152600b60209081526040808320805460ff199081168817909155848452928190208054909316909517909155835195865285015290830152600284900b60608301528716907f55acffbb5f13cac24c24fa3db22818d2b9cf1e26c6a0a492b84987d5b0267b039060800160405180910390a2505050505050565b611898611942565b61271081106118d35760405162461bcd60e51b81526020600482015260076024820152666270733e42505360c81b6044820152606401610beb565b603281101561190d5760405162461bcd60e51b815260206004820152600660248201526506270733c35360d41b6044820152606401610beb565b60048190556040518181527f7f261ba22feddec716b01f75cac5eea74c541d8bb71719189a6c2eafa29564f690602001610cbe565b5f546001600160a01b03163314610cda5760405163118cdaa760e01b8152336004820152602401610beb565b5f80546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6002600154036119e057604051633ee5aeb560e01b815260040160405180910390fd5b6002600155565b47801561167b575f516020612f925f395f51905f526001600160a01b031663d0e30db0826040518263ffffffff1660e01b81526004015f604051808303818588803b158015611a34575f5ffd5b505af1158015611a46573d5f5f3e3d5ffd5b505050505050565b5f5f611a5f83600454612710611f72565b905066b1a2bc2ec50000811115611a7f575066b1a2bc2ec5000092915050565b82811115611a8e575090919050565b92915050565b6040516001600160a01b03838116602483015260448201839052611af391859182169063a9059cbb906064015b604051602081830303815290604052915060e01b6020820180516001600160e01b038381831617835250505050612640565b505050565b5f8082815b6002548210611d2d57600d54601411611b3d576003811015611d2d57611b216126b2565b80611b2b81612e5a565b9150506014600d805490501015611d2d575b5f678ac7230489e800008311611b535782611b5d565b678ac7230489e800005b90505f611b7f73c50673edb3a7b94e8cad8a7d4e0cd68864e33edf835f612228565b600c8054604080516060810182528481526020808201888152600183850181815281870188555f97885293517fdf6966c971051c3d54ec59162606531493a51404a002842f56009d7e5cf4a8c7600388029081019190915591517fdf6966c971051c3d54ec59162606531493a51404a002842f56009d7e5cf4a8c883015592517fdf6966c971051c3d54ec59162606531493a51404a002842f56009d7e5cf4a8c9909101805460ff1916911515919091179055600d8054858752600e90925292852081905580820183559184527fd7b6990105719101dabeb77144f2a3385c8033acd3af97e9423a695e81ad1eb5909101829055600580549495509193909290611c8a908490612e47565b925050819055508260075f828254611ca29190612e47565b925050819055508260095f828254611cba9190612e47565b909155505060408051828152602081018490529081018490527f1235c671a6b39ea1918628853eceb400b8413f8cdb8ca6110e250065affa20d39060600160405180910390a1611d0b600187612e47565b9550611d178388612e47565b9650611d238386612e08565b9450505050611afd565b5050915091565b600d546060905f19908190819081908190819081905f5b81811015611e25575f600d8281548110611d6757611d67612dc9565b905f5260205f20015490505f600c8281548110611d8657611d86612dc9565b5f9182526020909120600390910201600281015490915060ff161580611dab57508054155b15611db7575050611e1d565b5f611dd28260010154670de0b6b3a7640000845f0154611f72565b90508a811015611df15799929892979296929550919350879189611e19565b88811015611e0a57889650879550809850839750611e19565b86811015611e19578096508395505b5050505b600101611d4b565b505f888714611e3c5780611e3881612e5a565b9150505b888514611e515780611e4d81612e5a565b9150505b888314611e665780611e6281612e5a565b9150505b805f03611e89575050604080515f81526020810190915298975050505050505050565b8067ffffffffffffffff811115611ea257611ea2612db5565b604051908082528060200260200182016040528015611ecb578160200160208202803683370190505b5099505f898814611f0157878b82611ee281612e5a565b935081518110611ef457611ef4612dc9565b6020026020010181815250505b898614611f3357858b82611f1481612e5a565b935081518110611f2657611f26612dc9565b6020026020010181815250505b898414611f6557838b82611f4681612e5a565b935081518110611f5857611f58612dc9565b6020026020010181815250505b5050505050505050505090565b5f5f5f611f7f86866128a2565b91509150815f03611fa357838181611f9957611f99612e72565b049250505061201c565b818411611fba57611fba60038515026011186128be565b5f848688095f868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010185841190960395909502919093039390930492909217029150505b9392505050565b6001600160a01b038084165f908152600a60205260408120805491928392161580159061205c575060018101546001600160a01b031615155b801561207557506001810154600160b81b900460020b15155b6120915760405162461bcd60e51b8152600401610beb90612e86565b5f61209b876128cf565b82549091506120b59088906001600160a01b031688612a0a565b81546001600160a01b031663b1a0d5718787600185306120d6607842612e47565b6040518763ffffffff1660e01b81526004016120f796959493929190612ead565b6020604051808303815f875af1925050508015612131575060408051601f3d908101601f1916820190925261212e91810190612ddd565b60015b612142575f5f935093505050612165565b5f8113612157575f5f94509450505050612165565b600194509250612165915050565b935093915050565b600d80545f919061218090600190612e08565b8154811061219057612190612dc9565b905f5260205f20015490505f600d83815481106121af576121af612dc9565b905f5260205f200154905081600d84815481106121ce576121ce612dc9565b5f918252602080832090910192909255838152600e90915260409020839055600d8054806121fe576121fe612f48565b5f828152602080822083015f19908101839055909201909255918152600e90915260408120555050565b6001600160a01b038084165f908152600a602052604081208054919290911615801590612261575060018101546001600160a01b031615155b801561227a57506001810154600160b81b900460020b15155b6122965760405162461bcd60e51b8152600401610beb90612e86565b604051632e1a7d4d60e01b8152600481018590525f516020612f925f395f51905f5290632e1a7d4d906024015f604051808303815f87803b1580156122d9575f5ffd5b505af11580156122eb573d5f5f3e3d5ffd5b505050505f6122f9866128cf565b82549091505f906001600160a01b031663b1a0d57187808860018730612320607842612e47565b6040518863ffffffff1660e01b815260040161234196959493929190612ead565b60206040518083038185885af115801561235d573d5f5f3e3d5ffd5b50505050506040513d601f19601f820116820180604052508101906123829190612ddd565b90505f81136123c65760405162461bcd60e51b815260206004820152601060248201526f076343a20616d6f756e744f75743c3d360841b6044820152606401610beb565b9695505050505050565b6001600160a01b038083165f908152600a602052604081208054919290911615801590612409575060018101546001600160a01b031615155b801561242257506001810154600160b81b900460020b15155b61243e5760405162461bcd60e51b8152600401610beb90612e86565b66038d7ea4c6800083116124ad575f5f61245986865f612023565b91509150816124a35760405162461bcd60e51b81526020600482015260166024820152751c1c9bd8994b5bdb9b1e481cddd85c0819985a5b195960521b6044820152606401610beb565b9250611a8e915050565b5f6124bc846032612710611f72565b9050805f036124cf575066038d7ea4c680005b838110612534575f5f6124e387875f612023565b91509150816125295760405162461bcd60e51b81526020600482015260126024820152711cda5b99db19481cddd85c0819985a5b195960721b6044820152606401610beb565b9350611a8e92505050565b5f5f61254187845f612023565b9150915081801561255157505f81115b6125875760405162461bcd60e51b8152602060048201526007602482015266070726f62653d360cc1b6044820152606401610beb565b5f61259b82670de0b6b3a764000086611f72565b90505f6125a88589612e08565b90505f6125be8284670de0b6b3a7640000611f72565b90505f6125d082612260612710611f72565b90505f5f6125df8d8685612023565b91509150816126255760405162461bcd60e51b815260206004820152601260248201527172657374207377617020736c69707061676560701b6044820152606401610beb565b61262f8188612e47565b9d9c50505050505050505050505050565b5f5f60205f8451602086015f885af18061265f576040513d5f823e3d81fd5b50505f513d91508115612676578060011415612683565b6001600160a01b0384163b155b156126ac57604051635274afe760e01b81526001600160a01b0385166004820152602401610beb565b50505050565b600d54600211156126bf57565b5f8080808080805b600d54811015612796575f600d82815481106126e5576126e5612dc9565b905f5260205f20015490505f600c828154811061270457612704612dc9565b5f9182526020909120600390910201600281015490915060ff16158061272957508054155b1561273557505061278e565b5f6127508260010154670de0b6b3a7640000845f0154611f72565b905089158061275e57508781105b1561276e57600199508097508295505b88158061277a57508681115b1561278a57600198508096508294505b5050505b6001016126c7565b508515806127a2575084155b806127ac57508082145b156127b957505050505050565b5f600c83815481106127cd576127cd612dc9565b905f5260205f20906003020190505f600c83815481106127ef576127ef612dc9565b905f5260205f2090600302019050805f0154825f015f8282546128129190612e47565b925050819055508060010154826001015f8282546128309190612e47565b909155505060028101805460ff1916905561284a83612b33565b8154600183015460408051878152602081018790529081019290925260608201527f23f618f6bbd9b457f1a83bce4b7223d6d20941fbacd6bec07cb19e93574d69d59060800160405180910390a15050505050505050565b5f805f1983850993909202808410938190039390930393915050565b634e487b715f52806020526024601cfd5b6040805160a0810182525f808252602082018190529181018290526060810182905260808101919091526001600160a01b0382165f908152600a602052604090206001810154600160d01b900460ff1661295e5760405162461bcd60e51b815260206004820152601060248201526f3937baba32903737ba10333937bd32b760811b6044820152606401610beb565b80546001600160a01b031615801590612983575060018101546001600160a01b031615155b801561299c57506001810154600160b81b900460020b15155b6129b85760405162461bcd60e51b8152600401610beb90612e86565b6040805160a0810182525f81526001600160a01b03948516602082015260019290920154600160a01b810462ffffff1691830191909152600160b81b810460020b606083015290921660808301525090565b612a49836040518060400160405280601881526020017f617070726f76653a20746f6b656e2021636f6e74726163740000000000000000815250612b4e565b612a88826040518060400160405280601a81526020017f617070726f76653a207370656e6465722021636f6e7472616374000000000000815250612b4e565b604051636eb1769f60e11b81523060048201526001600160a01b03838116602483015284915f9183169063dd62ed3e90604401602060405180830381865afa158015612ad6573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612afa9190612ddd565b905082811015612b2c57612b186001600160a01b038316855f612b77565b612b2c6001600160a01b0383168585612b77565b5050505050565b5f818152600e6020526040902054612b4a8161216d565b5050565b806001600160a01b0383163b611af35760405162461bcd60e51b8152600401610beb9190612f5c565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663095ea7b360e01b179052612bc88482612c06565b6126ac576040516001600160a01b0384811660248301525f6044830152612bfc91869182169063095ea7b390606401611ac1565b6126ac8482612640565b5f5f5f5f60205f8651602088015f8a5af192503d91505f5190508280156123c657508115612c3757806001146123c6565b50505050506001600160a01b03163b151590565b5f8151808452602084019350602083015f5b82811015612c7b578151865260209586019590910190600101612c5d565b5093949350505050565b606081525f612c976060830186612c4b565b8281036020840152612ca98186612c4b565b905082810360408401526123c68185612c4b565b80356001600160a01b0381168114612cd3575f5ffd5b919050565b5f5f60408385031215612ce9575f5ffd5b612cf283612cbd565b915060208301358015158114612d06575f5ffd5b809150509250929050565b5f60208284031215612d21575f5ffd5b5035919050565b5f60208284031215612d38575f5ffd5b61201c82612cbd565b5f5f5f5f5f60a08688031215612d55575f5ffd5b612d5e86612cbd565b9450612d6c60208701612cbd565b9350612d7a60408701612cbd565b9250606086013562ffffff81168114612d91575f5ffd5b91506080860135600281900b8114612da7575f5ffd5b809150509295509295909350565b634e487b7160e01b5f52604160045260245ffd5b634e487b7160e01b5f52603260045260245ffd5b5f60208284031215612ded575f5ffd5b5051919050565b634e487b7160e01b5f52601160045260245ffd5b81810381811115611a8e57611a8e612df4565b948552602085019390935260408401919091526001600160a01b03166060830152608082015260a00190565b80820180821115611a8e57611a8e612df4565b5f60018201612e6b57612e6b612df4565b5060010190565b634e487b7160e01b5f52601260045260245ffd5b6020808252600d908201526c763420696e636f6d706c65746560981b604082015260600190565b868152856020820152841515604082015260018060a01b03845116606082015260018060a01b03602085015116608082015262ffffff60408501511660a0820152606084015160020b60c082015260018060a01b0360808501511660e08201526101606101008201525f612f2861016083015f815260200190565b6001600160a01b0394909416610120830152506101400152949350505050565b634e487b7160e01b5f52603160045260245ffd5b602081525f82518060208401528060208501604085015e5f604082850101526040601f19601f8301168401019150509291505056fe000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2a2646970667358221220989b9d35f861785059a975926944dd29408af5757c913c29b59986eaf95ed5e564736f6c634300081c0033

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

00000000000000000000000024b5664083b89ae7c2b7a4a6efea472a6d47314c

-----Decoded View---------------
Arg [0] : strategyToken (address): 0x24b5664083b89Ae7c2b7a4A6EFEa472a6d47314C

-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 00000000000000000000000024b5664083b89ae7c2b7a4a6efea472a6d47314c


Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading
Loading...
Loading
[ Download: CSV Export  ]
[ 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.