Skip to main content

PositionInfo

Git Source - Generated with forge doc

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;

PositionInfoLibrary

Git Source

State Variables

EMPTY_POSITION_INFO

PositionInfo internal constant EMPTY_POSITION_INFO = PositionInfo.wrap(0);

MASK_UPPER_200_BITS

uint256 internal constant MASK_UPPER_200_BITS = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000000000;

MASK_8_BITS

uint256 internal constant MASK_8_BITS = 0xFF;

MASK_24_BITS

uint24 internal constant MASK_24_BITS = 0xFFFFFF;

SET_UNSUBSCRIBE

uint256 internal constant SET_UNSUBSCRIBE = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00;

SET_SUBSCRIBE

uint256 internal constant SET_SUBSCRIBE = 0x01;

TICK_LOWER_OFFSET

uint8 internal constant TICK_LOWER_OFFSET = 8;

TICK_UPPER_OFFSET

uint8 internal constant TICK_UPPER_OFFSET = 32;

Functions

poolId

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);

tickLower

function tickLower(PositionInfo info) internal pure returns (int24 _tickLower);

tickUpper

function tickUpper(PositionInfo info) internal pure returns (int24 _tickUpper);

hasSubscriber

function hasSubscriber(PositionInfo info) internal pure returns (bool _hasSubscriber);

setSubscribe

this does not actually set any storage

function setSubscribe(PositionInfo info) internal pure returns (PositionInfo _info);

setUnsubscribe

this does not actually set any storage

function setUnsubscribe(PositionInfo info) internal pure returns (PositionInfo _info);

initialize

Creates the default PositionInfo struct

Called when minting a new position

function initialize(PoolKey memory _poolKey, int24 _tickLower, int24 _tickUpper)
internal
pure
returns (PositionInfo info);

Parameters

NameTypeDescription
_poolKeyPoolKeythe pool key of the position
_tickLowerint24the lower tick of the position
_tickUpperint24the upper tick of the position

Returns

NameTypeDescription
infoPositionInfopacked position info, with the truncated poolId and the hasSubscriber flag set to false