@coinbase/agentkit 0.7.1 → 0.7.2

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.
@@ -1,16 +1,14 @@
1
1
  import { z } from "zod";
2
2
  import { Network } from "../../network";
3
3
  import { WalletProvider } from "../../wallet-providers";
4
- import { WalletProviderWithClient } from "../../wallet-providers/cdpV2Shared";
5
4
  import { ActionProvider } from "../actionProvider";
6
5
  import { RequestFaucetFundsV2Schema } from "./schemas";
7
- type CdpV2WalletProviderWithClient = WalletProvider & WalletProviderWithClient;
8
6
  /**
9
7
  * CdpApiActionProvider is an action provider for CDP API.
10
8
  *
11
9
  * This provider is used for any action that uses the CDP API, but does not require a CDP Wallet.
12
10
  */
13
- export declare class CdpApiV2ActionProvider extends ActionProvider<CdpV2WalletProviderWithClient> {
11
+ export declare class CdpApiV2ActionProvider extends ActionProvider<WalletProvider> {
14
12
  /**
15
13
  * Constructor for the CdpApiActionProvider class.
16
14
  */
@@ -22,7 +20,7 @@ export declare class CdpApiV2ActionProvider extends ActionProvider<CdpV2WalletPr
22
20
  * @param args - The input arguments for the action.
23
21
  * @returns A confirmation message with transaction details.
24
22
  */
25
- faucet(walletProvider: CdpV2WalletProviderWithClient, args: z.infer<typeof RequestFaucetFundsV2Schema>): Promise<string>;
23
+ faucet(walletProvider: WalletProvider, args: z.infer<typeof RequestFaucetFundsV2Schema>): Promise<string>;
26
24
  /**
27
25
  * Checks if the Cdp action provider supports the given network.
28
26
  *
@@ -34,4 +32,3 @@ export declare class CdpApiV2ActionProvider extends ActionProvider<CdpV2WalletPr
34
32
  supportsNetwork: (_: Network) => boolean;
35
33
  }
36
34
  export declare const cdpApiV2ActionProvider: () => CdpApiV2ActionProvider;
37
- export {};
@@ -11,6 +11,8 @@ var __metadata = (this && this.__metadata) || function (k, v) {
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.cdpApiV2ActionProvider = exports.CdpApiV2ActionProvider = void 0;
13
13
  const zod_1 = require("zod");
14
+ const wallet_providers_1 = require("../../wallet-providers");
15
+ const cdpV2Shared_1 = require("../../wallet-providers/cdpV2Shared");
14
16
  const actionDecorator_1 = require("../actionDecorator");
15
17
  const actionProvider_1 = require("../actionProvider");
16
18
  const schemas_1 = require("./schemas");
@@ -45,29 +47,34 @@ class CdpApiV2ActionProvider extends actionProvider_1.ActionProvider {
45
47
  async faucet(walletProvider, args) {
46
48
  const network = walletProvider.getNetwork();
47
49
  const networkId = network.networkId;
48
- if (network.protocolFamily === "evm") {
49
- if (networkId !== "base-sepolia" && networkId !== "ethereum-sepolia") {
50
- throw new Error("Faucet is only supported on 'base-sepolia' or 'ethereum-sepolia' evm networks.");
50
+ if ((0, cdpV2Shared_1.isWalletProviderWithClient)(walletProvider)) {
51
+ if (network.protocolFamily === "evm") {
52
+ if (networkId !== "base-sepolia" && networkId !== "ethereum-sepolia") {
53
+ throw new Error("Faucet is only supported on 'base-sepolia' or 'ethereum-sepolia' evm networks.");
54
+ }
55
+ const faucetTx = await walletProvider.getClient().evm.requestFaucet({
56
+ address: walletProvider.getAddress(),
57
+ token: (args.assetId || "eth"),
58
+ network: networkId,
59
+ });
60
+ return `Received ${args.assetId || "ETH"} from the faucet. Transaction hash: ${faucetTx.transactionHash}`;
51
61
  }
52
- const faucetTx = await walletProvider.getClient().evm.requestFaucet({
53
- address: walletProvider.getAddress(),
54
- token: (args.assetId || "eth"),
55
- network: networkId,
56
- });
57
- return `Received ${args.assetId || "ETH"} from the faucet. Transaction hash: ${faucetTx.transactionHash}`;
58
- }
59
- else if (network.protocolFamily === "svm") {
60
- if (networkId !== "solana-devnet") {
61
- throw new Error("Faucet is only supported on 'solana-devnet' solana networks.");
62
+ else if (network.protocolFamily === "svm") {
63
+ if (networkId !== "solana-devnet") {
64
+ throw new Error("Faucet is only supported on 'solana-devnet' solana networks.");
65
+ }
66
+ const faucetTx = await walletProvider.getClient().solana.requestFaucet({
67
+ address: walletProvider.getAddress(),
68
+ token: (args.assetId || "sol"),
69
+ });
70
+ return `Received ${args.assetId || "SOL"} from the faucet. Transaction signature hash: ${faucetTx.signature}`;
71
+ }
72
+ else {
73
+ throw new Error("Faucet is only supported on Ethereum and Solana protocol families.");
62
74
  }
63
- const faucetTx = await walletProvider.getClient().solana.requestFaucet({
64
- address: walletProvider.getAddress(),
65
- token: (args.assetId || "sol"),
66
- });
67
- return `Received ${args.assetId || "SOL"} from the faucet. Transaction signature hash: ${faucetTx.signature}`;
68
75
  }
69
76
  else {
70
- throw new Error("Faucet is only supported on Ethereum and Solana protocol families.");
77
+ throw new Error("Wallet provider is not a CDP Wallet Provider.");
71
78
  }
72
79
  }
73
80
  }
@@ -84,7 +91,7 @@ from another wallet and provide the user with your wallet details.`,
84
91
  schema: schemas_1.RequestFaucetFundsV2Schema,
85
92
  }),
86
93
  __metadata("design:type", Function),
87
- __metadata("design:paramtypes", [Object, void 0]),
94
+ __metadata("design:paramtypes", [wallet_providers_1.WalletProvider, void 0]),
88
95
  __metadata("design:returntype", Promise)
89
96
  ], CdpApiV2ActionProvider.prototype, "faucet", null);
90
97
  const cdpApiV2ActionProvider = () => new CdpApiV2ActionProvider();
@@ -118,9 +118,29 @@ class CdpV2EvmWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
118
118
  * @returns The hash of the transaction.
119
119
  */
120
120
  async sendTransaction(transaction) {
121
+ const txWithGasParams = {
122
+ ...transaction,
123
+ chainId: __classPrivateFieldGet(this, _CdpV2EvmWalletProvider_network, "f").chainId,
124
+ };
125
+ if (!txWithGasParams.maxFeePerGas && !txWithGasParams.gasPrice) {
126
+ const feeData = await __classPrivateFieldGet(this, _CdpV2EvmWalletProvider_publicClient, "f").estimateFeesPerGas();
127
+ txWithGasParams.maxFeePerGas = feeData.maxFeePerGas;
128
+ txWithGasParams.maxPriorityFeePerGas = feeData.maxPriorityFeePerGas;
129
+ }
130
+ if (!txWithGasParams.gas) {
131
+ try {
132
+ txWithGasParams.gas = await __classPrivateFieldGet(this, _CdpV2EvmWalletProvider_publicClient, "f").estimateGas({
133
+ account: __classPrivateFieldGet(this, _CdpV2EvmWalletProvider_serverAccount, "f").address,
134
+ ...txWithGasParams,
135
+ });
136
+ }
137
+ catch (error) {
138
+ console.warn("Failed to estimate gas, continuing without gas estimation", error);
139
+ }
140
+ }
121
141
  const result = await __classPrivateFieldGet(this, _CdpV2EvmWalletProvider_cdp, "f").evm.sendTransaction({
122
142
  address: __classPrivateFieldGet(this, _CdpV2EvmWalletProvider_serverAccount, "f").address,
123
- transaction: (0, viem_1.serializeTransaction)(transaction),
143
+ transaction: (0, viem_1.serializeTransaction)(txWithGasParams),
124
144
  network: __classPrivateFieldGet(this, _CdpV2EvmWalletProvider_instances, "m", _CdpV2EvmWalletProvider_getCdpSdkNetwork).call(this),
125
145
  });
126
146
  return result.transactionHash;
@@ -39,3 +39,10 @@ export interface WalletProviderWithClient {
39
39
  */
40
40
  getClient(): CdpClient;
41
41
  }
42
+ /**
43
+ * Type guard to check if a wallet provider implements WalletProviderWithClient interface.
44
+ *
45
+ * @param provider - The provider to check
46
+ * @returns True if the provider implements WalletProviderWithClient
47
+ */
48
+ export declare function isWalletProviderWithClient(provider: unknown): provider is WalletProviderWithClient;
@@ -1,2 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isWalletProviderWithClient = isWalletProviderWithClient;
4
+ /**
5
+ * Type guard to check if a wallet provider implements WalletProviderWithClient interface.
6
+ *
7
+ * @param provider - The provider to check
8
+ * @returns True if the provider implements WalletProviderWithClient
9
+ */
10
+ function isWalletProviderWithClient(provider) {
11
+ return (provider !== null &&
12
+ typeof provider === "object" &&
13
+ "getClient" in provider &&
14
+ typeof provider.getClient === "function");
15
+ }
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.7.1",
5
+ "version": "0.7.2",
6
6
  "author": "Coinbase Inc.",
7
7
  "license": "Apache-2.0",
8
8
  "main": "dist/index.js",