Skip to content

Conversation

@youngkidwarrior
Copy link
Collaborator

Extracted duplicated fixed pool calculation logic from distributorv2.ts
into shared helper functions in fixed-pool-calculation.ts. This enables
both backend distributor and frontend UI to use the same calculation
logic, ensuring consistency.

Where:

  • Created apps/distributor/src/fixed-pool-calculation.ts
    • calculateMultiplier: handles verification type multiplier logic
    • calculateCombinedMultiplier: combines multiple multipliers
    • calculateSlashPercentage: calculates progress/slash percentage
    • calculateBaseFixedAmount, calculateFixedPoolAmount helpers
  • Refactored apps/distributor/src/distributorv2.ts to use new helpers
  • Updated packages/app/features/rewards/activity/screen.tsx ProgressCard
    to use calculateSlashPercentage ensuring UI matches backend
  • Added verified_count to fetchDistributions query (distributions.ts)
    to support future percentile calculations

Why:
Fixed pool calculation logic was duplicated between distributorv2.ts
(lines 602-660) and UI approximations. Pure functions enable code reuse
and guarantee backend and frontend calculate identically.

Pattern from: apps/distributor/src/weights.ts calculatePercentageWithBips

Test plan:

  • npm run distributor:dev
    Expected: Distribution output identical to previous run
  • Verify ProgressCard displays slash percentage matching distributor logs
  • npm run biome:check apps/distributor/src/fixed-pool-calculation.ts
    Expected: No errors

Extracted duplicated fixed pool calculation logic from distributorv2.ts
into shared helper functions in fixed-pool-calculation.ts. This enables
both backend distributor and frontend UI to use the same calculation
logic, ensuring consistency.

Where:
- Created apps/distributor/src/fixed-pool-calculation.ts
  - calculateMultiplier: handles verification type multiplier logic
  - calculateCombinedMultiplier: combines multiple multipliers
  - calculateSlashPercentage: calculates progress/slash percentage
  - calculateBaseFixedAmount, calculateFixedPoolAmount helpers
- Refactored apps/distributor/src/distributorv2.ts to use new helpers
- Updated packages/app/features/rewards/activity/screen.tsx ProgressCard
  to use calculateSlashPercentage ensuring UI matches backend
- Added verified_count to fetchDistributions query (distributions.ts)
  to support future percentile calculations

Why:
Fixed pool calculation logic was duplicated between distributorv2.ts
(lines 602-660) and UI approximations. Pure functions enable code reuse
and guarantee backend and frontend calculate identically.

Pattern from: apps/distributor/src/weights.ts calculatePercentageWithBips

Test plan:
- npm run distributor:dev
  Expected: Distribution output identical to previous run
- Verify ProgressCard displays slash percentage matching distributor logs
- npm run biome:check apps/distributor/src/fixed-pool-calculation.ts
  Expected: No errors
Copy link
Collaborator Author

youngkidwarrior commented Dec 30, 2025

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.

2 participants