@show-karma/karma-gap-sdk 0.4.15 → 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.
Files changed (188) hide show
  1. package/.cursorrules +43 -0
  2. package/core/abi/AirdropNFT.json +1 -1
  3. package/core/abi/Allo.json +860 -860
  4. package/core/abi/AlloRegistry.json +578 -578
  5. package/core/abi/CommunityResolverABI.json +506 -506
  6. package/core/abi/Donations.json +251 -251
  7. package/core/abi/EAS.json +1 -1
  8. package/core/abi/MultiAttester.json +746 -746
  9. package/core/abi/ProjectResolver.json +574 -574
  10. package/core/abi/SchemaRegistry.json +1 -1
  11. package/core/abi/index.ts +21 -0
  12. package/core/class/AllGapSchemas.ts +21 -0
  13. package/core/class/Attestation.ts +429 -0
  14. package/core/class/Fetcher.ts +224 -0
  15. package/core/class/GAP.ts +481 -0
  16. package/core/class/GapSchema.ts +93 -0
  17. package/core/class/Gelato/{Gelato.js → Gelato.ts} +23 -0
  18. package/core/class/GrantProgramRegistry/Allo.ts +188 -0
  19. package/core/class/GrantProgramRegistry/AlloRegistry.ts +101 -0
  20. package/core/class/GraphQL/AxiosGQL.ts +29 -0
  21. package/core/class/GraphQL/EASClient.ts +34 -0
  22. package/core/class/GraphQL/GapEasClient.ts +869 -0
  23. package/core/class/Schema.ts +659 -0
  24. package/core/class/SchemaError.ts +42 -0
  25. package/core/class/contract/GapContract.ts +457 -0
  26. package/core/class/entities/Community.ts +148 -0
  27. package/core/class/entities/ContributorProfile.ts +108 -0
  28. package/core/class/entities/Grant.ts +321 -0
  29. package/core/class/entities/GrantUpdate.ts +187 -0
  30. package/core/class/entities/MemberOf.ts +52 -0
  31. package/core/class/entities/Milestone.ts +898 -0
  32. package/core/class/entities/Project.ts +672 -0
  33. package/core/class/entities/ProjectImpact.ts +170 -0
  34. package/core/class/entities/ProjectMilestone.ts +254 -0
  35. package/core/class/entities/ProjectPointer.ts +39 -0
  36. package/core/class/entities/ProjectUpdate.ts +176 -0
  37. package/core/class/entities/Track.ts +32 -0
  38. package/core/class/karma-indexer/GapIndexerClient.ts +383 -0
  39. package/core/class/karma-indexer/api/GapIndexerApi.ts +446 -0
  40. package/core/class/karma-indexer/api/types.ts +313 -0
  41. package/core/class/remote-storage/IpfsStorage.ts +76 -0
  42. package/core/class/remote-storage/RemoteStorage.ts +65 -0
  43. package/core/class/types/allo.ts +93 -0
  44. package/core/class/types/attestations.ts +223 -0
  45. package/core/consts.ts +775 -0
  46. package/core/scripts/create-grant.ts +102 -0
  47. package/core/scripts/create-program.ts +43 -0
  48. package/core/scripts/create-schemas.ts +65 -0
  49. package/core/scripts/deploy.ts +65 -0
  50. package/core/scripts/index.ts +1 -0
  51. package/core/scripts/milestone-multi-grants.ts +125 -0
  52. package/core/shared/types.ts +13 -0
  53. package/core/types.ts +224 -0
  54. package/core/utils/gelato/send-gelato-txn.ts +114 -0
  55. package/core/utils/gelato/sponsor-handler.ts +77 -0
  56. package/core/utils/gelato/watch-gelato-txn.ts +67 -0
  57. package/core/utils/get-date.ts +3 -0
  58. package/core/utils/get-ipfs-data.ts +13 -0
  59. package/core/utils/get-web3-provider.ts +18 -0
  60. package/core/utils/gql-queries.ts +133 -0
  61. package/core/utils/map-filter.ts +21 -0
  62. package/core/utils/serialize-bigint.ts +7 -0
  63. package/core/utils/to-unix.ts +18 -0
  64. package/create-community-example.ts +119 -0
  65. package/csv-upload/README.md +74 -0
  66. package/csv-upload/config.ts +41 -0
  67. package/csv-upload/example.csv +2 -0
  68. package/csv-upload/keys.example.json +8 -0
  69. package/csv-upload/scripts/run.ts +417 -0
  70. package/csv-upload/types.ts +39 -0
  71. package/docs/.gitkeep +0 -0
  72. package/docs/images/attestation-architecture.png +0 -0
  73. package/docs/images/dfd-get-projects.png +0 -0
  74. package/gap-schema.yaml +155 -0
  75. package/milestone-workflow-example.ts +353 -0
  76. package/package.json +45 -39
  77. package/readme.md +872 -0
  78. package/schemas/.gitkeep +0 -0
  79. package/schemas/GAP-schemas-1692135812877.json +33 -0
  80. package/test-file-indexer-api.ts +25 -0
  81. package/tsconfig.json +26 -0
  82. package/core/abi/index.d.ts +0 -1114
  83. package/core/abi/index.js +0 -26
  84. package/core/class/AllGapSchemas.d.ts +0 -9
  85. package/core/class/AllGapSchemas.js +0 -19
  86. package/core/class/Attestation.d.ts +0 -173
  87. package/core/class/Attestation.js +0 -333
  88. package/core/class/Fetcher.d.ts +0 -175
  89. package/core/class/Fetcher.js +0 -13
  90. package/core/class/GAP.d.ts +0 -254
  91. package/core/class/GAP.js +0 -289
  92. package/core/class/GapSchema.d.ts +0 -34
  93. package/core/class/GapSchema.js +0 -62
  94. package/core/class/GrantProgramRegistry/Allo.d.ts +0 -17
  95. package/core/class/GrantProgramRegistry/Allo.js +0 -137
  96. package/core/class/GrantProgramRegistry/AlloRegistry.d.ts +0 -15
  97. package/core/class/GrantProgramRegistry/AlloRegistry.js +0 -70
  98. package/core/class/GraphQL/AxiosGQL.d.ts +0 -6
  99. package/core/class/GraphQL/AxiosGQL.js +0 -25
  100. package/core/class/GraphQL/EASClient.d.ts +0 -16
  101. package/core/class/GraphQL/EASClient.js +0 -26
  102. package/core/class/GraphQL/GapEasClient.d.ts +0 -71
  103. package/core/class/GraphQL/GapEasClient.js +0 -451
  104. package/core/class/GraphQL/index.js +0 -19
  105. package/core/class/Schema.d.ts +0 -233
  106. package/core/class/Schema.js +0 -488
  107. package/core/class/SchemaError.d.ts +0 -30
  108. package/core/class/SchemaError.js +0 -39
  109. package/core/class/contract/GapContract.d.ts +0 -102
  110. package/core/class/contract/GapContract.js +0 -285
  111. package/core/class/entities/Community.d.ts +0 -34
  112. package/core/class/entities/Community.js +0 -109
  113. package/core/class/entities/ContributorProfile.d.ts +0 -41
  114. package/core/class/entities/ContributorProfile.js +0 -69
  115. package/core/class/entities/Grant.d.ts +0 -54
  116. package/core/class/entities/Grant.js +0 -223
  117. package/core/class/entities/GrantUpdate.d.ts +0 -40
  118. package/core/class/entities/GrantUpdate.js +0 -114
  119. package/core/class/entities/MemberOf.d.ts +0 -11
  120. package/core/class/entities/MemberOf.js +0 -33
  121. package/core/class/entities/Milestone.d.ts +0 -168
  122. package/core/class/entities/Milestone.js +0 -657
  123. package/core/class/entities/Project.d.ts +0 -92
  124. package/core/class/entities/Project.js +0 -418
  125. package/core/class/entities/ProjectImpact.d.ts +0 -50
  126. package/core/class/entities/ProjectImpact.js +0 -112
  127. package/core/class/entities/ProjectMilestone.d.ts +0 -60
  128. package/core/class/entities/ProjectMilestone.js +0 -174
  129. package/core/class/entities/ProjectPointer.d.ts +0 -12
  130. package/core/class/entities/ProjectPointer.js +0 -22
  131. package/core/class/entities/ProjectUpdate.d.ts +0 -50
  132. package/core/class/entities/ProjectUpdate.js +0 -110
  133. package/core/class/entities/Track.d.ts +0 -16
  134. package/core/class/entities/Track.js +0 -21
  135. package/core/class/entities/index.js +0 -26
  136. package/core/class/index.js +0 -26
  137. package/core/class/karma-indexer/GapIndexerClient.d.ts +0 -66
  138. package/core/class/karma-indexer/GapIndexerClient.js +0 -207
  139. package/core/class/karma-indexer/api/GapIndexerApi.d.ts +0 -73
  140. package/core/class/karma-indexer/api/GapIndexerApi.js +0 -256
  141. package/core/class/karma-indexer/api/types.d.ts +0 -295
  142. package/core/class/karma-indexer/api/types.js +0 -2
  143. package/core/class/remote-storage/IpfsStorage.d.ts +0 -23
  144. package/core/class/remote-storage/IpfsStorage.js +0 -56
  145. package/core/class/remote-storage/RemoteStorage.d.ts +0 -41
  146. package/core/class/remote-storage/RemoteStorage.js +0 -38
  147. package/core/class/types/allo.d.ts +0 -78
  148. package/core/class/types/allo.js +0 -2
  149. package/core/class/types/attestations.d.ts +0 -168
  150. package/core/class/types/attestations.js +0 -66
  151. package/core/consts.d.ts +0 -48
  152. package/core/consts.js +0 -641
  153. package/core/index.js +0 -24
  154. package/core/shared/types.d.ts +0 -6
  155. package/core/shared/types.js +0 -2
  156. package/core/types.d.ts +0 -131
  157. package/core/types.js +0 -13
  158. package/core/utils/gelato/index.js +0 -19
  159. package/core/utils/gelato/send-gelato-txn.d.ts +0 -55
  160. package/core/utils/gelato/send-gelato-txn.js +0 -100
  161. package/core/utils/gelato/sponsor-handler.d.ts +0 -9
  162. package/core/utils/gelato/sponsor-handler.js +0 -60
  163. package/core/utils/gelato/watch-gelato-txn.d.ts +0 -7
  164. package/core/utils/gelato/watch-gelato-txn.js +0 -63
  165. package/core/utils/get-date.d.ts +0 -1
  166. package/core/utils/get-date.js +0 -7
  167. package/core/utils/get-ipfs-data.d.ts +0 -1
  168. package/core/utils/get-ipfs-data.js +0 -20
  169. package/core/utils/get-web3-provider.d.ts +0 -2
  170. package/core/utils/get-web3-provider.js +0 -18
  171. package/core/utils/gql-queries.d.ts +0 -12
  172. package/core/utils/gql-queries.js +0 -90
  173. package/core/utils/index.js +0 -23
  174. package/core/utils/map-filter.d.ts +0 -8
  175. package/core/utils/map-filter.js +0 -20
  176. package/core/utils/serialize-bigint.d.ts +0 -1
  177. package/core/utils/serialize-bigint.js +0 -8
  178. package/core/utils/to-unix.d.ts +0 -1
  179. package/core/utils/to-unix.js +0 -25
  180. package/index.js +0 -17
  181. /package/core/class/GraphQL/{index.d.ts → index.ts} +0 -0
  182. /package/core/class/entities/{index.d.ts → index.ts} +0 -0
  183. /package/core/class/{index.d.ts → index.ts} +0 -0
  184. /package/core/{index.d.ts → index.ts} +0 -0
  185. /package/core/utils/gelato/{index.d.ts → index.ts} +0 -0
  186. /package/core/utils/{index.d.ts → index.ts} +0 -0
  187. /package/{core/class/Gelato/Gelato.d.ts → csv-upload/.gitkeep} +0 -0
  188. /package/{index.d.ts → index.ts} +0 -0
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
package/core/types.d.ts DELETED
@@ -1,131 +0,0 @@
1
- import { BytesLike } from "ethers";
2
- import { AttestationRequestData, EAS, MultiAttestationRequest, SchemaItem } from "@ethereum-attestation-service/eas-sdk";
3
- import { Attestation } from "./class";
4
- import { Fetcher } from "./class/Fetcher";
5
- export type Hex = `0x${string}`;
6
- export type SignerOrProvider = any;
7
- export interface SchemaInterface<T extends string = string> {
8
- name: string;
9
- schema: SchemaItem[];
10
- references?: T;
11
- uid: Hex;
12
- revocable?: boolean;
13
- oldSchemas?: {
14
- uid: string;
15
- raw: SchemaItem[];
16
- }[];
17
- }
18
- export interface MultiRevokeArgs {
19
- uid: Hex;
20
- schemaId: Hex;
21
- }
22
- export type CallbackStatus = "pending" | "confirmed" | "preparing";
23
- export interface AttestArgs<T = unknown> {
24
- to: Hex;
25
- data: T;
26
- refUID?: Hex;
27
- signer: SignerOrProvider;
28
- callback?: (status: CallbackStatus) => void;
29
- }
30
- export type TSchemaName = "Community" | "CommunityDetails" | "Grant" | "GrantDetails" | "GrantVerified" | "MemberOf" | "MemberDetails" | "Milestone" | "MilestoneCompleted" | "MilestoneApproved" | "Project" | "ProjectDetails" | "Details" | "ProjectImpact" | "ProjectUpdate" | "ProjectUpdateStatus" | "ProjectPointer" | "GrantUpdate" | "GrantUpdateStatus" | "ProjectEndorsement" | "ProjectMilestone" | "ProjectMilestoneStatus" | "ContributorProfile";
31
- export type TResolvedSchemaNames = "Community" | "Grant" | "GrantVerified" | "MemberOf" | "MilestoneCompleted" | "MilestoneApproved" | "Project" | "Details" | "ProjectUpdateStatus" | "GrantUpdateStatus" | "ProjectUpdateStatus" | "ProjectMilestoneStatus" | "ContributorProfile";
32
- export type TExternalLink = "twitter" | "github" | "website" | "linkedin" | "discord" | "pitchDeck" | "demoVideo" | "farcaster";
33
- export type TNetwork = "optimism" | "celo" | "optimism-sepolia" | "arbitrum" | "sepolia" | "sei" | "sei-testnet" | "base-sepolia" | "lisk" | "scroll";
34
- /**
35
- * Generic GAP Facade interface.
36
- * This supplies the GAP class with the necessary properties.
37
- */
38
- export declare abstract class Facade {
39
- abstract readonly network: TNetwork;
40
- abstract readonly schemas: SchemaInterface[];
41
- abstract readonly fetch: Fetcher;
42
- protected _eas: EAS;
43
- get eas(): EAS;
44
- }
45
- export interface RawAttestationPayload {
46
- schema: Hex;
47
- data: {
48
- payload: AttestationRequestData;
49
- raw: AttestationRequestData;
50
- };
51
- }
52
- export interface RawMultiAttestPayload {
53
- payload: MultiAttestData;
54
- raw: MultiAttestData;
55
- }
56
- export interface MultiAttestData {
57
- uid?: Hex;
58
- multiRequest: MultiAttestationRequest;
59
- refIdx: number;
60
- }
61
- export type MultiAttestPayload = [Attestation, RawMultiAttestPayload][];
62
- export interface EASNetworkConfig {
63
- url: string;
64
- rpcUrl: string;
65
- chainId: number;
66
- contracts: {
67
- eas: Hex;
68
- schema: Hex;
69
- multicall: Hex;
70
- projectResolver: Hex;
71
- communityResolver: Hex;
72
- donations: Hex;
73
- airdropNFT: Hex;
74
- };
75
- /**
76
- * A tuple containing the schema name and it's UID for that network
77
- */
78
- schemas: Record<TResolvedSchemaNames, Hex>;
79
- oldSchemas?: {
80
- name: string;
81
- uid: string;
82
- raw: SchemaItem[];
83
- }[];
84
- }
85
- export type IGapSchema = SchemaInterface<TSchemaName>;
86
- export type JSONStr = string;
87
- export interface Schemata {
88
- uid: Hex;
89
- schema: string;
90
- }
91
- export interface SchemataRes {
92
- schemata: Schemata[];
93
- }
94
- export interface IAttestation {
95
- uid: Hex;
96
- attester: Hex;
97
- data: BytesLike;
98
- decodedDataJson: JSONStr;
99
- recipient: Hex;
100
- revoked: boolean;
101
- createdAt: number;
102
- refUID?: Hex;
103
- isOffchain: boolean;
104
- revocable: boolean;
105
- revocationTime?: number;
106
- schemaId: Hex;
107
- }
108
- export interface AttestationRes {
109
- attestation: IAttestation;
110
- }
111
- export interface AttestationsRes {
112
- attestations: IAttestation[];
113
- }
114
- export interface SchemaRes {
115
- schema: {
116
- attestations: IAttestation[];
117
- };
118
- }
119
- /**
120
- * Valid remote storage types
121
- */
122
- export declare const enum STORAGE_TYPE {
123
- IPFS = 0,
124
- ARWEAVE = 1,
125
- SWARM = 2,
126
- UNKNOWN = 3
127
- }
128
- export type TRemoteStorageOutput<T = unknown> = {
129
- hash: T;
130
- storageType: number;
131
- };
package/core/types.js DELETED
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Facade = void 0;
4
- /**
5
- * Generic GAP Facade interface.
6
- * This supplies the GAP class with the necessary properties.
7
- */
8
- class Facade {
9
- get eas() {
10
- return this._eas;
11
- }
12
- }
13
- exports.Facade = Facade;
@@ -1,19 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./send-gelato-txn"), exports);
18
- __exportStar(require("./sponsor-handler"), exports);
19
- __exportStar(require("./watch-gelato-txn"), exports);
@@ -1,55 +0,0 @@
1
- import { GelatoRelay } from '@gelatonetwork/relay-sdk';
2
- import { Hex } from '../../types';
3
- declare function sendByUrl(...params: Parameters<GelatoRelay['sponsoredCall']>): Promise<string>;
4
- /**
5
- * Send gelato using an explicit api key.
6
- *
7
- * > __This is not safe in the frontend.__
8
- *
9
- * @param params
10
- * @returns Gelato's task id and a wait function.
11
- */
12
- declare function sendByApiKey(...params: Parameters<GelatoRelay['sponsoredCall']>): Promise<{
13
- taskId: string;
14
- /**
15
- * Waits for the transaction to be confirmed by Gelato.
16
- * @param ttl interval between checks in ms
17
- * @returns Txn id
18
- */
19
- wait: (ttl?: number) => Promise<string>;
20
- }>;
21
- /**
22
- * Sends a sponsored call using GelatoRelay
23
- * @param payload
24
- * @returns txn hash
25
- */
26
- declare function sendGelatoTxn(...params: Parameters<GelatoRelay['sponsoredCall']>): Promise<string>;
27
- /**
28
- * Builds the arguments for a sponsored call using GelatoRelay
29
- * @param data Populated contract call.
30
- * @param chainId
31
- * @param target target contract address (Hex)
32
- *
33
- * @example
34
- *
35
- * ```ts
36
- * const { data } = await contract.populateTransaction.transfer(
37
- * recipient,
38
- * amount
39
- * );
40
- * const args = buildArgs(data, chainId, target);
41
- * const txn = sendGelatoTxn(...args);
42
- * console.log(txn) // 0xabc..
43
- * ```
44
- */
45
- declare function buildArgs(
46
- /**
47
- * Populated transaction data.
48
- */
49
- data: string, chainId: bigint, target: Hex): Parameters<GelatoRelay['sponsoredCall']>;
50
- declare const Gelato: {
51
- sendByApiKey: typeof sendByApiKey;
52
- sendByUrl: typeof sendByUrl;
53
- buildArgs: typeof buildArgs;
54
- };
55
- export { sendGelatoTxn, Gelato };
@@ -1,100 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Gelato = exports.sendGelatoTxn = void 0;
7
- const axios_1 = __importDefault(require("axios"));
8
- const relay_sdk_1 = require("@gelatonetwork/relay-sdk");
9
- const watch_gelato_txn_1 = require("./watch-gelato-txn");
10
- const GAP_1 = require("../../class/GAP");
11
- async function sendByUrl(...params) {
12
- const { data } = await axios_1.default.post(GAP_1.GAP.gelatoOpts.sponsorUrl, params);
13
- return data;
14
- }
15
- /**
16
- * Send gelato using an explicit api key.
17
- *
18
- * > __This is not safe in the frontend.__
19
- *
20
- * @param params
21
- * @returns Gelato's task id and a wait function.
22
- */
23
- async function sendByApiKey(...params) {
24
- const { apiKey } = GAP_1.GAP?.gelatoOpts || {};
25
- if (!apiKey && params[1] === '{apiKey}')
26
- throw new Error('No api key provided.');
27
- if (apiKey && params[1] === '{apiKey}')
28
- params[1] = apiKey;
29
- const client = new relay_sdk_1.GelatoRelay();
30
- const relayResponse = await client.sponsoredCall(...params);
31
- return {
32
- taskId: relayResponse.taskId,
33
- /**
34
- * Waits for the transaction to be confirmed by Gelato.
35
- * @param ttl interval between checks in ms
36
- * @returns Txn id
37
- */
38
- wait: (ttl) => (0, watch_gelato_txn_1.watchGelatoTxn)(relayResponse.taskId, ttl),
39
- };
40
- }
41
- /**
42
- * Sends a sponsored call using GelatoRelay
43
- * @param payload
44
- * @returns txn hash
45
- */
46
- async function sendGelatoTxn(...params) {
47
- if (!GAP_1.GAP.gelatoOpts)
48
- throw new Error('Gelato opts not set.');
49
- const { env_gelatoApiKey, sponsorUrl, useGasless, contained } = GAP_1.GAP.gelatoOpts;
50
- if (!useGasless)
51
- throw new Error('Gasless is not enabled.');
52
- if ((sponsorUrl && contained && env_gelatoApiKey) ||
53
- (sponsorUrl && !contained)) {
54
- return sendByUrl(...params);
55
- }
56
- const { wait } = await sendByApiKey(...params);
57
- return wait();
58
- }
59
- exports.sendGelatoTxn = sendGelatoTxn;
60
- /**
61
- * Builds the arguments for a sponsored call using GelatoRelay
62
- * @param data Populated contract call.
63
- * @param chainId
64
- * @param target target contract address (Hex)
65
- *
66
- * @example
67
- *
68
- * ```ts
69
- * const { data } = await contract.populateTransaction.transfer(
70
- * recipient,
71
- * amount
72
- * );
73
- * const args = buildArgs(data, chainId, target);
74
- * const txn = sendGelatoTxn(...args);
75
- * console.log(txn) // 0xabc..
76
- * ```
77
- */
78
- function buildArgs(
79
- /**
80
- * Populated transaction data.
81
- */
82
- data, chainId, target) {
83
- return [
84
- {
85
- data,
86
- chainId,
87
- target,
88
- },
89
- '{apiKey}',
90
- {
91
- retries: 3,
92
- },
93
- ];
94
- }
95
- const Gelato = {
96
- sendByApiKey,
97
- sendByUrl,
98
- buildArgs,
99
- };
100
- exports.Gelato = Gelato;
@@ -1,9 +0,0 @@
1
- export interface ApiRequest {
2
- method: string;
3
- body: unknown;
4
- }
5
- export interface ApiResponse {
6
- statusCode: number;
7
- send: (body: unknown) => void;
8
- }
9
- export declare function handler(req: ApiRequest, res: ApiResponse, env_gelatoApiKey: string): Promise<void>;
@@ -1,60 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.handler = void 0;
4
- const send_gelato_txn_1 = require("./send-gelato-txn");
5
- const assertionObj = [
6
- {
7
- data: /0x[a-fA-F0-9]+/gim,
8
- chainId: /\d+/,
9
- target: /0x[a-fA-F0-9]{40}/gim,
10
- },
11
- /\{apiKey\}/,
12
- {
13
- retries: /\d+/,
14
- },
15
- ];
16
- function assert(body) {
17
- if (!Array.isArray(body) || body.length !== assertionObj.length)
18
- throw new Error("Invalid request body");
19
- assertionObj.forEach((item, index) => {
20
- // check if objects from assertion Object are present in body
21
- // and test them using the regexp from the assertion Object
22
- if (typeof item === "object") {
23
- Object.entries(item).forEach(([key, value]) => {
24
- if (!body[index][key]?.toString().match(value))
25
- throw new Error("Invalid request body");
26
- });
27
- }
28
- // test other items as strings
29
- else if (!body[index]?.toString().match(item))
30
- throw new Error("Invalid request body");
31
- });
32
- return true;
33
- }
34
- async function handler(req, res, env_gelatoApiKey) {
35
- if (req.method !== "POST") {
36
- res.statusCode = 405;
37
- res.send("Method not allowed");
38
- return;
39
- }
40
- try {
41
- const body = req.body;
42
- if (!assert(body))
43
- return;
44
- const { [env_gelatoApiKey]: apiKey } = process.env;
45
- if (!apiKey)
46
- throw new Error("Api key not provided.");
47
- body[1] = apiKey;
48
- const result = await send_gelato_txn_1.Gelato.sendByApiKey(...body);
49
- const txId = await result.wait();
50
- res.send(txId);
51
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
52
- }
53
- catch (error) {
54
- // eslint-disable-next-line no-console
55
- console.log(error);
56
- res.statusCode = 400;
57
- res.send(error.message);
58
- }
59
- }
60
- exports.handler = handler;
@@ -1,7 +0,0 @@
1
- /**
2
- * Waits for a transaction to be mined at Gelato Network
3
- * @param taskId
4
- * @returns
5
- */
6
- declare function watchGelatoTxn(taskId: string, ttl?: number): Promise<string>;
7
- export { watchGelatoTxn };
@@ -1,63 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.watchGelatoTxn = void 0;
4
- const relay_sdk_1 = require("@gelatonetwork/relay-sdk");
5
- var TaskState;
6
- (function (TaskState) {
7
- TaskState["CheckPending"] = "CheckPending";
8
- TaskState["ExecPending"] = "ExecPending";
9
- TaskState["ExecSuccess"] = "ExecSuccess";
10
- TaskState["ExecReverted"] = "ExecReverted";
11
- TaskState["WaitingForConfirmation"] = "WaitingForConfirmation";
12
- TaskState["Blacklisted"] = "Blacklisted";
13
- TaskState["Cancelled"] = "Cancelled";
14
- TaskState["NotFound"] = "NotFound";
15
- })(TaskState || (TaskState = {}));
16
- /**
17
- * Waits for a transaction to be mined at Gelato Network
18
- * @param taskId
19
- * @returns
20
- */
21
- async function watchGelatoTxn(taskId, ttl = 500) {
22
- const client = new relay_sdk_1.GelatoRelay();
23
- return new Promise((resolve, reject) => {
24
- const loop = async () => {
25
- const oneSecond = 1;
26
- try {
27
- while (oneSecond) {
28
- const status = await client.getTaskStatus(taskId);
29
- // print status :D so we can debug this for now
30
- // eslint-disable-next-line no-console
31
- console.log(status);
32
- if (!status) {
33
- reject(new Error('Transaction goes wrong.'));
34
- break;
35
- }
36
- if (status && status.taskState === TaskState.ExecSuccess) {
37
- resolve(status.transactionHash || '');
38
- break;
39
- }
40
- else if ([
41
- TaskState.Cancelled,
42
- TaskState.ExecReverted,
43
- TaskState.Blacklisted,
44
- ].includes(status?.taskState)) {
45
- reject(new Error(status.lastCheckMessage
46
- ?.split(/(RegisterDelegate)|(Execution error): /)
47
- .at(-1) || ''));
48
- break;
49
- }
50
- await new Promise((r) => setTimeout(r, ttl));
51
- }
52
- }
53
- catch {
54
- // gelato may throw 429 error, so we need to retry
55
- // Increase ttl to avoid too deadlocking
56
- // Max ttl is 30s
57
- ttl += Math.max(30000, ttl + 1000);
58
- }
59
- };
60
- loop();
61
- });
62
- }
63
- exports.watchGelatoTxn = watchGelatoTxn;
@@ -1 +0,0 @@
1
- export declare function getDate(date: Date | number): Date;
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getDate = void 0;
4
- function getDate(date) {
5
- return typeof date === "number" ? new Date(date * 1000) : date;
6
- }
7
- exports.getDate = getDate;
@@ -1 +0,0 @@
1
- export declare function getIPFSData<T>(cid: string): Promise<T>;
@@ -1,20 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getIPFSData = void 0;
7
- const axios_1 = __importDefault(require("axios"));
8
- async function getIPFSData(cid) {
9
- try {
10
- const { data } = await axios_1.default.get(`https://ipfs.io/ipfs/${cid}`, {
11
- timeout: 5000,
12
- });
13
- return data;
14
- }
15
- catch (err) {
16
- console.error(err);
17
- throw new Error(`Error to retrive data for CID: ${cid}`);
18
- }
19
- }
20
- exports.getIPFSData = getIPFSData;
@@ -1,2 +0,0 @@
1
- import { ethers } from "ethers";
2
- export declare const getWeb3Provider: (chainId: number) => ethers.JsonRpcProvider;
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getWeb3Provider = void 0;
4
- const consts_1 = require("../consts");
5
- const ethers_1 = require("ethers");
6
- const providers = {};
7
- const getWeb3Provider = (chainId) => {
8
- const rpcUrl = Object.values(consts_1.Networks).find((n) => n.chainId === chainId)
9
- ?.rpcUrl;
10
- if (!rpcUrl) {
11
- throw new Error(`No rpcUrl found for chainId ${chainId}`);
12
- }
13
- if (!providers[chainId]) {
14
- providers[chainId] = new ethers_1.ethers.JsonRpcProvider(rpcUrl);
15
- }
16
- return providers[chainId];
17
- };
18
- exports.getWeb3Provider = getWeb3Provider;
@@ -1,12 +0,0 @@
1
- import { Hex } from "../types";
2
- export declare const gqlQueries: {
3
- attestation: (uid: Hex) => string;
4
- attestations: (schemaId: Hex, uid: Hex) => string;
5
- attestationsIn: (uids: Hex[], search?: string) => string;
6
- attestationsFrom: (schemaId: Hex, attester: Hex) => string;
7
- attestationsTo: (schemaId: Hex, recipient: Hex) => string;
8
- attestationPairs: (schemaId: Hex, attester: Hex, recipient: Hex) => string;
9
- attestationsOf: (schemaId: Hex, search?: string[] | string, refUids?: Hex[]) => string;
10
- dependentsOf: (refs: Hex | Hex[], schemaIds: Hex[], attesters?: Hex[]) => string;
11
- schemata: (creator: Hex) => string;
12
- };
@@ -1,90 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.gqlQueries = void 0;
4
- const inStatement = (values) => `[${values.map((v) => `"${v}"`).join(",")}]`;
5
- const attestationFields = `
6
- uid: id
7
- attester
8
- data
9
- decodedDataJson
10
- recipient
11
- revoked
12
- createdAt: timeCreated
13
- refUID
14
- isOffchain
15
- revocable
16
- revocationTime
17
- schemaId
18
- `;
19
- const schemaQuery = (schemaId, content) => `{schema(where: {id: "${schemaId}"}) {${content}}}`;
20
- exports.gqlQueries = {
21
- attestation: (uid) => `
22
- {
23
- attestation(where: {
24
- id: "${uid}"
25
- }) {${attestationFields}}
26
- }`,
27
- attestations: (schemaId, uid) => schemaQuery(schemaId, `attestations(where: {
28
- revoked: {equals: false}
29
- decodedDataJson: {contains: "${uid}"}
30
- }) {${attestationFields}}`),
31
- attestationsIn: (uids, search) => `
32
- {
33
- attestations(where: {
34
- id:{in: ${inStatement(uids)}}
35
- revoked:{equals:false}
36
- ${search
37
- ? `decodedDataJson:{contains:"${search}",mode:insensitive}`
38
- : ""}
39
- }) {${attestationFields}}
40
- }`,
41
- attestationsFrom: (schemaId, attester) => schemaQuery(schemaId, `attestations(orderBy:{timeCreated: desc},
42
- where:{attester:{equals:"${attester}"}
43
- revoked:{equals:false}
44
- }){${attestationFields}}`),
45
- attestationsTo: (schemaId, recipient) => schemaQuery(schemaId, `attestations(orderBy:{timeCreated: desc},
46
- where:{
47
- recipient:{equals:"${recipient}"}
48
- revoked:{equals:false}
49
- }){${attestationFields}}`),
50
- attestationPairs: (schemaId, attester, recipient) => schemaQuery(schemaId, `attestations(where: {
51
- attester: {equals: "${attester}"}
52
- recipient: {equals: "${recipient}"}
53
- revoked: {equals: false}
54
- }) {${attestationFields}}`),
55
- attestationsOf: (schemaId, search, refUids) => schemaQuery(schemaId, `attestations(orderBy:{timeCreated: desc},
56
- where: {
57
- revoked:{equals:false}
58
- ${refUids && refUids.length
59
- ? `refUID:{in: ${inStatement(refUids)}}`
60
- : ""}
61
- ${search
62
- ? `OR: [
63
- ${[search]
64
- .flat()
65
- .map((s) => `{decodedDataJson:{contains:"${s}",mode:insensitive}}`)
66
- .join(",")}
67
- ]`
68
- : ""}
69
- })
70
- {${attestationFields}}`),
71
- dependentsOf: (refs, schemaIds, attesters = []) => `
72
- {
73
- attestations(
74
- orderBy:{timeCreated: desc},
75
- where: {
76
- refUID:{in: ${inStatement([refs].flat())}}
77
- revoked:{equals: false}
78
- schemaId:{in: ${inStatement(schemaIds)}}
79
- ${attesters.length ? `attester:{in:${inStatement(attesters)}}` : ""}
80
- }){${attestationFields}}
81
- }
82
- `,
83
- schemata: (creator) => `
84
- {
85
- schemata(where: {creator: {equals: "${creator}"}}) {
86
- uid: id
87
- schema
88
- }
89
- }`,
90
- };
@@ -1,23 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./gelato"), exports);
18
- __exportStar(require("./get-date"), exports);
19
- __exportStar(require("./gql-queries"), exports);
20
- __exportStar(require("./map-filter"), exports);
21
- __exportStar(require("./serialize-bigint"), exports);
22
- __exportStar(require("./to-unix"), exports);
23
- __exportStar(require("./get-ipfs-data"), exports);
@@ -1,8 +0,0 @@
1
- /**
2
- * Filters an array by its condition then maps it to the desired format.
3
- * @param arr
4
- * @param condition
5
- * @param mapTo
6
- * @returns
7
- */
8
- export declare function mapFilter<T = unknown, U = unknown>(arr: U[], condition: (item: U) => boolean, mapTo: (item: U) => T): T[];