Skip to content

fix: add quadratic scaling penalty to TimeWeightedVotingPower (#91)#107

Open
Tranquil-Flow wants to merge 4 commits into
mainfrom
fix/91-twvp-scaling
Open

fix: add quadratic scaling penalty to TimeWeightedVotingPower (#91)#107
Tranquil-Flow wants to merge 4 commits into
mainfrom
fix/91-twvp-scaling

Conversation

@Tranquil-Flow
Copy link
Copy Markdown

Summary

  • Adds optional quadratic scaling penalty for flash-loan mitigation in TimeWeightedVotingPower
  • When scalingPeriod > 0, intervals shorter than scalingPeriod receive quadratic penalty: contribution = value * duration^2 / scalingPeriod
  • Adds MAX_SCALING_PERIOD constant (~365 days in blocks) with upper-bound validation
  • Renames votingToken/cycleModule to VOTING_TOKEN/CYCLE_MODULE (immutable naming convention)
  • setScalingPeriod() with owner-only access and event emission
  • NatSpec corrected to match actual penalty formula

Closes #91

Test plan

  • testScalingPeriodDisabledWhenZero — no penalty when scalingPeriod=0
  • testQuadraticPenaltyApplied — 40-block interval with scalingPeriod=100 reduces 100 ETH to 40 ETH
  • testNoPenaltyWhenIntervalExceedsScalingPeriod — no reduction at boundary
  • testScalingPeriodOnlyAffectsShortIntervals — no reduction above boundary
  • testSetScalingPeriodByOwner / testSetScalingPeriodEmitsEvent — admin functions
  • testSetScalingPeriodRevertsNonOwner / testSetScalingPeriodRevertsExceedsMax — access control
  • testFlashLoanMitigatedByScaling — 1000 ETH for 1 block → 10 ETH (100x reduction)
  • Full suite: 191 tests pass

Tranquil-Flow and others added 4 commits April 4, 2026 19:19
Fix time-weighted voting power scaling to use the correct period
denominator, preventing inflated or deflated power values when
the scaling window does not align with cycle boundaries.
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.

Add per-interval linear scaling to TimeWeightedVotingPower

1 participant