false
true
0

Contract Address Details

0x543436A60B991eD646bE6CA6ef55F24B8152dC91

Contract Name
VouchStaking
Creator
0xeb59b0–dcef7f at 0x1d7c64–b0c1df
Balance
0 PLS ( )
Tokens
Fetching tokens...
Transactions
28 Transactions
Transfers
76 Transfers
Gas Used
85,472,333
Last Balance Update
26113503
Warning! Contract bytecode has been changed and doesn't match the verified one. Therefore, interaction with this smart contract may be risky.
Contract name:
VouchStaking




Optimization enabled
true
Compiler version
v0.8.26+commit.8a97fa7a




Optimization runs
10
EVM Version
paris




Verified at
2026-01-28T07:28:50.315941Z

Constructor Arguments

0x0000000000000000000000000000000000000000000000000000000069706b60000000000000000000000000d34f5adc24d8cc55c1e832bdf65fffdf80d1314f00000000000000000000000079bb3a0ee435f957ce4f54ee8c3cfadc7278da0c000000000000000000000000a1077a294dde1b09bb078844df40758a5d0f9a27

Arg [0] (uint256) : 1768975200
Arg [1] (address) : 0xd34f5adc24d8cc55c1e832bdf65fffdf80d1314f
Arg [2] (address) : 0x79bb3a0ee435f957ce4f54ee8c3cfadc7278da0c
Arg [3] (address) : 0xa1077a294dde1b09bb078844df40758a5d0f9a27

              

contracts/VouchStaking.sol

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

import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import "@openzeppelin/contracts/utils/Address.sol";

import {HolderRewardsVault} from "./HolderRewardsVault.sol";
import {LPRewardPool} from "./LPRewardPool.sol";
import {StakingRewardPool} from "./StakingRewardPool.sol";

/// @notice Minimal interface for canonical WPLS (wrapped native PLS)
interface IWPLS {
    function deposit() external payable;
    function withdraw(uint256) external;
    function balanceOf(address) external view returns (uint256);
    function transfer(address to, uint256 value) external returns (bool);
}

interface ILPRewardPool {
    function pullTokenTo(address token, address to, uint256 amount) external;
}

interface INetworkProposal {
    function isAdmin(address adminAddress) external view returns (bool);
    function admin() external view returns (address);
    function getVoters() external view returns (address[] memory);
}

/// @notice Interface for Capital Pool contracts
interface ICapitalPool {
    function totalShares() external view returns (uint256);
    function shares(address user) external view returns (uint256);
    function accrueYield() external;
}

/**
 * @title VouchStaking
 * @notice Multi-pool staking contract supporting standard per-second drip rewards and triple holder reward
 *         distributions (VOUCH, VPLS, native PLS) to addresses that stake the VOUCH token in any pool.
 * @dev    Holder rewards are globally aggregated across all pools where the staking token is VOUCH and
 *         distributed pro‑rata based on a user's total VOUCH principal (excludes holder rewards accrual). The
 *         contract uses per-share accumulators scaled by MULTIPLIER for precision. Arithmetic relies on
 *         Solidity 0.8 built-in overflow checks (SafeMath removed for clarity and gas).
 */
contract VouchStaking is ReentrancyGuard {
    using Address for address;
    using SafeERC20 for IERC20;
    using EnumerableSet for EnumerableSet.AddressSet;

    error StandardPoolUnlockOnly();
    error NotAdmin();
    error PoolNotActive();
    error AmountZero();
    error InsufficientStaked();
    error UnlockActive();
    error NotStandardPool();
    error NothingStaked();
    error NoActiveUnlock();
    error NotReady();
    error ConfigNotInitialized();
    error RatioTooHigh();
    error ThresholdTooHigh();
    error ZeroAddress();
    error NotContract(address a);
    error InvalidPoolId();
    error RewardPoolSyncFailed();
    error NotLiquidityPool();
    error PlsTransferFailed();
    error WplsHolderRewardMissing();
    error VouchNotAllowedInLiquidity();
    error UnlockPeriodTooLong();
    error InvalidAddress();
    error NotCapitalPool();
    error CapitalPoolDirectStakeNotAllowed();

    // --------------------------------------------------
    // Constants, Immutables, and Addresses
    // --------------------------------------------------
    uint256 private constant MULTIPLIER = 1e12;
    uint256 private constant SECONDS_PER_YEAR = 60 * 60 * 24 * 365;
    uint256 private immutable startTime;
    HolderRewardsVault public holderRewardsVault;
    IERC20 private vouchToken;
    IERC20 private vplsToken;
    IWPLS private wplsToken;
    address public lpRewardPool;
    INetworkProposal immutable networkProposal = INetworkProposal(0x7783D7040423f75aeF82a3Ec32ed366ca460Fa6c);

    // --------------------------------------------------
    // Data Structures
    // --------------------------------------------------
    /// @notice Staking pool types
    /// @param Standard Standard staking pool with single-token drip rewards
    /// @param Liquidity Liquidity mining pool with multi-token drip rewards
    /// @param Capital Capital pool that accepts vPLS/PLS, scrapes yield, and earns emissions
    enum PoolType { 
        Standard,
        Liquidity,
        Capital
    }
    
    /// @notice Per-user staking info per-pool
    /// @param amount Amount of tokens staked
    /// @param liqLastAccVouchPerShare Last accumulated VOUCH per share for liquidity pool
    /// @param liqLastAccVplsPerShare Last accumulated VPLS per share for liquidity pool
    /// @param liqLastAccWplsPerShare Last accumulated WPLS per share for liquidity pool
    /// @param stdLastAccVouchPerShare Last accumulated VOUCH per share for standard pool
    /// @param stdLastAccVplsPerShare Last accumulated VPLS per share for standard pool
    /// @param stdLastAccWplsPerShare Last accumulated WPLS per share for standard pool
    struct UserInfo {
        uint256 amount;
        uint256 liqLastAccVouchPerShare;
        uint256 liqLastAccVplsPerShare;
        uint256 liqLastAccWplsPerShare;
        uint256 stdLastAccVouchPerShare;
        uint256 stdLastAccVplsPerShare;
        uint256 stdLastAccWplsPerShare;
    }

    /// @notice Pool configuration and aggregate state
    /// @param stakingToken Token accepted for staking in this pool
    /// @param rewardsPool Address of the reward pool contract that holds tokens for drip emissions
    /// @param allocPoint Allocation points assigned to this pool (relative to others in the same rewardsPool)
    /// @param totalStaked Total tokens currently staked in this pool
    /// @param active Whether the pool is active (can stake/unstake/claim)
    /// @param poolType Type of the pool (Standard or Liquidity)
    /// @param liqAccVouchPerShare Accumulated VOUCH per share for liquidity pool
    /// @param liqAccVplsPerShare Accumulated VPLS per share for liquidity pool
    /// @param liqAccWplsPerShare Accumulated WPLS per share for liquidity pool
    /// @param liqLastCalcTime Last timestamp that liquidity pool accumulators were calculated
    /// @param stdAccVouchPerShare Accumulated VOUCH per share for standard pool
    /// @param stdAccVplsPerShare Accumulated VPLS per share for standard pool
    /// @param stdAccWplsPerShare Accumulated WPLS per share for standard pool
    /// @param stdLastCalcTime Last timestamp that standard pool accumulators were calculated
    /// @param unlockingTotal Total VOUCH currently in the process of unlocking in this pool
    struct PoolInfo {
        IERC20 stakingToken;
        address rewardsPool;
        uint256 allocPoint;
        uint256 totalStaked;
        bool active;
        PoolType poolType;
        uint256 liqAccVouchPerShare;
        uint256 liqAccVplsPerShare;
        uint256 liqAccWplsPerShare;
        uint256 liqLastCalcTime;
        uint256 stdAccVouchPerShare;
        uint256 stdAccVplsPerShare;
        uint256 stdAccWplsPerShare;
        uint256 stdLastCalcTime;
        uint256 unlockingTotal;
    }

    /// @notice Per-user global holder reward snapshots + redeemed tracking
    /// @param lastVouchAcc Last global accumulator snapshot for VOUCH holder rewards
    /// @param redeemedVouch Total VOUCH holder reward claimed
    /// @param lastVplsAcc Last global accumulator snapshot for VPLS holder rewards
    /// @param redeemedVpls Total VPLS holder reward claimed
    /// @param lastPlsAcc Last global accumulator snapshot for PLS holder rewards
    /// @param redeemedPls Total PLS holder reward claimed
    struct HolderRewardInfo {
        uint256 lastVouchAcc;
        uint256 redeemedVouch;
        uint256 lastVplsAcc;
        uint256 redeemedVpls;
        uint256 lastPlsAcc;
        uint256 redeemedPls;
    }

    /// @notice RewardPool-level emission configuration
    /// @param initialized Whether the config has been initialized
    /// @param autoUpdate Whether auto-update is enabled for this rewardsPool
    /// @param updateInterval Minimum time between auto-updates
    /// @param updateRatio Percentage of current balance to turn into annual budget on update
    /// @param updateThreshold Minimum % deviation between current drip and target drip to trigger update
    /// @param lastUpdateTime Timestamp of last auto-update
    /// @param baseVouchPerYear Base VOUCH drip rate for this rewardsPool (annualized)
    /// @param baseVplsPerYear Base VPLS drip rate for this rewardsPool (annualized)
    /// @param baseWplsPerYear Base WPLS drip rate for this rewardsPool (annualized)
    /// @param totalAllocPoint sum allocPoints of pools mapped to this rewardsPool
    struct RewardPoolConfig {
        bool initialized;
        bool autoUpdate;
        uint256 updateInterval;
        uint256 updateRatio;
        uint256 updateThreshold;
        uint256 lastUpdateTime;
        uint256 baseVouchPerYear;
        uint256 baseVplsPerYear;
        uint256 baseWplsPerYear;
        uint256 totalAllocPoint;
    }

    /// @notice VOUCH unlock request
    /// @param amount Amount of tokens to unlock
    /// @param startTime Timestamp when the unlock request was made
    struct UnlockRequest { 
        uint256 amount;
        uint256 startTime;
        bool principalReduced; // tracks whether principal/user totals were reduced at unlock time
    }

    /// @notice Per-user cumulative drip rewards (claimed) tracking
    /// @param vouch Total VOUCH drip rewards claimed
    /// @param vpls Total VPLS drip rewards claimed
    /// @param pls Total PLS drip rewards claimed
    struct DripTotals {
        uint256 vouch;
        uint256 vpls;
        uint256 pls;
    }

    // --------------------------------------------------
    // Storage Mappings
    // --------------------------------------------------
    mapping(uint256 => PoolInfo) private poolInfo;
    mapping(uint256 => mapping(address => UserInfo)) public userInfo;
    mapping(address => HolderRewardInfo) private holderRewardInfo; // user => holder rewards snapshot & redeemed cumulative
    mapping(address => uint256) public principalStakedToken; // token => total principal staked (excludes holder rewards)
    mapping(address => uint256) private userTotalVouchStaked; // user => aggregated VOUCH stake across all pools
    mapping(address => RewardPoolConfig) public rewardPoolConfig; // rewardsPool address => config
    mapping(uint256 => mapping(address => UnlockRequest)) private unlockRequests; // pid => user => unlock request
    mapping(uint256 => mapping(address => DripTotals)) private dripRedeemed; // per-pool totals
    mapping(address => DripTotals) private dripRedeemedAll; // global totals across all pools
    mapping(address => uint256) private unlockingTokenTotals; // token => amount currently unlocking (awaiting withdrawal)
    mapping(uint256 => uint256) public totalUnlocking; // pid => total currently unlocking
    mapping(address => uint256) public capitalPoolToPid; // capitalPool address => pid

    // --------------------------------------------------
    // Variables
    // --------------------------------------------------
    uint256 public standardUnlockPeriod = 5 days;
    uint256 private constant MAX_UNLOCK_PERIOD = 14 days;
    uint256 public totalPools;
    uint256 public accVouchHolderRewardsPerShare;
    uint256 public accVplsHolderRewardsPerShare;
    uint256 public accPlsHolderRewardsPerShare;

    // --------------------------------------------------
    // Events
    // --------------------------------------------------
    event Stake(address indexed user, uint256 indexed pid, uint256 amount);
    event Unstake(address indexed user, uint256 indexed pid, uint256 amount);
    event HolderRewardClaimed(address indexed user, uint256 vouchAmount, uint256 vplsAmount, uint256 plsAmount);
    event HolderRewardDistributed(uint256 vouchAmount, uint256 vplsAmount, uint256 plsAmount);
    event PoolInitialized(uint256 indexed pid, address indexed stakingToken, uint256 allocPoint, bool active);
    event PoolUpdated(uint256 indexed pid, uint256 indexed allocPoint, bool indexed active);
    event LiquidityPoolInitialized(uint256 indexed pid, address indexed stakingToken, uint256 allocPoint, bool active);
    event LiquidityClaim(address indexed user, uint256 indexed pid, uint256 vouchAmount, uint256 vplsAmount, uint256 wplsAmount);
    event Claim(address indexed user, uint256 indexed pid, uint256 vouchAmount, uint256 vplsAmount, uint256 wplsAmount);
    event AutoUpdateSettingsUpdated(address indexed rewardsPool, uint256 updateInterval, uint256 updateRatio, uint256 updateThreshold, bool autoUpdate);
    event RewardPoolUpdateSettingsUpdated(address indexed rewardsPool, uint256 updateInterval, uint256 updateRatio, uint256 updateThreshold, bool autoUpdate);
    event UnlockRequested(address indexed user, uint256 indexed pid, uint256 amount, uint256 unlockAt);
    event UnlockCanceled(address indexed user, uint256 indexed pid, uint256 amount);
    event UnlockFinalized(address indexed user, uint256 indexed pid, uint256 amount);
    event UnlockPeriodUpdated(uint256 oldPeriod, uint256 newPeriod);
    event RewardPoolRatesAutoUpdated(address indexed rewardsPool, uint256 baseVouchPerYear, uint256 baseVplsPerYear, uint256 baseWplsPerYear);
    event LpRewardPoolUpdated(address indexed lpRewardPool);
    event CapitalPoolInitialized(uint256 indexed pid, address indexed capitalPool, uint256 allocPoint, bool active);
    event CapitalClaim(address indexed user, uint256 indexed pid, uint256 vouchAmount, uint256 vplsAmount, uint256 wplsAmount);

    // --------------------------------------------------
    // Modifiers
    // --------------------------------------------------
    modifier onlyAdmin() {
        if (!networkProposal.isAdmin(msg.sender)) revert NotAdmin();
        _;
    }

    // --------------------------------------------------
    // Constructor
    // --------------------------------------------------
    /**
     * @param _startTime Emission start timestamp
     * @param _vouchToken Address of the VOUCH token (holder rewards + staking rewards)
     * @param _vplsToken Address of the VPLS token (staking rewards)
     * @param _wplsToken Address of wrapped PLS token (can be zero address to disable wrapping)
     */
    constructor(
        uint256 _startTime,
        address _vouchToken,
        address _vplsToken,
        address _wplsToken
    ) {
        if (_vouchToken == address(0)) revert InvalidAddress();
        if (_vplsToken == address(0)) revert InvalidAddress();
        if (_wplsToken == address(0)) revert InvalidAddress();
        startTime = _startTime;
        vouchToken = IERC20(_vouchToken);
        vplsToken = IERC20(_vplsToken);
        holderRewardsVault = new HolderRewardsVault(address(this));
        wplsToken = IWPLS(_wplsToken);

        lpRewardPool = address(new LPRewardPool(address(this)));
    }

    // --------------------------------------------------
    // User Functions
    // --------------------------------------------------
    /**
     * @notice Stake tokens into a pool
     * @param _pid Pool id
     * @param _amount Amount of staking token to deposit
     */
    function stake(uint256 _pid, uint256 _amount) external nonReentrant {
        PoolInfo storage pool = poolInfo[_pid];
        if (!pool.active) revert PoolNotActive();
        if (pool.poolType == PoolType.Capital) revert CapitalPoolDirectStakeNotAllowed();

        _maybeUpdateRewardPool(pool.rewardsPool);

        if (pool.poolType == PoolType.Liquidity) {
            _calcAccLiquidityRewardsPerShare(_pid);
            _claimLiquidity(_pid, msg.sender);
        } else {
            _claimStandardTriple(_pid, msg.sender);
            if (address(pool.stakingToken) == address(vouchToken)) {
                _distributeHolderRewardDividends(_pid);
                _claimGlobalHolderRewards(msg.sender);
            }
        }

        pool.stakingToken.safeTransferFrom(msg.sender, address(this), _amount);
        pool.totalStaked += _amount;
        principalStakedToken[address(pool.stakingToken)] = principalStakedToken[address(pool.stakingToken)] + _amount;

        UserInfo storage user = userInfo[_pid][msg.sender];
        user.amount += _amount;
        if (address(pool.stakingToken) == address(vouchToken)) {
            userTotalVouchStaked[msg.sender] = userTotalVouchStaked[msg.sender] + _amount;
        }

        if (pool.poolType == PoolType.Liquidity) {
            user.liqLastAccVouchPerShare = pool.liqAccVouchPerShare;
            user.liqLastAccVplsPerShare = pool.liqAccVplsPerShare;
            user.liqLastAccWplsPerShare = pool.liqAccWplsPerShare;
        } else {
            user.stdLastAccVouchPerShare = pool.stdAccVouchPerShare;
            user.stdLastAccVplsPerShare = pool.stdAccVplsPerShare;
            user.stdLastAccWplsPerShare = pool.stdAccWplsPerShare;
        }

        emit Stake(msg.sender, _pid, _amount);
    }

    /**
     * @notice Unstake tokens from a pool (liquidity pools only)
     * @dev Liquidity pools only. Settles and transfers any pending liquidity triple rewards
     *      (VOUCH, VPLS, WPLS) for the caller, then returns the requested principal. This function
     *      does not process global VOUCH holder rewards and cannot be used on Standard pools
     *      (Standard pools require {startUnlock}/{finalizeUnlock}, or {exit} for principal-only).
     * @param _pid Pool id
     * @param _amount Amount to withdraw
     */
    function unstake(uint256 _pid, uint256 _amount) external nonReentrant {
        PoolInfo storage pool = poolInfo[_pid];
        UserInfo storage user = userInfo[_pid][msg.sender];
        if (pool.poolType == PoolType.Standard) {
            revert StandardPoolUnlockOnly();
        }
    if (_amount == 0) revert AmountZero();
    if (user.amount < _amount) revert InsufficientStaked();

        _maybeUpdateRewardPool(pool.rewardsPool);

        _calcAccLiquidityRewardsPerShare(_pid);
        _claimLiquidity(_pid, msg.sender);

        pool.stakingToken.safeTransfer(msg.sender, _amount);
        pool.totalStaked -= _amount;
        principalStakedToken[address(pool.stakingToken)] = principalStakedToken[address(pool.stakingToken)] - _amount;
        user.amount -= _amount;

        user.liqLastAccVouchPerShare = pool.liqAccVouchPerShare;
        user.liqLastAccVplsPerShare = pool.liqAccVplsPerShare;
        user.liqLastAccWplsPerShare = pool.liqAccWplsPerShare;

        emit Unstake(msg.sender, _pid, _amount);
    }

    /**
     * @notice Emergency exit: withdraws full principal only.
     * @dev This does NOT claim any standard drip rewards or global holder rewards.
     *      All accrued rewards are forfeited. Intended for users to quickly recover
     *      their staked principal in emergency situations.
     * @param _pid Pool id
     */
    function exit(uint256 _pid) external nonReentrant {
        PoolInfo storage pool = poolInfo[_pid];
        UserInfo storage user = userInfo[_pid][msg.sender];
    if (user.amount == 0) revert NothingStaked();
        uint256 transferAmount = user.amount;

        if (pool.poolType == PoolType.Standard && standardUnlockPeriod > 0) {
            UnlockRequest storage req = unlockRequests[_pid][msg.sender];
            if (req.amount != 0) revert UnlockActive();

            pool.totalStaked -= transferAmount;
            principalStakedToken[address(pool.stakingToken)] -= transferAmount;
            if (address(pool.stakingToken) == address(vouchToken)) {
                userTotalVouchStaked[msg.sender] -= transferAmount;
                HolderRewardInfo storage hUnlock = holderRewardInfo[msg.sender];
                hUnlock.lastVouchAcc = accVouchHolderRewardsPerShare;
                hUnlock.lastVplsAcc  = accVplsHolderRewardsPerShare;
                hUnlock.lastPlsAcc   = accPlsHolderRewardsPerShare;
            }
            user.amount = 0;

            req.amount = transferAmount;
            req.startTime = block.timestamp;
            req.principalReduced = true;
            pool.unlockingTotal += transferAmount;
            totalUnlocking[_pid] += transferAmount;
            unlockingTokenTotals[address(pool.stakingToken)] += transferAmount;
            emit UnlockRequested(msg.sender, _pid, transferAmount, block.timestamp + standardUnlockPeriod);
        } else {
            pool.totalStaked -= transferAmount;
            principalStakedToken[address(pool.stakingToken)] = principalStakedToken[address(pool.stakingToken)] - transferAmount;
            if (address(pool.stakingToken) == address(vouchToken)) {
                userTotalVouchStaked[msg.sender] = userTotalVouchStaked[msg.sender] - transferAmount;
                HolderRewardInfo storage h = holderRewardInfo[msg.sender];
                h.lastVouchAcc = accVouchHolderRewardsPerShare;
                h.lastVplsAcc  = accVplsHolderRewardsPerShare;
                h.lastPlsAcc   = accPlsHolderRewardsPerShare;
            }
            user.amount = 0;
            pool.stakingToken.safeTransfer(msg.sender, transferAmount);
            emit Unstake(msg.sender, _pid, transferAmount);
        }
    }

    /**
     * @notice Claim all pending rewards for a pool without changing stake
     * @dev Standard pools settle: (1) original single-token drip, (2) standard triple overlay, and
     *      for VOUCH pools, (3) global holder rewards. LP pools settle both triple sources.
     *      Capital pools settle triple-token emissions based on user's share in the CapitalPool.
     */
    function claim(uint256 _pid) external nonReentrant {
        PoolInfo storage pool = poolInfo[_pid];
        _maybeUpdateRewardPool(pool.rewardsPool);
        if (pool.poolType == PoolType.Liquidity) {
            _calcAccLiquidityRewardsPerShare(_pid);
            _claimLiquidity(_pid, msg.sender);
        } else if (pool.poolType == PoolType.Capital) {
            _calcAccCapitalRewardsPerShare(_pid);
            _claimCapital(_pid, msg.sender);
        } else {
            _claimStandardTriple(_pid, msg.sender);
            if (address(pool.stakingToken) == address(vouchToken)) {
                _distributeHolderRewardDividends(_pid);
                _claimGlobalHolderRewards(msg.sender);
            }
        }
    }

    /**
     * @notice Claim all pending holder rewards
     */
    function claimHolderRewards() external nonReentrant {
        _syncHolderRewardsAccumulators();
        _claimGlobalHolderRewards(msg.sender);
    }

    /**
     * @notice Claim every pending reward across all pools for the caller.
     * @dev Iterates all pools and invokes the same logic as {claim} per-pool.
     *      For VOUCH staking pools, also settles global holder rewards. Liquidity
     *      pools settle triple-token emissions via the shared lpRewardPool.
     *      Gas usage scales with the number of pools; intended for convenience.
     */
    function claimAll() external nonReentrant {
        for (uint256 pid = 1; pid <= totalPools; ++pid) {
            PoolInfo storage pool = poolInfo[pid];
            _maybeUpdateRewardPool(pool.rewardsPool);
            if (pool.poolType == PoolType.Liquidity) {
                UserInfo storage user = userInfo[pid][msg.sender];
                if (user.amount == 0) continue;
                _calcAccLiquidityRewardsPerShare(pid);
                _claimLiquidity(pid, msg.sender);
            } else if (pool.poolType == PoolType.Capital) {
                ICapitalPool capitalPool = ICapitalPool(address(pool.stakingToken));
                if (capitalPool.shares(msg.sender) == 0) continue;
                _calcAccCapitalRewardsPerShare(pid);
                _claimCapital(pid, msg.sender);
            } else {
                UserInfo storage user = userInfo[pid][msg.sender];
                if (user.amount == 0) continue;
                _claimStandardTriple(pid, msg.sender);
                if (address(pool.stakingToken) == address(vouchToken)) {
                    _distributeHolderRewardDividends(pid);
                    _claimGlobalHolderRewards(msg.sender);
                }
            }
        }
    }

    /**
     * @notice Claim capital pool rewards for a user - callable by the CapitalPool contract
     * @dev Allows CapitalPool to trigger reward claims before share changes (deposits/withdrawals)
     * @param _capitalPool Address of the CapitalPool contract (must be msg.sender)
     * @param _user User address to claim rewards for
     */
    function claimCapitalFor(address _capitalPool, address _user) external nonReentrant {
        if (msg.sender != _capitalPool) revert NotCapitalPool();
        uint256 pid = capitalPoolToPid[_capitalPool];
        if (pid == 0) revert InvalidPoolId();
        PoolInfo storage pool = poolInfo[pid];
        if (pool.poolType != PoolType.Capital) revert NotCapitalPool();
        
        _maybeUpdateRewardPool(pool.rewardsPool);
        _calcAccCapitalRewardsPerShare(pid);
        _claimCapital(pid, _user);
    }


    /**
     * @notice Begin unlocking a portion of stake for any standard pool. Stops earning immediately.
     *         If unlock period == 0 the tokens are transferred out instantly.
     */
    function startUnlock(uint256 _pid, uint256 _amount) public nonReentrant {
        _startUnlock(_pid, msg.sender, _amount);
    }

    function _startUnlock(uint256 _pid, address _user, uint256 _amount) internal {
        PoolInfo storage pool = poolInfo[_pid];
    if (pool.poolType != PoolType.Standard) revert NotStandardPool();
        UserInfo storage user = userInfo[_pid][_user];
    if (_amount == 0) revert AmountZero();
    if (_amount > user.amount) revert InsufficientStaked();
        UnlockRequest storage req = unlockRequests[_pid][_user];
    if (req.amount != 0) revert UnlockActive();

        _maybeUpdateRewardPool(pool.rewardsPool);

        _claimStandardTriple(_pid, _user);
        if (address(pool.stakingToken) == address(vouchToken)) {
            _distributeHolderRewardDividends(_pid);
            _claimGlobalHolderRewards(_user);
        }

        bool reducePrincipal = address(pool.stakingToken) != address(vouchToken);

        user.amount -= _amount;
        pool.totalStaked -= _amount;
        if (reducePrincipal) {
            principalStakedToken[address(pool.stakingToken)] -= _amount;
        }

        user.stdLastAccVouchPerShare = pool.stdAccVouchPerShare;
        user.stdLastAccVplsPerShare = pool.stdAccVplsPerShare;
        user.stdLastAccWplsPerShare = pool.stdAccWplsPerShare;

        if (standardUnlockPeriod == 0) {
            if (address(pool.stakingToken) == address(vouchToken)) {
                principalStakedToken[address(pool.stakingToken)] -= _amount;
                userTotalVouchStaked[_user] -= _amount;
            }
            pool.stakingToken.safeTransfer(_user, _amount);
            emit UnlockFinalized(_user, _pid, _amount);
            emit Unstake(_user, _pid, _amount);
            return;
        }

        req.amount = _amount;
        req.startTime = block.timestamp;
        req.principalReduced = reducePrincipal;
        pool.unlockingTotal += _amount;
        totalUnlocking[_pid] += _amount;
        if (reducePrincipal) {
            unlockingTokenTotals[address(pool.stakingToken)] += _amount;
        }
        emit UnlockRequested(_user, _pid, _amount, block.timestamp + standardUnlockPeriod);
    }

    /**
     * @notice Cancel an active unlock before it matures and resume earning.
     */
    function cancelUnlock(uint256 _pid) public nonReentrant {
        _cancelUnlock(_pid, msg.sender);
    }

    function _cancelUnlock(uint256 _pid, address _user) internal {
        UnlockRequest storage req = unlockRequests[_pid][_user];
    if (req.amount == 0) revert NoActiveUnlock();
        PoolInfo storage pool = poolInfo[_pid];
    if (pool.poolType != PoolType.Standard) revert NotStandardPool();
        uint256 amt = req.amount;

        _maybeUpdateRewardPool(pool.rewardsPool);

        _calcAccStandardTriple(_pid);

        bool reduced = req.principalReduced;
        pool.unlockingTotal -= amt;
        totalUnlocking[_pid] -= amt;
        if (reduced) {
            unlockingTokenTotals[address(pool.stakingToken)] -= amt;
        }
        req.amount = 0;
        req.startTime = 0;
        req.principalReduced = false;

        UserInfo storage user = userInfo[_pid][_user];
        user.amount += amt;
        pool.totalStaked += amt;
        if (reduced) {
            principalStakedToken[address(pool.stakingToken)] += amt;
            if (address(pool.stakingToken) == address(vouchToken)) {
                userTotalVouchStaked[_user] += amt;
            }
        }

        user.stdLastAccVouchPerShare = pool.stdAccVouchPerShare;
        user.stdLastAccVplsPerShare = pool.stdAccVplsPerShare;
        user.stdLastAccWplsPerShare = pool.stdAccWplsPerShare;

        emit UnlockCanceled(_user, _pid, amt);
    }

    /**
     * @notice Finalize an unlock after the waiting period and withdraw the tokens.
     */
    function finalizeUnlock(uint256 _pid) public nonReentrant {
        _finalizeUnlock(_pid, msg.sender);
    }

    function _finalizeUnlock(uint256 _pid, address _user) internal {
        UnlockRequest storage req = unlockRequests[_pid][_user];
        if (req.amount == 0) revert NoActiveUnlock();
        PoolInfo storage pool = poolInfo[_pid];
        if (pool.poolType != PoolType.Standard) revert NotStandardPool();
        if (block.timestamp < req.startTime + standardUnlockPeriod) revert NotReady();
        uint256 amt = req.amount;

        pool.unlockingTotal -= amt;
        totalUnlocking[_pid] -= amt;
        req.amount = 0;
        req.startTime = 0;
        bool reducePrincipal = req.principalReduced;
        req.principalReduced = false;

        if (address(pool.stakingToken) == address(vouchToken)) {
            _distributeHolderRewardDividends(_pid);
            _claimGlobalHolderRewards(_user);
        }

        if (reducePrincipal) {
            unlockingTokenTotals[address(pool.stakingToken)] -= amt;
        } else {
            if (address(pool.stakingToken) == address(vouchToken)) {
                principalStakedToken[address(pool.stakingToken)] -= amt;
                userTotalVouchStaked[_user] -= amt;
            }
        }

        pool.stakingToken.safeTransfer(_user, amt);
        emit UnlockFinalized(_user, _pid, amt);
    }

    /**
     * @notice Finalize all matured unlocks across a list of pool ids.
     * @dev Skips pools with no unlock or not yet ready. Returns arrays of finalized pool ids and amounts.
     *      Gas usage is linear in pools length. Caller should keep list short/client-side filtered.
     */
    function finalizeAllMaturedUnlocks(uint256[] calldata _pids)
        external
        nonReentrant
        returns (uint256[] memory finalizedPids, uint256[] memory amounts)
    {
        return _finalizeAllMaturedUnlocks(msg.sender, _pids);
    }

    function _finalizeAllMaturedUnlocks(address _user, uint256[] calldata _pids)
        private
        returns (uint256[] memory finalizedPids, uint256[] memory amounts)
    {
        uint256 len = _pids.length;
        finalizedPids = new uint256[](len);
        amounts = new uint256[](len);
        uint256 count;
        for (uint256 i; i < len; ++i) {
            uint256 pid = _pids[i];
            UnlockRequest storage req = unlockRequests[pid][_user];
            if (req.amount == 0) continue;
            if (block.timestamp < req.startTime + standardUnlockPeriod) continue;
            PoolInfo storage pool = poolInfo[pid];
            if (pool.poolType != PoolType.Standard) continue;
            uint256 amt = req.amount;
            pool.unlockingTotal -= amt;
            totalUnlocking[pid] -= amt;
            req.amount = 0;
            req.startTime = 0;
            bool reducePrincipal = req.principalReduced;
            req.principalReduced = false;

            if (address(pool.stakingToken) == address(vouchToken)) {
                _distributeHolderRewardDividends(pid);
                _claimGlobalHolderRewards(_user);
            }

            if (reducePrincipal) {
                unlockingTokenTotals[address(pool.stakingToken)] -= amt;
            } else if (address(pool.stakingToken) == address(vouchToken)) {
                principalStakedToken[address(pool.stakingToken)] -= amt;
                userTotalVouchStaked[_user] -= amt;
            }
            pool.stakingToken.safeTransfer(_user, amt);
            emit UnlockFinalized(_user, pid, amt);
            finalizedPids[count] = pid;
            amounts[count] = amt;
            unchecked { ++count; }
        }

        assembly {
            mstore(finalizedPids, count)
            mstore(amounts, count)
        }
    }

    /**
     * @notice View current unlock status for a user on a pool.
     */
    function getUnlock(uint256 _pid, address _user)
        public
        view
        returns (
            uint256 amount,
            uint256 startTime_,
            uint256 unlockAt,
            uint256 secondsRemaining,
            bool ready
        )
    {
        UnlockRequest storage r = unlockRequests[_pid][_user];
        amount = r.amount;
        startTime_ = r.startTime;
        if (r.amount == 0) {
            unlockAt = 0;
            secondsRemaining = 0;
            ready = false;
        } else {
            unlockAt = r.startTime + standardUnlockPeriod;
            if (block.timestamp >= unlockAt) {
                secondsRemaining = 0;
                ready = true;
            } else {
                secondsRemaining = unlockAt - block.timestamp;
                ready = false;
            }
        }
    }

    /**
     * @notice Batch view helper returning unlock status for multiple pools for a single user.
     * @dev Each element mirrors getUnlock. Empty entries (all zeros, ready=false) mean no active unlock.
     */
    function getUnlocks(address _user, uint256[] calldata _pids)
        public
        view
        returns (
            uint256[] memory amounts,
            uint256[] memory startTimes,
            uint256[] memory unlockAts,
            uint256[] memory secondsRemainings,
            bool[] memory readies
        )
    {
        uint256 len = _pids.length;
        amounts = new uint256[](len);
        startTimes = new uint256[](len);
        unlockAts = new uint256[](len);
        secondsRemainings = new uint256[](len);
        readies = new bool[](len);
        for (uint256 i; i < len; ++i) {
            UnlockRequest storage r = unlockRequests[_pids[i]][_user];
            uint256 amt = r.amount;
            amounts[i] = amt;
            startTimes[i] = r.startTime;
            if (amt == 0) {
                unlockAts[i] = 0;
                secondsRemainings[i] = 0;
                readies[i] = false;
            } else {
                uint256 ua = r.startTime + standardUnlockPeriod;
                unlockAts[i] = ua;
                if (block.timestamp >= ua) {
                    secondsRemainings[i] = 0;
                    readies[i] = true;
                } else {
                    secondsRemainings[i] = ua - block.timestamp;
                    readies[i] = false;
                }
            }
        }
    }

    // --------------------------------------------------
    // Admin Functions
    // --------------------------------------------------    
    /**
     * @notice Configure automatic allocation adjustment parameters for a pool
     * @param _rewardPool Address of the rewards pool
     * @param _updateInterval Minimum seconds between auto-updates
     * @param _updateRatio Ratio (percentage) of rewardsPool token balance to use as new allocPoint baseline
     * @param _updateThreshold Percentage deviation required to trigger update
     * @param _autoUpdate Enable/disable automatic updates
     */
    function setUpdateSettings(
        address _rewardPool,
        uint256 _updateInterval,
        uint256 _updateRatio,
        uint256 _updateThreshold,
        bool _autoUpdate
    ) external onlyAdmin {
        RewardPoolConfig storage cfg = rewardPoolConfig[_rewardPool];
        if (!cfg.initialized) revert ConfigNotInitialized();
        if (_updateRatio > 36500) revert RatioTooHigh();
        if (_updateThreshold > 100) revert ThresholdTooHigh();
        cfg.updateInterval = _updateInterval;
        cfg.updateRatio = _updateRatio;
        cfg.updateThreshold = _updateThreshold;
        cfg.autoUpdate = _autoUpdate;
        emit AutoUpdateSettingsUpdated(
            _rewardPool,
            _updateInterval,
            _updateRatio,
            _updateThreshold,
            _autoUpdate
        );
    }

    /**
     * @notice Add a new staking pool
     * @param _stakingToken Token users will stake
     * @param _rewardsPool Address holding drip tokens
     * @param _allocPoint Initial alloc point (emission parameter)
     */
    function addPool(
        IERC20 _stakingToken,
        address _rewardsPool,
        uint256 _allocPoint,
        bool _active
    ) external onlyAdmin {
        if (address(_stakingToken) == address(0)) revert ZeroAddress();
        if (address(_stakingToken).code.length == 0) revert NotContract(address(_stakingToken));
        if (_rewardsPool == address(0)) revert ZeroAddress();
        if (_rewardsPool.code.length == 0) revert NotContract(_rewardsPool);

        _updateAllPoolsForRewardPool(_rewardsPool);

        PoolInfo storage pool = poolInfo[++totalPools];
        pool.stakingToken = _stakingToken;
        pool.rewardsPool = _rewardsPool;
        pool.allocPoint = _allocPoint;
        pool.totalStaked = 0;
        pool.active = _active;
        pool.poolType = PoolType.Standard;
        pool.stdLastCalcTime = block.timestamp;
        RewardPoolConfig storage cfg = rewardPoolConfig[_rewardsPool];
        if (!cfg.initialized) {
            cfg.initialized = true;
            cfg.lastUpdateTime = block.timestamp;
        }
        cfg.totalAllocPoint += _allocPoint;

        emit PoolInitialized(
            totalPools,
            address(_stakingToken),
            _allocPoint,
            pool.active
        );
    }

    /**
     * @notice Add a new liquidity pool (LP token staking, shared triple-currency drip from vault)
     * @param _stakingToken LP token users will stake
     * @param _allocPoint Pool weight (relative share of global liquidity emissions)
     * @param _active Initial active flag
     */
    function addLiquidityPool(
        IERC20 _stakingToken,
        uint256 _allocPoint,
        address _rewardPool,
        bool _active
    ) external onlyAdmin {
        if (address(_stakingToken) == address(0)) revert ZeroAddress();
        if (address(_stakingToken).code.length == 0) revert NotContract(address(_stakingToken));
        if (_rewardPool == address(0)) revert ZeroAddress();
        if (_rewardPool.code.length == 0) revert NotContract(_rewardPool);
        if (address(_stakingToken) == address(vouchToken)) revert VouchNotAllowedInLiquidity();

        _updateAllPoolsForRewardPool(_rewardPool);

        PoolInfo storage pool = poolInfo[++totalPools];
        pool.stakingToken = _stakingToken;
        pool.rewardsPool = _rewardPool;
        pool.allocPoint = _allocPoint;
        pool.liqLastCalcTime = block.timestamp;
        pool.totalStaked = 0;
        pool.active = _active;
        pool.poolType = PoolType.Liquidity;
        RewardPoolConfig storage cfg = rewardPoolConfig[_rewardPool];
        if (!cfg.initialized) {
            cfg.initialized = true;
            cfg.lastUpdateTime = block.timestamp;
        }
        cfg.totalAllocPoint += _allocPoint;

        emit LiquidityPoolInitialized(totalPools, address(_stakingToken), _allocPoint, _active);
    }

    /**
     * @notice Add a new Capital Pool (vPLS/PLS yield scraping with emission rewards)
     * @param _capitalPool Address of the CapitalPool contract
     * @param _allocPoint Pool weight (relative share of emissions from reward pool)
     * @param _rewardPool Address holding drip tokens
     * @param _active Initial active flag
     */
    function addCapitalPool(
        address _capitalPool,
        uint256 _allocPoint,
        address _rewardPool,
        bool _active
    ) external onlyAdmin {
        if (_capitalPool == address(0)) revert ZeroAddress();
        if (_capitalPool.code.length == 0) revert NotContract(_capitalPool);
        if (_rewardPool == address(0)) revert ZeroAddress();
        if (_rewardPool.code.length == 0) revert NotContract(_rewardPool);

        _updateAllPoolsForRewardPool(_rewardPool);

        PoolInfo storage pool = poolInfo[++totalPools];
        pool.stakingToken = IERC20(_capitalPool);
        pool.rewardsPool = _rewardPool;
        pool.allocPoint = _allocPoint;
        pool.liqLastCalcTime = block.timestamp;
        pool.totalStaked = 0;
        pool.active = _active;
        pool.poolType = PoolType.Capital;
        capitalPoolToPid[_capitalPool] = totalPools;
        RewardPoolConfig storage cfg = rewardPoolConfig[_rewardPool];
        if (!cfg.initialized) {
            cfg.initialized = true;
            cfg.lastUpdateTime = block.timestamp;
        }
        cfg.totalAllocPoint += _allocPoint;

        emit CapitalPoolInitialized(totalPools, _capitalPool, _allocPoint, _active);
    }

    /**
     * @notice Manually update pool allocation and active status
     * @param _pid Pool id
     * @param _allocPoint New allocation point
     * @param _active Active flag
     */
    function set(
        uint256 _pid,
        uint256 _allocPoint,
        bool _active
    ) external onlyAdmin {
    if (_pid > totalPools) revert InvalidPoolId();
        PoolInfo storage pool = poolInfo[_pid];
        _updateAllPoolsForRewardPool(pool.rewardsPool);

        if (pool.allocPoint != _allocPoint) {
            RewardPoolConfig storage cfg = rewardPoolConfig[pool.rewardsPool];
            if (_allocPoint > pool.allocPoint) {
                cfg.totalAllocPoint += (_allocPoint - pool.allocPoint);
            } else {
                cfg.totalAllocPoint -= (pool.allocPoint - _allocPoint);
            }
        }

        pool.allocPoint = _allocPoint;
        pool.active = _active;

        emit PoolUpdated(_pid, _allocPoint, _active);
    }

    /**
     * @dev Settle accumulators for all pools that share a rewardPool, so historical emissions
     *      are accounted with the previous allocation ratios before any change is applied.
     */
    function _updateAllPoolsForRewardPool(address _rewardPool) internal {
        uint256 total = totalPools;
        for (uint256 pid = 1; pid <= total; ++pid) {
            PoolInfo storage p = poolInfo[pid];
            if (p.rewardsPool != _rewardPool) continue;
            if (p.poolType == PoolType.Liquidity) {
                _calcAccLiquidityRewardsPerShare(pid);
            } else if (p.poolType == PoolType.Capital) {
                _calcAccCapitalRewardsPerShare(pid);
            } else {
                _calcAccStandardTriple(pid);
            }
        }
    }

    /**
     * @notice Set the LPRewardPool contract used as the source of liquidity emissions.
     */
    function setLPRewardPool(address _pool) external onlyAdmin {
        lpRewardPool = _pool;
        emit LpRewardPoolUpdated(_pool);
    }

    /// @notice Configure update settings for any rewardPool (used by both standard + liquidity pools)
    function setRewardPoolUpdateSettings(address _rewardPool, uint256 _updateInterval, uint256 _updateRatio, uint256 _updateThreshold, bool _autoUpdate) external onlyAdmin {
        if (_rewardPool == address(0)) revert ZeroAddress();
        RewardPoolConfig storage cfg = rewardPoolConfig[_rewardPool];
        if (!cfg.initialized) {
            cfg.initialized = true;
            cfg.lastUpdateTime = block.timestamp;
        }
        if (_updateRatio > 36500) revert RatioTooHigh();
        if (_updateThreshold > 100) revert ThresholdTooHigh();
        cfg.updateInterval = _updateInterval;
        cfg.updateRatio = _updateRatio;
        cfg.updateThreshold = _updateThreshold;
        cfg.autoUpdate = _autoUpdate;
        emit RewardPoolUpdateSettingsUpdated(_rewardPool, _updateInterval, _updateRatio, _updateThreshold, _autoUpdate);
    }

    /**
     * @notice Manually set rewardPool base yearly budgets (affects both Standard & Liquidity pools using it)
     */
    function setRewardPoolEmissions(address _rewardPool, uint256 _vouchPerYear, uint256 _vplsPerYear, uint256 _wplsPerYear) external onlyAdmin {
    RewardPoolConfig storage cfg = rewardPoolConfig[_rewardPool];
    if (!cfg.initialized) revert ConfigNotInitialized();
        cfg.baseVouchPerYear = _vouchPerYear;
        cfg.baseVplsPerYear  = _vplsPerYear;
        cfg.baseWplsPerYear  = _wplsPerYear;
        emit RewardPoolRatesAutoUpdated(_rewardPool, _vouchPerYear, _vplsPerYear, _wplsPerYear);
    }

    /**
     * @notice Set the global VOUCH unlock period (0..14 days). Applies only to VOUCH staking pools.
     */
    function setStandardUnlockPeriod(uint256 _seconds) public onlyAdmin {
        if (_seconds > MAX_UNLOCK_PERIOD) revert UnlockPeriodTooLong();
        uint256 old = standardUnlockPeriod;
        standardUnlockPeriod = _seconds;
        emit UnlockPeriodUpdated(old, _seconds);
    }

    /**
     * @notice Manually trigger global holder rewards accumulator update for a VOUCH pool
     * @param _pid Pool id (must be VOUCH staking pool)
     */
    function distributeHolderRewardDividends(uint256 _pid) external onlyAdmin nonReentrant {
        PoolInfo storage pool = poolInfo[_pid];
        if (address(pool.stakingToken) != address(vouchToken)) return;

        uint256 totalVouchPrincipal = principalStakedToken[address(vouchToken)];
        if (totalVouchPrincipal == 0) return;

        (uint256 vouchAmount, uint256 vplsAmount, uint256 plsAmount) = _calculateHolderRewardDeltas();
        if (vouchAmount == 0 && vplsAmount == 0 && plsAmount == 0) return;

        if (vouchAmount > 0) {
            accVouchHolderRewardsPerShare = accVouchHolderRewardsPerShare + (vouchAmount * MULTIPLIER / totalVouchPrincipal);
            vouchToken.safeTransfer(address(holderRewardsVault), vouchAmount);
        }
        if (vplsAmount > 0) {
            accVplsHolderRewardsPerShare = accVplsHolderRewardsPerShare + (vplsAmount * MULTIPLIER / totalVouchPrincipal);
            vplsToken.safeTransfer(address(holderRewardsVault), vplsAmount);
        }
        if (plsAmount > 0) {
            accPlsHolderRewardsPerShare = accPlsHolderRewardsPerShare + (plsAmount * MULTIPLIER / totalVouchPrincipal);
            IERC20(address(wplsToken)).safeTransfer(address(holderRewardsVault), plsAmount);
        }
        if (vouchAmount > 0 || vplsAmount > 0 || plsAmount > 0) {
            emit HolderRewardDistributed(vouchAmount, vplsAmount, plsAmount);
        }
    }

    // --------------------------------------------------
    // View Functions
    // --------------------------------------------------

    /**
     * @dev Read-only version of holder reward delta detection. Unlike _calculateHolderRewardDeltas,
     *      this does not wrap native PLS into WPLS; instead, when a wrapper is configured it
     *      treats current WPLS balance plus native balance as the effective WPLS amount.
     */
    function _holderRewardDeltasView()
        internal
        view
        returns (uint256 vouchAmount, uint256 vplsAmount, uint256 plsAmount)
    {
        uint256 vBal = vouchToken.balanceOf(address(this));
        uint256 vBaseline = principalStakedToken[address(vouchToken)] + unlockingTokenTotals[address(vouchToken)];
        if (vBal > vBaseline) vouchAmount = vBal - vBaseline;

        uint256 vplsBal = vplsToken.balanceOf(address(this));
        uint256 vplsBaseline = principalStakedToken[address(vplsToken)] + unlockingTokenTotals[address(vplsToken)];
        if (vplsBal > vplsBaseline) vplsAmount = vplsBal - vplsBaseline;

        if (address(wplsToken) != address(0)) {
            uint256 wplsBal = wplsToken.balanceOf(address(this)) + address(this).balance;
            uint256 wplsBaseline = principalStakedToken[address(wplsToken)] + unlockingTokenTotals[address(wplsToken)];
            if (wplsBal > wplsBaseline) plsAmount = wplsBal - wplsBaseline;
        } else {
            plsAmount = address(this).balance;
        }
    }

    /**
     * @notice View pending global holder rewards (VOUCH, VPLS, PLS) for a user
     * @param _user User address
     */
    function pendingHolderRewards(address _user)
        public
        view
        returns (uint256 vouchPending, uint256 vplsPending, uint256 plsPending)
    {
        uint256 userVouch = userTotalVouchStaked[_user];
        if (userVouch == 0) {
            return (0, 0, 0);
        }
        HolderRewardInfo storage info = holderRewardInfo[_user];
        uint256 totalVouchPrincipal = principalStakedToken[address(vouchToken)];
        uint256 accV = accVouchHolderRewardsPerShare;
        uint256 accP = accVplsHolderRewardsPerShare;
        uint256 accW = accPlsHolderRewardsPerShare;
        if (totalVouchPrincipal > 0) {
            (uint256 dv, uint256 dp, uint256 dw) = _holderRewardDeltasView();
            if (dv > 0) { accV = accV + (dv * MULTIPLIER / totalVouchPrincipal); }
            if (dp > 0) { accP = accP + (dp * MULTIPLIER / totalVouchPrincipal); }
            if (dw > 0) { accW = accW + (dw * MULTIPLIER / totalVouchPrincipal); }
        }
        vouchPending = (accV - info.lastVouchAcc) * userVouch / MULTIPLIER;
        vplsPending = (accP - info.lastVplsAcc) * userVouch / MULTIPLIER;
        plsPending = (accW - info.lastPlsAcc) * userVouch / MULTIPLIER;
    }

    /**
     * @notice View pending standard pool triple-drip overlay (VOUCH, VPLS, WPLS)
     * @param _pid Pool id (must be Standard)
     * @param _user User address
     */
    function pendingStandardTriple(uint256 _pid, address _user)
        public
        view
        returns (uint256 vouchPending, uint256 vplsPending, uint256 wplsPending)
    {
        PoolInfo storage pool = poolInfo[_pid];
        if (pool.poolType != PoolType.Standard) return (0,0,0);
        UserInfo storage user = userInfo[_pid][_user];
        if (user.amount == 0) return (0,0,0);
        uint256 accV = pool.stdAccVouchPerShare;
        uint256 accP = pool.stdAccVplsPerShare;
        uint256 accW = pool.stdAccWplsPerShare;
        RewardPoolConfig storage cfg = rewardPoolConfig[pool.rewardsPool];
        if (pool.totalStaked > 0 && cfg.totalAllocPoint > 0) {
            uint256 timeDiff = block.timestamp - pool.stdLastCalcTime;
            if (timeDiff > 0) {
                uint256 shareBP = (pool.allocPoint * MULTIPLIER) / cfg.totalAllocPoint;
                uint256 vouchPerSec = cfg.baseVouchPerYear / SECONDS_PER_YEAR;
                uint256 vplsPerSec  = cfg.baseVplsPerYear  / SECONDS_PER_YEAR;
                uint256 wplsPerSec  = cfg.baseWplsPerYear  / SECONDS_PER_YEAR;
                if (vouchPerSec > 0) {
                    uint256 inc = (vouchPerSec * timeDiff * shareBP) / MULTIPLIER;
                    accV = accV + (inc * MULTIPLIER / pool.totalStaked);
                }
                if (vplsPerSec > 0) {
                    uint256 inc = (vplsPerSec * timeDiff * shareBP) / MULTIPLIER;
                    accP = accP + (inc * MULTIPLIER / pool.totalStaked);
                }
                if (wplsPerSec > 0) {
                    uint256 inc = (wplsPerSec * timeDiff * shareBP) / MULTIPLIER;
                    accW = accW + (inc * MULTIPLIER / pool.totalStaked);
                }
            }
        }
        vouchPending = (accV - user.stdLastAccVouchPerShare) * user.amount / MULTIPLIER;
        vplsPending  = (accP - user.stdLastAccVplsPerShare)  * user.amount / MULTIPLIER;
        wplsPending  = (accW - user.stdLastAccWplsPerShare)  * user.amount / MULTIPLIER;
    }


    /**
     * @notice View projected pending liquidity rewards at current block including elapsed time since last calc.
     * @dev Purely a view projection; does not mutate state. Uses current per-year emission settings.
     */
    function pendingLiquidityRewardsProjected(uint256 _pid, address _user)
        public
        view
        returns (uint256 vouchPending, uint256 vplsPending, uint256 wplsPending)
    {
        PoolInfo storage pool = poolInfo[_pid];
        if (pool.poolType != PoolType.Liquidity) return (0,0,0);
        UserInfo storage user = userInfo[_pid][_user];
        if (user.amount == 0) return (0,0,0);
        uint256 accV = pool.liqAccVouchPerShare;
        uint256 accP = pool.liqAccVplsPerShare;
        uint256 accW = pool.liqAccWplsPerShare;
        RewardPoolConfig storage cfg = rewardPoolConfig[pool.rewardsPool];
        if (pool.totalStaked > 0 && cfg.totalAllocPoint > 0) {
            uint256 timeDiff = block.timestamp - pool.liqLastCalcTime;
            if (timeDiff > 0) {
                uint256 shareBP = (pool.allocPoint * MULTIPLIER) / cfg.totalAllocPoint;
                uint256 vouchPerSec = cfg.baseVouchPerYear / SECONDS_PER_YEAR;
                uint256 vplsPerSec  = cfg.baseVplsPerYear  / SECONDS_PER_YEAR;
                uint256 wplsPerSec  = cfg.baseWplsPerYear  / SECONDS_PER_YEAR;
                if (vouchPerSec > 0) { uint256 inc = (vouchPerSec * timeDiff * shareBP) / MULTIPLIER; accV += (inc * MULTIPLIER / pool.totalStaked); }
                if (vplsPerSec > 0)  { uint256 inc = (vplsPerSec  * timeDiff * shareBP) / MULTIPLIER; accP += (inc * MULTIPLIER / pool.totalStaked); }
                if (wplsPerSec > 0)  { uint256 inc = (wplsPerSec  * timeDiff * shareBP) / MULTIPLIER; accW += (inc * MULTIPLIER / pool.totalStaked); }
            }
        }
        vouchPending = (accV - user.liqLastAccVouchPerShare) * user.amount / MULTIPLIER;
        vplsPending  = (accP - user.liqLastAccVplsPerShare) * user.amount / MULTIPLIER;
        wplsPending  = (accW - user.liqLastAccWplsPerShare)  * user.amount / MULTIPLIER;
    }

    /**
     * @notice View projected pending capital pool rewards at current block including elapsed time since last calc.
     * @dev Purely a view projection; does not mutate state. Uses user's shares from CapitalPool contract.
     */
    function pendingCapitalRewardsProjected(uint256 _pid, address _user)
        public
        view
        returns (uint256 vouchPending, uint256 vplsPending, uint256 wplsPending)
    {
        PoolInfo storage pool = poolInfo[_pid];
        if (pool.poolType != PoolType.Capital) return (0,0,0);
        
        // Get shares from the CapitalPool contract
        ICapitalPool capitalPool = ICapitalPool(address(pool.stakingToken));
        uint256 userShares = capitalPool.shares(_user);
        uint256 totalPoolShares = capitalPool.totalShares();
        
        if (userShares == 0) return (0,0,0);
        
        UserInfo storage user = userInfo[_pid][_user];
        uint256 accV = pool.liqAccVouchPerShare;
        uint256 accP = pool.liqAccVplsPerShare;
        uint256 accW = pool.liqAccWplsPerShare;
        RewardPoolConfig storage cfg = rewardPoolConfig[pool.rewardsPool];
        if (totalPoolShares > 0 && cfg.totalAllocPoint > 0) {
            uint256 timeDiff = block.timestamp - pool.liqLastCalcTime;
            if (timeDiff > 0) {
                uint256 shareBP = (pool.allocPoint * MULTIPLIER) / cfg.totalAllocPoint;
                uint256 vouchPerSec = cfg.baseVouchPerYear / SECONDS_PER_YEAR;
                uint256 vplsPerSec  = cfg.baseVplsPerYear  / SECONDS_PER_YEAR;
                uint256 wplsPerSec  = cfg.baseWplsPerYear  / SECONDS_PER_YEAR;
                if (vouchPerSec > 0) { uint256 inc = (vouchPerSec * timeDiff * shareBP) / MULTIPLIER; accV += (inc * MULTIPLIER / totalPoolShares); }
                if (vplsPerSec > 0)  { uint256 inc = (vplsPerSec  * timeDiff * shareBP) / MULTIPLIER; accP += (inc * MULTIPLIER / totalPoolShares); }
                if (wplsPerSec > 0)  { uint256 inc = (wplsPerSec  * timeDiff * shareBP) / MULTIPLIER; accW += (inc * MULTIPLIER / totalPoolShares); }
            }
        }
        vouchPending = (accV - user.liqLastAccVouchPerShare) * userShares / MULTIPLIER;
        vplsPending  = (accP - user.liqLastAccVplsPerShare) * userShares / MULTIPLIER;
        wplsPending  = (accW - user.liqLastAccWplsPerShare)  * userShares / MULTIPLIER;
    }

    /**
     * @notice Aggregate all pending rewards for a user across all pools and holder rewards.
     * @return standardVouchTotal Total pending standard VOUCH rewards across all standard pools
     * @return standardVplsTotal Total pending standard VPLS rewards across all standard pools
     * @return standardWplsTotal Total pending standard WPLS rewards across all standard pools
     * @return liqVouchTotal Total projected pending VOUCH from all LP and Capital pools
     * @return liqVplsTotal Total projected pending VPLS from all LP and Capital pools
     * @return liqWplsTotal Total projected pending WPLS from all LP and Capital pools
     * @return holderVouch Pending global VOUCH holder rewards
     * @return holderVpls Pending global VPLS holder rewards
     * @return holderPls Pending global PLS holder rewards (WPLS/native)
     */
    function pendingAllRewards(address _user)
        external
        view
        returns (
            uint256 standardVouchTotal,
            uint256 standardVplsTotal,
            uint256 standardWplsTotal,
            uint256 liqVouchTotal,
            uint256 liqVplsTotal,
            uint256 liqWplsTotal,
            uint256 holderVouch,
            uint256 holderVpls,
            uint256 holderPls
        )
    {
        for (uint256 pid = 1; pid <= totalPools; ++pid) {
            PoolInfo storage pool = poolInfo[pid];
            if (pool.poolType == PoolType.Liquidity) {
                UserInfo storage user = userInfo[pid][_user];
                if (user.amount == 0) continue;
                (uint256 pv, uint256 pp, uint256 pw) = pendingLiquidityRewardsProjected(pid, _user);
                liqVouchTotal += pv;
                liqVplsTotal  += pp;
                liqWplsTotal  += pw;
            } else if (pool.poolType == PoolType.Capital) {
                // For capital pools, check shares from the CapitalPool contract
                ICapitalPool capitalPool = ICapitalPool(address(pool.stakingToken));
                if (capitalPool.shares(_user) == 0) continue;
                (uint256 cv, uint256 cp, uint256 cw) = pendingCapitalRewardsProjected(pid, _user);
                liqVouchTotal += cv;
                liqVplsTotal  += cp;
                liqWplsTotal  += cw;
            } else {
                UserInfo storage user = userInfo[pid][_user];
                if (user.amount == 0) continue;
                (uint256 sv, uint256 sp, uint256 sw) = pendingStandardTriple(pid, _user);
                standardVouchTotal += sv;
                standardVplsTotal  += sp;
                standardWplsTotal  += sw;
            }
        }
        (holderVouch, holderVpls, holderPls) = pendingHolderRewards(_user);
    }

    /**
     * @notice Get detailed holder reward info for a user
     * @param _user User address
     */
    function getHolderRewardInfo(address _user)
        external
        view
        returns (
            uint256 vouchPending,
            uint256 vplsPending,
            uint256 plsPending,
            uint256 redeemedVouch,
            uint256 redeemedVpls,
            uint256 redeemedPls
        )
    {
        (vouchPending, vplsPending, plsPending) = pendingHolderRewards(_user);
        HolderRewardInfo storage info = holderRewardInfo[_user];
        redeemedVouch = info.redeemedVouch;
        redeemedVpls = info.redeemedVpls;
        redeemedPls = info.redeemedPls;
    }

    /**
     * @notice Get redeemed (claimed) drip totals for a user on a specific pool
     */
    function getDripRedeemed(uint256 _pid, address _user)
        external
        view
        returns (uint256 vouchClaimed, uint256 vplsClaimed, uint256 plsClaimed)
    {
        DripTotals storage t = dripRedeemed[_pid][_user];
        return (t.vouch, t.vpls, t.pls);
    }

    /**
     * @notice Get redeemed (claimed) drip totals for a user across all pools
     */
    function getDripRedeemedAll(address _user)
        external
        view
        returns (uint256 vouchClaimed, uint256 vplsClaimed, uint256 plsClaimed)
    {
        DripTotals storage t = dripRedeemedAll[_user];
        return (t.vouch, t.vpls, t.pls);
    }

    /**
     * @notice Get a user's total VOUCH principal staked across all pools
     * @param _user User address
     */
    function getUserTotalVouchStaked(address _user) external view returns (uint256) {
        return userTotalVouchStaked[_user];
    }

    // --------------------------------------------------
    // Internal Reward Logic
    // --------------------------------------------------

    /**
     * @dev Iterate pools and, for the first VOUCH staking pool found, distribute holder reward
     *      dividends so global accumulators are synchronized before user claims.
     */
    function _syncHolderRewardsAccumulators() internal {
        uint256 total = totalPools;
        for (uint256 pid = 1; pid <= total; ++pid) {
            PoolInfo storage pool = poolInfo[pid];
            if (address(pool.stakingToken) == address(vouchToken)) {
                _distributeHolderRewardDividends(pid);
                break;
            }
        }
    }

    /**
     * @dev Settle and transfer pending standard (drip) rewards for a user in a pool.
     */
    function _claimLiquidity(uint256 _pid, address _user) internal {
    PoolInfo storage pool = poolInfo[_pid];
    if (pool.poolType != PoolType.Liquidity) revert NotLiquidityPool();
        _calcAccLiquidityRewardsPerShare(_pid);
        UserInfo storage user = userInfo[_pid][_user];
        uint256 pv = (pool.liqAccVouchPerShare - user.liqLastAccVouchPerShare) * user.amount / MULTIPLIER;
        uint256 pp = (pool.liqAccVplsPerShare  - user.liqLastAccVplsPerShare) * user.amount / MULTIPLIER;
        uint256 pw = (pool.liqAccWplsPerShare  - user.liqLastAccWplsPerShare) * user.amount / MULTIPLIER;

        user.liqLastAccVouchPerShare = pool.liqAccVouchPerShare;
        user.liqLastAccVplsPerShare = pool.liqAccVplsPerShare;
        user.liqLastAccWplsPerShare = pool.liqAccWplsPerShare;

        if (pv == 0 && pp == 0 && pw == 0) {
            return;
        }

        {
            if (pv > 0 || pp > 0 || pw > 0) {
                DripTotals storage perPool = dripRedeemed[_pid][_user];
                DripTotals storage all = dripRedeemedAll[_user];
                if (pv > 0) { perPool.vouch = perPool.vouch + pv; all.vouch = all.vouch + pv; }
                if (pp > 0) { perPool.vpls  = perPool.vpls  + pp; all.vpls  = all.vpls  + pp; }
                if (pw > 0) { perPool.pls   = perPool.pls   + pw; all.pls   = all.pls   + pw; }
            }
            if (pv > 0) {
                ILPRewardPool(pool.rewardsPool).pullTokenTo(address(vouchToken), _user, pv);
            }
            if (pp > 0) {
                ILPRewardPool(pool.rewardsPool).pullTokenTo(address(vplsToken), _user, pp);
            }
            if (pw > 0 && address(wplsToken) != address(0)) {
                ILPRewardPool(pool.rewardsPool).pullTokenTo(address(wplsToken), address(this), pw);
                IWPLS(wplsToken).withdraw(pw);
                (bool ok, ) = payable(_user).call{value: pw}("");
                if (!ok) revert PlsTransferFailed();
            }
            emit LiquidityClaim(_user, _pid, pv, pp, pw);
        }
    }

    function _claimStandardTriple(uint256 _pid, address _user) internal {
    PoolInfo storage pool = poolInfo[_pid];
    if (pool.poolType != PoolType.Standard) revert NotStandardPool();
        _calcAccStandardTriple(_pid);
        UserInfo storage user = userInfo[_pid][_user];
        uint256 vouchAmt = (pool.stdAccVouchPerShare - user.stdLastAccVouchPerShare) * user.amount / MULTIPLIER;
        uint256 vplsAmt  = (pool.stdAccVplsPerShare  - user.stdLastAccVplsPerShare)  * user.amount / MULTIPLIER;
        uint256 wplsAmt  = (pool.stdAccWplsPerShare  - user.stdLastAccWplsPerShare)  * user.amount / MULTIPLIER;
        user.stdLastAccVouchPerShare = pool.stdAccVouchPerShare;
        user.stdLastAccVplsPerShare = pool.stdAccVplsPerShare;
        user.stdLastAccWplsPerShare = pool.stdAccWplsPerShare;
        if (vouchAmt == 0 && vplsAmt == 0 && wplsAmt == 0) return;
        if (vouchAmt > 0 || vplsAmt > 0 || wplsAmt > 0) {
            DripTotals storage perPool = dripRedeemed[_pid][_user];
            DripTotals storage all = dripRedeemedAll[_user];
            if (vouchAmt > 0) { perPool.vouch = perPool.vouch + vouchAmt; all.vouch = all.vouch + vouchAmt; }
            if (vplsAmt  > 0) { perPool.vpls  = perPool.vpls  + vplsAmt;  all.vpls  = all.vpls  + vplsAmt;  }
            if (wplsAmt  > 0) { perPool.pls   = perPool.pls   + wplsAmt;  all.pls   = all.pls   + wplsAmt;  }
        }
        if (vouchAmt > 0) {
            ILPRewardPool(pool.rewardsPool).pullTokenTo(address(vouchToken), _user, vouchAmt);
        }
        if (vplsAmt > 0) {
            ILPRewardPool(pool.rewardsPool).pullTokenTo(address(vplsToken), _user, vplsAmt);
        }
        if (wplsAmt > 0 && address(wplsToken) != address(0)) {
            ILPRewardPool(pool.rewardsPool).pullTokenTo(address(wplsToken), address(this), wplsAmt);
            IWPLS(wplsToken).withdraw(wplsAmt);
            (bool ok, ) = payable(_user).call{value: wplsAmt}("");
            if (!ok) revert PlsTransferFailed();
        }
        emit Claim(_user, _pid, vouchAmt, vplsAmt, wplsAmt);
    }

    /**
     * @dev Settle and transfer all pending holder rewards (VOUCH, VPLS, WPLS or native PLS).
     *      Uses `holderRewardsVault` as the source for ERC20 holder rewards and contract-held WPLS/native
     *      as a fallback for PLS if `holderRewardsVault` is short.
     */
    function _claimGlobalHolderRewards(address _user) internal {
        uint256 userVouch = userTotalVouchStaked[_user];
        HolderRewardInfo storage info = holderRewardInfo[_user];
        if (userVouch == 0) {
            info.lastVouchAcc = accVouchHolderRewardsPerShare;
            info.lastVplsAcc = accVplsHolderRewardsPerShare;
            info.lastPlsAcc = accPlsHolderRewardsPerShare;
            return;
        }
        (uint256 vouchAmt, uint256 vplsAmt, uint256 plsAmt) = pendingHolderRewards(_user);
        if (vouchAmt == 0 && vplsAmt == 0 && plsAmt == 0) {
            info.lastVouchAcc = accVouchHolderRewardsPerShare;
            info.lastVplsAcc = accVplsHolderRewardsPerShare;
            info.lastPlsAcc = accPlsHolderRewardsPerShare;
            return;
        }
        if (vouchAmt > 0) {
            if (address(holderRewardsVault).code.length > 0) {
                holderRewardsVault.pullTokenTo(address(vouchToken), _user, vouchAmt);
            } else {
                vouchToken.safeTransferFrom(address(holderRewardsVault), _user, vouchAmt);
            }
            info.redeemedVouch += vouchAmt;
        }
        if (vplsAmt > 0) {
            if (address(holderRewardsVault).code.length > 0) {
                holderRewardsVault.pullTokenTo(address(vplsToken), _user, vplsAmt);
            } else {
                vplsToken.safeTransferFrom(address(holderRewardsVault), _user, vplsAmt);
            }
            info.redeemedVpls += vplsAmt;
        }
        if (plsAmt > 0) {
            if (address(wplsToken) != address(0)) {
                if (address(holderRewardsVault).code.length > 0) {
                    holderRewardsVault.pullTokenTo(address(wplsToken), address(this), plsAmt);
                } else {
                    uint256 poolBal = IERC20(address(wplsToken)).balanceOf(address(holderRewardsVault));
                    if (poolBal >= plsAmt) {
                        IERC20(address(wplsToken)).safeTransferFrom(address(holderRewardsVault), address(this), plsAmt);
                    } else {
                        uint256 selfBal = IERC20(address(wplsToken)).balanceOf(address(this));
                        if (selfBal < plsAmt) revert WplsHolderRewardMissing();
                    }
                }
                IWPLS(wplsToken).withdraw(plsAmt);
                (bool ok, ) = payable(_user).call{value: plsAmt}("");
                if (!ok) revert PlsTransferFailed();
            } else {
                (bool ok, ) = payable(_user).call{value: plsAmt}("");
                if (!ok) revert PlsTransferFailed();
            }
            info.redeemedPls += plsAmt;
        }
        info.lastVouchAcc = accVouchHolderRewardsPerShare;
        info.lastVplsAcc = accVplsHolderRewardsPerShare;
        info.lastPlsAcc = accPlsHolderRewardsPerShare;
        emit HolderRewardClaimed(_user, vouchAmt, vplsAmt, plsAmt);
    }

    /**
     * @dev Internal hook: if the pool is a VOUCH staking pool, detect any holder reward deltas held by
     *      this contract and update global per-share holder reward accumulators. Also relocates reflected
     *      tokens to `holderRewardsVault` to isolate claim source of truth.
     */
    function _distributeHolderRewardDividends(uint256 _pid) internal {
        PoolInfo storage pool = poolInfo[_pid];
        if (address(pool.stakingToken) != address(vouchToken)) return;

        uint256 totalVouchPrincipal = principalStakedToken[address(vouchToken)];
        if (totalVouchPrincipal == 0) return;

        (uint256 vouchAmount, uint256 vplsAmount, uint256 plsAmount) = _calculateHolderRewardDeltas();
        if (vouchAmount == 0 && vplsAmount == 0 && plsAmount == 0) return;

        if (vouchAmount > 0) {
            accVouchHolderRewardsPerShare = accVouchHolderRewardsPerShare + (vouchAmount * MULTIPLIER / totalVouchPrincipal);
            vouchToken.safeTransfer(address(holderRewardsVault), vouchAmount);
        }
        if (vplsAmount > 0) {
            accVplsHolderRewardsPerShare = accVplsHolderRewardsPerShare + (vplsAmount * MULTIPLIER / totalVouchPrincipal);
            vplsToken.safeTransfer(address(holderRewardsVault), vplsAmount);
        }
        if (plsAmount > 0) {
            accPlsHolderRewardsPerShare = accPlsHolderRewardsPerShare + (plsAmount * MULTIPLIER / totalVouchPrincipal);
            IERC20(address(wplsToken)).safeTransfer(address(holderRewardsVault), plsAmount);
        }
        if (vouchAmount > 0 || vplsAmount > 0 || plsAmount > 0) {
            emit HolderRewardDistributed(vouchAmount, vplsAmount, plsAmount);
        }
    }

    /**
     * @dev Detect holder reward token deltas over principal. Wraps any native PLS into WPLS if wrapper is set.
     *      Not view: performs a state-changing deposit() on WPLS when native balance is present.
     */
    function _calculateHolderRewardDeltas()
        internal
        returns (uint256 vouchAmount, uint256 vplsAmount, uint256 plsAmount)
    {
        uint256 vBal = vouchToken.balanceOf(address(this));
        uint256 vPrincipal = principalStakedToken[address(vouchToken)];
        uint256 vUnlocking = unlockingTokenTotals[address(vouchToken)];
        uint256 vBaseline = vPrincipal + vUnlocking;
        if (vBal > vBaseline) vouchAmount = vBal - vBaseline;

        uint256 vplsBal = vplsToken.balanceOf(address(this));
        uint256 vplsPrincipal = principalStakedToken[address(vplsToken)];
        uint256 vplsUnlocking = unlockingTokenTotals[address(vplsToken)];
        uint256 vplsBaseline = vplsPrincipal + vplsUnlocking;
        if (vplsBal > vplsBaseline) vplsAmount = vplsBal - vplsBaseline;
        if (address(wplsToken) != address(0)) {
            if (address(this).balance > 0) {
                IWPLS(wplsToken).deposit{value: address(this).balance}();
            }
            uint256 wplsBal = wplsToken.balanceOf(address(this));
            uint256 wplsPrincipal = principalStakedToken[address(wplsToken)];
            uint256 wplsUnlocking = unlockingTokenTotals[address(wplsToken)];
            uint256 wplsBaseline = wplsPrincipal + wplsUnlocking;
            if (wplsBal > wplsBaseline) {
                plsAmount = wplsBal - wplsBaseline;
            }
        } else {
            plsAmount = address(this).balance;
        }
    }

    function _calcAccStandardTriple(uint256 _pid) internal {
        PoolInfo storage pool = poolInfo[_pid];
        if (pool.poolType != PoolType.Standard) return;
        RewardPoolConfig storage cfg = rewardPoolConfig[pool.rewardsPool];
        if (pool.totalStaked == 0 || cfg.totalAllocPoint == 0) {
            pool.stdLastCalcTime = block.timestamp;
            return;
        }
        uint256 timeDiff = getTimeDiff(pool.stdLastCalcTime, block.timestamp);
        if (timeDiff == 0) return;
        uint256 shareBP = (pool.allocPoint * MULTIPLIER) / cfg.totalAllocPoint;
        uint256 vouchPerSec = cfg.baseVouchPerYear / SECONDS_PER_YEAR;
        uint256 vplsPerSec  = cfg.baseVplsPerYear  / SECONDS_PER_YEAR;
        uint256 wplsPerSec  = cfg.baseWplsPerYear  / SECONDS_PER_YEAR;

        if (vouchPerSec > 0) {
            uint256 inc = (vouchPerSec * timeDiff * shareBP) / MULTIPLIER;
            pool.stdAccVouchPerShare = pool.stdAccVouchPerShare + (inc * MULTIPLIER / pool.totalStaked);
        }
        if (vplsPerSec > 0) {
            uint256 inc = (vplsPerSec * timeDiff * shareBP) / MULTIPLIER;
            pool.stdAccVplsPerShare = pool.stdAccVplsPerShare + (inc * MULTIPLIER / pool.totalStaked);
        }
        if (wplsPerSec > 0) {
            uint256 inc = (wplsPerSec * timeDiff * shareBP) / MULTIPLIER;
            pool.stdAccWplsPerShare = pool.stdAccWplsPerShare + (inc * MULTIPLIER / pool.totalStaked);
        }
        pool.stdLastCalcTime = block.timestamp;
    }

    /**
     * @notice Internal: update liquidity pool accumulators using rewardPool-level budgets
     */
    function _calcAccLiquidityRewardsPerShare(uint256 _pid) internal {
        PoolInfo storage pool = poolInfo[_pid];
        if (pool.poolType != PoolType.Liquidity) return;
        RewardPoolConfig storage cfg = rewardPoolConfig[pool.rewardsPool];
        if (pool.totalStaked == 0 || cfg.totalAllocPoint == 0) {
            pool.liqLastCalcTime = block.timestamp;
            return;
        }
        uint256 timeDiff = getTimeDiff(pool.liqLastCalcTime, block.timestamp);
        if (timeDiff == 0) return;
        uint256 shareBP = (pool.allocPoint * MULTIPLIER) / cfg.totalAllocPoint;
        uint256 vouchPerSec = cfg.baseVouchPerYear / SECONDS_PER_YEAR;
        uint256 vplsPerSec  = cfg.baseVplsPerYear  / SECONDS_PER_YEAR;
        uint256 wplsPerSec  = cfg.baseWplsPerYear  / SECONDS_PER_YEAR;
    if (vouchPerSec > 0) { uint256 inc = (vouchPerSec * timeDiff * shareBP) / MULTIPLIER; pool.liqAccVouchPerShare = pool.liqAccVouchPerShare + (inc * MULTIPLIER / pool.totalStaked); }
    if (vplsPerSec  > 0) { uint256 inc = (vplsPerSec  * timeDiff * shareBP) / MULTIPLIER; pool.liqAccVplsPerShare  = pool.liqAccVplsPerShare  + (inc * MULTIPLIER / pool.totalStaked); }
    if (wplsPerSec  > 0) { uint256 inc = (wplsPerSec  * timeDiff * shareBP) / MULTIPLIER; pool.liqAccWplsPerShare  = pool.liqAccWplsPerShare  + (inc * MULTIPLIER / pool.totalStaked); }
        pool.liqLastCalcTime = block.timestamp;
    }

    /**
     * @notice Internal: update capital pool accumulators using rewardPool-level budgets
     * @dev Capital pools use totalShares from the CapitalPool contract as the staking denominator
     */
    function _calcAccCapitalRewardsPerShare(uint256 _pid) internal {
        PoolInfo storage pool = poolInfo[_pid];
        if (pool.poolType != PoolType.Capital) return;
        RewardPoolConfig storage cfg = rewardPoolConfig[pool.rewardsPool];
        
        // Get total shares from the CapitalPool contract
        ICapitalPool capitalPool = ICapitalPool(address(pool.stakingToken));
        uint256 totalPoolShares = capitalPool.totalShares();
        
        if (totalPoolShares == 0 || cfg.totalAllocPoint == 0) {
            pool.liqLastCalcTime = block.timestamp;
            return;
        }
        uint256 timeDiff = getTimeDiff(pool.liqLastCalcTime, block.timestamp);
        if (timeDiff == 0) return;
        uint256 shareBP = (pool.allocPoint * MULTIPLIER) / cfg.totalAllocPoint;
        uint256 vouchPerSec = cfg.baseVouchPerYear / SECONDS_PER_YEAR;
        uint256 vplsPerSec  = cfg.baseVplsPerYear  / SECONDS_PER_YEAR;
        uint256 wplsPerSec  = cfg.baseWplsPerYear  / SECONDS_PER_YEAR;
        if (vouchPerSec > 0) { uint256 inc = (vouchPerSec * timeDiff * shareBP) / MULTIPLIER; pool.liqAccVouchPerShare = pool.liqAccVouchPerShare + (inc * MULTIPLIER / totalPoolShares); }
        if (vplsPerSec  > 0) { uint256 inc = (vplsPerSec  * timeDiff * shareBP) / MULTIPLIER; pool.liqAccVplsPerShare  = pool.liqAccVplsPerShare  + (inc * MULTIPLIER / totalPoolShares); }
        if (wplsPerSec  > 0) { uint256 inc = (wplsPerSec  * timeDiff * shareBP) / MULTIPLIER; pool.liqAccWplsPerShare  = pool.liqAccWplsPerShare  + (inc * MULTIPLIER / totalPoolShares); }
        pool.liqLastCalcTime = block.timestamp;
    }

    /**
     * @notice Internal: claim capital pool rewards for a user based on their shares
     */
    function _claimCapital(uint256 _pid, address _user) internal {
        PoolInfo storage pool = poolInfo[_pid];
        if (pool.poolType != PoolType.Capital) revert NotCapitalPool();
        
        // Get user shares from the CapitalPool contract
        ICapitalPool capitalPool = ICapitalPool(address(pool.stakingToken));
        
        // Trigger yield accrual on the capital pool before calculating rewards
        try capitalPool.accrueYield() {} catch {}
        
        uint256 userShares = capitalPool.shares(_user);
        
        UserInfo storage user = userInfo[_pid][_user];
        
        uint256 pv = (pool.liqAccVouchPerShare - user.liqLastAccVouchPerShare) * userShares / MULTIPLIER;
        uint256 pp = (pool.liqAccVplsPerShare  - user.liqLastAccVplsPerShare) * userShares / MULTIPLIER;
        uint256 pw = (pool.liqAccWplsPerShare  - user.liqLastAccWplsPerShare) * userShares / MULTIPLIER;

        user.liqLastAccVouchPerShare = pool.liqAccVouchPerShare;
        user.liqLastAccVplsPerShare = pool.liqAccVplsPerShare;
        user.liqLastAccWplsPerShare = pool.liqAccWplsPerShare;

        if (pv == 0 && pp == 0 && pw == 0) {
            return;
        }

        {
            if (pv > 0 || pp > 0 || pw > 0) {
                DripTotals storage perPool = dripRedeemed[_pid][_user];
                DripTotals storage all = dripRedeemedAll[_user];
                if (pv > 0) { perPool.vouch = perPool.vouch + pv; all.vouch = all.vouch + pv; }
                if (pp > 0) { perPool.vpls  = perPool.vpls  + pp; all.vpls  = all.vpls  + pp; }
                if (pw > 0) { perPool.pls   = perPool.pls   + pw; all.pls   = all.pls   + pw; }
            }
            if (pv > 0) {
                ILPRewardPool(pool.rewardsPool).pullTokenTo(address(vouchToken), _user, pv);
            }
            if (pp > 0) {
                ILPRewardPool(pool.rewardsPool).pullTokenTo(address(vplsToken), _user, pp);
            }
            if (pw > 0 && address(wplsToken) != address(0)) {
                ILPRewardPool(pool.rewardsPool).pullTokenTo(address(wplsToken), address(this), pw);
                IWPLS(wplsToken).withdraw(pw);
                (bool ok, ) = payable(_user).call{value: pw}("");
                if (!ok) revert PlsTransferFailed();
            }
            emit CapitalClaim(_user, _pid, pv, pp, pw);
        }
    }

    /**
     * @notice View rewardPool base budgets
     */
    function getRewardPoolRates(address _rewardPool) external view returns (uint256 vouchPerYear, uint256 vplsPerYear, uint256 wplsPerYear, uint256 totalAllocPoint_) {
        RewardPoolConfig storage cfg = rewardPoolConfig[_rewardPool];
        vouchPerYear = cfg.baseVouchPerYear;
        vplsPerYear  = cfg.baseVplsPerYear;
        wplsPerYear  = cfg.baseWplsPerYear;
        totalAllocPoint_ = cfg.totalAllocPoint;
    }

    function getPoolInfo(uint256 _pid) external view returns (
        PoolType poolType,
        address stakingToken,
        address rewardsPool,
        uint256 allocPoint,
        bool active,
        uint256 totalStaked,
        uint256 stdAccVouchPerShare,
        uint256 stdAccVplsPerShare,
        uint256 stdAccWplsPerShare,
        uint256 stdLastCalcTime,
        uint256 liqAccVouchPerShare,
        uint256 liqAccVplsPerShare,
        uint256 liqAccWplsPerShare,
        uint256 liqLastCalcTime
    ) {
        PoolInfo storage pool = poolInfo[_pid];
        poolType = pool.poolType;
        stakingToken = address(pool.stakingToken);
        rewardsPool = address(pool.rewardsPool);
        allocPoint = pool.allocPoint;
        active = pool.active;
        totalStaked = pool.totalStaked;
        stdAccVouchPerShare = pool.stdAccVouchPerShare;
        stdAccVplsPerShare = pool.stdAccVplsPerShare;
        stdAccWplsPerShare = pool.stdAccWplsPerShare;
        stdLastCalcTime = pool.stdLastCalcTime;
        liqAccVouchPerShare = pool.liqAccVouchPerShare;
        liqAccVplsPerShare = pool.liqAccVplsPerShare;
        liqAccWplsPerShare = pool.liqAccWplsPerShare;
        liqLastCalcTime = pool.liqLastCalcTime;
    }

    function forceUpdateRewardPool(address _rewardPool) external onlyAdmin {
        _updateRewardPoolBudgets(_rewardPool, true);
    }

    function _deviationAboveThreshold(uint256 current, uint256 proposed, uint256 thresholdPct) internal pure returns (bool) {
        if (current == proposed) return false;
        if (current == 0) {
            return proposed > 0;
        }
        uint256 threshold = current * thresholdPct / 100;
        if (thresholdPct > 0 && proposed > current) {
            if (proposed <= current + threshold) return false;
        } else if (thresholdPct > 0 && proposed < current) {
            if (proposed + threshold >= current) return false;
        }
        if (thresholdPct == 0) {
            return proposed > current + 1 || proposed + 1 < current;
        }
        return true;
    }

    function _maybeUpdateRewardPool(address _rewardsPool) internal {
        try StakingRewardPool(payable(_rewardsPool)).sync() {} catch {}
        
        RewardPoolConfig storage cfg = rewardPoolConfig[_rewardsPool];
        if (!cfg.initialized) return;
        if (!cfg.autoUpdate) return;
        if (cfg.lastUpdateTime + cfg.updateInterval > block.timestamp) return;
        _updateRewardPoolBudgets(_rewardsPool, false);
    }

    function _updateRewardPoolBudgets(address _rewardsPool, bool force) internal {
        RewardPoolConfig storage cfg = rewardPoolConfig[_rewardsPool];
        if (!cfg.initialized) return;
        cfg.lastUpdateTime = block.timestamp;
        uint256 vBal = IERC20(address(vouchToken)).balanceOf(_rewardsPool);
        uint256 pBal = IERC20(address(vplsToken)).balanceOf(_rewardsPool);
        uint256 wBal = address(wplsToken) != address(0) ? IERC20(address(wplsToken)).balanceOf(_rewardsPool) : 0;
        uint256 proposedV = vBal * cfg.updateRatio / 100;
        uint256 proposedP = pBal * cfg.updateRatio / 100;
        uint256 proposedW = wBal * cfg.updateRatio / 100;
        bool changed;
        if (force || _deviationAboveThreshold(cfg.baseVouchPerYear, proposedV, cfg.updateThreshold)) { cfg.baseVouchPerYear = proposedV; changed = true; }
        if (force || _deviationAboveThreshold(cfg.baseVplsPerYear, proposedP, cfg.updateThreshold)) { cfg.baseVplsPerYear = proposedP; changed = true; }
        if (force || _deviationAboveThreshold(cfg.baseWplsPerYear, proposedW, cfg.updateThreshold)) { cfg.baseWplsPerYear = proposedW; changed = true; }
        if (changed) {
            emit RewardPoolRatesAutoUpdated(_rewardsPool, cfg.baseVouchPerYear, cfg.baseVplsPerYear, cfg.baseWplsPerYear);
        }
    }

    function getTimeDiff(uint256 _from, uint256 _to) internal pure returns (uint256) {
        return _to - _from;
    }

    receive() external payable {}
}
        

@openzeppelin/contracts/utils/Errors.sol

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

pragma solidity ^0.8.20;

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

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

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

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

@openzeppelin/contracts/interfaces/IERC1363.sol

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

@openzeppelin/contracts/interfaces/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";
          

@openzeppelin/contracts/interfaces/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";
          

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

@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol

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

@openzeppelin/contracts/utils/Address.sol

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

pragma solidity ^0.8.20;

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

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

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

        (bool success, bytes memory returndata) = recipient.call{value: amount}("");
        if (!success) {
            _revert(returndata);
        }
    }

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

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

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

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

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

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

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

@openzeppelin/contracts/utils/Arrays.sol

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

pragma solidity ^0.8.20;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        return low;
    }

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

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

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

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

        return low;
    }

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

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

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

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

        return low;
    }

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

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

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

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

        return low;
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@openzeppelin/contracts/utils/Comparators.sol

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

pragma solidity ^0.8.20;

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

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

@openzeppelin/contracts/utils/Panic.sol

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

pragma solidity ^0.8.20;

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

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

@openzeppelin/contracts/utils/ReentrancyGuard.sol

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

@openzeppelin/contracts/utils/SlotDerivation.sol

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

pragma solidity ^0.8.20;

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

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

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

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

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

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

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

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

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

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

@openzeppelin/contracts/utils/StorageSlot.sol

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

pragma solidity ^0.8.20;

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

    struct BooleanSlot {
        bool value;
    }

    struct Bytes32Slot {
        bytes32 value;
    }

    struct Uint256Slot {
        uint256 value;
    }

    struct Int256Slot {
        int256 value;
    }

    struct StringSlot {
        string value;
    }

    struct BytesSlot {
        bytes value;
    }

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

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

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

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

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

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

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

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

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

@openzeppelin/contracts/utils/introspection/IERC165.sol

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

@openzeppelin/contracts/utils/math/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;
    }
}
          

@openzeppelin/contracts/utils/math/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))
        }
    }
}
          

@openzeppelin/contracts/utils/structs/EnumerableSet.sol

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

pragma solidity ^0.8.20;

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

/**
 * @dev Library for managing
 * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
 * types.
 *
 * Sets have the following properties:
 *
 * - Elements are added, removed, and checked for existence in constant time
 * (O(1)).
 * - Elements are enumerated in O(n). No guarantees are made on the ordering.
 * - Set can be cleared (all elements removed) in O(n).
 *
 * ```solidity
 * contract Example {
 *     // Add the library methods
 *     using EnumerableSet for EnumerableSet.AddressSet;
 *
 *     // Declare a set state variable
 *     EnumerableSet.AddressSet private mySet;
 * }
 * ```
 *
 * The following types are supported:
 *
 * - `bytes32` (`Bytes32Set`) since v3.3.0
 * - `address` (`AddressSet`) since v3.3.0
 * - `uint256` (`UintSet`) since v3.3.0
 * - `string` (`StringSet`) since v5.4.0
 * - `bytes` (`BytesSet`) since v5.4.0
 *
 * [WARNING]
 * ====
 * Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
 * unusable.
 * See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
 *
 * In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an
 * array of EnumerableSet.
 * ====
 */
library EnumerableSet {
    // To implement this library for multiple types with as little code
    // repetition as possible, we write it in terms of a generic Set type with
    // bytes32 values.
    // The Set implementation uses private functions, and user-facing
    // implementations (such as AddressSet) are just wrappers around the
    // underlying Set.
    // This means that we can only create new EnumerableSets for types that fit
    // in bytes32.

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

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function _add(Set storage set, bytes32 value) private returns (bool) {
        if (!_contains(set, value)) {
            set._values.push(value);
            // The value is stored at length-1, but we add 1 to all indexes
            // and use 0 as a sentinel value
            set._positions[value] = set._values.length;
            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function _remove(Set storage set, bytes32 value) private returns (bool) {
        // We cache the value's position to prevent multiple reads from the same storage slot
        uint256 position = set._positions[value];

        if (position != 0) {
            // Equivalent to contains(set, value)
            // To delete an element from the _values array in O(1), we swap the element to delete with the last one in
            // the array, and then remove the last element (sometimes called as 'swap and pop').
            // This modifies the order of the array, as noted in {at}.

            uint256 valueIndex = position - 1;
            uint256 lastIndex = set._values.length - 1;

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

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

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

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

            return true;
        } else {
            return false;
        }
    }

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

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function _contains(Set storage set, bytes32 value) private view returns (bool) {
        return set._positions[value] != 0;
    }

    /**
     * @dev Returns the number of values on the set. O(1).
     */
    function _length(Set storage set) private view returns (uint256) {
        return set._values.length;
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function _at(Set storage set, uint256 index) private view returns (bytes32) {
        return set._values[index];
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function _values(Set storage set) private view returns (bytes32[] memory) {
        return set._values;
    }

    /**
     * @dev Return a slice of the set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function _values(Set storage set, uint256 start, uint256 end) private view returns (bytes32[] memory) {
        unchecked {
            end = Math.min(end, _length(set));
            start = Math.min(start, end);

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

    // Bytes32Set

    struct Bytes32Set {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _add(set._inner, value);
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _remove(set._inner, value);
    }

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

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
        return _contains(set._inner, value);
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(Bytes32Set storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
        return _at(set._inner, index);
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
        bytes32[] memory store = _values(set._inner);
        bytes32[] memory result;

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

        return result;
    }

    /**
     * @dev Return a slice of the set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(Bytes32Set storage set, uint256 start, uint256 end) internal view returns (bytes32[] memory) {
        bytes32[] memory store = _values(set._inner, start, end);
        bytes32[] memory result;

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

        return result;
    }

    // AddressSet

    struct AddressSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(AddressSet storage set, address value) internal returns (bool) {
        return _add(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(AddressSet storage set, address value) internal returns (bool) {
        return _remove(set._inner, bytes32(uint256(uint160(value))));
    }

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

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(AddressSet storage set, address value) internal view returns (bool) {
        return _contains(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(AddressSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(AddressSet storage set, uint256 index) internal view returns (address) {
        return address(uint160(uint256(_at(set._inner, index))));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(AddressSet storage set) internal view returns (address[] memory) {
        bytes32[] memory store = _values(set._inner);
        address[] memory result;

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

        return result;
    }

    /**
     * @dev Return a slice of the set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(AddressSet storage set, uint256 start, uint256 end) internal view returns (address[] memory) {
        bytes32[] memory store = _values(set._inner, start, end);
        address[] memory result;

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

        return result;
    }

    // UintSet

    struct UintSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(UintSet storage set, uint256 value) internal returns (bool) {
        return _add(set._inner, bytes32(value));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(UintSet storage set, uint256 value) internal returns (bool) {
        return _remove(set._inner, bytes32(value));
    }

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

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(UintSet storage set, uint256 value) internal view returns (bool) {
        return _contains(set._inner, bytes32(value));
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(UintSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(UintSet storage set, uint256 index) internal view returns (uint256) {
        return uint256(_at(set._inner, index));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(UintSet storage set) internal view returns (uint256[] memory) {
        bytes32[] memory store = _values(set._inner);
        uint256[] memory result;

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

        return result;
    }

    /**
     * @dev Return a slice of the set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(UintSet storage set, uint256 start, uint256 end) internal view returns (uint256[] memory) {
        bytes32[] memory store = _values(set._inner, start, end);
        uint256[] memory result;

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

        return result;
    }

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

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(StringSet storage set, string memory value) internal returns (bool) {
        if (!contains(set, value)) {
            set._values.push(value);
            // The value is stored at length-1, but we add 1 to all indexes
            // and use 0 as a sentinel value
            set._positions[value] = set._values.length;
            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(StringSet storage set, string memory value) internal returns (bool) {
        // We cache the value's position to prevent multiple reads from the same storage slot
        uint256 position = set._positions[value];

        if (position != 0) {
            // Equivalent to contains(set, value)
            // To delete an element from the _values array in O(1), we swap the element to delete with the last one in
            // the array, and then remove the last element (sometimes called as 'swap and pop').
            // This modifies the order of the array, as noted in {at}.

            uint256 valueIndex = position - 1;
            uint256 lastIndex = set._values.length - 1;

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

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

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

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

            return true;
        } else {
            return false;
        }
    }

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

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

    /**
     * @dev Returns the number of values on the set. O(1).
     */
    function length(StringSet storage set) internal view returns (uint256) {
        return set._values.length;
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(StringSet storage set, uint256 index) internal view returns (string memory) {
        return set._values[index];
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(StringSet storage set) internal view returns (string[] memory) {
        return set._values;
    }

    /**
     * @dev Return a slice of the set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(StringSet storage set, uint256 start, uint256 end) internal view returns (string[] memory) {
        unchecked {
            end = Math.min(end, length(set));
            start = Math.min(start, end);

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

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

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(BytesSet storage set, bytes memory value) internal returns (bool) {
        if (!contains(set, value)) {
            set._values.push(value);
            // The value is stored at length-1, but we add 1 to all indexes
            // and use 0 as a sentinel value
            set._positions[value] = set._values.length;
            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(BytesSet storage set, bytes memory value) internal returns (bool) {
        // We cache the value's position to prevent multiple reads from the same storage slot
        uint256 position = set._positions[value];

        if (position != 0) {
            // Equivalent to contains(set, value)
            // To delete an element from the _values array in O(1), we swap the element to delete with the last one in
            // the array, and then remove the last element (sometimes called as 'swap and pop').
            // This modifies the order of the array, as noted in {at}.

            uint256 valueIndex = position - 1;
            uint256 lastIndex = set._values.length - 1;

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

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

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

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

            return true;
        } else {
            return false;
        }
    }

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

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

    /**
     * @dev Returns the number of values on the set. O(1).
     */
    function length(BytesSet storage set) internal view returns (uint256) {
        return set._values.length;
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(BytesSet storage set, uint256 index) internal view returns (bytes memory) {
        return set._values[index];
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(BytesSet storage set) internal view returns (bytes[] memory) {
        return set._values;
    }

    /**
     * @dev Return a slice of the set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(BytesSet storage set, uint256 start, uint256 end) internal view returns (bytes[] memory) {
        unchecked {
            end = Math.min(end, length(set));
            start = Math.min(start, end);

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

contracts/HolderRewardsVault.sol

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

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

interface INetworkProposal {
    function isAdmin(address adminAddress) external view returns (bool);
    function admin() external view returns (address);
    function getVoters() external view returns (address[] memory);
}

interface IWPLS {
    function deposit() external payable;
}

/**
 * @title HolderRewardVault
 * @notice Simple vault to isolate holder reward tokens away from staking principal.
 */
contract HolderRewardsVault {
    using SafeERC20 for IERC20;

    address public controller;
    IWPLS public wplsToken = IWPLS(0xA1077a294dDE1B09bB078844df40758a5D0f9a27);
    address public vouchToken = 0xD34f5ADC24d8Cc55C1e832Bdf65fFfDF80D1314f;
    address public vplsToken = 0x79BB3A0Ee435f957ce4f54eE8c3CFADc7278da0C;
    INetworkProposal networkProposal = INetworkProposal(0x7783D7040423f75aeF82a3Ec32ed366ca460Fa6c);

    error NotAdmin();
    error NotController();
    error InvalidAddress();
    error UnsupportedToken(address token);

    modifier onlyAdmin() {
        if (!networkProposal.isAdmin(msg.sender)) revert NotAdmin();
        _;
    }

    modifier onlyController() {
        if (msg.sender != controller) revert NotController();
        _;
    }

    constructor(address _controller) {
        if (_controller == address(0)) revert InvalidAddress();
        controller = _controller;
    }

    event TokenPulled(address indexed token, address indexed to, uint256 amount);
    event NativeWrapped(uint256 amount);
    event NativeReceived(address indexed from, uint256 amount);

    function pullTokenTo(address token, address to, uint256 amount) external onlyController {
        _wrapIfNeeded();
        IERC20(token).safeTransfer(to, amount);
        emit TokenPulled(token, to, amount);
    }

    function recoverFunds(address token, address to, uint256 amount) external onlyAdmin {
        if (token == address(vouchToken) || token == address(vplsToken) || token == address(wplsToken)) {
            revert UnsupportedToken(token);
        }
        IERC20(token).safeTransfer(to, amount);
    }

    function wrapIfNeeded() external {
        _wrapIfNeeded();
    }

    function _wrapIfNeeded() internal {
        if (address(wplsToken) != address(0) && address(this).balance > 0) {
            uint256 amt = address(this).balance;
            wplsToken.deposit{value: amt}();
            emit NativeWrapped(amt);
        }
    }

    receive() external payable {
        emit NativeReceived(msg.sender, msg.value);
    }
}
          

contracts/LPRewardPool.sol

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

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

interface IWPLS {
    function deposit() external payable;
}

interface INetworkProposal {
    function isAdmin(address adminAddress) external view returns (bool);
    function admin() external view returns (address);
    function getVoters() external view returns (address[] memory);
}

/**
 * @title LPRewardPool
 * @notice Holds tokens dedicated to liquidity pool emissions (secondary source). A designated controller
 *         (the staking contract) instructs transfers to users on claim.
 */
contract LPRewardPool {
    using SafeERC20 for IERC20;

    address public controller;
    IWPLS public wplsToken = IWPLS(0xA1077a294dDE1B09bB078844df40758a5D0f9a27);
    address public vouchToken = 0xD34f5ADC24d8Cc55C1e832Bdf65fFfDF80D1314f;
    address public vplsToken = 0x79BB3A0Ee435f957ce4f54eE8c3CFADc7278da0C;
    INetworkProposal networkProposal = INetworkProposal(0x7783D7040423f75aeF82a3Ec32ed366ca460Fa6c);

    error NotAdmin();
    error NotController();
    error InvalidAddress();
    error UnsupportedToken(address token);

    modifier onlyAdmin() {
        if (!networkProposal.isAdmin(msg.sender)) revert NotAdmin();
        _;
    }

    modifier onlyController() {
        if (msg.sender != controller) revert NotController();
        _;
    }

    constructor(address _controller) {
        if (_controller == address(0)) revert InvalidAddress();
        controller = _controller;
    }

    event TokenPulled(address indexed token, address indexed to, uint256 amount);
    event NativeWrapped(uint256 amount);
    event NativeReceived(address indexed from, uint256 amount);

    function pullTokenTo(address token, address to, uint256 amount) external onlyController {
        _wrapIfNeeded();
        IERC20(token).safeTransfer(to, amount);
        emit TokenPulled(token, to, amount);
    }

    function recoverFunds(address token, address to, uint256 amount) external onlyAdmin {
        if (token == address(vouchToken) || token == address(vplsToken) || token == address(wplsToken)) {
            revert UnsupportedToken(token);
        }
        IERC20(token).safeTransfer(to, amount);
    }

    function sync() external {
        _wrapIfNeeded();
    }

    function _wrapIfNeeded() internal {
        if (address(wplsToken) != address(0) && address(this).balance > 0) {
            uint256 amt = address(this).balance;
            wplsToken.deposit{value: amt}();
            emit NativeWrapped(amt);
        }
    }

    receive() external payable {
        emit NativeReceived(msg.sender, msg.value);
    }
}
          

contracts/StakingRewardPool.sol

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

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/utils/Address.sol";

interface IWPLS {
    function deposit() external payable;
    function balanceOf(address) external view returns (uint256);
    function transfer(address to, uint256 value) external returns (bool);
}

interface INetworkProposal {
    function isAdmin(address adminAddress) external view returns (bool);
    function admin() external view returns (address);
    function getVoters() external view returns (address[] memory);
}

// This contract just receives and holds Vouch/vPLS/PLS Rewards that are dripped to stakers.
/**
 * @title StakingRewardPool
 * @notice Holds VOUCH/VPLS/WPLS for standard pools. Maintains internal reward balances per token.
 *         Only the designated controller (staking contract) can pull via pullTokenTo. When new
 *         funds arrive (balance > rewardBalance), on sync the contract credits the delta to the
 *         rewardBalance and forwards a percentage to the LPRewardPool.
 */
contract StakingRewardPool {
    using Address for address;
    using SafeERC20 for IERC20;

    IERC20 public vouchToken;
    IERC20 public vplsToken;
    IWPLS public wplsToken;
    address public vouchStaking; // controller
    address public lpRewardPool;
    uint256 public forwardPct;
    INetworkProposal networkProposal = INetworkProposal(0x7783D7040423f75aeF82a3Ec32ed366ca460Fa6c);

    uint256 public vouchRewardBalance;
    uint256 public vplsRewardBalance;
    uint256 public wplsRewardBalance;

    error UnsupportedToken(address token);
    error NotAdmin();
    error NotController();
    error InvalidAddress();
    error PctGreaterThan100();
    error InsufficientReward(address token, uint256 have, uint256 need);

    event LpRewardPoolUpdated(address indexed lpRewardPool);
    event ForwardPctUpdated(uint256 pct);
    event TokenPulled(address indexed token, address indexed to, uint256 amount);
    event NativeWrapped(uint256 amount);
    event NativeReceived(address indexed from, uint256 amount);
    event ForwardedToLp(address indexed token, address indexed lpPool, uint256 amount);

    modifier onlyAdmin() {
        if (!networkProposal.isAdmin(msg.sender)) revert NotAdmin();
        _;
    }

    modifier onlyController() {
        if (msg.sender != vouchStaking) revert NotController();
        _;
    }

    constructor(address _vouchToken, address _vplsToken, address _wplsToken, address _staking) {
        if (_staking == address(0)) revert InvalidAddress();
        if (_vouchToken == address(0)) revert InvalidAddress();
        if (_vplsToken == address(0)) revert InvalidAddress();
        if (_wplsToken == address(0)) revert InvalidAddress();
        vouchToken = IERC20(_vouchToken);
        vplsToken = IERC20(_vplsToken);
        wplsToken = IWPLS(_wplsToken);
        vouchStaking = _staking;
    }

    receive() external payable {
        emit NativeReceived(msg.sender, msg.value);
    }

    function setLpRewardPool(address _lpPool) external onlyAdmin {
        lpRewardPool = _lpPool;
        emit LpRewardPoolUpdated(_lpPool);
    }

    function setForwardPct(uint256 _pct) external onlyAdmin {
        if (_pct > 100) revert PctGreaterThan100();
        forwardPct = _pct;
        emit ForwardPctUpdated(_pct);
    }

    function recoverFunds(address token, address to, uint256 amount) external onlyAdmin {
        if (token == address(vouchToken) || token == address(vplsToken) || token == address(wplsToken)) {
            revert UnsupportedToken(token);
        }
        IERC20(token).safeTransfer(to, amount);
    }

    function sync() public { _sync(); }

    function pullTokenTo(address token, address to, uint256 amount) external onlyController {
        _sync();
        if (token == address(vouchToken)) {
            if (vouchRewardBalance < amount) revert InsufficientReward(token, vouchRewardBalance, amount);
            vouchRewardBalance = vouchRewardBalance - amount;
            vouchToken.safeTransfer(to, amount);
        } else if (token == address(vplsToken)) {
            if (vplsRewardBalance < amount) revert InsufficientReward(token, vplsRewardBalance, amount);
            vplsRewardBalance = vplsRewardBalance - amount;
            vplsToken.safeTransfer(to, amount);
        } else if (token == address(wplsToken)) {
            if (wplsRewardBalance < amount) revert InsufficientReward(token, wplsRewardBalance, amount);
            wplsRewardBalance = wplsRewardBalance - amount;
            IERC20(address(wplsToken)).safeTransfer(to, amount);
        } else {
            revert UnsupportedToken(token);
        }
        emit TokenPulled(token, to, amount);
    }

    function _sync() internal {
        if (address(this).balance > 0) {
            uint256 amt = address(this).balance;
            wplsToken.deposit{value: amt}();
            emit NativeWrapped(amt);
        }
        _syncOne(address(vouchToken));
        _syncOne(address(vplsToken));
        _syncOne(address(wplsToken));
    }

    function _syncOne(address tokenAddr) internal {
        uint256 cur;
        if (tokenAddr == address(vouchToken)) {
            cur = vouchToken.balanceOf(address(this));
        } else if (tokenAddr == address(vplsToken)) {
            cur = vplsToken.balanceOf(address(this));
        } else if (tokenAddr == address(wplsToken)) {
            cur = wplsToken.balanceOf(address(this));
        } else {
            return;
        }
        uint256 rewardBal = tokenAddr == address(vouchToken)
            ? vouchRewardBalance
            : tokenAddr == address(vplsToken)
                ? vplsRewardBalance
                : wplsRewardBalance;
        if (cur > rewardBal) {
            uint256 delta = cur - rewardBal;
            uint256 f = lpRewardPool != address(0) && forwardPct > 0 ? delta * forwardPct / 100 : 0;
            if (f > 0) {
                if (tokenAddr == address(vouchToken)) vouchToken.safeTransfer(lpRewardPool, f);
                else if (tokenAddr == address(vplsToken)) vplsToken.safeTransfer(lpRewardPool, f);
                else if (tokenAddr == address(wplsToken)) IERC20(address(wplsToken)).safeTransfer(lpRewardPool, f);
                emit ForwardedToLp(tokenAddr, lpRewardPool, f);
            }
            uint256 credit = delta - f;
            if (tokenAddr == address(vouchToken)) vouchRewardBalance += credit;
            else if (tokenAddr == address(vplsToken)) vplsRewardBalance += credit;
            else if (tokenAddr == address(wplsToken)) wplsRewardBalance += credit;
        }
    }
}
          

Compiler Settings

{"viaIR":true,"outputSelection":{"*":{"*":["*"],"":["*"]}},"optimizer":{"runs":10,"enabled":true},"libraries":{},"evmVersion":"paris"}
              

Contract ABI

[{"type":"constructor","stateMutability":"nonpayable","inputs":[{"type":"uint256","name":"_startTime","internalType":"uint256"},{"type":"address","name":"_vouchToken","internalType":"address"},{"type":"address","name":"_vplsToken","internalType":"address"},{"type":"address","name":"_wplsToken","internalType":"address"}]},{"type":"error","name":"AmountZero","inputs":[]},{"type":"error","name":"CapitalPoolDirectStakeNotAllowed","inputs":[]},{"type":"error","name":"ConfigNotInitialized","inputs":[]},{"type":"error","name":"InsufficientStaked","inputs":[]},{"type":"error","name":"InvalidAddress","inputs":[]},{"type":"error","name":"InvalidPoolId","inputs":[]},{"type":"error","name":"NoActiveUnlock","inputs":[]},{"type":"error","name":"NotAdmin","inputs":[]},{"type":"error","name":"NotCapitalPool","inputs":[]},{"type":"error","name":"NotContract","inputs":[{"type":"address","name":"a","internalType":"address"}]},{"type":"error","name":"NotLiquidityPool","inputs":[]},{"type":"error","name":"NotReady","inputs":[]},{"type":"error","name":"NotStandardPool","inputs":[]},{"type":"error","name":"NothingStaked","inputs":[]},{"type":"error","name":"PlsTransferFailed","inputs":[]},{"type":"error","name":"PoolNotActive","inputs":[]},{"type":"error","name":"RatioTooHigh","inputs":[]},{"type":"error","name":"ReentrancyGuardReentrantCall","inputs":[]},{"type":"error","name":"RewardPoolSyncFailed","inputs":[]},{"type":"error","name":"SafeERC20FailedOperation","inputs":[{"type":"address","name":"token","internalType":"address"}]},{"type":"error","name":"StandardPoolUnlockOnly","inputs":[]},{"type":"error","name":"ThresholdTooHigh","inputs":[]},{"type":"error","name":"UnlockActive","inputs":[]},{"type":"error","name":"UnlockPeriodTooLong","inputs":[]},{"type":"error","name":"VouchNotAllowedInLiquidity","inputs":[]},{"type":"error","name":"WplsHolderRewardMissing","inputs":[]},{"type":"error","name":"ZeroAddress","inputs":[]},{"type":"event","name":"AutoUpdateSettingsUpdated","inputs":[{"type":"address","name":"rewardsPool","internalType":"address","indexed":true},{"type":"uint256","name":"updateInterval","internalType":"uint256","indexed":false},{"type":"uint256","name":"updateRatio","internalType":"uint256","indexed":false},{"type":"uint256","name":"updateThreshold","internalType":"uint256","indexed":false},{"type":"bool","name":"autoUpdate","internalType":"bool","indexed":false}],"anonymous":false},{"type":"event","name":"CapitalClaim","inputs":[{"type":"address","name":"user","internalType":"address","indexed":true},{"type":"uint256","name":"pid","internalType":"uint256","indexed":true},{"type":"uint256","name":"vouchAmount","internalType":"uint256","indexed":false},{"type":"uint256","name":"vplsAmount","internalType":"uint256","indexed":false},{"type":"uint256","name":"wplsAmount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"CapitalPoolInitialized","inputs":[{"type":"uint256","name":"pid","internalType":"uint256","indexed":true},{"type":"address","name":"capitalPool","internalType":"address","indexed":true},{"type":"uint256","name":"allocPoint","internalType":"uint256","indexed":false},{"type":"bool","name":"active","internalType":"bool","indexed":false}],"anonymous":false},{"type":"event","name":"Claim","inputs":[{"type":"address","name":"user","internalType":"address","indexed":true},{"type":"uint256","name":"pid","internalType":"uint256","indexed":true},{"type":"uint256","name":"vouchAmount","internalType":"uint256","indexed":false},{"type":"uint256","name":"vplsAmount","internalType":"uint256","indexed":false},{"type":"uint256","name":"wplsAmount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"HolderRewardClaimed","inputs":[{"type":"address","name":"user","internalType":"address","indexed":true},{"type":"uint256","name":"vouchAmount","internalType":"uint256","indexed":false},{"type":"uint256","name":"vplsAmount","internalType":"uint256","indexed":false},{"type":"uint256","name":"plsAmount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"HolderRewardDistributed","inputs":[{"type":"uint256","name":"vouchAmount","internalType":"uint256","indexed":false},{"type":"uint256","name":"vplsAmount","internalType":"uint256","indexed":false},{"type":"uint256","name":"plsAmount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"LiquidityClaim","inputs":[{"type":"address","name":"user","internalType":"address","indexed":true},{"type":"uint256","name":"pid","internalType":"uint256","indexed":true},{"type":"uint256","name":"vouchAmount","internalType":"uint256","indexed":false},{"type":"uint256","name":"vplsAmount","internalType":"uint256","indexed":false},{"type":"uint256","name":"wplsAmount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"LiquidityPoolInitialized","inputs":[{"type":"uint256","name":"pid","internalType":"uint256","indexed":true},{"type":"address","name":"stakingToken","internalType":"address","indexed":true},{"type":"uint256","name":"allocPoint","internalType":"uint256","indexed":false},{"type":"bool","name":"active","internalType":"bool","indexed":false}],"anonymous":false},{"type":"event","name":"LpRewardPoolUpdated","inputs":[{"type":"address","name":"lpRewardPool","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"PoolInitialized","inputs":[{"type":"uint256","name":"pid","internalType":"uint256","indexed":true},{"type":"address","name":"stakingToken","internalType":"address","indexed":true},{"type":"uint256","name":"allocPoint","internalType":"uint256","indexed":false},{"type":"bool","name":"active","internalType":"bool","indexed":false}],"anonymous":false},{"type":"event","name":"PoolUpdated","inputs":[{"type":"uint256","name":"pid","internalType":"uint256","indexed":true},{"type":"uint256","name":"allocPoint","internalType":"uint256","indexed":true},{"type":"bool","name":"active","internalType":"bool","indexed":true}],"anonymous":false},{"type":"event","name":"RewardPoolRatesAutoUpdated","inputs":[{"type":"address","name":"rewardsPool","internalType":"address","indexed":true},{"type":"uint256","name":"baseVouchPerYear","internalType":"uint256","indexed":false},{"type":"uint256","name":"baseVplsPerYear","internalType":"uint256","indexed":false},{"type":"uint256","name":"baseWplsPerYear","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"RewardPoolUpdateSettingsUpdated","inputs":[{"type":"address","name":"rewardsPool","internalType":"address","indexed":true},{"type":"uint256","name":"updateInterval","internalType":"uint256","indexed":false},{"type":"uint256","name":"updateRatio","internalType":"uint256","indexed":false},{"type":"uint256","name":"updateThreshold","internalType":"uint256","indexed":false},{"type":"bool","name":"autoUpdate","internalType":"bool","indexed":false}],"anonymous":false},{"type":"event","name":"Stake","inputs":[{"type":"address","name":"user","internalType":"address","indexed":true},{"type":"uint256","name":"pid","internalType":"uint256","indexed":true},{"type":"uint256","name":"amount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"UnlockCanceled","inputs":[{"type":"address","name":"user","internalType":"address","indexed":true},{"type":"uint256","name":"pid","internalType":"uint256","indexed":true},{"type":"uint256","name":"amount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"UnlockFinalized","inputs":[{"type":"address","name":"user","internalType":"address","indexed":true},{"type":"uint256","name":"pid","internalType":"uint256","indexed":true},{"type":"uint256","name":"amount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"UnlockPeriodUpdated","inputs":[{"type":"uint256","name":"oldPeriod","internalType":"uint256","indexed":false},{"type":"uint256","name":"newPeriod","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"UnlockRequested","inputs":[{"type":"address","name":"user","internalType":"address","indexed":true},{"type":"uint256","name":"pid","internalType":"uint256","indexed":true},{"type":"uint256","name":"amount","internalType":"uint256","indexed":false},{"type":"uint256","name":"unlockAt","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"Unstake","inputs":[{"type":"address","name":"user","internalType":"address","indexed":true},{"type":"uint256","name":"pid","internalType":"uint256","indexed":true},{"type":"uint256","name":"amount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"accPlsHolderRewardsPerShare","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"accVouchHolderRewardsPerShare","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"accVplsHolderRewardsPerShare","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"addCapitalPool","inputs":[{"type":"address","name":"_capitalPool","internalType":"address"},{"type":"uint256","name":"_allocPoint","internalType":"uint256"},{"type":"address","name":"_rewardPool","internalType":"address"},{"type":"bool","name":"_active","internalType":"bool"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"addLiquidityPool","inputs":[{"type":"address","name":"_stakingToken","internalType":"contract IERC20"},{"type":"uint256","name":"_allocPoint","internalType":"uint256"},{"type":"address","name":"_rewardPool","internalType":"address"},{"type":"bool","name":"_active","internalType":"bool"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"addPool","inputs":[{"type":"address","name":"_stakingToken","internalType":"contract IERC20"},{"type":"address","name":"_rewardsPool","internalType":"address"},{"type":"uint256","name":"_allocPoint","internalType":"uint256"},{"type":"bool","name":"_active","internalType":"bool"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"cancelUnlock","inputs":[{"type":"uint256","name":"_pid","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"capitalPoolToPid","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"claim","inputs":[{"type":"uint256","name":"_pid","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"claimAll","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"claimCapitalFor","inputs":[{"type":"address","name":"_capitalPool","internalType":"address"},{"type":"address","name":"_user","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"claimHolderRewards","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"distributeHolderRewardDividends","inputs":[{"type":"uint256","name":"_pid","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"exit","inputs":[{"type":"uint256","name":"_pid","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"uint256[]","name":"finalizedPids","internalType":"uint256[]"},{"type":"uint256[]","name":"amounts","internalType":"uint256[]"}],"name":"finalizeAllMaturedUnlocks","inputs":[{"type":"uint256[]","name":"_pids","internalType":"uint256[]"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"finalizeUnlock","inputs":[{"type":"uint256","name":"_pid","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"forceUpdateRewardPool","inputs":[{"type":"address","name":"_rewardPool","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"vouchClaimed","internalType":"uint256"},{"type":"uint256","name":"vplsClaimed","internalType":"uint256"},{"type":"uint256","name":"plsClaimed","internalType":"uint256"}],"name":"getDripRedeemed","inputs":[{"type":"uint256","name":"_pid","internalType":"uint256"},{"type":"address","name":"_user","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"vouchClaimed","internalType":"uint256"},{"type":"uint256","name":"vplsClaimed","internalType":"uint256"},{"type":"uint256","name":"plsClaimed","internalType":"uint256"}],"name":"getDripRedeemedAll","inputs":[{"type":"address","name":"_user","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"vouchPending","internalType":"uint256"},{"type":"uint256","name":"vplsPending","internalType":"uint256"},{"type":"uint256","name":"plsPending","internalType":"uint256"},{"type":"uint256","name":"redeemedVouch","internalType":"uint256"},{"type":"uint256","name":"redeemedVpls","internalType":"uint256"},{"type":"uint256","name":"redeemedPls","internalType":"uint256"}],"name":"getHolderRewardInfo","inputs":[{"type":"address","name":"_user","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint8","name":"poolType","internalType":"enum VouchStaking.PoolType"},{"type":"address","name":"stakingToken","internalType":"address"},{"type":"address","name":"rewardsPool","internalType":"address"},{"type":"uint256","name":"allocPoint","internalType":"uint256"},{"type":"bool","name":"active","internalType":"bool"},{"type":"uint256","name":"totalStaked","internalType":"uint256"},{"type":"uint256","name":"stdAccVouchPerShare","internalType":"uint256"},{"type":"uint256","name":"stdAccVplsPerShare","internalType":"uint256"},{"type":"uint256","name":"stdAccWplsPerShare","internalType":"uint256"},{"type":"uint256","name":"stdLastCalcTime","internalType":"uint256"},{"type":"uint256","name":"liqAccVouchPerShare","internalType":"uint256"},{"type":"uint256","name":"liqAccVplsPerShare","internalType":"uint256"},{"type":"uint256","name":"liqAccWplsPerShare","internalType":"uint256"},{"type":"uint256","name":"liqLastCalcTime","internalType":"uint256"}],"name":"getPoolInfo","inputs":[{"type":"uint256","name":"_pid","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"vouchPerYear","internalType":"uint256"},{"type":"uint256","name":"vplsPerYear","internalType":"uint256"},{"type":"uint256","name":"wplsPerYear","internalType":"uint256"},{"type":"uint256","name":"totalAllocPoint_","internalType":"uint256"}],"name":"getRewardPoolRates","inputs":[{"type":"address","name":"_rewardPool","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"amount","internalType":"uint256"},{"type":"uint256","name":"startTime_","internalType":"uint256"},{"type":"uint256","name":"unlockAt","internalType":"uint256"},{"type":"uint256","name":"secondsRemaining","internalType":"uint256"},{"type":"bool","name":"ready","internalType":"bool"}],"name":"getUnlock","inputs":[{"type":"uint256","name":"_pid","internalType":"uint256"},{"type":"address","name":"_user","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256[]","name":"amounts","internalType":"uint256[]"},{"type":"uint256[]","name":"startTimes","internalType":"uint256[]"},{"type":"uint256[]","name":"unlockAts","internalType":"uint256[]"},{"type":"uint256[]","name":"secondsRemainings","internalType":"uint256[]"},{"type":"bool[]","name":"readies","internalType":"bool[]"}],"name":"getUnlocks","inputs":[{"type":"address","name":"_user","internalType":"address"},{"type":"uint256[]","name":"_pids","internalType":"uint256[]"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getUserTotalVouchStaked","inputs":[{"type":"address","name":"_user","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract HolderRewardsVault"}],"name":"holderRewardsVault","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"lpRewardPool","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"standardVouchTotal","internalType":"uint256"},{"type":"uint256","name":"standardVplsTotal","internalType":"uint256"},{"type":"uint256","name":"standardWplsTotal","internalType":"uint256"},{"type":"uint256","name":"liqVouchTotal","internalType":"uint256"},{"type":"uint256","name":"liqVplsTotal","internalType":"uint256"},{"type":"uint256","name":"liqWplsTotal","internalType":"uint256"},{"type":"uint256","name":"holderVouch","internalType":"uint256"},{"type":"uint256","name":"holderVpls","internalType":"uint256"},{"type":"uint256","name":"holderPls","internalType":"uint256"}],"name":"pendingAllRewards","inputs":[{"type":"address","name":"_user","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"vouchPending","internalType":"uint256"},{"type":"uint256","name":"vplsPending","internalType":"uint256"},{"type":"uint256","name":"wplsPending","internalType":"uint256"}],"name":"pendingCapitalRewardsProjected","inputs":[{"type":"uint256","name":"_pid","internalType":"uint256"},{"type":"address","name":"_user","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"vouchPending","internalType":"uint256"},{"type":"uint256","name":"vplsPending","internalType":"uint256"},{"type":"uint256","name":"plsPending","internalType":"uint256"}],"name":"pendingHolderRewards","inputs":[{"type":"address","name":"_user","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"vouchPending","internalType":"uint256"},{"type":"uint256","name":"vplsPending","internalType":"uint256"},{"type":"uint256","name":"wplsPending","internalType":"uint256"}],"name":"pendingLiquidityRewardsProjected","inputs":[{"type":"uint256","name":"_pid","internalType":"uint256"},{"type":"address","name":"_user","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"vouchPending","internalType":"uint256"},{"type":"uint256","name":"vplsPending","internalType":"uint256"},{"type":"uint256","name":"wplsPending","internalType":"uint256"}],"name":"pendingStandardTriple","inputs":[{"type":"uint256","name":"_pid","internalType":"uint256"},{"type":"address","name":"_user","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"principalStakedToken","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"initialized","internalType":"bool"},{"type":"bool","name":"autoUpdate","internalType":"bool"},{"type":"uint256","name":"updateInterval","internalType":"uint256"},{"type":"uint256","name":"updateRatio","internalType":"uint256"},{"type":"uint256","name":"updateThreshold","internalType":"uint256"},{"type":"uint256","name":"lastUpdateTime","internalType":"uint256"},{"type":"uint256","name":"baseVouchPerYear","internalType":"uint256"},{"type":"uint256","name":"baseVplsPerYear","internalType":"uint256"},{"type":"uint256","name":"baseWplsPerYear","internalType":"uint256"},{"type":"uint256","name":"totalAllocPoint","internalType":"uint256"}],"name":"rewardPoolConfig","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"set","inputs":[{"type":"uint256","name":"_pid","internalType":"uint256"},{"type":"uint256","name":"_allocPoint","internalType":"uint256"},{"type":"bool","name":"_active","internalType":"bool"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setLPRewardPool","inputs":[{"type":"address","name":"_pool","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setRewardPoolEmissions","inputs":[{"type":"address","name":"_rewardPool","internalType":"address"},{"type":"uint256","name":"_vouchPerYear","internalType":"uint256"},{"type":"uint256","name":"_vplsPerYear","internalType":"uint256"},{"type":"uint256","name":"_wplsPerYear","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setRewardPoolUpdateSettings","inputs":[{"type":"address","name":"_rewardPool","internalType":"address"},{"type":"uint256","name":"_updateInterval","internalType":"uint256"},{"type":"uint256","name":"_updateRatio","internalType":"uint256"},{"type":"uint256","name":"_updateThreshold","internalType":"uint256"},{"type":"bool","name":"_autoUpdate","internalType":"bool"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setStandardUnlockPeriod","inputs":[{"type":"uint256","name":"_seconds","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setUpdateSettings","inputs":[{"type":"address","name":"_rewardPool","internalType":"address"},{"type":"uint256","name":"_updateInterval","internalType":"uint256"},{"type":"uint256","name":"_updateRatio","internalType":"uint256"},{"type":"uint256","name":"_updateThreshold","internalType":"uint256"},{"type":"bool","name":"_autoUpdate","internalType":"bool"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"stake","inputs":[{"type":"uint256","name":"_pid","internalType":"uint256"},{"type":"uint256","name":"_amount","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"standardUnlockPeriod","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"startUnlock","inputs":[{"type":"uint256","name":"_pid","internalType":"uint256"},{"type":"uint256","name":"_amount","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"totalPools","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"totalUnlocking","inputs":[{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"unstake","inputs":[{"type":"uint256","name":"_pid","internalType":"uint256"},{"type":"uint256","name":"_amount","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"amount","internalType":"uint256"},{"type":"uint256","name":"liqLastAccVouchPerShare","internalType":"uint256"},{"type":"uint256","name":"liqLastAccVplsPerShare","internalType":"uint256"},{"type":"uint256","name":"liqLastAccWplsPerShare","internalType":"uint256"},{"type":"uint256","name":"stdLastAccVouchPerShare","internalType":"uint256"},{"type":"uint256","name":"stdLastAccVplsPerShare","internalType":"uint256"},{"type":"uint256","name":"stdLastAccWplsPerShare","internalType":"uint256"}],"name":"userInfo","inputs":[{"type":"uint256","name":"","internalType":"uint256"},{"type":"address","name":"","internalType":"address"}]},{"type":"receive","stateMutability":"payable"}]
              

Contract Creation Code

0x60c03461022e57601f616c5638819003918201601f19168301916001600160401b038311848410176102075780849260809460405283398101031261022e5780519061004d60208201610233565b90610066606061005f60408401610233565b9201610233565b6001600055737783d7040423f75aef82a3ec32ed366ca460fa6c60a05262069780601255916001600160a01b031690811561021d576001600160a01b031691821561021d576001600160a01b031692831561021d57608052600280546001600160a01b031990811692909217905560038054909116919091179055604051610600808201906001600160401b0382118383101761020757602091839161605683393081520301906000f080156101fb57600180546001600160a01b03929092166001600160a01b031992831617905560048054909116919091179055604051610600808201908282106001600160401b0383111761020757602091839161665683393081520301906000f080156101fb57600580546001600160a01b0319166001600160a01b0392909216919091179055604051615e0e9081610248823960805181505060a05181818161039001528181610455015281816104eb0152818161066001528181610df601528181610eb101528181610f5c015281816110010152818161208901528181612357015261273b0152f35b6040513d6000823e3d90fd5b634e487b7160e01b600052604160045260246000fd5b63e6c4247b60e01b60005260046000fd5b600080fd5b51906001600160a01b038216820361022e5756fe6080604052600436101561001b575b361561001957600080fd5b005b60003560e01c806303ca8c311461030b57806309410cb9146103065780630ed3d611146103015780631979f81e146102fc57806321724f43146102f757806326f8f673146102f25780632ecc6d80146102ed5780632f380b35146102e8578063379607f5146102e357806338bb1778146102de57806339ebfa5e146102d95780633b6221c7146102d4578063406e2bf8146102cf57806341e0af5a146102ca57806355fe454a146102c55780635f323c54146102c057806362e06941146102bb57806363338d7d146102b657806364482f79146102b1578063671d9dc3146102ac578063687e2baa146102a757806368e6fa29146102a25780636918f7f81461029d5780636a2dba83146102985780636dec4974146102935780637b0472f01461028e5780637f8661a114610289578063819bfd9e146102845780638b5a9d561461027f5780638cf7deea1461027a5780638d48581c146102755780638e09136f1461027057806392de5edd1461026b5780639349acd81461026657806393f1a40b146102615780639e2c8a5b1461025c578063a3485fad14610257578063a5e6aeaf14610252578063ab3c7e521461024d578063b5c7662714610248578063b8f149ff14610243578063ba635cdd1461023e578063bbb5165b14610239578063bee5e1ec14610234578063d1058e591461022f578063db0987a71461022a5763f3400c2d0361000e576126e7565b6126aa565b61252d565b6124cb565b612412565b6123e9565b6123be565b612328565b61230a565b6122ec565b6122c4565b612181565b6120f0565b61205a565b61203c565b611e3f565b611e02565b611db5565b611b97565b6119a8565b611705565b6114b5565b6113f9565b6113c9565b61139e565b611238565b611086565b611068565b610fc3565b610f18565b610e5d565b610dc7565b610d75565b610b6b565b610af8565b610acc565b610a4f565b610962565b610874565b6107d4565b6106dd565b610628565b6105ff565b61055d565b6104bc565b61041d565b61033c565b6001600160a01b031690565b6001600160a01b0381160361032d57565b600080fd5b8015150361032d57565b3461032d57608036600319011261032d576004356103598161031c565b6024356044356103688161031c565b6064359161037583610332565b604051630935e01b60e21b81523360048201526020816024817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa908115610418576000916103e9575b50156103d85761001993612871565b637bfa4b9f60e01b60005260046000fd5b61040b915060203d602011610411575b61040381836127b8565b8101906127e0565b386103c9565b503d6103f9565b6127f5565b3461032d57602036600319011261032d5760043561043a8161031c565b604051630935e01b60e21b81523360048201526020816024817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa9081156104185760009161049d575b50156103d8576100199061398c565b6104b6915060203d6020116104115761040381836127b8565b3861048e565b3461032d57602036600319011261032d57600435604051630935e01b60e21b81523360048201526020816024817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa90811561041857600091610533575b50156103d857610019906129ec565b61054c915060203d6020116104115761040381836127b8565b38610524565b600091031261032d57565b3461032d57600036600319011261032d57610576613e1a565b60135460015b81811115610598575b61058e3361411f565b6100196001600055565b6000818152600660205260409020546002546001600160a01b039081169116146105ca576105c590612817565b61057c565b6105d49150612a55565b3880610585565b6001600160a01b0316600452602490565b6001600160a01b03909116815260200190565b3461032d57600036600319011261032d576005546040516001600160a01b039091168152602090f35b3461032d57602036600319011261032d576004356106458161031c565b604051630935e01b60e21b81523360048201526020816024817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa908115610418576000916106a8575b50156103d85761001990612c05565b6106c1915060203d6020116104115761040381836127b8565b38610699565b6040919493926060820195825260208201520152565b3461032d57604036600319011261032d576107126024356004356107008261031c565b600052600d6020526040600020610a38565b805461072d60026001840154930154604051938493846106c7565b0390f35b6003111561073b57565b634e487b7160e01b600052602160045260246000fd5b9a979490919e9d9c9996939b9895929b6101c08c019f600384101561073b57928c526001600160a01b0392831660208d01529b90911660408b01526101a09a6107a3919060608c0152151560808b0152565b60a089015260c088015260e08701526101008601526101208501526101408401526101608301526101808201520152565b3461032d57602036600319011261032d5760043560005260066020526040600020600481015461072d61080b8260ff9060081c1690565b9161081e6108198554610310565b610310565b9361082c6001820154610310565b6002820154909260ff1660038301546009840154600a850154600b86015491600c87015493600588015495600689015497600860078b01549a01549a6040519e8f9e8f610751565b3461032d57602036600319011261032d57600435610890613e1a565b61089981610a8c565b6108ae6108a96001830154610310565b6145ed565b600481015460081c60ff166108c281610731565b600181036108e0575050806108d961058e926150cf565b3390615230565b806108ec600292610731565b0361090b5750806108ff61090692614a7d565b3390614c40565b61058e565b6108196109229161091c3385614680565b54610310565b610933610819610819600254610310565b6001600160a01b039091161461094a575b5061058e565b61095390612a55565b61095c3361411f565b38610944565b3461032d57604036600319011261032d5761072d61098d6024356004356109888261031c565b612c58565b604093919351938493846106c7565b6001600160a01b0316600090815260096020526040902090565b6001600160a01b03166000908152600a6020526040902090565b6001600160a01b03166000908152600f6020526040902090565b6001600160a01b0316600090815260086020526040902090565b6001600160a01b03166000908152600b6020526040902090565b6001600160a01b03166000908152600e6020526040902090565b9060018060a01b0316600052602052604060002090565b3461032d57602036600319011261032d57600435610a6c8161031c565b60018060a01b031660005260096020526020604060002054604051908152f35b6000526006602052604060002090565b600052600c602052604060002090565b6000526010602052604060002090565b6000526007602052604060002090565b3461032d57602036600319011261032d5760043560005260106020526020604060002054604051908152f35b3461032d57602036600319011261032d5760c0600435610b178161031c565b610b208161341e565b90919260018060a01b031660005260086020526040600020906001820154906005600384015493015493604051958652602086015260408501526060840152608083015260a0820152f35b3461032d57602036600319011261032d57600435610b87613e1a565b610b9933610b9483610a9c565b610a38565b8054908115610d6457610bab83610a8c565b90610bbe600483015460ff9060081c1690565b610bc781610731565b610d53576001810191610bde835460125490612864565b4210610d4257600284926000610c9a95600d8501610bfd878254612c4b565b9055610c0889610aac565b610c13878254612c4b565b90558183555501610c33610c28825460ff1690565b825460ff1916909255565b610c406108198354610310565b610c51610819610819600254610310565b6001600160a01b0390911614610d2b575b15610cc557610c7c610c776108198354610310565b6109d0565b610c87838254612c4b565b90555b610c95339154610310565b61407c565b6040519081523390600080516020615d398339815191529080602081015b0390a36100196001600055565b610cd26108198254610310565b610ce3610819610819600254610310565b6001600160a01b03821614610cf9575b50610c8a565b610d029061099c565b610d0d838254612c4b565b9055610d18336109b6565b610d23838254612c4b565b905538610cf3565b610d3486612a55565b610d3d3361411f565b610c62565b634a44555360e11b60005260046000fd5b631b3140af60e11b60005260046000fd5b6322f70c8d60e21b60005260046000fd5b3461032d57600036600319011261032d576020601254604051908152f35b60a090600319011261032d57600435610dab8161031c565b90602435906044359060643590608435610dc481610332565b90565b3461032d57610dd536610d93565b604051630935e01b60e21b81523360048201529093919291906020816024817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa90811561041857600091610e3e575b50156103d85761001994612ee6565b610e57915060203d6020116104115761040381836127b8565b38610e2f565b3461032d57608036600319011261032d57600435610e7a8161031c565b602435604435610e898161031c565b60643591610e9683610332565b604051630935e01b60e21b81523360048201526020816024817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa90811561041857600091610ef9575b50156103d85761001993612fa1565b610f12915060203d6020116104115761040381836127b8565b38610eea565b3461032d57608036600319011261032d57600435610f358161031c565b602435604435606435604051630935e01b60e21b81523360048201529092906020816024817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa90811561041857600091610fa4575b50156103d85761001993613097565b610fbd915060203d6020116104115761040381836127b8565b38610f95565b3461032d57606036600319011261032d57600435604435602435610fe682610332565b604051630935e01b60e21b81523360048201526020816024817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa90811561041857600091611049575b50156103d857610019926130ee565b611062915060203d6020116104115761040381836127b8565b3861103a565b3461032d57600036600319011261032d576020601554604051908152f35b3461032d57604036600319011261032d576004356110a38161031c565b602435906110b08261031c565b6110b8613e1a565b6001600160a01b03163381900361112b57600052601160205260406000205490811561113c576110e782610a8c565b9160026110fc600485015460ff9060081c1690565b61110581610731565b0361112b5761111d6108a9600161058e950154610310565b61112681614a7d565b614c40565b63da37af0b60e01b60005260046000fd5b63015f4fdd60e31b60005260046000fd5b9181601f8401121561032d578235916001600160401b03831161032d576020808501948460051b01011161032d57565b906020808351928381520192019060005b81811061119b5750505090565b825184526020938401939092019160010161118e565b9391926111de6111fa946111d06111ec9460a0895260a089019061117d565b90878203602089015261117d565b90858203604087015261117d565b90838203606085015261117d565b9060808183039101526020808351928381520192019060005b8181106112205750505090565b82511515845260209384019390920191600101611213565b3461032d57604036600319011261032d576004356112558161031c565b6024356001600160401b03811161032d5761127490369060040161114d565b61127d816131d5565b90611287816131d5565b92611291826131d5565b61129a836131d5565b916112a4846131d5565b9360005b8181106112c4575050509061072d9291604051958695866111b1565b806112df8a610b946112d9600195878961321d565b35610a9c565b82815491826112ee858d613232565b52015490816112fd848d613232565b526113315750600061130f8287613232565b52600061131c8288613232565b5260006113298289613232565b525b016112a8565b60125461133d91612864565b806113488388613232565b524281116113765750600061135d8288613232565b5261137161136b8289613232565b60019052565b61132b565b611381904290612c4b565b61138b8288613232565b5260006113988289613232565b5261132b565b3461032d57604036600319011261032d5761072d61098d6024356004356113c48261031c565b613255565b3461032d57604036600319011261032d576113f26024356004356113eb613e1a565b3390615639565b6001600055005b3461032d57602036600319011261032d576004356114168161031c565b60018060a01b0316600052600b6020526040600020805461072d600183015492600281015490600381015460048201546005830154906006840154926008600786015495015495604051998960ff808d9c60081c1691168b9693909a9998959261012098959261014089019c151589521515602089015260408801526060870152608086015260a085015260c084015260e08301526101008201520152565b3461032d57604036600319011261032d576004356024356114d4613e1a565b6114dd82610a8c565b600481019081546114f56114f18260ff1690565b1590565b6116f45760029060081c60ff1661150b81610731565b146116e3576115206108a96001830154610310565b815460019060081c60ff1661153481610731565b0361169457611542846150cf565b61154c3385615230565b6115638361155a8354610310565b309033906158ed565b60038101611572848254612864565b90556115816108198254610310565b61159d611597856115918461099c565b54612864565b9161099c565b5560016115f46115b033610b9488610abc565b936115bc868654612864565b85556115cb6108198554610310565b6115dc610819610819600254610310565b90848060a01b031614611678575b5460081c60ff1690565b6115fd81610731565b03611655576007816005600393015460018501556006810154600285015501549101555b60405190815233907f5af417134f72a9d41143ace85b0a26dce6f550f894f2cbc1eeee8810603d91b6908060208101610cb8565b600b81600960069301546004850155600a81015460058501550154910155611621565b61168586611591336109b6565b61168e336109b6565b556115ea565b61169e3385614680565b6116ab6108198254610310565b6116bc610819610819600254610310565b6001600160a01b039091160361154c576116d584612a55565b6116de3361411f565b61154c565b63e96142b160e01b60005260046000fd5b6338c0a90160e11b60005260046000fd5b3461032d57602036600319011261032d57600435611721613e1a565b61172a81610a8c565b61173d61173683610abc565b3390610a38565b908154918215611997576004820154839060081c60ff1661175d81610731565b158061198c575b156118b9575061177733610b9486610a9c565b9081546118a8578261180a6002610c7794600061081995600361183799016117a08b8254612c4b565b90556117b76117b26108198854610310565b61099c565b6117c28b8254612c4b565b90556117d16108198754610310565b6117e16108196108198754610310565b6001600160a01b0390911614611870575b5587815542600182015501600160ff19825416179055565b600d8101611819868254612864565b905561182486610aac565b61182f868254612864565b905554610310565b611842828254612864565b9055600080516020615d79833981519152610cb861186260125442612864565b6040519182913395836133ba565b611879336109b6565b6118848b8254612c4b565b905561188f336109ea565b60145481556015548582015560046016549101556117f2565b63b76ac96760e01b60005260046000fd5b9091600061193193600383016118d0858254612c4b565b90556118df6108198454610310565b6118f5611597866118ef8461099c565b54612c4b565b556119036108198454610310565b611914610819610819600254610310565b6001600160a01b0390911614611952575b55610c95339154610310565b6040519081523390600080516020615d9983398151915290602090a361058e565b61195f846118ef336109b6565b611968336109b6565b55611972336109ea565b601454815560155460028201556004601654910155611925565b506012541515611764565b639fe7bfd960e01b60005260046000fd5b3461032d57602036600319011261032d576004356119c4613e1a565b6119d133610b9483610a9c565b8054908115610d64576119e383610a8c565b600481015460081c60ff166119f781610731565b610d5357600b81611a106108a960016006950154610310565b611a1986615ae1565b611a6c6002850160006001611a2f835460ff1690565b97600d8601611a3f8b8254612c4b565b905588611a4b8c610aac565b611a568c8254612c4b565b9055611b50575b8281550155805460ff19169055565b611a7933610b9488610abc565b93611a85868654612864565b855560038201611a96878254612864565b9055611aea575b60098101546004850155600a8101546005850155015491015560405190815233907f9580ac8befa235ac705ab43a31830cbda760282bdbe4644eec9abd39a973a4d6908060208101610cb8565b611afa6117b26108198354610310565b611b05868254612864565b9055611b146108198254610310565b611b25610819610819600254610310565b6001600160a01b0390911603611a9d57611b3e336109b6565b611b49868254612864565b9055611a9d565b611b60610c776108198854610310565b611b6b8b8254612c4b565b9055611a5d565b9091611b89610dc49360408452604084019061117d565b91602081840391015261117d565b3461032d57602036600319011261032d576004356001600160401b03811161032d57611bc790369060040161114d565b90611bd0613e1a565b611bd9826131d5565b90611be3836131d5565b926000916000915b808310611c13575050508082528252611c046001600055565b61072d60405192839283611b72565b909192611c2184838561321d565b35611c2f33610b9483610a9c565b908154918215611da9576001810190611c4c825460125490612864565b4210611d9c57611c5b83610a8c565b91611c6e600484015460ff9060081c1690565b611c7781610731565b611d8e578483600260019896946000611d0795600d8c9b9901611c9b878254612c4b565b9055611ca688610aac565b611cb1878254612c4b565b90558183555501611cc6610c28825460ff1690565b611cd36108198354610310565b611ce4610819610819600254610310565b90898060a01b031614611d77575b15611d4657610c7c610c776108198354610310565b60405182815281903390600080516020615d3983398151915290602090a3611d2f838a613232565b52611d3a828a613232565b5201935b019190611beb565b611d536108198254610310565b611d64610819610819600254610310565b888060a01b03821614610cf95750610c8a565b611d8085612a55565b611d893361411f565b611cf2565b505050505092600190611d3e565b5050505092600190611d3e565b50505092600190611d3e565b3461032d57602036600319011261032d57600435611dd28161031c565b60018060a01b0316600052600e6020526040600020805461072d60026001840154930154604051938493846106c7565b3461032d57602036600319011261032d57600435611e1f8161031c565b60018060a01b031660005260116020526020604060002054604051908152f35b3461032d57602036600319011261032d57600435611e5c8161031c565b60008081829083918460016013545b80821115611ecb575050611e8361072d95969761341e565b9591939094604051998a998a95926101009794919a9998959261012088019b8852602088015260408701526060860152608085015260a084015260c083015260e08201520152565b9091949288611ed984610a8c565b600481015460081c60ff16611eed81610731565b60018103611f49575050611f0490610b9485610abc565b5415611f3d57611f30611f2a611f2a611f3793611f218d88612c58565b94919092612864565b97612864565b925b612817565b90611e6b565b929491611f3790612817565b80611f55600292610731565b03611fec57611f8e91611f7361081961081961081960209554610310565b604051808095819463673e156160e11b8352600483016105ec565b03915afa90811561041857600091611fbe575b5015611f3d57611f30611f2a611f2a611f3793611f218d88613255565b611fdf915060203d8111611fe5575b611fd781836127b8565b810190613246565b38611fa1565b503d611fcd565b5061200190610b9485979a9993969895610abc565b54156120305761202a61201e612024611f3793611f218d8a6135f7565b9a612864565b99612864565b94612817565b959693611f3790612817565b3461032d57600036600319011261032d576020601454604051908152f35b3461032d57602036600319011261032d57600435604051630935e01b60e21b81523360048201526020816024817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa908115610418576000916120d1575b50156103d857610019906133cb565b6120ea915060203d6020116104115761040381836127b8565b386120c2565b3461032d57604036600319011261032d576121256024356004356121138261031c565b60005260076020526040600020610a38565b805461072d600183015492600281015490600381015460048201549060066005840154930154936040519788978893909796959260c0959260e08601998652602086015260408501526060840152608083015260a08201520152565b3461032d57604036600319011261032d576004356024356121a0613e1a565b6121a982610a8c565b6121b561173684610abc565b906121c8600482015460ff9060081c1690565b6121d181610731565b156122b35782156122a25782825410612291576007816121f96108a960016003950154610310565b612202866150cf565b61220c3387615230565b61221b8533610c958454610310565b828101612229868254612c4b565b90556122386108198254610310565b612248611597876118ef8461099c565b55612254858554612c4b565b8455600581015460018501556006810154600285015501549101556040519081523390600080516020615d99833981519152908060208101610cb8565b632360e66f60e21b60005260046000fd5b6365e52d5160e11b60005260046000fd5b6306fe23cd60e51b60005260046000fd5b3461032d57602036600319011261032d5761072d61098d6004356122e78161031c565b61341e565b3461032d57600036600319011261032d576020601654604051908152f35b3461032d57600036600319011261032d576020601354604051908152f35b3461032d5761233636610d93565b604051630935e01b60e21b81523360048201529093919291906020816024817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa9081156104185760009161239f575b50156103d85761001994613554565b6123b8915060203d6020116104115761040381836127b8565b38612390565b3461032d57604036600319011261032d5761072d61098d6024356004356123e48261031c565b6135f7565b3461032d57600036600319011261032d576001546040516001600160a01b039091168152602090f35b3461032d57604036600319011261032d5761244760243560406004356124378361031c565b6000908152600c60205220610a38565b6001815491015490801560001461248d5761072d600080815b6040519586958693909594919260809360a086019786526020860152604085015260608401521515910152565b60125482018083116124c657804281116124b05761072d91506000600191612460565b4282039182116124c65761072d91600091612460565b612801565b3461032d57602036600319011261032d576004356124e88161031c565b60018060a01b0316600052600b602052608060406000206005810154906006810154906008600782015491015491604051938452602084015260408301526060820152f35b3461032d57600036600319011261032d57612546613e1a565b60015b601354811161058e5761255b81610a8c565b61256b6108a96001830154610310565b600481015460081c60ff1661257f81610731565b600181036125b7575050806125996117366125b293610abc565b5415611f32576125a8816150cf565b611f323382615230565b612549565b806125c3600292610731565b03612649576108196108196108196125db9354610310565b906020604051809363673e156160e11b825281806125fc33600483016105ec565b03915afa8015610418576125b29260009161262b575b5015611f325761262181614a7d565b611f323382614c40565b612643915060203d8111611fe557611fd781836127b8565b38612612565b906125b29161265a61173683610abc565b54156126a4576108196126719161091c3385614680565b612682610819610819600254610310565b6001600160a01b0390911603611f325761269b81612a55565b611f323361411f565b50612817565b3461032d57602036600319011261032d576004356126c78161031c565b60018060a01b0316600052600a6020526020604060002054604051908152f35b3461032d57608036600319011261032d576004356127048161031c565b6024356127108161031c565b6044356064359161272083610332565b604051630935e01b60e21b81523360048201526020816024817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa90811561041857600091612783575b50156103d857610019936137f7565b61279c915060203d6020116104115761040381836127b8565b38612774565b634e487b7160e01b600052604160045260246000fd5b601f909101601f19168101906001600160401b038211908210176127db57604052565b6127a2565b9081602091031261032d5751610dc481610332565b6040513d6000823e3d90fd5b634e487b7160e01b600052601160045260246000fd5b60001981146124c65760010190565b80546001600160a01b0319166001600160a01b03909216919091179055565b9060ff801983541691151516179055565b90600182018092116124c657565b919082018092116124c657565b6001600160a01b0381169391929084156129c757803b156129d8576001600160a01b038216156129c757813b156129af5761295a826008926128d47ff689203c966f70583b50d911d766ab0ecc2a966cd769b108a7f055d5a5a7953896956138ff565b61293860046128f56128e7601354612817565b6128f081601355565b610a8c565b6128ff8b82612826565b61290c8560018301612826565b896002820155428782015560006003820155016129298782612845565b805461ff001916610200179055565b6013546001600160a01b03909116600090815260116020526040902055610a04565b6129686114f1825460ff1690565b612999575b01612979848254612864565b90556013546040805194855291151560208501529290819081015b0390a3565b805460ff1916600117815542600482015561296d565b63b5cf5b8f60e01b6000526129c3826105db565b6000fd5b63d92e233d60e01b60005260046000fd5b63b5cf5b8f60e01b6000526129c3906105db565b6129fd906129f8613e1a565b612a55565b6001600055565b9064e8d4a5100082029180830464e8d4a5100014901517156124c657565b818102929181159184041417156124c657565b8115612a3f570490565b634e487b7160e01b600052601260045260246000fd5b61081961091c612a6492610a8c565b612a72610819600254610310565b90612a7c82610310565b6001600160a01b0390911603612c0257612a959061099c565b548015612c0257612aa4613e3c565b928291921590818092612bfa575b80612bf2575b612beb57811580612bbc575b8415159081612b8d575b8615159283612b37575b5092612b2f575b508115612b27575b50612af157505050565b612b227f03496c6e2a2d21afdf685b8a8bac6a73315ee13ed95156e776e20b5838f5a30e93604051938493846106c7565b0390a1565b905038612ae7565b915038612adf565b612b59612b5e91612b5360165491612b4e8c612a04565b612a35565b90612864565b601655565b612b8787612b73610819610819600454610310565b612b81610819600154610310565b9061407c565b38612ad8565b612ba8612ba3601554612b5386612b4e8b612a04565b601555565b612bb786612b73600354610310565b612ace565b612bd7612bd2601454612b5385612b4e89612a04565b601455565b612be684612b73600254610310565b612ac4565b5050505050565b508415612ab8565b508315612ab2565b50565b600580546001600160a01b0319166001600160a01b039290921691821790557f1fcf35f04a5b25cdc6b8e722590db86da086bb256cf7ad9f3d131e4f7ed07c4c600080a2565b919082039182116124c657565b9190612c6383610a8c565b926001612c78600486015460ff9060081c1690565b612c8181610731565b03612ea25790610b94612c9392610abc565b9081548015612e965760058401549360068101549484600783015492612cc4612cbf6001830154610310565b610a04565b60038201549182151580612e89575b612d2d575b505050612d0d926003612d24612d0d87612d08612d18612d0d83612d08610dc49d9b6001612d089c015490612c4b565b612a22565b64e8d4a51000900490565b9c60028d015490612c4b565b97015490612c4b565b612d3b600882015442612c4b565b9081612d48575b50612cd8565b612d6891929394506002612d5d910154612a04565b600884015490612a35565b91612d7b60058201546301e13380900490565b90612da06007612d9360068401546301e13380900490565b9201546301e13380900490565b9180612e65575b5080612e22575b509388612d0894612d0d979489979485610dc49b96612dd9575b505050509381959750839650612d42565b86612d08612d24976001612e14612d0d999c612b5360039d9a612b4e612e0f612d0d612d089d612d08612d189e612d0d9e612a22565b612a04565b9b9850509750509650612dc8565b848484612e548b99959e612b538f969a612b4e610dc49f9a612d0d9f9c612d0d90612d089f612e0f93612d0891612a22565b9d9498509499509497509450612dae565b95612b5386612b4e612e0f612d0d89612d088a612e82999e612a22565b9438612da7565b5060088201541515612cd3565b50600092508291508190565b50600092508291829150565b9061ff00825491151560081b169061ff001916179055565b926060929594919560808501968552602085015260408401521515910152565b9093612ef182610a04565b805490919060ff1615612f9057618e948411612f7f5760648511612f6e577f8f431beef2454b875352c7cca935b7977bb1e8a1786cc427b21fb3658ae0ec6394612f508284896001612f69970155876002820155836003820155612eae565b6040516001600160a01b03909416969394859485612ec6565b0390a2565b63e56d58cf60e01b60005260046000fd5b63971a803560e01b60005260046000fd5b631d51ca5b60e11b60005260046000fd5b6001600160a01b03811693919290919084156129c757843b15613083576001600160a01b038116156129c757803b156129d857612fe5610819610819600254610310565b85146130725761295a81612cbf60047fda69ac0b47fc0c71cff6468d04caf4baaf54677b77a1235772fd8368a23f45b2966130216008966138ff565b6130396130326128e7601354612817565b9182612826565b6130468460018301612826565b886002820155428682015560006003820155016130638682612845565b805461ff001916610100179055565b633fbade9b60e21b60005260046000fd5b63b5cf5b8f60e01b6000526129c3856105db565b6001600160a01b03166000818152600b602052604090208054919493929160ff1615612f905783600080516020615db983398151915294600783856005612f699601558660068201550155604051938493846106c7565b91601354831161113c5761313781600461310786610a8c565b856001820161311e6131198254610310565b6138ff565b6002830190815490838203613161575b50505501612845565b1515917fec70f7b7f8beefa9ff0456053baafec83986e3915f156e2ed04b0acb57d7dd55600080a4565b612cbf61316e9154610310565b90838181111561319e575050613194600861318a845486612c4b565b9201918254612864565b90555b388061312e565b6131ad6008916131b793612c4b565b9201918254612c4b565b9055613197565b6001600160401b0381116127db5760051b60200190565b906131df826131be565b6131ec60405191826127b8565b82815280926131fd601f19916131be565b0190602036910137565b634e487b7160e01b600052603260045260246000fd5b919081101561322d5760051b0190565b613207565b805182101561322d5760209160051b010190565b9081602091031261032d575190565b9161325f83610a8c565b916002613274600485015460ff9060081c1690565b61327d81610731565b03612e96576132956108196108196108198654610310565b906040519463673e156160e11b8652602086806132b585600483016105ec565b0381865afa92831561041857600496600094613398575b5060209060405197888092633a98ef3960e01b82525afa95861561041857600096613377575b5082156133665790610b9461330692610abc565b92600581015484600683015496600784015493613329612cbf6001830154610310565b9082151580612e8957612d2d57505050612d0d926003612d24612d0d87612d08612d18612d0d83612d08610dc49d9b6001612d089c015490612c4b565b505050915050600090600090600090565b61339191965060203d602011611fe557611fd781836127b8565b94386132f2565b60209194506133b390823d8411611fe557611fd781836127b8565b93906132cc565b908152602081019190915260400190565b62127500811161340d577faa1e10941c3aafb56ad74dad40ea5ec52cf44d83495362e44c775124edb040f59060125481601255612b22604051928392836133ba565b631c3c41f160e31b60005260046000fd5b90613428826109b6565b5491821561354957613439906109ea565b9061344b6117b2610819600254610310565b5492601454936015549484601654928061348b575b50612d0d926004612d24612d0d87612d08612d18612d0d83612d08610dc49d9b612d089b5490612c4b565b9050613495615923565b9180613530575b5080613500575b509284610dc4959388612d089487612d0d986134c8575b505093509350945092613460565b612d18612d0d86612d08612d24976134f1612d0d989b612b5360049c99612b4e612d089a612a04565b9a9750975050965050506134ba565b9480938884613521612d0d98959c612b53612d0898612b4e610dc49d612a04565b9b9497509450509395506134a3565b93612b5384612b4e6135429497612a04565b923861349c565b506000915081908190565b6001600160a01b038116949085156129c75761356f90610a04565b9061357e6114f1835460ff1690565b6135e1575b618e948411612f7f5760648511612f6e577f9d27ba522132b33ab70fcfdab90aea87b84ed6147139f6a5fef95b15fd1f9687946135d58284866001612f69970155876002820155836003820155612eae565b60405194859485612ec6565b815460ff19166001178255426004830155613583565b919061360283610a8c565b92613615600485015460ff9060081c1690565b61361e81610731565b612ea25790610b9461362f92610abc565b9081548015612e9657600984015493600a8101549484600b8301549261365b612cbf6001830154610310565b600382015491821515806137ea575b6136ab575b505050612d0d926006612d24612d0d87612d0861369f612d0d83612d08610dc49d9b6004612d089c015490612c4b565b9c60058d015490612c4b565b6136b9600c82015442612c4b565b90816136c6575b5061366f565b6136db91929394506002612d5d910154612a04565b916136ee60058201546301e13380900490565b906137066007612d9360068401546301e13380900490565b91806137c6575b5080613783575b509388612d0894612d0d979489979485610dc49b9661373f575b5050505093819597508396506136c0565b86612d08612d24976004613775612d0d999c612b5360069d9a612b4e612e0f612d0d612d089d612d0861369f9e612d0d9e612a22565b9b985050975050965061372e565b8484846137b58b99959e612b538f969a612b4e610dc49f9a612d0d9f9c612d0d90612d089f612e0f93612d0891612a22565b9d9498509499509497509450613714565b95612b5386612b4e612e0f612d0d89612d088a6137e3999e612a22565b943861370d565b506008820154151561366a565b6001600160a01b0381169392919084156129c757843b15613083576001600160a01b038216156129c757813b156129af576138a78260089261385a7f5a1ab27da2e22f0200f305e180a2e00bd4369d22cd036b19d02e987a16ce76f096956138ff565b61386b6130326128e7601354612817565b6138788260018301612826565b84600282015560006003820155613893600482019788612845565b865461ff0019168755600c42910155610a04565b6138b56114f1825460ff1690565b6138e9575b016138c6828254612864565b905560135492546040805192835260ff9091161515602083015281908101612994565b805460ff191660011781554260048201556138ba565b6013549060015b8281111561391357505050565b8061392061396492610a8c565b61392d6001820154610310565b6001600160a01b038581169116036126a4576004015460081c60ff1661395281610731565b600181036139695750611f32816150cf565b613906565b80613975600292610731565b0361398357611f3281614a7d565b611f3281615ae1565b61399581610a04565b906139a46114f1835460ff1690565b613ba8574260048301556139c2610819610819610819600254610310565b91602060405180946370a0823160e01b825281806139e387600483016105ec565b03915afa92831561041857600093613b87575b50613a0b610819610819610819600354610310565b91602060405180946370a0823160e01b82528180613a2c86600483016105ec565b03915afa92831561041857600093613b66575b50613a4e610819600454610310565b6001600160a01b03811615613b3957610819613a6991610310565b602060405180926370a0823160e01b82528180613a8987600483016105ec565b03915afa938415610418576007613ae8613ad5613ad5613ae2613ad5600080516020615db98339815191529a612f6998600091613b1a575b509b5b613adc60028c015494858093612a22565b6064900490565b97612a22565b99612a22565b600586019283556006860197885594018490555494546040516001600160a01b039093169592938493909190846106c7565b613b33915060203d602011611fe557611fd781836127b8565b38613ac1565b50612f69600080516020615db9833981519152936007613ae8613ad5613ad5613ae2613ad560009b613ac4565b613b8091935060203d602011611fe557611fd781836127b8565b9138613a3f565b613ba191935060203d602011611fe557611fd781836127b8565b91386139f6565b5050565b613bb581610a04565b613bc36114f1825460ff1690565b613ba857426004820155613be1610819610819610819600254610310565b91602060405180946370a0823160e01b82528180613c0286600483016105ec565b03915afa92831561041857600093613df9575b50613c2a610819610819610819600354610310565b90602060405180936370a0823160e01b82528180613c4b86600483016105ec565b03915afa91821561041857600092613dd8575b50613c6d610819600454610310565b6001600160a01b03811615613dc057610819613c8891610310565b602060405180926370a0823160e01b82528180613ca887600483016105ec565b03915afa801561041857613ad5613cdf613ad5613ad593613ce595600091613da1575b50985b613adc60028a015494858093612a22565b96612a22565b6000906005850194855494613d01600383019682885491615c22565b613d95575b506006810196613d1a885482885491615c22565b613d88575b506007613d33910194828654915491615c22565b613d7d575b50613d44575b50505050565b613d71600080516020615db983398151915293549454925460405193849360018060a01b031696846106c7565b0390a238808080613d3e565b835550600138613d38565b8755600192506007613d1f565b86556001925038613d06565b613dba915060203d602011611fe557611fd781836127b8565b38613ccb565b50613ce5613ad5613ad5613cdf613ad5600098613cce565b613df291925060203d602011611fe557611fd781836127b8565b9038613c5e565b613e1391935060203d602011611fe557611fd781836127b8565b9138613c15565b600260005414613e2b576002600055565b633ee5aeb560e01b60005260046000fd5b600090600090600090613e53610819600254610310565b6040516370a0823160e01b81529060208280613e7230600483016105ec565b0381845afa91821561041857600092614057575b5080613e9e613e97613ea59361099c565b54916109d0565b5490612864565b90818111614044575b5050613ebe610819600354610310565b6040516370a0823160e01b81529060208280613edd30600483016105ec565b0381845afa9182156104185760009261401f575b5080613e9e613e97613f029361099c565b9081811161400c575b5050613f1b610819600454610310565b6001600160a01b038116156140065747613fbf575b50613f3f610819600454610310565b6040516370a0823160e01b81529060208280613f5e30600483016105ec565b0381845afa91821561041857600092613f9a575b5080613e9e613e97613f839361099c565b90818111613f8f575050565b610dc4929350612c4b565b613f83919250613fb89060203d602011611fe557611fd781836127b8565b9190613f72565b4790803b1561032d57600090600460405180948193630d0e30db60e41b83525af180156104185715613f305780613ffa6000614000936127b8565b80610552565b38613f30565b50479150565b614017929450612c4b565b913880613f0b565b613f0291925061403d9060203d602011611fe557611fd781836127b8565b9190613ef1565b61404f929550612c4b565b923880613eae565b613ea59192506140759060203d602011611fe557611fd781836127b8565b9190613e86565b60405163a9059cbb60e01b60208201526001600160a01b0390921660248301526044808301939093529181526140bc916140b76064836127b8565b615cdd565b565b6001600160a01b03918216815291166020820152604081019190915260600190565b3d1561411a573d906001600160401b0382116127db576040519161410e601f8201601f1916602001846127b8565b82523d6000602084013e565b606090565b614128816109b6565b5490614133816109ea565b91156145d5576141428161341e565b9290919384158080916145cd575b806145c5575b6145a857156144f3575b82614439575b836141aa575b600080516020615d5983398151915293612f699160145481556015546002820155600460165491015560405193849360018060a01b031696846106c7565b6004546001600160a01b03906141c39061081990610310565b1615614400576141d7610819600154610310565b803b1561430957506141ed610819600154610310565b6141fb610819600454610310565b90803b1561032d578560009161422a9383604051809681958294630668be0d60e11b84523090600485016140be565b03925af18015610418576142f4575b505b614249610819600454610310565b803b1561032d57604051632e1a7d4d60e01b815260048101869052906000908290602490829084905af18015610418576142df575b506000808080876001600160a01b0387165af16142996140e0565b50156142ce57600080516020615d5983398151915293612f69915b600581016142c3838254612864565b90559150935061416c565b63a77a8f1d60e01b60005260046000fd5b80613ffa60006142ee936127b8565b3861427e565b80613ffa6000614303936127b8565b38614239565b61431a610819610819600454610310565b9061432482610310565b91604051916370a0823160e01b83526020838061434484600483016105ec565b0381875afa92831561041857889384916000916143e1575b50106143735761436e935030916158ed565b61423b565b505050602060405180926370a0823160e01b8252818061439630600483016105ec565b03915afa80156104185785916000916143c2575b50101561423b57631d93fd4d60e01b60005260046000fd5b6143db915060203d602011611fe557611fd781836127b8565b386143aa565b6143fa915060203d602011611fe557611fd781836127b8565b3861435c565b6000808080876001600160a01b0387165af161441a6140e0565b50156142ce57600080516020615d5983398151915293612f69916142b4565b614447610819600154610310565b8383823b156144da57505050614461610819600154610310565b61446f610819600354610310565b90803b1561032d5784600091858361449e9560405196879586948593630668be0d60e11b8552600485016140be565b03925af18015610418576144c5575b505b600381016144be848254612864565b9055614166565b80613ffa60006144d4936127b8565b386144ad565b6144ee926144e9600354610310565b6158ed565b6144af565b614501610819600154610310565b8583823b156145945750505061451b610819600154610310565b614529610819600254610310565b90803b1561032d578660009185836145589560405196879586948593630668be0d60e11b8552600485016140be565b03925af180156104185761457f575b505b60018101614578868254612864565b9055614160565b80613ffa600061458e936127b8565b38614567565b6145a3926144e9600254610310565b614569565b509350505050601454815560155460028201556004601654910155565b508415614156565b508315614150565b50601454815560155460028201556004601654910155565b6001600160a01b038116803b1561032d576000809160046040518094819363fff6cae960e01b83525af161466b575b5061462681610a04565b805460ff8116156146665761463f9060081c60ff161590565b613ba857806001600461465793015491015490612864565b4210612c02576140bc90613bac565b505050565b80613ffa600061467a936127b8565b3861461c565b9061468a82610a8c565b600481015460081c60ff1661469e81610731565b610d53576146ab83615ae1565b6146b882610b9485610abc565b9160098201549060048401926146cf845484612c4b565b946146df612d0d82548098612a22565b95600a83018054906146fe612d0d84612d086005880195865490612c4b565b9661471c612d0d600b880195612d0860068854990198895490612c4b565b985554905554905584158080614a75575b80614a6d575b614a645780158091614a5b575b8015614a52575b6149aa575b614930575b826148b6575b83151580614894575b6147a0575b506129947f68e1caf97c4c29c1ac46024e9590f80b7a1f690d393703879cf66eea4e1e84219360405193849360018060a01b031696846106c7565b61081961081960016147b3930154610310565b6147c1610819600454610310565b90803b1561032d57846000916147f09383604051809681958294630668be0d60e11b84523090600485016140be565b03925af180156104185761487f575b5061480e610819600454610310565b803b1561032d57604051632e1a7d4d60e01b815260048101859052906000908290602490829084905af180156104185761486a575b506000808080866001600160a01b0386165af161485e6140e0565b50156142ce5738614765565b80613ffa6000614879936127b8565b38614843565b80613ffa600061488e936127b8565b386147ff565b506004546001600160a01b03906148ae9061081990610310565b161515614760565b6148c96108196108196001840154610310565b6148d7610819600354610310565b90803b1561032d578460009185836149069560405196879586948593630668be0d60e11b8552600485016140be565b03925af180156104185761491b575b50614757565b80613ffa600061492a936127b8565b38614915565b6149436108196108196001840154610310565b614951610819600254610310565b90803b1561032d578660009185836149809560405196879586948593630668be0d60e11b8552600485016140be565b03925af1801561041857614995575b50614751565b80613ffa60006149a4936127b8565b3861498f565b6149c283610b9489600052600d602052604060002090565b816149cc85610a1e565b90614a33575b85614a0c575b866149e5575b505061474c565b60028092016149f5888254612864565b905501614a03868254612864565b905538806149de565b60018201614a1b878254612864565b905560018101614a2c878254612864565b90556149d8565b614a3e888354612864565b8255614a4b888254612864565b81556149d2565b50841515614747565b50831515614740565b50505050505050565b508415614733565b50831561472d565b614a8690610a8c565b600481015460029060081c60ff16614a9d81610731565b03612c02576004614ab4612cbf6001840154610310565b6020614ac96108196108196108198754610310565b604051633a98ef3960e01b815293849182905afa91821561041857600092614c1f575b5081158015614c13575b614c09576008830192614b0a845442612c4b565b8015612beb57614b2b614b206002840154612a04565b600885015490612a35565b60058401546301e13380900493614b4f6007612d9360068401546301e13380900490565b94838382614bd8575b90915082614ba7575b50505083614b74575b5050505050429055565b614b8d612d0d600792612d08612b5395614b9b98612a22565b920193612b4e855493612a04565b90553880808080614b6a565b612d08612d0d92614bb794612a22565b614bce6006850191612b5388612b4e855493612a04565b9055388282614b61565b612d08612d0d92614be894612a22565b614bff6005860191612b5389612b4e855493612a04565b9055388383614b58565b5050600842910155565b50600881015415614af6565b614c3991925060203d602011611fe557611fd781836127b8565b9038614aec565b90614c4a82610a8c565b906002614c5f600484015460ff9060081c1690565b614c6881610731565b0361112b57614c806108196108196108198554610310565b91823b1561032d5760405163059d9c7560e01b815260008160048183885af16150ba575b506020604051809463673e156160e11b82528180614cc587600483016105ec565b03915afa92831561041857600093615099575b50614ce682610b9486610abc565b916005820154916001840193614d04612d0d87612d08885488612c4b565b9560068301805490614d23612d0d84612d086002880195865490612c4b565b96614d41612d0d6007880195612d0860038854990198895490612c4b565b985554905554905584158080615091575b80615089575b614a645780158091615080575b8015615077575b614fcf575b614f55575b82614edb575b83151580614eb9575b614dc5575b506129947f53db52faf4f2c533709dc2c6bf586462f325c7ca9f3d47839847c0dcae221fc29360405193849360018060a01b031696846106c7565b6108196108196001614dd8930154610310565b614de6610819600454610310565b90803b1561032d5784600091614e159383604051809681958294630668be0d60e11b84523090600485016140be565b03925af1801561041857614ea4575b50614e33610819600454610310565b803b1561032d57604051632e1a7d4d60e01b815260048101859052906000908290602490829084905af1801561041857614e8f575b506000808080866001600160a01b0386165af1614e836140e0565b50156142ce5738614d8a565b80613ffa6000614e9e936127b8565b38614e68565b80613ffa6000614eb3936127b8565b38614e24565b506004546001600160a01b0390614ed39061081990610310565b161515614d85565b614eee6108196108196001840154610310565b614efc610819600354610310565b90803b1561032d57846000918583614f2b9560405196879586948593630668be0d60e11b8552600485016140be565b03925af1801561041857614f40575b50614d7c565b80613ffa6000614f4f936127b8565b38614f3a565b614f686108196108196001840154610310565b614f76610819600254610310565b90803b1561032d57866000918583614fa59560405196879586948593630668be0d60e11b8552600485016140be565b03925af1801561041857614fba575b50614d76565b80613ffa6000614fc9936127b8565b38614fb4565b614fe783610b9489600052600d602052604060002090565b81614ff185610a1e565b90615058575b85615031575b8661500a575b5050614d71565b600280920161501a888254612864565b905501615028868254612864565b90553880615003565b60018201615040878254612864565b905560018101615051878254612864565b9055614ffd565b615063888354612864565b8255615070888254612864565b8155614ff7565b50841515614d6c565b50831515614d65565b508415614d58565b508315614d52565b6150b391935060203d602011611fe557611fd781836127b8565b9138614cd8565b80613ffa60006150c9936127b8565b38614ca4565b6150d890610a8c565b600481015460019060081c60ff166150ef81610731565b03612c0257615104612cbf6001830154610310565b60038201908154158015615224575b614c09576008830192615127845442612c4b565b8015612beb5761513d614b206002840154612a04565b60058401546301e133809004936151616007612d9360068401546301e13380900490565b948383826151ec575b909150826151b4575b50505083615185575050505050429055565b61519e612d0d600792612d08612b5395614b9b98612a22565b9201936151ac855493612a04565b905490612a35565b612d08612d0d926151c494612a22565b6151e26006850191612b536151da845492612a04565b895490612a35565b9055388282615173565b612d08612d0d926151fc94612a22565b61521a6005860191612b53615212845492612a04565b8a5490612a35565b905538838361516a565b50600881015415615113565b9061523a82610a8c565b600481015460019060081c60ff1661525181610731565b036156285761525f836150cf565b61526c82610b9485610abc565b916005820154906001840192615283845484612c4b565b94615293612d0d82548098612a22565b95600683018054906152b2612d0d84612d086002880195865490612c4b565b966152d0612d0d6007880195612d0860038854990198895490612c4b565b985554905554905584158080615620575b80615618575b614a64578015809161560f575b8015615606575b61555e575b6154e4575b8261546a575b83151580615448575b615354575b506129947facd564f3e3cce2098aa0e23ad6930e6b15a566ba02994564aa384f13c781006b9360405193849360018060a01b031696846106c7565b6108196108196001615367930154610310565b615375610819600454610310565b90803b1561032d57846000916153a49383604051809681958294630668be0d60e11b84523090600485016140be565b03925af1801561041857615433575b506153c2610819600454610310565b803b1561032d57604051632e1a7d4d60e01b815260048101859052906000908290602490829084905af180156104185761541e575b506000808080866001600160a01b0386165af16154126140e0565b50156142ce5738615319565b80613ffa600061542d936127b8565b386153f7565b80613ffa6000615442936127b8565b386153b3565b506004546001600160a01b03906154629061081990610310565b161515615314565b61547d6108196108196001840154610310565b61548b610819600354610310565b90803b1561032d578460009185836154ba9560405196879586948593630668be0d60e11b8552600485016140be565b03925af18015610418576154cf575b5061530b565b80613ffa60006154de936127b8565b386154c9565b6154f76108196108196001840154610310565b615505610819600254610310565b90803b1561032d578660009185836155349560405196879586948593630668be0d60e11b8552600485016140be565b03925af1801561041857615549575b50615305565b80613ffa6000615558936127b8565b38615543565b61557683610b9489600052600d602052604060002090565b8161558085610a1e565b906155e7575b856155c0575b86615599575b5050615300565b60028092016155a9888254612864565b9055016155b7868254612864565b90553880615592565b600182016155cf878254612864565b9055600181016155e0878254612864565b905561558c565b6155f2888354612864565b82556155ff888254612864565b8155615586565b508415156152fb565b508315156152f4565b5084156152e7565b5083156152e1565b63f539349760e01b60005260046000fd5b919061564483610a8c565b90615657600483015460ff9060081c1690565b61566081610731565b610d535761567181610b9486610abc565b9183156122a257825484116122915761568d82610b9487610a9c565b9283546118a8576156a46108a96001840154610310565b6156ae8387614680565b6156bb6108198354610310565b6156cc610819610819600254610310565b6001600160a01b03909116146158d6575b6156ea6108198354610310565b6156fb610819610819600254610310565b9060018060a01b0316141590615712868254612c4b565b81558160038401615724888254612c4b565b90556158b4575b60098301546004820155600a83015460058201556006600b84015491015584601254156157ee578160028661577793600080516020615d79833981519152985542600182015501612845565b600d8201615786868254612864565b905561579186610aac565b61579c868254612864565b90556157cb575b506157b060125442612864565b6040516001600160a01b0390921693829161299491836133ba565b610c776108196157db9254610310565b6157e6848254612864565b9055386157a3565b600080516020615d998339815191529450615842915083610c958461581a610819612994989754610310565b61582b610819610819600254610310565b6001600160a01b03821614615882575b5054610310565b60018060a01b0316928484600080516020615d398339815191526040518061586f86829190602083019252565b0390a36040519081529081906020820190565b61588b9061099c565b615896858254612c4b565b90556158a1836109b6565b6158ac858254612c4b565b90553861583b565b6158c46117b26108198554610310565b6158cf878254612c4b565b905561572b565b6158df86612a55565b6158e88361411f565b6156dd565b906140b7906159156140bc956040519586936323b872dd60e01b6020860152602485016140be565b03601f1981018452836127b8565b60009060009060009061593a610819600254610310565b6040516370a0823160e01b8152906020828061595930600483016105ec565b0381845afa91821561041857600092615abc575b5080613e9e613e9761597e9361099c565b90818111615aa9575b5050615997610819600354610310565b6040516370a0823160e01b815290602082806159b630600483016105ec565b0381845afa91821561041857600092615a84575b5080613e9e613e976159db9361099c565b90818111615a71575b50506159f4610819600454610310565b6001600160a01b03811615614006576040516370a0823160e01b815260208180615a2130600483016105ec565b0381855afa90811561041857613f8391615a4591600091615a52575b504790612864565b91613e9e613e978261099c565b615a6b915060203d602011611fe557611fd781836127b8565b38615a3d565b615a7c929450612c4b565b9138806159e4565b6159db919250615aa29060203d602011611fe557611fd781836127b8565b91906159ca565b615ab4929550612c4b565b923880615987565b61597e919250615ada9060203d602011611fe557611fd781836127b8565b919061596d565b615aea90610a8c565b600481015460081c60ff16615afe81610731565b612c0257615b12612cbf6001830154610310565b60038201908154158015615c16575b615c0c57600c830192615b35845442612c4b565b8015612beb57615b4b614b206002840154612a04565b60058401546301e13380900493615b6f6007612d9360068401546301e13380900490565b94838382615bdc575b90915082615bac575b50505083615b93575050505050429055565b61519e612d0d600b92612d08612b5395614b9b98612a22565b612d08612d0d92615bbc94612a22565b615bd2600a850191612b536151da845492612a04565b9055388282615b81565b612d08612d0d92615bec94612a22565b615c026009860191612b53615212845492612a04565b9055388383615b78565b5050600c42910155565b50600881015415615b21565b9091828214615c93578115615cd65781615c3f613ad58383612a22565b91159182158080615ccd575b15615c9b5750615c5a91612864565b831115615c93575b615c6d575050600190565b615c7681612856565b8211918215615c8457505090565b615c8f919250612856565b1090565b505050600090565b80615cc4575b615cad575b5050615c62565b615cb79085612864565b1015615c93578138615ca6565b50818510615ca1565b50828611615c4b565b5050151590565b906000602091828151910182855af1156127f5576000513d615d2f57506001600160a01b0381163b155b615d0e5750565b635274afe760e01b60009081526001600160a01b0391909116600452602490fd5b60011415615d0756fe144424c1e710ba35ccb0319d0fe39227dfea5b78aaa426661ad54ebbed3e790b60dc412aff8039463644dbff180c6be3ff23f0595251da61b1f2ac26fbf6fa0e88bf5c4a0d372ab0014553e8af551b5aa4c534746f1d22bd1f4514d985c3e784f960dbf9e5d0682f7a298ed974e33a28b4464914b7a2bfac12ae419a9afeb280dcd53842d284e15eee6bbf1c7a17cd4971b03ba6ac761728f78c0e8a51527811a2646970667358221220b2f616c8deafd2e4e766bf0dc30c4485f3504c76f965af13fd821fb27bd8171f64736f6c634300081a003360803461010f57601f61060038819003918201601f19168301916001600160401b038311848410176101145780849260209460405283398101031261010f57516001600160a01b0381169081900361010f57600180546001600160a01b031990811673a1077a294dde1b09bb078844df40758a5d0f9a271790915560028054821673d34f5adc24d8cc55c1e832bdf65fffdf80d1314f1790556003805482167379bb3a0ee435f957ce4f54ee8c3cfadc7278da0c17905560048054909116737783d7040423f75aef82a3ec32ed366ca460fa6c17905580156100fe57600080546001600160a01b0319169190911790556040516104d5908161012b8239f35b63e6c4247b60e01b60005260046000fd5b600080fd5b634e487b7160e01b600052604160045260246000fdfe60806040526004361015610047575b361561001957600080fd5b6040513481527f8ac633e5b094e1150d2a6495df4d0c77f51d293abe99e7733c78870dfbee766060203392a2005b60003560e01c80630cd17c1a146102725780635d3590d51461015d5780637d40af9814610142578063bec2825f14610119578063c88bbb58146100f0578063f77c4791146100c75763fed810360361000e57346100c25760003660031901126100c2576003546040516001600160a01b039091168152602090f35b600080fd5b346100c25760003660031901126100c2576000546040516001600160a01b039091168152602090f35b346100c25760003660031901126100c2576002546040516001600160a01b039091168152602090f35b346100c25760003660031901126100c2576001546040516001600160a01b039091168152602090f35b346100c25760003660031901126100c25761015b61036d565b005b346100c25761016b366102fa565b906024602060018060a01b036004541660405192838092630935e01b60e21b82523360048301525afa90811561026657600091610224575b5015610213576002546001600160a01b039384169316831480156101ff575b80156101eb575b6101d65761015b9261040e565b82635f8b555b60e11b60005260045260246000fd5b506001546001600160a01b031683146101c9565b506003546001600160a01b031683146101c2565b637bfa4b9f60e01b60005260046000fd5b6020813d60201161025e575b8161023d60209383610334565b8101031261025a57519081151582036102575750846101a3565b80fd5b5080fd5b3d9150610230565b6040513d6000823e3d90fd5b346100c257610280366102fa565b6000549092906001600160a01b031633036102e95760207f1274f3225f379d2c168ab30ede4b7fd1e7481118755d7e76df6cb12cad0fc916916102c161036d565b6001600160a01b0316926102d685828661040e565b6040519485526001600160a01b031693a3005b6323019e6760e01b60005260046000fd5b60609060031901126100c2576004356001600160a01b03811681036100c257906024356001600160a01b03811681036100c2579060443590565b601f909101601f19168101906001600160401b0382119082101761035757604052565b634e487b7160e01b600052604160045260246000fd5b6001546001600160a01b0316600081151580610405575b61038c575050565b4791803b1561025a57818391600460405180948193630d0e30db60e41b83525af180156103fa57917f3726d2a921b044fa7c08115b7588e09652cbb8122294bbc71f80557b07b1842193916020936103ea575b5050604051908152a1565b816103f491610334565b386103df565b6040513d84823e3d90fd5b50471515610384565b60405163a9059cbb60e01b60208281019182526001600160a01b039094166024830152604480830195909552938152909260009161044d606482610334565b519082855af115610266576000513d61049657506001600160a01b0381163b155b6104755750565b635274afe760e01b60009081526001600160a01b0391909116600452602490fd5b6001141561046e56fea26469706673582212204dfff69b4762b005d0f590671c3d240ae939192d34a0438d64a069cd439e901864736f6c634300081a003360803461010f57601f61060038819003918201601f19168301916001600160401b038311848410176101145780849260209460405283398101031261010f57516001600160a01b0381169081900361010f57600180546001600160a01b031990811673a1077a294dde1b09bb078844df40758a5d0f9a271790915560028054821673d34f5adc24d8cc55c1e832bdf65fffdf80d1314f1790556003805482167379bb3a0ee435f957ce4f54ee8c3cfadc7278da0c17905560048054909116737783d7040423f75aef82a3ec32ed366ca460fa6c17905580156100fe57600080546001600160a01b0319169190911790556040516104d5908161012b8239f35b63e6c4247b60e01b60005260046000fd5b600080fd5b634e487b7160e01b600052604160045260246000fdfe60806040526004361015610047575b361561001957600080fd5b6040513481527f8ac633e5b094e1150d2a6495df4d0c77f51d293abe99e7733c78870dfbee766060203392a2005b60003560e01c80630cd17c1a146102725780635d3590d51461015d578063bec2825f14610134578063c88bbb581461010b578063f77c4791146100e2578063fed81036146100b95763fff6cae90361000e57346100b45760003660031901126100b4576100b261036d565b005b600080fd5b346100b45760003660031901126100b4576003546040516001600160a01b039091168152602090f35b346100b45760003660031901126100b4576000546040516001600160a01b039091168152602090f35b346100b45760003660031901126100b4576002546040516001600160a01b039091168152602090f35b346100b45760003660031901126100b4576001546040516001600160a01b039091168152602090f35b346100b45761016b366102fa565b906024602060018060a01b036004541660405192838092630935e01b60e21b82523360048301525afa90811561026657600091610224575b5015610213576002546001600160a01b039384169316831480156101ff575b80156101eb575b6101d6576100b29261040e565b82635f8b555b60e11b60005260045260246000fd5b506001546001600160a01b031683146101c9565b506003546001600160a01b031683146101c2565b637bfa4b9f60e01b60005260046000fd5b6020813d60201161025e575b8161023d60209383610334565b8101031261025a57519081151582036102575750846101a3565b80fd5b5080fd5b3d9150610230565b6040513d6000823e3d90fd5b346100b457610280366102fa565b6000549092906001600160a01b031633036102e95760207f1274f3225f379d2c168ab30ede4b7fd1e7481118755d7e76df6cb12cad0fc916916102c161036d565b6001600160a01b0316926102d685828661040e565b6040519485526001600160a01b031693a3005b6323019e6760e01b60005260046000fd5b60609060031901126100b4576004356001600160a01b03811681036100b457906024356001600160a01b03811681036100b4579060443590565b601f909101601f19168101906001600160401b0382119082101761035757604052565b634e487b7160e01b600052604160045260246000fd5b6001546001600160a01b0316600081151580610405575b61038c575050565b4791803b1561025a57818391600460405180948193630d0e30db60e41b83525af180156103fa57917f3726d2a921b044fa7c08115b7588e09652cbb8122294bbc71f80557b07b1842193916020936103ea575b5050604051908152a1565b816103f491610334565b386103df565b6040513d84823e3d90fd5b50471515610384565b60405163a9059cbb60e01b60208281019182526001600160a01b039094166024830152604480830195909552938152909260009161044d606482610334565b519082855af115610266576000513d61049657506001600160a01b0381163b155b6104755750565b635274afe760e01b60009081526001600160a01b0391909116600452602490fd5b6001141561046e56fea2646970667358221220de2b21e09c4f020ede34e476dd7ce055e223164891d2af491ade59545c719e5964736f6c634300081a00330000000000000000000000000000000000000000000000000000000069706b60000000000000000000000000d34f5adc24d8cc55c1e832bdf65fffdf80d1314f00000000000000000000000079bb3a0ee435f957ce4f54ee8c3cfadc7278da0c000000000000000000000000a1077a294dde1b09bb078844df40758a5d0f9a27

Deployed ByteCode

0x6080604052600436101561001b575b361561001957600080fd5b005b60003560e01c806303ca8c311461030b57806309410cb9146103065780630ed3d611146103015780631979f81e146102fc57806321724f43146102f757806326f8f673146102f25780632ecc6d80146102ed5780632f380b35146102e8578063379607f5146102e357806338bb1778146102de57806339ebfa5e146102d95780633b6221c7146102d4578063406e2bf8146102cf57806341e0af5a146102ca57806355fe454a146102c55780635f323c54146102c057806362e06941146102bb57806363338d7d146102b657806364482f79146102b1578063671d9dc3146102ac578063687e2baa146102a757806368e6fa29146102a25780636918f7f81461029d5780636a2dba83146102985780636dec4974146102935780637b0472f01461028e5780637f8661a114610289578063819bfd9e146102845780638b5a9d561461027f5780638cf7deea1461027a5780638d48581c146102755780638e09136f1461027057806392de5edd1461026b5780639349acd81461026657806393f1a40b146102615780639e2c8a5b1461025c578063a3485fad14610257578063a5e6aeaf14610252578063ab3c7e521461024d578063b5c7662714610248578063b8f149ff14610243578063ba635cdd1461023e578063bbb5165b14610239578063bee5e1ec14610234578063d1058e591461022f578063db0987a71461022a5763f3400c2d0361000e576126e7565b6126aa565b61252d565b6124cb565b612412565b6123e9565b6123be565b612328565b61230a565b6122ec565b6122c4565b612181565b6120f0565b61205a565b61203c565b611e3f565b611e02565b611db5565b611b97565b6119a8565b611705565b6114b5565b6113f9565b6113c9565b61139e565b611238565b611086565b611068565b610fc3565b610f18565b610e5d565b610dc7565b610d75565b610b6b565b610af8565b610acc565b610a4f565b610962565b610874565b6107d4565b6106dd565b610628565b6105ff565b61055d565b6104bc565b61041d565b61033c565b6001600160a01b031690565b6001600160a01b0381160361032d57565b600080fd5b8015150361032d57565b3461032d57608036600319011261032d576004356103598161031c565b6024356044356103688161031c565b6064359161037583610332565b604051630935e01b60e21b81523360048201526020816024817f0000000000000000000000007783d7040423f75aef82a3ec32ed366ca460fa6c6001600160a01b03165afa908115610418576000916103e9575b50156103d85761001993612871565b637bfa4b9f60e01b60005260046000fd5b61040b915060203d602011610411575b61040381836127b8565b8101906127e0565b386103c9565b503d6103f9565b6127f5565b3461032d57602036600319011261032d5760043561043a8161031c565b604051630935e01b60e21b81523360048201526020816024817f0000000000000000000000007783d7040423f75aef82a3ec32ed366ca460fa6c6001600160a01b03165afa9081156104185760009161049d575b50156103d8576100199061398c565b6104b6915060203d6020116104115761040381836127b8565b3861048e565b3461032d57602036600319011261032d57600435604051630935e01b60e21b81523360048201526020816024817f0000000000000000000000007783d7040423f75aef82a3ec32ed366ca460fa6c6001600160a01b03165afa90811561041857600091610533575b50156103d857610019906129ec565b61054c915060203d6020116104115761040381836127b8565b38610524565b600091031261032d57565b3461032d57600036600319011261032d57610576613e1a565b60135460015b81811115610598575b61058e3361411f565b6100196001600055565b6000818152600660205260409020546002546001600160a01b039081169116146105ca576105c590612817565b61057c565b6105d49150612a55565b3880610585565b6001600160a01b0316600452602490565b6001600160a01b03909116815260200190565b3461032d57600036600319011261032d576005546040516001600160a01b039091168152602090f35b3461032d57602036600319011261032d576004356106458161031c565b604051630935e01b60e21b81523360048201526020816024817f0000000000000000000000007783d7040423f75aef82a3ec32ed366ca460fa6c6001600160a01b03165afa908115610418576000916106a8575b50156103d85761001990612c05565b6106c1915060203d6020116104115761040381836127b8565b38610699565b6040919493926060820195825260208201520152565b3461032d57604036600319011261032d576107126024356004356107008261031c565b600052600d6020526040600020610a38565b805461072d60026001840154930154604051938493846106c7565b0390f35b6003111561073b57565b634e487b7160e01b600052602160045260246000fd5b9a979490919e9d9c9996939b9895929b6101c08c019f600384101561073b57928c526001600160a01b0392831660208d01529b90911660408b01526101a09a6107a3919060608c0152151560808b0152565b60a089015260c088015260e08701526101008601526101208501526101408401526101608301526101808201520152565b3461032d57602036600319011261032d5760043560005260066020526040600020600481015461072d61080b8260ff9060081c1690565b9161081e6108198554610310565b610310565b9361082c6001820154610310565b6002820154909260ff1660038301546009840154600a850154600b86015491600c87015493600588015495600689015497600860078b01549a01549a6040519e8f9e8f610751565b3461032d57602036600319011261032d57600435610890613e1a565b61089981610a8c565b6108ae6108a96001830154610310565b6145ed565b600481015460081c60ff166108c281610731565b600181036108e0575050806108d961058e926150cf565b3390615230565b806108ec600292610731565b0361090b5750806108ff61090692614a7d565b3390614c40565b61058e565b6108196109229161091c3385614680565b54610310565b610933610819610819600254610310565b6001600160a01b039091161461094a575b5061058e565b61095390612a55565b61095c3361411f565b38610944565b3461032d57604036600319011261032d5761072d61098d6024356004356109888261031c565b612c58565b604093919351938493846106c7565b6001600160a01b0316600090815260096020526040902090565b6001600160a01b03166000908152600a6020526040902090565b6001600160a01b03166000908152600f6020526040902090565b6001600160a01b0316600090815260086020526040902090565b6001600160a01b03166000908152600b6020526040902090565b6001600160a01b03166000908152600e6020526040902090565b9060018060a01b0316600052602052604060002090565b3461032d57602036600319011261032d57600435610a6c8161031c565b60018060a01b031660005260096020526020604060002054604051908152f35b6000526006602052604060002090565b600052600c602052604060002090565b6000526010602052604060002090565b6000526007602052604060002090565b3461032d57602036600319011261032d5760043560005260106020526020604060002054604051908152f35b3461032d57602036600319011261032d5760c0600435610b178161031c565b610b208161341e565b90919260018060a01b031660005260086020526040600020906001820154906005600384015493015493604051958652602086015260408501526060840152608083015260a0820152f35b3461032d57602036600319011261032d57600435610b87613e1a565b610b9933610b9483610a9c565b610a38565b8054908115610d6457610bab83610a8c565b90610bbe600483015460ff9060081c1690565b610bc781610731565b610d53576001810191610bde835460125490612864565b4210610d4257600284926000610c9a95600d8501610bfd878254612c4b565b9055610c0889610aac565b610c13878254612c4b565b90558183555501610c33610c28825460ff1690565b825460ff1916909255565b610c406108198354610310565b610c51610819610819600254610310565b6001600160a01b0390911614610d2b575b15610cc557610c7c610c776108198354610310565b6109d0565b610c87838254612c4b565b90555b610c95339154610310565b61407c565b6040519081523390600080516020615d398339815191529080602081015b0390a36100196001600055565b610cd26108198254610310565b610ce3610819610819600254610310565b6001600160a01b03821614610cf9575b50610c8a565b610d029061099c565b610d0d838254612c4b565b9055610d18336109b6565b610d23838254612c4b565b905538610cf3565b610d3486612a55565b610d3d3361411f565b610c62565b634a44555360e11b60005260046000fd5b631b3140af60e11b60005260046000fd5b6322f70c8d60e21b60005260046000fd5b3461032d57600036600319011261032d576020601254604051908152f35b60a090600319011261032d57600435610dab8161031c565b90602435906044359060643590608435610dc481610332565b90565b3461032d57610dd536610d93565b604051630935e01b60e21b81523360048201529093919291906020816024817f0000000000000000000000007783d7040423f75aef82a3ec32ed366ca460fa6c6001600160a01b03165afa90811561041857600091610e3e575b50156103d85761001994612ee6565b610e57915060203d6020116104115761040381836127b8565b38610e2f565b3461032d57608036600319011261032d57600435610e7a8161031c565b602435604435610e898161031c565b60643591610e9683610332565b604051630935e01b60e21b81523360048201526020816024817f0000000000000000000000007783d7040423f75aef82a3ec32ed366ca460fa6c6001600160a01b03165afa90811561041857600091610ef9575b50156103d85761001993612fa1565b610f12915060203d6020116104115761040381836127b8565b38610eea565b3461032d57608036600319011261032d57600435610f358161031c565b602435604435606435604051630935e01b60e21b81523360048201529092906020816024817f0000000000000000000000007783d7040423f75aef82a3ec32ed366ca460fa6c6001600160a01b03165afa90811561041857600091610fa4575b50156103d85761001993613097565b610fbd915060203d6020116104115761040381836127b8565b38610f95565b3461032d57606036600319011261032d57600435604435602435610fe682610332565b604051630935e01b60e21b81523360048201526020816024817f0000000000000000000000007783d7040423f75aef82a3ec32ed366ca460fa6c6001600160a01b03165afa90811561041857600091611049575b50156103d857610019926130ee565b611062915060203d6020116104115761040381836127b8565b3861103a565b3461032d57600036600319011261032d576020601554604051908152f35b3461032d57604036600319011261032d576004356110a38161031c565b602435906110b08261031c565b6110b8613e1a565b6001600160a01b03163381900361112b57600052601160205260406000205490811561113c576110e782610a8c565b9160026110fc600485015460ff9060081c1690565b61110581610731565b0361112b5761111d6108a9600161058e950154610310565b61112681614a7d565b614c40565b63da37af0b60e01b60005260046000fd5b63015f4fdd60e31b60005260046000fd5b9181601f8401121561032d578235916001600160401b03831161032d576020808501948460051b01011161032d57565b906020808351928381520192019060005b81811061119b5750505090565b825184526020938401939092019160010161118e565b9391926111de6111fa946111d06111ec9460a0895260a089019061117d565b90878203602089015261117d565b90858203604087015261117d565b90838203606085015261117d565b9060808183039101526020808351928381520192019060005b8181106112205750505090565b82511515845260209384019390920191600101611213565b3461032d57604036600319011261032d576004356112558161031c565b6024356001600160401b03811161032d5761127490369060040161114d565b61127d816131d5565b90611287816131d5565b92611291826131d5565b61129a836131d5565b916112a4846131d5565b9360005b8181106112c4575050509061072d9291604051958695866111b1565b806112df8a610b946112d9600195878961321d565b35610a9c565b82815491826112ee858d613232565b52015490816112fd848d613232565b526113315750600061130f8287613232565b52600061131c8288613232565b5260006113298289613232565b525b016112a8565b60125461133d91612864565b806113488388613232565b524281116113765750600061135d8288613232565b5261137161136b8289613232565b60019052565b61132b565b611381904290612c4b565b61138b8288613232565b5260006113988289613232565b5261132b565b3461032d57604036600319011261032d5761072d61098d6024356004356113c48261031c565b613255565b3461032d57604036600319011261032d576113f26024356004356113eb613e1a565b3390615639565b6001600055005b3461032d57602036600319011261032d576004356114168161031c565b60018060a01b0316600052600b6020526040600020805461072d600183015492600281015490600381015460048201546005830154906006840154926008600786015495015495604051998960ff808d9c60081c1691168b9693909a9998959261012098959261014089019c151589521515602089015260408801526060870152608086015260a085015260c084015260e08301526101008201520152565b3461032d57604036600319011261032d576004356024356114d4613e1a565b6114dd82610a8c565b600481019081546114f56114f18260ff1690565b1590565b6116f45760029060081c60ff1661150b81610731565b146116e3576115206108a96001830154610310565b815460019060081c60ff1661153481610731565b0361169457611542846150cf565b61154c3385615230565b6115638361155a8354610310565b309033906158ed565b60038101611572848254612864565b90556115816108198254610310565b61159d611597856115918461099c565b54612864565b9161099c565b5560016115f46115b033610b9488610abc565b936115bc868654612864565b85556115cb6108198554610310565b6115dc610819610819600254610310565b90848060a01b031614611678575b5460081c60ff1690565b6115fd81610731565b03611655576007816005600393015460018501556006810154600285015501549101555b60405190815233907f5af417134f72a9d41143ace85b0a26dce6f550f894f2cbc1eeee8810603d91b6908060208101610cb8565b600b81600960069301546004850155600a81015460058501550154910155611621565b61168586611591336109b6565b61168e336109b6565b556115ea565b61169e3385614680565b6116ab6108198254610310565b6116bc610819610819600254610310565b6001600160a01b039091160361154c576116d584612a55565b6116de3361411f565b61154c565b63e96142b160e01b60005260046000fd5b6338c0a90160e11b60005260046000fd5b3461032d57602036600319011261032d57600435611721613e1a565b61172a81610a8c565b61173d61173683610abc565b3390610a38565b908154918215611997576004820154839060081c60ff1661175d81610731565b158061198c575b156118b9575061177733610b9486610a9c565b9081546118a8578261180a6002610c7794600061081995600361183799016117a08b8254612c4b565b90556117b76117b26108198854610310565b61099c565b6117c28b8254612c4b565b90556117d16108198754610310565b6117e16108196108198754610310565b6001600160a01b0390911614611870575b5587815542600182015501600160ff19825416179055565b600d8101611819868254612864565b905561182486610aac565b61182f868254612864565b905554610310565b611842828254612864565b9055600080516020615d79833981519152610cb861186260125442612864565b6040519182913395836133ba565b611879336109b6565b6118848b8254612c4b565b905561188f336109ea565b60145481556015548582015560046016549101556117f2565b63b76ac96760e01b60005260046000fd5b9091600061193193600383016118d0858254612c4b565b90556118df6108198454610310565b6118f5611597866118ef8461099c565b54612c4b565b556119036108198454610310565b611914610819610819600254610310565b6001600160a01b0390911614611952575b55610c95339154610310565b6040519081523390600080516020615d9983398151915290602090a361058e565b61195f846118ef336109b6565b611968336109b6565b55611972336109ea565b601454815560155460028201556004601654910155611925565b506012541515611764565b639fe7bfd960e01b60005260046000fd5b3461032d57602036600319011261032d576004356119c4613e1a565b6119d133610b9483610a9c565b8054908115610d64576119e383610a8c565b600481015460081c60ff166119f781610731565b610d5357600b81611a106108a960016006950154610310565b611a1986615ae1565b611a6c6002850160006001611a2f835460ff1690565b97600d8601611a3f8b8254612c4b565b905588611a4b8c610aac565b611a568c8254612c4b565b9055611b50575b8281550155805460ff19169055565b611a7933610b9488610abc565b93611a85868654612864565b855560038201611a96878254612864565b9055611aea575b60098101546004850155600a8101546005850155015491015560405190815233907f9580ac8befa235ac705ab43a31830cbda760282bdbe4644eec9abd39a973a4d6908060208101610cb8565b611afa6117b26108198354610310565b611b05868254612864565b9055611b146108198254610310565b611b25610819610819600254610310565b6001600160a01b0390911603611a9d57611b3e336109b6565b611b49868254612864565b9055611a9d565b611b60610c776108198854610310565b611b6b8b8254612c4b565b9055611a5d565b9091611b89610dc49360408452604084019061117d565b91602081840391015261117d565b3461032d57602036600319011261032d576004356001600160401b03811161032d57611bc790369060040161114d565b90611bd0613e1a565b611bd9826131d5565b90611be3836131d5565b926000916000915b808310611c13575050508082528252611c046001600055565b61072d60405192839283611b72565b909192611c2184838561321d565b35611c2f33610b9483610a9c565b908154918215611da9576001810190611c4c825460125490612864565b4210611d9c57611c5b83610a8c565b91611c6e600484015460ff9060081c1690565b611c7781610731565b611d8e578483600260019896946000611d0795600d8c9b9901611c9b878254612c4b565b9055611ca688610aac565b611cb1878254612c4b565b90558183555501611cc6610c28825460ff1690565b611cd36108198354610310565b611ce4610819610819600254610310565b90898060a01b031614611d77575b15611d4657610c7c610c776108198354610310565b60405182815281903390600080516020615d3983398151915290602090a3611d2f838a613232565b52611d3a828a613232565b5201935b019190611beb565b611d536108198254610310565b611d64610819610819600254610310565b888060a01b03821614610cf95750610c8a565b611d8085612a55565b611d893361411f565b611cf2565b505050505092600190611d3e565b5050505092600190611d3e565b50505092600190611d3e565b3461032d57602036600319011261032d57600435611dd28161031c565b60018060a01b0316600052600e6020526040600020805461072d60026001840154930154604051938493846106c7565b3461032d57602036600319011261032d57600435611e1f8161031c565b60018060a01b031660005260116020526020604060002054604051908152f35b3461032d57602036600319011261032d57600435611e5c8161031c565b60008081829083918460016013545b80821115611ecb575050611e8361072d95969761341e565b9591939094604051998a998a95926101009794919a9998959261012088019b8852602088015260408701526060860152608085015260a084015260c083015260e08201520152565b9091949288611ed984610a8c565b600481015460081c60ff16611eed81610731565b60018103611f49575050611f0490610b9485610abc565b5415611f3d57611f30611f2a611f2a611f3793611f218d88612c58565b94919092612864565b97612864565b925b612817565b90611e6b565b929491611f3790612817565b80611f55600292610731565b03611fec57611f8e91611f7361081961081961081960209554610310565b604051808095819463673e156160e11b8352600483016105ec565b03915afa90811561041857600091611fbe575b5015611f3d57611f30611f2a611f2a611f3793611f218d88613255565b611fdf915060203d8111611fe5575b611fd781836127b8565b810190613246565b38611fa1565b503d611fcd565b5061200190610b9485979a9993969895610abc565b54156120305761202a61201e612024611f3793611f218d8a6135f7565b9a612864565b99612864565b94612817565b959693611f3790612817565b3461032d57600036600319011261032d576020601454604051908152f35b3461032d57602036600319011261032d57600435604051630935e01b60e21b81523360048201526020816024817f0000000000000000000000007783d7040423f75aef82a3ec32ed366ca460fa6c6001600160a01b03165afa908115610418576000916120d1575b50156103d857610019906133cb565b6120ea915060203d6020116104115761040381836127b8565b386120c2565b3461032d57604036600319011261032d576121256024356004356121138261031c565b60005260076020526040600020610a38565b805461072d600183015492600281015490600381015460048201549060066005840154930154936040519788978893909796959260c0959260e08601998652602086015260408501526060840152608083015260a08201520152565b3461032d57604036600319011261032d576004356024356121a0613e1a565b6121a982610a8c565b6121b561173684610abc565b906121c8600482015460ff9060081c1690565b6121d181610731565b156122b35782156122a25782825410612291576007816121f96108a960016003950154610310565b612202866150cf565b61220c3387615230565b61221b8533610c958454610310565b828101612229868254612c4b565b90556122386108198254610310565b612248611597876118ef8461099c565b55612254858554612c4b565b8455600581015460018501556006810154600285015501549101556040519081523390600080516020615d99833981519152908060208101610cb8565b632360e66f60e21b60005260046000fd5b6365e52d5160e11b60005260046000fd5b6306fe23cd60e51b60005260046000fd5b3461032d57602036600319011261032d5761072d61098d6004356122e78161031c565b61341e565b3461032d57600036600319011261032d576020601654604051908152f35b3461032d57600036600319011261032d576020601354604051908152f35b3461032d5761233636610d93565b604051630935e01b60e21b81523360048201529093919291906020816024817f0000000000000000000000007783d7040423f75aef82a3ec32ed366ca460fa6c6001600160a01b03165afa9081156104185760009161239f575b50156103d85761001994613554565b6123b8915060203d6020116104115761040381836127b8565b38612390565b3461032d57604036600319011261032d5761072d61098d6024356004356123e48261031c565b6135f7565b3461032d57600036600319011261032d576001546040516001600160a01b039091168152602090f35b3461032d57604036600319011261032d5761244760243560406004356124378361031c565b6000908152600c60205220610a38565b6001815491015490801560001461248d5761072d600080815b6040519586958693909594919260809360a086019786526020860152604085015260608401521515910152565b60125482018083116124c657804281116124b05761072d91506000600191612460565b4282039182116124c65761072d91600091612460565b612801565b3461032d57602036600319011261032d576004356124e88161031c565b60018060a01b0316600052600b602052608060406000206005810154906006810154906008600782015491015491604051938452602084015260408301526060820152f35b3461032d57600036600319011261032d57612546613e1a565b60015b601354811161058e5761255b81610a8c565b61256b6108a96001830154610310565b600481015460081c60ff1661257f81610731565b600181036125b7575050806125996117366125b293610abc565b5415611f32576125a8816150cf565b611f323382615230565b612549565b806125c3600292610731565b03612649576108196108196108196125db9354610310565b906020604051809363673e156160e11b825281806125fc33600483016105ec565b03915afa8015610418576125b29260009161262b575b5015611f325761262181614a7d565b611f323382614c40565b612643915060203d8111611fe557611fd781836127b8565b38612612565b906125b29161265a61173683610abc565b54156126a4576108196126719161091c3385614680565b612682610819610819600254610310565b6001600160a01b0390911603611f325761269b81612a55565b611f323361411f565b50612817565b3461032d57602036600319011261032d576004356126c78161031c565b60018060a01b0316600052600a6020526020604060002054604051908152f35b3461032d57608036600319011261032d576004356127048161031c565b6024356127108161031c565b6044356064359161272083610332565b604051630935e01b60e21b81523360048201526020816024817f0000000000000000000000007783d7040423f75aef82a3ec32ed366ca460fa6c6001600160a01b03165afa90811561041857600091612783575b50156103d857610019936137f7565b61279c915060203d6020116104115761040381836127b8565b38612774565b634e487b7160e01b600052604160045260246000fd5b601f909101601f19168101906001600160401b038211908210176127db57604052565b6127a2565b9081602091031261032d5751610dc481610332565b6040513d6000823e3d90fd5b634e487b7160e01b600052601160045260246000fd5b60001981146124c65760010190565b80546001600160a01b0319166001600160a01b03909216919091179055565b9060ff801983541691151516179055565b90600182018092116124c657565b919082018092116124c657565b6001600160a01b0381169391929084156129c757803b156129d8576001600160a01b038216156129c757813b156129af5761295a826008926128d47ff689203c966f70583b50d911d766ab0ecc2a966cd769b108a7f055d5a5a7953896956138ff565b61293860046128f56128e7601354612817565b6128f081601355565b610a8c565b6128ff8b82612826565b61290c8560018301612826565b896002820155428782015560006003820155016129298782612845565b805461ff001916610200179055565b6013546001600160a01b03909116600090815260116020526040902055610a04565b6129686114f1825460ff1690565b612999575b01612979848254612864565b90556013546040805194855291151560208501529290819081015b0390a3565b805460ff1916600117815542600482015561296d565b63b5cf5b8f60e01b6000526129c3826105db565b6000fd5b63d92e233d60e01b60005260046000fd5b63b5cf5b8f60e01b6000526129c3906105db565b6129fd906129f8613e1a565b612a55565b6001600055565b9064e8d4a5100082029180830464e8d4a5100014901517156124c657565b818102929181159184041417156124c657565b8115612a3f570490565b634e487b7160e01b600052601260045260246000fd5b61081961091c612a6492610a8c565b612a72610819600254610310565b90612a7c82610310565b6001600160a01b0390911603612c0257612a959061099c565b548015612c0257612aa4613e3c565b928291921590818092612bfa575b80612bf2575b612beb57811580612bbc575b8415159081612b8d575b8615159283612b37575b5092612b2f575b508115612b27575b50612af157505050565b612b227f03496c6e2a2d21afdf685b8a8bac6a73315ee13ed95156e776e20b5838f5a30e93604051938493846106c7565b0390a1565b905038612ae7565b915038612adf565b612b59612b5e91612b5360165491612b4e8c612a04565b612a35565b90612864565b601655565b612b8787612b73610819610819600454610310565b612b81610819600154610310565b9061407c565b38612ad8565b612ba8612ba3601554612b5386612b4e8b612a04565b601555565b612bb786612b73600354610310565b612ace565b612bd7612bd2601454612b5385612b4e89612a04565b601455565b612be684612b73600254610310565b612ac4565b5050505050565b508415612ab8565b508315612ab2565b50565b600580546001600160a01b0319166001600160a01b039290921691821790557f1fcf35f04a5b25cdc6b8e722590db86da086bb256cf7ad9f3d131e4f7ed07c4c600080a2565b919082039182116124c657565b9190612c6383610a8c565b926001612c78600486015460ff9060081c1690565b612c8181610731565b03612ea25790610b94612c9392610abc565b9081548015612e965760058401549360068101549484600783015492612cc4612cbf6001830154610310565b610a04565b60038201549182151580612e89575b612d2d575b505050612d0d926003612d24612d0d87612d08612d18612d0d83612d08610dc49d9b6001612d089c015490612c4b565b612a22565b64e8d4a51000900490565b9c60028d015490612c4b565b97015490612c4b565b612d3b600882015442612c4b565b9081612d48575b50612cd8565b612d6891929394506002612d5d910154612a04565b600884015490612a35565b91612d7b60058201546301e13380900490565b90612da06007612d9360068401546301e13380900490565b9201546301e13380900490565b9180612e65575b5080612e22575b509388612d0894612d0d979489979485610dc49b96612dd9575b505050509381959750839650612d42565b86612d08612d24976001612e14612d0d999c612b5360039d9a612b4e612e0f612d0d612d089d612d08612d189e612d0d9e612a22565b612a04565b9b9850509750509650612dc8565b848484612e548b99959e612b538f969a612b4e610dc49f9a612d0d9f9c612d0d90612d089f612e0f93612d0891612a22565b9d9498509499509497509450612dae565b95612b5386612b4e612e0f612d0d89612d088a612e82999e612a22565b9438612da7565b5060088201541515612cd3565b50600092508291508190565b50600092508291829150565b9061ff00825491151560081b169061ff001916179055565b926060929594919560808501968552602085015260408401521515910152565b9093612ef182610a04565b805490919060ff1615612f9057618e948411612f7f5760648511612f6e577f8f431beef2454b875352c7cca935b7977bb1e8a1786cc427b21fb3658ae0ec6394612f508284896001612f69970155876002820155836003820155612eae565b6040516001600160a01b03909416969394859485612ec6565b0390a2565b63e56d58cf60e01b60005260046000fd5b63971a803560e01b60005260046000fd5b631d51ca5b60e11b60005260046000fd5b6001600160a01b03811693919290919084156129c757843b15613083576001600160a01b038116156129c757803b156129d857612fe5610819610819600254610310565b85146130725761295a81612cbf60047fda69ac0b47fc0c71cff6468d04caf4baaf54677b77a1235772fd8368a23f45b2966130216008966138ff565b6130396130326128e7601354612817565b9182612826565b6130468460018301612826565b886002820155428682015560006003820155016130638682612845565b805461ff001916610100179055565b633fbade9b60e21b60005260046000fd5b63b5cf5b8f60e01b6000526129c3856105db565b6001600160a01b03166000818152600b602052604090208054919493929160ff1615612f905783600080516020615db983398151915294600783856005612f699601558660068201550155604051938493846106c7565b91601354831161113c5761313781600461310786610a8c565b856001820161311e6131198254610310565b6138ff565b6002830190815490838203613161575b50505501612845565b1515917fec70f7b7f8beefa9ff0456053baafec83986e3915f156e2ed04b0acb57d7dd55600080a4565b612cbf61316e9154610310565b90838181111561319e575050613194600861318a845486612c4b565b9201918254612864565b90555b388061312e565b6131ad6008916131b793612c4b565b9201918254612c4b565b9055613197565b6001600160401b0381116127db5760051b60200190565b906131df826131be565b6131ec60405191826127b8565b82815280926131fd601f19916131be565b0190602036910137565b634e487b7160e01b600052603260045260246000fd5b919081101561322d5760051b0190565b613207565b805182101561322d5760209160051b010190565b9081602091031261032d575190565b9161325f83610a8c565b916002613274600485015460ff9060081c1690565b61327d81610731565b03612e96576132956108196108196108198654610310565b906040519463673e156160e11b8652602086806132b585600483016105ec565b0381865afa92831561041857600496600094613398575b5060209060405197888092633a98ef3960e01b82525afa95861561041857600096613377575b5082156133665790610b9461330692610abc565b92600581015484600683015496600784015493613329612cbf6001830154610310565b9082151580612e8957612d2d57505050612d0d926003612d24612d0d87612d08612d18612d0d83612d08610dc49d9b6001612d089c015490612c4b565b505050915050600090600090600090565b61339191965060203d602011611fe557611fd781836127b8565b94386132f2565b60209194506133b390823d8411611fe557611fd781836127b8565b93906132cc565b908152602081019190915260400190565b62127500811161340d577faa1e10941c3aafb56ad74dad40ea5ec52cf44d83495362e44c775124edb040f59060125481601255612b22604051928392836133ba565b631c3c41f160e31b60005260046000fd5b90613428826109b6565b5491821561354957613439906109ea565b9061344b6117b2610819600254610310565b5492601454936015549484601654928061348b575b50612d0d926004612d24612d0d87612d08612d18612d0d83612d08610dc49d9b612d089b5490612c4b565b9050613495615923565b9180613530575b5080613500575b509284610dc4959388612d089487612d0d986134c8575b505093509350945092613460565b612d18612d0d86612d08612d24976134f1612d0d989b612b5360049c99612b4e612d089a612a04565b9a9750975050965050506134ba565b9480938884613521612d0d98959c612b53612d0898612b4e610dc49d612a04565b9b9497509450509395506134a3565b93612b5384612b4e6135429497612a04565b923861349c565b506000915081908190565b6001600160a01b038116949085156129c75761356f90610a04565b9061357e6114f1835460ff1690565b6135e1575b618e948411612f7f5760648511612f6e577f9d27ba522132b33ab70fcfdab90aea87b84ed6147139f6a5fef95b15fd1f9687946135d58284866001612f69970155876002820155836003820155612eae565b60405194859485612ec6565b815460ff19166001178255426004830155613583565b919061360283610a8c565b92613615600485015460ff9060081c1690565b61361e81610731565b612ea25790610b9461362f92610abc565b9081548015612e9657600984015493600a8101549484600b8301549261365b612cbf6001830154610310565b600382015491821515806137ea575b6136ab575b505050612d0d926006612d24612d0d87612d0861369f612d0d83612d08610dc49d9b6004612d089c015490612c4b565b9c60058d015490612c4b565b6136b9600c82015442612c4b565b90816136c6575b5061366f565b6136db91929394506002612d5d910154612a04565b916136ee60058201546301e13380900490565b906137066007612d9360068401546301e13380900490565b91806137c6575b5080613783575b509388612d0894612d0d979489979485610dc49b9661373f575b5050505093819597508396506136c0565b86612d08612d24976004613775612d0d999c612b5360069d9a612b4e612e0f612d0d612d089d612d0861369f9e612d0d9e612a22565b9b985050975050965061372e565b8484846137b58b99959e612b538f969a612b4e610dc49f9a612d0d9f9c612d0d90612d089f612e0f93612d0891612a22565b9d9498509499509497509450613714565b95612b5386612b4e612e0f612d0d89612d088a6137e3999e612a22565b943861370d565b506008820154151561366a565b6001600160a01b0381169392919084156129c757843b15613083576001600160a01b038216156129c757813b156129af576138a78260089261385a7f5a1ab27da2e22f0200f305e180a2e00bd4369d22cd036b19d02e987a16ce76f096956138ff565b61386b6130326128e7601354612817565b6138788260018301612826565b84600282015560006003820155613893600482019788612845565b865461ff0019168755600c42910155610a04565b6138b56114f1825460ff1690565b6138e9575b016138c6828254612864565b905560135492546040805192835260ff9091161515602083015281908101612994565b805460ff191660011781554260048201556138ba565b6013549060015b8281111561391357505050565b8061392061396492610a8c565b61392d6001820154610310565b6001600160a01b038581169116036126a4576004015460081c60ff1661395281610731565b600181036139695750611f32816150cf565b613906565b80613975600292610731565b0361398357611f3281614a7d565b611f3281615ae1565b61399581610a04565b906139a46114f1835460ff1690565b613ba8574260048301556139c2610819610819610819600254610310565b91602060405180946370a0823160e01b825281806139e387600483016105ec565b03915afa92831561041857600093613b87575b50613a0b610819610819610819600354610310565b91602060405180946370a0823160e01b82528180613a2c86600483016105ec565b03915afa92831561041857600093613b66575b50613a4e610819600454610310565b6001600160a01b03811615613b3957610819613a6991610310565b602060405180926370a0823160e01b82528180613a8987600483016105ec565b03915afa938415610418576007613ae8613ad5613ad5613ae2613ad5600080516020615db98339815191529a612f6998600091613b1a575b509b5b613adc60028c015494858093612a22565b6064900490565b97612a22565b99612a22565b600586019283556006860197885594018490555494546040516001600160a01b039093169592938493909190846106c7565b613b33915060203d602011611fe557611fd781836127b8565b38613ac1565b50612f69600080516020615db9833981519152936007613ae8613ad5613ad5613ae2613ad560009b613ac4565b613b8091935060203d602011611fe557611fd781836127b8565b9138613a3f565b613ba191935060203d602011611fe557611fd781836127b8565b91386139f6565b5050565b613bb581610a04565b613bc36114f1825460ff1690565b613ba857426004820155613be1610819610819610819600254610310565b91602060405180946370a0823160e01b82528180613c0286600483016105ec565b03915afa92831561041857600093613df9575b50613c2a610819610819610819600354610310565b90602060405180936370a0823160e01b82528180613c4b86600483016105ec565b03915afa91821561041857600092613dd8575b50613c6d610819600454610310565b6001600160a01b03811615613dc057610819613c8891610310565b602060405180926370a0823160e01b82528180613ca887600483016105ec565b03915afa801561041857613ad5613cdf613ad5613ad593613ce595600091613da1575b50985b613adc60028a015494858093612a22565b96612a22565b6000906005850194855494613d01600383019682885491615c22565b613d95575b506006810196613d1a885482885491615c22565b613d88575b506007613d33910194828654915491615c22565b613d7d575b50613d44575b50505050565b613d71600080516020615db983398151915293549454925460405193849360018060a01b031696846106c7565b0390a238808080613d3e565b835550600138613d38565b8755600192506007613d1f565b86556001925038613d06565b613dba915060203d602011611fe557611fd781836127b8565b38613ccb565b50613ce5613ad5613ad5613cdf613ad5600098613cce565b613df291925060203d602011611fe557611fd781836127b8565b9038613c5e565b613e1391935060203d602011611fe557611fd781836127b8565b9138613c15565b600260005414613e2b576002600055565b633ee5aeb560e01b60005260046000fd5b600090600090600090613e53610819600254610310565b6040516370a0823160e01b81529060208280613e7230600483016105ec565b0381845afa91821561041857600092614057575b5080613e9e613e97613ea59361099c565b54916109d0565b5490612864565b90818111614044575b5050613ebe610819600354610310565b6040516370a0823160e01b81529060208280613edd30600483016105ec565b0381845afa9182156104185760009261401f575b5080613e9e613e97613f029361099c565b9081811161400c575b5050613f1b610819600454610310565b6001600160a01b038116156140065747613fbf575b50613f3f610819600454610310565b6040516370a0823160e01b81529060208280613f5e30600483016105ec565b0381845afa91821561041857600092613f9a575b5080613e9e613e97613f839361099c565b90818111613f8f575050565b610dc4929350612c4b565b613f83919250613fb89060203d602011611fe557611fd781836127b8565b9190613f72565b4790803b1561032d57600090600460405180948193630d0e30db60e41b83525af180156104185715613f305780613ffa6000614000936127b8565b80610552565b38613f30565b50479150565b614017929450612c4b565b913880613f0b565b613f0291925061403d9060203d602011611fe557611fd781836127b8565b9190613ef1565b61404f929550612c4b565b923880613eae565b613ea59192506140759060203d602011611fe557611fd781836127b8565b9190613e86565b60405163a9059cbb60e01b60208201526001600160a01b0390921660248301526044808301939093529181526140bc916140b76064836127b8565b615cdd565b565b6001600160a01b03918216815291166020820152604081019190915260600190565b3d1561411a573d906001600160401b0382116127db576040519161410e601f8201601f1916602001846127b8565b82523d6000602084013e565b606090565b614128816109b6565b5490614133816109ea565b91156145d5576141428161341e565b9290919384158080916145cd575b806145c5575b6145a857156144f3575b82614439575b836141aa575b600080516020615d5983398151915293612f699160145481556015546002820155600460165491015560405193849360018060a01b031696846106c7565b6004546001600160a01b03906141c39061081990610310565b1615614400576141d7610819600154610310565b803b1561430957506141ed610819600154610310565b6141fb610819600454610310565b90803b1561032d578560009161422a9383604051809681958294630668be0d60e11b84523090600485016140be565b03925af18015610418576142f4575b505b614249610819600454610310565b803b1561032d57604051632e1a7d4d60e01b815260048101869052906000908290602490829084905af18015610418576142df575b506000808080876001600160a01b0387165af16142996140e0565b50156142ce57600080516020615d5983398151915293612f69915b600581016142c3838254612864565b90559150935061416c565b63a77a8f1d60e01b60005260046000fd5b80613ffa60006142ee936127b8565b3861427e565b80613ffa6000614303936127b8565b38614239565b61431a610819610819600454610310565b9061432482610310565b91604051916370a0823160e01b83526020838061434484600483016105ec565b0381875afa92831561041857889384916000916143e1575b50106143735761436e935030916158ed565b61423b565b505050602060405180926370a0823160e01b8252818061439630600483016105ec565b03915afa80156104185785916000916143c2575b50101561423b57631d93fd4d60e01b60005260046000fd5b6143db915060203d602011611fe557611fd781836127b8565b386143aa565b6143fa915060203d602011611fe557611fd781836127b8565b3861435c565b6000808080876001600160a01b0387165af161441a6140e0565b50156142ce57600080516020615d5983398151915293612f69916142b4565b614447610819600154610310565b8383823b156144da57505050614461610819600154610310565b61446f610819600354610310565b90803b1561032d5784600091858361449e9560405196879586948593630668be0d60e11b8552600485016140be565b03925af18015610418576144c5575b505b600381016144be848254612864565b9055614166565b80613ffa60006144d4936127b8565b386144ad565b6144ee926144e9600354610310565b6158ed565b6144af565b614501610819600154610310565b8583823b156145945750505061451b610819600154610310565b614529610819600254610310565b90803b1561032d578660009185836145589560405196879586948593630668be0d60e11b8552600485016140be565b03925af180156104185761457f575b505b60018101614578868254612864565b9055614160565b80613ffa600061458e936127b8565b38614567565b6145a3926144e9600254610310565b614569565b509350505050601454815560155460028201556004601654910155565b508415614156565b508315614150565b50601454815560155460028201556004601654910155565b6001600160a01b038116803b1561032d576000809160046040518094819363fff6cae960e01b83525af161466b575b5061462681610a04565b805460ff8116156146665761463f9060081c60ff161590565b613ba857806001600461465793015491015490612864565b4210612c02576140bc90613bac565b505050565b80613ffa600061467a936127b8565b3861461c565b9061468a82610a8c565b600481015460081c60ff1661469e81610731565b610d53576146ab83615ae1565b6146b882610b9485610abc565b9160098201549060048401926146cf845484612c4b565b946146df612d0d82548098612a22565b95600a83018054906146fe612d0d84612d086005880195865490612c4b565b9661471c612d0d600b880195612d0860068854990198895490612c4b565b985554905554905584158080614a75575b80614a6d575b614a645780158091614a5b575b8015614a52575b6149aa575b614930575b826148b6575b83151580614894575b6147a0575b506129947f68e1caf97c4c29c1ac46024e9590f80b7a1f690d393703879cf66eea4e1e84219360405193849360018060a01b031696846106c7565b61081961081960016147b3930154610310565b6147c1610819600454610310565b90803b1561032d57846000916147f09383604051809681958294630668be0d60e11b84523090600485016140be565b03925af180156104185761487f575b5061480e610819600454610310565b803b1561032d57604051632e1a7d4d60e01b815260048101859052906000908290602490829084905af180156104185761486a575b506000808080866001600160a01b0386165af161485e6140e0565b50156142ce5738614765565b80613ffa6000614879936127b8565b38614843565b80613ffa600061488e936127b8565b386147ff565b506004546001600160a01b03906148ae9061081990610310565b161515614760565b6148c96108196108196001840154610310565b6148d7610819600354610310565b90803b1561032d578460009185836149069560405196879586948593630668be0d60e11b8552600485016140be565b03925af180156104185761491b575b50614757565b80613ffa600061492a936127b8565b38614915565b6149436108196108196001840154610310565b614951610819600254610310565b90803b1561032d578660009185836149809560405196879586948593630668be0d60e11b8552600485016140be565b03925af1801561041857614995575b50614751565b80613ffa60006149a4936127b8565b3861498f565b6149c283610b9489600052600d602052604060002090565b816149cc85610a1e565b90614a33575b85614a0c575b866149e5575b505061474c565b60028092016149f5888254612864565b905501614a03868254612864565b905538806149de565b60018201614a1b878254612864565b905560018101614a2c878254612864565b90556149d8565b614a3e888354612864565b8255614a4b888254612864565b81556149d2565b50841515614747565b50831515614740565b50505050505050565b508415614733565b50831561472d565b614a8690610a8c565b600481015460029060081c60ff16614a9d81610731565b03612c02576004614ab4612cbf6001840154610310565b6020614ac96108196108196108198754610310565b604051633a98ef3960e01b815293849182905afa91821561041857600092614c1f575b5081158015614c13575b614c09576008830192614b0a845442612c4b565b8015612beb57614b2b614b206002840154612a04565b600885015490612a35565b60058401546301e13380900493614b4f6007612d9360068401546301e13380900490565b94838382614bd8575b90915082614ba7575b50505083614b74575b5050505050429055565b614b8d612d0d600792612d08612b5395614b9b98612a22565b920193612b4e855493612a04565b90553880808080614b6a565b612d08612d0d92614bb794612a22565b614bce6006850191612b5388612b4e855493612a04565b9055388282614b61565b612d08612d0d92614be894612a22565b614bff6005860191612b5389612b4e855493612a04565b9055388383614b58565b5050600842910155565b50600881015415614af6565b614c3991925060203d602011611fe557611fd781836127b8565b9038614aec565b90614c4a82610a8c565b906002614c5f600484015460ff9060081c1690565b614c6881610731565b0361112b57614c806108196108196108198554610310565b91823b1561032d5760405163059d9c7560e01b815260008160048183885af16150ba575b506020604051809463673e156160e11b82528180614cc587600483016105ec565b03915afa92831561041857600093615099575b50614ce682610b9486610abc565b916005820154916001840193614d04612d0d87612d08885488612c4b565b9560068301805490614d23612d0d84612d086002880195865490612c4b565b96614d41612d0d6007880195612d0860038854990198895490612c4b565b985554905554905584158080615091575b80615089575b614a645780158091615080575b8015615077575b614fcf575b614f55575b82614edb575b83151580614eb9575b614dc5575b506129947f53db52faf4f2c533709dc2c6bf586462f325c7ca9f3d47839847c0dcae221fc29360405193849360018060a01b031696846106c7565b6108196108196001614dd8930154610310565b614de6610819600454610310565b90803b1561032d5784600091614e159383604051809681958294630668be0d60e11b84523090600485016140be565b03925af1801561041857614ea4575b50614e33610819600454610310565b803b1561032d57604051632e1a7d4d60e01b815260048101859052906000908290602490829084905af1801561041857614e8f575b506000808080866001600160a01b0386165af1614e836140e0565b50156142ce5738614d8a565b80613ffa6000614e9e936127b8565b38614e68565b80613ffa6000614eb3936127b8565b38614e24565b506004546001600160a01b0390614ed39061081990610310565b161515614d85565b614eee6108196108196001840154610310565b614efc610819600354610310565b90803b1561032d57846000918583614f2b9560405196879586948593630668be0d60e11b8552600485016140be565b03925af1801561041857614f40575b50614d7c565b80613ffa6000614f4f936127b8565b38614f3a565b614f686108196108196001840154610310565b614f76610819600254610310565b90803b1561032d57866000918583614fa59560405196879586948593630668be0d60e11b8552600485016140be565b03925af1801561041857614fba575b50614d76565b80613ffa6000614fc9936127b8565b38614fb4565b614fe783610b9489600052600d602052604060002090565b81614ff185610a1e565b90615058575b85615031575b8661500a575b5050614d71565b600280920161501a888254612864565b905501615028868254612864565b90553880615003565b60018201615040878254612864565b905560018101615051878254612864565b9055614ffd565b615063888354612864565b8255615070888254612864565b8155614ff7565b50841515614d6c565b50831515614d65565b508415614d58565b508315614d52565b6150b391935060203d602011611fe557611fd781836127b8565b9138614cd8565b80613ffa60006150c9936127b8565b38614ca4565b6150d890610a8c565b600481015460019060081c60ff166150ef81610731565b03612c0257615104612cbf6001830154610310565b60038201908154158015615224575b614c09576008830192615127845442612c4b565b8015612beb5761513d614b206002840154612a04565b60058401546301e133809004936151616007612d9360068401546301e13380900490565b948383826151ec575b909150826151b4575b50505083615185575050505050429055565b61519e612d0d600792612d08612b5395614b9b98612a22565b9201936151ac855493612a04565b905490612a35565b612d08612d0d926151c494612a22565b6151e26006850191612b536151da845492612a04565b895490612a35565b9055388282615173565b612d08612d0d926151fc94612a22565b61521a6005860191612b53615212845492612a04565b8a5490612a35565b905538838361516a565b50600881015415615113565b9061523a82610a8c565b600481015460019060081c60ff1661525181610731565b036156285761525f836150cf565b61526c82610b9485610abc565b916005820154906001840192615283845484612c4b565b94615293612d0d82548098612a22565b95600683018054906152b2612d0d84612d086002880195865490612c4b565b966152d0612d0d6007880195612d0860038854990198895490612c4b565b985554905554905584158080615620575b80615618575b614a64578015809161560f575b8015615606575b61555e575b6154e4575b8261546a575b83151580615448575b615354575b506129947facd564f3e3cce2098aa0e23ad6930e6b15a566ba02994564aa384f13c781006b9360405193849360018060a01b031696846106c7565b6108196108196001615367930154610310565b615375610819600454610310565b90803b1561032d57846000916153a49383604051809681958294630668be0d60e11b84523090600485016140be565b03925af1801561041857615433575b506153c2610819600454610310565b803b1561032d57604051632e1a7d4d60e01b815260048101859052906000908290602490829084905af180156104185761541e575b506000808080866001600160a01b0386165af16154126140e0565b50156142ce5738615319565b80613ffa600061542d936127b8565b386153f7565b80613ffa6000615442936127b8565b386153b3565b506004546001600160a01b03906154629061081990610310565b161515615314565b61547d6108196108196001840154610310565b61548b610819600354610310565b90803b1561032d578460009185836154ba9560405196879586948593630668be0d60e11b8552600485016140be565b03925af18015610418576154cf575b5061530b565b80613ffa60006154de936127b8565b386154c9565b6154f76108196108196001840154610310565b615505610819600254610310565b90803b1561032d578660009185836155349560405196879586948593630668be0d60e11b8552600485016140be565b03925af1801561041857615549575b50615305565b80613ffa6000615558936127b8565b38615543565b61557683610b9489600052600d602052604060002090565b8161558085610a1e565b906155e7575b856155c0575b86615599575b5050615300565b60028092016155a9888254612864565b9055016155b7868254612864565b90553880615592565b600182016155cf878254612864565b9055600181016155e0878254612864565b905561558c565b6155f2888354612864565b82556155ff888254612864565b8155615586565b508415156152fb565b508315156152f4565b5084156152e7565b5083156152e1565b63f539349760e01b60005260046000fd5b919061564483610a8c565b90615657600483015460ff9060081c1690565b61566081610731565b610d535761567181610b9486610abc565b9183156122a257825484116122915761568d82610b9487610a9c565b9283546118a8576156a46108a96001840154610310565b6156ae8387614680565b6156bb6108198354610310565b6156cc610819610819600254610310565b6001600160a01b03909116146158d6575b6156ea6108198354610310565b6156fb610819610819600254610310565b9060018060a01b0316141590615712868254612c4b565b81558160038401615724888254612c4b565b90556158b4575b60098301546004820155600a83015460058201556006600b84015491015584601254156157ee578160028661577793600080516020615d79833981519152985542600182015501612845565b600d8201615786868254612864565b905561579186610aac565b61579c868254612864565b90556157cb575b506157b060125442612864565b6040516001600160a01b0390921693829161299491836133ba565b610c776108196157db9254610310565b6157e6848254612864565b9055386157a3565b600080516020615d998339815191529450615842915083610c958461581a610819612994989754610310565b61582b610819610819600254610310565b6001600160a01b03821614615882575b5054610310565b60018060a01b0316928484600080516020615d398339815191526040518061586f86829190602083019252565b0390a36040519081529081906020820190565b61588b9061099c565b615896858254612c4b565b90556158a1836109b6565b6158ac858254612c4b565b90553861583b565b6158c46117b26108198554610310565b6158cf878254612c4b565b905561572b565b6158df86612a55565b6158e88361411f565b6156dd565b906140b7906159156140bc956040519586936323b872dd60e01b6020860152602485016140be565b03601f1981018452836127b8565b60009060009060009061593a610819600254610310565b6040516370a0823160e01b8152906020828061595930600483016105ec565b0381845afa91821561041857600092615abc575b5080613e9e613e9761597e9361099c565b90818111615aa9575b5050615997610819600354610310565b6040516370a0823160e01b815290602082806159b630600483016105ec565b0381845afa91821561041857600092615a84575b5080613e9e613e976159db9361099c565b90818111615a71575b50506159f4610819600454610310565b6001600160a01b03811615614006576040516370a0823160e01b815260208180615a2130600483016105ec565b0381855afa90811561041857613f8391615a4591600091615a52575b504790612864565b91613e9e613e978261099c565b615a6b915060203d602011611fe557611fd781836127b8565b38615a3d565b615a7c929450612c4b565b9138806159e4565b6159db919250615aa29060203d602011611fe557611fd781836127b8565b91906159ca565b615ab4929550612c4b565b923880615987565b61597e919250615ada9060203d602011611fe557611fd781836127b8565b919061596d565b615aea90610a8c565b600481015460081c60ff16615afe81610731565b612c0257615b12612cbf6001830154610310565b60038201908154158015615c16575b615c0c57600c830192615b35845442612c4b565b8015612beb57615b4b614b206002840154612a04565b60058401546301e13380900493615b6f6007612d9360068401546301e13380900490565b94838382615bdc575b90915082615bac575b50505083615b93575050505050429055565b61519e612d0d600b92612d08612b5395614b9b98612a22565b612d08612d0d92615bbc94612a22565b615bd2600a850191612b536151da845492612a04565b9055388282615b81565b612d08612d0d92615bec94612a22565b615c026009860191612b53615212845492612a04565b9055388383615b78565b5050600c42910155565b50600881015415615b21565b9091828214615c93578115615cd65781615c3f613ad58383612a22565b91159182158080615ccd575b15615c9b5750615c5a91612864565b831115615c93575b615c6d575050600190565b615c7681612856565b8211918215615c8457505090565b615c8f919250612856565b1090565b505050600090565b80615cc4575b615cad575b5050615c62565b615cb79085612864565b1015615c93578138615ca6565b50818510615ca1565b50828611615c4b565b5050151590565b906000602091828151910182855af1156127f5576000513d615d2f57506001600160a01b0381163b155b615d0e5750565b635274afe760e01b60009081526001600160a01b0391909116600452602490fd5b60011415615d0756fe144424c1e710ba35ccb0319d0fe39227dfea5b78aaa426661ad54ebbed3e790b60dc412aff8039463644dbff180c6be3ff23f0595251da61b1f2ac26fbf6fa0e88bf5c4a0d372ab0014553e8af551b5aa4c534746f1d22bd1f4514d985c3e784f960dbf9e5d0682f7a298ed974e33a28b4464914b7a2bfac12ae419a9afeb280dcd53842d284e15eee6bbf1c7a17cd4971b03ba6ac761728f78c0e8a51527811a2646970667358221220b2f616c8deafd2e4e766bf0dc30c4485f3504c76f965af13fd821fb27bd8171f64736f6c634300081a0033