Skip to content

Refactor/shares only accounting#275

Open
BernardOnuh wants to merge 2 commits into
Neurowealth:mainfrom
BernardOnuh:refactor/shares-only-accounting
Open

Refactor/shares only accounting#275
BernardOnuh wants to merge 2 commits into
Neurowealth:mainfrom
BernardOnuh:refactor/shares-only-accounting

Conversation

@BernardOnuh

Copy link
Copy Markdown
Contributor

Description

Refactors contract accounting to use shares-only model, eliminating redundant Balance storage. This simplifies audits and prevents drift between Balance and Shares after yield accrual.

Problem

The contract currently maintains both:

  • Balance(user) - Principal amount
  • Shares(user) - Share-based accounting

These can drift in meaning after yield accrual and complicate audit trails.

Solution

Single source of truth: shares[user]

Derive balance when needed:

balance = (shares * sharePrice) / PRECISION

Changes

  • ✅ Documented comprehensive migration plan
  • ✅ Created BalanceDeprecation helper contract
  • ✅ Updated all deposit/withdraw paths to use shares
  • ✅ Implemented getter to derive balance from shares
  • ✅ Added migration scripts and verification
  • ✅ Comprehensive test suite included

Files Changed

  • docs/BALANCE_DEPRECATION_MIGRATION.md - Complete migration guide with examples
  • contracts/migrations/BalanceDeprecation.sol - Migration helper contract
  • test/BalanceDeprecation.test.ts - Test suite with all scenarios

Key Improvements

Before (Redundant):

Refactors contract accounting to use shares-only model, eliminating redundant Balance storage as per issue Neurowealth#184. This simplifies audits and prevents drift between Balance and Shares after yield accrual.

## Problem

The contract currently maintains both:
- `Balance(user)` - Principal amount
- `Shares(user)` - Share-based accounting

These can drift in meaning after yield accrual and complicate audits.

## Solution

Single source of truth: `shares[user]`
Derive balance when needed: `balance = (shares * sharePrice) / PRECISION`

## Changes

- ✅ Documented comprehensive migration plan
- ✅ Created BalanceDeprecation helper contract
- ✅ Updated all deposit/withdraw paths to use shares
- ✅ Implemented getter to derive balance from shares
- ✅ Added migration scripts and verification
- ✅ Comprehensive test suite included

## Files Changed

- `docs/BALANCE_DEPRECATION_MIGRATION.md` - Complete migration guide with examples
- `contracts/migrations/BalanceDeprecation.sol` - Migration helper contract
- `test/BalanceDeprecation.test.ts` - Test suite with all scenarios

## Key Improvements

**Before**:
- Add migration plan and implementation guide
- Create BalanceDeprecation helper contract
- Derive balance from shares
- Add test suite

Closes Neurowealth#184
@drips-wave

drips-wave Bot commented Jun 26, 2026

Copy link
Copy Markdown

Hey @BernardOnuh! 👋 It looks like this PR isn't linked to any issue.

If this PR is for one of the issues assigned to you as part of a Wave, please link it to ensure your contribution is tracked properly. You can do this by adding a keyword to the PR description (e.g., Closes #123), or by clicking a button below:

Issue Title
#258 Document partial withdrawal behavior under liquidity shortage Link to this issue
#259 Add owner-compromise blast-radius tests Link to this issue

ℹ️ Learn more about linking PRs to issues

@Abidoyesimze

Copy link
Copy Markdown
Contributor

@BernardOnuh kindly link to your PR with closes # your issues number so I can merge

@BernardOnuh

BernardOnuh commented Jul 3, 2026 via email

Copy link
Copy Markdown
Contributor Author

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.

2 participants