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

Aperta
#783 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@Bismithblde ci sta già lavorando.

Dal 5/11/2026.

  • #784 di @Bismithblde — chiusa senza merge
  • #789 di @Bismithblde — aperta

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust

Direzione di ricerca

Find the token-swap example and its existing LiteSVM harness, then read the deposit share calculation and the test setup. Reproduce the sequence with separate liquidity providers and compare the second provider’s minted shares against the proportional limit. Done means later deposits use the stated proportional calculation, zero-share deposits are rejected, and a LiteSVM regression test covers the dilution case.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

accepted

Problem

The Anchor token-swap example calculates LP shares as sqrt(amount_a * amount_b) for every deposit. Once swap fees increase the reserves, that calculation ignores the existing LP supply and can give a later depositor too large a share of the pool, diluting existing providers.

Reproduction

In the existing LiteSVM harness:

  1. Create a pool with a 5% swap fee and deposit 4,000,000 units of each token.
  2. Swap 2,000,000 units of token A for B, growing the pool's reserves through the fee.
  3. Have a second provider deposit up to 1,000,000 units of each token.

The second provider receives 672,292 LP tokens. Based on the actual deposited amounts and the effective existing supply (minted LP supply plus the locked minimum), a proportional deposit supports at most 666,665 LP tokens. The difference reduces the first provider's share of the reserves.

Suggested fix

Keep the geometric-mean calculation for the first deposit. For later deposits, calculate proportional shares from each actual deposited amount and its pre-deposit reserve, using the effective LP supply, and mint the smaller result rounded down. Reject deposits that mint no shares. Add a LiteSVM regression test using separate liquidity providers.

This concerns the educational example's accounting, not a claim about a deployed protocol. I have a tested patch and would like to contribute it.

Lingua principale
Rust
Stelle
1.4k
Fork
559
Merge medio
20h 9m
PR unite (30g)
17

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di solana-foundation/program-examples

Tutte le issue di solana-foundation/program-examples

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.