From a4d33c66d30ffb444501d1f5b024e1eece716d0a Mon Sep 17 00:00:00 2001 From: 0xdavinchee <0xdavinchee@gmail.com> Date: Wed, 27 Mar 2024 11:31:25 +0200 Subject: [PATCH] [SUBGRAPH] isToken must not be null (#1917) * isToken must not be null * lil optimizations --- packages/subgraph/src/mappings/resolver.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/subgraph/src/mappings/resolver.ts b/packages/subgraph/src/mappings/resolver.ts index b66a68290a..e814f18560 100644 --- a/packages/subgraph/src/mappings/resolver.ts +++ b/packages/subgraph/src/mappings/resolver.ts @@ -42,20 +42,28 @@ export function handleRoleRevoked(event: RoleRevoked): void { ev.save(); } +function getIsToken(id: string): boolean { + return Token.load(id) != null; +} + function getOrInitResolverEntry(id: string, target: Address, block: ethereum.Block): ResolverEntry { let resolverEntry = ResolverEntry.load(id); + const isListed = target.notEqual(ZERO_ADDRESS); + if (resolverEntry == null) { resolverEntry = new ResolverEntry(id); resolverEntry.createdAtBlockNumber = block.number; resolverEntry.createdAtTimestamp = block.timestamp; resolverEntry.targetAddress = target; + // on initialization, we are unlikely to set this to zero address + // if we do, this gets fixed in subsequent set events + resolverEntry.isToken = getIsToken(target.toHex()); } - const isListed = target.notEqual(ZERO_ADDRESS); // we only update this if the target is not equal to the zero address if (isListed) { - resolverEntry.isToken = Token.load(target.toHex()) != null; + resolverEntry.isToken = getIsToken(target.toHex()); } resolverEntry.updatedAtBlockNumber = block.number; resolverEntry.updatedAtTimestamp = block.timestamp;