@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,92 @@
1
+ import { Hex, MultiAttestPayload, SignerOrProvider, TNetwork } from "core/types";
2
+ import { Attestation } from "../Attestation";
3
+ import { IProjectResponse } from "../karma-indexer/api/types";
4
+ import { AttestationWithTx, Grantee, MemberDetails, ProjectDetails, ProjectEndorsement } from "../types/attestations";
5
+ import { Grant } from "./Grant";
6
+ import { MemberOf } from "./MemberOf";
7
+ import { IProjectImpact, ProjectImpact } from "./ProjectImpact";
8
+ import { ProjectMilestone } from "./ProjectMilestone";
9
+ import { ProjectPointer } from "./ProjectPointer";
10
+ import { ProjectUpdate } from "./ProjectUpdate";
11
+ export interface IProject {
12
+ project: true;
13
+ }
14
+ export declare class Project extends Attestation<IProject> {
15
+ details?: ProjectDetails;
16
+ members: MemberOf[];
17
+ grants: Grant[];
18
+ grantee: Grantee;
19
+ impacts: ProjectImpact[];
20
+ endorsements: ProjectEndorsement[];
21
+ updates: ProjectUpdate[];
22
+ pointers: ProjectPointer[];
23
+ milestones: ProjectMilestone[];
24
+ /**
25
+ * Creates the payload for a multi-attestation.
26
+ *
27
+ * > if Current payload is set, it'll be used as the base payload
28
+ * and the project should refer to an index of the current payload,
29
+ * usually the community position.
30
+ *
31
+ * @param payload
32
+ * @param communityIdx
33
+ */
34
+ multiAttestPayload(currentPayload?: MultiAttestPayload, communityIdx?: number): Promise<MultiAttestPayload>;
35
+ attest(signer: SignerOrProvider, callback?: Function): Promise<AttestationWithTx>;
36
+ transferOwnership(signer: SignerOrProvider, newOwner: Hex, callback?: Function): Promise<AttestationWithTx>;
37
+ isOwner(signer: SignerOrProvider, publicAddress?: string): Promise<boolean>;
38
+ isAdmin(signer: SignerOrProvider, publicAddress?: string): Promise<boolean>;
39
+ /**
40
+ * Add new members to the project.
41
+ * If any member in the array already exists in the project
42
+ * it'll be ignored.
43
+ * @param members
44
+ */
45
+ pushMembers(...members: Hex[]): void;
46
+ /**
47
+ * Add new members to the project.
48
+ * If any member in the array already exists in the project
49
+ * it'll be ignored.
50
+ *
51
+ * __To modify member details, use `addMemberDetails(signer, MemberDetails[])` instead.__
52
+ * @param signer
53
+ * @param members
54
+ */
55
+ attestMembers(signer: SignerOrProvider, members: MemberDetails[], callback?: Function): Promise<void>;
56
+ /**
57
+ * Add new details to the members of a project. Note that it will overwrite
58
+ * any existing details.
59
+ *
60
+ * @param signer
61
+ * @param entities
62
+ */
63
+ private addMemberDetails;
64
+ /**
65
+ * Clean member details.
66
+ * @param signer
67
+ * @param uids
68
+ */
69
+ cleanDetails(signer: SignerOrProvider, uids: Hex[]): Promise<void>;
70
+ /**
71
+ * Remove members from the project.
72
+ * @param signer
73
+ * @param uids
74
+ * @returns
75
+ */
76
+ removeMembers(signer: SignerOrProvider, uids: Hex[]): Promise<void>;
77
+ /**
78
+ * Remove all members from the project.
79
+ * @param signer
80
+ */
81
+ removeAllMembers(signer: SignerOrProvider): Promise<void>;
82
+ static from(attestations: IProjectResponse[], network: TNetwork): Project[];
83
+ attestUpdate(signer: SignerOrProvider, data: ProjectUpdate, callback?: Function): Promise<void>;
84
+ attestMilestone(signer: SignerOrProvider, data: ProjectUpdate, callback?: Function): Promise<void>;
85
+ attestPointer(signer: SignerOrProvider, data: ProjectPointer, callback?: Function): Promise<void>;
86
+ attestImpact(signer: SignerOrProvider, data: IProjectImpact, targetChainId?: number, callback?: Function): Promise<AttestationWithTx>;
87
+ private attestGhostProjectImpact;
88
+ attestEndorsement(signer: SignerOrProvider, data?: ProjectEndorsement): Promise<void>;
89
+ attestGhostProject(signer: SignerOrProvider, targetChainId: number): Promise<AttestationWithTx>;
90
+ addAdmin(signer: SignerOrProvider, newAdmin: Hex, callback?: Function): Promise<AttestationWithTx>;
91
+ removeAdmin(signer: SignerOrProvider, oldAdmin: Hex, callback?: Function): Promise<AttestationWithTx>;
92
+ }
@@ -0,0 +1,418 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Project = void 0;
4
+ const consts_1 = require("../../consts");
5
+ const utils_1 = require("../../utils");
6
+ const AllGapSchemas_1 = require("../AllGapSchemas");
7
+ const Attestation_1 = require("../Attestation");
8
+ const GapContract_1 = require("../contract/GapContract");
9
+ const SchemaError_1 = require("../SchemaError");
10
+ const attestations_1 = require("../types/attestations");
11
+ const Grant_1 = require("./Grant");
12
+ const MemberOf_1 = require("./MemberOf");
13
+ const ProjectImpact_1 = require("./ProjectImpact");
14
+ const ProjectMilestone_1 = require("./ProjectMilestone");
15
+ const ProjectPointer_1 = require("./ProjectPointer");
16
+ const ProjectUpdate_1 = require("./ProjectUpdate");
17
+ class Project extends Attestation_1.Attestation {
18
+ constructor() {
19
+ super(...arguments);
20
+ this.members = [];
21
+ this.grants = [];
22
+ this.impacts = [];
23
+ this.endorsements = [];
24
+ this.updates = [];
25
+ this.pointers = [];
26
+ this.milestones = [];
27
+ }
28
+ /**
29
+ * Creates the payload for a multi-attestation.
30
+ *
31
+ * > if Current payload is set, it'll be used as the base payload
32
+ * and the project should refer to an index of the current payload,
33
+ * usually the community position.
34
+ *
35
+ * @param payload
36
+ * @param communityIdx
37
+ */
38
+ async multiAttestPayload(currentPayload = [], communityIdx = 0) {
39
+ const payload = [...currentPayload];
40
+ const projectIdx = payload.push([this, await this.payloadFor(communityIdx)]) - 1;
41
+ if (this.details) {
42
+ payload.push([this.details, await this.details.payloadFor(projectIdx)]);
43
+ }
44
+ if (this.members?.length) {
45
+ await Promise.all(this.members.map(async (m) => payload.push(...(await m.multiAttestPayload(payload, projectIdx)))));
46
+ }
47
+ if (this.grants?.length) {
48
+ await Promise.all(this.grants.map(async (g) => payload.push(...(await g.multiAttestPayload(payload, projectIdx)))));
49
+ }
50
+ return payload.slice(currentPayload.length, payload.length);
51
+ }
52
+ async attest(signer, callback) {
53
+ const payload = await this.multiAttestPayload();
54
+ const { tx, uids } = await GapContract_1.GapContract.multiAttest(signer, payload.map((p) => p[1]), callback);
55
+ if (Array.isArray(uids)) {
56
+ uids.forEach((uid, index) => {
57
+ payload[index][0].uid = uid;
58
+ });
59
+ }
60
+ return { tx, uids };
61
+ }
62
+ async transferOwnership(signer, newOwner, callback) {
63
+ callback?.("preparing");
64
+ const tx = await GapContract_1.GapContract.transferProjectOwnership(signer, this.uid, newOwner);
65
+ callback?.("confirmed");
66
+ const txArray = [tx].flat();
67
+ return { tx: txArray, uids: [this.uid] };
68
+ }
69
+ isOwner(signer, publicAddress) {
70
+ return GapContract_1.GapContract.isProjectOwner(signer, this.uid, this.chainID, publicAddress);
71
+ }
72
+ isAdmin(signer, publicAddress) {
73
+ return GapContract_1.GapContract.isProjectAdmin(signer, this.uid, this.chainID, publicAddress);
74
+ }
75
+ /**
76
+ * Add new members to the project.
77
+ * If any member in the array already exists in the project
78
+ * it'll be ignored.
79
+ * @param members
80
+ */
81
+ pushMembers(...members) {
82
+ this.members.push(...(0, utils_1.mapFilter)(members, (member) => !!this.members.find((m) => m.recipient === member), (member) => new MemberOf_1.MemberOf({
83
+ data: { memberOf: true },
84
+ refUID: this.uid,
85
+ schema: this.schema.gap.findSchema("MemberOf"),
86
+ recipient: member,
87
+ uid: consts_1.nullRef,
88
+ })));
89
+ }
90
+ /**
91
+ * Add new members to the project.
92
+ * If any member in the array already exists in the project
93
+ * it'll be ignored.
94
+ *
95
+ * __To modify member details, use `addMemberDetails(signer, MemberDetails[])` instead.__
96
+ * @param signer
97
+ * @param members
98
+ */
99
+ async attestMembers(signer, members, callback) {
100
+ const newMembers = (0, utils_1.mapFilter)(members, (member) => !this.members.find((m) => m.recipient === member.recipient),
101
+ // (member) => !!member,
102
+ (details) => {
103
+ const member = new MemberOf_1.MemberOf({
104
+ data: { memberOf: true },
105
+ refUID: this.uid,
106
+ schema: this.schema.gap.findSchema("MemberOf"),
107
+ createdAt: Date.now(),
108
+ recipient: details.recipient,
109
+ uid: consts_1.nullRef,
110
+ });
111
+ return { member, details };
112
+ });
113
+ if (!newMembers.length) {
114
+ throw new SchemaError_1.AttestationError("ATTEST_ERROR", "No new members to add.");
115
+ }
116
+ console.log(`Creating ${newMembers.length} new members`);
117
+ const { uids: attestedMembers } = await this.schema.multiAttest(signer, newMembers.map((m) => m.member), callback);
118
+ console.log("attested-members", attestedMembers);
119
+ newMembers.forEach(({ member, details }, idx) => {
120
+ Object.assign(member, { uid: attestedMembers[idx] });
121
+ if (!details)
122
+ return;
123
+ Object.assign(details, { refUID: attestedMembers[idx] });
124
+ });
125
+ this.members.push(...newMembers.map((m) => m.member));
126
+ await this.addMemberDetails(signer, newMembers.map((m) => m.details));
127
+ }
128
+ /**
129
+ * Add new details to the members of a project. Note that it will overwrite
130
+ * any existing details.
131
+ *
132
+ * @param signer
133
+ * @param entities
134
+ */
135
+ async addMemberDetails(signer, entities, callback) {
136
+ // Check if any of members should be revoked (details modified)
137
+ const toRevoke = (0, utils_1.mapFilter)(this.members, (member) => !!entities.find((entity) => member.uid === entity.refUID &&
138
+ member.details &&
139
+ member.details?.refUID !== entity.refUID), (member) => member.uid);
140
+ if (toRevoke.length) {
141
+ console.log("Revoking details");
142
+ await this.cleanDetails(signer, toRevoke);
143
+ }
144
+ console.log(`Creating ${entities.length} new member details`);
145
+ const { uids: attestedEntities } = await this.schema.multiAttest(signer, entities, callback);
146
+ console.log("attested-entities", attestedEntities);
147
+ entities.forEach((entity, idx) => {
148
+ const member = this.members.find((member) => member.uid === entity.refUID);
149
+ if (!member)
150
+ return;
151
+ Object.assign(entity, { uid: attestedEntities[idx] });
152
+ member.details = entity;
153
+ });
154
+ }
155
+ /**
156
+ * Clean member details.
157
+ * @param signer
158
+ * @param uids
159
+ */
160
+ async cleanDetails(signer, uids) {
161
+ if (!uids.length) {
162
+ throw new SchemaError_1.AttestationError("ATTEST_ERROR", "No details to clean.");
163
+ }
164
+ const memberDetails = this.schema.gap.findSchema("MemberDetails");
165
+ await this.schema.multiRevoke(signer, uids.map((uid) => ({ schemaId: memberDetails.uid, uid })));
166
+ this.members.forEach((member) => {
167
+ if (!member.details)
168
+ return;
169
+ if (uids.includes(member.details.uid)) {
170
+ member.details = undefined;
171
+ }
172
+ });
173
+ }
174
+ /**
175
+ * Remove members from the project.
176
+ * @param signer
177
+ * @param uids
178
+ * @returns
179
+ */
180
+ async removeMembers(signer, uids) {
181
+ if (!uids.length) {
182
+ throw new SchemaError_1.AttestationError("ATTEST_ERROR", "No members to remove.");
183
+ }
184
+ const memberOf = this.schema.gap.findSchema("MemberOf");
185
+ const details = (0, utils_1.mapFilter)(this.members, (m) => uids.includes(m.uid) && !!m.details, (m) => m.details?.uid);
186
+ if (details.length) {
187
+ await this.cleanDetails(signer, details);
188
+ }
189
+ await this.schema.multiRevoke(signer, uids.map((uid) => ({ schemaId: memberOf.uid, uid })));
190
+ this.members = this.members.filter((m) => !uids.includes(m.uid));
191
+ }
192
+ /**
193
+ * Remove all members from the project.
194
+ * @param signer
195
+ */
196
+ async removeAllMembers(signer) {
197
+ const members = (0, utils_1.mapFilter)(this.members, (m) => !!m.uid, (m) => m.uid);
198
+ if (!members.length) {
199
+ throw new SchemaError_1.AttestationError("REVOKATION_ERROR", "No members to revoke.");
200
+ }
201
+ const details = (0, utils_1.mapFilter)(this.members, (m) => !!m.details, (m) => m.details?.uid);
202
+ if (details.length) {
203
+ await this.cleanDetails(signer, details);
204
+ }
205
+ await this.removeMembers(signer, members);
206
+ this.members.splice(0, this.members.length);
207
+ }
208
+ static from(attestations, network) {
209
+ const allSchemas = new AllGapSchemas_1.AllGapSchemas();
210
+ return attestations.map((attestation) => {
211
+ const project = new Project({
212
+ ...attestation,
213
+ data: {
214
+ project: true,
215
+ },
216
+ schema: allSchemas.findSchema("Project", consts_1.chainIdToNetwork[attestation.chainID]),
217
+ chainID: attestation.chainID,
218
+ });
219
+ if (attestation.details) {
220
+ const { details } = attestation;
221
+ project.details = new attestations_1.ProjectDetails({
222
+ ...details,
223
+ data: {
224
+ ...details.data,
225
+ },
226
+ schema: allSchemas.findSchema("ProjectDetails", consts_1.chainIdToNetwork[attestation.chainID]),
227
+ chainID: attestation.chainID,
228
+ });
229
+ project.details.links = details.data.links || [];
230
+ project.details.tags = details.data.tags || [];
231
+ if (attestation.data.links) {
232
+ project.details.links = attestation.data.links;
233
+ }
234
+ if (attestation.data.tags) {
235
+ project.details.tags = attestation.tags;
236
+ }
237
+ }
238
+ if (attestation.members) {
239
+ project.members = attestation.members.map((m) => {
240
+ const member = new MemberOf_1.MemberOf({
241
+ ...m,
242
+ data: {
243
+ memberOf: true,
244
+ },
245
+ schema: allSchemas.findSchema("MemberOf", consts_1.chainIdToNetwork[attestation.chainID]),
246
+ chainID: attestation.chainID,
247
+ });
248
+ if (m.details) {
249
+ const { details } = m;
250
+ member.details = new attestations_1.MemberDetails({
251
+ ...details,
252
+ data: {
253
+ ...details.data,
254
+ },
255
+ schema: allSchemas.findSchema("MemberDetails", consts_1.chainIdToNetwork[attestation.chainID]),
256
+ chainID: attestation.chainID,
257
+ });
258
+ }
259
+ return member;
260
+ });
261
+ }
262
+ if (attestation.grants) {
263
+ project.grants = Grant_1.Grant.from(attestation.grants, network);
264
+ }
265
+ if (attestation.impacts) {
266
+ project.impacts = ProjectImpact_1.ProjectImpact.from(attestation.impacts, network);
267
+ }
268
+ if (attestation.pointers) {
269
+ project.pointers = ProjectPointer_1.ProjectPointer.from(attestation.pointers, network);
270
+ }
271
+ if (attestation.updates) {
272
+ project.updates = ProjectUpdate_1.ProjectUpdate.from(attestation.updates, network);
273
+ }
274
+ if (attestation.milestones) {
275
+ project.milestones = ProjectMilestone_1.ProjectMilestone.from(attestation.milestones, network);
276
+ }
277
+ if (attestation.endorsements) {
278
+ project.endorsements = attestation.endorsements.map((pi) => {
279
+ const endorsement = new attestations_1.ProjectEndorsement({
280
+ ...pi,
281
+ data: {
282
+ ...pi.data,
283
+ },
284
+ schema: allSchemas.findSchema("ProjectDetails", consts_1.chainIdToNetwork[attestation.chainID]),
285
+ chainID: attestation.chainID,
286
+ });
287
+ return endorsement;
288
+ });
289
+ }
290
+ return project;
291
+ });
292
+ }
293
+ async attestUpdate(signer, data, callback) {
294
+ const projectUpdate = new ProjectUpdate_1.ProjectUpdate({
295
+ data: {
296
+ ...data,
297
+ type: "project-update",
298
+ },
299
+ recipient: this.recipient,
300
+ refUID: this.uid,
301
+ schema: this.schema.gap.findSchema("ProjectUpdate"),
302
+ });
303
+ await projectUpdate.attest(signer, callback);
304
+ this.updates.push(projectUpdate);
305
+ }
306
+ async attestMilestone(signer, data, callback) {
307
+ const projectMilestone = new ProjectMilestone_1.ProjectMilestone({
308
+ data: {
309
+ ...data,
310
+ type: "project-milestone",
311
+ },
312
+ recipient: this.recipient,
313
+ refUID: this.uid,
314
+ schema: this.schema.gap.findSchema("ProjectMilestone"),
315
+ });
316
+ await projectMilestone.attest(signer, callback);
317
+ this.milestones.push(projectMilestone);
318
+ }
319
+ async attestPointer(signer, data, callback) {
320
+ const projectPointer = new ProjectPointer_1.ProjectPointer({
321
+ data: {
322
+ ...data,
323
+ type: "project-pointer",
324
+ },
325
+ recipient: this.recipient,
326
+ refUID: this.uid,
327
+ schema: this.schema.gap.findSchema("ProjectPointer"),
328
+ });
329
+ await projectPointer.attest(signer, callback);
330
+ this.pointers.push(projectPointer);
331
+ }
332
+ async attestImpact(signer, data, targetChainId, callback) {
333
+ if (targetChainId && targetChainId !== this.chainID) {
334
+ return this.attestGhostProjectImpact(signer, data, targetChainId, callback);
335
+ }
336
+ const projectImpact = new ProjectImpact_1.ProjectImpact({
337
+ data: {
338
+ ...data,
339
+ type: "project-impact",
340
+ },
341
+ recipient: this.recipient,
342
+ refUID: this.uid,
343
+ schema: this.schema.gap.findSchema("ProjectDetails"),
344
+ });
345
+ const { tx, uids } = await projectImpact.attest(signer, callback);
346
+ this.impacts.push(projectImpact);
347
+ return { tx, uids };
348
+ }
349
+ async attestGhostProjectImpact(signer, data, targetChainId, callback) {
350
+ const { tx, uids } = await this.attestGhostProject(signer, targetChainId);
351
+ const ghostProjectUid = uids[0];
352
+ const allGapSchemas = new AllGapSchemas_1.AllGapSchemas();
353
+ const projectImpact = new ProjectImpact_1.ProjectImpact({
354
+ data: {
355
+ ...data,
356
+ type: "project-impact",
357
+ },
358
+ recipient: this.recipient,
359
+ refUID: ghostProjectUid,
360
+ schema: allGapSchemas.findSchema("ProjectDetails", consts_1.chainIdToNetwork[targetChainId]),
361
+ chainID: targetChainId,
362
+ });
363
+ const impactAttestation = await projectImpact.attest(signer, callback);
364
+ this.impacts.push(projectImpact);
365
+ return {
366
+ tx: impactAttestation.tx,
367
+ uids: [...uids, impactAttestation.uids[0]],
368
+ };
369
+ }
370
+ async attestEndorsement(signer, data) {
371
+ const projectEndorsement = new attestations_1.ProjectEndorsement({
372
+ data: {
373
+ ...data,
374
+ type: "project-endorsement",
375
+ },
376
+ recipient: this.recipient,
377
+ refUID: this.uid,
378
+ schema: this.schema.gap.findSchema("ProjectDetails"),
379
+ });
380
+ await projectEndorsement.attest(signer);
381
+ this.endorsements.push(projectEndorsement);
382
+ }
383
+ async attestGhostProject(signer, targetChainId) {
384
+ const allGapSchemas = new AllGapSchemas_1.AllGapSchemas();
385
+ const project = new Project({
386
+ data: { project: true },
387
+ schema: allGapSchemas.findSchema("Project", consts_1.chainIdToNetwork[targetChainId]),
388
+ recipient: this.recipient,
389
+ chainID: targetChainId,
390
+ });
391
+ project.details = new Attestation_1.Attestation({
392
+ data: {
393
+ originalProjectChainId: this.chainID,
394
+ uid: this.uid,
395
+ },
396
+ chainID: targetChainId,
397
+ recipient: this.recipient,
398
+ schema: allGapSchemas.findSchema("ProjectDetails", consts_1.chainIdToNetwork[targetChainId]),
399
+ });
400
+ const attestation = await project.attest(signer);
401
+ return attestation;
402
+ }
403
+ async addAdmin(signer, newAdmin, callback) {
404
+ callback?.("preparing");
405
+ const tx = await GapContract_1.GapContract.addProjectAdmin(signer, this.uid, newAdmin);
406
+ callback?.("confirmed");
407
+ const txArray = [tx].flat();
408
+ return { tx: txArray, uids: [this.uid] };
409
+ }
410
+ async removeAdmin(signer, oldAdmin, callback) {
411
+ callback?.("preparing");
412
+ const tx = await GapContract_1.GapContract.removeProjectAdmin(signer, this.uid, oldAdmin);
413
+ callback?.("confirmed");
414
+ const txArray = [tx].flat();
415
+ return { tx: txArray, uids: [this.uid] };
416
+ }
417
+ }
418
+ exports.Project = Project;
@@ -0,0 +1,50 @@
1
+ import { SignerOrProvider, TNetwork } from "../../types";
2
+ import { Attestation, AttestationArgs } from "../Attestation";
3
+ import { GapSchema } from "../GapSchema";
4
+ import { Transaction } from "ethers";
5
+ export interface _IProjectImpact extends ProjectImpact {
6
+ }
7
+ type IStatus = "verified";
8
+ export interface IProjectImpactStatus {
9
+ type?: `project-impact-${IStatus}`;
10
+ reason?: string;
11
+ }
12
+ export declare class ProjectImpactStatus extends Attestation<IProjectImpactStatus> implements IProjectImpactStatus {
13
+ type: `project-impact-${IStatus}`;
14
+ reason?: string;
15
+ }
16
+ export interface IProjectImpact {
17
+ work: string;
18
+ impact: string;
19
+ proof: string;
20
+ startedAt?: number;
21
+ completedAt: number;
22
+ type?: string;
23
+ verified?: ProjectImpactStatus[];
24
+ }
25
+ export declare class ProjectImpact extends Attestation<IProjectImpact> implements IProjectImpact {
26
+ work: string;
27
+ impact: string;
28
+ proof: string;
29
+ startedAt?: number;
30
+ completedAt: number;
31
+ type?: string;
32
+ verified: ProjectImpactStatus[];
33
+ constructor(data: AttestationArgs<IProjectImpact, GapSchema>);
34
+ /**
35
+ * Attest Project Impact.
36
+ */
37
+ private attestStatus;
38
+ /**
39
+ * Verify this ProjectImpact. If the ProjectImpact is not already verified,
40
+ * it will throw an error.
41
+ * @param signer
42
+ * @param reason
43
+ */
44
+ verify(signer: SignerOrProvider, data?: IProjectImpactStatus, callback?: Function): Promise<{
45
+ tx: Transaction[];
46
+ uids: `0x${string}`[];
47
+ }>;
48
+ static from(attestations: ProjectImpact[], network: TNetwork): ProjectImpact[];
49
+ }
50
+ export {};
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ProjectImpact = exports.ProjectImpactStatus = void 0;
4
+ const Attestation_1 = require("../Attestation");
5
+ const SchemaError_1 = require("../SchemaError");
6
+ const AllGapSchemas_1 = require("../AllGapSchemas");
7
+ const consts_1 = require("../../consts");
8
+ class ProjectImpactStatus extends Attestation_1.Attestation {
9
+ }
10
+ exports.ProjectImpactStatus = ProjectImpactStatus;
11
+ class ProjectImpact extends Attestation_1.Attestation {
12
+ constructor(data) {
13
+ data.data.type = "project-impact";
14
+ super(data);
15
+ this.verified = [];
16
+ }
17
+ /**
18
+ * Attest Project Impact.
19
+ */
20
+ async attestStatus(signer, schema, callback) {
21
+ const eas = this.schema.gap.eas.connect(signer);
22
+ try {
23
+ if (callback)
24
+ callback("preparing");
25
+ const tx = await eas.attest({
26
+ schema: schema.uid,
27
+ data: {
28
+ recipient: this.recipient,
29
+ data: schema.encode(),
30
+ refUID: this.uid,
31
+ expirationTime: 0n,
32
+ revocable: schema.revocable,
33
+ },
34
+ });
35
+ if (callback)
36
+ callback("pending");
37
+ const uid = await tx.wait();
38
+ if (callback)
39
+ callback("confirmed");
40
+ console.log(uid);
41
+ return {
42
+ tx: [
43
+ {
44
+ hash: tx.tx.hash,
45
+ },
46
+ ],
47
+ uids: [uid],
48
+ };
49
+ }
50
+ catch (error) {
51
+ console.error(error);
52
+ throw new SchemaError_1.AttestationError("ATTEST_ERROR", error.message, error);
53
+ }
54
+ }
55
+ /**
56
+ * Verify this ProjectImpact. If the ProjectImpact is not already verified,
57
+ * it will throw an error.
58
+ * @param signer
59
+ * @param reason
60
+ */
61
+ async verify(signer, data, callback) {
62
+ console.log("Verifying ProjectImpact");
63
+ const schema = this.schema.gap.findSchema("GrantUpdateStatus");
64
+ if (this.schema.isJsonSchema()) {
65
+ schema.setValue("json", JSON.stringify({
66
+ type: "project-impact-verified",
67
+ reason: data?.reason || '',
68
+ }));
69
+ }
70
+ else {
71
+ schema.setValue("type", "project-impact-verified");
72
+ schema.setValue("reason", data?.reason || '');
73
+ }
74
+ console.log("Before attest project impact verified");
75
+ const { tx, uids } = await this.attestStatus(signer, schema, callback);
76
+ console.log("After attest project impact verified");
77
+ this.verified.push(new ProjectImpactStatus({
78
+ data: {
79
+ type: "project-impact-verified",
80
+ reason: data?.reason || '',
81
+ },
82
+ refUID: this.uid,
83
+ schema: schema,
84
+ recipient: this.recipient,
85
+ }));
86
+ return { tx, uids };
87
+ }
88
+ static from(attestations, network) {
89
+ return attestations.map((attestation) => {
90
+ const projectImpact = new ProjectImpact({
91
+ ...attestation,
92
+ data: {
93
+ ...attestation.data,
94
+ },
95
+ schema: new AllGapSchemas_1.AllGapSchemas().findSchema("ProjectImpact", consts_1.chainIdToNetwork[attestation.chainID]),
96
+ chainID: attestation.chainID,
97
+ });
98
+ if (attestation.verified?.length > 0) {
99
+ projectImpact.verified = attestation.verified.map((m) => new ProjectImpactStatus({
100
+ ...m,
101
+ data: {
102
+ ...m.data,
103
+ },
104
+ schema: new AllGapSchemas_1.AllGapSchemas().findSchema("GrantUpdateStatus", consts_1.chainIdToNetwork[attestation.chainID]),
105
+ chainID: attestation.chainID,
106
+ }));
107
+ }
108
+ return projectImpact;
109
+ });
110
+ }
111
+ }
112
+ exports.ProjectImpact = ProjectImpact;