-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathapi.ts
More file actions
56 lines (48 loc) · 2 KB
/
api.ts
File metadata and controls
56 lines (48 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import type { PolkadotApi } from "@polkadot-agent-kit/core"
import type { PolkadotSigner } from "polkadot-api"
import { checkBalanceTool, transferNativeTool, xcmTransferNativeTool } from "../langchain"
import type { BalanceTool, TransferTool, XcmTransferNativeAssetTool } from "../types"
/**
* Interface for Polkadot API implementations
* Defines the interface that all Polkadot chain types must follow
*/
export interface IPolkadotAgentApi {
/**
* Returns a tool that checks the balance of a specific address
* @param address - The address to check the balance for
* @returns A dynamic structured tool that checks the balance of the specified address
*/
getNativeBalanceTool(address: string): BalanceTool
/**
* Returns a tool that transfers native tokens to a specific address
* @returns A dynamic structured tool that transfers native tokens to the specified address
*/
transferNativeTool(signer: PolkadotSigner): TransferTool
// /**
// * Returns a tool that transfers native tokens to a specific address via xcm
// * @returns A dynamic structured tool that transfers native tokens to the specified address via xcm
// */
xcmTransferNativeTool(signer: PolkadotSigner, sender: string): XcmTransferNativeAssetTool
}
/**
* Implementation of the IPolkadotAgentApi interface
* Provides access to Polkadot API methods
*/
export class PolkadotAgentApi implements IPolkadotAgentApi {
/**
* The Polkadot API instance
*/
private api: PolkadotApi
constructor(api: PolkadotApi) {
this.api = api
}
getNativeBalanceTool(address: string): BalanceTool {
return checkBalanceTool(this.api.getAllApis(), address) as unknown as BalanceTool
}
transferNativeTool(signer: PolkadotSigner): TransferTool {
return transferNativeTool(this.api.getAllApis(), signer) as unknown as TransferTool
}
xcmTransferNativeTool(signer: PolkadotSigner, sender: string): XcmTransferNativeAssetTool {
return xcmTransferNativeTool(signer, sender) as unknown as XcmTransferNativeAssetTool
}
}