Source Code
Overview
S Balance
0 S
More Info
ContractCreator
Latest 1 from a total of 1 transactions
Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
---|---|---|---|---|---|---|---|---|---|
Set Farming Cent... | 2939339 | 11 days ago | IN | 0 S | 0.00003705 |
Loading...
Loading
Contract Name:
AlgebraEternalFarming
Compiler Version
v0.8.20+commit.a1b79de6
Optimization Enabled:
Yes with 99999999 runs
Other Settings:
paris EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: BUSL-1.1 pragma solidity =0.8.20; import '@cryptoalgebra/integral-core/contracts/interfaces/IAlgebraPoolDeployer.sol'; import '@cryptoalgebra/integral-core/contracts/interfaces/IAlgebraPool.sol'; import '@cryptoalgebra/integral-core/contracts/interfaces/IAlgebraFactory.sol'; import '@cryptoalgebra/integral-core/contracts/interfaces/IERC20Minimal.sol'; import '@cryptoalgebra/integral-core/contracts/libraries/SafeCast.sol'; import '@cryptoalgebra/integral-core/contracts/libraries/FullMath.sol'; import '@cryptoalgebra/integral-core/contracts/libraries/Constants.sol'; import '@cryptoalgebra/integral-core/contracts/libraries/TickMath.sol'; import '@cryptoalgebra/integral-core/contracts/libraries/LowGasSafeMath.sol'; import '@cryptoalgebra/integral-periphery/contracts/libraries/TransferHelper.sol'; import '@cryptoalgebra/integral-base-plugin/contracts/interfaces/plugins/IFarmingPlugin.sol'; import '../interfaces/IAlgebraEternalFarming.sol'; import '../interfaces/IAlgebraEternalVirtualPool.sol'; import '../interfaces/IFarmingCenter.sol'; import '../libraries/IncentiveId.sol'; import '../libraries/NFTPositionInfo.sol'; import './EternalVirtualPool.sol'; /// @title Algebra Integral 1.0 eternal (v2-like) farming /// @notice Manages rewards and virtual pools 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; address pluginAddress; } /// @notice Represents the farm for nft struct Farm { uint128 liquidity; int24 tickLower; int24 tickUpper; uint256 innerRewardGrowth0; uint256 innerRewardGrowth1; } /// @inheritdoc IAlgebraEternalFarming bytes32 public constant override INCENTIVE_MAKER_ROLE = keccak256('INCENTIVE_MAKER_ROLE'); /// @inheritdoc IAlgebraEternalFarming bytes32 public constant override FARMINGS_ADMINISTRATOR_ROLE = keccak256('FARMINGS_ADMINISTRATOR_ROLE'); /// @inheritdoc IAlgebraEternalFarming INonfungiblePositionManager public immutable override nonfungiblePositionManager; IAlgebraPoolDeployer private immutable deployer; IAlgebraFactory private immutable factory; /// @inheritdoc IAlgebraEternalFarming address public override farmingCenter; /// @inheritdoc IAlgebraEternalFarming bool public override isEmergencyWithdrawActivated; // reentrancy lock bool private unlocked = true; /// @dev bytes32 incentiveId refers to the return value of IncentiveId.compute /// @inheritdoc IAlgebraEternalFarming mapping(bytes32 incentiveId => Incentive incentive) public override incentives; /// @dev farms[tokenId][incentiveHash] => Farm /// @inheritdoc IAlgebraEternalFarming mapping(uint256 tokenId => mapping(bytes32 incentiveId => Farm farm)) public override farms; /// @inheritdoc IAlgebraEternalFarming uint256 public numOfIncentives; /// @dev rewards[owner][rewardToken] => uint256 /// @inheritdoc IAlgebraEternalFarming mapping(address owner => mapping(IERC20Minimal rewardToken => uint256 rewardAmount)) 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 isIncentiveDeactivated(bytes32 incentiveId) external view override returns (bool res) { return _isIncentiveDeactivated(incentives[incentiveId]); } function _checkIsFarmingCenter() internal view { require(msg.sender == farmingCenter); } function _checkHasRole(bytes32 role) internal view { require(factory.hasRoleOrOwner(role, msg.sender)); } /// @inheritdoc IAlgebraEternalFarming function createEternalFarming( IncentiveKey memory key, IncentiveParams memory params, address plugin ) external override onlyIncentiveMaker returns (address virtualPool) { address connectedPlugin = key.pool.plugin(); if (connectedPlugin != plugin || connectedPlugin == address(0)) revert pluginNotConnected(); if (IFarmingPlugin(connectedPlugin).incentive() != address(0)) revert anotherFarmingIsActive(); virtualPool = address(new EternalVirtualPool(address(this), connectedPlugin)); IFarmingCenter(farmingCenter).connectVirtualPoolToPlugin(virtualPool, IFarmingPlugin(connectedPlugin)); 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 = virtualPool; newIncentive.minimalPositionWidth = params.minimalPositionWidth; newIncentive.pluginAddress = connectedPlugin; 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) = _getExistingIncentiveByKey(key); // if the virtual pool is deactivated automatically, it is still possible to correctly deactivate it manually if (incentive.deactivated) revert incentiveStopped(); IAlgebraEternalVirtualPool virtualPool = IAlgebraEternalVirtualPool(incentive.virtualPoolAddress); IFarmingPlugin plugin = IFarmingPlugin(incentive.pluginAddress); incentive.deactivated = true; virtualPool.deactivate(); (uint128 rewardRate0, uint128 rewardRate1) = virtualPool.rewardRates(); if (rewardRate0 | rewardRate1 != 0) _setRewardRates(virtualPool, 0, 0, incentiveId); IFarmingCenter(farmingCenter).disconnectVirtualPoolFromPlugin(address(virtualPool), plugin); emit IncentiveDeactivated(incentiveId); } /// @inheritdoc IAlgebraEternalFarming function decreaseRewardsAmount(IncentiveKey memory key, uint128 rewardAmount, uint128 bonusRewardAmount) external override onlyAdministrator { (bytes32 incentiveId, Incentive storage incentive) = _getExistingIncentiveByKey(key); IAlgebraEternalVirtualPool virtualPool = IAlgebraEternalVirtualPool(incentive.virtualPoolAddress); _distributeRewards(virtualPool); (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 != farmingCenter); farmingCenter = _farmingCenter; emit FarmingCenter(_farmingCenter); } /// @inheritdoc IAlgebraEternalFarming function setEmergencyWithdrawStatus(bool newStatus) external override onlyAdministrator { require(isEmergencyWithdrawActivated != newStatus); isEmergencyWithdrawActivated = newStatus; emit EmergencyWithdraw(newStatus); } /// @inheritdoc IAlgebraEternalFarming function addRewards(IncentiveKey memory key, uint128 rewardAmount, uint128 bonusRewardAmount) external override { (bytes32 incentiveId, Incentive storage incentive) = _getExistingIncentiveByKey(key); if (_isIncentiveDeactivated(incentive)) revert incentiveStopped(); IAlgebraEternalVirtualPool virtualPool = IAlgebraEternalVirtualPool(incentive.virtualPoolAddress); (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, Incentive storage incentive) = _getExistingIncentiveByKey(key); IAlgebraEternalVirtualPool virtualPool = IAlgebraEternalVirtualPool(incentive.virtualPoolAddress); if ((rewardRate | bonusRewardRate != 0) && (_isIncentiveDeactivated(incentive))) revert incentiveStopped(); _setRewardRates(virtualPool, rewardRate, bonusRewardRate, incentiveId); } /// @inheritdoc IAlgebraEternalFarming function enterFarming(IncentiveKey memory key, uint256 tokenId) external override onlyFarmingCenter { if (isEmergencyWithdrawActivated) revert emergencyActivated(); (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 = _getFarm(tokenId, incentiveId); uint256 reward; uint256 bonusReward; if (!isEmergencyWithdrawActivated) { (reward, 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); // pool can "detach" by itself or manually int24 tick = _isIncentiveDeactivated(incentive) ? virtualPool.globalTick() : _getTickInPoolAndCheckLock(key.pool); // update rewards, as ticks may be cleared when liquidity decreases _distributeRewards(virtualPool); (reward, bonusReward, , ) = _getNewRewardsForFarm(virtualPool, farm); // liquidityDelta will be nonzero. // If a desynchronization occurs and the current tick in the pool is incorrect from the point of view of the virtual pool, // the virtual pool will be deactivated automatically _updatePositionInVirtualPool(address(virtualPool), 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, Incentive storage incentive) = _getExistingIncentiveByKey(key); Farm memory farm = _getFarm(tokenId, incentiveId); IAlgebraEternalVirtualPool virtualPool = IAlgebraEternalVirtualPool(incentive.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) = _getExistingIncentiveByKey(key); Farm memory farm = _getFarm(tokenId, incentiveId); IAlgebraEternalVirtualPool virtualPool = IAlgebraEternalVirtualPool(incentive.virtualPoolAddress); _distributeRewards(virtualPool); uint256 innerRewardGrowth0; uint256 innerRewardGrowth1; (reward, bonusReward, innerRewardGrowth0, innerRewardGrowth1) = _getNewRewardsForFarm(virtualPool, farm); Farm storage _farm = farms[tokenId][incentiveId]; _farm.innerRewardGrowth0 = innerRewardGrowth0; _farm.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); } /// @dev Does not check if the incentive is indeed currently connected to the Algebra pool or not function _isIncentiveDeactivated(Incentive storage incentive) private view returns (bool) { address virtualPoolAddress = incentive.virtualPoolAddress; bool _deactivated = incentive.deactivated; // if incentive was deactivated directly if (!_deactivated) { _deactivated = IAlgebraEternalVirtualPool(virtualPoolAddress).deactivated(); // if incentive was deactivated automatically } return _deactivated; } 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); unchecked { (reward, bonusReward) = ( FullMath.mulDiv(innerRewardGrowth0 - farm.innerRewardGrowth0, farm.liquidity, Constants.Q128), FullMath.mulDiv(innerRewardGrowth1 - farm.innerRewardGrowth1, farm.liquidity, Constants.Q128) ); } } function _distributeRewards(IAlgebraEternalVirtualPool virtualPool) private { virtualPool.distributeRewards(); } 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 _getFarm(uint256 tokenId, bytes32 incentiveId) private view returns (Farm memory result) { result = farms[tokenId][incentiveId]; if (result.liquidity == 0) revert farmDoesNotExist(); } function _receiveRewards( IncentiveKey memory key, uint128 reward, uint128 bonusReward, Incentive storage incentive ) internal returns (uint128 receivedReward, uint128 receivedBonusReward) { if (!unlocked) revert reentrancyLock(); unlocked = false; // reentrancy lock if (reward > 0) receivedReward = _receiveToken(key.rewardToken, reward); if (bonusReward > 0) receivedBonusReward = _receiveToken(key.bonusRewardToken, bonusReward); unlocked = true; (uint128 _totalRewardBefore, uint128 _bonusRewardBefore) = (incentive.totalReward, incentive.bonusReward); incentive.totalReward = _totalRewardBefore + receivedReward; incentive.bonusReward = _bonusRewardBefore + receivedBonusReward; } function _receiveToken(IERC20Minimal token, uint128 amount) private returns (uint128) { uint256 balanceBefore = _getBalanceOf(token); TransferHelper.safeTransferFrom(address(token), msg.sender, address(this), amount); uint256 balanceAfter = _getBalanceOf(token); require(balanceAfter > balanceBefore); unchecked { uint256 received = balanceAfter - balanceBefore; if (received > type(uint128).max) revert invalidTokenAmount(); 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) = _getExistingIncentiveByKey(key); if (farms[tokenId][incentiveId].liquidity != 0) revert tokenAlreadyFarmed(); virtualPool = incentive.virtualPoolAddress; uint24 minimalAllowedTickWidth = incentive.minimalPositionWidth; if (_isIncentiveDeactivated(incentive)) revert incentiveStopped(); IAlgebraPool pool; (pool, tickLower, tickUpper, liquidity) = NFTPositionInfo.getPositionInfo(deployer, nonfungiblePositionManager, tokenId); if (pool != key.pool) revert invalidPool(); if (liquidity == 0) revert zeroLiquidity(); unchecked { if (int256(tickUpper) - int256(tickLower) < int256(uint256(minimalAllowedTickWidth))) revert positionIsTooNarrow(); } int24 tick = _getTickInPoolAndCheckLock(pool); _updatePositionInVirtualPool(virtualPool, 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(); mapping(IERC20Minimal => uint256) storage userRewards = rewards[from]; reward = userRewards[rewardToken]; if (amountRequested == 0 || amountRequested > reward) amountRequested = reward; if (amountRequested > 0) { unchecked { userRewards[rewardToken] = reward - amountRequested; } TransferHelper.safeTransfer(address(rewardToken), to, amountRequested); emit RewardClaimed(to, amountRequested, address(rewardToken), from); } } function _getExistingIncentiveByKey(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 _getTickInPoolAndCheckLock(IAlgebraPool pool) internal view returns (int24 tick) { bool poolUnlocked; (, tick, , , , poolUnlocked) = pool.globalState(); if (!poolUnlocked) revert poolReentrancyLock(); } function _getBalanceOf(IERC20Minimal token) internal view returns (uint256) { return token.balanceOf(address(this)); } function _updatePositionInVirtualPool(address virtualPool, int24 tickLower, int24 tickUpper, int128 liquidityDelta, int24 currentTick) internal { IAlgebraEternalVirtualPool(virtualPool).applyLiquidityDeltaToPosition(tickLower, tickUpper, liquidityDelta, currentTick); } }
// 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 Swap direction function crossTo(int24 targetTick, bool zeroToOne) external returns (bool success); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title The interface for the Algebra farming plugin /// @dev This contract used for virtual pools in farms interface IFarmingPlugin { /// @notice Emitted when new activeIncentive is set /// @param newIncentive The address of the new incentive event Incentive(address newIncentive); /// @notice Returns the address of the pool the plugin is created for /// @return address of the pool function pool() external view returns (address); /// @notice Connects or disconnects an incentive. /// @dev Only farming can connect incentives. /// The one who connected it and the current farming has the right to disconnect the incentive. /// @param newIncentive The address associated with the incentive or zero address function setIncentive(address newIncentive) external; /// @notice Checks if the incentive is connected to pool /// @dev Returns false if the plugin has a different incentive set, the plugin is not connected to the pool, /// or the plugin configuration is incorrect. /// @param targetIncentive The address of the incentive to be checked /// @return Indicates whether the target incentive is active function isIncentiveConnected(address targetIncentive) external view returns (bool); /// @notice Returns the address of active incentive /// @dev if there is no active incentive at the moment, incentiveAddress would be equal to address(0) /// @return The address associated with the current active incentive function incentive() external view returns (address); }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity =0.8.20; /// @title Abstract contract with modified blockTimestamp functionality /// @notice Allows the pool and other contracts to get a timestamp truncated to 32 bits /// @dev Can be overridden in tests to make testing easier abstract contract Timestamp { /// @dev This function is created for testing by overriding it. /// @return A timestamp converted to uint32 function _blockTimestamp() internal view virtual returns (uint32) { return uint32(block.timestamp); // truncation is desired } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; pragma abicoder v2; import './plugin/IAlgebraPluginFactory.sol'; import './vault/IAlgebraVaultFactory.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 default community fee is changed /// @param newDefaultCommunityFee The new default community fee value event DefaultCommunityFee(uint16 newDefaultCommunityFee); /// @notice Emitted when the default tickspacing is changed /// @param newDefaultTickspacing The new default tickspacing value event DefaultTickspacing(int24 newDefaultTickspacing); /// @notice Emitted when the default fee is changed /// @param newDefaultFee The new default fee value event DefaultFee(uint16 newDefaultFee); /// @notice Emitted when the defaultPluginFactory address is changed /// @param defaultPluginFactoryAddress The new defaultPluginFactory address event DefaultPluginFactory(address defaultPluginFactoryAddress); /// @notice Emitted when the vaultFactory address is changed /// @param newVaultFactory The new vaultFactory address event VaultFactory(address newVaultFactory); /// @notice role that can change communityFee and tickspacing in pools /// @return The hash corresponding to this role function POOLS_ADMINISTRATOR_ROLE() external view returns (bytes32); /// @notice Returns `true` if `account` has been granted `role` or `account` is owner. /// @param role The hash corresponding to the role /// @param account The address for which the role is checked /// @return bool Whether the address has this role or the owner role or not 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); /// @notice Returns the default community fee /// @return Fee which will be set at the creation of the pool function defaultCommunityFee() external view returns (uint16); /// @notice Returns the default fee /// @return Fee which will be set at the creation of the pool function defaultFee() external view returns (uint16); /// @notice Returns the default tickspacing /// @return Tickspacing which will be set at the creation of the pool function defaultTickspacing() external view returns (int24); /// @notice Return the current pluginFactory address /// @dev This contract is used to automatically set a plugin address in new liquidity pools /// @return Algebra plugin factory function defaultPluginFactory() external view returns (IAlgebraPluginFactory); /// @notice Return the current vaultFactory address /// @dev This contract is used to automatically set a vault address in new liquidity pools /// @return Algebra vault factory function vaultFactory() external view returns (IAlgebraVaultFactory); /// @notice Returns the default communityFee, tickspacing, fee and communityFeeVault for pool /// @param pool the address of liquidity pool /// @return communityFee which will be set at the creation of the pool /// @return tickSpacing which will be set at the creation of the pool /// @return fee which will be set at the creation of the pool /// @return communityFeeVault the address of communityFeeVault function defaultConfigurationForPool( address pool ) external view returns (uint16 communityFee, int24 tickSpacing, uint16 fee, address communityFeeVault); /// @notice Deterministically computes the pool address given the token0 and token1 /// @dev The method does not check if such a pool has been created /// @param token0 first token /// @param token1 second token /// @return pool The contract address of the Algebra pool function computePoolAddress(address token0, address token1) external view returns (address pool); /// @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); /// @notice returns keccak256 of AlgebraPool init bytecode. /// @dev the hash value changes with any change in the pool bytecode /// @return Keccak256 hash of AlgebraPool contract init bytecode function POOL_INIT_CODE_HASH() external view returns (bytes32); /// @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 default community fee for new pools /// @param newDefaultCommunityFee The new community fee, _must_ be <= MAX_COMMUNITY_FEE function setDefaultCommunityFee(uint16 newDefaultCommunityFee) external; /// @dev updates default fee for new pools /// @param newDefaultFee The new fee, _must_ be <= MAX_DEFAULT_FEE function setDefaultFee(uint16 newDefaultFee) external; /// @dev updates default tickspacing for new pools /// @param newDefaultTickspacing The new tickspacing, _must_ be <= MAX_TICK_SPACING and >= MIN_TICK_SPACING function setDefaultTickspacing(int24 newDefaultTickspacing) external; /// @dev updates pluginFactory address /// @param newDefaultPluginFactory address of new plugin factory function setDefaultPluginFactory(address newDefaultPluginFactory) external; /// @dev updates vaultFactory address /// @param newVaultFactory address of new vault factory function setVaultFactory(address newVaultFactory) 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; }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.8.4; import './pool/IAlgebraPoolImmutables.sol'; import './pool/IAlgebraPoolState.sol'; import './pool/IAlgebraPoolActions.sol'; import './pool/IAlgebraPoolPermissionedActions.sol'; import './pool/IAlgebraPoolEvents.sol'; import './pool/IAlgebraPoolErrors.sol'; /// @title The interface for a Algebra Pool /// @dev The pool interface is broken up into many smaller pieces. /// This interface includes custom error definitions and cannot be used in older versions of Solidity. /// For older versions of Solidity use #IAlgebraPoolLegacy /// 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, IAlgebraPoolActions, IAlgebraPoolPermissionedActions, IAlgebraPoolEvents, IAlgebraPoolErrors { // used only for combining interfaces }
// 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 plugin The pool associated plugin (if any) /// @return factory The Algebra Factory 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 plugin, address factory, address token0, address token1); /// @dev Deploys a pool with the given parameters by transiently setting the parameters in cache. /// @param plugin The pool associated plugin (if any) /// @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 plugin, address token0, address token1) external returns (address pool); }
// 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); }
// 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 plugins /// @dev Such a factory is needed if the plugin should be automatically created and connected to each new pool interface IAlgebraPluginFactory { /// @notice Deploys new plugin contract for pool /// @param pool The address of the pool for which the new plugin will be created /// @param token0 First token of the pool /// @param token1 Second token of the pool /// @return New plugin address function createPlugin(address pool, address token0, address token1) external returns (address); }
// 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 initialPrice The initial sqrt price of the pool as a Q64.96 function initialize(uint160 initialPrice) external; /// @notice Adds liquidity for the given recipient/bottomTick/topTick position /// @dev The caller of this method receives a callback in the form of IAlgebraMintCallback#algebraMintCallback /// in which they must pay any token0 or token1 owed for the liquidity. The amount of token0/token1 due depends /// on bottomTick, topTick, the amount of liquidity, and the current price. /// @param leftoversRecipient 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 liquidityDesired 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 leftoversRecipient, address recipient, int24 bottomTick, int24 topTick, uint128 liquidityDesired, 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 /// @param data Any data that should be passed through to the plugin /// @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, bytes calldata data) 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 with prepayment /// @dev The caller of this method receives a callback in the form of IAlgebraSwapCallback#algebraSwapCallback /// caller must send tokens in callback before swap calculation /// the actually sent amount of tokens is used for further calculations /// @param leftoversRecipient The address which will receive potential surplus of paid tokens /// @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 amountToSell The amount of the swap, only positive (exact input) amount allowed /// @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 swapWithPaymentInAdvance( address leftoversRecipient, address recipient, bool zeroToOne, int256 amountToSell, 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; }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.8.4; /// @title Errors emitted by a pool /// @notice Contains custom errors emitted by the pool /// @dev Custom errors are separated from the common pool interface for compatibility with older versions of Solidity 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 an attempt is made to mint or swap in uninitialized pool error notInitialized(); /// @notice Emitted if 0 is passed as amountRequired to swap function error zeroAmountRequired(); /// @notice Emitted if invalid amount is passed as amountRequired to swap function error invalidAmountRequired(); /// @notice Emitted if the pool received fewer tokens than it should have error insufficientInputAmount(); /// @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 tokens0 after flash than it should have error flashInsufficientPaid0(); /// @notice Emitted if the pool received fewer tokens1 after flash than it should have 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 new tick spacing exceeds max allowed value error invalidNewTickSpacing(); /// @notice Emitted if new community fee exceeds max allowed value error invalidNewCommunityFee(); /// @notice Emitted if an attempt is made to manually change the fee value, but dynamic fee is enabled error dynamicFeeActive(); /// @notice Emitted if an attempt is made by plugin to change the fee value, but dynamic fee is disabled error dynamicFeeDisabled(); /// @notice Emitted if an attempt is made to change the plugin configuration, but the plugin is not connected error pluginIsNotConnected(); /// @notice Emitted if a plugin returns invalid selector after hook call /// @param expectedSelector The expected selector error invalidHookResponse(bytes4 expectedSelector); // #### LiquidityMath errors #### /// @notice Emitted if liquidity underflows error liquiditySub(); /// @notice Emitted if liquidity overflows error liquidityAdd(); // #### TickManagement errors #### /// @notice Emitted if the topTick param not greater then the bottomTick param error topTickLowerOrEqBottomTick(); /// @notice Emitted if the bottomTick param is lower than min allowed value error bottomTickLowerThanMIN(); /// @notice Emitted if the topTick param is greater than max allowed value error topTickAboveMAX(); /// @notice Emitted if the liquidity value associated with the tick exceeds MAX_LIQUIDITY_PER_TICK error liquidityOverflow(); /// @notice Emitted if an attempt is made to interact with an uninitialized tick error tickIsNotInitialized(); /// @notice Emitted if there is an attempt to insert a new tick into the list of ticks with incorrect indexes of the previous and next ticks error tickInvalidLinks(); // #### SafeTransfer errors #### /// @notice Emitted if token transfer failed internally error transferFailed(); // #### TickMath errors #### /// @notice Emitted if tick is greater than the maximum or less than the minimum allowed value error tickOutOfRange(); /// @notice Emitted if price is greater than the maximum or less than the minimum allowed value error priceOutOfRange(); }
// 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/Swaps cannot be emitted by the pool before Initialize /// @param price The initial sqrt price of the pool, as a Q64.96 /// @param tick The initial tick of the pool, i.e. log base 1.0001 of the starting price of the pool event Initialize(uint160 price, int24 tick); /// @notice Emitted when liquidity is minted for a given position /// @param sender The address that minted the liquidity /// @param owner The owner of the position and recipient of any minted liquidity /// @param bottomTick The lower tick of the position /// @param topTick The upper tick of the position /// @param liquidityAmount The amount of liquidity minted to the position range /// @param amount0 How much token0 was required for the minted liquidity /// @param amount1 How much token1 was required for the minted liquidity event Mint( address sender, address indexed owner, int24 indexed bottomTick, int24 indexed topTick, uint128 liquidityAmount, uint256 amount0, uint256 amount1 ); /// @notice Emitted when fees are collected by the owner of a position /// @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(uint16 communityFeeNew); /// @notice Emitted when the tick spacing changes /// @param newTickSpacing The updated value of the new tick spacing event TickSpacing(int24 newTickSpacing); /// @notice Emitted when the plugin address changes /// @param newPluginAddress New plugin address event Plugin(address newPluginAddress); /// @notice Emitted when the plugin config changes /// @param newPluginConfig New plugin config event PluginConfig(uint8 newPluginConfig); /// @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); event CommunityVault(address newCommunityVault); }
// 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 Algebra factory contract, 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 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); }
// 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. Only factory owner or POOLS_ADMINISTRATOR_ROLE role /// @param newCommunityFee The new community fee percent in thousandths (1e-3) function setCommunityFee(uint16 newCommunityFee) external; /// @notice Set the new tick spacing values. Only factory owner or POOLS_ADMINISTRATOR_ROLE role /// @param newTickSpacing The new tick spacing value function setTickSpacing(int24 newTickSpacing) external; /// @notice Set the new plugin address. Only factory owner or POOLS_ADMINISTRATOR_ROLE role /// @param newPluginAddress The new plugin address function setPlugin(address newPluginAddress) external; /// @notice Set new plugin config. Only factory owner or POOLS_ADMINISTRATOR_ROLE role /// @param newConfig In the new configuration of the plugin, /// each bit of which is responsible for a particular hook. function setPluginConfig(uint8 newConfig) external; /// @notice Set new community fee vault address. Only factory owner or POOLS_ADMINISTRATOR_ROLE role /// @dev Community fee vault receives collected community fees. /// **accumulated but not yet sent to the vault community fees once will be sent to the `newCommunityVault` address** /// @param newCommunityVault The address of new community fee vault function setCommunityVault(address newCommunityVault) external; /// @notice Set new pool fee. Can be called by owner if dynamic fee is disabled. /// Called by the plugin if dynamic fee is enabled /// @param newFee The new fee value function setFee(uint16 newFee) external; }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Pool state that can change /// @dev Important security note: when using this data by external contracts, it is necessary to take into account the possibility /// of manipulation (including read-only reentrancy). /// This interface is based on the UniswapV3 interface, credit to Uniswap Labs under GPL-2.0-or-later license: /// https://github.com/Uniswap/v3-core/tree/main/contracts/interfaces interface IAlgebraPoolState { /// @notice Safely get most important state values of Algebra Integral AMM /// @dev Several values exposed as a single method to save gas when accessed externally. /// **Important security note: this method checks reentrancy lock and should be preferred in most cases**. /// @return sqrtPrice The current price of the pool as a sqrt(dToken1/dToken0) Q64.96 value /// @return tick The current global tick of the pool. May not always be equal to SqrtTickMath.getTickAtSqrtRatio(price) if the price is on a tick boundary /// @return lastFee The current (last known) pool fee value in hundredths of a bip, i.e. 1e-6 (so '100' is '0.01%'). May be obsolete if using dynamic fee plugin /// @return pluginConfig The current plugin config as bitmap. Each bit is responsible for enabling/disabling the hooks, the last bit turns on/off dynamic fees logic /// @return activeLiquidity The currently in-range liquidity available to the pool /// @return nextTick The next initialized tick after current global tick /// @return previousTick The previous initialized tick before (or at) current global tick function safelyGetStateOfAMM() external view returns (uint160 sqrtPrice, int24 tick, uint16 lastFee, uint8 pluginConfig, uint128 activeLiquidity, int24 nextTick, int24 previousTick); /// @notice Allows to easily get current reentrancy lock status /// @dev can be used to prevent read-only reentrancy. /// This method just returns `globalState.unlocked` value /// @return unlocked Reentrancy lock flag, true if the pool currently is unlocked, otherwise - false function isUnlocked() external view returns (bool unlocked); // ! IMPORTANT security note: the pool state can be manipulated. // ! The following methods do not check reentrancy lock themselves. /// @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. /// @dev **important security note: caller should check `unlocked` flag to prevent read-only reentrancy** /// @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 lastFee The current (last known) pool fee value in hundredths of a bip, i.e. 1e-6 (so '100' is '0.01%'). May be obsolete if using dynamic fee plugin /// @return pluginConfig The current plugin config as bitmap. Each bit is responsible for enabling/disabling the hooks, the last bit turns on/off dynamic fees logic /// @return communityFee The community fee represented as a percent of all collected fee in thousandths, i.e. 1e-3 (so 100 is 10%) /// @return unlocked Reentrancy lock flag, true if the pool currently is unlocked, otherwise - false function globalState() external view returns (uint160 price, int24 tick, uint16 lastFee, uint8 pluginConfig, uint16 communityFee, bool unlocked); /// @notice Look up information about a specific tick in the pool /// @dev **important security note: caller should check reentrancy lock to prevent read-only reentrancy** /// @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 prevTick The previous tick in tick list /// @return nextTick The next tick in tick list /// @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 /// 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 ( uint256 liquidityTotal, int128 liquidityDelta, int24 prevTick, int24 nextTick, uint256 outerFeeGrowth0Token, uint256 outerFeeGrowth1Token ); /// @notice The timestamp of the last sending of tokens to community vault /// @return The timestamp truncated to 32 bits 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 /// @return communityFeePending0 The amount of token0 that will be sent to the vault /// @return communityFeePending1 The amount of token1 that will be sent to the vault function getCommunityFeePending() external view returns (uint128 communityFeePending0, uint128 communityFeePending1); /// @notice Returns the address of currently used plugin /// @dev The plugin is subject to change /// @return pluginAddress The address of currently used plugin function plugin() external view returns (address pluginAddress); /// @notice The contract to which community fees are transferred /// @return communityVaultAddress The communityVault address function communityVault() external view returns (address communityVaultAddress); /// @notice Returns 256 packed tick initialized boolean values. See TickTree for more information /// @param wordPosition Index of 256-bits word with ticks /// @return The 256-bits word with packed ticks info function tickTable(int16 wordPosition) external view returns (uint256); /// @notice The fee growth as a Q128.128 fees of token0 collected per unit of liquidity for the entire life of the pool /// @dev This value can overflow the uint256 /// @return The fee growth accumulator for token0 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 /// @return The fee growth accumulator for token1 function totalFeeGrowth1Token() external view returns (uint256); /// @notice The current pool fee value /// @dev In case dynamic fee is enabled in the pool, this method will call the plugin to get the current fee. /// If the plugin implements complex fee logic, this method may return an incorrect value or revert. /// In this case, see the plugin implementation and related documentation. /// @dev **important security note: caller should check reentrancy lock to prevent read-only reentrancy** /// @return currentFee The current pool fee value in hundredths of a bip, i.e. 1e-6 function fee() external view returns (uint16 currentFee); /// @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. /// @return reserve0 The last known reserve of token0 /// @return reserve1 The last known reserve of token1 function getReserves() external view returns (uint128 reserve0, uint128 reserve1); /// @notice Returns the information about a position by the position's key /// @dev **important security note: caller should check reentrancy lock to prevent read-only reentrancy** /// @param key The position's key is a packed concatenation of the owner address, bottomTick and topTick indexes /// @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 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 /// @dev **important security note: caller should check reentrancy lock to prevent read-only reentrancy** /// @return The current in range liquidity function liquidity() external view returns (uint128); /// @notice The current tick spacing /// @dev Ticks can only be initialized by new mints 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, ... /// However, tickspacing can be changed after the ticks have been initialized. /// 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 previous initialized tick before (or at) current global tick /// @dev **important security note: caller should check reentrancy lock to prevent read-only reentrancy** /// @return The previous initialized tick function prevTickGlobal() external view returns (int24); /// @notice The next initialized tick after current global tick /// @dev **important security note: caller should check reentrancy lock to prevent read-only reentrancy** /// @return The next initialized tick function nextTickGlobal() external view returns (int24); /// @notice The root of tick search tree /// @dev Each bit corresponds to one node in the second layer of tick tree: '1' if node has at least one active bit. /// **important security note: caller should check reentrancy lock to prevent read-only reentrancy** /// @return The root of tick search tree as bitmap function tickTreeRoot() external view returns (uint32); /// @notice The second layer of tick search tree /// @dev Each bit in node corresponds to one node in the leafs layer (`tickTable`) of tick tree: '1' if leaf has at least one active bit. /// **important security note: caller should check reentrancy lock to prevent read-only reentrancy** /// @return The node of tick search tree second layer function tickTreeSecondLayer(int16) external view returns (uint256); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title The interface for the Algebra Vault Factory /// @notice This contract can be used for automatic vaults creation /// @dev Version: Algebra Integral interface IAlgebraVaultFactory { /// @notice returns address of the community fee vault for the pool /// @param pool the address of Algebra Integral pool /// @return communityFeeVault the address of community fee vault function getVaultForPool(address pool) external view returns (address communityFeeVault); /// @notice creates the community fee vault for the pool if needed /// @param pool the address of Algebra Integral pool /// @return communityFeeVault the address of community fee vault function createVaultForPool(address pool) external returns (address communityFeeVault); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0 <0.9.0; /// @title Contains common constants for Algebra contracts /// @dev Constants moved to the library, not the base contract, to further emphasize their constant nature library Constants { uint8 internal constant RESOLUTION = 96; uint256 internal constant Q96 = 1 << 96; uint256 internal constant Q128 = 1 << 128; uint24 internal constant FEE_DENOMINATOR = 1e6; uint16 internal constant FLASH_FEE = 0.01e4; // fee for flash loan in hundredths of a bip (0.01%) uint16 internal constant INIT_DEFAULT_FEE = 0.05e4; // init default fee value in hundredths of a bip (0.05%) uint16 internal constant MAX_DEFAULT_FEE = 5e4; // max default fee value in hundredths of a bip (5%) int24 internal constant INIT_DEFAULT_TICK_SPACING = 60; int24 internal constant MAX_TICK_SPACING = 500; int24 internal constant MIN_TICK_SPACING = 1; // 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 = 191757638537527648490752896198553; uint16 internal constant MAX_COMMUNITY_FEE = 1e3; // 100% uint256 internal constant COMMUNITY_FEE_DENOMINATOR = 1e3; // role that can change settings in pools bytes32 internal constant POOLS_ADMINISTRATOR_ROLE = keccak256('POOLS_ADMINISTRATOR'); }
// 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)) } } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.8.4 <0.9.0; import '../interfaces/pool/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)); } } }
// 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); } } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0 <0.9.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 uint128 to a int128, revert on overflow /// @param y The uint128 to be downcasted /// @return z The downcasted integer, now type int128 function toInt128(uint128 y) internal pure returns (int128 z) { require((z = int128(y)) >= 0); } /// @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); } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity =0.8.20; import '../interfaces/pool/IAlgebraPoolErrors.sol'; import './TickMath.sol'; import './LiquidityMath.sol'; import './Constants.sol'; /// @title Library for managing and interacting with ticks /// @notice Contains functions for managing tick processes and relevant calculations /// @dev Ticks are organized as a doubly linked list library TickManagement { // info stored for each initialized individual tick struct Tick { uint256 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), int24 prevTick; int24 nextTick; // 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; } function checkTickRangeValidity(int24 bottomTick, int24 topTick) internal pure { if (topTick > TickMath.MAX_TICK) revert IAlgebraPoolErrors.topTickAboveMAX(); if (topTick <= bottomTick) revert IAlgebraPoolErrors.topTickLowerOrEqBottomTick(); if (bottomTick < TickMath.MIN_TICK) revert IAlgebraPoolErrors.bottomTickLowerThanMIN(); } /// @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]; uint256 liquidityTotalBefore = data.liquidityTotal; uint256 liquidityTotalAfter = LiquidityMath.addDelta(uint128(liquidityTotalBefore), liquidityDelta); if (liquidityTotalAfter > Constants.MAX_LIQUIDITY_PER_TICK) revert IAlgebraPoolErrors.liquidityOverflow(); int128 liquidityDeltaBefore = data.liquidityDelta; // 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, data.outerFeeGrowth1Token) = (totalFeeGrowth0Token, 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 feeGrowth0 The all-time global fee growth, per unit of liquidity, in token0 /// @param feeGrowth1 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) /// @return prevTick The previous active tick before _tick_ /// @return nextTick The next active tick after _tick_ function cross( mapping(int24 => Tick) storage self, int24 tick, uint256 feeGrowth0, uint256 feeGrowth1 ) internal returns (int128 liquidityDelta, int24 prevTick, int24 nextTick) { Tick storage data = self[tick]; unchecked { (data.outerFeeGrowth1Token, data.outerFeeGrowth0Token) = (feeGrowth1 - data.outerFeeGrowth1Token, feeGrowth0 - data.outerFeeGrowth0Token); } return (data.liquidityDelta, data.prevTick, data.nextTick); } /// @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 the linked list /// @param self The mapping containing all tick information for initialized ticks /// @param tick The tick that will be removed /// @return prevTick The previous active tick before _tick_ /// @return nextTick The next active tick after _tick_ function removeTick(mapping(int24 => Tick) storage self, int24 tick) internal returns (int24 prevTick, int24 nextTick) { (prevTick, 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); } else { if (prevTick == nextTick) revert IAlgebraPoolErrors.tickIsNotInitialized(); self[prevTick].nextTick = nextTick; self[nextTick].prevTick = prevTick; } return (prevTick, nextTick); } /// @notice Adds tick to the 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 before _tick_ /// @param nextTick The next active tick after _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; } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.8.4 <0.9.0; import '../interfaces/pool/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 absTickMask = tick >> (24 - 1); uint256 absTick = uint24((tick + absTickMask) ^ absTickMask); if (absTick > uint24(MAX_TICK)) revert IAlgebraPoolErrors.tickOutOfRange(); uint256 ratio = 0x100000000000000000000000000000000; if (absTick & 0x1 != 0) ratio = 0xfffcb933bd6fad37aa2d162d1a594001; 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) { if (absTick & 0x40000 != 0) ratio = (ratio * 0x2216e584f5fa1ea926041bedfe98) >> 128; if (absTick & 0x80000 != 0) ratio = (ratio * 0x48a170391f7dc42444e8fa2) >> 128; } if (tick > 0) { assembly { ratio := div(not(0), 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; 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; } } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity =0.8.20; 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(-MIN_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 treeRoot The word with info about active subtrees /// @param tick The tick to toggle function toggleTick( mapping(int16 => uint256) storage leafs, mapping(int16 => uint256) storage secondLayer, uint32 treeRoot, int24 tick ) internal returns (uint32 newTreeRoot) { newTreeRoot = treeRoot; (bool toggledNode, int16 nodeIndex) = _toggleBitInNode(leafs, tick); // toggle in leaf if (toggledNode) { unchecked { (toggledNode, nodeIndex) = _toggleBitInNode(secondLayer, nodeIndex + SECOND_LAYER_OFFSET); } if (toggledNode) { assembly { newTreeRoot := xor(newTreeRoot, shl(nodeIndex, 1)) } } } } /// @notice Toggles a bit in a tree layer by its index /// @param treeLevel The level of tree /// @param bitIndex The end-to-end index of a bit in a layer of tree /// @return toggledNode Toggled whole node or not /// @return nodeIndex Number of corresponding node function _toggleBitInNode(mapping(int16 => uint256) storage treeLevel, int24 bitIndex) private returns (bool toggledNode, int16 nodeIndex) { assembly { nodeIndex := sar(8, bitIndex) } uint256 node = treeLevel[nodeIndex]; assembly { toggledNode := iszero(node) node := xor(node, shl(and(bitIndex, 0xFF), 1)) toggledNode := xor(toggledNode, iszero(node)) } treeLevel[nodeIndex] = 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, uint32 treeRoot, int24 tick ) internal view returns (int24 nextTick) { unchecked { tick++; // start searching from the next tick int16 nodeIndex; assembly { // index in treeRoot nodeIndex := shr(8, add(sar(8, tick), SECOND_LAYER_OFFSET)) } bool initialized; // if subtree has active ticks if (treeRoot & (1 << uint16(nodeIndex)) != 0) { // try to find initialized tick in the corresponding leaf of the tree (nodeIndex, nextTick, initialized) = _nextActiveBitInSameNode(leafs, tick); if (initialized) return nextTick; // try to find next initialized leaf in the tree (nodeIndex, nextTick, initialized) = _nextActiveBitInSameNode(secondLayer, nodeIndex + SECOND_LAYER_OFFSET + 1); } if (!initialized) { // try to find which subtree has an active leaf // nodeIndex is now the index of the second level node (nextTick, initialized) = _nextActiveBitInWord(treeRoot, ++nodeIndex); if (!initialized) return TickMath.MAX_TICK; nextTick = _firstActiveBitInNode(secondLayer, nextTick); // we found a second level node that has a leaf with an active tick } nextTick = _firstActiveBitInNode(leafs, nextTick - SECOND_LAYER_OFFSET); } } /// @notice Returns the index of the next active bit in the same tree node /// @param treeLevel The level of search tree /// @param bitIndex The starting bit index /// @return nodeIndex The index of corresponding node /// @return nextBitIndex The index of next active bit or last bit in node /// @return initialized Is nextBitIndex initialized or not function _nextActiveBitInSameNode( mapping(int16 => uint256) storage treeLevel, int24 bitIndex ) internal view returns (int16 nodeIndex, int24 nextBitIndex, bool initialized) { assembly { nodeIndex := sar(8, bitIndex) } (nextBitIndex, initialized) = _nextActiveBitInWord(treeLevel[nodeIndex], bitIndex); } /// @notice Returns first active bit in given node /// @param treeLevel The level of search tree /// @param nodeIndex The index of corresponding node in the level of tree /// @return bitIndex Number of next active bit or last bit in node function _firstActiveBitInNode(mapping(int16 => uint256) storage treeLevel, int24 nodeIndex) internal view returns (int24 bitIndex) { assembly { bitIndex := shl(8, nodeIndex) } (bitIndex, ) = _nextActiveBitInWord(treeLevel[int16(nodeIndex)], bitIndex); } /// @notice Returns the next initialized bit contained in the word that is to the right or at (gte) of the given bit /// @param word The word in which to compute the next initialized bit /// @param bitIndex The end-to-end index of a bit in a layer of tree /// @return nextBitIndex The next initialized or uninitialized bit up to 256 bits away from the current bit /// @return initialized Whether the next bit is initialized, as the function only searches within up to 256 bits function _nextActiveBitInWord(uint256 word, int24 bitIndex) internal pure returns (int24 nextBitIndex, bool initialized) { uint256 bitIndexInWord; assembly { bitIndexInWord := and(bitIndex, 0xFF) } unchecked { uint256 _row = word >> bitIndexInWord; // all the 1s at or to the left of the bitIndexInWord if (_row == 0) { nextBitIndex = bitIndex | 255; } else { nextBitIndex = bitIndex + 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)))) } } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity =0.8.20; 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(); } } }
// 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; }
// 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); }
// 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'; /// @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 liquidityDesired 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 liquidityDesired, 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 withdrawalFeeliquidity Withdrawal fee liq /// @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, uint128 withdrawalFeeliquidity, uint256 amount0, uint256 amount1 ); /// @notice Emitted when a fee vault is set for a pool /// @param pool The address of the pool to which the vault have been applied /// @param feeVault The address of the fee vault /// @param fee Percentage of withdrawal fee that will be sent to the vault event FeeVaultForPool(address pool, address feeVault, uint16 fee); /// @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 Emitted after farming center address change /// @param farmingCenterAddress The new address of connected farming center event FarmingCenter(address farmingCenterAddress); /// @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. /// @dev If native token is used as input, this function should be accompanied by a `refundNativeToken` in multicall to avoid potential loss of native tokens /// @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 liquidity delta amount as a result of the increase /// @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 /// @dev If native token is used as input, this function should be accompanied by a `refundNativeToken` in multicall to avoid potential loss of native tokens /// @return liquidity The liquidity delta 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 /// @param farmingAddress The address of farming: used to prevent tx frontrun function approveForFarming(uint256 tokenId, bool approve, address farmingAddress) external payable; /// @notice Changes farming status of token to 'farmed' or 'not farmed' /// @dev can be called only by farmingCenter /// @param tokenId The ID of the token /// @param toActive The new status function switchFarmingStatus(uint256 tokenId, bool toActive) external; struct FeesVault { address feeVault; uint16 fee; } struct WithdrawalFeePoolParams { uint64 apr0; uint64 apr1; uint16 withdrawalFee; FeesVault[] feeVaults; } /// @notice Returns withdrawal fee params for pool /// @param pool Pool address /// @return params function getWithdrawalFeePoolParams(address pool) external view returns (WithdrawalFeePoolParams memory params); /// @notice Changes withdrawalFee for pool /// @dev can be called only by factory owner or NONFUNGIBLE_POSITION_MANAGER_ADMINISTRATOR_ROLE /// @param pool The address of the pool to which the settings have been applied /// @param newWithdrawalFee Percentage of lst token earnings that will be sent to the vault function setWithdrawalFee(address pool, uint16 newWithdrawalFee) external; /// @notice Changes tokens apr for pool /// @dev can be called only by factory owner or NONFUNGIBLE_POSITION_MANAGER_ADMINISTRATOR_ROLE /// @param pool The address of the pool to which the settings have been applied /// @param apr0 APR of LST token0 /// @param apr1 APR of LST token1 function setTokenAPR(address pool, uint64 apr0, uint64 apr1) external; /// @notice Changes fee vault for pool /// @dev can be called only by factory owner or NONFUNGIBLE_POSITION_MANAGER_ADMINISTRATOR_ROLE /// @param pool The address of the pool to which the settings have been applied /// @param fees array of fees values /// @param vaults array of vault addresses function setVaultsForPool(address pool, uint16[] memory fees, address[] memory vaults) external; /// @notice Returns vault address to which fees will be sent /// @return vault The actual vault address function defaultWithdrawalFeesVault() external view returns (address vault); /// @notice Changes vault address /// @dev can be called only by factory owner or NONFUNGIBLE_POSITION_MANAGER_ADMINISTRATOR_ROLE /// @param newVault The new address of vault function setVaultAddress(address newVault) external; /// @notice Returns withdrawalFee information associated with a given token ID /// @param tokenId The ID of the token that represents the position /// @return lastUpdateTimestamp Last increase/decrease liquidity timestamp /// @return withdrawalFeeLiquidity Liqudity of accumulated withdrawal fee function positionsWithdrawalFee( uint256 tokenId ) external view returns (uint32 lastUpdateTimestamp, uint128 withdrawalFeeLiquidity); /// @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; /// @notice Returns whether `spender` is allowed to manage `tokenId` /// @dev Requirement: `tokenId` must exist function isApprovedOrOwner(address spender, uint256 tokenId) external view returns (bool); /// @notice Returns the address of currently connected farming, if any /// @return The address of the farming center contract, which handles farmings logic function farmingCenter() external view returns (address); /// @notice Returns the address of farming that is approved for this token, if any function farmingApprovals(uint256 tokenId) external view returns (address); /// @notice Returns the address of farming in which this token is farmed, if any function tokenFarmedIn(uint256 tokenId) external view returns (address); }
// 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); }
// 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; }
// 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); }
// 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 = 0xf96d2474815c32e070cd63233f06af5413efc5dcb430aee4ff18cc29007c562d; /// @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, 'Invalid order of tokens'); pool = address( uint160( uint256( keccak256( abi.encodePacked( hex'ff', poolDeployer, keccak256(abi.encode(key.token0, key.token1)), POOL_INIT_CODE_HASH ) ) ) ) ); } }
// 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'); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface 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); }
// 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); }
// 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); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.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 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: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721 * or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must * understand this adds an external call which potentially creates a reentrancy vulnerability. * * 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); }
// 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); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.7.6; pragma abicoder v2; import '@cryptoalgebra/integral-core/contracts/interfaces/IERC20Minimal.sol'; import '@cryptoalgebra/integral-core/contracts/interfaces/IAlgebraPool.sol'; /// @param rewardToken The token being distributed as a reward (token0) /// @param bonusRewardToken The bonus token being distributed as a reward (token1) /// @param pool The Algebra pool /// @param nonce The nonce of incentive struct IncentiveKey { IERC20Minimal rewardToken; IERC20Minimal bonusRewardToken; IAlgebraPool pool; uint256 nonce; }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity =0.8.20; import '@cryptoalgebra/integral-core/contracts/libraries/TickTree.sol'; import '@cryptoalgebra/integral-core/contracts/libraries/TickManagement.sol'; import '../interfaces/IAlgebraEternalVirtualPool.sol'; /// @title Algebra virtual 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 TickManagement for mapping(int24 => TickManagement.Tick); using TickTree for mapping(int16 => uint256); /// @inheritdoc IAlgebraEternalVirtualPool mapping(int24 tickId => TickManagement.Tick tick) public override ticks; uint32 internal tickTreeRoot; // The root of bitmap search tree mapping(int16 wordIndex => uint256 word) internal tickSecondLayer; // The second layer bitmap search tree mapping(int16 wordIndex => uint256 word) internal tickTable; // the leaves of the tree int24 internal globalPrevInitializedTick; int24 internal globalNextInitializedTick; 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 oldTickTreeRoot The current tick tree root /// @param prevInitializedTick Previous active tick before `currentTick` /// @param nextInitializedTick Next active tick after `currentTick` /// @param remove Remove or add the tick /// @return New previous active tick before `currentTick` if changed /// @return New next active tick after `currentTick` if changed /// @return New tick tree root if changed function _addOrRemoveTick( int24 tick, int24 currentTick, uint32 oldTickTreeRoot, int24 prevInitializedTick, int24 nextInitializedTick, bool remove ) internal returns (int24, int24, uint32) { if (remove) { (int24 prevTick, int24 nextTick) = ticks.removeTick(tick); if (prevInitializedTick == tick) prevInitializedTick = prevTick; else if (nextInitializedTick == tick) nextInitializedTick = nextTick; } else { int24 prevTick; int24 nextTick; if (prevInitializedTick < tick && nextInitializedTick > tick) { (prevTick, nextTick) = (prevInitializedTick, nextInitializedTick); // we know next and prev ticks if (tick > currentTick) nextInitializedTick = tick; else prevInitializedTick = tick; } else { nextTick = tickTable.getNextTick(tickSecondLayer, oldTickTreeRoot, tick); prevTick = ticks[nextTick].prevTick; } ticks.insertTick(tick, prevTick, nextTick); } uint32 newTickTreeRoot = tickTable.toggleTick(tickSecondLayer, oldTickTreeRoot, tick); return (prevInitializedTick, nextInitializedTick, newTickTreeRoot); } /// @notice Used to add or remove a pair of ticks from a doubly linked list and search tree /// @param bottomTick The bottom tick being removed or added now /// @param topTick The top tick being removed or added now /// @param toggleBottom Should bottom tick be changed or not /// @param toggleTop Should top tick be changed or not /// @param currentTick The current global tick in the pool /// @param remove Remove or add the ticks function _addOrRemoveTicks(int24 bottomTick, int24 topTick, bool toggleBottom, bool toggleTop, int24 currentTick, bool remove) internal { (int24 prevInitializedTick, int24 nextInitializedTick, uint32 oldTickTreeRoot) = ( globalPrevInitializedTick, globalNextInitializedTick, tickTreeRoot ); (int24 newPrevTick, int24 newNextTick, uint32 newTreeRoot) = (prevInitializedTick, nextInitializedTick, oldTickTreeRoot); if (toggleBottom) { (newPrevTick, newNextTick, newTreeRoot) = _addOrRemoveTick(bottomTick, currentTick, newTreeRoot, newPrevTick, newNextTick, remove); } if (toggleTop) { (newPrevTick, newNextTick, newTreeRoot) = _addOrRemoveTick(topTick, currentTick, newTreeRoot, newPrevTick, newNextTick, remove); } if (prevInitializedTick != newPrevTick || nextInitializedTick != newNextTick || newTreeRoot != oldTickTreeRoot) { (globalPrevInitializedTick, globalNextInitializedTick, tickTreeRoot) = (newPrevTick, newNextTick, newTreeRoot); } } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity =0.8.20; pragma abicoder v1; import '@cryptoalgebra/integral-core/contracts/base/common/Timestamp.sol'; import '@cryptoalgebra/integral-core/contracts/libraries/FullMath.sol'; import '@cryptoalgebra/integral-core/contracts/libraries/Constants.sol'; import '@cryptoalgebra/integral-core/contracts/libraries/TickMath.sol'; import '@cryptoalgebra/integral-core/contracts/libraries/LiquidityMath.sol'; import '@cryptoalgebra/integral-core/contracts/libraries/TickManagement.sol'; import '@cryptoalgebra/integral-core/contracts/interfaces/pool/IAlgebraPoolErrors.sol'; import '../base/VirtualTickStructure.sol'; /// @title Algebra Integral 1.0 eternal virtual pool /// @notice used to track active liquidity in farming and distribute rewards contract EternalVirtualPool is Timestamp, VirtualTickStructure { using TickManagement for mapping(int24 => TickManagement.Tick); /// @inheritdoc IAlgebraEternalVirtualPool address public immutable override farmingAddress; /// @inheritdoc IAlgebraEternalVirtualPool address public immutable override plugin; /// @inheritdoc IAlgebraEternalVirtualPool uint128 public override currentLiquidity; /// @inheritdoc IAlgebraEternalVirtualPool int24 public override globalTick; /// @inheritdoc IAlgebraEternalVirtualPool uint32 public override prevTimestamp; /// @inheritdoc IAlgebraEternalVirtualPool bool public override deactivated; uint128 internal rewardRate0; uint128 internal rewardRate1; uint128 internal rewardReserve0; uint128 internal rewardReserve1; uint256 internal totalRewardGrowth0 = 1; uint256 internal totalRewardGrowth1 = 1; modifier onlyFromFarming() { _checkIsFromFarming(); _; } constructor(address _farmingAddress, address _plugin) { farmingAddress = _farmingAddress; plugin = _plugin; prevTimestamp = _blockTimestamp(); globalPrevInitializedTick = TickMath.MIN_TICK; globalNextInitializedTick = TickMath.MAX_TICK; } /// @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 totalRewardGrowth() external view override returns (uint256 rewardGrowth0, uint256 rewardGrowth1) { return (totalRewardGrowth0, totalRewardGrowth1); } /// @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 || ticks[topTick].prevTick == ticks[topTick].nextTick) revert IAlgebraPoolErrors.tickIsNotInitialized(); uint32 timeDelta = _blockTimestamp() - prevTimestamp; int24 _globalTick = globalTick; (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 deactivate() external override onlyFromFarming { deactivated = true; } /// @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 /// @dev If the virtual pool is deactivated, does nothing function crossTo(int24 targetTick, bool zeroToOne) external override returns (bool) { if (msg.sender != plugin) revert onlyPlugin(); // All storage reads in this code block use the same slot uint128 _currentLiquidity = currentLiquidity; int24 _globalTick = globalTick; uint32 _prevTimestamp = prevTimestamp; bool _deactivated = deactivated; int24 previousTick = globalPrevInitializedTick; int24 nextTick = globalNextInitializedTick; if (_deactivated) return false; // early return if virtual pool is deactivated bool virtualZtO = targetTick <= _globalTick; // direction of movement from the point of view of the virtual pool // early return if without any crosses if (virtualZtO) { if (targetTick >= previousTick) return true; } else { if (targetTick < nextTick) return true; } if (virtualZtO != zeroToOne) { deactivated = true; // deactivate if invalid input params (possibly desynchronization) return false; } _distributeRewards(_prevTimestamp, _currentLiquidity); (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 { int128 liquidityDelta; _globalTick = previousTick - 1; // safe since tick index range is narrower than the data type nextTick = previousTick; (liquidityDelta, previousTick, ) = ticks.cross(previousTick, rewardGrowth0, rewardGrowth1); _currentLiquidity = LiquidityMath.addDelta(_currentLiquidity, -liquidityDelta); } } } else { while (_globalTick != TickMath.MAX_TICK - 1) { if (targetTick < nextTick) break; int128 liquidityDelta; _globalTick = nextTick; previousTick = nextTick; (liquidityDelta, , nextTick) = ticks.cross(nextTick, rewardGrowth0, rewardGrowth1); _currentLiquidity = LiquidityMath.addDelta(_currentLiquidity, liquidityDelta); } } currentLiquidity = _currentLiquidity; globalTick = targetTick; globalPrevInitializedTick = previousTick; globalNextInitializedTick = nextTick; return true; } /// @inheritdoc IAlgebraEternalVirtualPool function distributeRewards() external override onlyFromFarming { _distributeRewards(); } /// @inheritdoc IAlgebraEternalVirtualPool function applyLiquidityDeltaToPosition( int24 bottomTick, int24 topTick, int128 liquidityDelta, int24 currentTick ) external override onlyFromFarming { uint128 _currentLiquidity = currentLiquidity; uint32 _prevTimestamp = prevTimestamp; bool _deactivated = deactivated; { int24 _nextActiveTick = globalNextInitializedTick; int24 _prevActiveTick = globalPrevInitializedTick; if (!_deactivated) { // checking if the current tick is within the allowed range: it should not be on the other side of the nearest active tick // if the check is violated, the virtual pool deactivates if (!_isTickInsideRange(currentTick, _prevActiveTick, _nextActiveTick)) { deactivated = _deactivated = true; } } } if (_deactivated) { // early return if virtual pool is deactivated return; } globalTick = currentTick; if (_blockTimestamp() > _prevTimestamp) { _distributeRewards(_prevTimestamp, _currentLiquidity); } if (liquidityDelta != 0) { // if we need to update the ticks, do it bool flippedBottom = _updateTick(bottomTick, currentTick, liquidityDelta, false); bool flippedTop = _updateTick(topTick, currentTick, liquidityDelta, true); if (_isTickInsideRange(currentTick, bottomTick, topTick)) { currentLiquidity = LiquidityMath.addDelta(_currentLiquidity, liquidityDelta); } if (flippedBottom || flippedTop) { _addOrRemoveTicks(bottomTick, topTick, flippedBottom, flippedTop, currentTick, liquidityDelta < 0); } } } /// @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 _isTickInsideRange(int24 tick, int24 bottomTick, int24 topTick) internal pure returns (bool) { return tick >= bottomTick && tick < topTick; } function _applyRewardsDelta(bool add, uint128 token0Delta, uint128 token1Delta) private { _distributeRewards(); if (token0Delta | token1Delta != 0) { (uint128 _rewardReserve0, uint128 _rewardReserve1) = (rewardReserve0, rewardReserve1); if (add) { _rewardReserve0 = _rewardReserve0 + token0Delta; _rewardReserve1 = _rewardReserve1 + token1Delta; } else { _rewardReserve0 = _rewardReserve0 - token0Delta; _rewardReserve1 = _rewardReserve1 - token1Delta; } (rewardReserve0, rewardReserve1) = (_rewardReserve0, _rewardReserve1); } } function _distributeRewards() internal { _distributeRewards(prevTimestamp, currentLiquidity); } function _distributeRewards(uint32 _prevTimestamp, uint256 _currentLiquidity) internal { // currentLiquidity is uint128 unchecked { uint256 timeDelta = _blockTimestamp() - _prevTimestamp; // safe until timedelta > 136 years if (timeDelta == 0) return; // only once per block 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 = _blockTimestamp(); return; } function _updateTick(int24 tick, int24 currentTick, int128 liquidityDelta, bool isTopTick) internal returns (bool updated) { return ticks.update(tick, currentTick, liquidityDelta, totalRewardGrowth0, totalRewardGrowth1, isTopTick); } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.8.4; import '@cryptoalgebra/integral-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 { /// @notice Details of the incentive to create 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 farmDoesNotExist(); error tokenAlreadyFarmed(); error incentiveNotExist(); error incentiveStopped(); error anotherFarmingIsActive(); error pluginNotConnected(); error minimalPositionWidthTooWide(); error zeroRewardAmount(); error positionIsTooNarrow(); error zeroLiquidity(); error invalidPool(); error claimToZeroAddress(); error invalidTokenAmount(); error emergencyActivated(); error reentrancyLock(); error poolReentrancyLock(); /// @notice Returns hash of 'INCENTIVE_MAKER_ROLE', used as role for incentive creation function INCENTIVE_MAKER_ROLE() external view returns (bytes32); /// @notice Returns hash of 'FARMINGS_ADMINISTRATOR_ROLE', used as role for permissioned actions in farming function FARMINGS_ADMINISTRATOR_ROLE() external view returns (bytes32); /// @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, address pluginAddress ); /// @notice Check if incentive is deactivated (manually or automatically) /// @dev Does not check if the incentive is indeed currently connected to the Algebra pool or not /// @param incentiveId The ID of the incentive computed from its parameters /// @return True if incentive is deactivated (manually or automatically) function isIncentiveDeactivated(bytes32 incentiveId) external view returns (bool); /// @notice Returns address of current farmingCenter function farmingCenter() external view returns (address); /// @notice Users can withdraw liquidity without any checks if active. function isEmergencyWithdrawActivated() external view returns (bool); /// @notice Detach incentive from the pool and deactivate it /// @param key The key of the incentive function deactivateIncentive(IncentiveKey memory key) external; /// @notice Add rewards for incentive /// @param key The key of the incentive /// @param rewardAmount The amount of token0 /// @param bonusRewardAmount The amount of token1 function addRewards(IncentiveKey memory key, uint128 rewardAmount, uint128 bonusRewardAmount) external; /// @notice Decrease rewards for incentive and withdraw /// @param key The key of the incentive /// @param rewardAmount The amount of token0 /// @param bonusRewardAmount The amount of token1 function decreaseRewardsAmount(IncentiveKey memory key, uint128 rewardAmount, uint128 bonusRewardAmount) external; /// @notice Changes `isEmergencyWithdrawActivated`. Users can withdraw liquidity without any checks if activated. /// User cannot enter to farmings if activated. /// _Must_ only be used in emergency situations. Farmings may be unusable after activation. /// @dev only farmings administrator /// @param newStatus The new status of `isEmergencyWithdrawActivated`. function setEmergencyWithdrawStatus(bool newStatus) external; /// @notice Returns amount of created incentives function numOfIncentives() external view returns (uint256); /// @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 enter farming /// @param tokenId The ID of the token to enter farming function enterFarming(IncentiveKey memory key, uint256 tokenId) external; /// @notice exitFarmings for Algebra LP token /// @param key The key of the incentive for which to exit farming /// @param tokenId The ID of the token to exit farming /// @param _owner Owner of the token function exitFarming(IncentiveKey memory key, uint256 tokenId, address _owner) external; /// @notice Transfers `amountRequested` of accrued `rewardToken` (if possible) 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 rewardBalanceBefore The total amount of unclaimed reward *before* claim function claimReward(IERC20Minimal rewardToken, address to, uint256 amountRequested) external returns (uint256 rewardBalanceBefore); /// @notice Transfers `amountRequested` of accrued `rewardToken` (if possible) 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 rewardBalanceBefore The total amount of unclaimed reward *before* claim function claimRewardFrom( IERC20Minimal rewardToken, address from, address to, uint256 amountRequested ) external returns (uint256 rewardBalanceBefore); /// @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 farmed liquidity NFT /// @param tokenId The ID of the farmed token /// @param incentiveId The ID of the incentive for which the token is farmed /// @return liquidity The amount of liquidity in the NFT as of the last time the rewards were computed, /// @return tickLower The lower tick of position, /// @return tickUpper The upper tick of position, /// @return innerRewardGrowth0 The last saved reward0 growth inside position, /// @return 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 farming incentive program /// @param key Details of the incentive to create /// @param params Params of incentive /// @param plugin The address of corresponding plugin /// @return virtualPool The created virtual pool function createEternalFarming(IncentiveKey memory key, IncentiveParams memory params, address plugin) external returns (address virtualPool); /// @notice Change reward rates for incentive /// @param key The key of incentive /// @param rewardRate The new rate of main token (token0) distribution per sec /// @param bonusRewardRate The new rate of bonus token (token1) distribution per sec function setRates(IncentiveKey memory key, uint128 rewardRate, uint128 bonusRewardRate) external; /// @notice Collect rewards for tokenId /// @dev only FarmingCenter /// @param key The key of incentive /// @param tokenId The ID of the token to exit farming /// @param _owner Owner of the token /// @return reward The amount of main token (token0) collected /// @param bonusReward The amount of bonus token (token1) collected 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 farmed /// @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 farmed event FarmEntered(uint256 indexed tokenId, bytes32 indexed incentiveId, uint128 liquidity); /// @notice Event emitted when a Algebra LP token exited from farming /// @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 claimed /// @param bonusReward The amount of bonus reward tokens to be claimed event FarmEnded( uint256 indexed tokenId, bytes32 indexed incentiveId, address indexed rewardAddress, address bonusRewardToken, address owner, uint256 reward, uint256 bonusReward ); /// @notice Emitted when the farming center is changed /// @param farmingCenter The farming center after the address was changed event FarmingCenter(address indexed farmingCenter); /// @notice Event emitted when rewards were added /// @param rewardAmount The additional amount of main token /// @param bonusRewardAmount The additional amount of bonus token /// @param incentiveId The ID of the incentive for which rewards were added event RewardsAdded(uint256 rewardAmount, uint256 bonusRewardAmount, bytes32 incentiveId); /// @notice Event emitted when rewards were decreased /// @param rewardAmount The withdrawn amount of main token /// @param bonusRewardAmount The withdrawn amount of bonus token /// @param incentiveId The ID of the incentive for which rewards were decreased event RewardAmountsDecreased(uint256 rewardAmount, uint256 bonusRewardAmount, bytes32 incentiveId); /// @notice Event emitted when a reward token has been claimed /// @param to The address where claimed rewards were sent to /// @param reward The amount of reward tokens claimed /// @param rewardAddress The token reward address /// @param owner The address where claimed rewards were claimed from 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 (token0) distribution per sec /// @param bonusRewardRate The new rate of bonus token (token1) 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 ); /// @notice Emitted when status of `isEmergencyWithdrawActivated` changes /// @param newStatus New value of `isEmergencyWithdrawActivated`. Users can withdraw liquidity without any checks if active. event EmergencyWithdraw(bool newStatus); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.8.4; import '@cryptoalgebra/integral-base-plugin/contracts/interfaces/IAlgebraVirtualPool.sol'; /// @title Algebra eternal virtual pool interface /// @notice Used to track active liquidity in farming and distribute rewards interface IAlgebraEternalVirtualPool is IAlgebraVirtualPool { error onlyPlugin(); error onlyFarming(); /// @notice Returns address of the AlgebraEternalFarming function farmingAddress() external view returns (address); /// @notice Returns address of the plugin for which this virtual pool was created function plugin() external view returns (address); /// @notice Returns data associated with a tick function ticks( int24 tickId ) external view returns ( uint256 liquidityTotal, int128 liquidityDelta, int24 prevTick, int24 nextTick, uint256 outerFeeGrowth0Token, uint256 outerFeeGrowth1Token ); /// @notice Returns the current liquidity in virtual pool function currentLiquidity() external view returns (uint128); /// @notice Returns the current tick in virtual pool function globalTick() external view returns (int24); /// @notice Returns the timestamp after previous virtual pool update function prevTimestamp() external view returns (uint32); /// @notice Returns true if virtual pool is deactivated function deactivated() external view returns (bool); /// @dev This function is called when anyone changes their farmed liquidity. The position in a virtual pool should be changed accordingly. /// If the virtual pool is deactivated, does nothing. /// @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(int24 bottomTick, int24 topTick, int128 liquidityDelta, int24 currentTick) external; /// @dev This function is called by farming to increase rewards per liquidity accumulator. /// Can only be called by farming 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 This function is used to deactivate virtual pool /// @dev Can only be called by farming function deactivate() 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; /// @notice Retrieves rewards growth data inside specified range /// @dev Should only be used for relative comparison of the same range over time /// @param bottomTick The lower tick boundary of the range /// @param topTick The upper tick boundary of the range /// @return rewardGrowthInside0 The all-time reward growth in token0, per unit of liquidity, inside the range's tick boundaries /// @return rewardGrowthInside1 The all-time reward growth in token1, per unit of liquidity, inside the range's tick boundaries 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); /// @notice Get reward growth accumulators /// @return rewardGrowth0 The reward growth for reward0, per unit of liquidity, has only relative meaning /// @return rewardGrowth1 The reward growth for reward1, per unit of liquidity, has only relative meaning function totalRewardGrowth() external view returns (uint256 rewardGrowth0, uint256 rewardGrowth1); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.7.6; pragma abicoder v2; import '@cryptoalgebra/integral-core/contracts/interfaces/IERC20Minimal.sol'; import '@cryptoalgebra/integral-periphery/contracts/interfaces/IMulticall.sol'; import '@cryptoalgebra/integral-periphery/contracts/interfaces/INonfungiblePositionManager.sol'; import '@cryptoalgebra/integral-base-plugin/contracts/interfaces/plugins/IFarmingPlugin.sol'; import '../base/IncentiveKey.sol'; import '../interfaces/IAlgebraEternalFarming.sol'; /// @title Algebra main farming contract interface /// @dev Manages users deposits and performs entry, exit and other actions. interface IFarmingCenter is IMulticall { /// @notice Returns current virtual pool address for Algebra pool function virtualPoolAddresses(address poolAddress) external view returns (address virtualPoolAddresses); /// @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 Returns incentive key for specific incentiveId /// @param incentiveId The hash of incentive key function incentiveKeys( bytes32 incentiveId ) external view returns (IERC20Minimal rewardToken, IERC20Minimal bonusRewardToken, IAlgebraPool pool, uint256 nonce); /// @notice Used to connect incentive to compatible AlgebraPool plugin /// @dev only farming can do it /// Will revert if something is already connected to the plugin /// @param virtualPool The virtual pool to be connected, must not be zero address /// @param plugin The Algebra farming plugin function connectVirtualPoolToPlugin(address virtualPool, IFarmingPlugin plugin) external; /// @notice Used to disconnect incentive from compatible AlgebraPool plugin /// @dev only farming can do it. /// If the specified virtual pool is not connected to the plugin, nothing will happen /// @param virtualPool The virtual pool to be disconnected, must not be zero address /// @param plugin The Algebra farming plugin function disconnectVirtualPoolFromPlugin(address virtualPool, IFarmingPlugin plugin) external; /// @notice Enters in incentive (eternal farming) with NFT-position token /// @dev msg.sender must be the owner of NFT /// @param key The incentive key /// @param tokenId The id of position NFT function enterFarming(IncentiveKey memory key, uint256 tokenId) external; /// @notice Exits from incentive (eternal farming) with NFT-position token /// @dev msg.sender must be the owner of NFT /// @param key The incentive 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 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 rewardBalanceBefore The total amount of unclaimed reward *before* claim function claimReward(IERC20Minimal rewardToken, address to, uint256 amountRequested) external returns (uint256 rewardBalanceBefore); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.7.6; import '../base/IncentiveKey.sol'; library IncentiveId { /// @notice Calculate the key for a farming 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)); } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.7.6; import '@cryptoalgebra/integral-core/contracts/interfaces/IAlgebraPool.sol'; import '@cryptoalgebra/integral-core/contracts/interfaces/IAlgebraPoolDeployer.sol'; import '@cryptoalgebra/integral-periphery/contracts/interfaces/INonfungiblePositionManager.sol'; import '@cryptoalgebra/integral-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}))); } }
{ "evmVersion": "paris", "optimizer": { "enabled": true, "runs": 99999999 }, "metadata": { "bytecodeHash": "none" }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "libraries": {} }
[{"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":"emergencyActivated","type":"error"},{"inputs":[],"name":"farmDoesNotExist","type":"error"},{"inputs":[],"name":"incentiveNotExist","type":"error"},{"inputs":[],"name":"incentiveStopped","type":"error"},{"inputs":[],"name":"invalidPool","type":"error"},{"inputs":[],"name":"invalidTokenAmount","type":"error"},{"inputs":[],"name":"minimalPositionWidthTooWide","type":"error"},{"inputs":[],"name":"pluginNotConnected","type":"error"},{"inputs":[],"name":"poolReentrancyLock","type":"error"},{"inputs":[],"name":"positionIsTooNarrow","type":"error"},{"inputs":[],"name":"reentrancyLock","type":"error"},{"inputs":[],"name":"tokenAlreadyFarmed","type":"error"},{"inputs":[],"name":"zeroLiquidity","type":"error"},{"inputs":[],"name":"zeroRewardAmount","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"newStatus","type":"bool"}],"name":"EmergencyWithdraw","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"contract IERC20Minimal","name":"rewardToken","type":"address"},{"indexed":true,"internalType":"contract IERC20Minimal","name":"bonusRewardToken","type":"address"},{"indexed":true,"internalType":"contract IAlgebraPool","name":"pool","type":"address"},{"indexed":false,"internalType":"address","name":"virtualPool","type":"address"},{"indexed":false,"internalType":"uint256","name":"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":false,"internalType":"uint256","name":"rewardAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"bonusRewardAmount","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"},{"internalType":"address","name":"plugin","type":"address"}],"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":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes32","name":"incentiveId","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":"incentiveId","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"},{"internalType":"address","name":"pluginAddress","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isEmergencyWithdrawActivated","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"incentiveId","type":"bytes32"}],"name":"isIncentiveDeactivated","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":"owner","type":"address"},{"internalType":"contract IERC20Minimal","name":"rewardToken","type":"address"}],"name":"rewards","outputs":[{"internalType":"uint256","name":"rewardAmount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bool","name":"newStatus","type":"bool"}],"name":"setEmergencyWithdrawStatus","outputs":[],"stateMutability":"nonpayable","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"}]
Contract Creation Code
60e06040526000805460ff60a81b1916600160a81b1790553480156200002457600080fd5b5060405162006005380380620060058339810160408190526200004791620000ed565b6001600160a01b03808216608081905290831660a0526040805163c45a015560e01b8152905163c45a0155916004808201926020929091908290030181865afa15801562000099573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620000bf91906200012c565b6001600160a01b031660c05250620001539050565b6001600160a01b0381168114620000ea57600080fd5b50565b600080604083850312156200010157600080fd5b82516200010e81620000d4565b60208401519092506200012181620000d4565b809150509250929050565b6000602082840312156200013f57600080fd5b81516200014c81620000d4565b9392505050565b60805160a05160c051615e7b6200018a600039600061200e0152600061270d0152600081816104f9015261272e0152615e7b6000f3fe60806040523480156200001157600080fd5b5060043610620001ad5760003560e01c80638433524111620000f5578063dd56e5d81162000097578063f2256319116200006e578063f225631914620005d1578063f26ebf7a14620005f7578063f6de3cae146200060e57600080fd5b8063dd56e5d8146200056b578063df42efda146200058c578063e70b9e2714620005a357600080fd5b8063b44a272211620000cc578063b44a272214620004f3578063b5bae00a146200051b578063b8883c50146200054357600080fd5b80638433524114620004ae578063890cdcb314620004c557806396da9bd514620004dc57600080fd5b806336808b19116200015f5780635739f0b911620001365780635739f0b9146200037657806360777795146200038d57806382bd79ea14620004a457600080fd5b806336808b1914620002fa5780633c6d07151462000311578063547b6da9146200033957600080fd5b806327e6a99a116200019457806327e6a99a14620002095780632912bf1014620002ca5780632f2d783d14620002e357600080fd5b8063046ec16614620001b25780630a53075414620001e3575b600080fd5b620001c9620001c33660046200343a565b62000625565b604080519283526020830191909152015b60405180910390f35b620001fa620001f436600462003480565b620007dc565b604051908152602001620001da565b620002886200021a366004620034d8565b6002602081815260009384526040808520909152918352912080546001820154918301546fffffffffffffffffffffffffffffffff8216937001000000000000000000000000000000008304810b93730100000000000000000000000000000000000000909304900b919085565b604080516fffffffffffffffffffffffffffffffff9096168652600294850b60208701529290930b918401919091526060830152608082015260a001620001da565b620002e1620002db366004620034fb565b620007ff565b005b620001fa620002f43660046200351a565b62000ad2565b620002e16200030b3660046200343a565b62000aec565b620001fa7f681ab0361ab5f3ae8c1d864335ef2b9a8c12a6a67e1ed0f4083d00a4b8a9a39581565b620003506200034a3660046200357f565b62000c94565b60405173ffffffffffffffffffffffffffffffffffffffff9091168152602001620001da565b620002e16200038736600462003669565b62001259565b620004406200039e36600462003697565b60016020819052600091825260409091208054918101546002909101546fffffffffffffffffffffffffffffffff808416937001000000000000000000000000000000009004169173ffffffffffffffffffffffffffffffffffffffff8082169274010000000000000000000000000000000000000000830462ffffff169277010000000000000000000000000000000000000000000000900460ff16911686565b604080516fffffffffffffffffffffffffffffffff978816815296909516602087015273ffffffffffffffffffffffffffffffffffffffff9384169486019490945262ffffff9091166060850152151560808401521660a082015260c001620001da565b620001fa60035481565b620002e1620004bf366004620036b1565b62001455565b620002e1620004d636600462003706565b62001526565b620001c9620004ed36600462003669565b620015f6565b620003507f000000000000000000000000000000000000000000000000000000000000000081565b620005326200052c36600462003697565b62001654565b6040519015158152602001620001da565b620001fa7fa777c10270ee0b99d2c737c09ff865ed48064b252418bbd31d39c8b88ea1221981565b600054620003509073ffffffffffffffffffffffffffffffffffffffff1681565b620002e16200059d36600462003726565b62001673565b620001fa620005b436600462003746565b600460209081526000928352604080842090915290825290205481565b600054620005329074010000000000000000000000000000000000000000900460ff1681565b620002e162000608366004620036b1565b62001734565b620002e16200061f366004620036b1565b620017e0565b6000806200063262001b7c565b600080620006408762001ba3565b91509150600062000652878462001c7d565b600183015490915073ffffffffffffffffffffffffffffffffffffffff166200067b8162001d6c565b6000806200068a838562001dd1565b809450819550829a50839b50505050506000600260008c8152602001908152602001600020600088815260200190815260200160002090508281600101819055508181600201819055506000600460008c73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000209050896000146200074d578c5173ffffffffffffffffffffffffffffffffffffffff16600090815260208290526040902080548b0190555b881562000784576020808e015173ffffffffffffffffffffffffffffffffffffffff166000908152908290526040902080548a0190555b604080518d8152602081018a90529081018b9052606081018a90527f15b2e0f32b50efdbbdee9ec7884ed3c61e6209b1b395e5762011a6734b86f7b59060800160405180910390a15050505050505050935093915050565b6000620007e862001b7c565b620007f68585858562001e74565b95945050505050565b6200082a7fa777c10270ee0b99d2c737c09ff865ed48064b252418bbd31d39c8b88ea1221962001fd9565b600080620008388362001ba3565b6001810154919350915077010000000000000000000000000000000000000000000000900460ff161562000898576040517f260e553a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60018101805460028301547fffffffffffffffff00ffffffffffffffffffffffffffffffffffffffffffffff82167701000000000000000000000000000000000000000000000017909255604080517f51b42b00000000000000000000000000000000000000000000000000000000008152905173ffffffffffffffffffffffffffffffffffffffff928316939092169183916351b42b0091600480830192600092919082900301818387803b1580156200095257600080fd5b505af115801562000967573d6000803e3d6000fd5b505050506000808373ffffffffffffffffffffffffffffffffffffffff1663a88a5c166040518163ffffffff1660e01b81526004016040805180830381865afa158015620009b9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620009df919062003791565b915091508082176fffffffffffffffffffffffffffffffff1660001462000a0f5762000a0f84600080896200209e565b6000546040517f2bd34c4800000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8681166004830152858116602483015290911690632bd34c4890604401600060405180830381600087803b15801562000a8557600080fd5b505af115801562000a9a573d6000803e3d6000fd5b50506040518892507f907b91fb061b1c46367da11a5a0e8b2c0bd5fecd22eb92967e626cffa5ef63869150600090a250505050505050565b600062000ae28433858562001e74565b90505b9392505050565b62000af662001b7c565b600062000b688460408051825173ffffffffffffffffffffffffffffffffffffffff90811660208084019190915284015181168284015291830151909116606080830191909152820151608082015260009060a001604051602081830303815290604052805190602001209050919050565b9050600062000b78848362001c7d565b9050600080600060149054906101000a900460ff1662000bd25762000bcc8388868862000bbb88600001516fffffffffffffffffffffffffffffffff1662002195565b62000bc690620037f4565b620021ac565b90925090505b6000868152600260208181526040808420888552825280842080547fffffffffffffffffffff000000000000000000000000000000000000000000001681556001810185905590920192909255885189830151825173ffffffffffffffffffffffffffffffffffffffff918216815289821694810194909452918301859052606083018490521690859088907f7f2557bb15dcf63e3d029ef1dcb4333563fcd78edf263b8fe42ed3adb925ff849060800160405180910390a450505050505050565b600062000cc17fa777c10270ee0b99d2c737c09ff865ed48064b252418bbd31d39c8b88ea1221962001fd9565b6000846040015173ffffffffffffffffffffffffffffffffffffffff1663ef01df4f6040518163ffffffff1660e01b8152600401602060405180830381865afa15801562000d13573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000d39919062003842565b90508273ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614158062000d8b575073ffffffffffffffffffffffffffffffffffffffff8116155b1562000dc3576040517f093d6f1700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16631d4632ac6040518163ffffffff1660e01b8152600401602060405180830381865afa15801562000e27573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000e4d919062003842565b73ffffffffffffffffffffffffffffffffffffffff161462000e9b576040517f47146bcc00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b308160405162000eab90620032fd565b73ffffffffffffffffffffffffffffffffffffffff928316815291166020820152604001604051809103906000f08015801562000eec573d6000803e3d6000fd5b506000546040517fd68516bc00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8084166004830152848116602483015292945091169063d68516bc90604401600060405180830381600087803b15801562000f6557600080fd5b505af115801562000f7a573d6000803e3d6000fd5b50506003805492509050600062000f918362003862565b90915550606086015260006200100c8660408051825173ffffffffffffffffffffffffffffffffffffffff90811660208084019190915284015181168284015291830151909116606080830191909152820151608082015260009060a001604051602081830303815290604052805190602001209050919050565b60008181526001602090815260409091208751918801519293509162001035918991846200234a565b6fffffffffffffffffffffffffffffffff9081166020890152168087526000036200108c576040517f36ab0f6a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6080860151621b13d062ffffff9091161315620010d5576040517f1db9891100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600181018054608088015162ffffff811674010000000000000000000000000000000000000000027fffffffffffffffffff000000000000000000000000000000000000000000000090921673ffffffffffffffffffffffffffffffffffffffff80891691909117929092179092556002830180548683167fffffffffffffffffffffffff0000000000000000000000000000000000000000919091161790556040808a01516020808c01518c5160608e01518d51938e01519551948716979287169691909116947fcef9468c62cd8a6eca3a887fc30674c037943e423de07ab3a122bdf2f73c77e1946200121b948d9490929173ffffffffffffffffffffffffffffffffffffffff95909516855260208501939093526fffffffffffffffffffffffffffffffff918216604085015216606083015262ffffff16608082015260a00190565b60405180910390a4620012398487600001518860200151856200251c565b6200124f8487604001518860600151856200209e565b5050509392505050565b6200126362001b7c565b60005474010000000000000000000000000000000000000000900460ff1615620012b9576040517f05bfeb5900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000806000806000620012cd87876200260a565b93985091965094509250905080600080620012ea83888862002893565b915091506040518060a00160405280866fffffffffffffffffffffffffffffffff1681526020018860020b81526020018760020b815260200183815260200182815250600260008b815260200190815260200160002060008a815260200190815260200160002060008201518160000160006101000a8154816fffffffffffffffffffffffffffffffff02191690836fffffffffffffffffffffffffffffffff16021790555060208201518160000160106101000a81548162ffffff021916908360020b62ffffff16021790555060408201518160000160136101000a81548162ffffff021916908360020b62ffffff160217905550606082015181600101556080820151816002015590505087897f19bc21617a8d86ff19202ac9541480a99b9ae5fbd573a23f14f479af784392c4876040516200144191906fffffffffffffffffffffffffffffffff91909116815260200190565b60405180910390a350505050505050505050565b620014807fa777c10270ee0b99d2c737c09ff865ed48064b252418bbd31d39c8b88ea1221962001fd9565b6000806200148e8562001ba3565b6001810154919350915073ffffffffffffffffffffffffffffffffffffffff166fffffffffffffffffffffffffffffffff8585171615801590620014d85750620014d88262002940565b1562001510576040517f260e553a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6200151e818686866200209e565b505050505050565b620015517f681ab0361ab5f3ae8c1d864335ef2b9a8c12a6a67e1ed0f4083d00a4b8a9a39562001fd9565b801515600060149054906101000a900460ff161515036200157157600080fd5b6000805482151574010000000000000000000000000000000000000000027fffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffff9091161790556040517fee20b3d336390a4b077dbc7d702bf6e35a954bc96106f37b9e5ef08a1d0ce05990620015eb90831515815260200190565b60405180910390a150565b600080600080620016078662001ba3565b91509150600062001619868462001c7d565b600183015490915073ffffffffffffffffffffffffffffffffffffffff1662001643818362001dd1565b50919a909950975050505050505050565b60008181526001602052604081206200166d9062002940565b92915050565b6200169e7f681ab0361ab5f3ae8c1d864335ef2b9a8c12a6a67e1ed0f4083d00a4b8a9a39562001fd9565b60005473ffffffffffffffffffffffffffffffffffffffff90811690821603620016c757600080fd5b600080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff8316908117825560405190917f29f9e1ebeee07596f3165f3e42cb9d4d8d22b0481e968d6c74be3dd037c15d9b91a250565b600080620017428562001ba3565b91509150620017518162002940565b1562001789576040517f260e553a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600181015473ffffffffffffffffffffffffffffffffffffffff16620017b2868686856200234a565b90955093506fffffffffffffffffffffffffffffffff85851716156200151e576200151e818686866200251c565b6200180b7f681ab0361ab5f3ae8c1d864335ef2b9a8c12a6a67e1ed0f4083d00a4b8a9a39562001fd9565b600080620018198562001ba3565b6001810154919350915073ffffffffffffffffffffffffffffffffffffffff16620018448162001d6c565b6000808273ffffffffffffffffffffffffffffffffffffffff1663f0de82286040518163ffffffff1660e01b81526004016040805180830381865afa15801562001892573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620018b8919062003791565b91509150816fffffffffffffffffffffffffffffffff16876fffffffffffffffffffffffffffffffff161115620018ed578196505b83546fffffffffffffffffffffffffffffffff90811690881610620019315783546200192e906001906fffffffffffffffffffffffffffffffff166200389d565b96505b8354620019529088906fffffffffffffffffffffffffffffffff166200389d565b84547fffffffffffffffffffffffffffffffff00000000000000000000000000000000166fffffffffffffffffffffffffffffffff91821617855581811690871611156200199e578095505b8354620019d390879070010000000000000000000000000000000090046fffffffffffffffffffffffffffffffff166200389d565b84546fffffffffffffffffffffffffffffffff9182167001000000000000000000000000000000000291161784556040517fca16ca7e00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff84169063ca16ca7e9062001a74908a908a906004016fffffffffffffffffffffffffffffffff92831681529116602082015260400190565b600060405180830381600087803b15801562001a8f57600080fd5b505af115801562001aa4573d6000803e3d6000fd5b505050506fffffffffffffffffffffffffffffffff87161562001ae257875162001ae290336fffffffffffffffffffffffffffffffff8a16620029f6565b6fffffffffffffffffffffffffffffffff86161562001b1e5762001b1e886020015133886fffffffffffffffffffffffffffffffff16620029f6565b604080516fffffffffffffffffffffffffffffffff808a168252881660208201529081018690527f808ecc37f6d601dde1e43c133bee66af0ff9409b53aca0eb0d4f6c65fb8956e89060600160405180910390a15050505050505050565b60005473ffffffffffffffffffffffffffffffffffffffff16331462001ba157600080fd5b565b60008062001c168360408051825173ffffffffffffffffffffffffffffffffffffffff90811660208084019190915284015181168284015291830151909116606080830191909152820151608082015260009060a001604051602081830303815290604052805190602001209050919050565b6000818152600160205260408120805492945092506fffffffffffffffffffffffffffffffff909116900362001c78576040517fe4c8229200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b915091565b6040805160a0810182526000808252602082018190529181018290526060810182905260808101919091525060008281526002602081815260408084208585528252808420815160a08101835281546fffffffffffffffffffffffffffffffff81168083527001000000000000000000000000000000008204870b958301959095527301000000000000000000000000000000000000009004850b92810192909252600181015460608301529092015460808301529091036200166d576040517f7aa92c6600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff16636f4a2cd06040518163ffffffff1660e01b8152600401600060405180830381600087803b15801562001db557600080fd5b505af115801562001dca573d6000803e3d6000fd5b5050505050565b60008060008062001dec868660200151876040015162002893565b6060870151875192945090925062001e2c91908403906fffffffffffffffffffffffffffffffff1670010000000000000000000000000000000062002b6d565b62001e668660800151830387600001516fffffffffffffffffffffffffffffffff1670010000000000000000000000000000000062002b6d565b909790965091945092509050565b600073ffffffffffffffffffffffffffffffffffffffff831662001ec4576040517fabd1763600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5073ffffffffffffffffffffffffffffffffffffffff80841660009081526004602090815260408083209388168352908390529020549082158062001f0857508183115b1562001f12578192505b821562001fd05773ffffffffffffffffffffffffffffffffffffffff86166000908152602082905260409020838303905562001f50868585620029f6565b8473ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff167fe6ac6a784fb43c9f6329d2f5c82f88a26a93bad4281f7780725af5f071f0aafa8660405162001fc791815260200190565b60405180910390a45b50949350505050565b6040517fe8ae2b69000000000000000000000000000000000000000000000000000000008152600481018290523360248201527f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff169063e8ae2b6990604401602060405180830381865afa1580156200206b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620020919190620038d0565b6200209b57600080fd5b50565b6040517f7f463bb80000000000000000000000000000000000000000000000000000000081526fffffffffffffffffffffffffffffffff80851660048301528316602482015273ffffffffffffffffffffffffffffffffffffffff851690637f463bb890604401600060405180830381600087803b1580156200212057600080fd5b505af115801562002135573d6000803e3d6000fd5b5050604080516fffffffffffffffffffffffffffffffff8088168252861660208201529081018490527f1864e4cc903d98e44820faebd48409c410a2ad20adb3173984ba41ae2828805e925060600190505b60405180910390a150505050565b80600f81900b8114620021a757600080fd5b919050565b600083815260016020819052604082209081015482919073ffffffffffffffffffffffffffffffffffffffff1682620021e58362002940565b620021ff57620021f9896040015162002c27565b62002271565b8173ffffffffffffffffffffffffffffffffffffffff16638e76c3326040518163ffffffff1660e01b8152600401602060405180830381865afa1580156200224b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062002271919062003903565b90506200227e8262001d6c565b6200228a828b62001dd1565b9050508095508196505050620022ac828b602001518c60400151898562002ce6565b73ffffffffffffffffffffffffffffffffffffffff8716600090815260046020526040902085156200230557895173ffffffffffffffffffffffffffffffffffffffff1660009081526020829052604090208054870190555b84156200233c576020808b015173ffffffffffffffffffffffffffffffffffffffff16600090815290829052604090208054860190555b505050509550959350505050565b6000805481907501000000000000000000000000000000000000000000900460ff16620023a3576040517f2446d79f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600080547fffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffffff1690556fffffffffffffffffffffffffffffffff851615620023f5578551620023f2908662002d8c565b91505b6fffffffffffffffffffffffffffffffff84161562002421576200241e86602001518562002d8c565b90505b600080547fffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffffff16750100000000000000000000000000000000000000000017905582546fffffffffffffffffffffffffffffffff8082169170010000000000000000000000000000000090041662002499848362003921565b85547fffffffffffffffffffffffffffffffff00000000000000000000000000000000166fffffffffffffffffffffffffffffffff91909116178555620024e1838262003921565b85546fffffffffffffffffffffffffffffffff9182167001000000000000000000000000000000000291161790945550909590945092505050565b6040517ffddf08e50000000000000000000000000000000000000000000000000000000081526fffffffffffffffffffffffffffffffff80851660048301528316602482015273ffffffffffffffffffffffffffffffffffffffff85169063fddf08e590604401600060405180830381600087803b1580156200259e57600080fd5b505af1158015620025b3573d6000803e3d6000fd5b5050604080516fffffffffffffffffffffffffffffffff8088168252861660208201529081018490527f8b0312d8047895ce795779b66b705ccd39b1ece7c162f642c72d76a785d1b68a9250606001905062002187565b6000806000806000806200261e8862001ba3565b600089815260026020908152604080832085845290915290205491975091506fffffffffffffffffffffffffffffffff161562002687576040517ff352b37500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600181015473ffffffffffffffffffffffffffffffffffffffff8116925074010000000000000000000000000000000000000000900462ffffff16620026cd8262002940565b1562002705576040517f260e553a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000620027547f00000000000000000000000000000000000000000000000000000000000000007f00000000000000000000000000000000000000000000000000000000000000008b62002e26565b60408e0151929a50909850965090915073ffffffffffffffffffffffffffffffffffffffff808316911614620027b6576040517fdce2809300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b846fffffffffffffffffffffffffffffffff1660000362002803576040517f4eed436000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8162ffffff168760020b8760020b0312156200284b576040517feab0585000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000620028588262002c27565b9050620028858589896200287e8a6fffffffffffffffffffffffffffffffff1662002195565b8562002ce6565b505050509295509295909350565b6040517f0bd6f200000000000000000000000000000000000000000000000000000000008152600283810b600483015282900b6024820152600090819073ffffffffffffffffffffffffffffffffffffffff861690630bd6f200906044016040805180830381865afa1580156200290e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200293491906200394d565b91509150935093915050565b600181015460009073ffffffffffffffffffffffffffffffffffffffff81169077010000000000000000000000000000000000000000000000900460ff168062000ae5578173ffffffffffffffffffffffffffffffffffffffff1663556ed30e6040518163ffffffff1660e01b8152600401602060405180830381865afa158015620029d0573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000ae29190620038d0565b6040805173ffffffffffffffffffffffffffffffffffffffff8481166024830152604480830185905283518084039091018152606490920183526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fa9059cbb00000000000000000000000000000000000000000000000000000000179052915160009283929087169162002a8f919062003972565b6000604051808303816000865af19150503d806000811462002ace576040519150601f19603f3d011682016040523d82523d6000602084013e62002ad3565b606091505b509150915081801562002b0157508051158062002b0157508080602001905181019062002b019190620038d0565b62001dca576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600260248201527f535400000000000000000000000000000000000000000000000000000000000060448201526064015b60405180910390fd5b6000838302817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8587098281108382030391505080841162002bae57600080fd5b8060000362002bc35750829004905062000ae5565b8385870960008581038616958690049560026003880281188089028203028089028203028089028203028089028203028089028203028089029091030291819003819004600101858411909403939093029190930391909104170290509392505050565b6000808273ffffffffffffffffffffffffffffffffffffffff1663e76c01e46040518163ffffffff1660e01b815260040160c060405180830381865afa15801562002c76573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062002c9c9190620039b6565b93965092945084935062002ce092505050576040517f9ded0f5700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b50919050565b6040517fd6b83ede000000000000000000000000000000000000000000000000000000008152600285810b600483015284810b6024830152600f84900b604483015282900b606482015273ffffffffffffffffffffffffffffffffffffffff86169063d6b83ede90608401600060405180830381600087803b15801562002d6c57600080fd5b505af115801562002d81573d6000803e3d6000fd5b505050505050505050565b60008062002d9a8462002f0c565b905062002dbc843330866fffffffffffffffffffffffffffffffff1662002fa0565b600062002dc98562002f0c565b905081811162002dd857600080fd5b8181036fffffffffffffffffffffffffffffffff811115620007f6576040517f3ba11f1e00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000806000806000808773ffffffffffffffffffffffffffffffffffffffff166399fbab88886040518263ffffffff1660e01b815260040162002e6b91815260200190565b61016060405180830381865afa15801562002e8a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062002eb0919062003a44565b50506040805180820190915273ffffffffffffffffffffffffffffffffffffffff808916825287166020820152949d50929b5090995093975091955062002eff94508d935091506200311b9050565b9550505093509350935093565b6040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015260009073ffffffffffffffffffffffffffffffffffffffff8316906370a0823190602401602060405180830381865afa15801562002f7a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200166d919062003b2c565b6040805173ffffffffffffffffffffffffffffffffffffffff85811660248301528481166044830152606480830185905283518084039091018152608490920183526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f23b872dd00000000000000000000000000000000000000000000000000000000179052915160009283929088169162003041919062003972565b6000604051808303816000865af19150503d806000811462003080576040519150601f19603f3d011682016040523d82523d6000602084013e62003085565b606091505b5091509150818015620030b3575080511580620030b3575080806020019051810190620030b39190620038d0565b6200151e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600360248201527f5354460000000000000000000000000000000000000000000000000000000000604482015260640162002b64565b6000816020015173ffffffffffffffffffffffffffffffffffffffff16826000015173ffffffffffffffffffffffffffffffffffffffff1610620031bc576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601760248201527f496e76616c6964206f72646572206f6620746f6b656e73000000000000000000604482015260640162002b64565b8282600001518360200151604051602001620031fb92919073ffffffffffffffffffffffffffffffffffffffff92831681529116602082015260400190565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0818403018152908290528051602091820120620032c0939290917ff96d2474815c32e070cd63233f06af5413efc5dcb430aee4ff18cc29007c562d91017fff00000000000000000000000000000000000000000000000000000000000000815260609390931b7fffffffffffffffffffffffffffffffffffffffff0000000000000000000000001660018401526015830191909152603582015260550190565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe081840301815291905280516020909101209392505050565b6123288062003b4783390190565b60405160a0810167ffffffffffffffff8111828210171562003356577f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b60405290565b73ffffffffffffffffffffffffffffffffffffffff811681146200209b57600080fd5b6000608082840312156200339257600080fd5b6040516080810181811067ffffffffffffffff82111715620033dd577f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6040529050808235620033f0816200335c565b8152602083013562003402816200335c565b6020820152604083013562003417816200335c565b6040820152606092830135920191909152919050565b8035620021a7816200335c565b600080600060c084860312156200345057600080fd5b6200345c85856200337f565b92506080840135915060a084013562003475816200335c565b809150509250925092565b600080600080608085870312156200349757600080fd5b8435620034a4816200335c565b93506020850135620034b6816200335c565b92506040850135620034c8816200335c565b9396929550929360600135925050565b60008060408385031215620034ec57600080fd5b50508035926020909101359150565b6000608082840312156200350e57600080fd5b62000ae583836200337f565b6000806000606084860312156200353057600080fd5b83356200353d816200335c565b925060208401356200354f816200335c565b929592945050506040919091013590565b6fffffffffffffffffffffffffffffffff811681146200209b57600080fd5b60008060008385036101408112156200359757600080fd5b620035a386866200337f565b935060a07fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8082011215620035d657600080fd5b50620035e16200330b565b6080850135620035f18162003560565b815260a0850135620036038162003560565b602082015260c0850135620036188162003560565b604082015260e08501356200362d8162003560565b606082015261010085013562ffffff811681146200364a57600080fd5b608082015291506200366061012085016200342d565b90509250925092565b60008060a083850312156200367d57600080fd5b6200368984846200337f565b946080939093013593505050565b600060208284031215620036aa57600080fd5b5035919050565b600080600060c08486031215620036c757600080fd5b620036d385856200337f565b92506080840135620036e58162003560565b915060a0840135620034758162003560565b80151581146200209b57600080fd5b6000602082840312156200371957600080fd5b813562000ae581620036f7565b6000602082840312156200373957600080fd5b813562000ae5816200335c565b600080604083850312156200375a57600080fd5b823562003767816200335c565b9150602083013562003779816200335c565b809150509250929050565b8051620021a78162003560565b60008060408385031215620037a557600080fd5b8251620037b28162003560565b6020840151909250620037798162003560565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600081600f0b7fffffffffffffffffffffffffffffffff8000000000000000000000000000000081036200382c576200382c620037c5565b60000392915050565b8051620021a7816200335c565b6000602082840312156200385557600080fd5b815162000ae5816200335c565b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8203620038965762003896620037c5565b5060010190565b6fffffffffffffffffffffffffffffffff828116828216039080821115620038c957620038c9620037c5565b5092915050565b600060208284031215620038e357600080fd5b815162000ae581620036f7565b8051600281900b8114620021a757600080fd5b6000602082840312156200391657600080fd5b62000ae582620038f0565b6fffffffffffffffffffffffffffffffff818116838216019080821115620038c957620038c9620037c5565b600080604083850312156200396157600080fd5b505080516020909101519092909150565b6000825160005b8181101562003995576020818601810151858301520162003979565b506000920191825250919050565b805161ffff81168114620021a757600080fd5b60008060008060008060c08789031215620039d057600080fd5b8651620039dd816200335c565b9550620039ed60208801620038f0565b9450620039fd60408801620039a3565b9350606087015160ff8116811462003a1457600080fd5b925062003a2460808801620039a3565b915060a087015162003a3681620036f7565b809150509295509295509295565b60008060008060008060008060008060006101608c8e03121562003a6757600080fd5b8b516affffffffffffffffffffff8116811462003a8357600080fd5b60208d0151909b5062003a96816200335c565b60408d0151909a5062003aa9816200335c565b985062003ab960608d0162003835565b975062003ac960808d01620038f0565b965062003ad960a08d01620038f0565b955062003ae960c08d0162003784565b945060e08c015193506101008c0151925062003b096101208d0162003784565b915062003b1a6101408d0162003784565b90509295989b509295989b9093969950565b60006020828403121562003b3f57600080fd5b505191905056fe60c0604052600160075560016008553480156200001b57600080fd5b506040516200232838038062002328833981810160405260408110156200004157600080fd5b508051602090910151620000566000620000d2565b6001600160a01b03828116608052811660a0526004805462ffffff63ffffffff60c81b011916600160c81b4263ffffffff160262ffffff19161762f27618179055620000a6620d89e719620001c8565b6004805462ffffff9290921663010000000265ffffff0000001990921691909117905550620001f99050565b620d89e719620000e281620001c8565b620d89e7196000818152602085905260409020600101805465ffffffffffff60801b1916600160981b62ffffff9485160262ffffff60801b191617600160801b9490931693909302919091179091556200013c81620001c8565b8260006200014e620d89e719620001c8565b60020b60020b81526020019081526020016000206001016010846000620d89e7196200017a90620001c8565b60020b81526020810191909152604001600020600101805462ffffff948516600160981b0262ffffff60981b1990911617905581549383166101009190910a90810292021990921617905550565b60008160020b627fffff198103620001f057634e487b7160e01b600052601160045260246000fd5b60000392915050565b60805160a0516120fb6200022d6000396000818161044101526107e801526000818161028c015261132401526120fb6000f3fe608060405234801561001057600080fd5b50600436106101365760003560e01c80638e76c332116100b2578063d6b83ede11610081578063f0de822811610066578063f0de822814610463578063f30dba9314610495578063fddf08e51461054c57600080fd5b8063d6b83ede14610401578063ef01df4f1461043c57600080fd5b80638e76c332146102d7578063a88a5c1614610315578063ca16ca7e14610384578063d576dfc0146103bb57600080fd5b8063556ed30e116101095780636f4a2cd0116100ee5780636f4a2cd0146102485780637f463bb8146102505780638a2ade581461028757600080fd5b8063556ed30e1461020f5780635e075b531461023d57600080fd5b80630bd6f2001461013b57806334d335901461017e57806346caf2ae146101ba57806351b42b0014610205575b600080fd5b6101656004803603604081101561015157600080fd5b508035600290810b9160200135900b610583565b6040805192835260208301919091528051918290030190f35b6101a66004803603604081101561019457600080fd5b50803560020b906020013515156107ce565b604080519115158252519081900360200190f35b6004546101e090660100000000000090046fffffffffffffffffffffffffffffffff1681565b604080516fffffffffffffffffffffffffffffffff9092168252519081900360200190f35b61020d610c17565b005b6004546101a6907d010000000000000000000000000000000000000000000000000000000000900460ff1681565b600754600854610165565b61020d610c69565b61020d6004803603604081101561026657600080fd5b506fffffffffffffffffffffffffffffffff81358116916020013516610c7b565b6102ae7f000000000000000000000000000000000000000000000000000000000000000081565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b6004546102fe90760100000000000000000000000000000000000000000000900460020b81565b6040805160029290920b8252519081900360200190f35b6005546fffffffffffffffffffffffffffffffff808216917001000000000000000000000000000000009004165b60405180836fffffffffffffffffffffffffffffffff168152602001826fffffffffffffffffffffffffffffffff1681526020019250505060405180910390f35b61020d6004803603604081101561039a57600080fd5b506fffffffffffffffffffffffffffffffff81358116916020013516610cdc565b6004546103e890790100000000000000000000000000000000000000000000000000900463ffffffff1681565b6040805163ffffffff9092168252519081900360200190f35b61020d6004803603608081101561041757600080fd5b508035600290810b916020810135820b916040820135600f0b9160600135900b610cf4565b6102ae7f000000000000000000000000000000000000000000000000000000000000000081565b6006546fffffffffffffffffffffffffffffffff80821691700100000000000000000000000000000000900416610343565b610510600480360360208110156104ab57600080fd5b50600060208190529035600290810b8252604090912080546001820154828401546003909301549193600f82900b937001000000000000000000000000000000008304820b9373010000000000000000000000000000000000000090930490910b9186565b60408051968752600f9590950b6020870152600293840b868601529190920b6060850152608084019190915260a0830152519081900360c00190f35b61020d6004803603604081101561056257600080fd5b506fffffffffffffffffffffffffffffffff81358116916020013516610f0c565b600282810b600090815260208190526040812060010154909182917001000000000000000000000000000000008104820b73010000000000000000000000000000000000000090910490910b14806106205750600283810b6000908152602081905260409020600101547001000000000000000000000000000000008104820b73010000000000000000000000000000000000000090910490910b145b15610657576040517f0d6e094900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60045460075460085463ffffffff79010000000000000000000000000000000000000000000000000084048116420393760100000000000000000000000000000000000000000000900460020b9291908416156107af57600454660100000000000090046fffffffffffffffffffffffffffffffff1680156107ad5760055460065463ffffffff87166fffffffffffffffffffffffffffffffff8084168202811693700100000000000000000000000000000000908190048216909202811692818116929004168184111561072a578193505b80831115610736578092505b831561076f5761076a84700100000000000000000000000000000000876fffffffffffffffffffffffffffffffff16610f20565b870196505b82156107a8576107a383700100000000000000000000000000000000876fffffffffffffffffffffffffffffffff16610f20565b860195505b505050505b505b6107be60008989868686610fd8565b95509550505050505b9250929050565b60003373ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000161461083f576040517f545acb2400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6004546fffffffffffffffffffffffffffffffff6601000000000000820416907601000000000000000000000000000000000000000000008104600290810b9163ffffffff7901000000000000000000000000000000000000000000000000008204169160ff7d0100000000000000000000000000000000000000000000000000000000008304169180820b916301000000909104900b82156108eb5760009650505050505050610c11565b600285810b908a900b1380159061091e578260020b8a60020b12610919576001975050505050505050610c11565b61093c565b8160020b8a60020b121561093c576001975050505050505050610c11565b881515811515146109a0575050600480547fffff00ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff167d0100000000000000000000000000000000000000000000000000000000001790555060009450610c119350505050565b6109bc85886fffffffffffffffffffffffffffffffff16611076565b6007546008548a15610a8d575b600288900b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff2761814610a88578460020b8c60020b1215610b3a57600285810b600090815260208190526040812060038101805482850180548803905585039055600101547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff88019a50700100000000000000000000000000000000810490920b969550600f9190910b90610a80908b90839003611245565b9950506109c9565b610b3a565b6001610ab87ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff27618611fce565b610ac2919061200c565b60020b8860020b14610b3a578360020b8c60020b12610b3a57600284810b600090815260208190526040902060038101805482840180548703905584039055600101549498508895507301000000000000000000000000000000000000008504900b93600f0b610b328a82611245565b995050610a8d565b50506004805462ffffff9384166301000000027fffffffffffffffffffffffffffffffffffffffffffffffffffff000000000000858e16760100000000000000000000000000000000000000000000027fffffffffffffff000000ffffffffffffffffffffffffffffffffffffffffffff6fffffffffffffffffffffffffffffffff909c166601000000000000029b909b167fffffffffffffff00000000000000000000000000000000000000ffffffffffff90931692909217999099171693909216929092179590951790945550600193505050505b92915050565b610c1f61130c565b600480547fffff00ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff167d010000000000000000000000000000000000000000000000000000000000179055565b610c7161130c565b610c7961137b565b565b610c8361130c565b610c8b61137b565b6fffffffffffffffffffffffffffffffff9182169116700100000000000000000000000000000000027fffffffffffffffffffffffffffffffff000000000000000000000000000000001617600555565b610ce461130c565b610cf0600083836113c7565b5050565b610cfc61130c565b6004546fffffffffffffffffffffffffffffffff66010000000000008204169063ffffffff7901000000000000000000000000000000000000000000000000008204169060ff7d0100000000000000000000000000000000000000000000000000000000008204169063010000008104600290810b91900b82610dd557610d848682846114a7565b610dd557600480547fffff00ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff167d010000000000000000000000000000000000000000000000000000000000179055600192505b50508015610de557505050610f06565b600480547fffffffffffffff000000ffffffffffffffffffffffffffffffffffffffffffff1676010000000000000000000000000000000000000000000062ffffff87160217905563ffffffff82164263ffffffff161115610e5d57610e5d82846fffffffffffffffffffffffffffffffff16611076565b84600f0b600014610f02576000610e7788868860006114cc565b90506000610e8888878960016114cc565b9050610e95868a8a6114a7565b15610edd57610ea48588611245565b600460066101000a8154816fffffffffffffffffffffffffffffffff02191690836fffffffffffffffffffffffffffffffff1602179055505b8180610ee65750805b15610eff57610eff898984848a60008d600f0b126114f0565b50505b5050505b50505050565b610f1461130c565b610cf0600183836113c7565b6000838302817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff85870982811083820303915050808411610f6057600080fd5b80600003610f7357508290049050610fd1565b8385870960008581038616958690049560026003880281188089028203028089028203028089028203028089028203028089028203028089029091030291819003819004600101858411909403939093029190930391909104170290505b9392505050565b600285810b60009081526020889052604080822087840b8084529183209293849391929088900b121561104e578860020b8760020b1261102957816002015486039350816003015485039250611038565b81600201549350816003015492505b6002810154600382015494039390920391611069565b81600201548160020154039350816003015481600301540392505b5050965096945050505050565b63ffffffff4283900316600081900361108e57505050565b81156111f4576005546006546fffffffffffffffffffffffffffffffff8083168402927001000000000000000000000000000000009081900482168502928083169291900416818411156110f257816fffffffffffffffffffffffffffffffff1693505b806fffffffffffffffffffffffffffffffff1683111561112257806fffffffffffffffffffffffffffffffff1692505b838317156111ef576fffffffffffffffffffffffffffffffff91821684900391168290038315611172576111688470010000000000000000000000000000000088610f20565b6007805490910190555b821561119e576111948370010000000000000000000000000000000088610f20565b6008805490910190555b6fffffffffffffffffffffffffffffffff808316908216700100000000000000000000000000000000027fffffffffffffffffffffffffffffffff0000000000000000000000000000000016176006555b505050505b5050600480547fffffff00000000ffffffffffffffffffffffffffffffffffffffffffffffffff167901000000000000000000000000000000000000000000000000004263ffffffff160217905550565b60008082600f0b12156112a957508082016fffffffffffffffffffffffffffffffff808416908216106112a4576040517f1301f74800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610c11565b826fffffffffffffffffffffffffffffffff168284019150816fffffffffffffffffffffffffffffffff161015610c11576040517f997402f200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b3373ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001614610c79576040517fae74b17800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600454610c7990790100000000000000000000000000000000000000000000000000810463ffffffff1690660100000000000090046fffffffffffffffffffffffffffffffff16611076565b6113cf61137b565b6fffffffffffffffffffffffffffffffff82821716156114a2576006546fffffffffffffffffffffffffffffffff80821691700100000000000000000000000000000000900416841561143957611426848361204d565b9150611432838261204d565b9050611452565b611443848361207d565b915061144f838261207d565b90505b6fffffffffffffffffffffffffffffffff9182169116700100000000000000000000000000000000027fffffffffffffffffffffffffffffffff0000000000000000000000000000000016176006555b505050565b60008260020b8460020b121580156114c457508160020b8460020b125b949350505050565b6007546008546000916114e79183918891889188918861161f565b95945050505050565b600454600154600282810b9263010000009004900b9063ffffffff16828282891561152b576115238c898386868c611753565b919450925090505b88156115475761153f8b898386868c611753565b919450925090505b8260020b8660020b14158061156257508160020b8560020b14155b8061157957508363ffffffff168163ffffffff1614155b1561161157600180547fffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000001663ffffffff8316179055600480547fffffffffffffffffffffffffffffffffffffffffffffffffffff00000000000016630100000062ffffff858116919091027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000016919091179085161790555b505050505050505050505050565b600286900b600090815260208890526040812080548261163f8289611245565b6fffffffffffffffffffffffffffffffff1690506d09745258e83de0d0f4e400fce79981111561169b576040517f25b8364a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001830154600f0b856116bf5788600f0b81600f0b6116ba91906120a6565b6116d1565b88600f0b81600f0b6116d191906120ce565b6001850180547fffffffffffffffffffffffffffffffff00000000000000000000000000000000166fffffffffffffffffffffffffffffffff9290921691909117905581845581159450600083900361174457841594508960020b8b60020b136117445760038401879055600284018890555b50505050979650505050505050565b6000806000831561179c5760008061176b818c611854565b915091508a60020b8860020b0361178457819750611795565b8a60020b8760020b03611795578096505b5050611832565b6000808a60020b8860020b1280156117b957508a60020b8760020b135b156117e257508690508560028a810b908c900b13156117da578a9650611822565b8a9750611822565b6117f0600360028b8e611aca565b600281810b6000908152602081905260409020600101547001000000000000000000000000000000009004900b925090505b61182f60008c8484611ba7565b50505b6000611842600360028a8d611d53565b969a9599509597509395505050505050565b600281810b60008181526020859052604081206001810180548383557fffffffffffffffffffff0000000000000000000000000000000000000000000081169091558185018390556003909101919091557001000000000000000000000000000000008104830b92730100000000000000000000000000000000000000909104900b907ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff27618148061193157506119287ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff27618611fce565b60020b8360020b145b156119d657600283900b6000908152602085905260409020600101805462ffffff808516700100000000000000000000000000000000027fffffffffffffffffffffffffff000000ffffffffffffffffffffffffffffffff91851673010000000000000000000000000000000000000002919091167fffffffffffffffffffff000000000000ffffffffffffffffffffffffffffffff909216919091171790556107c7565b8060020b8260020b03611a15576040517f0d6e094900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600282810b6000908152602086905260408082206001908101805462ffffff808816730100000000000000000000000000000000000000027fffffffffffffffffffff000000ffffffffffffffffffffffffffffffffffffff909216919091179091559385900b83529120018054918416700100000000000000000000000000000000027fffffffffffffffffffffffffff000000ffffffffffffffffffffffffffffffff9092169190911790559250929050565b600190810190600090600883811d610d8a01901c90829061ffff83161b851663ffffffff1615611b2d57611afe8785611deb565b90945090925090508015611b135750506114c4565b611b2486610d8b840160010b611deb565b90945090925090505b80611b7057611b4b8563ffffffff168360010193508360010b611e1c565b909350905080611b635750620d89e891506114c49050565b611b6d8684611f73565b92505b611b9c877ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff2768501611f73565b979650505050505050565b600283900b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff276181480611c065750611bfd7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff27618611fce565b60020b8360020b145b610f06578260020b8260020b128015611c2457508260020b8160020b135b611c5a576040517fe45ac17d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600283810b60009081526020959095526040808620600190810180547fffffffffffffffffffff000000000000ffffffffffffffffffffffffffffffff1673010000000000000000000000000000000000000062ffffff87811682027fffffffffffffffffffffffffff000000ffffffffffffffffffffffffffffffff908116939093177001000000000000000000000000000000008a831681029190911790945597860b8a52848a20840180547fffffffffffffffffffff000000ffffffffffffffffffffffffffffffffffffff1698909916908102979097179097559390920b865290942090930180549092169202919091179055565b81600080611d908785600881901d600181810b60009081526020949094526040909320805460ff9093169390931b80831890935591811490151891565b915091508115611de157610d8a01600181810b60081d80820b6000908152602089905260409020805460ff9094169290921b808418909255821591909214818118935014611de1576001811b831892505b5050949350505050565b600881901d600181900b6000908152602084905260408120548190611e109085611e1c565b93969095509293505050565b60008060ff831684811c808303611e38578460ff179350611f6a565b7f555555555555555555555555555555555555555555555555555555555555555560008290038216908116156fffffffffffffffffffffffffffffffff82161560071b1777ffffffffffffffff0000000000000000ffffffffffffffff82161560061b177bffffffff00000000ffffffff00000000ffffffff00000000ffffffff82161560051b177dffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff82161560041b177eff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff82161560031b177f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f82161560021b177f33333333333333333333333333333333333333333333333333333333333333339091161560011b1760ff1685019350600192505b50509250929050565b600181900b600090815260208390526040902054600882901b90611f979082611e1c565b509392505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60008160020b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff800000810361200357612003611f9f565b60000392915050565b600282810b9082900b037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8000008112627fffff82131715610c1157610c11611f9f565b6fffffffffffffffffffffffffffffffff81811683821601908082111561207657612076611f9f565b5092915050565b6fffffffffffffffffffffffffffffffff82811682821603908082111561207657612076611f9f565b80820182811260008312801582168215821617156120c6576120c6611f9f565b505092915050565b818103600083128015838313168383128216171561207657612076611f9f56fea164736f6c6343000814000aa164736f6c6343000814000a000000000000000000000000f03875b5ec5eac83cab83a6c2ab17844304aa7a00000000000000000000000001c4cbb62e18cf9c137c5d85096b5bc7819082691
Deployed Bytecode
0x60806040523480156200001157600080fd5b5060043610620001ad5760003560e01c80638433524111620000f5578063dd56e5d81162000097578063f2256319116200006e578063f225631914620005d1578063f26ebf7a14620005f7578063f6de3cae146200060e57600080fd5b8063dd56e5d8146200056b578063df42efda146200058c578063e70b9e2714620005a357600080fd5b8063b44a272211620000cc578063b44a272214620004f3578063b5bae00a146200051b578063b8883c50146200054357600080fd5b80638433524114620004ae578063890cdcb314620004c557806396da9bd514620004dc57600080fd5b806336808b19116200015f5780635739f0b911620001365780635739f0b9146200037657806360777795146200038d57806382bd79ea14620004a457600080fd5b806336808b1914620002fa5780633c6d07151462000311578063547b6da9146200033957600080fd5b806327e6a99a116200019457806327e6a99a14620002095780632912bf1014620002ca5780632f2d783d14620002e357600080fd5b8063046ec16614620001b25780630a53075414620001e3575b600080fd5b620001c9620001c33660046200343a565b62000625565b604080519283526020830191909152015b60405180910390f35b620001fa620001f436600462003480565b620007dc565b604051908152602001620001da565b620002886200021a366004620034d8565b6002602081815260009384526040808520909152918352912080546001820154918301546fffffffffffffffffffffffffffffffff8216937001000000000000000000000000000000008304810b93730100000000000000000000000000000000000000909304900b919085565b604080516fffffffffffffffffffffffffffffffff9096168652600294850b60208701529290930b918401919091526060830152608082015260a001620001da565b620002e1620002db366004620034fb565b620007ff565b005b620001fa620002f43660046200351a565b62000ad2565b620002e16200030b3660046200343a565b62000aec565b620001fa7f681ab0361ab5f3ae8c1d864335ef2b9a8c12a6a67e1ed0f4083d00a4b8a9a39581565b620003506200034a3660046200357f565b62000c94565b60405173ffffffffffffffffffffffffffffffffffffffff9091168152602001620001da565b620002e16200038736600462003669565b62001259565b620004406200039e36600462003697565b60016020819052600091825260409091208054918101546002909101546fffffffffffffffffffffffffffffffff808416937001000000000000000000000000000000009004169173ffffffffffffffffffffffffffffffffffffffff8082169274010000000000000000000000000000000000000000830462ffffff169277010000000000000000000000000000000000000000000000900460ff16911686565b604080516fffffffffffffffffffffffffffffffff978816815296909516602087015273ffffffffffffffffffffffffffffffffffffffff9384169486019490945262ffffff9091166060850152151560808401521660a082015260c001620001da565b620001fa60035481565b620002e1620004bf366004620036b1565b62001455565b620002e1620004d636600462003706565b62001526565b620001c9620004ed36600462003669565b620015f6565b620003507f0000000000000000000000001c4cbb62e18cf9c137c5d85096b5bc781908269181565b620005326200052c36600462003697565b62001654565b6040519015158152602001620001da565b620001fa7fa777c10270ee0b99d2c737c09ff865ed48064b252418bbd31d39c8b88ea1221981565b600054620003509073ffffffffffffffffffffffffffffffffffffffff1681565b620002e16200059d36600462003726565b62001673565b620001fa620005b436600462003746565b600460209081526000928352604080842090915290825290205481565b600054620005329074010000000000000000000000000000000000000000900460ff1681565b620002e162000608366004620036b1565b62001734565b620002e16200061f366004620036b1565b620017e0565b6000806200063262001b7c565b600080620006408762001ba3565b91509150600062000652878462001c7d565b600183015490915073ffffffffffffffffffffffffffffffffffffffff166200067b8162001d6c565b6000806200068a838562001dd1565b809450819550829a50839b50505050506000600260008c8152602001908152602001600020600088815260200190815260200160002090508281600101819055508181600201819055506000600460008c73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000209050896000146200074d578c5173ffffffffffffffffffffffffffffffffffffffff16600090815260208290526040902080548b0190555b881562000784576020808e015173ffffffffffffffffffffffffffffffffffffffff166000908152908290526040902080548a0190555b604080518d8152602081018a90529081018b9052606081018a90527f15b2e0f32b50efdbbdee9ec7884ed3c61e6209b1b395e5762011a6734b86f7b59060800160405180910390a15050505050505050935093915050565b6000620007e862001b7c565b620007f68585858562001e74565b95945050505050565b6200082a7fa777c10270ee0b99d2c737c09ff865ed48064b252418bbd31d39c8b88ea1221962001fd9565b600080620008388362001ba3565b6001810154919350915077010000000000000000000000000000000000000000000000900460ff161562000898576040517f260e553a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60018101805460028301547fffffffffffffffff00ffffffffffffffffffffffffffffffffffffffffffffff82167701000000000000000000000000000000000000000000000017909255604080517f51b42b00000000000000000000000000000000000000000000000000000000008152905173ffffffffffffffffffffffffffffffffffffffff928316939092169183916351b42b0091600480830192600092919082900301818387803b1580156200095257600080fd5b505af115801562000967573d6000803e3d6000fd5b505050506000808373ffffffffffffffffffffffffffffffffffffffff1663a88a5c166040518163ffffffff1660e01b81526004016040805180830381865afa158015620009b9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620009df919062003791565b915091508082176fffffffffffffffffffffffffffffffff1660001462000a0f5762000a0f84600080896200209e565b6000546040517f2bd34c4800000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8681166004830152858116602483015290911690632bd34c4890604401600060405180830381600087803b15801562000a8557600080fd5b505af115801562000a9a573d6000803e3d6000fd5b50506040518892507f907b91fb061b1c46367da11a5a0e8b2c0bd5fecd22eb92967e626cffa5ef63869150600090a250505050505050565b600062000ae28433858562001e74565b90505b9392505050565b62000af662001b7c565b600062000b688460408051825173ffffffffffffffffffffffffffffffffffffffff90811660208084019190915284015181168284015291830151909116606080830191909152820151608082015260009060a001604051602081830303815290604052805190602001209050919050565b9050600062000b78848362001c7d565b9050600080600060149054906101000a900460ff1662000bd25762000bcc8388868862000bbb88600001516fffffffffffffffffffffffffffffffff1662002195565b62000bc690620037f4565b620021ac565b90925090505b6000868152600260208181526040808420888552825280842080547fffffffffffffffffffff000000000000000000000000000000000000000000001681556001810185905590920192909255885189830151825173ffffffffffffffffffffffffffffffffffffffff918216815289821694810194909452918301859052606083018490521690859088907f7f2557bb15dcf63e3d029ef1dcb4333563fcd78edf263b8fe42ed3adb925ff849060800160405180910390a450505050505050565b600062000cc17fa777c10270ee0b99d2c737c09ff865ed48064b252418bbd31d39c8b88ea1221962001fd9565b6000846040015173ffffffffffffffffffffffffffffffffffffffff1663ef01df4f6040518163ffffffff1660e01b8152600401602060405180830381865afa15801562000d13573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000d39919062003842565b90508273ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614158062000d8b575073ffffffffffffffffffffffffffffffffffffffff8116155b1562000dc3576040517f093d6f1700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16631d4632ac6040518163ffffffff1660e01b8152600401602060405180830381865afa15801562000e27573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000e4d919062003842565b73ffffffffffffffffffffffffffffffffffffffff161462000e9b576040517f47146bcc00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b308160405162000eab90620032fd565b73ffffffffffffffffffffffffffffffffffffffff928316815291166020820152604001604051809103906000f08015801562000eec573d6000803e3d6000fd5b506000546040517fd68516bc00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8084166004830152848116602483015292945091169063d68516bc90604401600060405180830381600087803b15801562000f6557600080fd5b505af115801562000f7a573d6000803e3d6000fd5b50506003805492509050600062000f918362003862565b90915550606086015260006200100c8660408051825173ffffffffffffffffffffffffffffffffffffffff90811660208084019190915284015181168284015291830151909116606080830191909152820151608082015260009060a001604051602081830303815290604052805190602001209050919050565b60008181526001602090815260409091208751918801519293509162001035918991846200234a565b6fffffffffffffffffffffffffffffffff9081166020890152168087526000036200108c576040517f36ab0f6a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6080860151621b13d062ffffff9091161315620010d5576040517f1db9891100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600181018054608088015162ffffff811674010000000000000000000000000000000000000000027fffffffffffffffffff000000000000000000000000000000000000000000000090921673ffffffffffffffffffffffffffffffffffffffff80891691909117929092179092556002830180548683167fffffffffffffffffffffffff0000000000000000000000000000000000000000919091161790556040808a01516020808c01518c5160608e01518d51938e01519551948716979287169691909116947fcef9468c62cd8a6eca3a887fc30674c037943e423de07ab3a122bdf2f73c77e1946200121b948d9490929173ffffffffffffffffffffffffffffffffffffffff95909516855260208501939093526fffffffffffffffffffffffffffffffff918216604085015216606083015262ffffff16608082015260a00190565b60405180910390a4620012398487600001518860200151856200251c565b6200124f8487604001518860600151856200209e565b5050509392505050565b6200126362001b7c565b60005474010000000000000000000000000000000000000000900460ff1615620012b9576040517f05bfeb5900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000806000806000620012cd87876200260a565b93985091965094509250905080600080620012ea83888862002893565b915091506040518060a00160405280866fffffffffffffffffffffffffffffffff1681526020018860020b81526020018760020b815260200183815260200182815250600260008b815260200190815260200160002060008a815260200190815260200160002060008201518160000160006101000a8154816fffffffffffffffffffffffffffffffff02191690836fffffffffffffffffffffffffffffffff16021790555060208201518160000160106101000a81548162ffffff021916908360020b62ffffff16021790555060408201518160000160136101000a81548162ffffff021916908360020b62ffffff160217905550606082015181600101556080820151816002015590505087897f19bc21617a8d86ff19202ac9541480a99b9ae5fbd573a23f14f479af784392c4876040516200144191906fffffffffffffffffffffffffffffffff91909116815260200190565b60405180910390a350505050505050505050565b620014807fa777c10270ee0b99d2c737c09ff865ed48064b252418bbd31d39c8b88ea1221962001fd9565b6000806200148e8562001ba3565b6001810154919350915073ffffffffffffffffffffffffffffffffffffffff166fffffffffffffffffffffffffffffffff8585171615801590620014d85750620014d88262002940565b1562001510576040517f260e553a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6200151e818686866200209e565b505050505050565b620015517f681ab0361ab5f3ae8c1d864335ef2b9a8c12a6a67e1ed0f4083d00a4b8a9a39562001fd9565b801515600060149054906101000a900460ff161515036200157157600080fd5b6000805482151574010000000000000000000000000000000000000000027fffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffff9091161790556040517fee20b3d336390a4b077dbc7d702bf6e35a954bc96106f37b9e5ef08a1d0ce05990620015eb90831515815260200190565b60405180910390a150565b600080600080620016078662001ba3565b91509150600062001619868462001c7d565b600183015490915073ffffffffffffffffffffffffffffffffffffffff1662001643818362001dd1565b50919a909950975050505050505050565b60008181526001602052604081206200166d9062002940565b92915050565b6200169e7f681ab0361ab5f3ae8c1d864335ef2b9a8c12a6a67e1ed0f4083d00a4b8a9a39562001fd9565b60005473ffffffffffffffffffffffffffffffffffffffff90811690821603620016c757600080fd5b600080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff8316908117825560405190917f29f9e1ebeee07596f3165f3e42cb9d4d8d22b0481e968d6c74be3dd037c15d9b91a250565b600080620017428562001ba3565b91509150620017518162002940565b1562001789576040517f260e553a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600181015473ffffffffffffffffffffffffffffffffffffffff16620017b2868686856200234a565b90955093506fffffffffffffffffffffffffffffffff85851716156200151e576200151e818686866200251c565b6200180b7f681ab0361ab5f3ae8c1d864335ef2b9a8c12a6a67e1ed0f4083d00a4b8a9a39562001fd9565b600080620018198562001ba3565b6001810154919350915073ffffffffffffffffffffffffffffffffffffffff16620018448162001d6c565b6000808273ffffffffffffffffffffffffffffffffffffffff1663f0de82286040518163ffffffff1660e01b81526004016040805180830381865afa15801562001892573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620018b8919062003791565b91509150816fffffffffffffffffffffffffffffffff16876fffffffffffffffffffffffffffffffff161115620018ed578196505b83546fffffffffffffffffffffffffffffffff90811690881610620019315783546200192e906001906fffffffffffffffffffffffffffffffff166200389d565b96505b8354620019529088906fffffffffffffffffffffffffffffffff166200389d565b84547fffffffffffffffffffffffffffffffff00000000000000000000000000000000166fffffffffffffffffffffffffffffffff91821617855581811690871611156200199e578095505b8354620019d390879070010000000000000000000000000000000090046fffffffffffffffffffffffffffffffff166200389d565b84546fffffffffffffffffffffffffffffffff9182167001000000000000000000000000000000000291161784556040517fca16ca7e00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff84169063ca16ca7e9062001a74908a908a906004016fffffffffffffffffffffffffffffffff92831681529116602082015260400190565b600060405180830381600087803b15801562001a8f57600080fd5b505af115801562001aa4573d6000803e3d6000fd5b505050506fffffffffffffffffffffffffffffffff87161562001ae257875162001ae290336fffffffffffffffffffffffffffffffff8a16620029f6565b6fffffffffffffffffffffffffffffffff86161562001b1e5762001b1e886020015133886fffffffffffffffffffffffffffffffff16620029f6565b604080516fffffffffffffffffffffffffffffffff808a168252881660208201529081018690527f808ecc37f6d601dde1e43c133bee66af0ff9409b53aca0eb0d4f6c65fb8956e89060600160405180910390a15050505050505050565b60005473ffffffffffffffffffffffffffffffffffffffff16331462001ba157600080fd5b565b60008062001c168360408051825173ffffffffffffffffffffffffffffffffffffffff90811660208084019190915284015181168284015291830151909116606080830191909152820151608082015260009060a001604051602081830303815290604052805190602001209050919050565b6000818152600160205260408120805492945092506fffffffffffffffffffffffffffffffff909116900362001c78576040517fe4c8229200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b915091565b6040805160a0810182526000808252602082018190529181018290526060810182905260808101919091525060008281526002602081815260408084208585528252808420815160a08101835281546fffffffffffffffffffffffffffffffff81168083527001000000000000000000000000000000008204870b958301959095527301000000000000000000000000000000000000009004850b92810192909252600181015460608301529092015460808301529091036200166d576040517f7aa92c6600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff16636f4a2cd06040518163ffffffff1660e01b8152600401600060405180830381600087803b15801562001db557600080fd5b505af115801562001dca573d6000803e3d6000fd5b5050505050565b60008060008062001dec868660200151876040015162002893565b6060870151875192945090925062001e2c91908403906fffffffffffffffffffffffffffffffff1670010000000000000000000000000000000062002b6d565b62001e668660800151830387600001516fffffffffffffffffffffffffffffffff1670010000000000000000000000000000000062002b6d565b909790965091945092509050565b600073ffffffffffffffffffffffffffffffffffffffff831662001ec4576040517fabd1763600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5073ffffffffffffffffffffffffffffffffffffffff80841660009081526004602090815260408083209388168352908390529020549082158062001f0857508183115b1562001f12578192505b821562001fd05773ffffffffffffffffffffffffffffffffffffffff86166000908152602082905260409020838303905562001f50868585620029f6565b8473ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff167fe6ac6a784fb43c9f6329d2f5c82f88a26a93bad4281f7780725af5f071f0aafa8660405162001fc791815260200190565b60405180910390a45b50949350505050565b6040517fe8ae2b69000000000000000000000000000000000000000000000000000000008152600481018290523360248201527f0000000000000000000000004eb881885fe22d895ff299f6cda6e0a8e00e66a073ffffffffffffffffffffffffffffffffffffffff169063e8ae2b6990604401602060405180830381865afa1580156200206b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620020919190620038d0565b6200209b57600080fd5b50565b6040517f7f463bb80000000000000000000000000000000000000000000000000000000081526fffffffffffffffffffffffffffffffff80851660048301528316602482015273ffffffffffffffffffffffffffffffffffffffff851690637f463bb890604401600060405180830381600087803b1580156200212057600080fd5b505af115801562002135573d6000803e3d6000fd5b5050604080516fffffffffffffffffffffffffffffffff8088168252861660208201529081018490527f1864e4cc903d98e44820faebd48409c410a2ad20adb3173984ba41ae2828805e925060600190505b60405180910390a150505050565b80600f81900b8114620021a757600080fd5b919050565b600083815260016020819052604082209081015482919073ffffffffffffffffffffffffffffffffffffffff1682620021e58362002940565b620021ff57620021f9896040015162002c27565b62002271565b8173ffffffffffffffffffffffffffffffffffffffff16638e76c3326040518163ffffffff1660e01b8152600401602060405180830381865afa1580156200224b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062002271919062003903565b90506200227e8262001d6c565b6200228a828b62001dd1565b9050508095508196505050620022ac828b602001518c60400151898562002ce6565b73ffffffffffffffffffffffffffffffffffffffff8716600090815260046020526040902085156200230557895173ffffffffffffffffffffffffffffffffffffffff1660009081526020829052604090208054870190555b84156200233c576020808b015173ffffffffffffffffffffffffffffffffffffffff16600090815290829052604090208054860190555b505050509550959350505050565b6000805481907501000000000000000000000000000000000000000000900460ff16620023a3576040517f2446d79f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600080547fffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffffff1690556fffffffffffffffffffffffffffffffff851615620023f5578551620023f2908662002d8c565b91505b6fffffffffffffffffffffffffffffffff84161562002421576200241e86602001518562002d8c565b90505b600080547fffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffffff16750100000000000000000000000000000000000000000017905582546fffffffffffffffffffffffffffffffff8082169170010000000000000000000000000000000090041662002499848362003921565b85547fffffffffffffffffffffffffffffffff00000000000000000000000000000000166fffffffffffffffffffffffffffffffff91909116178555620024e1838262003921565b85546fffffffffffffffffffffffffffffffff9182167001000000000000000000000000000000000291161790945550909590945092505050565b6040517ffddf08e50000000000000000000000000000000000000000000000000000000081526fffffffffffffffffffffffffffffffff80851660048301528316602482015273ffffffffffffffffffffffffffffffffffffffff85169063fddf08e590604401600060405180830381600087803b1580156200259e57600080fd5b505af1158015620025b3573d6000803e3d6000fd5b5050604080516fffffffffffffffffffffffffffffffff8088168252861660208201529081018490527f8b0312d8047895ce795779b66b705ccd39b1ece7c162f642c72d76a785d1b68a9250606001905062002187565b6000806000806000806200261e8862001ba3565b600089815260026020908152604080832085845290915290205491975091506fffffffffffffffffffffffffffffffff161562002687576040517ff352b37500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600181015473ffffffffffffffffffffffffffffffffffffffff8116925074010000000000000000000000000000000000000000900462ffffff16620026cd8262002940565b1562002705576040517f260e553a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000620027547f000000000000000000000000f03875b5ec5eac83cab83a6c2ab17844304aa7a07f0000000000000000000000001c4cbb62e18cf9c137c5d85096b5bc78190826918b62002e26565b60408e0151929a50909850965090915073ffffffffffffffffffffffffffffffffffffffff808316911614620027b6576040517fdce2809300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b846fffffffffffffffffffffffffffffffff1660000362002803576040517f4eed436000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8162ffffff168760020b8760020b0312156200284b576040517feab0585000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000620028588262002c27565b9050620028858589896200287e8a6fffffffffffffffffffffffffffffffff1662002195565b8562002ce6565b505050509295509295909350565b6040517f0bd6f200000000000000000000000000000000000000000000000000000000008152600283810b600483015282900b6024820152600090819073ffffffffffffffffffffffffffffffffffffffff861690630bd6f200906044016040805180830381865afa1580156200290e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200293491906200394d565b91509150935093915050565b600181015460009073ffffffffffffffffffffffffffffffffffffffff81169077010000000000000000000000000000000000000000000000900460ff168062000ae5578173ffffffffffffffffffffffffffffffffffffffff1663556ed30e6040518163ffffffff1660e01b8152600401602060405180830381865afa158015620029d0573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000ae29190620038d0565b6040805173ffffffffffffffffffffffffffffffffffffffff8481166024830152604480830185905283518084039091018152606490920183526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fa9059cbb00000000000000000000000000000000000000000000000000000000179052915160009283929087169162002a8f919062003972565b6000604051808303816000865af19150503d806000811462002ace576040519150601f19603f3d011682016040523d82523d6000602084013e62002ad3565b606091505b509150915081801562002b0157508051158062002b0157508080602001905181019062002b019190620038d0565b62001dca576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600260248201527f535400000000000000000000000000000000000000000000000000000000000060448201526064015b60405180910390fd5b6000838302817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8587098281108382030391505080841162002bae57600080fd5b8060000362002bc35750829004905062000ae5565b8385870960008581038616958690049560026003880281188089028203028089028203028089028203028089028203028089028203028089029091030291819003819004600101858411909403939093029190930391909104170290509392505050565b6000808273ffffffffffffffffffffffffffffffffffffffff1663e76c01e46040518163ffffffff1660e01b815260040160c060405180830381865afa15801562002c76573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062002c9c9190620039b6565b93965092945084935062002ce092505050576040517f9ded0f5700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b50919050565b6040517fd6b83ede000000000000000000000000000000000000000000000000000000008152600285810b600483015284810b6024830152600f84900b604483015282900b606482015273ffffffffffffffffffffffffffffffffffffffff86169063d6b83ede90608401600060405180830381600087803b15801562002d6c57600080fd5b505af115801562002d81573d6000803e3d6000fd5b505050505050505050565b60008062002d9a8462002f0c565b905062002dbc843330866fffffffffffffffffffffffffffffffff1662002fa0565b600062002dc98562002f0c565b905081811162002dd857600080fd5b8181036fffffffffffffffffffffffffffffffff811115620007f6576040517f3ba11f1e00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000806000806000808773ffffffffffffffffffffffffffffffffffffffff166399fbab88886040518263ffffffff1660e01b815260040162002e6b91815260200190565b61016060405180830381865afa15801562002e8a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062002eb0919062003a44565b50506040805180820190915273ffffffffffffffffffffffffffffffffffffffff808916825287166020820152949d50929b5090995093975091955062002eff94508d935091506200311b9050565b9550505093509350935093565b6040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015260009073ffffffffffffffffffffffffffffffffffffffff8316906370a0823190602401602060405180830381865afa15801562002f7a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200166d919062003b2c565b6040805173ffffffffffffffffffffffffffffffffffffffff85811660248301528481166044830152606480830185905283518084039091018152608490920183526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f23b872dd00000000000000000000000000000000000000000000000000000000179052915160009283929088169162003041919062003972565b6000604051808303816000865af19150503d806000811462003080576040519150601f19603f3d011682016040523d82523d6000602084013e62003085565b606091505b5091509150818015620030b3575080511580620030b3575080806020019051810190620030b39190620038d0565b6200151e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600360248201527f5354460000000000000000000000000000000000000000000000000000000000604482015260640162002b64565b6000816020015173ffffffffffffffffffffffffffffffffffffffff16826000015173ffffffffffffffffffffffffffffffffffffffff1610620031bc576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601760248201527f496e76616c6964206f72646572206f6620746f6b656e73000000000000000000604482015260640162002b64565b8282600001518360200151604051602001620031fb92919073ffffffffffffffffffffffffffffffffffffffff92831681529116602082015260400190565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0818403018152908290528051602091820120620032c0939290917ff96d2474815c32e070cd63233f06af5413efc5dcb430aee4ff18cc29007c562d91017fff00000000000000000000000000000000000000000000000000000000000000815260609390931b7fffffffffffffffffffffffffffffffffffffffff0000000000000000000000001660018401526015830191909152603582015260550190565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe081840301815291905280516020909101209392505050565b6123288062003b4783390190565b60405160a0810167ffffffffffffffff8111828210171562003356577f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b60405290565b73ffffffffffffffffffffffffffffffffffffffff811681146200209b57600080fd5b6000608082840312156200339257600080fd5b6040516080810181811067ffffffffffffffff82111715620033dd577f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6040529050808235620033f0816200335c565b8152602083013562003402816200335c565b6020820152604083013562003417816200335c565b6040820152606092830135920191909152919050565b8035620021a7816200335c565b600080600060c084860312156200345057600080fd5b6200345c85856200337f565b92506080840135915060a084013562003475816200335c565b809150509250925092565b600080600080608085870312156200349757600080fd5b8435620034a4816200335c565b93506020850135620034b6816200335c565b92506040850135620034c8816200335c565b9396929550929360600135925050565b60008060408385031215620034ec57600080fd5b50508035926020909101359150565b6000608082840312156200350e57600080fd5b62000ae583836200337f565b6000806000606084860312156200353057600080fd5b83356200353d816200335c565b925060208401356200354f816200335c565b929592945050506040919091013590565b6fffffffffffffffffffffffffffffffff811681146200209b57600080fd5b60008060008385036101408112156200359757600080fd5b620035a386866200337f565b935060a07fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8082011215620035d657600080fd5b50620035e16200330b565b6080850135620035f18162003560565b815260a0850135620036038162003560565b602082015260c0850135620036188162003560565b604082015260e08501356200362d8162003560565b606082015261010085013562ffffff811681146200364a57600080fd5b608082015291506200366061012085016200342d565b90509250925092565b60008060a083850312156200367d57600080fd5b6200368984846200337f565b946080939093013593505050565b600060208284031215620036aa57600080fd5b5035919050565b600080600060c08486031215620036c757600080fd5b620036d385856200337f565b92506080840135620036e58162003560565b915060a0840135620034758162003560565b80151581146200209b57600080fd5b6000602082840312156200371957600080fd5b813562000ae581620036f7565b6000602082840312156200373957600080fd5b813562000ae5816200335c565b600080604083850312156200375a57600080fd5b823562003767816200335c565b9150602083013562003779816200335c565b809150509250929050565b8051620021a78162003560565b60008060408385031215620037a557600080fd5b8251620037b28162003560565b6020840151909250620037798162003560565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600081600f0b7fffffffffffffffffffffffffffffffff8000000000000000000000000000000081036200382c576200382c620037c5565b60000392915050565b8051620021a7816200335c565b6000602082840312156200385557600080fd5b815162000ae5816200335c565b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8203620038965762003896620037c5565b5060010190565b6fffffffffffffffffffffffffffffffff828116828216039080821115620038c957620038c9620037c5565b5092915050565b600060208284031215620038e357600080fd5b815162000ae581620036f7565b8051600281900b8114620021a757600080fd5b6000602082840312156200391657600080fd5b62000ae582620038f0565b6fffffffffffffffffffffffffffffffff818116838216019080821115620038c957620038c9620037c5565b600080604083850312156200396157600080fd5b505080516020909101519092909150565b6000825160005b8181101562003995576020818601810151858301520162003979565b506000920191825250919050565b805161ffff81168114620021a757600080fd5b60008060008060008060c08789031215620039d057600080fd5b8651620039dd816200335c565b9550620039ed60208801620038f0565b9450620039fd60408801620039a3565b9350606087015160ff8116811462003a1457600080fd5b925062003a2460808801620039a3565b915060a087015162003a3681620036f7565b809150509295509295509295565b60008060008060008060008060008060006101608c8e03121562003a6757600080fd5b8b516affffffffffffffffffffff8116811462003a8357600080fd5b60208d0151909b5062003a96816200335c565b60408d0151909a5062003aa9816200335c565b985062003ab960608d0162003835565b975062003ac960808d01620038f0565b965062003ad960a08d01620038f0565b955062003ae960c08d0162003784565b945060e08c015193506101008c0151925062003b096101208d0162003784565b915062003b1a6101408d0162003784565b90509295989b509295989b9093969950565b60006020828403121562003b3f57600080fd5b505191905056fe60c0604052600160075560016008553480156200001b57600080fd5b506040516200232838038062002328833981810160405260408110156200004157600080fd5b508051602090910151620000566000620000d2565b6001600160a01b03828116608052811660a0526004805462ffffff63ffffffff60c81b011916600160c81b4263ffffffff160262ffffff19161762f27618179055620000a6620d89e719620001c8565b6004805462ffffff9290921663010000000265ffffff0000001990921691909117905550620001f99050565b620d89e719620000e281620001c8565b620d89e7196000818152602085905260409020600101805465ffffffffffff60801b1916600160981b62ffffff9485160262ffffff60801b191617600160801b9490931693909302919091179091556200013c81620001c8565b8260006200014e620d89e719620001c8565b60020b60020b81526020019081526020016000206001016010846000620d89e7196200017a90620001c8565b60020b81526020810191909152604001600020600101805462ffffff948516600160981b0262ffffff60981b1990911617905581549383166101009190910a90810292021990921617905550565b60008160020b627fffff198103620001f057634e487b7160e01b600052601160045260246000fd5b60000392915050565b60805160a0516120fb6200022d6000396000818161044101526107e801526000818161028c015261132401526120fb6000f3fe608060405234801561001057600080fd5b50600436106101365760003560e01c80638e76c332116100b2578063d6b83ede11610081578063f0de822811610066578063f0de822814610463578063f30dba9314610495578063fddf08e51461054c57600080fd5b8063d6b83ede14610401578063ef01df4f1461043c57600080fd5b80638e76c332146102d7578063a88a5c1614610315578063ca16ca7e14610384578063d576dfc0146103bb57600080fd5b8063556ed30e116101095780636f4a2cd0116100ee5780636f4a2cd0146102485780637f463bb8146102505780638a2ade581461028757600080fd5b8063556ed30e1461020f5780635e075b531461023d57600080fd5b80630bd6f2001461013b57806334d335901461017e57806346caf2ae146101ba57806351b42b0014610205575b600080fd5b6101656004803603604081101561015157600080fd5b508035600290810b9160200135900b610583565b6040805192835260208301919091528051918290030190f35b6101a66004803603604081101561019457600080fd5b50803560020b906020013515156107ce565b604080519115158252519081900360200190f35b6004546101e090660100000000000090046fffffffffffffffffffffffffffffffff1681565b604080516fffffffffffffffffffffffffffffffff9092168252519081900360200190f35b61020d610c17565b005b6004546101a6907d010000000000000000000000000000000000000000000000000000000000900460ff1681565b600754600854610165565b61020d610c69565b61020d6004803603604081101561026657600080fd5b506fffffffffffffffffffffffffffffffff81358116916020013516610c7b565b6102ae7f000000000000000000000000000000000000000000000000000000000000000081565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b6004546102fe90760100000000000000000000000000000000000000000000900460020b81565b6040805160029290920b8252519081900360200190f35b6005546fffffffffffffffffffffffffffffffff808216917001000000000000000000000000000000009004165b60405180836fffffffffffffffffffffffffffffffff168152602001826fffffffffffffffffffffffffffffffff1681526020019250505060405180910390f35b61020d6004803603604081101561039a57600080fd5b506fffffffffffffffffffffffffffffffff81358116916020013516610cdc565b6004546103e890790100000000000000000000000000000000000000000000000000900463ffffffff1681565b6040805163ffffffff9092168252519081900360200190f35b61020d6004803603608081101561041757600080fd5b508035600290810b916020810135820b916040820135600f0b9160600135900b610cf4565b6102ae7f000000000000000000000000000000000000000000000000000000000000000081565b6006546fffffffffffffffffffffffffffffffff80821691700100000000000000000000000000000000900416610343565b610510600480360360208110156104ab57600080fd5b50600060208190529035600290810b8252604090912080546001820154828401546003909301549193600f82900b937001000000000000000000000000000000008304820b9373010000000000000000000000000000000000000090930490910b9186565b60408051968752600f9590950b6020870152600293840b868601529190920b6060850152608084019190915260a0830152519081900360c00190f35b61020d6004803603604081101561056257600080fd5b506fffffffffffffffffffffffffffffffff81358116916020013516610f0c565b600282810b600090815260208190526040812060010154909182917001000000000000000000000000000000008104820b73010000000000000000000000000000000000000090910490910b14806106205750600283810b6000908152602081905260409020600101547001000000000000000000000000000000008104820b73010000000000000000000000000000000000000090910490910b145b15610657576040517f0d6e094900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60045460075460085463ffffffff79010000000000000000000000000000000000000000000000000084048116420393760100000000000000000000000000000000000000000000900460020b9291908416156107af57600454660100000000000090046fffffffffffffffffffffffffffffffff1680156107ad5760055460065463ffffffff87166fffffffffffffffffffffffffffffffff8084168202811693700100000000000000000000000000000000908190048216909202811692818116929004168184111561072a578193505b80831115610736578092505b831561076f5761076a84700100000000000000000000000000000000876fffffffffffffffffffffffffffffffff16610f20565b870196505b82156107a8576107a383700100000000000000000000000000000000876fffffffffffffffffffffffffffffffff16610f20565b860195505b505050505b505b6107be60008989868686610fd8565b95509550505050505b9250929050565b60003373ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000161461083f576040517f545acb2400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6004546fffffffffffffffffffffffffffffffff6601000000000000820416907601000000000000000000000000000000000000000000008104600290810b9163ffffffff7901000000000000000000000000000000000000000000000000008204169160ff7d0100000000000000000000000000000000000000000000000000000000008304169180820b916301000000909104900b82156108eb5760009650505050505050610c11565b600285810b908a900b1380159061091e578260020b8a60020b12610919576001975050505050505050610c11565b61093c565b8160020b8a60020b121561093c576001975050505050505050610c11565b881515811515146109a0575050600480547fffff00ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff167d0100000000000000000000000000000000000000000000000000000000001790555060009450610c119350505050565b6109bc85886fffffffffffffffffffffffffffffffff16611076565b6007546008548a15610a8d575b600288900b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff2761814610a88578460020b8c60020b1215610b3a57600285810b600090815260208190526040812060038101805482850180548803905585039055600101547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff88019a50700100000000000000000000000000000000810490920b969550600f9190910b90610a80908b90839003611245565b9950506109c9565b610b3a565b6001610ab87ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff27618611fce565b610ac2919061200c565b60020b8860020b14610b3a578360020b8c60020b12610b3a57600284810b600090815260208190526040902060038101805482840180548703905584039055600101549498508895507301000000000000000000000000000000000000008504900b93600f0b610b328a82611245565b995050610a8d565b50506004805462ffffff9384166301000000027fffffffffffffffffffffffffffffffffffffffffffffffffffff000000000000858e16760100000000000000000000000000000000000000000000027fffffffffffffff000000ffffffffffffffffffffffffffffffffffffffffffff6fffffffffffffffffffffffffffffffff909c166601000000000000029b909b167fffffffffffffff00000000000000000000000000000000000000ffffffffffff90931692909217999099171693909216929092179590951790945550600193505050505b92915050565b610c1f61130c565b600480547fffff00ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff167d010000000000000000000000000000000000000000000000000000000000179055565b610c7161130c565b610c7961137b565b565b610c8361130c565b610c8b61137b565b6fffffffffffffffffffffffffffffffff9182169116700100000000000000000000000000000000027fffffffffffffffffffffffffffffffff000000000000000000000000000000001617600555565b610ce461130c565b610cf0600083836113c7565b5050565b610cfc61130c565b6004546fffffffffffffffffffffffffffffffff66010000000000008204169063ffffffff7901000000000000000000000000000000000000000000000000008204169060ff7d0100000000000000000000000000000000000000000000000000000000008204169063010000008104600290810b91900b82610dd557610d848682846114a7565b610dd557600480547fffff00ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff167d010000000000000000000000000000000000000000000000000000000000179055600192505b50508015610de557505050610f06565b600480547fffffffffffffff000000ffffffffffffffffffffffffffffffffffffffffffff1676010000000000000000000000000000000000000000000062ffffff87160217905563ffffffff82164263ffffffff161115610e5d57610e5d82846fffffffffffffffffffffffffffffffff16611076565b84600f0b600014610f02576000610e7788868860006114cc565b90506000610e8888878960016114cc565b9050610e95868a8a6114a7565b15610edd57610ea48588611245565b600460066101000a8154816fffffffffffffffffffffffffffffffff02191690836fffffffffffffffffffffffffffffffff1602179055505b8180610ee65750805b15610eff57610eff898984848a60008d600f0b126114f0565b50505b5050505b50505050565b610f1461130c565b610cf0600183836113c7565b6000838302817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff85870982811083820303915050808411610f6057600080fd5b80600003610f7357508290049050610fd1565b8385870960008581038616958690049560026003880281188089028203028089028203028089028203028089028203028089028203028089029091030291819003819004600101858411909403939093029190930391909104170290505b9392505050565b600285810b60009081526020889052604080822087840b8084529183209293849391929088900b121561104e578860020b8760020b1261102957816002015486039350816003015485039250611038565b81600201549350816003015492505b6002810154600382015494039390920391611069565b81600201548160020154039350816003015481600301540392505b5050965096945050505050565b63ffffffff4283900316600081900361108e57505050565b81156111f4576005546006546fffffffffffffffffffffffffffffffff8083168402927001000000000000000000000000000000009081900482168502928083169291900416818411156110f257816fffffffffffffffffffffffffffffffff1693505b806fffffffffffffffffffffffffffffffff1683111561112257806fffffffffffffffffffffffffffffffff1692505b838317156111ef576fffffffffffffffffffffffffffffffff91821684900391168290038315611172576111688470010000000000000000000000000000000088610f20565b6007805490910190555b821561119e576111948370010000000000000000000000000000000088610f20565b6008805490910190555b6fffffffffffffffffffffffffffffffff808316908216700100000000000000000000000000000000027fffffffffffffffffffffffffffffffff0000000000000000000000000000000016176006555b505050505b5050600480547fffffff00000000ffffffffffffffffffffffffffffffffffffffffffffffffff167901000000000000000000000000000000000000000000000000004263ffffffff160217905550565b60008082600f0b12156112a957508082016fffffffffffffffffffffffffffffffff808416908216106112a4576040517f1301f74800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610c11565b826fffffffffffffffffffffffffffffffff168284019150816fffffffffffffffffffffffffffffffff161015610c11576040517f997402f200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b3373ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001614610c79576040517fae74b17800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600454610c7990790100000000000000000000000000000000000000000000000000810463ffffffff1690660100000000000090046fffffffffffffffffffffffffffffffff16611076565b6113cf61137b565b6fffffffffffffffffffffffffffffffff82821716156114a2576006546fffffffffffffffffffffffffffffffff80821691700100000000000000000000000000000000900416841561143957611426848361204d565b9150611432838261204d565b9050611452565b611443848361207d565b915061144f838261207d565b90505b6fffffffffffffffffffffffffffffffff9182169116700100000000000000000000000000000000027fffffffffffffffffffffffffffffffff0000000000000000000000000000000016176006555b505050565b60008260020b8460020b121580156114c457508160020b8460020b125b949350505050565b6007546008546000916114e79183918891889188918861161f565b95945050505050565b600454600154600282810b9263010000009004900b9063ffffffff16828282891561152b576115238c898386868c611753565b919450925090505b88156115475761153f8b898386868c611753565b919450925090505b8260020b8660020b14158061156257508160020b8560020b14155b8061157957508363ffffffff168163ffffffff1614155b1561161157600180547fffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000001663ffffffff8316179055600480547fffffffffffffffffffffffffffffffffffffffffffffffffffff00000000000016630100000062ffffff858116919091027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000016919091179085161790555b505050505050505050505050565b600286900b600090815260208890526040812080548261163f8289611245565b6fffffffffffffffffffffffffffffffff1690506d09745258e83de0d0f4e400fce79981111561169b576040517f25b8364a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001830154600f0b856116bf5788600f0b81600f0b6116ba91906120a6565b6116d1565b88600f0b81600f0b6116d191906120ce565b6001850180547fffffffffffffffffffffffffffffffff00000000000000000000000000000000166fffffffffffffffffffffffffffffffff9290921691909117905581845581159450600083900361174457841594508960020b8b60020b136117445760038401879055600284018890555b50505050979650505050505050565b6000806000831561179c5760008061176b818c611854565b915091508a60020b8860020b0361178457819750611795565b8a60020b8760020b03611795578096505b5050611832565b6000808a60020b8860020b1280156117b957508a60020b8760020b135b156117e257508690508560028a810b908c900b13156117da578a9650611822565b8a9750611822565b6117f0600360028b8e611aca565b600281810b6000908152602081905260409020600101547001000000000000000000000000000000009004900b925090505b61182f60008c8484611ba7565b50505b6000611842600360028a8d611d53565b969a9599509597509395505050505050565b600281810b60008181526020859052604081206001810180548383557fffffffffffffffffffff0000000000000000000000000000000000000000000081169091558185018390556003909101919091557001000000000000000000000000000000008104830b92730100000000000000000000000000000000000000909104900b907ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff27618148061193157506119287ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff27618611fce565b60020b8360020b145b156119d657600283900b6000908152602085905260409020600101805462ffffff808516700100000000000000000000000000000000027fffffffffffffffffffffffffff000000ffffffffffffffffffffffffffffffff91851673010000000000000000000000000000000000000002919091167fffffffffffffffffffff000000000000ffffffffffffffffffffffffffffffff909216919091171790556107c7565b8060020b8260020b03611a15576040517f0d6e094900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600282810b6000908152602086905260408082206001908101805462ffffff808816730100000000000000000000000000000000000000027fffffffffffffffffffff000000ffffffffffffffffffffffffffffffffffffff909216919091179091559385900b83529120018054918416700100000000000000000000000000000000027fffffffffffffffffffffffffff000000ffffffffffffffffffffffffffffffff9092169190911790559250929050565b600190810190600090600883811d610d8a01901c90829061ffff83161b851663ffffffff1615611b2d57611afe8785611deb565b90945090925090508015611b135750506114c4565b611b2486610d8b840160010b611deb565b90945090925090505b80611b7057611b4b8563ffffffff168360010193508360010b611e1c565b909350905080611b635750620d89e891506114c49050565b611b6d8684611f73565b92505b611b9c877ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff2768501611f73565b979650505050505050565b600283900b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff276181480611c065750611bfd7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff27618611fce565b60020b8360020b145b610f06578260020b8260020b128015611c2457508260020b8160020b135b611c5a576040517fe45ac17d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600283810b60009081526020959095526040808620600190810180547fffffffffffffffffffff000000000000ffffffffffffffffffffffffffffffff1673010000000000000000000000000000000000000062ffffff87811682027fffffffffffffffffffffffffff000000ffffffffffffffffffffffffffffffff908116939093177001000000000000000000000000000000008a831681029190911790945597860b8a52848a20840180547fffffffffffffffffffff000000ffffffffffffffffffffffffffffffffffffff1698909916908102979097179097559390920b865290942090930180549092169202919091179055565b81600080611d908785600881901d600181810b60009081526020949094526040909320805460ff9093169390931b80831890935591811490151891565b915091508115611de157610d8a01600181810b60081d80820b6000908152602089905260409020805460ff9094169290921b808418909255821591909214818118935014611de1576001811b831892505b5050949350505050565b600881901d600181900b6000908152602084905260408120548190611e109085611e1c565b93969095509293505050565b60008060ff831684811c808303611e38578460ff179350611f6a565b7f555555555555555555555555555555555555555555555555555555555555555560008290038216908116156fffffffffffffffffffffffffffffffff82161560071b1777ffffffffffffffff0000000000000000ffffffffffffffff82161560061b177bffffffff00000000ffffffff00000000ffffffff00000000ffffffff82161560051b177dffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff82161560041b177eff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff82161560031b177f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f82161560021b177f33333333333333333333333333333333333333333333333333333333333333339091161560011b1760ff1685019350600192505b50509250929050565b600181900b600090815260208390526040902054600882901b90611f979082611e1c565b509392505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60008160020b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff800000810361200357612003611f9f565b60000392915050565b600282810b9082900b037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8000008112627fffff82131715610c1157610c11611f9f565b6fffffffffffffffffffffffffffffffff81811683821601908082111561207657612076611f9f565b5092915050565b6fffffffffffffffffffffffffffffffff82811682821603908082111561207657612076611f9f565b80820182811260008312801582168215821617156120c6576120c6611f9f565b505092915050565b818103600083128015838313168383128216171561207657612076611f9f56fea164736f6c6343000814000aa164736f6c6343000814000a
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000f03875b5ec5eac83cab83a6c2ab17844304aa7a00000000000000000000000001c4cbb62e18cf9c137c5d85096b5bc7819082691
-----Decoded View---------------
Arg [0] : _deployer (address): 0xf03875b5Ec5eAc83cab83A6c2ab17844304AA7a0
Arg [1] : _nonfungiblePositionManager (address): 0x1C4cbb62e18CF9C137c5D85096b5bC7819082691
-----Encoded View---------------
2 Constructor Arguments found :
Arg [0] : 000000000000000000000000f03875b5ec5eac83cab83a6c2ab17844304aa7a0
Arg [1] : 0000000000000000000000001c4cbb62e18cf9c137c5d85096b5bc7819082691
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 30 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
[ Download: CSV Export ]
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.