-
Notifications
You must be signed in to change notification settings - Fork 262
Accounting integration test improvements #1572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rkolpakov
wants to merge
1
commit into
develop
Choose a base branch
from
fix/accounting-integration-test-fixes
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
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
Hardhat Unit Tests Coverage SummaryDiff against masterResults for commit: 7f3c3a6 Minimum allowed coverage is ♻️ This comment has been updated with latest results |
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.
Enhanced accounting integration tests.
Context
The accounting integration tests validate Lido's rebase mechanism and fee distribution logic. These tests ensure that share rate calculations, fee distribution between staking modules and treasury, and share minting/burning operations work correctly after each oracle report.
Problem
Fee distribution validation (TODO: check math, why it's not equal?)**
Previously:
The commented-out code attempted to verify:
Why this was not fully correct:
Now:
Check 1: All shares accounted
Check 2: Treasury received exact remainder (Accounting.sol:325)
Check 3: Each module received proportional share (Accounting.sol:319)
Test setup and actual calculations
Staking modules configuration (from scripts/scratch/steps/0140-plug-staking-modules.ts):
Fee distribution calculation:
Step 1: Calculate totalFee (weighted by validators)
NOR contribution: 96.15% × (5% + 5%) = 9.615%
SDVT contribution: 3.85% × (8% + 2%) = 0.385%
────────────────────────────────────────────────
totalFee = 10.0%
Step 2: Calculate module fees (only stakingModuleFee)
NOR module fee: 96.15% × 5% = 4.808%
SDVT module fee: 3.85% × 8% = 0.308%
──────────────────────────────────────
sum(moduleFees) = 5.116%
Step 3: Calculate treasury fee (remainder)
treasuryFee = totalFee - sum(moduleFees)
= 10.0% - 5.116%
= 4.884%
Verification (sum of configured treasury fees):
NOR treasury: 96.15% × 5% = 4.808%
SDVT treasury: 3.85% × 2% = 0.077%
─────────────────────────────────────
Expected = 4.885% ≈ 4.884% ✓
Solution
Replaced incorrect fee distribution check with proper validation
Instead of the incorrect assumption that treasury and module fees should be equal, added two helper functions that validate the actual protocol invariants:
validateTreasuryReceivedRemainder() - validates Accounting.sol:325:
treasurySharesToMint = totalSharesToMintAsFees - sum(moduleSharesToMint)
validateModuleFeeProportions() - validates Accounting.sol:319:
moduleFeeShares[i] = (totalSharesToMintAsFees × moduleFee[i]) / totalFee
These checks guarantee: