ETH Price: $3,506.81 (-0.08%)
Gas: 2 Gwei

Contract

0xD5941275AeDF59775D9Bb9A06757f2696b880ae9
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
Fulfill Thol Per...203468562024-07-20 9:30:1119 hrs ago1721467811IN
0xD5941275...96b880ae9
0 ETH0.000194292.66916297
Fulfill Thol Per...203396642024-07-19 9:25:1143 hrs ago1721381111IN
0xD5941275...96b880ae9
0 ETH0.000376655.17551203
Fulfill Thol Per...203324732024-07-18 9:20:232 days ago1721294423IN
0xD5941275...96b880ae9
0 ETH0.000603718.29056005
Fulfill Thol Per...203252882024-07-17 9:15:233 days ago1721207723IN
0xD5941275...96b880ae9
0 ETH0.00103314.18605842
Fulfill Thol Per...203181112024-07-16 9:15:234 days ago1721121323IN
0xD5941275...96b880ae9
0 ETH0.000546237.48742994
Fulfill Thol Per...203109282024-07-15 9:10:115 days ago1721034611IN
0xD5941275...96b880ae9
0 ETH0.000318664.37530262
Fulfill Thol Per...203037312024-07-14 9:05:116 days ago1720947911IN
0xD5941275...96b880ae9
0 ETH0.00022843.1365214
Fulfill Thol Per...202965532024-07-13 9:00:597 days ago1720861259IN
0xD5941275...96b880ae9
0 ETH0.000109841.50957829
Fulfill Thol Per...202893612024-07-12 8:55:118 days ago1720774511IN
0xD5941275...96b880ae9
0 ETH0.000193942.66408956
Fulfill Thol Per...202821782024-07-11 8:50:239 days ago1720687823IN
0xD5941275...96b880ae9
0 ETH0.000363064.98719664
Fulfill Thol Per...202749882024-07-10 8:45:2310 days ago1720601123IN
0xD5941275...96b880ae9
0 ETH0.000390435.35800065
Fulfill Thol Per...202678062024-07-09 8:40:2311 days ago1720514423IN
0xD5941275...96b880ae9
0 ETH0.000235953.241803
Fulfill Thol Per...202606382024-07-08 8:35:3512 days ago1720427735IN
0xD5941275...96b880ae9
0 ETH0.000363284.98409185
Fulfill Thol Per...202534522024-07-07 8:30:3513 days ago1720341035IN
0xD5941275...96b880ae9
0 ETH0.000112391.54377039
Fulfill Thol Per...202462622024-07-06 8:25:2314 days ago1720254323IN
0xD5941275...96b880ae9
0 ETH0.000145671.99676877
Fulfill Thol Per...202390512024-07-05 8:16:1115 days ago1720167371IN
0xD5941275...96b880ae9
0 ETH0.0009439212.96149386
Fulfill Thol Per...202318912024-07-04 8:15:2316 days ago1720080923IN
0xD5941275...96b880ae9
0 ETH0.000413285.67861989
Fulfill Thol Per...202247032024-07-03 8:10:3517 days ago1719994235IN
0xD5941275...96b880ae9
0 ETH0.000203412.79176919
Fulfill Thol Per...202175242024-07-02 8:05:4718 days ago1719907547IN
0xD5941275...96b880ae9
0 ETH0.000358424.92355158
Fulfill Thol Per...202103382024-07-01 8:00:4719 days ago1719820847IN
0xD5941275...96b880ae9
0 ETH0.000195412.68622565
Fulfill Thol Per...202031462024-06-30 7:55:5920 days ago1719734159IN
0xD5941275...96b880ae9
0 ETH0.00016252.23393774
Fulfill Thol Per...201959612024-06-29 7:50:1121 days ago1719647411IN
0xD5941275...96b880ae9
0 ETH0.000151192.07622626
Fulfill Thol Per...201887762024-06-28 7:45:2322 days ago1719560723IN
0xD5941275...96b880ae9
0 ETH0.000341374.68353336
Fulfill Thol Per...201816182024-06-27 7:45:4723 days ago1719474347IN
0xD5941275...96b880ae9
0 ETH0.00027513.77938894
Fulfill Thol Per...201744292024-06-26 7:40:2324 days ago1719387623IN
0xD5941275...96b880ae9
0 ETH0.000117961.61873515
View all transactions

View more zero value Internal Transactions in Advanced View mode

Advanced mode:
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
NFTDataOperator

Compiler Version
v0.8.17+commit.8df45f5f

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion
File 1 of 19 : NFTDataOperator.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

/**************************************

    security-contact:
    - [email protected]

    maintainers:
    - [email protected]
    - [email protected]
    - [email protected]
    - [email protected]

    contributors:
    - [email protected]

**************************************/

// OpenZeppelin
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";

// Uniswap
import { OracleLibrary } from "@uniswap/v3-periphery/contracts/libraries/OracleLibrary.sol";

// ABDK
import { ABDKMath64x64 } from "abdk-libraries-solidity/ABDKMath64x64.sol";

// Local
import { Configurable } from "../utils/Configurable.sol";
import { INFTDataOperator } from "../interfaces/INFTDataOperator.sol";
import { ITholosStaking } from "../interfaces/ITholosStaking.sol";

contract NFTDataOperator is Ownable, Configurable, INFTDataOperator {

    // -----------------------------------------------------------------------
    //                             Library usage
    // -----------------------------------------------------------------------

    using ABDKMath64x64 for int128;

    // -----------------------------------------------------------------------
    //                             State variables
    // -----------------------------------------------------------------------

    /// @dev Staking contract address.
    address public immutable staking; 
    /// @dev Address authorized to provide data. 
    address public dataProvider;
    /// @dev Uniswap V3 THOL-WETH pool address.
    address public tholWethPool;
    /// @dev WETH token address.
    address public weth;
    /// @dev THOL token address.
    address public thol;

    /// @dev 400% as 64.64-bit fixed point number
    int128 public localMaxPercentage;
    /// @dev 25% as 64.64-bit fixed point number
    int128 public localMinPercentage;

    // -----------------------------------------------------------------------
    //                             Modifiers
    // -----------------------------------------------------------------------

    /// @dev Verify if current 'msg.sender' is data provider.
    modifier onlyDataProvider() {
        if (msg.sender != dataProvider) revert Unauthorized();
        _;
    }

    // -----------------------------------------------------------------------
    //                             Setup
    // -----------------------------------------------------------------------

    constructor(bytes memory _arguments) {

        // decode arguments
        (
            address staking_
        ) = abi.decode(
            _arguments,
            (
                address
            )
        );
        
        // storage
        staking = staking_;

        // event
        emit Initialised(_arguments);

    }

    /**
     * @dev Allows to set configure contract.
     *
     * @dev Parameters
     * @param _arguments - all function arguments encoded to bytes
     *
     * @dev Validations :
     * - Only contract owner can perform this function.
     * - This function can be performed only once.
     *
     * @dev Events :
     * - {Configured}
     */
    function configure(
        bytes memory _arguments
    ) external override
    onlyOwner
    onlyInState(State.UNCONFIGURED) {

        // decode arguments
        (
            address dataProvider_,
            address tholWethPool_,
            address weth_,
            address thol_,
            Request memory request_
        ) = abi.decode(
            _arguments,
            (
                address,
                address,
                address,
                address,
                Request
            )
        );

        // storage
        dataProvider = dataProvider_;
        tholWethPool = tholWethPool_;
        weth = weth_;
        thol = thol_;

        // set local max and min cap
        localMaxPercentage = 73786976294838206464;
        localMinPercentage = 4611686018427387904;

        // first fulfill
        _fulfillTholPerNft(request_);

        // state
        state = State.CONFIGURED;

        // event
        emit Configured(_arguments);

    }

    // -----------------------------------------------------------------------
    //                             External
    // -----------------------------------------------------------------------

    /**
     * @dev Allows to set new local max percentage value.
     *
     * @dev Parameters :
     * @param _value - new local max percentage value.
     *
     * @dev Validations :
     * - Only contract owner can perform this function.
     * - New local max percentage must be greater than current local min percentage.
     *
     * @dev Events :
     * - {LocalMaxPercentageUpdated}
     */
    function updateLocalMaxPercentage(int128 _value) external
    onlyOwner {

        // assert
        if (_value <= localMinPercentage) revert MaxCapMustBeGreaterThanMinCap();

        // storage
        localMaxPercentage = _value;

        // event
        emit LocalMaxPercentageUpdated(_value);

    }

    /**
     * @dev Allows to set new local min percentage value.
     *
     * @dev Parameters :
     * @param _value - new local min percentage value.
     *
     * @dev Validations :
     * - Only contract owner can perform this function.
     * - New local min percentage must be lower than current local max percentage.
     *
     * @dev Events :
     * - {LocalMinPercentageUpdated}
     */
    function updateLocalMinPercentage(int128 _value) external
    onlyOwner {

        // assert
        if (_value >= localMaxPercentage) revert MinCapMustBeLowerThanMaxCap();

        // storage
        localMinPercentage = _value;

        // event
        emit LocalMinPercentageUpdated(_value);

    }

    /**
     * @dev Allows to calculate new 'tholPerNft' value which is send and set in the staking contract.
     *
     * @dev Parameters :
     * @param _request - all function arguments packed in the 'Request' struct.
     *
     * @dev Validations :
     * - Only data provider can perform this function.
     */
    function fulfillTholPerNft(Request memory _request) external override
    onlyDataProvider {

        // fulfill
        _fulfillTholPerNft(_request);

    }
    // -----------------------------------------------------------------------
    //                             Public
    // -----------------------------------------------------------------------

    /**
     * @dev Calculate amount of THOL for the given amount of WETH
     *
     * @dev Parameters :
     * @param _currentFloorPrice - amount of WETH which should be calculated to THOL
     *
     * @return tholAmount_ - amount of THOL for the given amount of WETH
     */
    function calculateWethToThol(uint128 _currentFloorPrice) public virtual override view
    returns (uint256 tholAmount_) {

        // consult
        (int24 tick_,) = OracleLibrary.consult(tholWethPool, 1);

        // get and return quote
        tholAmount_ = OracleLibrary.getQuoteAtTick(tick_, _currentFloorPrice, weth, thol);

    }

    // -----------------------------------------------------------------------
    //                             Private
    // -----------------------------------------------------------------------

    function _fulfillTholPerNft(Request memory _request) private {

        // calculate amount of THOL for given WETH amount
        uint96 floorPriceInThol_ = uint96(calculateWethToThol(_request.currentFloorPrice));

        // calculate ratio for the current and previous volume
        int128 volumeRatio_ = ABDKMath64x64.divu(
            _request.currentVolume,
            _request.previousVolume
        );

        // calculate ratio for the current and previous floor price
        int128 floorPriceRatio_ = ABDKMath64x64.divu(
            _request.currentFloorPrice,
            _request.previousFloorPrice
        );

        // calculate total ratio for volume and floor price
        int128 totalRatio_ = volumeRatio_.mul(floorPriceRatio_);

        // calculate THOL per NFT value
        uint96 tholPerNft_ = uint96(totalRatio_.mulu(floorPriceInThol_));

        // verify calculate THOL per NFT value with local cap
        tholPerNft_ = _compareWithLocalCap(tholPerNft_, floorPriceInThol_);

        // update THOL per NFT value in the staking contract
        ITholosStaking(staking).setTholPerNft(tholPerNft_);

        // event
        emit TholPerNftFulfilled(tholPerNft_, block.timestamp);

    }

    /**
     * @dev Allows to compare calculate THOL per NFT value is between max and min cap and set if
     *      necessary if value is out of cap range.
     *
     * @dev Parameters :
     * @param _tholPerNft - calculated THOL per NFT value.
     * @param _floorPriceInThol - current NFT collection floor price in THOL.
     *
     * @return uint96 - THOL per NFT including local cap.
     */
    function _compareWithLocalCap(
        uint96 _tholPerNft,
        uint96 _floorPriceInThol
    ) private view
    returns (uint96) {

        // calculate local max cap (400% of current floor price)
        uint96 max_ = uint96(localMaxPercentage.mulu(_floorPriceInThol));
        // calculate local min cap (25% of current floor price)
        uint96 min_ = uint96(localMinPercentage.mulu(_floorPriceInThol));

        // verify if calculated THOL per NFT is in the local cap range
        if (_tholPerNft <= max_ && _tholPerNft >= min_) {
            // case when THOL per NFT is in range
            return _tholPerNft;
        } else if (_tholPerNft < min_) {
            // case when THOL per NFT is less than min cap
            return min_;
        } else {
            // case when THOL per NFT is greater than local max cap
            return max_;
        }

    }

}

File 2 of 19 : Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)

pragma solidity ^0.8.0;

import "../utils/Context.sol";

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

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

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor() {
        _transferOwnership(_msgSender());
    }

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

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

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

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

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

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

File 3 of 19 : Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;

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

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

File 4 of 19 : IUniswapV3Pool.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

import {IUniswapV3PoolImmutables} from './pool/IUniswapV3PoolImmutables.sol';
import {IUniswapV3PoolState} from './pool/IUniswapV3PoolState.sol';
import {IUniswapV3PoolDerivedState} from './pool/IUniswapV3PoolDerivedState.sol';
import {IUniswapV3PoolActions} from './pool/IUniswapV3PoolActions.sol';
import {IUniswapV3PoolOwnerActions} from './pool/IUniswapV3PoolOwnerActions.sol';
import {IUniswapV3PoolErrors} from './pool/IUniswapV3PoolErrors.sol';
import {IUniswapV3PoolEvents} from './pool/IUniswapV3PoolEvents.sol';

/// @title The interface for a Uniswap V3 Pool
/// @notice A Uniswap pool facilitates swapping and automated market making between any two assets that strictly conform
/// to the ERC20 specification
/// @dev The pool interface is broken up into many smaller pieces
interface IUniswapV3Pool is
    IUniswapV3PoolImmutables,
    IUniswapV3PoolState,
    IUniswapV3PoolDerivedState,
    IUniswapV3PoolActions,
    IUniswapV3PoolOwnerActions,
    IUniswapV3PoolErrors,
    IUniswapV3PoolEvents
{

}

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

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

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

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

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

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

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

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

File 6 of 19 : IUniswapV3PoolDerivedState.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Pool state that is not stored
/// @notice Contains view functions to provide information about the pool that is computed rather than stored on the
/// blockchain. The functions here may have variable gas costs.
interface IUniswapV3PoolDerivedState {
    /// @notice Returns the cumulative tick and liquidity as of each timestamp `secondsAgo` from the current block timestamp
    /// @dev To get a time weighted average tick or liquidity-in-range, you must call this with two values, one representing
    /// the beginning of the period and another for the end of the period. E.g., to get the last hour time-weighted average tick,
    /// you must call it with secondsAgos = [3600, 0].
    /// @dev The time weighted average tick represents the geometric time weighted average price of the pool, in
    /// log base sqrt(1.0001) of token1 / token0. The TickMath library can be used to go from a tick value to a ratio.
    /// @param secondsAgos From how long ago each cumulative tick and liquidity value should be returned
    /// @return tickCumulatives Cumulative tick values as of each `secondsAgos` from the current block timestamp
    /// @return secondsPerLiquidityCumulativeX128s Cumulative seconds per liquidity-in-range value as of each `secondsAgos` from the current block
    /// timestamp
    function observe(uint32[] calldata secondsAgos)
        external
        view
        returns (int56[] memory tickCumulatives, uint160[] memory secondsPerLiquidityCumulativeX128s);

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

File 7 of 19 : IUniswapV3PoolErrors.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Errors emitted by a pool
/// @notice Contains all events emitted by the pool
interface IUniswapV3PoolErrors {
    error LOK();
    error TLU();
    error TLM();
    error TUM();
    error AI();
    error M0();
    error M1();
    error AS();
    error IIA();
    error L();
    error F0();
    error F1();
}

File 8 of 19 : IUniswapV3PoolEvents.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Events emitted by a pool
/// @notice Contains all events emitted by the pool
interface IUniswapV3PoolEvents {
    /// @notice Emitted exactly once by a pool when #initialize is first called on the pool
    /// @dev Mint/Burn/Swap cannot be emitted by the pool before Initialize
    /// @param sqrtPriceX96 The initial sqrt price of the pool, as a Q64.96
    /// @param tick The initial tick of the pool, i.e. log base 1.0001 of the starting price of the pool
    event Initialize(uint160 sqrtPriceX96, int24 tick);

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

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

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

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

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

    /// @notice Emitted by the pool for increases to the number of observations that can be stored
    /// @dev observationCardinalityNext is not the observation cardinality until an observation is written at the index
    /// just before a mint/swap/burn.
    /// @param observationCardinalityNextOld The previous value of the next observation cardinality
    /// @param observationCardinalityNextNew The updated value of the next observation cardinality
    event IncreaseObservationCardinalityNext(
        uint16 observationCardinalityNextOld,
        uint16 observationCardinalityNextNew
    );

    /// @notice Emitted when the protocol fee is changed by the pool
    /// @param feeProtocol0Old The previous value of the token0 protocol fee
    /// @param feeProtocol1Old The previous value of the token1 protocol fee
    /// @param feeProtocol0New The updated value of the token0 protocol fee
    /// @param feeProtocol1New The updated value of the token1 protocol fee
    event SetFeeProtocol(uint8 feeProtocol0Old, uint8 feeProtocol1Old, uint8 feeProtocol0New, uint8 feeProtocol1New);

    /// @notice Emitted when the collected protocol fees are withdrawn by the factory owner
    /// @param sender The address that collects the protocol fees
    /// @param recipient The address that receives the collected protocol fees
    /// @param amount0 The amount of token0 protocol fees that is withdrawn
    /// @param amount0 The amount of token1 protocol fees that is withdrawn
    event CollectProtocol(address indexed sender, address indexed recipient, uint128 amount0, uint128 amount1);
}

File 9 of 19 : IUniswapV3PoolImmutables.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Pool state that never changes
/// @notice These parameters are fixed for a pool forever, i.e., the methods will always return the same values
interface IUniswapV3PoolImmutables {
    /// @notice The contract that deployed the pool, which must adhere to the IUniswapV3Factory interface
    /// @return The contract address
    function factory() external view returns (address);

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

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

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

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

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

File 10 of 19 : IUniswapV3PoolOwnerActions.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Permissioned pool actions
/// @notice Contains pool methods that may only be called by the factory owner
interface IUniswapV3PoolOwnerActions {
    /// @notice Set the denominator of the protocol's % share of the fees
    /// @param feeProtocol0 new protocol fee for token0 of the pool
    /// @param feeProtocol1 new protocol fee for token1 of the pool
    function setFeeProtocol(uint8 feeProtocol0, uint8 feeProtocol1) external;

    /// @notice Collect the protocol fee accrued to the pool
    /// @param recipient The address to which collected protocol fees should be sent
    /// @param amount0Requested The maximum amount of token0 to send, can be 0 to collect fees in only token1
    /// @param amount1Requested The maximum amount of token1 to send, can be 0 to collect fees in only token0
    /// @return amount0 The protocol fee collected in token0
    /// @return amount1 The protocol fee collected in token1
    function collectProtocol(
        address recipient,
        uint128 amount0Requested,
        uint128 amount1Requested
    ) external returns (uint128 amount0, uint128 amount1);
}

File 11 of 19 : IUniswapV3PoolState.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

File 13 of 19 : TickMath.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;

/// @title Math library for computing sqrt prices from ticks and vice versa
/// @notice Computes sqrt price for ticks of size 1.0001, i.e. sqrt(1.0001^tick) as fixed point Q64.96 numbers. Supports
/// prices between 2**-128 and 2**128
library TickMath {
    error T();
    error R();

    /// @dev The minimum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**-128
    int24 internal constant MIN_TICK = -887272;
    /// @dev The maximum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**128
    int24 internal constant MAX_TICK = -MIN_TICK;

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

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

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

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

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

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

            uint256 r = ratio;
            uint256 msb = 0;

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

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

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

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

            int256 log_sqrt10001 = log_2 * 255738958999603826347141; // 128.128 number

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

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

File 14 of 19 : OracleLibrary.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0 <0.9.0;

import '@uniswap/v3-core/contracts/libraries/FullMath.sol';
import '@uniswap/v3-core/contracts/libraries/TickMath.sol';
import '@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol';

/// @title Oracle library
/// @notice Provides functions to integrate with V3 pool oracle
library OracleLibrary {
    /// @notice Calculates time-weighted means of tick and liquidity for a given Uniswap V3 pool
    /// @param pool Address of the pool that we want to observe
    /// @param secondsAgo Number of seconds in the past from which to calculate the time-weighted means
    /// @return arithmeticMeanTick The arithmetic mean tick from (block.timestamp - secondsAgo) to block.timestamp
    /// @return harmonicMeanLiquidity The harmonic mean liquidity from (block.timestamp - secondsAgo) to block.timestamp
    function consult(address pool, uint32 secondsAgo)
        internal
        view
        returns (int24 arithmeticMeanTick, uint128 harmonicMeanLiquidity)
    {
        require(secondsAgo != 0, 'BP');

        uint32[] memory secondsAgos = new uint32[](2);
        secondsAgos[0] = secondsAgo;
        secondsAgos[1] = 0;

        (int56[] memory tickCumulatives, uint160[] memory secondsPerLiquidityCumulativeX128s) = IUniswapV3Pool(pool)
            .observe(secondsAgos);

        int56 tickCumulativesDelta = tickCumulatives[1] - tickCumulatives[0];
        uint160 secondsPerLiquidityCumulativesDelta = secondsPerLiquidityCumulativeX128s[1] -
            secondsPerLiquidityCumulativeX128s[0];

        arithmeticMeanTick = int24(tickCumulativesDelta / int56(uint56(secondsAgo)));
        // Always round to negative infinity
        if (tickCumulativesDelta < 0 && (tickCumulativesDelta % int56(uint56(secondsAgo)) != 0)) arithmeticMeanTick--;

        // We are multiplying here instead of shifting to ensure that harmonicMeanLiquidity doesn't overflow uint128
        uint192 secondsAgoX160 = uint192(secondsAgo) * type(uint160).max;
        harmonicMeanLiquidity = uint128(secondsAgoX160 / (uint192(secondsPerLiquidityCumulativesDelta) << 32));
    }

    /// @notice Given a tick and a token amount, calculates the amount of token received in exchange
    /// @param tick Tick value used to calculate the quote
    /// @param baseAmount Amount of token to be converted
    /// @param baseToken Address of an ERC20 token contract used as the baseAmount denomination
    /// @param quoteToken Address of an ERC20 token contract used as the quoteAmount denomination
    /// @return quoteAmount Amount of quoteToken received for baseAmount of baseToken
    function getQuoteAtTick(
        int24 tick,
        uint128 baseAmount,
        address baseToken,
        address quoteToken
    ) internal pure returns (uint256 quoteAmount) {
        uint160 sqrtRatioX96 = TickMath.getSqrtRatioAtTick(tick);

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

    /// @notice Given a pool, it returns the number of seconds ago of the oldest stored observation
    /// @param pool Address of Uniswap V3 pool that we want to observe
    /// @return secondsAgo The number of seconds ago of the oldest observation stored for the pool
    function getOldestObservationSecondsAgo(address pool) internal view returns (uint32 secondsAgo) {
        (, , uint16 observationIndex, uint16 observationCardinality, , , ) = IUniswapV3Pool(pool).slot0();
        require(observationCardinality > 0, 'NI');

        (uint32 observationTimestamp, , , bool initialized) = IUniswapV3Pool(pool).observations(
            (observationIndex + 1) % observationCardinality
        );

        // The next index might not be initialized if the cardinality is in the process of increasing
        // In this case the oldest observation is always in index 0
        if (!initialized) {
            (observationTimestamp, , , ) = IUniswapV3Pool(pool).observations(0);
        }

        unchecked {
            secondsAgo = uint32(block.timestamp) - observationTimestamp;
        }
    }

    /// @notice Given a pool, it returns the tick value as of the start of the current block
    /// @param pool Address of Uniswap V3 pool
    /// @return The tick that the pool was in at the start of the current block
    function getBlockStartingTickAndLiquidity(address pool) internal view returns (int24, uint128) {
        (, int24 tick, uint16 observationIndex, uint16 observationCardinality, , , ) = IUniswapV3Pool(pool).slot0();

        // 2 observations are needed to reliably calculate the block starting tick
        require(observationCardinality > 1, 'NEO');

        // If the latest observation occurred in the past, then no tick-changing trades have happened in this block
        // therefore the tick in `slot0` is the same as at the beginning of the current block.
        // We don't need to check if this observation is initialized - it is guaranteed to be.
        (
            uint32 observationTimestamp,
            int56 tickCumulative,
            uint160 secondsPerLiquidityCumulativeX128,

        ) = IUniswapV3Pool(pool).observations(observationIndex);
        if (observationTimestamp != uint32(block.timestamp)) {
            return (tick, IUniswapV3Pool(pool).liquidity());
        }

        uint256 prevIndex = (uint256(observationIndex) + observationCardinality - 1) % observationCardinality;
        (
            uint32 prevObservationTimestamp,
            int56 prevTickCumulative,
            uint160 prevSecondsPerLiquidityCumulativeX128,
            bool prevInitialized
        ) = IUniswapV3Pool(pool).observations(prevIndex);

        require(prevInitialized, 'ONI');

        uint32 delta = observationTimestamp - prevObservationTimestamp;
        tick = int24((tickCumulative - int56(uint56(prevTickCumulative))) / int56(uint56(delta)));
        uint128 liquidity = uint128(
            (uint192(delta) * type(uint160).max) /
                (uint192(secondsPerLiquidityCumulativeX128 - prevSecondsPerLiquidityCumulativeX128) << 32)
        );
        return (tick, liquidity);
    }

    /// @notice Information for calculating a weighted arithmetic mean tick
    struct WeightedTickData {
        int24 tick;
        uint128 weight;
    }

    /// @notice Given an array of ticks and weights, calculates the weighted arithmetic mean tick
    /// @param weightedTickData An array of ticks and weights
    /// @return weightedArithmeticMeanTick The weighted arithmetic mean tick
    /// @dev Each entry of `weightedTickData` should represents ticks from pools with the same underlying pool tokens. If they do not,
    /// extreme care must be taken to ensure that ticks are comparable (including decimal differences).
    /// @dev Note that the weighted arithmetic mean tick corresponds to the weighted geometric mean price.
    function getWeightedArithmeticMeanTick(WeightedTickData[] memory weightedTickData)
        internal
        pure
        returns (int24 weightedArithmeticMeanTick)
    {
        // Accumulates the sum of products between each tick and its weight
        int256 numerator;

        // Accumulates the sum of the weights
        uint256 denominator;

        // Products fit in 152 bits, so it would take an array of length ~2**104 to overflow this logic
        for (uint256 i; i < weightedTickData.length; i++) {
            numerator += weightedTickData[i].tick * int256(uint256(weightedTickData[i].weight));
            denominator += weightedTickData[i].weight;
        }

        weightedArithmeticMeanTick = int24(numerator / int256(denominator));
        // Always round to negative infinity
        if (numerator < 0 && (numerator % int256(denominator) != 0)) weightedArithmeticMeanTick--;
    }

    /// @notice Returns the "synthetic" tick which represents the price of the first entry in `tokens` in terms of the last
    /// @dev Useful for calculating relative prices along routes.
    /// @dev There must be one tick for each pairwise set of tokens.
    /// @param tokens The token contract addresses
    /// @param ticks The ticks, representing the price of each token pair in `tokens`
    /// @return syntheticTick The synthetic tick, representing the relative price of the outermost tokens in `tokens`
    function getChainedPrice(address[] memory tokens, int24[] memory ticks)
        internal
        pure
        returns (int256 syntheticTick)
    {
        require(tokens.length - 1 == ticks.length, 'DL');
        for (uint256 i = 1; i <= ticks.length; i++) {
            // check the tokens for address sort order, then accumulate the
            // ticks into the running synthetic tick, ensuring that intermediate tokens "cancel out"
            tokens[i - 1] < tokens[i] ? syntheticTick += ticks[i - 1] : syntheticTick -= ticks[i - 1];
        }
    }
}

File 15 of 19 : ABDKMath64x64.sol
// SPDX-License-Identifier: BSD-4-Clause
/*
 * ABDK Math 64.64 Smart Contract Library.  Copyright © 2019 by ABDK Consulting.
 * Author: Mikhail Vladimirov <[email protected]>
 */
pragma solidity ^0.8.0;

/**
 * Smart contract library of mathematical functions operating with signed
 * 64.64-bit fixed point numbers.  Signed 64.64-bit fixed point number is
 * basically a simple fraction whose numerator is signed 128-bit integer and
 * denominator is 2^64.  As long as denominator is always the same, there is no
 * need to store it, thus in Solidity signed 64.64-bit fixed point numbers are
 * represented by int128 type holding only the numerator.
 */
library ABDKMath64x64 {
  /*
   * Minimum value signed 64.64-bit fixed point number may have. 
   */
  int128 private constant MIN_64x64 = -0x80000000000000000000000000000000;

  /*
   * Maximum value signed 64.64-bit fixed point number may have. 
   */
  int128 private constant MAX_64x64 = 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;

  /**
   * Convert signed 256-bit integer number into signed 64.64-bit fixed point
   * number.  Revert on overflow.
   *
   * @param x signed 256-bit integer number
   * @return signed 64.64-bit fixed point number
   */
  function fromInt (int256 x) internal pure returns (int128) {
    unchecked {
      require (x >= -0x8000000000000000 && x <= 0x7FFFFFFFFFFFFFFF);
      return int128 (x << 64);
    }
  }

  /**
   * Convert signed 64.64 fixed point number into signed 64-bit integer number
   * rounding down.
   *
   * @param x signed 64.64-bit fixed point number
   * @return signed 64-bit integer number
   */
  function toInt (int128 x) internal pure returns (int64) {
    unchecked {
      return int64 (x >> 64);
    }
  }

  /**
   * Convert unsigned 256-bit integer number into signed 64.64-bit fixed point
   * number.  Revert on overflow.
   *
   * @param x unsigned 256-bit integer number
   * @return signed 64.64-bit fixed point number
   */
  function fromUInt (uint256 x) internal pure returns (int128) {
    unchecked {
      require (x <= 0x7FFFFFFFFFFFFFFF);
      return int128 (int256 (x << 64));
    }
  }

  /**
   * Convert signed 64.64 fixed point number into unsigned 64-bit integer
   * number rounding down.  Revert on underflow.
   *
   * @param x signed 64.64-bit fixed point number
   * @return unsigned 64-bit integer number
   */
  function toUInt (int128 x) internal pure returns (uint64) {
    unchecked {
      require (x >= 0);
      return uint64 (uint128 (x >> 64));
    }
  }

  /**
   * Convert signed 128.128 fixed point number into signed 64.64-bit fixed point
   * number rounding down.  Revert on overflow.
   *
   * @param x signed 128.128-bin fixed point number
   * @return signed 64.64-bit fixed point number
   */
  function from128x128 (int256 x) internal pure returns (int128) {
    unchecked {
      int256 result = x >> 64;
      require (result >= MIN_64x64 && result <= MAX_64x64);
      return int128 (result);
    }
  }

  /**
   * Convert signed 64.64 fixed point number into signed 128.128 fixed point
   * number.
   *
   * @param x signed 64.64-bit fixed point number
   * @return signed 128.128 fixed point number
   */
  function to128x128 (int128 x) internal pure returns (int256) {
    unchecked {
      return int256 (x) << 64;
    }
  }

  /**
   * Calculate x + y.  Revert on overflow.
   *
   * @param x signed 64.64-bit fixed point number
   * @param y signed 64.64-bit fixed point number
   * @return signed 64.64-bit fixed point number
   */
  function add (int128 x, int128 y) internal pure returns (int128) {
    unchecked {
      int256 result = int256(x) + y;
      require (result >= MIN_64x64 && result <= MAX_64x64);
      return int128 (result);
    }
  }

  /**
   * Calculate x - y.  Revert on overflow.
   *
   * @param x signed 64.64-bit fixed point number
   * @param y signed 64.64-bit fixed point number
   * @return signed 64.64-bit fixed point number
   */
  function sub (int128 x, int128 y) internal pure returns (int128) {
    unchecked {
      int256 result = int256(x) - y;
      require (result >= MIN_64x64 && result <= MAX_64x64);
      return int128 (result);
    }
  }

  /**
   * Calculate x * y rounding down.  Revert on overflow.
   *
   * @param x signed 64.64-bit fixed point number
   * @param y signed 64.64-bit fixed point number
   * @return signed 64.64-bit fixed point number
   */
  function mul (int128 x, int128 y) internal pure returns (int128) {
    unchecked {
      int256 result = int256(x) * y >> 64;
      require (result >= MIN_64x64 && result <= MAX_64x64);
      return int128 (result);
    }
  }

  /**
   * Calculate x * y rounding towards zero, where x is signed 64.64 fixed point
   * number and y is signed 256-bit integer number.  Revert on overflow.
   *
   * @param x signed 64.64 fixed point number
   * @param y signed 256-bit integer number
   * @return signed 256-bit integer number
   */
  function muli (int128 x, int256 y) internal pure returns (int256) {
    unchecked {
      if (x == MIN_64x64) {
        require (y >= -0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF &&
          y <= 0x1000000000000000000000000000000000000000000000000);
        return -y << 63;
      } else {
        bool negativeResult = false;
        if (x < 0) {
          x = -x;
          negativeResult = true;
        }
        if (y < 0) {
          y = -y; // We rely on overflow behavior here
          negativeResult = !negativeResult;
        }
        uint256 absoluteResult = mulu (x, uint256 (y));
        if (negativeResult) {
          require (absoluteResult <=
            0x8000000000000000000000000000000000000000000000000000000000000000);
          return -int256 (absoluteResult); // We rely on overflow behavior here
        } else {
          require (absoluteResult <=
            0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
          return int256 (absoluteResult);
        }
      }
    }
  }

  /**
   * Calculate x * y rounding down, where x is signed 64.64 fixed point number
   * and y is unsigned 256-bit integer number.  Revert on overflow.
   *
   * @param x signed 64.64 fixed point number
   * @param y unsigned 256-bit integer number
   * @return unsigned 256-bit integer number
   */
  function mulu (int128 x, uint256 y) internal pure returns (uint256) {
    unchecked {
      if (y == 0) return 0;

      require (x >= 0);

      uint256 lo = (uint256 (int256 (x)) * (y & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)) >> 64;
      uint256 hi = uint256 (int256 (x)) * (y >> 128);

      require (hi <= 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
      hi <<= 64;

      require (hi <=
        0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF - lo);
      return hi + lo;
    }
  }

  /**
   * Calculate x / y rounding towards zero.  Revert on overflow or when y is
   * zero.
   *
   * @param x signed 64.64-bit fixed point number
   * @param y signed 64.64-bit fixed point number
   * @return signed 64.64-bit fixed point number
   */
  function div (int128 x, int128 y) internal pure returns (int128) {
    unchecked {
      require (y != 0);
      int256 result = (int256 (x) << 64) / y;
      require (result >= MIN_64x64 && result <= MAX_64x64);
      return int128 (result);
    }
  }

  /**
   * Calculate x / y rounding towards zero, where x and y are signed 256-bit
   * integer numbers.  Revert on overflow or when y is zero.
   *
   * @param x signed 256-bit integer number
   * @param y signed 256-bit integer number
   * @return signed 64.64-bit fixed point number
   */
  function divi (int256 x, int256 y) internal pure returns (int128) {
    unchecked {
      require (y != 0);

      bool negativeResult = false;
      if (x < 0) {
        x = -x; // We rely on overflow behavior here
        negativeResult = true;
      }
      if (y < 0) {
        y = -y; // We rely on overflow behavior here
        negativeResult = !negativeResult;
      }
      uint128 absoluteResult = divuu (uint256 (x), uint256 (y));
      if (negativeResult) {
        require (absoluteResult <= 0x80000000000000000000000000000000);
        return -int128 (absoluteResult); // We rely on overflow behavior here
      } else {
        require (absoluteResult <= 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
        return int128 (absoluteResult); // We rely on overflow behavior here
      }
    }
  }

  /**
   * Calculate x / y rounding towards zero, where x and y are unsigned 256-bit
   * integer numbers.  Revert on overflow or when y is zero.
   *
   * @param x unsigned 256-bit integer number
   * @param y unsigned 256-bit integer number
   * @return signed 64.64-bit fixed point number
   */
  function divu (uint256 x, uint256 y) internal pure returns (int128) {
    unchecked {
      require (y != 0);
      uint128 result = divuu (x, y);
      require (result <= uint128 (MAX_64x64));
      return int128 (result);
    }
  }

  /**
   * Calculate -x.  Revert on overflow.
   *
   * @param x signed 64.64-bit fixed point number
   * @return signed 64.64-bit fixed point number
   */
  function neg (int128 x) internal pure returns (int128) {
    unchecked {
      require (x != MIN_64x64);
      return -x;
    }
  }

  /**
   * Calculate |x|.  Revert on overflow.
   *
   * @param x signed 64.64-bit fixed point number
   * @return signed 64.64-bit fixed point number
   */
  function abs (int128 x) internal pure returns (int128) {
    unchecked {
      require (x != MIN_64x64);
      return x < 0 ? -x : x;
    }
  }

  /**
   * Calculate 1 / x rounding towards zero.  Revert on overflow or when x is
   * zero.
   *
   * @param x signed 64.64-bit fixed point number
   * @return signed 64.64-bit fixed point number
   */
  function inv (int128 x) internal pure returns (int128) {
    unchecked {
      require (x != 0);
      int256 result = int256 (0x100000000000000000000000000000000) / x;
      require (result >= MIN_64x64 && result <= MAX_64x64);
      return int128 (result);
    }
  }

  /**
   * Calculate arithmetics average of x and y, i.e. (x + y) / 2 rounding down.
   *
   * @param x signed 64.64-bit fixed point number
   * @param y signed 64.64-bit fixed point number
   * @return signed 64.64-bit fixed point number
   */
  function avg (int128 x, int128 y) internal pure returns (int128) {
    unchecked {
      return int128 ((int256 (x) + int256 (y)) >> 1);
    }
  }

  /**
   * Calculate geometric average of x and y, i.e. sqrt (x * y) rounding down.
   * Revert on overflow or in case x * y is negative.
   *
   * @param x signed 64.64-bit fixed point number
   * @param y signed 64.64-bit fixed point number
   * @return signed 64.64-bit fixed point number
   */
  function gavg (int128 x, int128 y) internal pure returns (int128) {
    unchecked {
      int256 m = int256 (x) * int256 (y);
      require (m >= 0);
      require (m <
          0x4000000000000000000000000000000000000000000000000000000000000000);
      return int128 (sqrtu (uint256 (m)));
    }
  }

  /**
   * Calculate x^y assuming 0^0 is 1, where x is signed 64.64 fixed point number
   * and y is unsigned 256-bit integer number.  Revert on overflow.
   *
   * @param x signed 64.64-bit fixed point number
   * @param y uint256 value
   * @return signed 64.64-bit fixed point number
   */
  function pow (int128 x, uint256 y) internal pure returns (int128) {
    unchecked {
      bool negative = x < 0 && y & 1 == 1;

      uint256 absX = uint128 (x < 0 ? -x : x);
      uint256 absResult;
      absResult = 0x100000000000000000000000000000000;

      if (absX <= 0x10000000000000000) {
        absX <<= 63;
        while (y != 0) {
          if (y & 0x1 != 0) {
            absResult = absResult * absX >> 127;
          }
          absX = absX * absX >> 127;

          if (y & 0x2 != 0) {
            absResult = absResult * absX >> 127;
          }
          absX = absX * absX >> 127;

          if (y & 0x4 != 0) {
            absResult = absResult * absX >> 127;
          }
          absX = absX * absX >> 127;

          if (y & 0x8 != 0) {
            absResult = absResult * absX >> 127;
          }
          absX = absX * absX >> 127;

          y >>= 4;
        }

        absResult >>= 64;
      } else {
        uint256 absXShift = 63;
        if (absX < 0x1000000000000000000000000) { absX <<= 32; absXShift -= 32; }
        if (absX < 0x10000000000000000000000000000) { absX <<= 16; absXShift -= 16; }
        if (absX < 0x1000000000000000000000000000000) { absX <<= 8; absXShift -= 8; }
        if (absX < 0x10000000000000000000000000000000) { absX <<= 4; absXShift -= 4; }
        if (absX < 0x40000000000000000000000000000000) { absX <<= 2; absXShift -= 2; }
        if (absX < 0x80000000000000000000000000000000) { absX <<= 1; absXShift -= 1; }

        uint256 resultShift = 0;
        while (y != 0) {
          require (absXShift < 64);

          if (y & 0x1 != 0) {
            absResult = absResult * absX >> 127;
            resultShift += absXShift;
            if (absResult > 0x100000000000000000000000000000000) {
              absResult >>= 1;
              resultShift += 1;
            }
          }
          absX = absX * absX >> 127;
          absXShift <<= 1;
          if (absX >= 0x100000000000000000000000000000000) {
              absX >>= 1;
              absXShift += 1;
          }

          y >>= 1;
        }

        require (resultShift < 64);
        absResult >>= 64 - resultShift;
      }
      int256 result = negative ? -int256 (absResult) : int256 (absResult);
      require (result >= MIN_64x64 && result <= MAX_64x64);
      return int128 (result);
    }
  }

  /**
   * Calculate sqrt (x) rounding down.  Revert if x < 0.
   *
   * @param x signed 64.64-bit fixed point number
   * @return signed 64.64-bit fixed point number
   */
  function sqrt (int128 x) internal pure returns (int128) {
    unchecked {
      require (x >= 0);
      return int128 (sqrtu (uint256 (int256 (x)) << 64));
    }
  }

  /**
   * Calculate binary logarithm of x.  Revert if x <= 0.
   *
   * @param x signed 64.64-bit fixed point number
   * @return signed 64.64-bit fixed point number
   */
  function log_2 (int128 x) internal pure returns (int128) {
    unchecked {
      require (x > 0);

      int256 msb = 0;
      int256 xc = x;
      if (xc >= 0x10000000000000000) { xc >>= 64; msb += 64; }
      if (xc >= 0x100000000) { xc >>= 32; msb += 32; }
      if (xc >= 0x10000) { xc >>= 16; msb += 16; }
      if (xc >= 0x100) { xc >>= 8; msb += 8; }
      if (xc >= 0x10) { xc >>= 4; msb += 4; }
      if (xc >= 0x4) { xc >>= 2; msb += 2; }
      if (xc >= 0x2) msb += 1;  // No need to shift xc anymore

      int256 result = msb - 64 << 64;
      uint256 ux = uint256 (int256 (x)) << uint256 (127 - msb);
      for (int256 bit = 0x8000000000000000; bit > 0; bit >>= 1) {
        ux *= ux;
        uint256 b = ux >> 255;
        ux >>= 127 + b;
        result += bit * int256 (b);
      }

      return int128 (result);
    }
  }

  /**
   * Calculate natural logarithm of x.  Revert if x <= 0.
   *
   * @param x signed 64.64-bit fixed point number
   * @return signed 64.64-bit fixed point number
   */
  function ln (int128 x) internal pure returns (int128) {
    unchecked {
      require (x > 0);

      return int128 (int256 (
          uint256 (int256 (log_2 (x))) * 0xB17217F7D1CF79ABC9E3B39803F2F6AF >> 128));
    }
  }

  /**
   * Calculate binary exponent of x.  Revert on overflow.
   *
   * @param x signed 64.64-bit fixed point number
   * @return signed 64.64-bit fixed point number
   */
  function exp_2 (int128 x) internal pure returns (int128) {
    unchecked {
      require (x < 0x400000000000000000); // Overflow

      if (x < -0x400000000000000000) return 0; // Underflow

      uint256 result = 0x80000000000000000000000000000000;

      if (x & 0x8000000000000000 > 0)
        result = result * 0x16A09E667F3BCC908B2FB1366EA957D3E >> 128;
      if (x & 0x4000000000000000 > 0)
        result = result * 0x1306FE0A31B7152DE8D5A46305C85EDEC >> 128;
      if (x & 0x2000000000000000 > 0)
        result = result * 0x1172B83C7D517ADCDF7C8C50EB14A791F >> 128;
      if (x & 0x1000000000000000 > 0)
        result = result * 0x10B5586CF9890F6298B92B71842A98363 >> 128;
      if (x & 0x800000000000000 > 0)
        result = result * 0x1059B0D31585743AE7C548EB68CA417FD >> 128;
      if (x & 0x400000000000000 > 0)
        result = result * 0x102C9A3E778060EE6F7CACA4F7A29BDE8 >> 128;
      if (x & 0x200000000000000 > 0)
        result = result * 0x10163DA9FB33356D84A66AE336DCDFA3F >> 128;
      if (x & 0x100000000000000 > 0)
        result = result * 0x100B1AFA5ABCBED6129AB13EC11DC9543 >> 128;
      if (x & 0x80000000000000 > 0)
        result = result * 0x10058C86DA1C09EA1FF19D294CF2F679B >> 128;
      if (x & 0x40000000000000 > 0)
        result = result * 0x1002C605E2E8CEC506D21BFC89A23A00F >> 128;
      if (x & 0x20000000000000 > 0)
        result = result * 0x100162F3904051FA128BCA9C55C31E5DF >> 128;
      if (x & 0x10000000000000 > 0)
        result = result * 0x1000B175EFFDC76BA38E31671CA939725 >> 128;
      if (x & 0x8000000000000 > 0)
        result = result * 0x100058BA01FB9F96D6CACD4B180917C3D >> 128;
      if (x & 0x4000000000000 > 0)
        result = result * 0x10002C5CC37DA9491D0985C348C68E7B3 >> 128;
      if (x & 0x2000000000000 > 0)
        result = result * 0x1000162E525EE054754457D5995292026 >> 128;
      if (x & 0x1000000000000 > 0)
        result = result * 0x10000B17255775C040618BF4A4ADE83FC >> 128;
      if (x & 0x800000000000 > 0)
        result = result * 0x1000058B91B5BC9AE2EED81E9B7D4CFAB >> 128;
      if (x & 0x400000000000 > 0)
        result = result * 0x100002C5C89D5EC6CA4D7C8ACC017B7C9 >> 128;
      if (x & 0x200000000000 > 0)
        result = result * 0x10000162E43F4F831060E02D839A9D16D >> 128;
      if (x & 0x100000000000 > 0)
        result = result * 0x100000B1721BCFC99D9F890EA06911763 >> 128;
      if (x & 0x80000000000 > 0)
        result = result * 0x10000058B90CF1E6D97F9CA14DBCC1628 >> 128;
      if (x & 0x40000000000 > 0)
        result = result * 0x1000002C5C863B73F016468F6BAC5CA2B >> 128;
      if (x & 0x20000000000 > 0)
        result = result * 0x100000162E430E5A18F6119E3C02282A5 >> 128;
      if (x & 0x10000000000 > 0)
        result = result * 0x1000000B1721835514B86E6D96EFD1BFE >> 128;
      if (x & 0x8000000000 > 0)
        result = result * 0x100000058B90C0B48C6BE5DF846C5B2EF >> 128;
      if (x & 0x4000000000 > 0)
        result = result * 0x10000002C5C8601CC6B9E94213C72737A >> 128;
      if (x & 0x2000000000 > 0)
        result = result * 0x1000000162E42FFF037DF38AA2B219F06 >> 128;
      if (x & 0x1000000000 > 0)
        result = result * 0x10000000B17217FBA9C739AA5819F44F9 >> 128;
      if (x & 0x800000000 > 0)
        result = result * 0x1000000058B90BFCDEE5ACD3C1CEDC823 >> 128;
      if (x & 0x400000000 > 0)
        result = result * 0x100000002C5C85FE31F35A6A30DA1BE50 >> 128;
      if (x & 0x200000000 > 0)
        result = result * 0x10000000162E42FF0999CE3541B9FFFCF >> 128;
      if (x & 0x100000000 > 0)
        result = result * 0x100000000B17217F80F4EF5AADDA45554 >> 128;
      if (x & 0x80000000 > 0)
        result = result * 0x10000000058B90BFBF8479BD5A81B51AD >> 128;
      if (x & 0x40000000 > 0)
        result = result * 0x1000000002C5C85FDF84BD62AE30A74CC >> 128;
      if (x & 0x20000000 > 0)
        result = result * 0x100000000162E42FEFB2FED257559BDAA >> 128;
      if (x & 0x10000000 > 0)
        result = result * 0x1000000000B17217F7D5A7716BBA4A9AE >> 128;
      if (x & 0x8000000 > 0)
        result = result * 0x100000000058B90BFBE9DDBAC5E109CCE >> 128;
      if (x & 0x4000000 > 0)
        result = result * 0x10000000002C5C85FDF4B15DE6F17EB0D >> 128;
      if (x & 0x2000000 > 0)
        result = result * 0x1000000000162E42FEFA494F1478FDE05 >> 128;
      if (x & 0x1000000 > 0)
        result = result * 0x10000000000B17217F7D20CF927C8E94C >> 128;
      if (x & 0x800000 > 0)
        result = result * 0x1000000000058B90BFBE8F71CB4E4B33D >> 128;
      if (x & 0x400000 > 0)
        result = result * 0x100000000002C5C85FDF477B662B26945 >> 128;
      if (x & 0x200000 > 0)
        result = result * 0x10000000000162E42FEFA3AE53369388C >> 128;
      if (x & 0x100000 > 0)
        result = result * 0x100000000000B17217F7D1D351A389D40 >> 128;
      if (x & 0x80000 > 0)
        result = result * 0x10000000000058B90BFBE8E8B2D3D4EDE >> 128;
      if (x & 0x40000 > 0)
        result = result * 0x1000000000002C5C85FDF4741BEA6E77E >> 128;
      if (x & 0x20000 > 0)
        result = result * 0x100000000000162E42FEFA39FE95583C2 >> 128;
      if (x & 0x10000 > 0)
        result = result * 0x1000000000000B17217F7D1CFB72B45E1 >> 128;
      if (x & 0x8000 > 0)
        result = result * 0x100000000000058B90BFBE8E7CC35C3F0 >> 128;
      if (x & 0x4000 > 0)
        result = result * 0x10000000000002C5C85FDF473E242EA38 >> 128;
      if (x & 0x2000 > 0)
        result = result * 0x1000000000000162E42FEFA39F02B772C >> 128;
      if (x & 0x1000 > 0)
        result = result * 0x10000000000000B17217F7D1CF7D83C1A >> 128;
      if (x & 0x800 > 0)
        result = result * 0x1000000000000058B90BFBE8E7BDCBE2E >> 128;
      if (x & 0x400 > 0)
        result = result * 0x100000000000002C5C85FDF473DEA871F >> 128;
      if (x & 0x200 > 0)
        result = result * 0x10000000000000162E42FEFA39EF44D91 >> 128;
      if (x & 0x100 > 0)
        result = result * 0x100000000000000B17217F7D1CF79E949 >> 128;
      if (x & 0x80 > 0)
        result = result * 0x10000000000000058B90BFBE8E7BCE544 >> 128;
      if (x & 0x40 > 0)
        result = result * 0x1000000000000002C5C85FDF473DE6ECA >> 128;
      if (x & 0x20 > 0)
        result = result * 0x100000000000000162E42FEFA39EF366F >> 128;
      if (x & 0x10 > 0)
        result = result * 0x1000000000000000B17217F7D1CF79AFA >> 128;
      if (x & 0x8 > 0)
        result = result * 0x100000000000000058B90BFBE8E7BCD6D >> 128;
      if (x & 0x4 > 0)
        result = result * 0x10000000000000002C5C85FDF473DE6B2 >> 128;
      if (x & 0x2 > 0)
        result = result * 0x1000000000000000162E42FEFA39EF358 >> 128;
      if (x & 0x1 > 0)
        result = result * 0x10000000000000000B17217F7D1CF79AB >> 128;

      result >>= uint256 (int256 (63 - (x >> 64)));
      require (result <= uint256 (int256 (MAX_64x64)));

      return int128 (int256 (result));
    }
  }

  /**
   * Calculate natural exponent of x.  Revert on overflow.
   *
   * @param x signed 64.64-bit fixed point number
   * @return signed 64.64-bit fixed point number
   */
  function exp (int128 x) internal pure returns (int128) {
    unchecked {
      require (x < 0x400000000000000000); // Overflow

      if (x < -0x400000000000000000) return 0; // Underflow

      return exp_2 (
          int128 (int256 (x) * 0x171547652B82FE1777D0FFDA0D23A7D12 >> 128));
    }
  }

  /**
   * Calculate x / y rounding towards zero, where x and y are unsigned 256-bit
   * integer numbers.  Revert on overflow or when y is zero.
   *
   * @param x unsigned 256-bit integer number
   * @param y unsigned 256-bit integer number
   * @return unsigned 64.64-bit fixed point number
   */
  function divuu (uint256 x, uint256 y) private pure returns (uint128) {
    unchecked {
      require (y != 0);

      uint256 result;

      if (x <= 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)
        result = (x << 64) / y;
      else {
        uint256 msb = 192;
        uint256 xc = x >> 192;
        if (xc >= 0x100000000) { xc >>= 32; msb += 32; }
        if (xc >= 0x10000) { xc >>= 16; msb += 16; }
        if (xc >= 0x100) { xc >>= 8; msb += 8; }
        if (xc >= 0x10) { xc >>= 4; msb += 4; }
        if (xc >= 0x4) { xc >>= 2; msb += 2; }
        if (xc >= 0x2) msb += 1;  // No need to shift xc anymore

        result = (x << 255 - msb) / ((y - 1 >> msb - 191) + 1);
        require (result <= 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);

        uint256 hi = result * (y >> 128);
        uint256 lo = result * (y & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);

        uint256 xh = x >> 192;
        uint256 xl = x << 64;

        if (xl < lo) xh -= 1;
        xl -= lo; // We rely on overflow behavior here
        lo = hi << 128;
        if (xl < lo) xh -= 1;
        xl -= lo; // We rely on overflow behavior here

        result += xh == hi >> 128 ? xl / y : 1;
      }

      require (result <= 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
      return uint128 (result);
    }
  }

  /**
   * Calculate sqrt (x) rounding down, where x is unsigned 256-bit integer
   * number.
   *
   * @param x unsigned 256-bit integer number
   * @return unsigned 128-bit integer number
   */
  function sqrtu (uint256 x) private pure returns (uint128) {
    unchecked {
      if (x == 0) return 0;
      else {
        uint256 xx = x;
        uint256 r = 1;
        if (xx >= 0x100000000000000000000000000000000) { xx >>= 128; r <<= 64; }
        if (xx >= 0x10000000000000000) { xx >>= 64; r <<= 32; }
        if (xx >= 0x100000000) { xx >>= 32; r <<= 16; }
        if (xx >= 0x10000) { xx >>= 16; r <<= 8; }
        if (xx >= 0x100) { xx >>= 8; r <<= 4; }
        if (xx >= 0x10) { xx >>= 4; r <<= 2; }
        if (xx >= 0x4) { r <<= 1; }
        r = (r + x / r) >> 1;
        r = (r + x / r) >> 1;
        r = (r + x / r) >> 1;
        r = (r + x / r) >> 1;
        r = (r + x / r) >> 1;
        r = (r + x / r) >> 1;
        r = (r + x / r) >> 1; // Seven iterations should be enough
        uint256 r1 = x / r;
        return uint128 (r < r1 ? r : r1);
      }
    }
  }
}

File 16 of 19 : INFTDataOperator.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

/**************************************

    security-contact:
    - [email protected]

    maintainers:
    - [email protected]
    - [email protected]
    - [email protected]
    - [email protected]

    contributors:
    - [email protected]

**************************************/

/// @dev Abstract contract used in the 'NFTDataOperator' contract.
abstract contract INFTDataOperator {

    // -----------------------------------------------------------------------
    //                                Errors
    // -----------------------------------------------------------------------
    
    error Unauthorized();

    error MaxCapMustBeGreaterThanMinCap();

    error MinCapMustBeLowerThanMaxCap();

    // -----------------------------------------------------------------------
    //                               Structs
    // -----------------------------------------------------------------------

    /// @dev Used in 'fulfillTholPerNft' function as parameter.
    struct Request {
        /// @dev Current NFT collection floor price in WETH.
        uint128 currentFloorPrice;
        /// @dev NFT collection floor price 30 days ago in WETH.
        uint128 previousFloorPrice;
        /// @dev NFT collection volume in current month (0 - 30 days ago) in WETH.
        uint128 currentVolume;
        /// @dev NFT collection volume in previous month (30 - 60 days ago) in WETH.
        uint128 previousVolume;
    }

    // -----------------------------------------------------------------------
    //                                Events
    // -----------------------------------------------------------------------

    event LocalMaxPercentageUpdated(int128 value);

    event LocalMinPercentageUpdated(int128 value);

    event TholPerNftFulfilled(uint96 tholPerNft, uint256 timestamp);

    // -----------------------------------------------------------------------
    //                           Public functions
    // -----------------------------------------------------------------------

    // Calculate THOL amount for given WETH amount.
    function calculateWethToThol(uint128 currentFloorPrice) public virtual view returns (uint256 tholAmount);

    // -----------------------------------------------------------------------
    //                          External functions
    // -----------------------------------------------------------------------

    // Calculate and set 'tholPerNft' in the staking contract.
    function fulfillTholPerNft(Request memory request) external virtual;

}

File 17 of 19 : IStaking.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

/**************************************

    security-contact:
    - [email protected]

    maintainers:
    - [email protected]
    - [email protected]
    - [email protected]
    - [email protected]

    contributors:
    - [email protected]

**************************************/

/**************************************

    Staking interface

 **************************************/

abstract contract IStaking {

    // -----------------------------------------------------------------------
    //                              Structs
    // -----------------------------------------------------------------------
    
    /**************************************

        Compounding struct

        ------------------------------

        @param rate Q64.64 compounding index
        @param dapy current value of deflationary APY
        @param extraRate byte encoded index for staking extensions
        @param ts timestamp of last compounding
        @param freeRewards last snapshot of free rewards

     **************************************/

    struct Compounding {
        int128 rate;
        int128 dapy;
        bytes32 extraRate;
        uint128 ts;
        uint96 freeRewards;
    }

    /**************************************

        Balance struct

        ------------------------------

        @param amount deposited erc20 and is constantly increased by yield during compounding
        @param compoundingSnapshot value of compounding rate at given time
        @param extraSnapshot value of extra rewards rate at given time

     **************************************/

    struct Balance {
        uint96 amount; // @dev 2**96 > total supply of $THOL
        int128 compoundingSnapshot;
        bytes32 extraSnapshot;
    }

    // -----------------------------------------------------------------------
    //                              Events
    // -----------------------------------------------------------------------

    event Deposit(
        address indexed sender,
        uint96 amount,
        bytes extraAmount,
        uint96 rewards
    );
    event Withdrawal(
        address indexed sender,
        uint96 amount,
        bytes extraAmount,
        uint96 rewards
    );
    event Compounded(
        Compounding compounding
    );

    // -----------------------------------------------------------------------
    //                              Errors
    // -----------------------------------------------------------------------

    error UninitializedRewardPool();
    error CompoundingNotReady(uint256 required, uint128 now);
    error NoMoreRewardsLeft();
    error InsufficientRewards(uint96 compoundRewards, uint96 freeRewards);

    // -----------------------------------------------------------------------
    //                              External
    // -----------------------------------------------------------------------

    /**************************************

        Deposit sender funds

    **************************************/

    function deposit(uint96 _amount, bytes memory _extraAmount) external virtual;

    /**************************************

        Withdraw sender funds

    **************************************/

    function withdraw(uint96 _amount, bytes memory _extraAmount) external virtual;

    /**************************************

        Compound

    **************************************/

    function compound() external virtual;

    /**************************************

        View functions

    **************************************/

    // Get total available balance
    function balanceOf(address _account) external virtual view returns (uint96);

    // -----------------------------------------------------------------------
    //                              Public
    // -----------------------------------------------------------------------

    /**************************************

        View functions

    **************************************/

    // Get free rewards
    function freeRewards() public virtual view returns (uint96);

    // Get compounded base rewards
    function userBaseRewards(address _account) public virtual view returns (uint96);

    // Get compounded extra rewards
    function userExtraRewards(address _account) public virtual view returns (uint96);

    // Get total amount from rewards
    function rewardOf(address _account) public virtual view returns (uint96);

    // -----------------------------------------------------------------------
    //                              Internal
    // -----------------------------------------------------------------------

    /**************************************

        Abstract functions: core

    **************************************/

    // Deposit
    function _deposit(uint96 _amount, bytes memory _extraAmount) internal virtual;

    // Withdraw
    function _withdraw(uint96 _amount, bytes memory _extraAmount) internal virtual;

    // Check balance
    function _checkBalance(uint96 _amount, bytes memory _extraAmount) internal virtual;

    // Increase balance
    function _increaseBalance(uint96 _amount, bytes memory _extraAmount) internal virtual;

    // Decrease balance
    function _decreaseBalance(uint96 _amount, bytes memory _extraAmount) internal virtual;

    /**************************************

        Abstract functions: rewards

    **************************************/

    // Reward pool withdraw
    function _rewardPoolWithdraw(address _receiver, uint256 _amount) internal virtual;
    
    // Reward pool info
    function _rewardPoolInfo() internal virtual view returns (uint96);

    /**************************************

        Abstract functions: extra

    **************************************/

    // Get compounded extra rewards
    function _userExtraRewards(address _account) internal virtual view
    returns (uint96);

    // Get total available extra
    function _getExtraSum() internal virtual view returns (uint96);

    // Calculate extra rewards and extra ratio for sum
    function _calculateExtraRewards(uint96 _extraSum, int128 _ipy) internal virtual view
    returns (uint96, bytes32);

    // Increment rate
    function _incrementExtraRate(bytes32 _existingRate, bytes32 _incrementRate) internal virtual pure
    returns (bytes32);

}

File 18 of 19 : ITholosStaking.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

/**************************************

    security-contact:
    - [email protected]

    maintainers:
    - [email protected]
    - [email protected]
    - [email protected]
    - [email protected]

    contributors:
    - [email protected]

**************************************/

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

/**************************************

    Staking interface

 **************************************/

abstract contract ITholosStaking is IStaking {

    // -----------------------------------------------------------------------
    //                              Structs
    // -----------------------------------------------------------------------

    /**************************************

        Unstake request struct

        ------------------------------

        @param amount number of tokens which is desired to be unstaked
        @param deadline deadline before which request can't be executed

     **************************************/

    struct UnstakeRequest {
        uint64 deadline;
        uint96 amount;
    }

    // -----------------------------------------------------------------------
    //                              Errors
    // -----------------------------------------------------------------------

    // errors
    error InvalidDeposit();
    error NotEnoughAllowance(address sender, uint96 amount);
    error NotEnoughNFTAllowance(address sender);
    error InvalidWithdrawal(); // 0xc945242d
    error BalanceSmallerThanAmount(address sender, uint96 balance, uint96 amount); // 0xaa991ed1
    error MissingNFT(address sender, uint256 tokenId); // 0x1f8cc0fb
    error TooManyUnstakeRequested(address sender);
    error NothingToUnstake();

    // -----------------------------------------------------------------------
    //                              Events
    // -----------------------------------------------------------------------

    // events
    event TholPerNftUpdated(uint96 value);
    event MaxRewardForNftsUpdated(uint96 value);
    event UnstakeClaimed(address indexed sender, uint96 totalAmount);

    // -----------------------------------------------------------------------
    //                              External
    // -----------------------------------------------------------------------

    /**************************************

        Set $THOL per NFT

    **************************************/

    function setTholPerNft(uint96 _tholPerNft) external virtual;

    /**************************************

        Set max reward cap for NFT

    **************************************/

    function setMaxNftRewardCap(uint96 _value) external virtual;

}

File 19 of 19 : Configurable.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

/**************************************

    security-contact:
    - [email protected]

    maintainers:
    - [email protected]
    - [email protected]
    - [email protected]
    - [email protected]

    contributors:
    - [email protected]

**************************************/

/**************************************
    
    Configurable utility

**************************************/

abstract contract Configurable {
    
    // enum
    enum State {
        UNCONFIGURED,
        CONFIGURED
    }

    // storage
    State public state;

    // events
    event Initialised(bytes args);
    event Configured(bytes args);
    
    // errors
    error InvalidState(State state, State expected);

    // modifiers
    modifier onlyInState(State _state) {
        
        // check state
        if (state != _state) {
            revert InvalidState(state, _state);
        }

        // enter function
        _;

    }

    // abstracts
    function configure(bytes calldata) external virtual;

}

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

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"bytes","name":"_arguments","type":"bytes"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"enum Configurable.State","name":"state","type":"uint8"},{"internalType":"enum Configurable.State","name":"expected","type":"uint8"}],"name":"InvalidState","type":"error"},{"inputs":[],"name":"MaxCapMustBeGreaterThanMinCap","type":"error"},{"inputs":[],"name":"MinCapMustBeLowerThanMaxCap","type":"error"},{"inputs":[],"name":"T","type":"error"},{"inputs":[],"name":"Unauthorized","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes","name":"args","type":"bytes"}],"name":"Configured","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes","name":"args","type":"bytes"}],"name":"Initialised","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"int128","name":"value","type":"int128"}],"name":"LocalMaxPercentageUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"int128","name":"value","type":"int128"}],"name":"LocalMinPercentageUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint96","name":"tholPerNft","type":"uint96"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"TholPerNftFulfilled","type":"event"},{"inputs":[{"internalType":"uint128","name":"_currentFloorPrice","type":"uint128"}],"name":"calculateWethToThol","outputs":[{"internalType":"uint256","name":"tholAmount_","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"_arguments","type":"bytes"}],"name":"configure","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"dataProvider","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint128","name":"currentFloorPrice","type":"uint128"},{"internalType":"uint128","name":"previousFloorPrice","type":"uint128"},{"internalType":"uint128","name":"currentVolume","type":"uint128"},{"internalType":"uint128","name":"previousVolume","type":"uint128"}],"internalType":"struct INFTDataOperator.Request","name":"_request","type":"tuple"}],"name":"fulfillTholPerNft","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"localMaxPercentage","outputs":[{"internalType":"int128","name":"","type":"int128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"localMinPercentage","outputs":[{"internalType":"int128","name":"","type":"int128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"staking","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"state","outputs":[{"internalType":"enum Configurable.State","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"thol","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tholWethPool","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"int128","name":"_value","type":"int128"}],"name":"updateLocalMaxPercentage","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"int128","name":"_value","type":"int128"}],"name":"updateLocalMinPercentage","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"weth","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}]

60a0604052346200016a57620017a2803803806200001d8162000185565b92833981019060209182828203126200016a5781516001600160401b03928382116200016a57019281601f850112156200016a5783519283116200016f57601f199362000071601f85018616830162000185565b93808552828501938382840101116200016a578383620000929301620001ab565b60008054336001600160a01b031982168117835560405195926001600160a01b039290919083167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08380a38383805181010312620001675784519182168092036200016757506040936200013f86947f2cea719fa16cdee2f0b507f5aa500d4513a695b244f6f58c4e24ab68ba482f159894601f94608052818752519283809288015287870190620001ab565b01168101030190a16040516115d19081620001d182396080518181816104e701526112960152f35b80fd5b600080fd5b634e487b7160e01b600052604160045260246000fd5b6040519190601f01601f191682016001600160401b038111838210176200016f57604052565b60005b838110620001bf5750506000910152565b8181015183820152602001620001ae56fe608060408181526004918236101561001657600080fd5b600092833560e01c9182631f7e0d211461079d575081633fc8cef31461077457816346739e73146105165781634cf088d9146104d25781636fa18611146104aa578163715018a61461044d5781638da5cb5b1461042557816396d0d93b146103fc578163a37a86f31461036f578163b334ed8614610346578163b91d26c1146102b4578163bb2ef64014610221578163c19d93fb146101f7578163f2fde38b1461012857508063f78fce04146101045763fc205c13146100d557600080fd5b34610100576020366003190112610100576020906100f96100f4610810565b6108ce565b9051908152f35b5080fd5b503461010057816003193601126101005760209060055460801d905190600f0b8152f35b919050346101f35760203660031901126101f3576001600160a01b038235818116939192908490036101ef5761015c61084e565b831561019d57505082546001600160a01b0319811683178455167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08380a380f35b906020608492519162461bcd60e51b8352820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152fd5b8480fd5b8280fd5b50503461010057816003193601126101005761021f60ff6020935460a01c169151809261082b565bf35b919050346101f35760203660031901126101f35781359182600f0b928381036101ef5761024c61084e565b600554918260801d600f0b8513156102a65750917f7a540a43310e9a18ce355055fb7867169ed59fcd13b24848cb0afb56bb9d2ffb93916020936001600160801b0316906001600160801b0319161760055551908152a180f35b835163768a39a760e01b8152fd5b9050346101f35760803660031901126101f3578151916102d3836107bc565b6102db610810565b83526001600160801b0360243581811681036103425760208501526044358181168103610342578285015260643590811681036101ef5760608401526001546001600160a01b0316330361033657836103338461120e565b80f35b516282b42960e81b8152fd5b8580fd5b50503461010057816003193601126101005760015490516001600160a01b039091168152602090f35b919050346101f35760203660031901126101f35781359182600f0b928381036101ef5761039a61084e565b6005549182600f0b8512156103ee5750917fbfad55c65286ecfe7e1bc56ed83022c32201fe540cbc7ef72b14c8ac6d81440b93916001600160801b0360209481199060801b1691161760055551908152a180f35b8351633d50699d60e21b8152fd5b50503461010057816003193601126101005760025490516001600160a01b039091168152602090f35b505034610100578160031936011261010057905490516001600160a01b039091168152602090f35b83346104a757806003193601126104a75761046661084e565b80546001600160a01b03198116825581906001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a380f35b80fd5b9050346101f357826003193601126101f3575490516001600160a01b03909116815260209150f35b505034610100578160031936011261010057517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b83833461010057602090816003193601126101f35767ffffffffffffffff9380358581116101ef57366023820112156101ef578082013595861161076157825191601f199661056c8689601f84011601856107ee565b80845285840192366024838301011161072657818892602489930186378501015261059561084e565b60ff865460a01c16600281101561074e578061072a575082805181010361010092838212610726576105c6906108a6565b906105d28686016108a6565b906105df606087016108a6565b9160806105ed8189016108a6565b92607f19011261072257906106a8959493929161064489519661060f886107bc565b61061b60a08b016108ba565b885261062960c08b016108ba565b8c89015261063960e08b016108ba565b8b89015289016108ba565b606087015260018060a01b0392838092816001600160601b0360a01b9716876001541617600155168560025416176002551683600354161760035516908254161790557740000000000000000000000000000004000000000000000060055561120e565b835460ff60a01b1916600160a01b1784558151838152815184820181905290939091855b83811061070f575050508394601f827f69e4b643748df9006fc37ef3f1b56ca47e33f040690f26d5d66385958c3faeef968587958601015201168101030190a180f35b81810183015186820186015282016106cc565b8980fd5b8780fd5b9086610747604493875193633bf2e2f960e11b855284019061082b565b6024820152fd5b634e487b7160e01b875260218252602487fd5b634e487b7160e01b855260418252602485fd5b50503461010057816003193601126101005760035490516001600160a01b039091168152602090f35b849034610100578160031936011261010057602090600554600f0b8152f35b6080810190811067ffffffffffffffff8211176107d857604052565b634e487b7160e01b600052604160045260246000fd5b90601f8019910116810190811067ffffffffffffffff8211176107d857604052565b600435906001600160801b038216820361082657565b600080fd5b9060028210156108385752565b634e487b7160e01b600052602160045260246000fd5b6000546001600160a01b0316330361086257565b606460405162461bcd60e51b815260206004820152602060248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152fd5b51906001600160a01b038216820361082657565b51906001600160801b038216820361082657565b600254604080519167ffffffffffffffff916001600160a01b03918216916000906060860185811187821017610fa557839692965260028252602080968184019585368837816001978861092188610fd1565b528161092c88610ff4565b52875192839163883bdbfd60e01b83526024988984019060049e8f86015251809152604484019190855b8d8a838310610f8757505050505082809103915afa978815610f7d5782918399610e77575b505061099061098982610ff4565b5191610fd1565b5160060b9060060b0396667fffffffffffff8813667fffffffffffff19891217610e6557836109ca816109c284610ff4565b511692610fd1565b5116900390838211610e5357508660060b9660020b9686600082129182610e44575b5050610e1a575b811b640100000000600160c01b031615610e0657816003541693828854169560009760020b888112600014610e00578089035b620d89e88111610df05789919083811615610dde576001600160881b036ffffcb933bd6fad37aa2d162d1a5940015b169460028216610dc2575b8c8216610da6575b60088216610d8a575b60108216610d6e575b868216610d52575b8116610d36575b608090818116610d1b575b6101008116610d00575b6102008116610ce5575b6104008116610cca575b6108008116610caf575b6110008116610c94575b6120008116610c79575b6140008116610c5e575b6180008116610c43575b620100008116610c28575b620200008116610c0e575b620400008116610bf4575b6208000016610bdb575b5013610bb8575b63ffffffff8216610bb0575060ff875b16911c0116946001600160801b039485871115600014610b85575085800295808704811490151715610b725750501015610b6857610b659216906111a3565b90565b610b659216611128565b601190634e487b7160e01b600052526000fd5b95610b939250809150611004565b93501015610ba657610b659216906110dd565b610b659216611054565b60ff90610b26565b908015610bc9576000190490610b16565b634e487b7160e01b8852601289528488fd5b90936b048a170391f7dc42444e8fa202901c9238610b0f565b6d2216e584f5fa1ea926041bedfe98909502811c94610b05565b946e5d6af8dedb81196699c329225ee60402811c94610afa565b946f09aa508b5b7a84e1c677de54f3e99bc902811c94610aef565b946f31be135f97d08fd981231505542fcfa602811c94610ae4565b946f70d869a156d2a1b890bb3df62baf32f702811c94610ada565b946fa9f746462d870fdf8a65dc1f90e061e502811c94610ad0565b946fd097f3bdfd2022b8845ad8f792aa582502811c94610ac6565b946fe7159475a2c29b7443b29c7fa6e889d902811c94610abc565b946ff3392b0822b70005940c7a398e4b70f302811c94610ab2565b946ff987a7253ac413176f2b074cf7815e5402811c94610aa8565b946ffcbe86c7900a88aedcffc83b479aa3a402811c94610a9e565b946ffe5dee046a99a2a811c461f1969c305302811c94610a94565b936fff2ea16466c96a3843ec78b326b528610260801c93610a89565b946fff973b41fa98c081472e6896dfb254c00260801c94610a82565b946fffcb9843d60f6159c9db58835c9266440260801c94610a7a565b946fffe5caca7e10e4e61c3624eaa0941cd00260801c94610a71565b946ffff2e50f5f656932ef12357cf3c7fdcc0260801c94610a68565b946ffff97272373d413259a46990580e213a0260801c94610a60565b6001600160881b03600160801b610a55565b83516315e4079d60e11b81528b90fd5b80610a26565b82601288634e487b7160e01b600052526000fd5b95627fffff198114610e305760001901956109f3565b83601189634e487b7160e01b600052526000fd5b0760060b1515905086386109ec565b634e487b7160e01b8152601189528490fd5b634e487b7160e01b8252601189528482fd5b915097503d8083833e610e8a81836107ee565b81019786828a03126101f3578151818111610f5c5782019189601f84011215610f5c57825192610eb984610fb9565b93610ec68a5195866107ee565b808552868086019160051b830101918c8311610f79578701905b828210610f605750505084810151918211610f5c57019780601f8a0112156101f3578851610f0d81610fb9565b99610f1a89519b8c6107ee565b818b5285808c019260051b8201019283116101ef578501905b828210610f4457505050388061097b565b81518781168103610342578152908501908501610f33565b8380fd5b81518060060b8103610726578152908701908701610ee0565b8680fd5b86513d84823e3d90fd5b845163ffffffff1686528a9850899750948501949093019201610956565b634e487b7160e01b83526041600452602483fd5b67ffffffffffffffff81116107d85760051b60200190565b805115610fde5760200190565b634e487b7160e01b600052603260045260246000fd5b805160011015610fde5760400190565b6000198282099082810292838084109303918383039360009314611049576801000000000000000092848411156104a757500990828211900360c01b910360401c1790565b505090505060401c90565b600160801b91600019828409928260801b928380861095039480860395146110cf57848311156108265782910981806000031680920460028082600302188083028203028083028203028083028203028083028203028083028203028092029003029360018380600003040190848311900302920304170290565b505080925015610826570490565b600019828209908281029283808410930391838303936000931461111d57600160801b92848411156104a757500990828211900360801b910360801c1790565b505090505060801c90565b600160c01b91600019828409928260c01b928380861095039480860395146110cf57848311156108265782910981806000031680920460028082600302188083028203028083028203028083028203028083028203028083028203028092029003029360018380600003040190848311900302920304170290565b60001982820990828102928380841093039183830393600093146111e357600160c01b92848411156104a757500990828211900360401b910360c01c1790565b505090505060c01c90565b81156111f8570490565b634e487b7160e01b600052601260045260246000fd5b6001600160601b03906001600160801b038261122c828451166108ce565b169061125b60409361124a83868301511684606084015116906113c5565b9260208183511692015116906113c5565b600f0b90600f0b02821d9060016001607f1b031982121580611367575b15610826578361128e8261129494600f0b611378565b16611535565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690813b1561082657600093602485928551968793849263293352b160e11b845216958660048401525af1801561135c57611324575b7f52de59985c8ca6cc14f539089a9cf5f08595bbd4e279a3c671d42619aee0958492508151908152426020820152a1565b67ffffffffffffffff83116107d8577f52de59985c8ca6cc14f539089a9cf5f08595bbd4e279a3c671d42619aee095849282526112f3565b82513d6000823e3d90fd5b5060016001607f1b03821315611278565b81156113be57600f0b600090818112610100576001600160801b038316810260401c9260801c026001600160c01b0381116101005760401b90821982116104a757500190565b5050600090565b9080156108265760006001600160c01b03831161140e57506113e99160401b6111ee565b6001600160801b0390818111610826571660016001607f1b03811161082657600f0b90565b9060c083811c9384640100000000811015611528575b8062010000600292101561151c575b610100811015611510575b6010811015611504575b60048110156114f9575b10156114ef575b6114776000199282600185870160be1984011c019160ff031b6111ee565b946001600160801b0390818711610342578460801c870291851687029084819460401b918383106114e5575b505003948160801b938487106114db575b505060801c036114d0576114c892036111ee565b905b016113e9565b5050506001906114ca565b90920191386114b4565b01935084386114a3565b9060010190611459565b92810192811c611452565b6004938401931c611448565b6008938401931c61143e565b6010938401931c611433565b5060e0915080821c611424565b61156291600554906001600160601b039384809216826115588286600f0b611378565b169360801d611378565b169282168181111580611591575b1561157c575050905090565b839192501060001461158c575090565b905090565b508381101561157056fea2646970667358221220a597e7777b40927588553f21d91226251fe75fa30b25a733a830f1a0d32f17c864736f6c63430008110033000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000200000000000000000000000004ad1dbef3f6663d4db0be2d2aebcf77b2e9da016

Deployed Bytecode

0x608060408181526004918236101561001657600080fd5b600092833560e01c9182631f7e0d211461079d575081633fc8cef31461077457816346739e73146105165781634cf088d9146104d25781636fa18611146104aa578163715018a61461044d5781638da5cb5b1461042557816396d0d93b146103fc578163a37a86f31461036f578163b334ed8614610346578163b91d26c1146102b4578163bb2ef64014610221578163c19d93fb146101f7578163f2fde38b1461012857508063f78fce04146101045763fc205c13146100d557600080fd5b34610100576020366003190112610100576020906100f96100f4610810565b6108ce565b9051908152f35b5080fd5b503461010057816003193601126101005760209060055460801d905190600f0b8152f35b919050346101f35760203660031901126101f3576001600160a01b038235818116939192908490036101ef5761015c61084e565b831561019d57505082546001600160a01b0319811683178455167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08380a380f35b906020608492519162461bcd60e51b8352820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152fd5b8480fd5b8280fd5b50503461010057816003193601126101005761021f60ff6020935460a01c169151809261082b565bf35b919050346101f35760203660031901126101f35781359182600f0b928381036101ef5761024c61084e565b600554918260801d600f0b8513156102a65750917f7a540a43310e9a18ce355055fb7867169ed59fcd13b24848cb0afb56bb9d2ffb93916020936001600160801b0316906001600160801b0319161760055551908152a180f35b835163768a39a760e01b8152fd5b9050346101f35760803660031901126101f3578151916102d3836107bc565b6102db610810565b83526001600160801b0360243581811681036103425760208501526044358181168103610342578285015260643590811681036101ef5760608401526001546001600160a01b0316330361033657836103338461120e565b80f35b516282b42960e81b8152fd5b8580fd5b50503461010057816003193601126101005760015490516001600160a01b039091168152602090f35b919050346101f35760203660031901126101f35781359182600f0b928381036101ef5761039a61084e565b6005549182600f0b8512156103ee5750917fbfad55c65286ecfe7e1bc56ed83022c32201fe540cbc7ef72b14c8ac6d81440b93916001600160801b0360209481199060801b1691161760055551908152a180f35b8351633d50699d60e21b8152fd5b50503461010057816003193601126101005760025490516001600160a01b039091168152602090f35b505034610100578160031936011261010057905490516001600160a01b039091168152602090f35b83346104a757806003193601126104a75761046661084e565b80546001600160a01b03198116825581906001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a380f35b80fd5b9050346101f357826003193601126101f3575490516001600160a01b03909116815260209150f35b505034610100578160031936011261010057517f0000000000000000000000004ad1dbef3f6663d4db0be2d2aebcf77b2e9da0166001600160a01b03168152602090f35b83833461010057602090816003193601126101f35767ffffffffffffffff9380358581116101ef57366023820112156101ef578082013595861161076157825191601f199661056c8689601f84011601856107ee565b80845285840192366024838301011161072657818892602489930186378501015261059561084e565b60ff865460a01c16600281101561074e578061072a575082805181010361010092838212610726576105c6906108a6565b906105d28686016108a6565b906105df606087016108a6565b9160806105ed8189016108a6565b92607f19011261072257906106a8959493929161064489519661060f886107bc565b61061b60a08b016108ba565b885261062960c08b016108ba565b8c89015261063960e08b016108ba565b8b89015289016108ba565b606087015260018060a01b0392838092816001600160601b0360a01b9716876001541617600155168560025416176002551683600354161760035516908254161790557740000000000000000000000000000004000000000000000060055561120e565b835460ff60a01b1916600160a01b1784558151838152815184820181905290939091855b83811061070f575050508394601f827f69e4b643748df9006fc37ef3f1b56ca47e33f040690f26d5d66385958c3faeef968587958601015201168101030190a180f35b81810183015186820186015282016106cc565b8980fd5b8780fd5b9086610747604493875193633bf2e2f960e11b855284019061082b565b6024820152fd5b634e487b7160e01b875260218252602487fd5b634e487b7160e01b855260418252602485fd5b50503461010057816003193601126101005760035490516001600160a01b039091168152602090f35b849034610100578160031936011261010057602090600554600f0b8152f35b6080810190811067ffffffffffffffff8211176107d857604052565b634e487b7160e01b600052604160045260246000fd5b90601f8019910116810190811067ffffffffffffffff8211176107d857604052565b600435906001600160801b038216820361082657565b600080fd5b9060028210156108385752565b634e487b7160e01b600052602160045260246000fd5b6000546001600160a01b0316330361086257565b606460405162461bcd60e51b815260206004820152602060248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152fd5b51906001600160a01b038216820361082657565b51906001600160801b038216820361082657565b600254604080519167ffffffffffffffff916001600160a01b03918216916000906060860185811187821017610fa557839692965260028252602080968184019585368837816001978861092188610fd1565b528161092c88610ff4565b52875192839163883bdbfd60e01b83526024988984019060049e8f86015251809152604484019190855b8d8a838310610f8757505050505082809103915afa978815610f7d5782918399610e77575b505061099061098982610ff4565b5191610fd1565b5160060b9060060b0396667fffffffffffff8813667fffffffffffff19891217610e6557836109ca816109c284610ff4565b511692610fd1565b5116900390838211610e5357508660060b9660020b9686600082129182610e44575b5050610e1a575b811b640100000000600160c01b031615610e0657816003541693828854169560009760020b888112600014610e00578089035b620d89e88111610df05789919083811615610dde576001600160881b036ffffcb933bd6fad37aa2d162d1a5940015b169460028216610dc2575b8c8216610da6575b60088216610d8a575b60108216610d6e575b868216610d52575b8116610d36575b608090818116610d1b575b6101008116610d00575b6102008116610ce5575b6104008116610cca575b6108008116610caf575b6110008116610c94575b6120008116610c79575b6140008116610c5e575b6180008116610c43575b620100008116610c28575b620200008116610c0e575b620400008116610bf4575b6208000016610bdb575b5013610bb8575b63ffffffff8216610bb0575060ff875b16911c0116946001600160801b039485871115600014610b85575085800295808704811490151715610b725750501015610b6857610b659216906111a3565b90565b610b659216611128565b601190634e487b7160e01b600052526000fd5b95610b939250809150611004565b93501015610ba657610b659216906110dd565b610b659216611054565b60ff90610b26565b908015610bc9576000190490610b16565b634e487b7160e01b8852601289528488fd5b90936b048a170391f7dc42444e8fa202901c9238610b0f565b6d2216e584f5fa1ea926041bedfe98909502811c94610b05565b946e5d6af8dedb81196699c329225ee60402811c94610afa565b946f09aa508b5b7a84e1c677de54f3e99bc902811c94610aef565b946f31be135f97d08fd981231505542fcfa602811c94610ae4565b946f70d869a156d2a1b890bb3df62baf32f702811c94610ada565b946fa9f746462d870fdf8a65dc1f90e061e502811c94610ad0565b946fd097f3bdfd2022b8845ad8f792aa582502811c94610ac6565b946fe7159475a2c29b7443b29c7fa6e889d902811c94610abc565b946ff3392b0822b70005940c7a398e4b70f302811c94610ab2565b946ff987a7253ac413176f2b074cf7815e5402811c94610aa8565b946ffcbe86c7900a88aedcffc83b479aa3a402811c94610a9e565b946ffe5dee046a99a2a811c461f1969c305302811c94610a94565b936fff2ea16466c96a3843ec78b326b528610260801c93610a89565b946fff973b41fa98c081472e6896dfb254c00260801c94610a82565b946fffcb9843d60f6159c9db58835c9266440260801c94610a7a565b946fffe5caca7e10e4e61c3624eaa0941cd00260801c94610a71565b946ffff2e50f5f656932ef12357cf3c7fdcc0260801c94610a68565b946ffff97272373d413259a46990580e213a0260801c94610a60565b6001600160881b03600160801b610a55565b83516315e4079d60e11b81528b90fd5b80610a26565b82601288634e487b7160e01b600052526000fd5b95627fffff198114610e305760001901956109f3565b83601189634e487b7160e01b600052526000fd5b0760060b1515905086386109ec565b634e487b7160e01b8152601189528490fd5b634e487b7160e01b8252601189528482fd5b915097503d8083833e610e8a81836107ee565b81019786828a03126101f3578151818111610f5c5782019189601f84011215610f5c57825192610eb984610fb9565b93610ec68a5195866107ee565b808552868086019160051b830101918c8311610f79578701905b828210610f605750505084810151918211610f5c57019780601f8a0112156101f3578851610f0d81610fb9565b99610f1a89519b8c6107ee565b818b5285808c019260051b8201019283116101ef578501905b828210610f4457505050388061097b565b81518781168103610342578152908501908501610f33565b8380fd5b81518060060b8103610726578152908701908701610ee0565b8680fd5b86513d84823e3d90fd5b845163ffffffff1686528a9850899750948501949093019201610956565b634e487b7160e01b83526041600452602483fd5b67ffffffffffffffff81116107d85760051b60200190565b805115610fde5760200190565b634e487b7160e01b600052603260045260246000fd5b805160011015610fde5760400190565b6000198282099082810292838084109303918383039360009314611049576801000000000000000092848411156104a757500990828211900360c01b910360401c1790565b505090505060401c90565b600160801b91600019828409928260801b928380861095039480860395146110cf57848311156108265782910981806000031680920460028082600302188083028203028083028203028083028203028083028203028083028203028092029003029360018380600003040190848311900302920304170290565b505080925015610826570490565b600019828209908281029283808410930391838303936000931461111d57600160801b92848411156104a757500990828211900360801b910360801c1790565b505090505060801c90565b600160c01b91600019828409928260c01b928380861095039480860395146110cf57848311156108265782910981806000031680920460028082600302188083028203028083028203028083028203028083028203028083028203028092029003029360018380600003040190848311900302920304170290565b60001982820990828102928380841093039183830393600093146111e357600160c01b92848411156104a757500990828211900360401b910360c01c1790565b505090505060c01c90565b81156111f8570490565b634e487b7160e01b600052601260045260246000fd5b6001600160601b03906001600160801b038261122c828451166108ce565b169061125b60409361124a83868301511684606084015116906113c5565b9260208183511692015116906113c5565b600f0b90600f0b02821d9060016001607f1b031982121580611367575b15610826578361128e8261129494600f0b611378565b16611535565b7f0000000000000000000000004ad1dbef3f6663d4db0be2d2aebcf77b2e9da0166001600160a01b031690813b1561082657600093602485928551968793849263293352b160e11b845216958660048401525af1801561135c57611324575b7f52de59985c8ca6cc14f539089a9cf5f08595bbd4e279a3c671d42619aee0958492508151908152426020820152a1565b67ffffffffffffffff83116107d8577f52de59985c8ca6cc14f539089a9cf5f08595bbd4e279a3c671d42619aee095849282526112f3565b82513d6000823e3d90fd5b5060016001607f1b03821315611278565b81156113be57600f0b600090818112610100576001600160801b038316810260401c9260801c026001600160c01b0381116101005760401b90821982116104a757500190565b5050600090565b9080156108265760006001600160c01b03831161140e57506113e99160401b6111ee565b6001600160801b0390818111610826571660016001607f1b03811161082657600f0b90565b9060c083811c9384640100000000811015611528575b8062010000600292101561151c575b610100811015611510575b6010811015611504575b60048110156114f9575b10156114ef575b6114776000199282600185870160be1984011c019160ff031b6111ee565b946001600160801b0390818711610342578460801c870291851687029084819460401b918383106114e5575b505003948160801b938487106114db575b505060801c036114d0576114c892036111ee565b905b016113e9565b5050506001906114ca565b90920191386114b4565b01935084386114a3565b9060010190611459565b92810192811c611452565b6004938401931c611448565b6008938401931c61143e565b6010938401931c611433565b5060e0915080821c611424565b61156291600554906001600160601b039384809216826115588286600f0b611378565b169360801d611378565b169282168181111580611591575b1561157c575050905090565b839192501060001461158c575090565b905090565b508381101561157056fea2646970667358221220a597e7777b40927588553f21d91226251fe75fa30b25a733a830f1a0d32f17c864736f6c63430008110033

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

000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000200000000000000000000000004ad1dbef3f6663d4db0be2d2aebcf77b2e9da016

-----Decoded View---------------
Arg [0] : _arguments (bytes): 0x0000000000000000000000004ad1dbef3f6663d4db0be2d2aebcf77b2e9da016

-----Encoded View---------------
3 Constructor Arguments found :
Arg [0] : 0000000000000000000000000000000000000000000000000000000000000020
Arg [1] : 0000000000000000000000000000000000000000000000000000000000000020
Arg [2] : 0000000000000000000000004ad1dbef3f6663d4db0be2d2aebcf77b2e9da016


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

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

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading
[ Download: CSV Export  ]

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