keyring-agent-core 0.2.0 → 0.2.2

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.
Files changed (417) hide show
  1. package/dist/index.d.ts +6692 -27
  2. package/dist/index.js +877 -70
  3. package/package.json +4 -3
  4. package/dist/agent/AgentCore.d.ts +0 -256
  5. package/dist/agent/AgentCore.d.ts.map +0 -1
  6. package/dist/agent/AgentCore.js +0 -1093
  7. package/dist/agent/AgentCore.js.map +0 -1
  8. package/dist/agent/QueryRewriter.d.ts +0 -84
  9. package/dist/agent/QueryRewriter.d.ts.map +0 -1
  10. package/dist/agent/QueryRewriter.js +0 -306
  11. package/dist/agent/QueryRewriter.js.map +0 -1
  12. package/dist/agent/Router.d.ts +0 -33
  13. package/dist/agent/Router.d.ts.map +0 -1
  14. package/dist/agent/Router.js +0 -229
  15. package/dist/agent/Router.js.map +0 -1
  16. package/dist/agent/Subagent.d.ts +0 -80
  17. package/dist/agent/Subagent.d.ts.map +0 -1
  18. package/dist/agent/Subagent.js +0 -272
  19. package/dist/agent/Subagent.js.map +0 -1
  20. package/dist/agent/Synthesizer.d.ts +0 -11
  21. package/dist/agent/Synthesizer.d.ts.map +0 -1
  22. package/dist/agent/Synthesizer.js +0 -86
  23. package/dist/agent/Synthesizer.js.map +0 -1
  24. package/dist/agent/chatGraph.d.ts +0 -364
  25. package/dist/agent/chatGraph.d.ts.map +0 -1
  26. package/dist/agent/chatGraph.js +0 -184
  27. package/dist/agent/chatGraph.js.map +0 -1
  28. package/dist/agent/index.d.ts +0 -10
  29. package/dist/agent/index.d.ts.map +0 -1
  30. package/dist/agent/index.js +0 -24
  31. package/dist/agent/index.js.map +0 -1
  32. package/dist/agent/subagents/AiAgent.d.ts +0 -6
  33. package/dist/agent/subagents/AiAgent.d.ts.map +0 -1
  34. package/dist/agent/subagents/AiAgent.js +0 -52
  35. package/dist/agent/subagents/AiAgent.js.map +0 -1
  36. package/dist/agent/subagents/NftAgent.d.ts +0 -6
  37. package/dist/agent/subagents/NftAgent.d.ts.map +0 -1
  38. package/dist/agent/subagents/NftAgent.js +0 -79
  39. package/dist/agent/subagents/NftAgent.js.map +0 -1
  40. package/dist/agent/subagents/PoolAgent.d.ts +0 -6
  41. package/dist/agent/subagents/PoolAgent.d.ts.map +0 -1
  42. package/dist/agent/subagents/PoolAgent.js +0 -184
  43. package/dist/agent/subagents/PoolAgent.js.map +0 -1
  44. package/dist/agent/subagents/PoolSubgraphAgent.d.ts +0 -6
  45. package/dist/agent/subagents/PoolSubgraphAgent.d.ts.map +0 -1
  46. package/dist/agent/subagents/PoolSubgraphAgent.js +0 -117
  47. package/dist/agent/subagents/PoolSubgraphAgent.js.map +0 -1
  48. package/dist/agent/subagents/TokenAgent.d.ts +0 -6
  49. package/dist/agent/subagents/TokenAgent.d.ts.map +0 -1
  50. package/dist/agent/subagents/TokenAgent.js +0 -76
  51. package/dist/agent/subagents/TokenAgent.js.map +0 -1
  52. package/dist/agent/subagents/WalletActionAgent.d.ts +0 -6
  53. package/dist/agent/subagents/WalletActionAgent.d.ts.map +0 -1
  54. package/dist/agent/subagents/WalletActionAgent.js +0 -55
  55. package/dist/agent/subagents/WalletActionAgent.js.map +0 -1
  56. package/dist/agent/subagents/WalletAgent.d.ts +0 -6
  57. package/dist/agent/subagents/WalletAgent.d.ts.map +0 -1
  58. package/dist/agent/subagents/WalletAgent.js +0 -93
  59. package/dist/agent/subagents/WalletAgent.js.map +0 -1
  60. package/dist/agent/subagents/index.d.ts +0 -34
  61. package/dist/agent/subagents/index.d.ts.map +0 -1
  62. package/dist/agent/subagents/index.js +0 -69
  63. package/dist/agent/subagents/index.js.map +0 -1
  64. package/dist/constants/abi.d.ts +0 -551
  65. package/dist/constants/abi.d.ts.map +0 -1
  66. package/dist/constants/abi.js +0 -690
  67. package/dist/constants/abi.js.map +0 -1
  68. package/dist/functions/pool.d.ts +0 -25
  69. package/dist/functions/pool.d.ts.map +0 -1
  70. package/dist/functions/pool.js +0 -151
  71. package/dist/functions/pool.js.map +0 -1
  72. package/dist/functions/web3.d.ts +0 -31
  73. package/dist/functions/web3.d.ts.map +0 -1
  74. package/dist/functions/web3.js +0 -232
  75. package/dist/functions/web3.js.map +0 -1
  76. package/dist/index.d.ts.map +0 -1
  77. package/dist/index.js.map +0 -1
  78. package/dist/llm/GeminiProvider.d.ts +0 -16
  79. package/dist/llm/GeminiProvider.d.ts.map +0 -1
  80. package/dist/llm/GeminiProvider.js +0 -329
  81. package/dist/llm/GeminiProvider.js.map +0 -1
  82. package/dist/llm/index.d.ts +0 -2
  83. package/dist/llm/index.d.ts.map +0 -1
  84. package/dist/llm/index.js +0 -6
  85. package/dist/llm/index.js.map +0 -1
  86. package/dist/memory/ChatHistory.d.ts +0 -83
  87. package/dist/memory/ChatHistory.d.ts.map +0 -1
  88. package/dist/memory/ChatHistory.js +0 -143
  89. package/dist/memory/ChatHistory.js.map +0 -1
  90. package/dist/memory/KnowledgeBase.d.ts +0 -38
  91. package/dist/memory/KnowledgeBase.d.ts.map +0 -1
  92. package/dist/memory/KnowledgeBase.js +0 -139
  93. package/dist/memory/KnowledgeBase.js.map +0 -1
  94. package/dist/memory/Summarizer.d.ts +0 -12
  95. package/dist/memory/Summarizer.d.ts.map +0 -1
  96. package/dist/memory/Summarizer.js +0 -39
  97. package/dist/memory/Summarizer.js.map +0 -1
  98. package/dist/memory/UpstashKnowledgeBase.d.ts +0 -124
  99. package/dist/memory/UpstashKnowledgeBase.d.ts.map +0 -1
  100. package/dist/memory/UpstashKnowledgeBase.js +0 -152
  101. package/dist/memory/UpstashKnowledgeBase.js.map +0 -1
  102. package/dist/memory/historyUtils.d.ts +0 -58
  103. package/dist/memory/historyUtils.d.ts.map +0 -1
  104. package/dist/memory/historyUtils.js +0 -190
  105. package/dist/memory/historyUtils.js.map +0 -1
  106. package/dist/memory/index.d.ts +0 -7
  107. package/dist/memory/index.d.ts.map +0 -1
  108. package/dist/memory/index.js +0 -12
  109. package/dist/memory/index.js.map +0 -1
  110. package/dist/memory/ingestKnowledgeBase.d.ts +0 -17
  111. package/dist/memory/ingestKnowledgeBase.d.ts.map +0 -1
  112. package/dist/memory/ingestKnowledgeBase.js +0 -35
  113. package/dist/memory/ingestKnowledgeBase.js.map +0 -1
  114. package/dist/services/MoralisService.d.ts +0 -1328
  115. package/dist/services/MoralisService.d.ts.map +0 -1
  116. package/dist/services/MoralisService.js +0 -1239
  117. package/dist/services/MoralisService.js.map +0 -1
  118. package/dist/services/PantographService.d.ts +0 -98
  119. package/dist/services/PantographService.d.ts.map +0 -1
  120. package/dist/services/PantographService.js +0 -451
  121. package/dist/services/PantographService.js.map +0 -1
  122. package/dist/services/PoolService.d.ts +0 -238
  123. package/dist/services/PoolService.d.ts.map +0 -1
  124. package/dist/services/PoolService.js +0 -485
  125. package/dist/services/PoolService.js.map +0 -1
  126. package/dist/services/UniswapService.d.ts +0 -289
  127. package/dist/services/UniswapService.d.ts.map +0 -1
  128. package/dist/services/UniswapService.js +0 -585
  129. package/dist/services/UniswapService.js.map +0 -1
  130. package/dist/services/UniswapSubgraphService.d.ts +0 -144
  131. package/dist/services/UniswapSubgraphService.d.ts.map +0 -1
  132. package/dist/services/UniswapSubgraphService.js +0 -606
  133. package/dist/services/UniswapSubgraphService.js.map +0 -1
  134. package/dist/services/rpc.d.ts +0 -35
  135. package/dist/services/rpc.d.ts.map +0 -1
  136. package/dist/services/rpc.js +0 -110
  137. package/dist/services/rpc.js.map +0 -1
  138. package/dist/services/swap/BaseSwapService.d.ts +0 -17
  139. package/dist/services/swap/BaseSwapService.d.ts.map +0 -1
  140. package/dist/services/swap/BaseSwapService.js +0 -19
  141. package/dist/services/swap/BaseSwapService.js.map +0 -1
  142. package/dist/services/swap/DebridgeAdapter.d.ts +0 -37
  143. package/dist/services/swap/DebridgeAdapter.d.ts.map +0 -1
  144. package/dist/services/swap/DebridgeAdapter.js +0 -243
  145. package/dist/services/swap/DebridgeAdapter.js.map +0 -1
  146. package/dist/services/swap/RelayAdapter.d.ts +0 -19
  147. package/dist/services/swap/RelayAdapter.d.ts.map +0 -1
  148. package/dist/services/swap/RelayAdapter.js +0 -189
  149. package/dist/services/swap/RelayAdapter.js.map +0 -1
  150. package/dist/services/swap/SwapServiceFactory.d.ts +0 -25
  151. package/dist/services/swap/SwapServiceFactory.d.ts.map +0 -1
  152. package/dist/services/swap/SwapServiceFactory.js +0 -79
  153. package/dist/services/swap/SwapServiceFactory.js.map +0 -1
  154. package/dist/services/swap/addresses.d.ts +0 -3
  155. package/dist/services/swap/addresses.d.ts.map +0 -1
  156. package/dist/services/swap/addresses.js +0 -68
  157. package/dist/services/swap/addresses.js.map +0 -1
  158. package/dist/services/swap/affiliate.d.ts +0 -17
  159. package/dist/services/swap/affiliate.d.ts.map +0 -1
  160. package/dist/services/swap/affiliate.js +0 -126
  161. package/dist/services/swap/affiliate.js.map +0 -1
  162. package/dist/services/swap/config.d.ts +0 -9
  163. package/dist/services/swap/config.d.ts.map +0 -1
  164. package/dist/services/swap/config.js +0 -19
  165. package/dist/services/swap/config.js.map +0 -1
  166. package/dist/services/swap/index.d.ts +0 -10
  167. package/dist/services/swap/index.d.ts.map +0 -1
  168. package/dist/services/swap/index.js +0 -22
  169. package/dist/services/swap/index.js.map +0 -1
  170. package/dist/services/swap/types.d.ts +0 -89
  171. package/dist/services/swap/types.d.ts.map +0 -1
  172. package/dist/services/swap/types.js +0 -6
  173. package/dist/services/swap/types.js.map +0 -1
  174. package/dist/tools/BaseTool.d.ts +0 -15
  175. package/dist/tools/BaseTool.d.ts.map +0 -1
  176. package/dist/tools/BaseTool.js +0 -35
  177. package/dist/tools/BaseTool.js.map +0 -1
  178. package/dist/tools/ToolRegistry.d.ts +0 -27
  179. package/dist/tools/ToolRegistry.d.ts.map +0 -1
  180. package/dist/tools/ToolRegistry.js +0 -80
  181. package/dist/tools/ToolRegistry.js.map +0 -1
  182. package/dist/tools/builtin/ai/GeminiSearchAiTool.d.ts +0 -36
  183. package/dist/tools/builtin/ai/GeminiSearchAiTool.d.ts.map +0 -1
  184. package/dist/tools/builtin/ai/GeminiSearchAiTool.js +0 -91
  185. package/dist/tools/builtin/ai/GeminiSearchAiTool.js.map +0 -1
  186. package/dist/tools/builtin/ai/index.d.ts +0 -3
  187. package/dist/tools/builtin/ai/index.d.ts.map +0 -1
  188. package/dist/tools/builtin/ai/index.js +0 -6
  189. package/dist/tools/builtin/ai/index.js.map +0 -1
  190. package/dist/tools/builtin/index.d.ts +0 -8
  191. package/dist/tools/builtin/index.d.ts.map +0 -1
  192. package/dist/tools/builtin/index.js +0 -24
  193. package/dist/tools/builtin/index.js.map +0 -1
  194. package/dist/tools/builtin/nft/BaseNftMessageTool.d.ts +0 -35
  195. package/dist/tools/builtin/nft/BaseNftMessageTool.d.ts.map +0 -1
  196. package/dist/tools/builtin/nft/BaseNftMessageTool.js +0 -45
  197. package/dist/tools/builtin/nft/BaseNftMessageTool.js.map +0 -1
  198. package/dist/tools/builtin/nft/NFTContractInfoTool.d.ts +0 -15
  199. package/dist/tools/builtin/nft/NFTContractInfoTool.d.ts.map +0 -1
  200. package/dist/tools/builtin/nft/NFTContractInfoTool.js +0 -19
  201. package/dist/tools/builtin/nft/NFTContractInfoTool.js.map +0 -1
  202. package/dist/tools/builtin/nft/NFTMetadataTool.d.ts +0 -15
  203. package/dist/tools/builtin/nft/NFTMetadataTool.d.ts.map +0 -1
  204. package/dist/tools/builtin/nft/NFTMetadataTool.js +0 -20
  205. package/dist/tools/builtin/nft/NFTMetadataTool.js.map +0 -1
  206. package/dist/tools/builtin/nft/SendNftTool.d.ts +0 -14
  207. package/dist/tools/builtin/nft/SendNftTool.d.ts.map +0 -1
  208. package/dist/tools/builtin/nft/SendNftTool.js +0 -20
  209. package/dist/tools/builtin/nft/SendNftTool.js.map +0 -1
  210. package/dist/tools/builtin/nft/WalletNFTsTool.d.ts +0 -15
  211. package/dist/tools/builtin/nft/WalletNFTsTool.d.ts.map +0 -1
  212. package/dist/tools/builtin/nft/WalletNFTsTool.js +0 -20
  213. package/dist/tools/builtin/nft/WalletNFTsTool.js.map +0 -1
  214. package/dist/tools/builtin/nft/index.d.ts +0 -7
  215. package/dist/tools/builtin/nft/index.d.ts.map +0 -1
  216. package/dist/tools/builtin/nft/index.js +0 -10
  217. package/dist/tools/builtin/nft/index.js.map +0 -1
  218. package/dist/tools/builtin/pool/EstimatePoolYieldTool.d.ts +0 -124
  219. package/dist/tools/builtin/pool/EstimatePoolYieldTool.d.ts.map +0 -1
  220. package/dist/tools/builtin/pool/EstimatePoolYieldTool.js +0 -236
  221. package/dist/tools/builtin/pool/EstimatePoolYieldTool.js.map +0 -1
  222. package/dist/tools/builtin/pool/OpenAddLiquidityFormTool.d.ts +0 -128
  223. package/dist/tools/builtin/pool/OpenAddLiquidityFormTool.d.ts.map +0 -1
  224. package/dist/tools/builtin/pool/OpenAddLiquidityFormTool.js +0 -520
  225. package/dist/tools/builtin/pool/OpenAddLiquidityFormTool.js.map +0 -1
  226. package/dist/tools/builtin/pool/PoolByAddressTool.d.ts +0 -127
  227. package/dist/tools/builtin/pool/PoolByAddressTool.d.ts.map +0 -1
  228. package/dist/tools/builtin/pool/PoolByAddressTool.js +0 -238
  229. package/dist/tools/builtin/pool/PoolByAddressTool.js.map +0 -1
  230. package/dist/tools/builtin/pool/PoolDetailTool.d.ts +0 -127
  231. package/dist/tools/builtin/pool/PoolDetailTool.d.ts.map +0 -1
  232. package/dist/tools/builtin/pool/PoolDetailTool.js +0 -273
  233. package/dist/tools/builtin/pool/PoolDetailTool.js.map +0 -1
  234. package/dist/tools/builtin/pool/PoolSearchTool.d.ts +0 -50
  235. package/dist/tools/builtin/pool/PoolSearchTool.d.ts.map +0 -1
  236. package/dist/tools/builtin/pool/PoolSearchTool.js +0 -160
  237. package/dist/tools/builtin/pool/PoolSearchTool.js.map +0 -1
  238. package/dist/tools/builtin/pool/PreviewAddLiquidityTool.d.ts +0 -124
  239. package/dist/tools/builtin/pool/PreviewAddLiquidityTool.d.ts.map +0 -1
  240. package/dist/tools/builtin/pool/PreviewAddLiquidityTool.js +0 -382
  241. package/dist/tools/builtin/pool/PreviewAddLiquidityTool.js.map +0 -1
  242. package/dist/tools/builtin/pool/TopPoolsTool.d.ts +0 -68
  243. package/dist/tools/builtin/pool/TopPoolsTool.d.ts.map +0 -1
  244. package/dist/tools/builtin/pool/TopPoolsTool.js +0 -159
  245. package/dist/tools/builtin/pool/TopPoolsTool.js.map +0 -1
  246. package/dist/tools/builtin/pool/index.d.ts +0 -15
  247. package/dist/tools/builtin/pool/index.d.ts.map +0 -1
  248. package/dist/tools/builtin/pool/index.js +0 -18
  249. package/dist/tools/builtin/pool/index.js.map +0 -1
  250. package/dist/tools/builtin/pool-subgraph/SubgraphCoinPoolPairsTool.d.ts +0 -54
  251. package/dist/tools/builtin/pool-subgraph/SubgraphCoinPoolPairsTool.d.ts.map +0 -1
  252. package/dist/tools/builtin/pool-subgraph/SubgraphCoinPoolPairsTool.js +0 -98
  253. package/dist/tools/builtin/pool-subgraph/SubgraphCoinPoolPairsTool.js.map +0 -1
  254. package/dist/tools/builtin/pool-subgraph/SubgraphPoolByAddressTool.d.ts +0 -63
  255. package/dist/tools/builtin/pool-subgraph/SubgraphPoolByAddressTool.d.ts.map +0 -1
  256. package/dist/tools/builtin/pool-subgraph/SubgraphPoolByAddressTool.js +0 -82
  257. package/dist/tools/builtin/pool-subgraph/SubgraphPoolByAddressTool.js.map +0 -1
  258. package/dist/tools/builtin/pool-subgraph/SubgraphPoolByPositionIdTool.d.ts +0 -79
  259. package/dist/tools/builtin/pool-subgraph/SubgraphPoolByPositionIdTool.d.ts.map +0 -1
  260. package/dist/tools/builtin/pool-subgraph/SubgraphPoolByPositionIdTool.js +0 -97
  261. package/dist/tools/builtin/pool-subgraph/SubgraphPoolByPositionIdTool.js.map +0 -1
  262. package/dist/tools/builtin/pool-subgraph/SubgraphPoolSearchTool.d.ts +0 -77
  263. package/dist/tools/builtin/pool-subgraph/SubgraphPoolSearchTool.d.ts.map +0 -1
  264. package/dist/tools/builtin/pool-subgraph/SubgraphPoolSearchTool.js +0 -190
  265. package/dist/tools/builtin/pool-subgraph/SubgraphPoolSearchTool.js.map +0 -1
  266. package/dist/tools/builtin/pool-subgraph/SubgraphPositionDetailTool.d.ts +0 -107
  267. package/dist/tools/builtin/pool-subgraph/SubgraphPositionDetailTool.d.ts.map +0 -1
  268. package/dist/tools/builtin/pool-subgraph/SubgraphPositionDetailTool.js +0 -92
  269. package/dist/tools/builtin/pool-subgraph/SubgraphPositionDetailTool.js.map +0 -1
  270. package/dist/tools/builtin/pool-subgraph/SubgraphTrendingPoolsTool.d.ts +0 -56
  271. package/dist/tools/builtin/pool-subgraph/SubgraphTrendingPoolsTool.d.ts.map +0 -1
  272. package/dist/tools/builtin/pool-subgraph/SubgraphTrendingPoolsTool.js +0 -94
  273. package/dist/tools/builtin/pool-subgraph/SubgraphTrendingPoolsTool.js.map +0 -1
  274. package/dist/tools/builtin/pool-subgraph/index.d.ts +0 -13
  275. package/dist/tools/builtin/pool-subgraph/index.d.ts.map +0 -1
  276. package/dist/tools/builtin/pool-subgraph/index.js +0 -18
  277. package/dist/tools/builtin/pool-subgraph/index.js.map +0 -1
  278. package/dist/tools/builtin/token/TokenAnalyticsTool.d.ts +0 -71
  279. package/dist/tools/builtin/token/TokenAnalyticsTool.d.ts.map +0 -1
  280. package/dist/tools/builtin/token/TokenAnalyticsTool.js +0 -147
  281. package/dist/tools/builtin/token/TokenAnalyticsTool.js.map +0 -1
  282. package/dist/tools/builtin/token/TokenHoldersTool.d.ts +0 -81
  283. package/dist/tools/builtin/token/TokenHoldersTool.d.ts.map +0 -1
  284. package/dist/tools/builtin/token/TokenHoldersTool.js +0 -139
  285. package/dist/tools/builtin/token/TokenHoldersTool.js.map +0 -1
  286. package/dist/tools/builtin/token/TokenInfoTool.d.ts +0 -40
  287. package/dist/tools/builtin/token/TokenInfoTool.d.ts.map +0 -1
  288. package/dist/tools/builtin/token/TokenInfoTool.js +0 -221
  289. package/dist/tools/builtin/token/TokenInfoTool.js.map +0 -1
  290. package/dist/tools/builtin/token/TokenScoreTool.d.ts +0 -63
  291. package/dist/tools/builtin/token/TokenScoreTool.d.ts.map +0 -1
  292. package/dist/tools/builtin/token/TokenScoreTool.js +0 -148
  293. package/dist/tools/builtin/token/TokenScoreTool.js.map +0 -1
  294. package/dist/tools/builtin/token/TopGainersTool.d.ts +0 -37
  295. package/dist/tools/builtin/token/TopGainersTool.d.ts.map +0 -1
  296. package/dist/tools/builtin/token/TopGainersTool.js +0 -100
  297. package/dist/tools/builtin/token/TopGainersTool.js.map +0 -1
  298. package/dist/tools/builtin/token/TopLosersTool.d.ts +0 -66
  299. package/dist/tools/builtin/token/TopLosersTool.d.ts.map +0 -1
  300. package/dist/tools/builtin/token/TopLosersTool.js +0 -129
  301. package/dist/tools/builtin/token/TopLosersTool.js.map +0 -1
  302. package/dist/tools/builtin/token/TrendingTokensTool.d.ts +0 -39
  303. package/dist/tools/builtin/token/TrendingTokensTool.d.ts.map +0 -1
  304. package/dist/tools/builtin/token/TrendingTokensTool.js +0 -83
  305. package/dist/tools/builtin/token/TrendingTokensTool.js.map +0 -1
  306. package/dist/tools/builtin/token/index.d.ts +0 -13
  307. package/dist/tools/builtin/token/index.d.ts.map +0 -1
  308. package/dist/tools/builtin/token/index.js +0 -16
  309. package/dist/tools/builtin/token/index.js.map +0 -1
  310. package/dist/tools/builtin/wallet/TransactionByHashTool.d.ts +0 -70
  311. package/dist/tools/builtin/wallet/TransactionByHashTool.d.ts.map +0 -1
  312. package/dist/tools/builtin/wallet/TransactionByHashTool.js +0 -111
  313. package/dist/tools/builtin/wallet/TransactionByHashTool.js.map +0 -1
  314. package/dist/tools/builtin/wallet/WalletApprovalsTool.d.ts +0 -107
  315. package/dist/tools/builtin/wallet/WalletApprovalsTool.d.ts.map +0 -1
  316. package/dist/tools/builtin/wallet/WalletApprovalsTool.js +0 -164
  317. package/dist/tools/builtin/wallet/WalletApprovalsTool.js.map +0 -1
  318. package/dist/tools/builtin/wallet/WalletDefiPositionsTool.d.ts +0 -61
  319. package/dist/tools/builtin/wallet/WalletDefiPositionsTool.d.ts.map +0 -1
  320. package/dist/tools/builtin/wallet/WalletDefiPositionsTool.js +0 -100
  321. package/dist/tools/builtin/wallet/WalletDefiPositionsTool.js.map +0 -1
  322. package/dist/tools/builtin/wallet/WalletDefiProtocolPositionsTool.d.ts +0 -68
  323. package/dist/tools/builtin/wallet/WalletDefiProtocolPositionsTool.d.ts.map +0 -1
  324. package/dist/tools/builtin/wallet/WalletDefiProtocolPositionsTool.js +0 -115
  325. package/dist/tools/builtin/wallet/WalletDefiProtocolPositionsTool.js.map +0 -1
  326. package/dist/tools/builtin/wallet/WalletDefiSummaryTool.d.ts +0 -50
  327. package/dist/tools/builtin/wallet/WalletDefiSummaryTool.d.ts.map +0 -1
  328. package/dist/tools/builtin/wallet/WalletDefiSummaryTool.js +0 -80
  329. package/dist/tools/builtin/wallet/WalletDefiSummaryTool.js.map +0 -1
  330. package/dist/tools/builtin/wallet/WalletHistoryTool.d.ts +0 -31
  331. package/dist/tools/builtin/wallet/WalletHistoryTool.d.ts.map +0 -1
  332. package/dist/tools/builtin/wallet/WalletHistoryTool.js +0 -154
  333. package/dist/tools/builtin/wallet/WalletHistoryTool.js.map +0 -1
  334. package/dist/tools/builtin/wallet/WalletNetWorthTool.d.ts +0 -44
  335. package/dist/tools/builtin/wallet/WalletNetWorthTool.d.ts.map +0 -1
  336. package/dist/tools/builtin/wallet/WalletNetWorthTool.js +0 -122
  337. package/dist/tools/builtin/wallet/WalletNetWorthTool.js.map +0 -1
  338. package/dist/tools/builtin/wallet/WalletNftTransfersTool.d.ts +0 -86
  339. package/dist/tools/builtin/wallet/WalletNftTransfersTool.d.ts.map +0 -1
  340. package/dist/tools/builtin/wallet/WalletNftTransfersTool.js +0 -265
  341. package/dist/tools/builtin/wallet/WalletNftTransfersTool.js.map +0 -1
  342. package/dist/tools/builtin/wallet/WalletPnlSummaryTool.d.ts +0 -43
  343. package/dist/tools/builtin/wallet/WalletPnlSummaryTool.d.ts.map +0 -1
  344. package/dist/tools/builtin/wallet/WalletPnlSummaryTool.js +0 -89
  345. package/dist/tools/builtin/wallet/WalletPnlSummaryTool.js.map +0 -1
  346. package/dist/tools/builtin/wallet/WalletPnlTool.d.ts +0 -43
  347. package/dist/tools/builtin/wallet/WalletPnlTool.d.ts.map +0 -1
  348. package/dist/tools/builtin/wallet/WalletPnlTool.js +0 -175
  349. package/dist/tools/builtin/wallet/WalletPnlTool.js.map +0 -1
  350. package/dist/tools/builtin/wallet/WalletTokenBalancesTool.d.ts +0 -35
  351. package/dist/tools/builtin/wallet/WalletTokenBalancesTool.d.ts.map +0 -1
  352. package/dist/tools/builtin/wallet/WalletTokenBalancesTool.js +0 -68
  353. package/dist/tools/builtin/wallet/WalletTokenBalancesTool.js.map +0 -1
  354. package/dist/tools/builtin/wallet/WalletTokenTransfersTool.d.ts +0 -109
  355. package/dist/tools/builtin/wallet/WalletTokenTransfersTool.d.ts.map +0 -1
  356. package/dist/tools/builtin/wallet/WalletTokenTransfersTool.js +0 -354
  357. package/dist/tools/builtin/wallet/WalletTokenTransfersTool.js.map +0 -1
  358. package/dist/tools/builtin/wallet/index.d.ts +0 -28
  359. package/dist/tools/builtin/wallet/index.d.ts.map +0 -1
  360. package/dist/tools/builtin/wallet/index.js +0 -32
  361. package/dist/tools/builtin/wallet/index.js.map +0 -1
  362. package/dist/tools/builtin/wallet-action/ApproveTokenTool.d.ts +0 -25
  363. package/dist/tools/builtin/wallet-action/ApproveTokenTool.d.ts.map +0 -1
  364. package/dist/tools/builtin/wallet-action/ApproveTokenTool.js +0 -98
  365. package/dist/tools/builtin/wallet-action/ApproveTokenTool.js.map +0 -1
  366. package/dist/tools/builtin/wallet-action/BaseWalletActionTool.d.ts +0 -211
  367. package/dist/tools/builtin/wallet-action/BaseWalletActionTool.d.ts.map +0 -1
  368. package/dist/tools/builtin/wallet-action/BaseWalletActionTool.js +0 -499
  369. package/dist/tools/builtin/wallet-action/BaseWalletActionTool.js.map +0 -1
  370. package/dist/tools/builtin/wallet-action/BuyTokenTool.d.ts +0 -240
  371. package/dist/tools/builtin/wallet-action/BuyTokenTool.d.ts.map +0 -1
  372. package/dist/tools/builtin/wallet-action/BuyTokenTool.js +0 -1257
  373. package/dist/tools/builtin/wallet-action/BuyTokenTool.js.map +0 -1
  374. package/dist/tools/builtin/wallet-action/SendNativeTool.d.ts +0 -41
  375. package/dist/tools/builtin/wallet-action/SendNativeTool.d.ts.map +0 -1
  376. package/dist/tools/builtin/wallet-action/SendNativeTool.js +0 -127
  377. package/dist/tools/builtin/wallet-action/SendNativeTool.js.map +0 -1
  378. package/dist/tools/builtin/wallet-action/SendTokenTool.d.ts +0 -63
  379. package/dist/tools/builtin/wallet-action/SendTokenTool.d.ts.map +0 -1
  380. package/dist/tools/builtin/wallet-action/SendTokenTool.js +0 -294
  381. package/dist/tools/builtin/wallet-action/SendTokenTool.js.map +0 -1
  382. package/dist/tools/builtin/wallet-action/SwapTokenTool.d.ts +0 -247
  383. package/dist/tools/builtin/wallet-action/SwapTokenTool.d.ts.map +0 -1
  384. package/dist/tools/builtin/wallet-action/SwapTokenTool.js +0 -1258
  385. package/dist/tools/builtin/wallet-action/SwapTokenTool.js.map +0 -1
  386. package/dist/tools/builtin/wallet-action/UnwrapNativeTool.d.ts +0 -20
  387. package/dist/tools/builtin/wallet-action/UnwrapNativeTool.d.ts.map +0 -1
  388. package/dist/tools/builtin/wallet-action/UnwrapNativeTool.js +0 -36
  389. package/dist/tools/builtin/wallet-action/UnwrapNativeTool.js.map +0 -1
  390. package/dist/tools/builtin/wallet-action/WrapNativeTool.d.ts +0 -23
  391. package/dist/tools/builtin/wallet-action/WrapNativeTool.d.ts.map +0 -1
  392. package/dist/tools/builtin/wallet-action/WrapNativeTool.js +0 -54
  393. package/dist/tools/builtin/wallet-action/WrapNativeTool.js.map +0 -1
  394. package/dist/tools/builtin/wallet-action/amountSpec.d.ts +0 -62
  395. package/dist/tools/builtin/wallet-action/amountSpec.d.ts.map +0 -1
  396. package/dist/tools/builtin/wallet-action/amountSpec.js +0 -93
  397. package/dist/tools/builtin/wallet-action/amountSpec.js.map +0 -1
  398. package/dist/tools/builtin/wallet-action/gasReserve.d.ts +0 -42
  399. package/dist/tools/builtin/wallet-action/gasReserve.d.ts.map +0 -1
  400. package/dist/tools/builtin/wallet-action/gasReserve.js +0 -103
  401. package/dist/tools/builtin/wallet-action/gasReserve.js.map +0 -1
  402. package/dist/tools/builtin/wallet-action/index.d.ts +0 -9
  403. package/dist/tools/builtin/wallet-action/index.d.ts.map +0 -1
  404. package/dist/tools/builtin/wallet-action/index.js +0 -20
  405. package/dist/tools/builtin/wallet-action/index.js.map +0 -1
  406. package/dist/tools/chainResolver.d.ts +0 -98
  407. package/dist/tools/chainResolver.d.ts.map +0 -1
  408. package/dist/tools/chainResolver.js +0 -302
  409. package/dist/tools/chainResolver.js.map +0 -1
  410. package/dist/tools/index.d.ts +0 -4
  411. package/dist/tools/index.d.ts.map +0 -1
  412. package/dist/tools/index.js +0 -23
  413. package/dist/tools/index.js.map +0 -1
  414. package/dist/types/index.d.ts +0 -777
  415. package/dist/types/index.d.ts.map +0 -1
  416. package/dist/types/index.js +0 -6
  417. package/dist/types/index.js.map +0 -1
@@ -1,1258 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SwapTokenTool = void 0;
4
- const BaseTool_1 = require("../../BaseTool");
5
- const web3_1 = require("../../../functions/web3");
6
- const MoralisService_1 = require("../../../services/MoralisService");
7
- const PantographService_1 = require("../../../services/PantographService");
8
- const swap_1 = require("../../../services/swap");
9
- const PoolService_1 = require("../../../services/PoolService");
10
- const abi_1 = require("../../../constants/abi");
11
- const amountSpec_1 = require("./amountSpec");
12
- const gasReserve_1 = require("./gasReserve");
13
- const chainResolver_1 = require("../../chainResolver");
14
- /**
15
- * Tool: open-swap-token-form
16
- *
17
- * A STANDALONE wallet-action tool (NOT a `BaseWalletActionTool`), built as the
18
- * mirror of {@link BuyTokenTool}: it does the quote + approval work itself and
19
- * ships a custom `SwapTokenConfirmTx` UI payload the FE executes directly. That's
20
- * why `swap_token` is intentionally NOT a member of `WalletActionType`.
21
- *
22
- * The defining difference from BUY: the SOURCE is a token the user ALREADY HOLDS.
23
- * Buy starts from a destination ("buy PEPE") and asks which wallet token to pay
24
- * with; swap starts from the user's own token ("swap USDC") and asks what to
25
- * receive. The source is therefore always balance-checked — we never quote a
26
- * swap the user can't fund.
27
- *
28
- * - "swap usdc to usdt" → from = USDC (held), to = USDT.
29
- * - "swap usdc" → from = USDC (held); destination unknown ⇒ trending
30
- * picker so the user picks what to receive.
31
- * - "swap" → nothing named ⇒ source picker built from the wallet's
32
- * own holdings so the user picks what to swap FROM.
33
- *
34
- * Branches, picked deterministically from the args:
35
- *
36
- * 0. **Source picker** — the user named NO source (`from_symbol`/`from_address`
37
- * empty). The tool fetches the wallet's native + ERC-20 holdings and emits
38
- * `actionButtons` so the user picks which token to swap FROM. A click
39
- * re-submits a prompt like `"swap USDC"` which routes back here.
40
- *
41
- * 1. **Destination picker (trending)** — the user named the source only. The
42
- * tool fetches the chain's live trending list (minus the source token) and
43
- * emits `actionButtons` so the user picks what to receive. A click submits a
44
- * prompt like `"swap USDC to PEPE"` which routes back for the standard flow.
45
- *
46
- * 1.4 **Balance check** — the source token is named (amount optional). Runs
47
- * before anything else so we never proceed with a token the user can't fund:
48
- * if the wallet holds NONE of it, the tool offers the tokens the user DOES
49
- * hold instead (source picker); if it holds SOME but less than the requested
50
- * amount, it reports the shortfall and emits 25/50/75/100% buttons sized off
51
- * the real balance. Skipped for the native source token.
52
- *
53
- * 1.5 **Amount picker** — source + dest known but no amount given. The tool
54
- * reads the source balance and emits 25/50/75/100% buttons so the user sizes
55
- * the swap in one tap (or types a custom amount).
56
- *
57
- * 1.75 **Confirm tx** — source + dest + a SOURCE amount are all known. The tool
58
- * fetches a swap quote (estimated receive amount + the raw swap tx), checks
59
- * allowance, and emits a `SwapTokenConfirmTx` payload bundling the estimate,
60
- * the raw swap transaction, and the approve transaction (when one is needed).
61
- * The FE executes approve (if any) then swap itself.
62
- *
63
- * When none of the above produces a result (couldn't resolve a token, quote
64
- * failed, …) the tool returns an error/_instructions object — it never opens a
65
- * generic form.
66
- *
67
- * Amount disambiguation mirrors BuyTokenTool. The swap is EXACT_INPUT (deBridge),
68
- * so the amount that seeds the quote is the SOURCE amount:
69
- * - "swap 10 USDC to USDT" → from_amount = "10"
70
- * - "swap USDC to 5 USDT" → to_amount = "5" (converted to a source amount via
71
- * live USD prices, like BuyTokenTool's buy side).
72
- */
73
- class SwapTokenTool extends BaseTool_1.BaseTool {
74
- name = 'open-swap-token-form';
75
- kind = 'action';
76
- category = 'wallet-action';
77
- // The tool drives a concrete confirm/pick step — no generic LLM follow-ups.
78
- noSuggestions = true;
79
- moralis;
80
- /** Trending tokens come from Pantograph (top-gainers), not Moralis. */
81
- pantograph;
82
- /** Branch-tracing on/off — shares AgentCore's `debug` flag (passed in). */
83
- debug;
84
- constructor(config, options) {
85
- super();
86
- if (config !== undefined) {
87
- this.moralis = new MoralisService_1.MoralisService(config);
88
- this.pantograph = new PantographService_1.PantographService({ baseUrl: config.pantographUrl });
89
- }
90
- this.debug = options?.debug ?? false;
91
- }
92
- /**
93
- * Branch-tracing logger. Prints which branch the tool takes and the key
94
- * values feeding that decision. Enabled by AgentCore's shared `debug` flag.
95
- */
96
- dbg(label, data) {
97
- if (this.debug) {
98
- if (data === undefined)
99
- console.log(`[SwapTokenTool] ${label}`);
100
- else
101
- console.log(`[SwapTokenTool] ${label}`, JSON.stringify(data));
102
- }
103
- }
104
- description = 'Open the SWAP TOKEN flow for ANY swap/exchange/convert intent where the user swaps a token they ' +
105
- 'ALREADY HOLD into another token — "swap USDC to USDT", "swap USDC", "đổi USDC sang ETH", "convert ' +
106
- 'DAI to USDC", "exchange 10 USDC for PEPE". The FROM token is the user\'s own holding (the source). ' +
107
- 'Handles both cases: (a) the user named the destination — "swap USDC to USDT": pass `from_symbol` ' +
108
- '(the source, e.g. "USDC") and `to_symbol` (the destination, e.g. "USDT"). ' +
109
- '(b) the user named only the source — "swap USDC": pass `from_symbol` and leave `to_symbol` blank; ' +
110
- "the tool returns buttons of the chain's current trending tokens so the user picks what to receive. " +
111
- 'If the user named NO token at all — "swap" / "đổi token": leave both blank and the tool returns the ' +
112
- "wallet's holdings so the user picks what to swap FROM. " +
113
- 'Amount: `from_amount` = source to SPEND; `to_amount` = destination to RECEIVE. Never both.';
114
- parameters = [
115
- { name: 'chain', type: 'string', description: 'Hex chain id. Defaults to connected chain.', required: false },
116
- {
117
- name: 'from_symbol',
118
- type: 'string',
119
- description: 'Symbol of the SOURCE token the user wants to swap FROM — a token they already hold (e.g. "USDC"). ' +
120
- 'Leave EMPTY only when the user named no token at all (e.g. "swap") — the tool then returns the ' +
121
- "wallet's holdings to pick the source from.",
122
- required: false,
123
- },
124
- {
125
- name: 'from_address',
126
- type: 'string',
127
- description: 'Source token address (0x…), OR "native" for the chain\'s native coin. Leave empty when unknown — ' +
128
- 'the tool resolves it from from_symbol.',
129
- required: false,
130
- },
131
- {
132
- name: 'from_amount',
133
- type: 'string',
134
- description: 'Quantity of the SOURCE token (the one being swapped FROM / spent) the user wants to SPEND. ' +
135
- 'Set this when the amount sits next to the source token: "swap 10 USDC to USDT", "đổi 10 USDC sang ETH" ' +
136
- '→ from_amount = the number next to USDC. May also be a PERCENT of the source balance ("swap 50% USDC ' +
137
- 'to USDT" → "50%"), the literal word "max" meaning the WHOLE balance, or a USD value ("swap $5 USDC ' +
138
- 'to USDT" → "5$"). NORMALIZE any "whole balance / everything / maximum" phrasing in ANY language ' +
139
- '(e.g. "all", "max", "tất cả", "toàn bộ", "全部", "すべて", "전부", "todo", "tout") to the literal ' +
140
- '"max"; pass plain/percent/USD numbers VERBATIM (the tool converts "%"/"$"/"max"). "max" is an AMOUNT, ' +
141
- 'never a token — still set from_symbol to the source token ("ETH" in "swap max ETH to USDC"). ' +
142
- 'Mutually exclusive with to_amount — set at most ONE of the two.',
143
- required: false,
144
- },
145
- {
146
- name: 'to_symbol',
147
- type: 'string',
148
- description: 'Symbol of the DESTINATION token the user wants to RECEIVE (e.g. "USDT"). Leave EMPTY when the user ' +
149
- 'did not name a destination (e.g. "swap USDC") — the tool then returns trending tokens to pick from.',
150
- required: false,
151
- },
152
- {
153
- name: 'to_address',
154
- type: 'string',
155
- description: 'Destination token address (0x…), OR "native" for the chain\'s native coin. Leave empty when unknown — ' +
156
- 'the tool resolves it from to_symbol.',
157
- required: false,
158
- },
159
- {
160
- name: 'to_amount',
161
- type: 'string',
162
- description: 'Quantity of the DESTINATION token (the one being received) the user wants to RECEIVE. ' +
163
- 'Set this when the amount sits next to the destination token: "swap USDC to 5 USDT" → to_amount = the ' +
164
- 'number next to USDT. May also be a USD value ("swap USDC to $5 USDT" → "5$"); pass the user\'s ' +
165
- 'expression VERBATIM (the tool converts "$"). Mutually exclusive with from_amount — set at most ONE.',
166
- required: false,
167
- },
168
- {
169
- name: 'limit',
170
- type: 'number',
171
- description: 'Only used when no destination is named: max number of trending tokens to show as buttons. Default 6. Clamped to [1, 10].',
172
- required: false,
173
- },
174
- {
175
- name: 'swap_from_prompt_template',
176
- type: 'string',
177
- description: 'A short "swap {token}" command IN THE USER\'S CURRENT LANGUAGE, used as the click-command for the ' +
178
- 'source picker (when the user named no token). Use the exact placeholder "{token}" (do not translate the ' +
179
- 'braces) for the source symbol; put the localized verb directly in the text. ' +
180
- 'English example: "swap {token}". Vietnamese example: "đổi {token}". Japanese example: "{token} をスワップ". ' +
181
- 'Always include {token}.',
182
- required: true,
183
- },
184
- {
185
- name: 'swap_to_prompt_template',
186
- type: 'string',
187
- description: 'A short "swap X to Y" command IN THE USER\'S CURRENT LANGUAGE, used as the click-command for the ' +
188
- 'destination (trending) picker and the percentage-spend buttons. Use these exact placeholders (do not ' +
189
- 'translate the braces): "{from}" = source token, "{to}" = destination token, "{from_amount}" = quantity ' +
190
- 'of the SOURCE token (place it next to {from}), "{to_amount}" = quantity of the DESTINATION token (place ' +
191
- 'it next to {to}). Put the localized verb and the "to" preposition directly in the text. ' +
192
- 'English example: "swap {from_amount} {from} to {to_amount} {to}". ' +
193
- 'Vietnamese example: "đổi {from_amount} {from} sang {to_amount} {to}". ' +
194
- 'Japanese example: "{from_amount} {from} を {to_amount} {to} にスワップ". ' +
195
- 'Always include {from} and {to}. Include both {from_amount} and {to_amount} too — the tool removes ' +
196
- 'whichever amount is unknown (only one side ever carries an amount).',
197
- required: true,
198
- },
199
- ];
200
- // -------------------------------------------------------------------------
201
- // execute: lift `ui` / `actionButtons` from run() onto the ToolResult.
202
- // -------------------------------------------------------------------------
203
- async execute(args, userContext) {
204
- const callId = `call_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
205
- const start = Date.now();
206
- try {
207
- const out = (await this.run(args, userContext));
208
- const result = {
209
- toolName: this.name,
210
- callId,
211
- success: true,
212
- data: out,
213
- duration: Date.now() - start,
214
- };
215
- if (out && typeof out === 'object' && out.ui) {
216
- result.ui = out.ui;
217
- }
218
- if (out && Array.isArray(out.actionButtons) && out.actionButtons.length > 0) {
219
- result.actionButtons = out.actionButtons;
220
- }
221
- return result;
222
- }
223
- catch (err) {
224
- return {
225
- toolName: this.name,
226
- callId,
227
- success: false,
228
- error: err instanceof Error ? err.message : String(err),
229
- duration: Date.now() - start,
230
- };
231
- }
232
- }
233
- async run(args, userContext) {
234
- const walletAddress = userContext?.walletAddress;
235
- if (!walletAddress) {
236
- return {
237
- error: 'wallet_not_connected',
238
- _instructions: 'The user is not connected. Ask them to connect their wallet before swapping. Do NOT proceed.',
239
- };
240
- }
241
- // The wallet can only sign on the chain it's connected to. If the user named
242
- // a chain that differs from their connected chain, ask them to switch first
243
- // instead of building a swap they can't sign.
244
- const mismatch = (0, chainResolver_1.detectChainMismatch)(args.chain, userContext);
245
- if (mismatch) {
246
- return {
247
- error: 'wrong_chain',
248
- _instructions: `The user asked to swap on ${mismatch.requestedLabel}, but their wallet is connected to ${mismatch.connectedLabel}. ` +
249
- `Tell them, in their language, that to swap on ${mismatch.requestedLabel} they must first switch their wallet's network to ${mismatch.requestedLabel}, ` +
250
- `or they can swap on ${mismatch.connectedLabel} (their current network) instead. Do NOT proceed. Do NOT mention tool names, UI, or forms.`,
251
- };
252
- }
253
- const chainId = this.requireChain(args, userContext);
254
- if (!chainId) {
255
- return {
256
- error: 'missing_chain',
257
- _instructions: 'No chain is set. Pass the hex chain id explicitly (e.g. "0x1") or set userContext.chain before calling.',
258
- };
259
- }
260
- return this.buildResult(args, userContext);
261
- }
262
- // -------------------------------------------------------------------------
263
- // Main branch dispatch
264
- // -------------------------------------------------------------------------
265
- async buildResult(args, userContext) {
266
- const fromSymbol = typeof args.from_symbol === 'string' ? args.from_symbol.trim() : '';
267
- const fromRef = typeof args.from_address === 'string' ? args.from_address.trim() : '';
268
- const toSymbol = typeof args.to_symbol === 'string' ? args.to_symbol.trim() : '';
269
- const chain = this.requireChain(args, userContext) ?? undefined;
270
- const walletAddress = userContext?.walletAddress ?? undefined;
271
- this.dbg('buildResult:args', { args, chain, walletAddress, hasMoralis: !!this.moralis });
272
- // ----- Branch 0: SOURCE PICKER — no source token named at all ----------
273
- if (!fromSymbol && !fromRef) {
274
- this.dbg('→ Branch 0: source picker (no source token named)');
275
- return await this.buildSourcePicker(args, userContext);
276
- }
277
- // ----- Resolve SOURCE token (symbol/address → address + decimals) ------
278
- const fromSide = await this.resolveSide(args.from_address, fromSymbol, chain, walletAddress, 'from');
279
- const fromContract = fromSide.address;
280
- const fromSym = fromSide.symbol ?? fromSymbol;
281
- const fromDecimals = fromSide.decimals;
282
- // ----- Resolve DEST token (if user gave one) ---------------------------
283
- const toSide = await this.resolveSide(args.to_address, toSymbol, chain, walletAddress, 'to');
284
- const toContract = toSide.address;
285
- const toSym = toSide.symbol ?? toSymbol;
286
- const toDecimals = toSide.decimals;
287
- // Amounts may be plain ("10"), a percent of balance ("50%"), or a USD value
288
- // ("5$"). From-side percent/usd resolve against the SOURCE token's
289
- // balance/price; to-side usd resolves against the DEST token's price (percent
290
- // on the to side is meaningless, so it's ignored).
291
- const toAmount = await this.resolveToAmountSpec(args.to_amount, toContract, chain, toSym);
292
- let fromAmount = fromContract
293
- ? await this.resolveFromAmountSpec(args.from_amount, fromContract, chain, walletAddress, fromSym)
294
- : this.normaliseAmount(args.from_amount);
295
- // Whether the from amount was sized off the balance (percent / "max" / usd):
296
- // such an amount is ≤ spendable by construction, so the balance check skips
297
- // the over-balance comparison for it (a re-read spendable can drift a hair).
298
- const fromSpec = (0, amountSpec_1.parseAmountSpec)(args.from_amount);
299
- let amountSizedToBalance = !!fromSpec && fromSpec.kind !== 'token';
300
- // Set to the to-side amount once we convert it into `fromAmount` (Branch 1.3)
301
- // so downstream messaging can explain the conversion.
302
- let derivedFromTo = null;
303
- this.dbg('resolved sides', {
304
- from: { fromContract, fromSym, fromDecimals },
305
- to: { toContract, toSym, toDecimals },
306
- fromAmount,
307
- toAmount,
308
- });
309
- // Could not resolve the source token — surface it (never open a form).
310
- if (!fromContract) {
311
- this.dbg('→ source token not resolved');
312
- return {
313
- error: 'from_token_not_found',
314
- _instructions: `Could not find the token "${fromSym || fromRef}" to swap from on this chain. ` +
315
- 'Tell the user, in their language, that the token could not be found and ask them to check the name ' +
316
- 'or provide its contract address. Do NOT invent an address. Do NOT mention tool names, UI, or forms.',
317
- };
318
- }
319
- // ----- Branch 1: DEST PICKER (trending) — source known, dest missing ---
320
- if (!toContract && this.moralis && userContext?.walletAddress) {
321
- this.dbg('→ Branch 1: destination picker (dest token missing)');
322
- return await this.buildToTrendingPicker({ args, userContext, fromSym, fromContract, fromAmount, toAmount });
323
- }
324
- if (!toContract) {
325
- return {
326
- error: 'to_token_missing',
327
- _instructions: `Ask the user, in their language, which token they want to receive when swapping ${fromSym}. ` +
328
- 'Do NOT invent a token. Do NOT mention tool names, UI, or forms.',
329
- };
330
- }
331
- // ----- Branch 1.3: TO-SIDE AMOUNT → FROM AMOUNT ------------------------
332
- // deBridge only supports EXACT_INPUT (spend X, receive ~Y). When the user
333
- // sized the TO side instead ("swap USDC to 5 USDT") we have no source amount
334
- // to seed the quote — derive one from the live USD price ratio
335
- // (fromAmount ≈ toAmount × toPrice / fromPrice, +2% buffer for slippage/fees
336
- // so they receive AT LEAST about the requested amount). The derived amount
337
- // then flows through the SAME balance-check + confirm-tx path below.
338
- if (toAmount && !fromAmount) {
339
- this.dbg('Branch 1.3: deriving from amount from to amount', { toAmount, fromSym, toSym });
340
- const derived = await this.deriveFromAmountFromTo({
341
- chain,
342
- toAmount,
343
- toContract,
344
- toSym,
345
- fromContract,
346
- fromSym,
347
- });
348
- if (!derived) {
349
- this.dbg('→ Branch 1.3: price unavailable — needs from amount');
350
- return {
351
- error: 'needs_from_amount',
352
- _instructions: `Could not work out how much ${fromSym ?? 'of the source token'} equals ${toAmount} ${toSym} right now. ` +
353
- `Tell the user, in their language, that the price couldn't be fetched at the moment, and ask how much ${fromSym ?? 'of the source token'} they want to swap instead. ` +
354
- 'Do NOT invent an amount or a price. Do NOT mention tool names, UI, or forms.',
355
- };
356
- }
357
- fromAmount = derived;
358
- derivedFromTo = toAmount;
359
- // A derived amount is a real cost that CAN exceed the balance — it must be
360
- // checked (it was sized off the dest amount, not off the source balance).
361
- amountSizedToBalance = false;
362
- this.dbg('→ Branch 1.3: derived from amount', { fromAmount, derivedFromTo });
363
- }
364
- // ----- Branch 1.4: BALANCE CHECK — source token named ------------------
365
- // Native is included: its spendable balance (held − gas reserve) is read by
366
- // readFromBalance, so an amount that wouldn't leave room for gas is caught
367
- // here just like an over-balance ERC-20 amount.
368
- if (this.moralis && userContext?.walletAddress) {
369
- this.dbg('Branch 1.4: checking source balance', { fromContract, fromSym, fromAmount });
370
- const shortfall = await this.checkFromBalance({
371
- args,
372
- userContext,
373
- chain,
374
- fromContract,
375
- fromSym,
376
- fromAmount,
377
- toAmount,
378
- derivedFromTo,
379
- amountSizedToBalance,
380
- });
381
- if (shortfall) {
382
- this.dbg('→ Branch 1.4: balance shortfall — returning', {
383
- error: shortfall.error,
384
- hasButtons: Array.isArray(shortfall.actionButtons),
385
- });
386
- return shortfall;
387
- }
388
- this.dbg('Branch 1.4: balance OK — continuing');
389
- }
390
- // ----- Branch 1.5: AMOUNT PICKER — source + dest known, no amount ------
391
- if (!fromAmount && !toAmount && this.moralis && userContext?.walletAddress) {
392
- this.dbg('Branch 1.5: building amount picker');
393
- const picker = await this.buildAmountPicker({
394
- userContext,
395
- chain,
396
- fromContract,
397
- fromSym,
398
- toSym,
399
- swapToTemplate: typeof args.swap_to_prompt_template === 'string' ? args.swap_to_prompt_template : '',
400
- });
401
- if (picker) {
402
- this.dbg('→ Branch 1.5: amount picker returned');
403
- return picker;
404
- }
405
- this.dbg('Branch 1.5: amount picker null — needs amount');
406
- }
407
- // ----- Branch 1.75: BUILD CONFIRM TX -----------------------------------
408
- // Everything is known AND the spend is expressed as a source-token amount
409
- // (EXACT_INPUT): estimate, build raw swap tx, check approval, ship the cube.
410
- if (fromAmount && (fromDecimals !== undefined || fromContract === 'native')) {
411
- this.dbg('Branch 1.75: building confirm tx');
412
- const confirm = await this.buildConfirmTx({
413
- userContext,
414
- chain,
415
- toContract,
416
- toSym,
417
- toDecimals,
418
- fromContract,
419
- fromSym,
420
- fromDecimals,
421
- fromAmount,
422
- });
423
- if (confirm && 'ui' in confirm) {
424
- this.dbg('→ Branch 1.75: confirm tx returned');
425
- return confirm;
426
- }
427
- // The swap provider returned a concrete reason — relay it to the user.
428
- if (confirm && 'quoteError' in confirm) {
429
- this.dbg('→ Branch 1.75: quote error from provider', { quoteError: confirm.quoteError });
430
- return {
431
- error: 'quote_failed',
432
- quoteError: confirm.quoteError,
433
- _instructions: `Could not quote swapping ${fromSym ?? 'the source token'} to ${toSym}. The swap provider reported: "${confirm.quoteError}". ` +
434
- 'Tell the user, in their language, exactly that reason (translate the wording, keep any numbers/limits verbatim) and suggest they adjust the amount or try again shortly. ' +
435
- 'Do NOT invent numbers or a different reason. Do NOT mention tool names, UI, or forms.',
436
- };
437
- }
438
- // null — couldn't even attempt a quote (bad chain, missing decimals, …).
439
- this.dbg('Branch 1.75: confirm tx unavailable (null)');
440
- return {
441
- error: 'quote_failed',
442
- _instructions: `Could not get a quote to swap ${fromSym ?? 'the source token'} to ${toSym} right now. ` +
443
- 'Tell the user, in their language, that the swap could not be quoted at the moment and ask them to try ' +
444
- 'again shortly or with a different amount. Do NOT invent numbers. Do NOT mention tool names, UI, or forms.',
445
- };
446
- }
447
- // The only thing missing is a spendable amount (or it was given on the to
448
- // side, which EXACT_INPUT can't seed off). Ask the user to size the spend.
449
- this.dbg('→ needs from amount');
450
- return {
451
- error: 'needs_from_amount',
452
- _instructions: `Ask the user, in their language, how much ${fromSym ?? 'of the source token'} they want to swap to ${toSym}. ` +
453
- 'Do NOT invent an amount. Do NOT mention tool names, UI, or forms.',
454
- };
455
- }
456
- // -------------------------------------------------------------------------
457
- // Token resolution (standalone — no BaseWalletActionTool dependency)
458
- // -------------------------------------------------------------------------
459
- normaliseAddress(value) {
460
- if (typeof value !== 'string')
461
- return null;
462
- const v = value.trim();
463
- return (0, web3_1.isAddressEVM)(v) ? v : null;
464
- }
465
- normaliseAmount(value) {
466
- if (typeof value === 'number' && Number.isFinite(value) && value > 0)
467
- return String(value);
468
- if (typeof value !== 'string')
469
- return null;
470
- const v = value.trim();
471
- if (!v)
472
- return null;
473
- const n = parseFloat(v);
474
- return Number.isFinite(n) && n > 0 ? v : null;
475
- }
476
- requireChain(args, userContext) {
477
- const fromArgs = typeof args.chain === 'string' && args.chain.trim() ? args.chain.trim() : null;
478
- if (fromArgs)
479
- return fromArgs;
480
- return typeof userContext?.chain === 'string' && userContext.chain.trim() ? userContext.chain.trim() : null;
481
- }
482
- /**
483
- * Resolve a token reference (symbol "USDC" or address "0x…") on a chain.
484
- * Wallet balances first (most reliable), then Pantograph search. Decimals come
485
- * from the API — never from the LLM.
486
- */
487
- async resolveContractAddress(key, chain, walletAddress) {
488
- if (!this.moralis || !key)
489
- return undefined;
490
- const keyLower = key.trim().toLowerCase();
491
- const keyIsAddress = (0, web3_1.isAddressEVM)(key.trim());
492
- const matches = (t) => keyIsAddress ? (t.token_address ?? '').toLowerCase() === keyLower : (t.symbol ?? '').toLowerCase() === keyLower;
493
- if (walletAddress) {
494
- const balRes = await this.moralis.getWalletTokenBalances({ address: walletAddress, chain });
495
- if (balRes.success && balRes.data?.result?.length) {
496
- const match = balRes.data.result.find(matches);
497
- if (match) {
498
- return {
499
- address: match.token_address,
500
- symbol: match.symbol,
501
- name: match.name,
502
- decimals: typeof match.decimals === 'number' ? match.decimals : undefined,
503
- };
504
- }
505
- }
506
- }
507
- const searchRes = await this.moralis.searchTokensByKey({ key, chain });
508
- if (searchRes.success && searchRes.data?.length) {
509
- const exact = searchRes.data.find(matches);
510
- const candidate = exact ?? searchRes.data[0];
511
- if (candidate?.token_address) {
512
- return {
513
- address: candidate.token_address,
514
- symbol: candidate.symbol,
515
- name: candidate.name,
516
- decimals: typeof candidate.decimals === 'number' ? candidate.decimals : undefined,
517
- };
518
- }
519
- }
520
- return undefined;
521
- }
522
- /**
523
- * Resolve one side of the swap (from or to). Honours the `"native"` sentinel
524
- * the swap providers expect. Never errors — a side that can't be resolved
525
- * just comes back with `address: null`.
526
- */
527
- async resolveSide(refArg, symbolArg, chain, walletAddress, label = 'side') {
528
- const refStr = typeof refArg === 'string' ? refArg.trim() : '';
529
- const symbolStr = typeof symbolArg === 'string' ? symbolArg.trim() : '';
530
- if (refStr.toLowerCase() === 'native' || symbolStr.toLowerCase() === 'native') {
531
- return { address: 'native', symbol: symbolStr || undefined };
532
- }
533
- const directAddress = this.normaliseAddress(refArg);
534
- const symbolHint = symbolStr || undefined;
535
- // The native coin surfaces as the zero address (in wallet balances, or when a
536
- // user pastes it) — map it back to the 'native' sentinel so downstream native
537
- // handling kicks in: gas-reserve deduction, approval skip, native-side quote.
538
- const toNative = (addr) => (addr.toLowerCase() === PoolService_1.ZERO_ADDRESS ? 'native' : addr);
539
- const key = directAddress ?? symbolHint ?? (refStr || undefined);
540
- if (!key) {
541
- this.dbg(`resolveSide:${label}`, { refStr, symbolStr, chain, resolved: 'none' });
542
- return { address: null, symbol: symbolHint };
543
- }
544
- const lookup = await this.resolveContractAddress(key, chain, walletAddress);
545
- this.dbg(`resolveSide:${label}`, { refStr, symbolStr, chain, key, lookup });
546
- if (!lookup) {
547
- // A concrete address with no enrichment — still usable.
548
- if (directAddress)
549
- return { address: toNative(directAddress), symbol: symbolHint };
550
- return { address: null, symbol: symbolHint };
551
- }
552
- return { address: toNative(lookup.address), symbol: symbolHint ?? lookup.symbol, decimals: lookup.decimals };
553
- }
554
- // -------------------------------------------------------------------------
555
- // Branch 1.75: build confirm tx (estimate + raw swap tx + approve)
556
- // -------------------------------------------------------------------------
557
- /**
558
- * Source token + dest token + a source-token amount are known. Fetch a swap
559
- * quote (estimated receive amount + raw swap tx), check approval, and return a
560
- * `SwapTokenConfirmTx` UI payload the FE executes itself. Returns `null` when
561
- * anything we need can't be produced (bad chain, quote failed, non-EVM tx).
562
- */
563
- async buildConfirmTx(input) {
564
- const { userContext, chain, toContract, toSym, toDecimals, fromContract, fromSym, fromDecimals, fromAmount } = input;
565
- const walletAddress = userContext?.walletAddress;
566
- if (!walletAddress || !chain || !toContract)
567
- return null;
568
- const meta = (0, PoolService_1.getChainMeta)(chain);
569
- const numericChainId = Number.parseInt(chain, 16);
570
- if (!meta || !Number.isFinite(numericChainId))
571
- return null;
572
- // Native source token needs no decimals (chain meta) and never approves.
573
- const fromIsNative = fromContract === 'native';
574
- const fromDec = fromIsNative ? (meta.native.decimals ?? 18) : fromDecimals;
575
- if (fromDec === undefined)
576
- return null;
577
- const rawAmount = this.toRawAmount(fromAmount, fromDec);
578
- if (!rawAmount)
579
- return null;
580
- // Providers want a concrete address for the native side; both accept zero.
581
- const srcTokenAddress = fromIsNative ? PoolService_1.ZERO_ADDRESS : fromContract;
582
- const dstTokenAddress = toContract === 'native' ? PoolService_1.ZERO_ADDRESS : toContract;
583
- let quote;
584
- try {
585
- const service = await swap_1.swapServiceFactory.getServiceByProvider('debridge');
586
- quote = await service.getQuote({
587
- srcChainId: numericChainId,
588
- srcTokenAddress,
589
- srcTokenAmount: rawAmount,
590
- dstChainId: numericChainId,
591
- dstTokenAddress,
592
- recipientAddress: walletAddress,
593
- senderAddress: walletAddress,
594
- slippage: 'auto',
595
- isCrossChain: false,
596
- });
597
- }
598
- catch (err) {
599
- // Network/throw — surface the message so the user sees the real reason.
600
- return { quoteError: err instanceof Error ? err.message : String(err) };
601
- }
602
- // The provider returned a structured failure — forward its reason verbatim.
603
- if (!quote.success) {
604
- this.dbg('buildConfirmTx: quote failed', { error: quote.error, errorMessage: quote.errorMessage });
605
- return { quoteError: this.extractQuoteError(quote) };
606
- }
607
- if (!quote.tx)
608
- return { quoteError: 'No route available for this swap.' };
609
- const tx = quote.tx;
610
- if (!tx.to || typeof tx.data !== 'string')
611
- return null; // non-EVM payload.
612
- const swapTx = {
613
- chainId: chain,
614
- to: tx.to,
615
- data: tx.data,
616
- value: tx.value ?? '0',
617
- from: walletAddress,
618
- };
619
- // Estimated receive amount of the dest token (provider-specific shape).
620
- const estimatedOutRaw = this.extractOutRaw(quote);
621
- const estimatedOut = estimatedOutRaw && toDecimals !== undefined
622
- ? this.trimAmount(Number(estimatedOutRaw) / 10 ** toDecimals)
623
- : undefined;
624
- // Approval: native never approves; otherwise ask the provider.
625
- let approveTx;
626
- if (!fromIsNative) {
627
- approveTx = await this.buildApproveTx({
628
- chain,
629
- walletAddress,
630
- fromAddr: fromContract,
631
- fromDec,
632
- rawAmount,
633
- quote,
634
- });
635
- }
636
- const props = {
637
- chain: { hexId: chain, name: meta.name },
638
- fromToken: {
639
- address: fromIsNative ? 'native' : fromContract,
640
- symbol: fromSym,
641
- decimals: fromDec,
642
- amount: fromAmount,
643
- rawAmount,
644
- },
645
- toToken: {
646
- address: toContract,
647
- symbol: toSym,
648
- decimals: toDecimals,
649
- amount: estimatedOut,
650
- rawAmount: estimatedOutRaw,
651
- },
652
- estimatedOut,
653
- estimatedOutRaw,
654
- provider: quote.provider,
655
- swapTx,
656
- approveTx,
657
- };
658
- const ui = { component: 'SwapTokenConfirmTx', props };
659
- const estPart = estimatedOut ? ` They will receive about ${estimatedOut} ${toSym}.` : '';
660
- return {
661
- ui: ui,
662
- _instructions: `A confirmation panel has been opened for swapping ${fromAmount} ${fromSym ?? 'the source token'} to ${toSym}.${estPart} ` +
663
- 'Briefly tell the user, in their language, the amount they are swapping and the estimated amount they will receive, ' +
664
- 'and ask them to review and confirm to complete the swap. The estimate is approximate — say "about"/"estimated", never a guaranteed amount. ' +
665
- 'NEVER invent numbers not provided here. Do NOT mention tool names, UI, forms, or internal steps like approval.',
666
- };
667
- }
668
- // -------------------------------------------------------------------------
669
- // Branch 1.3: derive a from amount from a to-side amount via USD prices
670
- // -------------------------------------------------------------------------
671
- /**
672
- * deBridge only quotes EXACT_INPUT, so a "swap to X of the dest token" request
673
- * has no input amount to seed the quote. Convert the desired output into a
674
- * source-token amount using each side's live USD price:
675
- *
676
- * fromAmount ≈ (toAmount × toPriceUsd) / fromPriceUsd × (1 + buffer)
677
- *
678
- * The +2% buffer covers slippage + fees so the user receives AT LEAST roughly
679
- * the requested amount (the confirm panel still shows the REAL estimate from
680
- * the quote, not this derived figure). Returns `null` when either token's USD
681
- * price can't be fetched — the caller then asks for a from amount instead.
682
- */
683
- async deriveFromAmountFromTo(input) {
684
- const { chain, toAmount, toContract, fromContract } = input;
685
- const [toPrice, fromPrice] = await Promise.all([
686
- this.getUsdPrice(toContract, chain),
687
- this.getUsdPrice(fromContract, chain),
688
- ]);
689
- this.dbg('deriveFromAmountFromTo: prices', { toPrice, fromPrice });
690
- if (!toPrice || !fromPrice)
691
- return null;
692
- const toNum = Number(toAmount);
693
- if (!Number.isFinite(toNum) || toNum <= 0)
694
- return null;
695
- const BUFFER = 1.02; // +2% headroom for slippage + provider/protocol fees.
696
- const rawFrom = (toNum * toPrice) / fromPrice;
697
- if (!Number.isFinite(rawFrom) || rawFrom <= 0)
698
- return null;
699
- return this.trimAmount(rawFrom * BUFFER);
700
- }
701
- /**
702
- * Best-effort live USD price for one side of the swap, sourced from
703
- * Pantograph (via `MoralisService.getTokenMetadata`). The native coin
704
- * (`'native'`) is looked up with the zero address. Returns `null` when no
705
- * positive price is available so the caller can degrade gracefully.
706
- */
707
- async getUsdPrice(tokenAddrOrNative, chain) {
708
- if (!this.moralis)
709
- return null;
710
- const address = tokenAddrOrNative === 'native' ? PoolService_1.ZERO_ADDRESS : tokenAddrOrNative;
711
- const res = await this.moralis.getTokenMetadata({ address, chain });
712
- const price = res.success ? res.data?.usd_price : undefined;
713
- return typeof price === 'number' && Number.isFinite(price) && price > 0 ? price : null;
714
- }
715
- // -------------------------------------------------------------------------
716
- // Amount-spec resolution ("50%" / "5$" / plain) for the from / to sides
717
- // -------------------------------------------------------------------------
718
- /**
719
- * Resolve the FROM-side amount, which may be plain ("10"), a PERCENT of the
720
- * held source-token balance ("50%"), or a USD value ("5$"). Percent reads the
721
- * wallet's source-token balance; usd divides by the source token's USD price.
722
- * Returns a plain token amount string, or `null` when nothing usable was given
723
- * / the balance or price needed for a percent/usd couldn't be fetched.
724
- */
725
- async resolveFromAmountSpec(rawAmount, fromAddr, chain, walletAddress, fromSym) {
726
- const spec = (0, amountSpec_1.parseAmountSpec)(rawAmount);
727
- if (!spec)
728
- return null;
729
- if (spec.kind === 'token')
730
- return this.trimAmount(spec.value);
731
- if (spec.kind === 'percent') {
732
- if (!walletAddress)
733
- return null;
734
- const bal = await this.readFromBalance(walletAddress, fromAddr, chain);
735
- this.dbg('resolveFromAmountSpec: percent', { percent: spec.percent, fromSym, bal: bal?.balanceNum });
736
- if (!bal || !Number.isFinite(bal.balanceNum) || bal.balanceNum <= 0)
737
- return null;
738
- // 100% ("max"/"all") spends the EXACT spendable balance string, never a
739
- // re-rounded number — `trimAmount` can round UP, which would then trip the
740
- // balance check (a second gas-reserve read can land a hair lower). The
741
- // exact string is the gas-aware spendable for native (readFromBalance) or
742
- // the held balance for an ERC-20.
743
- if (spec.percent >= 100)
744
- return this.cleanAmountString(bal.balanceFormatted);
745
- return this.trimAmount((bal.balanceNum * spec.percent) / 100);
746
- }
747
- // usd
748
- const price = await this.getUsdPrice(fromAddr, chain);
749
- this.dbg('resolveFromAmountSpec: usd', { usd: spec.usd, fromSym, price });
750
- if (!price)
751
- return null;
752
- return this.trimAmount(spec.usd / price);
753
- }
754
- /**
755
- * Resolve the TO-side amount, which may be plain ("5") or a USD value ("5$").
756
- * USD divides by the DEST token's price to get how many dest tokens "$X worth"
757
- * is — that token figure then flows through Branch 1.3 to derive the from
758
- * amount. A PERCENT on the to side is meaningless, so it's ignored (returns
759
- * null). Returns a plain token amount string or `null`.
760
- */
761
- async resolveToAmountSpec(rawAmount, toContract, chain, toSym) {
762
- const spec = (0, amountSpec_1.parseAmountSpec)(rawAmount);
763
- if (!spec)
764
- return null;
765
- if (spec.kind === 'token')
766
- return this.trimAmount(spec.value);
767
- if (spec.kind === 'percent')
768
- return null; // not meaningful for the to side.
769
- // usd → dest-token quantity via the dest price.
770
- if (!toContract)
771
- return null;
772
- const price = await this.getUsdPrice(toContract, chain);
773
- this.dbg('resolveToAmountSpec: usd', { usd: spec.usd, toSym, price });
774
- if (!price)
775
- return null;
776
- return this.trimAmount(spec.usd / price);
777
- }
778
- /**
779
- * Check whether the source token needs an allowance for this swap and, if so,
780
- * return a ready-to-sign ERC-20 approve tx. deBridge only reports the spender
781
- * (`tx.to`), so we encode the approve calldata ourselves; integrated providers
782
- * (Relay) hand back the approve tx directly.
783
- */
784
- async buildApproveTx(input) {
785
- const { chain, walletAddress, fromAddr, fromDec, rawAmount, quote } = input;
786
- try {
787
- const service = await swap_1.swapServiceFactory.getServiceByProvider('debridge');
788
- const approval = await service.checkApproval({
789
- chain,
790
- userAddress: walletAddress,
791
- tokenAddress: fromAddr,
792
- amount: rawAmount,
793
- tokenDecimals: fromDec,
794
- quoteData: quote,
795
- });
796
- if (!approval.isNeeded)
797
- return undefined;
798
- // Integrated providers (Relay) hand back the approve tx directly.
799
- const data = (approval.approvalData ?? {});
800
- if (data.to && typeof data.data === 'string') {
801
- return { chainId: chain, to: data.to, data: data.data, value: data.value ?? '0', from: walletAddress };
802
- }
803
- // deBridge: we only know the spender (the swap router). Encode approve().
804
- const spender = approval.contractAddress;
805
- if (!spender)
806
- return undefined;
807
- const approveData = (0, web3_1.encodeFunctionData)({
808
- abi: abi_1.erc20Abi,
809
- functionName: 'approve',
810
- args: [spender, BigInt(rawAmount)],
811
- });
812
- return { chainId: chain, to: fromAddr, data: approveData, value: '0', from: walletAddress };
813
- }
814
- catch {
815
- return undefined;
816
- }
817
- }
818
- /** Human amount → smallest-unit decimal string (no float drift via BigInt). */
819
- toRawAmount(human, decimals) {
820
- const trimmed = human.trim();
821
- if (!/^\d*\.?\d+$/.test(trimmed))
822
- return null;
823
- const [intPart, fracPartRaw = ''] = trimmed.split('.');
824
- const fracPart = fracPartRaw.slice(0, decimals).padEnd(decimals, '0');
825
- try {
826
- const raw = BigInt(intPart || '0') * 10n ** BigInt(decimals) + BigInt(fracPart || '0');
827
- return raw <= 0n ? null : raw.toString();
828
- }
829
- catch {
830
- return null;
831
- }
832
- }
833
- /**
834
- * Pull a human-readable failure reason out of a failed quote. Adapters set
835
- * `errorMessage` (string) and `error` (string or a provider object). deBridge
836
- * also nests a reason in `raw.errorMessage` / `raw.error`. Falls back to a
837
- * generic line so the caller always has something to show.
838
- */
839
- extractQuoteError(quote) {
840
- if (quote.errorMessage && quote.errorMessage.trim())
841
- return quote.errorMessage.trim();
842
- const fromError = (e) => {
843
- if (typeof e === 'string' && e.trim())
844
- return e.trim();
845
- if (e && typeof e === 'object') {
846
- const o = e;
847
- for (const v of [o.message, o.errorMessage, o.error]) {
848
- if (typeof v === 'string' && v.trim())
849
- return v.trim();
850
- }
851
- }
852
- return undefined;
853
- };
854
- const raw = (quote.raw ?? {});
855
- return (fromError(quote.error) ??
856
- fromError(raw.errorMessage) ??
857
- fromError(raw.error) ??
858
- 'The swap could not be quoted right now.');
859
- }
860
- /**
861
- * Estimated receive amount in the dest token's smallest units. Shape differs
862
- * per provider — deBridge same-chain: `raw.tokenOut.minAmount`; deBridge
863
- * cross-chain: `raw.estimation.dstChainTokenOut.amount`; Relay:
864
- * `raw.details.currencyOut.{amount|minimumAmount}`.
865
- */
866
- extractOutRaw(quote) {
867
- const raw = (quote.raw ?? {});
868
- const candidate = raw.tokenOut?.amount ??
869
- raw.tokenOut?.minAmount ??
870
- raw.details?.currencyOut?.amount ??
871
- raw.details?.currencyOut?.minimumAmount ??
872
- raw.estimation?.dstChainTokenOut?.recommendedAmount ??
873
- raw.estimation?.dstChainTokenOut?.amount;
874
- return candidate && /^\d+$/.test(candidate) ? candidate : undefined;
875
- }
876
- // -------------------------------------------------------------------------
877
- // Branch 0: source picker (user named no token — pick from wallet holdings)
878
- // -------------------------------------------------------------------------
879
- async buildSourcePicker(args, userContext) {
880
- if (!this.moralis || !userContext?.walletAddress) {
881
- return {
882
- error: 'source_unavailable',
883
- _instructions: 'Cannot list the wallet holdings in this build. Tell the user briefly and ask them to name the token they want to swap from.',
884
- };
885
- }
886
- const chain = this.requireChain(args, userContext) ?? undefined;
887
- const walletAddress = userContext.walletAddress;
888
- const balancesRes = await this.moralis.getWalletTokenBalances({
889
- address: walletAddress,
890
- chain,
891
- excludeSpam: true,
892
- excludeUnverifiedContracts: true,
893
- });
894
- const balances = balancesRes.success ? (balancesRes.data?.result ?? []) : [];
895
- // Include native + ERC-20s the wallet actually holds — these are swappable.
896
- const holdings = balances
897
- .filter((t) => {
898
- if (!t.symbol)
899
- return false;
900
- if (t.native_token)
901
- return true;
902
- return !!t.token_address;
903
- })
904
- .sort((a, b) => (b.usd_value ?? 0) - (a.usd_value ?? 0))
905
- .slice(0, 8);
906
- if (holdings.length === 0) {
907
- return {
908
- error: 'no_swap_holdings',
909
- _instructions: 'The wallet holds no tokens to swap on this chain. Tell the user to top up first. Do NOT mention tool names, UI, or forms.',
910
- };
911
- }
912
- // Click-prompt is re-submitted as a fresh user turn → phrase it in the
913
- // user's language via the LLM-supplied "swap {token}" template.
914
- const swapFromTemplate = typeof args.swap_from_prompt_template === 'string' ? args.swap_from_prompt_template : '';
915
- const actionButtons = holdings.map((t) => {
916
- const sym = t.symbol;
917
- const name = t.name?.trim() || sym;
918
- const amount = t.balance_formatted ? `${this.cleanAmountString(t.balance_formatted)} ` : '';
919
- const usdLabel = typeof t.usd_value === 'number' && t.usd_value > 0 ? ` ($${t.usd_value.toFixed(2)})` : '';
920
- const label = `${name}: ${amount}${sym}${usdLabel}`;
921
- return { label, prompt: this.buildSwapFromPrompt(swapFromTemplate, sym) };
922
- });
923
- return {
924
- actionButtons,
925
- _instructions: `Reply briefly in the user's language: ask them to pick which token they want to swap from the options below. Do NOT list the tokens in text. Do NOT mention tool names, UI, or forms.`,
926
- };
927
- }
928
- // -------------------------------------------------------------------------
929
- // Branch 1: destination picker (source known, dest missing → trending)
930
- // -------------------------------------------------------------------------
931
- async buildToTrendingPicker(input) {
932
- const { args, userContext, fromSym, fromContract } = input;
933
- const chain = this.requireChain(args, userContext) ?? undefined;
934
- const pantograph = this.pantograph;
935
- const requestedLimit = typeof args.limit === 'number' && Number.isFinite(args.limit) ? Math.floor(args.limit) : 6;
936
- const limit = Math.max(1, Math.min(10, requestedLimit));
937
- const res = await pantograph.getTrendingTokens({ chain, limit: limit + 2 });
938
- const list = res.success ? (res.data ?? []) : [];
939
- // Exclude the source token itself (no self-swap) — match by address or symbol.
940
- const fromLower = fromContract?.toLowerCase();
941
- const fromSymLower = fromSym.toLowerCase();
942
- const tokens = list
943
- .filter((t) => {
944
- if (!t.symbol)
945
- return false;
946
- if (fromLower && fromLower !== 'native' && t.tokenAddress && t.tokenAddress.toLowerCase() === fromLower) {
947
- return false;
948
- }
949
- if (t.symbol.toLowerCase() === fromSymLower)
950
- return false;
951
- return true;
952
- })
953
- .slice(0, limit);
954
- if (tokens.length === 0) {
955
- return {
956
- error: 'no_trending_tokens',
957
- _instructions: `No trending tokens are available to swap ${fromSym} into on this chain right now. Tell the user briefly and suggest they name the token they want to receive directly. Do NOT mention tool names, UI, or forms.`,
958
- };
959
- }
960
- // Prefer the caller's already-converted amounts (so "1$"/"50%" become a real
961
- // token quantity in the click-prompt); fall back to re-parsing args.
962
- const fromAmount = input.fromAmount ?? this.normaliseAmount(args.from_amount);
963
- const toAmount = input.toAmount ?? this.normaliseAmount(args.to_amount);
964
- const swapToTemplate = typeof args.swap_to_prompt_template === 'string' ? args.swap_to_prompt_template : '';
965
- const actionButtons = tokens.map((t) => {
966
- const sym = t.symbol;
967
- // from_amount sits next to the source token ({from_amount}); otherwise an
968
- // optional to_amount sits next to the dest token ({to_amount}). Only one
969
- // side ever carries an amount.
970
- const prompt = fromAmount
971
- ? this.buildSwapToPrompt(swapToTemplate, fromSym, sym, fromAmount, null)
972
- : this.buildSwapToPrompt(swapToTemplate, fromSym, sym, null, toAmount);
973
- return { label: sym, prompt };
974
- });
975
- const lines = tokens.map((t, i) => {
976
- const name = t.name?.trim() || t.symbol;
977
- const sym = t.symbol;
978
- const priceLabel = typeof t.usdPrice === 'number' && t.usdPrice > 0 ? `$${this.formatPrice(t.usdPrice)}` : 'N/A';
979
- const change = t.pricePercentChange?.['24h'];
980
- const hasChange = typeof change === 'number' && Number.isFinite(change);
981
- const arrow = hasChange ? (change > 0 ? '▲' : change < 0 ? '▼' : '▪') : '';
982
- const changeLabel = hasChange ? ` (${arrow} ${this.formatPercent(change)}%)` : '';
983
- return `${i + 1}. ${name} (${sym})\n${priceLabel}${changeLabel}`;
984
- });
985
- const listText = lines.join('\n-----\n') + `\n---\nWhich token do you want to receive?`;
986
- return {
987
- actionButtons,
988
- _instructions: `The user wants to swap ${fromSym} into another token. The trending tokens are on chain id "${chain ?? 'the connected chain'}" — use the human-readable chain name. ` +
989
- `Reply in the user's language. Start with a one-line header like "📈 Here are tokens currently trending on <chain name> that you can swap ${fromSym} into", then output EXACTLY the following list, preserving the line breaks, ordering, prices, and percentages verbatim (translate only the wording, never the numbers). Do NOT add or remove tokens, and do NOT mention tool names, UI, or forms:\n\n${listText}`,
990
- };
991
- }
992
- // -------------------------------------------------------------------------
993
- // Branch 1.4: balance check (source token named — with or without an amount)
994
- // -------------------------------------------------------------------------
995
- /**
996
- * Guard the swap flow against a source token the user can't fund. Returns:
997
- * - `null` when the user holds enough (or no amount yet, or balances can't be read).
998
- * - `no_from_balance` (+ source picker buttons) when the wallet holds none of it.
999
- * - `insufficient_from_balance` (+ percentage buttons) when it holds some but
1000
- * less than the requested amount.
1001
- */
1002
- async checkFromBalance(input) {
1003
- const { args, userContext, chain, fromContract, fromAmount, derivedFromTo } = input;
1004
- const walletAddress = userContext.walletAddress;
1005
- const bal = await this.readFromBalance(walletAddress, fromContract, chain);
1006
- const fromSym = input.fromSym ?? bal?.symbol ?? 'the selected token';
1007
- // No holding at all: tell the user, then offer the tokens they DO hold.
1008
- if (!bal) {
1009
- this.dbg('checkFromBalance: NOT held → source picker fallback', { fromSym });
1010
- const picker = await this.buildSourcePicker(args, userContext);
1011
- if ('actionButtons' in picker) {
1012
- return {
1013
- error: 'no_from_balance',
1014
- actionButtons: picker.actionButtons,
1015
- _instructions: `The user wanted to swap ${fromSym}, but their wallet holds no ${fromSym} on this chain. ` +
1016
- `Tell them, in their language, that they don't have any ${fromSym}, then say they can instead choose one of the tokens they already hold (shown below) to swap from. ` +
1017
- 'Do NOT list the tokens in text, do NOT invent a balance, and do NOT mention tool names, UI, or forms.',
1018
- };
1019
- }
1020
- return picker;
1021
- }
1022
- // No amount yet — the holding exists, so let the amount picker take over.
1023
- if (!fromAmount)
1024
- return null;
1025
- // When the amount was SIZED OFF the balance (a percent / "max" / usd spec),
1026
- // it's already ≤ spendable by construction — skip the over-balance check.
1027
- // Re-checking would compare it against a freshly re-read spendable, which can
1028
- // drift a hair (the gas reserve is read from a separate RPC call), and a
1029
- // legitimate "max" would falsely trip as "insufficient". Only a plain
1030
- // user-typed amount ("swap 5 ETH") is genuinely checked against the balance.
1031
- if (input.amountSizedToBalance)
1032
- return null;
1033
- const wanted = Number(fromAmount);
1034
- if (!Number.isFinite(wanted) || wanted <= bal.balanceNum)
1035
- return null;
1036
- // Holds some but not enough: report the shortfall + percentage options.
1037
- const spendable = this.trimAmount(bal.balanceNum);
1038
- const actionButtons = this.percentSpendButtons({
1039
- balanceFormatted: bal.balanceFormatted,
1040
- balanceNum: bal.balanceNum,
1041
- fromSym,
1042
- toSym: typeof args.to_symbol === 'string' ? args.to_symbol.trim() : (bal.symbol ?? 'the destination token'),
1043
- swapToTemplate: typeof args.swap_to_prompt_template === 'string' ? args.swap_to_prompt_template : '',
1044
- });
1045
- // Frame the message by what the user actually said: a derived from amount
1046
- // came from "swap to X dest", so explain the conversion; otherwise they
1047
- // typed the from amount directly.
1048
- const needLine = derivedFromTo
1049
- ? `Receiving ${derivedFromTo} of the destination token needs about ${fromAmount} ${fromSym}, but they only have ${spendable} ${fromSym} on this chain — not enough. ` +
1050
- `Tell them, in their language, that this would cost about ${fromAmount} ${fromSym}, which is more than their balance of ${spendable} ${fromSym}, and ask them to swap a smaller amount — `
1051
- : `The user wants to swap ${fromAmount} ${fromSym}, but they only have ${spendable} ${fromSym} on this chain — not enough. ` +
1052
- `Tell them, in their language, that ${fromAmount} ${fromSym} exceeds their balance of ${spendable} ${fromSym}, and ask them to pick a smaller amount — `;
1053
- return {
1054
- error: 'insufficient_from_balance',
1055
- actionButtons,
1056
- _instructions: needLine +
1057
- 'invite them to choose one of the options below (sized to their balance) or type the amount they want. ' +
1058
- 'CRITICAL: clickable percentage buttons are rendered separately below your message — your text must NOT contain any "%", percentage values, or a list of amounts (no "25%", "50%", "75%", "100%"). ' +
1059
- 'Do NOT invent numbers, and do NOT mention tool names, UI, buttons, or forms.',
1060
- };
1061
- }
1062
- /**
1063
- * Read the connected wallet's balance of the source token. Returns the held
1064
- * amount + on-chain symbol, or `null` when balances can't be fetched / the
1065
- * token isn't held (zero balance or not held at all).
1066
- *
1067
- * For the NATIVE source coin the returned balance is the SPENDABLE figure —
1068
- * the held balance minus a silently-estimated swap gas reserve (gasLimit
1069
- * 1_000_000 × gasPrice) — so the percent buttons, amount picker, and balance
1070
- * check all stay within what the user can actually swap while still covering
1071
- * gas. The reserve is never surfaced; callers only ever expose the spendable
1072
- * number. ERC-20 sources are returned at their raw held balance (gas is paid
1073
- * in the native coin, not the source token).
1074
- */
1075
- async readFromBalance(walletAddress, fromAddr, chain) {
1076
- if (!this.moralis)
1077
- return null;
1078
- const balancesRes = await this.moralis.getWalletTokenBalances({
1079
- address: walletAddress,
1080
- chain,
1081
- excludeSpam: true,
1082
- excludeUnverifiedContracts: true,
1083
- });
1084
- const balances = balancesRes.success ? (balancesRes.data?.result ?? []) : [];
1085
- this.dbg('readFromBalance', {
1086
- fromAddr,
1087
- chain,
1088
- ok: balancesRes.success,
1089
- count: balances.length,
1090
- });
1091
- const fromLower = fromAddr.toLowerCase();
1092
- const fromBal = balances.find((t) => fromLower === 'native' ? t.native_token === true : t.token_address?.toLowerCase() === fromLower);
1093
- if (!fromBal?.balance_formatted) {
1094
- this.dbg('readFromBalance: source token NOT held → null', { fromAddr });
1095
- return null;
1096
- }
1097
- const balanceNum = Number(fromBal.balance_formatted);
1098
- if (!Number.isFinite(balanceNum) || balanceNum <= 0) {
1099
- this.dbg('readFromBalance: zero/invalid balance → null', { fromAddr, balance: fromBal.balance_formatted });
1100
- return null;
1101
- }
1102
- // Native source: reduce to the spendable balance so we never quote/size a
1103
- // swap that would leave the user unable to pay gas.
1104
- if (fromLower === 'native' && chain) {
1105
- const reserve = await (0, gasReserve_1.estimateNativeGasReserveWei)(chain, 'swap');
1106
- const spendable = (0, gasReserve_1.spendableNative)(balanceNum, reserve, chain);
1107
- this.dbg('readFromBalance: native spendable', { balanceNum, spendable });
1108
- if (spendable <= 0) {
1109
- this.dbg('readFromBalance: native spendable ≤ 0 → null', { balanceNum });
1110
- return null;
1111
- }
1112
- const spendableStr = this.trimAmount(spendable);
1113
- return { balanceFormatted: spendableStr, balanceNum: spendable, symbol: fromBal.symbol };
1114
- }
1115
- this.dbg('readFromBalance: held', { fromAddr, balance: fromBal.balance_formatted, symbol: fromBal.symbol });
1116
- return { balanceFormatted: fromBal.balance_formatted, balanceNum, symbol: fromBal.symbol };
1117
- }
1118
- /**
1119
- * 25/50/75/100% quick-spend buttons sized off a held balance. 100% spends the
1120
- * EXACT held string; the partial fractions are float-trimmed. The amount rides
1121
- * in the prompt; the label is a bare percent.
1122
- */
1123
- percentSpendButtons(input) {
1124
- const { balanceFormatted, balanceNum, fromSym, toSym, swapToTemplate } = input;
1125
- const fractions = [0.25, 0.5, 0.75, 1];
1126
- return fractions.map((f) => {
1127
- const amount = f === 1 ? this.cleanAmountString(balanceFormatted) : this.trimAmount(balanceNum * f);
1128
- // The percentage amount is the SOURCE amount → it rides with the source
1129
- // token ({from_amount}), never with the destination token.
1130
- return {
1131
- label: `${Math.round(f * 100)}%`,
1132
- prompt: this.buildSwapToPrompt(swapToTemplate, fromSym, toSym, amount, null),
1133
- };
1134
- });
1135
- }
1136
- // -------------------------------------------------------------------------
1137
- // Branch 1.5: amount picker (source + dest known, no amount given)
1138
- // -------------------------------------------------------------------------
1139
- async buildAmountPicker(input) {
1140
- const { userContext, chain, fromContract, toSym, swapToTemplate } = input;
1141
- const walletAddress = userContext.walletAddress;
1142
- const bal = await this.readFromBalance(walletAddress, fromContract, chain);
1143
- const fromSym = input.fromSym ?? bal?.symbol;
1144
- if (!bal || !fromSym)
1145
- return null;
1146
- const actionButtons = this.percentSpendButtons({
1147
- balanceFormatted: bal.balanceFormatted,
1148
- balanceNum: bal.balanceNum,
1149
- fromSym,
1150
- toSym,
1151
- swapToTemplate,
1152
- });
1153
- const spendable = this.trimAmount(bal.balanceNum);
1154
- return {
1155
- actionButtons,
1156
- _instructions: `The user's spendable balance is ${spendable} ${fromSym}. Reply briefly in the user's language: tell them their spendable ${fromSym} balance and ask how much they want to swap to ${toSym}, inviting them to choose one of the options below or type the amount they want. CRITICAL: clickable percentage buttons are rendered separately below your message — your text must NOT contain any "%", percentage values, or a list of amounts (no "25%", "50%", "75%", "100%"). Just ask the question. Do NOT mention tool names, UI, buttons, or forms.`,
1157
- };
1158
- }
1159
- /**
1160
- * Trim IEEE-754 noise from a computed amount (≤8 significant digits) and
1161
- * ALWAYS return plain decimal notation — never exponential ("1.5e-7").
1162
- */
1163
- trimAmount(value) {
1164
- if (!Number.isFinite(value))
1165
- return '0';
1166
- return this.toPlainDecimal(parseFloat(value.toPrecision(8)));
1167
- }
1168
- /** Format a number as a plain decimal string, expanding any e-notation. */
1169
- toPlainDecimal(n) {
1170
- const s = String(n);
1171
- if (!/e/i.test(s))
1172
- return s;
1173
- const neg = n < 0;
1174
- const [mantissa, expPart] = Math.abs(n).toString().split('e');
1175
- const exp = Number(expPart);
1176
- const [intPart, fracPart = ''] = mantissa.split('.');
1177
- const digits = intPart + fracPart;
1178
- let out;
1179
- if (exp >= 0) {
1180
- const pointPos = intPart.length + exp;
1181
- out =
1182
- pointPos >= digits.length
1183
- ? digits.padEnd(pointPos, '0')
1184
- : `${digits.slice(0, pointPos)}.${digits.slice(pointPos)}`;
1185
- }
1186
- else {
1187
- out = `0.${'0'.repeat(-exp - intPart.length)}${digits}`;
1188
- }
1189
- if (out.includes('.'))
1190
- out = out.replace(/\.?0+$/, '');
1191
- return neg ? `-${out}` : out;
1192
- }
1193
- /**
1194
- * Sanitize an amount STRING from an external source (e.g. Moralis
1195
- * `balance_formatted`): expand e-notation to plain decimal; else pass through.
1196
- */
1197
- cleanAmountString(s) {
1198
- if (!/e/i.test(s))
1199
- return s;
1200
- const n = Number(s);
1201
- return Number.isFinite(n) ? this.toPlainDecimal(n) : s;
1202
- }
1203
- /**
1204
- * Build the source-picker click-prompt ("swap {token}") from the LLM-supplied,
1205
- * already-localized template. Falls back to English when the LLM omits one.
1206
- */
1207
- buildSwapFromPrompt(template, token) {
1208
- const tpl = template && template.includes('{token}') ? template : 'swap {token}';
1209
- return tpl
1210
- .replace(/\{token\}/g, token)
1211
- .replace(/\s+/g, ' ')
1212
- .trim();
1213
- }
1214
- /**
1215
- * Build the "swap X to Y" click-prompt from the LLM-supplied, already-localized
1216
- * template by substituting placeholders:
1217
- * {from} → source token {to} → destination token
1218
- * {from_amount} → quantity swapped (next to {from})
1219
- * {to_amount} → quantity received (next to {to})
1220
- * The localized verb and "to" preposition live INSIDE the template, so we only
1221
- * substitute concrete values. Only one side ever carries an amount; the unused
1222
- * amount placeholder is replaced with '' (no preposition is attached to it, so
1223
- * nothing dangles). Falls back to an English template when the LLM omits one.
1224
- */
1225
- buildSwapToPrompt(template, from, to, fromAmount, toAmount) {
1226
- const tpl = template && template.includes('{from}') && template.includes('{to}')
1227
- ? template
1228
- : 'swap {from_amount} {from} to {to_amount} {to}';
1229
- return tpl
1230
- .replace(/\{from\}/g, from)
1231
- .replace(/\{to\}/g, to)
1232
- .replace(/\{from_amount\}/g, fromAmount ?? '')
1233
- .replace(/\{to_amount\}/g, toAmount ?? '')
1234
- .replace(/\s+/g, ' ')
1235
- .trim();
1236
- }
1237
- /**
1238
- * Format a 24h price-change percentage: ~6 significant digits, no trailing
1239
- * noise, and always plain decimal (never exponential for a tiny change).
1240
- */
1241
- formatPercent(value) {
1242
- if (!Number.isFinite(value))
1243
- return '0';
1244
- return this.toPlainDecimal(parseFloat(value.toPrecision(6)));
1245
- }
1246
- /** Compact price string: e.g. 0.00001234 → "0.00001234", 1234.5 → "1,234.50". */
1247
- formatPrice(price) {
1248
- if (price >= 1)
1249
- return price.toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
1250
- if (price >= 0.01)
1251
- return price.toFixed(4);
1252
- const str = price.toFixed(12);
1253
- const match = str.match(/^0\.0*([1-9]\d{0,3})/);
1254
- return match ? str.slice(0, (match[0].length || 0) + 0) : str;
1255
- }
1256
- }
1257
- exports.SwapTokenTool = SwapTokenTool;
1258
- //# sourceMappingURL=SwapTokenTool.js.map