hak-saucerswap-plugin 1.0.1 → 2.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/dist/index.cjs CHANGED
@@ -2,10 +2,10 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var hederaAgentKit = require('@hashgraph/hedera-agent-kit');
5
6
  var zod = require('zod');
6
7
  var axios = require('axios');
7
- var sdk = require('@hashgraph/sdk');
8
- var hederaAgentKit = require('hedera-agent-kit');
8
+ var sdk = require('@hiero-ledger/sdk');
9
9
 
10
10
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
11
11
 
@@ -42,7 +42,8 @@ var SaucerSwapClient = class {
42
42
  this.retries = options.retries ?? 2;
43
43
  this.http = options.http ?? axios__default.default.create({
44
44
  baseURL: options.baseUrl ?? "https://api.saucerswap.finance",
45
- timeout: options.timeoutMs ?? 1e4
45
+ timeout: options.timeoutMs ?? 1e4,
46
+ headers: options.apiKey ? { "x-api-key": options.apiKey } : void 0
46
47
  });
47
48
  }
48
49
  async request(path, params) {
@@ -124,6 +125,30 @@ var createSaucerSwapClient = (options) => {
124
125
  return new SaucerSwapClient(options);
125
126
  };
126
127
 
128
+ // src/networks.ts
129
+ var SAUCERSWAP_MAINNET = {
130
+ routerContractId: "0.0.3045981",
131
+ routerV2ContractId: "0.0.3949434",
132
+ wrappedHbarTokenId: "0.0.1456986",
133
+ tokenAliases: {
134
+ SAUCE: "0.0.731861",
135
+ XSAUCE: "0.0.1460200"
136
+ }
137
+ };
138
+ var SAUCERSWAP_TESTNET = {
139
+ routerContractId: "0.0.19264",
140
+ routerV2ContractId: "0.0.1414040",
141
+ wrappedHbarTokenId: "0.0.15058",
142
+ tokenAliases: {
143
+ SAUCE: "0.0.1183558",
144
+ XSAUCE: "0.0.1418651"
145
+ }
146
+ };
147
+ var NETWORK_DEFAULTS = {
148
+ mainnet: SAUCERSWAP_MAINNET,
149
+ testnet: SAUCERSWAP_TESTNET
150
+ };
151
+
127
152
  // src/config.ts
128
153
  var DEFAULT_CONFIG = {
129
154
  baseUrl: "https://api.saucerswap.finance",
@@ -164,6 +189,12 @@ var readPoolVersion = (value) => {
164
189
  }
165
190
  return void 0;
166
191
  };
192
+ var readNetwork = (value) => {
193
+ if (value === "mainnet" || value === "testnet") {
194
+ return value;
195
+ }
196
+ return void 0;
197
+ };
167
198
  var readContextConfig = (context) => {
168
199
  if (!context || typeof context !== "object") {
169
200
  return {};
@@ -176,6 +207,8 @@ var readContextConfig = (context) => {
176
207
  };
177
208
  var resolveSaucerSwapConfig = (context) => {
178
209
  const ctxConfig = readContextConfig(context);
210
+ const network = ctxConfig.network ?? readNetwork(process.env.SAUCERSWAP_NETWORK);
211
+ const networkDefaults = network ? NETWORK_DEFAULTS[network] ?? {} : {};
179
212
  const envAliases = readTokenAliases(process.env.SAUCERSWAP_TOKEN_ALIASES);
180
213
  const envDefaultVersion = readPoolVersion(process.env.SAUCERSWAP_DEFAULT_POOL_VERSION);
181
214
  return {
@@ -184,10 +217,13 @@ var resolveSaucerSwapConfig = (context) => {
184
217
  baseUrl: ctxConfig.baseUrl ?? process.env.SAUCERSWAP_BASE_URL ?? DEFAULT_CONFIG.baseUrl,
185
218
  timeoutMs: ctxConfig.timeoutMs ?? toNumber(process.env.SAUCERSWAP_TIMEOUT_MS, DEFAULT_CONFIG.timeoutMs),
186
219
  retries: ctxConfig.retries ?? toNumber(process.env.SAUCERSWAP_RETRIES, DEFAULT_CONFIG.retries),
187
- routerContractId: ctxConfig.routerContractId ?? process.env.SAUCERSWAP_ROUTER_CONTRACT_ID,
188
- routerV2ContractId: ctxConfig.routerV2ContractId ?? process.env.SAUCERSWAP_ROUTER_V2_CONTRACT_ID,
189
- wrappedHbarTokenId: ctxConfig.wrappedHbarTokenId ?? process.env.SAUCERSWAP_WRAPPED_HBAR_TOKEN_ID,
220
+ apiKey: ctxConfig.apiKey ?? process.env.SAUCERSWAP_API_KEY,
221
+ network,
222
+ routerContractId: ctxConfig.routerContractId ?? process.env.SAUCERSWAP_ROUTER_CONTRACT_ID ?? networkDefaults.routerContractId,
223
+ routerV2ContractId: ctxConfig.routerV2ContractId ?? process.env.SAUCERSWAP_ROUTER_V2_CONTRACT_ID ?? networkDefaults.routerV2ContractId,
224
+ wrappedHbarTokenId: ctxConfig.wrappedHbarTokenId ?? process.env.SAUCERSWAP_WRAPPED_HBAR_TOKEN_ID ?? networkDefaults.wrappedHbarTokenId,
190
225
  tokenAliases: {
226
+ ...networkDefaults.tokenAliases ?? {},
191
227
  ...envAliases,
192
228
  ...ctxConfig.tokenAliases ?? {}
193
229
  },
@@ -201,13 +237,18 @@ var resolveSaucerSwapConfig = (context) => {
201
237
  var farmsInputSchema = zod.z.object({
202
238
  poolId: zod.z.number().int().positive().optional().describe("Optional pool ID to filter farms")
203
239
  });
204
- var farmsTool = {
205
- method: "saucerswap_get_farms",
206
- name: "SaucerSwap Get Farms",
207
- description: "Get active farming opportunities on SaucerSwap.",
208
- parameters: farmsInputSchema,
209
- execute: async (_client, context, params) => {
210
- const args = farmsInputSchema.parse(params);
240
+ var FarmsTool = class extends hederaAgentKit.BaseTool {
241
+ constructor() {
242
+ super(...arguments);
243
+ this.method = "saucerswap_get_farms";
244
+ this.name = "SaucerSwap Get Farms";
245
+ this.description = "Get active farming opportunities on SaucerSwap.";
246
+ this.parameters = farmsInputSchema;
247
+ }
248
+ async normalizeParams(params, _context, _client) {
249
+ return farmsInputSchema.parse(params);
250
+ }
251
+ async coreAction(args, context, _client) {
211
252
  const config = resolveSaucerSwapConfig(context);
212
253
  const api = context.saucerswapClient ?? createSaucerSwapClient(config);
213
254
  try {
@@ -224,7 +265,14 @@ var farmsTool = {
224
265
  };
225
266
  }
226
267
  }
268
+ async shouldSecondaryAction(_coreActionResult, _context) {
269
+ return false;
270
+ }
271
+ async secondaryAction(_request, _client, _context) {
272
+ return null;
273
+ }
227
274
  };
275
+ var farmsTool = new FarmsTool();
228
276
 
229
277
  // src/utils/amm.ts
230
278
  var calculatePriceImpact = (inputAmount, outputAmount, poolReserveIn, poolReserveOut) => {
@@ -274,27 +322,930 @@ var accountIdToSolidityAddress = (accountId) => {
274
322
  var contractIdFromString = (contractId) => {
275
323
  return sdk.ContractId.fromString(contractId);
276
324
  };
277
- var finalizeTransaction = async (transaction, client, context, extra) => {
278
- const mode = context.mode;
279
- if (mode === hederaAgentKit.AgentMode.RETURN_BYTES || mode === "returnBytes" || mode === "RETURN_BYTES") {
280
- const txBytes = await transaction.toBytes();
281
- return {
282
- success: true,
283
- transactionBytes: Buffer.from(txBytes).toString("base64"),
284
- ...extra
285
- };
286
- }
287
- const response = await transaction.execute(client);
288
- const receipt = await response.getReceipt(client);
289
- return {
290
- success: true,
291
- transactionId: response.transactionId?.toString(),
292
- status: receipt.status.toString(),
293
- ...extra
294
- };
325
+
326
+ // node_modules/long/index.js
327
+ var wasm = null;
328
+ try {
329
+ wasm = new WebAssembly.Instance(
330
+ new WebAssembly.Module(
331
+ new Uint8Array([
332
+ // \0asm
333
+ 0,
334
+ 97,
335
+ 115,
336
+ 109,
337
+ // version 1
338
+ 1,
339
+ 0,
340
+ 0,
341
+ 0,
342
+ // section "type"
343
+ 1,
344
+ 13,
345
+ 2,
346
+ // 0, () => i32
347
+ 96,
348
+ 0,
349
+ 1,
350
+ 127,
351
+ // 1, (i32, i32, i32, i32) => i32
352
+ 96,
353
+ 4,
354
+ 127,
355
+ 127,
356
+ 127,
357
+ 127,
358
+ 1,
359
+ 127,
360
+ // section "function"
361
+ 3,
362
+ 7,
363
+ 6,
364
+ // 0, type 0
365
+ 0,
366
+ // 1, type 1
367
+ 1,
368
+ // 2, type 1
369
+ 1,
370
+ // 3, type 1
371
+ 1,
372
+ // 4, type 1
373
+ 1,
374
+ // 5, type 1
375
+ 1,
376
+ // section "global"
377
+ 6,
378
+ 6,
379
+ 1,
380
+ // 0, "high", mutable i32
381
+ 127,
382
+ 1,
383
+ 65,
384
+ 0,
385
+ 11,
386
+ // section "export"
387
+ 7,
388
+ 50,
389
+ 6,
390
+ // 0, "mul"
391
+ 3,
392
+ 109,
393
+ 117,
394
+ 108,
395
+ 0,
396
+ 1,
397
+ // 1, "div_s"
398
+ 5,
399
+ 100,
400
+ 105,
401
+ 118,
402
+ 95,
403
+ 115,
404
+ 0,
405
+ 2,
406
+ // 2, "div_u"
407
+ 5,
408
+ 100,
409
+ 105,
410
+ 118,
411
+ 95,
412
+ 117,
413
+ 0,
414
+ 3,
415
+ // 3, "rem_s"
416
+ 5,
417
+ 114,
418
+ 101,
419
+ 109,
420
+ 95,
421
+ 115,
422
+ 0,
423
+ 4,
424
+ // 4, "rem_u"
425
+ 5,
426
+ 114,
427
+ 101,
428
+ 109,
429
+ 95,
430
+ 117,
431
+ 0,
432
+ 5,
433
+ // 5, "get_high"
434
+ 8,
435
+ 103,
436
+ 101,
437
+ 116,
438
+ 95,
439
+ 104,
440
+ 105,
441
+ 103,
442
+ 104,
443
+ 0,
444
+ 0,
445
+ // section "code"
446
+ 10,
447
+ 191,
448
+ 1,
449
+ 6,
450
+ // 0, "get_high"
451
+ 4,
452
+ 0,
453
+ 35,
454
+ 0,
455
+ 11,
456
+ // 1, "mul"
457
+ 36,
458
+ 1,
459
+ 1,
460
+ 126,
461
+ 32,
462
+ 0,
463
+ 173,
464
+ 32,
465
+ 1,
466
+ 173,
467
+ 66,
468
+ 32,
469
+ 134,
470
+ 132,
471
+ 32,
472
+ 2,
473
+ 173,
474
+ 32,
475
+ 3,
476
+ 173,
477
+ 66,
478
+ 32,
479
+ 134,
480
+ 132,
481
+ 126,
482
+ 34,
483
+ 4,
484
+ 66,
485
+ 32,
486
+ 135,
487
+ 167,
488
+ 36,
489
+ 0,
490
+ 32,
491
+ 4,
492
+ 167,
493
+ 11,
494
+ // 2, "div_s"
495
+ 36,
496
+ 1,
497
+ 1,
498
+ 126,
499
+ 32,
500
+ 0,
501
+ 173,
502
+ 32,
503
+ 1,
504
+ 173,
505
+ 66,
506
+ 32,
507
+ 134,
508
+ 132,
509
+ 32,
510
+ 2,
511
+ 173,
512
+ 32,
513
+ 3,
514
+ 173,
515
+ 66,
516
+ 32,
517
+ 134,
518
+ 132,
519
+ 127,
520
+ 34,
521
+ 4,
522
+ 66,
523
+ 32,
524
+ 135,
525
+ 167,
526
+ 36,
527
+ 0,
528
+ 32,
529
+ 4,
530
+ 167,
531
+ 11,
532
+ // 3, "div_u"
533
+ 36,
534
+ 1,
535
+ 1,
536
+ 126,
537
+ 32,
538
+ 0,
539
+ 173,
540
+ 32,
541
+ 1,
542
+ 173,
543
+ 66,
544
+ 32,
545
+ 134,
546
+ 132,
547
+ 32,
548
+ 2,
549
+ 173,
550
+ 32,
551
+ 3,
552
+ 173,
553
+ 66,
554
+ 32,
555
+ 134,
556
+ 132,
557
+ 128,
558
+ 34,
559
+ 4,
560
+ 66,
561
+ 32,
562
+ 135,
563
+ 167,
564
+ 36,
565
+ 0,
566
+ 32,
567
+ 4,
568
+ 167,
569
+ 11,
570
+ // 4, "rem_s"
571
+ 36,
572
+ 1,
573
+ 1,
574
+ 126,
575
+ 32,
576
+ 0,
577
+ 173,
578
+ 32,
579
+ 1,
580
+ 173,
581
+ 66,
582
+ 32,
583
+ 134,
584
+ 132,
585
+ 32,
586
+ 2,
587
+ 173,
588
+ 32,
589
+ 3,
590
+ 173,
591
+ 66,
592
+ 32,
593
+ 134,
594
+ 132,
595
+ 129,
596
+ 34,
597
+ 4,
598
+ 66,
599
+ 32,
600
+ 135,
601
+ 167,
602
+ 36,
603
+ 0,
604
+ 32,
605
+ 4,
606
+ 167,
607
+ 11,
608
+ // 5, "rem_u"
609
+ 36,
610
+ 1,
611
+ 1,
612
+ 126,
613
+ 32,
614
+ 0,
615
+ 173,
616
+ 32,
617
+ 1,
618
+ 173,
619
+ 66,
620
+ 32,
621
+ 134,
622
+ 132,
623
+ 32,
624
+ 2,
625
+ 173,
626
+ 32,
627
+ 3,
628
+ 173,
629
+ 66,
630
+ 32,
631
+ 134,
632
+ 132,
633
+ 130,
634
+ 34,
635
+ 4,
636
+ 66,
637
+ 32,
638
+ 135,
639
+ 167,
640
+ 36,
641
+ 0,
642
+ 32,
643
+ 4,
644
+ 167,
645
+ 11
646
+ ])
647
+ ),
648
+ {}
649
+ ).exports;
650
+ } catch {
651
+ }
652
+ function Long(low, high, unsigned) {
653
+ this.low = low | 0;
654
+ this.high = high | 0;
655
+ this.unsigned = !!unsigned;
656
+ }
657
+ Long.prototype.__isLong__;
658
+ Object.defineProperty(Long.prototype, "__isLong__", { value: true });
659
+ function isLong(obj) {
660
+ return (obj && obj["__isLong__"]) === true;
661
+ }
662
+ function ctz32(value) {
663
+ var c = Math.clz32(value & -value);
664
+ return value ? 31 - c : c;
665
+ }
666
+ Long.isLong = isLong;
667
+ var INT_CACHE = {};
668
+ var UINT_CACHE = {};
669
+ function fromInt(value, unsigned) {
670
+ var obj, cachedObj, cache;
671
+ if (unsigned) {
672
+ value >>>= 0;
673
+ if (cache = 0 <= value && value < 256) {
674
+ cachedObj = UINT_CACHE[value];
675
+ if (cachedObj) return cachedObj;
676
+ }
677
+ obj = fromBits(value, 0, true);
678
+ if (cache) UINT_CACHE[value] = obj;
679
+ return obj;
680
+ } else {
681
+ value |= 0;
682
+ if (cache = -128 <= value && value < 128) {
683
+ cachedObj = INT_CACHE[value];
684
+ if (cachedObj) return cachedObj;
685
+ }
686
+ obj = fromBits(value, value < 0 ? -1 : 0, false);
687
+ if (cache) INT_CACHE[value] = obj;
688
+ return obj;
689
+ }
690
+ }
691
+ Long.fromInt = fromInt;
692
+ function fromNumber(value, unsigned) {
693
+ if (isNaN(value)) return unsigned ? UZERO : ZERO;
694
+ if (unsigned) {
695
+ if (value < 0) return UZERO;
696
+ if (value >= TWO_PWR_64_DBL) return MAX_UNSIGNED_VALUE;
697
+ } else {
698
+ if (value <= -TWO_PWR_63_DBL) return MIN_VALUE;
699
+ if (value + 1 >= TWO_PWR_63_DBL) return MAX_VALUE;
700
+ }
701
+ if (value < 0) return fromNumber(-value, unsigned).neg();
702
+ return fromBits(
703
+ value % TWO_PWR_32_DBL | 0,
704
+ value / TWO_PWR_32_DBL | 0,
705
+ unsigned
706
+ );
707
+ }
708
+ Long.fromNumber = fromNumber;
709
+ function fromBits(lowBits, highBits, unsigned) {
710
+ return new Long(lowBits, highBits, unsigned);
711
+ }
712
+ Long.fromBits = fromBits;
713
+ var pow_dbl = Math.pow;
714
+ function fromString(str, unsigned, radix) {
715
+ if (str.length === 0) throw Error("empty string");
716
+ if (typeof unsigned === "number") {
717
+ radix = unsigned;
718
+ unsigned = false;
719
+ } else {
720
+ unsigned = !!unsigned;
721
+ }
722
+ if (str === "NaN" || str === "Infinity" || str === "+Infinity" || str === "-Infinity")
723
+ return unsigned ? UZERO : ZERO;
724
+ radix = radix || 10;
725
+ if (radix < 2 || 36 < radix) throw RangeError("radix");
726
+ var p;
727
+ if ((p = str.indexOf("-")) > 0) throw Error("interior hyphen");
728
+ else if (p === 0) {
729
+ return fromString(str.substring(1), unsigned, radix).neg();
730
+ }
731
+ var radixToPower = fromNumber(pow_dbl(radix, 8));
732
+ var result = ZERO;
733
+ for (var i = 0; i < str.length; i += 8) {
734
+ var size = Math.min(8, str.length - i), value = parseInt(str.substring(i, i + size), radix);
735
+ if (size < 8) {
736
+ var power = fromNumber(pow_dbl(radix, size));
737
+ result = result.mul(power).add(fromNumber(value));
738
+ } else {
739
+ result = result.mul(radixToPower);
740
+ result = result.add(fromNumber(value));
741
+ }
742
+ }
743
+ result.unsigned = unsigned;
744
+ return result;
745
+ }
746
+ Long.fromString = fromString;
747
+ function fromValue(val, unsigned) {
748
+ if (typeof val === "number") return fromNumber(val, unsigned);
749
+ if (typeof val === "string") return fromString(val, unsigned);
750
+ return fromBits(
751
+ val.low,
752
+ val.high,
753
+ typeof unsigned === "boolean" ? unsigned : val.unsigned
754
+ );
755
+ }
756
+ Long.fromValue = fromValue;
757
+ var TWO_PWR_16_DBL = 1 << 16;
758
+ var TWO_PWR_24_DBL = 1 << 24;
759
+ var TWO_PWR_32_DBL = TWO_PWR_16_DBL * TWO_PWR_16_DBL;
760
+ var TWO_PWR_64_DBL = TWO_PWR_32_DBL * TWO_PWR_32_DBL;
761
+ var TWO_PWR_63_DBL = TWO_PWR_64_DBL / 2;
762
+ var TWO_PWR_24 = fromInt(TWO_PWR_24_DBL);
763
+ var ZERO = fromInt(0);
764
+ Long.ZERO = ZERO;
765
+ var UZERO = fromInt(0, true);
766
+ Long.UZERO = UZERO;
767
+ var ONE = fromInt(1);
768
+ Long.ONE = ONE;
769
+ var UONE = fromInt(1, true);
770
+ Long.UONE = UONE;
771
+ var NEG_ONE = fromInt(-1);
772
+ Long.NEG_ONE = NEG_ONE;
773
+ var MAX_VALUE = fromBits(4294967295 | 0, 2147483647 | 0, false);
774
+ Long.MAX_VALUE = MAX_VALUE;
775
+ var MAX_UNSIGNED_VALUE = fromBits(4294967295 | 0, 4294967295 | 0, true);
776
+ Long.MAX_UNSIGNED_VALUE = MAX_UNSIGNED_VALUE;
777
+ var MIN_VALUE = fromBits(0, 2147483648 | 0, false);
778
+ Long.MIN_VALUE = MIN_VALUE;
779
+ var LongPrototype = Long.prototype;
780
+ LongPrototype.toInt = function toInt() {
781
+ return this.unsigned ? this.low >>> 0 : this.low;
782
+ };
783
+ LongPrototype.toNumber = function toNumber2() {
784
+ if (this.unsigned)
785
+ return (this.high >>> 0) * TWO_PWR_32_DBL + (this.low >>> 0);
786
+ return this.high * TWO_PWR_32_DBL + (this.low >>> 0);
787
+ };
788
+ LongPrototype.toString = function toString(radix) {
789
+ radix = radix || 10;
790
+ if (radix < 2 || 36 < radix) throw RangeError("radix");
791
+ if (this.isZero()) return "0";
792
+ if (this.isNegative()) {
793
+ if (this.eq(MIN_VALUE)) {
794
+ var radixLong = fromNumber(radix), div = this.div(radixLong), rem1 = div.mul(radixLong).sub(this);
795
+ return div.toString(radix) + rem1.toInt().toString(radix);
796
+ } else return "-" + this.neg().toString(radix);
797
+ }
798
+ var radixToPower = fromNumber(pow_dbl(radix, 6), this.unsigned), rem = this;
799
+ var result = "";
800
+ while (true) {
801
+ var remDiv = rem.div(radixToPower), intval = rem.sub(remDiv.mul(radixToPower)).toInt() >>> 0, digits = intval.toString(radix);
802
+ rem = remDiv;
803
+ if (rem.isZero()) return digits + result;
804
+ else {
805
+ while (digits.length < 6) digits = "0" + digits;
806
+ result = "" + digits + result;
807
+ }
808
+ }
809
+ };
810
+ LongPrototype.getHighBits = function getHighBits() {
811
+ return this.high;
812
+ };
813
+ LongPrototype.getHighBitsUnsigned = function getHighBitsUnsigned() {
814
+ return this.high >>> 0;
815
+ };
816
+ LongPrototype.getLowBits = function getLowBits() {
817
+ return this.low;
818
+ };
819
+ LongPrototype.getLowBitsUnsigned = function getLowBitsUnsigned() {
820
+ return this.low >>> 0;
821
+ };
822
+ LongPrototype.getNumBitsAbs = function getNumBitsAbs() {
823
+ if (this.isNegative())
824
+ return this.eq(MIN_VALUE) ? 64 : this.neg().getNumBitsAbs();
825
+ var val = this.high != 0 ? this.high : this.low;
826
+ for (var bit = 31; bit > 0; bit--) if ((val & 1 << bit) != 0) break;
827
+ return this.high != 0 ? bit + 33 : bit + 1;
828
+ };
829
+ LongPrototype.isSafeInteger = function isSafeInteger() {
830
+ var top11Bits = this.high >> 21;
831
+ if (!top11Bits) return true;
832
+ if (this.unsigned) return false;
833
+ return top11Bits === -1 && !(this.low === 0 && this.high === -2097152);
834
+ };
835
+ LongPrototype.isZero = function isZero() {
836
+ return this.high === 0 && this.low === 0;
837
+ };
838
+ LongPrototype.eqz = LongPrototype.isZero;
839
+ LongPrototype.isNegative = function isNegative() {
840
+ return !this.unsigned && this.high < 0;
841
+ };
842
+ LongPrototype.isPositive = function isPositive() {
843
+ return this.unsigned || this.high >= 0;
844
+ };
845
+ LongPrototype.isOdd = function isOdd() {
846
+ return (this.low & 1) === 1;
847
+ };
848
+ LongPrototype.isEven = function isEven() {
849
+ return (this.low & 1) === 0;
850
+ };
851
+ LongPrototype.equals = function equals(other) {
852
+ if (!isLong(other)) other = fromValue(other);
853
+ if (this.unsigned !== other.unsigned && this.high >>> 31 === 1 && other.high >>> 31 === 1)
854
+ return false;
855
+ return this.high === other.high && this.low === other.low;
856
+ };
857
+ LongPrototype.eq = LongPrototype.equals;
858
+ LongPrototype.notEquals = function notEquals(other) {
859
+ return !this.eq(
860
+ /* validates */
861
+ other
862
+ );
863
+ };
864
+ LongPrototype.neq = LongPrototype.notEquals;
865
+ LongPrototype.ne = LongPrototype.notEquals;
866
+ LongPrototype.lessThan = function lessThan(other) {
867
+ return this.comp(
868
+ /* validates */
869
+ other
870
+ ) < 0;
295
871
  };
872
+ LongPrototype.lt = LongPrototype.lessThan;
873
+ LongPrototype.lessThanOrEqual = function lessThanOrEqual(other) {
874
+ return this.comp(
875
+ /* validates */
876
+ other
877
+ ) <= 0;
878
+ };
879
+ LongPrototype.lte = LongPrototype.lessThanOrEqual;
880
+ LongPrototype.le = LongPrototype.lessThanOrEqual;
881
+ LongPrototype.greaterThan = function greaterThan(other) {
882
+ return this.comp(
883
+ /* validates */
884
+ other
885
+ ) > 0;
886
+ };
887
+ LongPrototype.gt = LongPrototype.greaterThan;
888
+ LongPrototype.greaterThanOrEqual = function greaterThanOrEqual(other) {
889
+ return this.comp(
890
+ /* validates */
891
+ other
892
+ ) >= 0;
893
+ };
894
+ LongPrototype.gte = LongPrototype.greaterThanOrEqual;
895
+ LongPrototype.ge = LongPrototype.greaterThanOrEqual;
896
+ LongPrototype.compare = function compare(other) {
897
+ if (!isLong(other)) other = fromValue(other);
898
+ if (this.eq(other)) return 0;
899
+ var thisNeg = this.isNegative(), otherNeg = other.isNegative();
900
+ if (thisNeg && !otherNeg) return -1;
901
+ if (!thisNeg && otherNeg) return 1;
902
+ if (!this.unsigned) return this.sub(other).isNegative() ? -1 : 1;
903
+ return other.high >>> 0 > this.high >>> 0 || other.high === this.high && other.low >>> 0 > this.low >>> 0 ? -1 : 1;
904
+ };
905
+ LongPrototype.comp = LongPrototype.compare;
906
+ LongPrototype.negate = function negate() {
907
+ if (!this.unsigned && this.eq(MIN_VALUE)) return MIN_VALUE;
908
+ return this.not().add(ONE);
909
+ };
910
+ LongPrototype.neg = LongPrototype.negate;
911
+ LongPrototype.add = function add(addend) {
912
+ if (!isLong(addend)) addend = fromValue(addend);
913
+ var a48 = this.high >>> 16;
914
+ var a32 = this.high & 65535;
915
+ var a16 = this.low >>> 16;
916
+ var a00 = this.low & 65535;
917
+ var b48 = addend.high >>> 16;
918
+ var b32 = addend.high & 65535;
919
+ var b16 = addend.low >>> 16;
920
+ var b00 = addend.low & 65535;
921
+ var c48 = 0, c32 = 0, c16 = 0, c00 = 0;
922
+ c00 += a00 + b00;
923
+ c16 += c00 >>> 16;
924
+ c00 &= 65535;
925
+ c16 += a16 + b16;
926
+ c32 += c16 >>> 16;
927
+ c16 &= 65535;
928
+ c32 += a32 + b32;
929
+ c48 += c32 >>> 16;
930
+ c32 &= 65535;
931
+ c48 += a48 + b48;
932
+ c48 &= 65535;
933
+ return fromBits(c16 << 16 | c00, c48 << 16 | c32, this.unsigned);
934
+ };
935
+ LongPrototype.subtract = function subtract(subtrahend) {
936
+ if (!isLong(subtrahend)) subtrahend = fromValue(subtrahend);
937
+ return this.add(subtrahend.neg());
938
+ };
939
+ LongPrototype.sub = LongPrototype.subtract;
940
+ LongPrototype.multiply = function multiply(multiplier) {
941
+ if (this.isZero()) return this;
942
+ if (!isLong(multiplier)) multiplier = fromValue(multiplier);
943
+ if (wasm) {
944
+ var low = wasm["mul"](this.low, this.high, multiplier.low, multiplier.high);
945
+ return fromBits(low, wasm["get_high"](), this.unsigned);
946
+ }
947
+ if (multiplier.isZero()) return this.unsigned ? UZERO : ZERO;
948
+ if (this.eq(MIN_VALUE)) return multiplier.isOdd() ? MIN_VALUE : ZERO;
949
+ if (multiplier.eq(MIN_VALUE)) return this.isOdd() ? MIN_VALUE : ZERO;
950
+ if (this.isNegative()) {
951
+ if (multiplier.isNegative()) return this.neg().mul(multiplier.neg());
952
+ else return this.neg().mul(multiplier).neg();
953
+ } else if (multiplier.isNegative()) return this.mul(multiplier.neg()).neg();
954
+ if (this.lt(TWO_PWR_24) && multiplier.lt(TWO_PWR_24))
955
+ return fromNumber(this.toNumber() * multiplier.toNumber(), this.unsigned);
956
+ var a48 = this.high >>> 16;
957
+ var a32 = this.high & 65535;
958
+ var a16 = this.low >>> 16;
959
+ var a00 = this.low & 65535;
960
+ var b48 = multiplier.high >>> 16;
961
+ var b32 = multiplier.high & 65535;
962
+ var b16 = multiplier.low >>> 16;
963
+ var b00 = multiplier.low & 65535;
964
+ var c48 = 0, c32 = 0, c16 = 0, c00 = 0;
965
+ c00 += a00 * b00;
966
+ c16 += c00 >>> 16;
967
+ c00 &= 65535;
968
+ c16 += a16 * b00;
969
+ c32 += c16 >>> 16;
970
+ c16 &= 65535;
971
+ c16 += a00 * b16;
972
+ c32 += c16 >>> 16;
973
+ c16 &= 65535;
974
+ c32 += a32 * b00;
975
+ c48 += c32 >>> 16;
976
+ c32 &= 65535;
977
+ c32 += a16 * b16;
978
+ c48 += c32 >>> 16;
979
+ c32 &= 65535;
980
+ c32 += a00 * b32;
981
+ c48 += c32 >>> 16;
982
+ c32 &= 65535;
983
+ c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48;
984
+ c48 &= 65535;
985
+ return fromBits(c16 << 16 | c00, c48 << 16 | c32, this.unsigned);
986
+ };
987
+ LongPrototype.mul = LongPrototype.multiply;
988
+ LongPrototype.divide = function divide(divisor) {
989
+ if (!isLong(divisor)) divisor = fromValue(divisor);
990
+ if (divisor.isZero()) throw Error("division by zero");
991
+ if (wasm) {
992
+ if (!this.unsigned && this.high === -2147483648 && divisor.low === -1 && divisor.high === -1) {
993
+ return this;
994
+ }
995
+ var low = (this.unsigned ? wasm["div_u"] : wasm["div_s"])(
996
+ this.low,
997
+ this.high,
998
+ divisor.low,
999
+ divisor.high
1000
+ );
1001
+ return fromBits(low, wasm["get_high"](), this.unsigned);
1002
+ }
1003
+ if (this.isZero()) return this.unsigned ? UZERO : ZERO;
1004
+ var approx, rem, res;
1005
+ if (!this.unsigned) {
1006
+ if (this.eq(MIN_VALUE)) {
1007
+ if (divisor.eq(ONE) || divisor.eq(NEG_ONE))
1008
+ return MIN_VALUE;
1009
+ else if (divisor.eq(MIN_VALUE)) return ONE;
1010
+ else {
1011
+ var halfThis = this.shr(1);
1012
+ approx = halfThis.div(divisor).shl(1);
1013
+ if (approx.eq(ZERO)) {
1014
+ return divisor.isNegative() ? ONE : NEG_ONE;
1015
+ } else {
1016
+ rem = this.sub(divisor.mul(approx));
1017
+ res = approx.add(rem.div(divisor));
1018
+ return res;
1019
+ }
1020
+ }
1021
+ } else if (divisor.eq(MIN_VALUE)) return this.unsigned ? UZERO : ZERO;
1022
+ if (this.isNegative()) {
1023
+ if (divisor.isNegative()) return this.neg().div(divisor.neg());
1024
+ return this.neg().div(divisor).neg();
1025
+ } else if (divisor.isNegative()) return this.div(divisor.neg()).neg();
1026
+ res = ZERO;
1027
+ } else {
1028
+ if (!divisor.unsigned) divisor = divisor.toUnsigned();
1029
+ if (divisor.gt(this)) return UZERO;
1030
+ if (divisor.gt(this.shru(1)))
1031
+ return UONE;
1032
+ res = UZERO;
1033
+ }
1034
+ rem = this;
1035
+ while (rem.gte(divisor)) {
1036
+ approx = Math.max(1, Math.floor(rem.toNumber() / divisor.toNumber()));
1037
+ var log2 = Math.ceil(Math.log(approx) / Math.LN2), delta = log2 <= 48 ? 1 : pow_dbl(2, log2 - 48), approxRes = fromNumber(approx), approxRem = approxRes.mul(divisor);
1038
+ while (approxRem.isNegative() || approxRem.gt(rem)) {
1039
+ approx -= delta;
1040
+ approxRes = fromNumber(approx, this.unsigned);
1041
+ approxRem = approxRes.mul(divisor);
1042
+ }
1043
+ if (approxRes.isZero()) approxRes = ONE;
1044
+ res = res.add(approxRes);
1045
+ rem = rem.sub(approxRem);
1046
+ }
1047
+ return res;
1048
+ };
1049
+ LongPrototype.div = LongPrototype.divide;
1050
+ LongPrototype.modulo = function modulo(divisor) {
1051
+ if (!isLong(divisor)) divisor = fromValue(divisor);
1052
+ if (wasm) {
1053
+ var low = (this.unsigned ? wasm["rem_u"] : wasm["rem_s"])(
1054
+ this.low,
1055
+ this.high,
1056
+ divisor.low,
1057
+ divisor.high
1058
+ );
1059
+ return fromBits(low, wasm["get_high"](), this.unsigned);
1060
+ }
1061
+ return this.sub(this.div(divisor).mul(divisor));
1062
+ };
1063
+ LongPrototype.mod = LongPrototype.modulo;
1064
+ LongPrototype.rem = LongPrototype.modulo;
1065
+ LongPrototype.not = function not() {
1066
+ return fromBits(~this.low, ~this.high, this.unsigned);
1067
+ };
1068
+ LongPrototype.countLeadingZeros = function countLeadingZeros() {
1069
+ return this.high ? Math.clz32(this.high) : Math.clz32(this.low) + 32;
1070
+ };
1071
+ LongPrototype.clz = LongPrototype.countLeadingZeros;
1072
+ LongPrototype.countTrailingZeros = function countTrailingZeros() {
1073
+ return this.low ? ctz32(this.low) : ctz32(this.high) + 32;
1074
+ };
1075
+ LongPrototype.ctz = LongPrototype.countTrailingZeros;
1076
+ LongPrototype.and = function and(other) {
1077
+ if (!isLong(other)) other = fromValue(other);
1078
+ return fromBits(this.low & other.low, this.high & other.high, this.unsigned);
1079
+ };
1080
+ LongPrototype.or = function or(other) {
1081
+ if (!isLong(other)) other = fromValue(other);
1082
+ return fromBits(this.low | other.low, this.high | other.high, this.unsigned);
1083
+ };
1084
+ LongPrototype.xor = function xor(other) {
1085
+ if (!isLong(other)) other = fromValue(other);
1086
+ return fromBits(this.low ^ other.low, this.high ^ other.high, this.unsigned);
1087
+ };
1088
+ LongPrototype.shiftLeft = function shiftLeft(numBits) {
1089
+ if (isLong(numBits)) numBits = numBits.toInt();
1090
+ if ((numBits &= 63) === 0) return this;
1091
+ else if (numBits < 32)
1092
+ return fromBits(
1093
+ this.low << numBits,
1094
+ this.high << numBits | this.low >>> 32 - numBits,
1095
+ this.unsigned
1096
+ );
1097
+ else return fromBits(0, this.low << numBits - 32, this.unsigned);
1098
+ };
1099
+ LongPrototype.shl = LongPrototype.shiftLeft;
1100
+ LongPrototype.shiftRight = function shiftRight(numBits) {
1101
+ if (isLong(numBits)) numBits = numBits.toInt();
1102
+ if ((numBits &= 63) === 0) return this;
1103
+ else if (numBits < 32)
1104
+ return fromBits(
1105
+ this.low >>> numBits | this.high << 32 - numBits,
1106
+ this.high >> numBits,
1107
+ this.unsigned
1108
+ );
1109
+ else
1110
+ return fromBits(
1111
+ this.high >> numBits - 32,
1112
+ this.high >= 0 ? 0 : -1,
1113
+ this.unsigned
1114
+ );
1115
+ };
1116
+ LongPrototype.shr = LongPrototype.shiftRight;
1117
+ LongPrototype.shiftRightUnsigned = function shiftRightUnsigned(numBits) {
1118
+ if (isLong(numBits)) numBits = numBits.toInt();
1119
+ if ((numBits &= 63) === 0) return this;
1120
+ if (numBits < 32)
1121
+ return fromBits(
1122
+ this.low >>> numBits | this.high << 32 - numBits,
1123
+ this.high >>> numBits,
1124
+ this.unsigned
1125
+ );
1126
+ if (numBits === 32) return fromBits(this.high, 0, this.unsigned);
1127
+ return fromBits(this.high >>> numBits - 32, 0, this.unsigned);
1128
+ };
1129
+ LongPrototype.shru = LongPrototype.shiftRightUnsigned;
1130
+ LongPrototype.shr_u = LongPrototype.shiftRightUnsigned;
1131
+ LongPrototype.rotateLeft = function rotateLeft(numBits) {
1132
+ var b;
1133
+ if (isLong(numBits)) numBits = numBits.toInt();
1134
+ if ((numBits &= 63) === 0) return this;
1135
+ if (numBits === 32) return fromBits(this.high, this.low, this.unsigned);
1136
+ if (numBits < 32) {
1137
+ b = 32 - numBits;
1138
+ return fromBits(
1139
+ this.low << numBits | this.high >>> b,
1140
+ this.high << numBits | this.low >>> b,
1141
+ this.unsigned
1142
+ );
1143
+ }
1144
+ numBits -= 32;
1145
+ b = 32 - numBits;
1146
+ return fromBits(
1147
+ this.high << numBits | this.low >>> b,
1148
+ this.low << numBits | this.high >>> b,
1149
+ this.unsigned
1150
+ );
1151
+ };
1152
+ LongPrototype.rotl = LongPrototype.rotateLeft;
1153
+ LongPrototype.rotateRight = function rotateRight(numBits) {
1154
+ var b;
1155
+ if (isLong(numBits)) numBits = numBits.toInt();
1156
+ if ((numBits &= 63) === 0) return this;
1157
+ if (numBits === 32) return fromBits(this.high, this.low, this.unsigned);
1158
+ if (numBits < 32) {
1159
+ b = 32 - numBits;
1160
+ return fromBits(
1161
+ this.high << b | this.low >>> numBits,
1162
+ this.low << b | this.high >>> numBits,
1163
+ this.unsigned
1164
+ );
1165
+ }
1166
+ numBits -= 32;
1167
+ b = 32 - numBits;
1168
+ return fromBits(
1169
+ this.low << b | this.high >>> numBits,
1170
+ this.high << b | this.low >>> numBits,
1171
+ this.unsigned
1172
+ );
1173
+ };
1174
+ LongPrototype.rotr = LongPrototype.rotateRight;
1175
+ LongPrototype.toSigned = function toSigned() {
1176
+ if (!this.unsigned) return this;
1177
+ return fromBits(this.low, this.high, false);
1178
+ };
1179
+ LongPrototype.toUnsigned = function toUnsigned() {
1180
+ if (this.unsigned) return this;
1181
+ return fromBits(this.low, this.high, true);
1182
+ };
1183
+ LongPrototype.toBytes = function toBytes(le) {
1184
+ return le ? this.toBytesLE() : this.toBytesBE();
1185
+ };
1186
+ LongPrototype.toBytesLE = function toBytesLE() {
1187
+ var hi = this.high, lo = this.low;
1188
+ return [
1189
+ lo & 255,
1190
+ lo >>> 8 & 255,
1191
+ lo >>> 16 & 255,
1192
+ lo >>> 24,
1193
+ hi & 255,
1194
+ hi >>> 8 & 255,
1195
+ hi >>> 16 & 255,
1196
+ hi >>> 24
1197
+ ];
1198
+ };
1199
+ LongPrototype.toBytesBE = function toBytesBE() {
1200
+ var hi = this.high, lo = this.low;
1201
+ return [
1202
+ hi >>> 24,
1203
+ hi >>> 16 & 255,
1204
+ hi >>> 8 & 255,
1205
+ hi & 255,
1206
+ lo >>> 24,
1207
+ lo >>> 16 & 255,
1208
+ lo >>> 8 & 255,
1209
+ lo & 255
1210
+ ];
1211
+ };
1212
+ Long.fromBytes = function fromBytes(bytes, unsigned, le) {
1213
+ return le ? Long.fromBytesLE(bytes, unsigned) : Long.fromBytesBE(bytes, unsigned);
1214
+ };
1215
+ Long.fromBytesLE = function fromBytesLE(bytes, unsigned) {
1216
+ return new Long(
1217
+ bytes[0] | bytes[1] << 8 | bytes[2] << 16 | bytes[3] << 24,
1218
+ bytes[4] | bytes[5] << 8 | bytes[6] << 16 | bytes[7] << 24,
1219
+ unsigned
1220
+ );
1221
+ };
1222
+ Long.fromBytesBE = function fromBytesBE(bytes, unsigned) {
1223
+ return new Long(
1224
+ bytes[4] << 24 | bytes[5] << 16 | bytes[6] << 8 | bytes[7],
1225
+ bytes[0] << 24 | bytes[1] << 16 | bytes[2] << 8 | bytes[3],
1226
+ unsigned
1227
+ );
1228
+ };
1229
+ if (typeof BigInt === "function") {
1230
+ Long.fromBigInt = function fromBigInt2(value, unsigned) {
1231
+ var lowBits = Number(BigInt.asIntN(32, value));
1232
+ var highBits = Number(BigInt.asIntN(32, value >> BigInt(32)));
1233
+ return fromBits(lowBits, highBits, unsigned);
1234
+ };
1235
+ Long.fromValue = function fromValueWithBigInt(value, unsigned) {
1236
+ if (typeof value === "bigint") return fromBigInt(value, unsigned);
1237
+ return fromValue(value, unsigned);
1238
+ };
1239
+ LongPrototype.toBigInt = function toBigInt() {
1240
+ var lowBigInt = BigInt(this.low >>> 0);
1241
+ var highBigInt = BigInt(this.unsigned ? this.high >>> 0 : this.high);
1242
+ return highBigInt << BigInt(32) | lowBigInt;
1243
+ };
1244
+ }
1245
+ var long_default = Long;
296
1246
 
297
1247
  // src/utils/units.ts
1248
+ var toUint256 = (value) => typeof value === "string" ? long_default.fromString(value) : long_default.fromNumber(value);
298
1249
  var parseUnits = (amount, decimals) => {
299
1250
  if (!amount || typeof amount !== "string") {
300
1251
  throw new Error("Amount must be a non-empty string.");
@@ -331,6 +1282,9 @@ var removeLiquidityInputSchema = zod.z.object({
331
1282
  minAmountA: zod.z.string().describe("Minimum amount of tokenA to receive"),
332
1283
  minAmountB: zod.z.string().describe("Minimum amount of tokenB to receive")
333
1284
  });
1285
+ var isLiquidityCorePayload = (value) => typeof value === "object" && value !== null && "transaction" in value;
1286
+ var addLiquidityPostProcess = (response) => `SaucerSwap add liquidity submitted. Status: ${response.status}. Transaction ID: ${response.transactionId}`;
1287
+ var removeLiquidityPostProcess = (response) => `SaucerSwap remove liquidity submitted. Status: ${response.status}. Transaction ID: ${response.transactionId}`;
334
1288
  var resolveDeadline = (defaultMinutes) => {
335
1289
  return Math.floor(Date.now() / 1e3) + defaultMinutes * 60;
336
1290
  };
@@ -341,13 +1295,18 @@ var resolveRouterContract = (config) => {
341
1295
  }
342
1296
  return routerContractId;
343
1297
  };
344
- var addLiquidityTool = {
345
- method: "saucerswap_add_liquidity",
346
- name: "SaucerSwap Add Liquidity",
347
- description: "Add liquidity to a SaucerSwap pool.",
348
- parameters: addLiquidityInputSchema,
349
- execute: async (client, context, params) => {
350
- const args = addLiquidityInputSchema.parse(params);
1298
+ var AddLiquidityTool = class extends hederaAgentKit.BaseTool {
1299
+ constructor() {
1300
+ super(...arguments);
1301
+ this.method = "saucerswap_add_liquidity";
1302
+ this.name = "SaucerSwap Add Liquidity";
1303
+ this.description = "Add liquidity to a SaucerSwap pool.";
1304
+ this.parameters = addLiquidityInputSchema;
1305
+ }
1306
+ async normalizeParams(params, _context, _client) {
1307
+ return addLiquidityInputSchema.parse(params);
1308
+ }
1309
+ async coreAction(args, context, client) {
351
1310
  const config = resolveSaucerSwapConfig(context);
352
1311
  const operatorAccountId = client?.operatorAccountId?.toString();
353
1312
  const slippageTolerance = args.slippageTolerance ?? 0.5;
@@ -378,14 +1337,13 @@ var addLiquidityTool = {
378
1337
  const routerContractId = resolveRouterContract(config);
379
1338
  const deadline = resolveDeadline(config.deadlineMinutes);
380
1339
  const toAddress = accountIdToSolidityAddress(operatorAccountId);
381
- const params2 = new sdk.ContractFunctionParameters().addAddress(tokenIdToSolidityAddress(requireTokenId(tokenAId))).addAddress(tokenIdToSolidityAddress(requireTokenId(tokenBId))).addUint256(amountADesired).addUint256(amountBDesired).addUint256(amountAMin).addUint256(amountBMin).addAddress(toAddress).addUint256(deadline);
382
- const transaction = new sdk.ContractExecuteTransaction().setContractId(contractIdFromString(routerContractId)).setGas(config.gasLimit).setFunction("addLiquidity", params2);
383
- return await finalizeTransaction(transaction, client, context, {
384
- amountADesired,
385
- amountBDesired,
386
- amountAMin,
387
- amountBMin
388
- });
1340
+ const params = new sdk.ContractFunctionParameters().addAddress(tokenIdToSolidityAddress(requireTokenId(tokenAId))).addAddress(tokenIdToSolidityAddress(requireTokenId(tokenBId))).addUint256(toUint256(amountADesired)).addUint256(toUint256(amountBDesired)).addUint256(toUint256(amountAMin)).addUint256(toUint256(amountBMin)).addAddress(toAddress).addUint256(toUint256(deadline));
1341
+ const transaction = new sdk.ContractExecuteTransaction().setContractId(contractIdFromString(routerContractId)).setGas(config.gasLimit).setFunction("addLiquidity", params);
1342
+ const payload = {
1343
+ transaction,
1344
+ extras: { amountADesired, amountBDesired, amountAMin, amountBMin }
1345
+ };
1346
+ return payload;
389
1347
  } catch (error) {
390
1348
  return {
391
1349
  success: false,
@@ -393,14 +1351,31 @@ var addLiquidityTool = {
393
1351
  };
394
1352
  }
395
1353
  }
1354
+ async shouldSecondaryAction(coreActionResult, _context) {
1355
+ return isLiquidityCorePayload(coreActionResult);
1356
+ }
1357
+ async secondaryAction(payload, client, context) {
1358
+ const result = await hederaAgentKit.handleTransaction(
1359
+ payload.transaction,
1360
+ client,
1361
+ context,
1362
+ addLiquidityPostProcess
1363
+ );
1364
+ return { ...result, ...payload.extras };
1365
+ }
396
1366
  };
397
- var removeLiquidityTool = {
398
- method: "saucerswap_remove_liquidity",
399
- name: "SaucerSwap Remove Liquidity",
400
- description: "Remove liquidity from a SaucerSwap pool.",
401
- parameters: removeLiquidityInputSchema,
402
- execute: async (client, context, params) => {
403
- const args = removeLiquidityInputSchema.parse(params);
1367
+ var RemoveLiquidityTool = class extends hederaAgentKit.BaseTool {
1368
+ constructor() {
1369
+ super(...arguments);
1370
+ this.method = "saucerswap_remove_liquidity";
1371
+ this.name = "SaucerSwap Remove Liquidity";
1372
+ this.description = "Remove liquidity from a SaucerSwap pool.";
1373
+ this.parameters = removeLiquidityInputSchema;
1374
+ }
1375
+ async normalizeParams(params, _context, _client) {
1376
+ return removeLiquidityInputSchema.parse(params);
1377
+ }
1378
+ async coreAction(args, context, client) {
404
1379
  const config = resolveSaucerSwapConfig(context);
405
1380
  const operatorAccountId = client?.operatorAccountId?.toString();
406
1381
  if (!operatorAccountId) {
@@ -436,13 +1411,13 @@ var removeLiquidityTool = {
436
1411
  const routerContractId = resolveRouterContract(config);
437
1412
  const deadline = resolveDeadline(config.deadlineMinutes);
438
1413
  const toAddress = accountIdToSolidityAddress(operatorAccountId);
439
- const params2 = new sdk.ContractFunctionParameters().addAddress(tokenIdToSolidityAddress(requireTokenId(tokenAId))).addAddress(tokenIdToSolidityAddress(requireTokenId(tokenBId))).addUint256(lpAmount).addUint256(minAmountA).addUint256(minAmountB).addAddress(toAddress).addUint256(deadline);
440
- const transaction = new sdk.ContractExecuteTransaction().setContractId(contractIdFromString(routerContractId)).setGas(config.gasLimit).setFunction("removeLiquidity", params2);
441
- return await finalizeTransaction(transaction, client, context, {
442
- lpAmount,
443
- minAmountA,
444
- minAmountB
445
- });
1414
+ const params = new sdk.ContractFunctionParameters().addAddress(tokenIdToSolidityAddress(requireTokenId(tokenAId))).addAddress(tokenIdToSolidityAddress(requireTokenId(tokenBId))).addUint256(toUint256(lpAmount)).addUint256(toUint256(minAmountA)).addUint256(toUint256(minAmountB)).addAddress(toAddress).addUint256(toUint256(deadline));
1415
+ const transaction = new sdk.ContractExecuteTransaction().setContractId(contractIdFromString(routerContractId)).setGas(config.gasLimit).setFunction("removeLiquidity", params);
1416
+ const payload = {
1417
+ transaction,
1418
+ extras: { lpAmount, minAmountA, minAmountB }
1419
+ };
1420
+ return payload;
446
1421
  } catch (error) {
447
1422
  return {
448
1423
  success: false,
@@ -450,20 +1425,39 @@ var removeLiquidityTool = {
450
1425
  };
451
1426
  }
452
1427
  }
1428
+ async shouldSecondaryAction(coreActionResult, _context) {
1429
+ return isLiquidityCorePayload(coreActionResult);
1430
+ }
1431
+ async secondaryAction(payload, client, context) {
1432
+ const result = await hederaAgentKit.handleTransaction(
1433
+ payload.transaction,
1434
+ client,
1435
+ context,
1436
+ removeLiquidityPostProcess
1437
+ );
1438
+ return { ...result, ...payload.extras };
1439
+ }
453
1440
  };
1441
+ var addLiquidityTool = new AddLiquidityTool();
1442
+ var removeLiquidityTool = new RemoveLiquidityTool();
454
1443
  var poolsInputSchema = zod.z.object({
455
1444
  tokenA: zod.z.string().optional().describe("First token ID or symbol"),
456
1445
  tokenB: zod.z.string().optional().describe("Second token ID or symbol"),
457
1446
  version: zod.z.enum(["v1", "v2"]).optional().describe("Pool version"),
458
1447
  limit: zod.z.number().int().positive().optional().describe("Maximum number of pools to return")
459
1448
  });
460
- var poolsTool = {
461
- method: "saucerswap_get_pools",
462
- name: "SaucerSwap Get Pools",
463
- description: "Query SaucerSwap liquidity pools and reserves.",
464
- parameters: poolsInputSchema,
465
- execute: async (_client, context, params) => {
466
- const args = poolsInputSchema.parse(params);
1449
+ var PoolsTool = class extends hederaAgentKit.BaseTool {
1450
+ constructor() {
1451
+ super(...arguments);
1452
+ this.method = "saucerswap_get_pools";
1453
+ this.name = "SaucerSwap Get Pools";
1454
+ this.description = "Query SaucerSwap liquidity pools and reserves.";
1455
+ this.parameters = poolsInputSchema;
1456
+ }
1457
+ async normalizeParams(params, _context, _client) {
1458
+ return poolsInputSchema.parse(params);
1459
+ }
1460
+ async coreAction(args, context, _client) {
467
1461
  const config = resolveSaucerSwapConfig(context);
468
1462
  const api = context.saucerswapClient ?? createSaucerSwapClient(config);
469
1463
  try {
@@ -496,7 +1490,14 @@ var poolsTool = {
496
1490
  };
497
1491
  }
498
1492
  }
1493
+ async shouldSecondaryAction(_coreActionResult, _context) {
1494
+ return false;
1495
+ }
1496
+ async secondaryAction(_request, _client, _context) {
1497
+ return null;
1498
+ }
499
1499
  };
1500
+ var poolsTool = new PoolsTool();
500
1501
 
501
1502
  // src/utils/quote.ts
502
1503
  var readAmount = (value) => {
@@ -530,16 +1531,21 @@ var quoteInputSchema = zod.z.object({
530
1531
  amount: zod.z.string().describe("Amount to swap (decimal format)"),
531
1532
  slippageTolerance: zod.z.number().optional().default(0.5).describe("Maximum slippage tolerance percentage")
532
1533
  });
533
- var quoteTool = {
534
- method: "saucerswap_get_swap_quote",
535
- name: "SaucerSwap Get Swap Quote",
536
- description: "Get a price quote for swapping tokens on SaucerSwap.",
537
- parameters: quoteInputSchema,
538
- execute: async (_client, context, params) => {
539
- const args = quoteInputSchema.parse(params);
1534
+ var QuoteTool = class extends hederaAgentKit.BaseTool {
1535
+ constructor() {
1536
+ super(...arguments);
1537
+ this.method = "saucerswap_get_swap_quote";
1538
+ this.name = "SaucerSwap Get Swap Quote";
1539
+ this.description = "Get a price quote for swapping tokens on SaucerSwap.";
1540
+ this.parameters = quoteInputSchema;
1541
+ }
1542
+ async normalizeParams(params, _context, _client) {
1543
+ return quoteInputSchema.parse(params);
1544
+ }
1545
+ async coreAction(args, context, _client) {
540
1546
  const config = resolveSaucerSwapConfig(context);
541
- const client = context.saucerswapClient;
542
- const api = client ?? createSaucerSwapClient(config);
1547
+ const cachedApi = context.saucerswapClient;
1548
+ const api = cachedApi ?? createSaucerSwapClient(config);
543
1549
  const slippageTolerance = args.slippageTolerance ?? 0.5;
544
1550
  try {
545
1551
  const fromToken = normalizeTokenAlias(args.fromToken, config);
@@ -585,7 +1591,14 @@ var quoteTool = {
585
1591
  };
586
1592
  }
587
1593
  }
1594
+ async shouldSecondaryAction(_coreActionResult, _context) {
1595
+ return false;
1596
+ }
1597
+ async secondaryAction(_request, _client, _context) {
1598
+ return null;
1599
+ }
588
1600
  };
1601
+ var quoteTool = new QuoteTool();
589
1602
  var swapInputSchema = zod.z.object({
590
1603
  fromToken: zod.z.string().describe("Token ID to swap from (e.g., 'HBAR' or '0.0.123456')"),
591
1604
  toToken: zod.z.string().describe("Token ID to swap to"),
@@ -593,6 +1606,8 @@ var swapInputSchema = zod.z.object({
593
1606
  slippageTolerance: zod.z.number().optional().default(0.5).describe("Maximum slippage tolerance percentage"),
594
1607
  deadline: zod.z.number().optional().describe("Transaction deadline in minutes from now or a unix timestamp")
595
1608
  });
1609
+ var isSwapCorePayload = (value) => typeof value === "object" && value !== null && "transaction" in value;
1610
+ var swapPostProcess = (response) => `SaucerSwap swap submitted. Status: ${response.status}. Transaction ID: ${response.transactionId}`;
596
1611
  var resolveDeadline2 = (deadlineInput, defaultMinutes) => {
597
1612
  const now = Math.floor(Date.now() / 1e3);
598
1613
  if (!deadlineInput) {
@@ -609,13 +1624,18 @@ var amountToSmallest = (amount, decimals) => {
609
1624
  var expectedToSmallest = (amount, decimals) => {
610
1625
  return amount.includes(".") ? parseUnits(amount, decimals) : amount;
611
1626
  };
612
- var swapTool = {
613
- method: "saucerswap_swap_tokens",
614
- name: "SaucerSwap Swap Tokens",
615
- description: "Execute a token swap on SaucerSwap DEX.",
616
- parameters: swapInputSchema,
617
- execute: async (client, context, params) => {
618
- const args = swapInputSchema.parse(params);
1627
+ var SwapTool = class extends hederaAgentKit.BaseTool {
1628
+ constructor() {
1629
+ super(...arguments);
1630
+ this.method = "saucerswap_swap_tokens";
1631
+ this.name = "SaucerSwap Swap Tokens";
1632
+ this.description = "Execute a token swap on SaucerSwap DEX.";
1633
+ this.parameters = swapInputSchema;
1634
+ }
1635
+ async normalizeParams(params, _context, _client) {
1636
+ return swapInputSchema.parse(params);
1637
+ }
1638
+ async coreAction(args, context, client) {
619
1639
  const config = resolveSaucerSwapConfig(context);
620
1640
  const operatorAccountId = client?.operatorAccountId?.toString();
621
1641
  const slippageTolerance = args.slippageTolerance ?? 0.5;
@@ -663,14 +1683,18 @@ var swapTool = {
663
1683
  tokenIdToSolidityAddress(requireTokenId(fromTokenId)),
664
1684
  tokenIdToSolidityAddress(requireTokenId(toTokenId))
665
1685
  ];
666
- const params2 = new sdk.ContractFunctionParameters().addUint256(amountInSmallest).addUint256(minOutSmallest).addAddressArray(path).addAddress(toAddress).addUint256(deadline);
667
- const transaction = new sdk.ContractExecuteTransaction().setContractId(contractIdFromString(routerContractId)).setGas(config.gasLimit).setFunction("swapExactTokensForTokens", params2);
668
- return await finalizeTransaction(transaction, client, context, {
669
- estimatedOutput: quote.expectedOutput,
670
- minOutput: minOutSmallest,
671
- priceImpact: quote.priceImpact,
672
- route: quote.route
673
- });
1686
+ const params = new sdk.ContractFunctionParameters().addUint256(toUint256(amountInSmallest)).addUint256(toUint256(minOutSmallest)).addAddressArray(path).addAddress(toAddress).addUint256(toUint256(deadline));
1687
+ const transaction = new sdk.ContractExecuteTransaction().setContractId(contractIdFromString(routerContractId)).setGas(config.gasLimit).setFunction("swapExactTokensForTokens", params);
1688
+ const payload = {
1689
+ transaction,
1690
+ extras: {
1691
+ estimatedOutput: quote.expectedOutput,
1692
+ minOutput: minOutSmallest,
1693
+ priceImpact: quote.priceImpact,
1694
+ route: quote.route
1695
+ }
1696
+ };
1697
+ return payload;
674
1698
  } catch (error) {
675
1699
  return {
676
1700
  success: false,
@@ -678,16 +1702,63 @@ var swapTool = {
678
1702
  };
679
1703
  }
680
1704
  }
1705
+ async shouldSecondaryAction(coreActionResult, _context) {
1706
+ return isSwapCorePayload(coreActionResult);
1707
+ }
1708
+ async secondaryAction(payload, client, context) {
1709
+ const result = await hederaAgentKit.handleTransaction(
1710
+ payload.transaction,
1711
+ client,
1712
+ context,
1713
+ swapPostProcess
1714
+ );
1715
+ return { ...result, ...payload.extras };
1716
+ }
681
1717
  };
1718
+ var swapTool = new SwapTool();
682
1719
 
683
1720
  // src/index.ts
1721
+ var saucerswapPluginToolNames = {
1722
+ SAUCERSWAP_GET_SWAP_QUOTE_TOOL: "saucerswap_get_swap_quote",
1723
+ SAUCERSWAP_SWAP_TOKENS_TOOL: "saucerswap_swap_tokens",
1724
+ SAUCERSWAP_GET_POOLS_TOOL: "saucerswap_get_pools",
1725
+ SAUCERSWAP_ADD_LIQUIDITY_TOOL: "saucerswap_add_liquidity",
1726
+ SAUCERSWAP_REMOVE_LIQUIDITY_TOOL: "saucerswap_remove_liquidity",
1727
+ SAUCERSWAP_GET_FARMS_TOOL: "saucerswap_get_farms"
1728
+ };
684
1729
  var saucerswapPlugin = {
685
1730
  name: "saucerswap",
686
1731
  description: "Integration with SaucerSwap DEX for token swaps, liquidity provision, and yield farming",
687
1732
  tools: () => [swapTool, quoteTool, poolsTool, addLiquidityTool, removeLiquidityTool, farmsTool]
688
1733
  };
1734
+ /*! Bundled license information:
1735
+
1736
+ long/index.js:
1737
+ (**
1738
+ * @license
1739
+ * Copyright 2009 The Closure Library Authors
1740
+ * Copyright 2020 Daniel Wirtz / The long.js Authors.
1741
+ *
1742
+ * Licensed under the Apache License, Version 2.0 (the "License");
1743
+ * you may not use this file except in compliance with the License.
1744
+ * You may obtain a copy of the License at
1745
+ *
1746
+ * http://www.apache.org/licenses/LICENSE-2.0
1747
+ *
1748
+ * Unless required by applicable law or agreed to in writing, software
1749
+ * distributed under the License is distributed on an "AS IS" BASIS,
1750
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1751
+ * See the License for the specific language governing permissions and
1752
+ * limitations under the License.
1753
+ *
1754
+ * SPDX-License-Identifier: Apache-2.0
1755
+ *)
1756
+ */
689
1757
 
1758
+ exports.SAUCERSWAP_MAINNET = SAUCERSWAP_MAINNET;
1759
+ exports.SAUCERSWAP_TESTNET = SAUCERSWAP_TESTNET;
690
1760
  exports.default = saucerswapPlugin;
691
1761
  exports.saucerswapPlugin = saucerswapPlugin;
1762
+ exports.saucerswapPluginToolNames = saucerswapPluginToolNames;
692
1763
  //# sourceMappingURL=index.cjs.map
693
1764
  //# sourceMappingURL=index.cjs.map