@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/index.js ADDED
@@ -0,0 +1,24 @@
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("./consts"), exports);
18
+ __exportStar(require("./types"), exports);
19
+ __exportStar(require("./utils"), exports);
20
+ __exportStar(require("./class/GAP"), exports);
21
+ __exportStar(require("./class/GapSchema"), exports);
22
+ __exportStar(require("./class/types/attestations"), exports);
23
+ __exportStar(require("./class/entities"), exports);
24
+ __exportStar(require("./abi"), exports);
@@ -0,0 +1,13 @@
1
+ export interface IGrantUpdateBase {
2
+ title: string;
3
+ text: string;
4
+ proofOfWork?: string;
5
+ completionPercentage?: string;
6
+ pitchDeck?: string;
7
+ demoVideo?: string;
8
+ trackExplanations?: Array<{
9
+ trackId: string;
10
+ trackName: string;
11
+ explanation: string;
12
+ }>;
13
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,131 @@
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" | "custom";
33
+ export type TNetwork = "optimism" | "celo" | "optimism-sepolia" | "arbitrum" | "sepolia" | "sei" | "sei-testnet" | "base-sepolia" | "lisk" | "scroll" | "base" | "polygon";
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 ADDED
@@ -0,0 +1,13 @@
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;
@@ -0,0 +1,19 @@
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);
@@ -0,0 +1,55 @@
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 };
@@ -0,0 +1,100 @@
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;
@@ -0,0 +1,9 @@
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>;
@@ -0,0 +1,60 @@
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;
@@ -0,0 +1,7 @@
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 };
@@ -0,0 +1,63 @@
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;
@@ -0,0 +1 @@
1
+ export declare function getDate(date: Date | number): Date;
@@ -0,0 +1,7 @@
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;
@@ -0,0 +1 @@
1
+ export declare function getIPFSData<T>(cid: string): Promise<T>;
@@ -0,0 +1,20 @@
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;
@@ -0,0 +1,2 @@
1
+ import { ethers } from "ethers";
2
+ export declare const getWeb3Provider: (chainId: number) => ethers.JsonRpcProvider;
@@ -0,0 +1,18 @@
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;
@@ -0,0 +1,12 @@
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
+ };
@@ -0,0 +1,90 @@
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
+ };