From 15cc20df8c0c47410d72e8e47fe89d4250cfc29f Mon Sep 17 00:00:00 2001 From: Harpal Jadeja Date: Fri, 14 Oct 2022 22:34:07 +0530 Subject: [PATCH 01/10] fix: `ownedBy` typo --- src/lens-hub.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lens-hub.ts b/src/lens-hub.ts index 73448e2..fdc1101 100644 --- a/src/lens-hub.ts +++ b/src/lens-hub.ts @@ -43,9 +43,9 @@ export function handleProfileCreated(event: ProfileCreated): void { profile = new Profile(event.params.profileId.toString()) profile.metadata = event.params.followNFTURI profile.handle = event.params.handle - profile.onwnedBy = event.params.creator.toHexString() + profile.ownedBy = event.params.creator.toHexString() profile.isDefault = true profile.isFollowedByMe = false profile.save() } -} \ No newline at end of file +} From e8700b47792f92f06ac67a2c7dfd26f236881ccd Mon Sep 17 00:00:00 2001 From: Matthew Date: Wed, 9 Nov 2022 22:11:40 +0800 Subject: [PATCH 02/10] Introduce handle comment created --- src/lens-hub.ts | 129 +++++++++++++++++++++++++++++------------------- 1 file changed, 77 insertions(+), 52 deletions(-) diff --git a/src/lens-hub.ts b/src/lens-hub.ts index e3dfbd3..81cb020 100644 --- a/src/lens-hub.ts +++ b/src/lens-hub.ts @@ -1,70 +1,95 @@ import { log } from "@graphprotocol/graph-ts"; import { - Approval as ApprovalEvent, - ApprovalForAll as ApprovalForAllEvent, - PostCreated, - ProfileCreated, - Transfer as TransferEvent -} from "../generated/LensHub/LensHub" -import { Approval, ApprovalForAll, Post, Profile, Transfer } from "../generated/schema" + Approval as ApprovalEvent, + ApprovalForAll as ApprovalForAllEvent, + CommentCreated, + PostCreated, + ProfileCreated, + Transfer as TransferEvent, +} from "../generated/LensHub/LensHub"; +import { + Approval, + ApprovalForAll, + Comment, + Post, + Profile, + Transfer, +} from "../generated/schema"; export function handleApproval(event: ApprovalEvent): void { - let entity = new Approval( - event.transaction.hash.toHex() + "-" + event.logIndex.toString() - ) - entity.owner = event.params.owner - entity.approved = event.params.approved - entity.tokenId = event.params.tokenId - entity.save() + let entity = new Approval( + event.transaction.hash.toHex() + "-" + event.logIndex.toString() + ); + entity.owner = event.params.owner; + entity.approved = event.params.approved; + entity.tokenId = event.params.tokenId; + entity.save(); } export function handleApprovalForAll(event: ApprovalForAllEvent): void { - let entity = new ApprovalForAll( - event.transaction.hash.toHex() + "-" + event.logIndex.toString() - ) - entity.owner = event.params.owner - entity.operator = event.params.operator - entity.approved = event.params.approved - entity.save() + let entity = new ApprovalForAll( + event.transaction.hash.toHex() + "-" + event.logIndex.toString() + ); + entity.owner = event.params.owner; + entity.operator = event.params.operator; + entity.approved = event.params.approved; + entity.save(); } export function handleTransfer(event: TransferEvent): void { - let entity = new Transfer( - event.transaction.hash.toHex() + "-" + event.logIndex.toString() - ) - entity.from = event.params.from - entity.to = event.params.to - entity.tokenId = event.params.tokenId - entity.save() + let entity = new Transfer( + event.transaction.hash.toHex() + "-" + event.logIndex.toString() + ); + entity.from = event.params.from; + entity.to = event.params.to; + entity.tokenId = event.params.tokenId; + entity.save(); } export function handleProfileCreated(event: ProfileCreated): void { - let profile = Profile.load(event.params.profileId.toString()) - log.info("Trigger Fired", []) + let profile = Profile.load(event.params.profileId.toString()); + log.info("Trigger Fired", []); - if(!profile) { - profile = new Profile(event.params.profileId.toString()) - profile.metadata = event.params.followNFTURI - profile.handle = event.params.handle - profile.onwnedBy = event.params.creator.toHexString() - profile.isDefault = true - profile.isFollowedByMe = false - profile.save() - } + if (!profile) { + profile = new Profile(event.params.profileId.toString()); + profile.metadata = event.params.followNFTURI; + profile.handle = event.params.handle; + profile.onwnedBy = event.params.creator.toHexString(); + profile.isDefault = true; + profile.isFollowedByMe = false; + profile.save(); + } } export function handlePostCreated(event: PostCreated): void { - let post = Post.load(event.params.pubId.toString()) + let post = Post.load(event.params.pubId.toString()); + + if (!post) { + post = new Post(event.params.pubId.toString()); + post.id = event.params.pubId.toString(); + post.onChainContentURI = event.params.contentURI; + post.createdAt = event.params.timestamp.toString(); + post.profile = event.params.profileId.toString(); + post.collectNftAddress = event.params.collectModule.toHexString(); + // post.metadata = event.params.referenceModule + // post.appId = event.params.referenceModule.toString() + post.save(); + } +} - if(!post) { - post = new Post(event.params.pubId.toString()) - post.id = event.params.pubId.toString() - post.onChainContentURI = event.params.contentURI - post.createdAt = event.params.timestamp.toString() - post.profile = event.params.profileId.toString() - post.collectNftAddress = event.params.collectModule.toHexString() - // post.metadata = event.params.referenceModule - // post.appId = event.params.referenceModule.toString() - post.save() - } -} \ No newline at end of file +export function handleCommentCreated(event: CommentCreated): void { + let comment = Comment.load(event.params.pubId.toString()); + + if (!comment) { + comment = new Comment(event.params.pubId.toString()); + comment.createdAt = event.params.timestamp.toString(); + comment.profile = event.params.profileId.toString(); + comment.onChainContentURI = event.params.contentURI.toString(); + + comment.collectModule = event.params.collectModule.toString(); + comment.referenceModule = event.params.referenceModule.toString(); + comment.publication = event.params.pubIdPointed.toString(); + comment.profilePointed = event.params.profileIdPointed.toString(); + comment.save(); + } +} From a05240f19874ed7243fc70805821977d15278474 Mon Sep 17 00:00:00 2001 From: Matthew Date: Wed, 9 Nov 2022 23:14:09 +0800 Subject: [PATCH 03/10] Clean up schema & introduce mirror event handler --- generated/schema.ts | 685 ++++++++++++-------------------------------- schema.graphql | 509 ++++++++++++++++---------------- src/lens-hub.ts | 73 ++++- 3 files changed, 501 insertions(+), 766 deletions(-) diff --git a/generated/schema.ts b/generated/schema.ts index b8c4ac4..0f0061d 100644 --- a/generated/schema.ts +++ b/generated/schema.ts @@ -952,253 +952,6 @@ export class Attribute extends Entity { } } -export class Profile extends Entity { - constructor(id: string) { - super(); - this.set("id", Value.fromString(id)); - } - - save(): void { - let id = this.get("id"); - assert(id != null, "Cannot save Profile entity without an ID"); - if (id) { - assert( - id.kind == ValueKind.STRING, - `Entities of type Profile must have an ID of type String but the id '${id.displayData()}' is of type ${id.displayKind()}` - ); - store.set("Profile", id.toString(), this); - } - } - - static load(id: string): Profile | null { - return changetype(store.get("Profile", id)); - } - - get id(): string { - let value = this.get("id"); - return value!.toString(); - } - - set id(value: string) { - this.set("id", Value.fromString(value)); - } - - get name(): string | null { - let value = this.get("name"); - if (!value || value.kind == ValueKind.NULL) { - return null; - } else { - return value.toString(); - } - } - - set name(value: string | null) { - if (!value) { - this.unset("name"); - } else { - this.set("name", Value.fromString(value)); - } - } - - get bio(): string | null { - let value = this.get("bio"); - if (!value || value.kind == ValueKind.NULL) { - return null; - } else { - return value.toString(); - } - } - - set bio(value: string | null) { - if (!value) { - this.unset("bio"); - } else { - this.set("bio", Value.fromString(value)); - } - } - - get followNftAddress(): string | null { - let value = this.get("followNftAddress"); - if (!value || value.kind == ValueKind.NULL) { - return null; - } else { - return value.toString(); - } - } - - set followNftAddress(value: string | null) { - if (!value) { - this.unset("followNftAddress"); - } else { - this.set("followNftAddress", Value.fromString(value)); - } - } - - get metadata(): string | null { - let value = this.get("metadata"); - if (!value || value.kind == ValueKind.NULL) { - return null; - } else { - return value.toString(); - } - } - - set metadata(value: string | null) { - if (!value) { - this.unset("metadata"); - } else { - this.set("metadata", Value.fromString(value)); - } - } - - get handle(): string { - let value = this.get("handle"); - return value!.toString(); - } - - set handle(value: string) { - this.set("handle", Value.fromString(value)); - } - - get picture(): string | null { - let value = this.get("picture"); - if (!value || value.kind == ValueKind.NULL) { - return null; - } else { - return value.toString(); - } - } - - set picture(value: string | null) { - if (!value) { - this.unset("picture"); - } else { - this.set("picture", Value.fromString(value)); - } - } - - get coverPicture(): string | null { - let value = this.get("coverPicture"); - if (!value || value.kind == ValueKind.NULL) { - return null; - } else { - return value.toString(); - } - } - - set coverPicture(value: string | null) { - if (!value) { - this.unset("coverPicture"); - } else { - this.set("coverPicture", Value.fromString(value)); - } - } - - get onwnedBy(): string { - let value = this.get("onwnedBy"); - return value!.toString(); - } - - set onwnedBy(value: string) { - this.set("onwnedBy", Value.fromString(value)); - } - - get dispatcher(): string | null { - let value = this.get("dispatcher"); - if (!value || value.kind == ValueKind.NULL) { - return null; - } else { - return value.toString(); - } - } - - set dispatcher(value: string | null) { - if (!value) { - this.unset("dispatcher"); - } else { - this.set("dispatcher", Value.fromString(value)); - } - } - - get stats(): string | null { - let value = this.get("stats"); - if (!value || value.kind == ValueKind.NULL) { - return null; - } else { - return value.toString(); - } - } - - set stats(value: string | null) { - if (!value) { - this.unset("stats"); - } else { - this.set("stats", Value.fromString(value)); - } - } - - get followModule(): string | null { - let value = this.get("followModule"); - if (!value || value.kind == ValueKind.NULL) { - return null; - } else { - return value.toString(); - } - } - - set followModule(value: string | null) { - if (!value) { - this.unset("followModule"); - } else { - this.set("followModule", Value.fromString(value)); - } - } - - get isDefault(): boolean { - let value = this.get("isDefault"); - return value!.toBoolean(); - } - - set isDefault(value: boolean) { - this.set("isDefault", Value.fromBoolean(value)); - } - - get attributes(): Array | null { - let value = this.get("attributes"); - if (!value || value.kind == ValueKind.NULL) { - return null; - } else { - return value.toStringArray(); - } - } - - set attributes(value: Array | null) { - if (!value) { - this.unset("attributes"); - } else { - this.set("attributes", Value.fromStringArray(>value)); - } - } - - get isFollowedByMe(): boolean { - let value = this.get("isFollowedByMe"); - return value!.toBoolean(); - } - - set isFollowedByMe(value: boolean) { - this.set("isFollowedByMe", Value.fromBoolean(value)); - } - - get isFollowingMe(): boolean { - let value = this.get("isFollowingMe"); - return value!.toBoolean(); - } - - set isFollowingMe(value: boolean) { - this.set("isFollowingMe", Value.fromBoolean(value)); - } -} - export class PublicationStats extends Entity { constructor(id: string) { super(); @@ -2179,7 +1932,7 @@ export class FollowOnlyReferenceModuleSettings extends Entity { } } -export class Mirror extends Entity { +export class Profile extends Entity { constructor(id: string) { super(); this.set("id", Value.fromString(id)); @@ -2187,18 +1940,18 @@ export class Mirror extends Entity { save(): void { let id = this.get("id"); - assert(id != null, "Cannot save Mirror entity without an ID"); + assert(id != null, "Cannot save Profile entity without an ID"); if (id) { assert( id.kind == ValueKind.STRING, - `Entities of type Mirror must have an ID of type String but the id '${id.displayData()}' is of type ${id.displayKind()}` + `Entities of type Profile must have an ID of type String but the id '${id.displayData()}' is of type ${id.displayKind()}` ); - store.set("Mirror", id.toString(), this); + store.set("Profile", id.toString(), this); } } - static load(id: string): Mirror | null { - return changetype(store.get("Mirror", id)); + static load(id: string): Profile | null { + return changetype(store.get("Profile", id)); } get id(): string { @@ -2210,96 +1963,95 @@ export class Mirror extends Entity { this.set("id", Value.fromString(value)); } - get profile(): string { - let value = this.get("profile"); - return value!.toString(); - } - - set profile(value: string) { - this.set("profile", Value.fromString(value)); - } - - get stats(): string { - let value = this.get("stats"); + get createdAt(): string { + let value = this.get("createdAt"); return value!.toString(); } - set stats(value: string) { - this.set("stats", Value.fromString(value)); + set createdAt(value: string) { + this.set("createdAt", Value.fromString(value)); } - get metadata(): string { - let value = this.get("metadata"); + get creator(): string { + let value = this.get("creator"); return value!.toString(); } - set metadata(value: string) { - this.set("metadata", Value.fromString(value)); + set creator(value: string) { + this.set("creator", Value.fromString(value)); } - get onChainContentURI(): string { - let value = this.get("onChainContentURI"); + get mintedTo(): string { + let value = this.get("mintedTo"); return value!.toString(); } - set onChainContentURI(value: string) { - this.set("onChainContentURI", Value.fromString(value)); + set mintedTo(value: string) { + this.set("mintedTo", Value.fromString(value)); } - get createdAt(): string { - let value = this.get("createdAt"); + get handle(): string { + let value = this.get("handle"); return value!.toString(); } - set createdAt(value: string) { - this.set("createdAt", Value.fromString(value)); + set handle(value: string) { + this.set("handle", Value.fromString(value)); } - get appId(): BigInt | null { - let value = this.get("appId"); + get picture(): string | null { + let value = this.get("picture"); if (!value || value.kind == ValueKind.NULL) { return null; } else { - return value.toBigInt(); + return value.toString(); } } - set appId(value: BigInt | null) { + set picture(value: string | null) { if (!value) { - this.unset("appId"); + this.unset("picture"); } else { - this.set("appId", Value.fromBigInt(value)); + this.set("picture", Value.fromString(value)); } } - get hidden(): boolean { - let value = this.get("hidden"); - return value!.toBoolean(); + get followModule(): string | null { + let value = this.get("followModule"); + if (!value || value.kind == ValueKind.NULL) { + return null; + } else { + return value.toString(); + } } - set hidden(value: boolean) { - this.set("hidden", Value.fromBoolean(value)); + set followModule(value: string | null) { + if (!value) { + this.unset("followModule"); + } else { + this.set("followModule", Value.fromString(value)); + } } - get collectNftAddress(): string | null { - let value = this.get("collectNftAddress"); + get followModuleReturnData(): Bytes | null { + let value = this.get("followModuleReturnData"); if (!value || value.kind == ValueKind.NULL) { return null; } else { - return value.toString(); + return value.toBytes(); } } - set collectNftAddress(value: string | null) { + set followModuleReturnData(value: Bytes | null) { if (!value) { - this.unset("collectNftAddress"); + this.unset("followModuleReturnData"); } else { - this.set("collectNftAddress", Value.fromString(value)); + this.set("followModuleReturnData", Value.fromBytes(value)); } } - get reaction(): string | null { - let value = this.get("reaction"); + get followNftUri(): string | null { + let value = this.get("followNftUri"); if (!value || value.kind == ValueKind.NULL) { return null; } else { @@ -2307,25 +2059,43 @@ export class Mirror extends Entity { } } - set reaction(value: string | null) { + set followNftUri(value: string | null) { if (!value) { - this.unset("reaction"); + this.unset("followNftUri"); } else { - this.set("reaction", Value.fromString(value)); + this.set("followNftUri", Value.fromString(value)); } } - get hasCollectedByMe(): boolean { - let value = this.get("hasCollectedByMe"); - return value!.toBoolean(); + get posts(): Array { + let value = this.get("posts"); + return value!.toStringArray(); + } + + set posts(value: Array) { + this.set("posts", Value.fromStringArray(value)); + } + + get comments(): Array { + let value = this.get("comments"); + return value!.toStringArray(); + } + + set comments(value: Array) { + this.set("comments", Value.fromStringArray(value)); } - set hasCollectedByMe(value: boolean) { - this.set("hasCollectedByMe", Value.fromBoolean(value)); + get mirrors(): Array { + let value = this.get("mirrors"); + return value!.toStringArray(); + } + + set mirrors(value: Array) { + this.set("mirrors", Value.fromStringArray(value)); } } -export class Post extends Entity { +export class Mirror extends Entity { constructor(id: string) { super(); this.set("id", Value.fromString(id)); @@ -2333,18 +2103,18 @@ export class Post extends Entity { save(): void { let id = this.get("id"); - assert(id != null, "Cannot save Post entity without an ID"); + assert(id != null, "Cannot save Mirror entity without an ID"); if (id) { assert( id.kind == ValueKind.STRING, - `Entities of type Post must have an ID of type String but the id '${id.displayData()}' is of type ${id.displayKind()}` + `Entities of type Mirror must have an ID of type String but the id '${id.displayData()}' is of type ${id.displayKind()}` ); - store.set("Post", id.toString(), this); + store.set("Mirror", id.toString(), this); } } - static load(id: string): Post | null { - return changetype(store.get("Post", id)); + static load(id: string): Mirror | null { + return changetype(store.get("Mirror", id)); } get id(): string { @@ -2356,77 +2126,112 @@ export class Post extends Entity { this.set("id", Value.fromString(value)); } - get profile(): string | null { + get profile(): string { let value = this.get("profile"); - if (!value || value.kind == ValueKind.NULL) { - return null; - } else { - return value.toString(); - } + return value!.toString(); } - set profile(value: string | null) { - if (!value) { - this.unset("profile"); - } else { - this.set("profile", Value.fromString(value)); - } + set profile(value: string) { + this.set("profile", Value.fromString(value)); } - get stats(): string | null { - let value = this.get("stats"); - if (!value || value.kind == ValueKind.NULL) { - return null; - } else { - return value.toString(); - } + get createdAt(): string { + let value = this.get("createdAt"); + return value!.toString(); } - set stats(value: string | null) { - if (!value) { - this.unset("stats"); - } else { - this.set("stats", Value.fromString(value)); - } + set createdAt(value: string) { + this.set("createdAt", Value.fromString(value)); } - get metadata(): string | null { - let value = this.get("metadata"); - if (!value || value.kind == ValueKind.NULL) { - return null; - } else { - return value.toString(); - } + get referenceModule(): string { + let value = this.get("referenceModule"); + return value!.toString(); } - set metadata(value: string | null) { - if (!value) { - this.unset("metadata"); - } else { - this.set("metadata", Value.fromString(value)); + set referenceModule(value: string) { + this.set("referenceModule", Value.fromString(value)); + } + + get referenceModuleReturnData(): Bytes { + let value = this.get("referenceModuleReturnData"); + return value!.toBytes(); + } + + set referenceModuleReturnData(value: Bytes) { + this.set("referenceModuleReturnData", Value.fromBytes(value)); + } + + get profilePointed(): string { + let value = this.get("profilePointed"); + return value!.toString(); + } + + set profilePointed(value: string) { + this.set("profilePointed", Value.fromString(value)); + } + + get publicationPointed(): string { + let value = this.get("publicationPointed"); + return value!.toString(); + } + + set publicationPointed(value: string) { + this.set("publicationPointed", Value.fromString(value)); + } +} + +export class Post extends Entity { + constructor(id: string) { + super(); + this.set("id", Value.fromString(id)); + } + + save(): void { + let id = this.get("id"); + assert(id != null, "Cannot save Post entity without an ID"); + if (id) { + assert( + id.kind == ValueKind.STRING, + `Entities of type Post must have an ID of type String but the id '${id.displayData()}' is of type ${id.displayKind()}` + ); + store.set("Post", id.toString(), this); } } - get onChainContentURI(): string { - let value = this.get("onChainContentURI"); + static load(id: string): Post | null { + return changetype(store.get("Post", id)); + } + + get id(): string { + let value = this.get("id"); return value!.toString(); } - set onChainContentURI(value: string) { - this.set("onChainContentURI", Value.fromString(value)); + set id(value: string) { + this.set("id", Value.fromString(value)); } - get createdAt(): string { - let value = this.get("createdAt"); + get profile(): string { + let value = this.get("profile"); return value!.toString(); } - set createdAt(value: string) { - this.set("createdAt", Value.fromString(value)); + set profile(value: string) { + this.set("profile", Value.fromString(value)); + } + + get contentUri(): string { + let value = this.get("contentUri"); + return value!.toString(); } - get appId(): string | null { - let value = this.get("appId"); + set contentUri(value: string) { + this.set("contentUri", Value.fromString(value)); + } + + get collectModule(): string | null { + let value = this.get("collectModule"); if (!value || value.kind == ValueKind.NULL) { return null; } else { @@ -2434,42 +2239,33 @@ export class Post extends Entity { } } - set appId(value: string | null) { + set collectModule(value: string | null) { if (!value) { - this.unset("appId"); + this.unset("collectModule"); } else { - this.set("appId", Value.fromString(value)); + this.set("collectModule", Value.fromString(value)); } } - get hidden(): boolean { - let value = this.get("hidden"); - return value!.toBoolean(); - } - - set hidden(value: boolean) { - this.set("hidden", Value.fromBoolean(value)); - } - - get collectNftAddress(): string | null { - let value = this.get("collectNftAddress"); + get collectModuleReturnData(): Bytes | null { + let value = this.get("collectModuleReturnData"); if (!value || value.kind == ValueKind.NULL) { return null; } else { - return value.toString(); + return value.toBytes(); } } - set collectNftAddress(value: string | null) { + set collectModuleReturnData(value: Bytes | null) { if (!value) { - this.unset("collectNftAddress"); + this.unset("collectModuleReturnData"); } else { - this.set("collectNftAddress", Value.fromString(value)); + this.set("collectModuleReturnData", Value.fromBytes(value)); } } - get collectedBy(): string | null { - let value = this.get("collectedBy"); + get referenceModule(): string | null { + let value = this.get("referenceModule"); if (!value || value.kind == ValueKind.NULL) { return null; } else { @@ -2477,38 +2273,38 @@ export class Post extends Entity { } } - set collectedBy(value: string | null) { + set referenceModule(value: string | null) { if (!value) { - this.unset("collectedBy"); + this.unset("referenceModule"); } else { - this.set("collectedBy", Value.fromString(value)); + this.set("referenceModule", Value.fromString(value)); } } - get reaction(): string | null { - let value = this.get("reaction"); + get referenceModuleReturnData(): Bytes | null { + let value = this.get("referenceModuleReturnData"); if (!value || value.kind == ValueKind.NULL) { return null; } else { - return value.toString(); + return value.toBytes(); } } - set reaction(value: string | null) { + set referenceModuleReturnData(value: Bytes | null) { if (!value) { - this.unset("reaction"); + this.unset("referenceModuleReturnData"); } else { - this.set("reaction", Value.fromString(value)); + this.set("referenceModuleReturnData", Value.fromBytes(value)); } } - get hasCollectedByMe(): boolean { - let value = this.get("hasCollectedByMe"); - return value!.toBoolean(); + get createdAt(): string { + let value = this.get("createdAt"); + return value!.toString(); } - set hasCollectedByMe(value: boolean) { - this.set("hasCollectedByMe", Value.fromBoolean(value)); + set createdAt(value: string) { + this.set("createdAt", Value.fromString(value)); } get mirrors(): Array | null { @@ -2639,111 +2435,6 @@ export class Comment extends Entity { set profilePointed(value: string) { this.set("profilePointed", Value.fromString(value)); } - - get stats(): string { - let value = this.get("stats"); - return value!.toString(); - } - - set stats(value: string) { - this.set("stats", Value.fromString(value)); - } - - get metadata(): string { - let value = this.get("metadata"); - return value!.toString(); - } - - set metadata(value: string) { - this.set("metadata", Value.fromString(value)); - } - - get firstComment(): string | null { - let value = this.get("firstComment"); - if (!value || value.kind == ValueKind.NULL) { - return null; - } else { - return value.toString(); - } - } - - set firstComment(value: string | null) { - if (!value) { - this.unset("firstComment"); - } else { - this.set("firstComment", Value.fromString(value)); - } - } - - get appId(): string { - let value = this.get("appId"); - return value!.toString(); - } - - set appId(value: string) { - this.set("appId", Value.fromString(value)); - } - - get hidden(): boolean { - let value = this.get("hidden"); - return value!.toBoolean(); - } - - set hidden(value: boolean) { - this.set("hidden", Value.fromBoolean(value)); - } - - get collectNftAddress(): string { - let value = this.get("collectNftAddress"); - return value!.toString(); - } - - set collectNftAddress(value: string) { - this.set("collectNftAddress", Value.fromString(value)); - } - - get reaction(): string | null { - let value = this.get("reaction"); - if (!value || value.kind == ValueKind.NULL) { - return null; - } else { - return value.toString(); - } - } - - set reaction(value: string | null) { - if (!value) { - this.unset("reaction"); - } else { - this.set("reaction", Value.fromString(value)); - } - } - - get collectedBy(): string | null { - let value = this.get("collectedBy"); - if (!value || value.kind == ValueKind.NULL) { - return null; - } else { - return value.toString(); - } - } - - set collectedBy(value: string | null) { - if (!value) { - this.unset("collectedBy"); - } else { - this.set("collectedBy", Value.fromString(value)); - } - } - - get hasCollectedByMe(): boolean { - let value = this.get("hasCollectedByMe"); - return value!.toBoolean(); - } - - set hasCollectedByMe(value: boolean) { - this.set("hasCollectedByMe", Value.fromBoolean(value)); - } } export class Owner extends Entity { diff --git a/schema.graphql b/schema.graphql index 0d9a44d..74937f3 100644 --- a/schema.graphql +++ b/schema.graphql @@ -1,351 +1,340 @@ type Approval @entity { - id: ID! - owner: Bytes! # address - approved: Bytes! # address - tokenId: BigInt! # uint256 + id: ID! + owner: Bytes! # address + approved: Bytes! # address + tokenId: BigInt! # uint256 } type ApprovalForAll @entity { - id: ID! - owner: Bytes! # address - operator: Bytes! # address - approved: Boolean! # bool + id: ID! + owner: Bytes! # address + operator: Bytes! # address + approved: Boolean! # bool } type Transfer @entity { - id: ID! - from: Bytes! # address - to: Bytes! # address - tokenId: BigInt! # uint256 + id: ID! + from: Bytes! # address + to: Bytes! # address + tokenId: BigInt! # uint256 } type Dispatcher @entity { - id: ID! - address: String! - canUseRelay: Boolean! + id: ID! + address: String! + canUseRelay: Boolean! } type ProfileStats @entity { - id: ID! - totalFollowers: BigInt! - totalFollowing: BigInt! - totalPosts: BigInt! - totalComments: BigInt! - totalMirrors: BigInt! - totalPublications: BigInt! - totalCollects: BigInt! + id: ID! + totalFollowers: BigInt! + totalFollowing: BigInt! + totalPosts: BigInt! + totalComments: BigInt! + totalMirrors: BigInt! + totalPublications: BigInt! + totalCollects: BigInt! } type NftImage @entity { - id: ID! - contractAddress: String! - tokenId: String! - url: String! - chainId: BigInt! - verified: Boolean! + id: ID! + contractAddress: String! + tokenId: String! + url: String! + chainId: BigInt! + verified: Boolean! } type Media @entity { - id: ID! - url: String! - width: BigInt - height: BigInt - size: BigInt - mimeType: String + id: ID! + url: String! + width: BigInt + height: BigInt + size: BigInt + mimeType: String } type MediaSet @entity { - id: ID! - original: Media! - small: Media - medium: Media + id: ID! + original: Media! + small: Media + medium: Media } enum ProfileMedia { - NftImage - MediaSet + NftImage + MediaSet } type Erc20 @entity { - id: ID! - name: String! - symbol: String! - decimals: BigInt! - address: String! + id: ID! + name: String! + symbol: String! + decimals: BigInt! + address: String! } type ModuleFeeAmount @entity { - id: ID! - asset: Erc20! - vaue: String! + id: ID! + asset: Erc20! + vaue: String! } type FeeFollowModuleSettings @entity { - id: ID! - contractAddress: String! - amount: ModuleFeeAmount! - recipient: String! + id: ID! + contractAddress: String! + amount: ModuleFeeAmount! + recipient: String! } type ProfileFollowModuleSettings @entity { - id: ID! - contractAddress: String! + id: ID! + contractAddress: String! } type RevertFollowModuleSettings @entity { - id: ID! - contractAddress: String! + id: ID! + contractAddress: String! } enum FollowModule { - FeeFollowModuleSettings - ProfileFollowModuleSettings - RevertFollowModuleSettings + FeeFollowModuleSettings + ProfileFollowModuleSettings + RevertFollowModuleSettings } type Attribute @entity { - id: ID! - displayType: String - traitType: String - key: String! - value: String! -} - -type Profile @entity { - id: ID! - name: String - bio: String - followNftAddress: String - metadata: String - handle: String! - picture: ProfileMedia - coverPicture: ProfileMedia - onwnedBy: String! - dispatcher: Dispatcher - stats: ProfileStats - followModule: FollowModule - isDefault: Boolean - attributes: [Attribute!] - isFollowedByMe: Boolean - isFollowingMe: Boolean + id: ID! + displayType: String + traitType: String + key: String! + value: String! } enum ReactionTypes { - UPVOTE - DOWNVOTE + UPVOTE + DOWNVOTE } type PublicationStats @entity { - id: ID! - totalAmountOfMirrors: BigInt! - totalAmountOfCollects: BigInt! - totalAmountOfComments: BigInt! - totalUpvotes: BigInt! - totalDownvotes: BigInt! + id: ID! + totalAmountOfMirrors: BigInt! + totalAmountOfCollects: BigInt! + totalAmountOfComments: BigInt! + totalUpvotes: BigInt! + totalDownvotes: BigInt! } type Wallet @entity { - id: ID! - address: String! - defaulProfile: Profile! + id: ID! + address: String! + defaulProfile: Profile! } enum MetadataDisplayType { - BigInt - String - String + BigInt + String + String } type MetadataAttributeOutput @entity { - id: ID! - displayType: MetadataDisplayType - traitType: String - value: String + id: ID! + displayType: MetadataDisplayType + traitType: String + value: String } type MetadataOutput @entity { - id: ID! - name: String - description: String - content: String - image: String - cover: MediaSet - media: [MediaSet!]! - attributes: [MetadataAttributeOutput!]! + id: ID! + name: String + description: String + content: String + image: String + cover: MediaSet + media: [MediaSet!]! + attributes: [MetadataAttributeOutput!]! } type ReactionFieldResolverRequest @entity { - id: ID! - profileId: BigInt + id: ID! + profileId: BigInt } enum CollectModule { - LimitedFeeCollectModule - FeeCollectModule - LimitedTimedFeeCollectModule - TimedFeeCollectModule - RevertCollectModule - FreeCollectModule + LimitedFeeCollectModule + FeeCollectModule + LimitedTimedFeeCollectModule + TimedFeeCollectModule + RevertCollectModule + FreeCollectModule } type FreeCollectModuleSettings @entity { - id: ID! - type: CollectModule! - contractAddress: String! - followerOnly: Boolean! + id: ID! + type: CollectModule! + contractAddress: String! + followerOnly: Boolean! } type FeeCollectModuleSettings @entity { - id: ID! - type: CollectModule! - contractAddress: String! - amount: ModuleFeeAmount! - recipient: String! - referralFee: BigDecimal! - followerOnly: Boolean! + id: ID! + type: CollectModule! + contractAddress: String! + amount: ModuleFeeAmount! + recipient: String! + referralFee: BigDecimal! + followerOnly: Boolean! } type LimitedFeeCollectModule @entity { - id: ID! - type: CollectModule! - contractAddress: String! - collectLimit: String! - amount: ModuleFeeAmount! - recipient: String! - referralFee: BigDecimal! - followerOnly: Boolean! + id: ID! + type: CollectModule! + contractAddress: String! + collectLimit: String! + amount: ModuleFeeAmount! + recipient: String! + referralFee: BigDecimal! + followerOnly: Boolean! } type LimitedTimedFeeCollectModuleSettings @entity { - id: ID! - type: CollectModule! - contractAddress: String! - collectLimit: String! - amount: ModuleFeeAmount! - recipient: String! - referralFee: BigDecimal! - followerOnly: Boolean! - endTimestamp: String! + id: ID! + type: CollectModule! + contractAddress: String! + collectLimit: String! + amount: ModuleFeeAmount! + recipient: String! + referralFee: BigDecimal! + followerOnly: Boolean! + endTimestamp: String! } type RevertCollectModuleSettings @entity { - id: ID! - type: CollectModule! - contractAddress: String! + id: ID! + type: CollectModule! + contractAddress: String! } type TimedFeeCollectModuleSettings @entity { - id: ID! - type: CollectModule! - contractAddress: String! - amount: ModuleFeeAmount! - recipient: String! - referralFee: BigDecimal! - followerOnly: Boolean! - endTimestamp: String! + id: ID! + type: CollectModule! + contractAddress: String! + amount: ModuleFeeAmount! + recipient: String! + referralFee: BigDecimal! + followerOnly: Boolean! + endTimestamp: String! } enum ReferenceModule { - FollowOnlyReferenceModule + FollowOnlyReferenceModule } type FollowOnlyReferenceModuleSettings @entity { - id: ID! - type: ReferenceModule! - contractAddress: String! + id: ID! + type: ReferenceModule! + contractAddress: String! +} + +# https://docs.lens.xyz/docs/events#profilecreated +type Profile @entity { + id: ID! + + createdAt: String! + + # Wallet address + creator: String! + mintedTo: String! + handle: String! + picture: ProfileMedia + + followModule: FollowModule + followModuleReturnData: Bytes + + followNftUri: String + + posts: [Post!]! + comments: [Comment!]! + mirrors: [Mirror!]! } +# Mirrors should extend "Post" +# https://docs.lens.xyz/docs/mirror type Mirror @entity { - id: ID! - profile: Profile! - stats: PublicationStats! - metadata: MetadataOutput! - onChainContentURI: String! - createdAt: String! - appId: BigInt - hidden: Boolean! - collectNftAddress: String - reaction: ReactionTypes - hasCollectedByMe: Boolean! + id: ID! + profile: Profile! + createdAt: String! + + referenceModule: ReferenceModule! + referenceModuleReturnData: Bytes! + + profilePointed: Profile! + publicationPointed: Post! } type Post @entity { - id: ID! - profile: Profile - stats: PublicationStats - metadata: MetadataOutput - onChainContentURI: String! - createdAt: String! - appId: String - hidden: Boolean - collectNftAddress: String - collectedBy: Wallet - reaction: ReactionTypes - hasCollectedByMe: Boolean - mirrors: [ID!] + id: ID! + profile: Profile! + + contentUri: String! + + # Address + collectModule: CollectModule + collectModuleReturnData: Bytes + + referenceModule: ReferenceModule + referenceModuleReturnData: Bytes + + createdAt: String! + + mirrors: [ID!] } # TODO: We need to make "Comment" extend from "Publication" type Comment @entity { - id: ID! - profile: Profile! - onChainContentURI: String! - createdAt: String! - mirrors: [ID!]! - - # Publication that comment points to - publication: Post! - # Reference module settings for this comment - referenceModule: ReferenceModule - # Collect module settings for this comment - collectModule: CollectModule! - # Profile that comment points to (may be different than comment author) - profilePointed: Profile! - - ##### - # Retrieved from https://graphiql-online.com (Voyager view) - not sure if we need them - stats: PublicationStats! - metadata: MetadataOutput! - - firstComment: Comment - appId: String! - hidden: Boolean! - collectNftAddress: String! - reaction: ReactionTypes - collectedBy: Wallet - ##### - - # Proposal to remove fields - hasCollectedByMe: Boolean! + id: ID! + profile: Profile! + onChainContentURI: String! + createdAt: String! + mirrors: [ID!]! + + # Publication that comment points to + publication: Post! + # Reference module settings for this comment + referenceModule: ReferenceModule + # Collect module settings for this comment + collectModule: CollectModule! + # Profile that comment points to (may be different than comment author) + profilePointed: Profile! } type Owner @entity { - id: ID! - amount: BigDecimal! - address: String! + id: ID! + amount: BigDecimal! + address: String! } type NFTContent @entity { - id: ID! - uri: String! - metaType: String! - animatedUrl: String + id: ID! + uri: String! + metaType: String! + animatedUrl: String } type NFT @entity { - id: ID! - contractName: String! - contractAddress: String! - symbol: String! - tokenId: String! - owners: [Owner!]! - name: String! - description: String! - contentURI: String! - originalContent: NFTContent! - chainId: ID! - collectionName: String! - ercType: String! + id: ID! + contractName: String! + contractAddress: String! + symbol: String! + tokenId: String! + owners: [Owner!]! + name: String! + description: String! + contentURI: String! + originalContent: NFTContent! + chainId: ID! + collectionName: String! + ercType: String! } # Handles @@ -353,38 +342,38 @@ type NFT @entity { # Retrieved from https://graphiql-online.com/voyager-view type ReservedClaimableHandle @entity { - id: ID! - # Requires custom "Handle" scalar type - handle: String! - source: String! - expiry: String! + id: ID! + # Requires custom "Handle" scalar type + handle: String! + source: String! + expiry: String! } type ClaimableHandles @entity { - id: ID! - canClaimFreeTextHandle: Boolean! - claimableHandles: [ReservedClaimableHandle!]! + id: ID! + canClaimFreeTextHandle: Boolean! + claimableHandles: [ReservedClaimableHandle!]! } # Address #13 type TransactionReceipt @entity { - id: ID! - to: String! - from: String! - contractAddress: String - transactionIndex: Int! - root: String - gasUsed: String! - logsBloom: String! - blockHash: String! - transactionHash: String! - blockNumber: Int! - confirmations: Int! - cumulativeGasUsed: String! - effectiveGasPrice: String! - byzantium: Boolean! - type: Int! - status: Int + id: ID! + to: String! + from: String! + contractAddress: String + transactionIndex: Int! + root: String + gasUsed: String! + logsBloom: String! + blockHash: String! + transactionHash: String! + blockNumber: Int! + confirmations: Int! + cumulativeGasUsed: String! + effectiveGasPrice: String! + byzantium: Boolean! + type: Int! + status: Int } diff --git a/src/lens-hub.ts b/src/lens-hub.ts index 81cb020..ff76890 100644 --- a/src/lens-hub.ts +++ b/src/lens-hub.ts @@ -3,6 +3,7 @@ import { Approval as ApprovalEvent, ApprovalForAll as ApprovalForAllEvent, CommentCreated, + MirrorCreated, PostCreated, ProfileCreated, Transfer as TransferEvent, @@ -11,6 +12,7 @@ import { Approval, ApprovalForAll, Comment, + Mirror, Post, Profile, Transfer, @@ -52,11 +54,19 @@ export function handleProfileCreated(event: ProfileCreated): void { if (!profile) { profile = new Profile(event.params.profileId.toString()); - profile.metadata = event.params.followNFTURI; - profile.handle = event.params.handle; - profile.onwnedBy = event.params.creator.toHexString(); - profile.isDefault = true; - profile.isFollowedByMe = false; + profile.handle = event.params.handle.toString(); + profile.creator = event.params.creator.toHexString(); + profile.mintedTo = event.params.to.toHexString(); + profile.picture = event.params.imageURI.toString(); + + profile.createdAt = event.params.timestamp.toString(); + + // Newly set follow module, can be zero address + profile.followModule = event.params.followModule.toHexString(); + profile.followModuleReturnData = event.params.followModuleReturnData; + + profile.followNftUri = event.params.followNFTURI; + profile.save(); } } @@ -67,14 +77,24 @@ export function handlePostCreated(event: PostCreated): void { if (!post) { post = new Post(event.params.pubId.toString()); post.id = event.params.pubId.toString(); - post.onChainContentURI = event.params.contentURI; + post.contentUri = event.params.contentURI; post.createdAt = event.params.timestamp.toString(); post.profile = event.params.profileId.toString(); - post.collectNftAddress = event.params.collectModule.toHexString(); - // post.metadata = event.params.referenceModule - // post.appId = event.params.referenceModule.toString() + + post.collectModule = event.params.collectModule.toHexString(); + post.collectModuleReturnData = event.params.collectModuleReturnData; + + post.referenceModule = event.params.referenceModule.toHexString(); + post.referenceModuleReturnData = event.params.referenceModuleReturnData; + post.save(); } + + let profile = Profile.load(event.params.profileId.toString()); + if (profile) { + profile.posts = (profile.posts ?? []).concat([post.id]); + profile.save(); + } } export function handleCommentCreated(event: CommentCreated): void { @@ -92,4 +112,39 @@ export function handleCommentCreated(event: CommentCreated): void { comment.profilePointed = event.params.profileIdPointed.toString(); comment.save(); } + + let profile = Profile.load(event.params.profileId.toString()); + if (profile) { + profile.comments = (profile.comments ?? []).concat([comment.id]); + profile.save(); + } +} + +export function handleMirrorCreated(event: MirrorCreated): void { + let mirror = Mirror.load(event.params.pubId.toString()); + + if (!mirror) { + mirror = new Mirror(event.params.pubId.toString()); + mirror.profile = event.params.profileId.toString(); + mirror.profilePointed = event.params.profileIdPointed.toString(); + mirror.createdAt = event.params.timestamp.toString(); + + mirror.referenceModule = event.params.referenceModule.toString(); + mirror.referenceModuleReturnData = event.params.referenceModuleReturnData; + mirror.publicationPointed = event.params.pubIdPointed.toString(); + mirror.save(); + } + + // Add publication mirrors + let post = Post.load(event.params.pubIdPointed.toString()); + if (post) { + post.mirrors = (post.mirrors ?? []).concat([event.params.pubId.toString()]); + } + + let comment = Comment.load(event.params.pubIdPointed.toString()); + if (comment) { + comment.mirrors = (comment.mirrors ?? []).concat([ + event.params.pubId.toString(), + ]); + } } From 1c93930be8f05214c41b811208755e5fd26a4876 Mon Sep 17 00:00:00 2001 From: Matthew Date: Wed, 9 Nov 2022 23:40:08 +0800 Subject: [PATCH 04/10] Introduce "Collected" event handler --- generated/schema.ts | 51 +++++++++++++++++++++++++++++++++++++++++++++ schema.graphql | 10 +++++++++ src/lens-hub.ts | 24 +++++++++++++++++++++ 3 files changed, 85 insertions(+) diff --git a/generated/schema.ts b/generated/schema.ts index 0f0061d..272121e 100644 --- a/generated/schema.ts +++ b/generated/schema.ts @@ -2179,6 +2179,23 @@ export class Mirror extends Entity { set publicationPointed(value: string) { this.set("publicationPointed", Value.fromString(value)); } + + get collectedBy(): string | null { + let value = this.get("collectedBy"); + if (!value || value.kind == ValueKind.NULL) { + return null; + } else { + return value.toString(); + } + } + + set collectedBy(value: string | null) { + if (!value) { + this.unset("collectedBy"); + } else { + this.set("collectedBy", Value.fromString(value)); + } + } } export class Post extends Entity { @@ -2307,6 +2324,23 @@ export class Post extends Entity { this.set("createdAt", Value.fromString(value)); } + get collectedBy(): string | null { + let value = this.get("collectedBy"); + if (!value || value.kind == ValueKind.NULL) { + return null; + } else { + return value.toString(); + } + } + + set collectedBy(value: string | null) { + if (!value) { + this.unset("collectedBy"); + } else { + this.set("collectedBy", Value.fromString(value)); + } + } + get mirrors(): Array | null { let value = this.get("mirrors"); if (!value || value.kind == ValueKind.NULL) { @@ -2435,6 +2469,23 @@ export class Comment extends Entity { set profilePointed(value: string) { this.set("profilePointed", Value.fromString(value)); } + + get collectedBy(): string | null { + let value = this.get("collectedBy"); + if (!value || value.kind == ValueKind.NULL) { + return null; + } else { + return value.toString(); + } + } + + set collectedBy(value: string | null) { + if (!value) { + this.unset("collectedBy"); + } else { + this.set("collectedBy", Value.fromString(value)); + } + } } export class Owner extends Entity { diff --git a/schema.graphql b/schema.graphql index 74937f3..ea09fc2 100644 --- a/schema.graphql +++ b/schema.graphql @@ -253,6 +253,7 @@ type Profile @entity { followNftUri: String + # TODO: Combine to single superclass "Publication" posts: [Post!]! comments: [Comment!]! mirrors: [Mirror!]! @@ -270,6 +271,9 @@ type Mirror @entity { profilePointed: Profile! publicationPointed: Post! + + # Address of user who collected + collectedBy: String } type Post @entity { @@ -287,6 +291,9 @@ type Post @entity { createdAt: String! + # Address of user who collected + collectedBy: String + mirrors: [ID!] } @@ -306,6 +313,9 @@ type Comment @entity { collectModule: CollectModule! # Profile that comment points to (may be different than comment author) profilePointed: Profile! + + # Address of user who collected + collectedBy: String } type Owner @entity { diff --git a/src/lens-hub.ts b/src/lens-hub.ts index ff76890..710846c 100644 --- a/src/lens-hub.ts +++ b/src/lens-hub.ts @@ -2,6 +2,7 @@ import { log } from "@graphprotocol/graph-ts"; import { Approval as ApprovalEvent, ApprovalForAll as ApprovalForAllEvent, + Collected, CommentCreated, MirrorCreated, PostCreated, @@ -148,3 +149,26 @@ export function handleMirrorCreated(event: MirrorCreated): void { ]); } } + +// https://docs.lens.xyz/docs/events#collected +export function handleCollected(event: Collected): void { + // TODO: Unsure to use "pubId" or "rootPubId" here + + let post = Post.load(event.params.pubId.toString()); + if (post) { + post.collectedBy = event.params.collector.toHexString(); + post.save(); + } + + let comment = Comment.load(event.params.pubId.toString()); + if (comment) { + comment.collectedBy = event.params.collector.toHexString(); + comment.save(); + } + + let mirror = Mirror.load(event.params.pubId.toString()); + if (mirror) { + mirror.collectedBy = event.params.collector.toHexString(); + mirror.save(); + } +} From 143be1cec2a54fa3311589eba66aa5a44031e362 Mon Sep 17 00:00:00 2001 From: Matthew Date: Wed, 9 Nov 2022 23:44:43 +0800 Subject: [PATCH 05/10] Add event handlers to subgraph.yaml --- subgraph.yaml | 35 ++++++----------------------------- 1 file changed, 6 insertions(+), 29 deletions(-) diff --git a/subgraph.yaml b/subgraph.yaml index d5bec42..86a9c8b 100644 --- a/subgraph.yaml +++ b/subgraph.yaml @@ -2,35 +2,6 @@ specVersion: 0.0.5 schema: file: ./schema.graphql dataSources: - # - kind: ethereum - # name: LensHub - # network: matic - # source: - # address: "0x20f4D7DdeE23029048C53B42dc73A02De19F1c9E" - # abi: LensHub - # startBlock: 30068251 - # mapping: - # kind: ethereum/events - # apiVersion: 0.0.5 - # language: wasm/assemblyscript - # entities: - # - Approval - # - ApprovalForAll - # - Transfer - # - Profile - # abis: - # - name: LensHub - # file: ./abis/LensHub.json - # eventHandlers: - # # - event: Approval(indexed address,indexed address,indexed uint256) - # # handler: handleApproval - # # - event: ApprovalForAll(indexed address,indexed address,bool) - # # handler: handleApprovalForAll - # # - event: Transfer(indexed address,indexed address,indexed uint256) - # # handler: handleTransfer - # - event: ProfileCreated(indexed uint256,indexed address,indexed address,string,string,address,bytes,string,uint256) - # handler: handleProfileCreated - # file: ./src/lens-hub.ts - kind: ethereum name: LensHub network: matic @@ -60,4 +31,10 @@ dataSources: handler: handleProfileCreated - event: PostCreated(indexed uint256,indexed uint256,string,address,bytes,address,bytes,uint256) handler: handlePostCreated + - event: CommentCreated(indexed uint256, indexed uint256, string, uint256, uint256, address, bytes, address, bytes, uint256); + handler: handleCommentCreated + - event: MirrorCreated(indexed uint256, indexed uint256, uint256, uint256, address, bytes, uint256) + handler: handleMirrorCreated + - event: Collected(indexed address, indexed uint256, indexed uint256, uint256, uint256, uint256) + handler: handleCollected file: ./src/lens-hub.ts From 344bf6f81d0ef2a9b01cad805ea7d94d752b6290 Mon Sep 17 00:00:00 2001 From: Nazeeh Vahora Date: Thu, 10 Nov 2022 15:07:27 +0530 Subject: [PATCH 06/10] format files --- schema.graphql | 474 ++++++++++++++++++++++++------------------------ src/lens-hub.ts | 268 +++++++++++++-------------- 2 files changed, 371 insertions(+), 371 deletions(-) diff --git a/schema.graphql b/schema.graphql index ea09fc2..e4114e4 100644 --- a/schema.graphql +++ b/schema.graphql @@ -1,350 +1,350 @@ type Approval @entity { - id: ID! - owner: Bytes! # address - approved: Bytes! # address - tokenId: BigInt! # uint256 + id: ID! + owner: Bytes! # address + approved: Bytes! # address + tokenId: BigInt! # uint256 } type ApprovalForAll @entity { - id: ID! - owner: Bytes! # address - operator: Bytes! # address - approved: Boolean! # bool + id: ID! + owner: Bytes! # address + operator: Bytes! # address + approved: Boolean! # bool } type Transfer @entity { - id: ID! - from: Bytes! # address - to: Bytes! # address - tokenId: BigInt! # uint256 + id: ID! + from: Bytes! # address + to: Bytes! # address + tokenId: BigInt! # uint256 } type Dispatcher @entity { - id: ID! - address: String! - canUseRelay: Boolean! + id: ID! + address: String! + canUseRelay: Boolean! } type ProfileStats @entity { - id: ID! - totalFollowers: BigInt! - totalFollowing: BigInt! - totalPosts: BigInt! - totalComments: BigInt! - totalMirrors: BigInt! - totalPublications: BigInt! - totalCollects: BigInt! + id: ID! + totalFollowers: BigInt! + totalFollowing: BigInt! + totalPosts: BigInt! + totalComments: BigInt! + totalMirrors: BigInt! + totalPublications: BigInt! + totalCollects: BigInt! } type NftImage @entity { - id: ID! - contractAddress: String! - tokenId: String! - url: String! - chainId: BigInt! - verified: Boolean! + id: ID! + contractAddress: String! + tokenId: String! + url: String! + chainId: BigInt! + verified: Boolean! } type Media @entity { - id: ID! - url: String! - width: BigInt - height: BigInt - size: BigInt - mimeType: String + id: ID! + url: String! + width: BigInt + height: BigInt + size: BigInt + mimeType: String } type MediaSet @entity { - id: ID! - original: Media! - small: Media - medium: Media + id: ID! + original: Media! + small: Media + medium: Media } enum ProfileMedia { - NftImage - MediaSet + NftImage + MediaSet } type Erc20 @entity { - id: ID! - name: String! - symbol: String! - decimals: BigInt! - address: String! + id: ID! + name: String! + symbol: String! + decimals: BigInt! + address: String! } type ModuleFeeAmount @entity { - id: ID! - asset: Erc20! - vaue: String! + id: ID! + asset: Erc20! + vaue: String! } type FeeFollowModuleSettings @entity { - id: ID! - contractAddress: String! - amount: ModuleFeeAmount! - recipient: String! + id: ID! + contractAddress: String! + amount: ModuleFeeAmount! + recipient: String! } type ProfileFollowModuleSettings @entity { - id: ID! - contractAddress: String! + id: ID! + contractAddress: String! } type RevertFollowModuleSettings @entity { - id: ID! - contractAddress: String! + id: ID! + contractAddress: String! } enum FollowModule { - FeeFollowModuleSettings - ProfileFollowModuleSettings - RevertFollowModuleSettings + FeeFollowModuleSettings + ProfileFollowModuleSettings + RevertFollowModuleSettings } type Attribute @entity { - id: ID! - displayType: String - traitType: String - key: String! - value: String! + id: ID! + displayType: String + traitType: String + key: String! + value: String! } enum ReactionTypes { - UPVOTE - DOWNVOTE + UPVOTE + DOWNVOTE } type PublicationStats @entity { - id: ID! - totalAmountOfMirrors: BigInt! - totalAmountOfCollects: BigInt! - totalAmountOfComments: BigInt! - totalUpvotes: BigInt! - totalDownvotes: BigInt! + id: ID! + totalAmountOfMirrors: BigInt! + totalAmountOfCollects: BigInt! + totalAmountOfComments: BigInt! + totalUpvotes: BigInt! + totalDownvotes: BigInt! } type Wallet @entity { - id: ID! - address: String! - defaulProfile: Profile! + id: ID! + address: String! + defaulProfile: Profile! } enum MetadataDisplayType { - BigInt - String - String + BigInt + String + String } type MetadataAttributeOutput @entity { - id: ID! - displayType: MetadataDisplayType - traitType: String - value: String + id: ID! + displayType: MetadataDisplayType + traitType: String + value: String } type MetadataOutput @entity { - id: ID! - name: String - description: String - content: String - image: String - cover: MediaSet - media: [MediaSet!]! - attributes: [MetadataAttributeOutput!]! + id: ID! + name: String + description: String + content: String + image: String + cover: MediaSet + media: [MediaSet!]! + attributes: [MetadataAttributeOutput!]! } type ReactionFieldResolverRequest @entity { - id: ID! - profileId: BigInt + id: ID! + profileId: BigInt } enum CollectModule { - LimitedFeeCollectModule - FeeCollectModule - LimitedTimedFeeCollectModule - TimedFeeCollectModule - RevertCollectModule - FreeCollectModule + LimitedFeeCollectModule + FeeCollectModule + LimitedTimedFeeCollectModule + TimedFeeCollectModule + RevertCollectModule + FreeCollectModule } type FreeCollectModuleSettings @entity { - id: ID! - type: CollectModule! - contractAddress: String! - followerOnly: Boolean! + id: ID! + type: CollectModule! + contractAddress: String! + followerOnly: Boolean! } type FeeCollectModuleSettings @entity { - id: ID! - type: CollectModule! - contractAddress: String! - amount: ModuleFeeAmount! - recipient: String! - referralFee: BigDecimal! - followerOnly: Boolean! + id: ID! + type: CollectModule! + contractAddress: String! + amount: ModuleFeeAmount! + recipient: String! + referralFee: BigDecimal! + followerOnly: Boolean! } type LimitedFeeCollectModule @entity { - id: ID! - type: CollectModule! - contractAddress: String! - collectLimit: String! - amount: ModuleFeeAmount! - recipient: String! - referralFee: BigDecimal! - followerOnly: Boolean! + id: ID! + type: CollectModule! + contractAddress: String! + collectLimit: String! + amount: ModuleFeeAmount! + recipient: String! + referralFee: BigDecimal! + followerOnly: Boolean! } type LimitedTimedFeeCollectModuleSettings @entity { - id: ID! - type: CollectModule! - contractAddress: String! - collectLimit: String! - amount: ModuleFeeAmount! - recipient: String! - referralFee: BigDecimal! - followerOnly: Boolean! - endTimestamp: String! + id: ID! + type: CollectModule! + contractAddress: String! + collectLimit: String! + amount: ModuleFeeAmount! + recipient: String! + referralFee: BigDecimal! + followerOnly: Boolean! + endTimestamp: String! } type RevertCollectModuleSettings @entity { - id: ID! - type: CollectModule! - contractAddress: String! + id: ID! + type: CollectModule! + contractAddress: String! } type TimedFeeCollectModuleSettings @entity { - id: ID! - type: CollectModule! - contractAddress: String! - amount: ModuleFeeAmount! - recipient: String! - referralFee: BigDecimal! - followerOnly: Boolean! - endTimestamp: String! + id: ID! + type: CollectModule! + contractAddress: String! + amount: ModuleFeeAmount! + recipient: String! + referralFee: BigDecimal! + followerOnly: Boolean! + endTimestamp: String! } enum ReferenceModule { - FollowOnlyReferenceModule + FollowOnlyReferenceModule } type FollowOnlyReferenceModuleSettings @entity { - id: ID! - type: ReferenceModule! - contractAddress: String! + id: ID! + type: ReferenceModule! + contractAddress: String! } # https://docs.lens.xyz/docs/events#profilecreated type Profile @entity { - id: ID! + id: ID! - createdAt: String! + createdAt: String! - # Wallet address - creator: String! - mintedTo: String! - handle: String! - picture: ProfileMedia + # Wallet address + creator: String! + mintedTo: String! + handle: String! + picture: ProfileMedia - followModule: FollowModule - followModuleReturnData: Bytes + followModule: FollowModule + followModuleReturnData: Bytes - followNftUri: String + followNftUri: String - # TODO: Combine to single superclass "Publication" - posts: [Post!]! - comments: [Comment!]! - mirrors: [Mirror!]! + # TODO: Combine to single superclass "Publication" + posts: [Post!]! + comments: [Comment!]! + mirrors: [Mirror!]! } # Mirrors should extend "Post" # https://docs.lens.xyz/docs/mirror type Mirror @entity { - id: ID! - profile: Profile! - createdAt: String! + id: ID! + profile: Profile! + createdAt: String! - referenceModule: ReferenceModule! - referenceModuleReturnData: Bytes! + referenceModule: ReferenceModule! + referenceModuleReturnData: Bytes! - profilePointed: Profile! - publicationPointed: Post! + profilePointed: Profile! + publicationPointed: Post! - # Address of user who collected - collectedBy: String + # Address of user who collected + collectedBy: String } type Post @entity { - id: ID! - profile: Profile! + id: ID! + profile: Profile! - contentUri: String! + contentUri: String! - # Address - collectModule: CollectModule - collectModuleReturnData: Bytes + # Address + collectModule: CollectModule + collectModuleReturnData: Bytes - referenceModule: ReferenceModule - referenceModuleReturnData: Bytes + referenceModule: ReferenceModule + referenceModuleReturnData: Bytes - createdAt: String! + createdAt: String! - # Address of user who collected - collectedBy: String + # Address of user who collected + collectedBy: String - mirrors: [ID!] + mirrors: [ID!] } # TODO: We need to make "Comment" extend from "Publication" type Comment @entity { - id: ID! - profile: Profile! - onChainContentURI: String! - createdAt: String! - mirrors: [ID!]! + id: ID! + profile: Profile! + onChainContentURI: String! + createdAt: String! + mirrors: [ID!]! - # Publication that comment points to - publication: Post! - # Reference module settings for this comment - referenceModule: ReferenceModule - # Collect module settings for this comment - collectModule: CollectModule! - # Profile that comment points to (may be different than comment author) - profilePointed: Profile! + # Publication that comment points to + publication: Post! + # Reference module settings for this comment + referenceModule: ReferenceModule + # Collect module settings for this comment + collectModule: CollectModule! + # Profile that comment points to (may be different than comment author) + profilePointed: Profile! - # Address of user who collected - collectedBy: String + # Address of user who collected + collectedBy: String } type Owner @entity { - id: ID! - amount: BigDecimal! - address: String! + id: ID! + amount: BigDecimal! + address: String! } type NFTContent @entity { - id: ID! - uri: String! - metaType: String! - animatedUrl: String + id: ID! + uri: String! + metaType: String! + animatedUrl: String } type NFT @entity { - id: ID! - contractName: String! - contractAddress: String! - symbol: String! - tokenId: String! - owners: [Owner!]! - name: String! - description: String! - contentURI: String! - originalContent: NFTContent! - chainId: ID! - collectionName: String! - ercType: String! + id: ID! + contractName: String! + contractAddress: String! + symbol: String! + tokenId: String! + owners: [Owner!]! + name: String! + description: String! + contentURI: String! + originalContent: NFTContent! + chainId: ID! + collectionName: String! + ercType: String! } # Handles @@ -352,38 +352,38 @@ type NFT @entity { # Retrieved from https://graphiql-online.com/voyager-view type ReservedClaimableHandle @entity { - id: ID! - # Requires custom "Handle" scalar type - handle: String! - source: String! - expiry: String! + id: ID! + # Requires custom "Handle" scalar type + handle: String! + source: String! + expiry: String! } type ClaimableHandles @entity { - id: ID! - canClaimFreeTextHandle: Boolean! - claimableHandles: [ReservedClaimableHandle!]! + id: ID! + canClaimFreeTextHandle: Boolean! + claimableHandles: [ReservedClaimableHandle!]! } # Address #13 type TransactionReceipt @entity { - id: ID! - to: String! - from: String! - contractAddress: String - transactionIndex: Int! - root: String - gasUsed: String! - logsBloom: String! - blockHash: String! - transactionHash: String! - blockNumber: Int! - confirmations: Int! - cumulativeGasUsed: String! - effectiveGasPrice: String! - byzantium: Boolean! - type: Int! - status: Int + id: ID! + to: String! + from: String! + contractAddress: String + transactionIndex: Int! + root: String + gasUsed: String! + logsBloom: String! + blockHash: String! + transactionHash: String! + blockNumber: Int! + confirmations: Int! + cumulativeGasUsed: String! + effectiveGasPrice: String! + byzantium: Boolean! + type: Int! + status: Int } diff --git a/src/lens-hub.ts b/src/lens-hub.ts index 710846c..ebab5ac 100644 --- a/src/lens-hub.ts +++ b/src/lens-hub.ts @@ -1,174 +1,174 @@ import { log } from "@graphprotocol/graph-ts"; import { - Approval as ApprovalEvent, - ApprovalForAll as ApprovalForAllEvent, - Collected, - CommentCreated, - MirrorCreated, - PostCreated, - ProfileCreated, - Transfer as TransferEvent, + Approval as ApprovalEvent, + ApprovalForAll as ApprovalForAllEvent, + Collected, + CommentCreated, + MirrorCreated, + PostCreated, + ProfileCreated, + Transfer as TransferEvent, } from "../generated/LensHub/LensHub"; import { - Approval, - ApprovalForAll, - Comment, - Mirror, - Post, - Profile, - Transfer, + Approval, + ApprovalForAll, + Comment, + Mirror, + Post, + Profile, + Transfer, } from "../generated/schema"; export function handleApproval(event: ApprovalEvent): void { - let entity = new Approval( - event.transaction.hash.toHex() + "-" + event.logIndex.toString() - ); - entity.owner = event.params.owner; - entity.approved = event.params.approved; - entity.tokenId = event.params.tokenId; - entity.save(); + let entity = new Approval( + event.transaction.hash.toHex() + "-" + event.logIndex.toString() + ); + entity.owner = event.params.owner; + entity.approved = event.params.approved; + entity.tokenId = event.params.tokenId; + entity.save(); } export function handleApprovalForAll(event: ApprovalForAllEvent): void { - let entity = new ApprovalForAll( - event.transaction.hash.toHex() + "-" + event.logIndex.toString() - ); - entity.owner = event.params.owner; - entity.operator = event.params.operator; - entity.approved = event.params.approved; - entity.save(); + let entity = new ApprovalForAll( + event.transaction.hash.toHex() + "-" + event.logIndex.toString() + ); + entity.owner = event.params.owner; + entity.operator = event.params.operator; + entity.approved = event.params.approved; + entity.save(); } export function handleTransfer(event: TransferEvent): void { - let entity = new Transfer( - event.transaction.hash.toHex() + "-" + event.logIndex.toString() - ); - entity.from = event.params.from; - entity.to = event.params.to; - entity.tokenId = event.params.tokenId; - entity.save(); + let entity = new Transfer( + event.transaction.hash.toHex() + "-" + event.logIndex.toString() + ); + entity.from = event.params.from; + entity.to = event.params.to; + entity.tokenId = event.params.tokenId; + entity.save(); } export function handleProfileCreated(event: ProfileCreated): void { - let profile = Profile.load(event.params.profileId.toString()); - log.info("Trigger Fired", []); + let profile = Profile.load(event.params.profileId.toString()); + log.info("Trigger Fired", []); - if (!profile) { - profile = new Profile(event.params.profileId.toString()); - profile.handle = event.params.handle.toString(); - profile.creator = event.params.creator.toHexString(); - profile.mintedTo = event.params.to.toHexString(); - profile.picture = event.params.imageURI.toString(); + if (!profile) { + profile = new Profile(event.params.profileId.toString()); + profile.handle = event.params.handle.toString(); + profile.creator = event.params.creator.toHexString(); + profile.mintedTo = event.params.to.toHexString(); + profile.picture = event.params.imageURI.toString(); - profile.createdAt = event.params.timestamp.toString(); + profile.createdAt = event.params.timestamp.toString(); - // Newly set follow module, can be zero address - profile.followModule = event.params.followModule.toHexString(); - profile.followModuleReturnData = event.params.followModuleReturnData; + // Newly set follow module, can be zero address + profile.followModule = event.params.followModule.toHexString(); + profile.followModuleReturnData = event.params.followModuleReturnData; - profile.followNftUri = event.params.followNFTURI; + profile.followNftUri = event.params.followNFTURI; - profile.save(); - } + profile.save(); + } } export function handlePostCreated(event: PostCreated): void { - let post = Post.load(event.params.pubId.toString()); + let post = Post.load(event.params.pubId.toString()); - if (!post) { - post = new Post(event.params.pubId.toString()); - post.id = event.params.pubId.toString(); - post.contentUri = event.params.contentURI; - post.createdAt = event.params.timestamp.toString(); - post.profile = event.params.profileId.toString(); + if (!post) { + post = new Post(event.params.pubId.toString()); + post.id = event.params.pubId.toString(); + post.contentUri = event.params.contentURI; + post.createdAt = event.params.timestamp.toString(); + post.profile = event.params.profileId.toString(); - post.collectModule = event.params.collectModule.toHexString(); - post.collectModuleReturnData = event.params.collectModuleReturnData; + post.collectModule = event.params.collectModule.toHexString(); + post.collectModuleReturnData = event.params.collectModuleReturnData; - post.referenceModule = event.params.referenceModule.toHexString(); - post.referenceModuleReturnData = event.params.referenceModuleReturnData; + post.referenceModule = event.params.referenceModule.toHexString(); + post.referenceModuleReturnData = event.params.referenceModuleReturnData; - post.save(); - } + post.save(); + } - let profile = Profile.load(event.params.profileId.toString()); - if (profile) { - profile.posts = (profile.posts ?? []).concat([post.id]); - profile.save(); - } + let profile = Profile.load(event.params.profileId.toString()); + if (profile) { + profile.posts = (profile.posts ?? []).concat([post.id]); + profile.save(); + } } export function handleCommentCreated(event: CommentCreated): void { - let comment = Comment.load(event.params.pubId.toString()); - - if (!comment) { - comment = new Comment(event.params.pubId.toString()); - comment.createdAt = event.params.timestamp.toString(); - comment.profile = event.params.profileId.toString(); - comment.onChainContentURI = event.params.contentURI.toString(); - - comment.collectModule = event.params.collectModule.toString(); - comment.referenceModule = event.params.referenceModule.toString(); - comment.publication = event.params.pubIdPointed.toString(); - comment.profilePointed = event.params.profileIdPointed.toString(); - comment.save(); - } - - let profile = Profile.load(event.params.profileId.toString()); - if (profile) { - profile.comments = (profile.comments ?? []).concat([comment.id]); - profile.save(); - } + let comment = Comment.load(event.params.pubId.toString()); + + if (!comment) { + comment = new Comment(event.params.pubId.toString()); + comment.createdAt = event.params.timestamp.toString(); + comment.profile = event.params.profileId.toString(); + comment.onChainContentURI = event.params.contentURI.toString(); + + comment.collectModule = event.params.collectModule.toString(); + comment.referenceModule = event.params.referenceModule.toString(); + comment.publication = event.params.pubIdPointed.toString(); + comment.profilePointed = event.params.profileIdPointed.toString(); + comment.save(); + } + + let profile = Profile.load(event.params.profileId.toString()); + if (profile) { + profile.comments = (profile.comments ?? []).concat([comment.id]); + profile.save(); + } } export function handleMirrorCreated(event: MirrorCreated): void { - let mirror = Mirror.load(event.params.pubId.toString()); - - if (!mirror) { - mirror = new Mirror(event.params.pubId.toString()); - mirror.profile = event.params.profileId.toString(); - mirror.profilePointed = event.params.profileIdPointed.toString(); - mirror.createdAt = event.params.timestamp.toString(); - - mirror.referenceModule = event.params.referenceModule.toString(); - mirror.referenceModuleReturnData = event.params.referenceModuleReturnData; - mirror.publicationPointed = event.params.pubIdPointed.toString(); - mirror.save(); - } - - // Add publication mirrors - let post = Post.load(event.params.pubIdPointed.toString()); - if (post) { - post.mirrors = (post.mirrors ?? []).concat([event.params.pubId.toString()]); - } - - let comment = Comment.load(event.params.pubIdPointed.toString()); - if (comment) { - comment.mirrors = (comment.mirrors ?? []).concat([ - event.params.pubId.toString(), - ]); - } + let mirror = Mirror.load(event.params.pubId.toString()); + + if (!mirror) { + mirror = new Mirror(event.params.pubId.toString()); + mirror.profile = event.params.profileId.toString(); + mirror.profilePointed = event.params.profileIdPointed.toString(); + mirror.createdAt = event.params.timestamp.toString(); + + mirror.referenceModule = event.params.referenceModule.toString(); + mirror.referenceModuleReturnData = event.params.referenceModuleReturnData; + mirror.publicationPointed = event.params.pubIdPointed.toString(); + mirror.save(); + } + + // Add publication mirrors + let post = Post.load(event.params.pubIdPointed.toString()); + if (post) { + post.mirrors = (post.mirrors ?? []).concat([event.params.pubId.toString()]); + } + + let comment = Comment.load(event.params.pubIdPointed.toString()); + if (comment) { + comment.mirrors = (comment.mirrors ?? []).concat([ + event.params.pubId.toString(), + ]); + } } // https://docs.lens.xyz/docs/events#collected export function handleCollected(event: Collected): void { - // TODO: Unsure to use "pubId" or "rootPubId" here - - let post = Post.load(event.params.pubId.toString()); - if (post) { - post.collectedBy = event.params.collector.toHexString(); - post.save(); - } - - let comment = Comment.load(event.params.pubId.toString()); - if (comment) { - comment.collectedBy = event.params.collector.toHexString(); - comment.save(); - } - - let mirror = Mirror.load(event.params.pubId.toString()); - if (mirror) { - mirror.collectedBy = event.params.collector.toHexString(); - mirror.save(); - } + // TODO: Unsure to use "pubId" or "rootPubId" here + + let post = Post.load(event.params.pubId.toString()); + if (post) { + post.collectedBy = event.params.collector.toHexString(); + post.save(); + } + + let comment = Comment.load(event.params.pubId.toString()); + if (comment) { + comment.collectedBy = event.params.collector.toHexString(); + comment.save(); + } + + let mirror = Mirror.load(event.params.pubId.toString()); + if (mirror) { + mirror.collectedBy = event.params.collector.toHexString(); + mirror.save(); + } } From 421ff269ca42fc8a01ca8488b6e7216ebdd09f27 Mon Sep 17 00:00:00 2001 From: Matthew Date: Fri, 11 Nov 2022 00:08:06 +0800 Subject: [PATCH 07/10] Fix invalid event handler signatures --- subgraph.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/subgraph.yaml b/subgraph.yaml index 86a9c8b..cdace1c 100644 --- a/subgraph.yaml +++ b/subgraph.yaml @@ -31,10 +31,10 @@ dataSources: handler: handleProfileCreated - event: PostCreated(indexed uint256,indexed uint256,string,address,bytes,address,bytes,uint256) handler: handlePostCreated - - event: CommentCreated(indexed uint256, indexed uint256, string, uint256, uint256, address, bytes, address, bytes, uint256); + - event: CommentCreated(indexed uint256,indexed uint256,string,uint256,uint256,bytes,address,bytes,address,bytes,uint256) handler: handleCommentCreated - - event: MirrorCreated(indexed uint256, indexed uint256, uint256, uint256, address, bytes, uint256) + - event: MirrorCreated(indexed uint256,indexed uint256,uint256,uint256,bytes,address,bytes,uint256) handler: handleMirrorCreated - - event: Collected(indexed address, indexed uint256, indexed uint256, uint256, uint256, uint256) + - event: Collected(indexed address,indexed uint256,indexed uint256,uint256,uint256,uint256) handler: handleCollected file: ./src/lens-hub.ts From 10ae0adb82d9916f49d6b90e384e36b7080fac54 Mon Sep 17 00:00:00 2001 From: Matthew Date: Fri, 11 Nov 2022 00:08:36 +0800 Subject: [PATCH 08/10] Reintroduce legacy fields in schema --- generated/schema.ts | 439 ++++++++++++++++++++++++++++++++++++- schema.graphql | 524 ++++++++++++++++++++++++-------------------- src/lens-hub.ts | 281 +++++++++++++----------- 3 files changed, 864 insertions(+), 380 deletions(-) diff --git a/generated/schema.ts b/generated/schema.ts index 272121e..6d817be 100644 --- a/generated/schema.ts +++ b/generated/schema.ts @@ -2093,6 +2093,221 @@ export class Profile extends Entity { set mirrors(value: Array) { this.set("mirrors", Value.fromStringArray(value)); } + + get name(): string | null { + let value = this.get("name"); + if (!value || value.kind == ValueKind.NULL) { + return null; + } else { + return value.toString(); + } + } + + set name(value: string | null) { + if (!value) { + this.unset("name"); + } else { + this.set("name", Value.fromString(value)); + } + } + + get bio(): string | null { + let value = this.get("bio"); + if (!value || value.kind == ValueKind.NULL) { + return null; + } else { + return value.toString(); + } + } + + set bio(value: string | null) { + if (!value) { + this.unset("bio"); + } else { + this.set("bio", Value.fromString(value)); + } + } + + get followNftAddress(): string | null { + let value = this.get("followNftAddress"); + if (!value || value.kind == ValueKind.NULL) { + return null; + } else { + return value.toString(); + } + } + + set followNftAddress(value: string | null) { + if (!value) { + this.unset("followNftAddress"); + } else { + this.set("followNftAddress", Value.fromString(value)); + } + } + + get metadata(): string | null { + let value = this.get("metadata"); + if (!value || value.kind == ValueKind.NULL) { + return null; + } else { + return value.toString(); + } + } + + set metadata(value: string | null) { + if (!value) { + this.unset("metadata"); + } else { + this.set("metadata", Value.fromString(value)); + } + } + + get handle(): string { + let value = this.get("handle"); + return value!.toString(); + } + + set handle(value: string) { + this.set("handle", Value.fromString(value)); + } + + get picture(): string | null { + let value = this.get("picture"); + if (!value || value.kind == ValueKind.NULL) { + return null; + } else { + return value.toString(); + } + } + + set picture(value: string | null) { + if (!value) { + this.unset("picture"); + } else { + this.set("picture", Value.fromString(value)); + } + } + + get coverPicture(): string | null { + let value = this.get("coverPicture"); + if (!value || value.kind == ValueKind.NULL) { + return null; + } else { + return value.toString(); + } + } + + set coverPicture(value: string | null) { + if (!value) { + this.unset("coverPicture"); + } else { + this.set("coverPicture", Value.fromString(value)); + } + } + + get ownedBy(): string { + let value = this.get("ownedBy"); + return value!.toString(); + } + + set ownedBy(value: string) { + this.set("ownedBy", Value.fromString(value)); + } + + get dispatcher(): string | null { + let value = this.get("dispatcher"); + if (!value || value.kind == ValueKind.NULL) { + return null; + } else { + return value.toString(); + } + } + + set dispatcher(value: string | null) { + if (!value) { + this.unset("dispatcher"); + } else { + this.set("dispatcher", Value.fromString(value)); + } + } + + get stats(): string | null { + let value = this.get("stats"); + if (!value || value.kind == ValueKind.NULL) { + return null; + } else { + return value.toString(); + } + } + + set stats(value: string | null) { + if (!value) { + this.unset("stats"); + } else { + this.set("stats", Value.fromString(value)); + } + } + + get followModule(): string | null { + let value = this.get("followModule"); + if (!value || value.kind == ValueKind.NULL) { + return null; + } else { + return value.toString(); + } + } + + set followModule(value: string | null) { + if (!value) { + this.unset("followModule"); + } else { + this.set("followModule", Value.fromString(value)); + } + } + + get isDefault(): boolean { + let value = this.get("isDefault"); + return value!.toBoolean(); + } + + set isDefault(value: boolean) { + this.set("isDefault", Value.fromBoolean(value)); + } + + get attributes(): Array | null { + let value = this.get("attributes"); + if (!value || value.kind == ValueKind.NULL) { + return null; + } else { + return value.toStringArray(); + } + } + + set attributes(value: Array | null) { + if (!value) { + this.unset("attributes"); + } else { + this.set("attributes", Value.fromStringArray(>value)); + } + } + + get isFollowedByMe(): boolean { + let value = this.get("isFollowedByMe"); + return value!.toBoolean(); + } + + set isFollowedByMe(value: boolean) { + this.set("isFollowedByMe", Value.fromBoolean(value)); + } + + get isFollowingMe(): boolean { + let value = this.get("isFollowingMe"); + return value!.toBoolean(); + } + + set isFollowingMe(value: boolean) { + this.set("isFollowingMe", Value.fromBoolean(value)); + } } export class Mirror extends Entity { @@ -2196,6 +2411,102 @@ export class Mirror extends Entity { this.set("collectedBy", Value.fromString(value)); } } + + get stats(): string { + let value = this.get("stats"); + return value!.toString(); + } + + set stats(value: string) { + this.set("stats", Value.fromString(value)); + } + + get metadata(): string { + let value = this.get("metadata"); + return value!.toString(); + } + + set metadata(value: string) { + this.set("metadata", Value.fromString(value)); + } + + get onChainContentURI(): string { + let value = this.get("onChainContentURI"); + return value!.toString(); + } + + set onChainContentURI(value: string) { + this.set("onChainContentURI", Value.fromString(value)); + } + + get appId(): BigInt | null { + let value = this.get("appId"); + if (!value || value.kind == ValueKind.NULL) { + return null; + } else { + return value.toBigInt(); + } + } + + set appId(value: BigInt | null) { + if (!value) { + this.unset("appId"); + } else { + this.set("appId", Value.fromBigInt(value)); + } + } + + get hidden(): boolean { + let value = this.get("hidden"); + return value!.toBoolean(); + } + + set hidden(value: boolean) { + this.set("hidden", Value.fromBoolean(value)); + } + + get collectNftAddress(): string | null { + let value = this.get("collectNftAddress"); + if (!value || value.kind == ValueKind.NULL) { + return null; + } else { + return value.toString(); + } + } + + set collectNftAddress(value: string | null) { + if (!value) { + this.unset("collectNftAddress"); + } else { + this.set("collectNftAddress", Value.fromString(value)); + } + } + + get reaction(): string | null { + let value = this.get("reaction"); + if (!value || value.kind == ValueKind.NULL) { + return null; + } else { + return value.toString(); + } + } + + set reaction(value: string | null) { + if (!value) { + this.unset("reaction"); + } else { + this.set("reaction", Value.fromString(value)); + } + } + + get hasCollectedByMe(): boolean { + let value = this.get("hasCollectedByMe"); + return value!.toBoolean(); + } + + set hasCollectedByMe(value: boolean) { + this.set("hasCollectedByMe", Value.fromBoolean(value)); + } } export class Post extends Entity { @@ -2238,13 +2549,13 @@ export class Post extends Entity { this.set("profile", Value.fromString(value)); } - get contentUri(): string { - let value = this.get("contentUri"); + get onChainContentURI(): string { + let value = this.get("onChainContentURI"); return value!.toString(); } - set contentUri(value: string) { - this.set("contentUri", Value.fromString(value)); + set onChainContentURI(value: string) { + this.set("onChainContentURI", Value.fromString(value)); } get collectModule(): string | null { @@ -2357,6 +2668,126 @@ export class Post extends Entity { this.set("mirrors", Value.fromStringArray(>value)); } } + + get appId(): string | null { + let value = this.get("appId"); + if (!value || value.kind == ValueKind.NULL) { + return null; + } else { + return value.toString(); + } + } + + set appId(value: string | null) { + if (!value) { + this.unset("appId"); + } else { + this.set("appId", Value.fromString(value)); + } + } + + get hidden(): boolean { + let value = this.get("hidden"); + return value!.toBoolean(); + } + + set hidden(value: boolean) { + this.set("hidden", Value.fromBoolean(value)); + } + + get collectNftAddress(): string | null { + let value = this.get("collectNftAddress"); + if (!value || value.kind == ValueKind.NULL) { + return null; + } else { + return value.toString(); + } + } + + set collectNftAddress(value: string | null) { + if (!value) { + this.unset("collectNftAddress"); + } else { + this.set("collectNftAddress", Value.fromString(value)); + } + } + + get collectedBy(): string | null { + let value = this.get("collectedBy"); + if (!value || value.kind == ValueKind.NULL) { + return null; + } else { + return value.toString(); + } + } + + set collectedBy(value: string | null) { + if (!value) { + this.unset("collectedBy"); + } else { + this.set("collectedBy", Value.fromString(value)); + } + } + + get reaction(): string | null { + let value = this.get("reaction"); + if (!value || value.kind == ValueKind.NULL) { + return null; + } else { + return value.toString(); + } + } + + set reaction(value: string | null) { + if (!value) { + this.unset("reaction"); + } else { + this.set("reaction", Value.fromString(value)); + } + } + + get hasCollectedByMe(): boolean { + let value = this.get("hasCollectedByMe"); + return value!.toBoolean(); + } + + set hasCollectedByMe(value: boolean) { + this.set("hasCollectedByMe", Value.fromBoolean(value)); + } + + get stats(): string | null { + let value = this.get("stats"); + if (!value || value.kind == ValueKind.NULL) { + return null; + } else { + return value.toString(); + } + } + + set stats(value: string | null) { + if (!value) { + this.unset("stats"); + } else { + this.set("stats", Value.fromString(value)); + } + } + + get metadata(): string | null { + let value = this.get("metadata"); + if (!value || value.kind == ValueKind.NULL) { + return null; + } else { + return value.toString(); + } + } + + set metadata(value: string | null) { + if (!value) { + this.unset("metadata"); + } else { + this.set("metadata", Value.fromString(value)); + } + } } export class Comment extends Entity { diff --git a/schema.graphql b/schema.graphql index e4114e4..3a976f0 100644 --- a/schema.graphql +++ b/schema.graphql @@ -1,350 +1,390 @@ type Approval @entity { - id: ID! - owner: Bytes! # address - approved: Bytes! # address - tokenId: BigInt! # uint256 + id: ID! + owner: Bytes! # address + approved: Bytes! # address + tokenId: BigInt! # uint256 } type ApprovalForAll @entity { - id: ID! - owner: Bytes! # address - operator: Bytes! # address - approved: Boolean! # bool + id: ID! + owner: Bytes! # address + operator: Bytes! # address + approved: Boolean! # bool } type Transfer @entity { - id: ID! - from: Bytes! # address - to: Bytes! # address - tokenId: BigInt! # uint256 + id: ID! + from: Bytes! # address + to: Bytes! # address + tokenId: BigInt! # uint256 } type Dispatcher @entity { - id: ID! - address: String! - canUseRelay: Boolean! + id: ID! + address: String! + canUseRelay: Boolean! } type ProfileStats @entity { - id: ID! - totalFollowers: BigInt! - totalFollowing: BigInt! - totalPosts: BigInt! - totalComments: BigInt! - totalMirrors: BigInt! - totalPublications: BigInt! - totalCollects: BigInt! + id: ID! + totalFollowers: BigInt! + totalFollowing: BigInt! + totalPosts: BigInt! + totalComments: BigInt! + totalMirrors: BigInt! + totalPublications: BigInt! + totalCollects: BigInt! } type NftImage @entity { - id: ID! - contractAddress: String! - tokenId: String! - url: String! - chainId: BigInt! - verified: Boolean! + id: ID! + contractAddress: String! + tokenId: String! + url: String! + chainId: BigInt! + verified: Boolean! } type Media @entity { - id: ID! - url: String! - width: BigInt - height: BigInt - size: BigInt - mimeType: String + id: ID! + url: String! + width: BigInt + height: BigInt + size: BigInt + mimeType: String } type MediaSet @entity { - id: ID! - original: Media! - small: Media - medium: Media + id: ID! + original: Media! + small: Media + medium: Media } enum ProfileMedia { - NftImage - MediaSet + NftImage + MediaSet } type Erc20 @entity { - id: ID! - name: String! - symbol: String! - decimals: BigInt! - address: String! + id: ID! + name: String! + symbol: String! + decimals: BigInt! + address: String! } type ModuleFeeAmount @entity { - id: ID! - asset: Erc20! - vaue: String! + id: ID! + asset: Erc20! + vaue: String! } type FeeFollowModuleSettings @entity { - id: ID! - contractAddress: String! - amount: ModuleFeeAmount! - recipient: String! + id: ID! + contractAddress: String! + amount: ModuleFeeAmount! + recipient: String! } type ProfileFollowModuleSettings @entity { - id: ID! - contractAddress: String! + id: ID! + contractAddress: String! } type RevertFollowModuleSettings @entity { - id: ID! - contractAddress: String! + id: ID! + contractAddress: String! } enum FollowModule { - FeeFollowModuleSettings - ProfileFollowModuleSettings - RevertFollowModuleSettings + FeeFollowModuleSettings + ProfileFollowModuleSettings + RevertFollowModuleSettings } type Attribute @entity { - id: ID! - displayType: String - traitType: String - key: String! - value: String! + id: ID! + displayType: String + traitType: String + key: String! + value: String! } enum ReactionTypes { - UPVOTE - DOWNVOTE + UPVOTE + DOWNVOTE } type PublicationStats @entity { - id: ID! - totalAmountOfMirrors: BigInt! - totalAmountOfCollects: BigInt! - totalAmountOfComments: BigInt! - totalUpvotes: BigInt! - totalDownvotes: BigInt! + id: ID! + totalAmountOfMirrors: BigInt! + totalAmountOfCollects: BigInt! + totalAmountOfComments: BigInt! + totalUpvotes: BigInt! + totalDownvotes: BigInt! } type Wallet @entity { - id: ID! - address: String! - defaulProfile: Profile! + id: ID! + address: String! + defaulProfile: Profile! } enum MetadataDisplayType { - BigInt - String - String + BigInt + String + String } type MetadataAttributeOutput @entity { - id: ID! - displayType: MetadataDisplayType - traitType: String - value: String + id: ID! + displayType: MetadataDisplayType + traitType: String + value: String } type MetadataOutput @entity { - id: ID! - name: String - description: String - content: String - image: String - cover: MediaSet - media: [MediaSet!]! - attributes: [MetadataAttributeOutput!]! + id: ID! + name: String + description: String + content: String + image: String + cover: MediaSet + media: [MediaSet!]! + attributes: [MetadataAttributeOutput!]! } type ReactionFieldResolverRequest @entity { - id: ID! - profileId: BigInt + id: ID! + profileId: BigInt } enum CollectModule { - LimitedFeeCollectModule - FeeCollectModule - LimitedTimedFeeCollectModule - TimedFeeCollectModule - RevertCollectModule - FreeCollectModule + LimitedFeeCollectModule + FeeCollectModule + LimitedTimedFeeCollectModule + TimedFeeCollectModule + RevertCollectModule + FreeCollectModule } type FreeCollectModuleSettings @entity { - id: ID! - type: CollectModule! - contractAddress: String! - followerOnly: Boolean! + id: ID! + type: CollectModule! + contractAddress: String! + followerOnly: Boolean! } type FeeCollectModuleSettings @entity { - id: ID! - type: CollectModule! - contractAddress: String! - amount: ModuleFeeAmount! - recipient: String! - referralFee: BigDecimal! - followerOnly: Boolean! + id: ID! + type: CollectModule! + contractAddress: String! + amount: ModuleFeeAmount! + recipient: String! + referralFee: BigDecimal! + followerOnly: Boolean! } type LimitedFeeCollectModule @entity { - id: ID! - type: CollectModule! - contractAddress: String! - collectLimit: String! - amount: ModuleFeeAmount! - recipient: String! - referralFee: BigDecimal! - followerOnly: Boolean! + id: ID! + type: CollectModule! + contractAddress: String! + collectLimit: String! + amount: ModuleFeeAmount! + recipient: String! + referralFee: BigDecimal! + followerOnly: Boolean! } type LimitedTimedFeeCollectModuleSettings @entity { - id: ID! - type: CollectModule! - contractAddress: String! - collectLimit: String! - amount: ModuleFeeAmount! - recipient: String! - referralFee: BigDecimal! - followerOnly: Boolean! - endTimestamp: String! + id: ID! + type: CollectModule! + contractAddress: String! + collectLimit: String! + amount: ModuleFeeAmount! + recipient: String! + referralFee: BigDecimal! + followerOnly: Boolean! + endTimestamp: String! } type RevertCollectModuleSettings @entity { - id: ID! - type: CollectModule! - contractAddress: String! + id: ID! + type: CollectModule! + contractAddress: String! } type TimedFeeCollectModuleSettings @entity { - id: ID! - type: CollectModule! - contractAddress: String! - amount: ModuleFeeAmount! - recipient: String! - referralFee: BigDecimal! - followerOnly: Boolean! - endTimestamp: String! + id: ID! + type: CollectModule! + contractAddress: String! + amount: ModuleFeeAmount! + recipient: String! + referralFee: BigDecimal! + followerOnly: Boolean! + endTimestamp: String! } enum ReferenceModule { - FollowOnlyReferenceModule + FollowOnlyReferenceModule } type FollowOnlyReferenceModuleSettings @entity { - id: ID! - type: ReferenceModule! - contractAddress: String! + id: ID! + type: ReferenceModule! + contractAddress: String! } # https://docs.lens.xyz/docs/events#profilecreated type Profile @entity { - id: ID! - - createdAt: String! - - # Wallet address - creator: String! - mintedTo: String! - handle: String! - picture: ProfileMedia - - followModule: FollowModule - followModuleReturnData: Bytes - - followNftUri: String - - # TODO: Combine to single superclass "Publication" - posts: [Post!]! - comments: [Comment!]! - mirrors: [Mirror!]! + id: ID! + + createdAt: String! + + # Wallet address + creator: String! + mintedTo: String! + handle: String! + picture: ProfileMedia + + followModule: FollowModule + followModuleReturnData: Bytes + + followNftUri: String + + # TODO: Combine to single superclass "Publication" + posts: [Post!]! + comments: [Comment!]! + mirrors: [Mirror!]! + + # Additional fields that we want to remove + # TODO: Refactor & remove + name: String + bio: String + followNftAddress: String + metadata: String + handle: String! + picture: ProfileMedia + coverPicture: ProfileMedia + ownedBy: String! + dispatcher: Dispatcher + stats: ProfileStats + followModule: FollowModule + isDefault: Boolean + attributes: [Attribute!] + isFollowedByMe: Boolean + isFollowingMe: Boolean } # Mirrors should extend "Post" # https://docs.lens.xyz/docs/mirror type Mirror @entity { - id: ID! - profile: Profile! - createdAt: String! + id: ID! + profile: Profile! + createdAt: String! + + referenceModule: ReferenceModule! + referenceModuleReturnData: Bytes! - referenceModule: ReferenceModule! - referenceModuleReturnData: Bytes! + profilePointed: Profile! + publicationPointed: Post! - profilePointed: Profile! - publicationPointed: Post! + # Address of user who collected + collectedBy: String - # Address of user who collected - collectedBy: String + # Additional fields that we want to remove + # TODO: Refactor & remove + stats: PublicationStats! + metadata: MetadataOutput! + onChainContentURI: String! + appId: BigInt + hidden: Boolean! + collectNftAddress: String + reaction: ReactionTypes + hasCollectedByMe: Boolean! } type Post @entity { - id: ID! - profile: Profile! + id: ID! + profile: Profile! + + onChainContentURI: String! - contentUri: String! + # Address + collectModule: CollectModule + collectModuleReturnData: Bytes - # Address - collectModule: CollectModule - collectModuleReturnData: Bytes + referenceModule: ReferenceModule + referenceModuleReturnData: Bytes - referenceModule: ReferenceModule - referenceModuleReturnData: Bytes + createdAt: String! - createdAt: String! + # Address of user who collected + collectedBy: String - # Address of user who collected - collectedBy: String + mirrors: [ID!] - mirrors: [ID!] + # Additional fields that we want to remove + # TODO: Refactor & remove + appId: String + hidden: Boolean + collectNftAddress: String + collectedBy: Wallet + reaction: ReactionTypes + hasCollectedByMe: Boolean + stats: PublicationStats + metadata: MetadataOutput } # TODO: We need to make "Comment" extend from "Publication" type Comment @entity { - id: ID! - profile: Profile! - onChainContentURI: String! - createdAt: String! - mirrors: [ID!]! + id: ID! + profile: Profile! + onChainContentURI: String! + createdAt: String! + mirrors: [ID!]! - # Publication that comment points to - publication: Post! - # Reference module settings for this comment - referenceModule: ReferenceModule - # Collect module settings for this comment - collectModule: CollectModule! - # Profile that comment points to (may be different than comment author) - profilePointed: Profile! + # Publication that comment points to + publication: Post! + # Reference module settings for this comment + referenceModule: ReferenceModule + # Collect module settings for this comment + collectModule: CollectModule! + # Profile that comment points to (may be different than comment author) + profilePointed: Profile! - # Address of user who collected - collectedBy: String + # Address of user who collected + collectedBy: String } type Owner @entity { - id: ID! - amount: BigDecimal! - address: String! + id: ID! + amount: BigDecimal! + address: String! } type NFTContent @entity { - id: ID! - uri: String! - metaType: String! - animatedUrl: String + id: ID! + uri: String! + metaType: String! + animatedUrl: String } type NFT @entity { - id: ID! - contractName: String! - contractAddress: String! - symbol: String! - tokenId: String! - owners: [Owner!]! - name: String! - description: String! - contentURI: String! - originalContent: NFTContent! - chainId: ID! - collectionName: String! - ercType: String! + id: ID! + contractName: String! + contractAddress: String! + symbol: String! + tokenId: String! + owners: [Owner!]! + name: String! + description: String! + contentURI: String! + originalContent: NFTContent! + chainId: ID! + collectionName: String! + ercType: String! } # Handles @@ -352,38 +392,38 @@ type NFT @entity { # Retrieved from https://graphiql-online.com/voyager-view type ReservedClaimableHandle @entity { - id: ID! - # Requires custom "Handle" scalar type - handle: String! - source: String! - expiry: String! + id: ID! + # Requires custom "Handle" scalar type + handle: String! + source: String! + expiry: String! } type ClaimableHandles @entity { - id: ID! - canClaimFreeTextHandle: Boolean! - claimableHandles: [ReservedClaimableHandle!]! + id: ID! + canClaimFreeTextHandle: Boolean! + claimableHandles: [ReservedClaimableHandle!]! } # Address #13 type TransactionReceipt @entity { - id: ID! - to: String! - from: String! - contractAddress: String - transactionIndex: Int! - root: String - gasUsed: String! - logsBloom: String! - blockHash: String! - transactionHash: String! - blockNumber: Int! - confirmations: Int! - cumulativeGasUsed: String! - effectiveGasPrice: String! - byzantium: Boolean! - type: Int! - status: Int + id: ID! + to: String! + from: String! + contractAddress: String + transactionIndex: Int! + root: String + gasUsed: String! + logsBloom: String! + blockHash: String! + transactionHash: String! + blockNumber: Int! + confirmations: Int! + cumulativeGasUsed: String! + effectiveGasPrice: String! + byzantium: Boolean! + type: Int! + status: Int } diff --git a/src/lens-hub.ts b/src/lens-hub.ts index ebab5ac..120bfed 100644 --- a/src/lens-hub.ts +++ b/src/lens-hub.ts @@ -1,174 +1,187 @@ import { log } from "@graphprotocol/graph-ts"; import { - Approval as ApprovalEvent, - ApprovalForAll as ApprovalForAllEvent, - Collected, - CommentCreated, - MirrorCreated, - PostCreated, - ProfileCreated, - Transfer as TransferEvent, + Approval as ApprovalEvent, + ApprovalForAll as ApprovalForAllEvent, + Collected, + CommentCreated, + MirrorCreated, + PostCreated, + ProfileCreated, + Transfer as TransferEvent, } from "../generated/LensHub/LensHub"; import { - Approval, - ApprovalForAll, - Comment, - Mirror, - Post, - Profile, - Transfer, + Approval, + ApprovalForAll, + Comment, + Mirror, + Post, + Profile, + Transfer, } from "../generated/schema"; export function handleApproval(event: ApprovalEvent): void { - let entity = new Approval( - event.transaction.hash.toHex() + "-" + event.logIndex.toString() - ); - entity.owner = event.params.owner; - entity.approved = event.params.approved; - entity.tokenId = event.params.tokenId; - entity.save(); + let entity = new Approval( + event.transaction.hash.toHex() + "-" + event.logIndex.toString() + ); + entity.owner = event.params.owner; + entity.approved = event.params.approved; + entity.tokenId = event.params.tokenId; + entity.save(); } export function handleApprovalForAll(event: ApprovalForAllEvent): void { - let entity = new ApprovalForAll( - event.transaction.hash.toHex() + "-" + event.logIndex.toString() - ); - entity.owner = event.params.owner; - entity.operator = event.params.operator; - entity.approved = event.params.approved; - entity.save(); + let entity = new ApprovalForAll( + event.transaction.hash.toHex() + "-" + event.logIndex.toString() + ); + entity.owner = event.params.owner; + entity.operator = event.params.operator; + entity.approved = event.params.approved; + entity.save(); } export function handleTransfer(event: TransferEvent): void { - let entity = new Transfer( - event.transaction.hash.toHex() + "-" + event.logIndex.toString() - ); - entity.from = event.params.from; - entity.to = event.params.to; - entity.tokenId = event.params.tokenId; - entity.save(); + let entity = new Transfer( + event.transaction.hash.toHex() + "-" + event.logIndex.toString() + ); + entity.from = event.params.from; + entity.to = event.params.to; + entity.tokenId = event.params.tokenId; + entity.save(); } export function handleProfileCreated(event: ProfileCreated): void { - let profile = Profile.load(event.params.profileId.toString()); - log.info("Trigger Fired", []); + let profile = Profile.load(event.params.profileId.toString()); + log.info("Trigger Fired", []); - if (!profile) { - profile = new Profile(event.params.profileId.toString()); - profile.handle = event.params.handle.toString(); - profile.creator = event.params.creator.toHexString(); - profile.mintedTo = event.params.to.toHexString(); - profile.picture = event.params.imageURI.toString(); + if (!profile) { + profile = new Profile(event.params.profileId.toString()); - profile.createdAt = event.params.timestamp.toString(); + profile.handle = event.params.handle.toString(); + profile.creator = event.params.creator.toHexString(); + profile.mintedTo = event.params.to.toHexString(); + profile.picture = event.params.imageURI.toString(); - // Newly set follow module, can be zero address - profile.followModule = event.params.followModule.toHexString(); - profile.followModuleReturnData = event.params.followModuleReturnData; + profile.createdAt = event.params.timestamp.toString(); - profile.followNftUri = event.params.followNFTURI; + // Newly set follow module, can be zero address + profile.followModule = event.params.followModule.toHexString(); + profile.followModuleReturnData = event.params.followModuleReturnData; - profile.save(); - } + profile.followNftUri = event.params.followNFTURI; + + // Superfluous legacy fields + // TODO: Refactor and remove + profile.metadata = event.params.followNFTURI; + profile.handle = event.params.handle; + profile.ownedBy = event.params.creator.toHexString(); + profile.isDefault = true; + profile.isFollowedByMe = false; + // End of legacy fields + + profile.save(); + } } export function handlePostCreated(event: PostCreated): void { - let post = Post.load(event.params.pubId.toString()); + let post = Post.load(event.params.pubId.toString()); + + if (!post) { + post = new Post(event.params.pubId.toString()); + post.id = event.params.pubId.toString(); + post.onChainContentURI = event.params.contentURI; + post.createdAt = event.params.timestamp.toString(); + post.profile = event.params.profileId.toString(); - if (!post) { - post = new Post(event.params.pubId.toString()); - post.id = event.params.pubId.toString(); - post.contentUri = event.params.contentURI; - post.createdAt = event.params.timestamp.toString(); - post.profile = event.params.profileId.toString(); + post.collectModule = event.params.collectModule.toHexString(); + post.collectModuleReturnData = event.params.collectModuleReturnData; - post.collectModule = event.params.collectModule.toHexString(); - post.collectModuleReturnData = event.params.collectModuleReturnData; + post.referenceModule = event.params.referenceModule.toHexString(); + post.referenceModuleReturnData = event.params.referenceModuleReturnData; - post.referenceModule = event.params.referenceModule.toHexString(); - post.referenceModuleReturnData = event.params.referenceModuleReturnData; + // Legacy field, consider to refactor and remove + post.collectNftAddress = event.params.collectModule.toHexString(); - post.save(); - } + post.save(); + } - let profile = Profile.load(event.params.profileId.toString()); - if (profile) { - profile.posts = (profile.posts ?? []).concat([post.id]); - profile.save(); - } + let profile = Profile.load(event.params.profileId.toString()); + if (profile) { + profile.posts = (profile.posts ?? []).concat([post.id]); + profile.save(); + } } export function handleCommentCreated(event: CommentCreated): void { - let comment = Comment.load(event.params.pubId.toString()); - - if (!comment) { - comment = new Comment(event.params.pubId.toString()); - comment.createdAt = event.params.timestamp.toString(); - comment.profile = event.params.profileId.toString(); - comment.onChainContentURI = event.params.contentURI.toString(); - - comment.collectModule = event.params.collectModule.toString(); - comment.referenceModule = event.params.referenceModule.toString(); - comment.publication = event.params.pubIdPointed.toString(); - comment.profilePointed = event.params.profileIdPointed.toString(); - comment.save(); - } - - let profile = Profile.load(event.params.profileId.toString()); - if (profile) { - profile.comments = (profile.comments ?? []).concat([comment.id]); - profile.save(); - } + let comment = Comment.load(event.params.pubId.toString()); + + if (!comment) { + comment = new Comment(event.params.pubId.toString()); + comment.createdAt = event.params.timestamp.toString(); + comment.profile = event.params.profileId.toString(); + comment.onChainContentURI = event.params.contentURI.toString(); + + comment.collectModule = event.params.collectModule.toString(); + comment.referenceModule = event.params.referenceModule.toString(); + comment.publication = event.params.pubIdPointed.toString(); + comment.profilePointed = event.params.profileIdPointed.toString(); + comment.save(); + } + + let profile = Profile.load(event.params.profileId.toString()); + if (profile) { + profile.comments = (profile.comments ?? []).concat([comment.id]); + profile.save(); + } } export function handleMirrorCreated(event: MirrorCreated): void { - let mirror = Mirror.load(event.params.pubId.toString()); - - if (!mirror) { - mirror = new Mirror(event.params.pubId.toString()); - mirror.profile = event.params.profileId.toString(); - mirror.profilePointed = event.params.profileIdPointed.toString(); - mirror.createdAt = event.params.timestamp.toString(); - - mirror.referenceModule = event.params.referenceModule.toString(); - mirror.referenceModuleReturnData = event.params.referenceModuleReturnData; - mirror.publicationPointed = event.params.pubIdPointed.toString(); - mirror.save(); - } - - // Add publication mirrors - let post = Post.load(event.params.pubIdPointed.toString()); - if (post) { - post.mirrors = (post.mirrors ?? []).concat([event.params.pubId.toString()]); - } - - let comment = Comment.load(event.params.pubIdPointed.toString()); - if (comment) { - comment.mirrors = (comment.mirrors ?? []).concat([ - event.params.pubId.toString(), - ]); - } + let mirror = Mirror.load(event.params.pubId.toString()); + + if (!mirror) { + mirror = new Mirror(event.params.pubId.toString()); + mirror.profile = event.params.profileId.toString(); + mirror.profilePointed = event.params.profileIdPointed.toString(); + mirror.createdAt = event.params.timestamp.toString(); + + mirror.referenceModule = event.params.referenceModule.toString(); + mirror.referenceModuleReturnData = event.params.referenceModuleReturnData; + mirror.publicationPointed = event.params.pubIdPointed.toString(); + mirror.save(); + } + + // Add publication mirrors + let post = Post.load(event.params.pubIdPointed.toString()); + if (post) { + post.mirrors = (post.mirrors ?? []).concat([event.params.pubId.toString()]); + } + + let comment = Comment.load(event.params.pubIdPointed.toString()); + if (comment) { + comment.mirrors = (comment.mirrors ?? []).concat([ + event.params.pubId.toString(), + ]); + } } // https://docs.lens.xyz/docs/events#collected export function handleCollected(event: Collected): void { - // TODO: Unsure to use "pubId" or "rootPubId" here - - let post = Post.load(event.params.pubId.toString()); - if (post) { - post.collectedBy = event.params.collector.toHexString(); - post.save(); - } - - let comment = Comment.load(event.params.pubId.toString()); - if (comment) { - comment.collectedBy = event.params.collector.toHexString(); - comment.save(); - } - - let mirror = Mirror.load(event.params.pubId.toString()); - if (mirror) { - mirror.collectedBy = event.params.collector.toHexString(); - mirror.save(); - } + // TODO: Unsure to use "pubId" or "rootPubId" here + + let post = Post.load(event.params.pubId.toString()); + if (post) { + post.collectedBy = event.params.collector.toHexString(); + post.save(); + } + + let comment = Comment.load(event.params.pubId.toString()); + if (comment) { + comment.collectedBy = event.params.collector.toHexString(); + comment.save(); + } + + let mirror = Mirror.load(event.params.pubId.toString()); + if (mirror) { + mirror.collectedBy = event.params.collector.toHexString(); + mirror.save(); + } } From 7d17f4be66c0ad76b5d1f48cefa632a38be58464 Mon Sep 17 00:00:00 2001 From: Matthew Date: Fri, 11 Nov 2022 00:09:58 +0800 Subject: [PATCH 09/10] Add comment to use "rootPubId" instead --- src/lens-hub.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/lens-hub.ts b/src/lens-hub.ts index 120bfed..b42a576 100644 --- a/src/lens-hub.ts +++ b/src/lens-hub.ts @@ -165,8 +165,7 @@ export function handleMirrorCreated(event: MirrorCreated): void { // https://docs.lens.xyz/docs/events#collected export function handleCollected(event: Collected): void { - // TODO: Unsure to use "pubId" or "rootPubId" here - + // Revisit "pubId" to maybe use "rootPubId" instead let post = Post.load(event.params.pubId.toString()); if (post) { post.collectedBy = event.params.collector.toHexString(); From 31c58fecbb6227dcd4ed0364931d0fd1abddc2a3 Mon Sep 17 00:00:00 2001 From: Nazeeh Vahora Date: Sat, 12 Nov 2022 00:49:12 +0530 Subject: [PATCH 10/10] Format code --- schema.graphql | 560 ++++++++++++++++++++++++------------------------ src/lens-hub.ts | 286 ++++++++++++------------- 2 files changed, 423 insertions(+), 423 deletions(-) diff --git a/schema.graphql b/schema.graphql index 3a976f0..73eeed2 100644 --- a/schema.graphql +++ b/schema.graphql @@ -1,390 +1,390 @@ type Approval @entity { - id: ID! - owner: Bytes! # address - approved: Bytes! # address - tokenId: BigInt! # uint256 + id: ID! + owner: Bytes! # address + approved: Bytes! # address + tokenId: BigInt! # uint256 } type ApprovalForAll @entity { - id: ID! - owner: Bytes! # address - operator: Bytes! # address - approved: Boolean! # bool + id: ID! + owner: Bytes! # address + operator: Bytes! # address + approved: Boolean! # bool } type Transfer @entity { - id: ID! - from: Bytes! # address - to: Bytes! # address - tokenId: BigInt! # uint256 + id: ID! + from: Bytes! # address + to: Bytes! # address + tokenId: BigInt! # uint256 } type Dispatcher @entity { - id: ID! - address: String! - canUseRelay: Boolean! + id: ID! + address: String! + canUseRelay: Boolean! } type ProfileStats @entity { - id: ID! - totalFollowers: BigInt! - totalFollowing: BigInt! - totalPosts: BigInt! - totalComments: BigInt! - totalMirrors: BigInt! - totalPublications: BigInt! - totalCollects: BigInt! + id: ID! + totalFollowers: BigInt! + totalFollowing: BigInt! + totalPosts: BigInt! + totalComments: BigInt! + totalMirrors: BigInt! + totalPublications: BigInt! + totalCollects: BigInt! } type NftImage @entity { - id: ID! - contractAddress: String! - tokenId: String! - url: String! - chainId: BigInt! - verified: Boolean! + id: ID! + contractAddress: String! + tokenId: String! + url: String! + chainId: BigInt! + verified: Boolean! } type Media @entity { - id: ID! - url: String! - width: BigInt - height: BigInt - size: BigInt - mimeType: String + id: ID! + url: String! + width: BigInt + height: BigInt + size: BigInt + mimeType: String } type MediaSet @entity { - id: ID! - original: Media! - small: Media - medium: Media + id: ID! + original: Media! + small: Media + medium: Media } enum ProfileMedia { - NftImage - MediaSet + NftImage + MediaSet } type Erc20 @entity { - id: ID! - name: String! - symbol: String! - decimals: BigInt! - address: String! + id: ID! + name: String! + symbol: String! + decimals: BigInt! + address: String! } type ModuleFeeAmount @entity { - id: ID! - asset: Erc20! - vaue: String! + id: ID! + asset: Erc20! + vaue: String! } type FeeFollowModuleSettings @entity { - id: ID! - contractAddress: String! - amount: ModuleFeeAmount! - recipient: String! + id: ID! + contractAddress: String! + amount: ModuleFeeAmount! + recipient: String! } type ProfileFollowModuleSettings @entity { - id: ID! - contractAddress: String! + id: ID! + contractAddress: String! } type RevertFollowModuleSettings @entity { - id: ID! - contractAddress: String! + id: ID! + contractAddress: String! } enum FollowModule { - FeeFollowModuleSettings - ProfileFollowModuleSettings - RevertFollowModuleSettings + FeeFollowModuleSettings + ProfileFollowModuleSettings + RevertFollowModuleSettings } type Attribute @entity { - id: ID! - displayType: String - traitType: String - key: String! - value: String! + id: ID! + displayType: String + traitType: String + key: String! + value: String! } enum ReactionTypes { - UPVOTE - DOWNVOTE + UPVOTE + DOWNVOTE } type PublicationStats @entity { - id: ID! - totalAmountOfMirrors: BigInt! - totalAmountOfCollects: BigInt! - totalAmountOfComments: BigInt! - totalUpvotes: BigInt! - totalDownvotes: BigInt! + id: ID! + totalAmountOfMirrors: BigInt! + totalAmountOfCollects: BigInt! + totalAmountOfComments: BigInt! + totalUpvotes: BigInt! + totalDownvotes: BigInt! } type Wallet @entity { - id: ID! - address: String! - defaulProfile: Profile! + id: ID! + address: String! + defaulProfile: Profile! } enum MetadataDisplayType { - BigInt - String - String + BigInt + String + String } type MetadataAttributeOutput @entity { - id: ID! - displayType: MetadataDisplayType - traitType: String - value: String + id: ID! + displayType: MetadataDisplayType + traitType: String + value: String } type MetadataOutput @entity { - id: ID! - name: String - description: String - content: String - image: String - cover: MediaSet - media: [MediaSet!]! - attributes: [MetadataAttributeOutput!]! + id: ID! + name: String + description: String + content: String + image: String + cover: MediaSet + media: [MediaSet!]! + attributes: [MetadataAttributeOutput!]! } type ReactionFieldResolverRequest @entity { - id: ID! - profileId: BigInt + id: ID! + profileId: BigInt } enum CollectModule { - LimitedFeeCollectModule - FeeCollectModule - LimitedTimedFeeCollectModule - TimedFeeCollectModule - RevertCollectModule - FreeCollectModule + LimitedFeeCollectModule + FeeCollectModule + LimitedTimedFeeCollectModule + TimedFeeCollectModule + RevertCollectModule + FreeCollectModule } type FreeCollectModuleSettings @entity { - id: ID! - type: CollectModule! - contractAddress: String! - followerOnly: Boolean! + id: ID! + type: CollectModule! + contractAddress: String! + followerOnly: Boolean! } type FeeCollectModuleSettings @entity { - id: ID! - type: CollectModule! - contractAddress: String! - amount: ModuleFeeAmount! - recipient: String! - referralFee: BigDecimal! - followerOnly: Boolean! + id: ID! + type: CollectModule! + contractAddress: String! + amount: ModuleFeeAmount! + recipient: String! + referralFee: BigDecimal! + followerOnly: Boolean! } type LimitedFeeCollectModule @entity { - id: ID! - type: CollectModule! - contractAddress: String! - collectLimit: String! - amount: ModuleFeeAmount! - recipient: String! - referralFee: BigDecimal! - followerOnly: Boolean! + id: ID! + type: CollectModule! + contractAddress: String! + collectLimit: String! + amount: ModuleFeeAmount! + recipient: String! + referralFee: BigDecimal! + followerOnly: Boolean! } type LimitedTimedFeeCollectModuleSettings @entity { - id: ID! - type: CollectModule! - contractAddress: String! - collectLimit: String! - amount: ModuleFeeAmount! - recipient: String! - referralFee: BigDecimal! - followerOnly: Boolean! - endTimestamp: String! + id: ID! + type: CollectModule! + contractAddress: String! + collectLimit: String! + amount: ModuleFeeAmount! + recipient: String! + referralFee: BigDecimal! + followerOnly: Boolean! + endTimestamp: String! } type RevertCollectModuleSettings @entity { - id: ID! - type: CollectModule! - contractAddress: String! + id: ID! + type: CollectModule! + contractAddress: String! } type TimedFeeCollectModuleSettings @entity { - id: ID! - type: CollectModule! - contractAddress: String! - amount: ModuleFeeAmount! - recipient: String! - referralFee: BigDecimal! - followerOnly: Boolean! - endTimestamp: String! + id: ID! + type: CollectModule! + contractAddress: String! + amount: ModuleFeeAmount! + recipient: String! + referralFee: BigDecimal! + followerOnly: Boolean! + endTimestamp: String! } enum ReferenceModule { - FollowOnlyReferenceModule + FollowOnlyReferenceModule } type FollowOnlyReferenceModuleSettings @entity { - id: ID! - type: ReferenceModule! - contractAddress: String! + id: ID! + type: ReferenceModule! + contractAddress: String! } # https://docs.lens.xyz/docs/events#profilecreated type Profile @entity { - id: ID! - - createdAt: String! - - # Wallet address - creator: String! - mintedTo: String! - handle: String! - picture: ProfileMedia - - followModule: FollowModule - followModuleReturnData: Bytes - - followNftUri: String - - # TODO: Combine to single superclass "Publication" - posts: [Post!]! - comments: [Comment!]! - mirrors: [Mirror!]! - - # Additional fields that we want to remove - # TODO: Refactor & remove - name: String - bio: String - followNftAddress: String - metadata: String - handle: String! - picture: ProfileMedia - coverPicture: ProfileMedia - ownedBy: String! - dispatcher: Dispatcher - stats: ProfileStats - followModule: FollowModule - isDefault: Boolean - attributes: [Attribute!] - isFollowedByMe: Boolean - isFollowingMe: Boolean + id: ID! + + createdAt: String! + + # Wallet address + creator: String! + mintedTo: String! + handle: String! + picture: ProfileMedia + + followModule: FollowModule + followModuleReturnData: Bytes + + followNftUri: String + + # TODO: Combine to single superclass "Publication" + posts: [Post!]! + comments: [Comment!]! + mirrors: [Mirror!]! + + # Additional fields that we want to remove + # TODO: Refactor & remove + name: String + bio: String + followNftAddress: String + metadata: String + handle: String! + picture: ProfileMedia + coverPicture: ProfileMedia + ownedBy: String! + dispatcher: Dispatcher + stats: ProfileStats + followModule: FollowModule + isDefault: Boolean + attributes: [Attribute!] + isFollowedByMe: Boolean + isFollowingMe: Boolean } # Mirrors should extend "Post" # https://docs.lens.xyz/docs/mirror type Mirror @entity { - id: ID! - profile: Profile! - createdAt: String! + id: ID! + profile: Profile! + createdAt: String! - referenceModule: ReferenceModule! - referenceModuleReturnData: Bytes! + referenceModule: ReferenceModule! + referenceModuleReturnData: Bytes! - profilePointed: Profile! - publicationPointed: Post! + profilePointed: Profile! + publicationPointed: Post! - # Address of user who collected - collectedBy: String + # Address of user who collected + collectedBy: String - # Additional fields that we want to remove - # TODO: Refactor & remove - stats: PublicationStats! - metadata: MetadataOutput! - onChainContentURI: String! - appId: BigInt - hidden: Boolean! - collectNftAddress: String - reaction: ReactionTypes - hasCollectedByMe: Boolean! + # Additional fields that we want to remove + # TODO: Refactor & remove + stats: PublicationStats! + metadata: MetadataOutput! + onChainContentURI: String! + appId: BigInt + hidden: Boolean! + collectNftAddress: String + reaction: ReactionTypes + hasCollectedByMe: Boolean! } type Post @entity { - id: ID! - profile: Profile! + id: ID! + profile: Profile! - onChainContentURI: String! + onChainContentURI: String! - # Address - collectModule: CollectModule - collectModuleReturnData: Bytes + # Address + collectModule: CollectModule + collectModuleReturnData: Bytes - referenceModule: ReferenceModule - referenceModuleReturnData: Bytes + referenceModule: ReferenceModule + referenceModuleReturnData: Bytes - createdAt: String! + createdAt: String! - # Address of user who collected - collectedBy: String + # Address of user who collected + collectedBy: String - mirrors: [ID!] + mirrors: [ID!] - # Additional fields that we want to remove - # TODO: Refactor & remove - appId: String - hidden: Boolean - collectNftAddress: String - collectedBy: Wallet - reaction: ReactionTypes - hasCollectedByMe: Boolean - stats: PublicationStats - metadata: MetadataOutput + # Additional fields that we want to remove + # TODO: Refactor & remove + appId: String + hidden: Boolean + collectNftAddress: String + collectedBy: Wallet + reaction: ReactionTypes + hasCollectedByMe: Boolean + stats: PublicationStats + metadata: MetadataOutput } # TODO: We need to make "Comment" extend from "Publication" type Comment @entity { - id: ID! - profile: Profile! - onChainContentURI: String! - createdAt: String! - mirrors: [ID!]! + id: ID! + profile: Profile! + onChainContentURI: String! + createdAt: String! + mirrors: [ID!]! - # Publication that comment points to - publication: Post! - # Reference module settings for this comment - referenceModule: ReferenceModule - # Collect module settings for this comment - collectModule: CollectModule! - # Profile that comment points to (may be different than comment author) - profilePointed: Profile! + # Publication that comment points to + publication: Post! + # Reference module settings for this comment + referenceModule: ReferenceModule + # Collect module settings for this comment + collectModule: CollectModule! + # Profile that comment points to (may be different than comment author) + profilePointed: Profile! - # Address of user who collected - collectedBy: String + # Address of user who collected + collectedBy: String } type Owner @entity { - id: ID! - amount: BigDecimal! - address: String! + id: ID! + amount: BigDecimal! + address: String! } type NFTContent @entity { - id: ID! - uri: String! - metaType: String! - animatedUrl: String + id: ID! + uri: String! + metaType: String! + animatedUrl: String } type NFT @entity { - id: ID! - contractName: String! - contractAddress: String! - symbol: String! - tokenId: String! - owners: [Owner!]! - name: String! - description: String! - contentURI: String! - originalContent: NFTContent! - chainId: ID! - collectionName: String! - ercType: String! + id: ID! + contractName: String! + contractAddress: String! + symbol: String! + tokenId: String! + owners: [Owner!]! + name: String! + description: String! + contentURI: String! + originalContent: NFTContent! + chainId: ID! + collectionName: String! + ercType: String! } # Handles @@ -392,38 +392,38 @@ type NFT @entity { # Retrieved from https://graphiql-online.com/voyager-view type ReservedClaimableHandle @entity { - id: ID! - # Requires custom "Handle" scalar type - handle: String! - source: String! - expiry: String! + id: ID! + # Requires custom "Handle" scalar type + handle: String! + source: String! + expiry: String! } type ClaimableHandles @entity { - id: ID! - canClaimFreeTextHandle: Boolean! - claimableHandles: [ReservedClaimableHandle!]! + id: ID! + canClaimFreeTextHandle: Boolean! + claimableHandles: [ReservedClaimableHandle!]! } # Address #13 type TransactionReceipt @entity { - id: ID! - to: String! - from: String! - contractAddress: String - transactionIndex: Int! - root: String - gasUsed: String! - logsBloom: String! - blockHash: String! - transactionHash: String! - blockNumber: Int! - confirmations: Int! - cumulativeGasUsed: String! - effectiveGasPrice: String! - byzantium: Boolean! - type: Int! - status: Int + id: ID! + to: String! + from: String! + contractAddress: String + transactionIndex: Int! + root: String + gasUsed: String! + logsBloom: String! + blockHash: String! + transactionHash: String! + blockNumber: Int! + confirmations: Int! + cumulativeGasUsed: String! + effectiveGasPrice: String! + byzantium: Boolean! + type: Int! + status: Int } diff --git a/src/lens-hub.ts b/src/lens-hub.ts index b42a576..785d5cb 100644 --- a/src/lens-hub.ts +++ b/src/lens-hub.ts @@ -1,186 +1,186 @@ import { log } from "@graphprotocol/graph-ts"; import { - Approval as ApprovalEvent, - ApprovalForAll as ApprovalForAllEvent, - Collected, - CommentCreated, - MirrorCreated, - PostCreated, - ProfileCreated, - Transfer as TransferEvent, + Approval as ApprovalEvent, + ApprovalForAll as ApprovalForAllEvent, + Collected, + CommentCreated, + MirrorCreated, + PostCreated, + ProfileCreated, + Transfer as TransferEvent, } from "../generated/LensHub/LensHub"; import { - Approval, - ApprovalForAll, - Comment, - Mirror, - Post, - Profile, - Transfer, + Approval, + ApprovalForAll, + Comment, + Mirror, + Post, + Profile, + Transfer, } from "../generated/schema"; export function handleApproval(event: ApprovalEvent): void { - let entity = new Approval( - event.transaction.hash.toHex() + "-" + event.logIndex.toString() - ); - entity.owner = event.params.owner; - entity.approved = event.params.approved; - entity.tokenId = event.params.tokenId; - entity.save(); + let entity = new Approval( + event.transaction.hash.toHex() + "-" + event.logIndex.toString() + ); + entity.owner = event.params.owner; + entity.approved = event.params.approved; + entity.tokenId = event.params.tokenId; + entity.save(); } export function handleApprovalForAll(event: ApprovalForAllEvent): void { - let entity = new ApprovalForAll( - event.transaction.hash.toHex() + "-" + event.logIndex.toString() - ); - entity.owner = event.params.owner; - entity.operator = event.params.operator; - entity.approved = event.params.approved; - entity.save(); + let entity = new ApprovalForAll( + event.transaction.hash.toHex() + "-" + event.logIndex.toString() + ); + entity.owner = event.params.owner; + entity.operator = event.params.operator; + entity.approved = event.params.approved; + entity.save(); } export function handleTransfer(event: TransferEvent): void { - let entity = new Transfer( - event.transaction.hash.toHex() + "-" + event.logIndex.toString() - ); - entity.from = event.params.from; - entity.to = event.params.to; - entity.tokenId = event.params.tokenId; - entity.save(); + let entity = new Transfer( + event.transaction.hash.toHex() + "-" + event.logIndex.toString() + ); + entity.from = event.params.from; + entity.to = event.params.to; + entity.tokenId = event.params.tokenId; + entity.save(); } export function handleProfileCreated(event: ProfileCreated): void { - let profile = Profile.load(event.params.profileId.toString()); - log.info("Trigger Fired", []); + let profile = Profile.load(event.params.profileId.toString()); + log.info("Trigger Fired", []); - if (!profile) { - profile = new Profile(event.params.profileId.toString()); + if (!profile) { + profile = new Profile(event.params.profileId.toString()); - profile.handle = event.params.handle.toString(); - profile.creator = event.params.creator.toHexString(); - profile.mintedTo = event.params.to.toHexString(); - profile.picture = event.params.imageURI.toString(); + profile.handle = event.params.handle.toString(); + profile.creator = event.params.creator.toHexString(); + profile.mintedTo = event.params.to.toHexString(); + profile.picture = event.params.imageURI.toString(); - profile.createdAt = event.params.timestamp.toString(); + profile.createdAt = event.params.timestamp.toString(); - // Newly set follow module, can be zero address - profile.followModule = event.params.followModule.toHexString(); - profile.followModuleReturnData = event.params.followModuleReturnData; + // Newly set follow module, can be zero address + profile.followModule = event.params.followModule.toHexString(); + profile.followModuleReturnData = event.params.followModuleReturnData; - profile.followNftUri = event.params.followNFTURI; + profile.followNftUri = event.params.followNFTURI; - // Superfluous legacy fields - // TODO: Refactor and remove - profile.metadata = event.params.followNFTURI; - profile.handle = event.params.handle; - profile.ownedBy = event.params.creator.toHexString(); - profile.isDefault = true; - profile.isFollowedByMe = false; - // End of legacy fields + // Superfluous legacy fields + // TODO: Refactor and remove + profile.metadata = event.params.followNFTURI; + profile.handle = event.params.handle; + profile.ownedBy = event.params.creator.toHexString(); + profile.isDefault = true; + profile.isFollowedByMe = false; + // End of legacy fields - profile.save(); - } + profile.save(); + } } export function handlePostCreated(event: PostCreated): void { - let post = Post.load(event.params.pubId.toString()); + let post = Post.load(event.params.pubId.toString()); - if (!post) { - post = new Post(event.params.pubId.toString()); - post.id = event.params.pubId.toString(); - post.onChainContentURI = event.params.contentURI; - post.createdAt = event.params.timestamp.toString(); - post.profile = event.params.profileId.toString(); + if (!post) { + post = new Post(event.params.pubId.toString()); + post.id = event.params.pubId.toString(); + post.onChainContentURI = event.params.contentURI; + post.createdAt = event.params.timestamp.toString(); + post.profile = event.params.profileId.toString(); - post.collectModule = event.params.collectModule.toHexString(); - post.collectModuleReturnData = event.params.collectModuleReturnData; + post.collectModule = event.params.collectModule.toHexString(); + post.collectModuleReturnData = event.params.collectModuleReturnData; - post.referenceModule = event.params.referenceModule.toHexString(); - post.referenceModuleReturnData = event.params.referenceModuleReturnData; + post.referenceModule = event.params.referenceModule.toHexString(); + post.referenceModuleReturnData = event.params.referenceModuleReturnData; - // Legacy field, consider to refactor and remove - post.collectNftAddress = event.params.collectModule.toHexString(); + // Legacy field, consider to refactor and remove + post.collectNftAddress = event.params.collectModule.toHexString(); - post.save(); - } + post.save(); + } - let profile = Profile.load(event.params.profileId.toString()); - if (profile) { - profile.posts = (profile.posts ?? []).concat([post.id]); - profile.save(); - } + let profile = Profile.load(event.params.profileId.toString()); + if (profile) { + profile.posts = (profile.posts ?? []).concat([post.id]); + profile.save(); + } } export function handleCommentCreated(event: CommentCreated): void { - let comment = Comment.load(event.params.pubId.toString()); - - if (!comment) { - comment = new Comment(event.params.pubId.toString()); - comment.createdAt = event.params.timestamp.toString(); - comment.profile = event.params.profileId.toString(); - comment.onChainContentURI = event.params.contentURI.toString(); - - comment.collectModule = event.params.collectModule.toString(); - comment.referenceModule = event.params.referenceModule.toString(); - comment.publication = event.params.pubIdPointed.toString(); - comment.profilePointed = event.params.profileIdPointed.toString(); - comment.save(); - } - - let profile = Profile.load(event.params.profileId.toString()); - if (profile) { - profile.comments = (profile.comments ?? []).concat([comment.id]); - profile.save(); - } + let comment = Comment.load(event.params.pubId.toString()); + + if (!comment) { + comment = new Comment(event.params.pubId.toString()); + comment.createdAt = event.params.timestamp.toString(); + comment.profile = event.params.profileId.toString(); + comment.onChainContentURI = event.params.contentURI.toString(); + + comment.collectModule = event.params.collectModule.toString(); + comment.referenceModule = event.params.referenceModule.toString(); + comment.publication = event.params.pubIdPointed.toString(); + comment.profilePointed = event.params.profileIdPointed.toString(); + comment.save(); + } + + let profile = Profile.load(event.params.profileId.toString()); + if (profile) { + profile.comments = (profile.comments ?? []).concat([comment.id]); + profile.save(); + } } export function handleMirrorCreated(event: MirrorCreated): void { - let mirror = Mirror.load(event.params.pubId.toString()); - - if (!mirror) { - mirror = new Mirror(event.params.pubId.toString()); - mirror.profile = event.params.profileId.toString(); - mirror.profilePointed = event.params.profileIdPointed.toString(); - mirror.createdAt = event.params.timestamp.toString(); - - mirror.referenceModule = event.params.referenceModule.toString(); - mirror.referenceModuleReturnData = event.params.referenceModuleReturnData; - mirror.publicationPointed = event.params.pubIdPointed.toString(); - mirror.save(); - } - - // Add publication mirrors - let post = Post.load(event.params.pubIdPointed.toString()); - if (post) { - post.mirrors = (post.mirrors ?? []).concat([event.params.pubId.toString()]); - } - - let comment = Comment.load(event.params.pubIdPointed.toString()); - if (comment) { - comment.mirrors = (comment.mirrors ?? []).concat([ - event.params.pubId.toString(), - ]); - } + let mirror = Mirror.load(event.params.pubId.toString()); + + if (!mirror) { + mirror = new Mirror(event.params.pubId.toString()); + mirror.profile = event.params.profileId.toString(); + mirror.profilePointed = event.params.profileIdPointed.toString(); + mirror.createdAt = event.params.timestamp.toString(); + + mirror.referenceModule = event.params.referenceModule.toString(); + mirror.referenceModuleReturnData = event.params.referenceModuleReturnData; + mirror.publicationPointed = event.params.pubIdPointed.toString(); + mirror.save(); + } + + // Add publication mirrors + let post = Post.load(event.params.pubIdPointed.toString()); + if (post) { + post.mirrors = (post.mirrors ?? []).concat([event.params.pubId.toString()]); + } + + let comment = Comment.load(event.params.pubIdPointed.toString()); + if (comment) { + comment.mirrors = (comment.mirrors ?? []).concat([ + event.params.pubId.toString(), + ]); + } } // https://docs.lens.xyz/docs/events#collected export function handleCollected(event: Collected): void { - // Revisit "pubId" to maybe use "rootPubId" instead - let post = Post.load(event.params.pubId.toString()); - if (post) { - post.collectedBy = event.params.collector.toHexString(); - post.save(); - } - - let comment = Comment.load(event.params.pubId.toString()); - if (comment) { - comment.collectedBy = event.params.collector.toHexString(); - comment.save(); - } - - let mirror = Mirror.load(event.params.pubId.toString()); - if (mirror) { - mirror.collectedBy = event.params.collector.toHexString(); - mirror.save(); - } + // Revisit "pubId" to maybe use "rootPubId" instead + let post = Post.load(event.params.pubId.toString()); + if (post) { + post.collectedBy = event.params.collector.toHexString(); + post.save(); + } + + let comment = Comment.load(event.params.pubId.toString()); + if (comment) { + comment.collectedBy = event.params.collector.toHexString(); + comment.save(); + } + + let mirror = Mirror.load(event.params.pubId.toString()); + if (mirror) { + mirror.collectedBy = event.params.collector.toHexString(); + mirror.save(); + } }