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

Đang mở
#783 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@Bismithblde đang làm issue này rồi.

Từ ngày 5/11/2026.

  • #784 của @Bismithblde — đã đóng, không merge
  • #789 của @Bismithblde — đang mở

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
rust
Lĩnh vực
blockchain, databases

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Rust
Star
1.4k
Fork
559
Merge trung bình
20 giờ 9 phút
Pull request đã merge (30 ngày)
17

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của solana-foundation/program-examples

Tất cả issue của solana-foundation/program-examples

Issue tương tự

Thêm issue về Rust

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.