@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.
- package/README.md +373 -234
- package/dist/action-providers/cdp/cdpApiActionProvider.d.ts +15 -15
- package/dist/action-providers/cdp/cdpApiActionProvider.js +110 -63
- package/dist/action-providers/cdp/cdpApiActionProvider.test.js +205 -124
- package/dist/action-providers/cdp/index.d.ts +0 -1
- package/dist/action-providers/cdp/index.js +0 -1
- package/dist/action-providers/cdp/schemas.d.ts +9 -70
- package/dist/action-providers/cdp/schemas.js +12 -61
- package/dist/action-providers/cdp-legacy/index.d.ts +3 -0
- package/dist/action-providers/{cdp-v2 → cdp-legacy}/index.js +2 -1
- package/dist/action-providers/cdp-legacy/legacyCdpApiActionProvider.d.ts +45 -0
- package/dist/action-providers/cdp-legacy/legacyCdpApiActionProvider.js +130 -0
- package/dist/action-providers/cdp-legacy/legacyCdpApiActionProvider.test.js +146 -0
- package/dist/action-providers/{cdp/cdpWalletActionProvider.d.ts → cdp-legacy/legacyCdpWalletActionProvider.d.ts} +8 -8
- package/dist/action-providers/{cdp/cdpWalletActionProvider.js → cdp-legacy/legacyCdpWalletActionProvider.js} +14 -14
- package/dist/action-providers/{cdp/cdpWalletActionProvider.test.js → cdp-legacy/legacyCdpWalletActionProvider.test.js} +3 -3
- package/dist/action-providers/cdp-legacy/schemas.d.ts +91 -0
- package/dist/action-providers/cdp-legacy/schemas.js +77 -0
- package/dist/action-providers/erc20/erc20ActionProvider.js +1 -1
- package/dist/action-providers/index.d.ts +1 -1
- package/dist/action-providers/index.js +1 -1
- package/dist/action-providers/jupiter/jupiterActionProvider.test.js +2 -4
- package/dist/action-providers/x402/schemas.d.ts +58 -11
- package/dist/action-providers/x402/schemas.js +60 -8
- package/dist/action-providers/x402/x402ActionProvider.d.ts +33 -16
- package/dist/action-providers/x402/x402ActionProvider.js +203 -153
- package/dist/action-providers/x402/x402ActionProvider.test.js +78 -225
- package/dist/agentkit.d.ts +1 -0
- package/dist/agentkit.js +3 -2
- package/dist/wallet-providers/{cdpV2EvmWalletProvider.d.ts → cdpEvmWalletProvider.d.ts} +16 -7
- package/dist/wallet-providers/{cdpV2EvmWalletProvider.js → cdpEvmWalletProvider.js} +50 -39
- package/dist/wallet-providers/{cdpV2EvmWalletProvider.test.js → cdpEvmWalletProvider.test.js} +7 -7
- package/dist/wallet-providers/{cdpV2Shared.d.ts → cdpShared.d.ts} +15 -4
- package/dist/wallet-providers/cdpSmartWalletProvider.d.ts +115 -0
- package/dist/wallet-providers/cdpSmartWalletProvider.js +263 -0
- package/dist/wallet-providers/cdpSmartWalletProvider.test.js +287 -0
- package/dist/wallet-providers/{cdpV2SolanaWalletProvider.d.ts → cdpSolanaWalletProvider.d.ts} +16 -7
- package/dist/wallet-providers/{cdpV2SolanaWalletProvider.js → cdpSolanaWalletProvider.js} +43 -32
- package/dist/wallet-providers/{cdpV2SolanaWalletProvider.test.js → cdpSolanaWalletProvider.test.js} +7 -7
- package/dist/wallet-providers/index.d.ts +6 -6
- package/dist/wallet-providers/index.js +6 -6
- package/dist/wallet-providers/{smartWalletProvider.d.ts → legacyCdpSmartWalletProvider.d.ts} +3 -3
- package/dist/wallet-providers/{smartWalletProvider.js → legacyCdpSmartWalletProvider.js} +21 -21
- package/dist/wallet-providers/legacyCdpSmartWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/{smartWalletProvider.test.js → legacyCdpSmartWalletProvider.test.js} +2 -2
- package/dist/wallet-providers/{cdpWalletProvider.d.ts → legacyCdpWalletProvider.d.ts} +15 -11
- package/dist/wallet-providers/{cdpWalletProvider.js → legacyCdpWalletProvider.js} +72 -70
- package/dist/wallet-providers/legacyCdpWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/{cdpWalletProvider.test.js → legacyCdpWalletProvider.test.js} +10 -10
- package/package.json +3 -2
- package/dist/action-providers/cdp-v2/cdpApiV2ActionProvider.d.ts +0 -34
- package/dist/action-providers/cdp-v2/cdpApiV2ActionProvider.js +0 -98
- package/dist/action-providers/cdp-v2/index.d.ts +0 -2
- package/dist/action-providers/cdp-v2/schemas.d.ts +0 -11
- package/dist/action-providers/cdp-v2/schemas.js +0 -13
- package/dist/wallet-providers/cdpV2WalletProvider.d.ts +0 -35
- package/dist/wallet-providers/cdpV2WalletProvider.js +0 -42
- /package/dist/action-providers/{cdp → cdp-legacy}/constants.d.ts +0 -0
- /package/dist/action-providers/{cdp → cdp-legacy}/constants.js +0 -0
- /package/dist/action-providers/{cdp/cdpWalletActionProvider.test.d.ts → cdp-legacy/legacyCdpApiActionProvider.test.d.ts} +0 -0
- /package/dist/{wallet-providers/cdpV2EvmWalletProvider.test.d.ts → action-providers/cdp-legacy/legacyCdpWalletActionProvider.test.d.ts} +0 -0
- /package/dist/wallet-providers/{cdpV2SolanaWalletProvider.test.d.ts → cdpEvmWalletProvider.test.d.ts} +0 -0
- /package/dist/wallet-providers/{cdpV2Shared.js → cdpShared.js} +0 -0
- /package/dist/wallet-providers/{cdpWalletProvider.test.d.ts → cdpSmartWalletProvider.test.d.ts} +0 -0
- /package/dist/wallet-providers/{smartWalletProvider.test.d.ts → cdpSolanaWalletProvider.test.d.ts} +0 -0
|
@@ -10,9 +10,9 @@ 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
|
|
13
|
+
var _CdpEvmWalletProvider_instances, _CdpEvmWalletProvider_publicClient, _CdpEvmWalletProvider_serverAccount, _CdpEvmWalletProvider_cdp, _CdpEvmWalletProvider_network, _CdpEvmWalletProvider_getCdpSdkNetwork;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.
|
|
15
|
+
exports.CdpEvmWalletProvider = void 0;
|
|
16
16
|
const cdp_sdk_1 = require("@coinbase/cdp-sdk");
|
|
17
17
|
const viem_1 = require("viem");
|
|
18
18
|
const network_1 = require("../network");
|
|
@@ -20,29 +20,29 @@ const evmWalletProvider_1 = require("./evmWalletProvider");
|
|
|
20
20
|
/**
|
|
21
21
|
* A wallet provider that uses the Coinbase SDK.
|
|
22
22
|
*/
|
|
23
|
-
class
|
|
23
|
+
class CdpEvmWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
24
24
|
/**
|
|
25
|
-
* Constructs a new
|
|
25
|
+
* Constructs a new CdpEvmWalletProvider.
|
|
26
26
|
*
|
|
27
|
-
* @param config - The configuration options for the
|
|
27
|
+
* @param config - The configuration options for the CdpEvmWalletProvider.
|
|
28
28
|
*/
|
|
29
29
|
constructor(config) {
|
|
30
30
|
super();
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
__classPrivateFieldSet(this,
|
|
37
|
-
__classPrivateFieldSet(this,
|
|
38
|
-
__classPrivateFieldSet(this,
|
|
39
|
-
__classPrivateFieldSet(this,
|
|
31
|
+
_CdpEvmWalletProvider_instances.add(this);
|
|
32
|
+
_CdpEvmWalletProvider_publicClient.set(this, void 0);
|
|
33
|
+
_CdpEvmWalletProvider_serverAccount.set(this, void 0);
|
|
34
|
+
_CdpEvmWalletProvider_cdp.set(this, void 0);
|
|
35
|
+
_CdpEvmWalletProvider_network.set(this, void 0);
|
|
36
|
+
__classPrivateFieldSet(this, _CdpEvmWalletProvider_serverAccount, config.serverAccount, "f");
|
|
37
|
+
__classPrivateFieldSet(this, _CdpEvmWalletProvider_cdp, config.cdp, "f");
|
|
38
|
+
__classPrivateFieldSet(this, _CdpEvmWalletProvider_publicClient, config.publicClient, "f");
|
|
39
|
+
__classPrivateFieldSet(this, _CdpEvmWalletProvider_network, config.network, "f");
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
|
-
* Configures a new
|
|
42
|
+
* Configures a new CdpEvmWalletProvider with a wallet.
|
|
43
43
|
*
|
|
44
44
|
* @param config - Optional configuration parameters
|
|
45
|
-
* @returns A Promise that resolves to a new
|
|
45
|
+
* @returns A Promise that resolves to a new CdpEvmWalletProvider instance
|
|
46
46
|
* @throws Error if required environment variables are missing or wallet initialization fails
|
|
47
47
|
*/
|
|
48
48
|
static async configureWithWallet(config = {}) {
|
|
@@ -71,13 +71,24 @@ class CdpV2EvmWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
71
71
|
chain: network_1.NETWORK_ID_TO_VIEM_CHAIN[networkId],
|
|
72
72
|
transport: (0, viem_1.http)(),
|
|
73
73
|
});
|
|
74
|
-
return new
|
|
74
|
+
return new CdpEvmWalletProvider({
|
|
75
75
|
publicClient,
|
|
76
76
|
cdp: cdpClient,
|
|
77
77
|
serverAccount,
|
|
78
78
|
network,
|
|
79
79
|
});
|
|
80
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* Exports the wallet.
|
|
83
|
+
*
|
|
84
|
+
* @returns The wallet's data.
|
|
85
|
+
*/
|
|
86
|
+
async exportWallet() {
|
|
87
|
+
return {
|
|
88
|
+
name: __classPrivateFieldGet(this, _CdpEvmWalletProvider_serverAccount, "f").name,
|
|
89
|
+
address: __classPrivateFieldGet(this, _CdpEvmWalletProvider_serverAccount, "f").address,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
81
92
|
/**
|
|
82
93
|
* Signs a message.
|
|
83
94
|
*
|
|
@@ -85,7 +96,7 @@ class CdpV2EvmWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
85
96
|
* @returns The signed message.
|
|
86
97
|
*/
|
|
87
98
|
async signMessage(message) {
|
|
88
|
-
return __classPrivateFieldGet(this,
|
|
99
|
+
return __classPrivateFieldGet(this, _CdpEvmWalletProvider_serverAccount, "f").signMessage({ message });
|
|
89
100
|
}
|
|
90
101
|
/**
|
|
91
102
|
* Signs a typed data object.
|
|
@@ -95,7 +106,7 @@ class CdpV2EvmWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
95
106
|
*/
|
|
96
107
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
97
108
|
async signTypedData(typedData) {
|
|
98
|
-
return __classPrivateFieldGet(this,
|
|
109
|
+
return __classPrivateFieldGet(this, _CdpEvmWalletProvider_serverAccount, "f").signTypedData(typedData);
|
|
99
110
|
}
|
|
100
111
|
/**
|
|
101
112
|
* Signs a transaction.
|
|
@@ -105,8 +116,8 @@ class CdpV2EvmWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
105
116
|
*/
|
|
106
117
|
async signTransaction(transaction) {
|
|
107
118
|
const serializedTx = (0, viem_1.serializeTransaction)(transaction);
|
|
108
|
-
const signedTx = await __classPrivateFieldGet(this,
|
|
109
|
-
address: __classPrivateFieldGet(this,
|
|
119
|
+
const signedTx = await __classPrivateFieldGet(this, _CdpEvmWalletProvider_cdp, "f").evm.signTransaction({
|
|
120
|
+
address: __classPrivateFieldGet(this, _CdpEvmWalletProvider_serverAccount, "f").address,
|
|
110
121
|
transaction: serializedTx,
|
|
111
122
|
});
|
|
112
123
|
return signedTx.signature;
|
|
@@ -120,17 +131,17 @@ class CdpV2EvmWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
120
131
|
async sendTransaction(transaction) {
|
|
121
132
|
const txWithGasParams = {
|
|
122
133
|
...transaction,
|
|
123
|
-
chainId: __classPrivateFieldGet(this,
|
|
134
|
+
chainId: __classPrivateFieldGet(this, _CdpEvmWalletProvider_network, "f").chainId,
|
|
124
135
|
};
|
|
125
136
|
if (!txWithGasParams.maxFeePerGas && !txWithGasParams.gasPrice) {
|
|
126
|
-
const feeData = await __classPrivateFieldGet(this,
|
|
137
|
+
const feeData = await __classPrivateFieldGet(this, _CdpEvmWalletProvider_publicClient, "f").estimateFeesPerGas();
|
|
127
138
|
txWithGasParams.maxFeePerGas = feeData.maxFeePerGas;
|
|
128
139
|
txWithGasParams.maxPriorityFeePerGas = feeData.maxPriorityFeePerGas;
|
|
129
140
|
}
|
|
130
141
|
if (!txWithGasParams.gas) {
|
|
131
142
|
try {
|
|
132
|
-
txWithGasParams.gas = await __classPrivateFieldGet(this,
|
|
133
|
-
account: __classPrivateFieldGet(this,
|
|
143
|
+
txWithGasParams.gas = await __classPrivateFieldGet(this, _CdpEvmWalletProvider_publicClient, "f").estimateGas({
|
|
144
|
+
account: __classPrivateFieldGet(this, _CdpEvmWalletProvider_serverAccount, "f").address,
|
|
134
145
|
...txWithGasParams,
|
|
135
146
|
});
|
|
136
147
|
}
|
|
@@ -138,10 +149,10 @@ class CdpV2EvmWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
138
149
|
console.warn("Failed to estimate gas, continuing without gas estimation", error);
|
|
139
150
|
}
|
|
140
151
|
}
|
|
141
|
-
const result = await __classPrivateFieldGet(this,
|
|
142
|
-
address: __classPrivateFieldGet(this,
|
|
152
|
+
const result = await __classPrivateFieldGet(this, _CdpEvmWalletProvider_cdp, "f").evm.sendTransaction({
|
|
153
|
+
address: __classPrivateFieldGet(this, _CdpEvmWalletProvider_serverAccount, "f").address,
|
|
143
154
|
transaction: (0, viem_1.serializeTransaction)(txWithGasParams),
|
|
144
|
-
network: __classPrivateFieldGet(this,
|
|
155
|
+
network: __classPrivateFieldGet(this, _CdpEvmWalletProvider_instances, "m", _CdpEvmWalletProvider_getCdpSdkNetwork).call(this),
|
|
145
156
|
});
|
|
146
157
|
return result.transactionHash;
|
|
147
158
|
}
|
|
@@ -151,7 +162,7 @@ class CdpV2EvmWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
151
162
|
* @returns The address of the wallet.
|
|
152
163
|
*/
|
|
153
164
|
getAddress() {
|
|
154
|
-
return __classPrivateFieldGet(this,
|
|
165
|
+
return __classPrivateFieldGet(this, _CdpEvmWalletProvider_serverAccount, "f").address;
|
|
155
166
|
}
|
|
156
167
|
/**
|
|
157
168
|
* Gets the network of the wallet.
|
|
@@ -159,7 +170,7 @@ class CdpV2EvmWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
159
170
|
* @returns The network of the wallet.
|
|
160
171
|
*/
|
|
161
172
|
getNetwork() {
|
|
162
|
-
return __classPrivateFieldGet(this,
|
|
173
|
+
return __classPrivateFieldGet(this, _CdpEvmWalletProvider_network, "f");
|
|
163
174
|
}
|
|
164
175
|
/**
|
|
165
176
|
* Gets the name of the wallet provider.
|
|
@@ -167,7 +178,7 @@ class CdpV2EvmWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
167
178
|
* @returns The name of the wallet provider.
|
|
168
179
|
*/
|
|
169
180
|
getName() {
|
|
170
|
-
return "
|
|
181
|
+
return "cdp_evm_wallet_provider";
|
|
171
182
|
}
|
|
172
183
|
/**
|
|
173
184
|
* Gets the CDP client.
|
|
@@ -175,7 +186,7 @@ class CdpV2EvmWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
175
186
|
* @returns The CDP client.
|
|
176
187
|
*/
|
|
177
188
|
getClient() {
|
|
178
|
-
return __classPrivateFieldGet(this,
|
|
189
|
+
return __classPrivateFieldGet(this, _CdpEvmWalletProvider_cdp, "f");
|
|
179
190
|
}
|
|
180
191
|
/**
|
|
181
192
|
* Gets the balance of the wallet.
|
|
@@ -183,7 +194,7 @@ class CdpV2EvmWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
183
194
|
* @returns The balance of the wallet in wei
|
|
184
195
|
*/
|
|
185
196
|
async getBalance() {
|
|
186
|
-
return await __classPrivateFieldGet(this,
|
|
197
|
+
return await __classPrivateFieldGet(this, _CdpEvmWalletProvider_publicClient, "f").getBalance({ address: __classPrivateFieldGet(this, _CdpEvmWalletProvider_serverAccount, "f").address });
|
|
187
198
|
}
|
|
188
199
|
/**
|
|
189
200
|
* Waits for a transaction receipt.
|
|
@@ -193,7 +204,7 @@ class CdpV2EvmWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
193
204
|
*/
|
|
194
205
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
195
206
|
async waitForTransactionReceipt(txHash) {
|
|
196
|
-
return await __classPrivateFieldGet(this,
|
|
207
|
+
return await __classPrivateFieldGet(this, _CdpEvmWalletProvider_publicClient, "f").waitForTransactionReceipt({ hash: txHash });
|
|
197
208
|
}
|
|
198
209
|
/**
|
|
199
210
|
* Reads a contract.
|
|
@@ -202,7 +213,7 @@ class CdpV2EvmWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
202
213
|
* @returns The response from the contract.
|
|
203
214
|
*/
|
|
204
215
|
async readContract(params) {
|
|
205
|
-
return __classPrivateFieldGet(this,
|
|
216
|
+
return __classPrivateFieldGet(this, _CdpEvmWalletProvider_publicClient, "f").readContract(params);
|
|
206
217
|
}
|
|
207
218
|
/**
|
|
208
219
|
* Transfer the native asset of the network.
|
|
@@ -219,14 +230,14 @@ class CdpV2EvmWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
219
230
|
});
|
|
220
231
|
}
|
|
221
232
|
}
|
|
222
|
-
exports.
|
|
223
|
-
|
|
224
|
-
switch (__classPrivateFieldGet(this,
|
|
233
|
+
exports.CdpEvmWalletProvider = CdpEvmWalletProvider;
|
|
234
|
+
_CdpEvmWalletProvider_publicClient = new WeakMap(), _CdpEvmWalletProvider_serverAccount = new WeakMap(), _CdpEvmWalletProvider_cdp = new WeakMap(), _CdpEvmWalletProvider_network = new WeakMap(), _CdpEvmWalletProvider_instances = new WeakSet(), _CdpEvmWalletProvider_getCdpSdkNetwork = function _CdpEvmWalletProvider_getCdpSdkNetwork() {
|
|
235
|
+
switch (__classPrivateFieldGet(this, _CdpEvmWalletProvider_network, "f").networkId) {
|
|
225
236
|
case "base-sepolia":
|
|
226
237
|
return "base-sepolia";
|
|
227
238
|
case "base-mainnet":
|
|
228
239
|
return "base";
|
|
229
240
|
default:
|
|
230
|
-
throw new Error(`Unsupported network: ${__classPrivateFieldGet(this,
|
|
241
|
+
throw new Error(`Unsupported network: ${__classPrivateFieldGet(this, _CdpEvmWalletProvider_network, "f").networkId}`);
|
|
231
242
|
}
|
|
232
243
|
};
|
package/dist/wallet-providers/{cdpV2EvmWalletProvider.test.js → cdpEvmWalletProvider.test.js}
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const cdp_sdk_1 = require("@coinbase/cdp-sdk");
|
|
4
|
-
const
|
|
4
|
+
const cdpEvmWalletProvider_1 = require("./cdpEvmWalletProvider");
|
|
5
5
|
// =========================================================
|
|
6
6
|
// consts
|
|
7
7
|
// =========================================================
|
|
@@ -95,7 +95,7 @@ const MOCK_NETWORK = {
|
|
|
95
95
|
const MOCK_TRANSACTION_RECEIPT = {
|
|
96
96
|
transactionHash: MOCK_TRANSACTION_HASH,
|
|
97
97
|
};
|
|
98
|
-
describe("
|
|
98
|
+
describe("CdpEvmWalletProvider", () => {
|
|
99
99
|
let provider;
|
|
100
100
|
let mockCdpClient;
|
|
101
101
|
let mockServerAccount;
|
|
@@ -131,7 +131,7 @@ describe("CdpV2EvmWalletProvider", () => {
|
|
|
131
131
|
mockPublicClient.estimateGas.mockResolvedValue(BigInt(21000));
|
|
132
132
|
mockPublicClient.getBalance.mockResolvedValue(MOCK_BALANCE);
|
|
133
133
|
mockWalletClient.sendTransaction.mockResolvedValue(MOCK_TRANSACTION_HASH);
|
|
134
|
-
provider = await
|
|
134
|
+
provider = await cdpEvmWalletProvider_1.CdpEvmWalletProvider.configureWithWallet({
|
|
135
135
|
apiKeyId: "test-key-id",
|
|
136
136
|
apiKeySecret: "test-key-secret",
|
|
137
137
|
walletSecret: "test-wallet-secret",
|
|
@@ -143,7 +143,7 @@ describe("CdpV2EvmWalletProvider", () => {
|
|
|
143
143
|
// =========================================================
|
|
144
144
|
describe("initialization", () => {
|
|
145
145
|
it("should initialize with API keys", async () => {
|
|
146
|
-
const provider = await
|
|
146
|
+
const provider = await cdpEvmWalletProvider_1.CdpEvmWalletProvider.configureWithWallet({
|
|
147
147
|
apiKeyId: "test-key-id",
|
|
148
148
|
apiKeySecret: "test-key-secret",
|
|
149
149
|
walletSecret: "test-wallet-secret",
|
|
@@ -153,7 +153,7 @@ describe("CdpV2EvmWalletProvider", () => {
|
|
|
153
153
|
expect(provider.getNetwork()).toEqual(MOCK_NETWORK);
|
|
154
154
|
});
|
|
155
155
|
it("should default to base-sepolia if network not provided", async () => {
|
|
156
|
-
const provider = await
|
|
156
|
+
const provider = await cdpEvmWalletProvider_1.CdpEvmWalletProvider.configureWithWallet({
|
|
157
157
|
apiKeyId: "test-key-id",
|
|
158
158
|
apiKeySecret: "test-key-secret",
|
|
159
159
|
walletSecret: "test-wallet-secret",
|
|
@@ -177,7 +177,7 @@ describe("CdpV2EvmWalletProvider", () => {
|
|
|
177
177
|
mockCdpClient.evm = mockEvmClient;
|
|
178
178
|
// Override the CdpClient constructor mock
|
|
179
179
|
cdp_sdk_1.CdpClient.mockImplementation(() => mockCdpClient);
|
|
180
|
-
await expect(
|
|
180
|
+
await expect(cdpEvmWalletProvider_1.CdpEvmWalletProvider.configureWithWallet({
|
|
181
181
|
apiKeyId: "test-key-id",
|
|
182
182
|
apiKeySecret: "test-key-secret",
|
|
183
183
|
walletSecret: "test-wallet-secret",
|
|
@@ -196,7 +196,7 @@ describe("CdpV2EvmWalletProvider", () => {
|
|
|
196
196
|
expect(provider.getNetwork()).toEqual(MOCK_NETWORK);
|
|
197
197
|
});
|
|
198
198
|
it("should get the name", () => {
|
|
199
|
-
expect(provider.getName()).toBe("
|
|
199
|
+
expect(provider.getName()).toBe("cdp_evm_wallet_provider");
|
|
200
200
|
});
|
|
201
201
|
it("should get the balance", async () => {
|
|
202
202
|
const balance = await provider.getBalance();
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { CdpClient } from "@coinbase/cdp-sdk";
|
|
2
|
-
|
|
1
|
+
import { CdpClient, type EvmServerAccount } from "@coinbase/cdp-sdk";
|
|
2
|
+
import type { Address, LocalAccount } from "viem";
|
|
3
|
+
export interface CdpProviderConfig {
|
|
3
4
|
/**
|
|
4
5
|
* The CDP API Key ID.
|
|
5
6
|
*/
|
|
@@ -16,11 +17,11 @@ export interface CdpV2ProviderConfig {
|
|
|
16
17
|
/**
|
|
17
18
|
* Configuration options for the CDP Providers.
|
|
18
19
|
*/
|
|
19
|
-
export interface
|
|
20
|
+
export interface CdpWalletProviderConfig extends CdpProviderConfig {
|
|
20
21
|
/**
|
|
21
22
|
* The address of the wallet.
|
|
22
23
|
*/
|
|
23
|
-
address?:
|
|
24
|
+
address?: Address;
|
|
24
25
|
/**
|
|
25
26
|
* The network of the wallet.
|
|
26
27
|
*/
|
|
@@ -30,6 +31,16 @@ export interface CdpV2WalletProviderConfig extends CdpV2ProviderConfig {
|
|
|
30
31
|
*/
|
|
31
32
|
idempotencyKey?: string;
|
|
32
33
|
}
|
|
34
|
+
export interface CdpSmartWalletProviderConfig extends CdpWalletProviderConfig {
|
|
35
|
+
/**
|
|
36
|
+
* The owner account of the smart wallet.
|
|
37
|
+
*/
|
|
38
|
+
owner?: EvmServerAccount | LocalAccount | Address;
|
|
39
|
+
/**
|
|
40
|
+
* The name of the smart wallet.
|
|
41
|
+
*/
|
|
42
|
+
smartAccountName?: string;
|
|
43
|
+
}
|
|
33
44
|
/**
|
|
34
45
|
* A wallet provider that can be used to interact with the CDP.
|
|
35
46
|
*/
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { CdpClient } from "@coinbase/cdp-sdk";
|
|
2
|
+
import { Abi, Address, ContractFunctionArgs, ContractFunctionName, Hex, ReadContractParameters, ReadContractReturnType, TransactionRequest } from "viem";
|
|
3
|
+
import { Network } from "../network";
|
|
4
|
+
import { EvmWalletProvider } from "./evmWalletProvider";
|
|
5
|
+
import { WalletProviderWithClient, CdpSmartWalletProviderConfig } from "./cdpShared";
|
|
6
|
+
/**
|
|
7
|
+
* A wallet provider that uses the Coinbase CDP SDK smart wallets.
|
|
8
|
+
*/
|
|
9
|
+
export declare class CdpSmartWalletProvider extends EvmWalletProvider implements WalletProviderWithClient {
|
|
10
|
+
#private;
|
|
11
|
+
/**
|
|
12
|
+
* Constructs a new CdpSmartWalletProvider.
|
|
13
|
+
*
|
|
14
|
+
* @param config - The configuration options for the CdpSmartWalletProvider.
|
|
15
|
+
*/
|
|
16
|
+
private constructor();
|
|
17
|
+
/**
|
|
18
|
+
* Configures a new CdpSmartWalletProvider with a smart wallet.
|
|
19
|
+
*
|
|
20
|
+
* @param config - Optional configuration parameters
|
|
21
|
+
* @returns A Promise that resolves to a new CdpSmartWalletProvider instance
|
|
22
|
+
* @throws Error if required environment variables are missing or wallet initialization fails
|
|
23
|
+
*/
|
|
24
|
+
static configureWithWallet(config?: CdpSmartWalletProviderConfig): Promise<CdpSmartWalletProvider>;
|
|
25
|
+
/**
|
|
26
|
+
* Exports the wallet.
|
|
27
|
+
*
|
|
28
|
+
* @returns The wallet's data.
|
|
29
|
+
*/
|
|
30
|
+
exportWallet(): Promise<{
|
|
31
|
+
name: string | undefined;
|
|
32
|
+
address: Address;
|
|
33
|
+
ownerAddress: Address;
|
|
34
|
+
}>;
|
|
35
|
+
/**
|
|
36
|
+
* Signs a message using the owner account.
|
|
37
|
+
*
|
|
38
|
+
* @param _message - The message to sign.
|
|
39
|
+
* @returns The signed message.
|
|
40
|
+
*/
|
|
41
|
+
signMessage(_message: string): Promise<Hex>;
|
|
42
|
+
/**
|
|
43
|
+
* Signs a typed data object using the owner account.
|
|
44
|
+
*
|
|
45
|
+
* @param typedData - The typed data object to sign.
|
|
46
|
+
* @returns The signed typed data object.
|
|
47
|
+
*/
|
|
48
|
+
signTypedData(typedData: any): Promise<Hex>;
|
|
49
|
+
/**
|
|
50
|
+
* Signs a transaction using the owner account.
|
|
51
|
+
*
|
|
52
|
+
* @param _ - The transaction to sign.
|
|
53
|
+
* @returns The signed transaction.
|
|
54
|
+
*/
|
|
55
|
+
signTransaction(_: TransactionRequest): Promise<Hex>;
|
|
56
|
+
/**
|
|
57
|
+
* Sends a user operation through the smart wallet.
|
|
58
|
+
*
|
|
59
|
+
* @param transaction - The transaction to send.
|
|
60
|
+
* @returns The user operation hash.
|
|
61
|
+
*/
|
|
62
|
+
sendTransaction(transaction: TransactionRequest): Promise<Hex>;
|
|
63
|
+
/**
|
|
64
|
+
* Gets the address of the smart wallet.
|
|
65
|
+
*
|
|
66
|
+
* @returns The address of the smart wallet.
|
|
67
|
+
*/
|
|
68
|
+
getAddress(): string;
|
|
69
|
+
/**
|
|
70
|
+
* Gets the network of the wallet.
|
|
71
|
+
*
|
|
72
|
+
* @returns The network of the wallet.
|
|
73
|
+
*/
|
|
74
|
+
getNetwork(): Network;
|
|
75
|
+
/**
|
|
76
|
+
* Gets the name of the wallet provider.
|
|
77
|
+
*
|
|
78
|
+
* @returns The name of the wallet provider.
|
|
79
|
+
*/
|
|
80
|
+
getName(): string;
|
|
81
|
+
/**
|
|
82
|
+
* Gets the CDP client.
|
|
83
|
+
*
|
|
84
|
+
* @returns The CDP client.
|
|
85
|
+
*/
|
|
86
|
+
getClient(): CdpClient;
|
|
87
|
+
/**
|
|
88
|
+
* Gets the balance of the smart wallet.
|
|
89
|
+
*
|
|
90
|
+
* @returns The balance of the wallet in wei
|
|
91
|
+
*/
|
|
92
|
+
getBalance(): Promise<bigint>;
|
|
93
|
+
/**
|
|
94
|
+
* Waits for a user operation receipt.
|
|
95
|
+
*
|
|
96
|
+
* @param userOpHash - The user operation hash to wait for.
|
|
97
|
+
* @returns The user operation receipt.
|
|
98
|
+
*/
|
|
99
|
+
waitForTransactionReceipt(userOpHash: Hex): Promise<any>;
|
|
100
|
+
/**
|
|
101
|
+
* Reads a contract.
|
|
102
|
+
*
|
|
103
|
+
* @param params - The parameters to read the contract.
|
|
104
|
+
* @returns The response from the contract.
|
|
105
|
+
*/
|
|
106
|
+
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>>;
|
|
107
|
+
/**
|
|
108
|
+
* Transfer the native asset of the network using smart wallet.
|
|
109
|
+
*
|
|
110
|
+
* @param to - The destination address.
|
|
111
|
+
* @param value - The amount to transfer in Wei.
|
|
112
|
+
* @returns The user operation hash.
|
|
113
|
+
*/
|
|
114
|
+
nativeTransfer(to: Address, value: string): Promise<Hex>;
|
|
115
|
+
}
|