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

Abierto
#783 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@Bismithblde ya está trabajando en esto.

Desde el 5/11/2026.

  • #784 de @Bismithblde — cerrado sin fusionar
  • #789 de @Bismithblde — abierto

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
45/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
rust

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Rust
Estrellas
1.4k
Forks
559
Merge medio
20 h 9 min
PR fusionados (30 d)
17

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de solana-foundation/program-examples

Todos los issues de solana-foundation/program-examples

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.