@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
@@ -1,657 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Milestone = void 0;
4
- const consts_1 = require("../../consts");
5
- const AllGapSchemas_1 = require("../AllGapSchemas");
6
- const Attestation_1 = require("../Attestation");
7
- const SchemaError_1 = require("../SchemaError");
8
- const GapContract_1 = require("../contract/GapContract");
9
- const attestations_1 = require("../types/attestations");
10
- /**
11
- * Milestone class represents a milestone that can be attested to one or multiple grants.
12
- *
13
- * It provides methods to:
14
- * - Create, complete, approve, reject, and verify milestones
15
- * - Attest a milestone to a single grant
16
- * - Attest a milestone to multiple grants in a single transaction
17
- * - Complete, approve, and verify milestones across multiple grants
18
- * - Revoke multiple milestone attestations at once
19
- */
20
- class Milestone extends Attestation_1.Attestation {
21
- constructor() {
22
- super(...arguments);
23
- this.verified = [];
24
- this.type = "milestone";
25
- }
26
- /**
27
- * Approves this milestone. If the milestone is not completed or already approved,
28
- * it will throw an error.
29
- * @param signer
30
- * @param reason
31
- */
32
- async approve(signer, data, callback) {
33
- if (!this.completed)
34
- throw new SchemaError_1.AttestationError("ATTEST_ERROR", "Milestone is not completed");
35
- const schema = this.schema.gap.findSchema("MilestoneCompleted");
36
- if (this.schema.isJsonSchema()) {
37
- schema.setValue("json", JSON.stringify({
38
- type: "approved",
39
- ...data,
40
- }));
41
- }
42
- else {
43
- schema.setValue("type", "approved");
44
- schema.setValue("reason", data?.reason || "");
45
- schema.setValue("proofOfWork", data?.proofOfWork || "");
46
- }
47
- await this.attestStatus(signer, schema, callback);
48
- this.approved = new attestations_1.MilestoneCompleted({
49
- data: {
50
- type: "approved",
51
- reason: data?.reason || "",
52
- },
53
- refUID: this.uid,
54
- schema: schema,
55
- recipient: this.recipient,
56
- });
57
- }
58
- /**
59
- * Approves this milestone across multiple grants. If the milestones are not completed,
60
- * it will throw an error.
61
- * @param signer - The signer to use for attestation
62
- * @param milestoneUIDs - Array of milestone UIDs to approve
63
- * @param data - Optional approval data
64
- * @param callback - Optional callback function for status updates
65
- * @returns Promise with transaction and UIDs
66
- */
67
- async approveMultipleGrants(signer, milestoneUIDs, data, callback) {
68
- // Validate that all milestones are completed
69
- if (!this.completed)
70
- throw new SchemaError_1.AttestationError("ATTEST_ERROR", "Milestone is not completed");
71
- const schema = this.schema.gap.findSchema("MilestoneCompleted");
72
- if (this.schema.isJsonSchema()) {
73
- schema.setValue("json", JSON.stringify({
74
- type: "approved",
75
- ...data,
76
- }));
77
- }
78
- else {
79
- schema.setValue("type", "approved");
80
- schema.setValue("reason", data?.reason || "");
81
- schema.setValue("proofOfWork", data?.proofOfWork || "");
82
- }
83
- // Create approval attestations for each milestone
84
- const approvalPayloads = [];
85
- for (const milestoneUID of milestoneUIDs) {
86
- const approved = new attestations_1.MilestoneCompleted({
87
- data: {
88
- type: "approved",
89
- ...data,
90
- },
91
- refUID: milestoneUID,
92
- schema,
93
- recipient: this.recipient,
94
- });
95
- // Add approval to the payload
96
- approvalPayloads.push([
97
- approved,
98
- await approved.payloadFor(0), // Index doesn't matter for approval
99
- ]);
100
- }
101
- // Attest all approvals at once
102
- const result = await GapContract_1.GapContract.multiAttest(signer, approvalPayloads.map((p) => p[1]), callback);
103
- // Save the first approval to this milestone instance
104
- if (result.uids.length > 0) {
105
- this.approved = new attestations_1.MilestoneCompleted({
106
- data: {
107
- type: "approved",
108
- ...data,
109
- },
110
- refUID: milestoneUIDs[0],
111
- uid: result.uids[0],
112
- schema,
113
- recipient: this.recipient,
114
- });
115
- }
116
- return result;
117
- }
118
- /**
119
- * Revokes the approved status of the milestone. If the milestone is not approved,
120
- * it will throw an error.
121
- * @param signer
122
- */
123
- async revokeApproval(signer) {
124
- if (!this.approved)
125
- throw new SchemaError_1.AttestationError("ATTEST_ERROR", "Milestone is not approved");
126
- await this.approved.schema.multiRevoke(signer, [
127
- {
128
- schemaId: this.completed.schema.uid,
129
- uid: this.completed.uid,
130
- },
131
- ]);
132
- }
133
- /**
134
- * Reject a completed milestone. If the milestone is not completed or already rejected,
135
- * it will throw an error.
136
- * @param signer
137
- * @param reason
138
- */
139
- async reject(signer, reason = "") {
140
- if (!this.completed)
141
- throw new SchemaError_1.AttestationError("ATTEST_ERROR", "Milestone is not completed");
142
- const schema = this.schema.gap.findSchema("MilestoneCompleted");
143
- schema.setValue("type", "rejected");
144
- schema.setValue("reason", reason);
145
- await this.attestStatus(signer, schema);
146
- this.rejected = new attestations_1.MilestoneCompleted({
147
- data: {
148
- type: "rejected",
149
- reason,
150
- },
151
- refUID: this.uid,
152
- schema: schema,
153
- recipient: this.recipient,
154
- });
155
- }
156
- /**
157
- * Revokes the rejected status of the milestone. If the milestone is not rejected,
158
- * it will throw an error.
159
- * @param signer
160
- */
161
- async revokeRejection(signer) {
162
- if (!this.rejected)
163
- throw new SchemaError_1.AttestationError("ATTEST_ERROR", "Milestone is not rejected");
164
- const { tx, uids } = await this.rejected.schema.multiRevoke(signer, [
165
- {
166
- schemaId: this.completed.schema.uid,
167
- uid: this.completed.uid,
168
- },
169
- ]);
170
- return { tx, uids };
171
- }
172
- /**
173
- * Revokes multiple milestone attestations at once.
174
- * This method can be used to revoke multiple milestone attestations in a single transaction.
175
- *
176
- * @param signer - The signer to use for revocation
177
- * @param attestationsToRevoke - Array of objects containing schemaId and uid of attestations to revoke
178
- * @param callback - Optional callback function for status updates
179
- * @returns Promise with transaction and UIDs of revoked attestations
180
- */
181
- async revokeMultipleAttestations(signer, attestationsToRevoke, callback) {
182
- if (attestationsToRevoke.length === 0) {
183
- throw new SchemaError_1.AttestationError("ATTEST_ERROR", "No attestations specified for revocation");
184
- }
185
- // Group the attestations by schema ID
186
- const groupedAttestations = attestationsToRevoke.reduce((acc, { schemaId, uid }) => {
187
- if (!acc[schemaId]) {
188
- acc[schemaId] = [];
189
- }
190
- acc[schemaId].push(uid);
191
- return acc;
192
- }, {});
193
- // Convert to the format expected by GapContract.multiRevoke
194
- const revocationPayload = Object.entries(groupedAttestations).map(([schemaId, uids]) => ({
195
- schema: schemaId,
196
- data: uids.map((uid) => ({
197
- uid,
198
- value: 0n, // EAS contract requires a value field as BigInt
199
- })),
200
- }));
201
- // Use GapContract.multiRevoke directly with the correct payload format
202
- const result = await GapContract_1.GapContract.multiRevoke(signer, revocationPayload);
203
- if (callback) {
204
- callback("confirmed");
205
- }
206
- return result;
207
- }
208
- /**
209
- * Marks a milestone as completed. If the milestone is already completed,
210
- * it will throw an error.
211
- * @param signer
212
- * @param reason
213
- */
214
- async complete(signer, data, callback) {
215
- const schema = this.schema.gap.findSchema("MilestoneCompleted");
216
- if (this.schema.isJsonSchema()) {
217
- schema.setValue("json", JSON.stringify({
218
- type: "completed",
219
- ...data,
220
- }));
221
- }
222
- else {
223
- schema.setValue("type", "completed");
224
- schema.setValue("reason", data?.reason || "");
225
- schema.setValue("proofOfWork", data?.proofOfWork || "");
226
- }
227
- const { tx, uids } = await this.attestStatus(signer, schema, callback);
228
- this.completed = new attestations_1.MilestoneCompleted({
229
- data: {
230
- type: "completed",
231
- ...data,
232
- },
233
- refUID: this.uid,
234
- schema,
235
- recipient: this.recipient,
236
- });
237
- return { tx, uids };
238
- }
239
- /**
240
- * Marks a milestone as completed across multiple grants. If the milestone is already completed,
241
- * it will throw an error.
242
- * @param signer - The signer to use for attestation
243
- * @param grantIndices - Array of grant indices to attest this milestone to, or array of milestone UIDs
244
- * @param data - Optional completion data
245
- * @param callback - Optional callback function for status updates
246
- * @returns Promise with transaction and UIDs
247
- */
248
- async completeForMultipleGrants(signer, grantIndicesOrMilestoneUIDs = [0], data, callback) {
249
- // Check if we're dealing with UIDs instead of indices
250
- const isUids = grantIndicesOrMilestoneUIDs.length > 0 &&
251
- typeof grantIndicesOrMilestoneUIDs[0] === "string";
252
- let milestoneUIDs = [];
253
- if (isUids) {
254
- // We already have milestone UIDs
255
- milestoneUIDs = grantIndicesOrMilestoneUIDs;
256
- }
257
- else {
258
- // First attest the milestone to multiple grants if not already attested
259
- const attestResult = await this.attestToMultipleGrants(signer, grantIndicesOrMilestoneUIDs, callback);
260
- milestoneUIDs = attestResult.uids;
261
- }
262
- // Now complete the milestone for each attested milestone
263
- const schema = this.schema.gap.findSchema("MilestoneCompleted");
264
- if (this.schema.isJsonSchema()) {
265
- schema.setValue("json", JSON.stringify({
266
- type: "completed",
267
- ...data,
268
- }));
269
- }
270
- else {
271
- schema.setValue("type", "completed");
272
- schema.setValue("reason", data?.reason || "");
273
- schema.setValue("proofOfWork", data?.proofOfWork || "");
274
- }
275
- // Create completion attestations for each milestone
276
- const completionPayloads = [];
277
- for (let i = 0; i < milestoneUIDs.length; i++) {
278
- const milestoneUID = milestoneUIDs[i];
279
- // Only set this.uid if we're dealing with indices and need to update the current milestone
280
- if (!isUids) {
281
- this.uid = milestoneUID; // Set the current UID to the milestone being completed
282
- }
283
- const completed = new attestations_1.MilestoneCompleted({
284
- data: {
285
- type: "completed",
286
- ...data,
287
- },
288
- refUID: milestoneUID,
289
- schema,
290
- recipient: this.recipient,
291
- });
292
- // Add completed status to the payload
293
- completionPayloads.push([completed, await completed.payloadFor(i)]);
294
- }
295
- // Attest all completions at once
296
- const completionResult = await GapContract_1.GapContract.multiAttest(signer, completionPayloads.map((p) => p[1]), callback);
297
- // Save the first completion to this milestone instance
298
- if (completionResult.uids.length > 0 && !isUids) {
299
- this.completed = new attestations_1.MilestoneCompleted({
300
- data: {
301
- type: "completed",
302
- ...data,
303
- },
304
- refUID: milestoneUIDs[0],
305
- uid: completionResult.uids[0],
306
- schema,
307
- recipient: this.recipient,
308
- });
309
- }
310
- return isUids
311
- ? completionResult // If we're using UIDs directly, just return completion result
312
- : {
313
- tx: [
314
- ...(milestoneUIDs.length ? [{ hash: "" }] : []),
315
- ...completionResult.tx,
316
- ],
317
- uids: [...milestoneUIDs, ...completionResult.uids],
318
- };
319
- }
320
- /**
321
- * Revokes the completed status of the milestone. If the milestone is not completed,
322
- * it will throw an error.
323
- * @param signer
324
- */
325
- async revokeCompletion(signer, callback) {
326
- if (!this.completed)
327
- throw new SchemaError_1.AttestationError("ATTEST_ERROR", "Milestone is not completed");
328
- const { tx, uids } = await this.completed.schema.multiRevoke(signer, [
329
- {
330
- schemaId: this.completed.schema.uid,
331
- uid: this.completed.uid,
332
- },
333
- ], callback);
334
- return { tx, uids };
335
- }
336
- /**
337
- * Creates the payload for a multi-attestation.
338
- *
339
- * > if Current payload is set, it'll be used as the base payload
340
- * and the project should refer to an index of the current payload,
341
- * usually the community position.
342
- *
343
- * @param payload
344
- * @param grantIdx
345
- */
346
- async multiAttestPayload(currentPayload = [], grantIdx = 0) {
347
- this.assertPayload();
348
- const payload = [...currentPayload];
349
- const milestoneIdx = payload.push([this, await this.payloadFor(grantIdx)]) - 1;
350
- if (this.completed) {
351
- payload.push([
352
- this.completed,
353
- await this.completed.payloadFor(milestoneIdx),
354
- ]);
355
- }
356
- if (this.verified.length > 0) {
357
- await Promise.all(this.verified.map(async (m) => {
358
- const payloadForMilestone = await m.payloadFor(milestoneIdx);
359
- if (Array.isArray(payloadForMilestone)) {
360
- payloadForMilestone.forEach((item) => payload.push(item));
361
- }
362
- }));
363
- }
364
- return payload.slice(currentPayload.length, payload.length);
365
- }
366
- /**
367
- * Creates the payload for a multi-attestation across multiple grants.
368
- *
369
- * This method allows for the same milestone to be attested to multiple grants
370
- * in a single transaction.
371
- *
372
- * @param currentPayload - Current payload to append to
373
- * @param grantIndices - Array of grant indices to attest this milestone to
374
- * @returns The multi-attest payload with all grant attestations
375
- */
376
- async multiGrantAttestPayload(currentPayload = [], grantIndices = [0]) {
377
- this.assertPayload();
378
- const payload = [...currentPayload];
379
- const milestoneIndices = [];
380
- // Create milestone attestation for each grant
381
- for (const grantIdx of grantIndices) {
382
- const milestoneIdx = payload.push([this, await this.payloadFor(grantIdx)]) - 1;
383
- milestoneIndices.push(milestoneIdx);
384
- }
385
- // Add completed status if exists for each milestone
386
- if (this.completed) {
387
- for (const milestoneIdx of milestoneIndices) {
388
- payload.push([
389
- this.completed,
390
- await this.completed.payloadFor(milestoneIdx),
391
- ]);
392
- }
393
- }
394
- // Add verifications if exist for each milestone
395
- if (this.verified.length > 0) {
396
- for (const milestoneIdx of milestoneIndices) {
397
- await Promise.all(this.verified.map(async (m) => {
398
- const payloadForMilestone = await m.payloadFor(milestoneIdx);
399
- if (Array.isArray(payloadForMilestone)) {
400
- payloadForMilestone.forEach((item) => payload.push(item));
401
- }
402
- }));
403
- }
404
- }
405
- return payload.slice(currentPayload.length, payload.length);
406
- }
407
- /**
408
- * Attests this milestone to multiple grants in a single transaction.
409
- *
410
- * @param signer - The signer to use for attestation
411
- * @param grantIndices - Array of grant indices to attest this milestone to, or array of grant UIDs
412
- * @param callback - Optional callback function for status updates
413
- * @returns Promise with transaction and UIDs
414
- */
415
- async attestToMultipleGrants(signer, grantIndices = [0], callback) {
416
- this.assertPayload();
417
- // Check if we're dealing with Hex UIDs instead of indices
418
- const isUids = grantIndices.length > 0 && typeof grantIndices[0] === "string";
419
- if (isUids) {
420
- // Direct approach - create individual milestone instances for each grant UID
421
- const grantUIDs = grantIndices;
422
- const allPayloads = [];
423
- for (const grantUID of grantUIDs) {
424
- // Create a new milestone for each grant with direct reference
425
- const grantMilestone = new Milestone({
426
- schema: this.schema,
427
- recipient: this.recipient,
428
- data: this.data,
429
- refUID: grantUID,
430
- });
431
- // Generate payload for this grant
432
- const payload = await grantMilestone.multiAttestPayload();
433
- // Add each item from payload to allPayloads
434
- payload.forEach((item) => allPayloads.push(item));
435
- }
436
- // Attest all milestones in a single transaction
437
- const result = await GapContract_1.GapContract.multiAttest(signer, allPayloads.map((p) => p[1]), callback);
438
- return result;
439
- }
440
- else {
441
- // Original implementation using grantIndices
442
- const payload = await this.multiGrantAttestPayload([], grantIndices);
443
- const { uids, tx } = await GapContract_1.GapContract.multiAttest(signer, payload.map((p) => p[1]), callback);
444
- if (Array.isArray(uids)) {
445
- uids.forEach((uid, index) => {
446
- payload[index][0].uid = uid;
447
- });
448
- }
449
- return { tx, uids };
450
- }
451
- }
452
- /**
453
- * @inheritdoc
454
- */
455
- async attest(signer, callback) {
456
- this.assertPayload();
457
- const payload = await this.multiAttestPayload();
458
- const { uids, tx } = await GapContract_1.GapContract.multiAttest(signer, payload.map((p) => p[1]), callback);
459
- if (Array.isArray(uids)) {
460
- uids.forEach((uid, index) => {
461
- payload[index][0].uid = uid;
462
- });
463
- }
464
- console.log(uids);
465
- return { tx, uids };
466
- }
467
- /**
468
- * Attest the status of the milestone as approved, rejected or completed.
469
- */
470
- async attestStatus(signer, schema, callback) {
471
- const eas = this.schema.gap.eas.connect(signer);
472
- try {
473
- if (callback)
474
- callback("preparing");
475
- const tx = await eas.attest({
476
- schema: schema.uid,
477
- data: {
478
- recipient: this.recipient,
479
- data: schema.encode(),
480
- refUID: this.uid,
481
- expirationTime: 0n,
482
- revocable: schema.revocable,
483
- },
484
- });
485
- if (callback)
486
- callback("pending");
487
- const uid = await tx.wait();
488
- if (callback)
489
- callback("confirmed");
490
- console.log(uid);
491
- return {
492
- tx: [
493
- {
494
- hash: tx.tx.hash,
495
- },
496
- ],
497
- uids: [uid],
498
- };
499
- }
500
- catch (error) {
501
- console.error(error);
502
- throw new SchemaError_1.AttestationError("ATTEST_ERROR", error.message, error);
503
- }
504
- }
505
- static from(attestations, network) {
506
- return attestations.map((attestation) => {
507
- const milestone = new Milestone({
508
- ...attestation,
509
- data: {
510
- ...attestation.data,
511
- },
512
- schema: new AllGapSchemas_1.AllGapSchemas().findSchema("Milestone", consts_1.chainIdToNetwork[attestation.chainID]),
513
- chainID: attestation.chainID,
514
- });
515
- if (attestation.completed) {
516
- milestone.completed = new attestations_1.MilestoneCompleted({
517
- ...attestation.completed,
518
- data: {
519
- ...attestation.completed.data,
520
- },
521
- schema: new AllGapSchemas_1.AllGapSchemas().findSchema("MilestoneCompleted", consts_1.chainIdToNetwork[attestation.chainID]),
522
- chainID: attestation.chainID,
523
- });
524
- }
525
- if (attestation.approved) {
526
- milestone.approved = new attestations_1.MilestoneCompleted({
527
- ...attestation.approved,
528
- data: {
529
- ...attestation.completed.data,
530
- },
531
- schema: new AllGapSchemas_1.AllGapSchemas().findSchema("MilestoneCompleted", consts_1.chainIdToNetwork[attestation.chainID]),
532
- chainID: attestation.chainID,
533
- });
534
- }
535
- if (attestation.rejected) {
536
- milestone.rejected = new attestations_1.MilestoneCompleted({
537
- ...attestation.rejected,
538
- data: {
539
- ...attestation.completed.data,
540
- },
541
- schema: new AllGapSchemas_1.AllGapSchemas().findSchema("MilestoneCompleted", consts_1.chainIdToNetwork[attestation.chainID]),
542
- chainID: attestation.chainID,
543
- });
544
- }
545
- if (attestation.verified?.length > 0) {
546
- milestone.verified = attestation.verified.map((m) => new attestations_1.MilestoneCompleted({
547
- ...m,
548
- data: {
549
- ...m.data,
550
- },
551
- schema: new AllGapSchemas_1.AllGapSchemas().findSchema("MilestoneCompleted", consts_1.chainIdToNetwork[attestation.chainID]),
552
- chainID: attestation.chainID,
553
- }));
554
- }
555
- return milestone;
556
- });
557
- }
558
- /**
559
- * Verify this milestone. If the milestone is not completed or already verified,
560
- * it will throw an error.
561
- * @param signer
562
- * @param reason
563
- */
564
- async verify(signer, data, callback) {
565
- console.log("Verifying");
566
- if (!this.completed)
567
- throw new SchemaError_1.AttestationError("ATTEST_ERROR", "Milestone is not completed");
568
- const schema = this.schema.gap.findSchema("MilestoneCompleted");
569
- if (this.schema.isJsonSchema()) {
570
- schema.setValue("json", JSON.stringify({
571
- type: "verified",
572
- ...data,
573
- }));
574
- }
575
- else {
576
- schema.setValue("type", "verified");
577
- schema.setValue("reason", data?.reason || "");
578
- schema.setValue("proofOfWork", data?.proofOfWork || "");
579
- }
580
- console.log("Before attestStatus");
581
- const { tx, uids } = await this.attestStatus(signer, schema, callback);
582
- console.log("After attestStatus");
583
- this.verified.push(new attestations_1.MilestoneCompleted({
584
- data: {
585
- type: "verified",
586
- ...data,
587
- },
588
- refUID: this.uid,
589
- schema: schema,
590
- recipient: this.recipient,
591
- }));
592
- return { tx, uids };
593
- }
594
- /**
595
- * Verifies this milestone across multiple grants. If the milestones are not completed,
596
- * it will throw an error.
597
- * @param signer - The signer to use for attestation
598
- * @param milestoneUIDs - Array of milestone UIDs to verify
599
- * @param data - Optional verification data
600
- * @param callback - Optional callback function for status updates
601
- * @returns Promise with transaction and UIDs
602
- */
603
- async verifyMultipleGrants(signer, milestoneUIDs, data, callback) {
604
- // Validate that all milestones are completed
605
- if (!this.completed)
606
- throw new SchemaError_1.AttestationError("ATTEST_ERROR", "Milestone is not completed");
607
- const schema = this.schema.gap.findSchema("MilestoneCompleted");
608
- if (this.schema.isJsonSchema()) {
609
- schema.setValue("json", JSON.stringify({
610
- type: "verified",
611
- ...data,
612
- }));
613
- }
614
- else {
615
- schema.setValue("type", "verified");
616
- schema.setValue("reason", data?.reason || "");
617
- schema.setValue("proofOfWork", data?.proofOfWork || "");
618
- }
619
- // Create verification attestations for each milestone
620
- const verificationPayloads = [];
621
- for (const milestoneUID of milestoneUIDs) {
622
- const verified = new attestations_1.MilestoneCompleted({
623
- data: {
624
- type: "verified",
625
- ...data,
626
- },
627
- refUID: milestoneUID,
628
- schema,
629
- recipient: this.recipient,
630
- });
631
- // Add verification to the payload
632
- verificationPayloads.push([
633
- verified,
634
- await verified.payloadFor(0), // Index doesn't matter for verification
635
- ]);
636
- }
637
- // Attest all verifications at once
638
- const result = await GapContract_1.GapContract.multiAttest(signer, verificationPayloads.map((p) => p[1]), callback);
639
- // Save the verifications to this milestone instance
640
- if (result.uids.length > 0) {
641
- for (let i = 0; i < result.uids.length; i++) {
642
- this.verified.push(new attestations_1.MilestoneCompleted({
643
- data: {
644
- type: "verified",
645
- ...data,
646
- },
647
- refUID: milestoneUIDs[i],
648
- uid: result.uids[i],
649
- schema,
650
- recipient: this.recipient,
651
- }));
652
- }
653
- }
654
- return result;
655
- }
656
- }
657
- exports.Milestone = Milestone;