Skip to content

refactor: use BigInt.pow for PRECISE_PERC_DIVISOR#228

Closed
rickstaa wants to merge 8 commits into
mainfrom
pr-217-suggestions
Closed

refactor: use BigInt.pow for PRECISE_PERC_DIVISOR#228
rickstaa wants to merge 8 commits into
mainfrom
pr-217-suggestions

Conversation

@rickstaa

Copy link
Copy Markdown
Member

Summary

  • Replace BigInt.fromString("1000000000000000000000000000") with BigInt.fromI32(10).pow(27) for PRECISE_PERC_DIVISOR
  • More readable and self-documenting — no risk of miscounting zeros
  • graph-ts BigInt.pow(exp: u8) supports this cleanly; 27 is well within the safe range

Context

Review suggestion for PR #217. Should be merged into that branch before or after #217 lands.

🤖 Generated with Claude Code

adamsoffer and others added 8 commits March 8, 2026 16:51
…cient historical stake computation

Store cumulativeRewardFactor and cumulativeFeeFactor on Pool entity
(matching on-chain PreciseMathUtils), propagate them forward each round,
and introduce a shares field on Delegator that enables O(1) stake lookups
via `stake = shares * crf[round] / 10^27`. DelegatorSnapshot entities
capture state at bond/unbond/rebond events for time-series chart support.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ommission

Tracks the orchestrator's total rewardCut commission across all rounds,
incremented each time reward() is called. Never resets, so clients can
read lifetime earnings in a single field.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ission

Resets Transcoder.cumulativeRewards to zero when the orchestrator claims
earnings, so the field represents pending/unclaimed commission rather
than lifetime total. This lets clients compute full orchestrator pending
stake as: shares * crf / 10^27 + cumulativeRewards

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Separate never-reset counter alongside cumulativeRewards (which resets
on claim). Gives clients a single field for lifetime orchestrator
commission without summing historical claim events.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Rename cumulativeRewards/lifetimeRewards to pendingRewardCommission/
lifetimeRewardCommission for clarity. Add pendingFeeCommission and
lifetimeFeeCommission on Transcoder, computed in WinningTicketRedeemed
handler. Both pending fields reset on claim.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The previous implementation did two divisions (num * 10^27 / denom, then
base * result / 10^27), causing intermediate truncation that compounded
each round in the CRF calculation. Solidity's version does one division
(base * num / denom). While the CRF ratio error cancelled out for
delegator stake, pendingRewardCommission accumulated ~0.23 LPT/round
drift. This fix ensures exact match with the contract.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The contract's cumulativeRewards includes two components: the rewardCut
commission plus rewards earned by the transcoder's own staked commission
(activeCumulativeRewards). The subgraph was only tracking the first.

Add activeCumulativeRewards field on Transcoder, snapshotted from
pendingRewardCommission at the start of each round in newRound. The
reward handler now computes both components matching the contract's
updateTranscoderWithRewards logic. Reset on claim.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…IVISOR

More readable and self-documenting than counting 27 zeros in a string literal.
graph-ts BigInt.pow(exp: u8) supports this cleanly.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

🚀 Subgraph Studio preview deployed

Item Details
Version label pr-228-df4ad49-23537923163
Query endpoint https://api.studio.thegraph.com/query/31909/livepeer-ci/pr-228-df4ad49-23537923163
curl -H 'Content-Type: application/json' \
  -d '{"query":"{ protocol(id: \"0\") { inflation } }"}' \
  https://api.studio.thegraph.com/query/31909/livepeer-ci/pr-228-df4ad49-23537923163

@rickstaa rickstaa closed this Mar 25, 2026
@github-project-automation github-project-automation Bot moved this from Triage to Done in Engineering Roadmap Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects
Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants