diff --git a/schema.graphql b/schema.graphql index 6097b3b..3c7a813 100644 --- a/schema.graphql +++ b/schema.graphql @@ -290,6 +290,13 @@ type ClaimEvent @entity { blockNumber: BigInt! } +type ClaimEventAmount @entity { + id: ID! + claimEvent: ClaimEvent! + rewards: BigInt! + user: User! +} + type SlashEvent @entity { id: ID! target: User! diff --git a/src/mappings/claimsManager.ts b/src/mappings/claimsManager.ts index aaf1d77..10c9e54 100644 --- a/src/mappings/claimsManager.ts +++ b/src/mappings/claimsManager.ts @@ -16,7 +16,8 @@ import { import { AudiusNetwork, ClaimRound, - ClaimEvent + ClaimEvent, + ClaimEventAmount } from '../types/schema' import { createOrLoadUser, @@ -64,10 +65,19 @@ export function handleClaimProcessed(event: ClaimProcessed): void { claimer.claimableDelegationReceivedAmount = totalClaimerDelegated.minus(totalClaimedDelegatedLocked) claimer.stakeAmount = totalStakedAmount.minus(claimer.delegationReceivedAmount) - claimer.claimableStakeAmount = claimer.stakeAmount.minus(pendingDecreaseStakeAmount) + let updatedClaimableStakeAmount = claimer.stakeAmount.minus(pendingDecreaseStakeAmount) + let claimerDiffAmount = updatedClaimableStakeAmount.minus(claimer.claimableStakeAmount) + claimer.claimableStakeAmount = updatedClaimableStakeAmount claimer.totalClaimableAmount = claimer.claimableStakeAmount.plus(claimer.claimableDelegationSentAmount) claimer.save() + // Save the individual sp'd increase during the claim + let claimEventAmount = new ClaimEventAmount(id.concat(claimer.id)) + claimEventAmount.claimEvent = claimEvent.id + claimEventAmount.rewards = claimerDiffAmount + claimEventAmount.user = claimer.id + claimEventAmount.save() + let addedTokensStaked = claimer.stakeAmount.minus(prevStaked) audiusNetwork.totalTokensStaked = audiusNetwork.totalTokensStaked.plus(addedTokensStaked) @@ -90,7 +100,14 @@ export function handleClaimProcessed(event: ClaimProcessed): void { delegator.claimableDelegationSentAmount = delegator.claimableDelegationSentAmount.plus(delegationDiff) delegator.delegationSentAmount = delegator.delegationSentAmount.plus(delegationDiff) delegator.totalClaimableAmount = delegator.totalClaimableAmount.plus(delegationDiff) - delegator.save() + delegator.save() + + let claimEventAmountId = id.concat(delegator.id) + let claimEventAmount = new ClaimEventAmount(claimEventAmountId) + claimEventAmount.claimEvent = claimEvent.id + claimEventAmount.rewards = delegationDiff + claimEventAmount.user = delegator + claimEventAmount.save() } }