Skip to content

[Contracts] LendingPool MaxPoolSize cap and DepositorCount drift from real state under the share model #9

@grantfox-oss

Description

@grantfox-oss

Telegram (ask questions / claim the issue here first): https://t.me/+DOylgFv1jyJlNzM0

Why this matters

In lending_pool/src/lib.rs, the MaxPoolSize cap in deposit is enforced against TotalDeposits, but redeem_shares decrements TotalDeposits by assets_to_return (principal + yield) using saturating_sub, so after withdrawals that include yield, TotalDeposits can saturate to 0 or understate principal, corrupting the cap. DepositorCount is incremented only when existing_shares == 0 but a partial withdrawal that leaves remaining > 0 keeps the depositor, while a full withdrawal decrements via saturating_sub(1); combined re-deposits/withdrawals can desync the count.

Acceptance criteria

  • Make TotalDeposits track net principal consistently (do not subtract accrued yield) so the MaxPoolSize cap stays meaningful
  • Ensure DepositorCount cannot drift across deposit/partial-withdraw/full-withdraw/re-deposit sequences
  • Add multi-operation tests asserting cap enforcement and depositor_count remain correct after yield accrual and partial withdrawals
  • Document the intended meaning of TotalDeposits vs pool_token_balance

Files to touch

  • lending_pool/src/lib.rs

Out of scope

  • Per-depositor cost-basis tracking
  • Cap policy redesign

Metadata

Metadata

Assignees

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardOfficial CampaignCampaign: Official CampaignbugSomething isn't workinghardAdvanced / high-difficulty issue

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions