From e4f118da868e8d14a238106bc3b4646cf0d4c142 Mon Sep 17 00:00:00 2001 From: Vamsi Date: Sat, 27 Mar 2021 18:50:45 +0530 Subject: [PATCH 1/5] total stake should be also reduced when delegator or validator unstakes --- root/src/mappings/staking-info.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/root/src/mappings/staking-info.ts b/root/src/mappings/staking-info.ts index fb31d07..d762423 100644 --- a/root/src/mappings/staking-info.ts +++ b/root/src/mappings/staking-info.ts @@ -98,6 +98,7 @@ export function handleUnstaked(event: Unstaked): void { // update unstaked status validator.status = 1 + validator.totalStaked = validator.totalStaked.minus(validator.selfStake) validator.selfStake = BigInt.fromI32(0) validator.save() } @@ -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 @@ -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 From 3116046c8488681c47152045331b44e5f3e8f19d Mon Sep 17 00:00:00 2001 From: Vamsi Date: Sat, 27 Mar 2021 19:23:50 +0530 Subject: [PATCH 2/5] Unstake Validator Total Stake should also reduce or go down --- 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 d762423..1e952a6 100644 --- a/root/src/mappings/staking-info.ts +++ b/root/src/mappings/staking-info.ts @@ -98,8 +98,8 @@ export function handleUnstaked(event: Unstaked): void { // update unstaked status validator.status = 1 - validator.totalStaked = validator.totalStaked.minus(validator.selfStake) - validator.selfStake = BigInt.fromI32(0) + validator.totalStaked = event.params.total + validator.selfStake = validator.selfStake.minus(event.params.amount) validator.save() } From 987e9d73d7e8c0c31a1a52c5e74cb58075351b02 Mon Sep 17 00:00:00 2001 From: Vamsi Date: Fri, 2 Apr 2021 12:54:13 +0530 Subject: [PATCH 3/5] validator owner address to be changed on the stakingNFT transfer. --- root/src/mappings/staking-nft.ts | 6 +++++- root/subgraph.template.yaml | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/root/src/mappings/staking-nft.ts b/root/src/mappings/staking-nft.ts index 010e734..1a57af1 100644 --- a/root/src/mappings/staking-nft.ts +++ b/root/src/mappings/staking-nft.ts @@ -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 // @@ -27,6 +27,10 @@ export function handleTransfer(event: Transfer): void { transactionHashes.push(event.transaction.hash) entity.transactionHashes = transactionHashes + let validator = Validator.load(event.params.tokenId) + validator.owner = event.params.to + // save entity entity.save() + validator.save() } diff --git a/root/subgraph.template.yaml b/root/subgraph.template.yaml index 4a52674..694f7de 100644 --- a/root/subgraph.template.yaml +++ b/root/subgraph.template.yaml @@ -210,6 +210,7 @@ dataSources: language: wasm/assemblyscript entities: - StakingNFTTransfer + - Validator abis: - name: StakingNft file: ./abis/StakingNft.json From c53af27e60b596ea538edb0c3baf0ed6615e78b2 Mon Sep 17 00:00:00 2001 From: Vamsi Date: Fri, 2 Apr 2021 14:14:54 +0530 Subject: [PATCH 4/5] validator owner address change --- root/src/mappings/staking-nft.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/root/src/mappings/staking-nft.ts b/root/src/mappings/staking-nft.ts index 1a57af1..18062c2 100644 --- a/root/src/mappings/staking-nft.ts +++ b/root/src/mappings/staking-nft.ts @@ -26,8 +26,8 @@ export function handleTransfer(event: Transfer): void { let transactionHashes = entity.transactionHashes transactionHashes.push(event.transaction.hash) entity.transactionHashes = transactionHashes - - let validator = Validator.load(event.params.tokenId) + let validatorId = "validator:" + event.params.tokenId.toString() + let validator = Validator.load(validatorId) validator.owner = event.params.to // save entity From 461ddb9e5f19765f347f8c1f890090f7d44be568 Mon Sep 17 00:00:00 2001 From: Vamsi Date: Mon, 5 Apr 2021 13:15:39 +0530 Subject: [PATCH 5/5] linting error fix --- root/src/mappings/staking-nft.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/root/src/mappings/staking-nft.ts b/root/src/mappings/staking-nft.ts index 18062c2..26b0e54 100644 --- a/root/src/mappings/staking-nft.ts +++ b/root/src/mappings/staking-nft.ts @@ -26,7 +26,7 @@ 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 validatorId = 'validator:' + event.params.tokenId.toString() let validator = Validator.load(validatorId) validator.owner = event.params.to