Repository navigation
fix(token-swap): issue LP shares proportionally after fee growth - #784
Bismithblde wants to merge 1 commit into
Conversation
|
Hi @Bismithblde, Thanks for the pull request. We ask that every change references an issue a maintainer has accepted, and there isn't one linked here. These examples are a teaching resource and each one has to stay small enough to read in one sitting, so whether a new example or framework flavor belongs here is worth settling before anyone writes it. Agreeing on the approach in an issue first means nobody writes code that can't be merged. See CONTRIBUTING.md for the full workflow. Please open an issue describing the change, or comment on the existing one. Once a maintainer has labelled it |
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