@show-karma/karma-gap-sdk 0.4.16 → 0.4.18

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 (188) hide show
  1. package/core/abi/AirdropNFT.json +1 -1
  2. package/core/abi/Allo.json +860 -860
  3. package/core/abi/AlloRegistry.json +578 -578
  4. package/core/abi/CommunityResolverABI.json +506 -506
  5. package/core/abi/Donations.json +251 -251
  6. package/core/abi/EAS.json +1 -1
  7. package/core/abi/MultiAttester.json +746 -746
  8. package/core/abi/ProjectResolver.json +574 -574
  9. package/core/abi/SchemaRegistry.json +1 -1
  10. package/core/abi/index.d.ts +1114 -0
  11. package/core/abi/index.js +26 -0
  12. package/core/class/AllGapSchemas.d.ts +9 -0
  13. package/core/class/AllGapSchemas.js +19 -0
  14. package/core/class/Attestation.d.ts +173 -0
  15. package/core/class/Attestation.js +333 -0
  16. package/core/class/Fetcher.d.ts +175 -0
  17. package/core/class/Fetcher.js +13 -0
  18. package/core/class/GAP.d.ts +254 -0
  19. package/core/class/GAP.js +289 -0
  20. package/core/class/GapSchema.d.ts +34 -0
  21. package/core/class/GapSchema.js +62 -0
  22. package/core/class/Gelato/{Gelato.ts → Gelato.js} +0 -23
  23. package/core/class/GrantProgramRegistry/Allo.d.ts +17 -0
  24. package/core/class/GrantProgramRegistry/Allo.js +137 -0
  25. package/core/class/GrantProgramRegistry/AlloRegistry.d.ts +15 -0
  26. package/core/class/GrantProgramRegistry/AlloRegistry.js +70 -0
  27. package/core/class/GraphQL/AxiosGQL.d.ts +6 -0
  28. package/core/class/GraphQL/AxiosGQL.js +25 -0
  29. package/core/class/GraphQL/EASClient.d.ts +16 -0
  30. package/core/class/GraphQL/EASClient.js +26 -0
  31. package/core/class/GraphQL/GapEasClient.d.ts +71 -0
  32. package/core/class/GraphQL/GapEasClient.js +451 -0
  33. package/core/class/GraphQL/index.js +19 -0
  34. package/core/class/Schema.d.ts +233 -0
  35. package/core/class/Schema.js +490 -0
  36. package/core/class/SchemaError.d.ts +30 -0
  37. package/core/class/SchemaError.js +39 -0
  38. package/core/class/contract/GapContract.d.ts +102 -0
  39. package/core/class/contract/GapContract.js +285 -0
  40. package/core/class/entities/Community.d.ts +34 -0
  41. package/core/class/entities/Community.js +109 -0
  42. package/core/class/entities/ContributorProfile.d.ts +41 -0
  43. package/core/class/entities/ContributorProfile.js +69 -0
  44. package/core/class/entities/Grant.d.ts +54 -0
  45. package/core/class/entities/Grant.js +223 -0
  46. package/core/class/entities/GrantUpdate.d.ts +62 -0
  47. package/core/class/entities/GrantUpdate.js +114 -0
  48. package/core/class/entities/MemberOf.d.ts +11 -0
  49. package/core/class/entities/MemberOf.js +33 -0
  50. package/core/class/entities/Milestone.d.ts +168 -0
  51. package/core/class/entities/Milestone.js +657 -0
  52. package/core/class/entities/Project.d.ts +92 -0
  53. package/core/class/entities/Project.js +418 -0
  54. package/core/class/entities/ProjectImpact.d.ts +50 -0
  55. package/core/class/entities/ProjectImpact.js +112 -0
  56. package/core/class/entities/ProjectMilestone.d.ts +60 -0
  57. package/core/class/entities/ProjectMilestone.js +174 -0
  58. package/core/class/entities/ProjectPointer.d.ts +12 -0
  59. package/core/class/entities/ProjectPointer.js +22 -0
  60. package/core/class/entities/ProjectUpdate.d.ts +50 -0
  61. package/core/class/entities/ProjectUpdate.js +110 -0
  62. package/core/class/entities/Track.d.ts +16 -0
  63. package/core/class/entities/Track.js +21 -0
  64. package/core/class/entities/index.js +26 -0
  65. package/core/class/index.js +26 -0
  66. package/core/class/karma-indexer/GapIndexerClient.d.ts +66 -0
  67. package/core/class/karma-indexer/GapIndexerClient.js +207 -0
  68. package/core/class/karma-indexer/api/GapIndexerApi.d.ts +73 -0
  69. package/core/class/karma-indexer/api/GapIndexerApi.js +256 -0
  70. package/core/class/karma-indexer/api/types.d.ts +309 -0
  71. package/core/class/karma-indexer/api/types.js +2 -0
  72. package/core/class/remote-storage/IpfsStorage.d.ts +23 -0
  73. package/core/class/remote-storage/IpfsStorage.js +56 -0
  74. package/core/class/remote-storage/RemoteStorage.d.ts +41 -0
  75. package/core/class/remote-storage/RemoteStorage.js +38 -0
  76. package/core/class/types/allo.d.ts +78 -0
  77. package/core/class/types/allo.js +2 -0
  78. package/core/class/types/attestations.d.ts +173 -0
  79. package/core/class/types/attestations.js +66 -0
  80. package/core/consts.d.ts +50 -0
  81. package/core/consts.js +699 -0
  82. package/core/index.js +24 -0
  83. package/core/shared/types.d.ts +13 -0
  84. package/core/shared/types.js +2 -0
  85. package/core/types.d.ts +131 -0
  86. package/core/types.js +13 -0
  87. package/core/utils/gelato/index.js +19 -0
  88. package/core/utils/gelato/send-gelato-txn.d.ts +55 -0
  89. package/core/utils/gelato/send-gelato-txn.js +100 -0
  90. package/core/utils/gelato/sponsor-handler.d.ts +9 -0
  91. package/core/utils/gelato/sponsor-handler.js +60 -0
  92. package/core/utils/gelato/watch-gelato-txn.d.ts +7 -0
  93. package/core/utils/gelato/watch-gelato-txn.js +63 -0
  94. package/core/utils/get-date.d.ts +1 -0
  95. package/core/utils/get-date.js +7 -0
  96. package/core/utils/get-ipfs-data.d.ts +1 -0
  97. package/core/utils/get-ipfs-data.js +20 -0
  98. package/core/utils/get-web3-provider.d.ts +2 -0
  99. package/core/utils/get-web3-provider.js +18 -0
  100. package/core/utils/gql-queries.d.ts +12 -0
  101. package/core/utils/gql-queries.js +90 -0
  102. package/core/utils/index.js +23 -0
  103. package/core/utils/map-filter.d.ts +8 -0
  104. package/core/utils/map-filter.js +20 -0
  105. package/core/utils/serialize-bigint.d.ts +1 -0
  106. package/core/utils/serialize-bigint.js +8 -0
  107. package/core/utils/to-unix.d.ts +1 -0
  108. package/core/utils/to-unix.js +25 -0
  109. package/index.js +17 -0
  110. package/package.json +45 -45
  111. package/.cursorrules +0 -43
  112. package/core/abi/index.ts +0 -21
  113. package/core/class/AllGapSchemas.ts +0 -21
  114. package/core/class/Attestation.ts +0 -429
  115. package/core/class/Fetcher.ts +0 -224
  116. package/core/class/GAP.ts +0 -481
  117. package/core/class/GapSchema.ts +0 -93
  118. package/core/class/GrantProgramRegistry/Allo.ts +0 -188
  119. package/core/class/GrantProgramRegistry/AlloRegistry.ts +0 -101
  120. package/core/class/GraphQL/AxiosGQL.ts +0 -29
  121. package/core/class/GraphQL/EASClient.ts +0 -34
  122. package/core/class/GraphQL/GapEasClient.ts +0 -869
  123. package/core/class/Schema.ts +0 -659
  124. package/core/class/SchemaError.ts +0 -42
  125. package/core/class/contract/GapContract.ts +0 -457
  126. package/core/class/entities/Community.ts +0 -148
  127. package/core/class/entities/ContributorProfile.ts +0 -108
  128. package/core/class/entities/Grant.ts +0 -321
  129. package/core/class/entities/GrantUpdate.ts +0 -187
  130. package/core/class/entities/MemberOf.ts +0 -52
  131. package/core/class/entities/Milestone.ts +0 -898
  132. package/core/class/entities/Project.ts +0 -672
  133. package/core/class/entities/ProjectImpact.ts +0 -170
  134. package/core/class/entities/ProjectMilestone.ts +0 -254
  135. package/core/class/entities/ProjectPointer.ts +0 -39
  136. package/core/class/entities/ProjectUpdate.ts +0 -176
  137. package/core/class/entities/Track.ts +0 -32
  138. package/core/class/karma-indexer/GapIndexerClient.ts +0 -383
  139. package/core/class/karma-indexer/api/GapIndexerApi.ts +0 -446
  140. package/core/class/karma-indexer/api/types.ts +0 -313
  141. package/core/class/remote-storage/IpfsStorage.ts +0 -76
  142. package/core/class/remote-storage/RemoteStorage.ts +0 -65
  143. package/core/class/types/allo.ts +0 -93
  144. package/core/class/types/attestations.ts +0 -223
  145. package/core/consts.ts +0 -775
  146. package/core/scripts/create-grant.ts +0 -102
  147. package/core/scripts/create-program.ts +0 -43
  148. package/core/scripts/create-schemas.ts +0 -65
  149. package/core/scripts/deploy.ts +0 -65
  150. package/core/scripts/index.ts +0 -1
  151. package/core/scripts/milestone-multi-grants.ts +0 -125
  152. package/core/shared/types.ts +0 -13
  153. package/core/types.ts +0 -224
  154. package/core/utils/gelato/send-gelato-txn.ts +0 -114
  155. package/core/utils/gelato/sponsor-handler.ts +0 -77
  156. package/core/utils/gelato/watch-gelato-txn.ts +0 -67
  157. package/core/utils/get-date.ts +0 -3
  158. package/core/utils/get-ipfs-data.ts +0 -13
  159. package/core/utils/get-web3-provider.ts +0 -18
  160. package/core/utils/gql-queries.ts +0 -133
  161. package/core/utils/map-filter.ts +0 -21
  162. package/core/utils/serialize-bigint.ts +0 -7
  163. package/core/utils/to-unix.ts +0 -18
  164. package/create-community-example.ts +0 -119
  165. package/csv-upload/README.md +0 -74
  166. package/csv-upload/config.ts +0 -41
  167. package/csv-upload/example.csv +0 -2
  168. package/csv-upload/keys.example.json +0 -8
  169. package/csv-upload/scripts/run.ts +0 -417
  170. package/csv-upload/types.ts +0 -39
  171. package/docs/.gitkeep +0 -0
  172. package/docs/images/attestation-architecture.png +0 -0
  173. package/docs/images/dfd-get-projects.png +0 -0
  174. package/gap-schema.yaml +0 -155
  175. package/milestone-workflow-example.ts +0 -353
  176. package/readme.md +0 -872
  177. package/schemas/.gitkeep +0 -0
  178. package/schemas/GAP-schemas-1692135812877.json +0 -33
  179. package/test-file-indexer-api.ts +0 -25
  180. package/tsconfig.json +0 -26
  181. /package/{csv-upload/.gitkeep → core/class/Gelato/Gelato.d.ts} +0 -0
  182. /package/core/class/GraphQL/{index.ts → index.d.ts} +0 -0
  183. /package/core/class/entities/{index.ts → index.d.ts} +0 -0
  184. /package/core/class/{index.ts → index.d.ts} +0 -0
  185. /package/core/{index.ts → index.d.ts} +0 -0
  186. /package/core/utils/gelato/{index.ts → index.d.ts} +0 -0
  187. /package/core/utils/{index.ts → index.d.ts} +0 -0
  188. /package/{index.ts → index.d.ts} +0 -0
package/core/class/GAP.ts DELETED
@@ -1,481 +0,0 @@
1
- import CommunityResolverABI from "../abi/CommunityResolverABI.json";
2
- import MulticallABI from "../abi/MultiAttester.json";
3
- import ProjectResolverABI from "../abi/ProjectResolver.json";
4
-
5
- import { EAS } from "@ethereum-attestation-service/eas-sdk";
6
- import { ethers } from "ethers";
7
- import { version } from "../../package.json";
8
- import { MountEntities, Networks } from "../consts";
9
- import {
10
- AttestArgs,
11
- Facade,
12
- SchemaInterface,
13
- SignerOrProvider,
14
- TNetwork,
15
- TSchemaName,
16
- } from "../types";
17
- import { getWeb3Provider } from "../utils/get-web3-provider";
18
- import { Fetcher } from "./Fetcher";
19
- import { GapSchema } from "./GapSchema";
20
- import { GapEasClient } from "./GraphQL";
21
- import { RemoteStorage } from "./remote-storage/RemoteStorage";
22
- import { Schema } from "./Schema";
23
-
24
- interface GAPArgs {
25
- network: TNetwork;
26
- globalSchemas?: boolean;
27
- /**
28
- * Custom API Client to be used to fetch attestation data.
29
- * If not defined, will use the default EAS Client and rely on EAS's GraphQL API.
30
- */
31
- apiClient?: Fetcher;
32
- schemas?: SchemaInterface<TSchemaName>[];
33
- /**
34
- * Defined if the transactions will be gasless or not.
35
- *
36
- * In case of true, the transactions will be sent through [Gelato](https://gelato.network)
37
- * and an API key is needed.
38
- *
39
- * > __Note that to safely transact through Gelato, the user must
40
- * have set a handlerUrl and not expose gelato api in the frontend.__
41
- */
42
- gelatoOpts?: {
43
- /**
44
- * Endpoint in which the transaction will be sent.
45
- * A custom endpoint will ensure that the transaction will be sent through Gelato
46
- * and api keys won't be exposed in the frontend.
47
- *
48
- * __If coding a backend, you can use `apiKey` prop instead.__
49
- *
50
- * `core/utils/gelato/sponsor-handler.ts` is a base handler that can be used
51
- * together with NextJS API routes.
52
- *
53
- * @example
54
- *
55
- * ```ts
56
- * // pages/api/gelato.ts
57
- * import { handler as sponsorHandler } from "core/utils/gelato/sponsor-handler";
58
- *
59
- * export default const handler(req, res) => sponsorHandler(req, res, "GELATO_API_KEY_ENV_VARIABLE");
60
- *
61
- * ```
62
- */
63
- sponsorUrl?: string;
64
- /**
65
- * If true, env_gelatoApiKey will be marked as required.
66
- * This means that the endpoint at sponsorUrl is contained in this application.
67
- *
68
- * E.g. Next.JS api route.
69
- */
70
- contained?: boolean;
71
- /**
72
- * The env key of gelato api key that will be used in the handler.
73
- *
74
- * @example
75
- *
76
- * ```
77
- * // .env
78
- * GELATO_API_KEY=1234567890
79
- *
80
- * // sponsor-handler.ts
81
- *
82
- * export async function handler(req, res) {
83
- * // ...code
84
- *
85
- * const { env_gelatoApiKey } = GAP.gelatoOpts;
86
- *
87
- * // Will be used to get the key from environment.
88
- * const { [env_gelatoApiKey]: apiKey } = process.env;
89
- *
90
- * // send txn
91
- * // res.send(result);
92
- * }
93
- * ```
94
- */
95
- env_gelatoApiKey?: string;
96
- /**
97
- * API key to be used in the handler.
98
- *
99
- * @deprecated Use this only if you have no option of setting a backend, next/nuxt api route
100
- * or if this application is a backend.
101
- *
102
- * > __This will expose the api key if used in the frontend.__
103
- */
104
- apiKey?: string;
105
- /**
106
- * If true, will use gelato to send transactions.
107
- */
108
- useGasless?: boolean;
109
- };
110
- /**
111
- * Defines a remote storage client to be used to store data.
112
- * If defined, all the details data from an attestation will
113
- * be stored in the remote storage, e.g. IPFS.
114
- */
115
- remoteStorage?: RemoteStorage;
116
- }
117
-
118
- /**
119
- * GAP SDK Facade.
120
- *
121
- * This is the main class that is used to interact with the GAP SDK.
122
- *
123
- * This class implements the singleton pattern to ensure only one instance exists
124
- * throughout the application lifecycle.
125
- *
126
- * Using this class, the user will be able to:
127
- *
128
- * - Create and manage attestations
129
- * - Create and manage schemas
130
- * - Fetch data from the EAS
131
- *
132
- * #### Features
133
- * - EAS Client: used to interact with EAS contracts
134
- * - EAS Fetcher: used to fetch data from the EAS GraphQL API, providing methods for:
135
- * - Get projects
136
- * - Get grants with its details
137
- * - Get grantees
138
- * - Get members
139
- * - Get tags
140
- * - Get external links
141
- * - Get schemas
142
- * - Get attestations by pair, attester, recipient, schema, or UID
143
- * - Get dependent attestations
144
- * - Schema: used to create and manage schemas
145
- * - Attestation: used to create and manage attestations
146
- * - Replace schemas: used to replace the schema list with a new list
147
- * - Replace single schema: used to replace a single schema from the schema list
148
- *
149
- * ---
150
- * @example
151
- * ```ts
152
- * import { GAP } from "./core/class/GAP";
153
- * import { GapSchema } from "./core/class/GapSchema";
154
- * import { Schema } from "./core/class/Schema";
155
- * import { MountEntities, Networks } from "./core/consts";
156
- *
157
- * const schemas = MountEntities(Networks.sepolia);
158
- *
159
- * // Initialize the singleton instance
160
- * const gap = GAP.getInstance({
161
- * network: "sepolia",
162
- * owner: "0xd7d1DB401EA825b0325141Cd5e6cd7C2d01825f2",
163
- * schemas: Object.values(schemas),
164
- * });
165
- *
166
- * // Later in the code, get the same instance
167
- * const sameGap = GAP.getInstance();
168
- *
169
- * gap.fetcher
170
- * .fetchProjects()
171
- * .then((res) => {
172
- * console.log(JSON.stringify(res, null, 2));
173
- * })
174
- *
175
- * ```
176
- */
177
- export class GAP extends Facade {
178
- private static remoteStorage?: RemoteStorage;
179
- private static instances: Map<TNetwork, GAP> = new Map();
180
-
181
- readonly fetch: Fetcher;
182
- readonly network: TNetwork;
183
-
184
- private _schemas: GapSchema[];
185
- private static _gelatoOpts = null;
186
-
187
- /**
188
- * Get the singleton instance of GAP for a specific network.
189
- * If no instance exists for the network, creates one with the provided args.
190
- * @param args Optional initialization arguments
191
- * @returns The singleton instance of GAP for the specified network
192
- */
193
- static getInstance(args?: GAPArgs): GAP {
194
- if (!args) {
195
- throw new Error("Network must be specified when getting GAP instance");
196
- }
197
-
198
- const existingInstance = GAP.instances.get(args.network);
199
- if (existingInstance) {
200
- return existingInstance;
201
- }
202
-
203
- if (!args) {
204
- throw new Error("Initialization arguments required for first instance");
205
- }
206
-
207
- const newInstance = new GAP(args);
208
- GAP.instances.set(args.network, newInstance);
209
- return newInstance;
210
- }
211
-
212
- /**
213
- * Creates a new instance of GAP.
214
- * You can either use this constructor directly or use the singleton pattern via getInstance().
215
- * @param args Initialization arguments
216
- */
217
- constructor(args: GAPArgs) {
218
- super();
219
-
220
- const schemas =
221
- args.schemas || Object.values(MountEntities(Networks[args.network]));
222
-
223
- this.network = args.network;
224
-
225
- this._eas = new EAS(Networks[args.network].contracts.eas);
226
-
227
- this.fetch =
228
- args.apiClient ||
229
- new GapEasClient({
230
- network: args.network,
231
- });
232
-
233
- this.fetch.gapInstance = this;
234
-
235
- this.assertGelatoOpts(args);
236
- GAP._gelatoOpts = args.gelatoOpts;
237
-
238
- GAP.remoteStorage = args.remoteStorage;
239
-
240
- this._schemas = schemas.map(
241
- (schema) =>
242
- new GapSchema(
243
- schema,
244
- this,
245
- false,
246
- args.globalSchemas ? !args.globalSchemas : false
247
- )
248
- );
249
-
250
- Schema.validate(this.network);
251
-
252
- console.info(`Loaded GAP SDK v${version} for network ${this.network}`);
253
-
254
- GAP.instances.set(this.network, this);
255
- }
256
-
257
- private assertGelatoOpts(args: GAPArgs) {
258
- if (
259
- args.gelatoOpts &&
260
- !(args.gelatoOpts.sponsorUrl || args.gelatoOpts.apiKey)
261
- ) {
262
- throw new Error("You must provide a `sponsorUrl` or an `apiKey`.");
263
- }
264
-
265
- if (
266
- args.gelatoOpts?.sponsorUrl &&
267
- args.gelatoOpts?.contained &&
268
- !args.gelatoOpts.env_gelatoApiKey
269
- ) {
270
- throw new Error(
271
- "You must provide `env_gelatoApiKey` to be able to use it in a backend handler."
272
- );
273
- }
274
-
275
- if (
276
- (args.gelatoOpts?.env_gelatoApiKey ||
277
- args.gelatoOpts?.apiKey ||
278
- args.gelatoOpts?.sponsorUrl) &&
279
- !args.gelatoOpts?.useGasless
280
- ) {
281
- console.warn(
282
- "GAP::You are using gelatoOpts but not setting useGasless to true. This will send transactions through the normal provider."
283
- );
284
- }
285
- }
286
-
287
- /**
288
- * Creates the attestation payload using a specific schema.
289
- * @param from
290
- * @param to
291
- * @param data
292
- * @param schema
293
- */
294
- async attest<T>(attestation: AttestArgs<T> & { schemaName: TSchemaName }) {
295
- const schema = GapSchema.find(attestation.schemaName, this.network);
296
- return schema.attest(attestation);
297
- }
298
-
299
- /**
300
- * Replaces the schema list with a new list.
301
- * @param schemas
302
- */
303
- replaceSchemas(schemas: GapSchema[]) {
304
- Schema.replaceAll(schemas, this.network);
305
- }
306
-
307
- /**
308
- * Replaces a schema from the schema list.
309
- * @throws {SchemaError} if desired schema name does not exist.
310
- */
311
- replaceSingleSchema(schema: GapSchema) {
312
- Schema.replaceOne(schema, this.network);
313
- }
314
-
315
- /**
316
- * Generates a slug from a text.
317
- * @param text
318
- * @returns
319
- */
320
- generateSlug = async (text: string): Promise<string> => {
321
- let slug = text
322
- .toLowerCase()
323
- // Remove emojis
324
- .replace(
325
- /([\uE000-\uF8FF]|\uD83C[\uDF00-\uDFFF]|\uD83D[\uDC00-\uDDFF])/g,
326
- ""
327
- )
328
- // Remove basic text emoticons
329
- .replace(/[:;=][()DP]/g, "")
330
- .replace(/ /g, "-")
331
- .replace(/[^\w-]+/g, "")
332
- .trim()
333
- .replace(/^-+|-+$/g, ""); // Remove leading and trailing hyphens
334
-
335
- const checkSlug = async (
336
- currentSlug: string,
337
- counter: number = 0
338
- ): Promise<string> => {
339
- const slugToCheck =
340
- counter === 0 ? currentSlug : `${currentSlug}-${counter}`;
341
- const slugExists = await this.fetch.slugExists(slugToCheck);
342
-
343
- if (slugExists) {
344
- return checkSlug(currentSlug, counter + 1);
345
- }
346
-
347
- return slugToCheck.toLowerCase();
348
- };
349
-
350
- return checkSlug(slug);
351
- };
352
-
353
- /**
354
- * Returns a copy of the original schema with no pointers.
355
- * @param name
356
- * @returns
357
- */
358
- findSchema(name: TSchemaName): GapSchema {
359
- const found = Schema.get<TSchemaName, GapSchema>(name, this.network);
360
- return GapSchema.clone(found);
361
- }
362
-
363
- /**
364
- * Find many schemas by name and return their copies as an array in the same order.
365
- * @param names
366
- * @returns
367
- */
368
- findManySchemas(names: TSchemaName[]): GapSchema[] {
369
- const schemas = Schema.getMany<TSchemaName, GapSchema>(names, this.network);
370
- return schemas.map((s) => GapSchema.clone(s));
371
- }
372
-
373
- /**
374
- * Get the multicall contract
375
- * @param signer
376
- */
377
- static async getMulticall(signer: SignerOrProvider) {
378
- const chain =
379
- (await signer.provider.getNetwork()) || (signer.provider as any).network;
380
- const network = Object.values(Networks).find(
381
- (n) => +n.chainId === Number(chain.chainId)
382
- );
383
- if (!network)
384
- throw new Error(`Network ${chain.name || chain.chainId} not supported.`);
385
-
386
- const address = network.contracts.multicall;
387
- return new ethers.Contract(address, MulticallABI, signer as any);
388
- }
389
-
390
- /**
391
- * Get the multicall contract
392
- * @param signer
393
- */
394
- static async getProjectResolver(
395
- signer: SignerOrProvider & { getChainId?: () => Promise<number> },
396
- chainId?: number
397
- ) {
398
- const currentChainId =
399
- chainId ||
400
- Number(
401
- (await signer.provider.getNetwork())?.chainId ||
402
- (await signer.getChainId())
403
- );
404
-
405
- const provider = chainId ? getWeb3Provider(chainId) : signer;
406
- const network = Object.values(Networks).find(
407
- (n) => +n.chainId === Number(currentChainId)
408
- );
409
- const address = network.contracts.projectResolver;
410
- return new ethers.Contract(address, ProjectResolverABI, provider as any);
411
- }
412
-
413
- /**
414
- * Get the multicall contract
415
- * @param signer
416
- */
417
- static async getCommunityResolver(
418
- signer: SignerOrProvider & { getChainId?: () => Promise<number> },
419
- chainId?: number
420
- ) {
421
- const currentChainId =
422
- chainId ||
423
- Number(
424
- (await signer.provider.getNetwork())?.chainId ||
425
- (await signer.getChainId())
426
- );
427
-
428
- const provider = chainId ? getWeb3Provider(chainId) : signer;
429
- const network = Object.values(Networks).find(
430
- (n) => +n.chainId === Number(currentChainId)
431
- );
432
- const address = network.contracts.communityResolver;
433
- return new ethers.Contract(address, CommunityResolverABI, provider as any);
434
- }
435
-
436
- get schemas() {
437
- return this._schemas;
438
- }
439
-
440
- /**
441
- * Defined if the transactions will be gasless or not.
442
- *
443
- * In case of true, the transactions will be sent through [Gelato](https://gelato.network)
444
- * and an API key is needed.
445
- */
446
- private static set gelatoOpts(gelatoOpts: GAPArgs["gelatoOpts"]) {
447
- if (typeof this._gelatoOpts === "undefined") {
448
- this._gelatoOpts = gelatoOpts;
449
- } else {
450
- throw new Error("Cannot change a readonly value gelatoOpts.");
451
- }
452
- }
453
-
454
- /**
455
- * Defined if the transactions will be gasless or not.
456
- *
457
- * In case of true, the transactions will be sent through [Gelato](https://gelato.network)
458
- * and an API key is needed.
459
- */
460
- static get gelatoOpts(): GAPArgs["gelatoOpts"] {
461
- return this._gelatoOpts;
462
- }
463
-
464
- static set useGasLess(useGasLess: boolean) {
465
- if (
466
- useGasLess &&
467
- !this._gelatoOpts?.apiKey &&
468
- !this._gelatoOpts?.sponsorUrl &&
469
- !this._gelatoOpts?.env_gelatoApiKey
470
- ) {
471
- throw new Error(
472
- "You must provide a `sponsorUrl` or an `apiKey` before using gasless transactions."
473
- );
474
- }
475
- this._gelatoOpts.useGasless = useGasLess;
476
- }
477
-
478
- static get remoteClient() {
479
- return this.remoteStorage;
480
- }
481
- }
@@ -1,93 +0,0 @@
1
- import { mapFilter } from '../utils';
2
- import { IGapSchema, SchemaInterface, TNetwork, TSchemaName } from '../types';
3
- import { Schema } from './Schema';
4
- import { GAP } from './GAP';
5
- import { MountEntities, Networks } from 'core/consts';
6
-
7
- /**
8
- * Represents the GapSchema
9
- * @extends Schema
10
- */
11
- export class GapSchema extends Schema implements IGapSchema {
12
- public readonly name: TSchemaName;
13
- public readonly references: TSchemaName;
14
-
15
- constructor(
16
- args: SchemaInterface<TSchemaName>,
17
- gap: GAP,
18
- strict = false,
19
- ignoreSchema = false
20
- ) {
21
- super(args, gap, strict, ignoreSchema);
22
-
23
- if (!ignoreSchema)
24
- Schema.add(
25
- gap.network,
26
- new GapSchema(
27
- {
28
- name: args.name,
29
- schema: args.schema.map((s) => ({ ...s })),
30
- uid: args.uid,
31
- references: args.references,
32
- revocable: args.revocable,
33
- oldSchemas: args.oldSchemas,
34
- },
35
- gap,
36
- strict,
37
- true
38
- )
39
- );
40
- }
41
-
42
- /**
43
- * Clones a schema without references to the original.
44
- * @param schema
45
- * @returns
46
- */
47
- static clone(schema: GapSchema) {
48
- return new GapSchema(
49
- {
50
- name: schema.name,
51
- schema: schema.schema.map((s) => ({ ...s })),
52
- uid: schema.uid,
53
- references: schema.references,
54
- revocable: schema.revocable,
55
- },
56
- schema.gap,
57
- false,
58
- true
59
- );
60
- }
61
-
62
- /**
63
- * Returns a copy of the original schema with no pointers.
64
- * @param name
65
- * @returns
66
- */
67
- static find(name: TSchemaName, network: TNetwork): GapSchema {
68
- const found = Schema.get<TSchemaName, GapSchema>(name, network);
69
- return this.clone(found);
70
- }
71
-
72
- /**
73
- * Find many schemas by name and return their copies as an array in the same order.
74
- * @param names
75
- * @returns
76
- */
77
- static findMany(names: TSchemaName[], network: TNetwork): GapSchema[] {
78
- const schemas = Schema.getMany<TSchemaName, GapSchema>(names, network);
79
- return schemas.map((s) => this.clone(s));
80
- }
81
-
82
- /**
83
- * Get all schemas that references this schema.
84
- */
85
- get children() {
86
- return mapFilter(
87
- GapSchema.schemas[this.gap.network],
88
- (s) => s.references === this.name || s.references === this.uid,
89
- (s: Schema<TSchemaName>) => new GapSchema(s, s.gap, false, true)
90
- );
91
- }
92
-
93
- }