@show-karma/karma-gap-sdk 0.1.29
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.
- package/core/abi/MultiAttester.json +676 -0
- package/core/class/Attestation.d.ts +169 -0
- package/core/class/Attestation.js +311 -0
- package/core/class/Fetcher.d.ts +132 -0
- package/core/class/Fetcher.js +7 -0
- package/core/class/GAP.d.ts +212 -0
- package/core/class/GAP.js +206 -0
- package/core/class/GapSchema.d.ts +33 -0
- package/core/class/GapSchema.js +61 -0
- package/core/class/Gelato/Gelato.d.ts +0 -0
- package/core/class/Gelato/Gelato.js +263 -0
- package/core/class/GraphQL/AxiosGQL.d.ts +6 -0
- package/core/class/GraphQL/AxiosGQL.js +25 -0
- package/core/class/GraphQL/EASClient.d.ts +16 -0
- package/core/class/GraphQL/EASClient.js +26 -0
- package/core/class/GraphQL/Fetcher.d.ts +132 -0
- package/core/class/GraphQL/Fetcher.js +7 -0
- package/core/class/GraphQL/GAPFetcher.d.ts +160 -0
- package/core/class/GraphQL/GAPFetcher.js +516 -0
- package/core/class/GraphQL/GapEasClient.d.ts +63 -0
- package/core/class/GraphQL/GapEasClient.js +420 -0
- package/core/class/GraphQL/index.d.ts +3 -0
- package/core/class/GraphQL/index.js +19 -0
- package/core/class/Schema.d.ts +213 -0
- package/core/class/Schema.js +434 -0
- package/core/class/SchemaError.d.ts +26 -0
- package/core/class/SchemaError.js +34 -0
- package/core/class/contract/GapContract.d.ts +55 -0
- package/core/class/contract/GapContract.js +176 -0
- package/core/class/contract/MultiAttest.d.ts +10 -0
- package/core/class/contract/MultiAttest.js +19 -0
- package/core/class/entities/Community.d.ts +36 -0
- package/core/class/entities/Community.js +88 -0
- package/core/class/entities/Grant.d.ts +53 -0
- package/core/class/entities/Grant.js +194 -0
- package/core/class/entities/MemberOf.d.ts +11 -0
- package/core/class/entities/MemberOf.js +31 -0
- package/core/class/entities/Milestone.d.ts +63 -0
- package/core/class/entities/Milestone.js +171 -0
- package/core/class/entities/Project.d.ts +73 -0
- package/core/class/entities/Project.js +243 -0
- package/core/class/entities/index.d.ts +5 -0
- package/core/class/entities/index.js +21 -0
- package/core/class/index.d.ts +7 -0
- package/core/class/index.js +23 -0
- package/core/class/karma-indexer/GapIndexerClient.d.ts +28 -0
- package/core/class/karma-indexer/GapIndexerClient.js +137 -0
- package/core/class/types/attestations.d.ts +108 -0
- package/core/class/types/attestations.js +55 -0
- package/core/consts.d.ts +19 -0
- package/core/consts.js +228 -0
- package/core/index.d.ts +7 -0
- package/core/index.js +23 -0
- package/core/types.d.ts +107 -0
- package/core/types.js +13 -0
- package/core/utils/gelato/index.d.ts +3 -0
- package/core/utils/gelato/index.js +19 -0
- package/core/utils/gelato/send-gelato-txn.d.ts +54 -0
- package/core/utils/gelato/send-gelato-txn.js +99 -0
- package/core/utils/gelato/sponsor-handler.d.ts +9 -0
- package/core/utils/gelato/sponsor-handler.js +60 -0
- package/core/utils/gelato/watch-gelato-txn.d.ts +7 -0
- package/core/utils/gelato/watch-gelato-txn.js +55 -0
- package/core/utils/get-date.d.ts +1 -0
- package/core/utils/get-date.js +7 -0
- package/core/utils/gql-queries.d.ts +12 -0
- package/core/utils/gql-queries.js +90 -0
- package/core/utils/index.d.ts +6 -0
- package/core/utils/index.js +22 -0
- package/core/utils/map-filter.d.ts +8 -0
- package/core/utils/map-filter.js +20 -0
- package/core/utils/serialize-bigint.d.ts +1 -0
- package/core/utils/serialize-bigint.js +8 -0
- package/core/utils/to-unix.d.ts +1 -0
- package/core/utils/to-unix.js +25 -0
- package/index.d.ts +1 -0
- package/index.js +17 -0
- package/package.json +37 -0
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Milestone = void 0;
|
|
4
|
+
const Attestation_1 = require("../Attestation");
|
|
5
|
+
const GAP_1 = require("../GAP");
|
|
6
|
+
const GapSchema_1 = require("../GapSchema");
|
|
7
|
+
const SchemaError_1 = require("../SchemaError");
|
|
8
|
+
const attestations_1 = require("../types/attestations");
|
|
9
|
+
class Milestone extends Attestation_1.Attestation {
|
|
10
|
+
/**
|
|
11
|
+
* Approves this milestone. If the milestone is not completed or already approved,
|
|
12
|
+
* it will throw an error.
|
|
13
|
+
* @param signer
|
|
14
|
+
* @param reason
|
|
15
|
+
*/
|
|
16
|
+
async approve(signer, reason = "") {
|
|
17
|
+
if (!this.completed)
|
|
18
|
+
throw new SchemaError_1.AttestationError("ATTEST_ERROR", "Milestone is not completed");
|
|
19
|
+
const schema = GapSchema_1.GapSchema.find("MilestoneCompleted");
|
|
20
|
+
schema.setValue("type", "approved");
|
|
21
|
+
schema.setValue("reason", reason);
|
|
22
|
+
await this.attestStatus(signer, schema);
|
|
23
|
+
this.approved = new attestations_1.MilestoneCompleted({
|
|
24
|
+
data: {
|
|
25
|
+
type: "approved",
|
|
26
|
+
reason,
|
|
27
|
+
},
|
|
28
|
+
refUID: this.uid,
|
|
29
|
+
schema: schema,
|
|
30
|
+
recipient: this.recipient,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Revokes the approved status of the milestone. If the milestone is not approved,
|
|
35
|
+
* it will throw an error.
|
|
36
|
+
* @param signer
|
|
37
|
+
*/
|
|
38
|
+
async revokeApproval(signer) {
|
|
39
|
+
if (!this.approved)
|
|
40
|
+
throw new SchemaError_1.AttestationError("ATTEST_ERROR", "Milestone is not approved");
|
|
41
|
+
await this.approved.revoke(signer);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Reject a completed milestone. If the milestone is not completed or already rejected,
|
|
45
|
+
* it will throw an error.
|
|
46
|
+
* @param signer
|
|
47
|
+
* @param reason
|
|
48
|
+
*/
|
|
49
|
+
async reject(signer, reason = "") {
|
|
50
|
+
if (!this.completed)
|
|
51
|
+
throw new SchemaError_1.AttestationError("ATTEST_ERROR", "Milestone is not completed");
|
|
52
|
+
const schema = GapSchema_1.GapSchema.find("MilestoneCompleted");
|
|
53
|
+
schema.setValue("type", "rejected");
|
|
54
|
+
schema.setValue("reason", reason);
|
|
55
|
+
await this.attestStatus(signer, schema);
|
|
56
|
+
this.rejected = new attestations_1.MilestoneCompleted({
|
|
57
|
+
data: {
|
|
58
|
+
type: "rejected",
|
|
59
|
+
reason,
|
|
60
|
+
},
|
|
61
|
+
refUID: this.uid,
|
|
62
|
+
schema: schema,
|
|
63
|
+
recipient: this.recipient,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Revokes the rejected status of the milestone. If the milestone is not rejected,
|
|
68
|
+
* it will throw an error.
|
|
69
|
+
* @param signer
|
|
70
|
+
*/
|
|
71
|
+
async revokeRejection(signer) {
|
|
72
|
+
if (!this.rejected)
|
|
73
|
+
throw new SchemaError_1.AttestationError("ATTEST_ERROR", "Milestone is not rejected");
|
|
74
|
+
await this.rejected.revoke(signer);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Marks a milestone as completed. If the milestone is already completed,
|
|
78
|
+
* it will throw an error.
|
|
79
|
+
* @param signer
|
|
80
|
+
* @param reason
|
|
81
|
+
*/
|
|
82
|
+
async complete(signer, reason = "") {
|
|
83
|
+
const schema = GapSchema_1.GapSchema.find("MilestoneCompleted");
|
|
84
|
+
schema.setValue("type", "completed");
|
|
85
|
+
schema.setValue("reason", reason);
|
|
86
|
+
await this.attestStatus(signer, schema);
|
|
87
|
+
this.completed = new attestations_1.MilestoneCompleted({
|
|
88
|
+
data: {
|
|
89
|
+
type: "completed",
|
|
90
|
+
reason,
|
|
91
|
+
},
|
|
92
|
+
refUID: this.uid,
|
|
93
|
+
schema,
|
|
94
|
+
recipient: this.recipient,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Revokes the completed status of the milestone. If the milestone is not completed,
|
|
99
|
+
* it will throw an error.
|
|
100
|
+
* @param signer
|
|
101
|
+
*/
|
|
102
|
+
async revokeCompletion(signer) {
|
|
103
|
+
if (!this.completed)
|
|
104
|
+
throw new SchemaError_1.AttestationError("ATTEST_ERROR", "Milestone is not completed");
|
|
105
|
+
await this.completed.revoke(signer);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Attest the status of the milestone as approved, rejected or completed.
|
|
109
|
+
*/
|
|
110
|
+
async attestStatus(signer, schema) {
|
|
111
|
+
const eas = GAP_1.GAP.eas.connect(signer);
|
|
112
|
+
try {
|
|
113
|
+
const tx = await eas.attest({
|
|
114
|
+
schema: schema.uid,
|
|
115
|
+
data: {
|
|
116
|
+
recipient: this.recipient,
|
|
117
|
+
data: schema.encode(),
|
|
118
|
+
refUID: this.uid,
|
|
119
|
+
expirationTime: 0n,
|
|
120
|
+
revocable: schema.revocable,
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
const uid = await tx.wait();
|
|
124
|
+
console.log(uid);
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
console.error(error);
|
|
128
|
+
throw new SchemaError_1.AttestationError("ATTEST_ERROR", error.message);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
static from(attestations) {
|
|
132
|
+
return attestations.map((attestation) => {
|
|
133
|
+
const milestone = new Milestone({
|
|
134
|
+
...attestation,
|
|
135
|
+
data: {
|
|
136
|
+
...attestation.data,
|
|
137
|
+
},
|
|
138
|
+
schema: GapSchema_1.GapSchema.find("Milestone"),
|
|
139
|
+
});
|
|
140
|
+
if (attestation.completed) {
|
|
141
|
+
milestone.completed = new attestations_1.MilestoneCompleted({
|
|
142
|
+
...attestation.completed,
|
|
143
|
+
data: {
|
|
144
|
+
...attestation.completed.data,
|
|
145
|
+
},
|
|
146
|
+
schema: GapSchema_1.GapSchema.find("MilestoneCompleted"),
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
if (attestation.approved) {
|
|
150
|
+
milestone.approved = new attestations_1.MilestoneCompleted({
|
|
151
|
+
...attestation.approved,
|
|
152
|
+
data: {
|
|
153
|
+
...attestation.completed.data,
|
|
154
|
+
},
|
|
155
|
+
schema: GapSchema_1.GapSchema.find("MilestoneCompleted"),
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
if (attestation.rejected) {
|
|
159
|
+
milestone.rejected = new attestations_1.MilestoneCompleted({
|
|
160
|
+
...attestation.rejected,
|
|
161
|
+
data: {
|
|
162
|
+
...attestation.completed.data,
|
|
163
|
+
},
|
|
164
|
+
schema: GapSchema_1.GapSchema.find("MilestoneCompleted"),
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
return milestone;
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
exports.Milestone = Milestone;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Attestation } from "../Attestation";
|
|
2
|
+
import { Grantee, MemberDetails, ProjectDetails } from "../types/attestations";
|
|
3
|
+
import { Hex, MultiAttestPayload, SignerOrProvider } from "core/types";
|
|
4
|
+
import { Grant } from "./Grant";
|
|
5
|
+
import { MemberOf } from "./MemberOf";
|
|
6
|
+
interface _Project extends Project {
|
|
7
|
+
}
|
|
8
|
+
export interface IProject {
|
|
9
|
+
project: true;
|
|
10
|
+
}
|
|
11
|
+
export declare class Project extends Attestation<IProject> {
|
|
12
|
+
details?: ProjectDetails;
|
|
13
|
+
members: MemberOf[];
|
|
14
|
+
grants: Grant[];
|
|
15
|
+
grantee: Grantee;
|
|
16
|
+
/**
|
|
17
|
+
* Creates the payload for a multi-attestation.
|
|
18
|
+
*
|
|
19
|
+
* > if Current payload is set, it'll be used as the base payload
|
|
20
|
+
* and the project should refer to an index of the current payload,
|
|
21
|
+
* usually the community position.
|
|
22
|
+
*
|
|
23
|
+
* @param payload
|
|
24
|
+
* @param communityIdx
|
|
25
|
+
*/
|
|
26
|
+
multiAttestPayload(currentPayload?: MultiAttestPayload, communityIdx?: number): MultiAttestPayload;
|
|
27
|
+
attest(signer: SignerOrProvider): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Add new members to the project.
|
|
30
|
+
* If any member in the array already exists in the project
|
|
31
|
+
* it'll be ignored.
|
|
32
|
+
* @param members
|
|
33
|
+
*/
|
|
34
|
+
pushMembers(...members: Hex[]): void;
|
|
35
|
+
/**
|
|
36
|
+
* Add new members to the project.
|
|
37
|
+
* If any member in the array already exists in the project
|
|
38
|
+
* it'll be ignored.
|
|
39
|
+
*
|
|
40
|
+
* __To modify member details, use `addMemberDetails(signer, MemberDetails[])` instead.__
|
|
41
|
+
* @param signer
|
|
42
|
+
* @param members
|
|
43
|
+
*/
|
|
44
|
+
attestMembers(signer: SignerOrProvider, members: MemberDetails[]): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Add new details to the members of a project. Note that it will overwrite
|
|
47
|
+
* any existing details.
|
|
48
|
+
*
|
|
49
|
+
* @param signer
|
|
50
|
+
* @param entities
|
|
51
|
+
*/
|
|
52
|
+
private addMemberDetails;
|
|
53
|
+
/**
|
|
54
|
+
* Clean member details.
|
|
55
|
+
* @param signer
|
|
56
|
+
* @param uids
|
|
57
|
+
*/
|
|
58
|
+
cleanDetails(signer: SignerOrProvider, uids: Hex[]): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Remove members from the project.
|
|
61
|
+
* @param signer
|
|
62
|
+
* @param uids
|
|
63
|
+
* @returns
|
|
64
|
+
*/
|
|
65
|
+
removeMembers(signer: SignerOrProvider, uids: Hex[]): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Remove all members from the project.
|
|
68
|
+
* @param signer
|
|
69
|
+
*/
|
|
70
|
+
removeAllMembers(signer: SignerOrProvider): Promise<void>;
|
|
71
|
+
static from(attestations: _Project[]): Project[];
|
|
72
|
+
}
|
|
73
|
+
export {};
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Project = void 0;
|
|
4
|
+
const Attestation_1 = require("../Attestation");
|
|
5
|
+
const attestations_1 = require("../types/attestations");
|
|
6
|
+
const GapSchema_1 = require("../GapSchema");
|
|
7
|
+
const SchemaError_1 = require("../SchemaError");
|
|
8
|
+
const utils_1 = require("../../utils");
|
|
9
|
+
const Grant_1 = require("./Grant");
|
|
10
|
+
const consts_1 = require("../../consts");
|
|
11
|
+
const MemberOf_1 = require("./MemberOf");
|
|
12
|
+
const GapContract_1 = require("../contract/GapContract");
|
|
13
|
+
class Project extends Attestation_1.Attestation {
|
|
14
|
+
constructor() {
|
|
15
|
+
super(...arguments);
|
|
16
|
+
this.members = [];
|
|
17
|
+
this.grants = [];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Creates the payload for a multi-attestation.
|
|
21
|
+
*
|
|
22
|
+
* > if Current payload is set, it'll be used as the base payload
|
|
23
|
+
* and the project should refer to an index of the current payload,
|
|
24
|
+
* usually the community position.
|
|
25
|
+
*
|
|
26
|
+
* @param payload
|
|
27
|
+
* @param communityIdx
|
|
28
|
+
*/
|
|
29
|
+
multiAttestPayload(currentPayload = [], communityIdx = 0) {
|
|
30
|
+
const payload = [...currentPayload];
|
|
31
|
+
const projectIdx = payload.push([this, this.payloadFor(communityIdx)]) - 1;
|
|
32
|
+
if (this.details) {
|
|
33
|
+
payload.push([this.details, this.details.payloadFor(projectIdx)]);
|
|
34
|
+
}
|
|
35
|
+
if (this.members?.length) {
|
|
36
|
+
this.members.forEach((m) => {
|
|
37
|
+
payload.push(...m.multiAttestPayload(payload, projectIdx));
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
if (this.grants?.length) {
|
|
41
|
+
this.grants.forEach((g) => {
|
|
42
|
+
payload.push(...g.multiAttestPayload(payload, projectIdx));
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return payload.slice(currentPayload.length, payload.length);
|
|
46
|
+
}
|
|
47
|
+
async attest(signer) {
|
|
48
|
+
const payload = this.multiAttestPayload();
|
|
49
|
+
const uids = await GapContract_1.GapContract.multiAttest(signer, payload.map((p) => p[1]));
|
|
50
|
+
uids.forEach((uid, index) => {
|
|
51
|
+
payload[index][0].uid = uid;
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Add new members to the project.
|
|
56
|
+
* If any member in the array already exists in the project
|
|
57
|
+
* it'll be ignored.
|
|
58
|
+
* @param members
|
|
59
|
+
*/
|
|
60
|
+
pushMembers(...members) {
|
|
61
|
+
this.members.push(...(0, utils_1.mapFilter)(members, (member) => !!this.members.find((m) => m.recipient === member), (member) => new MemberOf_1.MemberOf({
|
|
62
|
+
data: { memberOf: true },
|
|
63
|
+
refUID: this.uid,
|
|
64
|
+
schema: GapSchema_1.GapSchema.find("MemberOf"),
|
|
65
|
+
recipient: member,
|
|
66
|
+
uid: consts_1.nullRef,
|
|
67
|
+
})));
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Add new members to the project.
|
|
71
|
+
* If any member in the array already exists in the project
|
|
72
|
+
* it'll be ignored.
|
|
73
|
+
*
|
|
74
|
+
* __To modify member details, use `addMemberDetails(signer, MemberDetails[])` instead.__
|
|
75
|
+
* @param signer
|
|
76
|
+
* @param members
|
|
77
|
+
*/
|
|
78
|
+
async attestMembers(signer, members) {
|
|
79
|
+
const newMembers = (0, utils_1.mapFilter)(members, (member) => !this.members.find((m) => m.recipient === member.recipient),
|
|
80
|
+
// (member) => !!member,
|
|
81
|
+
(details) => {
|
|
82
|
+
const member = new MemberOf_1.MemberOf({
|
|
83
|
+
data: { memberOf: true },
|
|
84
|
+
refUID: this.uid,
|
|
85
|
+
schema: GapSchema_1.GapSchema.find("MemberOf"),
|
|
86
|
+
createdAt: Date.now(),
|
|
87
|
+
recipient: details.recipient,
|
|
88
|
+
uid: consts_1.nullRef,
|
|
89
|
+
});
|
|
90
|
+
return { member, details };
|
|
91
|
+
});
|
|
92
|
+
if (!newMembers.length) {
|
|
93
|
+
throw new SchemaError_1.AttestationError("ATTEST_ERROR", "No new members to add.");
|
|
94
|
+
}
|
|
95
|
+
console.log(`Creating ${newMembers.length} new members`);
|
|
96
|
+
const attestedMembers = await this.schema.multiAttest(signer, newMembers.map((m) => m.member));
|
|
97
|
+
console.log("attested-members", attestedMembers);
|
|
98
|
+
newMembers.forEach(({ member, details }, idx) => {
|
|
99
|
+
Object.assign(member, { uid: attestedMembers[idx] });
|
|
100
|
+
if (!details)
|
|
101
|
+
return;
|
|
102
|
+
Object.assign(details, { refUID: attestedMembers[idx] });
|
|
103
|
+
});
|
|
104
|
+
this.members.push(...newMembers.map((m) => m.member));
|
|
105
|
+
await this.addMemberDetails(signer, newMembers.map((m) => m.details));
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Add new details to the members of a project. Note that it will overwrite
|
|
109
|
+
* any existing details.
|
|
110
|
+
*
|
|
111
|
+
* @param signer
|
|
112
|
+
* @param entities
|
|
113
|
+
*/
|
|
114
|
+
async addMemberDetails(signer, entities) {
|
|
115
|
+
// Check if any of members should be revoked (details modified)
|
|
116
|
+
const toRevoke = (0, utils_1.mapFilter)(this.members, (member) => !!entities.find((entity) => member.uid === entity.refUID &&
|
|
117
|
+
member.details &&
|
|
118
|
+
member.details?.refUID !== entity.refUID), (member) => member.uid);
|
|
119
|
+
if (toRevoke.length) {
|
|
120
|
+
console.log("Revoking details");
|
|
121
|
+
await this.cleanDetails(signer, toRevoke);
|
|
122
|
+
}
|
|
123
|
+
console.log(`Creating ${entities.length} new member details`);
|
|
124
|
+
const attestedEntities = (await this.schema.multiAttest(signer, entities));
|
|
125
|
+
console.log("attested-entities", attestedEntities);
|
|
126
|
+
entities.forEach((entity, idx) => {
|
|
127
|
+
const member = this.members.find((member) => member.uid === entity.refUID);
|
|
128
|
+
if (!member)
|
|
129
|
+
return;
|
|
130
|
+
Object.assign(entity, { uid: attestedEntities[idx] });
|
|
131
|
+
member.details = entity;
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Clean member details.
|
|
136
|
+
* @param signer
|
|
137
|
+
* @param uids
|
|
138
|
+
*/
|
|
139
|
+
async cleanDetails(signer, uids) {
|
|
140
|
+
if (!uids.length) {
|
|
141
|
+
throw new SchemaError_1.AttestationError("ATTEST_ERROR", "No details to clean.");
|
|
142
|
+
}
|
|
143
|
+
const memberDetails = GapSchema_1.GapSchema.find("MemberDetails");
|
|
144
|
+
await this.schema.multiRevoke(signer, uids.map((uid) => ({ schemaId: memberDetails.uid, uid })));
|
|
145
|
+
this.members.forEach((member) => {
|
|
146
|
+
if (!member.details)
|
|
147
|
+
return;
|
|
148
|
+
if (uids.includes(member.details.uid)) {
|
|
149
|
+
member.details = undefined;
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Remove members from the project.
|
|
155
|
+
* @param signer
|
|
156
|
+
* @param uids
|
|
157
|
+
* @returns
|
|
158
|
+
*/
|
|
159
|
+
async removeMembers(signer, uids) {
|
|
160
|
+
if (!uids.length) {
|
|
161
|
+
throw new SchemaError_1.AttestationError("ATTEST_ERROR", "No members to remove.");
|
|
162
|
+
}
|
|
163
|
+
const memberOf = GapSchema_1.GapSchema.find("MemberOf");
|
|
164
|
+
const details = (0, utils_1.mapFilter)(this.members, (m) => uids.includes(m.uid) && !!m.details, (m) => m.details?.uid);
|
|
165
|
+
if (details.length) {
|
|
166
|
+
await this.cleanDetails(signer, details);
|
|
167
|
+
}
|
|
168
|
+
await this.schema.multiRevoke(signer, uids.map((uid) => ({ schemaId: memberOf.uid, uid })));
|
|
169
|
+
this.members = this.members.filter((m) => !uids.includes(m.uid));
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Remove all members from the project.
|
|
173
|
+
* @param signer
|
|
174
|
+
*/
|
|
175
|
+
async removeAllMembers(signer) {
|
|
176
|
+
const members = (0, utils_1.mapFilter)(this.members, (m) => !!m.uid, (m) => m.uid);
|
|
177
|
+
if (!members.length) {
|
|
178
|
+
throw new SchemaError_1.AttestationError("REVOKATION_ERROR", "No members to revoke.");
|
|
179
|
+
}
|
|
180
|
+
const details = (0, utils_1.mapFilter)(this.members, (m) => !!m.details, (m) => m.details?.uid);
|
|
181
|
+
if (details.length) {
|
|
182
|
+
await this.cleanDetails(signer, details);
|
|
183
|
+
}
|
|
184
|
+
await this.removeMembers(signer, members);
|
|
185
|
+
this.members.splice(0, this.members.length);
|
|
186
|
+
}
|
|
187
|
+
static from(attestations) {
|
|
188
|
+
return attestations.map((attestation) => {
|
|
189
|
+
const project = new Project({
|
|
190
|
+
...attestation,
|
|
191
|
+
data: {
|
|
192
|
+
project: true,
|
|
193
|
+
},
|
|
194
|
+
schema: GapSchema_1.GapSchema.find("Project"),
|
|
195
|
+
});
|
|
196
|
+
if (attestation.details) {
|
|
197
|
+
const { details } = attestation;
|
|
198
|
+
project.details = new attestations_1.ProjectDetails({
|
|
199
|
+
...details,
|
|
200
|
+
data: {
|
|
201
|
+
...details.data,
|
|
202
|
+
},
|
|
203
|
+
schema: GapSchema_1.GapSchema.find("ProjectDetails"),
|
|
204
|
+
});
|
|
205
|
+
project.details.links = details.data.links || [];
|
|
206
|
+
project.details.tags = details.data.tags || [];
|
|
207
|
+
if (attestation.data.links) {
|
|
208
|
+
project.details.links = attestation.data.links;
|
|
209
|
+
}
|
|
210
|
+
if (attestation.data.tags) {
|
|
211
|
+
project.details.tags = attestation.tags;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
if (attestation.members) {
|
|
215
|
+
project.members = attestation.members.map((m) => {
|
|
216
|
+
const member = new MemberOf_1.MemberOf({
|
|
217
|
+
...m,
|
|
218
|
+
data: {
|
|
219
|
+
memberOf: true,
|
|
220
|
+
},
|
|
221
|
+
schema: GapSchema_1.GapSchema.find("MemberOf"),
|
|
222
|
+
});
|
|
223
|
+
if (m.details) {
|
|
224
|
+
const { details } = m;
|
|
225
|
+
member.details = new attestations_1.MemberDetails({
|
|
226
|
+
...details,
|
|
227
|
+
data: {
|
|
228
|
+
...details.data,
|
|
229
|
+
},
|
|
230
|
+
schema: GapSchema_1.GapSchema.find("MemberDetails"),
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
return member;
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
if (attestation.grants) {
|
|
237
|
+
project.grants = Grant_1.Grant.from(attestation.grants);
|
|
238
|
+
}
|
|
239
|
+
return project;
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
exports.Project = Project;
|
|
@@ -0,0 +1,21 @@
|
|
|
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("./Grant"), exports);
|
|
18
|
+
__exportStar(require("./Milestone"), exports);
|
|
19
|
+
__exportStar(require("./Project"), exports);
|
|
20
|
+
__exportStar(require("./Community"), exports);
|
|
21
|
+
__exportStar(require("./MemberOf"), exports);
|
|
@@ -0,0 +1,23 @@
|
|
|
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("./Attestation"), exports);
|
|
18
|
+
__exportStar(require("./GAP"), exports);
|
|
19
|
+
__exportStar(require("./GapSchema"), exports);
|
|
20
|
+
__exportStar(require("./Schema"), exports);
|
|
21
|
+
__exportStar(require("./SchemaError"), exports);
|
|
22
|
+
__exportStar(require("./entities"), exports);
|
|
23
|
+
__exportStar(require("./karma-indexer/GapIndexerClient"), exports);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { TSchemaName, IAttestation } from "core/types";
|
|
2
|
+
import { Attestation } from "../Attestation";
|
|
3
|
+
import { GapSchema } from "../GapSchema";
|
|
4
|
+
import { Fetcher } from "../Fetcher";
|
|
5
|
+
import { Community, Project, Grant, Milestone, MemberOf } from "../entities";
|
|
6
|
+
import { Grantee } from "../types/attestations";
|
|
7
|
+
export declare class GapIndexerClient extends Fetcher {
|
|
8
|
+
attestation<T = unknown>(uid: `0x${string}`): Promise<Attestation<T, GapSchema>>;
|
|
9
|
+
attestations(schemaName: TSchemaName, search?: string): Promise<IAttestation[]>;
|
|
10
|
+
attestationsOf(schemaName: TSchemaName, attester: `0x${string}`): Promise<IAttestation[]>;
|
|
11
|
+
attestationsTo(schemaName: TSchemaName, recipient: `0x${string}`): Promise<IAttestation[]>;
|
|
12
|
+
communities(search?: string): Promise<Community[]>;
|
|
13
|
+
communitiesByIds(uids: `0x${string}`[]): Promise<Community[]>;
|
|
14
|
+
communityBySlug(slug: string): Promise<Community>;
|
|
15
|
+
communityById(uid: `0x${string}`): Promise<Community>;
|
|
16
|
+
projectBySlug(slug: string): Promise<Project>;
|
|
17
|
+
projectById(uid: `0x${string}`): Promise<Project>;
|
|
18
|
+
projects(name?: string): Promise<Project[]>;
|
|
19
|
+
projectsOf(grantee: `0x${string}`): Promise<Project[]>;
|
|
20
|
+
grantee(address: `0x${string}`): Promise<Grantee>;
|
|
21
|
+
grantees(): Promise<Grantee[]>;
|
|
22
|
+
grantsOf(grantee: `0x${string}`, withCommunity?: boolean): Promise<Grant[]>;
|
|
23
|
+
grantsFor(projects: Project[], withCommunity?: boolean): Promise<Grant[]>;
|
|
24
|
+
grantsByCommunity(uid: `0x${string}`): Promise<Grant[]>;
|
|
25
|
+
milestonesOf(grants: Grant[]): Promise<Milestone[]>;
|
|
26
|
+
membersOf(projects: Project[]): Promise<MemberOf[]>;
|
|
27
|
+
slugExists(slug: string): Promise<boolean>;
|
|
28
|
+
}
|