@coinbase/agentkit 0.1.2 → 0.2.1

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 (46) hide show
  1. package/README.md +388 -5
  2. package/dist/action-providers/erc20/schemas.d.ts +2 -2
  3. package/dist/action-providers/index.d.ts +8 -7
  4. package/dist/action-providers/index.js +8 -7
  5. package/dist/action-providers/morpho/schemas.d.ts +4 -4
  6. package/dist/action-providers/spl/index.d.ts +1 -0
  7. package/dist/action-providers/spl/index.js +17 -0
  8. package/dist/action-providers/spl/schemas.d.ts +30 -0
  9. package/dist/action-providers/spl/schemas.js +26 -0
  10. package/dist/action-providers/spl/splActionProvider.d.ts +45 -0
  11. package/dist/action-providers/spl/splActionProvider.js +160 -0
  12. package/dist/action-providers/spl/splActionProvider.test.d.ts +1 -0
  13. package/dist/action-providers/spl/splActionProvider.test.js +263 -0
  14. package/dist/action-providers/wallet/walletActionProvider.d.ts +1 -1
  15. package/dist/action-providers/wallet/walletActionProvider.js +31 -18
  16. package/dist/action-providers/wallet/walletActionProvider.test.js +101 -23
  17. package/dist/network/index.d.ts +2 -1
  18. package/dist/network/index.js +2 -1
  19. package/dist/network/network.d.ts +7 -0
  20. package/dist/network/network.js +46 -1
  21. package/dist/network/svm.d.ts +15 -0
  22. package/dist/network/svm.js +38 -0
  23. package/dist/utils.d.ts +11 -0
  24. package/dist/utils.js +14 -0
  25. package/dist/wallet-providers/cdpWalletProvider.d.ts +13 -0
  26. package/dist/wallet-providers/cdpWalletProvider.js +14 -7
  27. package/dist/wallet-providers/index.d.ts +5 -0
  28. package/dist/wallet-providers/index.js +5 -0
  29. package/dist/wallet-providers/privyEvmWalletProvider.d.ts +55 -0
  30. package/dist/wallet-providers/privyEvmWalletProvider.js +140 -0
  31. package/dist/wallet-providers/privyShared.d.ts +40 -0
  32. package/dist/wallet-providers/privyShared.js +49 -0
  33. package/dist/wallet-providers/privySvmWalletProvider.d.ts +128 -0
  34. package/dist/wallet-providers/privySvmWalletProvider.js +212 -0
  35. package/dist/wallet-providers/privyWalletProvider.d.ts +35 -0
  36. package/dist/wallet-providers/privyWalletProvider.js +39 -0
  37. package/dist/wallet-providers/solanaKeypairWalletProvider.d.ts +143 -0
  38. package/dist/wallet-providers/solanaKeypairWalletProvider.js +280 -0
  39. package/dist/wallet-providers/solanaKeypairWalletProvider.test.d.ts +1 -0
  40. package/dist/wallet-providers/solanaKeypairWalletProvider.test.js +24 -0
  41. package/dist/wallet-providers/svmWalletProvider.d.ts +56 -0
  42. package/dist/wallet-providers/svmWalletProvider.js +13 -0
  43. package/dist/wallet-providers/viemWalletProvider.d.ts +15 -1
  44. package/dist/wallet-providers/viemWalletProvider.js +22 -3
  45. package/dist/wallet-providers/walletProvider.d.ts +1 -1
  46. package/package.json +4 -1
@@ -0,0 +1,143 @@
1
+ import { SvmWalletProvider } from "./svmWalletProvider";
2
+ import { Network } from "../network";
3
+ import { Connection, PublicKey, VersionedTransaction, RpcResponseAndContext, SignatureResult, SignatureStatus, SignatureStatusConfig } from "@solana/web3.js";
4
+ import { SOLANA_CLUSTER, SOLANA_NETWORK_ID } from "../network/svm";
5
+ /**
6
+ * SolanaKeypairWalletProvider is a wallet provider that uses a local Solana keypair.
7
+ *
8
+ * @augments SvmWalletProvider
9
+ */
10
+ export declare class SolanaKeypairWalletProvider extends SvmWalletProvider {
11
+ #private;
12
+ /**
13
+ * Creates a new SolanaKeypairWalletProvider
14
+ *
15
+ * @param args - Configuration arguments
16
+ * @param args.keypair - Either a Uint8Array or a base58 encoded string representing a 32-byte secret key
17
+ * @param args.rpcUrl - URL of the Solana RPC endpoint
18
+ * @param args.genesisHash - The genesis hash of the network
19
+ */
20
+ constructor({ keypair, rpcUrl, genesisHash, }: {
21
+ keypair: Uint8Array | string;
22
+ rpcUrl: string;
23
+ genesisHash: string;
24
+ });
25
+ /**
26
+ * Get the default RPC URL for a Solana cluster
27
+ *
28
+ * @param cluster - The cluster to get the RPC URL for
29
+ * @returns The RPC URL for the cluster
30
+ */
31
+ static urlForCluster(cluster: SOLANA_CLUSTER): string;
32
+ /**
33
+ * Create a new SolanaKeypairWalletProvider from an SVM networkId and a keypair
34
+ *
35
+ * @param networkId - The SVM networkId
36
+ * @param keypair - Either a Uint8Array or a base58 encoded string representing a 32-byte secret key
37
+ * @returns The new SolanaKeypairWalletProvider
38
+ */
39
+ static fromNetwork<T extends SolanaKeypairWalletProvider>(networkId: SOLANA_NETWORK_ID, keypair: Uint8Array | string): Promise<T>;
40
+ /**
41
+ * Create a new SolanaKeypairWalletProvider from an RPC URL and a keypair
42
+ *
43
+ * @param rpcUrl - The URL of the Solana RPC endpoint
44
+ * @param keypair - Either a Uint8Array or a base58 encoded string representing a 32-byte secret key
45
+ * @returns The new SolanaKeypairWalletProvider
46
+ */
47
+ static fromRpcUrl<T extends SolanaKeypairWalletProvider>(rpcUrl: string, keypair: Uint8Array | string): Promise<T>;
48
+ /**
49
+ * Create a new SolanaKeypairWalletProvider from a Connection and a keypair
50
+ *
51
+ * @param connection - The Connection to use
52
+ * @param keypair - Either a Uint8Array or a base58 encoded string representing a 32-byte secret key
53
+ * @returns The new SolanaKeypairWalletProvider
54
+ */
55
+ static fromConnection<T extends SolanaKeypairWalletProvider>(connection: Connection, keypair: Uint8Array | string): Promise<T>;
56
+ /**
57
+ * Get the connection instance
58
+ *
59
+ * @returns The Solana connection instance
60
+ */
61
+ getConnection(): Connection;
62
+ /**
63
+ * Get the public key of the wallet
64
+ *
65
+ * @returns The wallet's public key
66
+ */
67
+ getPublicKey(): PublicKey;
68
+ /**
69
+ * Get the address of the wallet
70
+ *
71
+ * @returns The base58 encoded address of the wallet
72
+ */
73
+ getAddress(): string;
74
+ /**
75
+ * Get the network
76
+ *
77
+ * @returns The network
78
+ */
79
+ getNetwork(): Network;
80
+ /**
81
+ * Sign a transaction
82
+ *
83
+ * @param transaction - The transaction to sign
84
+ * @returns The signed transaction
85
+ */
86
+ signTransaction(transaction: VersionedTransaction): Promise<VersionedTransaction>;
87
+ /**
88
+ * Send a transaction
89
+ *
90
+ * @param transaction - The transaction to send
91
+ * @returns The signature
92
+ */
93
+ sendTransaction(transaction: VersionedTransaction): Promise<string>;
94
+ /**
95
+ * Sign and send a transaction
96
+ *
97
+ * @param transaction - The transaction to sign and send
98
+ * @returns The signature
99
+ */
100
+ signAndSendTransaction(transaction: VersionedTransaction): Promise<string>;
101
+ /**
102
+ * Get the status of a transaction
103
+ *
104
+ * @param signature - The signature
105
+ * @param options - The options for the status
106
+ * @returns The status
107
+ */
108
+ getSignatureStatus(signature: string, options?: SignatureStatusConfig): Promise<RpcResponseAndContext<SignatureStatus | null>>;
109
+ /**
110
+ * Wait for signature receipt
111
+ *
112
+ * @param signature - The signature
113
+ * @returns The confirmation response
114
+ */
115
+ waitForSignatureResult(signature: string): Promise<RpcResponseAndContext<SignatureResult>>;
116
+ /**
117
+ * Get the name of the wallet provider
118
+ *
119
+ * @returns The name of the wallet provider
120
+ */
121
+ getName(): string;
122
+ /**
123
+ * Get the balance of the wallet
124
+ *
125
+ * @returns The balance of the wallet
126
+ */
127
+ getBalance(): Promise<bigint>;
128
+ /**
129
+ * Transfer SOL from the wallet to another address
130
+ *
131
+ * @param to - The base58 encoded address to transfer the SOL to
132
+ * @param value - The amount of SOL to transfer (as a decimal string, e.g. "0.0001")
133
+ * @returns The signature
134
+ */
135
+ nativeTransfer(to: string, value: string): Promise<string>;
136
+ /**
137
+ * Request SOL tokens from the Solana faucet. This method only works on devnet and testnet networks.
138
+ *
139
+ * @param lamports - The amount of lamports (1 SOL = 1,000,000,000 lamports) to request from the faucet
140
+ * @returns A Promise that resolves to the signature of the airdrop
141
+ */
142
+ requestAirdrop(lamports: number): Promise<string>;
143
+ }
@@ -0,0 +1,280 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ var _SolanaKeypairWalletProvider_keypair, _SolanaKeypairWalletProvider_connection, _SolanaKeypairWalletProvider_genesisHash;
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.SolanaKeypairWalletProvider = void 0;
19
+ const svmWalletProvider_1 = require("./svmWalletProvider");
20
+ const web3_js_1 = require("@solana/web3.js");
21
+ const bs58_1 = __importDefault(require("bs58"));
22
+ const svm_1 = require("../network/svm");
23
+ /**
24
+ * SolanaKeypairWalletProvider is a wallet provider that uses a local Solana keypair.
25
+ *
26
+ * @augments SvmWalletProvider
27
+ */
28
+ class SolanaKeypairWalletProvider extends svmWalletProvider_1.SvmWalletProvider {
29
+ /**
30
+ * Creates a new SolanaKeypairWalletProvider
31
+ *
32
+ * @param args - Configuration arguments
33
+ * @param args.keypair - Either a Uint8Array or a base58 encoded string representing a 32-byte secret key
34
+ * @param args.rpcUrl - URL of the Solana RPC endpoint
35
+ * @param args.genesisHash - The genesis hash of the network
36
+ */
37
+ constructor({ keypair, rpcUrl, genesisHash, }) {
38
+ super();
39
+ _SolanaKeypairWalletProvider_keypair.set(this, void 0);
40
+ _SolanaKeypairWalletProvider_connection.set(this, void 0);
41
+ _SolanaKeypairWalletProvider_genesisHash.set(this, void 0);
42
+ __classPrivateFieldSet(this, _SolanaKeypairWalletProvider_keypair, typeof keypair === "string"
43
+ ? web3_js_1.Keypair.fromSecretKey(bs58_1.default.decode(keypair))
44
+ : web3_js_1.Keypair.fromSecretKey(keypair), "f");
45
+ __classPrivateFieldSet(this, _SolanaKeypairWalletProvider_connection, new web3_js_1.Connection(rpcUrl), "f");
46
+ if (genesisHash in svm_1.SOLANA_NETWORKS) {
47
+ __classPrivateFieldSet(this, _SolanaKeypairWalletProvider_genesisHash, genesisHash, "f");
48
+ }
49
+ else {
50
+ throw new Error(`Unknown network with genesis hash: ${genesisHash}`);
51
+ }
52
+ }
53
+ /**
54
+ * Get the default RPC URL for a Solana cluster
55
+ *
56
+ * @param cluster - The cluster to get the RPC URL for
57
+ * @returns The RPC URL for the cluster
58
+ */
59
+ static urlForCluster(cluster) {
60
+ if (cluster in svm_1.SOLANA_NETWORKS) {
61
+ switch (cluster) {
62
+ case svm_1.SOLANA_MAINNET_GENESIS_BLOCK_HASH:
63
+ return (0, web3_js_1.clusterApiUrl)("mainnet-beta");
64
+ case svm_1.SOLANA_TESTNET_GENESIS_BLOCK_HASH:
65
+ return (0, web3_js_1.clusterApiUrl)("testnet");
66
+ case svm_1.SOLANA_DEVNET_GENESIS_BLOCK_HASH:
67
+ return (0, web3_js_1.clusterApiUrl)("devnet");
68
+ default:
69
+ throw new Error(`Unknown cluster: ${cluster}`);
70
+ }
71
+ }
72
+ else {
73
+ throw new Error(`Unknown cluster: ${cluster}`);
74
+ }
75
+ }
76
+ /**
77
+ * Create a new SolanaKeypairWalletProvider from an SVM networkId and a keypair
78
+ *
79
+ * @param networkId - The SVM networkId
80
+ * @param keypair - Either a Uint8Array or a base58 encoded string representing a 32-byte secret key
81
+ * @returns The new SolanaKeypairWalletProvider
82
+ */
83
+ static async fromNetwork(networkId, keypair) {
84
+ let genesisHash;
85
+ switch (networkId) {
86
+ case svm_1.SOLANA_MAINNET_NETWORK_ID:
87
+ genesisHash = svm_1.SOLANA_MAINNET_GENESIS_BLOCK_HASH;
88
+ break;
89
+ case svm_1.SOLANA_DEVNET_NETWORK_ID:
90
+ genesisHash = svm_1.SOLANA_DEVNET_GENESIS_BLOCK_HASH;
91
+ break;
92
+ case svm_1.SOLANA_TESTNET_NETWORK_ID:
93
+ genesisHash = svm_1.SOLANA_TESTNET_GENESIS_BLOCK_HASH;
94
+ break;
95
+ default:
96
+ throw new Error(`${networkId} is not a valid SVM networkId`);
97
+ }
98
+ const rpcUrl = this.urlForCluster(genesisHash);
99
+ return await this.fromRpcUrl(rpcUrl, keypair);
100
+ }
101
+ /**
102
+ * Create a new SolanaKeypairWalletProvider from an RPC URL and a keypair
103
+ *
104
+ * @param rpcUrl - The URL of the Solana RPC endpoint
105
+ * @param keypair - Either a Uint8Array or a base58 encoded string representing a 32-byte secret key
106
+ * @returns The new SolanaKeypairWalletProvider
107
+ */
108
+ static async fromRpcUrl(rpcUrl, keypair) {
109
+ const connection = new web3_js_1.Connection(rpcUrl);
110
+ return await this.fromConnection(connection, keypair);
111
+ }
112
+ /**
113
+ * Create a new SolanaKeypairWalletProvider from a Connection and a keypair
114
+ *
115
+ * @param connection - The Connection to use
116
+ * @param keypair - Either a Uint8Array or a base58 encoded string representing a 32-byte secret key
117
+ * @returns The new SolanaKeypairWalletProvider
118
+ */
119
+ static async fromConnection(connection, keypair) {
120
+ const genesisHash = await connection.getGenesisHash();
121
+ return new SolanaKeypairWalletProvider({
122
+ keypair,
123
+ rpcUrl: connection.rpcEndpoint,
124
+ genesisHash: genesisHash,
125
+ });
126
+ }
127
+ /**
128
+ * Get the connection instance
129
+ *
130
+ * @returns The Solana connection instance
131
+ */
132
+ getConnection() {
133
+ return __classPrivateFieldGet(this, _SolanaKeypairWalletProvider_connection, "f");
134
+ }
135
+ /**
136
+ * Get the public key of the wallet
137
+ *
138
+ * @returns The wallet's public key
139
+ */
140
+ getPublicKey() {
141
+ return __classPrivateFieldGet(this, _SolanaKeypairWalletProvider_keypair, "f").publicKey;
142
+ }
143
+ /**
144
+ * Get the address of the wallet
145
+ *
146
+ * @returns The base58 encoded address of the wallet
147
+ */
148
+ getAddress() {
149
+ return __classPrivateFieldGet(this, _SolanaKeypairWalletProvider_keypair, "f").publicKey.toBase58();
150
+ }
151
+ /**
152
+ * Get the network
153
+ *
154
+ * @returns The network
155
+ */
156
+ getNetwork() {
157
+ return svm_1.SOLANA_NETWORKS[__classPrivateFieldGet(this, _SolanaKeypairWalletProvider_genesisHash, "f")];
158
+ }
159
+ /**
160
+ * Sign a transaction
161
+ *
162
+ * @param transaction - The transaction to sign
163
+ * @returns The signed transaction
164
+ */
165
+ async signTransaction(transaction) {
166
+ transaction.sign([__classPrivateFieldGet(this, _SolanaKeypairWalletProvider_keypair, "f")]);
167
+ return transaction;
168
+ }
169
+ /**
170
+ * Send a transaction
171
+ *
172
+ * @param transaction - The transaction to send
173
+ * @returns The signature
174
+ */
175
+ async sendTransaction(transaction) {
176
+ const signature = await __classPrivateFieldGet(this, _SolanaKeypairWalletProvider_connection, "f").sendTransaction(transaction);
177
+ await this.waitForSignatureResult(signature);
178
+ return signature;
179
+ }
180
+ /**
181
+ * Sign and send a transaction
182
+ *
183
+ * @param transaction - The transaction to sign and send
184
+ * @returns The signature
185
+ */
186
+ async signAndSendTransaction(transaction) {
187
+ const signedTransaction = await this.signTransaction(transaction);
188
+ return this.sendTransaction(signedTransaction);
189
+ }
190
+ /**
191
+ * Get the status of a transaction
192
+ *
193
+ * @param signature - The signature
194
+ * @param options - The options for the status
195
+ * @returns The status
196
+ */
197
+ async getSignatureStatus(signature, options) {
198
+ return __classPrivateFieldGet(this, _SolanaKeypairWalletProvider_connection, "f").getSignatureStatus(signature, options);
199
+ }
200
+ /**
201
+ * Wait for signature receipt
202
+ *
203
+ * @param signature - The signature
204
+ * @returns The confirmation response
205
+ */
206
+ async waitForSignatureResult(signature) {
207
+ const { blockhash, lastValidBlockHeight } = await __classPrivateFieldGet(this, _SolanaKeypairWalletProvider_connection, "f").getLatestBlockhash();
208
+ return __classPrivateFieldGet(this, _SolanaKeypairWalletProvider_connection, "f").confirmTransaction({
209
+ signature: signature,
210
+ lastValidBlockHeight,
211
+ blockhash,
212
+ });
213
+ }
214
+ /**
215
+ * Get the name of the wallet provider
216
+ *
217
+ * @returns The name of the wallet provider
218
+ */
219
+ getName() {
220
+ return "solana_keypair_wallet_provider";
221
+ }
222
+ /**
223
+ * Get the balance of the wallet
224
+ *
225
+ * @returns The balance of the wallet
226
+ */
227
+ getBalance() {
228
+ return __classPrivateFieldGet(this, _SolanaKeypairWalletProvider_connection, "f").getBalance(__classPrivateFieldGet(this, _SolanaKeypairWalletProvider_keypair, "f").publicKey).then(balance => BigInt(balance));
229
+ }
230
+ /**
231
+ * Transfer SOL from the wallet to another address
232
+ *
233
+ * @param to - The base58 encoded address to transfer the SOL to
234
+ * @param value - The amount of SOL to transfer (as a decimal string, e.g. "0.0001")
235
+ * @returns The signature
236
+ */
237
+ async nativeTransfer(to, value) {
238
+ const initialBalance = await this.getBalance();
239
+ const solAmount = parseFloat(value);
240
+ const lamports = BigInt(Math.floor(solAmount * web3_js_1.LAMPORTS_PER_SOL));
241
+ // Check if we have enough balance (including estimated fees)
242
+ if (initialBalance < lamports + BigInt(5000)) {
243
+ throw new Error(`Insufficient balance. Have ${Number(initialBalance) / web3_js_1.LAMPORTS_PER_SOL} SOL, need ${solAmount + 0.000005} SOL (including fees)`);
244
+ }
245
+ const toPubkey = new web3_js_1.PublicKey(to);
246
+ const instructions = [
247
+ web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
248
+ microLamports: 10000,
249
+ }),
250
+ web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({
251
+ units: 2000,
252
+ }),
253
+ web3_js_1.SystemProgram.transfer({
254
+ fromPubkey: __classPrivateFieldGet(this, _SolanaKeypairWalletProvider_keypair, "f").publicKey,
255
+ toPubkey: toPubkey,
256
+ lamports: lamports,
257
+ }),
258
+ ];
259
+ const tx = new web3_js_1.VersionedTransaction(web3_js_1.MessageV0.compile({
260
+ payerKey: __classPrivateFieldGet(this, _SolanaKeypairWalletProvider_keypair, "f").publicKey,
261
+ instructions: instructions,
262
+ recentBlockhash: (await __classPrivateFieldGet(this, _SolanaKeypairWalletProvider_connection, "f").getLatestBlockhash()).blockhash,
263
+ }));
264
+ tx.sign([__classPrivateFieldGet(this, _SolanaKeypairWalletProvider_keypair, "f")]);
265
+ const signature = await __classPrivateFieldGet(this, _SolanaKeypairWalletProvider_connection, "f").sendTransaction(tx);
266
+ await this.waitForSignatureResult(signature);
267
+ return signature;
268
+ }
269
+ /**
270
+ * Request SOL tokens from the Solana faucet. This method only works on devnet and testnet networks.
271
+ *
272
+ * @param lamports - The amount of lamports (1 SOL = 1,000,000,000 lamports) to request from the faucet
273
+ * @returns A Promise that resolves to the signature of the airdrop
274
+ */
275
+ async requestAirdrop(lamports) {
276
+ return await __classPrivateFieldGet(this, _SolanaKeypairWalletProvider_connection, "f").requestAirdrop(__classPrivateFieldGet(this, _SolanaKeypairWalletProvider_keypair, "f").publicKey, lamports);
277
+ }
278
+ }
279
+ exports.SolanaKeypairWalletProvider = SolanaKeypairWalletProvider;
280
+ _SolanaKeypairWalletProvider_keypair = new WeakMap(), _SolanaKeypairWalletProvider_connection = new WeakMap(), _SolanaKeypairWalletProvider_genesisHash = new WeakMap();
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const web3_js_1 = require("@solana/web3.js");
4
+ const solanaKeypairWalletProvider_1 = require("./solanaKeypairWalletProvider");
5
+ const svm_1 = require("../network/svm");
6
+ describe("Solana Keypair Wallet", () => {
7
+ it("should initialize correctly via convenience getters", async () => {
8
+ const keypair = web3_js_1.Keypair.generate();
9
+ let wallet = await solanaKeypairWalletProvider_1.SolanaKeypairWalletProvider.fromRpcUrl((0, web3_js_1.clusterApiUrl)("devnet"), keypair.secretKey);
10
+ expect(wallet.getNetwork()).toEqual(svm_1.SOLANA_NETWORKS[svm_1.SOLANA_DEVNET_GENESIS_BLOCK_HASH]);
11
+ wallet = await solanaKeypairWalletProvider_1.SolanaKeypairWalletProvider.fromRpcUrl((0, web3_js_1.clusterApiUrl)("testnet"), keypair.secretKey);
12
+ expect(wallet.getNetwork()).toEqual(svm_1.SOLANA_NETWORKS[svm_1.SOLANA_TESTNET_GENESIS_BLOCK_HASH]);
13
+ wallet = await solanaKeypairWalletProvider_1.SolanaKeypairWalletProvider.fromRpcUrl((0, web3_js_1.clusterApiUrl)("mainnet-beta"), keypair.secretKey);
14
+ expect(wallet.getNetwork()).toEqual(svm_1.SOLANA_NETWORKS[svm_1.SOLANA_MAINNET_GENESIS_BLOCK_HASH]);
15
+ expect(wallet.getAddress()).toEqual(keypair.publicKey.toBase58());
16
+ });
17
+ it("should error when the network genesis hash is unknown", async () => {
18
+ expect(() => new solanaKeypairWalletProvider_1.SolanaKeypairWalletProvider({
19
+ keypair: web3_js_1.Keypair.generate().secretKey,
20
+ rpcUrl: (0, web3_js_1.clusterApiUrl)("mainnet-beta"),
21
+ genesisHash: "0x123",
22
+ })).toThrowError("Unknown network with genesis hash");
23
+ });
24
+ });
@@ -0,0 +1,56 @@
1
+ import { WalletProvider } from "./walletProvider";
2
+ import { Connection, PublicKey, RpcResponseAndContext, SignatureStatus, SignatureStatusConfig, VersionedTransaction, SignatureResult } from "@solana/web3.js";
3
+ /**
4
+ * SvmWalletProvider is the abstract base class for all Solana wallet providers (non browsers).
5
+ *
6
+ * @abstract
7
+ */
8
+ export declare abstract class SvmWalletProvider extends WalletProvider {
9
+ /**
10
+ * Get the connection instance.
11
+ *
12
+ * @returns The Solana connection instance.
13
+ */
14
+ abstract getConnection(): Connection;
15
+ /**
16
+ * Get the public key of the wallet.
17
+ *
18
+ * @returns The wallet's public key.
19
+ */
20
+ abstract getPublicKey(): PublicKey;
21
+ /**
22
+ * Sign a transaction.
23
+ *
24
+ * @param transaction - The transaction to sign.
25
+ * @returns The signed transaction.
26
+ */
27
+ abstract signTransaction(transaction: VersionedTransaction): Promise<VersionedTransaction>;
28
+ /**
29
+ * Send a transaction.
30
+ *
31
+ * @param transaction - The transaction to send.
32
+ * @returns The signature.
33
+ */
34
+ abstract sendTransaction(transaction: VersionedTransaction): Promise<string>;
35
+ /**
36
+ * Sign and send a transaction.
37
+ *
38
+ * @param transaction - The transaction to sign and send.
39
+ * @returns The signature.
40
+ */
41
+ abstract signAndSendTransaction(transaction: VersionedTransaction): Promise<string>;
42
+ /**
43
+ * Get the status of a transaction.
44
+ *
45
+ * @param signature - The signature.
46
+ * @returns The status.
47
+ */
48
+ abstract getSignatureStatus(signature: string, options?: SignatureStatusConfig): Promise<RpcResponseAndContext<SignatureStatus | null>>;
49
+ /**
50
+ * Wait for signature receipt.
51
+ *
52
+ * @param signature - The signature
53
+ * @returns The confirmation response
54
+ */
55
+ abstract waitForSignatureResult(signature: string): Promise<RpcResponseAndContext<SignatureResult>>;
56
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ /* eslint-disable @typescript-eslint/no-explicit-any */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.SvmWalletProvider = void 0;
5
+ const walletProvider_1 = require("./walletProvider");
6
+ /**
7
+ * SvmWalletProvider is the abstract base class for all Solana wallet providers (non browsers).
8
+ *
9
+ * @abstract
10
+ */
11
+ class SvmWalletProvider extends walletProvider_1.WalletProvider {
12
+ }
13
+ exports.SvmWalletProvider = SvmWalletProvider;
@@ -1,6 +1,19 @@
1
1
  import { WalletClient as ViemWalletClient, TransactionRequest, ReadContractParameters, ReadContractReturnType } from "viem";
2
2
  import { EvmWalletProvider } from "./evmWalletProvider";
3
3
  import { Network } from "../network";
4
+ /**
5
+ * Configuration for gas multipliers.
6
+ */
7
+ export interface ViemWalletProviderGasConfig {
8
+ /**
9
+ * An internal multiplier on gas limit estimation.
10
+ */
11
+ gasLimitMultiplier?: number;
12
+ /**
13
+ * An internal multiplier on fee per gas estimation.
14
+ */
15
+ feePerGasMultiplier?: number;
16
+ }
4
17
  /**
5
18
  * A wallet provider that uses the Viem library.
6
19
  */
@@ -10,8 +23,9 @@ export declare class ViemWalletProvider extends EvmWalletProvider {
10
23
  * Constructs a new ViemWalletProvider.
11
24
  *
12
25
  * @param walletClient - The wallet client.
26
+ * @param gasConfig - Configuration for gas multipliers.
13
27
  */
14
- constructor(walletClient: ViemWalletClient);
28
+ constructor(walletClient: ViemWalletClient, gasConfig?: ViemWalletProviderGasConfig);
15
29
  /**
16
30
  * Signs a message.
17
31
  *
@@ -12,12 +12,13 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
12
12
  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");
13
13
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
14
14
  };
15
- var _ViemWalletProvider_walletClient, _ViemWalletProvider_publicClient;
15
+ var _ViemWalletProvider_walletClient, _ViemWalletProvider_publicClient, _ViemWalletProvider_gasLimitMultiplier, _ViemWalletProvider_feePerGasMultiplier;
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.ViemWalletProvider = void 0;
18
18
  const viem_1 = require("viem");
19
19
  const evmWalletProvider_1 = require("./evmWalletProvider");
20
20
  const network_1 = require("../network/network");
21
+ const utils_1 = require("../utils");
21
22
  /**
22
23
  * A wallet provider that uses the Viem library.
23
24
  */
@@ -26,16 +27,21 @@ class ViemWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
26
27
  * Constructs a new ViemWalletProvider.
27
28
  *
28
29
  * @param walletClient - The wallet client.
30
+ * @param gasConfig - Configuration for gas multipliers.
29
31
  */
30
- constructor(walletClient) {
32
+ constructor(walletClient, gasConfig) {
31
33
  super();
32
34
  _ViemWalletProvider_walletClient.set(this, void 0);
33
35
  _ViemWalletProvider_publicClient.set(this, void 0);
36
+ _ViemWalletProvider_gasLimitMultiplier.set(this, void 0);
37
+ _ViemWalletProvider_feePerGasMultiplier.set(this, void 0);
34
38
  __classPrivateFieldSet(this, _ViemWalletProvider_walletClient, walletClient, "f");
35
39
  __classPrivateFieldSet(this, _ViemWalletProvider_publicClient, (0, viem_1.createPublicClient)({
36
40
  chain: walletClient.chain,
37
41
  transport: (0, viem_1.http)(),
38
42
  }), "f");
43
+ __classPrivateFieldSet(this, _ViemWalletProvider_gasLimitMultiplier, Math.max(gasConfig?.gasLimitMultiplier ?? 1.2, 1), "f");
44
+ __classPrivateFieldSet(this, _ViemWalletProvider_feePerGasMultiplier, Math.max(gasConfig?.feePerGasMultiplier ?? 1, 1), "f");
39
45
  }
40
46
  /**
41
47
  * Signs a message.
@@ -96,12 +102,25 @@ class ViemWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
96
102
  if (!chain) {
97
103
  throw new Error("Chain not found");
98
104
  }
105
+ const feeData = await __classPrivateFieldGet(this, _ViemWalletProvider_publicClient, "f").estimateFeesPerGas();
106
+ const maxFeePerGas = (0, utils_1.applyGasMultiplier)(feeData.maxFeePerGas, __classPrivateFieldGet(this, _ViemWalletProvider_feePerGasMultiplier, "f"));
107
+ const maxPriorityFeePerGas = (0, utils_1.applyGasMultiplier)(feeData.maxPriorityFeePerGas, __classPrivateFieldGet(this, _ViemWalletProvider_feePerGasMultiplier, "f"));
108
+ const gasLimit = await __classPrivateFieldGet(this, _ViemWalletProvider_publicClient, "f").estimateGas({
109
+ account,
110
+ to: transaction.to,
111
+ value: transaction.value,
112
+ data: transaction.data,
113
+ });
114
+ const gas = BigInt(Math.round(Number(gasLimit) * __classPrivateFieldGet(this, _ViemWalletProvider_gasLimitMultiplier, "f")));
99
115
  const txParams = {
100
116
  account: account,
101
117
  chain: chain,
102
118
  data: transaction.data,
103
119
  to: transaction.to,
104
120
  value: transaction.value,
121
+ gas,
122
+ maxFeePerGas,
123
+ maxPriorityFeePerGas,
105
124
  };
106
125
  return __classPrivateFieldGet(this, _ViemWalletProvider_walletClient, "f").sendTransaction(txParams);
107
126
  }
@@ -184,4 +203,4 @@ class ViemWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
184
203
  }
185
204
  }
186
205
  exports.ViemWalletProvider = ViemWalletProvider;
187
- _ViemWalletProvider_walletClient = new WeakMap(), _ViemWalletProvider_publicClient = new WeakMap();
206
+ _ViemWalletProvider_walletClient = new WeakMap(), _ViemWalletProvider_publicClient = new WeakMap(), _ViemWalletProvider_gasLimitMultiplier = new WeakMap(), _ViemWalletProvider_feePerGasMultiplier = new WeakMap();
@@ -44,5 +44,5 @@ export declare abstract class WalletProvider {
44
44
  * @param value - The amount to transfer in whole units (e.g. ETH)
45
45
  * @returns The transaction hash.
46
46
  */
47
- abstract nativeTransfer(to: `0x${string}`, value: string): Promise<`0x${string}`>;
47
+ abstract nativeTransfer(to: string, value: string): Promise<string>;
48
48
  }
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.1.2",
5
+ "version": "0.2.1",
6
6
  "author": "Coinbase Inc.",
7
7
  "license": "Apache-2.0",
8
8
  "main": "dist/index.js",
@@ -40,6 +40,9 @@
40
40
  ],
41
41
  "dependencies": {
42
42
  "@coinbase/coinbase-sdk": "^0.17.0",
43
+ "@privy-io/server-auth": "^1.18.4",
44
+ "@solana/spl-token": "^0.4.12",
45
+ "@solana/web3.js": "^1.98.0",
43
46
  "md5": "^2.3.0",
44
47
  "reflect-metadata": "^0.2.2",
45
48
  "twitter-api-v2": "^1.18.2",