@@ -27,7 +27,7 @@ describe('SwapRouter', () => {
27
27
const liquidity = 1_000_000
28
28
29
29
// v3
30
- const makePool = ( token0 : Token , token1 : Token ) => {
30
+ const makePool = ( token0 : Token , token1 : Token , liquidity : number ) => {
31
31
return new Pool ( token0 , token1 , feeAmount , sqrtRatioX96 , liquidity , TickMath . getTickAtSqrtRatio ( sqrtRatioX96 ) , [
32
32
{
33
33
index : nearestUsableTick ( TickMath . MIN_TICK , TICK_SPACINGS [ feeAmount ] ) ,
@@ -50,10 +50,10 @@ describe('SwapRouter', () => {
50
50
return new Pair ( amount0 , amount1 )
51
51
}
52
52
53
- const pool_0_1 = makePool ( token0 , token1 )
53
+ const pool_0_1 = makePool ( token0 , token1 , liquidity )
54
54
const pair_0_1 = makePair ( token0 , token1 , liquidity )
55
55
56
- const pool_1_WETH = makePool ( token1 , WETH )
56
+ const pool_1_WETH = makePool ( token1 , WETH , liquidity )
57
57
const pair_1_WETH = makePair ( token1 , WETH , liquidity )
58
58
59
59
const slippageTolerance = new Percent ( 1 , 100 )
@@ -465,6 +465,60 @@ describe('SwapRouter', () => {
465
465
} )
466
466
} )
467
467
} )
468
+
469
+ describe ( 'high price impact with ETH input to result in refundETH being appended to calldata' , ( ) => {
470
+ const expectedCalldata =
471
+ '0x5ae401dc000000000000000000000000000000000000000000000000000000000000007b000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000002a000000000000000000000000000000000000000000000000000000000000000e4472b43f300000000000000000000000000000000000000000000000000000000000000640000000000000000000000000000000000000000000000000000000000000062000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e404e45aaf000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000bb8000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000640000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000412210e8a00000000000000000000000000000000000000000000000000000000'
472
+ const amountIn = CurrencyAmount . fromRawAmount ( ETHER , JSBI . BigInt ( 100 ) )
473
+ const pool_1_WETH_slippage = makePool ( token1 , WETH , 100 )
474
+ const REFUND_ETH_FUNCTION_SIG = / 1 2 2 1 0 e 8 a /
475
+
476
+ const v2Trade = V2Trade . exactIn ( new V2Route ( [ pair_1_WETH ] , ETHER , token1 ) , amountIn )
477
+ const v3Trade = V3Trade . fromRoute (
478
+ new V3Route ( [ pool_1_WETH_slippage ] , ETHER , token1 ) ,
479
+ amountIn ,
480
+ TradeType . EXACT_INPUT
481
+ )
482
+
483
+ it ( 'array of trades' , async ( ) => {
484
+ const trades = [ v2Trade , await v3Trade ]
485
+ const { calldata, value } = SwapRouter . swapCallParameters ( trades , {
486
+ slippageTolerance,
487
+ recipient,
488
+ deadlineOrPreviousBlockhash : deadline ,
489
+ } )
490
+ expect ( calldata ) . toEqual ( expectedCalldata )
491
+ expect ( calldata ) . toMatch ( REFUND_ETH_FUNCTION_SIG )
492
+ expect ( value ) . toBe ( '0xc8' )
493
+ } )
494
+ } )
495
+
496
+ describe ( 'high price impact with ERCO20 input does not result in refundETH call' , ( ) => {
497
+ const expectedCalldata =
498
+ '0x5ae401dc000000000000000000000000000000000000000000000000000000000000007b000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000000e4472b43f3000000000000000000000000000000000000000000000000000000000000006400000000000000000000000000000000000000000000000000000000000000620000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e404e45aaf0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000bb8000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000640000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
499
+ const amountIn = CurrencyAmount . fromRawAmount ( token1 , JSBI . BigInt ( 100 ) )
500
+ const pool_1_WETH_slippage = makePool ( token1 , WETH , 100 )
501
+ const REFUND_ETH_FUNCTION_SIG = / 1 2 2 1 0 e 8 a /
502
+
503
+ const v2Trade = V2Trade . exactIn ( new V2Route ( [ pair_1_WETH ] , token1 , WETH ) , amountIn )
504
+ const v3Trade = V3Trade . fromRoute (
505
+ new V3Route ( [ pool_1_WETH_slippage ] , token1 , WETH ) ,
506
+ amountIn ,
507
+ TradeType . EXACT_INPUT
508
+ )
509
+
510
+ it ( 'array of trades' , async ( ) => {
511
+ const trades = [ v2Trade , await v3Trade ]
512
+ const { calldata, value } = SwapRouter . swapCallParameters ( trades , {
513
+ slippageTolerance,
514
+ recipient,
515
+ deadlineOrPreviousBlockhash : deadline ,
516
+ } )
517
+ expect ( calldata ) . toEqual ( expectedCalldata )
518
+ expect ( calldata ) . not . toMatch ( REFUND_ETH_FUNCTION_SIG )
519
+ expect ( value ) . toBe ( '0x00' )
520
+ } )
521
+ } )
468
522
} )
469
523
470
524
describe ( 'ETH output' , ( ) => {
@@ -710,7 +764,7 @@ describe('SwapRouter', () => {
710
764
const expectedCalldata =
711
765
'0xac9650d80000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000700000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000022000000000000000000000000000000000000000000000000000000000000003800000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000048000000000000000000000000000000000000000000000000000000000000005c000000000000000000000000000000000000000000000000000000000000006400000000000000000000000000000000000000000000000000000000000000104472b43f30000000000000000000000000000000000000000000000000000000000000064000000000000000000000000000000000000000000000000000000000000006100000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000124b858183f0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000064000000000000000000000000000000000000000000000000000000000000005f00000000000000000000000000000000000000000000000000000000000000420000000000000000000000000000000000000001000bb80000000000000000000000000000000000000002000bb8c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044f2d5d56b000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000000032c7eb000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044f2d5d56b0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000032c8ad00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010411ed56c90000000000000000000000000000000000000000000000000000000000000001000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000bb8ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc4000000000000000000000000000000000000000000000000000000000000003c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044e90a182f00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044e90a182f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
712
766
713
- const pool_0_WETH = makePool ( token0 , WETH )
767
+ const pool_0_WETH = makePool ( token0 , WETH , liquidity )
714
768
const amountIn = CurrencyAmount . fromRawAmount ( token0 , JSBI . BigInt ( 100 ) )
715
769
const v2Trade = V2Trade . exactIn ( new V2Route ( [ pair_0_1 , pair_1_WETH ] , token0 , WETH ) , amountIn )
716
770
const v3Trade = V3Trade . fromRoute (
@@ -907,6 +961,7 @@ describe('SwapRouter', () => {
907
961
describe ( 'when input is native' , ( ) => {
908
962
const expectedCalldata =
909
963
'0xac9650d8000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000022000000000000000000000000000000000000000000000000000000000000002a00000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000036000000000000000000000000000000000000000000000000000000000000003c000000000000000000000000000000000000000000000000000000000000004a0000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000000000000000000000000000000000000000e404e45aaf000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000bb80000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000070000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044f2d5d56b0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000032c8a50000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000241c58db4f000000000000000000000000000000000000000000000000000000000032c8ad000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024571ac8b0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024571ac8b000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a4f100b2050000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024496169970000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044e90a182f0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
964
+
910
965
const ETH = Ether . onChain ( 1 )
911
966
const amountIn = CurrencyAmount . fromRawAmount ( ETH , JSBI . BigInt ( 10 ) )
912
967
const v3Trade = V3Trade . fromRoute ( new V3Route ( [ pool_1_WETH ] , ETH , token1 ) , amountIn , TradeType . EXACT_INPUT )
0 commit comments