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

オープン
#783 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@Bismithblde がすでに取り組んでいます。

2026年11月5日 から。

  • #784 @Bismithblde による — マージされずにクローズ
  • #789 @Bismithblde による — オープン

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
rust

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Rust
スター
1.4k
フォーク
559
平均マージ
20時間 9分
マージ済み PR(30日)
17

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

solana-foundation/program-examples のほかの issue

solana-foundation/program-examples の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。