From 0cb3fd9584c1817b68e79ad8225c0f3a2f50686a Mon Sep 17 00:00:00 2001 From: 0xdavinchee <0xdavinchee@gmail.com> Date: Wed, 27 Mar 2024 11:05:03 +0200 Subject: [PATCH 1/2] isToken must not be null --- packages/subgraph/src/mappings/resolver.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/subgraph/src/mappings/resolver.ts b/packages/subgraph/src/mappings/resolver.ts index b66a68290a..63248c78bc 100644 --- a/packages/subgraph/src/mappings/resolver.ts +++ b/packages/subgraph/src/mappings/resolver.ts @@ -45,17 +45,22 @@ export function handleRoleRevoked(event: RoleRevoked): void { function getOrInitResolverEntry(id: string, target: Address, block: ethereum.Block): ResolverEntry { let resolverEntry = ResolverEntry.load(id); + const isListed = target.notEqual(ZERO_ADDRESS); + const isToken = Token.load(target.toHex()) != null; + 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 = isToken; } - 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 = isToken; } resolverEntry.updatedAtBlockNumber = block.number; resolverEntry.updatedAtTimestamp = block.timestamp; From f7710cadb98209fc1dbb5e4368e013e5b48f30a6 Mon Sep 17 00:00:00 2001 From: 0xdavinchee <0xdavinchee@gmail.com> Date: Wed, 27 Mar 2024 11:19:00 +0200 Subject: [PATCH 2/2] lil optimizations --- packages/subgraph/src/mappings/resolver.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/subgraph/src/mappings/resolver.ts b/packages/subgraph/src/mappings/resolver.ts index 63248c78bc..e814f18560 100644 --- a/packages/subgraph/src/mappings/resolver.ts +++ b/packages/subgraph/src/mappings/resolver.ts @@ -42,11 +42,14 @@ 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); - const isToken = Token.load(target.toHex()) != null; if (resolverEntry == null) { resolverEntry = new ResolverEntry(id); @@ -55,12 +58,12 @@ function getOrInitResolverEntry(id: string, target: Address, block: ethereum.Blo 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 = isToken; + resolverEntry.isToken = getIsToken(target.toHex()); } // we only update this if the target is not equal to the zero address if (isListed) { - resolverEntry.isToken = isToken; + resolverEntry.isToken = getIsToken(target.toHex()); } resolverEntry.updatedAtBlockNumber = block.number; resolverEntry.updatedAtTimestamp = block.timestamp;