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

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/core/abi/AirdropNFT.json +1 -1
  2. package/core/abi/Allo.json +860 -860
  3. package/core/abi/AlloRegistry.json +578 -578
  4. package/core/abi/CommunityResolverABI.json +506 -506
  5. package/core/abi/Donations.json +251 -251
  6. package/core/abi/EAS.json +1 -1
  7. package/core/abi/MultiAttester.json +746 -746
  8. package/core/abi/ProjectResolver.json +574 -574
  9. package/core/abi/SchemaRegistry.json +1 -1
  10. package/core/abi/index.d.ts +1114 -0
  11. package/core/abi/index.js +26 -0
  12. package/core/class/AllGapSchemas.d.ts +9 -0
  13. package/core/class/AllGapSchemas.js +19 -0
  14. package/core/class/Attestation.d.ts +173 -0
  15. package/core/class/Attestation.js +333 -0
  16. package/core/class/Fetcher.d.ts +175 -0
  17. package/core/class/Fetcher.js +13 -0
  18. package/core/class/GAP.d.ts +254 -0
  19. package/core/class/GAP.js +289 -0
  20. package/core/class/GapSchema.d.ts +34 -0
  21. package/core/class/GapSchema.js +62 -0
  22. package/core/class/Gelato/{Gelato.ts → Gelato.js} +0 -23
  23. package/core/class/GrantProgramRegistry/Allo.d.ts +17 -0
  24. package/core/class/GrantProgramRegistry/Allo.js +137 -0
  25. package/core/class/GrantProgramRegistry/AlloRegistry.d.ts +15 -0
  26. package/core/class/GrantProgramRegistry/AlloRegistry.js +70 -0
  27. package/core/class/GraphQL/AxiosGQL.d.ts +6 -0
  28. package/core/class/GraphQL/AxiosGQL.js +25 -0
  29. package/core/class/GraphQL/EASClient.d.ts +16 -0
  30. package/core/class/GraphQL/EASClient.js +26 -0
  31. package/core/class/GraphQL/GapEasClient.d.ts +71 -0
  32. package/core/class/GraphQL/GapEasClient.js +451 -0
  33. package/core/class/GraphQL/index.js +19 -0
  34. package/core/class/Schema.d.ts +233 -0
  35. package/core/class/Schema.js +490 -0
  36. package/core/class/SchemaError.d.ts +30 -0
  37. package/core/class/SchemaError.js +39 -0
  38. package/core/class/contract/GapContract.d.ts +102 -0
  39. package/core/class/contract/GapContract.js +285 -0
  40. package/core/class/entities/Community.d.ts +34 -0
  41. package/core/class/entities/Community.js +109 -0
  42. package/core/class/entities/ContributorProfile.d.ts +41 -0
  43. package/core/class/entities/ContributorProfile.js +69 -0
  44. package/core/class/entities/Grant.d.ts +54 -0
  45. package/core/class/entities/Grant.js +223 -0
  46. package/core/class/entities/GrantUpdate.d.ts +62 -0
  47. package/core/class/entities/GrantUpdate.js +114 -0
  48. package/core/class/entities/MemberOf.d.ts +11 -0
  49. package/core/class/entities/MemberOf.js +33 -0
  50. package/core/class/entities/Milestone.d.ts +168 -0
  51. package/core/class/entities/Milestone.js +657 -0
  52. package/core/class/entities/Project.d.ts +92 -0
  53. package/core/class/entities/Project.js +418 -0
  54. package/core/class/entities/ProjectImpact.d.ts +50 -0
  55. package/core/class/entities/ProjectImpact.js +112 -0
  56. package/core/class/entities/ProjectMilestone.d.ts +60 -0
  57. package/core/class/entities/ProjectMilestone.js +174 -0
  58. package/core/class/entities/ProjectPointer.d.ts +12 -0
  59. package/core/class/entities/ProjectPointer.js +22 -0
  60. package/core/class/entities/ProjectUpdate.d.ts +50 -0
  61. package/core/class/entities/ProjectUpdate.js +110 -0
  62. package/core/class/entities/Track.d.ts +16 -0
  63. package/core/class/entities/Track.js +21 -0
  64. package/core/class/entities/index.js +26 -0
  65. package/core/class/index.js +26 -0
  66. package/core/class/karma-indexer/GapIndexerClient.d.ts +66 -0
  67. package/core/class/karma-indexer/GapIndexerClient.js +207 -0
  68. package/core/class/karma-indexer/api/GapIndexerApi.d.ts +73 -0
  69. package/core/class/karma-indexer/api/GapIndexerApi.js +256 -0
  70. package/core/class/karma-indexer/api/types.d.ts +309 -0
  71. package/core/class/karma-indexer/api/types.js +2 -0
  72. package/core/class/remote-storage/IpfsStorage.d.ts +23 -0
  73. package/core/class/remote-storage/IpfsStorage.js +56 -0
  74. package/core/class/remote-storage/RemoteStorage.d.ts +41 -0
  75. package/core/class/remote-storage/RemoteStorage.js +38 -0
  76. package/core/class/types/allo.d.ts +78 -0
  77. package/core/class/types/allo.js +2 -0
  78. package/core/class/types/attestations.d.ts +173 -0
  79. package/core/class/types/attestations.js +66 -0
  80. package/core/consts.d.ts +50 -0
  81. package/core/consts.js +699 -0
  82. package/core/index.js +24 -0
  83. package/core/shared/types.d.ts +13 -0
  84. package/core/shared/types.js +2 -0
  85. package/core/types.d.ts +131 -0
  86. package/core/types.js +13 -0
  87. package/core/utils/gelato/index.js +19 -0
  88. package/core/utils/gelato/send-gelato-txn.d.ts +55 -0
  89. package/core/utils/gelato/send-gelato-txn.js +100 -0
  90. package/core/utils/gelato/sponsor-handler.d.ts +9 -0
  91. package/core/utils/gelato/sponsor-handler.js +60 -0
  92. package/core/utils/gelato/watch-gelato-txn.d.ts +7 -0
  93. package/core/utils/gelato/watch-gelato-txn.js +63 -0
  94. package/core/utils/get-date.d.ts +1 -0
  95. package/core/utils/get-date.js +7 -0
  96. package/core/utils/get-ipfs-data.d.ts +1 -0
  97. package/core/utils/get-ipfs-data.js +20 -0
  98. package/core/utils/get-web3-provider.d.ts +2 -0
  99. package/core/utils/get-web3-provider.js +18 -0
  100. package/core/utils/gql-queries.d.ts +12 -0
  101. package/core/utils/gql-queries.js +90 -0
  102. package/core/utils/index.js +23 -0
  103. package/core/utils/map-filter.d.ts +8 -0
  104. package/core/utils/map-filter.js +20 -0
  105. package/core/utils/serialize-bigint.d.ts +1 -0
  106. package/core/utils/serialize-bigint.js +8 -0
  107. package/core/utils/to-unix.d.ts +1 -0
  108. package/core/utils/to-unix.js +25 -0
  109. package/index.js +17 -0
  110. package/package.json +45 -45
  111. package/.cursorrules +0 -43
  112. package/core/abi/index.ts +0 -21
  113. package/core/class/AllGapSchemas.ts +0 -21
  114. package/core/class/Attestation.ts +0 -429
  115. package/core/class/Fetcher.ts +0 -224
  116. package/core/class/GAP.ts +0 -481
  117. package/core/class/GapSchema.ts +0 -93
  118. package/core/class/GrantProgramRegistry/Allo.ts +0 -188
  119. package/core/class/GrantProgramRegistry/AlloRegistry.ts +0 -101
  120. package/core/class/GraphQL/AxiosGQL.ts +0 -29
  121. package/core/class/GraphQL/EASClient.ts +0 -34
  122. package/core/class/GraphQL/GapEasClient.ts +0 -869
  123. package/core/class/Schema.ts +0 -659
  124. package/core/class/SchemaError.ts +0 -42
  125. package/core/class/contract/GapContract.ts +0 -457
  126. package/core/class/entities/Community.ts +0 -148
  127. package/core/class/entities/ContributorProfile.ts +0 -108
  128. package/core/class/entities/Grant.ts +0 -321
  129. package/core/class/entities/GrantUpdate.ts +0 -187
  130. package/core/class/entities/MemberOf.ts +0 -52
  131. package/core/class/entities/Milestone.ts +0 -898
  132. package/core/class/entities/Project.ts +0 -672
  133. package/core/class/entities/ProjectImpact.ts +0 -170
  134. package/core/class/entities/ProjectMilestone.ts +0 -254
  135. package/core/class/entities/ProjectPointer.ts +0 -39
  136. package/core/class/entities/ProjectUpdate.ts +0 -176
  137. package/core/class/entities/Track.ts +0 -32
  138. package/core/class/karma-indexer/GapIndexerClient.ts +0 -383
  139. package/core/class/karma-indexer/api/GapIndexerApi.ts +0 -446
  140. package/core/class/karma-indexer/api/types.ts +0 -313
  141. package/core/class/remote-storage/IpfsStorage.ts +0 -76
  142. package/core/class/remote-storage/RemoteStorage.ts +0 -65
  143. package/core/class/types/allo.ts +0 -93
  144. package/core/class/types/attestations.ts +0 -223
  145. package/core/consts.ts +0 -775
  146. package/core/scripts/create-grant.ts +0 -102
  147. package/core/scripts/create-program.ts +0 -43
  148. package/core/scripts/create-schemas.ts +0 -65
  149. package/core/scripts/deploy.ts +0 -65
  150. package/core/scripts/index.ts +0 -1
  151. package/core/scripts/milestone-multi-grants.ts +0 -125
  152. package/core/shared/types.ts +0 -13
  153. package/core/types.ts +0 -224
  154. package/core/utils/gelato/send-gelato-txn.ts +0 -114
  155. package/core/utils/gelato/sponsor-handler.ts +0 -77
  156. package/core/utils/gelato/watch-gelato-txn.ts +0 -67
  157. package/core/utils/get-date.ts +0 -3
  158. package/core/utils/get-ipfs-data.ts +0 -13
  159. package/core/utils/get-web3-provider.ts +0 -18
  160. package/core/utils/gql-queries.ts +0 -133
  161. package/core/utils/map-filter.ts +0 -21
  162. package/core/utils/serialize-bigint.ts +0 -7
  163. package/core/utils/to-unix.ts +0 -18
  164. package/create-community-example.ts +0 -119
  165. package/csv-upload/README.md +0 -74
  166. package/csv-upload/config.ts +0 -41
  167. package/csv-upload/example.csv +0 -2
  168. package/csv-upload/keys.example.json +0 -8
  169. package/csv-upload/scripts/run.ts +0 -417
  170. package/csv-upload/types.ts +0 -39
  171. package/docs/.gitkeep +0 -0
  172. package/docs/images/attestation-architecture.png +0 -0
  173. package/docs/images/dfd-get-projects.png +0 -0
  174. package/gap-schema.yaml +0 -155
  175. package/milestone-workflow-example.ts +0 -353
  176. package/readme.md +0 -872
  177. package/schemas/.gitkeep +0 -0
  178. package/schemas/GAP-schemas-1692135812877.json +0 -33
  179. package/test-file-indexer-api.ts +0 -25
  180. package/tsconfig.json +0 -26
  181. /package/{csv-upload/.gitkeep → core/class/Gelato/Gelato.d.ts} +0 -0
  182. /package/core/class/GraphQL/{index.ts → index.d.ts} +0 -0
  183. /package/core/class/entities/{index.ts → index.d.ts} +0 -0
  184. /package/core/class/{index.ts → index.d.ts} +0 -0
  185. /package/core/{index.ts → index.d.ts} +0 -0
  186. /package/core/utils/gelato/{index.ts → index.d.ts} +0 -0
  187. /package/core/utils/{index.ts → index.d.ts} +0 -0
  188. /package/{index.ts → index.d.ts} +0 -0
@@ -0,0 +1,451 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GapEasClient = void 0;
4
+ const Attestation_1 = require("../Attestation");
5
+ const gql_queries_1 = require("../../utils/gql-queries");
6
+ const to_unix_1 = require("../../utils/to-unix");
7
+ const attestations_1 = require("../types/attestations");
8
+ const GapSchema_1 = require("../GapSchema");
9
+ const Schema_1 = require("../Schema");
10
+ const SchemaError_1 = require("../SchemaError");
11
+ const entities_1 = require("../entities");
12
+ const Community_1 = require("../entities/Community");
13
+ const utils_1 = require("../../utils");
14
+ const Fetcher_1 = require("../Fetcher");
15
+ const consts_1 = require("../../consts");
16
+ // TODO: Split this class into small ones
17
+ class GapEasClient extends Fetcher_1.Fetcher {
18
+ constructor(args) {
19
+ const { network } = args;
20
+ super(consts_1.Networks[network].url);
21
+ this.network = { ...consts_1.Networks[network], name: network };
22
+ }
23
+ /**
24
+ * Fetches all the schemas deployed by an owner
25
+ * @param owner
26
+ */
27
+ async schemas(owner) {
28
+ const query = gql_queries_1.gqlQueries.schemata(owner);
29
+ const { schemata } = await this.query(query);
30
+ return schemata.map((schema) => new GapSchema_1.GapSchema({
31
+ name: "",
32
+ schema: Schema_1.Schema.rawToObject(schema.schema),
33
+ uid: schema.uid,
34
+ }, this.gap));
35
+ }
36
+ async attestation(uid) {
37
+ const query = gql_queries_1.gqlQueries.attestation(uid);
38
+ const { attestation } = await this.query(query);
39
+ return Attestation_1.Attestation.fromInterface([attestation], this.network.name)[0];
40
+ }
41
+ async attestations(schemaName, search) {
42
+ const schema = this.gap.findSchema(schemaName);
43
+ const query = gql_queries_1.gqlQueries.attestationsOf(schema.uid, search);
44
+ const { schema: { attestations }, } = await this.query(query);
45
+ return attestations;
46
+ }
47
+ async attestationsOf(schemaName, recipient) {
48
+ const schema = this.gap.findSchema(schemaName);
49
+ const query = gql_queries_1.gqlQueries.attestationsOf(schema.uid, recipient);
50
+ const { schema: { attestations }, } = await this.query(query);
51
+ return attestations;
52
+ }
53
+ async attestationsTo(schemaName, recipient) {
54
+ const schema = this.gap.findSchema(schemaName);
55
+ const query = gql_queries_1.gqlQueries.attestationsTo(schema.uid, recipient);
56
+ const { schema: { attestations }, } = await this.query(query);
57
+ return attestations;
58
+ }
59
+ /**
60
+ * Fetch all dependent attestations of a parent schema.
61
+ * @param parentSchema the schema name to get dependents of.
62
+ * @param parentUid the parent uid to get dependents of.
63
+ */
64
+ async dependentsOf(parentSchema, parentUid) {
65
+ const parent = this.gap.findSchema(parentSchema);
66
+ const children = parent.children.map((c) => c.uid);
67
+ if (!children.length)
68
+ throw new SchemaError_1.SchemaError("INVALID_REFERENCE", `Schema ${parentSchema} has no children.`);
69
+ const query = gql_queries_1.gqlQueries.dependentsOf(parentUid, children);
70
+ const { attestations } = await this.query(query);
71
+ return Attestation_1.Attestation.fromInterface(attestations, this.network.name);
72
+ }
73
+ async communities(search) {
74
+ const [community, communityDetails] = this.gap.findManySchemas([
75
+ "Community",
76
+ "CommunityDetails",
77
+ ]);
78
+ const query = gql_queries_1.gqlQueries.attestationsOf(community.uid, search);
79
+ const { schema: { attestations }, } = await this.query(query);
80
+ const communities = Attestation_1.Attestation.fromInterface(attestations, this.network.name);
81
+ if (!communities.length)
82
+ return [];
83
+ return this.communitiesDetails(communities);
84
+ }
85
+ async communitiesOf(address) {
86
+ const [community] = this.gap.findManySchemas(["Community"]);
87
+ const query = gql_queries_1.gqlQueries.attestationsTo(community.uid, address);
88
+ const { schema: { attestations }, } = await this.query(query);
89
+ const communities = Attestation_1.Attestation.fromInterface(attestations, this.network.name);
90
+ if (!communities.length)
91
+ return [];
92
+ return this.communitiesDetails(communities);
93
+ }
94
+ async communitiesAdminOf(address) {
95
+ const [community] = this.gap.findManySchemas(["Community"]);
96
+ const query = gql_queries_1.gqlQueries.attestationsTo(community.uid, address);
97
+ const { schema: { attestations }, } = await this.query(query);
98
+ const communities = Attestation_1.Attestation.fromInterface(attestations, this.network.name);
99
+ if (!communities.length)
100
+ return [];
101
+ return this.communitiesDetails(communities);
102
+ }
103
+ async communitiesByIds(uids) {
104
+ if (!uids.length)
105
+ return [];
106
+ const communityDetails = this.gap.findSchema("CommunityDetails");
107
+ const communityQuery = gql_queries_1.gqlQueries.attestationsIn(uids);
108
+ const detailsQuery = gql_queries_1.gqlQueries.dependentsOf(uids, [communityDetails.uid]);
109
+ try {
110
+ const [communities, details] = await Promise.all([
111
+ this.query(communityQuery),
112
+ this.query(detailsQuery),
113
+ ]);
114
+ const communitiesAttestations = Attestation_1.Attestation.fromInterface(communities.attestations || [], this.network.name);
115
+ const detailsAttestations = Attestation_1.Attestation.fromInterface(details.attestations || [], this.network.name);
116
+ communitiesAttestations.forEach((community) => {
117
+ community.details = detailsAttestations.find((d) => d.refUID === community.uid);
118
+ });
119
+ return communitiesAttestations;
120
+ }
121
+ catch (error) {
122
+ throw error;
123
+ }
124
+ }
125
+ async communitiesDetails(communities) {
126
+ const [project, communityDetails] = this.gap.findManySchemas([
127
+ "Project",
128
+ "CommunityDetails",
129
+ ]);
130
+ const ref = gql_queries_1.gqlQueries.dependentsOf(communities.map((c) => c.uid), [communityDetails.uid]);
131
+ const results = await this.query(ref);
132
+ const deps = Attestation_1.Attestation.fromInterface(results.attestations || [], this.network.name);
133
+ return communities.map((community) => {
134
+ community.projects = (deps.filter((ref) => ref.schema.uid === project.uid && ref.refUID === community.uid));
135
+ community.details = (deps.find((ref) => ref.schema.uid === communityDetails.uid &&
136
+ ref.refUID === community.uid));
137
+ return community;
138
+ });
139
+ }
140
+ async communityBySlug(slug) {
141
+ const communitySchema = this.gap.findSchema("CommunityDetails");
142
+ const query = gql_queries_1.gqlQueries.attestationsOf(communitySchema.uid, this.getSearchFieldString("slug", slug));
143
+ try {
144
+ const { schema: { attestations }, } = await this.query(query);
145
+ if (!attestations.length)
146
+ throw new Error("Community not found.");
147
+ const communities = (0, utils_1.mapFilter)(Attestation_1.Attestation.fromInterface(attestations, this.network.name), (details) => !!details.name, (details) => {
148
+ const community = new Community_1.Community({
149
+ data: { community: true },
150
+ uid: details.refUID,
151
+ schema: communitySchema,
152
+ recipient: details.recipient,
153
+ });
154
+ community.details = details;
155
+ return community;
156
+ });
157
+ const [withDetails] = await this.communitiesDetails(communities);
158
+ if (!withDetails)
159
+ throw new Error("Community not found.");
160
+ const grants = await this.grantsByCommunity(withDetails.uid);
161
+ withDetails.grants = grants;
162
+ return withDetails;
163
+ }
164
+ catch (error) {
165
+ throw error;
166
+ }
167
+ }
168
+ async communityById(uid) {
169
+ const query = gql_queries_1.gqlQueries.attestation(uid);
170
+ const { attestation } = await this.query(query);
171
+ if (!attestation)
172
+ throw new Error("Community not found.");
173
+ const communities = Attestation_1.Attestation.fromInterface([attestation], this.network.name).map((c) => new Community_1.Community(c));
174
+ const [withDetails] = await this.communitiesDetails(communities);
175
+ if (!withDetails)
176
+ throw new Error("Community not found.");
177
+ const grants = await this.grantsByCommunity(uid);
178
+ withDetails.grants = grants;
179
+ return withDetails;
180
+ }
181
+ /**
182
+ * Fetch the details for a set of
183
+ * projects with project grants,
184
+ * members, milestones, and tags.
185
+ * @param projects
186
+ */
187
+ async projectsDetails(projects) {
188
+ // Get projects array and fetch details, members, grants, etc then append to the project and return the array.
189
+ const [projectDetails] = this.gap.findManySchemas(["ProjectDetails"]);
190
+ const refQuery = gql_queries_1.gqlQueries.dependentsOf(projects.map((p) => p.uid), [projectDetails.uid]);
191
+ const [result, members, grants] = await Promise.all([
192
+ this.query(refQuery),
193
+ this.membersOf(projects),
194
+ this.grantsFor(projects, true),
195
+ ]);
196
+ const deps = Attestation_1.Attestation.fromInterface(result.attestations || [], this.network.name);
197
+ return projects.map((project) => {
198
+ project.details = (deps.find((ref) => ref.schema.uid === projectDetails.uid && ref.refUID === project.uid));
199
+ project.members = members.filter((m) => m.refUID === project.uid);
200
+ project.grants = grants.filter((g) => g.refUID === project.uid);
201
+ return project;
202
+ });
203
+ }
204
+ async projectById(uid) {
205
+ const query = gql_queries_1.gqlQueries.attestation(uid);
206
+ const { attestation } = await this.query(query);
207
+ if (!attestation)
208
+ throw new Error("Project not found.");
209
+ const projectAttestation = Attestation_1.Attestation.fromInterface([attestation], this.network.name)[0];
210
+ const [result] = await this.projectsDetails([
211
+ new entities_1.Project(projectAttestation),
212
+ ]);
213
+ return result;
214
+ }
215
+ async projectBySlug(slug) {
216
+ const projectDetails = this.gap.findSchema("ProjectDetails");
217
+ const query = gql_queries_1.gqlQueries.attestationsOf(projectDetails.uid, this.getSearchFieldString("slug", slug));
218
+ const { schema: { attestations }, } = await this.query(query);
219
+ const projectAttestations = Attestation_1.Attestation.fromInterface(attestations, this.network.name).filter((p) => p.title);
220
+ if (!projectAttestations.length)
221
+ throw new Error("Project not found.");
222
+ const project = new entities_1.Project({
223
+ data: { project: true },
224
+ uid: projectAttestations[0].refUID,
225
+ schema: this.gap.findSchema("Project"),
226
+ recipient: projectAttestations[0].recipient,
227
+ });
228
+ const [withDetails] = await this.projectsDetails([project]);
229
+ if (!withDetails)
230
+ throw new Error("Project not found.");
231
+ return withDetails;
232
+ }
233
+ async slugExists(slug) {
234
+ const details = this.gap.findSchema("ProjectDetails");
235
+ const query = gql_queries_1.gqlQueries.attestationsOf(details.uid, "slug");
236
+ const { schema: { attestations }, } = await this.query(query);
237
+ return attestations.some((a) => a.decodedDataJson.includes(slug));
238
+ }
239
+ search(query) {
240
+ throw new Error("Method not implemented.");
241
+ }
242
+ searchProjects(query) {
243
+ throw new Error("Method not implemented.");
244
+ }
245
+ async projects(name) {
246
+ const result = await this.attestations("Project", name);
247
+ if (!result.length)
248
+ return [];
249
+ const projects = Attestation_1.Attestation.fromInterface(result, this.network.name);
250
+ return this.projectsDetails(projects);
251
+ }
252
+ async projectsOf(grantee) {
253
+ const result = await this.attestationsTo("Project", grantee);
254
+ if (!result.length)
255
+ return [];
256
+ const projects = Attestation_1.Attestation.fromInterface(result, this.network.name);
257
+ return this.projectsDetails(projects);
258
+ }
259
+ async grantee(address) {
260
+ const projects = await this.projectsOf(address);
261
+ return new attestations_1.Grantee(address, projects);
262
+ }
263
+ async grantees() {
264
+ const projects = await this.projects();
265
+ return projects.reduce((acc, item) => {
266
+ const hasGrantee = acc.find((g) => g.address === item.recipient);
267
+ if (hasGrantee)
268
+ hasGrantee.projects.push(item);
269
+ else
270
+ acc.push(new attestations_1.Grantee(item.recipient, [item]));
271
+ return acc;
272
+ }, []);
273
+ }
274
+ async grantsOf(grantee, withCommunity) {
275
+ const [grant, grantDetails, grantVerified] = this.gap.findManySchemas([
276
+ "Grant",
277
+ "GrantDetails",
278
+ "GrantVerified",
279
+ ]);
280
+ const query = gql_queries_1.gqlQueries.attestationsTo(grant.uid, grantee);
281
+ const { schema: { attestations }, } = await this.query(query);
282
+ const grants = Attestation_1.Attestation.fromInterface(attestations, this.network.name);
283
+ if (!grants.length)
284
+ return [];
285
+ const ref = gql_queries_1.gqlQueries.dependentsOf(grants.map((g) => g.uid), [grantDetails.uid, grantVerified.uid], grants.map((g) => g.recipient));
286
+ const results = await this.query(ref);
287
+ const deps = Attestation_1.Attestation.fromInterface(results.attestations || [], this.network.name);
288
+ const milestones = await this.milestonesOf(grants);
289
+ const communities = withCommunity
290
+ ? await this.communitiesByIds((0, utils_1.mapFilter)(grants, (g) => !!g.communityUID, (g) => g.communityUID))
291
+ : [];
292
+ const withDetails = grants.map((grant) => {
293
+ const refs = deps.filter((ref) => ref.refUID === grant.uid);
294
+ grant.verified = !!refs.find((ref) => ref.schema.uid === grantVerified.uid && ref.refUID === grant.uid);
295
+ grant.details = (refs.find((ref) => ref.schema.uid === grantDetails.uid &&
296
+ ref.refUID === grant.uid &&
297
+ typeof ref.endsAt === "undefined"));
298
+ grant.milestones = milestones.filter((m) => m.refUID === grant.uid && typeof m.endsAt !== "undefined");
299
+ grant.community = communities.find((c) => c.uid === grant.communityUID);
300
+ return grant;
301
+ });
302
+ return this.grantsUpdates(withDetails);
303
+ }
304
+ async grantsUpdates(grants) {
305
+ const details = this.gap.findSchema("GrantDetails");
306
+ const query = gql_queries_1.gqlQueries.attestationsOf(details.uid, this.getSearchFieldString("type", "grant-update"), grants.map((g) => g.uid));
307
+ const { schema: { attestations }, } = await this.query(query);
308
+ const updates = Attestation_1.Attestation.fromInterface(attestations, this.network.name);
309
+ return grants.map((grant) => {
310
+ grant.updates = updates.filter((u) => u.refUID === grant.uid);
311
+ return grant;
312
+ });
313
+ }
314
+ async grantsByCommunity(uid) {
315
+ const [grant, grantDetails, project, projectDetails] = this.gap.findManySchemas([
316
+ "Grant",
317
+ "GrantDetails",
318
+ "Project",
319
+ "ProjectDetails",
320
+ ]);
321
+ const query = gql_queries_1.gqlQueries.attestations(grant.uid, uid);
322
+ const { schema: { attestations }, } = await this.query(query);
323
+ const grants = Attestation_1.Attestation.fromInterface(attestations, this.network.name).map((g) => new entities_1.Grant(g));
324
+ if (!grants.length)
325
+ return [];
326
+ const refs = gql_queries_1.gqlQueries.dependentsOf(grants.map((g) => [g.uid, g.refUID]).flat(), [grantDetails.uid, project.uid]);
327
+ const results = await this.query(refs);
328
+ const deps = Attestation_1.Attestation.fromInterface(results.attestations || [], this.network.name);
329
+ const projectsQuery = gql_queries_1.gqlQueries.attestationsIn(grants.map((g) => g.refUID));
330
+ const { attestations: projectAttestations } = await this.query(projectsQuery);
331
+ const projects = Attestation_1.Attestation.fromInterface(projectAttestations, this.network.name);
332
+ const milestones = await this.milestonesOf(grants);
333
+ const getSummaryProject = (project) => ({
334
+ title: project.details?.title,
335
+ uid: project.uid,
336
+ slug: project.details?.slug,
337
+ });
338
+ return grants
339
+ .map((grant) => {
340
+ grant.project = getSummaryProject(projects.find((p) => p.uid === grant.refUID));
341
+ grant.details = (deps.find((d) => d.refUID === grant.uid &&
342
+ d.schema.uid === grantDetails.uid &&
343
+ typeof d.amount !== undefined &&
344
+ typeof d.endsAt === "undefined" &&
345
+ typeof d.data.type === "undefined"));
346
+ grant.milestones = milestones
347
+ .filter((m) => m.refUID === grant.uid && typeof m.endsAt !== "undefined")
348
+ .sort((a, b) => a.endsAt - b.endsAt);
349
+ grant.updates = deps.filter((d) => d.data.type && d.refUID === grant.uid);
350
+ return grant;
351
+ })
352
+ .filter((g) => !!g.project);
353
+ }
354
+ async grantsFor(projects, withCommunity) {
355
+ const [grant, grantDetails] = this.gap.findManySchemas([
356
+ "Grant",
357
+ "GrantDetails",
358
+ "Milestone",
359
+ "MilestoneApproved",
360
+ "MilestoneCompleted",
361
+ ]);
362
+ const query = gql_queries_1.gqlQueries.dependentsOf(projects.map((p) => p.uid), [grant.uid]);
363
+ const { attestations: grants } = await this.query(query);
364
+ const grantsWithDetails = Attestation_1.Attestation.fromInterface(grants, this.network.name).map((g) => new entities_1.Grant(g));
365
+ const ref = gql_queries_1.gqlQueries.dependentsOf(grants.map((g) => g.uid), [grantDetails.uid]);
366
+ const { attestations } = await this.query(ref);
367
+ const milestones = await this.milestonesOf(grantsWithDetails);
368
+ const deps = Attestation_1.Attestation.fromInterface(attestations, this.network.name);
369
+ // TODO unify this with grantsOf
370
+ grantsWithDetails.forEach((grant) => {
371
+ grant.details = (deps.find((d) => d.refUID === grant.uid &&
372
+ d.schema.uid === grantDetails.uid &&
373
+ typeof d.amount !== undefined &&
374
+ typeof d.endsAt === "undefined" &&
375
+ typeof d.data.type === "undefined"));
376
+ grant.milestones = milestones
377
+ .filter((m) => m.refUID === grant.uid && typeof m.endsAt !== "undefined")
378
+ .sort((a, b) => a.endsAt - b.endsAt);
379
+ });
380
+ const communities = withCommunity
381
+ ? await this.communitiesByIds((0, utils_1.mapFilter)(grantsWithDetails, (g) => !!g.communityUID, (g) => g.communityUID))
382
+ : [];
383
+ grantsWithDetails.forEach((grant) => {
384
+ grant.community = communities.find((c) => c.uid === grant.communityUID);
385
+ });
386
+ const grantsWithUpdates = await this.grantsUpdates(grantsWithDetails);
387
+ return grantsWithUpdates.sort((a, b) => a.milestones?.at(-1)?.endsAt - b.milestones?.at(-1)?.endsAt ||
388
+ a.createdAt.getTime() - b.createdAt.getTime());
389
+ }
390
+ async milestonesOf(grants) {
391
+ const [milestone, milestoneApproved, milestoneCompleted] = this.gap.findManySchemas([
392
+ "Milestone",
393
+ "MilestoneApproved",
394
+ "MilestoneCompleted",
395
+ ]);
396
+ const query = gql_queries_1.gqlQueries.dependentsOf(grants.map((g) => g.uid), [milestone.uid]);
397
+ const { attestations } = await this.query(query);
398
+ const milestones = Attestation_1.Attestation.fromInterface(attestations, this.network.name)
399
+ .map((milestone) => new entities_1.Milestone(milestone))
400
+ .filter((m) => typeof m.endsAt !== "undefined");
401
+ if (!milestones.length)
402
+ return [];
403
+ const ref = gql_queries_1.gqlQueries.dependentsOf(milestones.map((m) => m.uid), [milestoneApproved.uid, milestoneCompleted.uid]);
404
+ const results = await this.query(ref);
405
+ const deps = Attestation_1.Attestation.fromInterface(results.attestations || [], this.network.name);
406
+ return milestones.map((milestone) => {
407
+ const refs = deps.filter((ref) => ref.refUID === milestone.uid);
408
+ milestone.endsAt = (0, to_unix_1.toUnix)(milestone.endsAt);
409
+ milestone.completed = refs.find((dep) => dep.type === "completed" && dep.refUID === milestone.uid);
410
+ milestone.approved = refs.find((dep) => dep.type === "approved" && dep.refUID === milestone.uid);
411
+ milestone.rejected = refs.find((dep) => dep.type === "rejected" && dep.refUID === milestone.uid);
412
+ return milestone;
413
+ });
414
+ }
415
+ async membersOf(projects) {
416
+ const [member, memberDetails] = this.gap.findManySchemas([
417
+ "MemberOf",
418
+ "MemberDetails",
419
+ ]);
420
+ if (!projects.length)
421
+ return [];
422
+ const query = gql_queries_1.gqlQueries.dependentsOf(projects.map((p) => p.uid), [member.uid], projects.map((p) => p.attester));
423
+ const results = await this.query(query);
424
+ const members = Attestation_1.Attestation.fromInterface(results.attestations || [], this.network.name);
425
+ if (members.length) {
426
+ const ref = gql_queries_1.gqlQueries.dependentsOf(members.map((a) => a.uid), [memberDetails.uid], members.map((a) => a.attester));
427
+ const detailsResult = await this.query(ref);
428
+ const detailsRef = Attestation_1.Attestation.fromInterface(detailsResult.attestations || [], this.network.name);
429
+ members.forEach((member) => {
430
+ member.details = detailsRef.find((d) => d.refUID === member.uid);
431
+ });
432
+ }
433
+ return members;
434
+ }
435
+ /**
436
+ * Returns a string to be used to search by a value in `decodedDataJson`.
437
+ * @param field
438
+ * @param value
439
+ */
440
+ getSearchFieldString(field, value) {
441
+ return [
442
+ String.raw `\\\\\"${field}\\\\\":\\\\\"${value}\\\\\"`,
443
+ String.raw `\\\\\"${field}\\\\\": \\\\\"${value}\\\\\"`,
444
+ ];
445
+ }
446
+ async grantsForExtProject(projectExtId) {
447
+ console.error(new Error("Grants for external project is only supported by a custom indexer. Check https://github.com/show-karma/karma-gap-sdk for more information."));
448
+ return [];
449
+ }
450
+ }
451
+ exports.GapEasClient = GapEasClient;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./AxiosGQL"), exports);
18
+ __exportStar(require("./EASClient"), exports);
19
+ __exportStar(require("./GapEasClient"), exports);