Skip to main content
Helpful?

Position

Git Source | Generated with forge doc

Positions represent an owner address' liquidity between a lower and upper tick boundary

Positions store additional state for tracking fees owed to the position

Functions

get

Returns the State struct of a position, given an owner and position boundaries

function get(mapping(bytes32 => State) storage self, address owner, int24 tickLower, int24 tickUpper, bytes32 salt)
internal
view
returns (State storage position);

Parameters

NameTypeDescription
selfmapping(bytes32 => State)The mapping containing all user positions
owneraddressThe address of the position owner
tickLowerint24The lower tick boundary of the position
tickUpperint24The upper tick boundary of the position
saltbytes32A unique value to differentiate between multiple positions in the same range

Returns

NameTypeDescription
positionStateThe position info struct of the given owners' position

calculatePositionKey

A helper function to calculate the position key

function calculatePositionKey(address owner, int24 tickLower, int24 tickUpper, bytes32 salt)
internal
pure
returns (bytes32 positionKey);

Parameters

NameTypeDescription
owneraddressThe address of the position owner
tickLowerint24the lower tick boundary of the position
tickUpperint24the upper tick boundary of the position
saltbytes32A unique value to differentiate between multiple positions in the same range, by the same owner. Passed in by the caller.

update

Credits accumulated fees to a user's position

function update(State storage self, int128 liquidityDelta, uint256 feeGrowthInside0X128, uint256 feeGrowthInside1X128)
internal
returns (uint256 feesOwed0, uint256 feesOwed1);

Parameters

NameTypeDescription
selfStateThe individual position to update
liquidityDeltaint128The change in pool liquidity as a result of the position update
feeGrowthInside0X128uint256The all-time fee growth in currency0, per unit of liquidity, inside the position's tick boundaries
feeGrowthInside1X128uint256The all-time fee growth in currency1, per unit of liquidity, inside the position's tick boundaries

Returns

NameTypeDescription
feesOwed0uint256The amount of currency0 owed to the position owner
feesOwed1uint256The amount of currency1 owed to the position owner

Errors

CannotUpdateEmptyPosition

Cannot update a position with no liquidity

error CannotUpdateEmptyPosition();

Structs

State

struct State {
uint128 liquidity;
uint256 feeGrowthInside0LastX128;
uint256 feeGrowthInside1LastX128;
}
Helpful?