@show-karma/karma-gap-sdk 0.4.15 → 0.4.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (188) hide show
  1. package/.cursorrules +43 -0
  2. package/core/abi/AirdropNFT.json +1 -1
  3. package/core/abi/Allo.json +860 -860
  4. package/core/abi/AlloRegistry.json +578 -578
  5. package/core/abi/CommunityResolverABI.json +506 -506
  6. package/core/abi/Donations.json +251 -251
  7. package/core/abi/EAS.json +1 -1
  8. package/core/abi/MultiAttester.json +746 -746
  9. package/core/abi/ProjectResolver.json +574 -574
  10. package/core/abi/SchemaRegistry.json +1 -1
  11. package/core/abi/index.ts +21 -0
  12. package/core/class/AllGapSchemas.ts +21 -0
  13. package/core/class/Attestation.ts +429 -0
  14. package/core/class/Fetcher.ts +224 -0
  15. package/core/class/GAP.ts +481 -0
  16. package/core/class/GapSchema.ts +93 -0
  17. package/core/class/Gelato/{Gelato.js → Gelato.ts} +23 -0
  18. package/core/class/GrantProgramRegistry/Allo.ts +188 -0
  19. package/core/class/GrantProgramRegistry/AlloRegistry.ts +101 -0
  20. package/core/class/GraphQL/AxiosGQL.ts +29 -0
  21. package/core/class/GraphQL/EASClient.ts +34 -0
  22. package/core/class/GraphQL/GapEasClient.ts +869 -0
  23. package/core/class/Schema.ts +659 -0
  24. package/core/class/SchemaError.ts +42 -0
  25. package/core/class/contract/GapContract.ts +457 -0
  26. package/core/class/entities/Community.ts +148 -0
  27. package/core/class/entities/ContributorProfile.ts +108 -0
  28. package/core/class/entities/Grant.ts +321 -0
  29. package/core/class/entities/GrantUpdate.ts +187 -0
  30. package/core/class/entities/MemberOf.ts +52 -0
  31. package/core/class/entities/Milestone.ts +898 -0
  32. package/core/class/entities/Project.ts +672 -0
  33. package/core/class/entities/ProjectImpact.ts +170 -0
  34. package/core/class/entities/ProjectMilestone.ts +254 -0
  35. package/core/class/entities/ProjectPointer.ts +39 -0
  36. package/core/class/entities/ProjectUpdate.ts +176 -0
  37. package/core/class/entities/Track.ts +32 -0
  38. package/core/class/karma-indexer/GapIndexerClient.ts +383 -0
  39. package/core/class/karma-indexer/api/GapIndexerApi.ts +446 -0
  40. package/core/class/karma-indexer/api/types.ts +313 -0
  41. package/core/class/remote-storage/IpfsStorage.ts +76 -0
  42. package/core/class/remote-storage/RemoteStorage.ts +65 -0
  43. package/core/class/types/allo.ts +93 -0
  44. package/core/class/types/attestations.ts +223 -0
  45. package/core/consts.ts +775 -0
  46. package/core/scripts/create-grant.ts +102 -0
  47. package/core/scripts/create-program.ts +43 -0
  48. package/core/scripts/create-schemas.ts +65 -0
  49. package/core/scripts/deploy.ts +65 -0
  50. package/core/scripts/index.ts +1 -0
  51. package/core/scripts/milestone-multi-grants.ts +125 -0
  52. package/core/shared/types.ts +13 -0
  53. package/core/types.ts +224 -0
  54. package/core/utils/gelato/send-gelato-txn.ts +114 -0
  55. package/core/utils/gelato/sponsor-handler.ts +77 -0
  56. package/core/utils/gelato/watch-gelato-txn.ts +67 -0
  57. package/core/utils/get-date.ts +3 -0
  58. package/core/utils/get-ipfs-data.ts +13 -0
  59. package/core/utils/get-web3-provider.ts +18 -0
  60. package/core/utils/gql-queries.ts +133 -0
  61. package/core/utils/map-filter.ts +21 -0
  62. package/core/utils/serialize-bigint.ts +7 -0
  63. package/core/utils/to-unix.ts +18 -0
  64. package/create-community-example.ts +119 -0
  65. package/csv-upload/README.md +74 -0
  66. package/csv-upload/config.ts +41 -0
  67. package/csv-upload/example.csv +2 -0
  68. package/csv-upload/keys.example.json +8 -0
  69. package/csv-upload/scripts/run.ts +417 -0
  70. package/csv-upload/types.ts +39 -0
  71. package/docs/.gitkeep +0 -0
  72. package/docs/images/attestation-architecture.png +0 -0
  73. package/docs/images/dfd-get-projects.png +0 -0
  74. package/gap-schema.yaml +155 -0
  75. package/milestone-workflow-example.ts +353 -0
  76. package/package.json +45 -39
  77. package/readme.md +872 -0
  78. package/schemas/.gitkeep +0 -0
  79. package/schemas/GAP-schemas-1692135812877.json +33 -0
  80. package/test-file-indexer-api.ts +25 -0
  81. package/tsconfig.json +26 -0
  82. package/core/abi/index.d.ts +0 -1114
  83. package/core/abi/index.js +0 -26
  84. package/core/class/AllGapSchemas.d.ts +0 -9
  85. package/core/class/AllGapSchemas.js +0 -19
  86. package/core/class/Attestation.d.ts +0 -173
  87. package/core/class/Attestation.js +0 -333
  88. package/core/class/Fetcher.d.ts +0 -175
  89. package/core/class/Fetcher.js +0 -13
  90. package/core/class/GAP.d.ts +0 -254
  91. package/core/class/GAP.js +0 -289
  92. package/core/class/GapSchema.d.ts +0 -34
  93. package/core/class/GapSchema.js +0 -62
  94. package/core/class/GrantProgramRegistry/Allo.d.ts +0 -17
  95. package/core/class/GrantProgramRegistry/Allo.js +0 -137
  96. package/core/class/GrantProgramRegistry/AlloRegistry.d.ts +0 -15
  97. package/core/class/GrantProgramRegistry/AlloRegistry.js +0 -70
  98. package/core/class/GraphQL/AxiosGQL.d.ts +0 -6
  99. package/core/class/GraphQL/AxiosGQL.js +0 -25
  100. package/core/class/GraphQL/EASClient.d.ts +0 -16
  101. package/core/class/GraphQL/EASClient.js +0 -26
  102. package/core/class/GraphQL/GapEasClient.d.ts +0 -71
  103. package/core/class/GraphQL/GapEasClient.js +0 -451
  104. package/core/class/GraphQL/index.js +0 -19
  105. package/core/class/Schema.d.ts +0 -233
  106. package/core/class/Schema.js +0 -488
  107. package/core/class/SchemaError.d.ts +0 -30
  108. package/core/class/SchemaError.js +0 -39
  109. package/core/class/contract/GapContract.d.ts +0 -102
  110. package/core/class/contract/GapContract.js +0 -285
  111. package/core/class/entities/Community.d.ts +0 -34
  112. package/core/class/entities/Community.js +0 -109
  113. package/core/class/entities/ContributorProfile.d.ts +0 -41
  114. package/core/class/entities/ContributorProfile.js +0 -69
  115. package/core/class/entities/Grant.d.ts +0 -54
  116. package/core/class/entities/Grant.js +0 -223
  117. package/core/class/entities/GrantUpdate.d.ts +0 -40
  118. package/core/class/entities/GrantUpdate.js +0 -114
  119. package/core/class/entities/MemberOf.d.ts +0 -11
  120. package/core/class/entities/MemberOf.js +0 -33
  121. package/core/class/entities/Milestone.d.ts +0 -168
  122. package/core/class/entities/Milestone.js +0 -657
  123. package/core/class/entities/Project.d.ts +0 -92
  124. package/core/class/entities/Project.js +0 -418
  125. package/core/class/entities/ProjectImpact.d.ts +0 -50
  126. package/core/class/entities/ProjectImpact.js +0 -112
  127. package/core/class/entities/ProjectMilestone.d.ts +0 -60
  128. package/core/class/entities/ProjectMilestone.js +0 -174
  129. package/core/class/entities/ProjectPointer.d.ts +0 -12
  130. package/core/class/entities/ProjectPointer.js +0 -22
  131. package/core/class/entities/ProjectUpdate.d.ts +0 -50
  132. package/core/class/entities/ProjectUpdate.js +0 -110
  133. package/core/class/entities/Track.d.ts +0 -16
  134. package/core/class/entities/Track.js +0 -21
  135. package/core/class/entities/index.js +0 -26
  136. package/core/class/index.js +0 -26
  137. package/core/class/karma-indexer/GapIndexerClient.d.ts +0 -66
  138. package/core/class/karma-indexer/GapIndexerClient.js +0 -207
  139. package/core/class/karma-indexer/api/GapIndexerApi.d.ts +0 -73
  140. package/core/class/karma-indexer/api/GapIndexerApi.js +0 -256
  141. package/core/class/karma-indexer/api/types.d.ts +0 -295
  142. package/core/class/karma-indexer/api/types.js +0 -2
  143. package/core/class/remote-storage/IpfsStorage.d.ts +0 -23
  144. package/core/class/remote-storage/IpfsStorage.js +0 -56
  145. package/core/class/remote-storage/RemoteStorage.d.ts +0 -41
  146. package/core/class/remote-storage/RemoteStorage.js +0 -38
  147. package/core/class/types/allo.d.ts +0 -78
  148. package/core/class/types/allo.js +0 -2
  149. package/core/class/types/attestations.d.ts +0 -168
  150. package/core/class/types/attestations.js +0 -66
  151. package/core/consts.d.ts +0 -48
  152. package/core/consts.js +0 -641
  153. package/core/index.js +0 -24
  154. package/core/shared/types.d.ts +0 -6
  155. package/core/shared/types.js +0 -2
  156. package/core/types.d.ts +0 -131
  157. package/core/types.js +0 -13
  158. package/core/utils/gelato/index.js +0 -19
  159. package/core/utils/gelato/send-gelato-txn.d.ts +0 -55
  160. package/core/utils/gelato/send-gelato-txn.js +0 -100
  161. package/core/utils/gelato/sponsor-handler.d.ts +0 -9
  162. package/core/utils/gelato/sponsor-handler.js +0 -60
  163. package/core/utils/gelato/watch-gelato-txn.d.ts +0 -7
  164. package/core/utils/gelato/watch-gelato-txn.js +0 -63
  165. package/core/utils/get-date.d.ts +0 -1
  166. package/core/utils/get-date.js +0 -7
  167. package/core/utils/get-ipfs-data.d.ts +0 -1
  168. package/core/utils/get-ipfs-data.js +0 -20
  169. package/core/utils/get-web3-provider.d.ts +0 -2
  170. package/core/utils/get-web3-provider.js +0 -18
  171. package/core/utils/gql-queries.d.ts +0 -12
  172. package/core/utils/gql-queries.js +0 -90
  173. package/core/utils/index.js +0 -23
  174. package/core/utils/map-filter.d.ts +0 -8
  175. package/core/utils/map-filter.js +0 -20
  176. package/core/utils/serialize-bigint.d.ts +0 -1
  177. package/core/utils/serialize-bigint.js +0 -8
  178. package/core/utils/to-unix.d.ts +0 -1
  179. package/core/utils/to-unix.js +0 -25
  180. package/index.js +0 -17
  181. /package/core/class/GraphQL/{index.d.ts → index.ts} +0 -0
  182. /package/core/class/entities/{index.d.ts → index.ts} +0 -0
  183. /package/core/class/{index.d.ts → index.ts} +0 -0
  184. /package/core/{index.d.ts → index.ts} +0 -0
  185. /package/core/utils/gelato/{index.d.ts → index.ts} +0 -0
  186. /package/core/utils/{index.d.ts → index.ts} +0 -0
  187. /package/{core/class/Gelato/Gelato.d.ts → csv-upload/.gitkeep} +0 -0
  188. /package/{index.d.ts → index.ts} +0 -0
@@ -0,0 +1,170 @@
1
+ import { Hex, SignerOrProvider, TNetwork } from "../../types";
2
+ import { Attestation, AttestationArgs } from "../Attestation";
3
+ import { GapSchema } from "../GapSchema";
4
+ import { AttestationError } from "../SchemaError";
5
+ import { AllGapSchemas } from "../AllGapSchemas";
6
+ import { chainIdToNetwork } from "../../consts";
7
+ import { Transaction } from "ethers";
8
+
9
+ export interface _IProjectImpact extends ProjectImpact {}
10
+
11
+ type IStatus = "verified";
12
+
13
+ export interface IProjectImpactStatus {
14
+ type?: `project-impact-${IStatus}`;
15
+ reason?: string;
16
+ }
17
+
18
+ export class ProjectImpactStatus
19
+ extends Attestation<IProjectImpactStatus>
20
+ implements IProjectImpactStatus
21
+ {
22
+ type: `project-impact-${IStatus}`;
23
+ reason?: string;
24
+ }
25
+
26
+ export interface IProjectImpact {
27
+ work: string;
28
+ impact: string;
29
+ proof: string;
30
+ startedAt?: number;
31
+ completedAt: number;
32
+ type?: string;
33
+ verified?: ProjectImpactStatus[];
34
+ }
35
+
36
+ export class ProjectImpact
37
+ extends Attestation<IProjectImpact>
38
+ implements IProjectImpact
39
+ {
40
+ work: string;
41
+ impact: string;
42
+ proof: string;
43
+ startedAt?: number;
44
+ completedAt: number;
45
+ type?: string;
46
+ verified: ProjectImpactStatus[] = [];
47
+
48
+ constructor(data: AttestationArgs<IProjectImpact, GapSchema>) {
49
+ (data.data as any).type = "project-impact";
50
+ super(data);
51
+ }
52
+
53
+ /**
54
+ * Attest Project Impact.
55
+ */
56
+ private async attestStatus(
57
+ signer: SignerOrProvider,
58
+ schema: GapSchema,
59
+ callback?: Function
60
+ ) {
61
+ const eas = this.schema.gap.eas.connect(signer);
62
+ try {
63
+ if (callback) callback("preparing");
64
+ const tx = await eas.attest({
65
+ schema: schema.uid,
66
+ data: {
67
+ recipient: this.recipient,
68
+ data: schema.encode(),
69
+ refUID: this.uid,
70
+ expirationTime: 0n,
71
+ revocable: schema.revocable,
72
+ },
73
+ });
74
+
75
+ if (callback) callback("pending");
76
+ const uid = await tx.wait();
77
+ if (callback) callback("confirmed");
78
+
79
+ console.log(uid);
80
+ return {
81
+ tx: [
82
+ {
83
+ hash: tx.tx.hash as Hex,
84
+ } as Transaction,
85
+ ],
86
+ uids: [uid as `0x${string}`],
87
+ };
88
+ } catch (error: any) {
89
+ console.error(error);
90
+ throw new AttestationError("ATTEST_ERROR", error.message, error);
91
+ }
92
+ }
93
+
94
+ /**
95
+ * Verify this ProjectImpact. If the ProjectImpact is not already verified,
96
+ * it will throw an error.
97
+ * @param signer
98
+ * @param reason
99
+ */
100
+ async verify(signer: SignerOrProvider, data?: IProjectImpactStatus, callback?: Function) {
101
+ console.log("Verifying ProjectImpact");
102
+
103
+ const schema = this.schema.gap.findSchema("GrantUpdateStatus");
104
+ if (this.schema.isJsonSchema()) {
105
+ schema.setValue("json", JSON.stringify({
106
+ type: "project-impact-verified",
107
+ reason: data?.reason || '',
108
+ }))
109
+ } else {
110
+ schema.setValue("type", "project-impact-verified");
111
+ schema.setValue("reason", data?.reason || '');
112
+ }
113
+
114
+ console.log("Before attest project impact verified");
115
+ const { tx, uids } = await this.attestStatus(signer, schema, callback);
116
+ console.log("After attest project impact verified");
117
+
118
+ this.verified.push(
119
+ new ProjectImpactStatus({
120
+ data: {
121
+ type: "project-impact-verified",
122
+ reason: data?.reason || '',
123
+ },
124
+ refUID: this.uid,
125
+ schema: schema,
126
+ recipient: this.recipient,
127
+ })
128
+ );
129
+
130
+ return { tx, uids };
131
+ }
132
+
133
+ static from(
134
+ attestations: ProjectImpact[],
135
+ network: TNetwork
136
+ ): ProjectImpact[] {
137
+ return attestations.map((attestation) => {
138
+ const projectImpact = new ProjectImpact({
139
+ ...attestation,
140
+ data: {
141
+ ...attestation.data,
142
+ },
143
+ schema: new AllGapSchemas().findSchema(
144
+ "ProjectImpact",
145
+ chainIdToNetwork[attestation.chainID] as TNetwork
146
+ ),
147
+ chainID: attestation.chainID,
148
+ });
149
+
150
+ if (attestation.verified?.length > 0) {
151
+ projectImpact.verified = attestation.verified.map(
152
+ (m) =>
153
+ new ProjectImpactStatus({
154
+ ...m,
155
+ data: {
156
+ ...m.data,
157
+ },
158
+ schema: new AllGapSchemas().findSchema(
159
+ "GrantUpdateStatus",
160
+ chainIdToNetwork[attestation.chainID] as TNetwork
161
+ ),
162
+ chainID: attestation.chainID,
163
+ })
164
+ );
165
+ }
166
+
167
+ return projectImpact;
168
+ });
169
+ }
170
+ }
@@ -0,0 +1,254 @@
1
+ import { SignerOrProvider, TNetwork } from "../../../core/types";
2
+ import { Attestation, AttestationArgs } from "../Attestation";
3
+ import { GapSchema } from "../GapSchema";
4
+ import { AttestationError } from "../SchemaError";
5
+ import { AllGapSchemas } from "../AllGapSchemas";
6
+ import { chainIdToNetwork } from "../../../core/consts";
7
+ import { Transaction } from "ethers";
8
+ import { Hex, IProjectMilestoneResponse } from "../karma-indexer/api/types";
9
+ import {
10
+ AttestationWithTx,
11
+ IMilestoneCompleted as IProjectMilestoneCompleted,
12
+ MilestoneCompleted as ProjectMilestoneCompleted,
13
+ } from "../types/attestations";
14
+
15
+ export interface IProjectMilestone {
16
+ title: string;
17
+ text: string;
18
+ type?: string;
19
+ }
20
+
21
+ type IStatus = "verified" | "completed";
22
+
23
+ export interface IProjectMilestoneStatus {
24
+ type?: `project-milestone-${IStatus}`;
25
+ proofOfWork?: string;
26
+ reason?: string;
27
+ }
28
+
29
+ export class ProjectMilestoneStatus
30
+ extends Attestation<IProjectMilestoneStatus>
31
+ implements IProjectMilestoneStatus
32
+ {
33
+ type: `project-milestone-${IStatus}`;
34
+ reason?: string;
35
+ }
36
+
37
+ export class ProjectMilestone
38
+ extends Attestation<IProjectMilestone>
39
+ implements IProjectMilestone
40
+ {
41
+ title: string;
42
+ text: string;
43
+ verified: ProjectMilestoneStatus[] = [];
44
+ completed: ProjectMilestoneCompleted;
45
+
46
+ constructor(data: AttestationArgs<IProjectMilestone, GapSchema>) {
47
+ (data.data as any).type = "project-milestone";
48
+ super(data);
49
+ }
50
+
51
+ /**
52
+ * Attest the status of the update as approved, rejected or completed.
53
+ */
54
+ private async attestStatus(
55
+ signer: SignerOrProvider,
56
+ schema: GapSchema,
57
+ callback?: Function
58
+ ): Promise<AttestationWithTx> {
59
+ const eas = this.schema.gap.eas.connect(signer);
60
+ try {
61
+ if (callback) callback("preparing");
62
+ const tx = await eas.attest({
63
+ schema: schema.uid,
64
+ data: {
65
+ recipient: this.recipient,
66
+ data: schema.encode(),
67
+ refUID: this.uid,
68
+ expirationTime: 0n,
69
+ revocable: schema.revocable,
70
+ },
71
+ });
72
+
73
+ if (callback) callback("pending");
74
+ const uid = await tx.wait();
75
+ if (callback) callback("confirmed");
76
+
77
+ console.log(uid);
78
+ return {
79
+ tx: [
80
+ {
81
+ hash: tx.tx.hash as Hex,
82
+ } as Transaction,
83
+ ],
84
+ uids: [uid as `0x${string}`],
85
+ };
86
+ } catch (error: any) {
87
+ console.error(error);
88
+ throw new AttestationError("ATTEST_ERROR", error.message, error);
89
+ }
90
+ }
91
+
92
+ /**
93
+ * Verify this ProjectUpdate. If the ProjectUpdate is not already verified,
94
+ * it will throw an error.
95
+ * @param signer
96
+ * @param reason
97
+ */
98
+ async verify(
99
+ signer: SignerOrProvider,
100
+ data?: IProjectMilestoneStatus,
101
+ callback?: Function
102
+ ) {
103
+ console.log("Verifying");
104
+
105
+ const schema = this.schema.gap.findSchema("ProjectMilestoneStatus");
106
+ if (this.schema.isJsonSchema()) {
107
+ schema.setValue(
108
+ "json",
109
+ JSON.stringify({
110
+ type: "verified",
111
+ reason: data?.reason || "",
112
+ })
113
+ );
114
+ } else {
115
+ schema.setValue("type", "project-milestone-verified");
116
+ schema.setValue("reason", data?.reason || "");
117
+ }
118
+ console.log("Before attest project milestone verified");
119
+ await this.attestStatus(signer, schema, callback);
120
+ console.log("After attest project milestone verified");
121
+
122
+ this.verified.push(
123
+ new ProjectMilestoneStatus({
124
+ data: {
125
+ type: "project-milestone-verified",
126
+ reason: data?.reason || "",
127
+ },
128
+ refUID: this.uid,
129
+ schema: schema,
130
+ recipient: this.recipient,
131
+ })
132
+ );
133
+ }
134
+
135
+ /**
136
+ * Marks a milestone as completed. If the milestone is already completed,
137
+ * it will throw an error.
138
+ * @param signer
139
+ * @param reason
140
+ */
141
+ async complete(
142
+ signer: SignerOrProvider,
143
+ data?: IProjectMilestoneStatus,
144
+ callback?: Function
145
+ ) {
146
+ console.log("Completing");
147
+
148
+ const schema = this.schema.gap.findSchema("ProjectMilestoneStatus");
149
+ if (this.schema.isJsonSchema()) {
150
+ schema.setValue(
151
+ "json",
152
+ JSON.stringify({
153
+ type: "project-milestone-completed",
154
+ ...data,
155
+ })
156
+ );
157
+ } else {
158
+ schema.setValue("type", "project-milestone-completed");
159
+ schema.setValue("proofOfWork", data?.proofOfWork || "");
160
+ schema.setValue("reason", data?.reason || "");
161
+ }
162
+ console.log("Before attest project milestone completed");
163
+ const { tx, uids } = await this.attestStatus(signer, schema, callback);
164
+ console.log("After attest project milestone completed");
165
+
166
+ this.completed = new ProjectMilestoneCompleted({
167
+ data: {
168
+ reason: data?.reason || "",
169
+ },
170
+ refUID: this.uid,
171
+ schema: schema,
172
+ recipient: this.recipient,
173
+ });
174
+ return { tx, uids };
175
+ }
176
+
177
+ /**
178
+ * Revokes the completed status of the milestone. If the milestone is not completed,
179
+ * it will throw an error.
180
+ * @param signer
181
+ */
182
+ async revokeCompletion(signer: SignerOrProvider, callback?: Function) {
183
+ if (!this.completed)
184
+ throw new AttestationError("ATTEST_ERROR", "Milestone is not completed");
185
+
186
+ const { tx, uids } = await this.completed.schema.multiRevoke(
187
+ signer,
188
+ [
189
+ {
190
+ schemaId: this.completed.schema.uid,
191
+ uid: this.completed.uid,
192
+ },
193
+ ],
194
+ callback
195
+ );
196
+ return { tx, uids };
197
+ }
198
+
199
+ static from(
200
+ attestations: IProjectMilestoneResponse[],
201
+ network: TNetwork
202
+ ): ProjectMilestone[] {
203
+ return attestations.map((attestation) => {
204
+ const projectMilestone = new ProjectMilestone({
205
+ ...attestation,
206
+ data: {
207
+ ...attestation.data,
208
+ },
209
+ schema: new AllGapSchemas().findSchema(
210
+ "ProjectMilestone",
211
+ chainIdToNetwork[attestation.chainID] as TNetwork
212
+ ),
213
+ chainID: attestation.chainID,
214
+ });
215
+
216
+ if (attestation.verified?.length > 0) {
217
+ projectMilestone.verified = attestation.verified.map(
218
+ (m) =>
219
+ new ProjectMilestoneStatus({
220
+ ...m,
221
+ data: {
222
+ ...m.data,
223
+ type:
224
+ m.data.type === "completed"
225
+ ? "project-milestone-completed"
226
+ : "project-milestone-verified",
227
+ },
228
+ schema: new AllGapSchemas().findSchema(
229
+ "ProjectMilestoneStatus",
230
+ chainIdToNetwork[attestation.chainID] as TNetwork
231
+ ),
232
+ chainID: attestation.chainID,
233
+ })
234
+ );
235
+ }
236
+
237
+ if (attestation.completed) {
238
+ projectMilestone.completed = new ProjectMilestoneCompleted({
239
+ ...attestation.completed,
240
+ data: {
241
+ ...attestation.completed.data,
242
+ },
243
+ schema: new AllGapSchemas().findSchema(
244
+ "MilestoneCompleted",
245
+ chainIdToNetwork[attestation.chainID] as TNetwork
246
+ ),
247
+ chainID: attestation.chainID,
248
+ });
249
+ }
250
+
251
+ return projectMilestone;
252
+ });
253
+ }
254
+ }
@@ -0,0 +1,39 @@
1
+ import { TNetwork } from "../../../core/types";
2
+ import { Attestation } from "../Attestation";
3
+ import { AllGapSchemas } from "../AllGapSchemas";
4
+ import { chainIdToNetwork } from "../../../core/consts";
5
+
6
+ export interface _IProjectPointer extends ProjectPointer {}
7
+
8
+ export interface IProjectPointer {
9
+ ogProjectUID: string;
10
+ type?: string;
11
+ }
12
+
13
+ export class ProjectPointer
14
+ extends Attestation<IProjectPointer>
15
+ implements IProjectPointer
16
+ {
17
+ ogProjectUID: string;
18
+
19
+ static from(
20
+ attestations: _IProjectPointer[],
21
+ network: TNetwork
22
+ ): ProjectPointer[] {
23
+ return attestations.map((attestation) => {
24
+ const projectUpdate = new ProjectPointer({
25
+ ...attestation,
26
+ data: {
27
+ ...attestation.data,
28
+ },
29
+ schema: new AllGapSchemas().findSchema(
30
+ "ProjectUpdate",
31
+ chainIdToNetwork[attestation.chainID] as TNetwork
32
+ ),
33
+ chainID: attestation.chainID,
34
+ });
35
+
36
+ return projectUpdate;
37
+ });
38
+ }
39
+ }
@@ -0,0 +1,176 @@
1
+ import { SignerOrProvider, TNetwork } from "../../../core/types";
2
+ import { Attestation } from "../Attestation";
3
+ import { GapSchema } from "../GapSchema";
4
+ import { AttestationError } from "../SchemaError";
5
+ import { AllGapSchemas } from "../AllGapSchemas";
6
+ import { chainIdToNetwork } from "../../../core/consts";
7
+ import { Transaction } from "ethers";
8
+ import { Hex } from "../karma-indexer/api/types";
9
+ import { AttestationWithTx } from "../types/attestations";
10
+
11
+ export interface _IProjectUpdate extends ProjectUpdate {}
12
+ export interface IProjectUpdate {
13
+ title: string;
14
+ text: string;
15
+ startDate?: Date;
16
+ endDate?: Date;
17
+ type?: string;
18
+ grants?: string[];
19
+ indicators?: {
20
+ name: string;
21
+ indicatorId: string;
22
+ }[];
23
+ deliverables?: {
24
+ name: string;
25
+ proof: string;
26
+ description: string;
27
+ }[];
28
+ }
29
+
30
+ type IStatus = "verified";
31
+
32
+ export interface IProjectUpdateStatus {
33
+ type?: `project-update-${IStatus}`;
34
+ reason?: string;
35
+ proofOfWork?: string;
36
+ }
37
+
38
+ export class ProjectUpdateStatus
39
+ extends Attestation<IProjectUpdateStatus>
40
+ implements IProjectUpdateStatus
41
+ {
42
+ type: `project-update-${IStatus}`;
43
+ reason?: string;
44
+ proofOfWork?: string;
45
+ }
46
+
47
+ export class ProjectUpdate
48
+ extends Attestation<IProjectUpdate>
49
+ implements IProjectUpdate
50
+ {
51
+ title: string;
52
+ text: string;
53
+ verified: ProjectUpdateStatus[] = [];
54
+
55
+ /**
56
+ * Attest the status of the update as approved, rejected or completed.
57
+ */
58
+ private async attestStatus(
59
+ signer: SignerOrProvider,
60
+ schema: GapSchema,
61
+ callback?: Function
62
+ ): Promise<AttestationWithTx> {
63
+ const eas = this.schema.gap.eas.connect(signer);
64
+ try {
65
+ if (callback) callback("preparing");
66
+ const tx = await eas.attest({
67
+ schema: schema.uid,
68
+ data: {
69
+ recipient: this.recipient,
70
+ data: schema.encode(),
71
+ refUID: this.uid,
72
+ expirationTime: 0n,
73
+ revocable: schema.revocable,
74
+ },
75
+ });
76
+
77
+ if (callback) callback("pending");
78
+ const uid = await tx.wait();
79
+ if (callback) callback("confirmed");
80
+
81
+ console.log(uid);
82
+ return {
83
+ tx: [
84
+ {
85
+ hash: tx.tx.hash as Hex,
86
+ } as Transaction,
87
+ ],
88
+ uids: [uid as `0x${string}`],
89
+ };
90
+ } catch (error: any) {
91
+ console.error(error);
92
+ throw new AttestationError("ATTEST_ERROR", error.message, error);
93
+ }
94
+ }
95
+
96
+ /**
97
+ * Verify this ProjectUpdate. If the ProjectUpdate is not already verified,
98
+ * it will throw an error.
99
+ * @param signer
100
+ * @param reason
101
+ */
102
+ async verify(
103
+ signer: SignerOrProvider,
104
+ data?: IProjectUpdateStatus,
105
+ callback?: Function
106
+ ) {
107
+ console.log("Verifying");
108
+
109
+ const schema = this.schema.gap.findSchema("ProjectUpdateStatus");
110
+ if (this.schema.isJsonSchema()) {
111
+ schema.setValue(
112
+ "json",
113
+ JSON.stringify({
114
+ type: "verified",
115
+ reason: data?.reason || "",
116
+ })
117
+ );
118
+ } else {
119
+ schema.setValue("type", "project-update-verified");
120
+ schema.setValue("reason", data?.reason || "");
121
+ }
122
+ console.log("Before attest project update verified");
123
+ await this.attestStatus(signer, schema, callback);
124
+ console.log("After attest project update verified");
125
+
126
+ this.verified.push(
127
+ new ProjectUpdateStatus({
128
+ data: {
129
+ type: "project-update-verified",
130
+ reason: data?.reason || "",
131
+ },
132
+ refUID: this.uid,
133
+ schema: schema,
134
+ recipient: this.recipient,
135
+ })
136
+ );
137
+ }
138
+
139
+ static from(
140
+ attestations: _IProjectUpdate[],
141
+ network: TNetwork
142
+ ): ProjectUpdate[] {
143
+ return attestations.map((attestation) => {
144
+ const projectUpdate = new ProjectUpdate({
145
+ ...attestation,
146
+ data: {
147
+ ...attestation.data,
148
+ },
149
+ schema: new AllGapSchemas().findSchema(
150
+ "ProjectUpdate",
151
+ chainIdToNetwork[attestation.chainID] as TNetwork
152
+ ),
153
+ chainID: attestation.chainID,
154
+ });
155
+
156
+ if (attestation.verified?.length > 0) {
157
+ projectUpdate.verified = attestation.verified.map(
158
+ (m) =>
159
+ new ProjectUpdateStatus({
160
+ ...m,
161
+ data: {
162
+ ...m.data,
163
+ },
164
+ schema: new AllGapSchemas().findSchema(
165
+ "ProjectUpdateStatus",
166
+ chainIdToNetwork[attestation.chainID] as TNetwork
167
+ ),
168
+ chainID: attestation.chainID,
169
+ })
170
+ );
171
+ }
172
+
173
+ return projectUpdate;
174
+ });
175
+ }
176
+ }
@@ -0,0 +1,32 @@
1
+ import { TNetwork } from "core/types";
2
+ import { ITrackResponse } from "../karma-indexer/api/types";
3
+
4
+ export class Track {
5
+ id: string;
6
+ name: string;
7
+ description?: string;
8
+ communityUID: string;
9
+ isArchived: boolean;
10
+ createdAt: Date;
11
+ updatedAt: Date;
12
+ programId?: string;
13
+ isActive?: boolean;
14
+ network: TNetwork;
15
+
16
+ constructor(data: any, network: TNetwork) {
17
+ this.id = data.id;
18
+ this.name = data.name;
19
+ this.description = data.description;
20
+ this.communityUID = data.communityUID;
21
+ this.isArchived = data.isArchived ?? false;
22
+ this.createdAt = new Date(data.createdAt);
23
+ this.updatedAt = new Date(data.updatedAt);
24
+ this.programId = data.programId;
25
+ this.isActive = data.isActive;
26
+ this.network = network;
27
+ }
28
+
29
+ static from(data: ITrackResponse[], network: TNetwork): Track[] {
30
+ return data.map((item) => new Track(item, network));
31
+ }
32
+ }