@coinbase/agentkit 0.4.0 → 0.6.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 +103 -7
- package/dist/action-providers/across/acrossActionProvider.d.ts +50 -0
- package/dist/action-providers/across/acrossActionProvider.js +333 -0
- package/dist/action-providers/across/acrossActionProvider.test.d.ts +1 -0
- package/dist/action-providers/across/acrossActionProvider.test.js +391 -0
- package/dist/action-providers/across/constants.d.ts +1 -0
- package/dist/action-providers/across/constants.js +2 -0
- package/dist/action-providers/across/index.d.ts +1 -0
- package/dist/action-providers/across/index.js +17 -0
- package/dist/action-providers/across/schemas.d.ts +36 -0
- package/dist/action-providers/across/schemas.js +46 -0
- package/dist/action-providers/across/utils.d.ts +7 -0
- package/dist/action-providers/across/utils.js +25 -0
- package/dist/action-providers/erc20/constants.d.ts +2 -0
- package/dist/action-providers/erc20/constants.js +12 -1
- package/dist/action-providers/erc20/erc20ActionProvider.js +18 -0
- package/dist/action-providers/erc20/erc20ActionProvider.test.js +4 -0
- package/dist/action-providers/flaunch/constants.d.ts +1078 -0
- package/dist/action-providers/flaunch/constants.js +709 -0
- package/dist/action-providers/flaunch/flaunchActionProvider.d.ts +102 -0
- package/dist/action-providers/flaunch/flaunchActionProvider.js +519 -0
- package/dist/action-providers/flaunch/flaunchActionProvider.test.d.ts +1 -0
- package/dist/action-providers/flaunch/flaunchActionProvider.test.js +307 -0
- package/dist/action-providers/flaunch/index.d.ts +7 -0
- package/dist/action-providers/flaunch/index.js +23 -0
- package/dist/action-providers/flaunch/schemas.d.ts +77 -0
- package/dist/action-providers/flaunch/schemas.js +71 -0
- package/dist/action-providers/flaunch/types.d.ts +64 -0
- package/dist/action-providers/flaunch/types.js +2 -0
- package/dist/action-providers/flaunch/utils.d.ts +60 -0
- package/dist/action-providers/flaunch/utils.js +507 -0
- package/dist/action-providers/index.d.ts +4 -0
- package/dist/action-providers/index.js +4 -0
- package/dist/action-providers/messari/constants.d.ts +17 -0
- package/dist/action-providers/messari/constants.js +20 -0
- package/dist/action-providers/messari/index.d.ts +5 -0
- package/dist/action-providers/messari/index.js +21 -0
- package/dist/action-providers/messari/messariActionProvider.d.ts +42 -0
- package/dist/action-providers/messari/messariActionProvider.js +128 -0
- package/dist/action-providers/messari/messariActionProvider.test.d.ts +1 -0
- package/dist/action-providers/messari/messariActionProvider.test.js +152 -0
- package/dist/action-providers/messari/schemas.d.ts +11 -0
- package/dist/action-providers/messari/schemas.js +16 -0
- package/dist/action-providers/messari/types.d.ts +40 -0
- package/dist/action-providers/messari/types.js +2 -0
- package/dist/action-providers/messari/utils.d.ts +22 -0
- package/dist/action-providers/messari/utils.js +65 -0
- package/dist/action-providers/onramp/index.d.ts +7 -0
- package/dist/action-providers/onramp/index.js +23 -0
- package/dist/action-providers/onramp/onrampActionProvider.d.ts +56 -0
- package/dist/action-providers/onramp/onrampActionProvider.js +109 -0
- package/dist/action-providers/onramp/onrampActionProvider.test.d.ts +1 -0
- package/dist/action-providers/onramp/onrampActionProvider.test.js +97 -0
- package/dist/action-providers/onramp/schemas.d.ts +12 -0
- package/dist/action-providers/onramp/schemas.js +15 -0
- package/dist/action-providers/onramp/types.d.ts +107 -0
- package/dist/action-providers/onramp/types.js +2 -0
- package/dist/action-providers/onramp/utils.d.ts +16 -0
- package/dist/action-providers/onramp/utils.js +56 -0
- package/dist/action-providers/onramp/version.d.ts +2 -0
- package/dist/action-providers/onramp/version.js +5 -0
- package/dist/wallet-providers/cdpWalletProvider.d.ts +11 -2
- package/dist/wallet-providers/cdpWalletProvider.js +44 -10
- package/dist/wallet-providers/cdpWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/cdpWalletProvider.test.js +735 -0
- package/dist/wallet-providers/evmWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/evmWalletProvider.test.js +56 -0
- package/dist/wallet-providers/index.d.ts +1 -0
- package/dist/wallet-providers/index.js +1 -0
- package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.d.ts +167 -0
- package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.js +438 -0
- package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.test.js +280 -0
- package/dist/wallet-providers/privyEvmWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/privyEvmWalletProvider.test.js +331 -0
- package/dist/wallet-providers/privyShared.d.ts +9 -0
- package/dist/wallet-providers/privyShared.js +16 -5
- package/dist/wallet-providers/privySvmWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/privySvmWalletProvider.test.js +310 -0
- package/dist/wallet-providers/privyWalletProvider.d.ts +21 -8
- package/dist/wallet-providers/privyWalletProvider.js +39 -7
- package/dist/wallet-providers/privyWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/privyWalletProvider.test.js +124 -0
- package/dist/wallet-providers/smartWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/smartWalletProvider.test.js +388 -0
- package/dist/wallet-providers/solanaKeypairWalletProvider.test.js +210 -16
- package/dist/wallet-providers/svmWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/svmWalletProvider.test.js +55 -0
- package/dist/wallet-providers/viemWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/viemWalletProvider.test.js +338 -0
- package/dist/wallet-providers/walletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/walletProvider.test.js +103 -0
- package/package.json +26 -21
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>
|
|
@@ -252,6 +265,36 @@ const agent = createReactAgent({
|
|
|
252
265
|
</table>
|
|
253
266
|
</details>
|
|
254
267
|
<details>
|
|
268
|
+
<summary><strong>Flaunch</strong></summary>
|
|
269
|
+
<table width="100%">
|
|
270
|
+
<tr>
|
|
271
|
+
<td width="200"><code>flaunch</code></td>
|
|
272
|
+
<td width="768">Launches a new memecoin token with customizable name, symbol, image, and metadata.</td>
|
|
273
|
+
</tr>
|
|
274
|
+
<tr>
|
|
275
|
+
<td width="200"><code>buyCoinWithETHInput</code></td>
|
|
276
|
+
<td width="768">Purchases Flaunch memecoin tokens by specifying ETH input amount with configurable slippage.</td>
|
|
277
|
+
</tr>
|
|
278
|
+
<tr>
|
|
279
|
+
<td width="200"><code>buyCoinWithCoinInput</code></td>
|
|
280
|
+
<td width="768">Purchases Flaunch memecoin tokens by specifying desired token output amount with configurable slippage.</td>
|
|
281
|
+
</tr>
|
|
282
|
+
<tr>
|
|
283
|
+
<td width="200"><code>sellCoin</code></td>
|
|
284
|
+
<td width="768">Sells Flaunch memecoin tokens back to ETH with configurable slippage.</td>
|
|
285
|
+
</tr>
|
|
286
|
+
</table>
|
|
287
|
+
</details>
|
|
288
|
+
<details>
|
|
289
|
+
<summary><strong>Messari</strong></summary>
|
|
290
|
+
<table width="100%">
|
|
291
|
+
<tr>
|
|
292
|
+
<td width="200"><code>research_question</code></td>
|
|
293
|
+
<td width="768">Queries Messari AI for comprehensive crypto research across news, market data, protocol information, and more.</td>
|
|
294
|
+
</tr>
|
|
295
|
+
</table>
|
|
296
|
+
</details>
|
|
297
|
+
<details>
|
|
255
298
|
<summary><strong>Morpho</strong></summary>
|
|
256
299
|
<table width="100%">
|
|
257
300
|
<tr>
|
|
@@ -265,6 +308,15 @@ const agent = createReactAgent({
|
|
|
265
308
|
</table>
|
|
266
309
|
</details>
|
|
267
310
|
<details>
|
|
311
|
+
<summary><strong>Onramp</strong></summary>
|
|
312
|
+
<table width="100%">
|
|
313
|
+
<tr>
|
|
314
|
+
<td width="200"><code>get_onramp_buy_url</code></td>
|
|
315
|
+
<td width="768">Gets a URL to purchase cryptocurrency from Coinbase via Debit card or other payment methods.</td>
|
|
316
|
+
</tr>
|
|
317
|
+
</table>
|
|
318
|
+
</details>
|
|
319
|
+
<details>
|
|
268
320
|
<summary><strong>Opensea</strong></summary>
|
|
269
321
|
<table width="100%">
|
|
270
322
|
<tr>
|
|
@@ -624,24 +676,61 @@ const walletProvider = new ViemWalletProvider(client, {
|
|
|
624
676
|
|
|
625
677
|
### PrivyWalletProvider
|
|
626
678
|
|
|
627
|
-
The `PrivyWalletProvider` is a wallet provider that uses [Privy Server Wallets](https://docs.privy.io/guide/server-wallets/). This implementation extends the `
|
|
679
|
+
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`.
|
|
680
|
+
|
|
681
|
+
#### Server Wallet Configuration
|
|
628
682
|
|
|
629
683
|
```typescript
|
|
630
|
-
import { PrivyWalletProvider
|
|
684
|
+
import { PrivyWalletProvider } from "@coinbase/agentkit";
|
|
631
685
|
|
|
632
|
-
// Configure Wallet Provider
|
|
633
|
-
const config
|
|
686
|
+
// Configure Server Wallet Provider
|
|
687
|
+
const config = {
|
|
634
688
|
appId: "PRIVY_APP_ID",
|
|
635
689
|
appSecret: "PRIVY_APP_SECRET",
|
|
636
690
|
chainId: "84532", // base-sepolia
|
|
637
691
|
walletId: "PRIVY_WALLET_ID", // optional, otherwise a new wallet will be created
|
|
638
|
-
authorizationPrivateKey: PRIVY_WALLET_AUTHORIZATION_PRIVATE_KEY, // optional, required if your account is using authorization keys
|
|
639
|
-
authorizationKeyId: PRIVY_WALLET_AUTHORIZATION_KEY_ID, // optional, only required to create a new wallet if walletId is not provided
|
|
692
|
+
authorizationPrivateKey: "PRIVY_WALLET_AUTHORIZATION_PRIVATE_KEY", // optional, required if your account is using authorization keys
|
|
693
|
+
authorizationKeyId: "PRIVY_WALLET_AUTHORIZATION_KEY_ID", // optional, only required to create a new wallet if walletId is not provided
|
|
694
|
+
};
|
|
695
|
+
|
|
696
|
+
const walletProvider = await PrivyWalletProvider.configureWithWallet(config);
|
|
697
|
+
```
|
|
698
|
+
|
|
699
|
+
#### Delegated Embedded Wallet Configuration
|
|
700
|
+
|
|
701
|
+
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.
|
|
702
|
+
|
|
703
|
+
```typescript
|
|
704
|
+
import { PrivyWalletProvider } from "@coinbase/agentkit";
|
|
705
|
+
|
|
706
|
+
// Configure Embedded Wallet Provider
|
|
707
|
+
const config = {
|
|
708
|
+
appId: "PRIVY_APP_ID",
|
|
709
|
+
appSecret: "PRIVY_APP_SECRET",
|
|
710
|
+
authorizationPrivateKey: "PRIVY_WALLET_AUTHORIZATION_PRIVATE_KEY",
|
|
711
|
+
walletId: "PRIVY_DELEGATED_WALLET_ID", // The ID of the wallet that was delegated to your server
|
|
712
|
+
networkId: "base-mainnet", // or any supported network
|
|
713
|
+
walletType: "embedded" // Specify "embedded" to use the embedded wallet provider
|
|
640
714
|
};
|
|
641
715
|
|
|
642
716
|
const walletProvider = await PrivyWalletProvider.configureWithWallet(config);
|
|
643
717
|
```
|
|
644
718
|
|
|
719
|
+
### Prerequisites
|
|
720
|
+
|
|
721
|
+
Before using this wallet provider, you need to:
|
|
722
|
+
|
|
723
|
+
1. Set up Privy in your application
|
|
724
|
+
2. Enable server delegated actions
|
|
725
|
+
3. Have users delegate permissions to your server
|
|
726
|
+
4. Obtain the delegated wallet ID
|
|
727
|
+
|
|
728
|
+
For more information on setting up Privy and enabling delegated actions, see [Privy's documentation](https://docs.privy.io/guide/embedded/server-delegated-actions).
|
|
729
|
+
|
|
730
|
+
### Supported Operations
|
|
731
|
+
|
|
732
|
+
The `PrivyEvmDelegatedEmbeddedWalletProvider` supports all standard wallet operations including transaction signing, message signing, and native transfers, using the wallet that was delegated to your server.
|
|
733
|
+
|
|
645
734
|
#### Authorization Keys
|
|
646
735
|
|
|
647
736
|
Privy offers the option to use authorization keys to secure your server wallets.
|
|
@@ -657,12 +746,19 @@ The `PrivyWalletProvider` can export wallet information by calling the `exportWa
|
|
|
657
746
|
```typescript
|
|
658
747
|
const walletData = await walletProvider.exportWallet();
|
|
659
748
|
|
|
660
|
-
// walletData will be in the following format:
|
|
749
|
+
// For server wallets, walletData will be in the following format:
|
|
661
750
|
{
|
|
662
751
|
walletId: string;
|
|
663
752
|
authorizationKey: string | undefined;
|
|
664
753
|
chainId: string | undefined;
|
|
665
754
|
}
|
|
755
|
+
|
|
756
|
+
// For embedded wallets, walletData will be in the following format:
|
|
757
|
+
{
|
|
758
|
+
walletId: string;
|
|
759
|
+
networkId: string;
|
|
760
|
+
chainId: string | undefined;
|
|
761
|
+
}
|
|
666
762
|
```
|
|
667
763
|
|
|
668
764
|
### 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;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|