Skip to main content
Helpful?

PositionManager

Git Source | Generated with forge doc

Inherits: IPositionManager, ERC721Permit_v4, PoolInitializer, Multicall_v4, DeltaResolver, ReentrancyLock, BaseActionsRouter, Notifier, Permit2Forwarder

The PositionManager (PosM) contract is responsible for creating liquidity positions on v4. PosM mints and manages ERC721 tokens associated with each position.

State Variables

nextTokenId

Used to get the ID that will be used for the next minted liquidity position

The ID of the next token that will be minted. Skips 0

uint256 public nextTokenId = 1;

positionInfo

mapping(uint256 tokenId => PositionInfo info) public positionInfo;

poolKeys

mapping(bytes25 poolId => PoolKey poolKey) public poolKeys;

Functions

constructor

constructor(IPoolManager _poolManager, IAllowanceTransfer _permit2, uint256 _unsubscribeGasLimit)
BaseActionsRouter(_poolManager)
Permit2Forwarder(_permit2)
ERC721Permit_v4("Uniswap V4 Positions NFT", "UNI-V4-POSM")
Notifier(_unsubscribeGasLimit);

checkDeadline

Reverts if the deadline has passed

modifier checkDeadline(uint256 deadline);

Parameters

NameTypeDescription
deadlineuint256The timestamp at which the call is no longer valid, passed in by the caller

onlyIfApproved

Reverts if the caller is not the owner or approved for the ERC721 token

either msg.sender or msgSender() is passed in as the caller msgSender() should ONLY be used if this is called from within the unlockCallback, unless the codepath has reentrancy protection

modifier onlyIfApproved(address caller, uint256 tokenId) override;

Parameters

NameTypeDescription
calleraddressThe address of the caller
tokenIduint256the unique identifier of the ERC721 token

modifyLiquidities

Unlocks Uniswap v4 PoolManager and batches actions for modifying liquidity

This is the standard entrypoint for the PositionManager

function modifyLiquidities(bytes calldata unlockData, uint256 deadline)
external
payable
isNotLocked
checkDeadline(deadline);

Parameters

NameTypeDescription
unlockDatabytesis an encoding of actions, and parameters for those actions
deadlineuint256is the deadline for the batched actions to be executed

modifyLiquiditiesWithoutUnlock

Batches actions for modifying liquidity without unlocking v4 PoolManager

This must be called by a contract that has already unlocked the v4 PoolManager

function modifyLiquiditiesWithoutUnlock(bytes calldata actions, bytes[] calldata params) external payable isNotLocked;

Parameters

NameTypeDescription
actionsbytesthe actions to perform
paramsbytes[]the parameters to provide for the actions

msgSender

function that returns address considered executor of the actions

The other context functions, _msgData and _msgValue, are not supported by this contract In many contracts this will be the address that calls the initial entry point that calls _executeActionsmsg.sender shouldn't be used, as this will be the v4 pool manager contract that calls unlockCallback If using ReentrancyLock.sol, this function can return _getLocker()

function msgSender() public view override returns (address);

_handleAction

function _handleAction(uint256 action, bytes calldata params) internal virtual override;

_increase

Calling increase with 0 liquidity will credit the caller with any underlying fees of the position

function _increase(uint256 tokenId, uint256 liquidity, uint128 amount0Max, uint128 amount1Max, bytes calldata hookData)
internal
onlyIfApproved(msgSender(), tokenId);

_decrease

Calling decrease with 0 liquidity will credit the caller with any underlying fees of the position

function _decrease(uint256 tokenId, uint256 liquidity, uint128 amount0Min, uint128 amount1Min, bytes calldata hookData)
internal
onlyIfApproved(msgSender(), tokenId);

_mint

function _mint(
PoolKey calldata poolKey,
int24 tickLower,
int24 tickUpper,
uint256 liquidity,
uint128 amount0Max,
uint128 amount1Max,
address owner,
bytes calldata hookData
) internal;

_burn

this is overloaded with ERC721Permit_v4._burn

function _burn(uint256 tokenId, uint128 amount0Min, uint128 amount1Min, bytes calldata hookData)
internal
onlyIfApproved(msgSender(), tokenId);

_settlePair

function _settlePair(Currency currency0, Currency currency1) internal;

_takePair

function _takePair(Currency currency0, Currency currency1, address recipient) internal;

_close

function _close(Currency currency) internal;

_clearOrTake

integrators may elect to forfeit positive deltas with clear if the forfeit amount exceeds the user-specified max, the amount is taken instead

function _clearOrTake(Currency currency, uint256 amountMax) internal;

_sweep

Sweeps the entire contract balance of specified currency to the recipient

function _sweep(Currency currency, address to) internal;

_modifyLiquidity

function _modifyLiquidity(
PositionInfo info,
PoolKey memory poolKey,
int256 liquidityChange,
bytes32 salt,
bytes calldata hookData
) internal returns (BalanceDelta liquidityDelta, BalanceDelta feesAccrued);

_pay

function _pay(Currency currency, address payer, uint256 amount) internal override;

_setSubscribed

an internal helper used by Notifier

function _setSubscribed(uint256 tokenId) internal override;

_setUnsubscribed

an internal helper used by Notifier

function _setUnsubscribed(uint256 tokenId) internal override;

transferFrom

overrides solmate transferFrom in case a notification to subscribers is needed

function transferFrom(address from, address to, uint256 id) public virtual override;

getPoolAndPositionInfo

function getPoolAndPositionInfo(uint256 tokenId) public view returns (PoolKey memory poolKey, PositionInfo info);

Parameters

NameTypeDescription
tokenIduint256the ERC721 tokenId

Returns

NameTypeDescription
poolKeyPoolKeythe pool key of the position
infoPositionInfopoolKey the pool key of the position

getPositionLiquidity

this value can be processed as an amount0 and amount1 by using the LiquidityAmounts library

function getPositionLiquidity(uint256 tokenId) external view returns (uint128 liquidity);

Parameters

NameTypeDescription
tokenIduint256the ERC721 tokenId

Returns

NameTypeDescription
liquidityuint128the position's liquidity, as a liquidityAmount

_getLiquidity

function _getLiquidity(uint256 tokenId, PoolKey memory poolKey, int24 tickLower, int24 tickUpper)
internal
view
returns (uint128 liquidity);
Helpful?