@coinbase/agentkit 0.10.3 → 0.10.4
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 +47 -10
- package/dist/action-providers/across/acrossActionProvider.js +2 -4
- package/dist/action-providers/across/acrossActionProvider.test.js +10 -5
- package/dist/action-providers/baseAccount/baseAccountActionProvider.js +5 -7
- package/dist/action-providers/clanker/utils.d.ts +2 -1
- package/dist/action-providers/clanker/utils.js +2 -2
- package/dist/action-providers/index.d.ts +1 -0
- package/dist/action-providers/index.js +1 -0
- package/dist/action-providers/jupiter/jupiterActionProvider.js +2 -2
- package/dist/action-providers/spl/splActionProvider.js +12 -13
- package/dist/action-providers/superfluid/graphQueries/superfluidGraphQueries.js +2 -2
- package/dist/action-providers/sushi/constants.d.ts +35 -0
- package/dist/action-providers/sushi/constants.js +7 -0
- package/dist/action-providers/sushi/index.d.ts +4 -0
- package/dist/action-providers/sushi/index.js +20 -0
- package/dist/action-providers/sushi/sushiDataActionProvider.d.ts +32 -0
- package/dist/action-providers/sushi/sushiDataActionProvider.js +113 -0
- package/dist/action-providers/sushi/sushiDataSchemas.d.ts +11 -0
- package/dist/action-providers/sushi/sushiDataSchemas.js +16 -0
- package/dist/action-providers/sushi/sushiRouterActionProvider.d.ts +40 -0
- package/dist/action-providers/sushi/sushiRouterActionProvider.js +386 -0
- package/dist/action-providers/sushi/sushiRouterActionProvider.test.d.ts +1 -0
- package/dist/action-providers/sushi/sushiRouterActionProvider.test.js +392 -0
- package/dist/action-providers/sushi/sushiRouterSchemas.d.ts +36 -0
- package/dist/action-providers/sushi/sushiRouterSchemas.js +55 -0
- package/dist/action-providers/vaultsfyi/constants.d.ts +8 -12
- package/dist/action-providers/vaultsfyi/constants.js +47 -13
- package/dist/action-providers/vaultsfyi/schemas.d.ts +120 -65
- package/dist/action-providers/vaultsfyi/schemas.js +72 -38
- package/dist/action-providers/vaultsfyi/sdk.d.ts +8 -0
- package/dist/action-providers/vaultsfyi/sdk.js +15 -0
- package/dist/action-providers/vaultsfyi/utils.d.ts +151 -55
- package/dist/action-providers/vaultsfyi/utils.js +29 -75
- package/dist/action-providers/vaultsfyi/vaultsfyiActionProvider.d.ts +55 -16
- package/dist/action-providers/vaultsfyi/vaultsfyiActionProvider.js +413 -217
- package/dist/action-providers/vaultsfyi/vaultsfyiActionProvider.test.js +509 -316
- package/dist/action-providers/x402/constants.d.ts +67 -0
- package/dist/action-providers/x402/constants.js +37 -0
- package/dist/action-providers/x402/schemas.d.ts +45 -5
- package/dist/action-providers/x402/schemas.js +81 -11
- package/dist/action-providers/x402/utils.d.ts +85 -10
- package/dist/action-providers/x402/utils.js +302 -35
- package/dist/action-providers/x402/x402ActionProvider.d.ts +15 -1
- package/dist/action-providers/x402/x402ActionProvider.js +230 -179
- package/dist/action-providers/x402/x402ActionProvider.test.js +222 -262
- package/dist/action-providers/zora/zoraActionProvider.js +4 -5
- package/package.json +10 -7
- package/dist/action-providers/vaultsfyi/api/actions.d.ts +0 -41
- package/dist/action-providers/vaultsfyi/api/actions.js +0 -28
- package/dist/action-providers/vaultsfyi/api/historicalData.d.ts +0 -31
- package/dist/action-providers/vaultsfyi/api/historicalData.js +0 -44
- package/dist/action-providers/vaultsfyi/api/types.d.ts +0 -34
- package/dist/action-providers/vaultsfyi/api/types.js +0 -2
- package/dist/action-providers/vaultsfyi/api/vaults.d.ts +0 -66
- package/dist/action-providers/vaultsfyi/api/vaults.js +0 -57
package/README.md
CHANGED
|
@@ -505,6 +505,23 @@ const agent = createReactAgent({
|
|
|
505
505
|
</table>
|
|
506
506
|
</details>
|
|
507
507
|
<details>
|
|
508
|
+
<summary><strong>Sushi</strong></summary>
|
|
509
|
+
<table width="100%">
|
|
510
|
+
<tr>
|
|
511
|
+
<td width="200"><code>find-token</code></td>
|
|
512
|
+
<td width="768">Searches the Sushi Data API for up to 10 matching tokens by symbol or address.</td>
|
|
513
|
+
</tr>
|
|
514
|
+
<tr>
|
|
515
|
+
<td width="200"><code>quote</code></td>
|
|
516
|
+
<td width="768">Fetches an off-chain swap quote between ERC20 or native assets using the Sushi Swap API.</td>
|
|
517
|
+
</tr>
|
|
518
|
+
<tr>
|
|
519
|
+
<td width="200"><code>swap</code></td>
|
|
520
|
+
<td width="768">Executes a Sushi-routed swap after validating balances and approvals, returning the transaction hash.</td>
|
|
521
|
+
</tr>
|
|
522
|
+
</table>
|
|
523
|
+
</details>
|
|
524
|
+
<details>
|
|
508
525
|
<summary><strong>Twitter</strong></summary>
|
|
509
526
|
<table width="100%">
|
|
510
527
|
<tr>
|
|
@@ -558,25 +575,45 @@ const agent = createReactAgent({
|
|
|
558
575
|
<td width="768">Gets historical APY and TVL data for a specific vault over time.</td>
|
|
559
576
|
</tr>
|
|
560
577
|
<tr>
|
|
561
|
-
<td width="200"><code>
|
|
562
|
-
<td width="768">
|
|
563
|
-
</tr>
|
|
564
|
-
<tr>
|
|
565
|
-
<td width="200"><code>redeem</code></td>
|
|
566
|
-
<td width="768">Redeems assets from a vault to withdraw principal and earned yield.</td>
|
|
578
|
+
<td width="200"><code>transaction_context</code></td>
|
|
579
|
+
<td width="768">Gets the available balances and operations for a given vault.</td>
|
|
567
580
|
</tr>
|
|
568
581
|
<tr>
|
|
569
|
-
<td width="200"><code>
|
|
570
|
-
<td width="768">
|
|
582
|
+
<td width="200"><code>execute_step</code></td>
|
|
583
|
+
<td width="768">Executes an operation on a given vault.</td>
|
|
571
584
|
</tr>
|
|
572
585
|
<tr>
|
|
573
|
-
<td width="200"><code>
|
|
574
|
-
<td width="768">
|
|
586
|
+
<td width="200"><code>user_idle_assets</code></td>
|
|
587
|
+
<td width="768">Gets the user's idle assets.</td>
|
|
575
588
|
</tr>
|
|
576
589
|
<tr>
|
|
577
590
|
<td width="200"><code>positions</code></td>
|
|
578
591
|
<td width="768">Gets user's current positions in vaults including balances and unclaimed rewards.</td>
|
|
579
592
|
</tr>
|
|
593
|
+
<tr>
|
|
594
|
+
<td width="200"><code>rewards_context</code></td>
|
|
595
|
+
<td width="768">Gets the available rewards for a given user.</td>
|
|
596
|
+
</tr>
|
|
597
|
+
<tr>
|
|
598
|
+
<td width="200"><code>claim_rewards</code></td>
|
|
599
|
+
<td width="768">Claims requested rewards for a given user.</td>
|
|
600
|
+
</tr>
|
|
601
|
+
<tr>
|
|
602
|
+
<td width="200"><code>benchmark_apy</code></td>
|
|
603
|
+
<td width="768">Gets the benchmark APY.</td>
|
|
604
|
+
</tr>
|
|
605
|
+
<tr>
|
|
606
|
+
<td width="200"><code>historical_benchmark_apy</code></td>
|
|
607
|
+
<td width="768">Gets the historical benchmark APY.</td>
|
|
608
|
+
</tr>
|
|
609
|
+
<tr>
|
|
610
|
+
<td width="200"><code>total_vault_returns</code></td>
|
|
611
|
+
<td width="768">Gets the total returns for a given vault.</td>
|
|
612
|
+
</tr>
|
|
613
|
+
<tr>
|
|
614
|
+
<td width="200"><code>user_events</code></td>
|
|
615
|
+
<td width="768">Gets the user's events for a given vault.</td>
|
|
616
|
+
</tr>
|
|
580
617
|
</table>
|
|
581
618
|
</details>
|
|
582
619
|
<details>
|
|
@@ -32,6 +32,7 @@ const wallet_providers_1 = require("../../wallet-providers");
|
|
|
32
32
|
const utils_1 = require("./utils");
|
|
33
33
|
const accounts_1 = require("viem/accounts");
|
|
34
34
|
const viem_2 = require("viem");
|
|
35
|
+
const app_sdk_1 = require("@across-protocol/app-sdk");
|
|
35
36
|
/**
|
|
36
37
|
* AcrossActionProvider provides actions for cross-chain bridging via Across Protocol.
|
|
37
38
|
*/
|
|
@@ -68,9 +69,6 @@ class AcrossActionProvider extends actionProvider_1.ActionProvider {
|
|
|
68
69
|
*/
|
|
69
70
|
async bridgeToken(walletProvider, args) {
|
|
70
71
|
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
72
|
// Get recipient address if provided, otherwise use sender
|
|
75
73
|
const address = walletProvider.getAddress();
|
|
76
74
|
const recipient = (args.recipient || address);
|
|
@@ -105,7 +103,7 @@ class AcrossActionProvider extends actionProvider_1.ActionProvider {
|
|
|
105
103
|
transport: (0, viem_1.http)(),
|
|
106
104
|
});
|
|
107
105
|
// Create Across client
|
|
108
|
-
const acrossClient = createAcrossClient({
|
|
106
|
+
const acrossClient = (0, app_sdk_1.createAcrossClient)({
|
|
109
107
|
chains: [originChain, destinationChain],
|
|
110
108
|
useTestnet,
|
|
111
109
|
});
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const acrossActionProvider_1 = require("./acrossActionProvider");
|
|
4
4
|
const viem_1 = require("viem");
|
|
5
|
+
const app_sdk_1 = require("@across-protocol/app-sdk");
|
|
5
6
|
// Mock the necessary imports and modules
|
|
6
7
|
jest.mock("viem", () => {
|
|
7
8
|
return {
|
|
@@ -63,10 +64,11 @@ jest.mock("../../network", () => {
|
|
|
63
64
|
};
|
|
64
65
|
});
|
|
65
66
|
// Mock the Across SDK
|
|
66
|
-
const mockCreateAcrossClient = jest.fn();
|
|
67
67
|
jest.mock("@across-protocol/app-sdk", () => ({
|
|
68
|
-
createAcrossClient:
|
|
68
|
+
createAcrossClient: jest.fn(),
|
|
69
69
|
}));
|
|
70
|
+
// Cast the imported mock to a Jest mock function
|
|
71
|
+
const mockedCreateAcrossClient = app_sdk_1.createAcrossClient;
|
|
70
72
|
// Default implementation for the createAcrossClient mock
|
|
71
73
|
const defaultClientImplementation = () => ({
|
|
72
74
|
getSupportedChains: jest.fn().mockResolvedValue([
|
|
@@ -134,7 +136,7 @@ const defaultClientImplementation = () => ({
|
|
|
134
136
|
}),
|
|
135
137
|
});
|
|
136
138
|
// Set the default implementation
|
|
137
|
-
|
|
139
|
+
mockedCreateAcrossClient.mockImplementation(() => {
|
|
138
140
|
const client = defaultClientImplementation();
|
|
139
141
|
// Add the chains property to match what the code expects
|
|
140
142
|
return {
|
|
@@ -151,6 +153,7 @@ mockCreateAcrossClient.mockImplementation(() => {
|
|
|
151
153
|
network: "optimism",
|
|
152
154
|
},
|
|
153
155
|
],
|
|
156
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
154
157
|
};
|
|
155
158
|
});
|
|
156
159
|
// Mock the isTestnet function
|
|
@@ -170,7 +173,7 @@ describe("Across Action Provider", () => {
|
|
|
170
173
|
beforeEach(() => {
|
|
171
174
|
jest.clearAllMocks();
|
|
172
175
|
// Reset to default implementation
|
|
173
|
-
|
|
176
|
+
mockedCreateAcrossClient.mockImplementation(() => {
|
|
174
177
|
const client = defaultClientImplementation();
|
|
175
178
|
// Add the chains property to match what the code expects
|
|
176
179
|
return {
|
|
@@ -187,6 +190,7 @@ describe("Across Action Provider", () => {
|
|
|
187
190
|
network: "optimism",
|
|
188
191
|
},
|
|
189
192
|
],
|
|
193
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
190
194
|
};
|
|
191
195
|
});
|
|
192
196
|
mockPublicClient = {
|
|
@@ -247,7 +251,7 @@ describe("Across Action Provider", () => {
|
|
|
247
251
|
});
|
|
248
252
|
it("should fail when slippage is too high", async () => {
|
|
249
253
|
// Override the default mock with high slippage for this test only
|
|
250
|
-
|
|
254
|
+
mockedCreateAcrossClient.mockImplementationOnce(() => ({
|
|
251
255
|
getSupportedChains: jest.fn().mockResolvedValue([
|
|
252
256
|
{
|
|
253
257
|
chainId: 1,
|
|
@@ -288,6 +292,7 @@ describe("Across Action Provider", () => {
|
|
|
288
292
|
waitForDepositTx: jest.fn().mockResolvedValue({
|
|
289
293
|
depositId: "123456",
|
|
290
294
|
}),
|
|
295
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
291
296
|
}));
|
|
292
297
|
// Set a low max slippage
|
|
293
298
|
const args = {
|
|
@@ -19,6 +19,7 @@ const utils_1 = require("../erc20/utils");
|
|
|
19
19
|
const schemas_1 = require("./schemas");
|
|
20
20
|
const utils_2 = require("./utils");
|
|
21
21
|
const utils_3 = require("../../utils");
|
|
22
|
+
const spend_permission_1 = require("@base-org/account/spend-permission");
|
|
22
23
|
/**
|
|
23
24
|
* Fetch spend permissions for a user account from a spender address
|
|
24
25
|
*
|
|
@@ -29,8 +30,7 @@ const utils_3 = require("../../utils");
|
|
|
29
30
|
*/
|
|
30
31
|
async function fetchUserSpendPermissions(userAccount, spenderAccount, tokenAddress) {
|
|
31
32
|
try {
|
|
32
|
-
const
|
|
33
|
-
const permissions = await fetchPermissions({
|
|
33
|
+
const permissions = await (0, spend_permission_1.fetchPermissions)({
|
|
34
34
|
account: userAccount,
|
|
35
35
|
chainId: 8453,
|
|
36
36
|
spender: spenderAccount,
|
|
@@ -200,10 +200,9 @@ class BaseAccountActionProvider extends actionProvider_1.ActionProvider {
|
|
|
200
200
|
});
|
|
201
201
|
}
|
|
202
202
|
// Check permission status and prepare spend call data
|
|
203
|
-
const { getPermissionStatus, prepareSpendCallData } = await import("@base-org/account/spend-permission");
|
|
204
203
|
const status = await (0, utils_3.retryWithExponentialBackoff)(
|
|
205
204
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
206
|
-
() => getPermissionStatus(_permission), 3, // Max 3 retries
|
|
205
|
+
() => (0, spend_permission_1.getPermissionStatus)(_permission), 3, // Max 3 retries
|
|
207
206
|
1000, // 1s base delay
|
|
208
207
|
2000);
|
|
209
208
|
// Determine amount to spend - use provided amount or full remaining allowance
|
|
@@ -226,7 +225,7 @@ class BaseAccountActionProvider extends actionProvider_1.ActionProvider {
|
|
|
226
225
|
// Prepare the spend transaction - returns an array of calls
|
|
227
226
|
const spendCalls = await (0, utils_3.retryWithExponentialBackoff)(
|
|
228
227
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
229
|
-
() => prepareSpendCallData(_permission, amountInAtomicUnits), 3, // Max 3 retries
|
|
228
|
+
() => (0, spend_permission_1.prepareSpendCallData)(_permission, amountInAtomicUnits), 3, // Max 3 retries
|
|
230
229
|
1000, // 1s base delay
|
|
231
230
|
2000);
|
|
232
231
|
// Take the first call from the array (there should be one for spend operations)
|
|
@@ -303,9 +302,8 @@ class BaseAccountActionProvider extends actionProvider_1.ActionProvider {
|
|
|
303
302
|
// Use the specified permission (convert to 0-based index)
|
|
304
303
|
const _permission = permissions[permissionIndex - 1];
|
|
305
304
|
// Prepare the revoke transaction
|
|
306
|
-
const { prepareRevokeCallData } = await import("@base-org/account/spend-permission");
|
|
307
305
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
308
|
-
const revokeCall = await prepareRevokeCallData(_permission);
|
|
306
|
+
const revokeCall = await (0, spend_permission_1.prepareRevokeCallData)(_permission);
|
|
309
307
|
// Execute the revoke transaction
|
|
310
308
|
const txHash = await walletProvider.sendTransaction({
|
|
311
309
|
to: revokeCall.to,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { EvmWalletProvider } from "../../wallet-providers";
|
|
2
|
+
import { Clanker } from "clanker-sdk/v4";
|
|
2
3
|
/**
|
|
3
4
|
* Creates the client Clanker expects from the EvmWalletProvider
|
|
4
5
|
*
|
|
@@ -6,4 +7,4 @@ import { EvmWalletProvider } from "../../wallet-providers";
|
|
|
6
7
|
* @param networkId - The network to Clank on
|
|
7
8
|
* @returns The Clanker implementation
|
|
8
9
|
*/
|
|
9
|
-
export declare function createClankerClient(walletProvider: EvmWalletProvider, networkId: string): Promise<
|
|
10
|
+
export declare function createClankerClient(walletProvider: EvmWalletProvider, networkId: string): Promise<Clanker>;
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createClankerClient = createClankerClient;
|
|
4
4
|
const viem_1 = require("viem");
|
|
5
5
|
const network_1 = require("../../network");
|
|
6
|
+
const v4_1 = require("clanker-sdk/v4");
|
|
6
7
|
/**
|
|
7
8
|
* Creates the client Clanker expects from the EvmWalletProvider
|
|
8
9
|
*
|
|
@@ -11,7 +12,6 @@ const network_1 = require("../../network");
|
|
|
11
12
|
* @returns The Clanker implementation
|
|
12
13
|
*/
|
|
13
14
|
async function createClankerClient(walletProvider, networkId) {
|
|
14
|
-
const { Clanker } = await import("clanker-sdk/v4");
|
|
15
15
|
const account = walletProvider.toSigner();
|
|
16
16
|
const publicClient = walletProvider.getPublicClient();
|
|
17
17
|
const wallet = (0, viem_1.createWalletClient)({
|
|
@@ -19,5 +19,5 @@ async function createClankerClient(walletProvider, networkId) {
|
|
|
19
19
|
chain: network_1.NETWORK_ID_TO_VIEM_CHAIN[networkId],
|
|
20
20
|
transport: (0, viem_1.http)(publicClient.transport.url),
|
|
21
21
|
});
|
|
22
|
-
return new Clanker({ wallet, publicClient });
|
|
22
|
+
return new v4_1.Clanker({ wallet, publicClient });
|
|
23
23
|
}
|
|
@@ -38,6 +38,7 @@ __exportStar(require("./morpho"), exports);
|
|
|
38
38
|
__exportStar(require("./opensea"), exports);
|
|
39
39
|
__exportStar(require("./spl"), exports);
|
|
40
40
|
__exportStar(require("./superfluid"), exports);
|
|
41
|
+
__exportStar(require("./sushi"), exports);
|
|
41
42
|
__exportStar(require("./truemarkets"), exports);
|
|
42
43
|
__exportStar(require("./twitter"), exports);
|
|
43
44
|
__exportStar(require("./wallet"), exports);
|
|
@@ -17,6 +17,7 @@ const actionDecorator_1 = require("../actionDecorator");
|
|
|
17
17
|
const schemas_1 = require("./schemas");
|
|
18
18
|
const web3_js_1 = require("@solana/web3.js");
|
|
19
19
|
const api_1 = require("@jup-ag/api");
|
|
20
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
20
21
|
/**
|
|
21
22
|
* JupiterActionProvider handles token swaps using Jupiter's API.
|
|
22
23
|
*/
|
|
@@ -40,10 +41,9 @@ class JupiterActionProvider extends actionProvider_1.ActionProvider {
|
|
|
40
41
|
const userPublicKey = walletProvider.getPublicKey();
|
|
41
42
|
const inputMint = new web3_js_1.PublicKey(args.inputMint);
|
|
42
43
|
const outputMint = new web3_js_1.PublicKey(args.outputMint);
|
|
43
|
-
const { getMint } = await import("@solana/spl-token");
|
|
44
44
|
let mintInfo;
|
|
45
45
|
try {
|
|
46
|
-
mintInfo = await getMint(walletProvider.getConnection(), inputMint);
|
|
46
|
+
mintInfo = await (0, spl_token_1.getMint)(walletProvider.getConnection(), inputMint);
|
|
47
47
|
}
|
|
48
48
|
catch (error) {
|
|
49
49
|
return `Failed to fetch mint info for mint address ${args.inputMint}. Error: ${error}`;
|
|
@@ -16,6 +16,7 @@ const zod_1 = require("zod");
|
|
|
16
16
|
const actionDecorator_1 = require("../actionDecorator");
|
|
17
17
|
const schemas_1 = require("./schemas");
|
|
18
18
|
const web3_js_1 = require("@solana/web3.js");
|
|
19
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
19
20
|
/**
|
|
20
21
|
* SplActionProvider serves as a provider for SPL token actions.
|
|
21
22
|
* It provides SPL token transfer functionality.
|
|
@@ -42,22 +43,21 @@ class SplActionProvider extends actionProvider_1.ActionProvider {
|
|
|
42
43
|
const connection = walletProvider.getConnection();
|
|
43
44
|
const mintPubkey = new web3_js_1.PublicKey(args.mintAddress);
|
|
44
45
|
const ownerPubkey = new web3_js_1.PublicKey(args.address);
|
|
45
|
-
const { getMint, getAssociatedTokenAddress, getAccount, TokenAccountNotFoundError } = await import("@solana/spl-token");
|
|
46
46
|
let mintInfo;
|
|
47
47
|
try {
|
|
48
|
-
mintInfo = await getMint(connection, mintPubkey);
|
|
48
|
+
mintInfo = await (0, spl_token_1.getMint)(connection, mintPubkey);
|
|
49
49
|
}
|
|
50
50
|
catch (error) {
|
|
51
51
|
return `Failed to fetch mint info for mint address ${args.mintAddress}. Error: ${error}`;
|
|
52
52
|
}
|
|
53
53
|
try {
|
|
54
|
-
const ata = await getAssociatedTokenAddress(mintPubkey, ownerPubkey);
|
|
55
|
-
const account = await getAccount(connection, ata);
|
|
54
|
+
const ata = await (0, spl_token_1.getAssociatedTokenAddress)(mintPubkey, ownerPubkey);
|
|
55
|
+
const account = await (0, spl_token_1.getAccount)(connection, ata);
|
|
56
56
|
const balance = Number(account.amount) / Math.pow(10, mintInfo.decimals);
|
|
57
57
|
return `Balance for ${args.address} is ${balance} tokens`;
|
|
58
58
|
}
|
|
59
59
|
catch (error) {
|
|
60
|
-
if (error instanceof TokenAccountNotFoundError) {
|
|
60
|
+
if (error instanceof spl_token_1.TokenAccountNotFoundError) {
|
|
61
61
|
return `Balance for ${args.address} is 0 tokens`;
|
|
62
62
|
}
|
|
63
63
|
throw error;
|
|
@@ -80,29 +80,28 @@ class SplActionProvider extends actionProvider_1.ActionProvider {
|
|
|
80
80
|
const fromPubkey = walletProvider.getPublicKey();
|
|
81
81
|
const toPubkey = new web3_js_1.PublicKey(args.recipient);
|
|
82
82
|
const mintPubkey = new web3_js_1.PublicKey(args.mintAddress);
|
|
83
|
-
const { getMint, getAssociatedTokenAddress, getAccount, createAssociatedTokenAccountInstruction, createTransferCheckedInstruction, } = await import("@solana/spl-token");
|
|
84
83
|
let mintInfo;
|
|
85
84
|
try {
|
|
86
|
-
mintInfo = await getMint(connection, mintPubkey);
|
|
85
|
+
mintInfo = await (0, spl_token_1.getMint)(connection, mintPubkey);
|
|
87
86
|
}
|
|
88
87
|
catch (error) {
|
|
89
88
|
return `Failed to fetch mint info for mint address ${args.mintAddress}. Error: ${error}`;
|
|
90
89
|
}
|
|
91
90
|
const adjustedAmount = args.amount * Math.pow(10, mintInfo.decimals);
|
|
92
|
-
const sourceAta = await getAssociatedTokenAddress(mintPubkey, fromPubkey);
|
|
93
|
-
const destinationAta = await getAssociatedTokenAddress(mintPubkey, toPubkey);
|
|
91
|
+
const sourceAta = await (0, spl_token_1.getAssociatedTokenAddress)(mintPubkey, fromPubkey);
|
|
92
|
+
const destinationAta = await (0, spl_token_1.getAssociatedTokenAddress)(mintPubkey, toPubkey);
|
|
94
93
|
const instructions = [];
|
|
95
|
-
const sourceAccount = await getAccount(connection, sourceAta);
|
|
94
|
+
const sourceAccount = await (0, spl_token_1.getAccount)(connection, sourceAta);
|
|
96
95
|
if (sourceAccount.amount < BigInt(adjustedAmount)) {
|
|
97
96
|
throw new Error(`Insufficient token balance. Have ${sourceAccount.amount}, need ${adjustedAmount}`);
|
|
98
97
|
}
|
|
99
98
|
try {
|
|
100
|
-
await getAccount(connection, destinationAta);
|
|
99
|
+
await (0, spl_token_1.getAccount)(connection, destinationAta);
|
|
101
100
|
}
|
|
102
101
|
catch {
|
|
103
|
-
instructions.push(createAssociatedTokenAccountInstruction(fromPubkey, destinationAta, toPubkey, mintPubkey));
|
|
102
|
+
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(fromPubkey, destinationAta, toPubkey, mintPubkey));
|
|
104
103
|
}
|
|
105
|
-
instructions.push(createTransferCheckedInstruction(sourceAta, mintPubkey, destinationAta, fromPubkey, adjustedAmount, mintInfo.decimals));
|
|
104
|
+
instructions.push((0, spl_token_1.createTransferCheckedInstruction)(sourceAta, mintPubkey, destinationAta, fromPubkey, adjustedAmount, mintInfo.decimals));
|
|
106
105
|
const tx = new web3_js_1.VersionedTransaction(web3_js_1.MessageV0.compile({
|
|
107
106
|
payerKey: fromPubkey,
|
|
108
107
|
instructions: instructions,
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getAccountOutflow = getAccountOutflow;
|
|
4
4
|
const queries_1 = require("./queries");
|
|
5
5
|
const endpoints_1 = require("./endpoints");
|
|
6
|
+
const graphql_request_1 = require("graphql-request");
|
|
6
7
|
/**
|
|
7
8
|
* Gets the current account outflows for the user
|
|
8
9
|
*
|
|
@@ -11,8 +12,7 @@ const endpoints_1 = require("./endpoints");
|
|
|
11
12
|
*/
|
|
12
13
|
async function getAccountOutflow(userId) {
|
|
13
14
|
try {
|
|
14
|
-
const
|
|
15
|
-
const client = new GraphQLClient(endpoints_1.BASE_GRAPH_ENDPOINT);
|
|
15
|
+
const client = new graphql_request_1.GraphQLClient(endpoints_1.BASE_GRAPH_ENDPOINT);
|
|
16
16
|
const variables = { id: userId.toLowerCase() };
|
|
17
17
|
const data = await client.request(queries_1.getAccountOutflowQuery, variables);
|
|
18
18
|
return data;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export declare const routeProcessor9Abi_Route: readonly [{
|
|
2
|
+
readonly name: "Route";
|
|
3
|
+
readonly type: "event";
|
|
4
|
+
readonly inputs: readonly [{
|
|
5
|
+
readonly type: "address";
|
|
6
|
+
readonly name: "from";
|
|
7
|
+
readonly indexed: true;
|
|
8
|
+
}, {
|
|
9
|
+
readonly type: "address";
|
|
10
|
+
readonly name: "to";
|
|
11
|
+
}, {
|
|
12
|
+
readonly type: "address";
|
|
13
|
+
readonly name: "tokenIn";
|
|
14
|
+
readonly indexed: true;
|
|
15
|
+
}, {
|
|
16
|
+
readonly type: "address";
|
|
17
|
+
readonly name: "tokenOut";
|
|
18
|
+
}, {
|
|
19
|
+
readonly type: "uint256";
|
|
20
|
+
readonly name: "amountIn";
|
|
21
|
+
}, {
|
|
22
|
+
readonly type: "uint256";
|
|
23
|
+
readonly name: "amountOut";
|
|
24
|
+
}, {
|
|
25
|
+
readonly type: "int256";
|
|
26
|
+
readonly name: "slippage";
|
|
27
|
+
}, {
|
|
28
|
+
readonly type: "uint32";
|
|
29
|
+
readonly name: "referralCode";
|
|
30
|
+
readonly indexed: true;
|
|
31
|
+
}, {
|
|
32
|
+
readonly type: "bytes32";
|
|
33
|
+
readonly name: "diagnosticsFirst32";
|
|
34
|
+
}];
|
|
35
|
+
}];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.routeProcessor9Abi_Route = void 0;
|
|
4
|
+
const viem_1 = require("viem");
|
|
5
|
+
exports.routeProcessor9Abi_Route = (0, viem_1.parseAbi)([
|
|
6
|
+
"event Route(address indexed from, address to, address indexed tokenIn, address tokenOut, uint256 amountIn, uint256 amountOut, int256 slippage, uint32 indexed referralCode, bytes32 diagnosticsFirst32)",
|
|
7
|
+
]);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./sushiDataSchemas"), exports);
|
|
18
|
+
__exportStar(require("./sushiDataActionProvider"), exports);
|
|
19
|
+
__exportStar(require("./sushiRouterSchemas"), exports);
|
|
20
|
+
__exportStar(require("./sushiRouterActionProvider"), exports);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { EvmWalletProvider } from "../../wallet-providers";
|
|
3
|
+
import { ActionProvider } from "../actionProvider";
|
|
4
|
+
import { Network } from "../../network";
|
|
5
|
+
import { FindTokenSchema } from "./sushiDataSchemas";
|
|
6
|
+
/**
|
|
7
|
+
* SushiDataActionProvider is an action provider for Sushi.
|
|
8
|
+
*
|
|
9
|
+
* This provider is used for any action that uses the Sushi Data API.
|
|
10
|
+
*/
|
|
11
|
+
export declare class SushiDataActionProvider extends ActionProvider<EvmWalletProvider> {
|
|
12
|
+
/**
|
|
13
|
+
* Constructor for the SushiDataActionProvider class.
|
|
14
|
+
*/
|
|
15
|
+
constructor();
|
|
16
|
+
/**
|
|
17
|
+
* Swaps a specified amount of a from token to a to token for the wallet.
|
|
18
|
+
*
|
|
19
|
+
* @param walletProvider - The wallet provider to swap the tokens from.
|
|
20
|
+
* @param args - The input arguments for the action.
|
|
21
|
+
* @returns A message containing the swap details.
|
|
22
|
+
*/
|
|
23
|
+
findToken(walletProvider: EvmWalletProvider, args: z.infer<typeof FindTokenSchema>): Promise<string>;
|
|
24
|
+
/**
|
|
25
|
+
* Custom action providers are supported on all networks
|
|
26
|
+
*
|
|
27
|
+
* @param network - The network to checkpointSaver
|
|
28
|
+
* @returns True if the network is supported, false otherwise
|
|
29
|
+
*/
|
|
30
|
+
supportsNetwork(network: Network): boolean;
|
|
31
|
+
}
|
|
32
|
+
export declare const sushiDataActionProvider: () => SushiDataActionProvider;
|
|
@@ -0,0 +1,113 @@
|
|
|
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.sushiDataActionProvider = exports.SushiDataActionProvider = void 0;
|
|
13
|
+
const zod_1 = require("zod");
|
|
14
|
+
const wallet_providers_1 = require("../../wallet-providers");
|
|
15
|
+
const actionDecorator_1 = require("../actionDecorator");
|
|
16
|
+
const actionProvider_1 = require("../actionProvider");
|
|
17
|
+
const sushiDataSchemas_1 = require("./sushiDataSchemas");
|
|
18
|
+
const evm_1 = require("sushi/evm");
|
|
19
|
+
const viem_1 = require("viem");
|
|
20
|
+
/**
|
|
21
|
+
* SushiDataActionProvider is an action provider for Sushi.
|
|
22
|
+
*
|
|
23
|
+
* This provider is used for any action that uses the Sushi Data API.
|
|
24
|
+
*/
|
|
25
|
+
class SushiDataActionProvider extends actionProvider_1.ActionProvider {
|
|
26
|
+
/**
|
|
27
|
+
* Constructor for the SushiDataActionProvider class.
|
|
28
|
+
*/
|
|
29
|
+
constructor() {
|
|
30
|
+
super("sushi-data", []);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Swaps a specified amount of a from token to a to token for the wallet.
|
|
34
|
+
*
|
|
35
|
+
* @param walletProvider - The wallet provider to swap the tokens from.
|
|
36
|
+
* @param args - The input arguments for the action.
|
|
37
|
+
* @returns A message containing the swap details.
|
|
38
|
+
*/
|
|
39
|
+
async findToken(walletProvider, args) {
|
|
40
|
+
try {
|
|
41
|
+
const chainId = Number((await walletProvider.getNetwork()).chainId);
|
|
42
|
+
if (!(0, evm_1.isEvmChainId)(chainId)) {
|
|
43
|
+
return `Unsupported chainId: ${chainId}`;
|
|
44
|
+
}
|
|
45
|
+
const request = await fetch(`${evm_1.SUSHI_DATA_API_HOST}/graphql`, {
|
|
46
|
+
method: "POST",
|
|
47
|
+
headers: {
|
|
48
|
+
"Content-Type": "application/json",
|
|
49
|
+
Accept: "application/json",
|
|
50
|
+
},
|
|
51
|
+
body: `{"query":"query { tokenList(chainId: ${chainId}, first: 10, search: \\"${args.search}\\") { address symbol name decimals } }"}`,
|
|
52
|
+
});
|
|
53
|
+
const response = await request.json();
|
|
54
|
+
const schema = zod_1.z.object({
|
|
55
|
+
data: zod_1.z.object({
|
|
56
|
+
tokenList: zod_1.z.array(zod_1.z.object({
|
|
57
|
+
address: zod_1.z.string().refine(val => (0, viem_1.isAddress)(val, { strict: false })),
|
|
58
|
+
symbol: zod_1.z.string(),
|
|
59
|
+
name: zod_1.z.string(),
|
|
60
|
+
decimals: zod_1.z.number(),
|
|
61
|
+
})),
|
|
62
|
+
}),
|
|
63
|
+
});
|
|
64
|
+
const result = schema.safeParse(response);
|
|
65
|
+
if (!result.success) {
|
|
66
|
+
return `Error parsing response: ${result.error.message}`;
|
|
67
|
+
}
|
|
68
|
+
const tokens = result.data.data.tokenList;
|
|
69
|
+
const chain = (0, evm_1.getEvmChainById)(chainId);
|
|
70
|
+
let message = `Found ${tokens.length} tokens on ${chain.shortName}:`;
|
|
71
|
+
tokens.forEach(token => {
|
|
72
|
+
message += `\n- ${token.symbol} (${token.name}) - ${token.address}`;
|
|
73
|
+
});
|
|
74
|
+
return message;
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
return `Error finding tokens: ${error}`;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Custom action providers are supported on all networks
|
|
82
|
+
*
|
|
83
|
+
* @param network - The network to checkpointSaver
|
|
84
|
+
* @returns True if the network is supported, false otherwise
|
|
85
|
+
*/
|
|
86
|
+
supportsNetwork(network) {
|
|
87
|
+
if (network.protocolFamily !== "evm" || !network.chainId) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
return (0, evm_1.isEvmChainId)(Number(network.chainId));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
exports.SushiDataActionProvider = SushiDataActionProvider;
|
|
94
|
+
__decorate([
|
|
95
|
+
(0, actionDecorator_1.CreateAction)({
|
|
96
|
+
name: "find-token",
|
|
97
|
+
description: `This tool finds tokens (erc20) using the Sushi Data API
|
|
98
|
+
It takes the following inputs:
|
|
99
|
+
- Search: Either the token symbol (either full or partial) or token address to search for
|
|
100
|
+
|
|
101
|
+
Important notes:
|
|
102
|
+
- Only returns the first 10 tokens found
|
|
103
|
+
- Always use the full token symbol for better results
|
|
104
|
+
- Always use this tool to verify the token address if you are not sure about the address
|
|
105
|
+
`,
|
|
106
|
+
schema: sushiDataSchemas_1.FindTokenSchema,
|
|
107
|
+
}),
|
|
108
|
+
__metadata("design:type", Function),
|
|
109
|
+
__metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider, void 0]),
|
|
110
|
+
__metadata("design:returntype", Promise)
|
|
111
|
+
], SushiDataActionProvider.prototype, "findToken", null);
|
|
112
|
+
const sushiDataActionProvider = () => new SushiDataActionProvider();
|
|
113
|
+
exports.sushiDataActionProvider = sushiDataActionProvider;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FindTokenSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
/**
|
|
6
|
+
* Input schema for find token action
|
|
7
|
+
*/
|
|
8
|
+
exports.FindTokenSchema = zod_1.z
|
|
9
|
+
.object({
|
|
10
|
+
search: zod_1.z
|
|
11
|
+
.string()
|
|
12
|
+
.min(2)
|
|
13
|
+
.describe("Either the (partial or complete) symbol OR the address of the token to find"),
|
|
14
|
+
})
|
|
15
|
+
.strip()
|
|
16
|
+
.describe("Instructions for finding a token");
|