Skip to content

fix(pool): decrement LPInitialDeposit on withdrawal and add multi-wit…#35

Merged
K1NGD4VID merged 6 commits into
TrusTrove:mainfrom
Ce-Royals:LPInitialDeposit
Jul 3, 2026
Merged

fix(pool): decrement LPInitialDeposit on withdrawal and add multi-wit…#35
K1NGD4VID merged 6 commits into
TrusTrove:mainfrom
Ce-Royals:LPInitialDeposit

Conversation

@Ce-Royals

@Ce-Royals Ce-Royals commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

closes #19

Summary

Fixes an LP withdrawal accounting bug where LPInitialDeposit was not decremented after partial withdrawals. This caused repeated withdrawals to overstate principal, underreport yield, and leave stale initial deposit storage.

What changed

lib.rs

  • Updated withdraw() to decrement LPInitialDeposit by the withdrawn principal portion
  • If the remaining initial deposit becomes zero, the key is removed from persistent storage
  • Preserved TTL handling for remaining storage entries
  • Fixed code formatting to pass cargo fmt

test.rs

  • Added regression test to verify:
    • Two consecutive 50% partial withdrawals
    • Correct LPInitialDeposit decrement after the first withdrawal
    • Removal of the LPInitialDeposit key after full withdrawal
    • Correct yield accounting across repeated withdrawals

Why it matters

Without this fix, repeated partial withdrawals used stale initial deposit values for principal calculations, causing:

  • Inflated principal ratios
  • Zero or incorrect yield reporting
  • Incorrect LP accounting over time

@drips-wave

drips-wave Bot commented Jun 23, 2026

Copy link
Copy Markdown

@Ce-Royals Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@K1NGD4VID

Copy link
Copy Markdown
Contributor

@Ce-Royals fix ci error

@K1NGD4VID

Copy link
Copy Markdown
Contributor

Fix Ci Error @Ce-Royals

- Remove trusttrove_common dependency and persistent_set usage
- Add extend_instance_ttl calls across all contracts
- Escrow: enforce full repayment only, add handle_default with caller auth
- Invoice: remove supported assets feature, emit pool/expiry events
- Pool: remove checked math, update LPInitialDeposit tracking
- Update test snapshots to match new contract behavior
@K1NGD4VID

Copy link
Copy Markdown
Contributor

Please resolve Merge Conflict @Ce-Royals

@K1NGD4VID K1NGD4VID merged commit 46d6ff6 into TrusTrove:main Jul 3, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(pool): LPInitialDeposit is never updated during withdrawal, causing incorrect yield calculation

2 participants