@show-karma/karma-gap-sdk 0.3.4 → 0.3.5
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/CommunityResolverABI.json +508 -0
- package/core/class/AttestationIPFS.d.ts +7 -0
- package/core/class/AttestationIPFS.js +10 -0
- package/core/class/GAP.d.ts +7 -0
- package/core/class/GAP.js +14 -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/IPFS/IPFS.d.ts +13 -0
- package/core/class/IPFS/IPFS.js +24 -0
- package/core/class/contract/MultiAttest.d.ts +10 -0
- package/core/class/contract/MultiAttest.js +19 -0
- package/core/consts.js +4 -34
- package/core/types.d.ts +1 -0
- package/package.json +1 -1
- package/readme.md +34 -39
- package/config/keys.example.json +0 -6
- package/core/abi/EAS.json +0 -1
- package/core/abi/SchemaRegistry.json +0 -1
- package/core/class/Attestation.ts +0 -402
- package/core/class/Fetcher.ts +0 -202
- package/core/class/GAP.ts +0 -398
- package/core/class/GapSchema.ts +0 -90
- package/core/class/Gelato/Gelato.ts +0 -286
- package/core/class/GraphQL/AxiosGQL.ts +0 -29
- package/core/class/GraphQL/EASClient.ts +0 -34
- package/core/class/GraphQL/GapEasClient.ts +0 -845
- package/core/class/GraphQL/index.ts +0 -3
- package/core/class/Schema.ts +0 -609
- package/core/class/SchemaError.ts +0 -36
- package/core/class/contract/GapContract.ts +0 -353
- package/core/class/entities/Community.ts +0 -115
- package/core/class/entities/Grant.ts +0 -309
- package/core/class/entities/MemberOf.ts +0 -42
- package/core/class/entities/Milestone.ts +0 -269
- package/core/class/entities/Project.ts +0 -370
- package/core/class/entities/index.ts +0 -5
- package/core/class/index.ts +0 -10
- package/core/class/karma-indexer/GapIndexerClient.ts +0 -245
- package/core/class/remote-storage/IpfsStorage.ts +0 -51
- package/core/class/remote-storage/RemoteStorage.ts +0 -65
- package/core/class/types/attestations.ts +0 -158
- package/core/consts.ts +0 -282
- package/core/index.ts +0 -7
- package/core/scripts/deploy.ts +0 -67
- package/core/scripts/index.ts +0 -1
- package/core/types.ts +0 -186
- package/core/utils/gelato/index.ts +0 -3
- package/core/utils/gelato/send-gelato-txn.ts +0 -114
- package/core/utils/gelato/sponsor-handler.ts +0 -77
- package/core/utils/gelato/watch-gelato-txn.ts +0 -67
- package/core/utils/get-date.ts +0 -3
- package/core/utils/get-ipfs-data.ts +0 -13
- package/core/utils/get-web3-provider.ts +0 -20
- package/core/utils/gql-queries.ts +0 -133
- package/core/utils/index.ts +0 -7
- package/core/utils/map-filter.ts +0 -21
- package/core/utils/serialize-bigint.ts +0 -7
- package/core/utils/to-unix.ts +0 -18
- package/csv-upload/.gitkeep +0 -0
- package/csv-upload/example.csv +0 -2
- package/csv-upload/scripts/run.ts +0 -193
- package/docs/.gitkeep +0 -0
- package/docs/images/attestation-architecture.png +0 -0
- package/docs/images/dfd-get-projects.png +0 -0
- package/index.ts +0 -1
- package/schemas/.gitkeep +0 -0
- package/schemas/GAP-schemas-1692135812877.json +0 -33
- package/test-file.ts +0 -92
- package/tsconfig.json +0 -26
|
@@ -1,309 +0,0 @@
|
|
|
1
|
-
import { Attestation } from '../Attestation';
|
|
2
|
-
import {
|
|
3
|
-
GrantDetails,
|
|
4
|
-
GrantRound,
|
|
5
|
-
GrantUpdate,
|
|
6
|
-
IGrantUpdate,
|
|
7
|
-
GrantCompleted,
|
|
8
|
-
ProjectDetails,
|
|
9
|
-
} from '../types/attestations';
|
|
10
|
-
import { IMilestone, Milestone } from './Milestone';
|
|
11
|
-
import { GapSchema } from '../GapSchema';
|
|
12
|
-
import { GAP } from '../GAP';
|
|
13
|
-
import { AttestationError } from '../SchemaError';
|
|
14
|
-
import { nullRef } from '../../consts';
|
|
15
|
-
import {
|
|
16
|
-
Hex,
|
|
17
|
-
MultiAttestPayload,
|
|
18
|
-
SignerOrProvider,
|
|
19
|
-
TNetwork,
|
|
20
|
-
} from 'core/types';
|
|
21
|
-
import { GapContract } from '../contract/GapContract';
|
|
22
|
-
import { Community } from './Community';
|
|
23
|
-
import { Project } from './Project';
|
|
24
|
-
|
|
25
|
-
interface _Grant extends Grant {}
|
|
26
|
-
|
|
27
|
-
export interface IGrant {
|
|
28
|
-
communityUID: Hex;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export interface ISummaryProject {
|
|
32
|
-
title: string;
|
|
33
|
-
slug?: string;
|
|
34
|
-
uid: Hex;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export class Grant extends Attestation<IGrant> {
|
|
38
|
-
details?: GrantDetails;
|
|
39
|
-
communityUID: Hex;
|
|
40
|
-
verified?: boolean = false;
|
|
41
|
-
round?: GrantRound;
|
|
42
|
-
milestones: Milestone[] = [];
|
|
43
|
-
community: Community;
|
|
44
|
-
updates: GrantUpdate[] = [];
|
|
45
|
-
members: string[] = [];
|
|
46
|
-
completed?: GrantCompleted;
|
|
47
|
-
project?: ISummaryProject;
|
|
48
|
-
categories?: string[] = [];
|
|
49
|
-
|
|
50
|
-
async verify(signer: SignerOrProvider) {
|
|
51
|
-
const eas = this.schema.gap.eas.connect(signer);
|
|
52
|
-
const schema = this.schema.gap.findSchema('MilestoneApproved');
|
|
53
|
-
schema.setValue('approved', true);
|
|
54
|
-
|
|
55
|
-
try {
|
|
56
|
-
await eas.attest({
|
|
57
|
-
schema: schema.raw,
|
|
58
|
-
data: {
|
|
59
|
-
recipient: this.recipient,
|
|
60
|
-
data: schema.encode(),
|
|
61
|
-
refUID: this.uid,
|
|
62
|
-
expirationTime: 0n,
|
|
63
|
-
revocable: schema.revocable,
|
|
64
|
-
},
|
|
65
|
-
});
|
|
66
|
-
this.verified = true;
|
|
67
|
-
} catch (error) {
|
|
68
|
-
console.error(error);
|
|
69
|
-
throw new AttestationError('ATTEST_ERROR', error.message);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Add milestones to the grant.
|
|
75
|
-
* @param signer
|
|
76
|
-
* @param milestones
|
|
77
|
-
*/
|
|
78
|
-
addMilestones(milestones: IMilestone[]) {
|
|
79
|
-
const schema = this.schema.gap.findSchema('Milestone');
|
|
80
|
-
|
|
81
|
-
const newMilestones = milestones.map((milestone) => {
|
|
82
|
-
const m = new Milestone({
|
|
83
|
-
data: milestone,
|
|
84
|
-
refUID: this.uid,
|
|
85
|
-
schema,
|
|
86
|
-
createdAt: Date.now(),
|
|
87
|
-
recipient: this.recipient,
|
|
88
|
-
uid: nullRef,
|
|
89
|
-
});
|
|
90
|
-
return m;
|
|
91
|
-
});
|
|
92
|
-
this.milestones.push(...newMilestones);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Creates the payload for a multi-attestation.
|
|
97
|
-
*
|
|
98
|
-
* > if Current payload is set, it'll be used as the base payload
|
|
99
|
-
* and the project should refer to an index of the current payload,
|
|
100
|
-
* usually the community position.
|
|
101
|
-
*
|
|
102
|
-
* @param payload
|
|
103
|
-
* @param projectIdx
|
|
104
|
-
*/
|
|
105
|
-
async multiAttestPayload(
|
|
106
|
-
currentPayload: MultiAttestPayload = [],
|
|
107
|
-
projectIdx = 0
|
|
108
|
-
) {
|
|
109
|
-
this.assertPayload();
|
|
110
|
-
const payload = [...currentPayload];
|
|
111
|
-
const grantIdx =
|
|
112
|
-
payload.push([this, await this.payloadFor(projectIdx)]) - 1;
|
|
113
|
-
if (this.details) {
|
|
114
|
-
payload.push([this.details, await this.details.payloadFor(grantIdx)]);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if (this.milestones.length) {
|
|
118
|
-
await Promise.all(
|
|
119
|
-
this.milestones.map(async (m) =>
|
|
120
|
-
payload.push(
|
|
121
|
-
...(await m.multiAttestPayload(currentPayload, grantIdx))
|
|
122
|
-
)
|
|
123
|
-
)
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
if (this.updates.length) {
|
|
127
|
-
await Promise.all(
|
|
128
|
-
this.updates.map(async (u) =>
|
|
129
|
-
payload.push([u, await u.payloadFor(grantIdx)])
|
|
130
|
-
)
|
|
131
|
-
);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return payload.slice(currentPayload.length, payload.length);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
async attestProject(
|
|
138
|
-
signer: SignerOrProvider,
|
|
139
|
-
originalProjectChainId: number
|
|
140
|
-
) {
|
|
141
|
-
const project = new Project({
|
|
142
|
-
data: { project: true },
|
|
143
|
-
schema: this.schema.gap.findSchema('Project'),
|
|
144
|
-
recipient: this.recipient,
|
|
145
|
-
chainID: this.chainID,
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
(project.details as Attestation) = new Attestation({
|
|
149
|
-
data: {
|
|
150
|
-
originalProjectChainId,
|
|
151
|
-
uid: this.refUID,
|
|
152
|
-
},
|
|
153
|
-
chainID: this.chainID,
|
|
154
|
-
recipient: this.recipient,
|
|
155
|
-
schema: this.schema.gap.findSchema('ProjectDetails'),
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
// Overwrite refuid
|
|
159
|
-
Object.assign(this, { refUID: nullRef });
|
|
160
|
-
project.grants = [this];
|
|
161
|
-
|
|
162
|
-
await project.attest(signer);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* @inheritdoc
|
|
167
|
-
*/
|
|
168
|
-
async attest(
|
|
169
|
-
signer: SignerOrProvider,
|
|
170
|
-
projectChainId: number
|
|
171
|
-
): Promise<void> {
|
|
172
|
-
if (projectChainId !== this.chainID) {
|
|
173
|
-
return this.attestProject(signer, projectChainId);
|
|
174
|
-
}
|
|
175
|
-
this.assertPayload();
|
|
176
|
-
const payload = await this.multiAttestPayload();
|
|
177
|
-
|
|
178
|
-
const uids = await GapContract.multiAttest(
|
|
179
|
-
signer,
|
|
180
|
-
payload.map((p) => p[1])
|
|
181
|
-
);
|
|
182
|
-
|
|
183
|
-
uids.forEach((uid, index) => {
|
|
184
|
-
payload[index][0].uid = uid;
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
console.log(uids);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
async attestUpdate(signer: SignerOrProvider, data: IGrantUpdate) {
|
|
191
|
-
const grantUpdate = new GrantUpdate({
|
|
192
|
-
data: {
|
|
193
|
-
...data,
|
|
194
|
-
type: 'grant-update',
|
|
195
|
-
},
|
|
196
|
-
recipient: this.recipient,
|
|
197
|
-
refUID: this.uid,
|
|
198
|
-
schema: this.schema.gap.findSchema('GrantDetails'),
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
await grantUpdate.attest(signer);
|
|
202
|
-
this.updates.push(grantUpdate);
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
async complete(signer: SignerOrProvider, data: IGrantUpdate) {
|
|
206
|
-
const completed = new GrantCompleted({
|
|
207
|
-
data: {
|
|
208
|
-
...data,
|
|
209
|
-
type: 'grant-completed',
|
|
210
|
-
},
|
|
211
|
-
recipient: this.recipient,
|
|
212
|
-
refUID: this.uid,
|
|
213
|
-
schema: this.schema.gap.findSchema('GrantDetails'),
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
await completed.attest(signer);
|
|
217
|
-
this.completed = completed;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* Validate if the grant has a valid reference to a community.
|
|
222
|
-
*/
|
|
223
|
-
protected assertPayload() {
|
|
224
|
-
if (!this.details || !this.communityUID) {
|
|
225
|
-
throw new AttestationError(
|
|
226
|
-
'INVALID_REFERENCE',
|
|
227
|
-
'Grant should include a valid reference to a community on its details.'
|
|
228
|
-
);
|
|
229
|
-
}
|
|
230
|
-
return true;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
static from(attestations: _Grant[], network: TNetwork): Grant[] {
|
|
234
|
-
return attestations.map((attestation) => {
|
|
235
|
-
const grant = new Grant({
|
|
236
|
-
...attestation,
|
|
237
|
-
data: {
|
|
238
|
-
communityUID: attestation.data.communityUID,
|
|
239
|
-
},
|
|
240
|
-
schema: GapSchema.find('Grant', network),
|
|
241
|
-
chainID: attestation.chainID,
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
if (attestation.details) {
|
|
245
|
-
const { details } = attestation;
|
|
246
|
-
grant.details = new GrantDetails({
|
|
247
|
-
...details,
|
|
248
|
-
data: {
|
|
249
|
-
...details.data,
|
|
250
|
-
},
|
|
251
|
-
schema: GapSchema.find('GrantDetails', network),
|
|
252
|
-
chainID: attestation.chainID,
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
if (attestation.milestones) {
|
|
257
|
-
const { milestones } = attestation;
|
|
258
|
-
grant.milestones = Milestone.from(milestones, network);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
if (attestation.updates) {
|
|
262
|
-
const { updates } = attestation;
|
|
263
|
-
grant.updates = updates.map(
|
|
264
|
-
(u) =>
|
|
265
|
-
new GrantUpdate({
|
|
266
|
-
...u,
|
|
267
|
-
data: {
|
|
268
|
-
...u.data,
|
|
269
|
-
},
|
|
270
|
-
schema: GapSchema.find('GrantDetails', network),
|
|
271
|
-
chainID: attestation.chainID,
|
|
272
|
-
})
|
|
273
|
-
);
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
if (attestation.completed) {
|
|
277
|
-
const { completed } = attestation;
|
|
278
|
-
grant.completed = new GrantCompleted({
|
|
279
|
-
...completed,
|
|
280
|
-
data: {
|
|
281
|
-
...completed.data,
|
|
282
|
-
},
|
|
283
|
-
schema: GapSchema.find('GrantDetails', network),
|
|
284
|
-
chainID: attestation.chainID,
|
|
285
|
-
});
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
if (attestation.project) {
|
|
289
|
-
const { project } = attestation;
|
|
290
|
-
grant.project = project;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
if (attestation.community) {
|
|
294
|
-
const { community } = attestation;
|
|
295
|
-
grant.community = Community.from([community], network)[0];
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
if (attestation.members) {
|
|
299
|
-
grant.members = attestation.members;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
if (attestation.categories) {
|
|
303
|
-
grant.categories = attestation.categories;
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
return grant;
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { MultiAttestPayload, SignerOrProvider } from "core/types";
|
|
2
|
-
import { Attestation } from "../Attestation";
|
|
3
|
-
import { MemberDetails } from "../types/attestations";
|
|
4
|
-
import { AttestationError } from "../SchemaError";
|
|
5
|
-
import { GapContract } from "../contract/GapContract";
|
|
6
|
-
|
|
7
|
-
export interface IMemberOf {
|
|
8
|
-
memberOf: true;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export class MemberOf extends Attestation<IMemberOf> {
|
|
12
|
-
details?: MemberDetails;
|
|
13
|
-
|
|
14
|
-
async multiAttestPayload(currentPayload: MultiAttestPayload = [], projectIdx = 0) {
|
|
15
|
-
const payload = [...currentPayload];
|
|
16
|
-
const memberIdx = payload.push([this, await this.payloadFor(projectIdx)]) - 1;
|
|
17
|
-
|
|
18
|
-
if (this.details) {
|
|
19
|
-
payload.push([this.details, await this.details.payloadFor(memberIdx)]);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return payload.slice(currentPayload.length, payload.length);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
async attest(signer: SignerOrProvider) {
|
|
26
|
-
const payload = await this.multiAttestPayload();
|
|
27
|
-
try {
|
|
28
|
-
const [memberUID, detailsUID] = await GapContract.multiAttest(
|
|
29
|
-
signer,
|
|
30
|
-
payload.map((p) => p[1])
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
this.uid = memberUID;
|
|
34
|
-
if (this.details && detailsUID) {
|
|
35
|
-
this.details.uid = detailsUID;
|
|
36
|
-
}
|
|
37
|
-
} catch (error) {
|
|
38
|
-
console.error(error);
|
|
39
|
-
throw new AttestationError("ATTEST_ERROR", error.message);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
@@ -1,269 +0,0 @@
|
|
|
1
|
-
import { MultiAttestPayload, SignerOrProvider, TNetwork } from '../../types';
|
|
2
|
-
import { Attestation } from '../Attestation';
|
|
3
|
-
import { GAP } from '../GAP';
|
|
4
|
-
import { GapSchema } from '../GapSchema';
|
|
5
|
-
import { AttestationError } from '../SchemaError';
|
|
6
|
-
import { GapContract } from '../contract/GapContract';
|
|
7
|
-
import { MilestoneCompleted } from '../types/attestations';
|
|
8
|
-
|
|
9
|
-
interface _Milestone extends Milestone {}
|
|
10
|
-
|
|
11
|
-
export interface IMilestone {
|
|
12
|
-
title: string;
|
|
13
|
-
endsAt: number;
|
|
14
|
-
description: string;
|
|
15
|
-
}
|
|
16
|
-
export class Milestone extends Attestation<IMilestone> implements IMilestone {
|
|
17
|
-
title: string;
|
|
18
|
-
endsAt: number;
|
|
19
|
-
description: string;
|
|
20
|
-
completed: MilestoneCompleted;
|
|
21
|
-
approved: MilestoneCompleted;
|
|
22
|
-
rejected: MilestoneCompleted;
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Approves this milestone. If the milestone is not completed or already approved,
|
|
26
|
-
* it will throw an error.
|
|
27
|
-
* @param signer
|
|
28
|
-
* @param reason
|
|
29
|
-
*/
|
|
30
|
-
async approve(signer: SignerOrProvider, reason = '') {
|
|
31
|
-
if (!this.completed)
|
|
32
|
-
throw new AttestationError('ATTEST_ERROR', 'Milestone is not completed');
|
|
33
|
-
|
|
34
|
-
const schema = this.schema.gap.findSchema('MilestoneCompleted');
|
|
35
|
-
schema.setValue('type', 'approved');
|
|
36
|
-
schema.setValue('reason', reason);
|
|
37
|
-
|
|
38
|
-
await this.attestStatus(signer, schema);
|
|
39
|
-
|
|
40
|
-
this.approved = new MilestoneCompleted({
|
|
41
|
-
data: {
|
|
42
|
-
type: 'approved',
|
|
43
|
-
reason,
|
|
44
|
-
},
|
|
45
|
-
refUID: this.uid,
|
|
46
|
-
schema: schema,
|
|
47
|
-
recipient: this.recipient,
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Revokes the approved status of the milestone. If the milestone is not approved,
|
|
53
|
-
* it will throw an error.
|
|
54
|
-
* @param signer
|
|
55
|
-
*/
|
|
56
|
-
async revokeApproval(signer: SignerOrProvider) {
|
|
57
|
-
if (!this.approved)
|
|
58
|
-
throw new AttestationError('ATTEST_ERROR', 'Milestone is not approved');
|
|
59
|
-
|
|
60
|
-
await this.approved.schema.multiRevoke(signer, [
|
|
61
|
-
{
|
|
62
|
-
schemaId: this.completed.schema.uid,
|
|
63
|
-
uid: this.completed.uid,
|
|
64
|
-
},
|
|
65
|
-
]);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Reject a completed milestone. If the milestone is not completed or already rejected,
|
|
70
|
-
* it will throw an error.
|
|
71
|
-
* @param signer
|
|
72
|
-
* @param reason
|
|
73
|
-
*/
|
|
74
|
-
async reject(signer: SignerOrProvider, reason = '') {
|
|
75
|
-
if (!this.completed)
|
|
76
|
-
throw new AttestationError('ATTEST_ERROR', 'Milestone is not completed');
|
|
77
|
-
|
|
78
|
-
const schema = this.schema.gap.findSchema('MilestoneCompleted');
|
|
79
|
-
schema.setValue('type', 'rejected');
|
|
80
|
-
schema.setValue('reason', reason);
|
|
81
|
-
await this.attestStatus(signer, schema);
|
|
82
|
-
|
|
83
|
-
this.rejected = new MilestoneCompleted({
|
|
84
|
-
data: {
|
|
85
|
-
type: 'rejected',
|
|
86
|
-
reason,
|
|
87
|
-
},
|
|
88
|
-
refUID: this.uid,
|
|
89
|
-
schema: schema,
|
|
90
|
-
recipient: this.recipient,
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Revokes the rejected status of the milestone. If the milestone is not rejected,
|
|
96
|
-
* it will throw an error.
|
|
97
|
-
* @param signer
|
|
98
|
-
*/
|
|
99
|
-
async revokeRejection(signer: SignerOrProvider) {
|
|
100
|
-
if (!this.rejected)
|
|
101
|
-
throw new AttestationError('ATTEST_ERROR', 'Milestone is not rejected');
|
|
102
|
-
|
|
103
|
-
await this.rejected.schema.multiRevoke(signer, [
|
|
104
|
-
{
|
|
105
|
-
schemaId: this.completed.schema.uid,
|
|
106
|
-
uid: this.completed.uid,
|
|
107
|
-
},
|
|
108
|
-
]);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Marks a milestone as completed. If the milestone is already completed,
|
|
113
|
-
* it will throw an error.
|
|
114
|
-
* @param signer
|
|
115
|
-
* @param reason
|
|
116
|
-
*/
|
|
117
|
-
async complete(signer: SignerOrProvider, reason = '') {
|
|
118
|
-
const schema = this.schema.gap.findSchema('MilestoneCompleted');
|
|
119
|
-
schema.setValue('type', 'completed');
|
|
120
|
-
schema.setValue('reason', reason);
|
|
121
|
-
|
|
122
|
-
await this.attestStatus(signer, schema);
|
|
123
|
-
this.completed = new MilestoneCompleted({
|
|
124
|
-
data: {
|
|
125
|
-
type: 'completed',
|
|
126
|
-
reason,
|
|
127
|
-
},
|
|
128
|
-
refUID: this.uid,
|
|
129
|
-
schema,
|
|
130
|
-
recipient: this.recipient,
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Revokes the completed status of the milestone. If the milestone is not completed,
|
|
136
|
-
* it will throw an error.
|
|
137
|
-
* @param signer
|
|
138
|
-
*/
|
|
139
|
-
async revokeCompletion(signer: SignerOrProvider) {
|
|
140
|
-
if (!this.completed)
|
|
141
|
-
throw new AttestationError('ATTEST_ERROR', 'Milestone is not completed');
|
|
142
|
-
|
|
143
|
-
await this.completed.schema.multiRevoke(signer, [
|
|
144
|
-
{
|
|
145
|
-
schemaId: this.completed.schema.uid,
|
|
146
|
-
uid: this.completed.uid,
|
|
147
|
-
},
|
|
148
|
-
]);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Creates the payload for a multi-attestation.
|
|
153
|
-
*
|
|
154
|
-
* > if Current payload is set, it'll be used as the base payload
|
|
155
|
-
* and the project should refer to an index of the current payload,
|
|
156
|
-
* usually the community position.
|
|
157
|
-
*
|
|
158
|
-
* @param payload
|
|
159
|
-
* @param grantIdx
|
|
160
|
-
*/
|
|
161
|
-
async multiAttestPayload(
|
|
162
|
-
currentPayload: MultiAttestPayload = [],
|
|
163
|
-
grantIdx = 0
|
|
164
|
-
) {
|
|
165
|
-
this.assertPayload();
|
|
166
|
-
const payload = [...currentPayload];
|
|
167
|
-
const milestoneIdx =
|
|
168
|
-
payload.push([this, await this.payloadFor(grantIdx)]) - 1;
|
|
169
|
-
if (this.completed) {
|
|
170
|
-
payload.push([
|
|
171
|
-
this.completed,
|
|
172
|
-
await this.completed.payloadFor(milestoneIdx),
|
|
173
|
-
]);
|
|
174
|
-
}
|
|
175
|
-
return payload.slice(currentPayload.length, payload.length);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* @inheritdoc
|
|
180
|
-
*/
|
|
181
|
-
async attest(signer: SignerOrProvider): Promise<void> {
|
|
182
|
-
this.assertPayload();
|
|
183
|
-
const payload = await this.multiAttestPayload();
|
|
184
|
-
|
|
185
|
-
const uids = await GapContract.multiAttest(
|
|
186
|
-
signer,
|
|
187
|
-
payload.map((p) => p[1])
|
|
188
|
-
);
|
|
189
|
-
|
|
190
|
-
uids.forEach((uid, index) => {
|
|
191
|
-
payload[index][0].uid = uid;
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
console.log(uids);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Attest the status of the milestone as approved, rejected or completed.
|
|
199
|
-
*/
|
|
200
|
-
private async attestStatus(signer: SignerOrProvider, schema: GapSchema) {
|
|
201
|
-
const eas = this.schema.gap.eas.connect(signer);
|
|
202
|
-
try {
|
|
203
|
-
const tx = await eas.attest({
|
|
204
|
-
schema: schema.uid,
|
|
205
|
-
data: {
|
|
206
|
-
recipient: this.recipient,
|
|
207
|
-
data: schema.encode(),
|
|
208
|
-
refUID: this.uid,
|
|
209
|
-
expirationTime: 0n,
|
|
210
|
-
revocable: schema.revocable,
|
|
211
|
-
},
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
const uid = await tx.wait();
|
|
215
|
-
console.log(uid);
|
|
216
|
-
} catch (error: any) {
|
|
217
|
-
console.error(error);
|
|
218
|
-
throw new AttestationError('ATTEST_ERROR', error.message);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
static from(attestations: _Milestone[], network: TNetwork): Milestone[] {
|
|
223
|
-
return attestations.map((attestation) => {
|
|
224
|
-
const milestone = new Milestone({
|
|
225
|
-
...attestation,
|
|
226
|
-
data: {
|
|
227
|
-
...attestation.data,
|
|
228
|
-
},
|
|
229
|
-
schema: GapSchema.find('Milestone', network),
|
|
230
|
-
chainID: attestation.chainID,
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
if (attestation.completed) {
|
|
234
|
-
milestone.completed = new MilestoneCompleted({
|
|
235
|
-
...attestation.completed,
|
|
236
|
-
data: {
|
|
237
|
-
...attestation.completed.data,
|
|
238
|
-
},
|
|
239
|
-
schema: GapSchema.find('MilestoneCompleted', network),
|
|
240
|
-
chainID: attestation.chainID,
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
if (attestation.approved) {
|
|
245
|
-
milestone.approved = new MilestoneCompleted({
|
|
246
|
-
...attestation.approved,
|
|
247
|
-
data: {
|
|
248
|
-
...attestation.completed.data,
|
|
249
|
-
},
|
|
250
|
-
schema: GapSchema.find('MilestoneCompleted', network),
|
|
251
|
-
chainID: attestation.chainID,
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
if (attestation.rejected) {
|
|
256
|
-
milestone.rejected = new MilestoneCompleted({
|
|
257
|
-
...attestation.rejected,
|
|
258
|
-
data: {
|
|
259
|
-
...attestation.completed.data,
|
|
260
|
-
},
|
|
261
|
-
schema: GapSchema.find('MilestoneCompleted', network),
|
|
262
|
-
chainID: attestation.chainID,
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
return milestone;
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
}
|