@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,420 @@
|
|
|
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
|
+
}));
|
|
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])[0];
|
|
40
|
+
}
|
|
41
|
+
async attestations(schemaName, search) {
|
|
42
|
+
const schema = GapSchema_1.GapSchema.find(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 = GapSchema_1.GapSchema.find(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 = GapSchema_1.GapSchema.find(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 = GapSchema_1.GapSchema.find(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);
|
|
72
|
+
}
|
|
73
|
+
async communities(search) {
|
|
74
|
+
const [community, communityDetails] = GapSchema_1.GapSchema.findMany([
|
|
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);
|
|
81
|
+
if (!communities.length)
|
|
82
|
+
return [];
|
|
83
|
+
return this.communitiesDetails(communities);
|
|
84
|
+
}
|
|
85
|
+
async communitiesByIds(uids) {
|
|
86
|
+
if (!uids.length)
|
|
87
|
+
return [];
|
|
88
|
+
const communityDetails = GapSchema_1.GapSchema.find('CommunityDetails');
|
|
89
|
+
const communityQuery = gql_queries_1.gqlQueries.attestationsIn(uids);
|
|
90
|
+
const detailsQuery = gql_queries_1.gqlQueries.dependentsOf(uids, [communityDetails.uid]);
|
|
91
|
+
try {
|
|
92
|
+
const [communities, details] = await Promise.all([
|
|
93
|
+
this.query(communityQuery),
|
|
94
|
+
this.query(detailsQuery),
|
|
95
|
+
]);
|
|
96
|
+
const communitiesAttestations = Attestation_1.Attestation.fromInterface(communities.attestations || []);
|
|
97
|
+
const detailsAttestations = Attestation_1.Attestation.fromInterface(details.attestations || []);
|
|
98
|
+
communitiesAttestations.forEach((community) => {
|
|
99
|
+
community.details = detailsAttestations.find((d) => d.refUID === community.uid);
|
|
100
|
+
});
|
|
101
|
+
return communitiesAttestations;
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
throw error;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
async communitiesDetails(communities) {
|
|
108
|
+
const [project, communityDetails] = GapSchema_1.GapSchema.findMany([
|
|
109
|
+
'Project',
|
|
110
|
+
'CommunityDetails',
|
|
111
|
+
]);
|
|
112
|
+
const ref = gql_queries_1.gqlQueries.dependentsOf(communities.map((c) => c.uid), [communityDetails.uid]);
|
|
113
|
+
const results = await this.query(ref);
|
|
114
|
+
const deps = Attestation_1.Attestation.fromInterface(results.attestations || []);
|
|
115
|
+
return communities.map((community) => {
|
|
116
|
+
community.projects = (deps.filter((ref) => ref.schema.uid === project.uid && ref.refUID === community.uid));
|
|
117
|
+
community.details = (deps.find((ref) => ref.schema.uid === communityDetails.uid &&
|
|
118
|
+
ref.refUID === community.uid));
|
|
119
|
+
return community;
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
async communityBySlug(slug) {
|
|
123
|
+
const communitySchema = GapSchema_1.GapSchema.find('CommunityDetails');
|
|
124
|
+
const query = gql_queries_1.gqlQueries.attestationsOf(communitySchema.uid, this.getSearchFieldString('slug', slug));
|
|
125
|
+
try {
|
|
126
|
+
const { schema: { attestations }, } = await this.query(query);
|
|
127
|
+
if (!attestations.length)
|
|
128
|
+
throw new Error('Community not found.');
|
|
129
|
+
const communities = (0, utils_1.mapFilter)(Attestation_1.Attestation.fromInterface(attestations), (details) => !!details.name, (details) => {
|
|
130
|
+
const community = new Community_1.Community({
|
|
131
|
+
data: { community: true },
|
|
132
|
+
uid: details.refUID,
|
|
133
|
+
schema: communitySchema,
|
|
134
|
+
recipient: details.recipient,
|
|
135
|
+
});
|
|
136
|
+
community.details = details;
|
|
137
|
+
return community;
|
|
138
|
+
});
|
|
139
|
+
const [withDetails] = await this.communitiesDetails(communities);
|
|
140
|
+
if (!withDetails)
|
|
141
|
+
throw new Error('Community not found.');
|
|
142
|
+
const grants = await this.grantsByCommunity(withDetails.uid);
|
|
143
|
+
withDetails.grants = grants;
|
|
144
|
+
return withDetails;
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
throw error;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
async communityById(uid) {
|
|
151
|
+
const query = gql_queries_1.gqlQueries.attestation(uid);
|
|
152
|
+
const { attestation } = await this.query(query);
|
|
153
|
+
if (!attestation)
|
|
154
|
+
throw new Error('Community not found.');
|
|
155
|
+
const communities = Attestation_1.Attestation.fromInterface([attestation]).map((c) => new Community_1.Community(c));
|
|
156
|
+
const [withDetails] = await this.communitiesDetails(communities);
|
|
157
|
+
if (!withDetails)
|
|
158
|
+
throw new Error('Community not found.');
|
|
159
|
+
const grants = await this.grantsByCommunity(uid);
|
|
160
|
+
withDetails.grants = grants;
|
|
161
|
+
return withDetails;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Fetch the details for a set of
|
|
165
|
+
* projects with project grants,
|
|
166
|
+
* members, milestones, and tags.
|
|
167
|
+
* @param projects
|
|
168
|
+
*/
|
|
169
|
+
async projectsDetails(projects) {
|
|
170
|
+
// Get projects array and fetch details, members, grants, etc then append to the project and return the array.
|
|
171
|
+
const [projectDetails] = GapSchema_1.GapSchema.findMany(['ProjectDetails']);
|
|
172
|
+
const refQuery = gql_queries_1.gqlQueries.dependentsOf(projects.map((p) => p.uid), [projectDetails.uid]);
|
|
173
|
+
const [result, members, grants] = await Promise.all([
|
|
174
|
+
this.query(refQuery),
|
|
175
|
+
this.membersOf(projects),
|
|
176
|
+
this.grantsFor(projects, true),
|
|
177
|
+
]);
|
|
178
|
+
const deps = Attestation_1.Attestation.fromInterface(result.attestations || []);
|
|
179
|
+
return projects.map((project) => {
|
|
180
|
+
project.details = (deps.find((ref) => ref.schema.uid === projectDetails.uid && ref.refUID === project.uid));
|
|
181
|
+
project.members = members.filter((m) => m.refUID === project.uid);
|
|
182
|
+
project.grants = grants.filter((g) => g.refUID === project.uid);
|
|
183
|
+
return project;
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
async projectById(uid) {
|
|
187
|
+
const query = gql_queries_1.gqlQueries.attestation(uid);
|
|
188
|
+
const { attestation } = await this.query(query);
|
|
189
|
+
if (!attestation)
|
|
190
|
+
throw new Error('Project not found.');
|
|
191
|
+
const projectAttestation = Attestation_1.Attestation.fromInterface([
|
|
192
|
+
attestation,
|
|
193
|
+
])[0];
|
|
194
|
+
const [result] = await this.projectsDetails([
|
|
195
|
+
new entities_1.Project(projectAttestation),
|
|
196
|
+
]);
|
|
197
|
+
return result;
|
|
198
|
+
}
|
|
199
|
+
async projectBySlug(slug) {
|
|
200
|
+
const projectDetails = GapSchema_1.GapSchema.find('ProjectDetails');
|
|
201
|
+
const query = gql_queries_1.gqlQueries.attestationsOf(projectDetails.uid, this.getSearchFieldString('slug', slug));
|
|
202
|
+
const { schema: { attestations }, } = await this.query(query);
|
|
203
|
+
const projectAttestations = Attestation_1.Attestation.fromInterface(attestations).filter((p) => p.title);
|
|
204
|
+
if (!projectAttestations.length)
|
|
205
|
+
throw new Error('Project not found.');
|
|
206
|
+
const project = new entities_1.Project({
|
|
207
|
+
data: { project: true },
|
|
208
|
+
uid: projectAttestations[0].refUID,
|
|
209
|
+
schema: GapSchema_1.GapSchema.find('Project'),
|
|
210
|
+
recipient: projectAttestations[0].recipient,
|
|
211
|
+
});
|
|
212
|
+
const [withDetails] = await this.projectsDetails([project]);
|
|
213
|
+
if (!withDetails)
|
|
214
|
+
throw new Error('Project not found.');
|
|
215
|
+
return withDetails;
|
|
216
|
+
}
|
|
217
|
+
async slugExists(slug) {
|
|
218
|
+
const details = GapSchema_1.GapSchema.find('ProjectDetails');
|
|
219
|
+
const query = gql_queries_1.gqlQueries.attestationsOf(details.uid, 'slug');
|
|
220
|
+
const { schema: { attestations }, } = await this.query(query);
|
|
221
|
+
return attestations.some((a) => a.decodedDataJson.includes(slug));
|
|
222
|
+
}
|
|
223
|
+
async projects(name) {
|
|
224
|
+
const result = await this.attestations('Project', name);
|
|
225
|
+
if (!result.length)
|
|
226
|
+
return [];
|
|
227
|
+
const projects = Attestation_1.Attestation.fromInterface(result);
|
|
228
|
+
return this.projectsDetails(projects);
|
|
229
|
+
}
|
|
230
|
+
async projectsOf(grantee) {
|
|
231
|
+
const result = await this.attestationsTo('Project', grantee);
|
|
232
|
+
if (!result.length)
|
|
233
|
+
return [];
|
|
234
|
+
const projects = Attestation_1.Attestation.fromInterface(result);
|
|
235
|
+
return this.projectsDetails(projects);
|
|
236
|
+
}
|
|
237
|
+
async grantee(address) {
|
|
238
|
+
const projects = await this.projectsOf(address);
|
|
239
|
+
return new attestations_1.Grantee(address, projects);
|
|
240
|
+
}
|
|
241
|
+
async grantees() {
|
|
242
|
+
const projects = await this.projects();
|
|
243
|
+
return projects.reduce((acc, item) => {
|
|
244
|
+
const hasGrantee = acc.find((g) => g.address === item.recipient);
|
|
245
|
+
if (hasGrantee)
|
|
246
|
+
hasGrantee.projects.push(item);
|
|
247
|
+
else
|
|
248
|
+
acc.push(new attestations_1.Grantee(item.recipient, [item]));
|
|
249
|
+
return acc;
|
|
250
|
+
}, []);
|
|
251
|
+
}
|
|
252
|
+
async grantsOf(grantee, withCommunity) {
|
|
253
|
+
const [grant, grantDetails, grantVerified] = GapSchema_1.GapSchema.findMany([
|
|
254
|
+
'Grant',
|
|
255
|
+
'GrantDetails',
|
|
256
|
+
'GrantVerified',
|
|
257
|
+
]);
|
|
258
|
+
const query = gql_queries_1.gqlQueries.attestationsTo(grant.uid, grantee);
|
|
259
|
+
const { schema: { attestations }, } = await this.query(query);
|
|
260
|
+
const grants = Attestation_1.Attestation.fromInterface(attestations);
|
|
261
|
+
if (!grants.length)
|
|
262
|
+
return [];
|
|
263
|
+
const ref = gql_queries_1.gqlQueries.dependentsOf(grants.map((g) => g.uid), [grantDetails.uid, grantVerified.uid], grants.map((g) => g.recipient));
|
|
264
|
+
const results = await this.query(ref);
|
|
265
|
+
const deps = Attestation_1.Attestation.fromInterface(results.attestations || []);
|
|
266
|
+
const milestones = await this.milestonesOf(grants);
|
|
267
|
+
const communities = withCommunity
|
|
268
|
+
? await this.communitiesByIds((0, utils_1.mapFilter)(grants, (g) => !!g.communityUID, (g) => g.communityUID))
|
|
269
|
+
: [];
|
|
270
|
+
const withDetails = grants.map((grant) => {
|
|
271
|
+
const refs = deps.filter((ref) => ref.refUID === grant.uid);
|
|
272
|
+
grant.verified = !!refs.find((ref) => ref.schema.uid === grantVerified.uid && ref.refUID === grant.uid);
|
|
273
|
+
grant.details = (refs.find((ref) => ref.schema.uid === grantDetails.uid &&
|
|
274
|
+
ref.refUID === grant.uid &&
|
|
275
|
+
typeof ref.endsAt === 'undefined'));
|
|
276
|
+
grant.milestones = milestones.filter((m) => m.refUID === grant.uid && typeof m.endsAt !== 'undefined');
|
|
277
|
+
grant.community = communities.find((c) => c.uid === grant.communityUID);
|
|
278
|
+
return grant;
|
|
279
|
+
});
|
|
280
|
+
return this.grantsUpdates(withDetails);
|
|
281
|
+
}
|
|
282
|
+
async grantsUpdates(grants) {
|
|
283
|
+
const details = GapSchema_1.GapSchema.find('GrantDetails');
|
|
284
|
+
const query = gql_queries_1.gqlQueries.attestationsOf(details.uid, this.getSearchFieldString('type', 'grant-update'), grants.map((g) => g.uid));
|
|
285
|
+
const { schema: { attestations }, } = await this.query(query);
|
|
286
|
+
const updates = Attestation_1.Attestation.fromInterface(attestations);
|
|
287
|
+
return grants.map((grant) => {
|
|
288
|
+
grant.updates = updates.filter((u) => u.refUID === grant.uid);
|
|
289
|
+
return grant;
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
async grantsByCommunity(uid) {
|
|
293
|
+
const [grant, grantDetails, project, projectDetails] = GapSchema_1.GapSchema.findMany([
|
|
294
|
+
'Grant',
|
|
295
|
+
'GrantDetails',
|
|
296
|
+
'Project',
|
|
297
|
+
'ProjectDetails',
|
|
298
|
+
]);
|
|
299
|
+
const query = gql_queries_1.gqlQueries.attestations(grant.uid, uid);
|
|
300
|
+
const { schema: { attestations }, } = await this.query(query);
|
|
301
|
+
const grants = Attestation_1.Attestation.fromInterface(attestations).map((g) => new entities_1.Grant(g));
|
|
302
|
+
if (!grants.length)
|
|
303
|
+
return [];
|
|
304
|
+
const refs = gql_queries_1.gqlQueries.dependentsOf(grants.map((g) => [g.uid, g.refUID]).flat(), [grantDetails.uid, project.uid]);
|
|
305
|
+
const results = await this.query(refs);
|
|
306
|
+
const deps = Attestation_1.Attestation.fromInterface(results.attestations || []);
|
|
307
|
+
const projectsQuery = gql_queries_1.gqlQueries.attestationsIn(grants.map((g) => g.refUID));
|
|
308
|
+
const { attestations: projectAttestations } = await this.query(projectsQuery);
|
|
309
|
+
const projects = Attestation_1.Attestation.fromInterface(projectAttestations);
|
|
310
|
+
const milestones = await this.milestonesOf(grants);
|
|
311
|
+
return grants
|
|
312
|
+
.map((grant) => {
|
|
313
|
+
grant.project = projects.find((p) => p.uid === grant.refUID);
|
|
314
|
+
grant.details = (deps.find((d) => d.refUID === grant.uid &&
|
|
315
|
+
d.schema.uid === grantDetails.uid &&
|
|
316
|
+
typeof d.amount !== undefined &&
|
|
317
|
+
typeof d.endsAt === 'undefined' &&
|
|
318
|
+
typeof d.data.type === 'undefined'));
|
|
319
|
+
grant.milestones = milestones
|
|
320
|
+
.filter((m) => m.refUID === grant.uid && typeof m.endsAt !== 'undefined')
|
|
321
|
+
.sort((a, b) => a.endsAt - b.endsAt);
|
|
322
|
+
grant.updates = deps.filter((d) => d.data.type && d.refUID === grant.uid);
|
|
323
|
+
return grant;
|
|
324
|
+
})
|
|
325
|
+
.filter((g) => !!g.project);
|
|
326
|
+
}
|
|
327
|
+
async grantsFor(projects, withCommunity) {
|
|
328
|
+
const [grant, grantDetails] = GapSchema_1.GapSchema.findMany([
|
|
329
|
+
'Grant',
|
|
330
|
+
'GrantDetails',
|
|
331
|
+
'Milestone',
|
|
332
|
+
'MilestoneApproved',
|
|
333
|
+
'MilestoneCompleted',
|
|
334
|
+
]);
|
|
335
|
+
const query = gql_queries_1.gqlQueries.dependentsOf(projects.map((p) => p.uid), [grant.uid]);
|
|
336
|
+
const { attestations: grants } = await this.query(query);
|
|
337
|
+
const grantsWithDetails = Attestation_1.Attestation.fromInterface(grants).map((g) => new entities_1.Grant(g));
|
|
338
|
+
const ref = gql_queries_1.gqlQueries.dependentsOf(grants.map((g) => g.uid), [grantDetails.uid]);
|
|
339
|
+
const { attestations } = await this.query(ref);
|
|
340
|
+
const milestones = await this.milestonesOf(grantsWithDetails);
|
|
341
|
+
const deps = Attestation_1.Attestation.fromInterface(attestations);
|
|
342
|
+
// TODO unify this with grantsOf
|
|
343
|
+
grantsWithDetails.forEach((grant) => {
|
|
344
|
+
grant.details = (deps.find((d) => d.refUID === grant.uid &&
|
|
345
|
+
d.schema.uid === grantDetails.uid &&
|
|
346
|
+
typeof d.amount !== undefined &&
|
|
347
|
+
typeof d.endsAt === 'undefined' &&
|
|
348
|
+
typeof d.data.type === 'undefined'));
|
|
349
|
+
grant.milestones = milestones
|
|
350
|
+
.filter((m) => m.refUID === grant.uid && typeof m.endsAt !== 'undefined')
|
|
351
|
+
.sort((a, b) => a.endsAt - b.endsAt);
|
|
352
|
+
});
|
|
353
|
+
const communities = withCommunity
|
|
354
|
+
? await this.communitiesByIds((0, utils_1.mapFilter)(grantsWithDetails, (g) => !!g.communityUID, (g) => g.communityUID))
|
|
355
|
+
: [];
|
|
356
|
+
grantsWithDetails.forEach((grant) => {
|
|
357
|
+
grant.community = communities.find((c) => c.uid === grant.communityUID);
|
|
358
|
+
});
|
|
359
|
+
const grantsWithUpdates = await this.grantsUpdates(grantsWithDetails);
|
|
360
|
+
return grantsWithUpdates.sort((a, b) => a.milestones?.at(-1)?.endsAt - b.milestones?.at(-1)?.endsAt ||
|
|
361
|
+
a.createdAt.getTime() - b.createdAt.getTime());
|
|
362
|
+
}
|
|
363
|
+
async milestonesOf(grants) {
|
|
364
|
+
const [milestone, milestoneApproved, milestoneCompleted] = GapSchema_1.GapSchema.findMany([
|
|
365
|
+
'Milestone',
|
|
366
|
+
'MilestoneApproved',
|
|
367
|
+
'MilestoneCompleted',
|
|
368
|
+
]);
|
|
369
|
+
const query = gql_queries_1.gqlQueries.dependentsOf(grants.map((g) => g.uid), [milestone.uid]);
|
|
370
|
+
const { attestations } = await this.query(query);
|
|
371
|
+
const milestones = Attestation_1.Attestation.fromInterface(attestations)
|
|
372
|
+
.map((milestone) => new entities_1.Milestone(milestone))
|
|
373
|
+
.filter((m) => typeof m.endsAt !== 'undefined');
|
|
374
|
+
if (!milestones.length)
|
|
375
|
+
return [];
|
|
376
|
+
const ref = gql_queries_1.gqlQueries.dependentsOf(milestones.map((m) => m.uid), [milestoneApproved.uid, milestoneCompleted.uid]);
|
|
377
|
+
const results = await this.query(ref);
|
|
378
|
+
const deps = Attestation_1.Attestation.fromInterface(results.attestations || []);
|
|
379
|
+
return milestones.map((milestone) => {
|
|
380
|
+
const refs = deps.filter((ref) => ref.refUID === milestone.uid);
|
|
381
|
+
milestone.endsAt = (0, to_unix_1.toUnix)(milestone.endsAt);
|
|
382
|
+
milestone.completed = refs.find((dep) => dep.type === 'completed' && dep.refUID === milestone.uid);
|
|
383
|
+
milestone.approved = refs.find((dep) => dep.type === 'approved' && dep.refUID === milestone.uid);
|
|
384
|
+
milestone.rejected = refs.find((dep) => dep.type === 'rejected' && dep.refUID === milestone.uid);
|
|
385
|
+
return milestone;
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
async membersOf(projects) {
|
|
389
|
+
const [member, memberDetails] = GapSchema_1.GapSchema.findMany([
|
|
390
|
+
'MemberOf',
|
|
391
|
+
'MemberDetails',
|
|
392
|
+
]);
|
|
393
|
+
if (!projects.length)
|
|
394
|
+
return [];
|
|
395
|
+
const query = gql_queries_1.gqlQueries.dependentsOf(projects.map((p) => p.uid), [member.uid], projects.map((p) => p.attester));
|
|
396
|
+
const results = await this.query(query);
|
|
397
|
+
const members = Attestation_1.Attestation.fromInterface(results.attestations || []);
|
|
398
|
+
if (members.length) {
|
|
399
|
+
const ref = gql_queries_1.gqlQueries.dependentsOf(members.map((a) => a.uid), [memberDetails.uid], members.map((a) => a.attester));
|
|
400
|
+
const detailsResult = await this.query(ref);
|
|
401
|
+
const detailsRef = Attestation_1.Attestation.fromInterface(detailsResult.attestations || []);
|
|
402
|
+
members.forEach((member) => {
|
|
403
|
+
member.details = detailsRef.find((d) => d.refUID === member.uid);
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
return members;
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Returns a string to be used to search by a value in `decodedDataJson`.
|
|
410
|
+
* @param field
|
|
411
|
+
* @param value
|
|
412
|
+
*/
|
|
413
|
+
getSearchFieldString(field, value) {
|
|
414
|
+
return [
|
|
415
|
+
String.raw `\\\\\"${field}\\\\\":\\\\\"${value}\\\\\"`,
|
|
416
|
+
String.raw `\\\\\"${field}\\\\\": \\\\\"${value}\\\\\"`,
|
|
417
|
+
];
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
exports.GapEasClient = GapEasClient;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./AxiosGQL"), exports);
|
|
18
|
+
__exportStar(require("./EASClient"), exports);
|
|
19
|
+
__exportStar(require("./GapEasClient"), exports);
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { SchemaEncoder, SchemaItem, SchemaValue } from "@ethereum-attestation-service/eas-sdk";
|
|
2
|
+
import { AttestArgs, Hex, MultiRevokeArgs, SchemaInterface, SignerOrProvider } from "../types";
|
|
3
|
+
import { Attestation } from "./Attestation";
|
|
4
|
+
/**
|
|
5
|
+
* Represents the EAS Schema and provides methods to encode and decode the schema,
|
|
6
|
+
* and validate the schema references.
|
|
7
|
+
*
|
|
8
|
+
* Also provides a set of static methods to manage the schema list.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```
|
|
12
|
+
* // You may or not attribute a schema to a variable.
|
|
13
|
+
* new Schema({
|
|
14
|
+
* name: "Grantee",
|
|
15
|
+
* schema: [{ type: "bool", name: "grantee", value: true }],
|
|
16
|
+
* uid: "0x000000000
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* const granteeDetails = new Schema({
|
|
20
|
+
* name: "GranteeDetails",
|
|
21
|
+
* schema: [
|
|
22
|
+
* { type: "bool", name: "name", value: null }
|
|
23
|
+
* { type: "bool", name: "description", value: null }
|
|
24
|
+
* { type: "bool", name: "imageURL", value: null }
|
|
25
|
+
* ],
|
|
26
|
+
* uid: "0x000000000,
|
|
27
|
+
* references: "Grantee"
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* // Validate if references are correct and all of them exist.
|
|
31
|
+
* Schema.validate();
|
|
32
|
+
*
|
|
33
|
+
* // Gets the schema by name.
|
|
34
|
+
* const grantee = Schema.get("Grantee");
|
|
35
|
+
*
|
|
36
|
+
* // Sets a single schema value.
|
|
37
|
+
* grantee.setValue("grantee", true);
|
|
38
|
+
*
|
|
39
|
+
* // Sets multiple schema values.
|
|
40
|
+
* granteeDetails.setValues({ name: "John Doe", description: "A description", imageURL: "https://example.com/image.png" });
|
|
41
|
+
*
|
|
42
|
+
* // Gets the schema encoded data, used to create an attestation.
|
|
43
|
+
* const encodedGrantee = grantee.encode();
|
|
44
|
+
*
|
|
45
|
+
* // Verify if schema exists
|
|
46
|
+
* Schema.exists("Grantee"); // true
|
|
47
|
+
* Schema.exists("GranteeDetails"); // true
|
|
48
|
+
* Schema.exists("GranteeDetails2"); // false
|
|
49
|
+
*
|
|
50
|
+
* // Get all schemas.
|
|
51
|
+
* Schema.getAll(); // [grantee, granteeDetails]
|
|
52
|
+
*
|
|
53
|
+
* // Get all schema names.
|
|
54
|
+
* Schema.getNames(); // ["Grantee", "GranteeDetails"]
|
|
55
|
+
*
|
|
56
|
+
* // Get many schemas by name. Throws an error if schema does not exist.
|
|
57
|
+
* Schema.getMany(["Grantee", "GranteeDetails"]); // [grantee, granteeDetails]
|
|
58
|
+
*
|
|
59
|
+
* // Replace all schemas. Throws an error if schema does not exist.
|
|
60
|
+
* Schema.replaceAll([grantee, granteeDetails]);
|
|
61
|
+
*
|
|
62
|
+
* // Replace one schema. This will replace a schema using the inbound schema name.. Throws an error if schema does not exist.
|
|
63
|
+
* Schema.replaceOne(grantee);
|
|
64
|
+
*
|
|
65
|
+
* // Converts a raw schema string (e.g. "uint256 id, string name") to a SchemaItem[].
|
|
66
|
+
* const schema = Schema.rawToObject("uint256 id, string name");
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export declare abstract class Schema<T extends string = string> implements SchemaInterface<T> {
|
|
70
|
+
protected static schemas: Schema[];
|
|
71
|
+
protected encoder: SchemaEncoder;
|
|
72
|
+
private _schema;
|
|
73
|
+
readonly uid: Hex;
|
|
74
|
+
readonly name: string;
|
|
75
|
+
readonly revocable?: boolean;
|
|
76
|
+
readonly references?: T;
|
|
77
|
+
/**
|
|
78
|
+
* Creates a new schema instance
|
|
79
|
+
* @param args
|
|
80
|
+
* @param strict If true, will throw an error if schema reference is not valid. With this option, user should add schemas
|
|
81
|
+
* in a strict order.
|
|
82
|
+
*/
|
|
83
|
+
constructor(args: SchemaInterface<T>, strict?: boolean, ignoreSchema?: boolean);
|
|
84
|
+
/**
|
|
85
|
+
* Encode the schema to be used as payload in the attestation
|
|
86
|
+
* @returns
|
|
87
|
+
*/
|
|
88
|
+
encode(schema?: SchemaItem[]): string;
|
|
89
|
+
/**
|
|
90
|
+
* Set a schema field value.
|
|
91
|
+
* @param key
|
|
92
|
+
* @param value
|
|
93
|
+
*/
|
|
94
|
+
setValue(key: string, value: SchemaValue): void;
|
|
95
|
+
/**
|
|
96
|
+
* Tests if the current schema is a JSON Schema.
|
|
97
|
+
*
|
|
98
|
+
* @returns boolean
|
|
99
|
+
*/
|
|
100
|
+
isJsonSchema(): boolean;
|
|
101
|
+
private assertField;
|
|
102
|
+
/**
|
|
103
|
+
* Asserts if schema is valid.
|
|
104
|
+
* > Does not check references if `strict = false`. To check references use `Schema.validate()`
|
|
105
|
+
* @param args
|
|
106
|
+
*/
|
|
107
|
+
protected assert(args: SchemaInterface, strict?: boolean): void;
|
|
108
|
+
/**
|
|
109
|
+
* Attest off chain data
|
|
110
|
+
* @returns
|
|
111
|
+
*/
|
|
112
|
+
attestOffchain({ data, signer, to, refUID }: AttestArgs): Promise<import("@ethereum-attestation-service/eas-sdk").SignedOffchainAttestation>;
|
|
113
|
+
/**
|
|
114
|
+
* Revokes one off chain attestation by its UID.
|
|
115
|
+
* @param uid
|
|
116
|
+
* @param signer
|
|
117
|
+
* @returns
|
|
118
|
+
*/
|
|
119
|
+
revokeOffchain(uid: Hex, signer: SignerOrProvider): Promise<import("@ethereum-attestation-service/eas-sdk/dist/transaction").Transaction<bigint>>;
|
|
120
|
+
/**
|
|
121
|
+
* Revokes multiple off chain attestations by their UIDs.
|
|
122
|
+
* @param uids
|
|
123
|
+
* @param signer
|
|
124
|
+
* @returns
|
|
125
|
+
*/
|
|
126
|
+
multiRevokeOffchain(uids: Hex[], signer: SignerOrProvider): Promise<import("@ethereum-attestation-service/eas-sdk/dist/transaction").Transaction<bigint[]>>;
|
|
127
|
+
/**
|
|
128
|
+
* Attest for a schema.
|
|
129
|
+
* @param param0
|
|
130
|
+
* @returns
|
|
131
|
+
*/
|
|
132
|
+
attest<T>({ data, to, signer, refUID }: AttestArgs<T>): Promise<Hex>;
|
|
133
|
+
/**
|
|
134
|
+
* Bulk attest a set of attestations.
|
|
135
|
+
* @param signer
|
|
136
|
+
* @param entities
|
|
137
|
+
* @returns
|
|
138
|
+
*/
|
|
139
|
+
multiAttest(signer: SignerOrProvider, entities?: Attestation[]): Promise<string[]>;
|
|
140
|
+
/**
|
|
141
|
+
* Revokes a set of attestations by their UIDs.
|
|
142
|
+
* @param signer
|
|
143
|
+
* @param uids
|
|
144
|
+
* @returns
|
|
145
|
+
*/
|
|
146
|
+
multiRevoke(signer: SignerOrProvider, toRevoke: MultiRevokeArgs[]): Promise<void>;
|
|
147
|
+
static exists(name: string): Schema<string>;
|
|
148
|
+
/**
|
|
149
|
+
* Adds the schema signature to a shares list. Use Schema.get("SchemaName") to get the schema.
|
|
150
|
+
*
|
|
151
|
+
* __Note that this will make the schema available to all instances
|
|
152
|
+
* of the class AND its data can be overriden by any changes.__
|
|
153
|
+
* @param schemas
|
|
154
|
+
*/
|
|
155
|
+
static add<T extends Schema>(...schemas: T[]): void;
|
|
156
|
+
static getAll<T extends Schema>(): T[];
|
|
157
|
+
static get<N extends string, T extends Schema>(name: N): T;
|
|
158
|
+
/**
|
|
159
|
+
* Find many schemas by name and return them as an array in the same order.
|
|
160
|
+
* @param names
|
|
161
|
+
* @returns
|
|
162
|
+
*/
|
|
163
|
+
static getMany<N extends string, T extends Schema>(names: N[]): T[];
|
|
164
|
+
static getNames(): string[];
|
|
165
|
+
/**
|
|
166
|
+
* Validade references
|
|
167
|
+
* @throws {SchemaError} if any reference is not valid
|
|
168
|
+
* @returns {true} if references are valid
|
|
169
|
+
*/
|
|
170
|
+
static validate(): true;
|
|
171
|
+
/**
|
|
172
|
+
* Replaces the schema list with a new list.
|
|
173
|
+
* @param schemas
|
|
174
|
+
*/
|
|
175
|
+
static replaceAll(schemas: Schema[]): void;
|
|
176
|
+
/**
|
|
177
|
+
* Replaces a schema from the schema list.
|
|
178
|
+
* @throws {SchemaError} if desired schema name does not exist.
|
|
179
|
+
*/
|
|
180
|
+
static replaceOne(schema: Schema): void;
|
|
181
|
+
/**
|
|
182
|
+
* Transforms the given raw schema to SchemaItem[]
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* ```
|
|
186
|
+
* const schema = Schema.rawToObject("uint256 id, string name");
|
|
187
|
+
* // schema = [{ type: "uint256", name: "id", value: null }, { type: "string", name: "name", value: null }]
|
|
188
|
+
* ```
|
|
189
|
+
* @param abi
|
|
190
|
+
* @returns
|
|
191
|
+
*/
|
|
192
|
+
static rawToObject(abi: string): SchemaItem[];
|
|
193
|
+
/**
|
|
194
|
+
* Returns the raw schema string.
|
|
195
|
+
* @example
|
|
196
|
+
* ```ts
|
|
197
|
+
* const schema = new Schema({ name: "Grantee", schema: [{ type: "bool", name: "grantee", value: true }], uid: "0x000000000" });
|
|
198
|
+
* schema.raw; // "bool grantee"
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
get raw(): string;
|
|
202
|
+
get schema(): SchemaItem[];
|
|
203
|
+
/**
|
|
204
|
+
* Get all schemas that references this schema. Note that this
|
|
205
|
+
* will return a reference to the original schema and all
|
|
206
|
+
* the changes made to it will reflect the original instance.
|
|
207
|
+
*/
|
|
208
|
+
get children(): Schema<string>[];
|
|
209
|
+
/**
|
|
210
|
+
* Asserts and sets the schema value.
|
|
211
|
+
*/
|
|
212
|
+
set schema(schema: SchemaItem[]);
|
|
213
|
+
}
|