Contract: Implement dynamic fees in AMM based on volume#307
Open
RemmyAcee wants to merge 1 commit intoceejaylaboratory:mainfrom
Open
Contract: Implement dynamic fees in AMM based on volume#307RemmyAcee wants to merge 1 commit intoceejaylaboratory:mainfrom
RemmyAcee wants to merge 1 commit intoceejaylaboratory:mainfrom
Conversation
|
@RemmyAcee Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Author
|
Done, Close: #307 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Close: #266
I've successfully finalized the implementation of the dynamic fee mechanism for the MultiAssetSwap AMM contract and ensured the entire test suite passes properly under the constrained no_std Soroban environment.
Monotonic Price Formula: Replaced the simplified test approximation for tick_to_sqrt_price_x96 with a more precise, directionally correct logic where price(tick) scales appropriately for both positive and negative ticks. This fixed "invalid price limit" panics in tests evaluating the zero-for-one price drops.
Liquidity Math Overflow: The previous liquidity calculation for amount0 and amount1 involved large multiplications of u128 limits that overflowed. I implemented a mathematically safe, right-shifted division logic (>> 48) to ensure numerator and denominator remain within safety bounds before being divided.
Test Value Scaling: Since the math operates in Q96 fixed-point scales (where ratios are multiplied by
Fixed the test_burn_and_collect by re-ordering the logic to collect owed protocol fees before burning the entirety of the liquidity position, preventing "position not found" panics.
All 6 core tests now pass properly in debug/release profiles:
test_tick_out_of_bounds
test_invalid_tick_range
test_concentrated_liquidity_swap
test_concentrated_liquidity_mint
test_burn_and_collect
test_dynamic_fee_scaling
Validation Results
Running cargo test -p swap now yields a 100% pass rate.
shell
running 6 tests
test tests::test_tick_out_of_bounds - should panic ... ok
test tests::test_invalid_tick_range - should panic ... ok
test tests::test_concentrated_liquidity_swap ... ok
test tests::test_concentrated_liquidity_mint ... ok
test tests::test_burn_and_collect ... ok
test tests::test_dynamic_fee_scaling ... ok
test result: ok. 6 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.47s