Contract 0x2066c6d8726c7Aa782faC4988Aef49bFAaEDE6e9 1

 
Txn Hash Method
Block
From
To
Value [Txn Fee]
0xf8b4355a3944648bd10fd004c8db97f60578424facad6eff2cf953fecda041adSet Rates633734042023-05-31 14:44:462 days 18 hrs ago0xa2db1972fc411a9a788c62d7169962b7867f00ba IN  0x2066c6d8726c7aa782fac4988aef49bfaaede6e90 FTM0.00617978237
0x2555e45ff83dcb30f14f602b9fda2601662c71497605e0533c4629db16235974Set Rates633733702023-05-31 14:43:382 days 18 hrs ago0xa2db1972fc411a9a788c62d7169962b7867f00ba IN  0x2066c6d8726c7aa782fac4988aef49bfaaede6e90 FTM0.006177709753
0xa5693cb10cb91ecd77b37cea398faeb53acab3ac619699f4ece48824c606b0a4Set Rates633733412023-05-31 14:42:332 days 18 hrs ago0xa2db1972fc411a9a788c62d7169962b7867f00ba IN  0x2066c6d8726c7aa782fac4988aef49bfaaede6e90 FTM0.006653492478
0x0a0a6d229b176c2329566bd59ed7539ed58d1d55866e588bfc54839fba7b2662Create Eternal F...633733182023-05-31 14:41:482 days 18 hrs ago0xa2db1972fc411a9a788c62d7169962b7867f00ba IN  0x2066c6d8726c7aa782fac4988aef49bfaaede6e90 FTM0.242532120201
0xecf4e86bd9f1ac6f64aa6d31ea51484e28c8c42c852ab648d7c827530c4ef893Set Rates633707572023-05-31 13:12:062 days 19 hrs ago0xa2db1972fc411a9a788c62d7169962b7867f00ba IN  0x2066c6d8726c7aa782fac4988aef49bfaaede6e90 FTM0.004454719046
0xd1d156f2ad2aa5a98bc00e15a0ce27bbd74fa28dbea1cb19fbd70a0d9112a3e9Set Rates633681862023-05-31 12:15:232 days 20 hrs ago0xa2db1972fc411a9a788c62d7169962b7867f00ba IN  0x2066c6d8726c7aa782fac4988aef49bfaaede6e90 FTM0.005131502987
0x0c844018cee67cb44d271855e00a90871816530b722bbd58c2b118168c465d11Set Rates633681562023-05-31 12:14:522 days 20 hrs ago0xa2db1972fc411a9a788c62d7169962b7867f00ba IN  0x2066c6d8726c7aa782fac4988aef49bfaaede6e90 FTM0.005165671356
0xc3df14d45d786ce1a9ebb518bdf3c36a55de9e8c155089bbad6e4febd87b877dCreate Eternal F...633680892023-05-31 12:13:442 days 20 hrs ago0xa2db1972fc411a9a788c62d7169962b7867f00ba IN  0x2066c6d8726c7aa782fac4988aef49bfaaede6e90 FTM0.203689875618
0xb34fcb34d0c196942fa896d3dfd3224329a72a5c782d2053c5a6588ef4ab4511Deactivate Incen...629014042023-05-23 9:37:3410 days 23 hrs ago0xdead1f5af792afc125812e875a891b038f888258 IN  0x2066c6d8726c7aa782fac4988aef49bfaaede6e90 FTM0.064254583314
0xa8c73875acd1480a296cfcc28c562a94b6dbab07c33eaf962191268e8fed199bDecrease Rewards...626773942023-05-19 15:48:0314 days 17 hrs ago0xdead1f5af792afc125812e875a891b038f888258 IN  0x2066c6d8726c7aa782fac4988aef49bfaaede6e90 FTM0.03112765524
0x66be4765afc244827d9327771f2df1fc49f7186ac2f22da2aa67f40267ebf873Set Rates626773162023-05-19 15:46:4814 days 17 hrs ago0xdead1f5af792afc125812e875a891b038f888258 IN  0x2066c6d8726c7aa782fac4988aef49bfaaede6e90 FTM0.006238556611
0xa198adcb9af6730e44a5ab911b3ca1def1e60da10d9830d56bd099c1b10430c9Deactivate Incen...626768512023-05-19 15:40:3614 days 17 hrs ago0xdead1f5af792afc125812e875a891b038f888258 IN  0x2066c6d8726c7aa782fac4988aef49bfaaede6e90 FTM0.068323577752
0xc0982387c49d48e03401c2a5f85191da167938122218ea4190687d237d77e1eeCreate Eternal F...626675402023-05-19 12:53:0914 days 20 hrs ago0xdead1f5af792afc125812e875a891b038f888258 IN  0x2066c6d8726c7aa782fac4988aef49bfaaede6e90 FTM0.173939898393
0xdf3dc09fab4c81f22b0752d9dee9df1ffb9988718b1e7963abcaf825a45251b6Add Rewards626661482023-05-19 12:32:0614 days 20 hrs ago0xdead1f5af792afc125812e875a891b038f888258 IN  0x2066c6d8726c7aa782fac4988aef49bfaaede6e90 FTM0.007224894829
0xdd2e2d6e6cf67970cac201ed757c68973744b57fd027cf2eea992860c82ff12cDecrease Rewards...626658982023-05-19 12:27:1914 days 20 hrs ago0xdead1f5af792afc125812e875a891b038f888258 IN  0x2066c6d8726c7aa782fac4988aef49bfaaede6e90 FTM0.005533143206
0x48e1127e750c0dead55830c644bd3ed135f7d63aacad41b5184102bafe1d4a9dCreate Eternal F...625757482023-05-18 9:53:0715 days 23 hrs ago0xdead1f5af792afc125812e875a891b038f888258 IN  0x2066c6d8726c7aa782fac4988aef49bfaaede6e90 FTM0.267303144973
0xb3da93bbf37d5b2f024d47d47cc0df1829e48d25eeec1b781f26d2c7bff334b6Set Farming Cent...625754112023-05-18 9:47:1015 days 23 hrs ago0xdead1f5af792afc125812e875a891b038f888258 IN  0x2066c6d8726c7aa782fac4988aef49bfaaede6e90 FTM0.004166666
0xb78fde159bcaefeca941e4ad02e9c27ace334fa7a2bd35b176e613a8b395fd860x60e06040625753992023-05-18 9:46:5715 days 23 hrs ago0xdead1f5af792afc125812e875a891b038f888258 IN  Create: AlgebraEternalFarming0 FTM0.427496094
[ Download CSV Export 
Latest 5 internal transactions
Parent Txn Hash Block From To Value
0x0a0a6d229b176c2329566bd59ed7539ed58d1d55866e588bfc54839fba7b2662633733182023-05-31 14:41:482 days 18 hrs ago 0x2066c6d8726c7aa782fac4988aef49bfaaede6e9  Contract Creation0 FTM
0xc3df14d45d786ce1a9ebb518bdf3c36a55de9e8c155089bbad6e4febd87b877d633680892023-05-31 12:13:442 days 20 hrs ago 0x2066c6d8726c7aa782fac4988aef49bfaaede6e9  Contract Creation0 FTM
0xc0982387c49d48e03401c2a5f85191da167938122218ea4190687d237d77e1ee626675402023-05-19 12:53:0914 days 20 hrs ago 0x2066c6d8726c7aa782fac4988aef49bfaaede6e9  Contract Creation0 FTM
0x48e1127e750c0dead55830c644bd3ed135f7d63aacad41b5184102bafe1d4a9d625757482023-05-18 9:53:0715 days 23 hrs ago 0x2066c6d8726c7aa782fac4988aef49bfaaede6e9  Contract Creation0 FTM
0xb78fde159bcaefeca941e4ad02e9c27ace334fa7a2bd35b176e613a8b395fd86625753992023-05-18 9:46:5715 days 23 hrs ago 0xdead1f5af792afc125812e875a891b038f888258  Contract Creation0 FTM
[ Download CSV Export 
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
AlgebraEternalFarming

Compiler Version
v0.8.17+commit.8df45f5f

Optimization Enabled:
Yes with 99999999 runs

Other Settings:
default evmVersion
File 1 of 44 : AlgebraFeeConfiguration.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

// coefficients for sigmoids: α / (1 + e^( (β-x) / γ))
// alpha1 + alpha2 + baseFee must be <= type(uint16).max
struct AlgebraFeeConfiguration {
  uint16 alpha1; // max value of the first sigmoid
  uint16 alpha2; // max value of the second sigmoid
  uint32 beta1; // shift along the x-axis for the first sigmoid
  uint32 beta2; // shift along the x-axis for the second sigmoid
  uint16 gamma1; // horizontal stretch factor for the first sigmoid
  uint16 gamma2; // horizontal stretch factor for the second sigmoid
  uint16 baseFee; // minimum possible fee
}

File 2 of 44 : IAlgebraFactory.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
pragma abicoder v2;

import '../base/AlgebraFeeConfiguration.sol';

/// @title The interface for the Algebra Factory
/// @dev Credit to Uniswap Labs under GPL-2.0-or-later license:
/// https://github.com/Uniswap/v3-core/tree/main/contracts/interfaces
interface IAlgebraFactory {
  /// @notice Emitted when a process of ownership renounce is started
  /// @param timestamp The timestamp of event
  /// @param finishTimestamp The timestamp when ownership renounce will be possible to finish
  event RenounceOwnershipStart(uint256 timestamp, uint256 finishTimestamp);

  /// @notice Emitted when a process of ownership renounce cancelled
  /// @param timestamp The timestamp of event
  event RenounceOwnershipStop(uint256 timestamp);

  /// @notice Emitted when a process of ownership renounce finished
  /// @param timestamp The timestamp of ownership renouncement
  event RenounceOwnershipFinish(uint256 timestamp);

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

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

  /// @notice Emitted when the default fee configuration is changed
  /// @param newConfig The structure with dynamic fee parameters
  /// @dev See the AdaptiveFee library for more details
  event DefaultFeeConfiguration(AlgebraFeeConfiguration newConfig);

  /// @notice Emitted when the default community fee is changed
  /// @param newDefaultCommunityFee The new default community fee value
  event DefaultCommunityFee(uint8 newDefaultCommunityFee);

  /// @notice role that can change communityFee and tickspacing in pools
  function POOLS_ADMINISTRATOR_ROLE() external view returns (bytes32);

  /// @dev Returns `true` if `account` has been granted `role` or `account` is owner.
  function hasRoleOrOwner(bytes32 role, address account) external view returns (bool);

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

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

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

  /// @notice Returns the current communityVaultAddress
  /// @return The address to which community fees are transferred
  function communityVault() external view returns (address);

  /// @notice Returns the default community fee
  /// @return Fee which will be set at the creation of the pool
  function defaultCommunityFee() external view returns (uint8);

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

  /// @return timestamp The timestamp of the beginning of the renounceOwnership process
  function renounceOwnershipStartTimestamp() external view returns (uint256 timestamp);

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

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

  /// @dev updates default community fee for new pools
  /// @param newDefaultCommunityFee The new community fee, _must_ be <= MAX_COMMUNITY_FEE
  function setDefaultCommunityFee(uint8 newDefaultCommunityFee) external;

  /// @notice Changes initial fee configuration for new pools
  /// @dev changes coefficients for sigmoids: α / (1 + e^( (β-x) / γ))
  /// alpha1 + alpha2 + baseFee (max possible fee) must be <= type(uint16).max and gammas must be > 0
  /// @param newConfig new default fee configuration. See the #AdaptiveFee.sol library for details
  function setDefaultFeeConfiguration(AlgebraFeeConfiguration calldata newConfig) external;

  /// @notice Starts process of renounceOwnership. After that, a certain period
  /// of time must pass before the ownership renounce can be completed.
  function startRenounceOwnership() external;

  /// @notice Stops process of renounceOwnership and removes timer.
  function stopRenounceOwnership() external;
}

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

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

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

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

/// @title An interface for a contract that is capable of deploying Algebra Pools
/// @notice A contract that constructs a pool must implement this to pass arguments to the pool
/// @dev This is used to avoid having constructor arguments in the pool contract, which results in the init code hash
/// of the pool being constant allowing the CREATE2 address of the pool to be cheaply computed on-chain.
/// Credit to Uniswap Labs under GPL-2.0-or-later license:
/// https://github.com/Uniswap/v3-core/tree/main/contracts/interfaces
interface IAlgebraPoolDeployer {
  /// @notice Get the parameters to be used in constructing the pool, set transiently during pool creation.
  /// @dev Called by the pool constructor to fetch the parameters of the pool
  /// @return dataStorage The pools associated dataStorage
  /// @return factory The factory address
  /// @return communityVault The community vault address
  /// @return token0 The first token of the pool by address sort order
  /// @return token1 The second token of the pool by address sort order
  function getDeployParameters() external view returns (address dataStorage, address factory, address communityVault, address token0, address token1);

  /// @dev Deploys a pool with the given parameters by transiently setting the parameters in cache.
  /// @param dataStorage The pools associated dataStorage
  /// @param token0 The first token of the pool by address sort order
  /// @param token1 The second token of the pool by address sort order
  /// @return pool The deployed pool's address
  function deploy(address dataStorage, address token0, address token1) external returns (address pool);
}

File 5 of 44 : IAlgebraPoolErrors.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.8.4 <0.9.0;

/// @title Errors emitted by a pool
/// @notice Contains custom errors emitted by the pool
interface IAlgebraPoolErrors {
  // ####  pool errors  ####

  /// @notice Emitted by the reentrancy guard
  error locked();

  /// @notice Emitted if arithmetic error occurred
  error arithmeticError();

  /// @notice Emitted if an attempt is made to initialize the pool twice
  error alreadyInitialized();

  /// @notice Emitted if 0 is passed as amountRequired to swap function
  error zeroAmountRequired();

  /// @notice Emitted if invalid amount is passed as amountRequired to swapSupportingFeeOnInputTokens function
  error invalidAmountRequired();

  /// @notice Emitted if the pool received fewer tokens than it should have
  error insufficientInputAmount();
  /// @notice Emitted if the pool received fewer tokens than it should have to mint calculated actual liquidity
  error insufficientAmountReceivedAtMint();

  /// @notice Emitted if there was an attempt to mint zero liquidity
  error zeroLiquidityDesired();
  /// @notice Emitted if actual amount of liquidity is zero (due to insufficient amount of tokens received)
  error zeroLiquidityActual();

  /// @notice Emitted if the pool received fewer tokens{0,1} after flash than it should have
  error flashInsufficientPaid0();
  error flashInsufficientPaid1();

  /// @notice Emitted if limitSqrtPrice param is incorrect
  error invalidLimitSqrtPrice();

  /// @notice Tick must be divisible by tickspacing
  error tickIsNotSpaced();

  /// @notice Emitted if a method is called that is accessible only to the factory owner or dedicated role
  error notAllowed();
  /// @notice Emitted if a method is called that is accessible only to the farming
  error onlyFarming();

  error invalidNewTickSpacing();
  error invalidNewCommunityFee();

  // ####  LimitOrder errors  ####
  /// @notice Emitted if tick is too low/high for limit order
  error invalidTickForLimitOrder();
  /// @notice Emitted if amount is too high for limit order
  error invalidAmountForLimitOrder();

  // ####  LiquidityMath errors  ####
  /// @notice Emitted if liquidity underflows
  error liquiditySub();
  /// @notice Emitted if liquidity overflows
  error liquidityAdd();

  // ####  TickManagement errors  ####
  error topTickLowerThanBottomTick();
  error bottomTickLowerThanMIN();
  error topTickAboveMAX();
  error liquidityOverflow();
  error tickIsNotInitialized();
  error tickInvalidLinks();

  // ####  SafeTransfer errors  ####
  error transferFailed();

  // ####  TickMath errors  ####
  error tickOutOfRange();
  error priceOutOfRange();
}

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

/// @title The interface for the virtual pool
/// @dev Used to calculate active liquidity in farmings
interface IAlgebraVirtualPool {
  /// @dev This function is called by the main pool if an initialized ticks are crossed by swap.
  /// If any one of crossed ticks is also initialized in a virtual pool it should be crossed too
  /// @param targetTick The target tick up to which we need to cross all active ticks
  /// @param zeroToOne The direction
  function crossTo(int24 targetTick, bool zeroToOne) external returns (bool success);
}

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

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

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

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

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

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

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

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

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

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

  /// @notice Adds liquidity for the given recipient/bottomTick/topTick position
  /// @dev The caller of this method receives a callback in the form of IAlgebraMintCallback# AlgebraMintCallback
  /// in which they must pay any token0 or token1 owed for the liquidity. The amount of token0/token1 due depends
  /// on bottomTick, topTick, the amount of liquidity, and the current price. If bottomTick == topTick position is treated as a limit order
  /// @param sender The address which will receive potential surplus of paid tokens
  /// @param recipient The address for which the liquidity will be created
  /// @param bottomTick The lower tick of the position in which to add liquidity
  /// @param topTick The upper tick of the position in which to add liquidity
  /// @param amount The desired amount of liquidity to mint
  /// @param data Any data that should be passed through to the callback
  /// @return amount0 The amount of token0 that was paid to mint the given amount of liquidity. Matches the value in the callback
  /// @return amount1 The amount of token1 that was paid to mint the given amount of liquidity. Matches the value in the callback
  /// @return liquidityActual The actual minted amount of liquidity
  function mint(
    address sender,
    address recipient,
    int24 bottomTick,
    int24 topTick,
    uint128 amount,
    bytes calldata data
  ) external returns (uint256 amount0, uint256 amount1, uint128 liquidityActual);

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

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

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

  /// @notice Swap token0 for token1, or token1 for token0 (tokens that have fee on transfer)
  /// @dev The caller of this method receives a callback in the form of IAlgebraSwapCallback#AlgebraSwapCallback
  /// @param sender The address called this function (Comes from the Router)
  /// @param recipient The address to receive the output of the swap
  /// @param zeroToOne The direction of the swap, true for token0 to token1, false for token1 to token0
  /// @param amountRequired The amount of the swap, which implicitly configures the swap as exact input
  /// @param limitSqrtPrice The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this
  /// value after the swap. If one for zero, the price cannot be greater than this value after the swap
  /// @param data Any data to be passed through to the callback. If using the Router it should contain SwapRouter#SwapCallbackData
  /// @return amount0 The delta of the balance of token0 of the pool, exact when negative, minimum when positive
  /// @return amount1 The delta of the balance of token1 of the pool, exact when negative, minimum when positive
  function swapSupportingFeeOnInputTokens(
    address sender,
    address recipient,
    bool zeroToOne,
    int256 amountRequired,
    uint160 limitSqrtPrice,
    bytes calldata data
  ) external returns (int256 amount0, int256 amount1);

  /// @notice Receive token0 and/or token1 and pay it back, plus a fee, in the callback
  /// @dev The caller of this method receives a callback in the form of IAlgebraFlashCallback#AlgebraFlashCallback
  /// @dev All excess tokens paid in the callback are distributed to currently in-range liquidity providers as an additional fee.
  /// If there are no in-range liquidity providers, the fee will be transferred to the first active provider in the future
  /// @param recipient The address which will receive the token0 and token1 amounts
  /// @param amount0 The amount of token0 to send
  /// @param amount1 The amount of token1 to send
  /// @param data Any data to be passed through to the callback
  function flash(address recipient, uint256 amount0, uint256 amount1, bytes calldata data) external;
}

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

/// @title Pool state that is not stored
/// @notice Contains view functions to provide information about the pool that is computed rather than stored on the
/// blockchain. The functions here may have variable gas costs.
/// @dev Credit to Uniswap Labs under GPL-2.0-or-later license:
/// https://github.com/Uniswap/v3-core/tree/main/contracts/interfaces
interface IAlgebraPoolDerivedState {
  /// @notice Returns a snapshot of seconds per liquidity and seconds inside a tick range
  /// @dev Snapshots must only be compared to other snapshots, taken over a period for which a position existed.
  /// I.e., snapshots cannot be compared if a position is not held for the entire period between when the first
  /// snapshot is taken and the second snapshot is taken.
  /// @param bottomTick The lower tick of the range
  /// @param topTick The upper tick of the range
  /// @return innerSecondsSpentPerLiquidity The snapshot of seconds per liquidity for the range
  /// @return innerSecondsSpent The snapshot of the number of seconds during which the price was in this range
  function getInnerCumulatives(
    int24 bottomTick,
    int24 topTick
  ) external view returns (uint160 innerSecondsSpentPerLiquidity, uint32 innerSecondsSpent);
}

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

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

  /// @notice Emitted when liquidity is minted for a given position
  /// @dev If the top and bottom ticks match, this should be treated as a limit order
  /// @param sender The address that minted the liquidity
  /// @param owner The owner of the position and recipient of any minted liquidity
  /// @param bottomTick The lower tick of the position
  /// @param topTick The upper tick of the position
  /// @param liquidityAmount The amount of liquidity minted to the position range
  /// @param amount0 How much token0 was required for the minted liquidity
  /// @param amount1 How much token1 was required for the minted liquidity
  event Mint(
    address sender,
    address indexed owner,
    int24 indexed bottomTick,
    int24 indexed topTick,
    uint128 liquidityAmount,
    uint256 amount0,
    uint256 amount1
  );

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

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

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

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

  /// @notice Emitted when the community fee is changed by the pool
  /// @param communityFeeNew The updated value of the community fee in thousandths (1e-3)
  event CommunityFee(uint8 communityFeeNew);

  /// @notice Emitted when the tick spacing changes
  /// @param newTickSpacing The updated value of the new tick spacing
  /// @param newTickSpacingLimitOrders The updated value of the new tick spacing for limit orders
  event TickSpacing(int24 newTickSpacing, int24 newTickSpacingLimitOrders);

  /// @notice Emitted when new activeIncentive is set
  /// @param newIncentiveAddress The address of the new incentive
  event Incentive(address indexed newIncentiveAddress);

  /// @notice Emitted when the fee changes inside the pool
  /// @param fee The current fee in hundredths of a bip, i.e. 1e-6
  event Fee(uint16 fee);

  /// @notice Emitted in case of an error when trying to write to the DataStorage
  /// @dev This shouldn't happen
  event DataStorageFailure();
}

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

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

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

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

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

  /// @notice The contract to which community fees are transferred
  /// @return The communityVault address
  function communityVault() external view returns (address);

  /// @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 12 of 44 : IAlgebraPoolPermissionedActions.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

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

  /// @notice Set the new tick spacing values. Only factory owner or POOLS_ADMINISTRATOR_ROLE role
  /// @param newTickSpacing The new tick spacing value
  /// @param newTickSpacingLimitOrders The new tick spacing value for limit orders
  function setTickSpacing(int24 newTickSpacing, int24 newTickSpacingLimitOrders) external;

  /// @notice Sets an active incentive. Only farming
  /// @param newIncentiveAddress The address associated with the incentive
  function setIncentive(address newIncentiveAddress) external;
}

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

/// @title Pool state that can change
/// @dev Credit to Uniswap Labs under GPL-2.0-or-later license:
/// https://github.com/Uniswap/v3-core/tree/main/contracts/interfaces
interface IAlgebraPoolState {
  /// @notice The globalState structure in the pool stores many values but requires only one slot
  /// and is exposed as a single method to save gas when accessed externally.
  /// @return price The current price of the pool as a sqrt(dToken1/dToken0) 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(price) if the price is on a tick boundary;
  /// @return prevInitializedTick The previous initialized tick
  /// @return fee The last pool fee value in hundredths of a bip, i.e. 1e-6
  /// @return timepointIndex The index of the last written timepoint
  /// @return communityFee The community fee percentage of the swap fee in thousandths (1e-3)
  /// @return unlocked Whether the pool is currently locked to reentrancy
  function globalState()
    external
    view
    returns (uint160 price, int24 tick, int24 prevInitializedTick, uint16 fee, uint16 timepointIndex, uint8 communityFee, bool unlocked);

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

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

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

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

  /// @notice The current tick spacing for limit orders
  /// @dev Ticks can only be used for limit orders at multiples of this value
  /// This value is an int24 to avoid casting even though it is always positive.
  /// @return The current tick spacing for limit orders
  function tickSpacingLimitOrders() external view returns (int24);

  /// @notice The timestamp of the last sending of tokens to community vault
  function communityFeeLastTimestamp() external view returns (uint32);

  /// @notice The amounts of token0 and token1 that will be sent to the vault
  /// @dev Will be sent COMMUNITY_FEE_TRANSFER_FREQUENCY after communityFeeLastTimestamp
  function getCommunityFeePending() external view returns (uint128 communityFeePending0, uint128 communityFeePending1);

  /// @notice The tracked token0 and token1 reserves of pool
  /// @dev If at any time the real balance is larger, the excess will be transferred to liquidity providers as additional fee.
  /// If the balance exceeds uint128, the excess will be sent to the communityVault.
  function getReserves() external view returns (uint128 reserve0, uint128 reserve1);

  /// @notice The accumulator of seconds per liquidity since the pool was first initialized
  function secondsPerLiquidityCumulative() external view returns (uint160);

  /// @notice Look up information about a specific tick in the pool
  /// @param tick The tick to look up
  /// @return liquidityTotal The total amount of position liquidity that uses the pool either as tick lower or tick upper
  /// @return liquidityDelta How much liquidity changes when the pool price crosses the tick
  /// @return outerFeeGrowth0Token The fee growth on the other side of the tick from the current tick in token0
  /// @return outerFeeGrowth1Token The fee growth on the other side of the tick from the current tick in token1
  /// @return prevTick The previous tick in tick list
  /// @return nextTick The next tick in tick list
  /// @return outerSecondsPerLiquidity The seconds spent per liquidity on the other side of the tick from the current tick
  /// @return outerSecondsSpent The seconds spent on the other side of the tick from the current tick
  /// @return hasLimitOrders Whether there are limit orders on this tick or not
  /// In addition, these values are only relative and must be used only in comparison to previous snapshots for
  /// a specific position.
  function ticks(
    int24 tick
  )
    external
    view
    returns (
      uint128 liquidityTotal,
      int128 liquidityDelta,
      uint256 outerFeeGrowth0Token,
      uint256 outerFeeGrowth1Token,
      int24 prevTick,
      int24 nextTick,
      uint160 outerSecondsPerLiquidity,
      uint32 outerSecondsSpent,
      bool hasLimitOrders
    );

  /// @notice Returns the summary information about a limit orders at tick
  /// @param tick The tick to look up
  /// @return amountToSell The amount of tokens to sell. Has only relative meaning
  /// @return soldAmount The amount of tokens already sold. Has only relative meaning
  /// @return boughtAmount0Cumulative The accumulator of bought tokens0 per amountToSell. Has only relative meaning
  /// @return boughtAmount1Cumulative The accumulator of bought tokens1 per amountToSell. Has only relative meaning
  /// @return initialized Will be true if a limit order was created at least once on this tick
  function limitOrders(
    int24 tick
  )
    external
    view
    returns (uint128 amountToSell, uint128 soldAmount, uint256 boughtAmount0Cumulative, uint256 boughtAmount1Cumulative, bool initialized);

  /// @notice Returns 256 packed tick initialized boolean values. See TickTree for more information
  function tickTable(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, bottomTick and topTick
  /// @return liquidity The amount of liquidity in the position
  /// @return innerFeeGrowth0Token Fee growth of token0 inside the tick range as of the last mint/burn/poke
  /// @return innerFeeGrowth1Token Fee growth of token1 inside the tick range as of the last mint/burn/poke
  /// @return fees0 The computed amount of token0 owed to the position as of the last mint/burn/poke
  /// @return fees1 The computed amount of token1 owed to the position as of the last mint/burn/poke
  function positions(
    bytes32 key
  ) external view returns (uint256 liquidity, uint256 innerFeeGrowth0Token, uint256 innerFeeGrowth1Token, uint128 fees0, uint128 fees1);

  /// @notice Returns the information about active incentive
  /// @dev if there is no active incentive at the moment, incentiveAddress would be equal to address(0)
  /// @return incentiveAddress The address associated with the current active incentive
  function activeIncentive() external view returns (address incentiveAddress);
}

File 14 of 44 : Constants.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.8.17;

library Constants {
  uint8 internal constant RESOLUTION = 96;
  uint256 internal constant Q32 = 1 << 32;
  uint256 internal constant Q48 = 1 << 48;
  uint256 internal constant Q64 = 1 << 64;
  uint256 internal constant Q96 = 1 << 96;
  uint256 internal constant Q128 = 1 << 128;
  uint256 internal constant Q144 = 1 << 144;
  int256 internal constant Q160 = 1 << 160;

  uint16 internal constant BASE_FEE = 0.0001e6; // init minimum fee value in hundredths of a bip (0.01%)
  uint24 internal constant FEE_DENOMINATOR = 1e6;
  int24 internal constant INIT_TICK_SPACING = 60;
  int24 internal constant MAX_TICK_SPACING = 500;

  // Defines the maximum and minimum ticks allowed for limit orders. Corresponds to the range of possible
  // price values ​​in UniswapV2. Due to this limitation, sufficient accuracy is achieved even with the minimum allowable tick
  int24 constant MAX_LIMIT_ORDER_TICK = 776363;

  // the frequency with which the accumulated community fees are sent to the vault
  uint32 internal constant COMMUNITY_FEE_TRANSFER_FREQUENCY = 8 hours;

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

  uint8 internal constant MAX_COMMUNITY_FEE = 0.25e3; // 25%
  uint256 internal constant COMMUNITY_FEE_DENOMINATOR = 1e3;
  // role that can change communityFee and tickspacing in pools
  bytes32 internal constant POOLS_ADMINISTRATOR_ROLE = keccak256('POOLS_ADMINISTRATOR');
}

File 15 of 44 : 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 = a * b; // Least significant 256 bits of the product
      uint256 prod1; // Most significant 256 bits of the product
      assembly {
        let mm := mulmod(a, b, not(0))
        prod1 := sub(sub(mm, prod0), lt(mm, prod0))
      }

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

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

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

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

      // Factor powers of two out of denominator
      // Compute largest power of two divisor of denominator.
      // Always >= 1.
      uint256 twos = (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 preconditions guarantee
      // that the outcome is less than 2**256, this is the final result.
      // We don't need to compute the high bits of the result and prod1
      // is no longer required.
      result = prod0 * inv;
      return result;
    }
  }

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

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

File 16 of 44 : LiquidityMath.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.8.4 <0.9.0;

import '../interfaces/IAlgebraPoolErrors.sol';
import './TickMath.sol';
import './TokenDeltaMath.sol';

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

  function getAmountsForLiquidity(
    int24 bottomTick,
    int24 topTick,
    int128 liquidityDelta,
    int24 currentTick,
    uint160 currentPrice
  ) internal pure returns (uint256 amount0, uint256 amount1, int128 globalLiquidityDelta) {
    uint160 priceAtBottomTick = TickMath.getSqrtRatioAtTick(bottomTick);
    uint160 priceAtTopTick = TickMath.getSqrtRatioAtTick(topTick);

    int256 amount0Int;
    int256 amount1Int;
    if (currentTick < bottomTick) {
      // If current tick is less than the provided bottom one then only the token0 has to be provided
      amount0Int = TokenDeltaMath.getToken0Delta(priceAtBottomTick, priceAtTopTick, liquidityDelta);
    } else if (currentTick < topTick) {
      amount0Int = TokenDeltaMath.getToken0Delta(currentPrice, priceAtTopTick, liquidityDelta);
      amount1Int = TokenDeltaMath.getToken1Delta(priceAtBottomTick, currentPrice, liquidityDelta);
      globalLiquidityDelta = liquidityDelta;
    } else {
      // If current tick is greater than the provided top one then only the token1 has to be provided
      amount1Int = TokenDeltaMath.getToken1Delta(priceAtBottomTick, priceAtTopTick, liquidityDelta);
    }

    unchecked {
      (amount0, amount1) = liquidityDelta < 0 ? (uint256(-amount0Int), uint256(-amount1Int)) : (uint256(amount0Int), uint256(amount1Int));
    }
  }
}

File 17 of 44 : LowGasSafeMath.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;

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

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

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

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

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

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

File 18 of 44 : SafeCast.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.5.0 || ^0.6.0 || ^0.7.0 || ^0.8.0;

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

  /// @notice Cast a uint256 to a uint128, revert on overflow
  /// @param y The uint256 to be downcasted
  /// @return z The downcasted integer, now type uint128
  function toUint128(uint256 y) internal pure returns (uint128 z) {
    require((z = uint128(y)) == y);
  }

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

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

File 19 of 44 : TickMath.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.8.4 <0.9.0;

import '../interfaces/IAlgebraPoolErrors.sol';

/// @title Math library for computing sqrt prices from ticks and vice versa
/// @notice Computes sqrt price for ticks of size 1.0001, i.e. sqrt(1.0001^tick) as fixed point Q64.96 numbers. Supports
/// prices between 2**-128 and 2**128
/// @dev Credit to Uniswap Labs under GPL-2.0-or-later license:
/// https://github.com/Uniswap/v3-core/blob/main/contracts/libraries
library TickMath {
  /// @dev The minimum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**-128
  int24 internal constant MIN_TICK = -887272;
  /// @dev The maximum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**128
  int24 internal constant MAX_TICK = -MIN_TICK;

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

  /// @notice Calculates sqrt(1.0001^tick) * 2^96
  /// @dev Throws if |tick| > max tick
  /// @param tick The input tick for the above formula
  /// @return price A Fixed point Q64.96 number representing the sqrt of the ratio of the two assets (token1/token0)
  /// at the given tick
  function getSqrtRatioAtTick(int24 tick) internal pure returns (uint160 price) {
    unchecked {
      // get abs value
      int24 mask = tick >> (24 - 1);
      uint256 absTick = uint24((tick ^ mask) - mask);
      if (absTick > uint24(MAX_TICK)) revert IAlgebraPoolErrors.tickOutOfRange();

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

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

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

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

      uint256 r = ratio;
      uint256 msb = 0;

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

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

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

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

      int256 log_sqrt10001 = log_2 * 255738958999603826347141; // 128.128 number

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

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

File 20 of 44 : TickTree.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.8.17;

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

/// @title Packed tick initialized state library
/// @notice Stores a packed mapping of tick index to its initialized state and search tree
/// @dev The leafs mapping uses int16 for keys since ticks are represented as int24 and there are 256 (2^8) values per word.
library TickTree {
  int16 internal constant SECOND_LAYER_OFFSET = 3466; // ceil(MAX_TICK / 256)

  /// @notice Toggles the initialized state for a given tick from false to true, or vice versa
  /// @param leafs The mapping of words with ticks
  /// @param secondLayer The mapping of words with leafs
  /// @param tick The tick to toggle
  /// @param treeRoot The word with info about active subtrees
  function toggleTick(
    mapping(int16 => uint256) storage leafs,
    mapping(int16 => uint256) storage secondLayer,
    int24 tick,
    uint256 treeRoot
  ) internal returns (uint256 newTreeRoot) {
    newTreeRoot = treeRoot;
    (bool toggledNode, int16 nodeNumber) = _toggleTickInNode(leafs, tick);
    if (toggledNode) {
      unchecked {
        (toggledNode, nodeNumber) = _toggleTickInNode(secondLayer, nodeNumber + SECOND_LAYER_OFFSET);
      }
      if (toggledNode) {
        assembly {
          newTreeRoot := xor(newTreeRoot, shl(nodeNumber, 1))
        }
      }
    }
  }

  /// @notice Calculates the required node and toggles tick in it
  /// @param row The level of tree
  /// @param tick The tick to toggle
  /// @return toggledNode Toggled whole node or not
  /// @return nodeNumber Number of corresponding node
  function _toggleTickInNode(mapping(int16 => uint256) storage row, int24 tick) private returns (bool toggledNode, int16 nodeNumber) {
    assembly {
      nodeNumber := sar(8, tick)
    }
    uint256 node = row[nodeNumber];
    assembly {
      toggledNode := iszero(node)
      node := xor(node, shl(and(tick, 0xFF), 1))
      toggledNode := xor(toggledNode, iszero(node))
    }
    row[nodeNumber] = node;
  }

  /// @notice Returns the next initialized tick in tree to the right (gte) of the given tick or `MAX_TICK`
  /// @param leafs The words with ticks
  /// @param secondLayer The words with info about active leafs
  /// @param treeRoot The word with info about active subtrees
  /// @param tick The starting tick
  /// @return nextTick The next initialized tick or `MAX_TICK`
  function getNextTick(
    mapping(int16 => uint256) storage leafs,
    mapping(int16 => uint256) storage secondLayer,
    uint256 treeRoot,
    int24 tick
  ) internal view returns (int24 nextTick) {
    unchecked {
      tick++;
      int16 nodeNumber;
      bool initialized;
      assembly {
        // index in treeRoot
        nodeNumber := shr(8, add(sar(8, tick), SECOND_LAYER_OFFSET))
      }
      if (treeRoot & (1 << uint16(nodeNumber)) != 0) {
        // if subtree has active ticks
        // try to find initialized tick in the corresponding leaf of the tree
        (nodeNumber, nextTick, initialized) = _getNextActiveBitInSameNode(leafs, tick);
        if (initialized) return nextTick;

        // try to find next initialized leaf in the tree
        (nodeNumber, nextTick, initialized) = _getNextActiveBitInSameNode(secondLayer, nodeNumber + SECOND_LAYER_OFFSET + 1);
      }
      if (!initialized) {
        // try to find which subtree has an active leaf
        (nextTick, initialized) = _nextActiveBitInTheSameNode(treeRoot, ++nodeNumber);
        if (!initialized) return TickMath.MAX_TICK;
        nextTick = _getFirstActiveBitInNode(secondLayer, nextTick);
      }
      nextTick = _getFirstActiveBitInNode(leafs, nextTick - SECOND_LAYER_OFFSET);
    }
  }

  /// @notice Calculates node with given tick and returns next active tick
  /// @param row level of search tree
  /// @param tick The starting tick
  /// @return nodeNumber Number of corresponding node
  /// @return nextTick Number of next active tick or last tick in node
  /// @return initialized Is nextTick initialized or not
  function _getNextActiveBitInSameNode(
    mapping(int16 => uint256) storage row,
    int24 tick
  ) private view returns (int16 nodeNumber, int24 nextTick, bool initialized) {
    assembly {
      nodeNumber := sar(8, tick)
    }
    (nextTick, initialized) = _nextActiveBitInTheSameNode(row[nodeNumber], tick);
  }

  /// @notice Returns first active tick in given node
  /// @param row level of search tree
  /// @param nodeNumber Number of corresponding node
  /// @return nextTick Number of next active tick or last tick in node
  function _getFirstActiveBitInNode(mapping(int16 => uint256) storage row, int24 nodeNumber) private view returns (int24 nextTick) {
    assembly {
      nextTick := shl(8, nodeNumber)
    }
    (nextTick, ) = _nextActiveBitInTheSameNode(row[int16(nodeNumber)], nextTick);
  }

  /// @notice Returns the next initialized tick contained in the same word as the tick that is
  /// to the right or at (gte) of the given tick
  /// @param word The word in which to compute the next initialized tick
  /// @param tick The starting tick
  /// @return nextTick The next initialized or uninitialized tick up to 256 ticks away from the current tick
  /// @return initialized Whether the next tick is initialized, as the function only searches within up to 256 ticks
  function _nextActiveBitInTheSameNode(uint256 word, int24 tick) private pure returns (int24 nextTick, bool initialized) {
    uint256 bitNumber;
    assembly {
      bitNumber := and(tick, 0xFF)
    }
    unchecked {
      uint256 _row = word >> bitNumber; // all the 1s at or to the left of the bitNumber
      if (_row == 0) {
        nextTick = tick + int24(uint24(255 - bitNumber));
      } else {
        nextTick = tick + int24(uint24(getSingleSignificantBit((0 - _row) & _row))); // least significant bit
        initialized = true;
      }
    }
  }

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

File 21 of 44 : TokenDeltaMath.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.8.17;

import './SafeCast.sol';
import './FullMath.sol';
import './Constants.sol';

/// @title Functions based on Q64.96 sqrt price and liquidity
/// @notice Contains the math that uses square root of price as a Q64.96 and liquidity to compute deltas
library TokenDeltaMath {
  using SafeCast for uint256;

  /// @notice Gets the token0 delta between two prices
  /// @dev Calculates liquidity / sqrt(lower) - liquidity / sqrt(upper)
  /// @param priceLower A Q64.96 sqrt price
  /// @param priceUpper Another Q64.96 sqrt price
  /// @param liquidity The amount of usable liquidity
  /// @param roundUp Whether to round the amount up or down
  /// @return token0Delta Amount of token0 required to cover a position of size liquidity between the two passed prices
  function getToken0Delta(uint160 priceLower, uint160 priceUpper, uint128 liquidity, bool roundUp) internal pure returns (uint256 token0Delta) {
    unchecked {
      uint256 priceDelta = priceUpper - priceLower;
      require(priceDelta < priceUpper); // forbids underflow and 0 priceLower
      uint256 liquidityShifted = uint256(liquidity) << Constants.RESOLUTION;

      token0Delta = roundUp
        ? FullMath.unsafeDivRoundingUp(FullMath.mulDivRoundingUp(priceDelta, liquidityShifted, priceUpper), priceLower) // denominator always > 0
        : FullMath.mulDiv(priceDelta, liquidityShifted, priceUpper) / priceLower;
    }
  }

  /// @notice Gets the token1 delta between two prices
  /// @dev Calculates liquidity * (sqrt(upper) - sqrt(lower))
  /// @param priceLower A Q64.96 sqrt price
  /// @param priceUpper Another Q64.96 sqrt price
  /// @param liquidity The amount of usable liquidity
  /// @param roundUp Whether to round the amount up, or down
  /// @return token1Delta Amount of token1 required to cover a position of size liquidity between the two passed prices
  function getToken1Delta(uint160 priceLower, uint160 priceUpper, uint128 liquidity, bool roundUp) internal pure returns (uint256 token1Delta) {
    unchecked {
      require(priceUpper >= priceLower);
      uint256 priceDelta = priceUpper - priceLower;
      token1Delta = roundUp ? FullMath.mulDivRoundingUp(priceDelta, liquidity, Constants.Q96) : FullMath.mulDiv(priceDelta, liquidity, Constants.Q96);
    }
  }

  /// @notice Helper that gets signed token0 delta
  /// @param priceLower A Q64.96 sqrt price
  /// @param priceUpper Another Q64.96 sqrt price
  /// @param liquidity The change in liquidity for which to compute the token0 delta
  /// @return token0Delta Amount of token0 corresponding to the passed liquidityDelta between the two prices
  function getToken0Delta(uint160 priceLower, uint160 priceUpper, int128 liquidity) internal pure returns (int256 token0Delta) {
    unchecked {
      token0Delta = liquidity >= 0
        ? getToken0Delta(priceLower, priceUpper, uint128(liquidity), true).toInt256()
        : -getToken0Delta(priceLower, priceUpper, uint128(-liquidity), false).toInt256();
    }
  }

  /// @notice Helper that gets signed token1 delta
  /// @param priceLower A Q64.96 sqrt price
  /// @param priceUpper Another Q64.96 sqrt price
  /// @param liquidity The change in liquidity for which to compute the token1 delta
  /// @return token1Delta Amount of token1 corresponding to the passed liquidityDelta between the two prices
  function getToken1Delta(uint160 priceLower, uint160 priceUpper, int128 liquidity) internal pure returns (int256 token1Delta) {
    unchecked {
      token1Delta = liquidity >= 0
        ? getToken1Delta(priceLower, priceUpper, uint128(liquidity), true).toInt256()
        : -getToken1Delta(priceLower, priceUpper, uint128(-liquidity), false).toInt256();
    }
  }
}

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

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

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

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

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

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

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

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

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

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

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

    /// @notice Emitted when liquidity is decreased for a position NFT
    /// @param tokenId The ID of the token for which liquidity was decreased
    /// @param liquidity The amount by which liquidity for the NFT position was decreased
    /// @param amount0 The amount of token0 that was accounted for the decrease in liquidity
    /// @param amount1 The amount of token1 that was accounted for the decrease in liquidity
    event DecreaseLiquidity(uint256 indexed tokenId, uint128 liquidity, uint256 amount0, uint256 amount1);

    /// @notice Emitted when tokens are collected for a position NFT
    /// @dev The amounts reported may not be exactly equivalent to the amounts transferred, due to rounding behavior
    /// @param tokenId The ID of the token for which underlying tokens were collected
    /// @param recipient The address of the account that received the collected tokens
    /// @param amount0 The amount of token0 owed to the position that was collected
    /// @param amount1 The amount of token1 owed to the position that was collected
    event Collect(uint256 indexed tokenId, address recipient, uint256 amount0, uint256 amount1);

    /// @notice Emitted if farming failed in call from NonfungiblePositionManager.
    /// @dev Should never be emitted
    /// @param tokenId The ID of corresponding token
    event FarmingFailed(uint256 indexed tokenId);

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

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

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

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

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

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

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

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

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

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

    /// @notice Changes approval of token ID for farming.
    /// @param tokenId The ID of the token that is being approved / unapproved
    /// @param approve New status of approval
    function approveForFarming(uint256 tokenId, bool approve) external payable;

    /// @notice Changes farming status of token to 'farmed' or 'not farmed'
    /// @dev can be called only by farmingCenter
    /// @param tokenId tokenId The ID of the token
    /// @param tokenId isFarmed The new status
    function switchFarmingStatus(uint256 tokenId, bool isFarmed) external;

    /// @notice Changes address of farmingCenter
    /// @dev can be called only by factory owner or NONFUNGIBLE_POSITION_MANAGER_ADMINISTRATOR_ROLE
    /// @param newFarmingCenter The new address of farmingCenter
    function setFarmingCenter(address newFarmingCenter) external;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);

    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

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

    /**
     * @dev Moves `amount` tokens from the caller's account to `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, uint256 amount) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `from` to `to` using the
     * allowance mechanism. `amount` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(
        address from,
        address to,
        uint256 amount
    ) external returns (bool);
}

File 31 of 44 : IERC721Enumerable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC721/extensions/IERC721Enumerable.sol)

pragma solidity ^0.8.0;

import "../IERC721.sol";

/**
 * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
 * @dev See https://eips.ethereum.org/EIPS/eip-721
 */
interface IERC721Enumerable is IERC721 {
    /**
     * @dev Returns the total amount of tokens stored by the contract.
     */
    function totalSupply() external view returns (uint256);

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

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

File 32 of 44 : IERC721Metadata.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol)

pragma solidity ^0.8.0;

import "../IERC721.sol";

/**
 * @title ERC-721 Non-Fungible Token Standard, optional metadata extension
 * @dev See https://eips.ethereum.org/EIPS/eip-721
 */
interface IERC721Metadata is IERC721 {
    /**
     * @dev Returns the token collection name.
     */
    function name() external view returns (string memory);

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

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

File 33 of 44 : IERC721.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC721/IERC721.sol)

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

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

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

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

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

File 34 of 44 : IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)

pragma solidity ^0.8.0;

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

File 35 of 44 : IncentiveKey.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.6;
pragma abicoder v2;

import '@cryptoalgebra/core/contracts/interfaces/IERC20Minimal.sol';
import '@cryptoalgebra/core/contracts/interfaces/IAlgebraPool.sol';

/// @param rewardToken The token being distributed as a reward
/// @param bonusRewardToken The bonus token being distributed as a reward
/// @param pool The Algebra pool
/// @param nonce The nonce of incentive
struct IncentiveKey {
  IERC20Minimal rewardToken;
  IERC20Minimal bonusRewardToken;
  IAlgebraPool pool;
  uint256 nonce;
}

File 36 of 44 : VirtualTickStructure.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.8.17;

import '@cryptoalgebra/core/contracts/libraries/TickTree.sol';

import '../libraries/VirtualTickManagement.sol';
import '../interfaces/IAlgebraEternalVirtualPool.sol';

/// @title Algebra tick structure abstract contract
/// @notice Encapsulates the logic of interaction with the data structure with ticks
/// @dev Ticks are stored as a doubly linked list. A two-layer bitmap tree is used to search through the list
abstract contract VirtualTickStructure is IAlgebraEternalVirtualPool {
  using VirtualTickManagement for mapping(int24 => VirtualTickManagement.Tick);
  using TickTree for mapping(int16 => uint256);

  mapping(int24 => VirtualTickManagement.Tick) public ticks;

  uint256 internal tickTreeRoot; // The root of bitmap search tree
  mapping(int16 => uint256) internal tickSecondLayer; // The second layer bitmap search tree
  mapping(int16 => uint256) internal tickTable; // the leaves of the tree

  constructor() {
    ticks.initTickState();
  }

  /**
   * @notice Used to add or remove a tick from a doubly linked list and search tree
   * @param tick The tick being removed or added now
   * @param currentTick The current global tick in the pool
   * @param prevInitializedTick Previous active tick before `currentTick`
   * @param remove Remove or add the tick
   * @return newPrevInitializedTick New previous active tick before `currentTick` if changed
   */
  function _insertOrRemoveTick(
    int24 tick,
    int24 currentTick,
    int24 prevInitializedTick,
    bool remove
  ) internal returns (int24 newPrevInitializedTick) {
    uint256 oldTickTreeRoot = tickTreeRoot;

    int24 prevTick;
    if (remove) {
      prevTick = ticks.removeTick(tick);
      if (prevInitializedTick == tick) prevInitializedTick = prevTick;
    } else {
      int24 nextTick;
      if (prevInitializedTick < tick && tick <= currentTick) {
        nextTick = ticks[prevInitializedTick].nextTick;
        prevTick = prevInitializedTick;
        prevInitializedTick = tick;
      } else {
        nextTick = tickTable.getNextTick(tickSecondLayer, oldTickTreeRoot, tick);
        prevTick = ticks[nextTick].prevTick;
      }
      ticks.insertTick(tick, prevTick, nextTick);
    }

    uint256 newTickTreeRoot = tickTable.toggleTick(tickSecondLayer, tick, oldTickTreeRoot);
    if (newTickTreeRoot != oldTickTreeRoot) tickTreeRoot = newTickTreeRoot;
    return prevInitializedTick;
  }
}

File 37 of 44 : AlgebraEternalFarming.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.8.17;

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

import '@cryptoalgebra/core/contracts/interfaces/IAlgebraPoolDeployer.sol';
import '@cryptoalgebra/core/contracts/interfaces/IAlgebraPool.sol';
import '@cryptoalgebra/core/contracts/interfaces/IAlgebraFactory.sol';
import '@cryptoalgebra/core/contracts/interfaces/IERC20Minimal.sol';
import '@cryptoalgebra/core/contracts/libraries/SafeCast.sol';
import '@cryptoalgebra/core/contracts/libraries/FullMath.sol';
import '@cryptoalgebra/core/contracts/libraries/Constants.sol';
import '@cryptoalgebra/core/contracts/libraries/TickMath.sol';
import '@cryptoalgebra/core/contracts/libraries/LowGasSafeMath.sol';

import '@cryptoalgebra/periphery/contracts/libraries/TransferHelper.sol';

/// @title Algebra eternal (v2-like) farming
contract AlgebraEternalFarming is IAlgebraEternalFarming {
  using SafeCast for int256;
  using LowGasSafeMath for uint256;
  using LowGasSafeMath for uint128;

  /// @notice Represents a farming incentive
  struct Incentive {
    uint128 totalReward;
    uint128 bonusReward;
    address virtualPoolAddress;
    uint24 minimalPositionWidth;
    bool deactivated;
  }

  /// @notice Represents the farm for nft
  struct Farm {
    uint128 liquidity;
    int24 tickLower;
    int24 tickUpper;
    uint256 innerRewardGrowth0;
    uint256 innerRewardGrowth1;
  }

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

  IAlgebraPoolDeployer private immutable deployer;
  IAlgebraFactory private immutable factory;

  IFarmingCenter public farmingCenter;

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

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

  uint256 public numOfIncentives;

  bytes32 public constant INCENTIVE_MAKER_ROLE = keccak256('INCENTIVE_MAKER_ROLE');
  bytes32 public constant FARMINGS_ADMINISTRATOR_ROLE = keccak256('FARMINGS_ADMINISTRATOR_ROLE');

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

  modifier onlyIncentiveMaker() {
    _checkHasRole(INCENTIVE_MAKER_ROLE);
    _;
  }

  modifier onlyAdministrator() {
    _checkHasRole(FARMINGS_ADMINISTRATOR_ROLE);
    _;
  }

  modifier onlyFarmingCenter() {
    _checkIsFarmingCenter();
    _;
  }

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

  /// @inheritdoc IAlgebraEternalFarming
  function isIncentiveActiveInPool(bytes32 incentiveId, IAlgebraPool pool) external view override returns (bool res) {
    Incentive storage incentive = incentives[incentiveId];
    if (incentive.deactivated) return false;

    IAlgebraEternalVirtualPool virtualPool = IAlgebraEternalVirtualPool(incentive.virtualPoolAddress);
    if (_getCurrentVirtualPool(pool) != address(virtualPool)) return false; // pool can "detach" by itself

    return true;
  }

  function _checkIsFarmingCenter() internal view {
    require(msg.sender == address(farmingCenter));
  }

  function _checkHasRole(bytes32 role) internal view {
    require(factory.hasRoleOrOwner(role, msg.sender));
  }

  /// @inheritdoc IAlgebraEternalFarming
  function createEternalFarming(
    IncentiveKey memory key,
    IncentiveParams memory params
  ) external override onlyIncentiveMaker returns (address virtualPool) {
    if (_getCurrentVirtualPool(key.pool) != address(0)) revert farmingAlreadyExists();

    virtualPool = address(new EternalVirtualPool(address(this), address(key.pool)));
    _connectPoolToVirtualPool(key.pool, virtualPool);

    key.nonce = numOfIncentives++;
    bytes32 incentiveId = IncentiveId.compute(key);
    Incentive storage newIncentive = incentives[incentiveId];

    (params.reward, params.bonusReward) = _receiveRewards(key, params.reward, params.bonusReward, newIncentive);
    if (params.reward == 0) revert zeroRewardAmount();

    unchecked {
      if (int256(uint256(params.minimalPositionWidth)) > (int256(TickMath.MAX_TICK) - int256(TickMath.MIN_TICK)))
        revert minimalPositionWidthTooWide();
    }
    (newIncentive.virtualPoolAddress, newIncentive.minimalPositionWidth) = (virtualPool, params.minimalPositionWidth);

    emit EternalFarmingCreated(
      key.rewardToken,
      key.bonusRewardToken,
      key.pool,
      virtualPool,
      key.nonce,
      params.reward,
      params.bonusReward,
      params.minimalPositionWidth
    );

    _addRewards(IAlgebraEternalVirtualPool(virtualPool), params.reward, params.bonusReward, incentiveId);
    _setRewardRates(IAlgebraEternalVirtualPool(virtualPool), params.rewardRate, params.bonusRewardRate, incentiveId);
  }

  /// @inheritdoc IAlgebraEternalFarming
  function deactivateIncentive(IncentiveKey memory key) external override onlyIncentiveMaker {
    (bytes32 incentiveId, Incentive storage incentive) = _getIncentiveByKey(key);
    if (incentive.deactivated) revert incentiveStopped();

    IAlgebraEternalVirtualPool virtualPool = IAlgebraEternalVirtualPool(incentive.virtualPoolAddress);
    if (address(virtualPool) == address(0)) revert incentiveNotExist();

    incentive.deactivated = true;

    (uint128 rewardRate0, uint128 rewardRate1) = virtualPool.rewardRates();
    if (rewardRate0 | rewardRate1 != 0) _setRewardRates(virtualPool, 0, 0, incentiveId);

    if (address(virtualPool) == _getCurrentVirtualPool(key.pool)) {
      _connectPoolToVirtualPool(key.pool, address(0));
    }
    emit IncentiveDeactivated(incentiveId);
  }

  /// @inheritdoc IAlgebraEternalFarming
  function decreaseRewardsAmount(IncentiveKey memory key, uint128 rewardAmount, uint128 bonusRewardAmount) external override onlyAdministrator {
    (bytes32 incentiveId, Incentive storage incentive) = _getIncentiveByKey(key);
    IAlgebraEternalVirtualPool virtualPool = IAlgebraEternalVirtualPool(incentive.virtualPoolAddress);

    virtualPool.distributeRewards();
    (uint128 rewardReserve0, uint128 rewardReserve1) = virtualPool.rewardReserves();
    if (rewardAmount > rewardReserve0) rewardAmount = rewardReserve0;
    if (rewardAmount >= incentive.totalReward) rewardAmount = incentive.totalReward - 1; // to not trigger 'non-existent incentive'
    incentive.totalReward = incentive.totalReward - rewardAmount;

    if (bonusRewardAmount > rewardReserve1) bonusRewardAmount = rewardReserve1;
    incentive.bonusReward = incentive.bonusReward - bonusRewardAmount;

    virtualPool.decreaseRewards(rewardAmount, bonusRewardAmount);

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

    emit RewardAmountsDecreased(rewardAmount, bonusRewardAmount, incentiveId);
  }

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

  /// @inheritdoc IAlgebraEternalFarming
  function addRewards(IncentiveKey memory key, uint128 rewardAmount, uint128 bonusRewardAmount) external override {
    (bytes32 incentiveId, Incentive storage incentive) = _getIncentiveByKey(key);
    if (incentive.deactivated) revert incentiveStopped();

    IAlgebraEternalVirtualPool virtualPool = IAlgebraEternalVirtualPool(incentive.virtualPoolAddress);
    if (_getCurrentVirtualPool(key.pool) != address(virtualPool)) revert incentiveStopped(); // pool can "detach" by itself

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

    if (rewardAmount | bonusRewardAmount > 0) {
      _addRewards(virtualPool, rewardAmount, bonusRewardAmount, incentiveId);
    }
  }

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

    if ((incentives[incentiveId].deactivated || _getCurrentVirtualPool(key.pool) != address(virtualPool)) && (rewardRate | bonusRewardRate != 0))
      revert incentiveStopped();
    _setRewardRates(virtualPool, rewardRate, bonusRewardRate, incentiveId);
  }

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

    IAlgebraEternalVirtualPool virtualPool = IAlgebraEternalVirtualPool(virtualPoolAddress);
    (uint256 innerRewardGrowth0, uint256 innerRewardGrowth1) = _getInnerRewardsGrowth(virtualPool, tickLower, tickUpper);

    farms[tokenId][incentiveId] = Farm(liquidity, tickLower, tickUpper, innerRewardGrowth0, innerRewardGrowth1);

    emit FarmEntered(tokenId, incentiveId, liquidity);
  }

  /// @inheritdoc IAlgebraEternalFarming
  function exitFarming(IncentiveKey memory key, uint256 tokenId, address _owner) external override onlyFarmingCenter {
    bytes32 incentiveId = IncentiveId.compute(key);
    Farm memory farm = farms[tokenId][incentiveId];
    if (farm.liquidity == 0) revert farmDoesNotExist();

    (uint256 reward, uint256 bonusReward) = _updatePosition(farm, key, incentiveId, _owner, -int256(uint256(farm.liquidity)).toInt128());

    delete farms[tokenId][incentiveId];

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

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

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

  function _updatePosition(
    Farm memory farm,
    IncentiveKey memory key,
    bytes32 incentiveId,
    address _owner,
    int128 liquidityDelta
  ) internal returns (uint256 reward, uint256 bonusReward) {
    Incentive storage incentive = incentives[incentiveId];
    IAlgebraEternalVirtualPool virtualPool = IAlgebraEternalVirtualPool(incentive.virtualPoolAddress);

    if (_getCurrentVirtualPool(key.pool) != address(virtualPool)) incentive.deactivated = true; // pool can "detach" by itself
    int24 tick = incentive.deactivated ? virtualPool.globalTick() : _getTickInPool(key.pool);

    // update rewards, as ticks may be cleared when liquidity decreases
    virtualPool.distributeRewards();

    (reward, bonusReward, , ) = _getNewRewardsForFarm(virtualPool, farm);

    if (liquidityDelta != 0) {
      _updatePositionInVirtualPool(address(virtualPool), uint32(block.timestamp), farm.tickLower, farm.tickUpper, liquidityDelta, tick);
    }

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

  /// @notice reward amounts can be outdated, actual amounts could be obtained via static call of `collectRewards` in FarmingCenter
  /// @inheritdoc IAlgebraEternalFarming
  function getRewardInfo(IncentiveKey memory key, uint256 tokenId) external view override returns (uint256 reward, uint256 bonusReward) {
    bytes32 incentiveId = IncentiveId.compute(key);
    Farm memory farm = farms[tokenId][incentiveId];
    if (farm.liquidity == 0) revert farmDoesNotExist();

    IAlgebraEternalVirtualPool virtualPool = IAlgebraEternalVirtualPool(incentives[incentiveId].virtualPoolAddress);
    (reward, bonusReward, , ) = _getNewRewardsForFarm(virtualPool, farm);
  }

  /// @notice reward amounts should be updated before calling this method
  /// @inheritdoc IAlgebraEternalFarming
  function collectRewards(
    IncentiveKey memory key,
    uint256 tokenId,
    address _owner
  ) external override onlyFarmingCenter returns (uint256 reward, uint256 bonusReward) {
    (bytes32 incentiveId, Incentive storage incentive) = _getIncentiveByKey(key);
    Farm memory farm = farms[tokenId][incentiveId];
    if (farm.liquidity == 0) revert farmDoesNotExist();

    IAlgebraEternalVirtualPool virtualPool = IAlgebraEternalVirtualPool(incentive.virtualPoolAddress);
    virtualPool.distributeRewards();

    uint256 innerRewardGrowth0;
    uint256 innerRewardGrowth1;
    (reward, bonusReward, innerRewardGrowth0, innerRewardGrowth1) = _getNewRewardsForFarm(virtualPool, farm);

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

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

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

  function _getInnerRewardsGrowth(IAlgebraEternalVirtualPool virtualPool, int24 tickLower, int24 tickUpper) private view returns (uint256, uint256) {
    return virtualPool.getInnerRewardsGrowth(tickLower, tickUpper);
  }

  function _getNewRewardsForFarm(
    IAlgebraEternalVirtualPool virtualPool,
    Farm memory farm
  ) private view returns (uint256 reward, uint256 bonusReward, uint256 innerRewardGrowth0, uint256 innerRewardGrowth1) {
    (innerRewardGrowth0, innerRewardGrowth1) = _getInnerRewardsGrowth(virtualPool, farm.tickLower, farm.tickUpper);

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

  function _addRewards(IAlgebraEternalVirtualPool virtualPool, uint128 amount0, uint128 amount1, bytes32 incentiveId) private {
    virtualPool.addRewards(amount0, amount1);
    emit RewardsAdded(amount0, amount1, incentiveId);
  }

  function _setRewardRates(IAlgebraEternalVirtualPool virtualPool, uint128 rate0, uint128 rate1, bytes32 incentiveId) private {
    virtualPool.setRates(rate0, rate1);
    emit RewardsRatesChanged(rate0, rate1, incentiveId);
  }

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

  function _getCurrentVirtualPool(IAlgebraPool pool) internal view returns (address virtualPool) {
    return pool.activeIncentive();
  }

  function _receiveRewards(
    IncentiveKey memory key,
    uint128 reward,
    uint128 bonusReward,
    Incentive storage incentive
  ) internal returns (uint128 receivedReward, uint128 receivedBonusReward) {
    if (reward > 0) receivedReward = _receiveToken(key.rewardToken, reward);
    if (bonusReward > 0) receivedBonusReward = _receiveToken(key.bonusRewardToken, bonusReward);

    incentive.totalReward = incentive.totalReward + receivedReward;
    incentive.bonusReward = incentive.bonusReward + receivedBonusReward;
  }

  function _receiveToken(IERC20Minimal token, uint128 amount) private returns (uint128) {
    uint256 balanceBefore = token.balanceOf(address(this));
    TransferHelper.safeTransferFrom(address(token), msg.sender, address(this), amount);
    uint256 balanceAfter = token.balanceOf(address(this));
    require(balanceAfter > balanceBefore);
    unchecked {
      uint256 received = uint128(balanceAfter - balanceBefore);
      require(received <= type(uint128).max, 'invalid token amount');
      return (uint128(received));
    }
  }

  function _enterFarming(
    IncentiveKey memory key,
    uint256 tokenId
  ) internal returns (bytes32 incentiveId, int24 tickLower, int24 tickUpper, uint128 liquidity, address virtualPool) {
    Incentive storage incentive;
    (incentiveId, incentive) = _getIncentiveByKey(key);
    virtualPool = incentive.virtualPoolAddress;

    if (farms[tokenId][incentiveId].liquidity != 0) revert tokenAlreadyFarmed();
    if (_getCurrentVirtualPool(key.pool) != address(virtualPool) || incentive.deactivated) revert incentiveStopped(); // pool can "detach" by itself

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

    if (pool != key.pool) revert invalidPool();
    if (liquidity == 0) revert zeroLiquidity();

    uint24 minimalAllowedTickWidth = incentive.minimalPositionWidth;
    unchecked {
      if (int256(tickUpper) - int256(tickLower) < int256(uint256(minimalAllowedTickWidth))) revert positionIsTooNarrow();
    }

    int24 tick = _getTickInPool(pool);
    _updatePositionInVirtualPool(virtualPool, uint32(block.timestamp), tickLower, tickUpper, int256(uint256(liquidity)).toInt128(), tick);
  }

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

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

    if (amountRequested > 0) {
      unchecked {
        rewards[from][rewardToken] = reward - amountRequested;
      }
      TransferHelper.safeTransfer(address(rewardToken), to, amountRequested);
      emit RewardClaimed(to, amountRequested, address(rewardToken), from);
    }
  }

  function _getIncentiveByKey(IncentiveKey memory key) internal view returns (bytes32 incentiveId, Incentive storage incentive) {
    incentiveId = IncentiveId.compute(key);
    incentive = incentives[incentiveId];
    if (incentive.totalReward == 0) revert incentiveNotExist();
  }

  function _getTickInPool(IAlgebraPool pool) internal view returns (int24 tick) {
    (, tick, , , , , ) = pool.globalState();
  }

  function _updatePositionInVirtualPool(
    address virtualPool,
    uint32 timestamp,
    int24 tickLower,
    int24 tickUpper,
    int128 liquidityDelta,
    int24 currentTick
  ) internal {
    IAlgebraEternalVirtualPool(virtualPool).applyLiquidityDeltaToPosition(timestamp, tickLower, tickUpper, liquidityDelta, currentTick);
  }
}

File 38 of 44 : EternalVirtualPool.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.8.17;

import '@cryptoalgebra/core/contracts/libraries/FullMath.sol';
import '@cryptoalgebra/core/contracts/libraries/Constants.sol';
import '@cryptoalgebra/core/contracts/libraries/TickMath.sol';
import '@cryptoalgebra/core/contracts/libraries/LiquidityMath.sol';

import '../libraries/VirtualTickManagement.sol';

import '../base/VirtualTickStructure.sol';

/// @title Algebra eternal virtual pool
/// @notice used to track active liquidity in farming and distribute rewards
contract EternalVirtualPool is VirtualTickStructure {
  using VirtualTickManagement for mapping(int24 => VirtualTickManagement.Tick);

  address public immutable farmingAddress;
  address public immutable pool;

  /// @inheritdoc IAlgebraEternalVirtualPool
  uint128 public override currentLiquidity;
  /// @inheritdoc IAlgebraEternalVirtualPool
  int24 public override globalTick;
  /// @inheritdoc IAlgebraEternalVirtualPool
  uint32 public override prevTimestamp;

  int24 internal globalPrevInitializedTick;

  uint128 internal rewardRate0;
  uint128 internal rewardRate1;

  uint128 internal rewardReserve0;
  uint128 internal rewardReserve1;

  uint256 public totalRewardGrowth0 = 1;
  uint256 public totalRewardGrowth1 = 1;

  modifier onlyFromFarming() {
    _checkIsFromFarming();
    _;
  }

  constructor(address _farmingAddress, address _pool) {
    globalPrevInitializedTick = TickMath.MIN_TICK;
    farmingAddress = _farmingAddress;
    pool = _pool;
    prevTimestamp = uint32(block.timestamp);
  }

  // @inheritdoc IAlgebraEternalVirtualPool
  function rewardReserves() external view override returns (uint128 reserve0, uint128 reserve1) {
    return (rewardReserve0, rewardReserve1);
  }

  // @inheritdoc IAlgebraEternalVirtualPool
  function rewardRates() external view override returns (uint128 rate0, uint128 rate1) {
    return (rewardRate0, rewardRate1);
  }

  // @inheritdoc IAlgebraEternalVirtualPool
  function getInnerRewardsGrowth(
    int24 bottomTick,
    int24 topTick
  ) external view override returns (uint256 rewardGrowthInside0, uint256 rewardGrowthInside1) {
    unchecked {
      // check if ticks are initialized
      if (ticks[bottomTick].prevTick == ticks[bottomTick].nextTick) revert IAlgebraPoolErrors.tickIsNotInitialized();
      if (ticks[topTick].prevTick == ticks[topTick].nextTick) revert IAlgebraPoolErrors.tickIsNotInitialized();

      uint32 timeDelta = uint32(block.timestamp) - prevTimestamp;
      (uint256 _totalRewardGrowth0, uint256 _totalRewardGrowth1) = (totalRewardGrowth0, totalRewardGrowth1);

      if (timeDelta > 0) {
        // update rewards
        uint128 _currentLiquidity = currentLiquidity;
        if (_currentLiquidity > 0) {
          (uint256 reward0, uint256 reward1) = (rewardRate0 * timeDelta, rewardRate1 * timeDelta);
          (uint256 _rewardReserve0, uint256 _rewardReserve1) = (rewardReserve0, rewardReserve1);

          if (reward0 > _rewardReserve0) reward0 = _rewardReserve0;
          if (reward1 > _rewardReserve1) reward1 = _rewardReserve1;

          if (reward0 > 0) _totalRewardGrowth0 += FullMath.mulDiv(reward0, Constants.Q128, _currentLiquidity);
          if (reward1 > 0) _totalRewardGrowth1 += FullMath.mulDiv(reward1, Constants.Q128, _currentLiquidity);
        }
      }

      return ticks.getInnerFeeGrowth(bottomTick, topTick, globalTick, _totalRewardGrowth0, _totalRewardGrowth1);
    }
  }

  // @inheritdoc IAlgebraEternalVirtualPool
  function addRewards(uint128 token0Amount, uint128 token1Amount) external override onlyFromFarming {
    _applyRewardsDelta(true, token0Amount, token1Amount);
  }

  // @inheritdoc IAlgebraEternalVirtualPool
  function decreaseRewards(uint128 token0Amount, uint128 token1Amount) external override onlyFromFarming {
    _applyRewardsDelta(false, token0Amount, token1Amount);
  }

  /// @inheritdoc IAlgebraVirtualPool
  function crossTo(int24 targetTick, bool zeroToOne) external override returns (bool) {
    if (msg.sender != pool) revert onlyPool();
    _distributeRewards();

    int24 previousTick = globalPrevInitializedTick;
    uint128 _currentLiquidity = currentLiquidity;
    int24 _globalTick = globalTick;

    (uint256 rewardGrowth0, uint256 rewardGrowth1) = (totalRewardGrowth0, totalRewardGrowth1);
    // The set of active ticks in the virtual pool must be a subset of the active ticks in the real pool
    // so this loop will cross no more ticks than the real pool
    if (zeroToOne) {
      while (_globalTick != TickMath.MIN_TICK) {
        if (targetTick >= previousTick) break;
        unchecked {
          _currentLiquidity = LiquidityMath.addDelta(_currentLiquidity, -ticks.cross(previousTick, rewardGrowth0, rewardGrowth1));
          _globalTick = previousTick - 1; // safe since tick index range is narrower than the data type
          previousTick = ticks[previousTick].prevTick;
          if (_globalTick < TickMath.MIN_TICK) _globalTick = TickMath.MIN_TICK;
        }
      }
    } else {
      while (_globalTick != TickMath.MAX_TICK - 1) {
        int24 nextTick = ticks[previousTick].nextTick;
        if (targetTick < nextTick) break;

        _currentLiquidity = LiquidityMath.addDelta(_currentLiquidity, ticks.cross(nextTick, rewardGrowth0, rewardGrowth1));
        (_globalTick, previousTick) = (nextTick, nextTick);
      }
    }

    globalTick = targetTick;
    currentLiquidity = _currentLiquidity;
    globalPrevInitializedTick = previousTick;
    return true;
  }

  /// @inheritdoc IAlgebraEternalVirtualPool
  function distributeRewards() external override onlyFromFarming {
    _distributeRewards();
  }

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

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

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

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

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

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

      if (flippedBottom || flippedTop) {
        int24 previousTick = globalPrevInitializedTick;
        if (flippedBottom) {
          previousTick = _insertOrRemoveTick(bottomTick, currentTick, previousTick, liquidityDelta < 0);
        }
        if (flippedTop) {
          previousTick = _insertOrRemoveTick(topTick, currentTick, previousTick, liquidityDelta < 0);
        }
        globalPrevInitializedTick = previousTick;
      }
    }
  }

  // @inheritdoc IAlgebraEternalVirtualPool
  function setRates(uint128 rate0, uint128 rate1) external override onlyFromFarming {
    _distributeRewards();
    (rewardRate0, rewardRate1) = (rate0, rate1);
  }

  function _checkIsFromFarming() internal view {
    if (msg.sender != farmingAddress) revert onlyFarming();
  }

  function _applyRewardsDelta(bool add, uint128 token0Delta, uint128 token1Delta) private {
    _distributeRewards();
    if (token0Delta | token1Delta != 0) {
      (uint128 _rewardReserve0, uint128 _rewardReserve1) = (rewardReserve0, rewardReserve1);
      _rewardReserve0 = add ? _rewardReserve0 + token0Delta : _rewardReserve0 - token0Delta;
      _rewardReserve1 = add ? _rewardReserve1 + token1Delta : _rewardReserve1 - token1Delta;
      (rewardReserve0, rewardReserve1) = (_rewardReserve0, _rewardReserve1);
    }
  }

  function _distributeRewards() internal {
    unchecked {
      uint256 timeDelta = uint32(block.timestamp) - prevTimestamp; // safe until timedelta > 136 years
      if (timeDelta == 0) return; // only once per block

      uint256 _currentLiquidity = currentLiquidity; // currentLiquidity is uint128
      if (_currentLiquidity > 0) {
        (uint256 reward0, uint256 reward1) = (rewardRate0 * timeDelta, rewardRate1 * timeDelta);
        (uint128 _rewardReserve0, uint128 _rewardReserve1) = (rewardReserve0, rewardReserve1);

        if (reward0 > _rewardReserve0) reward0 = _rewardReserve0;
        if (reward1 > _rewardReserve1) reward1 = _rewardReserve1;

        if (reward0 | reward1 != 0) {
          _rewardReserve0 = uint128(_rewardReserve0 - reward0);
          _rewardReserve1 = uint128(_rewardReserve1 - reward1);

          if (reward0 > 0) totalRewardGrowth0 += FullMath.mulDiv(reward0, Constants.Q128, _currentLiquidity);
          if (reward1 > 0) totalRewardGrowth1 += FullMath.mulDiv(reward1, Constants.Q128, _currentLiquidity);

          (rewardReserve0, rewardReserve1) = (_rewardReserve0, _rewardReserve1);
        }
      }
    }

    prevTimestamp = uint32(block.timestamp);
    return;
  }

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

File 39 of 44 : IAlgebraEternalFarming.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.8.17;

import '@cryptoalgebra/periphery/contracts/interfaces/INonfungiblePositionManager.sol';
import '../base/IncentiveKey.sol';

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

  error farmingAlreadyExists();
  error farmDoesNotExist();
  error tokenAlreadyFarmed();
  error incentiveNotExist();
  error incentiveStopped();
  error anotherFarmingIsActive();

  error minimalPositionWidthTooWide();
  error zeroRewardAmount();

  error positionIsTooNarrow();
  error zeroLiquidity();
  error invalidPool();
  error claimToZeroAddress();

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

  /// @notice Represents a farming incentive
  /// @param incentiveId The ID of the incentive computed from its parameters
  function incentives(
    bytes32 incentiveId
  ) external view returns (uint128 totalReward, uint128 bonusReward, address virtualPoolAddress, uint24 minimalPositionWidth, bool deactivated);

  /// @notice Check if incentive is active in Algebra pool
  /// @dev Does not check that the pool is indeed an Algebra pool
  /// @param incentiveId The ID of the incentive computed from its parameters
  /// @param pool Corresponding Algebra pool
  /// @return res True if incentive is active in Algebra pool
  function isIncentiveActiveInPool(bytes32 incentiveId, IAlgebraPool pool) external view returns (bool res);

  /// @notice Detach incentive from the pool and deactivate it
  /// @param key The key of the incentive
  function deactivateIncentive(IncentiveKey memory key) external;

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

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

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

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

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

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

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

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

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

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

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

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

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

  /// @notice Event emitted when a liquidity mining incentive has been stopped from the outside
  /// @param incentiveId The stopped incentive
  event IncentiveDeactivated(bytes32 indexed incentiveId);

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

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

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

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

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

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

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

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

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

  /// @notice Event emitted when a liquidity mining incentive has been created
  /// @param rewardToken The token being distributed as a reward
  /// @param bonusRewardToken The token being distributed as a bonus reward
  /// @param pool The Algebra pool
  /// @param virtualPool The virtual pool address
  /// @param nonce The nonce of new farming
  /// @param reward The amount of reward tokens to be distributed
  /// @param bonusReward The amount of bonus reward tokens to be distributed
  /// @param minimalAllowedPositionWidth The minimal allowed position width (tickUpper - tickLower)
  event EternalFarmingCreated(
    IERC20Minimal indexed rewardToken,
    IERC20Minimal indexed bonusRewardToken,
    IAlgebraPool indexed pool,
    address virtualPool,
    uint256 nonce,
    uint256 reward,
    uint256 bonusReward,
    uint24 minimalAllowedPositionWidth
  );
}

File 40 of 44 : IAlgebraEternalVirtualPool.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.8.17;

import '@cryptoalgebra/core/contracts/interfaces/IAlgebraVirtualPool.sol';

interface IAlgebraEternalVirtualPool is IAlgebraVirtualPool {
  error onlyPool();
  error onlyFarming();

  // returns data associated with a tick
  function ticks(
    int24 tickId
  )
    external
    view
    returns (
      uint128 liquidityTotal,
      int128 liquidityDelta,
      uint256 outerFeeGrowth0Token,
      uint256 outerFeeGrowth1Token,
      int24 prevTick,
      int24 nextTick
    );

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

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

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

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

  /// @dev This function is called from the main pool before every swap To increase rewards per liquidity
  /// cumulative considering previous liquidity. The liquidity is stored in a virtual pool
  function distributeRewards() external;

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

  /// @notice Top up rewards reserves
  /// @param token0Amount The amount of token0
  /// @param token1Amount The amount of token1
  function addRewards(uint128 token0Amount, uint128 token1Amount) external;

  /// @notice Withdraw rewards from reserves directly
  /// @param token0Amount The amount of token0
  /// @param token1Amount The amount of token1
  function decreaseRewards(uint128 token0Amount, uint128 token1Amount) external;

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

  /// @notice Get reserves of rewards in one call
  /// @return reserve0 The reserve of token0
  /// @return reserve1 The reserve of token1
  function rewardReserves() external view returns (uint128 reserve0, uint128 reserve1);

  /// @notice Get rates of rewards in one call
  /// @return rate0 The rate of token0, rewards / sec
  /// @return rate1 The rate of token1, rewards / sec
  function rewardRates() external view returns (uint128 rate0, uint128 rate1);
}

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

import '@cryptoalgebra/core/contracts/interfaces/IAlgebraPool.sol';
import '@cryptoalgebra/core/contracts/interfaces/IERC20Minimal.sol';

import '@cryptoalgebra/periphery/contracts/interfaces/IMulticall.sol';
import '@cryptoalgebra/periphery/contracts/interfaces/INonfungiblePositionManager.sol';

import '../base/IncentiveKey.sol';
import '../interfaces/IAlgebraEternalFarming.sol';

interface IFarmingCenter is IMulticall {
  function virtualPoolAddresses(address) external view returns (address);

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

  /// @notice The eternal farming contract
  function eternalFarming() external view returns (IAlgebraEternalFarming);

  /// @notice The Algebra poolDeployer contract
  function algebraPoolDeployer() external view returns (address);

  /// @notice Returns information about a deposited NFT
  /// @param tokenId The ID of the deposit (and token) that is being transferred
  /// @return eternalIncentiveId The id of eternal incentive that is active for this NFT
  function deposits(uint256 tokenId) external view returns (bytes32 eternalIncentiveId);

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

  /// @notice Enters in incentive (time-limited or eternal farming) with NFT-position token
  /// @dev token must be deposited in FarmingCenter
  /// @param key The incentive event key
  /// @param tokenId The id of position NFT
  function enterFarming(IncentiveKey memory key, uint256 tokenId) external;

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

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

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

File 42 of 44 : IncentiveId.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.8.17;

import '../base/IncentiveKey.sol';

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

File 43 of 44 : NFTPositionInfo.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.8.17;

import '@cryptoalgebra/core/contracts/interfaces/IAlgebraPool.sol';
import '@cryptoalgebra/core/contracts/interfaces/IAlgebraPoolDeployer.sol';
import '@cryptoalgebra/periphery/contracts/interfaces/INonfungiblePositionManager.sol';
import '@cryptoalgebra/periphery/contracts/libraries/PoolAddress.sol';

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

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

File 44 of 44 : VirtualTickManagement.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.8.17;

import '@cryptoalgebra/core/contracts/interfaces/IAlgebraPoolErrors.sol';

import '@cryptoalgebra/core/contracts/libraries/TickMath.sol';
import '@cryptoalgebra/core/contracts/libraries/LiquidityMath.sol';
import '@cryptoalgebra/core/contracts/libraries/Constants.sol';

/// @title VirtualTickManagement
/// @notice Contains functions for managing tick processes and relevant calculations
library VirtualTickManagement {
  // info stored for each initialized individual tick
  struct Tick {
    uint128 liquidityTotal; // the total position liquidity that references this tick
    int128 liquidityDelta; // amount of net liquidity added (subtracted) when tick is crossed left-right (right-left),
    // fee growth per unit of liquidity on the _other_ side of this tick (relative to the current tick)
    // only has relative meaning, not absolute — the value depends on when the tick is initialized
    uint256 outerFeeGrowth0Token;
    uint256 outerFeeGrowth1Token;
    int24 prevTick;
    int24 nextTick;
  }

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

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

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

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

    uint128 liquidityTotalAfter = LiquidityMath.addDelta(liquidityTotalBefore, liquidityDelta);
    if (liquidityTotalAfter > Constants.MAX_LIQUIDITY_PER_TICK) revert IAlgebraPoolErrors.liquidityOverflow();

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

    data.liquidityTotal = liquidityTotalAfter;

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

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

    unchecked {
      data.outerFeeGrowth1Token = totalFeeGrowth1Token - data.outerFeeGrowth1Token;
      data.outerFeeGrowth0Token = totalFeeGrowth0Token - data.outerFeeGrowth0Token;
    }
    return data.liquidityDelta;
  }

  /// @notice Used for initial setup of ticks list
  /// @param self The mapping containing all tick information for initialized ticks
  function initTickState(mapping(int24 => Tick) storage self) internal {
    (self[TickMath.MIN_TICK].prevTick, self[TickMath.MIN_TICK].nextTick) = (TickMath.MIN_TICK, TickMath.MAX_TICK);
    (self[TickMath.MAX_TICK].prevTick, self[TickMath.MAX_TICK].nextTick) = (TickMath.MIN_TICK, TickMath.MAX_TICK);
  }

  /// @notice Removes tick from linked list
  /// @param self The mapping containing all tick information for initialized ticks
  /// @param tick The tick that will be removed
  /// @return prevTick
  function removeTick(mapping(int24 => Tick) storage self, int24 tick) internal returns (int24) {
    (int24 prevTick, int24 nextTick) = (self[tick].prevTick, self[tick].nextTick);
    delete self[tick];

    if (tick == TickMath.MIN_TICK || tick == TickMath.MAX_TICK) {
      // MIN_TICK and MAX_TICK cannot be removed from tick list
      (self[tick].prevTick, self[tick].nextTick) = (prevTick, nextTick);
      return prevTick;
    } else {
      if (prevTick == nextTick) revert IAlgebraPoolErrors.tickIsNotInitialized();
      self[prevTick].nextTick = nextTick;
      self[nextTick].prevTick = prevTick;
      return prevTick;
    }
  }

  /// @notice Adds tick to linked list
  /// @param self The mapping containing all tick information for initialized ticks
  /// @param tick The tick that will be inserted
  /// @param prevTick The previous active tick
  /// @param nextTick The next active tick
  function insertTick(mapping(int24 => Tick) storage self, int24 tick, int24 prevTick, int24 nextTick) internal {
    if (tick == TickMath.MIN_TICK || tick == TickMath.MAX_TICK) return;
    if (prevTick >= tick || nextTick <= tick) revert IAlgebraPoolErrors.tickInvalidLinks();
    (self[tick].prevTick, self[tick].nextTick) = (prevTick, nextTick);

    self[prevTick].nextTick = tick;
    self[nextTick].prevTick = tick;
  }
}

Settings
{
  "optimizer": {
    "enabled": true,
    "runs": 99999999
  },
  "metadata": {
    "bytecodeHash": "none"
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "libraries": {}
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"contract IAlgebraPoolDeployer","name":"_deployer","type":"address"},{"internalType":"contract INonfungiblePositionManager","name":"_nonfungiblePositionManager","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"anotherFarmingIsActive","type":"error"},{"inputs":[],"name":"claimToZeroAddress","type":"error"},{"inputs":[],"name":"farmDoesNotExist","type":"error"},{"inputs":[],"name":"farmingAlreadyExists","type":"error"},{"inputs":[],"name":"incentiveNotExist","type":"error"},{"inputs":[],"name":"incentiveStopped","type":"error"},{"inputs":[],"name":"invalidPool","type":"error"},{"inputs":[],"name":"minimalPositionWidthTooWide","type":"error"},{"inputs":[],"name":"positionIsTooNarrow","type":"error"},{"inputs":[],"name":"tokenAlreadyFarmed","type":"error"},{"inputs":[],"name":"zeroLiquidity","type":"error"},{"inputs":[],"name":"zeroRewardAmount","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"contract IERC20Minimal","name":"rewardToken","type":"address"},{"indexed":true,"internalType":"contract IERC20Minimal","name":"bonusRewardToken","type":"address"},{"indexed":true,"internalType":"contract IAlgebraPool","name":"pool","type":"address"},{"indexed":false,"internalType":"address","name":"virtualPool","type":"address"},{"indexed":false,"internalType":"uint256","name":"nonce","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"reward","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"bonusReward","type":"uint256"},{"indexed":false,"internalType":"uint24","name":"minimalAllowedPositionWidth","type":"uint24"}],"name":"EternalFarmingCreated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":true,"internalType":"bytes32","name":"incentiveId","type":"bytes32"},{"indexed":true,"internalType":"address","name":"rewardAddress","type":"address"},{"indexed":false,"internalType":"address","name":"bonusRewardToken","type":"address"},{"indexed":false,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"uint256","name":"reward","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"bonusReward","type":"uint256"}],"name":"FarmEnded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":true,"internalType":"bytes32","name":"incentiveId","type":"bytes32"},{"indexed":false,"internalType":"uint128","name":"liquidity","type":"uint128"}],"name":"FarmEntered","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"farmingCenter","type":"address"}],"name":"FarmingCenter","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"incentiveId","type":"bytes32"}],"name":"IncentiveDeactivated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"incentiveMaker","type":"address"}],"name":"IncentiveMaker","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"reward","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"bonusReward","type":"uint256"},{"indexed":false,"internalType":"bytes32","name":"incentiveId","type":"bytes32"}],"name":"RewardAmountsDecreased","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"reward","type":"uint256"},{"indexed":true,"internalType":"address","name":"rewardAddress","type":"address"},{"indexed":true,"internalType":"address","name":"owner","type":"address"}],"name":"RewardClaimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"rewardAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"bonusRewardAmount","type":"uint256"},{"indexed":false,"internalType":"bytes32","name":"incentiveId","type":"bytes32"}],"name":"RewardsAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"bytes32","name":"incentiveId","type":"bytes32"},{"indexed":false,"internalType":"uint256","name":"rewardAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"bonusRewardAmount","type":"uint256"}],"name":"RewardsCollected","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint128","name":"rewardRate","type":"uint128"},{"indexed":false,"internalType":"uint128","name":"bonusRewardRate","type":"uint128"},{"indexed":false,"internalType":"bytes32","name":"incentiveId","type":"bytes32"}],"name":"RewardsRatesChanged","type":"event"},{"inputs":[],"name":"FARMINGS_ADMINISTRATOR_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"INCENTIVE_MAKER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"contract IERC20Minimal","name":"rewardToken","type":"address"},{"internalType":"contract IERC20Minimal","name":"bonusRewardToken","type":"address"},{"internalType":"contract IAlgebraPool","name":"pool","type":"address"},{"internalType":"uint256","name":"nonce","type":"uint256"}],"internalType":"struct IncentiveKey","name":"key","type":"tuple"},{"internalType":"uint128","name":"rewardAmount","type":"uint128"},{"internalType":"uint128","name":"bonusRewardAmount","type":"uint128"}],"name":"addRewards","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20Minimal","name":"rewardToken","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amountRequested","type":"uint256"}],"name":"claimReward","outputs":[{"internalType":"uint256","name":"reward","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20Minimal","name":"rewardToken","type":"address"},{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amountRequested","type":"uint256"}],"name":"claimRewardFrom","outputs":[{"internalType":"uint256","name":"reward","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"contract IERC20Minimal","name":"rewardToken","type":"address"},{"internalType":"contract IERC20Minimal","name":"bonusRewardToken","type":"address"},{"internalType":"contract IAlgebraPool","name":"pool","type":"address"},{"internalType":"uint256","name":"nonce","type":"uint256"}],"internalType":"struct IncentiveKey","name":"key","type":"tuple"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"_owner","type":"address"}],"name":"collectRewards","outputs":[{"internalType":"uint256","name":"reward","type":"uint256"},{"internalType":"uint256","name":"bonusReward","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"contract IERC20Minimal","name":"rewardToken","type":"address"},{"internalType":"contract IERC20Minimal","name":"bonusRewardToken","type":"address"},{"internalType":"contract IAlgebraPool","name":"pool","type":"address"},{"internalType":"uint256","name":"nonce","type":"uint256"}],"internalType":"struct IncentiveKey","name":"key","type":"tuple"},{"components":[{"internalType":"uint128","name":"reward","type":"uint128"},{"internalType":"uint128","name":"bonusReward","type":"uint128"},{"internalType":"uint128","name":"rewardRate","type":"uint128"},{"internalType":"uint128","name":"bonusRewardRate","type":"uint128"},{"internalType":"uint24","name":"minimalPositionWidth","type":"uint24"}],"internalType":"struct IAlgebraEternalFarming.IncentiveParams","name":"params","type":"tuple"}],"name":"createEternalFarming","outputs":[{"internalType":"address","name":"virtualPool","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"contract IERC20Minimal","name":"rewardToken","type":"address"},{"internalType":"contract IERC20Minimal","name":"bonusRewardToken","type":"address"},{"internalType":"contract IAlgebraPool","name":"pool","type":"address"},{"internalType":"uint256","name":"nonce","type":"uint256"}],"internalType":"struct IncentiveKey","name":"key","type":"tuple"}],"name":"deactivateIncentive","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"contract IERC20Minimal","name":"rewardToken","type":"address"},{"internalType":"contract IERC20Minimal","name":"bonusRewardToken","type":"address"},{"internalType":"contract IAlgebraPool","name":"pool","type":"address"},{"internalType":"uint256","name":"nonce","type":"uint256"}],"internalType":"struct IncentiveKey","name":"key","type":"tuple"},{"internalType":"uint128","name":"rewardAmount","type":"uint128"},{"internalType":"uint128","name":"bonusRewardAmount","type":"uint128"}],"name":"decreaseRewardsAmount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"contract IERC20Minimal","name":"rewardToken","type":"address"},{"internalType":"contract IERC20Minimal","name":"bonusRewardToken","type":"address"},{"internalType":"contract IAlgebraPool","name":"pool","type":"address"},{"internalType":"uint256","name":"nonce","type":"uint256"}],"internalType":"struct IncentiveKey","name":"key","type":"tuple"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"enterFarming","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"contract IERC20Minimal","name":"rewardToken","type":"address"},{"internalType":"contract IERC20Minimal","name":"bonusRewardToken","type":"address"},{"internalType":"contract IAlgebraPool","name":"pool","type":"address"},{"internalType":"uint256","name":"nonce","type":"uint256"}],"internalType":"struct IncentiveKey","name":"key","type":"tuple"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"_owner","type":"address"}],"name":"exitFarming","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"farmingCenter","outputs":[{"internalType":"contract IFarmingCenter","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"farms","outputs":[{"internalType":"uint128","name":"liquidity","type":"uint128"},{"internalType":"int24","name":"tickLower","type":"int24"},{"internalType":"int24","name":"tickUpper","type":"int24"},{"internalType":"uint256","name":"innerRewardGrowth0","type":"uint256"},{"internalType":"uint256","name":"innerRewardGrowth1","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"contract IERC20Minimal","name":"rewardToken","type":"address"},{"internalType":"contract IERC20Minimal","name":"bonusRewardToken","type":"address"},{"internalType":"contract IAlgebraPool","name":"pool","type":"address"},{"internalType":"uint256","name":"nonce","type":"uint256"}],"internalType":"struct IncentiveKey","name":"key","type":"tuple"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getRewardInfo","outputs":[{"internalType":"uint256","name":"reward","type":"uint256"},{"internalType":"uint256","name":"bonusReward","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"incentives","outputs":[{"internalType":"uint128","name":"totalReward","type":"uint128"},{"internalType":"uint128","name":"bonusReward","type":"uint128"},{"internalType":"address","name":"virtualPoolAddress","type":"address"},{"internalType":"uint24","name":"minimalPositionWidth","type":"uint24"},{"internalType":"bool","name":"deactivated","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"incentiveId","type":"bytes32"},{"internalType":"contract IAlgebraPool","name":"pool","type":"address"}],"name":"isIncentiveActiveInPool","outputs":[{"internalType":"bool","name":"res","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nonfungiblePositionManager","outputs":[{"internalType":"contract INonfungiblePositionManager","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"numOfIncentives","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"contract IERC20Minimal","name":"","type":"address"}],"name":"rewards","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_farmingCenter","type":"address"}],"name":"setFarmingCenterAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"contract IERC20Minimal","name":"rewardToken","type":"address"},{"internalType":"contract IERC20Minimal","name":"bonusRewardToken","type":"address"},{"internalType":"contract IAlgebraPool","name":"pool","type":"address"},{"internalType":"uint256","name":"nonce","type":"uint256"}],"internalType":"struct IncentiveKey","name":"key","type":"tuple"},{"internalType":"uint128","name":"rewardRate","type":"uint128"},{"internalType":"uint128","name":"bonusRewardRate","type":"uint128"}],"name":"setRates","outputs":[],"stateMutability":"nonpayable","type":"function"}]

60e06040523480156200001157600080fd5b5060405162005f6738038062005f678339810160408190526200003491620000da565b6001600160a01b03808216608081905290831660a0526040805163c45a015560e01b8152905163c45a0155916004808201926020929091908290030181865afa15801562000086573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620000ac919062000119565b6001600160a01b031660c05250620001409050565b6001600160a01b0381168114620000d757600080fd5b50565b60008060408385031215620000ee57600080fd5b8251620000fb81620000c1565b60208401519092506200010e81620000c1565b809150509250929050565b6000602082840312156200012c57600080fd5b81516200013981620000c1565b9392505050565b60805160a05160c051615df06200017760003960006120260152600061288f0152600081816104ba01526128b00152615df06000f3fe60806040523480156200001157600080fd5b5060043610620001955760003560e01c806382bd79ea11620000e9578063d04984611162000097578063e70b9e27116200006e578063e70b9e271462000564578063f26ebf7a1462000592578063f6de3cae14620005a957600080fd5b8063d04984611462000504578063dd56e5d8146200052c578063df42efda146200054d57600080fd5b806396da9bd511620000cc57806396da9bd5146200049d578063b44a272214620004b4578063b8883c5014620004dc57600080fd5b806382bd79ea146200047c57806384335241146200048657600080fd5b806336808b191162000147578063566d3c71116200012a578063566d3c7114620003215780635739f0b9146200035e57806360777795146200037557600080fd5b806336808b1914620002e25780633c6d071514620002f957600080fd5b806327e6a99a116200017c57806327e6a99a14620001f15780632912bf1014620002b25780632f2d783d14620002cb57600080fd5b8063046ec166146200019a5780630a53075414620001cb575b600080fd5b620001b1620001ab36600462003541565b620005c0565b604080519283526020830191909152015b60405180910390f35b620001e2620001dc36600462003587565b620008ac565b604051908152602001620001c2565b6200027062000202366004620035df565b6002602081815260009384526040808520909152918352912080546001820154918301546fffffffffffffffffffffffffffffffff8216937001000000000000000000000000000000008304810b93730100000000000000000000000000000000000000909304900b919085565b604080516fffffffffffffffffffffffffffffffff9096168652600294850b60208701529290930b918401919091526060830152608082015260a001620001c2565b620002c9620002c336600462003602565b620008d1565b005b620001e2620002dc36600462003621565b62000b4c565b620002c9620002f336600462003541565b62000b66565b620001e27f681ab0361ab5f3ae8c1d864335ef2b9a8c12a6a67e1ed0f4083d00a4b8a9a39581565b620003386200033236600462003686565b62000dae565b60405173ffffffffffffffffffffffffffffffffffffffff9091168152602001620001c2565b620002c96200036f3660046200375f565b62001181565b6200041e620003863660046200378d565b600160208190526000918252604090912080549101546fffffffffffffffffffffffffffffffff808316927001000000000000000000000000000000009004169073ffffffffffffffffffffffffffffffffffffffff81169074010000000000000000000000000000000000000000810462ffffff169077010000000000000000000000000000000000000000000000900460ff1685565b604080516fffffffffffffffffffffffffffffffff968716815295909416602086015273ffffffffffffffffffffffffffffffffffffffff9092169284019290925262ffffff90911660608301521515608082015260a001620001c2565b620001e260035481565b620002c962000497366004620037a7565b62001327565b620001b1620004ae3660046200375f565b620014c3565b620003387f000000000000000000000000000000000000000000000000000000000000000081565b620001e27fa777c10270ee0b99d2c737c09ff865ed48064b252418bbd31d39c8b88ea1221981565b6200051b62000515366004620037ed565b62001643565b6040519015158152602001620001c2565b600054620003389073ffffffffffffffffffffffffffffffffffffffff1681565b620002c96200055e36600462003820565b620016e2565b620001e26200057536600462003840565b600460209081526000928352604080842090915290825290205481565b620002c9620005a3366004620037a7565b620017a3565b620002c9620005ba366004620037a7565b620018d3565b600080620005cd62001cd1565b600080620005db8762001cf8565b60008881526002602081815260408084208685528252808420815160a08101835281546fffffffffffffffffffffffffffffffff81168083527001000000000000000000000000000000008204870b958301959095527301000000000000000000000000000000000000009004850b928101929092526001810154606083015290920154608083015293955091935090919003620006a5576040517f7aa92c6600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001820154604080517f6f4a2cd0000000000000000000000000000000000000000000000000000000008152905173ffffffffffffffffffffffffffffffffffffffff909216918291636f4a2cd091600480830192600092919082900301818387803b1580156200071557600080fd5b505af11580156200072a573d6000803e3d6000fd5b505050506000806200073d838562001dd2565b809450819550829a50839b505050505081600260008c815260200190815260200160002060008881526020019081526020016000206001018190555080600260008c81526020019081526020016000206000888152602001908152602001600020600201819055506000600460008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000209050886000146200081e578b5173ffffffffffffffffffffffffffffffffffffffff16600090815260208290526040902080548a0190555b871562000855576020808d015173ffffffffffffffffffffffffffffffffffffffff16600090815290829052604090208054890190555b604080518c8152602081018990529081018a9052606081018990527f15b2e0f32b50efdbbdee9ec7884ed3c61e6209b1b395e5762011a6734b86f7b59060800160405180910390a150505050505050935093915050565b6000620008b862001cd1565b620008c68585858562001e84565b90505b949350505050565b620008fc7fa777c10270ee0b99d2c737c09ff865ed48064b252418bbd31d39c8b88ea1221962001ff1565b6000806200090a8362001cf8565b6001810154919350915077010000000000000000000000000000000000000000000000900460ff16156200096a576040517f260e553a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600181015473ffffffffffffffffffffffffffffffffffffffff1680620009bd576040517fe4c8229200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001820180547fffffffffffffffff00ffffffffffffffffffffffffffffffffffffffffffffff1677010000000000000000000000000000000000000000000000179055604080517fa88a5c160000000000000000000000000000000000000000000000000000000081528151600092839273ffffffffffffffffffffffffffffffffffffffff86169263a88a5c16926004808401939192918290030181865afa15801562000a70573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000a96919062003880565b915091508082176fffffffffffffffffffffffffffffffff1660001462000ac65762000ac68360008088620020b6565b62000ad58660400151620021ad565b73ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff160362000b195762000b198660400151600062002221565b60405185907f907b91fb061b1c46367da11a5a0e8b2c0bd5fecd22eb92967e626cffa5ef638690600090a2505050505050565b600062000b5c8433858562001e84565b90505b9392505050565b62000b7062001cd1565b600062000be28460408051825173ffffffffffffffffffffffffffffffffffffffff90811660208084019190915284015181168284015291830151909116606080830191909152820151608082015260009060a001604051602081830303815290604052805190602001209050919050565b60008481526002602081815260408084208585528252808420815160a08101835281546fffffffffffffffffffffffffffffffff81168083527001000000000000000000000000000000008204870b958301959095527301000000000000000000000000000000000000009004850b928101929092526001810154606083015290920154608083015292935091900362000ca8576040517f7aa92c6600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60008062000ce58388868862000cd488600001516fffffffffffffffffffffffffffffffff16620022ac565b62000cdf90620038e3565b620022c3565b60008881526002602081815260408084208a8552825280842080547fffffffffffffffffffff0000000000000000000000000000000000000000000016815560018101859055909201929092558a518b830151825173ffffffffffffffffffffffffffffffffffffffff91821681528b82169481019490945291830185905260608301849052939550919350911690859088907f7f2557bb15dcf63e3d029ef1dcb4333563fcd78edf263b8fe42ed3adb925ff849060800160405180910390a450505050505050565b600062000ddb7fa777c10270ee0b99d2c737c09ff865ed48064b252418bbd31d39c8b88ea1221962001ff1565b600073ffffffffffffffffffffffffffffffffffffffff1662000e028460400151620021ad565b73ffffffffffffffffffffffffffffffffffffffff161462000e50576040517fd95c741b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b30836040015160405162000e649062003411565b73ffffffffffffffffffffffffffffffffffffffff928316815291166020820152604001604051809103906000f08015801562000ea5573d6000803e3d6000fd5b50905062000eb883604001518262002221565b6003805490600062000eca8362003924565b909155506060840152600062000f458460408051825173ffffffffffffffffffffffffffffffffffffffff90811660208084019190915284015181168284015291830151909116606080830191909152820151608082015260009060a001604051602081830303815290604052805190602001209050919050565b60008181526001602090815260409091208551918601519293509162000f6e918791846200254e565b6fffffffffffffffffffffffffffffffff90811660208701521680855260000362000fc5576040517f36ab0f6a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6080840151621b13d062ffffff90911613156200100e576040517f1db9891100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b608084015160018201805473ffffffffffffffffffffffffffffffffffffffff8087167fffffffffffffffffffffffff000000000000000000000000000000000000000062ffffff86167401000000000000000000000000000000000000000002167fffffffffffffffffff000000000000000000000000000000000000000000000090931692909217919091179091556040808801516020808a01518a5160608c01518b51938c01519551948716979287169691909116947fcef9468c62cd8a6eca3a887fc30674c037943e423de07ab3a122bdf2f73c77e19462001145948c9490929173ffffffffffffffffffffffffffffffffffffffff95909516855260208501939093526fffffffffffffffffffffffffffffffff918216604085015216606083015262ffffff16608082015260a00190565b60405180910390a4620011638385600001518660200151856200265e565b62001179838560400151866060015185620020b6565b505092915050565b6200118b62001cd1565b60008060008060006200119f87876200274c565b93985091965094509250905080600080620011bc83888862002a34565b915091506040518060a00160405280866fffffffffffffffffffffffffffffffff1681526020018860020b81526020018760020b815260200183815260200182815250600260008b815260200190815260200160002060008a815260200190815260200160002060008201518160000160006101000a8154816fffffffffffffffffffffffffffffffff02191690836fffffffffffffffffffffffffffffffff16021790555060208201518160000160106101000a81548162ffffff021916908360020b62ffffff16021790555060408201518160000160136101000a81548162ffffff021916908360020b62ffffff160217905550606082015181600101556080820151816002015590505087897f19bc21617a8d86ff19202ac9541480a99b9ae5fbd573a23f14f479af784392c4876040516200131391906fffffffffffffffffffffffffffffffff91909116815260200190565b60405180910390a350505050505050505050565b620013527fa777c10270ee0b99d2c737c09ff865ed48064b252418bbd31d39c8b88ea1221962001ff1565b6000620013c48460408051825173ffffffffffffffffffffffffffffffffffffffff90811660208084019190915284015181168284015291830151909116606080830191909152820151608082015260009060a001604051602081830303815290604052805190602001209050919050565b6000818152600160208190526040909120015490915073ffffffffffffffffffffffffffffffffffffffff81169077010000000000000000000000000000000000000000000000900460ff16806200145657508073ffffffffffffffffffffffffffffffffffffffff166200143d8660400151620021ad565b73ffffffffffffffffffffffffffffffffffffffff1614155b80156200147657506fffffffffffffffffffffffffffffffff8484171615155b15620014ae576040517f260e553a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b620014bc81858585620020b6565b5050505050565b6000806000620015388560408051825173ffffffffffffffffffffffffffffffffffffffff90811660208084019190915284015181168284015291830151909116606080830191909152820151608082015260009060a001604051602081830303815290604052805190602001209050919050565b60008581526002602081815260408084208585528252808420815160a08101835281546fffffffffffffffffffffffffffffffff81168083527001000000000000000000000000000000008204870b958301959095527301000000000000000000000000000000000000009004850b9281019290925260018101546060830152909201546080830152929350919003620015fe576040517f7aa92c6600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000828152600160208190526040909120015473ffffffffffffffffffffffffffffffffffffffff1662001633818362001dd2565b5091999098509650505050505050565b600082815260016020819052604082209081015477010000000000000000000000000000000000000000000000900460ff161562001686576000915050620016dc565b600181015473ffffffffffffffffffffffffffffffffffffffff1680620016ad85620021ad565b73ffffffffffffffffffffffffffffffffffffffff1614620016d557600092505050620016dc565b6001925050505b92915050565b6200170d7f681ab0361ab5f3ae8c1d864335ef2b9a8c12a6a67e1ed0f4083d00a4b8a9a39562001ff1565b60005473ffffffffffffffffffffffffffffffffffffffff908116908216036200173657600080fd5b600080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff8316908117825560405190917f29f9e1ebeee07596f3165f3e42cb9d4d8d22b0481e968d6c74be3dd037c15d9b91a250565b600080620017b18562001cf8565b6001810154919350915077010000000000000000000000000000000000000000000000900460ff161562001811576040517f260e553a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001810154604086015173ffffffffffffffffffffffffffffffffffffffff9091169081906200184190620021ad565b73ffffffffffffffffffffffffffffffffffffffff16146200188f576040517f260e553a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6200189d868686856200254e565b90955093506fffffffffffffffffffffffffffffffff8585171615620018cb57620018cb818686866200265e565b505050505050565b620018fe7f681ab0361ab5f3ae8c1d864335ef2b9a8c12a6a67e1ed0f4083d00a4b8a9a39562001ff1565b6000806200190c8562001cf8565b6001810154604080517f6f4a2cd0000000000000000000000000000000000000000000000000000000008152905193955091935073ffffffffffffffffffffffffffffffffffffffff16918291636f4a2cd091600480830192600092919082900301818387803b1580156200198057600080fd5b505af115801562001995573d6000803e3d6000fd5b505050506000808273ffffffffffffffffffffffffffffffffffffffff1663f0de82286040518163ffffffff1660e01b81526004016040805180830381865afa158015620019e7573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062001a0d919062003880565b91509150816fffffffffffffffffffffffffffffffff16876fffffffffffffffffffffffffffffffff16111562001a42578196505b83546fffffffffffffffffffffffffffffffff9081169088161062001a8657835462001a83906001906fffffffffffffffffffffffffffffffff166200395f565b96505b835462001aa79088906fffffffffffffffffffffffffffffffff166200395f565b84547fffffffffffffffffffffffffffffffff00000000000000000000000000000000166fffffffffffffffffffffffffffffffff918216178555818116908716111562001af3578095505b835462001b2890879070010000000000000000000000000000000090046fffffffffffffffffffffffffffffffff166200395f565b84546fffffffffffffffffffffffffffffffff9182167001000000000000000000000000000000000291161784556040517fca16ca7e00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff84169063ca16ca7e9062001bc9908a908a906004016fffffffffffffffffffffffffffffffff92831681529116602082015260400190565b600060405180830381600087803b15801562001be457600080fd5b505af115801562001bf9573d6000803e3d6000fd5b505050506fffffffffffffffffffffffffffffffff87161562001c3757875162001c3790336fffffffffffffffffffffffffffffffff8a1662002ae1565b6fffffffffffffffffffffffffffffffff86161562001c735762001c73886020015133886fffffffffffffffffffffffffffffffff1662002ae1565b604080516fffffffffffffffffffffffffffffffff808a168252881660208201529081018690527f808ecc37f6d601dde1e43c133bee66af0ff9409b53aca0eb0d4f6c65fb8956e89060600160405180910390a15050505050505050565b60005473ffffffffffffffffffffffffffffffffffffffff16331462001cf657600080fd5b565b60008062001d6b8360408051825173ffffffffffffffffffffffffffffffffffffffff90811660208084019190915284015181168284015291830151909116606080830191909152820151608082015260009060a001604051602081830303815290604052805190602001209050919050565b6000818152600160205260408120805492945092506fffffffffffffffffffffffffffffffff909116900362001dcd576040517fe4c8229200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b915091565b60008060008062001ded868660200151876040015162002a34565b6060870151919350915062001e349062001e08908462003992565b86516fffffffffffffffffffffffffffffffff1670010000000000000000000000000000000062002c58565b62001e7686608001518362001e4a919062003992565b87516fffffffffffffffffffffffffffffffff1670010000000000000000000000000000000062002c58565b909790965091945092509050565b600073ffffffffffffffffffffffffffffffffffffffff831662001ed4576040517fabd1763600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5073ffffffffffffffffffffffffffffffffffffffff80841660009081526004602090815260408083209388168352929052205481158062001f1557508082115b1562001f1f578091505b8115620008c95773ffffffffffffffffffffffffffffffffffffffff8085166000908152600460209081526040808320938916835292905220828203905562001f6a85848462002ae1565b8373ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fe6ac6a784fb43c9f6329d2f5c82f88a26a93bad4281f7780725af5f071f0aafa8560405162001fe191815260200190565b60405180910390a4949350505050565b6040517fe8ae2b69000000000000000000000000000000000000000000000000000000008152600481018290523360248201527f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff169063e8ae2b6990604401602060405180830381865afa15801562002083573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620020a99190620039b9565b620020b357600080fd5b50565b6040517f7f463bb80000000000000000000000000000000000000000000000000000000081526fffffffffffffffffffffffffffffffff80851660048301528316602482015273ffffffffffffffffffffffffffffffffffffffff851690637f463bb890604401600060405180830381600087803b1580156200213857600080fd5b505af11580156200214d573d6000803e3d6000fd5b5050604080516fffffffffffffffffffffffffffffffff8088168252861660208201529081018490527f1864e4cc903d98e44820faebd48409c410a2ad20adb3173984ba41ae2828805e925060600190505b60405180910390a150505050565b60008173ffffffffffffffffffffffffffffffffffffffff1663facb0eb16040518163ffffffff1660e01b8152600401602060405180830381865afa158015620021fb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620016dc9190620039e4565b6000546040517fd8a900b100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff848116600483015283811660248301529091169063d8a900b190604401600060405180830381600087803b1580156200229757600080fd5b505af1158015620018cb573d6000803e3d6000fd5b80600f81900b8114620022be57600080fd5b919050565b6000838152600160208190526040808320918201549087015183929173ffffffffffffffffffffffffffffffffffffffff169081906200230390620021ad565b73ffffffffffffffffffffffffffffffffffffffff161462002364576001820180547fffffffffffffffff00ffffffffffffffffffffffffffffffffffffffffffffff16770100000000000000000000000000000000000000000000001790555b600182015460009077010000000000000000000000000000000000000000000000900460ff16620023a4576200239e896040015162002d12565b62002416565b8173ffffffffffffffffffffffffffffffffffffffff16638e76c3326040518163ffffffff1660e01b8152600401602060405180830381865afa158015620023f0573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062002416919062003a17565b90508173ffffffffffffffffffffffffffffffffffffffff16636f4a2cd06040518163ffffffff1660e01b8152600401600060405180830381600087803b1580156200246157600080fd5b505af115801562002476573d6000803e3d6000fd5b5050505062002486828b62001dd2565b50919650945050600f86900b15620024b057620024b082428c602001518d604001518a8662002d93565b73ffffffffffffffffffffffffffffffffffffffff8716600090815260046020526040902085156200250957895173ffffffffffffffffffffffffffffffffffffffff1660009081526020829052604090208054870190555b841562002540576020808b015173ffffffffffffffffffffffffffffffffffffffff16600090815290829052604090208054860190555b505050509550959350505050565b6000806fffffffffffffffffffffffffffffffff8516156200257b57855162002578908662002e46565b91505b6fffffffffffffffffffffffffffffffff841615620025a757620025a486602001518562002e46565b90505b8254620025c89083906fffffffffffffffffffffffffffffffff1662003a35565b83547fffffffffffffffffffffffffffffffff00000000000000000000000000000000166fffffffffffffffffffffffffffffffff918216178085556200262691839170010000000000000000000000000000000090041662003a35565b83546fffffffffffffffffffffffffffffffff9182167001000000000000000000000000000000000291161790925594909350915050565b6040517ffddf08e50000000000000000000000000000000000000000000000000000000081526fffffffffffffffffffffffffffffffff80851660048301528316602482015273ffffffffffffffffffffffffffffffffffffffff85169063fddf08e590604401600060405180830381600087803b158015620026e057600080fd5b505af1158015620026f5573d6000803e3d6000fd5b5050604080516fffffffffffffffffffffffffffffffff8088168252861660208201529081018490527f8b0312d8047895ce795779b66b705ccd39b1ece7c162f642c72d76a785d1b68a925060600190506200219f565b600080600080600080620027608862001cf8565b600181015460008a815260026020908152604080832086845290915290205492985073ffffffffffffffffffffffffffffffffffffffff16935091506fffffffffffffffffffffffffffffffff1615620027e6576040517ff352b37500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8173ffffffffffffffffffffffffffffffffffffffff166200280c8960400151620021ad565b73ffffffffffffffffffffffffffffffffffffffff161415806200284f5750600181015477010000000000000000000000000000000000000000000000900460ff165b1562002887576040517f260e553a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000620028d67f00000000000000000000000000000000000000000000000000000000000000007f00000000000000000000000000000000000000000000000000000000000000008a6200302c565b60408d0151929950909750955090915073ffffffffffffffffffffffffffffffffffffffff80831691161462002938576040517fdce2809300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b836fffffffffffffffffffffffffffffffff1660000362002985576040517f4eed436000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600182015474010000000000000000000000000000000000000000900462ffffff16600287810b9087900b03811315620029eb576040517feab0585000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000620029f88362002d12565b905062002a2685428a8a62002a1f8b6fffffffffffffffffffffffffffffffff16620022ac565b8662002d93565b505050509295509295909350565b6040517f0bd6f200000000000000000000000000000000000000000000000000000000008152600283810b600483015282900b6024820152600090819073ffffffffffffffffffffffffffffffffffffffff861690630bd6f200906044016040805180830381865afa15801562002aaf573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062002ad5919062003a61565b91509150935093915050565b6040805173ffffffffffffffffffffffffffffffffffffffff8481166024830152604480830185905283518084039091018152606490920183526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fa9059cbb00000000000000000000000000000000000000000000000000000000179052915160009283929087169162002b7a919062003a86565b6000604051808303816000865af19150503d806000811462002bb9576040519150601f19603f3d011682016040523d82523d6000602084013e62002bbe565b606091505b509150915081801562002bec57508051158062002bec57508080602001905181019062002bec9190620039b9565b620014bc576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600260248201527f535400000000000000000000000000000000000000000000000000000000000060448201526064015b60405180910390fd5b6000838302817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8587098281108382030391505080841162002c9957600080fd5b8060000362002cae5750829004905062000b5f565b8385870960008581038616958690049560026003880281188089028203028089028203028089028203028089028203028089028203028089029091030291819003819004600101858411909403939093029190930391909104170290509392505050565b60008173ffffffffffffffffffffffffffffffffffffffff1663e76c01e46040518163ffffffff1660e01b815260040160e060405180830381865afa15801562002d60573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062002d86919062003aca565b5093979650505050505050565b6040517f0f1019bc00000000000000000000000000000000000000000000000000000000815263ffffffff86166004820152600285810b602483015284810b6044830152600f84900b606483015282900b608482015273ffffffffffffffffffffffffffffffffffffffff871690630f1019bc9060a401600060405180830381600087803b15801562002e2557600080fd5b505af115801562002e3a573d6000803e3d6000fd5b50505050505050505050565b6040517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152600090819073ffffffffffffffffffffffffffffffffffffffff8516906370a0823190602401602060405180830381865afa15801562002eb6573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062002edc919062003b68565b905062002efe843330866fffffffffffffffffffffffffffffffff1662003112565b6040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015260009073ffffffffffffffffffffffffffffffffffffffff8616906370a0823190602401602060405180830381865afa15801562002f6c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062002f92919062003b68565b905081811162002fa157600080fd5b6fffffffffffffffffffffffffffffffff82820381169081111562003023576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f696e76616c696420746f6b656e20616d6f756e74000000000000000000000000604482015260640162002c4f565b95945050505050565b6000806000806000808773ffffffffffffffffffffffffffffffffffffffff166399fbab88886040518263ffffffff1660e01b81526004016200307191815260200190565b61016060405180830381865afa15801562003090573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620030b6919062003b82565b50506040805180820190915273ffffffffffffffffffffffffffffffffffffffff808916825287166020820152949d50929b509099509397509195506200310594508d935091506200328d9050565b9550505093509350935093565b6040805173ffffffffffffffffffffffffffffffffffffffff85811660248301528481166044830152606480830185905283518084039091018152608490920183526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f23b872dd000000000000000000000000000000000000000000000000000000001790529151600092839290881691620031b3919062003a86565b6000604051808303816000865af19150503d8060008114620031f2576040519150601f19603f3d011682016040523d82523d6000602084013e620031f7565b606091505b50915091508180156200322557508051158062003225575080806020019051810190620032259190620039b9565b620018cb576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600360248201527f5354460000000000000000000000000000000000000000000000000000000000604482015260640162002c4f565b6000816020015173ffffffffffffffffffffffffffffffffffffffff16826000015173ffffffffffffffffffffffffffffffffffffffff1610620032d057600080fd5b82826000015183602001516040516020016200330f92919073ffffffffffffffffffffffffffffffffffffffff92831681529116602082015260400190565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0818403018152908290528051602091820120620033d4939290917fe72bebd8b70e089fdcb38ed7e5940e8839837b4cdd27c69ff2461ff057192b8191017fff00000000000000000000000000000000000000000000000000000000000000815260609390931b7fffffffffffffffffffffffffffffffffffffffff0000000000000000000000001660018401526015830191909152603582015260550190565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe081840301815291905280516020909101209392505050565b6121798062003c6b83390190565b60405160a0810167ffffffffffffffff811182821017156200346a577f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b60405290565b73ffffffffffffffffffffffffffffffffffffffff81168114620020b357600080fd5b600060808284031215620034a657600080fd5b6040516080810181811067ffffffffffffffff82111715620034f1577f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6040529050808235620035048162003470565b81526020830135620035168162003470565b602082015260408301356200352b8162003470565b6040820152606092830135920191909152919050565b600080600060c084860312156200355757600080fd5b62003563858562003493565b92506080840135915060a08401356200357c8162003470565b809150509250925092565b600080600080608085870312156200359e57600080fd5b8435620035ab8162003470565b93506020850135620035bd8162003470565b92506040850135620035cf8162003470565b9396929550929360600135925050565b60008060408385031215620035f357600080fd5b50508035926020909101359150565b6000608082840312156200361557600080fd5b62000b5f838362003493565b6000806000606084860312156200363757600080fd5b8335620036448162003470565b92506020840135620036568162003470565b929592945050506040919091013590565b6fffffffffffffffffffffffffffffffff81168114620020b357600080fd5b6000808284036101208112156200369c57600080fd5b620036a8858562003493565b925060a07fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8082011215620036db57600080fd5b50620036e66200341f565b6080840135620036f68162003667565b815260a0840135620037088162003667565b602082015260c08401356200371d8162003667565b604082015260e0840135620037328162003667565b606082015261010084013562ffffff811681146200374f57600080fd5b6080820152919491935090915050565b60008060a083850312156200377357600080fd5b6200377f848462003493565b946080939093013593505050565b600060208284031215620037a057600080fd5b5035919050565b600080600060c08486031215620037bd57600080fd5b620037c9858562003493565b92506080840135620037db8162003667565b915060a08401356200357c8162003667565b600080604083850312156200380157600080fd5b823591506020830135620038158162003470565b809150509250929050565b6000602082840312156200383357600080fd5b813562000b5f8162003470565b600080604083850312156200385457600080fd5b8235620038618162003470565b91506020830135620038158162003470565b8051620022be8162003667565b600080604083850312156200389457600080fd5b8251620038a18162003667565b6020840151909250620038158162003667565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600081600f0b7fffffffffffffffffffffffffffffffff8000000000000000000000000000000081036200391b576200391b620038b4565b60000392915050565b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8203620039585762003958620038b4565b5060010190565b6fffffffffffffffffffffffffffffffff8281168282160390808211156200398b576200398b620038b4565b5092915050565b81810381811115620016dc57620016dc620038b4565b80518015158114620022be57600080fd5b600060208284031215620039cc57600080fd5b62000b5f82620039a8565b8051620022be8162003470565b600060208284031215620039f757600080fd5b815162000b5f8162003470565b8051600281900b8114620022be57600080fd5b60006020828403121562003a2a57600080fd5b62000b5f8262003a04565b6fffffffffffffffffffffffffffffffff8181168382160190808211156200398b576200398b620038b4565b6000806040838503121562003a7557600080fd5b505080516020909101519092909150565b6000825160005b8181101562003aa9576020818601810151858301520162003a8d565b506000920191825250919050565b805161ffff81168114620022be57600080fd5b600080600080600080600060e0888a03121562003ae657600080fd5b875162003af38162003470565b965062003b036020890162003a04565b955062003b136040890162003a04565b945062003b236060890162003ab7565b935062003b336080890162003ab7565b925060a088015160ff8116811462003b4a57600080fd5b915062003b5a60c08901620039a8565b905092959891949750929550565b60006020828403121562003b7b57600080fd5b5051919050565b60008060008060008060008060008060006101608c8e03121562003ba557600080fd5b8b516affffffffffffffffffffff8116811462003bc157600080fd5b60208d0151909b5062003bd48162003470565b60408d0151909a5062003be78162003470565b985062003bf760608d01620039d7565b975062003c0760808d0162003a04565b965062003c1760a08d0162003a04565b955062003c2760c08d0162003873565b945060e08c015193506101008c0151925062003c476101208d0162003873565b915062003c586101408d0162003873565b90509295989b509295989b909396995056fe60c0604052600160075560016008553480156200001b57600080fd5b5060405162002179380380620021798339810160408190526200003e916200019e565b6200005560006200009b60201b62000c651760201c565b600480546001600160a01b039384166080529190921660a05263ffffffff4216600160981b0266ffffffffffffff60981b1990911617621e4ec360bb1b17905562000207565b620d89e719620000ab81620001d6565b620d89e7196000818152602085905260409020600301805465ffffffffffff1916630100000062ffffff9485160262ffffff19161793909216929092179055620000f581620001d6565b82600062000107620d89e719620001d6565b60020b60020b81526020019081526020016000206003016000846000620d89e7196200013390620001d6565b60020b81526020810191909152604001600020600301805462ffffff94851663010000000265ffffff0000001990911617905581549383166101009190910a90810292021990921617905550565b80516001600160a01b03811681146200019957600080fd5b919050565b60008060408385031215620001b257600080fd5b620001bd8362000181565b9150620001cd6020840162000181565b90509250929050565b60008160020b627fffff198103620001fe57634e487b7160e01b600052601160045260246000fd5b60000392915050565b60805160a051611f3e6200023b60003960008181610167015261086f0152600081816102450152610f6f0152611f3e6000f3fe608060405234801561001057600080fd5b506004361061011b5760003560e01c80638a2ade58116100b2578063ca16ca7e11610081578063f0de822811610066578063f0de82281461034a578063f30dba931461037c578063fddf08e51461043257600080fd5b8063ca16ca7e146102fb578063d576dfc01461030e57600080fd5b80638a2ade58146102405780638e76c33214610267578063a69252af1461029b578063a88a5c16146102a457600080fd5b806346caf2ae116100ee57806346caf2ae146101d157806363f0580b1461020e5780636f4a2cd0146102255780637f463bb81461022d57600080fd5b80630bd6f200146101205780630f1019bc1461014d57806316f0115b1461016257806334d33590146101ae575b600080fd5b61013361012e366004611c9e565b610445565b604080519283526020830191909152015b60405180910390f35b61016061015b366004611cd1565b61065e565b005b6101897f000000000000000000000000000000000000000000000000000000000000000081565b60405173ffffffffffffffffffffffffffffffffffffffff9091168152602001610144565b6101c16101bc366004611d49565b610855565b6040519015158152602001610144565b6004546101ed906fffffffffffffffffffffffffffffffff1681565b6040516fffffffffffffffffffffffffffffffff9091168152602001610144565b61021760085481565b604051908152602001610144565b610160610bc6565b61016061023b366004611da5565b610bd8565b6101897f000000000000000000000000000000000000000000000000000000000000000081565b60045461028890700100000000000000000000000000000000900460020b81565b60405160029190910b8152602001610144565b61021760075481565b6005546fffffffffffffffffffffffffffffffff808216917001000000000000000000000000000000009004165b604080516fffffffffffffffffffffffffffffffff938416815292909116602083015201610144565b610160610309366004611da5565b610c39565b60045461033590730100000000000000000000000000000000000000900463ffffffff1681565b60405163ffffffff9091168152602001610144565b6006546fffffffffffffffffffffffffffffffff808216917001000000000000000000000000000000009004166102d2565b6103e961038a366004611dcf565b6000602081905290815260409020805460018201546002808401546003909401546fffffffffffffffffffffffffffffffff841694700100000000000000000000000000000000909404600f0b939181810b9163010000009004900b86565b604080516fffffffffffffffffffffffffffffffff9097168752600f9590950b6020870152938501929092526060840152600290810b60808401520b60a082015260c001610144565b610160610440366004611da5565b610c51565b600282810b6000908152602081905260408120600301549091829163010000008104820b910b036104a2576040517f0d6e094900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600283810b60009081526020819052604090206003015463010000008104820b910b036104fb576040517f0d6e094900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60045460075460085463ffffffff7301000000000000000000000000000000000000009093048316420392831615610624576004546fffffffffffffffffffffffffffffffff1680156106225760055460065463ffffffff86166fffffffffffffffffffffffffffffffff8084168202811693700100000000000000000000000000000000908190048216909202811692818116929004168184111561059f578193505b808311156105ab578092505b83156105e4576105df84700100000000000000000000000000000000876fffffffffffffffffffffffffffffffff16610e01565b870196505b821561061d5761061883700100000000000000000000000000000000876fffffffffffffffffffffffffffffffff16610e01565b860195505b505050505b505b6004546106509060009089908990700100000000000000000000000000000000900460020b8686610eb9565b945094505050509250929050565b610666610f57565b600480547fffffffffffffffffffffffffff000000ffffffffffffffffffffffffffffffff1670010000000000000000000000000000000062ffffff8416021790819055730100000000000000000000000000000000000000900463ffffffff90811690861611156106da576106da610fc6565b81600f0b60001461084e576000806106f586848660006111bc565b156106ff57600191505b61070c85848660016111bc565b15610715575060015b8560020b8360020b1215801561073057508460020b8360020b125b1561079657600454610754906fffffffffffffffffffffffffffffffff16856111e2565b600480547fffffffffffffffffffffffffffffffff00000000000000000000000000000000166fffffffffffffffffffffffffffffffff929092169190911790555b818061079f5750805b1561084b5760045477010000000000000000000000000000000000000000000000900460020b82156107e0576107dd878583600089600f0b126112a9565b90505b81156107fb576107f8868583600089600f0b126112a9565b90505b6004805462ffffff90921677010000000000000000000000000000000000000000000000027fffffffffffff000000ffffffffffffffffffffffffffffffffffffffffffffff9092169190911790555b50505b5050505050565b60003373ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016146108c6576040517f74e2852e00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6108ce610fc6565b600454600754600854770100000000000000000000000000000000000000000000008304600290810b936fffffffffffffffffffffffffffffffff81169370010000000000000000000000000000000090910490910b918615610a4d575b600283900b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff2761814610a48578460020b8860020b1215610b1557600285810b600090815260208190526040902090810180548303905560018101805484039055546109b19085907001000000000000000000000000000000009004600f0b6000036111e2565b600286810b600090815260208190526040902060030154810b969195507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff90910193507ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff276189084900b1215610a43577ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff2761892505b61092c565b610b15565b6001610a787ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff27618611e19565b610a829190611e57565b60020b8360020b14610b1557600285810b60009081526020819052604090206003015463010000009004810b9089900b811315610abf5750610b15565b600281810b60009081526020819052604090209081018054840390556001810180548503905554610b089086907001000000000000000000000000000000009004600f0b6111e2565b9095509350849250610a4d565b50506004805462ffffff94851677010000000000000000000000000000000000000000000000027fffffffffffff000000ffffffffffffff0000000000000000000000000000000095891670010000000000000000000000000000000002959095167fffffffffffff000000ffffffff00000000000000000000000000000000000000909116176fffffffffffffffffffffffffffffffff9093169290921792909217905550600190505b92915050565b610bce610f57565b610bd6610fc6565b565b610be0610f57565b610be8610fc6565b6fffffffffffffffffffffffffffffffff9182169116700100000000000000000000000000000000027fffffffffffffffffffffffffffffffff000000000000000000000000000000001617600555565b610c41610f57565b610c4d6000838361138c565b5050565b610c59610f57565b610c4d6001838361138c565b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff27618610c8f81611e19565b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff27618600081815260208590526040902060030180547fffffffffffffffffffffffffffffffffffffffffffffffffffff00000000000016630100000062ffffff948516027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000161793909216929092179055610d2881611e19565b826000610d547ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff27618611e19565b60020b60020b815260200190815260200160002060030160008460007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff27618610d9a90611e19565b60020b81526020810191909152604001600020600301805462ffffff9485166301000000027fffffffffffffffffffffffffffffffffffffffffffffffffffff000000ffffff90911617905581549383166101009190910a90810292021990921617905550565b6000838302817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff85870982811083820303915050808411610e4157600080fd5b80600003610e5457508290049050610eb2565b8385870960008581038616958690049560026003880281188089028203028089028203028089028203028089028203028089028203028089029091030291819003819004600101858411909403939093029190930391909104170290505b9392505050565b600285810b60009081526020889052604080822087840b8084529183209293849391929088900b1215610f2f578860020b8760020b12610f0a57816001015486039350816002015485039250610f19565b81600101549350816002015492505b6001810154600282015494039390920391610f4a565b81600101548160010154039350816002015481600201540392505b5050965096945050505050565b3373ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001614610bd6576040517fae74b17800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60045463ffffffff73010000000000000000000000000000000000000090910481164203166000819003610ff75750565b6004546fffffffffffffffffffffffffffffffff168015611172576005546006546fffffffffffffffffffffffffffffffff80831685029270010000000000000000000000000000000090819004821686029280831692919004168184111561107057816fffffffffffffffffffffffffffffffff1693505b806fffffffffffffffffffffffffffffffff168311156110a057806fffffffffffffffffffffffffffffffff1692505b8383171561116d576fffffffffffffffffffffffffffffffff918216849003911682900383156110f0576110e68470010000000000000000000000000000000087610e01565b6007805490910190555b821561111c576111128370010000000000000000000000000000000087610e01565b6008805490910190555b6fffffffffffffffffffffffffffffffff808316908216700100000000000000000000000000000000027fffffffffffffffffffffffffffffffff0000000000000000000000000000000016176006555b505050505b5050600480547fffffffffffffffffff00000000ffffffffffffffffffffffffffffffffffffff167301000000000000000000000000000000000000004263ffffffff1602179055565b6007546008546000916111d791839188918891889188611472565b90505b949350505050565b60008082600f0b121561124657508082016fffffffffffffffffffffffffffffffff80841690821610611241576040517f1301f74800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610bc0565b826fffffffffffffffffffffffffffffffff168284019150816fffffffffffffffffffffffffffffffff161015610bc0576040517f997402f200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001546000908183156112d9576112c16000886115d2565b90508660020b8560020b036112d4578094505b611361565b60008760020b8660020b1280156112f657508660020b8860020b13155b15611326575050600284810b6000908152602081905260409020600301548795916301000000909104900b611352565b61133460036002858b6117e2565b600281810b600090815260208190526040902060030154900b925090505b61135f60008984846118b3565b505b6000611371600360028a86611a39565b90508281146113805760018190555b50939695505050505050565b611394610fc6565b6fffffffffffffffffffffffffffffffff828217161561146d576006546fffffffffffffffffffffffffffffffff80821691700100000000000000000000000000000000900416846113ef576113ea8483611e98565b6113f9565b6113f98483611ec8565b91508461140f5761140a8382611e98565b611419565b6114198382611ec8565b6fffffffffffffffffffffffffffffffff9283169216700100000000000000000000000000000000027fffffffffffffffffffffffffffffffff000000000000000000000000000000001691909117600655505b505050565b600286900b600090815260208890526040812080547001000000000000000000000000000000008104600f0b906fffffffffffffffffffffffffffffffff16836114bc828a6111e2565b90506d02000004000008000010000020006fffffffffffffffffffffffffffffffff82161115611518576040517f25b8364a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b856115345788600f0b83600f0b61152f9190611ef1565b611546565b88600f0b83600f0b6115469190611f11565b6fffffffffffffffffffffffffffffffff828116918116700100000000000000000000000000000000027fffffffffffffffffffffffffffffffff0000000000000000000000000000000016821786559015955082166000036115c357841594508960020b8b60020b136115c35760018401889055600284018790555b50505050979650505050505050565b600281810b6000818152602085905260408120600381018054838355600183018490559185018390557fffffffffffffffffffffffffffffffffffffffffffffffffffff00000000000082169055909281810b926301000000909204900b907ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff27618148061168b57506116827ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff27618611e19565b60020b8460020b145b1561170a57600284900b600090815260208690526040902060030180547fffffffffffffffffffffffffffffffffffffffffffffffffffff00000000000016630100000062ffffff938416027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000016179183169190911790559050610bc0565b8060020b8260020b03611749576040517f0d6e094900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600282810b600090815260208790526040808220600390810180547fffffffffffffffffffffffffffffffffffffffffffffffffffff000000ffffff16630100000062ffffff88811691909102919091179091559490930b825290200180547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000169183169190911790559050610bc0565b505092915050565b600190810190600090600883811d610d8a01901c90829061ffff83161b85161561183f576118108785611ad1565b909450909250905080156118255750506111da565b61183686610d8b840160010b611ad1565b90945090925090505b8061187c57611857858360010193508360010b611b02565b90935090508061186f5750620d89e891506111da9050565b6118798684611c5b565b92505b6118a8877ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff2768501611c5b565b979650505050505050565b600283900b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff27618148061191257506119097ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff27618611e19565b60020b8360020b145b611a33578260020b8260020b12158061193157508260020b8160020b13155b15611968576040517fe45ac17d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600283810b600090815260208690526040808220600390810180547fffffffffffffffffffffffffffffffffffffffffffffffffffff00000000000016630100000062ffffff88811682027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000908116939093178a82161790935588870b8652848620840180547fffffffffffffffffffffffffffffffffffffffffffffffffffff000000ffffff16938b16918202939093179092559486900b84529190922090910180549092161790555b50505050565b80600080611a768786600881901d600181810b60009081526020949094526040909320805460ff9093169390931b80831890935591811490151891565b915091508115611ac757610d8a01600181810b60081d80820b6000908152602089905260409020805460ff9094169290921b808418909255821591909214818118935014611ac7576001811b831892505b5050949350505050565b600881901d600181900b6000908152602084905260408120548190611af69085611b02565b93969095509293505050565b60008060ff831684811c808303611b20578160ff0385019350611c52565b7f555555555555555555555555555555555555555555555555555555555555555560008290038216908116156fffffffffffffffffffffffffffffffff82161560071b1777ffffffffffffffff0000000000000000ffffffffffffffff82161560061b177bffffffff00000000ffffffff00000000ffffffff00000000ffffffff82161560051b177dffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff82161560041b177eff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff82161560031b177f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f82161560021b177f33333333333333333333333333333333333333333333333333333333333333339091161560011b1760ff1685019350600192505b50509250929050565b600181900b600090815260208390526040902054600882901b90611c7f9082611b02565b509392505050565b8035600281900b8114611c9957600080fd5b919050565b60008060408385031215611cb157600080fd5b611cba83611c87565b9150611cc860208401611c87565b90509250929050565b600080600080600060a08688031215611ce957600080fd5b853563ffffffff81168114611cfd57600080fd5b9450611d0b60208701611c87565b9350611d1960408701611c87565b9250606086013580600f0b8114611d2f57600080fd5b9150611d3d60808701611c87565b90509295509295909350565b60008060408385031215611d5c57600080fd5b611d6583611c87565b915060208301358015158114611d7a57600080fd5b809150509250929050565b80356fffffffffffffffffffffffffffffffff81168114611c9957600080fd5b60008060408385031215611db857600080fd5b611dc183611d85565b9150611cc860208401611d85565b600060208284031215611de157600080fd5b610eb282611c87565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60008160020b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8000008103611e4e57611e4e611dea565b60000392915050565b600282810b9082900b037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8000008112627fffff82131715610bc057610bc0611dea565b6fffffffffffffffffffffffffffffffff828116828216039080821115611ec157611ec1611dea565b5092915050565b6fffffffffffffffffffffffffffffffff818116838216019080821115611ec157611ec1611dea565b80820182811260008312801582168215821617156117da576117da611dea565b8181036000831280158383131683831282161715611ec157611ec1611dea56fea164736f6c6343000811000aa164736f6c6343000811000a0000000000000000000000009752f7027e3553a65ca4da99860828c6e5edc80f0000000000000000000000005f83bc541de4ec1b631f5abd11f36c6616d60cb3

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

0000000000000000000000009752f7027e3553a65ca4da99860828c6e5edc80f0000000000000000000000005f83bc541de4ec1b631f5abd11f36c6616d60cb3

-----Decoded View---------------
Arg [0] : _deployer (address): 0x9752f7027e3553a65ca4da99860828c6e5edc80f
Arg [1] : _nonfungiblePositionManager (address): 0x5f83bc541de4ec1b631f5abd11f36c6616d60cb3

-----Encoded View---------------
2 Constructor Arguments found :
Arg [0] : 0000000000000000000000009752f7027e3553a65ca4da99860828c6e5edc80f
Arg [1] : 0000000000000000000000005f83bc541de4ec1b631f5abd11f36c6616d60cb3


Block Transaction Gas Used Reward
Age Block Fee Address BC Fee Address Voting Power Jailed Incoming
Validator ID :
0 FTM

Amount Staked
0

Amount Delegated
0

Staking Total
0

Staking Start Epoch
0

Staking Start Time
0

Proof of Importance
0

Origination Score
0

Validation Score
0

Active
0

Online
0

Downtime
0 s
Address Amount claimed Rewards Created On Epoch Created On
Block Uncle Number Difficulty Gas Used Reward
Loading
Loading
Make sure to use the "Vote Down" button for any spammy posts, and the "Vote Up" for interesting conversations.