Repository navigation
fix(token-swap): issue LP shares proportionally after fee growth - #789
Open
Bismithblde wants to merge 2 commits into
Open
Bismithblde wants to merge 2 commits into
Bismithblde wants to merge 2 commits into
Conversation
Contributor
[Critical impact] The PR appears safe to merge. SummaryThe PR makes later deposits receive LP shares based on their contribution to both reserves, including the locked minimum in the share supply.
The previous request for guard tests is fully addressed. No new actionable issues were found. Reviews (2) · Last reviewed commit: "test(token-swap): cover rejected liquidi..." · Reviewed by Greptile |
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.
Linked issue
Fixes #783
What and why
After a fee-bearing swap, the Anchor token-swap example mints LP shares for a new deposit using the geometric mean of the deposit amounts. This ignores reserve growth and can dilute existing liquidity providers.
Keep the geometric mean for the initial deposit. For later deposits, calculate shares against both pre-deposit reserves and the effective LP supply, including the locked minimum used by withdrawals, and round down to the smaller result. Reject deposits that would mint zero shares, and return an error for one-sided reserves instead of dividing by zero. Update the example documentation.
Testing
NO_DNA=1 cargo build-sbf --manifest-path programs/token-swap/Cargo.toml --sbf-out-dir target/deploy --tools-version v1.57 --arch v3cargo testintokens/token-swap/anchor: 11 integration tests passed.rustfmt --checkon changed Rust files;git diff --check.AI disclosure