More Info
Private Name Tags
ContractCreator
TokenTracker
Latest 8 from a total of 8 transactions
| Transaction Hash |
|
Block
|
From
|
To
|
|||||
|---|---|---|---|---|---|---|---|---|---|
| Set Fees | 31344275 | 83 days ago | IN | 0 ETH | 0 | ||||
| Admin Rescue ETH | 17776370 | 240 days ago | IN | 0 ETH | 0.00000001 | ||||
| Lock NFT Positio... | 17775260 | 240 days ago | IN | 0.1 ETH | 0.00000005 | ||||
| Set Whitelist Fo... | 17521835 | 243 days ago | IN | 0 ETH | 0.00000002 | ||||
| Set Whitelist Fo... | 17521825 | 243 days ago | IN | 0 ETH | 0.00000002 | ||||
| Set Flat Fee | 17521757 | 243 days ago | IN | 0 ETH | 0.00000001 | ||||
| Set Fees | 17521749 | 243 days ago | IN | 0 ETH | 0.00000001 | ||||
| Set Migrator | 17521503 | 243 days ago | IN | 0 ETH | 0.00000001 |
Latest 1 internal transaction
| Parent Transaction Hash | Block | From | To | |||
|---|---|---|---|---|---|---|
| 17776370 | 240 days ago | 0.1 ETH |
Cross-Chain Transactions
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: UNLICENSED
// ALL RIGHTS RESERVED
// UNCX by SDDTech reserves all rights on this code. You may not copy these contracts.
pragma solidity ^0.8.26;
import {IERC20} from "@openzeppelin/contracts/interfaces/IERC20.sol";
import {IERC721} from "@openzeppelin/contracts/interfaces/IERC721.sol";
import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import {IERC721Receiver} from "@openzeppelin/contracts/interfaces/IERC721Receiver.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";
import {IPositionManager} from "@uniswap/v4-periphery/src/interfaces/IPositionManager.sol";
import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";
import {PoolIdLibrary} from "@uniswap/v4-core/src/types/PoolId.sol";
import {Currency, CurrencyLibrary} from "@uniswap/v4-core/src/types/Currency.sol";
import {StateLibrary} from "@uniswap/v4-core/src/libraries/StateLibrary.sol";
import {Actions} from "./libraries/Actions.sol";
import {Planner, Plan} from "./libraries/Planner.sol";
import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {IMigrateNFT} from "./interfaces/IMigrator.sol";
import {IUniversalLockerV2} from "./IUniversalLockerV2.sol";
/// @title Universal Liquidity Locker for Uniswap V4
/// @notice Manages locking and unlocking of Uniswap V4 NFT positions with fee collection and migration capabilities
/// @dev Implements ERC721 for NFTized locks, handles hook validation, and manages lock lifecycle
contract UniV4LiquidityLockerV2 is IUniversalLockerV2, ERC721, IERC721Receiver, Ownable, ReentrancyGuard {
using Planner for Plan;
using PoolIdLibrary for PoolKey;
using CurrencyLibrary for Currency;
using StateLibrary for IPoolManager;
using Strings for uint256;
using Strings for uint160;
using EnumerableSet for EnumerableSet.UintSet;
using SafeERC20 for IERC20;
// Add constant for native ETH address
address public constant NATIVE_ETH = address(0);
IPoolManager public immutable poolManager;
IPositionManager public immutable positionManager;
uint256 public constant ETERNAL_LOCK = type(uint256).max;
mapping(uint256 => IUniversalLockerV2.LockInfo) public locks;
mapping(address => bool) public whitelistedHooks;
mapping(address => EnumerableSet.UintSet) private userLocks;
uint256 private nextLockId;
// Add new state variables
address payable public FEE_ADDR_LP; // LP fee destination
address payable public FEE_ADDR_COLLECT; // collect fee destination
uint256 public constant FEE_DENOMINATOR = 10000; // denominator for all fees
address public AUTO_COLLECT_ACCOUNT; // account for auto collecting fees
uint256 public lpFee = 50; // 0.5% default LP fee
uint256 public collectFee = 200; // 2% default collect fee
uint256 public flatFee = 0.1 ether; // Flat fee to create lock
// Add state variables
IUniversalLockerV2.PermissionMode public permissionMode;
mapping(address => bool) public blacklistedHooks;
// Add these state variables near the top with other state variables
IMigrateNFT public MIGRATOR; // migrate to future amm versions while liquidity remains locked
string public baseURI;
string public baseExtension = ".json";
// Add whitelist mapping for free locks
mapping(address => bool) public whitelistedForFreeLock;
/// @notice Initializes the locker with required contract addresses and fee receivers
/// @param _poolManager Address of the Uniswap V4 pool manager
/// @param _positionManager Address of the Uniswap V4 position manager
/// @param _lpFeeReceiver Address to receive LP fees
/// @param _collectFeeReceiver Address to receive collection fees
/// @param _autoCollectAccount Address allowed to auto-collect fees
/// @dev Sets initial permission mode to Permissionless
constructor(
address _poolManager,
address _positionManager,
address payable _lpFeeReceiver,
address payable _collectFeeReceiver,
address _autoCollectAccount
) ERC721("UNCX V4 Lock", "UNCX-V4-LOCK") Ownable(msg.sender) {
if (_poolManager == address(0)) revert InvalidPoolManager();
if (_positionManager == address(0)) revert InvalidPositionManager();
if (_lpFeeReceiver == address(0)) revert InvalidLPFeeReceiver();
if (_collectFeeReceiver == address(0)) revert InvalidCollectFeeReceiver();
poolManager = IPoolManager(_poolManager);
positionManager = IPositionManager(_positionManager);
FEE_ADDR_LP = _lpFeeReceiver;
FEE_ADDR_COLLECT = _collectFeeReceiver;
AUTO_COLLECT_ACCOUNT = _autoCollectAccount;
permissionMode = PermissionMode.Permissionless;
}
/// @notice Sets whitelist status for free locks
/// @param user Address to whitelist
/// @param status Whitelist status to set
/// @dev Only callable by owner
function setWhitelistForFreeLock(address user, bool status) external onlyOwner {
if (user == address(0)) revert InvalidTokenAddress();
whitelistedForFreeLock[user] = status;
emit WhitelistedForFreeLock(user, status);
}
/// @notice Required implementation for ERC721 token reception
/// @return bytes4 Function selector for ERC721 token reception
function onERC721Received(address, address, uint256, bytes calldata) external pure returns (bytes4) {
return this.onERC721Received.selector;
}
function setHookWhitelist(address hookAddress, bool status) external onlyOwner {
if (hookAddress == address(0)) revert InvalidHookAddress();
if (whitelistedHooks[hookAddress] == status) revert NoChange();
whitelistedHooks[hookAddress] = status;
emit HookWhitelisted(hookAddress, status);
}
function setPermissionMode(PermissionMode _mode) external onlyOwner {
if (_mode == permissionMode) revert NoChange();
permissionMode = _mode;
emit PermissionModeChanged(_mode);
}
function setHookBlacklist(address hook, bool blacklisted) external onlyOwner {
if (hook == address(0)) revert InvalidHookAddress();
if (blacklistedHooks[hook] == blacklisted) revert NoChange();
blacklistedHooks[hook] = blacklisted;
emit HookBlacklisted(hook, blacklisted);
}
/// @notice Sets the flat fee required to create a lock
/// @param _flatFee New flat fee amount in ETH
/// @dev Only callable by owner
function setFlatFee(uint256 _flatFee) external onlyOwner {
flatFee = _flatFee;
emit FlatFeeSet(_flatFee);
}
/// @notice Validates a hook based on current permission mode
/// @param hook Address of the hook to validate
/// @dev Reverts if hook is not whitelisted in whitelist mode or is blacklisted in blacklist mode
function _validateHook(address hook) internal view {
if (permissionMode == PermissionMode.WhitelistOnly) {
if (!whitelistedHooks[hook]) revert HookNotWhitelisted();
} else if (permissionMode == PermissionMode.PermissionlessWithBlacklist) {
if (blacklistedHooks[hook]) revert HookIsBlacklisted();
}
// In Permissionless mode, no validation needed
}
/// @notice Parameters for creating a lock
/// @param tokenId NFT position token ID
/// @param unlockTime Timestamp when position can be unlocked
/// @param mintLockNFT Whether to mint an NFT representing the lock
/// @param liquidity Amount of liquidity being locked
/// @param poolKey Pool key associated with the position
struct LockParams {
uint256 tokenId;
uint256 unlockTime;
bool mintLockNFT;
uint128 liquidity;
PoolKey poolKey;
}
/// @notice Creates lock info for a position
/// @param params Lock parameters
/// @param lockId ID of the lock being created
/// @dev Stores lock info and adds to user's lock set
function _createLockInfo(LockParams memory params, uint256 lockId) internal {
locks[lockId] = IUniversalLockerV2.LockInfo({
lockId: lockId,
owner: msg.sender,
tokenId: params.tokenId,
poolKey: params.poolKey,
amount: params.liquidity,
unlockTime: params.unlockTime,
collectAddress: msg.sender,
ucf: collectFee,
isNFTized: params.mintLockNFT
});
userLocks[msg.sender].add(lockId);
}
/// @notice Locks an NFT position with optional NFT representation
/// @param tokenId Token ID of the position to lock
/// @param unlockTime Timestamp when position can be unlocked
/// @param mintLockNFT Whether to mint an NFT representing the lock
/// @return lockId ID of the created lock
/// @dev Handles LP fee calculation and collection
function lockNFTPosition(uint256 tokenId, uint256 unlockTime, bool mintLockNFT)
external
payable
nonReentrant
returns (uint256 lockId)
{
// Check flat fee unless whitelisted
if (!whitelistedForFreeLock[msg.sender]) {
if (msg.value < flatFee) revert InsufficientFlatFee();
}
// Basic validations
if (unlockTime <= block.timestamp) revert UnlockTimeInPast();
if (unlockTime >= 1e10 && unlockTime != ETERNAL_LOCK) revert InvalidUnlockTime();
// Transfer NFT first to reduce stack
IERC721(address(positionManager)).safeTransferFrom(msg.sender, address(this), tokenId);
// Get position info
(PoolKey memory poolKey,) = IPositionManager(address(positionManager)).getPoolAndPositionInfo(tokenId);
uint128 liquidity = IPositionManager(address(positionManager)).getPositionLiquidity(tokenId);
if (liquidity == 0) revert NoLiquidityInPosition();
// Check if pool exists by getting its state
(uint160 sqrtPriceX96,,,) = poolManager.getSlot0(poolKey.toId());
if (sqrtPriceX96 == 0) revert PoolNotInitialized();
// Validate hook based on permission mode
if (address(poolKey.hooks) != address(0)) {
_validateHook(address(poolKey.hooks));
}
// Handle LP fee
if (lpFee > 0 && !whitelistedForFreeLock[msg.sender]) {
uint256 feeAmount = (uint256(liquidity) * lpFee) / FEE_DENOMINATOR;
liquidity = uint128(uint256(liquidity) - feeAmount);
// Create a plan using Planner
Plan memory plan = Planner.init();
// Add decrease liquidity action for fee amount
plan = plan.add(
Actions.DECREASE_LIQUIDITY,
abi.encode(
tokenId,
feeAmount,
uint128(0), // min amount 0
uint128(0), // min amount 1
"" // hook data
)
);
// Add take pair action to collect tokens
plan = plan.add(Actions.TAKE_PAIR, abi.encode(poolKey.currency0, poolKey.currency1, FEE_ADDR_LP));
// Encode and execute the plan
bytes memory planData = plan.encode();
positionManager.modifyLiquidities(
planData,
block.timestamp + 60 // deadline
);
liquidity = IPositionManager(address(positionManager)).getPositionLiquidity(tokenId);
}
// Create lock
lockId = nextLockId++;
if (mintLockNFT) {
_mint(msg.sender, lockId); // Mint NFT with lockId as the token ID
}
_createLockInfo(
LockParams({
tokenId: tokenId,
unlockTime: unlockTime,
mintLockNFT: mintLockNFT,
liquidity: liquidity,
poolKey: poolKey
}),
lockId
);
// Transfer flat fee to LP fee receiver if not whitelisted
if (!whitelistedForFreeLock[msg.sender] && msg.value > 0) {
(bool success,) = FEE_ADDR_LP.call{value: msg.value}("");
if (!success) revert ETHTransferFailed();
}
emit LiquidityLocked(
lockId, msg.sender, address(positionManager), tokenId, poolKey.toId(), liquidity, unlockTime
);
}
/// @notice Creates a lock by migrating from a previous locker version
/// @param oldLockId Lock ID from the previous locker contract
/// @param oldLocker Address of the previous locker contract
/// @return lockId ID of the newly created lock
/// @dev Only callable by migrator contract
function lockFromMigration(
uint256 oldLockId,
address oldLocker
) external returns (uint256 lockId) {
// Only migrator can call
if (msg.sender != address(MIGRATOR)) revert InvalidMigrator();
// Get lock info from old locker
IUniversalLockerV2.LockInfo memory oldLock = IUniversalLockerV2(oldLocker).getLockInfo(oldLockId);
// Create new lock
lockId = nextLockId++;
if (oldLock.isNFTized) {
_mint(oldLock.owner, lockId);
}
// Store lock info
locks[lockId] = IUniversalLockerV2.LockInfo({
lockId: lockId,
owner: oldLock.owner,
tokenId: oldLock.tokenId,
poolKey: oldLock.poolKey,
amount: oldLock.amount,
unlockTime: oldLock.unlockTime,
collectAddress: oldLock.collectAddress,
ucf: oldLock.ucf,
isNFTized: oldLock.isNFTized
});
userLocks[oldLock.owner].add(lockId);
// Transfer NFT from old locker to this contract
IERC721(address(positionManager)).transferFrom(msg.sender, address(this), oldLock.tokenId);
emit LiquidityLocked(
lockId,
oldLock.owner,
address(positionManager),
oldLock.tokenId,
oldLock.poolKey.toId(),
oldLock.amount,
oldLock.unlockTime
);
}
/// @notice Unlocks a locked position
/// @param lockId ID of the lock to unlock
/// @dev Burns NFT if lock was NFTized, transfers position back to owner
function unlockLiquidity(uint256 lockId) external nonReentrant {
IUniversalLockerV2.LockInfo storage lock = locks[lockId];
if (lock.owner != msg.sender) revert NotOwner();
if (lock.unlockTime > block.timestamp) revert StillLocked();
if (lock.amount == 0) revert AlreadyUnlocked();
uint256 amount = lock.amount;
address owner = lock.owner;
uint256 tokenId = lock.tokenId;
// Get position info for fee collection
(PoolKey memory poolKey,) = IPositionManager(address(positionManager)).getPoolAndPositionInfo(tokenId);
uint128 currentLiquidity = IPositionManager(address(positionManager)).getPositionLiquidity(tokenId);
// Collect any pending fees first
if (currentLiquidity > 0) {
// Approve position manager to modify position
IERC721(address(positionManager)).approve(address(positionManager), tokenId);
// Create a plan using Planner
Plan memory plan = Planner.init();
// Add collect fees action (decrease with 0 liquidity)
plan = plan.add(
Actions.DECREASE_LIQUIDITY,
abi.encode(
tokenId,
uint256(0), // Don't remove any liquidity
uint128(0), // min amount 0
uint128(0), // min amount 1
"" // hook data
)
);
// Add take pair action to collect tokens
plan = plan.add(Actions.TAKE_PAIR, abi.encode(poolKey.currency0, poolKey.currency1, address(this)));
// Execute plan
positionManager.modifyLiquidities(
plan.encode(),
block.timestamp + 60 // deadline
);
// Get token addresses and check for native ETH
address token0 = Currency.unwrap(poolKey.currency0);
address token1 = Currency.unwrap(poolKey.currency1);
bool isToken0Native = _isNativeETH(poolKey.currency0);
bool isToken1Native = _isNativeETH(poolKey.currency1);
// Get collected amounts
uint256 amount0 = isToken0Native ? address(this).balance : IERC20(token0).balanceOf(address(this));
uint256 amount1 = isToken1Native ? address(this).balance : IERC20(token1).balanceOf(address(this));
// Handle protocol fees if any
if (lock.ucf > 0) {
// Calculate protocol fees
uint256 fee0 = (amount0 * lock.ucf) / FEE_DENOMINATOR;
uint256 fee1 = (amount1 * lock.ucf) / FEE_DENOMINATOR;
// Remaining amounts after fees
amount0 = amount0 - fee0;
amount1 = amount1 - fee1;
// Transfer protocol fees
if (fee0 > 0) {
if (isToken0Native) {
(bool success,) = FEE_ADDR_COLLECT.call{value: fee0}("");
if (!success) revert ETHTransferFailed();
} else {
IERC20(token0).safeTransfer(FEE_ADDR_COLLECT, fee0);
}
}
if (fee1 > 0) {
if (isToken1Native) {
(bool success,) = FEE_ADDR_COLLECT.call{value: fee1}("");
if (!success) revert ETHTransferFailed();
} else {
IERC20(token1).safeTransfer(FEE_ADDR_COLLECT, fee1);
}
}
}
// Transfer remaining amounts to owner
if (amount0 > 0) {
if (isToken0Native) {
(bool success,) = owner.call{value: amount0}("");
if (!success) revert ETHTransferFailed();
} else {
IERC20(token0).safeTransfer(owner, amount0);
}
}
if (amount1 > 0) {
if (isToken1Native) {
(bool success,) = owner.call{value: amount1}("");
if (!success) revert ETHTransferFailed();
} else {
IERC20(token1).safeTransfer(owner, amount1);
}
}
}
// Update state before transfer
lock.amount = 0;
userLocks[owner].remove(lockId);
// Burn NFT if lock was NFTized
if (lock.isNFTized) {
_burn(lockId);
}
// Use try-catch for NFT transfer
try IERC721(address(positionManager)).transferFrom(address(this), owner, tokenId) {
emit LiquidityUnlocked(lockId, owner, address(positionManager), tokenId, lock.poolKey.toId(), amount);
} catch Error(string memory reason) {
revert TransferFailed(reason);
} catch {
revert TransferFailed("Unknown transfer error");
}
// Delete lock info after successful transfer
delete locks[lockId];
}
/// @notice Updates fee receiver addresses
/// @param _lpFeeReceiver New LP fee receiver address
/// @param _collectFeeReceiver New collect fee receiver address
/// @param _autoCollectAccount New auto collect account address
/// @dev Only callable by owner
function setFeeAddresses(
address payable _lpFeeReceiver,
address payable _collectFeeReceiver,
address _autoCollectAccount
) external onlyOwner {
if (_lpFeeReceiver == address(0)) revert InvalidLPFeeReceiver();
if (_collectFeeReceiver == address(0)) revert InvalidCollectFeeReceiver();
FEE_ADDR_LP = _lpFeeReceiver;
FEE_ADDR_COLLECT = _collectFeeReceiver;
AUTO_COLLECT_ACCOUNT = _autoCollectAccount;
}
/// @notice Helper function to check if a currency is native ETH
/// @param currency The currency to check
/// @return bool True if the currency is native ETH
function _isNativeETH(Currency currency) internal pure returns (bool) {
return Currency.unwrap(currency) == NATIVE_ETH;
}
/// @notice Collects fees from a locked position
/// @param lockId ID of the lock to collect fees from
/// @param recipient Address to receive collected fees
/// @return amount0 Amount of token0 collected
/// @return amount1 Amount of token1 collected
/// @return fee0 Protocol fee amount for token0
/// @return fee1 Protocol fee amount for token1
/// @dev Handles fee splitting between protocol and user
function collect(uint256 lockId, address recipient)
external
nonReentrant
returns (uint256 amount0, uint256 amount1, uint256 fee0, uint256 fee1)
{
IUniversalLockerV2.LockInfo storage lock = locks[lockId];
if (lock.owner != msg.sender && msg.sender != AUTO_COLLECT_ACCOUNT) revert NotOwner();
if (recipient == address(0)) revert InvalidRecipient();
// Get position info
(PoolKey memory poolKey,) = IPositionManager(address(positionManager)).getPoolAndPositionInfo(lock.tokenId);
uint128 currentLiquidity = IPositionManager(address(positionManager)).getPositionLiquidity(lock.tokenId);
// Create a plan to collect fees without removing liquidity
if (currentLiquidity > 0) {
// Approve position manager to modify position
IERC721(address(positionManager)).approve(address(positionManager), lock.tokenId);
// Create a plan using Planner
Plan memory plan = Planner.init();
// Add collect fees action (decrease with 0 liquidity)
plan = plan.add(
Actions.DECREASE_LIQUIDITY,
abi.encode(
lock.tokenId,
uint256(0), // Don't remove any liquidity
uint128(0), // min amount 0
uint128(0), // min amount 1
"" // hook data
)
);
// Add take actions for both tokens to recipient
// TAKE_PAIR action withdraws any accumulated tokens for a currency pair from the PoolManager
// to the specified recipient address. This is used to collect fees and other accumulated value.
plan = plan.add(Actions.TAKE_PAIR, abi.encode(poolKey.currency0, poolKey.currency1, address(this)));
// Encode the final data
bytes memory unlockData = plan.encode();
positionManager.modifyLiquidities(
unlockData,
block.timestamp + 60 // deadline
);
// Get token addresses and check for native ETH
address token0 = Currency.unwrap(poolKey.currency0);
address token1 = Currency.unwrap(poolKey.currency1);
bool isToken0Native = _isNativeETH(poolKey.currency0);
bool isToken1Native = _isNativeETH(poolKey.currency1);
// Get collected amounts
amount0 = isToken0Native ? address(this).balance : IERC20(token0).balanceOf(address(this));
amount1 = isToken1Native ? address(this).balance : IERC20(token1).balanceOf(address(this));
if (lock.ucf > 0) {
// Calculate protocol fees
fee0 = (amount0 * lock.ucf) / FEE_DENOMINATOR;
fee1 = (amount1 * lock.ucf) / FEE_DENOMINATOR;
// Remaining amounts after fees
amount0 = amount0 - fee0;
amount1 = amount1 - fee1;
// Transfer protocol fees
address feeTo = msg.sender == AUTO_COLLECT_ACCOUNT ? recipient : FEE_ADDR_COLLECT;
if (fee0 > 0) {
if (isToken0Native) {
(bool success,) = feeTo.call{value: fee0}("");
if (!success) revert ETHTransferFailed();
} else {
IERC20(token0).safeTransfer(feeTo, fee0);
}
}
if (fee1 > 0) {
if (isToken1Native) {
(bool success,) = feeTo.call{value: fee1}("");
if (!success) revert ETHTransferFailed();
} else {
IERC20(token1).safeTransfer(feeTo, fee1);
}
}
// Transfer remaining amounts
address remainderTo = msg.sender == AUTO_COLLECT_ACCOUNT ? lock.collectAddress : recipient;
if (amount0 > 0) {
if (isToken0Native) {
(bool success,) = remainderTo.call{value: amount0}("");
if (!success) revert ETHTransferFailed();
} else {
IERC20(token0).safeTransfer(remainderTo, amount0);
}
}
if (amount1 > 0) {
if (isToken1Native) {
(bool success,) = remainderTo.call{value: amount1}("");
if (!success) revert ETHTransferFailed();
} else {
IERC20(token1).safeTransfer(remainderTo, amount1);
}
}
} else {
// No protocol fees, transfer full amounts
if (amount0 > 0) {
if (isToken0Native) {
(bool success,) = recipient.call{value: amount0}("");
if (!success) revert ETHTransferFailed();
} else {
IERC20(token0).safeTransfer(recipient, amount0);
}
}
if (amount1 > 0) {
if (isToken1Native) {
(bool success,) = recipient.call{value: amount1}("");
if (!success) revert ETHTransferFailed();
} else {
IERC20(token1).safeTransfer(recipient, amount1);
}
}
}
}
}
/// @notice Updates UCF (User Collection Fee) for a lock
/// @param _lockId ID of the lock to update
/// @param _ucf New UCF value
/// @dev Only callable by owner, can only decrease UCF
function setUCF(uint256 _lockId, uint256 _ucf) external onlyOwner {
IUniversalLockerV2.LockInfo storage lock = locks[_lockId];
if (_ucf >= lock.ucf) revert UCFCanOnlyBeDecreased();
lock.ucf = _ucf;
emit onSetUCF(_lockId, _ucf);
}
// Helper functions for managing locks
/// @notice Gets number of locks owned by a user
/// @param user Address of the user
/// @return uint256 Number of locks owned
function getUserLockCount(address user) external view returns (uint256) {
return userLocks[user].length();
}
/// @notice Gets lock ID at specific index for a user
/// @param user Address of the user
/// @param index Index in user's lock array
/// @return uint256 Lock ID at specified index
function getUserLockAt(address user, uint256 index) external view returns (uint256) {
return userLocks[user].at(index);
}
/// @notice Checks if a lock is currently active
/// @param lockId ID of the lock to check
/// @return bool True if lock is active and not expired
function isLocked(uint256 lockId) public view returns (bool) {
IUniversalLockerV2.LockInfo storage lock = locks[lockId];
return lock.amount > 0 && lock.unlockTime > block.timestamp;
}
/// @notice Verifies NFT ownership
/// @param tokenId Token ID to verify
/// @param expectedOwner Expected owner of the NFT
/// @dev Reverts if ownership doesn't match
function verifyNFTOwnership(uint256 tokenId, address expectedOwner) public view {
address currentOwner = IERC721(address(positionManager)).ownerOf(tokenId);
if (currentOwner != expectedOwner) revert NFTOwnerMismatch(expectedOwner, currentOwner);
}
/// @notice Decreases liquidity of an expired lock
/// @param lockId ID of the lock
/// @param liquidityDecrease Amount of liquidity to decrease
/// @param amount0Min Minimum amount of token0 to receive
/// @param amount1Min Minimum amount of token1 to receive
/// @return amount0 Amount of token0 received
/// @return amount1 Amount of token1 received
/// @dev Only callable after lock expiry
function decreaseLiquidity(uint256 lockId, uint128 liquidityDecrease, uint256 amount0Min, uint256 amount1Min)
external
nonReentrant
returns (uint256 amount0, uint256 amount1)
{
IUniversalLockerV2.LockInfo storage lock = locks[lockId];
if (lock.owner != msg.sender) revert NotOwner();
if (lock.unlockTime == ETERNAL_LOCK) revert EternalLock();
if (lock.unlockTime >= block.timestamp) revert NotYetExpired();
if (liquidityDecrease == 0) revert ZeroLiquidity();
if (liquidityDecrease > lock.amount) revert InsufficientLiquidity();
// Create a plan using Planner
Plan memory plan = Planner.init();
// Add decrease liquidity action
plan = plan.add(
Actions.DECREASE_LIQUIDITY,
abi.encode(
lock.tokenId,
liquidityDecrease,
amount0Min,
amount1Min,
"" // hook data
)
);
// Add take pair action to collect tokens
plan = plan.add(Actions.TAKE_PAIR, abi.encode(lock.poolKey.currency0, lock.poolKey.currency1, msg.sender));
// Execute plan using modifyLiquidities
positionManager.modifyLiquidities(
plan.encode(),
block.timestamp + 60 // deadline
);
// Update lock amount
lock.amount -= liquidityDecrease;
emit LiquidityDecreased(lockId);
return (amount0, amount1);
}
/// @notice Extends lock duration
/// @param lockId ID of the lock to extend
/// @param newUnlockTime New unlock timestamp
/// @dev Can only extend, not reduce unlock time
function relock(uint256 lockId, uint256 newUnlockTime) external nonReentrant {
IUniversalLockerV2.LockInfo storage lock = locks[lockId];
if (lock.owner != msg.sender) revert NotOwner();
if (newUnlockTime <= block.timestamp) revert UnlockTimeInPast();
if (newUnlockTime <= lock.unlockTime) revert InvalidUnlockTime();
if (newUnlockTime >= 1e10 && newUnlockTime != ETERNAL_LOCK) revert InvalidUnlockTime();
lock.unlockTime = newUnlockTime;
emit LockExtended(lockId, newUnlockTime);
}
/**
* @dev Override update hook to handle lock ownership
*/
function _update(address to, uint256 tokenId, address auth) internal virtual override returns (address) {
address from = super._update(to, tokenId, auth);
// Update lock ownership if this is an NFTized lock
if (locks[tokenId].isNFTized) {
// Remove from old owner's set
if (from != address(0)) {
userLocks[from].remove(tokenId);
}
// Add to new owner's set
if (to != address(0)) {
userLocks[to].add(tokenId);
locks[tokenId].owner = to;
locks[tokenId].collectAddress = to; // Update collect address when ownership changes
}
}
emit LockOwnershipTransferred(tokenId, from, to);
return from;
}
/// @notice Gets information about a lock
/// @param lockId ID of the lock
/// @return LockInfo Lock information struct
function getLockInfo(uint256 lockId) public view returns (IUniversalLockerV2.LockInfo memory) {
return locks[lockId];
}
/// @notice Sets fee percentages
/// @param _lpFee New LP fee percentage
/// @param _collectFee New collect fee percentage
/// @dev Only callable by owner, max 10% for each
function setFees(uint256 _lpFee, uint256 _collectFee) external onlyOwner {
if (_lpFee > 1000) revert LPFeeTooHigh(); // max 10%
if (_collectFee > 1000) revert CollectFeeTooHigh(); // max 10%
lpFee = _lpFee;
collectFee = _collectFee;
emit FeesSet(_lpFee, _collectFee);
}
/// @notice Migrates a lock to a new AMM version
/// @param lockId ID of the lock to migrate
/// @dev Transfers NFT to migrator contract
function migrate(uint256 lockId) external payable nonReentrant {
if (address(MIGRATOR) == address(0)) revert MigratorNotSet();
IUniversalLockerV2.LockInfo storage lock = locks[lockId];
if (lock.owner != msg.sender) revert NotOwner();
if (lock.amount == 0) revert LockNotActive();
// Get current NFT owner
address currentOwner = IERC721(address(positionManager)).ownerOf(lock.tokenId);
if (currentOwner != address(this)) revert NFTNotInLocker();
// First approve the migrator to take the NFT
IERC721(address(positionManager)).approve(address(MIGRATOR), lock.tokenId);
// Call migrate on the migrator contract
bool success =
MIGRATOR.migrate{value: msg.value}(lockId, IPositionManager(address(positionManager)), lock.tokenId);
if (!success) revert MigrationFailed();
// Clean up the lock
userLocks[lock.owner].remove(lockId);
delete locks[lockId];
emit LockMigrated(lockId, address(MIGRATOR));
}
/// @notice Sets the migrator contract address
/// @param _migrator Address of the new migrator contract
/// @dev Only callable by owner
function setMigrator(address _migrator) external onlyOwner {
MIGRATOR = IMigrateNFT(_migrator);
}
/// @notice Rescues mistakenly sent ERC20 tokens
/// @param token Address of the token to rescue
/// @param receiver Address to receive the tokens
/// @param amount Amount of tokens to rescue
/// @dev Cannot rescue locked NFTs
function adminRescueTokens(address token, address receiver, uint256 amount) external onlyOwner nonReentrant {
if (token == address(positionManager)) revert CannotRescueNFTs();
IERC20(token).safeTransfer(receiver, amount);
}
/// @notice Rescues mistakenly sent ETH
/// @param amount Amount of ETH to rescue
/// @param receiver Address to receive the ETH
/// @dev Only callable by owner
function adminRescueETH(uint256 amount, address payable receiver) external onlyOwner nonReentrant {
(bool success,) = receiver.call{value: amount}("");
if (!success) revert ETHTransferFailed();
}
/// @notice Sets the collect address for a lock
/// @param lockId ID of the lock
/// @param newCollectAddress New address to receive collected fees
/// @dev Only callable by lock owner
function setCollectAddress(uint256 lockId, address newCollectAddress) external nonReentrant {
if (newCollectAddress == address(0)) revert InvalidCollectAddress();
IUniversalLockerV2.LockInfo storage lock = locks[lockId];
if (lock.owner != msg.sender) revert NotOwner();
lock.collectAddress = newCollectAddress;
emit CollectAddressUpdated(lockId, newCollectAddress);
}
/// @notice Transfers lock ownership
/// @param lockId ID of the lock to transfer
/// @param newOwner New owner address
/// @dev Handles both NFTized and non-NFTized locks
function transferLockOwnership(uint256 lockId, address newOwner) external nonReentrant {
if (newOwner == address(0)) revert InvalidNewOwner();
IUniversalLockerV2.LockInfo storage lock = locks[lockId];
if (lock.owner != msg.sender) revert NotOwner();
// If lock is NFTized, transfer the NFT to new owner
if (lock.isNFTized) {
_transfer(msg.sender, newOwner, lockId);
} else {
// Remove from current owner's set
userLocks[msg.sender].remove(lockId);
// Add to new owner's set
userLocks[newOwner].add(lockId);
// Update owner
lock.owner = newOwner;
// Update collect address to match new owner
lock.collectAddress = newOwner;
}
emit LockOwnershipTransferred(lockId, msg.sender, newOwner);
}
/// @notice Sets the base URI for token metadata
/// @param _newBaseURI New base URI string
/// @dev Only callable by owner
function setBaseURI(string memory _newBaseURI) external onlyOwner {
baseURI = _newBaseURI;
}
/// @notice Sets the base extension for token metadata
/// @param _newBaseExtension New base extension string (e.g. ".json")
/// @dev Only callable by owner
function setBaseExtension(string memory _newBaseExtension) external onlyOwner {
baseExtension = _newBaseExtension;
}
/// @notice Returns the token URI for a given token ID
/// @param tokenId ID of the token to get URI for
/// @return string URI for the token metadata
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
if (!_exists(tokenId)) revert ERC721NonexistentToken(tokenId);
string memory currentBaseURI = baseURI;
return bytes(currentBaseURI).length > 0
? string(abi.encodePacked(currentBaseURI, tokenId.toString(), baseExtension))
: "";
}
// Add this helper function if not already present
function _exists(uint256 tokenId) internal view returns (bool) {
return _ownerOf(tokenId) != address(0);
}
/// @notice Allows the contract to receive native ETH
/// @dev Required for handling native ETH in pools
receive() external payable {}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../token/ERC20/IERC20.sol";// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC721.sol)
pragma solidity ^0.8.20;
import {IERC721} from "../token/ERC721/IERC721.sol";// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC721/ERC721.sol)
pragma solidity ^0.8.20;
import {IERC721} from "./IERC721.sol";
import {IERC721Metadata} from "./extensions/IERC721Metadata.sol";
import {ERC721Utils} from "./utils/ERC721Utils.sol";
import {Context} from "../../utils/Context.sol";
import {Strings} from "../../utils/Strings.sol";
import {IERC165, ERC165} from "../../utils/introspection/ERC165.sol";
import {IERC721Errors} from "../../interfaces/draft-IERC6093.sol";
/**
* @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC-721] Non-Fungible Token Standard, including
* the Metadata extension, but not including the Enumerable extension, which is available separately as
* {ERC721Enumerable}.
*/
abstract contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Errors {
using Strings for uint256;
// Token name
string private _name;
// Token symbol
string private _symbol;
mapping(uint256 tokenId => address) private _owners;
mapping(address owner => uint256) private _balances;
mapping(uint256 tokenId => address) private _tokenApprovals;
mapping(address owner => mapping(address operator => bool)) private _operatorApprovals;
/**
* @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return
interfaceId == type(IERC721).interfaceId ||
interfaceId == type(IERC721Metadata).interfaceId ||
super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721-balanceOf}.
*/
function balanceOf(address owner) public view virtual returns (uint256) {
if (owner == address(0)) {
revert ERC721InvalidOwner(address(0));
}
return _balances[owner];
}
/**
* @dev See {IERC721-ownerOf}.
*/
function ownerOf(uint256 tokenId) public view virtual returns (address) {
return _requireOwned(tokenId);
}
/**
* @dev See {IERC721Metadata-name}.
*/
function name() public view virtual returns (string memory) {
return _name;
}
/**
* @dev See {IERC721Metadata-symbol}.
*/
function symbol() public view virtual returns (string memory) {
return _symbol;
}
/**
* @dev See {IERC721Metadata-tokenURI}.
*/
function tokenURI(uint256 tokenId) public view virtual returns (string memory) {
_requireOwned(tokenId);
string memory baseURI = _baseURI();
return bytes(baseURI).length > 0 ? string.concat(baseURI, tokenId.toString()) : "";
}
/**
* @dev Base URI for computing {tokenURI}. If set, the resulting URI for each
* token will be the concatenation of the `baseURI` and the `tokenId`. Empty
* by default, can be overridden in child contracts.
*/
function _baseURI() internal view virtual returns (string memory) {
return "";
}
/**
* @dev See {IERC721-approve}.
*/
function approve(address to, uint256 tokenId) public virtual {
_approve(to, tokenId, _msgSender());
}
/**
* @dev See {IERC721-getApproved}.
*/
function getApproved(uint256 tokenId) public view virtual returns (address) {
_requireOwned(tokenId);
return _getApproved(tokenId);
}
/**
* @dev See {IERC721-setApprovalForAll}.
*/
function setApprovalForAll(address operator, bool approved) public virtual {
_setApprovalForAll(_msgSender(), operator, approved);
}
/**
* @dev See {IERC721-isApprovedForAll}.
*/
function isApprovedForAll(address owner, address operator) public view virtual returns (bool) {
return _operatorApprovals[owner][operator];
}
/**
* @dev See {IERC721-transferFrom}.
*/
function transferFrom(address from, address to, uint256 tokenId) public virtual {
if (to == address(0)) {
revert ERC721InvalidReceiver(address(0));
}
// Setting an "auth" arguments enables the `_isAuthorized` check which verifies that the token exists
// (from != 0). Therefore, it is not needed to verify that the return value is not 0 here.
address previousOwner = _update(to, tokenId, _msgSender());
if (previousOwner != from) {
revert ERC721IncorrectOwner(from, tokenId, previousOwner);
}
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(address from, address to, uint256 tokenId) public {
safeTransferFrom(from, to, tokenId, "");
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) public virtual {
transferFrom(from, to, tokenId);
ERC721Utils.checkOnERC721Received(_msgSender(), from, to, tokenId, data);
}
/**
* @dev Returns the owner of the `tokenId`. Does NOT revert if token doesn't exist
*
* IMPORTANT: Any overrides to this function that add ownership of tokens not tracked by the
* core ERC-721 logic MUST be matched with the use of {_increaseBalance} to keep balances
* consistent with ownership. The invariant to preserve is that for any address `a` the value returned by
* `balanceOf(a)` must be equal to the number of tokens such that `_ownerOf(tokenId)` is `a`.
*/
function _ownerOf(uint256 tokenId) internal view virtual returns (address) {
return _owners[tokenId];
}
/**
* @dev Returns the approved address for `tokenId`. Returns 0 if `tokenId` is not minted.
*/
function _getApproved(uint256 tokenId) internal view virtual returns (address) {
return _tokenApprovals[tokenId];
}
/**
* @dev Returns whether `spender` is allowed to manage `owner`'s tokens, or `tokenId` in
* particular (ignoring whether it is owned by `owner`).
*
* WARNING: This function assumes that `owner` is the actual owner of `tokenId` and does not verify this
* assumption.
*/
function _isAuthorized(address owner, address spender, uint256 tokenId) internal view virtual returns (bool) {
return
spender != address(0) &&
(owner == spender || isApprovedForAll(owner, spender) || _getApproved(tokenId) == spender);
}
/**
* @dev Checks if `spender` can operate on `tokenId`, assuming the provided `owner` is the actual owner.
* Reverts if:
* - `spender` does not have approval from `owner` for `tokenId`.
* - `spender` does not have approval to manage all of `owner`'s assets.
*
* WARNING: This function assumes that `owner` is the actual owner of `tokenId` and does not verify this
* assumption.
*/
function _checkAuthorized(address owner, address spender, uint256 tokenId) internal view virtual {
if (!_isAuthorized(owner, spender, tokenId)) {
if (owner == address(0)) {
revert ERC721NonexistentToken(tokenId);
} else {
revert ERC721InsufficientApproval(spender, tokenId);
}
}
}
/**
* @dev Unsafe write access to the balances, used by extensions that "mint" tokens using an {ownerOf} override.
*
* NOTE: the value is limited to type(uint128).max. This protect against _balance overflow. It is unrealistic that
* a uint256 would ever overflow from increments when these increments are bounded to uint128 values.
*
* WARNING: Increasing an account's balance using this function tends to be paired with an override of the
* {_ownerOf} function to resolve the ownership of the corresponding tokens so that balances and ownership
* remain consistent with one another.
*/
function _increaseBalance(address account, uint128 value) internal virtual {
unchecked {
_balances[account] += value;
}
}
/**
* @dev Transfers `tokenId` from its current owner to `to`, or alternatively mints (or burns) if the current owner
* (or `to`) is the zero address. Returns the owner of the `tokenId` before the update.
*
* The `auth` argument is optional. If the value passed is non 0, then this function will check that
* `auth` is either the owner of the token, or approved to operate on the token (by the owner).
*
* Emits a {Transfer} event.
*
* NOTE: If overriding this function in a way that tracks balances, see also {_increaseBalance}.
*/
function _update(address to, uint256 tokenId, address auth) internal virtual returns (address) {
address from = _ownerOf(tokenId);
// Perform (optional) operator check
if (auth != address(0)) {
_checkAuthorized(from, auth, tokenId);
}
// Execute the update
if (from != address(0)) {
// Clear approval. No need to re-authorize or emit the Approval event
_approve(address(0), tokenId, address(0), false);
unchecked {
_balances[from] -= 1;
}
}
if (to != address(0)) {
unchecked {
_balances[to] += 1;
}
}
_owners[tokenId] = to;
emit Transfer(from, to, tokenId);
return from;
}
/**
* @dev Mints `tokenId` and transfers it to `to`.
*
* WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
*
* Requirements:
*
* - `tokenId` must not exist.
* - `to` cannot be the zero address.
*
* Emits a {Transfer} event.
*/
function _mint(address to, uint256 tokenId) internal {
if (to == address(0)) {
revert ERC721InvalidReceiver(address(0));
}
address previousOwner = _update(to, tokenId, address(0));
if (previousOwner != address(0)) {
revert ERC721InvalidSender(address(0));
}
}
/**
* @dev Mints `tokenId`, transfers it to `to` and checks for `to` acceptance.
*
* Requirements:
*
* - `tokenId` must not exist.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeMint(address to, uint256 tokenId) internal {
_safeMint(to, tokenId, "");
}
/**
* @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
* forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
*/
function _safeMint(address to, uint256 tokenId, bytes memory data) internal virtual {
_mint(to, tokenId);
ERC721Utils.checkOnERC721Received(_msgSender(), address(0), to, tokenId, data);
}
/**
* @dev Destroys `tokenId`.
* The approval is cleared when the token is burned.
* This is an internal function that does not check if the sender is authorized to operate on the token.
*
* Requirements:
*
* - `tokenId` must exist.
*
* Emits a {Transfer} event.
*/
function _burn(uint256 tokenId) internal {
address previousOwner = _update(address(0), tokenId, address(0));
if (previousOwner == address(0)) {
revert ERC721NonexistentToken(tokenId);
}
}
/**
* @dev Transfers `tokenId` from `from` to `to`.
* As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
*
* Emits a {Transfer} event.
*/
function _transfer(address from, address to, uint256 tokenId) internal {
if (to == address(0)) {
revert ERC721InvalidReceiver(address(0));
}
address previousOwner = _update(to, tokenId, address(0));
if (previousOwner == address(0)) {
revert ERC721NonexistentToken(tokenId);
} else if (previousOwner != from) {
revert ERC721IncorrectOwner(from, tokenId, previousOwner);
}
}
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking that contract recipients
* are aware of the ERC-721 standard to prevent tokens from being forever locked.
*
* `data` is additional data, it has no specified format and it is sent in call to `to`.
*
* This internal function is like {safeTransferFrom} in the sense that it invokes
* {IERC721Receiver-onERC721Received} on the receiver, and can be used to e.g.
* implement alternative mechanisms to perform token transfer, such as signature-based.
*
* Requirements:
*
* - `tokenId` token must exist and be owned by `from`.
* - `to` cannot be the zero address.
* - `from` cannot be the zero address.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeTransfer(address from, address to, uint256 tokenId) internal {
_safeTransfer(from, to, tokenId, "");
}
/**
* @dev Same as {xref-ERC721-_safeTransfer-address-address-uint256-}[`_safeTransfer`], with an additional `data` parameter which is
* forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
*/
function _safeTransfer(address from, address to, uint256 tokenId, bytes memory data) internal virtual {
_transfer(from, to, tokenId);
ERC721Utils.checkOnERC721Received(_msgSender(), from, to, tokenId, data);
}
/**
* @dev Approve `to` to operate on `tokenId`
*
* The `auth` argument is optional. If the value passed is non 0, then this function will check that `auth` is
* either the owner of the token, or approved to operate on all tokens held by this owner.
*
* Emits an {Approval} event.
*
* Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.
*/
function _approve(address to, uint256 tokenId, address auth) internal {
_approve(to, tokenId, auth, true);
}
/**
* @dev Variant of `_approve` with an optional flag to enable or disable the {Approval} event. The event is not
* emitted in the context of transfers.
*/
function _approve(address to, uint256 tokenId, address auth, bool emitEvent) internal virtual {
// Avoid reading the owner unless necessary
if (emitEvent || auth != address(0)) {
address owner = _requireOwned(tokenId);
// We do not use _isAuthorized because single-token approvals should not be able to call approve
if (auth != address(0) && owner != auth && !isApprovedForAll(owner, auth)) {
revert ERC721InvalidApprover(auth);
}
if (emitEvent) {
emit Approval(owner, to, tokenId);
}
}
_tokenApprovals[tokenId] = to;
}
/**
* @dev Approve `operator` to operate on all of `owner` tokens
*
* Requirements:
* - operator can't be the address zero.
*
* Emits an {ApprovalForAll} event.
*/
function _setApprovalForAll(address owner, address operator, bool approved) internal virtual {
if (operator == address(0)) {
revert ERC721InvalidOperator(operator);
}
_operatorApprovals[owner][operator] = approved;
emit ApprovalForAll(owner, operator, approved);
}
/**
* @dev Reverts if the `tokenId` doesn't have a current owner (it hasn't been minted, or it has been burned).
* Returns the owner.
*
* Overrides to ownership logic should be done to {_ownerOf}.
*/
function _requireOwned(uint256 tokenId) internal view returns (address) {
address owner = _ownerOf(tokenId);
if (owner == address(0)) {
revert ERC721NonexistentToken(tokenId);
}
return owner;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC721Receiver.sol)
pragma solidity ^0.8.20;
import {IERC721Receiver} from "../token/ERC721/IERC721Receiver.sol";// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/structs/EnumerableSet.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.
pragma solidity ^0.8.20;
/**
* @dev Library for managing
* https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
* types.
*
* Sets have the following properties:
*
* - Elements are added, removed, and checked for existence in constant time
* (O(1)).
* - Elements are enumerated in O(n). No guarantees are made on the ordering.
*
* ```solidity
* contract Example {
* // Add the library methods
* using EnumerableSet for EnumerableSet.AddressSet;
*
* // Declare a set state variable
* EnumerableSet.AddressSet private mySet;
* }
* ```
*
* As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
* and `uint256` (`UintSet`) are supported.
*
* [WARNING]
* ====
* Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
* unusable.
* See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
*
* In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an
* array of EnumerableSet.
* ====
*/
library EnumerableSet {
// To implement this library for multiple types with as little code
// repetition as possible, we write it in terms of a generic Set type with
// bytes32 values.
// The Set implementation uses private functions, and user-facing
// implementations (such as AddressSet) are just wrappers around the
// underlying Set.
// This means that we can only create new EnumerableSets for types that fit
// in bytes32.
struct Set {
// Storage of set values
bytes32[] _values;
// Position is the index of the value in the `values` array plus 1.
// Position 0 is used to mean a value is not in the set.
mapping(bytes32 value => uint256) _positions;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function _add(Set storage set, bytes32 value) private returns (bool) {
if (!_contains(set, value)) {
set._values.push(value);
// The value is stored at length-1, but we add 1 to all indexes
// and use 0 as a sentinel value
set._positions[value] = set._values.length;
return true;
} else {
return false;
}
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function _remove(Set storage set, bytes32 value) private returns (bool) {
// We cache the value's position to prevent multiple reads from the same storage slot
uint256 position = set._positions[value];
if (position != 0) {
// Equivalent to contains(set, value)
// To delete an element from the _values array in O(1), we swap the element to delete with the last one in
// the array, and then remove the last element (sometimes called as 'swap and pop').
// This modifies the order of the array, as noted in {at}.
uint256 valueIndex = position - 1;
uint256 lastIndex = set._values.length - 1;
if (valueIndex != lastIndex) {
bytes32 lastValue = set._values[lastIndex];
// Move the lastValue to the index where the value to delete is
set._values[valueIndex] = lastValue;
// Update the tracked position of the lastValue (that was just moved)
set._positions[lastValue] = position;
}
// Delete the slot where the moved value was stored
set._values.pop();
// Delete the tracked position for the deleted slot
delete set._positions[value];
return true;
} else {
return false;
}
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function _contains(Set storage set, bytes32 value) private view returns (bool) {
return set._positions[value] != 0;
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function _length(Set storage set) private view returns (uint256) {
return set._values.length;
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function _at(Set storage set, uint256 index) private view returns (bytes32) {
return set._values[index];
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function _values(Set storage set) private view returns (bytes32[] memory) {
return set._values;
}
// Bytes32Set
struct Bytes32Set {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _add(set._inner, value);
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _remove(set._inner, value);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
return _contains(set._inner, value);
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(Bytes32Set storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
return _at(set._inner, index);
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
bytes32[] memory store = _values(set._inner);
bytes32[] memory result;
assembly ("memory-safe") {
result := store
}
return result;
}
// AddressSet
struct AddressSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(AddressSet storage set, address value) internal returns (bool) {
return _add(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(AddressSet storage set, address value) internal returns (bool) {
return _remove(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(AddressSet storage set, address value) internal view returns (bool) {
return _contains(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(AddressSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(AddressSet storage set, uint256 index) internal view returns (address) {
return address(uint160(uint256(_at(set._inner, index))));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(AddressSet storage set) internal view returns (address[] memory) {
bytes32[] memory store = _values(set._inner);
address[] memory result;
assembly ("memory-safe") {
result := store
}
return result;
}
// UintSet
struct UintSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(UintSet storage set, uint256 value) internal returns (bool) {
return _add(set._inner, bytes32(value));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(UintSet storage set, uint256 value) internal returns (bool) {
return _remove(set._inner, bytes32(value));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(UintSet storage set, uint256 value) internal view returns (bool) {
return _contains(set._inner, bytes32(value));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(UintSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(UintSet storage set, uint256 index) internal view returns (uint256) {
return uint256(_at(set._inner, index));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(UintSet storage set) internal view returns (uint256[] memory) {
bytes32[] memory store = _values(set._inner);
uint256[] memory result;
assembly ("memory-safe") {
result := store
}
return result;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Strings.sol)
pragma solidity ^0.8.20;
import {Math} from "./math/Math.sol";
import {SafeCast} from "./math/SafeCast.sol";
import {SignedMath} from "./math/SignedMath.sol";
/**
* @dev String operations.
*/
library Strings {
using SafeCast for *;
bytes16 private constant HEX_DIGITS = "0123456789abcdef";
uint8 private constant ADDRESS_LENGTH = 20;
/**
* @dev The `value` string doesn't fit in the specified `length`.
*/
error StringsInsufficientHexLength(uint256 value, uint256 length);
/**
* @dev The string being parsed contains characters that are not in scope of the given base.
*/
error StringsInvalidChar();
/**
* @dev The string being parsed is not a properly formatted address.
*/
error StringsInvalidAddressFormat();
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = Math.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
assembly ("memory-safe") {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
assembly ("memory-safe") {
mstore8(ptr, byte(mod(value, 10), HEX_DIGITS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
/**
* @dev Converts a `int256` to its ASCII `string` decimal representation.
*/
function toStringSigned(int256 value) internal pure returns (string memory) {
return string.concat(value < 0 ? "-" : "", toString(SignedMath.abs(value)));
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, Math.log256(value) + 1);
}
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
uint256 localValue = value;
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = HEX_DIGITS[localValue & 0xf];
localValue >>= 4;
}
if (localValue != 0) {
revert StringsInsufficientHexLength(value, length);
}
return string(buffer);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal
* representation.
*/
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), ADDRESS_LENGTH);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its checksummed ASCII `string` hexadecimal
* representation, according to EIP-55.
*/
function toChecksumHexString(address addr) internal pure returns (string memory) {
bytes memory buffer = bytes(toHexString(addr));
// hash the hex part of buffer (skip length + 2 bytes, length 40)
uint256 hashValue;
assembly ("memory-safe") {
hashValue := shr(96, keccak256(add(buffer, 0x22), 40))
}
for (uint256 i = 41; i > 1; --i) {
// possible values for buffer[i] are 48 (0) to 57 (9) and 97 (a) to 102 (f)
if (hashValue & 0xf > 7 && uint8(buffer[i]) > 96) {
// case shift by xoring with 0x20
buffer[i] ^= 0x20;
}
hashValue >>= 4;
}
return string(buffer);
}
/**
* @dev Returns true if the two strings are equal.
*/
function equal(string memory a, string memory b) internal pure returns (bool) {
return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b));
}
/**
* @dev Parse a decimal string and returns the value as a `uint256`.
*
* Requirements:
* - The string must be formatted as `[0-9]*`
* - The result must fit into an `uint256` type
*/
function parseUint(string memory input) internal pure returns (uint256) {
return parseUint(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseUint} that parses a substring of `input` located between position `begin` (included) and
* `end` (excluded).
*
* Requirements:
* - The substring must be formatted as `[0-9]*`
* - The result must fit into an `uint256` type
*/
function parseUint(string memory input, uint256 begin, uint256 end) internal pure returns (uint256) {
(bool success, uint256 value) = tryParseUint(input, begin, end);
if (!success) revert StringsInvalidChar();
return value;
}
/**
* @dev Variant of {parseUint-string} that returns false if the parsing fails because of an invalid character.
*
* NOTE: This function will revert if the result does not fit in a `uint256`.
*/
function tryParseUint(string memory input) internal pure returns (bool success, uint256 value) {
return _tryParseUintUncheckedBounds(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseUint-string-uint256-uint256} that returns false if the parsing fails because of an invalid
* character.
*
* NOTE: This function will revert if the result does not fit in a `uint256`.
*/
function tryParseUint(
string memory input,
uint256 begin,
uint256 end
) internal pure returns (bool success, uint256 value) {
if (end > bytes(input).length || begin > end) return (false, 0);
return _tryParseUintUncheckedBounds(input, begin, end);
}
/**
* @dev Implementation of {tryParseUint} that does not check bounds. Caller should make sure that
* `begin <= end <= input.length`. Other inputs would result in undefined behavior.
*/
function _tryParseUintUncheckedBounds(
string memory input,
uint256 begin,
uint256 end
) private pure returns (bool success, uint256 value) {
bytes memory buffer = bytes(input);
uint256 result = 0;
for (uint256 i = begin; i < end; ++i) {
uint8 chr = _tryParseChr(bytes1(_unsafeReadBytesOffset(buffer, i)));
if (chr > 9) return (false, 0);
result *= 10;
result += chr;
}
return (true, result);
}
/**
* @dev Parse a decimal string and returns the value as a `int256`.
*
* Requirements:
* - The string must be formatted as `[-+]?[0-9]*`
* - The result must fit in an `int256` type.
*/
function parseInt(string memory input) internal pure returns (int256) {
return parseInt(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseInt-string} that parses a substring of `input` located between position `begin` (included) and
* `end` (excluded).
*
* Requirements:
* - The substring must be formatted as `[-+]?[0-9]*`
* - The result must fit in an `int256` type.
*/
function parseInt(string memory input, uint256 begin, uint256 end) internal pure returns (int256) {
(bool success, int256 value) = tryParseInt(input, begin, end);
if (!success) revert StringsInvalidChar();
return value;
}
/**
* @dev Variant of {parseInt-string} that returns false if the parsing fails because of an invalid character or if
* the result does not fit in a `int256`.
*
* NOTE: This function will revert if the absolute value of the result does not fit in a `uint256`.
*/
function tryParseInt(string memory input) internal pure returns (bool success, int256 value) {
return _tryParseIntUncheckedBounds(input, 0, bytes(input).length);
}
uint256 private constant ABS_MIN_INT256 = 2 ** 255;
/**
* @dev Variant of {parseInt-string-uint256-uint256} that returns false if the parsing fails because of an invalid
* character or if the result does not fit in a `int256`.
*
* NOTE: This function will revert if the absolute value of the result does not fit in a `uint256`.
*/
function tryParseInt(
string memory input,
uint256 begin,
uint256 end
) internal pure returns (bool success, int256 value) {
if (end > bytes(input).length || begin > end) return (false, 0);
return _tryParseIntUncheckedBounds(input, begin, end);
}
/**
* @dev Implementation of {tryParseInt} that does not check bounds. Caller should make sure that
* `begin <= end <= input.length`. Other inputs would result in undefined behavior.
*/
function _tryParseIntUncheckedBounds(
string memory input,
uint256 begin,
uint256 end
) private pure returns (bool success, int256 value) {
bytes memory buffer = bytes(input);
// Check presence of a negative sign.
bytes1 sign = begin == end ? bytes1(0) : bytes1(_unsafeReadBytesOffset(buffer, begin)); // don't do out-of-bound (possibly unsafe) read if sub-string is empty
bool positiveSign = sign == bytes1("+");
bool negativeSign = sign == bytes1("-");
uint256 offset = (positiveSign || negativeSign).toUint();
(bool absSuccess, uint256 absValue) = tryParseUint(input, begin + offset, end);
if (absSuccess && absValue < ABS_MIN_INT256) {
return (true, negativeSign ? -int256(absValue) : int256(absValue));
} else if (absSuccess && negativeSign && absValue == ABS_MIN_INT256) {
return (true, type(int256).min);
} else return (false, 0);
}
/**
* @dev Parse a hexadecimal string (with or without "0x" prefix), and returns the value as a `uint256`.
*
* Requirements:
* - The string must be formatted as `(0x)?[0-9a-fA-F]*`
* - The result must fit in an `uint256` type.
*/
function parseHexUint(string memory input) internal pure returns (uint256) {
return parseHexUint(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseHexUint} that parses a substring of `input` located between position `begin` (included) and
* `end` (excluded).
*
* Requirements:
* - The substring must be formatted as `(0x)?[0-9a-fA-F]*`
* - The result must fit in an `uint256` type.
*/
function parseHexUint(string memory input, uint256 begin, uint256 end) internal pure returns (uint256) {
(bool success, uint256 value) = tryParseHexUint(input, begin, end);
if (!success) revert StringsInvalidChar();
return value;
}
/**
* @dev Variant of {parseHexUint-string} that returns false if the parsing fails because of an invalid character.
*
* NOTE: This function will revert if the result does not fit in a `uint256`.
*/
function tryParseHexUint(string memory input) internal pure returns (bool success, uint256 value) {
return _tryParseHexUintUncheckedBounds(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseHexUint-string-uint256-uint256} that returns false if the parsing fails because of an
* invalid character.
*
* NOTE: This function will revert if the result does not fit in a `uint256`.
*/
function tryParseHexUint(
string memory input,
uint256 begin,
uint256 end
) internal pure returns (bool success, uint256 value) {
if (end > bytes(input).length || begin > end) return (false, 0);
return _tryParseHexUintUncheckedBounds(input, begin, end);
}
/**
* @dev Implementation of {tryParseHexUint} that does not check bounds. Caller should make sure that
* `begin <= end <= input.length`. Other inputs would result in undefined behavior.
*/
function _tryParseHexUintUncheckedBounds(
string memory input,
uint256 begin,
uint256 end
) private pure returns (bool success, uint256 value) {
bytes memory buffer = bytes(input);
// skip 0x prefix if present
bool hasPrefix = (end > begin + 1) && bytes2(_unsafeReadBytesOffset(buffer, begin)) == bytes2("0x"); // don't do out-of-bound (possibly unsafe) read if sub-string is empty
uint256 offset = hasPrefix.toUint() * 2;
uint256 result = 0;
for (uint256 i = begin + offset; i < end; ++i) {
uint8 chr = _tryParseChr(bytes1(_unsafeReadBytesOffset(buffer, i)));
if (chr > 15) return (false, 0);
result *= 16;
unchecked {
// Multiplying by 16 is equivalent to a shift of 4 bits (with additional overflow check).
// This guaratees that adding a value < 16 will not cause an overflow, hence the unchecked.
result += chr;
}
}
return (true, result);
}
/**
* @dev Parse a hexadecimal string (with or without "0x" prefix), and returns the value as an `address`.
*
* Requirements:
* - The string must be formatted as `(0x)?[0-9a-fA-F]{40}`
*/
function parseAddress(string memory input) internal pure returns (address) {
return parseAddress(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseAddress} that parses a substring of `input` located between position `begin` (included) and
* `end` (excluded).
*
* Requirements:
* - The substring must be formatted as `(0x)?[0-9a-fA-F]{40}`
*/
function parseAddress(string memory input, uint256 begin, uint256 end) internal pure returns (address) {
(bool success, address value) = tryParseAddress(input, begin, end);
if (!success) revert StringsInvalidAddressFormat();
return value;
}
/**
* @dev Variant of {parseAddress-string} that returns false if the parsing fails because the input is not a properly
* formatted address. See {parseAddress} requirements.
*/
function tryParseAddress(string memory input) internal pure returns (bool success, address value) {
return tryParseAddress(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseAddress-string-uint256-uint256} that returns false if the parsing fails because input is not a properly
* formatted address. See {parseAddress} requirements.
*/
function tryParseAddress(
string memory input,
uint256 begin,
uint256 end
) internal pure returns (bool success, address value) {
if (end > bytes(input).length || begin > end) return (false, address(0));
bool hasPrefix = (end > begin + 1) && bytes2(_unsafeReadBytesOffset(bytes(input), begin)) == bytes2("0x"); // don't do out-of-bound (possibly unsafe) read if sub-string is empty
uint256 expectedLength = 40 + hasPrefix.toUint() * 2;
// check that input is the correct length
if (end - begin == expectedLength) {
// length guarantees that this does not overflow, and value is at most type(uint160).max
(bool s, uint256 v) = _tryParseHexUintUncheckedBounds(input, begin, end);
return (s, address(uint160(v)));
} else {
return (false, address(0));
}
}
function _tryParseChr(bytes1 chr) private pure returns (uint8) {
uint8 value = uint8(chr);
// Try to parse `chr`:
// - Case 1: [0-9]
// - Case 2: [a-f]
// - Case 3: [A-F]
// - otherwise not supported
unchecked {
if (value > 47 && value < 58) value -= 48;
else if (value > 96 && value < 103) value -= 87;
else if (value > 64 && value < 71) value -= 55;
else return type(uint8).max;
}
return value;
}
/**
* @dev Reads a bytes32 from a bytes array without bounds checking.
*
* NOTE: making this function internal would mean it could be used with memory unsafe offset, and marking the
* assembly block as such would prevent some optimizations.
*/
function _unsafeReadBytesOffset(bytes memory buffer, uint256 offset) private pure returns (bytes32 value) {
// This is not memory safe in the general case, but all calls to this private function are within bounds.
assembly ("memory-safe") {
value := mload(add(buffer, add(0x20, offset)))
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import {Currency} from "../types/Currency.sol";
import {PoolKey} from "../types/PoolKey.sol";
import {IHooks} from "./IHooks.sol";
import {IERC6909Claims} from "./external/IERC6909Claims.sol";
import {IProtocolFees} from "./IProtocolFees.sol";
import {BalanceDelta} from "../types/BalanceDelta.sol";
import {PoolId} from "../types/PoolId.sol";
import {IExtsload} from "./IExtsload.sol";
import {IExttload} from "./IExttload.sol";
/// @notice Interface for the PoolManager
interface IPoolManager is IProtocolFees, IERC6909Claims, IExtsload, IExttload {
/// @notice Thrown when a currency is not netted out after the contract is unlocked
error CurrencyNotSettled();
/// @notice Thrown when trying to interact with a non-initialized pool
error PoolNotInitialized();
/// @notice Thrown when unlock is called, but the contract is already unlocked
error AlreadyUnlocked();
/// @notice Thrown when a function is called that requires the contract to be unlocked, but it is not
error ManagerLocked();
/// @notice Pools are limited to type(int16).max tickSpacing in #initialize, to prevent overflow
error TickSpacingTooLarge(int24 tickSpacing);
/// @notice Pools must have a positive non-zero tickSpacing passed to #initialize
error TickSpacingTooSmall(int24 tickSpacing);
/// @notice PoolKey must have currencies where address(currency0) < address(currency1)
error CurrenciesOutOfOrderOrEqual(address currency0, address currency1);
/// @notice Thrown when a call to updateDynamicLPFee is made by an address that is not the hook,
/// or on a pool that does not have a dynamic swap fee.
error UnauthorizedDynamicLPFeeUpdate();
/// @notice Thrown when trying to swap amount of 0
error SwapAmountCannotBeZero();
///@notice Thrown when native currency is passed to a non native settlement
error NonzeroNativeValue();
/// @notice Thrown when `clear` is called with an amount that is not exactly equal to the open currency delta.
error MustClearExactPositiveDelta();
/// @notice Emitted when a new pool is initialized
/// @param id The abi encoded hash of the pool key struct for the new pool
/// @param currency0 The first currency of the pool by address sort order
/// @param currency1 The second currency of the pool by address sort order
/// @param fee The fee collected upon every swap in the pool, denominated in hundredths of a bip
/// @param tickSpacing The minimum number of ticks between initialized ticks
/// @param hooks The hooks contract address for the pool, or address(0) if none
/// @param sqrtPriceX96 The price of the pool on initialization
/// @param tick The initial tick of the pool corresponding to the initialized price
event Initialize(
PoolId indexed id,
Currency indexed currency0,
Currency indexed currency1,
uint24 fee,
int24 tickSpacing,
IHooks hooks,
uint160 sqrtPriceX96,
int24 tick
);
/// @notice Emitted when a liquidity position is modified
/// @param id The abi encoded hash of the pool key struct for the pool that was modified
/// @param sender The address that modified the pool
/// @param tickLower The lower tick of the position
/// @param tickUpper The upper tick of the position
/// @param liquidityDelta The amount of liquidity that was added or removed
/// @param salt The extra data to make positions unique
event ModifyLiquidity(
PoolId indexed id, address indexed sender, int24 tickLower, int24 tickUpper, int256 liquidityDelta, bytes32 salt
);
/// @notice Emitted for swaps between currency0 and currency1
/// @param id The abi encoded hash of the pool key struct for the pool that was modified
/// @param sender The address that initiated the swap call, and that received the callback
/// @param amount0 The delta of the currency0 balance of the pool
/// @param amount1 The delta of the currency1 balance of the pool
/// @param sqrtPriceX96 The sqrt(price) of the pool after the swap, as a Q64.96
/// @param liquidity The liquidity of the pool after the swap
/// @param tick The log base 1.0001 of the price of the pool after the swap
/// @param fee The swap fee in hundredths of a bip
event Swap(
PoolId indexed id,
address indexed sender,
int128 amount0,
int128 amount1,
uint160 sqrtPriceX96,
uint128 liquidity,
int24 tick,
uint24 fee
);
/// @notice Emitted for donations
/// @param id The abi encoded hash of the pool key struct for the pool that was donated to
/// @param sender The address that initiated the donate call
/// @param amount0 The amount donated in currency0
/// @param amount1 The amount donated in currency1
event Donate(PoolId indexed id, address indexed sender, uint256 amount0, uint256 amount1);
/// @notice All interactions on the contract that account deltas require unlocking. A caller that calls `unlock` must implement
/// `IUnlockCallback(msg.sender).unlockCallback(data)`, where they interact with the remaining functions on this contract.
/// @dev The only functions callable without an unlocking are `initialize` and `updateDynamicLPFee`
/// @param data Any data to pass to the callback, via `IUnlockCallback(msg.sender).unlockCallback(data)`
/// @return The data returned by the call to `IUnlockCallback(msg.sender).unlockCallback(data)`
function unlock(bytes calldata data) external returns (bytes memory);
/// @notice Initialize the state for a given pool ID
/// @dev A swap fee totaling MAX_SWAP_FEE (100%) makes exact output swaps impossible since the input is entirely consumed by the fee
/// @param key The pool key for the pool to initialize
/// @param sqrtPriceX96 The initial square root price
/// @return tick The initial tick of the pool
function initialize(PoolKey memory key, uint160 sqrtPriceX96) external returns (int24 tick);
struct ModifyLiquidityParams {
// the lower and upper tick of the position
int24 tickLower;
int24 tickUpper;
// how to modify the liquidity
int256 liquidityDelta;
// a value to set if you want unique liquidity positions at the same range
bytes32 salt;
}
/// @notice Modify the liquidity for the given pool
/// @dev Poke by calling with a zero liquidityDelta
/// @param key The pool to modify liquidity in
/// @param params The parameters for modifying the liquidity
/// @param hookData The data to pass through to the add/removeLiquidity hooks
/// @return callerDelta The balance delta of the caller of modifyLiquidity. This is the total of both principal, fee deltas, and hook deltas if applicable
/// @return feesAccrued The balance delta of the fees generated in the liquidity range. Returned for informational purposes
function modifyLiquidity(PoolKey memory key, ModifyLiquidityParams memory params, bytes calldata hookData)
external
returns (BalanceDelta callerDelta, BalanceDelta feesAccrued);
struct SwapParams {
/// Whether to swap token0 for token1 or vice versa
bool zeroForOne;
/// The desired input amount if negative (exactIn), or the desired output amount if positive (exactOut)
int256 amountSpecified;
/// The sqrt price at which, if reached, the swap will stop executing
uint160 sqrtPriceLimitX96;
}
/// @notice Swap against the given pool
/// @param key The pool to swap in
/// @param params The parameters for swapping
/// @param hookData The data to pass through to the swap hooks
/// @return swapDelta The balance delta of the address swapping
/// @dev Swapping on low liquidity pools may cause unexpected swap amounts when liquidity available is less than amountSpecified.
/// Additionally note that if interacting with hooks that have the BEFORE_SWAP_RETURNS_DELTA_FLAG or AFTER_SWAP_RETURNS_DELTA_FLAG
/// the hook may alter the swap input/output. Integrators should perform checks on the returned swapDelta.
function swap(PoolKey memory key, SwapParams memory params, bytes calldata hookData)
external
returns (BalanceDelta swapDelta);
/// @notice Donate the given currency amounts to the in-range liquidity providers of a pool
/// @dev Calls to donate can be frontrun adding just-in-time liquidity, with the aim of receiving a portion donated funds.
/// Donors should keep this in mind when designing donation mechanisms.
/// @dev This function donates to in-range LPs at slot0.tick. In certain edge-cases of the swap algorithm, the `sqrtPrice` of
/// a pool can be at the lower boundary of tick `n`, but the `slot0.tick` of the pool is already `n - 1`. In this case a call to
/// `donate` would donate to tick `n - 1` (slot0.tick) not tick `n` (getTickAtSqrtPrice(slot0.sqrtPriceX96)).
/// Read the comments in `Pool.swap()` for more information about this.
/// @param key The key of the pool to donate to
/// @param amount0 The amount of currency0 to donate
/// @param amount1 The amount of currency1 to donate
/// @param hookData The data to pass through to the donate hooks
/// @return BalanceDelta The delta of the caller after the donate
function donate(PoolKey memory key, uint256 amount0, uint256 amount1, bytes calldata hookData)
external
returns (BalanceDelta);
/// @notice Writes the current ERC20 balance of the specified currency to transient storage
/// This is used to checkpoint balances for the manager and derive deltas for the caller.
/// @dev This MUST be called before any ERC20 tokens are sent into the contract, but can be skipped
/// for native tokens because the amount to settle is determined by the sent value.
/// However, if an ERC20 token has been synced and not settled, and the caller instead wants to settle
/// native funds, this function can be called with the native currency to then be able to settle the native currency
function sync(Currency currency) external;
/// @notice Called by the user to net out some value owed to the user
/// @dev Will revert if the requested amount is not available, consider using `mint` instead
/// @dev Can also be used as a mechanism for free flash loans
/// @param currency The currency to withdraw from the pool manager
/// @param to The address to withdraw to
/// @param amount The amount of currency to withdraw
function take(Currency currency, address to, uint256 amount) external;
/// @notice Called by the user to pay what is owed
/// @return paid The amount of currency settled
function settle() external payable returns (uint256 paid);
/// @notice Called by the user to pay on behalf of another address
/// @param recipient The address to credit for the payment
/// @return paid The amount of currency settled
function settleFor(address recipient) external payable returns (uint256 paid);
/// @notice WARNING - Any currency that is cleared, will be non-retrievable, and locked in the contract permanently.
/// A call to clear will zero out a positive balance WITHOUT a corresponding transfer.
/// @dev This could be used to clear a balance that is considered dust.
/// Additionally, the amount must be the exact positive balance. This is to enforce that the caller is aware of the amount being cleared.
function clear(Currency currency, uint256 amount) external;
/// @notice Called by the user to move value into ERC6909 balance
/// @param to The address to mint the tokens to
/// @param id The currency address to mint to ERC6909s, as a uint256
/// @param amount The amount of currency to mint
/// @dev The id is converted to a uint160 to correspond to a currency address
/// If the upper 12 bytes are not 0, they will be 0-ed out
function mint(address to, uint256 id, uint256 amount) external;
/// @notice Called by the user to move value from ERC6909 balance
/// @param from The address to burn the tokens from
/// @param id The currency address to burn from ERC6909s, as a uint256
/// @param amount The amount of currency to burn
/// @dev The id is converted to a uint160 to correspond to a currency address
/// If the upper 12 bytes are not 0, they will be 0-ed out
function burn(address from, uint256 id, uint256 amount) external;
/// @notice Updates the pools lp fees for the a pool that has enabled dynamic lp fees.
/// @dev A swap fee totaling MAX_SWAP_FEE (100%) makes exact output swaps impossible since the input is entirely consumed by the fee
/// @param key The key of the pool to update dynamic LP fees for
/// @param newDynamicLPFee The new dynamic pool LP fee
function updateDynamicLPFee(PoolKey memory key, uint24 newDynamicLPFee) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";
import {PositionInfo} from "../libraries/PositionInfoLibrary.sol";
import {INotifier} from "./INotifier.sol";
import {IImmutableState} from "./IImmutableState.sol";
import {IERC721Permit_v4} from "./IERC721Permit_v4.sol";
import {IEIP712_v4} from "./IEIP712_v4.sol";
import {IMulticall_v4} from "./IMulticall_v4.sol";
import {IPoolInitializer_v4} from "./IPoolInitializer_v4.sol";
import {IUnorderedNonce} from "./IUnorderedNonce.sol";
import {IPermit2Forwarder} from "./IPermit2Forwarder.sol";
/// @title IPositionManager
/// @notice Interface for the PositionManager contract
interface IPositionManager is
INotifier,
IImmutableState,
IERC721Permit_v4,
IEIP712_v4,
IMulticall_v4,
IPoolInitializer_v4,
IUnorderedNonce,
IPermit2Forwarder
{
/// @notice Thrown when the caller is not approved to modify a position
error NotApproved(address caller);
/// @notice Thrown when the block.timestamp exceeds the user-provided deadline
error DeadlinePassed(uint256 deadline);
/// @notice Thrown when calling transfer, subscribe, or unsubscribe when the PoolManager is unlocked.
/// @dev This is to prevent hooks from being able to trigger notifications at the same time the position is being modified.
error PoolManagerMustBeLocked();
/// @notice Unlocks Uniswap v4 PoolManager and batches actions for modifying liquidity
/// @dev This is the standard entrypoint for the PositionManager
/// @param unlockData is an encoding of actions, and parameters for those actions
/// @param deadline is the deadline for the batched actions to be executed
function modifyLiquidities(bytes calldata unlockData, uint256 deadline) external payable;
/// @notice Batches actions for modifying liquidity without unlocking v4 PoolManager
/// @dev This must be called by a contract that has already unlocked the v4 PoolManager
/// @param actions the actions to perform
/// @param params the parameters to provide for the actions
function modifyLiquiditiesWithoutUnlock(bytes calldata actions, bytes[] calldata params) external payable;
/// @notice Used to get the ID that will be used for the next minted liquidity position
/// @return uint256 The next token ID
function nextTokenId() external view returns (uint256);
/// @notice Returns the liquidity of a position
/// @param tokenId the ERC721 tokenId
/// @return liquidity the position's liquidity, as a liquidityAmount
/// @dev this value can be processed as an amount0 and amount1 by using the LiquidityAmounts library
function getPositionLiquidity(uint256 tokenId) external view returns (uint128 liquidity);
/// @notice Returns the pool key and position info of a position
/// @param tokenId the ERC721 tokenId
/// @return poolKey the pool key of the position
/// @return PositionInfo a uint256 packed value holding information about the position including the range (tickLower, tickUpper)
function getPoolAndPositionInfo(uint256 tokenId) external view returns (PoolKey memory, PositionInfo);
/// @notice Returns the position info of a position
/// @param tokenId the ERC721 tokenId
/// @return a uint256 packed value holding information about the position including the range (tickLower, tickUpper)
function positionInfo(uint256 tokenId) external view returns (PositionInfo);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {Currency} from "./Currency.sol";
import {IHooks} from "../interfaces/IHooks.sol";
import {PoolIdLibrary} from "./PoolId.sol";
using PoolIdLibrary for PoolKey global;
/// @notice Returns the key for identifying a pool
struct PoolKey {
/// @notice The lower currency of the pool, sorted numerically
Currency currency0;
/// @notice The higher currency of the pool, sorted numerically
Currency currency1;
/// @notice The pool LP fee, capped at 1_000_000. If the highest bit is 1, the pool has a dynamic fee and must be exactly equal to 0x800000
uint24 fee;
/// @notice Ticks that involve positions must be a multiple of tick spacing
int24 tickSpacing;
/// @notice The hooks of the pool
IHooks hooks;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {PoolKey} from "./PoolKey.sol";
type PoolId is bytes32;
/// @notice Library for computing the ID of a pool
library PoolIdLibrary {
/// @notice Returns value equal to keccak256(abi.encode(poolKey))
function toId(PoolKey memory poolKey) internal pure returns (PoolId poolId) {
assembly ("memory-safe") {
// 0xa0 represents the total size of the poolKey struct (5 slots of 32 bytes)
poolId := keccak256(poolKey, 0xa0)
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {IERC20Minimal} from "../interfaces/external/IERC20Minimal.sol";
import {CustomRevert} from "../libraries/CustomRevert.sol";
type Currency is address;
using {greaterThan as >, lessThan as <, greaterThanOrEqualTo as >=, equals as ==} for Currency global;
using CurrencyLibrary for Currency global;
function equals(Currency currency, Currency other) pure returns (bool) {
return Currency.unwrap(currency) == Currency.unwrap(other);
}
function greaterThan(Currency currency, Currency other) pure returns (bool) {
return Currency.unwrap(currency) > Currency.unwrap(other);
}
function lessThan(Currency currency, Currency other) pure returns (bool) {
return Currency.unwrap(currency) < Currency.unwrap(other);
}
function greaterThanOrEqualTo(Currency currency, Currency other) pure returns (bool) {
return Currency.unwrap(currency) >= Currency.unwrap(other);
}
/// @title CurrencyLibrary
/// @dev This library allows for transferring and holding native tokens and ERC20 tokens
library CurrencyLibrary {
/// @notice Additional context for ERC-7751 wrapped error when a native transfer fails
error NativeTransferFailed();
/// @notice Additional context for ERC-7751 wrapped error when an ERC20 transfer fails
error ERC20TransferFailed();
/// @notice A constant to represent the native currency
Currency public constant ADDRESS_ZERO = Currency.wrap(address(0));
function transfer(Currency currency, address to, uint256 amount) internal {
// altered from https://github.com/transmissions11/solmate/blob/44a9963d4c78111f77caa0e65d677b8b46d6f2e6/src/utils/SafeTransferLib.sol
// modified custom error selectors
bool success;
if (currency.isAddressZero()) {
assembly ("memory-safe") {
// Transfer the ETH and revert if it fails.
success := call(gas(), to, amount, 0, 0, 0, 0)
}
// revert with NativeTransferFailed, containing the bubbled up error as an argument
if (!success) {
CustomRevert.bubbleUpAndRevertWith(to, bytes4(0), NativeTransferFailed.selector);
}
} else {
assembly ("memory-safe") {
// Get a pointer to some free memory.
let fmp := mload(0x40)
// Write the abi-encoded calldata into memory, beginning with the function selector.
mstore(fmp, 0xa9059cbb00000000000000000000000000000000000000000000000000000000)
mstore(add(fmp, 4), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "to" argument.
mstore(add(fmp, 36), amount) // Append the "amount" argument. Masking not required as it's a full 32 byte type.
success :=
and(
// Set success to whether the call reverted, if not we check it either
// returned exactly 1 (can't just be non-zero data), or had no return data.
or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),
// We use 68 because the length of our calldata totals up like so: 4 + 32 * 2.
// We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
// Counterintuitively, this call must be positioned second to the or() call in the
// surrounding and() call or else returndatasize() will be zero during the computation.
call(gas(), currency, 0, fmp, 68, 0, 32)
)
// Now clean the memory we used
mstore(fmp, 0) // 4 byte `selector` and 28 bytes of `to` were stored here
mstore(add(fmp, 0x20), 0) // 4 bytes of `to` and 28 bytes of `amount` were stored here
mstore(add(fmp, 0x40), 0) // 4 bytes of `amount` were stored here
}
// revert with ERC20TransferFailed, containing the bubbled up error as an argument
if (!success) {
CustomRevert.bubbleUpAndRevertWith(
Currency.unwrap(currency), IERC20Minimal.transfer.selector, ERC20TransferFailed.selector
);
}
}
}
function balanceOfSelf(Currency currency) internal view returns (uint256) {
if (currency.isAddressZero()) {
return address(this).balance;
} else {
return IERC20Minimal(Currency.unwrap(currency)).balanceOf(address(this));
}
}
function balanceOf(Currency currency, address owner) internal view returns (uint256) {
if (currency.isAddressZero()) {
return owner.balance;
} else {
return IERC20Minimal(Currency.unwrap(currency)).balanceOf(owner);
}
}
function isAddressZero(Currency currency) internal pure returns (bool) {
return Currency.unwrap(currency) == Currency.unwrap(ADDRESS_ZERO);
}
function toId(Currency currency) internal pure returns (uint256) {
return uint160(Currency.unwrap(currency));
}
// If the upper 12 bytes are non-zero, they will be zero-ed out
// Therefore, fromId() and toId() are not inverses of each other
function fromId(uint256 id) internal pure returns (Currency) {
return Currency.wrap(address(uint160(id)));
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {PoolId} from "../types/PoolId.sol";
import {IPoolManager} from "../interfaces/IPoolManager.sol";
import {Position} from "./Position.sol";
/// @notice A helper library to provide state getters that use extsload
library StateLibrary {
/// @notice index of pools mapping in the PoolManager
bytes32 public constant POOLS_SLOT = bytes32(uint256(6));
/// @notice index of feeGrowthGlobal0X128 in Pool.State
uint256 public constant FEE_GROWTH_GLOBAL0_OFFSET = 1;
// feeGrowthGlobal1X128 offset in Pool.State = 2
/// @notice index of liquidity in Pool.State
uint256 public constant LIQUIDITY_OFFSET = 3;
/// @notice index of TicksInfo mapping in Pool.State: mapping(int24 => TickInfo) ticks;
uint256 public constant TICKS_OFFSET = 4;
/// @notice index of tickBitmap mapping in Pool.State
uint256 public constant TICK_BITMAP_OFFSET = 5;
/// @notice index of Position.State mapping in Pool.State: mapping(bytes32 => Position.State) positions;
uint256 public constant POSITIONS_OFFSET = 6;
/**
* @notice Get Slot0 of the pool: sqrtPriceX96, tick, protocolFee, lpFee
* @dev Corresponds to pools[poolId].slot0
* @param manager The pool manager contract.
* @param poolId The ID of the pool.
* @return sqrtPriceX96 The square root of the price of the pool, in Q96 precision.
* @return tick The current tick of the pool.
* @return protocolFee The protocol fee of the pool.
* @return lpFee The swap fee of the pool.
*/
function getSlot0(IPoolManager manager, PoolId poolId)
internal
view
returns (uint160 sqrtPriceX96, int24 tick, uint24 protocolFee, uint24 lpFee)
{
// slot key of Pool.State value: `pools[poolId]`
bytes32 stateSlot = _getPoolStateSlot(poolId);
bytes32 data = manager.extsload(stateSlot);
// 24 bits |24bits|24bits |24 bits|160 bits
// 0x000000 |000bb8|000000 |ffff75 |0000000000000000fe3aa841ba359daa0ea9eff7
// ---------- | fee |protocolfee | tick | sqrtPriceX96
assembly ("memory-safe") {
// bottom 160 bits of data
sqrtPriceX96 := and(data, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)
// next 24 bits of data
tick := signextend(2, shr(160, data))
// next 24 bits of data
protocolFee := and(shr(184, data), 0xFFFFFF)
// last 24 bits of data
lpFee := and(shr(208, data), 0xFFFFFF)
}
}
/**
* @notice Retrieves the tick information of a pool at a specific tick.
* @dev Corresponds to pools[poolId].ticks[tick]
* @param manager The pool manager contract.
* @param poolId The ID of the pool.
* @param tick The tick to retrieve information for.
* @return liquidityGross The total position liquidity that references this tick
* @return liquidityNet The amount of net liquidity added (subtracted) when tick is crossed from left to right (right to left)
* @return feeGrowthOutside0X128 fee growth per unit of liquidity on the _other_ side of this tick (relative to the current tick)
* @return feeGrowthOutside1X128 fee growth per unit of liquidity on the _other_ side of this tick (relative to the current tick)
*/
function getTickInfo(IPoolManager manager, PoolId poolId, int24 tick)
internal
view
returns (
uint128 liquidityGross,
int128 liquidityNet,
uint256 feeGrowthOutside0X128,
uint256 feeGrowthOutside1X128
)
{
bytes32 slot = _getTickInfoSlot(poolId, tick);
// read all 3 words of the TickInfo struct
bytes32[] memory data = manager.extsload(slot, 3);
assembly ("memory-safe") {
let firstWord := mload(add(data, 32))
liquidityNet := sar(128, firstWord)
liquidityGross := and(firstWord, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)
feeGrowthOutside0X128 := mload(add(data, 64))
feeGrowthOutside1X128 := mload(add(data, 96))
}
}
/**
* @notice Retrieves the liquidity information of a pool at a specific tick.
* @dev Corresponds to pools[poolId].ticks[tick].liquidityGross and pools[poolId].ticks[tick].liquidityNet. A more gas efficient version of getTickInfo
* @param manager The pool manager contract.
* @param poolId The ID of the pool.
* @param tick The tick to retrieve liquidity for.
* @return liquidityGross The total position liquidity that references this tick
* @return liquidityNet The amount of net liquidity added (subtracted) when tick is crossed from left to right (right to left)
*/
function getTickLiquidity(IPoolManager manager, PoolId poolId, int24 tick)
internal
view
returns (uint128 liquidityGross, int128 liquidityNet)
{
bytes32 slot = _getTickInfoSlot(poolId, tick);
bytes32 value = manager.extsload(slot);
assembly ("memory-safe") {
liquidityNet := sar(128, value)
liquidityGross := and(value, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)
}
}
/**
* @notice Retrieves the fee growth outside a tick range of a pool
* @dev Corresponds to pools[poolId].ticks[tick].feeGrowthOutside0X128 and pools[poolId].ticks[tick].feeGrowthOutside1X128. A more gas efficient version of getTickInfo
* @param manager The pool manager contract.
* @param poolId The ID of the pool.
* @param tick The tick to retrieve fee growth for.
* @return feeGrowthOutside0X128 fee growth per unit of liquidity on the _other_ side of this tick (relative to the current tick)
* @return feeGrowthOutside1X128 fee growth per unit of liquidity on the _other_ side of this tick (relative to the current tick)
*/
function getTickFeeGrowthOutside(IPoolManager manager, PoolId poolId, int24 tick)
internal
view
returns (uint256 feeGrowthOutside0X128, uint256 feeGrowthOutside1X128)
{
bytes32 slot = _getTickInfoSlot(poolId, tick);
// offset by 1 word, since the first word is liquidityGross + liquidityNet
bytes32[] memory data = manager.extsload(bytes32(uint256(slot) + 1), 2);
assembly ("memory-safe") {
feeGrowthOutside0X128 := mload(add(data, 32))
feeGrowthOutside1X128 := mload(add(data, 64))
}
}
/**
* @notice Retrieves the global fee growth of a pool.
* @dev Corresponds to pools[poolId].feeGrowthGlobal0X128 and pools[poolId].feeGrowthGlobal1X128
* @param manager The pool manager contract.
* @param poolId The ID of the pool.
* @return feeGrowthGlobal0 The global fee growth for token0.
* @return feeGrowthGlobal1 The global fee growth for token1.
*/
function getFeeGrowthGlobals(IPoolManager manager, PoolId poolId)
internal
view
returns (uint256 feeGrowthGlobal0, uint256 feeGrowthGlobal1)
{
// slot key of Pool.State value: `pools[poolId]`
bytes32 stateSlot = _getPoolStateSlot(poolId);
// Pool.State, `uint256 feeGrowthGlobal0X128`
bytes32 slot_feeGrowthGlobal0X128 = bytes32(uint256(stateSlot) + FEE_GROWTH_GLOBAL0_OFFSET);
// read the 2 words of feeGrowthGlobal
bytes32[] memory data = manager.extsload(slot_feeGrowthGlobal0X128, 2);
assembly ("memory-safe") {
feeGrowthGlobal0 := mload(add(data, 32))
feeGrowthGlobal1 := mload(add(data, 64))
}
}
/**
* @notice Retrieves total the liquidity of a pool.
* @dev Corresponds to pools[poolId].liquidity
* @param manager The pool manager contract.
* @param poolId The ID of the pool.
* @return liquidity The liquidity of the pool.
*/
function getLiquidity(IPoolManager manager, PoolId poolId) internal view returns (uint128 liquidity) {
// slot key of Pool.State value: `pools[poolId]`
bytes32 stateSlot = _getPoolStateSlot(poolId);
// Pool.State: `uint128 liquidity`
bytes32 slot = bytes32(uint256(stateSlot) + LIQUIDITY_OFFSET);
liquidity = uint128(uint256(manager.extsload(slot)));
}
/**
* @notice Retrieves the tick bitmap of a pool at a specific tick.
* @dev Corresponds to pools[poolId].tickBitmap[tick]
* @param manager The pool manager contract.
* @param poolId The ID of the pool.
* @param tick The tick to retrieve the bitmap for.
* @return tickBitmap The bitmap of the tick.
*/
function getTickBitmap(IPoolManager manager, PoolId poolId, int16 tick)
internal
view
returns (uint256 tickBitmap)
{
// slot key of Pool.State value: `pools[poolId]`
bytes32 stateSlot = _getPoolStateSlot(poolId);
// Pool.State: `mapping(int16 => uint256) tickBitmap;`
bytes32 tickBitmapMapping = bytes32(uint256(stateSlot) + TICK_BITMAP_OFFSET);
// slot id of the mapping key: `pools[poolId].tickBitmap[tick]
bytes32 slot = keccak256(abi.encodePacked(int256(tick), tickBitmapMapping));
tickBitmap = uint256(manager.extsload(slot));
}
/**
* @notice Retrieves the position information of a pool without needing to calculate the `positionId`.
* @dev Corresponds to pools[poolId].positions[positionId]
* @param poolId The ID of the pool.
* @param owner The owner of the liquidity position.
* @param tickLower The lower tick of the liquidity range.
* @param tickUpper The upper tick of the liquidity range.
* @param salt The bytes32 randomness to further distinguish position state.
* @return liquidity The liquidity of the position.
* @return feeGrowthInside0LastX128 The fee growth inside the position for token0.
* @return feeGrowthInside1LastX128 The fee growth inside the position for token1.
*/
function getPositionInfo(
IPoolManager manager,
PoolId poolId,
address owner,
int24 tickLower,
int24 tickUpper,
bytes32 salt
) internal view returns (uint128 liquidity, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128) {
// positionKey = keccak256(abi.encodePacked(owner, tickLower, tickUpper, salt))
bytes32 positionKey = Position.calculatePositionKey(owner, tickLower, tickUpper, salt);
(liquidity, feeGrowthInside0LastX128, feeGrowthInside1LastX128) = getPositionInfo(manager, poolId, positionKey);
}
/**
* @notice Retrieves the position information of a pool at a specific position ID.
* @dev Corresponds to pools[poolId].positions[positionId]
* @param manager The pool manager contract.
* @param poolId The ID of the pool.
* @param positionId The ID of the position.
* @return liquidity The liquidity of the position.
* @return feeGrowthInside0LastX128 The fee growth inside the position for token0.
* @return feeGrowthInside1LastX128 The fee growth inside the position for token1.
*/
function getPositionInfo(IPoolManager manager, PoolId poolId, bytes32 positionId)
internal
view
returns (uint128 liquidity, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128)
{
bytes32 slot = _getPositionInfoSlot(poolId, positionId);
// read all 3 words of the Position.State struct
bytes32[] memory data = manager.extsload(slot, 3);
assembly ("memory-safe") {
liquidity := mload(add(data, 32))
feeGrowthInside0LastX128 := mload(add(data, 64))
feeGrowthInside1LastX128 := mload(add(data, 96))
}
}
/**
* @notice Retrieves the liquidity of a position.
* @dev Corresponds to pools[poolId].positions[positionId].liquidity. More gas efficient for just retrieiving liquidity as compared to getPositionInfo
* @param manager The pool manager contract.
* @param poolId The ID of the pool.
* @param positionId The ID of the position.
* @return liquidity The liquidity of the position.
*/
function getPositionLiquidity(IPoolManager manager, PoolId poolId, bytes32 positionId)
internal
view
returns (uint128 liquidity)
{
bytes32 slot = _getPositionInfoSlot(poolId, positionId);
liquidity = uint128(uint256(manager.extsload(slot)));
}
/**
* @notice Calculate the fee growth inside a tick range of a pool
* @dev pools[poolId].feeGrowthInside0LastX128 in Position.State is cached and can become stale. This function will calculate the up to date feeGrowthInside
* @param manager The pool manager contract.
* @param poolId The ID of the pool.
* @param tickLower The lower tick of the range.
* @param tickUpper The upper tick of the range.
* @return feeGrowthInside0X128 The fee growth inside the tick range for token0.
* @return feeGrowthInside1X128 The fee growth inside the tick range for token1.
*/
function getFeeGrowthInside(IPoolManager manager, PoolId poolId, int24 tickLower, int24 tickUpper)
internal
view
returns (uint256 feeGrowthInside0X128, uint256 feeGrowthInside1X128)
{
(uint256 feeGrowthGlobal0X128, uint256 feeGrowthGlobal1X128) = getFeeGrowthGlobals(manager, poolId);
(uint256 lowerFeeGrowthOutside0X128, uint256 lowerFeeGrowthOutside1X128) =
getTickFeeGrowthOutside(manager, poolId, tickLower);
(uint256 upperFeeGrowthOutside0X128, uint256 upperFeeGrowthOutside1X128) =
getTickFeeGrowthOutside(manager, poolId, tickUpper);
(, int24 tickCurrent,,) = getSlot0(manager, poolId);
unchecked {
if (tickCurrent < tickLower) {
feeGrowthInside0X128 = lowerFeeGrowthOutside0X128 - upperFeeGrowthOutside0X128;
feeGrowthInside1X128 = lowerFeeGrowthOutside1X128 - upperFeeGrowthOutside1X128;
} else if (tickCurrent >= tickUpper) {
feeGrowthInside0X128 = upperFeeGrowthOutside0X128 - lowerFeeGrowthOutside0X128;
feeGrowthInside1X128 = upperFeeGrowthOutside1X128 - lowerFeeGrowthOutside1X128;
} else {
feeGrowthInside0X128 = feeGrowthGlobal0X128 - lowerFeeGrowthOutside0X128 - upperFeeGrowthOutside0X128;
feeGrowthInside1X128 = feeGrowthGlobal1X128 - lowerFeeGrowthOutside1X128 - upperFeeGrowthOutside1X128;
}
}
}
function _getPoolStateSlot(PoolId poolId) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(PoolId.unwrap(poolId), POOLS_SLOT));
}
function _getTickInfoSlot(PoolId poolId, int24 tick) internal pure returns (bytes32) {
// slot key of Pool.State value: `pools[poolId]`
bytes32 stateSlot = _getPoolStateSlot(poolId);
// Pool.State: `mapping(int24 => TickInfo) ticks`
bytes32 ticksMappingSlot = bytes32(uint256(stateSlot) + TICKS_OFFSET);
// slot key of the tick key: `pools[poolId].ticks[tick]
return keccak256(abi.encodePacked(int256(tick), ticksMappingSlot));
}
function _getPositionInfoSlot(PoolId poolId, bytes32 positionId) internal pure returns (bytes32) {
// slot key of Pool.State value: `pools[poolId]`
bytes32 stateSlot = _getPoolStateSlot(poolId);
// Pool.State: `mapping(bytes32 => Position.State) positions;`
bytes32 positionMapping = bytes32(uint256(stateSlot) + POSITIONS_OFFSET);
// slot of the mapping key: `pools[poolId].positions[positionId]
return keccak256(abi.encodePacked(positionId, positionMapping));
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
/// @notice Library to define different pool actions.
/// @dev These are suggested common commands, however additional commands should be defined as required
/// Some of these actions are not supported in the Router contracts or Position Manager contracts, but are left as they may be helpful commands for other peripheral contracts.
library Actions {
// pool actions
// liquidity actions
uint256 constant INCREASE_LIQUIDITY = 0x00;
uint256 constant DECREASE_LIQUIDITY = 0x01;
uint256 constant MINT_POSITION = 0x02;
uint256 constant BURN_POSITION = 0x03;
uint256 constant INCREASE_LIQUIDITY_FROM_DELTAS = 0x04;
uint256 constant MINT_POSITION_FROM_DELTAS = 0x05;
// swapping
uint256 constant SWAP_EXACT_IN_SINGLE = 0x06;
uint256 constant SWAP_EXACT_IN = 0x07;
uint256 constant SWAP_EXACT_OUT_SINGLE = 0x08;
uint256 constant SWAP_EXACT_OUT = 0x09;
// donate
// note this is not supported in the position manager or router
uint256 constant DONATE = 0x0a;
// closing deltas on the pool manager
// settling
uint256 constant SETTLE = 0x0b;
uint256 constant SETTLE_ALL = 0x0c;
uint256 constant SETTLE_PAIR = 0x0d;
// taking
uint256 constant TAKE = 0x0e;
uint256 constant TAKE_ALL = 0x0f;
uint256 constant TAKE_PORTION = 0x10;
uint256 constant TAKE_PAIR = 0x11;
uint256 constant CLOSE_CURRENCY = 0x12;
uint256 constant CLEAR_OR_TAKE = 0x13;
uint256 constant SWEEP = 0x14;
uint256 constant WRAP = 0x15;
uint256 constant UNWRAP = 0x16;
// minting/burning 6909s to close deltas
// note this is not supported in the position manager or router
uint256 constant MINT_6909 = 0x17;
uint256 constant BURN_6909 = 0x18;
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;
import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";
import {Actions} from "./Actions.sol";
import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";
import {ActionConstants} from "./ActionConstants.sol";
struct Plan {
bytes actions;
bytes[] params;
}
library Planner {
using Planner for Plan;
function init() internal pure returns (Plan memory plan) {
return Plan({actions: bytes(""), params: new bytes[](0)});
}
function add(Plan memory plan, uint256 action, bytes memory param) internal pure returns (Plan memory) {
bytes memory actions = new bytes(plan.params.length + 1);
bytes[] memory params = new bytes[](plan.params.length + 1);
for (uint256 i; i < params.length - 1; i++) {
// Copy from plan.
params[i] = plan.params[i];
actions[i] = plan.actions[i];
}
params[params.length - 1] = param;
actions[params.length - 1] = bytes1(uint8(action));
plan.actions = actions;
plan.params = params;
return plan;
}
function finalizeModifyLiquidityWithTake(Plan memory plan, PoolKey memory poolKey, address takeRecipient)
internal
pure
returns (bytes memory)
{
plan.add(Actions.TAKE, abi.encode(poolKey.currency0, takeRecipient, ActionConstants.OPEN_DELTA));
plan.add(Actions.TAKE, abi.encode(poolKey.currency1, takeRecipient, ActionConstants.OPEN_DELTA));
return plan.encode();
}
function finalizeModifyLiquidityWithClose(Plan memory plan, PoolKey memory poolKey)
internal
pure
returns (bytes memory)
{
plan.add(Actions.CLOSE_CURRENCY, abi.encode(poolKey.currency0));
plan.add(Actions.CLOSE_CURRENCY, abi.encode(poolKey.currency1));
return plan.encode();
}
function finalizeModifyLiquidityWithSettlePair(Plan memory plan, PoolKey memory poolKey)
internal
pure
returns (bytes memory)
{
plan.add(Actions.SETTLE_PAIR, abi.encode(poolKey.currency0, poolKey.currency1));
return plan.encode();
}
function finalizeModifyLiquidityWithTakePair(Plan memory plan, PoolKey memory poolKey, address takeRecipient)
internal
pure
returns (bytes memory)
{
plan.add(Actions.TAKE_PAIR, abi.encode(poolKey.currency0, poolKey.currency1, takeRecipient));
return plan.encode();
}
function encode(Plan memory plan) internal pure returns (bytes memory) {
return abi.encode(plan.actions, plan.params);
}
function finalizeSwap(Plan memory plan, Currency inputCurrency, Currency outputCurrency, address takeRecipient)
internal
pure
returns (bytes memory)
{
if (takeRecipient == ActionConstants.MSG_SENDER) {
// blindly settling and taking all, without slippage checks, isnt recommended in prod
plan = plan.add(Actions.SETTLE_ALL, abi.encode(inputCurrency, type(uint256).max));
plan = plan.add(Actions.TAKE_ALL, abi.encode(outputCurrency, 0));
} else {
plan = plan.add(Actions.SETTLE, abi.encode(inputCurrency, ActionConstants.OPEN_DELTA, true));
plan = plan.add(Actions.TAKE, abi.encode(outputCurrency, takeRecipient, ActionConstants.OPEN_DELTA));
}
return plan.encode();
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/ReentrancyGuard.sol)
pragma solidity ^0.8.20;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If EIP-1153 (transient storage) is available on the chain you're deploying at,
* consider using {ReentrancyGuardTransient} instead.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant NOT_ENTERED = 1;
uint256 private constant ENTERED = 2;
uint256 private _status;
/**
* @dev Unauthorized reentrant call.
*/
error ReentrancyGuardReentrantCall();
constructor() {
_status = NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be NOT_ENTERED
if (_status == ENTERED) {
revert ReentrancyGuardReentrantCall();
}
// Any calls to nonReentrant after this point will fail
_status = ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == ENTERED;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC-20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
/**
* @dev An operation with an ERC-20 token failed.
*/
error SafeERC20FailedOperation(address token);
/**
* @dev Indicates a failed `decreaseAllowance` request.
*/
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
* value, non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*
* NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function
* only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being
* set here.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
safeTransfer(token, to, value);
} else if (!token.transferAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target
* has no code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferFromAndCallRelaxed(
IERC1363 token,
address from,
address to,
uint256 value,
bytes memory data
) internal {
if (to.code.length == 0) {
safeTransferFrom(token, from, to, value);
} else if (!token.transferFromAndCall(from, to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.
* Opposedly, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}
* once without retrying, and relies on the returned value to be true.
*
* Reverts if the returned value is other than `true`.
*/
function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
forceApprove(token, to, value);
} else if (!token.approveAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturnBool} that reverts if call fails to meet the requirements.
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
// bubble errors
if iszero(success) {
let ptr := mload(0x40)
returndatacopy(ptr, 0, returndatasize())
revert(ptr, returndatasize())
}
returnSize := returndatasize()
returnValue := mload(0)
}
if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 1) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silently catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
bool success;
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
returnSize := returndatasize()
returnValue := mload(0)
}
return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1);
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.26;
import {IPositionManager} from "@uniswap/v4-periphery/src/interfaces/IPositionManager.sol";
/**
* @dev Interface of the MigrateNFT contract
*/
interface IMigrateNFT {
function migrate(uint256 lockId, IPositionManager nftPositionManager, uint256 tokenId)
external
payable
returns (bool);
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.26;
import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";
import {PoolId} from "@uniswap/v4-core/src/types/PoolId.sol";
interface IUniversalLockerV2 {
// Custom errors
error InvalidPoolManager();
error InvalidPositionManager();
error InvalidLPFeeReceiver();
error InvalidCollectFeeReceiver();
error InsufficientFlatFee();
error InvalidHookAddress();
error InvalidHookAddressFormat();
error NoChange();
error HookNotWhitelisted();
error HookIsBlacklisted();
error UnlockTimeInPast();
error InvalidUnlockTime();
error NoLiquidityInPosition();
error PoolNotInitialized();
error NotOwner();
error StillLocked();
error AlreadyUnlocked();
error TransferFailed(string reason);
error InvalidRecipient();
error EternalLock();
error NotYetExpired();
error ZeroLiquidity();
error InsufficientLiquidity();
error MigratorNotSet();
error NFTNotInLocker();
error MigrationFailed();
error InvalidNewOwner();
error LockIsNFTized();
error LPFeeTooHigh();
error CollectFeeTooHigh();
error CannotRescueNFTs();
error ETHTransferFailed();
error InvalidCollectAddress();
error NFTOwnerMismatch(address expected, address actual);
error LockNotActive();
error UCFCanOnlyBeDecreased();
error InvalidMigrateInContract();
error InvalidMigrator();
error TransferToZeroAddress();
error InvalidTokenAddress();
error InvalidAmount();
error InvalidReceiver();
error InvalidAutoCollectAccount();
error InvalidPermissionMode();
error InvalidHookBlacklist();
error InvalidHookWhitelist();
error InvalidLockId();
error InvalidTokenId();
error InvalidUnlockTimeRange();
error InvalidLiquidity();
error InvalidFeeAmount();
error InvalidFeeRecipient();
error InvalidCollectFee();
error InvalidLPFee();
error InvalidUCF();
// Events
event LiquidityLocked(
uint256 indexed lockId,
address indexed owner,
address positionManager,
uint256 tokenId,
PoolId indexed poolId,
uint256 amount,
uint256 unlockTime
);
event LiquidityUnlocked(
uint256 indexed lockId,
address indexed owner,
address token,
uint256 tokenId,
PoolId indexed poolId,
uint256 amount
);
event HookWhitelisted(address indexed hookAddress, bool status);
event LiquidityDecreased(uint256 indexed lockId);
event LockExtended(uint256 indexed lockId, uint256 newUnlockTime);
event PermissionModeChanged(PermissionMode newMode);
event HookBlacklisted(address hook, bool blacklisted);
event MigrateInContractSet(address migrateIn);
event MigratorSet(address migrator);
event LockMigrated(uint256 indexed lockId, address indexed migrator);
event CollectAddressUpdated(uint256 indexed lockId, address indexed newCollectAddress);
event LockOwnershipTransferred(uint256 indexed lockId, address indexed previousOwner, address indexed newOwner);
event onSetUCF(uint256 indexed _lockId, uint256 _ucf);
event FlatFeeSet(uint256 _flatFee);
event WhitelistedForFreeLock(address indexed user, bool status);
event FeesSet(uint256 _lpFee, uint256 _collectFee);
// Structs
struct LockInfo {
uint256 lockId;
address owner;
uint256 tokenId;
PoolKey poolKey;
uint256 amount;
uint256 unlockTime;
address collectAddress;
bool isNFTized;
uint256 ucf;
}
// Enums
enum PermissionMode {
Permissionless,
PermissionlessWithBlacklist,
WhitelistOnly
}
// Core functions
function lockNFTPosition(uint256 tokenId, uint256 unlockTime, bool mintLockNFT)
external
payable
returns (uint256 lockId);
function unlockLiquidity(uint256 lockId) external;
function decreaseLiquidity(uint256 lockId, uint128 liquidityDecrease, uint256 amount0Min, uint256 amount1Min)
external
returns (uint256 amount0, uint256 amount1);
function relock(uint256 lockId, uint256 newUnlockTime) external;
function migrate(uint256 lockId) external payable;
function lockFromMigration(uint256 oldLockId, address oldLocker) external returns (uint256 lockId);
// View functions
function getLockInfo(uint256 lockId) external view returns (LockInfo memory);
function isLocked(uint256 lockId) external view returns (bool);
function getUserLockCount(address user) external view returns (uint256);
function getUserLockAt(address user, uint256 index) external view returns (uint256);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
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 value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of 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 value) 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 a `value` amount of tokens 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 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` 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 value) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC721/IERC721.sol)
pragma solidity ^0.8.20;
import {IERC165} from "../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC-721 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 ERC-721 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 ERC-721
* 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 address zero.
*
* 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 (last updated v5.0.0) (token/ERC721/extensions/IERC721Metadata.sol)
pragma solidity ^0.8.20;
import {IERC721} from "../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 v5.1.0) (token/ERC721/utils/ERC721Utils.sol)
pragma solidity ^0.8.20;
import {IERC721Receiver} from "../IERC721Receiver.sol";
import {IERC721Errors} from "../../../interfaces/draft-IERC6093.sol";
/**
* @dev Library that provide common ERC-721 utility functions.
*
* See https://eips.ethereum.org/EIPS/eip-721[ERC-721].
*
* _Available since v5.1._
*/
library ERC721Utils {
/**
* @dev Performs an acceptance check for the provided `operator` by calling {IERC721-onERC721Received}
* on the `to` address. The `operator` is generally the address that initiated the token transfer (i.e. `msg.sender`).
*
* The acceptance call is not executed and treated as a no-op if the target address doesn't contain code (i.e. an EOA).
* Otherwise, the recipient must implement {IERC721Receiver-onERC721Received} and return the acceptance magic value to accept
* the transfer.
*/
function checkOnERC721Received(
address operator,
address from,
address to,
uint256 tokenId,
bytes memory data
) internal {
if (to.code.length > 0) {
try IERC721Receiver(to).onERC721Received(operator, from, tokenId, data) returns (bytes4 retval) {
if (retval != IERC721Receiver.onERC721Received.selector) {
// Token rejected
revert IERC721Errors.ERC721InvalidReceiver(to);
}
} catch (bytes memory reason) {
if (reason.length == 0) {
// non-IERC721Receiver implementer
revert IERC721Errors.ERC721InvalidReceiver(to);
} else {
assembly ("memory-safe") {
revert(add(32, reason), mload(reason))
}
}
}
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/ERC165.sol)
pragma solidity ^0.8.20;
import {IERC165} from "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC-165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/draft-IERC6093.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard ERC-20 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-20 tokens.
*/
interface IERC20Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC20InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC20InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.
* @param spender Address that may be allowed to operate on tokens without being their owner.
* @param allowance Amount of tokens a `spender` is allowed to operate with.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC20InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `spender` to be approved. Used in approvals.
* @param spender Address that may be allowed to operate on tokens without being their owner.
*/
error ERC20InvalidSpender(address spender);
}
/**
* @dev Standard ERC-721 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-721 tokens.
*/
interface IERC721Errors {
/**
* @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in ERC-20.
* Used in balance queries.
* @param owner Address of the current owner of a token.
*/
error ERC721InvalidOwner(address owner);
/**
* @dev Indicates a `tokenId` whose `owner` is the zero address.
* @param tokenId Identifier number of a token.
*/
error ERC721NonexistentToken(uint256 tokenId);
/**
* @dev Indicates an error related to the ownership over a particular token. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param tokenId Identifier number of a token.
* @param owner Address of the current owner of a token.
*/
error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC721InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC721InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param tokenId Identifier number of a token.
*/
error ERC721InsufficientApproval(address operator, uint256 tokenId);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC721InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC721InvalidOperator(address operator);
}
/**
* @dev Standard ERC-1155 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-1155 tokens.
*/
interface IERC1155Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
* @param tokenId Identifier number of a token.
*/
error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC1155InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC1155InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param owner Address of the current owner of a token.
*/
error ERC1155MissingApprovalForAll(address operator, address owner);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC1155InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC1155InvalidOperator(address operator);
/**
* @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.
* Used in batch transfers.
* @param idsLength Length of the array of token identifiers
* @param valuesLength Length of the array of token amounts
*/
error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC721/IERC721Receiver.sol)
pragma solidity ^0.8.20;
/**
* @title ERC-721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers
* from ERC-721 asset contracts.
*/
interface IERC721Receiver {
/**
* @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
* by `operator` from `from`, this function is called.
*
* It must return its Solidity selector to confirm the token transfer.
* If any other value is returned or the interface is not implemented by the recipient, the transfer will be
* reverted.
*
* The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`.
*/
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/Math.sol)
pragma solidity ^0.8.20;
import {Panic} from "../Panic.sol";
import {SafeCast} from "./SafeCast.sol";
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
enum Rounding {
Floor, // Toward negative infinity
Ceil, // Toward positive infinity
Trunc, // Toward zero
Expand // Away from zero
}
/**
* @dev Returns the addition of two unsigned integers, with an success flag (no overflow).
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the subtraction of two unsigned integers, with an success flag (no overflow).
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an success flag (no overflow).
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a success flag (no division by zero).
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a success flag (no division by zero).
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.
*
* IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.
* However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute
* one branch when needed, making this function more expensive.
*/
function ternary(bool condition, uint256 a, uint256 b) internal pure returns (uint256) {
unchecked {
// branchless ternary works because:
// b ^ (a ^ b) == a
// b ^ 0 == b
return b ^ ((a ^ b) * SafeCast.toUint(condition));
}
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return ternary(a > b, a, b);
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return ternary(a < b, a, b);
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds towards infinity instead
* of rounding towards zero.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
if (b == 0) {
// Guarantee the same behavior as in a regular Solidity division.
Panic.panic(Panic.DIVISION_BY_ZERO);
}
// The following calculation ensures accurate ceiling division without overflow.
// Since a is non-zero, (a - 1) / b will not overflow.
// The largest possible result occurs when (a - 1) / b is type(uint256).max,
// but the largest value we can obtain is type(uint256).max - 1, which happens
// when a = type(uint256).max and b = 1.
unchecked {
return SafeCast.toUint(a > 0) * ((a - 1) / b + 1);
}
}
/**
* @dev Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or
* denominator == 0.
*
* Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by
* Uniswap Labs also under MIT license.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2²⁵⁶ and mod 2²⁵⁶ - 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²⁵⁶ + prod0.
uint256 prod0 = x * y; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
// Solidity will revert if denominator == 0, unlike the div opcode on its own.
// The surrounding unchecked block does not change this fact.
// See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
return prod0 / denominator;
}
// Make sure the result is less than 2²⁵⁶. Also prevents denominator == 0.
if (denominator <= prod1) {
Panic.panic(ternary(denominator == 0, Panic.DIVISION_BY_ZERO, Panic.UNDER_OVERFLOW));
}
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator.
// Always >= 1. See https://cs.stackexchange.com/q/138556/92363.
uint256 twos = denominator & (0 - denominator);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2²⁵⁶ / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2²⁵⁶. Now that denominator is an odd number, it has an inverse modulo 2²⁵⁶ such
// that denominator * inv ≡ 1 mod 2²⁵⁶. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv ≡ 1 mod 2⁴.
uint256 inverse = (3 * denominator) ^ 2;
// Use the 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.
inverse *= 2 - denominator * inverse; // inverse mod 2⁸
inverse *= 2 - denominator * inverse; // inverse mod 2¹⁶
inverse *= 2 - denominator * inverse; // inverse mod 2³²
inverse *= 2 - denominator * inverse; // inverse mod 2⁶⁴
inverse *= 2 - denominator * inverse; // inverse mod 2¹²⁸
inverse *= 2 - denominator * inverse; // inverse mod 2²⁵⁶
// 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²⁵⁶. Since the preconditions guarantee that the outcome is
// less than 2²⁵⁶, 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 * inverse;
return result;
}
}
/**
* @dev Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
return mulDiv(x, y, denominator) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0);
}
/**
* @dev Calculate the modular multiplicative inverse of a number in Z/nZ.
*
* If n is a prime, then Z/nZ is a field. In that case all elements are inversible, except 0.
* If n is not a prime, then Z/nZ is not a field, and some elements might not be inversible.
*
* If the input value is not inversible, 0 is returned.
*
* NOTE: If you know for sure that n is (big) a prime, it may be cheaper to use Fermat's little theorem and get the
* inverse using `Math.modExp(a, n - 2, n)`. See {invModPrime}.
*/
function invMod(uint256 a, uint256 n) internal pure returns (uint256) {
unchecked {
if (n == 0) return 0;
// The inverse modulo is calculated using the Extended Euclidean Algorithm (iterative version)
// Used to compute integers x and y such that: ax + ny = gcd(a, n).
// When the gcd is 1, then the inverse of a modulo n exists and it's x.
// ax + ny = 1
// ax = 1 + (-y)n
// ax ≡ 1 (mod n) # x is the inverse of a modulo n
// If the remainder is 0 the gcd is n right away.
uint256 remainder = a % n;
uint256 gcd = n;
// Therefore the initial coefficients are:
// ax + ny = gcd(a, n) = n
// 0a + 1n = n
int256 x = 0;
int256 y = 1;
while (remainder != 0) {
uint256 quotient = gcd / remainder;
(gcd, remainder) = (
// The old remainder is the next gcd to try.
remainder,
// Compute the next remainder.
// Can't overflow given that (a % gcd) * (gcd // (a % gcd)) <= gcd
// where gcd is at most n (capped to type(uint256).max)
gcd - remainder * quotient
);
(x, y) = (
// Increment the coefficient of a.
y,
// Decrement the coefficient of n.
// Can overflow, but the result is casted to uint256 so that the
// next value of y is "wrapped around" to a value between 0 and n - 1.
x - y * int256(quotient)
);
}
if (gcd != 1) return 0; // No inverse exists.
return ternary(x < 0, n - uint256(-x), uint256(x)); // Wrap the result if it's negative.
}
}
/**
* @dev Variant of {invMod}. More efficient, but only works if `p` is known to be a prime greater than `2`.
*
* From https://en.wikipedia.org/wiki/Fermat%27s_little_theorem[Fermat's little theorem], we know that if p is
* prime, then `a**(p-1) ≡ 1 mod p`. As a consequence, we have `a * a**(p-2) ≡ 1 mod p`, which means that
* `a**(p-2)` is the modular multiplicative inverse of a in Fp.
*
* NOTE: this function does NOT check that `p` is a prime greater than `2`.
*/
function invModPrime(uint256 a, uint256 p) internal view returns (uint256) {
unchecked {
return Math.modExp(a, p - 2, p);
}
}
/**
* @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m)
*
* Requirements:
* - modulus can't be zero
* - underlying staticcall to precompile must succeed
*
* IMPORTANT: The result is only valid if the underlying call succeeds. When using this function, make
* sure the chain you're using it on supports the precompiled contract for modular exponentiation
* at address 0x05 as specified in https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise,
* the underlying function will succeed given the lack of a revert, but the result may be incorrectly
* interpreted as 0.
*/
function modExp(uint256 b, uint256 e, uint256 m) internal view returns (uint256) {
(bool success, uint256 result) = tryModExp(b, e, m);
if (!success) {
Panic.panic(Panic.DIVISION_BY_ZERO);
}
return result;
}
/**
* @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m).
* It includes a success flag indicating if the operation succeeded. Operation will be marked as failed if trying
* to operate modulo 0 or if the underlying precompile reverted.
*
* IMPORTANT: The result is only valid if the success flag is true. When using this function, make sure the chain
* you're using it on supports the precompiled contract for modular exponentiation at address 0x05 as specified in
* https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise, the underlying function will succeed given the lack
* of a revert, but the result may be incorrectly interpreted as 0.
*/
function tryModExp(uint256 b, uint256 e, uint256 m) internal view returns (bool success, uint256 result) {
if (m == 0) return (false, 0);
assembly ("memory-safe") {
let ptr := mload(0x40)
// | Offset | Content | Content (Hex) |
// |-----------|------------|--------------------------------------------------------------------|
// | 0x00:0x1f | size of b | 0x0000000000000000000000000000000000000000000000000000000000000020 |
// | 0x20:0x3f | size of e | 0x0000000000000000000000000000000000000000000000000000000000000020 |
// | 0x40:0x5f | size of m | 0x0000000000000000000000000000000000000000000000000000000000000020 |
// | 0x60:0x7f | value of b | 0x<.............................................................b> |
// | 0x80:0x9f | value of e | 0x<.............................................................e> |
// | 0xa0:0xbf | value of m | 0x<.............................................................m> |
mstore(ptr, 0x20)
mstore(add(ptr, 0x20), 0x20)
mstore(add(ptr, 0x40), 0x20)
mstore(add(ptr, 0x60), b)
mstore(add(ptr, 0x80), e)
mstore(add(ptr, 0xa0), m)
// Given the result < m, it's guaranteed to fit in 32 bytes,
// so we can use the memory scratch space located at offset 0.
success := staticcall(gas(), 0x05, ptr, 0xc0, 0x00, 0x20)
result := mload(0x00)
}
}
/**
* @dev Variant of {modExp} that supports inputs of arbitrary length.
*/
function modExp(bytes memory b, bytes memory e, bytes memory m) internal view returns (bytes memory) {
(bool success, bytes memory result) = tryModExp(b, e, m);
if (!success) {
Panic.panic(Panic.DIVISION_BY_ZERO);
}
return result;
}
/**
* @dev Variant of {tryModExp} that supports inputs of arbitrary length.
*/
function tryModExp(
bytes memory b,
bytes memory e,
bytes memory m
) internal view returns (bool success, bytes memory result) {
if (_zeroBytes(m)) return (false, new bytes(0));
uint256 mLen = m.length;
// Encode call args in result and move the free memory pointer
result = abi.encodePacked(b.length, e.length, mLen, b, e, m);
assembly ("memory-safe") {
let dataPtr := add(result, 0x20)
// Write result on top of args to avoid allocating extra memory.
success := staticcall(gas(), 0x05, dataPtr, mload(result), dataPtr, mLen)
// Overwrite the length.
// result.length > returndatasize() is guaranteed because returndatasize() == m.length
mstore(result, mLen)
// Set the memory pointer after the returned data.
mstore(0x40, add(dataPtr, mLen))
}
}
/**
* @dev Returns whether the provided byte array is zero.
*/
function _zeroBytes(bytes memory byteArray) private pure returns (bool) {
for (uint256 i = 0; i < byteArray.length; ++i) {
if (byteArray[i] != 0) {
return false;
}
}
return true;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded
* towards zero.
*
* This method is based on Newton's method for computing square roots; the algorithm is restricted to only
* using integer operations.
*/
function sqrt(uint256 a) internal pure returns (uint256) {
unchecked {
// Take care of easy edge cases when a == 0 or a == 1
if (a <= 1) {
return a;
}
// In this function, we use Newton's method to get a root of `f(x) := x² - a`. It involves building a
// sequence x_n that converges toward sqrt(a). For each iteration x_n, we also define the error between
// the current value as `ε_n = | x_n - sqrt(a) |`.
//
// For our first estimation, we consider `e` the smallest power of 2 which is bigger than the square root
// of the target. (i.e. `2**(e-1) ≤ sqrt(a) < 2**e`). We know that `e ≤ 128` because `(2¹²⁸)² = 2²⁵⁶` is
// bigger than any uint256.
//
// By noticing that
// `2**(e-1) ≤ sqrt(a) < 2**e → (2**(e-1))² ≤ a < (2**e)² → 2**(2*e-2) ≤ a < 2**(2*e)`
// we can deduce that `e - 1` is `log2(a) / 2`. We can thus compute `x_n = 2**(e-1)` using a method similar
// to the msb function.
uint256 aa = a;
uint256 xn = 1;
if (aa >= (1 << 128)) {
aa >>= 128;
xn <<= 64;
}
if (aa >= (1 << 64)) {
aa >>= 64;
xn <<= 32;
}
if (aa >= (1 << 32)) {
aa >>= 32;
xn <<= 16;
}
if (aa >= (1 << 16)) {
aa >>= 16;
xn <<= 8;
}
if (aa >= (1 << 8)) {
aa >>= 8;
xn <<= 4;
}
if (aa >= (1 << 4)) {
aa >>= 4;
xn <<= 2;
}
if (aa >= (1 << 2)) {
xn <<= 1;
}
// We now have x_n such that `x_n = 2**(e-1) ≤ sqrt(a) < 2**e = 2 * x_n`. This implies ε_n ≤ 2**(e-1).
//
// We can refine our estimation by noticing that the middle of that interval minimizes the error.
// If we move x_n to equal 2**(e-1) + 2**(e-2), then we reduce the error to ε_n ≤ 2**(e-2).
// This is going to be our x_0 (and ε_0)
xn = (3 * xn) >> 1; // ε_0 := | x_0 - sqrt(a) | ≤ 2**(e-2)
// From here, Newton's method give us:
// x_{n+1} = (x_n + a / x_n) / 2
//
// One should note that:
// x_{n+1}² - a = ((x_n + a / x_n) / 2)² - a
// = ((x_n² + a) / (2 * x_n))² - a
// = (x_n⁴ + 2 * a * x_n² + a²) / (4 * x_n²) - a
// = (x_n⁴ + 2 * a * x_n² + a² - 4 * a * x_n²) / (4 * x_n²)
// = (x_n⁴ - 2 * a * x_n² + a²) / (4 * x_n²)
// = (x_n² - a)² / (2 * x_n)²
// = ((x_n² - a) / (2 * x_n))²
// ≥ 0
// Which proves that for all n ≥ 1, sqrt(a) ≤ x_n
//
// This gives us the proof of quadratic convergence of the sequence:
// ε_{n+1} = | x_{n+1} - sqrt(a) |
// = | (x_n + a / x_n) / 2 - sqrt(a) |
// = | (x_n² + a - 2*x_n*sqrt(a)) / (2 * x_n) |
// = | (x_n - sqrt(a))² / (2 * x_n) |
// = | ε_n² / (2 * x_n) |
// = ε_n² / | (2 * x_n) |
//
// For the first iteration, we have a special case where x_0 is known:
// ε_1 = ε_0² / | (2 * x_0) |
// ≤ (2**(e-2))² / (2 * (2**(e-1) + 2**(e-2)))
// ≤ 2**(2*e-4) / (3 * 2**(e-1))
// ≤ 2**(e-3) / 3
// ≤ 2**(e-3-log2(3))
// ≤ 2**(e-4.5)
//
// For the following iterations, we use the fact that, 2**(e-1) ≤ sqrt(a) ≤ x_n:
// ε_{n+1} = ε_n² / | (2 * x_n) |
// ≤ (2**(e-k))² / (2 * 2**(e-1))
// ≤ 2**(2*e-2*k) / 2**e
// ≤ 2**(e-2*k)
xn = (xn + a / xn) >> 1; // ε_1 := | x_1 - sqrt(a) | ≤ 2**(e-4.5) -- special case, see above
xn = (xn + a / xn) >> 1; // ε_2 := | x_2 - sqrt(a) | ≤ 2**(e-9) -- general case with k = 4.5
xn = (xn + a / xn) >> 1; // ε_3 := | x_3 - sqrt(a) | ≤ 2**(e-18) -- general case with k = 9
xn = (xn + a / xn) >> 1; // ε_4 := | x_4 - sqrt(a) | ≤ 2**(e-36) -- general case with k = 18
xn = (xn + a / xn) >> 1; // ε_5 := | x_5 - sqrt(a) | ≤ 2**(e-72) -- general case with k = 36
xn = (xn + a / xn) >> 1; // ε_6 := | x_6 - sqrt(a) | ≤ 2**(e-144) -- general case with k = 72
// Because e ≤ 128 (as discussed during the first estimation phase), we know have reached a precision
// ε_6 ≤ 2**(e-144) < 1. Given we're operating on integers, then we can ensure that xn is now either
// sqrt(a) or sqrt(a) + 1.
return xn - SafeCast.toUint(xn > a / xn);
}
}
/**
* @dev Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && result * result < a);
}
}
/**
* @dev Return the log in base 2 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log2(uint256 x) internal pure returns (uint256 r) {
// If value has upper 128 bits set, log2 result is at least 128
r = SafeCast.toUint(x > 0xffffffffffffffffffffffffffffffff) << 7;
// If upper 64 bits of 128-bit half set, add 64 to result
r |= SafeCast.toUint((x >> r) > 0xffffffffffffffff) << 6;
// If upper 32 bits of 64-bit half set, add 32 to result
r |= SafeCast.toUint((x >> r) > 0xffffffff) << 5;
// If upper 16 bits of 32-bit half set, add 16 to result
r |= SafeCast.toUint((x >> r) > 0xffff) << 4;
// If upper 8 bits of 16-bit half set, add 8 to result
r |= SafeCast.toUint((x >> r) > 0xff) << 3;
// If upper 4 bits of 8-bit half set, add 4 to result
r |= SafeCast.toUint((x >> r) > 0xf) << 2;
// Shifts value right by the current result and use it as an index into this lookup table:
//
// | x (4 bits) | index | table[index] = MSB position |
// |------------|---------|-----------------------------|
// | 0000 | 0 | table[0] = 0 |
// | 0001 | 1 | table[1] = 0 |
// | 0010 | 2 | table[2] = 1 |
// | 0011 | 3 | table[3] = 1 |
// | 0100 | 4 | table[4] = 2 |
// | 0101 | 5 | table[5] = 2 |
// | 0110 | 6 | table[6] = 2 |
// | 0111 | 7 | table[7] = 2 |
// | 1000 | 8 | table[8] = 3 |
// | 1001 | 9 | table[9] = 3 |
// | 1010 | 10 | table[10] = 3 |
// | 1011 | 11 | table[11] = 3 |
// | 1100 | 12 | table[12] = 3 |
// | 1101 | 13 | table[13] = 3 |
// | 1110 | 14 | table[14] = 3 |
// | 1111 | 15 | table[15] = 3 |
//
// The lookup table is represented as a 32-byte value with the MSB positions for 0-15 in the last 16 bytes.
assembly ("memory-safe") {
r := or(r, byte(shr(r, x), 0x0000010102020202030303030303030300000000000000000000000000000000))
}
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << result < value);
}
}
/**
* @dev Return the log in base 10 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10 ** 64) {
value /= 10 ** 64;
result += 64;
}
if (value >= 10 ** 32) {
value /= 10 ** 32;
result += 32;
}
if (value >= 10 ** 16) {
value /= 10 ** 16;
result += 16;
}
if (value >= 10 ** 8) {
value /= 10 ** 8;
result += 8;
}
if (value >= 10 ** 4) {
value /= 10 ** 4;
result += 4;
}
if (value >= 10 ** 2) {
value /= 10 ** 2;
result += 2;
}
if (value >= 10 ** 1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 10 ** result < value);
}
}
/**
* @dev Return the log in base 256 of a positive value rounded towards zero.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 x) internal pure returns (uint256 r) {
// If value has upper 128 bits set, log2 result is at least 128
r = SafeCast.toUint(x > 0xffffffffffffffffffffffffffffffff) << 7;
// If upper 64 bits of 128-bit half set, add 64 to result
r |= SafeCast.toUint((x >> r) > 0xffffffffffffffff) << 6;
// If upper 32 bits of 64-bit half set, add 32 to result
r |= SafeCast.toUint((x >> r) > 0xffffffff) << 5;
// If upper 16 bits of 32-bit half set, add 16 to result
r |= SafeCast.toUint((x >> r) > 0xffff) << 4;
// Add 1 if upper 8 bits of 16-bit half set, and divide accumulated result by 8
return (r >> 3) | SafeCast.toUint((x >> r) > 0xff);
}
/**
* @dev Return the log in base 256, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << (result << 3) < value);
}
}
/**
* @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
*/
function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
return uint8(rounding) % 2 == 1;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.
pragma solidity ^0.8.20;
/**
* @dev Wrappers over Solidity's uintXX/intXX/bool casting operators with added overflow
* checks.
*
* Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
* easily result in undesired exploitation or bugs, since developers usually
* assume that overflows raise errors. `SafeCast` restores this intuition by
* reverting the transaction when such an operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/
library SafeCast {
/**
* @dev Value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);
/**
* @dev An int value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedIntToUint(int256 value);
/**
* @dev Value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);
/**
* @dev An uint value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedUintToInt(uint256 value);
/**
* @dev Returns the downcasted uint248 from uint256, reverting on
* overflow (when the input is greater than largest uint248).
*
* Counterpart to Solidity's `uint248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toUint248(uint256 value) internal pure returns (uint248) {
if (value > type(uint248).max) {
revert SafeCastOverflowedUintDowncast(248, value);
}
return uint248(value);
}
/**
* @dev Returns the downcasted uint240 from uint256, reverting on
* overflow (when the input is greater than largest uint240).
*
* Counterpart to Solidity's `uint240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toUint240(uint256 value) internal pure returns (uint240) {
if (value > type(uint240).max) {
revert SafeCastOverflowedUintDowncast(240, value);
}
return uint240(value);
}
/**
* @dev Returns the downcasted uint232 from uint256, reverting on
* overflow (when the input is greater than largest uint232).
*
* Counterpart to Solidity's `uint232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toUint232(uint256 value) internal pure returns (uint232) {
if (value > type(uint232).max) {
revert SafeCastOverflowedUintDowncast(232, value);
}
return uint232(value);
}
/**
* @dev Returns the downcasted uint224 from uint256, reverting on
* overflow (when the input is greater than largest uint224).
*
* Counterpart to Solidity's `uint224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toUint224(uint256 value) internal pure returns (uint224) {
if (value > type(uint224).max) {
revert SafeCastOverflowedUintDowncast(224, value);
}
return uint224(value);
}
/**
* @dev Returns the downcasted uint216 from uint256, reverting on
* overflow (when the input is greater than largest uint216).
*
* Counterpart to Solidity's `uint216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toUint216(uint256 value) internal pure returns (uint216) {
if (value > type(uint216).max) {
revert SafeCastOverflowedUintDowncast(216, value);
}
return uint216(value);
}
/**
* @dev Returns the downcasted uint208 from uint256, reverting on
* overflow (when the input is greater than largest uint208).
*
* Counterpart to Solidity's `uint208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toUint208(uint256 value) internal pure returns (uint208) {
if (value > type(uint208).max) {
revert SafeCastOverflowedUintDowncast(208, value);
}
return uint208(value);
}
/**
* @dev Returns the downcasted uint200 from uint256, reverting on
* overflow (when the input is greater than largest uint200).
*
* Counterpart to Solidity's `uint200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toUint200(uint256 value) internal pure returns (uint200) {
if (value > type(uint200).max) {
revert SafeCastOverflowedUintDowncast(200, value);
}
return uint200(value);
}
/**
* @dev Returns the downcasted uint192 from uint256, reverting on
* overflow (when the input is greater than largest uint192).
*
* Counterpart to Solidity's `uint192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toUint192(uint256 value) internal pure returns (uint192) {
if (value > type(uint192).max) {
revert SafeCastOverflowedUintDowncast(192, value);
}
return uint192(value);
}
/**
* @dev Returns the downcasted uint184 from uint256, reverting on
* overflow (when the input is greater than largest uint184).
*
* Counterpart to Solidity's `uint184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toUint184(uint256 value) internal pure returns (uint184) {
if (value > type(uint184).max) {
revert SafeCastOverflowedUintDowncast(184, value);
}
return uint184(value);
}
/**
* @dev Returns the downcasted uint176 from uint256, reverting on
* overflow (when the input is greater than largest uint176).
*
* Counterpart to Solidity's `uint176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toUint176(uint256 value) internal pure returns (uint176) {
if (value > type(uint176).max) {
revert SafeCastOverflowedUintDowncast(176, value);
}
return uint176(value);
}
/**
* @dev Returns the downcasted uint168 from uint256, reverting on
* overflow (when the input is greater than largest uint168).
*
* Counterpart to Solidity's `uint168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toUint168(uint256 value) internal pure returns (uint168) {
if (value > type(uint168).max) {
revert SafeCastOverflowedUintDowncast(168, value);
}
return uint168(value);
}
/**
* @dev Returns the downcasted uint160 from uint256, reverting on
* overflow (when the input is greater than largest uint160).
*
* Counterpart to Solidity's `uint160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toUint160(uint256 value) internal pure returns (uint160) {
if (value > type(uint160).max) {
revert SafeCastOverflowedUintDowncast(160, value);
}
return uint160(value);
}
/**
* @dev Returns the downcasted uint152 from uint256, reverting on
* overflow (when the input is greater than largest uint152).
*
* Counterpart to Solidity's `uint152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toUint152(uint256 value) internal pure returns (uint152) {
if (value > type(uint152).max) {
revert SafeCastOverflowedUintDowncast(152, value);
}
return uint152(value);
}
/**
* @dev Returns the downcasted uint144 from uint256, reverting on
* overflow (when the input is greater than largest uint144).
*
* Counterpart to Solidity's `uint144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toUint144(uint256 value) internal pure returns (uint144) {
if (value > type(uint144).max) {
revert SafeCastOverflowedUintDowncast(144, value);
}
return uint144(value);
}
/**
* @dev Returns the downcasted uint136 from uint256, reverting on
* overflow (when the input is greater than largest uint136).
*
* Counterpart to Solidity's `uint136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toUint136(uint256 value) internal pure returns (uint136) {
if (value > type(uint136).max) {
revert SafeCastOverflowedUintDowncast(136, value);
}
return uint136(value);
}
/**
* @dev Returns the downcasted uint128 from uint256, reverting on
* overflow (when the input is greater than largest uint128).
*
* Counterpart to Solidity's `uint128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toUint128(uint256 value) internal pure returns (uint128) {
if (value > type(uint128).max) {
revert SafeCastOverflowedUintDowncast(128, value);
}
return uint128(value);
}
/**
* @dev Returns the downcasted uint120 from uint256, reverting on
* overflow (when the input is greater than largest uint120).
*
* Counterpart to Solidity's `uint120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toUint120(uint256 value) internal pure returns (uint120) {
if (value > type(uint120).max) {
revert SafeCastOverflowedUintDowncast(120, value);
}
return uint120(value);
}
/**
* @dev Returns the downcasted uint112 from uint256, reverting on
* overflow (when the input is greater than largest uint112).
*
* Counterpart to Solidity's `uint112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toUint112(uint256 value) internal pure returns (uint112) {
if (value > type(uint112).max) {
revert SafeCastOverflowedUintDowncast(112, value);
}
return uint112(value);
}
/**
* @dev Returns the downcasted uint104 from uint256, reverting on
* overflow (when the input is greater than largest uint104).
*
* Counterpart to Solidity's `uint104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toUint104(uint256 value) internal pure returns (uint104) {
if (value > type(uint104).max) {
revert SafeCastOverflowedUintDowncast(104, value);
}
return uint104(value);
}
/**
* @dev Returns the downcasted uint96 from uint256, reverting on
* overflow (when the input is greater than largest uint96).
*
* Counterpart to Solidity's `uint96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toUint96(uint256 value) internal pure returns (uint96) {
if (value > type(uint96).max) {
revert SafeCastOverflowedUintDowncast(96, value);
}
return uint96(value);
}
/**
* @dev Returns the downcasted uint88 from uint256, reverting on
* overflow (when the input is greater than largest uint88).
*
* Counterpart to Solidity's `uint88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toUint88(uint256 value) internal pure returns (uint88) {
if (value > type(uint88).max) {
revert SafeCastOverflowedUintDowncast(88, value);
}
return uint88(value);
}
/**
* @dev Returns the downcasted uint80 from uint256, reverting on
* overflow (when the input is greater than largest uint80).
*
* Counterpart to Solidity's `uint80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toUint80(uint256 value) internal pure returns (uint80) {
if (value > type(uint80).max) {
revert SafeCastOverflowedUintDowncast(80, value);
}
return uint80(value);
}
/**
* @dev Returns the downcasted uint72 from uint256, reverting on
* overflow (when the input is greater than largest uint72).
*
* Counterpart to Solidity's `uint72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toUint72(uint256 value) internal pure returns (uint72) {
if (value > type(uint72).max) {
revert SafeCastOverflowedUintDowncast(72, value);
}
return uint72(value);
}
/**
* @dev Returns the downcasted uint64 from uint256, reverting on
* overflow (when the input is greater than largest uint64).
*
* Counterpart to Solidity's `uint64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toUint64(uint256 value) internal pure returns (uint64) {
if (value > type(uint64).max) {
revert SafeCastOverflowedUintDowncast(64, value);
}
return uint64(value);
}
/**
* @dev Returns the downcasted uint56 from uint256, reverting on
* overflow (when the input is greater than largest uint56).
*
* Counterpart to Solidity's `uint56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toUint56(uint256 value) internal pure returns (uint56) {
if (value > type(uint56).max) {
revert SafeCastOverflowedUintDowncast(56, value);
}
return uint56(value);
}
/**
* @dev Returns the downcasted uint48 from uint256, reverting on
* overflow (when the input is greater than largest uint48).
*
* Counterpart to Solidity's `uint48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toUint48(uint256 value) internal pure returns (uint48) {
if (value > type(uint48).max) {
revert SafeCastOverflowedUintDowncast(48, value);
}
return uint48(value);
}
/**
* @dev Returns the downcasted uint40 from uint256, reverting on
* overflow (when the input is greater than largest uint40).
*
* Counterpart to Solidity's `uint40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toUint40(uint256 value) internal pure returns (uint40) {
if (value > type(uint40).max) {
revert SafeCastOverflowedUintDowncast(40, value);
}
return uint40(value);
}
/**
* @dev Returns the downcasted uint32 from uint256, reverting on
* overflow (when the input is greater than largest uint32).
*
* Counterpart to Solidity's `uint32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toUint32(uint256 value) internal pure returns (uint32) {
if (value > type(uint32).max) {
revert SafeCastOverflowedUintDowncast(32, value);
}
return uint32(value);
}
/**
* @dev Returns the downcasted uint24 from uint256, reverting on
* overflow (when the input is greater than largest uint24).
*
* Counterpart to Solidity's `uint24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toUint24(uint256 value) internal pure returns (uint24) {
if (value > type(uint24).max) {
revert SafeCastOverflowedUintDowncast(24, value);
}
return uint24(value);
}
/**
* @dev Returns the downcasted uint16 from uint256, reverting on
* overflow (when the input is greater than largest uint16).
*
* Counterpart to Solidity's `uint16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toUint16(uint256 value) internal pure returns (uint16) {
if (value > type(uint16).max) {
revert SafeCastOverflowedUintDowncast(16, value);
}
return uint16(value);
}
/**
* @dev Returns the downcasted uint8 from uint256, reverting on
* overflow (when the input is greater than largest uint8).
*
* Counterpart to Solidity's `uint8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toUint8(uint256 value) internal pure returns (uint8) {
if (value > type(uint8).max) {
revert SafeCastOverflowedUintDowncast(8, value);
}
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*/
function toUint256(int256 value) internal pure returns (uint256) {
if (value < 0) {
revert SafeCastOverflowedIntToUint(value);
}
return uint256(value);
}
/**
* @dev Returns the downcasted int248 from int256, reverting on
* overflow (when the input is less than smallest int248 or
* greater than largest int248).
*
* Counterpart to Solidity's `int248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toInt248(int256 value) internal pure returns (int248 downcasted) {
downcasted = int248(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(248, value);
}
}
/**
* @dev Returns the downcasted int240 from int256, reverting on
* overflow (when the input is less than smallest int240 or
* greater than largest int240).
*
* Counterpart to Solidity's `int240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toInt240(int256 value) internal pure returns (int240 downcasted) {
downcasted = int240(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(240, value);
}
}
/**
* @dev Returns the downcasted int232 from int256, reverting on
* overflow (when the input is less than smallest int232 or
* greater than largest int232).
*
* Counterpart to Solidity's `int232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toInt232(int256 value) internal pure returns (int232 downcasted) {
downcasted = int232(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(232, value);
}
}
/**
* @dev Returns the downcasted int224 from int256, reverting on
* overflow (when the input is less than smallest int224 or
* greater than largest int224).
*
* Counterpart to Solidity's `int224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toInt224(int256 value) internal pure returns (int224 downcasted) {
downcasted = int224(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(224, value);
}
}
/**
* @dev Returns the downcasted int216 from int256, reverting on
* overflow (when the input is less than smallest int216 or
* greater than largest int216).
*
* Counterpart to Solidity's `int216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toInt216(int256 value) internal pure returns (int216 downcasted) {
downcasted = int216(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(216, value);
}
}
/**
* @dev Returns the downcasted int208 from int256, reverting on
* overflow (when the input is less than smallest int208 or
* greater than largest int208).
*
* Counterpart to Solidity's `int208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toInt208(int256 value) internal pure returns (int208 downcasted) {
downcasted = int208(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(208, value);
}
}
/**
* @dev Returns the downcasted int200 from int256, reverting on
* overflow (when the input is less than smallest int200 or
* greater than largest int200).
*
* Counterpart to Solidity's `int200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toInt200(int256 value) internal pure returns (int200 downcasted) {
downcasted = int200(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(200, value);
}
}
/**
* @dev Returns the downcasted int192 from int256, reverting on
* overflow (when the input is less than smallest int192 or
* greater than largest int192).
*
* Counterpart to Solidity's `int192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toInt192(int256 value) internal pure returns (int192 downcasted) {
downcasted = int192(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(192, value);
}
}
/**
* @dev Returns the downcasted int184 from int256, reverting on
* overflow (when the input is less than smallest int184 or
* greater than largest int184).
*
* Counterpart to Solidity's `int184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toInt184(int256 value) internal pure returns (int184 downcasted) {
downcasted = int184(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(184, value);
}
}
/**
* @dev Returns the downcasted int176 from int256, reverting on
* overflow (when the input is less than smallest int176 or
* greater than largest int176).
*
* Counterpart to Solidity's `int176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toInt176(int256 value) internal pure returns (int176 downcasted) {
downcasted = int176(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(176, value);
}
}
/**
* @dev Returns the downcasted int168 from int256, reverting on
* overflow (when the input is less than smallest int168 or
* greater than largest int168).
*
* Counterpart to Solidity's `int168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toInt168(int256 value) internal pure returns (int168 downcasted) {
downcasted = int168(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(168, value);
}
}
/**
* @dev Returns the downcasted int160 from int256, reverting on
* overflow (when the input is less than smallest int160 or
* greater than largest int160).
*
* Counterpart to Solidity's `int160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toInt160(int256 value) internal pure returns (int160 downcasted) {
downcasted = int160(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(160, value);
}
}
/**
* @dev Returns the downcasted int152 from int256, reverting on
* overflow (when the input is less than smallest int152 or
* greater than largest int152).
*
* Counterpart to Solidity's `int152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toInt152(int256 value) internal pure returns (int152 downcasted) {
downcasted = int152(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(152, value);
}
}
/**
* @dev Returns the downcasted int144 from int256, reverting on
* overflow (when the input is less than smallest int144 or
* greater than largest int144).
*
* Counterpart to Solidity's `int144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toInt144(int256 value) internal pure returns (int144 downcasted) {
downcasted = int144(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(144, value);
}
}
/**
* @dev Returns the downcasted int136 from int256, reverting on
* overflow (when the input is less than smallest int136 or
* greater than largest int136).
*
* Counterpart to Solidity's `int136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toInt136(int256 value) internal pure returns (int136 downcasted) {
downcasted = int136(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(136, value);
}
}
/**
* @dev Returns the downcasted int128 from int256, reverting on
* overflow (when the input is less than smallest int128 or
* greater than largest int128).
*
* Counterpart to Solidity's `int128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toInt128(int256 value) internal pure returns (int128 downcasted) {
downcasted = int128(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(128, value);
}
}
/**
* @dev Returns the downcasted int120 from int256, reverting on
* overflow (when the input is less than smallest int120 or
* greater than largest int120).
*
* Counterpart to Solidity's `int120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toInt120(int256 value) internal pure returns (int120 downcasted) {
downcasted = int120(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(120, value);
}
}
/**
* @dev Returns the downcasted int112 from int256, reverting on
* overflow (when the input is less than smallest int112 or
* greater than largest int112).
*
* Counterpart to Solidity's `int112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toInt112(int256 value) internal pure returns (int112 downcasted) {
downcasted = int112(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(112, value);
}
}
/**
* @dev Returns the downcasted int104 from int256, reverting on
* overflow (when the input is less than smallest int104 or
* greater than largest int104).
*
* Counterpart to Solidity's `int104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toInt104(int256 value) internal pure returns (int104 downcasted) {
downcasted = int104(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(104, value);
}
}
/**
* @dev Returns the downcasted int96 from int256, reverting on
* overflow (when the input is less than smallest int96 or
* greater than largest int96).
*
* Counterpart to Solidity's `int96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toInt96(int256 value) internal pure returns (int96 downcasted) {
downcasted = int96(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(96, value);
}
}
/**
* @dev Returns the downcasted int88 from int256, reverting on
* overflow (when the input is less than smallest int88 or
* greater than largest int88).
*
* Counterpart to Solidity's `int88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toInt88(int256 value) internal pure returns (int88 downcasted) {
downcasted = int88(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(88, value);
}
}
/**
* @dev Returns the downcasted int80 from int256, reverting on
* overflow (when the input is less than smallest int80 or
* greater than largest int80).
*
* Counterpart to Solidity's `int80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toInt80(int256 value) internal pure returns (int80 downcasted) {
downcasted = int80(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(80, value);
}
}
/**
* @dev Returns the downcasted int72 from int256, reverting on
* overflow (when the input is less than smallest int72 or
* greater than largest int72).
*
* Counterpart to Solidity's `int72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toInt72(int256 value) internal pure returns (int72 downcasted) {
downcasted = int72(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(72, value);
}
}
/**
* @dev Returns the downcasted int64 from int256, reverting on
* overflow (when the input is less than smallest int64 or
* greater than largest int64).
*
* Counterpart to Solidity's `int64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toInt64(int256 value) internal pure returns (int64 downcasted) {
downcasted = int64(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(64, value);
}
}
/**
* @dev Returns the downcasted int56 from int256, reverting on
* overflow (when the input is less than smallest int56 or
* greater than largest int56).
*
* Counterpart to Solidity's `int56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toInt56(int256 value) internal pure returns (int56 downcasted) {
downcasted = int56(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(56, value);
}
}
/**
* @dev Returns the downcasted int48 from int256, reverting on
* overflow (when the input is less than smallest int48 or
* greater than largest int48).
*
* Counterpart to Solidity's `int48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toInt48(int256 value) internal pure returns (int48 downcasted) {
downcasted = int48(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(48, value);
}
}
/**
* @dev Returns the downcasted int40 from int256, reverting on
* overflow (when the input is less than smallest int40 or
* greater than largest int40).
*
* Counterpart to Solidity's `int40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toInt40(int256 value) internal pure returns (int40 downcasted) {
downcasted = int40(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(40, value);
}
}
/**
* @dev Returns the downcasted int32 from int256, reverting on
* overflow (when the input is less than smallest int32 or
* greater than largest int32).
*
* Counterpart to Solidity's `int32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toInt32(int256 value) internal pure returns (int32 downcasted) {
downcasted = int32(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(32, value);
}
}
/**
* @dev Returns the downcasted int24 from int256, reverting on
* overflow (when the input is less than smallest int24 or
* greater than largest int24).
*
* Counterpart to Solidity's `int24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toInt24(int256 value) internal pure returns (int24 downcasted) {
downcasted = int24(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(24, value);
}
}
/**
* @dev Returns the downcasted int16 from int256, reverting on
* overflow (when the input is less than smallest int16 or
* greater than largest int16).
*
* Counterpart to Solidity's `int16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toInt16(int256 value) internal pure returns (int16 downcasted) {
downcasted = int16(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(16, value);
}
}
/**
* @dev Returns the downcasted int8 from int256, reverting on
* overflow (when the input is less than smallest int8 or
* greater than largest int8).
*
* Counterpart to Solidity's `int8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toInt8(int256 value) internal pure returns (int8 downcasted) {
downcasted = int8(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(8, value);
}
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*/
function toInt256(uint256 value) internal pure returns (int256) {
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
if (value > uint256(type(int256).max)) {
revert SafeCastOverflowedUintToInt(value);
}
return int256(value);
}
/**
* @dev Cast a boolean (false or true) to a uint256 (0 or 1) with no jump.
*/
function toUint(bool b) internal pure returns (uint256 u) {
assembly ("memory-safe") {
u := iszero(iszero(b))
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SignedMath.sol)
pragma solidity ^0.8.20;
import {SafeCast} from "./SafeCast.sol";
/**
* @dev Standard signed math utilities missing in the Solidity language.
*/
library SignedMath {
/**
* @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.
*
* IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.
* However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute
* one branch when needed, making this function more expensive.
*/
function ternary(bool condition, int256 a, int256 b) internal pure returns (int256) {
unchecked {
// branchless ternary works because:
// b ^ (a ^ b) == a
// b ^ 0 == b
return b ^ ((a ^ b) * int256(SafeCast.toUint(condition)));
}
}
/**
* @dev Returns the largest of two signed numbers.
*/
function max(int256 a, int256 b) internal pure returns (int256) {
return ternary(a > b, a, b);
}
/**
* @dev Returns the smallest of two signed numbers.
*/
function min(int256 a, int256 b) internal pure returns (int256) {
return ternary(a < b, a, b);
}
/**
* @dev Returns the average of two signed numbers without overflow.
* The result is rounded towards zero.
*/
function average(int256 a, int256 b) internal pure returns (int256) {
// Formula from the book "Hacker's Delight"
int256 x = (a & b) + ((a ^ b) >> 1);
return x + (int256(uint256(x) >> 255) & (a ^ b));
}
/**
* @dev Returns the absolute unsigned value of a signed value.
*/
function abs(int256 n) internal pure returns (uint256) {
unchecked {
// Formula from the "Bit Twiddling Hacks" by Sean Eron Anderson.
// Since `n` is a signed integer, the generated bytecode will use the SAR opcode to perform the right shift,
// taking advantage of the most significant (or "sign" bit) in two's complement representation.
// This opcode adds new most significant bits set to the value of the previous most significant bit. As a result,
// the mask will either be `bytes32(0)` (if n is positive) or `~bytes32(0)` (if n is negative).
int256 mask = n >> 255;
// A `bytes32(0)` mask leaves the input unchanged, while a `~bytes32(0)` mask complements it.
return uint256((n + mask) ^ mask);
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {PoolKey} from "../types/PoolKey.sol";
import {BalanceDelta} from "../types/BalanceDelta.sol";
import {IPoolManager} from "./IPoolManager.sol";
import {BeforeSwapDelta} from "../types/BeforeSwapDelta.sol";
/// @notice V4 decides whether to invoke specific hooks by inspecting the least significant bits
/// of the address that the hooks contract is deployed to.
/// For example, a hooks contract deployed to address: 0x0000000000000000000000000000000000002400
/// has the lowest bits '10 0100 0000 0000' which would cause the 'before initialize' and 'after add liquidity' hooks to be used.
/// See the Hooks library for the full spec.
/// @dev Should only be callable by the v4 PoolManager.
interface IHooks {
/// @notice The hook called before the state of a pool is initialized
/// @param sender The initial msg.sender for the initialize call
/// @param key The key for the pool being initialized
/// @param sqrtPriceX96 The sqrt(price) of the pool as a Q64.96
/// @return bytes4 The function selector for the hook
function beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96) external returns (bytes4);
/// @notice The hook called after the state of a pool is initialized
/// @param sender The initial msg.sender for the initialize call
/// @param key The key for the pool being initialized
/// @param sqrtPriceX96 The sqrt(price) of the pool as a Q64.96
/// @param tick The current tick after the state of a pool is initialized
/// @return bytes4 The function selector for the hook
function afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)
external
returns (bytes4);
/// @notice The hook called before liquidity is added
/// @param sender The initial msg.sender for the add liquidity call
/// @param key The key for the pool
/// @param params The parameters for adding liquidity
/// @param hookData Arbitrary data handed into the PoolManager by the liquidity provider to be passed on to the hook
/// @return bytes4 The function selector for the hook
function beforeAddLiquidity(
address sender,
PoolKey calldata key,
IPoolManager.ModifyLiquidityParams calldata params,
bytes calldata hookData
) external returns (bytes4);
/// @notice The hook called after liquidity is added
/// @param sender The initial msg.sender for the add liquidity call
/// @param key The key for the pool
/// @param params The parameters for adding liquidity
/// @param delta The caller's balance delta after adding liquidity; the sum of principal delta, fees accrued, and hook delta
/// @param feesAccrued The fees accrued since the last time fees were collected from this position
/// @param hookData Arbitrary data handed into the PoolManager by the liquidity provider to be passed on to the hook
/// @return bytes4 The function selector for the hook
/// @return BalanceDelta The hook's delta in token0 and token1. Positive: the hook is owed/took currency, negative: the hook owes/sent currency
function afterAddLiquidity(
address sender,
PoolKey calldata key,
IPoolManager.ModifyLiquidityParams calldata params,
BalanceDelta delta,
BalanceDelta feesAccrued,
bytes calldata hookData
) external returns (bytes4, BalanceDelta);
/// @notice The hook called before liquidity is removed
/// @param sender The initial msg.sender for the remove liquidity call
/// @param key The key for the pool
/// @param params The parameters for removing liquidity
/// @param hookData Arbitrary data handed into the PoolManager by the liquidity provider to be be passed on to the hook
/// @return bytes4 The function selector for the hook
function beforeRemoveLiquidity(
address sender,
PoolKey calldata key,
IPoolManager.ModifyLiquidityParams calldata params,
bytes calldata hookData
) external returns (bytes4);
/// @notice The hook called after liquidity is removed
/// @param sender The initial msg.sender for the remove liquidity call
/// @param key The key for the pool
/// @param params The parameters for removing liquidity
/// @param delta The caller's balance delta after removing liquidity; the sum of principal delta, fees accrued, and hook delta
/// @param feesAccrued The fees accrued since the last time fees were collected from this position
/// @param hookData Arbitrary data handed into the PoolManager by the liquidity provider to be be passed on to the hook
/// @return bytes4 The function selector for the hook
/// @return BalanceDelta The hook's delta in token0 and token1. Positive: the hook is owed/took currency, negative: the hook owes/sent currency
function afterRemoveLiquidity(
address sender,
PoolKey calldata key,
IPoolManager.ModifyLiquidityParams calldata params,
BalanceDelta delta,
BalanceDelta feesAccrued,
bytes calldata hookData
) external returns (bytes4, BalanceDelta);
/// @notice The hook called before a swap
/// @param sender The initial msg.sender for the swap call
/// @param key The key for the pool
/// @param params The parameters for the swap
/// @param hookData Arbitrary data handed into the PoolManager by the swapper to be be passed on to the hook
/// @return bytes4 The function selector for the hook
/// @return BeforeSwapDelta The hook's delta in specified and unspecified currencies. Positive: the hook is owed/took currency, negative: the hook owes/sent currency
/// @return uint24 Optionally override the lp fee, only used if three conditions are met: 1. the Pool has a dynamic fee, 2. the value's 2nd highest bit is set (23rd bit, 0x400000), and 3. the value is less than or equal to the maximum fee (1 million)
function beforeSwap(
address sender,
PoolKey calldata key,
IPoolManager.SwapParams calldata params,
bytes calldata hookData
) external returns (bytes4, BeforeSwapDelta, uint24);
/// @notice The hook called after a swap
/// @param sender The initial msg.sender for the swap call
/// @param key The key for the pool
/// @param params The parameters for the swap
/// @param delta The amount owed to the caller (positive) or owed to the pool (negative)
/// @param hookData Arbitrary data handed into the PoolManager by the swapper to be be passed on to the hook
/// @return bytes4 The function selector for the hook
/// @return int128 The hook's delta in unspecified currency. Positive: the hook is owed/took currency, negative: the hook owes/sent currency
function afterSwap(
address sender,
PoolKey calldata key,
IPoolManager.SwapParams calldata params,
BalanceDelta delta,
bytes calldata hookData
) external returns (bytes4, int128);
/// @notice The hook called before donate
/// @param sender The initial msg.sender for the donate call
/// @param key The key for the pool
/// @param amount0 The amount of token0 being donated
/// @param amount1 The amount of token1 being donated
/// @param hookData Arbitrary data handed into the PoolManager by the donor to be be passed on to the hook
/// @return bytes4 The function selector for the hook
function beforeDonate(
address sender,
PoolKey calldata key,
uint256 amount0,
uint256 amount1,
bytes calldata hookData
) external returns (bytes4);
/// @notice The hook called after donate
/// @param sender The initial msg.sender for the donate call
/// @param key The key for the pool
/// @param amount0 The amount of token0 being donated
/// @param amount1 The amount of token1 being donated
/// @param hookData Arbitrary data handed into the PoolManager by the donor to be be passed on to the hook
/// @return bytes4 The function selector for the hook
function afterDonate(
address sender,
PoolKey calldata key,
uint256 amount0,
uint256 amount1,
bytes calldata hookData
) external returns (bytes4);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @notice Interface for claims over a contract balance, wrapped as a ERC6909
interface IERC6909Claims {
/*//////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////*/
event OperatorSet(address indexed owner, address indexed operator, bool approved);
event Approval(address indexed owner, address indexed spender, uint256 indexed id, uint256 amount);
event Transfer(address caller, address indexed from, address indexed to, uint256 indexed id, uint256 amount);
/*//////////////////////////////////////////////////////////////
FUNCTIONS
//////////////////////////////////////////////////////////////*/
/// @notice Owner balance of an id.
/// @param owner The address of the owner.
/// @param id The id of the token.
/// @return amount The balance of the token.
function balanceOf(address owner, uint256 id) external view returns (uint256 amount);
/// @notice Spender allowance of an id.
/// @param owner The address of the owner.
/// @param spender The address of the spender.
/// @param id The id of the token.
/// @return amount The allowance of the token.
function allowance(address owner, address spender, uint256 id) external view returns (uint256 amount);
/// @notice Checks if a spender is approved by an owner as an operator
/// @param owner The address of the owner.
/// @param spender The address of the spender.
/// @return approved The approval status.
function isOperator(address owner, address spender) external view returns (bool approved);
/// @notice Transfers an amount of an id from the caller to a receiver.
/// @param receiver The address of the receiver.
/// @param id The id of the token.
/// @param amount The amount of the token.
/// @return bool True, always, unless the function reverts
function transfer(address receiver, uint256 id, uint256 amount) external returns (bool);
/// @notice Transfers an amount of an id from a sender to a receiver.
/// @param sender The address of the sender.
/// @param receiver The address of the receiver.
/// @param id The id of the token.
/// @param amount The amount of the token.
/// @return bool True, always, unless the function reverts
function transferFrom(address sender, address receiver, uint256 id, uint256 amount) external returns (bool);
/// @notice Approves an amount of an id to a spender.
/// @param spender The address of the spender.
/// @param id The id of the token.
/// @param amount The amount of the token.
/// @return bool True, always
function approve(address spender, uint256 id, uint256 amount) external returns (bool);
/// @notice Sets or removes an operator for the caller.
/// @param operator The address of the operator.
/// @param approved The approval status.
/// @return bool True, always
function setOperator(address operator, bool approved) external returns (bool);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {Currency} from "../types/Currency.sol";
import {PoolId} from "../types/PoolId.sol";
import {PoolKey} from "../types/PoolKey.sol";
/// @notice Interface for all protocol-fee related functions in the pool manager
interface IProtocolFees {
/// @notice Thrown when protocol fee is set too high
error ProtocolFeeTooLarge(uint24 fee);
/// @notice Thrown when collectProtocolFees or setProtocolFee is not called by the controller.
error InvalidCaller();
/// @notice Thrown when collectProtocolFees is attempted on a token that is synced.
error ProtocolFeeCurrencySynced();
/// @notice Emitted when the protocol fee controller address is updated in setProtocolFeeController.
event ProtocolFeeControllerUpdated(address indexed protocolFeeController);
/// @notice Emitted when the protocol fee is updated for a pool.
event ProtocolFeeUpdated(PoolId indexed id, uint24 protocolFee);
/// @notice Given a currency address, returns the protocol fees accrued in that currency
/// @param currency The currency to check
/// @return amount The amount of protocol fees accrued in the currency
function protocolFeesAccrued(Currency currency) external view returns (uint256 amount);
/// @notice Sets the protocol fee for the given pool
/// @param key The key of the pool to set a protocol fee for
/// @param newProtocolFee The fee to set
function setProtocolFee(PoolKey memory key, uint24 newProtocolFee) external;
/// @notice Sets the protocol fee controller
/// @param controller The new protocol fee controller
function setProtocolFeeController(address controller) external;
/// @notice Collects the protocol fees for a given recipient and currency, returning the amount collected
/// @dev This will revert if the contract is unlocked
/// @param recipient The address to receive the protocol fees
/// @param currency The currency to withdraw
/// @param amount The amount of currency to withdraw
/// @return amountCollected The amount of currency successfully withdrawn
function collectProtocolFees(address recipient, Currency currency, uint256 amount)
external
returns (uint256 amountCollected);
/// @notice Returns the current protocol fee controller address
/// @return address The current protocol fee controller address
function protocolFeeController() external view returns (address);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {SafeCast} from "../libraries/SafeCast.sol";
/// @dev Two `int128` values packed into a single `int256` where the upper 128 bits represent the amount0
/// and the lower 128 bits represent the amount1.
type BalanceDelta is int256;
using {add as +, sub as -, eq as ==, neq as !=} for BalanceDelta global;
using BalanceDeltaLibrary for BalanceDelta global;
using SafeCast for int256;
function toBalanceDelta(int128 _amount0, int128 _amount1) pure returns (BalanceDelta balanceDelta) {
assembly ("memory-safe") {
balanceDelta := or(shl(128, _amount0), and(sub(shl(128, 1), 1), _amount1))
}
}
function add(BalanceDelta a, BalanceDelta b) pure returns (BalanceDelta) {
int256 res0;
int256 res1;
assembly ("memory-safe") {
let a0 := sar(128, a)
let a1 := signextend(15, a)
let b0 := sar(128, b)
let b1 := signextend(15, b)
res0 := add(a0, b0)
res1 := add(a1, b1)
}
return toBalanceDelta(res0.toInt128(), res1.toInt128());
}
function sub(BalanceDelta a, BalanceDelta b) pure returns (BalanceDelta) {
int256 res0;
int256 res1;
assembly ("memory-safe") {
let a0 := sar(128, a)
let a1 := signextend(15, a)
let b0 := sar(128, b)
let b1 := signextend(15, b)
res0 := sub(a0, b0)
res1 := sub(a1, b1)
}
return toBalanceDelta(res0.toInt128(), res1.toInt128());
}
function eq(BalanceDelta a, BalanceDelta b) pure returns (bool) {
return BalanceDelta.unwrap(a) == BalanceDelta.unwrap(b);
}
function neq(BalanceDelta a, BalanceDelta b) pure returns (bool) {
return BalanceDelta.unwrap(a) != BalanceDelta.unwrap(b);
}
/// @notice Library for getting the amount0 and amount1 deltas from the BalanceDelta type
library BalanceDeltaLibrary {
/// @notice A BalanceDelta of 0
BalanceDelta public constant ZERO_DELTA = BalanceDelta.wrap(0);
function amount0(BalanceDelta balanceDelta) internal pure returns (int128 _amount0) {
assembly ("memory-safe") {
_amount0 := sar(128, balanceDelta)
}
}
function amount1(BalanceDelta balanceDelta) internal pure returns (int128 _amount1) {
assembly ("memory-safe") {
_amount1 := signextend(15, balanceDelta)
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @notice Interface for functions to access any storage slot in a contract
interface IExtsload {
/// @notice Called by external contracts to access granular pool state
/// @param slot Key of slot to sload
/// @return value The value of the slot as bytes32
function extsload(bytes32 slot) external view returns (bytes32 value);
/// @notice Called by external contracts to access granular pool state
/// @param startSlot Key of slot to start sloading from
/// @param nSlots Number of slots to load into return value
/// @return values List of loaded values.
function extsload(bytes32 startSlot, uint256 nSlots) external view returns (bytes32[] memory values);
/// @notice Called by external contracts to access sparse pool state
/// @param slots List of slots to SLOAD from.
/// @return values List of loaded values.
function extsload(bytes32[] calldata slots) external view returns (bytes32[] memory values);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
/// @notice Interface for functions to access any transient storage slot in a contract
interface IExttload {
/// @notice Called by external contracts to access transient storage of the contract
/// @param slot Key of slot to tload
/// @return value The value of the slot as bytes32
function exttload(bytes32 slot) external view returns (bytes32 value);
/// @notice Called by external contracts to access sparse transient pool state
/// @param slots List of slots to tload
/// @return values List of loaded values
function exttload(bytes32[] calldata slots) external view returns (bytes32[] memory values);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";
import {PoolId, PoolIdLibrary} from "@uniswap/v4-core/src/types/PoolId.sol";
/**
* @dev PositionInfo is a packed version of solidity structure.
* Using the packaged version saves gas and memory by not storing the structure fields in memory slots.
*
* Layout:
* 200 bits poolId | 24 bits tickUpper | 24 bits tickLower | 8 bits hasSubscriber
*
* Fields in the direction from the least significant bit:
*
* A flag to know if the tokenId is subscribed to an address
* uint8 hasSubscriber;
*
* The tickUpper of the position
* int24 tickUpper;
*
* The tickLower of the position
* int24 tickLower;
*
* The truncated poolId. Truncates a bytes32 value so the most signifcant (highest) 200 bits are used.
* bytes25 poolId;
*
* Note: If more bits are needed, hasSubscriber can be a single bit.
*
*/
type PositionInfo is uint256;
library PositionInfoLibrary {
using PoolIdLibrary for PoolKey;
PositionInfo internal constant EMPTY_POSITION_INFO = PositionInfo.wrap(0);
uint256 internal constant MASK_UPPER_200_BITS = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000000000;
uint256 internal constant MASK_8_BITS = 0xFF;
uint24 internal constant MASK_24_BITS = 0xFFFFFF;
uint256 internal constant SET_UNSUBSCRIBE = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00;
uint256 internal constant SET_SUBSCRIBE = 0x01;
uint8 internal constant TICK_LOWER_OFFSET = 8;
uint8 internal constant TICK_UPPER_OFFSET = 32;
/// @dev This poolId is NOT compatible with the poolId used in UniswapV4 core. It is truncated to 25 bytes, and just used to lookup PoolKey in the poolKeys mapping.
function poolId(PositionInfo info) internal pure returns (bytes25 _poolId) {
assembly ("memory-safe") {
_poolId := and(MASK_UPPER_200_BITS, info)
}
}
function tickLower(PositionInfo info) internal pure returns (int24 _tickLower) {
assembly ("memory-safe") {
_tickLower := signextend(2, shr(TICK_LOWER_OFFSET, info))
}
}
function tickUpper(PositionInfo info) internal pure returns (int24 _tickUpper) {
assembly ("memory-safe") {
_tickUpper := signextend(2, shr(TICK_UPPER_OFFSET, info))
}
}
function hasSubscriber(PositionInfo info) internal pure returns (bool _hasSubscriber) {
assembly ("memory-safe") {
_hasSubscriber := and(MASK_8_BITS, info)
}
}
/// @dev this does not actually set any storage
function setSubscribe(PositionInfo info) internal pure returns (PositionInfo _info) {
assembly ("memory-safe") {
_info := or(info, SET_SUBSCRIBE)
}
}
/// @dev this does not actually set any storage
function setUnsubscribe(PositionInfo info) internal pure returns (PositionInfo _info) {
assembly ("memory-safe") {
_info := and(info, SET_UNSUBSCRIBE)
}
}
/// @notice Creates the default PositionInfo struct
/// @dev Called when minting a new position
/// @param _poolKey the pool key of the position
/// @param _tickLower the lower tick of the position
/// @param _tickUpper the upper tick of the position
/// @return info packed position info, with the truncated poolId and the hasSubscriber flag set to false
function initialize(PoolKey memory _poolKey, int24 _tickLower, int24 _tickUpper)
internal
pure
returns (PositionInfo info)
{
bytes25 _poolId = bytes25(PoolId.unwrap(_poolKey.toId()));
assembly {
info :=
or(
or(and(MASK_UPPER_200_BITS, _poolId), shl(TICK_UPPER_OFFSET, and(MASK_24_BITS, _tickUpper))),
shl(TICK_LOWER_OFFSET, and(MASK_24_BITS, _tickLower))
)
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {ISubscriber} from "./ISubscriber.sol";
/// @title INotifier
/// @notice Interface for the Notifier contract
interface INotifier {
/// @notice Thrown when unsubscribing without a subscriber
error NotSubscribed();
/// @notice Thrown when a subscriber does not have code
error NoCodeSubscriber();
/// @notice Thrown when a user specifies a gas limit too low to avoid valid unsubscribe notifications
error GasLimitTooLow();
/// @notice Wraps the revert message of the subscriber contract on a reverting subscription
error SubscriptionReverted(address subscriber, bytes reason);
/// @notice Wraps the revert message of the subscriber contract on a reverting modify liquidity notification
error ModifyLiquidityNotificationReverted(address subscriber, bytes reason);
/// @notice Wraps the revert message of the subscriber contract on a reverting burn notification
error BurnNotificationReverted(address subscriber, bytes reason);
/// @notice Thrown when a tokenId already has a subscriber
error AlreadySubscribed(uint256 tokenId, address subscriber);
/// @notice Emitted on a successful call to subscribe
event Subscription(uint256 indexed tokenId, address indexed subscriber);
/// @notice Emitted on a successful call to unsubscribe
event Unsubscription(uint256 indexed tokenId, address indexed subscriber);
/// @notice Returns the subscriber for a respective position
/// @param tokenId the ERC721 tokenId
/// @return subscriber the subscriber contract
function subscriber(uint256 tokenId) external view returns (ISubscriber subscriber);
/// @notice Enables the subscriber to receive notifications for a respective position
/// @param tokenId the ERC721 tokenId
/// @param newSubscriber the address of the subscriber contract
/// @param data caller-provided data that's forwarded to the subscriber contract
/// @dev Calling subscribe when a position is already subscribed will revert
/// @dev payable so it can be multicalled with NATIVE related actions
/// @dev will revert if pool manager is locked
function subscribe(uint256 tokenId, address newSubscriber, bytes calldata data) external payable;
/// @notice Removes the subscriber from receiving notifications for a respective position
/// @param tokenId the ERC721 tokenId
/// @dev Callers must specify a high gas limit (remaining gas should be higher than unsubscriberGasLimit) such that the subscriber can be notified
/// @dev payable so it can be multicalled with NATIVE related actions
/// @dev Must always allow a user to unsubscribe. In the case of a malicious subscriber, a user can always unsubscribe safely, ensuring liquidity is always modifiable.
/// @dev will revert if pool manager is locked
function unsubscribe(uint256 tokenId) external payable;
/// @notice Returns and determines the maximum allowable gas-used for notifying unsubscribe
/// @return uint256 the maximum gas limit when notifying a subscriber's `notifyUnsubscribe` function
function unsubscribeGasLimit() external view returns (uint256);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";
/// @title IImmutableState
/// @notice Interface for the ImmutableState contract
interface IImmutableState {
/// @notice The Uniswap v4 PoolManager contract
function poolManager() external view returns (IPoolManager);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @title IERC721Permit_v4
/// @notice Interface for the ERC721Permit_v4 contract
interface IERC721Permit_v4 {
error SignatureDeadlineExpired();
error NoSelfPermit();
error Unauthorized();
/// @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 nonce a unique value, for an owner, to prevent replay attacks; an unordered nonce where the top 248 bits correspond to a word and the bottom 8 bits calculate the bit position of the word
/// @param signature Concatenated data from a valid secp256k1 signature from the holder, i.e. abi.encodePacked(r, s, v)
/// @dev payable so it can be multicalled with NATIVE related actions
function permit(address spender, uint256 tokenId, uint256 deadline, uint256 nonce, bytes calldata signature)
external
payable;
/// @notice Set an operator with full permission to an owner's tokens via signature
/// @param owner The address that is setting the operator
/// @param operator The address that will be set as an operator for the owner
/// @param approved The permission to set on the operator
/// @param deadline The deadline timestamp by which the call must be mined for the approve to work
/// @param nonce a unique value, for an owner, to prevent replay attacks; an unordered nonce where the top 248 bits correspond to a word and the bottom 8 bits calculate the bit position of the word
/// @param signature Concatenated data from a valid secp256k1 signature from the holder, i.e. abi.encodePacked(r, s, v)
/// @dev payable so it can be multicalled with NATIVE related actions
function permitForAll(
address owner,
address operator,
bool approved,
uint256 deadline,
uint256 nonce,
bytes calldata signature
) external payable;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @title IEIP712_v4
/// @notice Interface for the EIP712 contract
interface IEIP712_v4 {
/// @notice Returns the domain separator for the current chain.
/// @return bytes32 The domain separator
function DOMAIN_SEPARATOR() external view returns (bytes32);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @title IMulticall_v4
/// @notice Interface for the Multicall_v4 contract
interface IMulticall_v4 {
/// @notice Call multiple functions in the current contract and return the data from all of them if they all succeed
/// @dev The `msg.value` is passed onto all subcalls, even if a previous subcall has consumed the ether.
/// Subcalls can instead use `address(this).value` to see the available ETH, and consume it using {value: x}.
/// @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: MIT
pragma solidity ^0.8.0;
import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";
/// @title IPoolInitializer_v4
/// @notice Interface for the PoolInitializer_v4 contract
interface IPoolInitializer_v4 {
/// @notice Initialize a Uniswap v4 Pool
/// @dev If the pool is already initialized, this function will not revert and just return type(int24).max
/// @param key The PoolKey of the pool to initialize
/// @param sqrtPriceX96 The initial starting price of the pool, expressed as a sqrtPriceX96
/// @return The current tick of the pool, or type(int24).max if the pool creation failed, or the pool already existed
function initializePool(PoolKey calldata key, uint160 sqrtPriceX96) external payable returns (int24);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @title IUnorderedNonce
/// @notice Interface for the UnorderedNonce contract
interface IUnorderedNonce {
error NonceAlreadyUsed();
/// @notice mapping of nonces consumed by each address, where a nonce is a single bit on the 256-bit bitmap
/// @dev word is at most type(uint248).max
function nonces(address owner, uint256 word) external view returns (uint256);
/// @notice Revoke a nonce by spending it, preventing it from being used again
/// @dev Used in cases where a valid nonce has not been broadcasted onchain, and the owner wants to revoke the validity of the nonce
/// @dev payable so it can be multicalled with native-token related actions
function revokeNonce(uint256 nonce) external payable;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {IAllowanceTransfer} from "permit2/src/interfaces/IAllowanceTransfer.sol";
/// @title IPermit2Forwarder
/// @notice Interface for the Permit2Forwarder contract
interface IPermit2Forwarder {
/// @notice allows forwarding a single permit to permit2
/// @dev this function is payable to allow multicall with NATIVE based actions
/// @param owner the owner of the tokens
/// @param permitSingle the permit data
/// @param signature the signature of the permit; abi.encodePacked(r, s, v)
/// @return err the error returned by a reverting permit call, empty if successful
function permit(address owner, IAllowanceTransfer.PermitSingle calldata permitSingle, bytes calldata signature)
external
payable
returns (bytes memory err);
/// @notice allows forwarding batch permits to permit2
/// @dev this function is payable to allow multicall with NATIVE based actions
/// @param owner the owner of the tokens
/// @param _permitBatch a batch of approvals
/// @param signature the signature of the permit; abi.encodePacked(r, s, v)
/// @return err the error returned by a reverting permit call, empty if successful
function permitBatch(address owner, IAllowanceTransfer.PermitBatch calldata _permitBatch, bytes calldata signature)
external
payable
returns (bytes memory err);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @title Minimal ERC20 interface for Uniswap
/// @notice Contains a subset of the full ERC20 interface that is used in Uniswap V3
interface IERC20Minimal {
/// @notice Returns an account's balance in the 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: MIT
pragma solidity ^0.8.0;
/// @title Library for reverting with custom errors efficiently
/// @notice Contains functions for reverting with custom errors with different argument types efficiently
/// @dev To use this library, declare `using CustomRevert for bytes4;` and replace `revert CustomError()` with
/// `CustomError.selector.revertWith()`
/// @dev The functions may tamper with the free memory pointer but it is fine since the call context is exited immediately
library CustomRevert {
/// @dev ERC-7751 error for wrapping bubbled up reverts
error WrappedError(address target, bytes4 selector, bytes reason, bytes details);
/// @dev Reverts with the selector of a custom error in the scratch space
function revertWith(bytes4 selector) internal pure {
assembly ("memory-safe") {
mstore(0, selector)
revert(0, 0x04)
}
}
/// @dev Reverts with a custom error with an address argument in the scratch space
function revertWith(bytes4 selector, address addr) internal pure {
assembly ("memory-safe") {
mstore(0, selector)
mstore(0x04, and(addr, 0xffffffffffffffffffffffffffffffffffffffff))
revert(0, 0x24)
}
}
/// @dev Reverts with a custom error with an int24 argument in the scratch space
function revertWith(bytes4 selector, int24 value) internal pure {
assembly ("memory-safe") {
mstore(0, selector)
mstore(0x04, signextend(2, value))
revert(0, 0x24)
}
}
/// @dev Reverts with a custom error with a uint160 argument in the scratch space
function revertWith(bytes4 selector, uint160 value) internal pure {
assembly ("memory-safe") {
mstore(0, selector)
mstore(0x04, and(value, 0xffffffffffffffffffffffffffffffffffffffff))
revert(0, 0x24)
}
}
/// @dev Reverts with a custom error with two int24 arguments
function revertWith(bytes4 selector, int24 value1, int24 value2) internal pure {
assembly ("memory-safe") {
let fmp := mload(0x40)
mstore(fmp, selector)
mstore(add(fmp, 0x04), signextend(2, value1))
mstore(add(fmp, 0x24), signextend(2, value2))
revert(fmp, 0x44)
}
}
/// @dev Reverts with a custom error with two uint160 arguments
function revertWith(bytes4 selector, uint160 value1, uint160 value2) internal pure {
assembly ("memory-safe") {
let fmp := mload(0x40)
mstore(fmp, selector)
mstore(add(fmp, 0x04), and(value1, 0xffffffffffffffffffffffffffffffffffffffff))
mstore(add(fmp, 0x24), and(value2, 0xffffffffffffffffffffffffffffffffffffffff))
revert(fmp, 0x44)
}
}
/// @dev Reverts with a custom error with two address arguments
function revertWith(bytes4 selector, address value1, address value2) internal pure {
assembly ("memory-safe") {
let fmp := mload(0x40)
mstore(fmp, selector)
mstore(add(fmp, 0x04), and(value1, 0xffffffffffffffffffffffffffffffffffffffff))
mstore(add(fmp, 0x24), and(value2, 0xffffffffffffffffffffffffffffffffffffffff))
revert(fmp, 0x44)
}
}
/// @notice bubble up the revert message returned by a call and revert with a wrapped ERC-7751 error
/// @dev this method can be vulnerable to revert data bombs
function bubbleUpAndRevertWith(
address revertingContract,
bytes4 revertingFunctionSelector,
bytes4 additionalContext
) internal pure {
bytes4 wrappedErrorSelector = WrappedError.selector;
assembly ("memory-safe") {
// Ensure the size of the revert data is a multiple of 32 bytes
let encodedDataSize := mul(div(add(returndatasize(), 31), 32), 32)
let fmp := mload(0x40)
// Encode wrapped error selector, address, function selector, offset, additional context, size, revert reason
mstore(fmp, wrappedErrorSelector)
mstore(add(fmp, 0x04), and(revertingContract, 0xffffffffffffffffffffffffffffffffffffffff))
mstore(
add(fmp, 0x24),
and(revertingFunctionSelector, 0xffffffff00000000000000000000000000000000000000000000000000000000)
)
// offset revert reason
mstore(add(fmp, 0x44), 0x80)
// offset additional context
mstore(add(fmp, 0x64), add(0xa0, encodedDataSize))
// size revert reason
mstore(add(fmp, 0x84), returndatasize())
// revert reason
returndatacopy(add(fmp, 0xa4), 0, returndatasize())
// size additional context
mstore(add(fmp, add(0xa4, encodedDataSize)), 0x04)
// additional context
mstore(
add(fmp, add(0xc4, encodedDataSize)),
and(additionalContext, 0xffffffff00000000000000000000000000000000000000000000000000000000)
)
revert(fmp, add(0xe4, encodedDataSize))
}
}
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;
import {FullMath} from "./FullMath.sol";
import {FixedPoint128} from "./FixedPoint128.sol";
import {LiquidityMath} from "./LiquidityMath.sol";
import {CustomRevert} from "./CustomRevert.sol";
/// @title Position
/// @notice Positions represent an owner address' liquidity between a lower and upper tick boundary
/// @dev Positions store additional state for tracking fees owed to the position
library Position {
using CustomRevert for bytes4;
/// @notice Cannot update a position with no liquidity
error CannotUpdateEmptyPosition();
// info stored for each user's position
struct State {
// the amount of liquidity owned by this position
uint128 liquidity;
// fee growth per unit of liquidity as of the last update to liquidity or fees owed
uint256 feeGrowthInside0LastX128;
uint256 feeGrowthInside1LastX128;
}
/// @notice Returns the State struct of a position, given an owner and position boundaries
/// @param self The mapping containing all user positions
/// @param owner The address of the position owner
/// @param tickLower The lower tick boundary of the position
/// @param tickUpper The upper tick boundary of the position
/// @param salt A unique value to differentiate between multiple positions in the same range
/// @return position The position info struct of the given owners' position
function get(mapping(bytes32 => State) storage self, address owner, int24 tickLower, int24 tickUpper, bytes32 salt)
internal
view
returns (State storage position)
{
bytes32 positionKey = calculatePositionKey(owner, tickLower, tickUpper, salt);
position = self[positionKey];
}
/// @notice A helper function to calculate the position key
/// @param owner The address of the position owner
/// @param tickLower the lower tick boundary of the position
/// @param tickUpper the upper tick boundary of the position
/// @param salt A unique value to differentiate between multiple positions in the same range, by the same owner. Passed in by the caller.
function calculatePositionKey(address owner, int24 tickLower, int24 tickUpper, bytes32 salt)
internal
pure
returns (bytes32 positionKey)
{
// positionKey = keccak256(abi.encodePacked(owner, tickLower, tickUpper, salt))
assembly ("memory-safe") {
let fmp := mload(0x40)
mstore(add(fmp, 0x26), salt) // [0x26, 0x46)
mstore(add(fmp, 0x06), tickUpper) // [0x23, 0x26)
mstore(add(fmp, 0x03), tickLower) // [0x20, 0x23)
mstore(fmp, owner) // [0x0c, 0x20)
positionKey := keccak256(add(fmp, 0x0c), 0x3a) // len is 58 bytes
// now clean the memory we used
mstore(add(fmp, 0x40), 0) // fmp+0x40 held salt
mstore(add(fmp, 0x20), 0) // fmp+0x20 held tickLower, tickUpper, salt
mstore(fmp, 0) // fmp held owner
}
}
/// @notice Credits accumulated fees to a user's position
/// @param self The individual position to update
/// @param liquidityDelta The change in pool liquidity as a result of the position update
/// @param feeGrowthInside0X128 The all-time fee growth in currency0, per unit of liquidity, inside the position's tick boundaries
/// @param feeGrowthInside1X128 The all-time fee growth in currency1, per unit of liquidity, inside the position's tick boundaries
/// @return feesOwed0 The amount of currency0 owed to the position owner
/// @return feesOwed1 The amount of currency1 owed to the position owner
function update(
State storage self,
int128 liquidityDelta,
uint256 feeGrowthInside0X128,
uint256 feeGrowthInside1X128
) internal returns (uint256 feesOwed0, uint256 feesOwed1) {
uint128 liquidity = self.liquidity;
if (liquidityDelta == 0) {
// disallow pokes for 0 liquidity positions
if (liquidity == 0) CannotUpdateEmptyPosition.selector.revertWith();
} else {
self.liquidity = LiquidityMath.addDelta(liquidity, liquidityDelta);
}
// calculate accumulated fees. overflow in the subtraction of fee growth is expected
unchecked {
feesOwed0 =
FullMath.mulDiv(feeGrowthInside0X128 - self.feeGrowthInside0LastX128, liquidity, FixedPoint128.Q128);
feesOwed1 =
FullMath.mulDiv(feeGrowthInside1X128 - self.feeGrowthInside1LastX128, liquidity, FixedPoint128.Q128);
}
// update the position
self.feeGrowthInside0LastX128 = feeGrowthInside0X128;
self.feeGrowthInside1LastX128 = feeGrowthInside1X128;
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @title Action Constants
/// @notice Common constants used in actions
/// @dev Constants are gas efficient alternatives to their literal values
library ActionConstants {
/// @notice used to signal that an action should use the input value of the open delta on the pool manager
/// or of the balance that the contract holds
uint128 internal constant OPEN_DELTA = 0;
/// @notice used to signal that an action should use the contract's entire balance of a currency
/// This value is equivalent to 1<<255, i.e. a singular 1 in the most significant bit.
uint256 internal constant CONTRACT_BALANCE = 0x8000000000000000000000000000000000000000000000000000000000000000;
/// @notice used to signal that the recipient of an action should be the msgSender
address internal constant MSG_SENDER = address(1);
/// @notice used to signal that the recipient of an action should be the address(this)
address internal constant ADDRESS_THIS = address(2);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/IERC1363.sol)
pragma solidity ^0.8.20;
import {IERC20} from "./IERC20.sol";
import {IERC165} from "./IERC165.sol";
/**
* @title IERC1363
* @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].
*
* Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract
* after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.
*/
interface IERC1363 is IERC20, IERC165 {
/*
* Note: the ERC-165 identifier for this interface is 0xb0202a11.
* 0xb0202a11 ===
* bytes4(keccak256('transferAndCall(address,uint256)')) ^
* bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^
* bytes4(keccak256('approveAndCall(address,uint256)')) ^
* bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
*/
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @param data Additional data with no specified format, sent in call to `spender`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/IERC165.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[ERC].
*
* 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[ERC 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: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Panic.sol)
pragma solidity ^0.8.20;
/**
* @dev Helper library for emitting standardized panic codes.
*
* ```solidity
* contract Example {
* using Panic for uint256;
*
* // Use any of the declared internal constants
* function foo() { Panic.GENERIC.panic(); }
*
* // Alternatively
* function foo() { Panic.panic(Panic.GENERIC); }
* }
* ```
*
* Follows the list from https://github.com/ethereum/solidity/blob/v0.8.24/libsolutil/ErrorCodes.h[libsolutil].
*
* _Available since v5.1._
*/
// slither-disable-next-line unused-state
library Panic {
/// @dev generic / unspecified error
uint256 internal constant GENERIC = 0x00;
/// @dev used by the assert() builtin
uint256 internal constant ASSERT = 0x01;
/// @dev arithmetic underflow or overflow
uint256 internal constant UNDER_OVERFLOW = 0x11;
/// @dev division or modulo by zero
uint256 internal constant DIVISION_BY_ZERO = 0x12;
/// @dev enum conversion error
uint256 internal constant ENUM_CONVERSION_ERROR = 0x21;
/// @dev invalid encoding in storage
uint256 internal constant STORAGE_ENCODING_ERROR = 0x22;
/// @dev empty array pop
uint256 internal constant EMPTY_ARRAY_POP = 0x31;
/// @dev array out of bounds access
uint256 internal constant ARRAY_OUT_OF_BOUNDS = 0x32;
/// @dev resource error (too large allocation or too large array)
uint256 internal constant RESOURCE_ERROR = 0x41;
/// @dev calling invalid internal function
uint256 internal constant INVALID_INTERNAL_FUNCTION = 0x51;
/// @dev Reverts with a panic code. Recommended to use with
/// the internal constants with predefined codes.
function panic(uint256 code) internal pure {
assembly ("memory-safe") {
mstore(0x00, 0x4e487b71)
mstore(0x20, code)
revert(0x1c, 0x24)
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
// Return type of the beforeSwap hook.
// Upper 128 bits is the delta in specified tokens. Lower 128 bits is delta in unspecified tokens (to match the afterSwap hook)
type BeforeSwapDelta is int256;
// Creates a BeforeSwapDelta from specified and unspecified
function toBeforeSwapDelta(int128 deltaSpecified, int128 deltaUnspecified)
pure
returns (BeforeSwapDelta beforeSwapDelta)
{
assembly ("memory-safe") {
beforeSwapDelta := or(shl(128, deltaSpecified), and(sub(shl(128, 1), 1), deltaUnspecified))
}
}
/// @notice Library for getting the specified and unspecified deltas from the BeforeSwapDelta type
library BeforeSwapDeltaLibrary {
/// @notice A BeforeSwapDelta of 0
BeforeSwapDelta public constant ZERO_DELTA = BeforeSwapDelta.wrap(0);
/// extracts int128 from the upper 128 bits of the BeforeSwapDelta
/// returned by beforeSwap
function getSpecifiedDelta(BeforeSwapDelta delta) internal pure returns (int128 deltaSpecified) {
assembly ("memory-safe") {
deltaSpecified := sar(128, delta)
}
}
/// extracts int128 from the lower 128 bits of the BeforeSwapDelta
/// returned by beforeSwap and afterSwap
function getUnspecifiedDelta(BeforeSwapDelta delta) internal pure returns (int128 deltaUnspecified) {
assembly ("memory-safe") {
deltaUnspecified := signextend(15, delta)
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {CustomRevert} from "./CustomRevert.sol";
/// @title Safe casting methods
/// @notice Contains methods for safely casting between types
library SafeCast {
using CustomRevert for bytes4;
error SafeCastOverflow();
/// @notice Cast a uint256 to a uint160, revert on overflow
/// @param x The uint256 to be downcasted
/// @return y The downcasted integer, now type uint160
function toUint160(uint256 x) internal pure returns (uint160 y) {
y = uint160(x);
if (y != x) SafeCastOverflow.selector.revertWith();
}
/// @notice Cast a uint256 to a uint128, revert on overflow
/// @param x The uint256 to be downcasted
/// @return y The downcasted integer, now type uint128
function toUint128(uint256 x) internal pure returns (uint128 y) {
y = uint128(x);
if (x != y) SafeCastOverflow.selector.revertWith();
}
/// @notice Cast a int128 to a uint128, revert on overflow or underflow
/// @param x The int128 to be casted
/// @return y The casted integer, now type uint128
function toUint128(int128 x) internal pure returns (uint128 y) {
if (x < 0) SafeCastOverflow.selector.revertWith();
y = uint128(x);
}
/// @notice Cast a int256 to a int128, revert on overflow or underflow
/// @param x The int256 to be downcasted
/// @return y The downcasted integer, now type int128
function toInt128(int256 x) internal pure returns (int128 y) {
y = int128(x);
if (y != x) SafeCastOverflow.selector.revertWith();
}
/// @notice Cast a uint256 to a int256, revert on overflow
/// @param x The uint256 to be casted
/// @return y The casted integer, now type int256
function toInt256(uint256 x) internal pure returns (int256 y) {
y = int256(x);
if (y < 0) SafeCastOverflow.selector.revertWith();
}
/// @notice Cast a uint256 to a int128, revert on overflow
/// @param x The uint256 to be downcasted
/// @return The downcasted integer, now type int128
function toInt128(uint256 x) internal pure returns (int128) {
if (x >= 1 << 127) SafeCastOverflow.selector.revertWith();
return int128(int256(x));
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";
import {PositionInfo} from "../libraries/PositionInfoLibrary.sol";
/// @title ISubscriber
/// @notice Interface that a Subscriber contract should implement to receive updates from the v4 position manager
interface ISubscriber {
/// @notice Called when a position subscribes to this subscriber contract
/// @param tokenId the token ID of the position
/// @param data additional data passed in by the caller
function notifySubscribe(uint256 tokenId, bytes memory data) external;
/// @notice Called when a position unsubscribes from the subscriber
/// @dev This call's gas is capped at `unsubscribeGasLimit` (set at deployment)
/// @dev Because of EIP-150, solidity may only allocate 63/64 of gasleft()
/// @param tokenId the token ID of the position
function notifyUnsubscribe(uint256 tokenId) external;
/// @notice Called when a position is burned
/// @param tokenId the token ID of the position
/// @param owner the current owner of the tokenId
/// @param info information about the position
/// @param liquidity the amount of liquidity decreased in the position, may be 0
/// @param feesAccrued the fees accrued by the position if liquidity was decreased
function notifyBurn(uint256 tokenId, address owner, PositionInfo info, uint256 liquidity, BalanceDelta feesAccrued)
external;
/// @notice Called when a position modifies its liquidity or collects fees
/// @param tokenId the token ID of the position
/// @param liquidityChange the change in liquidity on the underlying position
/// @param feesAccrued the fees to be collected from the position as a result of the modifyLiquidity call
/// @dev Note that feesAccrued can be artificially inflated by a malicious user
/// Pools with a single liquidity position can inflate feeGrowthGlobal (and consequently feesAccrued) by donating to themselves;
/// atomically donating and collecting fees within the same unlockCallback may further inflate feeGrowthGlobal/feesAccrued
function notifyModifyLiquidity(uint256 tokenId, int256 liquidityChange, BalanceDelta feesAccrued) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {IEIP712} from "./IEIP712.sol";
/// @title AllowanceTransfer
/// @notice Handles ERC20 token permissions through signature based allowance setting and ERC20 token transfers by checking allowed amounts
/// @dev Requires user's token approval on the Permit2 contract
interface IAllowanceTransfer is IEIP712 {
/// @notice Thrown when an allowance on a token has expired.
/// @param deadline The timestamp at which the allowed amount is no longer valid
error AllowanceExpired(uint256 deadline);
/// @notice Thrown when an allowance on a token has been depleted.
/// @param amount The maximum amount allowed
error InsufficientAllowance(uint256 amount);
/// @notice Thrown when too many nonces are invalidated.
error ExcessiveInvalidation();
/// @notice Emits an event when the owner successfully invalidates an ordered nonce.
event NonceInvalidation(
address indexed owner, address indexed token, address indexed spender, uint48 newNonce, uint48 oldNonce
);
/// @notice Emits an event when the owner successfully sets permissions on a token for the spender.
event Approval(
address indexed owner, address indexed token, address indexed spender, uint160 amount, uint48 expiration
);
/// @notice Emits an event when the owner successfully sets permissions using a permit signature on a token for the spender.
event Permit(
address indexed owner,
address indexed token,
address indexed spender,
uint160 amount,
uint48 expiration,
uint48 nonce
);
/// @notice Emits an event when the owner sets the allowance back to 0 with the lockdown function.
event Lockdown(address indexed owner, address token, address spender);
/// @notice The permit data for a token
struct PermitDetails {
// ERC20 token address
address token;
// the maximum amount allowed to spend
uint160 amount;
// timestamp at which a spender's token allowances become invalid
uint48 expiration;
// an incrementing value indexed per owner,token,and spender for each signature
uint48 nonce;
}
/// @notice The permit message signed for a single token allowance
struct PermitSingle {
// the permit data for a single token alownce
PermitDetails details;
// address permissioned on the allowed tokens
address spender;
// deadline on the permit signature
uint256 sigDeadline;
}
/// @notice The permit message signed for multiple token allowances
struct PermitBatch {
// the permit data for multiple token allowances
PermitDetails[] details;
// address permissioned on the allowed tokens
address spender;
// deadline on the permit signature
uint256 sigDeadline;
}
/// @notice The saved permissions
/// @dev This info is saved per owner, per token, per spender and all signed over in the permit message
/// @dev Setting amount to type(uint160).max sets an unlimited approval
struct PackedAllowance {
// amount allowed
uint160 amount;
// permission expiry
uint48 expiration;
// an incrementing value indexed per owner,token,and spender for each signature
uint48 nonce;
}
/// @notice A token spender pair.
struct TokenSpenderPair {
// the token the spender is approved
address token;
// the spender address
address spender;
}
/// @notice Details for a token transfer.
struct AllowanceTransferDetails {
// the owner of the token
address from;
// the recipient of the token
address to;
// the amount of the token
uint160 amount;
// the token to be transferred
address token;
}
/// @notice A mapping from owner address to token address to spender address to PackedAllowance struct, which contains details and conditions of the approval.
/// @notice The mapping is indexed in the above order see: allowance[ownerAddress][tokenAddress][spenderAddress]
/// @dev The packed slot holds the allowed amount, expiration at which the allowed amount is no longer valid, and current nonce thats updated on any signature based approvals.
function allowance(address user, address token, address spender)
external
view
returns (uint160 amount, uint48 expiration, uint48 nonce);
/// @notice Approves the spender to use up to amount of the specified token up until the expiration
/// @param token The token to approve
/// @param spender The spender address to approve
/// @param amount The approved amount of the token
/// @param expiration The timestamp at which the approval is no longer valid
/// @dev The packed allowance also holds a nonce, which will stay unchanged in approve
/// @dev Setting amount to type(uint160).max sets an unlimited approval
function approve(address token, address spender, uint160 amount, uint48 expiration) external;
/// @notice Permit a spender to a given amount of the owners token via the owner's EIP-712 signature
/// @dev May fail if the owner's nonce was invalidated in-flight by invalidateNonce
/// @param owner The owner of the tokens being approved
/// @param permitSingle Data signed over by the owner specifying the terms of approval
/// @param signature The owner's signature over the permit data
function permit(address owner, PermitSingle memory permitSingle, bytes calldata signature) external;
/// @notice Permit a spender to the signed amounts of the owners tokens via the owner's EIP-712 signature
/// @dev May fail if the owner's nonce was invalidated in-flight by invalidateNonce
/// @param owner The owner of the tokens being approved
/// @param permitBatch Data signed over by the owner specifying the terms of approval
/// @param signature The owner's signature over the permit data
function permit(address owner, PermitBatch memory permitBatch, bytes calldata signature) external;
/// @notice Transfer approved tokens from one address to another
/// @param from The address to transfer from
/// @param to The address of the recipient
/// @param amount The amount of the token to transfer
/// @param token The token address to transfer
/// @dev Requires the from address to have approved at least the desired amount
/// of tokens to msg.sender.
function transferFrom(address from, address to, uint160 amount, address token) external;
/// @notice Transfer approved tokens in a batch
/// @param transferDetails Array of owners, recipients, amounts, and tokens for the transfers
/// @dev Requires the from addresses to have approved at least the desired amount
/// of tokens to msg.sender.
function transferFrom(AllowanceTransferDetails[] calldata transferDetails) external;
/// @notice Enables performing a "lockdown" of the sender's Permit2 identity
/// by batch revoking approvals
/// @param approvals Array of approvals to revoke.
function lockdown(TokenSpenderPair[] calldata approvals) external;
/// @notice Invalidate nonces for a given (token, spender) pair
/// @param token The token to invalidate nonces for
/// @param spender The spender to invalidate nonces for
/// @param newNonce The new nonce to set. Invalidates all nonces less than it.
/// @dev Can't invalidate more than 2**16 nonces per transaction.
function invalidateNonces(address token, address spender, uint48 newNonce) external;
}// 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 ("memory-safe") {
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 ("memory-safe") {
result := div(prod0, denominator)
}
return result;
}
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0]
// Compute remainder using mulmod
uint256 remainder;
assembly ("memory-safe") {
remainder := mulmod(a, b, denominator)
}
// Subtract 256 bit number from 512 bit number
assembly ("memory-safe") {
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 ("memory-safe") {
denominator := div(denominator, twos)
}
// Divide [prod1 prod0] by the factors of two
assembly ("memory-safe") {
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 ("memory-safe") {
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 {
result = mulDiv(a, b, denominator);
if (mulmod(a, b, denominator) != 0) {
require(++result > 0);
}
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @title FixedPoint128
/// @notice A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format)
library FixedPoint128 {
uint256 internal constant Q128 = 0x100000000000000000000000000000000;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @title Math library for liquidity
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) {
assembly ("memory-safe") {
z := add(and(x, 0xffffffffffffffffffffffffffffffff), signextend(15, y))
if shr(128, z) {
// revert SafeCastOverflow()
mstore(0, 0x93dafdf1)
revert(0x1c, 0x04)
}
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC165.sol)
pragma solidity ^0.8.20;
import {IERC165} from "../utils/introspection/IERC165.sol";// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface IEIP712 {
function DOMAIN_SEPARATOR() external view returns (bytes32);
}{
"remappings": [
"@uniswap/v4-core/=lib/v4-core/",
"@uniswap/v4-periphery/=lib/v4-periphery/",
"forge-gas-snapshot/=lib/v4-core/lib/forge-gas-snapshot/src/",
"forge-std/=lib/v4-core/lib/forge-std/src/",
"solmate/=lib/v4-core/lib/solmate/",
"v4-core/=lib/v4-core/",
"v4-periphery/=lib/v4-periphery/",
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"@ensdomains/=lib/v4-core/node_modules/@ensdomains/",
"ds-test/=lib/v4-core/lib/forge-std/lib/ds-test/src/",
"erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
"halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
"hardhat/=lib/v4-core/node_modules/hardhat/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/",
"permit2/=lib/v4-periphery/lib/permit2/"
],
"optimizer": {
"enabled": true,
"runs": 200
},
"metadata": {
"useLiteralContent": false,
"bytecodeHash": "ipfs",
"appendCBOR": true
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"evmVersion": "cancun",
"viaIR": true,
"libraries": {}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"address","name":"_poolManager","type":"address"},{"internalType":"address","name":"_positionManager","type":"address"},{"internalType":"address payable","name":"_lpFeeReceiver","type":"address"},{"internalType":"address payable","name":"_collectFeeReceiver","type":"address"},{"internalType":"address","name":"_autoCollectAccount","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AlreadyUnlocked","type":"error"},{"inputs":[],"name":"CannotRescueNFTs","type":"error"},{"inputs":[],"name":"CollectFeeTooHigh","type":"error"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"owner","type":"address"}],"name":"ERC721IncorrectOwner","type":"error"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"ERC721InsufficientApproval","type":"error"},{"inputs":[{"internalType":"address","name":"approver","type":"address"}],"name":"ERC721InvalidApprover","type":"error"},{"inputs":[{"internalType":"address","name":"operator","type":"address"}],"name":"ERC721InvalidOperator","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"ERC721InvalidOwner","type":"error"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"}],"name":"ERC721InvalidReceiver","type":"error"},{"inputs":[{"internalType":"address","name":"sender","type":"address"}],"name":"ERC721InvalidSender","type":"error"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"ERC721NonexistentToken","type":"error"},{"inputs":[],"name":"ETHTransferFailed","type":"error"},{"inputs":[],"name":"EternalLock","type":"error"},{"inputs":[],"name":"HookIsBlacklisted","type":"error"},{"inputs":[],"name":"HookNotWhitelisted","type":"error"},{"inputs":[],"name":"InsufficientFlatFee","type":"error"},{"inputs":[],"name":"InsufficientLiquidity","type":"error"},{"inputs":[],"name":"InvalidAmount","type":"error"},{"inputs":[],"name":"InvalidAutoCollectAccount","type":"error"},{"inputs":[],"name":"InvalidCollectAddress","type":"error"},{"inputs":[],"name":"InvalidCollectFee","type":"error"},{"inputs":[],"name":"InvalidCollectFeeReceiver","type":"error"},{"inputs":[],"name":"InvalidFeeAmount","type":"error"},{"inputs":[],"name":"InvalidFeeRecipient","type":"error"},{"inputs":[],"name":"InvalidHookAddress","type":"error"},{"inputs":[],"name":"InvalidHookAddressFormat","type":"error"},{"inputs":[],"name":"InvalidHookBlacklist","type":"error"},{"inputs":[],"name":"InvalidHookWhitelist","type":"error"},{"inputs":[],"name":"InvalidLPFee","type":"error"},{"inputs":[],"name":"InvalidLPFeeReceiver","type":"error"},{"inputs":[],"name":"InvalidLiquidity","type":"error"},{"inputs":[],"name":"InvalidLockId","type":"error"},{"inputs":[],"name":"InvalidMigrateInContract","type":"error"},{"inputs":[],"name":"InvalidMigrator","type":"error"},{"inputs":[],"name":"InvalidNewOwner","type":"error"},{"inputs":[],"name":"InvalidPermissionMode","type":"error"},{"inputs":[],"name":"InvalidPoolManager","type":"error"},{"inputs":[],"name":"InvalidPositionManager","type":"error"},{"inputs":[],"name":"InvalidReceiver","type":"error"},{"inputs":[],"name":"InvalidRecipient","type":"error"},{"inputs":[],"name":"InvalidTokenAddress","type":"error"},{"inputs":[],"name":"InvalidTokenId","type":"error"},{"inputs":[],"name":"InvalidUCF","type":"error"},{"inputs":[],"name":"InvalidUnlockTime","type":"error"},{"inputs":[],"name":"InvalidUnlockTimeRange","type":"error"},{"inputs":[],"name":"LPFeeTooHigh","type":"error"},{"inputs":[],"name":"LockIsNFTized","type":"error"},{"inputs":[],"name":"LockNotActive","type":"error"},{"inputs":[],"name":"MigrationFailed","type":"error"},{"inputs":[],"name":"MigratorNotSet","type":"error"},{"inputs":[],"name":"NFTNotInLocker","type":"error"},{"inputs":[{"internalType":"address","name":"expected","type":"address"},{"internalType":"address","name":"actual","type":"address"}],"name":"NFTOwnerMismatch","type":"error"},{"inputs":[],"name":"NoChange","type":"error"},{"inputs":[],"name":"NoLiquidityInPosition","type":"error"},{"inputs":[],"name":"NotOwner","type":"error"},{"inputs":[],"name":"NotYetExpired","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"OwnableInvalidOwner","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"OwnableUnauthorizedAccount","type":"error"},{"inputs":[],"name":"PoolNotInitialized","type":"error"},{"inputs":[],"name":"ReentrancyGuardReentrantCall","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"inputs":[],"name":"StillLocked","type":"error"},{"inputs":[{"internalType":"string","name":"reason","type":"string"}],"name":"TransferFailed","type":"error"},{"inputs":[],"name":"TransferToZeroAddress","type":"error"},{"inputs":[],"name":"UCFCanOnlyBeDecreased","type":"error"},{"inputs":[],"name":"UnlockTimeInPast","type":"error"},{"inputs":[],"name":"ZeroLiquidity","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"approved","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"lockId","type":"uint256"},{"indexed":true,"internalType":"address","name":"newCollectAddress","type":"address"}],"name":"CollectAddressUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_lpFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_collectFee","type":"uint256"}],"name":"FeesSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_flatFee","type":"uint256"}],"name":"FlatFeeSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"hook","type":"address"},{"indexed":false,"internalType":"bool","name":"blacklisted","type":"bool"}],"name":"HookBlacklisted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"hookAddress","type":"address"},{"indexed":false,"internalType":"bool","name":"status","type":"bool"}],"name":"HookWhitelisted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"lockId","type":"uint256"}],"name":"LiquidityDecreased","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"lockId","type":"uint256"},{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"address","name":"positionManager","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":true,"internalType":"PoolId","name":"poolId","type":"bytes32"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"unlockTime","type":"uint256"}],"name":"LiquidityLocked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"lockId","type":"uint256"},{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":true,"internalType":"PoolId","name":"poolId","type":"bytes32"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"LiquidityUnlocked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"lockId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newUnlockTime","type":"uint256"}],"name":"LockExtended","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"lockId","type":"uint256"},{"indexed":true,"internalType":"address","name":"migrator","type":"address"}],"name":"LockMigrated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"lockId","type":"uint256"},{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"LockOwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"migrateIn","type":"address"}],"name":"MigrateInContractSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"migrator","type":"address"}],"name":"MigratorSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"enum IUniversalLockerV2.PermissionMode","name":"newMode","type":"uint8"}],"name":"PermissionModeChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"bool","name":"status","type":"bool"}],"name":"WhitelistedForFreeLock","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"_lockId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_ucf","type":"uint256"}],"name":"onSetUCF","type":"event"},{"inputs":[],"name":"AUTO_COLLECT_ACCOUNT","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ETERNAL_LOCK","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"FEE_ADDR_COLLECT","outputs":[{"internalType":"address payable","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"FEE_ADDR_LP","outputs":[{"internalType":"address payable","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"FEE_DENOMINATOR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MIGRATOR","outputs":[{"internalType":"contract IMigrateNFT","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"NATIVE_ETH","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address payable","name":"receiver","type":"address"}],"name":"adminRescueETH","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"adminRescueTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"approve","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"baseExtension","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"baseURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"blacklistedHooks","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"lockId","type":"uint256"},{"internalType":"address","name":"recipient","type":"address"}],"name":"collect","outputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"},{"internalType":"uint256","name":"fee0","type":"uint256"},{"internalType":"uint256","name":"fee1","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"collectFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"lockId","type":"uint256"},{"internalType":"uint128","name":"liquidityDecrease","type":"uint128"},{"internalType":"uint256","name":"amount0Min","type":"uint256"},{"internalType":"uint256","name":"amount1Min","type":"uint256"}],"name":"decreaseLiquidity","outputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"flatFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getApproved","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"lockId","type":"uint256"}],"name":"getLockInfo","outputs":[{"components":[{"internalType":"uint256","name":"lockId","type":"uint256"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"components":[{"internalType":"Currency","name":"currency0","type":"address"},{"internalType":"Currency","name":"currency1","type":"address"},{"internalType":"uint24","name":"fee","type":"uint24"},{"internalType":"int24","name":"tickSpacing","type":"int24"},{"internalType":"contract IHooks","name":"hooks","type":"address"}],"internalType":"struct PoolKey","name":"poolKey","type":"tuple"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"unlockTime","type":"uint256"},{"internalType":"address","name":"collectAddress","type":"address"},{"internalType":"bool","name":"isNFTized","type":"bool"},{"internalType":"uint256","name":"ucf","type":"uint256"}],"internalType":"struct IUniversalLockerV2.LockInfo","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getUserLockAt","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"getUserLockCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"lockId","type":"uint256"}],"name":"isLocked","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"oldLockId","type":"uint256"},{"internalType":"address","name":"oldLocker","type":"address"}],"name":"lockFromMigration","outputs":[{"internalType":"uint256","name":"lockId","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"unlockTime","type":"uint256"},{"internalType":"bool","name":"mintLockNFT","type":"bool"}],"name":"lockNFTPosition","outputs":[{"internalType":"uint256","name":"lockId","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"locks","outputs":[{"internalType":"uint256","name":"lockId","type":"uint256"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"components":[{"internalType":"Currency","name":"currency0","type":"address"},{"internalType":"Currency","name":"currency1","type":"address"},{"internalType":"uint24","name":"fee","type":"uint24"},{"internalType":"int24","name":"tickSpacing","type":"int24"},{"internalType":"contract IHooks","name":"hooks","type":"address"}],"internalType":"struct PoolKey","name":"poolKey","type":"tuple"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"unlockTime","type":"uint256"},{"internalType":"address","name":"collectAddress","type":"address"},{"internalType":"bool","name":"isNFTized","type":"bool"},{"internalType":"uint256","name":"ucf","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lpFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"lockId","type":"uint256"}],"name":"migrate","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"onERC721Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"ownerOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"permissionMode","outputs":[{"internalType":"enum IUniversalLockerV2.PermissionMode","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"poolManager","outputs":[{"internalType":"contract IPoolManager","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"positionManager","outputs":[{"internalType":"contract IPositionManager","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"lockId","type":"uint256"},{"internalType":"uint256","name":"newUnlockTime","type":"uint256"}],"name":"relock","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"_newBaseExtension","type":"string"}],"name":"setBaseExtension","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"_newBaseURI","type":"string"}],"name":"setBaseURI","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"lockId","type":"uint256"},{"internalType":"address","name":"newCollectAddress","type":"address"}],"name":"setCollectAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address payable","name":"_lpFeeReceiver","type":"address"},{"internalType":"address payable","name":"_collectFeeReceiver","type":"address"},{"internalType":"address","name":"_autoCollectAccount","type":"address"}],"name":"setFeeAddresses","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_lpFee","type":"uint256"},{"internalType":"uint256","name":"_collectFee","type":"uint256"}],"name":"setFees","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_flatFee","type":"uint256"}],"name":"setFlatFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"hook","type":"address"},{"internalType":"bool","name":"blacklisted","type":"bool"}],"name":"setHookBlacklist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"hookAddress","type":"address"},{"internalType":"bool","name":"status","type":"bool"}],"name":"setHookWhitelist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_migrator","type":"address"}],"name":"setMigrator","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"enum IUniversalLockerV2.PermissionMode","name":"_mode","type":"uint8"}],"name":"setPermissionMode","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_lockId","type":"uint256"},{"internalType":"uint256","name":"_ucf","type":"uint256"}],"name":"setUCF","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"bool","name":"status","type":"bool"}],"name":"setWhitelistForFreeLock","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"tokenURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"transferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"lockId","type":"uint256"},{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferLockOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"lockId","type":"uint256"}],"name":"unlockLiquidity","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"expectedOwner","type":"address"}],"name":"verifyNFTOwnership","outputs":[],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"whitelistedForFreeLock","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"whitelistedHooks","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"stateMutability":"payable","type":"receive"}]Contract Creation Code
60c0604052346104e35761555e60a0813803918261001c816104e7565b9384928339810103126104e3576100328161050c565b9061003f6020820161050c565b9061004c6040820161050c565b610064608061005d6060850161050c565b930161050c565b9361006f60406104e7565b600c81526b554e4358205634204c6f636b60a01b602082015261009260406104e7565b600c81526b554e43582d56342d4c4f434b60a01b6020820152815190916001600160401b0382116104145781906100c95f54610520565b601f8111610496575b50602090601f8311600114610433575f92610428575b50508160011b915f199060031b1c1916175f555b8051906001600160401b03821161041457819061011a600154610520565b601f81116103bb575b50602090601f8311600114610355575f9261034a575b50508160011b915f199060031b1c1916176001555b33156103375760068054336001600160a01b0319821681179092556001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e05f80a360016007556032600f5560c860105567016345785d8a00006011556101bc601654610520565b601f81116102f9575b50600a64173539b7b760d91b016016556001600160a01b03169283156102ea576001600160a01b03169081156102db576001600160a01b03169182156102cc576001600160a01b03169283156102bd5760805260a05260018060a01b0319600c541617600c5560018060a01b0319600d541617600d5560018060a01b031660018060a01b0319600e541617600e5560ff1960125416601255604051614fef908161056f82396080518181816104940152610e63015260a05181818161037e01528181610d1001528181611bca0152818161261c015281816127f901528181612e4501528181612ee50152818161339a01526139a90152f35b633621ffa560e11b5f5260045ffd5b630b670b9760e21b5f5260045ffd5b63ed5f09f160e01b5f5260045ffd5b63bc12814760e01b5f5260045ffd5b60165f5261033190601f0160051c7fd833147d7dc355ba459fc788f669e58cfaf9dc25ddcd0702e87d69c7b512428990810190610558565b5f6101c5565b631e4fbdf760e01b5f525f60045260245ffd5b015190505f80610139565b60015f9081528281209350601f198516905b8181106103a3575090846001959493921061038b575b505050811b0160015561014e565b01515f1960f88460031b161c191690555f808061037d565b92936020600181928786015181550195019301610367565b60015f52610404907fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6601f850160051c8101916020861061040a575b601f0160051c0190610558565b5f610123565b90915081906103f7565b634e487b7160e01b5f52604160045260245ffd5b015190505f806100e8565b5f8080528281209350601f198516905b81811061047e5750908460019594939210610466575b505050811b015f556100fc565b01515f1960f88460031b161c191690555f8080610459565b92936020600181928786015181550195019301610443565b5f80526104dd907f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563601f850160051c8101916020861061040a57601f0160051c0190610558565b5f6100d2565b5f80fd5b6040519190601f01601f191682016001600160401b0381118382101761041457604052565b51906001600160a01b03821682036104e357565b90600182811c9216801561054e575b602083101461053a57565b634e487b7160e01b5f52602260045260245ffd5b91607f169161052f565b818110610563575050565b5f815560010161055856fe608080604052600436101561001c575b50361561001a575f80fd5b005b5f905f3560e01c908163011e116714613f015750806301ffc9a714613e94578063066b58c714613e6c57806306fdde0314613da5578063081812fc14613d69578063095ea7b314613c7f5780630ae300bf14613c575780630b78f9c014613bd7578063150b7a0214613b685780631c76046e146137305780631f113fc31461370757806322758802146136c857806323b872dd146136b057806323cf31181461367057806323fa495a1461362257806342842e0e146135f8578063454b06081461332457806355f804b3146131da5780635a04fb691461308a5780636352211e146130595780636c0360eb1461303d5780636d3b96c314612ffe578063704ce43e14612fe057806370a0823114612f8d578063715018a614612f3057806375eb8e6914612f14578063791b98bc14612ecf5780637dccbb9914612e84578063879905a114612e145780638d3c100a1461277b5780638da5cb5b146127525780638e5f59771461251857806393ac8305146124c557806395d89b411461241e57806396e8392414611b655780639b7d02ad14611b2c5780639caf4f0b14611a925780639ecd747214611a69578063a22cb465146119c5578063aa1ef5981461190b578063aa67bf3a14611860578063b2fb30cb146117a3578063b707a288146116f1578063b88d4fde1461168e578063c45d7c56146115ec578063c668286214611530578063c87b56dd1461127d578063c9102afd1461110d578063ce79eb6014611049578063d4d5d32a1461102b578063d73792a91461100e578063d9eb594714610ff0578063da3ef23f14610e92578063dc4c90d314610e4d578063e4877d3f14610e0e578063e985e9c514610db6578063eb3a79ed14610cd7578063ef24894414610c68578063f0cf6c9614610c3e578063f2fde38b14610bb5578063f4dadc6114610b0a578063f62f5a23146103235763f6aacfb10361000f573461032057602036600319011261032057604060209160043581526008835220600681015415159081610312575b506040519015158152f35b60079150015442105f610307565b80fd5b50606036600319011261032057604435600435811515602435818403610b065761034b6149ab565b338552601760205260ff60408620541615610aed575b42811115610ade576402540be40081101580610ad3575b610ac4577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031691823b15610ac057604051632142170760e11b8152336004820152306024820152604481018590528690818160648183895af1801561091157610aab575b5050604051637ba03aad60e01b8152600481018590529560c087602481875afa968715610a9e578197610a6c575b50604051631efeed3360e01b81526004810186905291602083602481885afa928315610911578293610a4b575b506001600160801b0383168015610a3c5760a0892060405160208101918252600660408201526040815261047460608261401f565b519020604051631e2eaeaf60e01b815260048101919091526020816024817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa908115610a315784916109fb575b506001600160a01b0316156109ec5760808901516001600160a01b031680610960575b50600f5480151580610949575b6107aa575b5050600b549661051088614317565b600b5561079b575b8760806001600160801b036040519561053087613fe9565b898752876020880152846040880152169485606082015201526009601054886040519361055c85613fb9565b81855260208501338152604086018b81528d6060880190815260808801918a835260a08901938c855260c08a019633885260e08b019687526101008b019889528b52600860205260408b2099518a5560018060a01b0390511660018a019060018060a01b03166001600160601b0360a01b8254161790555160028901555160018060a01b03815116600389019060018060a01b03166001600160601b0360a01b8254161790556004880160018060a01b0360018060a01b03602084015116166001600160601b0360a01b82541617815560408201518154606084015160b81b62ffffff60b81b169162ffffff60a01b9060a01b169065ffffffffffff60a01b191617179055608060018060a01b0391015116600588019060018060a01b03166001600160601b0360a01b825416179055516006870155516007860155600885019160018060a01b039060018060a01b03905116166001600160601b0360a01b83541617825551151581549060ff60a01b9060a01b169060ff60a01b191617905551910155338152600a6020526106f58660408320614e25565b50338152601760205260ff6040822054161580610792575b610762575b5060a060209620936040519384528684015260408301526060820152827f49def1ccceea7771ce91254bcad08254733e55bec4be0b3b47a01b7f2cb53b0060803393a46001600755604051908152f35b8080808060018060a01b03600c541634905af161077d6145c6565b50610712575b63b12d13eb60e01b8152600490fd5b5034151561070d565b6107a587336147fb565b610518565b610863929450816107cf6127106107c76108139461085e966145f5565b048092614608565b506107d8614ad3565b604051918a6020840152604083015285606083015285608083015260a0808301528560c083015260c0825261080e60e08361401f565b614b6f565b60018060a01b038a51169060018060a01b0360208c01511660018060a01b03600c541690604051936020850152604084015260608301526060825261085960808361401f565b614c7a565b614d77565b603c42019081421161093557853b156109315760405163dd46508f60e01b8152918391839182916108989190600484016145aa565b038183895af180156109115790829161091c575b5050604051631efeed3360e01b815260048101869052602081602481885afa9081156109115782916108e2575b50915f80610501565b610904915060203d60201161090a575b6108fc818361401f565b81019061458b565b5f6108d9565b503d6108f2565b6040513d84823e3d90fd5b816109269161401f565b61032057805f6108ac565b8280fd5b634e487b7160e01b83526011600452602483fd5b50338452601760205260ff604085205416156104fc565b60ff6012541660038110156109d857600281036109a257508352600960205260ff60408420541615610993575b5f6104ef565b632812ca3b60e21b8352600483fd5b6001146109b0575b5061098d565b8352601360205260ff6040842054166109c9575f6109aa565b6308ed3ca360e01b8352600483fd5b634e487b7160e01b85526021600452602485fd5b63486aa30760e01b8352600483fd5b90506020813d602011610a29575b81610a166020938361401f565b81010312610a2557515f6104cc565b8380fd5b3d9150610a09565b6040513d86823e3d90fd5b6378b8b76160e01b8352600483fd5b610a6591935060203d60201161090a576108fc818361401f565b915f61043f565b610a8f91975060c03d60c011610a97575b610a87818361401f565b81019061456d565b50955f610412565b503d610a7d565b50604051903d90823e3d90fd5b81610ab59161401f565b610ac057855f6103e4565b8580fd5b6352aba6d360e11b8552600485fd5b505f19811415610378565b63ae130dfb60e01b8552600485fd5b601154341015610361576340b7d5ed60e11b8552600485fd5b8480fd5b50346103205760203660031901126103205760406101a091600435815260086020522080549060ff60018060a01b03600183015416916002810154610b5160038301614224565b610b856006840154916007850154936009600887015496015497604051998a5260208a0152604089015260608801906141ba565b6101008601526101208501526001600160a01b03811661014085015260a01c161515610160830152610180820152f35b503461032057602036600319011261032057610bcf613f3d565b610bd76147d4565b6001600160a01b03168015610c2a57600680546001600160a01b0319811683179091556001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08380a380f35b631e4fbdf760e01b82526004829052602482fd5b5034610320578060031936011261032057610c6460ff60125416604051918291826141fd565b0390f35b503461032057610c7736613f69565b610c7f6147d4565b8183526008602052600960408420018054821015610cc857817fa4b63b21571e7c2b944a681b0a39cda220f85f67aaa7aa4d23fcf7d31e2379a39260209255604051908152a280f35b630927c5af60e41b8452600484fd5b503461032057604036600319011261032057610cf1613f53565b6040516331a9108f60e11b8152600480359082015291906020836024817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa928315610911578293610d76575b506001600160a01b039081169216828103610d61575080f35b604492634877b8df60e01b8352600452602452fd5b9092506020813d602011610dae575b81610d926020938361401f565b81010312610daa57610da390614277565b915f610d48565b5080fd5b3d9150610d85565b5034610320576040366003190112610320576040610dd2613f3d565b91610ddb613f53565b9260018060a01b031681526005602052209060018060a01b03165f52602052602060ff60405f2054166040519015158152f35b50346103205760203660031901126103205760209060ff906040906001600160a01b03610e39613f3d565b168152601784522054166040519015158152f35b50346103205780600319360112610320576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b503461032057610ea136614091565b90610eaa6147d4565b81516001600160401b038111610fdc57610ec56016546140cf565b601f8111610f74575b50602092601f8211600114610f0a57928293829392610eff575b50508160011b915f199060031b1c19161760165580f35b015190505f80610ee8565b60168352601f198216935f80516020614f9a83398151915291845b868110610f5c5750836001959610610f44575b505050811b0160165580f35b01515f1960f88460031b161c191690555f8080610f38565b91926020600181928685015181550194019201610f25565b60168352601f820160051c5f80516020614f9a833981519152019060208310610fc7575b601f0160051c5f80516020614f9a83398151915201905b818110610fbc5750610ece565b838155600101610faf565b5f80516020614f9a8339815191529150610f98565b634e487b7160e01b82526041600452602482fd5b50346103205780600319360112610320576020601154604051908152f35b503461032057806003193601126103205760206040516127108152f35b50346103205780600319360112610320576020601054604051908152f35b503461032057604036600319011261032057611063613f3d565b61106b6141ab565b906110746147d4565b6001600160a01b03169081156110fe57818352600960205260ff6040842054169080151580921515146110ef577f5b2460eb1f1133b6714bb07afb85ae0d9c49f24afa50d9800c1cc6d789f4acc7916110e560209285875260098452604087209060ff801983541691151516179055565b604051908152a280f35b63a88ee57760e01b8452600484fd5b632a96f9e160e21b8352600483fd5b5034610320576020366003190112610320576040816101a092610100835161113481613fb9565b8281528260208201528285820152845161114d81613fe9565b838152836020820152838682015283606082015283608082015260608201528260808201528260a08201528260c08201528260e0820152015260043581526008602052206040519061119e82613fb9565b8054825260018101546001600160a01b03166020830190815260028201546040840190815290916111d160038201614224565b6060850190815260068201546080860190815261124d60078401549260a08801938452600885015495600960c08a019660018060a01b038916885260ff60e08c019960a01c16151589520154976101008a0198895260405199518a5260018060a01b0390511660208a01525160408901525160608801906141ba565b5161010086015251610120850152516001600160a01b031661014084015251151561016083015251610180820152f35b503461032057602036600319011261032057600435808252600260205260408220546001600160a01b03161561151e576112b5614107565b8051909190156115035782818072184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b8110156114dd575b50806d04ee2d6d415b85acef8100000000600a9210156114c2575b662386f26fc100008110156114ae575b6305f5e10081101561149d575b61271081101561148e575b6064811015611480575b1015611478575b6001810191600a602161136061134a86614040565b95611358604051978861401f565b808752614040565b602086019490601f19013686378501015b5f1901916f181899199a1a9b1b9c1cb0b131b232b360811b8282061a83530490811561139f57600a90611371565b505060209182604051948051918291018587015e84019083820190868252519283915e010182815260165490836113d5836140cf565b926001811690811561145b5750600114611417575b50505061140381610c649303601f19810183528261401f565b604051918291602083526020830190613f19565b90919350601681525f80516020614f9a8339815191525b84821061144757505081610c64936114039201936113ea565b60018160209254848601520191019061142e565b60ff19168352505081151590910201915061140381610c646113ea565b600101611335565b60646002910492019161132e565b61271060049104920191611324565b6305f5e10060089104920191611319565b662386f26fc100006010910492019161130c565b6d04ee2d6d415b85acef8100000000602091049201916112fc565b6040925072184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b90049050600a6112e1565b5050604051610c649161151760208361401f565b8152611403565b637e27328960e01b8252600452602490fd5b5034610320578060031936011261032057604051908060165490611553826140cf565b80855291600181169081156115c5575060011461157b575b610c64846114038186038261401f565b601681525f80516020614f9a833981519152939250905b8082106115ab575090915081016020016114038261156b565b919260018160209254838588010152019101909291611592565b60ff191660208087019190915292151560051b85019092019250611403915083905061156b565b5034610320576020366003190112610320576004356003811015610daa576116126147d4565b60125460ff8116600381101561167a57821461166b5760ff191660ff8216176012556040517fd2e6f9601313cfd1c3bd69d8a281aed29a764c8a456a0ac3fe12a4767608c16891819061166590826141fd565b0390a180f35b63a88ee57760e01b8352600483fd5b634e487b7160e01b84526021600452602484fd5b5034610320576080366003190112610320576116a8613f3d565b6116b0613f53565b606435916001600160401b038311610a255736602384011215610a25576116e46116ee93369060248160040135910161405b565b9160443591614687565b80f35b50346103205760403660031901126103205760043561170e613f53565b6117166149ab565b6001600160a01b03169081156117945780835260086020526040832060018101546001600160a01b031633036117855760080180546001600160a01b031916831790557f570a1ee460fe39844fcfa359db528b53324ce4c22fa7080d3834db0a6349ed808380a3600160075580f35b6330cd747160e01b8452600484fd5b635447822f60e01b8352600483fd5b5034610320576117b236613f69565b6117ba6149ab565b81835260086020526040832060018101546001600160a01b031633036117855742821115611851576007018054821115611837576402540be40082101580611846575b61183757817f4e4187a5cfd31a235276a431f3c394962d1b05cc4da52f6fa4e5460a5808ee219260209255604051908152a2600160075580f35b6352aba6d360e11b8452600484fd5b505f198214156117fd565b63ae130dfb60e01b8452600484fd5b50346103205760403660031901126103205761187a613f3d565b6118826141ab565b9061188b6147d4565b6001600160a01b03169081156110fe57818352601360205260ff6040842054169080151580921515146110ef57916040916118fd7f4cc0d8bbc18f4db77c5226d5370b9a94a5e93e3cf2671017043e55c190be6d6d9483875260136020528487209060ff801983541691151516179055565b82519182526020820152a180f35b503461032057606036600319011261032057611925613f3d565b61192d613f53565b6044356001600160a01b0381169290839003610a255761194b6147d4565b6001600160a01b03169081156119b6576001600160a01b03169081156119a7576001600160601b0360a01b600c541617600c556001600160601b0360a01b600d541617600d556001600160601b0360a01b600e541617600e5580f35b633621ffa560e11b8452600484fd5b630b670b9760e21b8452600484fd5b5034610320576040366003190112610320576119df613f3d565b6119e76141ab565b6001600160a01b03909116908115611a5557338352600560205260408320825f52602052611a248160405f209060ff801983541691151516179055565b60405190151581527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c3160203392a380f35b630b61174360e31b83526004829052602483fd5b50346103205780600319360112610320576014546040516001600160a01b039091168152602090f35b503461032057604036600319011261032057611aac613f3d565b611ab46141ab565b90611abd6147d4565b6001600160a01b0316908115611b1d5760207fee6dc5e65d61241c43ff3037dcd8a7857d0780c354fac7a12f99285a476cf9ed9183855260178252611b1181604087209060ff801983541691151516179055565b6040519015158152a280f35b630f58058360e11b8352600483fd5b5034610320576020366003190112610320576020906040906001600160a01b03611b54613f3d565b168152600a83522054604051908152f35b503461032057602036600319011261032057600435611b826149ab565b80825260086020526040822060018101546001600160a01b0316338103611785576007820154421061240f576006820180548015612400576002840154938660018060a01b037f00000000000000000000000000000000000000000000000000000000000000001693604051637ba03aad60e01b815287600482015260c081602481895afa9081156123f55783916123d5575b50604051631efeed3360e01b8152600481018990526020816024818a5afa8015610a31576001600160801b039185916123b6575b5016611f1c575b5055838752600a602052611c678660408920614e94565b5060ff600882015460a01c16611e17575b823b15611e13576040516323b872dd60e01b81523060048201526001600160a01b03851660248201526044810186905287808260648183895af19182611dfa575b5050611d6257868060033d11611d51575b506308c379a014611d15575b6040516312dfddb360e01b81526020600482015260166024820152752ab735b737bbb7103a3930b739b332b91032b93937b960511b6044820152606490fd5b611d1d614615565b80611d285750611cd6565b6040516312dfddb360e01b815260206004820152908190611d4d906024830190613f19565b0390fd5b9050600481803e5160e01c81611cca565b85927fba4a3f8e2e6613ba4f7a58a5f3afbe56fdaae5ed213275b0d9bec44761f6cb059260a0611d96600360609501614224565b209660405192835260208301526040820152a481526008602052611df26040822060095f918281558260018201558260028201558260038201558260048201558260058201558260068201558260078201558260088201550155565b600160075580f35b81611e049161401f565b611e0f57875f611cb9565b8780fd5b8680fd5b858752600260205260408720546001600160a01b0316801590811580611ee9575b888a52600260205260408a2080546001600160a01b0319169055888a837fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8280a4888a52600860205260ff600860408c20015460a01c16611ec3575b508881895f80516020614f7a8339815191528380a45015611c7857637e27328960e01b87526004869052602487fd5b611ece575b5f611e94565b808952600a602052611ee38860408b20614e94565b50611ec8565b5f89815260046020526040902080546001600160a01b0319169055818a52600360205260408a2080545f19019055611e38565b909150843b156123b25760405163095ea7b360e01b81526001600160a01b03861660048201526024810188905289908181604481838b5af180156109115761239d575b5050611fb2611f6c614ad3565b6040519061080e82611fa48c6020830160c09181525f60208201525f60408201525f606082015260a060808201525f60a08201520190565b03601f19810184528361401f565b815160208084018051604080516001600160a01b0395861694810194909452931692820192909252306060820152909291611ff89161085e916108598260808101611fa4565b603c42019081421161238957908b94939291883b15610ac05760405163dd46508f60e01b8152918691839182916120339190600484016145aa565b0381838c5af190811561237e578591612369575b50505190516001600160a01b039081169116878215821580156122f15747935b8491831561227657475b809660098c0154908161213b575b505050826120e3575b50505082612099575b505050611c50565b929492156120d45782939450829182915af16120b36145c6565b50156120c55787905b5f808781612091565b63b12d13eb60e01b8852600488fd5b6120de92946149cb565b6120bc565b97939192949596975f14612125575082809281925af16121016145c6565b50156121165790878b9493925b5f8080612088565b63b12d13eb60e01b8b5260048bfd5b9181612136929498979695936149cb565b61210e565b61216298508192955061216b6127108061215861217195856145f5565b049a8b95896145f5565b04938492614608565b95614608565b96806121fd575b5080612186575b808061207f565b909294849697989992945f146121d95750600d54829182918291906001600160a01b03165af16121b46145c6565b50156121ca57918d96959493918b935b5f61217f565b63b12d13eb60e01b8e5260048efd5b9492906121f89060018060a09c9b9a9997959c1b03600d5416896149cb565b6121c4565b90929496979899919395845f146122525750600d54829182918291906001600160a01b03165af161222c6145c6565b501561224357918b93918f98979695935b5f612178565b63b12d13eb60e01b8f5260048ffd5b959391999897969492906122719060018060a01b03600d5416856149cb565b61223d565b6040516370a0823160e01b815230600482015294506020856024818a5afa80156122e6578d958a916122a9575b50612071565b95505097506020843d6020116122de575b816122c76020938361401f565b810103126122da578e978c94515f6122a3565b5f80fd5b3d91506122ba565b6040513d8b823e3d90fd5b6040516370a0823160e01b81523060048201529250602083602481875afa801561235e578b938891612325575b5093612067565b93505095506020823d602011612356575b816123436020938361401f565b810103126122da578c958a92515f61231e565b3d9150612336565b6040513d89823e3d90fd5b816123739161401f565b610a2557835f612047565b6040513d87823e3d90fd5b634e487b7160e01b8c52601160045260248cfd5b816123a79161401f565b6123b257885f611f5f565b8880fd5b6123cf915060203d60201161090a576108fc818361401f565b5f611c49565b6123ee915060c03d60c011610a9757610a87818361401f565b505f611c15565b6040513d85823e3d90fd5b6328486b6360e11b8652600486fd5b636100d92960e11b8452600484fd5b5034610320578060031936011261032057604051908060015490612441826140cf565b80855291600181169081156115c5575060011461246857610c64846114038186038261401f565b600181527fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6939250905b8082106124ab575090915081016020016114038261156b565b919260018160209254838588010152019101909291612492565b503461032057604036600319011261032057808080806124e3613f53565b6124eb6147d4565b6124f36149ab565b600435906001600160a01b03165af161250a6145c6565b501561078357600160075580f35b503461032057608036600319011261032057600435602435916001600160801b0383168093036103205761254a6149ab565b81815260086020526040812060018101546001600160a01b031633036127435760078101545f19811461273157421115612722578315612713576006810190815485116127045761261a906125e06125a0614ad3565b6002830154906040519160208301528860408301526044356060830152606435608083015260a0808301528660c083015260c0825261080e60e08361401f565b6003820154600490920154604080516001600160a01b03948516602082015293909116908301523360608301526108598260808101611fa4565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169061264e90614d77565b90603c4201918242116126f057813b15610b0657918491612686938360405180968195829463dd46508f60e01b8452600484016145aa565b03925af180156123f5576126db575b506126a36040948254614608565b90558251917f64d0c470254fcda065fe0e66b5395405b2b6f2997de63b73f166031c81c4bdbb8280a260016007558082526020820152f35b6126e683809261401f565b610daa575f612695565b634e487b7160e01b85526011600452602485fd5b63bb55fd2760e01b8352600483fd5b630200e8a960e31b8252600482fd5b632cc8960360e11b8252600482fd5b600162f96b2f60e01b03198352600483fd5b6330cd747160e01b8252600482fd5b50346103205780600319360112610320576006546040516001600160a01b039091168152602090f35b503461032057604036600319011261032057612795613f53565b9061279e6149ab565b808081908260043581526008602052604081209560018060a01b0360018801541633141580612dff575b612743576001600160a01b03811615612df057600287018054604051637ba03aad60e01b81526004810182905290987f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169290919060c082602481875afa918215612de5578692612dc3575b50604051631efeed3360e01b8152600481018c9052602081602481885afa90811561235e57906001600160801b03918891612da4575b501661289b575b60808a8a8a8a6001600755604051938452602084015260408301526060820152f35b92859a9194979899508096509491943b15610daa5760405163095ea7b360e01b81526001600160a01b038716600482015260248101919091528181604481838a5af1801561091157612d8f575b5050611fa46129309161080e6128fc614ad3565b91546040519384916020830160c09181525f60208201525f60408201525f606082015260a060808201525f60a08201520190565b815160208084018051604080516001600160a01b03958616948101949094529316928201929092523060608201529094916129769161085e916108598260808101611fa4565b603c4201804211612d7b579082918a933b15610a25576129af9284928360405180968195829463dd46508f60e01b8452600484016145aa565b03925af1801561091157612d66575b50505191516001600160a01b0392831680159693909116928315928715612cf85747965b878515612c8a5747935b849260098501938d855415155f14612bdc575050505050918796959391612a3f612a3761271080612a24612a2e9e9a9854809d6145f5565b049c8d9b866145f5565b049b8c9b614608565b9a8b93614608565b9660018060a01b03600e541633145f14612bc7578b8a825b8b612b74575b81612b39575b5050600e546001600160a01b03163314159050612b305750600801546001600160a01b03169485905b82612afb575b5050505083612aaf575b505050608094505b5f8080808080612879565b15612ae757508580808481945af1612ac56145c6565b5015612ad857608094505b5f8080612a9c565b63b12d13eb60e01b8552600485fd5b60809650612af69183916149cb565b612ad0565b15612b22578a809350809281925af1612b126145c6565b50156120c5575b5f878482612a92565b612b2b926149cb565b612b19565b90508095612a8c565b8715612b64578293949550829182915af1612b526145c6565b5015612116579089915b8b8a5f612a63565b612b6f9250886149cb565b612b5c565b9293949190895f14612bb2575080808093508c855af1612b926145c6565b5015612ba357908b8a8c9493612a5d565b63b12d13eb60e01b8c5260048cfd5b9091949392612bc28c82896149cb565b612a5d565b600d548c908b906001600160a01b0316612a57565b9450989597945098958a929b87929b612c46575b505050505083612c08575b5050505060809450612aa4565b15612c3257508680809381935af1612c1e6145c6565b5015612ad857608094505b5f808080612bfb565b6080975090612c4192916149cb565b612c29565b15612c7b575082809281925af1612c5b6145c6565b5015612c6c575b885f848180612bf0565b63b12d13eb60e01b8952600489fd5b612c8593506149cb565b612c62565b6040516370a0823160e01b81523060048201526020816024818b5afa908115612ced578c91612cbb575b50936129ec565b90506020813d602011612ce5575b81612cd66020938361401f565b810103126122da57515f612cb4565b3d9150612cc9565b6040513d8e823e3d90fd5b6040516370a0823160e01b8152306004820152602081602481875afa908115612d5b578a91612d29575b50966129e2565b90506020813d602011612d53575b81612d446020938361401f565b810103126122da57515f612d22565b3d9150612d37565b6040513d8c823e3d90fd5b81612d709161401f565b611e1357865f6129be565b634e487b7160e01b8a52601160045260248afd5b81612d999161401f565b611e0f57875f6128e8565b612dbd915060203d60201161090a576108fc818361401f565b5f612872565b612ddd91925060c03d60c011610a9757610a87818361401f565b50905f61283c565b6040513d88823e3d90fd5b634e46966960e11b8252600482fd5b50600e546001600160a01b03163314156127c8565b503461032057612e2336613f7f565b909291612e2e6147d4565b612e366149ab565b6001600160a01b0390811693907f0000000000000000000000000000000000000000000000000000000000000000168414612e7557611df292936149cb565b633d8647d760e11b8352600483fd5b503461032057604036600319011261032057602090612ec0906001600160a01b03612ead613f3d565b168152600a835260406024359120614e10565b90549060031b1c604051908152f35b50346103205780600319360112610320576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b503461032057806003193601126103205760206040515f198152f35b5034610320578060031936011261032057612f496147d4565b600680546001600160a01b0319811690915581906001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a380f35b5034610320576020366003190112610320576001600160a01b03612faf613f3d565b168015612fcc578160409160209352600383522054604051908152f35b6322718ad960e21b82526004829052602482fd5b50346103205780600319360112610320576020600f54604051908152f35b50346103205760203660031901126103205760209060ff906040906001600160a01b03613029613f3d565b168152600984522054166040519015158152f35b5034610320578060031936011261032057610c64611403614107565b50346103205760203660031901126103205760206130786004356147a0565b6040516001600160a01b039091168152f35b503461032057604036600319011261032057600435906130a8613f53565b916130b16149ab565b6001600160a01b0383169283156131cb578183526008602052604083206001810180549091906001600160a01b031633036131bc576008019060ff825460a01c165f1461316b57506001600160a01b039161310e91508390614838565b16928361312957637e27328960e01b83526004829052602483fd5b919233810361314f57505b33905f80516020614f7a8339815191528480a4600160075580f35b6364283d7b60e01b845233600452602491909152604452606482fd5b909150939293338552600a6020526131868360408720614e94565b50838552600a60205261319c8360408720614e25565b5080546001600160a01b0319908116851790915581541683179055613134565b6330cd747160e01b8552600485fd5b632a52b3c360e11b8352600483fd5b5034610320576131e936614091565b906131f26147d4565b81516001600160401b038111610fdc5761320d6015546140cf565b601f81116132bc575b50602092601f821160011461325257928293829392613247575b50508160011b915f199060031b1c19161760155580f35b015190505f80613230565b60158352601f198216935f80516020614f5a83398151915291845b8681106132a4575083600195961061328c575b505050811b0160155580f35b01515f1960f88460031b161c191690555f8080613280565b9192602060018192868501518155019401920161326d565b60158352601f820160051c5f80516020614f5a83398151915201906020831061330f575b601f0160051c5f80516020614f5a83398151915201905b8181106133045750613216565b8381556001016132f7565b5f80516020614f5a83398151915291506132e0565b5060203660031901126103205760043561333c6149ab565b6014546001600160a01b031680156135e957818352600860205260408320600181018054909291906001600160a01b031633036131bc576006810154156135da5760020180546040516331a9108f60e11b81526004810182905291927f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031692602081602481875afa9081156135cf578891613595575b50306001600160a01b039091160361358657908691833b156109315760405163095ea7b360e01b81526001600160a01b039190911660048201526024810191909152818160448183875af1801561091157613571575b5050601454915460405163277c45f560e11b81526004810186905260248101929092526044820152906020908290606490829034906001600160a01b03165af1908115610a31578491613537575b501561352857546001600160a01b03168252600a602052604082206134a4908290614e94565b5080825260086020526134ef6040832060095f918281558260018201558260028201558260038201558260048201558260058201558260068201558260078201558260088201550155565b6014546001600160a01b0316907f44428b5f080165ed3e2574589b3d8fdfed8c7aeddd00fb5e847fb6034dcea7b38380a3600160075580f35b63513dfed160e11b8352600483fd5b90506020813d602011613569575b816135526020938361401f565b81010312610a25576135639061430a565b5f61347e565b3d9150613545565b8161357b9161401f565b610b0657845f613430565b63213eeaa160e21b8752600487fd5b90506020813d6020116135c7575b816135b06020938361401f565b81010312611e0f576135c190614277565b5f6133da565b3d91506135a3565b6040513d8a823e3d90fd5b6304a417d360e31b8552600485fd5b632ed9bf5360e21b8352600483fd5b5034610320576116ee61360a36613f7f565b906040519261361a60208561401f565b858452614687565b5034610320576020366003190112610320577f02e6220a8c55d7fd57319e91a44a9aac5a5fd4c64a19bb34bb83c8cedbf3f39860206004356136626147d4565b80601155604051908152a180f35b50346103205760203660031901126103205761368a613f3d565b6136926147d4565b60018060a01b03166001600160601b0360a01b601454161760145580f35b5034610320576116ee6136c236613f7f565b91614339565b50346103205760203660031901126103205760209060ff906040906001600160a01b036136f3613f3d565b168152601384522054166040519015158152f35b5034610320578060031936011261032057600d546040516001600160a01b039091168152602090f35b346122da5760403660031901126122da57613749613f53565b6014546001600160a01b03163303613b595760405163c9102afd60e01b81526004803590820152906101a090829060249082906001600160a01b03165afa908115613a7b575f91613aa4575b50600b546137a281614317565b600b5560e082018051613a86575b6020830160018060a01b0381511693604081019184600984519560608501948551996080820198895160a084019c8d519261010060018060a01b0360c0880151169601519651151594604051996138068b613fb9565b808b5260208b0191825260408b0192835260608b0193845260808b0194855260a08b0195865260c08b0197885260e08b019687526101008b019889525f52600860205260405f2099518a5560018060a01b0390511660018a019060018060a01b03166001600160601b0360a01b8254161790555160028901555160018060a01b03815116600389019060018060a01b03166001600160601b0360a01b8254161790556004880160018060a01b0360018060a01b03602084015116166001600160601b0360a01b82541617815560408201518154606084015160b81b62ffffff60b81b169162ffffff60a01b9060a01b169065ffffffffffff60a01b191617179055608060018060a01b0391015116600588019060018060a01b03166001600160601b0360a01b825416179055516006870155516007860155600885019160018060a01b039060018060a01b03905116166001600160601b0360a01b83541617825551151581549060ff60a01b9060a01b169060ff60a01b19161790555191015560018060a01b038151165f52600a6020526139a48560405f20614e25565b5082517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316803b156122da576040516323b872dd60e01b815233600482015230602482015260448101929092525f8260648183855af1938415613a7b5760209860a07f49def1ccceea7771ce91254bcad08254733e55bec4be0b3b47a01b7f2cb53b00956080958b98613a6b575b50600180831b03905116975192512097519051916040519384528a84015260408301526060820152a4604051908152f35b5f613a759161401f565b5f613a3a565b6040513d5f823e3d90fd5b6020830151613a9f9083906001600160a01b03166147fb565b6137b0565b90506101a03d8111613b52575b613abb818361401f565b8101906101a0818303126122da5761018090613b0560405193613add85613fb9565b82518552613aed60208401614277565b6020860152604083015160408601526060830161428b565b6060840152610100810151608084015261012081015160a0840152613b2d6101408201614277565b60c0840152613b3f610160820161430a565b60e0840152015161010082015281613795565b503d613ab1565b6323479f3d60e21b5f5260045ffd5b346122da5760803660031901126122da57613b81613f3d565b50613b8a613f53565b506064356001600160401b0381116122da57366023820112156122da5780600401356001600160401b0381116122da57369101602401116122da57604051630a85bd0160e11b8152602090f35b346122da57613be536613f69565b613bed6147d4565b6103e88211613c48576103e88111613c3957816040917f93525d3c7f4fafe56faedbca6d501a13c63f47857d8b30d8282ec2dd806259a793600f558060105582519182526020820152a1005b63596b468d60e01b5f5260045ffd5b632df1c0af60e01b5f5260045ffd5b346122da575f3660031901126122da57600c546040516001600160a01b039091168152602090f35b346122da5760403660031901126122da57613c98613f3d565b602435613ca4816147a0565b33151580613d56575b80613d29575b613d165781906001600160a01b0384811691167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9255f80a45f90815260046020526040902080546001600160a01b0319166001600160a01b03909216919091179055005b63a9fbf51f60e01b5f523360045260245ffd5b506001600160a01b0381165f90815260056020908152604080832033845290915290205460ff1615613cb3565b506001600160a01b038116331415613cad565b346122da5760203660031901126122da57600435613d86816147a0565b505f526004602052602060018060a01b0360405f205416604051908152f35b346122da575f3660031901126122da576040515f8054613dc4816140cf565b8084529060018116908115613e485750600114613dec575b610c64836114038185038261401f565b5f8080527f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563939250905b808210613e2e57509091508101602001611403613ddc565b919260018160209254838588010152019101909291613e16565b60ff191660208086019190915291151560051b840190910191506114039050613ddc565b346122da575f3660031901126122da57600e546040516001600160a01b039091168152602090f35b346122da5760203660031901126122da5760043563ffffffff60e01b81168091036122da576020906380ac58cd60e01b8114908115613ef0575b8115613edf57506040519015158152f35b6301ffc9a760e01b14905082610307565b635b5e139f60e01b81149150613ece565b346122da575f3660031901126122da57805f60209252f35b805180835260209291819084018484015e5f828201840152601f01601f1916010190565b600435906001600160a01b03821682036122da57565b602435906001600160a01b03821682036122da57565b60409060031901126122da576004359060243590565b60609060031901126122da576004356001600160a01b03811681036122da57906024356001600160a01b03811681036122da579060443590565b61012081019081106001600160401b03821117613fd557604052565b634e487b7160e01b5f52604160045260245ffd5b60a081019081106001600160401b03821117613fd557604052565b604081019081106001600160401b03821117613fd557604052565b90601f801991011681019081106001600160401b03821117613fd557604052565b6001600160401b038111613fd557601f01601f191660200190565b92919261406782614040565b91614075604051938461401f565b8294818452818301116122da578281602093845f960137010152565b60206003198201126122da57600435906001600160401b0382116122da57806023830112156122da578160246140cc9360040135910161405b565b90565b90600182811c921680156140fd575b60208310146140e957565b634e487b7160e01b5f52602260045260245ffd5b91607f16916140de565b604051905f826015549161411a836140cf565b808352926001811690811561418c5750600114614140575b61413e9250038361401f565b565b5060155f90815290915f80516020614f5a8339815191525b81831061417057505090602061413e92820101614132565b6020919350806001915483858901015201910190918492614158565b6020925061413e94915060ff191682840152151560051b820101614132565b6024359081151582036122da57565b80516001600160a01b03908116835260208083015182169084015260408083015162ffffff169084015260608083015160020b9084015260809182015116910152565b9190602083019260038210156142105752565b634e487b7160e01b5f52602160045260245ffd5b9060405161423181613fe9565b82546001600160a01b0390811682526001840154808216602084015260a081901c62ffffff16604084015260b81c600290810b6060840152909301549092166080830152565b51906001600160a01b03821682036122da57565b91908260a09103126122da576040516142a381613fe9565b80926142ae81614277565b82526142bc60208201614277565b6020830152604081015162ffffff811681036122da5760408301526060810151908160020b82036122da57606083019190915260800151906001600160a01b03821682036122da5760800152565b519081151582036122da57565b5f1981146143255760010190565b634e487b7160e01b5f52601160045260245ffd5b6001600160a01b039091169190821561455a575f828152600260205260409020546001600160a01b031692331515806144ca575b5083151580614497575b815f52600360205260405f2060018154019055835f52600260205260405f20826001600160601b0360a01b8254161790558382867fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef5f80a4835f52600860205260ff600860405f20015460a01c1661442b575b5083835f80516020614f7a8339815191525f80a46001600160a01b031680830361441357505050565b6364283d7b60e01b5f5260045260245260445260645ffd5b61447c575b805f52600a6020526144458360405f20614e25565b505f83815260086020819052604082206001810180546001600160a01b0319908116861790915591018054909116831790556143ea565b835f52600a6020526144918360405f20614e94565b50614430565b5f84815260046020526040902080546001600160a01b0319169055845f52600360205260405f205f198154019055614377565b80614509575b156144db575f61436d565b82846144f357637e27328960e01b5f5260045260245ffd5b63177e802f60e01b5f523360045260245260445ffd5b503384148015614538575b806144d057505f838152600460205260409020546001600160a01b031633146144d0565b505f84815260056020908152604080832033845290915290205460ff16614514565b633250574960e11b5f525f60045260245ffd5b919060c0838203126122da5761458560a0918461428b565b92015190565b908160209103126122da57516001600160801b03811681036122da5790565b9291906145c1602091604086526040860190613f19565b930152565b3d156145f0573d906145d782614040565b916145e5604051938461401f565b82523d5f602084013e565b606090565b8181029291811591840414171561432557565b9190820391821161432557565b5f60443d106140cc576040513d600319016004823e8051913d60248401116001600160401b0384111761468157828201928351916001600160401b038311614679573d8401600319018584016020011161467957506140cc9291016020019061401f565b949350505050565b92915050565b9291614694818386614339565b813b6146a1575b50505050565b604051630a85bd0160e11b81523360048201526001600160a01b03948516602482015260448101919091526080606482015292169190602090829081906146ec906084830190613f19565b03815f865af15f918161475b575b5061472857506147086145c6565b805190816147235782633250574960e11b5f5260045260245ffd5b602001fd5b6001600160e01b03191663757a42ff60e11b0161474957505f80808061469b565b633250574960e11b5f5260045260245ffd5b9091506020813d602011614798575b816147776020938361401f565b810103126122da57516001600160e01b0319811681036122da57905f6146fa565b3d915061476a565b5f818152600260205260409020546001600160a01b03169081156147c2575090565b637e27328960e01b5f5260045260245ffd5b6006546001600160a01b031633036147e857565b63118cdaa760e01b5f523360045260245ffd5b906001600160a01b0382161561455a576001600160a01b039161481e9190614838565b1661482557565b6339e3563760e11b5f525f60045260245ffd5b5f828152600260205260409020546001600160a01b0316918215159183919083614978575b6001600160a01b0316928315159081614960575b825f52600260205260405f20856001600160601b0360a01b8254161790558285857fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef5f80a4825f52600860205260ff600860405f20015460a01c166148e7575b50505f80516020614f7a8339815191525f80a490565b614945575b6148f8575b5f806148d1565b825f52600a60205261490d8160405f20614e25565b505f8181526008602081905260409091206001810180546001600160a01b0319908116871790915591018054909116841790556148f1565b825f52600a60205261495a8260405f20614e94565b506148ec565b845f52600360205260405f2060018154019055614871565b5f82815260046020526040902080546001600160a01b0319169055825f52600360205260405f205f19815401905561485d565b6002600754146149bc576002600755565b633ee5aeb560e01b5f5260045ffd5b60405163a9059cbb60e01b60208083019182526001600160a01b0394909416602483015260448083019590955293815290925f91614a0a60648261401f565b519082855af115613a7b575f513d614a5157506001600160a01b0381163b155b614a315750565b635274afe760e01b5f9081526001600160a01b0391909116600452602490fd5b60011415614a2a565b60405190614a6782614004565b60606020838281520152565b6001600160401b038111613fd55760051b60200190565b90614a9482614a73565b614aa1604051918261401f565b8281528092614ab2601f1991614a73565b01905f5b828110614ac257505050565b806060602080938501015201614ab6565b614adb614a5a565b506040516020614aeb818361401f565b5f825260405190614afc818361401f565b5f8252601f198101815f5b828110614b265750505060405192614b1e84614004565b835282015290565b6060828287010152018290614b07565b8051821015614b4a5760209160051b010190565b634e487b7160e01b5f52603260045260245ffd5b908151811015614b4a570160200190565b614b77614a5a565b506020810190815151916001830180931161432557614b9583614040565b92614ba3604051948561401f565b808452614bb2601f1991614040565b013660208501378051516001810180911161432557614bd090614a8a565b945f5b86515f19810190811161432557811015614c315780614bf56001928551614b36565b51614c00828a614b36565b52614c0b8189614b36565b5060ff60f81b614c1c828751614b5e565b51165f1a614c2a8288614b5e565b5301614bd3565b50949290919383515f19810190811161432557614c5991614c528287614b36565b5284614b36565b5082515f19810190811161432557614c7360019183614b5e565b5383525290565b614c82614a5a565b506020810190815151916001830180931161432557614ca083614040565b92614cae604051948561401f565b808452614cbd601f1991614040565b013660208501378051516001810180911161432557614cdb90614a8a565b945f5b86515f19810190811161432557811015614d3c5780614d006001928551614b36565b51614d0b828a614b36565b52614d168189614b36565b5060ff60f81b614d27828751614b5e565b51165f1a614d358288614b5e565b5301614cde565b50949290919383515f19810190811161432557614d5d91614c528287614b36565b5082515f19810190811161432557614c7360119183614b5e565b614d9a906020815191015190604051928391604060208401526060830190613f19565b91601f19828403016040830152805180845260208401936020808360051b8301019301945f915b838310614ddf57505050506140cc925003601f19810183528261401f565b91936001919395506020614dfe8192601f198682030187528951613f19565b97019301930190928694929593614dc1565b8054821015614b4a575f5260205f2001905f90565b6001810190825f528160205260405f2054155f14614e8d57805468010000000000000000811015613fd557614e7a614e64826001879401855584614e10565b819391549060031b91821b915f19901b19161790565b905554915f5260205260405f2055600190565b5050505f90565b906001820191815f528260205260405f20548015155f14614f51575f1981018181116143255782545f1981019190821161432557818103614f1c575b50505080548015614f08575f190190614ee98282614e10565b8154905f199060031b1b19169055555f526020525f6040812055600190565b634e487b7160e01b5f52603160045260245ffd5b614f3c614f2c614e649386614e10565b90549060031b1c92839286614e10565b90555f528360205260405f20555f8080614ed0565b505050505f9056fe55f448fdea98c4d29eb340757ef0a66cd03dbb9538908a6a81d96026b71ec47594cb47eeeeb76a68c4d24f7c656bc9e63d5bc82211fc7784b33e438103b2f873d833147d7dc355ba459fc788f669e58cfaf9dc25ddcd0702e87d69c7b5124289a26469706673582212204bf628d5ced724f675c8299577c4436c4da370b916d16697f9968330db207a8f64736f6c634300081a00330000000000000000000000001f984000000000000000000000000000000000040000000000000000000000004529a01c7a0410167c5740c487a8de60232617bf000000000000000000000000d45dd91df475bfd944335160f538c1a14888dc1c000000000000000000000000d45dd91df475bfd944335160f538c1a14888dc1c000000000000000000000000d45dd91df475bfd944335160f538c1a14888dc1c
Deployed Bytecode
0x608080604052600436101561001c575b50361561001a575f80fd5b005b5f905f3560e01c908163011e116714613f015750806301ffc9a714613e94578063066b58c714613e6c57806306fdde0314613da5578063081812fc14613d69578063095ea7b314613c7f5780630ae300bf14613c575780630b78f9c014613bd7578063150b7a0214613b685780631c76046e146137305780631f113fc31461370757806322758802146136c857806323b872dd146136b057806323cf31181461367057806323fa495a1461362257806342842e0e146135f8578063454b06081461332457806355f804b3146131da5780635a04fb691461308a5780636352211e146130595780636c0360eb1461303d5780636d3b96c314612ffe578063704ce43e14612fe057806370a0823114612f8d578063715018a614612f3057806375eb8e6914612f14578063791b98bc14612ecf5780637dccbb9914612e84578063879905a114612e145780638d3c100a1461277b5780638da5cb5b146127525780638e5f59771461251857806393ac8305146124c557806395d89b411461241e57806396e8392414611b655780639b7d02ad14611b2c5780639caf4f0b14611a925780639ecd747214611a69578063a22cb465146119c5578063aa1ef5981461190b578063aa67bf3a14611860578063b2fb30cb146117a3578063b707a288146116f1578063b88d4fde1461168e578063c45d7c56146115ec578063c668286214611530578063c87b56dd1461127d578063c9102afd1461110d578063ce79eb6014611049578063d4d5d32a1461102b578063d73792a91461100e578063d9eb594714610ff0578063da3ef23f14610e92578063dc4c90d314610e4d578063e4877d3f14610e0e578063e985e9c514610db6578063eb3a79ed14610cd7578063ef24894414610c68578063f0cf6c9614610c3e578063f2fde38b14610bb5578063f4dadc6114610b0a578063f62f5a23146103235763f6aacfb10361000f573461032057602036600319011261032057604060209160043581526008835220600681015415159081610312575b506040519015158152f35b60079150015442105f610307565b80fd5b50606036600319011261032057604435600435811515602435818403610b065761034b6149ab565b338552601760205260ff60408620541615610aed575b42811115610ade576402540be40081101580610ad3575b610ac4577f0000000000000000000000004529a01c7a0410167c5740c487a8de60232617bf6001600160a01b031691823b15610ac057604051632142170760e11b8152336004820152306024820152604481018590528690818160648183895af1801561091157610aab575b5050604051637ba03aad60e01b8152600481018590529560c087602481875afa968715610a9e578197610a6c575b50604051631efeed3360e01b81526004810186905291602083602481885afa928315610911578293610a4b575b506001600160801b0383168015610a3c5760a0892060405160208101918252600660408201526040815261047460608261401f565b519020604051631e2eaeaf60e01b815260048101919091526020816024817f0000000000000000000000001f984000000000000000000000000000000000046001600160a01b03165afa908115610a315784916109fb575b506001600160a01b0316156109ec5760808901516001600160a01b031680610960575b50600f5480151580610949575b6107aa575b5050600b549661051088614317565b600b5561079b575b8760806001600160801b036040519561053087613fe9565b898752876020880152846040880152169485606082015201526009601054886040519361055c85613fb9565b81855260208501338152604086018b81528d6060880190815260808801918a835260a08901938c855260c08a019633885260e08b019687526101008b019889528b52600860205260408b2099518a5560018060a01b0390511660018a019060018060a01b03166001600160601b0360a01b8254161790555160028901555160018060a01b03815116600389019060018060a01b03166001600160601b0360a01b8254161790556004880160018060a01b0360018060a01b03602084015116166001600160601b0360a01b82541617815560408201518154606084015160b81b62ffffff60b81b169162ffffff60a01b9060a01b169065ffffffffffff60a01b191617179055608060018060a01b0391015116600588019060018060a01b03166001600160601b0360a01b825416179055516006870155516007860155600885019160018060a01b039060018060a01b03905116166001600160601b0360a01b83541617825551151581549060ff60a01b9060a01b169060ff60a01b191617905551910155338152600a6020526106f58660408320614e25565b50338152601760205260ff6040822054161580610792575b610762575b5060a060209620936040519384528684015260408301526060820152827f49def1ccceea7771ce91254bcad08254733e55bec4be0b3b47a01b7f2cb53b0060803393a46001600755604051908152f35b8080808060018060a01b03600c541634905af161077d6145c6565b50610712575b63b12d13eb60e01b8152600490fd5b5034151561070d565b6107a587336147fb565b610518565b610863929450816107cf6127106107c76108139461085e966145f5565b048092614608565b506107d8614ad3565b604051918a6020840152604083015285606083015285608083015260a0808301528560c083015260c0825261080e60e08361401f565b614b6f565b60018060a01b038a51169060018060a01b0360208c01511660018060a01b03600c541690604051936020850152604084015260608301526060825261085960808361401f565b614c7a565b614d77565b603c42019081421161093557853b156109315760405163dd46508f60e01b8152918391839182916108989190600484016145aa565b038183895af180156109115790829161091c575b5050604051631efeed3360e01b815260048101869052602081602481885afa9081156109115782916108e2575b50915f80610501565b610904915060203d60201161090a575b6108fc818361401f565b81019061458b565b5f6108d9565b503d6108f2565b6040513d84823e3d90fd5b816109269161401f565b61032057805f6108ac565b8280fd5b634e487b7160e01b83526011600452602483fd5b50338452601760205260ff604085205416156104fc565b60ff6012541660038110156109d857600281036109a257508352600960205260ff60408420541615610993575b5f6104ef565b632812ca3b60e21b8352600483fd5b6001146109b0575b5061098d565b8352601360205260ff6040842054166109c9575f6109aa565b6308ed3ca360e01b8352600483fd5b634e487b7160e01b85526021600452602485fd5b63486aa30760e01b8352600483fd5b90506020813d602011610a29575b81610a166020938361401f565b81010312610a2557515f6104cc565b8380fd5b3d9150610a09565b6040513d86823e3d90fd5b6378b8b76160e01b8352600483fd5b610a6591935060203d60201161090a576108fc818361401f565b915f61043f565b610a8f91975060c03d60c011610a97575b610a87818361401f565b81019061456d565b50955f610412565b503d610a7d565b50604051903d90823e3d90fd5b81610ab59161401f565b610ac057855f6103e4565b8580fd5b6352aba6d360e11b8552600485fd5b505f19811415610378565b63ae130dfb60e01b8552600485fd5b601154341015610361576340b7d5ed60e11b8552600485fd5b8480fd5b50346103205760203660031901126103205760406101a091600435815260086020522080549060ff60018060a01b03600183015416916002810154610b5160038301614224565b610b856006840154916007850154936009600887015496015497604051998a5260208a0152604089015260608801906141ba565b6101008601526101208501526001600160a01b03811661014085015260a01c161515610160830152610180820152f35b503461032057602036600319011261032057610bcf613f3d565b610bd76147d4565b6001600160a01b03168015610c2a57600680546001600160a01b0319811683179091556001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08380a380f35b631e4fbdf760e01b82526004829052602482fd5b5034610320578060031936011261032057610c6460ff60125416604051918291826141fd565b0390f35b503461032057610c7736613f69565b610c7f6147d4565b8183526008602052600960408420018054821015610cc857817fa4b63b21571e7c2b944a681b0a39cda220f85f67aaa7aa4d23fcf7d31e2379a39260209255604051908152a280f35b630927c5af60e41b8452600484fd5b503461032057604036600319011261032057610cf1613f53565b6040516331a9108f60e11b8152600480359082015291906020836024817f0000000000000000000000004529a01c7a0410167c5740c487a8de60232617bf6001600160a01b03165afa928315610911578293610d76575b506001600160a01b039081169216828103610d61575080f35b604492634877b8df60e01b8352600452602452fd5b9092506020813d602011610dae575b81610d926020938361401f565b81010312610daa57610da390614277565b915f610d48565b5080fd5b3d9150610d85565b5034610320576040366003190112610320576040610dd2613f3d565b91610ddb613f53565b9260018060a01b031681526005602052209060018060a01b03165f52602052602060ff60405f2054166040519015158152f35b50346103205760203660031901126103205760209060ff906040906001600160a01b03610e39613f3d565b168152601784522054166040519015158152f35b50346103205780600319360112610320576040517f0000000000000000000000001f984000000000000000000000000000000000046001600160a01b03168152602090f35b503461032057610ea136614091565b90610eaa6147d4565b81516001600160401b038111610fdc57610ec56016546140cf565b601f8111610f74575b50602092601f8211600114610f0a57928293829392610eff575b50508160011b915f199060031b1c19161760165580f35b015190505f80610ee8565b60168352601f198216935f80516020614f9a83398151915291845b868110610f5c5750836001959610610f44575b505050811b0160165580f35b01515f1960f88460031b161c191690555f8080610f38565b91926020600181928685015181550194019201610f25565b60168352601f820160051c5f80516020614f9a833981519152019060208310610fc7575b601f0160051c5f80516020614f9a83398151915201905b818110610fbc5750610ece565b838155600101610faf565b5f80516020614f9a8339815191529150610f98565b634e487b7160e01b82526041600452602482fd5b50346103205780600319360112610320576020601154604051908152f35b503461032057806003193601126103205760206040516127108152f35b50346103205780600319360112610320576020601054604051908152f35b503461032057604036600319011261032057611063613f3d565b61106b6141ab565b906110746147d4565b6001600160a01b03169081156110fe57818352600960205260ff6040842054169080151580921515146110ef577f5b2460eb1f1133b6714bb07afb85ae0d9c49f24afa50d9800c1cc6d789f4acc7916110e560209285875260098452604087209060ff801983541691151516179055565b604051908152a280f35b63a88ee57760e01b8452600484fd5b632a96f9e160e21b8352600483fd5b5034610320576020366003190112610320576040816101a092610100835161113481613fb9565b8281528260208201528285820152845161114d81613fe9565b838152836020820152838682015283606082015283608082015260608201528260808201528260a08201528260c08201528260e0820152015260043581526008602052206040519061119e82613fb9565b8054825260018101546001600160a01b03166020830190815260028201546040840190815290916111d160038201614224565b6060850190815260068201546080860190815261124d60078401549260a08801938452600885015495600960c08a019660018060a01b038916885260ff60e08c019960a01c16151589520154976101008a0198895260405199518a5260018060a01b0390511660208a01525160408901525160608801906141ba565b5161010086015251610120850152516001600160a01b031661014084015251151561016083015251610180820152f35b503461032057602036600319011261032057600435808252600260205260408220546001600160a01b03161561151e576112b5614107565b8051909190156115035782818072184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b8110156114dd575b50806d04ee2d6d415b85acef8100000000600a9210156114c2575b662386f26fc100008110156114ae575b6305f5e10081101561149d575b61271081101561148e575b6064811015611480575b1015611478575b6001810191600a602161136061134a86614040565b95611358604051978861401f565b808752614040565b602086019490601f19013686378501015b5f1901916f181899199a1a9b1b9c1cb0b131b232b360811b8282061a83530490811561139f57600a90611371565b505060209182604051948051918291018587015e84019083820190868252519283915e010182815260165490836113d5836140cf565b926001811690811561145b5750600114611417575b50505061140381610c649303601f19810183528261401f565b604051918291602083526020830190613f19565b90919350601681525f80516020614f9a8339815191525b84821061144757505081610c64936114039201936113ea565b60018160209254848601520191019061142e565b60ff19168352505081151590910201915061140381610c646113ea565b600101611335565b60646002910492019161132e565b61271060049104920191611324565b6305f5e10060089104920191611319565b662386f26fc100006010910492019161130c565b6d04ee2d6d415b85acef8100000000602091049201916112fc565b6040925072184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b90049050600a6112e1565b5050604051610c649161151760208361401f565b8152611403565b637e27328960e01b8252600452602490fd5b5034610320578060031936011261032057604051908060165490611553826140cf565b80855291600181169081156115c5575060011461157b575b610c64846114038186038261401f565b601681525f80516020614f9a833981519152939250905b8082106115ab575090915081016020016114038261156b565b919260018160209254838588010152019101909291611592565b60ff191660208087019190915292151560051b85019092019250611403915083905061156b565b5034610320576020366003190112610320576004356003811015610daa576116126147d4565b60125460ff8116600381101561167a57821461166b5760ff191660ff8216176012556040517fd2e6f9601313cfd1c3bd69d8a281aed29a764c8a456a0ac3fe12a4767608c16891819061166590826141fd565b0390a180f35b63a88ee57760e01b8352600483fd5b634e487b7160e01b84526021600452602484fd5b5034610320576080366003190112610320576116a8613f3d565b6116b0613f53565b606435916001600160401b038311610a255736602384011215610a25576116e46116ee93369060248160040135910161405b565b9160443591614687565b80f35b50346103205760403660031901126103205760043561170e613f53565b6117166149ab565b6001600160a01b03169081156117945780835260086020526040832060018101546001600160a01b031633036117855760080180546001600160a01b031916831790557f570a1ee460fe39844fcfa359db528b53324ce4c22fa7080d3834db0a6349ed808380a3600160075580f35b6330cd747160e01b8452600484fd5b635447822f60e01b8352600483fd5b5034610320576117b236613f69565b6117ba6149ab565b81835260086020526040832060018101546001600160a01b031633036117855742821115611851576007018054821115611837576402540be40082101580611846575b61183757817f4e4187a5cfd31a235276a431f3c394962d1b05cc4da52f6fa4e5460a5808ee219260209255604051908152a2600160075580f35b6352aba6d360e11b8452600484fd5b505f198214156117fd565b63ae130dfb60e01b8452600484fd5b50346103205760403660031901126103205761187a613f3d565b6118826141ab565b9061188b6147d4565b6001600160a01b03169081156110fe57818352601360205260ff6040842054169080151580921515146110ef57916040916118fd7f4cc0d8bbc18f4db77c5226d5370b9a94a5e93e3cf2671017043e55c190be6d6d9483875260136020528487209060ff801983541691151516179055565b82519182526020820152a180f35b503461032057606036600319011261032057611925613f3d565b61192d613f53565b6044356001600160a01b0381169290839003610a255761194b6147d4565b6001600160a01b03169081156119b6576001600160a01b03169081156119a7576001600160601b0360a01b600c541617600c556001600160601b0360a01b600d541617600d556001600160601b0360a01b600e541617600e5580f35b633621ffa560e11b8452600484fd5b630b670b9760e21b8452600484fd5b5034610320576040366003190112610320576119df613f3d565b6119e76141ab565b6001600160a01b03909116908115611a5557338352600560205260408320825f52602052611a248160405f209060ff801983541691151516179055565b60405190151581527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c3160203392a380f35b630b61174360e31b83526004829052602483fd5b50346103205780600319360112610320576014546040516001600160a01b039091168152602090f35b503461032057604036600319011261032057611aac613f3d565b611ab46141ab565b90611abd6147d4565b6001600160a01b0316908115611b1d5760207fee6dc5e65d61241c43ff3037dcd8a7857d0780c354fac7a12f99285a476cf9ed9183855260178252611b1181604087209060ff801983541691151516179055565b6040519015158152a280f35b630f58058360e11b8352600483fd5b5034610320576020366003190112610320576020906040906001600160a01b03611b54613f3d565b168152600a83522054604051908152f35b503461032057602036600319011261032057600435611b826149ab565b80825260086020526040822060018101546001600160a01b0316338103611785576007820154421061240f576006820180548015612400576002840154938660018060a01b037f0000000000000000000000004529a01c7a0410167c5740c487a8de60232617bf1693604051637ba03aad60e01b815287600482015260c081602481895afa9081156123f55783916123d5575b50604051631efeed3360e01b8152600481018990526020816024818a5afa8015610a31576001600160801b039185916123b6575b5016611f1c575b5055838752600a602052611c678660408920614e94565b5060ff600882015460a01c16611e17575b823b15611e13576040516323b872dd60e01b81523060048201526001600160a01b03851660248201526044810186905287808260648183895af19182611dfa575b5050611d6257868060033d11611d51575b506308c379a014611d15575b6040516312dfddb360e01b81526020600482015260166024820152752ab735b737bbb7103a3930b739b332b91032b93937b960511b6044820152606490fd5b611d1d614615565b80611d285750611cd6565b6040516312dfddb360e01b815260206004820152908190611d4d906024830190613f19565b0390fd5b9050600481803e5160e01c81611cca565b85927fba4a3f8e2e6613ba4f7a58a5f3afbe56fdaae5ed213275b0d9bec44761f6cb059260a0611d96600360609501614224565b209660405192835260208301526040820152a481526008602052611df26040822060095f918281558260018201558260028201558260038201558260048201558260058201558260068201558260078201558260088201550155565b600160075580f35b81611e049161401f565b611e0f57875f611cb9565b8780fd5b8680fd5b858752600260205260408720546001600160a01b0316801590811580611ee9575b888a52600260205260408a2080546001600160a01b0319169055888a837fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8280a4888a52600860205260ff600860408c20015460a01c16611ec3575b508881895f80516020614f7a8339815191528380a45015611c7857637e27328960e01b87526004869052602487fd5b611ece575b5f611e94565b808952600a602052611ee38860408b20614e94565b50611ec8565b5f89815260046020526040902080546001600160a01b0319169055818a52600360205260408a2080545f19019055611e38565b909150843b156123b25760405163095ea7b360e01b81526001600160a01b03861660048201526024810188905289908181604481838b5af180156109115761239d575b5050611fb2611f6c614ad3565b6040519061080e82611fa48c6020830160c09181525f60208201525f60408201525f606082015260a060808201525f60a08201520190565b03601f19810184528361401f565b815160208084018051604080516001600160a01b0395861694810194909452931692820192909252306060820152909291611ff89161085e916108598260808101611fa4565b603c42019081421161238957908b94939291883b15610ac05760405163dd46508f60e01b8152918691839182916120339190600484016145aa565b0381838c5af190811561237e578591612369575b50505190516001600160a01b039081169116878215821580156122f15747935b8491831561227657475b809660098c0154908161213b575b505050826120e3575b50505082612099575b505050611c50565b929492156120d45782939450829182915af16120b36145c6565b50156120c55787905b5f808781612091565b63b12d13eb60e01b8852600488fd5b6120de92946149cb565b6120bc565b97939192949596975f14612125575082809281925af16121016145c6565b50156121165790878b9493925b5f8080612088565b63b12d13eb60e01b8b5260048bfd5b9181612136929498979695936149cb565b61210e565b61216298508192955061216b6127108061215861217195856145f5565b049a8b95896145f5565b04938492614608565b95614608565b96806121fd575b5080612186575b808061207f565b909294849697989992945f146121d95750600d54829182918291906001600160a01b03165af16121b46145c6565b50156121ca57918d96959493918b935b5f61217f565b63b12d13eb60e01b8e5260048efd5b9492906121f89060018060a09c9b9a9997959c1b03600d5416896149cb565b6121c4565b90929496979899919395845f146122525750600d54829182918291906001600160a01b03165af161222c6145c6565b501561224357918b93918f98979695935b5f612178565b63b12d13eb60e01b8f5260048ffd5b959391999897969492906122719060018060a01b03600d5416856149cb565b61223d565b6040516370a0823160e01b815230600482015294506020856024818a5afa80156122e6578d958a916122a9575b50612071565b95505097506020843d6020116122de575b816122c76020938361401f565b810103126122da578e978c94515f6122a3565b5f80fd5b3d91506122ba565b6040513d8b823e3d90fd5b6040516370a0823160e01b81523060048201529250602083602481875afa801561235e578b938891612325575b5093612067565b93505095506020823d602011612356575b816123436020938361401f565b810103126122da578c958a92515f61231e565b3d9150612336565b6040513d89823e3d90fd5b816123739161401f565b610a2557835f612047565b6040513d87823e3d90fd5b634e487b7160e01b8c52601160045260248cfd5b816123a79161401f565b6123b257885f611f5f565b8880fd5b6123cf915060203d60201161090a576108fc818361401f565b5f611c49565b6123ee915060c03d60c011610a9757610a87818361401f565b505f611c15565b6040513d85823e3d90fd5b6328486b6360e11b8652600486fd5b636100d92960e11b8452600484fd5b5034610320578060031936011261032057604051908060015490612441826140cf565b80855291600181169081156115c5575060011461246857610c64846114038186038261401f565b600181527fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6939250905b8082106124ab575090915081016020016114038261156b565b919260018160209254838588010152019101909291612492565b503461032057604036600319011261032057808080806124e3613f53565b6124eb6147d4565b6124f36149ab565b600435906001600160a01b03165af161250a6145c6565b501561078357600160075580f35b503461032057608036600319011261032057600435602435916001600160801b0383168093036103205761254a6149ab565b81815260086020526040812060018101546001600160a01b031633036127435760078101545f19811461273157421115612722578315612713576006810190815485116127045761261a906125e06125a0614ad3565b6002830154906040519160208301528860408301526044356060830152606435608083015260a0808301528660c083015260c0825261080e60e08361401f565b6003820154600490920154604080516001600160a01b03948516602082015293909116908301523360608301526108598260808101611fa4565b7f0000000000000000000000004529a01c7a0410167c5740c487a8de60232617bf6001600160a01b03169061264e90614d77565b90603c4201918242116126f057813b15610b0657918491612686938360405180968195829463dd46508f60e01b8452600484016145aa565b03925af180156123f5576126db575b506126a36040948254614608565b90558251917f64d0c470254fcda065fe0e66b5395405b2b6f2997de63b73f166031c81c4bdbb8280a260016007558082526020820152f35b6126e683809261401f565b610daa575f612695565b634e487b7160e01b85526011600452602485fd5b63bb55fd2760e01b8352600483fd5b630200e8a960e31b8252600482fd5b632cc8960360e11b8252600482fd5b600162f96b2f60e01b03198352600483fd5b6330cd747160e01b8252600482fd5b50346103205780600319360112610320576006546040516001600160a01b039091168152602090f35b503461032057604036600319011261032057612795613f53565b9061279e6149ab565b808081908260043581526008602052604081209560018060a01b0360018801541633141580612dff575b612743576001600160a01b03811615612df057600287018054604051637ba03aad60e01b81526004810182905290987f0000000000000000000000004529a01c7a0410167c5740c487a8de60232617bf6001600160a01b03169290919060c082602481875afa918215612de5578692612dc3575b50604051631efeed3360e01b8152600481018c9052602081602481885afa90811561235e57906001600160801b03918891612da4575b501661289b575b60808a8a8a8a6001600755604051938452602084015260408301526060820152f35b92859a9194979899508096509491943b15610daa5760405163095ea7b360e01b81526001600160a01b038716600482015260248101919091528181604481838a5af1801561091157612d8f575b5050611fa46129309161080e6128fc614ad3565b91546040519384916020830160c09181525f60208201525f60408201525f606082015260a060808201525f60a08201520190565b815160208084018051604080516001600160a01b03958616948101949094529316928201929092523060608201529094916129769161085e916108598260808101611fa4565b603c4201804211612d7b579082918a933b15610a25576129af9284928360405180968195829463dd46508f60e01b8452600484016145aa565b03925af1801561091157612d66575b50505191516001600160a01b0392831680159693909116928315928715612cf85747965b878515612c8a5747935b849260098501938d855415155f14612bdc575050505050918796959391612a3f612a3761271080612a24612a2e9e9a9854809d6145f5565b049c8d9b866145f5565b049b8c9b614608565b9a8b93614608565b9660018060a01b03600e541633145f14612bc7578b8a825b8b612b74575b81612b39575b5050600e546001600160a01b03163314159050612b305750600801546001600160a01b03169485905b82612afb575b5050505083612aaf575b505050608094505b5f8080808080612879565b15612ae757508580808481945af1612ac56145c6565b5015612ad857608094505b5f8080612a9c565b63b12d13eb60e01b8552600485fd5b60809650612af69183916149cb565b612ad0565b15612b22578a809350809281925af1612b126145c6565b50156120c5575b5f878482612a92565b612b2b926149cb565b612b19565b90508095612a8c565b8715612b64578293949550829182915af1612b526145c6565b5015612116579089915b8b8a5f612a63565b612b6f9250886149cb565b612b5c565b9293949190895f14612bb2575080808093508c855af1612b926145c6565b5015612ba357908b8a8c9493612a5d565b63b12d13eb60e01b8c5260048cfd5b9091949392612bc28c82896149cb565b612a5d565b600d548c908b906001600160a01b0316612a57565b9450989597945098958a929b87929b612c46575b505050505083612c08575b5050505060809450612aa4565b15612c3257508680809381935af1612c1e6145c6565b5015612ad857608094505b5f808080612bfb565b6080975090612c4192916149cb565b612c29565b15612c7b575082809281925af1612c5b6145c6565b5015612c6c575b885f848180612bf0565b63b12d13eb60e01b8952600489fd5b612c8593506149cb565b612c62565b6040516370a0823160e01b81523060048201526020816024818b5afa908115612ced578c91612cbb575b50936129ec565b90506020813d602011612ce5575b81612cd66020938361401f565b810103126122da57515f612cb4565b3d9150612cc9565b6040513d8e823e3d90fd5b6040516370a0823160e01b8152306004820152602081602481875afa908115612d5b578a91612d29575b50966129e2565b90506020813d602011612d53575b81612d446020938361401f565b810103126122da57515f612d22565b3d9150612d37565b6040513d8c823e3d90fd5b81612d709161401f565b611e1357865f6129be565b634e487b7160e01b8a52601160045260248afd5b81612d999161401f565b611e0f57875f6128e8565b612dbd915060203d60201161090a576108fc818361401f565b5f612872565b612ddd91925060c03d60c011610a9757610a87818361401f565b50905f61283c565b6040513d88823e3d90fd5b634e46966960e11b8252600482fd5b50600e546001600160a01b03163314156127c8565b503461032057612e2336613f7f565b909291612e2e6147d4565b612e366149ab565b6001600160a01b0390811693907f0000000000000000000000004529a01c7a0410167c5740c487a8de60232617bf168414612e7557611df292936149cb565b633d8647d760e11b8352600483fd5b503461032057604036600319011261032057602090612ec0906001600160a01b03612ead613f3d565b168152600a835260406024359120614e10565b90549060031b1c604051908152f35b50346103205780600319360112610320576040517f0000000000000000000000004529a01c7a0410167c5740c487a8de60232617bf6001600160a01b03168152602090f35b503461032057806003193601126103205760206040515f198152f35b5034610320578060031936011261032057612f496147d4565b600680546001600160a01b0319811690915581906001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a380f35b5034610320576020366003190112610320576001600160a01b03612faf613f3d565b168015612fcc578160409160209352600383522054604051908152f35b6322718ad960e21b82526004829052602482fd5b50346103205780600319360112610320576020600f54604051908152f35b50346103205760203660031901126103205760209060ff906040906001600160a01b03613029613f3d565b168152600984522054166040519015158152f35b5034610320578060031936011261032057610c64611403614107565b50346103205760203660031901126103205760206130786004356147a0565b6040516001600160a01b039091168152f35b503461032057604036600319011261032057600435906130a8613f53565b916130b16149ab565b6001600160a01b0383169283156131cb578183526008602052604083206001810180549091906001600160a01b031633036131bc576008019060ff825460a01c165f1461316b57506001600160a01b039161310e91508390614838565b16928361312957637e27328960e01b83526004829052602483fd5b919233810361314f57505b33905f80516020614f7a8339815191528480a4600160075580f35b6364283d7b60e01b845233600452602491909152604452606482fd5b909150939293338552600a6020526131868360408720614e94565b50838552600a60205261319c8360408720614e25565b5080546001600160a01b0319908116851790915581541683179055613134565b6330cd747160e01b8552600485fd5b632a52b3c360e11b8352600483fd5b5034610320576131e936614091565b906131f26147d4565b81516001600160401b038111610fdc5761320d6015546140cf565b601f81116132bc575b50602092601f821160011461325257928293829392613247575b50508160011b915f199060031b1c19161760155580f35b015190505f80613230565b60158352601f198216935f80516020614f5a83398151915291845b8681106132a4575083600195961061328c575b505050811b0160155580f35b01515f1960f88460031b161c191690555f8080613280565b9192602060018192868501518155019401920161326d565b60158352601f820160051c5f80516020614f5a83398151915201906020831061330f575b601f0160051c5f80516020614f5a83398151915201905b8181106133045750613216565b8381556001016132f7565b5f80516020614f5a83398151915291506132e0565b5060203660031901126103205760043561333c6149ab565b6014546001600160a01b031680156135e957818352600860205260408320600181018054909291906001600160a01b031633036131bc576006810154156135da5760020180546040516331a9108f60e11b81526004810182905291927f0000000000000000000000004529a01c7a0410167c5740c487a8de60232617bf6001600160a01b031692602081602481875afa9081156135cf578891613595575b50306001600160a01b039091160361358657908691833b156109315760405163095ea7b360e01b81526001600160a01b039190911660048201526024810191909152818160448183875af1801561091157613571575b5050601454915460405163277c45f560e11b81526004810186905260248101929092526044820152906020908290606490829034906001600160a01b03165af1908115610a31578491613537575b501561352857546001600160a01b03168252600a602052604082206134a4908290614e94565b5080825260086020526134ef6040832060095f918281558260018201558260028201558260038201558260048201558260058201558260068201558260078201558260088201550155565b6014546001600160a01b0316907f44428b5f080165ed3e2574589b3d8fdfed8c7aeddd00fb5e847fb6034dcea7b38380a3600160075580f35b63513dfed160e11b8352600483fd5b90506020813d602011613569575b816135526020938361401f565b81010312610a25576135639061430a565b5f61347e565b3d9150613545565b8161357b9161401f565b610b0657845f613430565b63213eeaa160e21b8752600487fd5b90506020813d6020116135c7575b816135b06020938361401f565b81010312611e0f576135c190614277565b5f6133da565b3d91506135a3565b6040513d8a823e3d90fd5b6304a417d360e31b8552600485fd5b632ed9bf5360e21b8352600483fd5b5034610320576116ee61360a36613f7f565b906040519261361a60208561401f565b858452614687565b5034610320576020366003190112610320577f02e6220a8c55d7fd57319e91a44a9aac5a5fd4c64a19bb34bb83c8cedbf3f39860206004356136626147d4565b80601155604051908152a180f35b50346103205760203660031901126103205761368a613f3d565b6136926147d4565b60018060a01b03166001600160601b0360a01b601454161760145580f35b5034610320576116ee6136c236613f7f565b91614339565b50346103205760203660031901126103205760209060ff906040906001600160a01b036136f3613f3d565b168152601384522054166040519015158152f35b5034610320578060031936011261032057600d546040516001600160a01b039091168152602090f35b346122da5760403660031901126122da57613749613f53565b6014546001600160a01b03163303613b595760405163c9102afd60e01b81526004803590820152906101a090829060249082906001600160a01b03165afa908115613a7b575f91613aa4575b50600b546137a281614317565b600b5560e082018051613a86575b6020830160018060a01b0381511693604081019184600984519560608501948551996080820198895160a084019c8d519261010060018060a01b0360c0880151169601519651151594604051996138068b613fb9565b808b5260208b0191825260408b0192835260608b0193845260808b0194855260a08b0195865260c08b0197885260e08b019687526101008b019889525f52600860205260405f2099518a5560018060a01b0390511660018a019060018060a01b03166001600160601b0360a01b8254161790555160028901555160018060a01b03815116600389019060018060a01b03166001600160601b0360a01b8254161790556004880160018060a01b0360018060a01b03602084015116166001600160601b0360a01b82541617815560408201518154606084015160b81b62ffffff60b81b169162ffffff60a01b9060a01b169065ffffffffffff60a01b191617179055608060018060a01b0391015116600588019060018060a01b03166001600160601b0360a01b825416179055516006870155516007860155600885019160018060a01b039060018060a01b03905116166001600160601b0360a01b83541617825551151581549060ff60a01b9060a01b169060ff60a01b19161790555191015560018060a01b038151165f52600a6020526139a48560405f20614e25565b5082517f0000000000000000000000004529a01c7a0410167c5740c487a8de60232617bf6001600160a01b0316803b156122da576040516323b872dd60e01b815233600482015230602482015260448101929092525f8260648183855af1938415613a7b5760209860a07f49def1ccceea7771ce91254bcad08254733e55bec4be0b3b47a01b7f2cb53b00956080958b98613a6b575b50600180831b03905116975192512097519051916040519384528a84015260408301526060820152a4604051908152f35b5f613a759161401f565b5f613a3a565b6040513d5f823e3d90fd5b6020830151613a9f9083906001600160a01b03166147fb565b6137b0565b90506101a03d8111613b52575b613abb818361401f565b8101906101a0818303126122da5761018090613b0560405193613add85613fb9565b82518552613aed60208401614277565b6020860152604083015160408601526060830161428b565b6060840152610100810151608084015261012081015160a0840152613b2d6101408201614277565b60c0840152613b3f610160820161430a565b60e0840152015161010082015281613795565b503d613ab1565b6323479f3d60e21b5f5260045ffd5b346122da5760803660031901126122da57613b81613f3d565b50613b8a613f53565b506064356001600160401b0381116122da57366023820112156122da5780600401356001600160401b0381116122da57369101602401116122da57604051630a85bd0160e11b8152602090f35b346122da57613be536613f69565b613bed6147d4565b6103e88211613c48576103e88111613c3957816040917f93525d3c7f4fafe56faedbca6d501a13c63f47857d8b30d8282ec2dd806259a793600f558060105582519182526020820152a1005b63596b468d60e01b5f5260045ffd5b632df1c0af60e01b5f5260045ffd5b346122da575f3660031901126122da57600c546040516001600160a01b039091168152602090f35b346122da5760403660031901126122da57613c98613f3d565b602435613ca4816147a0565b33151580613d56575b80613d29575b613d165781906001600160a01b0384811691167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9255f80a45f90815260046020526040902080546001600160a01b0319166001600160a01b03909216919091179055005b63a9fbf51f60e01b5f523360045260245ffd5b506001600160a01b0381165f90815260056020908152604080832033845290915290205460ff1615613cb3565b506001600160a01b038116331415613cad565b346122da5760203660031901126122da57600435613d86816147a0565b505f526004602052602060018060a01b0360405f205416604051908152f35b346122da575f3660031901126122da576040515f8054613dc4816140cf565b8084529060018116908115613e485750600114613dec575b610c64836114038185038261401f565b5f8080527f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563939250905b808210613e2e57509091508101602001611403613ddc565b919260018160209254838588010152019101909291613e16565b60ff191660208086019190915291151560051b840190910191506114039050613ddc565b346122da575f3660031901126122da57600e546040516001600160a01b039091168152602090f35b346122da5760203660031901126122da5760043563ffffffff60e01b81168091036122da576020906380ac58cd60e01b8114908115613ef0575b8115613edf57506040519015158152f35b6301ffc9a760e01b14905082610307565b635b5e139f60e01b81149150613ece565b346122da575f3660031901126122da57805f60209252f35b805180835260209291819084018484015e5f828201840152601f01601f1916010190565b600435906001600160a01b03821682036122da57565b602435906001600160a01b03821682036122da57565b60409060031901126122da576004359060243590565b60609060031901126122da576004356001600160a01b03811681036122da57906024356001600160a01b03811681036122da579060443590565b61012081019081106001600160401b03821117613fd557604052565b634e487b7160e01b5f52604160045260245ffd5b60a081019081106001600160401b03821117613fd557604052565b604081019081106001600160401b03821117613fd557604052565b90601f801991011681019081106001600160401b03821117613fd557604052565b6001600160401b038111613fd557601f01601f191660200190565b92919261406782614040565b91614075604051938461401f565b8294818452818301116122da578281602093845f960137010152565b60206003198201126122da57600435906001600160401b0382116122da57806023830112156122da578160246140cc9360040135910161405b565b90565b90600182811c921680156140fd575b60208310146140e957565b634e487b7160e01b5f52602260045260245ffd5b91607f16916140de565b604051905f826015549161411a836140cf565b808352926001811690811561418c5750600114614140575b61413e9250038361401f565b565b5060155f90815290915f80516020614f5a8339815191525b81831061417057505090602061413e92820101614132565b6020919350806001915483858901015201910190918492614158565b6020925061413e94915060ff191682840152151560051b820101614132565b6024359081151582036122da57565b80516001600160a01b03908116835260208083015182169084015260408083015162ffffff169084015260608083015160020b9084015260809182015116910152565b9190602083019260038210156142105752565b634e487b7160e01b5f52602160045260245ffd5b9060405161423181613fe9565b82546001600160a01b0390811682526001840154808216602084015260a081901c62ffffff16604084015260b81c600290810b6060840152909301549092166080830152565b51906001600160a01b03821682036122da57565b91908260a09103126122da576040516142a381613fe9565b80926142ae81614277565b82526142bc60208201614277565b6020830152604081015162ffffff811681036122da5760408301526060810151908160020b82036122da57606083019190915260800151906001600160a01b03821682036122da5760800152565b519081151582036122da57565b5f1981146143255760010190565b634e487b7160e01b5f52601160045260245ffd5b6001600160a01b039091169190821561455a575f828152600260205260409020546001600160a01b031692331515806144ca575b5083151580614497575b815f52600360205260405f2060018154019055835f52600260205260405f20826001600160601b0360a01b8254161790558382867fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef5f80a4835f52600860205260ff600860405f20015460a01c1661442b575b5083835f80516020614f7a8339815191525f80a46001600160a01b031680830361441357505050565b6364283d7b60e01b5f5260045260245260445260645ffd5b61447c575b805f52600a6020526144458360405f20614e25565b505f83815260086020819052604082206001810180546001600160a01b0319908116861790915591018054909116831790556143ea565b835f52600a6020526144918360405f20614e94565b50614430565b5f84815260046020526040902080546001600160a01b0319169055845f52600360205260405f205f198154019055614377565b80614509575b156144db575f61436d565b82846144f357637e27328960e01b5f5260045260245ffd5b63177e802f60e01b5f523360045260245260445ffd5b503384148015614538575b806144d057505f838152600460205260409020546001600160a01b031633146144d0565b505f84815260056020908152604080832033845290915290205460ff16614514565b633250574960e11b5f525f60045260245ffd5b919060c0838203126122da5761458560a0918461428b565b92015190565b908160209103126122da57516001600160801b03811681036122da5790565b9291906145c1602091604086526040860190613f19565b930152565b3d156145f0573d906145d782614040565b916145e5604051938461401f565b82523d5f602084013e565b606090565b8181029291811591840414171561432557565b9190820391821161432557565b5f60443d106140cc576040513d600319016004823e8051913d60248401116001600160401b0384111761468157828201928351916001600160401b038311614679573d8401600319018584016020011161467957506140cc9291016020019061401f565b949350505050565b92915050565b9291614694818386614339565b813b6146a1575b50505050565b604051630a85bd0160e11b81523360048201526001600160a01b03948516602482015260448101919091526080606482015292169190602090829081906146ec906084830190613f19565b03815f865af15f918161475b575b5061472857506147086145c6565b805190816147235782633250574960e11b5f5260045260245ffd5b602001fd5b6001600160e01b03191663757a42ff60e11b0161474957505f80808061469b565b633250574960e11b5f5260045260245ffd5b9091506020813d602011614798575b816147776020938361401f565b810103126122da57516001600160e01b0319811681036122da57905f6146fa565b3d915061476a565b5f818152600260205260409020546001600160a01b03169081156147c2575090565b637e27328960e01b5f5260045260245ffd5b6006546001600160a01b031633036147e857565b63118cdaa760e01b5f523360045260245ffd5b906001600160a01b0382161561455a576001600160a01b039161481e9190614838565b1661482557565b6339e3563760e11b5f525f60045260245ffd5b5f828152600260205260409020546001600160a01b0316918215159183919083614978575b6001600160a01b0316928315159081614960575b825f52600260205260405f20856001600160601b0360a01b8254161790558285857fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef5f80a4825f52600860205260ff600860405f20015460a01c166148e7575b50505f80516020614f7a8339815191525f80a490565b614945575b6148f8575b5f806148d1565b825f52600a60205261490d8160405f20614e25565b505f8181526008602081905260409091206001810180546001600160a01b0319908116871790915591018054909116841790556148f1565b825f52600a60205261495a8260405f20614e94565b506148ec565b845f52600360205260405f2060018154019055614871565b5f82815260046020526040902080546001600160a01b0319169055825f52600360205260405f205f19815401905561485d565b6002600754146149bc576002600755565b633ee5aeb560e01b5f5260045ffd5b60405163a9059cbb60e01b60208083019182526001600160a01b0394909416602483015260448083019590955293815290925f91614a0a60648261401f565b519082855af115613a7b575f513d614a5157506001600160a01b0381163b155b614a315750565b635274afe760e01b5f9081526001600160a01b0391909116600452602490fd5b60011415614a2a565b60405190614a6782614004565b60606020838281520152565b6001600160401b038111613fd55760051b60200190565b90614a9482614a73565b614aa1604051918261401f565b8281528092614ab2601f1991614a73565b01905f5b828110614ac257505050565b806060602080938501015201614ab6565b614adb614a5a565b506040516020614aeb818361401f565b5f825260405190614afc818361401f565b5f8252601f198101815f5b828110614b265750505060405192614b1e84614004565b835282015290565b6060828287010152018290614b07565b8051821015614b4a5760209160051b010190565b634e487b7160e01b5f52603260045260245ffd5b908151811015614b4a570160200190565b614b77614a5a565b506020810190815151916001830180931161432557614b9583614040565b92614ba3604051948561401f565b808452614bb2601f1991614040565b013660208501378051516001810180911161432557614bd090614a8a565b945f5b86515f19810190811161432557811015614c315780614bf56001928551614b36565b51614c00828a614b36565b52614c0b8189614b36565b5060ff60f81b614c1c828751614b5e565b51165f1a614c2a8288614b5e565b5301614bd3565b50949290919383515f19810190811161432557614c5991614c528287614b36565b5284614b36565b5082515f19810190811161432557614c7360019183614b5e565b5383525290565b614c82614a5a565b506020810190815151916001830180931161432557614ca083614040565b92614cae604051948561401f565b808452614cbd601f1991614040565b013660208501378051516001810180911161432557614cdb90614a8a565b945f5b86515f19810190811161432557811015614d3c5780614d006001928551614b36565b51614d0b828a614b36565b52614d168189614b36565b5060ff60f81b614d27828751614b5e565b51165f1a614d358288614b5e565b5301614cde565b50949290919383515f19810190811161432557614d5d91614c528287614b36565b5082515f19810190811161432557614c7360119183614b5e565b614d9a906020815191015190604051928391604060208401526060830190613f19565b91601f19828403016040830152805180845260208401936020808360051b8301019301945f915b838310614ddf57505050506140cc925003601f19810183528261401f565b91936001919395506020614dfe8192601f198682030187528951613f19565b97019301930190928694929593614dc1565b8054821015614b4a575f5260205f2001905f90565b6001810190825f528160205260405f2054155f14614e8d57805468010000000000000000811015613fd557614e7a614e64826001879401855584614e10565b819391549060031b91821b915f19901b19161790565b905554915f5260205260405f2055600190565b5050505f90565b906001820191815f528260205260405f20548015155f14614f51575f1981018181116143255782545f1981019190821161432557818103614f1c575b50505080548015614f08575f190190614ee98282614e10565b8154905f199060031b1b19169055555f526020525f6040812055600190565b634e487b7160e01b5f52603160045260245ffd5b614f3c614f2c614e649386614e10565b90549060031b1c92839286614e10565b90555f528360205260405f20555f8080614ed0565b505050505f9056fe55f448fdea98c4d29eb340757ef0a66cd03dbb9538908a6a81d96026b71ec47594cb47eeeeb76a68c4d24f7c656bc9e63d5bc82211fc7784b33e438103b2f873d833147d7dc355ba459fc788f669e58cfaf9dc25ddcd0702e87d69c7b5124289a26469706673582212204bf628d5ced724f675c8299577c4436c4da370b916d16697f9968330db207a8f64736f6c634300081a0033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
0000000000000000000000001f984000000000000000000000000000000000040000000000000000000000004529a01c7a0410167c5740c487a8de60232617bf000000000000000000000000d45dd91df475bfd944335160f538c1a14888dc1c000000000000000000000000d45dd91df475bfd944335160f538c1a14888dc1c000000000000000000000000d45dd91df475bfd944335160f538c1a14888dc1c
-----Decoded View---------------
Arg [0] : _poolManager (address): 0x1F98400000000000000000000000000000000004
Arg [1] : _positionManager (address): 0x4529A01c7A0410167c5740C487A8DE60232617bf
Arg [2] : _lpFeeReceiver (address): 0xD45dD91DF475bFD944335160f538C1A14888DC1C
Arg [3] : _collectFeeReceiver (address): 0xD45dD91DF475bFD944335160f538C1A14888DC1C
Arg [4] : _autoCollectAccount (address): 0xD45dD91DF475bFD944335160f538C1A14888DC1C
-----Encoded View---------------
5 Constructor Arguments found :
Arg [0] : 0000000000000000000000001f98400000000000000000000000000000000004
Arg [1] : 0000000000000000000000004529a01c7a0410167c5740c487a8de60232617bf
Arg [2] : 000000000000000000000000d45dd91df475bfd944335160f538c1a14888dc1c
Arg [3] : 000000000000000000000000d45dd91df475bfd944335160f538c1a14888dc1c
Arg [4] : 000000000000000000000000d45dd91df475bfd944335160f538c1a14888dc1c
Net Worth in USD
Net Worth in ETH
Multichain Portfolio | 35 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
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.