Skip to content

[Contract] LendingPool β€” No Share-Based Accounting (Deposit/Withdraw Use Raw Amounts)Β #355

@ogazboiz

Description

@ogazboiz

πŸ’¬ Want to contribute? Join us on Telegram: https://t.me/+DOylgFv1jyJlNzM0

Problem

The LendingPool contract tracks deposits using raw token amounts per depositor. When yield is distributed via distribute_yield(), the total pool balance increases but individual depositor balances don't change until they withdraw.

This creates several issues:

  1. Late depositors dilute early depositors β€” a new deposit after yield distribution gets proportional withdrawal rights without having earned the yield
  2. Yield is socialized incorrectly β€” the test test_subsequent_depositor_does_not_dilute_existing_holders exists but the contract may not correctly handle all edge cases
  3. No share price tracking β€” no way for the frontend to show accurate portfolio value including accrued yield

Expected Behavior

Implement share-based accounting (like ERC-4626 vault pattern):

  • Deposits mint shares based on current share price
  • Withdrawals burn shares and return proportional pool value
  • Share price increases as yield accumulates

Files to Change

  • contracts/lending_pool/src/lib.rs β€” implement share-based deposit/withdraw
  • contracts/lending_pool/src/test.rs β€” update tests for share accounting

Acceptance Criteria

  • deposit() mints shares based on amount / share_price
  • withdraw() burns shares and returns shares * share_price
  • get_share_price() query function returns current price
  • get_shares(provider) returns share balance
  • Yield distribution increases share price, not individual balances
  • All existing tests updated to reflect share-based model

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave program

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions