-
Notifications
You must be signed in to change notification settings - Fork 5
Description
Problem Description
Currently, the bondedAmount field in the Livepeer subgraph accurately reflects a delegator’s or orchestrator’s bonded stake as of the last explicit bonding transaction (Bond, Unbond, Rebond, TransferBond). However, it does not include unclaimed rewards, which can lead to discrepancies when comparing with on-chain views (e.g., Arbiscan).
Example:
- Subgraph
bondedAmount:1.002563476329049571LPT - On-chain actual stake:
2.536529849800865LPT
This difference arises because the bondedAmount is static and does not dynamically include accumulated but unclaimed rewards.
While the bondedAmount is correct, users and applications often need to display the total effective stake (i.e., bonded amount plus pending rewards) to match what is visible on-chain.
Proposed Solution
Introduce a new field, pendingStake, in the subgraph, only for transcoders (orchestrators). This field will represent the total stake for the orchestrator, including unclaimed rewards.
It is not feasible to add pendingStake for delegators, as individual delegator pending stake is tracked internally in BondingManager and is not available from emitted events.
Implementation Plan
-
Schema Update
Add a
pendingStakefield to theTranscoderentity:type Transcoder @entity { id: ID! totalStake: BigDecimal! bondedAmount: BigDecimal! pendingStake: BigDecimal! # New field ... }
-
Reward Event Handling
Update the
Rewardevent handler to calculate and updatependingStakefor the transcoder.// src/mappings/bondingManager.ts export function reward(event: Reward): void { let transcoder = Transcoder.load(event.params.transcoder.toHex()); if (!transcoder) return; let bondingManager = BondingManager.bind(event.address); // Compute transcoder pending stake let transcoderPendingStake = convertToDecimal( bondingManager.pendingStake( Address.fromString(transcoder.id), event.params.round ) ); transcoder.pendingStake = transcoderPendingStake; transcoder.save(); }
-
GraphQL Query Example
Users can then query the orchestrator’s
bondedAmountandpendingStake:{ transcoder(id: "0x5bdeedca9c6346b0ce6b17ffa8227a4dace37039") { bondedAmount pendingStake } } -
Testing and Validation
- Ensure
pendingStakeupdates correctly whenRewardevents are triggered. - Validate against on-chain values (e.g., Arbiscan) for orchestrators.
- Ensure
Benefits
- Accurate Display: Provides a real-time view of an orchestrator’s effective total stake.
- Improved Transparency: Aligns subgraph data with on-chain reality for orchestrators.
- Minimal Overhead: Builds on existing reward event handling logic already in place.