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.
@@ -0,0 +1,481 @@
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": "error",
29
+ "name": "RespCode",
30
+ "inputs": [
31
+ {
32
+ "type": "int32",
33
+ "name": "respCode"
34
+ }
35
+ ]
36
+ },
37
+ {
38
+ "type": "event",
39
+ "anonymous": false,
40
+ "name": "OwnershipTransferred",
41
+ "inputs": [
42
+ {
43
+ "type": "address",
44
+ "name": "previousOwner",
45
+ "indexed": true
46
+ },
47
+ {
48
+ "type": "address",
49
+ "name": "newOwner",
50
+ "indexed": true
51
+ }
52
+ ]
53
+ },
54
+ {
55
+ "type": "function",
56
+ "name": "WHBAR",
57
+ "constant": true,
58
+ "stateMutability": "view",
59
+ "payable": false,
60
+ "inputs": [],
61
+ "outputs": [
62
+ {
63
+ "type": "address",
64
+ "name": ""
65
+ }
66
+ ]
67
+ },
68
+ {
69
+ "type": "function",
70
+ "name": "associateSwapRouterToToken",
71
+ "constant": false,
72
+ "payable": false,
73
+ "inputs": [
74
+ {
75
+ "type": "address",
76
+ "name": "token"
77
+ }
78
+ ],
79
+ "outputs": []
80
+ },
81
+ {
82
+ "type": "function",
83
+ "name": "exactInput",
84
+ "constant": false,
85
+ "stateMutability": "payable",
86
+ "payable": true,
87
+ "inputs": [
88
+ {
89
+ "type": "tuple",
90
+ "name": "params",
91
+ "components": [
92
+ {
93
+ "type": "bytes",
94
+ "name": "path"
95
+ },
96
+ {
97
+ "type": "address",
98
+ "name": "recipient"
99
+ },
100
+ {
101
+ "type": "uint256",
102
+ "name": "deadline"
103
+ },
104
+ {
105
+ "type": "uint256",
106
+ "name": "amountIn"
107
+ },
108
+ {
109
+ "type": "uint256",
110
+ "name": "amountOutMinimum"
111
+ }
112
+ ]
113
+ }
114
+ ],
115
+ "outputs": [
116
+ {
117
+ "type": "uint256",
118
+ "name": "amountOut"
119
+ }
120
+ ]
121
+ },
122
+ {
123
+ "type": "function",
124
+ "name": "exactInputSingle",
125
+ "constant": false,
126
+ "stateMutability": "payable",
127
+ "payable": true,
128
+ "inputs": [
129
+ {
130
+ "type": "tuple",
131
+ "name": "params",
132
+ "components": [
133
+ {
134
+ "type": "address",
135
+ "name": "tokenIn"
136
+ },
137
+ {
138
+ "type": "address",
139
+ "name": "tokenOut"
140
+ },
141
+ {
142
+ "type": "uint24",
143
+ "name": "fee"
144
+ },
145
+ {
146
+ "type": "address",
147
+ "name": "recipient"
148
+ },
149
+ {
150
+ "type": "uint256",
151
+ "name": "deadline"
152
+ },
153
+ {
154
+ "type": "uint256",
155
+ "name": "amountIn"
156
+ },
157
+ {
158
+ "type": "uint256",
159
+ "name": "amountOutMinimum"
160
+ },
161
+ {
162
+ "type": "uint160",
163
+ "name": "sqrtPriceLimitX96"
164
+ }
165
+ ]
166
+ }
167
+ ],
168
+ "outputs": [
169
+ {
170
+ "type": "uint256",
171
+ "name": "amountOut"
172
+ }
173
+ ]
174
+ },
175
+ {
176
+ "type": "function",
177
+ "name": "exactOutput",
178
+ "constant": false,
179
+ "stateMutability": "payable",
180
+ "payable": true,
181
+ "inputs": [
182
+ {
183
+ "type": "tuple",
184
+ "name": "params",
185
+ "components": [
186
+ {
187
+ "type": "bytes",
188
+ "name": "path"
189
+ },
190
+ {
191
+ "type": "address",
192
+ "name": "recipient"
193
+ },
194
+ {
195
+ "type": "uint256",
196
+ "name": "deadline"
197
+ },
198
+ {
199
+ "type": "uint256",
200
+ "name": "amountOut"
201
+ },
202
+ {
203
+ "type": "uint256",
204
+ "name": "amountInMaximum"
205
+ }
206
+ ]
207
+ }
208
+ ],
209
+ "outputs": [
210
+ {
211
+ "type": "uint256",
212
+ "name": "amountIn"
213
+ }
214
+ ]
215
+ },
216
+ {
217
+ "type": "function",
218
+ "name": "exactOutputSingle",
219
+ "constant": false,
220
+ "stateMutability": "payable",
221
+ "payable": true,
222
+ "inputs": [
223
+ {
224
+ "type": "tuple",
225
+ "name": "params",
226
+ "components": [
227
+ {
228
+ "type": "address",
229
+ "name": "tokenIn"
230
+ },
231
+ {
232
+ "type": "address",
233
+ "name": "tokenOut"
234
+ },
235
+ {
236
+ "type": "uint24",
237
+ "name": "fee"
238
+ },
239
+ {
240
+ "type": "address",
241
+ "name": "recipient"
242
+ },
243
+ {
244
+ "type": "uint256",
245
+ "name": "deadline"
246
+ },
247
+ {
248
+ "type": "uint256",
249
+ "name": "amountOut"
250
+ },
251
+ {
252
+ "type": "uint256",
253
+ "name": "amountInMaximum"
254
+ },
255
+ {
256
+ "type": "uint160",
257
+ "name": "sqrtPriceLimitX96"
258
+ }
259
+ ]
260
+ }
261
+ ],
262
+ "outputs": [
263
+ {
264
+ "type": "uint256",
265
+ "name": "amountIn"
266
+ }
267
+ ]
268
+ },
269
+ {
270
+ "type": "function",
271
+ "name": "factory",
272
+ "constant": true,
273
+ "stateMutability": "view",
274
+ "payable": false,
275
+ "inputs": [],
276
+ "outputs": [
277
+ {
278
+ "type": "address",
279
+ "name": ""
280
+ }
281
+ ]
282
+ },
283
+ {
284
+ "type": "function",
285
+ "name": "multicall",
286
+ "constant": false,
287
+ "stateMutability": "payable",
288
+ "payable": true,
289
+ "inputs": [
290
+ {
291
+ "type": "bytes[]",
292
+ "name": "data"
293
+ }
294
+ ],
295
+ "outputs": [
296
+ {
297
+ "type": "bytes[]",
298
+ "name": "results"
299
+ }
300
+ ]
301
+ },
302
+ {
303
+ "type": "function",
304
+ "name": "owner",
305
+ "constant": true,
306
+ "stateMutability": "view",
307
+ "payable": false,
308
+ "inputs": [],
309
+ "outputs": [
310
+ {
311
+ "type": "address",
312
+ "name": ""
313
+ }
314
+ ]
315
+ },
316
+ {
317
+ "type": "function",
318
+ "name": "refundETH",
319
+ "constant": false,
320
+ "stateMutability": "payable",
321
+ "payable": true,
322
+ "inputs": [],
323
+ "outputs": []
324
+ },
325
+ {
326
+ "type": "function",
327
+ "name": "renounceOwnership",
328
+ "constant": false,
329
+ "payable": false,
330
+ "inputs": [],
331
+ "outputs": []
332
+ },
333
+ {
334
+ "type": "function",
335
+ "name": "sweepToken",
336
+ "constant": false,
337
+ "stateMutability": "payable",
338
+ "payable": true,
339
+ "inputs": [
340
+ {
341
+ "type": "address",
342
+ "name": "token"
343
+ },
344
+ {
345
+ "type": "uint256",
346
+ "name": "amountMinimum"
347
+ },
348
+ {
349
+ "type": "address",
350
+ "name": "recipient"
351
+ }
352
+ ],
353
+ "outputs": []
354
+ },
355
+ {
356
+ "type": "function",
357
+ "name": "sweepTokenWithFee",
358
+ "constant": false,
359
+ "stateMutability": "payable",
360
+ "payable": true,
361
+ "inputs": [
362
+ {
363
+ "type": "address",
364
+ "name": "token"
365
+ },
366
+ {
367
+ "type": "uint256",
368
+ "name": "amountMinimum"
369
+ },
370
+ {
371
+ "type": "address",
372
+ "name": "recipient"
373
+ },
374
+ {
375
+ "type": "uint256",
376
+ "name": "feeBips"
377
+ },
378
+ {
379
+ "type": "address",
380
+ "name": "feeRecipient"
381
+ }
382
+ ],
383
+ "outputs": []
384
+ },
385
+ {
386
+ "type": "function",
387
+ "name": "transferOwnership",
388
+ "constant": false,
389
+ "payable": false,
390
+ "inputs": [
391
+ {
392
+ "type": "address",
393
+ "name": "newOwner"
394
+ }
395
+ ],
396
+ "outputs": []
397
+ },
398
+ {
399
+ "type": "function",
400
+ "name": "uniswapV3SwapCallback",
401
+ "constant": false,
402
+ "payable": false,
403
+ "inputs": [
404
+ {
405
+ "type": "int256",
406
+ "name": "amount0Delta"
407
+ },
408
+ {
409
+ "type": "int256",
410
+ "name": "amount1Delta"
411
+ },
412
+ {
413
+ "type": "bytes",
414
+ "name": "_data"
415
+ }
416
+ ],
417
+ "outputs": []
418
+ },
419
+ {
420
+ "type": "function",
421
+ "name": "unwrapWHBAR",
422
+ "constant": false,
423
+ "stateMutability": "payable",
424
+ "payable": true,
425
+ "inputs": [
426
+ {
427
+ "type": "uint256",
428
+ "name": "amountMinimum"
429
+ },
430
+ {
431
+ "type": "address",
432
+ "name": "recipient"
433
+ }
434
+ ],
435
+ "outputs": []
436
+ },
437
+ {
438
+ "type": "function",
439
+ "name": "unwrapWHBARWithFee",
440
+ "constant": false,
441
+ "stateMutability": "payable",
442
+ "payable": true,
443
+ "inputs": [
444
+ {
445
+ "type": "uint256",
446
+ "name": "amountMinimum"
447
+ },
448
+ {
449
+ "type": "address",
450
+ "name": "recipient"
451
+ },
452
+ {
453
+ "type": "uint256",
454
+ "name": "feeBips"
455
+ },
456
+ {
457
+ "type": "address",
458
+ "name": "feeRecipient"
459
+ }
460
+ ],
461
+ "outputs": []
462
+ },
463
+ {
464
+ "type": "function",
465
+ "name": "whbar",
466
+ "constant": true,
467
+ "stateMutability": "view",
468
+ "payable": false,
469
+ "inputs": [],
470
+ "outputs": [
471
+ {
472
+ "type": "address",
473
+ "name": ""
474
+ }
475
+ ]
476
+ },
477
+ {
478
+ "type": "receive",
479
+ "stateMutability": "payable"
480
+ }
481
+ ]
package/dist/config.js ADDED
@@ -0,0 +1,17 @@
1
+ import { LedgerId } from "@hashgraph/sdk";
2
+ export const saucerSwapConfig = {
3
+ networks: {
4
+ [LedgerId.MAINNET.toString()]: {
5
+ router: "0x00000000000000000000000000000000003c437a",
6
+ factory: "0x0000000000000000000000000000000000103780",
7
+ wrappedHBAR: "0x0000000000000000000000000000000000163b5a",
8
+ quoter: "0x00000000000000000000000000000000003c4370",
9
+ },
10
+ [LedgerId.TESTNET.toString()]: {
11
+ router: "0x0000000000000000000000000000000000000000",
12
+ factory: "0x00000000000000000000000000000000000026e7",
13
+ wrappedHBAR: "0x0000000000000000000000000000000000003ad1",
14
+ quoter: "0x00000000000000000000000000000000001535b2",
15
+ },
16
+ }
17
+ };
@@ -0,0 +1,34 @@
1
+ // Configuration constants for SaucerSwap plugin
2
+ export const SAUCER_SWAP_CONFIG = {
3
+ // Transaction timeouts
4
+ DEFAULT_DEADLINE_SECONDS: 120, // 2 minutes
5
+ MAX_DEADLINE_SECONDS: 1800, // 30 minutes
6
+ // Gas limits
7
+ SWAP_GAS_LIMIT: 15_000_000, // Gas limit for swap transactions
8
+ QUOTE_GAS_LIMIT: 15_000_000, // Gas limit for quote operations
9
+ DECIMALS_GAS_LIMIT: 15_000_000, // Gas limit for decimals queries
10
+ // Gas price (in tinybar)
11
+ DEFAULT_GAS_PRICE: 100_000_000,
12
+ // Slippage tolerance
13
+ DEFAULT_SLIPPAGE_BPS: 300, // 3%
14
+ MAX_SLIPPAGE_BPS: 1000, // 10%
15
+ // Retry configuration
16
+ MAX_RETRIES: 3,
17
+ RETRY_DELAY_MS: 1000,
18
+ // Mirror node call defaults
19
+ MIRROR_NODE_FROM_ADDRESS: "0x0000000000000000000000000000000000000032", // System account
20
+ };
21
+ export const NETWORK_CONFIG = {
22
+ MAINNET: {
23
+ name: 'mainnet',
24
+ timeout: 60000,
25
+ maxAttempts: 10,
26
+ maxBackoff: 5000,
27
+ },
28
+ TESTNET: {
29
+ name: 'testnet',
30
+ timeout: 30000,
31
+ maxAttempts: 5,
32
+ maxBackoff: 3000,
33
+ },
34
+ };
package/dist/errors.js ADDED
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Custom error classes for SaucerSwap plugin
3
+ */
4
+ export class SaucerSwapError extends Error {
5
+ code;
6
+ constructor(message, code) {
7
+ super(message);
8
+ this.code = code;
9
+ this.name = 'SaucerSwapError';
10
+ Object.setPrototypeOf(this, SaucerSwapError.prototype);
11
+ }
12
+ }
13
+ export class PoolNotFoundError extends SaucerSwapError {
14
+ constructor(tokenA, tokenB) {
15
+ super(`Pool not found for tokens ${tokenA} and ${tokenB}`, 'POOL_NOT_FOUND');
16
+ this.name = 'PoolNotFoundError';
17
+ Object.setPrototypeOf(this, PoolNotFoundError.prototype);
18
+ }
19
+ }
20
+ export class InvalidTokenAddressError extends SaucerSwapError {
21
+ constructor(address) {
22
+ super(`Invalid token address: ${address}`, 'INVALID_TOKEN_ADDRESS');
23
+ this.name = 'InvalidTokenAddressError';
24
+ Object.setPrototypeOf(this, InvalidTokenAddressError.prototype);
25
+ }
26
+ }
27
+ export class InvalidAmountError extends SaucerSwapError {
28
+ constructor(amount) {
29
+ super(`Invalid amount: ${amount}. Amount must be greater than zero`, 'INVALID_AMOUNT');
30
+ this.name = 'InvalidAmountError';
31
+ Object.setPrototypeOf(this, InvalidAmountError.prototype);
32
+ }
33
+ }
34
+ export class MirrorNodeError extends SaucerSwapError {
35
+ statusCode;
36
+ constructor(message, statusCode) {
37
+ super(`Mirror Node error: ${message}`, 'MIRROR_NODE_ERROR');
38
+ this.statusCode = statusCode;
39
+ this.name = 'MirrorNodeError';
40
+ Object.setPrototypeOf(this, MirrorNodeError.prototype);
41
+ }
42
+ }
43
+ export class ConfigurationError extends SaucerSwapError {
44
+ constructor(message) {
45
+ super(`Configuration error: ${message}`, 'CONFIGURATION_ERROR');
46
+ this.name = 'ConfigurationError';
47
+ Object.setPrototypeOf(this, ConfigurationError.prototype);
48
+ }
49
+ }
package/dist/index.js ADDED
@@ -0,0 +1,19 @@
1
+ // Import all tool files
2
+ import getSwapQuoteV2Tool, { GET_SWAP_QUOTE_V2_TOOL } from "./tools/get-swap-quote-v2";
3
+ import swapV2Tool, { SWAP_V2_TOOL } from "./tools/swap-v2";
4
+ export const saucerSwapPlugin = {
5
+ name: 'saucer-swap-plugin',
6
+ version: '1.0.0',
7
+ description: 'A plugin for SaucerSwap V2 DeFi operations on Hedera',
8
+ tools: (context) => {
9
+ return [
10
+ getSwapQuoteV2Tool(context),
11
+ swapV2Tool(context),
12
+ ];
13
+ }
14
+ };
15
+ export const saucerSwapPluginToolNames = {
16
+ GET_SWAP_QUOTE_V2_TOOL,
17
+ SWAP_V2_TOOL
18
+ };
19
+ export default { saucerSwapPlugin, saucerSwapPluginToolNames };