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

fix(#patch); currentHolderCount in erc20 subgraph #2459

Merged
merged 2 commits into from
Jul 5, 2024
Merged
Changes from 1 commit
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
17 changes: 5 additions & 12 deletions subgraphs/erc20/src/mappings/token.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Bytes, BigInt, ethereum, log } from "@graphprotocol/graph-ts";

Check failure on line 1 in subgraphs/erc20/src/mappings/token.ts

View workflow job for this annotation

GitHub Actions / LintStagedFiles

'log' is defined but never used

import { ERC20, Transfer } from "../../generated/templates/StandardToken/ERC20";
import { Burn } from "../../generated/templates/BurnableToken/Burnable";
Expand Down Expand Up @@ -30,14 +30,14 @@
} from "./account";

export function handleTransfer(event: Transfer): void {
let token = Token.load(event.address.toHex());

Check failure on line 33 in subgraphs/erc20/src/mappings/token.ts

View workflow job for this annotation

GitHub Actions / LintStagedFiles

'token' is never reassigned. Use 'const' instead

if (token != null) {
if (token.name == "") {
let erc20 = ERC20.bind(event.address);

Check failure on line 37 in subgraphs/erc20/src/mappings/token.ts

View workflow job for this annotation

GitHub Actions / LintStagedFiles

'erc20' is never reassigned. Use 'const' instead
let tokenName = erc20.try_name();

Check failure on line 38 in subgraphs/erc20/src/mappings/token.ts

View workflow job for this annotation

GitHub Actions / LintStagedFiles

'tokenName' is never reassigned. Use 'const' instead
let tokenSymbol = erc20.try_symbol();

Check failure on line 39 in subgraphs/erc20/src/mappings/token.ts

View workflow job for this annotation

GitHub Actions / LintStagedFiles

'tokenSymbol' is never reassigned. Use 'const' instead
let tokenDecimals = erc20.try_decimals();

Check failure on line 40 in subgraphs/erc20/src/mappings/token.ts

View workflow job for this annotation

GitHub Actions / LintStagedFiles

'tokenDecimals' is never reassigned. Use 'const' instead

token.name = tokenName.reverted ? "" : tokenName.value;
token.symbol = tokenSymbol.reverted ? "" : tokenSymbol.value;
Expand All @@ -50,11 +50,11 @@
if (event.params.value == BIGINT_ZERO) {
return;
}
let amount = event.params.value;

Check failure on line 53 in subgraphs/erc20/src/mappings/token.ts

View workflow job for this annotation

GitHub Actions / LintStagedFiles

'amount' is never reassigned. Use 'const' instead

let isBurn = event.params.to.toHex() == GENESIS_ADDRESS;

Check failure on line 55 in subgraphs/erc20/src/mappings/token.ts

View workflow job for this annotation

GitHub Actions / LintStagedFiles

'isBurn' is never reassigned. Use 'const' instead
let isMint = event.params.from.toHex() == GENESIS_ADDRESS;

Check failure on line 56 in subgraphs/erc20/src/mappings/token.ts

View workflow job for this annotation

GitHub Actions / LintStagedFiles

'isMint' is never reassigned. Use 'const' instead
let isTransfer = !isBurn && !isMint;

Check failure on line 57 in subgraphs/erc20/src/mappings/token.ts

View workflow job for this annotation

GitHub Actions / LintStagedFiles

'isTransfer' is never reassigned. Use 'const' instead
let isEventProcessed = false;

if (isBurn) {
Expand Down Expand Up @@ -320,20 +320,15 @@
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)
dhruv-chauhan marked this conversation as resolved.
Show resolved Hide resolved
.plus(toBalanceIsZeroNum);
token.cumulativeHolderCount = token.cumulativeHolderCount.plus(
toAddressIsNewHolderNum
Expand All @@ -343,7 +338,6 @@
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 @@
let hourlySnapshot = getOrCreateTokenHourlySnapshot(token, event.block);
hourlySnapshot.currentHolderCount = hourlySnapshot.currentHolderCount
.minus(FromBalanceToZeroNum)
.plus(toAddressIsNewHolderNum)
.plus(toBalanceIsZeroNum);
hourlySnapshot.cumulativeHolderCount =
hourlySnapshot.cumulativeHolderCount.plus(toAddressIsNewHolderNum);
Expand Down
Loading