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
Tech Stack
contracts/pool/src/lib.rs function withdraw (lines 238-317)
Summary
The
withdrawfunction atcontracts/pool/src/lib.rs:290-293tracks 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
Where
init_depis 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 = 200butlp_shares = 166. A partial withdrawal of 50 shares computesprincipal_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
Tech Stack
contracts/pool/src/lib.rsfunctionwithdraw(lines 238-317)