diff --git a/root/abis/StakingInfo.json b/root/abis/StakingInfo.json index c732d8a..1cc939a 100644 --- a/root/abis/StakingInfo.json +++ b/root/abis/StakingInfo.json @@ -155,6 +155,37 @@ "name": "DelegatorUnstaked", "type": "event" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "validatorId", + "type": "uint256" + }, + { + "indexed": true, + "internalType": "address", + "name": "user", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "nonce", + "type": "uint256" + } + ], + "name": "DelegatorUnstakeWithId", + "type": "event" + }, { "anonymous": false, "inputs": [ @@ -312,6 +343,43 @@ "name": "ShareBurned", "type": "event" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "validatorId", + "type": "uint256" + }, + { + "indexed": true, + "internalType": "address", + "name": "user", + "type": "address" + }, + { + "indexed": true, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "tokens", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "nonce", + "type": "uint256" + } + ], + "name": "ShareBurnedWithId", + "type": "event" + }, { "anonymous": false, "inputs": [ @@ -1351,6 +1419,41 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "constant": false, + "inputs": [ + { + "internalType": "uint256", + "name": "validatorId", + "type": "uint256" + }, + { + "internalType": "address", + "name": "user", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokens", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "nonce", + "type": "uint256" + } + ], + "name": "logShareBurnedWithId", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, { "constant": false, "inputs": [ @@ -1426,6 +1529,36 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "constant": false, + "inputs": [ + { + "internalType": "uint256", + "name": "validatorId", + "type": "uint256" + }, + { + "internalType": "address", + "name": "user", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "nonce", + "type": "uint256" + } + ], + "name": "logDelegatorUnstakedWithId", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, { "constant": false, "inputs": [ diff --git a/root/src/mappings/staking-info.ts b/root/src/mappings/staking-info.ts index 53a0d6d..3b5973d 100644 --- a/root/src/mappings/staking-info.ts +++ b/root/src/mappings/staking-info.ts @@ -11,12 +11,14 @@ import { ClaimRewards, DelegatorClaimedRewards, DelegatorUnstaked, + DelegatorUnstakeWithId, DynastyValueChange, Jailed, OwnershipTransferred, ProposerBonusChange, Restaked, ShareBurned, + ShareBurnedWithId, ShareMinted, SignerChange, StakeUpdate, @@ -277,6 +279,30 @@ export function handleShareBurned(event: ShareBurned): void { delegator.unclaimedAmount = delegator.unclaimedAmount.plus(event.params.amount) // this works until tokens are not transaferable delegator.tokens = delegator.tokens.minus(event.params.tokens) + delegator.delegatedAmount = delegator.delegatedAmount.minus(event.params.amount) + + // save entity + delegator.save() + + // -- Also updating delegated stake for validator + let validator = loadValidator(event.params.validatorId) + + validator.delegatedStake = validator.delegatedStake.minus(event.params.amount) + + validator.save() + // -- Saving updation +} + +export function handleShareBurnedWithId(event: ShareBurnedWithId): void { + let delegator = loadDelegator(event.params.validatorId, event.params.user) + + // update claimedAmount and tokens + // it is possible to have: claimed amount < amount (when slashing happens) + // that's why having claimedAmount would be better + delegator.unclaimedAmount = delegator.unclaimedAmount.plus(event.params.amount) + // this works until tokens are not transaferable + delegator.tokens = delegator.tokens.minus(event.params.tokens) + delegator.delegatedAmount = delegator.delegatedAmount.minus(event.params.amount) // save entity delegator.save() @@ -298,9 +324,16 @@ export function handleDelegatorUnstaked(event: DelegatorUnstaked): void { // update claimed amount delegator.claimedAmount = delegator.claimedAmount.plus(event.params.amount) - // As delegator just unstaked, we can decrement their delegatedAmount i.e. - // `stake` as it's described in `staking-api` - delegator.delegatedAmount = delegator.delegatedAmount.minus(event.params.amount) + delegator.save() +} + +export function handleDelegatorUnstakeWithId(event: DelegatorUnstakeWithId): void { + let delegator = loadDelegator(event.params.validatorId, event.params.user) + + // update unclaimed amount by deducting total unclaimed amount + delegator.unclaimedAmount = delegator.unclaimedAmount.minus(event.params.amount) + // update claimed amount + delegator.claimedAmount = delegator.claimedAmount.plus(event.params.amount) delegator.save() } diff --git a/root/subgraph.template.yaml b/root/subgraph.template.yaml index 74b8cc5..ae7726c 100644 --- a/root/subgraph.template.yaml +++ b/root/subgraph.template.yaml @@ -157,6 +157,8 @@ dataSources: # handler: handleDelegatorRestaked - event: DelegatorUnstaked(indexed uint256,indexed address,uint256) handler: handleDelegatorUnstaked + - event: DelegatorUnstakeWithId(indexed uint256,indexed address,uint256,uint256) + handler: handleDelegatorUnstakeWithId - event: DynastyValueChange(uint256,uint256) handler: handleDynastyValueChange - event: Jailed(indexed uint256,indexed uint256,indexed address) @@ -170,6 +172,8 @@ dataSources: # - event: RewardUpdate(uint256,uint256) - event: ShareBurned(indexed uint256,indexed address,indexed uint256,uint256) handler: handleShareBurned + - event: ShareBurnedWithId(indexed uint256,indexed address,indexed uint256,uint256,uint256) + handler: handleShareBurnedWithId - event: ShareMinted(indexed uint256,indexed address,indexed uint256,uint256) handler: handleShareMinted - event: SignerChange(indexed uint256,uint256,indexed address,indexed address,bytes)