Skip to content

Commit

Permalink
fix(#patch); currentHolderCount in erc20 subgraph (#2459)
Browse files Browse the repository at this point in the history
  • Loading branch information
zjesko authored Jul 5, 2024
1 parent 1e58d16 commit 032220a
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions subgraphs/erc20/src/mappings/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,20 +320,15 @@ function handleTransferEvent(
if (isNewAccount(destination)) {
// It means the receiver is a new holder
toAddressIsNewHolderNum = BIGINT_ONE;
} else {
balance = getOrCreateAccountBalance(
getOrCreateAccount(destination),
token
);
if (balance.amount == BIGINT_ONE) {
// It means the receiver's token balance is 0 before transferal.
toBalanceIsZeroNum = BIGINT_ONE;
}
}
balance = getOrCreateAccountBalance(getOrCreateAccount(destination), token);
if (balance.amount == BIGINT_ZERO) {
// It means the receiver's token balance is 0 before transferal.
toBalanceIsZeroNum = BIGINT_ONE;
}

token.currentHolderCount = token.currentHolderCount
.minus(FromBalanceToZeroNum)
.plus(toAddressIsNewHolderNum)
.plus(toBalanceIsZeroNum);
token.cumulativeHolderCount = token.cumulativeHolderCount.plus(
toAddressIsNewHolderNum
Expand All @@ -343,7 +338,6 @@ function handleTransferEvent(
let dailySnapshot = getOrCreateTokenDailySnapshot(token, event.block);
dailySnapshot.currentHolderCount = dailySnapshot.currentHolderCount
.minus(FromBalanceToZeroNum)
.plus(toAddressIsNewHolderNum)
.plus(toBalanceIsZeroNum);
dailySnapshot.cumulativeHolderCount =
dailySnapshot.cumulativeHolderCount.plus(toAddressIsNewHolderNum);
Expand All @@ -357,7 +351,6 @@ function handleTransferEvent(
let hourlySnapshot = getOrCreateTokenHourlySnapshot(token, event.block);
hourlySnapshot.currentHolderCount = hourlySnapshot.currentHolderCount
.minus(FromBalanceToZeroNum)
.plus(toAddressIsNewHolderNum)
.plus(toBalanceIsZeroNum);
hourlySnapshot.cumulativeHolderCount =
hourlySnapshot.cumulativeHolderCount.plus(toAddressIsNewHolderNum);
Expand Down

0 comments on commit 032220a

Please sign in to comment.