Skip to content

Commit

Permalink
Merge pull request #35 from maticnetwork/new-delegator-unbond-events
Browse files Browse the repository at this point in the history
Total stake to be reduced on unstake of a delegator or validator.
Owner Address change also to be recorded.
  • Loading branch information
reddyismav authored Apr 5, 2021
2 parents 2d357a1 + 461ddb9 commit 502dcf5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
5 changes: 4 additions & 1 deletion root/src/mappings/staking-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ export function handleUnstaked(event: Unstaked): void {

// update unstaked status
validator.status = 1
validator.selfStake = BigInt.fromI32(0)
validator.totalStaked = event.params.total
validator.selfStake = validator.selfStake.minus(event.params.amount)
validator.save()
}

Expand Down Expand Up @@ -289,6 +290,7 @@ export function handleShareBurned(event: ShareBurned): void {
let validator = loadValidator(event.params.validatorId)

validator.delegatedStake = validator.delegatedStake.minus(event.params.amount)
validator.totalStaked = validator.totalStaked.minus(event.params.amount)

validator.save()
// -- Saving updation
Expand All @@ -312,6 +314,7 @@ export function handleShareBurnedWithId(event: ShareBurnedWithId): void {
let validator = loadValidator(event.params.validatorId)

validator.delegatedStake = validator.delegatedStake.minus(event.params.amount)
validator.totalStaked = validator.totalStaked.minus(event.params.amount)

validator.save()
// -- Saving updation
Expand Down
6 changes: 5 additions & 1 deletion root/src/mappings/staking-nft.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Transfer } from '../../generated/StakingNft/StakingNft'
import { StakingNFTTransfer } from '../../generated/schema'
import { StakingNFTTransfer, Validator } from '../../generated/schema'

// To be invoked when staking NFT contracts Transfer event to be emitted
//
Expand All @@ -26,7 +26,11 @@ export function handleTransfer(event: Transfer): void {
let transactionHashes = entity.transactionHashes
transactionHashes.push(event.transaction.hash)
entity.transactionHashes = transactionHashes
let validatorId = 'validator:' + event.params.tokenId.toString()
let validator = Validator.load(validatorId)
validator.owner = event.params.to

// save entity
entity.save()
validator.save()
}
1 change: 1 addition & 0 deletions root/subgraph.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ dataSources:
language: wasm/assemblyscript
entities:
- StakingNFTTransfer
- Validator
abis:
- name: StakingNft
file: ./abis/StakingNft.json
Expand Down

0 comments on commit 502dcf5

Please sign in to comment.