@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,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EASClient = void 0;
4
- const consts_1 = require("../../consts");
5
- const AxiosGQL_1 = require("./AxiosGQL");
6
- class EASClient extends AxiosGQL_1.AxiosGQL {
7
- constructor(args) {
8
- const { network } = args;
9
- super(consts_1.Networks[network].url);
10
- this.assert(args);
11
- this._network = { ...consts_1.Networks[network], name: network };
12
- }
13
- /**
14
- * Validate the constructor arguments
15
- * @param args
16
- */
17
- assert(args) {
18
- if (!consts_1.Networks[args.network]) {
19
- throw new Error("Invalid network");
20
- }
21
- }
22
- get network() {
23
- return this._network.name;
24
- }
25
- }
26
- exports.EASClient = EASClient;
@@ -1,71 +0,0 @@
1
- import { Attestation } from "../Attestation";
2
- import { EASNetworkConfig, Hex, IAttestation, TNetwork, TSchemaName } from "../../types";
3
- import { Grantee } from "../types/attestations";
4
- import { GapSchema } from "../GapSchema";
5
- import { Grant, Milestone, Project, MemberOf } from "../entities";
6
- import { Community } from "../entities/Community";
7
- import { Fetcher } from "../Fetcher";
8
- interface EASClientProps {
9
- network: TNetwork;
10
- }
11
- export declare class GapEasClient extends Fetcher {
12
- network: EASNetworkConfig & {
13
- name: TNetwork;
14
- };
15
- constructor(args: EASClientProps);
16
- /**
17
- * Fetches all the schemas deployed by an owner
18
- * @param owner
19
- */
20
- schemas(owner: Hex): Promise<GapSchema[]>;
21
- attestation<T = unknown>(uid: Hex): Promise<Attestation<T, GapSchema>>;
22
- attestations(schemaName: TSchemaName, search?: string): Promise<IAttestation[]>;
23
- attestationsOf(schemaName: TSchemaName, recipient: Hex): Promise<IAttestation[]>;
24
- attestationsTo(schemaName: TSchemaName, recipient: Hex): Promise<IAttestation[]>;
25
- /**
26
- * Fetch all dependent attestations of a parent schema.
27
- * @param parentSchema the schema name to get dependents of.
28
- * @param parentUid the parent uid to get dependents of.
29
- */
30
- dependentsOf(parentSchema: TSchemaName, parentUid: Hex): Promise<Attestation[]>;
31
- communities(search?: string): Promise<Community[]>;
32
- communitiesOf(address?: Hex): Promise<Community[]>;
33
- communitiesAdminOf(address?: Hex): Promise<Community[]>;
34
- communitiesByIds(uids: Hex[]): Promise<Community[]>;
35
- communitiesDetails(communities: Community[]): Promise<Community[]>;
36
- communityBySlug(slug: string): Promise<Community>;
37
- communityById(uid: Hex): Promise<Community>;
38
- /**
39
- * Fetch the details for a set of
40
- * projects with project grants,
41
- * members, milestones, and tags.
42
- * @param projects
43
- */
44
- projectsDetails(projects: Project[]): Promise<Project[]>;
45
- projectById(uid: Hex): Promise<Project>;
46
- projectBySlug(slug: string): Promise<Project>;
47
- slugExists(slug: string): Promise<boolean>;
48
- search(query: string): Promise<{
49
- projects: Project[];
50
- communities: Community[];
51
- }>;
52
- searchProjects(query: string): Promise<Project[]>;
53
- projects(name?: string): Promise<Project[]>;
54
- projectsOf(grantee: Hex): Promise<Project[]>;
55
- grantee(address: Hex): Promise<Grantee>;
56
- grantees(): Promise<Grantee[]>;
57
- grantsOf(grantee: Hex, withCommunity?: boolean): Promise<Grant[]>;
58
- grantsUpdates(grants: Grant[]): Promise<Grant[]>;
59
- grantsByCommunity(uid: Hex): Promise<Grant[]>;
60
- grantsFor(projects: Project[], withCommunity?: boolean): Promise<Grant[]>;
61
- milestonesOf(grants: Grant[]): Promise<Milestone[]>;
62
- membersOf(projects: Project[]): Promise<MemberOf[]>;
63
- /**
64
- * Returns a string to be used to search by a value in `decodedDataJson`.
65
- * @param field
66
- * @param value
67
- */
68
- private getSearchFieldString;
69
- grantsForExtProject(projectExtId: string): Promise<Grant[]>;
70
- }
71
- export {};
@@ -1,451 +0,0 @@
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;
@@ -1,19 +0,0 @@
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);