@coinbase/agentkit 0.1.1 → 0.2.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 +338 -5
- package/dist/action-providers/alchemy/alchemyTokenPricesActionProvider.d.ts +55 -0
- package/dist/action-providers/alchemy/alchemyTokenPricesActionProvider.js +173 -0
- package/dist/action-providers/alchemy/alchemyTokenPricesActionProvider.test.d.ts +1 -0
- package/dist/action-providers/alchemy/alchemyTokenPricesActionProvider.test.js +131 -0
- package/dist/action-providers/alchemy/index.d.ts +2 -0
- package/dist/action-providers/alchemy/index.js +18 -0
- package/dist/action-providers/alchemy/schemas.d.ts +41 -0
- package/dist/action-providers/alchemy/schemas.js +34 -0
- package/dist/action-providers/basename/basenameActionProvider.d.ts +1 -1
- package/dist/action-providers/cdp/cdpApiActionProvider.js +7 -1
- package/dist/action-providers/erc20/erc20ActionProvider.d.ts +1 -1
- package/dist/action-providers/erc20/schemas.d.ts +2 -2
- package/dist/action-providers/erc721/erc721ActionProvider.d.ts +1 -1
- package/dist/action-providers/index.d.ts +8 -5
- package/dist/action-providers/index.js +8 -5
- package/dist/action-providers/moonwell/constants.d.ts +78 -0
- package/dist/action-providers/moonwell/constants.js +111 -0
- package/dist/action-providers/moonwell/index.d.ts +1 -0
- package/dist/action-providers/moonwell/index.js +5 -0
- package/dist/action-providers/moonwell/moonwellActionProvider.d.ts +39 -0
- package/dist/action-providers/moonwell/moonwellActionProvider.js +249 -0
- package/dist/action-providers/moonwell/moonwellActionProvider.test.d.ts +1 -0
- package/dist/action-providers/moonwell/moonwellActionProvider.test.js +455 -0
- package/dist/action-providers/moonwell/schemas.d.ts +30 -0
- package/dist/action-providers/moonwell/schemas.js +39 -0
- package/dist/action-providers/morpho/morphoActionProvider.d.ts +1 -1
- package/dist/action-providers/morpho/schemas.d.ts +4 -4
- package/dist/action-providers/pyth/pythActionProvider.test.d.ts +1 -0
- package/dist/action-providers/pyth/pythActionProvider.test.js +113 -0
- package/dist/action-providers/spl/index.d.ts +1 -0
- package/dist/action-providers/spl/index.js +17 -0
- package/dist/action-providers/spl/schemas.d.ts +17 -0
- package/dist/action-providers/spl/schemas.js +14 -0
- package/dist/action-providers/spl/splActionProvider.d.ts +37 -0
- package/dist/action-providers/spl/splActionProvider.js +112 -0
- package/dist/action-providers/spl/splActionProvider.test.d.ts +1 -0
- package/dist/action-providers/spl/splActionProvider.test.js +206 -0
- package/dist/action-providers/wallet/walletActionProvider.d.ts +1 -1
- package/dist/action-providers/wallet/walletActionProvider.js +31 -18
- package/dist/action-providers/wallet/walletActionProvider.test.js +101 -23
- package/dist/action-providers/weth/wethActionProvider.d.ts +1 -1
- package/dist/action-providers/wow/wowActionProvider.d.ts +1 -1
- package/dist/network/index.d.ts +2 -1
- package/dist/network/index.js +2 -1
- package/dist/network/network.d.ts +7 -0
- package/dist/network/network.js +46 -1
- package/dist/network/svm.d.ts +14 -0
- package/dist/network/svm.js +33 -0
- package/dist/utils.d.ts +11 -0
- package/dist/utils.js +14 -0
- package/dist/wallet-providers/cdpWalletProvider.d.ts +13 -0
- package/dist/wallet-providers/cdpWalletProvider.js +31 -8
- package/dist/wallet-providers/index.d.ts +3 -0
- package/dist/wallet-providers/index.js +3 -0
- package/dist/wallet-providers/privyWalletProvider.d.ts +70 -0
- package/dist/wallet-providers/privyWalletProvider.js +139 -0
- package/dist/wallet-providers/solanaKeypairWalletProvider.d.ts +143 -0
- package/dist/wallet-providers/solanaKeypairWalletProvider.js +280 -0
- package/dist/wallet-providers/solanaKeypairWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/solanaKeypairWalletProvider.test.js +24 -0
- package/dist/wallet-providers/svmWalletProvider.d.ts +56 -0
- package/dist/wallet-providers/svmWalletProvider.js +13 -0
- package/dist/wallet-providers/viemWalletProvider.d.ts +15 -1
- package/dist/wallet-providers/viemWalletProvider.js +23 -4
- package/dist/wallet-providers/walletProvider.d.ts +1 -1
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -8,18 +8,32 @@ AgentKit is a framework for easily enabling AI agents to take actions onchain. I
|
|
|
8
8
|
- [Getting Started](#getting-started)
|
|
9
9
|
- [Installation](#installation)
|
|
10
10
|
- [Usage](#usage)
|
|
11
|
-
- [Create an AgentKit instance](
|
|
11
|
+
- [Create an AgentKit instance](#create-an-agentkit-instance)
|
|
12
12
|
- [Create an AgentKit instance with a specified wallet provider](#create-an-agentkit-instance-with-a-specified-wallet-provider)
|
|
13
13
|
- [Create an AgentKit instance with a specified action providers](#create-an-agentkit-instance-with-a-specified-action-providers)
|
|
14
14
|
- [Use the agent's actions with a framework extension. For example, using LangChain + OpenAI](#use-the-agents-actions-with-a-framework-extension-for-example-using-langchain--openai)
|
|
15
|
-
- [
|
|
15
|
+
- [Action Providers](#action-providers)
|
|
16
|
+
- [Creating an Action Provider](#creating-an-action-provider)
|
|
17
|
+
- [Adding Actions to your Action Provider](#adding-actions-to-your-action-provider)
|
|
18
|
+
- [Adding Actions to your Action Provider that use a Wallet Provider](#adding-actions-to-your-action-provider-that-use-a-wallet-provider)
|
|
19
|
+
- [Adding an Action Provider to your AgentKit instance](#adding-an-action-provider-to-your-agentkit-instance)
|
|
20
|
+
- [EVM Wallet Providers](#evm-wallet-providers)
|
|
16
21
|
- [CdpWalletProvider](#cdpwalletprovider)
|
|
17
22
|
- [Network Configuration](#network-configuration)
|
|
18
23
|
- [Configuring from an existing CDP API Wallet](#configuring-from-an-existing-cdp-api-wallet)
|
|
19
24
|
- [Configuring from a mnemonic phrase](#configuring-from-a-mnemonic-phrase)
|
|
20
25
|
- [Exporting a wallet](#exporting-a-wallet)
|
|
21
26
|
- [Importing a wallet from WalletData JSON string](#importing-a-wallet-from-walletdata-json-string)
|
|
27
|
+
- [Configuring gas parameters](#configuring-cdpwalletprovider-gas-parameters)
|
|
22
28
|
- [ViemWalletProvider](#viemwalletprovider)
|
|
29
|
+
- [Configuring gas parameters](#configuring-viemwalletprovider-gas-parameters)
|
|
30
|
+
- [PrivyWalletProvider](#privywalletprovider)
|
|
31
|
+
- [Authorization Keys](#authorization-keys)
|
|
32
|
+
- [Exporting Privy Wallet information](#exporting-privy-wallet-information)
|
|
33
|
+
- [SVM Wallet Providers](#svm-wallet-providers)
|
|
34
|
+
- [SolanaKeypairWalletProvider](#solanakeypairwalletprovider)
|
|
35
|
+
- [Network Configuration](#solana-network-configuration)
|
|
36
|
+
- [RPC URL Configuration](#rpc-url-configuration)
|
|
23
37
|
- [Contributing](#contributing)
|
|
24
38
|
|
|
25
39
|
## Getting Started
|
|
@@ -45,6 +59,17 @@ const agentKit = await AgentKit.from({
|
|
|
45
59
|
});
|
|
46
60
|
```
|
|
47
61
|
|
|
62
|
+
### Create an AgentKit instance
|
|
63
|
+
|
|
64
|
+
If no wallet or action provider are specified, the agent will use the `CdpWalletProvider` and `WalletActionProvider` action provider by default.
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
const agentKit = await AgentKit.from({
|
|
68
|
+
cdpApiKeyName: "CDP API KEY NAME",
|
|
69
|
+
cdpApiKeyPrivate: "CDP API KEY PRIVATE KEY",
|
|
70
|
+
});
|
|
71
|
+
```
|
|
72
|
+
|
|
48
73
|
### Create an AgentKit instance with a specified wallet provider.
|
|
49
74
|
|
|
50
75
|
```typescript
|
|
@@ -105,6 +130,167 @@ const agent = createReactAgent({
|
|
|
105
130
|
});
|
|
106
131
|
```
|
|
107
132
|
|
|
133
|
+
## Action Providers
|
|
134
|
+
<details>
|
|
135
|
+
<summary><strong>Basename</strong></summary>
|
|
136
|
+
<table width="100%">
|
|
137
|
+
<tr>
|
|
138
|
+
<td width="200"><code>register_basename</code></td>
|
|
139
|
+
<td width="768">Registers a custom .base.eth or .basetest.eth domain name for the wallet address.</td>
|
|
140
|
+
</tr>
|
|
141
|
+
</table>
|
|
142
|
+
</details>
|
|
143
|
+
<details>
|
|
144
|
+
<summary><strong>CDP Wallet</strong></summary>
|
|
145
|
+
<table width="100%">
|
|
146
|
+
<tr>
|
|
147
|
+
<td width="200"><code>deploy_contract</code></td>
|
|
148
|
+
<td width="768">Deploys a custom smart contract using specified Solidity version and constructor arguments.</td>
|
|
149
|
+
</tr>
|
|
150
|
+
<tr>
|
|
151
|
+
<td width="200"><code>deploy_nft</code></td>
|
|
152
|
+
<td width="768">Deploys a standard ERC-721 NFT contract with configurable name, symbol, and metadata URI.</td>
|
|
153
|
+
</tr>
|
|
154
|
+
<tr>
|
|
155
|
+
<td width="200"><code>deploy_token</code></td>
|
|
156
|
+
<td width="768">Deploys a standard ERC-20 token contract with configurable name, symbol, and initial supply.</td>
|
|
157
|
+
</tr>
|
|
158
|
+
<tr>
|
|
159
|
+
<td width="200"><code>trade</code></td>
|
|
160
|
+
<td width="768">Executes a token swap between two assets at current market rates on mainnet networks.</td>
|
|
161
|
+
</tr>
|
|
162
|
+
</table>
|
|
163
|
+
</details>
|
|
164
|
+
<details>
|
|
165
|
+
<summary><strong>ERC20</strong></summary>
|
|
166
|
+
<table width="100%">
|
|
167
|
+
<tr>
|
|
168
|
+
<td width="200"><code>get_balance</code></td>
|
|
169
|
+
<td width="768">Retrieves the token balance for a specified address and ERC-20 contract.</td>
|
|
170
|
+
</tr>
|
|
171
|
+
<tr>
|
|
172
|
+
<td width="200"><code>transfer</code></td>
|
|
173
|
+
<td width="768">Transfers a specified amount of ERC-20 tokens to a destination address.</td>
|
|
174
|
+
</tr>
|
|
175
|
+
</table>
|
|
176
|
+
</details>
|
|
177
|
+
<details>
|
|
178
|
+
<summary><strong>ERC721</strong></summary>
|
|
179
|
+
<table width="100%">
|
|
180
|
+
<tr>
|
|
181
|
+
<td width="200"><code>get_balance</code></td>
|
|
182
|
+
<td width="768">Retrieves the NFT balance for a specified address and ERC-721 contract.</td>
|
|
183
|
+
</tr>
|
|
184
|
+
<tr>
|
|
185
|
+
<td width="200"><code>mint</code></td>
|
|
186
|
+
<td width="768">Creates a new NFT token and assigns it to a specified destination address.</td>
|
|
187
|
+
</tr>
|
|
188
|
+
<tr>
|
|
189
|
+
<td width="200"><code>transfer</code></td>
|
|
190
|
+
<td width="768">Transfers ownership of a specific NFT token to a destination address.</td>
|
|
191
|
+
</tr>
|
|
192
|
+
</table>
|
|
193
|
+
</details>
|
|
194
|
+
<details>
|
|
195
|
+
<summary><strong>Farcaster</strong></summary>
|
|
196
|
+
<table width="100%">
|
|
197
|
+
<tr>
|
|
198
|
+
<td width="200"><code>account_details</code></td>
|
|
199
|
+
<td width="768">Fetches profile information and metadata for the authenticated Farcaster account.</td>
|
|
200
|
+
</tr>
|
|
201
|
+
<tr>
|
|
202
|
+
<td width="200"><code>post_cast</code></td>
|
|
203
|
+
<td width="768">Creates a new cast (message) on Farcaster with up to 280 characters.</td>
|
|
204
|
+
</tr>
|
|
205
|
+
</table>
|
|
206
|
+
</details>
|
|
207
|
+
<details>
|
|
208
|
+
<summary><strong>Morpho</strong></summary>
|
|
209
|
+
<table width="100%">
|
|
210
|
+
<tr>
|
|
211
|
+
<td width="200"><code>deposit</code></td>
|
|
212
|
+
<td width="768">Deposits a specified amount of assets into a designated Morpho Vault.</td>
|
|
213
|
+
</tr>
|
|
214
|
+
<tr>
|
|
215
|
+
<td width="200"><code>withdraw</code></td>
|
|
216
|
+
<td width="768">Withdraws a specified amount of assets from a designated Morpho Vault.</td>
|
|
217
|
+
</tr>
|
|
218
|
+
</table>
|
|
219
|
+
</details>
|
|
220
|
+
<details>
|
|
221
|
+
<summary><strong>Pyth</strong></summary>
|
|
222
|
+
<table width="100%">
|
|
223
|
+
<tr>
|
|
224
|
+
<td width="200"><code>fetch_price</code></td>
|
|
225
|
+
<td width="768">Retrieves current price data from a specified Pyth price feed.</td>
|
|
226
|
+
</tr>
|
|
227
|
+
<tr>
|
|
228
|
+
<td width="200"><code>fetch_price_feed_id</code></td>
|
|
229
|
+
<td width="768">Retrieves the unique price feed identifier for a given token symbol.</td>
|
|
230
|
+
</tr>
|
|
231
|
+
</table>
|
|
232
|
+
</details>
|
|
233
|
+
<details>
|
|
234
|
+
<summary><strong>Twitter</strong></summary>
|
|
235
|
+
<table width="100%">
|
|
236
|
+
<tr>
|
|
237
|
+
<td width="200"><code>account_details</code></td>
|
|
238
|
+
<td width="768">Fetches profile information and metadata for the authenticated Twitter account.</td>
|
|
239
|
+
</tr>
|
|
240
|
+
<tr>
|
|
241
|
+
<td width="200"><code>account_mentions</code></td>
|
|
242
|
+
<td width="768">Retrieves recent mentions and interactions for the authenticated account.</td>
|
|
243
|
+
</tr>
|
|
244
|
+
<tr>
|
|
245
|
+
<td width="200"><code>post_tweet</code></td>
|
|
246
|
+
<td width="768">Creates a new tweet on the authenticated Twitter account.</td>
|
|
247
|
+
</tr>
|
|
248
|
+
<tr>
|
|
249
|
+
<td width="200"><code>post_tweet_reply</code></td>
|
|
250
|
+
<td width="768">Creates a reply to an existing tweet using the tweet's unique identifier.</td>
|
|
251
|
+
</tr>
|
|
252
|
+
</table>
|
|
253
|
+
</details>
|
|
254
|
+
<details>
|
|
255
|
+
<summary><strong>Wallet</strong></summary>
|
|
256
|
+
<table width="100%">
|
|
257
|
+
<tr>
|
|
258
|
+
<td width="200"><code>get_wallet_details</code></td>
|
|
259
|
+
<td width="768">Retrieves wallet address, network info, balances, and provider details.</td>
|
|
260
|
+
</tr>
|
|
261
|
+
<tr>
|
|
262
|
+
<td width="200"><code>native_transfer</code></td>
|
|
263
|
+
<td width="768">Transfers native blockchain tokens (e.g., ETH) to a destination address.</td>
|
|
264
|
+
</tr>
|
|
265
|
+
</table>
|
|
266
|
+
</details>
|
|
267
|
+
<details>
|
|
268
|
+
<summary><strong>WETH</strong></summary>
|
|
269
|
+
<table width="100%">
|
|
270
|
+
<tr>
|
|
271
|
+
<td width="200"><code>wrap_eth</code></td>
|
|
272
|
+
<td width="768">Converts native ETH to Wrapped ETH (WETH) on Base Sepolia or Base Mainnet.</td>
|
|
273
|
+
</tr>
|
|
274
|
+
</table>
|
|
275
|
+
</details>
|
|
276
|
+
<details>
|
|
277
|
+
<summary><strong>WOW</strong></summary>
|
|
278
|
+
<table width="100%">
|
|
279
|
+
<tr>
|
|
280
|
+
<td width="200"><code>buy_token</code></td>
|
|
281
|
+
<td width="768">Purchases WOW tokens from a contract using ETH based on bonding curve pricing.</td>
|
|
282
|
+
</tr>
|
|
283
|
+
<tr>
|
|
284
|
+
<td width="200"><code>create_token</code></td>
|
|
285
|
+
<td width="768">Creates a new WOW memecoin with bonding curve functionality via Zora factory.</td>
|
|
286
|
+
</tr>
|
|
287
|
+
<tr>
|
|
288
|
+
<td width="200"><code>sell_token</code></td>
|
|
289
|
+
<td width="768">Sells WOW tokens back to the contract for ETH based on bonding curve pricing.</td>
|
|
290
|
+
</tr>
|
|
291
|
+
</table>
|
|
292
|
+
</details>
|
|
293
|
+
|
|
108
294
|
## Creating an Action Provider
|
|
109
295
|
|
|
110
296
|
Action providers are used to define the actions that an agent can take. They are defined as a class that extends the `ActionProvider` abstract class.
|
|
@@ -127,6 +313,21 @@ class MyActionProvider extends ActionProvider<WalletProvider> {
|
|
|
127
313
|
|
|
128
314
|
Actions are defined as instance methods on the action provider class with the `@CreateAction` decorator. Actions can use a wallet provider or not and always return a Promise that resolves to a string.
|
|
129
315
|
|
|
316
|
+
#### Required Typescript Compiler Options
|
|
317
|
+
|
|
318
|
+
Creating actions with the `@CreateAction` decorator requires the following compilerOptions to be included in your project's `tsconfig.json`.
|
|
319
|
+
|
|
320
|
+
```json
|
|
321
|
+
{
|
|
322
|
+
"compilerOptions": {
|
|
323
|
+
"experimentalDecorators": true,
|
|
324
|
+
"emitDecoratorMetadata": true
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
#### Steps to create an action
|
|
330
|
+
|
|
130
331
|
1. Define the action schema. Action schemas are defined using the `zod` library.
|
|
131
332
|
|
|
132
333
|
```typescript
|
|
@@ -197,13 +398,14 @@ const agentKit = new AgentKit({
|
|
|
197
398
|
});
|
|
198
399
|
```
|
|
199
400
|
|
|
200
|
-
## Wallet Providers
|
|
401
|
+
## EVM Wallet Providers
|
|
201
402
|
|
|
202
403
|
Wallet providers give an agent access to a wallet. AgentKit currently supports the following wallet providers:
|
|
203
404
|
|
|
204
405
|
EVM:
|
|
205
|
-
- [CdpWalletProvider](
|
|
206
|
-
- [ViemWalletProvider](
|
|
406
|
+
- [CdpWalletProvider](https://github.com/coinbase/agentkit/blob/main/typescript/agentkit/src/wallet-providers/cdpWalletProvider.ts)
|
|
407
|
+
- [ViemWalletProvider](https://github.com/coinbase/agentkit/blob/main/typescript/agentkit/src/wallet-providers/viemWalletProvider.ts)
|
|
408
|
+
- [PrivyWalletProvider](https://github.com/coinbase/agentkit/blob/main/typescript/agentkit/src/wallet-providers/privyWalletProvider.ts)
|
|
207
409
|
|
|
208
410
|
### CdpWalletProvider
|
|
209
411
|
|
|
@@ -277,6 +479,27 @@ const walletProvider = await CdpWalletProvider.configureWithWallet({
|
|
|
277
479
|
});
|
|
278
480
|
```
|
|
279
481
|
|
|
482
|
+
#### Configuring CdpWalletProvider gas parameters
|
|
483
|
+
|
|
484
|
+
The `CdpWalletProvider` also exposes parameters for effecting the gas calculations.
|
|
485
|
+
|
|
486
|
+
```typescript
|
|
487
|
+
import { CdpWalletProvider } from "@coinbase/agentkit";
|
|
488
|
+
|
|
489
|
+
const walletProvider = await CdpWalletProvider.configureWithWallet({
|
|
490
|
+
cdpWalletData: "WALLET DATA JSON STRING",
|
|
491
|
+
apiKeyName: "CDP API KEY NAME",
|
|
492
|
+
apiKeyPrivate: "CDP API KEY PRIVATE KEY",
|
|
493
|
+
gas: {
|
|
494
|
+
gasLimitMultiplier: 2.0, // Adjusts gas limit estimation
|
|
495
|
+
feePerGasMultiplier: 2.0, // Adjusts max fee per gas
|
|
496
|
+
}
|
|
497
|
+
});
|
|
498
|
+
```
|
|
499
|
+
|
|
500
|
+
**Note**: Gas parameters only impact the `walletProvider.sendTransaction` behavior. Actions that do not rely on direct transaction calls, such as `deploy_token`, `deploy_contract`, and `native_transfer`, remain unaffected.
|
|
501
|
+
|
|
502
|
+
|
|
280
503
|
### ViemWalletProvider
|
|
281
504
|
|
|
282
505
|
The `ViemWalletProvider` is a wallet provider that uses the [Viem library](https://viem.sh/docs/getting-started). It is useful for interacting with any EVM-compatible chain.
|
|
@@ -301,6 +524,116 @@ const client = createWalletClient({
|
|
|
301
524
|
const walletProvider = new ViemWalletProvider(client);
|
|
302
525
|
```
|
|
303
526
|
|
|
527
|
+
#### Configuring ViemWalletProvider gas parameters
|
|
528
|
+
|
|
529
|
+
The `ViemWalletProvider` also exposes parameters for effecting the gas calculations.
|
|
530
|
+
|
|
531
|
+
```typescript
|
|
532
|
+
import { ViemWalletProvider } from "@coinbase/agentkit";
|
|
533
|
+
import { privateKeyToAccount } from "viem/accounts";
|
|
534
|
+
import { baseSepolia } from "viem/chains";
|
|
535
|
+
import { http } from "viem/transports";
|
|
536
|
+
import { createWalletClient } from "viem";
|
|
537
|
+
|
|
538
|
+
const account = privateKeyToAccount(
|
|
539
|
+
"0x4c0883a69102937d6231471b5dbb6208ffd70c02a813d7f2da1c54f2e3be9f38",
|
|
540
|
+
);
|
|
541
|
+
|
|
542
|
+
const client = createWalletClient({
|
|
543
|
+
account,
|
|
544
|
+
chain: baseSepolia,
|
|
545
|
+
transport: http(),
|
|
546
|
+
});
|
|
547
|
+
|
|
548
|
+
const walletProvider = new ViemWalletProvider(client, {
|
|
549
|
+
gasLimitMultiplier: 2.0, // Adjusts gas limit estimation
|
|
550
|
+
feePerGasMultiplier: 2.0, // Adjusts max fee per gas
|
|
551
|
+
});
|
|
552
|
+
```
|
|
553
|
+
|
|
554
|
+
### PrivyWalletProvider
|
|
555
|
+
|
|
556
|
+
The `PrivyWalletProvider` is a wallet provider that uses [Privy Server Wallets](https://docs.privy.io/guide/server-wallets/). This implementation extends the `ViemWalletProvider`.
|
|
557
|
+
|
|
558
|
+
```typescript
|
|
559
|
+
import { PrivyWalletProvider } from "@coinbase/agentkit";
|
|
560
|
+
|
|
561
|
+
// Configure Wallet Provider
|
|
562
|
+
const config = {
|
|
563
|
+
appId: "PRIVY_APP_ID",
|
|
564
|
+
appSecret: "PRIVY_APP_SECRET",
|
|
565
|
+
chainId: "84532", // base-sepolia
|
|
566
|
+
walletId: "PRIVY_WALLET_ID", // optional, otherwise a new wallet will be created
|
|
567
|
+
authorizationPrivateKey: PRIVY_WALLET_AUTHORIZATION_PRIVATE_KEY, // optional, required if your account is using authorization keys
|
|
568
|
+
authorizationKeyId: PRIVY_WALLET_AUTHORIZATION_KEY_ID, // optional, only required to create a new wallet if walletId is not provided
|
|
569
|
+
};
|
|
570
|
+
|
|
571
|
+
const walletProvider = await PrivyWalletProvider.configureWithWallet(config);
|
|
572
|
+
```
|
|
573
|
+
|
|
574
|
+
#### Authorization Keys
|
|
575
|
+
|
|
576
|
+
Privy offers the option to use authorization keys to secure your server wallets.
|
|
577
|
+
|
|
578
|
+
You can manage authorization keys from your [Privy dashboard](https://dashboard.privy.io/account) or programmatically [using the API](https://docs.privy.io/guide/server-wallets/authorization/signatures).
|
|
579
|
+
|
|
580
|
+
When using authorization keys, you must provide the `authorizationPrivateKey` and `authorizationKeyId` parameters to the `configureWithWallet` method if you are creating a new wallet. Please note that when creating a key, if you enable "Create and modify wallets", you will be required to use that key when creating new wallets via the PrivyWalletProvider.
|
|
581
|
+
|
|
582
|
+
#### Exporting Privy Wallet information
|
|
583
|
+
|
|
584
|
+
The `PrivyWalletProvider` can export wallet information by calling the `exportWallet` method.
|
|
585
|
+
|
|
586
|
+
```typescript
|
|
587
|
+
const walletData = await walletProvider.exportWallet();
|
|
588
|
+
|
|
589
|
+
// walletData will be in the following format:
|
|
590
|
+
{
|
|
591
|
+
walletId: string;
|
|
592
|
+
authorizationKey: string | undefined;
|
|
593
|
+
chainId: string | undefined;
|
|
594
|
+
}
|
|
595
|
+
```
|
|
596
|
+
|
|
597
|
+
## SVM Wallet Providers
|
|
598
|
+
|
|
599
|
+
SVM:
|
|
600
|
+
- [SolanaKeypairWalletProvider](https://github.com/coinbase/agentkit/blob/main/typescript/agentkit/src/wallet-providers/solanaKeypairWalletProvider.ts)
|
|
601
|
+
|
|
602
|
+
### SolanaKeypairWalletProvider
|
|
603
|
+
|
|
604
|
+
The `SolanaKeypairWalletProvider` is a wallet provider that uses the API [Solana web3.js](https://solana-labs.github.io/solana-web3.js/).
|
|
605
|
+
|
|
606
|
+
#### Solana Network Configuration
|
|
607
|
+
|
|
608
|
+
The `SolanaKeypairWalletProvider` can be configured to use a specific network by passing the `networkId` parameter to the `fromNetwork` method. The `networkId` is the ID of the Solana network you want to use. Valid values are `solana-mainnet`, `solana-devnet` and `solana-testnet`.
|
|
609
|
+
|
|
610
|
+
The default RPC endpoints for each network are as follows:
|
|
611
|
+
- `solana-mainnet`: `https://api.mainnet-beta.solana.com`
|
|
612
|
+
- `solana-devnet`: `https://api.devnet.solana.com`
|
|
613
|
+
- `solana-testnet`: `https://api.testnet.solana.com`
|
|
614
|
+
|
|
615
|
+
```typescript
|
|
616
|
+
import { SOLANA_NETWORK_ID, SolanaKeypairWalletProvider } from "@coinbase/agentkit";
|
|
617
|
+
|
|
618
|
+
// Configure Solana Keypair Wallet Provider
|
|
619
|
+
const privateKey = process.env.SOLANA_PRIVATE_KEY;
|
|
620
|
+
const network = process.env.NETWORK_ID as SOLANA_NETWORK_ID;
|
|
621
|
+
const walletProvider = await SolanaKeypairWalletProvider.fromNetwork(network, privateKey);
|
|
622
|
+
```
|
|
623
|
+
|
|
624
|
+
#### RPC URL Configuration
|
|
625
|
+
|
|
626
|
+
The `SolanaKeypairWalletProvider` can be configured to use a specific RPC url by passing the `rpcUrl` parameter to the `fromRpcUrl` method. The `rpcUrl` will determine the network you are using.
|
|
627
|
+
|
|
628
|
+
```typescript
|
|
629
|
+
import { SOLANA_NETWORK_ID, SolanaKeypairWalletProvider } from "@coinbase/agentkit";
|
|
630
|
+
|
|
631
|
+
// Configure Solana Keypair Wallet Provider
|
|
632
|
+
const privateKey = process.env.SOLANA_PRIVATE_KEY;
|
|
633
|
+
const rpcUrl = process.env.SOLANA_RPC_URL;
|
|
634
|
+
const walletProvider = await SolanaKeypairWalletProvider.fromRpcUrl(network, privateKey);
|
|
635
|
+
```
|
|
636
|
+
|
|
304
637
|
## Contributing
|
|
305
638
|
|
|
306
639
|
See [CONTRIBUTING.md](../../CONTRIBUTING.md) for more information.
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { ActionProvider } from "../actionProvider";
|
|
3
|
+
import { AlchemyTokenPricesBySymbolSchema, AlchemyTokenPricesByAddressSchema } from "./schemas";
|
|
4
|
+
/**
|
|
5
|
+
* Configuration options for the AlchemyTokenPricesActionProvider.
|
|
6
|
+
*/
|
|
7
|
+
export interface AlchemyTokenPricesActionProviderConfig {
|
|
8
|
+
/**
|
|
9
|
+
* Alchemy API Key
|
|
10
|
+
*/
|
|
11
|
+
apiKey?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* AlchemyTokenPricesActionProvider is an action provider for fetching token prices via the Alchemy Prices API.
|
|
15
|
+
* This provider enables querying current and historical token prices using symbols or addresses.
|
|
16
|
+
*
|
|
17
|
+
*/
|
|
18
|
+
export declare class AlchemyTokenPricesActionProvider extends ActionProvider {
|
|
19
|
+
private readonly apiKey;
|
|
20
|
+
private readonly baseUrl;
|
|
21
|
+
/**
|
|
22
|
+
* Creates a new instance of AlchemyTokenPricesActionProvider
|
|
23
|
+
*
|
|
24
|
+
* @param config - Configuration options including the API key
|
|
25
|
+
*/
|
|
26
|
+
constructor(config?: AlchemyTokenPricesActionProviderConfig);
|
|
27
|
+
/**
|
|
28
|
+
* Fetch current token prices for one or more token symbols.
|
|
29
|
+
*
|
|
30
|
+
* @param args - The arguments containing an array of token symbols.
|
|
31
|
+
* @returns A JSON string with the token prices or an error message.
|
|
32
|
+
*/
|
|
33
|
+
tokenPricesBySymbol(args: z.infer<typeof AlchemyTokenPricesBySymbolSchema>): Promise<string>;
|
|
34
|
+
/**
|
|
35
|
+
* Fetch current token prices for one or more tokens identified by network and address pairs.
|
|
36
|
+
*
|
|
37
|
+
* @param args - The arguments containing an array of token network/address pairs.
|
|
38
|
+
* @returns A JSON string with the token prices or an error message.
|
|
39
|
+
*/
|
|
40
|
+
tokenPricesByAddress(args: z.infer<typeof AlchemyTokenPricesByAddressSchema>): Promise<string>;
|
|
41
|
+
/**
|
|
42
|
+
* Checks if the Alchemy Prices action provider supports the given network.
|
|
43
|
+
* Since the API works with multiple networks, this always returns true.
|
|
44
|
+
*
|
|
45
|
+
* @returns Always returns true.
|
|
46
|
+
*/
|
|
47
|
+
supportsNetwork(): boolean;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Factory function to create a new AlchemyTokenPricesActionProvider instance.
|
|
51
|
+
*
|
|
52
|
+
* @param config - The configuration options for the provider.
|
|
53
|
+
* @returns A new instance of AlchemyTokenPricesActionProvider.
|
|
54
|
+
*/
|
|
55
|
+
export declare const alchemyTokenPricesActionProvider: (config?: AlchemyTokenPricesActionProviderConfig) => AlchemyTokenPricesActionProvider;
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.alchemyTokenPricesActionProvider = exports.AlchemyTokenPricesActionProvider = void 0;
|
|
13
|
+
const zod_1 = require("zod");
|
|
14
|
+
const actionProvider_1 = require("../actionProvider");
|
|
15
|
+
const actionDecorator_1 = require("../actionDecorator");
|
|
16
|
+
const schemas_1 = require("./schemas");
|
|
17
|
+
/**
|
|
18
|
+
* AlchemyTokenPricesActionProvider is an action provider for fetching token prices via the Alchemy Prices API.
|
|
19
|
+
* This provider enables querying current and historical token prices using symbols or addresses.
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
class AlchemyTokenPricesActionProvider extends actionProvider_1.ActionProvider {
|
|
23
|
+
/**
|
|
24
|
+
* Creates a new instance of AlchemyTokenPricesActionProvider
|
|
25
|
+
*
|
|
26
|
+
* @param config - Configuration options including the API key
|
|
27
|
+
*/
|
|
28
|
+
constructor(config = {}) {
|
|
29
|
+
super("alchemyTokenPrices", []);
|
|
30
|
+
config.apiKey || (config.apiKey = process.env.ALCHEMY_API_KEY);
|
|
31
|
+
if (!config.apiKey) {
|
|
32
|
+
throw new Error("ALCHEMY_API_KEY is not configured.");
|
|
33
|
+
}
|
|
34
|
+
this.apiKey = config.apiKey;
|
|
35
|
+
this.baseUrl = "https://api.g.alchemy.com/prices/v1";
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Fetch current token prices for one or more token symbols.
|
|
39
|
+
*
|
|
40
|
+
* @param args - The arguments containing an array of token symbols.
|
|
41
|
+
* @returns A JSON string with the token prices or an error message.
|
|
42
|
+
*/
|
|
43
|
+
async tokenPricesBySymbol(args) {
|
|
44
|
+
try {
|
|
45
|
+
// Build query parameters: for each symbol add a separate query parameter
|
|
46
|
+
const params = new URLSearchParams();
|
|
47
|
+
for (const symbol of args.symbols) {
|
|
48
|
+
params.append("symbols", symbol);
|
|
49
|
+
}
|
|
50
|
+
const url = `${this.baseUrl}/${this.apiKey}/tokens/by-symbol?${params.toString()}`;
|
|
51
|
+
const response = await fetch(url, {
|
|
52
|
+
method: "GET",
|
|
53
|
+
headers: {
|
|
54
|
+
Accept: "application/json",
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
if (!response.ok) {
|
|
58
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
59
|
+
}
|
|
60
|
+
const data = await response.json();
|
|
61
|
+
return `Successfully fetched token prices by symbol:\n${JSON.stringify(data, null, 2)}`;
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
return `Error fetching token prices by symbol: ${error}`;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Fetch current token prices for one or more tokens identified by network and address pairs.
|
|
69
|
+
*
|
|
70
|
+
* @param args - The arguments containing an array of token network/address pairs.
|
|
71
|
+
* @returns A JSON string with the token prices or an error message.
|
|
72
|
+
*/
|
|
73
|
+
async tokenPricesByAddress(args) {
|
|
74
|
+
try {
|
|
75
|
+
const url = `${this.baseUrl}/${this.apiKey}/tokens/by-address`;
|
|
76
|
+
const response = await fetch(url, {
|
|
77
|
+
method: "POST",
|
|
78
|
+
headers: {
|
|
79
|
+
Accept: "application/json",
|
|
80
|
+
"Content-Type": "application/json",
|
|
81
|
+
},
|
|
82
|
+
body: JSON.stringify(args),
|
|
83
|
+
});
|
|
84
|
+
if (!response.ok) {
|
|
85
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
86
|
+
}
|
|
87
|
+
const data = await response.json();
|
|
88
|
+
return `Successfully fetched token prices by address:\n${JSON.stringify(data, null, 2)}`;
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
return `Error fetching token prices by address: ${error}`;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Checks if the Alchemy Prices action provider supports the given network.
|
|
96
|
+
* Since the API works with multiple networks, this always returns true.
|
|
97
|
+
*
|
|
98
|
+
* @returns Always returns true.
|
|
99
|
+
*/
|
|
100
|
+
supportsNetwork() {
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
exports.AlchemyTokenPricesActionProvider = AlchemyTokenPricesActionProvider;
|
|
105
|
+
__decorate([
|
|
106
|
+
(0, actionDecorator_1.CreateAction)({
|
|
107
|
+
name: "token_prices_by_symbol",
|
|
108
|
+
description: `
|
|
109
|
+
This tool will fetch current prices for one or more tokens using their symbols via the Alchemy Prices API.
|
|
110
|
+
|
|
111
|
+
A successful response will return a JSON payload similar to:
|
|
112
|
+
{
|
|
113
|
+
"data": [
|
|
114
|
+
{
|
|
115
|
+
"symbol": "ETH",
|
|
116
|
+
"prices": [
|
|
117
|
+
{
|
|
118
|
+
"currency": "usd",
|
|
119
|
+
"value": "2873.490923459",
|
|
120
|
+
"lastUpdatedAt": "2025-02-03T23:46:40Z"
|
|
121
|
+
}
|
|
122
|
+
]
|
|
123
|
+
}
|
|
124
|
+
]
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
A failure response will return an error message with details.
|
|
128
|
+
`,
|
|
129
|
+
schema: schemas_1.AlchemyTokenPricesBySymbolSchema,
|
|
130
|
+
}),
|
|
131
|
+
__metadata("design:type", Function),
|
|
132
|
+
__metadata("design:paramtypes", [void 0]),
|
|
133
|
+
__metadata("design:returntype", Promise)
|
|
134
|
+
], AlchemyTokenPricesActionProvider.prototype, "tokenPricesBySymbol", null);
|
|
135
|
+
__decorate([
|
|
136
|
+
(0, actionDecorator_1.CreateAction)({
|
|
137
|
+
name: "token_prices_by_address",
|
|
138
|
+
description: `
|
|
139
|
+
This tool will fetch current prices for tokens using network and address pairs via the Alchemy Prices API.
|
|
140
|
+
|
|
141
|
+
A successful response will return a JSON payload similar to:
|
|
142
|
+
{
|
|
143
|
+
"data": [
|
|
144
|
+
{
|
|
145
|
+
"network": "eth-mainnet",
|
|
146
|
+
"address": "0xYourTokenAddress",
|
|
147
|
+
"prices": [
|
|
148
|
+
{
|
|
149
|
+
"currency": "usd",
|
|
150
|
+
"value": "1234.56",
|
|
151
|
+
"lastUpdatedAt": "2025-02-03T23:46:40Z"
|
|
152
|
+
}
|
|
153
|
+
]
|
|
154
|
+
}
|
|
155
|
+
]
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
A failure response will return an error message with details.
|
|
159
|
+
`,
|
|
160
|
+
schema: schemas_1.AlchemyTokenPricesByAddressSchema,
|
|
161
|
+
}),
|
|
162
|
+
__metadata("design:type", Function),
|
|
163
|
+
__metadata("design:paramtypes", [void 0]),
|
|
164
|
+
__metadata("design:returntype", Promise)
|
|
165
|
+
], AlchemyTokenPricesActionProvider.prototype, "tokenPricesByAddress", null);
|
|
166
|
+
/**
|
|
167
|
+
* Factory function to create a new AlchemyTokenPricesActionProvider instance.
|
|
168
|
+
*
|
|
169
|
+
* @param config - The configuration options for the provider.
|
|
170
|
+
* @returns A new instance of AlchemyTokenPricesActionProvider.
|
|
171
|
+
*/
|
|
172
|
+
const alchemyTokenPricesActionProvider = (config) => new AlchemyTokenPricesActionProvider(config);
|
|
173
|
+
exports.alchemyTokenPricesActionProvider = alchemyTokenPricesActionProvider;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|