@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
@@ -0,0 +1,93 @@
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
+ }
@@ -5,11 +5,13 @@
5
5
  // /* eslint-disable class-methods-use-this */
6
6
  // /* eslint-disable no-useless-constructor */
7
7
  // /* eslint-disable import/no-extraneous-dependencies */
8
+
8
9
  // import { GelatoRelay } from "@gelatonetwork/relay-sdk";
9
10
  // import { ethers } from "ethers";
10
11
  // import axios from "axios";
11
12
  // import ABI from "./";
12
13
  // import { Hex } from "core/types";
14
+
13
15
  // enum TaskState {
14
16
  // CheckPending = "CheckPending",
15
17
  // ExecPending = "ExecPending",
@@ -20,12 +22,15 @@
20
22
  // Cancelled = "Cancelled",
21
23
  // NotFound = "NotFound",
22
24
  // }
25
+
23
26
  // export class DelegateRegistryContract extends GelatoRelay {
24
27
  // contract: ethers.Contract;
28
+
25
29
  // constructor(readonly contractAddress: Hex) {
26
30
  // super();
27
31
  // this.contract = new ethers.Contract(contractAddress, ABI);
28
32
  // }
33
+
29
34
  // /**
30
35
  // * Returns the r, s, v values of a signature
31
36
  // * @param signature
@@ -37,6 +42,7 @@
37
42
  // const v = `0x${signature.slice(130, 132)}`;
38
43
  // return { r, s, v };
39
44
  // }
45
+
40
46
  // /**
41
47
  // * Returns the nonce of a delegate
42
48
  // * @param address
@@ -50,11 +56,13 @@
50
56
  // args: [address],
51
57
  // chainId: 10,
52
58
  // });
59
+
53
60
  // return {
54
61
  // nonce: Number(nonce),
55
62
  // next: Number(nonce + 1n),
56
63
  // };
57
64
  // }
65
+
58
66
  // /**
59
67
  // * Waits for a transaction to be mined at Gelato Network
60
68
  // * @param taskId
@@ -92,12 +100,14 @@
92
100
  // );
93
101
  // break;
94
102
  // }
103
+
95
104
  // await new Promise((r) => setTimeout(r, 500));
96
105
  // }
97
106
  // };
98
107
  // loop();
99
108
  // });
100
109
  // }
110
+
101
111
  // /**
102
112
  // * Executes a transaction on the DelegateRegistry contract
103
113
  // * @param fn the function to call
@@ -117,6 +127,7 @@
117
127
  // wait: () => waitForTransaction({ hash }),
118
128
  // };
119
129
  // }
130
+
120
131
  // public async registerDelegate(data: DelegateWithProfile) {
121
132
  // return this.transaction("registerDelegate", [
122
133
  // data.tokenAddress,
@@ -124,6 +135,7 @@
124
135
  // JSON.stringify(data.profile),
125
136
  // ]);
126
137
  // }
138
+
127
139
  // /**
128
140
  // * Creates the payload for register delegate by signature
129
141
  // * returning the payload
@@ -137,7 +149,9 @@
137
149
  // const { nonce } = await this.getNonce(address);
138
150
  // // 2 minutes expiry
139
151
  // const expiry = ((Date.now() + 1000 * 120) / 1000).toFixed(0);
152
+
140
153
  // const metadata = JSON.stringify(data.profile);
154
+
141
155
  // const types = {
142
156
  // RegisterDelegate: [
143
157
  // { name: "tokenAddress", type: "address" },
@@ -164,7 +178,9 @@
164
178
  // primaryType: "RegisterDelegate",
165
179
  // types,
166
180
  // });
181
+
167
182
  // const { r, s, v } = this.getRSV(signature);
183
+
168
184
  // const { data: payload } =
169
185
  // await this.contract.populateTransaction.registerDelegateBySig(
170
186
  // address,
@@ -177,6 +193,7 @@
177
193
  // r,
178
194
  // s
179
195
  // );
196
+
180
197
  // // eslint-disable-next-line no-console
181
198
  // console.log({ payload, signature, r, s, v });
182
199
  // if (!payload) throw new Error("Payload is undefined");
@@ -192,6 +209,7 @@
192
209
  // },
193
210
  // ];
194
211
  // }
212
+
195
213
  // /**
196
214
  // * Sends a sponsored call to the DelegateRegistry contract using GelatoRelay
197
215
  // * @param payload
@@ -200,11 +218,13 @@
200
218
  // static async sendGelato(...params: Parameters<GelatoRelay["sponsoredCall"]>) {
201
219
  // const client = new this(params[0].target as Hex);
202
220
  // const relayResponse = await client.sponsoredCall(...params);
221
+
203
222
  // return {
204
223
  // taskId: relayResponse.taskId,
205
224
  // wait: () => client.wait(relayResponse.taskId),
206
225
  // };
207
226
  // }
227
+
208
228
  // /**
209
229
  // * Deregisters a delegate on the DelegateRegistry contract
210
230
  // * @param tokenAddress
@@ -214,6 +234,7 @@
214
234
  // public deregisterDelegate(tokenAddress: string, tokenChainId: number) {
215
235
  // return this.transaction("deregisterDelegate", [tokenAddress, tokenChainId]);
216
236
  // }
237
+
217
238
  // /**
218
239
  // * Returns a delegate from the DelegateRegistry contract
219
240
  // * @param delegateAddress
@@ -244,6 +265,7 @@
244
265
  // interests
245
266
  // }
246
267
  // }`;
268
+
247
269
  // const {
248
270
  // data: {
249
271
  // data: { delegates },
@@ -251,6 +273,7 @@
251
273
  // } = await axios.post<{ data: DelegateStatementRes }>(this.subgraphUrl, {
252
274
  // query,
253
275
  // });
276
+
254
277
  // return delegates.map((item) => {
255
278
  // if (Array.isArray(item?.interests))
256
279
  // return item as DelegateRegistryWithInterests;
@@ -0,0 +1,188 @@
1
+ import { ethers, formatEther } from "ethers";
2
+ import AlloContractABI from "../../abi/Allo.json";
3
+ import { AlloContracts } from "../../consts";
4
+ import { Address } from "../types/allo";
5
+ import { AbiCoder } from "ethers";
6
+ import { Allo } from "@allo-team/allo-v2-sdk/";
7
+ import { CreatePoolArgs } from "@allo-team/allo-v2-sdk/dist/Allo/types";
8
+ import { TransactionData } from "@allo-team/allo-v2-sdk/dist/Common/types";
9
+ import axios from "axios";
10
+
11
+ // ABI fragment for the Initialized event
12
+ const INITIALIZED_EVENT = ["event Initialized(uint256 poolId, bytes data)"];
13
+
14
+ export class AlloBase {
15
+ private signer: ethers.Signer;
16
+ private contract: ethers.Contract;
17
+ private allo: Allo;
18
+ private pinataJWTToken: string;
19
+
20
+ constructor(signer: ethers.Signer, pinataJWTToken: string, chainId: number) {
21
+ this.signer = signer;
22
+ this.contract = new ethers.Contract(
23
+ AlloContracts.alloProxy,
24
+ AlloContractABI,
25
+ signer
26
+ );
27
+ this.allo = new Allo({ chain: chainId });
28
+ this.pinataJWTToken = pinataJWTToken;
29
+ }
30
+
31
+ async saveAndGetCID(
32
+ data: any,
33
+ pinataMetadata = { name: "via karma-gap-sdk" }
34
+ ) {
35
+ try {
36
+ const res = await axios.post(
37
+ "https://api.pinata.cloud/pinning/pinJSONToIPFS",
38
+ {
39
+ pinataContent: data,
40
+ pinataMetadata: pinataMetadata,
41
+ },
42
+ {
43
+ headers: {
44
+ "Content-Type": "application/json",
45
+ Authorization: `Bearer ${this.pinataJWTToken}`,
46
+ },
47
+ }
48
+ );
49
+ return res.data.IpfsHash;
50
+ } catch (error) {
51
+ console.log(error);
52
+ }
53
+ }
54
+
55
+ async encodeStrategyInitData(
56
+ applicationStart: number,
57
+ applicationEnd: number,
58
+ roundStart: number,
59
+ roundEnd: number,
60
+ payoutToken: string
61
+ ) {
62
+ const encoder = new AbiCoder();
63
+ const initStrategyData = encoder.encode(
64
+ ["bool", "bool", "uint256", "uint256", "uint256", "uint256", "address[]"],
65
+ [
66
+ false, // useRegistryAnchor
67
+ true, // metadataRequired
68
+ applicationStart, // Eg. Curr + 1 hour later registrationStartTime
69
+ applicationEnd, // Eg. Curr + 5 days later registrationEndTime
70
+ roundStart, // Eg. Curr + 2 hours later allocationStartTime
71
+ roundEnd, // Eg. Curr + 10 days later allocaitonEndTime
72
+ [payoutToken],
73
+ ]
74
+ );
75
+
76
+ return initStrategyData;
77
+ }
78
+
79
+ async createGrant(args: any, callback?: Function) {
80
+ console.log("Creating grant...");
81
+ const walletBalance = await this.signer.provider.getBalance(
82
+ await this.signer.getAddress()
83
+ );
84
+
85
+ console.log(
86
+ "Wallet balance:",
87
+ formatEther(walletBalance.toString()),
88
+ " ETH"
89
+ );
90
+
91
+ try {
92
+ const metadata_cid = await this.saveAndGetCID({
93
+ round: args.roundMetadata,
94
+ application: args.applicationMetadata,
95
+ });
96
+
97
+ const metadata = {
98
+ protocol: BigInt(1),
99
+ pointer: metadata_cid,
100
+ };
101
+
102
+ const initStrategyData = (await this.encodeStrategyInitData(
103
+ args.applicationStart,
104
+ args.applicationEnd,
105
+ args.roundStart,
106
+ args.roundEnd,
107
+ args.payoutToken
108
+ )) as Address;
109
+
110
+ const createPoolArgs: CreatePoolArgs = {
111
+ profileId: args.profileId,
112
+ strategy: args.strategy,
113
+ initStrategyData: initStrategyData, // unique to the strategy
114
+ token: args.payoutToken,
115
+ amount: BigInt(args.matchingFundAmt),
116
+ metadata: metadata,
117
+ managers: args.managers,
118
+ };
119
+
120
+ callback?.("preparing");
121
+ const txData: TransactionData = this.allo.createPool(createPoolArgs);
122
+
123
+ const tx = await this.signer.sendTransaction({
124
+ data: txData.data,
125
+ to: txData.to,
126
+ value: BigInt(txData.value),
127
+ });
128
+ callback?.("pending");
129
+ const receipt = await tx.wait();
130
+ callback?.("confirmed");
131
+
132
+ // Create interface to parse the logs
133
+ const iface = new ethers.Interface(INITIALIZED_EVENT);
134
+ let poolId;
135
+
136
+ // Find the Initialized event in the logs
137
+ const initializedLog = receipt.logs.find((log) => {
138
+ try {
139
+ const parsed = iface.parseLog(log);
140
+ return parsed.name === "Initialized";
141
+ } catch {
142
+ return false;
143
+ }
144
+ });
145
+
146
+ if (initializedLog) {
147
+ const parsedLog = iface.parseLog(initializedLog);
148
+ poolId = parsedLog.args.poolId.toString();
149
+ console.log(`Transaction ${tx.hash} - Found poolId: ${poolId}`);
150
+ } else {
151
+ poolId = receipt.logs[receipt.logs.length - 1].topics[1]; // Fallback to Initialized order logic
152
+ console.log(`No Initialized event found in tx ${tx.hash}`);
153
+ }
154
+
155
+ return {
156
+ poolId: BigInt(poolId).toString(),
157
+ txHash: tx.hash,
158
+ };
159
+ } catch (error) {
160
+ console.error(`Failed to create pool: ${error}`);
161
+ throw new Error(`Failed to create pool metadata: ${error}`);
162
+ }
163
+ }
164
+
165
+ async updatePoolMetadata(
166
+ poolId: string,
167
+ poolMetadata: any,
168
+ callback?: Function
169
+ ) {
170
+ try {
171
+ callback?.("preparing");
172
+ const metadata_cid = await this.saveAndGetCID(poolMetadata);
173
+ const metadata = {
174
+ protocol: 1,
175
+ pointer: metadata_cid,
176
+ };
177
+
178
+ const tx = await this.contract.updatePoolMetadata(poolId, metadata);
179
+ callback?.("pending");
180
+ const receipt = await tx.wait();
181
+ callback?.("confirmed");
182
+ return receipt;
183
+ } catch (error) {
184
+ console.error(`Failed to update pool metadata: ${error}`);
185
+ throw new Error(`Failed to update pool metadata: ${error}`);
186
+ }
187
+ }
188
+ }
@@ -0,0 +1,101 @@
1
+ import { ethers } from "ethers";
2
+ import AlloRegistryABI from "../../abi/AlloRegistry.json";
3
+ import { AlloContracts } from "../../consts";
4
+ import { ProfileMetadata } from "../types/allo";
5
+ import axios from "axios";
6
+
7
+ export class AlloRegistry {
8
+ private contract: ethers.Contract;
9
+ private pinataJWTToken: string;
10
+
11
+ constructor(signer: ethers.Signer, pinataJWTToken: string) {
12
+ this.contract = new ethers.Contract(
13
+ AlloContracts.registry,
14
+ AlloRegistryABI,
15
+ signer
16
+ );
17
+
18
+ this.pinataJWTToken = pinataJWTToken;
19
+ }
20
+
21
+ async saveAndGetCID(
22
+ data: any,
23
+ pinataMetadata = { name: "via karma-gap-sdk" }
24
+ ) {
25
+ try {
26
+ const res = await axios.post(
27
+ "https://api.pinata.cloud/pinning/pinJSONToIPFS",
28
+ {
29
+ pinataContent: data,
30
+ pinataMetadata: pinataMetadata,
31
+ },
32
+ {
33
+ headers: {
34
+ "Content-Type": "application/json",
35
+ Authorization: `Bearer ${this.pinataJWTToken}`,
36
+ },
37
+ }
38
+ );
39
+ return res.data.IpfsHash;
40
+ } catch (error) {
41
+ console.log(error);
42
+ }
43
+ }
44
+
45
+ async createProgram(
46
+ nonce: number,
47
+ name: string,
48
+ profileMetadata: ProfileMetadata,
49
+ owner: string,
50
+ members: string[]
51
+ ) {
52
+ console.log("Creating program...");
53
+ try {
54
+ const metadata_cid = await this.saveAndGetCID(profileMetadata);
55
+ const metadata = {
56
+ protocol: 1,
57
+ pointer: metadata_cid,
58
+ };
59
+
60
+ const tx = await this.contract.createProfile(
61
+ nonce,
62
+ name,
63
+ metadata,
64
+ owner,
65
+ members
66
+ );
67
+ const receipt = await tx.wait();
68
+
69
+ // Get ProfileCreated event
70
+ const profileCreatedEvent = receipt.logs.find(
71
+ (event) => event.eventName === "ProfileCreated"
72
+ );
73
+
74
+ return {
75
+ profileId: profileCreatedEvent.args[0],
76
+ txHash: receipt.hash,
77
+ };
78
+ } catch (error) {
79
+ console.error(`Failed to register program: ${error}`);
80
+ }
81
+ }
82
+
83
+ async updateProgramMetadata(
84
+ profileId: string,
85
+ profileMetadata: ProfileMetadata
86
+ ) {
87
+ try {
88
+ const metadata_cid = await this.saveAndGetCID(profileMetadata);
89
+ const metadata = {
90
+ protocol: 1,
91
+ pointer: metadata_cid,
92
+ };
93
+
94
+ const tx = await this.contract.updateProfileMetadata(profileId, metadata);
95
+ const receipt = await tx.wait();
96
+ return receipt;
97
+ } catch (error) {
98
+ console.error(`Failed to update profile metadata: ${error}`);
99
+ }
100
+ }
101
+ }
@@ -0,0 +1,29 @@
1
+ import type { AxiosInstance } from "axios";
2
+ import axios from "axios";
3
+
4
+ export abstract class AxiosGQL {
5
+ protected client: AxiosInstance;
6
+
7
+ constructor(url: string) {
8
+ this.client = axios.create({
9
+ baseURL: url,
10
+ headers: {
11
+ "Content-Type": "application/json",
12
+ },
13
+ });
14
+ }
15
+
16
+ protected async query<R = unknown, T = unknown>(
17
+ query: string,
18
+ variables?: T
19
+ ): Promise<R> {
20
+ const {
21
+ data: { data },
22
+ } = await this.client.post<{ data: R }>("", {
23
+ query,
24
+ variables,
25
+ });
26
+
27
+ return data;
28
+ }
29
+ }
@@ -0,0 +1,34 @@
1
+ import { Networks } from "../../consts";
2
+ import { EASNetworkConfig, Hex, TNetwork } from "../../types";
3
+ import { AxiosGQL } from "./AxiosGQL";
4
+
5
+ interface EASClientProps {
6
+ network: TNetwork;
7
+ }
8
+
9
+ export class EASClient extends AxiosGQL implements EASClientProps {
10
+ private readonly _network: EASNetworkConfig & { name: TNetwork };
11
+
12
+ constructor(args: EASClientProps) {
13
+ const { network } = args;
14
+ super(Networks[network].url);
15
+
16
+ this.assert(args);
17
+
18
+ this._network = { ...Networks[network], name: network };
19
+ }
20
+
21
+ /**
22
+ * Validate the constructor arguments
23
+ * @param args
24
+ */
25
+ private assert(args: EASClientProps) {
26
+ if (!Networks[args.network]) {
27
+ throw new Error("Invalid network");
28
+ }
29
+ }
30
+
31
+ get network(): TNetwork {
32
+ return this._network.name;
33
+ }
34
+ }