{
  "language": "Solidity",
  "sources": {
    "contracts/base/CloneFactory.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity ^0.8.15;\n\n// Reference: https://github.com/optionality/clone-factory/blob/master/contracts/CloneFactory.sol\nabstract contract CloneFactory {\n    function _createClone(address target) internal returns (address result) {\n        bytes20 targetBytes = bytes20(target);\n        assembly {\n            let clone := mload(0x40)\n            mstore(clone, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)\n            mstore(add(clone, 0x14), targetBytes)\n            mstore(add(clone, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)\n            result := create(0, clone, 0x37)\n        }\n    }\n\n    function _isClone(address target, address query) internal view returns (bool result) {\n        bytes20 targetBytes = bytes20(target);\n        assembly {\n            let clone := mload(0x40)\n            mstore(clone, 0x363d3d373d3d3d363d7300000000000000000000000000000000000000000000)\n            mstore(add(clone, 0xa), targetBytes)\n            mstore(add(clone, 0x1e), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)\n\n            let other := add(clone, 0x40)\n            extcodecopy(query, other, 0, 0x2d)\n            result := and(eq(mload(clone), mload(other)), eq(mload(add(clone, 0xd)), mload(add(other, 0xd))))\n        }\n    }\n}\n"
    },
    "contracts/NFTGaugeFactory.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity ^0.8.15;\n\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\n\nimport \"./base/CloneFactory.sol\";\nimport \"./interfaces/INFTGaugeFactory.sol\";\nimport \"./libraries/Integers.sol\";\nimport \"./libraries/Tokens.sol\";\nimport \"./NFTGauge.sol\";\n\ncontract NFTGaugeFactory is CloneFactory, Ownable, INFTGaugeFactory {\n    using SafeERC20 for IERC20;\n    using Integers for int128;\n    using Integers for uint256;\n\n    struct Fee {\n        uint64 timestamp;\n        uint192 amountPerShare;\n    }\n\n    address public immutable override tokenURIRenderer;\n    address public immutable override minter;\n    address public immutable override votingEscrow;\n\n    address public override target;\n    uint256 public override targetVersion;\n\n    uint256 public override feeRatio;\n    mapping(address => address) public override currencyConverter;\n    mapping(address => address) public override gauges;\n    mapping(address => bool) public override isGauge;\n\n    mapping(address => Fee[]) public override fees;\n    mapping(address => mapping(address => uint256)) public override lastFeeClaimed;\n\n    constructor(\n        address _tokenURIRenderer,\n        address _minter,\n        uint256 _feeRatio\n    ) {\n        tokenURIRenderer = _tokenURIRenderer;\n        minter = _minter;\n        votingEscrow = IGaugeController(IMinter(_minter).controller()).votingEscrow();\n        feeRatio = _feeRatio;\n\n        emit UpdateFeeRatio(_feeRatio);\n\n        NFTGauge gauge = new NFTGauge();\n        gauge.initialize(address(0), address(0), address(0));\n        target = address(gauge);\n    }\n\n    function feesLength(address token) external view override returns (uint256) {\n        return fees[token].length;\n    }\n\n    function upgradeTarget(address _target) external override onlyOwner {\n        target = _target;\n\n        uint256 version = targetVersion + 1;\n        targetVersion = version;\n\n        emit UpgradeTarget(_target, version);\n    }\n\n    function updateCurrencyConverter(address token, address converter) external override onlyOwner {\n        currencyConverter[token] = converter;\n\n        emit UpdateCurrencyConverter(token, converter);\n    }\n\n    function updateFeeRatio(uint256 _feeRatio) external override onlyOwner {\n        feeRatio = _feeRatio;\n\n        emit UpdateFeeRatio(_feeRatio);\n    }\n\n    function createNFTGauge(address nftContract) external override returns (address gauge) {\n        require(gauges[nftContract] == address(0), \"NFTGF: GAUGE_CREATED\");\n\n        gauge = _createClone(target);\n        INFTGauge(gauge).initialize(nftContract, tokenURIRenderer, minter);\n\n        gauges[nftContract] = gauge;\n        isGauge[gauge] = true;\n\n        emit CreateNFTGauge(nftContract, gauge);\n    }\n\n    function executePayment(\n        address currency,\n        address from,\n        uint256 amount\n    ) external override {\n        require(isGauge[msg.sender], \"NFTGF: FORBIDDEN\");\n        require(currencyConverter[currency] != address(0), \"NFTGF: INVALID_TOKEN\");\n\n        IERC20(currency).safeTransferFrom(from, msg.sender, amount);\n    }\n\n    function distributeFeesETH() external payable override returns (uint256 amountFee) {\n        amountFee = (msg.value * feeRatio) / 10000;\n        _distributeFees(address(0), amountFee);\n    }\n\n    function distributeFees(address token, uint256 amount) external override returns (uint256 amountFee) {\n        amountFee = (amount * feeRatio) / 10000;\n        _distributeFees(token, amountFee);\n    }\n\n    function _distributeFees(address token, uint256 amount) internal {\n        require(isGauge[msg.sender], \"NFTGF: FORBIDDEN\");\n\n        fees[token].push(\n            Fee(uint64(block.timestamp), uint192((amount * 1e18) / IVotingEscrow(votingEscrow).totalSupply()))\n        );\n\n        emit DistributeFees(token, fees[token].length - 1, amount);\n    }\n\n    /**\n     * @notice Claim accumulated fees\n     * @param token In which currency fees were paid\n     * @param to the last index of the fee (exclusive)\n     */\n    function claimFees(address token, uint256 to) external override {\n        uint256 from = lastFeeClaimed[token][msg.sender];\n\n        (int128 value, , uint256 start, ) = IVotingEscrow(votingEscrow).locked(msg.sender);\n        require(value > 0, \"NFTGF: LOCK_NOT_FOUND\");\n\n        uint256 epoch = IVotingEscrow(votingEscrow).userPointEpoch(msg.sender);\n        (int128 bias, int128 slope, uint256 ts, ) = IVotingEscrow(votingEscrow).userPointHistory(msg.sender, epoch);\n\n        uint256 amount;\n        for (uint256 i = from; i < to; ) {\n            Fee memory fee = fees[token][i];\n            if (start < fee.timestamp) {\n                int128 balance = bias - slope * (uint256(fee.timestamp) - ts).toInt128();\n                if (balance > 0) {\n                    amount += (balance.toUint256() * uint256(fee.amountPerShare)) / 1e18;\n                }\n            }\n            unchecked {\n                ++i;\n            }\n        }\n        lastFeeClaimed[token][msg.sender] = to;\n\n        emit ClaimFees(token, amount, msg.sender);\n        Tokens.transfer(token, msg.sender, amount);\n    }\n}\n"
    },
    "@openzeppelin/contracts/access/Ownable.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (access/Ownable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/Context.sol\";\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract Ownable is Context {\n    address private _owner;\n\n    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Initializes the contract setting the deployer as the initial owner.\n     */\n    constructor() {\n        _transferOwnership(_msgSender());\n    }\n\n    /**\n     * @dev Returns the address of the current owner.\n     */\n    function owner() public view virtual returns (address) {\n        return _owner;\n    }\n\n    /**\n     * @dev Throws if called by any account other than the owner.\n     */\n    modifier onlyOwner() {\n        require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n        _;\n    }\n\n    /**\n     * @dev Leaves the contract without owner. It will not be possible to call\n     * `onlyOwner` functions anymore. Can only be called by the current owner.\n     *\n     * NOTE: Renouncing ownership will leave the contract without an owner,\n     * thereby removing any functionality that is only available to the owner.\n     */\n    function renounceOwnership() public virtual onlyOwner {\n        _transferOwnership(address(0));\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual onlyOwner {\n        require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n        _transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual {\n        address oldOwner = _owner;\n        _owner = newOwner;\n        emit OwnershipTransferred(oldOwner, newOwner);\n    }\n}\n"
    },
    "contracts/interfaces/INFTGaugeFactory.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity ^0.8.0;\n\ninterface INFTGaugeFactory {\n    event UpgradeTarget(address target, uint256 indexed version);\n    event UpdateCurrencyConverter(address indexed token, address indexed converter);\n    event CreateNFTGauge(address indexed nftContract, address indexed gauge);\n    event UpdateFeeRatio(uint256 feeRatio);\n    event DistributeFees(address indexed token, uint256 indexed id, uint256 amount);\n    event ClaimFees(address indexed token, uint256 amount, address indexed to);\n\n    function tokenURIRenderer() external view returns (address);\n\n    function minter() external view returns (address);\n\n    function votingEscrow() external view returns (address);\n\n    function target() external view returns (address);\n\n    function targetVersion() external view returns (uint256);\n\n    function feeRatio() external view returns (uint256);\n\n    function currencyConverter(address currency) external view returns (address);\n\n    function gauges(address nftContract) external view returns (address);\n\n    function isGauge(address addr) external view returns (bool);\n\n    function fees(address token, uint256 id) external view returns (uint64 timestamp, uint192 amountPerShare);\n\n    function lastFeeClaimed(address token, address user) external view returns (uint256);\n\n    function feesLength(address token) external view returns (uint256);\n\n    function upgradeTarget(address target) external;\n\n    function updateCurrencyConverter(address token, address converter) external;\n\n    function updateFeeRatio(uint256 feeRatio) external;\n\n    function createNFTGauge(address nftContract) external returns (address gauge);\n\n    function executePayment(\n        address currency,\n        address from,\n        uint256 amount\n    ) external;\n\n    function distributeFeesETH() external payable returns (uint256 amountFee);\n\n    function distributeFees(address token, uint256 amount) external returns (uint256 amountFee);\n\n    function claimFees(address token, uint256 to) external;\n}\n"
    },
    "contracts/libraries/Integers.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity ^0.8.15;\n\nlibrary Integers {\n    function toInt128(uint256 u) internal pure returns (int128) {\n        return int128(int256(u));\n    }\n\n    function toUint256(int128 i) internal pure returns (uint256) {\n        return uint256(uint128(i));\n    }\n}\n"
    },
    "contracts/libraries/Tokens.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity ^0.8.15;\n\nimport \"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol\";\n\nlibrary Tokens {\n    using SafeERC20 for IERC20;\n\n    function transfer(\n        address token,\n        address to,\n        uint256 amount\n    ) internal {\n        if (token == address(0)) {\n            (bool success, ) = payable(to).call{value: amount}(\"\");\n            require(success, \"LEVX: FAILED_TO_TRANSFER_ETH\");\n        } else {\n            IERC20(token).safeTransfer(to, amount);\n        }\n    }\n}\n"
    },
    "contracts/NFTGauge.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity ^0.8.15;\n\nimport \"./base/WrappedERC721.sol\";\nimport \"./interfaces/INFTGauge.sol\";\nimport \"./interfaces/IGaugeController.sol\";\nimport \"./interfaces/IMinter.sol\";\nimport \"./interfaces/IVotingEscrow.sol\";\nimport \"./interfaces/ICurrencyConverter.sol\";\nimport \"./libraries/Tokens.sol\";\nimport \"./libraries/Math.sol\";\nimport \"./libraries/NFTs.sol\";\n\ncontract NFTGauge is WrappedERC721, INFTGauge {\n    struct Snapshot {\n        uint64 timestamp;\n        uint192 value;\n    }\n\n    address public override minter;\n    address public override controller;\n    address public override votingEscrow;\n    uint256 public override futureEpochTime;\n\n    mapping(uint256 => uint256) public override dividendRatios;\n    mapping(address => mapping(uint256 => Snapshot[])) public override dividends; // currency -> tokenId -> Snapshot\n    mapping(address => mapping(uint256 => mapping(address => uint256))) public override lastDividendClaimed; // currency -> tokenId -> user -> index\n\n    int128 public override period;\n    mapping(int128 => uint256) public override periodTimestamp;\n    mapping(int128 => uint256) public override integrateInvSupply; // bump epoch when rate() changes\n\n    mapping(uint256 => mapping(address => int128)) public override periodOf; // tokenId -> user -> period\n    mapping(uint256 => mapping(address => uint256)) public override integrateFraction; // tokenId -> user -> fraction\n\n    uint256 public override inflationRate;\n\n    bool public override isKilled;\n\n    mapping(address => mapping(uint256 => uint256)) public override userWeight;\n    mapping(address => uint256) public override userWeightSum;\n\n    uint256 internal _interval;\n\n    mapping(uint256 => uint256) internal _nonces; // tokenId -> nonce\n    mapping(uint256 => mapping(uint256 => mapping(address => Snapshot[]))) internal _points; // tokenId -> nonce -> user -> Snapshot\n    mapping(uint256 => mapping(uint256 => Snapshot[])) internal _pointsSum; // tokenId -> nonce -> Snapshot\n    Snapshot[] internal _pointsTotal;\n\n    function initialize(\n        address _nftContract,\n        address _tokenURIRenderer,\n        address _minter\n    ) external override initializer {\n        __WrappedERC721_init(_nftContract, _tokenURIRenderer);\n\n        minter = _minter;\n        address _controller = IMinter(_minter).controller();\n        controller = _controller;\n        votingEscrow = IGaugeController(_controller).votingEscrow();\n        periodTimestamp[0] = block.timestamp;\n        inflationRate = IMinter(_minter).rate();\n        futureEpochTime = IMinter(_minter).futureEpochTimeWrite();\n        _interval = IGaugeController(_controller).interval();\n    }\n\n    function integrateCheckpoint() external view override returns (uint256) {\n        return periodTimestamp[period];\n    }\n\n    function points(uint256 tokenId, address user) public view override returns (uint256) {\n        return _lastValue(_points[tokenId][_nonces[tokenId]][user]);\n    }\n\n    function pointsAt(\n        uint256 tokenId,\n        address user,\n        uint256 timestamp\n    ) public view override returns (uint256) {\n        return _getValueAt(_points[tokenId][_nonces[tokenId]][user], timestamp);\n    }\n\n    function pointsSum(uint256 tokenId) external view override returns (uint256) {\n        return _lastValue(_pointsSum[tokenId][_nonces[tokenId]]);\n    }\n\n    function pointsSumAt(uint256 tokenId, uint256 timestamp) public view override returns (uint256) {\n        return _getValueAt(_pointsSum[tokenId][_nonces[tokenId]], timestamp);\n    }\n\n    function pointsTotal() external view override returns (uint256) {\n        return _lastValue(_pointsTotal);\n    }\n\n    function pointsTotalAt(uint256 timestamp) external view override returns (uint256) {\n        return _getValueAt(_pointsTotal, timestamp);\n    }\n\n    function dividendsLength(address token, uint256 tokenId) external view override returns (uint256) {\n        return dividends[token][tokenId].length;\n    }\n\n    /**\n     * @notice Toggle the killed status of the gauge\n     */\n    function killMe() external override {\n        require(msg.sender == controller, \"NFTG: FORBIDDDEN\");\n        isKilled = !isKilled;\n    }\n\n    function _checkpoint() internal returns (int128 _period, uint256 _integrateInvSupply) {\n        address _minter = minter;\n        address _controller = controller;\n        _period = period;\n        uint256 _periodTime = periodTimestamp[_period];\n        _integrateInvSupply = integrateInvSupply[_period];\n        uint256 rate = inflationRate;\n        uint256 newRate = rate;\n        uint256 prevFutureEpoch = futureEpochTime;\n        if (prevFutureEpoch >= _periodTime) {\n            futureEpochTime = IMinter(_minter).futureEpochTimeWrite();\n            newRate = IMinter(_minter).rate();\n            inflationRate = newRate;\n        }\n        IGaugeController(_controller).checkpointGauge(address(this));\n\n        uint256 total = _lastValue(_pointsTotal);\n\n        if (isKilled) rate = 0; // Stop distributing inflation as soon as killed\n\n        // Update integral of 1/total\n        if (block.timestamp > _periodTime) {\n            uint256 interval = _interval;\n            uint256 prevWeekTime = _periodTime;\n            uint256 weekTime = Math.min(((_periodTime + interval) / interval) * interval, block.timestamp);\n            for (uint256 i; i < 250; ) {\n                uint256 dt = weekTime - prevWeekTime;\n                uint256 w = IGaugeController(_controller).gaugeRelativeWeight(\n                    address(this),\n                    (prevWeekTime / interval) * interval\n                );\n\n                if (total > 0) {\n                    if (prevFutureEpoch >= prevWeekTime && prevFutureEpoch < weekTime) {\n                        // If we went across one or multiple epochs, apply the rate\n                        // of the first epoch until it ends, and then the rate of\n                        // the last epoch.\n                        // If more than one epoch is crossed - the gauge gets less,\n                        // but that'd meen it wasn't called for more than 1 year\n                        _integrateInvSupply += (rate * w * (prevFutureEpoch - prevWeekTime)) / total;\n                        rate = newRate;\n                        _integrateInvSupply += (rate * w * (weekTime - prevFutureEpoch)) / total;\n                    } else {\n                        _integrateInvSupply += (rate * w * dt) / total;\n                    }\n                }\n\n                if (weekTime == block.timestamp) break;\n                prevWeekTime = weekTime;\n                weekTime = Math.min(weekTime + interval, block.timestamp);\n\n                unchecked {\n                    ++i;\n                }\n            }\n        }\n\n        ++_period;\n        period = _period;\n        periodTimestamp[_period] = block.timestamp;\n        integrateInvSupply[_period] = _integrateInvSupply;\n    }\n\n    /**\n     * @notice Checkpoint for a user for a specific token\n     * @param tokenId Token Id\n     * @param user User address\n     */\n    function userCheckpoint(uint256 tokenId, address user) public override {\n        require(msg.sender == user || user == minter, \"NFTG: FORBIDDEN\");\n        (int128 _period, uint256 _integrateInvSupply) = _checkpoint();\n\n        // Update user-specific integrals\n        int128 userPeriod = periodOf[tokenId][user];\n        uint256 oldIntegrateInvSupply = integrateInvSupply[userPeriod];\n        uint256 dIntegrate = _integrateInvSupply - oldIntegrateInvSupply;\n        if (dIntegrate > 0) {\n            uint256 nonce = _nonces[tokenId];\n            uint256 sum = _lastValue(_pointsSum[tokenId][nonce]);\n            uint256 pt = _lastValue(_points[tokenId][nonce][user]);\n            integrateFraction[tokenId][user] += (pt * dIntegrate * 2) / 3 / 1e18; // 67% goes to voters\n            if (ownerOf(tokenId) == user) {\n                integrateFraction[tokenId][user] += (sum * dIntegrate) / 3 / 1e18; // 33% goes to the owner\n            }\n        }\n        periodOf[tokenId][user] = _period;\n    }\n\n    /**\n     * @notice Mint a wrapped NFT and commit gauge voting to this tokenId\n     * @param tokenId Token Id to deposit\n     * @param dividendRatio Dividend ratio for the voters in bps (units of 0.01%)\n     * @param to The owner of the newly minted wrapped NFT\n     * @param _userWeight Weight for a gauge in bps (units of 0.01%). Minimal is 0.01%. Ignored if 0\n     */\n    function wrap(\n        uint256 tokenId,\n        uint256 dividendRatio,\n        address to,\n        uint256 _userWeight\n    ) public override {\n        require(dividendRatio <= 10000, \"NFTG: INVALID_RATIO\");\n\n        dividendRatios[tokenId] = dividendRatio;\n\n        _mint(to, tokenId);\n\n        vote(tokenId, _userWeight);\n\n        emit Wrap(tokenId, to);\n\n        NFTs.safeTransferFrom(nftContract, msg.sender, address(this), tokenId);\n    }\n\n    function unwrap(uint256 tokenId, address to) public override {\n        require(ownerOf(tokenId) == msg.sender, \"NFTG: FORBIDDEN\");\n\n        dividendRatios[tokenId] = 0;\n\n        _burn(tokenId);\n\n        uint256 nonce = _nonces[tokenId];\n        _updateValueAtNow(_pointsTotal, _lastValue(_pointsTotal) - _lastValue(_pointsSum[tokenId][nonce]));\n        _nonces[tokenId] = nonce + 1;\n\n        emit Unwrap(tokenId, to);\n\n        NFTs.safeTransferFrom(nftContract, address(this), to, tokenId);\n    }\n\n    function vote(uint256 tokenId, uint256 _userWeight) public override {\n        require(_exists(tokenId), \"NFTG: NON_EXISTENT\");\n\n        userCheckpoint(tokenId, msg.sender);\n\n        uint256 balance = IVotingEscrow(votingEscrow).balanceOf(msg.sender);\n        uint256 pointNew = (balance * _userWeight) / 10000;\n        uint256 pointOld = points(tokenId, msg.sender);\n\n        uint256 nonce = _nonces[tokenId];\n        _updateValueAtNow(_points[tokenId][nonce][msg.sender], pointNew);\n        _updateValueAtNow(_pointsSum[tokenId][nonce], _lastValue(_pointsSum[tokenId][nonce]) + pointNew - pointOld);\n        _updateValueAtNow(_pointsTotal, _lastValue(_pointsTotal) + pointNew - pointOld);\n\n        uint256 userWeightOld = userWeight[msg.sender][tokenId];\n        uint256 _userWeightSum = userWeightSum[msg.sender] + _userWeight - userWeightOld;\n        userWeight[msg.sender][tokenId] = _userWeight;\n        userWeightSum[msg.sender] = _userWeightSum;\n\n        IGaugeController(controller).voteForGaugeWeights(msg.sender, _userWeightSum);\n\n        emit Vote(tokenId, msg.sender, _userWeight);\n    }\n\n    function claimDividends(address token, uint256 tokenId) external override {\n        uint256 amount;\n        uint256 _last = lastDividendClaimed[token][tokenId][msg.sender];\n        uint256 i;\n        while (i < 250) {\n            uint256 id = _last + i;\n            if (id >= dividends[token][tokenId].length) break;\n\n            Snapshot memory dividend = dividends[token][tokenId][id];\n            uint256 pt = _getValueAt(_points[tokenId][_nonces[tokenId]][msg.sender], dividend.timestamp);\n            if (pt > 0) {\n                amount += (pt * uint256(dividend.value)) / 1e18;\n            }\n\n            unchecked {\n                ++i;\n            }\n        }\n\n        require(i > 0, \"NFTG: NO_AMOUNT_TO_CLAIM\");\n        lastDividendClaimed[token][tokenId][msg.sender] = _last + i;\n\n        emit ClaimDividends(token, tokenId, amount, msg.sender);\n        Tokens.transfer(token, msg.sender, amount);\n    }\n\n    /**\n     * @dev `_getValueAt` retrieves the number of tokens at a given time\n     * @param snapshots The history of values being queried\n     * @param timestamp The block timestamp to retrieve the value at\n     * @return The weight at `timestamp`\n     */\n    function _getValueAt(Snapshot[] storage snapshots, uint256 timestamp) internal view returns (uint256) {\n        if (snapshots.length == 0) return 0;\n\n        // Shortcut for the actual value\n        Snapshot storage last = snapshots[snapshots.length - 1];\n        if (timestamp >= last.timestamp) return last.value;\n        if (timestamp < snapshots[0].timestamp) return 0;\n\n        // Binary search of the value in the array\n        uint256 min = 0;\n        uint256 max = snapshots.length - 1;\n        while (max > min) {\n            uint256 mid = (max + min + 1) / 2;\n            if (snapshots[mid].timestamp <= timestamp) {\n                min = mid;\n            } else {\n                max = mid - 1;\n            }\n        }\n        return snapshots[min].value;\n    }\n\n    function _lastValue(Snapshot[] storage snapshots) internal view returns (uint256) {\n        uint256 length = snapshots.length;\n        return length > 0 ? uint256(snapshots[length - 1].value) : 0;\n    }\n\n    /**\n     * @dev `_updateValueAtNow` is used to update snapshots\n     * @param snapshots The history of data being updated\n     * @param _value The new number of weight\n     */\n    function _updateValueAtNow(Snapshot[] storage snapshots, uint256 _value) internal {\n        if ((snapshots.length == 0) || (snapshots[snapshots.length - 1].timestamp < block.timestamp)) {\n            Snapshot storage newCheckPoint = snapshots.push();\n            newCheckPoint.timestamp = uint64(block.timestamp);\n            newCheckPoint.value = uint192(_value);\n        } else {\n            Snapshot storage oldCheckPoint = snapshots[snapshots.length - 1];\n            oldCheckPoint.value = uint192(_value);\n        }\n    }\n\n    function _settle(\n        uint256 tokenId,\n        address currency,\n        address to,\n        uint256 amount\n    ) internal override {\n        address _factory = factory;\n        address converter = INFTGaugeFactory(_factory).currencyConverter(currency);\n        uint256 amountETH = ICurrencyConverter(converter).getAmountETH(amount);\n        if (amountETH >= 1e18) {\n            IGaugeController(controller).increaseGaugeWeight(amountETH / 1e18);\n        }\n\n        uint256 fee;\n        if (currency == address(0)) {\n            fee = INFTGaugeFactory(_factory).distributeFeesETH{value: amount}();\n        } else {\n            fee = INFTGaugeFactory(_factory).distributeFees(currency, amount);\n        }\n\n        uint256 dividend;\n        uint256 sum = _lastValue(_pointsSum[tokenId][_nonces[tokenId]]);\n        if (sum > 0) {\n            dividend = ((amount - fee) * dividendRatios[tokenId]) / 10000;\n            dividends[currency][tokenId].push(Snapshot(uint64(block.timestamp), uint192((dividend * 1e18) / sum)));\n            emit DistributeDividend(currency, tokenId, dividend);\n        }\n        Tokens.transfer(currency, to, amount - fee - dividend);\n    }\n\n    function _beforeTokenTransfer(\n        address from,\n        address to,\n        uint256 tokenId\n    ) internal override {\n        super._beforeTokenTransfer(from, to, tokenId);\n\n        userCheckpoint(tokenId, from);\n    }\n}\n"
    },
    "@openzeppelin/contracts/utils/Context.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n    function _msgSender() internal view virtual returns (address) {\n        return msg.sender;\n    }\n\n    function _msgData() internal view virtual returns (bytes calldata) {\n        return msg.data;\n    }\n}\n"
    },
    "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/utils/SafeERC20.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC20.sol\";\nimport \"../../../utils/Address.sol\";\n\n/**\n * @title SafeERC20\n * @dev Wrappers around ERC20 operations that throw on failure (when the token\n * contract returns false). Tokens that return no value (and instead revert or\n * throw on failure) are also supported, non-reverting calls are assumed to be\n * successful.\n * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,\n * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.\n */\nlibrary SafeERC20 {\n    using Address for address;\n\n    function safeTransfer(\n        IERC20 token,\n        address to,\n        uint256 value\n    ) internal {\n        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));\n    }\n\n    function safeTransferFrom(\n        IERC20 token,\n        address from,\n        address to,\n        uint256 value\n    ) internal {\n        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));\n    }\n\n    /**\n     * @dev Deprecated. This function has issues similar to the ones found in\n     * {IERC20-approve}, and its usage is discouraged.\n     *\n     * Whenever possible, use {safeIncreaseAllowance} and\n     * {safeDecreaseAllowance} instead.\n     */\n    function safeApprove(\n        IERC20 token,\n        address spender,\n        uint256 value\n    ) internal {\n        // safeApprove should only be called when setting an initial allowance,\n        // or when resetting it to zero. To increase and decrease it, use\n        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'\n        require(\n            (value == 0) || (token.allowance(address(this), spender) == 0),\n            \"SafeERC20: approve from non-zero to non-zero allowance\"\n        );\n        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));\n    }\n\n    function safeIncreaseAllowance(\n        IERC20 token,\n        address spender,\n        uint256 value\n    ) internal {\n        uint256 newAllowance = token.allowance(address(this), spender) + value;\n        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));\n    }\n\n    function safeDecreaseAllowance(\n        IERC20 token,\n        address spender,\n        uint256 value\n    ) internal {\n        unchecked {\n            uint256 oldAllowance = token.allowance(address(this), spender);\n            require(oldAllowance >= value, \"SafeERC20: decreased allowance below zero\");\n            uint256 newAllowance = oldAllowance - value;\n            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));\n        }\n    }\n\n    /**\n     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement\n     * on the return value: the return value is optional (but if data is returned, it must not be false).\n     * @param token The token targeted by the call.\n     * @param data The call data (encoded using abi.encode or one of its variants).\n     */\n    function _callOptionalReturn(IERC20 token, bytes memory data) private {\n        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since\n        // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that\n        // the target address contains contract code and also asserts for success in the low-level call.\n\n        bytes memory returndata = address(token).functionCall(data, \"SafeERC20: low-level call failed\");\n        if (returndata.length > 0) {\n            // Return data is optional\n            require(abi.decode(returndata, (bool)), \"SafeERC20: ERC20 operation did not succeed\");\n        }\n    }\n}\n"
    },
    "@openzeppelin/contracts/token/ERC20/IERC20.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IERC20 {\n    /**\n     * @dev Emitted when `value` tokens are moved from one account (`from`) to\n     * another (`to`).\n     *\n     * Note that `value` may be zero.\n     */\n    event Transfer(address indexed from, address indexed to, uint256 value);\n\n    /**\n     * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n     * a call to {approve}. `value` is the new allowance.\n     */\n    event Approval(address indexed owner, address indexed spender, uint256 value);\n\n    /**\n     * @dev Returns the amount of tokens in existence.\n     */\n    function totalSupply() external view returns (uint256);\n\n    /**\n     * @dev Returns the amount of tokens owned by `account`.\n     */\n    function balanceOf(address account) external view returns (uint256);\n\n    /**\n     * @dev Moves `amount` tokens from the caller's account to `to`.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transfer(address to, uint256 amount) external returns (bool);\n\n    /**\n     * @dev Returns the remaining number of tokens that `spender` will be\n     * allowed to spend on behalf of `owner` through {transferFrom}. This is\n     * zero by default.\n     *\n     * This value changes when {approve} or {transferFrom} are called.\n     */\n    function allowance(address owner, address spender) external view returns (uint256);\n\n    /**\n     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * IMPORTANT: Beware that changing an allowance with this method brings the risk\n     * that someone may use both the old and the new allowance by unfortunate\n     * transaction ordering. One possible solution to mitigate this race\n     * condition is to first reduce the spender's allowance to 0 and set the\n     * desired value afterwards:\n     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n     *\n     * Emits an {Approval} event.\n     */\n    function approve(address spender, uint256 amount) external returns (bool);\n\n    /**\n     * @dev Moves `amount` tokens from `from` to `to` using the\n     * allowance mechanism. `amount` is then deducted from the caller's\n     * allowance.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transferFrom(\n        address from,\n        address to,\n        uint256 amount\n    ) external returns (bool);\n}\n"
    },
    "@openzeppelin/contracts/utils/Address.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.5.0) (utils/Address.sol)\n\npragma solidity ^0.8.1;\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary Address {\n    /**\n     * @dev Returns true if `account` is a contract.\n     *\n     * [IMPORTANT]\n     * ====\n     * It is unsafe to assume that an address for which this function returns\n     * false is an externally-owned account (EOA) and not a contract.\n     *\n     * Among others, `isContract` will return false for the following\n     * types of addresses:\n     *\n     *  - an externally-owned account\n     *  - a contract in construction\n     *  - an address where a contract will be created\n     *  - an address where a contract lived, but was destroyed\n     * ====\n     *\n     * [IMPORTANT]\n     * ====\n     * You shouldn't rely on `isContract` to protect against flash loan attacks!\n     *\n     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n     * constructor.\n     * ====\n     */\n    function isContract(address account) internal view returns (bool) {\n        // This method relies on extcodesize/address.code.length, which returns 0\n        // for contracts in construction, since the code is only stored at the end\n        // of the constructor execution.\n\n        return account.code.length > 0;\n    }\n\n    /**\n     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n     * `recipient`, forwarding all available gas and reverting on errors.\n     *\n     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n     * of certain opcodes, possibly making contracts go over the 2300 gas limit\n     * imposed by `transfer`, making them unable to receive funds via\n     * `transfer`. {sendValue} removes this limitation.\n     *\n     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n     *\n     * IMPORTANT: because control is transferred to `recipient`, care must be\n     * taken to not create reentrancy vulnerabilities. Consider using\n     * {ReentrancyGuard} or the\n     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n     */\n    function sendValue(address payable recipient, uint256 amount) internal {\n        require(address(this).balance >= amount, \"Address: insufficient balance\");\n\n        (bool success, ) = recipient.call{value: amount}(\"\");\n        require(success, \"Address: unable to send value, recipient may have reverted\");\n    }\n\n    /**\n     * @dev Performs a Solidity function call using a low level `call`. A\n     * plain `call` is an unsafe replacement for a function call: use this\n     * function instead.\n     *\n     * If `target` reverts with a revert reason, it is bubbled up by this\n     * function (like regular Solidity function calls).\n     *\n     * Returns the raw returned data. To convert to the expected return value,\n     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n     *\n     * Requirements:\n     *\n     * - `target` must be a contract.\n     * - calling `target` with `data` must not revert.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionCall(target, data, \"Address: low-level call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n     * `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but also transferring `value` wei to `target`.\n     *\n     * Requirements:\n     *\n     * - the calling contract must have an ETH balance of at least `value`.\n     * - the called Solidity function must be `payable`.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(\n        address target,\n        bytes memory data,\n        uint256 value\n    ) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n     * with `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(\n        address target,\n        bytes memory data,\n        uint256 value,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        require(address(this).balance >= value, \"Address: insufficient balance for call\");\n        require(isContract(target), \"Address: call to non-contract\");\n\n        (bool success, bytes memory returndata) = target.call{value: value}(data);\n        return verifyCallResult(success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n        return functionStaticCall(target, data, \"Address: low-level static call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        require(isContract(target), \"Address: static call to non-contract\");\n\n        (bool success, bytes memory returndata) = target.staticcall(data);\n        return verifyCallResult(success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        require(isContract(target), \"Address: delegate call to non-contract\");\n\n        (bool success, bytes memory returndata) = target.delegatecall(data);\n        return verifyCallResult(success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the\n     * revert reason using the provided one.\n     *\n     * _Available since v4.3._\n     */\n    function verifyCallResult(\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal pure returns (bytes memory) {\n        if (success) {\n            return returndata;\n        } else {\n            // Look for revert reason and bubble it up if present\n            if (returndata.length > 0) {\n                // The easiest way to bubble the revert reason is using memory via assembly\n\n                assembly {\n                    let returndata_size := mload(returndata)\n                    revert(add(32, returndata), returndata_size)\n                }\n            } else {\n                revert(errorMessage);\n            }\n        }\n    }\n}\n"
    },
    "contracts/base/WrappedERC721.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity ^0.8.15;\n\nimport \"@openzeppelin/contracts/security/ReentrancyGuard.sol\";\nimport \"@openzeppelin/contracts/utils/Strings.sol\";\n\nimport \"../base/ERC721Initializable.sol\";\nimport \"../interfaces/IWrappedERC721.sol\";\nimport \"../interfaces/ITokenURIRenderer.sol\";\nimport \"../interfaces/INFTGaugeFactory.sol\";\nimport \"../libraries/Signature.sol\";\nimport \"../libraries/Tokens.sol\";\nimport \"../libraries/Math.sol\";\n\nabstract contract WrappedERC721 is ERC721Initializable, ReentrancyGuard, IWrappedERC721 {\n    using Strings for uint256;\n\n    struct Order {\n        uint256 price;\n        address currency;\n        uint64 deadline;\n        bool auction;\n    }\n\n    struct Bid_ {\n        uint256 price;\n        address bidder;\n        uint64 timestamp;\n    }\n\n    address public override nftContract;\n    address public override tokenURIRenderer;\n    address public override factory;\n\n    mapping(uint256 => mapping(address => Order)) public override sales;\n    mapping(uint256 => mapping(address => Bid_)) public override currentBids;\n    mapping(uint256 => mapping(address => Order)) public override offers;\n\n    function __WrappedERC721_init(address _nftContract, address _tokenURIRenderer) internal initializer {\n        nftContract = _nftContract;\n        tokenURIRenderer = _tokenURIRenderer;\n        factory = msg.sender;\n\n        string memory name;\n        string memory symbol;\n        try IERC721Metadata(_nftContract).name() returns (string memory _name) {\n            name = _name;\n        } catch {\n            name = uint256(uint160(nftContract)).toHexString(20);\n        }\n        try IERC721Metadata(_nftContract).symbol() returns (string memory _symbol) {\n            symbol = string(abi.encodePacked(\"W\", _symbol));\n        } catch {\n            symbol = \"WNFT\";\n        }\n        __ERC721_init(string(abi.encodePacked(\"Wrapped \", name)), symbol);\n    }\n\n    function tokenURI(uint256 tokenId)\n        public\n        view\n        override(ERC721Initializable, IERC721Metadata)\n        returns (string memory output)\n    {\n        require(_exists(tokenId), \"WERC721: TOKEN_NON_EXISTENT\");\n\n        return ITokenURIRenderer(tokenURIRenderer).render(nftContract, tokenId);\n    }\n\n    function listForSale(\n        uint256 tokenId,\n        uint256 price,\n        address currency,\n        uint64 deadline,\n        bool auction\n    ) external override {\n        require(block.timestamp < deadline, \"WERC721: INVALID_DEADLINE\");\n        require(ownerOf(tokenId) == msg.sender, \"WERC721: FORBIDDEN\");\n        require(currency == address(0), \"WERC721: INVALID_CURRENCY\");\n\n        sales[tokenId][msg.sender] = Order(price, currency, deadline, auction);\n\n        emit ListForSale(tokenId, msg.sender, price, currency, deadline, auction);\n    }\n\n    function cancelListing(uint256 tokenId) external override {\n        require(ownerOf(tokenId) == msg.sender, \"WERC721: FORBIDDEN\");\n\n        delete sales[tokenId][msg.sender];\n        delete currentBids[tokenId][msg.sender];\n\n        emit CancelListing(tokenId, msg.sender);\n    }\n\n    function buyETH(uint256 tokenId, address owner) external payable override {\n        address currency = _buy(tokenId, owner, msg.value);\n        require(currency == address(0), \"WERC721: ETH_UNACCEPTABLE\");\n\n        _settle(tokenId, address(0), owner, msg.value);\n    }\n\n    function buy(\n        uint256 tokenId,\n        address owner,\n        uint256 price\n    ) external override nonReentrant {\n        address currency = _buy(tokenId, owner, price);\n        require(currency != address(0), \"WERC721: ONLY_ETH_ACCEPTABLE\");\n\n        INFTGaugeFactory(factory).executePayment(currency, msg.sender, price);\n\n        _settle(tokenId, currency, owner, price);\n    }\n\n    function _buy(\n        uint256 tokenId,\n        address owner,\n        uint256 price\n    ) internal returns (address currency) {\n        Order memory sale = sales[tokenId][owner];\n        require(sale.deadline > 0, \"WERC721: NOT_LISTED_FOR_SALE\");\n        require(block.timestamp <= sale.deadline, \"WERC721: EXPIRED\");\n        require(sale.price == price, \"WERC721: INVALID_PRICE\");\n        require(!sale.auction, \"WERC721: BID_REQUIRED\");\n\n        _safeTransfer(owner, msg.sender, tokenId, \"0x\");\n\n        currency = sale.currency;\n        emit Buy(tokenId, owner, msg.sender, price, currency);\n    }\n\n    function bidETH(uint256 tokenId, address owner) external payable override {\n        address currency = _bid(tokenId, owner, msg.value);\n        require(currency == address(0), \"WERC721: ETH_UNACCEPTABLE\");\n    }\n\n    function bid(\n        uint256 tokenId,\n        address owner,\n        uint256 price\n    ) external override nonReentrant {\n        address currency = _bid(tokenId, owner, price);\n        require(currency != address(0), \"WERC721: ONLY_ETH_ACCEPTABLE\");\n\n        INFTGaugeFactory(factory).executePayment(currency, msg.sender, price);\n    }\n\n    function _bid(\n        uint256 tokenId,\n        address owner,\n        uint256 price\n    ) internal returns (address currency) {\n        Order memory sale = sales[tokenId][owner];\n        uint256 deadline = sale.deadline;\n        require(deadline > 0, \"WERC721: NOT_LISTED_FOR_SALE\");\n        require(sale.auction, \"WERC721: NOT_BIDDABLE\");\n\n        currency = sale.currency;\n        Bid_ memory prevBid = currentBids[tokenId][owner];\n        if (prevBid.price == 0) {\n            require(price >= sale.price, \"WERC721: PRICE_TOO_LOW\");\n            require(block.timestamp <= deadline, \"WERC721: EXPIRED\");\n        } else {\n            require(price >= (prevBid.price * 110) / 100, \"WERC721: PRICE_TOO_LOW\");\n            require(block.timestamp <= Math.max(deadline, prevBid.timestamp + 10 minutes), \"WERC721: EXPIRED\");\n\n            Tokens.transfer(currency, prevBid.bidder, prevBid.price);\n        }\n        currentBids[tokenId][owner] = Bid_(price, msg.sender, uint64(block.timestamp));\n\n        emit Bid(tokenId, owner, msg.sender, price, currency);\n    }\n\n    function claim(uint256 tokenId, address owner) external override nonReentrant {\n        Order memory sale = sales[tokenId][owner];\n        require(sale.deadline > 0, \"WERC721: NOT_LISTED_FOR_SALE\");\n        require(sale.auction, \"WERC721: NOT_CLAIMABLE\");\n\n        Bid_ memory currentBid = currentBids[tokenId][owner];\n        require(currentBid.bidder == msg.sender, \"WERC721: FORBIDDEN\");\n        require(currentBid.timestamp + 10 minutes < block.timestamp, \"WERC721: BID_NOT_FINISHED\");\n\n        Tokens.transfer(owner, msg.sender, tokenId);\n\n        _settle(tokenId, sale.currency, owner, sale.price);\n\n        emit Claim(tokenId, owner, msg.sender, sale.price, sale.currency);\n    }\n\n    function makeOfferETH(uint256 tokenId, uint64 deadline) external payable override nonReentrant {\n        _makeOffer(tokenId, msg.value, address(0), deadline);\n    }\n\n    function makeOffer(\n        uint256 tokenId,\n        uint256 price,\n        address currency,\n        uint64 deadline\n    ) external override nonReentrant {\n        _makeOffer(tokenId, price, currency, deadline);\n\n        INFTGaugeFactory(factory).executePayment(currency, msg.sender, price);\n    }\n\n    function _makeOffer(\n        uint256 tokenId,\n        uint256 price,\n        address currency,\n        uint64 deadline\n    ) internal {\n        require(_exists(tokenId), \"WERC721: INVALID_TOKEN_ID\");\n        require(price > 0, \"WERC721: INVALID_PRICE\");\n        require(block.timestamp < uint256(deadline), \"WERC721: INVALID_DEADLINE\");\n\n        Order memory offer = offers[tokenId][msg.sender];\n        if (offer.deadline > 0) {\n            emit WithdrawOffer(tokenId, msg.sender);\n\n            Tokens.transfer(offer.currency, msg.sender, offer.price);\n        }\n\n        offers[tokenId][msg.sender] = Order(price, currency, deadline, false);\n\n        emit MakeOffer(tokenId, msg.sender, price, currency, uint256(deadline));\n    }\n\n    function withdrawOffer(uint256 tokenId) external override {\n        Order memory offer = offers[tokenId][msg.sender];\n        require(offer.deadline > 0, \"WERC721: INVALID_OFFER\");\n\n        delete offers[tokenId][msg.sender];\n\n        emit WithdrawOffer(tokenId, msg.sender);\n\n        Tokens.transfer(offer.currency, msg.sender, offer.price);\n    }\n\n    function acceptOffer(uint256 tokenId, address maker) external override nonReentrant {\n        require(ownerOf(tokenId) == msg.sender, \"WERC721: FORBIDDEN\");\n\n        Order memory offer = offers[tokenId][maker];\n        require(offer.deadline > 0, \"WERC721: INVALID_OFFER\");\n        require(block.timestamp <= offer.deadline, \"WERC721: EXPIRED\");\n\n        delete offers[tokenId][maker];\n        _safeTransfer(msg.sender, maker, tokenId, \"0x\");\n\n        _settle(tokenId, offer.currency, msg.sender, offer.price);\n\n        emit AcceptOffer(tokenId, maker, msg.sender, offer.price, offer.currency, offer.deadline);\n    }\n\n    function _settle(\n        uint256 tokenId,\n        address currency,\n        address to,\n        uint256 amount\n    ) internal virtual;\n\n    function _beforeTokenTransfer(\n        address from,\n        address,\n        uint256 tokenId\n    ) internal virtual override {\n        if (from != address(0)) {\n            delete sales[tokenId][from];\n            delete currentBids[tokenId][from];\n        }\n    }\n}\n"
    },
    "contracts/interfaces/INFTGauge.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity ^0.8.0;\n\nimport \"./IWrappedERC721.sol\";\nimport \"./IGauge.sol\";\n\ninterface INFTGauge is IWrappedERC721, IGauge {\n    event Wrap(uint256 indexed tokenId, address indexed to);\n    event Unwrap(uint256 indexed tokenId, address indexed to);\n    event Vote(uint256 indexed tokenId, address indexed user, uint256 weight);\n    event DistributeDividend(address indexed token, uint256 indexed tokenId, uint256 amount);\n    event ClaimDividends(address indexed token, uint256 indexed tokenId, uint256 amount, address indexed to);\n\n    function initialize(\n        address _nftContract,\n        address _tokenURIRenderer,\n        address _minter\n    ) external;\n\n    function controller() external view returns (address);\n\n    function minter() external view returns (address);\n\n    function votingEscrow() external view returns (address);\n\n    function futureEpochTime() external view returns (uint256);\n\n    function dividendRatios(uint256 tokenId) external view returns (uint256);\n\n    function dividends(\n        address token,\n        uint256 tokenId,\n        uint256 id\n    ) external view returns (uint64 blockNumber, uint192 amountPerShare);\n\n    function lastDividendClaimed(\n        address token,\n        uint256 tokenId,\n        address user\n    ) external view returns (uint256);\n\n    function integrateCheckpoint() external view returns (uint256);\n\n    function period() external view returns (int128);\n\n    function periodTimestamp(int128 period) external view returns (uint256);\n\n    function integrateInvSupply(int128 period) external view returns (uint256);\n\n    function periodOf(uint256 tokenId, address user) external view returns (int128);\n\n    function integrateFraction(uint256 tokenId, address user) external view returns (uint256);\n\n    function inflationRate() external view returns (uint256);\n\n    function isKilled() external view returns (bool);\n\n    function userWeight(address user, uint256 tokenId) external view returns (uint256);\n\n    function userWeightSum(address user) external view returns (uint256);\n\n    function points(uint256 tokenId, address user) external view returns (uint256);\n\n    function pointsAt(\n        uint256 tokenId,\n        address user,\n        uint256 _block\n    ) external view returns (uint256);\n\n    function pointsSum(uint256 tokenId) external view returns (uint256);\n\n    function pointsSumAt(uint256 tokenId, uint256 _block) external view returns (uint256);\n\n    function pointsTotal() external view returns (uint256);\n\n    function pointsTotalAt(uint256 _block) external view returns (uint256);\n\n    function dividendsLength(address token, uint256 tokenId) external view returns (uint256);\n\n    function userCheckpoint(uint256 tokenId, address user) external;\n\n    function wrap(\n        uint256 tokenId,\n        uint256 ratio,\n        address to,\n        uint256 _userWeight\n    ) external;\n\n    function unwrap(uint256 tokenId, address to) external;\n\n    function vote(uint256 tokenId, uint256 _userWeight) external;\n\n    function claimDividends(address token, uint256 tokenId) external;\n}\n"
    },
    "contracts/interfaces/IGaugeController.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity ^0.8.0;\n\ninterface IGaugeController {\n    event AddType(string name, int128 gaugeType);\n    event NewTypeWeight(int128 gaugeType, uint256 time, uint256 weight, uint256 totalWeight);\n    event NewGaugeWeight(address addr, uint256 time, uint256 weight, uint256 totalWeight);\n    event VoteForGauge(uint256 time, address user, address addr, uint256 weight);\n    event NewGauge(address addr, int128 gaugeType, uint256 weight);\n\n    function interval() external view returns (uint256);\n\n    function weightVoteDelay() external view returns (uint256);\n\n    function votingEscrow() external view returns (address);\n\n    function gaugeTypesLength() external view returns (int128);\n\n    function gaugesLength() external view returns (int128);\n\n    function gaugeTypeNames(int128 gaugeType) external view returns (string memory);\n\n    function gauges(int128 gaugeType) external view returns (address);\n\n    function voteUserSlopes(address user, address addr)\n        external\n        view\n        returns (\n            uint256 slope,\n            uint256 power,\n            uint256 end\n        );\n\n    function voteUserPower(address user) external view returns (uint256 totalVotePower);\n\n    function lastUserVote(address user, address addr) external view returns (uint256 time);\n\n    function pointsWeight(address addr, uint256 time) external view returns (uint256 bias, uint256 slope);\n\n    function timeWeight(address addr) external view returns (uint256 lastScheduledTime);\n\n    function pointsSum(int128 gaugeType, uint256 time) external view returns (uint256 bias, uint256 slope);\n\n    function timeSum(int128 gaugeType) external view returns (uint256 lastScheduledTime);\n\n    function pointsTotal(uint256 time) external view returns (uint256 totalWeight);\n\n    function timeTotal() external view returns (uint256 lastScheduledTime);\n\n    function pointsTypeWeight(int128 gaugeType, uint256 time) external view returns (uint256 typeWeight);\n\n    function timeTypeWeight(int128 gaugeType) external view returns (uint256 lastScheduledTime);\n\n    function gaugeTypes(address addr) external view returns (int128);\n\n    function getGaugeWeight(address addr) external view returns (uint256);\n\n    function getTypeWeight(int128 gaugeType) external view returns (uint256);\n\n    function getTotalWeight() external view returns (uint256);\n\n    function getWeightsSumPerType(int128 gaugeType) external view returns (uint256);\n\n    function gaugeRelativeWeight(address addr) external view returns (uint256);\n\n    function gaugeRelativeWeight(address addr, uint256 time) external view returns (uint256);\n\n    function addType(string calldata name) external;\n\n    function addType(string calldata name, uint256 weight) external;\n\n    function changeTypeWeight(int128 gaugeType, uint256 weight) external;\n\n    function addGauge(address addr, int128 gaugeType) external;\n\n    function addGauge(\n        address addr,\n        int128 gaugeType,\n        uint256 weight\n    ) external;\n\n    function increaseGaugeWeight(uint256 weight) external;\n\n    function killGauge(address addr) external;\n\n    function checkpoint() external;\n\n    function checkpointGauge(address addr) external;\n\n    function gaugeRelativeWeightWrite(address addr) external returns (uint256);\n\n    function gaugeRelativeWeightWrite(address addr, uint256 time) external returns (uint256);\n\n    function voteForGaugeWeights(address user, uint256 userWeight) external;\n}\n"
    },
    "contracts/interfaces/IMinter.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity ^0.8.0;\n\ninterface IMinter {\n    event UpdateMiningParameters(uint256 time, uint256 rate, uint256 supply);\n    event Minted(address indexed recipient, address indexed gaugeAddr, uint256 indexed tokenId, uint256 minted);\n\n    function token() external view returns (address);\n\n    function controller() external view returns (address);\n\n    function initialSupply() external view returns (uint256);\n\n    function initialRate() external view returns (uint256);\n\n    function rateReductionTime() external view returns (uint256);\n\n    function rateReductionCoefficient() external view returns (uint256);\n\n    function miningEpoch() external view returns (int128);\n\n    function startEpochTime() external view returns (uint256);\n\n    function rate() external view returns (uint256);\n\n    function availableSupply() external view returns (uint256);\n\n    function mintableInTimeframe(uint256 start, uint256 end) external view returns (uint256);\n\n    function minted(\n        address gaugeAddr,\n        uint256 tokenId,\n        address user\n    ) external view returns (uint256);\n\n    function updateMiningParameters() external;\n\n    function startEpochTimeWrite() external returns (uint256);\n\n    function futureEpochTimeWrite() external returns (uint256);\n\n    function mint(address gaugeAddr, uint256 tokenId) external;\n}\n"
    },
    "contracts/interfaces/IVotingEscrow.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity ^0.8.0;\n\ninterface IVotingEscrow {\n    event SetMigrator(address indexed account);\n    event SetDelegate(address indexed account, bool isDelegate);\n    event Deposit(\n        address indexed provider,\n        uint256 value,\n        uint256 discount,\n        uint256 indexed unlockTime,\n        int128 indexed _type,\n        uint256 ts\n    );\n    event Cancel(address indexed provider, uint256 value, uint256 discount, uint256 penaltyRate, uint256 ts);\n    event Withdraw(address indexed provider, uint256 value, uint256 discount, uint256 ts);\n    event Migrate(address indexed provider, uint256 value, uint256 discount, uint256 ts);\n    event Supply(uint256 prevSupply, uint256 supply);\n\n    function interval() external view returns (uint256);\n\n    function maxDuration() external view returns (uint256);\n\n    function token() external view returns (address);\n\n    function name() external view returns (string memory);\n\n    function symbol() external view returns (string memory);\n\n    function decimals() external view returns (uint8);\n\n    function migrator() external view returns (address);\n\n    function isDelegate(address account) external view returns (bool);\n\n    function supply() external view returns (uint256);\n\n    function migrated(address account) external view returns (bool);\n\n    function delegateAt(address account, uint256 index) external view returns (address);\n\n    function locked(address account)\n        external\n        view\n        returns (\n            int128 amount,\n            int128 discount,\n            uint256 start,\n            uint256 end\n        );\n\n    function epoch() external view returns (uint256);\n\n    function pointHistory(uint256 epoch)\n        external\n        view\n        returns (\n            int128 bias,\n            int128 slope,\n            uint256 ts,\n            uint256 blk\n        );\n\n    function userPointHistory(address account, uint256 epoch)\n        external\n        view\n        returns (\n            int128 bias,\n            int128 slope,\n            uint256 ts,\n            uint256 blk\n        );\n\n    function userPointEpoch(address account) external view returns (uint256);\n\n    function slopeChanges(uint256 epoch) external view returns (int128);\n\n    function delegateLength(address addr) external view returns (uint256);\n\n    function getLastUserSlope(address addr) external view returns (int128);\n\n    function getCheckpointTime(address _addr, uint256 _idx) external view returns (uint256);\n\n    function unlockTime(address _addr) external view returns (uint256);\n\n    function setMigrator(address _migrator) external;\n\n    function setDelegate(address account, bool _isDelegate) external;\n\n    function checkpoint() external;\n\n    function depositFor(address _addr, uint256 _value) external;\n\n    function createLockFor(\n        address _addr,\n        uint256 _value,\n        uint256 _discount,\n        uint256 _duration\n    ) external;\n\n    function createLock(uint256 _value, uint256 _duration) external;\n\n    function increaseAmountFor(\n        address _addr,\n        uint256 _value,\n        uint256 _discount\n    ) external;\n\n    function increaseAmount(uint256 _value) external;\n\n    function increaseUnlockTime(uint256 _duration) external;\n\n    function cancel() external;\n\n    function withdraw() external;\n\n    function migrate() external;\n\n    function balanceOf(address addr) external view returns (uint256);\n\n    function balanceOf(address addr, uint256 _t) external view returns (uint256);\n\n    function balanceOfAt(address addr, uint256 _block) external view returns (uint256);\n\n    function totalSupply() external view returns (uint256);\n\n    function totalSupply(uint256 t) external view returns (uint256);\n\n    function totalSupplyAt(uint256 _block) external view returns (uint256);\n}\n"
    },
    "contracts/interfaces/ICurrencyConverter.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity ^0.8.0;\n\ninterface ICurrencyConverter {\n    function getAmountETH(uint256 amount) external view returns (uint256);\n}\n"
    },
    "contracts/libraries/Math.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity ^0.8.15;\n\nlibrary Math {\n    function max(uint256 a, uint256 b) internal pure returns (uint256) {\n        if (a > b) return a;\n        return b;\n    }\n\n    function min(uint256 a, uint256 b) internal pure returns (uint256) {\n        if (a < b) return a;\n        return b;\n    }\n}\n"
    },
    "contracts/libraries/NFTs.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity ^0.8.15;\n\nimport \"@openzeppelin/contracts/token/ERC721/IERC721.sol\";\nimport \"../interfaces/ICryptoPunksMarket.sol\";\n\nlibrary NFTs {\n    address constant CRYPTOPUNKS = 0xb47e3cd837dDF8e4c57F05d70Ab865de6e193BBB;\n\n    function ownerOf(address token, uint256 tokenId) internal view returns (address) {\n        if (token == CRYPTOPUNKS) {\n            return ICryptoPunksMarket(token).punkIndexToAddress(tokenId);\n        } else {\n            return IERC721(token).ownerOf(tokenId);\n        }\n    }\n\n    function safeTransferFrom(\n        address token,\n        address from,\n        address to,\n        uint256 tokenId\n    ) internal {\n        if (token == CRYPTOPUNKS) {\n            // ICryptoPunksMarket.offerPunkForSaleToAddress() should have been called by the owner prior to this call\n            ICryptoPunksMarket(token).buyPunk(tokenId);\n            if (to != address(this)) {\n                ICryptoPunksMarket(token).transferPunk(to, tokenId);\n            }\n        } else {\n            IERC721(token).safeTransferFrom(from, to, tokenId);\n        }\n    }\n}\n"
    },
    "@openzeppelin/contracts/security/ReentrancyGuard.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Contract module that helps prevent reentrant calls to a function.\n *\n * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier\n * available, which can be applied to functions to make sure there are no nested\n * (reentrant) calls to them.\n *\n * Note that because there is a single `nonReentrant` guard, functions marked as\n * `nonReentrant` may not call one another. This can be worked around by making\n * those functions `private`, and then adding `external` `nonReentrant` entry\n * points to them.\n *\n * TIP: If you would like to learn more about reentrancy and alternative ways\n * to protect against it, check out our blog post\n * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].\n */\nabstract contract ReentrancyGuard {\n    // Booleans are more expensive than uint256 or any type that takes up a full\n    // word because each write operation emits an extra SLOAD to first read the\n    // slot's contents, replace the bits taken up by the boolean, and then write\n    // back. This is the compiler's defense against contract upgrades and\n    // pointer aliasing, and it cannot be disabled.\n\n    // The values being non-zero value makes deployment a bit more expensive,\n    // but in exchange the refund on every call to nonReentrant will be lower in\n    // amount. Since refunds are capped to a percentage of the total\n    // transaction's gas, it is best to keep them low in cases like this one, to\n    // increase the likelihood of the full refund coming into effect.\n    uint256 private constant _NOT_ENTERED = 1;\n    uint256 private constant _ENTERED = 2;\n\n    uint256 private _status;\n\n    constructor() {\n        _status = _NOT_ENTERED;\n    }\n\n    /**\n     * @dev Prevents a contract from calling itself, directly or indirectly.\n     * Calling a `nonReentrant` function from another `nonReentrant`\n     * function is not supported. It is possible to prevent this from happening\n     * by making the `nonReentrant` function external, and making it call a\n     * `private` function that does the actual work.\n     */\n    modifier nonReentrant() {\n        // On the first call to nonReentrant, _notEntered will be true\n        require(_status != _ENTERED, \"ReentrancyGuard: reentrant call\");\n\n        // Any calls to nonReentrant after this point will fail\n        _status = _ENTERED;\n\n        _;\n\n        // By storing the original value once again, a refund is triggered (see\n        // https://eips.ethereum.org/EIPS/eip-2200)\n        _status = _NOT_ENTERED;\n    }\n}\n"
    },
    "@openzeppelin/contracts/utils/Strings.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Strings.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev String operations.\n */\nlibrary Strings {\n    bytes16 private constant _HEX_SYMBOLS = \"0123456789abcdef\";\n\n    /**\n     * @dev Converts a `uint256` to its ASCII `string` decimal representation.\n     */\n    function toString(uint256 value) internal pure returns (string memory) {\n        // Inspired by OraclizeAPI's implementation - MIT licence\n        // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol\n\n        if (value == 0) {\n            return \"0\";\n        }\n        uint256 temp = value;\n        uint256 digits;\n        while (temp != 0) {\n            digits++;\n            temp /= 10;\n        }\n        bytes memory buffer = new bytes(digits);\n        while (value != 0) {\n            digits -= 1;\n            buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));\n            value /= 10;\n        }\n        return string(buffer);\n    }\n\n    /**\n     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.\n     */\n    function toHexString(uint256 value) internal pure returns (string memory) {\n        if (value == 0) {\n            return \"0x00\";\n        }\n        uint256 temp = value;\n        uint256 length = 0;\n        while (temp != 0) {\n            length++;\n            temp >>= 8;\n        }\n        return toHexString(value, length);\n    }\n\n    /**\n     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.\n     */\n    function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {\n        bytes memory buffer = new bytes(2 * length + 2);\n        buffer[0] = \"0\";\n        buffer[1] = \"x\";\n        for (uint256 i = 2 * length + 1; i > 1; --i) {\n            buffer[i] = _HEX_SYMBOLS[value & 0xf];\n            value >>= 4;\n        }\n        require(value == 0, \"Strings: hex length insufficient\");\n        return string(buffer);\n    }\n}\n"
    },
    "contracts/base/ERC721Initializable.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED\n\npragma solidity ^0.8.15;\n\nimport \"@openzeppelin/contracts/proxy/utils/Initializable.sol\";\nimport \"@openzeppelin/contracts/utils/introspection/ERC165.sol\";\nimport \"@openzeppelin/contracts/token/ERC721/IERC721.sol\";\nimport \"@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol\";\nimport \"@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol\";\nimport \"@openzeppelin/contracts/utils/Address.sol\";\nimport \"@openzeppelin/contracts/utils/Strings.sol\";\n\n/**\n * @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including\n * the Metadata extension, but not including the Enumerable extension, which is available separately as\n * {ERC721Enumerable}.\n */\nabstract contract ERC721Initializable is Initializable, ERC165, IERC721, IERC721Metadata {\n    using Address for address;\n    using Strings for uint256;\n\n    // Token name\n    string private _name;\n\n    // Token symbol\n    string private _symbol;\n\n    // Upper bound of tokenId parked\n    uint256 private _toTokenIdParked;\n\n    // Mapping from token ID to owner address\n    mapping(uint256 => address) private _owners;\n\n    // Mapping owner address to token count\n    mapping(address => uint256) private _balances;\n\n    // Mapping from token ID to approved address\n    mapping(uint256 => address) private _tokenApprovals;\n\n    // Mapping from owner to operator approvals\n    mapping(address => mapping(address => bool)) private _operatorApprovals;\n\n    /**\n     * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.\n     */\n    function __ERC721_init(string memory name_, string memory symbol_) internal initializer {\n        __ERC721_init_unchained(name_, symbol_);\n    }\n\n    function __ERC721_init_unchained(string memory name_, string memory symbol_) internal initializer {\n        _name = name_;\n        _symbol = symbol_;\n    }\n\n    /**\n     * @dev See {IERC165-supportsInterface}.\n     */\n    function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {\n        return\n            interfaceId == type(IERC721).interfaceId ||\n            interfaceId == type(IERC721Metadata).interfaceId ||\n            super.supportsInterface(interfaceId);\n    }\n\n    /**\n     * @dev See {IERC721-balanceOf}.\n     */\n    function balanceOf(address owner) public view virtual override returns (uint256) {\n        require(owner != address(0), \"ERC721: INVALID_OWNER\");\n        return _balances[owner];\n    }\n\n    /**\n     * @dev See {IERC721-ownerOf}.\n     */\n    function ownerOf(uint256 tokenId) public view virtual override returns (address) {\n        return _owners[tokenId];\n    }\n\n    /**\n     * @dev See {IERC721Metadata-name}.\n     */\n    function name() public view virtual override returns (string memory) {\n        return _name;\n    }\n\n    /**\n     * @dev See {IERC721Metadata-symbol}.\n     */\n    function symbol() public view virtual override returns (string memory) {\n        return _symbol;\n    }\n\n    /**\n     * @dev See {IERC721Metadata-tokenURI}.\n     */\n    function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {\n        require(_exists(tokenId), \"ERC721: INVALID_TOKEN_ID\");\n\n        string memory baseURI = _baseURI();\n        return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : \"\";\n    }\n\n    /**\n     * @dev Base URI for computing {tokenURI}. Empty by default, can be overriden\n     * in child contracts.\n     */\n    function _baseURI() internal view virtual returns (string memory) {\n        return \"\";\n    }\n\n    /**\n     * @dev See {IERC721-approve}.\n     */\n    function approve(address to, uint256 tokenId) public virtual override {\n        address owner = ERC721Initializable.ownerOf(tokenId);\n        require(to != owner, \"ERC721: INVALID_TO\");\n\n        require(msg.sender == owner || isApprovedForAll(owner, msg.sender), \"ERC721: FORBIDDEN\");\n\n        _approve(to, tokenId);\n    }\n\n    /**\n     * @dev See {IERC721-getApproved}.\n     */\n    function getApproved(uint256 tokenId) public view virtual override returns (address) {\n        require(_exists(tokenId), \"ERC721: INVALID_TOKEN_ID\");\n\n        return _tokenApprovals[tokenId];\n    }\n\n    /**\n     * @dev See {IERC721-setApprovalForAll}.\n     */\n    function setApprovalForAll(address operator, bool approved) public virtual override {\n        _setApprovalForAll(msg.sender, operator, approved);\n    }\n\n    /**\n     * @dev See {IERC721-isApprovedForAll}.\n     */\n    function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {\n        return _operatorApprovals[owner][operator];\n    }\n\n    /**\n     * @dev See {IERC721-transferFrom}.\n     */\n    function transferFrom(\n        address from,\n        address to,\n        uint256 tokenId\n    ) public virtual override {\n        //solhint-disable-next-line max-line-length\n        require(_isApprovedOrOwner(msg.sender, tokenId), \"ERC721: NOT_APPROVED_NOR_OWNER\");\n\n        _transfer(from, to, tokenId);\n    }\n\n    /**\n     * @dev See {IERC721-safeTransferFrom}.\n     */\n    function safeTransferFrom(\n        address from,\n        address to,\n        uint256 tokenId\n    ) public virtual override {\n        safeTransferFrom(from, to, tokenId, \"\");\n    }\n\n    /**\n     * @dev See {IERC721-safeTransferFrom}.\n     */\n    function safeTransferFrom(\n        address from,\n        address to,\n        uint256 tokenId,\n        bytes memory _data\n    ) public virtual override {\n        require(_isApprovedOrOwner(msg.sender, tokenId), \"ERC721: FORBIDDEN\");\n        _safeTransfer(from, to, tokenId, _data);\n    }\n\n    /**\n     * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients\n     * are aware of the ERC721 protocol to prevent tokens from being forever locked.\n     *\n     * `_data` is additional data, it has no specified format and it is sent in call to `to`.\n     *\n     * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.\n     * implement alternative mechanisms to perform token transfer, such as signature-based.\n     *\n     * Requirements:\n     *\n     * - `from` cannot be the zero address.\n     * - `to` cannot be the zero address.\n     * - `tokenId` token must exist and be owned by `from`.\n     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.\n     *\n     * Emits a {Transfer} event.\n     */\n    function _safeTransfer(\n        address from,\n        address to,\n        uint256 tokenId,\n        bytes memory _data\n    ) internal virtual {\n        _transfer(from, to, tokenId);\n        require(_checkOnERC721Received(from, to, tokenId, _data), \"ERC721: INVALID_RECEIVER\");\n    }\n\n    /**\n     * @dev Returns whether `tokenId` exists.\n     *\n     * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.\n     *\n     * Tokens start existing when they are minted (`_mint`),\n     * and stop existing when they are burned (`_burn`).\n     */\n    function _exists(uint256 tokenId) internal view virtual returns (bool) {\n        return _owners[tokenId] != address(0);\n    }\n\n    /**\n     * @dev Returns whether `spender` is allowed to manage `tokenId`.\n     *\n     * Requirements:\n     *\n     * - `tokenId` must exist.\n     */\n    function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {\n        require(_exists(tokenId), \"ERC721: INVALID_TOKEN_ID\");\n        address owner = ERC721Initializable.ownerOf(tokenId);\n        return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender));\n    }\n\n    function _setApprovalForAll(\n        address owner,\n        address operator,\n        bool approved\n    ) internal {\n        require(operator != owner, \"ERC721: INVALID_OPERATOR\");\n\n        _operatorApprovals[owner][operator] = approved;\n        emit ApprovalForAll(owner, operator, approved);\n    }\n\n    function _parked(uint256 tokenId) internal view virtual returns (bool) {\n        address owner = ERC721Initializable.ownerOf(tokenId);\n        return owner == address(0) && tokenId < _toTokenIdParked;\n    }\n\n    function _parkTokenIds(uint256 toTokenId) internal virtual {\n        uint256 fromTokenId = _toTokenIdParked;\n        require(toTokenId > fromTokenId, \"ERC721: INVALID_TO_TOKEN_ID\");\n\n        _toTokenIdParked = toTokenId;\n    }\n\n    /**\n     * @dev Safely mints `tokenId` and transfers it to `to`.\n     *\n     * Requirements:\n     *\n     * - `tokenId` must not exist.\n     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.\n     *\n     * Emits a {Transfer} event.\n     */\n    function _safeMint(address to, uint256 tokenId) internal virtual {\n        _safeMint(to, tokenId, \"\");\n    }\n\n    /**\n     * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is\n     * forwarded in {IERC721Receiver-onERC721Received} to contract recipients.\n     */\n    function _safeMint(\n        address to,\n        uint256 tokenId,\n        bytes memory _data\n    ) internal virtual {\n        _mint(to, tokenId);\n        require(_checkOnERC721Received(address(0), to, tokenId, _data), \"ERC721: INVALID_RECEIVER\");\n    }\n\n    /**\n     * @dev Mints `tokenId` and transfers it to `to`.\n     *\n     * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible\n     *\n     * Requirements:\n     *\n     * - `tokenId` must not exist.\n     * - `to` cannot be the zero address.\n     *\n     * Emits a {Transfer} event.\n     */\n    function _mint(address to, uint256 tokenId) internal virtual {\n        require(to != address(0), \"ERC721: INVALID_TO\");\n        require(!_exists(tokenId), \"ERC721: ALREADY_MINTED\");\n\n        _beforeTokenTransfer(address(0), to, tokenId);\n\n        _balances[to] += 1;\n        _owners[tokenId] = to;\n\n        emit Transfer(address(0), to, tokenId);\n    }\n\n    /**\n     * @dev Destroys `tokenId`.\n     * The approval is cleared when the token is burned.\n     *\n     * Requirements:\n     *\n     * - `tokenId` must exist.\n     *\n     * Emits a {Transfer} event.\n     */\n    function _burn(uint256 tokenId) internal virtual {\n        address owner = ERC721Initializable.ownerOf(tokenId);\n        require(owner != address(0), \"ERC721: INVALID_TOKEN_ID\");\n\n        _beforeTokenTransfer(owner, address(0), tokenId);\n\n        // Clear approvals\n        _approve(address(0), tokenId);\n\n        _balances[owner] -= 1;\n        delete _owners[tokenId];\n\n        emit Transfer(owner, address(0), tokenId);\n    }\n\n    /**\n     * @dev Transfers `tokenId` from `from` to `to`.\n     *  As opposed to {transferFrom}, this imposes no restrictions on msg.sender.\n     *\n     * Requirements:\n     *\n     * - `to` cannot be the zero address.\n     * - `tokenId` token must be owned by `from`.\n     *\n     * Emits a {Transfer} event.\n     */\n    function _transfer(\n        address from,\n        address to,\n        uint256 tokenId\n    ) internal virtual {\n        require(ERC721Initializable.ownerOf(tokenId) == from, \"ERC721: TRANSFER_FORBIDDEN\");\n        require(to != address(0), \"ERC721: INVALID_RECIPIENT\");\n\n        _beforeTokenTransfer(from, to, tokenId);\n\n        // Clear approvals from the previous owner\n        _approve(address(0), tokenId);\n\n        _balances[from] -= 1;\n        _balances[to] += 1;\n        _owners[tokenId] = to;\n\n        emit Transfer(from, to, tokenId);\n    }\n\n    /**\n     * @dev Approve `to` to operate on `tokenId`\n     *\n     * Emits a {Approval} event.\n     */\n    function _approve(address to, uint256 tokenId) internal virtual {\n        _tokenApprovals[tokenId] = to;\n        emit Approval(ERC721Initializable.ownerOf(tokenId), to, tokenId);\n    }\n\n    /**\n     * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.\n     * The call is not executed if the target address is not a contract.\n     *\n     * @param from address representing the previous owner of the given token ID\n     * @param to target address that will receive the tokens\n     * @param tokenId uint256 ID of the token to be transferred\n     * @param _data bytes optional data to send along with the call\n     * @return bool whether the call correctly returned the expected magic value\n     */\n    function _checkOnERC721Received(\n        address from,\n        address to,\n        uint256 tokenId,\n        bytes memory _data\n    ) private returns (bool) {\n        if (to.isContract()) {\n            try IERC721Receiver(to).onERC721Received(msg.sender, from, tokenId, _data) returns (bytes4 retval) {\n                return retval == IERC721Receiver(to).onERC721Received.selector;\n            } catch (bytes memory reason) {\n                if (reason.length == 0) {\n                    revert(\"ERC721: INVALID_RECEIVER\");\n                } else {\n                    // solhint-disable-next-line no-inline-assembly\n                    assembly {\n                        revert(add(32, reason), mload(reason))\n                    }\n                }\n            }\n        } else {\n            return true;\n        }\n    }\n\n    /**\n     * @dev Hook that is called before any token transfer. This includes minting\n     * and burning.\n     *\n     * Calling conditions:\n     *\n     * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be\n     * transferred to `to`.\n     * - When `from` is zero, `tokenId` will be minted for `to`.\n     * - When `to` is zero, ``from``'s `tokenId` will be burned.\n     * - `from` cannot be the zero address.\n     * - `to` cannot be the zero address.\n     *\n     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\n     */\n    function _beforeTokenTransfer(\n        address from,\n        address to,\n        uint256 tokenId\n    ) internal virtual {}\n}\n"
    },
    "contracts/interfaces/IWrappedERC721.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity ^0.8.0;\n\nimport \"@openzeppelin/contracts/utils/introspection/IERC165.sol\";\nimport \"@openzeppelin/contracts/token/ERC721/IERC721.sol\";\nimport \"@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol\";\n\ninterface IWrappedERC721 is IERC165, IERC721, IERC721Metadata {\n    function nftContract() external view returns (address);\n\n    function tokenURIRenderer() external view returns (address);\n\n    function factory() external view returns (address);\n\n    function sales(uint256 tokenId, address owner)\n        external\n        view\n        returns (\n            uint256 price,\n            address currency,\n            uint64 deadline,\n            bool auction\n        );\n\n    function currentBids(uint256 tokenId, address owner)\n        external\n        view\n        returns (\n            uint256 price,\n            address bidder,\n            uint64 timestamp\n        );\n\n    function offers(uint256 tokenId, address maker)\n        external\n        view\n        returns (\n            uint256 price,\n            address currency,\n            uint64 deadline,\n            bool auction\n        );\n\n    function listForSale(\n        uint256 tokenId,\n        uint256 price,\n        address currency,\n        uint64 deadline,\n        bool auction\n    ) external;\n\n    function cancelListing(uint256 tokenId) external;\n\n    function buyETH(uint256 tokenId, address owner) external payable;\n\n    function buy(\n        uint256 tokenId,\n        address owner,\n        uint256 price\n    ) external;\n\n    function bidETH(uint256 tokenId, address owner) external payable;\n\n    function bid(\n        uint256 tokenId,\n        address owner,\n        uint256 price\n    ) external;\n\n    function claim(uint256 tokenId, address owner) external;\n\n    function makeOfferETH(uint256 tokenId, uint64 deadline) external payable;\n\n    function makeOffer(\n        uint256 tokenId,\n        uint256 price,\n        address currency,\n        uint64 deadline\n    ) external;\n\n    function withdrawOffer(uint256 tokenId) external;\n\n    function acceptOffer(uint256 tokenId, address maker) external;\n\n    event ListForSale(\n        uint256 indexed tokenId,\n        address indexed owner,\n        uint256 price,\n        address currency,\n        uint64 deadline,\n        bool indexed auction\n    );\n    event CancelListing(uint256 indexed tokenId, address indexed owner);\n    event MakeOffer(uint256 indexed tokenId, address indexed maker, uint256 price, address currency, uint256 deadline);\n    event WithdrawOffer(uint256 indexed tokenId, address indexed maker);\n    event AcceptOffer(\n        uint256 indexed tokenId,\n        address indexed maker,\n        address indexed taker,\n        uint256 price,\n        address currency,\n        uint256 deadline\n    );\n    event Buy(uint256 indexed tokenId, address indexed owner, address indexed bidder, uint256 price, address currency);\n    event Bid(uint256 indexed tokenId, address indexed owner, address indexed bidder, uint256 price, address currency);\n    event Claim(\n        uint256 indexed tokenId,\n        address indexed owner,\n        address indexed bidder,\n        uint256 price,\n        address currency\n    );\n}\n"
    },
    "contracts/interfaces/ITokenURIRenderer.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity ^0.8.0;\n\ninterface ITokenURIRenderer {\n    function render(address nftContract, uint256 tokenId) external view returns (string memory output);\n}\n"
    },
    "contracts/libraries/Signature.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity ^0.8.15;\n\nimport \"@openzeppelin/contracts/interfaces/IERC1271.sol\";\nimport \"@openzeppelin/contracts/utils/Address.sol\";\n\nlibrary Signature {\n    function recover(\n        bytes32 hash,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    ) internal pure returns (address) {\n        // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature\n        // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines\n        // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most\n        // signatures from current libraries generate a unique signature with an s-value in the lower half order.\n        //\n        // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value\n        // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or\n        // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept\n        // these malleable signatures as well.\n        require(\n            uint256(s) <= 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0,\n            \"LEVX: INVALID_SIGNATURE_S_VALUE\"\n        );\n        require(v == 27 || v == 28, \"LEVX: INVALID_SIGNATURE_V_VALUE\");\n\n        // If the signature is valid (and not malleable), return the signer address\n        address signer = ecrecover(hash, v, r, s);\n        require(signer != address(0), \"LEVX: INVALID_SIGNATURE\");\n\n        return signer;\n    }\n\n    function verify(\n        bytes32 hash,\n        address signer,\n        uint8 v,\n        bytes32 r,\n        bytes32 s,\n        bytes32 domainSeparator\n    ) internal view {\n        bytes32 digest = keccak256(abi.encodePacked(\"\\x19\\x01\", domainSeparator, hash));\n        if (Address.isContract(signer)) {\n            require(\n                IERC1271(signer).isValidSignature(digest, abi.encodePacked(r, s, v)) == 0x1626ba7e,\n                \"LEVX: UNAUTHORIZED\"\n            );\n        } else {\n            require(recover(digest, v, r, s) == signer, \"LEVX: UNAUTHORIZED\");\n        }\n    }\n}\n"
    },
    "@openzeppelin/contracts/proxy/utils/Initializable.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.6.0) (proxy/utils/Initializable.sol)\n\npragma solidity ^0.8.2;\n\nimport \"../../utils/Address.sol\";\n\n/**\n * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed\n * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an\n * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer\n * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.\n *\n * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be\n * reused. This mechanism prevents re-execution of each \"step\" but allows the creation of new initialization steps in\n * case an upgrade adds a module that needs to be initialized.\n *\n * For example:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * contract MyToken is ERC20Upgradeable {\n *     function initialize() initializer public {\n *         __ERC20_init(\"MyToken\", \"MTK\");\n *     }\n * }\n * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {\n *     function initializeV2() reinitializer(2) public {\n *         __ERC20Permit_init(\"MyToken\");\n *     }\n * }\n * ```\n *\n * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as\n * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.\n *\n * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure\n * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.\n *\n * [CAUTION]\n * ====\n * Avoid leaving a contract uninitialized.\n *\n * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation\n * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke\n * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * /// @custom:oz-upgrades-unsafe-allow constructor\n * constructor() {\n *     _disableInitializers();\n * }\n * ```\n * ====\n */\nabstract contract Initializable {\n    /**\n     * @dev Indicates that the contract has been initialized.\n     * @custom:oz-retyped-from bool\n     */\n    uint8 private _initialized;\n\n    /**\n     * @dev Indicates that the contract is in the process of being initialized.\n     */\n    bool private _initializing;\n\n    /**\n     * @dev Triggered when the contract has been initialized or reinitialized.\n     */\n    event Initialized(uint8 version);\n\n    /**\n     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,\n     * `onlyInitializing` functions can be used to initialize parent contracts. Equivalent to `reinitializer(1)`.\n     */\n    modifier initializer() {\n        bool isTopLevelCall = _setInitializedVersion(1);\n        if (isTopLevelCall) {\n            _initializing = true;\n        }\n        _;\n        if (isTopLevelCall) {\n            _initializing = false;\n            emit Initialized(1);\n        }\n    }\n\n    /**\n     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the\n     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be\n     * used to initialize parent contracts.\n     *\n     * `initializer` is equivalent to `reinitializer(1)`, so a reinitializer may be used after the original\n     * initialization step. This is essential to configure modules that are added through upgrades and that require\n     * initialization.\n     *\n     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in\n     * a contract, executing them in the right order is up to the developer or operator.\n     */\n    modifier reinitializer(uint8 version) {\n        bool isTopLevelCall = _setInitializedVersion(version);\n        if (isTopLevelCall) {\n            _initializing = true;\n        }\n        _;\n        if (isTopLevelCall) {\n            _initializing = false;\n            emit Initialized(version);\n        }\n    }\n\n    /**\n     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the\n     * {initializer} and {reinitializer} modifiers, directly or indirectly.\n     */\n    modifier onlyInitializing() {\n        require(_initializing, \"Initializable: contract is not initializing\");\n        _;\n    }\n\n    /**\n     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.\n     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized\n     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called\n     * through proxies.\n     */\n    function _disableInitializers() internal virtual {\n        _setInitializedVersion(type(uint8).max);\n    }\n\n    function _setInitializedVersion(uint8 version) private returns (bool) {\n        // If the contract is initializing we ignore whether _initialized is set in order to support multiple\n        // inheritance patterns, but we only do this in the context of a constructor, and for the lowest level\n        // of initializers, because in other contexts the contract may have been reentered.\n        if (_initializing) {\n            require(\n                version == 1 && !Address.isContract(address(this)),\n                \"Initializable: contract is already initialized\"\n            );\n            return false;\n        } else {\n            require(_initialized < version, \"Initializable: contract is already initialized\");\n            _initialized = version;\n            return true;\n        }\n    }\n}\n"
    },
    "@openzeppelin/contracts/utils/introspection/ERC165.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IERC165.sol\";\n\n/**\n * @dev Implementation of the {IERC165} interface.\n *\n * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check\n * for the additional interface id that will be supported. For example:\n *\n * ```solidity\n * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);\n * }\n * ```\n *\n * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.\n */\nabstract contract ERC165 is IERC165 {\n    /**\n     * @dev See {IERC165-supportsInterface}.\n     */\n    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n        return interfaceId == type(IERC165).interfaceId;\n    }\n}\n"
    },
    "@openzeppelin/contracts/token/ERC721/IERC721.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC721/IERC721.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../../utils/introspection/IERC165.sol\";\n\n/**\n * @dev Required interface of an ERC721 compliant contract.\n */\ninterface IERC721 is IERC165 {\n    /**\n     * @dev Emitted when `tokenId` token is transferred from `from` to `to`.\n     */\n    event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);\n\n    /**\n     * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.\n     */\n    event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);\n\n    /**\n     * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.\n     */\n    event ApprovalForAll(address indexed owner, address indexed operator, bool approved);\n\n    /**\n     * @dev Returns the number of tokens in ``owner``'s account.\n     */\n    function balanceOf(address owner) external view returns (uint256 balance);\n\n    /**\n     * @dev Returns the owner of the `tokenId` token.\n     *\n     * Requirements:\n     *\n     * - `tokenId` must exist.\n     */\n    function ownerOf(uint256 tokenId) external view returns (address owner);\n\n    /**\n     * @dev Safely transfers `tokenId` token from `from` to `to`.\n     *\n     * Requirements:\n     *\n     * - `from` cannot be the zero address.\n     * - `to` cannot be the zero address.\n     * - `tokenId` token must exist and be owned by `from`.\n     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.\n     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.\n     *\n     * Emits a {Transfer} event.\n     */\n    function safeTransferFrom(\n        address from,\n        address to,\n        uint256 tokenId,\n        bytes calldata data\n    ) external;\n\n    /**\n     * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients\n     * are aware of the ERC721 protocol to prevent tokens from being forever locked.\n     *\n     * Requirements:\n     *\n     * - `from` cannot be the zero address.\n     * - `to` cannot be the zero address.\n     * - `tokenId` token must exist and be owned by `from`.\n     * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}.\n     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.\n     *\n     * Emits a {Transfer} event.\n     */\n    function safeTransferFrom(\n        address from,\n        address to,\n        uint256 tokenId\n    ) external;\n\n    /**\n     * @dev Transfers `tokenId` token from `from` to `to`.\n     *\n     * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.\n     *\n     * Requirements:\n     *\n     * - `from` cannot be the zero address.\n     * - `to` cannot be the zero address.\n     * - `tokenId` token must be owned by `from`.\n     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transferFrom(\n        address from,\n        address to,\n        uint256 tokenId\n    ) external;\n\n    /**\n     * @dev Gives permission to `to` to transfer `tokenId` token to another account.\n     * The approval is cleared when the token is transferred.\n     *\n     * Only a single account can be approved at a time, so approving the zero address clears previous approvals.\n     *\n     * Requirements:\n     *\n     * - The caller must own the token or be an approved operator.\n     * - `tokenId` must exist.\n     *\n     * Emits an {Approval} event.\n     */\n    function approve(address to, uint256 tokenId) external;\n\n    /**\n     * @dev Approve or remove `operator` as an operator for the caller.\n     * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.\n     *\n     * Requirements:\n     *\n     * - The `operator` cannot be the caller.\n     *\n     * Emits an {ApprovalForAll} event.\n     */\n    function setApprovalForAll(address operator, bool _approved) external;\n\n    /**\n     * @dev Returns the account approved for `tokenId` token.\n     *\n     * Requirements:\n     *\n     * - `tokenId` must exist.\n     */\n    function getApproved(uint256 tokenId) external view returns (address operator);\n\n    /**\n     * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.\n     *\n     * See {setApprovalForAll}\n     */\n    function isApprovedForAll(address owner, address operator) external view returns (bool);\n}\n"
    },
    "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC721.sol\";\n\n/**\n * @title ERC-721 Non-Fungible Token Standard, optional metadata extension\n * @dev See https://eips.ethereum.org/EIPS/eip-721\n */\ninterface IERC721Metadata is IERC721 {\n    /**\n     * @dev Returns the token collection name.\n     */\n    function name() external view returns (string memory);\n\n    /**\n     * @dev Returns the token collection symbol.\n     */\n    function symbol() external view returns (string memory);\n\n    /**\n     * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.\n     */\n    function tokenURI(uint256 tokenId) external view returns (string memory);\n}\n"
    },
    "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC721/IERC721Receiver.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @title ERC721 token receiver interface\n * @dev Interface for any contract that wants to support safeTransfers\n * from ERC721 asset contracts.\n */\ninterface IERC721Receiver {\n    /**\n     * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}\n     * by `operator` from `from`, this function is called.\n     *\n     * It must return its Solidity selector to confirm the token transfer.\n     * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.\n     *\n     * The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`.\n     */\n    function onERC721Received(\n        address operator,\n        address from,\n        uint256 tokenId,\n        bytes calldata data\n    ) external returns (bytes4);\n}\n"
    },
    "@openzeppelin/contracts/utils/introspection/IERC165.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC165 standard, as defined in the\n * https://eips.ethereum.org/EIPS/eip-165[EIP].\n *\n * Implementers can declare support of contract interfaces, which can then be\n * queried by others ({ERC165Checker}).\n *\n * For an implementation, see {ERC165}.\n */\ninterface IERC165 {\n    /**\n     * @dev Returns true if this contract implements the interface defined by\n     * `interfaceId`. See the corresponding\n     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]\n     * to learn more about how these ids are created.\n     *\n     * This function call must use less than 30 000 gas.\n     */\n    function supportsInterface(bytes4 interfaceId) external view returns (bool);\n}\n"
    },
    "@openzeppelin/contracts/interfaces/IERC1271.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (interfaces/IERC1271.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC1271 standard signature validation method for\n * contracts as defined in https://eips.ethereum.org/EIPS/eip-1271[ERC-1271].\n *\n * _Available since v4.1._\n */\ninterface IERC1271 {\n    /**\n     * @dev Should return whether the signature provided is valid for the provided data\n     * @param hash      Hash of the data to be signed\n     * @param signature Signature byte array associated with _data\n     */\n    function isValidSignature(bytes32 hash, bytes memory signature) external view returns (bytes4 magicValue);\n}\n"
    },
    "contracts/interfaces/IGauge.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity ^0.8.0;\n\ninterface IGauge {\n    function killMe() external;\n}\n"
    },
    "contracts/interfaces/ICryptoPunksMarket.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity ^0.8.0;\n\ninterface ICryptoPunksMarket {\n    function offerPunkForSaleToAddress(\n        uint256 punkIndex,\n        uint256 minSalePriceInWei,\n        address toAddress\n    ) external;\n\n    function punkIndexToAddress(uint256 punkIndex) external view returns (address);\n\n    function transferPunk(address to, uint256 punkIndex) external;\n\n    function buyPunk(uint256 punkIndex) external;\n}\n"
    },
    "@openzeppelin/contracts/token/ERC721/ERC721.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC721/ERC721.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IERC721.sol\";\nimport \"./IERC721Receiver.sol\";\nimport \"./extensions/IERC721Metadata.sol\";\nimport \"../../utils/Address.sol\";\nimport \"../../utils/Context.sol\";\nimport \"../../utils/Strings.sol\";\nimport \"../../utils/introspection/ERC165.sol\";\n\n/**\n * @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including\n * the Metadata extension, but not including the Enumerable extension, which is available separately as\n * {ERC721Enumerable}.\n */\ncontract ERC721 is Context, ERC165, IERC721, IERC721Metadata {\n    using Address for address;\n    using Strings for uint256;\n\n    // Token name\n    string private _name;\n\n    // Token symbol\n    string private _symbol;\n\n    // Mapping from token ID to owner address\n    mapping(uint256 => address) private _owners;\n\n    // Mapping owner address to token count\n    mapping(address => uint256) private _balances;\n\n    // Mapping from token ID to approved address\n    mapping(uint256 => address) private _tokenApprovals;\n\n    // Mapping from owner to operator approvals\n    mapping(address => mapping(address => bool)) private _operatorApprovals;\n\n    /**\n     * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.\n     */\n    constructor(string memory name_, string memory symbol_) {\n        _name = name_;\n        _symbol = symbol_;\n    }\n\n    /**\n     * @dev See {IERC165-supportsInterface}.\n     */\n    function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {\n        return\n            interfaceId == type(IERC721).interfaceId ||\n            interfaceId == type(IERC721Metadata).interfaceId ||\n            super.supportsInterface(interfaceId);\n    }\n\n    /**\n     * @dev See {IERC721-balanceOf}.\n     */\n    function balanceOf(address owner) public view virtual override returns (uint256) {\n        require(owner != address(0), \"ERC721: balance query for the zero address\");\n        return _balances[owner];\n    }\n\n    /**\n     * @dev See {IERC721-ownerOf}.\n     */\n    function ownerOf(uint256 tokenId) public view virtual override returns (address) {\n        address owner = _owners[tokenId];\n        require(owner != address(0), \"ERC721: owner query for nonexistent token\");\n        return owner;\n    }\n\n    /**\n     * @dev See {IERC721Metadata-name}.\n     */\n    function name() public view virtual override returns (string memory) {\n        return _name;\n    }\n\n    /**\n     * @dev See {IERC721Metadata-symbol}.\n     */\n    function symbol() public view virtual override returns (string memory) {\n        return _symbol;\n    }\n\n    /**\n     * @dev See {IERC721Metadata-tokenURI}.\n     */\n    function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {\n        require(_exists(tokenId), \"ERC721Metadata: URI query for nonexistent token\");\n\n        string memory baseURI = _baseURI();\n        return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : \"\";\n    }\n\n    /**\n     * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each\n     * token will be the concatenation of the `baseURI` and the `tokenId`. Empty\n     * by default, can be overridden in child contracts.\n     */\n    function _baseURI() internal view virtual returns (string memory) {\n        return \"\";\n    }\n\n    /**\n     * @dev See {IERC721-approve}.\n     */\n    function approve(address to, uint256 tokenId) public virtual override {\n        address owner = ERC721.ownerOf(tokenId);\n        require(to != owner, \"ERC721: approval to current owner\");\n\n        require(\n            _msgSender() == owner || isApprovedForAll(owner, _msgSender()),\n            \"ERC721: approve caller is not owner nor approved for all\"\n        );\n\n        _approve(to, tokenId);\n    }\n\n    /**\n     * @dev See {IERC721-getApproved}.\n     */\n    function getApproved(uint256 tokenId) public view virtual override returns (address) {\n        require(_exists(tokenId), \"ERC721: approved query for nonexistent token\");\n\n        return _tokenApprovals[tokenId];\n    }\n\n    /**\n     * @dev See {IERC721-setApprovalForAll}.\n     */\n    function setApprovalForAll(address operator, bool approved) public virtual override {\n        _setApprovalForAll(_msgSender(), operator, approved);\n    }\n\n    /**\n     * @dev See {IERC721-isApprovedForAll}.\n     */\n    function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {\n        return _operatorApprovals[owner][operator];\n    }\n\n    /**\n     * @dev See {IERC721-transferFrom}.\n     */\n    function transferFrom(\n        address from,\n        address to,\n        uint256 tokenId\n    ) public virtual override {\n        //solhint-disable-next-line max-line-length\n        require(_isApprovedOrOwner(_msgSender(), tokenId), \"ERC721: transfer caller is not owner nor approved\");\n\n        _transfer(from, to, tokenId);\n    }\n\n    /**\n     * @dev See {IERC721-safeTransferFrom}.\n     */\n    function safeTransferFrom(\n        address from,\n        address to,\n        uint256 tokenId\n    ) public virtual override {\n        safeTransferFrom(from, to, tokenId, \"\");\n    }\n\n    /**\n     * @dev See {IERC721-safeTransferFrom}.\n     */\n    function safeTransferFrom(\n        address from,\n        address to,\n        uint256 tokenId,\n        bytes memory _data\n    ) public virtual override {\n        require(_isApprovedOrOwner(_msgSender(), tokenId), \"ERC721: transfer caller is not owner nor approved\");\n        _safeTransfer(from, to, tokenId, _data);\n    }\n\n    /**\n     * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients\n     * are aware of the ERC721 protocol to prevent tokens from being forever locked.\n     *\n     * `_data` is additional data, it has no specified format and it is sent in call to `to`.\n     *\n     * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.\n     * implement alternative mechanisms to perform token transfer, such as signature-based.\n     *\n     * Requirements:\n     *\n     * - `from` cannot be the zero address.\n     * - `to` cannot be the zero address.\n     * - `tokenId` token must exist and be owned by `from`.\n     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.\n     *\n     * Emits a {Transfer} event.\n     */\n    function _safeTransfer(\n        address from,\n        address to,\n        uint256 tokenId,\n        bytes memory _data\n    ) internal virtual {\n        _transfer(from, to, tokenId);\n        require(_checkOnERC721Received(from, to, tokenId, _data), \"ERC721: transfer to non ERC721Receiver implementer\");\n    }\n\n    /**\n     * @dev Returns whether `tokenId` exists.\n     *\n     * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.\n     *\n     * Tokens start existing when they are minted (`_mint`),\n     * and stop existing when they are burned (`_burn`).\n     */\n    function _exists(uint256 tokenId) internal view virtual returns (bool) {\n        return _owners[tokenId] != address(0);\n    }\n\n    /**\n     * @dev Returns whether `spender` is allowed to manage `tokenId`.\n     *\n     * Requirements:\n     *\n     * - `tokenId` must exist.\n     */\n    function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {\n        require(_exists(tokenId), \"ERC721: operator query for nonexistent token\");\n        address owner = ERC721.ownerOf(tokenId);\n        return (spender == owner || isApprovedForAll(owner, spender) || getApproved(tokenId) == spender);\n    }\n\n    /**\n     * @dev Safely mints `tokenId` and transfers it to `to`.\n     *\n     * Requirements:\n     *\n     * - `tokenId` must not exist.\n     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.\n     *\n     * Emits a {Transfer} event.\n     */\n    function _safeMint(address to, uint256 tokenId) internal virtual {\n        _safeMint(to, tokenId, \"\");\n    }\n\n    /**\n     * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is\n     * forwarded in {IERC721Receiver-onERC721Received} to contract recipients.\n     */\n    function _safeMint(\n        address to,\n        uint256 tokenId,\n        bytes memory _data\n    ) internal virtual {\n        _mint(to, tokenId);\n        require(\n            _checkOnERC721Received(address(0), to, tokenId, _data),\n            \"ERC721: transfer to non ERC721Receiver implementer\"\n        );\n    }\n\n    /**\n     * @dev Mints `tokenId` and transfers it to `to`.\n     *\n     * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible\n     *\n     * Requirements:\n     *\n     * - `tokenId` must not exist.\n     * - `to` cannot be the zero address.\n     *\n     * Emits a {Transfer} event.\n     */\n    function _mint(address to, uint256 tokenId) internal virtual {\n        require(to != address(0), \"ERC721: mint to the zero address\");\n        require(!_exists(tokenId), \"ERC721: token already minted\");\n\n        _beforeTokenTransfer(address(0), to, tokenId);\n\n        _balances[to] += 1;\n        _owners[tokenId] = to;\n\n        emit Transfer(address(0), to, tokenId);\n\n        _afterTokenTransfer(address(0), to, tokenId);\n    }\n\n    /**\n     * @dev Destroys `tokenId`.\n     * The approval is cleared when the token is burned.\n     *\n     * Requirements:\n     *\n     * - `tokenId` must exist.\n     *\n     * Emits a {Transfer} event.\n     */\n    function _burn(uint256 tokenId) internal virtual {\n        address owner = ERC721.ownerOf(tokenId);\n\n        _beforeTokenTransfer(owner, address(0), tokenId);\n\n        // Clear approvals\n        _approve(address(0), tokenId);\n\n        _balances[owner] -= 1;\n        delete _owners[tokenId];\n\n        emit Transfer(owner, address(0), tokenId);\n\n        _afterTokenTransfer(owner, address(0), tokenId);\n    }\n\n    /**\n     * @dev Transfers `tokenId` from `from` to `to`.\n     *  As opposed to {transferFrom}, this imposes no restrictions on msg.sender.\n     *\n     * Requirements:\n     *\n     * - `to` cannot be the zero address.\n     * - `tokenId` token must be owned by `from`.\n     *\n     * Emits a {Transfer} event.\n     */\n    function _transfer(\n        address from,\n        address to,\n        uint256 tokenId\n    ) internal virtual {\n        require(ERC721.ownerOf(tokenId) == from, \"ERC721: transfer from incorrect owner\");\n        require(to != address(0), \"ERC721: transfer to the zero address\");\n\n        _beforeTokenTransfer(from, to, tokenId);\n\n        // Clear approvals from the previous owner\n        _approve(address(0), tokenId);\n\n        _balances[from] -= 1;\n        _balances[to] += 1;\n        _owners[tokenId] = to;\n\n        emit Transfer(from, to, tokenId);\n\n        _afterTokenTransfer(from, to, tokenId);\n    }\n\n    /**\n     * @dev Approve `to` to operate on `tokenId`\n     *\n     * Emits a {Approval} event.\n     */\n    function _approve(address to, uint256 tokenId) internal virtual {\n        _tokenApprovals[tokenId] = to;\n        emit Approval(ERC721.ownerOf(tokenId), to, tokenId);\n    }\n\n    /**\n     * @dev Approve `operator` to operate on all of `owner` tokens\n     *\n     * Emits a {ApprovalForAll} event.\n     */\n    function _setApprovalForAll(\n        address owner,\n        address operator,\n        bool approved\n    ) internal virtual {\n        require(owner != operator, \"ERC721: approve to caller\");\n        _operatorApprovals[owner][operator] = approved;\n        emit ApprovalForAll(owner, operator, approved);\n    }\n\n    /**\n     * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.\n     * The call is not executed if the target address is not a contract.\n     *\n     * @param from address representing the previous owner of the given token ID\n     * @param to target address that will receive the tokens\n     * @param tokenId uint256 ID of the token to be transferred\n     * @param _data bytes optional data to send along with the call\n     * @return bool whether the call correctly returned the expected magic value\n     */\n    function _checkOnERC721Received(\n        address from,\n        address to,\n        uint256 tokenId,\n        bytes memory _data\n    ) private returns (bool) {\n        if (to.isContract()) {\n            try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) {\n                return retval == IERC721Receiver.onERC721Received.selector;\n            } catch (bytes memory reason) {\n                if (reason.length == 0) {\n                    revert(\"ERC721: transfer to non ERC721Receiver implementer\");\n                } else {\n                    assembly {\n                        revert(add(32, reason), mload(reason))\n                    }\n                }\n            }\n        } else {\n            return true;\n        }\n    }\n\n    /**\n     * @dev Hook that is called before any token transfer. This includes minting\n     * and burning.\n     *\n     * Calling conditions:\n     *\n     * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be\n     * transferred to `to`.\n     * - When `from` is zero, `tokenId` will be minted for `to`.\n     * - When `to` is zero, ``from``'s `tokenId` will be burned.\n     * - `from` and `to` are never both zero.\n     *\n     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\n     */\n    function _beforeTokenTransfer(\n        address from,\n        address to,\n        uint256 tokenId\n    ) internal virtual {}\n\n    /**\n     * @dev Hook that is called after any transfer of tokens. This includes\n     * minting and burning.\n     *\n     * Calling conditions:\n     *\n     * - when `from` and `to` are both non-zero.\n     * - `from` and `to` are never both zero.\n     *\n     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\n     */\n    function _afterTokenTransfer(\n        address from,\n        address to,\n        uint256 tokenId\n    ) internal virtual {}\n}\n"
    },
    "contracts/Minter.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity ^0.8.15;\n\nimport \"./interfaces/IMinter.sol\";\nimport \"./interfaces/IGaugeController.sol\";\nimport \"./interfaces/INFTGauge.sol\";\n\ninterface IToken {\n    function mint(address account, uint256 value) external;\n}\n\ncontract Minter is IMinter {\n    uint256 constant RATE_DENOMINATOR = 1e18;\n    uint256 constant INFLATION_DELAY = 86400;\n\n    address public immutable override token;\n    address public immutable override controller;\n    uint256 public immutable override initialSupply;\n    uint256 public immutable override initialRate;\n    uint256 public immutable override rateReductionTime;\n    uint256 public immutable override rateReductionCoefficient;\n\n    int128 public override miningEpoch;\n    uint256 public override startEpochTime;\n    uint256 public override rate;\n\n    mapping(address => mapping(uint256 => mapping(address => uint256))) public override minted; // gauge -> tokenId -> user -> amount\n\n    uint256 internal startEpochSupply;\n\n    constructor(\n        address _token,\n        address _controller,\n        uint256 _initialSupply,\n        uint256 _initialRate,\n        uint256 _rateReductionTime,\n        uint256 _rateReductionCoefficient\n    ) {\n        token = _token;\n        controller = _controller;\n        initialSupply = _initialSupply;\n        initialRate = _initialRate;\n        rateReductionTime = _rateReductionTime;\n        rateReductionCoefficient = _rateReductionCoefficient;\n\n        startEpochTime = block.timestamp + INFLATION_DELAY - rateReductionTime;\n        miningEpoch = -1;\n        rate = 0;\n        startEpochSupply = initialSupply;\n    }\n\n    /**\n     * @notice Current number of tokens in existence (claimed or unclaimed)\n     */\n    function availableSupply() external view override returns (uint256) {\n        return _availableSupply();\n    }\n\n    /**\n     * @notice How much supply is mintable from start timestamp till end timestamp\n     * @param start Start of the time interval (timestamp)\n     * @param end End of the time interval (timestamp)\n     * @return Tokens mintable from `start` till `end`\n     */\n    function mintableInTimeframe(uint256 start, uint256 end) external view returns (uint256) {\n        require(start <= end, \"MT: INVALID_TIME_RANGE\");\n        uint256 toMint = 0;\n        uint256 currentEpochTime = startEpochTime;\n        uint256 currentRate = rate;\n\n        // Special case if end is in future (not yet minted) epoch\n        if (end > currentEpochTime + rateReductionTime) {\n            currentEpochTime += rateReductionTime;\n            currentRate = (currentRate * RATE_DENOMINATOR) / rateReductionCoefficient;\n        }\n\n        require(end <= currentEpochTime + rateReductionTime, \"MT: TOO_FAR_IN_FUTURE\");\n\n        for (uint256 i; i < 1000; ) {\n            if (end >= currentEpochTime) {\n                uint256 currentEnd = end;\n                if (currentEnd > currentEpochTime + rateReductionTime)\n                    currentEnd = currentEpochTime + rateReductionTime;\n\n                uint256 currentStart = start;\n                if (currentStart >= currentEpochTime + rateReductionTime) break;\n                else if (currentStart < currentEpochTime) currentStart = currentEpochTime;\n\n                toMint += currentRate * (currentEnd - currentStart);\n\n                if (start >= currentEpochTime) break;\n            }\n\n            currentEpochTime -= rateReductionTime;\n            currentRate = (currentRate * rateReductionCoefficient) / RATE_DENOMINATOR; // double-division with rounding made rate a bit less => good\n            require(currentRate <= initialRate, \"MT: THIS_SHOULD_NEVER_HAPPEN\");\n\n            unchecked {\n                ++i;\n            }\n        }\n\n        return toMint;\n    }\n\n    /**\n     * @notice Update mining rate and supply at the start of the epoch\n     * @dev Callable by any address, but only once per epoch\n     *      Total supply becomes slightly larger if this function is called late\n     */\n    function updateMiningParameters() external override {\n        require(block.timestamp >= startEpochTime + rateReductionTime, \"MT: TOO_SOON\");\n        _updateMiningParameters();\n    }\n\n    /**\n     * @notice Get timestamp of the current mining epoch start\n     *         while simultaneously updating mining parameters\n     * @return Timestamp of the epoch\n     */\n    function startEpochTimeWrite() external override returns (uint256) {\n        uint256 _startEpochTime = startEpochTime;\n        if (block.timestamp >= _startEpochTime + rateReductionTime) {\n            _updateMiningParameters();\n            return startEpochTime;\n        } else return _startEpochTime;\n    }\n\n    /**\n     * @notice Get timestamp of the next mining epoch start\n     *         while simultaneously updating mining parameters\n     * @return Timestamp of the next epoch\n     */\n    function futureEpochTimeWrite() external override returns (uint256) {\n        uint256 _startEpochTime = startEpochTime;\n        if (block.timestamp >= _startEpochTime + rateReductionTime) {\n            _updateMiningParameters();\n            return startEpochTime + rateReductionTime;\n        } else return _startEpochTime + rateReductionTime;\n    }\n\n    /**\n     * @notice Mint everything which belongs to `msg.sender` and send to them\n     * @param gaugeAddr `NFTGauge` address to get mintable amount from\n     * @param tokenId tokenId\n     */\n    function mint(address gaugeAddr, uint256 tokenId) external override {\n        require(IGaugeController(controller).gaugeTypes(gaugeAddr) >= 0, \"MT: GAUGE_NOT_ADDED\");\n\n        INFTGauge(gaugeAddr).userCheckpoint(tokenId, msg.sender);\n        uint256 total = INFTGauge(gaugeAddr).integrateFraction(tokenId, msg.sender);\n\n        uint256 _minted = minted[gaugeAddr][tokenId][msg.sender];\n        if (total > _minted) {\n            minted[gaugeAddr][tokenId][msg.sender] = total;\n\n            emit Minted(msg.sender, gaugeAddr, tokenId, total - _minted);\n            IToken(token).mint(msg.sender, total - _minted);\n        }\n    }\n\n    function _availableSupply() internal view returns (uint256) {\n        return startEpochSupply + (block.timestamp - startEpochTime) * rate;\n    }\n\n    /**\n     * @dev Update mining rate and supply at the start of the epoch\n     *      Any modifying mining call must also call this\n     */\n    function _updateMiningParameters() internal {\n        uint256 _rate = rate;\n        uint256 _startEpochSupply = startEpochSupply;\n\n        startEpochTime += rateReductionTime;\n        miningEpoch += 1;\n\n        if (_rate == 0) _rate = initialRate;\n        else {\n            _startEpochSupply += _rate * rateReductionTime;\n            startEpochSupply = _startEpochSupply;\n            _rate = (_rate * RATE_DENOMINATOR) / rateReductionCoefficient;\n        }\n\n        rate = _rate;\n\n        emit UpdateMiningParameters(block.timestamp, _rate, _startEpochSupply);\n    }\n}\n"
    },
    "contracts/GaugeController.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity ^0.8.15;\n\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\nimport \"./interfaces/IGaugeController.sol\";\nimport \"./interfaces/IVotingEscrow.sol\";\nimport \"./interfaces/IGauge.sol\";\nimport \"./libraries/Math.sol\";\n\n/**\n * @title Gauge Controller\n * @author LevX (team@levx.io)\n * @notice Controls liquidity gauges and the issuance of coins through the gauges\n * @dev Ported from vyper (https://github.com/curvefi/curve-dao-contracts/blob/master/contracts/GaugeController.vy)\n */\ncontract GaugeController is Ownable, IGaugeController {\n    struct Point {\n        uint256 bias;\n        uint256 slope;\n    }\n\n    struct VotedSlope {\n        uint256 slope;\n        uint256 power;\n        uint256 end;\n    }\n\n    uint256 internal constant MULTIPLIER = 1e18;\n\n    uint256 public override interval;\n    uint256 public override weightVoteDelay;\n    address public override votingEscrow;\n\n    // Gauge parameters\n    // All numbers are \"fixed point\" on the basis of 1e18\n    int128 public override gaugeTypesLength;\n    int128 public override gaugesLength;\n    mapping(int128 => string) public override gaugeTypeNames;\n\n    // Needed for enumeration\n    mapping(int128 => address) public override gauges;\n\n    // we increment values by 1 prior to storing them here so we can rely on a value\n    // of zero as meaning the gauge has not been set\n    mapping(address => int128) internal _gaugeTypes;\n\n    mapping(address => mapping(address => VotedSlope)) public override voteUserSlopes; // user -> addr -> VotedSlope\n    mapping(address => uint256) public override voteUserPower; // Total vote power used by user\n    mapping(address => mapping(address => uint256)) public override lastUserVote; // Last user vote's timestamp for each gauge address\n\n    // Past and scheduled points for gauge weight, sum of weights per type, total weight\n    // Point is for bias+slope\n    // changes_* are for changes in slope\n    // time_* are for the last change timestamp\n    // timestamps are rounded to whole weeks\n\n    mapping(address => mapping(uint256 => Point)) public override pointsWeight; // addr -> time -> Point\n    mapping(address => mapping(uint256 => uint256)) internal _changesWeight; // addr -> time -> slope\n    mapping(address => uint256) public override timeWeight; // addr -> last scheduled time (next week)\n\n    mapping(int128 => mapping(uint256 => Point)) public override pointsSum; // gaugeType -> time -> Point\n    mapping(int128 => mapping(uint256 => uint256)) internal _changesSum; // gaugeType -> time -> slope\n    mapping(int128 => uint256) public override timeSum; // gaugeType -> last scheduled time (next week)\n\n    mapping(uint256 => uint256) public override pointsTotal; // time -> total weight\n    uint256 public override timeTotal; // last scheduled time\n\n    mapping(int128 => mapping(uint256 => uint256)) public override pointsTypeWeight; // gaugeType -> time -> type weight\n    mapping(int128 => uint256) public override timeTypeWeight; // gaugeType -> last scheduled time (next week)\n\n    /**\n     * @notice Contract constructor\n     * @param _interval for how many seconds gauge weights will remain the same\n     * @param _weightVoteDelay for how many seconds weight votes cannot be changed\n     * @param _votingEscrow `VotingEscrow` contract address\n     */\n    constructor(\n        uint256 _interval,\n        uint256 _weightVoteDelay,\n        address _votingEscrow\n    ) {\n        interval = _interval;\n        weightVoteDelay = _weightVoteDelay;\n        votingEscrow = _votingEscrow;\n        timeTotal = (block.timestamp / _interval) * _interval;\n    }\n\n    /**\n     * @notice Get gauge type for id\n     * @param addr Gauge address\n     * @return Gauge type id\n     */\n    function gaugeTypes(address addr) external view override returns (int128) {\n        int128 gaugeType = _gaugeTypes[addr];\n        require(gaugeType != 0, \"GC: INVALID_GAUGE_TYPE\");\n\n        return gaugeType - 1;\n    }\n\n    /**\n     * @notice Get current gauge weight\n     * @param addr Gauge address\n     * @return Gauge weight\n     */\n    function getGaugeWeight(address addr) external view override returns (uint256) {\n        return pointsWeight[addr][timeWeight[addr]].bias;\n    }\n\n    /**\n     * @notice Get current type weight\n     * @param gaugeType Type id\n     * @return Type weight\n     */\n    function getTypeWeight(int128 gaugeType) external view override returns (uint256) {\n        return pointsTypeWeight[gaugeType][timeTypeWeight[gaugeType]];\n    }\n\n    /**\n     * @notice Get current total (type-weighted) weight\n     * @return Total weight\n     */\n    function getTotalWeight() external view override returns (uint256) {\n        return pointsTotal[timeTotal];\n    }\n\n    /**\n     * @notice Get sum of gauge weights per type\n     * @param gaugeType Type id\n     * @return Sum of gauge weights\n     */\n    function getWeightsSumPerType(int128 gaugeType) external view override returns (uint256) {\n        return pointsSum[gaugeType][timeSum[gaugeType]].bias;\n    }\n\n    /**\n     * @notice Get Gauge relative weight (not more than 1.0) normalized to 1e18\n     * (e.g. 1.0 == 1e18). Inflation which will be received by it is\n     * inflation_rate * relative_weight / 1e18\n     * @param addr Gauge address\n     * @return Value of relative weight normalized to 1e18\n     */\n    function gaugeRelativeWeight(address addr) external view override returns (uint256) {\n        return _gaugeRelativeWeight(addr, block.timestamp);\n    }\n\n    /**\n     * @notice Get Gauge relative weight (not more than 1.0) normalized to 1e18\n     * (e.g. 1.0 == 1e18). Inflation which will be received by it is\n     * inflation_rate * relative_weight / 1e18\n     * @param addr Gauge address\n     * @param time Relative weight at the specified timestamp in the past or present\n     * @return Value of relative weight normalized to 1e18\n     */\n    function gaugeRelativeWeight(address addr, uint256 time) public view override returns (uint256) {\n        return _gaugeRelativeWeight(addr, time);\n    }\n\n    /**\n     * @notice Add gauge type with name `name` and weight `weight`\n     * @param name Name of gauge type\n     */\n    function addType(string memory name) external override {\n        addType(name, 0);\n    }\n\n    /**\n     * @notice Add gauge type with name `name` and weight `weight`\n     * @param name Name of gauge type\n     * @param weight Weight of gauge type\n     */\n    function addType(string memory name, uint256 weight) public override onlyOwner {\n        int128 gaugeType = gaugeTypesLength;\n        gaugeTypeNames[gaugeType] = name;\n        gaugeTypesLength = gaugeType + 1;\n        if (weight != 0) {\n            _changeTypeWeight(gaugeType, weight);\n        }\n        emit AddType(name, gaugeType);\n    }\n\n    /**\n     * @notice Change type weight\n     * @param gaugeType Type id\n     * @param weight New type weight\n     */\n    function changeTypeWeight(int128 gaugeType, uint256 weight) external override onlyOwner {\n        _changeTypeWeight(gaugeType, weight);\n    }\n\n    /**\n     * @notice Add gauge `addr` of type `gaugeType` with weight `weight`\n     * @param addr Gauge address\n     * @param gaugeType Gauge type\n     */\n    function addGauge(address addr, int128 gaugeType) external override {\n        addGauge(addr, gaugeType, 0);\n    }\n\n    /**\n     * @notice Add gauge `addr` of type `gaugeType` with weight `weight`\n     * @param addr Gauge address\n     * @param gaugeType Gauge type\n     * @param weight Gauge weight\n     */\n    function addGauge(\n        address addr,\n        int128 gaugeType,\n        uint256 weight\n    ) public override onlyOwner {\n        require((gaugeType >= 0) && (gaugeType < gaugeTypesLength), \"GC: INVALID_GAUGE_TYPE\");\n        require(_gaugeTypes[addr] == 0, \"GC: DUPLICATE_GAUGE\");\n\n        int128 n = gaugesLength;\n        gaugesLength = n + 1;\n        gauges[n] = addr;\n\n        _gaugeTypes[addr] = gaugeType + 1;\n        uint256 _interval = interval;\n        uint256 nextTime = ((block.timestamp + _interval) / _interval) * _interval;\n\n        if (weight > 0) {\n            uint256 typeWeight = _getTypeWeight(gaugeType);\n            uint256 oldSum = _getSum(gaugeType);\n            uint256 oldTotal = _getTotal();\n\n            pointsSum[gaugeType][nextTime].bias = weight + oldSum;\n            timeSum[gaugeType] = nextTime;\n            pointsTotal[nextTime] = oldTotal + typeWeight * weight;\n            timeTotal = nextTime;\n\n            pointsWeight[addr][nextTime].bias = weight;\n        }\n\n        if (timeSum[gaugeType] == 0) timeSum[gaugeType] = nextTime;\n        timeWeight[addr] = nextTime;\n\n        emit NewGauge(addr, gaugeType, weight);\n    }\n\n    /**\n     * @notice Change weight of gauge `addr` to `weight`\n     * @param increment Gauge weight to be increased\n     */\n    function increaseGaugeWeight(uint256 increment) external override {\n        _increaseGaugeWeight(increment);\n    }\n\n    /**\n     * @notice Toggle the killed status of the gauge\n     * @param addr Gauge address\n     */\n    function killGauge(address addr) external override onlyOwner {\n        IGauge(addr).killMe();\n    }\n\n    /**\n     * @notice Checkpoint to fill data common for all gauges\n     */\n    function checkpoint() external override {\n        _getTotal();\n    }\n\n    /**\n     * @notice Checkpoint to fill data for both a specific gauge and common for all gauges\n     * @param addr Gauge address\n     */\n    function checkpointGauge(address addr) external override {\n        _getWeight(addr);\n        _getTotal();\n    }\n\n    /**\n     * @notice Get gauge weight normalized to 1e18 and also fill all the unfilled\n    values for type and gauge records\n     * @dev Any address can call, however nothing is recorded if the values are filled already\n     * @param addr Gauge address\n     * @return Value of relative weight normalized to 1e18\n     */\n    function gaugeRelativeWeightWrite(address addr) external override returns (uint256) {\n        return gaugeRelativeWeightWrite(addr, block.timestamp);\n    }\n\n    /**\n     * @notice Get gauge weight normalized to 1e18 and also fill all the unfilled\n    values for type and gauge records\n     * @dev Any address can call, however nothing is recorded if the values are filled already\n     * @param addr Gauge address\n     * @param time Relative weight at the specified timestamp in the past or present\n     * @return Value of relative weight normalized to 1e18\n     */\n    function gaugeRelativeWeightWrite(address addr, uint256 time) public override returns (uint256) {\n        _getWeight(addr);\n        _getTotal(); // Also calculates get_sum\n        return gaugeRelativeWeight(addr, time);\n    }\n\n    /**\n     * @notice Allocate voting power for changing pool weights on behalf of a user (only called by gauges)\n     * @param user Actual user whose voting power will be utilized\n     * @param userWeight Weight for a gauge in bps (units of 0.01%). Minimal is 0.01%. Ignored if 0\n     */\n    function voteForGaugeWeights(address user, uint256 userWeight) external override {\n        address escrow = votingEscrow;\n        uint256 slope = uint256(uint128(IVotingEscrow(escrow).getLastUserSlope(user)));\n        uint256 lockEnd = IVotingEscrow(escrow).unlockTime(user);\n        uint256 _interval = interval;\n        uint256 nextTime = ((block.timestamp + _interval) / _interval) * _interval;\n        require(lockEnd > nextTime, \"GC: LOCK_EXPIRES_TOO_EARLY\");\n        require((userWeight >= 0) && (userWeight <= 10000), \"GC: VOTING_POWER_ALL_USED\");\n        require(block.timestamp >= lastUserVote[user][msg.sender] + weightVoteDelay, \"GC: VOTED_TOO_EARLY\");\n\n        // Avoid stack too deep error\n        {\n            int128 gaugeType = _gaugeTypes[msg.sender] - 1;\n            require(gaugeType >= 0, \"GC: GAUGE_NOT_ADDED\");\n            // Prepare slopes and biases in memory\n            VotedSlope memory oldSlope = voteUserSlopes[user][msg.sender];\n            uint256 oldDt;\n            if (oldSlope.end > nextTime) oldDt = oldSlope.end - nextTime;\n            VotedSlope memory newSlope = VotedSlope({\n                slope: (slope * userWeight) / 10000,\n                end: lockEnd,\n                power: userWeight\n            });\n\n            // Check and update powers (weights) used\n            uint256 powerUsed = voteUserPower[user];\n            powerUsed = powerUsed + newSlope.power - oldSlope.power;\n            voteUserPower[user] = powerUsed;\n            require((powerUsed >= 0) && (powerUsed <= 10000), \"GC: USED_TOO_MUCH_POWER\");\n\n            /// Remove old and schedule new slope changes\n            _updateSlopeChanges(\n                msg.sender,\n                nextTime,\n                gaugeType,\n                oldSlope.slope * oldDt,\n                newSlope.slope * (lockEnd - nextTime),\n                oldSlope,\n                newSlope\n            );\n        }\n\n        // Record last action time\n        lastUserVote[user][msg.sender] = block.timestamp;\n\n        emit VoteForGauge(block.timestamp, user, msg.sender, userWeight);\n    }\n\n    /**\n     * @notice Get Gauge relative weight (not more than 1.0) normalized to 1e18\n     * (e.g. 1.0 == 1e18). Inflation which will be received by it is\n     * inflation_rate * relative_weight / 1e18\n     * @param addr Gauge address\n     * @param time Relative weight at the specified timestamp in the past or present\n     * @return Value of relative weight normalized to 1e18\n     */\n    function _gaugeRelativeWeight(address addr, uint256 time) internal view returns (uint256) {\n        uint256 _interval = interval;\n        uint256 t = (time / _interval) * _interval;\n        uint256 totalWeight = pointsTotal[t];\n\n        if (totalWeight > 0) {\n            int128 gaugeType = _gaugeTypes[addr] - 1;\n            uint256 typeWeight = pointsTypeWeight[gaugeType][t];\n            uint256 gaugeWeight = pointsWeight[addr][t].bias;\n            return (MULTIPLIER * typeWeight * gaugeWeight) / totalWeight;\n        } else return 0;\n    }\n\n    /**\n     * @notice Change type weight\n     * @param gaugeType Type id\n     * @param weight New type weight\n     */\n    function _changeTypeWeight(int128 gaugeType, uint256 weight) internal {\n        uint256 oldWeight = _getTypeWeight(gaugeType);\n        uint256 oldSum = _getSum(gaugeType);\n        uint256 totalWeight = _getTotal();\n        uint256 _interval = interval;\n        uint256 nextTime = ((block.timestamp + _interval) / _interval) * _interval;\n\n        totalWeight = totalWeight + oldSum * weight - oldSum * oldWeight;\n        pointsTotal[nextTime] = totalWeight;\n        pointsTypeWeight[gaugeType][nextTime] = weight;\n        timeTotal = nextTime;\n        timeTypeWeight[gaugeType] = nextTime;\n\n        emit NewTypeWeight(gaugeType, nextTime, weight, totalWeight);\n    }\n\n    /**\n     * @notice Change weight of gauge `addr` to `weight`\n     * @param increment Gauge weight to be increased\n     */\n    function _increaseGaugeWeight(uint256 increment) internal {\n        int128 gaugeType = _gaugeTypes[msg.sender] - 1;\n        require(gaugeType >= 0, \"GC: GAUGE_NOT_ADDED\");\n\n        uint256 oldGaugeWeight = _getWeight(msg.sender);\n        uint256 typeWeight = _getTypeWeight(gaugeType);\n        uint256 oldSum = _getSum(gaugeType);\n        uint256 totalWeight = _getTotal();\n        uint256 _interval = interval;\n        uint256 nextTime = ((block.timestamp + _interval) / _interval) * _interval;\n\n        pointsWeight[msg.sender][nextTime].bias = oldGaugeWeight + increment;\n        timeWeight[msg.sender] = nextTime;\n\n        uint256 newSum = oldSum + increment;\n        pointsSum[gaugeType][nextTime].bias = newSum;\n        timeSum[gaugeType] = nextTime;\n\n        totalWeight = totalWeight + newSum * typeWeight - oldSum * typeWeight;\n        pointsTotal[nextTime] = totalWeight;\n        timeTotal = nextTime;\n\n        emit NewGaugeWeight(msg.sender, block.timestamp, oldGaugeWeight + increment, totalWeight);\n    }\n\n    /**\n     * @notice Fill historic total weights week-over-week for missed checkins\n     * and return the total for the future week\n     * @return Total weight\n     */\n    function _getTotal() internal returns (uint256) {\n        uint256 _interval = interval;\n        uint256 t = timeTotal;\n        int128 nGaugeTypes = gaugeTypesLength;\n        // If we have already checkpointed - still need to change the value\n        if (t > block.timestamp) t -= _interval;\n        uint256 pt = pointsTotal[t];\n\n        for (int128 gaugeType; gaugeType < 100; ) {\n            if (gaugeType == nGaugeTypes) break;\n            _getSum(gaugeType);\n            _getTypeWeight(gaugeType);\n\n            unchecked {\n                ++gaugeType;\n            }\n        }\n\n        for (uint256 i; i < 500; ) {\n            if (t > block.timestamp) break;\n            t += _interval;\n            pt = 0;\n            // Scales as n_types * n_unchecked_weeks (hopefully 1 at most)\n            for (int128 gaugeType; gaugeType < 100; ) {\n                if (gaugeType == nGaugeTypes) break;\n                uint256 typeSum = pointsSum[gaugeType][t].bias;\n                uint256 typeWeight = pointsTypeWeight[gaugeType][t];\n                pt += typeSum * typeWeight;\n\n                unchecked {\n                    ++gaugeType;\n                }\n            }\n            pointsTotal[t] = pt;\n\n            if (t > block.timestamp) timeTotal = t;\n\n            unchecked {\n                ++i;\n            }\n        }\n        return pt;\n    }\n\n    /**\n     * @notice Fill sum of gauge weights for the same type week-over-week for\n     * missed checkins and return the sum for the future week\n     * @param gaugeType Gauge type id\n     * @return Sum of weights\n     */\n    function _getSum(int128 gaugeType) internal returns (uint256) {\n        uint256 t = timeSum[gaugeType];\n        if (t > 0) {\n            Point memory pt = pointsSum[gaugeType][t];\n            uint256 _interval = interval;\n            for (uint256 i; i < 500; ) {\n                if (t > block.timestamp) break;\n                t += _interval;\n                uint256 dBias = pt.slope * _interval;\n                if (pt.bias > dBias) {\n                    pt.bias -= dBias;\n                    uint256 dSlope = _changesSum[gaugeType][t];\n                    pt.slope -= dSlope;\n                } else {\n                    pt.bias = 0;\n                    pt.slope = 0;\n                }\n                pointsSum[gaugeType][t] = pt;\n                if (t > block.timestamp) timeSum[gaugeType] = t;\n\n                unchecked {\n                    ++i;\n                }\n            }\n            return pt.bias;\n        } else return 0;\n    }\n\n    /**\n     * @notice Fill historic type weights week-over-week for missed checkins\n     * and return the type weight for the future week\n     * @param gaugeType Gauge type id\n     * @return Type weight\n     */\n    function _getTypeWeight(int128 gaugeType) internal returns (uint256) {\n        uint256 t = timeTypeWeight[gaugeType];\n        if (t > 0) {\n            uint256 w = pointsTypeWeight[gaugeType][t];\n            uint256 _interval = interval;\n            for (uint256 i; i < 500; ) {\n                if (t > block.timestamp) break;\n                t += _interval;\n                pointsTypeWeight[gaugeType][t] = w;\n                if (t > block.timestamp) timeTypeWeight[gaugeType] = t;\n\n                unchecked {\n                    ++i;\n                }\n            }\n            return w;\n        } else return 0;\n    }\n\n    /**\n     * @notice Fill historic gauge weights week-over-week for missed checkins\n     * and return the total for the future week\n     * @param addr Gauge address\n     * @return Gauge weight\n     */\n    function _getWeight(address addr) internal returns (uint256) {\n        uint256 t = timeWeight[addr];\n        if (t > 0) {\n            Point memory pt = pointsWeight[addr][t];\n            uint256 _interval = interval;\n            for (uint256 i; i < 500; ) {\n                if (t > block.timestamp) break;\n                t += _interval;\n                uint256 dBias = pt.slope * _interval;\n                if (pt.bias > dBias) {\n                    pt.bias -= dBias;\n                    uint256 dSlope = _changesWeight[addr][t];\n                    pt.slope -= dSlope;\n                } else {\n                    pt.bias = 0;\n                    pt.slope = 0;\n                }\n                pointsWeight[addr][t] = pt;\n                if (t > block.timestamp) timeWeight[addr] = t;\n\n                unchecked {\n                    ++i;\n                }\n            }\n            return pt.bias;\n        } else return 0;\n    }\n\n    function _updateSlopeChanges(\n        address addr,\n        uint256 nextTime,\n        int128 gaugeType,\n        uint256 oldBias,\n        uint256 newBias,\n        VotedSlope memory oldSlope,\n        VotedSlope memory newSlope\n    ) internal {\n        // Remove slope changes for old slopes\n        // Schedule recording of initial slope for next_time\n        pointsWeight[addr][nextTime].bias = Math.max(_getWeight(addr) + newBias, oldBias) - oldBias;\n        pointsSum[gaugeType][nextTime].bias = Math.max(_getSum(gaugeType) + newBias, oldBias) - oldBias;\n        if (oldSlope.end > nextTime) {\n            pointsWeight[addr][nextTime].slope =\n                Math.max(pointsWeight[addr][nextTime].slope + newSlope.slope, oldSlope.slope) -\n                oldSlope.slope;\n            pointsSum[gaugeType][nextTime].slope =\n                Math.max(pointsSum[gaugeType][nextTime].slope + newSlope.slope, oldSlope.slope) -\n                oldSlope.slope;\n        } else {\n            pointsWeight[addr][nextTime].slope += newSlope.slope;\n            pointsSum[gaugeType][nextTime].slope += newSlope.slope;\n        }\n        if (oldSlope.end > block.timestamp) {\n            // Cancel old slope changes if they still didn't happen\n            _changesWeight[addr][oldSlope.end] -= oldSlope.slope;\n            _changesSum[gaugeType][oldSlope.end] -= oldSlope.slope;\n        }\n        // Add slope changes for new slopes\n        _changesWeight[addr][newSlope.end] += newSlope.slope;\n        _changesSum[gaugeType][newSlope.end] += newSlope.slope;\n\n        _getTotal();\n\n        voteUserSlopes[msg.sender][addr] = newSlope;\n    }\n}\n"
    },
    "contracts/VotingEscrow.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity ^0.8.15;\n\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\nimport \"@openzeppelin/contracts/security/ReentrancyGuard.sol\";\nimport \"./interfaces/IVotingEscrow.sol\";\nimport \"./interfaces/IVotingEscrowMigrator.sol\";\nimport \"./interfaces/IVotingEscrowDelegate.sol\";\nimport \"./libraries/Integers.sol\";\n\n/**\n * @title Voting Escrow\n * @author LevX (team@levx.io)\n * @notice Votes have a weight depending on time, so that users are\n *         committed to the future of (whatever they are voting for)\n * @dev Vote weight decays linearly over time. Lock time cannot be\n *      more than `MAXTIME`.\n * @dev Ported from vyper (https://github.com/curvefi/curve-dao-contracts/blob/master/contracts/VotingEscrow.vy)\n */\n\n// Voting escrow to have time-weighted votes\n// Votes have a weight depending on time, so that users are committed\n// to the future of (whatever they are voting for).\n// The weight in this implementation is linear, and lock cannot be more than maxtime:\n// w ^\n// 1 +        /\n//   |      /\n//   |    /\n//   |  /\n//   |/\n// 0 +--------+------> time\n//       maxtime\n\ncontract VotingEscrow is Ownable, ReentrancyGuard, IVotingEscrow {\n    using SafeERC20 for IERC20;\n    using Integers for int128;\n    using Integers for uint256;\n\n    struct Point {\n        int128 bias;\n        int128 slope; // - dweight / dt\n        uint256 ts;\n        uint256 blk; // block\n    }\n\n    struct LockedBalance {\n        int128 amount;\n        int128 discount;\n        uint256 start;\n        uint256 end;\n    }\n\n    int128 public constant DEPOSIT_FOR_TYPE = 0;\n    int128 public constant CRETE_LOCK_TYPE = 1;\n    int128 public constant INCREASE_LOCK_AMOUNT = 2;\n    int128 public constant INCREASE_UNLOCK_TIME = 3;\n    uint256 internal constant MULTIPLIER = 1e18;\n\n    uint256 public immutable override interval;\n    uint256 public immutable override maxDuration;\n    address public immutable override token;\n    string public override name;\n    string public override symbol;\n    uint8 public immutable override decimals;\n\n    address public override migrator;\n    mapping(address => bool) public override isDelegate;\n\n    uint256 public override supply;\n    mapping(address => bool) public override migrated;\n    mapping(address => address[]) public override delegateAt;\n    mapping(address => LockedBalance) public override locked;\n    uint256 public override epoch;\n\n    mapping(uint256 => Point) public override pointHistory; // epoch -> unsigned point\n    mapping(address => mapping(uint256 => Point)) public override userPointHistory; // user -> Point[user_epoch]\n    mapping(address => uint256) public override userPointEpoch;\n    mapping(uint256 => int128) public override slopeChanges; // time -> signed slope change\n\n    constructor(\n        address _token,\n        string memory _name,\n        string memory _symbol,\n        uint256 _interval,\n        uint256 _maxDuration\n    ) {\n        token = _token;\n        name = _name;\n        symbol = _symbol;\n        decimals = IERC20Metadata(_token).decimals();\n\n        interval = _interval;\n        maxDuration = (_maxDuration / _interval) * _interval; // rounded down to a multiple of interval\n\n        pointHistory[0].blk = block.number;\n        pointHistory[0].ts = block.timestamp;\n    }\n\n    modifier beforeMigrated(address addr) {\n        require(!migrated[addr], \"VE: LOCK_MIGRATED\");\n        _;\n    }\n\n    modifier onlyDelegate {\n        require(isDelegate[msg.sender], \"VE: NOT_DELEGATE\");\n        _;\n    }\n\n    /**\n     * @notice Check if the call is from an EOA or a whitelisted smart contract, revert if not\n     */\n    modifier authorized {\n        if (msg.sender != tx.origin) {\n            require(isDelegate[msg.sender], \"VE: CONTRACT_NOT_DELEGATE\");\n        }\n        _;\n    }\n\n    function delegateLength(address addr) external view returns (uint256) {\n        return delegateAt[addr].length;\n    }\n\n    /**\n     * @notice Get the most recently recorded rate of voting power decrease for `addr`\n     * @param addr Address of the user wallet\n     * @return Value of the slope\n     */\n    function getLastUserSlope(address addr) external view override returns (int128) {\n        uint256 uepoch = userPointEpoch[addr];\n        return userPointHistory[addr][uepoch].slope;\n    }\n\n    /**\n     * @notice Get the timestamp for checkpoint `_idx` for `_addr`\n     * @param _addr User wallet address\n     * @param _idx User epoch number\n     * @return Epoch time of the checkpoint\n     */\n    function getCheckpointTime(address _addr, uint256 _idx) external view override returns (uint256) {\n        return userPointHistory[_addr][_idx].ts;\n    }\n\n    /**\n     * @notice Get timestamp when `_addr`'s lock finishes\n     * @param _addr User wallet\n     * @return Epoch time of the lock end\n     */\n    function unlockTime(address _addr) external view override returns (uint256) {\n        return locked[_addr].end;\n    }\n\n    function setMigrator(address _migrator) external override onlyOwner {\n        require(migrator == address(0), \"VE: MIGRATOR_SET\");\n\n        migrator = _migrator;\n\n        emit SetMigrator(_migrator);\n    }\n\n    function setDelegate(address account, bool _isDelegate) external override onlyOwner {\n        isDelegate[account] = _isDelegate;\n\n        emit SetDelegate(account, _isDelegate);\n    }\n\n    /**\n     * @notice Record global and per-user data to checkpoint\n     * @param addr User's wallet address. No user checkpoint if 0x0\n     * @param old_locked Pevious locked amount / end lock time for the user\n     * @param new_locked New locked amount / end lock time for the user\n     */\n    function _checkpoint(\n        address addr,\n        LockedBalance memory old_locked,\n        LockedBalance memory new_locked\n    ) internal {\n        Point memory u_old;\n        Point memory u_new;\n        int128 old_dslope;\n        int128 new_dslope;\n        uint256 _epoch = epoch;\n\n        if (addr != address(0)) {\n            // Calculate slopes and biases\n            // Kept at zero when they have to\n            if (old_locked.end > block.timestamp && old_locked.amount > 0) {\n                u_old.slope = old_locked.amount / maxDuration.toInt128();\n                u_old.bias = u_old.slope * (old_locked.end - block.timestamp).toInt128();\n            }\n            if (new_locked.end > block.timestamp && new_locked.amount > 0) {\n                u_new.slope = new_locked.amount / maxDuration.toInt128();\n                u_new.bias = u_new.slope * (new_locked.end - block.timestamp).toInt128();\n            }\n\n            // Read values of scheduled changes in the slope\n            // old_locked.end can be in the past and in the future\n            // new_locked.end can ONLY by in the FUTURE unless everything expired: than zeros\n            old_dslope = slopeChanges[old_locked.end];\n            if (new_locked.end != 0) {\n                if (new_locked.end == old_locked.end) new_dslope = old_dslope;\n                else new_dslope = slopeChanges[new_locked.end];\n            }\n        }\n\n        Point memory last_point = Point({bias: 0, slope: 0, ts: block.timestamp, blk: block.number});\n        if (_epoch > 0) last_point = pointHistory[_epoch];\n        uint256 last_checkpoint = last_point.ts;\n        // initial_last_point is used for extrapolation to calculate block number\n        // (approximately, for *At methods) and save them\n        // as we cannot figure that out exactly from inside the contract\n        Point memory initial_last_point = Point(last_point.bias, last_point.slope, last_point.ts, last_point.blk);\n        uint256 block_slope; // dblock/dt\n        if (block.timestamp > last_point.ts)\n            block_slope = (MULTIPLIER * (block.number - last_point.blk)) / (block.timestamp - last_point.ts);\n        // If last point is already recorded in this block, slope=0\n        // But that's ok b/c we know the block in such case\n\n        {\n            // Go over weeks to fill history and calculate what the current point is\n            uint256 t_i = (last_checkpoint / interval) * interval;\n            for (uint256 i; i < 255; i++) {\n                // Hopefully it won't happen that this won't get used in 5 years!\n                // If it does, users will be able to withdraw but vote weight will be broken\n                t_i += interval;\n                int128 d_slope;\n                if (t_i > block.timestamp) t_i = block.timestamp;\n                else d_slope = slopeChanges[t_i];\n                last_point.bias -= last_point.slope * (t_i - last_checkpoint).toInt128();\n                last_point.slope += d_slope;\n                if (last_point.bias < 0)\n                    // This can happen\n                    last_point.bias = 0;\n                if (last_point.slope < 0)\n                    // This cannot happen - just in case\n                    last_point.slope = 0;\n                last_checkpoint = t_i;\n                last_point.ts = t_i;\n                last_point.blk = initial_last_point.blk + (block_slope * (t_i - initial_last_point.ts)) / MULTIPLIER;\n                _epoch += 1;\n                if (t_i == block.timestamp) {\n                    last_point.blk = block.number;\n                    break;\n                } else pointHistory[_epoch] = last_point;\n            }\n        }\n\n        epoch = _epoch;\n        // Now point_history is filled until t=now\n\n        if (addr != address(0)) {\n            // If last point was in this block, the slope change has been applied already\n            // But in such case we have 0 slope(s)\n            last_point.slope += (u_new.slope - u_old.slope);\n            last_point.bias += (u_new.bias - u_old.bias);\n            if (last_point.slope < 0) last_point.slope = 0;\n            if (last_point.bias < 0) last_point.bias = 0;\n        }\n\n        // Record the changed point into history\n        pointHistory[_epoch] = last_point;\n\n        if (addr != address(0)) {\n            // Schedule the slope changes (slope is going down)\n            // We subtract new_user_slope from [new_locked.end]\n            // and add old_user_slope to [old_locked.end]\n            if (old_locked.end > block.timestamp) {\n                // old_dslope was <something> - u_old.slope, so we cancel that\n                old_dslope += u_old.slope;\n                if (new_locked.end == old_locked.end) old_dslope -= u_new.slope; // It was a new deposit, not extension\n                slopeChanges[old_locked.end] = old_dslope;\n            }\n\n            if (new_locked.end > block.timestamp) {\n                if (new_locked.end > old_locked.end) {\n                    new_dslope -= u_new.slope; // old slope disappeared at this point\n                    slopeChanges[new_locked.end] = new_dslope;\n                }\n                // else: we recorded it already in old_dslope\n            }\n\n            // Now handle user history\n            uint256 user_epoch = userPointEpoch[addr] + 1;\n\n            userPointEpoch[addr] = user_epoch;\n            u_new.ts = block.timestamp;\n            u_new.blk = block.number;\n            userPointHistory[addr][user_epoch] = u_new;\n        }\n    }\n\n    /**\n     * @notice Deposit and lock tokens for a user\n     * @param _addr User's wallet address\n     * @param _value Amount to deposit\n     * @param _discount Amount to get discounted out of _value\n     * @param unlock_time New time when to unlock the tokens, or 0 if unchanged\n     * @param locked_balance Previous locked amount / timestamp\n     */\n    function _depositFor(\n        address _addr,\n        uint256 _value,\n        uint256 _discount,\n        uint256 unlock_time,\n        LockedBalance memory locked_balance,\n        int128 _type\n    ) internal {\n        LockedBalance memory _locked = locked_balance;\n        uint256 supply_before = supply;\n\n        supply = supply_before + _value;\n        LockedBalance memory old_locked;\n        (old_locked.amount, old_locked.discount, old_locked.start, old_locked.end) = (\n            _locked.amount,\n            _locked.discount,\n            _locked.start,\n            _locked.end\n        );\n        // Adding to existing lock, or if a lock is expired - creating a new one\n        _locked.amount += (_value).toInt128();\n        if (_discount != 0) _locked.discount += _discount.toInt128();\n        if (unlock_time != 0) {\n            if (_locked.start == 0) _locked.start = block.timestamp;\n            _locked.end = unlock_time;\n        }\n        locked[_addr] = _locked;\n\n        // Possibilities:\n        // Both old_locked.end could be current or expired (>/< block.timestamp)\n        // value == 0 (extend lock) or value > 0 (add to lock or extend lock)\n        // _locked.end > block.timestamp (always)\n        _checkpoint(_addr, old_locked, _locked);\n\n        if (_value > _discount) {\n            IERC20(token).safeTransferFrom(_addr, address(this), _value - _discount);\n        }\n\n        emit Deposit(_addr, _value, _discount, _locked.end, _type, block.timestamp);\n        emit Supply(supply_before, supply_before + _value);\n    }\n\n    function _pushDelegate(address addr, address delegate) internal {\n        bool found;\n        address[] storage delegates = delegateAt[addr];\n        for (uint256 i; i < delegates.length; ) {\n            if (delegates[i] == delegate) found = true;\n            unchecked {\n                ++i;\n            }\n        }\n        if (!found) delegateAt[addr].push(delegate);\n    }\n\n    /**\n     * @notice Record global data to checkpoint\n     */\n    function checkpoint() external override {\n        _checkpoint(address(0), LockedBalance(0, 0, 0, 0), LockedBalance(0, 0, 0, 0));\n    }\n\n    /**\n     * @notice Deposit `_value` tokens for `_addr` and add to the lock\n     * @dev Anyone (even a smart contract) can deposit for someone else, but\n     *      cannot extend their locktime and deposit for a brand new user\n     * @param _addr User's wallet address\n     * @param _value Amount to add to user's lock\n     */\n    function depositFor(address _addr, uint256 _value) external override nonReentrant beforeMigrated(_addr) {\n        LockedBalance memory _locked = locked[_addr];\n\n        require(_value > 0, \"VE: INVALID_VALUE\");\n        require(_locked.amount > 0, \"VE: LOCK_NOT_FOUND\");\n        require(_locked.end > block.timestamp, \"VE: LOCK_EXPIRED\");\n\n        _depositFor(_addr, _value, 0, 0, _locked, DEPOSIT_FOR_TYPE);\n    }\n\n    /**\n     * @notice Deposit `_value` tokens with `_discount` for `_addr` and lock for `_duration`\n     * @dev Only delegates can creat a lock for someone else\n     * @param _addr User's wallet address\n     * @param _value Amount to add to user's lock\n     * @param _discount Amount to get discounted out of _value\n     * @param _duration Epoch time until tokens unlock from now\n     */\n    function createLockFor(\n        address _addr,\n        uint256 _value,\n        uint256 _discount,\n        uint256 _duration\n    ) external override nonReentrant onlyDelegate beforeMigrated(_addr) {\n        _pushDelegate(_addr, msg.sender);\n\n        uint256 unlock_time = ((block.timestamp + _duration) / interval) * interval; // Locktime is rounded down to a multiple of interval\n        LockedBalance memory _locked = locked[_addr];\n\n        require(_value > 0, \"VE: INVALID_VALUE\");\n        require(_value >= _discount, \"VE: DISCOUNT_TOO_HIGH\");\n        require(_locked.amount == 0, \"VE: EXISTING_LOCK_FOUND\");\n        require(unlock_time > block.timestamp, \"VE: UNLOCK_TIME_TOO_EARLY\");\n        require(unlock_time <= block.timestamp + maxDuration, \"VE: UNLOCK_TIME_TOO_LATE\");\n\n        _depositFor(_addr, _value, _discount, unlock_time, _locked, CRETE_LOCK_TYPE);\n    }\n\n    /**\n     * @notice Deposit `_value` tokens for `msg.sender` and lock for `_duration`\n     * @param _value Amount to deposit\n     * @param _duration Epoch time until tokens unlock from now\n     */\n    function createLock(uint256 _value, uint256 _duration)\n        external\n        override\n        nonReentrant\n        authorized\n        beforeMigrated(msg.sender)\n    {\n        uint256 unlock_time = ((block.timestamp + _duration) / interval) * interval; // Locktime is rounded down to a multiple of interval\n        LockedBalance memory _locked = locked[msg.sender];\n\n        require(_value > 0, \"VE: INVALID_VALUE\");\n        require(_locked.amount == 0, \"VE: EXISTING_LOCK_FOUND\");\n        require(unlock_time > block.timestamp, \"VE: UNLOCK_TIME_TOO_EARLY\");\n        require(unlock_time <= block.timestamp + maxDuration, \"VE: UNLOCK_TIME_TOO_LATE\");\n\n        _depositFor(msg.sender, _value, 0, unlock_time, _locked, CRETE_LOCK_TYPE);\n    }\n\n    /**\n     * @notice Deposit `_value` additional tokens for `msg.sender`\n     *          without modifying the unlock time\n     * @param _addr User's wallet address\n     * @param _value Amount of tokens to deposit and add to the lock\n     * @param _discount Amount to get discounted out of _value\n     */\n    function increaseAmountFor(\n        address _addr,\n        uint256 _value,\n        uint256 _discount\n    ) external override nonReentrant onlyDelegate beforeMigrated(_addr) {\n        _pushDelegate(_addr, msg.sender);\n\n        LockedBalance memory _locked = locked[_addr];\n\n        require(_value > 0, \"VE: INVALID_VALUE\");\n        require(_value >= _discount, \"VE: DISCOUNT_TOO_HIGH\");\n        require(_locked.amount > 0, \"VE: LOCK_NOT_FOUND\");\n        require(_locked.end > block.timestamp, \"VE: LOCK_EXPIRED\");\n\n        _depositFor(_addr, _value, _discount, 0, _locked, INCREASE_LOCK_AMOUNT);\n    }\n\n    /**\n     * @notice Deposit `_value` additional tokens for `msg.sender`\n     *          without modifying the unlock time\n     * @param _value Amount of tokens to deposit and add to the lock\n     */\n    function increaseAmount(uint256 _value) external override nonReentrant authorized beforeMigrated(msg.sender) {\n        LockedBalance memory _locked = locked[msg.sender];\n\n        require(_value > 0, \"VE: INVALID_VALUE\");\n        require(_locked.amount > 0, \"VE: LOCK_NOT_FOUND\");\n        require(_locked.end > block.timestamp, \"VE: LOCK_EXPIRED\");\n\n        _depositFor(msg.sender, _value, 0, 0, _locked, INCREASE_LOCK_AMOUNT);\n    }\n\n    /**\n     * @notice Extend the unlock time for `msg.sender` to `_duration`\n     * @param _duration Increased epoch time for unlocking\n     */\n    function increaseUnlockTime(uint256 _duration)\n        external\n        override\n        nonReentrant\n        authorized\n        beforeMigrated(msg.sender)\n    {\n        LockedBalance memory _locked = locked[msg.sender];\n        uint256 unlock_time = ((_locked.end + _duration) / interval) * interval; // Locktime is rounded down to a multiple of interval\n\n        require(_locked.end > block.timestamp, \"VE: LOCK_EXPIRED\");\n        require(_locked.amount > 0, \"VE: LOCK_NOT_FOUND\");\n        require(_locked.discount == 0, \"VE: LOCK_DISCOUNTED\");\n        require(unlock_time >= _locked.end + interval, \"VE: UNLOCK_TIME_TOO_EARLY\");\n        require(unlock_time <= block.timestamp + maxDuration, \"VE: UNLOCK_TIME_TOO_LATE\");\n\n        _depositFor(msg.sender, 0, 0, unlock_time, _locked, INCREASE_UNLOCK_TIME);\n    }\n\n    /**\n     * @notice Cancel the existing lock of `msg.sender` with penalty\n     * @dev Only possible if the lock exists\n     */\n    function cancel() external override nonReentrant {\n        LockedBalance memory _locked = locked[msg.sender];\n        require(_locked.amount > 0, \"VE: LOCK_NOT_FOUND\");\n        require(_locked.end > block.timestamp, \"VE: LOCK_EXPIRED\");\n\n        uint256 penaltyRate = _penaltyRate(_locked.start, _locked.end);\n        uint256 supply_before = _clear(_locked, penaltyRate);\n\n        uint256 value = _locked.amount.toUint256();\n        uint256 discount = _locked.discount.toUint256();\n\n        IERC20(token).safeTransfer(msg.sender, ((value - discount) * (1e18 - penaltyRate)) / 1e18);\n\n        emit Cancel(msg.sender, value, discount, penaltyRate, block.timestamp);\n        emit Supply(supply_before, supply_before - value);\n    }\n\n    function _penaltyRate(uint256 start, uint256 end) internal view returns (uint256 penalty) {\n        penalty = (1e18 * (end - block.timestamp)) / (end - start);\n        if (penalty < 1e18 / 2) penalty = 1e18 / 2;\n    }\n\n    /**\n     * @notice Withdraw all tokens for `msg.sender`\n     * @dev Only possible if the lock has expired\n     */\n    function withdraw() external override nonReentrant {\n        LockedBalance memory _locked = locked[msg.sender];\n        require(block.timestamp >= _locked.end, \"VE: LOCK_NOT_EXPIRED\");\n\n        uint256 supply_before = _clear(_locked, 0);\n\n        uint256 value = _locked.amount.toUint256();\n        uint256 discount = _locked.discount.toUint256();\n\n        if (value > discount) {\n            IERC20(token).safeTransfer(msg.sender, value - discount);\n        }\n\n        emit Withdraw(msg.sender, value, discount, block.timestamp);\n        emit Supply(supply_before, supply_before - value);\n    }\n\n    function migrate() external override nonReentrant beforeMigrated(msg.sender) {\n        require(migrator != address(0), \"VE: MIGRATOR_NOT_SET\");\n\n        LockedBalance memory _locked = locked[msg.sender];\n        require(_locked.amount > 0, \"VE: LOCK_NOT_FOUND\");\n        require(_locked.end > block.timestamp, \"VE: LOCK_EXPIRED\");\n\n        address[] memory delegates = delegateAt[msg.sender];\n        uint256 supply_before = _clear(_locked, 0);\n\n        uint256 value = _locked.amount.toUint256();\n        uint256 discount = _locked.discount.toUint256();\n\n        IVotingEscrowMigrator(migrator).migrate(\n            msg.sender,\n            _locked.amount,\n            _locked.discount,\n            _locked.start,\n            _locked.end,\n            delegates\n        );\n        migrated[msg.sender] = true;\n\n        if (value > discount) {\n            IERC20(token).safeTransfer(migrator, value - discount);\n        }\n\n        emit Migrate(msg.sender, value, discount, block.timestamp);\n        emit Supply(supply_before, supply_before - value);\n    }\n\n    function _clear(LockedBalance memory _locked, uint256 penaltyRate) internal returns (uint256 supply_before) {\n        uint256 value = _locked.amount.toUint256();\n\n        locked[msg.sender] = LockedBalance(0, 0, 0, 0);\n        supply_before = supply;\n        supply = supply_before - value;\n\n        // old_locked can have either expired <= timestamp or zero end\n        // _locked has only 0 end\n        // Both can have >= 0 amount\n        _checkpoint(msg.sender, _locked, LockedBalance(0, 0, 0, 0));\n\n        address[] storage delegates = delegateAt[msg.sender];\n        for (uint256 i; i < delegates.length; ) {\n            IVotingEscrowDelegate(delegates[i]).withdraw(msg.sender, penaltyRate);\n            unchecked {\n                ++i;\n            }\n        }\n        delete delegateAt[msg.sender];\n    }\n\n    // The following ERC20/minime-compatible methods are not real balanceOf and supply!\n    // They measure the weights for the purpose of voting, so they don't represent\n    // real coins.\n\n    /**\n     * @notice Binary search to estimate timestamp for block number\n     * @param _block Block to find\n     * @param max_epoch Don't go beyond this epoch\n     * @return Approximate timestamp for block\n     */\n    function _findBlockEpoch(uint256 _block, uint256 max_epoch) internal view returns (uint256) {\n        uint256 _min;\n        uint256 _max = max_epoch;\n        for (uint256 i; i < 128; i++) {\n            if (_min >= _max) break;\n            uint256 _mid = (_min + _max + 1) / 2;\n            if (pointHistory[_mid].blk <= _block) _min = _mid;\n            else _max = _mid - 1;\n        }\n        return _min;\n    }\n\n    function balanceOf(address addr) public view override returns (uint256) {\n        return balanceOf(addr, block.timestamp);\n    }\n\n    /**\n     * @notice Get the current voting power for `msg.sender`\n     * @dev Adheres to the ERC20 `balanceOf` interface for Aragon compatibility\n     * @param addr User wallet address\n     * @param _t Epoch time to return voting power at\n     * @return User voting power\n     */\n    function balanceOf(address addr, uint256 _t) public view override returns (uint256) {\n        uint256 _epoch = userPointEpoch[addr];\n        if (_epoch == 0) return 0;\n        else {\n            Point memory last_point = userPointHistory[addr][_epoch];\n            last_point.bias -= last_point.slope * (_t - last_point.ts).toInt128();\n            if (last_point.bias < 0) last_point.bias = 0;\n            return last_point.bias.toUint256();\n        }\n    }\n\n    /**\n     * @notice Measure voting power of `addr` at block height `_block`\n     * @dev Adheres to MiniMe `balanceOfAt` interface: https://github.com/Giveth/minime\n     * @param addr User's wallet address\n     * @param _block Block to calculate the voting power at\n     * @return Voting power\n     */\n    function balanceOfAt(address addr, uint256 _block) external view override returns (uint256) {\n        // Copying and pasting totalSupply code because Vyper cannot pass by\n        // reference yet\n        require(_block <= block.number);\n\n        // Binary search\n        uint256 _min;\n        uint256 _max = userPointEpoch[addr];\n        for (uint256 i; i < 128; i++) {\n            if (_min >= _max) break;\n            uint256 _mid = (_min + _max + 1) / 2;\n            if (userPointHistory[addr][_mid].blk <= _block) _min = _mid;\n            else _max = _mid - 1;\n        }\n\n        Point memory upoint = userPointHistory[addr][_min];\n\n        uint256 max_epoch = epoch;\n        uint256 _epoch = _findBlockEpoch(_block, max_epoch);\n        Point memory point_0 = pointHistory[_epoch];\n        uint256 d_block;\n        uint256 d_t;\n        if (_epoch < max_epoch) {\n            Point memory point_1 = pointHistory[_epoch + 1];\n            d_block = point_1.blk - point_0.blk;\n            d_t = point_1.ts - point_0.ts;\n        } else {\n            d_block = block.number - point_0.blk;\n            d_t = block.timestamp - point_0.ts;\n        }\n        uint256 block_time = point_0.ts;\n        if (d_block != 0) block_time += ((d_t * (_block - point_0.blk)) / d_block);\n\n        upoint.bias -= upoint.slope * (block_time - upoint.ts).toInt128();\n        if (upoint.bias >= 0) return upoint.bias.toUint256();\n        else return 0;\n    }\n\n    /**\n     * @notice Calculate total voting power at some point in the past\n     * @param point The point (bias/slope) to start search from\n     * @param t Time to calculate the total voting power at\n     * @return Total voting power at that time\n     */\n    function _supplyAt(Point memory point, uint256 t) internal view returns (uint256) {\n        Point memory last_point = point;\n        uint256 t_i = (last_point.ts / interval) * interval;\n        for (uint256 i; i < 255; i++) {\n            t_i += interval;\n            int128 d_slope;\n            if (t_i > t) t_i = t;\n            else d_slope = slopeChanges[t_i];\n            last_point.bias -= last_point.slope * (t_i - last_point.ts).toInt128();\n            if (t_i == t) break;\n            last_point.slope += d_slope;\n            last_point.ts = t_i;\n        }\n\n        if (last_point.bias < 0) last_point.bias = 0;\n        return last_point.bias.toUint256();\n    }\n\n    function totalSupply() public view override returns (uint256) {\n        return totalSupply(block.timestamp);\n    }\n\n    /**\n     * @notice Calculate total voting power\n     * @dev Adheres to the ERC20 `totalSupply` interface for Aragon compatibility\n     * @return Total voting power\n     */\n    function totalSupply(uint256 t) public view override returns (uint256) {\n        uint256 _epoch = epoch;\n        Point memory last_point = pointHistory[_epoch];\n        return _supplyAt(last_point, t);\n    }\n\n    /**\n     * @notice Calculate total voting power at some point in the past\n     * @param _block Block to calculate the total voting power at\n     * @return Total voting power at `_block`\n     */\n    function totalSupplyAt(uint256 _block) external view override returns (uint256) {\n        require(_block <= block.number);\n        uint256 _epoch = epoch;\n        uint256 target_epoch = _findBlockEpoch(_block, _epoch);\n\n        Point memory point = pointHistory[target_epoch];\n        uint256 dt;\n        if (target_epoch < _epoch) {\n            Point memory point_next = pointHistory[target_epoch + 1];\n            if (point.blk != point_next.blk)\n                dt = ((_block - point.blk) * (point_next.ts - point.ts)) / (point_next.blk - point.blk);\n        } else if (point.blk != block.number)\n            dt = ((_block - point.blk) * (block.timestamp - point.ts)) / (block.number - point.blk);\n        // Now dt contains info on how far are we beyond point\n\n        return _supplyAt(point, point.ts + dt);\n    }\n}\n"
    },
    "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC20.sol\";\n\n/**\n * @dev Interface for the optional metadata functions from the ERC20 standard.\n *\n * _Available since v4.1._\n */\ninterface IERC20Metadata is IERC20 {\n    /**\n     * @dev Returns the name of the token.\n     */\n    function name() external view returns (string memory);\n\n    /**\n     * @dev Returns the symbol of the token.\n     */\n    function symbol() external view returns (string memory);\n\n    /**\n     * @dev Returns the decimals places of the token.\n     */\n    function decimals() external view returns (uint8);\n}\n"
    },
    "contracts/interfaces/IVotingEscrowMigrator.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity ^0.8.0;\n\ninterface IVotingEscrowMigrator {\n    function migrate(\n        address account,\n        int128 amount,\n        int128 discount,\n        uint256 start,\n        uint256 end,\n        address[] calldata delegates\n    ) external;\n}\n"
    },
    "contracts/interfaces/IVotingEscrowDelegate.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity ^0.8.0;\n\ninterface IVotingEscrowDelegate {\n    event Withdraw(address indexed addr, uint256 amount, uint256 penaltyRate);\n\n    function withdraw(address addr, uint256 penaltyRate) external;\n}\n"
    },
    "contracts/mocks/VotingEscrowMigratorMock.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity ^0.8.15;\n\nimport \"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol\";\nimport \"../interfaces/IVotingEscrow.sol\";\nimport \"../interfaces/IVotingEscrowMigrator.sol\";\nimport \"../libraries/Integers.sol\";\n\ncontract VotingEscrowMigratorMock is IVotingEscrowMigrator {\n    using SafeERC20 for IERC20;\n    using Integers for int128;\n    using Integers for uint256;\n\n    struct LockedBalance {\n        int128 amount;\n        int128 discount;\n        uint256 start;\n        uint256 end;\n    }\n\n    address public immutable token;\n    mapping(address => LockedBalance) public locked;\n    mapping(address => address[]) public delegates;\n\n    constructor(address ve) {\n        token = IVotingEscrow(ve).token();\n    }\n\n    function migrate(\n        address account,\n        int128 amount,\n        int128 discount,\n        uint256 start,\n        uint256 end,\n        address[] calldata _delegates\n    ) external override {\n        locked[account] = LockedBalance(amount, discount, start, end);\n        delegates[account] = _delegates;\n    }\n\n    function withdraw() external {\n        LockedBalance memory _locked = locked[msg.sender];\n        require(block.timestamp >= _locked.end, \"VE: LOCK_NOT_EXPIRED\");\n\n        uint256 value = _locked.amount.toUint256();\n        uint256 discount = _locked.discount.toUint256();\n\n        locked[msg.sender] = LockedBalance(0, 0, 0, 0);\n\n        if (value > discount) {\n            IERC20(token).safeTransfer(msg.sender, value - discount);\n        }\n    }\n}\n"
    },
    "contracts/LPVotingEscrowDelegate.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity ^0.8.15;\n\nimport \"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol\";\nimport \"./interfaces/IUniswapV2Pair.sol\";\nimport \"./VotingEscrowDelegate.sol\";\nimport \"./interfaces/IVotingEscrowMigrator.sol\";\n\ncontract LPVotingEscrowDelegate is VotingEscrowDelegate {\n    using SafeERC20 for IERC20;\n\n    struct LockedBalance {\n        uint256 amount;\n        uint256 end;\n    }\n\n    bool internal immutable isToken1;\n    uint256 public immutable minAmount;\n    uint256 public immutable maxBoost;\n\n    uint256 public lockedTotal;\n    mapping(address => uint256) public locked;\n\n    constructor(\n        address _ve,\n        address _lpToken,\n        address _discountToken,\n        bool _isToken1,\n        uint256 _minAmount,\n        uint256 _maxBoost\n    ) VotingEscrowDelegate(_ve, _lpToken, _discountToken) {\n        isToken1 = _isToken1;\n        minAmount = _minAmount;\n        maxBoost = _maxBoost;\n    }\n\n    function _createLock(\n        uint256 amount,\n        uint256 duration,\n        bool discounted\n    ) internal override {\n        require(amount >= minAmount, \"LSVED: AMOUNT_TOO_LOW\");\n\n        super._createLock(amount, duration, discounted);\n\n        lockedTotal += amount;\n        locked[msg.sender] += amount;\n        IERC20(token).safeTransferFrom(msg.sender, address(this), amount);\n    }\n\n    function _increaseAmount(uint256 amount, bool discounted) internal override {\n        require(amount >= minAmount, \"LSVED: AMOUNT_TOO_LOW\");\n\n        super._increaseAmount(amount, discounted);\n\n        lockedTotal += amount;\n        locked[msg.sender] += amount;\n        IERC20(token).safeTransferFrom(msg.sender, address(this), amount);\n    }\n\n    function _getAmounts(uint256 amount, uint256)\n        internal\n        view\n        override\n        returns (uint256 amountVE, uint256 amountToken)\n    {\n        (uint112 reserve0, uint112 reserve1, ) = IUniswapV2Pair(token).getReserves();\n        uint256 reserve = isToken1 ? uint256(reserve1) : uint256(reserve0);\n\n        uint256 totalSupply = IUniswapV2Pair(token).totalSupply();\n        uint256 _amountToken = (amount * reserve) / totalSupply;\n\n        amountVE = _amountToken + (_amountToken * maxBoost * (totalSupply - lockedTotal)) / totalSupply / totalSupply;\n        uint256 upperBound = (_amountToken * 333) / 10;\n        if (amountVE > upperBound) {\n            amountVE = upperBound;\n        }\n        amountToken = 0;\n    }\n\n    function withdraw(address addr, uint256 penaltyRate) external override {\n        require(msg.sender == ve, \"LSVED: FORBIDDEN\");\n\n        uint256 amount = locked[addr];\n        require(amount > 0, \"LSVED: LOCK_NOT_FOUND\");\n\n        lockedTotal -= amount;\n        locked[addr] = 0;\n        IERC20(token).safeTransfer(addr, (amount * (1e18 - penaltyRate)) / 1e18);\n\n        emit Withdraw(addr, amount, penaltyRate);\n    }\n}\n"
    },
    "contracts/interfaces/IUniswapV2Pair.sol": {
      "content": "// SPDX-License-Identifier: GPL-3.0\n\npragma solidity >=0.5.0;\n\ninterface IUniswapV2Pair {\n    event Approval(address indexed owner, address indexed spender, uint value);\n    event Transfer(address indexed from, address indexed to, uint value);\n\n    function name() external pure returns (string memory);\n    function symbol() external pure returns (string memory);\n    function decimals() external pure returns (uint8);\n    function totalSupply() external view returns (uint);\n    function balanceOf(address owner) external view returns (uint);\n    function allowance(address owner, address spender) external view returns (uint);\n\n    function approve(address spender, uint value) external returns (bool);\n    function transfer(address to, uint value) external returns (bool);\n    function transferFrom(address from, address to, uint value) external returns (bool);\n\n    function DOMAIN_SEPARATOR() external view returns (bytes32);\n    function PERMIT_TYPEHASH() external pure returns (bytes32);\n    function nonces(address owner) external view returns (uint);\n\n    function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;\n\n    event Mint(address indexed sender, uint amount0, uint amount1);\n    event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);\n    event Swap(\n        address indexed sender,\n        uint amount0In,\n        uint amount1In,\n        uint amount0Out,\n        uint amount1Out,\n        address indexed to\n    );\n    event Sync(uint112 reserve0, uint112 reserve1);\n\n    function MINIMUM_LIQUIDITY() external pure returns (uint);\n    function factory() external view returns (address);\n    function token0() external view returns (address);\n    function token1() external view returns (address);\n    function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);\n    function price0CumulativeLast() external view returns (uint);\n    function price1CumulativeLast() external view returns (uint);\n    function kLast() external view returns (uint);\n\n    function mint(address to) external returns (uint liquidity);\n    function burn(address to) external returns (uint amount0, uint amount1);\n    function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;\n    function skim(address to) external;\n    function sync() external;\n\n    function initialize(address, address) external;\n}\n"
    },
    "contracts/VotingEscrowDelegate.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity ^0.8.15;\n\nimport \"./interfaces/IVotingEscrowDelegate.sol\";\nimport \"./interfaces/IVotingEscrow.sol\";\nimport \"./interfaces/INFT.sol\";\n\nabstract contract VotingEscrowDelegate is IVotingEscrowDelegate {\n    address public immutable ve;\n    address public immutable token;\n    address public immutable discountToken;\n\n    uint256 internal immutable _maxDuration;\n    uint256 internal immutable _interval;\n\n    event CreateLock(address indexed account, uint256 amount, uint256 discount, uint256 indexed locktime);\n    event IncreaseAmount(address indexed account, uint256 amount, uint256 discount);\n\n    constructor(\n        address _ve,\n        address _token,\n        address _discountToken\n    ) {\n        ve = _ve;\n        token = _token;\n        discountToken = _discountToken;\n\n        _maxDuration = IVotingEscrow(_ve).maxDuration();\n        _interval = IVotingEscrow(ve).interval();\n    }\n\n    modifier eligibleForDiscount {\n        require(INFT(discountToken).balanceOf(msg.sender) > 0, \"VED: DISCOUNT_TOKEN_NOT_OWNED\");\n        _;\n    }\n\n    function createLockDiscounted(uint256 amount, uint256 duration) external eligibleForDiscount {\n        _createLock(amount, duration, true);\n    }\n\n    function createLock(uint256 amount, uint256 duration) external {\n        _createLock(amount, duration, false);\n    }\n\n    function _createLock(\n        uint256 amount,\n        uint256 duration,\n        bool discounted\n    ) internal virtual {\n        require(duration <= _maxDuration, \"VED: DURATION_TOO_LONG\");\n\n        uint256 unlockTime = ((block.timestamp + duration) / _interval) * _interval; // rounded down to a multiple of interval\n        uint256 _duration = unlockTime - block.timestamp;\n        (uint256 amountVE, uint256 amountToken) = _getAmounts(amount, _duration);\n        if (discounted) {\n            amountVE = (amountVE * 100) / 90;\n        }\n\n        emit CreateLock(msg.sender, amountVE, amountVE - amountToken, unlockTime);\n        IVotingEscrow(ve).createLockFor(msg.sender, amountVE, amountVE - amountToken, _duration);\n    }\n\n    function increaseAmountDiscounted(uint256 amount) external eligibleForDiscount {\n        _increaseAmount(amount, true);\n    }\n\n    function increaseAmount(uint256 amount) external {\n        _increaseAmount(amount, false);\n    }\n\n    function _increaseAmount(uint256 amount, bool discounted) internal virtual {\n        uint256 unlockTime = IVotingEscrow(ve).unlockTime(msg.sender);\n        require(unlockTime > 0, \"VED: LOCK_NOT_FOUND\");\n\n        (uint256 amountVE, uint256 amountToken) = _getAmounts(amount, unlockTime - block.timestamp);\n        if (discounted) {\n            amountVE = (amountVE * 100) / 90;\n        }\n\n        emit IncreaseAmount(msg.sender, amountVE, amountVE - amountToken);\n        IVotingEscrow(ve).increaseAmountFor(msg.sender, amountVE, amountVE - amountToken);\n    }\n\n    function _getAmounts(uint256 amount, uint256 duration)\n        internal\n        view\n        virtual\n        returns (uint256 amountVE, uint256 amountToken);\n\n    function withdraw(address, uint256) external virtual override {\n        // Empty\n    }\n}\n"
    },
    "contracts/interfaces/INFT.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity ^0.8.0;\n\ninterface INFT {\n    function balanceOf(address owner) external view returns (uint256 balance);\n\n    function safeTransferFrom(\n        address from,\n        address to,\n        uint256 tokenId\n    ) external;\n\n    function mint(\n        address to,\n        uint256 tokenId,\n        bytes calldata data\n    ) external;\n\n    function mintBatch(\n        address to,\n        uint256[] calldata tokenIds,\n        bytes calldata data\n    ) external;\n\n    function burn(\n        uint256 tokenId,\n        uint256 label,\n        bytes32 data\n    ) external;\n}\n"
    },
    "contracts/mocks/NFTMock.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED\n\npragma solidity ^0.8.15;\n\nimport \"@openzeppelin/contracts/token/ERC721/ERC721.sol\";\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\n\nimport \"../interfaces/INFT.sol\";\n\ncontract NFTMock is ERC721, Ownable, INFT {\n    constructor(string memory name_, string memory symbol_) ERC721(name_, symbol_) {\n        // Empty\n    }\n\n    function balanceOf(address owner) public view override(ERC721, INFT) returns (uint256 balance) {\n        return ERC721.balanceOf(owner);\n    }\n\n    function safeTransferFrom(\n        address from,\n        address to,\n        uint256 tokenId\n    ) public override(ERC721, INFT) {\n        ERC721.safeTransferFrom(from, to, tokenId);\n    }\n\n    function mint(\n        address to,\n        uint256 tokenId,\n        bytes calldata data\n    ) external override onlyOwner {\n        _safeMint(to, tokenId, data);\n    }\n\n    function mintBatch(\n        address to,\n        uint256[] calldata tokenIds,\n        bytes calldata data\n    ) external override onlyOwner {\n        for (uint256 i; i < tokenIds.length; i++) {\n            _safeMint(to, tokenIds[i], data);\n        }\n    }\n\n    function burn(\n        uint256 tokenId,\n        uint256,\n        bytes32\n    ) external override {\n        _burn(tokenId);\n    }\n}\n"
    },
    "@openzeppelin/contracts/token/ERC20/ERC20.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/ERC20.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IERC20.sol\";\nimport \"./extensions/IERC20Metadata.sol\";\nimport \"../../utils/Context.sol\";\n\n/**\n * @dev Implementation of the {IERC20} interface.\n *\n * This implementation is agnostic to the way tokens are created. This means\n * that a supply mechanism has to be added in a derived contract using {_mint}.\n * For a generic mechanism see {ERC20PresetMinterPauser}.\n *\n * TIP: For a detailed writeup see our guide\n * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How\n * to implement supply mechanisms].\n *\n * We have followed general OpenZeppelin Contracts guidelines: functions revert\n * instead returning `false` on failure. This behavior is nonetheless\n * conventional and does not conflict with the expectations of ERC20\n * applications.\n *\n * Additionally, an {Approval} event is emitted on calls to {transferFrom}.\n * This allows applications to reconstruct the allowance for all accounts just\n * by listening to said events. Other implementations of the EIP may not emit\n * these events, as it isn't required by the specification.\n *\n * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}\n * functions have been added to mitigate the well-known issues around setting\n * allowances. See {IERC20-approve}.\n */\ncontract ERC20 is Context, IERC20, IERC20Metadata {\n    mapping(address => uint256) private _balances;\n\n    mapping(address => mapping(address => uint256)) private _allowances;\n\n    uint256 private _totalSupply;\n\n    string private _name;\n    string private _symbol;\n\n    /**\n     * @dev Sets the values for {name} and {symbol}.\n     *\n     * The default value of {decimals} is 18. To select a different value for\n     * {decimals} you should overload it.\n     *\n     * All two of these values are immutable: they can only be set once during\n     * construction.\n     */\n    constructor(string memory name_, string memory symbol_) {\n        _name = name_;\n        _symbol = symbol_;\n    }\n\n    /**\n     * @dev Returns the name of the token.\n     */\n    function name() public view virtual override returns (string memory) {\n        return _name;\n    }\n\n    /**\n     * @dev Returns the symbol of the token, usually a shorter version of the\n     * name.\n     */\n    function symbol() public view virtual override returns (string memory) {\n        return _symbol;\n    }\n\n    /**\n     * @dev Returns the number of decimals used to get its user representation.\n     * For example, if `decimals` equals `2`, a balance of `505` tokens should\n     * be displayed to a user as `5.05` (`505 / 10 ** 2`).\n     *\n     * Tokens usually opt for a value of 18, imitating the relationship between\n     * Ether and Wei. This is the value {ERC20} uses, unless this function is\n     * overridden;\n     *\n     * NOTE: This information is only used for _display_ purposes: it in\n     * no way affects any of the arithmetic of the contract, including\n     * {IERC20-balanceOf} and {IERC20-transfer}.\n     */\n    function decimals() public view virtual override returns (uint8) {\n        return 18;\n    }\n\n    /**\n     * @dev See {IERC20-totalSupply}.\n     */\n    function totalSupply() public view virtual override returns (uint256) {\n        return _totalSupply;\n    }\n\n    /**\n     * @dev See {IERC20-balanceOf}.\n     */\n    function balanceOf(address account) public view virtual override returns (uint256) {\n        return _balances[account];\n    }\n\n    /**\n     * @dev See {IERC20-transfer}.\n     *\n     * Requirements:\n     *\n     * - `to` cannot be the zero address.\n     * - the caller must have a balance of at least `amount`.\n     */\n    function transfer(address to, uint256 amount) public virtual override returns (bool) {\n        address owner = _msgSender();\n        _transfer(owner, to, amount);\n        return true;\n    }\n\n    /**\n     * @dev See {IERC20-allowance}.\n     */\n    function allowance(address owner, address spender) public view virtual override returns (uint256) {\n        return _allowances[owner][spender];\n    }\n\n    /**\n     * @dev See {IERC20-approve}.\n     *\n     * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on\n     * `transferFrom`. This is semantically equivalent to an infinite approval.\n     *\n     * Requirements:\n     *\n     * - `spender` cannot be the zero address.\n     */\n    function approve(address spender, uint256 amount) public virtual override returns (bool) {\n        address owner = _msgSender();\n        _approve(owner, spender, amount);\n        return true;\n    }\n\n    /**\n     * @dev See {IERC20-transferFrom}.\n     *\n     * Emits an {Approval} event indicating the updated allowance. This is not\n     * required by the EIP. See the note at the beginning of {ERC20}.\n     *\n     * NOTE: Does not update the allowance if the current allowance\n     * is the maximum `uint256`.\n     *\n     * Requirements:\n     *\n     * - `from` and `to` cannot be the zero address.\n     * - `from` must have a balance of at least `amount`.\n     * - the caller must have allowance for ``from``'s tokens of at least\n     * `amount`.\n     */\n    function transferFrom(\n        address from,\n        address to,\n        uint256 amount\n    ) public virtual override returns (bool) {\n        address spender = _msgSender();\n        _spendAllowance(from, spender, amount);\n        _transfer(from, to, amount);\n        return true;\n    }\n\n    /**\n     * @dev Atomically increases the allowance granted to `spender` by the caller.\n     *\n     * This is an alternative to {approve} that can be used as a mitigation for\n     * problems described in {IERC20-approve}.\n     *\n     * Emits an {Approval} event indicating the updated allowance.\n     *\n     * Requirements:\n     *\n     * - `spender` cannot be the zero address.\n     */\n    function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {\n        address owner = _msgSender();\n        _approve(owner, spender, allowance(owner, spender) + addedValue);\n        return true;\n    }\n\n    /**\n     * @dev Atomically decreases the allowance granted to `spender` by the caller.\n     *\n     * This is an alternative to {approve} that can be used as a mitigation for\n     * problems described in {IERC20-approve}.\n     *\n     * Emits an {Approval} event indicating the updated allowance.\n     *\n     * Requirements:\n     *\n     * - `spender` cannot be the zero address.\n     * - `spender` must have allowance for the caller of at least\n     * `subtractedValue`.\n     */\n    function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {\n        address owner = _msgSender();\n        uint256 currentAllowance = allowance(owner, spender);\n        require(currentAllowance >= subtractedValue, \"ERC20: decreased allowance below zero\");\n        unchecked {\n            _approve(owner, spender, currentAllowance - subtractedValue);\n        }\n\n        return true;\n    }\n\n    /**\n     * @dev Moves `amount` of tokens from `sender` to `recipient`.\n     *\n     * This internal function is equivalent to {transfer}, and can be used to\n     * e.g. implement automatic token fees, slashing mechanisms, etc.\n     *\n     * Emits a {Transfer} event.\n     *\n     * Requirements:\n     *\n     * - `from` cannot be the zero address.\n     * - `to` cannot be the zero address.\n     * - `from` must have a balance of at least `amount`.\n     */\n    function _transfer(\n        address from,\n        address to,\n        uint256 amount\n    ) internal virtual {\n        require(from != address(0), \"ERC20: transfer from the zero address\");\n        require(to != address(0), \"ERC20: transfer to the zero address\");\n\n        _beforeTokenTransfer(from, to, amount);\n\n        uint256 fromBalance = _balances[from];\n        require(fromBalance >= amount, \"ERC20: transfer amount exceeds balance\");\n        unchecked {\n            _balances[from] = fromBalance - amount;\n        }\n        _balances[to] += amount;\n\n        emit Transfer(from, to, amount);\n\n        _afterTokenTransfer(from, to, amount);\n    }\n\n    /** @dev Creates `amount` tokens and assigns them to `account`, increasing\n     * the total supply.\n     *\n     * Emits a {Transfer} event with `from` set to the zero address.\n     *\n     * Requirements:\n     *\n     * - `account` cannot be the zero address.\n     */\n    function _mint(address account, uint256 amount) internal virtual {\n        require(account != address(0), \"ERC20: mint to the zero address\");\n\n        _beforeTokenTransfer(address(0), account, amount);\n\n        _totalSupply += amount;\n        _balances[account] += amount;\n        emit Transfer(address(0), account, amount);\n\n        _afterTokenTransfer(address(0), account, amount);\n    }\n\n    /**\n     * @dev Destroys `amount` tokens from `account`, reducing the\n     * total supply.\n     *\n     * Emits a {Transfer} event with `to` set to the zero address.\n     *\n     * Requirements:\n     *\n     * - `account` cannot be the zero address.\n     * - `account` must have at least `amount` tokens.\n     */\n    function _burn(address account, uint256 amount) internal virtual {\n        require(account != address(0), \"ERC20: burn from the zero address\");\n\n        _beforeTokenTransfer(account, address(0), amount);\n\n        uint256 accountBalance = _balances[account];\n        require(accountBalance >= amount, \"ERC20: burn amount exceeds balance\");\n        unchecked {\n            _balances[account] = accountBalance - amount;\n        }\n        _totalSupply -= amount;\n\n        emit Transfer(account, address(0), amount);\n\n        _afterTokenTransfer(account, address(0), amount);\n    }\n\n    /**\n     * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.\n     *\n     * This internal function is equivalent to `approve`, and can be used to\n     * e.g. set automatic allowances for certain subsystems, etc.\n     *\n     * Emits an {Approval} event.\n     *\n     * Requirements:\n     *\n     * - `owner` cannot be the zero address.\n     * - `spender` cannot be the zero address.\n     */\n    function _approve(\n        address owner,\n        address spender,\n        uint256 amount\n    ) internal virtual {\n        require(owner != address(0), \"ERC20: approve from the zero address\");\n        require(spender != address(0), \"ERC20: approve to the zero address\");\n\n        _allowances[owner][spender] = amount;\n        emit Approval(owner, spender, amount);\n    }\n\n    /**\n     * @dev Updates `owner` s allowance for `spender` based on spent `amount`.\n     *\n     * Does not update the allowance amount in case of infinite allowance.\n     * Revert if not enough allowance is available.\n     *\n     * Might emit an {Approval} event.\n     */\n    function _spendAllowance(\n        address owner,\n        address spender,\n        uint256 amount\n    ) internal virtual {\n        uint256 currentAllowance = allowance(owner, spender);\n        if (currentAllowance != type(uint256).max) {\n            require(currentAllowance >= amount, \"ERC20: insufficient allowance\");\n            unchecked {\n                _approve(owner, spender, currentAllowance - amount);\n            }\n        }\n    }\n\n    /**\n     * @dev Hook that is called before any transfer of tokens. This includes\n     * minting and burning.\n     *\n     * Calling conditions:\n     *\n     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\n     * will be transferred to `to`.\n     * - when `from` is zero, `amount` tokens will be minted for `to`.\n     * - when `to` is zero, `amount` of ``from``'s tokens will be burned.\n     * - `from` and `to` are never both zero.\n     *\n     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\n     */\n    function _beforeTokenTransfer(\n        address from,\n        address to,\n        uint256 amount\n    ) internal virtual {}\n\n    /**\n     * @dev Hook that is called after any transfer of tokens. This includes\n     * minting and burning.\n     *\n     * Calling conditions:\n     *\n     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\n     * has been transferred to `to`.\n     * - when `from` is zero, `amount` tokens have been minted for `to`.\n     * - when `to` is zero, `amount` of ``from``'s tokens have been burned.\n     * - `from` and `to` are never both zero.\n     *\n     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\n     */\n    function _afterTokenTransfer(\n        address from,\n        address to,\n        uint256 amount\n    ) internal virtual {}\n}\n"
    },
    "contracts/mocks/ERC20Mock.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity ^0.8.15;\n\nimport \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\n\ncontract ERC20Mock is ERC20 {\n    constructor(\n        string memory name,\n        string memory symbol,\n        uint256 initialSupply\n    ) ERC20(name, symbol) {\n        _mint(msg.sender, initialSupply);\n    }\n}\n"
    },
    "contracts/EarlyAccess.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity ^0.8.15;\n\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\nimport \"./interfaces/INFTGaugeFactory.sol\";\nimport \"./interfaces/INFTGauge.sol\";\nimport \"./interfaces/IVotingEscrow.sol\";\nimport \"./libraries/NFTs.sol\";\n\ncontract EarlyAccess is Ownable {\n    event AddCollection(address indexed collection);\n    event WhitelistNFT(address indexed collection, uint256 tokenId);\n\n    uint256 public immutable amount;\n    uint256 public immutable limit;\n    address public factory;\n    address public votingEscrow;\n    uint256 public maxDuration;\n\n    uint256 public totalNumberWhitelisted;\n    uint256 public launchedAt;\n    mapping(address => bool) public collections;\n    mapping(address => mapping(uint256 => bool)) public whitelisted;\n    mapping(address => mapping(uint256 => bool)) public wrapped;\n\n    constructor(uint256 _amount, uint256 _limit) {\n        amount = _amount;\n        limit = _limit;\n    }\n\n    function setFactory(address _factory) external onlyOwner {\n        factory = _factory;\n\n        votingEscrow = INFTGaugeFactory(_factory).votingEscrow();\n        maxDuration = IVotingEscrow(_factory).maxDuration();\n    }\n\n    function launch() external onlyOwner {\n        require(launchedAt == 0, \"EA: LAUNCHED\");\n\n        launchedAt = block.timestamp;\n    }\n\n    function addCollections(address[] calldata _collections) external onlyOwner {\n        require(launchedAt == 0, \"EA: LAUNCHED\");\n        for (uint256 i; i < _collections.length; i++) {\n            collections[_collections[i]] = true;\n            emit AddCollection(_collections[i]);\n        }\n    }\n\n    function whitelistNFTs(address collection, uint256[] calldata tokenIds) external {\n        require(launchedAt == 0, \"EA: LAUNCHED\");\n        require(collections[collection], \"EA: COLLECTION_NOT_ALLOWED\");\n        require(totalNumberWhitelisted + tokenIds.length <= limit, \"EA: LIMIT_REACHED\");\n\n        for (uint256 i; i < tokenIds.length; i++) {\n            require(NFTs.ownerOf(collection, tokenIds[i]) == msg.sender, \"EA: FORBIDDEN\");\n            whitelisted[collection][tokenIds[i]] = true;\n\n            emit WhitelistNFT(collection, tokenIds[i]);\n        }\n        totalNumberWhitelisted += tokenIds.length;\n    }\n\n    function wrapNFT(\n        address collection,\n        uint256 tokenId,\n        uint256 dividendRatio\n    ) external {\n        require(launchedAt > 0, \"EA: NOT_LAUNCHED\");\n        require(whitelisted[collection][tokenId], \"EA: NOT_WHITELISTED\");\n        require(!wrapped[collection][tokenId], \"EA: WRAPPED\");\n\n        wrapped[collection][tokenId] = true;\n\n        NFTs.safeTransferFrom(collection, msg.sender, address(this), tokenId);\n\n        address gauge = INFTGaugeFactory(factory).gauges(collection);\n        INFTGauge(gauge).wrap(tokenId, dividendRatio, msg.sender, 0);\n\n        IVotingEscrow(votingEscrow).createLockFor(msg.sender, amount, amount, maxDuration);\n    }\n}\n"
    },
    "contracts/BoostedVotingEscrowDelegate.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity ^0.8.15;\n\nimport \"./VotingEscrowDelegate.sol\";\n\ncontract BoostedVotingEscrowDelegate is VotingEscrowDelegate {\n    uint256 public immutable minDuration;\n    uint256 public immutable maxBoost;\n    uint256 public immutable deadline;\n\n    constructor(\n        address _ve,\n        address _token,\n        address _discountToken,\n        uint256 _minDuration,\n        uint256 _maxBoost,\n        uint256 _deadline\n    ) VotingEscrowDelegate(_ve, _token, _discountToken) {\n        minDuration = _minDuration;\n        maxBoost = _maxBoost;\n        deadline = _deadline;\n    }\n\n    function _createLock(\n        uint256 amountToken,\n        uint256 duration,\n        bool discounted\n    ) internal override {\n        require(block.timestamp < deadline, \"BVED: EXPIRED\");\n        require(duration >= minDuration, \"BVED: DURATION_TOO_SHORT\");\n\n        super._createLock(amountToken, duration, discounted);\n    }\n\n    function _increaseAmount(uint256 amountToken, bool discounted) internal override {\n        require(block.timestamp < deadline, \"BVED: EXPIRED\");\n\n        super._increaseAmount(amountToken, discounted);\n    }\n\n    function _getAmounts(uint256 amount, uint256 duration)\n        internal\n        view\n        override\n        returns (uint256 amountVE, uint256 amountToken)\n    {\n        amountVE = (amount * maxBoost * duration) / _maxDuration;\n        amountToken = amount;\n    }\n}\n"
    },
    "contracts/TokenURIRenderer.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity ^0.8.15;\n\nimport \"@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol\";\nimport \"@openzeppelin/contracts/utils/Strings.sol\";\nimport \"./libraries/Base64.sol\";\n\ncontract TokenURIRenderer {\n    using Strings for uint256;\n\n    bytes16 private constant _HEX_SYMBOLS = \"0123456789abcdef\";\n\n    function render(address nftContract, uint256 tokenId) external view returns (string memory output) {\n        string memory _name;\n        try IERC721Metadata(nftContract).name() returns (string memory name) {\n            _name = name;\n        } catch {\n            _name = uint256(uint160(nftContract)).toHexString(20);\n        }\n        string memory color = _toColor(nftContract);\n        output = string(\n            abi.encodePacked(\n                '<svg width=\"600px\" height=\"600px\" viewBox=\"0 0 600 600\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"><defs><polygon points=\"0 0 200 0 200 232 0 232\"></polygon></defs><g stroke=\"none\" stroke-width=\"1\" fill=\"none\" fill-rule=\"evenodd\"><g><rect fill=\"#FFFFFF\" fill-rule=\"nonzero\" x=\"0\" y=\"0\" width=\"600\" height=\"599.999985\"></rect><rect fill=\"',\n                color,\n                '\" fill-rule=\"nonzero\" x=\"0\" y=\"0\" width=\"600\" height=\"599.999985\"></rect><g transform=\"translate(79.843749, 99.999999)\"><g><mask fill=\"white\"><use xlink:href=\"#path-1\"></use></mask><g></g><path d=\"M199.578125,146.468749 C199.578125,146.119792 199.442709,145.786459 199.192709,145.536459 L165.875,112.161459 L191.755209,86.2239587 C191.947917,86.0468747 192.062501,85.8125 192.114584,85.5625 L199.546876,48.5260413 C199.557292,48.494792 199.505209,48.4739587 199.505209,48.432292 C199.557292,48.0364587 199.494792,47.635416 199.192709,47.3333333 L153.432292,1.48437467 C152.942709,0.989584 152.072917,0.989584 151.578125,1.48437467 L103.505209,49.6718747 L55.432292,1.48437467 C54.9427093,0.989584 54.0729173,1 53.5781253,1.494792 L7.81770933,47.4583333 C7.671876,47.5937493 7.671876,47.7812507 7.609376,47.9583333 C7.57812533,48.0364587 7.47395867,48.0468747 7.45312533,48.119792 L0.0208346667,85.260416 C-0.0624986667,85.6875 0.0625013333,86.130208 0.375,86.442708 L33.5781253,119.713541 L7.807292,145.536459 C7.671876,145.671875 7.66145867,145.869792 7.59895867,146.046875 C7.56770933,146.119792 7.46354267,146.130208 7.45312533,146.218749 L0.0208346667,183.359375 C-0.0624986667,183.786459 0.0625013333,184.229167 0.375,184.541667 L46.1354173,230.390625 C46.1979173,230.453125 46.302084,230.442708 46.3854173,230.494792 C46.427084,230.526041 46.3958347,230.593749 46.4479173,230.625 C46.6458347,230.729167 46.859376,230.781251 47.0677093,230.781251 C47.1927093,230.781251 47.3177093,230.760416 47.4427093,230.729167 C47.5260427,230.708333 47.5260427,230.593749 47.5989587,230.552083 C47.7239587,230.484375 47.8854173,230.494792 47.989584,230.380208 L96.0208347,182.171875 L144.156251,230.390625 C144.218751,230.453125 144.322917,230.442708 144.406251,230.494792 C144.447917,230.526041 144.416667,230.593749 144.468751,230.625 C144.666667,230.729167 144.880209,230.781251 145.088543,230.781251 C145.213543,230.781251 145.338543,230.760416 145.463543,230.718749 C145.536459,230.697917 145.536459,230.604167 145.598959,230.572917 C145.734376,230.505208 145.906251,230.505208 146.010417,230.401041 L191.765625,184.552083 C191.958333,184.364584 192.072917,184.135416 192.125,183.880208 L199.557292,146.739584 C199.567709,146.708333 199.515625,146.6875 199.515625,146.645833 C199.515625,146.583333 199.578125,146.531251 199.578125,146.468749 Z M189.630209,84.6614587 L164.031251,110.3125 L151.119792,97.375 L196.135417,52.2708333 L189.630209,84.6614587 Z M49.2031253,225.463541 L55.7031253,192.979167 L78.984376,169.656251 L101.421876,147.171875 L94.9010427,179.588541 L49.2031253,225.463541 Z M189.630209,182.968749 L147.203125,225.484375 L151.286459,204.833333 L153.609376,193.083333 L196.135417,150.473959 L189.630209,182.968749 Z M152.406251,190.567708 L104.427084,142.489584 C104.427084,142.489584 104.427084,142.489584 104.416667,142.489584 L104.291667,142.364584 C104.041667,142.135416 103.713543,142.010416 103.390625,142.010416 C103.057292,142.010416 102.718751,142.145833 102.468751,142.385416 L54.489584,190.458333 L10.5833333,146.468749 L36.354168,120.656251 C36.354168,120.656251 36.364584,120.656251 36.364584,120.656251 L58.5625013,98.4166667 C59.0781253,97.9010413 59.0781253,97.0729173 58.5625013,96.557292 L10.5937507,48.380208 L54.5,4.27083333 L102.583333,52.4635413 C103.078125,52.9531253 103.947917,52.9531253 104.437501,52.4635413 L152.520835,4.27083333 L196.427084,48.2656253 L181.234376,63.5 L148.354168,96.442708 C148.093751,96.692708 147.958333,97.0416667 147.958333,97.375 C147.958333,97.7135413 148.083333,98.0468747 148.343751,98.3020827 L163.109376,113.093749 C163.109376,113.104167 163.109376,113.104167 163.109376,113.104167 L196.416667,146.468749 L152.406251,190.567708 Z\" fill=\"#FFFFFF\" fill-rule=\"nonzero\" mask=\"url(#mask-2)\"></path></g><path d=\"M147.958333,97.375 C147.958333,97.0416667 148.083333,96.7031253 148.343751,96.442708 L181.223959,63.5 L196.416667,48.2656253 L152.510417,4.27083333 L104.437501,52.4635413 C103.947917,52.9531253 103.078125,52.9531253 102.583333,52.4635413 L54.5,4.27083333 L10.5937507,48.380208 L58.5729173,96.557292 C59.0885427,97.0729173 59.0885427,97.9010413 58.5729173,98.4166667 L36.375,120.656251 C36.375,120.656251 36.364584,120.656251 36.364584,120.656251 L10.5937507,146.468749 L54.5,190.458333 L102.479168,142.385416 C102.729168,142.145833 103.067709,142.010416 103.401043,142.010416 C103.723959,142.010416 104.052084,142.135416 104.302084,142.364584 L104.427084,142.489584 C104.427084,142.489584 104.427084,142.489584 104.437501,142.489584 L152.416667,190.567708 L196.427084,146.468749 L163.119792,113.104167 C163.119792,113.104167 163.119792,113.104167 163.119792,113.093749 L148.354168,98.3020827 C148.093751,98.0468747 147.958333,97.7135413 147.958333,97.375 Z\" fill=\"',\n                color,\n                '\" fill-rule=\"nonzero\"></path></g></g><text font-family=\"Arial-BoldMT, Arial\" font-size=\"48\" font-weight=\"bold\" fill=\"#FFFFFF\"><tspan x=\"79.5\" y=\"404\">Wrapped</tspan><tspan x=\"79.5\" y=\"457\">',\n                _name,\n                '</tspan><tspan x=\"79.5\" y=\"510\">#',\n                tokenId.toString(),\n                \"</tspan></text></g></svg>\"\n            )\n        );\n\n        string memory json = Base64.encode(\n            bytes(\n                string(\n                    abi.encodePacked(\n                        '{\"name\": \"Wrapped ',\n                        _name,\n                        \" #\",\n                        tokenId.toString(),\n                        '\", \"description\": \"Wrapped NFT that earns passive LEVX yield in proportional to the THANO$ staked together\", \"image\": \"data:image/svg+xml;base64,',\n                        Base64.encode(bytes(output)),\n                        '\"}'\n                    )\n                )\n            )\n        );\n        output = string(abi.encodePacked(\"data:application/json;base64,\", json));\n    }\n\n    function _toColor(address addr) internal pure returns (string memory) {\n        uint160 value = uint160(addr);\n        bytes memory buffer = new bytes(7);\n        for (uint256 i = 6; i > 0; --i) {\n            buffer[i] = _HEX_SYMBOLS[value & 0xf];\n            value >>= 4;\n        }\n        require(value == 0, \"TURIR: HEX_LENGTH_INSUFFICIENT\");\n        return string(buffer);\n    }\n}\n"
    },
    "contracts/libraries/Base64.sol": {
      "content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity ^0.8.15;\n\n/// [MIT License]\n/// @title Base64\n/// @notice Provides a function for encoding some bytes in base64\n/// @author Brecht Devos <brecht@loopring.org>\nlibrary Base64 {\n    bytes internal constant TABLE = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\";\n\n    /// @notice Encodes some bytes to the base64 representation\n    function encode(bytes memory data) internal pure returns (string memory) {\n        uint256 len = data.length;\n        if (len == 0) return \"\";\n\n        // multiply by 4/3 rounded up\n        uint256 encodedLen = 4 * ((len + 2) / 3);\n\n        // Add some extra buffer at the end\n        bytes memory result = new bytes(encodedLen + 32);\n\n        bytes memory table = TABLE;\n\n        assembly {\n            let tablePtr := add(table, 1)\n            let resultPtr := add(result, 32)\n\n            for {\n                let i := 0\n            } lt(i, len) {\n\n            } {\n                i := add(i, 3)\n                let input := and(mload(add(data, i)), 0xffffff)\n\n                let out := mload(add(tablePtr, and(shr(18, input), 0x3F)))\n                out := shl(8, out)\n                out := add(out, and(mload(add(tablePtr, and(shr(12, input), 0x3F))), 0xFF))\n                out := shl(8, out)\n                out := add(out, and(mload(add(tablePtr, and(shr(6, input), 0x3F))), 0xFF))\n                out := shl(8, out)\n                out := add(out, and(mload(add(tablePtr, and(input, 0x3F))), 0xFF))\n                out := shl(224, out)\n\n                mstore(resultPtr, out)\n\n                resultPtr := add(resultPtr, 4)\n            }\n\n            switch mod(len, 3)\n            case 1 {\n                mstore(sub(resultPtr, 2), shl(240, 0x3d3d))\n            }\n            case 2 {\n                mstore(sub(resultPtr, 1), shl(248, 0x3d))\n            }\n\n            mstore(result, encodedLen)\n        }\n\n        return string(result);\n    }\n}\n"
    }
  },
  "settings": {
    "optimizer": {
      "enabled": true,
      "runs": 200
    },
    "outputSelection": {
      "*": {
        "*": [
          "abi",
          "evm.bytecode",
          "evm.deployedBytecode",
          "evm.methodIdentifiers",
          "metadata",
          "devdoc",
          "userdoc",
          "storageLayout",
          "evm.gasEstimates"
        ],
        "": [
          "ast"
        ]
      }
    },
    "metadata": {
      "useLiteralContent": true
    },
    "libraries": {
      "": {
        "__CACHE_BREAKER__": "0x00000000d41867734bbee4c6863d9255b2b06ac1"
      }
    }
  }
}