@show-karma/karma-gap-sdk 0.3.43 → 0.3.44
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/class/Attestation.d.ts +3 -2
- package/core/class/Attestation.js +11 -8
- package/core/class/GAP.d.ts +1 -1
- package/core/class/GapSchema.js +1 -0
- package/core/class/GraphQL/GapEasClient.d.ts +7 -7
- package/core/class/GraphQL/GapEasClient.js +60 -60
- package/core/class/Schema.d.ts +12 -3
- package/core/class/Schema.js +31 -10
- package/core/class/SchemaError.d.ts +2 -1
- package/core/class/SchemaError.js +4 -3
- package/core/class/contract/GapContract.d.ts +11 -6
- package/core/class/contract/GapContract.js +35 -6
- package/core/class/entities/Community.d.ts +2 -2
- package/core/class/entities/Community.js +9 -3
- package/core/class/entities/Grant.d.ts +11 -11
- package/core/class/entities/Grant.js +25 -21
- package/core/class/entities/GrantUpdate.d.ts +8 -2
- package/core/class/entities/GrantUpdate.js +29 -6
- package/core/class/entities/MemberOf.d.ts +2 -2
- package/core/class/entities/MemberOf.js +4 -2
- package/core/class/entities/Milestone.d.ts +14 -7
- package/core/class/entities/Milestone.js +60 -21
- package/core/class/entities/Project.d.ts +3 -3
- package/core/class/entities/Project.js +12 -7
- package/core/class/entities/ProjectImpact.d.ts +6 -2
- package/core/class/entities/ProjectImpact.js +23 -6
- package/core/class/entities/ProjectUpdate.d.ts +2 -2
- package/core/class/entities/ProjectUpdate.js +21 -5
- package/core/class/karma-indexer/api/types.d.ts +1 -0
- package/core/class/types/attestations.d.ts +8 -1
- package/core/consts.js +189 -45
- package/core/types.d.ts +9 -0
- package/package.json +1 -1
|
@@ -2,6 +2,7 @@ import { Hex, IAttestation, JSONStr, MultiAttestData, SignerOrProvider, TNetwork
|
|
|
2
2
|
import { Schema } from "./Schema";
|
|
3
3
|
import { SchemaItem, SchemaValue } from "@ethereum-attestation-service/eas-sdk";
|
|
4
4
|
import { GapSchema } from "./GapSchema";
|
|
5
|
+
import { AttestationWithTx } from "./types/attestations";
|
|
5
6
|
export interface AttestationArgs<T = unknown, S extends Schema = Schema> {
|
|
6
7
|
data: T | string;
|
|
7
8
|
schema: S;
|
|
@@ -88,7 +89,7 @@ export declare class Attestation<T = unknown, S extends Schema = GapSchema> impl
|
|
|
88
89
|
* @param signer
|
|
89
90
|
* @returns
|
|
90
91
|
*/
|
|
91
|
-
revoke(signer: SignerOrProvider, callback?: Function): Promise<
|
|
92
|
+
revoke(signer: SignerOrProvider, callback?: Function): Promise<AttestationWithTx>;
|
|
92
93
|
/**
|
|
93
94
|
* Attests the data using the specified signer and schema.
|
|
94
95
|
* @param signer - The signer or provider to use for attestation.
|
|
@@ -96,7 +97,7 @@ export declare class Attestation<T = unknown, S extends Schema = GapSchema> impl
|
|
|
96
97
|
* @returns A Promise that resolves to the UID of the attestation.
|
|
97
98
|
* @throws An `AttestationError` if an error occurs during attestation.
|
|
98
99
|
*/
|
|
99
|
-
attest(signer: SignerOrProvider, ...args: unknown[]): Promise<
|
|
100
|
+
attest(signer: SignerOrProvider, ...args: unknown[]): Promise<AttestationWithTx>;
|
|
100
101
|
/**
|
|
101
102
|
* Validates the payload.
|
|
102
103
|
*
|
|
@@ -104,7 +104,7 @@ class Attestation {
|
|
|
104
104
|
async revoke(signer, callback) {
|
|
105
105
|
try {
|
|
106
106
|
callback?.("preparing");
|
|
107
|
-
|
|
107
|
+
const { tx } = await GapContract_1.GapContract.multiRevoke(signer, [
|
|
108
108
|
{
|
|
109
109
|
data: [
|
|
110
110
|
{
|
|
@@ -114,13 +114,15 @@ class Attestation {
|
|
|
114
114
|
],
|
|
115
115
|
schema: this.schema.uid,
|
|
116
116
|
},
|
|
117
|
-
]).then(() => {
|
|
117
|
+
]).then((res) => {
|
|
118
118
|
callback?.("confirmed");
|
|
119
|
+
return res;
|
|
119
120
|
});
|
|
121
|
+
return { tx, uids: [this.uid] };
|
|
120
122
|
}
|
|
121
123
|
catch (error) {
|
|
122
124
|
console.error(error);
|
|
123
|
-
throw new SchemaError_1.SchemaError("REVOKE_ERROR", "Error revoking attestation.");
|
|
125
|
+
throw new SchemaError_1.SchemaError("REVOKE_ERROR", "Error revoking attestation.", error);
|
|
124
126
|
}
|
|
125
127
|
}
|
|
126
128
|
/**
|
|
@@ -136,19 +138,20 @@ class Attestation {
|
|
|
136
138
|
: null;
|
|
137
139
|
console.log(`Attesting ${this.schema.name}`);
|
|
138
140
|
try {
|
|
139
|
-
const
|
|
141
|
+
const { tx, uids } = await this.schema.attest({
|
|
140
142
|
data: this.data,
|
|
141
143
|
to: this.recipient,
|
|
142
144
|
refUID: this.refUID,
|
|
143
145
|
signer,
|
|
144
146
|
callback: callback,
|
|
145
147
|
});
|
|
146
|
-
this._uid =
|
|
147
|
-
console.log(`Attested ${this.schema.name} with UID ${uid}`);
|
|
148
|
+
this._uid = uids[0];
|
|
149
|
+
console.log(`Attested ${this.schema.name} with UID ${this.uid}`);
|
|
150
|
+
return { tx, uids };
|
|
148
151
|
}
|
|
149
152
|
catch (error) {
|
|
150
153
|
console.error(error);
|
|
151
|
-
throw new SchemaError_1.AttestationError("ATTEST_ERROR", "Error during attestation.");
|
|
154
|
+
throw new SchemaError_1.AttestationError("ATTEST_ERROR", "Error during attestation.", error);
|
|
152
155
|
}
|
|
153
156
|
}
|
|
154
157
|
/**
|
|
@@ -255,7 +258,7 @@ class Attestation {
|
|
|
255
258
|
}
|
|
256
259
|
catch (error) {
|
|
257
260
|
console.error(error);
|
|
258
|
-
throw new SchemaError_1.SchemaError("INVALID_DATA", "Data must be a valid JSON string.");
|
|
261
|
+
throw new SchemaError_1.SchemaError("INVALID_DATA", "Data must be a valid JSON string.", error);
|
|
259
262
|
}
|
|
260
263
|
}
|
|
261
264
|
/**
|
package/core/class/GAP.d.ts
CHANGED
|
@@ -167,7 +167,7 @@ export declare class GAP extends Facade {
|
|
|
167
167
|
*/
|
|
168
168
|
attest<T>(attestation: AttestArgs<T> & {
|
|
169
169
|
schemaName: TSchemaName;
|
|
170
|
-
}): Promise
|
|
170
|
+
}): Promise<import("..").AttestationWithTx>;
|
|
171
171
|
/**
|
|
172
172
|
* Replaces the schema list with a new list.
|
|
173
173
|
* @param schemas
|
package/core/class/GapSchema.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Attestation } from
|
|
2
|
-
import { EASNetworkConfig, Hex, IAttestation, TNetwork, TSchemaName } from
|
|
3
|
-
import { Grantee } from
|
|
4
|
-
import { GapSchema } from
|
|
5
|
-
import { Grant, Milestone, Project, MemberOf } from
|
|
6
|
-
import { Community } from
|
|
7
|
-
import { Fetcher } from
|
|
1
|
+
import { Attestation } from "../Attestation";
|
|
2
|
+
import { EASNetworkConfig, Hex, IAttestation, TNetwork, TSchemaName } from "../../types";
|
|
3
|
+
import { Grantee } from "../types/attestations";
|
|
4
|
+
import { GapSchema } from "../GapSchema";
|
|
5
|
+
import { Grant, Milestone, Project, MemberOf } from "../entities";
|
|
6
|
+
import { Community } from "../entities/Community";
|
|
7
|
+
import { Fetcher } from "../Fetcher";
|
|
8
8
|
interface EASClientProps {
|
|
9
9
|
network: TNetwork;
|
|
10
10
|
}
|
|
@@ -28,7 +28,7 @@ class GapEasClient extends Fetcher_1.Fetcher {
|
|
|
28
28
|
const query = gql_queries_1.gqlQueries.schemata(owner);
|
|
29
29
|
const { schemata } = await this.query(query);
|
|
30
30
|
return schemata.map((schema) => new GapSchema_1.GapSchema({
|
|
31
|
-
name:
|
|
31
|
+
name: "",
|
|
32
32
|
schema: Schema_1.Schema.rawToObject(schema.schema),
|
|
33
33
|
uid: schema.uid,
|
|
34
34
|
}, this.gap));
|
|
@@ -65,15 +65,15 @@ class GapEasClient extends Fetcher_1.Fetcher {
|
|
|
65
65
|
const parent = this.gap.findSchema(parentSchema);
|
|
66
66
|
const children = parent.children.map((c) => c.uid);
|
|
67
67
|
if (!children.length)
|
|
68
|
-
throw new SchemaError_1.SchemaError(
|
|
68
|
+
throw new SchemaError_1.SchemaError("INVALID_REFERENCE", `Schema ${parentSchema} has no children.`);
|
|
69
69
|
const query = gql_queries_1.gqlQueries.dependentsOf(parentUid, children);
|
|
70
70
|
const { attestations } = await this.query(query);
|
|
71
71
|
return Attestation_1.Attestation.fromInterface(attestations, this.network.name);
|
|
72
72
|
}
|
|
73
73
|
async communities(search) {
|
|
74
74
|
const [community, communityDetails] = this.gap.findManySchemas([
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
"Community",
|
|
76
|
+
"CommunityDetails",
|
|
77
77
|
]);
|
|
78
78
|
const query = gql_queries_1.gqlQueries.attestationsOf(community.uid, search);
|
|
79
79
|
const { schema: { attestations }, } = await this.query(query);
|
|
@@ -83,7 +83,7 @@ class GapEasClient extends Fetcher_1.Fetcher {
|
|
|
83
83
|
return this.communitiesDetails(communities);
|
|
84
84
|
}
|
|
85
85
|
async communitiesOf(address) {
|
|
86
|
-
const [community] = this.gap.findManySchemas([
|
|
86
|
+
const [community] = this.gap.findManySchemas(["Community"]);
|
|
87
87
|
const query = gql_queries_1.gqlQueries.attestationsTo(community.uid, address);
|
|
88
88
|
const { schema: { attestations }, } = await this.query(query);
|
|
89
89
|
const communities = Attestation_1.Attestation.fromInterface(attestations, this.network.name);
|
|
@@ -92,7 +92,7 @@ class GapEasClient extends Fetcher_1.Fetcher {
|
|
|
92
92
|
return this.communitiesDetails(communities);
|
|
93
93
|
}
|
|
94
94
|
async communitiesAdminOf(address) {
|
|
95
|
-
const [community] = this.gap.findManySchemas([
|
|
95
|
+
const [community] = this.gap.findManySchemas(["Community"]);
|
|
96
96
|
const query = gql_queries_1.gqlQueries.attestationsTo(community.uid, address);
|
|
97
97
|
const { schema: { attestations }, } = await this.query(query);
|
|
98
98
|
const communities = Attestation_1.Attestation.fromInterface(attestations, this.network.name);
|
|
@@ -103,7 +103,7 @@ class GapEasClient extends Fetcher_1.Fetcher {
|
|
|
103
103
|
async communitiesByIds(uids) {
|
|
104
104
|
if (!uids.length)
|
|
105
105
|
return [];
|
|
106
|
-
const communityDetails = this.gap.findSchema(
|
|
106
|
+
const communityDetails = this.gap.findSchema("CommunityDetails");
|
|
107
107
|
const communityQuery = gql_queries_1.gqlQueries.attestationsIn(uids);
|
|
108
108
|
const detailsQuery = gql_queries_1.gqlQueries.dependentsOf(uids, [communityDetails.uid]);
|
|
109
109
|
try {
|
|
@@ -124,8 +124,8 @@ class GapEasClient extends Fetcher_1.Fetcher {
|
|
|
124
124
|
}
|
|
125
125
|
async communitiesDetails(communities) {
|
|
126
126
|
const [project, communityDetails] = this.gap.findManySchemas([
|
|
127
|
-
|
|
128
|
-
|
|
127
|
+
"Project",
|
|
128
|
+
"CommunityDetails",
|
|
129
129
|
]);
|
|
130
130
|
const ref = gql_queries_1.gqlQueries.dependentsOf(communities.map((c) => c.uid), [communityDetails.uid]);
|
|
131
131
|
const results = await this.query(ref);
|
|
@@ -138,12 +138,12 @@ class GapEasClient extends Fetcher_1.Fetcher {
|
|
|
138
138
|
});
|
|
139
139
|
}
|
|
140
140
|
async communityBySlug(slug) {
|
|
141
|
-
const communitySchema = this.gap.findSchema(
|
|
142
|
-
const query = gql_queries_1.gqlQueries.attestationsOf(communitySchema.uid, this.getSearchFieldString(
|
|
141
|
+
const communitySchema = this.gap.findSchema("CommunityDetails");
|
|
142
|
+
const query = gql_queries_1.gqlQueries.attestationsOf(communitySchema.uid, this.getSearchFieldString("slug", slug));
|
|
143
143
|
try {
|
|
144
144
|
const { schema: { attestations }, } = await this.query(query);
|
|
145
145
|
if (!attestations.length)
|
|
146
|
-
throw new Error(
|
|
146
|
+
throw new Error("Community not found.");
|
|
147
147
|
const communities = (0, utils_1.mapFilter)(Attestation_1.Attestation.fromInterface(attestations, this.network.name), (details) => !!details.name, (details) => {
|
|
148
148
|
const community = new Community_1.Community({
|
|
149
149
|
data: { community: true },
|
|
@@ -156,7 +156,7 @@ class GapEasClient extends Fetcher_1.Fetcher {
|
|
|
156
156
|
});
|
|
157
157
|
const [withDetails] = await this.communitiesDetails(communities);
|
|
158
158
|
if (!withDetails)
|
|
159
|
-
throw new Error(
|
|
159
|
+
throw new Error("Community not found.");
|
|
160
160
|
const grants = await this.grantsByCommunity(withDetails.uid);
|
|
161
161
|
withDetails.grants = grants;
|
|
162
162
|
return withDetails;
|
|
@@ -169,11 +169,11 @@ class GapEasClient extends Fetcher_1.Fetcher {
|
|
|
169
169
|
const query = gql_queries_1.gqlQueries.attestation(uid);
|
|
170
170
|
const { attestation } = await this.query(query);
|
|
171
171
|
if (!attestation)
|
|
172
|
-
throw new Error(
|
|
172
|
+
throw new Error("Community not found.");
|
|
173
173
|
const communities = Attestation_1.Attestation.fromInterface([attestation], this.network.name).map((c) => new Community_1.Community(c));
|
|
174
174
|
const [withDetails] = await this.communitiesDetails(communities);
|
|
175
175
|
if (!withDetails)
|
|
176
|
-
throw new Error(
|
|
176
|
+
throw new Error("Community not found.");
|
|
177
177
|
const grants = await this.grantsByCommunity(uid);
|
|
178
178
|
withDetails.grants = grants;
|
|
179
179
|
return withDetails;
|
|
@@ -186,7 +186,7 @@ class GapEasClient extends Fetcher_1.Fetcher {
|
|
|
186
186
|
*/
|
|
187
187
|
async projectsDetails(projects) {
|
|
188
188
|
// Get projects array and fetch details, members, grants, etc then append to the project and return the array.
|
|
189
|
-
const [projectDetails] = this.gap.findManySchemas([
|
|
189
|
+
const [projectDetails] = this.gap.findManySchemas(["ProjectDetails"]);
|
|
190
190
|
const refQuery = gql_queries_1.gqlQueries.dependentsOf(projects.map((p) => p.uid), [projectDetails.uid]);
|
|
191
191
|
const [result, members, grants] = await Promise.all([
|
|
192
192
|
this.query(refQuery),
|
|
@@ -205,7 +205,7 @@ class GapEasClient extends Fetcher_1.Fetcher {
|
|
|
205
205
|
const query = gql_queries_1.gqlQueries.attestation(uid);
|
|
206
206
|
const { attestation } = await this.query(query);
|
|
207
207
|
if (!attestation)
|
|
208
|
-
throw new Error(
|
|
208
|
+
throw new Error("Project not found.");
|
|
209
209
|
const projectAttestation = Attestation_1.Attestation.fromInterface([attestation], this.network.name)[0];
|
|
210
210
|
const [result] = await this.projectsDetails([
|
|
211
211
|
new entities_1.Project(projectAttestation),
|
|
@@ -213,44 +213,44 @@ class GapEasClient extends Fetcher_1.Fetcher {
|
|
|
213
213
|
return result;
|
|
214
214
|
}
|
|
215
215
|
async projectBySlug(slug) {
|
|
216
|
-
const projectDetails = this.gap.findSchema(
|
|
217
|
-
const query = gql_queries_1.gqlQueries.attestationsOf(projectDetails.uid, this.getSearchFieldString(
|
|
216
|
+
const projectDetails = this.gap.findSchema("ProjectDetails");
|
|
217
|
+
const query = gql_queries_1.gqlQueries.attestationsOf(projectDetails.uid, this.getSearchFieldString("slug", slug));
|
|
218
218
|
const { schema: { attestations }, } = await this.query(query);
|
|
219
219
|
const projectAttestations = Attestation_1.Attestation.fromInterface(attestations, this.network.name).filter((p) => p.title);
|
|
220
220
|
if (!projectAttestations.length)
|
|
221
|
-
throw new Error(
|
|
221
|
+
throw new Error("Project not found.");
|
|
222
222
|
const project = new entities_1.Project({
|
|
223
223
|
data: { project: true },
|
|
224
224
|
uid: projectAttestations[0].refUID,
|
|
225
|
-
schema: this.gap.findSchema(
|
|
225
|
+
schema: this.gap.findSchema("Project"),
|
|
226
226
|
recipient: projectAttestations[0].recipient,
|
|
227
227
|
});
|
|
228
228
|
const [withDetails] = await this.projectsDetails([project]);
|
|
229
229
|
if (!withDetails)
|
|
230
|
-
throw new Error(
|
|
230
|
+
throw new Error("Project not found.");
|
|
231
231
|
return withDetails;
|
|
232
232
|
}
|
|
233
233
|
async slugExists(slug) {
|
|
234
|
-
const details = this.gap.findSchema(
|
|
235
|
-
const query = gql_queries_1.gqlQueries.attestationsOf(details.uid,
|
|
234
|
+
const details = this.gap.findSchema("ProjectDetails");
|
|
235
|
+
const query = gql_queries_1.gqlQueries.attestationsOf(details.uid, "slug");
|
|
236
236
|
const { schema: { attestations }, } = await this.query(query);
|
|
237
237
|
return attestations.some((a) => a.decodedDataJson.includes(slug));
|
|
238
238
|
}
|
|
239
239
|
search(query) {
|
|
240
|
-
throw new Error(
|
|
240
|
+
throw new Error("Method not implemented.");
|
|
241
241
|
}
|
|
242
242
|
searchProjects(query) {
|
|
243
|
-
throw new Error(
|
|
243
|
+
throw new Error("Method not implemented.");
|
|
244
244
|
}
|
|
245
245
|
async projects(name) {
|
|
246
|
-
const result = await this.attestations(
|
|
246
|
+
const result = await this.attestations("Project", name);
|
|
247
247
|
if (!result.length)
|
|
248
248
|
return [];
|
|
249
249
|
const projects = Attestation_1.Attestation.fromInterface(result, this.network.name);
|
|
250
250
|
return this.projectsDetails(projects);
|
|
251
251
|
}
|
|
252
252
|
async projectsOf(grantee) {
|
|
253
|
-
const result = await this.attestationsTo(
|
|
253
|
+
const result = await this.attestationsTo("Project", grantee);
|
|
254
254
|
if (!result.length)
|
|
255
255
|
return [];
|
|
256
256
|
const projects = Attestation_1.Attestation.fromInterface(result, this.network.name);
|
|
@@ -273,9 +273,9 @@ class GapEasClient extends Fetcher_1.Fetcher {
|
|
|
273
273
|
}
|
|
274
274
|
async grantsOf(grantee, withCommunity) {
|
|
275
275
|
const [grant, grantDetails, grantVerified] = this.gap.findManySchemas([
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
276
|
+
"Grant",
|
|
277
|
+
"GrantDetails",
|
|
278
|
+
"GrantVerified",
|
|
279
279
|
]);
|
|
280
280
|
const query = gql_queries_1.gqlQueries.attestationsTo(grant.uid, grantee);
|
|
281
281
|
const { schema: { attestations }, } = await this.query(query);
|
|
@@ -294,16 +294,16 @@ class GapEasClient extends Fetcher_1.Fetcher {
|
|
|
294
294
|
grant.verified = !!refs.find((ref) => ref.schema.uid === grantVerified.uid && ref.refUID === grant.uid);
|
|
295
295
|
grant.details = (refs.find((ref) => ref.schema.uid === grantDetails.uid &&
|
|
296
296
|
ref.refUID === grant.uid &&
|
|
297
|
-
typeof ref.endsAt ===
|
|
298
|
-
grant.milestones = milestones.filter((m) => m.refUID === grant.uid && typeof m.endsAt !==
|
|
297
|
+
typeof ref.endsAt === "undefined"));
|
|
298
|
+
grant.milestones = milestones.filter((m) => m.refUID === grant.uid && typeof m.endsAt !== "undefined");
|
|
299
299
|
grant.community = communities.find((c) => c.uid === grant.communityUID);
|
|
300
300
|
return grant;
|
|
301
301
|
});
|
|
302
302
|
return this.grantsUpdates(withDetails);
|
|
303
303
|
}
|
|
304
304
|
async grantsUpdates(grants) {
|
|
305
|
-
const details = this.gap.findSchema(
|
|
306
|
-
const query = gql_queries_1.gqlQueries.attestationsOf(details.uid, this.getSearchFieldString(
|
|
305
|
+
const details = this.gap.findSchema("GrantDetails");
|
|
306
|
+
const query = gql_queries_1.gqlQueries.attestationsOf(details.uid, this.getSearchFieldString("type", "grant-update"), grants.map((g) => g.uid));
|
|
307
307
|
const { schema: { attestations }, } = await this.query(query);
|
|
308
308
|
const updates = Attestation_1.Attestation.fromInterface(attestations, this.network.name);
|
|
309
309
|
return grants.map((grant) => {
|
|
@@ -313,10 +313,10 @@ class GapEasClient extends Fetcher_1.Fetcher {
|
|
|
313
313
|
}
|
|
314
314
|
async grantsByCommunity(uid) {
|
|
315
315
|
const [grant, grantDetails, project, projectDetails] = this.gap.findManySchemas([
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
316
|
+
"Grant",
|
|
317
|
+
"GrantDetails",
|
|
318
|
+
"Project",
|
|
319
|
+
"ProjectDetails",
|
|
320
320
|
]);
|
|
321
321
|
const query = gql_queries_1.gqlQueries.attestations(grant.uid, uid);
|
|
322
322
|
const { schema: { attestations }, } = await this.query(query);
|
|
@@ -341,10 +341,10 @@ class GapEasClient extends Fetcher_1.Fetcher {
|
|
|
341
341
|
grant.details = (deps.find((d) => d.refUID === grant.uid &&
|
|
342
342
|
d.schema.uid === grantDetails.uid &&
|
|
343
343
|
typeof d.amount !== undefined &&
|
|
344
|
-
typeof d.endsAt ===
|
|
345
|
-
typeof d.data.type ===
|
|
344
|
+
typeof d.endsAt === "undefined" &&
|
|
345
|
+
typeof d.data.type === "undefined"));
|
|
346
346
|
grant.milestones = milestones
|
|
347
|
-
.filter((m) => m.refUID === grant.uid && typeof m.endsAt !==
|
|
347
|
+
.filter((m) => m.refUID === grant.uid && typeof m.endsAt !== "undefined")
|
|
348
348
|
.sort((a, b) => a.endsAt - b.endsAt);
|
|
349
349
|
grant.updates = deps.filter((d) => d.data.type && d.refUID === grant.uid);
|
|
350
350
|
return grant;
|
|
@@ -353,11 +353,11 @@ class GapEasClient extends Fetcher_1.Fetcher {
|
|
|
353
353
|
}
|
|
354
354
|
async grantsFor(projects, withCommunity) {
|
|
355
355
|
const [grant, grantDetails] = this.gap.findManySchemas([
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
356
|
+
"Grant",
|
|
357
|
+
"GrantDetails",
|
|
358
|
+
"Milestone",
|
|
359
|
+
"MilestoneApproved",
|
|
360
|
+
"MilestoneCompleted",
|
|
361
361
|
]);
|
|
362
362
|
const query = gql_queries_1.gqlQueries.dependentsOf(projects.map((p) => p.uid), [grant.uid]);
|
|
363
363
|
const { attestations: grants } = await this.query(query);
|
|
@@ -371,10 +371,10 @@ class GapEasClient extends Fetcher_1.Fetcher {
|
|
|
371
371
|
grant.details = (deps.find((d) => d.refUID === grant.uid &&
|
|
372
372
|
d.schema.uid === grantDetails.uid &&
|
|
373
373
|
typeof d.amount !== undefined &&
|
|
374
|
-
typeof d.endsAt ===
|
|
375
|
-
typeof d.data.type ===
|
|
374
|
+
typeof d.endsAt === "undefined" &&
|
|
375
|
+
typeof d.data.type === "undefined"));
|
|
376
376
|
grant.milestones = milestones
|
|
377
|
-
.filter((m) => m.refUID === grant.uid && typeof m.endsAt !==
|
|
377
|
+
.filter((m) => m.refUID === grant.uid && typeof m.endsAt !== "undefined")
|
|
378
378
|
.sort((a, b) => a.endsAt - b.endsAt);
|
|
379
379
|
});
|
|
380
380
|
const communities = withCommunity
|
|
@@ -389,15 +389,15 @@ class GapEasClient extends Fetcher_1.Fetcher {
|
|
|
389
389
|
}
|
|
390
390
|
async milestonesOf(grants) {
|
|
391
391
|
const [milestone, milestoneApproved, milestoneCompleted] = this.gap.findManySchemas([
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
392
|
+
"Milestone",
|
|
393
|
+
"MilestoneApproved",
|
|
394
|
+
"MilestoneCompleted",
|
|
395
395
|
]);
|
|
396
396
|
const query = gql_queries_1.gqlQueries.dependentsOf(grants.map((g) => g.uid), [milestone.uid]);
|
|
397
397
|
const { attestations } = await this.query(query);
|
|
398
398
|
const milestones = Attestation_1.Attestation.fromInterface(attestations, this.network.name)
|
|
399
399
|
.map((milestone) => new entities_1.Milestone(milestone))
|
|
400
|
-
.filter((m) => typeof m.endsAt !==
|
|
400
|
+
.filter((m) => typeof m.endsAt !== "undefined");
|
|
401
401
|
if (!milestones.length)
|
|
402
402
|
return [];
|
|
403
403
|
const ref = gql_queries_1.gqlQueries.dependentsOf(milestones.map((m) => m.uid), [milestoneApproved.uid, milestoneCompleted.uid]);
|
|
@@ -406,16 +406,16 @@ class GapEasClient extends Fetcher_1.Fetcher {
|
|
|
406
406
|
return milestones.map((milestone) => {
|
|
407
407
|
const refs = deps.filter((ref) => ref.refUID === milestone.uid);
|
|
408
408
|
milestone.endsAt = (0, to_unix_1.toUnix)(milestone.endsAt);
|
|
409
|
-
milestone.completed = refs.find((dep) => dep.type ===
|
|
410
|
-
milestone.approved = refs.find((dep) => dep.type ===
|
|
411
|
-
milestone.rejected = refs.find((dep) => dep.type ===
|
|
409
|
+
milestone.completed = refs.find((dep) => dep.type === "completed" && dep.refUID === milestone.uid);
|
|
410
|
+
milestone.approved = refs.find((dep) => dep.type === "approved" && dep.refUID === milestone.uid);
|
|
411
|
+
milestone.rejected = refs.find((dep) => dep.type === "rejected" && dep.refUID === milestone.uid);
|
|
412
412
|
return milestone;
|
|
413
413
|
});
|
|
414
414
|
}
|
|
415
415
|
async membersOf(projects) {
|
|
416
416
|
const [member, memberDetails] = this.gap.findManySchemas([
|
|
417
|
-
|
|
418
|
-
|
|
417
|
+
"MemberOf",
|
|
418
|
+
"MemberDetails",
|
|
419
419
|
]);
|
|
420
420
|
if (!projects.length)
|
|
421
421
|
return [];
|
|
@@ -444,7 +444,7 @@ class GapEasClient extends Fetcher_1.Fetcher {
|
|
|
444
444
|
];
|
|
445
445
|
}
|
|
446
446
|
async grantsForExtProject(projectExtId) {
|
|
447
|
-
console.error(new Error(
|
|
447
|
+
console.error(new Error("Grants for external project is only supported by a custom indexer. Check https://github.com/show-karma/karma-gap-sdk for more information."));
|
|
448
448
|
return [];
|
|
449
449
|
}
|
|
450
450
|
}
|
package/core/class/Schema.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { SchemaEncoder, SchemaItem, SchemaValue } from "@ethereum-attestation-service/eas-sdk";
|
|
2
2
|
import { AttestArgs, Hex, MultiRevokeArgs, SchemaInterface, SignerOrProvider, TNetwork } from "../types";
|
|
3
|
+
import { ethers } from "ethers";
|
|
3
4
|
import { GAP } from "./GAP";
|
|
4
5
|
import { Attestation } from "./Attestation";
|
|
6
|
+
import { AttestationWithTx } from "./types/attestations";
|
|
5
7
|
/**
|
|
6
8
|
* Represents the EAS Schema and provides methods to encode and decode the schema,
|
|
7
9
|
* and validate the schema references.
|
|
@@ -76,6 +78,10 @@ export declare abstract class Schema<T extends string = string> implements Schem
|
|
|
76
78
|
readonly revocable?: boolean;
|
|
77
79
|
readonly references?: T;
|
|
78
80
|
readonly gap: GAP;
|
|
81
|
+
readonly oldSchemas?: {
|
|
82
|
+
uid: string;
|
|
83
|
+
raw: SchemaItem[];
|
|
84
|
+
}[];
|
|
79
85
|
/**
|
|
80
86
|
* Creates a new schema instance
|
|
81
87
|
* @param args
|
|
@@ -140,21 +146,24 @@ export declare abstract class Schema<T extends string = string> implements Schem
|
|
|
140
146
|
* @param {Object} param0 - An object containing the schema and other optional settings.
|
|
141
147
|
* @returns {Object} An object containing the attestation results, including the CID if 'ipfsKey' is enabled.
|
|
142
148
|
*/
|
|
143
|
-
attest<T>({ data, to, signer, refUID, callback, }: AttestArgs<T>): Promise<
|
|
149
|
+
attest<T>({ data, to, signer, refUID, callback, }: AttestArgs<T>): Promise<AttestationWithTx>;
|
|
144
150
|
/**
|
|
145
151
|
* Bulk attest a set of attestations.
|
|
146
152
|
* @param signer
|
|
147
153
|
* @param entities
|
|
148
154
|
* @returns
|
|
149
155
|
*/
|
|
150
|
-
multiAttest(signer: SignerOrProvider, entities?: Attestation[], callback?: Function): Promise<
|
|
156
|
+
multiAttest(signer: SignerOrProvider, entities?: Attestation[], callback?: Function): Promise<AttestationWithTx>;
|
|
151
157
|
/**
|
|
152
158
|
* Revokes a set of attestations by their UIDs.
|
|
153
159
|
* @param signer
|
|
154
160
|
* @param uids
|
|
155
161
|
* @returns
|
|
156
162
|
*/
|
|
157
|
-
multiRevoke(signer: SignerOrProvider, toRevoke: MultiRevokeArgs[], callback?: Function): Promise<
|
|
163
|
+
multiRevoke(signer: SignerOrProvider, toRevoke: MultiRevokeArgs[], callback?: Function): Promise<{
|
|
164
|
+
tx: ethers.Transaction[];
|
|
165
|
+
uids: `0x${string}`[];
|
|
166
|
+
}>;
|
|
158
167
|
static exists(name: string, network: TNetwork): Schema<string>;
|
|
159
168
|
/**
|
|
160
169
|
* Adds the schema signature to a shares list. Use Schema.get("SchemaName") to get the schema.
|
package/core/class/Schema.js
CHANGED
|
@@ -87,6 +87,7 @@ class Schema {
|
|
|
87
87
|
this.name = args.name;
|
|
88
88
|
this.references = args.references;
|
|
89
89
|
this.revocable = args.revocable || true;
|
|
90
|
+
this.oldSchemas = args.oldSchemas || null;
|
|
90
91
|
this.encoder = new eas_sdk_1.SchemaEncoder(this.raw);
|
|
91
92
|
}
|
|
92
93
|
/**
|
|
@@ -142,7 +143,7 @@ class Schema {
|
|
|
142
143
|
JSON.parse(value);
|
|
143
144
|
}
|
|
144
145
|
catch (error) {
|
|
145
|
-
throw new SchemaError_1.SchemaError("INVALID_SCHEMA_FIELD", `Field ${name} is of type ${type} but value is not a valid JSON string
|
|
146
|
+
throw new SchemaError_1.SchemaError("INVALID_SCHEMA_FIELD", `Field ${name} is of type ${type} but value is not a valid JSON string.`, error);
|
|
146
147
|
}
|
|
147
148
|
}
|
|
148
149
|
}
|
|
@@ -253,17 +254,27 @@ class Schema {
|
|
|
253
254
|
};
|
|
254
255
|
callback?.("preparing");
|
|
255
256
|
if (consts_1.useDefaultAttestation.includes(this.name)) {
|
|
256
|
-
const
|
|
257
|
+
const uid = await eas.attest({
|
|
257
258
|
schema: this.uid,
|
|
258
259
|
data: payload.data.payload,
|
|
259
260
|
});
|
|
260
261
|
callback?.("pending");
|
|
261
|
-
const
|
|
262
|
+
const uidResult = await uid.wait();
|
|
262
263
|
callback?.("confirmed");
|
|
263
|
-
return
|
|
264
|
+
return {
|
|
265
|
+
tx: [
|
|
266
|
+
{
|
|
267
|
+
hash: uidResult,
|
|
268
|
+
},
|
|
269
|
+
],
|
|
270
|
+
uids: [uidResult],
|
|
271
|
+
};
|
|
264
272
|
}
|
|
265
|
-
const
|
|
266
|
-
return
|
|
273
|
+
const { tx, uids } = await GapContract_1.GapContract.attest(signer, payload, callback);
|
|
274
|
+
return {
|
|
275
|
+
tx,
|
|
276
|
+
uids,
|
|
277
|
+
};
|
|
267
278
|
}
|
|
268
279
|
/**
|
|
269
280
|
* Bulk attest a set of attestations.
|
|
@@ -295,15 +306,21 @@ class Schema {
|
|
|
295
306
|
}));
|
|
296
307
|
if (callback)
|
|
297
308
|
callback("preparing");
|
|
298
|
-
const
|
|
309
|
+
const attestation = await eas.multiAttest(payload, {
|
|
299
310
|
gasLimit: 5000000n,
|
|
300
311
|
});
|
|
301
312
|
if (callback)
|
|
302
313
|
callback("pending");
|
|
303
|
-
|
|
314
|
+
const txResult = await attestation.wait().then((res) => {
|
|
304
315
|
if (callback)
|
|
305
316
|
callback("confirmed");
|
|
317
|
+
return res;
|
|
306
318
|
});
|
|
319
|
+
const tx = txResult.map((item) => ({ hash: item }));
|
|
320
|
+
return {
|
|
321
|
+
tx,
|
|
322
|
+
uids: txResult,
|
|
323
|
+
};
|
|
307
324
|
}
|
|
308
325
|
/**
|
|
309
326
|
* Revokes a set of attestations by their UIDs.
|
|
@@ -328,9 +345,13 @@ class Schema {
|
|
|
328
345
|
gasLimit: 5000000n,
|
|
329
346
|
});
|
|
330
347
|
callback?.("pending");
|
|
331
|
-
|
|
348
|
+
tx.wait().then(() => {
|
|
332
349
|
callback?.("confirmed");
|
|
333
350
|
});
|
|
351
|
+
return {
|
|
352
|
+
tx: [{ hash: tx.tx.hash }],
|
|
353
|
+
uids: payload.map((p) => p.data.map((d) => d.uid)).flat(),
|
|
354
|
+
};
|
|
334
355
|
}
|
|
335
356
|
static exists(name, network) {
|
|
336
357
|
return this.schemas[network].find((schema) => schema.name === name);
|
|
@@ -460,7 +481,7 @@ Schema.schemas = {
|
|
|
460
481
|
sepolia: [],
|
|
461
482
|
arbitrum: [],
|
|
462
483
|
celo: [],
|
|
463
|
-
|
|
484
|
+
sei: [],
|
|
464
485
|
"sei-testnet": [],
|
|
465
486
|
"base-sepolia": [],
|
|
466
487
|
};
|
|
@@ -19,7 +19,8 @@ declare const SchemaErrorCodes: {
|
|
|
19
19
|
export declare class SchemaError extends Error {
|
|
20
20
|
readonly code: number;
|
|
21
21
|
private readonly _message;
|
|
22
|
-
|
|
22
|
+
readonly originalError: any;
|
|
23
|
+
constructor(code: keyof typeof SchemaErrorCodes, append?: string, originalError?: any);
|
|
23
24
|
get message(): string;
|
|
24
25
|
}
|
|
25
26
|
export declare class AttestationError extends SchemaError {
|
|
@@ -20,10 +20,11 @@ const SchemaErrorCodes = {
|
|
|
20
20
|
REMOTE_STORAGE_UPLOAD: 50016,
|
|
21
21
|
};
|
|
22
22
|
class SchemaError extends Error {
|
|
23
|
-
constructor(code, append) {
|
|
24
|
-
super(`${code}${append ? `: ${append}` :
|
|
25
|
-
this._message = append || code.replace(/_/g,
|
|
23
|
+
constructor(code, append, originalError) {
|
|
24
|
+
super(`${code}${append ? `: ${append}` : ""}`);
|
|
25
|
+
this._message = append || code.replace(/_/g, " ");
|
|
26
26
|
this.code = SchemaErrorCodes[code];
|
|
27
|
+
this.originalError = originalError;
|
|
27
28
|
}
|
|
28
29
|
get message() {
|
|
29
30
|
return this._message;
|