Line data Source code
1 : import 'dart:typed_data';
2 : import 'package:walletkit_dart/walletkit_dart.dart';
3 :
4 3 : final uniswap_v2_router_abi = ContractABI.fromAbi("""
5 : [
6 : {
7 : "inputs": [
8 : {
9 : "internalType": "address",
10 : "name": "_factory",
11 : "type": "address"
12 : },
13 : {
14 : "internalType": "address",
15 : "name": "_WETH",
16 : "type": "address"
17 : }
18 : ],
19 : "stateMutability": "nonpayable",
20 : "type": "constructor"
21 : },
22 : {
23 : "inputs": [],
24 : "name": "WETH",
25 : "outputs": [
26 : {
27 : "internalType": "address",
28 : "name": "",
29 : "type": "address"
30 : }
31 : ],
32 : "stateMutability": "view",
33 : "type": "function"
34 : },
35 : {
36 : "inputs": [
37 : {
38 : "internalType": "address",
39 : "name": "tokenA",
40 : "type": "address"
41 : },
42 : {
43 : "internalType": "address",
44 : "name": "tokenB",
45 : "type": "address"
46 : },
47 : {
48 : "internalType": "uint256",
49 : "name": "amountADesired",
50 : "type": "uint256"
51 : },
52 : {
53 : "internalType": "uint256",
54 : "name": "amountBDesired",
55 : "type": "uint256"
56 : },
57 : {
58 : "internalType": "uint256",
59 : "name": "amountAMin",
60 : "type": "uint256"
61 : },
62 : {
63 : "internalType": "uint256",
64 : "name": "amountBMin",
65 : "type": "uint256"
66 : },
67 : {
68 : "internalType": "address",
69 : "name": "to",
70 : "type": "address"
71 : },
72 : {
73 : "internalType": "uint256",
74 : "name": "deadline",
75 : "type": "uint256"
76 : }
77 : ],
78 : "name": "addLiquidity",
79 : "outputs": [
80 : {
81 : "internalType": "uint256",
82 : "name": "amountA",
83 : "type": "uint256"
84 : },
85 : {
86 : "internalType": "uint256",
87 : "name": "amountB",
88 : "type": "uint256"
89 : },
90 : {
91 : "internalType": "uint256",
92 : "name": "liquidity",
93 : "type": "uint256"
94 : }
95 : ],
96 : "stateMutability": "nonpayable",
97 : "type": "function"
98 : },
99 : {
100 : "inputs": [
101 : {
102 : "internalType": "address",
103 : "name": "token",
104 : "type": "address"
105 : },
106 : {
107 : "internalType": "uint256",
108 : "name": "amountTokenDesired",
109 : "type": "uint256"
110 : },
111 : {
112 : "internalType": "uint256",
113 : "name": "amountTokenMin",
114 : "type": "uint256"
115 : },
116 : {
117 : "internalType": "uint256",
118 : "name": "amountETHMin",
119 : "type": "uint256"
120 : },
121 : {
122 : "internalType": "address",
123 : "name": "to",
124 : "type": "address"
125 : },
126 : {
127 : "internalType": "uint256",
128 : "name": "deadline",
129 : "type": "uint256"
130 : }
131 : ],
132 : "name": "addLiquidityETH",
133 : "outputs": [
134 : {
135 : "internalType": "uint256",
136 : "name": "amountToken",
137 : "type": "uint256"
138 : },
139 : {
140 : "internalType": "uint256",
141 : "name": "amountETH",
142 : "type": "uint256"
143 : },
144 : {
145 : "internalType": "uint256",
146 : "name": "liquidity",
147 : "type": "uint256"
148 : }
149 : ],
150 : "stateMutability": "payable",
151 : "type": "function"
152 : },
153 : {
154 : "inputs": [],
155 : "name": "factory",
156 : "outputs": [
157 : {
158 : "internalType": "address",
159 : "name": "",
160 : "type": "address"
161 : }
162 : ],
163 : "stateMutability": "view",
164 : "type": "function"
165 : },
166 : {
167 : "inputs": [
168 : {
169 : "internalType": "uint256",
170 : "name": "amountOut",
171 : "type": "uint256"
172 : },
173 : {
174 : "internalType": "uint256",
175 : "name": "reserveIn",
176 : "type": "uint256"
177 : },
178 : {
179 : "internalType": "uint256",
180 : "name": "reserveOut",
181 : "type": "uint256"
182 : }
183 : ],
184 : "name": "getAmountIn",
185 : "outputs": [
186 : {
187 : "internalType": "uint256",
188 : "name": "amountIn",
189 : "type": "uint256"
190 : }
191 : ],
192 : "stateMutability": "pure",
193 : "type": "function"
194 : },
195 : {
196 : "inputs": [
197 : {
198 : "internalType": "uint256",
199 : "name": "amountIn",
200 : "type": "uint256"
201 : },
202 : {
203 : "internalType": "uint256",
204 : "name": "reserveIn",
205 : "type": "uint256"
206 : },
207 : {
208 : "internalType": "uint256",
209 : "name": "reserveOut",
210 : "type": "uint256"
211 : }
212 : ],
213 : "name": "getAmountOut",
214 : "outputs": [
215 : {
216 : "internalType": "uint256",
217 : "name": "amountOut",
218 : "type": "uint256"
219 : }
220 : ],
221 : "stateMutability": "pure",
222 : "type": "function"
223 : },
224 : {
225 : "inputs": [
226 : {
227 : "internalType": "uint256",
228 : "name": "amountOut",
229 : "type": "uint256"
230 : },
231 : {
232 : "internalType": "address[]",
233 : "name": "path",
234 : "type": "address[]"
235 : }
236 : ],
237 : "name": "getAmountsIn",
238 : "outputs": [
239 : {
240 : "internalType": "uint256[]",
241 : "name": "amounts",
242 : "type": "uint256[]"
243 : }
244 : ],
245 : "stateMutability": "view",
246 : "type": "function"
247 : },
248 : {
249 : "inputs": [
250 : {
251 : "internalType": "uint256",
252 : "name": "amountIn",
253 : "type": "uint256"
254 : },
255 : {
256 : "internalType": "address[]",
257 : "name": "path",
258 : "type": "address[]"
259 : }
260 : ],
261 : "name": "getAmountsOut",
262 : "outputs": [
263 : {
264 : "internalType": "uint256[]",
265 : "name": "amounts",
266 : "type": "uint256[]"
267 : }
268 : ],
269 : "stateMutability": "view",
270 : "type": "function"
271 : },
272 : {
273 : "inputs": [
274 : {
275 : "internalType": "uint256",
276 : "name": "amountA",
277 : "type": "uint256"
278 : },
279 : {
280 : "internalType": "uint256",
281 : "name": "reserveA",
282 : "type": "uint256"
283 : },
284 : {
285 : "internalType": "uint256",
286 : "name": "reserveB",
287 : "type": "uint256"
288 : }
289 : ],
290 : "name": "quote",
291 : "outputs": [
292 : {
293 : "internalType": "uint256",
294 : "name": "amountB",
295 : "type": "uint256"
296 : }
297 : ],
298 : "stateMutability": "pure",
299 : "type": "function"
300 : },
301 : {
302 : "inputs": [
303 : {
304 : "internalType": "address",
305 : "name": "tokenA",
306 : "type": "address"
307 : },
308 : {
309 : "internalType": "address",
310 : "name": "tokenB",
311 : "type": "address"
312 : },
313 : {
314 : "internalType": "uint256",
315 : "name": "liquidity",
316 : "type": "uint256"
317 : },
318 : {
319 : "internalType": "uint256",
320 : "name": "amountAMin",
321 : "type": "uint256"
322 : },
323 : {
324 : "internalType": "uint256",
325 : "name": "amountBMin",
326 : "type": "uint256"
327 : },
328 : {
329 : "internalType": "address",
330 : "name": "to",
331 : "type": "address"
332 : },
333 : {
334 : "internalType": "uint256",
335 : "name": "deadline",
336 : "type": "uint256"
337 : }
338 : ],
339 : "name": "removeLiquidity",
340 : "outputs": [
341 : {
342 : "internalType": "uint256",
343 : "name": "amountA",
344 : "type": "uint256"
345 : },
346 : {
347 : "internalType": "uint256",
348 : "name": "amountB",
349 : "type": "uint256"
350 : }
351 : ],
352 : "stateMutability": "nonpayable",
353 : "type": "function"
354 : },
355 : {
356 : "inputs": [
357 : {
358 : "internalType": "address",
359 : "name": "token",
360 : "type": "address"
361 : },
362 : {
363 : "internalType": "uint256",
364 : "name": "liquidity",
365 : "type": "uint256"
366 : },
367 : {
368 : "internalType": "uint256",
369 : "name": "amountTokenMin",
370 : "type": "uint256"
371 : },
372 : {
373 : "internalType": "uint256",
374 : "name": "amountETHMin",
375 : "type": "uint256"
376 : },
377 : {
378 : "internalType": "address",
379 : "name": "to",
380 : "type": "address"
381 : },
382 : {
383 : "internalType": "uint256",
384 : "name": "deadline",
385 : "type": "uint256"
386 : }
387 : ],
388 : "name": "removeLiquidityETH",
389 : "outputs": [
390 : {
391 : "internalType": "uint256",
392 : "name": "amountToken",
393 : "type": "uint256"
394 : },
395 : {
396 : "internalType": "uint256",
397 : "name": "amountETH",
398 : "type": "uint256"
399 : }
400 : ],
401 : "stateMutability": "nonpayable",
402 : "type": "function"
403 : },
404 : {
405 : "inputs": [
406 : {
407 : "internalType": "address",
408 : "name": "token",
409 : "type": "address"
410 : },
411 : {
412 : "internalType": "uint256",
413 : "name": "liquidity",
414 : "type": "uint256"
415 : },
416 : {
417 : "internalType": "uint256",
418 : "name": "amountTokenMin",
419 : "type": "uint256"
420 : },
421 : {
422 : "internalType": "uint256",
423 : "name": "amountETHMin",
424 : "type": "uint256"
425 : },
426 : {
427 : "internalType": "address",
428 : "name": "to",
429 : "type": "address"
430 : },
431 : {
432 : "internalType": "uint256",
433 : "name": "deadline",
434 : "type": "uint256"
435 : }
436 : ],
437 : "name": "removeLiquidityETHSupportingFeeOnTransferTokens",
438 : "outputs": [
439 : {
440 : "internalType": "uint256",
441 : "name": "amountETH",
442 : "type": "uint256"
443 : }
444 : ],
445 : "stateMutability": "nonpayable",
446 : "type": "function"
447 : },
448 : {
449 : "inputs": [
450 : {
451 : "internalType": "address",
452 : "name": "token",
453 : "type": "address"
454 : },
455 : {
456 : "internalType": "uint256",
457 : "name": "liquidity",
458 : "type": "uint256"
459 : },
460 : {
461 : "internalType": "uint256",
462 : "name": "amountTokenMin",
463 : "type": "uint256"
464 : },
465 : {
466 : "internalType": "uint256",
467 : "name": "amountETHMin",
468 : "type": "uint256"
469 : },
470 : {
471 : "internalType": "address",
472 : "name": "to",
473 : "type": "address"
474 : },
475 : {
476 : "internalType": "uint256",
477 : "name": "deadline",
478 : "type": "uint256"
479 : },
480 : {
481 : "internalType": "bool",
482 : "name": "approveMax",
483 : "type": "bool"
484 : },
485 : {
486 : "internalType": "uint8",
487 : "name": "v",
488 : "type": "uint8"
489 : },
490 : {
491 : "internalType": "bytes32",
492 : "name": "r",
493 : "type": "bytes32"
494 : },
495 : {
496 : "internalType": "bytes32",
497 : "name": "s",
498 : "type": "bytes32"
499 : }
500 : ],
501 : "name": "removeLiquidityETHWithPermit",
502 : "outputs": [
503 : {
504 : "internalType": "uint256",
505 : "name": "amountToken",
506 : "type": "uint256"
507 : },
508 : {
509 : "internalType": "uint256",
510 : "name": "amountETH",
511 : "type": "uint256"
512 : }
513 : ],
514 : "stateMutability": "nonpayable",
515 : "type": "function"
516 : },
517 : {
518 : "inputs": [
519 : {
520 : "internalType": "address",
521 : "name": "token",
522 : "type": "address"
523 : },
524 : {
525 : "internalType": "uint256",
526 : "name": "liquidity",
527 : "type": "uint256"
528 : },
529 : {
530 : "internalType": "uint256",
531 : "name": "amountTokenMin",
532 : "type": "uint256"
533 : },
534 : {
535 : "internalType": "uint256",
536 : "name": "amountETHMin",
537 : "type": "uint256"
538 : },
539 : {
540 : "internalType": "address",
541 : "name": "to",
542 : "type": "address"
543 : },
544 : {
545 : "internalType": "uint256",
546 : "name": "deadline",
547 : "type": "uint256"
548 : },
549 : {
550 : "internalType": "bool",
551 : "name": "approveMax",
552 : "type": "bool"
553 : },
554 : {
555 : "internalType": "uint8",
556 : "name": "v",
557 : "type": "uint8"
558 : },
559 : {
560 : "internalType": "bytes32",
561 : "name": "r",
562 : "type": "bytes32"
563 : },
564 : {
565 : "internalType": "bytes32",
566 : "name": "s",
567 : "type": "bytes32"
568 : }
569 : ],
570 : "name": "removeLiquidityETHWithPermitSupportingFeeOnTransferTokens",
571 : "outputs": [
572 : {
573 : "internalType": "uint256",
574 : "name": "amountETH",
575 : "type": "uint256"
576 : }
577 : ],
578 : "stateMutability": "nonpayable",
579 : "type": "function"
580 : },
581 : {
582 : "inputs": [
583 : {
584 : "internalType": "address",
585 : "name": "tokenA",
586 : "type": "address"
587 : },
588 : {
589 : "internalType": "address",
590 : "name": "tokenB",
591 : "type": "address"
592 : },
593 : {
594 : "internalType": "uint256",
595 : "name": "liquidity",
596 : "type": "uint256"
597 : },
598 : {
599 : "internalType": "uint256",
600 : "name": "amountAMin",
601 : "type": "uint256"
602 : },
603 : {
604 : "internalType": "uint256",
605 : "name": "amountBMin",
606 : "type": "uint256"
607 : },
608 : {
609 : "internalType": "address",
610 : "name": "to",
611 : "type": "address"
612 : },
613 : {
614 : "internalType": "uint256",
615 : "name": "deadline",
616 : "type": "uint256"
617 : },
618 : {
619 : "internalType": "bool",
620 : "name": "approveMax",
621 : "type": "bool"
622 : },
623 : {
624 : "internalType": "uint8",
625 : "name": "v",
626 : "type": "uint8"
627 : },
628 : {
629 : "internalType": "bytes32",
630 : "name": "r",
631 : "type": "bytes32"
632 : },
633 : {
634 : "internalType": "bytes32",
635 : "name": "s",
636 : "type": "bytes32"
637 : }
638 : ],
639 : "name": "removeLiquidityWithPermit",
640 : "outputs": [
641 : {
642 : "internalType": "uint256",
643 : "name": "amountA",
644 : "type": "uint256"
645 : },
646 : {
647 : "internalType": "uint256",
648 : "name": "amountB",
649 : "type": "uint256"
650 : }
651 : ],
652 : "stateMutability": "nonpayable",
653 : "type": "function"
654 : },
655 : {
656 : "inputs": [
657 : {
658 : "internalType": "uint256",
659 : "name": "amountOut",
660 : "type": "uint256"
661 : },
662 : {
663 : "internalType": "address[]",
664 : "name": "path",
665 : "type": "address[]"
666 : },
667 : {
668 : "internalType": "address",
669 : "name": "to",
670 : "type": "address"
671 : },
672 : {
673 : "internalType": "uint256",
674 : "name": "deadline",
675 : "type": "uint256"
676 : }
677 : ],
678 : "name": "swapETHForExactTokens",
679 : "outputs": [
680 : {
681 : "internalType": "uint256[]",
682 : "name": "amounts",
683 : "type": "uint256[]"
684 : }
685 : ],
686 : "stateMutability": "payable",
687 : "type": "function"
688 : },
689 : {
690 : "inputs": [
691 : {
692 : "internalType": "uint256",
693 : "name": "amountOutMin",
694 : "type": "uint256"
695 : },
696 : {
697 : "internalType": "address[]",
698 : "name": "path",
699 : "type": "address[]"
700 : },
701 : {
702 : "internalType": "address",
703 : "name": "to",
704 : "type": "address"
705 : },
706 : {
707 : "internalType": "uint256",
708 : "name": "deadline",
709 : "type": "uint256"
710 : }
711 : ],
712 : "name": "swapExactETHForTokens",
713 : "outputs": [
714 : {
715 : "internalType": "uint256[]",
716 : "name": "amounts",
717 : "type": "uint256[]"
718 : }
719 : ],
720 : "stateMutability": "payable",
721 : "type": "function"
722 : },
723 : {
724 : "inputs": [
725 : {
726 : "internalType": "uint256",
727 : "name": "amountOutMin",
728 : "type": "uint256"
729 : },
730 : {
731 : "internalType": "address[]",
732 : "name": "path",
733 : "type": "address[]"
734 : },
735 : {
736 : "internalType": "address",
737 : "name": "to",
738 : "type": "address"
739 : },
740 : {
741 : "internalType": "uint256",
742 : "name": "deadline",
743 : "type": "uint256"
744 : }
745 : ],
746 : "name": "swapExactETHForTokensSupportingFeeOnTransferTokens",
747 : "outputs": [],
748 : "stateMutability": "payable",
749 : "type": "function"
750 : },
751 : {
752 : "inputs": [
753 : {
754 : "internalType": "uint256",
755 : "name": "amountIn",
756 : "type": "uint256"
757 : },
758 : {
759 : "internalType": "uint256",
760 : "name": "amountOutMin",
761 : "type": "uint256"
762 : },
763 : {
764 : "internalType": "address[]",
765 : "name": "path",
766 : "type": "address[]"
767 : },
768 : {
769 : "internalType": "address",
770 : "name": "to",
771 : "type": "address"
772 : },
773 : {
774 : "internalType": "uint256",
775 : "name": "deadline",
776 : "type": "uint256"
777 : }
778 : ],
779 : "name": "swapExactTokensForETH",
780 : "outputs": [
781 : {
782 : "internalType": "uint256[]",
783 : "name": "amounts",
784 : "type": "uint256[]"
785 : }
786 : ],
787 : "stateMutability": "nonpayable",
788 : "type": "function"
789 : },
790 : {
791 : "inputs": [
792 : {
793 : "internalType": "uint256",
794 : "name": "amountIn",
795 : "type": "uint256"
796 : },
797 : {
798 : "internalType": "uint256",
799 : "name": "amountOutMin",
800 : "type": "uint256"
801 : },
802 : {
803 : "internalType": "address[]",
804 : "name": "path",
805 : "type": "address[]"
806 : },
807 : {
808 : "internalType": "address",
809 : "name": "to",
810 : "type": "address"
811 : },
812 : {
813 : "internalType": "uint256",
814 : "name": "deadline",
815 : "type": "uint256"
816 : }
817 : ],
818 : "name": "swapExactTokensForETHSupportingFeeOnTransferTokens",
819 : "outputs": [],
820 : "stateMutability": "nonpayable",
821 : "type": "function"
822 : },
823 : {
824 : "inputs": [
825 : {
826 : "internalType": "uint256",
827 : "name": "amountIn",
828 : "type": "uint256"
829 : },
830 : {
831 : "internalType": "uint256",
832 : "name": "amountOutMin",
833 : "type": "uint256"
834 : },
835 : {
836 : "internalType": "address[]",
837 : "name": "path",
838 : "type": "address[]"
839 : },
840 : {
841 : "internalType": "address",
842 : "name": "to",
843 : "type": "address"
844 : },
845 : {
846 : "internalType": "uint256",
847 : "name": "deadline",
848 : "type": "uint256"
849 : }
850 : ],
851 : "name": "swapExactTokensForTokens",
852 : "outputs": [
853 : {
854 : "internalType": "uint256[]",
855 : "name": "amounts",
856 : "type": "uint256[]"
857 : }
858 : ],
859 : "stateMutability": "nonpayable",
860 : "type": "function"
861 : },
862 : {
863 : "inputs": [
864 : {
865 : "internalType": "uint256",
866 : "name": "amountIn",
867 : "type": "uint256"
868 : },
869 : {
870 : "internalType": "uint256",
871 : "name": "amountOutMin",
872 : "type": "uint256"
873 : },
874 : {
875 : "internalType": "address[]",
876 : "name": "path",
877 : "type": "address[]"
878 : },
879 : {
880 : "internalType": "address",
881 : "name": "to",
882 : "type": "address"
883 : },
884 : {
885 : "internalType": "uint256",
886 : "name": "deadline",
887 : "type": "uint256"
888 : }
889 : ],
890 : "name": "swapExactTokensForTokensSupportingFeeOnTransferTokens",
891 : "outputs": [],
892 : "stateMutability": "nonpayable",
893 : "type": "function"
894 : },
895 : {
896 : "inputs": [
897 : {
898 : "internalType": "uint256",
899 : "name": "amountOut",
900 : "type": "uint256"
901 : },
902 : {
903 : "internalType": "uint256",
904 : "name": "amountInMax",
905 : "type": "uint256"
906 : },
907 : {
908 : "internalType": "address[]",
909 : "name": "path",
910 : "type": "address[]"
911 : },
912 : {
913 : "internalType": "address",
914 : "name": "to",
915 : "type": "address"
916 : },
917 : {
918 : "internalType": "uint256",
919 : "name": "deadline",
920 : "type": "uint256"
921 : }
922 : ],
923 : "name": "swapTokensForExactETH",
924 : "outputs": [
925 : {
926 : "internalType": "uint256[]",
927 : "name": "amounts",
928 : "type": "uint256[]"
929 : }
930 : ],
931 : "stateMutability": "nonpayable",
932 : "type": "function"
933 : },
934 : {
935 : "inputs": [
936 : {
937 : "internalType": "uint256",
938 : "name": "amountOut",
939 : "type": "uint256"
940 : },
941 : {
942 : "internalType": "uint256",
943 : "name": "amountInMax",
944 : "type": "uint256"
945 : },
946 : {
947 : "internalType": "address[]",
948 : "name": "path",
949 : "type": "address[]"
950 : },
951 : {
952 : "internalType": "address",
953 : "name": "to",
954 : "type": "address"
955 : },
956 : {
957 : "internalType": "uint256",
958 : "name": "deadline",
959 : "type": "uint256"
960 : }
961 : ],
962 : "name": "swapTokensForExactTokens",
963 : "outputs": [
964 : {
965 : "internalType": "uint256[]",
966 : "name": "amounts",
967 : "type": "uint256[]"
968 : }
969 : ],
970 : "stateMutability": "nonpayable",
971 : "type": "function"
972 : },
973 : {
974 : "stateMutability": "payable",
975 : "type": "receive"
976 : }
977 : ]
978 : """);
979 :
980 : class UniswapV2Router extends InternalContract {
981 0 : UniswapV2Router({
982 : required super.rpc,
983 : required super.contractAddress,
984 0 : }) : super(
985 0 : abi: uniswap_v2_router_abi,
986 : );
987 :
988 0 : Future<List<BigInt>> getAmountsOut({
989 : required BigInt amountIn,
990 : required List<String> path,
991 : }) async {
992 0 : final function = abi.getFunction("getAmountsOut")!;
993 :
994 0 : final result = await readSafe(
995 0 : function: function.addValues(values: [amountIn, path]),
996 : );
997 :
998 0 : return [
999 0 : for (final r in result.outputs.first.value) r as BigInt,
1000 : ];
1001 : }
1002 :
1003 0 : Future<List<BigInt>> getAmountsIn({
1004 : required BigInt amountOut,
1005 : required List<String> path,
1006 : }) async {
1007 0 : final function = abi.getFunction("getAmountsIn")!;
1008 :
1009 0 : final result = await readSafe(
1010 0 : function: function.addValues(values: [amountOut, path]),
1011 : );
1012 :
1013 0 : return [
1014 0 : for (final r in result.outputs.first.value) r as BigInt,
1015 : ];
1016 : }
1017 :
1018 0 : Future<String> swapExactEthForTokens({
1019 : required BigInt amountIn,
1020 : required BigInt amountOutMin,
1021 : required List<String> path,
1022 : required String to,
1023 : required BigInt deadline,
1024 : required Uint8List privateKey,
1025 : required String sender,
1026 : EvmFeeInformation? feeInformation,
1027 : }) async {
1028 0 : final function = abi.getFunction("swapExactETHForTokens")!;
1029 :
1030 0 : final result = await interact(
1031 : privateKey: privateKey,
1032 : value: amountIn,
1033 0 : function: function.addValues(values: [amountOutMin, path, to, deadline]),
1034 : sender: sender,
1035 : feeInfo: feeInformation,
1036 : );
1037 :
1038 : return result;
1039 : }
1040 :
1041 0 : Future<RawEvmTransaction> swapExactEthForTokensTransaction({
1042 : required BigInt amountIn,
1043 : required BigInt amountOutMin,
1044 : required List<String> path,
1045 : required String to,
1046 : required BigInt deadline,
1047 : required String sender,
1048 : EvmFeeInformation? feeInformation,
1049 : }) async {
1050 0 : final function = abi.getFunction("swapExactETHForTokens")!;
1051 :
1052 0 : final result = await buildTransactionForFunction(
1053 : value: amountIn,
1054 0 : function: function.addValues(values: [amountOutMin, path, to, deadline]),
1055 : sender: sender,
1056 : feeInfo: feeInformation,
1057 : );
1058 :
1059 : return result;
1060 : }
1061 :
1062 0 : Future<String> swapExactTokensForEth({
1063 : required BigInt amountIn,
1064 : required BigInt amountOutMin,
1065 : required List<String> path,
1066 : required String to,
1067 : required BigInt deadline,
1068 : required Uint8List privateKey,
1069 : required String sender,
1070 : }) async {
1071 0 : final function = abi.getFunction("swapExactTokensForETH")!;
1072 :
1073 0 : final result = await interact(
1074 : privateKey: privateKey,
1075 : sender: sender,
1076 : function: function
1077 0 : .addValues(values: [amountIn, amountOutMin, path, to, deadline]),
1078 : );
1079 :
1080 : return result;
1081 : }
1082 :
1083 0 : Future<RawEvmTransaction> swapExactTokensForEthTx({
1084 : required BigInt amountIn,
1085 : required BigInt amountOutMin,
1086 : required List<String> path,
1087 : required String to,
1088 : required BigInt deadline,
1089 : required String sender,
1090 : }) async {
1091 0 : final function = abi.getFunction("swapExactTokensForETH")!;
1092 :
1093 0 : final result = await buildTransactionForFunction(
1094 : sender: sender,
1095 : function: function
1096 0 : .addValues(values: [amountIn, amountOutMin, path, to, deadline]),
1097 : );
1098 :
1099 : return result;
1100 : }
1101 :
1102 0 : Future<String> swapExactTokenForTokens({
1103 : required BigInt amountIn,
1104 : required BigInt amountOutMin,
1105 : required List<String> path,
1106 : required String to,
1107 : required BigInt deadline,
1108 : required Uint8List privateKey,
1109 : required String sender,
1110 : }) async {
1111 0 : final function = abi.getFunction("swapExactTokensForTokens")!;
1112 :
1113 0 : final result = await interact(
1114 : privateKey: privateKey,
1115 : sender: sender,
1116 : function: function
1117 0 : .addValues(values: [amountIn, amountOutMin, path, to, deadline]),
1118 : );
1119 :
1120 : return result;
1121 : }
1122 :
1123 0 : Future<RawEvmTransaction> swapExactTokenForTokensTx({
1124 : required BigInt amountIn,
1125 : required BigInt amountOutMin,
1126 : required List<String> path,
1127 : required String to,
1128 : required BigInt deadline,
1129 : required String sender,
1130 : }) async {
1131 0 : final function = abi.getFunction("swapExactTokensForTokens")!;
1132 :
1133 0 : final result = await buildTransactionForFunction(
1134 : sender: sender,
1135 : function: function
1136 0 : .addValues(values: [amountIn, amountOutMin, path, to, deadline]),
1137 : );
1138 :
1139 : return result;
1140 : }
1141 :
1142 0 : Future<String> swapEthForExactTokens({
1143 : required BigInt amountOut,
1144 : required BigInt amountInMax,
1145 : required List<String> path,
1146 : required String to,
1147 : required BigInt deadline,
1148 : required Uint8List privateKey,
1149 : required String sender,
1150 : }) async {
1151 0 : final function = abi.getFunction("swapETHForExactTokens")!;
1152 :
1153 0 : final result = await interact(
1154 : privateKey: privateKey,
1155 : sender: sender,
1156 0 : function: function.addValues(values: [amountOut, path, to, deadline]),
1157 : value: amountInMax,
1158 : );
1159 :
1160 : return result;
1161 : }
1162 :
1163 0 : Future<RawEvmTransaction> swapEthForExactTokensTx({
1164 : required BigInt amountOut,
1165 : required BigInt amountInMax,
1166 : required List<String> path,
1167 : required String to,
1168 : required BigInt deadline,
1169 : required String sender,
1170 : }) async {
1171 0 : final function = abi.getFunction("swapETHForExactTokens")!;
1172 :
1173 0 : final result = await buildTransactionForFunction(
1174 : sender: sender,
1175 0 : function: function.addValues(values: [amountOut, path, to, deadline]),
1176 : value: amountInMax,
1177 : );
1178 :
1179 : return result;
1180 : }
1181 :
1182 0 : Future<String> swapTokenForExactEth({
1183 : required BigInt amountOut,
1184 : required BigInt amountInMax,
1185 : required List<String> path,
1186 : required String to,
1187 : required BigInt deadline,
1188 : required Uint8List privateKey,
1189 : required String sender,
1190 : }) async {
1191 0 : final function = abi.getFunction("swapTokensForExactETH")!;
1192 :
1193 0 : final result = await interact(
1194 : privateKey: privateKey,
1195 : sender: sender,
1196 : function: function
1197 0 : .addValues(values: [amountOut, amountInMax, path, to, deadline]),
1198 : );
1199 :
1200 : return result;
1201 : }
1202 :
1203 0 : Future<RawEvmTransaction> swapTokenForExactEthTx({
1204 : required BigInt amountOut,
1205 : required BigInt amountInMax,
1206 : required List<String> path,
1207 : required String to,
1208 : required BigInt deadline,
1209 : required String sender,
1210 : }) async {
1211 0 : final function = abi.getFunction("swapTokensForExactETH")!;
1212 :
1213 0 : final result = await buildTransactionForFunction(
1214 : sender: sender,
1215 : function: function
1216 0 : .addValues(values: [amountOut, amountInMax, path, to, deadline]),
1217 : );
1218 :
1219 : return result;
1220 : }
1221 :
1222 0 : Future<String> swapTokenForExactTokens({
1223 : required BigInt amountOut,
1224 : required BigInt amountInMax,
1225 : required List<String> path,
1226 : required String to,
1227 : required BigInt deadline,
1228 : required Uint8List privateKey,
1229 : required String sender,
1230 : }) async {
1231 0 : final function = abi.getFunction("swapTokensForExactTokens")!;
1232 :
1233 0 : final result = await interact(
1234 : privateKey: privateKey,
1235 : sender: sender,
1236 : function: function
1237 0 : .addValues(values: [amountOut, amountInMax, path, to, deadline]),
1238 : );
1239 :
1240 : return result;
1241 : }
1242 :
1243 0 : Future<RawEvmTransaction> swapTokenForExactTokensTx({
1244 : required BigInt amountOut,
1245 : required BigInt amountInMax,
1246 : required List<String> path,
1247 : required String to,
1248 : required BigInt deadline,
1249 : required String sender,
1250 : }) async {
1251 0 : final function = abi.getFunction("swapTokensForExactTokens")!;
1252 :
1253 0 : final result = await buildTransactionForFunction(
1254 : sender: sender,
1255 : function: function
1256 0 : .addValues(values: [amountOut, amountInMax, path, to, deadline]),
1257 : );
1258 :
1259 : return result;
1260 : }
1261 :
1262 0 : Future<BigInt> quote({
1263 : required BigInt amountA,
1264 : required BigInt reserveA,
1265 : required BigInt reserveB,
1266 : }) async {
1267 0 : final function = abi.getFunction("quote")!;
1268 :
1269 0 : final result = await readSafe(
1270 0 : function: function.addValues(values: [
1271 : amountA,
1272 : reserveA,
1273 : reserveB,
1274 : ]),
1275 : );
1276 :
1277 0 : return result.outputs.first.value as BigInt;
1278 : }
1279 :
1280 0 : Future<RawEvmTransaction> addLiquidityTx({
1281 : required String tokenA,
1282 : required String tokenB,
1283 : required BigInt amountADesired,
1284 : required BigInt amountBDesired,
1285 : required BigInt amountAMin,
1286 : required BigInt amountBMin,
1287 : required String to,
1288 : required BigInt deadline,
1289 : required String sender,
1290 : }) async {
1291 0 : final function = abi.getFunction("addLiquidity")!;
1292 0 : final result = await buildTransactionForFunction(
1293 : sender: sender,
1294 0 : function: function.addValues(
1295 0 : values: [
1296 : tokenA,
1297 : tokenB,
1298 : amountADesired,
1299 : amountBDesired,
1300 : amountAMin,
1301 : amountBMin,
1302 : to,
1303 : deadline,
1304 : ],
1305 : ),
1306 : );
1307 : return result;
1308 : }
1309 :
1310 0 : Future<RawEvmTransaction> addLiquidityETHTx({
1311 : required String token,
1312 : required BigInt amountTokenDesired,
1313 : required BigInt amountETHMin,
1314 : required BigInt amountTokenMin,
1315 : required String to,
1316 : required BigInt deadline,
1317 : required String sender,
1318 : required BigInt amountETHDesired,
1319 : }) async {
1320 0 : final function = abi.getFunction("addLiquidityETH")!;
1321 0 : final result = await buildTransactionForFunction(
1322 : value: amountETHDesired,
1323 : sender: sender,
1324 0 : function: function.addValues(values: [
1325 : token,
1326 : amountTokenDesired,
1327 : amountTokenMin,
1328 : amountETHMin,
1329 : to,
1330 : deadline,
1331 : ]),
1332 : );
1333 : return result;
1334 : }
1335 :
1336 0 : Future<RawEvmTransaction> removeLiquidityETHTx({
1337 : required String token,
1338 : required BigInt liquidity,
1339 : required BigInt amountTokenMin,
1340 : required BigInt amountETHMin,
1341 : required String to,
1342 : required BigInt deadline,
1343 : required String sender,
1344 : }) async {
1345 0 : final function = abi.getFunction("removeLiquidityETH")!;
1346 0 : final result = await buildTransactionForFunction(
1347 : sender: sender,
1348 0 : function: function.addValues(values: [
1349 : token,
1350 : liquidity,
1351 : amountTokenMin,
1352 : amountETHMin,
1353 : to,
1354 : deadline,
1355 : ]),
1356 : );
1357 : return result;
1358 : }
1359 : }
|