-
-
Notifications
You must be signed in to change notification settings - Fork 269
Description
Summary
When opening an Orca CLMM position, the positionRent field should include the rent for tick arrays that are initialized as part of the transaction. Currently, positionRent only includes:
- Position mint account rent
- Position data account rent
- Position token account (ATA) rent
It does not include tick array rent when tick arrays are initialized by the transaction.
Background
Per the Orca whirlpools program, collect_rent_for_ticks_in_position is called during position creation:
collect_rent_for_ticks_in_position(
&ctx.accounts.funder,
position,
&ctx.accounts.system_program,
)?;This tick rent is refundable when the position is closed.
Implementation
openPosition.ts
-
Modify
initializeTickArrays()to return an array ofPublicKey[]for tick arrays that were initialized:async function initializeTickArrays(...): Promise<PublicKey[]> { const initializedTickArrays: PublicKey[] = []; // ... existing logic ... if (!lowerTickArray) { // ... add instruction ... initializedTickArrays.push(lowerTickArrayPda.publicKey); } if (!upperTickArray && !upperTickArrayPda.publicKey.equals(lowerTickArrayPda.publicKey)) { // ... add instruction ... initializedTickArrays.push(upperTickArrayPda.publicKey); } return initializedTickArrays; }
-
Capture the returned tick array pubkeys:
const initializedTickArrays = await initializeTickArrays(...);
-
After TX confirms, query tick array balances and add to positionRent:
const tickArrayBalances = await Promise.all( initializedTickArrays.map(pubkey => solana.connection.getBalance(pubkey)) ); const tickArrayRent = tickArrayBalances.reduce((sum, bal) => sum + bal, 0); const positionRent = (positionMintBalance + positionDataBalance + positionAtaBalance + tickArrayRent) * LAMPORT_TO_SOL;
-
Update the log message to include tick array rent breakdown.
closePosition.ts
The developer using the API should verify that positionRentRefunded includes the expected tick rent. Note that tick arrays are shared resources - if other positions are using the same tick arrays, they won't be closed and that rent won't be refunded to this specific user.
The position data account balance (positionDataBalance) already includes any tick rent that was stored in the position account itself via collect_rent_for_ticks_in_position.
Related
- Token-2022 positions already ensure full rent recovery on close (recent fix)
- This enhancement captures the additional tick array initialization cost for complete cost transparency