ETH Price: $2,398.33 (+3.25%)

Contract

0x1fd3f47B363f5b844eD7B7FAB6ceb679A367621E

Overview

ETH Balance

0 ETH

ETH Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
Set Rates102426492024-02-26 2:02:44200 days ago1708912964IN
QuickSwap: Infinite Farming
0 ETH0.000208583.7
Set Rates102426172024-02-26 2:01:10200 days ago1708912870IN
QuickSwap: Infinite Farming
0 ETH0.000216513.84
Set Rates102425342024-02-26 1:57:01200 days ago1708912621IN
QuickSwap: Infinite Farming
0 ETH0.000212733.97
Set Rates102425272024-02-26 1:56:42200 days ago1708912602IN
QuickSwap: Infinite Farming
0 ETH0.000195934.01
Set Rates102425222024-02-26 1:56:27200 days ago1708912587IN
QuickSwap: Infinite Farming
0 ETH0.000222723.95
Set Rates102424992024-02-26 1:55:18200 days ago1708912518IN
QuickSwap: Infinite Farming
0 ETH0.000226664.02
Add Rewards102424932024-02-26 1:55:00200 days ago1708912500IN
QuickSwap: Infinite Farming
0 ETH0.000337713.58
Set Rates102424902024-02-26 1:54:51200 days ago1708912491IN
QuickSwap: Infinite Farming
0 ETH0.00017943.72
Set Rates102424782024-02-26 1:54:12200 days ago1708912452IN
QuickSwap: Infinite Farming
0 ETH0.000127363.84
Set Rates102424672024-02-26 1:53:39200 days ago1708912419IN
QuickSwap: Infinite Farming
0 ETH0.000139634.21
Set Rates102424592024-02-26 1:53:15200 days ago1708912395IN
QuickSwap: Infinite Farming
0 ETH0.000134664.06
Set Rates102424492024-02-26 1:52:45200 days ago1708912365IN
QuickSwap: Infinite Farming
0 ETH0.00024644.37
Set Rates102424392024-02-26 1:52:15200 days ago1708912335IN
QuickSwap: Infinite Farming
0 ETH0.000233994.15
Set Rates102424172024-02-26 1:51:10200 days ago1708912270IN
QuickSwap: Infinite Farming
0 ETH0.000148534.48
Add Rewards102424092024-02-26 1:50:46200 days ago1708912246IN
QuickSwap: Infinite Farming
0 ETH0.00039624.2
Set Rates102424062024-02-26 1:50:37200 days ago1708912237IN
QuickSwap: Infinite Farming
0 ETH0.000190013.94
Add Rewards102423962024-02-26 1:50:07200 days ago1708912207IN
QuickSwap: Infinite Farming
0 ETH0.000373563.96
Set Rates102423902024-02-26 1:49:49200 days ago1708912189IN
QuickSwap: Infinite Farming
0 ETH0.000197734.1
Set Rates102423772024-02-26 1:49:10200 days ago1708912150IN
QuickSwap: Infinite Farming
0 ETH0.000138974.19
Add Rewards102423072024-02-26 1:45:40200 days ago1708911940IN
QuickSwap: Infinite Farming
0 ETH0.000389594.13
Set Rates102422922024-02-26 1:44:55200 days ago1708911895IN
QuickSwap: Infinite Farming
0 ETH0.000154363.2
Add Rewards100493632024-02-19 8:03:26207 days ago1708329806IN
QuickSwap: Infinite Farming
0 ETH0.000303893.68
Add Rewards100493592024-02-19 8:03:14207 days ago1708329794IN
QuickSwap: Infinite Farming
0 ETH0.000312973.79
Add Rewards100493552024-02-19 8:03:05207 days ago1708329785IN
QuickSwap: Infinite Farming
0 ETH0.000328663.98
Add Rewards100493512024-02-19 8:02:52207 days ago1708329772IN
QuickSwap: Infinite Farming
0 ETH0.000340174.12
View all transactions

Latest 13 internal transactions

Parent Transaction Hash Block From To
99570742024-02-16 2:50:33210 days ago1708051833
QuickSwap: Infinite Farming
 Contract Creation0 ETH
5796332023-06-01 12:24:50470 days ago1685622290
QuickSwap: Infinite Farming
 Contract Creation0 ETH
5796222023-06-01 12:24:50470 days ago1685622290
QuickSwap: Infinite Farming
 Contract Creation0 ETH
5796122023-06-01 12:24:50470 days ago1685622290
QuickSwap: Infinite Farming
 Contract Creation0 ETH
5795902023-06-01 12:23:02470 days ago1685622182
QuickSwap: Infinite Farming
 Contract Creation0 ETH
4323512023-05-26 9:44:06476 days ago1685094246
QuickSwap: Infinite Farming
 Contract Creation0 ETH
2615612023-05-16 6:34:00486 days ago1684218840
QuickSwap: Infinite Farming
 Contract Creation0 ETH
2615342023-05-16 6:30:04486 days ago1684218604
QuickSwap: Infinite Farming
 Contract Creation0 ETH
1790722023-04-27 13:12:31505 days ago1682601151
QuickSwap: Infinite Farming
 Contract Creation0 ETH
1790692023-04-27 13:12:31505 days ago1682601151
QuickSwap: Infinite Farming
 Contract Creation0 ETH
1402742023-04-17 7:40:56515 days ago1681717256
QuickSwap: Infinite Farming
 Contract Creation0 ETH
224302023-03-30 13:10:11533 days ago1680181811
QuickSwap: Infinite Farming
 Contract Creation0 ETH
164182023-03-29 11:35:31534 days ago1680089731
QuickSwap: Infinite Farming
 Contract Creation0 ETH
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
AlgebraEternalFarming

Compiler Version
v0.7.6+commit.7338295f

Optimization Enabled:
Yes with 99999999 runs

Other Settings:
default evmVersion, None license
File 1 of 83 : AlgebraEternalFarming.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.7.6;
pragma abicoder v2;

import './interfaces/IAlgebraEternalFarming.sol';
import './interfaces/IAlgebraEternalVirtualPool.sol';
import '../../libraries/IncentiveId.sol';
import './EternalVirtualPool.sol';

import 'algebra/contracts/libraries/SafeCast.sol';

import 'algebra/contracts/libraries/FullMath.sol';
import 'algebra/contracts/libraries/Constants.sol';

import '../AlgebraFarming.sol';

/// @title Algebra eternal (v2-like) farming
contract AlgebraEternalFarming is AlgebraFarming, IAlgebraEternalFarming {
    using SafeCast for int256;
    /// @notice Represents the farm for nft
    struct Farm {
        uint128 liquidity;
        int24 tickLower;
        int24 tickUpper;
        uint256 innerRewardGrowth0;
        uint256 innerRewardGrowth1;
    }
    /// @dev farms[tokenId][incentiveHash] => Farm
    /// @inheritdoc IAlgebraEternalFarming
    mapping(uint256 => mapping(bytes32 => Farm)) public override farms;

    /// @param _deployer pool deployer contract address
    /// @param _nonfungiblePositionManager the NFT position manager contract address
    constructor(IAlgebraPoolDeployer _deployer, INonfungiblePositionManager _nonfungiblePositionManager)
        AlgebraFarming(_deployer, _nonfungiblePositionManager)
    {
        // just initialize AlgebraFarming
    }

    /// @inheritdoc IAlgebraEternalFarming
    function createEternalFarming(
        IncentiveKey memory key,
        IncentiveParams memory params,
        Tiers calldata tiers
    ) external override onlyIncentiveMaker returns (address virtualPool) {
        (, address _incentive) = _getCurrentVirtualPools(key.pool);
        require(_incentive == address(0), 'Farming already exists');

        virtualPool = address(new EternalVirtualPool(address(farmingCenter), address(this), address(key.pool)));
        bytes32 incentiveId;
        (incentiveId, params.reward, params.bonusReward) = _createFarming(
            virtualPool,
            key,
            params.reward,
            params.bonusReward,
            params.minimalPositionWidth,
            params.multiplierToken,
            tiers
        );

        emit EternalFarmingCreated(
            key.rewardToken,
            key.bonusRewardToken,
            key.pool,
            virtualPool,
            key.startTime,
            key.endTime,
            params.reward,
            params.bonusReward,
            tiers,
            params.multiplierToken,
            params.minimalPositionWidth
        );

        IAlgebraEternalVirtualPool(virtualPool).addRewards(params.reward, params.bonusReward);
        IAlgebraEternalVirtualPool(virtualPool).setRates(params.rewardRate, params.bonusRewardRate);

        emit RewardsAdded(params.reward, params.bonusReward, incentiveId);
        emit RewardsRatesChanged(params.rewardRate, params.bonusRewardRate, incentiveId);
    }

    /// @inheritdoc IAlgebraFarming
    function detachIncentive(IncentiveKey memory key) external override onlyIncentiveMaker {
        (, address _eternalVirtualPool) = _getCurrentVirtualPools(key.pool);
        _detachIncentive(key, _eternalVirtualPool);
    }

    /// @inheritdoc IAlgebraFarming
    function attachIncentive(IncentiveKey memory key) external override onlyIncentiveMaker {
        (, address _eternalVirtualPool) = _getCurrentVirtualPools(key.pool);
        _attachIncentive(key, _eternalVirtualPool);
    }

    /// @inheritdoc IAlgebraEternalFarming
    function addRewards(
        IncentiveKey memory key,
        uint256 rewardAmount,
        uint256 bonusRewardAmount
    ) external override {
        bytes32 incentiveId = IncentiveId.compute(key);
        Incentive storage incentive = incentives[incentiveId];
        require(incentive.totalReward > 0, 'non-existent incentive');

        (rewardAmount, bonusRewardAmount) = _receiveRewards(key, rewardAmount, bonusRewardAmount, incentive);

        if (rewardAmount | bonusRewardAmount > 0) {
            IAlgebraEternalVirtualPool virtualPool = IAlgebraEternalVirtualPool(incentive.virtualPoolAddress);
            virtualPool.addRewards(rewardAmount, bonusRewardAmount);

            emit RewardsAdded(rewardAmount, bonusRewardAmount, incentiveId);
        }
    }

    /// @inheritdoc IAlgebraEternalFarming
    function setRates(
        IncentiveKey memory key,
        uint128 rewardRate,
        uint128 bonusRewardRate
    ) external override onlyIncentiveMaker {
        bytes32 incentiveId = IncentiveId.compute(key);
        IAlgebraEternalVirtualPool virtualPool = IAlgebraEternalVirtualPool(incentives[incentiveId].virtualPoolAddress);
        virtualPool.setRates(rewardRate, bonusRewardRate);

        emit RewardsRatesChanged(rewardRate, bonusRewardRate, incentiveId);
    }

    /// @inheritdoc IAlgebraFarming
    function enterFarming(
        IncentiveKey memory key,
        uint256 tokenId,
        uint256 tokensLocked
    ) external override onlyFarmingCenter {
        (
            bytes32 incentiveId,
            int24 tickLower,
            int24 tickUpper,
            uint128 liquidity,
            address virtualPoolAddress
        ) = _enterFarming(key, tokenId, tokensLocked);

        mapping(bytes32 => Farm) storage farmsForToken = farms[tokenId];
        require(farmsForToken[incentiveId].liquidity == 0, 'token already farmed');

        (uint256 innerRewardGrowth0, uint256 innerRewardGrowth1) = IAlgebraEternalVirtualPool(virtualPoolAddress)
            .getInnerRewardsGrowth(tickLower, tickUpper);

        farmsForToken[incentiveId] = Farm({
            liquidity: liquidity,
            tickLower: tickLower,
            tickUpper: tickUpper,
            innerRewardGrowth0: innerRewardGrowth0,
            innerRewardGrowth1: innerRewardGrowth1
        });

        emit FarmEntered(tokenId, incentiveId, liquidity, tokensLocked);
    }

    /// @inheritdoc IAlgebraFarming
    function exitFarming(
        IncentiveKey memory key,
        uint256 tokenId,
        address _owner
    ) external override onlyFarmingCenter {
        bytes32 incentiveId = IncentiveId.compute(key);

        Farm memory farm = farms[tokenId][incentiveId];
        require(farm.liquidity != 0, 'farm does not exist');

        Incentive storage incentive = incentives[incentiveId];
        IAlgebraEternalVirtualPool virtualPool = IAlgebraEternalVirtualPool(incentive.virtualPoolAddress);

        uint256 reward;
        uint256 bonusReward;

        {
            (, int24 tick, , , , , ) = key.pool.globalState();

            // update rewards, as ticks may be cleared when liquidity decreases
            virtualPool.applyLiquidityDeltaToPosition(uint32(block.timestamp), farm.tickLower, farm.tickUpper, 0, tick);

            (uint256 innerRewardGrowth0, uint256 innerRewardGrowth1) = virtualPool.getInnerRewardsGrowth(
                farm.tickLower,
                farm.tickUpper
            );

            virtualPool.applyLiquidityDeltaToPosition(
                uint32(block.timestamp),
                farm.tickLower,
                farm.tickUpper,
                -int256(farm.liquidity).toInt128(),
                tick
            );

            (reward, bonusReward) = (
                FullMath.mulDiv(innerRewardGrowth0 - farm.innerRewardGrowth0, farm.liquidity, Constants.Q128),
                FullMath.mulDiv(innerRewardGrowth1 - farm.innerRewardGrowth1, farm.liquidity, Constants.Q128)
            );
        }

        mapping(IERC20Minimal => uint256) storage rewardBalances = rewards[_owner];
        if (reward != 0) {
            rewardBalances[key.rewardToken] += reward; // user must claim before overflow
        }
        if (bonusReward != 0) {
            rewardBalances[key.bonusRewardToken] += bonusReward; // user must claim before overflow
        }

        delete farms[tokenId][incentiveId];

        emit FarmEnded(
            tokenId,
            incentiveId,
            address(key.rewardToken),
            address(key.bonusRewardToken),
            _owner,
            reward,
            bonusReward
        );
    }

    /// @notice reward amounts can be outdated, actual amounts could be obtained via static call of `collectRewards` in FarmingCenter
    /// @inheritdoc IAlgebraFarming
    function getRewardInfo(IncentiveKey memory key, uint256 tokenId)
        external
        view
        override
        returns (uint256 reward, uint256 bonusReward)
    {
        bytes32 incentiveId = IncentiveId.compute(key);

        Farm memory farm = farms[tokenId][incentiveId];
        require(farm.liquidity > 0, 'farm does not exist');

        IAlgebraEternalVirtualPool virtualPool = IAlgebraEternalVirtualPool(incentives[incentiveId].virtualPoolAddress);

        (uint256 innerRewardGrowth0, uint256 innerRewardGrowth1) = virtualPool.getInnerRewardsGrowth(
            farm.tickLower,
            farm.tickUpper
        );

        (reward, bonusReward) = (
            FullMath.mulDiv(innerRewardGrowth0 - farm.innerRewardGrowth0, farm.liquidity, Constants.Q128),
            FullMath.mulDiv(innerRewardGrowth1 - farm.innerRewardGrowth1, farm.liquidity, Constants.Q128)
        );
    }

    /// @notice reward amounts should be updated before calling this method
    /// @inheritdoc IAlgebraEternalFarming
    function collectRewards(
        IncentiveKey memory key,
        uint256 tokenId,
        address _owner
    ) external override onlyFarmingCenter returns (uint256 reward, uint256 bonusReward) {
        bytes32 incentiveId = IncentiveId.compute(key);
        Incentive storage incentive = incentives[incentiveId];
        require(incentive.totalReward > 0, 'non-existent incentive');

        IAlgebraEternalVirtualPool virtualPool = IAlgebraEternalVirtualPool(incentive.virtualPoolAddress);

        Farm memory farm = farms[tokenId][incentiveId];
        require(farm.liquidity != 0, 'farm does not exist');

        (uint256 innerRewardGrowth0, uint256 innerRewardGrowth1) = virtualPool.getInnerRewardsGrowth(
            farm.tickLower,
            farm.tickUpper
        );

        (reward, bonusReward) = (
            FullMath.mulDiv(innerRewardGrowth0 - farm.innerRewardGrowth0, farm.liquidity, Constants.Q128),
            FullMath.mulDiv(innerRewardGrowth1 - farm.innerRewardGrowth1, farm.liquidity, Constants.Q128)
        );

        farms[tokenId][incentiveId].innerRewardGrowth0 = innerRewardGrowth0;
        farms[tokenId][incentiveId].innerRewardGrowth1 = innerRewardGrowth1;

        mapping(IERC20Minimal => uint256) storage rewardBalances = rewards[_owner];
        if (reward != 0) {
            rewardBalances[key.rewardToken] += reward; // user must claim before overflow
        }
        if (bonusReward != 0) {
            rewardBalances[key.bonusRewardToken] += bonusReward; // user must claim before overflow
        }

        emit RewardsCollected(tokenId, incentiveId, reward, bonusReward);
    }
}

File 2 of 83 : AlgebraTokenStaking.sol
// SPDX-License-Identifier: MIT

pragma solidity =0.7.6;

import './base/FreezableToken.sol';

// This contract handles swapping to and from xALGB, Algebra's staking token.
contract AlgebraTokenStaking is FreezableToken {
    using SafeMath for uint256;

    uint256 public freezeTime = 1800;
    address public owner;
    IERC20Minimal public ALGB;

    event Entered(address staker, uint256 ALGBAmount, uint256 xALGBAmount);
    event Left(address staker, uint256 xALGBAmount, uint256 ALGBAmount);

    modifier onlyOwner() {
        require(msg.sender == owner, 'only owner can call this');
        _;
    }

    // Define the ALGB token contract
    constructor(IERC20Minimal _ALGB) ERC20('Algebra Staking Token', 'xALGB') {
        ALGB = _ALGB;
        owner = msg.sender;
    }

    function _beforeTokenTransfer(
        address from,
        address to,
        uint256 amount
    ) internal override {
        to;
        amount; // not used
        (uint64 release, uint256 balance) = getFreezing(from, 0);
        if (release < block.timestamp && balance > 0) {
            releaseAll(from);
        }
    }

    // Enter the bar. Pay some ALGBSs. Earn some shares.
    // Locks ALGB and mints xALGB
    function enter(uint256 _amount) external {
        // Gets the amount of ALGB locked in the contract
        uint256 totalALGB = ALGB.balanceOf(address(this));
        // Gets the amount of xALGB in existence
        uint256 totalShares = totalSupply();
        uint256 what;
        // If no xALGB exists, mint it 1:1 to the amount put in
        if (totalShares == 0 || totalALGB == 0) {
            what = _amount;
            mintAndFreeze(msg.sender, _amount, uint64(block.timestamp + freezeTime));
        }
        // Calculate and mint the amount of xALGB the ALGB is worth. The ratio will change overtime, as xALGB is burned/minted and ALGB deposited + gained from fees / withdrawn.
        else {
            what = _amount.mul(totalShares).div(totalALGB);
            mintAndFreeze(msg.sender, what, uint64(block.timestamp + freezeTime));
        }
        // Lock the ALGB in the contract
        ALGB.transferFrom(msg.sender, address(this), _amount);
        emit Entered(msg.sender, _amount, what);
    }

    // Leave the bar. Claim back your ALGBs.
    // Unlocks the staked + gained ALGB and burns xALGB
    function leave(uint256 _share) external {
        // Gets the amount of xALGB in existence
        uint256 totalShares = totalSupply();
        // Calculates the amount of ALGB the xALGB is worth
        uint256 what = _share.mul(ALGB.balanceOf(address(this))).div(totalShares);
        _burn(msg.sender, _share);
        ALGB.transfer(msg.sender, what);
        emit Left(msg.sender, _share, what);
    }

    function currentBalance(uint256 _amount) external view returns (uint256) {
        uint256 totalShares = totalSupply();
        return _amount.mul(ALGB.balanceOf(address(this))).div(totalShares);
    }

    function setFreezeTime(uint256 _freezeTime) external onlyOwner {
        require(_freezeTime <= 3600, 'freezeTime is to big');
        freezeTime = _freezeTime;
    }

    function transferOwner(address _newOwner) external onlyOwner {
        require(_newOwner != address(0), 'cannot be 0 address');
        owner = _newOwner;
    }
}

File 3 of 83 : FreezableToken.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.7.6;

import '../base/ERC20.sol';

abstract contract FreezableToken is ERC20 {
    using SafeMath for uint256;
    // freezing chains
    mapping(bytes32 => uint64) internal chains;
    // freezing amounts for each chain
    mapping(bytes32 => uint256) internal freezings;
    // total freezing balance per address
    mapping(address => uint256) internal freezingBalance;

    event Freezed(address indexed to, uint64 release, uint256 amount);
    event Released(address indexed owner, uint256 amount);

    /**
     * @dev Gets the balance of the specified address include freezing tokens.
     * @param _owner The address to query the the balance of.
     * @return balance An uint256 representing the amount owned by the passed address.
     */
    function balanceOf(address _owner) public view override returns (uint256 balance) {
        return super.balanceOf(_owner) + freezingBalance[_owner];
    }

    /**
     * @dev Gets the balance of the specified address without freezing tokens.
     * @param _owner The address to query the the balance of.
     * @return balance n uint256 representing the amount owned by the passed address.
     */
    function actualBalanceOf(address _owner) public view returns (uint256 balance) {
        return super.balanceOf(_owner);
    }

    function freezingBalanceOf(address _owner) public view returns (uint256 balance) {
        return freezingBalance[_owner];
    }

    /**
     * @dev gets freezing end date and freezing balance for the freezing portion specified by index.
     * @param _addr Address of freeze tokens owner.
     * @param _index Freezing portion index. It ordered by release date descending.
     */
    function getFreezing(address _addr, uint256 _index) internal view returns (uint64 _release, uint256 _balance) {
        for (uint256 i = 0; i < _index + 1; i++) {
            _release = chains[toKey(_addr, _release)];
            if (_release == 0) {
                return (0, 0);
            }
        }
        _balance = freezings[toKey(_addr, _release)];
    }

    /**
     * @dev release first available freezing tokens.
     */
    function releaseOnce(address account) internal {
        bytes32 headKey = toKey(account, 0);
        uint64 head = chains[headKey];
        require(head != 0);
        require(uint64(block.timestamp) > head);
        bytes32 currentKey = toKey(account, head);

        uint64 next = chains[currentKey];

        uint256 amount = freezings[currentKey];
        delete freezings[currentKey];

        _balances[account] = _balances[account].add(amount);
        freezingBalance[account] = freezingBalance[account].sub(amount);

        if (next == 0) {
            delete chains[headKey];
        } else {
            chains[headKey] = next;
            delete chains[currentKey];
        }
        emit Released(account, amount);
    }

    /**
     * @dev release all available for release freezing tokens. Gas usage is not deterministic!
     * @return tokens how many tokens was released
     */
    function releaseAll(address account) internal returns (uint256 tokens) {
        uint256 release;
        uint256 balance;
        (release, balance) = getFreezing(account, 0);
        while (release != 0 && block.timestamp > release) {
            releaseOnce(account);
            tokens += balance;
            (release, balance) = getFreezing(account, 0);
        }
    }

    function toKey(address _addr, uint256 _release) internal pure returns (bytes32 result) {
        // increase entropy
        result = 0x5749534800000000000000000000000000000000000000000000000000000000;
        assembly {
            result := or(result, mul(_addr, 0x10000000000000000))
            result := or(result, and(_release, 0xffffffffffffffff))
        }
    }

    function freeze(address _to, uint64 _until) internal {
        require(_until > block.timestamp);
        bytes32 key = toKey(_to, _until);
        bytes32 parentKey = toKey(_to, uint64(0));
        uint64 next = chains[parentKey];

        if (next == 0) {
            chains[parentKey] = _until;
            return;
        }

        bytes32 nextKey = toKey(_to, next);
        uint256 parent;

        while (next != 0 && _until > next) {
            parent = next;
            parentKey = nextKey;

            next = chains[nextKey];
            nextKey = toKey(_to, next);
        }

        if (_until == next) {
            return;
        }

        if (next != 0) {
            chains[key] = next;
        }

        chains[parentKey] = _until;
    }

    /**
     * @dev Mint the specified amount of token to the specified address and freeze it until the specified date.
     *      Be careful, gas usage is not deterministic,
     *      and depends on how many freezes _to address already has.
     * @param _to Address to which token will be freeze.
     * @param _amount Amount of token to mint and freeze.
     * @param _until Release date, must be in future.
     * @return A boolean that indicates if the operation was successful.
     */
    function mintAndFreeze(
        address _to,
        uint256 _amount,
        uint64 _until
    ) internal returns (bool) {
        _totalSupply = _totalSupply.add(_amount);

        bytes32 currentKey = toKey(_to, _until);
        freezings[currentKey] = freezings[currentKey].add(_amount);
        freezingBalance[_to] = freezingBalance[_to].add(_amount);

        freeze(_to, _until);
        emit Freezed(_to, _until, _amount);
        emit Transfer(address(0), _to, _amount);
        return true;
    }
}

File 4 of 83 : ERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.7.0;

import 'algebra/contracts/interfaces/IERC20Minimal.sol';
import '@openzeppelin/contracts/math/SafeMath.sol';

contract ERC20 is IERC20Minimal {
    using SafeMath for uint256;

    mapping(address => uint256) internal _balances;

    mapping(address => mapping(address => uint256)) private _allowances;

    uint256 internal _totalSupply;

    string private _name;
    string private _symbol;
    uint8 private _decimals;

    /**
     * @dev Sets the values for {name} and {symbol}, initializes {decimals} with
     * a default value of 18.
     *
     * To select a different value for {decimals}, use {_setupDecimals}.
     *
     * All three of these values are immutable: they can only be set once during
     * construction.
     */
    constructor(string memory name_, string memory symbol_) {
        _name = name_;
        _symbol = symbol_;
        _decimals = 18;
    }

    /**
     * @dev Returns the name of the token.
     */
    function name() public view virtual returns (string memory) {
        return _name;
    }

    /**
     * @dev Returns the symbol of the token, usually a shorter version of the
     * name.
     */
    function symbol() public view virtual returns (string memory) {
        return _symbol;
    }

    /**
     * @dev Returns the number of decimals used to get its user representation.
     * For example, if `decimals` equals `2`, a balance of `505` tokens should
     * be displayed to a user as `5,05` (`505 / 10 ** 2`).
     *
     * Tokens usually opt for a value of 18, imitating the relationship between
     * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
     * called.
     *
     * NOTE: This information is only used for _display_ purposes: it in
     * no way affects any of the arithmetic of the contract, including
     * {IERC20-balanceOf} and {IERC20-transfer}.
     */
    function decimals() public view virtual returns (uint8) {
        return _decimals;
    }

    /**
     * @dev See {IERC20-totalSupply}.
     */
    function totalSupply() public view virtual returns (uint256) {
        return _totalSupply;
    }

    /**
     * @dev See {IERC20-balanceOf}.
     */
    function balanceOf(address account) public view virtual override returns (uint256) {
        return _balances[account];
    }

    /**
     * @dev See {IERC20-transfer}.
     *
     * Requirements:
     *
     * - `recipient` cannot be the zero address.
     * - the caller must have a balance of at least `amount`.
     */
    function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
        _transfer(msg.sender, recipient, amount);
        return true;
    }

    /**
     * @dev See {IERC20-allowance}.
     */
    function allowance(address owner, address spender) public view virtual override returns (uint256) {
        return _allowances[owner][spender];
    }

    /**
     * @dev See {IERC20-approve}.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function approve(address spender, uint256 amount) public virtual override returns (bool) {
        _approve(msg.sender, spender, amount);
        return true;
    }

    /**
     * @dev See {IERC20-transferFrom}.
     *
     * Emits an {Approval} event indicating the updated allowance. This is not
     * required by the EIP. See the note at the beginning of {ERC20}.
     *
     * Requirements:
     *
     * - `sender` and `recipient` cannot be the zero address.
     * - `sender` must have a balance of at least `amount`.
     * - the caller must have allowance for ``sender``'s tokens of at least
     * `amount`.
     */
    function transferFrom(
        address sender,
        address recipient,
        uint256 amount
    ) public virtual override returns (bool) {
        _transfer(sender, recipient, amount);
        _approve(
            sender,
            msg.sender,
            _allowances[sender][msg.sender].sub(amount, 'ERC20: transfer amount exceeds allowance')
        );
        return true;
    }

    /**
     * @dev Atomically increases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
        _approve(msg.sender, spender, _allowances[msg.sender][spender].add(addedValue));
        return true;
    }

    /**
     * @dev Atomically decreases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `spender` must have allowance for the caller of at least
     * `subtractedValue`.
     */
    function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
        _approve(
            msg.sender,
            spender,
            _allowances[msg.sender][spender].sub(subtractedValue, 'ERC20: decreased allowance below zero')
        );
        return true;
    }

    /**
     * @dev Moves tokens `amount` from `sender` to `recipient`.
     *
     * This is internal function is equivalent to {transfer}, and can be used to
     * e.g. implement automatic token fees, slashing mechanisms, etc.
     *
     * Emits a {Transfer} event.
     *
     * Requirements:
     *
     * - `sender` cannot be the zero address.
     * - `recipient` cannot be the zero address.
     * - `sender` must have a balance of at least `amount`.
     */
    function _transfer(
        address sender,
        address recipient,
        uint256 amount
    ) internal virtual {
        require(sender != address(0), 'ERC20: transfer from the zero address');
        require(recipient != address(0), 'ERC20: transfer to the zero address');

        _beforeTokenTransfer(sender, recipient, amount);

        _balances[sender] = _balances[sender].sub(amount, 'ERC20: transfer amount exceeds balance');
        _balances[recipient] = _balances[recipient].add(amount);
        emit Transfer(sender, recipient, amount);
    }

    /** @dev Creates `amount` tokens and assigns them to `account`, increasing
     * the total supply.
     *
     * Emits a {Transfer} event with `from` set to the zero address.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     */
    function _mint(address account, uint256 amount) internal virtual {
        require(account != address(0), 'ERC20: mint to the zero address');

        _beforeTokenTransfer(address(0), account, amount);

        _totalSupply = _totalSupply.add(amount);
        _balances[account] = _balances[account].add(amount);
        emit Transfer(address(0), account, amount);
    }

    /**
     * @dev Destroys `amount` tokens from `account`, reducing the
     * total supply.
     *
     * Emits a {Transfer} event with `to` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     * - `account` must have at least `amount` tokens.
     */
    function _burn(address account, uint256 amount) internal virtual {
        require(account != address(0), 'ERC20: burn from the zero address');

        _beforeTokenTransfer(account, address(0), amount);

        _balances[account] = _balances[account].sub(amount, 'ERC20: burn amount exceeds balance');
        _totalSupply = _totalSupply.sub(amount);
        emit Transfer(account, address(0), amount);
    }

    /**
     * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
     *
     * This internal function is equivalent to `approve`, and can be used to
     * e.g. set automatic allowances for certain subsystems, etc.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `owner` cannot be the zero address.
     * - `spender` cannot be the zero address.
     */
    function _approve(
        address owner,
        address spender,
        uint256 amount
    ) internal virtual {
        require(owner != address(0), 'ERC20: approve from the zero address');
        require(spender != address(0), 'ERC20: approve to the zero address');

        _allowances[owner][spender] = amount;
        emit Approval(owner, spender, amount);
    }

    /**
     * @dev Sets {decimals} to a value other than the default one of 18.
     *
     * WARNING: This function should only be called from the constructor. Most
     * applications that interact with token contracts will not expect
     * {decimals} to ever change, and may work incorrectly if it does.
     */
    function _setupDecimals(uint8 decimals_) internal virtual {
        _decimals = decimals_;
    }

    /**
     * @dev Hook that is called before any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * will be to transferred to `to`.
     * - when `from` is zero, `amount` tokens will be minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens will be burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _beforeTokenTransfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual {}
}

File 5 of 83 : IERC20Minimal.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Minimal ERC20 interface for Algebra
/// @notice Contains a subset of the full ERC20 interface that is used in Algebra
/// @dev Credit to Uniswap Labs under GPL-2.0-or-later license:
/// https://github.com/Uniswap/v3-core/tree/main/contracts/interfaces
interface IERC20Minimal {
  /// @notice Returns the balance of a token
  /// @param account The account for which to look up the number of tokens it has, i.e. its balance
  /// @return The number of tokens held by the account
  function balanceOf(address account) external view returns (uint256);

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

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

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

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

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

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

File 6 of 83 : SafeMath.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.7.0;

/**
 * @dev Wrappers over Solidity's arithmetic operations with added overflow
 * checks.
 *
 * Arithmetic operations in Solidity wrap on overflow. This can easily result
 * in bugs, because programmers usually assume that an overflow raises an
 * error, which is the standard behavior in high level programming languages.
 * `SafeMath` restores this intuition by reverting the transaction when an
 * operation overflows.
 *
 * Using this library instead of the unchecked operations eliminates an entire
 * class of bugs, so it's recommended to use it always.
 */
library SafeMath {
    /**
     * @dev Returns the addition of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        uint256 c = a + b;
        if (c < a) return (false, 0);
        return (true, c);
    }

    /**
     * @dev Returns the substraction of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        if (b > a) return (false, 0);
        return (true, a - b);
    }

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

    /**
     * @dev Returns the division of two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        if (b == 0) return (false, 0);
        return (true, a / b);
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        if (b == 0) return (false, 0);
        return (true, a % b);
    }

    /**
     * @dev Returns the addition of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `+` operator.
     *
     * Requirements:
     *
     * - Addition cannot overflow.
     */
    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        uint256 c = a + b;
        require(c >= a, "SafeMath: addition overflow");
        return c;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting on
     * overflow (when the result is negative).
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b) internal pure returns (uint256) {
        require(b <= a, "SafeMath: subtraction overflow");
        return a - b;
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `*` operator.
     *
     * Requirements:
     *
     * - Multiplication cannot overflow.
     */
    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        if (a == 0) return 0;
        uint256 c = a * b;
        require(c / a == b, "SafeMath: multiplication overflow");
        return c;
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b) internal pure returns (uint256) {
        require(b > 0, "SafeMath: division by zero");
        return a / b;
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting when dividing by zero.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b) internal pure returns (uint256) {
        require(b > 0, "SafeMath: modulo by zero");
        return a % b;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
     * overflow (when the result is negative).
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {trySub}.
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        require(b <= a, errorMessage);
        return a - b;
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting with custom message on
     * division by zero. The result is rounded towards zero.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryDiv}.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        require(b > 0, errorMessage);
        return a / b;
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting with custom message when dividing by zero.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryMod}.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        require(b > 0, errorMessage);
        return a % b;
    }
}

File 7 of 83 : ERC721.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.7.0;

import "../../utils/Context.sol";
import "./IERC721.sol";
import "./IERC721Metadata.sol";
import "./IERC721Enumerable.sol";
import "./IERC721Receiver.sol";
import "../../introspection/ERC165.sol";
import "../../math/SafeMath.sol";
import "../../utils/Address.sol";
import "../../utils/EnumerableSet.sol";
import "../../utils/EnumerableMap.sol";
import "../../utils/Strings.sol";

/**
 * @title ERC721 Non-Fungible Token Standard basic implementation
 * @dev see https://eips.ethereum.org/EIPS/eip-721
 */
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Enumerable {
    using SafeMath for uint256;
    using Address for address;
    using EnumerableSet for EnumerableSet.UintSet;
    using EnumerableMap for EnumerableMap.UintToAddressMap;
    using Strings for uint256;

    // Equals to `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`
    // which can be also obtained as `IERC721Receiver(0).onERC721Received.selector`
    bytes4 private constant _ERC721_RECEIVED = 0x150b7a02;

    // Mapping from holder address to their (enumerable) set of owned tokens
    mapping (address => EnumerableSet.UintSet) private _holderTokens;

    // Enumerable mapping from token ids to their owners
    EnumerableMap.UintToAddressMap private _tokenOwners;

    // Mapping from token ID to approved address
    mapping (uint256 => address) private _tokenApprovals;

    // Mapping from owner to operator approvals
    mapping (address => mapping (address => bool)) private _operatorApprovals;

    // Token name
    string private _name;

    // Token symbol
    string private _symbol;

    // Optional mapping for token URIs
    mapping (uint256 => string) private _tokenURIs;

    // Base URI
    string private _baseURI;

    /*
     *     bytes4(keccak256('balanceOf(address)')) == 0x70a08231
     *     bytes4(keccak256('ownerOf(uint256)')) == 0x6352211e
     *     bytes4(keccak256('approve(address,uint256)')) == 0x095ea7b3
     *     bytes4(keccak256('getApproved(uint256)')) == 0x081812fc
     *     bytes4(keccak256('setApprovalForAll(address,bool)')) == 0xa22cb465
     *     bytes4(keccak256('isApprovedForAll(address,address)')) == 0xe985e9c5
     *     bytes4(keccak256('transferFrom(address,address,uint256)')) == 0x23b872dd
     *     bytes4(keccak256('safeTransferFrom(address,address,uint256)')) == 0x42842e0e
     *     bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) == 0xb88d4fde
     *
     *     => 0x70a08231 ^ 0x6352211e ^ 0x095ea7b3 ^ 0x081812fc ^
     *        0xa22cb465 ^ 0xe985e9c5 ^ 0x23b872dd ^ 0x42842e0e ^ 0xb88d4fde == 0x80ac58cd
     */
    bytes4 private constant _INTERFACE_ID_ERC721 = 0x80ac58cd;

    /*
     *     bytes4(keccak256('name()')) == 0x06fdde03
     *     bytes4(keccak256('symbol()')) == 0x95d89b41
     *     bytes4(keccak256('tokenURI(uint256)')) == 0xc87b56dd
     *
     *     => 0x06fdde03 ^ 0x95d89b41 ^ 0xc87b56dd == 0x5b5e139f
     */
    bytes4 private constant _INTERFACE_ID_ERC721_METADATA = 0x5b5e139f;

    /*
     *     bytes4(keccak256('totalSupply()')) == 0x18160ddd
     *     bytes4(keccak256('tokenOfOwnerByIndex(address,uint256)')) == 0x2f745c59
     *     bytes4(keccak256('tokenByIndex(uint256)')) == 0x4f6ccce7
     *
     *     => 0x18160ddd ^ 0x2f745c59 ^ 0x4f6ccce7 == 0x780e9d63
     */
    bytes4 private constant _INTERFACE_ID_ERC721_ENUMERABLE = 0x780e9d63;

    /**
     * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
     */
    constructor (string memory name_, string memory symbol_) {
        _name = name_;
        _symbol = symbol_;

        // register the supported interfaces to conform to ERC721 via ERC165
        _registerInterface(_INTERFACE_ID_ERC721);
        _registerInterface(_INTERFACE_ID_ERC721_METADATA);
        _registerInterface(_INTERFACE_ID_ERC721_ENUMERABLE);
    }

    /**
     * @dev See {IERC721-balanceOf}.
     */
    function balanceOf(address owner) public view virtual override returns (uint256) {
        require(owner != address(0), "ERC721: balance query for the zero address");
        return _holderTokens[owner].length();
    }

    /**
     * @dev See {IERC721-ownerOf}.
     */
    function ownerOf(uint256 tokenId) public view virtual override returns (address) {
        return _tokenOwners.get(tokenId, "ERC721: owner query for nonexistent token");
    }

    /**
     * @dev See {IERC721Metadata-name}.
     */
    function name() public view virtual override returns (string memory) {
        return _name;
    }

    /**
     * @dev See {IERC721Metadata-symbol}.
     */
    function symbol() public view virtual override returns (string memory) {
        return _symbol;
    }

    /**
     * @dev See {IERC721Metadata-tokenURI}.
     */
    function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
        require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");

        string memory _tokenURI = _tokenURIs[tokenId];
        string memory base = baseURI();

        // If there is no base URI, return the token URI.
        if (bytes(base).length == 0) {
            return _tokenURI;
        }
        // If both are set, concatenate the baseURI and tokenURI (via abi.encodePacked).
        if (bytes(_tokenURI).length > 0) {
            return string(abi.encodePacked(base, _tokenURI));
        }
        // If there is a baseURI but no tokenURI, concatenate the tokenID to the baseURI.
        return string(abi.encodePacked(base, tokenId.toString()));
    }

    /**
    * @dev Returns the base URI set via {_setBaseURI}. This will be
    * automatically added as a prefix in {tokenURI} to each token's URI, or
    * to the token ID if no specific URI is set for that token ID.
    */
    function baseURI() public view virtual returns (string memory) {
        return _baseURI;
    }

    /**
     * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}.
     */
    function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) {
        return _holderTokens[owner].at(index);
    }

    /**
     * @dev See {IERC721Enumerable-totalSupply}.
     */
    function totalSupply() public view virtual override returns (uint256) {
        // _tokenOwners are indexed by tokenIds, so .length() returns the number of tokenIds
        return _tokenOwners.length();
    }

    /**
     * @dev See {IERC721Enumerable-tokenByIndex}.
     */
    function tokenByIndex(uint256 index) public view virtual override returns (uint256) {
        (uint256 tokenId, ) = _tokenOwners.at(index);
        return tokenId;
    }

    /**
     * @dev See {IERC721-approve}.
     */
    function approve(address to, uint256 tokenId) public virtual override {
        address owner = ERC721.ownerOf(tokenId);
        require(to != owner, "ERC721: approval to current owner");

        require(_msgSender() == owner || ERC721.isApprovedForAll(owner, _msgSender()),
            "ERC721: approve caller is not owner nor approved for all"
        );

        _approve(to, tokenId);
    }

    /**
     * @dev See {IERC721-getApproved}.
     */
    function getApproved(uint256 tokenId) public view virtual override returns (address) {
        require(_exists(tokenId), "ERC721: approved query for nonexistent token");

        return _tokenApprovals[tokenId];
    }

    /**
     * @dev See {IERC721-setApprovalForAll}.
     */
    function setApprovalForAll(address operator, bool approved) public virtual override {
        require(operator != _msgSender(), "ERC721: approve to caller");

        _operatorApprovals[_msgSender()][operator] = approved;
        emit ApprovalForAll(_msgSender(), operator, approved);
    }

    /**
     * @dev See {IERC721-isApprovedForAll}.
     */
    function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
        return _operatorApprovals[owner][operator];
    }

    /**
     * @dev See {IERC721-transferFrom}.
     */
    function transferFrom(address from, address to, uint256 tokenId) public virtual override {
        //solhint-disable-next-line max-line-length
        require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");

        _transfer(from, to, tokenId);
    }

    /**
     * @dev See {IERC721-safeTransferFrom}.
     */
    function safeTransferFrom(address from, address to, uint256 tokenId) public virtual override {
        safeTransferFrom(from, to, tokenId, "");
    }

    /**
     * @dev See {IERC721-safeTransferFrom}.
     */
    function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory _data) public virtual override {
        require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
        _safeTransfer(from, to, tokenId, _data);
    }

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
     * are aware of the ERC721 protocol to prevent tokens from being forever locked.
     *
     * `_data` is additional data, it has no specified format and it is sent in call to `to`.
     *
     * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.
     * implement alternative mechanisms to perform token transfer, such as signature-based.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function _safeTransfer(address from, address to, uint256 tokenId, bytes memory _data) internal virtual {
        _transfer(from, to, tokenId);
        require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer");
    }

    /**
     * @dev Returns whether `tokenId` exists.
     *
     * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.
     *
     * Tokens start existing when they are minted (`_mint`),
     * and stop existing when they are burned (`_burn`).
     */
    function _exists(uint256 tokenId) internal view virtual returns (bool) {
        return _tokenOwners.contains(tokenId);
    }

    /**
     * @dev Returns whether `spender` is allowed to manage `tokenId`.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {
        require(_exists(tokenId), "ERC721: operator query for nonexistent token");
        address owner = ERC721.ownerOf(tokenId);
        return (spender == owner || getApproved(tokenId) == spender || ERC721.isApprovedForAll(owner, spender));
    }

    /**
     * @dev Safely mints `tokenId` and transfers it to `to`.
     *
     * Requirements:
     d*
     * - `tokenId` must not exist.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function _safeMint(address to, uint256 tokenId) internal virtual {
        _safeMint(to, tokenId, "");
    }

    /**
     * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
     * forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
     */
    function _safeMint(address to, uint256 tokenId, bytes memory _data) internal virtual {
        _mint(to, tokenId);
        require(_checkOnERC721Received(address(0), to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer");
    }

    /**
     * @dev Mints `tokenId` and transfers it to `to`.
     *
     * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
     *
     * Requirements:
     *
     * - `tokenId` must not exist.
     * - `to` cannot be the zero address.
     *
     * Emits a {Transfer} event.
     */
    function _mint(address to, uint256 tokenId) internal virtual {
        require(to != address(0), "ERC721: mint to the zero address");
        require(!_exists(tokenId), "ERC721: token already minted");

        _beforeTokenTransfer(address(0), to, tokenId);

        _holderTokens[to].add(tokenId);

        _tokenOwners.set(tokenId, to);

        emit Transfer(address(0), to, tokenId);
    }

    /**
     * @dev Destroys `tokenId`.
     * The approval is cleared when the token is burned.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     *
     * Emits a {Transfer} event.
     */
    function _burn(uint256 tokenId) internal virtual {
        address owner = ERC721.ownerOf(tokenId); // internal owner

        _beforeTokenTransfer(owner, address(0), tokenId);

        // Clear approvals
        _approve(address(0), tokenId);

        // Clear metadata (if any)
        if (bytes(_tokenURIs[tokenId]).length != 0) {
            delete _tokenURIs[tokenId];
        }

        _holderTokens[owner].remove(tokenId);

        _tokenOwners.remove(tokenId);

        emit Transfer(owner, address(0), tokenId);
    }

    /**
     * @dev Transfers `tokenId` from `from` to `to`.
     *  As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - `tokenId` token must be owned by `from`.
     *
     * Emits a {Transfer} event.
     */
    function _transfer(address from, address to, uint256 tokenId) internal virtual {
        require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own"); // internal owner
        require(to != address(0), "ERC721: transfer to the zero address");

        _beforeTokenTransfer(from, to, tokenId);

        // Clear approvals from the previous owner
        _approve(address(0), tokenId);

        _holderTokens[from].remove(tokenId);
        _holderTokens[to].add(tokenId);

        _tokenOwners.set(tokenId, to);

        emit Transfer(from, to, tokenId);
    }

    /**
     * @dev Sets `_tokenURI` as the tokenURI of `tokenId`.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal virtual {
        require(_exists(tokenId), "ERC721Metadata: URI set of nonexistent token");
        _tokenURIs[tokenId] = _tokenURI;
    }

    /**
     * @dev Internal function to set the base URI for all token IDs. It is
     * automatically added as a prefix to the value returned in {tokenURI},
     * or to the token ID if {tokenURI} is empty.
     */
    function _setBaseURI(string memory baseURI_) internal virtual {
        _baseURI = baseURI_;
    }

    /**
     * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.
     * The call is not executed if the target address is not a contract.
     *
     * @param from address representing the previous owner of the given token ID
     * @param to target address that will receive the tokens
     * @param tokenId uint256 ID of the token to be transferred
     * @param _data bytes optional data to send along with the call
     * @return bool whether the call correctly returned the expected magic value
     */
    function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes memory _data)
        private returns (bool)
    {
        if (!to.isContract()) {
            return true;
        }
        bytes memory returndata = to.functionCall(abi.encodeWithSelector(
            IERC721Receiver(to).onERC721Received.selector,
            _msgSender(),
            from,
            tokenId,
            _data
        ), "ERC721: transfer to non ERC721Receiver implementer");
        bytes4 retval = abi.decode(returndata, (bytes4));
        return (retval == _ERC721_RECEIVED);
    }

    /**
     * @dev Approve `to` to operate on `tokenId`
     *
     * Emits an {Approval} event.
     */
    function _approve(address to, uint256 tokenId) internal virtual {
        _tokenApprovals[tokenId] = to;
        emit Approval(ERC721.ownerOf(tokenId), to, tokenId); // internal owner
    }

    /**
     * @dev Hook that is called before any token transfer. This includes minting
     * and burning.
     *
     * Calling conditions:
     *
     * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be
     * transferred to `to`.
     * - When `from` is zero, `tokenId` will be minted for `to`.
     * - When `to` is zero, ``from``'s `tokenId` will be burned.
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual { }
}

File 8 of 83 : Context.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

/*
 * @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 GSN meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address payable) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes memory) {
        this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
        return msg.data;
    }
}

File 9 of 83 : IERC721.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.7.0;

import "../../introspection/IERC165.sol";

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

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

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

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

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

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

    /**
     * @dev Transfers `tokenId` token from `from` to `to`.
     *
     * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 tokenId) external;

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

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

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

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

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

File 10 of 83 : IERC721Metadata.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.7.0;

import "./IERC721.sol";

/**
 * @title ERC-721 Non-Fungible Token Standard, optional metadata extension
 * @dev See https://eips.ethereum.org/EIPS/eip-721
 */
interface IERC721Metadata is IERC721 {

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

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

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

File 11 of 83 : IERC721Enumerable.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.7.0;

import "./IERC721.sol";

/**
 * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
 * @dev See https://eips.ethereum.org/EIPS/eip-721
 */
interface IERC721Enumerable is IERC721 {

    /**
     * @dev Returns the total amount of tokens stored by the contract.
     */
    function totalSupply() external view returns (uint256);

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

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

File 12 of 83 : IERC721Receiver.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.7.0;

/**
 * @title ERC721 token receiver interface
 * @dev Interface for any contract that wants to support safeTransfers
 * from ERC721 asset contracts.
 */
interface IERC721Receiver {
    /**
     * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
     * by `operator` from `from`, this function is called.
     *
     * It must return its Solidity selector to confirm the token transfer.
     * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
     *
     * The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`.
     */
    function onERC721Received(address operator, address from, uint256 tokenId, bytes calldata data) external returns (bytes4);
}

File 13 of 83 : ERC165.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.7.0;

import "./IERC165.sol";

/**
 * @dev Implementation of the {IERC165} interface.
 *
 * Contracts may inherit from this and call {_registerInterface} to declare
 * their support of an interface.
 */
abstract contract ERC165 is IERC165 {
    /*
     * bytes4(keccak256('supportsInterface(bytes4)')) == 0x01ffc9a7
     */
    bytes4 private constant _INTERFACE_ID_ERC165 = 0x01ffc9a7;

    /**
     * @dev Mapping of interface ids to whether or not it's supported.
     */
    mapping(bytes4 => bool) private _supportedInterfaces;

    constructor () {
        // Derived contracts need only register support for their own interfaces,
        // we register support for ERC165 itself here
        _registerInterface(_INTERFACE_ID_ERC165);
    }

    /**
     * @dev See {IERC165-supportsInterface}.
     *
     * Time complexity O(1), guaranteed to always use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return _supportedInterfaces[interfaceId];
    }

    /**
     * @dev Registers the contract as an implementer of the interface defined by
     * `interfaceId`. Support of the actual ERC165 interface is automatic and
     * registering its interface id is not required.
     *
     * See {IERC165-supportsInterface}.
     *
     * Requirements:
     *
     * - `interfaceId` cannot be the ERC165 invalid interface (`0xffffffff`).
     */
    function _registerInterface(bytes4 interfaceId) internal virtual {
        require(interfaceId != 0xffffffff, "ERC165: invalid interface id");
        _supportedInterfaces[interfaceId] = true;
    }
}

File 14 of 83 : Address.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.7.0;

/**
 * @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
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize, which returns 0 for contracts in
        // construction, since the code is only stored at the end of the
        // constructor execution.

        uint256 size;
        // solhint-disable-next-line no-inline-assembly
        assembly { size := extcodesize(account) }
        return size > 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");

        // solhint-disable-next-line avoid-low-level-calls, avoid-call-value
        (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");

        // solhint-disable-next-line avoid-low-level-calls
        (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");

        // solhint-disable-next-line avoid-low-level-calls
        (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");

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return _verifyCallResult(success, returndata, errorMessage);
    }

    function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private 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

                // solhint-disable-next-line no-inline-assembly
                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}

File 15 of 83 : EnumerableSet.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.7.0;

/**
 * @dev Library for managing
 * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
 * types.
 *
 * Sets have the following properties:
 *
 * - Elements are added, removed, and checked for existence in constant time
 * (O(1)).
 * - Elements are enumerated in O(n). No guarantees are made on the ordering.
 *
 * ```
 * contract Example {
 *     // Add the library methods
 *     using EnumerableSet for EnumerableSet.AddressSet;
 *
 *     // Declare a set state variable
 *     EnumerableSet.AddressSet private mySet;
 * }
 * ```
 *
 * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
 * and `uint256` (`UintSet`) are supported.
 */
library EnumerableSet {
    // To implement this library for multiple types with as little code
    // repetition as possible, we write it in terms of a generic Set type with
    // bytes32 values.
    // The Set implementation uses private functions, and user-facing
    // implementations (such as AddressSet) are just wrappers around the
    // underlying Set.
    // This means that we can only create new EnumerableSets for types that fit
    // in bytes32.

    struct Set {
        // Storage of set values
        bytes32[] _values;

        // Position of the value in the `values` array, plus 1 because index 0
        // means a value is not in the set.
        mapping (bytes32 => uint256) _indexes;
    }

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

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

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

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

            // When the value to delete is the last one, the swap operation is unnecessary. However, since this occurs
            // so rarely, we still do the swap anyway to avoid the gas cost of adding an 'if' statement.

            bytes32 lastvalue = set._values[lastIndex];

            // Move the last value to the index where the value to delete is
            set._values[toDeleteIndex] = lastvalue;
            // Update the index for the moved value
            set._indexes[lastvalue] = toDeleteIndex + 1; // All indexes are 1-based

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

            // Delete the index for the deleted slot
            delete set._indexes[value];

            return true;
        } else {
            return false;
        }
    }

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

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

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

    // Bytes32Set

    struct Bytes32Set {
        Set _inner;
    }

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

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

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

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

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

    // AddressSet

    struct AddressSet {
        Set _inner;
    }

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

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

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

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

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


    // UintSet

    struct UintSet {
        Set _inner;
    }

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

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

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

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

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

File 16 of 83 : EnumerableMap.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.7.0;

/**
 * @dev Library for managing an enumerable variant of Solidity's
 * https://solidity.readthedocs.io/en/latest/types.html#mapping-types[`mapping`]
 * type.
 *
 * Maps have the following properties:
 *
 * - Entries are added, removed, and checked for existence in constant time
 * (O(1)).
 * - Entries are enumerated in O(n). No guarantees are made on the ordering.
 *
 * ```
 * contract Example {
 *     // Add the library methods
 *     using EnumerableMap for EnumerableMap.UintToAddressMap;
 *
 *     // Declare a set state variable
 *     EnumerableMap.UintToAddressMap private myMap;
 * }
 * ```
 *
 * As of v3.0.0, only maps of type `uint256 -> address` (`UintToAddressMap`) are
 * supported.
 */
library EnumerableMap {
    // To implement this library for multiple types with as little code
    // repetition as possible, we write it in terms of a generic Map type with
    // bytes32 keys and values.
    // The Map implementation uses private functions, and user-facing
    // implementations (such as Uint256ToAddressMap) are just wrappers around
    // the underlying Map.
    // This means that we can only create new EnumerableMaps for types that fit
    // in bytes32.

    struct MapEntry {
        bytes32 _key;
        bytes32 _value;
    }

    struct Map {
        // Storage of map keys and values
        MapEntry[] _entries;

        // Position of the entry defined by a key in the `entries` array, plus 1
        // because index 0 means a key is not in the map.
        mapping (bytes32 => uint256) _indexes;
    }

    /**
     * @dev Adds a key-value pair to a map, or updates the value for an existing
     * key. O(1).
     *
     * Returns true if the key was added to the map, that is if it was not
     * already present.
     */
    function _set(Map storage map, bytes32 key, bytes32 value) private returns (bool) {
        // We read and store the key's index to prevent multiple reads from the same storage slot
        uint256 keyIndex = map._indexes[key];

        if (keyIndex == 0) { // Equivalent to !contains(map, key)
            map._entries.push(MapEntry({ _key: key, _value: value }));
            // The entry is stored at length-1, but we add 1 to all indexes
            // and use 0 as a sentinel value
            map._indexes[key] = map._entries.length;
            return true;
        } else {
            map._entries[keyIndex - 1]._value = value;
            return false;
        }
    }

    /**
     * @dev Removes a key-value pair from a map. O(1).
     *
     * Returns true if the key was removed from the map, that is if it was present.
     */
    function _remove(Map storage map, bytes32 key) private returns (bool) {
        // We read and store the key's index to prevent multiple reads from the same storage slot
        uint256 keyIndex = map._indexes[key];

        if (keyIndex != 0) { // Equivalent to contains(map, key)
            // To delete a key-value pair from the _entries array in O(1), we swap the entry to delete with the last one
            // in the array, and then remove the last entry (sometimes called as 'swap and pop').
            // This modifies the order of the array, as noted in {at}.

            uint256 toDeleteIndex = keyIndex - 1;
            uint256 lastIndex = map._entries.length - 1;

            // When the entry to delete is the last one, the swap operation is unnecessary. However, since this occurs
            // so rarely, we still do the swap anyway to avoid the gas cost of adding an 'if' statement.

            MapEntry storage lastEntry = map._entries[lastIndex];

            // Move the last entry to the index where the entry to delete is
            map._entries[toDeleteIndex] = lastEntry;
            // Update the index for the moved entry
            map._indexes[lastEntry._key] = toDeleteIndex + 1; // All indexes are 1-based

            // Delete the slot where the moved entry was stored
            map._entries.pop();

            // Delete the index for the deleted slot
            delete map._indexes[key];

            return true;
        } else {
            return false;
        }
    }

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

    /**
     * @dev Returns the number of key-value pairs in the map. O(1).
     */
    function _length(Map storage map) private view returns (uint256) {
        return map._entries.length;
    }

   /**
    * @dev Returns the key-value pair stored at position `index` in the map. O(1).
    *
    * Note that there are no guarantees on the ordering of entries inside the
    * array, and it may change when more entries are added or removed.
    *
    * Requirements:
    *
    * - `index` must be strictly less than {length}.
    */
    function _at(Map storage map, uint256 index) private view returns (bytes32, bytes32) {
        require(map._entries.length > index, "EnumerableMap: index out of bounds");

        MapEntry storage entry = map._entries[index];
        return (entry._key, entry._value);
    }

    /**
     * @dev Tries to returns the value associated with `key`.  O(1).
     * Does not revert if `key` is not in the map.
     */
    function _tryGet(Map storage map, bytes32 key) private view returns (bool, bytes32) {
        uint256 keyIndex = map._indexes[key];
        if (keyIndex == 0) return (false, 0); // Equivalent to contains(map, key)
        return (true, map._entries[keyIndex - 1]._value); // All indexes are 1-based
    }

    /**
     * @dev Returns the value associated with `key`.  O(1).
     *
     * Requirements:
     *
     * - `key` must be in the map.
     */
    function _get(Map storage map, bytes32 key) private view returns (bytes32) {
        uint256 keyIndex = map._indexes[key];
        require(keyIndex != 0, "EnumerableMap: nonexistent key"); // Equivalent to contains(map, key)
        return map._entries[keyIndex - 1]._value; // All indexes are 1-based
    }

    /**
     * @dev Same as {_get}, with a custom error message when `key` is not in the map.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {_tryGet}.
     */
    function _get(Map storage map, bytes32 key, string memory errorMessage) private view returns (bytes32) {
        uint256 keyIndex = map._indexes[key];
        require(keyIndex != 0, errorMessage); // Equivalent to contains(map, key)
        return map._entries[keyIndex - 1]._value; // All indexes are 1-based
    }

    // UintToAddressMap

    struct UintToAddressMap {
        Map _inner;
    }

    /**
     * @dev Adds a key-value pair to a map, or updates the value for an existing
     * key. O(1).
     *
     * Returns true if the key was added to the map, that is if it was not
     * already present.
     */
    function set(UintToAddressMap storage map, uint256 key, address value) internal returns (bool) {
        return _set(map._inner, bytes32(key), bytes32(uint256(uint160(value))));
    }

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

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

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

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

    /**
     * @dev Tries to returns the value associated with `key`.  O(1).
     * Does not revert if `key` is not in the map.
     *
     * _Available since v3.4._
     */
    function tryGet(UintToAddressMap storage map, uint256 key) internal view returns (bool, address) {
        (bool success, bytes32 value) = _tryGet(map._inner, bytes32(key));
        return (success, address(uint160(uint256(value))));
    }

    /**
     * @dev Returns the value associated with `key`.  O(1).
     *
     * Requirements:
     *
     * - `key` must be in the map.
     */
    function get(UintToAddressMap storage map, uint256 key) internal view returns (address) {
        return address(uint160(uint256(_get(map._inner, bytes32(key)))));
    }

    /**
     * @dev Same as {get}, with a custom error message when `key` is not in the map.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryGet}.
     */
    function get(UintToAddressMap storage map, uint256 key, string memory errorMessage) internal view returns (address) {
        return address(uint160(uint256(_get(map._inner, bytes32(key), errorMessage))));
    }
}

File 17 of 83 : Strings.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.7.0;

/**
 * @dev String operations.
 */
library Strings {
    /**
     * @dev Converts a `uint256` to its ASCII `string` representation.
     */
    function toString(uint256 value) internal pure returns (string memory) {
        // Inspired by OraclizeAPI's implementation - MIT licence
        // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol

        if (value == 0) {
            return "0";
        }
        uint256 temp = value;
        uint256 digits;
        while (temp != 0) {
            digits++;
            temp /= 10;
        }
        bytes memory buffer = new bytes(digits);
        uint256 index = digits - 1;
        temp = value;
        while (temp != 0) {
            buffer[index--] = bytes1(uint8(48 + temp % 10));
            temp /= 10;
        }
        return string(buffer);
    }
}

File 18 of 83 : IERC165.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.7.0;

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

File 19 of 83 : ERC721Permit.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.7.6;

import '@openzeppelin/contracts/token/ERC721/ERC721.sol';
import '@openzeppelin/contracts/utils/Address.sol';

import '../libraries/ChainId.sol';
import '../interfaces/external/IERC1271.sol';
import '../interfaces/IERC721Permit.sol';
import './BlockTimestamp.sol';

/// @title ERC721 with permit
/// @notice Nonfungible tokens that support an approve via signature, i.e. permit
abstract contract ERC721Permit is BlockTimestamp, ERC721, IERC721Permit {
    /// @dev Gets the current nonce for a token ID and then increments it, returning the original value
    function _getAndIncrementNonce(uint256 tokenId) internal virtual returns (uint256);

    /// @dev The hash of the name used in the permit signature verification
    bytes32 private immutable nameHash;

    /// @dev The hash of the version string used in the permit signature verification
    bytes32 private immutable versionHash;

    /// @notice Computes the nameHash and versionHash
    constructor(
        string memory name_,
        string memory symbol_,
        string memory version_
    ) ERC721(name_, symbol_) {
        nameHash = keccak256(bytes(name_));
        versionHash = keccak256(bytes(version_));
    }

    /// @inheritdoc IERC721Permit
    function DOMAIN_SEPARATOR() public view override returns (bytes32) {
        return
            keccak256(
                abi.encode(
                    // keccak256('EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)')
                    0x8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f,
                    nameHash,
                    versionHash,
                    ChainId.get(),
                    address(this)
                )
            );
    }

    /// @inheritdoc IERC721Permit
    /// @dev Value is equal to keccak256("Permit(address spender,uint256 tokenId,uint256 nonce,uint256 deadline)");
    bytes32 public constant override PERMIT_TYPEHASH =
        0x49ecf333e5b8c95c40fdafc95c1ad136e8914a8fb55e9dc8bb01eaa83a2df9ad;

    /// @inheritdoc IERC721Permit
    function permit(
        address spender,
        uint256 tokenId,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external payable override {
        require(_blockTimestamp() <= deadline, 'Permit expired');

        bytes32 digest = keccak256(
            abi.encodePacked(
                '\x19\x01',
                DOMAIN_SEPARATOR(),
                keccak256(abi.encode(PERMIT_TYPEHASH, spender, tokenId, _getAndIncrementNonce(tokenId), deadline))
            )
        );
        address owner = ownerOf(tokenId);
        require(spender != owner, 'ERC721Permit: approval to current owner');

        if (Address.isContract(owner)) {
            require(IERC1271(owner).isValidSignature(digest, abi.encodePacked(r, s, v)) == 0x1626ba7e, 'Unauthorized');
        } else {
            address recoveredAddress = ecrecover(digest, v, r, s);
            require(recoveredAddress != address(0), 'Invalid signature');
            require(recoveredAddress == owner, 'Unauthorized');
        }

        _approve(spender, tokenId);
    }
}

File 20 of 83 : ChainId.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.0;

/// @title Function for getting the current chain ID
library ChainId {
    /// @dev Gets the current chain ID
    /// @return chainId The current chain ID
    function get() internal pure returns (uint256 chainId) {
        assembly {
            chainId := chainid()
        }
    }
}

File 21 of 83 : IERC1271.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Interface for verifying contract-based account signatures
/// @notice Interface that verifies provided signature for the data
/// @dev Interface defined by EIP-1271
interface IERC1271 {
    /// @notice Returns whether the provided signature is valid for the provided data
    /// @dev MUST return the bytes4 magic value 0x1626ba7e when function passes.
    /// MUST NOT modify state (using STATICCALL for solc < 0.5, view modifier for solc > 0.5).
    /// MUST allow external calls.
    /// @param hash Hash of the data to be signed
    /// @param signature Signature byte array associated with _data
    /// @return magicValue The bytes4 magic value 0x1626ba7e
    function isValidSignature(bytes32 hash, bytes memory signature) external view returns (bytes4 magicValue);
}

File 22 of 83 : IERC721Permit.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;

import '@openzeppelin/contracts/token/ERC721/IERC721.sol';

/// @title ERC721 with permit
/// @notice Extension to ERC721 that includes a permit function for signature based approvals
interface IERC721Permit is IERC721 {
    /// @notice The permit typehash used in the permit signature
    /// @return The typehash for the permit
    function PERMIT_TYPEHASH() external pure returns (bytes32);

    /// @notice The domain separator used in the permit signature
    /// @return The domain separator used in encoding of permit signature
    function DOMAIN_SEPARATOR() external view returns (bytes32);

    /// @notice Approve of a specific token ID for spending by spender via signature
    /// @param spender The account that is being approved
    /// @param tokenId The ID of the token that is being approved for spending
    /// @param deadline The deadline timestamp by which the call must be mined for the approve to work
    /// @param v Must produce valid secp256k1 signature from the holder along with `r` and `s`
    /// @param r Must produce valid secp256k1 signature from the holder along with `v` and `s`
    /// @param s Must produce valid secp256k1 signature from the holder along with `r` and `v`
    function permit(
        address spender,
        uint256 tokenId,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external payable;
}

File 23 of 83 : BlockTimestamp.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.7.6;

/// @title Function for getting block timestamp
/// @dev Base contract that is overridden for tests
abstract contract BlockTimestamp {
    /// @dev Method that exists purely to be overridden for tests
    /// @return The current block timestamp
    function _blockTimestamp() internal view virtual returns (uint256) {
        return block.timestamp;
    }
}

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

import '@openzeppelin/contracts/token/ERC721/IERC721Metadata.sol';
import '@openzeppelin/contracts/token/ERC721/IERC721Enumerable.sol';

import './IPoolInitializer.sol';
import './IERC721Permit.sol';
import './IPeripheryPayments.sol';
import './IPeripheryImmutableState.sol';
import '../libraries/PoolAddress.sol';

/// @title Non-fungible token for positions
/// @notice Wraps Algebra positions in a non-fungible token interface which allows for them to be transferred
/// and authorized.
/// @dev Credit to Uniswap Labs under GPL-2.0-or-later license:
/// https://github.com/Uniswap/v3-periphery
interface INonfungiblePositionManager is
    IPoolInitializer,
    IPeripheryPayments,
    IPeripheryImmutableState,
    IERC721Metadata,
    IERC721Enumerable,
    IERC721Permit
{
    /// @notice Emitted when liquidity is increased for a position NFT
    /// @dev Also emitted when a token is minted
    /// @param tokenId The ID of the token for which liquidity was increased
    /// @param liquidity The amount by which liquidity for the NFT position was increased
    /// @param actualLiquidity the actual liquidity that was added into a pool. Could differ from
    /// _liquidity_ when using FeeOnTransfer tokens
    /// @param amount0 The amount of token0 that was paid for the increase in liquidity
    /// @param amount1 The amount of token1 that was paid for the increase in liquidity
    event IncreaseLiquidity(
        uint256 indexed tokenId,
        uint128 liquidity,
        uint128 actualLiquidity,
        uint256 amount0,
        uint256 amount1,
        address pool
    );
    /// @notice Emitted when liquidity is decreased for a position NFT
    /// @param tokenId The ID of the token for which liquidity was decreased
    /// @param liquidity The amount by which liquidity for the NFT position was decreased
    /// @param amount0 The amount of token0 that was accounted for the decrease in liquidity
    /// @param amount1 The amount of token1 that was accounted for the decrease in liquidity
    event DecreaseLiquidity(uint256 indexed tokenId, uint128 liquidity, uint256 amount0, uint256 amount1);
    /// @notice Emitted when tokens are collected for a position NFT
    /// @dev The amounts reported may not be exactly equivalent to the amounts transferred, due to rounding behavior
    /// @param tokenId The ID of the token for which underlying tokens were collected
    /// @param recipient The address of the account that received the collected tokens
    /// @param amount0 The amount of token0 owed to the position that was collected
    /// @param amount1 The amount of token1 owed to the position that was collected
    event Collect(uint256 indexed tokenId, address recipient, uint256 amount0, uint256 amount1);

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

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

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

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

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

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

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

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

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

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

File 25 of 83 : IPoolInitializer.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;
pragma abicoder v2;

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

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

/// @title Periphery Payments
/// @notice Functions to ease deposits and withdrawals of NativeToken
/// @dev Credit to Uniswap Labs under GPL-2.0-or-later license:
/// https://github.com/Uniswap/v3-periphery
interface IPeripheryPayments {
    /// @notice Unwraps the contract's WNativeToken balance and sends it to recipient as NativeToken.
    /// @dev The amountMinimum parameter prevents malicious contracts from stealing WNativeToken from users.
    /// @param amountMinimum The minimum amount of WNativeToken to unwrap
    /// @param recipient The address receiving NativeToken
    function unwrapWNativeToken(uint256 amountMinimum, address recipient) external payable;

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

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

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

/// @title Immutable state
/// @notice Functions that return immutable state of the router
/// @dev Credit to Uniswap Labs under GPL-2.0-or-later license:
/// https://github.com/Uniswap/v3-periphery
interface IPeripheryImmutableState {
    /// @return Returns the address of the Algebra factory
    function factory() external view returns (address);

    /// @return Returns the address of the pool Deployer
    function poolDeployer() external view returns (address);

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

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

/// @title Provides functions for deriving a pool address from the factory, tokens, and the fee
/// @dev Credit to Uniswap Labs under GPL-2.0-or-later license:
/// https://github.com/Uniswap/v3-periphery
library PoolAddress {
    bytes32 internal constant POOL_INIT_CODE_HASH = 0x6ec6c9c8091d160c0aa74b2b14ba9c1717e95093bd3ac085cee99a49aab294a4;

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

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

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

File 29 of 83 : NFTPositionInfo.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.7.6;

import 'algebra-periphery/contracts/interfaces/INonfungiblePositionManager.sol';
import 'algebra/contracts/interfaces/IAlgebraFactory.sol';
import 'algebra/contracts/interfaces/IAlgebraPool.sol';
import 'algebra/contracts/interfaces/IAlgebraPoolDeployer.sol';
import 'algebra-periphery/contracts/libraries/PoolAddress.sol';

/// @notice Encapsulates the logic for getting info about a NFT token ID
library NFTPositionInfo {
    /// @param deployer The address of the Algebra Deployer used in computing the pool address
    /// @param nonfungiblePositionManager The address of the nonfungible position manager to query
    /// @param tokenId The unique identifier of an Algebra LP token
    /// @return pool The address of the Algebra pool
    /// @return tickLower The lower tick of the Algebra position
    /// @return tickUpper The upper tick of the Algebra position
    /// @return liquidity The amount of liquidity farmd
    function getPositionInfo(
        IAlgebraPoolDeployer deployer,
        INonfungiblePositionManager nonfungiblePositionManager,
        uint256 tokenId
    )
        internal
        view
        returns (
            IAlgebraPool pool,
            int24 tickLower,
            int24 tickUpper,
            uint128 liquidity
        )
    {
        address token0;
        address token1;
        (, , token0, token1, tickLower, tickUpper, liquidity, , , , ) = nonfungiblePositionManager.positions(tokenId);

        pool = IAlgebraPool(
            PoolAddress.computeAddress(address(deployer), PoolAddress.PoolKey({token0: token0, token1: token1}))
        );
    }
}

File 30 of 83 : IAlgebraFactory.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/**
 * @title The interface for the Algebra Factory
 * @dev Credit to Uniswap Labs under GPL-2.0-or-later license:
 * https://github.com/Uniswap/v3-core/tree/main/contracts/interfaces
 */
interface IAlgebraFactory {
  /**
   *  @notice Emitted when the owner of the factory is changed
   *  @param newOwner The owner after the owner was changed
   */
  event Owner(address indexed newOwner);

  /**
   *  @notice Emitted when the vault address is changed
   *  @param newVaultAddress The vault address after the address was changed
   */
  event VaultAddress(address indexed newVaultAddress);

  /**
   *  @notice Emitted when a pool is created
   *  @param token0 The first token of the pool by address sort order
   *  @param token1 The second token of the pool by address sort order
   *  @param pool The address of the created pool
   */
  event Pool(address indexed token0, address indexed token1, address pool);

  /**
   *  @notice Emitted when the farming address is changed
   *  @param newFarmingAddress The farming address after the address was changed
   */
  event FarmingAddress(address indexed newFarmingAddress);

  event FeeConfiguration(
    uint16 alpha1,
    uint16 alpha2,
    uint32 beta1,
    uint32 beta2,
    uint16 gamma1,
    uint16 gamma2,
    uint32 volumeBeta,
    uint16 volumeGamma,
    uint16 baseFee
  );

  /**
   *  @notice Returns the current owner of the factory
   *  @dev Can be changed by the current owner via setOwner
   *  @return The address of the factory owner
   */
  function owner() external view returns (address);

  /**
   *  @notice Returns the current poolDeployerAddress
   *  @return The address of the poolDeployer
   */
  function poolDeployer() external view returns (address);

  /**
   * @dev Is retrieved from the pools to restrict calling
   * certain functions not by a tokenomics contract
   * @return The tokenomics contract address
   */
  function farmingAddress() external view returns (address);

  function vaultAddress() external view returns (address);

  /**
   *  @notice Returns the pool address for a given pair of tokens and a fee, or address 0 if it does not exist
   *  @dev tokenA and tokenB may be passed in either token0/token1 or token1/token0 order
   *  @param tokenA The contract address of either token0 or token1
   *  @param tokenB The contract address of the other token
   *  @return pool The pool address
   */
  function poolByPair(address tokenA, address tokenB) external view returns (address pool);

  /**
   *  @notice Creates a pool for the given two tokens and fee
   *  @param tokenA One of the two tokens in the desired pool
   *  @param tokenB The other of the two tokens in the desired pool
   *  @dev tokenA and tokenB may be passed in either order: token0/token1 or token1/token0. tickSpacing is retrieved
   *  from the fee. The call will revert if the pool already exists, the fee is invalid, or the token arguments
   *  are invalid.
   *  @return pool The address of the newly created pool
   */
  function createPool(address tokenA, address tokenB) external returns (address pool);

  /**
   *  @notice Updates the owner of the factory
   *  @dev Must be called by the current owner
   *  @param _owner The new owner of the factory
   */
  function setOwner(address _owner) external;

  /**
   * @dev updates tokenomics address on the factory
   * @param _farmingAddress The new tokenomics contract address
   */
  function setFarmingAddress(address _farmingAddress) external;

  /**
   * @dev updates vault address on the factory
   * @param _vaultAddress The new vault contract address
   */
  function setVaultAddress(address _vaultAddress) external;

  /**
   * @notice Changes initial fee configuration for new pools
   * @dev changes coefficients for sigmoids: α / (1 + e^( (β-x) / γ))
   * alpha1 + alpha2 + baseFee (max possible fee) must be <= type(uint16).max
   * gammas must be > 0
   * @param alpha1 max value of the first sigmoid
   * @param alpha2 max value of the second sigmoid
   * @param beta1 shift along the x-axis for the first sigmoid
   * @param beta2 shift along the x-axis for the second sigmoid
   * @param gamma1 horizontal stretch factor for the first sigmoid
   * @param gamma2 horizontal stretch factor for the second sigmoid
   * @param volumeBeta shift along the x-axis for the outer volume-sigmoid
   * @param volumeGamma horizontal stretch factor the outer volume-sigmoid
   * @param baseFee minimum possible fee
   */
  function setBaseFeeConfiguration(
    uint16 alpha1,
    uint16 alpha2,
    uint32 beta1,
    uint32 beta2,
    uint16 gamma1,
    uint16 gamma2,
    uint32 volumeBeta,
    uint16 volumeGamma,
    uint16 baseFee
  ) external;
}

File 31 of 83 : IAlgebraPool.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

import './pool/IAlgebraPoolImmutables.sol';
import './pool/IAlgebraPoolState.sol';
import './pool/IAlgebraPoolDerivedState.sol';
import './pool/IAlgebraPoolActions.sol';
import './pool/IAlgebraPoolPermissionedActions.sol';
import './pool/IAlgebraPoolEvents.sol';

/**
 * @title The interface for a Algebra Pool
 * @dev The pool interface is broken up into many smaller pieces.
 * Credit to Uniswap Labs under GPL-2.0-or-later license:
 * https://github.com/Uniswap/v3-core/tree/main/contracts/interfaces
 */
interface IAlgebraPool is
  IAlgebraPoolImmutables,
  IAlgebraPoolState,
  IAlgebraPoolDerivedState,
  IAlgebraPoolActions,
  IAlgebraPoolPermissionedActions,
  IAlgebraPoolEvents
{
  // used only for combining interfaces
}

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

/**
 * @title An interface for a contract that is capable of deploying Algebra Pools
 * @notice A contract that constructs a pool must implement this to pass arguments to the pool
 * @dev This is used to avoid having constructor arguments in the pool contract, which results in the init code hash
 * of the pool being constant allowing the CREATE2 address of the pool to be cheaply computed on-chain.
 * Credit to Uniswap Labs under GPL-2.0-or-later license:
 * https://github.com/Uniswap/v3-core/tree/main/contracts/interfaces
 */
interface IAlgebraPoolDeployer {
  /**
   *  @notice Emitted when the factory address is changed
   *  @param factory The factory address after the address was changed
   */
  event Factory(address indexed factory);

  /**
   * @notice Get the parameters to be used in constructing the pool, set transiently during pool creation.
   * @dev Called by the pool constructor to fetch the parameters of the pool
   * Returns dataStorage The pools associated dataStorage
   * Returns factory The factory address
   * Returns token0 The first token of the pool by address sort order
   * Returns token1 The second token of the pool by address sort order
   */
  function parameters()
    external
    view
    returns (
      address dataStorage,
      address factory,
      address token0,
      address token1
    );

  /**
   * @dev Deploys a pool with the given parameters by transiently setting the parameters storage slot and then
   * clearing it after deploying the pool.
   * @param dataStorage The pools associated dataStorage
   * @param factory The contract address of the Algebra factory
   * @param token0 The first token of the pool by address sort order
   * @param token1 The second token of the pool by address sort order
   * @return pool The deployed pool's address
   */
  function deploy(
    address dataStorage,
    address factory,
    address token0,
    address token1
  ) external returns (address pool);

  /**
   * @dev Sets the factory address to the poolDeployer for permissioned actions
   * @param factory The address of the Algebra factory
   */
  function setFactory(address factory) external;
}

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

import '../IDataStorageOperator.sol';

/// @title Pool state that never changes
/// @dev Credit to Uniswap Labs under GPL-2.0-or-later license:
/// https://github.com/Uniswap/v3-core/tree/main/contracts/interfaces
interface IAlgebraPoolImmutables {
  /**
   * @notice The contract that stores all the timepoints and can perform actions with them
   * @return The operator address
   */
  function dataStorageOperator() external view returns (address);

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

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

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

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

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

File 34 of 83 : IAlgebraPoolState.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Pool state that can change
/// @dev Credit to Uniswap Labs under GPL-2.0-or-later license:
/// https://github.com/Uniswap/v3-core/tree/main/contracts/interfaces
interface IAlgebraPoolState {
  /**
   * @notice The globalState structure in the pool stores many values but requires only one slot
   * and is exposed as a single method to save gas when accessed externally.
   * @return price The current price of the pool as a sqrt(token1/token0) Q64.96 value;
   * Returns tick The current tick of the pool, i.e. according to the last tick transition that was run;
   * Returns This value may not always be equal to SqrtTickMath.getTickAtSqrtRatio(price) if the price is on a tick
   * boundary;
   * Returns fee The last pool fee value in hundredths of a bip, i.e. 1e-6;
   * Returns timepointIndex The index of the last written timepoint;
   * Returns communityFeeToken0 The community fee percentage of the swap fee in thousandths (1e-3) for token0;
   * Returns communityFeeToken1 The community fee percentage of the swap fee in thousandths (1e-3) for token1;
   * Returns unlocked Whether the pool is currently locked to reentrancy;
   */
  function globalState()
    external
    view
    returns (
      uint160 price,
      int24 tick,
      uint16 fee,
      uint16 timepointIndex,
      uint8 communityFeeToken0,
      uint8 communityFeeToken1,
      bool unlocked
    );

  /**
   * @notice The fee growth as a Q128.128 fees of token0 collected per unit of liquidity for the entire life of the pool
   * @dev This value can overflow the uint256
   */
  function totalFeeGrowth0Token() 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 totalFeeGrowth1Token() external view returns (uint256);

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

  /**
   * @notice Look up information about a specific tick in the pool
   * @dev This is a public structure, so the `return` natspec tags are omitted.
   * @param tick The tick to look up
   * @return liquidityTotal the total amount of position liquidity that uses the pool either as tick lower or
   * tick upper;
   * Returns liquidityDelta how much liquidity changes when the pool price crosses the tick;
   * Returns outerFeeGrowth0Token the fee growth on the other side of the tick from the current tick in token0;
   * Returns outerFeeGrowth1Token the fee growth on the other side of the tick from the current tick in token1;
   * Returns outerTickCumulative the cumulative tick value on the other side of the tick from the current tick;
   * Returns outerSecondsPerLiquidity the seconds spent per liquidity on the other side of the tick from the current tick;
   * Returns outerSecondsSpent the seconds spent on the other side of the tick from the current tick;
   * Returns initialized Set to true if the tick is initialized, i.e. liquidityTotal is greater than 0
   * otherwise equal to false. Outside values can only be used if the tick is initialized.
   * 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 liquidityTotal,
      int128 liquidityDelta,
      uint256 outerFeeGrowth0Token,
      uint256 outerFeeGrowth1Token,
      int56 outerTickCumulative,
      uint160 outerSecondsPerLiquidity,
      uint32 outerSecondsSpent,
      bool initialized
    );

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

  /**
   * @notice Returns the information about a position by the position's key
   * @dev This is a public mapping of structures, so the `return` natspec tags are omitted.
   * @param key The position's key is a hash of a preimage composed by the owner, bottomTick and topTick
   * @return liquidityAmount The amount of liquidity in the position;
   * Returns lastLiquidityAddTimestamp Timestamp of last adding of liquidity;
   * Returns innerFeeGrowth0Token Fee growth of token0 inside the tick range as of the last mint/burn/poke;
   * Returns innerFeeGrowth1Token Fee growth of token1 inside the tick range as of the last mint/burn/poke;
   * Returns fees0 The computed amount of token0 owed to the position as of the last mint/burn/poke;
   * Returns fees1 The computed amount of token1 owed to the position as of the last mint/burn/poke
   */
  function positions(bytes32 key)
    external
    view
    returns (
      uint128 liquidityAmount,
      uint32 lastLiquidityAddTimestamp,
      uint256 innerFeeGrowth0Token,
      uint256 innerFeeGrowth1Token,
      uint128 fees0,
      uint128 fees1
    );

  /**
   * @notice Returns data about a specific timepoint index
   * @param index The element of the timepoints array to fetch
   * @dev You most likely want to use #getTimepoints() instead of this method to get an timepoint as of some amount of time
   * ago, rather than at a specific index in the array.
   * This is a public mapping of structures, so the `return` natspec tags are omitted.
   * @return initialized whether the timepoint has been initialized and the values are safe to use;
   * Returns blockTimestamp The timestamp of the timepoint;
   * Returns tickCumulative the tick multiplied by seconds elapsed for the life of the pool as of the timepoint timestamp;
   * Returns secondsPerLiquidityCumulative the seconds per in range liquidity for the life of the pool as of the timepoint timestamp;
   * Returns volatilityCumulative Cumulative standard deviation for the life of the pool as of the timepoint timestamp;
   * Returns averageTick Time-weighted average tick;
   * Returns volumePerLiquidityCumulative Cumulative swap volume per liquidity for the life of the pool as of the timepoint timestamp;
   */
  function timepoints(uint256 index)
    external
    view
    returns (
      bool initialized,
      uint32 blockTimestamp,
      int56 tickCumulative,
      uint160 secondsPerLiquidityCumulative,
      uint88 volatilityCumulative,
      int24 averageTick,
      uint144 volumePerLiquidityCumulative
    );

  /**
   * @notice Returns the information about active incentive
   * @dev if there is no active incentive at the moment, virtualPool,endTimestamp,startTimestamp would be equal to 0
   * @return virtualPool The address of a virtual pool associated with the current active incentive
   */
  function activeIncentive() external view returns (address virtualPool);

  /**
   * @notice Returns the lock time for added liquidity
   */
  function liquidityCooldown() external view returns (uint32 cooldownInSeconds);
}

File 35 of 83 : IAlgebraPoolDerivedState.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/**
 * @title Pool state that is not stored
 * @notice Contains view functions to provide information about the pool that is computed rather than stored on the
 * blockchain. The functions here may have variable gas costs.
 * @dev Credit to Uniswap Labs under GPL-2.0-or-later license:
 * https://github.com/Uniswap/v3-core/tree/main/contracts/interfaces
 */
interface IAlgebraPoolDerivedState {
  /**
   * @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 secondsPerLiquidityCumulatives Cumulative seconds per liquidity-in-range value as of each `secondsAgos`
   * from the current block timestamp
   * @return volatilityCumulatives Cumulative standard deviation as of each `secondsAgos`
   * @return volumePerAvgLiquiditys Cumulative swap volume per liquidity as of each `secondsAgos`
   */
  function getTimepoints(uint32[] calldata secondsAgos)
    external
    view
    returns (
      int56[] memory tickCumulatives,
      uint160[] memory secondsPerLiquidityCumulatives,
      uint112[] memory volatilityCumulatives,
      uint256[] memory volumePerAvgLiquiditys
    );

  /**
   * @notice Returns a snapshot of the tick cumulative, seconds per liquidity and seconds inside a tick range
   * @dev Snapshots must only be compared to other snapshots, taken over a period for which a position existed.
   * I.e., snapshots cannot be compared if a position is not held for the entire period between when the first
   * snapshot is taken and the second snapshot is taken.
   * @param bottomTick The lower tick of the range
   * @param topTick The upper tick of the range
   * @return innerTickCumulative The snapshot of the tick accumulator for the range
   * @return innerSecondsSpentPerLiquidity The snapshot of seconds per liquidity for the range
   * @return innerSecondsSpent The snapshot of the number of seconds during which the price was in this range
   */
  function getInnerCumulatives(int24 bottomTick, int24 topTick)
    external
    view
    returns (
      int56 innerTickCumulative,
      uint160 innerSecondsSpentPerLiquidity,
      uint32 innerSecondsSpent
    );
}

File 36 of 83 : IAlgebraPoolActions.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Permissionless pool actions
/// @dev Credit to Uniswap Labs under GPL-2.0-or-later license:
/// https://github.com/Uniswap/v3-core/tree/main/contracts/interfaces
interface IAlgebraPoolActions {
  /**
   * @notice Sets the initial price for the pool
   * @dev Price is represented as a sqrt(amountToken1/amountToken0) Q64.96 value
   * @param price the initial sqrt price of the pool as a Q64.96
   */
  function initialize(uint160 price) external;

  /**
   * @notice Adds liquidity for the given recipient/bottomTick/topTick position
   * @dev The caller of this method receives a callback in the form of IAlgebraMintCallback# AlgebraMintCallback
   * in which they must pay any token0 or token1 owed for the liquidity. The amount of token0/token1 due depends
   * on bottomTick, topTick, the amount of liquidity, and the current price.
   * @param sender The address which will receive potential surplus of paid tokens
   * @param recipient The address for which the liquidity will be created
   * @param bottomTick The lower tick of the position in which to add liquidity
   * @param topTick The upper tick of the position in which to add liquidity
   * @param amount The desired 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
   * @return liquidityActual The actual minted amount of liquidity
   */
  function mint(
    address sender,
    address recipient,
    int24 bottomTick,
    int24 topTick,
    uint128 amount,
    bytes calldata data
  )
    external
    returns (
      uint256 amount0,
      uint256 amount1,
      uint128 liquidityActual
    );

  /**
   * @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 bottomTick The lower tick of the position for which to collect fees
   * @param topTick 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 bottomTick,
    int24 topTick,
    uint128 amount0Requested,
    uint128 amount1Requested
  ) external returns (uint128 amount0, uint128 amount1);

  /**
   * @notice Burn liquidity from the sender and account tokens owed for the liquidity to the position
   * @dev Can be used to trigger a recalculation of fees owed to a position by calling with an amount of 0
   * @dev Fees must be collected separately via a call to #collect
   * @param bottomTick The lower tick of the position for which to burn liquidity
   * @param topTick 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 bottomTick,
    int24 topTick,
    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 IAlgebraSwapCallback# AlgebraSwapCallback
   * @param recipient The address to receive the output of the swap
   * @param zeroToOne 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 limitSqrtPrice 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. If using the Router it should contain
   * SwapRouter#SwapCallbackData
   * @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 zeroToOne,
    int256 amountSpecified,
    uint160 limitSqrtPrice,
    bytes calldata data
  ) external returns (int256 amount0, int256 amount1);

  /**
   * @notice Swap token0 for token1, or token1 for token0 (tokens that have fee on transfer)
   * @dev The caller of this method receives a callback in the form of I AlgebraSwapCallback# AlgebraSwapCallback
   * @param sender The address called this function (Comes from the Router)
   * @param recipient The address to receive the output of the swap
   * @param zeroToOne 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 limitSqrtPrice 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. If using the Router it should contain
   * SwapRouter#SwapCallbackData
   * @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 swapSupportingFeeOnInputTokens(
    address sender,
    address recipient,
    bool zeroToOne,
    int256 amountSpecified,
    uint160 limitSqrtPrice,
    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 IAlgebraFlashCallback# AlgebraFlashCallback
   * @dev All excess tokens paid in the callback are distributed to liquidity providers as an additional fee. So this method can be used
   * to donate underlying tokens 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;
}

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

/**
 * @title Permissioned pool actions
 * @notice Contains pool methods that may only be called by the factory owner or tokenomics
 * @dev Credit to Uniswap Labs under GPL-2.0-or-later license:
 * https://github.com/Uniswap/v3-core/tree/main/contracts/interfaces
 */
interface IAlgebraPoolPermissionedActions {
  /**
   * @notice Set the community's % share of the fees. Cannot exceed 25% (250)
   * @param communityFee0 new community fee percent for token0 of the pool in thousandths (1e-3)
   * @param communityFee1 new community fee percent for token1 of the pool in thousandths (1e-3)
   */
  function setCommunityFee(uint8 communityFee0, uint8 communityFee1) external;

  /**
   * @notice Sets an active incentive
   * @param virtualPoolAddress The address of a virtual pool associated with the incentive
   */
  function setIncentive(address virtualPoolAddress) external;

  /**
   * @notice Sets new lock time for added liquidity
   * @param newLiquidityCooldown The time in seconds
   */
  function setLiquidityCooldown(uint32 newLiquidityCooldown) external;
}

File 38 of 83 : IAlgebraPoolEvents.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Events emitted by a pool
/// @dev Credit to Uniswap Labs under GPL-2.0-or-later license:
/// https://github.com/Uniswap/v3-core/tree/main/contracts/interfaces
interface IAlgebraPoolEvents {
  /**
   * @notice Emitted exactly once by a pool when #initialize is first called on the pool
   * @dev Mint/Burn/Swap cannot be emitted by the pool before Initialize
   * @param price The initial sqrt price of the pool, as a Q64.96
   * @param tick The initial tick of the pool, i.e. log base 1.0001 of the starting price of the pool
   */
  event Initialize(uint160 price, int24 tick);

  /**
   * @notice Emitted when liquidity is minted for a given position
   * @param sender The address that minted the liquidity
   * @param owner The owner of the position and recipient of any minted liquidity
   * @param bottomTick The lower tick of the position
   * @param topTick The upper tick of the position
   * @param liquidityAmount The amount of liquidity minted to the position range
   * @param amount0 How much token0 was required for the minted liquidity
   * @param amount1 How much token1 was required for the minted liquidity
   */
  event Mint(
    address sender,
    address indexed owner,
    int24 indexed bottomTick,
    int24 indexed topTick,
    uint128 liquidityAmount,
    uint256 amount0,
    uint256 amount1
  );

  /**
   * @notice Emitted when fees are collected by the owner of a position
   * @dev Collect events may be emitted with zero amount0 and amount1 when the caller chooses not to collect fees
   * @param owner The owner of the position for which fees are collected
   * @param recipient The address that received fees
   * @param bottomTick The lower tick of the position
   * @param topTick The upper tick of the position
   * @param amount0 The amount of token0 fees collected
   * @param amount1 The amount of token1 fees collected
   */
  event Collect(address indexed owner, address recipient, int24 indexed bottomTick, int24 indexed topTick, uint128 amount0, uint128 amount1);

  /**
   * @notice Emitted when a position's liquidity is removed
   * @dev Does not withdraw any fees earned by the liquidity position, which must be withdrawn via #collect
   * @param owner The owner of the position for which liquidity is removed
   * @param bottomTick The lower tick of the position
   * @param topTick The upper tick of the position
   * @param liquidityAmount The amount of liquidity to remove
   * @param amount0 The amount of token0 withdrawn
   * @param amount1 The amount of token1 withdrawn
   */
  event Burn(address indexed owner, int24 indexed bottomTick, int24 indexed topTick, uint128 liquidityAmount, uint256 amount0, uint256 amount1);

  /**
   * @notice Emitted by the pool for any swaps between token0 and token1
   * @param sender The address that initiated the swap call, and that received the callback
   * @param recipient The address that received the output of the swap
   * @param amount0 The delta of the token0 balance of the pool
   * @param amount1 The delta of the token1 balance of the pool
   * @param price The sqrt(price) of the pool after the swap, as a Q64.96
   * @param liquidity The liquidity of the pool after the swap
   * @param tick The log base 1.0001 of price of the pool after the swap
   */
  event Swap(address indexed sender, address indexed recipient, int256 amount0, int256 amount1, uint160 price, uint128 liquidity, int24 tick);

  /**
   * @notice Emitted by the pool for any flashes of token0/token1
   * @param sender The address that initiated the swap call, and that received the callback
   * @param recipient The address that received the tokens from flash
   * @param amount0 The amount of token0 that was flashed
   * @param amount1 The amount of token1 that was flashed
   * @param paid0 The amount of token0 paid for the flash, which can exceed the amount0 plus the fee
   * @param paid1 The amount of token1 paid for the flash, which can exceed the amount1 plus the fee
   */
  event Flash(address indexed sender, address indexed recipient, uint256 amount0, uint256 amount1, uint256 paid0, uint256 paid1);

  /**
   * @notice Emitted when the community fee is changed by the pool
   * @param communityFee0New The updated value of the token0 community fee percent
   * @param communityFee1New The updated value of the token1 community fee percent
   */
  event CommunityFee(uint8 communityFee0New, uint8 communityFee1New);

  /**
   * @notice Emitted when new activeIncentive is set
   * @param virtualPoolAddress The address of a virtual pool associated with the current active incentive
   */
  event Incentive(address indexed virtualPoolAddress);

  /**
   * @notice Emitted when the fee changes
   * @param fee The value of the token fee
   */
  event Fee(uint16 fee);

  /**
   * @notice Emitted when the LiquidityCooldown changes
   * @param liquidityCooldown The value of locktime for added liquidity
   */
  event LiquidityCooldown(uint32 liquidityCooldown);
}

File 39 of 83 : IDataStorageOperator.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
pragma abicoder v2;

import '../libraries/AdaptiveFee.sol';

interface IDataStorageOperator {
  event FeeConfiguration(AdaptiveFee.Configuration feeConfig);

  /**
   * @notice Returns data belonging to a certain timepoint
   * @param index The index of timepoint in the array
   * @dev There is more convenient function to fetch a timepoint: observe(). Which requires not an index but seconds
   * @return initialized Whether the timepoint has been initialized and the values are safe to use,
   * blockTimestamp The timestamp of the observation,
   * tickCumulative The tick multiplied by seconds elapsed for the life of the pool as of the timepoint timestamp,
   * secondsPerLiquidityCumulative The seconds per in range liquidity for the life of the pool as of the timepoint timestamp,
   * volatilityCumulative Cumulative standard deviation for the life of the pool as of the timepoint timestamp,
   * averageTick Time-weighted average tick,
   * volumePerLiquidityCumulative Cumulative swap volume per liquidity for the life of the pool as of the timepoint timestamp
   */
  function timepoints(uint256 index)
    external
    view
    returns (
      bool initialized,
      uint32 blockTimestamp,
      int56 tickCumulative,
      uint160 secondsPerLiquidityCumulative,
      uint88 volatilityCumulative,
      int24 averageTick,
      uint144 volumePerLiquidityCumulative
    );

  /// @notice Initialize the dataStorage array by writing the first slot. Called once for the lifecycle of the timepoints array
  /// @param time The time of the dataStorage initialization, via block.timestamp truncated to uint32
  /// @param tick Initial tick
  function initialize(uint32 time, int24 tick) external;

  /// @dev Reverts if an timepoint at or before the desired timepoint timestamp does not exist.
  /// 0 may be passed as `secondsAgo' to return the current cumulative values.
  /// If called with a timestamp falling between two timepoints, returns the counterfactual accumulator values
  /// at exactly the timestamp between the two timepoints.
  /// @param time The current block timestamp
  /// @param secondsAgo The amount of time to look back, in seconds, at which point to return an timepoint
  /// @param tick The current tick
  /// @param index The index of the timepoint that was most recently written to the timepoints array
  /// @param liquidity The current in-range pool liquidity
  /// @return tickCumulative The cumulative tick since the pool was first initialized, as of `secondsAgo`
  /// @return secondsPerLiquidityCumulative The cumulative seconds / max(1, liquidity) since the pool was first initialized, as of `secondsAgo`
  /// @return volatilityCumulative The cumulative volatility value since the pool was first initialized, as of `secondsAgo`
  /// @return volumePerAvgLiquidity The cumulative volume per liquidity value since the pool was first initialized, as of `secondsAgo`
  function getSingleTimepoint(
    uint32 time,
    uint32 secondsAgo,
    int24 tick,
    uint16 index,
    uint128 liquidity
  )
    external
    view
    returns (
      int56 tickCumulative,
      uint160 secondsPerLiquidityCumulative,
      uint112 volatilityCumulative,
      uint256 volumePerAvgLiquidity
    );

  /// @notice Returns the accumulator values as of each time seconds ago from the given time in the array of `secondsAgos`
  /// @dev Reverts if `secondsAgos` > oldest timepoint
  /// @param time The current block.timestamp
  /// @param secondsAgos Each amount of time to look back, in seconds, at which point to return an timepoint
  /// @param tick The current tick
  /// @param index The index of the timepoint that was most recently written to the timepoints array
  /// @param liquidity The current in-range pool liquidity
  /// @return tickCumulatives The cumulative tick since the pool was first initialized, as of each `secondsAgo`
  /// @return secondsPerLiquidityCumulatives The cumulative seconds / max(1, liquidity) since the pool was first initialized, as of each `secondsAgo`
  /// @return volatilityCumulatives The cumulative volatility values since the pool was first initialized, as of each `secondsAgo`
  /// @return volumePerAvgLiquiditys The cumulative volume per liquidity values since the pool was first initialized, as of each `secondsAgo`
  function getTimepoints(
    uint32 time,
    uint32[] memory secondsAgos,
    int24 tick,
    uint16 index,
    uint128 liquidity
  )
    external
    view
    returns (
      int56[] memory tickCumulatives,
      uint160[] memory secondsPerLiquidityCumulatives,
      uint112[] memory volatilityCumulatives,
      uint256[] memory volumePerAvgLiquiditys
    );

  /// @notice Returns average volatility in the range from time-WINDOW to time
  /// @param time The current block.timestamp
  /// @param tick The current tick
  /// @param index The index of the timepoint that was most recently written to the timepoints array
  /// @param liquidity The current in-range pool liquidity
  /// @return TWVolatilityAverage The average volatility in the recent range
  /// @return TWVolumePerLiqAverage The average volume per liquidity in the recent range
  function getAverages(
    uint32 time,
    int24 tick,
    uint16 index,
    uint128 liquidity
  ) external view returns (uint112 TWVolatilityAverage, uint256 TWVolumePerLiqAverage);

  /// @notice Writes an dataStorage timepoint to the array
  /// @dev Writable at most once per block. Index represents the most recently written element. index must be tracked externally.
  /// @param index The index of the timepoint that was most recently written to the timepoints array
  /// @param blockTimestamp The timestamp of the new timepoint
  /// @param tick The active tick at the time of the new timepoint
  /// @param liquidity The total in-range liquidity at the time of the new timepoint
  /// @param volumePerLiquidity The gmean(volumes)/liquidity at the time of the new timepoint
  /// @return indexUpdated The new index of the most recently written element in the dataStorage array
  function write(
    uint16 index,
    uint32 blockTimestamp,
    int24 tick,
    uint128 liquidity,
    uint128 volumePerLiquidity
  ) external returns (uint16 indexUpdated);

  /// @notice Changes fee configuration for the pool
  function changeFeeConfiguration(AdaptiveFee.Configuration calldata feeConfig) external;

  /// @notice Calculates gmean(volume/liquidity) for block
  /// @param liquidity The current in-range pool liquidity
  /// @param amount0 Total amount of swapped token0
  /// @param amount1 Total amount of swapped token1
  /// @return volumePerLiquidity gmean(volume/liquidity) capped by 100000 << 64
  function calculateVolumePerLiquidity(
    uint128 liquidity,
    int256 amount0,
    int256 amount1
  ) external pure returns (uint128 volumePerLiquidity);

  /// @return windowLength Length of window used to calculate averages
  function window() external view returns (uint32 windowLength);

  /// @notice Calculates fee based on combination of sigmoids
  /// @param time The current block.timestamp
  /// @param tick The current tick
  /// @param index The index of the timepoint that was most recently written to the timepoints array
  /// @param liquidity The current in-range pool liquidity
  /// @return fee The fee in hundredths of a bip, i.e. 1e-6
  function getFee(
    uint32 time,
    int24 tick,
    uint16 index,
    uint128 liquidity
  ) external view returns (uint16 fee);
}

File 40 of 83 : AdaptiveFee.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.7.6;

import './Constants.sol';

/// @title AdaptiveFee
/// @notice Calculates fee based on combination of sigmoids
library AdaptiveFee {
  // alpha1 + alpha2 + baseFee must be <= type(uint16).max
  struct Configuration {
    uint16 alpha1; // max value of the first sigmoid
    uint16 alpha2; // max value of the second sigmoid
    uint32 beta1; // shift along the x-axis for the first sigmoid
    uint32 beta2; // shift along the x-axis for the second sigmoid
    uint16 gamma1; // horizontal stretch factor for the first sigmoid
    uint16 gamma2; // horizontal stretch factor for the second sigmoid
    uint32 volumeBeta; // shift along the x-axis for the outer volume-sigmoid
    uint16 volumeGamma; // horizontal stretch factor the outer volume-sigmoid
    uint16 baseFee; // minimum possible fee
  }

  /// @notice Calculates fee based on formula:
  /// baseFee + sigmoidVolume(sigmoid1(volatility, volumePerLiquidity) + sigmoid2(volatility, volumePerLiquidity))
  /// maximum value capped by baseFee + alpha1 + alpha2
  function getFee(
    uint88 volatility,
    uint256 volumePerLiquidity,
    Configuration memory config
  ) internal pure returns (uint16 fee) {
    uint256 sumOfSigmoids = sigmoid(volatility, config.gamma1, config.alpha1, config.beta1) +
      sigmoid(volatility, config.gamma2, config.alpha2, config.beta2);

    if (sumOfSigmoids > type(uint16).max) {
      // should be impossible, just in case
      sumOfSigmoids = type(uint16).max;
    }

    return uint16(config.baseFee + sigmoid(volumePerLiquidity, config.volumeGamma, uint16(sumOfSigmoids), config.volumeBeta)); // safe since alpha1 + alpha2 + baseFee _must_ be <= type(uint16).max
  }

  /// @notice calculates α / (1 + e^( (β-x) / γ))
  /// that is a sigmoid with a maximum value of α, x-shifted by β, and stretched by γ
  /// @dev returns uint256 for fuzzy testing. Guaranteed that the result is not greater than alpha
  function sigmoid(
    uint256 x,
    uint16 g,
    uint16 alpha,
    uint256 beta
  ) internal pure returns (uint256 res) {
    if (x > beta) {
      x = x - beta;
      if (x >= 6 * uint256(g)) return alpha; // so x < 19 bits
      uint256 g8 = uint256(g)**8; // < 128 bits (8*16)
      uint256 ex = exp(x, g, g8); // < 155 bits
      res = (alpha * ex) / (g8 + ex); // in worst case: (16 + 155 bits) / 155 bits
      // so res <= alpha
    } else {
      x = beta - x;
      if (x >= 6 * uint256(g)) return 0; // so x < 19 bits
      uint256 g8 = uint256(g)**8; // < 128 bits (8*16)
      uint256 ex = g8 + exp(x, g, g8); // < 156 bits
      res = (alpha * g8) / ex; // in worst case: (16 + 128 bits) / 156 bits
      // g8 <= ex, so res <= alpha
    }
  }

  /// @notice calculates e^(x/g) * g^8 in a series, since (around zero):
  /// e^x = 1 + x + x^2/2 + ... + x^n/n! + ...
  /// e^(x/g) = 1 + x/g + x^2/(2*g^2) + ... + x^(n)/(g^n * n!) + ...
  function exp(
    uint256 x,
    uint16 g,
    uint256 gHighestDegree
  ) internal pure returns (uint256 res) {
    // calculating:
    // g**8 + x * g**7 + (x**2 * g**6) / 2 + (x**3 * g**5) / 6 + (x**4 * g**4) / 24 + (x**5 * g**3) / 120 + (x**6 * g^2) / 720 + x**7 * g / 5040 + x**8 / 40320

    // x**8 < 152 bits (19*8) and g**8 < 128 bits (8*16)
    // so each summand < 152 bits and res < 155 bits
    uint256 xLowestDegree = x;
    res = gHighestDegree; // g**8

    gHighestDegree /= g; // g**7
    res += xLowestDegree * gHighestDegree;

    gHighestDegree /= g; // g**6
    xLowestDegree *= x; // x**2
    res += (xLowestDegree * gHighestDegree) / 2;

    gHighestDegree /= g; // g**5
    xLowestDegree *= x; // x**3
    res += (xLowestDegree * gHighestDegree) / 6;

    gHighestDegree /= g; // g**4
    xLowestDegree *= x; // x**4
    res += (xLowestDegree * gHighestDegree) / 24;

    gHighestDegree /= g; // g**3
    xLowestDegree *= x; // x**5
    res += (xLowestDegree * gHighestDegree) / 120;

    gHighestDegree /= g; // g**2
    xLowestDegree *= x; // x**6
    res += (xLowestDegree * gHighestDegree) / 720;

    xLowestDegree *= x; // x**7
    res += (xLowestDegree * g) / 5040 + (xLowestDegree * x) / (40320);
  }
}

File 41 of 83 : Constants.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.7.6;

library Constants {
  uint8 internal constant RESOLUTION = 96;
  uint256 internal constant Q96 = 0x1000000000000000000000000;
  uint256 internal constant Q128 = 0x100000000000000000000000000000000;
  // fee value in hundredths of a bip, i.e. 1e-6
  uint16 internal constant BASE_FEE = 100;
  int24 internal constant TICK_SPACING = 60;

  // max(uint128) / ( (MAX_TICK - MIN_TICK) / TICK_SPACING )
  uint128 internal constant MAX_LIQUIDITY_PER_TICK = 11505743598341114571880798222544994;

  uint32 internal constant MAX_LIQUIDITY_COOLDOWN = 1 days;
  uint8 internal constant MAX_COMMUNITY_FEE = 250;
  uint256 internal constant COMMUNITY_FEE_DENOMINATOR = 1000;
}

File 42 of 83 : AlgebraFarming.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.7.6;
pragma abicoder v2;

import '../interfaces/IAlgebraFarming.sol';
import '../interfaces/IFarmingCenter.sol';
import './IAlgebraVirtualPoolBase.sol';
import '../libraries/IncentiveId.sol';
import '../libraries/NFTPositionInfo.sol';
import '../libraries/LiquidityTier.sol';

import 'algebra/contracts/interfaces/IAlgebraPoolDeployer.sol';
import 'algebra/contracts/interfaces/IAlgebraPool.sol';
import 'algebra/contracts/interfaces/IERC20Minimal.sol';
import 'algebra/contracts/libraries/SafeCast.sol';
import 'algebra/contracts/libraries/TickMath.sol';
import 'algebra/contracts/libraries/Constants.sol';
import 'algebra/contracts/libraries/LowGasSafeMath.sol';
import 'algebra/contracts/libraries/FullMath.sol';

import 'algebra-periphery/contracts/interfaces/INonfungiblePositionManager.sol';
import 'algebra-periphery/contracts/libraries/TransferHelper.sol';

/// @title Abstract base contract for Algebra farmings
abstract contract AlgebraFarming is IAlgebraFarming {
    using SafeCast for int256;
    using LowGasSafeMath for uint256;

    /// @notice Represents a farming incentive
    struct Incentive {
        uint256 totalReward;
        uint256 bonusReward;
        address virtualPoolAddress;
        uint24 minimalPositionWidth;
        uint224 totalLiquidity;
        address multiplierToken;
        Tiers tiers;
    }

    /// @inheritdoc IAlgebraFarming
    INonfungiblePositionManager public immutable override nonfungiblePositionManager;

    /// @inheritdoc IAlgebraFarming
    IAlgebraPoolDeployer public immutable override deployer;

    /// @inheritdoc IAlgebraFarming
    IFarmingCenter public override farmingCenter;

    /// @dev bytes32 refers to the return value of IncentiveId.compute
    /// @inheritdoc IAlgebraFarming
    mapping(bytes32 => Incentive) public override incentives;

    address internal incentiveMaker;
    address internal immutable owner;

    /// @dev rewards[owner][rewardToken] => uint256
    /// @inheritdoc IAlgebraFarming
    mapping(address => mapping(IERC20Minimal => uint256)) public override rewards;

    modifier onlyIncentiveMaker() {
        require(msg.sender == incentiveMaker);
        _;
    }

    modifier onlyOwner() {
        require(msg.sender == owner);
        _;
    }

    modifier onlyFarmingCenter() {
        require(msg.sender == address(farmingCenter));
        _;
    }

    /// @param _deployer pool deployer contract address
    /// @param _nonfungiblePositionManager the NFT position manager contract address
    constructor(IAlgebraPoolDeployer _deployer, INonfungiblePositionManager _nonfungiblePositionManager) {
        owner = msg.sender;
        deployer = _deployer;
        nonfungiblePositionManager = _nonfungiblePositionManager;
    }

    /// @inheritdoc IAlgebraFarming
    function setIncentiveMaker(address _incentiveMaker) external override onlyOwner {
        require(incentiveMaker != _incentiveMaker);
        incentiveMaker = _incentiveMaker;
        emit IncentiveMaker(_incentiveMaker);
    }

    /// @inheritdoc IAlgebraFarming
    function setFarmingCenterAddress(address _farmingCenter) external override onlyOwner {
        require(_farmingCenter != address(farmingCenter));
        farmingCenter = IFarmingCenter(_farmingCenter);
        emit FarmingCenter(_farmingCenter);
    }

    /// @inheritdoc IAlgebraFarming
    function claimReward(
        IERC20Minimal rewardToken,
        address to,
        uint256 amountRequested
    ) external override returns (uint256 reward) {
        return _claimReward(rewardToken, msg.sender, to, amountRequested);
    }

    /// @inheritdoc IAlgebraFarming
    function claimRewardFrom(
        IERC20Minimal rewardToken,
        address from,
        address to,
        uint256 amountRequested
    ) external override onlyFarmingCenter returns (uint256 reward) {
        return _claimReward(rewardToken, from, to, amountRequested);
    }

    function _connectPoolToVirtualPool(IAlgebraPool pool, address virtualPool) private {
        farmingCenter.connectVirtualPool(pool, virtualPool);
    }

    function _getCurrentVirtualPools(IAlgebraPool pool) internal view returns (address incentive, address eternal) {
        return farmingCenter.virtualPoolAddresses(address(pool));
    }

    function _receiveRewards(
        IncentiveKey memory key,
        uint256 reward,
        uint256 bonusReward,
        Incentive storage incentive
    ) internal returns (uint256 receivedReward, uint256 receivedBonusReward) {
        if (reward > 0) {
            IERC20Minimal rewardToken = key.rewardToken;
            uint256 balanceBefore = rewardToken.balanceOf(address(this));
            TransferHelper.safeTransferFrom(address(rewardToken), msg.sender, address(this), reward);
            require((receivedReward = rewardToken.balanceOf(address(this))) > balanceBefore);
            receivedReward -= balanceBefore;
            incentive.totalReward = incentive.totalReward.add(receivedReward);
        }
        if (bonusReward > 0) {
            IERC20Minimal bonusRewardToken = key.bonusRewardToken;
            uint256 balanceBefore = bonusRewardToken.balanceOf(address(this));
            TransferHelper.safeTransferFrom(address(bonusRewardToken), msg.sender, address(this), bonusReward);
            require((receivedBonusReward = bonusRewardToken.balanceOf(address(this))) > balanceBefore);
            receivedBonusReward -= balanceBefore;
            incentive.bonusReward = incentive.bonusReward.add(receivedBonusReward);
        }
    }

    function _createFarming(
        address virtualPool,
        IncentiveKey memory key,
        uint256 reward,
        uint256 bonusReward,
        uint24 minimalPositionWidth,
        address multiplierToken,
        Tiers calldata tiers
    )
        internal
        returns (
            bytes32 incentiveId,
            uint256 receivedReward,
            uint256 receivedBonusReward
        )
    {
        _connectPoolToVirtualPool(key.pool, virtualPool);

        incentiveId = IncentiveId.compute(key);

        Incentive storage newIncentive = incentives[incentiveId];

        (receivedReward, receivedBonusReward) = _receiveRewards(key, reward, bonusReward, newIncentive);

        require(
            minimalPositionWidth <=
                ((int256(TickMath.MAX_TICK) / Constants.TICK_SPACING) *
                    Constants.TICK_SPACING -
                    (int256(TickMath.MIN_TICK) / Constants.TICK_SPACING) *
                    Constants.TICK_SPACING),
            'minimalPositionWidth too wide'
        );
        newIncentive.virtualPoolAddress = virtualPool;
        newIncentive.minimalPositionWidth = minimalPositionWidth;

        require(
            tiers.tier1Multiplier <= LiquidityTier.MAX_MULTIPLIER &&
                tiers.tier2Multiplier <= LiquidityTier.MAX_MULTIPLIER &&
                tiers.tier3Multiplier <= LiquidityTier.MAX_MULTIPLIER,
            'Multiplier cant be greater than MAX_MULTIPLIER'
        );

        require(
            tiers.tier1Multiplier >= LiquidityTier.DENOMINATOR &&
                tiers.tier2Multiplier >= LiquidityTier.DENOMINATOR &&
                tiers.tier3Multiplier >= LiquidityTier.DENOMINATOR,
            'Multiplier cant be less than DENOMINATOR'
        );

        newIncentive.tiers = tiers;
        newIncentive.multiplierToken = multiplierToken;
    }

    function _detachIncentive(IncentiveKey memory key, address currentVirtualPool) internal {
        require(currentVirtualPool != address(0), 'Farming do not exist');

        require(
            incentives[IncentiveId.compute(key)].virtualPoolAddress == currentVirtualPool,
            'Another farming is active'
        );
        _connectPoolToVirtualPool(key.pool, address(0));

        emit IncentiveDetached(
            key.rewardToken,
            key.bonusRewardToken,
            key.pool,
            currentVirtualPool,
            key.startTime,
            key.endTime
        );
    }

    function _attachIncentive(IncentiveKey memory key, address currentVirtualPool) internal {
        require(currentVirtualPool == address(0), 'Farming already exists');

        address virtualPoolAddress = incentives[IncentiveId.compute(key)].virtualPoolAddress;
        require(virtualPoolAddress != address(0), 'Invalid farming');

        _connectPoolToVirtualPool(key.pool, virtualPoolAddress);

        emit IncentiveAttached(
            key.rewardToken,
            key.bonusRewardToken,
            key.pool,
            virtualPoolAddress,
            key.startTime,
            key.endTime
        );
    }

    function _enterFarming(
        IncentiveKey memory key,
        uint256 tokenId,
        uint256 tokensLocked
    )
        internal
        returns (
            bytes32 incentiveId,
            int24 tickLower,
            int24 tickUpper,
            uint128 liquidity,
            address virtualPool
        )
    {
        incentiveId = IncentiveId.compute(key);
        Incentive storage incentive = incentives[incentiveId];

        require(incentive.totalReward > 0, 'non-existent incentive');

        IAlgebraPool pool;
        (pool, tickLower, tickUpper, liquidity) = NFTPositionInfo.getPositionInfo(
            deployer,
            nonfungiblePositionManager,
            tokenId
        );

        require(pool == key.pool, 'invalid pool for token');
        require(liquidity > 0, 'cannot farm token with 0 liquidity');
        (, int24 tick, , , , , ) = pool.globalState();

        uint32 multiplier = LiquidityTier.getLiquidityMultiplier(tokensLocked, incentive.tiers);
        uint256 liquidityAmountWithMultiplier = FullMath.mulDiv(liquidity, multiplier, LiquidityTier.DENOMINATOR);
        require(liquidityAmountWithMultiplier <= type(uint128).max);
        liquidity = uint128(liquidityAmountWithMultiplier);

        virtualPool = incentive.virtualPoolAddress;
        uint24 minimalAllowedTickWidth = incentive.minimalPositionWidth;
        require(int256(tickUpper) - int256(tickLower) >= int256(minimalAllowedTickWidth), 'position too narrow');

        IAlgebraVirtualPoolBase(virtualPool).applyLiquidityDeltaToPosition(
            uint32(block.timestamp),
            tickLower,
            tickUpper,
            int256(liquidity).toInt128(),
            tick
        );
    }

    function _claimReward(
        IERC20Minimal rewardToken,
        address from,
        address to,
        uint256 amountRequested
    ) internal returns (uint256 reward) {
        reward = rewards[from][rewardToken];

        if (amountRequested == 0 || amountRequested > reward) {
            amountRequested = reward;
        }

        rewards[from][rewardToken] = reward - amountRequested;
        TransferHelper.safeTransfer(address(rewardToken), to, amountRequested);

        emit RewardClaimed(to, amountRequested, address(rewardToken), from);
    }
}

File 43 of 83 : IAlgebraFarming.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.7.6;
pragma abicoder v2;

import 'algebra/contracts/interfaces/IAlgebraPoolDeployer.sol';
import 'algebra/contracts/interfaces/IAlgebraPool.sol';
import 'algebra/contracts/interfaces/IERC20Minimal.sol';
import 'algebra-periphery/contracts/interfaces/INonfungiblePositionManager.sol';

import './IFarmingCenter.sol';
import './IIncentiveKey.sol';

/// @title Algebra Farming Interface
/// @notice Allows farming nonfungible liquidity tokens in exchange for reward tokens
interface IAlgebraFarming is IIncentiveKey {
    /// @notice The nonfungible position manager with which this farming contract is compatible
    function nonfungiblePositionManager() external view returns (INonfungiblePositionManager);

    /// @notice The farming Center
    function farmingCenter() external view returns (IFarmingCenter);

    /// @notice The pool deployer
    function deployer() external returns (IAlgebraPoolDeployer);

    /// @notice Updates the incentive maker
    /// @param _incentiveMaker The new incentive maker address
    function setIncentiveMaker(address _incentiveMaker) external;

    struct Tiers {
        // amount of token to reach the tier
        uint256 tokenAmountForTier1;
        uint256 tokenAmountForTier2;
        uint256 tokenAmountForTier3;
        // 1 = 0.01%
        uint32 tier1Multiplier;
        uint32 tier2Multiplier;
        uint32 tier3Multiplier;
    }

    /// @notice Represents a farming incentive
    /// @param incentiveId The ID of the incentive computed from its parameters
    function incentives(bytes32 incentiveId)
        external
        view
        returns (
            uint256 totalReward,
            uint256 bonusReward,
            address virtualPoolAddress,
            uint24 minimalPositionWidth,
            uint224 totalLiquidity,
            address multiplierToken,
            Tiers memory tiers
        );

    /// @notice Detach incentive from the pool
    /// @param key The key of the incentive
    function detachIncentive(IncentiveKey memory key) external;

    /// @notice Attach incentive to the pool
    /// @param key The key of the incentive
    function attachIncentive(IncentiveKey memory key) external;

    /// @notice Returns amounts of reward tokens owed to a given address according to the last time all farms were updated
    /// @param owner The owner for which the rewards owed are checked
    /// @param rewardToken The token for which to check rewards
    /// @return rewardsOwed The amount of the reward token claimable by the owner
    function rewards(address owner, IERC20Minimal rewardToken) external view returns (uint256 rewardsOwed);

    /// @notice Updates farming center address
    /// @param _farmingCenter The new farming center contract address
    function setFarmingCenterAddress(address _farmingCenter) external;

    /// @notice enter farming for Algebra LP token
    /// @param key The key of the incentive for which to enterFarming the NFT
    /// @param tokenId The ID of the token to exitFarming
    /// @param tokensLocked The amount of tokens locked for boost
    function enterFarming(
        IncentiveKey memory key,
        uint256 tokenId,
        uint256 tokensLocked
    ) external;

    /// @notice exitFarmings for Algebra LP token
    /// @param key The key of the incentive for which to exitFarming the NFT
    /// @param tokenId The ID of the token to exitFarming
    /// @param _owner Owner of the token
    function exitFarming(
        IncentiveKey memory key,
        uint256 tokenId,
        address _owner
    ) external;

    /// @notice Transfers `amountRequested` of accrued `rewardToken` rewards from the contract to the recipient `to`
    /// @param rewardToken The token being distributed as a reward
    /// @param to The address where claimed rewards will be sent to
    /// @param amountRequested The amount of reward tokens to claim. Claims entire reward amount if set to 0.
    /// @return reward The amount of reward tokens claimed
    function claimReward(
        IERC20Minimal rewardToken,
        address to,
        uint256 amountRequested
    ) external returns (uint256 reward);

    /// @notice Transfers `amountRequested` of accrued `rewardToken` rewards from the contract to the recipient `to`
    /// @notice only for FarmingCenter
    /// @param rewardToken The token being distributed as a reward
    /// @param from The address of position owner
    /// @param to The address where claimed rewards will be sent to
    /// @param amountRequested The amount of reward tokens to claim. Claims entire reward amount if set to 0.
    /// @return reward The amount of reward tokens claimed
    function claimRewardFrom(
        IERC20Minimal rewardToken,
        address from,
        address to,
        uint256 amountRequested
    ) external returns (uint256 reward);

    /// @notice Calculates the reward amount that will be received for the given farm
    /// @param key The key of the incentive
    /// @param tokenId The ID of the token
    /// @return reward The reward accrued to the NFT for the given incentive thus far
    /// @return bonusReward The bonus reward accrued to the NFT for the given incentive thus far
    function getRewardInfo(IncentiveKey memory key, uint256 tokenId)
        external
        returns (uint256 reward, uint256 bonusReward);

    /// @notice Event emitted when a liquidity mining incentive has been stopped from the outside
    /// @param rewardToken The token being distributed as a reward
    /// @param bonusRewardToken The token being distributed as a bonus reward
    /// @param pool The Algebra pool
    /// @param virtualPool The detached virtual pool address
    /// @param startTime The time when the incentive program begins
    /// @param endTime The time when rewards stop accruing
    event IncentiveDetached(
        IERC20Minimal indexed rewardToken,
        IERC20Minimal indexed bonusRewardToken,
        IAlgebraPool indexed pool,
        address virtualPool,
        uint256 startTime,
        uint256 endTime
    );

    /// @notice Event emitted when a liquidity mining incentive has been runned again from the outside
    /// @param rewardToken The token being distributed as a reward
    /// @param bonusRewardToken The token being distributed as a bonus reward
    /// @param pool The Algebra pool
    /// @param virtualPool The attached virtual pool address
    /// @param startTime The time when the incentive program begins
    /// @param endTime The time when rewards stop accruing
    event IncentiveAttached(
        IERC20Minimal indexed rewardToken,
        IERC20Minimal indexed bonusRewardToken,
        IAlgebraPool indexed pool,
        address virtualPool,
        uint256 startTime,
        uint256 endTime
    );

    /// @notice Event emitted when a Algebra LP token has been farmd
    /// @param tokenId The unique identifier of an Algebra LP token
    /// @param incentiveId The incentive in which the token is farming
    /// @param liquidity The amount of liquidity farmd
    /// @param tokensLocked The amount of tokens locked for multiplier
    event FarmEntered(uint256 indexed tokenId, bytes32 indexed incentiveId, uint128 liquidity, uint256 tokensLocked);

    /// @notice Event emitted when a Algebra LP token has been exitFarmingd
    /// @param tokenId The unique identifier of an Algebra LP token
    /// @param incentiveId The incentive in which the token is farming
    /// @param rewardAddress The token being distributed as a reward
    /// @param bonusRewardToken The token being distributed as a bonus reward
    /// @param owner The address where claimed rewards were sent to
    /// @param reward The amount of reward tokens to be distributed
    /// @param bonusReward The amount of bonus reward tokens to be distributed
    event FarmEnded(
        uint256 indexed tokenId,
        bytes32 indexed incentiveId,
        address indexed rewardAddress,
        address bonusRewardToken,
        address owner,
        uint256 reward,
        uint256 bonusReward
    );

    /// @notice Emitted when the incentive maker is changed
    /// @param incentiveMaker The incentive maker after the address was changed
    event IncentiveMaker(address indexed incentiveMaker);

    /// @notice Emitted when the farming center is changed
    /// @param farmingCenter The farming center after the address was changed
    event FarmingCenter(address indexed farmingCenter);

    /// @notice Event emitted when rewards were added
    /// @param rewardAmount The additional amount of main token
    /// @param bonusRewardAmount The additional amount of bonus token
    /// @param incentiveId The ID of the incentive for which rewards were added
    event RewardsAdded(uint256 rewardAmount, uint256 bonusRewardAmount, bytes32 incentiveId);

    /// @notice Event emitted when a reward token has been claimed
    /// @param to The address where claimed rewards were sent to
    /// @param reward The amount of reward tokens claimed
    /// @param rewardAddress The token reward address
    /// @param owner The address where claimed rewards were sent to
    event RewardClaimed(address indexed to, uint256 reward, address indexed rewardAddress, address indexed owner);
}

File 44 of 83 : IFarmingCenter.sol
// SPDX-License-Identifier: MIT
pragma solidity =0.7.6;
pragma abicoder v2;

import 'algebra/contracts/interfaces/IAlgebraPool.sol';
import 'algebra/contracts/interfaces/IAlgebraVirtualPool.sol';
import 'algebra/contracts/interfaces/IERC20Minimal.sol';

import 'algebra-periphery/contracts/interfaces/IMulticall.sol';
import 'algebra-periphery/contracts/interfaces/INonfungiblePositionManager.sol';

import 'algebra-periphery/contracts/interfaces/IPeripheryPayments.sol';

import '@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol';

import '../farmings/limitFarming/interfaces/IAlgebraLimitFarming.sol';
import '../farmings/eternalFarming/interfaces/IAlgebraEternalFarming.sol';
import './IFarmingCenterVault.sol';
import './IIncentiveKey.sol';

interface IFarmingCenter is
    IAlgebraVirtualPool,
    IERC721Receiver,
    IIncentiveKey,
    IMulticall,
    IERC721Permit,
    IPeripheryPayments
{
    struct VirtualPoolAddresses {
        address eternalVirtualPool;
        address limitVirtualPool;
    }

    function virtualPoolAddresses(address) external view returns (address, address);

    /// @notice The nonfungible position manager with which this farming contract is compatible
    function nonfungiblePositionManager() external view returns (INonfungiblePositionManager);

    function limitFarming() external view returns (IAlgebraLimitFarming);

    function eternalFarming() external view returns (IAlgebraEternalFarming);

    function farmingCenterVault() external view returns (IFarmingCenterVault);

    function l2Nfts(uint256)
        external
        view
        returns (
            uint96 nonce,
            address operator,
            uint256 tokenId
        );

    /// @notice Returns information about a deposited NFT
    /// @param tokenId The ID of the deposit (and token) that is being transferred
    /// @return L2TokenId The nft layer2 id,
    /// numberOfFarms The number of farms,
    /// inLimitFarming The parameter showing if the token is in the limit farm,
    /// owner The owner of deposit
    function deposits(uint256 tokenId)
        external
        view
        returns (
            uint256 L2TokenId,
            uint32 numberOfFarms,
            bool inLimitFarming,
            address owner
        );

    /// @notice Updates activeIncentive in AlgebraPool
    /// @dev only farming can do it
    /// @param pool The AlgebraPool for which farming was created
    /// @param virtualPool The virtual pool to be connected
    function connectVirtualPool(IAlgebraPool pool, address virtualPool) external;

    /// @notice Enters in incentive (time-limited or eternal farming) with NFT-position token
    /// @dev token must be deposited in FarmingCenter
    /// @param key The incentive event key
    /// @param tokenId The id of position NFT
    /// @param tokensLocked Amount of tokens to lock for liquidity multiplier (if tiers are used)
    /// @param isLimit Is incentive time-limited or eternal
    function enterFarming(
        IncentiveKey memory key,
        uint256 tokenId,
        uint256 tokensLocked,
        bool isLimit
    ) external;

    /// @notice Exits from incentive (time-limited or eternal farming) with NFT-position token
    /// @param key The incentive event key
    /// @param tokenId The id of position NFT
    /// @param isLimit Is incentive time-limited or eternal
    function exitFarming(
        IncentiveKey memory key,
        uint256 tokenId,
        bool isLimit
    ) external;

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

    /// @notice Used to collect reward from eternal farming. Then reward can be claimed.
    /// @param key The incentive event key
    /// @param tokenId The id of position NFT
    /// @return reward The amount of collected reward
    /// @return bonusReward The amount of collected  bonus reward
    function collectRewards(IncentiveKey memory key, uint256 tokenId)
        external
        returns (uint256 reward, uint256 bonusReward);

    /// @notice Used to claim and send rewards from farming(s)
    /// @dev can be used via static call to get current rewards for user
    /// @param rewardToken The token that is a reward
    /// @param to The address to be rewarded
    /// @param amountRequestedIncentive Amount to claim in incentive (limit) farming
    /// @param amountRequestedEternal Amount to claim in eternal farming
    /// @return reward The summary amount of claimed rewards
    function claimReward(
        IERC20Minimal rewardToken,
        address to,
        uint256 amountRequestedIncentive,
        uint256 amountRequestedEternal
    ) external returns (uint256 reward);

    /// @notice Withdraw Algebra NFT-position token
    /// @dev can be used via static call to get current rewards for user
    /// @param tokenId The id of position NFT
    /// @param to New owner of position NFT
    /// @param data The additional data for NonfungiblePositionManager
    function withdrawToken(
        uint256 tokenId,
        address to,
        bytes memory data
    ) external;

    /// @notice Emitted when ownership of a deposit changes
    /// @param tokenId The ID of the deposit (and token) that is being transferred
    /// @param oldOwner The owner before the deposit was transferred
    /// @param newOwner The owner after the deposit was transferred
    event DepositTransferred(uint256 indexed tokenId, address indexed oldOwner, address indexed newOwner);
}

File 45 of 83 : IAlgebraVirtualPoolBase.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.7.6;
pragma abicoder v2;

import 'algebra/contracts/interfaces/IAlgebraVirtualPool.sol';

/// @title Base interface for virtual pools
interface IAlgebraVirtualPoolBase is IAlgebraVirtualPool {
    // returns how much time the price was out of any farmd liquidity
    function timeOutside() external view returns (uint32);

    // returns data associated with a tick
    function ticks(int24 tickId)
        external
        view
        returns (
            uint128 liquidityTotal,
            int128 liquidityDelta,
            uint256 outerFeeGrowth0Token,
            uint256 outerFeeGrowth1Token,
            int56 outerTickCumulative,
            uint160 outerSecondsPerLiquidity,
            uint32 outerSecondsSpent,
            bool initialized
        );

    // returns the current liquidity in virtual pool
    function currentLiquidity() external view returns (uint128);

    // returns the current tick in virtual pool
    function globalTick() external view returns (int24);

    // returns total seconds per farmd liquidity from the moment of initialization of the virtual pool
    function globalSecondsPerLiquidityCumulative() external view returns (uint160);

    // returns the timestamp after previous swap (like the last timepoint in a default pool)
    function prevTimestamp() external view returns (uint32);

    /// @notice This function is used to calculate the seconds per liquidity inside a certain position
    /// @param bottomTick The bottom tick of a position
    /// @param topTick The top tick of a position
    /// @return innerSecondsSpentPerLiquidity The seconds per liquidity inside the position
    function getInnerSecondsPerLiquidity(int24 bottomTick, int24 topTick)
        external
        view
        returns (uint160 innerSecondsSpentPerLiquidity);

    /**
     * @dev This function is called when anyone farms their liquidity. The position in a virtual pool
     * should be changed accordingly
     * @param currentTimestamp The timestamp of current block
     * @param bottomTick The bottom tick of a position
     * @param topTick The top tick of a position
     * @param liquidityDelta The amount of liquidity in a position
     * @param currentTick The current tick in the main pool
     */
    function applyLiquidityDeltaToPosition(
        uint32 currentTimestamp,
        int24 bottomTick,
        int24 topTick,
        int128 liquidityDelta,
        int24 currentTick
    ) external;
}

File 46 of 83 : IncentiveId.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.7.6;
pragma abicoder v2;

import '../interfaces/IIncentiveKey.sol';

library IncentiveId {
    /// @notice Calculate the key for a staking incentive
    /// @param key The components used to compute the incentive identifier
    /// @return incentiveId The identifier for the incentive
    function compute(IIncentiveKey.IncentiveKey memory key) internal pure returns (bytes32 incentiveId) {
        return keccak256(abi.encode(key));
    }
}

File 47 of 83 : LiquidityTier.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.7.6;

import '../interfaces/IAlgebraFarming.sol';

/// @title Functions for liquidity attraction programs with liquidity multipliers
/// @notice Allows computing liquidity multiplier based on locked tokens amount
library LiquidityTier {
    uint32 constant DENOMINATOR = 10000;
    uint32 constant MAX_MULTIPLIER = 50000;

    /// @notice Get the multiplier by tokens locked amount
    /// @param tokenAmount The amount of locked tokens
    /// @param tiers The structure showing the dependence of the multiplier on the amount of locked tokens
    /// @return multiplier The value represent percent of liquidity in ten thousands(1 = 0.01%)
    function getLiquidityMultiplier(uint256 tokenAmount, IAlgebraFarming.Tiers memory tiers)
        internal
        pure
        returns (uint32 multiplier)
    {
        if (tokenAmount >= tiers.tokenAmountForTier3) {
            return tiers.tier3Multiplier;
        } else if (tokenAmount >= tiers.tokenAmountForTier2) {
            return tiers.tier2Multiplier;
        } else if (tokenAmount >= tiers.tokenAmountForTier1) {
            return tiers.tier1Multiplier;
        } else {
            return DENOMINATOR;
        }
    }
}

File 48 of 83 : SafeCast.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Safe casting methods
/// @notice Contains methods for safely casting between types
/// @dev Credit to Uniswap Labs under GPL-2.0-or-later license:
/// https://github.com/Uniswap/v3-core/blob/main/contracts/libraries
library SafeCast {
  /// @notice Cast a uint256 to a uint160, revert on overflow
  /// @param y The uint256 to be downcasted
  /// @return z The downcasted integer, now type uint160
  function toUint160(uint256 y) internal pure returns (uint160 z) {
    require((z = uint160(y)) == y);
  }

  /// @notice Cast a int256 to a int128, revert on overflow or underflow
  /// @param y The int256 to be downcasted
  /// @return z The downcasted integer, now type int128
  function toInt128(int256 y) internal pure returns (int128 z) {
    require((z = int128(y)) == y);
  }

  /// @notice Cast a uint256 to a int256, revert on overflow
  /// @param y The uint256 to be casted
  /// @return z The casted integer, now type int256
  function toInt256(uint256 y) internal pure returns (int256 z) {
    require(y < 2**255);
    z = int256(y);
  }
}

File 49 of 83 : TickMath.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.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
/// @dev Credit to Uniswap Labs under GPL-2.0-or-later license:
/// https://github.com/Uniswap/v3-core/blob/main/contracts/libraries
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 price 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 price) {
    // get abs value
    int24 mask = tick >> (24 - 1);
    uint256 absTick = uint256((tick ^ mask) - mask);
    require(absTick <= uint256(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
    price = uint160((ratio >> 32) + (ratio % (1 << 32) == 0 ? 0 : 1));
  }

  /// @notice Calculates the greatest tick value such that getRatioAtTick(tick) <= ratio
  /// @dev Throws in case price < MIN_SQRT_RATIO, as MIN_SQRT_RATIO is the lowest value getRatioAtTick may
  /// ever return.
  /// @param price 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 price) internal pure returns (int24 tick) {
    // second inequality must be < because the price can never reach the price at the max tick
    require(price >= MIN_SQRT_RATIO && price < MAX_SQRT_RATIO, 'R');
    uint256 ratio = uint256(price) << 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) <= price ? tickHi : tickLow;
  }
}

File 50 of 83 : LowGasSafeMath.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.0;

/// @title Optimized overflow and underflow safe math operations
/// @notice Contains methods for doing math operations that revert on overflow or underflow for minimal gas cost
/// @dev Credit to Uniswap Labs under GPL-2.0-or-later license:
/// https://github.com/Uniswap/v3-core/blob/main/contracts/libraries
library LowGasSafeMath {
  /// @notice Returns x + y, reverts if sum overflows uint256
  /// @param x The augend
  /// @param y The addend
  /// @return z The sum of x and y
  function add(uint256 x, uint256 y) internal pure returns (uint256 z) {
    require((z = x + y) >= x);
  }

  /// @notice Returns x - y, reverts if underflows
  /// @param x The minuend
  /// @param y The subtrahend
  /// @return z The difference of x and y
  function sub(uint256 x, uint256 y) internal pure returns (uint256 z) {
    require((z = x - y) <= x);
  }

  /// @notice Returns x * y, reverts if overflows
  /// @param x The multiplicand
  /// @param y The multiplier
  /// @return z The product of x and y
  function mul(uint256 x, uint256 y) internal pure returns (uint256 z) {
    require(x == 0 || (z = x * y) / x == y);
  }

  /// @notice Returns x + y, reverts if overflows or underflows
  /// @param x The augend
  /// @param y The addend
  /// @return z The sum of x and y
  function add(int256 x, int256 y) internal pure returns (int256 z) {
    require((z = x + y) >= x == (y >= 0));
  }

  /// @notice Returns x - y, reverts if overflows or underflows
  /// @param x The minuend
  /// @param y The subtrahend
  /// @return z The difference of x and y
  function sub(int256 x, int256 y) internal pure returns (int256 z) {
    require((z = x - y) <= x == (y >= 0));
  }

  /// @notice Returns x + y, reverts if overflows or underflows
  /// @param x The augend
  /// @param y The addend
  /// @return z The sum of x and y
  function add128(uint128 x, uint128 y) internal pure returns (uint128 z) {
    require((z = x + y) >= x);
  }
}

File 51 of 83 : FullMath.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.4.0 || ^0.5.0 || ^0.6.0 || ^0.7.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) {
    // 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 = a * b; // Least significant 256 bits of the product
    uint256 prod1; // Most significant 256 bits of the product
    assembly {
      let mm := mulmod(a, b, not(0))
      prod1 := sub(sub(mm, prod0), lt(mm, prod0))
    }

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

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

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

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

    // Factor powers of two out of denominator
    // Compute largest power of two divisor of denominator.
    // Always >= 1.
    uint256 twos = -denominator & denominator;
    // Divide denominator by power of two
    assembly {
      denominator := div(denominator, twos)
    }

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

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

    // Because the division is now exact we can divide by multiplying
    // with the modular inverse of denominator. This will give us the
    // correct result modulo 2**256. Since the preconditions 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) {
    if (a == 0 || ((result = a * b) / a == b)) {
      require(denominator > 0);
      assembly {
        result := add(div(result, denominator), gt(mod(result, denominator), 0))
      }
    } else {
      result = mulDiv(a, b, denominator);
      if (mulmod(a, b, denominator) > 0) {
        require(result < type(uint256).max);
        result++;
      }
    }
  }

  /// @notice Returns ceil(x / y)
  /// @dev division by 0 has unspecified behavior, and must be checked externally
  /// @param x The dividend
  /// @param y The divisor
  /// @return z The quotient, ceil(x / y)
  function divRoundingUp(uint256 x, uint256 y) internal pure returns (uint256 z) {
    assembly {
      z := add(div(x, y), gt(mod(x, y), 0))
    }
  }
}

File 52 of 83 : TransferHelper.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.6.0;

import '@openzeppelin/contracts/token/ERC20/IERC20.sol';

/// @dev Credit to Uniswap Labs under GPL-2.0-or-later license:
/// https://github.com/Uniswap/v3-periphery
library TransferHelper {
    /// @notice Transfers tokens from the targeted address to the given destination
    /// @notice Errors with 'STF' if transfer fails
    /// @param token The contract address of the token to be transferred
    /// @param from The originating address from which the tokens will be transferred
    /// @param to The destination address of the transfer
    /// @param value The amount to be transferred
    function safeTransferFrom(
        address token,
        address from,
        address to,
        uint256 value
    ) internal {
        (bool success, bytes memory data) = token.call(
            abi.encodeWithSelector(IERC20.transferFrom.selector, from, to, value)
        );
        require(success && (data.length == 0 || abi.decode(data, (bool))), 'STF');
    }

    /// @notice Transfers tokens from msg.sender to a recipient
    /// @dev Errors with ST if transfer fails
    /// @param token The contract address of the token which will be transferred
    /// @param to The recipient of the transfer
    /// @param value The value of the transfer
    function safeTransfer(
        address token,
        address to,
        uint256 value
    ) internal {
        (bool success, bytes memory data) = token.call(abi.encodeWithSelector(IERC20.transfer.selector, to, value));
        require(success && (data.length == 0 || abi.decode(data, (bool))), 'ST');
    }

    /// @notice Approves the stipulated contract to spend the given allowance in the given token
    /// @dev Errors with 'SA' if transfer fails
    /// @param token The contract address of the token to be approved
    /// @param to The target of the approval
    /// @param value The amount of the given token the target will be allowed to spend
    function safeApprove(
        address token,
        address to,
        uint256 value
    ) internal {
        (bool success, bytes memory data) = token.call(abi.encodeWithSelector(IERC20.approve.selector, to, value));
        require(success && (data.length == 0 || abi.decode(data, (bool))), 'SA');
    }

    /// @notice Transfers NativeToken to the recipient address
    /// @dev Fails with `STE`
    /// @param to The destination of the transfer
    /// @param value The value to be transferred
    function safeTransferNative(address to, uint256 value) internal {
        (bool success, ) = to.call{value: value}(new bytes(0));
        require(success, 'STE');
    }
}

File 53 of 83 : IIncentiveKey.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.7.6;

import 'algebra/contracts/interfaces/IERC20Minimal.sol';
import 'algebra/contracts/interfaces/IAlgebraPool.sol';

interface IIncentiveKey {
    /// @param rewardToken The token being distributed as a reward
    /// @param bonusRewardToken The bonus token being distributed as a reward
    /// @param pool The Algebra pool
    /// @param startTime The time when the incentive program begins
    /// @param endTime The time when rewards stop accruing
    struct IncentiveKey {
        IERC20Minimal rewardToken;
        IERC20Minimal bonusRewardToken;
        IAlgebraPool pool;
        uint256 startTime;
        uint256 endTime;
    }
}

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

interface IAlgebraVirtualPool {
  enum Status {
    NOT_EXIST,
    ACTIVE,
    NOT_STARTED
  }

  /**
   * @dev This function is called by the main pool when an initialized tick is crossed there.
   * If the tick is also initialized in a virtual pool it should be crossed too
   * @param nextTick The crossed tick
   * @param zeroToOne The direction
   */
  function cross(int24 nextTick, bool zeroToOne) external;

  /**
   * @dev This function is called from the main pool before every swap To increase seconds per liquidity
   * cumulative considering previous timestamp and liquidity. The liquidity is stored in a virtual pool
   * @param currentTimestamp The timestamp of the current swap
   * @return Status The status of virtual pool
   */
  function increaseCumulative(uint32 currentTimestamp) external returns (Status);
}

File 55 of 83 : IMulticall.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;
pragma abicoder v2;

/// @title Multicall interface
/// @notice Enables calling multiple methods in a single call to the contract
interface IMulticall {
    /// @notice Call multiple functions in the current contract and return the data from all of them if they all succeed
    /// @dev The `msg.value` should not be trusted for any method callable from multicall.
    /// @param data The encoded function data for each of the calls to make to this contract
    /// @return results The results from each of the calls passed in via data
    function multicall(bytes[] calldata data) external payable returns (bytes[] memory results);
}

File 56 of 83 : IAlgebraLimitFarming.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.7.6;
pragma abicoder v2;

import '../../../interfaces/IAlgebraFarming.sol';

/// @title Algebra Farming Interface
/// @notice Allows farming nonfungible liquidity tokens in exchange for reward tokens
interface IAlgebraLimitFarming is IAlgebraFarming {
    struct IncentiveParams {
        uint256 reward; // The amount of reward tokens to be distributed
        uint256 bonusReward; // The amount of bonus reward tokens to be distributed
        uint24 minimalPositionWidth; // The minimal allowed width of position (tickUpper - tickLower)
        address multiplierToken; // The address of token which can be locked to get liquidity multiplier
        uint32 enterStartTime; // The time when enter should become possible
    }

    /// @notice The max duration of an incentive in seconds
    function maxIncentiveDuration() external view returns (uint256);

    /// @notice The max amount of seconds into the future the incentive startTime can be set
    function maxIncentiveStartLeadTime() external view returns (uint256);

    /// @notice Returns information about a farmd liquidity NFT
    /// @param tokenId The ID of the farmd token
    /// @param incentiveId The ID of the incentive for which the token is farmd
    /// @return liquidity The amount of liquidity in the NFT as of the last time the rewards were computed,
    /// tickLower The lower end of the tick range for the position,
    /// tickUpper The upper end of the tick range for the position
    function farms(uint256 tokenId, bytes32 incentiveId)
        external
        view
        returns (
            uint128 liquidity,
            int24 tickLower,
            int24 tickUpper
        );

    function createLimitFarming(
        IncentiveKey memory key,
        Tiers calldata tiers,
        IncentiveParams memory params
    ) external returns (address virtualPool);

    function addRewards(
        IncentiveKey memory key,
        uint256 reward,
        uint256 bonusReward
    ) external;

    function decreaseRewardsAmount(
        IncentiveKey memory key,
        uint256 rewardAmount,
        uint256 bonusRewardAmount
    ) external;

    /// @notice Event emitted when a liquidity mining incentive has been created
    /// @param rewardToken The token being distributed as a reward
    /// @param bonusRewardToken The token being distributed as a bonus reward
    /// @param pool The Algebra pool
    /// @param startTime The time when the incentive program begins
    /// @param endTime The time when rewards stop accruing
    /// @param reward The amount of reward tokens to be distributed
    /// @param bonusReward The amount of bonus reward tokens to be distributed
    /// @param tiers The amounts of locked token for liquidity multipliers
    /// @param multiplierToken The address of token which can be locked to get liquidity multiplier
    /// @param minimalAllowedPositionWidth The minimal allowed position width (tickUpper - tickLower)
    /// @param enterStartTime The time when enter becomes possible
    event LimitFarmingCreated(
        IERC20Minimal indexed rewardToken,
        IERC20Minimal indexed bonusRewardToken,
        IAlgebraPool indexed pool,
        uint256 startTime,
        uint256 endTime,
        uint256 reward,
        uint256 bonusReward,
        Tiers tiers,
        address multiplierToken,
        uint24 minimalAllowedPositionWidth,
        uint32 enterStartTime
    );

    event RewardAmountsDecreased(uint256 reward, uint256 bonusReward, bytes32 incentiveId);
}

File 57 of 83 : IAlgebraEternalFarming.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.7.6;
pragma abicoder v2;
import '../../../interfaces/IAlgebraFarming.sol';

/// @title Algebra Eternal Farming Interface
/// @notice Allows farming nonfungible liquidity tokens in exchange for reward tokens without locking NFT for incentive time
interface IAlgebraEternalFarming is IAlgebraFarming {
    struct IncentiveParams {
        uint256 reward; // The amount of reward tokens to be distributed
        uint256 bonusReward; // The amount of bonus reward tokens to be distributed
        uint128 rewardRate; // The rate of reward distribution per second
        uint128 bonusRewardRate; // The rate of bonus reward distribution per second
        uint24 minimalPositionWidth; // The minimal allowed width of position (tickUpper - tickLower)
        address multiplierToken; // The address of token which can be locked to get liquidity multiplier
    }

    /// @notice Event emitted when reward rates were changed
    /// @param rewardRate The new rate of main token distribution per sec
    /// @param bonusRewardRate The new rate of bonus token distribution per sec
    /// @param incentiveId The ID of the incentive for which rates were changed
    event RewardsRatesChanged(uint128 rewardRate, uint128 bonusRewardRate, bytes32 incentiveId);

    /// @notice Event emitted when rewards were added
    /// @param tokenId The ID of the token for which rewards were collected
    /// @param incentiveId The ID of the incentive for which rewards were collected
    /// @param rewardAmount Collected amount of reward
    /// @param bonusRewardAmount Collected amount of bonus reward
    event RewardsCollected(uint256 tokenId, bytes32 incentiveId, uint256 rewardAmount, uint256 bonusRewardAmount);

    /// @notice Returns information about a farmd liquidity NFT
    /// @param tokenId The ID of the farmd token
    /// @param incentiveId The ID of the incentive for which the token is farmd
    /// @return liquidity The amount of liquidity in the NFT as of the last time the rewards were computed,
    /// tickLower The lower tick of position,
    /// tickUpper The upper tick of position,
    /// innerRewardGrowth0 The last saved reward0 growth inside position,
    /// innerRewardGrowth1 The last saved reward1 growth inside position
    function farms(uint256 tokenId, bytes32 incentiveId)
        external
        view
        returns (
            uint128 liquidity,
            int24 tickLower,
            int24 tickUpper,
            uint256 innerRewardGrowth0,
            uint256 innerRewardGrowth1
        );

    /// @notice Creates a new liquidity mining incentive program
    /// @param key Details of the incentive to create
    /// @param params Params of incentive
    /// @param tiers The amounts of locked token for liquidity multipliers
    /// @return virtualPool The virtual pool
    function createEternalFarming(
        IncentiveKey memory key,
        IncentiveParams memory params,
        Tiers calldata tiers
    ) external returns (address virtualPool);

    function addRewards(
        IncentiveKey memory key,
        uint256 rewardAmount,
        uint256 bonusRewardAmount
    ) external;

    function setRates(
        IncentiveKey memory key,
        uint128 rewardRate,
        uint128 bonusRewardRate
    ) external;

    function collectRewards(
        IncentiveKey memory key,
        uint256 tokenId,
        address _owner
    ) external returns (uint256 reward, uint256 bonusReward);

    /// @notice Event emitted when a liquidity mining incentive has been created
    /// @param rewardToken The token being distributed as a reward
    /// @param bonusRewardToken The token being distributed as a bonus reward
    /// @param pool The Algebra pool
    /// @param virtualPool The virtual pool address
    /// @param startTime The time when the incentive program begins
    /// @param endTime The time when rewards stop accruing
    /// @param reward The amount of reward tokens to be distributed
    /// @param bonusReward The amount of bonus reward tokens to be distributed
    /// @param tiers The amounts of locked token for liquidity multipliers
    /// @param multiplierToken The address of token which can be locked to get liquidity multiplier
    /// @param minimalAllowedPositionWidth The minimal allowed position width (tickUpper - tickLower)
    event EternalFarmingCreated(
        IERC20Minimal indexed rewardToken,
        IERC20Minimal indexed bonusRewardToken,
        IAlgebraPool indexed pool,
        address virtualPool,
        uint256 startTime,
        uint256 endTime,
        uint256 reward,
        uint256 bonusReward,
        Tiers tiers,
        address multiplierToken,
        uint24 minimalAllowedPositionWidth
    );
}

File 58 of 83 : IFarmingCenterVault.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.7.6;

interface IFarmingCenterVault {
    function claimTokens(
        address token,
        address to,
        uint256 tokenId,
        bytes32 incentiveId
    ) external;

    function setFarmingCenter(address farming) external;

    function lockTokens(
        uint256 tokenId,
        bytes32 incentiveId,
        uint256 tokenAmount
    ) external;

    function balances(uint256 tokenId, bytes32 incentiveId) external view returns (uint256 balance);
}

File 59 of 83 : IERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.7.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @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 `recipient`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address recipient, 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 `sender` to `recipient` 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 sender, address recipient, uint256 amount) external returns (bool);

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

File 60 of 83 : AlgebraLimitFarming.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.7.6;
pragma abicoder v2;

import './interfaces/IAlgebraLimitFarming.sol';
import './interfaces/IAlgebraLimitVirtualPool.sol';
import '../../libraries/IncentiveId.sol';
import '../../libraries/RewardMath.sol';

import './LimitVirtualPool.sol';
import 'algebra/contracts/libraries/SafeCast.sol';
import 'algebra-periphery/contracts/libraries/TransferHelper.sol';

import '../AlgebraFarming.sol';

/// @title Algebra incentive (time-limited) farming
contract AlgebraLimitFarming is AlgebraFarming, IAlgebraLimitFarming {
    using SafeCast for int256;

    /// @notice Represents the farm for nft
    struct Farm {
        uint128 liquidity;
        int24 tickLower;
        int24 tickUpper;
    }
    /// @inheritdoc IAlgebraLimitFarming
    uint256 public immutable override maxIncentiveStartLeadTime;
    /// @inheritdoc IAlgebraLimitFarming
    uint256 public immutable override maxIncentiveDuration;

    /// @dev farms[tokenId][incentiveHash] => Farm
    /// @inheritdoc IAlgebraLimitFarming
    mapping(uint256 => mapping(bytes32 => Farm)) public override farms;

    /// @param _deployer pool deployer contract address
    /// @param _nonfungiblePositionManager the NFT position manager contract address
    /// @param _maxIncentiveStartLeadTime the max duration of an incentive in seconds
    /// @param _maxIncentiveDuration the max amount of seconds into the future the incentive startTime can be set
    constructor(
        IAlgebraPoolDeployer _deployer,
        INonfungiblePositionManager _nonfungiblePositionManager,
        uint256 _maxIncentiveStartLeadTime,
        uint256 _maxIncentiveDuration
    ) AlgebraFarming(_deployer, _nonfungiblePositionManager) {
        maxIncentiveStartLeadTime = _maxIncentiveStartLeadTime;
        maxIncentiveDuration = _maxIncentiveDuration;
    }

    /// @inheritdoc IAlgebraLimitFarming
    function createLimitFarming(
        IncentiveKey memory key,
        Tiers calldata tiers,
        IncentiveParams memory params
    ) external override onlyIncentiveMaker returns (address virtualPool) {
        (address _incentive, ) = _getCurrentVirtualPools(key.pool);
        address activeIncentive = key.pool.activeIncentive();
        uint32 _activeEndTimestamp;
        if (_incentive != address(0)) {
            _activeEndTimestamp = IAlgebraLimitVirtualPool(_incentive).desiredEndTimestamp();
        }

        require(
            _activeEndTimestamp < block.timestamp && (activeIncentive != _incentive || _incentive == address(0)),
            'already has active incentive'
        );
        require(params.reward > 0, 'reward must be positive');
        require(block.timestamp <= key.startTime, 'start time too low');
        require(key.startTime - block.timestamp <= maxIncentiveStartLeadTime, 'start time too far into future');
        require(key.startTime < key.endTime, 'start must be before end time');
        require(key.endTime - key.startTime <= maxIncentiveDuration, 'incentive duration is too long');

        virtualPool = address(
            new LimitVirtualPool(
                address(farmingCenter),
                address(this),
                address(key.pool),
                uint32(key.startTime),
                uint32(key.endTime)
            )
        );
        (, params.reward, params.bonusReward) = _createFarming(
            virtualPool,
            key,
            params.reward,
            params.bonusReward,
            params.minimalPositionWidth,
            params.multiplierToken,
            tiers
        );

        emit LimitFarmingCreated(
            key.rewardToken,
            key.bonusRewardToken,
            key.pool,
            key.startTime,
            key.endTime,
            params.reward,
            params.bonusReward,
            tiers,
            params.multiplierToken,
            params.minimalPositionWidth,
            params.enterStartTime
        );
    }

    function addRewards(
        IncentiveKey memory key,
        uint256 reward,
        uint256 bonusReward
    ) external override onlyIncentiveMaker {
        require(block.timestamp < key.endTime, 'cannot add rewards after endTime');

        bytes32 incentiveId = IncentiveId.compute(key);
        Incentive storage incentive = incentives[incentiveId];
        (reward, bonusReward) = _receiveRewards(key, reward, bonusReward, incentive);

        if (reward | bonusReward > 0) {
            emit RewardsAdded(reward, bonusReward, incentiveId);
        }
    }

    function decreaseRewardsAmount(
        IncentiveKey memory key,
        uint256 rewardAmount,
        uint256 bonusRewardAmount
    ) external override onlyIncentiveMaker {
        bytes32 incentiveId = IncentiveId.compute(key);
        Incentive storage incentive = incentives[incentiveId];

        require(block.timestamp < key.endTime || incentive.totalLiquidity == 0, 'incentive finished');

        uint256 _totalReward = incentive.totalReward;
        if (rewardAmount > _totalReward) rewardAmount = _totalReward;
        incentive.totalReward = _totalReward - rewardAmount;

        uint256 _bonusReward = incentive.bonusReward;
        if (bonusRewardAmount > _bonusReward) bonusRewardAmount = _bonusReward;
        incentive.bonusReward = _bonusReward - bonusRewardAmount;

        TransferHelper.safeTransfer(address(key.bonusRewardToken), msg.sender, bonusRewardAmount);
        TransferHelper.safeTransfer(address(key.rewardToken), msg.sender, rewardAmount);

        emit RewardAmountsDecreased(rewardAmount, bonusRewardAmount, incentiveId);
    }

    /// @inheritdoc IAlgebraFarming
    function detachIncentive(IncentiveKey memory key) external override onlyIncentiveMaker {
        (address _incentiveVirtualPool, ) = _getCurrentVirtualPools(key.pool);
        _detachIncentive(key, _incentiveVirtualPool);
    }

    /// @inheritdoc IAlgebraFarming
    function attachIncentive(IncentiveKey memory key) external override onlyIncentiveMaker {
        (address _incentiveVirtualPool, ) = _getCurrentVirtualPools(key.pool);
        _attachIncentive(key, _incentiveVirtualPool);
    }

    /// @inheritdoc IAlgebraFarming
    function enterFarming(
        IncentiveKey memory key,
        uint256 tokenId,
        uint256 tokensLocked
    ) external override onlyFarmingCenter {
        require(block.timestamp < key.startTime, 'incentive has already started');

        (bytes32 incentiveId, int24 tickLower, int24 tickUpper, uint128 liquidity, ) = _enterFarming(
            key,
            tokenId,
            tokensLocked
        );

        mapping(bytes32 => Farm) storage farmsForToken = farms[tokenId];
        require(farmsForToken[incentiveId].liquidity == 0, 'token already farmed');

        Incentive storage incentive = incentives[incentiveId];
        uint224 _currentTotalLiquidity = incentive.totalLiquidity;
        require(_currentTotalLiquidity + liquidity >= _currentTotalLiquidity, 'liquidity overflow');
        incentive.totalLiquidity = _currentTotalLiquidity + liquidity;

        farmsForToken[incentiveId] = Farm({liquidity: liquidity, tickLower: tickLower, tickUpper: tickUpper});

        emit FarmEntered(tokenId, incentiveId, liquidity, tokensLocked);
    }

    /// @inheritdoc IAlgebraFarming
    function exitFarming(
        IncentiveKey memory key,
        uint256 tokenId,
        address _owner
    ) external override onlyFarmingCenter {
        bytes32 incentiveId = IncentiveId.compute(key);
        Incentive storage incentive = incentives[incentiveId];
        // anyone can call exitFarming if the block time is after the end time of the incentive
        require(block.timestamp > key.endTime || block.timestamp < key.startTime, 'cannot exitFarming before end time');

        Farm memory farm = farms[tokenId][incentiveId];

        require(farm.liquidity != 0, 'farm does not exist');

        uint256 reward;
        uint256 bonusReward;

        IAlgebraLimitVirtualPool virtualPool = IAlgebraLimitVirtualPool(incentive.virtualPoolAddress);

        if (block.timestamp > key.endTime) {
            uint256 activeTime;
            {
                bool wasFinished;
                (wasFinished, activeTime) = virtualPool.finish();
                if (!wasFinished) {
                    (address _incentive, ) = _getCurrentVirtualPools(key.pool);
                    if (address(virtualPool) == _incentive) {
                        farmingCenter.connectVirtualPool(key.pool, address(0));
                    }
                }
            }

            uint160 secondsPerLiquidityInsideX128 = virtualPool.getInnerSecondsPerLiquidity(
                farm.tickLower,
                farm.tickUpper
            );

            uint224 _totalLiquidity = activeTime > 0 ? 0 : incentive.totalLiquidity; // used only if no one was active in incentive
            reward = RewardMath.computeRewardAmount(
                incentive.totalReward,
                activeTime,
                farm.liquidity,
                _totalLiquidity,
                secondsPerLiquidityInsideX128
            );

            mapping(IERC20Minimal => uint256) storage rewardBalances = rewards[_owner];
            if (reward > 0) {
                rewardBalances[key.rewardToken] += reward; // user must claim before overflow
            }

            if (incentive.bonusReward != 0) {
                bonusReward = RewardMath.computeRewardAmount(
                    incentive.bonusReward,
                    activeTime,
                    farm.liquidity,
                    _totalLiquidity,
                    secondsPerLiquidityInsideX128
                );
                if (bonusReward > 0) {
                    rewardBalances[key.bonusRewardToken] += bonusReward; // user must claim before overflow
                }
            }
        } else {
            (, int24 tick, , , , , ) = key.pool.globalState();

            virtualPool.applyLiquidityDeltaToPosition(
                uint32(block.timestamp),
                farm.tickLower,
                farm.tickUpper,
                -int256(farm.liquidity).toInt128(),
                tick
            );
            incentive.totalLiquidity -= farm.liquidity;
        }

        delete farms[tokenId][incentiveId];

        emit FarmEnded(
            tokenId,
            incentiveId,
            address(key.rewardToken),
            address(key.bonusRewardToken),
            _owner,
            reward,
            bonusReward
        );
    }

    /// @inheritdoc IAlgebraFarming
    function getRewardInfo(IncentiveKey memory key, uint256 tokenId)
        external
        view
        override
        returns (uint256 reward, uint256 bonusReward)
    {
        bytes32 incentiveId = IncentiveId.compute(key);

        Farm memory farm = farms[tokenId][incentiveId];
        require(farm.liquidity != 0, 'farm does not exist');

        Incentive storage incentive = incentives[incentiveId];

        IAlgebraLimitVirtualPool virtualPool = IAlgebraLimitVirtualPool(incentive.virtualPoolAddress);
        uint160 secondsPerLiquidityInsideX128 = virtualPool.getInnerSecondsPerLiquidity(farm.tickLower, farm.tickUpper);

        uint256 activeTime = key.endTime - virtualPool.timeOutside() - key.startTime;

        uint224 _totalLiquidity = activeTime > 0 ? 0 : incentive.totalLiquidity; // used only if no one was active in incentive
        reward = RewardMath.computeRewardAmount(
            incentive.totalReward,
            activeTime,
            farm.liquidity,
            _totalLiquidity,
            secondsPerLiquidityInsideX128
        );
        bonusReward = RewardMath.computeRewardAmount(
            incentive.bonusReward,
            activeTime,
            farm.liquidity,
            _totalLiquidity,
            secondsPerLiquidityInsideX128
        );
    }
}

File 61 of 83 : IAlgebraLimitVirtualPool.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.7.6;
pragma abicoder v2;

import '../../IAlgebraVirtualPoolBase.sol';

interface IAlgebraLimitVirtualPool is IAlgebraVirtualPoolBase {
    // The timestamp when the active incentive is finished
    function desiredEndTimestamp() external view returns (uint32);

    // The first swap after this timestamp is going to initialize the virtual pool
    function desiredStartTimestamp() external view returns (uint32);

    // Is incentive already finished or not
    function isFinished() external view returns (bool);

    /**
     * @notice Finishes incentive if it wasn't
     * @dev This function is called by a AlgebraLimitFarming when someone calls #exitFarming() after the end timestamp
     * @return wasFinished Was incentive finished before this call or not
     * @return activeTime The summary amount of seconds inside active positions
     */
    function finish() external returns (bool wasFinished, uint32 activeTime);
}

File 62 of 83 : RewardMath.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.7.6;

import 'algebra/contracts/libraries/FullMath.sol';

/// @title Math for computing rewards
/// @notice Allows computing rewards given some parameters of farms and incentives
library RewardMath {
    /// @notice Compute the amount of rewards owed given parameters of the incentive and farm
    /// @param totalReward The total amount of rewards
    /// @param activeTime Time of active incentive rewards distribution
    /// @param liquidity The amount of liquidity, assumed to be constant over the period over which the snapshots are measured
    /// @param totalLiquidity The amount of liquidity of all positions participating in the incentive
    /// @param secondsPerLiquidityInsideX128 The seconds per liquidity of the liquidity tick range as of the current block timestamp
    /// @return reward The amount of rewards owed
    function computeRewardAmount(
        uint256 totalReward,
        uint256 activeTime,
        uint128 liquidity,
        uint224 totalLiquidity,
        uint160 secondsPerLiquidityInsideX128
    ) internal pure returns (uint256 reward) {
        // this operation is safe, as the difference cannot be greater than 1/deposit.liquidity
        uint256 secondsInsideX128 = secondsPerLiquidityInsideX128 * liquidity;

        if (activeTime == 0) {
            reward = FullMath.mulDiv(totalReward, liquidity, totalLiquidity); // liquidity <= totalLiquidity
        } else {
            // reward less than uint256, as secondsInsideX128 cannot be greater than (activeTime) << 128
            reward = FullMath.mulDiv(totalReward, secondsInsideX128, (activeTime) << 128);
        }
    }
}

File 63 of 83 : LimitVirtualPool.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.7.6;

import 'algebra/contracts/libraries/TickManager.sol';

import './interfaces/IAlgebraLimitVirtualPool.sol';

import '../AlgebraVirtualPoolBase.sol';

contract LimitVirtualPool is AlgebraVirtualPoolBase, IAlgebraLimitVirtualPool {
    using TickManager for mapping(int24 => TickManager.Tick);

    /// @inheritdoc IAlgebraLimitVirtualPool
    bool public override isFinished;

    /// @inheritdoc IAlgebraLimitVirtualPool
    uint32 public immutable override desiredEndTimestamp;
    /// @inheritdoc IAlgebraLimitVirtualPool
    uint32 public immutable override desiredStartTimestamp;

    constructor(
        address _farmingCenterAddress,
        address _farmingAddress,
        address _pool,
        uint32 _desiredStartTimestamp,
        uint32 _desiredEndTimestamp
    ) AlgebraVirtualPoolBase(_farmingCenterAddress, _farmingAddress, _pool) {
        desiredStartTimestamp = _desiredStartTimestamp;
        desiredEndTimestamp = _desiredEndTimestamp;
        prevTimestamp = _desiredStartTimestamp;
    }

    /// @inheritdoc IAlgebraLimitVirtualPool
    function finish() external override onlyFarming returns (bool wasFinished, uint32 activeTime) {
        wasFinished = isFinished;
        if (!wasFinished) {
            isFinished = true;
            _increaseCumulative(desiredEndTimestamp);
        }
        activeTime = desiredEndTimestamp - timeOutside - desiredStartTimestamp;
    }

    function _crossTick(int24 nextTick) internal override returns (int128 liquidityDelta) {
        return ticks.cross(nextTick, 0, 0, globalSecondsPerLiquidityCumulative, 0, 0);
    }

    function _increaseCumulative(uint32 currentTimestamp) internal override returns (Status) {
        if (currentTimestamp <= desiredStartTimestamp) {
            return Status.NOT_STARTED;
        }
        if (currentTimestamp > desiredEndTimestamp) {
            return Status.NOT_EXIST;
        }

        uint32 _previousTimestamp = prevTimestamp;
        if (currentTimestamp > _previousTimestamp) {
            uint128 _currentLiquidity = currentLiquidity;
            if (_currentLiquidity > 0) {
                globalSecondsPerLiquidityCumulative +=
                    (uint160(currentTimestamp - _previousTimestamp) << 128) /
                    _currentLiquidity;
                prevTimestamp = currentTimestamp;
            } else {
                timeOutside += currentTimestamp - _previousTimestamp;
                prevTimestamp = currentTimestamp;
            }
        }

        return Status.ACTIVE;
    }

    function _updateTick(
        int24 tick,
        int24 currentTick,
        int128 liquidityDelta,
        bool isTopTick
    ) internal override returns (bool updated) {
        return ticks.update(tick, currentTick, liquidityDelta, 0, 0, 0, 0, 0, isTopTick);
    }
}

File 64 of 83 : TickManager.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.7.6;

import './LowGasSafeMath.sol';
import './SafeCast.sol';

import './LiquidityMath.sol';
import './Constants.sol';

/// @title TickManager
/// @notice Contains functions for managing tick processes and relevant calculations
library TickManager {
  using LowGasSafeMath for int256;
  using SafeCast for int256;

  // info stored for each initialized individual tick
  struct Tick {
    uint128 liquidityTotal; // the total position liquidity that references this tick
    int128 liquidityDelta; // amount of net liquidity added (subtracted) when tick is crossed left-right (right-left),
    // fee growth per unit of liquidity on the _other_ side of this tick (relative to the current tick)
    // only has relative meaning, not absolute — the value depends on when the tick is initialized
    uint256 outerFeeGrowth0Token;
    uint256 outerFeeGrowth1Token;
    int56 outerTickCumulative; // the cumulative tick value on the other side of the tick
    uint160 outerSecondsPerLiquidity; // the seconds per unit of liquidity on the _other_ side of current tick, (relative meaning)
    uint32 outerSecondsSpent; // the seconds spent on the other side of the current tick, only has relative meaning
    bool initialized; // these 8 bits are set to prevent fresh sstores when crossing newly initialized ticks
  }

  /// @notice Retrieves fee growth data
  /// @param self The mapping containing all tick information for initialized ticks
  /// @param bottomTick The lower tick boundary of the position
  /// @param topTick The upper tick boundary of the position
  /// @param currentTick The current tick
  /// @param totalFeeGrowth0Token The all-time global fee growth, per unit of liquidity, in token0
  /// @param totalFeeGrowth1Token The all-time global fee growth, per unit of liquidity, in token1
  /// @return innerFeeGrowth0Token The all-time fee growth in token0, per unit of liquidity, inside the position's tick boundaries
  /// @return innerFeeGrowth1Token The all-time fee growth in token1, per unit of liquidity, inside the position's tick boundaries
  function getInnerFeeGrowth(
    mapping(int24 => Tick) storage self,
    int24 bottomTick,
    int24 topTick,
    int24 currentTick,
    uint256 totalFeeGrowth0Token,
    uint256 totalFeeGrowth1Token
  ) internal view returns (uint256 innerFeeGrowth0Token, uint256 innerFeeGrowth1Token) {
    Tick storage lower = self[bottomTick];
    Tick storage upper = self[topTick];

    if (currentTick < topTick) {
      if (currentTick >= bottomTick) {
        innerFeeGrowth0Token = totalFeeGrowth0Token - lower.outerFeeGrowth0Token;
        innerFeeGrowth1Token = totalFeeGrowth1Token - lower.outerFeeGrowth1Token;
      } else {
        innerFeeGrowth0Token = lower.outerFeeGrowth0Token;
        innerFeeGrowth1Token = lower.outerFeeGrowth1Token;
      }
      innerFeeGrowth0Token -= upper.outerFeeGrowth0Token;
      innerFeeGrowth1Token -= upper.outerFeeGrowth1Token;
    } else {
      innerFeeGrowth0Token = upper.outerFeeGrowth0Token - lower.outerFeeGrowth0Token;
      innerFeeGrowth1Token = upper.outerFeeGrowth1Token - lower.outerFeeGrowth1Token;
    }
  }

  /// @notice Updates a tick and returns true if the tick was flipped from initialized to uninitialized, or vice versa
  /// @param self The mapping containing all tick information for initialized ticks
  /// @param tick The tick that will be updated
  /// @param currentTick The current tick
  /// @param liquidityDelta A new amount of liquidity to be added (subtracted) when tick is crossed from left to right (right to left)
  /// @param totalFeeGrowth0Token The all-time global fee growth, per unit of liquidity, in token0
  /// @param totalFeeGrowth1Token The all-time global fee growth, per unit of liquidity, in token1
  /// @param secondsPerLiquidityCumulative The all-time seconds per max(1, liquidity) of the pool
  /// @param tickCumulative The all-time global cumulative tick
  /// @param time The current block timestamp cast to a uint32
  /// @param upper true for updating a position's upper tick, or false for updating a position's lower tick
  /// @return flipped Whether the tick was flipped from initialized to uninitialized, or vice versa
  function update(
    mapping(int24 => Tick) storage self,
    int24 tick,
    int24 currentTick,
    int128 liquidityDelta,
    uint256 totalFeeGrowth0Token,
    uint256 totalFeeGrowth1Token,
    uint160 secondsPerLiquidityCumulative,
    int56 tickCumulative,
    uint32 time,
    bool upper
  ) internal returns (bool flipped) {
    Tick storage data = self[tick];

    int128 liquidityDeltaBefore = data.liquidityDelta;
    uint128 liquidityTotalBefore = data.liquidityTotal;

    uint128 liquidityTotalAfter = LiquidityMath.addDelta(liquidityTotalBefore, liquidityDelta);
    require(liquidityTotalAfter < Constants.MAX_LIQUIDITY_PER_TICK + 1, 'LO');

    // when the lower (upper) tick is crossed left to right (right to left), liquidity must be added (removed)
    data.liquidityDelta = upper
      ? int256(liquidityDeltaBefore).sub(liquidityDelta).toInt128()
      : int256(liquidityDeltaBefore).add(liquidityDelta).toInt128();

    data.liquidityTotal = liquidityTotalAfter;

    flipped = (liquidityTotalAfter == 0);
    if (liquidityTotalBefore == 0) {
      flipped = !flipped;
      // by convention, we assume that all growth before a tick was initialized happened _below_ the tick
      if (tick <= currentTick) {
        data.outerFeeGrowth0Token = totalFeeGrowth0Token;
        data.outerFeeGrowth1Token = totalFeeGrowth1Token;
        data.outerSecondsPerLiquidity = secondsPerLiquidityCumulative;
        data.outerTickCumulative = tickCumulative;
        data.outerSecondsSpent = time;
      }
      data.initialized = true;
    }
  }

  /// @notice Transitions to next tick as needed by price movement
  /// @param self The mapping containing all tick information for initialized ticks
  /// @param tick The destination tick of the transition
  /// @param totalFeeGrowth0Token The all-time global fee growth, per unit of liquidity, in token0
  /// @param totalFeeGrowth1Token The all-time global fee growth, per unit of liquidity, in token1
  /// @param secondsPerLiquidityCumulative The current seconds per liquidity
  /// @param tickCumulative The all-time global cumulative tick
  /// @param time The current block.timestamp
  /// @return liquidityDelta The amount of liquidity added (subtracted) when tick is crossed from left to right (right to left)
  function cross(
    mapping(int24 => Tick) storage self,
    int24 tick,
    uint256 totalFeeGrowth0Token,
    uint256 totalFeeGrowth1Token,
    uint160 secondsPerLiquidityCumulative,
    int56 tickCumulative,
    uint32 time
  ) internal returns (int128 liquidityDelta) {
    Tick storage data = self[tick];

    data.outerSecondsSpent = time - data.outerSecondsSpent;
    data.outerSecondsPerLiquidity = secondsPerLiquidityCumulative - data.outerSecondsPerLiquidity;
    data.outerTickCumulative = tickCumulative - data.outerTickCumulative;

    data.outerFeeGrowth1Token = totalFeeGrowth1Token - data.outerFeeGrowth1Token;
    data.outerFeeGrowth0Token = totalFeeGrowth0Token - data.outerFeeGrowth0Token;

    return data.liquidityDelta;
  }
}

File 65 of 83 : AlgebraVirtualPoolBase.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.7.6;

import 'algebra/contracts/libraries/TickManager.sol';
import 'algebra/contracts/libraries/TickTable.sol';
import 'algebra/contracts/libraries/LiquidityMath.sol';

import './IAlgebraVirtualPoolBase.sol';

/// @title Abstract base contract for Algebra virtual pools
abstract contract AlgebraVirtualPoolBase is IAlgebraVirtualPoolBase {
    using TickTable for mapping(int16 => uint256);

    address public immutable farmingCenterAddress;
    address public immutable farmingAddress;
    address public immutable pool;

    /// @inheritdoc IAlgebraVirtualPoolBase
    mapping(int24 => TickManager.Tick) public override ticks;

    mapping(int16 => uint256) internal tickTable;

    /// @inheritdoc IAlgebraVirtualPoolBase
    uint128 public override currentLiquidity;
    /// @inheritdoc IAlgebraVirtualPoolBase
    int24 public override globalTick;
    /// @inheritdoc IAlgebraVirtualPoolBase
    uint32 public override timeOutside;

    /// @inheritdoc IAlgebraVirtualPoolBase
    uint160 public override globalSecondsPerLiquidityCumulative;
    /// @inheritdoc IAlgebraVirtualPoolBase
    uint32 public override prevTimestamp;

    /// @notice only pool (or FarmingCenter as "proxy") can call
    modifier onlyFromPool() {
        require(msg.sender == farmingCenterAddress || msg.sender == pool, 'only pool can call this function');
        _;
    }

    modifier onlyFarming() {
        require(msg.sender == farmingAddress, 'only farming can call this function');
        _;
    }

    constructor(
        address _farmingCenterAddress,
        address _farmingAddress,
        address _pool
    ) {
        farmingCenterAddress = _farmingCenterAddress;
        farmingAddress = _farmingAddress;
        pool = _pool;
    }

    /// @notice get seconds per liquidity inside range
    function getInnerSecondsPerLiquidity(int24 bottomTick, int24 topTick)
        external
        view
        override
        returns (uint160 innerSecondsSpentPerLiquidity)
    {
        uint160 lowerSecondsPerLiquidity = ticks[bottomTick].outerSecondsPerLiquidity;
        uint160 upperSecondsPerLiquidity = ticks[topTick].outerSecondsPerLiquidity;

        if (globalTick < bottomTick) {
            return (lowerSecondsPerLiquidity - upperSecondsPerLiquidity);
        } else if (globalTick < topTick) {
            return (globalSecondsPerLiquidityCumulative - lowerSecondsPerLiquidity - upperSecondsPerLiquidity);
        } else {
            return (upperSecondsPerLiquidity - lowerSecondsPerLiquidity);
        }
    }

    /// @dev logic of tick crossing differs in virtual pools
    function _crossTick(int24 nextTick) internal virtual returns (int128 liquidityDelta);

    /// @inheritdoc IAlgebraVirtualPool
    function cross(int24 nextTick, bool zeroToOne) external override onlyFromPool {
        if (ticks[nextTick].initialized) {
            int128 liquidityDelta = _crossTick(nextTick);
            if (zeroToOne) liquidityDelta = -liquidityDelta;
            currentLiquidity = LiquidityMath.addDelta(currentLiquidity, liquidityDelta);
        }
        globalTick = zeroToOne ? nextTick - 1 : nextTick;
    }

    /// @dev logic of cumulatives differs in virtual pools
    function _increaseCumulative(uint32 currentTimestamp) internal virtual returns (Status);

    /// @inheritdoc IAlgebraVirtualPool
    function increaseCumulative(uint32 currentTimestamp) external override onlyFromPool returns (Status) {
        return _increaseCumulative(currentTimestamp);
    }

    /// @dev logic of tick updating differs in virtual pools
    function _updateTick(
        int24 tick,
        int24 currentTick,
        int128 liquidityDelta,
        bool isTopTick
    ) internal virtual returns (bool updated);

    /// @inheritdoc IAlgebraVirtualPoolBase
    function applyLiquidityDeltaToPosition(
        uint32 currentTimestamp,
        int24 bottomTick,
        int24 topTick,
        int128 liquidityDelta,
        int24 currentTick
    ) external override onlyFarming {
        globalTick = currentTick;

        if (currentTimestamp > prevTimestamp) {
            _increaseCumulative(currentTimestamp);
        }

        if (liquidityDelta != 0) {
            // if we need to update the ticks, do it
            bool flippedBottom;
            bool flippedTop;

            if (_updateTick(bottomTick, currentTick, liquidityDelta, false)) {
                flippedBottom = true;
                tickTable.toggleTick(bottomTick);
            }

            if (_updateTick(topTick, currentTick, liquidityDelta, true)) {
                flippedTop = true;
                tickTable.toggleTick(topTick);
            }

            if (currentTick >= bottomTick && currentTick < topTick) {
                currentLiquidity = LiquidityMath.addDelta(currentLiquidity, liquidityDelta);
            }

            // clear any tick data that is no longer needed
            if (liquidityDelta < 0) {
                if (flippedBottom) {
                    delete ticks[bottomTick];
                }
                if (flippedTop) {
                    delete ticks[topTick];
                }
            }
        }
    }
}

File 66 of 83 : LiquidityMath.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Math library for liquidity
/// @dev Credit to Uniswap Labs under GPL-2.0-or-later license:
/// https://github.com/Uniswap/v3-core/blob/main/contracts/libraries
library LiquidityMath {
  /// @notice Add a signed liquidity delta to liquidity and revert if it overflows or underflows
  /// @param x The liquidity before change
  /// @param y The delta by which liquidity should be changed
  /// @return z The liquidity delta
  function addDelta(uint128 x, int128 y) internal pure returns (uint128 z) {
    if (y < 0) {
      require((z = x - uint128(-y)) < x, 'LS');
    } else {
      require((z = x + uint128(y)) >= x, 'LA');
    }
  }
}

File 67 of 83 : TickTable.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.7.6;

import './Constants.sol';
import './TickMath.sol';

/// @title Packed tick initialized state library
/// @notice Stores a packed mapping of tick index to its initialized state
/// @dev The mapping uses int16 for keys since ticks are represented as int24 and there are 256 (2^8) values per word.
library TickTable {
  /// @notice Toggles the initialized state for a given tick from false to true, or vice versa
  /// @param self The mapping in which to toggle the tick
  /// @param tick The tick to toggle
  function toggleTick(mapping(int16 => uint256) storage self, int24 tick) internal {
    require(tick % Constants.TICK_SPACING == 0, 'tick is not spaced'); // ensure that the tick is spaced
    tick /= Constants.TICK_SPACING; // compress tick
    int16 rowNumber;
    uint8 bitNumber;

    assembly {
      bitNumber := and(tick, 0xFF)
      rowNumber := shr(8, tick)
    }
    self[rowNumber] ^= 1 << bitNumber;
  }

  /// @notice get position of single 1-bit
  /// @dev it is assumed that word contains exactly one 1-bit, otherwise the result will be incorrect
  /// @param word The word containing only one 1-bit
  function getSingleSignificantBit(uint256 word) internal pure returns (uint8 singleBitPos) {
    assembly {
      singleBitPos := iszero(and(word, 0x5555555555555555555555555555555555555555555555555555555555555555))
      singleBitPos := or(singleBitPos, shl(7, iszero(and(word, 0x00000000000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))))
      singleBitPos := or(singleBitPos, shl(6, iszero(and(word, 0x0000000000000000FFFFFFFFFFFFFFFF0000000000000000FFFFFFFFFFFFFFFF))))
      singleBitPos := or(singleBitPos, shl(5, iszero(and(word, 0x00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF))))
      singleBitPos := or(singleBitPos, shl(4, iszero(and(word, 0x0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF))))
      singleBitPos := or(singleBitPos, shl(3, iszero(and(word, 0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF))))
      singleBitPos := or(singleBitPos, shl(2, iszero(and(word, 0x0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F))))
      singleBitPos := or(singleBitPos, shl(1, iszero(and(word, 0x3333333333333333333333333333333333333333333333333333333333333333))))
    }
  }

  /// @notice get position of most significant 1-bit (leftmost)
  /// @dev it is assumed that before the call, a check will be made that the argument (word) is not equal to zero
  /// @param word The word containing at least one 1-bit
  function getMostSignificantBit(uint256 word) internal pure returns (uint8 mostBitPos) {
    assembly {
      word := or(word, shr(1, word))
      word := or(word, shr(2, word))
      word := or(word, shr(4, word))
      word := or(word, shr(8, word))
      word := or(word, shr(16, word))
      word := or(word, shr(32, word))
      word := or(word, shr(64, word))
      word := or(word, shr(128, word))
      word := sub(word, shr(1, word))
    }
    return (getSingleSignificantBit(word));
  }

  /// @notice Returns the next initialized tick contained in the same word (or adjacent word) as the tick that is either
  /// to the left (less than or equal to) or right (greater than) of the given tick
  /// @param self The mapping in which to compute the next initialized tick
  /// @param tick The starting tick
  /// @param lte Whether to search for the next initialized tick to the left (less than or equal to the starting tick)
  /// @return nextTick The next initialized or uninitialized tick up to 256 ticks away from the current tick
  /// @return initialized Whether the next tick is initialized, as the function only searches within up to 256 ticks
  function nextTickInTheSameRow(
    mapping(int16 => uint256) storage self,
    int24 tick,
    bool lte
  ) internal view returns (int24 nextTick, bool initialized) {
    {
      int24 tickSpacing = Constants.TICK_SPACING;
      // compress and round towards negative infinity if negative
      assembly {
        tick := sub(sdiv(tick, tickSpacing), and(slt(tick, 0), not(iszero(smod(tick, tickSpacing)))))
      }
    }

    if (lte) {
      // unpacking not made into a separate function for gas and contract size savings
      int16 rowNumber;
      uint8 bitNumber;
      assembly {
        bitNumber := and(tick, 0xFF)
        rowNumber := shr(8, tick)
      }
      uint256 _row = self[rowNumber] << (255 - bitNumber); // all the 1s at or to the right of the current bitNumber

      if (_row != 0) {
        tick -= int24(255 - getMostSignificantBit(_row));
        return (uncompressAndBoundTick(tick), true);
      } else {
        tick -= int24(bitNumber);
        return (uncompressAndBoundTick(tick), false);
      }
    } else {
      // start from the word of the next tick, since the current tick state doesn't matter
      tick += 1;
      int16 rowNumber;
      uint8 bitNumber;
      assembly {
        bitNumber := and(tick, 0xFF)
        rowNumber := shr(8, tick)
      }

      // all the 1s at or to the left of the bitNumber
      uint256 _row = self[rowNumber] >> (bitNumber);

      if (_row != 0) {
        tick += int24(getSingleSignificantBit(-_row & _row)); // least significant bit
        return (uncompressAndBoundTick(tick), true);
      } else {
        tick += int24(255 - bitNumber);
        return (uncompressAndBoundTick(tick), false);
      }
    }
  }

  function uncompressAndBoundTick(int24 tick) private pure returns (int24 boundedTick) {
    boundedTick = tick * Constants.TICK_SPACING;
    if (boundedTick < TickMath.MIN_TICK) {
      boundedTick = TickMath.MIN_TICK;
    } else if (boundedTick > TickMath.MAX_TICK) {
      boundedTick = TickMath.MAX_TICK;
    }
  }
}

File 68 of 83 : FarmingCenterVault.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.7.6;

import 'algebra-periphery/contracts/libraries/TransferHelper.sol';
import './interfaces/IFarmingCenterVault.sol';

contract FarmingCenterVault is IFarmingCenterVault {
    address public farmingCenter;
    address public immutable owner;
    // tokenId => IncentiveId => TokenAmount
    mapping(uint256 => mapping(bytes32 => uint256)) public override balances;

    constructor() {
        owner = msg.sender;
    }

    function lockTokens(
        uint256 tokenId,
        bytes32 incentiveId,
        uint256 tokenAmount
    ) external override {
        require(msg.sender == farmingCenter, 'onlyFarming');
        balances[tokenId][incentiveId] = tokenAmount;
    }

    function setFarmingCenter(address _farmingCenter) external override {
        require(msg.sender == owner, 'onlyOwner');
        require(farmingCenter == address(0), 'Already initialized');
        farmingCenter = _farmingCenter;
    }

    function claimTokens(
        address multiplierToken,
        address to,
        uint256 tokenId,
        bytes32 incentiveId
    ) external override {
        require(msg.sender == farmingCenter, 'onlyFarming');

        uint256 balance = balances[tokenId][incentiveId];
        if (balance > 0) {
            TransferHelper.safeTransfer(multiplierToken, to, balance);
            balances[tokenId][incentiveId] = 0;
        }
    }
}

File 69 of 83 : TestRewardMath.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.7.6;
pragma abicoder v2;

import '../interfaces/IAlgebraFarming.sol';

import '../libraries/RewardMath.sol';

/// @dev Test contract for RewardMatrh
contract TestRewardMath {
    function computeRewardAmount(
        uint256 totalReward,
        uint256 startTime,
        uint256 endTime,
        uint128 liquidity,
        uint224 totalLiquidity,
        uint160 secondsPerLiquidityInsideX128
    ) public pure returns (uint256 reward) {
        reward = RewardMath.computeRewardAmount(
            totalReward,
            endTime - startTime,
            liquidity,
            totalLiquidity,
            secondsPerLiquidityInsideX128
        );
    }
}

File 70 of 83 : EternalVirtualPool.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.7.6;

import 'algebra/contracts/libraries/TickManager.sol';

import 'algebra/contracts/libraries/FullMath.sol';
import 'algebra/contracts/libraries/Constants.sol';
import 'algebra/contracts/libraries/LowGasSafeMath.sol';

import './interfaces/IAlgebraEternalVirtualPool.sol';

import '../AlgebraVirtualPoolBase.sol';

contract EternalVirtualPool is AlgebraVirtualPoolBase, IAlgebraEternalVirtualPool {
    using TickManager for mapping(int24 => TickManager.Tick);
    using LowGasSafeMath for uint256;

    uint128 public rewardRate0;
    uint128 public rewardRate1;

    uint256 public rewardReserve0;
    uint256 public rewardReserve1;

    uint256 public totalRewardGrowth0;
    uint256 public totalRewardGrowth1;

    constructor(
        address _farmingCenterAddress,
        address _farmingAddress,
        address _pool
    ) AlgebraVirtualPoolBase(_farmingCenterAddress, _farmingAddress, _pool) {
        prevTimestamp = uint32(block.timestamp);
    }

    function addRewards(uint256 token0Amount, uint256 token1Amount) external override onlyFarming {
        _increaseCumulative(uint32(block.timestamp));
        if (token0Amount > 0) rewardReserve0 = rewardReserve0.add(token0Amount);
        if (token1Amount > 0) rewardReserve1 = rewardReserve1.add(token1Amount);
    }

    // @inheritdoc IAlgebraEternalVirtualPool
    function setRates(uint128 rate0, uint128 rate1) external override onlyFarming {
        _increaseCumulative(uint32(block.timestamp));
        (rewardRate0, rewardRate1) = (rate0, rate1);
    }

    // @inheritdoc IAlgebraEternalVirtualPool
    function getInnerRewardsGrowth(int24 bottomTick, int24 topTick)
        external
        view
        override
        returns (uint256 rewardGrowthInside0, uint256 rewardGrowthInside1)
    {
        return ticks.getInnerFeeGrowth(bottomTick, topTick, globalTick, totalRewardGrowth0, totalRewardGrowth1);
    }

    function _crossTick(int24 nextTick) internal override returns (int128 liquidityDelta) {
        return ticks.cross(nextTick, totalRewardGrowth0, totalRewardGrowth1, globalSecondsPerLiquidityCumulative, 0, 0);
    }

    function _increaseCumulative(uint32 currentTimestamp) internal override returns (Status) {
        uint256 timeDelta = currentTimestamp - prevTimestamp; // safe until timedelta > 136 years
        if (timeDelta == 0) return Status.ACTIVE; // only once per block

        uint256 _currentLiquidity = currentLiquidity; // currentLiquidity is uint128
        if (_currentLiquidity > 0) {
            (uint256 _rewardRate0, uint256 _rewardRate1) = (rewardRate0, rewardRate1);
            uint256 _rewardReserve0 = _rewardRate0 > 0 ? rewardReserve0 : 0;
            uint256 _rewardReserve1 = _rewardRate1 > 0 ? rewardReserve1 : 0;

            if (_rewardReserve0 > 0) {
                uint256 reward0 = _rewardRate0 * timeDelta;
                if (reward0 > _rewardReserve0) reward0 = _rewardReserve0;
                rewardReserve0 = _rewardReserve0 - reward0;
                totalRewardGrowth0 += FullMath.mulDiv(reward0, Constants.Q128, _currentLiquidity);
            }

            if (_rewardReserve1 > 0) {
                uint256 reward1 = _rewardRate1 * timeDelta;
                if (reward1 > _rewardReserve1) reward1 = _rewardReserve1;
                rewardReserve1 = _rewardReserve1 - reward1;
                totalRewardGrowth1 += FullMath.mulDiv(reward1, Constants.Q128, _currentLiquidity);
            }
            globalSecondsPerLiquidityCumulative += (uint160(timeDelta) << 128) / uint160(_currentLiquidity);
            prevTimestamp = currentTimestamp; // duplicated for gas optimization
        } else {
            timeOutside += uint32(timeDelta);
            prevTimestamp = currentTimestamp; // duplicated for gas optimization
        }

        return Status.ACTIVE;
    }

    function _updateTick(
        int24 tick,
        int24 currentTick,
        int128 liquidityDelta,
        bool isTopTick
    ) internal override returns (bool updated) {
        return
            ticks.update(tick, currentTick, liquidityDelta, totalRewardGrowth0, totalRewardGrowth1, 0, 0, 0, isTopTick);
    }
}

File 71 of 83 : IAlgebraEternalVirtualPool.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.7.6;
pragma abicoder v2;

import '../../IAlgebraVirtualPoolBase.sol';

interface IAlgebraEternalVirtualPool is IAlgebraVirtualPoolBase {
    /// @notice Change reward rates
    /// @param rate0 The new rate of main token distribution per sec
    /// @param rate1 The new rate of bonus token distribution per sec
    function setRates(uint128 rate0, uint128 rate1) external;

    function addRewards(uint256 token0Amount, uint256 token1Amount) external;

    function getInnerRewardsGrowth(int24 bottomTick, int24 topTick)
        external
        view
        returns (uint256 rewardGrowthInside0, uint256 rewardGrowthInside1);
}

File 72 of 83 : TestIncentiveId.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.7.6;
pragma abicoder v2;

import '../interfaces/IAlgebraFarming.sol';

import '../libraries/IncentiveId.sol';

/// @dev Test contract for IncentiveId
contract TestIncentiveId {
    function compute(IAlgebraFarming.IncentiveKey memory key) public pure returns (bytes32) {
        return IncentiveId.compute(key);
    }
}

File 73 of 83 : FarmingCenter.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.7.6;
pragma abicoder v2;
import './interfaces/IFarmingCenter.sol';
import './interfaces/IFarmingCenterVault.sol';

import 'algebra/contracts/interfaces/IAlgebraPool.sol';
import 'algebra/contracts/interfaces/IERC20Minimal.sol';

import 'algebra-periphery/contracts/interfaces/INonfungiblePositionManager.sol';
import 'algebra-periphery/contracts/base/Multicall.sol';
import 'algebra-periphery/contracts/base/ERC721Permit.sol';

import './base/PeripheryPayments.sol';
import './libraries/IncentiveId.sol';

/// @title Algebra main farming contract
/// @dev Manages farmings and performs entry, exit and other actions.
contract FarmingCenter is IFarmingCenter, ERC721Permit, Multicall, PeripheryPayments {
    IAlgebraLimitFarming public immutable override limitFarming;
    IAlgebraEternalFarming public immutable override eternalFarming;
    INonfungiblePositionManager public immutable override nonfungiblePositionManager;
    IFarmingCenterVault public immutable override farmingCenterVault;

    /// @dev The ID of the next token that will be minted. Skips 0
    uint256 private _nextId = 1;

    /// @dev saves addresses of virtual pools for pool
    mapping(address => VirtualPoolAddresses) private _virtualPoolAddresses;

    /// @dev deposits[tokenId] => Deposit
    mapping(uint256 => Deposit) public override deposits;

    mapping(uint256 => L2Nft) public override l2Nfts;

    /// @notice Represents the deposit of a liquidity NFT
    struct Deposit {
        uint256 L2TokenId;
        uint32 numberOfFarms;
        bool inLimitFarming;
        address owner;
    }

    /// @notice Represents the nft layer 2
    struct L2Nft {
        uint96 nonce; // the nonce for permits
        address operator; // the address that is approved for spending this token
        uint256 tokenId;
    }

    constructor(
        IAlgebraLimitFarming _limitFarming,
        IAlgebraEternalFarming _eternalFarming,
        INonfungiblePositionManager _nonfungiblePositionManager,
        IFarmingCenterVault _farmingCenterVault
    )
        ERC721Permit('Algebra Farming NFT-V2', 'ALGB-FARM', '2')
        PeripheryPayments(INonfungiblePositionManager(_nonfungiblePositionManager).WNativeToken())
    {
        limitFarming = _limitFarming;
        eternalFarming = _eternalFarming;
        nonfungiblePositionManager = _nonfungiblePositionManager;
        farmingCenterVault = _farmingCenterVault;
    }

    function checkAuthorizationForToken(uint256 tokenId) private view {
        require(_isApprovedOrOwner(msg.sender, tokenId), 'Not approved');
    }

    /// @notice Upon receiving a Algebra ERC721, creates the token deposit setting owner to `from`.
    /// @inheritdoc IERC721Receiver
    function onERC721Received(
        address,
        address from,
        uint256 tokenId,
        bytes calldata
    ) external override returns (bytes4) {
        require(msg.sender == address(nonfungiblePositionManager), 'not an Algebra nft');

        uint256 id = _nextId;
        Deposit storage newDeposit = deposits[tokenId];
        (newDeposit.L2TokenId, newDeposit.owner) = (id, from);

        l2Nfts[id].tokenId = tokenId;

        _mint(from, id);
        _nextId = id + 1;

        emit DepositTransferred(tokenId, address(0), from);

        return this.onERC721Received.selector;
    }

    function _getTokenBalanceOfVault(address token) private view returns (uint256 balance) {
        return IERC20Minimal(token).balanceOf(address(farmingCenterVault));
    }

    /// @inheritdoc IFarmingCenter
    function enterFarming(
        IncentiveKey memory key,
        uint256 tokenId,
        uint256 tokensLocked,
        bool isLimit
    ) external override {
        Deposit storage _deposit = deposits[tokenId];
        checkAuthorizationForToken(_deposit.L2TokenId);
        (uint32 numberOfFarms, bool inLimitFarming) = (_deposit.numberOfFarms, _deposit.inLimitFarming);
        numberOfFarms++;
        IAlgebraFarming _farming;
        if (isLimit) {
            require(!inLimitFarming, 'token already farmed');
            inLimitFarming = true;
            _farming = IAlgebraFarming(limitFarming);
        } else _farming = IAlgebraFarming(eternalFarming);

        (_deposit.numberOfFarms, _deposit.inLimitFarming) = (numberOfFarms, inLimitFarming);
        bytes32 incentiveId = IncentiveId.compute(key);
        (, , , , , address multiplierToken, ) = _farming.incentives(incentiveId);
        if (tokensLocked > 0) {
            uint256 balanceBefore = _getTokenBalanceOfVault(multiplierToken);
            TransferHelper.safeTransferFrom(multiplierToken, msg.sender, address(farmingCenterVault), tokensLocked);
            uint256 balanceAfter = _getTokenBalanceOfVault(multiplierToken);
            require(balanceAfter > balanceBefore, 'Insufficient tokens locked');
            tokensLocked = balanceAfter - balanceBefore;
            farmingCenterVault.lockTokens(tokenId, incentiveId, tokensLocked);
        }

        _farming.enterFarming(key, tokenId, tokensLocked);
    }

    /// @inheritdoc IFarmingCenter
    function exitFarming(
        IncentiveKey memory key,
        uint256 tokenId,
        bool isLimit
    ) external override {
        Deposit storage deposit = deposits[tokenId];
        checkAuthorizationForToken(deposit.L2TokenId);
        IAlgebraFarming _farming;

        deposit.numberOfFarms -= 1;
        deposit.owner = msg.sender;
        if (isLimit) {
            deposit.inLimitFarming = false;
            _farming = IAlgebraFarming(limitFarming);
        } else _farming = IAlgebraFarming(eternalFarming);

        _farming.exitFarming(key, tokenId, msg.sender);

        bytes32 incentiveId = IncentiveId.compute(key);
        (, , , , , address multiplierToken, ) = _farming.incentives(incentiveId);
        if (multiplierToken != address(0)) {
            farmingCenterVault.claimTokens(multiplierToken, msg.sender, tokenId, incentiveId);
        }
    }

    /// @inheritdoc IFarmingCenter
    function collect(INonfungiblePositionManager.CollectParams memory params)
        external
        override
        returns (uint256 amount0, uint256 amount1)
    {
        checkAuthorizationForToken(deposits[params.tokenId].L2TokenId);
        if (params.recipient == address(0)) {
            params.recipient = address(this);
        }
        return nonfungiblePositionManager.collect(params);
    }

    /// @inheritdoc IFarmingCenter
    function collectRewards(IncentiveKey memory key, uint256 tokenId)
        external
        override
        returns (uint256 reward, uint256 bonusReward)
    {
        checkAuthorizationForToken(deposits[tokenId].L2TokenId);
        address _virtualPool = _virtualPoolAddresses[address(key.pool)].eternalVirtualPool;
        if (_virtualPool != address(0)) {
            IAlgebraVirtualPool(_virtualPool).increaseCumulative(uint32(block.timestamp));
        }
        (reward, bonusReward) = eternalFarming.collectRewards(key, tokenId, msg.sender);
    }

    function _claimRewardFromFarming(
        IAlgebraFarming _farming,
        IERC20Minimal rewardToken,
        address to,
        uint256 amountRequested
    ) internal returns (uint256 reward) {
        return _farming.claimRewardFrom(rewardToken, msg.sender, to, amountRequested);
    }

    /// @inheritdoc IFarmingCenter
    function claimReward(
        IERC20Minimal rewardToken,
        address to,
        uint256 amountRequestedIncentive,
        uint256 amountRequestedEternal
    ) external override returns (uint256 reward) {
        if (amountRequestedIncentive != 0) {
            reward = _claimRewardFromFarming(limitFarming, rewardToken, to, amountRequestedIncentive);
        }
        if (amountRequestedEternal != 0) {
            reward += _claimRewardFromFarming(eternalFarming, rewardToken, to, amountRequestedEternal);
        }
    }

    /// @inheritdoc IFarmingCenter
    function connectVirtualPool(IAlgebraPool pool, address newVirtualPool) external override {
        bool isLimitFarming = msg.sender == address(limitFarming);
        require(isLimitFarming || msg.sender == address(eternalFarming), 'only farming can call this');

        VirtualPoolAddresses storage virtualPools = _virtualPoolAddresses[address(pool)];
        address newIncentive;
        if (pool.activeIncentive() == address(0)) {
            newIncentive = newVirtualPool; // turn on pool directly
        } else {
            if (newVirtualPool == address(0)) {
                // turn on directly another pool if it exists
                newIncentive = isLimitFarming ? virtualPools.eternalVirtualPool : virtualPools.limitVirtualPool;
            } else {
                newIncentive = address(this); // turn on via "proxy"
            }
        }

        pool.setIncentive(newIncentive);

        if (isLimitFarming) {
            virtualPools.limitVirtualPool = newVirtualPool;
        } else {
            virtualPools.eternalVirtualPool = newVirtualPool;
        }
    }

    /// @inheritdoc IFarmingCenter
    function withdrawToken(
        uint256 tokenId,
        address to,
        bytes memory data
    ) external override {
        require(to != address(this), 'cannot withdraw to farming');
        Deposit storage deposit = deposits[tokenId];
        uint256 l2TokenId = deposit.L2TokenId;

        checkAuthorizationForToken(l2TokenId);
        require(deposit.numberOfFarms == 0, 'cannot withdraw token while farmd');

        delete l2Nfts[l2TokenId];
        _burn(l2TokenId);
        delete deposits[tokenId];

        emit DepositTransferred(tokenId, msg.sender, address(0));
        nonfungiblePositionManager.safeTransferFrom(address(this), to, tokenId, data);
    }

    /**
     * @dev This function is called by the main pool when an initialized tick is crossed and two farmings are active at same time.
     * @param nextTick The crossed tick
     * @param zeroToOne The direction
     */
    function cross(int24 nextTick, bool zeroToOne) external override {
        VirtualPoolAddresses storage _virtualPoolAddressesForPool = _virtualPoolAddresses[msg.sender];

        IAlgebraVirtualPool(_virtualPoolAddressesForPool.eternalVirtualPool).cross(nextTick, zeroToOne);
        IAlgebraVirtualPool(_virtualPoolAddressesForPool.limitVirtualPool).cross(nextTick, zeroToOne);
    }

    /**
     * @dev This function is called by the main pool at start of the swap if two farmings are active at same time.
     * @param blockTimestamp The current block timestamp, truncated
     * @return status The current farming(s) status
     */
    function increaseCumulative(uint32 blockTimestamp) external override returns (Status status) {
        VirtualPoolAddresses storage _virtualPoolAddressesForPool = _virtualPoolAddresses[msg.sender];
        Status eternalStatus = IAlgebraVirtualPool(_virtualPoolAddressesForPool.eternalVirtualPool).increaseCumulative(
            blockTimestamp
        );

        Status limitStatus = IAlgebraVirtualPool(_virtualPoolAddressesForPool.limitVirtualPool).increaseCumulative(
            blockTimestamp
        );

        if (eternalStatus == Status.ACTIVE || limitStatus == Status.ACTIVE) {
            return Status.ACTIVE;
        } else if (limitStatus == Status.NOT_STARTED) {
            return Status.NOT_STARTED;
        }

        return Status.NOT_EXIST;
    }

    function virtualPoolAddresses(address pool) external view override returns (address limitVP, address eternalVP) {
        (limitVP, eternalVP) = (
            _virtualPoolAddresses[pool].limitVirtualPool,
            _virtualPoolAddresses[pool].eternalVirtualPool
        );
    }

    function _getAndIncrementNonce(uint256 tokenId) internal override returns (uint256) {
        return uint256(l2Nfts[tokenId].nonce++);
    }

    /// @inheritdoc IERC721
    function getApproved(uint256 tokenId) public view override(ERC721, IERC721) returns (address) {
        require(_exists(tokenId), 'ERC721: approved query for nonexistent token');

        return l2Nfts[tokenId].operator;
    }

    /// @dev Overrides _approve to use the operator in the position, which is packed with the position permit nonce
    function _approve(address to, uint256 tokenId) internal override(ERC721) {
        l2Nfts[tokenId].operator = to;
        emit Approval(ownerOf(tokenId), to, tokenId);
    }
}

File 74 of 83 : Multicall.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.7.6;
pragma abicoder v2;

import '../interfaces/IMulticall.sol';

/// @title Multicall
/// @notice Enables calling multiple methods in a single call to the contract
abstract contract Multicall is IMulticall {
    /// @inheritdoc IMulticall
    function multicall(bytes[] calldata data) external payable override returns (bytes[] memory results) {
        results = new bytes[](data.length);
        for (uint256 i = 0; i < data.length; i++) {
            (bool success, bytes memory result) = address(this).delegatecall(data[i]);

            if (!success) {
                // Next 5 lines from https://ethereum.stackexchange.com/a/83577
                if (result.length < 68) revert();
                assembly {
                    result := add(result, 0x04)
                }
                revert(abi.decode(result, (string)));
            }

            results[i] = result;
        }
    }
}

File 75 of 83 : PeripheryPayments.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;

import '@openzeppelin/contracts/token/ERC20/IERC20.sol';

import 'algebra-periphery/contracts/interfaces/IPeripheryPayments.sol';
import 'algebra-periphery/contracts/interfaces/external/IWNativeToken.sol';

import 'algebra-periphery/contracts/libraries/TransferHelper.sol';

abstract contract PeripheryPayments is IPeripheryPayments {
    address public immutable WNativeToken;

    constructor(address _WNativeToken) {
        WNativeToken = _WNativeToken;
    }

    receive() external payable {
        require(msg.sender == WNativeToken, 'Not WNativeToken');
    }

    /// @inheritdoc IPeripheryPayments
    function unwrapWNativeToken(uint256 amountMinimum, address recipient) external payable override {
        uint256 balanceWNativeToken = IWNativeToken(WNativeToken).balanceOf(address(this));
        require(balanceWNativeToken >= amountMinimum, 'Insufficient WNativeToken');

        if (balanceWNativeToken > 0) {
            IWNativeToken(WNativeToken).withdraw(balanceWNativeToken);
            TransferHelper.safeTransferNative(recipient, balanceWNativeToken);
        }
    }

    /// @inheritdoc IPeripheryPayments
    function sweepToken(
        address token,
        uint256 amountMinimum,
        address recipient
    ) external payable override {
        uint256 balanceToken = IERC20(token).balanceOf(address(this));
        require(balanceToken >= amountMinimum, 'Insufficient token');

        if (balanceToken > 0) {
            TransferHelper.safeTransfer(token, recipient, balanceToken);
        }
    }

    /// @inheritdoc IPeripheryPayments
    function refundNativeToken() external payable override {
        if (address(this).balance > 0) TransferHelper.safeTransferNative(msg.sender, address(this).balance);
    }
}

File 76 of 83 : IWNativeToken.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.7.6;

import '@openzeppelin/contracts/token/ERC20/IERC20.sol';

/// @title Interface for WNativeToken
interface IWNativeToken is IERC20 {
    /// @notice Deposit ether to get wrapped ether
    function deposit() external payable;

    /// @notice Withdraw wrapped ether to get ether
    function withdraw(uint256) external;
}

File 77 of 83 : ERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.7.0;

import "../../utils/Context.sol";
import "./IERC20.sol";
import "../../math/SafeMath.sol";

/**
 * @dev Implementation of the {IERC20} interface.
 *
 * This implementation is agnostic to the way tokens are created. This means
 * that a supply mechanism has to be added in a derived contract using {_mint}.
 * For a generic mechanism see {ERC20PresetMinterPauser}.
 *
 * TIP: For a detailed writeup see our guide
 * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
 * to implement supply mechanisms].
 *
 * We have followed general OpenZeppelin guidelines: functions revert instead
 * of returning `false` on failure. This behavior is nonetheless conventional
 * and does not conflict with the expectations of ERC20 applications.
 *
 * Additionally, an {Approval} event is emitted on calls to {transferFrom}.
 * This allows applications to reconstruct the allowance for all accounts just
 * by listening to said events. Other implementations of the EIP may not emit
 * these events, as it isn't required by the specification.
 *
 * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
 * functions have been added to mitigate the well-known issues around setting
 * allowances. See {IERC20-approve}.
 */
contract ERC20 is Context, IERC20 {
    using SafeMath for uint256;

    mapping (address => uint256) private _balances;

    mapping (address => mapping (address => uint256)) private _allowances;

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;
    uint8 private _decimals;

    /**
     * @dev Sets the values for {name} and {symbol}, initializes {decimals} with
     * a default value of 18.
     *
     * To select a different value for {decimals}, use {_setupDecimals}.
     *
     * All three of these values are immutable: they can only be set once during
     * construction.
     */
    constructor (string memory name_, string memory symbol_) {
        _name = name_;
        _symbol = symbol_;
        _decimals = 18;
    }

    /**
     * @dev Returns the name of the token.
     */
    function name() public view virtual returns (string memory) {
        return _name;
    }

    /**
     * @dev Returns the symbol of the token, usually a shorter version of the
     * name.
     */
    function symbol() public view virtual returns (string memory) {
        return _symbol;
    }

    /**
     * @dev Returns the number of decimals used to get its user representation.
     * For example, if `decimals` equals `2`, a balance of `505` tokens should
     * be displayed to a user as `5,05` (`505 / 10 ** 2`).
     *
     * Tokens usually opt for a value of 18, imitating the relationship between
     * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
     * called.
     *
     * NOTE: This information is only used for _display_ purposes: it in
     * no way affects any of the arithmetic of the contract, including
     * {IERC20-balanceOf} and {IERC20-transfer}.
     */
    function decimals() public view virtual returns (uint8) {
        return _decimals;
    }

    /**
     * @dev See {IERC20-totalSupply}.
     */
    function totalSupply() public view virtual override returns (uint256) {
        return _totalSupply;
    }

    /**
     * @dev See {IERC20-balanceOf}.
     */
    function balanceOf(address account) public view virtual override returns (uint256) {
        return _balances[account];
    }

    /**
     * @dev See {IERC20-transfer}.
     *
     * Requirements:
     *
     * - `recipient` cannot be the zero address.
     * - the caller must have a balance of at least `amount`.
     */
    function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
        _transfer(_msgSender(), recipient, amount);
        return true;
    }

    /**
     * @dev See {IERC20-allowance}.
     */
    function allowance(address owner, address spender) public view virtual override returns (uint256) {
        return _allowances[owner][spender];
    }

    /**
     * @dev See {IERC20-approve}.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function approve(address spender, uint256 amount) public virtual override returns (bool) {
        _approve(_msgSender(), spender, amount);
        return true;
    }

    /**
     * @dev See {IERC20-transferFrom}.
     *
     * Emits an {Approval} event indicating the updated allowance. This is not
     * required by the EIP. See the note at the beginning of {ERC20}.
     *
     * Requirements:
     *
     * - `sender` and `recipient` cannot be the zero address.
     * - `sender` must have a balance of at least `amount`.
     * - the caller must have allowance for ``sender``'s tokens of at least
     * `amount`.
     */
    function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
        _transfer(sender, recipient, amount);
        _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
        return true;
    }

    /**
     * @dev Atomically increases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
        _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
        return true;
    }

    /**
     * @dev Atomically decreases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `spender` must have allowance for the caller of at least
     * `subtractedValue`.
     */
    function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
        _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
        return true;
    }

    /**
     * @dev Moves tokens `amount` from `sender` to `recipient`.
     *
     * This is internal function is equivalent to {transfer}, and can be used to
     * e.g. implement automatic token fees, slashing mechanisms, etc.
     *
     * Emits a {Transfer} event.
     *
     * Requirements:
     *
     * - `sender` cannot be the zero address.
     * - `recipient` cannot be the zero address.
     * - `sender` must have a balance of at least `amount`.
     */
    function _transfer(address sender, address recipient, uint256 amount) internal virtual {
        require(sender != address(0), "ERC20: transfer from the zero address");
        require(recipient != address(0), "ERC20: transfer to the zero address");

        _beforeTokenTransfer(sender, recipient, amount);

        _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
        _balances[recipient] = _balances[recipient].add(amount);
        emit Transfer(sender, recipient, amount);
    }

    /** @dev Creates `amount` tokens and assigns them to `account`, increasing
     * the total supply.
     *
     * Emits a {Transfer} event with `from` set to the zero address.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     */
    function _mint(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: mint to the zero address");

        _beforeTokenTransfer(address(0), account, amount);

        _totalSupply = _totalSupply.add(amount);
        _balances[account] = _balances[account].add(amount);
        emit Transfer(address(0), account, amount);
    }

    /**
     * @dev Destroys `amount` tokens from `account`, reducing the
     * total supply.
     *
     * Emits a {Transfer} event with `to` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     * - `account` must have at least `amount` tokens.
     */
    function _burn(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: burn from the zero address");

        _beforeTokenTransfer(account, address(0), amount);

        _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
        _totalSupply = _totalSupply.sub(amount);
        emit Transfer(account, address(0), amount);
    }

    /**
     * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
     *
     * This internal function is equivalent to `approve`, and can be used to
     * e.g. set automatic allowances for certain subsystems, etc.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `owner` cannot be the zero address.
     * - `spender` cannot be the zero address.
     */
    function _approve(address owner, address spender, uint256 amount) internal virtual {
        require(owner != address(0), "ERC20: approve from the zero address");
        require(spender != address(0), "ERC20: approve to the zero address");

        _allowances[owner][spender] = amount;
        emit Approval(owner, spender, amount);
    }

    /**
     * @dev Sets {decimals} to a value other than the default one of 18.
     *
     * WARNING: This function should only be called from the constructor. Most
     * applications that interact with token contracts will not expect
     * {decimals} to ever change, and may work incorrectly if it does.
     */
    function _setupDecimals(uint8 decimals_) internal virtual {
        _decimals = decimals_;
    }

    /**
     * @dev Hook that is called before any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * will be to transferred to `to`.
     * - when `from` is zero, `amount` tokens will be minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens will be burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
}

File 78 of 83 : DogeDragon.sol
pragma solidity 0.7.6;


import '@openzeppelin/contracts/token/ERC20/ERC20.sol';


contract DogeDragon is ERC20 {

    constructor() ERC20("Doge Dragon", "DD") {

        _mint(_msgSender(), 1000000000 ether);
    }
}

File 79 of 83 : SafeERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.7.0;

import "./IERC20.sol";
import "../../math/SafeMath.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 SafeMath for uint256;
    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'
        // solhint-disable-next-line max-line-length
        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).add(value);
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

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

    /**
     * @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
            // solhint-disable-next-line max-line-length
            require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
        }
    }
}

File 80 of 83 : AlgebraVault.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.7.6;
pragma abicoder v2;

import '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import '@openzeppelin/contracts/token/ERC20/SafeERC20.sol';
import 'algebra/contracts/libraries/FullMath.sol';
import 'algebra-periphery/contracts/interfaces/ISwapRouter.sol';

contract AlgebraVault {
    using SafeERC20 for IERC20;
    using FullMath for uint256;

    address public stakingAddress;
    address public immutable ALGB;

    address public owner;
    address public relayer;

    uint256 public accumulatedALGB;

    uint256 public startTime;
    uint256 public count;
    uint256 public maxCount;
    uint256 public transferRate = 3600;
    uint256 public amountToTransferByBack;

    ISwapRouter immutable AlgebraRouter;

    event Swap(IERC20 swappedToken, bytes path, uint256 amountIn, uint256 amountOut);

    modifier onlyOwner() {
        require(msg.sender == owner, 'only owner can call this');
        _;
    }

    modifier onlyRelayerOrOwner() {
        require(msg.sender == relayer || msg.sender == owner, 'only relayer or owner can call this');
        _;
    }

    constructor(
        address _ALGB,
        address _stakingAddress,
        ISwapRouter _AlgebraRouter
    ) {
        owner = msg.sender;
        ALGB = _ALGB;
        stakingAddress = _stakingAddress;
        AlgebraRouter = _AlgebraRouter;
    }

    function swapToALGB(
        IERC20 tokenToSwap,
        bytes calldata path,
        uint256 amountOutMin,
        uint256 withFee
    ) external onlyRelayerOrOwner {
        uint256 _allowance = tokenToSwap.allowance(address(this), address(AlgebraRouter));
        uint256 balance = tokenToSwap.balanceOf(address(this));
        uint256 amountOut;
        if (_allowance < balance) {
            if (_allowance == 0) {
                tokenToSwap.safeApprove(address(AlgebraRouter), type(uint256).max);
            } else {
                try tokenToSwap.approve(address(AlgebraRouter), type(uint256).max) returns (bool res) {
                    require(res == true, 'Vault: approve failed');
                } catch {
                    tokenToSwap.safeApprove(address(AlgebraRouter), 0);
                    tokenToSwap.safeApprove(address(AlgebraRouter), type(uint256).max);
                }
            }
        }
        if (withFee == 0) {
            ISwapRouter.ExactInputParams memory params = ISwapRouter.ExactInputParams(
                path,
                address(this),
                block.timestamp,
                balance,
                amountOutMin
            );
            amountOut = AlgebraRouter.exactInput(params);
        } else {
            ISwapRouter.ExactInputSingleParams memory params = ISwapRouter.ExactInputSingleParams(
                address(tokenToSwap),
                ALGB,
                address(this),
                block.timestamp,
                balance,
                amountOutMin,
                0
            );
            amountOut = AlgebraRouter.exactInputSingleSupportingFeeOnTransferTokens(params);
        }

        emit Swap(tokenToSwap, path, balance, amountOut);
    }

    function transferALGB(uint256 percentToTransfer) external onlyRelayerOrOwner {
        IERC20 ALGBToken = IERC20(ALGB);

        uint256 amountToTransfer = (ALGBToken.balanceOf(address(this)) - accumulatedALGB).mulDiv(
            percentToTransfer,
            1e6
        );
        ALGBToken.transfer(stakingAddress, amountToTransfer);

        accumulatedALGB = ALGBToken.balanceOf(address(this));
    }

    function setRelayer(address _relayer) external onlyOwner {
        require(_relayer != address(0));
        relayer = _relayer;
    }

    function setStakingAddress(address _staking) external onlyOwner {
        require(_staking != address(0));
        stakingAddress = _staking;
    }

    function sweepTokens(
        IERC20 token,
        uint256 amount,
        address _to
    ) external onlyOwner {
        require(_to != address(0));
        token.transfer(_to, amount);
    }

    function transferALGBToStaking() external onlyRelayerOrOwner {
        require(startTime > 0, 'vault: start time is not set');
        require(startTime < block.timestamp, 'vault: hasnt started yet');
        uint256 N = (block.timestamp - startTime) / transferRate;

        if (N > maxCount) {
            IERC20 ALGBToken = IERC20(ALGB);
            uint256 numberOfTransfers = maxCount - count;
            require(numberOfTransfers > 0, 'vault: maxCount exceeded');

            ALGBToken.transfer(stakingAddress, amountToTransferByBack * numberOfTransfers);

            count += numberOfTransfers;
        } else if (N > count) {
            IERC20 ALGBToken = IERC20(ALGB);
            uint256 numberOfTransfers = N - count;
            ALGBToken.transfer(stakingAddress, amountToTransferByBack * numberOfTransfers);

            count = N;
        }
    }

    function collectAccumulatedALGB() external onlyOwner {
        IERC20 ALGBToken = IERC20(ALGB);
        uint256 balance = ALGBToken.balanceOf(address(this));

        if (accumulatedALGB > balance) {
            ALGBToken.transfer(msg.sender, balance);
        } else {
            ALGBToken.transfer(msg.sender, accumulatedALGB);
        }

        accumulatedALGB = 0;
    }

    ///// MANAGEMENT /////

    /**
     * @dev Sets start time of backend transfers campaign
     */
    function setStartTime(uint256 _startTime) external onlyOwner {
        startTime = _startTime;
    }

    function setAmountByBack(uint256 _amount) external onlyOwner {
        amountToTransferByBack = _amount;
    }

    function setMaxCount(uint256 _maxCount) external onlyOwner {
        maxCount = _maxCount;
    }

    function setRate(uint256 _rate) external onlyOwner {
        require(_rate > 0);
        transferRate = _rate;
    }

    function transferOwner(address _newOwner) external onlyOwner {
        require(_newOwner != address(0));
        owner = _newOwner;
    }
}

File 81 of 83 : ISwapRouter.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;
pragma abicoder v2;

import 'algebra/contracts/interfaces/callback/IAlgebraSwapCallback.sol';

/// @title Router token swapping functionality
/// @notice Functions for swapping tokens via Algebra
/// @dev Credit to Uniswap Labs under GPL-2.0-or-later license:
/// https://github.com/Uniswap/v3-periphery
interface ISwapRouter is IAlgebraSwapCallback {
    struct ExactInputSingleParams {
        address tokenIn;
        address tokenOut;
        address recipient;
        uint256 deadline;
        uint256 amountIn;
        uint256 amountOutMinimum;
        uint160 limitSqrtPrice;
    }

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

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

    /// @notice Swaps `amountIn` of one token for as much as possible of another along the specified path
    /// @dev Unlike standard swaps, handles transferring from user before the actual swap.
    /// @param params The parameters necessary for the multi-hop swap, encoded as `ExactInputParams` in calldata
    /// @return amountOut The amount of the received token
    function exactInputSingleSupportingFeeOnTransferTokens(ExactInputSingleParams calldata params)
        external
        returns (uint256 amountOut);
}

File 82 of 83 : IAlgebraSwapCallback.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Callback for IAlgebraPoolActions#swap
/// @notice Any contract that calls IAlgebraPoolActions#swap must implement this interface
/// @dev Credit to Uniswap Labs under GPL-2.0-or-later license:
/// https://github.com/Uniswap/v3-core/tree/main/contracts/interfaces
interface IAlgebraSwapCallback {
  /// @notice Called to `msg.sender` after executing a swap via IAlgebraPool#swap.
  /// @dev In the implementation you must pay the pool tokens owed for the swap.
  /// The caller of this method must be checked to be a AlgebraPool deployed by the canonical AlgebraFactory.
  /// amount0Delta and amount1Delta can both be 0 if no tokens were swapped.
  /// @param amount0Delta The amount of token0 that was sent (negative) or must be received (positive) by the pool by
  /// the end of the swap. If positive, the callback must send that amount of token0 to the pool.
  /// @param amount1Delta The amount of token1 that was sent (negative) or must be received (positive) by the pool by
  /// the end of the swap. If positive, the callback must send that amount of token1 to the pool.
  /// @param data Any data passed through by the caller via the IAlgebraPoolActions#swap call
  function algebraSwapCallback(
    int256 amount0Delta,
    int256 amount1Delta,
    bytes calldata data
  ) external;
}

File 83 of 83 : TestERC20.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.7.6;

import 'algebra/contracts/interfaces/IERC20Minimal.sol';

contract TestERC20 is IERC20Minimal {
    mapping(address => uint256) public override balanceOf;
    mapping(address => mapping(address => uint256)) public override allowance;

    constructor(uint256 amountToMint) {
        mint(msg.sender, amountToMint);
    }

    function mint(address to, uint256 amount) public {
        uint256 balanceNext = balanceOf[to] + amount;
        require(balanceNext >= amount, 'overflow balance');
        balanceOf[to] = balanceNext;
    }

    function transfer(address recipient, uint256 amount) external override returns (bool) {
        uint256 balanceBefore = balanceOf[msg.sender];
        require(balanceBefore >= amount, 'insufficient balance');
        balanceOf[msg.sender] = balanceBefore - amount;

        uint256 balanceRecipient = balanceOf[recipient];
        require(balanceRecipient + amount >= balanceRecipient, 'recipient balance overflow');
        if (!isDeflationary) {
            balanceOf[recipient] = balanceRecipient + amount;
        } else {
            balanceOf[recipient] = balanceRecipient + (amount - (amount * 5) / 100);
        }

        emit Transfer(msg.sender, recipient, amount);
        return true;
    }

    function approve(address spender, uint256 amount) external override returns (bool) {
        allowance[msg.sender][spender] = amount;
        emit Approval(msg.sender, spender, amount);
        return true;
    }

    bool isDeflationary = false;

    function setDefl() external {
        isDeflationary = true;
    }

    function transferFrom(
        address sender,
        address recipient,
        uint256 amount
    ) external override returns (bool) {
        uint256 allowanceBefore = allowance[sender][msg.sender];
        require(allowanceBefore >= amount, 'allowance insufficient');

        allowance[sender][msg.sender] = allowanceBefore - amount;

        uint256 balanceRecipient = balanceOf[recipient];
        require(balanceRecipient + amount >= balanceRecipient, 'overflow balance recipient');
        if (!isDeflationary) {
            balanceOf[recipient] = balanceRecipient + amount;
        } else {
            balanceOf[recipient] = balanceRecipient + (amount - (amount * 5) / 100);
        }
        uint256 balanceSender = balanceOf[sender];
        require(balanceSender >= amount, 'underflow balance sender');
        balanceOf[sender] = balanceSender - amount;

        emit Transfer(sender, recipient, amount);
        return true;
    }
}

Settings
{
  "optimizer": {
    "enabled": true,
    "runs": 99999999
  },
  "metadata": {
    "bytecodeHash": "none",
    "useLiteralContent": true
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "abi"
      ]
    }
  }
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"contract IAlgebraPoolDeployer","name":"_deployer","type":"address"},{"internalType":"contract INonfungiblePositionManager","name":"_nonfungiblePositionManager","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"contract IERC20Minimal","name":"rewardToken","type":"address"},{"indexed":true,"internalType":"contract IERC20Minimal","name":"bonusRewardToken","type":"address"},{"indexed":true,"internalType":"contract IAlgebraPool","name":"pool","type":"address"},{"indexed":false,"internalType":"address","name":"virtualPool","type":"address"},{"indexed":false,"internalType":"uint256","name":"startTime","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"endTime","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"reward","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"bonusReward","type":"uint256"},{"components":[{"internalType":"uint256","name":"tokenAmountForTier1","type":"uint256"},{"internalType":"uint256","name":"tokenAmountForTier2","type":"uint256"},{"internalType":"uint256","name":"tokenAmountForTier3","type":"uint256"},{"internalType":"uint32","name":"tier1Multiplier","type":"uint32"},{"internalType":"uint32","name":"tier2Multiplier","type":"uint32"},{"internalType":"uint32","name":"tier3Multiplier","type":"uint32"}],"indexed":false,"internalType":"struct IAlgebraFarming.Tiers","name":"tiers","type":"tuple"},{"indexed":false,"internalType":"address","name":"multiplierToken","type":"address"},{"indexed":false,"internalType":"uint24","name":"minimalAllowedPositionWidth","type":"uint24"}],"name":"EternalFarmingCreated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":true,"internalType":"bytes32","name":"incentiveId","type":"bytes32"},{"indexed":true,"internalType":"address","name":"rewardAddress","type":"address"},{"indexed":false,"internalType":"address","name":"bonusRewardToken","type":"address"},{"indexed":false,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"uint256","name":"reward","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"bonusReward","type":"uint256"}],"name":"FarmEnded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":true,"internalType":"bytes32","name":"incentiveId","type":"bytes32"},{"indexed":false,"internalType":"uint128","name":"liquidity","type":"uint128"},{"indexed":false,"internalType":"uint256","name":"tokensLocked","type":"uint256"}],"name":"FarmEntered","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"farmingCenter","type":"address"}],"name":"FarmingCenter","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"contract IERC20Minimal","name":"rewardToken","type":"address"},{"indexed":true,"internalType":"contract IERC20Minimal","name":"bonusRewardToken","type":"address"},{"indexed":true,"internalType":"contract IAlgebraPool","name":"pool","type":"address"},{"indexed":false,"internalType":"address","name":"virtualPool","type":"address"},{"indexed":false,"internalType":"uint256","name":"startTime","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"endTime","type":"uint256"}],"name":"IncentiveAttached","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"contract IERC20Minimal","name":"rewardToken","type":"address"},{"indexed":true,"internalType":"contract IERC20Minimal","name":"bonusRewardToken","type":"address"},{"indexed":true,"internalType":"contract IAlgebraPool","name":"pool","type":"address"},{"indexed":false,"internalType":"address","name":"virtualPool","type":"address"},{"indexed":false,"internalType":"uint256","name":"startTime","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"endTime","type":"uint256"}],"name":"IncentiveDetached","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"incentiveMaker","type":"address"}],"name":"IncentiveMaker","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"reward","type":"uint256"},{"indexed":true,"internalType":"address","name":"rewardAddress","type":"address"},{"indexed":true,"internalType":"address","name":"owner","type":"address"}],"name":"RewardClaimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"rewardAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"bonusRewardAmount","type":"uint256"},{"indexed":false,"internalType":"bytes32","name":"incentiveId","type":"bytes32"}],"name":"RewardsAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"bytes32","name":"incentiveId","type":"bytes32"},{"indexed":false,"internalType":"uint256","name":"rewardAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"bonusRewardAmount","type":"uint256"}],"name":"RewardsCollected","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint128","name":"rewardRate","type":"uint128"},{"indexed":false,"internalType":"uint128","name":"bonusRewardRate","type":"uint128"},{"indexed":false,"internalType":"bytes32","name":"incentiveId","type":"bytes32"}],"name":"RewardsRatesChanged","type":"event"},{"inputs":[{"components":[{"internalType":"contract IERC20Minimal","name":"rewardToken","type":"address"},{"internalType":"contract IERC20Minimal","name":"bonusRewardToken","type":"address"},{"internalType":"contract IAlgebraPool","name":"pool","type":"address"},{"internalType":"uint256","name":"startTime","type":"uint256"},{"internalType":"uint256","name":"endTime","type":"uint256"}],"internalType":"struct IIncentiveKey.IncentiveKey","name":"key","type":"tuple"},{"internalType":"uint256","name":"rewardAmount","type":"uint256"},{"internalType":"uint256","name":"bonusRewardAmount","type":"uint256"}],"name":"addRewards","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"contract IERC20Minimal","name":"rewardToken","type":"address"},{"internalType":"contract IERC20Minimal","name":"bonusRewardToken","type":"address"},{"internalType":"contract IAlgebraPool","name":"pool","type":"address"},{"internalType":"uint256","name":"startTime","type":"uint256"},{"internalType":"uint256","name":"endTime","type":"uint256"}],"internalType":"struct IIncentiveKey.IncentiveKey","name":"key","type":"tuple"}],"name":"attachIncentive","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20Minimal","name":"rewardToken","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amountRequested","type":"uint256"}],"name":"claimReward","outputs":[{"internalType":"uint256","name":"reward","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20Minimal","name":"rewardToken","type":"address"},{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amountRequested","type":"uint256"}],"name":"claimRewardFrom","outputs":[{"internalType":"uint256","name":"reward","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"contract IERC20Minimal","name":"rewardToken","type":"address"},{"internalType":"contract IERC20Minimal","name":"bonusRewardToken","type":"address"},{"internalType":"contract IAlgebraPool","name":"pool","type":"address"},{"internalType":"uint256","name":"startTime","type":"uint256"},{"internalType":"uint256","name":"endTime","type":"uint256"}],"internalType":"struct IIncentiveKey.IncentiveKey","name":"key","type":"tuple"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"_owner","type":"address"}],"name":"collectRewards","outputs":[{"internalType":"uint256","name":"reward","type":"uint256"},{"internalType":"uint256","name":"bonusReward","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"contract IERC20Minimal","name":"rewardToken","type":"address"},{"internalType":"contract IERC20Minimal","name":"bonusRewardToken","type":"address"},{"internalType":"contract IAlgebraPool","name":"pool","type":"address"},{"internalType":"uint256","name":"startTime","type":"uint256"},{"internalType":"uint256","name":"endTime","type":"uint256"}],"internalType":"struct IIncentiveKey.IncentiveKey","name":"key","type":"tuple"},{"components":[{"internalType":"uint256","name":"reward","type":"uint256"},{"internalType":"uint256","name":"bonusReward","type":"uint256"},{"internalType":"uint128","name":"rewardRate","type":"uint128"},{"internalType":"uint128","name":"bonusRewardRate","type":"uint128"},{"internalType":"uint24","name":"minimalPositionWidth","type":"uint24"},{"internalType":"address","name":"multiplierToken","type":"address"}],"internalType":"struct IAlgebraEternalFarming.IncentiveParams","name":"params","type":"tuple"},{"components":[{"internalType":"uint256","name":"tokenAmountForTier1","type":"uint256"},{"internalType":"uint256","name":"tokenAmountForTier2","type":"uint256"},{"internalType":"uint256","name":"tokenAmountForTier3","type":"uint256"},{"internalType":"uint32","name":"tier1Multiplier","type":"uint32"},{"internalType":"uint32","name":"tier2Multiplier","type":"uint32"},{"internalType":"uint32","name":"tier3Multiplier","type":"uint32"}],"internalType":"struct IAlgebraFarming.Tiers","name":"tiers","type":"tuple"}],"name":"createEternalFarming","outputs":[{"internalType":"address","name":"virtualPool","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"deployer","outputs":[{"internalType":"contract IAlgebraPoolDeployer","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"contract IERC20Minimal","name":"rewardToken","type":"address"},{"internalType":"contract IERC20Minimal","name":"bonusRewardToken","type":"address"},{"internalType":"contract IAlgebraPool","name":"pool","type":"address"},{"internalType":"uint256","name":"startTime","type":"uint256"},{"internalType":"uint256","name":"endTime","type":"uint256"}],"internalType":"struct IIncentiveKey.IncentiveKey","name":"key","type":"tuple"}],"name":"detachIncentive","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"contract IERC20Minimal","name":"rewardToken","type":"address"},{"internalType":"contract IERC20Minimal","name":"bonusRewardToken","type":"address"},{"internalType":"contract IAlgebraPool","name":"pool","type":"address"},{"internalType":"uint256","name":"startTime","type":"uint256"},{"internalType":"uint256","name":"endTime","type":"uint256"}],"internalType":"struct IIncentiveKey.IncentiveKey","name":"key","type":"tuple"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"tokensLocked","type":"uint256"}],"name":"enterFarming","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"contract IERC20Minimal","name":"rewardToken","type":"address"},{"internalType":"contract IERC20Minimal","name":"bonusRewardToken","type":"address"},{"internalType":"contract IAlgebraPool","name":"pool","type":"address"},{"internalType":"uint256","name":"startTime","type":"uint256"},{"internalType":"uint256","name":"endTime","type":"uint256"}],"internalType":"struct IIncentiveKey.IncentiveKey","name":"key","type":"tuple"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"_owner","type":"address"}],"name":"exitFarming","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"farmingCenter","outputs":[{"internalType":"contract IFarmingCenter","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"farms","outputs":[{"internalType":"uint128","name":"liquidity","type":"uint128"},{"internalType":"int24","name":"tickLower","type":"int24"},{"internalType":"int24","name":"tickUpper","type":"int24"},{"internalType":"uint256","name":"innerRewardGrowth0","type":"uint256"},{"internalType":"uint256","name":"innerRewardGrowth1","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"contract IERC20Minimal","name":"rewardToken","type":"address"},{"internalType":"contract IERC20Minimal","name":"bonusRewardToken","type":"address"},{"internalType":"contract IAlgebraPool","name":"pool","type":"address"},{"internalType":"uint256","name":"startTime","type":"uint256"},{"internalType":"uint256","name":"endTime","type":"uint256"}],"internalType":"struct IIncentiveKey.IncentiveKey","name":"key","type":"tuple"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getRewardInfo","outputs":[{"internalType":"uint256","name":"reward","type":"uint256"},{"internalType":"uint256","name":"bonusReward","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"incentives","outputs":[{"internalType":"uint256","name":"totalReward","type":"uint256"},{"internalType":"uint256","name":"bonusReward","type":"uint256"},{"internalType":"address","name":"virtualPoolAddress","type":"address"},{"internalType":"uint24","name":"minimalPositionWidth","type":"uint24"},{"internalType":"uint224","name":"totalLiquidity","type":"uint224"},{"internalType":"address","name":"multiplierToken","type":"address"},{"components":[{"internalType":"uint256","name":"tokenAmountForTier1","type":"uint256"},{"internalType":"uint256","name":"tokenAmountForTier2","type":"uint256"},{"internalType":"uint256","name":"tokenAmountForTier3","type":"uint256"},{"internalType":"uint32","name":"tier1Multiplier","type":"uint32"},{"internalType":"uint32","name":"tier2Multiplier","type":"uint32"},{"internalType":"uint32","name":"tier3Multiplier","type":"uint32"}],"internalType":"struct IAlgebraFarming.Tiers","name":"tiers","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nonfungiblePositionManager","outputs":[{"internalType":"contract INonfungiblePositionManager","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"contract IERC20Minimal","name":"","type":"address"}],"name":"rewards","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_farmingCenter","type":"address"}],"name":"setFarmingCenterAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_incentiveMaker","type":"address"}],"name":"setIncentiveMaker","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"contract IERC20Minimal","name":"rewardToken","type":"address"},{"internalType":"contract IERC20Minimal","name":"bonusRewardToken","type":"address"},{"internalType":"contract IAlgebraPool","name":"pool","type":"address"},{"internalType":"uint256","name":"startTime","type":"uint256"},{"internalType":"uint256","name":"endTime","type":"uint256"}],"internalType":"struct IIncentiveKey.IncentiveKey","name":"key","type":"tuple"},{"internalType":"uint128","name":"rewardRate","type":"uint128"},{"internalType":"uint128","name":"bonusRewardRate","type":"uint128"}],"name":"setRates","outputs":[],"stateMutability":"nonpayable","type":"function"}]

60e06040523480156200001157600080fd5b506040516200592838038062005928833981016040819052620000349162000059565b33606090811b60c0526001600160601b031992811b831660a0521b16608052620000b0565b600080604083850312156200006c578182fd5b8251620000798162000097565b60208401519092506200008c8162000097565b809150509250929050565b6001600160a01b0381168114620000ad57600080fd5b50565b60805160601c60a05160601c60c05160601c615833620000f560003980610cad52806113a352508061134d528061260b525080610fbe528061262c52506158336000f3fe608060405234801561001057600080fd5b50600436106101515760003560e01c8063826cc0a1116100cd578063dd56e5d811610081578063e70b9e2711610066578063e70b9e27146102bc578063f43930a3146102cf578063fe4282fb146102e257610151565b8063dd56e5d8146102a1578063df42efda146102a957610151565b8063b44a2722116100b2578063b44a272214610271578063b58a723914610286578063d5f394881461029957610151565b8063826cc0a11461024b57806392aa2d891461025e57610151565b80633ee0dd02116101245780636394adbb116101095780636394adbb14610204578063704972f414610217578063779fa0c41461023857610151565b80633ee0dd02146101cb57806360777795146101de57610151565b80630705506b146101565780630a5307541461016b57806327e6a99a146101945780632f2d783d146101b8575b600080fd5b6101696101643660046133b4565b6102f5565b005b61017e6101793660046131c2565b61084b565b60405161018b9190613b66565b60405180910390f35b6101a76101a23660046134d7565b610885565b60405161018b959493929190613ab7565b61017e6101c6366004613212565b6108f4565b6101696101d9366004613252565b61090c565b6101f16101ec3660046131aa565b610950565b60405161018b9796959493929190613b98565b610169610212366004613252565b610a33565b61022a61022536600461338a565b610a73565b60405161018b929190613b8a565b610169610246366004613128565b610c95565b6101696102593660046133f4565b610d6e565b61016961026c366004613350565b610eae565b610279610fbc565b60405161018b9190613564565b61027961029436600461326d565b610fe0565b61027961134b565b61027961136f565b6101696102b7366004613128565b61138b565b61017e6102ca36600461317d565b611462565b6101696102dd3660046133f4565b61147f565b61022a6102f03660046133b4565b6116f9565b60005473ffffffffffffffffffffffffffffffffffffffff16331461031957600080fd5b600061032484611a65565b6000848152600460209081526040808320848452825291829020825160a08101845281546fffffffffffffffffffffffffffffffff81168083527001000000000000000000000000000000008204600290810b810b810b95840195909552730100000000000000000000000000000000000000909104840b840b840b948201949094526001820154606082015291015460808201529192506103fb576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103f29061394e565b60405180910390fd5b60008281526001602052604080822060028101548883015183517fe76c01e40000000000000000000000000000000000000000000000000000000081529351929473ffffffffffffffffffffffffffffffffffffffff92831694909384938493169163e76c01e49160048083019260e0929190829003018186803b15801561048257600080fd5b505afa158015610496573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104ba9190613427565b50505060208a01516040808c015190517f0f1019bc00000000000000000000000000000000000000000000000000000000815294965073ffffffffffffffffffffffffffffffffffffffff8a169550630f1019bc9461052494504293506000908890600401613c6c565b600060405180830381600087803b15801561053e57600080fd5b505af1158015610552573d6000803e3d6000fd5b505050506000808573ffffffffffffffffffffffffffffffffffffffff16630bd6f20089602001518a604001516040518363ffffffff1660e01b815260040161059c929190613710565b604080518083038186803b1580156105b357600080fd5b505afa1580156105c7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105eb91906134f8565b915091508573ffffffffffffffffffffffffffffffffffffffff16630f1019bc428a602001518b604001516106358d600001516fffffffffffffffffffffffffffffffff16611a96565b600003886040518663ffffffff1660e01b8152600401610659959493929190613c6c565b600060405180830381600087803b15801561067357600080fd5b505af1158015610687573d6000803e3d6000fd5b505050506106c38860600151830389600001516fffffffffffffffffffffffffffffffff16700100000000000000000000000000000000611aa7565b6106fb896080015183038a600001516fffffffffffffffffffffffffffffffff16700100000000000000000000000000000000611aa7565b73ffffffffffffffffffffffffffffffffffffffff8c16600090815260036020526040902091965094509250508315905061075d57895173ffffffffffffffffffffffffffffffffffffffff1660009081526020829052604090208054840190555b8115610793576020808b015173ffffffffffffffffffffffffffffffffffffffff16600090815290829052604090208054830190555b60008981526004602090815260408083208a8452825280832080547fffffffffffffffffffff0000000000000000000000000000000000000000000016815560018101849055600201929092558b51908c0151915173ffffffffffffffffffffffffffffffffffffffff9091169189918c917f7f2557bb15dcf63e3d029ef1dcb4333563fcd78edf263b8fe42ed3adb925ff849161083791908e908a908a906135b5565b60405180910390a450505050505050505050565b6000805473ffffffffffffffffffffffffffffffffffffffff16331461087057600080fd5b61087c85858585611b5b565b95945050505050565b60046020908152600092835260408084209091529082529020805460018201546002928301546fffffffffffffffffffffffffffffffff8316937001000000000000000000000000000000008404810b937301000000000000000000000000000000000000009004900b919085565b600061090284338585611b5b565b90505b9392505050565b60025473ffffffffffffffffffffffffffffffffffffffff16331461093057600080fd5b600061093f8260400151611c69565b91505061094c8282611d18565b5050565b600160208181526000928352604092839020805492810154600282015460038301546004840154875160c0810189526005860154815260068601549681019690965260078501549786019790975260089093015463ffffffff8082166060870152640100000000820481166080870152680100000000000000009091041660a08501529394909373ffffffffffffffffffffffffffffffffffffffff808216947401000000000000000000000000000000000000000090920462ffffff16937bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1692169087565b60025473ffffffffffffffffffffffffffffffffffffffff163314610a5757600080fd5b6000610a668260400151611c69565b91505061094c8282611e91565b6000806000610a8185611a65565b6000858152600460209081526040808320848452825291829020825160a08101845281546fffffffffffffffffffffffffffffffff81168083527001000000000000000000000000000000008204600290810b810b810b95840195909552730100000000000000000000000000000000000000909104840b840b840b94820194909452600182015460608201529101546080820152919250610b4f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103f29061394e565b600082815260016020908152604080832060020154918401518482015191517f0bd6f20000000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff909316939283928592630bd6f20092610bc29290600401613710565b604080518083038186803b158015610bd957600080fd5b505afa158015610bed573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c1191906134f8565b91509150610c4d8460600151830385600001516fffffffffffffffffffffffffffffffff16700100000000000000000000000000000000611aa7565b610c858560800151830386600001516fffffffffffffffffffffffffffffffff16700100000000000000000000000000000000611aa7565b909a909950975050505050505050565b3373ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001614610cd757600080fd5b60025473ffffffffffffffffffffffffffffffffffffffff82811691161415610cff57600080fd5b600280547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff83169081179091556040517f7aa996b8cecffbf29f5d2a3564db96e010e2dcae822601312970ae9690ec1c5290600090a250565b6000610d7984611a65565b6000818152600160205260409020805491925090610dc3576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103f290613985565b610dcf85858584611ff8565b909450925083831715610ea75760028101546040517ffc41aa0900000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff90911690819063fc41aa0990610e389088908890600401613b8a565b600060405180830381600087803b158015610e5257600080fd5b505af1158015610e66573d6000803e3d6000fd5b505050507f8b0312d8047895ce795779b66b705ccd39b1ece7c162f642c72d76a785d1b68a858585604051610e9d93929190613c56565b60405180910390a1505b5050505050565b60025473ffffffffffffffffffffffffffffffffffffffff163314610ed257600080fd5b6000610edd84611a65565b600081815260016020526040908190206002015490517f7f463bb800000000000000000000000000000000000000000000000000000000815291925073ffffffffffffffffffffffffffffffffffffffff16908190637f463bb890610f489087908790600401613af4565b600060405180830381600087803b158015610f6257600080fd5b505af1158015610f76573d6000803e3d6000fd5b505050507f1864e4cc903d98e44820faebd48409c410a2ad20adb3173984ba41ae2828805e848484604051610fad93929190613b17565b60405180910390a15050505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b60025460009073ffffffffffffffffffffffffffffffffffffffff16331461100757600080fd5b60006110168560400151611c69565b91505073ffffffffffffffffffffffffffffffffffffffff811615611067576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103f290613724565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1630866040015160405161109a90613014565b6110a693929190613585565b604051809103906000f0801580156110c2573d6000803e3d6000fd5b50915060006110e683878760000151886020015189608001518a60a001518a612311565b87600001886020018281525082815250829350505050856040015173ffffffffffffffffffffffffffffffffffffffff16866020015173ffffffffffffffffffffffffffffffffffffffff16876000015173ffffffffffffffffffffffffffffffffffffffff167f0402a2abfe823f7036d0b24f3e7c00b60362a9e8214880b0fa5a74d6b216caf3868a606001518b608001518b600001518c602001518c8e60a001518f608001516040516111a2989796959493929190613619565b60405180910390a4845160208601516040517ffc41aa0900000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff86169263fc41aa099261120192600401613b8a565b600060405180830381600087803b15801561121b57600080fd5b505af115801561122f573d6000803e3d6000fd5b505050604080870151606088015191517f7f463bb800000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff87169350637f463bb89261128e9291600401613af4565b600060405180830381600087803b1580156112a857600080fd5b505af11580156112bc573d6000803e3d6000fd5b5050865160208801516040517f8b0312d8047895ce795779b66b705ccd39b1ece7c162f642c72d76a785d1b68a94506112f793508590613c56565b60405180910390a17f1864e4cc903d98e44820faebd48409c410a2ad20adb3173984ba41ae2828805e856040015186606001518360405161133a93929190613b17565b60405180910390a150509392505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b60005473ffffffffffffffffffffffffffffffffffffffff1681565b3373ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016146113cd57600080fd5b60005473ffffffffffffffffffffffffffffffffffffffff828116911614156113f557600080fd5b600080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff8316908117825560405190917f29f9e1ebeee07596f3165f3e42cb9d4d8d22b0481e968d6c74be3dd037c15d9b91a250565b600360209081526000928352604080842090915290825290205481565b60005473ffffffffffffffffffffffffffffffffffffffff1633146114a357600080fd5b60008060008060006114b68888886125a9565b60008c81526004602090815260408083208884529182905290912054959a5093985091965094509250906fffffffffffffffffffffffffffffffff1615611529576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103f29061375b565b6000808373ffffffffffffffffffffffffffffffffffffffff16630bd6f20088886040518363ffffffff1660e01b8152600401611567929190613710565b604080518083038186803b15801561157e57600080fd5b505afa158015611592573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115b691906134f8565b915091506040518060a00160405280866fffffffffffffffffffffffffffffffff1681526020018860020b81526020018760020b8152602001838152602001828152508360008a815260200190815260200160002060008201518160000160006101000a8154816fffffffffffffffffffffffffffffffff02191690836fffffffffffffffffffffffffffffffff16021790555060208201518160000160106101000a81548162ffffff021916908360020b62ffffff16021790555060408201518160000160136101000a81548162ffffff021916908360020b62ffffff1602179055506060820151816001015560808201518160020155905050878a7f4a9757f8f71efdde4b041ff384e461c5707a95d74463b60892bd1f7b9c34a289878c6040516116e4929190613b44565b60405180910390a35050505050505050505050565b60008054819073ffffffffffffffffffffffffffffffffffffffff16331461172057600080fd5b600061172b86611a65565b6000818152600160205260409020805491925090611775576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103f290613985565b6002808201546000888152600460209081526040808320878452825291829020825160a08101845281546fffffffffffffffffffffffffffffffff81168083527001000000000000000000000000000000008204880b880b880b948301949094527301000000000000000000000000000000000000009004860b860b860b938101939093526001810154606084015290930154608082015273ffffffffffffffffffffffffffffffffffffffff9091169161185c576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103f29061394e565b6000808373ffffffffffffffffffffffffffffffffffffffff16630bd6f200846020015185604001516040518363ffffffff1660e01b81526004016118a2929190613710565b604080518083038186803b1580156118b957600080fd5b505afa1580156118cd573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118f191906134f8565b9150915061192d8360600151830384600001516fffffffffffffffffffffffffffffffff16700100000000000000000000000000000000611aa7565b6119658460800151830385600001516fffffffffffffffffffffffffffffffff16700100000000000000000000000000000000611aa7565b60008c81526004602090815260408083208b845282528083206001810188905560020186905573ffffffffffffffffffffffffffffffffffffffff8e16835260039091529020919950975088156119e3578b5173ffffffffffffffffffffffffffffffffffffffff16600090815260208290526040902080548a0190555b8715611a19576020808d015173ffffffffffffffffffffffffffffffffffffffff16600090815290829052604090208054890190555b7f15b2e0f32b50efdbbdee9ec7884ed3c61e6209b1b395e5762011a6734b86f7b58b888b8b604051611a4e9493929190613b6f565b60405180910390a150505050505050935093915050565b600081604051602001611a789190613a61565b6040516020818303038152906040528051906020012090505b919050565b80600f81900b8114611a9157600080fd5b6000838302817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff85870982811083820303915050808411611ae757600080fd5b80611af757508290049050610905565b8385870960008581038616958690049560026003880281188089028203028089028203028089028203028089028203028089028203028089029091030291819003819004600101858411909403939093029190930391909104170290509392505050565b73ffffffffffffffffffffffffffffffffffffffff808416600090815260036020908152604080832093881683529290522054811580611b9a57508082115b15611ba3578091505b73ffffffffffffffffffffffffffffffffffffffff80851660009081526003602090815260408083209389168352929052208282039055611be585848461295b565b8373ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fe6ac6a784fb43c9f6329d2f5c82f88a26a93bad4281f7780725af5f071f0aafa85604051611c599190613b66565b60405180910390a4949350505050565b600080546040517f32dc5a25000000000000000000000000000000000000000000000000000000008152829173ffffffffffffffffffffffffffffffffffffffff16906332dc5a2590611cc0908690600401613564565b604080518083038186803b158015611cd757600080fd5b505afa158015611ceb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d0f9190613144565b91509150915091565b73ffffffffffffffffffffffffffffffffffffffff8116611d65576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103f2906139bc565b8073ffffffffffffffffffffffffffffffffffffffff1660016000611d8985611a65565b815260208101919091526040016000206002015473ffffffffffffffffffffffffffffffffffffffff1614611dea576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103f290613826565b611df982604001516000612b30565b816040015173ffffffffffffffffffffffffffffffffffffffff16826020015173ffffffffffffffffffffffffffffffffffffffff16836000015173ffffffffffffffffffffffffffffffffffffffff167f0ab9cc241fe819ccf1100504defd5fe1366c71aba48092174547ccd7191f3d068486606001518760800151604051611e85939291906135eb565b60405180910390a45050565b73ffffffffffffffffffffffffffffffffffffffff811615611edf576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103f290613724565b600060016000611eee85611a65565b815260208101919091526040016000206002015473ffffffffffffffffffffffffffffffffffffffff16905080611f51576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103f290613792565b611f5f836040015182612b30565b826040015173ffffffffffffffffffffffffffffffffffffffff16836020015173ffffffffffffffffffffffffffffffffffffffff16846000015173ffffffffffffffffffffffffffffffffffffffff167f6d3b554600fa5af9295315554801e6206cbdb85866f653f9488e5875c06a6b648487606001518860800151604051611feb939291906135eb565b60405180910390a4505050565b600080841561217d5785516040517f70a0823100000000000000000000000000000000000000000000000000000000815260009073ffffffffffffffffffffffffffffffffffffffff8316906370a0823190612058903090600401613564565b60206040518083038186803b15801561207057600080fd5b505afa158015612084573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120a891906134bf565b90506120b68233308a612bbe565b6040517f70a08231000000000000000000000000000000000000000000000000000000008152819073ffffffffffffffffffffffffffffffffffffffff8416906370a082319061210a903090600401613564565b60206040518083038186803b15801561212257600080fd5b505afa158015612136573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061215a91906134bf565b9450841161216757600080fd5b845493819003936121789085612d9b565b855550505b83156123085760208601516040517f70a0823100000000000000000000000000000000000000000000000000000000815260009073ffffffffffffffffffffffffffffffffffffffff8316906370a08231906121dd903090600401613564565b60206040518083038186803b1580156121f557600080fd5b505afa158015612209573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061222d91906134bf565b905061223b82333089612bbe565b6040517f70a08231000000000000000000000000000000000000000000000000000000008152819073ffffffffffffffffffffffffffffffffffffffff8416906370a082319061228f903090600401613564565b60206040518083038186803b1580156122a757600080fd5b505afa1580156122bb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122df91906134bf565b935083116122ec57600080fd5b600185015492819003926123009084612d9b565b600186015550505b94509492505050565b600080600061232489604001518b612b30565b61232d89611a65565b600081815260016020526040902090935061234a8a8a8a84611ff8565b9093509150621b136862ffffff88161315612391576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103f290613a2a565b6002810180547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff8d16177fffffffffffffffffff000000ffffffffffffffffffffffffffffffffffffffff167401000000000000000000000000000000000000000062ffffff8a160217905561c350612426608087016060880161351b565b63ffffffff1611158015612451575061c35061244860a087016080880161351b565b63ffffffff1611155b8015612474575061c35061246b60c0870160a0880161351b565b63ffffffff1611155b6124aa576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103f2906138f1565b6127106124bd608087016060880161351b565b63ffffffff16101580156124e857506127106124df60a087016080880161351b565b63ffffffff1610155b801561250b575061271061250260c0870160a0880161351b565b63ffffffff1610155b612541576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103f2906137c9565b84600582016125508282613c9e565b505060040180547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff96909616959095179094559098909750919550909350505050565b60008060008060006125ba88611a65565b6000818152600160205260409020805491965090612604576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103f290613985565b60006126517f00000000000000000000000000000000000000000000000000000000000000007f00000000000000000000000000000000000000000000000000000000000000008b612db1565b60408e0151929950909750955090915073ffffffffffffffffffffffffffffffffffffffff8083169116146126b2576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103f29061385d565b6000846fffffffffffffffffffffffffffffffff16116126fe576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103f290613894565b60008173ffffffffffffffffffffffffffffffffffffffff1663e76c01e46040518163ffffffff1660e01b815260040160e06040518083038186803b15801561274657600080fd5b505afa15801561275a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061277e9190613427565b50506040805160c08101825260058a0154815260068a0154602082015260078a015491810191909152600889015463ffffffff8082166060840152640100000000820481166080840152680100000000000000009091041660a0820152939550600094506127f2938e93509150612ea29050565b9050600061281b6fffffffffffffffffffffffffffffffff881663ffffffff8416612710611aa7565b90506fffffffffffffffffffffffffffffffff81111561283a57600080fd5b60028581015491975073ffffffffffffffffffffffffffffffffffffffff82169650879174010000000000000000000000000000000000000000900462ffffff16908a810b908a900b038113156128bd576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103f2906139f3565b8673ffffffffffffffffffffffffffffffffffffffff16630f1019bc428c8c6128f78d6fffffffffffffffffffffffffffffffff16611a96565b896040518663ffffffff1660e01b8152600401612918959493929190613c6c565b600060405180830381600087803b15801561293257600080fd5b505af1158015612946573d6000803e3d6000fd5b50505050505050505050939792965093509350565b6040805173ffffffffffffffffffffffffffffffffffffffff8481166024830152604480830185905283518084039091018152606490920183526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fa9059cbb000000000000000000000000000000000000000000000000000000001781529251825160009485949389169392918291908083835b60208310612a3057805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe090920191602091820191016129f3565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d8060008114612a92576040519150601f19603f3d011682016040523d82523d6000602084013e612a97565b606091505b5091509150818015612ac5575080511580612ac55750808060200190516020811015612ac257600080fd5b50515b610ea757604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600260248201527f5354000000000000000000000000000000000000000000000000000000000000604482015290519081900360640190fd5b6000546040517fd8a900b100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff9091169063d8a900b190612b8890859085906004016136e9565b600060405180830381600087803b158015612ba257600080fd5b505af1158015612bb6573d6000803e3d6000fd5b505050505050565b6040805173ffffffffffffffffffffffffffffffffffffffff85811660248301528481166044830152606480830185905283518084039091018152608490920183526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f23b872dd00000000000000000000000000000000000000000000000000000000178152925182516000948594938a169392918291908083835b60208310612c9b57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101612c5e565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d8060008114612cfd576040519150601f19603f3d011682016040523d82523d6000602084013e612d02565b606091505b5091509150818015612d30575080511580612d305750808060200190516020811015612d2d57600080fd5b50515b612bb657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600360248201527f5354460000000000000000000000000000000000000000000000000000000000604482015290519081900360640190fd5b80820182811015612dab57600080fd5b92915050565b6000806000806000808773ffffffffffffffffffffffffffffffffffffffff166399fbab88886040518263ffffffff1660e01b8152600401808281526020019150506101606040518083038186803b158015612e0c57600080fd5b505afa158015612e20573d6000803e3d6000fd5b505050506040513d610160811015612e3757600080fd5b506040808201516060830151608084015160a085015160c090950151845180860190955273ffffffffffffffffffffffffffffffffffffffff8085168652831660208601529099509397509295509350909150612e95908a90612eec565b9550505093509350935093565b600081604001518310612eba575060a0810151612dab565b81602001518310612ed057506080810151612dab565b81518310612ee357506060810151612dab565b50612710612dab565b6000816020015173ffffffffffffffffffffffffffffffffffffffff16826000015173ffffffffffffffffffffffffffffffffffffffff1610612f2e57600080fd5b5080516020918201516040805173ffffffffffffffffffffffffffffffffffffffff938416818601529290911682820152805180830382018152606080840183528151918501919091207fff00000000000000000000000000000000000000000000000000000000000000608085015294901b7fffffffffffffffffffffffffffffffffffffffff00000000000000000000000016608183015260958201939093527f6ec6c9c8091d160c0aa74b2b14ba9c1717e95093bd3ac085cee99a49aab294a460b5808301919091528351808303909101815260d5909101909252815191012090565b611a6380613dc483390190565b8035611a9181613d8c565b600060a0828403121561303d578081fd5b60405160a0810181811067ffffffffffffffff8211171561305a57fe5b604052905080823561306b81613d8c565b8152602083013561307b81613d8c565b6020820152604083013561308e81613d8c565b8060408301525060608301356060820152608083013560808201525092915050565b600060c082840312156130c1578081fd5b50919050565b80356fffffffffffffffffffffffffffffffff81168114611a9157600080fd5b805161ffff81168114611a9157600080fd5b803562ffffff81168114611a9157600080fd5b8035611a9181613db1565b805160ff81168114611a9157600080fd5b600060208284031215613139578081fd5b813561090581613d8c565b60008060408385031215613156578081fd5b825161316181613d8c565b602084015190925061317281613d8c565b809150509250929050565b6000806040838503121561318f578182fd5b823561319a81613d8c565b9150602083013561317281613d8c565b6000602082840312156131bb578081fd5b5035919050565b600080600080608085870312156131d7578182fd5b84356131e281613d8c565b935060208501356131f281613d8c565b9250604085013561320281613d8c565b9396929550929360600135925050565b600080600060608486031215613226578283fd5b833561323181613d8c565b9250602084013561324181613d8c565b929592945050506040919091013590565b600060a08284031215613263578081fd5b610905838361302c565b6000806000838503610220811215613283578182fd5b61328d868661302c565b935060c07fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff60820112156132be578182fd5b5060405160c0810181811067ffffffffffffffff821117156132dc57fe5b60405260a0850135815260c085013560208201526132fc60e086016130c7565b604082015261330e61010086016130c7565b606082015261332061012086016130f9565b60808201526133326101408601613021565b60a082015291506133478561016086016130b0565b90509250925092565b600080600060e08486031215613364578081fd5b61336e858561302c565b925061337c60a085016130c7565b915061334760c085016130c7565b60008060c0838503121561339c578182fd5b6133a6848461302c565b9460a0939093013593505050565b600080600060e084860312156133c8578081fd5b6133d2858561302c565b925060a0840135915060c08401356133e981613d8c565b809150509250925092565b600080600060e08486031215613408578081fd5b613412858561302c565b9560a0850135955060c0909401359392505050565b600080600080600080600060e0888a031215613441578485fd5b875161344c81613d8c565b8097505060208801518060020b8114613463578586fd5b9550613471604089016130e7565b945061347f606089016130e7565b935061348d60808901613117565b925061349b60a08901613117565b915060c088015180151581146134af578182fd5b8091505092959891949750929550565b6000602082840312156134d0578081fd5b5051919050565b600080604083850312156134e9578182fd5b50508035926020909101359150565b6000806040838503121561350a578182fd5b505080516020909101519092909150565b60006020828403121561352c578081fd5b813561090581613db1565b73ffffffffffffffffffffffffffffffffffffffff169052565b62ffffff169052565b63ffffffff169052565b73ffffffffffffffffffffffffffffffffffffffff91909116815260200190565b73ffffffffffffffffffffffffffffffffffffffff93841681529183166020830152909116604082015260600190565b73ffffffffffffffffffffffffffffffffffffffff94851681529290931660208301526040820152606081019190915260800190565b73ffffffffffffffffffffffffffffffffffffffff9390931683526020830191909152604082015260600190565b60006101a08201905073ffffffffffffffffffffffffffffffffffffffff8a168252886020830152876040830152866060830152856080830152843560a0830152602085013560c0830152604085013560e0830152606085013561367c81613db1565b63ffffffff16610100830152608085013561369681613db1565b6136a461012084018261355a565b506136b160a0860161310c565b6136bf61014084018261355a565b506136ce610160830185613537565b6136dc610180830184613551565b9998505050505050505050565b73ffffffffffffffffffffffffffffffffffffffff92831681529116602082015260400190565b600292830b8152910b602082015260400190565b60208082526016908201527f4661726d696e6720616c72656164792065786973747300000000000000000000604082015260600190565b60208082526014908201527f746f6b656e20616c7265616479206661726d6564000000000000000000000000604082015260600190565b6020808252600f908201527f496e76616c6964206661726d696e670000000000000000000000000000000000604082015260600190565b60208082526028908201527f4d756c7469706c6965722063616e74206265206c657373207468616e2044454e60408201527f4f4d494e41544f52000000000000000000000000000000000000000000000000606082015260800190565b60208082526019908201527f416e6f74686572206661726d696e672069732061637469766500000000000000604082015260600190565b60208082526016908201527f696e76616c696420706f6f6c20666f7220746f6b656e00000000000000000000604082015260600190565b60208082526022908201527f63616e6e6f74206661726d20746f6b656e20776974682030206c69717569646960408201527f7479000000000000000000000000000000000000000000000000000000000000606082015260800190565b6020808252602e908201527f4d756c7469706c6965722063616e742062652067726561746572207468616e2060408201527f4d41585f4d554c5449504c494552000000000000000000000000000000000000606082015260800190565b60208082526013908201527f6661726d20646f6573206e6f7420657869737400000000000000000000000000604082015260600190565b60208082526016908201527f6e6f6e2d6578697374656e7420696e63656e7469766500000000000000000000604082015260600190565b60208082526014908201527f4661726d696e6720646f206e6f74206578697374000000000000000000000000604082015260600190565b60208082526013908201527f706f736974696f6e20746f6f206e6172726f7700000000000000000000000000604082015260600190565b6020808252601d908201527f6d696e696d616c506f736974696f6e576964746820746f6f2077696465000000604082015260600190565b600060a08201905073ffffffffffffffffffffffffffffffffffffffff80845116835280602085015116602084015280604085015116604084015250606083015160608301526080830151608083015292915050565b6fffffffffffffffffffffffffffffffff959095168552600293840b60208601529190920b60408401526060830191909152608082015260a00190565b6fffffffffffffffffffffffffffffffff92831681529116602082015260400190565b6fffffffffffffffffffffffffffffffff9384168152919092166020820152604081019190915260600190565b6fffffffffffffffffffffffffffffffff929092168252602082015260400190565b90815260200190565b93845260208401929092526040830152606082015260800190565b918252602082015260400190565b60006101808201905088825287602083015273ffffffffffffffffffffffffffffffffffffffff808816604084015262ffffff871660608401527bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8616608084015280851660a084015250825160c0830152602083015160e08301526040830151610100830152606083015163ffffffff808216610120850152806080860151166101408501528060a086015116610160850152505098975050505050505050565b9283526020830191909152604082015260600190565b63ffffffff959095168552600293840b602086015291830b6040850152600f0b6060840152900b608082015260a00190565b813581556020820135600182015560408201356002820155600381016060830135613cc881613db1565b63ffffffff81167fffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000008354161790508082556080840135613d0781613db1565b67ffffffff000000008160201b167fffffffffffffffffffffffffffffffffffffffffffffffff00000000ffffffff83161791505080825560a0840135613d4d81613db1565b6bffffffff00000000000000008160401b167fffffffffffffffffffffffffffffffffffffffff00000000ffffffffffffffff83161783555050505050565b73ffffffffffffffffffffffffffffffffffffffff81168114613dae57600080fd5b50565b63ffffffff81168114613dae57600080fdfe60e060405234801561001057600080fd5b50604051611a63380380611a638339818101604052606081101561003357600080fd5b5080516020820151604090920151606082811b6001600160601b031990811660805284821b811660a0529082901b1660c0526003805463ffffffff60a01b1916600160a01b4263ffffffff16021790556001600160a01b03918216928216911661198a6100d9600039806104f2528061092d5280610ac15250806106f25280610b775280610c545280610e295250806104b35280610a825280610d06525061198a6000f3fe608060405234801561001057600080fd5b50600436106101825760003560e01c80637f463bb8116100d8578063a69252af1161008c578063d576dfc011610066578063d576dfc0146103d8578063f30dba93146103e0578063fc41aa091461047857610182565b8063a69252af146103c0578063ae855939146103c8578063d3369fd7146103d057610182565b80638e76c332116100bd5780638e76c332146103785780638eebc5d614610397578063a1ec508a146103b857610182565b80637f463bb8146103395780638a2ade581461037057610182565b80632ca1a8951161013a57806363f0580b1161011457806363f0580b146102e5578063735dd189146102ed5780637f376059146102f557610182565b80632ca1a8951461029657806346caf2ae146102c35780635354d98a146102cb57610182565b80630f1019bc1161016b5780630f1019bc146101f457806316f0115b1461023b5780631fcd27fd1461026c57610182565b806301342b19146101875780630bd6f200146101b1575b600080fd5b6101af6004803603604081101561019d57600080fd5b50803560020b9060200135151561049b565b005b6101db600480360360408110156101c757600080fd5b508035600290810b9160200135900b610699565b6040805192835260208301919091528051918290030190f35b6101af600480360360a081101561020a57600080fd5b5063ffffffff813516906020810135600290810b916040810135820b916060820135600f0b9160800135900b6106da565b61024361092b565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b6102436004803603604081101561028257600080fd5b508035600290810b9160200135900b61094f565b61029e610a26565b604080516fffffffffffffffffffffffffffffffff9092168252519081900360200190f35b61029e610a3e565b6102d3610a56565b60408051918252519081900360200190f35b6102d3610a5c565b6102d3610a62565b6103186004803603602081101561030b57600080fd5b503563ffffffff16610a68565b6040518082600281111561032857fe5b815260200191505060405180910390f35b6101af6004803603604081101561034f57600080fd5b506fffffffffffffffffffffffffffffffff81358116916020013516610b5f565b610243610c52565b610380610c76565b6040805160029290920b8252519081900360200190f35b61039f610c93565b6040805163ffffffff9092168252519081900360200190f35b61029e610cb6565b6102d3610ce2565b610243610ce8565b610243610d04565b61039f610d28565b610400600480360360208110156103f657600080fd5b503560020b610d4c565b604080516fffffffffffffffffffffffffffffffff9099168952600f9790970b602089015287870195909552606087019390935260069190910b608086015273ffffffffffffffffffffffffffffffffffffffff1660a085015263ffffffff1660c0840152151560e083015251908190036101000190f35b6101af6004803603604081101561048e57600080fd5b5080359060200135610e11565b3373ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016148061051457503373ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016145b61057f57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f6f6e6c7920706f6f6c2063616e2063616c6c20746869732066756e6374696f6e604482015290519081900360640190fd5b600282810b900b6000908152602081905260409020600301547f0100000000000000000000000000000000000000000000000000000000000000900460ff161561063c5760006105ce83610edb565b905081156105da576000035b6002546105f9906fffffffffffffffffffffffffffffffff1682610f0e565b600280547fffffffffffffffffffffffffffffffff00000000000000000000000000000000166fffffffffffffffffffffffffffffffff92909216919091179055505b80610647578161064c565b600182035b6002805491810b62ffffff16700100000000000000000000000000000000027fffffffffffffffffffffffffff000000ffffffffffffffffffffffffffffffff9092169190911790555050565b6002805460075460085460009384936106cf938593899389937001000000000000000000000000000000009004900b9190611052565b915091509250929050565b3373ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001614610768576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602381526020018061195b6023913960400191505060405180910390fd5b600280547fffffffffffffffffffffffffff000000ffffffffffffffffffffffffffffffff1670010000000000000000000000000000000062ffffff84840b160217905560035474010000000000000000000000000000000000000000900463ffffffff90811690861611156107e3576107e1856110f4565b505b81600f0b600014610924576000806107fe8684866000611397565b15610811576001915061081182876113be565b61081e8584866001611397565b156108305750600161083081866113be565b8560020b8360020b1215801561084b57508460020b8360020b125b156108b15760025461086f906fffffffffffffffffffffffffffffffff1685610f0e565b600280547fffffffffffffffffffffffffffffffff00000000000000000000000000000000166fffffffffffffffffffffffffffffffff929092169190911790555b600084600f0b12156109215781156108ef57600286810b810b6000908152602081905260408120818155600181018290559182018190556003909101555b801561092157600285810b810b6000908152602081905260408120818155600181018290559182018190556003909101555b50505b5050505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b600282810b80820b60009081526020819052604080822060039081015486860b860b845291832001548454929473ffffffffffffffffffffffffffffffffffffffff6701000000000000009384900481169593909204909116927001000000000000000000000000000000009004810b900b12156109d05790039050610a20565b6002805485820b700100000000000000000000000000000000909104820b90910b1215610a1c5760035473ffffffffffffffffffffffffffffffffffffffff1691909103039050610a20565b0390505b92915050565b6004546fffffffffffffffffffffffffffffffff1681565b6002546fffffffffffffffffffffffffffffffff1681565b60065481565b60085481565b60055481565b60003373ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000161480610ae357503373ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016145b610b4e57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f6f6e6c7920706f6f6c2063616e2063616c6c20746869732066756e6374696f6e604482015290519081900360640190fd5b610b57826110f4565b90505b919050565b3373ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001614610bed576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602381526020018061195b6023913960400191505060405180910390fd5b610bf6426110f4565b50600480546fffffffffffffffffffffffffffffffff938416928416700100000000000000000000000000000000029316929092177fffffffffffffffffffffffffffffffff0000000000000000000000000000000016179055565b7f000000000000000000000000000000000000000000000000000000000000000081565b600280547001000000000000000000000000000000009004900b81565b600254730100000000000000000000000000000000000000900463ffffffff1681565b60045470010000000000000000000000000000000090046fffffffffffffffffffffffffffffffff1681565b60075481565b60035473ffffffffffffffffffffffffffffffffffffffff1681565b7f000000000000000000000000000000000000000000000000000000000000000081565b60035474010000000000000000000000000000000000000000900463ffffffff1681565b60006020819052908152604090208054600182015460028301546003909301546fffffffffffffffffffffffffffffffff831693700100000000000000000000000000000000909304600f0b9290600681900b90670100000000000000810473ffffffffffffffffffffffffffffffffffffffff16907b01000000000000000000000000000000000000000000000000000000810463ffffffff16907f0100000000000000000000000000000000000000000000000000000000000000900460ff1688565b3373ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001614610e9f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602381526020018061195b6023913960400191505060405180910390fd5b610ea8426110f4565b508115610ec057600554610ebc908361146a565b6005555b8015610ed757600654610ed3908261146a565b6006555b5050565b600754600854600354600092610b579284928692919073ffffffffffffffffffffffffffffffffffffffff16848061147a565b60008082600f0b1215610fba57826fffffffffffffffffffffffffffffffff168260000384039150816fffffffffffffffffffffffffffffffff1610610fb557604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600260248201527f4c53000000000000000000000000000000000000000000000000000000000000604482015290519081900360640190fd5b610a20565b826fffffffffffffffffffffffffffffffff168284019150816fffffffffffffffffffffffffffffffff161015610a2057604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600260248201527f4c41000000000000000000000000000000000000000000000000000000000000604482015290519081900360640190fd5b600285810b810b60009081526020889052604080822087840b80850b84529183209293849391929088900b12156110cc578860020b8760020b126110a7578160010154860393508160020154850392506110b6565b81600101549350816002015492505b60018101546002820154940393909203916110e7565b81600101548160010154039350816002015481600201540392505b5050965096945050505050565b60035460009063ffffffff7401000000000000000000000000000000000000000090910481168303168061112c576001915050610b5a565b6002546fffffffffffffffffffffffffffffffff1680156112f1576004546fffffffffffffffffffffffffffffffff80821691700100000000000000000000000000000000900416600082611182576000611186565b6005545b9050600080831161119857600061119c565b6006545b905081156111df57838602828111156111b25750815b8083036005556111d481700100000000000000000000000000000000886115a9565b600780549091019055505b801561122057828602818111156111f35750805b80820360065561121581700100000000000000000000000000000000886115a9565b600880549091019055505b73ffffffffffffffffffffffffffffffffffffffff851673ffffffff00000000000000000000000000000000608088901b168161125957fe5b600380547fffffffffffffffffffffffff000000000000000000000000000000000000000081169390920473ffffffffffffffffffffffffffffffffffffffff92831601909116919091177fffffffffffffffff00000000ffffffffffffffffffffffffffffffffffffffff167401000000000000000000000000000000000000000063ffffffff8b16021790555061138d92505050565b6002805463ffffffff730100000000000000000000000000000000000000808304821686018216027fffffffffffffffffff00000000ffffffffffffffffffffffffffffffffffffff909216919091179091556003805491861674010000000000000000000000000000000000000000027fffffffffffffffff00000000ffffffffffffffffffffffffffffffffffffffff9092169190911790555b5060019392505050565b6007546008546000916113b59183918891889188918580808b61165e565b95945050505050565b603c600282900b0760020b1561143557604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601260248201527f7469636b206973206e6f74207370616365640000000000000000000000000000604482015290519081900360640190fd5b603c60029190910b05600881901c600190810b810b60009081526020939093526040909220805460ff9092169290921b189055565b80820182811015610a2057600080fd5b600286810b810b600090815260208990526040902060038101805473ffffffffffffffffffffffffffffffffffffffff67010000000000000063ffffffff7b0100000000000000000000000000000000000000000000000000000080850482168903909116027fff00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffff90931692909217828104821689039091169091027fffffffffff0000000000000000000000000000000000000000ffffffffffffff90911617600681810b8703900b66ffffffffffffff167fffffffffffffffffffffffffffffffffffffffffffffffffff0000000000000090911617905590810180548603905560018101805487039055547001000000000000000000000000000000009004600f0b979650505050505050565b6000838302817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff858709828110838203039150508084116115e957600080fd5b806115f957508290049050611657565b8385870960008581038616958690049560026003880281188089028203028089028203028089028203028089028203028089028203028089029091030291819003819004600101858411909403939093029190930391909104170290505b9392505050565b600289810b900b600090815260208b90526040812080547001000000000000000000000000000000008104600f0b906fffffffffffffffffffffffffffffffff16836116aa828d610f0e565b90506e023746e6a58dcb13d4af821b93f0636fffffffffffffffffffffffffffffffff82161061173b57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600260248201527f4c4f000000000000000000000000000000000000000000000000000000000000604482015290519081900360640190fd5b8561175e57611759611754600f85810b908f900b61191d565b611933565b611772565b611772611754600f85810b908f900b611944565b84546fffffffffffffffffffffffffffffffff838116600f9390930b811670010000000000000000000000000000000002918116919091177fffffffffffffffffffffffffffffffff00000000000000000000000000000000168217865590159550821661190b57841594508c60020b8e60020b136118bf57600184018b9055600284018a90556003840180547fffffffffff0000000000000000000000000000000000000000ffffffffffffff1667010000000000000073ffffffffffffffffffffffffffffffffffffffff8c1602177fffffffffffffffffffffffffffffffffffffffffffffffffff000000000000001666ffffffffffffff60068b900b16177fff00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffff167b0100000000000000000000000000000000000000000000000000000063ffffffff8a16021790555b6003840180547effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f01000000000000000000000000000000000000000000000000000000000000001790555b505050509a9950505050505050505050565b81810182811215600083121514610a2057600080fd5b80600f81900b8114610b5a57600080fd5b80820382811315600083121514610a2057600080fdfe6f6e6c79206661726d696e672063616e2063616c6c20746869732066756e6374696f6ea164736f6c6343000706000aa164736f6c6343000706000a0000000000000000000000000d500b1d8e8ef31e21c99d1db9a6444d3adf1270000000000000000000000000d8e1e7009802c914b0d39b31fc1759a865b727b1

Deployed Bytecode

0x608060405234801561001057600080fd5b50600436106101515760003560e01c8063826cc0a1116100cd578063dd56e5d811610081578063e70b9e2711610066578063e70b9e27146102bc578063f43930a3146102cf578063fe4282fb146102e257610151565b8063dd56e5d8146102a1578063df42efda146102a957610151565b8063b44a2722116100b2578063b44a272214610271578063b58a723914610286578063d5f394881461029957610151565b8063826cc0a11461024b57806392aa2d891461025e57610151565b80633ee0dd02116101245780636394adbb116101095780636394adbb14610204578063704972f414610217578063779fa0c41461023857610151565b80633ee0dd02146101cb57806360777795146101de57610151565b80630705506b146101565780630a5307541461016b57806327e6a99a146101945780632f2d783d146101b8575b600080fd5b6101696101643660046133b4565b6102f5565b005b61017e6101793660046131c2565b61084b565b60405161018b9190613b66565b60405180910390f35b6101a76101a23660046134d7565b610885565b60405161018b959493929190613ab7565b61017e6101c6366004613212565b6108f4565b6101696101d9366004613252565b61090c565b6101f16101ec3660046131aa565b610950565b60405161018b9796959493929190613b98565b610169610212366004613252565b610a33565b61022a61022536600461338a565b610a73565b60405161018b929190613b8a565b610169610246366004613128565b610c95565b6101696102593660046133f4565b610d6e565b61016961026c366004613350565b610eae565b610279610fbc565b60405161018b9190613564565b61027961029436600461326d565b610fe0565b61027961134b565b61027961136f565b6101696102b7366004613128565b61138b565b61017e6102ca36600461317d565b611462565b6101696102dd3660046133f4565b61147f565b61022a6102f03660046133b4565b6116f9565b60005473ffffffffffffffffffffffffffffffffffffffff16331461031957600080fd5b600061032484611a65565b6000848152600460209081526040808320848452825291829020825160a08101845281546fffffffffffffffffffffffffffffffff81168083527001000000000000000000000000000000008204600290810b810b810b95840195909552730100000000000000000000000000000000000000909104840b840b840b948201949094526001820154606082015291015460808201529192506103fb576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103f29061394e565b60405180910390fd5b60008281526001602052604080822060028101548883015183517fe76c01e40000000000000000000000000000000000000000000000000000000081529351929473ffffffffffffffffffffffffffffffffffffffff92831694909384938493169163e76c01e49160048083019260e0929190829003018186803b15801561048257600080fd5b505afa158015610496573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104ba9190613427565b50505060208a01516040808c015190517f0f1019bc00000000000000000000000000000000000000000000000000000000815294965073ffffffffffffffffffffffffffffffffffffffff8a169550630f1019bc9461052494504293506000908890600401613c6c565b600060405180830381600087803b15801561053e57600080fd5b505af1158015610552573d6000803e3d6000fd5b505050506000808573ffffffffffffffffffffffffffffffffffffffff16630bd6f20089602001518a604001516040518363ffffffff1660e01b815260040161059c929190613710565b604080518083038186803b1580156105b357600080fd5b505afa1580156105c7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105eb91906134f8565b915091508573ffffffffffffffffffffffffffffffffffffffff16630f1019bc428a602001518b604001516106358d600001516fffffffffffffffffffffffffffffffff16611a96565b600003886040518663ffffffff1660e01b8152600401610659959493929190613c6c565b600060405180830381600087803b15801561067357600080fd5b505af1158015610687573d6000803e3d6000fd5b505050506106c38860600151830389600001516fffffffffffffffffffffffffffffffff16700100000000000000000000000000000000611aa7565b6106fb896080015183038a600001516fffffffffffffffffffffffffffffffff16700100000000000000000000000000000000611aa7565b73ffffffffffffffffffffffffffffffffffffffff8c16600090815260036020526040902091965094509250508315905061075d57895173ffffffffffffffffffffffffffffffffffffffff1660009081526020829052604090208054840190555b8115610793576020808b015173ffffffffffffffffffffffffffffffffffffffff16600090815290829052604090208054830190555b60008981526004602090815260408083208a8452825280832080547fffffffffffffffffffff0000000000000000000000000000000000000000000016815560018101849055600201929092558b51908c0151915173ffffffffffffffffffffffffffffffffffffffff9091169189918c917f7f2557bb15dcf63e3d029ef1dcb4333563fcd78edf263b8fe42ed3adb925ff849161083791908e908a908a906135b5565b60405180910390a450505050505050505050565b6000805473ffffffffffffffffffffffffffffffffffffffff16331461087057600080fd5b61087c85858585611b5b565b95945050505050565b60046020908152600092835260408084209091529082529020805460018201546002928301546fffffffffffffffffffffffffffffffff8316937001000000000000000000000000000000008404810b937301000000000000000000000000000000000000009004900b919085565b600061090284338585611b5b565b90505b9392505050565b60025473ffffffffffffffffffffffffffffffffffffffff16331461093057600080fd5b600061093f8260400151611c69565b91505061094c8282611d18565b5050565b600160208181526000928352604092839020805492810154600282015460038301546004840154875160c0810189526005860154815260068601549681019690965260078501549786019790975260089093015463ffffffff8082166060870152640100000000820481166080870152680100000000000000009091041660a08501529394909373ffffffffffffffffffffffffffffffffffffffff808216947401000000000000000000000000000000000000000090920462ffffff16937bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1692169087565b60025473ffffffffffffffffffffffffffffffffffffffff163314610a5757600080fd5b6000610a668260400151611c69565b91505061094c8282611e91565b6000806000610a8185611a65565b6000858152600460209081526040808320848452825291829020825160a08101845281546fffffffffffffffffffffffffffffffff81168083527001000000000000000000000000000000008204600290810b810b810b95840195909552730100000000000000000000000000000000000000909104840b840b840b94820194909452600182015460608201529101546080820152919250610b4f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103f29061394e565b600082815260016020908152604080832060020154918401518482015191517f0bd6f20000000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff909316939283928592630bd6f20092610bc29290600401613710565b604080518083038186803b158015610bd957600080fd5b505afa158015610bed573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c1191906134f8565b91509150610c4d8460600151830385600001516fffffffffffffffffffffffffffffffff16700100000000000000000000000000000000611aa7565b610c858560800151830386600001516fffffffffffffffffffffffffffffffff16700100000000000000000000000000000000611aa7565b909a909950975050505050505050565b3373ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000476307dac3fd170166e007fcaa14f0a1297214631614610cd757600080fd5b60025473ffffffffffffffffffffffffffffffffffffffff82811691161415610cff57600080fd5b600280547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff83169081179091556040517f7aa996b8cecffbf29f5d2a3564db96e010e2dcae822601312970ae9690ec1c5290600090a250565b6000610d7984611a65565b6000818152600160205260409020805491925090610dc3576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103f290613985565b610dcf85858584611ff8565b909450925083831715610ea75760028101546040517ffc41aa0900000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff90911690819063fc41aa0990610e389088908890600401613b8a565b600060405180830381600087803b158015610e5257600080fd5b505af1158015610e66573d6000803e3d6000fd5b505050507f8b0312d8047895ce795779b66b705ccd39b1ece7c162f642c72d76a785d1b68a858585604051610e9d93929190613c56565b60405180910390a1505b5050505050565b60025473ffffffffffffffffffffffffffffffffffffffff163314610ed257600080fd5b6000610edd84611a65565b600081815260016020526040908190206002015490517f7f463bb800000000000000000000000000000000000000000000000000000000815291925073ffffffffffffffffffffffffffffffffffffffff16908190637f463bb890610f489087908790600401613af4565b600060405180830381600087803b158015610f6257600080fd5b505af1158015610f76573d6000803e3d6000fd5b505050507f1864e4cc903d98e44820faebd48409c410a2ad20adb3173984ba41ae2828805e848484604051610fad93929190613b17565b60405180910390a15050505050565b7f000000000000000000000000d8e1e7009802c914b0d39b31fc1759a865b727b181565b60025460009073ffffffffffffffffffffffffffffffffffffffff16331461100757600080fd5b60006110168560400151611c69565b91505073ffffffffffffffffffffffffffffffffffffffff811615611067576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103f290613724565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1630866040015160405161109a90613014565b6110a693929190613585565b604051809103906000f0801580156110c2573d6000803e3d6000fd5b50915060006110e683878760000151886020015189608001518a60a001518a612311565b87600001886020018281525082815250829350505050856040015173ffffffffffffffffffffffffffffffffffffffff16866020015173ffffffffffffffffffffffffffffffffffffffff16876000015173ffffffffffffffffffffffffffffffffffffffff167f0402a2abfe823f7036d0b24f3e7c00b60362a9e8214880b0fa5a74d6b216caf3868a606001518b608001518b600001518c602001518c8e60a001518f608001516040516111a2989796959493929190613619565b60405180910390a4845160208601516040517ffc41aa0900000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff86169263fc41aa099261120192600401613b8a565b600060405180830381600087803b15801561121b57600080fd5b505af115801561122f573d6000803e3d6000fd5b505050604080870151606088015191517f7f463bb800000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff87169350637f463bb89261128e9291600401613af4565b600060405180830381600087803b1580156112a857600080fd5b505af11580156112bc573d6000803e3d6000fd5b5050865160208801516040517f8b0312d8047895ce795779b66b705ccd39b1ece7c162f642c72d76a785d1b68a94506112f793508590613c56565b60405180910390a17f1864e4cc903d98e44820faebd48409c410a2ad20adb3173984ba41ae2828805e856040015186606001518360405161133a93929190613b17565b60405180910390a150509392505050565b7f0000000000000000000000000d500b1d8e8ef31e21c99d1db9a6444d3adf127081565b60005473ffffffffffffffffffffffffffffffffffffffff1681565b3373ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000476307dac3fd170166e007fcaa14f0a12972146316146113cd57600080fd5b60005473ffffffffffffffffffffffffffffffffffffffff828116911614156113f557600080fd5b600080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff8316908117825560405190917f29f9e1ebeee07596f3165f3e42cb9d4d8d22b0481e968d6c74be3dd037c15d9b91a250565b600360209081526000928352604080842090915290825290205481565b60005473ffffffffffffffffffffffffffffffffffffffff1633146114a357600080fd5b60008060008060006114b68888886125a9565b60008c81526004602090815260408083208884529182905290912054959a5093985091965094509250906fffffffffffffffffffffffffffffffff1615611529576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103f29061375b565b6000808373ffffffffffffffffffffffffffffffffffffffff16630bd6f20088886040518363ffffffff1660e01b8152600401611567929190613710565b604080518083038186803b15801561157e57600080fd5b505afa158015611592573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115b691906134f8565b915091506040518060a00160405280866fffffffffffffffffffffffffffffffff1681526020018860020b81526020018760020b8152602001838152602001828152508360008a815260200190815260200160002060008201518160000160006101000a8154816fffffffffffffffffffffffffffffffff02191690836fffffffffffffffffffffffffffffffff16021790555060208201518160000160106101000a81548162ffffff021916908360020b62ffffff16021790555060408201518160000160136101000a81548162ffffff021916908360020b62ffffff1602179055506060820151816001015560808201518160020155905050878a7f4a9757f8f71efdde4b041ff384e461c5707a95d74463b60892bd1f7b9c34a289878c6040516116e4929190613b44565b60405180910390a35050505050505050505050565b60008054819073ffffffffffffffffffffffffffffffffffffffff16331461172057600080fd5b600061172b86611a65565b6000818152600160205260409020805491925090611775576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103f290613985565b6002808201546000888152600460209081526040808320878452825291829020825160a08101845281546fffffffffffffffffffffffffffffffff81168083527001000000000000000000000000000000008204880b880b880b948301949094527301000000000000000000000000000000000000009004860b860b860b938101939093526001810154606084015290930154608082015273ffffffffffffffffffffffffffffffffffffffff9091169161185c576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103f29061394e565b6000808373ffffffffffffffffffffffffffffffffffffffff16630bd6f200846020015185604001516040518363ffffffff1660e01b81526004016118a2929190613710565b604080518083038186803b1580156118b957600080fd5b505afa1580156118cd573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118f191906134f8565b9150915061192d8360600151830384600001516fffffffffffffffffffffffffffffffff16700100000000000000000000000000000000611aa7565b6119658460800151830385600001516fffffffffffffffffffffffffffffffff16700100000000000000000000000000000000611aa7565b60008c81526004602090815260408083208b845282528083206001810188905560020186905573ffffffffffffffffffffffffffffffffffffffff8e16835260039091529020919950975088156119e3578b5173ffffffffffffffffffffffffffffffffffffffff16600090815260208290526040902080548a0190555b8715611a19576020808d015173ffffffffffffffffffffffffffffffffffffffff16600090815290829052604090208054890190555b7f15b2e0f32b50efdbbdee9ec7884ed3c61e6209b1b395e5762011a6734b86f7b58b888b8b604051611a4e9493929190613b6f565b60405180910390a150505050505050935093915050565b600081604051602001611a789190613a61565b6040516020818303038152906040528051906020012090505b919050565b80600f81900b8114611a9157600080fd5b6000838302817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff85870982811083820303915050808411611ae757600080fd5b80611af757508290049050610905565b8385870960008581038616958690049560026003880281188089028203028089028203028089028203028089028203028089028203028089029091030291819003819004600101858411909403939093029190930391909104170290509392505050565b73ffffffffffffffffffffffffffffffffffffffff808416600090815260036020908152604080832093881683529290522054811580611b9a57508082115b15611ba3578091505b73ffffffffffffffffffffffffffffffffffffffff80851660009081526003602090815260408083209389168352929052208282039055611be585848461295b565b8373ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fe6ac6a784fb43c9f6329d2f5c82f88a26a93bad4281f7780725af5f071f0aafa85604051611c599190613b66565b60405180910390a4949350505050565b600080546040517f32dc5a25000000000000000000000000000000000000000000000000000000008152829173ffffffffffffffffffffffffffffffffffffffff16906332dc5a2590611cc0908690600401613564565b604080518083038186803b158015611cd757600080fd5b505afa158015611ceb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d0f9190613144565b91509150915091565b73ffffffffffffffffffffffffffffffffffffffff8116611d65576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103f2906139bc565b8073ffffffffffffffffffffffffffffffffffffffff1660016000611d8985611a65565b815260208101919091526040016000206002015473ffffffffffffffffffffffffffffffffffffffff1614611dea576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103f290613826565b611df982604001516000612b30565b816040015173ffffffffffffffffffffffffffffffffffffffff16826020015173ffffffffffffffffffffffffffffffffffffffff16836000015173ffffffffffffffffffffffffffffffffffffffff167f0ab9cc241fe819ccf1100504defd5fe1366c71aba48092174547ccd7191f3d068486606001518760800151604051611e85939291906135eb565b60405180910390a45050565b73ffffffffffffffffffffffffffffffffffffffff811615611edf576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103f290613724565b600060016000611eee85611a65565b815260208101919091526040016000206002015473ffffffffffffffffffffffffffffffffffffffff16905080611f51576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103f290613792565b611f5f836040015182612b30565b826040015173ffffffffffffffffffffffffffffffffffffffff16836020015173ffffffffffffffffffffffffffffffffffffffff16846000015173ffffffffffffffffffffffffffffffffffffffff167f6d3b554600fa5af9295315554801e6206cbdb85866f653f9488e5875c06a6b648487606001518860800151604051611feb939291906135eb565b60405180910390a4505050565b600080841561217d5785516040517f70a0823100000000000000000000000000000000000000000000000000000000815260009073ffffffffffffffffffffffffffffffffffffffff8316906370a0823190612058903090600401613564565b60206040518083038186803b15801561207057600080fd5b505afa158015612084573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120a891906134bf565b90506120b68233308a612bbe565b6040517f70a08231000000000000000000000000000000000000000000000000000000008152819073ffffffffffffffffffffffffffffffffffffffff8416906370a082319061210a903090600401613564565b60206040518083038186803b15801561212257600080fd5b505afa158015612136573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061215a91906134bf565b9450841161216757600080fd5b845493819003936121789085612d9b565b855550505b83156123085760208601516040517f70a0823100000000000000000000000000000000000000000000000000000000815260009073ffffffffffffffffffffffffffffffffffffffff8316906370a08231906121dd903090600401613564565b60206040518083038186803b1580156121f557600080fd5b505afa158015612209573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061222d91906134bf565b905061223b82333089612bbe565b6040517f70a08231000000000000000000000000000000000000000000000000000000008152819073ffffffffffffffffffffffffffffffffffffffff8416906370a082319061228f903090600401613564565b60206040518083038186803b1580156122a757600080fd5b505afa1580156122bb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122df91906134bf565b935083116122ec57600080fd5b600185015492819003926123009084612d9b565b600186015550505b94509492505050565b600080600061232489604001518b612b30565b61232d89611a65565b600081815260016020526040902090935061234a8a8a8a84611ff8565b9093509150621b136862ffffff88161315612391576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103f290613a2a565b6002810180547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff8d16177fffffffffffffffffff000000ffffffffffffffffffffffffffffffffffffffff167401000000000000000000000000000000000000000062ffffff8a160217905561c350612426608087016060880161351b565b63ffffffff1611158015612451575061c35061244860a087016080880161351b565b63ffffffff1611155b8015612474575061c35061246b60c0870160a0880161351b565b63ffffffff1611155b6124aa576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103f2906138f1565b6127106124bd608087016060880161351b565b63ffffffff16101580156124e857506127106124df60a087016080880161351b565b63ffffffff1610155b801561250b575061271061250260c0870160a0880161351b565b63ffffffff1610155b612541576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103f2906137c9565b84600582016125508282613c9e565b505060040180547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff96909616959095179094559098909750919550909350505050565b60008060008060006125ba88611a65565b6000818152600160205260409020805491965090612604576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103f290613985565b60006126517f0000000000000000000000000d500b1d8e8ef31e21c99d1db9a6444d3adf12707f000000000000000000000000d8e1e7009802c914b0d39b31fc1759a865b727b18b612db1565b60408e0151929950909750955090915073ffffffffffffffffffffffffffffffffffffffff8083169116146126b2576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103f29061385d565b6000846fffffffffffffffffffffffffffffffff16116126fe576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103f290613894565b60008173ffffffffffffffffffffffffffffffffffffffff1663e76c01e46040518163ffffffff1660e01b815260040160e06040518083038186803b15801561274657600080fd5b505afa15801561275a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061277e9190613427565b50506040805160c08101825260058a0154815260068a0154602082015260078a015491810191909152600889015463ffffffff8082166060840152640100000000820481166080840152680100000000000000009091041660a0820152939550600094506127f2938e93509150612ea29050565b9050600061281b6fffffffffffffffffffffffffffffffff881663ffffffff8416612710611aa7565b90506fffffffffffffffffffffffffffffffff81111561283a57600080fd5b60028581015491975073ffffffffffffffffffffffffffffffffffffffff82169650879174010000000000000000000000000000000000000000900462ffffff16908a810b908a900b038113156128bd576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103f2906139f3565b8673ffffffffffffffffffffffffffffffffffffffff16630f1019bc428c8c6128f78d6fffffffffffffffffffffffffffffffff16611a96565b896040518663ffffffff1660e01b8152600401612918959493929190613c6c565b600060405180830381600087803b15801561293257600080fd5b505af1158015612946573d6000803e3d6000fd5b50505050505050505050939792965093509350565b6040805173ffffffffffffffffffffffffffffffffffffffff8481166024830152604480830185905283518084039091018152606490920183526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fa9059cbb000000000000000000000000000000000000000000000000000000001781529251825160009485949389169392918291908083835b60208310612a3057805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe090920191602091820191016129f3565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d8060008114612a92576040519150601f19603f3d011682016040523d82523d6000602084013e612a97565b606091505b5091509150818015612ac5575080511580612ac55750808060200190516020811015612ac257600080fd5b50515b610ea757604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600260248201527f5354000000000000000000000000000000000000000000000000000000000000604482015290519081900360640190fd5b6000546040517fd8a900b100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff9091169063d8a900b190612b8890859085906004016136e9565b600060405180830381600087803b158015612ba257600080fd5b505af1158015612bb6573d6000803e3d6000fd5b505050505050565b6040805173ffffffffffffffffffffffffffffffffffffffff85811660248301528481166044830152606480830185905283518084039091018152608490920183526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f23b872dd00000000000000000000000000000000000000000000000000000000178152925182516000948594938a169392918291908083835b60208310612c9b57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101612c5e565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d8060008114612cfd576040519150601f19603f3d011682016040523d82523d6000602084013e612d02565b606091505b5091509150818015612d30575080511580612d305750808060200190516020811015612d2d57600080fd5b50515b612bb657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600360248201527f5354460000000000000000000000000000000000000000000000000000000000604482015290519081900360640190fd5b80820182811015612dab57600080fd5b92915050565b6000806000806000808773ffffffffffffffffffffffffffffffffffffffff166399fbab88886040518263ffffffff1660e01b8152600401808281526020019150506101606040518083038186803b158015612e0c57600080fd5b505afa158015612e20573d6000803e3d6000fd5b505050506040513d610160811015612e3757600080fd5b506040808201516060830151608084015160a085015160c090950151845180860190955273ffffffffffffffffffffffffffffffffffffffff8085168652831660208601529099509397509295509350909150612e95908a90612eec565b9550505093509350935093565b600081604001518310612eba575060a0810151612dab565b81602001518310612ed057506080810151612dab565b81518310612ee357506060810151612dab565b50612710612dab565b6000816020015173ffffffffffffffffffffffffffffffffffffffff16826000015173ffffffffffffffffffffffffffffffffffffffff1610612f2e57600080fd5b5080516020918201516040805173ffffffffffffffffffffffffffffffffffffffff938416818601529290911682820152805180830382018152606080840183528151918501919091207fff00000000000000000000000000000000000000000000000000000000000000608085015294901b7fffffffffffffffffffffffffffffffffffffffff00000000000000000000000016608183015260958201939093527f6ec6c9c8091d160c0aa74b2b14ba9c1717e95093bd3ac085cee99a49aab294a460b5808301919091528351808303909101815260d5909101909252815191012090565b611a6380613dc483390190565b8035611a9181613d8c565b600060a0828403121561303d578081fd5b60405160a0810181811067ffffffffffffffff8211171561305a57fe5b604052905080823561306b81613d8c565b8152602083013561307b81613d8c565b6020820152604083013561308e81613d8c565b8060408301525060608301356060820152608083013560808201525092915050565b600060c082840312156130c1578081fd5b50919050565b80356fffffffffffffffffffffffffffffffff81168114611a9157600080fd5b805161ffff81168114611a9157600080fd5b803562ffffff81168114611a9157600080fd5b8035611a9181613db1565b805160ff81168114611a9157600080fd5b600060208284031215613139578081fd5b813561090581613d8c565b60008060408385031215613156578081fd5b825161316181613d8c565b602084015190925061317281613d8c565b809150509250929050565b6000806040838503121561318f578182fd5b823561319a81613d8c565b9150602083013561317281613d8c565b6000602082840312156131bb578081fd5b5035919050565b600080600080608085870312156131d7578182fd5b84356131e281613d8c565b935060208501356131f281613d8c565b9250604085013561320281613d8c565b9396929550929360600135925050565b600080600060608486031215613226578283fd5b833561323181613d8c565b9250602084013561324181613d8c565b929592945050506040919091013590565b600060a08284031215613263578081fd5b610905838361302c565b6000806000838503610220811215613283578182fd5b61328d868661302c565b935060c07fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff60820112156132be578182fd5b5060405160c0810181811067ffffffffffffffff821117156132dc57fe5b60405260a0850135815260c085013560208201526132fc60e086016130c7565b604082015261330e61010086016130c7565b606082015261332061012086016130f9565b60808201526133326101408601613021565b60a082015291506133478561016086016130b0565b90509250925092565b600080600060e08486031215613364578081fd5b61336e858561302c565b925061337c60a085016130c7565b915061334760c085016130c7565b60008060c0838503121561339c578182fd5b6133a6848461302c565b9460a0939093013593505050565b600080600060e084860312156133c8578081fd5b6133d2858561302c565b925060a0840135915060c08401356133e981613d8c565b809150509250925092565b600080600060e08486031215613408578081fd5b613412858561302c565b9560a0850135955060c0909401359392505050565b600080600080600080600060e0888a031215613441578485fd5b875161344c81613d8c565b8097505060208801518060020b8114613463578586fd5b9550613471604089016130e7565b945061347f606089016130e7565b935061348d60808901613117565b925061349b60a08901613117565b915060c088015180151581146134af578182fd5b8091505092959891949750929550565b6000602082840312156134d0578081fd5b5051919050565b600080604083850312156134e9578182fd5b50508035926020909101359150565b6000806040838503121561350a578182fd5b505080516020909101519092909150565b60006020828403121561352c578081fd5b813561090581613db1565b73ffffffffffffffffffffffffffffffffffffffff169052565b62ffffff169052565b63ffffffff169052565b73ffffffffffffffffffffffffffffffffffffffff91909116815260200190565b73ffffffffffffffffffffffffffffffffffffffff93841681529183166020830152909116604082015260600190565b73ffffffffffffffffffffffffffffffffffffffff94851681529290931660208301526040820152606081019190915260800190565b73ffffffffffffffffffffffffffffffffffffffff9390931683526020830191909152604082015260600190565b60006101a08201905073ffffffffffffffffffffffffffffffffffffffff8a168252886020830152876040830152866060830152856080830152843560a0830152602085013560c0830152604085013560e0830152606085013561367c81613db1565b63ffffffff16610100830152608085013561369681613db1565b6136a461012084018261355a565b506136b160a0860161310c565b6136bf61014084018261355a565b506136ce610160830185613537565b6136dc610180830184613551565b9998505050505050505050565b73ffffffffffffffffffffffffffffffffffffffff92831681529116602082015260400190565b600292830b8152910b602082015260400190565b60208082526016908201527f4661726d696e6720616c72656164792065786973747300000000000000000000604082015260600190565b60208082526014908201527f746f6b656e20616c7265616479206661726d6564000000000000000000000000604082015260600190565b6020808252600f908201527f496e76616c6964206661726d696e670000000000000000000000000000000000604082015260600190565b60208082526028908201527f4d756c7469706c6965722063616e74206265206c657373207468616e2044454e60408201527f4f4d494e41544f52000000000000000000000000000000000000000000000000606082015260800190565b60208082526019908201527f416e6f74686572206661726d696e672069732061637469766500000000000000604082015260600190565b60208082526016908201527f696e76616c696420706f6f6c20666f7220746f6b656e00000000000000000000604082015260600190565b60208082526022908201527f63616e6e6f74206661726d20746f6b656e20776974682030206c69717569646960408201527f7479000000000000000000000000000000000000000000000000000000000000606082015260800190565b6020808252602e908201527f4d756c7469706c6965722063616e742062652067726561746572207468616e2060408201527f4d41585f4d554c5449504c494552000000000000000000000000000000000000606082015260800190565b60208082526013908201527f6661726d20646f6573206e6f7420657869737400000000000000000000000000604082015260600190565b60208082526016908201527f6e6f6e2d6578697374656e7420696e63656e7469766500000000000000000000604082015260600190565b60208082526014908201527f4661726d696e6720646f206e6f74206578697374000000000000000000000000604082015260600190565b60208082526013908201527f706f736974696f6e20746f6f206e6172726f7700000000000000000000000000604082015260600190565b6020808252601d908201527f6d696e696d616c506f736974696f6e576964746820746f6f2077696465000000604082015260600190565b600060a08201905073ffffffffffffffffffffffffffffffffffffffff80845116835280602085015116602084015280604085015116604084015250606083015160608301526080830151608083015292915050565b6fffffffffffffffffffffffffffffffff959095168552600293840b60208601529190920b60408401526060830191909152608082015260a00190565b6fffffffffffffffffffffffffffffffff92831681529116602082015260400190565b6fffffffffffffffffffffffffffffffff9384168152919092166020820152604081019190915260600190565b6fffffffffffffffffffffffffffffffff929092168252602082015260400190565b90815260200190565b93845260208401929092526040830152606082015260800190565b918252602082015260400190565b60006101808201905088825287602083015273ffffffffffffffffffffffffffffffffffffffff808816604084015262ffffff871660608401527bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8616608084015280851660a084015250825160c0830152602083015160e08301526040830151610100830152606083015163ffffffff808216610120850152806080860151166101408501528060a086015116610160850152505098975050505050505050565b9283526020830191909152604082015260600190565b63ffffffff959095168552600293840b602086015291830b6040850152600f0b6060840152900b608082015260a00190565b813581556020820135600182015560408201356002820155600381016060830135613cc881613db1565b63ffffffff81167fffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000008354161790508082556080840135613d0781613db1565b67ffffffff000000008160201b167fffffffffffffffffffffffffffffffffffffffffffffffff00000000ffffffff83161791505080825560a0840135613d4d81613db1565b6bffffffff00000000000000008160401b167fffffffffffffffffffffffffffffffffffffffff00000000ffffffffffffffff83161783555050505050565b73ffffffffffffffffffffffffffffffffffffffff81168114613dae57600080fd5b50565b63ffffffff81168114613dae57600080fdfe60e060405234801561001057600080fd5b50604051611a63380380611a638339818101604052606081101561003357600080fd5b5080516020820151604090920151606082811b6001600160601b031990811660805284821b811660a0529082901b1660c0526003805463ffffffff60a01b1916600160a01b4263ffffffff16021790556001600160a01b03918216928216911661198a6100d9600039806104f2528061092d5280610ac15250806106f25280610b775280610c545280610e295250806104b35280610a825280610d06525061198a6000f3fe608060405234801561001057600080fd5b50600436106101825760003560e01c80637f463bb8116100d8578063a69252af1161008c578063d576dfc011610066578063d576dfc0146103d8578063f30dba93146103e0578063fc41aa091461047857610182565b8063a69252af146103c0578063ae855939146103c8578063d3369fd7146103d057610182565b80638e76c332116100bd5780638e76c332146103785780638eebc5d614610397578063a1ec508a146103b857610182565b80637f463bb8146103395780638a2ade581461037057610182565b80632ca1a8951161013a57806363f0580b1161011457806363f0580b146102e5578063735dd189146102ed5780637f376059146102f557610182565b80632ca1a8951461029657806346caf2ae146102c35780635354d98a146102cb57610182565b80630f1019bc1161016b5780630f1019bc146101f457806316f0115b1461023b5780631fcd27fd1461026c57610182565b806301342b19146101875780630bd6f200146101b1575b600080fd5b6101af6004803603604081101561019d57600080fd5b50803560020b9060200135151561049b565b005b6101db600480360360408110156101c757600080fd5b508035600290810b9160200135900b610699565b6040805192835260208301919091528051918290030190f35b6101af600480360360a081101561020a57600080fd5b5063ffffffff813516906020810135600290810b916040810135820b916060820135600f0b9160800135900b6106da565b61024361092b565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b6102436004803603604081101561028257600080fd5b508035600290810b9160200135900b61094f565b61029e610a26565b604080516fffffffffffffffffffffffffffffffff9092168252519081900360200190f35b61029e610a3e565b6102d3610a56565b60408051918252519081900360200190f35b6102d3610a5c565b6102d3610a62565b6103186004803603602081101561030b57600080fd5b503563ffffffff16610a68565b6040518082600281111561032857fe5b815260200191505060405180910390f35b6101af6004803603604081101561034f57600080fd5b506fffffffffffffffffffffffffffffffff81358116916020013516610b5f565b610243610c52565b610380610c76565b6040805160029290920b8252519081900360200190f35b61039f610c93565b6040805163ffffffff9092168252519081900360200190f35b61029e610cb6565b6102d3610ce2565b610243610ce8565b610243610d04565b61039f610d28565b610400600480360360208110156103f657600080fd5b503560020b610d4c565b604080516fffffffffffffffffffffffffffffffff9099168952600f9790970b602089015287870195909552606087019390935260069190910b608086015273ffffffffffffffffffffffffffffffffffffffff1660a085015263ffffffff1660c0840152151560e083015251908190036101000190f35b6101af6004803603604081101561048e57600080fd5b5080359060200135610e11565b3373ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016148061051457503373ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016145b61057f57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f6f6e6c7920706f6f6c2063616e2063616c6c20746869732066756e6374696f6e604482015290519081900360640190fd5b600282810b900b6000908152602081905260409020600301547f0100000000000000000000000000000000000000000000000000000000000000900460ff161561063c5760006105ce83610edb565b905081156105da576000035b6002546105f9906fffffffffffffffffffffffffffffffff1682610f0e565b600280547fffffffffffffffffffffffffffffffff00000000000000000000000000000000166fffffffffffffffffffffffffffffffff92909216919091179055505b80610647578161064c565b600182035b6002805491810b62ffffff16700100000000000000000000000000000000027fffffffffffffffffffffffffff000000ffffffffffffffffffffffffffffffff9092169190911790555050565b6002805460075460085460009384936106cf938593899389937001000000000000000000000000000000009004900b9190611052565b915091509250929050565b3373ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001614610768576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602381526020018061195b6023913960400191505060405180910390fd5b600280547fffffffffffffffffffffffffff000000ffffffffffffffffffffffffffffffff1670010000000000000000000000000000000062ffffff84840b160217905560035474010000000000000000000000000000000000000000900463ffffffff90811690861611156107e3576107e1856110f4565b505b81600f0b600014610924576000806107fe8684866000611397565b15610811576001915061081182876113be565b61081e8584866001611397565b156108305750600161083081866113be565b8560020b8360020b1215801561084b57508460020b8360020b125b156108b15760025461086f906fffffffffffffffffffffffffffffffff1685610f0e565b600280547fffffffffffffffffffffffffffffffff00000000000000000000000000000000166fffffffffffffffffffffffffffffffff929092169190911790555b600084600f0b12156109215781156108ef57600286810b810b6000908152602081905260408120818155600181018290559182018190556003909101555b801561092157600285810b810b6000908152602081905260408120818155600181018290559182018190556003909101555b50505b5050505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b600282810b80820b60009081526020819052604080822060039081015486860b860b845291832001548454929473ffffffffffffffffffffffffffffffffffffffff6701000000000000009384900481169593909204909116927001000000000000000000000000000000009004810b900b12156109d05790039050610a20565b6002805485820b700100000000000000000000000000000000909104820b90910b1215610a1c5760035473ffffffffffffffffffffffffffffffffffffffff1691909103039050610a20565b0390505b92915050565b6004546fffffffffffffffffffffffffffffffff1681565b6002546fffffffffffffffffffffffffffffffff1681565b60065481565b60085481565b60055481565b60003373ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000161480610ae357503373ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016145b610b4e57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f6f6e6c7920706f6f6c2063616e2063616c6c20746869732066756e6374696f6e604482015290519081900360640190fd5b610b57826110f4565b90505b919050565b3373ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001614610bed576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602381526020018061195b6023913960400191505060405180910390fd5b610bf6426110f4565b50600480546fffffffffffffffffffffffffffffffff938416928416700100000000000000000000000000000000029316929092177fffffffffffffffffffffffffffffffff0000000000000000000000000000000016179055565b7f000000000000000000000000000000000000000000000000000000000000000081565b600280547001000000000000000000000000000000009004900b81565b600254730100000000000000000000000000000000000000900463ffffffff1681565b60045470010000000000000000000000000000000090046fffffffffffffffffffffffffffffffff1681565b60075481565b60035473ffffffffffffffffffffffffffffffffffffffff1681565b7f000000000000000000000000000000000000000000000000000000000000000081565b60035474010000000000000000000000000000000000000000900463ffffffff1681565b60006020819052908152604090208054600182015460028301546003909301546fffffffffffffffffffffffffffffffff831693700100000000000000000000000000000000909304600f0b9290600681900b90670100000000000000810473ffffffffffffffffffffffffffffffffffffffff16907b01000000000000000000000000000000000000000000000000000000810463ffffffff16907f0100000000000000000000000000000000000000000000000000000000000000900460ff1688565b3373ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001614610e9f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602381526020018061195b6023913960400191505060405180910390fd5b610ea8426110f4565b508115610ec057600554610ebc908361146a565b6005555b8015610ed757600654610ed3908261146a565b6006555b5050565b600754600854600354600092610b579284928692919073ffffffffffffffffffffffffffffffffffffffff16848061147a565b60008082600f0b1215610fba57826fffffffffffffffffffffffffffffffff168260000384039150816fffffffffffffffffffffffffffffffff1610610fb557604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600260248201527f4c53000000000000000000000000000000000000000000000000000000000000604482015290519081900360640190fd5b610a20565b826fffffffffffffffffffffffffffffffff168284019150816fffffffffffffffffffffffffffffffff161015610a2057604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600260248201527f4c41000000000000000000000000000000000000000000000000000000000000604482015290519081900360640190fd5b600285810b810b60009081526020889052604080822087840b80850b84529183209293849391929088900b12156110cc578860020b8760020b126110a7578160010154860393508160020154850392506110b6565b81600101549350816002015492505b60018101546002820154940393909203916110e7565b81600101548160010154039350816002015481600201540392505b5050965096945050505050565b60035460009063ffffffff7401000000000000000000000000000000000000000090910481168303168061112c576001915050610b5a565b6002546fffffffffffffffffffffffffffffffff1680156112f1576004546fffffffffffffffffffffffffffffffff80821691700100000000000000000000000000000000900416600082611182576000611186565b6005545b9050600080831161119857600061119c565b6006545b905081156111df57838602828111156111b25750815b8083036005556111d481700100000000000000000000000000000000886115a9565b600780549091019055505b801561122057828602818111156111f35750805b80820360065561121581700100000000000000000000000000000000886115a9565b600880549091019055505b73ffffffffffffffffffffffffffffffffffffffff851673ffffffff00000000000000000000000000000000608088901b168161125957fe5b600380547fffffffffffffffffffffffff000000000000000000000000000000000000000081169390920473ffffffffffffffffffffffffffffffffffffffff92831601909116919091177fffffffffffffffff00000000ffffffffffffffffffffffffffffffffffffffff167401000000000000000000000000000000000000000063ffffffff8b16021790555061138d92505050565b6002805463ffffffff730100000000000000000000000000000000000000808304821686018216027fffffffffffffffffff00000000ffffffffffffffffffffffffffffffffffffff909216919091179091556003805491861674010000000000000000000000000000000000000000027fffffffffffffffff00000000ffffffffffffffffffffffffffffffffffffffff9092169190911790555b5060019392505050565b6007546008546000916113b59183918891889188918580808b61165e565b95945050505050565b603c600282900b0760020b1561143557604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601260248201527f7469636b206973206e6f74207370616365640000000000000000000000000000604482015290519081900360640190fd5b603c60029190910b05600881901c600190810b810b60009081526020939093526040909220805460ff9092169290921b189055565b80820182811015610a2057600080fd5b600286810b810b600090815260208990526040902060038101805473ffffffffffffffffffffffffffffffffffffffff67010000000000000063ffffffff7b0100000000000000000000000000000000000000000000000000000080850482168903909116027fff00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffff90931692909217828104821689039091169091027fffffffffff0000000000000000000000000000000000000000ffffffffffffff90911617600681810b8703900b66ffffffffffffff167fffffffffffffffffffffffffffffffffffffffffffffffffff0000000000000090911617905590810180548603905560018101805487039055547001000000000000000000000000000000009004600f0b979650505050505050565b6000838302817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff858709828110838203039150508084116115e957600080fd5b806115f957508290049050611657565b8385870960008581038616958690049560026003880281188089028203028089028203028089028203028089028203028089028203028089029091030291819003819004600101858411909403939093029190930391909104170290505b9392505050565b600289810b900b600090815260208b90526040812080547001000000000000000000000000000000008104600f0b906fffffffffffffffffffffffffffffffff16836116aa828d610f0e565b90506e023746e6a58dcb13d4af821b93f0636fffffffffffffffffffffffffffffffff82161061173b57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600260248201527f4c4f000000000000000000000000000000000000000000000000000000000000604482015290519081900360640190fd5b8561175e57611759611754600f85810b908f900b61191d565b611933565b611772565b611772611754600f85810b908f900b611944565b84546fffffffffffffffffffffffffffffffff838116600f9390930b811670010000000000000000000000000000000002918116919091177fffffffffffffffffffffffffffffffff00000000000000000000000000000000168217865590159550821661190b57841594508c60020b8e60020b136118bf57600184018b9055600284018a90556003840180547fffffffffff0000000000000000000000000000000000000000ffffffffffffff1667010000000000000073ffffffffffffffffffffffffffffffffffffffff8c1602177fffffffffffffffffffffffffffffffffffffffffffffffffff000000000000001666ffffffffffffff60068b900b16177fff00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffff167b0100000000000000000000000000000000000000000000000000000063ffffffff8a16021790555b6003840180547effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f01000000000000000000000000000000000000000000000000000000000000001790555b505050509a9950505050505050505050565b81810182811215600083121514610a2057600080fd5b80600f81900b8114610b5a57600080fd5b80820382811315600083121514610a2057600080fdfe6f6e6c79206661726d696e672063616e2063616c6c20746869732066756e6374696f6ea164736f6c6343000706000aa164736f6c6343000706000a

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

0000000000000000000000000d500b1d8e8ef31e21c99d1db9a6444d3adf1270000000000000000000000000d8e1e7009802c914b0d39b31fc1759a865b727b1

-----Decoded View---------------
Arg [0] : _deployer (address): 0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270
Arg [1] : _nonfungiblePositionManager (address): 0xd8E1E7009802c914b0d39B31Fc1759A865b727B1

-----Encoded View---------------
2 Constructor Arguments found :
Arg [0] : 0000000000000000000000000d500b1d8e8ef31e21c99d1db9a6444d3adf1270
Arg [1] : 000000000000000000000000d8e1e7009802c914b0d39b31fc1759a865b727b1


Deployed Bytecode Sourcemap

506:10414:64:-:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;5917:2172;;;;;;:::i;:::-;;:::i;:::-;;3684:278:61;;;;;;:::i;:::-;;:::i;:::-;;;;;;;:::i;:::-;;;;;;;;927:66:64;;;;;;:::i;:::-;;:::i;:::-;;;;;;;;;;;:::i;3402:240:61:-;;;;;;:::i;:::-;;:::i;2950:223:64:-;;;;;;:::i;:::-;;:::i;1822:56:61:-;;;;;;:::i;:::-;;:::i;:::-;;;;;;;;;;;;;:::i;3215:223:64:-;;;;;;:::i;:::-;;:::i;8265:900::-;;;;;;:::i;:::-;;:::i;:::-;;;;;;;;:::i;2840:227:61:-;;;;;;:::i;:::-;;:::i;3487:770:64:-;;;;;;:::i;:::-;;:::i;4306:475::-;;;;;;:::i;:::-;;:::i;1443:80:61:-;;;:::i;:::-;;;;;;;:::i;1407:1501:64:-;;;;;;:::i;:::-;;:::i;1566:55:61:-;;;:::i;1664:44::-;;;:::i;3109:251::-;;;;;;:::i;:::-;;:::i;2049:77::-;;;;;;:::i;:::-;;:::i;4823:1052:64:-;;;;;;:::i;:::-;;:::i;9290:1628::-;;;;;;:::i;:::-;;:::i;5917:2172::-;2386:13:61;;;;2364:10;:36;2356:45;;;;;;6072:19:64::1;6094:24;6114:3;6094:19;:24::i;:::-;6129:16;6148:14:::0;;;:5:::1;:14;::::0;;;;;;;:27;;;;;;;;;6129:46;;::::1;::::0;::::1;::::0;;;;::::1;::::0;::::1;::::0;;;;;::::1;;::::0;;::::1;::::0;::::1;::::0;::::1;::::0;;::::1;::::0;;;;;;;::::1;::::0;::::1;::::0;::::1;::::0;::::1;::::0;;;;;;;;;::::1;::::0;;;;;;::::1;::::0;;;;;6072;;-1:-1:-1;6185:51:64::1;;;;;;;;;;;;:::i;:::-;;;;;;;;;6247:27;6277:23:::0;;;:10:::1;:23;::::0;;;;;6378:28:::1;::::0;::::1;::::0;6513:8;;::::1;::::0;:22;;;;;;;6277:23;;6378:28:::1;::::0;;::::1;::::0;6247:27;;;;;;6513:20:::1;::::0;::::1;::::0;:22:::1;::::0;;::::1;::::0;::::1;::::0;;;;;;;;:20;:22;::::1;;::::0;::::1;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;-1:-1:-1::0;;;6697:14:64::1;::::0;::::1;::::0;6713::::1;::::0;;::::1;::::0;6630:107;;;;;6486:49;;-1:-1:-1;6630:41:64::1;::::0;::::1;::::0;-1:-1:-1;6630:41:64::1;::::0;:107:::1;::::0;-1:-1:-1;6679:15:64::1;::::0;-1:-1:-1;6729:1:64::1;::::0;6486:49;;6630:107:::1;;;:::i;:::-;;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;;;;;6753:26;6781::::0;6811:11:::1;:33;;;6862:4;:14;;;6894:4;:14;;;6811:111;;;;;;;;;;;;;;;;:::i;:::-;;::::0;::::1;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;6752:170;;;;6937:11;:41;;;7003:15;7037:4;:14;;;7069:4;:14;;;7102:33;7109:4;:14;;;7102:22;;:31;:33::i;:::-;7101:34;;7153:4;6937:234;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;;;;;7228:93;7265:4;:23;;;7244:18;:44;7290:4;:14;;;7228:93;;231:35:45;7228:15:64;:93::i;:::-;7339;7376:4;:23;;;7355:18;:44;7401:4;:14;;;7339:93;;231:35:45;7339:15:64;:93::i;:::-;7526:15;::::0;::::1;7467:56;7526:15:::0;;;:7:::1;:15;::::0;;;;7186:260;;-1:-1:-1;7186:260:64;-1:-1:-1;7526:15:64;-1:-1:-1;;7555:11:64;;;-1:-1:-1;7551:118:64::1;;7597:15:::0;;7582:31:::1;;;::::0;;;::::1;::::0;;;;;;:41;;;::::1;::::0;;7551:118:::1;7682:16:::0;;7678:133:::1;;7729:20;::::0;;::::1;::::0;7714:36:::1;;;::::0;;;;;;;;;;:51;;;::::1;::::0;;7678:133:::1;7828:14;::::0;;;:5:::1;:14;::::0;;;;;;;:27;;;;;;;;7821:34;;;;;;;;::::1;::::0;;;::::1;;::::0;;;;7948:15;;7986:20;;::::1;::::0;7871:211;;::::1;::::0;;::::1;::::0;7843:11;;7834:7;;7871:211:::1;::::0;::::1;::::0;7986:20;8021:6;;8041;;8061:11;;7871:211:::1;:::i;:::-;;;;;;;;2411:1:61;;;;;;;5917:2172:64::0;;;:::o;3684:278:61:-;3870:14;2386:13;;;;2364:10;:36;2356:45;;;;;;3903:52:::1;3916:11;3929:4;3935:2;3939:15;3903:12;:52::i;:::-;3896:59:::0;3684:278;-1:-1:-1;;;;;3684:278:61:o;927:66:64:-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;3402:240:61:-;3544:14;3577:58;3590:11;3603:10;3615:2;3619:15;3577:12;:58::i;:::-;3570:65;;3402:240;;;;;;:::o;2950:223:64:-;2195:14:61;;;;2181:10;:28;2173:37;;;;;;3050:27:64::1;3081:33;3105:3;:8;;;3081:23;:33::i;:::-;3047:67;;;3124:42;3141:3;3146:19;3124:16;:42::i;:::-;2220:1:61;2950:223:64::0;:::o;1822:56:61:-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;3215:223:64:-;2195:14:61;;;;2181:10;:28;2173:37;;;;;;3315:27:64::1;3346:33;3370:3;:8;;;3346:23;:33::i;:::-;3312:67;;;3389:42;3406:3;3411:19;3389:16;:42::i;8265:900::-:0;8394:14;8410:19;8445;8467:24;8487:3;8467:19;:24::i;:::-;8502:16;8521:14;;;:5;:14;;;;;;;;:27;;;;;;;;;8502:46;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;8445;;-1:-1:-1;8558:50:64;;;;;;;;;;;;:::i;:::-;8619:38;8687:23;;;:10;:23;;;;;;;;:42;;;8847:14;;;;8875;;;;8800:99;;;;;8687:42;;;;;8619:38;;;8687:42;;8800:33;;:99;;8875:14;8800:99;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;8741:158;;;;8948:93;8985:4;:23;;;8964:18;:44;9010:4;:14;;;8948:93;;231:35:45;8948:15:64;:93::i;:::-;9055;9092:4;:23;;;9071:18;:44;9117:4;:14;;;9055:93;;231:35:45;9055:15:64;:93::i;:::-;8910:248;;;;-1:-1:-1;8265:900:64;-1:-1:-1;;;;;;;;8265:900:64:o;2840:227:61:-;2273:10;:19;2287:5;2273:19;;2265:28;;;;;;2938:14:::1;::::0;:33:::1;::::0;;::::1;:14:::0;::::1;:33;;2930:42;;;::::0;::::1;;2982:14;:32:::0;;;::::1;;::::0;::::1;::::0;;::::1;::::0;;;3029:31:::1;::::0;::::1;::::0;-1:-1:-1;;3029:31:61::1;2840:227:::0;:::o;3487:770:64:-;3639:19;3661:24;3681:3;3661:19;:24::i;:::-;3695:27;3725:23;;;:10;:23;;;;;3766:21;;3639:46;;-1:-1:-1;3725:23:64;3758:60;;;;;;;;;;;;:::i;:::-;3865:64;3881:3;3886:12;3900:17;3919:9;3865:15;:64::i;:::-;3829:100;;-1:-1:-1;3829:100:64;-1:-1:-1;3944:32:64;;;:36;3940:311;;4064:28;;;;4107:55;;;;;4064:28;;;;;;;4107:22;;:55;;4130:12;;4144:17;;4107:55;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4182:58;4195:12;4209:17;4228:11;4182:58;;;;;;;;:::i;:::-;;;;;;;;3940:311;;3487:770;;;;;:::o;4306:475::-;2195:14:61;;;;2181:10;:28;2173:37;;;;;;4471:19:64::1;4493:24;4513:3;4493:19;:24::i;:::-;4527:38;4595:23:::0;;;:10:::1;:23;::::0;;;;;;:42:::1;;::::0;4648:49;;;;;4471:46;;-1:-1:-1;4595:42:64::1;;::::0;;;4648:20:::1;::::0;:49:::1;::::0;4669:10;;4681:15;;4648:49:::1;;;:::i;:::-;;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;;;;;4713:61;4733:10;4745:15;4762:11;4713:61;;;;;;;;:::i;:::-;;;;;;;;2220:1:61;;4306:475:64::0;;;:::o;1443:80:61:-;;;:::o;1407:1501:64:-;2195:14:61;;1591:19:64;;2195:14:61;;2181:10;:28;2173:37;;;;;;1625:18:64::1;1647:33;1671:3;:8;;;1647:23;:33::i;:::-;1622:58:::0;-1:-1:-1;;1698:24:64::1;::::0;::::1;::::0;1690:59:::1;;;;;;;;;;;;:::i;:::-;1813:13;::::0;::::1;;;;;;;;1837:4;1852:3;:8;;;1782:80;;;;;:::i;:::-;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;1760:103;;1873:19;1953:221;1981:11;2006:3;2023:6;:13;;;2050:6;:18;;;2082:6;:27;;;2123:6;:22;;;2159:5;1953:14;:221::i;:::-;1916:6;:13;;1931:6;:18;;1902:272;;;::::0;::::1;;;::::0;::::1;;;;;;2288:3;:8;;;2190:348;;2254:3;:20;;;2190:348;;2225:3;:15;;;2190:348;;;2310:11;2335:3;:13;;;2362:3;:11;;;2387:6;:13;;;2414:6;:18;;;2446:5;2465:6;:22;;;2501:6;:27;;;2190:348;;;;;;;;;;;;;:::i;:::-;;;;;;;;2600:13:::0;;2615:18:::1;::::0;::::1;::::0;2549:85:::1;::::0;;;;:50:::1;::::0;::::1;::::0;::::1;::::0;:85:::1;::::0;::::1;;;:::i;:::-;;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;-1:-1:-1::0;;;2693:17:64::1;::::0;;::::1;::::0;2712:22:::1;::::0;::::1;::::0;2644:91;;;;;:48:::1;::::0;::::1;::::0;-1:-1:-1;2644:48:64::1;::::0;:91:::1;::::0;2693:17;2644:91:::1;;;:::i;:::-;;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;-1:-1:-1::0;;2764:13:64;;2779:18:::1;::::0;::::1;::::0;2751:60:::1;::::0;::::1;::::0;-1:-1:-1;2751:60:64::1;::::0;-1:-1:-1;2799:11:64;;2751:60:::1;:::i;:::-;;;;;;;;2826:75;2846:6;:17;;;2865:6;:22;;;2889:11;2826:75;;;;;;;;:::i;:::-;;;;;;;;2220:1:61;;1407:1501:64::0;;;;;:::o;1566:55:61:-;;;:::o;1664:44::-;;;;;;:::o;3109:251::-;2273:10;:19;2287:5;2273:19;;2265:28;;;;;;3238:13:::1;::::0;::::1;3212:40:::0;;::::1;3238:13:::0;::::1;3212:40;;3204:49;;;::::0;::::1;;3263:13;:46:::0;;;::::1;;::::0;::::1;::::0;;::::1;::::0;;3324:29:::1;::::0;3263:46;;3324:29:::1;::::0;::::1;3109:251:::0;:::o;2049:77::-;;;;;;;;;;;;;;;;;;;;;;;;:::o;4823:1052:64:-;2386:13:61;;;;2364:10;:36;2356:45;;;;;;4999:19:64::1;5032:15:::0;5061::::1;5090:17:::0;5121:26:::1;5160:41;5174:3;5179:7;5188:12;5160:13;:41::i;:::-;5212:46;5261:14:::0;;;:5:::1;:14;::::0;;;;;;;5293:26;;;;;;;;;;:36;4985:216;;-1:-1:-1;4985:216:64;;-1:-1:-1;4985:216:64;;-1:-1:-1;4985:216:64;-1:-1:-1;4985:216:64;-1:-1:-1;5261:14:64;5293:36:::1;;:41:::0;5285:74:::1;;;;;;;;;;;;:::i;:::-;5371:26;5399::::0;5456:18:::1;5429:81;;;5511:9;5522;5429:103;;;;;;;;;;;;;;;;:::i;:::-;;::::0;::::1;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;5370:162;;;;5572:222;;;;;;;;5602:9;5572:222;;;;;;5636:9;5572:222;;;;;;5670:9;5572:222;;;;;;5713:18;5572:222;;;;5765:18;5572:222;;::::0;5543:13:::1;:26;5557:11;5543:26;;;;;;;;;;;:251;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;5831:11;5822:7;5810:58;5844:9;5855:12;5810:58;;;;;;;:::i;:::-;;;;;;;;2411:1:61;;;;;;;;4823:1052:64::0;;;:::o;9290:1628::-;9447:14;2386:13:61;;9447:14:64;;2386:13:61;;2364:10;:36;2356:45;;;;;;9494:19:64::1;9516:24;9536:3;9516:19;:24::i;:::-;9550:27;9580:23:::0;;;:10:::1;:23;::::0;;;;9621:21;;9494:46;;-1:-1:-1;9580:23:64;9613:60:::1;;;;;;;;;;;;:::i;:::-;9752:28;::::0;;::::1;::::0;9684:38:::1;9811:14:::0;;;:5:::1;:14;::::0;;;;;;;:27;;;;;;;;;9792:46;;::::1;::::0;::::1;::::0;;;;::::1;::::0;::::1;::::0;;;;;::::1;::::0;::::1;::::0;::::1;::::0;::::1;::::0;;::::1;::::0;;;;;;::::1;::::0;::::1;::::0;::::1;::::0;::::1;::::0;;;;;;;9752:28;9792:46;::::1;::::0;;;;;;;::::1;::::0;;;;;9752:28:::1;::::0;;::::1;::::0;9848:51:::1;;;;;;;;;;;;:::i;:::-;9911:26;9939::::0;9969:11:::1;:33;;;10016:4;:14;;;10044:4;:14;;;9969:99;;;;;;;;;;;;;;;;:::i;:::-;;::::0;::::1;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;9910:158;;;;10117:93;10154:4;:23;;;10133:18;:44;10179:4;:14;;;10117:93;;231:35:45;10117:15:64;:93::i;:::-;10224;10261:4;:23;;;10240:18;:44;10286:4;:14;;;10224:93;;231:35:45;10224:15:64;:93::i;:::-;10338:14;::::0;;;:5:::1;:14;::::0;;;;;;;:27;;;;;;;;:46:::1;::::0;::::1;:67:::0;;;10415:46:::1;;:67:::0;;;10552:15:::1;::::0;::::1;::::0;;:7:::1;:15:::0;;;;;10079:248;;-1:-1:-1;10079:248:64;-1:-1:-1;10581:11:64;;10577:118:::1;;10623:15:::0;;10608:31:::1;;;::::0;;;::::1;::::0;;;;;;:41;;;::::1;::::0;;10577:118:::1;10708:16:::0;;10704:133:::1;;10755:20;::::0;;::::1;::::0;10740:36:::1;;;::::0;;;;;;;;;;:51;;;::::1;::::0;;10704:133:::1;10852:59;10869:7;10878:11;10891:6;10899:11;10852:59;;;;;;;;;:::i;:::-;;;;;;;;2411:1:61;;;;;;;9290:1628:64::0;;;;;;:::o;353:150:76:-;432:19;491:3;480:15;;;;;;;;:::i;:::-;;;;;;;;;;;;;470:26;;;;;;463:33;;353:150;;;;:::o;763:101:49:-;857:1;838:20;;;;;;830:29;;;;;757:3329:46;855:14;1176:5;;;855:14;1335:6;1180:1;1176;1322:20;1385:5;1381:2;1378:13;1370:5;1366:2;1362:14;1358:34;1349:43;;;1513:5;1499:11;:19;1491:28;;;;;;1584:10;1580:111;;-1:-1:-1;1633:23:46;;;;-1:-1:-1;1671:13:46;;1580:111;2044:11;2041:1;2038;2031:25;2280:12;2295;;;:26;;2401:22;;;;;3128:1;3109;:15;;3108:21;;3339:17;;;3335:21;;3328:28;3393:17;;;3389:21;;3382:28;3448:17;;;3444:21;;3437:28;3503:17;;;3499:21;;3492:28;3558:17;;;3554:21;;3547:28;3614:17;;;3610:21;;;3603:28;2729:12;;;;2725:23;;;2750:1;2721:31;2083:20;;;2072:32;;;2772:12;;;;2120:21;;;;2511:16;;;;2763:21;4051:11;;-1:-1:-1;757:3329:46;;;;;:::o;10368:559:61:-;10559:13;;;;10524:14;10559:13;;;:7;:13;;;;;;;;:26;;;;;;;;;;10600:20;;;:48;;;10642:6;10624:15;:24;10600:48;10596:103;;;10682:6;10664:24;;10596:103;10709:13;;;;;;;;:7;:13;;;;;;;;:26;;;;;;;;;10738:24;;;10709:53;;10772:70;10723:11;10822:2;10747:15;10772:27;:70::i;:::-;10915:4;10858:62;;10901:11;10858:62;;10872:2;10858:62;;;10876:15;10858:62;;;;;;:::i;:::-;;;;;;;;10368:559;;;;;;:::o;4125:184::-;4200:17;4253:13;;:49;;;;;4200:17;;4253:13;;;:34;;:49;;4296:4;;4253:49;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;4246:56;;;;4125:184;;;:::o;7424:599::-;7530:32;;;7522:65;;;;;;;;;;;;:::i;:::-;7678:18;7619:77;;:10;:36;7630:24;7650:3;7630:19;:24::i;:::-;7619:36;;;;;;;;;;;-1:-1:-1;7619:36:61;:55;;;;;:77;7598:149;;;;;;;;;;;;:::i;:::-;7757:47;7783:3;:8;;;7801:1;7757:25;:47::i;:::-;7914:3;:8;;;7820:196;;7880:3;:20;;;7820:196;;7851:3;:15;;;7820:196;;;7936:18;7968:3;:13;;;7995:3;:11;;;7820:196;;;;;;;;:::i;:::-;;;;;;;;7424:599;;:::o;8029:615::-;8135:32;;;;8127:67;;;;;;;;;;;;:::i;:::-;8205:26;8234:10;:36;8245:24;8265:3;8245:19;:24::i;:::-;8234:36;;;;;;;;;;;-1:-1:-1;8234:36:61;:55;;;;;;-1:-1:-1;8307:32:61;8299:60;;;;;;;;;;;;:::i;:::-;8370:55;8396:3;:8;;;8406:18;8370:25;:55::i;:::-;8535:3;:8;;;8441:196;;8501:3;:20;;;8441:196;;8472:3;:15;;;8441:196;;;8557:18;8589:3;:13;;;8616:3;:11;;;8441:196;;;;;;;;:::i;:::-;;;;;;;;8029:615;;;:::o;4315:1256::-;4487:22;;4554:10;;4550:478;;4608:15;;4661:36;;;;;4580:25;;4661:21;;;;;;:36;;4691:4;;4661:36;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;4637:60;;4711:88;4751:11;4765:10;4785:4;4792:6;4711:31;:88::i;:::-;4839:36;;;;;4879:13;;4839:21;;;;;;:36;;4869:4;;4839:36;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;4822:53;;;4821:71;4813:80;;;;;;4976:21;;4907:31;;;;;4976:41;;4907:31;4976:25;:41::i;:::-;4952:65;;-1:-1:-1;;4550:478:61;5041:15;;5037:528;;5105:20;;;;5163:41;;;;;5072:30;;5163:26;;;;;;:41;;5198:4;;5163:41;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;5139:65;;5218:98;5258:16;5277:10;5297:4;5304:11;5218:31;:98::i;:::-;5361:41;;;;;5406:13;;5361:26;;;;;;:41;;5396:4;;5361:41;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;5339:63;;;5338:81;5330:90;;;;;;5508:21;;;;5434:36;;;;;5508:46;;5434:36;5508:25;:46::i;:::-;5484:21;;;:70;-1:-1:-1;;5037:528:61;4315:1256;;;;;;;:::o;5577:1841::-;5869:19;5902:22;5938:27;5990:48;6016:3;:8;;;6026:11;5990:25;:48::i;:::-;6063:24;6083:3;6063:19;:24::i;:::-;6098:30;6131:23;;;:10;:23;;;;;6049:38;;-1:-1:-1;6205:55:61;6221:3;6226:6;6234:11;6131:23;6205:15;:55::i;:::-;6165:95;;-1:-1:-1;6165:95:61;-1:-1:-1;6333:217:61;6292:259;;;;;6271:335;;;;;;;;;;;;:::i;:::-;6616:31;;;:45;;;;;;;;6671:56;;;;;;;;;;379:5:77;6759:21:61;;;;;;;;:::i;:::-;:53;;;;:126;;;;-1:-1:-1;379:5:77;6832:21:61;;;;;;;;:::i;:::-;:53;;;;6759:126;:199;;;;-1:-1:-1;379:5:77;6905:21:61;;;;;;;;:::i;:::-;:53;;;;6759:199;6738:292;;;;;;;;;;;;:::i;:::-;335:5:77;7062:21:61;;;;;;;;:::i;:::-;:50;;;;:120;;;;-1:-1:-1;335:5:77;7132:21:61;;;;;;;;:::i;:::-;:50;;;;7062:120;:190;;;;-1:-1:-1;335:5:77;7202:21:61;;;;;;;;:::i;:::-;:50;;;;7062:190;7041:277;;;;;;;;;;;;:::i;:::-;7350:5;7329:18;;;:26;7350:5;7329:18;:26;:::i;:::-;-1:-1:-1;;7365:28:61;;:46;;;;;;;;;;;;;;;;5577:1841;;;;-1:-1:-1;7365:46:61;;-1:-1:-1;5577:1841:61;;-1:-1:-1;;;;5577:1841:61:o;8650:1712::-;8814:19;8847:15;8876;8905:17;8936:19;8994:24;9014:3;8994:19;:24::i;:::-;9028:27;9058:23;;;:10;:23;;;;;9100:21;;8980:38;;-1:-1:-1;9058:23:61;9092:60;;;;;;;;;;;;:::i;:::-;9163:17;9232:124;9277:8;9299:26;9339:7;9232:31;:124::i;:::-;9383:8;;;;9190:166;;-1:-1:-1;9190:166:61;;-1:-1:-1;9190:166:61;-1:-1:-1;9190:166:61;;-1:-1:-1;9375:16:61;;;;;;;9367:51;;;;;;;;;;;;:::i;:::-;9448:1;9436:9;:13;;;9428:60;;;;;;;;;;;;:::i;:::-;9501:10;9525:4;:16;;;:18;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;-1:-1:-1;;9574:67:61;;;;;;;;9625:15;;;9574:67;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;9498:45;;-1:-1:-1;9554:17:61;;-1:-1:-1;9574:67:61;;9611:12;;-1:-1:-1;9574:67:61;-1:-1:-1;9574:36:61;;-1:-1:-1;9574:67:61:i;:::-;9554:87;-1:-1:-1;9651:37:61;9691:65;;;;;;;335:5:77;9691:15:61;:65::i;:::-;9651:105;-1:-1:-1;9807:17:61;9774:50;;;9766:59;;;;;;9910:28;;;;;9855:29;;-1:-1:-1;9910:28:61;;;;-1:-1:-1;9855:29:61;;9981:30;;;;;;10049:17;;;10029;;;;:37;-1:-1:-1;;10029:72:61;10021:104;;;;;;;;;;;;:::i;:::-;10160:11;10136:66;;;10223:15;10253:9;10276;10299:28;10306:9;10299:17;;:26;:28::i;:::-;10341:4;10136:219;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;8650:1712;;;;;;;;;;;;;;;:::o;1329:309:30:-;1489:59;;;1478:10;1489:59;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1512:24;1489:59;;;1478:71;;;;1443:12;;;;1478:10;;;;1489:59;1478:71;;;1489:59;1478:71;;1489:59;1478:71;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1442:107;;;;1567:7;:57;;;;-1:-1:-1;1579:11:30;;:16;;:44;;;1610:4;1599:24;;;;;;;;;;;;;;;-1:-1:-1;1599:24:30;1579:44;1559:72;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;3968:151:61;4061:13;;:51;;;;;:13;;;;;:32;;:51;;4094:4;;4100:11;;4061:51;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;3968:151;;:::o;669:368:30:-;868:69;;;844:10;868:69;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;891:28;868:69;;;844:103;;;;809:12;;;;844:10;;;;868:69;844:103;;;868:69;844:103;;868:69;844:103;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;808:139;;;;965:7;:57;;;;-1:-1:-1;977:11:30;;:16;;:44;;;1008:4;997:24;;;;;;;;;;;;;;;-1:-1:-1;997:24:30;977:44;957:73;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;558:105:48;646:5;;;641:16;;;;633:25;;;;;;558:105;;;;:::o;999:668:78:-;1218:17;1249:15;1278;1307:17;1349:14;1373;1461:26;:36;;;1498:7;1461:45;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;1461:45:78;;;;;;;;;;;;;;;;;;;;;;1596:53;;;;;;;;;;;;;;;;1461:45;1596:53;;;1461:45;;-1:-1:-1;1461:45:78;;-1:-1:-1;1461:45:78;;-1:-1:-1;1461:45:78;-1:-1:-1;1461:45:78;;-1:-1:-1;1550:100:78;;1585:8;;1550:26;:100::i;:::-;1517:143;;999:668;;;;;;;;;:::o;708:533:77:-;844:17;896:5;:25;;;881:11;:40;877:358;;-1:-1:-1;944:21:77;;;;937:28;;877:358;1001:5;:25;;;986:11;:40;982:253;;-1:-1:-1;1049:21:77;;;;1042:28;;982:253;1106:25;;1091:40;;1087:148;;-1:-1:-1;1154:21:77;;;;1147:28;;1087:148;-1:-1:-1;335:5:77;1206:18;;1293:503:29;1377:12;1422:3;:10;;;1409:23;;:3;:10;;;:23;;;1401:32;;;;;;-1:-1:-1;1656:10:29;;1668;;;;;1645:34;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1635:45;;;;;;;;;1527:220;;;;;;;;;;;;;;;;;;;;;349:66;1527:220;;;;;;;;;;;;;;;;;;;;;;;;;1496:269;;;;;;1293:503::o;-1:-1:-1:-;;;;;;;;:::o;14:138:83:-;84:20;;113:33;84:20;113:33;:::i;157:904::-;;267:4;255:9;250:3;246:19;242:30;239:2;;;289:5;282;275:20;239:2;326;320:9;368:4;360:6;356:17;439:6;427:10;424:22;403:18;391:10;388:34;385:62;382:2;;;450:9;382:2;477;470:22;510:6;-1:-1:-1;510:6:83;540:23;;572:35;540:23;572:35;:::i;:::-;616:23;;691:2;676:18;;663:32;704:35;663:32;704:35;:::i;:::-;767:2;755:15;;748:32;832:2;817:18;;804:32;845:35;804:32;845:35;:::i;:::-;913:7;908:2;900:6;896:15;889:32;;982:2;971:9;967:18;954:32;949:2;941:6;937:15;930:57;1049:3;1038:9;1034:19;1021:33;1015:3;1007:6;1003:16;996:59;;229:832;;;;:::o;1066:165::-;;1172:3;1163:6;1158:3;1154:16;1150:26;1147:2;;;1193:5;1186;1179:20;1147:2;-1:-1:-1;1219:6:83;1137:94;-1:-1:-1;1137:94:83:o;1236:190::-;1306:20;;1366:34;1355:46;;1345:57;;1335:2;;1416:1;1413;1406:12;1431:165;1511:13;;1564:6;1553:18;;1543:29;;1533:2;;1586:1;1583;1576:12;1601:163;1670:20;;1730:8;1719:20;;1709:31;;1699:2;;1754:1;1751;1744:12;1769:136;1838:20;;1867:32;1838:20;1867:32;:::i;1910:162::-;1989:13;;2042:4;2031:16;;2021:27;;2011:2;;2062:1;2059;2052:12;2077:259;;2189:2;2177:9;2168:7;2164:23;2160:32;2157:2;;;2210:6;2202;2195:22;2157:2;2254:9;2241:23;2273:33;2300:5;2273:33;:::i;2341:399::-;;;2481:2;2469:9;2460:7;2456:23;2452:32;2449:2;;;2502:6;2494;2487:22;2449:2;2539:9;2533:16;2558:33;2585:5;2558:33;:::i;:::-;2660:2;2645:18;;2639:25;2610:5;;-1:-1:-1;2673:35:83;2639:25;2673:35;:::i;:::-;2727:7;2717:17;;;2439:301;;;;;:::o;2745:424::-;;;2896:2;2884:9;2875:7;2871:23;2867:32;2864:2;;;2917:6;2909;2902:22;2864:2;2961:9;2948:23;2980:33;3007:5;2980:33;:::i;:::-;3032:5;-1:-1:-1;3089:2:83;3074:18;;3061:32;3102:35;3061:32;3102:35;:::i;3174:190::-;;3286:2;3274:9;3265:7;3261:23;3257:32;3254:2;;;3307:6;3299;3292:22;3254:2;-1:-1:-1;3335:23:83;;3244:120;-1:-1:-1;3244:120:83:o;3369:636::-;;;;;3554:3;3542:9;3533:7;3529:23;3525:33;3522:2;;;3576:6;3568;3561:22;3522:2;3620:9;3607:23;3639:33;3666:5;3639:33;:::i;:::-;3691:5;-1:-1:-1;3748:2:83;3733:18;;3720:32;3761:35;3720:32;3761:35;:::i;:::-;3815:7;-1:-1:-1;3874:2:83;3859:18;;3846:32;3887:35;3846:32;3887:35;:::i;:::-;3512:493;;;;-1:-1:-1;3941:7:83;;3995:2;3980:18;3967:32;;-1:-1:-1;;3512:493:83:o;4010:492::-;;;;4178:2;4166:9;4157:7;4153:23;4149:32;4146:2;;;4199:6;4191;4184:22;4146:2;4243:9;4230:23;4262:33;4289:5;4262:33;:::i;:::-;4314:5;-1:-1:-1;4371:2:83;4356:18;;4343:32;4384:35;4343:32;4384:35;:::i;:::-;4136:366;;4438:7;;-1:-1:-1;;;4492:2:83;4477:18;;;;4464:32;;4136:366::o;4507:252::-;;4650:3;4638:9;4629:7;4625:23;4621:33;4618:2;;;4672:6;4664;4657:22;4618:2;4700:53;4745:7;4734:9;4700:53;:::i;4764:1223::-;;;;4992:9;4983:7;4979:23;5022:3;5018:2;5014:12;5011:2;;;5044:6;5036;5029:22;5011:2;5072:53;5117:7;5106:9;5072:53;:::i;:::-;5062:63;;5218:4;5149:66;5145:2;5141:75;5137:86;5134:2;;;5241:6;5233;5226:22;5134:2;;5279;5273:9;5321:4;5313:6;5309:17;5392:6;5380:10;5377:22;5356:18;5344:10;5341:34;5338:62;5335:2;;;5403:9;5335:2;5430;5423:22;5497:3;5482:19;;5469:33;5454:49;;5564:4;5549:20;;5536:34;5531:2;5519:15;;5512:59;5604:41;5640:3;5625:19;;5604:41;:::i;:::-;5599:2;5591:6;5587:15;5580:66;5679:41;5715:3;5704:9;5700:19;5679:41;:::i;:::-;5674:2;5666:6;5662:15;5655:66;5755:40;5790:3;5779:9;5775:19;5755:40;:::i;:::-;5749:3;5741:6;5737:16;5730:66;5830:41;5866:3;5855:9;5851:19;5830:41;:::i;:::-;5824:3;5812:16;;5805:67;5816:6;-1:-1:-1;5916:65:83;5973:7;5967:3;5952:19;;5916:65;:::i;:::-;5906:75;;4959:1028;;;;;:::o;5992:406::-;;;;6169:3;6157:9;6148:7;6144:23;6140:33;6137:2;;;6191:6;6183;6176:22;6137:2;6219:53;6264:7;6253:9;6219:53;:::i;:::-;6209:63;;6291:41;6327:3;6316:9;6312:19;6291:41;:::i;:::-;6281:51;;6351:41;6387:3;6376:9;6372:19;6351:41;:::i;6403:321::-;;;6563:3;6551:9;6542:7;6538:23;6534:33;6531:2;;;6585:6;6577;6570:22;6531:2;6613:53;6658:7;6647:9;6613:53;:::i;:::-;6603:63;6713:3;6698:19;;;;6685:33;;-1:-1:-1;;;6521:203:83:o;6729:459::-;;;;6906:3;6894:9;6885:7;6881:23;6877:33;6874:2;;;6928:6;6920;6913:22;6874:2;6956:53;7001:7;6990:9;6956:53;:::i;:::-;6946:63;;7056:3;7045:9;7041:19;7028:33;7018:43;;7111:3;7100:9;7096:19;7083:33;7125;7152:5;7125:33;:::i;:::-;7177:5;7167:15;;;6864:324;;;;;:::o;7193:390::-;;;;7370:3;7358:9;7349:7;7345:23;7341:33;7338:2;;;7392:6;7384;7377:22;7338:2;7420:53;7465:7;7454:9;7420:53;:::i;:::-;7410:63;7520:3;7505:19;;7492:33;;-1:-1:-1;7572:3:83;7557:19;;;7544:33;;7328:255;-1:-1:-1;;;7328:255:83:o;7588:947::-;;;;;;;;7802:3;7790:9;7781:7;7777:23;7773:33;7770:2;;;7824:6;7816;7809:22;7770:2;7861:9;7855:16;7880:33;7907:5;7880:33;:::i;:::-;7932:5;7922:15;;;7982:2;7971:9;7967:18;7961:25;8031:7;8028:1;8017:22;8008:7;8005:35;7995:2;;8059:6;8051;8044:22;7995:2;8087:7;-1:-1:-1;8113:50:83;8159:2;8144:18;;8113:50;:::i;:::-;8103:60;;8182:50;8228:2;8217:9;8213:18;8182:50;:::i;:::-;8172:60;;8251:50;8296:3;8285:9;8281:19;8251:50;:::i;:::-;8241:60;;8320:50;8365:3;8354:9;8350:19;8320:50;:::i;:::-;8310:60;;8415:3;8404:9;8400:19;8394:26;8465:7;8458:15;8451:23;8442:7;8439:36;8429:2;;8494:6;8486;8479:22;8429:2;8522:7;8512:17;;;7760:775;;;;;;;;;;:::o;8540:194::-;;8663:2;8651:9;8642:7;8638:23;8634:32;8631:2;;;8684:6;8676;8669:22;8631:2;-1:-1:-1;8712:16:83;;8621:113;-1:-1:-1;8621:113:83:o;8739:258::-;;;8868:2;8856:9;8847:7;8843:23;8839:32;8836:2;;;8889:6;8881;8874:22;8836:2;-1:-1:-1;;8917:23:83;;;8987:2;8972:18;;;8959:32;;-1:-1:-1;8826:171:83:o;9002:255::-;;;9142:2;9130:9;9121:7;9117:23;9113:32;9110:2;;;9163:6;9155;9148:22;9110:2;-1:-1:-1;;9191:16:83;;9247:2;9232:18;;;9226:25;9191:16;;9226:25;;-1:-1:-1;9100:157:83:o;9262:257::-;;9373:2;9361:9;9352:7;9348:23;9344:32;9341:2;;;9394:6;9386;9379:22;9341:2;9438:9;9425:23;9457:32;9483:5;9457:32;:::i;9524:129::-;9603:42;9592:54;9580:67;;9570:83::o;9658:94::-;9736:8;9725:20;9713:33;;9703:49::o;9757:96::-;9835:10;9824:22;9812:35;;9802:51::o;9858:226::-;10034:42;10022:55;;;;10004:74;;9992:2;9977:18;;9959:125::o;10089:407::-;10301:42;10370:15;;;10352:34;;10422:15;;;10417:2;10402:18;;10395:43;10474:15;;;10469:2;10454:18;;10447:43;10279:2;10264:18;;10246:250::o;10501:470::-;10742:42;10811:15;;;10793:34;;10863:15;;;;10858:2;10843:18;;10836:43;10910:2;10895:18;;10888:34;10953:2;10938:18;;10931:34;;;;10719:3;10704:19;;10686:285::o;10976:368::-;11208:42;11196:55;;;;11178:74;;11283:2;11268:18;;11261:34;;;;11326:2;11311:18;;11304:34;11166:2;11151:18;;11133:211::o;11349:1377::-;;11727:3;11716:9;11712:19;11704:27;;11770:42;11762:6;11758:55;11747:9;11740:74;11850:6;11845:2;11834:9;11830:18;11823:34;11893:6;11888:2;11877:9;11873:18;11866:34;11936:6;11931:2;11920:9;11916:18;11909:34;11980:6;11974:3;11963:9;11959:19;11952:35;12037:6;12024:20;12018:3;12007:9;12003:19;11996:49;12107:2;12099:6;12095:15;12082:29;12076:3;12065:9;12061:19;12054:58;12174:2;12166:6;12162:15;12149:29;12143:3;12132:9;12128:19;12121:58;12226:2;12218:6;12214:15;12201:29;12239:32;12265:5;12239:32;:::i;:::-;12319:10;12308:22;12302:3;12287:19;;12280:51;12380:3;12368:16;;12355:30;12394:34;12355:30;12394:34;:::i;:::-;12437:49;12481:3;12470:9;12466:19;12457:7;12437:49;:::i;:::-;;12510:37;12542:3;12534:6;12530:16;12510:37;:::i;:::-;12556:49;12600:3;12589:9;12585:19;12576:7;12556:49;:::i;:::-;;12614;12658:3;12647:9;12643:19;12635:6;12614:49;:::i;:::-;12672:48;12715:3;12704:9;12700:19;12692:6;12672:48;:::i;:::-;11694:1032;;;;;;;;;;;:::o;12991:348::-;13196:42;13265:15;;;13247:34;;13317:15;;13312:2;13297:18;;13290:43;13174:2;13159:18;;13141:198::o;13866:270::-;14061:1;14050:21;;;14032:40;;14108:21;;14103:2;14088:18;;14081:49;14020:2;14005:18;;13987:149::o;14141:346::-;14343:2;14325:21;;;14382:2;14362:18;;;14355:30;14421:24;14416:2;14401:18;;14394:52;14478:2;14463:18;;14315:172::o;14492:344::-;14694:2;14676:21;;;14733:2;14713:18;;;14706:30;14772:22;14767:2;14752:18;;14745:50;14827:2;14812:18;;14666:170::o;14841:339::-;15043:2;15025:21;;;15082:2;15062:18;;;15055:30;15121:17;15116:2;15101:18;;15094:45;15171:2;15156:18;;15015:165::o;15185:404::-;15387:2;15369:21;;;15426:2;15406:18;;;15399:30;15465:34;15460:2;15445:18;;15438:62;15536:10;15531:2;15516:18;;15509:38;15579:3;15564:19;;15359:230::o;15594:349::-;15796:2;15778:21;;;15835:2;15815:18;;;15808:30;15874:27;15869:2;15854:18;;15847:55;15934:2;15919:18;;15768:175::o;15948:346::-;16150:2;16132:21;;;16189:2;16169:18;;;16162:30;16228:24;16223:2;16208:18;;16201:52;16285:2;16270:18;;16122:172::o;16299:398::-;16501:2;16483:21;;;16540:2;16520:18;;;16513:30;16579:34;16574:2;16559:18;;16552:62;16650:4;16645:2;16630:18;;16623:32;16687:3;16672:19;;16473:224::o;16702:410::-;16904:2;16886:21;;;16943:2;16923:18;;;16916:30;16982:34;16977:2;16962:18;;16955:62;17053:16;17048:2;17033:18;;17026:44;17102:3;17087:19;;16876:236::o;17117:343::-;17319:2;17301:21;;;17358:2;17338:18;;;17331:30;17397:21;17392:2;17377:18;;17370:49;17451:2;17436:18;;17291:169::o;17465:346::-;17667:2;17649:21;;;17706:2;17686:18;;;17679:30;17745:24;17740:2;17725:18;;17718:52;17802:2;17787:18;;17639:172::o;17816:344::-;18018:2;18000:21;;;18057:2;18037:18;;;18030:30;18096:22;18091:2;18076:18;;18069:50;18151:2;18136:18;;17990:170::o;18165:343::-;18367:2;18349:21;;;18406:2;18386:18;;;18379:30;18445:21;18440:2;18425:18;;18418:49;18499:2;18484:18;;18339:169::o;18513:353::-;18715:2;18697:21;;;18754:2;18734:18;;;18727:30;18793:31;18788:2;18773:18;;18766:59;18857:2;18842:18;;18687:179::o;18871:587::-;;19067:3;19056:9;19052:19;19044:27;;19090:42;19178:2;19169:6;19163:13;19159:22;19148:9;19141:41;19250:2;19242:4;19234:6;19230:17;19224:24;19220:33;19213:4;19202:9;19198:20;19191:63;19322:2;19314:4;19306:6;19302:17;19296:24;19292:33;19285:4;19274:9;19270:20;19263:63;;19382:4;19374:6;19370:17;19364:24;19357:4;19346:9;19342:20;19335:54;19445:4;19437:6;19433:17;19427:24;19420:4;19409:9;19405:20;19398:54;19034:424;;;;:::o;19463:526::-;19744:34;19732:47;;;;19714:66;;19827:1;19816:21;;;19811:2;19796:18;;19789:49;19874:21;;;;19869:2;19854:18;;19847:49;19927:2;19912:18;;19905:34;;;;19970:3;19955:19;;19948:35;19701:3;19686:19;;19668:321::o;19994:319::-;20178:34;20239:15;;;20221:34;;20291:15;;20286:2;20271:18;;20264:43;20156:2;20141:18;;20123:190::o;20318:390::-;20530:34;20591:15;;;20573:34;;20643:15;;;;20638:2;20623:18;;20616:43;20690:2;20675:18;;20668:34;;;;20508:2;20493:18;;20475:233::o;20713:289::-;20917:34;20905:47;;;;20887:66;;20984:2;20969:18;;20962:34;20875:2;20860:18;;20842:160::o;21007:177::-;21153:25;;;21141:2;21126:18;;21108:76::o;21189:391::-;21420:25;;;21476:2;21461:18;;21454:34;;;;21519:2;21504:18;;21497:34;21562:2;21547:18;;21540:34;21407:3;21392:19;;21374:206::o;21585:248::-;21759:25;;;21815:2;21800:18;;21793:34;21747:2;21732:18;;21714:119::o;21838:1218::-;;22186:3;22175:9;22171:19;22163:27;;22217:6;22206:9;22199:25;22260:6;22255:2;22244:9;22240:18;22233:34;22286:42;22376:2;22368:6;22364:15;22359:2;22348:9;22344:18;22337:43;22428:8;22420:6;22416:21;22411:2;22400:9;22396:18;22389:49;22487:58;22479:6;22475:71;22469:3;22458:9;22454:19;22447:100;22596:2;22588:6;22584:15;22578:3;22567:9;22563:19;22556:44;;22643:6;22637:13;22631:3;22620:9;22616:19;22609:42;22706:2;22698:6;22694:15;22688:22;22682:3;22671:9;22667:19;22660:51;22766:2;22758:6;22754:15;22748:22;22742:3;22731:9;22727:19;22720:51;22818:2;22810:6;22806:15;22800:22;22841:10;22906:2;22892:12;22888:21;22882:3;22871:9;22867:19;22860:50;22976:2;22969:3;22961:6;22957:16;22951:23;22947:32;22941:3;22930:9;22926:19;22919:61;23046:2;23039:3;23031:6;23027:16;23021:23;23017:32;23011:3;23000:9;22996:19;22989:61;;;22153:903;;;;;;;;;;:::o;23061:319::-;23263:25;;;23319:2;23304:18;;23297:34;;;;23362:2;23347:18;;23340:34;23251:2;23236:18;;23218:162::o;23385:525::-;23658:10;23646:23;;;;23628:42;;23717:1;23706:21;;;23701:2;23686:18;;23679:49;23764:21;;;23759:2;23744:18;;23737:49;23833:2;23822:22;23817:2;23802:18;;23795:50;23882:21;;23876:3;23861:19;;23854:50;23615:3;23600:19;;23582:328::o;24454:1119::-;24615:5;24602:19;24596:4;24589:33;24676:2;24669:5;24665:14;24652:28;24648:1;24642:4;24638:12;24631:50;24735:2;24728:5;24724:14;24711:28;24707:1;24701:4;24697:12;24690:50;24777:1;24771:4;24767:12;24827:2;24820:5;24816:14;24803:28;24840:34;24866:7;24840:34;:::i;:::-;25001:10;24992:7;24988:24;24919:66;24906:10;24900:17;24896:90;24893:120;24883:130;;25041:2;25029:10;25022:22;25092:3;25085:5;25081:15;25068:29;25106:34;25132:7;25106:34;:::i;:::-;25261:18;25251:7;25247:2;25243:16;25239:41;25170:66;25166:2;25162:75;25159:122;25149:132;;;25309:2;25297:10;25290:22;25360:3;25353:5;25349:15;25336:29;25374:34;25400:7;25374:34;:::i;:::-;25538:26;25528:7;25524:2;25520:16;25516:49;25447:66;25443:2;25439:75;25436:130;25424:10;25417:150;;;;24579:994;;:::o;25578:156::-;25666:42;25659:5;25655:54;25648:5;25645:65;25635:2;;25724:1;25721;25714:12;25635:2;25625:109;:::o;25739:123::-;25826:10;25819:5;25815:22;25808:5;25805:33;25795:2;;25852:1;25849;25842:12

Swarm Source

none

Block Transaction Gas Used Reward
view all blocks sequenced

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

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
[ Download: CSV Export  ]
[ Download: CSV Export  ]

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