Skip to content

Commit

Permalink
Merge pull request #42 from maticnetwork/partial-unbonds
Browse files Browse the repository at this point in the history
new: DelegatorUnbond for partial unbonds
  • Loading branch information
nitinmittal23 authored Aug 27, 2021
2 parents 6da5cd6 + cec0582 commit e5633fd
Show file tree
Hide file tree
Showing 2 changed files with 41 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,3 +158,13 @@ type StakingNFTTransfer @entity {
previousOwners: [Bytes!]!
transactionHashes: [Bytes!]!
}

type DelegatorUnbond @entity {
id: ID!
nonce: BigInt!
validatorId: BigInt!
user: Bytes!
amount: BigInt!
tokens: BigInt!
completed: Boolean!
}
31 changes: 31 additions & 0 deletions root/src/mappings/staking-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Topup,
StakingParams,
GlobalDelegatorCounter,
DelegatorUnbond,
} from '../../generated/schema'
import {
ClaimFee,
Expand Down Expand Up @@ -249,6 +250,21 @@ function loadDelegator(validatorId: BigInt, delegator: Address): Delegator {
return entity as Delegator
}

function loadDelegatorUnbond(validatorId: BigInt, delegator: Address, nonce: BigInt): DelegatorUnbond {
let id = 'delegatorUnbond:' + delegator.toHexString() + ':' + validatorId.toString() + ':' + nonce.toString()
let entity = DelegatorUnbond.load(id)
if (entity == null) {
entity = new DelegatorUnbond(id)
entity.validatorId = validatorId
entity.user = delegator
entity.nonce = nonce
entity.amount = BigInt.fromI32(0)
entity.tokens = BigInt.fromI32(0)
entity.completed = false
}
return entity as DelegatorUnbond
}

export function handleShareMinted(event: ShareMinted): void {
let delegator = loadDelegator(event.params.validatorId, event.params.user)

Expand Down Expand Up @@ -315,6 +331,14 @@ export function handleShareBurnedWithId(event: ShareBurnedWithId): void {

validator.save()
// -- Saving updation

// save unbond details with nonce value
let delegatorUnbond = loadDelegatorUnbond(event.params.validatorId, event.params.user, event.params.nonce)
delegatorUnbond.amount = event.params.amount
delegatorUnbond.tokens = event.params.tokens

// save entity
delegatorUnbond.save()
}

export function handleDelegatorUnstaked(event: DelegatorUnstaked): void {
Expand All @@ -337,6 +361,13 @@ export function handleDelegatorUnstakeWithId(event: DelegatorUnstakeWithId): voi
delegator.claimedAmount = delegator.claimedAmount.plus(event.params.amount)

delegator.save()

// save unbond details with completed as false
let delegatorUnbond = loadDelegatorUnbond(event.params.validatorId, event.params.user, event.params.nonce)
delegatorUnbond.completed = true

// save entity
delegatorUnbond.save()
}

export function handleDelegatorClaimedRewards(event: DelegatorClaimedRewards): void {
Expand Down

0 comments on commit e5633fd

Please sign in to comment.