Skip to content

bug(pool): withdraw yield calculation uses single cumulative LPInitialDeposit, inaccurate for multi-deposit LPs #442

Description

@K1NGD4VID

Summary

The withdraw function at contracts/pool/src/lib.rs:290-293 tracks LP principal as a single cumulative value (LPInitialDeposit) rather than per-deposit basis. For LPs who have made multiple deposits at different share prices, a partial withdrawal computes an incorrect principal portion and yield.

Current Behavior

let principal_portion = shares * init_dep / (lp_shares);
let yield_earned = usdc_to_return.saturating_sub(principal_portion);

Where init_dep is the sum of all deposits this LP ever made. For an LP depositing 100 at share price 1.0 and 100 at share price 1.5, init_dep = 200 but lp_shares = 166. A partial withdrawal of 50 shares computes principal_portion = 50 * 200 / 166 = 60, overstating principal and understating yield.

Expected Behavior

Track per-deposit lots (FIFO or HIFO) for accurate yield calculation, or clearly document the approximation and its limitations.

Acceptance Criteria

  • Analysis of the impact on multi-deposit LPs
  • Either fix the calculation or document the limitation
  • Tests demonstrate the error margin for realistic multi-deposit scenarios

Tech Stack

contracts/pool/src/lib.rs function withdraw (lines 238-317)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions