Fix sub-cent fee rounding in YeetfulStaking (closes #1) - #3
Open
nategeier wants to merge 2 commits into
Open
Conversation
ACC_PRECISION 1e18 was too small: an 18-dec memecoin stake (Flaunch supply ~1e29) against 6-dec USDC meant any sub-$1000 routeFees rounded the per-share increment to zero, stranding the USDC in the vault. Bump to 1e30 and carry the truncation remainder forward across routes so dust accrues instead of stranding. Adds regression tests: a single $0.001 route at 100B supply stays claimable, and 50 non-share-aligned tiny routes accrue losslessly (within 1 micro). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
What
Fixes the High finding from the pre-publish security review (#1): per-call USDC fees rounded to zero and stranded in the vault.
Why
accFeePerShare += amount * ACC_PRECISION / totalStakedwithACC_PRECISION = 1e18is too coarse when the stake token is an 18-dec Flaunch memecoin (~1e29 supply) and the payout is 6-dec USDC at fraction-of-a-cent granularity. At ~1e27 staked, any deposit under ~$1000 rounded the increment to zero, soaccFeePerSharenever moved and the routed USDC piled up unclaimable.Change
ACC_PRECISION1e18 → 1e30 — keeps even a 1-micro-USDC route non-zero at full supply.feeRemainder: carry the truncation remainder (scaled USDC) into the next route's numerator so dust accrues across routes instead of stranding. The matching USDC stays in the contract until it converts — solvency preserved.staked * accFeePerSharereconstructsearned * 1e30, bounded by total-routed-USDC × 1e30 ≪ 2^256.Tests (19/19 green)
test_subCentFee_atFullSupply_notStranded— a single $0.001 route against a 100B (1e29) stake stays fully claimable (was 0 under 1e18).test_remainderCarry_losslessOverManyRoutes— 50 non-share-aligned tiny routes accrue losslessly (within 1 micro).Also renames the README H1 to match the
Yeetful/contractsrepo name (separate commit).Medium finding #2 (permissionless
launch()) is left as a separate issue per the publish plan.Closes #1