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