Skip to content

Commit

Permalink
Merge pull request #62 from maticnetwork/vr_new-stake-update
Browse files Browse the repository at this point in the history
New: Staking Update Events
  • Loading branch information
nitinmittal23 authored Apr 27, 2022
2 parents 56036ba + 9b78477 commit 35b8b8a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions root/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,16 @@ type Validator @entity {
isInAuction: Boolean!
}

type StakeUpdate @entity {
id: ID!
validatorId: BigInt!
totalStaked: BigInt!
block: BigInt!
nonce: BigInt!
transactionHash: Bytes!
logIndex: BigInt!
}

# Keeps track of current delegator counter i.e. how many
# delegators are present as of now
type GlobalDelegatorCounter @entity {
Expand Down
11 changes: 11 additions & 0 deletions root/src/mappings/staking-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
StakingParams,
GlobalDelegatorCounter,
DelegatorUnbond,
StakeUpdate as StakeUpdateEntity,
} from '../../generated/schema'
import {
ClaimFee,
Expand Down Expand Up @@ -163,7 +164,17 @@ export function handleStakeUpdate(event: StakeUpdate): void {
// from totalStaked
validator.selfStake = validator.totalStaked.minus(validator.delegatedStake)

//Stake update entity
let stakeUpdate = new StakeUpdateEntity(event.transaction.hash.toHex() + '-' + event.logIndex.toString())
stakeUpdate.totalStaked = event.params.newAmount
stakeUpdate.nonce = event.params.nonce
stakeUpdate.block = event.block.number
stakeUpdate.transactionHash = event.transaction.hash
stakeUpdate.validatorId = event.params.validatorId
stakeUpdate.logIndex = event.logIndex

validator.save()
stakeUpdate.save()
}

export function handleClaimRewards(event: ClaimRewards): void {
Expand Down

0 comments on commit 35b8b8a

Please sign in to comment.