diff --git a/schema.graphql b/schema.graphql index 2a4539db..57b5596c 100644 --- a/schema.graphql +++ b/schema.graphql @@ -769,8 +769,10 @@ type Indexer @entity(immutable: false) { indexerIndexingRewards: BigInt! "The total amount of indexing rewards given to delegators" delegatorIndexingRewards: BigInt! - "Percentage of indexers' own rewards received in relation to its own stake. 1 (100%) means that the indexer is receiving the exact amount that is generated by his own stake" + "[Horizon only] Percentage of indexers' own rewards received in relation to its own stake. 1 (100%) means that the indexer is receiving the exact amount that is generated by his own stake" indexerRewardsOwnGenerationRatio: BigDecimal! + "Percentage of indexers' own rewards received in relation to its own stake. 1 (100%) means that the indexer is receiving the exact amount that is generated by his own stake. This is the indexerRewardsOwnGenerationRatio before Horizon" + legacyIndexerRewardsOwnGenerationRatio: BigDecimal! "Whether the indexer has been transferred from L1 to L2 partially or fully" transferredToL2: Boolean! "Timestamp for the FIRST L1 -> L2 Transfer" @@ -813,18 +815,26 @@ type Indexer @entity(immutable: false) { delegatorShares: BigInt! "Exchange rate of of tokens received for each share" delegationExchangeRate: BigDecimal! - "The percent of indexing rewards generated by the total stake that the Indexer keeps for itself. In parts per million" + "[Horizon only] The percent of indexing rewards generated by the total stake that the Indexer keeps for itself. In parts per million" indexingRewardCut: Int! - "The percent of indexing rewards generated by the delegated stake that the Indexer keeps for itself" + "The percent of indexing rewards generated by the total stake that the Indexer keeps for itself. In parts per million. This is the indexingRewardCut before Horizon" + legacyIndexingRewardCut: Int! + "[Horizon only] The percent of indexing rewards generated by the delegated stake that the Indexer keeps for itself" indexingRewardEffectiveCut: BigDecimal! + "The percent of indexing rewards generated by the delegated stake that the Indexer keeps for itself. This is the indexingRewardEffectiveCut before Horizon" + legacyIndexingRewardEffectiveCut: BigDecimal! "The percent of reward dilution delegators experience because of overdelegation. Overdelegated stake can't be used to generate rewards but still gets accounted while distributing the generated rewards. This causes dilution of the rewards for the rest of the pool." overDelegationDilution: BigDecimal! "The total amount of query fees given to delegators" delegatorQueryFees: BigInt! - "The percent of query rebate rewards the Indexer keeps for itself. In parts per million" + "[Horizon only] The percent of query rebate rewards generated by the total stake that the Indexer keeps for itself. In parts per million" queryFeeCut: Int! - "The percent of query rebate rewards generated by the delegated stake that the Indexer keeps for itself" + "The percent of query rebate rewards generated by the total stake that the Indexer keeps for itself. In parts per million. This is the queryFeeCut before Horizon" + legacyQueryFeeCut: Int! + "[Horizon only] The percent of query rebate rewards generated by the delegated stake that the Indexer keeps for itself" queryFeeEffectiveCut: BigDecimal! + "The percent of query rebate rewards generated by the delegated stake that the Indexer keeps for itself. This is the queryFeeEffectiveCut before Horizon" + legacyQueryFeeEffectiveCut: BigDecimal! "Amount of blocks a delegator chooses for the waiting period for changing their params" delegatorParameterCooldown: Int! "Block number for the last time the delegator updated their parameters" @@ -834,14 +844,6 @@ type Indexer @entity(immutable: false) { # Provisioning provisions: [Provision!]! @derivedFrom(field: "indexer") - - # Metrics - "NOT IMPLEMENTED - Total return this indexer has earned" - totalReturn: BigDecimal! - "NOT IMPLEMENTED - Annualized rate of return for the indexer" - annualizedReturn: BigDecimal! # You must multiple by 100 to get percentage - "NOT IMPLEMENTED - Staking efficiency of the indexer" - stakingEfficiency: BigDecimal! } type PaymentSource @entity(immutable: false) { diff --git a/src/mappings/helpers/helpers.ts b/src/mappings/helpers/helpers.ts index 00f969e5..64412e9e 100644 --- a/src/mappings/helpers/helpers.ts +++ b/src/mappings/helpers/helpers.ts @@ -153,6 +153,7 @@ export function createOrLoadIndexer(indexerAddress: Bytes, timestamp: BigInt ): indexer.queryFeeRebates = BigInt.fromI32(0) indexer.rewardsEarned = BigInt.fromI32(0) indexer.indexerRewardsOwnGenerationRatio = BigDecimal.fromString('0') + indexer.legacyIndexerRewardsOwnGenerationRatio = BigDecimal.fromString('0') indexer.delegatedCapacity = BigInt.fromI32(0) indexer.tokenCapacity = BigInt.fromI32(0) @@ -163,24 +164,24 @@ export function createOrLoadIndexer(indexerAddress: Bytes, timestamp: BigInt ): indexer.delegatedStakeRatio = BigDecimal.fromString('0') indexer.delegatorShares = BigInt.fromI32(0) indexer.delegationExchangeRate = BigDecimal.fromString('1') - indexer.indexingRewardCut = 0 + indexer.indexingRewardCut = 1000000 indexer.indexingRewardEffectiveCut = BigDecimal.fromString('0') + indexer.legacyIndexingRewardCut = 0 + indexer.legacyIndexingRewardEffectiveCut = BigDecimal.fromString('0') indexer.overDelegationDilution = BigDecimal.fromString('0') indexer.delegatorIndexingRewards = BigInt.fromI32(0) indexer.indexerIndexingRewards = BigInt.fromI32(0) indexer.delegatorQueryFees = BigInt.fromI32(0) - indexer.queryFeeCut = 0 + indexer.queryFeeCut = 1000000 indexer.queryFeeEffectiveCut = BigDecimal.fromString('0') + indexer.legacyQueryFeeCut = 0 + indexer.legacyQueryFeeEffectiveCut = BigDecimal.fromString('0') indexer.delegatorParameterCooldown = 0 indexer.lastDelegationParameterUpdate = 0 indexer.forcedClosures = 0 indexer.allocationCount = 0 indexer.totalAllocationCount = BigInt.fromI32(0) - indexer.totalReturn = BigDecimal.fromString('0') - indexer.annualizedReturn = BigDecimal.fromString('0') - indexer.stakingEfficiency = BigDecimal.fromString('0') - indexer.url = '' indexer.geoHash = '' indexer.rewardsDestination = Address.fromString('0x0000000000000000000000000000000000000000') @@ -226,9 +227,9 @@ export function createOrLoadProvision(indexerAddress: Bytes, verifierAddress: By provision.maxVerifierCutPending = BigInt.fromI32(0) provision.thawingPeriod = BigInt.fromI32(0) provision.thawingPeriodPending = BigInt.fromI32(0) - provision.queryFeeCut = BigInt.fromI32(0) - provision.indexingFeeCut = BigInt.fromI32(0) - provision.indexingRewardsCut = BigInt.fromI32(0) + provision.queryFeeCut = BigInt.fromI32(1000000) + provision.indexingFeeCut = BigInt.fromI32(1000000) + provision.indexingRewardsCut = BigInt.fromI32(1000000) provision.indexingRewardEffectiveCut = BigInt.fromI32(0).toBigDecimal() provision.queryFeeEffectiveCut = BigInt.fromI32(0).toBigDecimal() provision.overDelegationDilution = BigInt.fromI32(0).toBigDecimal() @@ -956,17 +957,14 @@ export function calculateDelegatedStakeRatio(indexer: Indexer): BigDecimal { } export function calculateIndexingRewardEffectiveCut(indexer: Indexer): BigDecimal { - let delegatorCut = - BigInt.fromI32(1000000 - indexer.indexingRewardCut).toBigDecimal() / - BigDecimal.fromString('1000000') + let delegatorCut = BigInt.fromI32(indexer.indexingRewardCut).toBigDecimal() / BigDecimal.fromString('1000000') return indexer.delegatedStakeRatio == BigDecimal.fromString('0') ? BigDecimal.fromString('0') : BigDecimal.fromString('1') - delegatorCut / indexer.delegatedStakeRatio } export function calculateQueryFeeEffectiveCut(indexer: Indexer): BigDecimal { - let delegatorCut = - BigInt.fromI32(1000000 - indexer.queryFeeCut).toBigDecimal() / BigDecimal.fromString('1000000') + let delegatorCut = BigInt.fromI32(indexer.queryFeeCut).toBigDecimal() / BigDecimal.fromString('1000000') return indexer.delegatedStakeRatio == BigDecimal.fromString('0') ? BigDecimal.fromString('0') : BigDecimal.fromString('1') - delegatorCut / indexer.delegatedStakeRatio @@ -974,7 +972,29 @@ export function calculateQueryFeeEffectiveCut(indexer: Indexer): BigDecimal { export function calculateIndexerRewardOwnGenerationRatio(indexer: Indexer): BigDecimal { let rewardCut = - BigInt.fromI32(indexer.indexingRewardCut).toBigDecimal() / BigDecimal.fromString('1000000') + BigInt.fromI32(1000000 -indexer.indexingRewardCut).toBigDecimal() / BigDecimal.fromString('1000000') + return indexer.ownStakeRatio == BigDecimal.fromString('0') + ? BigDecimal.fromString('0') + : rewardCut / indexer.ownStakeRatio +} + +export function calculateLegacyIndexingRewardEffectiveCut(indexer: Indexer): BigDecimal { + let delegatorCut = BigInt.fromI32(indexer.legacyIndexingRewardCut).toBigDecimal() / BigDecimal.fromString('1000000') + return indexer.delegatedStakeRatio == BigDecimal.fromString('0') + ? BigDecimal.fromString('0') + : BigDecimal.fromString('1') - delegatorCut / indexer.delegatedStakeRatio +} + +export function calculateLegacyQueryFeeEffectiveCut(indexer: Indexer): BigDecimal { + let delegatorCut = BigInt.fromI32(indexer.legacyQueryFeeCut).toBigDecimal() / BigDecimal.fromString('1000000') + return indexer.delegatedStakeRatio == BigDecimal.fromString('0') + ? BigDecimal.fromString('0') + : BigDecimal.fromString('1') - delegatorCut / indexer.delegatedStakeRatio +} + +export function calculateLegacyIndexerRewardOwnGenerationRatio(indexer: Indexer): BigDecimal { + let rewardCut = + BigInt.fromI32(1000000 - indexer.legacyIndexingRewardCut).toBigDecimal() / BigDecimal.fromString('1000000') return indexer.ownStakeRatio == BigDecimal.fromString('0') ? BigDecimal.fromString('0') : rewardCut / indexer.ownStakeRatio @@ -1004,6 +1024,18 @@ export function updateAdvancedIndexerMetrics(indexer: Indexer): Indexer { return indexer as Indexer } +export function updateLegacyAdvancedIndexerMetrics(indexer: Indexer): Indexer { + indexer.ownStakeRatio = calculateOwnStakeRatio(indexer as Indexer) + indexer.delegatedStakeRatio = calculateDelegatedStakeRatio(indexer as Indexer) + indexer.legacyIndexingRewardEffectiveCut = calculateLegacyIndexingRewardEffectiveCut(indexer as Indexer) + indexer.legacyQueryFeeEffectiveCut = calculateLegacyQueryFeeEffectiveCut(indexer as Indexer) + indexer.legacyIndexerRewardsOwnGenerationRatio = calculateLegacyIndexerRewardOwnGenerationRatio( + indexer as Indexer, + ) + indexer.overDelegationDilution = calculateOverdelegationDilution(indexer as Indexer) + return indexer as Indexer +} + export function calculateOwnStakeRatioForProvision(provision: Provision): BigDecimal { let totalTokens = provision.tokensProvisioned.plus(provision.delegatedTokens) return totalTokens == BigInt.fromI32(0) @@ -1020,7 +1052,7 @@ export function calculateDelegatedStakeRatioForProvision(provision: Provision): export function calculateIndexingRewardEffectiveCutForProvision(provision: Provision): BigDecimal { let delegatorCut = - provision.indexingRewardsCut.toBigDecimal() / + BigInt.fromI32(1000000).minus(provision.indexingRewardsCut).toBigDecimal() / BigDecimal.fromString('1000000') return provision.delegatedStakeRatio == BigDecimal.fromString('0') ? BigDecimal.fromString('0') @@ -1029,7 +1061,8 @@ export function calculateIndexingRewardEffectiveCutForProvision(provision: Provi export function calculateQueryFeeEffectiveCutForProvision(provision: Provision): BigDecimal { let delegatorCut = - provision.queryFeeCut.toBigDecimal() / BigDecimal.fromString('1000000') + BigInt.fromI32(1000000).minus(provision.queryFeeCut).toBigDecimal() / + BigDecimal.fromString('1000000') return provision.delegatedStakeRatio == BigDecimal.fromString('0') ? BigDecimal.fromString('0') : BigDecimal.fromString('1') - delegatorCut / provision.delegatedStakeRatio @@ -1037,7 +1070,8 @@ export function calculateQueryFeeEffectiveCutForProvision(provision: Provision): export function calculateIndexerRewardOwnGenerationRatioForProvision(provision: Provision): BigDecimal { let delegatorCut = - provision.indexingRewardsCut.toBigDecimal() / BigDecimal.fromString('1000000') + BigInt.fromI32(1000000).minus(provision.indexingRewardsCut).toBigDecimal() / + BigDecimal.fromString('1000000') return provision.ownStakeRatio == BigDecimal.fromString('0') ? BigDecimal.fromString('0') : (BigDecimal.fromString('1') - delegatorCut) / provision.ownStakeRatio @@ -1215,7 +1249,7 @@ export function batchUpdateSubgraphSignalledTokens(deployment: SubgraphDeploymen } } -export function convertBigIntSubgraphIDToBase58(bigIntRepresentation: BigInt): String { +export function convertBigIntSubgraphIDToBase58(bigIntRepresentation: BigInt): string { // Might need to unpad the BigInt since `fromUnsignedBytes` pads one byte with a zero. // Although for the events where the uint256 is provided, we probably don't need to unpad. let hexString = bigIntRepresentation.toHexString() diff --git a/src/mappings/horizonStaking.ts b/src/mappings/horizonStaking.ts index 1dee16e5..2c97e792 100644 --- a/src/mappings/horizonStaking.ts +++ b/src/mappings/horizonStaking.ts @@ -218,10 +218,21 @@ export function handleOperatorSet(event: OperatorSet): void { export function handleDelegationFeeCutSet(event: DelegationFeeCutSet): void { let provision = createOrLoadProvision(event.params.serviceProvider, event.params.verifier, event.block.timestamp) - provision.queryFeeCut = event.params.paymentType == 0 ? event.params.feeCut : provision.queryFeeCut - provision.indexingFeeCut = event.params.paymentType == 1 ? event.params.feeCut : provision.indexingFeeCut - provision.indexingRewardsCut = event.params.paymentType == 2 ? event.params.feeCut : provision.indexingRewardsCut + + // Before horizon the cuts represented how much the indexer took home. After horizon they now represent how much the delegators get + // To avoid confusion and more changes on explorer we invert the meaning here to keep it consistent. + let invertedCut = BigInt.fromI32(1_000_000).minus(event.params.feeCut) + provision.queryFeeCut = event.params.paymentType == 0 ? invertedCut : provision.queryFeeCut + provision.indexingFeeCut = event.params.paymentType == 1 ? invertedCut : provision.indexingFeeCut + provision.indexingRewardsCut = event.params.paymentType == 2 ? invertedCut : provision.indexingRewardsCut + provision = updateAdvancedProvisionMetrics(provision as Provision) provision.save() + + let indexer = Indexer.load(event.params.serviceProvider.toHexString())! + indexer.indexingRewardCut = event.params.paymentType == 2 ? invertedCut.toI32() : indexer.indexingRewardCut + indexer.queryFeeCut = event.params.paymentType == 0 ? invertedCut.toI32() : indexer.queryFeeCut + indexer = updateAdvancedIndexerMetrics(indexer as Indexer) + indexer.save() } export function handleProvisionSlashed(event: ProvisionSlashed): void { diff --git a/src/mappings/l1staking.ts b/src/mappings/l1staking.ts index 2a4589fd..00190b23 100644 --- a/src/mappings/l1staking.ts +++ b/src/mappings/l1staking.ts @@ -6,7 +6,7 @@ import { } from '../types/L1Staking/L1Staking' import { Indexer, DelegatedStake, GraphNetwork } from '../types/schema' -import { calculateCapacities, createOrLoadGraphNetwork, joinID, updateAdvancedIndexerMetrics, updateDelegationExchangeRate } from './helpers/helpers' +import { calculateCapacities, createOrLoadGraphNetwork, joinID, updateLegacyAdvancedIndexerMetrics, updateDelegationExchangeRate } from './helpers/helpers' /* /// @dev Emitted when an indexer transfers their stake to L2. @@ -34,7 +34,7 @@ export function handleIndexerStakeTransferredToL2(event: IndexerStakeTransferred indexer.lastTransferredToL2At = event.block.timestamp indexer.lastTransferredToL2AtBlockNumber = event.block.number indexer.lastTransferredToL2AtTx = event.transaction.hash.toHexString() - indexer = updateAdvancedIndexerMetrics(indexer as Indexer) + indexer = updateLegacyAdvancedIndexerMetrics(indexer as Indexer) indexer = calculateCapacities(indexer as Indexer) indexer.save() @@ -84,7 +84,7 @@ export function handleDelegationTransferredToL2(event: DelegationTransferredToL2 if (indexer.delegatorShares != BigInt.fromI32(0)) { indexer = updateDelegationExchangeRate(indexer as Indexer) } - indexer = updateAdvancedIndexerMetrics(indexer as Indexer) + indexer = updateLegacyAdvancedIndexerMetrics(indexer as Indexer) indexer = calculateCapacities(indexer as Indexer) indexer.save() diff --git a/src/mappings/rewardsManager.ts b/src/mappings/rewardsManager.ts index 443b127d..2bbff6d5 100644 --- a/src/mappings/rewardsManager.ts +++ b/src/mappings/rewardsManager.ts @@ -9,7 +9,7 @@ import { import { createOrLoadSubgraphDeployment, createOrLoadEpoch, - updateAdvancedIndexerMetrics, + updateLegacyAdvancedIndexerMetrics, updateDelegationExchangeRate, createOrLoadGraphNetwork } from './helpers/helpers' @@ -28,7 +28,7 @@ export function handleRewardsAssigned(event: RewardsAssigned): void { indexer.delegatedTokens == BigInt.fromI32(0) ? event.params.amount : event.params.amount - .times(BigInt.fromI32(indexer.indexingRewardCut)) + .times(BigInt.fromI32(indexer.legacyIndexingRewardCut)) .div(BigInt.fromI32(1000000)) let delegatorIndexingRewards = event.params.amount.minus(indexerIndexingRewards) @@ -40,7 +40,7 @@ export function handleRewardsAssigned(event: RewardsAssigned): void { if (indexer.delegatorShares != BigInt.fromI32(0)) { indexer = updateDelegationExchangeRate(indexer as Indexer) } - indexer = updateAdvancedIndexerMetrics(indexer as Indexer) + indexer = updateLegacyAdvancedIndexerMetrics(indexer as Indexer) indexer.save() // update allocation diff --git a/src/mappings/staking.ts b/src/mappings/staking.ts index d77fd5d4..8e612f7d 100644 --- a/src/mappings/staking.ts +++ b/src/mappings/staking.ts @@ -40,7 +40,7 @@ import { createOrLoadDelegator, createOrLoadDelegatedStake, createOrLoadGraphAccount, - updateAdvancedIndexerMetrics, + updateLegacyAdvancedIndexerMetrics, updateDelegationExchangeRate, calculatePricePerShare, batchUpdateSubgraphSignalledTokens, @@ -54,13 +54,13 @@ import { addresses } from '../../config/addresses' export function handleDelegationParametersUpdated(event: DelegationParametersUpdated): void { let graphNetwork = createOrLoadGraphNetwork(event.block.number, event.address) let indexer = createOrLoadLegacyIndexer(event.params.indexer, event.block.timestamp) - indexer.indexingRewardCut = event.params.indexingRewardCut.toI32() - indexer.queryFeeCut = event.params.queryFeeCut.toI32() + indexer.legacyIndexingRewardCut = event.params.indexingRewardCut.toI32() + indexer.legacyQueryFeeCut = event.params.queryFeeCut.toI32() indexer.delegatorParameterCooldown = event.params.cooldownBlocks.toI32() indexer.lastDelegationParameterUpdate = ( addresses.isL1 ? event.block.number : graphNetwork.currentL1BlockNumber! ).toI32() - indexer = updateAdvancedIndexerMetrics(indexer as Indexer) + indexer = updateLegacyAdvancedIndexerMetrics(indexer as Indexer) indexer.save() } @@ -76,7 +76,7 @@ export function handleStakeDeposited(event: StakeDeposited): void { let indexer = createOrLoadLegacyIndexer(event.params.indexer, event.block.timestamp) let previousStake = indexer.stakedTokens indexer.stakedTokens = indexer.stakedTokens.plus(event.params.tokens) - indexer = updateAdvancedIndexerMetrics(indexer as Indexer) + indexer = updateLegacyAdvancedIndexerMetrics(indexer as Indexer) indexer = calculateCapacities(indexer as Indexer) indexer.save() @@ -108,7 +108,7 @@ export function handleStakeLocked(event: StakeLocked): void { let indexer = Indexer.load(id)! indexer.lockedTokens = event.params.tokens indexer.tokensLockedUntil = event.params.until.toI32() - indexer = updateAdvancedIndexerMetrics(indexer as Indexer) + indexer = updateLegacyAdvancedIndexerMetrics(indexer as Indexer) indexer = calculateCapacities(indexer as Indexer) indexer.save() @@ -135,7 +135,7 @@ export function handleStakeWithdrawn(event: StakeWithdrawn): void { indexer.stakedTokens = indexer.stakedTokens.minus(event.params.tokens) indexer.lockedTokens = indexer.lockedTokens.minus(event.params.tokens) indexer.tokensLockedUntil = 0 // always set to 0 when withdrawn - indexer = updateAdvancedIndexerMetrics(indexer as Indexer) + indexer = updateLegacyAdvancedIndexerMetrics(indexer as Indexer) indexer = calculateCapacities(indexer as Indexer) indexer.save() @@ -164,7 +164,7 @@ export function handleStakeSlashed(event: StakeSlashed): void { let staking = Staking.bind(event.address) let indexerStored = staking.stakes(event.params.indexer) indexer.lockedTokens = indexerStored.tokensLocked - indexer = updateAdvancedIndexerMetrics(indexer as Indexer) + indexer = updateLegacyAdvancedIndexerMetrics(indexer as Indexer) indexer = calculateCapacities(indexer as Indexer) indexer.save() @@ -184,7 +184,7 @@ export function handleStakeDelegated(event: StakeDelegated): void { if (indexer.delegatorShares != BigInt.fromI32(0)) { indexer = updateDelegationExchangeRate(indexer as Indexer) } - indexer = updateAdvancedIndexerMetrics(indexer as Indexer) + indexer = updateLegacyAdvancedIndexerMetrics(indexer as Indexer) indexer = calculateCapacities(indexer as Indexer) indexer.save() @@ -253,7 +253,7 @@ export function handleStakeDelegatedLocked(event: StakeDelegatedLocked): void { if (indexer.delegatorShares != BigInt.fromI32(0)) { indexer = updateDelegationExchangeRate(indexer as Indexer) } - indexer = updateAdvancedIndexerMetrics(indexer as Indexer) + indexer = updateLegacyAdvancedIndexerMetrics(indexer as Indexer) indexer = calculateCapacities(indexer as Indexer) indexer.save() @@ -330,7 +330,7 @@ export function handleAllocationCreated(event: AllocationCreated): void { indexer.allocatedTokens = indexer.allocatedTokens.plus(event.params.tokens) indexer.totalAllocationCount = indexer.totalAllocationCount.plus(BigInt.fromI32(1)) indexer.allocationCount = indexer.allocationCount + 1 - indexer = updateAdvancedIndexerMetrics(indexer as Indexer) + indexer = updateLegacyAdvancedIndexerMetrics(indexer as Indexer) indexer = calculateCapacities(indexer as Indexer) indexer.save() @@ -370,10 +370,10 @@ export function handleAllocationCreated(event: AllocationCreated): void { allocation.totalReturn = BigDecimal.fromString('0') allocation.annualizedReturn = BigDecimal.fromString('0') allocation.createdAt = event.block.timestamp.toI32() - allocation.indexingRewardCutAtStart = indexer.indexingRewardCut - allocation.indexingRewardEffectiveCutAtStart = indexer.indexingRewardEffectiveCut - allocation.queryFeeCutAtStart = indexer.queryFeeCut - allocation.queryFeeEffectiveCutAtStart = indexer.queryFeeEffectiveCut + allocation.indexingRewardCutAtStart = indexer.legacyIndexingRewardCut + allocation.indexingRewardEffectiveCutAtStart = indexer.legacyIndexingRewardEffectiveCut + allocation.queryFeeCutAtStart = indexer.legacyQueryFeeCut + allocation.queryFeeEffectiveCutAtStart = indexer.legacyQueryFeeEffectiveCut allocation.isLegacy = true allocation.save() } @@ -507,7 +507,7 @@ export function handleAllocationClosed(event: AllocationClosed): void { } indexer.allocatedTokens = indexer.allocatedTokens.minus(event.params.tokens) indexer.allocationCount = indexer.allocationCount - 1 - indexer = updateAdvancedIndexerMetrics(indexer as Indexer) + indexer = updateLegacyAdvancedIndexerMetrics(indexer as Indexer) indexer = calculateCapacities(indexer as Indexer) indexer.save() @@ -522,10 +522,10 @@ export function handleAllocationClosed(event: AllocationClosed): void { allocation.status = 'Closed' allocation.closedAt = event.block.timestamp.toI32() allocation.poi = event.params.poi - allocation.indexingRewardCutAtClose = indexer.indexingRewardCut - allocation.indexingRewardEffectiveCutAtClose = indexer.indexingRewardEffectiveCut - allocation.queryFeeCutAtClose = indexer.queryFeeCut - allocation.queryFeeEffectiveCutAtClose = indexer.queryFeeEffectiveCut + allocation.indexingRewardCutAtClose = indexer.legacyIndexingRewardCut + allocation.indexingRewardEffectiveCutAtClose = indexer.legacyIndexingRewardEffectiveCut + allocation.queryFeeCutAtClose = indexer.legacyQueryFeeCut + allocation.queryFeeEffectiveCutAtClose = indexer.legacyQueryFeeEffectiveCut allocation.save() // update epoch - We do it here to have more epochs created, instead of seeing none created @@ -578,7 +578,7 @@ export function handleAllocationClosedCobbDouglas(event: AllocationClosed1): voi } indexer.allocatedTokens = indexer.allocatedTokens.minus(event.params.tokens) indexer.allocationCount = indexer.allocationCount - 1 - indexer = updateAdvancedIndexerMetrics(indexer as Indexer) + indexer = updateLegacyAdvancedIndexerMetrics(indexer as Indexer) indexer = calculateCapacities(indexer as Indexer) indexer.save() @@ -594,10 +594,10 @@ export function handleAllocationClosedCobbDouglas(event: AllocationClosed1): voi allocation.status = 'Closed' allocation.closedAt = event.block.timestamp.toI32() allocation.poi = event.params.poi - allocation.indexingRewardCutAtClose = indexer.indexingRewardCut - allocation.indexingRewardEffectiveCutAtClose = indexer.indexingRewardEffectiveCut - allocation.queryFeeCutAtClose = indexer.queryFeeCut - allocation.queryFeeEffectiveCutAtClose = indexer.queryFeeEffectiveCut + allocation.indexingRewardCutAtClose = indexer.legacyIndexingRewardCut + allocation.indexingRewardEffectiveCutAtClose = indexer.legacyIndexingRewardEffectiveCut + allocation.queryFeeCutAtClose = indexer.legacyQueryFeeCut + allocation.queryFeeEffectiveCutAtClose = indexer.legacyQueryFeeEffectiveCut allocation.save() // update epoch - We do it here to have more epochs created, instead of seeing none created @@ -656,7 +656,7 @@ export function handleRebateClaimed(event: RebateClaimed): void { if (indexer.delegatorShares != BigInt.fromI32(0)) { indexer = updateDelegationExchangeRate(indexer as Indexer) } - indexer = updateAdvancedIndexerMetrics(indexer as Indexer) + indexer = updateLegacyAdvancedIndexerMetrics(indexer as Indexer) indexer.save() // update allocation let allocation = Allocation.load(allocationID)! @@ -721,7 +721,7 @@ export function handleRebateCollected(event: RebateCollected): void { if (indexer.delegatorShares != BigInt.fromI32(0)) { indexer = updateDelegationExchangeRate(indexer as Indexer) } - indexer = updateAdvancedIndexerMetrics(indexer as Indexer) + indexer = updateLegacyAdvancedIndexerMetrics(indexer as Indexer) indexer.save() // Replicate for payment source specific aggregation diff --git a/tests/helpers.test.ts b/tests/helpers.test.ts index 5e313c0e..4c4ddf28 100644 --- a/tests/helpers.test.ts +++ b/tests/helpers.test.ts @@ -46,5 +46,5 @@ test('createOrLoadGraphAccount creates a new graph account', () => { test('createOrLoadIndexer creates a new indexer', () => { createOrLoadIndexer(Bytes.fromHexString(indexerID), BigInt.fromI32(1)) assert.fieldEquals('Indexer', indexerID, 'stakedTokens', '0') - assert.fieldEquals('Indexer', indexerID, 'indexingRewardCut', '0') + assert.fieldEquals('Indexer', indexerID, 'legacyIndexingRewardCut', '0') }) diff --git a/tests/staking.test.ts b/tests/staking.test.ts index 3f345274..ff3942e6 100644 --- a/tests/staking.test.ts +++ b/tests/staking.test.ts @@ -141,12 +141,12 @@ describe('INDEXER STAKE', () => { cooldownBlocks, ) handleDelegationParametersUpdated(event) - assert.fieldEquals('Indexer', indexerID, 'queryFeeCut', queryFeeCut.toString()) + assert.fieldEquals('Indexer', indexerID, 'legacyQueryFeeCut', queryFeeCut.toString()) }) test('assigns the right values to params', () => { - assert.fieldEquals('Indexer', indexerID, 'indexingRewardCut', indexingRewardCut.toString()) - assert.fieldEquals('Indexer', indexerID, 'queryFeeCut', queryFeeCut.toString()) + assert.fieldEquals('Indexer', indexerID, 'legacyIndexingRewardCut', indexingRewardCut.toString()) + assert.fieldEquals('Indexer', indexerID, 'legacyQueryFeeCut', queryFeeCut.toString()) assert.fieldEquals( 'Indexer', indexerID, @@ -163,8 +163,8 @@ describe('INDEXER STAKE', () => { cooldownBlocks2, ) handleDelegationParametersUpdated(event) - assert.fieldEquals('Indexer', indexerID, 'indexingRewardCut', indexingRewardCut2.toString()) - assert.fieldEquals('Indexer', indexerID, 'queryFeeCut', queryFeeCut2.toString()) + assert.fieldEquals('Indexer', indexerID, 'legacyIndexingRewardCut', indexingRewardCut2.toString()) + assert.fieldEquals('Indexer', indexerID, 'legacyQueryFeeCut', queryFeeCut2.toString()) assert.fieldEquals( 'Indexer', indexerID,