@coinbase/agentkit 0.0.0-nightly-20250807210405 → 0.0.0-nightly-20250815210416

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 (55) hide show
  1. package/README.md +106 -54
  2. package/dist/action-providers/cdp/cdpEvmWalletActionProvider.d.ts +43 -0
  3. package/dist/action-providers/cdp/cdpEvmWalletActionProvider.js +151 -0
  4. package/dist/action-providers/cdp/cdpEvmWalletActionProvider.test.d.ts +1 -0
  5. package/dist/action-providers/cdp/cdpEvmWalletActionProvider.test.js +242 -0
  6. package/dist/action-providers/cdp/cdpSmartWalletActionProvider.d.ts +42 -0
  7. package/dist/action-providers/cdp/cdpSmartWalletActionProvider.js +132 -0
  8. package/dist/action-providers/cdp/cdpSmartWalletActionProvider.test.d.ts +1 -0
  9. package/dist/action-providers/cdp/cdpSmartWalletActionProvider.test.js +199 -0
  10. package/dist/action-providers/cdp/index.d.ts +3 -0
  11. package/dist/action-providers/cdp/index.js +3 -0
  12. package/dist/action-providers/cdp/schemas.d.ts +29 -0
  13. package/dist/action-providers/cdp/schemas.js +32 -1
  14. package/dist/action-providers/cdp/spendPermissionUtils.d.ts +24 -0
  15. package/dist/action-providers/cdp/spendPermissionUtils.js +66 -0
  16. package/dist/action-providers/flaunch/flaunchActionProvider.js +3 -11
  17. package/dist/action-providers/flaunch/flaunchActionProvider.test.js +5 -0
  18. package/dist/action-providers/index.d.ts +1 -0
  19. package/dist/action-providers/index.js +1 -0
  20. package/dist/action-providers/truemarkets/truemarketsActionProvider.d.ts +4 -16
  21. package/dist/action-providers/truemarkets/truemarketsActionProvider.js +10 -31
  22. package/dist/action-providers/truemarkets/truemarketsActionProvider.test.js +11 -33
  23. package/dist/action-providers/zerion/constants.d.ts +1 -0
  24. package/dist/action-providers/zerion/constants.js +4 -0
  25. package/dist/action-providers/zerion/index.d.ts +2 -0
  26. package/dist/action-providers/zerion/index.js +18 -0
  27. package/dist/action-providers/zerion/schemas.d.ts +11 -0
  28. package/dist/action-providers/zerion/schemas.js +15 -0
  29. package/dist/action-providers/zerion/types.d.ts +125 -0
  30. package/dist/action-providers/zerion/types.js +16 -0
  31. package/dist/action-providers/zerion/utils.d.ts +3 -0
  32. package/dist/action-providers/zerion/utils.js +45 -0
  33. package/dist/action-providers/zerion/zerionActionProvider.d.ts +57 -0
  34. package/dist/action-providers/zerion/zerionActionProvider.js +159 -0
  35. package/dist/action-providers/zerion/zerionActionProvider.test.d.ts +1 -0
  36. package/dist/action-providers/zerion/zerionActionProvider.test.js +213 -0
  37. package/dist/wallet-providers/cdpEvmWalletProvider.d.ts +7 -1
  38. package/dist/wallet-providers/cdpEvmWalletProvider.js +10 -1
  39. package/dist/wallet-providers/cdpShared.d.ts +5 -0
  40. package/dist/wallet-providers/cdpSmartWalletProvider.d.ts +9 -2
  41. package/dist/wallet-providers/cdpSmartWalletProvider.js +20 -12
  42. package/dist/wallet-providers/evmWalletProvider.d.ts +5 -1
  43. package/dist/wallet-providers/legacyCdpSmartWalletProvider.d.ts +8 -1
  44. package/dist/wallet-providers/legacyCdpSmartWalletProvider.js +11 -1
  45. package/dist/wallet-providers/legacyCdpWalletProvider.d.ts +11 -1
  46. package/dist/wallet-providers/legacyCdpWalletProvider.js +10 -1
  47. package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.d.ts +9 -1
  48. package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.js +10 -1
  49. package/dist/wallet-providers/privyEvmWalletProvider.d.ts +2 -0
  50. package/dist/wallet-providers/privyEvmWalletProvider.js +2 -1
  51. package/dist/wallet-providers/viemWalletProvider.d.ts +7 -1
  52. package/dist/wallet-providers/viemWalletProvider.js +8 -0
  53. package/dist/wallet-providers/zeroDevWalletProvider.d.ts +9 -1
  54. package/dist/wallet-providers/zeroDevWalletProvider.js +10 -1
  55. package/package.json +2 -2
@@ -0,0 +1,159 @@
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.zerionActionProvider = exports.ZerionActionProvider = void 0;
13
+ const viem_1 = require("viem");
14
+ const zod_1 = require("zod");
15
+ const actionDecorator_1 = require("../actionDecorator");
16
+ const actionProvider_1 = require("../actionProvider");
17
+ const constants_1 = require("./constants");
18
+ const schemas_1 = require("./schemas");
19
+ const utils_1 = require("./utils");
20
+ /**
21
+ * ZerionActionProvider provides actions for zerion operations.
22
+ *
23
+ * @description
24
+ * This provider is designed to provide EVM-based operations.
25
+ * It supports all EVM-based networks.
26
+ */
27
+ class ZerionActionProvider extends actionProvider_1.ActionProvider {
28
+ /**
29
+ * Constructor for the ZerionActionProvider.
30
+ *
31
+ * @param config - The configuration options for the ZerionActionProvider.
32
+ */
33
+ constructor(config = {}) {
34
+ super("zerion", []);
35
+ const apiKey = config.apiKey || process.env.ZERION_API_KEY;
36
+ if (!apiKey) {
37
+ throw new Error("ZERION_API_KEY is not configured.");
38
+ }
39
+ const encodedKey = Buffer.from(`${apiKey}:`).toString("base64");
40
+ this.apiKey = encodedKey;
41
+ }
42
+ /**
43
+ * Fetches and summarizes a crypto wallet's portfolio in USD.
44
+ *
45
+ * @param args - Arguments defined by GetWalletPortfolioSchema
46
+ * @returns A promise that resolves to a string describing the action result
47
+ */
48
+ async getPortfolioOverview(args) {
49
+ try {
50
+ const address = args.walletAddress || "";
51
+ if (!(0, viem_1.isAddress)(address)) {
52
+ return `Invalid wallet address: ${address}`;
53
+ }
54
+ const options = {
55
+ method: "GET",
56
+ headers: {
57
+ accept: "application/json",
58
+ authorization: `Basic ${this.apiKey}`,
59
+ },
60
+ };
61
+ const url = `${constants_1.ZERION_V1_BASE_URL}/wallets/${args.walletAddress}/portfolio?filter[positions]=no_filter&currency=usd`;
62
+ const response = await fetch(url, options);
63
+ const { data } = await response.json();
64
+ return (0, utils_1.formatPortfolioData)(data);
65
+ }
66
+ catch (error) {
67
+ return `Error fetching portfolio overview for wallet ${args.walletAddress}: ${error}`;
68
+ }
69
+ }
70
+ /**
71
+ * Retrieves and summarizes a wallet's fungible token holdings.
72
+ *
73
+ * @param args - Arguments defined by GetWalletPortfolioSchema
74
+ * @returns A promise that resolves to a string describing the action result
75
+ */
76
+ async getFungiblePositions(args) {
77
+ try {
78
+ const address = args.walletAddress || "";
79
+ if (!(0, viem_1.isAddress)(address)) {
80
+ return `Invalid wallet address: ${address}`;
81
+ }
82
+ const options = {
83
+ method: "GET",
84
+ headers: {
85
+ accept: "application/json",
86
+ authorization: `Basic ${this.apiKey}`,
87
+ },
88
+ };
89
+ const url = `${constants_1.ZERION_V1_BASE_URL}/wallets/${args.walletAddress}/positions?filter[positions]=no_filter&currency=usd&filter[trash]=only_non_trash&sort=value`;
90
+ const response = await fetch(url, options);
91
+ const { data } = await response.json();
92
+ return (0, utils_1.formatPositionsData)(data);
93
+ }
94
+ catch (error) {
95
+ return `Error fetching fungible positions for wallet ${args.walletAddress}: ${error}`;
96
+ }
97
+ }
98
+ /**
99
+ * Checks if this provider supports the given network.
100
+ *
101
+ * @param network - The network to check support for
102
+ * @returns True if the network is supported
103
+ */
104
+ supportsNetwork(network) {
105
+ // all protocol networks
106
+ return network.protocolFamily === "evm";
107
+ }
108
+ }
109
+ exports.ZerionActionProvider = ZerionActionProvider;
110
+ __decorate([
111
+ (0, actionDecorator_1.CreateAction)({
112
+ name: "get_portfolio_overview",
113
+ description: `
114
+ Fetches and summarizes a crypto wallet's portfolio in USD.
115
+ The tool returns a human-readable overview of the wallet's total value, value distribution across blockchains, position types (e.g., staked, deposited), and 24-hour performance change.
116
+ Useful for providing quick insights into a wallet's DeFi and cross-chain holdings.
117
+ Input:
118
+ - walletAddress: The wallet address to fetch portfolio overview for.
119
+ Output a structured text summary with:
120
+ - Total portfolio value in USD
121
+ - 24h percentage change in value
122
+ - Breakdown of value by position types (e.g., wallet, deposited, staked, locked, borrowed)
123
+ - Top 5 chains by value distribution
124
+ `,
125
+ schema: schemas_1.GetWalletPortfolioSchema,
126
+ }),
127
+ __metadata("design:type", Function),
128
+ __metadata("design:paramtypes", [void 0]),
129
+ __metadata("design:returntype", Promise)
130
+ ], ZerionActionProvider.prototype, "getPortfolioOverview", null);
131
+ __decorate([
132
+ (0, actionDecorator_1.CreateAction)({
133
+ name: "get_fungible_positions",
134
+ description: `
135
+ Retrieves and summarizes a wallet's fungible token holdings.
136
+ For each token, it includes metadata such as symbol, name, holding value, associated protocol (if applicable), and the type of position (e.g., deposit, wallet, reward).
137
+ The summary also reports the total USD value of all qualifying token positions.
138
+ Input:
139
+ - walletAddress: The wallet address to fetch fungible positions for.
140
+ Output a readable text summary including:
141
+ - All token positions
142
+ - For each: token name, symbol, USD value, chain, position type
143
+ - If applicable: protocol used and type of action (e.g. staked, deposited via protocol)
144
+ - A final total value in USD across all included positions
145
+ `,
146
+ schema: schemas_1.GetWalletPortfolioSchema,
147
+ }),
148
+ __metadata("design:type", Function),
149
+ __metadata("design:paramtypes", [void 0]),
150
+ __metadata("design:returntype", Promise)
151
+ ], ZerionActionProvider.prototype, "getFungiblePositions", null);
152
+ /**
153
+ * Factory function to create a new ZerionActionProvider instance.
154
+ *
155
+ * @param config - The configuration options for the ZerionActionProvider.
156
+ * @returns A new ZerionActionProvider instance
157
+ */
158
+ const zerionActionProvider = (config) => new ZerionActionProvider(config);
159
+ exports.zerionActionProvider = zerionActionProvider;
@@ -0,0 +1,213 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const zerionActionProvider_1 = require("./zerionActionProvider");
4
+ const utils_1 = require("./utils");
5
+ // Mocks for fetch and utils
6
+ global.fetch = jest.fn();
7
+ jest.mock("./utils", () => ({
8
+ formatPortfolioData: jest.fn(() => "formatted portfolio"),
9
+ formatPositionsData: jest.fn(() => "formatted positions"),
10
+ }));
11
+ describe("ZerionActionProvider", () => {
12
+ const mockApiKey = "test-api-key";
13
+ const originalEnv = process.env.ZERION_API_KEY;
14
+ const mockFungiblePositionResponse = {
15
+ links: {
16
+ self: "https://api.zerion.io/v1/wallets/0x42b9df65b219b3dd36ff330a4dd8f327a6ada990/positions/",
17
+ },
18
+ data: [
19
+ {
20
+ type: "positions",
21
+ id: "0x111c47865ade3b172a928df8f990bc7f2a3b9aaa-polygon-asset-none-",
22
+ attributes: {
23
+ parent: "0x111c47865ade3b172a928df8f990bc7f2a3b9aaa-polygon-asset-none-",
24
+ protocol: null,
25
+ pool_address: "0x109830a1aaad605bbf02a9dfa7b0b92ec2fb7daa",
26
+ name: "Asset",
27
+ group_id: "0a771a0064dad468045899032c7fb01a971f973f7dff0a5cdc3ce199f45e94d7",
28
+ position_type: "deposit",
29
+ quantity: {
30
+ int: "12345678",
31
+ decimals: 5,
32
+ float: 123.45678,
33
+ numeric: "123.45678",
34
+ },
35
+ value: 5.384656557642683,
36
+ price: 0.043615722,
37
+ changes: {
38
+ absolute_1d: 0.272309794,
39
+ percent_1d: 5.326512552079021,
40
+ },
41
+ fungible_info: {
42
+ name: "Bankless BED Index",
43
+ symbol: "BED",
44
+ description: "The BED index is meant to track crypto’s top 3 investab...",
45
+ icon: {
46
+ url: "https://token-icons.s3.amazonaws.com/0x0391d2021f89dc339f60fff84546ea23e337750f.png",
47
+ },
48
+ flags: {
49
+ verified: true,
50
+ },
51
+ implementations: [
52
+ {
53
+ chain_id: "ethereum",
54
+ address: "0x2af1df3ab0ab157e1e2ad8f88a7d04fbea0c7dc6",
55
+ decimals: 18,
56
+ },
57
+ ],
58
+ },
59
+ flags: {
60
+ displayable: true,
61
+ is_trash: true,
62
+ },
63
+ updated_at: "2023-11-10T23:00:00Z",
64
+ updated_at_block: 0,
65
+ application_metadata: {
66
+ name: "AAVE",
67
+ icon: {
68
+ url: "https://token-icons.s3.amazonaws.com/0x0391d2021f89dc339f60fff84546ea23e337750f.png",
69
+ },
70
+ url: "https://app.aave.com/",
71
+ },
72
+ },
73
+ relationships: {
74
+ chain: {
75
+ links: {
76
+ related: "https://api.zerion.io/v1/chains/polygon",
77
+ },
78
+ data: {
79
+ type: "chains",
80
+ id: "polygon",
81
+ },
82
+ },
83
+ fungible: {
84
+ links: {
85
+ related: "https://api.zerion.io/v1/fungibles/0x111c47865ade3b172a928df8f990bc7f2a3b9aaa",
86
+ },
87
+ data: {
88
+ type: "fungibles",
89
+ id: "0x111c47865ade3b172a928df8f990bc7f2a3b9aaa",
90
+ },
91
+ },
92
+ dapp: {
93
+ data: {
94
+ type: "dapps",
95
+ id: "aave-v3",
96
+ },
97
+ },
98
+ },
99
+ },
100
+ ],
101
+ };
102
+ const mockPortfolioResponse = {
103
+ links: {
104
+ self: "https://api.zerion.io/v1/wallets/0x42b9df65b219b3dd36ff330a4dd8f327a6ada990/portfolio",
105
+ },
106
+ data: {
107
+ type: "portfolio",
108
+ id: "0x42b9df65b219b3dd36ff330a4dd8f327a6ada990",
109
+ attributes: {
110
+ positions_distribution_by_type: {
111
+ wallet: 1864.774102420957,
112
+ deposited: 78.04192492782934,
113
+ borrowed: 0.9751475798305564,
114
+ locked: 5.780032725068765,
115
+ staked: 66.13183205505294,
116
+ },
117
+ positions_distribution_by_chain: {
118
+ arbitrum: 458.3555051522226,
119
+ aurora: 72.01031337463428,
120
+ avalanche: 17.128850607339444,
121
+ base: 55.01550749900544,
122
+ "binance-smart-chain": 5.561075880033699,
123
+ celo: 31.293849330045006,
124
+ ethereum: 1214.009900354964,
125
+ fantom: 84.58514074264951,
126
+ linea: 8.258227109505139,
127
+ optimism: 573.032664994399,
128
+ polygon: 64.31407562634853,
129
+ xdai: 113.1679493137936,
130
+ "zksync-era": 9.451002156306377,
131
+ },
132
+ total: {
133
+ positions: 2017.4858230069574,
134
+ },
135
+ changes: {
136
+ absolute_1d: 102.0271468171374,
137
+ percent_1d: 5.326512552079021,
138
+ },
139
+ },
140
+ },
141
+ };
142
+ beforeEach(() => {
143
+ jest.clearAllMocks();
144
+ process.env.ZERION_API_KEY = mockApiKey;
145
+ });
146
+ afterAll(() => {
147
+ process.env.ZERION_API_KEY = originalEnv;
148
+ });
149
+ it("should throw if no API key is provided", () => {
150
+ delete process.env.ZERION_API_KEY;
151
+ expect(() => new zerionActionProvider_1.ZerionActionProvider()).toThrow("ZERION_API_KEY is not configured.");
152
+ });
153
+ it("should use provided API key from config", () => {
154
+ const provider = new zerionActionProvider_1.ZerionActionProvider({ apiKey: "foo" });
155
+ expect(provider).toBeDefined();
156
+ });
157
+ // supportsNetwork tests
158
+ const provider = new zerionActionProvider_1.ZerionActionProvider({ apiKey: mockApiKey });
159
+ it("should support the protocol family", () => {
160
+ expect(provider.supportsNetwork({ protocolFamily: "evm" })).toBe(true);
161
+ });
162
+ it("should not support other protocol families", () => {
163
+ expect(provider.supportsNetwork({ protocolFamily: "other-protocol-family" })).toBe(false);
164
+ });
165
+ it("should handle invalid network objects", () => {
166
+ expect(provider.supportsNetwork({ protocolFamily: "invalid-protocol" })).toBe(false);
167
+ expect(provider.supportsNetwork({})).toBe(false);
168
+ });
169
+ describe("getPortfolioOverview", () => {
170
+ const validAddress = "0x42b9df65b219b3dd36ff330a4dd8f327a6ada990";
171
+ const invalidAddress = "invalid-address";
172
+ const provider = new zerionActionProvider_1.ZerionActionProvider({ apiKey: mockApiKey });
173
+ it("returns error for invalid address", async () => {
174
+ const result = await provider.getPortfolioOverview({ walletAddress: invalidAddress });
175
+ expect(result).toMatch(/Invalid wallet address/);
176
+ });
177
+ it("returns formatted data for valid address", async () => {
178
+ global.fetch.mockResolvedValueOnce({
179
+ json: jest.fn().mockResolvedValue(mockPortfolioResponse),
180
+ });
181
+ const result = await provider.getPortfolioOverview({ walletAddress: validAddress });
182
+ expect(utils_1.formatPortfolioData).toHaveBeenCalledWith(mockPortfolioResponse.data);
183
+ expect(result).toBe("formatted portfolio");
184
+ });
185
+ it("returns error on fetch failure", async () => {
186
+ global.fetch.mockRejectedValueOnce(new Error("fail"));
187
+ const result = await provider.getPortfolioOverview({ walletAddress: validAddress });
188
+ expect(result).toMatch(/Error fetching portfolio overview/);
189
+ });
190
+ });
191
+ describe("getFungiblePositions", () => {
192
+ const validAddress = "0x42b9df65b219b3dd36ff330a4dd8f327a6ada990";
193
+ const invalidAddress = "invalid-address";
194
+ const provider = new zerionActionProvider_1.ZerionActionProvider({ apiKey: mockApiKey });
195
+ it("returns error for invalid address", async () => {
196
+ const result = await provider.getFungiblePositions({ walletAddress: invalidAddress });
197
+ expect(result).toMatch(/Invalid wallet address/);
198
+ });
199
+ it("returns formatted data for valid address", async () => {
200
+ global.fetch.mockResolvedValueOnce({
201
+ json: jest.fn().mockResolvedValue(mockFungiblePositionResponse),
202
+ });
203
+ const result = await provider.getFungiblePositions({ walletAddress: validAddress });
204
+ expect(utils_1.formatPositionsData).toHaveBeenCalledWith(mockFungiblePositionResponse.data);
205
+ expect(result).toBe("formatted positions");
206
+ });
207
+ it("returns error on fetch failure", async () => {
208
+ global.fetch.mockRejectedValueOnce(new Error("fail"));
209
+ const result = await provider.getFungiblePositions({ walletAddress: validAddress });
210
+ expect(result).toMatch(/Error fetching fungible positions/);
211
+ });
212
+ });
213
+ });
@@ -1,5 +1,5 @@
1
1
  import { CdpClient } from "@coinbase/cdp-sdk";
2
- import { Abi, Address, ContractFunctionArgs, ContractFunctionName, Hex, ReadContractParameters, ReadContractReturnType, TransactionRequest } from "viem";
2
+ import { Abi, Address, ContractFunctionArgs, ContractFunctionName, Hex, PublicClient, ReadContractParameters, ReadContractReturnType, TransactionRequest } from "viem";
3
3
  import { Network } from "../network";
4
4
  import { EvmWalletProvider } from "./evmWalletProvider";
5
5
  import { WalletProviderWithClient, CdpWalletProviderConfig } from "./cdpShared";
@@ -83,6 +83,12 @@ export declare class CdpEvmWalletProvider extends EvmWalletProvider implements W
83
83
  * @returns The CDP client.
84
84
  */
85
85
  getClient(): CdpClient;
86
+ /**
87
+ * Gets the Viem PublicClient used for read-only operations.
88
+ *
89
+ * @returns The Viem PublicClient instance used for read-only operations.
90
+ */
91
+ getPublicClient(): PublicClient;
86
92
  /**
87
93
  * Gets the balance of the wallet.
88
94
  *
@@ -67,9 +67,10 @@ class CdpEvmWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
67
67
  const serverAccount = await (config.address
68
68
  ? cdpClient.evm.getAccount({ address: config.address })
69
69
  : cdpClient.evm.createAccount({ idempotencyKey }));
70
+ const rpcUrl = config.rpcUrl || process.env.RPC_URL;
70
71
  const publicClient = (0, viem_1.createPublicClient)({
71
72
  chain: network_1.NETWORK_ID_TO_VIEM_CHAIN[networkId],
72
- transport: (0, viem_1.http)(),
73
+ transport: rpcUrl ? (0, viem_1.http)(rpcUrl) : (0, viem_1.http)(),
73
74
  });
74
75
  return new CdpEvmWalletProvider({
75
76
  publicClient,
@@ -188,6 +189,14 @@ class CdpEvmWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
188
189
  getClient() {
189
190
  return __classPrivateFieldGet(this, _CdpEvmWalletProvider_cdp, "f");
190
191
  }
192
+ /**
193
+ * Gets the Viem PublicClient used for read-only operations.
194
+ *
195
+ * @returns The Viem PublicClient instance used for read-only operations.
196
+ */
197
+ getPublicClient() {
198
+ return __classPrivateFieldGet(this, _CdpEvmWalletProvider_publicClient, "f");
199
+ }
191
200
  /**
192
201
  * Gets the balance of the wallet.
193
202
  *
@@ -30,6 +30,11 @@ export interface CdpWalletProviderConfig extends CdpProviderConfig {
30
30
  * The idempotency key of the wallet. Only used when creating a new account.
31
31
  */
32
32
  idempotencyKey?: string;
33
+ /**
34
+ * Optional RPC URL for Viem public client HTTP transport.
35
+ * Falls back to process.env.RPC_URL when not provided.
36
+ */
37
+ rpcUrl?: string;
33
38
  }
34
39
  export interface CdpSmartWalletProviderConfig extends CdpWalletProviderConfig {
35
40
  /**
@@ -1,5 +1,5 @@
1
- import { CdpClient } from "@coinbase/cdp-sdk";
2
- import { Abi, Address, ContractFunctionArgs, ContractFunctionName, Hex, ReadContractParameters, ReadContractReturnType, TransactionRequest } from "viem";
1
+ import { CdpClient, EvmSmartAccount } from "@coinbase/cdp-sdk";
2
+ import { Abi, Address, ContractFunctionArgs, ContractFunctionName, Hex, PublicClient, ReadContractParameters, ReadContractReturnType, TransactionRequest } from "viem";
3
3
  import { Network } from "../network";
4
4
  import { EvmWalletProvider } from "./evmWalletProvider";
5
5
  import { WalletProviderWithClient, CdpSmartWalletProviderConfig } from "./cdpShared";
@@ -8,6 +8,7 @@ import { WalletProviderWithClient, CdpSmartWalletProviderConfig } from "./cdpSha
8
8
  */
9
9
  export declare class CdpSmartWalletProvider extends EvmWalletProvider implements WalletProviderWithClient {
10
10
  #private;
11
+ smartAccount: EvmSmartAccount;
11
12
  /**
12
13
  * Constructs a new CdpSmartWalletProvider.
13
14
  *
@@ -90,6 +91,12 @@ export declare class CdpSmartWalletProvider extends EvmWalletProvider implements
90
91
  * @returns The paymaster URL if configured, undefined otherwise.
91
92
  */
92
93
  getPaymasterUrl(): string | undefined;
94
+ /**
95
+ * Gets the Viem PublicClient used for read-only operations.
96
+ *
97
+ * @returns The Viem PublicClient instance used for read-only operations.
98
+ */
99
+ getPublicClient(): PublicClient;
93
100
  /**
94
101
  * Gets the balance of the smart wallet.
95
102
  *
@@ -10,7 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  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");
11
11
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
12
  };
13
- var _CdpSmartWalletProvider_instances, _CdpSmartWalletProvider_publicClient, _CdpSmartWalletProvider_smartAccount, _CdpSmartWalletProvider_ownerAccount, _CdpSmartWalletProvider_cdp, _CdpSmartWalletProvider_network, _CdpSmartWalletProvider_paymasterUrl, _CdpSmartWalletProvider_getCdpSdkNetwork;
13
+ var _CdpSmartWalletProvider_instances, _CdpSmartWalletProvider_publicClient, _CdpSmartWalletProvider_ownerAccount, _CdpSmartWalletProvider_cdp, _CdpSmartWalletProvider_network, _CdpSmartWalletProvider_paymasterUrl, _CdpSmartWalletProvider_getCdpSdkNetwork;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.CdpSmartWalletProvider = void 0;
16
16
  const cdp_sdk_1 = require("@coinbase/cdp-sdk");
@@ -30,12 +30,11 @@ class CdpSmartWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
30
30
  super();
31
31
  _CdpSmartWalletProvider_instances.add(this);
32
32
  _CdpSmartWalletProvider_publicClient.set(this, void 0);
33
- _CdpSmartWalletProvider_smartAccount.set(this, void 0);
34
33
  _CdpSmartWalletProvider_ownerAccount.set(this, void 0);
35
34
  _CdpSmartWalletProvider_cdp.set(this, void 0);
36
35
  _CdpSmartWalletProvider_network.set(this, void 0);
37
36
  _CdpSmartWalletProvider_paymasterUrl.set(this, void 0);
38
- __classPrivateFieldSet(this, _CdpSmartWalletProvider_smartAccount, config.smartAccount, "f");
37
+ this.smartAccount = config.smartAccount;
39
38
  __classPrivateFieldSet(this, _CdpSmartWalletProvider_ownerAccount, config.ownerAccount, "f");
40
39
  __classPrivateFieldSet(this, _CdpSmartWalletProvider_cdp, config.cdp, "f");
41
40
  __classPrivateFieldSet(this, _CdpSmartWalletProvider_publicClient, config.publicClient, "f");
@@ -93,9 +92,10 @@ class CdpSmartWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
93
92
  : cdpClient.evm.createSmartAccount({
94
93
  owner: ownerAccount,
95
94
  }));
95
+ const rpcUrl = config.rpcUrl || process.env.RPC_URL;
96
96
  const publicClient = (0, viem_1.createPublicClient)({
97
97
  chain: network_1.NETWORK_ID_TO_VIEM_CHAIN[networkId],
98
- transport: (0, viem_1.http)(),
98
+ transport: rpcUrl ? (0, viem_1.http)(rpcUrl) : (0, viem_1.http)(),
99
99
  });
100
100
  return new CdpSmartWalletProvider({
101
101
  publicClient,
@@ -113,8 +113,8 @@ class CdpSmartWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
113
113
  */
114
114
  async exportWallet() {
115
115
  return {
116
- name: __classPrivateFieldGet(this, _CdpSmartWalletProvider_smartAccount, "f").name,
117
- address: __classPrivateFieldGet(this, _CdpSmartWalletProvider_smartAccount, "f").address,
116
+ name: this.smartAccount.name,
117
+ address: this.smartAccount.address,
118
118
  ownerAddress: __classPrivateFieldGet(this, _CdpSmartWalletProvider_ownerAccount, "f").address,
119
119
  };
120
120
  }
@@ -136,7 +136,7 @@ class CdpSmartWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
136
136
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
137
137
  async signTypedData(typedData) {
138
138
  const { domain, types, primaryType, message } = typedData;
139
- return await __classPrivateFieldGet(this, _CdpSmartWalletProvider_smartAccount, "f").signTypedData({
139
+ return await this.smartAccount.signTypedData({
140
140
  domain,
141
141
  types,
142
142
  primaryType,
@@ -168,7 +168,7 @@ class CdpSmartWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
168
168
  },
169
169
  ];
170
170
  const userOperation = await __classPrivateFieldGet(this, _CdpSmartWalletProvider_cdp, "f").evm.sendUserOperation({
171
- smartAccount: __classPrivateFieldGet(this, _CdpSmartWalletProvider_smartAccount, "f"),
171
+ smartAccount: this.smartAccount,
172
172
  network: __classPrivateFieldGet(this, _CdpSmartWalletProvider_instances, "m", _CdpSmartWalletProvider_getCdpSdkNetwork).call(this),
173
173
  calls,
174
174
  paymasterUrl: __classPrivateFieldGet(this, _CdpSmartWalletProvider_paymasterUrl, "f"),
@@ -181,7 +181,7 @@ class CdpSmartWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
181
181
  * @returns The address of the smart wallet.
182
182
  */
183
183
  getAddress() {
184
- return __classPrivateFieldGet(this, _CdpSmartWalletProvider_smartAccount, "f").address;
184
+ return this.smartAccount.address;
185
185
  }
186
186
  /**
187
187
  * Gets the network of the wallet.
@@ -215,13 +215,21 @@ class CdpSmartWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
215
215
  getPaymasterUrl() {
216
216
  return __classPrivateFieldGet(this, _CdpSmartWalletProvider_paymasterUrl, "f");
217
217
  }
218
+ /**
219
+ * Gets the Viem PublicClient used for read-only operations.
220
+ *
221
+ * @returns The Viem PublicClient instance used for read-only operations.
222
+ */
223
+ getPublicClient() {
224
+ return __classPrivateFieldGet(this, _CdpSmartWalletProvider_publicClient, "f");
225
+ }
218
226
  /**
219
227
  * Gets the balance of the smart wallet.
220
228
  *
221
229
  * @returns The balance of the wallet in wei
222
230
  */
223
231
  async getBalance() {
224
- return await __classPrivateFieldGet(this, _CdpSmartWalletProvider_publicClient, "f").getBalance({ address: __classPrivateFieldGet(this, _CdpSmartWalletProvider_smartAccount, "f").address });
232
+ return await __classPrivateFieldGet(this, _CdpSmartWalletProvider_publicClient, "f").getBalance({ address: this.smartAccount.address });
225
233
  }
226
234
  /**
227
235
  * Waits for a user operation receipt.
@@ -235,7 +243,7 @@ class CdpSmartWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
235
243
  // This is a simplified implementation - in practice you might want to poll
236
244
  // the CDP API for user operation status
237
245
  return __classPrivateFieldGet(this, _CdpSmartWalletProvider_cdp, "f").evm.waitForUserOperation({
238
- smartAccountAddress: __classPrivateFieldGet(this, _CdpSmartWalletProvider_smartAccount, "f").address,
246
+ smartAccountAddress: this.smartAccount.address,
239
247
  userOpHash,
240
248
  });
241
249
  }
@@ -264,7 +272,7 @@ class CdpSmartWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
264
272
  }
265
273
  }
266
274
  exports.CdpSmartWalletProvider = CdpSmartWalletProvider;
267
- _CdpSmartWalletProvider_publicClient = new WeakMap(), _CdpSmartWalletProvider_smartAccount = new WeakMap(), _CdpSmartWalletProvider_ownerAccount = new WeakMap(), _CdpSmartWalletProvider_cdp = new WeakMap(), _CdpSmartWalletProvider_network = new WeakMap(), _CdpSmartWalletProvider_paymasterUrl = new WeakMap(), _CdpSmartWalletProvider_instances = new WeakSet(), _CdpSmartWalletProvider_getCdpSdkNetwork = function _CdpSmartWalletProvider_getCdpSdkNetwork() {
275
+ _CdpSmartWalletProvider_publicClient = new WeakMap(), _CdpSmartWalletProvider_ownerAccount = new WeakMap(), _CdpSmartWalletProvider_cdp = new WeakMap(), _CdpSmartWalletProvider_network = new WeakMap(), _CdpSmartWalletProvider_paymasterUrl = new WeakMap(), _CdpSmartWalletProvider_instances = new WeakSet(), _CdpSmartWalletProvider_getCdpSdkNetwork = function _CdpSmartWalletProvider_getCdpSdkNetwork() {
268
276
  switch (__classPrivateFieldGet(this, _CdpSmartWalletProvider_network, "f").networkId) {
269
277
  case "base-sepolia":
270
278
  return "base-sepolia";
@@ -1,5 +1,5 @@
1
1
  import { WalletProvider } from "./walletProvider";
2
- import { TransactionRequest, ReadContractParameters, ReadContractReturnType, ContractFunctionName, Abi, ContractFunctionArgs, Account } from "viem";
2
+ import { TransactionRequest, ReadContractParameters, ReadContractReturnType, ContractFunctionName, Abi, ContractFunctionArgs, Account, PublicClient } from "viem";
3
3
  /**
4
4
  * EvmWalletProvider is the abstract base class for all EVM wallet providers.
5
5
  *
@@ -54,4 +54,8 @@ export declare abstract class EvmWalletProvider extends WalletProvider {
54
54
  * @returns The response from the contract.
55
55
  */
56
56
  abstract readContract<const abi extends Abi | readonly unknown[], functionName extends ContractFunctionName<abi, "pure" | "view">, const args extends ContractFunctionArgs<abi, "pure" | "view", functionName>>(params: ReadContractParameters<abi, functionName, args>): Promise<ReadContractReturnType<abi, functionName, args>>;
57
+ /**
58
+ * Get the underlying Viem PublicClient for read-only blockchain operations.
59
+ */
60
+ abstract getPublicClient(): PublicClient;
57
61
  }
@@ -1,5 +1,5 @@
1
1
  import { SendUserOperationOptions, Signer } from "@coinbase/coinbase-sdk";
2
- import { Abi, Address, ContractFunctionArgs, ContractFunctionName, Hex, ReadContractParameters, ReadContractReturnType, TransactionRequest } from "viem";
2
+ import { Abi, Address, ContractFunctionArgs, ContractFunctionName, Hex, ReadContractParameters, ReadContractReturnType, TransactionRequest, PublicClient as ViemPublicClient } from "viem";
3
3
  import { Network } from "../network";
4
4
  import { EvmWalletProvider } from "./evmWalletProvider";
5
5
  export interface ConfigureLegacyCdpSmartWalletOptions {
@@ -9,6 +9,7 @@ export interface ConfigureLegacyCdpSmartWalletOptions {
9
9
  smartWalletAddress?: Hex;
10
10
  paymasterUrl?: string;
11
11
  signer: Signer;
12
+ rpcUrl?: string;
12
13
  }
13
14
  /**
14
15
  * A wallet provider that uses Smart Wallets from the Coinbase SDK.
@@ -146,6 +147,12 @@ export declare class LegacyCdpSmartWalletProvider extends EvmWalletProvider {
146
147
  * @returns The name of the wallet provider.
147
148
  */
148
149
  getName(): string;
150
+ /**
151
+ * Gets the Viem PublicClient used for read-only operations.
152
+ *
153
+ * @returns The Viem PublicClient instance used for read-only operations.
154
+ */
155
+ getPublicClient(): ViemPublicClient;
149
156
  /**
150
157
  * Gets the balance of the wallet.
151
158
  *
@@ -34,9 +34,10 @@ class LegacyCdpSmartWalletProvider extends evmWalletProvider_1.EvmWalletProvider
34
34
  _LegacyCdpSmartWalletProvider_publicClient.set(this, void 0);
35
35
  __classPrivateFieldSet(this, _LegacyCdpSmartWalletProvider_network, config.network, "f");
36
36
  __classPrivateFieldSet(this, _LegacyCdpSmartWalletProvider_smartWallet, config.smartWallet, "f");
37
+ const rpcUrl = config.rpcUrl || process.env.RPC_URL;
37
38
  __classPrivateFieldSet(this, _LegacyCdpSmartWalletProvider_publicClient, (0, viem_1.createPublicClient)({
38
39
  chain: network_1.NETWORK_ID_TO_VIEM_CHAIN[config.network.networkId],
39
- transport: (0, viem_1.http)(),
40
+ transport: rpcUrl ? (0, viem_1.http)(rpcUrl) : (0, viem_1.http)(),
40
41
  }), "f");
41
42
  }
42
43
  /**
@@ -106,6 +107,7 @@ class LegacyCdpSmartWalletProvider extends evmWalletProvider_1.EvmWalletProvider
106
107
  smartWallet: networkScopedSmartWallet,
107
108
  network,
108
109
  chainId: network.chainId,
110
+ rpcUrl: config.rpcUrl,
109
111
  });
110
112
  return legacyCdpSmartWalletProvider;
111
113
  }
@@ -242,6 +244,14 @@ class LegacyCdpSmartWalletProvider extends evmWalletProvider_1.EvmWalletProvider
242
244
  getName() {
243
245
  return "legacy_cdp_smart_wallet_provider";
244
246
  }
247
+ /**
248
+ * Gets the Viem PublicClient used for read-only operations.
249
+ *
250
+ * @returns The Viem PublicClient instance used for read-only operations.
251
+ */
252
+ getPublicClient() {
253
+ return __classPrivateFieldGet(this, _LegacyCdpSmartWalletProvider_publicClient, "f");
254
+ }
245
255
  /**
246
256
  * Gets the balance of the wallet.
247
257
  *