Skip to content

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

Open
Bismithblde wants to merge 2 commits into
solana-foundation:mainfrom
Bismithblde:fix/token-swap-lp-issuance
Open

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

Conversation

@Bismithblde

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.

@greptile-apps

greptile-apps Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Critical impact] The PR appears safe to merge.

Summary

The PR makes later deposits receive LP shares based on their contribution to both reserves, including the locked minimum in the share supply.

  • Later deposits receive LP shares based on both pool reserves.

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

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.

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

1 participant