Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,8 @@ type Provision @entity(immutable: false) {
delegatedTokens: BigInt!
"Tokens delegated that are thawing from the provision"
delegatedThawingTokens: BigInt!
"Actively-earning delegated tokens: delegatedTokens minus delegatedThawingTokens. This is the correct denominator for delegation APR/APY: it excludes both in-period thawing and completed-but-not-yet-withdrawn delegation, since thawed-but-unwithdrawn tokens remain counted in delegatedThawingTokens until withdrawal. Prefer this over delegatedTokens when computing returns."
delegatedTokensActive: BigInt!
"Total shares of the delegator pool"
delegatorShares: BigInt!
"Exchange rate of tokens received for each share"
Expand Down
2 changes: 2 additions & 0 deletions src/mappings/helpers/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ export function createOrLoadProvision(indexerAddress: Bytes, verifierAddress: By
provision.delegatorShares = BigInt.fromI32(0)
provision.delegationExchangeRate = BigInt.fromI32(0).toBigDecimal()
}
provision.delegatedTokensActive = provision.delegatedTokens.minus(provision.delegatedThawingTokens)
provision.thawingUntil = BigInt.fromI32(0)
provision.ownStakeRatio = BigInt.fromI32(0).toBigDecimal()
provision.delegatedStakeRatio = BigInt.fromI32(0).toBigDecimal()
Expand Down Expand Up @@ -1168,6 +1169,7 @@ export function calculateOverdelegationDilutionForProvision(provision: Provision
}

export function updateAdvancedProvisionMetrics(provision: Provision): Provision {
provision.delegatedTokensActive = provision.delegatedTokens.minus(provision.delegatedThawingTokens)
provision.ownStakeRatio = calculateOwnStakeRatioForProvision(provision as Provision)
provision.delegatedStakeRatio = calculateDelegatedStakeRatioForProvision(provision as Provision)
provision.indexingRewardEffectiveCut = calculateIndexingRewardEffectiveCutForProvision(provision as Provision)
Expand Down
3 changes: 3 additions & 0 deletions src/mappings/horizonStaking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,9 @@ export function handleDelegatedTokensWithdrawn(event: DelegatedTokensWithdrawn):
// might want to track locked/thawing tokens in provision too
provision.delegatedTokens = provision.delegatedTokens.minus(event.params.tokens)
provision.delegatedThawingTokens = provision.delegatedThawingTokens.minus(event.params.tokens)
// Withdrawal removes equal amounts from both totals, so the actively-earning base is unchanged;
// recompute explicitly to keep the field consistent (this handler bypasses updateAdvancedProvisionMetrics).
provision.delegatedTokensActive = provision.delegatedTokens.minus(provision.delegatedThawingTokens)
provision.save()

let indexerID = event.params.serviceProvider.toHexString()
Expand Down
Loading