@coinbase/agentkit 0.9.0 → 0.9.1

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 (42) hide show
  1. package/README.md +31 -1
  2. package/dist/action-providers/farcaster/farcasterActionProvider.js +2 -0
  3. package/dist/action-providers/farcaster/farcasterActionProvider.test.js +55 -0
  4. package/dist/action-providers/farcaster/schemas.d.ts +13 -0
  5. package/dist/action-providers/farcaster/schemas.js +6 -0
  6. package/dist/action-providers/index.d.ts +2 -0
  7. package/dist/action-providers/index.js +2 -0
  8. package/dist/action-providers/truemarkets/constants.d.ts +179 -0
  9. package/dist/action-providers/truemarkets/constants.js +46 -0
  10. package/dist/action-providers/truemarkets/index.d.ts +1 -0
  11. package/dist/action-providers/truemarkets/index.js +17 -0
  12. package/dist/action-providers/truemarkets/schemas.d.ts +21 -0
  13. package/dist/action-providers/truemarkets/schemas.js +29 -0
  14. package/dist/action-providers/truemarkets/truemarketsActionProvider.d.ts +51 -0
  15. package/dist/action-providers/truemarkets/truemarketsActionProvider.js +469 -0
  16. package/dist/action-providers/truemarkets/truemarketsActionProvider.test.d.ts +1 -0
  17. package/dist/action-providers/truemarkets/truemarketsActionProvider.test.js +217 -0
  18. package/dist/action-providers/truemarkets/utils.d.ts +10 -0
  19. package/dist/action-providers/truemarkets/utils.js +9 -0
  20. package/dist/action-providers/twitter/schemas.d.ts +16 -0
  21. package/dist/action-providers/twitter/schemas.js +23 -1
  22. package/dist/action-providers/twitter/twitterActionProvider.d.ts +8 -1
  23. package/dist/action-providers/twitter/twitterActionProvider.js +56 -5
  24. package/dist/action-providers/twitter/twitterActionProvider.test.js +52 -2
  25. package/dist/action-providers/weth/constants.d.ts +9 -0
  26. package/dist/action-providers/weth/constants.js +12 -0
  27. package/dist/action-providers/weth/schemas.d.ts +7 -0
  28. package/dist/action-providers/weth/schemas.js +7 -1
  29. package/dist/action-providers/weth/wethActionProvider.d.ts +9 -1
  30. package/dist/action-providers/weth/wethActionProvider.js +50 -1
  31. package/dist/action-providers/weth/wethActionProvider.test.js +60 -0
  32. package/dist/action-providers/zora/index.d.ts +3 -0
  33. package/dist/action-providers/zora/index.js +19 -0
  34. package/dist/action-providers/zora/schemas.d.ts +29 -0
  35. package/dist/action-providers/zora/schemas.js +31 -0
  36. package/dist/action-providers/zora/utils.d.ts +28 -0
  37. package/dist/action-providers/zora/utils.js +200 -0
  38. package/dist/action-providers/zora/zoraActionProvider.d.ts +36 -0
  39. package/dist/action-providers/zora/zoraActionProvider.js +151 -0
  40. package/dist/action-providers/zora/zoraActionProvider.test.d.ts +1 -0
  41. package/dist/action-providers/zora/zoraActionProvider.test.js +205 -0
  42. package/package.json +2 -1
@@ -58,6 +58,30 @@ class WethActionProvider extends actionProvider_1.ActionProvider {
58
58
  return `Error wrapping ETH: ${error}`;
59
59
  }
60
60
  }
61
+ /**
62
+ * Unwraps WETH to ETH.
63
+ *
64
+ * @param walletProvider - The wallet provider to use for the action.
65
+ * @param args - The input arguments for the action.
66
+ * @returns A message containing the transaction hash.
67
+ */
68
+ async unwrapEth(walletProvider, args) {
69
+ try {
70
+ const hash = await walletProvider.sendTransaction({
71
+ to: constants_1.WETH_ADDRESS,
72
+ data: (0, viem_1.encodeFunctionData)({
73
+ abi: constants_1.WETH_ABI,
74
+ functionName: "withdraw",
75
+ args: [BigInt(args.amountToUnwrap)],
76
+ }),
77
+ });
78
+ await walletProvider.waitForTransactionReceipt(hash);
79
+ return `Unwrapped WETH with transaction hash: ${hash}`;
80
+ }
81
+ catch (error) {
82
+ return `Error unwrapping WETH: ${error}`;
83
+ }
84
+ }
61
85
  }
62
86
  exports.WethActionProvider = WethActionProvider;
63
87
  __decorate([
@@ -74,7 +98,7 @@ Important notes:
74
98
  - The amount is a string and cannot have any decimal points, since the unit of measurement is wei.
75
99
  - Make sure to use the exact amount provided, and if there's any doubt, check by getting more information before continuing with the action.
76
100
  - 1 wei = 0.000000000000000001 WETH
77
- - Minimum purchase amount is 100000000000000 wei (0.0000001 WETH)
101
+ - Minimum purchase amount is 100000000000 wei (0.0000001 WETH)
78
102
  - Only supported on the following networks:
79
103
  - Base Sepolia (ie, 'base-sepolia')
80
104
  - Base Mainnet (ie, 'base', 'base-mainnet')
@@ -85,5 +109,30 @@ Important notes:
85
109
  __metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider, void 0]),
86
110
  __metadata("design:returntype", Promise)
87
111
  ], WethActionProvider.prototype, "wrapEth", null);
112
+ __decorate([
113
+ (0, actionDecorator_1.CreateAction)({
114
+ name: "unwrap_eth",
115
+ description: `
116
+ This tool can only be used to unwrap WETH to ETH.
117
+ Do not use this tool for any other purpose, or trading other assets.
118
+
119
+ Inputs:
120
+ - Amount of WETH to unwrap.
121
+
122
+ Important notes:
123
+ - The amount is a string and cannot have any decimal points, since the unit of measurement is wei.
124
+ - Make sure to use the exact amount provided, and if there's any doubt, check by getting more information before continuing with the action.
125
+ - 1 wei = 0.000000000000000001 WETH
126
+ - Minimum unwrap amount is 100000000000 wei (0.0000001 WETH)
127
+ - Only supported on the following networks:
128
+ - Base Sepolia (ie, 'base-sepolia')
129
+ - Base Mainnet (ie, 'base', 'base-mainnet')
130
+ `,
131
+ schema: schemas_1.UnwrapEthSchema,
132
+ }),
133
+ __metadata("design:type", Function),
134
+ __metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider, void 0]),
135
+ __metadata("design:returntype", Promise)
136
+ ], WethActionProvider.prototype, "unwrapEth", null);
88
137
  const wethActionProvider = () => new WethActionProvider();
89
138
  exports.wethActionProvider = wethActionProvider;
@@ -21,6 +21,21 @@ describe("Wrap Eth Schema", () => {
21
21
  expect(result.success).toBe(false);
22
22
  });
23
23
  });
24
+ describe("Unwrap Eth Schema", () => {
25
+ it("should successfully parse valid input", () => {
26
+ const validInput = {
27
+ amountToUnwrap: MOCK_AMOUNT,
28
+ };
29
+ const result = schemas_1.UnwrapEthSchema.safeParse(validInput);
30
+ expect(result.success).toBe(true);
31
+ expect(result.data).toEqual(validInput);
32
+ });
33
+ it("should fail parsing empty input", () => {
34
+ const emptyInput = {};
35
+ const result = schemas_1.UnwrapEthSchema.safeParse(emptyInput);
36
+ expect(result.success).toBe(false);
37
+ });
38
+ });
24
39
  describe("Wrap Eth Action", () => {
25
40
  let mockWallet;
26
41
  const actionProvider = (0, wethActionProvider_1.wethActionProvider)();
@@ -66,6 +81,51 @@ describe("Wrap Eth Action", () => {
66
81
  expect(response).toContain(`Error wrapping ETH: ${error}`);
67
82
  });
68
83
  });
84
+ describe("Unwrap Eth Action", () => {
85
+ let mockWallet;
86
+ const actionProvider = (0, wethActionProvider_1.wethActionProvider)();
87
+ beforeEach(async () => {
88
+ mockWallet = {
89
+ getAddress: jest.fn().mockReturnValue(MOCK_ADDRESS),
90
+ sendTransaction: jest.fn(),
91
+ waitForTransactionReceipt: jest.fn(),
92
+ };
93
+ });
94
+ it("should successfully respond", async () => {
95
+ const args = {
96
+ amountToUnwrap: MOCK_AMOUNT,
97
+ };
98
+ const hash = "0x1234567890123456789012345678901234567890";
99
+ mockWallet.sendTransaction.mockResolvedValue(hash);
100
+ const response = await actionProvider.unwrapEth(mockWallet, args);
101
+ expect(mockWallet.sendTransaction).toHaveBeenCalledWith({
102
+ to: constants_1.WETH_ADDRESS,
103
+ data: (0, viem_1.encodeFunctionData)({
104
+ abi: constants_1.WETH_ABI,
105
+ functionName: "withdraw",
106
+ args: [BigInt(MOCK_AMOUNT)],
107
+ }),
108
+ });
109
+ expect(response).toContain(`Unwrapped WETH with transaction hash: ${hash}`);
110
+ });
111
+ it("should fail with an error", async () => {
112
+ const args = {
113
+ amountToUnwrap: MOCK_AMOUNT,
114
+ };
115
+ const error = new Error("Failed to unwrap WETH");
116
+ mockWallet.sendTransaction.mockRejectedValue(error);
117
+ const response = await actionProvider.unwrapEth(mockWallet, args);
118
+ expect(mockWallet.sendTransaction).toHaveBeenCalledWith({
119
+ to: constants_1.WETH_ADDRESS,
120
+ data: (0, viem_1.encodeFunctionData)({
121
+ abi: constants_1.WETH_ABI,
122
+ functionName: "withdraw",
123
+ args: [BigInt(MOCK_AMOUNT)],
124
+ }),
125
+ });
126
+ expect(response).toContain(`Error unwrapping WETH: ${error}`);
127
+ });
128
+ });
69
129
  describe("supportsNetwork", () => {
70
130
  const actionProvider = (0, wethActionProvider_1.wethActionProvider)();
71
131
  it("should return true for base-mainnet", () => {
@@ -0,0 +1,3 @@
1
+ export * from "./zoraActionProvider";
2
+ export * from "./schemas";
3
+ export * from "./utils";
@@ -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("./zoraActionProvider"), exports);
18
+ __exportStar(require("./schemas"), exports);
19
+ __exportStar(require("./utils"), exports);
@@ -0,0 +1,29 @@
1
+ import { z } from "zod";
2
+ export declare const CreateCoinSchema: z.ZodObject<{
3
+ name: z.ZodString;
4
+ symbol: z.ZodString;
5
+ description: z.ZodString;
6
+ image: z.ZodString;
7
+ category: z.ZodDefault<z.ZodString>;
8
+ payoutRecipient: z.ZodOptional<z.ZodString>;
9
+ platformReferrer: z.ZodOptional<z.ZodString>;
10
+ currency: z.ZodDefault<z.ZodEnum<["ZORA", "ETH"]>>;
11
+ }, "strip", z.ZodTypeAny, {
12
+ symbol: string;
13
+ name: string;
14
+ description: string;
15
+ currency: "ETH" | "ZORA";
16
+ image: string;
17
+ category: string;
18
+ platformReferrer?: string | undefined;
19
+ payoutRecipient?: string | undefined;
20
+ }, {
21
+ symbol: string;
22
+ name: string;
23
+ description: string;
24
+ image: string;
25
+ currency?: "ETH" | "ZORA" | undefined;
26
+ platformReferrer?: string | undefined;
27
+ category?: string | undefined;
28
+ payoutRecipient?: string | undefined;
29
+ }>;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CreateCoinSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ exports.CreateCoinSchema = zod_1.z
6
+ .object({
7
+ name: zod_1.z.string().describe("The name of the coin to create"),
8
+ symbol: zod_1.z.string().describe("The symbol of the coin to create"),
9
+ description: zod_1.z.string().describe("The description of the coin"),
10
+ image: zod_1.z.string().describe("Local image file path or URI (ipfs:// or https://)"),
11
+ category: zod_1.z
12
+ .string()
13
+ .default("social")
14
+ .describe("The category of the coin, optional, defaults to 'social'"),
15
+ payoutRecipient: zod_1.z
16
+ .string()
17
+ .regex(/^0x[a-fA-F0-9]{40}$/, "Invalid Ethereum address format")
18
+ .optional()
19
+ .describe("The address that will receive creator earnings, defaults to wallet address"),
20
+ platformReferrer: zod_1.z
21
+ .string()
22
+ .regex(/^0x[a-fA-F0-9]{40}$/, "Invalid Ethereum address format")
23
+ .optional()
24
+ .describe("The address that will receive platform referrer fees, optional"),
25
+ currency: zod_1.z
26
+ .enum(["ZORA", "ETH"])
27
+ .default("ZORA")
28
+ .describe("Currency to be used for the trading pair, optional, defaults to 'ZORA'."),
29
+ })
30
+ .strip()
31
+ .describe("Instructions for creating a new coin on Zora");
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Configuration for Pinata
3
+ */
4
+ interface PinataConfig {
5
+ jwt: string;
6
+ }
7
+ /**
8
+ * Parameters for generating token URI
9
+ */
10
+ interface TokenUriParams {
11
+ name: string;
12
+ symbol: string;
13
+ description: string;
14
+ image: string;
15
+ category?: string;
16
+ pinataConfig: PinataConfig;
17
+ }
18
+ /**
19
+ * Generates a Zora token URI by handling local file or URI
20
+ *
21
+ * @param params - Parameters for generating the token URI
22
+ * @returns A promise that resolves to object containing the IPFS URI
23
+ */
24
+ export declare function generateZoraTokenUri(params: TokenUriParams): Promise<{
25
+ uri: string;
26
+ imageUri: string;
27
+ }>;
28
+ export {};
@@ -0,0 +1,200 @@
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.generateZoraTokenUri = generateZoraTokenUri;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ /**
10
+ * Reads a local file and converts it to base64
11
+ *
12
+ * @param imageFileName - Path to the local file
13
+ * @returns Base64 encoded file and mime type
14
+ */
15
+ async function readFileAsBase64(imageFileName) {
16
+ return new Promise((resolve, reject) => {
17
+ fs_1.default.readFile(imageFileName, (err, data) => {
18
+ if (err) {
19
+ reject(new Error(`Failed to read file: ${err.message}`));
20
+ return;
21
+ }
22
+ // Determine mime type based on file extension
23
+ const extension = path_1.default.extname(imageFileName).toLowerCase();
24
+ let mimeType = "application/octet-stream"; // default
25
+ if (extension === ".png")
26
+ mimeType = "image/png";
27
+ else if (extension === ".jpg" || extension === ".jpeg")
28
+ mimeType = "image/jpeg";
29
+ else if (extension === ".gif")
30
+ mimeType = "image/gif";
31
+ else if (extension === ".svg")
32
+ mimeType = "image/svg+xml";
33
+ const base64 = data.toString("base64");
34
+ resolve({ base64, mimeType });
35
+ });
36
+ });
37
+ }
38
+ /**
39
+ * Uploads a file to IPFS using Pinata
40
+ *
41
+ * @param params - Configuration and file data
42
+ * @param params.pinataConfig - Pinata configuration including JWT
43
+ * @param params.fileData - Base64 encoded file data
44
+ * @param params.fileName - Name for the uploaded file
45
+ * @param params.mimeType - MIME type of the file
46
+ * @returns Upload response with CID and other details
47
+ */
48
+ async function uploadFileToIPFS(params) {
49
+ try {
50
+ const formData = new FormData();
51
+ // Convert base64 to Blob and then to File
52
+ const byteCharacters = atob(params.fileData);
53
+ const byteArrays = [];
54
+ for (let offset = 0; offset < byteCharacters.length; offset += 1024) {
55
+ const slice = byteCharacters.slice(offset, offset + 1024);
56
+ const byteNumbers = new Array(slice.length);
57
+ for (let i = 0; i < slice.length; i++) {
58
+ byteNumbers[i] = slice.charCodeAt(i);
59
+ }
60
+ const byteArray = new Uint8Array(byteNumbers);
61
+ byteArrays.push(byteArray);
62
+ }
63
+ const blob = new Blob(byteArrays, { type: params.mimeType });
64
+ const file = new File([blob], params.fileName, { type: params.mimeType });
65
+ formData.append("file", file);
66
+ const pinataMetadata = {
67
+ name: params.fileName,
68
+ };
69
+ formData.append("pinataMetadata", JSON.stringify(pinataMetadata));
70
+ const pinataOptions = {
71
+ cidVersion: 1,
72
+ };
73
+ formData.append("pinataOptions", JSON.stringify(pinataOptions));
74
+ const response = await fetch("https://api.pinata.cloud/pinning/pinFileToIPFS", {
75
+ method: "POST",
76
+ headers: {
77
+ Authorization: `Bearer ${params.pinataConfig.jwt}`,
78
+ },
79
+ body: formData,
80
+ });
81
+ if (!response.ok) {
82
+ const error = await response.json();
83
+ throw new Error(`Failed to upload file to IPFS: ${error.message || response.statusText}`);
84
+ }
85
+ const data = await response.json();
86
+ return {
87
+ IpfsHash: data.IpfsHash,
88
+ PinSize: data.PinSize,
89
+ Timestamp: data.Timestamp,
90
+ isDuplicate: data.isDuplicate || false,
91
+ };
92
+ }
93
+ catch (error) {
94
+ if (error instanceof Error) {
95
+ throw new Error(`Failed to upload file to IPFS: ${error.message}`);
96
+ }
97
+ throw error;
98
+ }
99
+ }
100
+ /**
101
+ * Uploads JSON data to IPFS using Pinata
102
+ *
103
+ * @param params - Configuration and JSON data
104
+ * @param params.pinataConfig - Pinata configuration including JWT
105
+ * @param params.json - JSON data to upload
106
+ * @returns Upload response with CID and other details
107
+ */
108
+ async function uploadJsonToIPFS(params) {
109
+ try {
110
+ const requestBody = {
111
+ pinataOptions: {
112
+ cidVersion: 1,
113
+ },
114
+ pinataMetadata: {
115
+ name: `${params.json.name}-metadata.json`,
116
+ },
117
+ pinataContent: params.json,
118
+ };
119
+ const response = await fetch("https://api.pinata.cloud/pinning/pinJSONToIPFS", {
120
+ method: "POST",
121
+ headers: {
122
+ Authorization: `Bearer ${params.pinataConfig.jwt}`,
123
+ "Content-Type": "application/json",
124
+ },
125
+ body: JSON.stringify(requestBody),
126
+ });
127
+ if (!response.ok) {
128
+ const error = await response.json();
129
+ throw new Error(`Failed to upload JSON to IPFS: ${error.message || response.statusText}`);
130
+ }
131
+ const data = await response.json();
132
+ return {
133
+ IpfsHash: data.IpfsHash,
134
+ PinSize: data.PinSize,
135
+ Timestamp: data.Timestamp,
136
+ isDuplicate: data.isDuplicate || false,
137
+ };
138
+ }
139
+ catch (error) {
140
+ if (error instanceof Error) {
141
+ throw new Error(`Failed to upload JSON to IPFS: ${error.message}`);
142
+ }
143
+ throw error;
144
+ }
145
+ }
146
+ /**
147
+ * Generates a Zora token URI by handling local file or URI
148
+ *
149
+ * @param params - Parameters for generating the token URI
150
+ * @returns A promise that resolves to object containing the IPFS URI
151
+ */
152
+ async function generateZoraTokenUri(params) {
153
+ try {
154
+ let imageUri;
155
+ // Check if image is already a URI (ipfs:// or https://)
156
+ if (params.image.startsWith("ipfs://") || params.image.startsWith("https://")) {
157
+ imageUri = params.image;
158
+ }
159
+ else {
160
+ // Handle local file
161
+ const { base64, mimeType } = await readFileAsBase64(params.image);
162
+ const fileName = path_1.default.basename(params.image);
163
+ const imageRes = await uploadFileToIPFS({
164
+ pinataConfig: params.pinataConfig,
165
+ fileData: base64,
166
+ fileName,
167
+ mimeType,
168
+ });
169
+ imageUri = `ipfs://${imageRes.IpfsHash}`;
170
+ }
171
+ // Create and upload the metadata
172
+ const metadata = {
173
+ name: params.name,
174
+ description: params.description,
175
+ symbol: params.symbol,
176
+ image: imageUri,
177
+ content: {
178
+ uri: imageUri,
179
+ mime: imageUri.startsWith("ipfs://") || imageUri.startsWith("https://")
180
+ ? "image/*"
181
+ : "image/png",
182
+ },
183
+ properties: {
184
+ category: params.category || "social",
185
+ },
186
+ };
187
+ const metadataRes = await uploadJsonToIPFS({
188
+ pinataConfig: params.pinataConfig,
189
+ json: metadata,
190
+ });
191
+ const uri = `ipfs://${metadataRes.IpfsHash}`;
192
+ return { uri, imageUri };
193
+ }
194
+ catch (error) {
195
+ if (error instanceof Error) {
196
+ throw new Error(`Failed to generate Zora token URI: ${error.message}`);
197
+ }
198
+ throw error;
199
+ }
200
+ }
@@ -0,0 +1,36 @@
1
+ import { z } from "zod";
2
+ import { ActionProvider } from "../actionProvider";
3
+ import { EvmWalletProvider } from "../../wallet-providers/evmWalletProvider";
4
+ import { CreateCoinSchema } from "./schemas";
5
+ import { Network } from "../../network";
6
+ /**
7
+ * ZoraActionProvider provides actions for interacting with the Zora protocol.
8
+ */
9
+ export declare class ZoraActionProvider extends ActionProvider<EvmWalletProvider> {
10
+ #private;
11
+ /**
12
+ * Constructor for the ZoraActionProvider.
13
+ */
14
+ constructor();
15
+ /**
16
+ * Creates a new Zora coin.
17
+ *
18
+ * @param walletProvider - The wallet provider to use for the transaction.
19
+ * @param args - The input arguments for the action.
20
+ * @returns A message containing the coin creation details.
21
+ */
22
+ createCoin(walletProvider: EvmWalletProvider, args: z.infer<typeof CreateCoinSchema>): Promise<string>;
23
+ /**
24
+ * Checks if the Zora action provider supports the given network.
25
+ *
26
+ * @param network - The network to check.
27
+ * @returns True if the Zora action provider supports the network, false otherwise.
28
+ */
29
+ supportsNetwork: (network: Network) => boolean;
30
+ }
31
+ /**
32
+ * Factory function to create a new ZoraActionProvider instance.
33
+ *
34
+ * @returns A new ZoraActionProvider instance
35
+ */
36
+ export declare const zoraActionProvider: () => ZoraActionProvider;
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
12
+ if (kind === "m") throw new TypeError("Private method is not writable");
13
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
14
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
15
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
16
+ };
17
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
18
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
19
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
20
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
21
+ };
22
+ var _ZoraActionProvider_pinataJwt;
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.zoraActionProvider = exports.ZoraActionProvider = void 0;
25
+ const zod_1 = require("zod");
26
+ const actionProvider_1 = require("../actionProvider");
27
+ const evmWalletProvider_1 = require("../../wallet-providers/evmWalletProvider");
28
+ const schemas_1 = require("./schemas");
29
+ const actionDecorator_1 = require("../actionDecorator");
30
+ const viem_1 = require("viem");
31
+ const utils_1 = require("./utils");
32
+ const SUPPORTED_NETWORKS = ["base-mainnet", "base-sepolia"];
33
+ /**
34
+ * ZoraActionProvider provides actions for interacting with the Zora protocol.
35
+ */
36
+ class ZoraActionProvider extends actionProvider_1.ActionProvider {
37
+ /**
38
+ * Constructor for the ZoraActionProvider.
39
+ */
40
+ constructor() {
41
+ super("zora", []);
42
+ _ZoraActionProvider_pinataJwt.set(this, void 0);
43
+ /**
44
+ * Checks if the Zora action provider supports the given network.
45
+ *
46
+ * @param network - The network to check.
47
+ * @returns True if the Zora action provider supports the network, false otherwise.
48
+ */
49
+ this.supportsNetwork = (network) => network.protocolFamily === "evm" && SUPPORTED_NETWORKS.includes(network.networkId);
50
+ // Set Pinata JWT
51
+ const pinataJwt = process.env.PINATA_JWT;
52
+ if (!pinataJwt) {
53
+ throw new Error("PINATA_JWT is not configured. Required for IPFS uploads.");
54
+ }
55
+ __classPrivateFieldSet(this, _ZoraActionProvider_pinataJwt, pinataJwt, "f");
56
+ }
57
+ /**
58
+ * Creates a new Zora coin.
59
+ *
60
+ * @param walletProvider - The wallet provider to use for the transaction.
61
+ * @param args - The input arguments for the action.
62
+ * @returns A message containing the coin creation details.
63
+ */
64
+ async createCoin(walletProvider, args) {
65
+ try {
66
+ // Generate token URI from local file or URI
67
+ const { uri, imageUri } = await (0, utils_1.generateZoraTokenUri)({
68
+ name: args.name,
69
+ symbol: args.symbol,
70
+ description: args.description,
71
+ image: args.image,
72
+ category: args.category,
73
+ pinataConfig: { jwt: __classPrivateFieldGet(this, _ZoraActionProvider_pinataJwt, "f") },
74
+ });
75
+ // Dynamically import Zora SDK
76
+ const { createCoinCall, DeployCurrency, getCoinCreateFromLogs } = await import("@zoralabs/coins-sdk");
77
+ // Create coin call
78
+ const call = {
79
+ name: args.name,
80
+ symbol: args.symbol,
81
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
82
+ uri: uri,
83
+ payoutRecipient: args.payoutRecipient || walletProvider.getAddress(),
84
+ platformReferrer: args.platformReferrer || "0x0000000000000000000000000000000000000000",
85
+ currency: args.currency === "ZORA" ? DeployCurrency.ZORA : DeployCurrency.ETH,
86
+ };
87
+ const createCoinRequest = await createCoinCall(call);
88
+ const { abi, functionName, address, args: callArgs, value } = createCoinRequest;
89
+ const data = (0, viem_1.encodeFunctionData)({ abi, functionName, args: callArgs });
90
+ const txRequest = { to: address, data, value };
91
+ // Send transaction
92
+ const hash = await walletProvider.sendTransaction(txRequest);
93
+ const receipt = await walletProvider.waitForTransactionReceipt(hash);
94
+ const deployment = getCoinCreateFromLogs(receipt);
95
+ if (receipt.status === "success") {
96
+ return JSON.stringify({
97
+ success: true,
98
+ transactionHash: hash,
99
+ coinAddress: deployment?.coin,
100
+ imageUri,
101
+ uri,
102
+ deployment,
103
+ ...(walletProvider.getNetwork().networkId === "base-mainnet" &&
104
+ deployment?.coin && {
105
+ zoraURL: `https://zora.co/coin/base:${deployment.coin}`,
106
+ }),
107
+ });
108
+ }
109
+ else {
110
+ throw new Error("Coin creation transaction reverted");
111
+ }
112
+ }
113
+ catch (error) {
114
+ return JSON.stringify({
115
+ success: false,
116
+ error: error instanceof Error ? error.message : String(error),
117
+ });
118
+ }
119
+ }
120
+ }
121
+ exports.ZoraActionProvider = ZoraActionProvider;
122
+ _ZoraActionProvider_pinataJwt = new WeakMap();
123
+ __decorate([
124
+ (0, actionDecorator_1.CreateAction)({
125
+ name: "coinIt",
126
+ description: `
127
+ This tool will create a new Zora coin.
128
+ It takes the following parameters:
129
+ - name: The name of the coin
130
+ - symbol: The symbol of the coin
131
+ - image: Local image file path or URI (ipfs:// or https://)
132
+ - description: The description of the coin
133
+ - payoutRecipient: The address that will receive creator earnings (optional, defaults to the wallet address)
134
+ - platformReferrer: The address that will receive platform referrer fees (optional, defaults to 0x0000000000000000000000000000000000000000)
135
+ - category: The category of the coin (optional, defaults to 'social')
136
+ - currency: The currency for deployment, can be 'ZORA' or 'ETH'. Determines which token will be used for the trading pair (optional, defaults to 'ZORA').
137
+ The action will return the transaction hash, coin address, and deployment details upon success.
138
+ `,
139
+ schema: schemas_1.CreateCoinSchema,
140
+ }),
141
+ __metadata("design:type", Function),
142
+ __metadata("design:paramtypes", [evmWalletProvider_1.EvmWalletProvider, void 0]),
143
+ __metadata("design:returntype", Promise)
144
+ ], ZoraActionProvider.prototype, "createCoin", null);
145
+ /**
146
+ * Factory function to create a new ZoraActionProvider instance.
147
+ *
148
+ * @returns A new ZoraActionProvider instance
149
+ */
150
+ const zoraActionProvider = () => new ZoraActionProvider();
151
+ exports.zoraActionProvider = zoraActionProvider;