saucer-swap-plugin 0.2.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,10 +4,20 @@ A plugin for the Hedera Agent Kit that enables SaucerSwap V2 DeFi operations on
4
4
 
5
5
  ## Features
6
6
 
7
+ - **Token Discovery**: List what is tradable, ranked by liquidity, so an agent never has to recall token ids
8
+ - **Name Resolution**: Accept symbols and names in chat, and ask the user to choose when one matches several tokens
7
9
  - **Token Swaps**: Execute token swaps on SaucerSwap V2 protocol
8
10
  - **Quote Queries**: Get swap quotes to estimate output amounts before executing swaps
9
11
  - **Network Support**: Works with Hedera Mainnet and Testnet
10
- - **Automatic Pool Discovery**: Automatically finds the best pool for token pairs
12
+ - **Automatic Pool Discovery**: Picks the deepest fee tier for a token pair
13
+
14
+ ### Why discovery matters
15
+
16
+ Given only `tokenIn` / `tokenOut` address parameters, an LLM asked to "swap 100 HBAR for USDC"
17
+ will invent plausible-looking ids — Hedera system accounts such as `0.0.2` and `0.0.3` are a
18
+ common guess — and every swap then fails with `POOL_NOT_FOUND`. The discovery tools remove the
19
+ need to guess: the model lists real tokens, resolves what the user said against live pool data,
20
+ and asks a clarifying question when a symbol is shared.
11
21
 
12
22
  ## Installation
13
23
 
@@ -63,22 +73,71 @@ const hederaAgentToolkit = new HederaLangchainToolkit({
63
73
 
64
74
  ## Available Tools
65
75
 
66
- ### Implemented Tools
76
+ ### Token references
77
+
78
+ Every `tokenIn` / `tokenOut` / `token` parameter accepts any of:
79
+
80
+ - a symbol — `USDC`
81
+ - a token name — `USD Coin`
82
+ - a Hedera token id — `0.0.456858`
83
+ - an EVM address — `0x000000000000000000000000000000000006f89a`
84
+ - `HBAR` or `WHBAR`, both routed through the network's WHBAR token
85
+
86
+ Resolution runs against live pool data, in this order: identifier, HBAR alias, exact symbol,
87
+ exact name, then substring. The first tier that matches wins, and a tier matching more than one
88
+ token raises `AMBIGUOUS_TOKEN` rather than silently picking the largest — Hedera lets anyone mint
89
+ a token called `USDC`, so the choice belongs to the user.
90
+
91
+ Amounts are always in display units: `swap 100 HBAR` means `amountIn: 100`, not 10 000 000 000.
92
+
93
+ ### Discovery tools
94
+
95
+ - **`list_saucerswap_tokens_tool`** - List tokens that can be swapped, deepest liquidity first
96
+ - Parameters:
97
+ - `limit` (number, optional): How many to return, 1–100 (default 25)
98
+ - `search` (string, optional): Filter on symbol or name, e.g. `"usd"`
99
+ - Returns: Symbol, name, Hedera id, decimals, USD price, USD liquidity and pool count per token
100
+
101
+ - **`find_saucerswap_token_tool`** - Resolve what the user typed to one token id
102
+ - Parameters:
103
+ - `query` (string, required): Symbol, name, Hedera id or EVM address
104
+ - Returns: The matched token plus what it can be swapped for; or the candidate list when the
105
+ query is ambiguous; or suggestions when nothing matches
106
+
107
+ - **`list_saucerswap_pools_tool`** - Show swap routes and pool depth
108
+ - Parameters:
109
+ - `token` (string, optional): When given, returns everything this token can be swapped for
110
+ - `limit` (number, optional): How many to return, 1–100 (default 25)
111
+ - Returns: Counterpart tokens with fee tier and USD liquidity, or the busiest pools network-wide
112
+
113
+ ### Trading tools
67
114
 
68
115
  - **`get_swap_quote_v2_tool`** - Get a quote for swapping tokens
69
116
  - Parameters:
70
- - `tokenIn` (string, required): The input token address
71
- - `tokenOut` (string, required): The output token address
72
- - `amountIn` (number, required): The amount of input tokens to swap
73
- - Returns: The estimated output amount and exchange rate
117
+ - `tokenIn` (string, required): The token being sold
118
+ - `tokenOut` (string, required): The token being bought
119
+ - `amountIn` (number, required): The amount of `tokenIn` to sell, in display units
120
+ - Returns: The output amount in display units, the rate, and the fee tier used
74
121
 
75
122
  - **`swap_v2_tool`** - Execute a token swap on SaucerSwap V2
76
123
  - Parameters:
77
- - `tokenIn` (string, required): The input token address
78
- - `tokenOut` (string, required): The output token address
79
- - `amountIn` (number, required): The amount of input tokens to swap
124
+ - `tokenIn` (string, required): The token being sold
125
+ - `tokenOut` (string, required): The token being bought
126
+ - `amountIn` (number, required): The amount of `tokenIn` to sell, in display units
80
127
  - `recipientAddress` (string, optional): The address to receive the output tokens (defaults to operator account)
81
- - Returns: Transaction ID and swap confirmation
128
+ - Returns: Transaction ID and a confirmation naming both tokens
129
+
130
+ ### Error codes
131
+
132
+ Failures carry a `code` so the agent can react instead of only apologising:
133
+
134
+ | Code | Meaning | What the agent should do |
135
+ | --- | --- | --- |
136
+ | `AMBIGUOUS_TOKEN` | The symbol or name matches several tokens | Show the candidates, ask which id |
137
+ | `TOKEN_NOT_FOUND` | Nothing tradable matches | Offer the listed alternatives |
138
+ | `POOL_NOT_FOUND` | The pair shares no pool | Suggest a counterpart from the error's route list |
139
+ | `SAME_TOKEN` | Both sides resolved to one token | Ask which two tokens were meant |
140
+ | `AMOUNT_BELOW_MINIMUM` | The amount floors to zero base units | Ask for at least the stated minimum |
82
141
 
83
142
  ## Configuration
84
143
 
@@ -88,12 +147,22 @@ Network addresses are defined in the plugin configuration:
88
147
  - **Router**: Handles swap execution
89
148
  - **Factory**: Manages pool creation
90
149
  - **Quoter**: Provides quote calculations
91
- - **Wrapped HBAR**: Wrapped HBAR token address
150
+ - **Wrapped HBAR**: Wrapped HBAR **token** id — note this is not the WHBAR contract id, which is
151
+ one lower on both networks (`0.0.1456986` vs `0.0.1456985` on mainnet, `0.0.15058` vs
152
+ `0.0.15057` on testnet). Pool data only ever names the token id, and using the contract id
153
+ breaks HBAR-funded swaps.
154
+
155
+ Addresses are verified against [SaucerSwap's contract deployments](https://docs.saucerswap.finance/developerx/contract-deployments).
92
156
 
93
- For the latest contract addresses, refer to:
94
- - [SaucerSwap Documentation](https://docs.saucerswap.finance/home)
95
- - SaucerSwap GitHub repository
96
- - Hedera ecosystem documentation
157
+ The `GET /v2/pools` response is cached for 30 seconds per network, so a single chat turn that
158
+ lists tokens, resolves a symbol and then quotes makes one HTTP request rather than three.
159
+
160
+ ## Known limitations
161
+
162
+ - **Single-hop routing.** A swap only works when both tokens share a pool. `POOL_NOT_FOUND`
163
+ reports what each token *can* be traded against so the agent can propose a workable pair.
164
+ - **No slippage limit.** Swaps are submitted with `amountOutMinimum: 0`, so they execute at
165
+ whatever price the pool gives. Keep amounts modest on thin pairs.
97
166
 
98
167
  ## Development
99
168
 
@@ -130,6 +199,37 @@ npm run dev
130
199
 
131
200
  See the `examples/` directory for a complete example of using the plugin with LangChain and OpenAI.
132
201
 
202
+ ### A swap from scratch, entirely in chat
203
+
204
+ ```
205
+ user > what can I swap on saucerswap?
206
+ -> list_saucerswap_tokens_tool { limit: 25 }
207
+ agent > Top 25 of 44 swappable tokens on mainnet, deepest liquidity first:
208
+ 1. HBAR — WHBAR [new] — id 0.0.1456986 — 8 decimals — $0.07 — $3,948,624 liquidity across 37 pool(s)
209
+ 2. USDC — USD Coin — id 0.0.456858 — 6 decimals — $0.97 — $818,617 liquidity across 9 pool(s)
210
+ ...
211
+
212
+ user > what can I get for USD Coin?
213
+ -> list_saucerswap_pools_tool { token: "USD Coin" }
214
+ agent > "USD Coin" matches 2 different tokens. Which do you mean?
215
+ 1. USDC — USD Coin — id 0.0.456858 — $818,617 liquidity
216
+ 2. USDC[hts] — USD Coin — id 0.0.1055459 — $28,870 liquidity
217
+
218
+ user > the first one
219
+ -> list_saucerswap_pools_tool { token: "0.0.456858" }
220
+ agent > USDC (0.0.456858) can be swapped directly for HBAR, USDC[hts], USDT0, ...
221
+
222
+ user > quote 100 hbar to usdc
223
+ -> get_swap_quote_v2_tool { tokenIn: "HBAR", tokenOut: "0.0.456858", amountIn: 100 }
224
+ agent > Swapping 100 HBAR returns about 6.68 USDC. Rate: 1 HBAR ≈ 0.0668 USDC.
225
+ Routed through the 0.15% fee pool.
226
+
227
+ user > do it
228
+ -> swap_v2_tool { tokenIn: "HBAR", tokenOut: "0.0.456858", amountIn: 100 }
229
+ agent > Swapped 100 HBAR (0.0.1456986) for USDC (0.0.456858) through the 0.15% fee pool.
230
+ Transaction ID: 0.0.5273913@1755164231.123456789
231
+ ```
232
+
133
233
  ## License
134
234
 
135
235
  MIT