Contract

0xd3538a2312B37f59E405bb1202B064e2205eBAb9

Overview

S Balance

Sonic LogoSonic LogoSonic Logo0 S

S Value

-

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To

There are no matching entries

Please try again later

Parent Transaction Hash Block From To
View All Internal Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
StrategyPassiveManagerShadow

Compiler Version
v0.8.23+commit.f704f362

Optimization Enabled:
Yes with 200 runs

Other Settings:
paris EvmVersion
File 1 of 32 : StrategyPassiveManagerShadow.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;

// import {SafeERC20} from "@openzeppelin-4/contracts/token/ERC20/utils/SafeERC20.sol";
import {SafeERC20Upgradeable, IERC20Upgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol";
import {IERC20Metadata} from "@openzeppelin-4/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {SafeERC20} from "@openzeppelin-4/contracts/token/ERC20/utils/SafeERC20.sol";
import {SignedMath} from "@openzeppelin-4/contracts/utils/math/SignedMath.sol";
import {StratFeeCowManagerInitializable, IFeeConfig} from "../Common/StratFeeCowManagerInitializable.sol";
import {INuriPool} from "../../interfaces/ramses/INuriPool.sol";
import {LiquidityAmounts} from "../../utils/LiquidityAmounts.sol";
import {TickMath} from "../../utils/TickMath.sol";
import {TickUtils, FullMath} from "../../utils/TickUtils.sol";
import {UniswapV3Utils} from "../../utils/UniswapV3Utils.sol";
import {IBeefyVaultConcLiq} from "../../interfaces/beefy/IBeefyVaultConcLiq.sol";
import {IStrategyFactory} from "../../interfaces/beefy/IStrategyFactory.sol";
import {IStrategyConcLiq} from "../../interfaces/beefy/IStrategyConcLiq.sol";
import {IRamsesGauge} from "../../interfaces/ramses/IRamsesGauge.sol";
import {IBeefySwapper} from "../../interfaces/beefy/IBeefySwapper.sol";
import {IBeefyRewardPool} from "../../interfaces/beefy/IBeefyRewardPool.sol";

/// @title Beefy Passive Position Manager. Version: Shadow
/// @author weso, Beefy
/// @notice This is a contract for managing a passive concentrated liquidity position on Nuri.
contract StrategyPassiveManagerShadow is StratFeeCowManagerInitializable, IStrategyConcLiq {
    using SafeERC20Upgradeable for IERC20Upgradeable;
    using TickMath for int24;

    /// @notice The precision for pricing.
    uint256 private constant PRECISION = 1e36;
    uint256 private constant SQRT_PRECISION = 1e18;

    /// @notice The max and min ticks univ3 allows.
    int56 private constant MIN_TICK = -887272;
    int56 private constant MAX_TICK = 887272;

    /// @notice The address of the pool.
    address public pool;
    /// @notice The address of the gauge.
    address public gauge;
    /// @notice The address of the reward pool.
    address public rewardPool;
    /// @notice The address of the first token in the liquidity pool.
    address public lpToken0;
    /// @notice The address of the second token in the liquidity pool.
    address public lpToken1;

    /// @notice The address array of reward tokens.
    address[] public rewardTokens;

    /// @notice The uint array of reward token balances.
    mapping(address => uint256) public rewardBalances;

    /// @notice The fees that are collected in the strategy but have not yet completed the harvest process.
    uint256 public fees0;
    uint256 public fees1;

    /// @notice The struct to store our tick positioning.
    struct Position {
        int24 tickLower;
        int24 tickUpper;
    }

    /// @notice The main position of the strategy.
    /// @dev this will always be a 50/50 position that will be equal to position width * tickSpacing on each side.
    Position public positionMain;

    /// @notice The alternative position of the strategy.
    /// @dev this will always be a single sided (limit order) position that will start closest to current tick and continue to width * tickSpacing.
    /// This will always be in the token that has the most value after we fill our main position. 
    Position public positionAlt;

    /// @notice The width of the position, thats a multiplier for tick spacing to find our range. 
    int24 public positionWidth;

    /// @notice the max tick deviations we will allow for deposits/harvests. 
    int56 public maxTickDeviation;

    /// @notice The twap interval seconds we use for the twap check. 
    uint32 public twapInterval;

    /// @notice Bool switch to prevent reentrancy on the mint callback.
    bool private minting;

    /// @notice Initializes the ticks on first deposit. 
    bool private initTicks;

    // Errors 
    error NotAuthorized();
    error NotPool();
    error InvalidEntry();
    error NotVault();
    error InvalidInput();
    error InvalidOutput();
    error NotCalm();
    error TooMuchSlippage();
    error InvalidTicks();

    // Events
    event TVL(uint256 bal0, uint256 bal1);
    event Harvest(uint256 fee0, uint256 fee1);
    event SetPositionWidth(int24 oldWidth, int24 width);
    event SetDeviation(int56 maxTickDeviation);
    event SetTwapInterval(uint32 oldInterval, uint32 interval);
    event SetRewardPool(address rewardPool);
    event SetGauge(address gauge);
    event ChargedFees(uint256 callFeeAmount, uint256 beefyFeeAmount, uint256 strategistFeeAmount);
    event ClaimedFees(uint256 feeMain0, uint256 feeMain1, uint256 feeAlt0, uint256 feeAlt1);

    /// @custom:oz-upgrades-unsafe-allow constructor
    constructor() {
        _disableInitializers();
    }
 
    /// @notice Modifier to only allow deposit/harvest actions when current price is within a certain deviation of twap.
    modifier onlyCalmPeriods() {
        _onlyCalmPeriods();
        _;
    }

    modifier onlyRebalancers() {
        if (!IStrategyFactory(factory).rebalancers(msg.sender)) revert NotAuthorized();
        _;
    }

    /// @notice function to only allow deposit/harvest actions when current price is within a certain deviation of twap.
    function _onlyCalmPeriods() private view {
        if (!isCalm()) revert NotCalm();
    }

    /// @notice function to only allow deposit/harvest actions when current price is within a certain deviation of twap.
    function isCalm() public view returns (bool) {
        int24 tick = currentTick();
        int56 twapTick = twap();

        int56 minCalmTick = int56(SignedMath.max(twapTick - maxTickDeviation, MIN_TICK));
        int56 maxCalmTick = int56(SignedMath.min(twapTick + maxTickDeviation, MAX_TICK));

        // Calculate if greater than deviation % from twap and revert if it is. 
        if(minCalmTick > tick  || maxCalmTick < tick) return false;
        else return true;
    }

    /**
     * @notice Initializes the strategy and the inherited strat fee manager.
     * @dev Make sure cardinality is set appropriately for the twap.
     * @param _pool The underlying pool.
     * @param _gauge The address of the gauge.
     * @param _positionWidth The multiplier for tick spacing to find our range.
     * @param _commonAddresses The common addresses needed for the strat fee manager.
     */
    function initialize (
        address _pool,
        address _gauge,
        address _rewardPool,
        int24 _positionWidth,
        CommonAddresses calldata _commonAddresses
    ) external initializer {
        __StratFeeManager_init(_commonAddresses);

        pool = _pool;
        gauge = _gauge;
        rewardPool = _rewardPool;
        lpToken0 = INuriPool(_pool).token0();
        lpToken1 = INuriPool(_pool).token1();

        // Our width multiplier. The tick distance of each side will be width * tickSpacing.
        positionWidth = _positionWidth;
    
        // Set the twap interval to 120 seconds.
        twapInterval = 120;

        _giveAllowances();
    }

    /// @notice Only allows the vault to call a function.
    function _onlyVault () private view {
        if (msg.sender != vault) revert NotVault();
    }

    /// @notice Called during deposit and withdraw to remove liquidity and harvest fees for accounting purposes.
    function beforeAction() external {
        _onlyVault();
        _claimEarnings();
        _removeLiquidity();
    }

    /// @notice Called during deposit to add all liquidity back to their positions. 
    function deposit() external onlyCalmPeriods {
        _onlyVault();

        // Add all liquidity
        if (!initTicks) {
            _setTicks();
            initTicks = true;
        }

        _addLiquidity();
        
        (uint256 bal0, uint256 bal1) = balances();

        // TVL Balances after deposit
        emit TVL(bal0, bal1);
    }

    /**
     * @notice Withdraws the specified amount of tokens from the strategy as calculated by the vault.
     * @param _amount0 The amount of token0 to withdraw.
     * @param _amount1 The amount of token1 to withdraw.
     */
    function withdraw(uint256 _amount0, uint256 _amount1) external {
        _onlyVault();

        // Liquidity has already been removed in beforeAction() so this is just a simple withdraw.
        if (_amount0 > 0) IERC20Upgradeable(lpToken0).safeTransfer(vault, _amount0);
        if (_amount1 > 0) IERC20Upgradeable(lpToken1).safeTransfer(vault, _amount1);

        // After we take what is needed we add it all back to our positions. 
        if (!_isPaused()) _addLiquidity();

        (uint256 bal0, uint256 bal1) = balances();

        // TVL Balances after withdraw
        emit TVL(bal0, bal1);
    }

    /// @notice Adds liquidity to the main and alternative positions called on deposit, harvest and withdraw.
    function _addLiquidity() private {
        _whenStrategyNotPaused();

        (uint256 bal0, uint256 bal1) = balancesOfThis();

        // Then we fetch how much liquidity we get for adding at the main position ticks with our token balances. 
        uint160 sqrtprice = sqrtPrice();
        uint128 liquidity = LiquidityAmounts.getLiquidityForAmounts(
            sqrtprice,
            TickMath.getSqrtRatioAtTick(positionMain.tickLower),
            TickMath.getSqrtRatioAtTick(positionMain.tickUpper),
            bal0,
            bal1
        );

        bool amountsOk = _checkAmounts(liquidity, positionMain.tickLower, positionMain.tickUpper);

        // Flip minting to true and call the pool to mint the liquidity. 
        if (liquidity > 0 && amountsOk) {
            minting = true;
            INuriPool(pool).mint(address(this), 0, positionMain.tickLower, positionMain.tickUpper, liquidity, "Beefy Main");
        } else  _onlyCalmPeriods();

        (bal0, bal1) = balancesOfThis();

        // Fetch how much liquidity we get for adding at the alternative position ticks with our token balances.
        liquidity = LiquidityAmounts.getLiquidityForAmounts(
            sqrtprice,
            TickMath.getSqrtRatioAtTick(positionAlt.tickLower),
            TickMath.getSqrtRatioAtTick(positionAlt.tickUpper),
            bal0,
            bal1
        );

        // Flip minting to true and call the pool to mint the liquidity.
        if (liquidity > 0) {
            minting = true;
            INuriPool(pool).mint(address(this), 0, positionAlt.tickLower, positionAlt.tickUpper, liquidity, "Beefy Alt");
        }
    }

    /// @notice Removes liquidity from the main and alternative positions, called on deposit, withdraw and harvest.
    function _removeLiquidity() private {

        // First we fetch our position keys in order to get our liquidity balances from the pool. 
        (bytes32 keyMain, bytes32 keyAlt) = getKeys();
        
        // Fetch the liquidity balances from the pool.
        (uint128 liquidity,,,,) = INuriPool(pool).positions(keyMain);
        (uint128 liquidityAlt,,,,) = INuriPool(pool).positions(keyAlt);
        // If we have liquidity in the positions we remove it and collect our tokens.
        if (liquidity > 0) {
            INuriPool(pool).burn(positionMain.tickLower, positionMain.tickUpper, liquidity);
            INuriPool(pool).collect(address(this), positionMain.tickLower, positionMain.tickUpper, type(uint128).max, type(uint128).max);
        }

        if (liquidityAlt > 0) {
            INuriPool(pool).burn(positionAlt.tickLower, positionAlt.tickUpper, liquidityAlt);
            INuriPool(pool).collect(address(this), positionAlt.tickLower, positionAlt.tickUpper, type(uint128).max, type(uint128).max);
        }
    }

    /**
     *  @notice Checks if the amounts are ok to add liquidity.
     * @param _liquidity The liquidity to add.
     * @param _tickLower The lower tick of the position.
     * @param _tickUpper The upper tick of the position.
     * @return bool True if the amounts are ok, false if not.
     */
    function _checkAmounts(uint128 _liquidity, int24 _tickLower, int24 _tickUpper) private view returns (bool) {
        (uint256 amount0, uint256 amount1) = LiquidityAmounts.getAmountsForLiquidity(
            sqrtPrice(),
            TickMath.getSqrtRatioAtTick(_tickLower),
            TickMath.getSqrtRatioAtTick(_tickUpper),
            _liquidity
        );

        if (amount0 == 0 || amount1 == 0) return false;
        else return true;
    }

    /// @notice Harvest call to claim fees from pool, charge fees for Beefy, then readjust our positions.
    /// @param _callFeeRecipient The address to send the call fee to.
    function harvest(address _callFeeRecipient) external {
        _harvest(_callFeeRecipient);
    }

    /// @notice Harvest call to claim fees from the pool, charge fees for Beefy, then readjust our positions.
    /// @dev Call fee goes to the tx.origin. 
    function harvest() external {
        _harvest(tx.origin);
    }

    /// @notice Internal function to claim fees from the pool, charge fees for Beefy, then readjust our positions.
    function _harvest (address _callFeeRecipient) private {
        // Claim fees from the pool and collect them.
        claimEarnings();
        _removeLiquidity();

        // Charge fees for Beefy and send them to the appropriate addresses, charge fees to accrued state fee amounts.
        uint256 nativeRewards;
        if (rewardTokens.length > 0) nativeRewards = _swapRewards();
        (uint256 fee0, uint256 fee1) = _chargeFees(_callFeeRecipient, fees0, fees1, nativeRewards);

        _addLiquidity();

        // Reset state fees to 0. 
        fees0 = 0;
        fees1 = 0;
        
        // We stream the rewards over time to the LP. 
        (uint256 currentLock0, uint256 currentLock1) = lockedProfit();
        totalLocked0 = fee0 + currentLock0;
        totalLocked1 = fee1 + currentLock1;

        // Log the last time we claimed fees. 
        lastHarvest = block.timestamp;

        // Log the fees post Beefy fees.
        emit Harvest(fee0, fee1);
    }

    /// @notice Function called to moveTicks of the position 
    function moveTicks() external onlyCalmPeriods onlyRebalancers {
        _claimEarnings();
        _removeLiquidity();
        _setTicks();
        _addLiquidity();

        (uint256 bal0, uint256 bal1) = balances();
        emit TVL(bal0, bal1);
    }

    /// @notice Claims fees from the pool and collects them.
    function claimEarnings() public returns (uint256 fee0, uint256 fee1, uint256 feeAlt0, uint256 feeAlt1) {
        (fee0, fee1, feeAlt0, feeAlt1) = _claimEarnings();
        if (rewardTokens.length > 0 && address(gauge) != address(0)) _getRewards();
    }

    /// @notice Internal function to claim fees from the pool and collect them.
    function _claimEarnings() private returns (uint256 fee0, uint256 fee1, uint256 feeAlt0, uint256 feeAlt1) {
        // Claim fees
        (bytes32 keyMain, bytes32 keyAlt) = getKeys();
        (uint128 liquidity,,,,) = INuriPool(pool).positions(keyMain);
        (uint128 liquidityAlt,,,,) = INuriPool(pool).positions(keyAlt);

        // Burn 0 liquidity to make fees available to claim. 
        if (liquidity > 0) INuriPool(pool).burn(positionMain.tickLower, positionMain.tickUpper, 0);
        if (liquidityAlt > 0) INuriPool(pool).burn(positionAlt.tickLower, positionAlt.tickUpper, 0);

        // Collect fees from the pool. 
        (fee0, fee1) = INuriPool(pool).collect(address(this), positionMain.tickLower, positionMain.tickUpper, type(uint128).max, type(uint128).max);
        (feeAlt0, feeAlt1) = INuriPool(pool).collect(address(this), positionAlt.tickLower, positionAlt.tickUpper, type(uint128).max, type(uint128).max);

        // Set the total fees collected to state.
        fees0 = fees0 + fee0 + feeAlt0;
        fees1 = fees1 + fee1 + feeAlt1;

        emit ClaimedFees(fee0, fee1, feeAlt0, feeAlt1);
    }

    /// @notice Function to claim rewards from the gauge.
    function _getRewards() private {
        uint256[] memory beforeBalances = new uint256[](rewardTokens.length);
        for (uint i; i < rewardTokens.length;) {
            beforeBalances[i] = IERC20Metadata(rewardTokens[i]).balanceOf(address(this));
            unchecked { ++i; }
        }

        IRamsesGauge(gauge).getReward(address(this), 0, positionMain.tickLower, positionMain.tickUpper, rewardTokens, address(this));
        IRamsesGauge(gauge).getReward(address(this), 0, positionAlt.tickLower, positionAlt.tickUpper, rewardTokens, address(this));

        for (uint i; i < rewardTokens.length;) {
            uint256 rewardBalance = IERC20Metadata(rewardTokens[i]).balanceOf(address(this)) - beforeBalances[i];
            rewardBalances[rewardTokens[i]] += rewardBalance;
            unchecked { ++i; }
        }
    }

    /// @notice Function to swap rewards to native token.
    function _swapRewards() private returns (uint256 nativeEarned) {
        /// Fetch our fee percentage amounts from the fee config.
        IFeeConfig.FeeCategory memory fees = getFees();

        for (uint i; i < rewardTokens.length;) {
            if (rewardBalances[rewardTokens[i]] > 0) {
                uint256 feeAmount = rewardBalances[rewardTokens[i]] * fees.total / DIVISOR;
                uint256 nativeReturned;

                if (rewardTokens[i] != native) nativeReturned = IBeefySwapper(unirouter).swap(rewardTokens[i], native, feeAmount);
                else nativeReturned = feeAmount;

                IBeefyRewardPool(rewardPool).notifyRewardAmount(rewardTokens[i], rewardBalances[rewardTokens[i]] - feeAmount, 1 days);
                
                nativeEarned += nativeReturned;
                rewardBalances[rewardTokens[i]] = 0;
            }

            unchecked { ++i; }
        }
    }

    /**
     * @notice Internal function to charge fees for Beefy and send them to the appropriate addresses.
     * @param _callFeeRecipient The address to send the call fee to.
     * @param _amount0 The amount of token0 to charge fees on.
     * @param _amount1 The amount of token1 to charge fees on.
     * @return _amountLeft0 The amount of token0 left after fees.
     * @return _amountLeft1 The amount of token1 left after fees.
     */
    function _chargeFees(address _callFeeRecipient, uint256 _amount0, uint256 _amount1, uint256 _nativeRewards) private returns (uint256 _amountLeft0, uint256 _amountLeft1){
        /// Fetch our fee percentage amounts from the fee config.
        IFeeConfig.FeeCategory memory fees = getFees();

        /// We calculate how much to swap and then swap both tokens to native and charge fees.
        uint256 nativeEarned = _nativeRewards;
        if (_amount0 > 0) {
            // Calculate amount of token 0 to swap for fees.
            uint256 amountToSwap0 = _amount0 * fees.total / DIVISOR;
            _amountLeft0 = _amount0 - amountToSwap0;
            
            // If token0 is not native, swap to native the fee amount.
            uint256 out0;
            if (lpToken0 != native) out0 = IBeefySwapper(unirouter).swap(lpToken0, native, amountToSwap0);
            
            // Add the native earned to the total of native we earned for beefy fees, handle if token0 is native.
            if (lpToken0 == native)  nativeEarned += amountToSwap0;
            else nativeEarned += out0;
        }

        if (_amount1 > 0) {
            // Calculate amount of token 1 to swap for fees.
            uint256 amountToSwap1 = _amount1 * fees.total / DIVISOR;
            _amountLeft1 = _amount1 - amountToSwap1;

            // If token1 is not native, swap to native the fee amount.
            uint256 out1;
            if (lpToken1 != native) out1 = IBeefySwapper(unirouter).swap(lpToken1, native, amountToSwap1);
            
            // Add the native earned to the total of native we earned for beefy fees, handle if token1 is native.
            if (lpToken1 == native) nativeEarned += amountToSwap1;
            else nativeEarned += out1;
        }

        // Distribute the native earned to the appropriate addresses.
        uint256 callFeeAmount = nativeEarned * fees.call / DIVISOR;
        IERC20Upgradeable(native).safeTransfer(_callFeeRecipient, callFeeAmount);

        uint256 strategistFeeAmount = nativeEarned * fees.strategist / DIVISOR;
        IERC20Upgradeable(native).safeTransfer(strategist, strategistFeeAmount);

        uint256 beefyFeeAmount = nativeEarned - callFeeAmount - strategistFeeAmount;
        IERC20Upgradeable(native).safeTransfer(beefyFeeRecipient(), beefyFeeAmount);

        emit ChargedFees(callFeeAmount, beefyFeeAmount, strategistFeeAmount);
    }

    /** 
     * @notice Returns total token balances in the strategy.
     * @return token0Bal The amount of token0 in the strategy.
     * @return token1Bal The amount of token1 in the strategy.
    */
    function balances() public view returns (uint256 token0Bal, uint256 token1Bal) {
        (uint256 thisBal0, uint256 thisBal1) = balancesOfThis();
        (uint256 poolBal0, uint256 poolBal1,,,,) = balancesOfPool();
        (uint256 locked0, uint256 locked1) = lockedProfit();

        uint256 total0 = thisBal0 + poolBal0 - locked0;
        uint256 total1 = thisBal1 + poolBal1 - locked1;
        uint256 unharvestedFees0 = fees0;
        uint256 unharvestedFees1 = fees1;

        // If pair is so imbalanced that we no longer have any enough tokens to pay fees, we set them to 0.
        if (unharvestedFees0 > total0) unharvestedFees0 = total0;
        if (unharvestedFees1 > total1) unharvestedFees1 = total1;

        // For token0 and token1 we return balance of this contract + balance of positions - locked profit - feesUnharvested.
        return (total0 - unharvestedFees0, total1 - unharvestedFees1);
    }

    /**
     * @notice Returns total tokens sitting in the strategy.
     * @return token0Bal The amount of token0 in the strategy.
     * @return token1Bal The amount of token1 in the strategy.
    */
    function balancesOfThis() public view returns (uint256 token0Bal, uint256 token1Bal) {
        uint256 rewardBalance0;
        uint256 rewardBalance1;

        // Check to see if one of our reward tokens is a pool token and remove from balance; 
        for (uint i; i < rewardTokens.length;) {
            if (rewardTokens[i] == lpToken0) rewardBalance0 = rewardBalances[rewardTokens[i]];
            if (rewardTokens[i] == lpToken1) rewardBalance1 = rewardBalances[rewardTokens[i]];
            unchecked { ++i; }
        }

        token0Bal = IERC20Metadata(lpToken0).balanceOf(address(this)) - rewardBalance0; 
        token1Bal = IERC20Metadata(lpToken1).balanceOf(address(this)) - rewardBalance1;
    }

    /** 
     * @notice Returns total tokens in pool positions (is a calculation which means it could be a little off by a few wei). 
     * @return token0Bal The amount of token0 in the pool.
     * @return token1Bal The amount of token1 in the pool.
     * @return mainAmount0 The amount of token0 in the main position.
     * @return mainAmount1 The amount of token1 in the main position.
     * @return altAmount0 The amount of token0 in the alt position.
     * @return altAmount1 The amount of token1 in the alt position.
    */
    function balancesOfPool() public view returns (uint256 token0Bal, uint256 token1Bal, uint256 mainAmount0, uint256 mainAmount1, uint256 altAmount0, uint256 altAmount1) {
        (bytes32 keyMain, bytes32 keyAlt) = getKeys();
        uint160 sqrtPriceX96 = sqrtPrice();
        (uint128 liquidity,,,uint256 owed0, uint256 owed1) = INuriPool(pool).positions(keyMain);
        (uint128 altLiquidity,,,uint256 altOwed0, uint256 altOwed1) =INuriPool(pool).positions(keyAlt);

        (mainAmount0, mainAmount1) = LiquidityAmounts.getAmountsForLiquidity(
            sqrtPriceX96,
            TickMath.getSqrtRatioAtTick(positionMain.tickLower),
            TickMath.getSqrtRatioAtTick(positionMain.tickUpper),
            liquidity
        );

        (altAmount0, altAmount1) = LiquidityAmounts.getAmountsForLiquidity(
            sqrtPriceX96,   
            TickMath.getSqrtRatioAtTick(positionAlt.tickLower),
            TickMath.getSqrtRatioAtTick(positionAlt.tickUpper),
            altLiquidity
        );

        mainAmount0 += owed0;
        mainAmount1 += owed1;

        altAmount0 += altOwed0;
        altAmount1 += altOwed1;
        
        token0Bal = mainAmount0 + altAmount0;
        token1Bal = mainAmount1 + altAmount1;
    }

    /**
     * @notice Returns the amount of locked profit in the strategy, this is linearly release over a duration defined in the fee manager.
     * @return locked0 The amount of token0 locked in the strategy.
     * @return locked1 The amount of token1 locked in the strategy.
    */
    function lockedProfit() public override view returns (uint256 locked0, uint256 locked1) {
        (uint256 balThis0, uint256 balThis1) = balancesOfThis();
        (uint256 balPool0, uint256 balPool1,,,,) = balancesOfPool();
        uint256 totalBal0 = balThis0 + balPool0;
        uint256 totalBal1 = balThis1 + balPool1;

        uint256 elapsed = block.timestamp - lastHarvest;
        uint256 remaining = elapsed < DURATION ? DURATION - elapsed : 0;

        // Make sure we don't lock more than we have.
        if (totalBal0 > totalLocked0) locked0 = totalLocked0 * remaining / DURATION;
        else locked0 = totalBal0 * remaining / DURATION;

        if (totalBal1 > totalLocked1) locked1 = totalLocked1 * remaining / DURATION; 
        else locked1 = totalBal1 * remaining / DURATION;
    }
    
    /**
     * @notice Returns the range of the pool, will always be the main position.
     * @return lowerPrice The lower price of the position.
     * @return upperPrice The upper price of the position.
    */
    function range() external view returns (uint256 lowerPrice, uint256 upperPrice) {
        // the main position is always covering the alt range
        lowerPrice = FullMath.mulDiv(uint256(TickMath.getSqrtRatioAtTick(positionMain.tickLower)), SQRT_PRECISION, (2 ** 96)) ** 2;
        upperPrice = FullMath.mulDiv(uint256(TickMath.getSqrtRatioAtTick(positionMain.tickUpper)), SQRT_PRECISION, (2 ** 96)) ** 2;
    }

    /**
     * @notice Returns the keys for the main and alternative positions.
     * @return keyMain The key for the main position.
     * @return keyAlt The key for the alternative position.
    */
    function getKeys() public view returns (bytes32 keyMain, bytes32 keyAlt) {
        keyMain = keccak256(abi.encodePacked(address(this), uint256(0), positionMain.tickLower, positionMain.tickUpper));
        keyAlt = keccak256(abi.encodePacked(address(this), uint256(0), positionAlt.tickLower, positionAlt.tickUpper));
    }

    /**
     * @notice The current tick of the pool.
     * @return tick The current tick of the pool.
    */
    function currentTick() public view returns (int24 tick) {
        (,tick,,,,,) = INuriPool(pool).slot0();
    }

    /**
     * @notice The current price of the pool in token1, encoded with 36 decimals.
     * @return _price The current price of the pool.
    */
    function price() public view returns (uint256 _price) {
        uint160 sqrtPriceX96 = sqrtPrice();
        _price = FullMath.mulDiv(uint256(sqrtPriceX96), SQRT_PRECISION, (2 ** 96)) ** 2;
    }

    /**
     * @notice The sqrt price of the pool.
     * @return sqrtPriceX96 The sqrt price of the pool.
    */
    function sqrtPrice() public view returns (uint160 sqrtPriceX96) {
        (sqrtPriceX96,,,,,,) = INuriPool(pool).slot0();
    }

    /**
     * @notice The swap fee variable is the fee charged for swaps in the underlying pool in 18 decimals
     * @return fee The swap fee of the underlying pool
    */
    function swapFee() external override view returns (uint256 fee) {
        fee = uint256(INuriPool(pool).fee()) * SQRT_PRECISION / 1e6;
    }

    /** 
     * @notice The tick distance of the pool.
     * @return int24 The tick distance/spacing of the pool.
    */
    function _tickDistance() private view returns (int24) {
        return INuriPool(pool).tickSpacing();
    }

    /**
     * @notice Callback function for Uniswap V3 pool to call when minting liquidity.
     * @param amount0 Amount of token0 owed to the pool
     * @param amount1 Amount of token1 owed to the pool
     * bytes Additional data but unused in this case.
    */
    function ramsesV2MintCallback(uint256 amount0, uint256 amount1, bytes memory /*data*/) external {
        if (msg.sender != pool) revert NotPool();
        if (!minting) revert InvalidEntry();

        if (amount0 > 0) IERC20Upgradeable(lpToken0).safeTransfer(pool, amount0);
        if (amount1 > 0) IERC20Upgradeable(lpToken1).safeTransfer(pool, amount1);
        minting = false;
    }

    /// @notice Sets the tick positions for the main and alternative positions.
    function _setTicks() private onlyCalmPeriods {
        int24 tick = currentTick();
        int24 distance = _tickDistance();
        int24 width = positionWidth * distance;

        _setMainTick(tick, distance, width);
        _setAltTick(tick, distance, width);

        lastPositionAdjustment = block.timestamp;
    }

    /// @notice Sets the main tick position.
    function _setMainTick(int24 tick, int24 distance, int24 width) private {
        (positionMain.tickLower, positionMain.tickUpper) = TickUtils.baseTicks(
            tick,
            width,
            distance
        );
    }

    /// @notice Sets the alternative tick position.
    function _setAltTick(int24 tick, int24 distance, int24 width) private {
        (uint256 bal0, uint256 bal1) = balancesOfThis();

        // We calculate how much token0 we have in the price of token1. 
        uint256 amount0;

        if (bal0 > 0) {
            amount0 = bal0 * price() / PRECISION;
        }

        // We set the alternative position based on the token that has the most value available. 
        if (amount0 < bal1) {
            (positionAlt.tickLower, ) = TickUtils.baseTicks(
                tick,
                width,
                distance
            );

            (positionAlt.tickUpper, ) = TickUtils.baseTicks(
                tick,
                distance,
                distance
            ); 
        } else if (bal1 < amount0) {
            (, positionAlt.tickLower) = TickUtils.baseTicks(
                tick,
                distance,
                distance
            );

            (, positionAlt.tickUpper) = TickUtils.baseTicks(
                tick,
                width,
                distance
            ); 
        }

        if (positionMain.tickLower == positionAlt.tickLower && positionMain.tickUpper == positionAlt.tickUpper) revert InvalidTicks();
    }

    /**
     * @notice Sets the deviation from the twap we will allow on adding liquidity.
     * @param _maxDeviation The max deviation from twap we will allow.
    */
    function setDeviation(int56 _maxDeviation) external onlyOwner {
        emit SetDeviation(_maxDeviation);

        // Require the deviation to be less than or equal to 4 times the tick spacing.
        if (_maxDeviation >= _tickDistance() * 4) revert InvalidInput();

        maxTickDeviation = _maxDeviation;
    }

    /** 
     * @notice The twap of the last minute from the pool.
     * @return twapTick The twap of the last minute from the pool.
    */
    function twap() public view returns (int56 twapTick) {
        uint32[] memory secondsAgo = new uint32[](2);
        secondsAgo[0] = uint32(twapInterval);
        secondsAgo[1] = 0;

        (int56[] memory tickCuml,) = INuriPool(pool).observe(secondsAgo);
        twapTick = (tickCuml[1] - tickCuml[0]) / int32(twapInterval);
    }

    /**
     * @notice Sets the gauge address.
     * @param _gauge The new gauge address.
    */
    function setGauge(address _gauge) external onlyManager {
        emit SetGauge(_gauge);
        gauge = _gauge;
    }

    /**
     * @notice Adds a reward token to the strategy.
     * @param _token The token we will recieve from gauge as reward.
     */
    function addRewardToken(address _token) external onlyManager {
        IERC20Upgradeable(_token).forceApprove(rewardPool, 0);
        IERC20Upgradeable(_token).forceApprove(rewardPool, type(uint256).max);

        IERC20Upgradeable(_token).forceApprove(unirouter, 0);
        IERC20Upgradeable(_token).forceApprove(unirouter, type(uint256).max);
        rewardTokens.push(_token);
    }

    /// @notice Resets the reward tokens in the strategy.
    function resetRewards() external onlyManager {
        for (uint i; i < rewardTokens.length;) {
            IERC20Upgradeable(rewardTokens[i]).forceApprove(rewardPool, 0);
            IERC20Upgradeable(rewardTokens[i]).forceApprove(unirouter, 0);
            unchecked { ++i; }
        }

        delete rewardTokens;
    }

    /**
     * @notice Sets the twap interval for the strategy.
     * @param _interval The new twap interval.
    */
    function setTwapInterval(uint32 _interval) external onlyOwner {
        emit SetTwapInterval(twapInterval, _interval);

        // Require the interval to be greater than 60 seconds.
        if (_interval < 60) revert InvalidInput();

        twapInterval = _interval;
    }

    /** 
     * @notice Sets our position width and readjusts our positions.
     * @param _width The new width multiplier of the position.
    */
    function setPositionWidth(int24 _width) external onlyOwner {
        emit SetPositionWidth(positionWidth, _width);
        _claimEarnings();
        _removeLiquidity();
        positionWidth = _width;
        _setTicks();
        _addLiquidity();
    }

    /**
     * @notice Sets the reward pool address.
     * @param _rewardPool The new reward pool address.
     */
    function setRewardPool(address _rewardPool) external onlyOwner {
        _removeAllowances();
        rewardPool = _rewardPool;
        _giveAllowances();
        emit SetRewardPool(_rewardPool);
    }

    /**
     * @notice set the unirouter address
     * @param _unirouter The new unirouter address
     */
    function setUnirouter(address _unirouter) external override onlyOwner {
        _removeAllowances();
        unirouter = _unirouter;
        _giveAllowances();
        emit SetUnirouter(_unirouter);
    }

    /// @notice Retire the strategy and return all the dust to the fee recipient.
    function retireVault() external onlyOwner {
        if (IBeefyVaultConcLiq(vault).totalSupply() != 10**3) revert NotAuthorized();
        panic(0,0);
        address feeRecipient = beefyFeeRecipient();
        (uint bal0, uint bal1) = balancesOfThis();
        if (bal0 > 0) IERC20Upgradeable(lpToken0).safeTransfer(feeRecipient, IERC20Metadata(lpToken0).balanceOf(address(this)));
        if (bal1 > 0) IERC20Upgradeable(lpToken1).safeTransfer(feeRecipient, IERC20Metadata(lpToken1).balanceOf(address(this)));
        _transferOwnership(address(0));
    }

    /**  
     * @notice Remove Liquidity and Allowances, then pause deposits.
     * @param _minAmount0 The minimum amount of token0 in the strategy after panic.
     * @param _minAmount1 The minimum amount of token1 in the strategy after panic.
     */
    function panic(uint256 _minAmount0, uint256 _minAmount1) public onlyManager {
        _claimEarnings();
        _removeLiquidity();
        _removeAllowances();
        _pause();

        (uint256 bal0, uint256 bal1) = balances();
        if (bal0 < _minAmount0 || bal1 < _minAmount1) revert TooMuchSlippage();
    }

    /// @notice Unpause deposits, give allowances and add liquidity.
    function unpause() external onlyManager {
        if (owner() == address(0)) revert NotAuthorized();
        _giveAllowances();
        _unpause();
        _setTicks();
        _addLiquidity();
    }

    /// @notice gives swap permisions for the tokens to the unirouter.
    function _giveAllowances() private {
        IERC20Upgradeable(lpToken0).forceApprove(unirouter, type(uint256).max);
        IERC20Upgradeable(lpToken1).forceApprove(unirouter, type(uint256).max);

        for (uint i; i < rewardTokens.length;) {
            IERC20Upgradeable(rewardTokens[i]).forceApprove(unirouter, 0);
            IERC20Upgradeable(rewardTokens[i]).forceApprove(unirouter, type(uint256).max);

            IERC20Upgradeable(rewardTokens[i]).forceApprove(rewardPool, 0);
            IERC20Upgradeable(rewardTokens[i]).forceApprove(rewardPool, type(uint256).max);
            unchecked { ++i; }
        }
    }

    /// @notice removes swap permisions for the tokens from the unirouter.
    function _removeAllowances() private {
        IERC20Upgradeable(lpToken0).forceApprove(unirouter, 0);
        IERC20Upgradeable(lpToken1).forceApprove(unirouter, 0);

        for (uint i; i < rewardTokens.length;) {
            IERC20Upgradeable(rewardTokens[i]).forceApprove(unirouter, 0);
            IERC20Upgradeable(rewardTokens[i]).forceApprove(rewardPool, 0);
            unchecked { ++i; }
        }
    }
}

File 2 of 32 : draft-IERC20Permit.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 */
interface IERC20Permit {
    /**
     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
     * given ``owner``'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

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

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

File 3 of 32 : IERC20Metadata.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";

/**
 * @dev Interface for the optional metadata functions from the ERC20 standard.
 *
 * _Available since v4.1._
 */
interface IERC20Metadata is IERC20 {
    /**
     * @dev Returns the name of the token.
     */
    function name() external view returns (string memory);

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

    /**
     * @dev Returns the decimals places of the token.
     */
    function decimals() external view returns (uint8);
}

File 4 of 32 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
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 amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

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

    /**
     * @dev Moves `amount` 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 amount) 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 `amount` 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 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `from` to `to` using the
     * allowance mechanism. `amount` 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 amount
    ) external returns (bool);
}

File 5 of 32 : SafeERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";
import "../extensions/draft-IERC20Permit.sol";
import "../../../utils/Address.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 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 {
    using Address for address;

    function safeTransfer(
        IERC20 token,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    function safeTransferFrom(
        IERC20 token,
        address from,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

    /**
     * @dev Deprecated. This function has issues similar to the ones found in
     * {IERC20-approve}, and its usage is discouraged.
     *
     * Whenever possible, use {safeIncreaseAllowance} and
     * {safeDecreaseAllowance} instead.
     */
    function safeApprove(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero. To increase and decrease it, use
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
        require(
            (value == 0) || (token.allowance(address(this), spender) == 0),
            "SafeERC20: approve from non-zero to non-zero allowance"
        );
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
    }

    function safeIncreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        uint256 newAllowance = token.allowance(address(this), spender) + value;
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

    function safeDecreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            uint256 newAllowance = oldAllowance - value;
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
        }
    }

    function safePermit(
        IERC20Permit token,
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal {
        uint256 nonceBefore = token.nonces(owner);
        token.permit(owner, spender, value, deadline, v, r, s);
        uint256 nonceAfter = token.nonces(owner);
        require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
    }

    /**
     * @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).
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
        if (returndata.length > 0) {
            // Return data is optional
            require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
        }
    }
}

File 6 of 32 : Address.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 0;
    }

    /**
     * @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://diligence.consensys.net/posts/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.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @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, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * 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.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCall(target, data, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @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`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        require(isContract(target), "Address: call to non-contract");

        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        require(isContract(target), "Address: static call to non-contract");

        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(isContract(target), "Address: delegate call to non-contract");

        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            // 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
                /// @solidity memory-safe-assembly
                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}

File 7 of 32 : SignedMath.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (utils/math/SignedMath.sol)

pragma solidity ^0.8.0;

/**
 * @dev Standard signed math utilities missing in the Solidity language.
 */
library SignedMath {
    /**
     * @dev Returns the largest of two signed numbers.
     */
    function max(int256 a, int256 b) internal pure returns (int256) {
        return a >= b ? a : b;
    }

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

    /**
     * @dev Returns the average of two signed numbers without overflow.
     * The result is rounded towards zero.
     */
    function average(int256 a, int256 b) internal pure returns (int256) {
        // Formula from the book "Hacker's Delight"
        int256 x = (a & b) + ((a ^ b) >> 1);
        return x + (int256(uint256(x) >> 255) & (a ^ b));
    }

    /**
     * @dev Returns the absolute unsigned value of a signed value.
     */
    function abs(int256 n) internal pure returns (uint256) {
        unchecked {
            // must be unchecked in order to support `n = type(int256).min`
            return uint256(n >= 0 ? n : -n);
        }
    }
}

File 8 of 32 : OwnableUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)

pragma solidity ^0.8.0;

import "../utils/ContextUpgradeable.sol";
import {Initializable} from "../proxy/utils/Initializable.sol";

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

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

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    function __Ownable_init() internal onlyInitializing {
        __Ownable_init_unchained();
    }

    function __Ownable_init_unchained() internal onlyInitializing {
        _transferOwnership(_msgSender());
    }

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

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

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
    }

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

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        _transferOwnership(newOwner);
    }

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

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[49] private __gap;
}

File 9 of 32 : Initializable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol)

pragma solidity ^0.8.2;

import "../../utils/AddressUpgradeable.sol";

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

    /**
     * @dev Indicates that the contract is in the process of being initialized.
     */
    bool private _initializing;

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

    /**
     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
     * `onlyInitializing` functions can be used to initialize parent contracts.
     *
     * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a
     * constructor.
     *
     * Emits an {Initialized} event.
     */
    modifier initializer() {
        bool isTopLevelCall = !_initializing;
        require(
            (isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),
            "Initializable: contract is already initialized"
        );
        _initialized = 1;
        if (isTopLevelCall) {
            _initializing = true;
        }
        _;
        if (isTopLevelCall) {
            _initializing = false;
            emit Initialized(1);
        }
    }

    /**
     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
     * used to initialize parent contracts.
     *
     * A reinitializer may be used after the original initialization step. This is essential to configure modules that
     * are added through upgrades and that require initialization.
     *
     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
     * cannot be nested. If one is invoked in the context of another, execution will revert.
     *
     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
     * a contract, executing them in the right order is up to the developer or operator.
     *
     * WARNING: setting the version to 255 will prevent any future reinitialization.
     *
     * Emits an {Initialized} event.
     */
    modifier reinitializer(uint8 version) {
        require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
        _initialized = version;
        _initializing = true;
        _;
        _initializing = false;
        emit Initialized(version);
    }

    /**
     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
     * {initializer} and {reinitializer} modifiers, directly or indirectly.
     */
    modifier onlyInitializing() {
        require(_initializing, "Initializable: contract is not initializing");
        _;
    }

    /**
     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called
     * through proxies.
     *
     * Emits an {Initialized} event the first time it is successfully executed.
     */
    function _disableInitializers() internal virtual {
        require(!_initializing, "Initializable: contract is initializing");
        if (_initialized != type(uint8).max) {
            _initialized = type(uint8).max;
            emit Initialized(type(uint8).max);
        }
    }

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

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

File 10 of 32 : PausableUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)

pragma solidity ^0.8.0;

import "../utils/ContextUpgradeable.sol";
import {Initializable} from "../proxy/utils/Initializable.sol";

/**
 * @dev Contract module which allows children to implement an emergency stop
 * mechanism that can be triggered by an authorized account.
 *
 * This module is used through inheritance. It will make available the
 * modifiers `whenNotPaused` and `whenPaused`, which can be applied to
 * the functions of your contract. Note that they will not be pausable by
 * simply including this module, only once the modifiers are put in place.
 */
abstract contract PausableUpgradeable is Initializable, ContextUpgradeable {
    /**
     * @dev Emitted when the pause is triggered by `account`.
     */
    event Paused(address account);

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

    bool private _paused;

    /**
     * @dev Initializes the contract in unpaused state.
     */
    function __Pausable_init() internal onlyInitializing {
        __Pausable_init_unchained();
    }

    function __Pausable_init_unchained() internal onlyInitializing {
        _paused = false;
    }

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

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

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

    /**
     * @dev Throws if the contract is paused.
     */
    function _requireNotPaused() internal view virtual {
        require(!paused(), "Pausable: paused");
    }

    /**
     * @dev Throws if the contract is not paused.
     */
    function _requirePaused() internal view virtual {
        require(paused(), "Pausable: not paused");
    }

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

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

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[49] private __gap;
}

File 11 of 32 : IERC20PermitUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (token/ERC20/extensions/IERC20Permit.sol)

pragma solidity ^0.8.0;

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

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

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

File 12 of 32 : IERC20Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20Upgradeable {
    /**
     * @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 amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

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

    /**
     * @dev Moves `amount` 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 amount) 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 `amount` 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 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `from` to `to` using the
     * allowance mechanism. `amount` 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 amount) external returns (bool);
}

File 13 of 32 : SafeERC20Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.3) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "../IERC20Upgradeable.sol";
import "../extensions/IERC20PermitUpgradeable.sol";
import "../../../utils/AddressUpgradeable.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 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 SafeERC20Upgradeable {
    using AddressUpgradeable for address;

    /**
     * @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(IERC20Upgradeable token, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, 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(IERC20Upgradeable token, address from, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

    /**
     * @dev Deprecated. This function has issues similar to the ones found in
     * {IERC20-approve}, and its usage is discouraged.
     *
     * Whenever possible, use {safeIncreaseAllowance} and
     * {safeDecreaseAllowance} instead.
     */
    function safeApprove(IERC20Upgradeable token, address spender, uint256 value) internal {
        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero. To increase and decrease it, use
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
        require(
            (value == 0) || (token.allowance(address(this), spender) == 0),
            "SafeERC20: approve from non-zero to non-zero allowance"
        );
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 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.
     */
    function safeIncreaseAllowance(IERC20Upgradeable token, address spender, uint256 value) internal {
        uint256 oldAllowance = token.allowance(address(this), spender);
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeDecreaseAllowance(IERC20Upgradeable token, address spender, uint256 value) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));
        }
    }

    /**
     * @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.
     */
    function forceApprove(IERC20Upgradeable token, address spender, uint256 value) internal {
        bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);

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

    /**
     * @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
     * Revert on invalid signature.
     */
    function safePermit(
        IERC20PermitUpgradeable token,
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal {
        uint256 nonceBefore = token.nonces(owner);
        token.permit(owner, spender, value, deadline, v, r, s);
        uint256 nonceAfter = token.nonces(owner);
        require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
    }

    /**
     * @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).
     */
    function _callOptionalReturn(IERC20Upgradeable token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
        require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
    }

    /**
     * @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 silents catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20Upgradeable token, bytes memory data) private returns (bool) {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
        // and not revert is the subcall reverts.

        (bool success, bytes memory returndata) = address(token).call(data);
        return
            success && (returndata.length == 0 || abi.decode(returndata, (bool))) && AddressUpgradeable.isContract(address(token));
    }
}

File 14 of 32 : AddressUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @dev Collection of functions related to the address type
 */
library AddressUpgradeable {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     *
     * Furthermore, `isContract` will also return true if the target contract within
     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
     * which only has an effect at the end of a transaction.
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 0;
    }

    /**
     * @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.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @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, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * 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.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @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`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

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

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");
    }

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

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
     *
     * _Available since v4.8._
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        if (success) {
            if (returndata.length == 0) {
                // only check isContract if the call was successful and the return data is empty
                // otherwise we already know that it was a contract
                require(isContract(target), "Address: call to non-contract");
            }
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason or using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    function _revert(bytes memory returndata, string memory errorMessage) 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
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert(errorMessage);
        }
    }
}

File 15 of 32 : ContextUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (utils/Context.sol)

pragma solidity ^0.8.0;
import {Initializable} from "../proxy/utils/Initializable.sol";

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

    function __Context_init_unchained() internal onlyInitializing {
    }
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

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

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

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[50] private __gap;
}

File 16 of 32 : IBeefyRewardPool.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.19;

interface IBeefyRewardPool {
    function stake(uint256 amount) external;
    function withdraw(uint256 amount) external;
    function getReward() external;
    function earned(address user, address reward) external view returns (uint256);
    function notifyRewardAmount(address reward, uint256 amount, uint256 duration) external;
    function removeReward(address reward, address recipient) external;
    function rescueTokens(address token, address recipient) external;
    function setWhitelist(address manager, bool whitelisted) external;
    function transferOwnership(address owner) external;
}

File 17 of 32 : IBeefySwapper.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

interface IBeefySwapper {
    function swap(
        address fromToken,
        address toToken,
        uint256 amountIn
    ) external returns (uint256 amountOut);

    function swap(
        address fromToken,
        address toToken,
        uint256 amountIn,
        uint256 minAmountOut
    ) external returns (uint256 amountOut);

    function getAmountOut(
        address _fromToken,
        address _toToken,
        uint256 _amountIn
    ) external view returns (uint256 amountOut);

    function swapInfo(
        address _fromToken,
        address _toToken
    ) external view returns (
        address router,
        bytes calldata data,
        uint256 amountIndex,
        uint256 minIndex,
        int8 minAmountSign
    );

    struct SwapInfo {
        address router;
        bytes data;
        uint256 amountIndex;
        uint256 minIndex;
        int8 minAmountSign;
    }
}

interface ISimplifiedSwapInfo {
    function swapInfo(address _fromToken, address _toToken) external view returns (address router, bytes calldata data);
}

File 18 of 32 : IBeefyVaultConcLiq.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;

interface IBeefyVaultConcLiq {
    function previewDeposit(uint256 _amount0, uint256 _amount1) external view returns (uint256 shares);
    function previewWithdraw(uint256 shares) external view returns (uint256 amount0, uint256 amount1);
    function strategy() external view returns (address);
    function totalSupply() external view returns (uint256);
}

File 19 of 32 : IStrategyConcLiq.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;

interface IStrategyConcLiq {
    function balances() external view returns (uint256, uint256);
    function beforeAction() external;
    function deposit() external;
    function withdraw(uint256 _amount0, uint256 _amount1) external;
    function pool() external view returns (address);
    function lpToken0() external view returns (address);
    function lpToken1() external view returns (address);
    function isCalm() external view returns (bool);
    function swapFee() external view returns (uint256);
    
    /// @notice The current price of the pool in token1, encoded with `36 + lpToken1.decimals - lpToken0.decimals`.
    /// @return _price The current price of the pool in token1.
    function price() external view returns (uint256 _price);

}

File 20 of 32 : IStrategyFactory.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface IStrategyFactory {
    function createStrategy(string calldata _strategyName) external returns (address);
    function native() external view returns (address);
    function keeper() external view returns (address);
    function rebalancers(address) external view returns (bool);
    function beefyFeeRecipient() external view returns (address);
    function beefyFeeConfig() external view returns (address);
    function globalPause() external view returns (bool);
    function strategyPause(string calldata stratName) external view returns (bool);
}

File 21 of 32 : IFeeConfig.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

interface IFeeConfig {
    struct FeeCategory {
        uint256 total;
        uint256 beefy;
        uint256 call;
        uint256 strategist;
        string label;
        bool active;
    }
    struct AllFees {
        FeeCategory performance;
        uint256 deposit;
        uint256 withdraw;
    }
    function getFees(address strategy) external view returns (FeeCategory memory);
    function stratFeeId(address strategy) external view returns (uint256);
    function setStratFeeId(uint256 feeId) external;
}

File 22 of 32 : IUniswapRouterV3WithDeadline.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;


interface IUniswapRouterV3WithDeadline {
    struct ExactInputSingleParams {
        address tokenIn;
        address tokenOut;
        uint24 fee;
        address recipient;
        uint256 deadline;
        uint256 amountIn;
        uint256 amountOutMinimum;
        uint160 sqrtPriceLimitX96;
    }

    /// @notice Swaps `amountIn` of one token for as much as possible of another token
    /// @param params The parameters necessary for the swap, encoded as `ExactInputSingleParams` in calldata
    /// @return amountOut The amount of the received token
    function exactInputSingle(ExactInputSingleParams calldata params) external payable returns (uint256 amountOut);

    struct ExactInputParams {
        bytes path;
        address recipient;
        uint256 deadline;
        uint256 amountIn;
        uint256 amountOutMinimum;
    }

    /// @notice Swaps `amountIn` of one token for as much as possible of another along the specified path
    /// @param params The parameters necessary for the multi-hop swap, encoded as `ExactInputParams` in calldata
    /// @return amountOut The amount of the received token
    function exactInput(ExactInputParams calldata params) external payable returns (uint256 amountOut);

    struct ExactOutputSingleParams {
        address tokenIn;
        address tokenOut;
        uint24 fee;
        address recipient;
        uint256 deadline;
        uint256 amountOut;
        uint256 amountInMaximum;
        uint160 sqrtPriceLimitX96;
    }

    /// @notice Swaps as little as possible of one token for `amountOut` of another token
    /// @param params The parameters necessary for the swap, encoded as `ExactOutputSingleParams` in calldata
    /// @return amountIn The amount of the input token
    function exactOutputSingle(ExactOutputSingleParams calldata params) external payable returns (uint256 amountIn);

    struct ExactOutputParams {
        bytes path;
        address recipient;
        uint256 deadline;
        uint256 amountOut;
        uint256 amountInMaximum;
    }

    /// @notice Swaps as little as possible of one token for `amountOut` of another along the specified path (reversed)
    /// @param params The parameters necessary for the multi-hop swap, encoded as `ExactOutputParams` in calldata
    /// @return amountIn The amount of the input token
    function exactOutput(ExactOutputParams calldata params) external payable returns (uint256 amountIn);
}

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

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

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

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

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

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

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

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

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

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

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

    /// @notice Returns the cumulative tick and liquidity as of each timestamp `secondsAgo` from the current block timestamp
    /// @dev To get a time weighted average tick or liquidity-in-range, you must call this with two values, one representing
    /// the beginning of the period and another for the end of the period. E.g., to get the last hour time-weighted average tick,
    /// you must call it with secondsAgos = [3600, 0].
    /// @dev The time weighted average tick represents the geometric time weighted average price of the pool, in
    /// log base sqrt(1.0001) of token1 / token0. The TickMath library can be used to go from a tick value to a ratio.
    /// @param secondsAgos From how long ago each cumulative tick and liquidity value should be returned
    /// @return tickCumulatives Cumulative tick values as of each `secondsAgos` from the current block timestamp
    /// @return secondsPerLiquidityCumulativeX128s Cumulative seconds per liquidity-in-range value as of each `secondsAgos` from the current block timestamp
    function observe(
        uint32[] calldata secondsAgos
    )
        external
        view
        returns (
            int56[] memory tickCumulatives,
            uint160[] memory secondsPerLiquidityCumulativeX128s
        );

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

    /// @notice Returns the seconds per liquidity and seconds inside a tick range for a period
    /// @param tickLower The lower tick of the range
    /// @param tickUpper The upper tick of the range
    /// @return secondsPerLiquidityInsideX128 The snapshot of seconds per liquidity for the range
    function periodCumulativesInside(
        uint32 period,
        int24 tickLower,
        int24 tickUpper
    ) external view returns (uint160 secondsPerLiquidityInsideX128);

    /// @notice The contract that deployed the pool, which must adhere to the IClPoolFactory interface
    /// @return The contract address
    function factory() external view returns (address);

    /// @notice The contract that manages CL NFPs, which must adhere to the INonfungiblePositionManager interface
    /// @return The contract address
    function nfpManager() external view returns (address);

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

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

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

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

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

    /// @notice returns the current fee set for the pool
    function currentFee() external view returns (uint24);

    /// @notice reads arbitrary storage slots and returns the bytes
    /// @param slots The slots to read from
    /// @return returnData The data read from the slots
    function readStorage(
        bytes32[] calldata slots
    ) external view returns (bytes32[] memory returnData);

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

    /// @notice Returns the last tick of a given period
    /// @param period The period in question
    /// @return previousPeriod The period before current period
    /// @dev this is because there might be periods without trades
    ///  startTick The start tick of the period
    ///  lastTick The last tick of the period, if the period is finished
    function periods(
        uint256 period
    )
        external
        view
        returns (
            uint32 previousPeriod,
            int24 startTick,
            int24 lastTick,
            uint160 endSecondsPerLiquidityCumulativeX128
        );

    /// @notice The last period where a trade or liquidity change happened
    function lastPeriod() external view returns (uint256);

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

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

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

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

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

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

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

    /// @notice Get the period seconds debt of a specific position
    /// @param period the period number
    /// @param recipient recipient address
    /// @param index position index
    /// @param tickLower lower bound of range
    /// @param tickUpper upper bound of range
    /// @return secondsDebtX96 seconds the position was not in range for the period
    function positionPeriodDebt(
        uint256 period,
        address recipient,
        uint256 index,
        int24 tickLower,
        int24 tickUpper
    ) external view returns (int256 secondsDebtX96);

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

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

File 24 of 32 : IRamsesGauge.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;

interface IRamsesGauge  {
    function getReward(
        address owner,
        uint256 index,
        int24 tickLower,
        int24 tickUpper,
        address[] memory tokens,
        address receiver
    ) external;
}

File 25 of 32 : StratFeeCowManagerInitializable.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.23;

import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import {PausableUpgradeable} from "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
import {IFeeConfig} from "../../interfaces/common/IFeeConfig.sol";
import {IStrategyFactory} from "../../interfaces/beefy/IStrategyFactory.sol";

contract StratFeeCowManagerInitializable is OwnableUpgradeable, PausableUpgradeable {
    struct CommonAddresses {
        address vault;
        address unirouter;
        address strategist;
        address factory;
    }

    /// @notice The native address of the chain
    address public native;

    /// @notice The address of the vault
    address public vault;

    /// @notice The address of the unirouter
    address public unirouter;

    /// @notice The address of the strategist
    address public strategist;

    /// @notice The address of the strategy factory
    IStrategyFactory public factory;

    /// @notice The total amount of token0 locked in the vault
    uint256 public totalLocked0;

    /// @notice The total amount of token1 locked in the vault
    uint256 public totalLocked1;

    /// @notice The last time the strat harvested
    uint256 public lastHarvest;

    /// @notice The last time we adjusted the position
    uint256 public lastPositionAdjustment;

    /// @notice The duration of the locked rewards
    uint256 constant DURATION = 1 hours;

    /// @notice The divisor used to calculate the fee
    uint256 constant DIVISOR = 1 ether;


    // Events
    event SetStratFeeId(uint256 feeId);
    event SetUnirouter(address unirouter);
    event SetStrategist(address strategist);

    // Errors
    error NotManager();
    error NotStrategist();
    error OverLimit();
    error StrategyPaused();

    /**
     * @notice Initialize the Strategy Fee Manager inherited contract with the common addresses
     * @param _commonAddresses The common addresses of the vault, unirouter, keeper, strategist, beefyFeeRecipient and beefyFeeConfig
     */
    function __StratFeeManager_init(CommonAddresses calldata _commonAddresses) internal onlyInitializing {
        __Ownable_init();
        __Pausable_init();
        vault = _commonAddresses.vault;
        unirouter = _commonAddresses.unirouter;
        strategist = _commonAddresses.strategist;
        factory = IStrategyFactory(_commonAddresses.factory);
        native = factory.native();
    }

    /**
     * @notice function that throws if the strategy is paused
     */
    function _whenStrategyNotPaused() internal view {
        if (paused() || factory.globalPause()) revert StrategyPaused();
    }

    /**
     * @notice function that returns true if the strategy is paused
     */
    function _isPaused() internal view returns (bool) {
        return paused() || factory.globalPause();
    }

    /** 
     * @notice Modifier that throws if called by any account other than the manager or the owner
    */
    modifier onlyManager() {
        if (msg.sender != owner() && msg.sender != keeper()) revert NotManager();
        _;
    }

    /// @notice The address of the keeper, set on the factory. 
    function keeper() public view returns (address) {
        return factory.keeper();
    }

    /// @notice The address of the beefy fee recipient, set on the factory.
    function beefyFeeRecipient() public view returns (address) {
        return factory.beefyFeeRecipient();
    }

    /// @notice The address of the beefy fee config, set on the factory.
    function beefyFeeConfig() public view returns (IFeeConfig) {
        return IFeeConfig(factory.beefyFeeConfig());
    }

    /**
     * @notice get the fees breakdown from the fee config for this contract
     * @return IFeeConfig.FeeCategory The fees breakdown
     */
    function getFees() internal view returns (IFeeConfig.FeeCategory memory) {
        return beefyFeeConfig().getFees(address(this));
    }

    /**
     * @notice get all the fees from the fee config for this contract
     * @return IFeeConfig.AllFees The fees
     */
    function getAllFees() external view returns (IFeeConfig.AllFees memory) {
        return IFeeConfig.AllFees(getFees(), depositFee(), withdrawFee());
    }

    /**
     * @notice get the strat fee id from the fee config
     * @return uint256 The strat fee id
     */
    function getStratFeeId() external view returns (uint256) {
        return beefyFeeConfig().stratFeeId(address(this));
    }

    /**
     * @notice set the strat fee id in the fee config
     * @param _feeId The new strat fee id
     */
    function setStratFeeId(uint256 _feeId) external onlyManager {
        beefyFeeConfig().setStratFeeId(_feeId);
        emit SetStratFeeId(_feeId);
    }

    /**
     * @notice set the unirouter address
     * @param _unirouter The new unirouter address
     */
    function setUnirouter(address _unirouter) external virtual onlyOwner {
        unirouter = _unirouter;
        emit SetUnirouter(_unirouter);
    }

    /**
     * @notice set the strategist address
     * @param _strategist The new strategist address
     */
    function setStrategist(address _strategist) external {
        if (msg.sender != strategist) revert NotStrategist();
        strategist = _strategist;
        emit SetStrategist(_strategist);
    }

    /**
     * @notice The deposit fee variable will alwasy be 0. This is used by the UI. 
     * @return uint256 The deposit fee
     */
    function depositFee() public virtual view returns (uint256) {
        return 0;
    }

    /**
     * @notice The withdraw fee variable will alwasy be 0. This is used by the UI. 
     * @return uint256 The withdraw fee
     */
    function withdrawFee() public virtual view returns (uint256) {
        return 0;
    }

    /**
     * @notice The locked profit is the amount of token0 and token1 that is locked in the vault, this can be overriden by the strategy contract.
     * @return locked0 The amount of token0 locked
     * @return locked1 The amount of token1 locked
     */
    function lockedProfit() public virtual view returns (uint256 locked0, uint256 locked1) {
        uint256 elapsed = block.timestamp - lastHarvest;
        uint256 remaining = elapsed < DURATION ? DURATION - elapsed : 0;
        return (totalLocked0 * remaining / DURATION, totalLocked1 * remaining / DURATION);
    }

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[49] private __gap;
}

File 26 of 32 : BytesLib.sol
// SPDX-License-Identifier: Unlicense
/*
 * @title Solidity Bytes Arrays Utils
 * @author Gonçalo Sá <[email protected]>
 *
 * @dev Bytes tightly packed arrays utility library for ethereum contracts written in Solidity.
 *      The library lets you concatenate, slice and type cast bytes arrays both in memory and storage.
 */
pragma solidity >=0.8.0 <0.9.0;


library BytesLib {
    function concat(
        bytes memory _preBytes,
        bytes memory _postBytes
    )
    internal
    pure
    returns (bytes memory)
    {
        bytes memory tempBytes;

        assembly {
        // Get a location of some free memory and store it in tempBytes as
        // Solidity does for memory variables.
            tempBytes := mload(0x40)

        // Store the length of the first bytes array at the beginning of
        // the memory for tempBytes.
            let length := mload(_preBytes)
            mstore(tempBytes, length)

        // Maintain a memory counter for the current write location in the
        // temp bytes array by adding the 32 bytes for the array length to
        // the starting location.
            let mc := add(tempBytes, 0x20)
        // Stop copying when the memory counter reaches the length of the
        // first bytes array.
            let end := add(mc, length)

            for {
            // Initialize a copy counter to the start of the _preBytes data,
            // 32 bytes into its memory.
                let cc := add(_preBytes, 0x20)
            } lt(mc, end) {
            // Increase both counters by 32 bytes each iteration.
                mc := add(mc, 0x20)
                cc := add(cc, 0x20)
            } {
            // Write the _preBytes data into the tempBytes memory 32 bytes
            // at a time.
                mstore(mc, mload(cc))
            }

        // Add the length of _postBytes to the current length of tempBytes
        // and store it as the new length in the first 32 bytes of the
        // tempBytes memory.
            length := mload(_postBytes)
            mstore(tempBytes, add(length, mload(tempBytes)))

        // Move the memory counter back from a multiple of 0x20 to the
        // actual end of the _preBytes data.
            mc := end
        // Stop copying when the memory counter reaches the new combined
        // length of the arrays.
            end := add(mc, length)

            for {
                let cc := add(_postBytes, 0x20)
            } lt(mc, end) {
                mc := add(mc, 0x20)
                cc := add(cc, 0x20)
            } {
                mstore(mc, mload(cc))
            }

        // Update the free-memory pointer by padding our last write location
        // to 32 bytes: add 31 bytes to the end of tempBytes to move to the
        // next 32 byte block, then round down to the nearest multiple of
        // 32. If the sum of the length of the two arrays is zero then add
        // one before rounding down to leave a blank 32 bytes (the length block with 0).
            mstore(0x40, and(
            add(add(end, iszero(add(length, mload(_preBytes)))), 31),
            not(31) // Round down to the nearest 32 bytes.
            ))
        }

        return tempBytes;
    }

    function concatStorage(bytes storage _preBytes, bytes memory _postBytes) internal {
        assembly {
        // Read the first 32 bytes of _preBytes storage, which is the length
        // of the array. (We don't need to use the offset into the slot
        // because arrays use the entire slot.)
            let fslot := sload(_preBytes.slot)
        // Arrays of 31 bytes or less have an even value in their slot,
        // while longer arrays have an odd value. The actual length is
        // the slot divided by two for odd values, and the lowest order
        // byte divided by two for even values.
        // If the slot is even, bitwise and the slot with 255 and divide by
        // two to get the length. If the slot is odd, bitwise and the slot
        // with -1 and divide by two.
            let slength := div(and(fslot, sub(mul(0x100, iszero(and(fslot, 1))), 1)), 2)
            let mlength := mload(_postBytes)
            let newlength := add(slength, mlength)
        // slength can contain both the length and contents of the array
        // if length < 32 bytes so let's prepare for that
        // v. http://solidity.readthedocs.io/en/latest/miscellaneous.html#layout-of-state-variables-in-storage
            switch add(lt(slength, 32), lt(newlength, 32))
            case 2 {
            // Since the new array still fits in the slot, we just need to
            // update the contents of the slot.
            // uint256(bytes_storage) = uint256(bytes_storage) + uint256(bytes_memory) + new_length
                sstore(
                _preBytes.slot,
                // all the modifications to the slot are inside this
                // next block
                add(
                // we can just add to the slot contents because the
                // bytes we want to change are the LSBs
                fslot,
                add(
                mul(
                div(
                // load the bytes from memory
                mload(add(_postBytes, 0x20)),
                // zero all bytes to the right
                exp(0x100, sub(32, mlength))
                ),
                // and now shift left the number of bytes to
                // leave space for the length in the slot
                exp(0x100, sub(32, newlength))
                ),
                // increase length by the double of the memory
                // bytes length
                mul(mlength, 2)
                )
                )
                )
            }
            case 1 {
            // The stored value fits in the slot, but the combined value
            // will exceed it.
            // get the keccak hash to get the contents of the array
                mstore(0x0, _preBytes.slot)
                let sc := add(keccak256(0x0, 0x20), div(slength, 32))

            // save new length
                sstore(_preBytes.slot, add(mul(newlength, 2), 1))

            // The contents of the _postBytes array start 32 bytes into
            // the structure. Our first read should obtain the `submod`
            // bytes that can fit into the unused space in the last word
            // of the stored array. To get this, we read 32 bytes starting
            // from `submod`, so the data we read overlaps with the array
            // contents by `submod` bytes. Masking the lowest-order
            // `submod` bytes allows us to add that value directly to the
            // stored value.

                let submod := sub(32, slength)
                let mc := add(_postBytes, submod)
                let end := add(_postBytes, mlength)
                let mask := sub(exp(0x100, submod), 1)

                sstore(
                sc,
                add(
                and(
                fslot,
                0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00
                ),
                and(mload(mc), mask)
                )
                )

                for {
                    mc := add(mc, 0x20)
                    sc := add(sc, 1)
                } lt(mc, end) {
                    sc := add(sc, 1)
                    mc := add(mc, 0x20)
                } {
                    sstore(sc, mload(mc))
                }

                mask := exp(0x100, sub(mc, end))

                sstore(sc, mul(div(mload(mc), mask), mask))
            }
            default {
            // get the keccak hash to get the contents of the array
                mstore(0x0, _preBytes.slot)
            // Start copying to the last used word of the stored array.
                let sc := add(keccak256(0x0, 0x20), div(slength, 32))

            // save new length
                sstore(_preBytes.slot, add(mul(newlength, 2), 1))

            // Copy over the first `submod` bytes of the new data as in
            // case 1 above.
                let slengthmod := mod(slength, 32)
                let mlengthmod := mod(mlength, 32)
                let submod := sub(32, slengthmod)
                let mc := add(_postBytes, submod)
                let end := add(_postBytes, mlength)
                let mask := sub(exp(0x100, submod), 1)

                sstore(sc, add(sload(sc), and(mload(mc), mask)))

                for {
                    sc := add(sc, 1)
                    mc := add(mc, 0x20)
                } lt(mc, end) {
                    sc := add(sc, 1)
                    mc := add(mc, 0x20)
                } {
                    sstore(sc, mload(mc))
                }

                mask := exp(0x100, sub(mc, end))

                sstore(sc, mul(div(mload(mc), mask), mask))
            }
        }
    }

    function slice(
        bytes memory _bytes,
        uint256 _start,
        uint256 _length
    )
    internal
    pure
    returns (bytes memory)
    {
        require(_length + 31 >= _length, "slice_overflow");
        require(_bytes.length >= _start + _length, "slice_outOfBounds");

        bytes memory tempBytes;

        assembly {
            switch iszero(_length)
            case 0 {
            // Get a location of some free memory and store it in tempBytes as
            // Solidity does for memory variables.
                tempBytes := mload(0x40)

            // The first word of the slice result is potentially a partial
            // word read from the original array. To read it, we calculate
            // the length of that partial word and start copying that many
            // bytes into the array. The first word we copy will start with
            // data we don't care about, but the last `lengthmod` bytes will
            // land at the beginning of the contents of the new array. When
            // we're done copying, we overwrite the full first word with
            // the actual length of the slice.
                let lengthmod := and(_length, 31)

            // The multiplication in the next line is necessary
            // because when slicing multiples of 32 bytes (lengthmod == 0)
            // the following copy loop was copying the origin's length
            // and then ending prematurely not copying everything it should.
                let mc := add(add(tempBytes, lengthmod), mul(0x20, iszero(lengthmod)))
                let end := add(mc, _length)

                for {
                // The multiplication in the next line has the same exact purpose
                // as the one above.
                    let cc := add(add(add(_bytes, lengthmod), mul(0x20, iszero(lengthmod))), _start)
                } lt(mc, end) {
                    mc := add(mc, 0x20)
                    cc := add(cc, 0x20)
                } {
                    mstore(mc, mload(cc))
                }

                mstore(tempBytes, _length)

            //update free-memory pointer
            //allocating the array padded to 32 bytes like the compiler does now
                mstore(0x40, and(add(mc, 31), not(31)))
            }
            //if we want a zero-length slice let's just return a zero-length array
            default {
                tempBytes := mload(0x40)
            //zero out the 32 bytes slice we are about to return
            //we need to do it because Solidity does not garbage collect
                mstore(tempBytes, 0)

                mstore(0x40, add(tempBytes, 0x20))
            }
        }

        return tempBytes;
    }

    function toAddress(bytes memory _bytes, uint256 _start) internal pure returns (address) {
        require(_bytes.length >= _start + 20, "toAddress_outOfBounds");
        address tempAddress;

        assembly {
            tempAddress := div(mload(add(add(_bytes, 0x20), _start)), 0x1000000000000000000000000)
        }

        return tempAddress;
    }

    function toUint8(bytes memory _bytes, uint256 _start) internal pure returns (uint8) {
        require(_bytes.length >= _start + 1 , "toUint8_outOfBounds");
        uint8 tempUint;

        assembly {
            tempUint := mload(add(add(_bytes, 0x1), _start))
        }

        return tempUint;
    }

    function toUint16(bytes memory _bytes, uint256 _start) internal pure returns (uint16) {
        require(_bytes.length >= _start + 2, "toUint16_outOfBounds");
        uint16 tempUint;

        assembly {
            tempUint := mload(add(add(_bytes, 0x2), _start))
        }

        return tempUint;
    }

    function toUint24(bytes memory _bytes, uint256 _start) internal pure returns (uint24) {
        require(_start + 3 >= _start, 'toUint24_overflow');
        require(_bytes.length >= _start + 3, 'toUint24_outOfBounds');
        uint24 tempUint;

        assembly {
            tempUint := mload(add(add(_bytes, 0x3), _start))
        }

        return tempUint;
    }

    function toUint32(bytes memory _bytes, uint256 _start) internal pure returns (uint32) {
        require(_bytes.length >= _start + 4, "toUint32_outOfBounds");
        uint32 tempUint;

        assembly {
            tempUint := mload(add(add(_bytes, 0x4), _start))
        }

        return tempUint;
    }

    function toUint64(bytes memory _bytes, uint256 _start) internal pure returns (uint64) {
        require(_bytes.length >= _start + 8, "toUint64_outOfBounds");
        uint64 tempUint;

        assembly {
            tempUint := mload(add(add(_bytes, 0x8), _start))
        }

        return tempUint;
    }

    function toUint96(bytes memory _bytes, uint256 _start) internal pure returns (uint96) {
        require(_bytes.length >= _start + 12, "toUint96_outOfBounds");
        uint96 tempUint;

        assembly {
            tempUint := mload(add(add(_bytes, 0xc), _start))
        }

        return tempUint;
    }

    function toUint128(bytes memory _bytes, uint256 _start) internal pure returns (uint128) {
        require(_bytes.length >= _start + 16, "toUint128_outOfBounds");
        uint128 tempUint;

        assembly {
            tempUint := mload(add(add(_bytes, 0x10), _start))
        }

        return tempUint;
    }

    function toUint256(bytes memory _bytes, uint256 _start) internal pure returns (uint256) {
        require(_bytes.length >= _start + 32, "toUint256_outOfBounds");
        uint256 tempUint;

        assembly {
            tempUint := mload(add(add(_bytes, 0x20), _start))
        }

        return tempUint;
    }

    function toBytes32(bytes memory _bytes, uint256 _start) internal pure returns (bytes32) {
        require(_bytes.length >= _start + 32, "toBytes32_outOfBounds");
        bytes32 tempBytes32;

        assembly {
            tempBytes32 := mload(add(add(_bytes, 0x20), _start))
        }

        return tempBytes32;
    }

    function equal(bytes memory _preBytes, bytes memory _postBytes) internal pure returns (bool) {
        bool success = true;

        assembly {
            let length := mload(_preBytes)

        // if lengths don't match the arrays are not equal
            switch eq(length, mload(_postBytes))
            case 1 {
            // cb is a circuit breaker in the for loop since there's
            //  no said feature for inline assembly loops
            // cb = 1 - don't breaker
            // cb = 0 - break
                let cb := 1

                let mc := add(_preBytes, 0x20)
                let end := add(mc, length)

                for {
                    let cc := add(_postBytes, 0x20)
                // the next line is the loop condition:
                // while(uint256(mc < end) + cb == 2)
                } eq(add(lt(mc, end), cb), 2) {
                    mc := add(mc, 0x20)
                    cc := add(cc, 0x20)
                } {
                // if any of these checks fails then arrays are not equal
                    if iszero(eq(mload(mc), mload(cc))) {
                    // unsuccess:
                        success := 0
                        cb := 0
                    }
                }
            }
            default {
            // unsuccess:
                success := 0
            }
        }

        return success;
    }

    function equalStorage(
        bytes storage _preBytes,
        bytes memory _postBytes
    )
    internal
    view
    returns (bool)
    {
        bool success = true;

        assembly {
        // we know _preBytes_offset is 0
            let fslot := sload(_preBytes.slot)
        // Decode the length of the stored array like in concatStorage().
            let slength := div(and(fslot, sub(mul(0x100, iszero(and(fslot, 1))), 1)), 2)
            let mlength := mload(_postBytes)

        // if lengths don't match the arrays are not equal
            switch eq(slength, mlength)
            case 1 {
            // slength can contain both the length and contents of the array
            // if length < 32 bytes so let's prepare for that
            // v. http://solidity.readthedocs.io/en/latest/miscellaneous.html#layout-of-state-variables-in-storage
                if iszero(iszero(slength)) {
                    switch lt(slength, 32)
                    case 1 {
                    // blank the last byte which is the length
                        fslot := mul(div(fslot, 0x100), 0x100)

                        if iszero(eq(fslot, mload(add(_postBytes, 0x20)))) {
                        // unsuccess:
                            success := 0
                        }
                    }
                    default {
                    // cb is a circuit breaker in the for loop since there's
                    //  no said feature for inline assembly loops
                    // cb = 1 - don't breaker
                    // cb = 0 - break
                        let cb := 1

                    // get the keccak hash to get the contents of the array
                        mstore(0x0, _preBytes.slot)
                        let sc := keccak256(0x0, 0x20)

                        let mc := add(_postBytes, 0x20)
                        let end := add(mc, mlength)

                    // the next line is the loop condition:
                    // while(uint256(mc < end) + cb == 2)
                        for {} eq(add(lt(mc, end), cb), 2) {
                            sc := add(sc, 1)
                            mc := add(mc, 0x20)
                        } {
                            if iszero(eq(sload(sc), mload(mc))) {
                            // unsuccess:
                                success := 0
                                cb := 0
                            }
                        }
                    }
                }
            }
            default {
            // unsuccess:
                success := 0
            }
        }

        return success;
    }
}

File 27 of 32 : FullMath.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

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

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

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

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

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

            // Factor powers of two out of denominator
            // Compute largest power of two divisor of denominator.
            // Always >= 1.
            // EDIT for 0.8 compatibility:
            // see: https://ethereum.stackexchange.com/questions/96642/unary-operator-cannot-be-applied-to-type-uint256
            uint256 twos = denominator & (~denominator + 1);

            // Divide denominator by power of two
            assembly {
                denominator := div(denominator, twos)
            }

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

            // Invert denominator mod 2**256
            // Now that denominator is an odd number, it has an inverse
            // modulo 2**256 such that denominator * inv = 1 mod 2**256.
            // Compute the inverse by starting with a seed that is correct
            // correct for four bits. That is, denominator * inv = 1 mod 2**4
            uint256 inv = (3 * denominator) ^ 2;
            // Now use Newton-Raphson iteration to improve the precision.
            // Thanks to Hensel's lifting lemma, this also works in modular
            // arithmetic, doubling the correct bits in each step.
            inv *= 2 - denominator * inv; // inverse mod 2**8
            inv *= 2 - denominator * inv; // inverse mod 2**16
            inv *= 2 - denominator * inv; // inverse mod 2**32
            inv *= 2 - denominator * inv; // inverse mod 2**64
            inv *= 2 - denominator * inv; // inverse mod 2**128
            inv *= 2 - denominator * inv; // inverse mod 2**256

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

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

File 28 of 32 : LiquidityAmounts.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./FullMath.sol";

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

/// @title Liquidity amount functions
/// @notice Provides functions for computing liquidity amounts from token amounts and prices
library LiquidityAmounts {
    function toUint128(uint256 x) private pure returns (uint128 y) {
        require((y = uint128(x)) == x);
    }

    /// @notice Computes the amount of liquidity received for a given amount of token0 and price range
    /// @dev Calculates amount0 * (sqrt(upper) * sqrt(lower)) / (sqrt(upper) - sqrt(lower)).
    /// @param sqrtRatioAX96 A sqrt price
    /// @param sqrtRatioBX96 Another sqrt price
    /// @param amount0 The amount0 being sent in
    /// @return liquidity The amount of returned liquidity
    function getLiquidityForAmount0(
        uint160 sqrtRatioAX96,
        uint160 sqrtRatioBX96,
        uint256 amount0
    ) internal pure returns (uint128 liquidity) {
        if (sqrtRatioAX96 > sqrtRatioBX96)
            (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);
        uint256 intermediate =
            FullMath.mulDiv(sqrtRatioAX96, sqrtRatioBX96, FixedPoint96.Q96);
        return
            toUint128(
                FullMath.mulDiv(
                    amount0,
                    intermediate,
                    sqrtRatioBX96 - sqrtRatioAX96
                )
            );
    }

    /// @notice Computes the amount of liquidity received for a given amount of token1 and price range
    /// @dev Calculates amount1 / (sqrt(upper) - sqrt(lower)).
    /// @param sqrtRatioAX96 A sqrt price
    /// @param sqrtRatioBX96 Another sqrt price
    /// @param amount1 The amount1 being sent in
    /// @return liquidity The amount of returned liquidity
    function getLiquidityForAmount1(
        uint160 sqrtRatioAX96,
        uint160 sqrtRatioBX96,
        uint256 amount1
    ) internal pure returns (uint128 liquidity) {
        if (sqrtRatioAX96 > sqrtRatioBX96)
            (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);
        return
            toUint128(
                FullMath.mulDiv(
                    amount1,
                    FixedPoint96.Q96,
                    sqrtRatioBX96 - sqrtRatioAX96
                )
            );
    }

    /// @notice Computes the maximum amount of liquidity received for a given amount of token0, token1, the current
    /// pool prices and the prices at the tick boundaries
    function getLiquidityForAmounts(
        uint160 sqrtRatioX96,
        uint160 sqrtRatioAX96,
        uint160 sqrtRatioBX96,
        uint256 amount0,
        uint256 amount1
    ) internal pure returns (uint128 liquidity) {
        if (sqrtRatioAX96 > sqrtRatioBX96)
            (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);

        if (sqrtRatioX96 <= sqrtRatioAX96) {
            liquidity = getLiquidityForAmount0(
                sqrtRatioAX96,
                sqrtRatioBX96,
                amount0
            );
        } else if (sqrtRatioX96 < sqrtRatioBX96) {
            uint128 liquidity0 =
                getLiquidityForAmount0(sqrtRatioX96, sqrtRatioBX96, amount0);
            uint128 liquidity1 =
                getLiquidityForAmount1(sqrtRatioAX96, sqrtRatioX96, amount1);

            liquidity = liquidity0 < liquidity1 ? liquidity0 : liquidity1;
        } else {
            liquidity = getLiquidityForAmount1(
                sqrtRatioAX96,
                sqrtRatioBX96,
                amount1
            );
        }
    }

    /// @notice Computes the amount of token0 for a given amount of liquidity and a price range
    /// @param sqrtRatioAX96 A sqrt price
    /// @param sqrtRatioBX96 Another sqrt price
    /// @param liquidity The liquidity being valued
    /// @return amount0 The amount0
    function getAmount0ForLiquidity(
        uint160 sqrtRatioAX96,
        uint160 sqrtRatioBX96,
        uint128 liquidity
    ) internal pure returns (uint256 amount0) {
        if (sqrtRatioAX96 > sqrtRatioBX96)
            (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);

        return
            FullMath.mulDiv(
                uint256(liquidity) << FixedPoint96.RESOLUTION,
                sqrtRatioBX96 - sqrtRatioAX96,
                sqrtRatioBX96
            ) / sqrtRatioAX96;
    }

    /// @notice Computes the amount of token1 for a given amount of liquidity and a price range
    /// @param sqrtRatioAX96 A sqrt price
    /// @param sqrtRatioBX96 Another sqrt price
    /// @param liquidity The liquidity being valued
    /// @return amount1 The amount1
    function getAmount1ForLiquidity(
        uint160 sqrtRatioAX96,
        uint160 sqrtRatioBX96,
        uint128 liquidity
    ) internal pure returns (uint256 amount1) {
        if (sqrtRatioAX96 > sqrtRatioBX96)
            (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);

        return
            FullMath.mulDiv(
                liquidity,
                sqrtRatioBX96 - sqrtRatioAX96,
                FixedPoint96.Q96
            );
    }

    /// @notice Computes the token0 and token1 value for a given amount of liquidity, the current
    /// pool prices and the prices at the tick boundaries
    function getAmountsForLiquidity(
        uint160 sqrtRatioX96,
        uint160 sqrtRatioAX96,
        uint160 sqrtRatioBX96,
        uint128 liquidity
    ) internal pure returns (uint256 amount0, uint256 amount1) {
        if (sqrtRatioAX96 > sqrtRatioBX96)
            (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);

        if (sqrtRatioX96 <= sqrtRatioAX96) {
            amount0 = getAmount0ForLiquidity(
                sqrtRatioAX96,
                sqrtRatioBX96,
                liquidity
            );
        } else if (sqrtRatioX96 < sqrtRatioBX96) {
            amount0 = getAmount0ForLiquidity(
                sqrtRatioX96,
                sqrtRatioBX96,
                liquidity
            );
            amount1 = getAmount1ForLiquidity(
                sqrtRatioAX96,
                sqrtRatioX96,
                liquidity
            );
        } else {
            amount1 = getAmount1ForLiquidity(
                sqrtRatioAX96,
                sqrtRatioBX96,
                liquidity
            );
        }
    }
}

File 29 of 32 : Path.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.6.0;

import './BytesLib.sol';

/// @title Functions for manipulating path data for multihop swaps
library Path {
    using BytesLib for bytes;

    /// @dev The length of the bytes encoded address
    uint256 private constant ADDR_SIZE = 20;
    /// @dev The length of the bytes encoded fee
    uint256 private constant FEE_SIZE = 3;

    /// @dev The offset of a single token address and pool fee
    uint256 private constant NEXT_OFFSET = ADDR_SIZE + FEE_SIZE;
    /// @dev The offset of an encoded pool key
    uint256 private constant POP_OFFSET = NEXT_OFFSET + ADDR_SIZE;
    /// @dev The minimum length of an encoding that contains 2 or more pools
    uint256 private constant MULTIPLE_POOLS_MIN_LENGTH = POP_OFFSET + NEXT_OFFSET;

    /// @notice Returns true iff the path contains two or more pools
    /// @param path The encoded swap path
    /// @return True if path contains two or more pools, otherwise false
    function hasMultiplePools(bytes memory path) internal pure returns (bool) {
        return path.length >= MULTIPLE_POOLS_MIN_LENGTH;
    }

    /// @notice Returns the number of pools in the path
    /// @param path The encoded swap path
    /// @return The number of pools in the path
    function numPools(bytes memory path) internal pure returns (uint256) {
        // Ignore the first token address. From then on every fee and token offset indicates a pool.
        return ((path.length - ADDR_SIZE) / NEXT_OFFSET);
    }

    /// @notice Decodes the first pool in path
    /// @param path The bytes encoded swap path
    /// @return tokenA The first token of the given pool
    /// @return tokenB The second token of the given pool
    /// @return fee The fee level of the pool
    function decodeFirstPool(bytes memory path)
    internal
    pure
    returns (
        address tokenA,
        address tokenB,
        uint24 fee
    )
    {
        tokenA = path.toAddress(0);
        fee = path.toUint24(ADDR_SIZE);
        tokenB = path.toAddress(NEXT_OFFSET);
    }

    /// @notice Gets the segment corresponding to the first pool in the path
    /// @param path The bytes encoded swap path
    /// @return The segment containing all data necessary to target the first pool in the path
    function getFirstPool(bytes memory path) internal pure returns (bytes memory) {
        return path.slice(0, POP_OFFSET);
    }

    /// @notice Skips a token + fee element from the buffer and returns the remainder
    /// @param path The swap path
    /// @return The remaining token + fee elements in the path
    function skipToken(bytes memory path) internal pure returns (bytes memory) {
        return path.slice(NEXT_OFFSET, path.length - NEXT_OFFSET);
    }
}

File 30 of 32 : TickMath.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

/// @title Math library for computing sqrt prices from ticks and vice versa
/// @notice Computes sqrt price for ticks of size 1.0001, i.e. sqrt(1.0001^tick) as fixed point Q64.96 numbers. Supports
/// prices between 2**-128 and 2**128
library TickMath {
    /// @dev The minimum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**-128
    int24 internal constant MIN_TICK = -887272;
    /// @dev The maximum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**128
    int24 internal constant MAX_TICK = -MIN_TICK;

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

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

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

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

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

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

        uint256 r = ratio;
        uint256 msb = 0;

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

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

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

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

        int256 log_sqrt10001 = log_2 * 255738958999603826347141; // 128.128 number

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

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

File 31 of 32 : TickUtils.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "./Path.sol";
import "./TickMath.sol";
import "./LiquidityAmounts.sol";

library TickUtils {
    using Path for bytes;
    using TickMath for int24;
    
    function floor(int24 tick, int24 tickSpacing) internal pure returns (int24) {
        int24 compressed = tick / tickSpacing;
        if (tick < 0 && tick % tickSpacing != 0) compressed--;
        return compressed * tickSpacing;
    }

    /// @dev Calc base ticks depending on base threshold and tickspacing
    function baseTicks(
        int24 currentTick,
        int24 baseThreshold,
        int24 tickSpacing
    ) internal pure returns (int24 tickLower, int24 tickUpper) {
        int24 tickFloor = floor(currentTick, tickSpacing);

        tickLower = tickFloor - baseThreshold;
        tickUpper = tickFloor + baseThreshold;
    }

    function quoteAddLiquidity(int24 _currentTick, int24 _lowerTick, int24 _upperTick, uint256 _amt0, uint256 _amt1) internal pure returns(uint256 _actualAmount0, uint256 _actualAmount1, uint256 _liquidity) {
        // Grab the amount of liquidity for our token balances
        _liquidity = LiquidityAmounts.getLiquidityForAmounts(
                _currentTick.getSqrtRatioAtTick(),
                _lowerTick.getSqrtRatioAtTick(),
                _upperTick.getSqrtRatioAtTick(),
                _amt0,
                _amt1
        );
        
        ( _actualAmount0,  _actualAmount1) = LiquidityAmounts.getAmountsForLiquidity(
                _currentTick.getSqrtRatioAtTick(),
                _lowerTick.getSqrtRatioAtTick(),
                _upperTick.getSqrtRatioAtTick(),
                uint128(_liquidity)
        );
    }

    function getQuoteAtTick(
        int24 tick,
        uint128 baseAmount,
        address baseToken,
        address quoteToken
    ) internal pure returns (uint256 quoteAmount) {
        uint160 sqrtRatioX96 = TickMath.getSqrtRatioAtTick(tick);

        // Calculate quoteAmount with better precision if it doesn't overflow when multiplied by itself
        if (sqrtRatioX96 <= type(uint128).max) {
            uint256 ratioX192 = uint256(sqrtRatioX96) * sqrtRatioX96;
            quoteAmount = baseToken < quoteToken
                ? FullMath.mulDiv(ratioX192, baseAmount, 1 << 192)
                : FullMath.mulDiv(1 << 192, baseAmount, ratioX192);
        } else {
            uint256 ratioX128 = FullMath.mulDiv(sqrtRatioX96, sqrtRatioX96, 1 << 64);
            quoteAmount = baseToken < quoteToken
                ? FullMath.mulDiv(ratioX128, baseAmount, 1 << 128)
                : FullMath.mulDiv(1 << 128, baseAmount, ratioX128);
        }
    }

    // Convert encoded path to token route
    function pathToRoute(bytes memory _path) internal pure returns (address[] memory, uint24[] memory) {
        uint256 numPools = _path.numPools();
        address[] memory route = new address[](numPools + 1);
        uint24[] memory fees = new uint24[](numPools);
        for (uint256 i; i < numPools; i++) {
            (address tokenA, address tokenB, uint24 fee) = _path.decodeFirstPool();
            route[i] = tokenA;
            route[i + 1] = tokenB;
            fees[i] = fee;
            _path = _path.skipToken();
        }
        return (route, fees);
    }

    // Convert token route to encoded path
    // uint24 type for fees so path is packed tightly
    function routeToPath(
        address[] memory _route,
        uint24[] memory _fee
    ) internal pure returns (bytes memory path) {
        path = abi.encodePacked(_route[0]);
        uint256 feeLength = _fee.length;
        for (uint256 i = 0; i < feeLength; i++) {
            path = abi.encodePacked(path, _fee[i], _route[i+1]);
        }
    }

}

File 32 of 32 : UniswapV3Utils.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import './Path.sol';
import "../interfaces/common/IUniswapRouterV3WithDeadline.sol";

library UniswapV3Utils {
    using Path for bytes;

    // Swap along an encoded path using known amountIn
    function swap(
        address _router,
        bytes memory _path,
        uint256 _amountIn
    ) internal returns (uint256 amountOut) {
        IUniswapRouterV3WithDeadline.ExactInputParams memory params = IUniswapRouterV3WithDeadline.ExactInputParams({
            path: _path,
            recipient: address(this),
            deadline: block.timestamp,
            amountIn: _amountIn,
            amountOutMinimum: 0
        });
        return IUniswapRouterV3WithDeadline(_router).exactInput(params);
    }

    // Swap along a token route using known fees and amountIn
    function swap(
        address _router,
        address[] memory _route,
        uint24[] memory _fee,
        uint256 _amountIn
    ) internal returns (uint256 amountOut) {
        return swap(_router, routeToPath(_route, _fee), _amountIn);
    }

    // Convert encoded path to token route
    function pathToRoute(bytes memory _path) internal pure returns (address[] memory) {
        uint256 numPools = _path.numPools();
        address[] memory route = new address[](numPools + 1);
        for (uint256 i; i < numPools; i++) {
            (address tokenA, address tokenB,) = _path.decodeFirstPool();
            route[i] = tokenA;
            route[i + 1] = tokenB;
            _path = _path.skipToken();
        }
        return route;
    }

    // Convert token route to encoded path
    // uint24 type for fees so path is packed tightly
    function routeToPath(
        address[] memory _route,
        uint24[] memory _fee
    ) internal pure returns (bytes memory path) {
        path = abi.encodePacked(_route[0]);
        uint256 feeLength = _fee.length;
        for (uint256 i = 0; i < feeLength; i++) {
            path = abi.encodePacked(path, _fee[i], _route[i+1]);
        }
    }
}

Settings
{
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "evmVersion": "paris",
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "libraries": {}
}

Contract Security Audit

Contract ABI

[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"InvalidEntry","type":"error"},{"inputs":[],"name":"InvalidInput","type":"error"},{"inputs":[],"name":"InvalidOutput","type":"error"},{"inputs":[],"name":"InvalidTicks","type":"error"},{"inputs":[],"name":"NotAuthorized","type":"error"},{"inputs":[],"name":"NotCalm","type":"error"},{"inputs":[],"name":"NotManager","type":"error"},{"inputs":[],"name":"NotPool","type":"error"},{"inputs":[],"name":"NotStrategist","type":"error"},{"inputs":[],"name":"NotVault","type":"error"},{"inputs":[],"name":"OverLimit","type":"error"},{"inputs":[],"name":"StrategyPaused","type":"error"},{"inputs":[],"name":"TooMuchSlippage","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"callFeeAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"beefyFeeAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"strategistFeeAmount","type":"uint256"}],"name":"ChargedFees","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"feeMain0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"feeMain1","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"feeAlt0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"feeAlt1","type":"uint256"}],"name":"ClaimedFees","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"fee0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"fee1","type":"uint256"}],"name":"Harvest","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"int56","name":"maxTickDeviation","type":"int56"}],"name":"SetDeviation","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"gauge","type":"address"}],"name":"SetGauge","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"int24","name":"oldWidth","type":"int24"},{"indexed":false,"internalType":"int24","name":"width","type":"int24"}],"name":"SetPositionWidth","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"rewardPool","type":"address"}],"name":"SetRewardPool","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"feeId","type":"uint256"}],"name":"SetStratFeeId","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"strategist","type":"address"}],"name":"SetStrategist","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint32","name":"oldInterval","type":"uint32"},{"indexed":false,"internalType":"uint32","name":"interval","type":"uint32"}],"name":"SetTwapInterval","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"unirouter","type":"address"}],"name":"SetUnirouter","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"bal0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"bal1","type":"uint256"}],"name":"TVL","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"inputs":[{"internalType":"address","name":"_token","type":"address"}],"name":"addRewardToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"balances","outputs":[{"internalType":"uint256","name":"token0Bal","type":"uint256"},{"internalType":"uint256","name":"token1Bal","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"balancesOfPool","outputs":[{"internalType":"uint256","name":"token0Bal","type":"uint256"},{"internalType":"uint256","name":"token1Bal","type":"uint256"},{"internalType":"uint256","name":"mainAmount0","type":"uint256"},{"internalType":"uint256","name":"mainAmount1","type":"uint256"},{"internalType":"uint256","name":"altAmount0","type":"uint256"},{"internalType":"uint256","name":"altAmount1","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"balancesOfThis","outputs":[{"internalType":"uint256","name":"token0Bal","type":"uint256"},{"internalType":"uint256","name":"token1Bal","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"beefyFeeConfig","outputs":[{"internalType":"contract IFeeConfig","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"beefyFeeRecipient","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"beforeAction","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"claimEarnings","outputs":[{"internalType":"uint256","name":"fee0","type":"uint256"},{"internalType":"uint256","name":"fee1","type":"uint256"},{"internalType":"uint256","name":"feeAlt0","type":"uint256"},{"internalType":"uint256","name":"feeAlt1","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"currentTick","outputs":[{"internalType":"int24","name":"tick","type":"int24"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"deposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"depositFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"factory","outputs":[{"internalType":"contract IStrategyFactory","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"fees0","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"fees1","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"gauge","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getAllFees","outputs":[{"components":[{"components":[{"internalType":"uint256","name":"total","type":"uint256"},{"internalType":"uint256","name":"beefy","type":"uint256"},{"internalType":"uint256","name":"call","type":"uint256"},{"internalType":"uint256","name":"strategist","type":"uint256"},{"internalType":"string","name":"label","type":"string"},{"internalType":"bool","name":"active","type":"bool"}],"internalType":"struct IFeeConfig.FeeCategory","name":"performance","type":"tuple"},{"internalType":"uint256","name":"deposit","type":"uint256"},{"internalType":"uint256","name":"withdraw","type":"uint256"}],"internalType":"struct IFeeConfig.AllFees","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getKeys","outputs":[{"internalType":"bytes32","name":"keyMain","type":"bytes32"},{"internalType":"bytes32","name":"keyAlt","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getStratFeeId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_callFeeRecipient","type":"address"}],"name":"harvest","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"harvest","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_pool","type":"address"},{"internalType":"address","name":"_gauge","type":"address"},{"internalType":"address","name":"_rewardPool","type":"address"},{"internalType":"int24","name":"_positionWidth","type":"int24"},{"components":[{"internalType":"address","name":"vault","type":"address"},{"internalType":"address","name":"unirouter","type":"address"},{"internalType":"address","name":"strategist","type":"address"},{"internalType":"address","name":"factory","type":"address"}],"internalType":"struct StratFeeCowManagerInitializable.CommonAddresses","name":"_commonAddresses","type":"tuple"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"isCalm","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"keeper","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastHarvest","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastPositionAdjustment","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lockedProfit","outputs":[{"internalType":"uint256","name":"locked0","type":"uint256"},{"internalType":"uint256","name":"locked1","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lpToken0","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lpToken1","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxTickDeviation","outputs":[{"internalType":"int56","name":"","type":"int56"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"moveTicks","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"native","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_minAmount0","type":"uint256"},{"internalType":"uint256","name":"_minAmount1","type":"uint256"}],"name":"panic","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pool","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"positionAlt","outputs":[{"internalType":"int24","name":"tickLower","type":"int24"},{"internalType":"int24","name":"tickUpper","type":"int24"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"positionMain","outputs":[{"internalType":"int24","name":"tickLower","type":"int24"},{"internalType":"int24","name":"tickUpper","type":"int24"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"positionWidth","outputs":[{"internalType":"int24","name":"","type":"int24"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"price","outputs":[{"internalType":"uint256","name":"_price","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"ramsesV2MintCallback","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"range","outputs":[{"internalType":"uint256","name":"lowerPrice","type":"uint256"},{"internalType":"uint256","name":"upperPrice","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"resetRewards","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"retireVault","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"rewardBalances","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rewardPool","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"rewardTokens","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"int56","name":"_maxDeviation","type":"int56"}],"name":"setDeviation","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_gauge","type":"address"}],"name":"setGauge","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"int24","name":"_width","type":"int24"}],"name":"setPositionWidth","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_rewardPool","type":"address"}],"name":"setRewardPool","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_feeId","type":"uint256"}],"name":"setStratFeeId","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_strategist","type":"address"}],"name":"setStrategist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"_interval","type":"uint32"}],"name":"setTwapInterval","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_unirouter","type":"address"}],"name":"setUnirouter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"sqrtPrice","outputs":[{"internalType":"uint160","name":"sqrtPriceX96","type":"uint160"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"strategist","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"swapFee","outputs":[{"internalType":"uint256","name":"fee","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalLocked0","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalLocked1","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"twap","outputs":[{"internalType":"int56","name":"twapTick","type":"int56"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"twapInterval","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"unirouter","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"vault","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount0","type":"uint256"},{"internalType":"uint256","name":"_amount1","type":"uint256"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdrawFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]

60806040523480156200001157600080fd5b506200001c62000022565b620000e3565b600054610100900460ff16156200008f5760405162461bcd60e51b815260206004820152602760248201527f496e697469616c697a61626c653a20636f6e747261637420697320696e697469604482015266616c697a696e6760c81b606482015260840160405180910390fd5b60005460ff90811614620000e1576000805460ff191660ff9081179091556040519081527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b565b615dcb80620000f36000396000f3fe608060405234801561001057600080fd5b50600436106103fb5760003560e01c806378238c3711610215578063ad29f5da11610125578063d0e30db0116100b8578063e97206a911610087578063e97206a914610832578063f1a392da1461083a578063f2fde38b14610843578063fbfa77cf14610856578063fcc25e131461086957600080fd5b8063d0e30db0146107ef578063d92f3d73146107f7578063d9ceab131461080a578063e941fa781461064657600080fd5b8063bc415d8a116100f4578063bc415d8a146107a8578063c45a0155146107c1578063c7b9d530146107d4578063c7d54132146107e757600080fd5b8063ad29f5da1461077b578063b20feaaf14610783578063b3a60cb314610798578063b83d2683146107a057600080fd5b80638e145459116101a85780639bdde46b116101775780639bdde46b1461073d578063a035b1fe14610745578063a6f19c841461074d578063a80f35b814610760578063aced16611461077357600080fd5b80638e145459146106d957806393c8dc6d146106e157806393f1c4421461070157806399cd24461461070a57600080fd5b8063865238d4116101e4578063865238d4146106a4578063877562b6146106ad5780638cfc0250146106c05780638da5cb5b146106c857600080fd5b806378238c37146106695780637bb7bed11461067c5780637bb98a681461068f5780638097e2491461069757600080fd5b80633e48f4171161031057806354cf2aeb116102a35780636099134611610272578063609913461461062057806366666aa91461063357806367a5279314610646578063696c58e51461064d578063715018a61461066157600080fd5b806354cf2aeb146105db57806355a68ed3146105e35780635c975abb146105f65780635ee167c01461060d57600080fd5b806344b81396116102df57806344b81396146105ba5780634641257d146105c25780634746fb55146105ca5780634c02a21c146105d257600080fd5b80633e48f417146105795780633e55f9321461058c5780633f4ba83a1461059f578063441a3e70146105a757600080fd5b806317dd7a72116103935780632150c518116103625780632150c51814610516578063257ae0de1461051e5780632b950b6614610531578063362c28c61461053a5780633c1d5df01461054d57600080fd5b806317dd7a72146104d55780631c03e6cc146104dd5780631d27050f146104f05780631fe4a6861461050357600080fd5b806311b0b42d116103cf57806311b0b42d146104695780631208aa181461049457806312cf1381146104af57806316f0115b146104c257600080fd5b8062a4b5c91461040057806304c404b314610422578063065e5360146104395780630e5c011e14610454575b600080fd5b61040861089e565b604080519283526020830191909152015b60405180910390f35b61042b609d5481565b604051908152602001610419565b610441610aab565b60405160029190910b8152602001610419565b6104676104623660046150ac565b610b25565b005b60975461047c906001600160a01b031681565b6040516001600160a01b039091168152602001610419565b61049c610b31565b60405160069190910b8152602001610419565b6104676104bd3660046150d8565b610ca0565b60d15461047c906001600160a01b031681565b610467610d21565b6104676104eb3660046150ac565b610d3f565b6104676104fe3660046150f5565b610e51565b609a5461047c906001600160a01b031681565b610408610ef2565b60995461047c906001600160a01b031681565b61042b609c5481565b61046761054836600461512a565b610f79565b60dc5461056490600160501b900463ffffffff1681565b60405163ffffffff9091168152602001610419565b6104676105873660046151df565b61101c565b61046761059a366004615272565b6110c9565b6104676111be565b6104676105b536600461528b565b61126b565b61040861131d565b61046761142a565b61047c611433565b61042b60d95481565b61042b6114a6565b6104676105f13660046150ac565b611545565b60655460ff165b6040519015158152602001610419565b60d45461047c906001600160a01b031681565b61046761062e36600461528b565b6115f5565b60d35461047c906001600160a01b031681565b600061042b565b60dc5461049c906301000000900460060b81565b6104676116ab565b6104676106773660046150ac565b6116bd565b61047c61068a366004615272565b611729565b610408611753565b60dc546104419060020b81565b61042b609f5481565b60d55461047c906001600160a01b031681565b61042b6117ff565b6033546001600160a01b031661047c565b61047c611873565b61042b6106ef3660046150ac565b60d76020526000908152604090205481565b61042b60d85481565b60db5461072390600281810b9163010000009004900b82565b60408051600293840b81529190920b602082015201610419565b6105fd6118bd565b61042b611965565b60d25461047c906001600160a01b031681565b61046761076e3660046152ad565b6119a4565b61047c611c31565b610467611c7b565b61078b611d5b565b6040516104199190615377565b610467611d8b565b61047c611f77565b60da5461072390600281810b9163010000009004900b82565b609b5461047c906001600160a01b031681565b6104676107e23660046150ac565b611ff1565b61046761206a565b61046761216d565b6104676108053660046150ac565b6121b1565b61081261221d565b604080519485526020850193909352918301526060820152608001610419565b610408612263565b61042b609e5481565b6104676108513660046150ac565b6122d2565b60985461047c906001600160a01b031681565b610871612348565b604080519687526020870195909552938501929092526060840152608083015260a082015260c001610419565b60008060008060005b60d6548110156109b15760d45460d680546001600160a01b0390921691839081106108d4576108d46153f4565b6000918252602090912001546001600160a01b03160361092d5760d7600060d68381548110610905576109056153f4565b60009182526020808320909101546001600160a01b0316835282019290925260400190205492505b60d55460d680546001600160a01b039092169183908110610950576109506153f4565b6000918252602090912001546001600160a01b0316036109a95760d7600060d68381548110610981576109816153f4565b60009182526020808320909101546001600160a01b0316835282019290925260400190205491505b6001016108a7565b5060d4546040516370a0823160e01b815230600482015283916001600160a01b0316906370a0823190602401602060405180830381865afa1580156109fa573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a1e919061540a565b610a289190615439565b60d5546040516370a0823160e01b815230600482015291955082916001600160a01b03909116906370a0823190602401602060405180830381865afa158015610a75573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a99919061540a565b610aa39190615439565b925050509091565b60d15460408051633850c7bd60e01b815290516000926001600160a01b031691633850c7bd9160048083019260e09291908290030181865afa158015610af5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b19919061546e565b50939695505050505050565b610b2e81612545565b50565b6040805160028082526060820183526000928392919060208301908036833701905050905060dc600a9054906101000a900463ffffffff1681600081518110610b7c57610b7c6153f4565b602002602001019063ffffffff16908163ffffffff1681525050600081600181518110610bab57610bab6153f4565b63ffffffff9092166020928302919091019091015260d15460405163883bdbfd60e01b81526000916001600160a01b03169063883bdbfd90610bf1908590600401615501565b600060405180830381865afa158015610c0e573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610c3691908101906155e2565b50905060dc600a9054906101000a900463ffffffff1660030b81600081518110610c6257610c626153f4565b602002602001015182600181518110610c7d57610c7d6153f4565b6020026020010151610c8f91906156a7565b610c9991906156ea565b9250505090565b610ca86125fc565b60dc5460408051600292830b81529183900b60208301527f69d927977053f4ff4a26e8d792564e367e844a869cda4df12630bf7b62a632de910160405180910390a1610cf2612656565b50505050610cfe612a55565b60dc805462ffffff191662ffffff8316179055610d19612da7565b610b2e612dfd565b610d296130a8565b610d31612656565b50505050610d3d612a55565b565b6033546001600160a01b03163314801590610d735750610d5d611c31565b6001600160a01b0316336001600160a01b031614155b15610d915760405163607e454560e11b815260040160405180910390fd5b60d354610dac906001600160a01b03838116911660006130d3565b60d354610dc8906001600160a01b0383811691166000196130d3565b609954610de3906001600160a01b03838116911660006130d3565b609954610dff906001600160a01b0383811691166000196130d3565b60d680546001810182556000919091527fe767803f8ecf1dee6bb0345811f7312cda556058b19db6389ad9ae3568643ddd0180546001600160a01b0319166001600160a01b0392909216919091179055565b610e596125fc565b60dc546040805163ffffffff600160501b9093048316815291831660208301527f86139943149914833c057d2c24f3a3967cce8e6aba2eb12e422500d8a51ffc7b910160405180910390a1603c8163ffffffff161015610ecc5760405163b4fa3fb360e01b815260040160405180910390fd5b60dc805463ffffffff909216600160501b0263ffffffff60501b19909216919091179055565b60da546040516000918291610f1e9130918491600281810b926301000000909204900b90602001615728565b60408051601f1981840301815290829052805160209182012060db54909450610f5d923092600092600281810b936301000000909204900b9101615728565b6040516020818303038152906040528051906020012090509091565b610f816125fc565b604051600682900b81527f69d3f73bfb3c2f0de63dc1de2ed486cf45d88ebfff8cb1e8f124b085d2bafb979060200160405180910390a1610fc0613195565b610fcb90600461575d565b60020b8160060b12610ff05760405163b4fa3fb360e01b815260040160405180910390fd5b60dc805466ffffffffffffff90921663010000000269ffffffffffffff00000019909216919091179055565b60d1546001600160a01b0316331461104757604051636f61f64160e01b815260040160405180910390fd5b60dc54600160701b900460ff166110715760405163887efaa560e01b815260040160405180910390fd5b82156110945760d15460d454611094916001600160a01b03918216911685613203565b81156110b75760d15460d5546110b7916001600160a01b03918216911684613203565b505060dc805460ff60701b1916905550565b6033546001600160a01b031633148015906110fd57506110e7611c31565b6001600160a01b0316336001600160a01b031614155b1561111b5760405163607e454560e11b815260040160405180910390fd5b611123611433565b6001600160a01b0316633e55f932826040518263ffffffff1660e01b815260040161115091815260200190565b600060405180830381600087803b15801561116a57600080fd5b505af115801561117e573d6000803e3d6000fd5b505050507f9163810ee1e29168d4ce900e48a333fb8fbd3fd070d2bef67f6d4db0846a469f816040516111b391815260200190565b60405180910390a150565b6033546001600160a01b031633148015906111f257506111dc611c31565b6001600160a01b0316336001600160a01b031614155b156112105760405163607e454560e11b815260040160405180910390fd5b60006112246033546001600160a01b031690565b6001600160a01b03160361124b5760405163ea8e4eb560e01b815260040160405180910390fd5b611253613233565b61125b613328565b611263612da7565b610d3d612dfd565b6112736130a8565b81156112965760985460d454611296916001600160a01b03918216911684613203565b80156112b95760985460d5546112b9916001600160a01b03918216911683613203565b6112c161337a565b6112cd576112cd612dfd565b6000806112d8611753565b60408051838152602081018390529294509092507f631c4f79c14099a717f4be2f25e6cef89e310b3944ef0e44ea2c0811ebb982a8910160405180910390a150505050565b60008060008061132b61089e565b9150915060008061133a612348565b5050505091509150600082856113509190615784565b9050600061135e8386615784565b90506000609e54426113709190615439565b90506000610e108210611384576000611390565b61139082610e10615439565b9050609c548411156113be57610e1081609c546113ad9190615797565b6113b791906157ae565b99506113d8565b610e106113cb8286615797565b6113d591906157ae565b99505b609d5483111561140457610e1081609d546113f39190615797565b6113fd91906157ae565b985061141e565b610e106114118285615797565b61141b91906157ae565b98505b50505050505050509091565b610d3d32612545565b609b5460408051634746fb5560e01b815290516000926001600160a01b031691634746fb559160048083019260209291908290030181865afa15801561147d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114a191906157c2565b905090565b6000620f4240670de0b6b3a764000060d160009054906101000a90046001600160a01b03166001600160a01b031663ddca3f436040518163ffffffff1660e01b8152600401602060405180830381865afa158015611508573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061152c91906157df565b62ffffff1661153b9190615797565b6114a191906157ae565b6033546001600160a01b031633148015906115795750611563611c31565b6001600160a01b0316336001600160a01b031614155b156115975760405163607e454560e11b815260040160405180910390fd5b6040516001600160a01b03821681527f17228b08e4c958112a0827a6d8dc8475dba58dd068a3d400800a606794db02a69060200160405180910390a160d280546001600160a01b0319166001600160a01b0392909216919091179055565b6033546001600160a01b031633148015906116295750611613611c31565b6001600160a01b0316336001600160a01b031614155b156116475760405163607e454560e11b815260040160405180910390fd5b61164f612656565b5050505061165b612a55565b611663613405565b61166b6134a6565b600080611676611753565b915091508382108061168757508281105b156116a55760405163fa6ad35560e01b815260040160405180910390fd5b50505050565b6116b36125fc565b610d3d60006134e3565b6116c56125fc565b6116cd613405565b60d380546001600160a01b0319166001600160a01b0383161790556116f0613233565b6040516001600160a01b03821681527f173d73afad648e625c4a53878536f7a2debed1f51a04f21d728bce3cf534fcc1906020016111b3565b60d6818154811061173957600080fd5b6000918252602090912001546001600160a01b0316905081565b60008060008061176161089e565b91509150600080611770612348565b505050509150915060008061178361131d565b90925090506000826117958689615784565b61179f9190615439565b90506000826117ae8689615784565b6117b89190615439565b60d85460d95491925090838211156117ce578391505b828111156117d95750815b6117e38285615439565b6117ed8285615439565b9b509b50505050505050505050509091565b6000611809611433565b604051636788231160e11b81523060048201526001600160a01b03919091169063cf10462290602401602060405180830381865afa15801561184f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114a1919061540a565b609b5460408051638e14545960e01b815290516000926001600160a01b031691638e1454599160048083019260209291908290030181865afa15801561147d573d6000803e3d6000fd5b6000806118c8610aab565b905060006118d4610b31565b60dc54909150600090611902906118f5906301000000900460060b846156a7565b60060b620d89e719613535565b60dc5490915060009061192f90611923906301000000900460060b85615804565b60060b620d89e8613550565b90508360020b8260060b138061194a57508360020b8160060b125b1561195a57600094505050505090565b600194505050505090565b600080611970611f77565b90506002611994826001600160a01b0316670de0b6b3a7640000600160601b61355f565b61199e9190615915565b91505090565b600054610100900460ff16158080156119c45750600054600160ff909116105b806119de5750303b1580156119de575060005460ff166001145b611a465760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b60648201526084015b60405180910390fd5b6000805460ff191660011790558015611a69576000805461ff0019166101001790555b611a7282613613565b60d180546001600160a01b038089166001600160a01b0319928316811790935560d2805489831690841617905560d380549188169190921617905560408051630dfe168160e01b81529051630dfe1681916004808201926020929091908290030181865afa158015611ae8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b0c91906157c2565b60d460006101000a8154816001600160a01b0302191690836001600160a01b03160217905550856001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa158015611b70573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b9491906157c2565b60d580546001600160a01b0319166001600160a01b039290921691909117905560dc805462ffffff85166dffffffff00000000000000ffffff1990911617600f60531b179055611be2613233565b8015611c29576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb3847402498906020015b60405180910390a15b505050505050565b609b546040805163aced166160e01b815290516000926001600160a01b03169163aced16619160048083019260209291908290030181865afa15801561147d573d6000803e3d6000fd5b6033546001600160a01b03163314801590611caf5750611c99611c31565b6001600160a01b0316336001600160a01b031614155b15611ccd5760405163607e454560e11b815260040160405180910390fd5b60005b60d654811015611d4e5760d35460d68054611d1e926001600160a01b03169160009185908110611d0257611d026153f4565b6000918252602090912001546001600160a01b031691906130d3565b60995460d68054611d46926001600160a01b03169160009185908110611d0257611d026153f4565b600101611cd0565b50610d3d60d66000615006565b611d63615024565b6040518060600160405280611d76613788565b81526020016000815260200160009052919050565b611d936125fc565b609860009054906101000a90046001600160a01b03166001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611de6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e0a919061540a565b6103e814611e2b5760405163ea8e4eb560e01b815260040160405180910390fd5b611e366000806115f5565b6000611e40611873565b9050600080611e4d61089e565b90925090508115611edd5760d4546040516370a0823160e01b8152306004820152611edd9185916001600160a01b03909116906370a0823190602401602060405180830381865afa158015611ea6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611eca919061540a565b60d4546001600160a01b03169190613203565b8015611f685760d5546040516370a0823160e01b8152306004820152611f689185916001600160a01b03909116906370a0823190602401602060405180830381865afa158015611f31573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f55919061540a565b60d5546001600160a01b03169190613203565b611f7260006134e3565b505050565b60d15460408051633850c7bd60e01b815290516000926001600160a01b031691633850c7bd9160048083019260e09291908290030181865afa158015611fc1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611fe5919061546e565b50949695505050505050565b609a546001600160a01b0316331461201c57604051633163ba6d60e11b815260040160405180910390fd5b609a80546001600160a01b0319166001600160a01b0383169081179091556040519081527f46d58e3fa07bf19b1d27240f0e286b27e9f7c1b0d88933333fe833b60eec5412906020016111b3565b612072613839565b609b546040516305226abd60e51b81523360048201526001600160a01b039091169063a44d57a090602401602060405180830381865afa1580156120ba573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120de9190615924565b6120fb5760405163ea8e4eb560e01b815260040160405180910390fd5b612103612656565b5050505061210f612a55565b612117612da7565b61211f612dfd565b60008061212a611753565b60408051838152602081018390529294509092507f631c4f79c14099a717f4be2f25e6cef89e310b3944ef0e44ea2c0811ebb982a8910160405180910390a15050565b612175613839565b61217d6130a8565b60dc54600160781b900460ff1661211757612196612da7565b60dc805460ff60781b1916600160781b17905561211f612dfd565b6121b96125fc565b6121c1613405565b609980546001600160a01b0319166001600160a01b0383161790556121e4613233565b6040516001600160a01b03821681527f5ca6e64c4522e68e154aa9372f2c5969cd37d9640e59f66953dc472f54ee86fa906020016111b3565b60008060008061222b612656565b60d6549397509195509350915015801590612250575060d2546001600160a01b031615155b1561225d5761225d61385e565b90919293565b60da5460009081906002906122999061227d90830b613b78565b6001600160a01b0316670de0b6b3a7640000600160601b61355f565b6122a39190615915565b60da549092506002906122c29061227d9063010000009004830b613b78565b6122cc9190615915565b90509091565b6122da6125fc565b6001600160a01b03811661233f5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401611a3d565b610b2e816134e3565b60008060008060008060008061235c610ef2565b91509150600061236a611f77565b60d15460405163514ea4bf60e01b815260048101869052919250600091829182916001600160a01b039091169063514ea4bf9060240160a060405180830381865afa1580156123bd573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123e19190615956565b60d15460405163514ea4bf60e01b8152600481018c90529598506001600160801b039283169750911694506000938493508392506001600160a01b039091169063514ea4bf9060240160a060405180830381865afa158015612447573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061246b9190615956565b60da549497506001600160801b0391821696501693506124b1928a9250612495915060020b613b78565b60da546124ab906301000000900460020b613b78565b89613f9a565b60db54919e509c506124e79088906124cb9060020b613b78565b60db546124e1906301000000900460020b613b78565b86613f9a565b909b5099506124f6858e615784565b9c50612502848d615784565b9b5061250e828c615784565b9a5061251a818b615784565b99506125268b8e615784565b9e506125328a8d615784565b9d50505050505050505050909192939495565b61254d61221d565b50505050612559612a55565b60d6546000901561256f5761256c614036565b90505b6000806125828460d85460d95486614344565b9150915061258e612dfd565b600060d881905560d9819055806125a361131d565b90925090506125b28285615784565b609c556125bf8184615784565b609d5542609e5560408051858152602081018590527f6c8433a8e155f0af04dba058d4e4695f7da554578963d876bdf4a6d8d6399d9c9101611c20565b6033546001600160a01b03163314610d3d5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401611a3d565b600080600080600080612667610ef2565b60d15460405163514ea4bf60e01b8152600481018490529294509092506000916001600160a01b039091169063514ea4bf9060240160a060405180830381865afa1580156126b9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126dd9190615956565b505060d15460405163514ea4bf60e01b8152600481018790529394506000936001600160a01b03909116925063514ea4bf915060240160a060405180830381865afa158015612730573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127549190615956565b5050505090506000826001600160801b031611156127f55760d15460da5460405163a34123a760e01b81526001600160a01b039092169163a34123a7916127b091600282810b9263010000009004900b906000906004016159ad565b60408051808303816000875af11580156127ce573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127f291906159d3565b50505b6001600160801b0381161561288d5760d15460db5460405163a34123a760e01b81526001600160a01b039092169163a34123a79161284891600282810b9263010000009004900b906000906004016159ad565b60408051808303816000875af1158015612866573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061288a91906159d3565b50505b60d15460da546040516309e3d67b60e31b81526001600160a01b0390921691634f1eb3d8916128dc913091600281810b926301000000909204900b906001600160801b039081906004016159f7565b60408051808303816000875af11580156128fa573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061291e9190615a34565b60d15460db546040516309e3d67b60e31b81526001600160801b039485169c509284169a506001600160a01b0390911692634f1eb3d892612976923092600282810b936301000000909304900b9181906004016159f7565b60408051808303816000875af1158015612994573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129b89190615a34565b60d8546001600160801b0392831698509116955086906129d9908a90615784565b6129e39190615784565b60d85560d95485906129f6908990615784565b612a009190615784565b60d9556040805189815260208101899052908101879052606081018690527f6fe7c663aa15def6e80578b76ddd894fcefeabf14a0106afbec24da4a6c578729060800160405180910390a15050505090919293565b600080612a60610ef2565b60d15460405163514ea4bf60e01b8152600481018490529294509092506000916001600160a01b039091169063514ea4bf9060240160a060405180830381865afa158015612ab2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ad69190615956565b505060d15460405163514ea4bf60e01b8152600481018790529394506000936001600160a01b03909116925063514ea4bf915060240160a060405180830381865afa158015612b29573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b4d9190615956565b5050505090506000826001600160801b03161115612c805760d15460da5460405163a34123a760e01b81526001600160a01b039092169163a34123a791612ba891600282810b9263010000009004900b9087906004016159ad565b60408051808303816000875af1158015612bc6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612bea91906159d3565b505060d15460da546040516309e3d67b60e31b81526001600160a01b0390921691634f1eb3d891612c3b913091600281810b926301000000909204900b906001600160801b039081906004016159f7565b60408051808303816000875af1158015612c59573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c7d9190615a34565b50505b6001600160801b038116156116a55760d15460db5460405163a34123a760e01b81526001600160a01b039092169163a34123a791612cd291600282810b9263010000009004900b9086906004016159ad565b60408051808303816000875af1158015612cf0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d1491906159d3565b505060d15460db546040516309e3d67b60e31b81526001600160a01b0390921691634f1eb3d891612d65913091600281810b926301000000909204900b906001600160801b039081906004016159f7565b60408051808303816000875af1158015612d83573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c299190615a34565b612daf613839565b6000612db9610aab565b90506000612dc5613195565b60dc54909150600090612ddc90839060020b61575d565b9050612de9838383614684565b612df48383836146bf565b505042609f5550565b612e0561480f565b600080612e1061089e565b915091506000612e1e611f77565b60da54909150600090612e56908390612e399060020b613b78565b60da54612e4f906301000000900460020b613b78565b87876148b0565b60da54909150600090612e79908390600281810b9163010000009004900b614974565b90506000826001600160801b0316118015612e915750805b15612f725760dc805460ff60701b1916600160701b17905560d15460da54604051638221b8c160e01b815230600482015260006024820152600282810b6044830152630100000090920490910b60648201526001600160801b038416608482015260c060a4820152600a60c4820152692132b2b33c9026b0b4b760b11b60e48201526001600160a01b0390911690638221b8c1906101040160408051808303816000875af1158015612f47573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f6b91906159d3565b5050612f7a565b612f7a613839565b612f8261089e565b60db549196509450612fb9908490612f9c9060020b613b78565b60db54612fb2906301000000900460020b613b78565b88886148b0565b91506001600160801b038216156130a15760dc805460ff60701b1916600160701b17905560d15460db54604051638221b8c160e01b815230600482015260006024820152600282810b6044830152630100000090920490910b60648201526001600160801b038416608482015260c060a4820152600960c482015268109959599e48105b1d60ba1b60e48201526001600160a01b0390911690638221b8c1906101040160408051808303816000875af115801561307a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061309e91906159d3565b50505b5050505050565b6098546001600160a01b03163314610d3d576040516362df054560e01b815260040160405180910390fd5b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663095ea7b360e01b17905261312484826149c2565b6116a5576040516001600160a01b03841660248201526000604482015261318b90859063095ea7b360e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152614a65565b6116a58482614a65565b60d154604080516334324e9f60e21b815290516000926001600160a01b03169163d0c93a7c9160048083019260209291908290030181865afa1580156131df573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114a19190615a67565b6040516001600160a01b038316602482015260448101829052611f7290849063a9059cbb60e01b90606401613154565b60995460d454613252916001600160a01b0391821691166000196130d3565b60995460d554613271916001600160a01b0391821691166000196130d3565b60005b60d654811015610b2e5760995460d680546132a6926001600160a01b03169160009185908110611d0257611d026153f4565b60995460d680546132cf926001600160a01b0316916000199185908110611d0257611d026153f4565b60d35460d680546132f7926001600160a01b03169160009185908110611d0257611d026153f4565b60d35460d68054613320926001600160a01b0316916000199185908110611d0257611d026153f4565b600101613274565b613330614b3a565b6065805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b600061338860655460ff1690565b806114a15750609b60009054906101000a90046001600160a01b03166001600160a01b031663f12d54d86040518163ffffffff1660e01b8152600401602060405180830381865afa1580156133e1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114a19190615924565b60995460d454613423916001600160a01b03918216911660006130d3565b60995460d554613441916001600160a01b03918216911660006130d3565b60005b60d654811015610b2e5760995460d68054613476926001600160a01b03169160009185908110611d0257611d026153f4565b60d35460d6805461349e926001600160a01b03169160009185908110611d0257611d026153f4565b600101613444565b6134ae614b83565b6065805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a25861335d3390565b603380546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b6000818312156135455781613547565b825b90505b92915050565b60008183126135455781613547565b6000808060001985870985870292508281108382030391505080600003613598576000841161358d57600080fd5b50829004905061360c565b8084116135a457600080fd5b600084868809851960019081018716968790049682860381900495909211909303600082900391909104909201919091029190911760038402600290811880860282030280860282030280860282030280860282030280860282030280860290910302029150505b9392505050565b600054610100900460ff1661363a5760405162461bcd60e51b8152600401611a3d90615a84565b613642614bc9565b61364a614bf8565b61365760208201826150ac565b609880546001600160a01b0319166001600160a01b039290921691909117905561368760408201602083016150ac565b609980546001600160a01b0319166001600160a01b03929092169190911790556136b760608201604083016150ac565b609a80546001600160a01b0319166001600160a01b03929092169190911790556136e760808201606083016150ac565b609b80546001600160a01b0319166001600160a01b03929092169182179055604080516311b0b42d60e01b815290516311b0b42d916004808201926020929091908290030181865afa158015613741573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061376591906157c2565b609780546001600160a01b0319166001600160a01b039290921691909117905550565b6137c36040518060c0016040528060008152602001600081526020016000815260200160008152602001606081526020016000151581525090565b6137cb611433565b604051639af608c960e01b81523060048201526001600160a01b039190911690639af608c990602401600060405180830381865afa158015613811573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526114a19190810190615acf565b6138416118bd565b610d3d576040516313643c3b60e11b815260040160405180910390fd5b60d65460009067ffffffffffffffff81111561387c5761387c615147565b6040519080825280602002602001820160405280156138a5578160200160208202803683370190505b50905060005b60d6548110156139625760d681815481106138c8576138c86153f4565b6000918252602090912001546040516370a0823160e01b81523060048201526001600160a01b03909116906370a0823190602401602060405180830381865afa158015613919573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061393d919061540a565b82828151811061394f5761394f6153f4565b60209081029190910101526001016138ab565b5060d25460da546040516318d9dceb60e31b81526001600160a01b039092169163c6cee758916139ae913091600091600282810b9263010000009004900b9060d6908590600401615bad565b600060405180830381600087803b1580156139c857600080fd5b505af11580156139dc573d6000803e3d6000fd5b505060d25460db546040516318d9dceb60e31b81526001600160a01b03909216935063c6cee7589250613a2b913091600091600282810b9263010000009004900b9060d6908590600401615bad565b600060405180830381600087803b158015613a4557600080fd5b505af1158015613a59573d6000803e3d6000fd5b5050505060005b60d654811015613b74576000828281518110613a7e57613a7e6153f4565b602002602001015160d68381548110613a9957613a996153f4565b6000918252602090912001546040516370a0823160e01b81523060048201526001600160a01b03909116906370a0823190602401602060405180830381865afa158015613aea573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613b0e919061540a565b613b189190615439565b90508060d7600060d68581548110613b3257613b326153f4565b60009182526020808320909101546001600160a01b0316835282019290925260400181208054909190613b66908490615784565b909155505050600101613a60565b5050565b60008060008360020b12613b8f578260020b613b9c565b8260020b613b9c90615c34565b9050613bab620d89e719615c50565b62ffffff16811115613be35760405162461bcd60e51b81526020600482015260016024820152601560fa1b6044820152606401611a3d565b600081600116600003613bfa57600160801b613c0c565b6ffffcb933bd6fad37aa2d162d1a5940015b70ffffffffffffffffffffffffffffffffff1690506002821615613c4b576080613c46826ffff97272373d413259a46990580e213a615797565b901c90505b6004821615613c75576080613c70826ffff2e50f5f656932ef12357cf3c7fdcc615797565b901c90505b6008821615613c9f576080613c9a826fffe5caca7e10e4e61c3624eaa0941cd0615797565b901c90505b6010821615613cc9576080613cc4826fffcb9843d60f6159c9db58835c926644615797565b901c90505b6020821615613cf3576080613cee826fff973b41fa98c081472e6896dfb254c0615797565b901c90505b6040821615613d1d576080613d18826fff2ea16466c96a3843ec78b326b52861615797565b901c90505b6080821615613d47576080613d42826ffe5dee046a99a2a811c461f1969c3053615797565b901c90505b610100821615613d72576080613d6d826ffcbe86c7900a88aedcffc83b479aa3a4615797565b901c90505b610200821615613d9d576080613d98826ff987a7253ac413176f2b074cf7815e54615797565b901c90505b610400821615613dc8576080613dc3826ff3392b0822b70005940c7a398e4b70f3615797565b901c90505b610800821615613df3576080613dee826fe7159475a2c29b7443b29c7fa6e889d9615797565b901c90505b611000821615613e1e576080613e19826fd097f3bdfd2022b8845ad8f792aa5825615797565b901c90505b612000821615613e49576080613e44826fa9f746462d870fdf8a65dc1f90e061e5615797565b901c90505b614000821615613e74576080613e6f826f70d869a156d2a1b890bb3df62baf32f7615797565b901c90505b618000821615613e9f576080613e9a826f31be135f97d08fd981231505542fcfa6615797565b901c90505b62010000821615613ecb576080613ec6826f09aa508b5b7a84e1c677de54f3e99bc9615797565b901c90505b62020000821615613ef6576080613ef1826e5d6af8dedb81196699c329225ee604615797565b901c90505b62040000821615613f20576080613f1b826d2216e584f5fa1ea926041bedfe98615797565b901c90505b62080000821615613f48576080613f43826b048a170391f7dc42444e8fa2615797565b901c90505b60008460020b1315613f6357613f60816000196157ae565b90505b613f7264010000000082615c72565b15613f7e576001613f81565b60005b613f929060ff16602083901c615784565b949350505050565b600080836001600160a01b0316856001600160a01b03161115613fbb579293925b846001600160a01b0316866001600160a01b031611613fe657613fdf858585614c27565b915061402d565b836001600160a01b0316866001600160a01b0316101561401f5761400b868585614c27565b9150614018858785614c9a565b905061402d565b61402a858585614c9a565b90505b94509492505050565b600080614041613788565b905060005b60d65481101561433f57600060d7600060d68481548110614069576140696153f4565b60009182526020808320909101546001600160a01b031683528201929092526040019020541115614337576000670de0b6b3a7640000836000015160d7600060d686815481106140bb576140bb6153f4565b60009182526020808320909101546001600160a01b031683528201929092526040019020546140ea9190615797565b6140f491906157ae565b60975460d680549293506000926001600160a01b03909216918590811061411d5761411d6153f4565b6000918252602090912001546001600160a01b0316146141ef5760995460d680546001600160a01b039092169163df791e50919086908110614161576141616153f4565b60009182526020909120015460975460405160e084901b6001600160e01b03191681526001600160a01b03928316600482015291166024820152604481018590526064016020604051808303816000875af11580156141c4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906141e8919061540a565b90506141f2565b50805b60d35460d680546001600160a01b039092169163a3cd8ac491908690811061421c5761421c6153f4565b9060005260206000200160009054906101000a90046001600160a01b03168460d7600060d68981548110614252576142526153f4565b60009182526020808320909101546001600160a01b031683528201929092526040019020546142819190615439565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152620151806044820152606401600060405180830381600087803b1580156142d057600080fd5b505af11580156142e4573d6000803e3d6000fd5b5050505080856142f49190615784565b9450600060d7600060d6868154811061430f5761430f6153f4565b60009182526020808320909101546001600160a01b0316835282019290925260400190205550505b600101614046565b505090565b6000806000614351613788565b9050838615614467578151600090670de0b6b3a764000090614373908a615797565b61437d91906157ae565b90506143898189615439565b60975460d4549196506000916001600160a01b0390811691161461442e5760995460d454609754604051630df791e560e41b81526001600160a01b03928316600482015290821660248201526044810185905291169063df791e50906064016020604051808303816000875af1158015614407573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061442b919061540a565b90505b60975460d4546001600160a01b03918216911603614457576144508284615784565b9250614464565b6144618184615784565b92505b50505b851561457a578151600090670de0b6b3a7640000906144869089615797565b61449091906157ae565b905061449c8188615439565b60975460d5549195506000916001600160a01b039081169116146145415760995460d554609754604051630df791e560e41b81526001600160a01b03928316600482015290821660248201526044810185905291169063df791e50906064016020604051808303816000875af115801561451a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061453e919061540a565b90505b60975460d5546001600160a01b0391821691160361456a576145638284615784565b9250614577565b6145748184615784565b92505b50505b6000670de0b6b3a76400008360400151836145959190615797565b61459f91906157ae565b6097549091506145b9906001600160a01b03168a83613203565b6000670de0b6b3a76400008460600151846145d49190615797565b6145de91906157ae565b609a546097549192506145fe916001600160a01b03908116911683613203565b60008161460b8486615439565b6146159190615439565b9050614635614622611873565b6097546001600160a01b03169083613203565b60408051848152602081018390529081018390527fd255b592c7f268a73e534da5219a60ff911b4cf6daae21c7d20527dd657bd99a9060600160405180910390a1505050505094509492505050565b61468f838284614ce4565b60da805465ffffffffffff1916630100000062ffffff9384160262ffffff19161792909116919091179055505050565b6000806146ca61089e565b909250905060008215614706576ec097ce7bc90715b34b9f10000000006146ef611965565b6146f99085615797565b61470391906157ae565b90505b8181101561476557614719868587614ce4565b5060db805462ffffff191662ffffff9290921691909117905561473d868680614ce4565b5060db805462ffffff90921663010000000265ffffff000000199092169190911790556147c0565b808210156147c057614778868687614ce4565b60db805462ffffff191662ffffff929092169190911790555061479c868587614ce4565b60db805462ffffff90921663010000000265ffffff00000019909216919091179055505b60db5460da54600291820b910b1480156147f1575060db5460da54630100000091829004600290810b92909104900b145b15611c2957604051631434ed7f60e01b815260040160405180910390fd5b60655460ff16806148925750609b60009054906101000a90046001600160a01b03166001600160a01b031663f12d54d86040518163ffffffff1660e01b8152600401602060405180830381865afa15801561486e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906148929190615924565b15610d3d5760405163e628b94960e01b815260040160405180910390fd5b6000836001600160a01b0316856001600160a01b031611156148d0579293925b846001600160a01b0316866001600160a01b0316116148fb576148f4858585614d16565b905061496b565b836001600160a01b0316866001600160a01b0316101561495d576000614922878686614d16565b90506000614931878986614d80565b9050806001600160801b0316826001600160801b0316106149525780614954565b815b9250505061496b565b614968858584614d80565b90505b95945050505050565b6000806000614996614984611f77565b61498d87613b78565b6124ab87613b78565b9150915081600014806149a7575080155b156149b75760009250505061360c565b60019250505061360c565b6000806000846001600160a01b0316846040516149df9190615c86565b6000604051808303816000865af19150503d8060008114614a1c576040519150601f19603f3d011682016040523d82523d6000602084013e614a21565b606091505b5091509150818015614a4b575080511580614a4b575080806020019051810190614a4b9190615924565b801561496b5750505050506001600160a01b03163b151590565b6000614aba826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316614db69092919063ffffffff16565b9050805160001480614adb575080806020019051810190614adb9190615924565b611f725760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401611a3d565b60655460ff16610d3d5760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401611a3d565b60655460ff1615610d3d5760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401611a3d565b600054610100900460ff16614bf05760405162461bcd60e51b8152600401611a3d90615a84565b610d3d614dc5565b600054610100900460ff16614c1f5760405162461bcd60e51b8152600401611a3d90615a84565b610d3d614df5565b6000826001600160a01b0316846001600160a01b03161115614c47579192915b6001600160a01b038416614c906fffffffffffffffffffffffffffffffff60601b606085901b16614c788787615ca2565b6001600160a01b0316866001600160a01b031661355f565b613f9291906157ae565b6000826001600160a01b0316846001600160a01b03161115614cba579192915b613f926001600160801b038316614cd18686615ca2565b6001600160a01b0316600160601b61355f565b6000806000614cf38685614e28565b9050614cff8582615cc2565b9250614d0b8582615ce7565b915050935093915050565b6000826001600160a01b0316846001600160a01b03161115614d36579192915b6000614d59856001600160a01b0316856001600160a01b0316600160601b61355f565b905061496b614d7b8483614d6d8989615ca2565b6001600160a01b031661355f565b614e72565b6000826001600160a01b0316846001600160a01b03161115614da0579192915b613f92614d7b83600160601b614d6d8888615ca2565b6060613f928484600085614e8d565b600054610100900460ff16614dec5760405162461bcd60e51b8152600401611a3d90615a84565b610d3d336134e3565b600054610100900460ff16614e1c5760405162461bcd60e51b8152600401611a3d90615a84565b6065805460ff19169055565b600080614e358385615d0c565b905060008460020b128015614e555750614e4f8385615d3d565b60020b15155b15614e685780614e6481615d5f565b9150505b613f92838261575d565b806001600160801b0381168114614e8857600080fd5b919050565b606082471015614eee5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401611a3d565b600080866001600160a01b03168587604051614f0a9190615c86565b60006040518083038185875af1925050503d8060008114614f47576040519150601f19603f3d011682016040523d82523d6000602084013e614f4c565b606091505b5091509150614f5d87838387614f68565b979650505050505050565b60608315614fd7578251600003614fd0576001600160a01b0385163b614fd05760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401611a3d565b5081613f92565b613f928383815115614fec5781518083602001fd5b8060405162461bcd60e51b8152600401611a3d9190615d82565b5080546000825590600052602060002090810190610b2e919061507e565b604051806060016040528061506a6040518060c0016040528060008152602001600081526020016000815260200160008152602001606081526020016000151581525090565b815260200160008152602001600081525090565b5b80821115615093576000815560010161507f565b5090565b6001600160a01b0381168114610b2e57600080fd5b6000602082840312156150be57600080fd5b813561360c81615097565b8060020b8114610b2e57600080fd5b6000602082840312156150ea57600080fd5b813561360c816150c9565b60006020828403121561510757600080fd5b813563ffffffff8116811461360c57600080fd5b8060060b8114610b2e57600080fd5b60006020828403121561513c57600080fd5b813561360c8161511b565b634e487b7160e01b600052604160045260246000fd5b60405160c0810167ffffffffffffffff8111828210171561518057615180615147565b60405290565b604051601f8201601f1916810167ffffffffffffffff811182821017156151af576151af615147565b604052919050565b600067ffffffffffffffff8211156151d1576151d1615147565b50601f01601f191660200190565b6000806000606084860312156151f457600080fd5b8335925060208401359150604084013567ffffffffffffffff81111561521957600080fd5b8401601f8101861361522a57600080fd5b803561523d615238826151b7565b615186565b81815287602083850101111561525257600080fd5b816020840160208301376000602083830101528093505050509250925092565b60006020828403121561528457600080fd5b5035919050565b6000806040838503121561529e57600080fd5b50508035926020909101359150565b60008060008060008587036101008112156152c757600080fd5b86356152d281615097565b955060208701356152e281615097565b945060408701356152f281615097565b93506060870135615302816150c9565b92506080607f198201121561531657600080fd5b506080860190509295509295909350565b60005b8381101561534257818101518382015260200161532a565b50506000910152565b60008151808452615363816020860160208601615327565b601f01601f19169290920160200192915050565b60208152600082516060602084015280516080840152602081015160a0840152604081015160c0840152606081015160e0840152608081015160c06101008501526153c661014085018261534b565b905060a082015115156101208501526020850151604085015260408501516060850152809250505092915050565b634e487b7160e01b600052603260045260246000fd5b60006020828403121561541c57600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b8181038181111561354a5761354a615423565b805161ffff81168114614e8857600080fd5b80518015158114614e8857600080fd5b600080600080600080600060e0888a03121561548957600080fd5b875161549481615097565b60208901519097506154a5816150c9565b95506154b36040890161544c565b94506154c16060890161544c565b93506154cf6080890161544c565b925060a088015160ff811681146154e557600080fd5b91506154f360c0890161545e565b905092959891949750929550565b6020808252825182820181905260009190848201906040850190845b8181101561553f57835163ffffffff168352928401929184019160010161551d565b50909695505050505050565b600067ffffffffffffffff82111561556557615565615147565b5060051b60200190565b600082601f83011261558057600080fd5b815160206155906152388361554b565b8083825260208201915060208460051b8701019350868411156155b257600080fd5b602086015b848110156155d75780516155ca81615097565b83529183019183016155b7565b509695505050505050565b600080604083850312156155f557600080fd5b825167ffffffffffffffff8082111561560d57600080fd5b818501915085601f83011261562157600080fd5b815160206156316152388361554b565b82815260059290921b8401810191818101908984111561565057600080fd5b948201945b838610156156775785516156688161511b565b82529482019490820190615655565b9188015191965090935050508082111561569057600080fd5b5061569d8582860161556f565b9150509250929050565b600682810b9082900b03667fffffffffffff198112667fffffffffffff8213171561354a5761354a615423565b634e487b7160e01b600052601260045260246000fd5b60008160060b8360060b80615701576157016156d4565b667fffffffffffff1982146000198214161561571f5761571f615423565b90059392505050565b60609490941b6bffffffffffffffffffffffff19168452601484019290925260e890811b60348401521b6037820152603a0190565b60008260020b8260020b028060020b915080821461577d5761577d615423565b5092915050565b8082018082111561354a5761354a615423565b808202811582820484141761354a5761354a615423565b6000826157bd576157bd6156d4565b500490565b6000602082840312156157d457600080fd5b815161360c81615097565b6000602082840312156157f157600080fd5b815162ffffff8116811461360c57600080fd5b600681810b9083900b01667fffffffffffff8113667fffffffffffff198212171561354a5761354a615423565b600181815b8085111561586c57816000190482111561585257615852615423565b8085161561585f57918102915b93841c9390800290615836565b509250929050565b6000826158835750600161354a565b816158905750600061354a565b81600181146158a657600281146158b0576158cc565b600191505061354a565b60ff8411156158c1576158c1615423565b50506001821b61354a565b5060208310610133831016604e8410600b84101617156158ef575081810a61354a565b6158f98383615831565b806000190482111561590d5761590d615423565b029392505050565b600061354760ff841683615874565b60006020828403121561593657600080fd5b6135478261545e565b80516001600160801b0381168114614e8857600080fd5b600080600080600060a0868803121561596e57600080fd5b6159778661593f565b945060208601519350604086015192506159936060870161593f565b91506159a16080870161593f565b90509295509295909350565b600293840b81529190920b60208201526001600160801b03909116604082015260600190565b600080604083850312156159e657600080fd5b505080516020909101519092909150565b6001600160a01b03959095168552600293840b60208601529190920b60408401526001600160801b03918216606084015216608082015260a00190565b60008060408385031215615a4757600080fd5b615a508361593f565b9150615a5e6020840161593f565b90509250929050565b600060208284031215615a7957600080fd5b815161360c816150c9565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b60006020808385031215615ae257600080fd5b825167ffffffffffffffff80821115615afa57600080fd5b9084019060c08287031215615b0e57600080fd5b615b1661515d565b8251815283830151848201526040830151604082015260608301516060820152608083015182811115615b4857600080fd5b83019150601f82018713615b5b57600080fd5b8151615b69615238826151b7565b8181528886838601011115615b7d57600080fd5b615b8c82878301888701615327565b608083015250615b9e60a0840161545e565b60a08201529695505050505050565b600060c0820160018060a01b03808a16845260208960208601528860020b60408601528760020b606086015260c0608086015282875480855260e087019150886000526020600020945060005b81811015615c18578554851683526001958601959284019201615bfa565b50506001600160a01b03871660a08701529350614f5d92505050565b6000600160ff1b8201615c4957615c49615423565b5060000390565b60008160020b627fffff198103615c6957615c69615423565b60000392915050565b600082615c8157615c816156d4565b500690565b60008251615c98818460208701615327565b9190910192915050565b6001600160a01b0382811682821603908082111561577d5761577d615423565b600282810b9082900b03627fffff198112627fffff8213171561354a5761354a615423565b600281810b9083900b01627fffff8113627fffff198212171561354a5761354a615423565b60008160020b8360020b80615d2357615d236156d4565b627fffff1982146000198214161561571f5761571f615423565b60008260020b80615d5057615d506156d4565b808360020b0791505092915050565b60008160020b627fffff198103615d7857615d78615423565b6000190192915050565b602081526000613547602083018461534b56fea2646970667358221220ca77a92c0dca4ba3a01cd6e06090a1a242b4d8f7179c2df6b7573d091b51cdf864736f6c63430008170033

Deployed Bytecode

0x608060405234801561001057600080fd5b50600436106103fb5760003560e01c806378238c3711610215578063ad29f5da11610125578063d0e30db0116100b8578063e97206a911610087578063e97206a914610832578063f1a392da1461083a578063f2fde38b14610843578063fbfa77cf14610856578063fcc25e131461086957600080fd5b8063d0e30db0146107ef578063d92f3d73146107f7578063d9ceab131461080a578063e941fa781461064657600080fd5b8063bc415d8a116100f4578063bc415d8a146107a8578063c45a0155146107c1578063c7b9d530146107d4578063c7d54132146107e757600080fd5b8063ad29f5da1461077b578063b20feaaf14610783578063b3a60cb314610798578063b83d2683146107a057600080fd5b80638e145459116101a85780639bdde46b116101775780639bdde46b1461073d578063a035b1fe14610745578063a6f19c841461074d578063a80f35b814610760578063aced16611461077357600080fd5b80638e145459146106d957806393c8dc6d146106e157806393f1c4421461070157806399cd24461461070a57600080fd5b8063865238d4116101e4578063865238d4146106a4578063877562b6146106ad5780638cfc0250146106c05780638da5cb5b146106c857600080fd5b806378238c37146106695780637bb7bed11461067c5780637bb98a681461068f5780638097e2491461069757600080fd5b80633e48f4171161031057806354cf2aeb116102a35780636099134611610272578063609913461461062057806366666aa91461063357806367a5279314610646578063696c58e51461064d578063715018a61461066157600080fd5b806354cf2aeb146105db57806355a68ed3146105e35780635c975abb146105f65780635ee167c01461060d57600080fd5b806344b81396116102df57806344b81396146105ba5780634641257d146105c25780634746fb55146105ca5780634c02a21c146105d257600080fd5b80633e48f417146105795780633e55f9321461058c5780633f4ba83a1461059f578063441a3e70146105a757600080fd5b806317dd7a72116103935780632150c518116103625780632150c51814610516578063257ae0de1461051e5780632b950b6614610531578063362c28c61461053a5780633c1d5df01461054d57600080fd5b806317dd7a72146104d55780631c03e6cc146104dd5780631d27050f146104f05780631fe4a6861461050357600080fd5b806311b0b42d116103cf57806311b0b42d146104695780631208aa181461049457806312cf1381146104af57806316f0115b146104c257600080fd5b8062a4b5c91461040057806304c404b314610422578063065e5360146104395780630e5c011e14610454575b600080fd5b61040861089e565b604080519283526020830191909152015b60405180910390f35b61042b609d5481565b604051908152602001610419565b610441610aab565b60405160029190910b8152602001610419565b6104676104623660046150ac565b610b25565b005b60975461047c906001600160a01b031681565b6040516001600160a01b039091168152602001610419565b61049c610b31565b60405160069190910b8152602001610419565b6104676104bd3660046150d8565b610ca0565b60d15461047c906001600160a01b031681565b610467610d21565b6104676104eb3660046150ac565b610d3f565b6104676104fe3660046150f5565b610e51565b609a5461047c906001600160a01b031681565b610408610ef2565b60995461047c906001600160a01b031681565b61042b609c5481565b61046761054836600461512a565b610f79565b60dc5461056490600160501b900463ffffffff1681565b60405163ffffffff9091168152602001610419565b6104676105873660046151df565b61101c565b61046761059a366004615272565b6110c9565b6104676111be565b6104676105b536600461528b565b61126b565b61040861131d565b61046761142a565b61047c611433565b61042b60d95481565b61042b6114a6565b6104676105f13660046150ac565b611545565b60655460ff165b6040519015158152602001610419565b60d45461047c906001600160a01b031681565b61046761062e36600461528b565b6115f5565b60d35461047c906001600160a01b031681565b600061042b565b60dc5461049c906301000000900460060b81565b6104676116ab565b6104676106773660046150ac565b6116bd565b61047c61068a366004615272565b611729565b610408611753565b60dc546104419060020b81565b61042b609f5481565b60d55461047c906001600160a01b031681565b61042b6117ff565b6033546001600160a01b031661047c565b61047c611873565b61042b6106ef3660046150ac565b60d76020526000908152604090205481565b61042b60d85481565b60db5461072390600281810b9163010000009004900b82565b60408051600293840b81529190920b602082015201610419565b6105fd6118bd565b61042b611965565b60d25461047c906001600160a01b031681565b61046761076e3660046152ad565b6119a4565b61047c611c31565b610467611c7b565b61078b611d5b565b6040516104199190615377565b610467611d8b565b61047c611f77565b60da5461072390600281810b9163010000009004900b82565b609b5461047c906001600160a01b031681565b6104676107e23660046150ac565b611ff1565b61046761206a565b61046761216d565b6104676108053660046150ac565b6121b1565b61081261221d565b604080519485526020850193909352918301526060820152608001610419565b610408612263565b61042b609e5481565b6104676108513660046150ac565b6122d2565b60985461047c906001600160a01b031681565b610871612348565b604080519687526020870195909552938501929092526060840152608083015260a082015260c001610419565b60008060008060005b60d6548110156109b15760d45460d680546001600160a01b0390921691839081106108d4576108d46153f4565b6000918252602090912001546001600160a01b03160361092d5760d7600060d68381548110610905576109056153f4565b60009182526020808320909101546001600160a01b0316835282019290925260400190205492505b60d55460d680546001600160a01b039092169183908110610950576109506153f4565b6000918252602090912001546001600160a01b0316036109a95760d7600060d68381548110610981576109816153f4565b60009182526020808320909101546001600160a01b0316835282019290925260400190205491505b6001016108a7565b5060d4546040516370a0823160e01b815230600482015283916001600160a01b0316906370a0823190602401602060405180830381865afa1580156109fa573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a1e919061540a565b610a289190615439565b60d5546040516370a0823160e01b815230600482015291955082916001600160a01b03909116906370a0823190602401602060405180830381865afa158015610a75573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a99919061540a565b610aa39190615439565b925050509091565b60d15460408051633850c7bd60e01b815290516000926001600160a01b031691633850c7bd9160048083019260e09291908290030181865afa158015610af5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b19919061546e565b50939695505050505050565b610b2e81612545565b50565b6040805160028082526060820183526000928392919060208301908036833701905050905060dc600a9054906101000a900463ffffffff1681600081518110610b7c57610b7c6153f4565b602002602001019063ffffffff16908163ffffffff1681525050600081600181518110610bab57610bab6153f4565b63ffffffff9092166020928302919091019091015260d15460405163883bdbfd60e01b81526000916001600160a01b03169063883bdbfd90610bf1908590600401615501565b600060405180830381865afa158015610c0e573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610c3691908101906155e2565b50905060dc600a9054906101000a900463ffffffff1660030b81600081518110610c6257610c626153f4565b602002602001015182600181518110610c7d57610c7d6153f4565b6020026020010151610c8f91906156a7565b610c9991906156ea565b9250505090565b610ca86125fc565b60dc5460408051600292830b81529183900b60208301527f69d927977053f4ff4a26e8d792564e367e844a869cda4df12630bf7b62a632de910160405180910390a1610cf2612656565b50505050610cfe612a55565b60dc805462ffffff191662ffffff8316179055610d19612da7565b610b2e612dfd565b610d296130a8565b610d31612656565b50505050610d3d612a55565b565b6033546001600160a01b03163314801590610d735750610d5d611c31565b6001600160a01b0316336001600160a01b031614155b15610d915760405163607e454560e11b815260040160405180910390fd5b60d354610dac906001600160a01b03838116911660006130d3565b60d354610dc8906001600160a01b0383811691166000196130d3565b609954610de3906001600160a01b03838116911660006130d3565b609954610dff906001600160a01b0383811691166000196130d3565b60d680546001810182556000919091527fe767803f8ecf1dee6bb0345811f7312cda556058b19db6389ad9ae3568643ddd0180546001600160a01b0319166001600160a01b0392909216919091179055565b610e596125fc565b60dc546040805163ffffffff600160501b9093048316815291831660208301527f86139943149914833c057d2c24f3a3967cce8e6aba2eb12e422500d8a51ffc7b910160405180910390a1603c8163ffffffff161015610ecc5760405163b4fa3fb360e01b815260040160405180910390fd5b60dc805463ffffffff909216600160501b0263ffffffff60501b19909216919091179055565b60da546040516000918291610f1e9130918491600281810b926301000000909204900b90602001615728565b60408051601f1981840301815290829052805160209182012060db54909450610f5d923092600092600281810b936301000000909204900b9101615728565b6040516020818303038152906040528051906020012090509091565b610f816125fc565b604051600682900b81527f69d3f73bfb3c2f0de63dc1de2ed486cf45d88ebfff8cb1e8f124b085d2bafb979060200160405180910390a1610fc0613195565b610fcb90600461575d565b60020b8160060b12610ff05760405163b4fa3fb360e01b815260040160405180910390fd5b60dc805466ffffffffffffff90921663010000000269ffffffffffffff00000019909216919091179055565b60d1546001600160a01b0316331461104757604051636f61f64160e01b815260040160405180910390fd5b60dc54600160701b900460ff166110715760405163887efaa560e01b815260040160405180910390fd5b82156110945760d15460d454611094916001600160a01b03918216911685613203565b81156110b75760d15460d5546110b7916001600160a01b03918216911684613203565b505060dc805460ff60701b1916905550565b6033546001600160a01b031633148015906110fd57506110e7611c31565b6001600160a01b0316336001600160a01b031614155b1561111b5760405163607e454560e11b815260040160405180910390fd5b611123611433565b6001600160a01b0316633e55f932826040518263ffffffff1660e01b815260040161115091815260200190565b600060405180830381600087803b15801561116a57600080fd5b505af115801561117e573d6000803e3d6000fd5b505050507f9163810ee1e29168d4ce900e48a333fb8fbd3fd070d2bef67f6d4db0846a469f816040516111b391815260200190565b60405180910390a150565b6033546001600160a01b031633148015906111f257506111dc611c31565b6001600160a01b0316336001600160a01b031614155b156112105760405163607e454560e11b815260040160405180910390fd5b60006112246033546001600160a01b031690565b6001600160a01b03160361124b5760405163ea8e4eb560e01b815260040160405180910390fd5b611253613233565b61125b613328565b611263612da7565b610d3d612dfd565b6112736130a8565b81156112965760985460d454611296916001600160a01b03918216911684613203565b80156112b95760985460d5546112b9916001600160a01b03918216911683613203565b6112c161337a565b6112cd576112cd612dfd565b6000806112d8611753565b60408051838152602081018390529294509092507f631c4f79c14099a717f4be2f25e6cef89e310b3944ef0e44ea2c0811ebb982a8910160405180910390a150505050565b60008060008061132b61089e565b9150915060008061133a612348565b5050505091509150600082856113509190615784565b9050600061135e8386615784565b90506000609e54426113709190615439565b90506000610e108210611384576000611390565b61139082610e10615439565b9050609c548411156113be57610e1081609c546113ad9190615797565b6113b791906157ae565b99506113d8565b610e106113cb8286615797565b6113d591906157ae565b99505b609d5483111561140457610e1081609d546113f39190615797565b6113fd91906157ae565b985061141e565b610e106114118285615797565b61141b91906157ae565b98505b50505050505050509091565b610d3d32612545565b609b5460408051634746fb5560e01b815290516000926001600160a01b031691634746fb559160048083019260209291908290030181865afa15801561147d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114a191906157c2565b905090565b6000620f4240670de0b6b3a764000060d160009054906101000a90046001600160a01b03166001600160a01b031663ddca3f436040518163ffffffff1660e01b8152600401602060405180830381865afa158015611508573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061152c91906157df565b62ffffff1661153b9190615797565b6114a191906157ae565b6033546001600160a01b031633148015906115795750611563611c31565b6001600160a01b0316336001600160a01b031614155b156115975760405163607e454560e11b815260040160405180910390fd5b6040516001600160a01b03821681527f17228b08e4c958112a0827a6d8dc8475dba58dd068a3d400800a606794db02a69060200160405180910390a160d280546001600160a01b0319166001600160a01b0392909216919091179055565b6033546001600160a01b031633148015906116295750611613611c31565b6001600160a01b0316336001600160a01b031614155b156116475760405163607e454560e11b815260040160405180910390fd5b61164f612656565b5050505061165b612a55565b611663613405565b61166b6134a6565b600080611676611753565b915091508382108061168757508281105b156116a55760405163fa6ad35560e01b815260040160405180910390fd5b50505050565b6116b36125fc565b610d3d60006134e3565b6116c56125fc565b6116cd613405565b60d380546001600160a01b0319166001600160a01b0383161790556116f0613233565b6040516001600160a01b03821681527f173d73afad648e625c4a53878536f7a2debed1f51a04f21d728bce3cf534fcc1906020016111b3565b60d6818154811061173957600080fd5b6000918252602090912001546001600160a01b0316905081565b60008060008061176161089e565b91509150600080611770612348565b505050509150915060008061178361131d565b90925090506000826117958689615784565b61179f9190615439565b90506000826117ae8689615784565b6117b89190615439565b60d85460d95491925090838211156117ce578391505b828111156117d95750815b6117e38285615439565b6117ed8285615439565b9b509b50505050505050505050509091565b6000611809611433565b604051636788231160e11b81523060048201526001600160a01b03919091169063cf10462290602401602060405180830381865afa15801561184f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114a1919061540a565b609b5460408051638e14545960e01b815290516000926001600160a01b031691638e1454599160048083019260209291908290030181865afa15801561147d573d6000803e3d6000fd5b6000806118c8610aab565b905060006118d4610b31565b60dc54909150600090611902906118f5906301000000900460060b846156a7565b60060b620d89e719613535565b60dc5490915060009061192f90611923906301000000900460060b85615804565b60060b620d89e8613550565b90508360020b8260060b138061194a57508360020b8160060b125b1561195a57600094505050505090565b600194505050505090565b600080611970611f77565b90506002611994826001600160a01b0316670de0b6b3a7640000600160601b61355f565b61199e9190615915565b91505090565b600054610100900460ff16158080156119c45750600054600160ff909116105b806119de5750303b1580156119de575060005460ff166001145b611a465760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b60648201526084015b60405180910390fd5b6000805460ff191660011790558015611a69576000805461ff0019166101001790555b611a7282613613565b60d180546001600160a01b038089166001600160a01b0319928316811790935560d2805489831690841617905560d380549188169190921617905560408051630dfe168160e01b81529051630dfe1681916004808201926020929091908290030181865afa158015611ae8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b0c91906157c2565b60d460006101000a8154816001600160a01b0302191690836001600160a01b03160217905550856001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa158015611b70573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b9491906157c2565b60d580546001600160a01b0319166001600160a01b039290921691909117905560dc805462ffffff85166dffffffff00000000000000ffffff1990911617600f60531b179055611be2613233565b8015611c29576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb3847402498906020015b60405180910390a15b505050505050565b609b546040805163aced166160e01b815290516000926001600160a01b03169163aced16619160048083019260209291908290030181865afa15801561147d573d6000803e3d6000fd5b6033546001600160a01b03163314801590611caf5750611c99611c31565b6001600160a01b0316336001600160a01b031614155b15611ccd5760405163607e454560e11b815260040160405180910390fd5b60005b60d654811015611d4e5760d35460d68054611d1e926001600160a01b03169160009185908110611d0257611d026153f4565b6000918252602090912001546001600160a01b031691906130d3565b60995460d68054611d46926001600160a01b03169160009185908110611d0257611d026153f4565b600101611cd0565b50610d3d60d66000615006565b611d63615024565b6040518060600160405280611d76613788565b81526020016000815260200160009052919050565b611d936125fc565b609860009054906101000a90046001600160a01b03166001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611de6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e0a919061540a565b6103e814611e2b5760405163ea8e4eb560e01b815260040160405180910390fd5b611e366000806115f5565b6000611e40611873565b9050600080611e4d61089e565b90925090508115611edd5760d4546040516370a0823160e01b8152306004820152611edd9185916001600160a01b03909116906370a0823190602401602060405180830381865afa158015611ea6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611eca919061540a565b60d4546001600160a01b03169190613203565b8015611f685760d5546040516370a0823160e01b8152306004820152611f689185916001600160a01b03909116906370a0823190602401602060405180830381865afa158015611f31573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f55919061540a565b60d5546001600160a01b03169190613203565b611f7260006134e3565b505050565b60d15460408051633850c7bd60e01b815290516000926001600160a01b031691633850c7bd9160048083019260e09291908290030181865afa158015611fc1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611fe5919061546e565b50949695505050505050565b609a546001600160a01b0316331461201c57604051633163ba6d60e11b815260040160405180910390fd5b609a80546001600160a01b0319166001600160a01b0383169081179091556040519081527f46d58e3fa07bf19b1d27240f0e286b27e9f7c1b0d88933333fe833b60eec5412906020016111b3565b612072613839565b609b546040516305226abd60e51b81523360048201526001600160a01b039091169063a44d57a090602401602060405180830381865afa1580156120ba573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120de9190615924565b6120fb5760405163ea8e4eb560e01b815260040160405180910390fd5b612103612656565b5050505061210f612a55565b612117612da7565b61211f612dfd565b60008061212a611753565b60408051838152602081018390529294509092507f631c4f79c14099a717f4be2f25e6cef89e310b3944ef0e44ea2c0811ebb982a8910160405180910390a15050565b612175613839565b61217d6130a8565b60dc54600160781b900460ff1661211757612196612da7565b60dc805460ff60781b1916600160781b17905561211f612dfd565b6121b96125fc565b6121c1613405565b609980546001600160a01b0319166001600160a01b0383161790556121e4613233565b6040516001600160a01b03821681527f5ca6e64c4522e68e154aa9372f2c5969cd37d9640e59f66953dc472f54ee86fa906020016111b3565b60008060008061222b612656565b60d6549397509195509350915015801590612250575060d2546001600160a01b031615155b1561225d5761225d61385e565b90919293565b60da5460009081906002906122999061227d90830b613b78565b6001600160a01b0316670de0b6b3a7640000600160601b61355f565b6122a39190615915565b60da549092506002906122c29061227d9063010000009004830b613b78565b6122cc9190615915565b90509091565b6122da6125fc565b6001600160a01b03811661233f5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401611a3d565b610b2e816134e3565b60008060008060008060008061235c610ef2565b91509150600061236a611f77565b60d15460405163514ea4bf60e01b815260048101869052919250600091829182916001600160a01b039091169063514ea4bf9060240160a060405180830381865afa1580156123bd573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123e19190615956565b60d15460405163514ea4bf60e01b8152600481018c90529598506001600160801b039283169750911694506000938493508392506001600160a01b039091169063514ea4bf9060240160a060405180830381865afa158015612447573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061246b9190615956565b60da549497506001600160801b0391821696501693506124b1928a9250612495915060020b613b78565b60da546124ab906301000000900460020b613b78565b89613f9a565b60db54919e509c506124e79088906124cb9060020b613b78565b60db546124e1906301000000900460020b613b78565b86613f9a565b909b5099506124f6858e615784565b9c50612502848d615784565b9b5061250e828c615784565b9a5061251a818b615784565b99506125268b8e615784565b9e506125328a8d615784565b9d50505050505050505050909192939495565b61254d61221d565b50505050612559612a55565b60d6546000901561256f5761256c614036565b90505b6000806125828460d85460d95486614344565b9150915061258e612dfd565b600060d881905560d9819055806125a361131d565b90925090506125b28285615784565b609c556125bf8184615784565b609d5542609e5560408051858152602081018590527f6c8433a8e155f0af04dba058d4e4695f7da554578963d876bdf4a6d8d6399d9c9101611c20565b6033546001600160a01b03163314610d3d5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401611a3d565b600080600080600080612667610ef2565b60d15460405163514ea4bf60e01b8152600481018490529294509092506000916001600160a01b039091169063514ea4bf9060240160a060405180830381865afa1580156126b9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126dd9190615956565b505060d15460405163514ea4bf60e01b8152600481018790529394506000936001600160a01b03909116925063514ea4bf915060240160a060405180830381865afa158015612730573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127549190615956565b5050505090506000826001600160801b031611156127f55760d15460da5460405163a34123a760e01b81526001600160a01b039092169163a34123a7916127b091600282810b9263010000009004900b906000906004016159ad565b60408051808303816000875af11580156127ce573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127f291906159d3565b50505b6001600160801b0381161561288d5760d15460db5460405163a34123a760e01b81526001600160a01b039092169163a34123a79161284891600282810b9263010000009004900b906000906004016159ad565b60408051808303816000875af1158015612866573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061288a91906159d3565b50505b60d15460da546040516309e3d67b60e31b81526001600160a01b0390921691634f1eb3d8916128dc913091600281810b926301000000909204900b906001600160801b039081906004016159f7565b60408051808303816000875af11580156128fa573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061291e9190615a34565b60d15460db546040516309e3d67b60e31b81526001600160801b039485169c509284169a506001600160a01b0390911692634f1eb3d892612976923092600282810b936301000000909304900b9181906004016159f7565b60408051808303816000875af1158015612994573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129b89190615a34565b60d8546001600160801b0392831698509116955086906129d9908a90615784565b6129e39190615784565b60d85560d95485906129f6908990615784565b612a009190615784565b60d9556040805189815260208101899052908101879052606081018690527f6fe7c663aa15def6e80578b76ddd894fcefeabf14a0106afbec24da4a6c578729060800160405180910390a15050505090919293565b600080612a60610ef2565b60d15460405163514ea4bf60e01b8152600481018490529294509092506000916001600160a01b039091169063514ea4bf9060240160a060405180830381865afa158015612ab2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ad69190615956565b505060d15460405163514ea4bf60e01b8152600481018790529394506000936001600160a01b03909116925063514ea4bf915060240160a060405180830381865afa158015612b29573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b4d9190615956565b5050505090506000826001600160801b03161115612c805760d15460da5460405163a34123a760e01b81526001600160a01b039092169163a34123a791612ba891600282810b9263010000009004900b9087906004016159ad565b60408051808303816000875af1158015612bc6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612bea91906159d3565b505060d15460da546040516309e3d67b60e31b81526001600160a01b0390921691634f1eb3d891612c3b913091600281810b926301000000909204900b906001600160801b039081906004016159f7565b60408051808303816000875af1158015612c59573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c7d9190615a34565b50505b6001600160801b038116156116a55760d15460db5460405163a34123a760e01b81526001600160a01b039092169163a34123a791612cd291600282810b9263010000009004900b9086906004016159ad565b60408051808303816000875af1158015612cf0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d1491906159d3565b505060d15460db546040516309e3d67b60e31b81526001600160a01b0390921691634f1eb3d891612d65913091600281810b926301000000909204900b906001600160801b039081906004016159f7565b60408051808303816000875af1158015612d83573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c299190615a34565b612daf613839565b6000612db9610aab565b90506000612dc5613195565b60dc54909150600090612ddc90839060020b61575d565b9050612de9838383614684565b612df48383836146bf565b505042609f5550565b612e0561480f565b600080612e1061089e565b915091506000612e1e611f77565b60da54909150600090612e56908390612e399060020b613b78565b60da54612e4f906301000000900460020b613b78565b87876148b0565b60da54909150600090612e79908390600281810b9163010000009004900b614974565b90506000826001600160801b0316118015612e915750805b15612f725760dc805460ff60701b1916600160701b17905560d15460da54604051638221b8c160e01b815230600482015260006024820152600282810b6044830152630100000090920490910b60648201526001600160801b038416608482015260c060a4820152600a60c4820152692132b2b33c9026b0b4b760b11b60e48201526001600160a01b0390911690638221b8c1906101040160408051808303816000875af1158015612f47573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f6b91906159d3565b5050612f7a565b612f7a613839565b612f8261089e565b60db549196509450612fb9908490612f9c9060020b613b78565b60db54612fb2906301000000900460020b613b78565b88886148b0565b91506001600160801b038216156130a15760dc805460ff60701b1916600160701b17905560d15460db54604051638221b8c160e01b815230600482015260006024820152600282810b6044830152630100000090920490910b60648201526001600160801b038416608482015260c060a4820152600960c482015268109959599e48105b1d60ba1b60e48201526001600160a01b0390911690638221b8c1906101040160408051808303816000875af115801561307a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061309e91906159d3565b50505b5050505050565b6098546001600160a01b03163314610d3d576040516362df054560e01b815260040160405180910390fd5b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663095ea7b360e01b17905261312484826149c2565b6116a5576040516001600160a01b03841660248201526000604482015261318b90859063095ea7b360e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152614a65565b6116a58482614a65565b60d154604080516334324e9f60e21b815290516000926001600160a01b03169163d0c93a7c9160048083019260209291908290030181865afa1580156131df573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114a19190615a67565b6040516001600160a01b038316602482015260448101829052611f7290849063a9059cbb60e01b90606401613154565b60995460d454613252916001600160a01b0391821691166000196130d3565b60995460d554613271916001600160a01b0391821691166000196130d3565b60005b60d654811015610b2e5760995460d680546132a6926001600160a01b03169160009185908110611d0257611d026153f4565b60995460d680546132cf926001600160a01b0316916000199185908110611d0257611d026153f4565b60d35460d680546132f7926001600160a01b03169160009185908110611d0257611d026153f4565b60d35460d68054613320926001600160a01b0316916000199185908110611d0257611d026153f4565b600101613274565b613330614b3a565b6065805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b600061338860655460ff1690565b806114a15750609b60009054906101000a90046001600160a01b03166001600160a01b031663f12d54d86040518163ffffffff1660e01b8152600401602060405180830381865afa1580156133e1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114a19190615924565b60995460d454613423916001600160a01b03918216911660006130d3565b60995460d554613441916001600160a01b03918216911660006130d3565b60005b60d654811015610b2e5760995460d68054613476926001600160a01b03169160009185908110611d0257611d026153f4565b60d35460d6805461349e926001600160a01b03169160009185908110611d0257611d026153f4565b600101613444565b6134ae614b83565b6065805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a25861335d3390565b603380546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b6000818312156135455781613547565b825b90505b92915050565b60008183126135455781613547565b6000808060001985870985870292508281108382030391505080600003613598576000841161358d57600080fd5b50829004905061360c565b8084116135a457600080fd5b600084868809851960019081018716968790049682860381900495909211909303600082900391909104909201919091029190911760038402600290811880860282030280860282030280860282030280860282030280860282030280860290910302029150505b9392505050565b600054610100900460ff1661363a5760405162461bcd60e51b8152600401611a3d90615a84565b613642614bc9565b61364a614bf8565b61365760208201826150ac565b609880546001600160a01b0319166001600160a01b039290921691909117905561368760408201602083016150ac565b609980546001600160a01b0319166001600160a01b03929092169190911790556136b760608201604083016150ac565b609a80546001600160a01b0319166001600160a01b03929092169190911790556136e760808201606083016150ac565b609b80546001600160a01b0319166001600160a01b03929092169182179055604080516311b0b42d60e01b815290516311b0b42d916004808201926020929091908290030181865afa158015613741573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061376591906157c2565b609780546001600160a01b0319166001600160a01b039290921691909117905550565b6137c36040518060c0016040528060008152602001600081526020016000815260200160008152602001606081526020016000151581525090565b6137cb611433565b604051639af608c960e01b81523060048201526001600160a01b039190911690639af608c990602401600060405180830381865afa158015613811573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526114a19190810190615acf565b6138416118bd565b610d3d576040516313643c3b60e11b815260040160405180910390fd5b60d65460009067ffffffffffffffff81111561387c5761387c615147565b6040519080825280602002602001820160405280156138a5578160200160208202803683370190505b50905060005b60d6548110156139625760d681815481106138c8576138c86153f4565b6000918252602090912001546040516370a0823160e01b81523060048201526001600160a01b03909116906370a0823190602401602060405180830381865afa158015613919573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061393d919061540a565b82828151811061394f5761394f6153f4565b60209081029190910101526001016138ab565b5060d25460da546040516318d9dceb60e31b81526001600160a01b039092169163c6cee758916139ae913091600091600282810b9263010000009004900b9060d6908590600401615bad565b600060405180830381600087803b1580156139c857600080fd5b505af11580156139dc573d6000803e3d6000fd5b505060d25460db546040516318d9dceb60e31b81526001600160a01b03909216935063c6cee7589250613a2b913091600091600282810b9263010000009004900b9060d6908590600401615bad565b600060405180830381600087803b158015613a4557600080fd5b505af1158015613a59573d6000803e3d6000fd5b5050505060005b60d654811015613b74576000828281518110613a7e57613a7e6153f4565b602002602001015160d68381548110613a9957613a996153f4565b6000918252602090912001546040516370a0823160e01b81523060048201526001600160a01b03909116906370a0823190602401602060405180830381865afa158015613aea573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613b0e919061540a565b613b189190615439565b90508060d7600060d68581548110613b3257613b326153f4565b60009182526020808320909101546001600160a01b0316835282019290925260400181208054909190613b66908490615784565b909155505050600101613a60565b5050565b60008060008360020b12613b8f578260020b613b9c565b8260020b613b9c90615c34565b9050613bab620d89e719615c50565b62ffffff16811115613be35760405162461bcd60e51b81526020600482015260016024820152601560fa1b6044820152606401611a3d565b600081600116600003613bfa57600160801b613c0c565b6ffffcb933bd6fad37aa2d162d1a5940015b70ffffffffffffffffffffffffffffffffff1690506002821615613c4b576080613c46826ffff97272373d413259a46990580e213a615797565b901c90505b6004821615613c75576080613c70826ffff2e50f5f656932ef12357cf3c7fdcc615797565b901c90505b6008821615613c9f576080613c9a826fffe5caca7e10e4e61c3624eaa0941cd0615797565b901c90505b6010821615613cc9576080613cc4826fffcb9843d60f6159c9db58835c926644615797565b901c90505b6020821615613cf3576080613cee826fff973b41fa98c081472e6896dfb254c0615797565b901c90505b6040821615613d1d576080613d18826fff2ea16466c96a3843ec78b326b52861615797565b901c90505b6080821615613d47576080613d42826ffe5dee046a99a2a811c461f1969c3053615797565b901c90505b610100821615613d72576080613d6d826ffcbe86c7900a88aedcffc83b479aa3a4615797565b901c90505b610200821615613d9d576080613d98826ff987a7253ac413176f2b074cf7815e54615797565b901c90505b610400821615613dc8576080613dc3826ff3392b0822b70005940c7a398e4b70f3615797565b901c90505b610800821615613df3576080613dee826fe7159475a2c29b7443b29c7fa6e889d9615797565b901c90505b611000821615613e1e576080613e19826fd097f3bdfd2022b8845ad8f792aa5825615797565b901c90505b612000821615613e49576080613e44826fa9f746462d870fdf8a65dc1f90e061e5615797565b901c90505b614000821615613e74576080613e6f826f70d869a156d2a1b890bb3df62baf32f7615797565b901c90505b618000821615613e9f576080613e9a826f31be135f97d08fd981231505542fcfa6615797565b901c90505b62010000821615613ecb576080613ec6826f09aa508b5b7a84e1c677de54f3e99bc9615797565b901c90505b62020000821615613ef6576080613ef1826e5d6af8dedb81196699c329225ee604615797565b901c90505b62040000821615613f20576080613f1b826d2216e584f5fa1ea926041bedfe98615797565b901c90505b62080000821615613f48576080613f43826b048a170391f7dc42444e8fa2615797565b901c90505b60008460020b1315613f6357613f60816000196157ae565b90505b613f7264010000000082615c72565b15613f7e576001613f81565b60005b613f929060ff16602083901c615784565b949350505050565b600080836001600160a01b0316856001600160a01b03161115613fbb579293925b846001600160a01b0316866001600160a01b031611613fe657613fdf858585614c27565b915061402d565b836001600160a01b0316866001600160a01b0316101561401f5761400b868585614c27565b9150614018858785614c9a565b905061402d565b61402a858585614c9a565b90505b94509492505050565b600080614041613788565b905060005b60d65481101561433f57600060d7600060d68481548110614069576140696153f4565b60009182526020808320909101546001600160a01b031683528201929092526040019020541115614337576000670de0b6b3a7640000836000015160d7600060d686815481106140bb576140bb6153f4565b60009182526020808320909101546001600160a01b031683528201929092526040019020546140ea9190615797565b6140f491906157ae565b60975460d680549293506000926001600160a01b03909216918590811061411d5761411d6153f4565b6000918252602090912001546001600160a01b0316146141ef5760995460d680546001600160a01b039092169163df791e50919086908110614161576141616153f4565b60009182526020909120015460975460405160e084901b6001600160e01b03191681526001600160a01b03928316600482015291166024820152604481018590526064016020604051808303816000875af11580156141c4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906141e8919061540a565b90506141f2565b50805b60d35460d680546001600160a01b039092169163a3cd8ac491908690811061421c5761421c6153f4565b9060005260206000200160009054906101000a90046001600160a01b03168460d7600060d68981548110614252576142526153f4565b60009182526020808320909101546001600160a01b031683528201929092526040019020546142819190615439565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152620151806044820152606401600060405180830381600087803b1580156142d057600080fd5b505af11580156142e4573d6000803e3d6000fd5b5050505080856142f49190615784565b9450600060d7600060d6868154811061430f5761430f6153f4565b60009182526020808320909101546001600160a01b0316835282019290925260400190205550505b600101614046565b505090565b6000806000614351613788565b9050838615614467578151600090670de0b6b3a764000090614373908a615797565b61437d91906157ae565b90506143898189615439565b60975460d4549196506000916001600160a01b0390811691161461442e5760995460d454609754604051630df791e560e41b81526001600160a01b03928316600482015290821660248201526044810185905291169063df791e50906064016020604051808303816000875af1158015614407573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061442b919061540a565b90505b60975460d4546001600160a01b03918216911603614457576144508284615784565b9250614464565b6144618184615784565b92505b50505b851561457a578151600090670de0b6b3a7640000906144869089615797565b61449091906157ae565b905061449c8188615439565b60975460d5549195506000916001600160a01b039081169116146145415760995460d554609754604051630df791e560e41b81526001600160a01b03928316600482015290821660248201526044810185905291169063df791e50906064016020604051808303816000875af115801561451a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061453e919061540a565b90505b60975460d5546001600160a01b0391821691160361456a576145638284615784565b9250614577565b6145748184615784565b92505b50505b6000670de0b6b3a76400008360400151836145959190615797565b61459f91906157ae565b6097549091506145b9906001600160a01b03168a83613203565b6000670de0b6b3a76400008460600151846145d49190615797565b6145de91906157ae565b609a546097549192506145fe916001600160a01b03908116911683613203565b60008161460b8486615439565b6146159190615439565b9050614635614622611873565b6097546001600160a01b03169083613203565b60408051848152602081018390529081018390527fd255b592c7f268a73e534da5219a60ff911b4cf6daae21c7d20527dd657bd99a9060600160405180910390a1505050505094509492505050565b61468f838284614ce4565b60da805465ffffffffffff1916630100000062ffffff9384160262ffffff19161792909116919091179055505050565b6000806146ca61089e565b909250905060008215614706576ec097ce7bc90715b34b9f10000000006146ef611965565b6146f99085615797565b61470391906157ae565b90505b8181101561476557614719868587614ce4565b5060db805462ffffff191662ffffff9290921691909117905561473d868680614ce4565b5060db805462ffffff90921663010000000265ffffff000000199092169190911790556147c0565b808210156147c057614778868687614ce4565b60db805462ffffff191662ffffff929092169190911790555061479c868587614ce4565b60db805462ffffff90921663010000000265ffffff00000019909216919091179055505b60db5460da54600291820b910b1480156147f1575060db5460da54630100000091829004600290810b92909104900b145b15611c2957604051631434ed7f60e01b815260040160405180910390fd5b60655460ff16806148925750609b60009054906101000a90046001600160a01b03166001600160a01b031663f12d54d86040518163ffffffff1660e01b8152600401602060405180830381865afa15801561486e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906148929190615924565b15610d3d5760405163e628b94960e01b815260040160405180910390fd5b6000836001600160a01b0316856001600160a01b031611156148d0579293925b846001600160a01b0316866001600160a01b0316116148fb576148f4858585614d16565b905061496b565b836001600160a01b0316866001600160a01b0316101561495d576000614922878686614d16565b90506000614931878986614d80565b9050806001600160801b0316826001600160801b0316106149525780614954565b815b9250505061496b565b614968858584614d80565b90505b95945050505050565b6000806000614996614984611f77565b61498d87613b78565b6124ab87613b78565b9150915081600014806149a7575080155b156149b75760009250505061360c565b60019250505061360c565b6000806000846001600160a01b0316846040516149df9190615c86565b6000604051808303816000865af19150503d8060008114614a1c576040519150601f19603f3d011682016040523d82523d6000602084013e614a21565b606091505b5091509150818015614a4b575080511580614a4b575080806020019051810190614a4b9190615924565b801561496b5750505050506001600160a01b03163b151590565b6000614aba826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316614db69092919063ffffffff16565b9050805160001480614adb575080806020019051810190614adb9190615924565b611f725760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401611a3d565b60655460ff16610d3d5760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401611a3d565b60655460ff1615610d3d5760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401611a3d565b600054610100900460ff16614bf05760405162461bcd60e51b8152600401611a3d90615a84565b610d3d614dc5565b600054610100900460ff16614c1f5760405162461bcd60e51b8152600401611a3d90615a84565b610d3d614df5565b6000826001600160a01b0316846001600160a01b03161115614c47579192915b6001600160a01b038416614c906fffffffffffffffffffffffffffffffff60601b606085901b16614c788787615ca2565b6001600160a01b0316866001600160a01b031661355f565b613f9291906157ae565b6000826001600160a01b0316846001600160a01b03161115614cba579192915b613f926001600160801b038316614cd18686615ca2565b6001600160a01b0316600160601b61355f565b6000806000614cf38685614e28565b9050614cff8582615cc2565b9250614d0b8582615ce7565b915050935093915050565b6000826001600160a01b0316846001600160a01b03161115614d36579192915b6000614d59856001600160a01b0316856001600160a01b0316600160601b61355f565b905061496b614d7b8483614d6d8989615ca2565b6001600160a01b031661355f565b614e72565b6000826001600160a01b0316846001600160a01b03161115614da0579192915b613f92614d7b83600160601b614d6d8888615ca2565b6060613f928484600085614e8d565b600054610100900460ff16614dec5760405162461bcd60e51b8152600401611a3d90615a84565b610d3d336134e3565b600054610100900460ff16614e1c5760405162461bcd60e51b8152600401611a3d90615a84565b6065805460ff19169055565b600080614e358385615d0c565b905060008460020b128015614e555750614e4f8385615d3d565b60020b15155b15614e685780614e6481615d5f565b9150505b613f92838261575d565b806001600160801b0381168114614e8857600080fd5b919050565b606082471015614eee5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401611a3d565b600080866001600160a01b03168587604051614f0a9190615c86565b60006040518083038185875af1925050503d8060008114614f47576040519150601f19603f3d011682016040523d82523d6000602084013e614f4c565b606091505b5091509150614f5d87838387614f68565b979650505050505050565b60608315614fd7578251600003614fd0576001600160a01b0385163b614fd05760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401611a3d565b5081613f92565b613f928383815115614fec5781518083602001fd5b8060405162461bcd60e51b8152600401611a3d9190615d82565b5080546000825590600052602060002090810190610b2e919061507e565b604051806060016040528061506a6040518060c0016040528060008152602001600081526020016000815260200160008152602001606081526020016000151581525090565b815260200160008152602001600081525090565b5b80821115615093576000815560010161507f565b5090565b6001600160a01b0381168114610b2e57600080fd5b6000602082840312156150be57600080fd5b813561360c81615097565b8060020b8114610b2e57600080fd5b6000602082840312156150ea57600080fd5b813561360c816150c9565b60006020828403121561510757600080fd5b813563ffffffff8116811461360c57600080fd5b8060060b8114610b2e57600080fd5b60006020828403121561513c57600080fd5b813561360c8161511b565b634e487b7160e01b600052604160045260246000fd5b60405160c0810167ffffffffffffffff8111828210171561518057615180615147565b60405290565b604051601f8201601f1916810167ffffffffffffffff811182821017156151af576151af615147565b604052919050565b600067ffffffffffffffff8211156151d1576151d1615147565b50601f01601f191660200190565b6000806000606084860312156151f457600080fd5b8335925060208401359150604084013567ffffffffffffffff81111561521957600080fd5b8401601f8101861361522a57600080fd5b803561523d615238826151b7565b615186565b81815287602083850101111561525257600080fd5b816020840160208301376000602083830101528093505050509250925092565b60006020828403121561528457600080fd5b5035919050565b6000806040838503121561529e57600080fd5b50508035926020909101359150565b60008060008060008587036101008112156152c757600080fd5b86356152d281615097565b955060208701356152e281615097565b945060408701356152f281615097565b93506060870135615302816150c9565b92506080607f198201121561531657600080fd5b506080860190509295509295909350565b60005b8381101561534257818101518382015260200161532a565b50506000910152565b60008151808452615363816020860160208601615327565b601f01601f19169290920160200192915050565b60208152600082516060602084015280516080840152602081015160a0840152604081015160c0840152606081015160e0840152608081015160c06101008501526153c661014085018261534b565b905060a082015115156101208501526020850151604085015260408501516060850152809250505092915050565b634e487b7160e01b600052603260045260246000fd5b60006020828403121561541c57600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b8181038181111561354a5761354a615423565b805161ffff81168114614e8857600080fd5b80518015158114614e8857600080fd5b600080600080600080600060e0888a03121561548957600080fd5b875161549481615097565b60208901519097506154a5816150c9565b95506154b36040890161544c565b94506154c16060890161544c565b93506154cf6080890161544c565b925060a088015160ff811681146154e557600080fd5b91506154f360c0890161545e565b905092959891949750929550565b6020808252825182820181905260009190848201906040850190845b8181101561553f57835163ffffffff168352928401929184019160010161551d565b50909695505050505050565b600067ffffffffffffffff82111561556557615565615147565b5060051b60200190565b600082601f83011261558057600080fd5b815160206155906152388361554b565b8083825260208201915060208460051b8701019350868411156155b257600080fd5b602086015b848110156155d75780516155ca81615097565b83529183019183016155b7565b509695505050505050565b600080604083850312156155f557600080fd5b825167ffffffffffffffff8082111561560d57600080fd5b818501915085601f83011261562157600080fd5b815160206156316152388361554b565b82815260059290921b8401810191818101908984111561565057600080fd5b948201945b838610156156775785516156688161511b565b82529482019490820190615655565b9188015191965090935050508082111561569057600080fd5b5061569d8582860161556f565b9150509250929050565b600682810b9082900b03667fffffffffffff198112667fffffffffffff8213171561354a5761354a615423565b634e487b7160e01b600052601260045260246000fd5b60008160060b8360060b80615701576157016156d4565b667fffffffffffff1982146000198214161561571f5761571f615423565b90059392505050565b60609490941b6bffffffffffffffffffffffff19168452601484019290925260e890811b60348401521b6037820152603a0190565b60008260020b8260020b028060020b915080821461577d5761577d615423565b5092915050565b8082018082111561354a5761354a615423565b808202811582820484141761354a5761354a615423565b6000826157bd576157bd6156d4565b500490565b6000602082840312156157d457600080fd5b815161360c81615097565b6000602082840312156157f157600080fd5b815162ffffff8116811461360c57600080fd5b600681810b9083900b01667fffffffffffff8113667fffffffffffff198212171561354a5761354a615423565b600181815b8085111561586c57816000190482111561585257615852615423565b8085161561585f57918102915b93841c9390800290615836565b509250929050565b6000826158835750600161354a565b816158905750600061354a565b81600181146158a657600281146158b0576158cc565b600191505061354a565b60ff8411156158c1576158c1615423565b50506001821b61354a565b5060208310610133831016604e8410600b84101617156158ef575081810a61354a565b6158f98383615831565b806000190482111561590d5761590d615423565b029392505050565b600061354760ff841683615874565b60006020828403121561593657600080fd5b6135478261545e565b80516001600160801b0381168114614e8857600080fd5b600080600080600060a0868803121561596e57600080fd5b6159778661593f565b945060208601519350604086015192506159936060870161593f565b91506159a16080870161593f565b90509295509295909350565b600293840b81529190920b60208201526001600160801b03909116604082015260600190565b600080604083850312156159e657600080fd5b505080516020909101519092909150565b6001600160a01b03959095168552600293840b60208601529190920b60408401526001600160801b03918216606084015216608082015260a00190565b60008060408385031215615a4757600080fd5b615a508361593f565b9150615a5e6020840161593f565b90509250929050565b600060208284031215615a7957600080fd5b815161360c816150c9565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b60006020808385031215615ae257600080fd5b825167ffffffffffffffff80821115615afa57600080fd5b9084019060c08287031215615b0e57600080fd5b615b1661515d565b8251815283830151848201526040830151604082015260608301516060820152608083015182811115615b4857600080fd5b83019150601f82018713615b5b57600080fd5b8151615b69615238826151b7565b8181528886838601011115615b7d57600080fd5b615b8c82878301888701615327565b608083015250615b9e60a0840161545e565b60a08201529695505050505050565b600060c0820160018060a01b03808a16845260208960208601528860020b60408601528760020b606086015260c0608086015282875480855260e087019150886000526020600020945060005b81811015615c18578554851683526001958601959284019201615bfa565b50506001600160a01b03871660a08701529350614f5d92505050565b6000600160ff1b8201615c4957615c49615423565b5060000390565b60008160020b627fffff198103615c6957615c69615423565b60000392915050565b600082615c8157615c816156d4565b500690565b60008251615c98818460208701615327565b9190910192915050565b6001600160a01b0382811682821603908082111561577d5761577d615423565b600282810b9082900b03627fffff198112627fffff8213171561354a5761354a615423565b600281810b9083900b01627fffff8113627fffff198212171561354a5761354a615423565b60008160020b8360020b80615d2357615d236156d4565b627fffff1982146000198214161561571f5761571f615423565b60008260020b80615d5057615d506156d4565b808360020b0791505092915050565b60008160020b627fffff198103615d7857615d78615423565b6000190192915050565b602081526000613547602083018461534b56fea2646970667358221220ca77a92c0dca4ba3a01cd6e06090a1a242b4d8f7179c2df6b7573d091b51cdf864736f6c63430008170033

Block Transaction Gas Used Reward
view all blocks produced

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

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits

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