Skip to content

Commit

Permalink
[SUBGRAPH] fix missing token name/symbol (#2017)
Browse files Browse the repository at this point in the history
  • Loading branch information
d10r authored Sep 9, 2024
1 parent 6e19531 commit 2b2fe84
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
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

0 comments on commit 2b2fe84

Please sign in to comment.