@show-karma/karma-gap-sdk 0.3.4 → 0.3.6

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.
Files changed (76) hide show
  1. package/core/abi/CommunityResolverABI.json +508 -0
  2. package/core/class/Attestation.js +4 -0
  3. package/core/class/AttestationIPFS.d.ts +7 -0
  4. package/core/class/AttestationIPFS.js +10 -0
  5. package/core/class/GAP.d.ts +7 -0
  6. package/core/class/GAP.js +14 -0
  7. package/core/class/GraphQL/Fetcher.d.ts +132 -0
  8. package/core/class/GraphQL/Fetcher.js +7 -0
  9. package/core/class/GraphQL/GAPFetcher.d.ts +160 -0
  10. package/core/class/GraphQL/GAPFetcher.js +516 -0
  11. package/core/class/IPFS/IPFS.d.ts +13 -0
  12. package/core/class/IPFS/IPFS.js +24 -0
  13. package/core/class/contract/MultiAttest.d.ts +10 -0
  14. package/core/class/contract/MultiAttest.js +19 -0
  15. package/core/class/entities/Milestone.d.ts +2 -0
  16. package/core/class/entities/Milestone.js +4 -0
  17. package/core/class/types/attestations.d.ts +6 -0
  18. package/core/class/types/attestations.js +6 -0
  19. package/core/consts.js +4 -34
  20. package/core/types.d.ts +1 -0
  21. package/package.json +1 -1
  22. package/readme.md +34 -39
  23. package/config/keys.example.json +0 -6
  24. package/core/abi/EAS.json +0 -1
  25. package/core/abi/SchemaRegistry.json +0 -1
  26. package/core/class/Attestation.ts +0 -402
  27. package/core/class/Fetcher.ts +0 -202
  28. package/core/class/GAP.ts +0 -398
  29. package/core/class/GapSchema.ts +0 -90
  30. package/core/class/Gelato/Gelato.ts +0 -286
  31. package/core/class/GraphQL/AxiosGQL.ts +0 -29
  32. package/core/class/GraphQL/EASClient.ts +0 -34
  33. package/core/class/GraphQL/GapEasClient.ts +0 -845
  34. package/core/class/GraphQL/index.ts +0 -3
  35. package/core/class/Schema.ts +0 -609
  36. package/core/class/SchemaError.ts +0 -36
  37. package/core/class/contract/GapContract.ts +0 -353
  38. package/core/class/entities/Community.ts +0 -115
  39. package/core/class/entities/Grant.ts +0 -309
  40. package/core/class/entities/MemberOf.ts +0 -42
  41. package/core/class/entities/Milestone.ts +0 -269
  42. package/core/class/entities/Project.ts +0 -370
  43. package/core/class/entities/index.ts +0 -5
  44. package/core/class/index.ts +0 -10
  45. package/core/class/karma-indexer/GapIndexerClient.ts +0 -245
  46. package/core/class/remote-storage/IpfsStorage.ts +0 -51
  47. package/core/class/remote-storage/RemoteStorage.ts +0 -65
  48. package/core/class/types/attestations.ts +0 -158
  49. package/core/consts.ts +0 -282
  50. package/core/index.ts +0 -7
  51. package/core/scripts/deploy.ts +0 -67
  52. package/core/scripts/index.ts +0 -1
  53. package/core/types.ts +0 -186
  54. package/core/utils/gelato/index.ts +0 -3
  55. package/core/utils/gelato/send-gelato-txn.ts +0 -114
  56. package/core/utils/gelato/sponsor-handler.ts +0 -77
  57. package/core/utils/gelato/watch-gelato-txn.ts +0 -67
  58. package/core/utils/get-date.ts +0 -3
  59. package/core/utils/get-ipfs-data.ts +0 -13
  60. package/core/utils/get-web3-provider.ts +0 -20
  61. package/core/utils/gql-queries.ts +0 -133
  62. package/core/utils/index.ts +0 -7
  63. package/core/utils/map-filter.ts +0 -21
  64. package/core/utils/serialize-bigint.ts +0 -7
  65. package/core/utils/to-unix.ts +0 -18
  66. package/csv-upload/.gitkeep +0 -0
  67. package/csv-upload/example.csv +0 -2
  68. package/csv-upload/scripts/run.ts +0 -193
  69. package/docs/.gitkeep +0 -0
  70. package/docs/images/attestation-architecture.png +0 -0
  71. package/docs/images/dfd-get-projects.png +0 -0
  72. package/index.ts +0 -1
  73. package/schemas/.gitkeep +0 -0
  74. package/schemas/GAP-schemas-1692135812877.json +0 -33
  75. package/test-file.ts +0 -92
  76. package/tsconfig.json +0 -26
@@ -1,353 +0,0 @@
1
- import {
2
- Hex,
3
- RawAttestationPayload,
4
- RawMultiAttestPayload,
5
- SignerOrProvider,
6
- } from 'core/types';
7
- import { GAP } from '../GAP';
8
- import { serializeWithBigint } from '../../utils/serialize-bigint';
9
- import { Gelato, sendGelatoTxn } from '../../utils/gelato/send-gelato-txn';
10
- import {
11
- MultiRevocationRequest,
12
- getUIDsFromAttestReceipt,
13
- } from '@ethereum-attestation-service/eas-sdk';
14
-
15
- type TSignature = {
16
- r: string;
17
- s: string;
18
- v: string;
19
- nonce: number;
20
- chainId: bigint;
21
- };
22
-
23
- const AttestationDataTypes = {
24
- Attest: [
25
- { name: 'payloadHash', type: 'string' },
26
- { name: 'nonce', type: 'uint256' },
27
- { name: 'expiry', type: 'uint256' },
28
- ],
29
- };
30
-
31
- export class GapContract {
32
- static nonces: { [key: string]: number } = {};
33
- /**
34
- * Signs a message for the delegated attestation.
35
- * @param signer
36
- * @param payload
37
- * @returns r,s,v signature
38
- */
39
- private static async signAttestation(
40
- signer: SignerOrProvider,
41
- payload: string,
42
- expiry: bigint
43
- ): Promise<TSignature> {
44
- let { nonce } = await this.getNonce(signer);
45
- const { chainId } = await signer.provider.getNetwork();
46
-
47
- const domain = {
48
- chainId,
49
- name: 'gap-attestation',
50
- version: '1',
51
- verifyingContract: (await GAP.getMulticall(signer)).address,
52
- };
53
-
54
- const data = { payloadHash: payload, nonce, expiry };
55
-
56
- console.log({ domain, AttestationDataTypes, data });
57
-
58
- const signature = await (signer as any)._signTypedData(
59
- domain,
60
- AttestationDataTypes,
61
- data
62
- );
63
-
64
- const { r, s, v } = this.getRSV(signature);
65
- return { r, s, v, nonce, chainId };
66
- }
67
-
68
- /**
69
- * Returns the r, s, v values of a signature
70
- * @param signature
71
- * @returns
72
- */
73
- private static getRSV(signature: string) {
74
- const r = signature.slice(0, 66);
75
- const s = `0x${signature.slice(66, 130)}`;
76
- const v = `0x${signature.slice(130, 132)}`;
77
- return { r, s, v };
78
- }
79
-
80
- public static async getSignerAddress(signer: SignerOrProvider) {
81
- const address =
82
- signer.address || signer._address || (await signer.getAddress());
83
- if (!address)
84
- throw new Error(
85
- 'Signer does not provider either address or getAddress().'
86
- );
87
- return address;
88
- }
89
-
90
- /**
91
- * Get nonce for the transaction
92
- * @param address
93
- * @returns
94
- */
95
- private static async getNonce(signer: SignerOrProvider) {
96
- const contract = await GAP.getMulticall(signer);
97
- const address = await this.getSignerAddress(signer);
98
-
99
- console.log({ address });
100
-
101
- const nonce = <bigint>await contract.functions.nonces(address);
102
- return {
103
- nonce: Number(nonce),
104
- next: Number(nonce + 1n),
105
- };
106
- }
107
-
108
- /**
109
- * Send a single attestation
110
- * @param signer
111
- * @param payload
112
- * @returns
113
- */
114
- static async attest(
115
- signer: SignerOrProvider,
116
- payload: RawAttestationPayload
117
- ) {
118
- const contract = await GAP.getMulticall(signer);
119
-
120
- if (GAP.gelatoOpts?.useGasless) {
121
- return this.attestBySig(signer, payload);
122
- }
123
-
124
- const tx = await contract.functions.attest({
125
- schema: payload.schema,
126
- data: payload.data.payload,
127
- });
128
-
129
- const result = await tx.wait?.();
130
- const attestations = getUIDsFromAttestReceipt(result)[0];
131
-
132
- return attestations as Hex;
133
- }
134
-
135
- static async attestBySig(
136
- signer: SignerOrProvider,
137
- payload: RawAttestationPayload
138
- ) {
139
- const contract = await GAP.getMulticall(signer);
140
- const expiry = BigInt(Math.floor(Date.now() / 1000) + 60 * 60 * 24 * 30);
141
- const address = await this.getSignerAddress(signer);
142
- const payloadHash = serializeWithBigint({
143
- schema: payload.schema,
144
- data: payload.data.raw,
145
- });
146
-
147
- const { r, s, v, nonce, chainId } = await this.signAttestation(
148
- signer,
149
- payloadHash,
150
- expiry
151
- );
152
-
153
- const { data: populatedTxn } =
154
- await contract.populateTransaction.attestBySig(
155
- {
156
- data: payload.data.payload,
157
- schema: payload.schema,
158
- },
159
- payloadHash,
160
- address,
161
- nonce,
162
- expiry,
163
- v,
164
- r,
165
- s
166
- );
167
-
168
- if (!populatedTxn) throw new Error('Transaction data is empty');
169
-
170
- const txn = await sendGelatoTxn(
171
- ...Gelato.buildArgs(populatedTxn, chainId, contract.address as Hex)
172
- );
173
-
174
- const attestations = await this.getTransactionLogs(signer, txn);
175
- return attestations[0];
176
- }
177
-
178
- /**
179
- * Performs a referenced multi attestation.
180
- *
181
- * @returns an array with the attestation UIDs.
182
- */
183
- static async multiAttest(
184
- signer: SignerOrProvider,
185
- payload: RawMultiAttestPayload[]
186
- ): Promise<Hex[]> {
187
- const contract = await GAP.getMulticall(signer);
188
-
189
- if (GAP.gelatoOpts?.useGasless) {
190
- return this.multiAttestBySig(signer, payload);
191
- }
192
-
193
- const tx = await contract.functions.multiSequentialAttest(
194
- payload.map((p) => p.payload)
195
- );
196
-
197
- const result = await tx.wait?.();
198
- const attestations = getUIDsFromAttestReceipt(result);
199
-
200
- return attestations as Hex[];
201
- }
202
-
203
- /**
204
- * Performs a referenced multi attestation.
205
- *
206
- * @returns an array with the attestation UIDs.
207
- */
208
- static async multiAttestBySig(
209
- signer: SignerOrProvider,
210
- payload: RawMultiAttestPayload[]
211
- ): Promise<Hex[]> {
212
- const contract = await GAP.getMulticall(signer);
213
- const expiry = BigInt(Math.floor(Date.now() / 1000) + 60 * 60 * 24 * 30);
214
- const address = await this.getSignerAddress(signer);
215
-
216
- const payloadHash = serializeWithBigint(payload.map((p) => p.raw));
217
-
218
- const { r, s, v, nonce, chainId } = await this.signAttestation(
219
- signer,
220
- payloadHash,
221
- expiry
222
- );
223
-
224
- console.info({ r, s, v, nonce, chainId, payloadHash, address });
225
-
226
- const { data: populatedTxn } =
227
- await contract.populateTransaction.multiSequentialAttestBySig(
228
- payload.map((p) => p.payload),
229
- payloadHash,
230
- address,
231
- nonce,
232
- expiry,
233
- v,
234
- r,
235
- s
236
- );
237
-
238
- if (!populatedTxn) throw new Error('Transaction data is empty');
239
-
240
- const txn = await sendGelatoTxn(
241
- ...Gelato.buildArgs(populatedTxn, chainId, contract.address as Hex)
242
- );
243
-
244
- const attestations = await this.getTransactionLogs(signer, txn);
245
- return attestations;
246
- }
247
-
248
- static async multiRevoke(
249
- signer: SignerOrProvider,
250
- payload: MultiRevocationRequest[]
251
- ) {
252
- const contract = await GAP.getMulticall(signer);
253
-
254
- if (GAP.gelatoOpts?.useGasless) {
255
- return this.multiRevokeBySig(signer, payload);
256
- }
257
-
258
- const tx = await contract.functions.multiRevoke(payload);
259
-
260
- return tx.wait?.();
261
- }
262
-
263
- /**
264
- * Performs a referenced multi attestation.
265
- *
266
- * @returns an array with the attestation UIDs.
267
- */
268
- static async multiRevokeBySig(
269
- signer: SignerOrProvider,
270
- payload: MultiRevocationRequest[]
271
- ): Promise<void> {
272
- const contract = await GAP.getMulticall(signer);
273
- const expiry = BigInt(Math.floor(Date.now() / 1000) + 60 * 60 * 24 * 30);
274
- const address = await this.getSignerAddress(signer);
275
-
276
- const payloadHash = serializeWithBigint(payload);
277
-
278
- const { r, s, v, nonce, chainId } = await this.signAttestation(
279
- signer,
280
- payloadHash,
281
- expiry
282
- );
283
-
284
- console.info({ r, s, v, nonce, chainId, payloadHash, address });
285
-
286
- const { data: populatedTxn } =
287
- await contract.populateTransaction.multiRevokeBySig(
288
- payload,
289
- payloadHash,
290
- address,
291
- nonce,
292
- expiry,
293
- v,
294
- r,
295
- s
296
- );
297
-
298
- if (!populatedTxn) throw new Error('Transaction data is empty');
299
-
300
- await sendGelatoTxn(
301
- ...Gelato.buildArgs(populatedTxn, chainId, contract.address as Hex)
302
- );
303
- }
304
-
305
- /**
306
- * Transfer the ownership of an attestation
307
- * @param signer
308
- * @param projectUID
309
- * @param newOwner
310
- * @returns
311
- */
312
- static async transferProjectOwnership(
313
- signer: SignerOrProvider,
314
- projectUID: Hex,
315
- newOwner: Hex
316
- ) {
317
- const contract = GAP.getProjectResolver(signer);
318
- const tx = await contract.functions.transferProjectOwnership(
319
- projectUID,
320
- newOwner
321
- );
322
- return tx.wait?.();
323
- }
324
-
325
- /**
326
- * Check if the signer is the owner of the project
327
- * @param signer
328
- * @param projectUID
329
- * @returns
330
- */
331
- static async isProjectOwner(
332
- signer: SignerOrProvider,
333
- projectUID: Hex,
334
- projectChainId: number
335
- ): Promise<boolean> {
336
- const contract = GAP.getProjectResolver(signer, projectChainId);
337
- const address = await this.getSignerAddress(signer);
338
- const isOwner = await contract.functions.isAdmin(projectUID, address);
339
- return !!isOwner?.[0];
340
- }
341
-
342
- private static async getTransactionLogs(
343
- signer: SignerOrProvider,
344
- txnHash: string
345
- ) {
346
- const txn = await signer.provider.getTransactionReceipt(txnHash);
347
- if (!txn || !txn.logs.length) throw new Error('Transaction not found');
348
-
349
- // Returns the txn logs with the attestation results. Tha last two logs are the
350
- // the ones from the GelatoRelay contract.
351
- return getUIDsFromAttestReceipt(txn) as Hex[];
352
- }
353
- }
@@ -1,115 +0,0 @@
1
- import { Attestation } from '../Attestation';
2
- import {
3
- CommunityDetails,
4
- Grantee,
5
- ICommunityDetails,
6
- } from '../types/attestations';
7
- import { nullRef } from '../../consts';
8
- import { AttestationError } from '../SchemaError';
9
- import { GapSchema } from '../GapSchema';
10
- import { Project } from './Project';
11
- import {
12
- IAttestation,
13
- MultiAttestPayload,
14
- SignerOrProvider,
15
- TNetwork,
16
- } from 'core/types';
17
- import { GapContract } from '../contract/GapContract';
18
- import { Grant, IGrant } from './Grant';
19
-
20
- interface _Community extends Community {}
21
- export interface ICommunity {
22
- community: true;
23
- }
24
-
25
- export class Community extends Attestation<ICommunity> {
26
- projects: Project[] = [];
27
- grants: Grant[] = [];
28
- details?: CommunityDetails;
29
-
30
- /**
31
- * Creates the payload for a multi-attestation.
32
- *
33
- * > if Current payload is set, it'll be used as the base payload
34
- * and the project should refer to an index of the current payload,
35
- * usually the community position.
36
- *
37
- * @param payload
38
- * @param refIdx
39
- */
40
- async multiAttestPayload() {
41
- const payload: MultiAttestPayload = [[this, await this.payloadFor(0)]];
42
-
43
- if (this.details) {
44
- payload.push([this.details, await this.details.payloadFor(0)]);
45
- }
46
-
47
- if (this.projects?.length) {
48
- await Promise.all(
49
- this.projects.map(async (p) =>
50
- payload.push(...(await p.multiAttestPayload(payload, 0)))
51
- )
52
- );
53
- }
54
-
55
- return payload;
56
- }
57
-
58
- /**
59
- * Attest a community with its details.
60
- *
61
- * If the community exists, it will not be revoked but its details will be updated.
62
- * @param signer
63
- * @param details
64
- */
65
- async attest(
66
- signer: SignerOrProvider,
67
- details?: ICommunityDetails
68
- ): Promise<void> {
69
- console.log('Attesting community');
70
- try {
71
- this._uid = await this.schema.attest({
72
- signer,
73
- to: this.recipient,
74
- refUID: nullRef,
75
- data: this.data,
76
- });
77
- console.log(this.uid);
78
- } catch (error) {
79
- console.error(error);
80
- throw new AttestationError('ATTEST_ERROR', 'Error during attestation.');
81
- }
82
- }
83
-
84
- static from(attestations: _Community[], network: TNetwork): Community[] {
85
- return attestations.map((attestation) => {
86
- const community = new Community({
87
- ...attestation,
88
- data: {
89
- community: true,
90
- },
91
- schema: GapSchema.find('Community', network),
92
- chainID: attestation.chainID,
93
- });
94
-
95
- if (attestation.details) {
96
- const { details } = attestation;
97
- community.details = new CommunityDetails({
98
- ...details,
99
- data: {
100
- ...details.data,
101
- },
102
- schema: GapSchema.find('CommunityDetails', network),
103
- chainID: attestation.chainID,
104
- });
105
- }
106
-
107
- if (attestation.grants) {
108
- const { grants } = attestation as Community;
109
- community.grants = Grant.from(grants, network);
110
- }
111
-
112
- return community;
113
- });
114
- }
115
- }