Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update unclaimedAmounts in handleRewardsClaimed #93

Merged
merged 3 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/entities/merkleDistributor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ export function createOrLoadDistributorClaim(user: Address): DistributorClaim {
return claim
}

export function loadDistributorClaim(user: Address): DistributorClaim | null {
return DistributorClaim.load(user.toHex())
}

export function getDistributionType(distData: Bytes): DistributionType {
// only passed addresses are currently supported
const distAddress = Address.fromBytes(distData)
Expand Down
25 changes: 12 additions & 13 deletions src/mappings/merkleDistributor.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
import {
Address,
BigInt,
Bytes,
ethereum,
ipfs,
json,
JSONValue,
JSONValueKind,
log,
store,
} from '@graphprotocol/graph-ts'
import { Address, BigInt, Bytes, ethereum, ipfs, json, JSONValue, JSONValueKind, log } from '@graphprotocol/graph-ts'
import { DistributorClaimedAmount, PeriodicDistribution } from '../../generated/schema'
import {
OneTimeDistributionAdded,
Expand All @@ -27,6 +16,7 @@ import {
DistributionType,
getDistributionType,
loadDistributor,
loadDistributorClaim,
} from '../entities/merkleDistributor'
import { createTransaction } from '../entities/transaction'
import { loadUniswapPool } from '../entities/uniswap'
Expand Down Expand Up @@ -280,6 +270,12 @@ export function handleRewardsClaimed(event: RewardsClaimed): void {
const user = event.params.account
const tokens = event.params.tokens
const cumulativeAmounts = event.params.cumulativeAmounts

// The DistributorClaim object is guaranteed to exist at this point because
// the user has claimed rewards using the DistributorClaim object.
const claim = loadDistributorClaim(user)!
const unclaimedAmounts = claim.unclaimedAmounts

for (let i = 0; i < tokens.length; i++) {
const claimedAmountId = `${tokens[i].toHex()}-${user.toHex()}`
let claimedAmount = DistributorClaimedAmount.load(claimedAmountId)
Expand All @@ -289,8 +285,11 @@ export function handleRewardsClaimed(event: RewardsClaimed): void {
}
claimedAmount.cumulativeClaimedAmount = cumulativeAmounts[i]
claimedAmount.save()
unclaimedAmounts[i] = BigInt.zero()
}
store.remove('DistributorClaim', user.toHex())

claim.unclaimedAmounts = unclaimedAmounts
claim.save()

createTransaction(event.transaction.hash.toHex())
log.info('[MerkleDistributor] RewardsClaimed user={}', [user.toHex()])
Expand Down