Skip to content

fix(token-swap): issue LP shares proportionally after fee growth - #784

Closed
Bismithblde wants to merge 1 commit into
solana-foundation:mainfrom
Bismithblde:fix/token-swap-lp-issuance
Closed

Bismithblde wants to merge 1 commit into
solana-foundation:mainfrom
Bismithblde:fix/token-swap-lp-issuance

Conversation

@Bismithblde

@Bismithblde Bismithblde commented Nov 4, 2026 •

Copy link
Copy Markdown

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

  • Existing token-swap LiteSVM tests: 10 passed before the fix.
  • Added a separate-provider regression after a fee-bearing swap. Before the fix it failed: 672,292 LP tokens minted versus a proportional maximum of 666,665; after the fix it passed.
  • NO_DNA=1 cargo build-sbf --manifest-path programs/token-swap/Cargo.toml --sbf-out-dir target/deploy --tools-version v1.57 --arch v3
  • cargo test in tokens/token-swap/anchor: 11 integration tests passed.
  • rustfmt --check on changed Rust files; git diff --check.

AI disclosure

  • No AI tooling was used beyond editor autocomplete.
  • AI tooling was used. Tool and extent: OpenAI Codex investigated the bug, wrote the regression test, implementation, and documentation, and ran the checks described above.

@github-actions github-actions Bot added the needs-issue PR does not reference an issue a maintainer has accepted label Nov 4, 2026
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

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 accepted, put Fixes #<issue> in this description and reopen this pull request; the check runs again and clears itself. Typos, broken links and comment-only fixes are exempt: write Linked issue: trivial instead.

@github-actions github-actions Bot closed this Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-issue PR does not reference an issue a maintainer has accepted

Projects

None yet

Development

Successfully merging this pull request may close these issues.

token-swap: later deposits can dilute LPs after fee growth

1 participant