diff --git a/packages/subgraph/src/mappingHelpers.ts b/packages/subgraph/src/mappingHelpers.ts index 91a1a6e6db..a13d7739cb 100644 --- a/packages/subgraph/src/mappingHelpers.ts +++ b/packages/subgraph/src/mappingHelpers.ts @@ -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 { @@ -43,7 +43,8 @@ import { getStreamID, getStreamRevisionID, getSubscriptionID, - handleTokenRPCCalls + handleTokenRPCCalls, + getTokenInfoAndReturn, } from "./utils"; /************************************************************************** @@ -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); @@ -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; } @@ -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; @@ -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; } diff --git a/packages/subgraph/src/utils.ts b/packages/subgraph/src/utils.ts index f7b84b85e7..fd418ef6e7 100644 --- a/packages/subgraph/src/utils.ts +++ b/packages/subgraph/src/utils.ts @@ -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; }