@uniswap/router-sdk 2.0.0 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (176) hide show
  1. package/dist/{cjs/src/approveAndCall.d.ts → approveAndCall.d.ts} +33 -33
  2. package/dist/{types/src/constants.d.ts → constants.d.ts} +13 -13
  3. package/dist/{types/src/entities → entities}/mixedRoute/route.d.ts +29 -29
  4. package/dist/{esm/src/entities → entities}/mixedRoute/trade.d.ts +183 -183
  5. package/dist/{cjs/src/entities → entities}/protocol.d.ts +6 -6
  6. package/dist/{esm/src/entities → entities}/route.d.ts +40 -40
  7. package/dist/{esm/src/entities → entities}/trade.d.ts +127 -127
  8. package/dist/{cjs/src/index.d.ts → index.d.ts} +14 -14
  9. package/dist/index.js +8 -0
  10. package/dist/{cjs/src/multicallExtended.d.ts → multicallExtended.d.ts} +11 -11
  11. package/dist/{types/src/paymentsExtended.d.ts → paymentsExtended.d.ts} +15 -15
  12. package/dist/router-sdk.cjs.development.js +2460 -0
  13. package/dist/router-sdk.cjs.development.js.map +1 -0
  14. package/dist/router-sdk.cjs.production.min.js +2 -0
  15. package/dist/router-sdk.cjs.production.min.js.map +1 -0
  16. package/dist/router-sdk.esm.js +2427 -0
  17. package/dist/router-sdk.esm.js.map +1 -0
  18. package/dist/{cjs/src/swapRouter.d.ts → swapRouter.d.ts} +95 -95
  19. package/dist/{cjs/src/utils → utils}/TPool.d.ts +4 -4
  20. package/dist/{cjs/src/utils → utils}/encodeMixedRouteToPath.d.ts +9 -9
  21. package/dist/{types/src/utils → utils}/index.d.ts +16 -16
  22. package/dist/{cjs/src/utils → utils}/pathCurrency.d.ts +4 -4
  23. package/package.json +18 -33
  24. package/dist/cjs/src/approveAndCall.js +0 -111
  25. package/dist/cjs/src/approveAndCall.js.map +0 -1
  26. package/dist/cjs/src/constants.d.ts +0 -13
  27. package/dist/cjs/src/constants.js +0 -22
  28. package/dist/cjs/src/constants.js.map +0 -1
  29. package/dist/cjs/src/entities/mixedRoute/route.d.ts +0 -29
  30. package/dist/cjs/src/entities/mixedRoute/route.js +0 -119
  31. package/dist/cjs/src/entities/mixedRoute/route.js.map +0 -1
  32. package/dist/cjs/src/entities/mixedRoute/route.test.d.ts +0 -1
  33. package/dist/cjs/src/entities/mixedRoute/route.test.js +0 -469
  34. package/dist/cjs/src/entities/mixedRoute/route.test.js.map +0 -1
  35. package/dist/cjs/src/entities/mixedRoute/trade.d.ts +0 -183
  36. package/dist/cjs/src/entities/mixedRoute/trade.js +0 -357
  37. package/dist/cjs/src/entities/mixedRoute/trade.js.map +0 -1
  38. package/dist/cjs/src/entities/mixedRoute/trade.test.d.ts +0 -1
  39. package/dist/cjs/src/entities/mixedRoute/trade.test.js +0 -1010
  40. package/dist/cjs/src/entities/mixedRoute/trade.test.js.map +0 -1
  41. package/dist/cjs/src/entities/protocol.js +0 -11
  42. package/dist/cjs/src/entities/protocol.js.map +0 -1
  43. package/dist/cjs/src/entities/route.d.ts +0 -40
  44. package/dist/cjs/src/entities/route.js +0 -63
  45. package/dist/cjs/src/entities/route.js.map +0 -1
  46. package/dist/cjs/src/entities/route.test.d.ts +0 -1
  47. package/dist/cjs/src/entities/route.test.js +0 -192
  48. package/dist/cjs/src/entities/route.test.js.map +0 -1
  49. package/dist/cjs/src/entities/trade.d.ts +0 -127
  50. package/dist/cjs/src/entities/trade.js +0 -366
  51. package/dist/cjs/src/entities/trade.js.map +0 -1
  52. package/dist/cjs/src/entities/trade.test.d.ts +0 -1
  53. package/dist/cjs/src/entities/trade.test.js +0 -1267
  54. package/dist/cjs/src/entities/trade.test.js.map +0 -1
  55. package/dist/cjs/src/index.js +0 -18
  56. package/dist/cjs/src/index.js.map +0 -1
  57. package/dist/cjs/src/multicallExtended.js +0 -43
  58. package/dist/cjs/src/multicallExtended.js.map +0 -1
  59. package/dist/cjs/src/multicallExtended.test.d.ts +0 -1
  60. package/dist/cjs/src/multicallExtended.test.js +0 -22
  61. package/dist/cjs/src/multicallExtended.test.js.map +0 -1
  62. package/dist/cjs/src/paymentsExtended.d.ts +0 -15
  63. package/dist/cjs/src/paymentsExtended.js +0 -65
  64. package/dist/cjs/src/paymentsExtended.js.map +0 -1
  65. package/dist/cjs/src/paymentsExtended.test.d.ts +0 -1
  66. package/dist/cjs/src/paymentsExtended.test.js +0 -60
  67. package/dist/cjs/src/paymentsExtended.test.js.map +0 -1
  68. package/dist/cjs/src/swapRouter.js +0 -439
  69. package/dist/cjs/src/swapRouter.js.map +0 -1
  70. package/dist/cjs/src/swapRouter.test.d.ts +0 -1
  71. package/dist/cjs/src/swapRouter.test.js +0 -1161
  72. package/dist/cjs/src/swapRouter.test.js.map +0 -1
  73. package/dist/cjs/src/utils/TPool.js +0 -3
  74. package/dist/cjs/src/utils/TPool.js.map +0 -1
  75. package/dist/cjs/src/utils/encodeMixedRouteToPath.js +0 -90
  76. package/dist/cjs/src/utils/encodeMixedRouteToPath.js.map +0 -1
  77. package/dist/cjs/src/utils/encodeMixedRouteToPath.test.d.ts +0 -1
  78. package/dist/cjs/src/utils/encodeMixedRouteToPath.test.js +0 -136
  79. package/dist/cjs/src/utils/encodeMixedRouteToPath.test.js.map +0 -1
  80. package/dist/cjs/src/utils/index.d.ts +0 -16
  81. package/dist/cjs/src/utils/index.js +0 -51
  82. package/dist/cjs/src/utils/index.js.map +0 -1
  83. package/dist/cjs/src/utils/pathCurrency.js +0 -35
  84. package/dist/cjs/src/utils/pathCurrency.js.map +0 -1
  85. package/dist/cjs/src/utils/pathCurrency.test.d.ts +0 -1
  86. package/dist/cjs/src/utils/pathCurrency.test.js +0 -17
  87. package/dist/cjs/src/utils/pathCurrency.test.js.map +0 -1
  88. package/dist/esm/src/approveAndCall.d.ts +0 -33
  89. package/dist/esm/src/approveAndCall.js +0 -105
  90. package/dist/esm/src/approveAndCall.js.map +0 -1
  91. package/dist/esm/src/constants.d.ts +0 -13
  92. package/dist/esm/src/constants.js +0 -18
  93. package/dist/esm/src/constants.js.map +0 -1
  94. package/dist/esm/src/entities/mixedRoute/route.d.ts +0 -29
  95. package/dist/esm/src/entities/mixedRoute/route.js +0 -114
  96. package/dist/esm/src/entities/mixedRoute/route.js.map +0 -1
  97. package/dist/esm/src/entities/mixedRoute/route.test.d.ts +0 -1
  98. package/dist/esm/src/entities/mixedRoute/route.test.js +0 -467
  99. package/dist/esm/src/entities/mixedRoute/route.test.js.map +0 -1
  100. package/dist/esm/src/entities/mixedRoute/trade.js +0 -352
  101. package/dist/esm/src/entities/mixedRoute/trade.js.map +0 -1
  102. package/dist/esm/src/entities/mixedRoute/trade.test.d.ts +0 -1
  103. package/dist/esm/src/entities/mixedRoute/trade.test.js +0 -1008
  104. package/dist/esm/src/entities/mixedRoute/trade.test.js.map +0 -1
  105. package/dist/esm/src/entities/protocol.d.ts +0 -6
  106. package/dist/esm/src/entities/protocol.js +0 -8
  107. package/dist/esm/src/entities/protocol.js.map +0 -1
  108. package/dist/esm/src/entities/route.js +0 -55
  109. package/dist/esm/src/entities/route.js.map +0 -1
  110. package/dist/esm/src/entities/route.test.d.ts +0 -1
  111. package/dist/esm/src/entities/route.test.js +0 -190
  112. package/dist/esm/src/entities/route.test.js.map +0 -1
  113. package/dist/esm/src/entities/trade.js +0 -362
  114. package/dist/esm/src/entities/trade.js.map +0 -1
  115. package/dist/esm/src/entities/trade.test.d.ts +0 -1
  116. package/dist/esm/src/entities/trade.test.js +0 -1265
  117. package/dist/esm/src/entities/trade.test.js.map +0 -1
  118. package/dist/esm/src/index.d.ts +0 -14
  119. package/dist/esm/src/index.js +0 -15
  120. package/dist/esm/src/index.js.map +0 -1
  121. package/dist/esm/src/multicallExtended.d.ts +0 -11
  122. package/dist/esm/src/multicallExtended.js +0 -39
  123. package/dist/esm/src/multicallExtended.js.map +0 -1
  124. package/dist/esm/src/multicallExtended.test.d.ts +0 -1
  125. package/dist/esm/src/multicallExtended.test.js +0 -20
  126. package/dist/esm/src/multicallExtended.test.js.map +0 -1
  127. package/dist/esm/src/paymentsExtended.d.ts +0 -15
  128. package/dist/esm/src/paymentsExtended.js +0 -61
  129. package/dist/esm/src/paymentsExtended.js.map +0 -1
  130. package/dist/esm/src/paymentsExtended.test.d.ts +0 -1
  131. package/dist/esm/src/paymentsExtended.test.js +0 -57
  132. package/dist/esm/src/paymentsExtended.test.js.map +0 -1
  133. package/dist/esm/src/swapRouter.d.ts +0 -95
  134. package/dist/esm/src/swapRouter.js +0 -434
  135. package/dist/esm/src/swapRouter.js.map +0 -1
  136. package/dist/esm/src/swapRouter.test.d.ts +0 -1
  137. package/dist/esm/src/swapRouter.test.js +0 -1159
  138. package/dist/esm/src/swapRouter.test.js.map +0 -1
  139. package/dist/esm/src/utils/TPool.d.ts +0 -4
  140. package/dist/esm/src/utils/TPool.js +0 -2
  141. package/dist/esm/src/utils/TPool.js.map +0 -1
  142. package/dist/esm/src/utils/encodeMixedRouteToPath.d.ts +0 -9
  143. package/dist/esm/src/utils/encodeMixedRouteToPath.js +0 -86
  144. package/dist/esm/src/utils/encodeMixedRouteToPath.js.map +0 -1
  145. package/dist/esm/src/utils/encodeMixedRouteToPath.test.d.ts +0 -1
  146. package/dist/esm/src/utils/encodeMixedRouteToPath.test.js +0 -134
  147. package/dist/esm/src/utils/encodeMixedRouteToPath.test.js.map +0 -1
  148. package/dist/esm/src/utils/index.d.ts +0 -16
  149. package/dist/esm/src/utils/index.js +0 -46
  150. package/dist/esm/src/utils/index.js.map +0 -1
  151. package/dist/esm/src/utils/pathCurrency.d.ts +0 -4
  152. package/dist/esm/src/utils/pathCurrency.js +0 -30
  153. package/dist/esm/src/utils/pathCurrency.js.map +0 -1
  154. package/dist/esm/src/utils/pathCurrency.test.d.ts +0 -1
  155. package/dist/esm/src/utils/pathCurrency.test.js +0 -15
  156. package/dist/esm/src/utils/pathCurrency.test.js.map +0 -1
  157. package/dist/types/src/approveAndCall.d.ts +0 -33
  158. package/dist/types/src/entities/mixedRoute/route.test.d.ts +0 -1
  159. package/dist/types/src/entities/mixedRoute/trade.d.ts +0 -183
  160. package/dist/types/src/entities/mixedRoute/trade.test.d.ts +0 -1
  161. package/dist/types/src/entities/protocol.d.ts +0 -6
  162. package/dist/types/src/entities/route.d.ts +0 -40
  163. package/dist/types/src/entities/route.test.d.ts +0 -1
  164. package/dist/types/src/entities/trade.d.ts +0 -127
  165. package/dist/types/src/entities/trade.test.d.ts +0 -1
  166. package/dist/types/src/index.d.ts +0 -14
  167. package/dist/types/src/multicallExtended.d.ts +0 -11
  168. package/dist/types/src/multicallExtended.test.d.ts +0 -1
  169. package/dist/types/src/paymentsExtended.test.d.ts +0 -1
  170. package/dist/types/src/swapRouter.d.ts +0 -95
  171. package/dist/types/src/swapRouter.test.d.ts +0 -1
  172. package/dist/types/src/utils/TPool.d.ts +0 -4
  173. package/dist/types/src/utils/encodeMixedRouteToPath.d.ts +0 -9
  174. package/dist/types/src/utils/encodeMixedRouteToPath.test.d.ts +0 -1
  175. package/dist/types/src/utils/pathCurrency.d.ts +0 -4
  176. package/dist/types/src/utils/pathCurrency.test.d.ts +0 -1
@@ -1,1159 +0,0 @@
1
- import { __awaiter } from "tslib";
2
- import { CurrencyAmount, Ether, Percent, Token, TradeType, WETH9 } from '@uniswap/sdk-core';
3
- import { Pair, Route as V2Route, Trade as V2Trade } from '@uniswap/v2-sdk';
4
- import { encodeSqrtRatioX96, FeeAmount, nearestUsableTick, Pool, Position, Route as V3Route, TickMath, TICK_SPACINGS, Trade as V3Trade, } from '@uniswap/v3-sdk';
5
- import { Pool as V4Pool } from '@uniswap/v4-sdk';
6
- import JSBI from 'jsbi';
7
- import { SwapRouter, Trade } from '.';
8
- import { ApprovalTypes } from './approveAndCall';
9
- import { MixedRouteSDK } from './entities/mixedRoute/route';
10
- import { MixedRouteTrade } from './entities/mixedRoute/trade';
11
- import { ADDRESS_ZERO } from './constants';
12
- describe('SwapRouter', () => {
13
- const ETHER = Ether.onChain(1);
14
- const WETH = WETH9[1];
15
- const token0 = new Token(1, '0x0000000000000000000000000000000000000001', 18, 't0', 'token0');
16
- const token1 = new Token(1, '0x0000000000000000000000000000000000000002', 18, 't1', 'token1');
17
- const token2 = new Token(1, '0x0000000000000000000000000000000000000003', 18, 't2', 'token2');
18
- const feeAmount = FeeAmount.MEDIUM;
19
- const sqrtRatioX96 = encodeSqrtRatioX96(1, 1);
20
- const liquidity = 1000000;
21
- // v4
22
- const makeV4Pool = (token0, token1, liquidity) => {
23
- return new V4Pool(token0, token1, feeAmount, TICK_SPACINGS[feeAmount], ADDRESS_ZERO, sqrtRatioX96, liquidity, TickMath.getTickAtSqrtRatio(sqrtRatioX96), [
24
- {
25
- index: nearestUsableTick(TickMath.MIN_TICK, TICK_SPACINGS[feeAmount]),
26
- liquidityNet: liquidity,
27
- liquidityGross: liquidity,
28
- },
29
- {
30
- index: nearestUsableTick(TickMath.MAX_TICK, TICK_SPACINGS[feeAmount]),
31
- liquidityNet: -liquidity,
32
- liquidityGross: liquidity,
33
- },
34
- ]);
35
- };
36
- // v3
37
- const makeV3Pool = (token0, token1, liquidity) => {
38
- return new Pool(token0, token1, feeAmount, sqrtRatioX96, liquidity, TickMath.getTickAtSqrtRatio(sqrtRatioX96), [
39
- {
40
- index: nearestUsableTick(TickMath.MIN_TICK, TICK_SPACINGS[feeAmount]),
41
- liquidityNet: liquidity,
42
- liquidityGross: liquidity,
43
- },
44
- {
45
- index: nearestUsableTick(TickMath.MAX_TICK, TICK_SPACINGS[feeAmount]),
46
- liquidityNet: -liquidity,
47
- liquidityGross: liquidity,
48
- },
49
- ]);
50
- };
51
- // v2
52
- const makePair = (token0, token1, liquidity) => {
53
- const amount0 = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(liquidity));
54
- const amount1 = CurrencyAmount.fromRawAmount(token1, JSBI.BigInt(liquidity));
55
- return new Pair(amount0, amount1);
56
- };
57
- const pool_V3_0_1 = makeV3Pool(token0, token1, liquidity);
58
- const pool_V4_0_1 = makeV4Pool(token0, token1, liquidity);
59
- const pair_0_1 = makePair(token0, token1, liquidity);
60
- const pair_1_2 = makePair(token1, token2, liquidity);
61
- const pool_V3_1_WETH = makeV3Pool(token1, WETH, liquidity);
62
- const pair_1_WETH = makePair(token1, WETH, liquidity);
63
- const pair_2_WETH = makePair(token2, WETH, liquidity);
64
- const pool_V3_2_WETH = makeV3Pool(token2, WETH, liquidity);
65
- const slippageTolerance = new Percent(1, 100);
66
- const recipient = '0x0000000000000000000000000000000000000003';
67
- const deadline = 123;
68
- describe('#swapCallParameters', () => {
69
- describe('single-hop exact input (v2 + v3)', () => {
70
- describe('different trade configurations result in identical calldata', () => {
71
- const expectedCalldata = '0x5ae401dc000000000000000000000000000000000000000000000000000000000000007b000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000000e4472b43f300000000000000000000000000000000000000000000000000000000000000640000000000000000000000000000000000000000000000000000000000000062000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e404e45aaf000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000bb8000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000640000000000000000000000000000000000000000000000000000000000000061000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';
72
- const amountIn = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100));
73
- const v2Trade = V2Trade.exactIn(new V2Route([pair_0_1], token0, token1), amountIn);
74
- const v3Trade = V3Trade.fromRoute(new V3Route([pool_V3_0_1], token0, token1), amountIn, TradeType.EXACT_INPUT);
75
- it('array of trades', () => __awaiter(void 0, void 0, void 0, function* () {
76
- const trades = [v2Trade, yield v3Trade];
77
- const { calldata, value } = SwapRouter.swapCallParameters(trades, {
78
- slippageTolerance,
79
- recipient,
80
- deadlineOrPreviousBlockhash: deadline,
81
- });
82
- expect(calldata).toEqual(expectedCalldata);
83
- expect(value).toBe('0x00');
84
- }));
85
- it('meta-trade', () => __awaiter(void 0, void 0, void 0, function* () {
86
- const trades = yield Trade.fromRoutes([
87
- {
88
- routev2: v2Trade.route,
89
- amount: amountIn,
90
- },
91
- ], [
92
- {
93
- routev3: (yield v3Trade).swaps[0].route,
94
- amount: amountIn,
95
- },
96
- ], TradeType.EXACT_INPUT);
97
- const { calldata, value } = SwapRouter.swapCallParameters(trades, {
98
- slippageTolerance,
99
- recipient,
100
- deadlineOrPreviousBlockhash: deadline,
101
- });
102
- expect(calldata).toEqual(expectedCalldata);
103
- expect(value).toBe('0x00');
104
- }));
105
- });
106
- });
107
- describe('single-hop exact output (v2 + v3)', () => {
108
- describe('different trade configurations result in identical calldata', () => {
109
- const expectedCalldata = '0x5ae401dc000000000000000000000000000000000000000000000000000000000000007b000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000000e442712a6700000000000000000000000000000000000000000000000000000000000000640000000000000000000000000000000000000000000000000000000000000066000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e45023b4df000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000bb8000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000640000000000000000000000000000000000000000000000000000000000000067000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';
110
- const amountOut = CurrencyAmount.fromRawAmount(token1, JSBI.BigInt(100));
111
- const v2Trade = V2Trade.exactOut(new V2Route([pair_0_1], token0, token1), amountOut);
112
- const v3Trade = V3Trade.fromRoute(new V3Route([pool_V3_0_1], token0, token1), amountOut, TradeType.EXACT_OUTPUT);
113
- it('array of trades', () => __awaiter(void 0, void 0, void 0, function* () {
114
- const trades = [v2Trade, yield v3Trade];
115
- const { calldata, value } = SwapRouter.swapCallParameters(trades, {
116
- slippageTolerance,
117
- recipient,
118
- deadlineOrPreviousBlockhash: deadline,
119
- });
120
- expect(calldata).toEqual(expectedCalldata);
121
- expect(value).toBe('0x00');
122
- }));
123
- it('meta-trade', () => __awaiter(void 0, void 0, void 0, function* () {
124
- const trades = yield Trade.fromRoutes([
125
- {
126
- routev2: v2Trade.route,
127
- amount: amountOut,
128
- },
129
- ], [
130
- {
131
- routev3: (yield v3Trade).swaps[0].route,
132
- amount: amountOut,
133
- },
134
- ], TradeType.EXACT_OUTPUT);
135
- const { calldata, value } = SwapRouter.swapCallParameters(trades, {
136
- slippageTolerance,
137
- recipient,
138
- deadlineOrPreviousBlockhash: deadline,
139
- });
140
- expect(calldata).toEqual(expectedCalldata);
141
- expect(value).toBe('0x00');
142
- }));
143
- });
144
- });
145
- describe('multi-hop exact input (v2 + v3)', () => {
146
- describe('different trade configurations result in identical calldata', () => {
147
- const expectedCalldata = '0x5ae401dc000000000000000000000000000000000000000000000000000000000000007b00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000001800000000000000000000000000000000000000000000000000000000000000104472b43f30000000000000000000000000000000000000000000000000000000000000064000000000000000000000000000000000000000000000000000000000000006100000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000124b858183f0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000064000000000000000000000000000000000000000000000000000000000000005f00000000000000000000000000000000000000000000000000000000000000420000000000000000000000000000000000000001000bb80000000000000000000000000000000000000002000bb8c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';
148
- const amountIn = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100));
149
- const v2Trade = V2Trade.exactIn(new V2Route([pair_0_1, pair_1_WETH], token0, WETH), amountIn);
150
- const v3Trade = V3Trade.fromRoute(new V3Route([pool_V3_0_1, pool_V3_1_WETH], token0, WETH), amountIn, TradeType.EXACT_INPUT);
151
- it('array of trades', () => __awaiter(void 0, void 0, void 0, function* () {
152
- const trades = [v2Trade, yield v3Trade];
153
- const { calldata, value } = SwapRouter.swapCallParameters(trades, {
154
- slippageTolerance,
155
- recipient,
156
- deadlineOrPreviousBlockhash: deadline,
157
- });
158
- expect(calldata).toEqual(expectedCalldata);
159
- expect(value).toBe('0x00');
160
- }));
161
- it('meta-trade', () => __awaiter(void 0, void 0, void 0, function* () {
162
- const trades = yield Trade.fromRoutes([
163
- {
164
- routev2: v2Trade.route,
165
- amount: amountIn,
166
- },
167
- ], [
168
- {
169
- routev3: (yield v3Trade).swaps[0].route,
170
- amount: amountIn,
171
- },
172
- ], TradeType.EXACT_INPUT);
173
- const { calldata, value } = SwapRouter.swapCallParameters(trades, {
174
- slippageTolerance,
175
- recipient,
176
- deadlineOrPreviousBlockhash: deadline,
177
- });
178
- expect(calldata).toEqual(expectedCalldata);
179
- expect(value).toBe('0x00');
180
- }));
181
- });
182
- });
183
- describe('multi-hop exact output (v2 + v3)', () => {
184
- describe('different trade configurations result in identical calldata', () => {
185
- const expectedCalldata = '0x5ae401dc000000000000000000000000000000000000000000000000000000000000007b0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000180000000000000000000000000000000000000000000000000000000000000010442712a670000000000000000000000000000000000000000000000000000000000000064000000000000000000000000000000000000000000000000000000000000006700000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000012409b81346000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006400000000000000000000000000000000000000000000000000000000000000690000000000000000000000000000000000000000000000000000000000000042c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000bb80000000000000000000000000000000000000002000bb8000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';
186
- const amountOut = CurrencyAmount.fromRawAmount(WETH, JSBI.BigInt(100));
187
- const v2Trade = V2Trade.exactOut(new V2Route([pair_0_1, pair_1_WETH], token0, WETH), amountOut);
188
- const v3Trade = V3Trade.fromRoute(new V3Route([pool_V3_0_1, pool_V3_1_WETH], token0, WETH), amountOut, TradeType.EXACT_OUTPUT);
189
- it('array of trades', () => __awaiter(void 0, void 0, void 0, function* () {
190
- const trades = [v2Trade, yield v3Trade];
191
- const { calldata, value } = SwapRouter.swapCallParameters(trades, {
192
- slippageTolerance,
193
- recipient,
194
- deadlineOrPreviousBlockhash: deadline,
195
- });
196
- expect(calldata).toEqual(expectedCalldata);
197
- expect(value).toBe('0x00');
198
- }));
199
- it('meta-trade', () => __awaiter(void 0, void 0, void 0, function* () {
200
- const trades = yield Trade.fromRoutes([
201
- {
202
- routev2: v2Trade.route,
203
- amount: amountOut,
204
- },
205
- ], [
206
- {
207
- routev3: (yield v3Trade).swaps[0].route,
208
- amount: amountOut,
209
- },
210
- ], TradeType.EXACT_OUTPUT);
211
- const { calldata, value } = SwapRouter.swapCallParameters(trades, {
212
- slippageTolerance,
213
- recipient,
214
- deadlineOrPreviousBlockhash: deadline,
215
- });
216
- expect(calldata).toEqual(expectedCalldata);
217
- expect(value).toBe('0x00');
218
- }));
219
- });
220
- });
221
- describe('Mixed Route', () => {
222
- it('throws an error with v4 pool', () => __awaiter(void 0, void 0, void 0, function* () {
223
- const amountIn = CurrencyAmount.fromRawAmount(WETH, JSBI.BigInt(100));
224
- const mixedRouteTrade = MixedRouteTrade.fromRoute(new MixedRouteSDK([pair_1_WETH, pool_V4_0_1], WETH, token0), amountIn, TradeType.EXACT_INPUT);
225
- const trades = yield mixedRouteTrade;
226
- expect(() => SwapRouter.swapCallParameters(trades, {
227
- slippageTolerance,
228
- recipient,
229
- deadlineOrPreviousBlockhash: deadline,
230
- })).toThrow('Encoding mixed routes with V4 not supported');
231
- }));
232
- describe('single-hop exact input (v2 + v3) backwards compatible', () => {
233
- describe('different trade configurations result in identical calldata', () => {
234
- const expectedCalldata = '0x5ae401dc000000000000000000000000000000000000000000000000000000000000007b000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000000e4472b43f300000000000000000000000000000000000000000000000000000000000000640000000000000000000000000000000000000000000000000000000000000062000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e404e45aaf000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000bb8000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000640000000000000000000000000000000000000000000000000000000000000061000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';
235
- const amountIn = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100));
236
- const v2Trade = V2Trade.exactIn(new V2Route([pair_0_1], token0, token1), amountIn);
237
- const v3Trade = V3Trade.fromRoute(new V3Route([pool_V3_0_1], token0, token1), amountIn, TradeType.EXACT_INPUT);
238
- const mixedRouteTrade1 = MixedRouteTrade.fromRoute(new MixedRouteSDK([pair_0_1], token0, token1), amountIn, TradeType.EXACT_INPUT);
239
- const mixedRouteTrade2 = MixedRouteTrade.fromRoute(new MixedRouteSDK([pool_V3_0_1], token0, token1), amountIn, TradeType.EXACT_INPUT);
240
- it('generates the same calldata', () => __awaiter(void 0, void 0, void 0, function* () {
241
- const trades = [v2Trade, yield v3Trade];
242
- const { calldata, value } = SwapRouter.swapCallParameters(trades, {
243
- slippageTolerance,
244
- recipient,
245
- deadlineOrPreviousBlockhash: deadline,
246
- });
247
- expect(calldata).toEqual(expectedCalldata);
248
- expect(value).toBe('0x00');
249
- const mixedRouteTrades = [yield mixedRouteTrade1, yield mixedRouteTrade2];
250
- const { calldata: mixedRouteCalldata, value: mixedRouteValue } = SwapRouter.swapCallParameters(mixedRouteTrades, {
251
- slippageTolerance,
252
- recipient,
253
- deadlineOrPreviousBlockhash: deadline,
254
- });
255
- expect(mixedRouteCalldata).toEqual(expectedCalldata);
256
- expect(mixedRouteValue).toBe('0x00');
257
- }));
258
- it('meta-trade', () => __awaiter(void 0, void 0, void 0, function* () {
259
- const trades = yield Trade.fromRoutes([
260
- {
261
- routev2: v2Trade.route,
262
- amount: amountIn,
263
- },
264
- ], [
265
- {
266
- routev3: (yield v3Trade).swaps[0].route,
267
- amount: amountIn,
268
- },
269
- ], TradeType.EXACT_INPUT);
270
- const { calldata, value } = SwapRouter.swapCallParameters(trades, {
271
- slippageTolerance,
272
- recipient,
273
- deadlineOrPreviousBlockhash: deadline,
274
- });
275
- expect(calldata).toEqual(expectedCalldata);
276
- expect(value).toBe('0x00');
277
- const mixedRouteTrades = yield Trade.fromRoutes([], [], TradeType.EXACT_INPUT, [
278
- {
279
- mixedRoute: (yield mixedRouteTrade1).swaps[0].route,
280
- amount: amountIn,
281
- },
282
- {
283
- mixedRoute: (yield mixedRouteTrade2).swaps[0].route,
284
- amount: amountIn,
285
- },
286
- ]);
287
- const { calldata: mixedRouteCalldata, value: mixedRouteValue } = SwapRouter.swapCallParameters(mixedRouteTrades, {
288
- slippageTolerance,
289
- recipient,
290
- deadlineOrPreviousBlockhash: deadline,
291
- });
292
- expect(mixedRouteCalldata).toEqual(expectedCalldata);
293
- expect(mixedRouteValue).toBe('0x00');
294
- }));
295
- });
296
- });
297
- describe('multi-hop exact input (mixed route) backwards compatible', () => {
298
- describe('different trade configurations result in identical calldata', () => {
299
- /// calldata verified and taken from existing test
300
- const expectedCalldata = '0x5ae401dc000000000000000000000000000000000000000000000000000000000000007b00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000001800000000000000000000000000000000000000000000000000000000000000104472b43f30000000000000000000000000000000000000000000000000000000000000064000000000000000000000000000000000000000000000000000000000000006100000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000124b858183f0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000064000000000000000000000000000000000000000000000000000000000000005f00000000000000000000000000000000000000000000000000000000000000420000000000000000000000000000000000000001000bb80000000000000000000000000000000000000002000bb8c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';
301
- const amountIn = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100));
302
- const mixedRouteTrade1 = MixedRouteTrade.fromRoute(new MixedRouteSDK([pair_0_1, pair_1_WETH], token0, WETH), amountIn, TradeType.EXACT_INPUT);
303
- const mixedRouteTrade2 = MixedRouteTrade.fromRoute(new MixedRouteSDK([pool_V3_0_1, pool_V3_1_WETH], token0, WETH), amountIn, TradeType.EXACT_INPUT);
304
- it('single mixedRoute trade', () => __awaiter(void 0, void 0, void 0, function* () {
305
- const trades = [yield mixedRouteTrade1, yield mixedRouteTrade2];
306
- const { calldata, value } = SwapRouter.swapCallParameters(trades, {
307
- slippageTolerance,
308
- recipient,
309
- deadlineOrPreviousBlockhash: deadline,
310
- });
311
- expect(calldata).toEqual(expectedCalldata);
312
- expect(value).toBe('0x00');
313
- }));
314
- it('meta-trade', () => __awaiter(void 0, void 0, void 0, function* () {
315
- const trades = yield Trade.fromRoutes([], [], TradeType.EXACT_INPUT, [
316
- {
317
- mixedRoute: (yield mixedRouteTrade1).swaps[0].route,
318
- amount: amountIn,
319
- },
320
- {
321
- mixedRoute: (yield mixedRouteTrade2).swaps[0].route,
322
- amount: amountIn,
323
- },
324
- ]);
325
- const { calldata, value } = SwapRouter.swapCallParameters(trades, {
326
- slippageTolerance,
327
- recipient,
328
- deadlineOrPreviousBlockhash: deadline,
329
- });
330
- expect(calldata).toEqual(expectedCalldata);
331
- expect(value).toBe('0x00');
332
- }));
333
- });
334
- });
335
- describe('mixed route trades with routes with consecutive pools/pairs', () => {
336
- /// manually verified calldata
337
- const expectedCalldata = '0x5ae401dc000000000000000000000000000000000000000000000000000000000000007b00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000001e0000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000004400000000000000000000000000000000000000000000000000000000000000124b858183f0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000064000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000420000000000000000000000000000000000000001000bb80000000000000000000000000000000000000002000bb8c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e4472b43f30000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005e000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000104472b43f300000000000000000000000000000000000000000000000000000000000000640000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000104b858183f0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005f000000000000000000000000000000000000000000000000000000000000002b0000000000000000000000000000000000000003000bb8c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';
338
- const amountIn = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100));
339
- const mixedRouteTrade1 = MixedRouteTrade.fromRoute(new MixedRouteSDK([pool_V3_0_1, pool_V3_1_WETH, pair_2_WETH], token0, WETH), amountIn, TradeType.EXACT_INPUT);
340
- const mixedRouteTrade2 = MixedRouteTrade.fromRoute(new MixedRouteSDK([pair_0_1, pair_1_2, pool_V3_2_WETH], token0, WETH), amountIn, TradeType.EXACT_INPUT);
341
- it('generates correct calldata', () => __awaiter(void 0, void 0, void 0, function* () {
342
- const trades = [yield mixedRouteTrade1, yield mixedRouteTrade2];
343
- const { calldata, value } = SwapRouter.swapCallParameters(trades, {
344
- slippageTolerance,
345
- recipient,
346
- deadlineOrPreviousBlockhash: deadline,
347
- });
348
- expect(calldata).toEqual(expectedCalldata);
349
- expect(value).toBe('0x00');
350
- }));
351
- });
352
- });
353
- describe('ETH input', () => {
354
- describe('single-hop exact input (v2 + v3)', () => {
355
- describe('different trade configurations result in identical calldata', () => {
356
- const expectedCalldata = '0x5ae401dc000000000000000000000000000000000000000000000000000000000000007b000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000000e4472b43f300000000000000000000000000000000000000000000000000000000000000640000000000000000000000000000000000000000000000000000000000000062000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e404e45aaf000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000bb8000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000640000000000000000000000000000000000000000000000000000000000000061000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';
357
- const amountIn = CurrencyAmount.fromRawAmount(ETHER, JSBI.BigInt(100));
358
- const v2Trade = V2Trade.exactIn(new V2Route([pair_1_WETH], ETHER, token1), amountIn);
359
- const v3Trade = V3Trade.fromRoute(new V3Route([pool_V3_1_WETH], ETHER, token1), amountIn, TradeType.EXACT_INPUT);
360
- /// mixedRouteTrade mirrors the V3Trade
361
- const mixedRouteTrade = MixedRouteTrade.fromRoute(new MixedRouteSDK([pool_V3_1_WETH], ETHER, token1), amountIn, TradeType.EXACT_INPUT);
362
- it('array of trades', () => __awaiter(void 0, void 0, void 0, function* () {
363
- const trades = [v2Trade, yield v3Trade];
364
- const { calldata, value } = SwapRouter.swapCallParameters(trades, {
365
- slippageTolerance,
366
- recipient,
367
- deadlineOrPreviousBlockhash: deadline,
368
- });
369
- expect(calldata).toEqual(expectedCalldata);
370
- expect(value).toBe('0xc8');
371
- }));
372
- it('mixedRoute produces the same calldata when swapped in', () => __awaiter(void 0, void 0, void 0, function* () {
373
- const trades = [v2Trade, yield mixedRouteTrade];
374
- const { calldata, value } = SwapRouter.swapCallParameters(trades, {
375
- slippageTolerance,
376
- recipient,
377
- deadlineOrPreviousBlockhash: deadline,
378
- });
379
- expect(calldata).toEqual(expectedCalldata);
380
- expect(value).toBe('0xc8');
381
- }));
382
- it('meta-trade', () => __awaiter(void 0, void 0, void 0, function* () {
383
- const trades = yield Trade.fromRoutes([
384
- {
385
- routev2: v2Trade.route,
386
- amount: amountIn,
387
- },
388
- ], [
389
- {
390
- routev3: (yield v3Trade).swaps[0].route,
391
- amount: amountIn,
392
- },
393
- ], TradeType.EXACT_INPUT);
394
- const { calldata, value } = SwapRouter.swapCallParameters(trades, {
395
- slippageTolerance,
396
- recipient,
397
- deadlineOrPreviousBlockhash: deadline,
398
- });
399
- expect(calldata).toEqual(expectedCalldata);
400
- expect(value).toBe('0xc8');
401
- }));
402
- it('meta-trade with mixedRoute', () => __awaiter(void 0, void 0, void 0, function* () {
403
- const trades = yield Trade.fromRoutes([
404
- {
405
- routev2: v2Trade.route,
406
- amount: amountIn,
407
- },
408
- ], [], TradeType.EXACT_INPUT, [
409
- {
410
- mixedRoute: (yield mixedRouteTrade).swaps[0].route,
411
- amount: amountIn,
412
- },
413
- ]);
414
- const { calldata, value } = SwapRouter.swapCallParameters(trades, {
415
- slippageTolerance,
416
- recipient,
417
- deadlineOrPreviousBlockhash: deadline,
418
- });
419
- expect(calldata).toEqual(expectedCalldata);
420
- expect(value).toBe('0xc8');
421
- }));
422
- });
423
- });
424
- describe('single-hop exact output (v2 + v3)', () => {
425
- describe('different trade configurations result in identical calldata', () => {
426
- const expectedCalldata = '0x5ae401dc000000000000000000000000000000000000000000000000000000000000007b000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000002a000000000000000000000000000000000000000000000000000000000000000e442712a6700000000000000000000000000000000000000000000000000000000000000640000000000000000000000000000000000000000000000000000000000000066000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e45023b4df000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000bb8000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000640000000000000000000000000000000000000000000000000000000000000067000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000412210e8a00000000000000000000000000000000000000000000000000000000';
427
- const amountOut = CurrencyAmount.fromRawAmount(token1, JSBI.BigInt(100));
428
- const v2Trade = V2Trade.exactOut(new V2Route([pair_1_WETH], ETHER, token1), amountOut);
429
- const v3Trade = V3Trade.fromRoute(new V3Route([pool_V3_1_WETH], ETHER, token1), amountOut, TradeType.EXACT_OUTPUT);
430
- it('array of trades', () => __awaiter(void 0, void 0, void 0, function* () {
431
- const trades = [v2Trade, yield v3Trade];
432
- const { calldata, value } = SwapRouter.swapCallParameters(trades, {
433
- slippageTolerance,
434
- recipient,
435
- deadlineOrPreviousBlockhash: deadline,
436
- });
437
- expect(calldata).toEqual(expectedCalldata);
438
- expect(value).toBe('0xcd');
439
- }));
440
- it('meta-trade', () => __awaiter(void 0, void 0, void 0, function* () {
441
- const trades = yield Trade.fromRoutes([
442
- {
443
- routev2: v2Trade.route,
444
- amount: amountOut,
445
- },
446
- ], [
447
- {
448
- routev3: (yield v3Trade).swaps[0].route,
449
- amount: amountOut,
450
- },
451
- ], TradeType.EXACT_OUTPUT);
452
- const { calldata, value } = SwapRouter.swapCallParameters(trades, {
453
- slippageTolerance,
454
- recipient,
455
- deadlineOrPreviousBlockhash: deadline,
456
- });
457
- expect(calldata).toEqual(expectedCalldata);
458
- expect(value).toBe('0xcd');
459
- }));
460
- });
461
- });
462
- describe('multi-hop exact input (v2 + v3)', () => {
463
- describe('different trade configurations result in identical calldata', () => {
464
- const expectedCalldata = '0x5ae401dc000000000000000000000000000000000000000000000000000000000000007b00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000001800000000000000000000000000000000000000000000000000000000000000104472b43f300000000000000000000000000000000000000000000000000000000000000640000000000000000000000000000000000000000000000000000000000000061000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000003000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000124b858183f0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000064000000000000000000000000000000000000000000000000000000000000005f0000000000000000000000000000000000000000000000000000000000000042c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000bb80000000000000000000000000000000000000002000bb8000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';
465
- const amountIn = CurrencyAmount.fromRawAmount(ETHER, JSBI.BigInt(100));
466
- const v2Trade = V2Trade.exactIn(new V2Route([pair_1_WETH, pair_0_1], ETHER, token0), amountIn);
467
- /// mixedRouteTrade mirrors V2Trade
468
- const mixedRouteTrade = MixedRouteTrade.fromRoute(new MixedRouteSDK([pair_1_WETH, pair_0_1], ETHER, token0), amountIn, TradeType.EXACT_INPUT);
469
- const v3Trade = V3Trade.fromRoute(new V3Route([pool_V3_1_WETH, pool_V3_0_1], ETHER, token0), amountIn, TradeType.EXACT_INPUT);
470
- it('array of trades', () => __awaiter(void 0, void 0, void 0, function* () {
471
- const trades = [v2Trade, yield v3Trade];
472
- const { calldata, value } = SwapRouter.swapCallParameters(trades, {
473
- slippageTolerance,
474
- recipient,
475
- deadlineOrPreviousBlockhash: deadline,
476
- });
477
- expect(calldata).toEqual(expectedCalldata);
478
- expect(value).toBe('0xc8');
479
- }));
480
- it('mixedRoutes in array produce same calldata', () => __awaiter(void 0, void 0, void 0, function* () {
481
- const trades = [yield mixedRouteTrade, yield v3Trade];
482
- const { calldata, value } = SwapRouter.swapCallParameters(trades, {
483
- slippageTolerance,
484
- recipient,
485
- deadlineOrPreviousBlockhash: deadline,
486
- });
487
- expect(calldata).toEqual(expectedCalldata);
488
- expect(value).toBe('0xc8');
489
- }));
490
- it('meta-trade', () => __awaiter(void 0, void 0, void 0, function* () {
491
- const trades = yield Trade.fromRoutes([
492
- {
493
- routev2: v2Trade.route,
494
- amount: amountIn,
495
- },
496
- ], [
497
- {
498
- routev3: (yield v3Trade).swaps[0].route,
499
- amount: amountIn,
500
- },
501
- ], TradeType.EXACT_INPUT);
502
- const { calldata, value } = SwapRouter.swapCallParameters(trades, {
503
- slippageTolerance,
504
- recipient,
505
- deadlineOrPreviousBlockhash: deadline,
506
- });
507
- expect(calldata).toEqual(expectedCalldata);
508
- expect(value).toBe('0xc8');
509
- }));
510
- it('meta-trade with mixedRoutes produces calldata in different order but same content', () => __awaiter(void 0, void 0, void 0, function* () {
511
- /// @dev since we order the calldata in the array in a particular way (v2, v3, mixedRoute) the ordering will be different, but the encoded swap data will be the same
512
- /// Additionally, since we aren't sharing balances across trades order should not matter
513
- const expectedCalldata = '0x5ae401dc000000000000000000000000000000000000000000000000000000000000007b00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000001a00000000000000000000000000000000000000000000000000000000000000124b858183f0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000064000000000000000000000000000000000000000000000000000000000000005f0000000000000000000000000000000000000000000000000000000000000042c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000bb80000000000000000000000000000000000000002000bb80000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000104472b43f300000000000000000000000000000000000000000000000000000000000000640000000000000000000000000000000000000000000000000000000000000061000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000003000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000';
514
- const trades = yield Trade.fromRoutes([], [
515
- {
516
- routev3: (yield v3Trade).swaps[0].route,
517
- amount: amountIn,
518
- },
519
- ], TradeType.EXACT_INPUT, [
520
- {
521
- mixedRoute: (yield mixedRouteTrade).swaps[0].route,
522
- amount: amountIn,
523
- },
524
- ]);
525
- const { calldata, value } = SwapRouter.swapCallParameters(trades, {
526
- slippageTolerance,
527
- recipient,
528
- deadlineOrPreviousBlockhash: deadline,
529
- });
530
- expect(calldata).toEqual(expectedCalldata);
531
- expect(value).toBe('0xc8');
532
- }));
533
- });
534
- });
535
- describe('multi-hop exact output (v2 + v3)', () => {
536
- describe('different trade configurations result in identical calldata', () => {
537
- const expectedCalldata = '0x5ae401dc000000000000000000000000000000000000000000000000000000000000007b00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001a00000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000010442712a6700000000000000000000000000000000000000000000000000000000000000640000000000000000000000000000000000000000000000000000000000000067000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000003000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000012409b813460000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000064000000000000000000000000000000000000000000000000000000000000006900000000000000000000000000000000000000000000000000000000000000420000000000000000000000000000000000000001000bb80000000000000000000000000000000000000002000bb8c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000412210e8a00000000000000000000000000000000000000000000000000000000';
538
- const amountOut = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100));
539
- const v2Trade = V2Trade.exactOut(new V2Route([pair_1_WETH, pair_0_1], ETHER, token0), amountOut);
540
- const v3Trade = V3Trade.fromRoute(new V3Route([pool_V3_1_WETH, pool_V3_0_1], ETHER, token0), amountOut, TradeType.EXACT_OUTPUT);
541
- it('array of trades', () => __awaiter(void 0, void 0, void 0, function* () {
542
- const trades = [v2Trade, yield v3Trade];
543
- const { calldata, value } = SwapRouter.swapCallParameters(trades, {
544
- slippageTolerance,
545
- recipient,
546
- deadlineOrPreviousBlockhash: deadline,
547
- });
548
- expect(calldata).toEqual(expectedCalldata);
549
- expect(value).toBe('0xd0');
550
- }));
551
- it('meta-trade', () => __awaiter(void 0, void 0, void 0, function* () {
552
- const trades = yield Trade.fromRoutes([
553
- {
554
- routev2: v2Trade.route,
555
- amount: amountOut,
556
- },
557
- ], [
558
- {
559
- routev3: (yield v3Trade).swaps[0].route,
560
- amount: amountOut,
561
- },
562
- ], TradeType.EXACT_OUTPUT);
563
- const { calldata, value } = SwapRouter.swapCallParameters(trades, {
564
- slippageTolerance,
565
- recipient,
566
- deadlineOrPreviousBlockhash: deadline,
567
- });
568
- expect(calldata).toEqual(expectedCalldata);
569
- expect(value).toBe('0xd0');
570
- }));
571
- });
572
- });
573
- describe('high price impact with ETH input to result in refundETH being appended to calldata', () => {
574
- const expectedCalldata = '0x5ae401dc000000000000000000000000000000000000000000000000000000000000007b000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000002a000000000000000000000000000000000000000000000000000000000000000e4472b43f300000000000000000000000000000000000000000000000000000000000000640000000000000000000000000000000000000000000000000000000000000062000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e404e45aaf000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000bb8000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000640000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000412210e8a00000000000000000000000000000000000000000000000000000000';
575
- const amountIn = CurrencyAmount.fromRawAmount(ETHER, JSBI.BigInt(100));
576
- const pool_V3_1_WETH_slippage = makeV3Pool(token1, WETH, 100);
577
- const REFUND_ETH_FUNCTION_SIG = /12210e8a/;
578
- const v2Trade = V2Trade.exactIn(new V2Route([pair_1_WETH], ETHER, token1), amountIn);
579
- const v3Trade = V3Trade.fromRoute(new V3Route([pool_V3_1_WETH_slippage], ETHER, token1), amountIn, TradeType.EXACT_INPUT);
580
- it('array of trades', () => __awaiter(void 0, void 0, void 0, function* () {
581
- const trades = [v2Trade, yield v3Trade];
582
- const { calldata, value } = SwapRouter.swapCallParameters(trades, {
583
- slippageTolerance,
584
- recipient,
585
- deadlineOrPreviousBlockhash: deadline,
586
- });
587
- expect(calldata).toEqual(expectedCalldata);
588
- expect(calldata).toMatch(REFUND_ETH_FUNCTION_SIG);
589
- expect(value).toBe('0xc8');
590
- }));
591
- });
592
- describe('high price impact with ERCO20 input does not result in refundETH call', () => {
593
- const expectedCalldata = '0x5ae401dc000000000000000000000000000000000000000000000000000000000000007b000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000000e4472b43f3000000000000000000000000000000000000000000000000000000000000006400000000000000000000000000000000000000000000000000000000000000620000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e404e45aaf0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000bb8000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000640000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';
594
- const amountIn = CurrencyAmount.fromRawAmount(token1, JSBI.BigInt(100));
595
- const pool_V3_1_WETH_slippage = makeV3Pool(token1, WETH, 100);
596
- const REFUND_ETH_FUNCTION_SIG = /12210e8a/;
597
- const v2Trade = V2Trade.exactIn(new V2Route([pair_1_WETH], token1, WETH), amountIn);
598
- const v3Trade = V3Trade.fromRoute(new V3Route([pool_V3_1_WETH_slippage], token1, WETH), amountIn, TradeType.EXACT_INPUT);
599
- it('array of trades', () => __awaiter(void 0, void 0, void 0, function* () {
600
- const trades = [v2Trade, yield v3Trade];
601
- const { calldata, value } = SwapRouter.swapCallParameters(trades, {
602
- slippageTolerance,
603
- recipient,
604
- deadlineOrPreviousBlockhash: deadline,
605
- });
606
- expect(calldata).toEqual(expectedCalldata);
607
- expect(calldata).not.toMatch(REFUND_ETH_FUNCTION_SIG);
608
- expect(value).toBe('0x00');
609
- }));
610
- });
611
- });
612
- describe('ETH output', () => {
613
- describe('single-hop exact input (v2 + v3)', () => {
614
- describe('different trade configurations result in identical calldata', () => {
615
- const expectedCalldata = '0x5ae401dc000000000000000000000000000000000000000000000000000000000000007b000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000002a000000000000000000000000000000000000000000000000000000000000000e4472b43f3000000000000000000000000000000000000000000000000000000000000006400000000000000000000000000000000000000000000000000000000000000620000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e404e45aaf0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000bb8000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000640000000000000000000000000000000000000000000000000000000000000061000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004449404b7c00000000000000000000000000000000000000000000000000000000000000c3000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000';
616
- const amountIn = CurrencyAmount.fromRawAmount(token1, JSBI.BigInt(100));
617
- const v2Trade = V2Trade.exactIn(new V2Route([pair_1_WETH], token1, ETHER), amountIn);
618
- const v3Trade = V3Trade.fromRoute(new V3Route([pool_V3_1_WETH], token1, ETHER), amountIn, TradeType.EXACT_INPUT);
619
- /// mixedRoute mirrors v3Trade
620
- const mixedRouteTrade = MixedRouteTrade.fromRoute(new MixedRouteSDK([pool_V3_1_WETH], token1, ETHER), amountIn, TradeType.EXACT_INPUT);
621
- it('array of trades', () => __awaiter(void 0, void 0, void 0, function* () {
622
- const trades = [v2Trade, yield v3Trade];
623
- const { calldata, value } = SwapRouter.swapCallParameters(trades, {
624
- slippageTolerance,
625
- recipient,
626
- deadlineOrPreviousBlockhash: deadline,
627
- });
628
- expect(calldata).toEqual(expectedCalldata);
629
- expect(value).toBe('0x00');
630
- }));
631
- it('array of trades with mixedRoute produces same calldata', () => __awaiter(void 0, void 0, void 0, function* () {
632
- const trades = [v2Trade, yield mixedRouteTrade];
633
- const { calldata, value } = SwapRouter.swapCallParameters(trades, {
634
- slippageTolerance,
635
- recipient,
636
- deadlineOrPreviousBlockhash: deadline,
637
- });
638
- expect(calldata).toEqual(expectedCalldata);
639
- expect(value).toBe('0x00');
640
- }));
641
- it('meta-trade', () => __awaiter(void 0, void 0, void 0, function* () {
642
- const trades = yield Trade.fromRoutes([
643
- {
644
- routev2: v2Trade.route,
645
- amount: amountIn,
646
- },
647
- ], [
648
- {
649
- routev3: (yield v3Trade).swaps[0].route,
650
- amount: amountIn,
651
- },
652
- ], TradeType.EXACT_INPUT);
653
- const { calldata, value } = SwapRouter.swapCallParameters(trades, {
654
- slippageTolerance,
655
- recipient,
656
- deadlineOrPreviousBlockhash: deadline,
657
- });
658
- expect(calldata).toEqual(expectedCalldata);
659
- expect(value).toBe('0x00');
660
- }));
661
- it('meta-trade with mixedRoute produces same calldata', () => __awaiter(void 0, void 0, void 0, function* () {
662
- const trades = yield Trade.fromRoutes([
663
- {
664
- routev2: v2Trade.route,
665
- amount: amountIn,
666
- },
667
- ], [], TradeType.EXACT_INPUT, [
668
- {
669
- mixedRoute: (yield mixedRouteTrade).swaps[0].route,
670
- amount: amountIn,
671
- },
672
- ]);
673
- const { calldata, value } = SwapRouter.swapCallParameters(trades, {
674
- slippageTolerance,
675
- recipient,
676
- deadlineOrPreviousBlockhash: deadline,
677
- });
678
- expect(calldata).toEqual(expectedCalldata);
679
- expect(value).toBe('0x00');
680
- }));
681
- });
682
- });
683
- describe('single-hop exact output (v2 + v3)', () => {
684
- describe('different trade configurations result in identical calldata', () => {
685
- const expectedCalldata = '0x5ae401dc000000000000000000000000000000000000000000000000000000000000007b000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000002a000000000000000000000000000000000000000000000000000000000000000e442712a67000000000000000000000000000000000000000000000000000000000000006400000000000000000000000000000000000000000000000000000000000000660000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e45023b4df0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000bb8000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000640000000000000000000000000000000000000000000000000000000000000067000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004449404b7c00000000000000000000000000000000000000000000000000000000000000c8000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000';
686
- const amountOut = CurrencyAmount.fromRawAmount(ETHER, JSBI.BigInt(100));
687
- const v2Trade = V2Trade.exactOut(new V2Route([pair_1_WETH], token1, ETHER), amountOut);
688
- const v3Trade = V3Trade.fromRoute(new V3Route([pool_V3_1_WETH], token1, ETHER), amountOut, TradeType.EXACT_OUTPUT);
689
- it('array of trades', () => __awaiter(void 0, void 0, void 0, function* () {
690
- const trades = [v2Trade, yield v3Trade];
691
- const { calldata, value } = SwapRouter.swapCallParameters(trades, {
692
- slippageTolerance,
693
- recipient,
694
- deadlineOrPreviousBlockhash: deadline,
695
- });
696
- expect(calldata).toEqual(expectedCalldata);
697
- expect(value).toBe('0x00');
698
- }));
699
- it('meta-trade', () => __awaiter(void 0, void 0, void 0, function* () {
700
- const trades = yield Trade.fromRoutes([
701
- {
702
- routev2: v2Trade.route,
703
- amount: amountOut,
704
- },
705
- ], [
706
- {
707
- routev3: (yield v3Trade).swaps[0].route,
708
- amount: amountOut,
709
- },
710
- ], TradeType.EXACT_OUTPUT);
711
- const { calldata, value } = SwapRouter.swapCallParameters(trades, {
712
- slippageTolerance,
713
- recipient,
714
- deadlineOrPreviousBlockhash: deadline,
715
- });
716
- expect(calldata).toEqual(expectedCalldata);
717
- expect(value).toBe('0x00');
718
- }));
719
- });
720
- });
721
- describe('multi-hop exact input (v2 + v3)', () => {
722
- describe('different trade configurations result in identical calldata', () => {
723
- const expectedCalldata = '0x5ae401dc000000000000000000000000000000000000000000000000000000000000007b00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001a000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000104472b43f30000000000000000000000000000000000000000000000000000000000000064000000000000000000000000000000000000000000000000000000000000006100000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000124b858183f0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000064000000000000000000000000000000000000000000000000000000000000005f00000000000000000000000000000000000000000000000000000000000000420000000000000000000000000000000000000001000bb80000000000000000000000000000000000000002000bb8c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004449404b7c00000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000';
724
- const amountIn = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100));
725
- const v2Trade = V2Trade.exactIn(new V2Route([pair_0_1, pair_1_WETH], token0, ETHER), amountIn);
726
- /// mixedRouteTrade mirrors v2Trade
727
- const mixedRouteTrade = MixedRouteTrade.fromRoute(new MixedRouteSDK([pair_0_1, pair_1_WETH], token0, ETHER), amountIn, TradeType.EXACT_INPUT);
728
- const v3Trade = V3Trade.fromRoute(new V3Route([pool_V3_0_1, pool_V3_1_WETH], token0, ETHER), amountIn, TradeType.EXACT_INPUT);
729
- it('array of trades', () => __awaiter(void 0, void 0, void 0, function* () {
730
- const trades = [v2Trade, yield v3Trade];
731
- const { calldata, value } = SwapRouter.swapCallParameters(trades, {
732
- slippageTolerance,
733
- recipient,
734
- deadlineOrPreviousBlockhash: deadline,
735
- });
736
- expect(calldata).toEqual(expectedCalldata);
737
- expect(value).toBe('0x00');
738
- }));
739
- it('array of trades with mixedRoute produces same calldata', () => __awaiter(void 0, void 0, void 0, function* () {
740
- const trades = [yield mixedRouteTrade, yield v3Trade];
741
- const { calldata, value } = SwapRouter.swapCallParameters(trades, {
742
- slippageTolerance,
743
- recipient,
744
- deadlineOrPreviousBlockhash: deadline,
745
- });
746
- expect(calldata).toEqual(expectedCalldata);
747
- expect(value).toBe('0x00');
748
- }));
749
- it('meta-trade', () => __awaiter(void 0, void 0, void 0, function* () {
750
- const trades = yield Trade.fromRoutes([
751
- {
752
- routev2: v2Trade.route,
753
- amount: amountIn,
754
- },
755
- ], [
756
- {
757
- routev3: (yield v3Trade).swaps[0].route,
758
- amount: amountIn,
759
- },
760
- ], TradeType.EXACT_INPUT);
761
- const { calldata, value } = SwapRouter.swapCallParameters(trades, {
762
- slippageTolerance,
763
- recipient,
764
- deadlineOrPreviousBlockhash: deadline,
765
- });
766
- expect(calldata).toEqual(expectedCalldata);
767
- expect(value).toBe('0x00');
768
- }));
769
- it('meta-trade with mixedRoute produces same calldata but in different order', () => __awaiter(void 0, void 0, void 0, function* () {
770
- const expectedCalldata = '0x5ae401dc000000000000000000000000000000000000000000000000000000000000007b00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000124b858183f0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000064000000000000000000000000000000000000000000000000000000000000005f00000000000000000000000000000000000000000000000000000000000000420000000000000000000000000000000000000001000bb80000000000000000000000000000000000000002000bb8c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000104472b43f30000000000000000000000000000000000000000000000000000000000000064000000000000000000000000000000000000000000000000000000000000006100000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004449404b7c00000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000';
771
- const trades = yield Trade.fromRoutes([], [
772
- {
773
- routev3: (yield v3Trade).swaps[0].route,
774
- amount: amountIn,
775
- },
776
- ], TradeType.EXACT_INPUT, [
777
- {
778
- mixedRoute: (yield mixedRouteTrade).swaps[0].route,
779
- amount: amountIn,
780
- },
781
- ]);
782
- const { calldata, value } = SwapRouter.swapCallParameters(trades, {
783
- slippageTolerance,
784
- recipient,
785
- deadlineOrPreviousBlockhash: deadline,
786
- });
787
- expect(calldata).toEqual(expectedCalldata);
788
- expect(value).toBe('0x00');
789
- }));
790
- });
791
- });
792
- describe('multi-hop exact output (v2 + v3)', () => {
793
- describe('different trade configurations result in identical calldata', () => {
794
- const expectedCalldata = '0x5ae401dc000000000000000000000000000000000000000000000000000000000000007b00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001a00000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000010442712a670000000000000000000000000000000000000000000000000000000000000064000000000000000000000000000000000000000000000000000000000000006700000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000012409b81346000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000006400000000000000000000000000000000000000000000000000000000000000690000000000000000000000000000000000000000000000000000000000000042c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000bb80000000000000000000000000000000000000002000bb8000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004449404b7c00000000000000000000000000000000000000000000000000000000000000c8000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000';
795
- const amountOut = CurrencyAmount.fromRawAmount(ETHER, JSBI.BigInt(100));
796
- const v2Trade = V2Trade.exactOut(new V2Route([pair_0_1, pair_1_WETH], token0, ETHER), amountOut);
797
- const v3Trade = V3Trade.fromRoute(new V3Route([pool_V3_0_1, pool_V3_1_WETH], token0, ETHER), amountOut, TradeType.EXACT_OUTPUT);
798
- it('array of trades', () => __awaiter(void 0, void 0, void 0, function* () {
799
- const trades = [v2Trade, yield v3Trade];
800
- const { calldata, value } = SwapRouter.swapCallParameters(trades, {
801
- slippageTolerance,
802
- recipient,
803
- deadlineOrPreviousBlockhash: deadline,
804
- });
805
- expect(calldata).toEqual(expectedCalldata);
806
- expect(value).toBe('0x00');
807
- }));
808
- it('meta-trade', () => __awaiter(void 0, void 0, void 0, function* () {
809
- const trades = yield Trade.fromRoutes([
810
- {
811
- routev2: v2Trade.route,
812
- amount: amountOut,
813
- },
814
- ], [
815
- {
816
- routev3: (yield v3Trade).swaps[0].route,
817
- amount: amountOut,
818
- },
819
- ], TradeType.EXACT_OUTPUT);
820
- const { calldata, value } = SwapRouter.swapCallParameters(trades, {
821
- slippageTolerance,
822
- recipient,
823
- deadlineOrPreviousBlockhash: deadline,
824
- });
825
- expect(calldata).toEqual(expectedCalldata);
826
- expect(value).toBe('0x00');
827
- }));
828
- });
829
- });
830
- });
831
- describe('#swapAndAddCallParameters', () => {
832
- describe('single-hop trades', () => {
833
- const expectedCalldata = '0xac9650d80000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000700000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000032000000000000000000000000000000000000000000000000000000000000003a00000000000000000000000000000000000000000000000000000000000000420000000000000000000000000000000000000000000000000000000000000056000000000000000000000000000000000000000000000000000000000000005e000000000000000000000000000000000000000000000000000000000000000e4472b43f3000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e404e45aaf000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000bb80000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000070000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044f2d5d56b0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000032c89c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044f2d5d56b0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000032c8ad00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010411ed56c9000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000bb8ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc4000000000000000000000000000000000000000000000000000000000000003c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044e90a182f00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044e90a182f0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';
834
- const amountIn = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(10));
835
- const v2Trade = V2Trade.exactIn(new V2Route([pair_0_1], token0, token1), amountIn);
836
- /// mirrors V2Trade
837
- const mixedRouteTrade2 = MixedRouteTrade.fromRoute(new MixedRouteSDK([pair_0_1], token0, token1), amountIn, TradeType.EXACT_INPUT);
838
- const v3Trade = V3Trade.fromRoute(new V3Route([pool_V3_0_1], token0, token1), amountIn, TradeType.EXACT_INPUT);
839
- /// mixedRoute mirrors v3Trade
840
- const mixedRouteTrade3 = MixedRouteTrade.fromRoute(new MixedRouteSDK([pool_V3_0_1], token0, token1), amountIn, TradeType.EXACT_INPUT);
841
- const position = new Position({
842
- pool: pool_V3_0_1,
843
- tickLower: -60,
844
- tickUpper: 60,
845
- liquidity: 1111111111,
846
- });
847
- const addLiquidityOptions = {
848
- recipient: '0x0000000000000000000000000000000000000006',
849
- slippageTolerance,
850
- deadline: Math.pow(2, 32),
851
- };
852
- it('correctly encodes the entire swap process', () => __awaiter(void 0, void 0, void 0, function* () {
853
- const trades = [v2Trade, yield v3Trade];
854
- const methodParameters = SwapRouter.swapAndAddCallParameters(trades, { slippageTolerance }, position, addLiquidityOptions, ApprovalTypes.NOT_REQUIRED, ApprovalTypes.NOT_REQUIRED);
855
- expect(methodParameters.calldata).toEqual(expectedCalldata);
856
- }));
857
- it('correctly encodes the entire swap process when v2 + mixedRoute', () => __awaiter(void 0, void 0, void 0, function* () {
858
- const trades = [v2Trade, yield mixedRouteTrade3];
859
- const methodParameters = SwapRouter.swapAndAddCallParameters(trades, { slippageTolerance }, position, addLiquidityOptions, ApprovalTypes.NOT_REQUIRED, ApprovalTypes.NOT_REQUIRED);
860
- expect(methodParameters.calldata).toEqual(expectedCalldata);
861
- }));
862
- it('correctly encodes the entire swap process when mixedRoute + v3', () => __awaiter(void 0, void 0, void 0, function* () {
863
- const trades = [yield mixedRouteTrade2, yield v3Trade];
864
- const methodParameters = SwapRouter.swapAndAddCallParameters(trades, { slippageTolerance }, position, addLiquidityOptions, ApprovalTypes.NOT_REQUIRED, ApprovalTypes.NOT_REQUIRED);
865
- expect(methodParameters.calldata).toEqual(expectedCalldata);
866
- }));
867
- });
868
- describe('multi-hop trades', () => {
869
- const expectedCalldata = '0xac9650d80000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000700000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000022000000000000000000000000000000000000000000000000000000000000003800000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000048000000000000000000000000000000000000000000000000000000000000005c000000000000000000000000000000000000000000000000000000000000006400000000000000000000000000000000000000000000000000000000000000104472b43f30000000000000000000000000000000000000000000000000000000000000064000000000000000000000000000000000000000000000000000000000000006100000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000124b858183f0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000064000000000000000000000000000000000000000000000000000000000000005f00000000000000000000000000000000000000000000000000000000000000420000000000000000000000000000000000000001000bb80000000000000000000000000000000000000002000bb8c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044f2d5d56b000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000000032c7eb000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044f2d5d56b0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000032c8ad00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010411ed56c90000000000000000000000000000000000000000000000000000000000000001000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000bb8ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc4000000000000000000000000000000000000000000000000000000000000003c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044e90a182f00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044e90a182f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';
870
- const pool_V3_0_WETH = makeV3Pool(token0, WETH, liquidity);
871
- const amountIn = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100));
872
- const v2Trade = V2Trade.exactIn(new V2Route([pair_0_1, pair_1_WETH], token0, WETH), amountIn);
873
- /// mirrors V2Trade
874
- const mixedRouteTrade2 = MixedRouteTrade.fromRoute(new MixedRouteSDK([pair_0_1, pair_1_WETH], token0, WETH), amountIn, TradeType.EXACT_INPUT);
875
- const v3Trade = V3Trade.fromRoute(new V3Route([pool_V3_0_1, pool_V3_1_WETH], token0, WETH), amountIn, TradeType.EXACT_INPUT);
876
- /// mixedRoute mirrors v3Trade
877
- const mixedRouteTrade3 = MixedRouteTrade.fromRoute(new MixedRouteSDK([pool_V3_0_1, pool_V3_1_WETH], token0, WETH), amountIn, TradeType.EXACT_INPUT);
878
- const position = new Position({
879
- pool: pool_V3_0_WETH,
880
- tickLower: -60,
881
- tickUpper: 60,
882
- liquidity: 1111111111,
883
- });
884
- const addLiquidityOptions = {
885
- recipient: '0x0000000000000000000000000000000000000006',
886
- slippageTolerance,
887
- deadline: Math.pow(2, 32),
888
- };
889
- it('encodes the entire swap process for a multi route trade', () => __awaiter(void 0, void 0, void 0, function* () {
890
- const trades = [v2Trade, yield v3Trade];
891
- const methodParameters = SwapRouter.swapAndAddCallParameters(trades, { slippageTolerance }, position, addLiquidityOptions, ApprovalTypes.NOT_REQUIRED, ApprovalTypes.NOT_REQUIRED);
892
- expect(methodParameters.calldata).toEqual(expectedCalldata);
893
- }));
894
- it('encodes the entire swap process for a multi route trade with v2, mixedRoute', () => __awaiter(void 0, void 0, void 0, function* () {
895
- const trades = [v2Trade, yield mixedRouteTrade3];
896
- const methodParameters = SwapRouter.swapAndAddCallParameters(trades, { slippageTolerance }, position, addLiquidityOptions, ApprovalTypes.NOT_REQUIRED, ApprovalTypes.NOT_REQUIRED);
897
- expect(methodParameters.calldata).toEqual(expectedCalldata);
898
- }));
899
- it('encodes the entire swap process for a multi route trade with mixedRoute, v3', () => __awaiter(void 0, void 0, void 0, function* () {
900
- const trades = [yield mixedRouteTrade2, yield v3Trade];
901
- const methodParameters = SwapRouter.swapAndAddCallParameters(trades, { slippageTolerance }, position, addLiquidityOptions, ApprovalTypes.NOT_REQUIRED, ApprovalTypes.NOT_REQUIRED);
902
- expect(methodParameters.calldata).toEqual(expectedCalldata);
903
- }));
904
- it('encodes the entire swap process for a multi route trade with mixedRoute, mixedRoute', () => __awaiter(void 0, void 0, void 0, function* () {
905
- const trades = [yield mixedRouteTrade2, yield mixedRouteTrade3];
906
- const methodParameters = SwapRouter.swapAndAddCallParameters(trades, { slippageTolerance }, position, addLiquidityOptions, ApprovalTypes.NOT_REQUIRED, ApprovalTypes.NOT_REQUIRED);
907
- expect(methodParameters.calldata).toEqual(expectedCalldata);
908
- }));
909
- });
910
- describe('adding liquidity to an existing position', () => {
911
- const expectedCalldata = '0xac9650d80000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000700000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000032000000000000000000000000000000000000000000000000000000000000003a000000000000000000000000000000000000000000000000000000000000004200000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000058000000000000000000000000000000000000000000000000000000000000000e4472b43f3000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e404e45aaf000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000bb80000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000070000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044f2d5d56b0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000032c89c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044f2d5d56b0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000032c8ad0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a4f100b20500000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044e90a182f00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044e90a182f0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';
912
- const amountIn = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(10));
913
- const v2Trade = V2Trade.exactIn(new V2Route([pair_0_1], token0, token1), amountIn);
914
- const mixedRouteTrade2 = MixedRouteTrade.fromRoute(new MixedRouteSDK([pair_0_1], token0, token1), amountIn, TradeType.EXACT_INPUT);
915
- const v3Trade = V3Trade.fromRoute(new V3Route([pool_V3_0_1], token0, token1), amountIn, TradeType.EXACT_INPUT);
916
- const mixedRouteTrade3 = MixedRouteTrade.fromRoute(new MixedRouteSDK([pool_V3_0_1], token0, token1), amountIn, TradeType.EXACT_INPUT);
917
- const position = new Position({
918
- pool: pool_V3_0_1,
919
- tickLower: -60,
920
- tickUpper: 60,
921
- liquidity: 1111111111,
922
- });
923
- const addLiquidityOptions = {
924
- slippageTolerance,
925
- deadline: Math.pow(2, 32),
926
- tokenId: 1,
927
- };
928
- it('correctly encodes the entire swap process', () => __awaiter(void 0, void 0, void 0, function* () {
929
- const trades = [v2Trade, yield v3Trade];
930
- const methodParameters = SwapRouter.swapAndAddCallParameters(trades, { slippageTolerance }, position, addLiquidityOptions, ApprovalTypes.NOT_REQUIRED, ApprovalTypes.NOT_REQUIRED);
931
- expect(methodParameters.calldata).toEqual(expectedCalldata);
932
- }));
933
- it('correctly encodes the entire swap process, v2, mixed', () => __awaiter(void 0, void 0, void 0, function* () {
934
- const trades = [v2Trade, yield mixedRouteTrade3];
935
- const methodParameters = SwapRouter.swapAndAddCallParameters(trades, { slippageTolerance }, position, addLiquidityOptions, ApprovalTypes.NOT_REQUIRED, ApprovalTypes.NOT_REQUIRED);
936
- expect(methodParameters.calldata).toEqual(expectedCalldata);
937
- }));
938
- it('correctly encodes the entire swap process, mixed, v3', () => __awaiter(void 0, void 0, void 0, function* () {
939
- const trades = [yield mixedRouteTrade2, yield v3Trade];
940
- const methodParameters = SwapRouter.swapAndAddCallParameters(trades, { slippageTolerance }, position, addLiquidityOptions, ApprovalTypes.NOT_REQUIRED, ApprovalTypes.NOT_REQUIRED);
941
- expect(methodParameters.calldata).toEqual(expectedCalldata);
942
- }));
943
- });
944
- describe('when MAX tokens must be approved to the NFT Manager', () => {
945
- const expectedCalldata = '0xac9650d80000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000900000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000240000000000000000000000000000000000000000000000000000000000000036000000000000000000000000000000000000000000000000000000000000003e0000000000000000000000000000000000000000000000000000000000000046000000000000000000000000000000000000000000000000000000000000004c000000000000000000000000000000000000000000000000000000000000005200000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000068000000000000000000000000000000000000000000000000000000000000000e4472b43f3000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e404e45aaf000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000bb80000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000070000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044f2d5d56b0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000032c89c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044f2d5d56b0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000032c8ad000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024571ac8b00000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024571ac8b000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a4f100b20500000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044e90a182f00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044e90a182f0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';
946
- const amountIn = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(10));
947
- const v2Trade = V2Trade.exactIn(new V2Route([pair_0_1], token0, token1), amountIn);
948
- const mixedRouteTrade2 = MixedRouteTrade.fromRoute(new MixedRouteSDK([pair_0_1], token0, token1), amountIn, TradeType.EXACT_INPUT);
949
- const v3Trade = V3Trade.fromRoute(new V3Route([pool_V3_0_1], token0, token1), amountIn, TradeType.EXACT_INPUT);
950
- const mixedRouteTrade3 = MixedRouteTrade.fromRoute(new MixedRouteSDK([pool_V3_0_1], token0, token1), amountIn, TradeType.EXACT_INPUT);
951
- const position = new Position({
952
- pool: pool_V3_0_1,
953
- tickLower: -60,
954
- tickUpper: 60,
955
- liquidity: 1111111111,
956
- });
957
- const addLiquidityOptions = {
958
- slippageTolerance,
959
- deadline: Math.pow(2, 32),
960
- tokenId: 1,
961
- };
962
- it('correctly encodes the entire swap process', () => __awaiter(void 0, void 0, void 0, function* () {
963
- const trades = [v2Trade, yield v3Trade];
964
- const methodParameters = SwapRouter.swapAndAddCallParameters(trades, { slippageTolerance }, position, addLiquidityOptions, ApprovalTypes.MAX, ApprovalTypes.MAX);
965
- expect(methodParameters.calldata).toEqual(expectedCalldata);
966
- }));
967
- it('correctly encodes the entire swap process, v2, mixed', () => __awaiter(void 0, void 0, void 0, function* () {
968
- const trades = [v2Trade, yield mixedRouteTrade3];
969
- const methodParameters = SwapRouter.swapAndAddCallParameters(trades, { slippageTolerance }, position, addLiquidityOptions, ApprovalTypes.MAX, ApprovalTypes.MAX);
970
- expect(methodParameters.calldata).toEqual(expectedCalldata);
971
- }));
972
- it('correctly encodes the entire swap process, mixed, v3', () => __awaiter(void 0, void 0, void 0, function* () {
973
- const trades = [yield mixedRouteTrade2, yield v3Trade];
974
- const methodParameters = SwapRouter.swapAndAddCallParameters(trades, { slippageTolerance }, position, addLiquidityOptions, ApprovalTypes.MAX, ApprovalTypes.MAX);
975
- expect(methodParameters.calldata).toEqual(expectedCalldata);
976
- }));
977
- it('correctly encodes the entire swap process, mixed, mixed', () => __awaiter(void 0, void 0, void 0, function* () {
978
- const trades = [yield mixedRouteTrade2, yield mixedRouteTrade3];
979
- const methodParameters = SwapRouter.swapAndAddCallParameters(trades, { slippageTolerance }, position, addLiquidityOptions, ApprovalTypes.MAX, ApprovalTypes.MAX);
980
- expect(methodParameters.calldata).toEqual(expectedCalldata);
981
- }));
982
- });
983
- describe('when MAX_MINUS_ONE tokens must be approved to the NFT Manager', () => {
984
- const expectedCalldata = '0xac9650d80000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000900000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000240000000000000000000000000000000000000000000000000000000000000036000000000000000000000000000000000000000000000000000000000000003e0000000000000000000000000000000000000000000000000000000000000046000000000000000000000000000000000000000000000000000000000000004c000000000000000000000000000000000000000000000000000000000000005200000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000068000000000000000000000000000000000000000000000000000000000000000e4472b43f3000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e404e45aaf000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000bb80000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000070000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044f2d5d56b0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000032c89c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044f2d5d56b0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000032c8ad000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024cab372ce0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024cab372ce00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a4f100b20500000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044e90a182f00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044e90a182f0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';
985
- const amountIn = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(10));
986
- const v2Trade = V2Trade.exactIn(new V2Route([pair_0_1], token0, token1), amountIn);
987
- const mixedRouteTrade2 = MixedRouteTrade.fromRoute(new MixedRouteSDK([pair_0_1], token0, token1), amountIn, TradeType.EXACT_INPUT);
988
- const v3Trade = V3Trade.fromRoute(new V3Route([pool_V3_0_1], token0, token1), amountIn, TradeType.EXACT_INPUT);
989
- const mixedRouteTrade3 = MixedRouteTrade.fromRoute(new MixedRouteSDK([pool_V3_0_1], token0, token1), amountIn, TradeType.EXACT_INPUT);
990
- const position = new Position({
991
- pool: pool_V3_0_1,
992
- tickLower: -60,
993
- tickUpper: 60,
994
- liquidity: 1111111111,
995
- });
996
- const addLiquidityOptions = {
997
- slippageTolerance,
998
- deadline: Math.pow(2, 32),
999
- tokenId: 1,
1000
- };
1001
- it('correctly encodes the entire swap process', () => __awaiter(void 0, void 0, void 0, function* () {
1002
- const trades = [v2Trade, yield v3Trade];
1003
- const methodParameters = SwapRouter.swapAndAddCallParameters(trades, { slippageTolerance }, position, addLiquidityOptions, ApprovalTypes.MAX_MINUS_ONE, ApprovalTypes.MAX_MINUS_ONE);
1004
- expect(methodParameters.calldata).toEqual(expectedCalldata);
1005
- }));
1006
- it('correctly encodes the entire swap process, v2, mixed', () => __awaiter(void 0, void 0, void 0, function* () {
1007
- const trades = [v2Trade, yield mixedRouteTrade3];
1008
- const methodParameters = SwapRouter.swapAndAddCallParameters(trades, { slippageTolerance }, position, addLiquidityOptions, ApprovalTypes.MAX_MINUS_ONE, ApprovalTypes.MAX_MINUS_ONE);
1009
- expect(methodParameters.calldata).toEqual(expectedCalldata);
1010
- }));
1011
- it('correctly encodes the entire swap process, mixed, v3', () => __awaiter(void 0, void 0, void 0, function* () {
1012
- const trades = [yield mixedRouteTrade2, yield v3Trade];
1013
- const methodParameters = SwapRouter.swapAndAddCallParameters(trades, { slippageTolerance }, position, addLiquidityOptions, ApprovalTypes.MAX_MINUS_ONE, ApprovalTypes.MAX_MINUS_ONE);
1014
- expect(methodParameters.calldata).toEqual(expectedCalldata);
1015
- }));
1016
- it('correctly encodes the entire swap process, mixed, mixed', () => __awaiter(void 0, void 0, void 0, function* () {
1017
- const trades = [yield mixedRouteTrade2, yield mixedRouteTrade3];
1018
- const methodParameters = SwapRouter.swapAndAddCallParameters(trades, { slippageTolerance }, position, addLiquidityOptions, ApprovalTypes.MAX_MINUS_ONE, ApprovalTypes.MAX_MINUS_ONE);
1019
- expect(methodParameters.calldata).toEqual(expectedCalldata);
1020
- }));
1021
- });
1022
- describe('when ZERO_THEN_MAX tokens must be approved to the NFT Manager', () => {
1023
- const expectedCalldata = '0xac9650d80000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000900000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000240000000000000000000000000000000000000000000000000000000000000036000000000000000000000000000000000000000000000000000000000000003e0000000000000000000000000000000000000000000000000000000000000046000000000000000000000000000000000000000000000000000000000000004c000000000000000000000000000000000000000000000000000000000000005200000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000068000000000000000000000000000000000000000000000000000000000000000e4472b43f3000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e404e45aaf000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000bb80000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000070000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044f2d5d56b0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000032c89c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044f2d5d56b0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000032c8ad000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024639d71a90000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024639d71a900000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a4f100b20500000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044e90a182f00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044e90a182f0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';
1024
- const amountIn = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(10));
1025
- const v2Trade = V2Trade.exactIn(new V2Route([pair_0_1], token0, token1), amountIn);
1026
- const mixedRouteTrade2 = MixedRouteTrade.fromRoute(new MixedRouteSDK([pair_0_1], token0, token1), amountIn, TradeType.EXACT_INPUT);
1027
- const v3Trade = V3Trade.fromRoute(new V3Route([pool_V3_0_1], token0, token1), amountIn, TradeType.EXACT_INPUT);
1028
- const mixedRouteTrade3 = MixedRouteTrade.fromRoute(new MixedRouteSDK([pool_V3_0_1], token0, token1), amountIn, TradeType.EXACT_INPUT);
1029
- const position = new Position({
1030
- pool: pool_V3_0_1,
1031
- tickLower: -60,
1032
- tickUpper: 60,
1033
- liquidity: 1111111111,
1034
- });
1035
- const addLiquidityOptions = {
1036
- slippageTolerance,
1037
- deadline: Math.pow(2, 32),
1038
- tokenId: 1,
1039
- };
1040
- it('correctly encodes the entire swap process', () => __awaiter(void 0, void 0, void 0, function* () {
1041
- const trades = [v2Trade, yield v3Trade];
1042
- const methodParameters = SwapRouter.swapAndAddCallParameters(trades, { slippageTolerance }, position, addLiquidityOptions, ApprovalTypes.ZERO_THEN_MAX, ApprovalTypes.ZERO_THEN_MAX);
1043
- expect(methodParameters.calldata).toEqual(expectedCalldata);
1044
- }));
1045
- it('correctly encodes the entire swap process v2, mixed', () => __awaiter(void 0, void 0, void 0, function* () {
1046
- const trades = [v2Trade, yield mixedRouteTrade3];
1047
- const methodParameters = SwapRouter.swapAndAddCallParameters(trades, { slippageTolerance }, position, addLiquidityOptions, ApprovalTypes.ZERO_THEN_MAX, ApprovalTypes.ZERO_THEN_MAX);
1048
- expect(methodParameters.calldata).toEqual(expectedCalldata);
1049
- }));
1050
- it('correctly encodes the entire swap process mixed, v3', () => __awaiter(void 0, void 0, void 0, function* () {
1051
- const trades = [yield mixedRouteTrade2, yield v3Trade];
1052
- const methodParameters = SwapRouter.swapAndAddCallParameters(trades, { slippageTolerance }, position, addLiquidityOptions, ApprovalTypes.ZERO_THEN_MAX, ApprovalTypes.ZERO_THEN_MAX);
1053
- expect(methodParameters.calldata).toEqual(expectedCalldata);
1054
- }));
1055
- it('correctly encodes the entire swap process mixed, mixed', () => __awaiter(void 0, void 0, void 0, function* () {
1056
- const trades = [yield mixedRouteTrade2, yield mixedRouteTrade3];
1057
- const methodParameters = SwapRouter.swapAndAddCallParameters(trades, { slippageTolerance }, position, addLiquidityOptions, ApprovalTypes.ZERO_THEN_MAX, ApprovalTypes.ZERO_THEN_MAX);
1058
- expect(methodParameters.calldata).toEqual(expectedCalldata);
1059
- }));
1060
- });
1061
- describe('when ZERO_THEN_MAX_MINUS_ONE tokens must be approved to the NFT Manager', () => {
1062
- const expectedCalldata = '0xac9650d80000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000900000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000240000000000000000000000000000000000000000000000000000000000000036000000000000000000000000000000000000000000000000000000000000003e0000000000000000000000000000000000000000000000000000000000000046000000000000000000000000000000000000000000000000000000000000004c000000000000000000000000000000000000000000000000000000000000005200000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000068000000000000000000000000000000000000000000000000000000000000000e4472b43f3000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e404e45aaf000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000bb80000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000070000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044f2d5d56b0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000032c89c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044f2d5d56b0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000032c8ad000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024ab3fdd500000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024ab3fdd5000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a4f100b20500000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044e90a182f00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044e90a182f0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';
1063
- const amountIn = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(10));
1064
- const v2Trade = V2Trade.exactIn(new V2Route([pair_0_1], token0, token1), amountIn);
1065
- const mixedRouteTrade2 = MixedRouteTrade.fromRoute(new MixedRouteSDK([pair_0_1], token0, token1), amountIn, TradeType.EXACT_INPUT);
1066
- const v3Trade = V3Trade.fromRoute(new V3Route([pool_V3_0_1], token0, token1), amountIn, TradeType.EXACT_INPUT);
1067
- const mixedRouteTrade3 = MixedRouteTrade.fromRoute(new MixedRouteSDK([pool_V3_0_1], token0, token1), amountIn, TradeType.EXACT_INPUT);
1068
- const position = new Position({
1069
- pool: pool_V3_0_1,
1070
- tickLower: -60,
1071
- tickUpper: 60,
1072
- liquidity: 1111111111,
1073
- });
1074
- const addLiquidityOptions = {
1075
- slippageTolerance,
1076
- deadline: Math.pow(2, 32),
1077
- tokenId: 1,
1078
- };
1079
- it('correctly encodes the entire swap process', () => __awaiter(void 0, void 0, void 0, function* () {
1080
- const trades = [v2Trade, yield v3Trade];
1081
- const methodParameters = SwapRouter.swapAndAddCallParameters(trades, { slippageTolerance }, position, addLiquidityOptions, ApprovalTypes.ZERO_THEN_MAX_MINUS_ONE, ApprovalTypes.ZERO_THEN_MAX_MINUS_ONE);
1082
- expect(methodParameters.calldata).toEqual(expectedCalldata);
1083
- }));
1084
- it('correctly encodes the entire swap process v2, mixed', () => __awaiter(void 0, void 0, void 0, function* () {
1085
- const trades = [v2Trade, yield mixedRouteTrade3];
1086
- const methodParameters = SwapRouter.swapAndAddCallParameters(trades, { slippageTolerance }, position, addLiquidityOptions, ApprovalTypes.ZERO_THEN_MAX_MINUS_ONE, ApprovalTypes.ZERO_THEN_MAX_MINUS_ONE);
1087
- expect(methodParameters.calldata).toEqual(expectedCalldata);
1088
- }));
1089
- it('correctly encodes the entire swap process mixed, v3', () => __awaiter(void 0, void 0, void 0, function* () {
1090
- const trades = [yield mixedRouteTrade2, yield v3Trade];
1091
- const methodParameters = SwapRouter.swapAndAddCallParameters(trades, { slippageTolerance }, position, addLiquidityOptions, ApprovalTypes.ZERO_THEN_MAX_MINUS_ONE, ApprovalTypes.ZERO_THEN_MAX_MINUS_ONE);
1092
- expect(methodParameters.calldata).toEqual(expectedCalldata);
1093
- }));
1094
- it('correctly encodes the entire swap process mixed, mixed', () => __awaiter(void 0, void 0, void 0, function* () {
1095
- const trades = [yield mixedRouteTrade2, yield mixedRouteTrade3];
1096
- const methodParameters = SwapRouter.swapAndAddCallParameters(trades, { slippageTolerance }, position, addLiquidityOptions, ApprovalTypes.ZERO_THEN_MAX_MINUS_ONE, ApprovalTypes.ZERO_THEN_MAX_MINUS_ONE);
1097
- expect(methodParameters.calldata).toEqual(expectedCalldata);
1098
- }));
1099
- });
1100
- describe('when input is native', () => {
1101
- const expectedCalldata = '0xac9650d8000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000022000000000000000000000000000000000000000000000000000000000000002a00000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000036000000000000000000000000000000000000000000000000000000000000003c000000000000000000000000000000000000000000000000000000000000004a0000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000000000000000000000000000000000000000e404e45aaf000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000bb80000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000070000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044f2d5d56b0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000032c8a50000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000241c58db4f000000000000000000000000000000000000000000000000000000000032c8ad000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024571ac8b0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024571ac8b000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a4f100b2050000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024496169970000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044e90a182f0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';
1102
- const ETH = Ether.onChain(1);
1103
- const amountIn = CurrencyAmount.fromRawAmount(ETH, JSBI.BigInt(10));
1104
- const v3Trade = V3Trade.fromRoute(new V3Route([pool_V3_1_WETH], ETH, token1), amountIn, TradeType.EXACT_INPUT);
1105
- const mixedRouteTrade3 = MixedRouteTrade.fromRoute(new MixedRouteSDK([pool_V3_1_WETH], ETH, token1), amountIn, TradeType.EXACT_INPUT);
1106
- const position = new Position({
1107
- pool: pool_V3_1_WETH,
1108
- tickLower: -60,
1109
- tickUpper: 60,
1110
- liquidity: 1111111111,
1111
- });
1112
- const addLiquidityOptions = {
1113
- slippageTolerance,
1114
- deadline: Math.pow(2, 32),
1115
- tokenId: 1,
1116
- };
1117
- it('correctly encodes the entire swap process', () => __awaiter(void 0, void 0, void 0, function* () {
1118
- const trades = [yield v3Trade];
1119
- const methodParameters = SwapRouter.swapAndAddCallParameters(trades, { slippageTolerance }, position, addLiquidityOptions, ApprovalTypes.MAX, ApprovalTypes.MAX);
1120
- expect(methodParameters.calldata).toEqual(expectedCalldata);
1121
- }));
1122
- it('correctly encodes the entire swap process when is a mixedRoute', () => __awaiter(void 0, void 0, void 0, function* () {
1123
- const trades = [yield mixedRouteTrade3];
1124
- const methodParameters = SwapRouter.swapAndAddCallParameters(trades, { slippageTolerance }, position, addLiquidityOptions, ApprovalTypes.MAX, ApprovalTypes.MAX);
1125
- expect(methodParameters.calldata).toEqual(expectedCalldata);
1126
- }));
1127
- });
1128
- describe('when output is native', () => {
1129
- const expectedCalldata = '0xac9650d8000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000022000000000000000000000000000000000000000000000000000000000000002800000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000036000000000000000000000000000000000000000000000000000000000000003c000000000000000000000000000000000000000000000000000000000000004a0000000000000000000000000000000000000000000000000000000000000052000000000000000000000000000000000000000000000000000000000000000e404e45aaf0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000bb80000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000241c58db4f000000000000000000000000000000000000000000000000000000000032c8a5000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044f2d5d56b0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000032c8ad000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024571ac8b00000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024571ac8b0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a4f100b2050000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044e90a182f0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002449616997000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';
1130
- const ETH = Ether.onChain(1);
1131
- const amountIn = CurrencyAmount.fromRawAmount(token1, JSBI.BigInt(10));
1132
- const v3Trade = V3Trade.fromRoute(new V3Route([pool_V3_1_WETH], token1, ETH), amountIn, TradeType.EXACT_INPUT);
1133
- const mixedRouteTrade3 = MixedRouteTrade.fromRoute(new MixedRouteSDK([pool_V3_1_WETH], token1, ETH), amountIn, TradeType.EXACT_INPUT);
1134
- const position = new Position({
1135
- pool: pool_V3_1_WETH,
1136
- tickLower: -60,
1137
- tickUpper: 60,
1138
- liquidity: 1111111111,
1139
- });
1140
- const addLiquidityOptions = {
1141
- slippageTolerance,
1142
- deadline: Math.pow(2, 32),
1143
- tokenId: 1,
1144
- };
1145
- it('correctly encodes the entire swap process', () => __awaiter(void 0, void 0, void 0, function* () {
1146
- const trades = [yield v3Trade];
1147
- const methodParameters = SwapRouter.swapAndAddCallParameters(trades, { slippageTolerance }, position, addLiquidityOptions, ApprovalTypes.MAX, ApprovalTypes.MAX);
1148
- expect(methodParameters.calldata).toEqual(expectedCalldata);
1149
- }));
1150
- it('correctly encodes the entire swap process when is mixedRoute', () => __awaiter(void 0, void 0, void 0, function* () {
1151
- const trades = [yield mixedRouteTrade3];
1152
- const methodParameters = SwapRouter.swapAndAddCallParameters(trades, { slippageTolerance }, position, addLiquidityOptions, ApprovalTypes.MAX, ApprovalTypes.MAX);
1153
- expect(methodParameters.calldata).toEqual(expectedCalldata);
1154
- }));
1155
- });
1156
- });
1157
- });
1158
- });
1159
- //# sourceMappingURL=swapRouter.test.js.map