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

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 (70) hide show
  1. package/config/keys.example.json +6 -0
  2. package/core/abi/EAS.json +1 -0
  3. package/core/abi/SchemaRegistry.json +1 -0
  4. package/core/class/Attestation.ts +402 -0
  5. package/core/class/Fetcher.ts +202 -0
  6. package/core/class/GAP.d.ts +3 -1
  7. package/core/class/GAP.js +5 -2
  8. package/core/class/GAP.ts +398 -0
  9. package/core/class/GapSchema.ts +90 -0
  10. package/core/class/Gelato/Gelato.ts +286 -0
  11. package/core/class/GraphQL/AxiosGQL.ts +29 -0
  12. package/core/class/GraphQL/EASClient.ts +34 -0
  13. package/core/class/GraphQL/GapEasClient.ts +845 -0
  14. package/core/class/GraphQL/index.ts +3 -0
  15. package/core/class/Schema.ts +609 -0
  16. package/core/class/SchemaError.ts +36 -0
  17. package/core/class/contract/GapContract.js +2 -2
  18. package/core/class/contract/GapContract.ts +353 -0
  19. package/core/class/entities/Community.ts +115 -0
  20. package/core/class/entities/Grant.ts +309 -0
  21. package/core/class/entities/MemberOf.ts +42 -0
  22. package/core/class/entities/Milestone.ts +269 -0
  23. package/core/class/entities/Project.ts +370 -0
  24. package/core/class/entities/index.ts +5 -0
  25. package/core/class/index.ts +10 -0
  26. package/core/class/karma-indexer/GapIndexerClient.ts +245 -0
  27. package/core/class/remote-storage/IpfsStorage.ts +51 -0
  28. package/core/class/remote-storage/RemoteStorage.ts +65 -0
  29. package/core/class/types/attestations.ts +158 -0
  30. package/core/consts.js +1 -1
  31. package/core/consts.ts +282 -0
  32. package/core/index.ts +7 -0
  33. package/core/scripts/deploy.ts +67 -0
  34. package/core/scripts/index.ts +1 -0
  35. package/core/types.ts +186 -0
  36. package/core/utils/gelato/index.ts +3 -0
  37. package/core/utils/gelato/send-gelato-txn.ts +114 -0
  38. package/core/utils/gelato/sponsor-handler.ts +77 -0
  39. package/core/utils/gelato/watch-gelato-txn.ts +67 -0
  40. package/core/utils/get-date.ts +3 -0
  41. package/core/utils/get-ipfs-data.ts +13 -0
  42. package/core/utils/get-web3-provider.ts +20 -0
  43. package/core/utils/gql-queries.ts +133 -0
  44. package/core/utils/index.ts +7 -0
  45. package/core/utils/map-filter.ts +21 -0
  46. package/core/utils/serialize-bigint.ts +7 -0
  47. package/core/utils/to-unix.ts +18 -0
  48. package/csv-upload/.gitkeep +0 -0
  49. package/csv-upload/example.csv +2 -0
  50. package/csv-upload/scripts/run.ts +193 -0
  51. package/docs/.gitkeep +0 -0
  52. package/docs/images/attestation-architecture.png +0 -0
  53. package/docs/images/dfd-get-projects.png +0 -0
  54. package/index.ts +1 -0
  55. package/package.json +1 -1
  56. package/readme.md +39 -34
  57. package/schemas/.gitkeep +0 -0
  58. package/schemas/GAP-schemas-1692135812877.json +33 -0
  59. package/test-file.ts +92 -0
  60. package/tsconfig.json +26 -0
  61. package/core/class/AttestationIPFS.d.ts +0 -7
  62. package/core/class/AttestationIPFS.js +0 -10
  63. package/core/class/GraphQL/Fetcher.d.ts +0 -132
  64. package/core/class/GraphQL/Fetcher.js +0 -7
  65. package/core/class/GraphQL/GAPFetcher.d.ts +0 -160
  66. package/core/class/GraphQL/GAPFetcher.js +0 -516
  67. package/core/class/IPFS/IPFS.d.ts +0 -13
  68. package/core/class/IPFS/IPFS.js +0 -24
  69. package/core/class/contract/MultiAttest.d.ts +0 -10
  70. package/core/class/contract/MultiAttest.js +0 -19
@@ -0,0 +1,286 @@
1
+ // /* eslint-disable no-shadow */
2
+ // /* eslint-disable no-promise-executor-return */
3
+ // /* eslint-disable no-await-in-loop */
4
+ // /* eslint-disable id-length */
5
+ // /* eslint-disable class-methods-use-this */
6
+ // /* eslint-disable no-useless-constructor */
7
+ // /* eslint-disable import/no-extraneous-dependencies */
8
+
9
+ // import { GelatoRelay } from "@gelatonetwork/relay-sdk";
10
+ // import { ethers } from "ethers";
11
+ // import axios from "axios";
12
+ // import ABI from "./";
13
+ // import { Hex } from "core/types";
14
+
15
+ // enum TaskState {
16
+ // CheckPending = "CheckPending",
17
+ // ExecPending = "ExecPending",
18
+ // ExecSuccess = "ExecSuccess",
19
+ // ExecReverted = "ExecReverted",
20
+ // WaitingForConfirmation = "WaitingForConfirmation",
21
+ // Blacklisted = "Blacklisted",
22
+ // Cancelled = "Cancelled",
23
+ // NotFound = "NotFound",
24
+ // }
25
+
26
+ // export class DelegateRegistryContract extends GelatoRelay {
27
+ // contract: ethers.Contract;
28
+
29
+ // constructor(readonly contractAddress: Hex) {
30
+ // super();
31
+ // this.contract = new ethers.Contract(contractAddress, ABI);
32
+ // }
33
+
34
+ // /**
35
+ // * Returns the r, s, v values of a signature
36
+ // * @param signature
37
+ // * @returns
38
+ // */
39
+ // private getRSV(signature: string) {
40
+ // const r = signature.slice(0, 66);
41
+ // const s = `0x${signature.slice(66, 130)}`;
42
+ // const v = `0x${signature.slice(130, 132)}`;
43
+ // return { r, s, v };
44
+ // }
45
+
46
+ // /**
47
+ // * Returns the nonce of a delegate
48
+ // * @param address
49
+ // * @returns
50
+ // */
51
+ // async getNonce(address: Hex) {
52
+ // const nonce = <bigint>await readFn({
53
+ // abi: ABI,
54
+ // address: this.contractAddress,
55
+ // functionName: "nonces",
56
+ // args: [address],
57
+ // chainId: 10,
58
+ // });
59
+
60
+ // return {
61
+ // nonce: Number(nonce),
62
+ // next: Number(nonce + 1n),
63
+ // };
64
+ // }
65
+
66
+ // /**
67
+ // * Waits for a transaction to be mined at Gelato Network
68
+ // * @param taskId
69
+ // * @returns
70
+ // */
71
+ // wait(taskId: string): Promise<string> {
72
+ // return new Promise((resolve, reject) => {
73
+ // const loop = async () => {
74
+ // const oneSecond = 1;
75
+ // while (oneSecond) {
76
+ // const status = await this.getTaskStatus(taskId);
77
+ // // print status :D so we can debug this for now
78
+ // // eslint-disable-next-line no-console
79
+ // console.log(status);
80
+ // if (!status) {
81
+ // reject(new Error("Transaction goes wrong."));
82
+ // break;
83
+ // }
84
+ // if (status && status.taskState === TaskState.ExecSuccess) {
85
+ // resolve(status.transactionHash || "");
86
+ // break;
87
+ // } else if (
88
+ // [
89
+ // TaskState.Cancelled,
90
+ // TaskState.ExecReverted,
91
+ // TaskState.Blacklisted,
92
+ // ].includes(status?.taskState)
93
+ // ) {
94
+ // reject(
95
+ // new Error(
96
+ // status.lastCheckMessage
97
+ // ?.split(/(RegisterDelegate)|(Execution error): /)
98
+ // .at(-1) || ""
99
+ // )
100
+ // );
101
+ // break;
102
+ // }
103
+
104
+ // await new Promise((r) => setTimeout(r, 500));
105
+ // }
106
+ // };
107
+ // loop();
108
+ // });
109
+ // }
110
+
111
+ // /**
112
+ // * Executes a transaction on the DelegateRegistry contract
113
+ // * @param fn the function to call
114
+ // * @param args the arguments to pass to the function
115
+ // * @returns the transaction hash and a wait function to wait for the transaction to be mined
116
+ // */
117
+ // public async transaction(fn: string, args: unknown[]) {
118
+ // const { hash } = await writeFn({
119
+ // abi: ABI,
120
+ // address: this.contractAddress,
121
+ // functionName: fn,
122
+ // args,
123
+ // chainId: 10,
124
+ // });
125
+ // return {
126
+ // hash,
127
+ // wait: () => waitForTransaction({ hash }),
128
+ // };
129
+ // }
130
+
131
+ // public async registerDelegate(data: DelegateWithProfile) {
132
+ // return this.transaction("registerDelegate", [
133
+ // data.tokenAddress,
134
+ // BigInt(data.tokenChainId),
135
+ // JSON.stringify(data.profile),
136
+ // ]);
137
+ // }
138
+
139
+ // /**
140
+ // * Creates the payload for register delegate by signature
141
+ // * returning the payload
142
+ // * @param data
143
+ // * @returns
144
+ // */
145
+ // public async registerDelegateBySig(
146
+ // address: Hex,
147
+ // data: DelegateWithProfile
148
+ // ): Promise<Parameters<GelatoRelay["sponsoredCall"]>> {
149
+ // const { nonce } = await this.getNonce(address);
150
+ // // 2 minutes expiry
151
+ // const expiry = ((Date.now() + 1000 * 120) / 1000).toFixed(0);
152
+
153
+ // const metadata = JSON.stringify(data.profile);
154
+
155
+ // const types = {
156
+ // RegisterDelegate: [
157
+ // { name: "tokenAddress", type: "address" },
158
+ // { name: "tokenChainId", type: "uint256" },
159
+ // { name: "metadata", type: "string" },
160
+ // { name: "nonce", type: "uint256" },
161
+ // { name: "expiry", type: "uint256" },
162
+ // ],
163
+ // } as const;
164
+ // const signature = await signTypedData({
165
+ // message: {
166
+ // tokenAddress: data.tokenAddress,
167
+ // tokenChainId: BigInt(data.tokenChainId),
168
+ // metadata,
169
+ // nonce,
170
+ // expiry,
171
+ // },
172
+ // domain: {
173
+ // name: "delegate-registry",
174
+ // version: "1.0",
175
+ // chainId: data.tokenChainId,
176
+ // verifyingContract: this.contractAddress,
177
+ // },
178
+ // primaryType: "RegisterDelegate",
179
+ // types,
180
+ // });
181
+
182
+ // const { r, s, v } = this.getRSV(signature);
183
+
184
+ // const { data: payload } =
185
+ // await this.contract.populateTransaction.registerDelegateBySig(
186
+ // address,
187
+ // data.tokenAddress,
188
+ // BigInt(data.tokenChainId),
189
+ // metadata,
190
+ // nonce,
191
+ // expiry,
192
+ // v,
193
+ // r,
194
+ // s
195
+ // );
196
+
197
+ // // eslint-disable-next-line no-console
198
+ // console.log({ payload, signature, r, s, v });
199
+ // if (!payload) throw new Error("Payload is undefined");
200
+ // return [
201
+ // {
202
+ // data: payload,
203
+ // chainId: 10,
204
+ // target: this.contractAddress,
205
+ // },
206
+ // "{apiKey}", // filled in the api
207
+ // {
208
+ // retries: 3,
209
+ // },
210
+ // ];
211
+ // }
212
+
213
+ // /**
214
+ // * Sends a sponsored call to the DelegateRegistry contract using GelatoRelay
215
+ // * @param payload
216
+ // * @returns
217
+ // */
218
+ // static async sendGelato(...params: Parameters<GelatoRelay["sponsoredCall"]>) {
219
+ // const client = new this(params[0].target as Hex);
220
+ // const relayResponse = await client.sponsoredCall(...params);
221
+
222
+ // return {
223
+ // taskId: relayResponse.taskId,
224
+ // wait: () => client.wait(relayResponse.taskId),
225
+ // };
226
+ // }
227
+
228
+ // /**
229
+ // * Deregisters a delegate on the DelegateRegistry contract
230
+ // * @param tokenAddress
231
+ // * @param tokenChainId
232
+ // * @returns
233
+ // */
234
+ // public deregisterDelegate(tokenAddress: string, tokenChainId: number) {
235
+ // return this.transaction("deregisterDelegate", [tokenAddress, tokenChainId]);
236
+ // }
237
+
238
+ // /**
239
+ // * Returns a delegate from the DelegateRegistry contract
240
+ // * @param delegateAddress
241
+ // * @param tokenAddress
242
+ // * @param tokenChainId
243
+ // * @returns
244
+ // */
245
+ // static async getDelegate(
246
+ // addresses: string[],
247
+ // tokenAddress: string,
248
+ // tokenChainId: number
249
+ // ): Promise<DelegateRegistryWithInterests[]> {
250
+ // const query = `
251
+ // {
252
+ // delegates(where: { delegateAddress_in: ["${addresses.join(
253
+ // '","'
254
+ // )}"], tokenAddress: "${tokenAddress}", tokenChainId: ${tokenChainId} }) {
255
+ // id
256
+ // delegateAddress
257
+ // tokenAddress
258
+ // tokenChainId
259
+ // statement
260
+ // status
261
+ // blockTimestamp
262
+ // name
263
+ // ipfsMetadata
264
+ // acceptedCoC
265
+ // interests
266
+ // }
267
+ // }`;
268
+
269
+ // const {
270
+ // data: {
271
+ // data: { delegates },
272
+ // },
273
+ // } = await axios.post<{ data: DelegateStatementRes }>(this.subgraphUrl, {
274
+ // query,
275
+ // });
276
+
277
+ // return delegates.map((item) => {
278
+ // if (Array.isArray(item?.interests))
279
+ // return item as DelegateRegistryWithInterests;
280
+ // return <DelegateRegistryWithInterests>{
281
+ // ...item,
282
+ // interests: item.interests?.split(",") || [],
283
+ // };
284
+ // });
285
+ // }
286
+ // }
@@ -0,0 +1,29 @@
1
+ import type { AxiosInstance } from "axios";
2
+ import axios from "axios";
3
+
4
+ export abstract class AxiosGQL {
5
+ protected client: AxiosInstance;
6
+
7
+ constructor(url: string) {
8
+ this.client = axios.create({
9
+ baseURL: url,
10
+ headers: {
11
+ "Content-Type": "application/json",
12
+ },
13
+ });
14
+ }
15
+
16
+ protected async query<R = unknown, T = unknown>(
17
+ query: string,
18
+ variables?: T
19
+ ): Promise<R> {
20
+ const {
21
+ data: { data },
22
+ } = await this.client.post<{ data: R }>("", {
23
+ query,
24
+ variables,
25
+ });
26
+
27
+ return data;
28
+ }
29
+ }
@@ -0,0 +1,34 @@
1
+ import { Networks } from "../../consts";
2
+ import { EASNetworkConfig, Hex, TNetwork } from "../../types";
3
+ import { AxiosGQL } from "./AxiosGQL";
4
+
5
+ interface EASClientProps {
6
+ network: TNetwork;
7
+ }
8
+
9
+ export class EASClient extends AxiosGQL implements EASClientProps {
10
+ private readonly _network: EASNetworkConfig & { name: TNetwork };
11
+
12
+ constructor(args: EASClientProps) {
13
+ const { network } = args;
14
+ super(Networks[network].url);
15
+
16
+ this.assert(args);
17
+
18
+ this._network = { ...Networks[network], name: network };
19
+ }
20
+
21
+ /**
22
+ * Validate the constructor arguments
23
+ * @param args
24
+ */
25
+ private assert(args: EASClientProps) {
26
+ if (!Networks[args.network]) {
27
+ throw new Error("Invalid network");
28
+ }
29
+ }
30
+
31
+ get network(): TNetwork {
32
+ return this._network.name;
33
+ }
34
+ }