@coinbase/agentkit 0.6.2 → 0.7.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.
- package/README.md +234 -0
- package/dist/action-providers/cdp-v2/cdpApiV2ActionProvider.d.ts +37 -0
- package/dist/action-providers/cdp-v2/cdpApiV2ActionProvider.js +91 -0
- package/dist/action-providers/cdp-v2/index.d.ts +2 -0
- package/dist/action-providers/cdp-v2/index.js +18 -0
- package/dist/action-providers/cdp-v2/schemas.d.ts +11 -0
- package/dist/action-providers/cdp-v2/schemas.js +13 -0
- package/dist/action-providers/compound/schemas.d.ts +8 -8
- package/dist/action-providers/index.d.ts +2 -0
- package/dist/action-providers/index.js +2 -0
- package/dist/action-providers/zerodev/index.d.ts +1 -0
- package/dist/action-providers/zerodev/index.js +17 -0
- package/dist/action-providers/zerodev/schemas.d.ts +29 -0
- package/dist/action-providers/zerodev/schemas.js +21 -0
- package/dist/action-providers/zerodev/zeroDevWalletActionProvider.d.ts +32 -0
- package/dist/action-providers/zerodev/zeroDevWalletActionProvider.js +66 -0
- package/dist/action-providers/zerodev/zeroDevWalletActionProvider.test.d.ts +1 -0
- package/dist/action-providers/zerodev/zeroDevWalletActionProvider.test.js +112 -0
- package/dist/network/svm.d.ts +1 -0
- package/dist/network/svm.js +6 -1
- package/dist/wallet-providers/cdpV2EvmWalletProvider.d.ts +105 -0
- package/dist/wallet-providers/cdpV2EvmWalletProvider.js +212 -0
- package/dist/wallet-providers/cdpV2EvmWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/cdpV2EvmWalletProvider.test.js +343 -0
- package/dist/wallet-providers/cdpV2Shared.d.ts +41 -0
- package/dist/wallet-providers/cdpV2Shared.js +2 -0
- package/dist/wallet-providers/cdpV2SolanaWalletProvider.d.ts +111 -0
- package/dist/wallet-providers/cdpV2SolanaWalletProvider.js +247 -0
- package/dist/wallet-providers/cdpV2SolanaWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/cdpV2SolanaWalletProvider.test.js +307 -0
- package/dist/wallet-providers/cdpV2WalletProvider.d.ts +35 -0
- package/dist/wallet-providers/cdpV2WalletProvider.js +42 -0
- package/dist/wallet-providers/cdpWalletProvider.js +1 -1
- package/dist/wallet-providers/cdpWalletProvider.test.js +1 -0
- package/dist/wallet-providers/evmWalletProvider.d.ts +7 -1
- package/dist/wallet-providers/evmWalletProvider.js +20 -0
- package/dist/wallet-providers/index.d.ts +5 -0
- package/dist/wallet-providers/index.js +5 -0
- package/dist/wallet-providers/walletProvider.test.js +22 -0
- package/dist/wallet-providers/zeroDevWalletProvider.d.ts +147 -0
- package/dist/wallet-providers/zeroDevWalletProvider.js +301 -0
- package/dist/wallet-providers/zeroDevWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/zeroDevWalletProvider.test.js +435 -0
- package/package.json +5 -1
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const cdp_sdk_1 = require("@coinbase/cdp-sdk");
|
|
4
|
+
const cdpV2EvmWalletProvider_1 = require("./cdpV2EvmWalletProvider");
|
|
5
|
+
// =========================================================
|
|
6
|
+
// consts
|
|
7
|
+
// =========================================================
|
|
8
|
+
const mockPublicClient = {
|
|
9
|
+
waitForTransactionReceipt: jest.fn(),
|
|
10
|
+
readContract: jest.fn(),
|
|
11
|
+
getTransactionCount: jest.fn(),
|
|
12
|
+
estimateFeesPerGas: jest.fn(),
|
|
13
|
+
estimateGas: jest.fn(),
|
|
14
|
+
getBalance: jest.fn(),
|
|
15
|
+
};
|
|
16
|
+
const mockWalletClient = {
|
|
17
|
+
sendTransaction: jest.fn(),
|
|
18
|
+
};
|
|
19
|
+
// =========================================================
|
|
20
|
+
// mocks
|
|
21
|
+
// =========================================================
|
|
22
|
+
jest.mock("../analytics", () => ({
|
|
23
|
+
sendAnalyticsEvent: jest.fn().mockImplementation(() => Promise.resolve()),
|
|
24
|
+
}));
|
|
25
|
+
jest.mock("../../package.json", () => ({
|
|
26
|
+
version: "1.0.0",
|
|
27
|
+
}));
|
|
28
|
+
jest.mock("viem", () => {
|
|
29
|
+
return {
|
|
30
|
+
createPublicClient: jest.fn(() => mockPublicClient),
|
|
31
|
+
createWalletClient: jest.fn(() => mockWalletClient),
|
|
32
|
+
http: jest.fn(),
|
|
33
|
+
serializeTransaction: jest.fn((_tx) => "0xserialized"),
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
jest.mock("../network", () => {
|
|
37
|
+
return {
|
|
38
|
+
NETWORK_ID_TO_CHAIN_ID: {
|
|
39
|
+
"base-mainnet": "8453",
|
|
40
|
+
"base-sepolia": "84532",
|
|
41
|
+
},
|
|
42
|
+
NETWORK_ID_TO_VIEM_CHAIN: {
|
|
43
|
+
"base-mainnet": { id: 8453 },
|
|
44
|
+
"base-sepolia": { id: 84532 },
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
// Mock CdpClient
|
|
49
|
+
jest.mock("@coinbase/cdp-sdk", () => {
|
|
50
|
+
const MOCK_ADDRESS = "0x742d35Cc6634C0532925a3b844Bc454e4438f44e";
|
|
51
|
+
const MOCK_SIGNATURE = "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1b01";
|
|
52
|
+
const mockCreateAccount = jest.fn().mockImplementation(() => Promise.resolve({
|
|
53
|
+
address: MOCK_ADDRESS,
|
|
54
|
+
signMessage: jest.fn().mockResolvedValue(MOCK_SIGNATURE),
|
|
55
|
+
signTypedData: jest.fn().mockResolvedValue(MOCK_SIGNATURE),
|
|
56
|
+
signTransaction: jest.fn().mockResolvedValue({ signature: MOCK_SIGNATURE }),
|
|
57
|
+
}));
|
|
58
|
+
const mockSignTransaction = jest
|
|
59
|
+
.fn()
|
|
60
|
+
.mockImplementation(async () => ({ signature: MOCK_SIGNATURE }));
|
|
61
|
+
const mockSendTransaction = jest
|
|
62
|
+
.fn()
|
|
63
|
+
.mockImplementation(async () => ({ transactionHash: MOCK_TRANSACTION_HASH }));
|
|
64
|
+
const mockEvmClient = {
|
|
65
|
+
createAccount: mockCreateAccount,
|
|
66
|
+
getAccount: jest.fn(),
|
|
67
|
+
signTransaction: mockSignTransaction,
|
|
68
|
+
sendTransaction: mockSendTransaction,
|
|
69
|
+
};
|
|
70
|
+
return {
|
|
71
|
+
CdpClient: jest.fn().mockImplementation(() => ({
|
|
72
|
+
evm: mockEvmClient,
|
|
73
|
+
})),
|
|
74
|
+
EvmServerAccount: jest.fn().mockImplementation(() => ({
|
|
75
|
+
address: MOCK_ADDRESS,
|
|
76
|
+
signMessage: jest.fn().mockResolvedValue(MOCK_SIGNATURE),
|
|
77
|
+
signTypedData: jest.fn().mockResolvedValue(MOCK_SIGNATURE),
|
|
78
|
+
signTransaction: jest.fn().mockResolvedValue({ signature: MOCK_SIGNATURE }),
|
|
79
|
+
})),
|
|
80
|
+
};
|
|
81
|
+
});
|
|
82
|
+
// =========================================================
|
|
83
|
+
// test constants
|
|
84
|
+
// =========================================================
|
|
85
|
+
const MOCK_ADDRESS = "0x742d35Cc6634C0532925a3b844Bc454e4438f44e";
|
|
86
|
+
const MOCK_NETWORK_ID = "base-mainnet";
|
|
87
|
+
const MOCK_TRANSACTION_HASH = "0x9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba";
|
|
88
|
+
const MOCK_SIGNATURE = "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1b01";
|
|
89
|
+
const MOCK_BALANCE = 1000000000000000000n;
|
|
90
|
+
const MOCK_NETWORK = {
|
|
91
|
+
protocolFamily: "evm",
|
|
92
|
+
networkId: MOCK_NETWORK_ID,
|
|
93
|
+
chainId: "8453",
|
|
94
|
+
};
|
|
95
|
+
const MOCK_TRANSACTION_RECEIPT = {
|
|
96
|
+
transactionHash: MOCK_TRANSACTION_HASH,
|
|
97
|
+
};
|
|
98
|
+
describe("CdpV2EvmWalletProvider", () => {
|
|
99
|
+
let provider;
|
|
100
|
+
let mockCdpClient;
|
|
101
|
+
let mockServerAccount;
|
|
102
|
+
let mockSignTransaction;
|
|
103
|
+
let mockSendTransaction;
|
|
104
|
+
beforeEach(async () => {
|
|
105
|
+
jest.clearAllMocks();
|
|
106
|
+
mockSignTransaction = jest.fn().mockImplementation(async () => ({ signature: MOCK_SIGNATURE }));
|
|
107
|
+
mockSendTransaction = jest
|
|
108
|
+
.fn()
|
|
109
|
+
.mockImplementation(async () => ({ transactionHash: MOCK_TRANSACTION_HASH }));
|
|
110
|
+
mockCdpClient = new cdp_sdk_1.CdpClient({
|
|
111
|
+
apiKeyId: "test-key-id",
|
|
112
|
+
apiKeySecret: "test-key-secret",
|
|
113
|
+
walletSecret: "test-wallet-secret",
|
|
114
|
+
});
|
|
115
|
+
mockServerAccount = {
|
|
116
|
+
address: MOCK_ADDRESS,
|
|
117
|
+
signMessage: jest.fn().mockResolvedValue(MOCK_SIGNATURE),
|
|
118
|
+
signTypedData: jest.fn().mockResolvedValue(MOCK_SIGNATURE),
|
|
119
|
+
};
|
|
120
|
+
// Set up the mock server account for the provider
|
|
121
|
+
mockCdpClient.evm.createAccount.mockResolvedValue(mockServerAccount);
|
|
122
|
+
mockCdpClient.evm.signTransaction = mockSignTransaction;
|
|
123
|
+
mockCdpClient.evm.sendTransaction = mockSendTransaction;
|
|
124
|
+
mockPublicClient.waitForTransactionReceipt.mockResolvedValue(MOCK_TRANSACTION_RECEIPT);
|
|
125
|
+
mockPublicClient.readContract.mockResolvedValue("mock_result");
|
|
126
|
+
mockPublicClient.getTransactionCount.mockResolvedValue(1);
|
|
127
|
+
mockPublicClient.estimateFeesPerGas.mockResolvedValue({
|
|
128
|
+
maxFeePerGas: BigInt(100000000),
|
|
129
|
+
maxPriorityFeePerGas: BigInt(10000000),
|
|
130
|
+
});
|
|
131
|
+
mockPublicClient.estimateGas.mockResolvedValue(BigInt(21000));
|
|
132
|
+
mockPublicClient.getBalance.mockResolvedValue(MOCK_BALANCE);
|
|
133
|
+
mockWalletClient.sendTransaction.mockResolvedValue(MOCK_TRANSACTION_HASH);
|
|
134
|
+
provider = await cdpV2EvmWalletProvider_1.CdpV2EvmWalletProvider.configureWithWallet({
|
|
135
|
+
apiKeyId: "test-key-id",
|
|
136
|
+
apiKeySecret: "test-key-secret",
|
|
137
|
+
walletSecret: "test-wallet-secret",
|
|
138
|
+
networkId: MOCK_NETWORK_ID,
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
// =========================================================
|
|
142
|
+
// initialization tests
|
|
143
|
+
// =========================================================
|
|
144
|
+
describe("initialization", () => {
|
|
145
|
+
it("should initialize with API keys", async () => {
|
|
146
|
+
const provider = await cdpV2EvmWalletProvider_1.CdpV2EvmWalletProvider.configureWithWallet({
|
|
147
|
+
apiKeyId: "test-key-id",
|
|
148
|
+
apiKeySecret: "test-key-secret",
|
|
149
|
+
walletSecret: "test-wallet-secret",
|
|
150
|
+
networkId: MOCK_NETWORK_ID,
|
|
151
|
+
});
|
|
152
|
+
expect(provider.getAddress()).toBe(MOCK_ADDRESS);
|
|
153
|
+
expect(provider.getNetwork()).toEqual(MOCK_NETWORK);
|
|
154
|
+
});
|
|
155
|
+
it("should default to base-sepolia if network not provided", async () => {
|
|
156
|
+
const provider = await cdpV2EvmWalletProvider_1.CdpV2EvmWalletProvider.configureWithWallet({
|
|
157
|
+
apiKeyId: "test-key-id",
|
|
158
|
+
apiKeySecret: "test-key-secret",
|
|
159
|
+
walletSecret: "test-wallet-secret",
|
|
160
|
+
});
|
|
161
|
+
expect(provider.getNetwork().networkId).toBe("base-sepolia");
|
|
162
|
+
});
|
|
163
|
+
it("should handle initialization failures gracefully", async () => {
|
|
164
|
+
// Create a new mock client for this test
|
|
165
|
+
const mockCreateAccount = jest.fn().mockRejectedValue(new Error("Failed to create account"));
|
|
166
|
+
const mockEvmClient = {
|
|
167
|
+
createAccount: mockCreateAccount,
|
|
168
|
+
getAccount: jest.fn(),
|
|
169
|
+
signTransaction: jest.fn(),
|
|
170
|
+
};
|
|
171
|
+
// Override the mock for this test
|
|
172
|
+
const mockCdpClient = new cdp_sdk_1.CdpClient({
|
|
173
|
+
apiKeyId: "test-key-id",
|
|
174
|
+
apiKeySecret: "test-key-secret",
|
|
175
|
+
walletSecret: "test-wallet-secret",
|
|
176
|
+
});
|
|
177
|
+
mockCdpClient.evm = mockEvmClient;
|
|
178
|
+
// Override the CdpClient constructor mock
|
|
179
|
+
cdp_sdk_1.CdpClient.mockImplementation(() => mockCdpClient);
|
|
180
|
+
await expect(cdpV2EvmWalletProvider_1.CdpV2EvmWalletProvider.configureWithWallet({
|
|
181
|
+
apiKeyId: "test-key-id",
|
|
182
|
+
apiKeySecret: "test-key-secret",
|
|
183
|
+
walletSecret: "test-wallet-secret",
|
|
184
|
+
networkId: MOCK_NETWORK_ID,
|
|
185
|
+
})).rejects.toThrow("Failed to create account");
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
// =========================================================
|
|
189
|
+
// basic wallet method tests
|
|
190
|
+
// =========================================================
|
|
191
|
+
describe("basic wallet methods", () => {
|
|
192
|
+
it("should get the address", () => {
|
|
193
|
+
expect(provider.getAddress()).toBe(MOCK_ADDRESS);
|
|
194
|
+
});
|
|
195
|
+
it("should get the network", () => {
|
|
196
|
+
expect(provider.getNetwork()).toEqual(MOCK_NETWORK);
|
|
197
|
+
});
|
|
198
|
+
it("should get the name", () => {
|
|
199
|
+
expect(provider.getName()).toBe("cdp_v2_wallet_provider");
|
|
200
|
+
});
|
|
201
|
+
it("should get the balance", async () => {
|
|
202
|
+
const balance = await provider.getBalance();
|
|
203
|
+
expect(balance).toBe(MOCK_BALANCE);
|
|
204
|
+
expect(mockPublicClient.getBalance).toHaveBeenCalledWith({
|
|
205
|
+
address: MOCK_ADDRESS,
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
it("should handle connection errors during balance check", async () => {
|
|
209
|
+
mockPublicClient.getBalance.mockRejectedValueOnce(new Error("Network connection error"));
|
|
210
|
+
await expect(provider.getBalance()).rejects.toThrow("Network connection error");
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
// =========================================================
|
|
214
|
+
// signing operation tests
|
|
215
|
+
// =========================================================
|
|
216
|
+
describe("signing operations", () => {
|
|
217
|
+
it("should sign messages", async () => {
|
|
218
|
+
const signature = await provider.signMessage("Hello, world!");
|
|
219
|
+
expect(mockServerAccount.signMessage).toHaveBeenCalledWith({ message: "Hello, world!" });
|
|
220
|
+
expect(signature).toBe(MOCK_SIGNATURE);
|
|
221
|
+
});
|
|
222
|
+
it("should sign typed data", async () => {
|
|
223
|
+
const typedData = {
|
|
224
|
+
domain: { name: "Example" },
|
|
225
|
+
types: { Test: [{ name: "test", type: "string" }] },
|
|
226
|
+
message: { test: "example" },
|
|
227
|
+
primaryType: "Test",
|
|
228
|
+
};
|
|
229
|
+
const signature = await provider.signTypedData(typedData);
|
|
230
|
+
expect(mockServerAccount.signTypedData).toHaveBeenCalledWith(typedData);
|
|
231
|
+
expect(signature).toBe(MOCK_SIGNATURE);
|
|
232
|
+
});
|
|
233
|
+
it("should sign transactions", async () => {
|
|
234
|
+
const tx = {
|
|
235
|
+
to: "0x1234567890123456789012345678901234567890",
|
|
236
|
+
value: BigInt(1000000000000000000),
|
|
237
|
+
};
|
|
238
|
+
const signature = await provider.signTransaction(tx);
|
|
239
|
+
expect(mockCdpClient.evm.signTransaction).toHaveBeenCalledWith({
|
|
240
|
+
address: MOCK_ADDRESS,
|
|
241
|
+
transaction: expect.any(String),
|
|
242
|
+
});
|
|
243
|
+
expect(signature).toBe(MOCK_SIGNATURE);
|
|
244
|
+
});
|
|
245
|
+
it("should handle signing failures", async () => {
|
|
246
|
+
// Create a failing mock for this test
|
|
247
|
+
const mockFailingSignTransaction = jest.fn().mockRejectedValue(new Error("Signing failed"));
|
|
248
|
+
mockCdpClient.evm.signTransaction = mockFailingSignTransaction;
|
|
249
|
+
const tx = {
|
|
250
|
+
to: "0x1234567890123456789012345678901234567890",
|
|
251
|
+
value: BigInt(1000000000000000000),
|
|
252
|
+
};
|
|
253
|
+
await expect(provider.signTransaction(tx)).rejects.toThrow("Signing failed");
|
|
254
|
+
// Restore the original mock
|
|
255
|
+
mockCdpClient.evm.signTransaction = mockSignTransaction;
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
// =========================================================
|
|
259
|
+
// transaction operation tests
|
|
260
|
+
// =========================================================
|
|
261
|
+
describe("transaction operations", () => {
|
|
262
|
+
it("should send transactions", async () => {
|
|
263
|
+
const transaction = {
|
|
264
|
+
to: "0x1234567890123456789012345678901234567890",
|
|
265
|
+
value: BigInt(1000000000000000000),
|
|
266
|
+
};
|
|
267
|
+
const txHash = await provider.sendTransaction(transaction);
|
|
268
|
+
expect(mockSendTransaction).toHaveBeenCalled();
|
|
269
|
+
expect(txHash).toBe(MOCK_TRANSACTION_HASH);
|
|
270
|
+
});
|
|
271
|
+
it("should handle transaction failures during send", async () => {
|
|
272
|
+
mockSendTransaction.mockRejectedValueOnce(new Error("Transaction signing failed"));
|
|
273
|
+
const transaction = {
|
|
274
|
+
to: "0x1234567890123456789012345678901234567890",
|
|
275
|
+
value: BigInt(1000000000000000000),
|
|
276
|
+
};
|
|
277
|
+
await expect(provider.sendTransaction(transaction)).rejects.toThrow("Transaction signing failed");
|
|
278
|
+
});
|
|
279
|
+
it("should handle receipt timeout errors", async () => {
|
|
280
|
+
mockPublicClient.waitForTransactionReceipt.mockRejectedValueOnce(new Error("Timed out"));
|
|
281
|
+
const hash = "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef";
|
|
282
|
+
await expect(provider.waitForTransactionReceipt(hash)).rejects.toThrow("Timed out");
|
|
283
|
+
});
|
|
284
|
+
it("should handle transaction with invalid address", async () => {
|
|
285
|
+
mockSendTransaction.mockRejectedValueOnce(new Error("Invalid address format"));
|
|
286
|
+
const invalidAddress = "not_a_valid_address";
|
|
287
|
+
const value = "1000000000000000000"; // 1 ETH in wei
|
|
288
|
+
await expect(provider.nativeTransfer(invalidAddress, value)).rejects.toThrow("Invalid address format");
|
|
289
|
+
});
|
|
290
|
+
});
|
|
291
|
+
// =========================================================
|
|
292
|
+
// contract interaction tests
|
|
293
|
+
// =========================================================
|
|
294
|
+
describe("contract interactions", () => {
|
|
295
|
+
it("should read contract data", async () => {
|
|
296
|
+
const abi = [
|
|
297
|
+
{
|
|
298
|
+
name: "balanceOf",
|
|
299
|
+
type: "function",
|
|
300
|
+
inputs: [{ name: "account", type: "address" }],
|
|
301
|
+
outputs: [{ name: "balance", type: "uint256" }],
|
|
302
|
+
stateMutability: "view",
|
|
303
|
+
},
|
|
304
|
+
];
|
|
305
|
+
const result = await provider.readContract({
|
|
306
|
+
address: "0x1234567890123456789012345678901234567890",
|
|
307
|
+
abi,
|
|
308
|
+
functionName: "balanceOf",
|
|
309
|
+
args: [MOCK_ADDRESS],
|
|
310
|
+
});
|
|
311
|
+
expect(result).toBe("mock_result");
|
|
312
|
+
expect(mockPublicClient.readContract).toHaveBeenCalled();
|
|
313
|
+
});
|
|
314
|
+
it("should handle network errors during contract reads", async () => {
|
|
315
|
+
mockPublicClient.readContract.mockRejectedValueOnce(new Error("Contract read error"));
|
|
316
|
+
const abi = [
|
|
317
|
+
{
|
|
318
|
+
name: "balanceOf",
|
|
319
|
+
type: "function",
|
|
320
|
+
inputs: [{ name: "account", type: "address" }],
|
|
321
|
+
outputs: [{ name: "balance", type: "uint256" }],
|
|
322
|
+
stateMutability: "view",
|
|
323
|
+
},
|
|
324
|
+
];
|
|
325
|
+
await expect(provider.readContract({
|
|
326
|
+
address: "0x1234567890123456789012345678901234567890",
|
|
327
|
+
abi,
|
|
328
|
+
functionName: "balanceOf",
|
|
329
|
+
args: [MOCK_ADDRESS],
|
|
330
|
+
})).rejects.toThrow("Contract read error");
|
|
331
|
+
});
|
|
332
|
+
it("should handle invalid ABI format in contract reads", async () => {
|
|
333
|
+
mockPublicClient.readContract.mockRejectedValueOnce(new TypeError("Invalid ABI format"));
|
|
334
|
+
const invalidAbi = "not_a_valid_abi";
|
|
335
|
+
await expect(provider.readContract({
|
|
336
|
+
address: "0x1234567890123456789012345678901234567890",
|
|
337
|
+
abi: invalidAbi,
|
|
338
|
+
functionName: "balanceOf",
|
|
339
|
+
args: [MOCK_ADDRESS],
|
|
340
|
+
})).rejects.toThrow("Invalid ABI format");
|
|
341
|
+
});
|
|
342
|
+
});
|
|
343
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { CdpClient } from "@coinbase/cdp-sdk";
|
|
2
|
+
export interface CdpV2ProviderConfig {
|
|
3
|
+
/**
|
|
4
|
+
* The CDP API Key ID.
|
|
5
|
+
*/
|
|
6
|
+
apiKeyId?: string;
|
|
7
|
+
/**
|
|
8
|
+
* The CDP API Key Secret.
|
|
9
|
+
*/
|
|
10
|
+
apiKeySecret?: string;
|
|
11
|
+
/**
|
|
12
|
+
* The CDP Wallet Secret.
|
|
13
|
+
*/
|
|
14
|
+
walletSecret?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Configuration options for the CDP Providers.
|
|
18
|
+
*/
|
|
19
|
+
export interface CdpV2WalletProviderConfig extends CdpV2ProviderConfig {
|
|
20
|
+
/**
|
|
21
|
+
* The address of the wallet.
|
|
22
|
+
*/
|
|
23
|
+
address?: string;
|
|
24
|
+
/**
|
|
25
|
+
* The network of the wallet.
|
|
26
|
+
*/
|
|
27
|
+
networkId?: string;
|
|
28
|
+
/**
|
|
29
|
+
* The idempotency key of the wallet. Only used when creating a new account.
|
|
30
|
+
*/
|
|
31
|
+
idempotencyKey?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* A wallet provider that can be used to interact with the CDP.
|
|
35
|
+
*/
|
|
36
|
+
export interface WalletProviderWithClient {
|
|
37
|
+
/**
|
|
38
|
+
* Gets the CDP client.
|
|
39
|
+
*/
|
|
40
|
+
getClient(): CdpClient;
|
|
41
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { CdpClient } from "@coinbase/cdp-sdk";
|
|
2
|
+
import { Connection, PublicKey, RpcResponseAndContext, SignatureResult, SignatureStatus, SignatureStatusConfig, VersionedTransaction } from "@solana/web3.js";
|
|
3
|
+
import { Network } from "../network";
|
|
4
|
+
import { WalletProviderWithClient, CdpV2WalletProviderConfig } from "./cdpV2Shared";
|
|
5
|
+
import { SvmWalletProvider } from "./svmWalletProvider";
|
|
6
|
+
/**
|
|
7
|
+
* A wallet provider that uses the Coinbase SDK.
|
|
8
|
+
*/
|
|
9
|
+
export declare class CdpV2SolanaWalletProvider extends SvmWalletProvider implements WalletProviderWithClient {
|
|
10
|
+
#private;
|
|
11
|
+
/**
|
|
12
|
+
* Constructs a new CdpWalletProvider.
|
|
13
|
+
*
|
|
14
|
+
* @param config - The configuration options for the CdpWalletProvider.
|
|
15
|
+
*/
|
|
16
|
+
private constructor();
|
|
17
|
+
/**
|
|
18
|
+
* Configures a new CdpWalletProvider with a wallet.
|
|
19
|
+
*
|
|
20
|
+
* @param config - Optional configuration parameters
|
|
21
|
+
* @returns A Promise that resolves to a new CdpWalletProvider instance
|
|
22
|
+
* @throws Error if required environment variables are missing or wallet initialization fails
|
|
23
|
+
*/
|
|
24
|
+
static configureWithWallet(config?: CdpV2WalletProviderConfig): Promise<CdpV2SolanaWalletProvider>;
|
|
25
|
+
/**
|
|
26
|
+
* Get the connection instance
|
|
27
|
+
*
|
|
28
|
+
* @returns The Solana connection instance
|
|
29
|
+
*/
|
|
30
|
+
getConnection(): Connection;
|
|
31
|
+
/**
|
|
32
|
+
* Get the public key of the wallet
|
|
33
|
+
*
|
|
34
|
+
* @returns The wallet's public key
|
|
35
|
+
*/
|
|
36
|
+
getPublicKey(): PublicKey;
|
|
37
|
+
/**
|
|
38
|
+
* Get the address of the wallet
|
|
39
|
+
*
|
|
40
|
+
* @returns The base58 encoded address of the wallet
|
|
41
|
+
*/
|
|
42
|
+
getAddress(): string;
|
|
43
|
+
/**
|
|
44
|
+
* Get the network
|
|
45
|
+
*
|
|
46
|
+
* @returns The network
|
|
47
|
+
*/
|
|
48
|
+
getNetwork(): Network;
|
|
49
|
+
/**
|
|
50
|
+
* Gets the name of the wallet provider.
|
|
51
|
+
*
|
|
52
|
+
* @returns The name of the wallet provider.
|
|
53
|
+
*/
|
|
54
|
+
getName(): string;
|
|
55
|
+
/**
|
|
56
|
+
* Sign a transaction
|
|
57
|
+
*
|
|
58
|
+
* @param transaction - The transaction to sign
|
|
59
|
+
* @returns The signed transaction
|
|
60
|
+
*/
|
|
61
|
+
signTransaction(transaction: VersionedTransaction): Promise<VersionedTransaction>;
|
|
62
|
+
/**
|
|
63
|
+
* Send a transaction
|
|
64
|
+
*
|
|
65
|
+
* @param transaction - The transaction to send
|
|
66
|
+
* @returns The signature
|
|
67
|
+
*/
|
|
68
|
+
sendTransaction(transaction: VersionedTransaction): Promise<string>;
|
|
69
|
+
/**
|
|
70
|
+
* Sign and send a transaction
|
|
71
|
+
*
|
|
72
|
+
* @param transaction - The transaction to sign and send
|
|
73
|
+
* @returns The signature
|
|
74
|
+
*/
|
|
75
|
+
signAndSendTransaction(transaction: VersionedTransaction): Promise<string>;
|
|
76
|
+
/**
|
|
77
|
+
* Get the status of a transaction
|
|
78
|
+
*
|
|
79
|
+
* @param signature - The signature
|
|
80
|
+
* @param options - The options for the status
|
|
81
|
+
* @returns The status
|
|
82
|
+
*/
|
|
83
|
+
getSignatureStatus(signature: string, options?: SignatureStatusConfig): Promise<RpcResponseAndContext<SignatureStatus | null>>;
|
|
84
|
+
/**
|
|
85
|
+
* Wait for signature receipt
|
|
86
|
+
*
|
|
87
|
+
* @param signature - The signature
|
|
88
|
+
* @returns The confirmation response
|
|
89
|
+
*/
|
|
90
|
+
waitForSignatureResult(signature: string): Promise<RpcResponseAndContext<SignatureResult>>;
|
|
91
|
+
/**
|
|
92
|
+
* Get the balance of the wallet
|
|
93
|
+
*
|
|
94
|
+
* @returns The balance of the wallet
|
|
95
|
+
*/
|
|
96
|
+
getBalance(): Promise<bigint>;
|
|
97
|
+
/**
|
|
98
|
+
* Gets the CDP client.
|
|
99
|
+
*
|
|
100
|
+
* @returns The CDP client.
|
|
101
|
+
*/
|
|
102
|
+
getClient(): CdpClient;
|
|
103
|
+
/**
|
|
104
|
+
* Transfer SOL from the wallet to another address
|
|
105
|
+
*
|
|
106
|
+
* @param to - The base58 encoded address to transfer the SOL to
|
|
107
|
+
* @param value - The amount of SOL to transfer (as a decimal string, e.g. "0.0001")
|
|
108
|
+
* @returns The signature
|
|
109
|
+
*/
|
|
110
|
+
nativeTransfer(to: string, value: string): Promise<string>;
|
|
111
|
+
}
|