Refactor/shares only accounting#275
Open
BernardOnuh wants to merge 2 commits into
Open
Conversation
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
|
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.,
|
Contributor
|
@BernardOnuh kindly link to your PR with closes # your issues number so I can merge |
Contributor
Author
|
Alright working on it now
…On Fri, 3 Jul 2026 at 09:17, Similoluwa Abidoye ***@***.***> wrote:
*Abidoyesimze* left a comment (Neurowealth/NeuroWealth-Smartcontract#275)
<#275 (comment)>
@BernardOnuh <https://github.com/BernardOnuh> kindly link to your PR with
closes # your issues number so I can merge
—
Reply to this email directly, view it on GitHub
<#275?email_source=notifications&email_token=A3JPVVVKHP72XJPDPYETK4L5C5TX7A5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTIOBXGQZDEMJXGQZ2M4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJLDGN5XXIZLSL5RWY2LDNM#issuecomment-4874221743>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/A3JPVVUPCTQPFQXGQA3F5E35C5TX7AVCNFSNUABGKJSXA33TNF2G64TZHMYTCNRUHA3TANZQGY5US43TOVSTWNBXGU2TMNJQGE4TNILWAI>
.
Triage notifications, keep track of coding agent tasks and review pull
requests on the go with GitHub Mobile for iOS
<https://github.com/notifications/mobile/ios/A3JPVVWGXVXQKBE45JAY2XT5C5TX7A5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTIOBXGQZDEMJXGQZ2M4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJKTGN5XXIZLSL5UW64Y>
and Android
<https://github.com/notifications/mobile/android/A3JPVVWJJ4Z7HWYS5A45SRT5C5TX7A5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTIOBXGQZDEMJXGQZ2M4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJLTGN5XXIZLSL5QW4ZDSN5UWI>.
Download it today!
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 amountShares(user)- Share-based accountingThese can drift in meaning after yield accrual and complicate audit trails.
Solution
Single source of truth:
shares[user]Derive balance when needed:
Changes
Files Changed
docs/BALANCE_DEPRECATION_MIGRATION.md- Complete migration guide with examplescontracts/migrations/BalanceDeprecation.sol- Migration helper contracttest/BalanceDeprecation.test.ts- Test suite with all scenariosKey Improvements
Before (Redundant):