@@ -10,11 +10,12 @@ import { take } from "lodash";
10
10
11
11
const expect = getWaffleExpect ( ) ;
12
12
13
- describe ( "ZeroExApiAdapter" , ( ) => {
13
+ describe . only ( "ZeroExApiAdapter" , ( ) => {
14
14
let owner : Account ;
15
15
const sourceToken = "0x6cf5f1d59fddae3a688210953a512b6aee6ea643" ;
16
16
const destToken = "0x5e5d0bea9d4a15db2d0837aff0435faba166190d" ;
17
17
const otherToken = "0xae9902bb655de1a67f334d8661b3ae6a96723d5b" ;
18
+ const wethToken = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2" ;
18
19
const extraHopToken = "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48" ;
19
20
const destination = "0x89b3515cad4f23c1deacea79fc12445cc21bd0e1" ;
20
21
const otherDestination = "0xdeb100c55cccfd6e39753f78c8b0c3bcbef86157" ;
@@ -33,7 +34,7 @@ describe("ZeroExApiAdapter", () => {
33
34
34
35
// Mock OneInch exchange that allows for only fixed exchange amounts
35
36
zeroExMock = await deployer . mocks . deployZeroExMock ( ADDRESS_ZERO , ADDRESS_ZERO , ZERO , ZERO ) ;
36
- zeroExApiAdapter = await deployer . adapters . deployZeroExApiAdapter ( zeroExMock . address ) ;
37
+ zeroExApiAdapter = await deployer . adapters . deployZeroExApiAdapter ( zeroExMock . address , wethToken ) ;
37
38
} ) ;
38
39
39
40
addSnapshotBeforeRestoreAfterEach ( ) ;
@@ -305,6 +306,26 @@ describe("ZeroExApiAdapter", () => {
305
306
expect ( _data ) . to . deep . eq ( data ) ;
306
307
} ) ;
307
308
309
+ it ( "permits any destination address when recipient is null" , async ( ) => {
310
+ const data = zeroExMock . interface . encodeFunctionData ( "sellToLiquidityProvider" , [
311
+ sourceToken ,
312
+ destToken ,
313
+ ADDRESS_ZERO ,
314
+ ADDRESS_ZERO ,
315
+ sourceQuantity ,
316
+ minDestinationQuantity ,
317
+ EMPTY_BYTES ,
318
+ ] ) ;
319
+ await zeroExApiAdapter . getTradeCalldata (
320
+ sourceToken ,
321
+ destToken ,
322
+ destination ,
323
+ sourceQuantity ,
324
+ minDestinationQuantity ,
325
+ data ,
326
+ ) ;
327
+ } ) ;
328
+
308
329
it ( "rejects wrong input token" , async ( ) => {
309
330
const data = zeroExMock . interface . encodeFunctionData ( "sellToLiquidityProvider" , [
310
331
otherToken ,
@@ -659,6 +680,7 @@ describe("ZeroExApiAdapter", () => {
659
680
660
681
describe ( "sellTokenForTokenToUniswapV3" , ( ) => {
661
682
const additionalHops = [ otherToken , extraHopToken ] ;
683
+
662
684
for ( let i = 0 ; i <= additionalHops . length ; i ++ ) {
663
685
const hops = take ( additionalHops , i ) ;
664
686
it ( `validates data for ${ i + 1 } hops` , async ( ) => {
@@ -684,6 +706,25 @@ describe("ZeroExApiAdapter", () => {
684
706
} ) ;
685
707
}
686
708
709
+ it ( "permits any destination address when recipient is null" , async ( ) => {
710
+ const path = [ sourceToken , destToken ] ;
711
+
712
+ const data = zeroExMock . interface . encodeFunctionData ( "sellTokenForTokenToUniswapV3" , [
713
+ encodePath ( path ) ,
714
+ sourceQuantity ,
715
+ minDestinationQuantity ,
716
+ ADDRESS_ZERO ,
717
+ ] ) ;
718
+ await zeroExApiAdapter . getTradeCalldata (
719
+ sourceToken ,
720
+ destToken ,
721
+ destination ,
722
+ sourceQuantity ,
723
+ minDestinationQuantity ,
724
+ data ,
725
+ ) ;
726
+ } ) ;
727
+
687
728
it ( "rejects wrong input token" , async ( ) => {
688
729
const data = zeroExMock . interface . encodeFunctionData ( "sellTokenForTokenToUniswapV3" , [
689
730
encodePath ( [ otherToken , destToken ] ) ,
@@ -779,12 +820,12 @@ describe("ZeroExApiAdapter", () => {
779
820
encodePath ( [ sourceToken , destToken ] ) ,
780
821
sourceQuantity ,
781
822
minDestinationQuantity ,
782
- ADDRESS_ZERO ,
823
+ destination ,
783
824
] ) ;
784
825
const tx = zeroExApiAdapter . getTradeCalldata (
785
826
sourceToken ,
786
827
destToken ,
787
- destination ,
828
+ otherDestination ,
788
829
sourceQuantity ,
789
830
minDestinationQuantity ,
790
831
data ,
@@ -798,7 +839,7 @@ describe("ZeroExApiAdapter", () => {
798
839
for ( let i = 0 ; i <= additionalHops . length ; i ++ ) {
799
840
const hops = take ( additionalHops , i ) ;
800
841
it ( `validates data for ${ i + 1 } hops` , async ( ) => {
801
- const path = [ sourceToken , ...hops , ETH_ADDRESS ] ;
842
+ const path = [ sourceToken , ...hops , wethToken ] ;
802
843
803
844
const data = zeroExMock . interface . encodeFunctionData ( "sellTokenForEthToUniswapV3" , [
804
845
encodePath ( path ) ,
@@ -820,9 +861,28 @@ describe("ZeroExApiAdapter", () => {
820
861
} ) ;
821
862
}
822
863
864
+ it ( "permits any destination address when recipient is null" , async ( ) => {
865
+ const path = [ sourceToken , wethToken ] ;
866
+
867
+ const data = zeroExMock . interface . encodeFunctionData ( "sellTokenForEthToUniswapV3" , [
868
+ encodePath ( path ) ,
869
+ sourceQuantity ,
870
+ minDestinationQuantity ,
871
+ ADDRESS_ZERO ,
872
+ ] ) ;
873
+ await zeroExApiAdapter . getTradeCalldata (
874
+ sourceToken ,
875
+ ETH_ADDRESS ,
876
+ destination ,
877
+ sourceQuantity ,
878
+ minDestinationQuantity ,
879
+ data ,
880
+ ) ;
881
+ } ) ;
882
+
823
883
it ( "rejects wrong input token" , async ( ) => {
824
884
const data = zeroExMock . interface . encodeFunctionData ( "sellTokenForEthToUniswapV3" , [
825
- encodePath ( [ otherToken , ETH_ADDRESS ] ) ,
885
+ encodePath ( [ otherToken , wethToken ] ) ,
826
886
sourceQuantity ,
827
887
minDestinationQuantity ,
828
888
destination ,
@@ -839,6 +899,24 @@ describe("ZeroExApiAdapter", () => {
839
899
} ) ;
840
900
841
901
it ( "rejects wrong output token" , async ( ) => {
902
+ const data = zeroExMock . interface . encodeFunctionData ( "sellTokenForEthToUniswapV3" , [
903
+ encodePath ( [ sourceToken , wethToken ] ) ,
904
+ sourceQuantity ,
905
+ minDestinationQuantity ,
906
+ destination ,
907
+ ] ) ;
908
+ const tx = zeroExApiAdapter . getTradeCalldata (
909
+ sourceToken ,
910
+ otherToken ,
911
+ destination ,
912
+ sourceQuantity ,
913
+ minDestinationQuantity ,
914
+ data ,
915
+ ) ;
916
+ await expect ( tx ) . to . be . revertedWith ( "Mismatched output token" ) ;
917
+ } ) ;
918
+
919
+ it ( "rejects non-WETH output token in encoded path" , async ( ) => {
842
920
const data = zeroExMock . interface . encodeFunctionData ( "sellTokenForEthToUniswapV3" , [
843
921
encodePath ( [ sourceToken , otherToken ] ) ,
844
922
sourceQuantity ,
@@ -853,12 +931,12 @@ describe("ZeroExApiAdapter", () => {
853
931
minDestinationQuantity ,
854
932
data ,
855
933
) ;
856
- await expect ( tx ) . to . be . revertedWith ( "Mismatched output token" ) ;
934
+ await expect ( tx ) . to . be . revertedWith ( "Last token must be WETH " ) ;
857
935
} ) ;
858
936
859
937
it ( "rejects wrong input token quantity" , async ( ) => {
860
938
const data = zeroExMock . interface . encodeFunctionData ( "sellTokenForEthToUniswapV3" , [
861
- encodePath ( [ sourceToken , ETH_ADDRESS ] ) ,
939
+ encodePath ( [ sourceToken , wethToken ] ) ,
862
940
otherQuantity ,
863
941
minDestinationQuantity ,
864
942
destination ,
@@ -876,7 +954,7 @@ describe("ZeroExApiAdapter", () => {
876
954
877
955
it ( "rejects wrong output token quantity" , async ( ) => {
878
956
const data = zeroExMock . interface . encodeFunctionData ( "sellTokenForEthToUniswapV3" , [
879
- encodePath ( [ sourceToken , ETH_ADDRESS ] ) ,
957
+ encodePath ( [ sourceToken , wethToken ] ) ,
880
958
sourceQuantity ,
881
959
otherQuantity ,
882
960
destination ,
@@ -912,15 +990,15 @@ describe("ZeroExApiAdapter", () => {
912
990
913
991
it ( "rejects wrong destination" , async ( ) => {
914
992
const data = zeroExMock . interface . encodeFunctionData ( "sellTokenForEthToUniswapV3" , [
915
- encodePath ( [ sourceToken , ETH_ADDRESS ] ) ,
993
+ encodePath ( [ sourceToken , wethToken ] ) ,
916
994
sourceQuantity ,
917
995
minDestinationQuantity ,
918
- ADDRESS_ZERO ,
996
+ destination ,
919
997
] ) ;
920
998
const tx = zeroExApiAdapter . getTradeCalldata (
921
999
sourceToken ,
922
1000
ETH_ADDRESS ,
923
- destination ,
1001
+ otherDestination ,
924
1002
sourceQuantity ,
925
1003
minDestinationQuantity ,
926
1004
data ,
@@ -934,7 +1012,7 @@ describe("ZeroExApiAdapter", () => {
934
1012
for ( let i = 0 ; i <= additionalHops . length ; i ++ ) {
935
1013
const hops = take ( additionalHops , i ) ;
936
1014
it ( `validates data for ${ i + 1 } hops` , async ( ) => {
937
- const path = [ ETH_ADDRESS , ...hops , destToken ] ;
1015
+ const path = [ wethToken , ...hops , destToken ] ;
938
1016
939
1017
const data = zeroExMock . interface . encodeFunctionData ( "sellEthForTokenToUniswapV3" , [
940
1018
encodePath ( path ) ,
@@ -955,9 +1033,44 @@ describe("ZeroExApiAdapter", () => {
955
1033
} ) ;
956
1034
}
957
1035
1036
+ it ( "permits any destination address when recipient is null" , async ( ) => {
1037
+ const path = [ wethToken , destToken ] ;
1038
+
1039
+ const data = zeroExMock . interface . encodeFunctionData ( "sellEthForTokenToUniswapV3" , [
1040
+ encodePath ( path ) ,
1041
+ minDestinationQuantity ,
1042
+ ADDRESS_ZERO ,
1043
+ ] ) ;
1044
+ await zeroExApiAdapter . getTradeCalldata (
1045
+ ETH_ADDRESS ,
1046
+ destToken ,
1047
+ destination ,
1048
+ sourceQuantity ,
1049
+ minDestinationQuantity ,
1050
+ data ,
1051
+ ) ;
1052
+ } ) ;
1053
+
1054
+ it ( "rejects non-WETH input token in encoded path" , async ( ) => {
1055
+ const data = zeroExMock . interface . encodeFunctionData ( "sellEthForTokenToUniswapV3" , [
1056
+ encodePath ( [ otherToken , destToken ] ) ,
1057
+ minDestinationQuantity ,
1058
+ destination ,
1059
+ ] ) ;
1060
+ const tx = zeroExApiAdapter . getTradeCalldata (
1061
+ ETH_ADDRESS ,
1062
+ destToken ,
1063
+ destination ,
1064
+ sourceQuantity ,
1065
+ minDestinationQuantity ,
1066
+ data ,
1067
+ ) ;
1068
+ await expect ( tx ) . to . be . revertedWith ( "First token must be WETH" ) ;
1069
+ } ) ;
1070
+
958
1071
it ( "rejects wrong input token" , async ( ) => {
959
1072
const data = zeroExMock . interface . encodeFunctionData ( "sellEthForTokenToUniswapV3" , [
960
- encodePath ( [ ETH_ADDRESS , destToken ] ) ,
1073
+ encodePath ( [ wethToken , destToken ] ) ,
961
1074
minDestinationQuantity ,
962
1075
destination ,
963
1076
] ) ;
@@ -974,7 +1087,7 @@ describe("ZeroExApiAdapter", () => {
974
1087
975
1088
it ( "rejects wrong output token" , async ( ) => {
976
1089
const data = zeroExMock . interface . encodeFunctionData ( "sellEthForTokenToUniswapV3" , [
977
- encodePath ( [ ETH_ADDRESS , otherToken ] ) ,
1090
+ encodePath ( [ wethToken , otherToken ] ) ,
978
1091
minDestinationQuantity ,
979
1092
destination ,
980
1093
] ) ;
@@ -991,7 +1104,7 @@ describe("ZeroExApiAdapter", () => {
991
1104
992
1105
it ( "rejects wrong output token quantity" , async ( ) => {
993
1106
const data = zeroExMock . interface . encodeFunctionData ( "sellEthForTokenToUniswapV3" , [
994
- encodePath ( [ ETH_ADDRESS , destToken ] ) ,
1107
+ encodePath ( [ wethToken , destToken ] ) ,
995
1108
otherQuantity ,
996
1109
destination ,
997
1110
] ) ;
@@ -1008,7 +1121,7 @@ describe("ZeroExApiAdapter", () => {
1008
1121
1009
1122
it ( "rejects invalid uniswap path" , async ( ) => {
1010
1123
const data = zeroExMock . interface . encodeFunctionData ( "sellEthForTokenToUniswapV3" , [
1011
- encodePath ( [ ETH_ADDRESS ] ) ,
1124
+ encodePath ( [ wethToken ] ) ,
1012
1125
minDestinationQuantity ,
1013
1126
destination ,
1014
1127
] ) ;
@@ -1025,14 +1138,14 @@ describe("ZeroExApiAdapter", () => {
1025
1138
1026
1139
it ( "rejects wrong destination" , async ( ) => {
1027
1140
const data = zeroExMock . interface . encodeFunctionData ( "sellEthForTokenToUniswapV3" , [
1028
- encodePath ( [ ETH_ADDRESS , destToken ] ) ,
1141
+ encodePath ( [ wethToken , destToken ] ) ,
1029
1142
minDestinationQuantity ,
1030
- ADDRESS_ZERO ,
1143
+ destination ,
1031
1144
] ) ;
1032
1145
const tx = zeroExApiAdapter . getTradeCalldata (
1033
1146
ETH_ADDRESS ,
1034
1147
destToken ,
1035
- destination ,
1148
+ otherDestination ,
1036
1149
sourceQuantity ,
1037
1150
minDestinationQuantity ,
1038
1151
data ,
0 commit comments