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

[SUBGRAPH] fix missing token name/symbol #2017

Merged
merged 4 commits into from
Sep 9, 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
27 changes: 13 additions & 14 deletions packages/subgraph/src/mappingHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Address, BigInt, ethereum } from "@graphprotocol/graph-ts";
import { Address, BigInt, ethereum, log } from "@graphprotocol/graph-ts";
import { FlowUpdated } from "../generated/ConstantFlowAgreementV1/IConstantFlowAgreementV1";
import { ISuperfluid as Superfluid } from "../generated/Host/ISuperfluid";
import {
Expand Down Expand Up @@ -43,7 +43,8 @@ import {
getStreamID,
getStreamRevisionID,
getSubscriptionID,
handleTokenRPCCalls
handleTokenRPCCalls,
getTokenInfoAndReturn,
} from "./utils";

/**************************************************************************
Expand Down Expand Up @@ -101,6 +102,7 @@ export function getOrInitSuperToken(
const resolverAddress = getResolverAddress();

if (token == null) {
log.info("Init SuperToken {} triggered by event {}", [tokenAddress.toHexString(), triggeredByEventName]);
// Note: this is necessary otherwise we will not be able to capture
// template data source events.
SuperTokenTemplate.create(tokenAddress);
Expand Down Expand Up @@ -145,17 +147,14 @@ export function getOrInitSuperToken(
let address = Address.fromString(underlyingAddress.toHexString());
getOrInitToken(address, block, resolverAddress);
}
return token as Token;
}

if (token.symbol == "") {
const tokenContract = SuperToken.bind(tokenAddress);
const symbolResult = tokenContract.try_symbol();
token.symbol = symbolResult.reverted ? "" : symbolResult.value;
} else if (token.name.length == 0 && token.symbol.length == 0) {
// custom SuperTokens may emit the factory event before the token is initialized, resulting in empty name and symbol.
// In such cases, this branch allows is to be updated once set.
log.info("Trying to update SuperToken {} with empty name or symbol", [tokenId]);
token = getTokenInfoAndReturn(token);
token.save();
}

token.save();

return token as Token;
}

Expand Down Expand Up @@ -532,7 +531,7 @@ export function getOrInitOrUpdatePoolMember(
poolMember = new PoolMember(poolMemberID);
poolMember.createdAtTimestamp = event.block.timestamp;
poolMember.createdAtBlockNumber = event.block.number;

poolMember.units = BIG_INT_ZERO;
poolMember.isConnected = false;
poolMember.totalAmountClaimed = BIG_INT_ZERO;
Expand All @@ -547,10 +546,10 @@ export function getOrInitOrUpdatePoolMember(
}
poolMember.updatedAtTimestamp = event.block.timestamp;
poolMember.updatedAtBlockNumber = event.block.number;

poolMember.updatedAtTimestamp = event.block.timestamp;
poolMember.updatedAtBlockNumber = event.block.number;

return poolMember;
}

Expand Down
2 changes: 2 additions & 0 deletions packages/subgraph/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ export function getTokenInfoAndReturn(token: Token): Token {
token.symbol = symbolResult.reverted ? "" : symbolResult.value;
token.decimals = decimalsResult.reverted ? 0 : decimalsResult.value;

log.info("Got token info: underlying {}, name {}, symbol {}, decimals {}", [token.underlyingAddress.toHexString(), token.name, token.symbol, token.decimals.toString()]);

return token;
}

Expand Down
Loading