|
1 | 1 | import { tool } from "@langchain/core/tools" |
2 | | -import type { Api, KnownChainId } from "@polkadot-agent-kit/common" |
| 2 | +import type { KnownChainId } from "@polkadot-agent-kit/common" |
3 | 3 | import { getDecimalsByChainId, parseUnits } from "@polkadot-agent-kit/common" |
| 4 | +import type { PolkadotApi } from "@polkadot-agent-kit/core" |
4 | 5 | import { submitTxWithPolkadotSigner, transferNativeCall } from "@polkadot-agent-kit/core" |
5 | 6 | import type { PolkadotSigner } from "polkadot-api/signer" |
6 | 7 | import type { z } from "zod" |
7 | 8 |
|
8 | 9 | import type { TransferToolResult, transferToolSchema } from "../types" |
9 | 10 | import { ToolNames } from "../types/common" |
10 | 11 | import { toolConfigTransferNative } from "../types/transfer" |
11 | | -import { executeTool, getApiForChain, validateAndFormatMultiAddress } from "../utils" |
| 12 | +import { executeTool, validateAndFormatMultiAddress } from "../utils" |
12 | 13 |
|
13 | 14 | /** |
14 | 15 | * Returns a tool that transfers native tokens to a specific address |
15 | 16 | * @param api - The API instance to use for the transfer |
16 | 17 | * @returns A dynamic structured tool that transfers native tokens to the specified address |
17 | 18 | */ |
18 | | -export const transferNativeTool = ( |
19 | | - apis: Map<KnownChainId, Api<KnownChainId>>, |
20 | | - signer: PolkadotSigner |
21 | | -) => { |
| 19 | +export const transferNativeTool = (polkadotApi: PolkadotApi, signer: PolkadotSigner) => { |
22 | 20 | return tool(async ({ amount, to, chain }: z.infer<typeof transferToolSchema>) => { |
23 | 21 | return executeTool<TransferToolResult>( |
24 | 22 | ToolNames.TRANSFER_NATIVE, |
25 | 23 | async () => { |
26 | | - const api = getApiForChain(apis, chain) |
| 24 | + const api = polkadotApi.getApi(chain as KnownChainId) |
27 | 25 | const formattedAddress = validateAndFormatMultiAddress(to, chain as KnownChainId) |
28 | 26 | const parsedAmount = parseUnits(amount, getDecimalsByChainId(chain)) |
29 | 27 | const tx = await submitTxWithPolkadotSigner( |
|
0 commit comments