-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathapi.ts
More file actions
168 lines (144 loc) · 5.58 KB
/
api.ts
File metadata and controls
168 lines (144 loc) · 5.58 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import type { PolkadotApi } from "@polkadot-agent-kit/core"
import type { PolkadotSigner } from "polkadot-api"
import {
bondExtraTool,
checkBalanceTool,
claimRewardsTool,
initializeChainApiTool,
joinPoolTool,
registerIdentityTool,
swapTokensTool,
transferNativeTool,
unbondTool,
withdrawUnbondedTool,
xcmTransferNativeTool
} from "../langchain"
import type {
BalanceTool,
BondExtraTool,
ClaimRewardsTool,
InitializeChainApiTool,
JoinPoolTool,
RegisterIdentityTool,
SwapTokensTool,
TransferTool,
UnbondTool,
WithdrawUnbondedTool,
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
/**
* Returns a tool that initializes a new chain API dynamically
* @returns A dynamic structured tool that initializes chain APIs
*/
getInitializeChainApiTool(): InitializeChainApiTool
/**
* Returns a tool that swaps tokens across different chains using the Hydration DEX
* @returns A dynamic structured tool that swaps tokens across different chains using the Hydration DEX
*/
swapTokensTool(signer: PolkadotSigner, sender: string): SwapTokensTool
/**
* Returns a tool that joins a nomination pool
* @param signer - The signer to use for transactions
* @returns A dynamic structured tool that joins nomination pools
*/
joinPoolTool(signer: PolkadotSigner): JoinPoolTool
/**
* Returns a tool that bonds extra tokens to a nomination pool
* @param signer - The signer to use for transactions
* @returns A dynamic structured tool that bonds extra tokens
*/
bondExtraTool(signer: PolkadotSigner): BondExtraTool
/**
* Returns a tool that unbonds tokens from a nomination pool
* @param signer - The signer to use for transactions
* @param address - The address to unbond from
* @returns A dynamic structured tool that unbonds tokens
*/
unbondTool(signer: PolkadotSigner, address: string): UnbondTool
/**
* Returns a tool that withdraws unbonded tokens from a nomination pool
* @param signer - The signer to use for transactions
* @param address - The address to withdraw for
* @returns A dynamic structured tool that withdraws unbonded tokens
*/
withdrawUnbondedTool(signer: PolkadotSigner, address: string): WithdrawUnbondedTool
/**
* Returns a tool that claims rewards from a nomination pool
* @param signer - The signer to use for transactions
* @returns A dynamic structured tool that claims rewards
*/
claimRewardsTool(signer: PolkadotSigner): ClaimRewardsTool
/**
* Returns a tool that registers an identity on People Chain
* @param signer - The signer to use for transactions
* @returns A dynamic structured tool that registers an identity on People Chain
*/
registerIdentityTool(signer: PolkadotSigner): RegisterIdentityTool
}
/**
* 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, address) as unknown as BalanceTool
}
transferNativeTool(signer: PolkadotSigner): TransferTool {
return transferNativeTool(this.api, signer) as unknown as TransferTool
}
xcmTransferNativeTool(signer: PolkadotSigner, sender: string): XcmTransferNativeAssetTool {
return xcmTransferNativeTool(signer, sender) as unknown as XcmTransferNativeAssetTool
}
getInitializeChainApiTool(): InitializeChainApiTool {
return initializeChainApiTool(this.api) as unknown as InitializeChainApiTool
}
swapTokensTool(signer: PolkadotSigner, sender: string): SwapTokensTool {
return swapTokensTool(signer, sender) as unknown as SwapTokensTool
}
joinPoolTool(signer: PolkadotSigner): JoinPoolTool {
return joinPoolTool(this.api, signer) as unknown as JoinPoolTool
}
bondExtraTool(signer: PolkadotSigner): BondExtraTool {
return bondExtraTool(this.api, signer) as unknown as BondExtraTool
}
unbondTool(signer: PolkadotSigner, address: string): UnbondTool {
return unbondTool(this.api, signer, address) as unknown as UnbondTool
}
withdrawUnbondedTool(signer: PolkadotSigner, address: string): WithdrawUnbondedTool {
return withdrawUnbondedTool(this.api, signer, address) as unknown as WithdrawUnbondedTool
}
claimRewardsTool(signer: PolkadotSigner): ClaimRewardsTool {
return claimRewardsTool(this.api, signer) as unknown as ClaimRewardsTool
}
registerIdentityTool(signer: PolkadotSigner): RegisterIdentityTool {
return registerIdentityTool(this.api, signer) as unknown as RegisterIdentityTool
}
}