LpPosition
PersonalYieldTrackers
Wrapper for a vector of personal yield trackers for farm emissions.PersonalYieldTracker
Individual tracker for interest and emissions earned by deposits.PrincipalShareTrackers
Wrapper for a vector of principal share trackers.PrincipalShare
Tracker for LP shares and emissions across a specific tick range.CrossingSplit
When a position spans the active tick, it is logically split into three segments (A, B, C) with separate fee and farm tracking.Key Concepts
Tick Range
Each LP position is defined by a lower and upper tick index (lower_tick_idx and upper_tick_idx). The position only earns fees and provides liquidity when the market’s current price falls within this range.
Fee Accrual Tracking
The fieldsfee_inside_last_pt and fee_inside_last_sy use Q64.64 fixed-point arithmetic to track the cumulative fees per unit of liquidity at the last time the position was updated. This allows for precise calculation of fees owed to the position.
When fees are calculated:
- The current fee-per-liquidity values are fetched from the market
- The difference between current and last-seen values is computed
- This difference is multiplied by the position’s
lp_balanceto determine fees owed - Fees are added to
tokens_owed_syandtokens_owed_pt
Tokens Owed
Thetokens_owed_sy and tokens_owed_pt fields accumulate fees earned by the position. These tokens can be claimed by the position owner through a withdrawal instruction. The tokens remain tracked here until explicitly claimed.
Farm Emissions
Thefarms field tracks farm emission rewards that the position has earned. Each PersonalYieldTracker in the vector corresponds to a different emission token, tracking the last-seen index and tokens owed for that specific reward.
Position Lifecycle
- Creation — A position is created when an LP adds liquidity to a market within a specific tick range
- Active — While the position has
lp_balance > 0, it earns fees when the market price is within range - Fee Accrual — Fees accumulate in
tokens_owed_*fields and can be claimed at any time - Liquidity Adjustment — The LP can add or remove liquidity, updating
lp_balance - Closure — When
lp_balancereaches 0 and all tokens owed are claimed, the position can be closed
Share Trackers
Theshare_trackers field maintains a PrincipalShare entry per tick interval in the position’s range. Each tick interval tracks the principal amounts of PT and SY deposited by LPs, along with a share supply for proportional emission distribution.
When a new tick is inserted within an existing range, principals are split proportionally between the old and new intervals using the spot prices of the bounding ticks. The split_epoch counter tracks when the last split occurred so positions can correctly account for historical splits.