@@ -594,26 +594,31 @@ def _token_to_eth_swap_input(
594
594
min_tokens_bought = int ((1 - slippage ) * self ._get_token_eth_input_price (input_token , qty , fee = fee ))
595
595
sqrtPriceLimitX96 = 0
596
596
597
- # Prepare swap data
598
- swap_arg_types = [ "address" , "address" , "uint24" , "address" , "uint256" , "uint256" , "uint256" , "uint160" ]
599
- swap_arg_types_str = f"( { ',' . join ( swap_arg_types ) } )"
600
-
601
- swap_selector = function_signature_to_4byte_selector ( f"exactInputSingle( { swap_arg_types_str } )" )
602
-
603
- swap_args = [ input_token , output_token , fee , ETH_ADDRESS , self . _deadline (), qty , min_tokens_bought , sqrtPriceLimitX96 ]
604
- swap_args_encoded = encode_abi ( swap_arg_types , swap_args )
605
-
606
- # Prepare unwrap data
607
- unwrap_arg_types = [ "uint256" , "address" ]
608
- unwrap_arg_types_str = f" { ',' . join ( unwrap_arg_types ) } "
609
-
610
- unwrap_selector = function_signature_to_4byte_selector ( f"unwrapWETH9( { unwrap_arg_types_str } )" )
597
+ swap_data = self . router . encodeABI (
598
+ fn_name = "exactInputSingle" ,
599
+ args = [
600
+ ( input_token ,
601
+ output_token ,
602
+ fee ,
603
+ ETH_ADDRESS ,
604
+ self . _deadline (),
605
+ qty ,
606
+ min_tokens_bought ,
607
+ sqrtPriceLimitX96
608
+ )
609
+ ]
610
+ )
611
611
612
- unwrap_args = [min_tokens_bought , recipient ]
613
- unwrap_args_encoded = encode_abi (unwrap_arg_types , unwrap_args )
612
+ unwrap_data = self .router .encodeABI (
613
+ fn_name = "unwrapWETH9" ,
614
+ args = [
615
+ min_tokens_bought ,
616
+ recipient
617
+ ]
618
+ )
614
619
615
620
# Multicall
616
- multicall_data = [swap_selector + swap_args_encoded , unwrap_selector + unwrap_args_encoded ]
621
+ multicall_data = [swap_data , unwrap_data ]
617
622
618
623
return self ._build_and_send_tx (
619
624
self .router .functions .multicall (
@@ -776,20 +781,28 @@ def _eth_to_token_swap_output(
776
781
777
782
sqrtPriceLimitX96 = 0
778
783
779
- # Prepare swap data
780
- swap_arg_types = ["address" , "address" , "uint24" , "address" , "uint256" , "uint256" , "uint256" , "uint160" ]
781
- swap_arg_types_str = f"({ ',' .join (swap_arg_types )} )"
782
-
783
- swap_selector = function_signature_to_4byte_selector (f"exactOutputSingle({ swap_arg_types_str } )" )
784
-
785
- swap_args = [self .get_weth_address (), output_token , fee , recipient , self ._deadline (), qty , amount_in_max , sqrtPriceLimitX96 ]
786
- swap_args_encoded = encode_abi (swap_arg_types , swap_args )
784
+ swap_data = self .router .encodeABI (
785
+ fn_name = "exactOutputSingle" ,
786
+ args = [
787
+ (self .get_weth_address (),
788
+ output_token ,
789
+ fee ,
790
+ recipient ,
791
+ self ._deadline (),
792
+ qty ,
793
+ amount_in_max ,
794
+ sqrtPriceLimitX96
795
+ )
796
+ ]
797
+ )
787
798
788
- # Prepare refund data
789
- refund_selector = function_signature_to_4byte_selector (f"refundETH()" )
799
+ refund_data = self .router .encodeABI (
800
+ fn_name = "refundETH" ,
801
+ args = None
802
+ )
790
803
791
804
# Multicall
792
- multicall_data = [swap_selector + swap_args_encoded , refund_selector ]
805
+ multicall_data = [swap_data , refund_data ]
793
806
794
807
return self ._build_and_send_tx (
795
808
self .router .functions .multicall (
@@ -862,26 +875,31 @@ def _token_to_eth_swap_output(
862
875
863
876
sqrtPriceLimitX96 = 0
864
877
865
- # Prepare swap data
866
- swap_arg_types = [ "address" , "address" , "uint24" , "address" , "uint256" , "uint256" , "uint256" , "uint160" ]
867
- swap_arg_types_str = f"( { ',' . join ( swap_arg_types ) } )"
868
-
869
- swap_selector = function_signature_to_4byte_selector ( f"exactOutputSingle( { swap_arg_types_str } )" )
870
-
871
- swap_args = [ input_token , self . get_weth_address (), fee , ETH_ADDRESS , self . _deadline (), qty , amount_in_max , sqrtPriceLimitX96 ]
872
- swap_args_encoded = encode_abi ( swap_arg_types , swap_args )
873
-
874
- # Prepare unwrap data
875
- unwrap_arg_types = [ "uint256" , "address" ]
876
- unwrap_arg_types_str = f" { ',' . join ( unwrap_arg_types ) } "
877
-
878
- unwrap_selector = function_signature_to_4byte_selector ( f"unwrapWETH9( { unwrap_arg_types_str } )" )
878
+ swap_data = self . router . encodeABI (
879
+ fn_name = "exactOutputSingle" ,
880
+ args = [
881
+ ( input_token ,
882
+ self . get_weth_address (),
883
+ fee ,
884
+ ETH_ADDRESS ,
885
+ self . _deadline (),
886
+ qty ,
887
+ amount_in_max ,
888
+ sqrtPriceLimitX96
889
+ )
890
+ ]
891
+ )
879
892
880
- unwrap_args = [qty , recipient ]
881
- unwrap_args_encoded = encode_abi (unwrap_arg_types , unwrap_args )
893
+ unwrap_data = self .router .encodeABI (
894
+ fn_name = "unwrapWETH9" ,
895
+ args = [
896
+ qty ,
897
+ recipient
898
+ ]
899
+ )
882
900
883
901
# Multicall
884
- multicall_data = [swap_selector + swap_args_encoded , unwrap_selector + unwrap_args_encoded ]
902
+ multicall_data = [swap_data , unwrap_data ]
885
903
886
904
return self ._build_and_send_tx (
887
905
self .router .functions .multicall (
0 commit comments