collecttransfers requested owed amounts into token records and advances fee checkpoints.burnconsumes an empty ownership record and removes the public position row.
Outcome
Collection is complete when the transaction is accepted, requested owed amounts are transferred into token records, the replacementPositionNFT is stored, and the wallet has discovered both payout records. Burning is complete only after liquidity and owed amounts are zero and the public position row is removed.
Before you start
Read the public position and current inside fee growth, verify the position is not frozen, reserve the currentPositionNFT, choose base-unit collection amounts within the settled and pending entitlement, and obtain non-inclusion proofs for the NFT owner and immutable withdrawal address.
What can be collected
A position can have value from:- Pending LP fees not yet reflected in
tokens_owed - Previously settled LP fees
- Principal credited by decrease or freeze
tokens_owed0 and tokens_owed1 fields include only amounts already settled. A collect transaction also calculates pending fees from current inside growth before checking the requested amounts.
Collect inputs and outputs
collect accepts:
- Current
PositionNFTrecord - Public base-unit token0 amount requested
- Public base-unit token1 amount requested
- Public token0 and token1 program IDs
- Two owner and two withdrawal
MerkleProofvalues
- Replacement
PositionNFTrecord - Token0 payout record
- Token1 payout record
withdrawal address in the NFT. That address cannot be the AMM, router, or zero address.
Collection amounts and position accounting are public. The withdrawal address and payout token records are confidential under Aleo’s record model, but the investigator-owned mint record contains the withdrawal address.
Read Public data for the broader observability boundary.
Amount validation
Collection requests use native token base units. The contract checks each request directly against total owed after pending fee settlement.Pending-fee settlement
For each token:total_owed remains uncollected. The uncollected integer amount is preserved in tokens_owed.
The fractional remainder below one native base unit is discarded when the checkpoint advances. Collect changes fee checkpoints and owed balances.
Read Fee entitlements and Q128.128 fee growth.
Choosing requested amounts
A caller may request less than the available amount. This is useful when:- Keeping part of the balance in the AMM’s owed accounting
- Matching a custody or treasury instruction
- Avoiding an overestimate caused by stale off-chain state
- Collecting one token without collecting the other
Settlement dust
Each step’s LP fee is recorded with 128 fractional bits and no cross-epoch residual. This prevents a later LP set from receiving an earlier set’s fractional fee. Two floors still matter:- Step growth is
floor(lp_fee * 2^128 / active_liquidity). - Position settlement is
floor(delta_growth * position_liquidity / 2^128).
protocol_fees0 and protocol_fees1.
See Rounding, overflow, and invariants.
Collect under controls
Collect does not apply the pool entry-pause hierarchy. Disabling a pool or pausing trading does not by itself trap an LP’s settled value. A position freeze is different. Frozen positions cannot collect. If a live position is frozen, the freeze path first removes its liquidity and settles principal and fees intotokens_owed. Unfreeze makes that value collectable but does not restore liquidity.
Burn prerequisites
burn succeeds only when:
PositionNFT and removes the public positions[token_id] entry. It returns no replacement ownership record.
The transition does not inspect pending fee growth. With zero position liquidity, later fee growth creates no additional position entitlement. Any fees earned before liquidity reached zero were settled by the decrease or freeze operation that removed the liquidity.
Complete closeout
Use this sequence:- Decrease all remaining liquidity.
- Wait for acceptance and save the replacement
PositionNFT. - Read public
tokens_owedbalances. - Include any pending fee estimate if liquidity was not actually zero.
- Collect token0 and token1 in native base units.
- Save the replacement ownership record from collect.
- Verify liquidity and both owed balances are zero.
- Burn using the latest record.
- Mark the token ID closed in the custody and accounting systems.
Closeout records
An institutional closeout record should retain:- Deployment ID and program checksum
- Position token ID and pool key
- Decrease transaction and credited principal
- Fee calculation inputs and rounding policy
- Public requested collection amounts
- Payout record custody references
- Final zero position state
- Burn transaction removing the mapping row