@uniswap/router-sdk 2.0.1 → 2.0.3

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,1265 +0,0 @@
1
- import { __awaiter } from "tslib";
2
- import { sqrt, Token, CurrencyAmount, TradeType, WETH9, Ether, Percent, Price } from '@uniswap/sdk-core';
3
- import { BigNumber } from '@ethersproject/bignumber';
4
- import JSBI from 'jsbi';
5
- import { MixedRoute, RouteV2, RouteV3, RouteV4 } from './route';
6
- import { Trade } from './trade';
7
- import { Route as V3RouteSDK, FeeAmount, TICK_SPACINGS, Pool as V3Pool, TickMath, nearestUsableTick, encodeSqrtRatioX96, } from '@uniswap/v3-sdk';
8
- import { Pair, Route as V2RouteSDK } from '@uniswap/v2-sdk';
9
- import { MixedRouteSDK } from './mixedRoute/route';
10
- import { Route as V4RouteSDK, Pool as V4Pool } from '@uniswap/v4-sdk';
11
- import { ADDRESS_ZERO } from '../constants';
12
- describe('Trade', () => {
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 token3 = new Token(1, '0x0000000000000000000000000000000000000004', 18, 't3', 'token3');
19
- const SQRT_RATIO_ONE = encodeSqrtRatioX96(1, 1);
20
- const token4WithTax = new Token(1, '0x0000000000000000000000000000000000000005', 18, 't4', 'token4', false, BigNumber.from(100), BigNumber.from(100));
21
- const token5WithTax = new Token(1, '0x0000000000000000000000000000000000000005', 18, 't5', 'token5', false, BigNumber.from(500), BigNumber.from(500));
22
- function v2StylePool(reserve0, reserve1, feeAmount = FeeAmount.MEDIUM) {
23
- const sqrtRatioX96 = encodeSqrtRatioX96(reserve1.quotient, reserve0.quotient);
24
- const liquidity = sqrt(JSBI.multiply(reserve0.quotient, reserve1.quotient));
25
- return new V3Pool(reserve0.currency, reserve1.currency, feeAmount, sqrtRatioX96, liquidity, TickMath.getTickAtSqrtRatio(sqrtRatioX96), [
26
- {
27
- index: nearestUsableTick(TickMath.MIN_TICK, TICK_SPACINGS[feeAmount]),
28
- liquidityNet: liquidity,
29
- liquidityGross: liquidity,
30
- },
31
- {
32
- index: nearestUsableTick(TickMath.MAX_TICK, TICK_SPACINGS[feeAmount]),
33
- liquidityNet: JSBI.multiply(liquidity, JSBI.BigInt(-1)),
34
- liquidityGross: liquidity,
35
- },
36
- ]);
37
- }
38
- const pool_0_1 = v2StylePool(CurrencyAmount.fromRawAmount(token0, 100000), CurrencyAmount.fromRawAmount(token1, 100000));
39
- const pool_0_2 = v2StylePool(CurrencyAmount.fromRawAmount(token0, 100000), CurrencyAmount.fromRawAmount(token2, 110000));
40
- const pool_1_2 = v2StylePool(CurrencyAmount.fromRawAmount(token1, JSBI.BigInt(12000)), CurrencyAmount.fromRawAmount(token2, JSBI.BigInt(10000)));
41
- const pool_0_3 = v2StylePool(CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(10000)), CurrencyAmount.fromRawAmount(token3, JSBI.BigInt(10000)));
42
- const pair_0_1 = new Pair(CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(12000)), CurrencyAmount.fromRawAmount(token1, JSBI.BigInt(12000)));
43
- const pair_1_2 = new Pair(CurrencyAmount.fromRawAmount(token1, JSBI.BigInt(12000)), CurrencyAmount.fromRawAmount(token2, JSBI.BigInt(10000)));
44
- const pair_0_2 = new Pair(CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(10000)), CurrencyAmount.fromRawAmount(token2, JSBI.BigInt(12000)));
45
- const pair_2_3 = new Pair(CurrencyAmount.fromRawAmount(token2, JSBI.BigInt(10000)), CurrencyAmount.fromRawAmount(token3, JSBI.BigInt(10000)));
46
- const pair_weth_0 = new Pair(CurrencyAmount.fromRawAmount(weth, JSBI.BigInt(10000)), CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(10000)));
47
- const pair_weth_1 = new Pair(CurrencyAmount.fromRawAmount(weth, JSBI.BigInt(10000)), CurrencyAmount.fromRawAmount(token1, JSBI.BigInt(10000)));
48
- const pair_weth_2 = new Pair(CurrencyAmount.fromRawAmount(weth, JSBI.BigInt(10000)), CurrencyAmount.fromRawAmount(token2, JSBI.BigInt(10000)));
49
- const pair_tax_output = new Pair(CurrencyAmount.fromRawAmount(weth, JSBI.BigInt(100000)), CurrencyAmount.fromRawAmount(token4WithTax, JSBI.BigInt(100000)));
50
- const pair_tax_input = new Pair(CurrencyAmount.fromRawAmount(token5WithTax, JSBI.BigInt(100000)), CurrencyAmount.fromRawAmount(weth, JSBI.BigInt(100000)));
51
- const pool_weth_0 = v2StylePool(CurrencyAmount.fromRawAmount(weth, JSBI.BigInt(100000)), CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100000)));
52
- const pool_weth_2 = v2StylePool(CurrencyAmount.fromRawAmount(weth, JSBI.BigInt(100000)), CurrencyAmount.fromRawAmount(token2, JSBI.BigInt(100000)));
53
- const pool_weth_1 = v2StylePool(CurrencyAmount.fromRawAmount(weth, JSBI.BigInt(100000)), CurrencyAmount.fromRawAmount(token1, JSBI.BigInt(100000)));
54
- const pool_v4_1_eth = new V4Pool(token1, ETHER, FeeAmount.MEDIUM, 60, ADDRESS_ZERO, SQRT_RATIO_ONE, JSBI.BigInt(10000000000000), 0, [
55
- {
56
- index: nearestUsableTick(TickMath.MIN_TICK, TICK_SPACINGS[FeeAmount.MEDIUM]),
57
- liquidityNet: JSBI.BigInt(10000000000000),
58
- liquidityGross: JSBI.BigInt(10000000000000),
59
- },
60
- {
61
- index: nearestUsableTick(TickMath.MAX_TICK, TICK_SPACINGS[FeeAmount.MEDIUM]),
62
- liquidityNet: JSBI.multiply(JSBI.BigInt(10000000000000), JSBI.BigInt(-1)),
63
- liquidityGross: JSBI.BigInt(10000000000000),
64
- },
65
- ]);
66
- const pool_v4_0_eth = new V4Pool(token0, ETHER, FeeAmount.MEDIUM, 60, ADDRESS_ZERO, SQRT_RATIO_ONE, JSBI.BigInt(10000000000000), 0, [
67
- {
68
- index: nearestUsableTick(TickMath.MIN_TICK, TICK_SPACINGS[FeeAmount.MEDIUM]),
69
- liquidityNet: JSBI.BigInt(10000000000000),
70
- liquidityGross: JSBI.BigInt(10000000000000),
71
- },
72
- {
73
- index: nearestUsableTick(TickMath.MAX_TICK, TICK_SPACINGS[FeeAmount.MEDIUM]),
74
- liquidityNet: JSBI.multiply(JSBI.BigInt(10000000000000), JSBI.BigInt(-1)),
75
- liquidityGross: JSBI.BigInt(10000000000000),
76
- },
77
- ]);
78
- const pool_v4_1_weth = new V4Pool(token1, WETH9[1], FeeAmount.MEDIUM, 60, ADDRESS_ZERO, SQRT_RATIO_ONE, JSBI.BigInt(10000000000000), 0, [
79
- {
80
- index: nearestUsableTick(TickMath.MIN_TICK, TICK_SPACINGS[FeeAmount.MEDIUM]),
81
- liquidityNet: JSBI.BigInt(10000000000000),
82
- liquidityGross: JSBI.BigInt(10000000000000),
83
- },
84
- {
85
- index: nearestUsableTick(TickMath.MAX_TICK, TICK_SPACINGS[FeeAmount.MEDIUM]),
86
- liquidityNet: JSBI.multiply(JSBI.BigInt(10000000000000), JSBI.BigInt(-1)),
87
- liquidityGross: JSBI.BigInt(10000000000000),
88
- },
89
- ]);
90
- describe('#fromRoute', () => {
91
- it('can contain only a v3 route', () => __awaiter(void 0, void 0, void 0, function* () {
92
- const routeOriginal = new V3RouteSDK([pool_0_1], token0, token1);
93
- const route = new RouteV3(routeOriginal);
94
- const amount = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(1000));
95
- const tradeType = TradeType.EXACT_INPUT;
96
- const expectedOut = yield pool_0_1.getOutputAmount(amount);
97
- const trade = yield Trade.fromRoute(route, amount, tradeType);
98
- expect(trade.inputAmount.currency).toEqual(token0);
99
- expect(trade.outputAmount.currency).toEqual(token1);
100
- expect(trade.inputAmount).toEqual(amount);
101
- expect(trade.outputAmount).toEqual(expectedOut[0]);
102
- expect(trade.swaps.length).toEqual(1);
103
- expect(trade.routes.length).toEqual(1);
104
- expect(trade.tradeType).toEqual(TradeType.EXACT_INPUT);
105
- expect(trade.amounts.inputAmountNative).toEqual(undefined);
106
- expect(trade.amounts.outputAmountNative).toEqual(undefined);
107
- }));
108
- it('can contain only a v2 route', () => __awaiter(void 0, void 0, void 0, function* () {
109
- const routeOriginal = new V2RouteSDK([pair_0_1], token0, token1);
110
- const route = new RouteV2(routeOriginal);
111
- const amount = CurrencyAmount.fromRawAmount(token1, JSBI.BigInt(1000));
112
- const tradeType = TradeType.EXACT_OUTPUT;
113
- const expectedIn = pair_0_1.getInputAmount(amount)[0];
114
- const trade = yield Trade.fromRoute(route, amount, tradeType);
115
- expect(trade.inputAmount.currency).toEqual(token0);
116
- expect(trade.outputAmount.currency).toEqual(token1);
117
- expect(trade.outputAmount).toEqual(amount);
118
- expect(trade.inputAmount).toEqual(expectedIn);
119
- expect(trade.swaps.length).toEqual(1);
120
- expect(trade.routes.length).toEqual(1);
121
- expect(trade.tradeType).toEqual(TradeType.EXACT_OUTPUT);
122
- expect(trade.amounts.inputAmountNative).toEqual(undefined);
123
- expect(trade.amounts.outputAmountNative).toEqual(undefined);
124
- }));
125
- it('can contain only a mixed route', () => __awaiter(void 0, void 0, void 0, function* () {
126
- const routeOriginal = new MixedRouteSDK([pool_0_1], token0, token1);
127
- const route = new MixedRoute(routeOriginal);
128
- const amount = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(1000));
129
- const tradeType = TradeType.EXACT_INPUT;
130
- const expectedOut = yield pool_0_1.getOutputAmount(amount);
131
- const trade = yield Trade.fromRoute(route, amount, tradeType);
132
- expect(trade.inputAmount.currency).toEqual(token0);
133
- expect(trade.outputAmount.currency).toEqual(token1);
134
- expect(trade.inputAmount).toEqual(amount);
135
- expect(trade.outputAmount).toEqual(expectedOut[0]);
136
- expect(trade.swaps.length).toEqual(1);
137
- expect(trade.routes.length).toEqual(1);
138
- expect(trade.tradeType).toEqual(TradeType.EXACT_INPUT);
139
- expect(trade.amounts.inputAmountNative).toEqual(undefined);
140
- expect(trade.amounts.outputAmountNative).toEqual(undefined);
141
- }));
142
- it('can be constructed with ETHER as input for a V3 Route exact input swap', () => __awaiter(void 0, void 0, void 0, function* () {
143
- var _a;
144
- const routeOriginal = new V3RouteSDK([pool_weth_0], ETHER, token0);
145
- const route = new RouteV3(routeOriginal);
146
- const amount = CurrencyAmount.fromRawAmount(ETHER, JSBI.BigInt(10));
147
- const trade = yield Trade.fromRoute(route, amount, TradeType.EXACT_INPUT);
148
- expect(trade.inputAmount.currency).toEqual(ETHER);
149
- expect(trade.outputAmount.currency).toEqual(token0);
150
- expect(trade.amounts.inputAmountNative).toBeDefined();
151
- expect((_a = trade.amounts.inputAmountNative) === null || _a === void 0 ? void 0 : _a.equalTo(0)).toBe(true);
152
- expect(trade.amounts.outputAmountNative).toEqual(undefined);
153
- }));
154
- it('can be constructed with ETHER as input for a V3 Route exact output swap', () => __awaiter(void 0, void 0, void 0, function* () {
155
- var _b;
156
- const routeOriginal = new V3RouteSDK([pool_weth_0], ETHER, token0);
157
- const route = new RouteV3(routeOriginal);
158
- const amount = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100));
159
- const trade = yield Trade.fromRoute(route, amount, TradeType.EXACT_OUTPUT);
160
- expect(trade.inputAmount.currency).toEqual(ETHER);
161
- expect(trade.outputAmount.currency).toEqual(token0);
162
- expect(trade.amounts.inputAmountNative).toBeDefined();
163
- expect((_b = trade.amounts.inputAmountNative) === null || _b === void 0 ? void 0 : _b.equalTo(0)).toBe(true);
164
- expect(trade.amounts.outputAmountNative).toEqual(undefined);
165
- }));
166
- it('can be constructed with ETHER as output for a V3 Route exact output swap', () => __awaiter(void 0, void 0, void 0, function* () {
167
- var _c;
168
- const routeOriginal = new V3RouteSDK([pool_weth_0], token0, ETHER);
169
- const route = new RouteV3(routeOriginal);
170
- const amount = CurrencyAmount.fromRawAmount(ETHER, JSBI.BigInt(100));
171
- const expectedIn = yield pool_weth_0.getInputAmount(amount.wrapped);
172
- const trade = yield Trade.fromRoute(route, amount, TradeType.EXACT_OUTPUT);
173
- expect(trade.inputAmount.currency).toEqual(token0);
174
- expect(trade.outputAmount.currency).toEqual(ETHER);
175
- expect(trade.outputAmount).toEqual(amount);
176
- expect(trade.inputAmount).toEqual(expectedIn[0]);
177
- expect(trade.amounts.outputAmountNative).toBeDefined();
178
- expect((_c = trade.amounts.outputAmountNative) === null || _c === void 0 ? void 0 : _c.equalTo(0)).toBe(true);
179
- expect(trade.amounts.inputAmountNative).toEqual(undefined);
180
- }));
181
- it('can be constructed with ETHER as output for a V3 Route exact input swap', () => __awaiter(void 0, void 0, void 0, function* () {
182
- var _d;
183
- const routeOriginal = new V3RouteSDK([pool_weth_0], token0, ETHER);
184
- const route = new RouteV3(routeOriginal);
185
- const amount = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100));
186
- const expectedOut = yield pool_weth_0.getOutputAmount(amount);
187
- const trade = yield Trade.fromRoute(route, amount, TradeType.EXACT_INPUT);
188
- expect(trade.inputAmount.currency).toEqual(token0);
189
- expect(trade.outputAmount.currency).toEqual(ETHER);
190
- expect(trade.inputAmount).toEqual(amount);
191
- expect(trade.outputAmount.wrapped).toEqual(expectedOut[0]);
192
- expect(trade.amounts.outputAmountNative).toBeDefined();
193
- expect((_d = trade.amounts.outputAmountNative) === null || _d === void 0 ? void 0 : _d.equalTo(0)).toBe(true);
194
- expect(trade.amounts.inputAmountNative).toEqual(undefined);
195
- }));
196
- it('can be constructed with ETHER as input for a V2 Route exact input swap', () => __awaiter(void 0, void 0, void 0, function* () {
197
- var _e;
198
- const routeOriginal = new V2RouteSDK([pair_weth_2], ETHER, token2);
199
- const route = new RouteV2(routeOriginal);
200
- const amount = CurrencyAmount.fromRawAmount(ETHER, JSBI.BigInt(10));
201
- const trade = yield Trade.fromRoute(route, amount, TradeType.EXACT_INPUT);
202
- expect(trade.inputAmount.currency).toEqual(ETHER);
203
- expect(trade.outputAmount.currency).toEqual(token2);
204
- expect(trade.amounts.inputAmountNative).toBeDefined();
205
- expect((_e = trade.amounts.inputAmountNative) === null || _e === void 0 ? void 0 : _e.equalTo(0)).toBe(true);
206
- expect(trade.amounts.outputAmountNative).toEqual(undefined);
207
- }));
208
- it('can be constructed with ETHER as input for a V2 Route exact output swap', () => __awaiter(void 0, void 0, void 0, function* () {
209
- var _f;
210
- const routeOriginal = new V2RouteSDK([pair_weth_2], ETHER, token2);
211
- const route = new RouteV2(routeOriginal);
212
- const amount = CurrencyAmount.fromRawAmount(token2, JSBI.BigInt(100));
213
- const trade = yield Trade.fromRoute(route, amount, TradeType.EXACT_OUTPUT);
214
- expect(trade.inputAmount.currency).toEqual(ETHER);
215
- expect(trade.outputAmount.currency).toEqual(token2);
216
- expect(trade.amounts.inputAmountNative).toBeDefined();
217
- expect((_f = trade.amounts.inputAmountNative) === null || _f === void 0 ? void 0 : _f.equalTo(0)).toBe(true);
218
- expect(trade.amounts.outputAmountNative).toEqual(undefined);
219
- }));
220
- it('can be constructed with ETHER as output for a V2 Route exact output swap', () => __awaiter(void 0, void 0, void 0, function* () {
221
- var _g;
222
- const routeOriginal = new V2RouteSDK([pair_weth_2], token2, ETHER);
223
- const route = new RouteV2(routeOriginal);
224
- const amount = CurrencyAmount.fromRawAmount(ETHER, JSBI.BigInt(100));
225
- const trade = yield Trade.fromRoute(route, amount, TradeType.EXACT_OUTPUT);
226
- expect(trade.inputAmount.currency).toEqual(token2);
227
- expect(trade.outputAmount.currency).toEqual(ETHER);
228
- expect(trade.amounts.outputAmountNative).toBeDefined();
229
- expect((_g = trade.amounts.outputAmountNative) === null || _g === void 0 ? void 0 : _g.equalTo(0)).toBe(true);
230
- expect(trade.amounts.inputAmountNative).toEqual(undefined);
231
- }));
232
- it('can be constructed with ETHER as output for a V2 Route exact input swap', () => __awaiter(void 0, void 0, void 0, function* () {
233
- var _h;
234
- const routeOriginal = new V2RouteSDK([pair_weth_2], token2, ETHER);
235
- const route = new RouteV2(routeOriginal);
236
- const amount = CurrencyAmount.fromRawAmount(token2, JSBI.BigInt(100));
237
- const trade = yield Trade.fromRoute(route, amount, TradeType.EXACT_INPUT);
238
- expect(trade.inputAmount.currency).toEqual(token2);
239
- expect(trade.outputAmount.currency).toEqual(ETHER);
240
- expect(trade.amounts.outputAmountNative).toBeDefined();
241
- expect((_h = trade.amounts.outputAmountNative) === null || _h === void 0 ? void 0 : _h.equalTo(0)).toBe(true);
242
- expect(trade.amounts.inputAmountNative).toEqual(undefined);
243
- }));
244
- it('can be constructed with ETHER as input for a Mixed Route exact input swap', () => __awaiter(void 0, void 0, void 0, function* () {
245
- var _j;
246
- const routeOriginal = new MixedRouteSDK([pool_weth_0], ETHER, token0);
247
- const route = new MixedRoute(routeOriginal);
248
- const amount = CurrencyAmount.fromRawAmount(ETHER, JSBI.BigInt(10));
249
- const trade = yield Trade.fromRoute(route, amount, TradeType.EXACT_INPUT);
250
- expect(trade.inputAmount.currency).toEqual(ETHER);
251
- expect(trade.outputAmount.currency).toEqual(token0);
252
- expect(trade.amounts.inputAmountNative).toBeDefined();
253
- expect((_j = trade.amounts.inputAmountNative) === null || _j === void 0 ? void 0 : _j.equalTo(0)).toBe(true);
254
- expect(trade.amounts.outputAmountNative).toEqual(undefined);
255
- }));
256
- it('can be constructed with ETHER as output for a Mixed Route exact input swap', () => __awaiter(void 0, void 0, void 0, function* () {
257
- var _k;
258
- const routeOriginal = new MixedRouteSDK([pool_weth_0], token0, ETHER);
259
- const route = new MixedRoute(routeOriginal);
260
- const amount = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100));
261
- const expectedOut = yield pool_weth_0.getOutputAmount(amount);
262
- const trade = yield Trade.fromRoute(route, amount, TradeType.EXACT_INPUT);
263
- expect(trade.inputAmount.currency).toEqual(token0);
264
- expect(trade.outputAmount.currency).toEqual(ETHER);
265
- expect(trade.inputAmount).toEqual(amount);
266
- expect(trade.outputAmount.wrapped).toEqual(expectedOut[0]);
267
- expect(trade.amounts.outputAmountNative).toBeDefined();
268
- expect((_k = trade.amounts.outputAmountNative) === null || _k === void 0 ? void 0 : _k.equalTo(0)).toBe(true);
269
- expect(trade.amounts.inputAmountNative).toEqual(undefined);
270
- }));
271
- it('throws if input currency does not match for V2 Route', () => __awaiter(void 0, void 0, void 0, function* () {
272
- const routeOriginal = new V2RouteSDK([pair_weth_2], token2, ETHER);
273
- const route = new RouteV2(routeOriginal);
274
- const amount = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100));
275
- yield expect(Trade.fromRoute(route, amount, TradeType.EXACT_INPUT)).rejects.toThrow('INPUT');
276
- }));
277
- it('throws if output currency does not match for V2 Route', () => __awaiter(void 0, void 0, void 0, function* () {
278
- const routeOriginal = new V2RouteSDK([pair_0_1], token0, token1);
279
- const route = new RouteV2(routeOriginal);
280
- const amount = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100));
281
- yield expect(Trade.fromRoute(route, amount, TradeType.EXACT_OUTPUT)).rejects.toThrow('OUTPUT');
282
- }));
283
- it('throws if input currency does not match for V3 route', () => __awaiter(void 0, void 0, void 0, function* () {
284
- const routeOriginal = new V3RouteSDK([pool_0_1], token0, token1);
285
- const route = new RouteV3(routeOriginal);
286
- const amount = CurrencyAmount.fromRawAmount(token2, JSBI.BigInt(1000));
287
- const tradeType = TradeType.EXACT_INPUT;
288
- yield expect(Trade.fromRoute(route, amount, tradeType)).rejects.toThrow('INPUT');
289
- }));
290
- it('throws if output currency does not match for V3 route', () => __awaiter(void 0, void 0, void 0, function* () {
291
- const routeOriginal = new V3RouteSDK([pool_0_1], token0, token1);
292
- const route = new RouteV3(routeOriginal);
293
- const amount = CurrencyAmount.fromRawAmount(token2, JSBI.BigInt(1000));
294
- const tradeType = TradeType.EXACT_OUTPUT;
295
- yield expect(Trade.fromRoute(route, amount, tradeType)).rejects.toThrow('OUTPUT');
296
- }));
297
- it('throws if input currency does not match for Mixed route', () => __awaiter(void 0, void 0, void 0, function* () {
298
- const routeOriginal = new MixedRouteSDK([pool_0_1], token0, token1);
299
- const route = new MixedRoute(routeOriginal);
300
- const amount = CurrencyAmount.fromRawAmount(token2, JSBI.BigInt(1000));
301
- const tradeType = TradeType.EXACT_INPUT;
302
- yield expect(Trade.fromRoute(route, amount, tradeType)).rejects.toThrow('INPUT');
303
- }));
304
- });
305
- describe('#fromRoutes', () => {
306
- it('can contain both a v2 and a v3 route', () => __awaiter(void 0, void 0, void 0, function* () {
307
- const routeOriginalV2 = new V2RouteSDK([pair_0_1, pair_1_2], token0, token2);
308
- const routev2 = new RouteV2(routeOriginalV2);
309
- const amountv2 = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100));
310
- const routeOriginalV3 = new V3RouteSDK([pool_0_1, pool_1_2], token0, token2);
311
- const routev3 = new RouteV3(routeOriginalV3);
312
- const amountv3 = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(1000));
313
- const amountIn = amountv2.add(amountv3);
314
- const outv2 = pair_1_2.getOutputAmount(pair_0_1.getOutputAmount(amountv2)[0])[0];
315
- const out1v3 = yield pool_0_1.getOutputAmount(amountv3);
316
- const out2v3 = yield pool_1_2.getOutputAmount(out1v3[0]);
317
- const expectedOut = outv2.add(out2v3[0]);
318
- const trade = yield Trade.fromRoutes([{ routev2, amount: amountv2 }], [{ routev3, amount: amountv3 }], TradeType.EXACT_INPUT);
319
- expect(trade.inputAmount.currency).toEqual(token0);
320
- expect(trade.outputAmount.currency).toEqual(token2);
321
- expect(trade.inputAmount).toEqual(amountIn);
322
- expect(trade.outputAmount).toEqual(expectedOut);
323
- expect(trade.swaps.length).toEqual(2);
324
- expect(trade.routes.length).toEqual(2);
325
- expect(trade.tradeType).toEqual(TradeType.EXACT_INPUT);
326
- }));
327
- it('can contain a v2, a v3, and a mixed route', () => __awaiter(void 0, void 0, void 0, function* () {
328
- const routeOriginalV2 = new V2RouteSDK([pair_0_1, pair_1_2], token0, token2);
329
- const routev2 = new RouteV2(routeOriginalV2);
330
- const amountv2 = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100));
331
- const routeOriginalV3 = new V3RouteSDK([pool_0_1, pool_1_2], token0, token2);
332
- const routev3 = new RouteV3(routeOriginalV3);
333
- const amountv3 = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(1000));
334
- const mixedRouteOriginal = new MixedRouteSDK([pool_weth_0, pair_weth_2], token0, token2);
335
- const mixedRoute = new MixedRoute(mixedRouteOriginal);
336
- const amountMixedRoute = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(1000));
337
- const amountIn = amountv2.add(amountv3).add(amountMixedRoute);
338
- const outv2 = pair_1_2.getOutputAmount(pair_0_1.getOutputAmount(amountv2)[0])[0];
339
- const out1v3 = yield pool_0_1.getOutputAmount(amountv3);
340
- const out2v3 = yield pool_1_2.getOutputAmount(out1v3[0]);
341
- const out1mixed = yield pool_weth_0.getOutputAmount(amountMixedRoute);
342
- const out2mixed = pair_weth_2.getOutputAmount(out1mixed[0])[0];
343
- const expectedOut = outv2.add(out2v3[0]).add(out2mixed);
344
- const trade = yield Trade.fromRoutes([{ routev2, amount: amountv2 }], [{ routev3, amount: amountv3 }], TradeType.EXACT_INPUT, [{ mixedRoute, amount: amountMixedRoute }]);
345
- expect(trade.inputAmount.currency).toEqual(token0);
346
- expect(trade.outputAmount.currency).toEqual(token2);
347
- expect(trade.inputAmount).toEqual(amountIn);
348
- expect(trade.outputAmount).toEqual(expectedOut);
349
- expect(trade.swaps.length).toEqual(3);
350
- expect(trade.routes.length).toEqual(3);
351
- expect(trade.tradeType).toEqual(TradeType.EXACT_INPUT);
352
- }));
353
- it('can contain multiple v2, v3, and mixed routes', () => __awaiter(void 0, void 0, void 0, function* () {
354
- const routeOriginalV2 = new V2RouteSDK([pair_0_1, pair_1_2], token0, token2);
355
- const routev2 = new RouteV2(routeOriginalV2);
356
- const amountv2 = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100));
357
- const routeOriginalV3 = new V3RouteSDK([pool_0_1, pool_1_2], token0, token2);
358
- const routev3 = new RouteV3(routeOriginalV3);
359
- const amountv3 = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(1000));
360
- const mixedRouteOriginal = new MixedRouteSDK([pool_weth_0, pair_weth_2], token0, token2);
361
- const mixedRoute = new MixedRoute(mixedRouteOriginal);
362
- const amountMixedRoute = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(1000));
363
- const mixedRoute2Original = new MixedRouteSDK([pool_0_3, pair_2_3], token0, token2);
364
- const mixedRoute2 = new MixedRoute(mixedRoute2Original);
365
- const amountMixedRoute2 = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(1000));
366
- const amountIn = amountv2.add(amountv3).add(amountMixedRoute).add(amountMixedRoute2);
367
- const outv2 = pair_1_2.getOutputAmount(pair_0_1.getOutputAmount(amountv2)[0])[0];
368
- const out1v3 = yield pool_0_1.getOutputAmount(amountv3);
369
- const out2v3 = yield pool_1_2.getOutputAmount(out1v3[0]);
370
- const out1mixed = yield pool_weth_0.getOutputAmount(amountMixedRoute);
371
- const out2mixed = pair_weth_2.getOutputAmount(out1mixed[0])[0];
372
- const out1mixed2 = yield pool_0_3.getOutputAmount(amountMixedRoute2);
373
- const out2mixed2 = pair_2_3.getOutputAmount(out1mixed2[0])[0];
374
- const expectedOut = outv2.add(out2v3[0]).add(out2mixed).add(out2mixed2);
375
- const trade = yield Trade.fromRoutes([{ routev2, amount: amountv2 }], [{ routev3, amount: amountv3 }], TradeType.EXACT_INPUT, [
376
- { mixedRoute, amount: amountMixedRoute },
377
- { mixedRoute: mixedRoute2, amount: amountMixedRoute2 },
378
- ]);
379
- expect(trade.inputAmount.currency).toEqual(token0);
380
- expect(trade.outputAmount.currency).toEqual(token2);
381
- expect(trade.inputAmount).toEqual(amountIn);
382
- expect(trade.outputAmount).toEqual(expectedOut);
383
- expect(trade.swaps.length).toEqual(4);
384
- expect(trade.routes.length).toEqual(4);
385
- expect(trade.tradeType).toEqual(TradeType.EXACT_INPUT);
386
- }));
387
- it('can contain muliptle v2 and v3 routes', () => __awaiter(void 0, void 0, void 0, function* () {
388
- const routeOriginalV2 = new V2RouteSDK([pair_0_1, pair_1_2], token0, token2);
389
- const routev2 = new RouteV2(routeOriginalV2);
390
- const amountv2 = CurrencyAmount.fromRawAmount(token2, JSBI.BigInt(100));
391
- const route2OriginalV2 = new V2RouteSDK([pair_weth_0, pair_weth_2], token0, token2);
392
- const route2v2 = new RouteV2(route2OriginalV2);
393
- const amount2v2 = CurrencyAmount.fromRawAmount(token2, JSBI.BigInt(1000));
394
- const routeOriginalV3 = new V3RouteSDK([pool_0_1, pool_1_2], token0, token2);
395
- const routev3 = new RouteV3(routeOriginalV3);
396
- const amountv3 = CurrencyAmount.fromRawAmount(token2, JSBI.BigInt(1000));
397
- const route2OriginalV3 = new V3RouteSDK([pool_weth_0, pool_weth_2], token0, token2);
398
- const route2v3 = new RouteV3(route2OriginalV3);
399
- const amount2v3 = CurrencyAmount.fromRawAmount(token2, JSBI.BigInt(1000));
400
- const amountOutExpected = amountv2.add(amount2v2).add(amountv3).add(amount2v3);
401
- // calculate expected amount in across v2
402
- const amountIn1v2 = pair_0_1.getInputAmount(pair_1_2.getInputAmount(amountv2)[0]);
403
- const amountIn2v2 = pair_weth_0.getInputAmount(pair_weth_2.getInputAmount(amount2v2)[0]);
404
- // calculate expected amount in across v3
405
- const amountIn1v3 = yield pool_1_2.getInputAmount(amountv3);
406
- const amountIn2v3 = yield pool_0_1.getInputAmount(amountIn1v3[0]);
407
- const amountIn3v3 = yield pool_weth_2.getInputAmount(amount2v3);
408
- const amountIn4v3 = yield pool_weth_0.getInputAmount(amountIn3v3[0]);
409
- // calculate total expected amount in
410
- const expectedIn = amountIn1v2[0].add(amountIn2v2[0]).add(amountIn2v3[0]).add(amountIn4v3[0]);
411
- const trade = yield Trade.fromRoutes([
412
- { routev2, amount: amountv2 },
413
- { routev2: route2v2, amount: amount2v2 },
414
- ], [
415
- { routev3, amount: amountv3 },
416
- { routev3: route2v3, amount: amount2v3 },
417
- ], TradeType.EXACT_OUTPUT);
418
- expect(trade.inputAmount.currency).toEqual(token0);
419
- expect(trade.outputAmount.currency).toEqual(token2);
420
- expect(trade.outputAmount).toEqual(amountOutExpected);
421
- expect(trade.inputAmount).toEqual(expectedIn);
422
- expect(trade.swaps.length).toEqual(4);
423
- expect(trade.routes.length).toEqual(4);
424
- expect(trade.tradeType).toEqual(TradeType.EXACT_OUTPUT);
425
- expect(trade.routes[0].path).toEqual([token0, token1, token2]);
426
- expect(trade.routes[1].path).toEqual([token0, weth, token2]);
427
- expect(trade.routes[2].path).toEqual([token0, token1, token2]);
428
- expect(trade.routes[3].path).toEqual([token0, weth, token2]);
429
- }));
430
- it('can be constructed with ETHER as input for exact input', () => __awaiter(void 0, void 0, void 0, function* () {
431
- const routeOriginalV2 = new V2RouteSDK([pair_weth_0, pair_0_1], ETHER, token1);
432
- const routev2 = new RouteV2(routeOriginalV2);
433
- const amountv2 = CurrencyAmount.fromRawAmount(ETHER, JSBI.BigInt(100));
434
- const routeOriginalV3 = new V3RouteSDK([pool_weth_0, pool_0_1], ETHER, token1);
435
- const routev3 = new RouteV3(routeOriginalV3);
436
- const amountv3 = CurrencyAmount.fromRawAmount(ETHER, JSBI.BigInt(1000));
437
- const mixedRouteOriginal = new MixedRouteSDK([pool_weth_2, pair_1_2], ETHER, token1);
438
- const mixedRoute = new MixedRoute(mixedRouteOriginal);
439
- const amountMixedRoute = CurrencyAmount.fromRawAmount(ETHER, JSBI.BigInt(1000));
440
- const trade = yield Trade.fromRoutes([{ routev2, amount: amountv2 }], [{ routev3, amount: amountv3 }], TradeType.EXACT_INPUT, [{ mixedRoute, amount: amountMixedRoute }]);
441
- expect(trade.inputAmount.currency).toEqual(ETHER);
442
- expect(trade.outputAmount.currency).toEqual(token1);
443
- expect(trade.swaps.length).toEqual(3);
444
- // Expect all input amounts to be native
445
- expect(trade.swaps.every((swap) => swap.inputAmount.currency.isNative)).toBe(true);
446
- // Expect all route inputs to be ETH
447
- expect(trade.swaps.every((swap) => swap.route.input.isNative)).toBe(true);
448
- // Expect all route path inputs to be WETH, can't use pathInput because not supported in older SDKs
449
- expect(trade.swaps.every((swap) => swap.route.pools[0].involvesToken(weth))).toBe(true);
450
- expect(trade.routes.length).toEqual(3);
451
- expect(trade.tradeType).toEqual(TradeType.EXACT_INPUT);
452
- }));
453
- it('can be constructed with ETHER as input for exact output', () => __awaiter(void 0, void 0, void 0, function* () {
454
- const routeOriginalV2 = new V2RouteSDK([pair_weth_0, pair_0_1], ETHER, token1);
455
- const routev2 = new RouteV2(routeOriginalV2);
456
- const amountv2 = CurrencyAmount.fromRawAmount(token1, JSBI.BigInt(100));
457
- const routeOriginalV3 = new V3RouteSDK([pool_weth_0, pool_0_1], ETHER, token1);
458
- const routev3 = new RouteV3(routeOriginalV3);
459
- const amountv3 = CurrencyAmount.fromRawAmount(token1, JSBI.BigInt(1000));
460
- const trade = yield Trade.fromRoutes([{ routev2, amount: amountv2 }], [{ routev3, amount: amountv3 }], TradeType.EXACT_OUTPUT);
461
- expect(trade.inputAmount.currency).toEqual(ETHER);
462
- expect(trade.outputAmount.currency).toEqual(token1);
463
- expect(trade.swaps.length).toEqual(2);
464
- expect(trade.routes.length).toEqual(2);
465
- expect(trade.tradeType).toEqual(TradeType.EXACT_OUTPUT);
466
- }));
467
- it('can be constructed with ETHER as output for exact output swap', () => __awaiter(void 0, void 0, void 0, function* () {
468
- const routeOriginalV2 = new V2RouteSDK([pair_0_1, pair_weth_0], token1, ETHER);
469
- const routev2 = new RouteV2(routeOriginalV2);
470
- const amountv2 = CurrencyAmount.fromRawAmount(ETHER, JSBI.BigInt(100));
471
- const routeOriginalV3 = new V3RouteSDK([pool_0_1, pool_weth_0], token1, ETHER);
472
- const routev3 = new RouteV3(routeOriginalV3);
473
- const amountv3 = CurrencyAmount.fromRawAmount(ETHER, JSBI.BigInt(1000));
474
- const trade = yield Trade.fromRoutes([{ routev2, amount: amountv2 }], [{ routev3, amount: amountv3 }], TradeType.EXACT_OUTPUT);
475
- expect(trade.inputAmount.currency).toEqual(token1);
476
- expect(trade.outputAmount.currency).toEqual(ETHER);
477
- expect(trade.swaps.length).toEqual(2);
478
- expect(trade.routes.length).toEqual(2);
479
- expect(trade.tradeType).toEqual(TradeType.EXACT_OUTPUT);
480
- }));
481
- it('can be constructed with ETHER as output for exact input swap', () => __awaiter(void 0, void 0, void 0, function* () {
482
- const routeOriginalV2 = new V2RouteSDK([pair_0_1, pair_weth_0], token1, ETHER);
483
- const routev2 = new RouteV2(routeOriginalV2);
484
- const amountv2 = CurrencyAmount.fromRawAmount(token1, JSBI.BigInt(100));
485
- const routeOriginalV3 = new V3RouteSDK([pool_0_1, pool_weth_0], token1, ETHER);
486
- const routev3 = new RouteV3(routeOriginalV3);
487
- const amountv3 = CurrencyAmount.fromRawAmount(token1, JSBI.BigInt(1000));
488
- const mixedRouteOriginal = new MixedRouteSDK([pair_1_2, pool_weth_2], token1, ETHER);
489
- const mixedRoute = new MixedRoute(mixedRouteOriginal);
490
- const amountMixedRoute = CurrencyAmount.fromRawAmount(token1, JSBI.BigInt(1000));
491
- const trade = yield Trade.fromRoutes([{ routev2, amount: amountv2 }], [{ routev3, amount: amountv3 }], TradeType.EXACT_INPUT, [{ mixedRoute, amount: amountMixedRoute }]);
492
- expect(trade.inputAmount.currency).toEqual(token1);
493
- expect(trade.outputAmount.currency).toEqual(ETHER);
494
- expect(trade.swaps.length).toEqual(3);
495
- expect(trade.routes.length).toEqual(3);
496
- expect(trade.tradeType).toEqual(TradeType.EXACT_INPUT);
497
- }));
498
- it('can be constructed with ETHER as input for exact input swap, with V4 eth route and V2 weth route', () => __awaiter(void 0, void 0, void 0, function* () {
499
- var _a;
500
- const routeOriginalV2 = new V2RouteSDK([pair_weth_0, pair_0_1], ETHER, token1);
501
- const routev2 = new RouteV2(routeOriginalV2);
502
- const amountv2 = CurrencyAmount.fromRawAmount(ETHER, JSBI.BigInt(100));
503
- const routeOriginalV4 = new V4RouteSDK([pool_v4_1_eth], ETHER, token1);
504
- const routev4 = new RouteV4(routeOriginalV4);
505
- const amountv4 = CurrencyAmount.fromRawAmount(ETHER, JSBI.BigInt(1000));
506
- const trade = yield Trade.fromRoutes([{ routev2, amount: amountv2 }], [], TradeType.EXACT_INPUT, [], [{ routev4, amount: amountv4 }]);
507
- expect(trade.tradeType).toEqual(TradeType.EXACT_INPUT);
508
- expect(trade.inputAmount.currency).toEqual(ETHER);
509
- expect(trade.outputAmount.currency).toEqual(token1);
510
- expect(trade.swaps.length).toEqual(2);
511
- expect(trade.routes.length).toEqual(2);
512
- // Expect all swap input amounts to be native
513
- expect(trade.swaps.every((swap) => swap.inputAmount.currency.isNative)).toBe(true);
514
- // Expect all route inputs to be ETH
515
- expect(trade.swaps.every((swap) => swap.route.input.isNative)).toBe(true);
516
- // However, expect the routes to be preserved (v2 using WETH and v4 using ETH)
517
- expect(trade.swaps[0].route.pathInput).toEqual(weth);
518
- expect(trade.swaps[1].route.pathInput).toEqual(ETHER);
519
- // Expect inputAmount to be the sum of the input amounts of the swaps
520
- expect(trade.amounts.inputAmount.equalTo(trade.amounts.inputAmount)).toBe(true);
521
- expect(trade.amounts.inputAmount.equalTo(amountv2.add(amountv4))).toBe(true);
522
- // Expect inputAmountNative to correctly track only the amount required for the ETH input V4 route
523
- expect(trade.amounts.inputAmountNative).toBeDefined();
524
- expect((_a = trade.amounts.inputAmountNative) === null || _a === void 0 ? void 0 : _a.equalTo(amountv4)).toBe(true);
525
- // Expect outputAmount to be the sum of the output amounts of the swaps
526
- expect(trade.amounts.outputAmount.equalTo(trade.amounts.outputAmount)).toBe(true);
527
- // Expect outputAmountNative to be undefined because there is no ETH output path
528
- expect(trade.amounts.outputAmountNative).toBeUndefined();
529
- }));
530
- it('can be constructed with ETHER as input for exact output swap, with V4 eth route and V2 weth route', () => __awaiter(void 0, void 0, void 0, function* () {
531
- var _b;
532
- const routeOriginalV2 = new V2RouteSDK([pair_weth_0, pair_0_1], ETHER, token1);
533
- const routev2 = new RouteV2(routeOriginalV2);
534
- const amountv2 = CurrencyAmount.fromRawAmount(token1, JSBI.BigInt(100));
535
- const routeOriginalV4 = new V4RouteSDK([pool_v4_1_eth], ETHER, token1);
536
- const routev4 = new RouteV4(routeOriginalV4);
537
- const amountv4 = CurrencyAmount.fromRawAmount(token1, JSBI.BigInt(1000));
538
- const trade = yield Trade.fromRoutes([{ routev2, amount: amountv2 }], [], TradeType.EXACT_OUTPUT, [], [{ routev4, amount: amountv4 }]);
539
- expect(trade.tradeType).toEqual(TradeType.EXACT_OUTPUT);
540
- expect(trade.inputAmount.currency).toEqual(ETHER);
541
- expect(trade.outputAmount.currency).toEqual(token1);
542
- expect(trade.swaps.length).toEqual(2);
543
- expect(trade.routes.length).toEqual(2);
544
- // Expect all swap input amounts to be native
545
- expect(trade.swaps.every((swap) => swap.inputAmount.currency.isNative)).toBe(true);
546
- // Expect all route inputs to be ETH
547
- expect(trade.swaps.every((swap) => swap.route.input.isNative)).toBe(true);
548
- // However, expect the routes to be preserved (v2 using WETH and v4 using ETH)
549
- expect(trade.swaps[0].route.pathInput).toEqual(weth);
550
- expect(trade.swaps[1].route.pathInput).toEqual(ETHER);
551
- // Expect inputAmount to be the sum of the input amounts of the swaps
552
- expect(trade.amounts.inputAmount.equalTo(trade.amounts.inputAmount)).toBe(true);
553
- // Expect inputAmountNative to correctly track only the amount required for the ETH input V4 route
554
- expect(trade.amounts.inputAmountNative).toBeDefined();
555
- expect((_b = trade.amounts.inputAmountNative) === null || _b === void 0 ? void 0 : _b.greaterThan(0)).toBe(true);
556
- // Expect outputAmount to be the sum of the output amounts of the swaps
557
- expect(trade.amounts.outputAmount.equalTo(trade.amounts.outputAmount)).toBe(true);
558
- expect(trade.amounts.outputAmount.equalTo(amountv2.add(amountv4))).toBe(true);
559
- // Expect outputAmountNative to be undefined because there is no ETH output path
560
- expect(trade.amounts.outputAmountNative).toBeUndefined();
561
- }));
562
- it('can be constructed with ETHER as output for exact input swap, with V4 eth route and V2 weth route', () => __awaiter(void 0, void 0, void 0, function* () {
563
- var _c;
564
- const routeOriginalV2 = new V2RouteSDK([pair_0_1, pair_weth_0], token1, ETHER);
565
- const routev2 = new RouteV2(routeOriginalV2);
566
- const amountv2 = CurrencyAmount.fromRawAmount(token1, JSBI.BigInt(100));
567
- const routeOriginalV4 = new V4RouteSDK([pool_v4_1_eth], token1, ETHER);
568
- const routev4 = new RouteV4(routeOriginalV4);
569
- const amountv4 = CurrencyAmount.fromRawAmount(token1, JSBI.BigInt(1000));
570
- const trade = yield Trade.fromRoutes([{ routev2, amount: amountv2 }], [], TradeType.EXACT_INPUT, [], [{ routev4, amount: amountv4 }]);
571
- expect(trade.tradeType).toEqual(TradeType.EXACT_INPUT);
572
- expect(trade.inputAmount.currency).toEqual(token1);
573
- expect(trade.outputAmount.currency).toEqual(ETHER);
574
- expect(trade.swaps.length).toEqual(2);
575
- expect(trade.routes.length).toEqual(2);
576
- // Expect all swap output amounts to be native
577
- expect(trade.swaps.every((swap) => swap.outputAmount.currency.isNative)).toBe(true);
578
- // Expect all route outputs to be ETH
579
- expect(trade.swaps.every((swap) => swap.route.output.isNative)).toBe(true);
580
- // However, expect the routes to be preserved (v2 using WETH and v4 using ETH)
581
- expect(trade.swaps[0].route.pathOutput).toEqual(weth);
582
- expect(trade.swaps[1].route.pathOutput).toEqual(ETHER);
583
- // Expect inputAmount to be the sum of the input amounts of the swaps
584
- expect(trade.amounts.inputAmount.equalTo(trade.amounts.inputAmount)).toBe(true);
585
- expect(trade.amounts.inputAmount.equalTo(amountv2.add(amountv4))).toBe(true);
586
- // Expect inputAmountNative to be undefined because there is no ETH input path
587
- expect(trade.amounts.inputAmountNative).toBeUndefined();
588
- // Expect outputAmount to be the sum of the output amounts of the swaps
589
- expect(trade.amounts.outputAmount.equalTo(trade.amounts.outputAmount)).toBe(true);
590
- // Expect outputAmountNative to correctly track only the amount required for the ETH output V4 route
591
- expect(trade.amounts.outputAmountNative).toBeDefined();
592
- expect((_c = trade.amounts.outputAmountNative) === null || _c === void 0 ? void 0 : _c.greaterThan(0)).toBe(true);
593
- }));
594
- it('can be constructed with ETHER as output for exact output swap, with V4 eth route and V2 weth route', () => __awaiter(void 0, void 0, void 0, function* () {
595
- var _d;
596
- const routeOriginalV2 = new V2RouteSDK([pair_0_1, pair_weth_0], token1, ETHER);
597
- const routev2 = new RouteV2(routeOriginalV2);
598
- const amountv2 = CurrencyAmount.fromRawAmount(ETHER, JSBI.BigInt(100));
599
- const routeOriginalV4 = new V4RouteSDK([pool_v4_1_eth], token1, ETHER);
600
- const routev4 = new RouteV4(routeOriginalV4);
601
- const amountv4 = CurrencyAmount.fromRawAmount(ETHER, JSBI.BigInt(1000));
602
- const trade = yield Trade.fromRoutes([{ routev2, amount: amountv2 }], [], TradeType.EXACT_OUTPUT, [], [{ routev4, amount: amountv4 }]);
603
- expect(trade.tradeType).toEqual(TradeType.EXACT_OUTPUT);
604
- expect(trade.inputAmount.currency).toEqual(token1);
605
- expect(trade.outputAmount.currency).toEqual(ETHER);
606
- expect(trade.swaps.length).toEqual(2);
607
- expect(trade.routes.length).toEqual(2);
608
- // Expect all swap output amounts to be native
609
- expect(trade.swaps.every((swap) => swap.outputAmount.currency.isNative)).toBe(true);
610
- // Expect all route outputs to be ETH
611
- expect(trade.swaps.every((swap) => swap.route.output.isNative)).toBe(true);
612
- // However, expect the routes to be preserved (v2 using WETH and v4 using ETH)
613
- expect(trade.swaps[0].route.pathOutput).toEqual(weth);
614
- expect(trade.swaps[1].route.pathOutput).toEqual(ETHER);
615
- // Expect inputAmount to be the sum of the input amounts of the swaps
616
- expect(trade.amounts.inputAmount.equalTo(trade.amounts.inputAmount)).toBe(true);
617
- expect(trade.amounts.inputAmount.greaterThan(0)).toBe(true);
618
- // Expect inputAmountNative to be undefined because there is no ETH input path
619
- expect(trade.amounts.inputAmountNative).toBeUndefined();
620
- // Expect outputAmount to be the sum of the output amounts of the swaps
621
- expect(trade.amounts.outputAmount.equalTo(trade.amounts.outputAmount)).toBe(true);
622
- expect(trade.amounts.outputAmount.equalTo(amountv2.add(amountv4))).toBe(true);
623
- // Expect outputAmountNative to correctly track only the amount required for the ETH output V4 route
624
- expect(trade.amounts.outputAmountNative).toBeDefined();
625
- expect((_d = trade.amounts.outputAmountNative) === null || _d === void 0 ? void 0 : _d.equalTo(amountv4)).toBe(true);
626
- }));
627
- it('throws if pools are re-used between V3 routes', () => __awaiter(void 0, void 0, void 0, function* () {
628
- const routeOriginalV2 = new V2RouteSDK([pair_0_1, pair_1_2], token0, token2);
629
- const routev2 = new RouteV2(routeOriginalV2);
630
- const amountv2 = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100));
631
- const routeOriginalV3 = new V3RouteSDK([pool_0_1, pool_1_2], token0, token2);
632
- const routev3 = new RouteV3(routeOriginalV3);
633
- const amountv3 = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(1000));
634
- //duplicate pool
635
- const route2OriginalV3 = new V3RouteSDK([pool_0_1, pool_weth_1, pool_weth_2], token0, token2);
636
- const route2v3 = new RouteV3(route2OriginalV3);
637
- const amount2v3 = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(1000));
638
- yield expect(Trade.fromRoutes([{ routev2, amount: amountv2 }], [
639
- { routev3, amount: amountv3 },
640
- { routev3: route2v3, amount: amount2v3 },
641
- ], TradeType.EXACT_INPUT)).rejects.toThrow('POOLS_DUPLICATED');
642
- }));
643
- it('throws if pools are re-used between V2 routes', () => __awaiter(void 0, void 0, void 0, function* () {
644
- const routeOriginalV2 = new V2RouteSDK([pair_0_1, pair_1_2], token0, token2);
645
- const routev2 = new RouteV2(routeOriginalV2);
646
- const amountv2 = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100));
647
- const route2OriginalV2 = new V2RouteSDK([pair_0_1, pair_weth_1, pair_weth_2], token0, token2);
648
- const route2v2 = new RouteV2(route2OriginalV2);
649
- const amount2v2 = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(1000));
650
- const routeOriginalV3 = new V3RouteSDK([pool_0_1, pool_1_2], token0, token2);
651
- const routev3 = new RouteV3(routeOriginalV3);
652
- const amountv3 = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(1000));
653
- yield expect(Trade.fromRoutes([
654
- { routev2, amount: amountv2 },
655
- { routev2: route2v2, amount: amount2v2 },
656
- ], [{ routev3, amount: amountv3 }], TradeType.EXACT_INPUT)).rejects.toThrow('POOLS_DUPLICATED');
657
- }));
658
- it('throws if pools are re-used between mixed routes and v2 routes', () => __awaiter(void 0, void 0, void 0, function* () {
659
- const routeOriginalV2 = new V2RouteSDK([pair_0_1, pair_1_2], token0, token2);
660
- const routev2 = new RouteV2(routeOriginalV2);
661
- const amountv2 = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100));
662
- const routeOriginalV3 = new V3RouteSDK([pool_0_1, pool_1_2], token0, token2);
663
- const routev3 = new RouteV3(routeOriginalV3);
664
- const amountv3 = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(1000));
665
- // mixed route which will use v2 pair again
666
- const mixedRouteOriginal = new MixedRouteSDK([pair_0_1, pool_weth_1, pool_weth_2], token0, token2);
667
- const mixedRoute = new MixedRoute(mixedRouteOriginal);
668
- const amountMixedRoute = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(1000));
669
- yield expect(Trade.fromRoutes([{ routev2, amount: amountv2 }], [{ routev3, amount: amountv3 }], TradeType.EXACT_INPUT, [
670
- { mixedRoute, amount: amountMixedRoute },
671
- ])).rejects.toThrow('POOLS_DUPLICATED');
672
- }));
673
- it('throws if pools are re-used between mixed routes and v3 routes', () => __awaiter(void 0, void 0, void 0, function* () {
674
- const routeOriginalV2 = new V2RouteSDK([pair_0_1, pair_1_2], token0, token2);
675
- const routev2 = new RouteV2(routeOriginalV2);
676
- const amountv2 = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100));
677
- const routeOriginalV3 = new V3RouteSDK([pool_0_1, pool_1_2], token0, token2);
678
- const routev3 = new RouteV3(routeOriginalV3);
679
- const amountv3 = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(1000));
680
- // mixed route which will use v3 pair again
681
- const mixedRouteOriginal = new MixedRouteSDK([pool_0_1, pair_weth_1, pool_weth_2], token0, token2);
682
- const mixedRoute = new MixedRoute(mixedRouteOriginal);
683
- const amountMixedRoute = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(1000));
684
- yield expect(Trade.fromRoutes([{ routev2, amount: amountv2 }], [{ routev3, amount: amountv3 }], TradeType.EXACT_INPUT, [
685
- { mixedRoute, amount: amountMixedRoute },
686
- ])).rejects.toThrow('POOLS_DUPLICATED');
687
- }));
688
- it('throws if routes have different inputs', () => __awaiter(void 0, void 0, void 0, function* () {
689
- const routeOriginalV2 = new V2RouteSDK([pair_1_2], token1, token2);
690
- const routev2 = new RouteV2(routeOriginalV2);
691
- const amountv2 = CurrencyAmount.fromRawAmount(token1, JSBI.BigInt(100));
692
- const routeOriginalV3 = new V3RouteSDK([pool_0_1, pool_1_2], token0, token2);
693
- const routev3 = new RouteV3(routeOriginalV3);
694
- const amountv3 = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(1000));
695
- yield expect(Trade.fromRoutes([{ routev2, amount: amountv2 }], [{ routev3, amount: amountv3 }], TradeType.EXACT_INPUT)).rejects.toThrow('INPUT_CURRENCY_MATCH');
696
- }));
697
- it('throws if routes have different inputs mixedRoute', () => __awaiter(void 0, void 0, void 0, function* () {
698
- const routeOriginalV2 = new V2RouteSDK([pair_1_2], token1, token2);
699
- const routev2 = new RouteV2(routeOriginalV2);
700
- const amountv2 = CurrencyAmount.fromRawAmount(token1, JSBI.BigInt(100));
701
- const mixedRouteOriginal = new MixedRouteSDK([pair_0_1, pool_1_2], token0, token2);
702
- const mixedRoute = new MixedRoute(mixedRouteOriginal);
703
- const amountMixedRoute = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(1000));
704
- yield expect(Trade.fromRoutes([{ routev2, amount: amountv2 }], [], TradeType.EXACT_INPUT, [
705
- { mixedRoute, amount: amountMixedRoute },
706
- ])).rejects.toThrow('INPUT_CURRENCY_MATCH');
707
- }));
708
- it('throws if routes have different outputs', () => __awaiter(void 0, void 0, void 0, function* () {
709
- const routeOriginalV2 = new V2RouteSDK([pair_0_1], token0, token1);
710
- const routev2 = new RouteV2(routeOriginalV2);
711
- const amountv2 = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100));
712
- const routeOriginalV3 = new V3RouteSDK([pool_0_1, pool_1_2], token0, token2);
713
- const routev3 = new RouteV3(routeOriginalV3);
714
- const amountv3 = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(1000));
715
- yield expect(Trade.fromRoutes([{ routev2, amount: amountv2 }], [{ routev3, amount: amountv3 }], TradeType.EXACT_INPUT)).rejects.toThrow('OUTPUT_CURRENCY_MATCH');
716
- }));
717
- it('throws if routes have different outputs mixedRoutes', () => __awaiter(void 0, void 0, void 0, function* () {
718
- const routeOriginalV3 = new V3RouteSDK([pool_0_1, pool_1_2], token0, token2);
719
- const routev3 = new RouteV3(routeOriginalV3);
720
- const amountv3 = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(1000));
721
- const mixedRouteOriginal = new MixedRouteSDK([pair_0_1, pool_weth_1], token0, weth);
722
- const mixedRoute = new MixedRoute(mixedRouteOriginal);
723
- const amountMixedRoute = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(1000));
724
- yield expect(Trade.fromRoutes([], [{ routev3, amount: amountv3 }], TradeType.EXACT_INPUT, [
725
- { mixedRoute, amount: amountMixedRoute },
726
- ])).rejects.toThrow('OUTPUT_CURRENCY_MATCH');
727
- }));
728
- it('throws if trade is created with EXACT_OUTPUT and contains mixedRoutes', () => __awaiter(void 0, void 0, void 0, function* () {
729
- const routeOriginalV2 = new V2RouteSDK([pair_weth_0, pair_0_1], ETHER, token1);
730
- const routev2 = new RouteV2(routeOriginalV2);
731
- const amountv2 = CurrencyAmount.fromRawAmount(token1, JSBI.BigInt(100));
732
- const mixedRouteOriginal = new MixedRouteSDK([pool_weth_0, pool_0_1], ETHER, token1);
733
- const mixedRoute = new MixedRoute(mixedRouteOriginal);
734
- const mixedRouteAmount = CurrencyAmount.fromRawAmount(token1, JSBI.BigInt(1000));
735
- yield expect(Trade.fromRoutes([{ routev2, amount: amountv2 }], [], TradeType.EXACT_OUTPUT, [
736
- { mixedRoute, amount: mixedRouteAmount },
737
- ])).rejects.toThrow('TRADE_TYPE');
738
- }));
739
- });
740
- describe('#worstExecutionPrice', () => {
741
- describe('tradeType = EXACT_INPUT', () => {
742
- const routev3 = new V3RouteSDK([pool_0_1, pool_1_2], token0, token2);
743
- const route2v3 = new V3RouteSDK([pool_0_2], token0, token2);
744
- const mixedRoute = new MixedRouteSDK([pool_0_1, pool_1_2], token0, token2);
745
- const mixedRoute2 = new MixedRouteSDK([pool_0_2], token0, token2);
746
- const inputAmount = CurrencyAmount.fromRawAmount(token0, 100);
747
- const outputAmount = CurrencyAmount.fromRawAmount(token2, 69);
748
- const tradeType = TradeType.EXACT_INPUT;
749
- const exactInV3 = new Trade({
750
- v2Routes: [],
751
- v3Routes: [{ routev3, inputAmount, outputAmount }],
752
- tradeType,
753
- });
754
- const exactInMixed = new Trade({
755
- v2Routes: [],
756
- v3Routes: [],
757
- tradeType,
758
- mixedRoutes: [{ mixedRoute, inputAmount, outputAmount }],
759
- });
760
- const exactInMultiRoute = new Trade({
761
- v2Routes: [],
762
- v3Routes: [
763
- {
764
- routev3,
765
- inputAmount: CurrencyAmount.fromRawAmount(token0, 50),
766
- outputAmount: CurrencyAmount.fromRawAmount(token2, 35),
767
- },
768
- {
769
- routev3: route2v3,
770
- inputAmount: CurrencyAmount.fromRawAmount(token0, 50),
771
- outputAmount: CurrencyAmount.fromRawAmount(token2, 34),
772
- },
773
- ],
774
- tradeType: TradeType.EXACT_INPUT,
775
- });
776
- const exactInMultiMixedRoute = new Trade({
777
- v2Routes: [],
778
- v3Routes: [],
779
- tradeType: TradeType.EXACT_INPUT,
780
- mixedRoutes: [
781
- {
782
- mixedRoute,
783
- inputAmount: CurrencyAmount.fromRawAmount(token0, 50),
784
- outputAmount: CurrencyAmount.fromRawAmount(token2, 35),
785
- },
786
- {
787
- mixedRoute: mixedRoute2,
788
- inputAmount: CurrencyAmount.fromRawAmount(token0, 50),
789
- outputAmount: CurrencyAmount.fromRawAmount(token2, 34),
790
- },
791
- ],
792
- });
793
- it('throws if less than 0', () => {
794
- expect(() => exactInV3.worstExecutionPrice(new Percent(-1, 100))).toThrow('SLIPPAGE_TOLERANCE');
795
- expect(() => exactInMixed.worstExecutionPrice(new Percent(-1, 100))).toThrow('SLIPPAGE_TOLERANCE');
796
- });
797
- it('returns exact if 0', () => {
798
- expect(exactInV3.worstExecutionPrice(new Percent(0, 100))).toEqual(exactInV3.executionPrice);
799
- expect(exactInMixed.worstExecutionPrice(new Percent(0, 100))).toEqual(exactInV3.executionPrice);
800
- });
801
- it('returns exact if nonzero', () => {
802
- expect(exactInV3.worstExecutionPrice(new Percent(0, 100))).toEqual(new Price(token0, token2, 100, 69));
803
- expect(exactInV3.worstExecutionPrice(new Percent(5, 100))).toEqual(new Price(token0, token2, 100, 65));
804
- expect(exactInV3.worstExecutionPrice(new Percent(200, 100))).toEqual(new Price(token0, token2, 100, 23));
805
- expect(exactInMixed.worstExecutionPrice(new Percent(0, 100))).toEqual(new Price(token0, token2, 100, 69));
806
- expect(exactInMixed.worstExecutionPrice(new Percent(5, 100))).toEqual(new Price(token0, token2, 100, 65));
807
- expect(exactInMixed.worstExecutionPrice(new Percent(200, 100))).toEqual(new Price(token0, token2, 100, 23));
808
- });
809
- it('returns exact if nonzero with multiple routes', () => {
810
- expect(exactInMultiRoute.worstExecutionPrice(new Percent(0, 100))).toEqual(new Price(token0, token2, 100, 69));
811
- expect(exactInMultiRoute.worstExecutionPrice(new Percent(5, 100))).toEqual(new Price(token0, token2, 100, 65));
812
- expect(exactInMultiRoute.worstExecutionPrice(new Percent(200, 100))).toEqual(new Price(token0, token2, 100, 23));
813
- expect(exactInMultiMixedRoute.worstExecutionPrice(new Percent(0, 100))).toEqual(new Price(token0, token2, 100, 69));
814
- expect(exactInMultiMixedRoute.worstExecutionPrice(new Percent(5, 100))).toEqual(new Price(token0, token2, 100, 65));
815
- expect(exactInMultiMixedRoute.worstExecutionPrice(new Percent(200, 100))).toEqual(new Price(token0, token2, 100, 23));
816
- });
817
- });
818
- describe('tradeType = EXACT_OUTPUT', () => {
819
- const routev3 = new V3RouteSDK([pool_0_1, pool_1_2], token0, token2);
820
- const route2v3 = new V3RouteSDK([pool_0_2], token0, token2);
821
- const exactOut = new Trade({
822
- v2Routes: [],
823
- v3Routes: [
824
- {
825
- routev3,
826
- inputAmount: CurrencyAmount.fromRawAmount(token0, 156),
827
- outputAmount: CurrencyAmount.fromRawAmount(token2, 100),
828
- },
829
- ],
830
- tradeType: TradeType.EXACT_OUTPUT,
831
- });
832
- const exactOutMultiRoute = new Trade({
833
- v2Routes: [],
834
- v3Routes: [
835
- {
836
- routev3,
837
- inputAmount: CurrencyAmount.fromRawAmount(token0, 78),
838
- outputAmount: CurrencyAmount.fromRawAmount(token2, 50),
839
- },
840
- {
841
- routev3: route2v3,
842
- inputAmount: CurrencyAmount.fromRawAmount(token0, 78),
843
- outputAmount: CurrencyAmount.fromRawAmount(token2, 50),
844
- },
845
- ],
846
- tradeType: TradeType.EXACT_OUTPUT,
847
- });
848
- it('throws if less than 0', () => {
849
- expect(() => exactOut.worstExecutionPrice(new Percent(-1, 100))).toThrow('SLIPPAGE_TOLERANCE');
850
- });
851
- it('returns exact if 0', () => {
852
- expect(exactOut.worstExecutionPrice(new Percent(0, 100))).toEqual(exactOut.executionPrice);
853
- });
854
- it('returns slippage amount if nonzero', () => {
855
- expect(exactOut.worstExecutionPrice(new Percent(0, 100)).equalTo(new Price(token0, token2, 156, 100))).toBeTruthy();
856
- expect(exactOut.worstExecutionPrice(new Percent(5, 100)).equalTo(new Price(token0, token2, 163, 100))).toBeTruthy();
857
- expect(exactOut.worstExecutionPrice(new Percent(200, 100)).equalTo(new Price(token0, token2, 468, 100))).toBeTruthy();
858
- });
859
- it('returns exact if nonzero with multiple routes', () => {
860
- expect(exactOutMultiRoute.worstExecutionPrice(new Percent(0, 100)).equalTo(new Price(token0, token2, 156, 100))).toBeTruthy();
861
- expect(exactOutMultiRoute.worstExecutionPrice(new Percent(5, 100)).equalTo(new Price(token0, token2, 163, 100))).toBeTruthy();
862
- expect(exactOutMultiRoute.worstExecutionPrice(new Percent(200, 100)).equalTo(new Price(token0, token2, 468, 100))).toBeTruthy();
863
- });
864
- });
865
- describe('worst execution price across v2 and v3 trades exact input', () => {
866
- const routev3 = new V3RouteSDK([pool_0_1, pool_1_2], token0, token2);
867
- const routev2 = new V2RouteSDK([pair_0_2], token0, token2);
868
- const mixedRoute = new MixedRouteSDK([pool_weth_0, pair_weth_2], token0, token2);
869
- const exactIn = new Trade({
870
- v2Routes: [
871
- {
872
- routev2,
873
- inputAmount: CurrencyAmount.fromRawAmount(token0, 100),
874
- outputAmount: CurrencyAmount.fromRawAmount(token2, 100),
875
- },
876
- ],
877
- v3Routes: [
878
- {
879
- routev3,
880
- inputAmount: CurrencyAmount.fromRawAmount(token0, 156),
881
- outputAmount: CurrencyAmount.fromRawAmount(token2, 100),
882
- },
883
- ],
884
- v4Routes: [],
885
- tradeType: TradeType.EXACT_INPUT,
886
- mixedRoutes: [
887
- {
888
- mixedRoute,
889
- inputAmount: CurrencyAmount.fromRawAmount(token0, 94),
890
- outputAmount: CurrencyAmount.fromRawAmount(token2, 50),
891
- },
892
- ],
893
- });
894
- it('throws if less than 0', () => {
895
- expect(() => exactIn.worstExecutionPrice(new Percent(-1, 100))).toThrow('SLIPPAGE_TOLERANCE');
896
- });
897
- it('returns exact if 0', () => {
898
- expect(exactIn.worstExecutionPrice(new Percent(0, 100))).toEqual(exactIn.executionPrice);
899
- });
900
- it('returns exact if nonzero', () => {
901
- expect(exactIn.worstExecutionPrice(new Percent(0, 100))).toEqual(new Price(token0, token2, 350, 250));
902
- expect(exactIn.worstExecutionPrice(new Percent(5, 100))).toEqual(new Price(token0, token2, 350, 238));
903
- expect(exactIn.worstExecutionPrice(new Percent(200, 100))).toEqual(new Price(token0, token2, 350, 83));
904
- });
905
- });
906
- describe('worst execution price across only mixedRoute trades exact input', () => {
907
- const mixedRoute = new MixedRouteSDK([pool_weth_0, pair_weth_2], token0, token2);
908
- const mixedRoute2 = new MixedRouteSDK([pair_0_1, pool_weth_1, pool_weth_2], token0, token2);
909
- const exactIn = new Trade({
910
- tradeType: TradeType.EXACT_INPUT,
911
- mixedRoutes: [
912
- {
913
- mixedRoute,
914
- inputAmount: CurrencyAmount.fromRawAmount(token0, 100),
915
- outputAmount: CurrencyAmount.fromRawAmount(token2, 100),
916
- },
917
- {
918
- mixedRoute: mixedRoute2,
919
- inputAmount: CurrencyAmount.fromRawAmount(token0, 156),
920
- outputAmount: CurrencyAmount.fromRawAmount(token2, 100),
921
- },
922
- ],
923
- });
924
- it('throws if less than 0', () => {
925
- expect(() => exactIn.worstExecutionPrice(new Percent(-1, 100))).toThrow('SLIPPAGE_TOLERANCE');
926
- });
927
- it('returns exact if 0', () => {
928
- expect(exactIn.worstExecutionPrice(new Percent(0, 100))).toEqual(exactIn.executionPrice);
929
- });
930
- it('returns exact if nonzero', () => {
931
- expect(exactIn.worstExecutionPrice(new Percent(0, 100))).toEqual(new Price(token0, token2, 256, 200));
932
- expect(exactIn.worstExecutionPrice(new Percent(5, 100))).toEqual(new Price(token0, token2, 256, 190));
933
- expect(exactIn.worstExecutionPrice(new Percent(200, 100))).toEqual(new Price(token0, token2, 256, 66));
934
- });
935
- });
936
- describe('worst execution price across v2 and v3 trades exact output', () => {
937
- const routev3 = new V3RouteSDK([pool_0_1, pool_1_2], token0, token2);
938
- const routev2 = new V2RouteSDK([pair_0_2], token0, token2);
939
- const exactOut = new Trade({
940
- v2Routes: [
941
- {
942
- routev2,
943
- inputAmount: CurrencyAmount.fromRawAmount(token0, 100),
944
- outputAmount: CurrencyAmount.fromRawAmount(token2, 100),
945
- },
946
- ],
947
- v3Routes: [
948
- {
949
- routev3,
950
- inputAmount: CurrencyAmount.fromRawAmount(token0, 156),
951
- outputAmount: CurrencyAmount.fromRawAmount(token2, 100),
952
- },
953
- ],
954
- tradeType: TradeType.EXACT_OUTPUT,
955
- });
956
- it('throws if less than 0', () => {
957
- expect(() => exactOut.worstExecutionPrice(new Percent(-1, 100))).toThrow('SLIPPAGE_TOLERANCE');
958
- });
959
- it('returns exact if 0', () => {
960
- expect(exactOut.worstExecutionPrice(new Percent(0, 100))).toEqual(exactOut.executionPrice);
961
- });
962
- it('returns exact if nonzero', () => {
963
- expect(exactOut.worstExecutionPrice(new Percent(0, 100))).toEqual(new Price(token0, token2, 256, 200));
964
- expect(exactOut.worstExecutionPrice(new Percent(5, 100))).toEqual(new Price(token0, token2, 268, 200));
965
- expect(exactOut.worstExecutionPrice(new Percent(200, 100))).toEqual(new Price(token0, token2, 768, 200));
966
- });
967
- });
968
- });
969
- describe('#minimumAmountOut', () => {
970
- describe('tradeType = EXACT_INPUT', () => {
971
- const routev3 = new V3RouteSDK([pool_0_1], token0, token1);
972
- const routev2 = new V2RouteSDK([pair_0_1], token0, token1);
973
- const mixedRoute = new MixedRouteSDK([pair_0_2, pool_1_2], token0, token1);
974
- const inputAmount = CurrencyAmount.fromRawAmount(token0, 100);
975
- const outputAmount = CurrencyAmount.fromRawAmount(token1, 100);
976
- const tradeType = TradeType.EXACT_INPUT;
977
- const trade = new Trade({
978
- v2Routes: [{ routev2, inputAmount, outputAmount }],
979
- v3Routes: [{ routev3, inputAmount, outputAmount }],
980
- tradeType,
981
- mixedRoutes: [{ mixedRoute, inputAmount, outputAmount }],
982
- });
983
- it('throws if less than 0', () => {
984
- expect(() => trade.minimumAmountOut(new Percent(JSBI.BigInt(-1), 100))).toThrow('SLIPPAGE_TOLERANCE');
985
- });
986
- it('returns exact if 0', () => {
987
- expect(trade.minimumAmountOut(new Percent(JSBI.BigInt(0), 100))).toEqual(trade.outputAmount);
988
- });
989
- it('returns exact if nonzero', () => {
990
- expect(trade.minimumAmountOut(new Percent(JSBI.BigInt(5), 100))).toEqual(CurrencyAmount.fromRawAmount(token1, 285) // 300 * 0.95
991
- );
992
- expect(trade.minimumAmountOut(new Percent(JSBI.BigInt(200), 100))).toEqual(CurrencyAmount.fromRawAmount(token1, 100));
993
- });
994
- describe('tradeType = EXACT_OUTPUT', () => {
995
- const routev3 = new V3RouteSDK([pool_0_1], token0, token1);
996
- const routev2 = new V2RouteSDK([pair_0_1], token0, token1);
997
- const inputAmount = CurrencyAmount.fromRawAmount(token0, 100);
998
- const outputAmount = CurrencyAmount.fromRawAmount(token1, 100);
999
- const tradeType = TradeType.EXACT_OUTPUT;
1000
- const trade = new Trade({
1001
- v2Routes: [{ routev2, inputAmount, outputAmount }],
1002
- v3Routes: [{ routev3, inputAmount, outputAmount }],
1003
- tradeType,
1004
- });
1005
- it('throws if less than 0', () => {
1006
- expect(() => trade.minimumAmountOut(new Percent(JSBI.BigInt(-1), 100))).toThrow('SLIPPAGE_TOLERANCE');
1007
- });
1008
- it('returns exact if 0', () => {
1009
- expect(trade.minimumAmountOut(new Percent(JSBI.BigInt(0), 100))).toEqual(trade.outputAmount);
1010
- });
1011
- it('returns exact if nonzero', () => {
1012
- expect(trade.minimumAmountOut(new Percent(JSBI.BigInt(5), 100))).toEqual(CurrencyAmount.fromRawAmount(token1, 200));
1013
- });
1014
- });
1015
- });
1016
- });
1017
- describe('#maximumAmountIn', () => {
1018
- describe('tradeType = EXACT_INPUT', () => {
1019
- const routev3 = new V3RouteSDK([pool_0_1], token0, token1);
1020
- const routev2 = new V2RouteSDK([pair_0_1], token0, token1);
1021
- const mixedRoute = new MixedRouteSDK([pair_0_2, pool_1_2], token0, token1);
1022
- const inputAmount = CurrencyAmount.fromRawAmount(token0, 100);
1023
- const outputAmount = CurrencyAmount.fromRawAmount(token1, 100);
1024
- const tradeType = TradeType.EXACT_INPUT;
1025
- const trade = new Trade({
1026
- v2Routes: [{ routev2, inputAmount, outputAmount }],
1027
- v3Routes: [{ routev3, inputAmount, outputAmount }],
1028
- tradeType,
1029
- mixedRoutes: [{ mixedRoute, inputAmount, outputAmount }],
1030
- });
1031
- it('throws if less than 0', () => {
1032
- expect(() => trade.maximumAmountIn(new Percent(JSBI.BigInt(-1), 100))).toThrow('SLIPPAGE_TOLERANCE');
1033
- });
1034
- it('returns exact if 0', () => {
1035
- expect(trade.maximumAmountIn(new Percent(JSBI.BigInt(0), 100))).toEqual(trade.inputAmount);
1036
- });
1037
- it('returns exact if nonzero', () => {
1038
- expect(trade.maximumAmountIn(new Percent(JSBI.BigInt(5), 100))).toEqual(CurrencyAmount.fromRawAmount(token0, 300));
1039
- });
1040
- describe('tradeType = EXACT_OUTPUT', () => {
1041
- const routev3 = new V3RouteSDK([pool_0_1], token0, token1);
1042
- const routev2 = new V2RouteSDK([pair_0_1], token0, token1);
1043
- const inputAmount = CurrencyAmount.fromRawAmount(token0, 100);
1044
- const outputAmount = CurrencyAmount.fromRawAmount(token1, 100);
1045
- const tradeType = TradeType.EXACT_OUTPUT;
1046
- const trade = new Trade({
1047
- v2Routes: [{ routev2, inputAmount, outputAmount }],
1048
- v3Routes: [{ routev3, inputAmount, outputAmount }],
1049
- tradeType,
1050
- });
1051
- it('throws if less than 0', () => {
1052
- expect(() => trade.maximumAmountIn(new Percent(JSBI.BigInt(-1), 100))).toThrow('SLIPPAGE_TOLERANCE');
1053
- });
1054
- it('returns exact if 0', () => {
1055
- expect(trade.maximumAmountIn(new Percent(JSBI.BigInt(0), 100))).toEqual(trade.inputAmount);
1056
- });
1057
- it('returns exact if nonzero', () => {
1058
- expect(trade.maximumAmountIn(new Percent(JSBI.BigInt(5), 100))).toEqual(CurrencyAmount.fromRawAmount(token0, 210));
1059
- expect(trade.maximumAmountIn(new Percent(JSBI.BigInt(200), 100))).toEqual(CurrencyAmount.fromRawAmount(token0, 600));
1060
- });
1061
- });
1062
- });
1063
- });
1064
- // v3 sdk price impact tests
1065
- describe('#priceImpact', () => {
1066
- describe('with FOT sell fees', () => {
1067
- const routev2 = new V2RouteSDK([pair_tax_output], weth, token4WithTax);
1068
- const trade = new Trade({
1069
- v2Routes: [
1070
- {
1071
- routev2,
1072
- inputAmount: CurrencyAmount.fromRawAmount(weth, 100),
1073
- outputAmount: CurrencyAmount.fromRawAmount(token4WithTax, 69),
1074
- },
1075
- ],
1076
- v3Routes: [],
1077
- tradeType: TradeType.EXACT_INPUT,
1078
- });
1079
- it('is correct', () => {
1080
- expect(trade.priceImpact.toSignificant(3)).toEqual('30.3');
1081
- });
1082
- });
1083
- describe('with FOT buy fees', () => {
1084
- const routev2 = new V2RouteSDK([pair_tax_input], token5WithTax, weth);
1085
- const trade = new Trade({
1086
- v2Routes: [
1087
- {
1088
- routev2,
1089
- inputAmount: CurrencyAmount.fromRawAmount(token5WithTax, 100),
1090
- outputAmount: CurrencyAmount.fromRawAmount(weth, 69),
1091
- },
1092
- ],
1093
- tradeType: TradeType.EXACT_INPUT,
1094
- });
1095
- it('is correct', () => {
1096
- expect(trade.priceImpact.toSignificant(3)).toEqual('27.4');
1097
- });
1098
- });
1099
- describe('tradeType = EXACT_INPUT', () => {
1100
- const routev3 = new V3RouteSDK([pool_0_1, pool_1_2], token0, token2);
1101
- const mixedRoute = new MixedRouteSDK([pool_0_1, pool_1_2], token0, token2);
1102
- const trade = new Trade({
1103
- v3Routes: [
1104
- {
1105
- routev3,
1106
- inputAmount: CurrencyAmount.fromRawAmount(token0, 100),
1107
- outputAmount: CurrencyAmount.fromRawAmount(token2, 69),
1108
- },
1109
- ],
1110
- tradeType: TradeType.EXACT_INPUT,
1111
- });
1112
- const mixedTrade = new Trade({
1113
- tradeType: TradeType.EXACT_INPUT,
1114
- mixedRoutes: [
1115
- {
1116
- mixedRoute,
1117
- inputAmount: CurrencyAmount.fromRawAmount(token0, 100),
1118
- outputAmount: CurrencyAmount.fromRawAmount(token2, 69),
1119
- },
1120
- ],
1121
- });
1122
- it('is cached', () => {
1123
- expect(mixedTrade.priceImpact.equalTo(trade.priceImpact)).toBe(true);
1124
- });
1125
- it('is correct', () => {
1126
- expect(trade.priceImpact.toSignificant(3)).toEqual('17.2');
1127
- expect(mixedTrade.priceImpact.toSignificant(3)).toEqual(trade.priceImpact.toSignificant(3));
1128
- });
1129
- });
1130
- describe('tradeType = EXACT_OUTPUT', () => {
1131
- const routev3 = new V3RouteSDK([pool_0_1, pool_1_2], token0, token2);
1132
- const exactOut = new Trade({
1133
- v3Routes: [
1134
- {
1135
- routev3,
1136
- inputAmount: CurrencyAmount.fromRawAmount(token0, 156),
1137
- outputAmount: CurrencyAmount.fromRawAmount(token2, 100),
1138
- },
1139
- ],
1140
- tradeType: TradeType.EXACT_OUTPUT,
1141
- });
1142
- it('is correct', () => {
1143
- expect(exactOut.priceImpact.toSignificant(3)).toEqual('23.1');
1144
- });
1145
- });
1146
- });
1147
- describe('#executionPrice', () => {
1148
- it('is correct for tradeType = EXACT_INPUT', () => __awaiter(void 0, void 0, void 0, function* () {
1149
- const routeOriginalV2 = new V2RouteSDK([pair_0_1], token0, token1);
1150
- const routev2 = new RouteV2(routeOriginalV2);
1151
- const amountv2 = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100));
1152
- const routeOriginalV3 = new V3RouteSDK([pool_0_1], token0, token1);
1153
- const routev3 = new RouteV3(routeOriginalV3);
1154
- const amountv3 = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100));
1155
- const mixedRouteOriginal = new MixedRouteSDK([pair_weth_0, pool_weth_1], token0, token1);
1156
- const mixedRoute = new MixedRoute(mixedRouteOriginal);
1157
- const amountMixed = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(100));
1158
- const expectedOutV3 = yield pool_0_1.getOutputAmount(amountv3);
1159
- const expectedOutMixed = yield pool_weth_1.getOutputAmount((yield pair_weth_0.getOutputAmount(amountMixed))[0]);
1160
- const expectedOut = expectedOutV3[0].add(pair_0_1.getOutputAmount(amountv2)[0]).add(expectedOutMixed[0]);
1161
- const trade = yield Trade.fromRoutes([{ routev2, amount: amountv2 }], [{ routev3, amount: amountv3 }], TradeType.EXACT_INPUT, [{ mixedRoute, amount: amountMixed }]);
1162
- const expectedPrice = new Price(token0, token1, CurrencyAmount.fromRawAmount(token0, 300).quotient, expectedOut.quotient);
1163
- expect(trade.executionPrice).toEqual(expectedPrice);
1164
- }));
1165
- it('is correct for tradeType = EXACT_OUTPUT', () => __awaiter(void 0, void 0, void 0, function* () {
1166
- const routeOriginalV2 = new V2RouteSDK([pair_0_1], token0, token1);
1167
- const routev2 = new RouteV2(routeOriginalV2);
1168
- const amountv2 = CurrencyAmount.fromRawAmount(token1, JSBI.BigInt(100));
1169
- const routeOriginalV3 = new V3RouteSDK([pool_0_1], token0, token1);
1170
- const routev3 = new RouteV3(routeOriginalV3);
1171
- const amountv3 = CurrencyAmount.fromRawAmount(token1, JSBI.BigInt(100));
1172
- const expectedInV3 = yield pool_0_1.getInputAmount(amountv3);
1173
- const expectedIn = expectedInV3[0].add(pair_0_1.getInputAmount(amountv2)[0]);
1174
- const trade = yield Trade.fromRoutes([{ routev2, amount: amountv2 }], [{ routev3, amount: amountv3 }], TradeType.EXACT_OUTPUT);
1175
- const expectedPrice = new Price(token0, token1, expectedIn.quotient, CurrencyAmount.fromRawAmount(token1, 200).quotient);
1176
- expect(trade.executionPrice).toEqual(expectedPrice);
1177
- }));
1178
- });
1179
- describe('eth-weth split routes', () => {
1180
- it('returns none for trade not involving eth-weth', () => __awaiter(void 0, void 0, void 0, function* () {
1181
- // TRADE OBJECT
1182
- // input : protocol : path : trade requirement
1183
- // [token0] : v2 : [token0 - token1] : NONE
1184
- // [token0] : v4 : [token0 - token1]: NONE
1185
- const routev2 = new V2RouteSDK([pair_0_1], token0, token1);
1186
- const routev3 = new V3RouteSDK([pool_0_1], token0, token1);
1187
- const amountv2 = CurrencyAmount.fromRawAmount(token0, 999);
1188
- const amountv3 = CurrencyAmount.fromRawAmount(token0, 101010);
1189
- const splitTrade = yield Trade.fromRoutes([{ routev2, amount: amountv2 }], [{ routev3, amount: amountv3 }], TradeType.EXACT_INPUT, [], []);
1190
- expect(splitTrade.numberOfInputUnwraps).toEqual(0);
1191
- expect(splitTrade.numberOfInputWraps).toEqual(0);
1192
- expect(splitTrade.nativeInputRoutes.length).toEqual(0);
1193
- expect(splitTrade.wethInputRoutes.length).toEqual(0);
1194
- }));
1195
- it('WETH input exactIn, no unwraps', () => __awaiter(void 0, void 0, void 0, function* () {
1196
- // TRADE OBJECT
1197
- // input : protocol : path : trade requirement
1198
- // [WETH] : v2 : [WETH - token1] : NONE
1199
- // [WETH] : v4 : [WETH - token1]: NONE
1200
- const routev2 = new V2RouteSDK([pair_weth_1], weth, token1);
1201
- const routev4 = new V4RouteSDK([pool_v4_1_weth], weth, token1);
1202
- const amountv2 = CurrencyAmount.fromRawAmount(weth, 100);
1203
- const amountv4 = CurrencyAmount.fromRawAmount(weth, 200);
1204
- const splitTrade = yield Trade.fromRoutes([{ routev2, amount: amountv2 }], [], TradeType.EXACT_INPUT, [], [{ routev4, amount: amountv4 }]);
1205
- expect(splitTrade.numberOfInputUnwraps).toEqual(0);
1206
- expect(splitTrade.numberOfInputWraps).toEqual(0);
1207
- expect(splitTrade.nativeInputRoutes.length).toEqual(0);
1208
- expect(splitTrade.wethInputRoutes.length).toEqual(2);
1209
- expect(splitTrade.wethInputRoutes[0]).toEqual(new RouteV2(routev2));
1210
- expect(splitTrade.wethInputRoutes[1]).toEqual(new RouteV4(routev4));
1211
- }));
1212
- it('WETH input exactIn, 1 unwrap', () => __awaiter(void 0, void 0, void 0, function* () {
1213
- // TRADE OBJECT
1214
- // input : protocol : path : trade requirement
1215
- // [WETH] : v2 : [WETH - token1] : NONE
1216
- // [WETH] : v4 : [ETH - token1] : UNWRAP
1217
- const routev2 = new V2RouteSDK([pair_weth_1], weth, token1);
1218
- const routev4 = new V4RouteSDK([pool_v4_1_eth], weth, token1);
1219
- const amountv2 = CurrencyAmount.fromRawAmount(weth, 100);
1220
- const amountv4 = CurrencyAmount.fromRawAmount(weth, 200);
1221
- const splitTrade = yield Trade.fromRoutes([{ routev2, amount: amountv2 }], [], TradeType.EXACT_INPUT, [], [{ routev4, amount: amountv4 }]);
1222
- expect(splitTrade.numberOfInputUnwraps).toEqual(1);
1223
- expect(splitTrade.numberOfInputWraps).toEqual(0);
1224
- expect(splitTrade.nativeInputRoutes.length).toEqual(1);
1225
- expect(splitTrade.nativeInputRoutes[0]).toEqual(new RouteV4(routev4));
1226
- expect(splitTrade.wethInputRoutes.length).toEqual(1);
1227
- expect(splitTrade.wethInputRoutes[0]).toEqual(new RouteV2(routev2));
1228
- }));
1229
- it('ETH input exactIn, no wraps', () => __awaiter(void 0, void 0, void 0, function* () {
1230
- // TRADE OBJECT
1231
- // input : protocol : path : trade requirement
1232
- // [ETH] : v4 : [ETH - token1] : NONE
1233
- // [ETH] : mixed : [ETH - token0], [token0 - token1] : NONE
1234
- const routev4 = new V4RouteSDK([pool_v4_1_eth], ETHER, token1);
1235
- const mixedRoute = new MixedRouteSDK([pool_v4_0_eth, pool_0_1], ETHER, token1);
1236
- const amountv4 = CurrencyAmount.fromRawAmount(ETHER, 1111);
1237
- const amountMixed = CurrencyAmount.fromRawAmount(ETHER, 2222);
1238
- const splitTrade = yield Trade.fromRoutes([], [], TradeType.EXACT_INPUT, [{ mixedRoute, amount: amountMixed }], [{ routev4, amount: amountv4 }]);
1239
- expect(splitTrade.numberOfInputUnwraps).toEqual(0);
1240
- expect(splitTrade.numberOfInputWraps).toEqual(0);
1241
- expect(splitTrade.nativeInputRoutes.length).toEqual(2);
1242
- expect(splitTrade.wethInputRoutes.length).toEqual(0);
1243
- expect(splitTrade.nativeInputRoutes[0]).toEqual(new RouteV4(routev4));
1244
- expect(splitTrade.nativeInputRoutes[1]).toEqual(new MixedRoute(mixedRoute));
1245
- }));
1246
- it('ETH input exactIn, 1 wrap', () => __awaiter(void 0, void 0, void 0, function* () {
1247
- // TRADE OBJECT
1248
- // input : protocol : path : trade requirement
1249
- // [ETH] : v4 : [ETH - token1] : NONE
1250
- // [ETH] : mixed : [WETH - token0], [token0 - token1] : WRAP
1251
- const routev4 = new V4RouteSDK([pool_v4_1_eth], ETHER, token1);
1252
- const mixedRoute = new MixedRouteSDK([pool_weth_0, pool_0_1], ETHER, token1);
1253
- const amountv4 = CurrencyAmount.fromRawAmount(ETHER, 1111);
1254
- const amountMixed = CurrencyAmount.fromRawAmount(ETHER, 2222);
1255
- const splitTrade = yield Trade.fromRoutes([], [], TradeType.EXACT_INPUT, [{ mixedRoute, amount: amountMixed }], [{ routev4, amount: amountv4 }]);
1256
- expect(splitTrade.numberOfInputUnwraps).toEqual(0);
1257
- expect(splitTrade.numberOfInputWraps).toEqual(1);
1258
- expect(splitTrade.nativeInputRoutes.length).toEqual(1);
1259
- expect(splitTrade.wethInputRoutes.length).toEqual(1);
1260
- expect(splitTrade.nativeInputRoutes[0]).toEqual(new RouteV4(routev4));
1261
- expect(splitTrade.wethInputRoutes[0]).toEqual(new MixedRoute(mixedRoute));
1262
- }));
1263
- });
1264
- });
1265
- //# sourceMappingURL=trade.test.js.map