Skip to content

WIP: DynamicTickArray#19

Open
AngSin wants to merge 24 commits intomasterfrom
use_dynamic_tick_arrays
Open

WIP: DynamicTickArray#19
AngSin wants to merge 24 commits intomasterfrom
use_dynamic_tick_arrays

Conversation

@AngSin
Copy link
Contributor

@AngSin AngSin commented Dec 5, 2025

No description provided.

@AngSin AngSin changed the title Add: DynamicTickArray WIP: DynamicTickArray Dec 5, 2025
@AngSin AngSin force-pushed the use_dynamic_tick_arrays branch from a570568 to 5143b3f Compare December 7, 2025 11:59
@AngSin AngSin force-pushed the use_dynamic_tick_arrays branch from 5143b3f to fadbb3d Compare December 7, 2025 14:40
@AngSin AngSin force-pushed the use_dynamic_tick_arrays branch from 61d7c68 to c027f4f Compare December 8, 2025 11:07
@AngSin AngSin force-pushed the use_dynamic_tick_arrays branch from fdde0d2 to dc02bdf Compare February 3, 2026 10:31
Copy link
Contributor

@danielpavel danielpavel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the critical part which needs to be fixed is: "fee growth not initialized for new ticks" - otherwise, looks good to me

veerbal1 and others added 4 commits February 10, 2026 11:48
* test: Added test to check Uninitialized dynamic tick size

* test: Added test for initialized dynamic tick serialization size

* test: Add round-trip serialization test for DynamicTick

* feat: Add tests for dynamic tick array bitmap management and introduce a test plan and PR review guide.

* test: Add unit tests for tick updates and validation in DynamicTickArrayLoader

* test: Added tests for next init tick index and clear tick

* test: Enhance next init tick index tests to cover additional scenarios

* test: added exact bit filp testing when tick init/uninit

* test: Add tests for data integrity after tick initialization and uninitialization in DynamicTickArrayLoader

* test: Add tests for handling negative start tick indices and edge cases in DynamicTickArrayLoader

* test: Add unit tests for DynamicTick::update() fee initialization logic across various scenarios

* Added comments on tests
@AngSin AngSin requested a review from danielpavel February 16, 2026 16:52
@AngSin AngSin requested a review from veerbal1 February 16, 2026 17:27
@AngSin AngSin force-pushed the use_dynamic_tick_arrays branch from b370c8f to 5643731 Compare February 16, 2026 17:54
Copy link
Contributor

@danielpavel danielpavel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If @veerbal1 issue with stale pointer is taken care of then LGTM

veerbal1 and others added 2 commits March 4, 2026 09:10
* fix: move dynamic tick array realloc out of update_tick to avoid double borrow

Solana's realloc() calls try_borrow_mut_data() internally, which panics when a RefMut is already held. Move realloc to instruction handlers (add_liquidity, burn_liquidity) after borrows are dropped, following Orca's pattern.

* refactor: optimize dynamic tick array reallocations in add_liquidity and burn_liquidity

Consolidate realloc logic for dynamic tick arrays when both ticks are in the same account, reducing redundant operations. Adjust handling for grow and shrink scenarios to improve efficiency and maintain clarity in memory management.

* Setup bankrun tests

* created basic mint, ata helper functions

* Fix: dropping tick arrays ref. to double mut ref issue

* Wrote basic tests to check increase, decrease liquidity within same array

* Added various integration tests

* Minor cleanup

* Added new edge case

* removed negative reallocation from add liquidity function

* MInor cleanup

* Fix pool-level tick_array_bitmap bugs for same-array dynamic positions

When both ticks of a position land in the same dynamic tick array,
the pool-level bitmap was not updated correctly:

Bug 1 (open_position): modify_position initializes both ticks before the bitmap check runs. initialized_tick_count() returns 2, so the guard `if count == 1` never fires and flip_tick_array_bit is never called. The array is invisible to swaps despite having liquidity.

Bug 2 (decrease_liquidity): Both ticks are deinitialized before the bitmap check. initialized_tick_count() returns 0 for both checks, causing flip_tick_array_bit (XOR) to fire twice on the same bit. The two XOR operations cancel each other, leaving the bit unchanged.

Fix: Capture initialized_tick_count() before modify_position runs.
Compare before vs after to decide whether to flip the pool bit. For same-array dynamic positions, only flip once (during the lower tick's check) and skip the upper tick's check entirely. Fixed arrays are unaffected their stored counter approach already works correctly.

* Add pool bitmap verification tests for bitmap fix coverage gaps

- Overlapping positions: verify pool bitmap unchanged when array already has ticks
- Partial decrease: verify pool bitmap stays ON when ticks remain initialized
- Fixed same-array: verify pool bitmap set on open, cleared on full decrease

* Minor cleanup

* Add mutability to tick_array_lower and tick_array_upper in liquidity instructions

- Updated IncreaseLiquidityV2 and DecreaseLiquidityV2 structs to mark tick_array_lower and tick_array_upper as mutable accounts, ensuring proper state management during liquidity operations.

* Added swap and fee integrity tests

* Added more edge cases in testing

* Added some more tests
@veerbal1 veerbal1 requested review from veerbal1 and removed request for veerbal1 March 5, 2026 06:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants