Skip to content

Linear Fee Drip System (resolves M-01, L-02)#20

Closed
mzhakun wants to merge 103 commits intomainfrom
drip-system
Closed

Linear Fee Drip System (resolves M-01, L-02)#20
mzhakun wants to merge 103 commits intomainfrom
drip-system

Conversation

@mzhakun
Copy link
Copy Markdown
Collaborator

@mzhakun mzhakun commented Mar 16, 2026

Linear Fee Drip System (resolves M-01, L-02)

  • Linear fee drip — exit fees are no longer added to totalPooledRnbw instantly. They accumulate in undistributedFees and drip linearly into the pool over dripDuration (default 7 days), producing a smooth exchange rate curve
  • _syncPool() settles accrued drip before every state-changing operation
  • _effectivePooledRnbw() view helper ensures frontend shows accurate exchange rate including pending drip
  • Overlapping drips are combined: remaining undistributed fees + new fee, fresh drip window
  • setDripDuration() admin function with bounds checking, syncs and recalculates active drip mid-stream
  • emergencyWithdraw and residual sweep account for undistributedFees
  • Interface updated with DripDurationTooLow, DripDurationTooHigh errors and setDripDuration() declaration

mzhakun and others added 19 commits March 3, 2026 17:28
…ature' into @mzhakun/add-stake-for-with-signature

# Conflicts:
#	test/RNBWStaking.t.sol
- stakeForWithSignature now uses pre-funded stakingReserve (no funder param)
- Added staking reserve to Key Mechanics table
- Updated Security Features with staking reserve protection
- Fixed emergencyWithdraw docs to include all three reserves
- Updated wind-down procedure (pause ≠ wind-down)
- Updated defund functions for both reserves
- Updated xRNBW future integration section
- Renamed test_StakeForWithSignatureNonceIndependentFromCashback to
  test_StakeForWithSignatureSharedNonceDifferentUsers (accurate name)
- Added test_StakeForWithSignatureSharedNonceSameUserCollides to validate
  the collision path when same address uses same nonce for both operations
- Documented shared nonce behavior in README with recommended nonce range
  strategy (cashback: 0-999999, stakeFor: 1000000+)
…erve

Share calculation, dead-share logic, metadata tracking, and event
emission are now in a single _mintShares(user, amount) helper.
_stake handles token transfer then calls _mintShares.
_stakeFromReserve deducts from stakingReserve then calls _mintShares.
- Custom Errors: BelowMinimumStake thrown in _stake + _stakeFromReserve,
  ZeroSharesMinted thrown in _mintShares (post-refactor)
- Security Features: recipient guards apply to both stakeFor and
  stakeForWithSignature
- Cashback reserve recovery: reference defundCashbackReserve() instead
  of emergencyWithdraw (which only recovers excess)
Replace instant exit fee distribution with linear drip over configurable
dripDuration (default 7 days, bounds 7-60 days). Exit fees accumulate in
undistributedFees and drip into totalPooledRnbw via _syncPool(), called
before every state-changing operation. View functions use
_effectivePooledRnbw() to reflect pending drip without mutating state.

Resolves whale self-absorption (M-01) and APY manipulation (L-02).
Add 12 drip-specific tests covering linear distribution, overlapping
fees, view function accuracy, residual sweep, self-absorption prevention,
and configurable duration. Update 6 existing tests for delayed fee
settlement. Add RNBWStakingHarness for internal _syncPool access.
Update invariant tests to include undistributedFees in accounting.
@mzhakun mzhakun marked this pull request as draft March 16, 2026 08:23
@mzhakun mzhakun marked this pull request as ready for review March 16, 2026 15:37
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.

1 participant