Repository navigation
fix(portfolio): compute stake, rewards and fees as the contract does - #892
Open
adamsoffer wants to merge 2 commits into
Open
adamsoffer wants to merge 2 commits into
adamsoffer wants to merge 2 commits into
Conversation
Subgraph `shares` can't represent a claim made before the orchestrator's reward() call, which forfeits that round's reward, so stake and reward history counted it. Use the contract's formula instead: the stake bonded at the last claim, grown by the round-final cumulative factors, in wei with its rounding. - Order each claim against the old delegate's reward call by block and log index, and count no reward for a claim that came first. - Take a claim round's fees from what the claim event says it paid. - Rebuild the snapshot of a claim on deployments that don't write one. - Reset an orchestrator's commission only on its own claims, and count what staked commission earned in a round claimed after its reward call. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Fees earned by staked reward commission are omitted from total fees, understating historical earnings and trailingFeeRate.
1 open issue
What changed in this PR
This PR replaces share-based estimates with contract-style calculations for portfolio stake, rewards, fees, and orchestrator delegator balances.
Changes:
- Uses bonded amounts and cumulative factors with BigInt rounding.
- Orders claims against reward calls, reconstructs missing claim snapshots, and updates commission accounting.
- Updates subgraph queries, mock data, documentation, and regression tests.
| File | Description |
|---|---|
scripts/mock/server.mjs |
Adds claim and reward-call resolvers; updates delegator responses. |
scripts/mock/README.md |
Updates the fixture description. |
scripts/mock/fixtures.mjs |
Adds self-claim events to mock data. |
README.md |
Documents contract-style formulas and claim timing. |
lib/subgraph/portfolio.ts |
Fetches earnings claims and reward-call ordering data; removes shares. |
lib/subgraph/portfolio.test.ts |
Tests parsing event ordering information. |
lib/subgraph/network.ts |
Uses contract-style stake calculations for delegator lists. |
lib/portfolio/pre-claim.ts |
Represents migration history using bonded amounts. |
lib/portfolio/pre-claim.test.ts |
Adapts migration tests to bonded positions. |
lib/portfolio/compute.ts |
Implements factor-based calculations and claim-aware history. |
lib/portfolio/compute.test.ts |
Expands coverage for claim timing, fees, commissions, and rounding. |
lib/config.ts |
Updates documentation of required subgraph fields. |
Review effort: Balanced
Only the fee cut was counted in an orchestrator's fee history, not what its unclaimed reward commission earned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
Exact financial balances depend on unverified deployment of subgraph rounding commit 88bb219, and live multi-wallet portfolio and orchestrator-page checks remain outstanding.
No open issues 🎉
1 resolved since last review
Review effort: Balanced
This branch was successfully deployed
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.

Problem
Stake and reward history were computed from the subgraph's
shares, which is an approximation. If a delegator claims before their orchestrator'sreward()call in a round, the contract forfeits that round's reward for them, butsharesdoesn't reflect it, so the explorer still counted it. Bonding, unbonding and rebonding also claim first.Example: 100 LPT, +10% in rounds 11 and 12, claimed in round 11 before reward. The contract says 110 and no round-11 reward; the explorer showed 121 and 10.
This came out of review on livepeer/subgraph#217: @jmulq pointed out that
sharesrounds in a different order thanpendingStake(), and suggested using the bonded amount and starting factor instead. Following up showed the difference can be more than rounding: a claim beforereward()overstates stake by that round's reward.Example
0x6Ac5…2CeEclaimed before its orchestrator's reward call in rounds 3867, 3868, 3922 and 3926, so the contract didn't pay it those four rounds' rewards. It hasn't bonded, unbonded or rebonded since, so nothing recomputed itsshares, and beta still counts them.pendingStake()0x6Ac5…2CeE0x353e…C7D60x5B5d…1190Values are the pages' unrounded stake in round 4423, to four decimals; the app displays fewer.
A scan of Arbitrum's claim history (410 ordinary claims before reward) found 12 wallets in this position. More wallets are affected in reward history, which a later bond doesn't correct.
Changes
sharesis no longer queried.Verification
pendingStakeandpendingFees: 80 of 80 delegators match to the wei (39 self-delegated; 2 whose last claim was before reward).Before merging
pendingStake()to four decimals.0x6Ac5…2CeE,0x5B5d…1190) still matchpendingStake()to the wei; a very large stake could be off by a few wei until it's deployed.Known limits
🤖 Generated with Claude Code