diff --git a/generated/schema.ts b/generated/schema.ts index b8c4ac4..6d817be 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,7 +1963,385 @@ export class Mirror extends Entity { this.set("id", Value.fromString(value)); } - get profile(): string { + get createdAt(): string { + let value = this.get("createdAt"); + return value!.toString(); + } + + set createdAt(value: string) { + this.set("createdAt", Value.fromString(value)); + } + + get creator(): string { + let value = this.get("creator"); + return value!.toString(); + } + + set creator(value: string) { + this.set("creator", Value.fromString(value)); + } + + get mintedTo(): string { + let value = this.get("mintedTo"); + return value!.toString(); + } + + set mintedTo(value: string) { + this.set("mintedTo", 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 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 followModuleReturnData(): Bytes | null { + let value = this.get("followModuleReturnData"); + if (!value || value.kind == ValueKind.NULL) { + return null; + } else { + return value.toBytes(); + } + } + + set followModuleReturnData(value: Bytes | null) { + if (!value) { + this.unset("followModuleReturnData"); + } else { + this.set("followModuleReturnData", Value.fromBytes(value)); + } + } + + get followNftUri(): string | null { + let value = this.get("followNftUri"); + if (!value || value.kind == ValueKind.NULL) { + return null; + } else { + return value.toString(); + } + } + + set followNftUri(value: string | null) { + if (!value) { + this.unset("followNftUri"); + } else { + this.set("followNftUri", Value.fromString(value)); + } + } + + 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)); + } + + get mirrors(): Array { + let value = this.get("mirrors"); + return value!.toStringArray(); + } + + 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 { + constructor(id: string) { + super(); + this.set("id", Value.fromString(id)); + } + + save(): void { + let id = this.get("id"); + assert(id != null, "Cannot save Mirror 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()}` + ); + store.set("Mirror", id.toString(), this); + } + } + + static load(id: string): Mirror | null { + return changetype(store.get("Mirror", id)); + } + + get id(): string { + let value = this.get("id"); + return value!.toString(); + } + + set id(value: string) { + this.set("id", Value.fromString(value)); + } + + get profile(): string { let value = this.get("profile"); return value!.toString(); } @@ -2219,6 +2350,68 @@ export class Mirror extends Entity { this.set("profile", Value.fromString(value)); } + get createdAt(): string { + let value = this.get("createdAt"); + return value!.toString(); + } + + set createdAt(value: string) { + this.set("createdAt", Value.fromString(value)); + } + + get referenceModule(): string { + let value = this.get("referenceModule"); + return value!.toString(); + } + + 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)); + } + + 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 stats(): string { let value = this.get("stats"); return value!.toString(); @@ -2246,15 +2439,6 @@ export class Mirror extends Entity { this.set("onChainContentURI", Value.fromString(value)); } - get createdAt(): string { - let value = this.get("createdAt"); - return value!.toString(); - } - - set createdAt(value: string) { - this.set("createdAt", Value.fromString(value)); - } - get appId(): BigInt | null { let value = this.get("appId"); if (!value || value.kind == ValueKind.NULL) { @@ -2356,8 +2540,26 @@ export class Post extends Entity { this.set("id", Value.fromString(value)); } - get profile(): string | null { + get profile(): string { let value = this.get("profile"); + return value!.toString(); + } + + set profile(value: string) { + this.set("profile", 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 collectModule(): string | null { + let value = this.get("collectModule"); if (!value || value.kind == ValueKind.NULL) { return null; } else { @@ -2365,33 +2567,33 @@ export class Post extends Entity { } } - set profile(value: string | null) { + set collectModule(value: string | null) { if (!value) { - this.unset("profile"); + this.unset("collectModule"); } else { - this.set("profile", Value.fromString(value)); + this.set("collectModule", Value.fromString(value)); } } - get stats(): string | null { - let value = this.get("stats"); + 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 stats(value: string | null) { + set collectModuleReturnData(value: Bytes | null) { if (!value) { - this.unset("stats"); + this.unset("collectModuleReturnData"); } else { - this.set("stats", Value.fromString(value)); + this.set("collectModuleReturnData", Value.fromBytes(value)); } } - get metadata(): string | null { - let value = this.get("metadata"); + get referenceModule(): string | null { + let value = this.get("referenceModule"); if (!value || value.kind == ValueKind.NULL) { return null; } else { @@ -2399,21 +2601,29 @@ export class Post extends Entity { } } - set metadata(value: string | null) { + set referenceModule(value: string | null) { if (!value) { - this.unset("metadata"); + this.unset("referenceModule"); } else { - this.set("metadata", Value.fromString(value)); + this.set("referenceModule", Value.fromString(value)); } } - get onChainContentURI(): string { - let value = this.get("onChainContentURI"); - return value!.toString(); + get referenceModuleReturnData(): Bytes | null { + let value = this.get("referenceModuleReturnData"); + if (!value || value.kind == ValueKind.NULL) { + return null; + } else { + return value.toBytes(); + } } - set onChainContentURI(value: string) { - this.set("onChainContentURI", Value.fromString(value)); + set referenceModuleReturnData(value: Bytes | null) { + if (!value) { + this.unset("referenceModuleReturnData"); + } else { + this.set("referenceModuleReturnData", Value.fromBytes(value)); + } } get createdAt(): string { @@ -2425,6 +2635,40 @@ 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) { + return null; + } else { + return value.toStringArray(); + } + } + + set mirrors(value: Array | null) { + if (!value) { + this.unset("mirrors"); + } else { + this.set("mirrors", Value.fromStringArray(>value)); + } + } + get appId(): string | null { let value = this.get("appId"); if (!value || value.kind == ValueKind.NULL) { @@ -2511,20 +2755,37 @@ export class Post extends Entity { this.set("hasCollectedByMe", Value.fromBoolean(value)); } - get mirrors(): Array | null { - let value = this.get("mirrors"); + get stats(): string | null { + let value = this.get("stats"); if (!value || value.kind == ValueKind.NULL) { return null; } else { - return value.toStringArray(); + return value.toString(); } } - set mirrors(value: Array | null) { + set stats(value: string | null) { if (!value) { - this.unset("mirrors"); + this.unset("stats"); } else { - this.set("mirrors", Value.fromStringArray(>value)); + 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)); } } } @@ -2640,85 +2901,6 @@ export class Comment extends Entity { 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) { @@ -2735,15 +2917,6 @@ export class Comment extends Entity { 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..73eeed2 100644 --- a/schema.graphql +++ b/schema.graphql @@ -111,25 +111,6 @@ type Attribute @entity { 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 -} - enum ReactionTypes { UPVOTE DOWNVOTE @@ -255,13 +236,68 @@ type FollowOnlyReferenceModuleSettings @entity { 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 +} + +# Mirrors should extend "Post" +# https://docs.lens.xyz/docs/mirror type Mirror @entity { id: ID! profile: Profile! + createdAt: String! + + referenceModule: ReferenceModule! + referenceModuleReturnData: Bytes! + + profilePointed: Profile! + publicationPointed: Post! + + # Address of user who collected + collectedBy: String + + # Additional fields that we want to remove + # TODO: Refactor & remove stats: PublicationStats! metadata: MetadataOutput! onChainContentURI: String! - createdAt: String! appId: BigInt hidden: Boolean! collectNftAddress: String @@ -271,18 +307,34 @@ type Mirror @entity { type Post @entity { id: ID! - profile: Profile - stats: PublicationStats - metadata: MetadataOutput + profile: Profile! + onChainContentURI: String! + + # Address + collectModule: CollectModule + collectModuleReturnData: Bytes + + referenceModule: ReferenceModule + referenceModuleReturnData: Bytes + createdAt: String! + + # Address of user who collected + collectedBy: String + + mirrors: [ID!] + + # Additional fields that we want to remove + # TODO: Refactor & remove appId: String hidden: Boolean collectNftAddress: String collectedBy: Wallet reaction: ReactionTypes hasCollectedByMe: Boolean - mirrors: [ID!] + stats: PublicationStats + metadata: MetadataOutput } # TODO: We need to make "Comment" extend from "Publication" @@ -302,21 +354,8 @@ type Comment @entity { # 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! + # Address of user who collected + collectedBy: String } type Owner @entity { diff --git a/src/lens-hub.ts b/src/lens-hub.ts index e3dfbd3..785d5cb 100644 --- a/src/lens-hub.ts +++ b/src/lens-hub.ts @@ -2,69 +2,185 @@ import { log } from "@graphprotocol/graph-ts"; import { Approval as ApprovalEvent, ApprovalForAll as ApprovalForAllEvent, + Collected, + CommentCreated, + MirrorCreated, PostCreated, ProfileCreated, - Transfer as TransferEvent -} from "../generated/LensHub/LensHub" -import { Approval, ApprovalForAll, Post, Profile, Transfer } from "../generated/schema" + Transfer as TransferEvent, +} from "../generated/LensHub/LensHub"; +import { + 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() + ); + 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() + ); + 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() + ); + 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", []) - - 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() + 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(); + + 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; + + // 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()) - - 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() + 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.collectModule = event.params.collectModule.toHexString(); + post.collectModuleReturnData = event.params.collectModuleReturnData; + + 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(); + } + + 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(); } -} \ No newline at end of file + + 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(), + ]); + } +} + +// 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(); + } +} diff --git a/subgraph.yaml b/subgraph.yaml index d5bec42..cdace1c 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,bytes,address,bytes,address,bytes,uint256) + handler: handleCommentCreated + - 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) + handler: handleCollected file: ./src/lens-hub.ts