Skip to content

Commit

Permalink
Merge pull request #14 from graphprotocol/juanmardefago/add-rebate-co…
Browse files Browse the repository at this point in the history
…llected

feat: add RebateCollected support
  • Loading branch information
juanmardefago authored Jul 1, 2024
2 parents 9df3505 + 94da393 commit 3d96d79
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
38 changes: 38 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type CounterEntity @entity {
allocationCollectedEventCount: BigInt!
allocationClosedEventCount: BigInt!
rebateClaimedEventCount: BigInt!
rebateCollectedEventCount: BigInt!
nSignalMintedEventCount: BigInt!
nSignalBurnedEventCount: BigInt!
grtWithdrawnEventCount: BigInt!
Expand Down Expand Up @@ -1074,6 +1075,43 @@ type RebateClaimedEvent implements IndexerEvent & SubgraphDeploymentEvent & Grap
tx_cumulativeGasUsed: BigInt!
}

type RebateCollectedEvent implements IndexerEvent & SubgraphDeploymentEvent & GraphAccountEvent & Event
@entity(immutable: true) {
"Generic ID only for uniqueness purposes."
id: ID!

timestamp: BigInt!

blockNumber: BigInt!

tx_hash: Bytes!

typename: String!

indexer: Indexer!

accounts: [GraphAccount!]!

"ID of the allocation created"
allocation: String!

deployment: SubgraphDeployment!

collectedQueryFees: BigInt!

queryFeeRebates: BigInt!

curatorQueryFees: BigInt!

tx_gasLimit: BigInt!

tx_gasPrice: BigInt!

tx_gasUsed: BigInt!

tx_cumulativeGasUsed: BigInt!
}

type IndexerStakeTransferredToL2Event implements IndexerEvent & GraphAccountEvent & Event
@entity(immutable: true) {
"Generic ID only for uniqueness purposes."
Expand Down
1 change: 1 addition & 0 deletions src/mappings/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export function getCounter(): CounterEntity {
counter.allocationCollectedEventCount = BIGINT_ZERO
counter.allocationClosedEventCount = BIGINT_ZERO
counter.rebateClaimedEventCount = BIGINT_ZERO
counter.rebateCollectedEventCount = BIGINT_ZERO
counter.nSignalMintedEventCount = BIGINT_ZERO
counter.nSignalBurnedEventCount = BIGINT_ZERO
counter.grtWithdrawnEventCount = BIGINT_ZERO
Expand Down
35 changes: 35 additions & 0 deletions src/mappings/staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
DelegatorStakeWithdrawnEvent,
AllocationCreatedEvent,
AllocationCollectedEvent,
RebateCollectedEvent,
AllocationClosedEvent,
RebateClaimedEvent,
SetOperatorEvent,
Expand All @@ -49,6 +50,7 @@ import {
getCounter,
BIGINT_ONE,
} from './helpers'
import { RebateCollected } from '../types/L1Staking/L1Staking'

export function handleDelegationParametersUpdated(event: DelegationParametersUpdated): void {
let eventId = event.transaction.hash.toHexString().concat('-').concat(event.logIndex.toString())
Expand Down Expand Up @@ -525,6 +527,39 @@ export function handleRebateClaimed(event: RebateClaimed): void {
counter.save()
}

export function handleRebateCollected(event: RebateCollected): void {
let eventId = event.transaction.hash.toHexString().concat('-').concat(event.logIndex.toString())
let indexerAddress = event.params.indexer.toHexString()
let accounts = new Array<String>()
accounts.push(indexerAddress)

let eventEntity = new RebateCollectedEvent(eventId)
eventEntity.timestamp = event.block.timestamp
eventEntity.tx_gasLimit = event.transaction.gasLimit
eventEntity.tx_gasPrice = event.transaction.gasPrice
eventEntity.tx_gasUsed = event.receipt!.gasUsed
eventEntity.tx_cumulativeGasUsed = event.receipt!.cumulativeGasUsed
eventEntity.blockNumber = event.block.number
eventEntity.tx_hash = event.transaction.hash
eventEntity.typename = 'RebateCollectedEvent'
eventEntity.indexer = indexerAddress
eventEntity.accounts = accounts
eventEntity.allocation = event.params.allocationID.toHexString()
eventEntity.deployment = event.params.subgraphDeploymentID.toHexString()
eventEntity.collectedQueryFees = event.params.queryFees
eventEntity.queryFeeRebates = event.params.queryRebates
eventEntity.curatorQueryFees = event.params.curationFees
eventEntity.save()

let counter = getCounter()
counter.rebateCollectedEventCount = counter.rebateCollectedEventCount.plus(BIGINT_ONE)
counter.subgraphDeploymentEventCount = counter.subgraphDeploymentEventCount.plus(BIGINT_ONE)
counter.indexerEventCount = counter.indexerEventCount.plus(BIGINT_ONE)
counter.graphAccountEventCount = counter.graphAccountEventCount.plus(BIGINT_ONE)
counter.eventCount = counter.eventCount.plus(BIGINT_ONE)
counter.save()
}

/**
* @dev handleParameterUpdated
* - updates all parameters of staking, depending on string passed. We then can
Expand Down
3 changes: 3 additions & 0 deletions subgraph.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,9 @@ dataSources:
- event: RebateClaimed(indexed address,indexed bytes32,indexed address,uint256,uint256,uint256,uint256,uint256)
handler: handleRebateClaimed
receipt: true
- event: RebateCollected(address,indexed address,indexed bytes32,indexed address,uint256,uint256,uint256,uint256,uint256,uint256,uint256)
handler: handleRebateCollected
receipt: true
- event: SetOperator(indexed address,indexed address,bool)
handler: handleSetOperator
receipt: true
Expand Down

0 comments on commit 3d96d79

Please sign in to comment.