@@ -87,6 +87,72 @@ describe('RouterPlanner', () => {
8787 '0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000bb8000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000de0b6b3a764000000000000000000000000000000000000000000000000000006f05b59d3b2000000000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000000'
8888 )
8989 } )
90+
91+ it ( 'encodes a v4 exactIn swap with V2.1 (includes maxHopSlippage)' , async ( ) => {
92+ const route = new Route ( [ DAI_USDC , USDC_WETH ] , DAI , WETH9 [ 1 ] )
93+ const maxHopSlippage = [ BigNumber . from ( '10000' ) , BigNumber . from ( '20000' ) ]
94+
95+ planner . addAction (
96+ Actions . SWAP_EXACT_IN ,
97+ [
98+ {
99+ currencyIn : DAI . address ,
100+ path : encodeRouteToPath ( route ) ,
101+ maxHopSlippage : maxHopSlippage ,
102+ amountIn : ONE_ETHER_BN . toString ( ) ,
103+ amountOutMinimum : 0 ,
104+ } ,
105+ ] ,
106+ URVersion . V2_1
107+ )
108+
109+ expect ( planner . actions ) . toEqual ( '0x07' )
110+
111+ // Decode with V2.1 ABI to verify maxHopSlippage values
112+ const decoded = defaultAbiCoder . decode (
113+ V4_SWAP_ACTIONS_V2_1 [ Actions . SWAP_EXACT_IN ] . map ( ( v ) => v . type ) ,
114+ planner . params [ 0 ]
115+ )
116+
117+ expect ( decoded [ 0 ] . currencyIn ) . toEqual ( DAI . address )
118+ expect ( decoded [ 0 ] . maxHopSlippage ) . toHaveLength ( 2 )
119+ expect ( decoded [ 0 ] . maxHopSlippage [ 0 ] . toString ( ) ) . toEqual ( '10000' )
120+ expect ( decoded [ 0 ] . maxHopSlippage [ 1 ] . toString ( ) ) . toEqual ( '20000' )
121+ expect ( decoded [ 0 ] . amountIn . toString ( ) ) . toEqual ( ONE_ETHER_BN . toString ( ) )
122+ } )
123+
124+ it ( 'encodes a v4 exactOut swap with V2.1 (includes maxHopSlippage)' , async ( ) => {
125+ const route = new Route ( [ DAI_USDC , USDC_WETH ] , DAI , WETH9 [ 1 ] )
126+ const maxHopSlippage = [ BigNumber . from ( '15000' ) , BigNumber . from ( '25000' ) ]
127+
128+ planner . addAction (
129+ Actions . SWAP_EXACT_OUT ,
130+ [
131+ {
132+ currencyOut : WETH9 [ 1 ] . address ,
133+ path : encodeRouteToPath ( route , true ) ,
134+ maxHopSlippage : maxHopSlippage ,
135+ amountOut : ONE_ETHER_BN . toString ( ) ,
136+ amountInMaximum : ONE_ETHER_BN . mul ( 2 ) . toString ( ) ,
137+ } ,
138+ ] ,
139+ URVersion . V2_1
140+ )
141+
142+ expect ( planner . actions ) . toEqual ( '0x09' )
143+
144+ // Decode with V2.1 ABI to verify maxHopSlippage values
145+ const decoded = defaultAbiCoder . decode (
146+ V4_SWAP_ACTIONS_V2_1 [ Actions . SWAP_EXACT_OUT ] . map ( ( v ) => v . type ) ,
147+ planner . params [ 0 ]
148+ )
149+
150+ expect ( decoded [ 0 ] . currencyOut ) . toEqual ( WETH9 [ 1 ] . address )
151+ expect ( decoded [ 0 ] . maxHopSlippage ) . toHaveLength ( 2 )
152+ expect ( decoded [ 0 ] . maxHopSlippage [ 0 ] . toString ( ) ) . toEqual ( '15000' )
153+ expect ( decoded [ 0 ] . maxHopSlippage [ 1 ] . toString ( ) ) . toEqual ( '25000' )
154+ expect ( decoded [ 0 ] . amountOut . toString ( ) ) . toEqual ( ONE_ETHER_BN . toString ( ) )
155+ } )
90156 } )
91157
92158 describe ( 'addTrade' , ( ) => {
0 commit comments