@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
@@ -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/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@coinbase/agentkit",
3
3
  "description": "Coinbase AgentKit core primitives",
4
4
  "repository": "https://github.com/coinbase/agentkit",
5
- "version": "0.9.0",
5
+ "version": "0.9.1",
6
6
  "author": "Coinbase Inc.",
7
7
  "license": "Apache-2.0",
8
8
  "main": "dist/index.js",
@@ -34,6 +34,7 @@
34
34
  "@zerodev/ecdsa-validator": "^5.4.5",
35
35
  "@zerodev/intent": "^0.0.24",
36
36
  "@zerodev/sdk": "^5.4.28",
37
+ "@zoralabs/coins-sdk": "^0.2.8",
37
38
  "axios": "^1.9.0",
38
39
  "bs58": "^4.0.1",
39
40
  "canonicalize": "^2.1.0",