@coinbase/agentkit 0.8.2 → 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.
- package/README.md +404 -235
- package/dist/action-providers/cdp/cdpApiActionProvider.d.ts +15 -15
- package/dist/action-providers/cdp/cdpApiActionProvider.js +110 -63
- package/dist/action-providers/cdp/cdpApiActionProvider.test.js +205 -124
- package/dist/action-providers/cdp/index.d.ts +0 -1
- package/dist/action-providers/cdp/index.js +0 -1
- package/dist/action-providers/cdp/schemas.d.ts +9 -70
- package/dist/action-providers/cdp/schemas.js +12 -61
- package/dist/action-providers/cdp-legacy/index.d.ts +3 -0
- package/dist/action-providers/cdp-legacy/index.js +19 -0
- package/dist/action-providers/cdp-legacy/legacyCdpApiActionProvider.d.ts +45 -0
- package/dist/action-providers/cdp-legacy/legacyCdpApiActionProvider.js +130 -0
- package/dist/action-providers/cdp-legacy/legacyCdpApiActionProvider.test.js +146 -0
- package/dist/action-providers/{cdp/cdpWalletActionProvider.d.ts → cdp-legacy/legacyCdpWalletActionProvider.d.ts} +8 -8
- package/dist/action-providers/{cdp/cdpWalletActionProvider.js → cdp-legacy/legacyCdpWalletActionProvider.js} +14 -14
- package/dist/action-providers/{cdp/cdpWalletActionProvider.test.js → cdp-legacy/legacyCdpWalletActionProvider.test.js} +3 -3
- package/dist/action-providers/cdp-legacy/schemas.d.ts +91 -0
- package/dist/action-providers/cdp-legacy/schemas.js +77 -0
- package/dist/action-providers/erc20/erc20ActionProvider.js +1 -1
- package/dist/action-providers/farcaster/farcasterActionProvider.js +2 -0
- package/dist/action-providers/farcaster/farcasterActionProvider.test.js +55 -0
- package/dist/action-providers/farcaster/schemas.d.ts +13 -0
- package/dist/action-providers/farcaster/schemas.js +6 -0
- package/dist/action-providers/index.d.ts +3 -1
- package/dist/action-providers/index.js +3 -1
- package/dist/action-providers/jupiter/jupiterActionProvider.test.js +2 -4
- package/dist/action-providers/truemarkets/constants.d.ts +179 -0
- package/dist/action-providers/truemarkets/constants.js +46 -0
- package/dist/action-providers/truemarkets/index.d.ts +1 -0
- package/dist/action-providers/truemarkets/index.js +17 -0
- package/dist/action-providers/truemarkets/schemas.d.ts +21 -0
- package/dist/action-providers/truemarkets/schemas.js +29 -0
- package/dist/action-providers/truemarkets/truemarketsActionProvider.d.ts +51 -0
- package/dist/action-providers/truemarkets/truemarketsActionProvider.js +469 -0
- package/dist/action-providers/truemarkets/truemarketsActionProvider.test.js +217 -0
- package/dist/action-providers/truemarkets/utils.d.ts +10 -0
- package/dist/action-providers/truemarkets/utils.js +9 -0
- package/dist/action-providers/twitter/schemas.d.ts +16 -0
- package/dist/action-providers/twitter/schemas.js +23 -1
- package/dist/action-providers/twitter/twitterActionProvider.d.ts +8 -1
- package/dist/action-providers/twitter/twitterActionProvider.js +56 -5
- package/dist/action-providers/twitter/twitterActionProvider.test.js +52 -2
- package/dist/action-providers/weth/constants.d.ts +9 -0
- package/dist/action-providers/weth/constants.js +12 -0
- package/dist/action-providers/weth/schemas.d.ts +7 -0
- package/dist/action-providers/weth/schemas.js +7 -1
- package/dist/action-providers/weth/wethActionProvider.d.ts +9 -1
- package/dist/action-providers/weth/wethActionProvider.js +50 -1
- package/dist/action-providers/weth/wethActionProvider.test.js +60 -0
- package/dist/action-providers/x402/schemas.d.ts +58 -11
- package/dist/action-providers/x402/schemas.js +60 -8
- package/dist/action-providers/x402/x402ActionProvider.d.ts +33 -16
- package/dist/action-providers/x402/x402ActionProvider.js +203 -153
- package/dist/action-providers/x402/x402ActionProvider.test.js +78 -225
- package/dist/action-providers/zora/index.d.ts +3 -0
- package/dist/action-providers/{cdp-v2 → zora}/index.js +2 -1
- package/dist/action-providers/zora/schemas.d.ts +29 -0
- package/dist/action-providers/zora/schemas.js +31 -0
- package/dist/action-providers/zora/utils.d.ts +28 -0
- package/dist/action-providers/zora/utils.js +200 -0
- package/dist/action-providers/zora/zoraActionProvider.d.ts +36 -0
- package/dist/action-providers/zora/zoraActionProvider.js +151 -0
- package/dist/action-providers/zora/zoraActionProvider.test.js +205 -0
- package/dist/agentkit.d.ts +1 -0
- package/dist/agentkit.js +3 -2
- package/dist/wallet-providers/{cdpV2EvmWalletProvider.d.ts → cdpEvmWalletProvider.d.ts} +16 -7
- package/dist/wallet-providers/{cdpV2EvmWalletProvider.js → cdpEvmWalletProvider.js} +50 -39
- package/dist/wallet-providers/{cdpV2EvmWalletProvider.test.js → cdpEvmWalletProvider.test.js} +7 -7
- package/dist/wallet-providers/{cdpV2Shared.d.ts → cdpShared.d.ts} +15 -4
- package/dist/wallet-providers/cdpSmartWalletProvider.d.ts +115 -0
- package/dist/wallet-providers/cdpSmartWalletProvider.js +263 -0
- package/dist/wallet-providers/cdpSmartWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/cdpSmartWalletProvider.test.js +287 -0
- package/dist/wallet-providers/{cdpV2SolanaWalletProvider.d.ts → cdpSolanaWalletProvider.d.ts} +16 -7
- package/dist/wallet-providers/{cdpV2SolanaWalletProvider.js → cdpSolanaWalletProvider.js} +43 -32
- package/dist/wallet-providers/cdpSolanaWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/{cdpV2SolanaWalletProvider.test.js → cdpSolanaWalletProvider.test.js} +7 -7
- package/dist/wallet-providers/index.d.ts +6 -6
- package/dist/wallet-providers/index.js +6 -6
- package/dist/wallet-providers/{smartWalletProvider.d.ts → legacyCdpSmartWalletProvider.d.ts} +3 -3
- package/dist/wallet-providers/{smartWalletProvider.js → legacyCdpSmartWalletProvider.js} +21 -21
- package/dist/wallet-providers/legacyCdpSmartWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/{smartWalletProvider.test.js → legacyCdpSmartWalletProvider.test.js} +2 -2
- package/dist/wallet-providers/{cdpWalletProvider.d.ts → legacyCdpWalletProvider.d.ts} +15 -11
- package/dist/wallet-providers/{cdpWalletProvider.js → legacyCdpWalletProvider.js} +72 -70
- package/dist/wallet-providers/legacyCdpWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/{cdpWalletProvider.test.js → legacyCdpWalletProvider.test.js} +10 -10
- package/package.json +4 -2
- package/dist/action-providers/cdp-v2/cdpApiV2ActionProvider.d.ts +0 -34
- package/dist/action-providers/cdp-v2/cdpApiV2ActionProvider.js +0 -98
- package/dist/action-providers/cdp-v2/index.d.ts +0 -2
- package/dist/action-providers/cdp-v2/schemas.d.ts +0 -11
- package/dist/action-providers/cdp-v2/schemas.js +0 -13
- package/dist/wallet-providers/cdpV2WalletProvider.d.ts +0 -35
- package/dist/wallet-providers/cdpV2WalletProvider.js +0 -42
- /package/dist/action-providers/{cdp → cdp-legacy}/constants.d.ts +0 -0
- /package/dist/action-providers/{cdp → cdp-legacy}/constants.js +0 -0
- /package/dist/action-providers/{cdp/cdpWalletActionProvider.test.d.ts → cdp-legacy/legacyCdpApiActionProvider.test.d.ts} +0 -0
- /package/dist/{wallet-providers/cdpV2EvmWalletProvider.test.d.ts → action-providers/cdp-legacy/legacyCdpWalletActionProvider.test.d.ts} +0 -0
- /package/dist/{wallet-providers/cdpV2SolanaWalletProvider.test.d.ts → action-providers/truemarkets/truemarketsActionProvider.test.d.ts} +0 -0
- /package/dist/{wallet-providers/cdpWalletProvider.test.d.ts → action-providers/zora/zoraActionProvider.test.d.ts} +0 -0
- /package/dist/wallet-providers/{smartWalletProvider.test.d.ts → cdpEvmWalletProvider.test.d.ts} +0 -0
- /package/dist/wallet-providers/{cdpV2Shared.js → cdpShared.js} +0 -0
|
@@ -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;
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const zoraActionProvider_1 = require("./zoraActionProvider");
|
|
4
|
+
const schemas_1 = require("./schemas");
|
|
5
|
+
// Mock viem's encodeFunctionData function to prevent ABI errors
|
|
6
|
+
jest.mock("viem", () => {
|
|
7
|
+
const originalModule = jest.requireActual("viem");
|
|
8
|
+
return {
|
|
9
|
+
...originalModule,
|
|
10
|
+
encodeFunctionData: jest.fn().mockReturnValue("0x1234"),
|
|
11
|
+
};
|
|
12
|
+
});
|
|
13
|
+
// Mock the dynamically imported Zora SDK
|
|
14
|
+
jest.mock("@zoralabs/coins-sdk", () => ({
|
|
15
|
+
createCoinCall: jest.fn().mockResolvedValue({
|
|
16
|
+
abi: [{ name: "createCoin" }], // Add a minimal abi to prevent "function not found" error
|
|
17
|
+
functionName: "createCoin",
|
|
18
|
+
address: "0x1234567890123456789012345678901234567890",
|
|
19
|
+
args: [],
|
|
20
|
+
value: BigInt(0),
|
|
21
|
+
}),
|
|
22
|
+
getCoinCreateFromLogs: jest.fn().mockReturnValue({
|
|
23
|
+
coin: "0x2345678901234567890123456789012345678901",
|
|
24
|
+
}),
|
|
25
|
+
DeployCurrency: {
|
|
26
|
+
ZORA: "ZORA",
|
|
27
|
+
ETH: "ETH",
|
|
28
|
+
},
|
|
29
|
+
}), { virtual: true });
|
|
30
|
+
// Mock the utils module
|
|
31
|
+
jest.mock("./utils", () => ({
|
|
32
|
+
generateZoraTokenUri: jest.fn().mockResolvedValue({
|
|
33
|
+
uri: "ipfs://testCID",
|
|
34
|
+
imageUri: "ipfs://testImageCID",
|
|
35
|
+
}),
|
|
36
|
+
}));
|
|
37
|
+
describe("ZoraActionProvider", () => {
|
|
38
|
+
const MOCK_TX_HASH = "0xabcdef1234567890";
|
|
39
|
+
const MOCK_ADDRESS = "0x9876543210987654321098765432109876543210";
|
|
40
|
+
let provider;
|
|
41
|
+
let mockWalletProvider;
|
|
42
|
+
let originalPinataJwt;
|
|
43
|
+
beforeEach(() => {
|
|
44
|
+
// Reset mocks between tests
|
|
45
|
+
jest.clearAllMocks();
|
|
46
|
+
originalPinataJwt = process.env.PINATA_JWT;
|
|
47
|
+
process.env.PINATA_JWT = "test-jwt";
|
|
48
|
+
// Create the provider
|
|
49
|
+
provider = new zoraActionProvider_1.ZoraActionProvider();
|
|
50
|
+
// Set up the mock wallet provider
|
|
51
|
+
mockWalletProvider = {
|
|
52
|
+
getAddress: jest.fn().mockReturnValue(MOCK_ADDRESS),
|
|
53
|
+
getNetwork: jest.fn().mockReturnValue({
|
|
54
|
+
protocolFamily: "evm",
|
|
55
|
+
networkId: "base-sepolia",
|
|
56
|
+
}),
|
|
57
|
+
sendTransaction: jest.fn().mockResolvedValue(MOCK_TX_HASH),
|
|
58
|
+
waitForTransactionReceipt: jest.fn().mockResolvedValue({
|
|
59
|
+
status: "success",
|
|
60
|
+
logs: [],
|
|
61
|
+
}),
|
|
62
|
+
};
|
|
63
|
+
});
|
|
64
|
+
afterEach(() => {
|
|
65
|
+
process.env.PINATA_JWT = originalPinataJwt;
|
|
66
|
+
});
|
|
67
|
+
describe("constructor", () => {
|
|
68
|
+
it("should throw an error if Pinata JWT is not provided", () => {
|
|
69
|
+
delete process.env.PINATA_JWT;
|
|
70
|
+
expect(() => new zoraActionProvider_1.ZoraActionProvider()).toThrow("PINATA_JWT is not configured. Required for IPFS uploads.");
|
|
71
|
+
});
|
|
72
|
+
it("should create provider with Pinata JWT from environment", () => {
|
|
73
|
+
expect(new zoraActionProvider_1.ZoraActionProvider()).toBeInstanceOf(zoraActionProvider_1.ZoraActionProvider);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
describe("supportsNetwork", () => {
|
|
77
|
+
const testCases = [
|
|
78
|
+
{ network: { protocolFamily: "evm", networkId: "base-mainnet" }, expected: true },
|
|
79
|
+
{ network: { protocolFamily: "evm", networkId: "base-sepolia" }, expected: true },
|
|
80
|
+
{ network: { protocolFamily: "evm", networkId: "ethereum" }, expected: false },
|
|
81
|
+
{ network: { protocolFamily: "solana", networkId: "base-mainnet" }, expected: false },
|
|
82
|
+
];
|
|
83
|
+
testCases.forEach(({ network, expected }) => {
|
|
84
|
+
it(`should ${expected ? "support" : "not support"} ${network.protocolFamily}/${network.networkId}`, () => {
|
|
85
|
+
expect(provider.supportsNetwork(network)).toBe(expected);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
describe("createCoin", () => {
|
|
90
|
+
it("should validate createCoin schema", () => {
|
|
91
|
+
const validInput = {
|
|
92
|
+
name: "Test Coin",
|
|
93
|
+
symbol: "TEST",
|
|
94
|
+
description: "A test coin",
|
|
95
|
+
image: "https://example.com/image.png",
|
|
96
|
+
category: "social",
|
|
97
|
+
currency: "ZORA",
|
|
98
|
+
};
|
|
99
|
+
const parseResult = schemas_1.CreateCoinSchema.safeParse(validInput);
|
|
100
|
+
expect(parseResult.success).toBe(true);
|
|
101
|
+
});
|
|
102
|
+
it("should reject invalid input", () => {
|
|
103
|
+
const invalidInput = {
|
|
104
|
+
name: "Test Coin",
|
|
105
|
+
symbol: "TEST",
|
|
106
|
+
description: "A test coin",
|
|
107
|
+
image: "https://example.com/image.png",
|
|
108
|
+
category: "social",
|
|
109
|
+
currency: "ZORA",
|
|
110
|
+
payoutRecipient: "invalid-address", // Should be 0x format
|
|
111
|
+
};
|
|
112
|
+
const parseResult = schemas_1.CreateCoinSchema.safeParse(invalidInput);
|
|
113
|
+
expect(parseResult.success).toBe(false);
|
|
114
|
+
});
|
|
115
|
+
it("should successfully create a coin", async () => {
|
|
116
|
+
const args = {
|
|
117
|
+
name: "Test Coin",
|
|
118
|
+
symbol: "TEST",
|
|
119
|
+
description: "A test coin",
|
|
120
|
+
image: "https://example.com/image.png",
|
|
121
|
+
category: "social",
|
|
122
|
+
currency: "ZORA",
|
|
123
|
+
};
|
|
124
|
+
const result = await provider.createCoin(mockWalletProvider, args);
|
|
125
|
+
const parsedResult = JSON.parse(result);
|
|
126
|
+
expect(mockWalletProvider.sendTransaction).toHaveBeenCalled();
|
|
127
|
+
expect(mockWalletProvider.waitForTransactionReceipt).toHaveBeenCalledWith(MOCK_TX_HASH);
|
|
128
|
+
expect(parsedResult.success).toBe(true);
|
|
129
|
+
expect(parsedResult.transactionHash).toBe(MOCK_TX_HASH);
|
|
130
|
+
expect(parsedResult.coinAddress).toBe("0x2345678901234567890123456789012345678901");
|
|
131
|
+
});
|
|
132
|
+
it("should include zoraURL for base-mainnet network", async () => {
|
|
133
|
+
// Mock wallet provider to return base-mainnet network
|
|
134
|
+
mockWalletProvider.getNetwork.mockReturnValue({
|
|
135
|
+
protocolFamily: "evm",
|
|
136
|
+
networkId: "base-mainnet",
|
|
137
|
+
});
|
|
138
|
+
const args = {
|
|
139
|
+
name: "Test Coin",
|
|
140
|
+
symbol: "TEST",
|
|
141
|
+
description: "A test coin",
|
|
142
|
+
image: "https://example.com/image.png",
|
|
143
|
+
category: "social",
|
|
144
|
+
currency: "ZORA",
|
|
145
|
+
};
|
|
146
|
+
const result = await provider.createCoin(mockWalletProvider, args);
|
|
147
|
+
const parsedResult = JSON.parse(result);
|
|
148
|
+
expect(parsedResult.success).toBe(true);
|
|
149
|
+
expect(parsedResult.coinAddress).toBe("0x2345678901234567890123456789012345678901");
|
|
150
|
+
expect(parsedResult.zoraURL).toBe("https://zora.co/coin/base:0x2345678901234567890123456789012345678901");
|
|
151
|
+
});
|
|
152
|
+
it("should not include zoraURL for non-base-mainnet networks", async () => {
|
|
153
|
+
// Keep the default base-sepolia network from beforeEach
|
|
154
|
+
const args = {
|
|
155
|
+
name: "Test Coin",
|
|
156
|
+
symbol: "TEST",
|
|
157
|
+
description: "A test coin",
|
|
158
|
+
image: "https://example.com/image.png",
|
|
159
|
+
category: "social",
|
|
160
|
+
currency: "ZORA",
|
|
161
|
+
};
|
|
162
|
+
const result = await provider.createCoin(mockWalletProvider, args);
|
|
163
|
+
const parsedResult = JSON.parse(result);
|
|
164
|
+
expect(parsedResult.success).toBe(true);
|
|
165
|
+
expect(parsedResult.coinAddress).toBe("0x2345678901234567890123456789012345678901");
|
|
166
|
+
expect(parsedResult.zoraURL).toBeUndefined();
|
|
167
|
+
});
|
|
168
|
+
it("should handle transaction failure", async () => {
|
|
169
|
+
const args = {
|
|
170
|
+
name: "Test Coin",
|
|
171
|
+
symbol: "TEST",
|
|
172
|
+
description: "A test coin",
|
|
173
|
+
image: "https://example.com/image.png",
|
|
174
|
+
category: "social",
|
|
175
|
+
currency: "ZORA",
|
|
176
|
+
};
|
|
177
|
+
// Mock a reverted transaction
|
|
178
|
+
mockWalletProvider.waitForTransactionReceipt.mockResolvedValueOnce({
|
|
179
|
+
status: "reverted",
|
|
180
|
+
logs: [],
|
|
181
|
+
});
|
|
182
|
+
const result = await provider.createCoin(mockWalletProvider, args);
|
|
183
|
+
const parsedResult = JSON.parse(result);
|
|
184
|
+
expect(parsedResult.success).toBe(false);
|
|
185
|
+
expect(parsedResult.error).toBe("Coin creation transaction reverted");
|
|
186
|
+
});
|
|
187
|
+
it("should handle errors", async () => {
|
|
188
|
+
const args = {
|
|
189
|
+
name: "Test Coin",
|
|
190
|
+
symbol: "TEST",
|
|
191
|
+
description: "A test coin",
|
|
192
|
+
image: "https://example.com/image.png",
|
|
193
|
+
category: "social",
|
|
194
|
+
currency: "ZORA",
|
|
195
|
+
};
|
|
196
|
+
// Create an error that will be thrown during the request
|
|
197
|
+
const error = new Error("Failed to create coin");
|
|
198
|
+
mockWalletProvider.sendTransaction.mockRejectedValueOnce(error);
|
|
199
|
+
const result = await provider.createCoin(mockWalletProvider, args);
|
|
200
|
+
const parsedResult = JSON.parse(result);
|
|
201
|
+
expect(parsedResult.success).toBe(false);
|
|
202
|
+
expect(parsedResult.error).toBe("Failed to create coin");
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
});
|
package/dist/agentkit.d.ts
CHANGED
package/dist/agentkit.js
CHANGED
|
@@ -32,12 +32,13 @@ class AgentKit {
|
|
|
32
32
|
static async from(config = { actionProviders: [(0, action_providers_1.walletActionProvider)()] }) {
|
|
33
33
|
let walletProvider = config.walletProvider;
|
|
34
34
|
if (!config.walletProvider) {
|
|
35
|
-
if (!config.cdpApiKeyId || !config.cdpApiKeySecret) {
|
|
35
|
+
if (!config.cdpApiKeyId || !config.cdpApiKeySecret || !config.cdpWalletSecret) {
|
|
36
36
|
throw new Error("cdpApiKeyId and cdpApiKeySecret are required if not providing a walletProvider");
|
|
37
37
|
}
|
|
38
|
-
walletProvider = await wallet_providers_1.
|
|
38
|
+
walletProvider = await wallet_providers_1.CdpSmartWalletProvider.configureWithWallet({
|
|
39
39
|
apiKeyId: config.cdpApiKeyId,
|
|
40
40
|
apiKeySecret: config.cdpApiKeySecret,
|
|
41
|
+
walletSecret: config.cdpWalletSecret,
|
|
41
42
|
});
|
|
42
43
|
}
|
|
43
44
|
return new AgentKit({ ...config, walletProvider: walletProvider });
|
|
@@ -2,26 +2,35 @@ import { CdpClient } from "@coinbase/cdp-sdk";
|
|
|
2
2
|
import { Abi, Address, ContractFunctionArgs, ContractFunctionName, Hex, ReadContractParameters, ReadContractReturnType, TransactionRequest } from "viem";
|
|
3
3
|
import { Network } from "../network";
|
|
4
4
|
import { EvmWalletProvider } from "./evmWalletProvider";
|
|
5
|
-
import { WalletProviderWithClient,
|
|
5
|
+
import { WalletProviderWithClient, CdpWalletProviderConfig } from "./cdpShared";
|
|
6
6
|
/**
|
|
7
7
|
* A wallet provider that uses the Coinbase SDK.
|
|
8
8
|
*/
|
|
9
|
-
export declare class
|
|
9
|
+
export declare class CdpEvmWalletProvider extends EvmWalletProvider implements WalletProviderWithClient {
|
|
10
10
|
#private;
|
|
11
11
|
/**
|
|
12
|
-
* Constructs a new
|
|
12
|
+
* Constructs a new CdpEvmWalletProvider.
|
|
13
13
|
*
|
|
14
|
-
* @param config - The configuration options for the
|
|
14
|
+
* @param config - The configuration options for the CdpEvmWalletProvider.
|
|
15
15
|
*/
|
|
16
16
|
private constructor();
|
|
17
17
|
/**
|
|
18
|
-
* Configures a new
|
|
18
|
+
* Configures a new CdpEvmWalletProvider with a wallet.
|
|
19
19
|
*
|
|
20
20
|
* @param config - Optional configuration parameters
|
|
21
|
-
* @returns A Promise that resolves to a new
|
|
21
|
+
* @returns A Promise that resolves to a new CdpEvmWalletProvider instance
|
|
22
22
|
* @throws Error if required environment variables are missing or wallet initialization fails
|
|
23
23
|
*/
|
|
24
|
-
static configureWithWallet(config?:
|
|
24
|
+
static configureWithWallet(config?: CdpWalletProviderConfig): Promise<CdpEvmWalletProvider>;
|
|
25
|
+
/**
|
|
26
|
+
* Exports the wallet.
|
|
27
|
+
*
|
|
28
|
+
* @returns The wallet's data.
|
|
29
|
+
*/
|
|
30
|
+
exportWallet(): Promise<{
|
|
31
|
+
name: string | undefined;
|
|
32
|
+
address: `0x${string}`;
|
|
33
|
+
}>;
|
|
25
34
|
/**
|
|
26
35
|
* Signs a message.
|
|
27
36
|
*
|