@coinbase/agentkit 0.8.2 → 0.9.0

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 (65) hide show
  1. package/README.md +373 -234
  2. package/dist/action-providers/cdp/cdpApiActionProvider.d.ts +15 -15
  3. package/dist/action-providers/cdp/cdpApiActionProvider.js +110 -63
  4. package/dist/action-providers/cdp/cdpApiActionProvider.test.js +205 -124
  5. package/dist/action-providers/cdp/index.d.ts +0 -1
  6. package/dist/action-providers/cdp/index.js +0 -1
  7. package/dist/action-providers/cdp/schemas.d.ts +9 -70
  8. package/dist/action-providers/cdp/schemas.js +12 -61
  9. package/dist/action-providers/cdp-legacy/index.d.ts +3 -0
  10. package/dist/action-providers/{cdp-v2 → cdp-legacy}/index.js +2 -1
  11. package/dist/action-providers/cdp-legacy/legacyCdpApiActionProvider.d.ts +45 -0
  12. package/dist/action-providers/cdp-legacy/legacyCdpApiActionProvider.js +130 -0
  13. package/dist/action-providers/cdp-legacy/legacyCdpApiActionProvider.test.js +146 -0
  14. package/dist/action-providers/{cdp/cdpWalletActionProvider.d.ts → cdp-legacy/legacyCdpWalletActionProvider.d.ts} +8 -8
  15. package/dist/action-providers/{cdp/cdpWalletActionProvider.js → cdp-legacy/legacyCdpWalletActionProvider.js} +14 -14
  16. package/dist/action-providers/{cdp/cdpWalletActionProvider.test.js → cdp-legacy/legacyCdpWalletActionProvider.test.js} +3 -3
  17. package/dist/action-providers/cdp-legacy/schemas.d.ts +91 -0
  18. package/dist/action-providers/cdp-legacy/schemas.js +77 -0
  19. package/dist/action-providers/erc20/erc20ActionProvider.js +1 -1
  20. package/dist/action-providers/index.d.ts +1 -1
  21. package/dist/action-providers/index.js +1 -1
  22. package/dist/action-providers/jupiter/jupiterActionProvider.test.js +2 -4
  23. package/dist/action-providers/x402/schemas.d.ts +58 -11
  24. package/dist/action-providers/x402/schemas.js +60 -8
  25. package/dist/action-providers/x402/x402ActionProvider.d.ts +33 -16
  26. package/dist/action-providers/x402/x402ActionProvider.js +203 -153
  27. package/dist/action-providers/x402/x402ActionProvider.test.js +78 -225
  28. package/dist/agentkit.d.ts +1 -0
  29. package/dist/agentkit.js +3 -2
  30. package/dist/wallet-providers/{cdpV2EvmWalletProvider.d.ts → cdpEvmWalletProvider.d.ts} +16 -7
  31. package/dist/wallet-providers/{cdpV2EvmWalletProvider.js → cdpEvmWalletProvider.js} +50 -39
  32. package/dist/wallet-providers/{cdpV2EvmWalletProvider.test.js → cdpEvmWalletProvider.test.js} +7 -7
  33. package/dist/wallet-providers/{cdpV2Shared.d.ts → cdpShared.d.ts} +15 -4
  34. package/dist/wallet-providers/cdpSmartWalletProvider.d.ts +115 -0
  35. package/dist/wallet-providers/cdpSmartWalletProvider.js +263 -0
  36. package/dist/wallet-providers/cdpSmartWalletProvider.test.js +287 -0
  37. package/dist/wallet-providers/{cdpV2SolanaWalletProvider.d.ts → cdpSolanaWalletProvider.d.ts} +16 -7
  38. package/dist/wallet-providers/{cdpV2SolanaWalletProvider.js → cdpSolanaWalletProvider.js} +43 -32
  39. package/dist/wallet-providers/{cdpV2SolanaWalletProvider.test.js → cdpSolanaWalletProvider.test.js} +7 -7
  40. package/dist/wallet-providers/index.d.ts +6 -6
  41. package/dist/wallet-providers/index.js +6 -6
  42. package/dist/wallet-providers/{smartWalletProvider.d.ts → legacyCdpSmartWalletProvider.d.ts} +3 -3
  43. package/dist/wallet-providers/{smartWalletProvider.js → legacyCdpSmartWalletProvider.js} +21 -21
  44. package/dist/wallet-providers/legacyCdpSmartWalletProvider.test.d.ts +1 -0
  45. package/dist/wallet-providers/{smartWalletProvider.test.js → legacyCdpSmartWalletProvider.test.js} +2 -2
  46. package/dist/wallet-providers/{cdpWalletProvider.d.ts → legacyCdpWalletProvider.d.ts} +15 -11
  47. package/dist/wallet-providers/{cdpWalletProvider.js → legacyCdpWalletProvider.js} +72 -70
  48. package/dist/wallet-providers/legacyCdpWalletProvider.test.d.ts +1 -0
  49. package/dist/wallet-providers/{cdpWalletProvider.test.js → legacyCdpWalletProvider.test.js} +10 -10
  50. package/package.json +3 -2
  51. package/dist/action-providers/cdp-v2/cdpApiV2ActionProvider.d.ts +0 -34
  52. package/dist/action-providers/cdp-v2/cdpApiV2ActionProvider.js +0 -98
  53. package/dist/action-providers/cdp-v2/index.d.ts +0 -2
  54. package/dist/action-providers/cdp-v2/schemas.d.ts +0 -11
  55. package/dist/action-providers/cdp-v2/schemas.js +0 -13
  56. package/dist/wallet-providers/cdpV2WalletProvider.d.ts +0 -35
  57. package/dist/wallet-providers/cdpV2WalletProvider.js +0 -42
  58. /package/dist/action-providers/{cdp → cdp-legacy}/constants.d.ts +0 -0
  59. /package/dist/action-providers/{cdp → cdp-legacy}/constants.js +0 -0
  60. /package/dist/action-providers/{cdp/cdpWalletActionProvider.test.d.ts → cdp-legacy/legacyCdpApiActionProvider.test.d.ts} +0 -0
  61. /package/dist/{wallet-providers/cdpV2EvmWalletProvider.test.d.ts → action-providers/cdp-legacy/legacyCdpWalletActionProvider.test.d.ts} +0 -0
  62. /package/dist/wallet-providers/{cdpV2SolanaWalletProvider.test.d.ts → cdpEvmWalletProvider.test.d.ts} +0 -0
  63. /package/dist/wallet-providers/{cdpV2Shared.js → cdpShared.js} +0 -0
  64. /package/dist/wallet-providers/{cdpWalletProvider.test.d.ts → cdpSmartWalletProvider.test.d.ts} +0 -0
  65. /package/dist/wallet-providers/{smartWalletProvider.test.d.ts → cdpSolanaWalletProvider.test.d.ts} +0 -0
@@ -1,72 +1,8 @@
1
1
  import { z } from "zod";
2
- /**
3
- * Input schema for address reputation check.
4
- */
5
- export declare const AddressReputationSchema: z.ZodObject<{
6
- address: z.ZodString;
7
- network: z.ZodString;
8
- }, "strip", z.ZodTypeAny, {
9
- address: string;
10
- network: string;
11
- }, {
12
- address: string;
13
- network: string;
14
- }>;
15
- /**
16
- * Input schema for deploy contract action.
17
- */
18
- export declare const DeployContractSchema: z.ZodObject<{
19
- solidityVersion: z.ZodEnum<[string, ...string[]]>;
20
- solidityInputJson: z.ZodString;
21
- contractName: z.ZodString;
22
- constructorArgs: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
23
- }, "strip", z.ZodTypeAny, {
24
- solidityVersion: string;
25
- solidityInputJson: string;
26
- contractName: string;
27
- constructorArgs?: Record<string, any> | undefined;
28
- }, {
29
- solidityVersion: string;
30
- solidityInputJson: string;
31
- contractName: string;
32
- constructorArgs?: Record<string, any> | undefined;
33
- }>;
34
- /**
35
- * Input schema for deploy NFT action
36
- */
37
- export declare const DeployNftSchema: z.ZodObject<{
38
- name: z.ZodString;
39
- symbol: z.ZodString;
40
- baseURI: z.ZodString;
41
- }, "strip", z.ZodTypeAny, {
42
- symbol: string;
43
- name: string;
44
- baseURI: string;
45
- }, {
46
- symbol: string;
47
- name: string;
48
- baseURI: string;
49
- }>;
50
- /**
51
- * Input schema for deploy token action.
52
- */
53
- export declare const DeployTokenSchema: z.ZodObject<{
54
- name: z.ZodString;
55
- symbol: z.ZodString;
56
- totalSupply: z.ZodType<bigint, z.ZodTypeDef, bigint>;
57
- }, "strip", z.ZodTypeAny, {
58
- symbol: string;
59
- name: string;
60
- totalSupply: bigint;
61
- }, {
62
- symbol: string;
63
- name: string;
64
- totalSupply: bigint;
65
- }>;
66
2
  /**
67
3
  * Input schema for request faucet funds action.
68
4
  */
69
- export declare const RequestFaucetFundsSchema: z.ZodObject<{
5
+ export declare const RequestFaucetFundsV2Schema: z.ZodObject<{
70
6
  assetId: z.ZodOptional<z.ZodString>;
71
7
  }, "strip", z.ZodTypeAny, {
72
8
  assetId?: string | undefined;
@@ -74,18 +10,21 @@ export declare const RequestFaucetFundsSchema: z.ZodObject<{
74
10
  assetId?: string | undefined;
75
11
  }>;
76
12
  /**
77
- * Input schema for trade action.
13
+ * Input schema for swap tokens action.
78
14
  */
79
- export declare const TradeSchema: z.ZodObject<{
80
- amount: z.ZodType<bigint, z.ZodTypeDef, bigint>;
15
+ export declare const SwapSchema: z.ZodObject<{
81
16
  fromAssetId: z.ZodString;
82
17
  toAssetId: z.ZodString;
18
+ amount: z.ZodString;
19
+ network: z.ZodOptional<z.ZodString>;
83
20
  }, "strip", z.ZodTypeAny, {
84
- amount: bigint;
21
+ amount: string;
85
22
  fromAssetId: string;
86
23
  toAssetId: string;
24
+ network?: string | undefined;
87
25
  }, {
88
- amount: bigint;
26
+ amount: string;
89
27
  fromAssetId: string;
90
28
  toAssetId: string;
29
+ network?: string | undefined;
91
30
  }>;
@@ -1,77 +1,28 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TradeSchema = exports.RequestFaucetFundsSchema = exports.DeployTokenSchema = exports.DeployNftSchema = exports.DeployContractSchema = exports.AddressReputationSchema = void 0;
3
+ exports.SwapSchema = exports.RequestFaucetFundsV2Schema = void 0;
4
4
  const zod_1 = require("zod");
5
- const constants_1 = require("./constants");
6
- /**
7
- * Input schema for address reputation check.
8
- */
9
- exports.AddressReputationSchema = zod_1.z
10
- .object({
11
- address: zod_1.z
12
- .string()
13
- .regex(/^0x[a-fA-F0-9]{40}$/, "Invalid Ethereum address format")
14
- .describe("The Ethereum address to check"),
15
- network: zod_1.z.string().describe("The network to check the address on"),
16
- })
17
- .strip()
18
- .describe("Input schema for address reputation check");
19
- /**
20
- * Input schema for deploy contract action.
21
- */
22
- exports.DeployContractSchema = zod_1.z
23
- .object({
24
- solidityVersion: zod_1.z
25
- .enum(Object.keys(constants_1.SolidityVersions))
26
- .describe("The solidity compiler version"),
27
- solidityInputJson: zod_1.z.string().describe("The input json for the solidity compiler"),
28
- contractName: zod_1.z.string().describe("The name of the contract class to be deployed"),
29
- constructorArgs: zod_1.z
30
- .record(zod_1.z.string(), zod_1.z.any())
31
- .describe("The constructor arguments for the contract")
32
- .optional(),
33
- })
34
- .strip()
35
- .describe("Instructions for deploying an arbitrary contract");
36
- /**
37
- * Input schema for deploy NFT action
38
- */
39
- exports.DeployNftSchema = zod_1.z
40
- .object({
41
- name: zod_1.z.string().describe("The name of the NFT collection"),
42
- symbol: zod_1.z.string().describe("The symbol of the NFT collection"),
43
- baseURI: zod_1.z.string().describe("The base URI for the token metadata"),
44
- })
45
- .strip()
46
- .describe("Instructions for deploying an NFT collection");
47
- /**
48
- * Input schema for deploy token action.
49
- */
50
- exports.DeployTokenSchema = zod_1.z
51
- .object({
52
- name: zod_1.z.string().describe("The name of the token"),
53
- symbol: zod_1.z.string().describe("The token symbol"),
54
- totalSupply: zod_1.z.custom().describe("The total supply of tokens to mint"),
55
- })
56
- .strip()
57
- .describe("Instructions for deploying a token");
58
5
  /**
59
6
  * Input schema for request faucet funds action.
60
7
  */
61
- exports.RequestFaucetFundsSchema = zod_1.z
8
+ exports.RequestFaucetFundsV2Schema = zod_1.z
62
9
  .object({
63
10
  assetId: zod_1.z.string().optional().describe("The optional asset ID to request from faucet"),
64
11
  })
65
12
  .strip()
66
13
  .describe("Instructions for requesting faucet funds");
67
14
  /**
68
- * Input schema for trade action.
15
+ * Input schema for swap tokens action.
69
16
  */
70
- exports.TradeSchema = zod_1.z
17
+ exports.SwapSchema = zod_1.z
71
18
  .object({
72
- amount: zod_1.z.custom().describe("The amount of the from asset to trade"),
73
- fromAssetId: zod_1.z.string().describe("The from asset ID to trade"),
74
- toAssetId: zod_1.z.string().describe("The to asset ID to receive from the trade"),
19
+ fromAssetId: zod_1.z.string().describe("The asset ID to swap from (e.g., 'eth', 'usdc')"),
20
+ toAssetId: zod_1.z.string().describe("The asset ID to swap to (e.g., 'eth', 'usdc')"),
21
+ amount: zod_1.z.string().describe("The amount to swap (in the from asset's units)"),
22
+ network: zod_1.z
23
+ .string()
24
+ .optional()
25
+ .describe("The network to perform the swap on (defaults to wallet's network)"),
75
26
  })
76
27
  .strip()
77
- .describe("Instructions for trading assets");
28
+ .describe("Instructions for swapping tokens");
@@ -0,0 +1,3 @@
1
+ export * from "./schemas";
2
+ export * from "./legacyCdpApiActionProvider";
3
+ export * from "./legacyCdpWalletActionProvider";
@@ -15,4 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./schemas"), exports);
18
- __exportStar(require("./cdpApiV2ActionProvider"), exports);
18
+ __exportStar(require("./legacyCdpApiActionProvider"), exports);
19
+ __exportStar(require("./legacyCdpWalletActionProvider"), exports);
@@ -0,0 +1,45 @@
1
+ import { z } from "zod";
2
+ import { ActionProvider } from "../actionProvider";
3
+ import { Network } from "../../network";
4
+ import { LegacyCdpProviderConfig, WalletProvider } from "../../wallet-providers";
5
+ import { AddressReputationSchema, RequestFaucetFundsSchema } from "./schemas";
6
+ /**
7
+ * LegacyCdpApiActionProvider is a legacy action provider for CDP API using the old Coinbase SDK.
8
+ *
9
+ * This provider is used for any action that uses the CDP API, but does not require a CDP Wallet.
10
+ *
11
+ * @deprecated Use CdpApiActionProvider instead
12
+ */
13
+ export declare class LegacyCdpApiActionProvider extends ActionProvider<WalletProvider> {
14
+ /**
15
+ * Constructor for the LegacyCdpApiActionProvider class.
16
+ *
17
+ * @param config - The configuration options for the LegacyCdpApiActionProvider.
18
+ */
19
+ constructor(config?: LegacyCdpProviderConfig);
20
+ /**
21
+ * Check the reputation of an address.
22
+ *
23
+ * @param args - The input arguments for the action
24
+ * @returns A string containing reputation data or error message
25
+ */
26
+ addressReputation(args: z.infer<typeof AddressReputationSchema>): Promise<string>;
27
+ /**
28
+ * Requests test tokens from the faucet for the default address in the wallet.
29
+ *
30
+ * @param walletProvider - The wallet provider to request funds from.
31
+ * @param args - The input arguments for the action.
32
+ * @returns A confirmation message with transaction details.
33
+ */
34
+ faucet(walletProvider: WalletProvider, args: z.infer<typeof RequestFaucetFundsSchema>): Promise<string>;
35
+ /**
36
+ * Checks if the Cdp action provider supports the given network.
37
+ *
38
+ * NOTE: Network scoping is done at the action implementation level
39
+ *
40
+ * @param _ - The network to check.
41
+ * @returns True if the Cdp action provider supports the network, false otherwise.
42
+ */
43
+ supportsNetwork: (_: Network) => boolean;
44
+ }
45
+ export declare const legacyCdpApiActionProvider: (config?: LegacyCdpProviderConfig) => LegacyCdpApiActionProvider;
@@ -0,0 +1,130 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.legacyCdpApiActionProvider = exports.LegacyCdpApiActionProvider = void 0;
13
+ const package_json_1 = require("../../../package.json");
14
+ const coinbase_sdk_1 = require("@coinbase/coinbase-sdk");
15
+ const zod_1 = require("zod");
16
+ const actionDecorator_1 = require("../actionDecorator");
17
+ const actionProvider_1 = require("../actionProvider");
18
+ const wallet_providers_1 = require("../../wallet-providers");
19
+ const schemas_1 = require("./schemas");
20
+ /**
21
+ * LegacyCdpApiActionProvider is a legacy action provider for CDP API using the old Coinbase SDK.
22
+ *
23
+ * This provider is used for any action that uses the CDP API, but does not require a CDP Wallet.
24
+ *
25
+ * @deprecated Use CdpApiActionProvider instead
26
+ */
27
+ class LegacyCdpApiActionProvider extends actionProvider_1.ActionProvider {
28
+ /**
29
+ * Constructor for the LegacyCdpApiActionProvider class.
30
+ *
31
+ * @param config - The configuration options for the LegacyCdpApiActionProvider.
32
+ */
33
+ constructor(config = {}) {
34
+ super("legacy_cdp_api", []);
35
+ /**
36
+ * Checks if the Cdp action provider supports the given network.
37
+ *
38
+ * NOTE: Network scoping is done at the action implementation level
39
+ *
40
+ * @param _ - The network to check.
41
+ * @returns True if the Cdp action provider supports the network, false otherwise.
42
+ */
43
+ this.supportsNetwork = (_) => true;
44
+ if (config.apiKeyId && config.apiKeySecret) {
45
+ coinbase_sdk_1.Coinbase.configure({
46
+ apiKeyName: config.apiKeyId,
47
+ privateKey: config.apiKeySecret?.replace(/\\n/g, "\n"),
48
+ source: "agentkit",
49
+ sourceVersion: package_json_1.version,
50
+ });
51
+ }
52
+ else {
53
+ coinbase_sdk_1.Coinbase.configureFromJson({ source: "agentkit", sourceVersion: package_json_1.version });
54
+ }
55
+ }
56
+ /**
57
+ * Check the reputation of an address.
58
+ *
59
+ * @param args - The input arguments for the action
60
+ * @returns A string containing reputation data or error message
61
+ */
62
+ async addressReputation(args) {
63
+ if (args.network.includes("solana")) {
64
+ return "Address reputation is only supported on Ethereum networks.";
65
+ }
66
+ try {
67
+ const address = new coinbase_sdk_1.ExternalAddress(args.network, args.address);
68
+ const reputation = await address.reputation();
69
+ return reputation.toString();
70
+ }
71
+ catch (error) {
72
+ return `Error checking address reputation: ${error}`;
73
+ }
74
+ }
75
+ /**
76
+ * Requests test tokens from the faucet for the default address in the wallet.
77
+ *
78
+ * @param walletProvider - The wallet provider to request funds from.
79
+ * @param args - The input arguments for the action.
80
+ * @returns A confirmation message with transaction details.
81
+ */
82
+ async faucet(walletProvider, args) {
83
+ const network = walletProvider.getNetwork();
84
+ if (network.networkId !== "base-sepolia" && network.networkId !== "solana-devnet") {
85
+ return `Faucet is only allowed on 'base-sepolia' or 'solana-devnet'.`;
86
+ }
87
+ try {
88
+ const address = new coinbase_sdk_1.ExternalAddress(walletProvider.getNetwork().networkId, walletProvider.getAddress());
89
+ const faucetTx = await address.faucet(args.assetId || undefined);
90
+ const result = await faucetTx.wait({ timeoutSeconds: 60 });
91
+ return `Received ${args.assetId || "ETH"} from the faucet. Transaction: ${result.getTransactionLink()}`;
92
+ }
93
+ catch (error) {
94
+ return `Error requesting faucet funds: ${error}`;
95
+ }
96
+ }
97
+ }
98
+ exports.LegacyCdpApiActionProvider = LegacyCdpApiActionProvider;
99
+ __decorate([
100
+ (0, actionDecorator_1.CreateAction)({
101
+ name: "address_reputation",
102
+ description: `
103
+ This tool checks the reputation of an address on a given network. It takes:
104
+
105
+ - network: The network to check the address on (e.g. "base-mainnet")
106
+ - address: The Ethereum address to check
107
+ `,
108
+ schema: schemas_1.AddressReputationSchema,
109
+ }),
110
+ __metadata("design:type", Function),
111
+ __metadata("design:paramtypes", [void 0]),
112
+ __metadata("design:returntype", Promise)
113
+ ], LegacyCdpApiActionProvider.prototype, "addressReputation", null);
114
+ __decorate([
115
+ (0, actionDecorator_1.CreateAction)({
116
+ name: "request_faucet_funds",
117
+ description: `This tool will request test tokens from the faucet for the default address in the wallet. It takes the wallet and asset ID as input.
118
+ Faucet is only allowed on 'base-sepolia' or 'solana-devnet'.
119
+ If fauceting on 'base-sepolia', user can only provide asset ID 'eth' or 'usdc', if no asset ID is provided, the faucet will default to 'eth'.
120
+ If fauceting on 'solana-devnet', user can only provide asset ID 'sol', if no asset ID is provided, the faucet will default to 'sol'.
121
+ You are not allowed to faucet with any other network or asset ID. If you are on another network, suggest that the user sends you some ETH
122
+ from another wallet and provide the user with your wallet details.`,
123
+ schema: schemas_1.RequestFaucetFundsSchema,
124
+ }),
125
+ __metadata("design:type", Function),
126
+ __metadata("design:paramtypes", [wallet_providers_1.WalletProvider, void 0]),
127
+ __metadata("design:returntype", Promise)
128
+ ], LegacyCdpApiActionProvider.prototype, "faucet", null);
129
+ const legacyCdpApiActionProvider = (config = {}) => new LegacyCdpApiActionProvider(config);
130
+ exports.legacyCdpApiActionProvider = legacyCdpApiActionProvider;
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const legacyCdpApiActionProvider_1 = require("./legacyCdpApiActionProvider");
4
+ const schemas_1 = require("./schemas");
5
+ jest.mock("@coinbase/coinbase-sdk");
6
+ const { ExternalAddress } = jest.requireMock("@coinbase/coinbase-sdk");
7
+ describe("CDP API Action Provider Input Schemas", () => {
8
+ describe("Address Reputation Schema", () => {
9
+ it("should successfully parse valid input", () => {
10
+ const validInput = {
11
+ address: "0xe6b2af36b3bb8d47206a129ff11d5a2de2a63c83",
12
+ network: "base-mainnet",
13
+ };
14
+ const result = schemas_1.AddressReputationSchema.safeParse(validInput);
15
+ expect(result.success).toBe(true);
16
+ expect(result.data).toEqual(validInput);
17
+ });
18
+ it("should fail parsing invalid address", () => {
19
+ const invalidInput = {
20
+ address: "invalid-address",
21
+ network: "base-mainnet",
22
+ };
23
+ const result = schemas_1.AddressReputationSchema.safeParse(invalidInput);
24
+ expect(result.success).toBe(false);
25
+ });
26
+ });
27
+ describe("Request Faucet Funds Schema", () => {
28
+ it("should successfully parse with optional assetId", () => {
29
+ const validInput = {
30
+ assetId: "eth",
31
+ };
32
+ const result = schemas_1.RequestFaucetFundsSchema.safeParse(validInput);
33
+ expect(result.success).toBe(true);
34
+ expect(result.data).toEqual(validInput);
35
+ });
36
+ it("should successfully parse without assetId", () => {
37
+ const validInput = {};
38
+ const result = schemas_1.RequestFaucetFundsSchema.safeParse(validInput);
39
+ expect(result.success).toBe(true);
40
+ expect(result.data).toEqual(validInput);
41
+ });
42
+ });
43
+ });
44
+ describe("CDP API Action Provider", () => {
45
+ let actionProvider;
46
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
47
+ let mockExternalAddressInstance;
48
+ let mockWallet;
49
+ beforeEach(() => {
50
+ // Reset all mocks before each test
51
+ jest.clearAllMocks();
52
+ actionProvider = new legacyCdpApiActionProvider_1.LegacyCdpApiActionProvider();
53
+ mockExternalAddressInstance = {
54
+ reputation: jest.fn(),
55
+ faucet: jest.fn(),
56
+ };
57
+ // Mock the constructor to return our mock instance
58
+ ExternalAddress.mockImplementation(() => mockExternalAddressInstance);
59
+ mockWallet = {
60
+ deployToken: jest.fn(),
61
+ deployContract: jest.fn(),
62
+ getAddress: jest.fn().mockReturnValue("0xe6b2af36b3bb8d47206a129ff11d5a2de2a63c83"),
63
+ getNetwork: jest.fn().mockReturnValue({ networkId: "base-sepolia" }),
64
+ };
65
+ });
66
+ describe("addressReputation", () => {
67
+ it("should successfully check address reputation", async () => {
68
+ const args = {
69
+ address: "0xe6b2af36b3bb8d47206a129ff11d5a2de2a63c83",
70
+ network: "base-mainnet",
71
+ };
72
+ mockExternalAddressInstance.reputation.mockResolvedValue("Good reputation");
73
+ const result = await actionProvider.addressReputation(args);
74
+ expect(ExternalAddress).toHaveBeenCalledWith(args.network, args.address);
75
+ expect(ExternalAddress).toHaveBeenCalledTimes(1);
76
+ expect(mockExternalAddressInstance.reputation).toHaveBeenCalled();
77
+ expect(mockExternalAddressInstance.reputation).toHaveBeenCalledTimes(1);
78
+ expect(result).toBe("Good reputation");
79
+ });
80
+ it("should handle errors when checking reputation", async () => {
81
+ const args = {
82
+ address: "0xe6b2af36b3bb8d47206a129ff11d5a2de2a63c83",
83
+ network: "base-mainnet",
84
+ };
85
+ const error = new Error("Reputation check failed");
86
+ mockExternalAddressInstance.reputation.mockRejectedValue(error);
87
+ const result = await actionProvider.addressReputation(args);
88
+ expect(ExternalAddress).toHaveBeenCalledWith(args.network, args.address);
89
+ expect(ExternalAddress).toHaveBeenCalledTimes(1);
90
+ expect(mockExternalAddressInstance.reputation).toHaveBeenCalled();
91
+ expect(mockExternalAddressInstance.reputation).toHaveBeenCalledTimes(1);
92
+ expect(result).toBe(`Error checking address reputation: ${error}`);
93
+ });
94
+ it("should return error if not on Ethereum network", async () => {
95
+ const args = {
96
+ address: "0xe6b2af36b3bb8d47206a129ff11d5a2de2a63c83",
97
+ network: "solana-devnet",
98
+ };
99
+ const result = await actionProvider.addressReputation(args);
100
+ expect(result).toBe("Address reputation is only supported on Ethereum networks.");
101
+ });
102
+ });
103
+ describe("faucet", () => {
104
+ beforeEach(() => {
105
+ mockExternalAddressInstance.faucet.mockResolvedValue({
106
+ wait: jest.fn().mockResolvedValue({
107
+ getTransactionLink: jest.fn().mockReturnValue("tx-link"),
108
+ }),
109
+ });
110
+ });
111
+ it("should successfully request faucet funds with assetId", async () => {
112
+ const args = {
113
+ assetId: "eth",
114
+ };
115
+ const result = await actionProvider.faucet(mockWallet, args);
116
+ expect(ExternalAddress).toHaveBeenCalledWith("base-sepolia", mockWallet.getAddress());
117
+ expect(ExternalAddress).toHaveBeenCalledTimes(1);
118
+ expect(mockExternalAddressInstance.faucet).toHaveBeenCalledWith("eth");
119
+ expect(mockExternalAddressInstance.faucet).toHaveBeenCalledTimes(1);
120
+ expect(result).toContain("Received eth from the faucet");
121
+ expect(result).toContain("tx-link");
122
+ });
123
+ it("should successfully request faucet funds without assetId", async () => {
124
+ const args = {};
125
+ const result = await actionProvider.faucet(mockWallet, args);
126
+ expect(ExternalAddress).toHaveBeenCalledWith("base-sepolia", mockWallet.getAddress());
127
+ expect(ExternalAddress).toHaveBeenCalledTimes(1);
128
+ expect(mockExternalAddressInstance.faucet).toHaveBeenCalledWith(undefined);
129
+ expect(mockExternalAddressInstance.faucet).toHaveBeenCalledTimes(1);
130
+ expect(result).toContain("Received ETH from the faucet");
131
+ });
132
+ it("should handle faucet errors", async () => {
133
+ const args = {};
134
+ const error = new Error("Faucet request failed");
135
+ mockExternalAddressInstance.faucet.mockRejectedValue(error);
136
+ const result = await actionProvider.faucet(mockWallet, args);
137
+ expect(result).toBe(`Error requesting faucet funds: ${error}`);
138
+ });
139
+ it("should return error if not on base-sepolia or solana-devnet", async () => {
140
+ mockWallet.getNetwork.mockReturnValue({ networkId: "solana-mainnet", protocolFamily: "svm" });
141
+ const args = {};
142
+ const result = await actionProvider.faucet(mockWallet, args);
143
+ expect(result).toBe("Faucet is only allowed on 'base-sepolia' or 'solana-devnet'.");
144
+ });
145
+ });
146
+ });
@@ -1,20 +1,20 @@
1
1
  import { z } from "zod";
2
2
  import { ActionProvider } from "../actionProvider";
3
3
  import { Network } from "../../network";
4
- import { CdpWalletProvider, CdpProviderConfig } from "../../wallet-providers";
4
+ import { LegacyCdpWalletProvider, LegacyCdpProviderConfig } from "../../wallet-providers";
5
5
  import { DeployContractSchema, DeployNftSchema, DeployTokenSchema, TradeSchema } from "./schemas";
6
6
  /**
7
7
  * CdpWalletActionProvider is an action provider for Cdp.
8
8
  *
9
9
  * This provider is used for any action that requires a CDP Wallet.
10
10
  */
11
- export declare class CdpWalletActionProvider extends ActionProvider<CdpWalletProvider> {
11
+ export declare class LegacyCdpWalletActionProvider extends ActionProvider<LegacyCdpWalletProvider> {
12
12
  /**
13
13
  * Constructor for the CdpWalletActionProvider class.
14
14
  *
15
15
  * @param config - The configuration options for the CdpWalletActionProvider.
16
16
  */
17
- constructor(config?: CdpProviderConfig);
17
+ constructor(config?: LegacyCdpProviderConfig);
18
18
  /**
19
19
  * Deploys a contract.
20
20
  *
@@ -22,7 +22,7 @@ export declare class CdpWalletActionProvider extends ActionProvider<CdpWalletPro
22
22
  * @param args - The input arguments for the action
23
23
  * @returns A message containing the deployed contract address and details
24
24
  */
25
- deployContract(walletProvider: CdpWalletProvider, args: z.infer<typeof DeployContractSchema>): Promise<string>;
25
+ deployContract(walletProvider: LegacyCdpWalletProvider, args: z.infer<typeof DeployContractSchema>): Promise<string>;
26
26
  /**
27
27
  * Deploys an NFT (ERC-721) token collection onchain from the wallet.
28
28
  *
@@ -30,7 +30,7 @@ export declare class CdpWalletActionProvider extends ActionProvider<CdpWalletPro
30
30
  * @param args - The input arguments for the action.
31
31
  * @returns A message containing the NFT token deployment details.
32
32
  */
33
- deployNFT(walletProvider: CdpWalletProvider, args: z.infer<typeof DeployNftSchema>): Promise<string>;
33
+ deployNFT(walletProvider: LegacyCdpWalletProvider, args: z.infer<typeof DeployNftSchema>): Promise<string>;
34
34
  /**
35
35
  * Deploys a token.
36
36
  *
@@ -38,7 +38,7 @@ export declare class CdpWalletActionProvider extends ActionProvider<CdpWalletPro
38
38
  * @param args - The arguments for the token deployment.
39
39
  * @returns The deployed token.
40
40
  */
41
- deployToken(walletProvider: CdpWalletProvider, args: z.infer<typeof DeployTokenSchema>): Promise<string>;
41
+ deployToken(walletProvider: LegacyCdpWalletProvider, args: z.infer<typeof DeployTokenSchema>): Promise<string>;
42
42
  /**
43
43
  * Trades a specified amount of a from asset to a to asset for the wallet.
44
44
  *
@@ -46,7 +46,7 @@ export declare class CdpWalletActionProvider extends ActionProvider<CdpWalletPro
46
46
  * @param args - The input arguments for the action.
47
47
  * @returns A message containing the trade details.
48
48
  */
49
- trade(walletProvider: CdpWalletProvider, args: z.infer<typeof TradeSchema>): Promise<string>;
49
+ trade(walletProvider: LegacyCdpWalletProvider, args: z.infer<typeof TradeSchema>): Promise<string>;
50
50
  /**
51
51
  * Checks if the Cdp action provider supports the given network.
52
52
  *
@@ -55,4 +55,4 @@ export declare class CdpWalletActionProvider extends ActionProvider<CdpWalletPro
55
55
  */
56
56
  supportsNetwork: (network: Network) => boolean;
57
57
  }
58
- export declare const cdpWalletActionProvider: (config?: CdpProviderConfig) => CdpWalletActionProvider;
58
+ export declare const legacyCdpWalletActionProvider: (config?: LegacyCdpProviderConfig) => LegacyCdpWalletActionProvider;