From 5b30e43282d75c9a4c4fee5819e61884402162e9 Mon Sep 17 00:00:00 2001 From: vibhurajeev Date: Wed, 27 Apr 2022 13:27:02 +0530 Subject: [PATCH 1/2] New: Staking Update Events --- root/schema.graphql | 10 ++++++++++ root/src/mappings/staking-info.ts | 13 ++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/root/schema.graphql b/root/schema.graphql index 6444629..0453674 100644 --- a/root/schema.graphql +++ b/root/schema.graphql @@ -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 { diff --git a/root/src/mappings/staking-info.ts b/root/src/mappings/staking-info.ts index 3be695f..36b2e66 100644 --- a/root/src/mappings/staking-info.ts +++ b/root/src/mappings/staking-info.ts @@ -6,6 +6,7 @@ import { StakingParams, GlobalDelegatorCounter, DelegatorUnbond, + StakeUpdate as StakeUpdateEntity, } from '../../generated/schema' import { ClaimFee, @@ -151,7 +152,7 @@ export function handleUnJailed(event: UnJailed): void { export function handleStakeUpdate(event: StakeUpdate): void { let validator = loadValidator(event.params.validatorId) - + // update total staked and nonce validator.totalStaked = event.params.newAmount validator.nonce = event.params.nonce @@ -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 { From 9b78477dc37e00b151a09fa3ec4588527c8827a6 Mon Sep 17 00:00:00 2001 From: vibhurajeev Date: Wed, 27 Apr 2022 13:34:18 +0530 Subject: [PATCH 2/2] Fix: Cleanup --- root/src/mappings/staking-info.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/root/src/mappings/staking-info.ts b/root/src/mappings/staking-info.ts index 36b2e66..39feb38 100644 --- a/root/src/mappings/staking-info.ts +++ b/root/src/mappings/staking-info.ts @@ -152,7 +152,7 @@ export function handleUnJailed(event: UnJailed): void { export function handleStakeUpdate(event: StakeUpdate): void { let validator = loadValidator(event.params.validatorId) - + // update total staked and nonce validator.totalStaked = event.params.newAmount validator.nonce = event.params.nonce @@ -171,7 +171,7 @@ export function handleStakeUpdate(event: StakeUpdate): void { stakeUpdate.block = event.block.number stakeUpdate.transactionHash = event.transaction.hash stakeUpdate.validatorId = event.params.validatorId - stakeUpdate.logIndex = event.logIndex; + stakeUpdate.logIndex = event.logIndex validator.save() stakeUpdate.save()