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 resolver entry #1843

Merged
merged 6 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
25 changes: 0 additions & 25 deletions packages/subgraph/src/mappingHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
Pool,
PoolDistributor,
PoolMember,
ResolverEntry,
Stream,
StreamRevision,
Token,
Expand Down Expand Up @@ -462,30 +461,6 @@ export function getOrInitSubscription(
return subscription as IndexSubscription;
}

export function getOrInitResolverEntry(
id: string,
target: Address,
block: ethereum.Block
): ResolverEntry {
let resolverEntry = ResolverEntry.load(id);

if (resolverEntry == null) {
resolverEntry = new ResolverEntry(id);
resolverEntry.createdAtBlockNumber = block.number;
resolverEntry.createdAtTimestamp = block.timestamp;
resolverEntry.targetAddress = target;

const superToken = Token.load(target.toHex());
resolverEntry.isToken = superToken != null;
}
resolverEntry.updatedAtBlockNumber = block.number;
resolverEntry.updatedAtTimestamp = block.timestamp;
resolverEntry.isListed = target.notEqual(ZERO_ADDRESS);

resolverEntry.save();
return resolverEntry as ResolverEntry;
}

export function getOrInitPool(event: ethereum.Event, poolId: string): Pool {
// get existing pool
let pool = Pool.load(poolId);
Expand Down
47 changes: 29 additions & 18 deletions packages/subgraph/src/mappings/resolver.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import { Bytes, ethereum } from "@graphprotocol/graph-ts";
import {
RoleAdminChanged,
RoleGranted,
RoleRevoked,
Set,
} from "../../generated/ResolverV1/Resolver";
import { Address, Bytes, ethereum } from "@graphprotocol/graph-ts";
import { RoleAdminChanged, RoleGranted, RoleRevoked, Set } from "../../generated/ResolverV1/Resolver";
import {
ResolverEntry,
RoleAdminChangedEvent,
RoleGrantedEvent,
RoleRevokedEvent,
SetEvent,
Token,
} from "../../generated/schema";
import { getOrInitResolverEntry } from "../mappingHelpers";
import { createEventID, initializeEventEntity, ZERO_ADDRESS } from "../utils";

export function handleRoleAdminChanged(event: RoleAdminChanged): void {
Expand Down Expand Up @@ -47,14 +42,34 @@ export function handleRoleRevoked(event: RoleRevoked): void {
ev.save();
}

function getOrInitResolverEntry(id: string, target: Address, block: ethereum.Block): ResolverEntry {
let resolverEntry = ResolverEntry.load(id);

if (resolverEntry == null) {
resolverEntry = new ResolverEntry(id);
resolverEntry.createdAtBlockNumber = block.number;
resolverEntry.createdAtTimestamp = block.timestamp;
resolverEntry.targetAddress = target;
}
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.updatedAtBlockNumber = block.number;
resolverEntry.updatedAtTimestamp = block.timestamp;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it ok to always update when getOrInit is called? it's called in very few places?

resolverEntry.isListed = isListed;

resolverEntry.save();

return resolverEntry as ResolverEntry;
}

export function handleSet(event: Set): void {
_createSetEvent(event, event.params.target, event.params.name);

const resolverEntry = getOrInitResolverEntry(
event.params.name.toHex(),
event.params.target,
event.block
);
const resolverEntry = getOrInitResolverEntry(event.params.name.toHex(), event.params.target, event.block);

// upon initial setting, we will know if this address belongs to a token contract
if (resolverEntry.isToken) {
Expand All @@ -80,11 +95,7 @@ export function handleSet(event: Set): void {
resolverEntry.save();
}

function _createSetEvent(
event: ethereum.Event,
target: Bytes,
name: Bytes
): void {
function _createSetEvent(event: ethereum.Event, target: Bytes, name: Bytes): void {
const eventId = createEventID("Set", event);
const ev = new SetEvent(eventId);
initializeEventEntity(ev, event, [target]);
Expand Down
Loading