@coinbase/agentkit 0.3.0 → 0.5.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.
Files changed (83) hide show
  1. package/README.md +90 -7
  2. package/dist/action-providers/across/acrossActionProvider.d.ts +50 -0
  3. package/dist/action-providers/across/acrossActionProvider.js +333 -0
  4. package/dist/action-providers/across/acrossActionProvider.test.d.ts +1 -0
  5. package/dist/action-providers/across/acrossActionProvider.test.js +391 -0
  6. package/dist/action-providers/across/constants.d.ts +1 -0
  7. package/dist/action-providers/across/constants.js +2 -0
  8. package/dist/action-providers/across/index.d.ts +1 -0
  9. package/dist/action-providers/across/index.js +17 -0
  10. package/dist/action-providers/across/schemas.d.ts +36 -0
  11. package/dist/action-providers/across/schemas.js +46 -0
  12. package/dist/action-providers/across/utils.d.ts +7 -0
  13. package/dist/action-providers/across/utils.js +25 -0
  14. package/dist/action-providers/defillama/constants.d.ts +8 -0
  15. package/dist/action-providers/defillama/constants.js +11 -0
  16. package/dist/action-providers/defillama/defillamaActionProvider.d.ts +54 -0
  17. package/dist/action-providers/defillama/defillamaActionProvider.js +180 -0
  18. package/dist/action-providers/defillama/defillamaActionProvider.test.d.ts +1 -0
  19. package/dist/action-providers/defillama/defillamaActionProvider.test.js +114 -0
  20. package/dist/action-providers/defillama/index.d.ts +1 -0
  21. package/dist/action-providers/defillama/index.js +17 -0
  22. package/dist/action-providers/defillama/schemas.d.ts +34 -0
  23. package/dist/action-providers/defillama/schemas.js +34 -0
  24. package/dist/action-providers/defillama/types.d.ts +73 -0
  25. package/dist/action-providers/defillama/types.js +2 -0
  26. package/dist/action-providers/defillama/utils.d.ts +10 -0
  27. package/dist/action-providers/defillama/utils.js +87 -0
  28. package/dist/action-providers/defillama/utils.test.d.ts +1 -0
  29. package/dist/action-providers/defillama/utils.test.js +124 -0
  30. package/dist/action-providers/erc20/constants.d.ts +2 -0
  31. package/dist/action-providers/erc20/constants.js +12 -1
  32. package/dist/action-providers/erc20/erc20ActionProvider.js +18 -0
  33. package/dist/action-providers/erc20/erc20ActionProvider.test.js +4 -0
  34. package/dist/action-providers/index.d.ts +3 -0
  35. package/dist/action-providers/index.js +3 -0
  36. package/dist/action-providers/messari/constants.d.ts +17 -0
  37. package/dist/action-providers/messari/constants.js +20 -0
  38. package/dist/action-providers/messari/index.d.ts +5 -0
  39. package/dist/action-providers/messari/index.js +21 -0
  40. package/dist/action-providers/messari/messariActionProvider.d.ts +42 -0
  41. package/dist/action-providers/messari/messariActionProvider.js +128 -0
  42. package/dist/action-providers/messari/messariActionProvider.test.d.ts +1 -0
  43. package/dist/action-providers/messari/messariActionProvider.test.js +152 -0
  44. package/dist/action-providers/messari/schemas.d.ts +11 -0
  45. package/dist/action-providers/messari/schemas.js +16 -0
  46. package/dist/action-providers/messari/types.d.ts +40 -0
  47. package/dist/action-providers/messari/types.js +2 -0
  48. package/dist/action-providers/messari/utils.d.ts +22 -0
  49. package/dist/action-providers/messari/utils.js +65 -0
  50. package/dist/action-providers/morpho/morphoActionProvider.js +11 -4
  51. package/dist/action-providers/morpho/morphoActionProvider.test.js +2 -0
  52. package/dist/wallet-providers/cdpWalletProvider.d.ts +11 -2
  53. package/dist/wallet-providers/cdpWalletProvider.js +24 -0
  54. package/dist/wallet-providers/cdpWalletProvider.test.d.ts +1 -0
  55. package/dist/wallet-providers/cdpWalletProvider.test.js +701 -0
  56. package/dist/wallet-providers/evmWalletProvider.test.d.ts +1 -0
  57. package/dist/wallet-providers/evmWalletProvider.test.js +56 -0
  58. package/dist/wallet-providers/index.d.ts +1 -0
  59. package/dist/wallet-providers/index.js +1 -0
  60. package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.d.ts +167 -0
  61. package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.js +438 -0
  62. package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.test.d.ts +1 -0
  63. package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.test.js +280 -0
  64. package/dist/wallet-providers/privyEvmWalletProvider.test.d.ts +1 -0
  65. package/dist/wallet-providers/privyEvmWalletProvider.test.js +331 -0
  66. package/dist/wallet-providers/privyShared.d.ts +9 -0
  67. package/dist/wallet-providers/privyShared.js +16 -5
  68. package/dist/wallet-providers/privySvmWalletProvider.test.d.ts +1 -0
  69. package/dist/wallet-providers/privySvmWalletProvider.test.js +310 -0
  70. package/dist/wallet-providers/privyWalletProvider.d.ts +21 -8
  71. package/dist/wallet-providers/privyWalletProvider.js +39 -7
  72. package/dist/wallet-providers/privyWalletProvider.test.d.ts +1 -0
  73. package/dist/wallet-providers/privyWalletProvider.test.js +124 -0
  74. package/dist/wallet-providers/smartWalletProvider.test.d.ts +1 -0
  75. package/dist/wallet-providers/smartWalletProvider.test.js +388 -0
  76. package/dist/wallet-providers/solanaKeypairWalletProvider.test.js +210 -16
  77. package/dist/wallet-providers/svmWalletProvider.test.d.ts +1 -0
  78. package/dist/wallet-providers/svmWalletProvider.test.js +55 -0
  79. package/dist/wallet-providers/viemWalletProvider.test.d.ts +1 -0
  80. package/dist/wallet-providers/viemWalletProvider.test.js +338 -0
  81. package/dist/wallet-providers/walletProvider.test.d.ts +1 -0
  82. package/dist/wallet-providers/walletProvider.test.js +103 -0
  83. package/package.json +24 -20
package/README.md CHANGED
@@ -137,6 +137,19 @@ const agent = createReactAgent({
137
137
 
138
138
  ## Action Providers
139
139
  <details>
140
+ <summary><strong>Across</strong></summary>
141
+ <table width="100%">
142
+ <tr>
143
+ <td width="200"><code>bridge_token</code></td>
144
+ <td width="768">Bridges tokens between supported chains using Across Protocol.</td>
145
+ </tr>
146
+ <tr>
147
+ <td width="200"><code>check_deposit_status</code></td>
148
+ <td width="768">Checks the status of a cross-chain bridge deposit on the Across Protocol (mainnet networks only).</td>
149
+ </tr>
150
+ </table>
151
+ </details>
152
+ <details>
140
153
  <summary><strong>Basename</strong></summary>
141
154
  <table width="100%">
142
155
  <tr>
@@ -192,6 +205,23 @@ const agent = createReactAgent({
192
205
  </table>
193
206
  </details>
194
207
  <details>
208
+ <summary><strong>DefiLlama</strong></summary>
209
+ <table width="100%">
210
+ <tr>
211
+ <td width="200"><code>find_protocol</code></td>
212
+ <td width="768">Searches for DeFi protocols on DefiLlama by name, returning protocol metadata including TVL, chain, and category.</td>
213
+ </tr>
214
+ <tr>
215
+ <td width="200"><code>get_protocol</code></td>
216
+ <td width="768">Fetches detailed information about a specific protocol from DefiLlama, including TVL, description, and historical data.</td>
217
+ </tr>
218
+ <tr>
219
+ <td width="200"><code>get_token_prices</code></td>
220
+ <td width="768">Fetches current token prices from DefiLlama for specified token addresses with chain prefixes.</td>
221
+ </tr>
222
+ </table>
223
+ </details>
224
+ <details>
195
225
  <summary><strong>ERC20</strong></summary>
196
226
  <table width="100%">
197
227
  <tr>
@@ -235,6 +265,15 @@ const agent = createReactAgent({
235
265
  </table>
236
266
  </details>
237
267
  <details>
268
+ <summary><strong>Messari</strong></summary>
269
+ <table width="100%">
270
+ <tr>
271
+ <td width="200"><code>research_question</code></td>
272
+ <td width="768">Queries Messari AI for comprehensive crypto research across news, market data, protocol information, and more.</td>
273
+ </tr>
274
+ </table>
275
+ </details>
276
+ <details>
238
277
  <summary><strong>Morpho</strong></summary>
239
278
  <table width="100%">
240
279
  <tr>
@@ -607,24 +646,61 @@ const walletProvider = new ViemWalletProvider(client, {
607
646
 
608
647
  ### PrivyWalletProvider
609
648
 
610
- The `PrivyWalletProvider` is a wallet provider that uses [Privy Server Wallets](https://docs.privy.io/guide/server-wallets/). This implementation extends the `ViemWalletProvider`.
649
+ The `PrivyWalletProvider` is a wallet provider that uses [Privy Server Wallets](https://docs.privy.io/guide/server-wallets/) or [Privy Embedded Wallets](https://docs.privy.io/guide/embedded-wallets/). This implementation extends the `EvmWalletProvider`.
650
+
651
+ #### Server Wallet Configuration
611
652
 
612
653
  ```typescript
613
- import { PrivyWalletProvider, PrivyWalletConfig } from "@coinbase/agentkit";
654
+ import { PrivyWalletProvider } from "@coinbase/agentkit";
614
655
 
615
- // Configure Wallet Provider
616
- const config: PrivyWalletConfig = {
656
+ // Configure Server Wallet Provider
657
+ const config = {
617
658
  appId: "PRIVY_APP_ID",
618
659
  appSecret: "PRIVY_APP_SECRET",
619
660
  chainId: "84532", // base-sepolia
620
661
  walletId: "PRIVY_WALLET_ID", // optional, otherwise a new wallet will be created
621
- authorizationPrivateKey: PRIVY_WALLET_AUTHORIZATION_PRIVATE_KEY, // optional, required if your account is using authorization keys
622
- authorizationKeyId: PRIVY_WALLET_AUTHORIZATION_KEY_ID, // optional, only required to create a new wallet if walletId is not provided
662
+ authorizationPrivateKey: "PRIVY_WALLET_AUTHORIZATION_PRIVATE_KEY", // optional, required if your account is using authorization keys
663
+ authorizationKeyId: "PRIVY_WALLET_AUTHORIZATION_KEY_ID", // optional, only required to create a new wallet if walletId is not provided
664
+ };
665
+
666
+ const walletProvider = await PrivyWalletProvider.configureWithWallet(config);
667
+ ```
668
+
669
+ #### Delegated Embedded Wallet Configuration
670
+
671
+ You can also use Privy's embedded wallets with delegation for agent actions. This allows your agent to use wallets that have been delegated transaction signing authority by users.
672
+
673
+ ```typescript
674
+ import { PrivyWalletProvider } from "@coinbase/agentkit";
675
+
676
+ // Configure Embedded Wallet Provider
677
+ const config = {
678
+ appId: "PRIVY_APP_ID",
679
+ appSecret: "PRIVY_APP_SECRET",
680
+ authorizationPrivateKey: "PRIVY_WALLET_AUTHORIZATION_PRIVATE_KEY",
681
+ walletId: "PRIVY_DELEGATED_WALLET_ID", // The ID of the wallet that was delegated to your server
682
+ networkId: "base-mainnet", // or any supported network
683
+ walletType: "embedded" // Specify "embedded" to use the embedded wallet provider
623
684
  };
624
685
 
625
686
  const walletProvider = await PrivyWalletProvider.configureWithWallet(config);
626
687
  ```
627
688
 
689
+ ### Prerequisites
690
+
691
+ Before using this wallet provider, you need to:
692
+
693
+ 1. Set up Privy in your application
694
+ 2. Enable server delegated actions
695
+ 3. Have users delegate permissions to your server
696
+ 4. Obtain the delegated wallet ID
697
+
698
+ For more information on setting up Privy and enabling delegated actions, see [Privy's documentation](https://docs.privy.io/guide/embedded/server-delegated-actions).
699
+
700
+ ### Supported Operations
701
+
702
+ The `PrivyEvmDelegatedEmbeddedWalletProvider` supports all standard wallet operations including transaction signing, message signing, and native transfers, using the wallet that was delegated to your server.
703
+
628
704
  #### Authorization Keys
629
705
 
630
706
  Privy offers the option to use authorization keys to secure your server wallets.
@@ -640,12 +716,19 @@ The `PrivyWalletProvider` can export wallet information by calling the `exportWa
640
716
  ```typescript
641
717
  const walletData = await walletProvider.exportWallet();
642
718
 
643
- // walletData will be in the following format:
719
+ // For server wallets, walletData will be in the following format:
644
720
  {
645
721
  walletId: string;
646
722
  authorizationKey: string | undefined;
647
723
  chainId: string | undefined;
648
724
  }
725
+
726
+ // For embedded wallets, walletData will be in the following format:
727
+ {
728
+ walletId: string;
729
+ networkId: string;
730
+ chainId: string | undefined;
731
+ }
649
732
  ```
650
733
 
651
734
  ### SmartWalletProvider
@@ -0,0 +1,50 @@
1
+ import { z } from "zod";
2
+ import { ActionProvider } from "../actionProvider";
3
+ import { Network } from "../../network";
4
+ import { BridgeTokenSchema, CheckDepositStatusSchema } from "./schemas";
5
+ import { EvmWalletProvider } from "../../wallet-providers";
6
+ /**
7
+ * Configuration options for the SafeWalletProvider.
8
+ */
9
+ export interface AcrossActionProviderConfig {
10
+ /**
11
+ * Private key of the wallet provider
12
+ */
13
+ privateKey: string;
14
+ }
15
+ /**
16
+ * AcrossActionProvider provides actions for cross-chain bridging via Across Protocol.
17
+ */
18
+ export declare class AcrossActionProvider extends ActionProvider<EvmWalletProvider> {
19
+ #private;
20
+ /**
21
+ * Constructor for the AcrossActionProvider.
22
+ *
23
+ * @param config - The configuration options for the AcrossActionProvider.
24
+ */
25
+ constructor(config: AcrossActionProviderConfig);
26
+ /**
27
+ * Bridges a token from one chain to another using Across Protocol.
28
+ *
29
+ * @param walletProvider - The wallet provider to use for the transaction.
30
+ * @param args - The input arguments for the action.
31
+ * @returns A message containing the bridge details.
32
+ */
33
+ bridgeToken(walletProvider: EvmWalletProvider, args: z.infer<typeof BridgeTokenSchema>): Promise<string>;
34
+ /**
35
+ * Checks the status of a bridge deposit via Across Protocol.
36
+ *
37
+ * @param walletProvider - The wallet provider to use for the transaction.
38
+ * @param args - The input arguments for the action.
39
+ * @returns A message containing the deposit status details.
40
+ */
41
+ checkDepositStatus(walletProvider: EvmWalletProvider, args: z.infer<typeof CheckDepositStatusSchema>): Promise<string>;
42
+ /**
43
+ * Checks if the Across action provider supports the given network.
44
+ *
45
+ * @param network - The network to check.
46
+ * @returns True if the Across action provider supports the network, false otherwise.
47
+ */
48
+ supportsNetwork: (network: Network) => boolean;
49
+ }
50
+ export declare const acrossActionProvider: (config: AcrossActionProviderConfig) => AcrossActionProvider;
@@ -0,0 +1,333 @@
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
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
12
+ if (kind === "m") throw new TypeError("Private method is not writable");
13
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
14
+ 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");
15
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
16
+ };
17
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
18
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
19
+ 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");
20
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
21
+ };
22
+ var _AcrossActionProvider_privateKey;
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.acrossActionProvider = exports.AcrossActionProvider = void 0;
25
+ const zod_1 = require("zod");
26
+ const viem_1 = require("viem");
27
+ const actionProvider_1 = require("../actionProvider");
28
+ const network_1 = require("../../network");
29
+ const actionDecorator_1 = require("../actionDecorator");
30
+ const schemas_1 = require("./schemas");
31
+ const wallet_providers_1 = require("../../wallet-providers");
32
+ const utils_1 = require("./utils");
33
+ const accounts_1 = require("viem/accounts");
34
+ const constants_1 = require("../erc20/constants");
35
+ /**
36
+ * AcrossActionProvider provides actions for cross-chain bridging via Across Protocol.
37
+ */
38
+ class AcrossActionProvider extends actionProvider_1.ActionProvider {
39
+ /**
40
+ * Constructor for the AcrossActionProvider.
41
+ *
42
+ * @param config - The configuration options for the AcrossActionProvider.
43
+ */
44
+ constructor(config) {
45
+ super("across", []);
46
+ _AcrossActionProvider_privateKey.set(this, void 0);
47
+ /**
48
+ * Checks if the Across action provider supports the given network.
49
+ *
50
+ * @param network - The network to check.
51
+ * @returns True if the Across action provider supports the network, false otherwise.
52
+ */
53
+ this.supportsNetwork = (network) => {
54
+ // Across only supports EVM-compatible chains
55
+ return network.protocolFamily === "evm";
56
+ };
57
+ __classPrivateFieldSet(this, _AcrossActionProvider_privateKey, config.privateKey, "f");
58
+ const account = (0, accounts_1.privateKeyToAccount)(__classPrivateFieldGet(this, _AcrossActionProvider_privateKey, "f"));
59
+ if (!account)
60
+ throw new Error("Invalid private key");
61
+ }
62
+ /**
63
+ * Bridges a token from one chain to another using Across Protocol.
64
+ *
65
+ * @param walletProvider - The wallet provider to use for the transaction.
66
+ * @param args - The input arguments for the action.
67
+ * @returns A message containing the bridge details.
68
+ */
69
+ async bridgeToken(walletProvider, args) {
70
+ try {
71
+ // Use dynamic import to get the Across SDK
72
+ const acrossModule = await import("@across-protocol/app-sdk");
73
+ const createAcrossClient = acrossModule.createAcrossClient;
74
+ // Get recipient address if provided, otherwise use sender
75
+ const address = walletProvider.getAddress();
76
+ const recipient = (args.recipient || address);
77
+ // Get origin chain
78
+ const originChain = (0, network_1.getChain)(walletProvider.getNetwork().chainId);
79
+ if (!originChain) {
80
+ throw new Error(`Unsupported origin chain: ${walletProvider.getNetwork()}`);
81
+ }
82
+ // Get destination chain
83
+ const destinationNetworkId = network_1.CHAIN_ID_TO_NETWORK_ID[Number(args.destinationChainId)];
84
+ const destinationChain = network_1.NETWORK_ID_TO_VIEM_CHAIN[destinationNetworkId];
85
+ if (!destinationChain) {
86
+ throw new Error(`Unsupported destination chain: ${args.destinationChainId}`);
87
+ }
88
+ // Sanity checks
89
+ if (originChain.id === destinationChain.id) {
90
+ throw new Error("Origin and destination chains cannot be the same");
91
+ }
92
+ const useTestnet = (0, utils_1.isAcrossSupportedTestnet)(originChain.id);
93
+ if (useTestnet !== (0, utils_1.isAcrossSupportedTestnet)(destinationChain.id)) {
94
+ throw new Error(`Cross-chain transfers between ${originChain.name} and ${destinationChain.name} are not supported.
95
+ Origin and destination chains must either be both testnets or both mainnets.`);
96
+ }
97
+ // Create wallet client
98
+ const account = (0, accounts_1.privateKeyToAccount)(__classPrivateFieldGet(this, _AcrossActionProvider_privateKey, "f"));
99
+ if (account.address !== walletProvider.getAddress()) {
100
+ throw new Error("Private key does not match wallet provider address");
101
+ }
102
+ const walletClient = (0, viem_1.createWalletClient)({
103
+ account,
104
+ chain: originChain,
105
+ transport: (0, viem_1.http)(),
106
+ });
107
+ // Create Across client
108
+ const acrossClient = createAcrossClient({
109
+ chains: [originChain, destinationChain],
110
+ useTestnet,
111
+ });
112
+ // Get chain details to find token information
113
+ const chainDetails = await acrossClient.getSupportedChains({});
114
+ const originChainDetails = chainDetails.find(chain => chain.chainId === originChain.id);
115
+ if (!originChainDetails) {
116
+ throw new Error(`Origin chain ${originChain.id} not supported by Across Protocol`);
117
+ }
118
+ // Find token by symbol on the origin chain
119
+ const inputTokens = originChainDetails.inputTokens;
120
+ if (!inputTokens || inputTokens.length === 0) {
121
+ throw new Error(`No input tokens available on chain ${originChain.id}`);
122
+ }
123
+ const tokenInfo = inputTokens.find(token => token.symbol.toUpperCase() === args.inputTokenSymbol.toUpperCase());
124
+ if (!tokenInfo) {
125
+ throw new Error(`Token ${args.inputTokenSymbol} not found on chain ${originChain.id}. Available tokens: ${inputTokens.map(t => t.symbol).join(", ")}`);
126
+ }
127
+ // Get token address and decimals to parse the amount
128
+ const inputToken = tokenInfo.address;
129
+ const decimals = tokenInfo.decimals;
130
+ const inputAmount = (0, viem_1.parseUnits)(args.amount, decimals);
131
+ // Check balance
132
+ const isNative = args.inputTokenSymbol.toUpperCase() === "ETH";
133
+ if (isNative) {
134
+ // Check native ETH balance
135
+ const ethBalance = await walletProvider.getBalance();
136
+ if (ethBalance < inputAmount) {
137
+ throw new Error(`Insufficient balance. Requested to bridge ${(0, viem_1.formatUnits)(inputAmount, decimals)} ${args.inputTokenSymbol} but balance is only ${(0, viem_1.formatUnits)(ethBalance, decimals)} ${args.inputTokenSymbol}`);
138
+ }
139
+ }
140
+ else {
141
+ // Check ERC20 token balance
142
+ const tokenBalance = (await walletProvider.readContract({
143
+ address: inputToken,
144
+ abi: constants_1.abi,
145
+ functionName: "balanceOf",
146
+ args: [address],
147
+ }));
148
+ if (tokenBalance < inputAmount) {
149
+ throw new Error(`Insufficient balance. Requested to bridge ${(0, viem_1.formatUnits)(inputAmount, decimals)} ${args.inputTokenSymbol} but balance is only ${(0, viem_1.formatUnits)(tokenBalance, decimals)} ${args.inputTokenSymbol}`);
150
+ }
151
+ }
152
+ // Get available routes
153
+ const routeInfo = await acrossClient.getAvailableRoutes({
154
+ originChainId: originChain.id,
155
+ destinationChainId: destinationChain.id,
156
+ originToken: inputToken,
157
+ });
158
+ // Select the appropriate route for native ETH or ERC20 token
159
+ const route = routeInfo.find(route => route.isNative === isNative);
160
+ if (!route) {
161
+ throw new Error(`No routes available from chain ${originChain.name} to chain ${destinationChain.name} for token ${args.inputTokenSymbol}`);
162
+ }
163
+ // Get quote
164
+ const quote = await acrossClient.getQuote({
165
+ route,
166
+ inputAmount,
167
+ recipient,
168
+ });
169
+ // Convert units to readable format
170
+ const formattedInfo = {
171
+ minDeposit: (0, viem_1.formatUnits)(quote.limits.minDeposit, decimals),
172
+ maxDeposit: (0, viem_1.formatUnits)(quote.limits.maxDeposit, decimals),
173
+ inputAmount: (0, viem_1.formatUnits)(quote.deposit.inputAmount, decimals),
174
+ outputAmount: (0, viem_1.formatUnits)(quote.deposit.outputAmount, decimals),
175
+ };
176
+ // Check if input amount is within valid deposit range
177
+ if (quote.deposit.inputAmount < quote.limits.minDeposit) {
178
+ throw new Error(`Input amount ${formattedInfo.inputAmount} ${args.inputTokenSymbol} is below the minimum deposit of ${formattedInfo.minDeposit} ${args.inputTokenSymbol}`);
179
+ }
180
+ if (quote.deposit.inputAmount > quote.limits.maxDeposit) {
181
+ throw new Error(`Input amount ${formattedInfo.inputAmount} ${args.inputTokenSymbol} exceeds the maximum deposit of ${formattedInfo.maxDeposit} ${args.inputTokenSymbol}`);
182
+ }
183
+ // Check if output amount is within acceptable slippage limits
184
+ const actualSlippagePercentage = ((Number(formattedInfo.inputAmount) - Number(formattedInfo.outputAmount)) /
185
+ Number(formattedInfo.inputAmount)) *
186
+ 100;
187
+ if (actualSlippagePercentage > args.maxSplippage) {
188
+ throw new Error(`Output amount has high slippage of ${actualSlippagePercentage.toFixed(2)}%, which exceeds the maximum allowed slippage of ${args.maxSplippage}%. ` +
189
+ `Input: ${formattedInfo.inputAmount} ${args.inputTokenSymbol}, Output: ${formattedInfo.outputAmount} ${args.inputTokenSymbol}`);
190
+ }
191
+ //Approve ERC20 token if needed
192
+ let approvalTxHash;
193
+ if (!isNative) {
194
+ approvalTxHash = await walletProvider.sendTransaction({
195
+ to: inputToken,
196
+ data: (0, viem_1.encodeFunctionData)({
197
+ abi: constants_1.abi,
198
+ functionName: "approve",
199
+ args: [quote.deposit.spokePoolAddress, quote.deposit.inputAmount],
200
+ }),
201
+ });
202
+ await walletProvider.waitForTransactionReceipt(approvalTxHash);
203
+ }
204
+ // Simulate the deposit transaction
205
+ const { request } = await acrossClient.simulateDepositTx({
206
+ walletClient: walletClient,
207
+ deposit: quote.deposit,
208
+ });
209
+ // Execute the deposit transaction
210
+ const transactionHash = await walletClient.writeContract(request);
211
+ // Wait for tx to be mined
212
+ const { depositId } = await acrossClient.waitForDepositTx({
213
+ transactionHash,
214
+ originChainId: originChain.id,
215
+ });
216
+ return `
217
+ Successfully deposited tokens:
218
+ - From: Chain ${originChain.id} (${originChain.name})
219
+ - To: Chain ${destinationChain.id} (${destinationChain.name})
220
+ - Token: ${args.inputTokenSymbol} (${inputToken})
221
+ - Input Amount: ${formattedInfo.inputAmount} ${args.inputTokenSymbol}
222
+ - Output Amount: ${formattedInfo.outputAmount} ${args.inputTokenSymbol}
223
+ - Recipient: ${recipient}
224
+ ${!isNative ? `- Transaction Hash for approval: ${approvalTxHash}\n` : ""}
225
+ - Transaction Hash for deposit: ${transactionHash}
226
+ - Deposit ID: ${depositId}
227
+ `;
228
+ }
229
+ catch (error) {
230
+ return `Error with Across SDK: ${error}`;
231
+ }
232
+ }
233
+ /**
234
+ * Checks the status of a bridge deposit via Across Protocol.
235
+ *
236
+ * @param walletProvider - The wallet provider to use for the transaction.
237
+ * @param args - The input arguments for the action.
238
+ * @returns A message containing the deposit status details.
239
+ */
240
+ async checkDepositStatus(walletProvider, args) {
241
+ const originChainId = Number(args.originChainId) || Number(walletProvider.getNetwork().chainId);
242
+ if ((0, utils_1.isAcrossSupportedTestnet)(originChainId)) {
243
+ throw new Error("Checking deposit status on testnets is currently not supported by the Across API");
244
+ }
245
+ try {
246
+ const response = await fetch(`https://app.across.to/api/deposit/status?originChainId=${originChainId}&depositId=${args.depositId}`, {
247
+ method: "GET",
248
+ });
249
+ if (!response.ok) {
250
+ throw new Error(`Across API request failed with status ${response.status}`);
251
+ }
252
+ const apiData = await response.json();
253
+ // Get chain names
254
+ const originChainName = (0, network_1.getChain)(String(apiData.originChainId))?.name || "Unknown Chain";
255
+ const destinationChainName = (0, network_1.getChain)(String(apiData.destinationChainId))?.name || "Unknown Chain";
256
+ // Create structured response
257
+ const structuredResponse = {
258
+ status: apiData.status || "unknown",
259
+ depositTxInfo: apiData.depositTxHash
260
+ ? {
261
+ txHash: apiData.depositTxHash,
262
+ chainId: apiData.originChainId,
263
+ chainName: originChainName,
264
+ }
265
+ : null,
266
+ fillTxInfo: apiData.fillTx
267
+ ? {
268
+ txHash: apiData.fillTx,
269
+ chainId: apiData.destinationChainId,
270
+ chainName: destinationChainName,
271
+ }
272
+ : null,
273
+ depositRefundTxInfo: apiData.depositRefundTxHash
274
+ ? {
275
+ txHash: apiData.depositRefundTxHash,
276
+ chainId: apiData.originChainId,
277
+ chainName: originChainName,
278
+ }
279
+ : null,
280
+ };
281
+ return JSON.stringify(structuredResponse, null, 2);
282
+ }
283
+ catch (error) {
284
+ return `Error checking deposit status: ${error}`;
285
+ }
286
+ }
287
+ }
288
+ exports.AcrossActionProvider = AcrossActionProvider;
289
+ _AcrossActionProvider_privateKey = new WeakMap();
290
+ __decorate([
291
+ (0, actionDecorator_1.CreateAction)({
292
+ name: "bridge_token",
293
+ description: `
294
+ This tool will bridge tokens from the current chain to another chain using the Across Protocol.
295
+
296
+ It takes the following inputs:
297
+ - destinationChainId: The chain ID of the destination chain (e.g. 8453 for base-mainnet)
298
+ - inputTokenSymbol: The symbol of the token to bridge (e.g. 'ETH', 'USDC')
299
+ - amount: The amount of tokens to bridge in whole units (e.g. 1.5 WETH, 10 USDC)
300
+ - recipient: (Optional) The recipient address on the destination chain (defaults to sender)
301
+ - maxSplippage: (Optional) The maximum slippage percentage (defaults to 1.5%)
302
+
303
+ Important notes:
304
+ - Origin chain is the currently connected chain of the wallet provider
305
+ - Supports cross-chain transfers between EVM-compatible chains for both mainnets and test networks
306
+ - Testnet deposits are not refunded if not filled on destination chain
307
+ - Ensure sufficient balance of the input token before bridging
308
+ - Returns deposit ID that can be used to check the status of the deposit
309
+ `,
310
+ schema: schemas_1.BridgeTokenSchema,
311
+ }),
312
+ __metadata("design:type", Function),
313
+ __metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider, void 0]),
314
+ __metadata("design:returntype", Promise)
315
+ ], AcrossActionProvider.prototype, "bridgeToken", null);
316
+ __decorate([
317
+ (0, actionDecorator_1.CreateAction)({
318
+ name: "check_deposit_status",
319
+ description: `
320
+ This tool will check the status of a cross-chain bridge deposit on the Across Protocol.
321
+
322
+ It takes the following inputs:
323
+ - originChainId: The chain ID of the origin chain (defaults to the current chain)
324
+ - depositId: The ID of the deposit to check (returned by the bridge deposit transaction)
325
+ `,
326
+ schema: schemas_1.CheckDepositStatusSchema,
327
+ }),
328
+ __metadata("design:type", Function),
329
+ __metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider, void 0]),
330
+ __metadata("design:returntype", Promise)
331
+ ], AcrossActionProvider.prototype, "checkDepositStatus", null);
332
+ const acrossActionProvider = (config) => new AcrossActionProvider(config);
333
+ exports.acrossActionProvider = acrossActionProvider;