@coinbase/agentkit 0.2.3-nightly.20250226.17 → 0.2.3-nightly.20250227.19
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 +48 -0
- package/dist/action-providers/compound/compoundActionProvider.d.ts +67 -0
- package/dist/action-providers/compound/compoundActionProvider.js +365 -0
- package/dist/action-providers/compound/compoundActionProvider.test.d.ts +1 -0
- package/dist/action-providers/compound/compoundActionProvider.test.js +353 -0
- package/dist/action-providers/compound/constants.d.ts +180 -0
- package/dist/action-providers/compound/constants.js +129 -0
- package/dist/action-providers/compound/index.d.ts +1 -0
- package/dist/action-providers/compound/index.js +17 -0
- package/dist/action-providers/compound/schemas.d.ts +57 -0
- package/dist/action-providers/compound/schemas.js +58 -0
- package/dist/action-providers/compound/utils.d.ts +95 -0
- package/dist/action-providers/compound/utils.js +353 -0
- package/dist/action-providers/index.d.ts +1 -0
- package/dist/action-providers/index.js +1 -0
- package/dist/wallet-providers/index.d.ts +1 -0
- package/dist/wallet-providers/index.js +1 -0
- package/dist/wallet-providers/smartWalletProvider.d.ts +177 -0
- package/dist/wallet-providers/smartWalletProvider.js +303 -0
- package/package.json +2 -2
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { SendUserOperationOptions, Signer } from "@coinbase/coinbase-sdk";
|
|
2
|
+
import { Abi, Address, ContractFunctionArgs, ContractFunctionName, Hex, ReadContractParameters, ReadContractReturnType, TransactionRequest } from "viem";
|
|
3
|
+
import { Network } from "../network";
|
|
4
|
+
import { EvmWalletProvider } from "./evmWalletProvider";
|
|
5
|
+
export interface ConfigureSmartWalletOptions {
|
|
6
|
+
cdpApiKeyName?: string;
|
|
7
|
+
cdpApiKeyPrivateKey?: string;
|
|
8
|
+
networkId?: string;
|
|
9
|
+
smartWalletAddress?: Hex;
|
|
10
|
+
paymasterUrl?: string;
|
|
11
|
+
signer: Signer;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* A wallet provider that uses Smart Wallets from the Coinbase SDK.
|
|
15
|
+
*/
|
|
16
|
+
export declare class SmartWalletProvider extends EvmWalletProvider {
|
|
17
|
+
#private;
|
|
18
|
+
/**
|
|
19
|
+
* Constructs a new CdpWalletProvider.
|
|
20
|
+
*
|
|
21
|
+
* @param config - The configuration options for the CdpWalletProvider.
|
|
22
|
+
*/
|
|
23
|
+
private constructor();
|
|
24
|
+
/**
|
|
25
|
+
* Configures and returns a `SmartWalletProvider` instance using the provided configuration options.
|
|
26
|
+
* This method initializes a smart wallet based on the given network and credentials.
|
|
27
|
+
*
|
|
28
|
+
* @param {ConfigureSmartWalletOptions} config
|
|
29
|
+
* - Configuration parameters for setting up the smart wallet.
|
|
30
|
+
*
|
|
31
|
+
* @returns {Promise<SmartWalletProvider>}
|
|
32
|
+
* - A promise that resolves to an instance of `SmartWalletProvider` configured with the provided settings.
|
|
33
|
+
*
|
|
34
|
+
* @throws {Error}
|
|
35
|
+
* - If networkId is not a supported network.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* const smartWalletProvider = await SmartWalletProvider.configureWithWallet({
|
|
40
|
+
* networkId: "base-sepolia",
|
|
41
|
+
* signer: privateKeyToAccount("0xethprivatekey"),
|
|
42
|
+
* cdpApiKeyName: "my-api-key",
|
|
43
|
+
* cdpApiKeyPrivateKey: "my-private-key",
|
|
44
|
+
* smartWalletAddress: "0x123456...",
|
|
45
|
+
* });
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
static configureWithWallet(config: ConfigureSmartWalletOptions): Promise<SmartWalletProvider>;
|
|
49
|
+
/**
|
|
50
|
+
* Stub for message signing
|
|
51
|
+
*
|
|
52
|
+
* @throws as signing messages is not implemented for SmartWallets.
|
|
53
|
+
*
|
|
54
|
+
* @param _ - The message to sign.
|
|
55
|
+
* @returns The signed message.
|
|
56
|
+
*/
|
|
57
|
+
signMessage(_: string): Promise<Hex>;
|
|
58
|
+
/**
|
|
59
|
+
* Stub for typed data signing
|
|
60
|
+
*
|
|
61
|
+
* @throws as signing typed data is not implemented for SmartWallets.
|
|
62
|
+
*
|
|
63
|
+
* @param _ - The typed data object to sign.
|
|
64
|
+
* @returns The signed typed data object.
|
|
65
|
+
*/
|
|
66
|
+
signTypedData(_: any): Promise<Hex>;
|
|
67
|
+
/**
|
|
68
|
+
* Stub for transaction signing
|
|
69
|
+
*
|
|
70
|
+
* @throws as signing transactions is not implemented for SmartWallets.
|
|
71
|
+
*
|
|
72
|
+
* @param _ - The transaction to sign.
|
|
73
|
+
* @returns The signed transaction.
|
|
74
|
+
*/
|
|
75
|
+
signTransaction(_: TransactionRequest): Promise<Hex>;
|
|
76
|
+
/**
|
|
77
|
+
* Sends a transaction using the smart wallet.
|
|
78
|
+
*
|
|
79
|
+
* Unlike traditional Ethereum transactions, this method submits a **User Operation**
|
|
80
|
+
* instead of directly broadcasting a transaction. The smart wallet handles execution,
|
|
81
|
+
* but a standard transaction hash is still returned upon completion.
|
|
82
|
+
*
|
|
83
|
+
* @param {TransactionRequest} transaction - The transaction details, including:
|
|
84
|
+
* - `to`: The recipient address.
|
|
85
|
+
* - `value`: The amount of ETH (or native token) to send.
|
|
86
|
+
* - `data`: Optional calldata for contract interactions.
|
|
87
|
+
*
|
|
88
|
+
* @returns A promise resolving to the transaction hash (`0x...`).
|
|
89
|
+
*
|
|
90
|
+
* @throws {Error} If the transaction does not complete successfully.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* const txHash = await smartWallet.sendTransaction({
|
|
95
|
+
* to: "0x123...",
|
|
96
|
+
* value: parseEther("0.1"),
|
|
97
|
+
* data: "0x",
|
|
98
|
+
* });
|
|
99
|
+
* console.log(`Transaction sent: ${txHash}`);
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
sendTransaction(transaction: TransactionRequest): Promise<Hex>;
|
|
103
|
+
/**
|
|
104
|
+
* Sends a **User Operation** to the smart wallet.
|
|
105
|
+
*
|
|
106
|
+
* This method directly exposes the **sendUserOperation** functionality, allowing
|
|
107
|
+
* **SmartWallet-aware tools** to fully leverage its capabilities, including batching multiple calls.
|
|
108
|
+
* Unlike `sendTransaction`, which wraps calls in a single operation, this method allows
|
|
109
|
+
* direct execution of arbitrary operations within a **User Operation**.
|
|
110
|
+
*
|
|
111
|
+
* @param {Omit<SendUserOperationOptions<T>, "chainId" | "paymasterUrl">} operation
|
|
112
|
+
* - The user operation configuration, omitting `chainId` and `paymasterUrl`,
|
|
113
|
+
* which are managed internally by the smart wallet.
|
|
114
|
+
*
|
|
115
|
+
* @returns A promise resolving to the transaction hash (`0x...`) if the operation completes successfully.
|
|
116
|
+
*
|
|
117
|
+
* @throws {Error} If the operation does not complete successfully.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```typescript
|
|
121
|
+
* const txHash = await smartWallet.sendUserOperation({
|
|
122
|
+
* calls: [
|
|
123
|
+
* { to: "0x123...", value: parseEther("0.1"), data: "0x" },
|
|
124
|
+
* { to: "0x456...", value: parseEther("0.05"), data: "0x" }
|
|
125
|
+
* ],
|
|
126
|
+
* });
|
|
127
|
+
* console.log(`User Operation sent: ${txHash}`);
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
sendUserOperation<T extends readonly unknown[]>(operation: Omit<SendUserOperationOptions<T>, "chainId" | "paymasterUrl">): Promise<Hex>;
|
|
131
|
+
/**
|
|
132
|
+
* Gets the address of the smart wallet.
|
|
133
|
+
*
|
|
134
|
+
* @returns The address of the smart wallet.
|
|
135
|
+
*/
|
|
136
|
+
getAddress(): string;
|
|
137
|
+
/**
|
|
138
|
+
* Gets the network of the wallet.
|
|
139
|
+
*
|
|
140
|
+
* @returns The network of the wallet.
|
|
141
|
+
*/
|
|
142
|
+
getNetwork(): Network;
|
|
143
|
+
/**
|
|
144
|
+
* Gets the name of the wallet provider.
|
|
145
|
+
*
|
|
146
|
+
* @returns The name of the wallet provider.
|
|
147
|
+
*/
|
|
148
|
+
getName(): string;
|
|
149
|
+
/**
|
|
150
|
+
* Gets the balance of the wallet.
|
|
151
|
+
*
|
|
152
|
+
* @returns The balance of the wallet in wei
|
|
153
|
+
*/
|
|
154
|
+
getBalance(): Promise<bigint>;
|
|
155
|
+
/**
|
|
156
|
+
* Waits for a transaction receipt.
|
|
157
|
+
*
|
|
158
|
+
* @param txHash - The hash of the transaction to wait for.
|
|
159
|
+
* @returns The transaction receipt.
|
|
160
|
+
*/
|
|
161
|
+
waitForTransactionReceipt(txHash: Hex): Promise<any>;
|
|
162
|
+
/**
|
|
163
|
+
* Reads a contract.
|
|
164
|
+
*
|
|
165
|
+
* @param params - The parameters to read the contract.
|
|
166
|
+
* @returns The response from the contract.
|
|
167
|
+
*/
|
|
168
|
+
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>>;
|
|
169
|
+
/**
|
|
170
|
+
* Transfer the native asset of the network.
|
|
171
|
+
*
|
|
172
|
+
* @param to - The destination address.
|
|
173
|
+
* @param value - The amount to transfer in Wei.
|
|
174
|
+
* @returns The transaction hash.
|
|
175
|
+
*/
|
|
176
|
+
nativeTransfer(to: Address, value: string): Promise<Hex>;
|
|
177
|
+
}
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
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
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _SmartWalletProvider_smartWallet, _SmartWalletProvider_network, _SmartWalletProvider_publicClient;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.SmartWalletProvider = void 0;
|
|
16
|
+
const coinbase_sdk_1 = require("@coinbase/coinbase-sdk");
|
|
17
|
+
const viem_1 = require("viem");
|
|
18
|
+
const network_1 = require("../network");
|
|
19
|
+
const evmWalletProvider_1 = require("./evmWalletProvider");
|
|
20
|
+
const package_json_1 = require("../../package.json");
|
|
21
|
+
/**
|
|
22
|
+
* A wallet provider that uses Smart Wallets from the Coinbase SDK.
|
|
23
|
+
*/
|
|
24
|
+
class SmartWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
25
|
+
/**
|
|
26
|
+
* Constructs a new CdpWalletProvider.
|
|
27
|
+
*
|
|
28
|
+
* @param config - The configuration options for the CdpWalletProvider.
|
|
29
|
+
*/
|
|
30
|
+
constructor(config) {
|
|
31
|
+
super();
|
|
32
|
+
_SmartWalletProvider_smartWallet.set(this, void 0);
|
|
33
|
+
_SmartWalletProvider_network.set(this, void 0);
|
|
34
|
+
_SmartWalletProvider_publicClient.set(this, void 0);
|
|
35
|
+
__classPrivateFieldSet(this, _SmartWalletProvider_network, config.network, "f");
|
|
36
|
+
__classPrivateFieldSet(this, _SmartWalletProvider_smartWallet, config.smartWallet, "f");
|
|
37
|
+
__classPrivateFieldSet(this, _SmartWalletProvider_publicClient, (0, viem_1.createPublicClient)({
|
|
38
|
+
chain: network_1.NETWORK_ID_TO_VIEM_CHAIN[config.network.networkId],
|
|
39
|
+
transport: (0, viem_1.http)(),
|
|
40
|
+
}), "f");
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Configures and returns a `SmartWalletProvider` instance using the provided configuration options.
|
|
44
|
+
* This method initializes a smart wallet based on the given network and credentials.
|
|
45
|
+
*
|
|
46
|
+
* @param {ConfigureSmartWalletOptions} config
|
|
47
|
+
* - Configuration parameters for setting up the smart wallet.
|
|
48
|
+
*
|
|
49
|
+
* @returns {Promise<SmartWalletProvider>}
|
|
50
|
+
* - A promise that resolves to an instance of `SmartWalletProvider` configured with the provided settings.
|
|
51
|
+
*
|
|
52
|
+
* @throws {Error}
|
|
53
|
+
* - If networkId is not a supported network.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* const smartWalletProvider = await SmartWalletProvider.configureWithWallet({
|
|
58
|
+
* networkId: "base-sepolia",
|
|
59
|
+
* signer: privateKeyToAccount("0xethprivatekey"),
|
|
60
|
+
* cdpApiKeyName: "my-api-key",
|
|
61
|
+
* cdpApiKeyPrivateKey: "my-private-key",
|
|
62
|
+
* smartWalletAddress: "0x123456...",
|
|
63
|
+
* });
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
static async configureWithWallet(config) {
|
|
67
|
+
const networkId = config.networkId || process.env.NETWORK_ID || coinbase_sdk_1.Coinbase.networks.BaseSepolia;
|
|
68
|
+
const network = {
|
|
69
|
+
protocolFamily: "evm",
|
|
70
|
+
chainId: network_1.NETWORK_ID_TO_CHAIN_ID[networkId],
|
|
71
|
+
networkId,
|
|
72
|
+
};
|
|
73
|
+
if (!network.chainId) {
|
|
74
|
+
throw new Error(`Unable to determine chainId for network ${networkId}`);
|
|
75
|
+
}
|
|
76
|
+
const supportedChainIds = Object.keys(coinbase_sdk_1.CHAIN_ID_TO_NETWORK_ID);
|
|
77
|
+
if (!supportedChainIds.includes(network.chainId)) {
|
|
78
|
+
throw new Error(`Invalid chain id ${network.chainId}. Chain id must be one of ${supportedChainIds.join(", ")}`);
|
|
79
|
+
}
|
|
80
|
+
const cdpApiKeyName = config.cdpApiKeyName || process.env.CDP_API_KEY_NAME;
|
|
81
|
+
const cdpApiKeyPrivateKey = config.cdpApiKeyPrivateKey || process.env.CDP_API_KEY_PRIVATE_KEY;
|
|
82
|
+
if (cdpApiKeyName && cdpApiKeyPrivateKey) {
|
|
83
|
+
coinbase_sdk_1.Coinbase.configure({
|
|
84
|
+
apiKeyName: cdpApiKeyName,
|
|
85
|
+
privateKey: cdpApiKeyPrivateKey?.replace(/\\n/g, "\n"),
|
|
86
|
+
source: "agentkit",
|
|
87
|
+
sourceVersion: package_json_1.version,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
coinbase_sdk_1.Coinbase.configureFromJson();
|
|
92
|
+
}
|
|
93
|
+
const smartWallet = config.smartWalletAddress
|
|
94
|
+
? (0, coinbase_sdk_1.toSmartWallet)({
|
|
95
|
+
signer: config.signer,
|
|
96
|
+
smartWalletAddress: config.smartWalletAddress,
|
|
97
|
+
})
|
|
98
|
+
: await (0, coinbase_sdk_1.createSmartWallet)({
|
|
99
|
+
signer: config.signer,
|
|
100
|
+
});
|
|
101
|
+
const networkScopedSmartWallet = smartWallet.useNetwork({
|
|
102
|
+
chainId: Number(network.chainId),
|
|
103
|
+
paymasterUrl: config.paymasterUrl,
|
|
104
|
+
});
|
|
105
|
+
const smartWalletProvider = new SmartWalletProvider({
|
|
106
|
+
smartWallet: networkScopedSmartWallet,
|
|
107
|
+
network,
|
|
108
|
+
chainId: network.chainId,
|
|
109
|
+
});
|
|
110
|
+
return smartWalletProvider;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Stub for message signing
|
|
114
|
+
*
|
|
115
|
+
* @throws as signing messages is not implemented for SmartWallets.
|
|
116
|
+
*
|
|
117
|
+
* @param _ - The message to sign.
|
|
118
|
+
* @returns The signed message.
|
|
119
|
+
*/
|
|
120
|
+
async signMessage(_) {
|
|
121
|
+
throw new Error("Not implemented");
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Stub for typed data signing
|
|
125
|
+
*
|
|
126
|
+
* @throws as signing typed data is not implemented for SmartWallets.
|
|
127
|
+
*
|
|
128
|
+
* @param _ - The typed data object to sign.
|
|
129
|
+
* @returns The signed typed data object.
|
|
130
|
+
*/
|
|
131
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
132
|
+
async signTypedData(_) {
|
|
133
|
+
throw new Error("Not implemented");
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Stub for transaction signing
|
|
137
|
+
*
|
|
138
|
+
* @throws as signing transactions is not implemented for SmartWallets.
|
|
139
|
+
*
|
|
140
|
+
* @param _ - The transaction to sign.
|
|
141
|
+
* @returns The signed transaction.
|
|
142
|
+
*/
|
|
143
|
+
async signTransaction(_) {
|
|
144
|
+
throw new Error("Not implemented");
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Sends a transaction using the smart wallet.
|
|
148
|
+
*
|
|
149
|
+
* Unlike traditional Ethereum transactions, this method submits a **User Operation**
|
|
150
|
+
* instead of directly broadcasting a transaction. The smart wallet handles execution,
|
|
151
|
+
* but a standard transaction hash is still returned upon completion.
|
|
152
|
+
*
|
|
153
|
+
* @param {TransactionRequest} transaction - The transaction details, including:
|
|
154
|
+
* - `to`: The recipient address.
|
|
155
|
+
* - `value`: The amount of ETH (or native token) to send.
|
|
156
|
+
* - `data`: Optional calldata for contract interactions.
|
|
157
|
+
*
|
|
158
|
+
* @returns A promise resolving to the transaction hash (`0x...`).
|
|
159
|
+
*
|
|
160
|
+
* @throws {Error} If the transaction does not complete successfully.
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```typescript
|
|
164
|
+
* const txHash = await smartWallet.sendTransaction({
|
|
165
|
+
* to: "0x123...",
|
|
166
|
+
* value: parseEther("0.1"),
|
|
167
|
+
* data: "0x",
|
|
168
|
+
* });
|
|
169
|
+
* console.log(`Transaction sent: ${txHash}`);
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
sendTransaction(transaction) {
|
|
173
|
+
const { to, value, data } = transaction;
|
|
174
|
+
return this.sendUserOperation({
|
|
175
|
+
calls: [
|
|
176
|
+
{
|
|
177
|
+
to: to,
|
|
178
|
+
value,
|
|
179
|
+
data,
|
|
180
|
+
},
|
|
181
|
+
],
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Sends a **User Operation** to the smart wallet.
|
|
186
|
+
*
|
|
187
|
+
* This method directly exposes the **sendUserOperation** functionality, allowing
|
|
188
|
+
* **SmartWallet-aware tools** to fully leverage its capabilities, including batching multiple calls.
|
|
189
|
+
* Unlike `sendTransaction`, which wraps calls in a single operation, this method allows
|
|
190
|
+
* direct execution of arbitrary operations within a **User Operation**.
|
|
191
|
+
*
|
|
192
|
+
* @param {Omit<SendUserOperationOptions<T>, "chainId" | "paymasterUrl">} operation
|
|
193
|
+
* - The user operation configuration, omitting `chainId` and `paymasterUrl`,
|
|
194
|
+
* which are managed internally by the smart wallet.
|
|
195
|
+
*
|
|
196
|
+
* @returns A promise resolving to the transaction hash (`0x...`) if the operation completes successfully.
|
|
197
|
+
*
|
|
198
|
+
* @throws {Error} If the operation does not complete successfully.
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* ```typescript
|
|
202
|
+
* const txHash = await smartWallet.sendUserOperation({
|
|
203
|
+
* calls: [
|
|
204
|
+
* { to: "0x123...", value: parseEther("0.1"), data: "0x" },
|
|
205
|
+
* { to: "0x456...", value: parseEther("0.05"), data: "0x" }
|
|
206
|
+
* ],
|
|
207
|
+
* });
|
|
208
|
+
* console.log(`User Operation sent: ${txHash}`);
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
211
|
+
async sendUserOperation(operation) {
|
|
212
|
+
const sendUserOperationResult = await __classPrivateFieldGet(this, _SmartWalletProvider_smartWallet, "f").sendUserOperation(operation);
|
|
213
|
+
const result = await (0, coinbase_sdk_1.waitForUserOperation)(sendUserOperationResult);
|
|
214
|
+
if (result.status === "complete") {
|
|
215
|
+
return result.transactionHash;
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
throw new Error(`Transaction failed with status ${result.status}`);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Gets the address of the smart wallet.
|
|
223
|
+
*
|
|
224
|
+
* @returns The address of the smart wallet.
|
|
225
|
+
*/
|
|
226
|
+
getAddress() {
|
|
227
|
+
return __classPrivateFieldGet(this, _SmartWalletProvider_smartWallet, "f").address;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Gets the network of the wallet.
|
|
231
|
+
*
|
|
232
|
+
* @returns The network of the wallet.
|
|
233
|
+
*/
|
|
234
|
+
getNetwork() {
|
|
235
|
+
return __classPrivateFieldGet(this, _SmartWalletProvider_network, "f");
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Gets the name of the wallet provider.
|
|
239
|
+
*
|
|
240
|
+
* @returns The name of the wallet provider.
|
|
241
|
+
*/
|
|
242
|
+
getName() {
|
|
243
|
+
return "cdp_smart_wallet_provider";
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Gets the balance of the wallet.
|
|
247
|
+
*
|
|
248
|
+
* @returns The balance of the wallet in wei
|
|
249
|
+
*/
|
|
250
|
+
async getBalance() {
|
|
251
|
+
const balance = await __classPrivateFieldGet(this, _SmartWalletProvider_publicClient, "f").getBalance({
|
|
252
|
+
address: this.getAddress(),
|
|
253
|
+
});
|
|
254
|
+
return balance;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Waits for a transaction receipt.
|
|
258
|
+
*
|
|
259
|
+
* @param txHash - The hash of the transaction to wait for.
|
|
260
|
+
* @returns The transaction receipt.
|
|
261
|
+
*/
|
|
262
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
263
|
+
waitForTransactionReceipt(txHash) {
|
|
264
|
+
return __classPrivateFieldGet(this, _SmartWalletProvider_publicClient, "f").waitForTransactionReceipt({
|
|
265
|
+
hash: txHash,
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Reads a contract.
|
|
270
|
+
*
|
|
271
|
+
* @param params - The parameters to read the contract.
|
|
272
|
+
* @returns The response from the contract.
|
|
273
|
+
*/
|
|
274
|
+
async readContract(params) {
|
|
275
|
+
return __classPrivateFieldGet(this, _SmartWalletProvider_publicClient, "f").readContract(params);
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Transfer the native asset of the network.
|
|
279
|
+
*
|
|
280
|
+
* @param to - The destination address.
|
|
281
|
+
* @param value - The amount to transfer in Wei.
|
|
282
|
+
* @returns The transaction hash.
|
|
283
|
+
*/
|
|
284
|
+
async nativeTransfer(to, value) {
|
|
285
|
+
const sendUserOperationResult = await __classPrivateFieldGet(this, _SmartWalletProvider_smartWallet, "f").sendUserOperation({
|
|
286
|
+
calls: [
|
|
287
|
+
{
|
|
288
|
+
to,
|
|
289
|
+
value: BigInt(value),
|
|
290
|
+
},
|
|
291
|
+
],
|
|
292
|
+
});
|
|
293
|
+
const result = await (0, coinbase_sdk_1.waitForUserOperation)(sendUserOperationResult);
|
|
294
|
+
if (result.status === "complete") {
|
|
295
|
+
return result.transactionHash;
|
|
296
|
+
}
|
|
297
|
+
else {
|
|
298
|
+
throw new Error(`Transfer failed with status ${result.status}`);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
exports.SmartWalletProvider = SmartWalletProvider;
|
|
303
|
+
_SmartWalletProvider_smartWallet = new WeakMap(), _SmartWalletProvider_network = new WeakMap(), _SmartWalletProvider_publicClient = new WeakMap();
|
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.2.3-nightly.
|
|
5
|
+
"version": "0.2.3-nightly.20250227.19",
|
|
6
6
|
"author": "Coinbase Inc.",
|
|
7
7
|
"license": "Apache-2.0",
|
|
8
8
|
"main": "dist/index.js",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"typescript"
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@coinbase/coinbase-sdk": "^0.
|
|
42
|
+
"@coinbase/coinbase-sdk": "^0.19.0",
|
|
43
43
|
"@jup-ag/api": "^6.0.39",
|
|
44
44
|
"@privy-io/server-auth": "^1.18.4",
|
|
45
45
|
"@solana/spl-token": "^0.4.12",
|