saucer-swap-plugin 0.1.0

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 ADDED
@@ -0,0 +1,125 @@
1
+ # SaucerSwap Plugin for Hedera Agent Kit
2
+
3
+ A plugin for the Hedera Agent Kit that enables SaucerSwap V2 DeFi operations on Hedera, including token swaps and quote queries.
4
+
5
+ ## Features
6
+
7
+ - **Token Swaps**: Execute token swaps on SaucerSwap V2 protocol
8
+ - **Quote Queries**: Get swap quotes to estimate output amounts before executing swaps
9
+ - **Network Support**: Works with Hedera Mainnet and Testnet
10
+ - **Automatic Pool Discovery**: Automatically finds the best pool for token pairs
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ npm install saucer-swap-plugin
16
+ ```
17
+
18
+ ## Usage
19
+
20
+ ### With Hedera Agent Kit
21
+
22
+ ```typescript
23
+ import { HederaAIToolkit, AgentMode } from "hedera-agent-kit";
24
+ import { saucerSwapPlugin } from "saucer-swap-plugin";
25
+
26
+ const hederaAgentToolkit = new HederaAIToolkit({
27
+ client,
28
+ configuration: {
29
+ plugins: [saucerSwapPlugin],
30
+ context: {
31
+ mode: AgentMode.RETURN_BYTES,
32
+ },
33
+ },
34
+ });
35
+ ```
36
+
37
+ ### With LangChain
38
+
39
+ ```typescript
40
+ import { HederaLangchainToolkit, AgentMode } from "hedera-agent-kit";
41
+ import { saucerSwapPlugin } from "saucer-swap-plugin";
42
+
43
+ const hederaAgentToolkit = new HederaLangchainToolkit({
44
+ client,
45
+ configuration: {
46
+ plugins: [saucerSwapPlugin],
47
+ context: {
48
+ mode: AgentMode.AUTONOMOUS,
49
+ },
50
+ },
51
+ });
52
+ ```
53
+
54
+ ## Available Tools
55
+
56
+ ### Implemented Tools
57
+
58
+ - **`get_swap_quote_v2_tool`** - Get a quote for swapping tokens
59
+ - Parameters:
60
+ - `tokenIn` (string, required): The input token address
61
+ - `tokenOut` (string, required): The output token address
62
+ - `amountIn` (number, required): The amount of input tokens to swap
63
+ - Returns: The estimated output amount and exchange rate
64
+
65
+ - **`swap_v2_tool`** - Execute a token swap on SaucerSwap V2
66
+ - Parameters:
67
+ - `tokenIn` (string, required): The input token address
68
+ - `tokenOut` (string, required): The output token address
69
+ - `amountIn` (number, required): The amount of input tokens to swap
70
+ - `recipientAddress` (string, optional): The address to receive the output tokens (defaults to operator account)
71
+ - Returns: Transaction ID and swap confirmation
72
+
73
+ ## Configuration
74
+
75
+ The plugin uses pre-configured network addresses for SaucerSwap V2 contracts. The configuration is automatically selected based on the Hedera client's ledger ID (Mainnet or Testnet).
76
+
77
+ Network addresses are defined in the plugin configuration:
78
+ - **Router**: Handles swap execution
79
+ - **Factory**: Manages pool creation
80
+ - **Quoter**: Provides quote calculations
81
+ - **Wrapped HBAR**: Wrapped HBAR token address
82
+
83
+ For the latest contract addresses, refer to:
84
+ - [SaucerSwap Documentation](https://docs.saucerswap.finance/home)
85
+ - SaucerSwap GitHub repository
86
+ - Hedera ecosystem documentation
87
+
88
+ ## Development
89
+
90
+ ```bash
91
+ # Install dependencies
92
+ npm install
93
+
94
+ # Build the plugin
95
+ npm run build
96
+
97
+ # Run tests
98
+ npm test
99
+
100
+ # Run tests in watch mode
101
+ npm run test:watch
102
+
103
+ # Run tests with coverage
104
+ npm run test:coverage
105
+
106
+ # Lint code
107
+ npm run lint
108
+
109
+ # Fix linting issues
110
+ npm run lint:fix
111
+
112
+ # Type check without building
113
+ npm run type-check
114
+
115
+ # Watch mode for development
116
+ npm run dev
117
+ ```
118
+
119
+ ## Example
120
+
121
+ See the `examples/` directory for a complete example of using the plugin with LangChain and OpenAI.
122
+
123
+ ## License
124
+
125
+ MIT
@@ -0,0 +1,222 @@
1
+ [
2
+ {
3
+ "constant": true,
4
+ "inputs": [],
5
+ "name": "name",
6
+ "outputs": [
7
+ {
8
+ "name": "",
9
+ "type": "string"
10
+ }
11
+ ],
12
+ "payable": false,
13
+ "stateMutability": "view",
14
+ "type": "function"
15
+ },
16
+ {
17
+ "constant": false,
18
+ "inputs": [
19
+ {
20
+ "name": "_spender",
21
+ "type": "address"
22
+ },
23
+ {
24
+ "name": "_value",
25
+ "type": "uint256"
26
+ }
27
+ ],
28
+ "name": "approve",
29
+ "outputs": [
30
+ {
31
+ "name": "",
32
+ "type": "bool"
33
+ }
34
+ ],
35
+ "payable": false,
36
+ "stateMutability": "nonpayable",
37
+ "type": "function"
38
+ },
39
+ {
40
+ "constant": true,
41
+ "inputs": [],
42
+ "name": "totalSupply",
43
+ "outputs": [
44
+ {
45
+ "name": "",
46
+ "type": "uint256"
47
+ }
48
+ ],
49
+ "payable": false,
50
+ "stateMutability": "view",
51
+ "type": "function"
52
+ },
53
+ {
54
+ "constant": false,
55
+ "inputs": [
56
+ {
57
+ "name": "_from",
58
+ "type": "address"
59
+ },
60
+ {
61
+ "name": "_to",
62
+ "type": "address"
63
+ },
64
+ {
65
+ "name": "_value",
66
+ "type": "uint256"
67
+ }
68
+ ],
69
+ "name": "transferFrom",
70
+ "outputs": [
71
+ {
72
+ "name": "",
73
+ "type": "bool"
74
+ }
75
+ ],
76
+ "payable": false,
77
+ "stateMutability": "nonpayable",
78
+ "type": "function"
79
+ },
80
+ {
81
+ "constant": true,
82
+ "inputs": [],
83
+ "name": "decimals",
84
+ "outputs": [
85
+ {
86
+ "name": "",
87
+ "type": "uint8"
88
+ }
89
+ ],
90
+ "payable": false,
91
+ "stateMutability": "view",
92
+ "type": "function"
93
+ },
94
+ {
95
+ "constant": true,
96
+ "inputs": [
97
+ {
98
+ "name": "_owner",
99
+ "type": "address"
100
+ }
101
+ ],
102
+ "name": "balanceOf",
103
+ "outputs": [
104
+ {
105
+ "name": "balance",
106
+ "type": "uint256"
107
+ }
108
+ ],
109
+ "payable": false,
110
+ "stateMutability": "view",
111
+ "type": "function"
112
+ },
113
+ {
114
+ "constant": true,
115
+ "inputs": [],
116
+ "name": "symbol",
117
+ "outputs": [
118
+ {
119
+ "name": "",
120
+ "type": "string"
121
+ }
122
+ ],
123
+ "payable": false,
124
+ "stateMutability": "view",
125
+ "type": "function"
126
+ },
127
+ {
128
+ "constant": false,
129
+ "inputs": [
130
+ {
131
+ "name": "_to",
132
+ "type": "address"
133
+ },
134
+ {
135
+ "name": "_value",
136
+ "type": "uint256"
137
+ }
138
+ ],
139
+ "name": "transfer",
140
+ "outputs": [
141
+ {
142
+ "name": "",
143
+ "type": "bool"
144
+ }
145
+ ],
146
+ "payable": false,
147
+ "stateMutability": "nonpayable",
148
+ "type": "function"
149
+ },
150
+ {
151
+ "constant": true,
152
+ "inputs": [
153
+ {
154
+ "name": "_owner",
155
+ "type": "address"
156
+ },
157
+ {
158
+ "name": "_spender",
159
+ "type": "address"
160
+ }
161
+ ],
162
+ "name": "allowance",
163
+ "outputs": [
164
+ {
165
+ "name": "",
166
+ "type": "uint256"
167
+ }
168
+ ],
169
+ "payable": false,
170
+ "stateMutability": "view",
171
+ "type": "function"
172
+ },
173
+ {
174
+ "payable": true,
175
+ "stateMutability": "payable",
176
+ "type": "fallback"
177
+ },
178
+ {
179
+ "anonymous": false,
180
+ "inputs": [
181
+ {
182
+ "indexed": true,
183
+ "name": "owner",
184
+ "type": "address"
185
+ },
186
+ {
187
+ "indexed": true,
188
+ "name": "spender",
189
+ "type": "address"
190
+ },
191
+ {
192
+ "indexed": false,
193
+ "name": "value",
194
+ "type": "uint256"
195
+ }
196
+ ],
197
+ "name": "Approval",
198
+ "type": "event"
199
+ },
200
+ {
201
+ "anonymous": false,
202
+ "inputs": [
203
+ {
204
+ "indexed": true,
205
+ "name": "from",
206
+ "type": "address"
207
+ },
208
+ {
209
+ "indexed": true,
210
+ "name": "to",
211
+ "type": "address"
212
+ },
213
+ {
214
+ "indexed": false,
215
+ "name": "value",
216
+ "type": "uint256"
217
+ }
218
+ ],
219
+ "name": "Transfer",
220
+ "type": "event"
221
+ }
222
+ ]
@@ -0,0 +1,328 @@
1
+ [
2
+ {
3
+ "type": "constructor",
4
+ "stateMutability": "undefined",
5
+ "payable": false,
6
+ "inputs": [
7
+ {
8
+ "type": "address",
9
+ "name": "_factory"
10
+ },
11
+ {
12
+ "type": "address",
13
+ "name": "_WHBAR"
14
+ }
15
+ ]
16
+ },
17
+ {
18
+ "type": "error",
19
+ "name": "AssociateFail",
20
+ "inputs": [
21
+ {
22
+ "type": "int256",
23
+ "name": "respCode"
24
+ }
25
+ ]
26
+ },
27
+ {
28
+ "type": "event",
29
+ "anonymous": false,
30
+ "name": "OwnershipTransferred",
31
+ "inputs": [
32
+ {
33
+ "type": "address",
34
+ "name": "previousOwner",
35
+ "indexed": true
36
+ },
37
+ {
38
+ "type": "address",
39
+ "name": "newOwner",
40
+ "indexed": true
41
+ }
42
+ ]
43
+ },
44
+ {
45
+ "type": "function",
46
+ "name": "WHBAR",
47
+ "constant": true,
48
+ "stateMutability": "view",
49
+ "payable": false,
50
+ "inputs": [],
51
+ "outputs": [
52
+ {
53
+ "type": "address",
54
+ "name": ""
55
+ }
56
+ ]
57
+ },
58
+ {
59
+ "type": "function",
60
+ "name": "associateQuoterToToken",
61
+ "constant": false,
62
+ "payable": false,
63
+ "inputs": [
64
+ {
65
+ "type": "address",
66
+ "name": "token"
67
+ }
68
+ ],
69
+ "outputs": []
70
+ },
71
+ {
72
+ "type": "function",
73
+ "name": "factory",
74
+ "constant": true,
75
+ "stateMutability": "view",
76
+ "payable": false,
77
+ "inputs": [],
78
+ "outputs": [
79
+ {
80
+ "type": "address",
81
+ "name": ""
82
+ }
83
+ ]
84
+ },
85
+ {
86
+ "type": "function",
87
+ "name": "owner",
88
+ "constant": true,
89
+ "stateMutability": "view",
90
+ "payable": false,
91
+ "inputs": [],
92
+ "outputs": [
93
+ {
94
+ "type": "address",
95
+ "name": ""
96
+ }
97
+ ]
98
+ },
99
+ {
100
+ "type": "function",
101
+ "name": "quoteExactInput",
102
+ "constant": false,
103
+ "payable": false,
104
+ "inputs": [
105
+ {
106
+ "type": "bytes",
107
+ "name": "path"
108
+ },
109
+ {
110
+ "type": "uint256",
111
+ "name": "amountIn"
112
+ }
113
+ ],
114
+ "outputs": [
115
+ {
116
+ "type": "uint256",
117
+ "name": "amountOut"
118
+ },
119
+ {
120
+ "type": "uint160[]",
121
+ "name": "sqrtPriceX96AfterList"
122
+ },
123
+ {
124
+ "type": "uint32[]",
125
+ "name": "initializedTicksCrossedList"
126
+ },
127
+ {
128
+ "type": "uint256",
129
+ "name": "gasEstimate"
130
+ }
131
+ ]
132
+ },
133
+ {
134
+ "type": "function",
135
+ "name": "quoteExactInputSingle",
136
+ "constant": false,
137
+ "payable": false,
138
+ "inputs": [
139
+ {
140
+ "type": "tuple",
141
+ "name": "params",
142
+ "components": [
143
+ {
144
+ "type": "address",
145
+ "name": "tokenIn"
146
+ },
147
+ {
148
+ "type": "address",
149
+ "name": "tokenOut"
150
+ },
151
+ {
152
+ "type": "uint256",
153
+ "name": "amountIn"
154
+ },
155
+ {
156
+ "type": "uint24",
157
+ "name": "fee"
158
+ },
159
+ {
160
+ "type": "uint160",
161
+ "name": "sqrtPriceLimitX96"
162
+ }
163
+ ]
164
+ }
165
+ ],
166
+ "outputs": [
167
+ {
168
+ "type": "uint256",
169
+ "name": "amountOut"
170
+ },
171
+ {
172
+ "type": "uint160",
173
+ "name": "sqrtPriceX96After"
174
+ },
175
+ {
176
+ "type": "uint32",
177
+ "name": "initializedTicksCrossed"
178
+ },
179
+ {
180
+ "type": "uint256",
181
+ "name": "gasEstimate"
182
+ }
183
+ ]
184
+ },
185
+ {
186
+ "type": "function",
187
+ "name": "quoteExactOutput",
188
+ "constant": false,
189
+ "payable": false,
190
+ "inputs": [
191
+ {
192
+ "type": "bytes",
193
+ "name": "path"
194
+ },
195
+ {
196
+ "type": "uint256",
197
+ "name": "amountOut"
198
+ }
199
+ ],
200
+ "outputs": [
201
+ {
202
+ "type": "uint256",
203
+ "name": "amountIn"
204
+ },
205
+ {
206
+ "type": "uint160[]",
207
+ "name": "sqrtPriceX96AfterList"
208
+ },
209
+ {
210
+ "type": "uint32[]",
211
+ "name": "initializedTicksCrossedList"
212
+ },
213
+ {
214
+ "type": "uint256",
215
+ "name": "gasEstimate"
216
+ }
217
+ ]
218
+ },
219
+ {
220
+ "type": "function",
221
+ "name": "quoteExactOutputSingle",
222
+ "constant": false,
223
+ "payable": false,
224
+ "inputs": [
225
+ {
226
+ "type": "tuple",
227
+ "name": "params",
228
+ "components": [
229
+ {
230
+ "type": "address",
231
+ "name": "tokenIn"
232
+ },
233
+ {
234
+ "type": "address",
235
+ "name": "tokenOut"
236
+ },
237
+ {
238
+ "type": "uint256",
239
+ "name": "amount"
240
+ },
241
+ {
242
+ "type": "uint24",
243
+ "name": "fee"
244
+ },
245
+ {
246
+ "type": "uint160",
247
+ "name": "sqrtPriceLimitX96"
248
+ }
249
+ ]
250
+ }
251
+ ],
252
+ "outputs": [
253
+ {
254
+ "type": "uint256",
255
+ "name": "amountIn"
256
+ },
257
+ {
258
+ "type": "uint160",
259
+ "name": "sqrtPriceX96After"
260
+ },
261
+ {
262
+ "type": "uint32",
263
+ "name": "initializedTicksCrossed"
264
+ },
265
+ {
266
+ "type": "uint256",
267
+ "name": "gasEstimate"
268
+ }
269
+ ]
270
+ },
271
+ {
272
+ "type": "function",
273
+ "name": "renounceOwnership",
274
+ "constant": false,
275
+ "payable": false,
276
+ "inputs": [],
277
+ "outputs": []
278
+ },
279
+ {
280
+ "type": "function",
281
+ "name": "transferOwnership",
282
+ "constant": false,
283
+ "payable": false,
284
+ "inputs": [
285
+ {
286
+ "type": "address",
287
+ "name": "newOwner"
288
+ }
289
+ ],
290
+ "outputs": []
291
+ },
292
+ {
293
+ "type": "function",
294
+ "name": "uniswapV3SwapCallback",
295
+ "constant": true,
296
+ "stateMutability": "view",
297
+ "payable": false,
298
+ "inputs": [
299
+ {
300
+ "type": "int256",
301
+ "name": "amount0Delta"
302
+ },
303
+ {
304
+ "type": "int256",
305
+ "name": "amount1Delta"
306
+ },
307
+ {
308
+ "type": "bytes",
309
+ "name": "path"
310
+ }
311
+ ],
312
+ "outputs": []
313
+ },
314
+ {
315
+ "type": "function",
316
+ "name": "whbar",
317
+ "constant": true,
318
+ "stateMutability": "view",
319
+ "payable": false,
320
+ "inputs": [],
321
+ "outputs": [
322
+ {
323
+ "type": "address",
324
+ "name": ""
325
+ }
326
+ ]
327
+ }
328
+ ]