@kittycorn-labs/v4-sdk 1.1.29 → 2.0.0

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 (197) hide show
  1. package/README.md +9 -0
  2. package/dist/{PositionManager.d.ts → cjs/src/PositionManager.d.ts} +169 -169
  3. package/dist/cjs/src/PositionManager.js +242 -0
  4. package/dist/cjs/src/PositionManager.js.map +1 -0
  5. package/dist/cjs/src/abis/IMulticall.json +23 -0
  6. package/dist/{actionConstants.d.ts → cjs/src/actionConstants.d.ts} +1 -1
  7. package/dist/cjs/src/actionConstants.js +6 -0
  8. package/dist/cjs/src/actionConstants.js.map +1 -0
  9. package/dist/{entities → cjs/src/entities}/index.d.ts +4 -4
  10. package/dist/cjs/src/entities/index.js +8 -0
  11. package/dist/cjs/src/entities/index.js.map +1 -0
  12. package/dist/{entities → cjs/src/entities}/pool.d.ts +103 -103
  13. package/dist/cjs/src/entities/pool.js +196 -0
  14. package/dist/cjs/src/entities/pool.js.map +1 -0
  15. package/dist/{entities → cjs/src/entities}/position.d.ts +144 -144
  16. package/dist/cjs/src/entities/position.js +273 -0
  17. package/dist/cjs/src/entities/position.js.map +1 -0
  18. package/dist/{entities → cjs/src/entities}/route.d.ts +28 -28
  19. package/dist/cjs/src/entities/route.js +89 -0
  20. package/dist/cjs/src/entities/route.js.map +1 -0
  21. package/dist/{entities → cjs/src/entities}/trade.d.ts +220 -220
  22. package/dist/cjs/src/entities/trade.js +441 -0
  23. package/dist/cjs/src/entities/trade.js.map +1 -0
  24. package/dist/{index.d.ts → cjs/src/index.d.ts} +4 -4
  25. package/dist/cjs/src/index.js +8 -0
  26. package/dist/cjs/src/index.js.map +1 -0
  27. package/dist/{internalConstants.d.ts → cjs/src/internalConstants.d.ts} +46 -46
  28. package/dist/cjs/src/internalConstants.js +69 -0
  29. package/dist/cjs/src/internalConstants.js.map +1 -0
  30. package/dist/{multicall.d.ts → cjs/src/multicall.d.ts} +10 -10
  31. package/dist/cjs/src/multicall.js +26 -0
  32. package/dist/cjs/src/multicall.js.map +1 -0
  33. package/dist/cjs/src/tokenize.d.ts +17 -0
  34. package/dist/cjs/src/tokenize.js +42 -0
  35. package/dist/cjs/src/tokenize.js.map +1 -0
  36. package/dist/{utils → cjs/src/utils}/calldata.d.ts +20 -20
  37. package/dist/cjs/src/utils/calldata.js +20 -0
  38. package/dist/cjs/src/utils/calldata.js.map +1 -0
  39. package/dist/{utils → cjs/src/utils}/currencyMap.d.ts +2 -2
  40. package/dist/cjs/src/utils/currencyMap.js +15 -0
  41. package/dist/cjs/src/utils/currencyMap.js.map +1 -0
  42. package/dist/{utils → cjs/src/utils}/encodeRouteToPath.d.ts +10 -10
  43. package/dist/cjs/src/utils/encodeRouteToPath.js +26 -0
  44. package/dist/cjs/src/utils/encodeRouteToPath.js.map +1 -0
  45. package/dist/{utils → cjs/src/utils}/hook.d.ts +45 -45
  46. package/dist/cjs/src/utils/hook.js +97 -0
  47. package/dist/cjs/src/utils/hook.js.map +1 -0
  48. package/dist/{utils → cjs/src/utils}/index.d.ts +11 -11
  49. package/dist/cjs/src/utils/index.js +15 -0
  50. package/dist/cjs/src/utils/index.js.map +1 -0
  51. package/dist/{utils → cjs/src/utils}/pathCurrency.d.ts +4 -4
  52. package/dist/cjs/src/utils/pathCurrency.js +27 -0
  53. package/dist/cjs/src/utils/pathCurrency.js.map +1 -0
  54. package/dist/{utils → cjs/src/utils}/positionManagerAbi.d.ts +102 -102
  55. package/dist/cjs/src/utils/positionManagerAbi.js +1318 -0
  56. package/dist/cjs/src/utils/positionManagerAbi.js.map +1 -0
  57. package/dist/{utils → cjs/src/utils}/priceTickConversions.d.ts +20 -20
  58. package/dist/cjs/src/utils/priceTickConversions.js +55 -0
  59. package/dist/cjs/src/utils/priceTickConversions.js.map +1 -0
  60. package/dist/{utils → cjs/src/utils}/sortsBefore.d.ts +2 -2
  61. package/dist/cjs/src/utils/sortsBefore.js +12 -0
  62. package/dist/cjs/src/utils/sortsBefore.js.map +1 -0
  63. package/dist/{utils → cjs/src/utils}/v4BaseActionsParser.d.ts +49 -45
  64. package/dist/cjs/src/utils/v4BaseActionsParser.js +193 -0
  65. package/dist/cjs/src/utils/v4BaseActionsParser.js.map +1 -0
  66. package/dist/{utils → cjs/src/utils}/v4Planner.d.ts +71 -55
  67. package/dist/cjs/src/utils/v4Planner.js +267 -0
  68. package/dist/cjs/src/utils/v4Planner.js.map +1 -0
  69. package/dist/{utils → cjs/src/utils}/v4PositionPlanner.d.ts +13 -12
  70. package/dist/cjs/src/utils/v4PositionPlanner.js +61 -0
  71. package/dist/cjs/src/utils/v4PositionPlanner.js.map +1 -0
  72. package/dist/esm/package.json +1 -0
  73. package/dist/esm/src/PositionManager.d.ts +169 -0
  74. package/dist/esm/src/PositionManager.js +237 -0
  75. package/dist/esm/src/PositionManager.js.map +1 -0
  76. package/dist/esm/src/abis/IMulticall.json +23 -0
  77. package/dist/esm/src/actionConstants.d.ts +1 -0
  78. package/dist/esm/src/actionConstants.js +3 -0
  79. package/dist/esm/src/actionConstants.js.map +1 -0
  80. package/dist/esm/src/entities/index.d.ts +4 -0
  81. package/dist/esm/src/entities/index.js +5 -0
  82. package/dist/esm/src/entities/index.js.map +1 -0
  83. package/dist/esm/src/entities/pool.d.ts +103 -0
  84. package/dist/esm/src/entities/pool.js +191 -0
  85. package/dist/esm/src/entities/pool.js.map +1 -0
  86. package/dist/esm/src/entities/position.d.ts +144 -0
  87. package/dist/esm/src/entities/position.js +268 -0
  88. package/dist/esm/src/entities/position.js.map +1 -0
  89. package/dist/esm/src/entities/route.d.ts +28 -0
  90. package/dist/esm/src/entities/route.js +84 -0
  91. package/dist/esm/src/entities/route.js.map +1 -0
  92. package/dist/esm/src/entities/trade.d.ts +220 -0
  93. package/dist/esm/src/entities/trade.js +435 -0
  94. package/dist/esm/src/entities/trade.js.map +1 -0
  95. package/dist/esm/src/index.d.ts +4 -0
  96. package/dist/esm/src/index.js +5 -0
  97. package/dist/esm/src/index.js.map +1 -0
  98. package/dist/esm/src/internalConstants.d.ts +46 -0
  99. package/dist/esm/src/internalConstants.js +65 -0
  100. package/dist/esm/src/internalConstants.js.map +1 -0
  101. package/dist/esm/src/multicall.d.ts +10 -0
  102. package/dist/esm/src/multicall.js +21 -0
  103. package/dist/esm/src/multicall.js.map +1 -0
  104. package/dist/esm/src/tokenize.d.ts +17 -0
  105. package/dist/esm/src/tokenize.js +37 -0
  106. package/dist/esm/src/tokenize.js.map +1 -0
  107. package/dist/esm/src/utils/calldata.d.ts +20 -0
  108. package/dist/esm/src/utils/calldata.js +15 -0
  109. package/dist/esm/src/utils/calldata.js.map +1 -0
  110. package/dist/esm/src/utils/currencyMap.d.ts +2 -0
  111. package/dist/esm/src/utils/currencyMap.js +11 -0
  112. package/dist/esm/src/utils/currencyMap.js.map +1 -0
  113. package/dist/esm/src/utils/encodeRouteToPath.d.ts +10 -0
  114. package/dist/esm/src/utils/encodeRouteToPath.js +22 -0
  115. package/dist/esm/src/utils/encodeRouteToPath.js.map +1 -0
  116. package/dist/esm/src/utils/hook.d.ts +45 -0
  117. package/dist/esm/src/utils/hook.js +92 -0
  118. package/dist/esm/src/utils/hook.js.map +1 -0
  119. package/dist/esm/src/utils/index.d.ts +11 -0
  120. package/dist/esm/src/utils/index.js +12 -0
  121. package/dist/esm/src/utils/index.js.map +1 -0
  122. package/dist/esm/src/utils/pathCurrency.d.ts +4 -0
  123. package/dist/esm/src/utils/pathCurrency.js +22 -0
  124. package/dist/esm/src/utils/pathCurrency.js.map +1 -0
  125. package/dist/esm/src/utils/positionManagerAbi.d.ts +102 -0
  126. package/dist/esm/src/utils/positionManagerAbi.js +1315 -0
  127. package/dist/esm/src/utils/positionManagerAbi.js.map +1 -0
  128. package/dist/esm/src/utils/priceTickConversions.d.ts +20 -0
  129. package/dist/esm/src/utils/priceTickConversions.js +49 -0
  130. package/dist/esm/src/utils/priceTickConversions.js.map +1 -0
  131. package/dist/esm/src/utils/sortsBefore.d.ts +2 -0
  132. package/dist/esm/src/utils/sortsBefore.js +8 -0
  133. package/dist/esm/src/utils/sortsBefore.js.map +1 -0
  134. package/dist/esm/src/utils/v4BaseActionsParser.d.ts +49 -0
  135. package/dist/esm/src/utils/v4BaseActionsParser.js +189 -0
  136. package/dist/esm/src/utils/v4BaseActionsParser.js.map +1 -0
  137. package/dist/esm/src/utils/v4Planner.d.ts +71 -0
  138. package/dist/esm/src/utils/v4Planner.js +261 -0
  139. package/dist/esm/src/utils/v4Planner.js.map +1 -0
  140. package/dist/esm/src/utils/v4PositionPlanner.d.ts +13 -0
  141. package/dist/esm/src/utils/v4PositionPlanner.js +57 -0
  142. package/dist/esm/src/utils/v4PositionPlanner.js.map +1 -0
  143. package/dist/types/src/PositionManager.d.ts +170 -0
  144. package/dist/types/src/PositionManager.d.ts.map +1 -0
  145. package/dist/types/src/actionConstants.d.ts +2 -0
  146. package/dist/types/src/actionConstants.d.ts.map +1 -0
  147. package/dist/types/src/entities/index.d.ts +5 -0
  148. package/dist/types/src/entities/index.d.ts.map +1 -0
  149. package/dist/types/src/entities/pool.d.ts +104 -0
  150. package/dist/types/src/entities/pool.d.ts.map +1 -0
  151. package/dist/types/src/entities/position.d.ts +145 -0
  152. package/dist/types/src/entities/position.d.ts.map +1 -0
  153. package/dist/types/src/entities/route.d.ts +29 -0
  154. package/dist/types/src/entities/route.d.ts.map +1 -0
  155. package/dist/types/src/entities/trade.d.ts +221 -0
  156. package/dist/types/src/entities/trade.d.ts.map +1 -0
  157. package/dist/types/src/index.d.ts +5 -0
  158. package/dist/types/src/index.d.ts.map +1 -0
  159. package/dist/types/src/internalConstants.d.ts +47 -0
  160. package/dist/types/src/internalConstants.d.ts.map +1 -0
  161. package/dist/types/src/multicall.d.ts +11 -0
  162. package/dist/types/src/multicall.d.ts.map +1 -0
  163. package/dist/types/src/tokenize.d.ts +18 -0
  164. package/dist/types/src/tokenize.d.ts.map +1 -0
  165. package/dist/types/src/utils/calldata.d.ts +21 -0
  166. package/dist/types/src/utils/calldata.d.ts.map +1 -0
  167. package/dist/types/src/utils/currencyMap.d.ts +3 -0
  168. package/dist/types/src/utils/currencyMap.d.ts.map +1 -0
  169. package/dist/types/src/utils/encodeRouteToPath.d.ts +11 -0
  170. package/dist/types/src/utils/encodeRouteToPath.d.ts.map +1 -0
  171. package/dist/types/src/utils/hook.d.ts +46 -0
  172. package/dist/types/src/utils/hook.d.ts.map +1 -0
  173. package/dist/types/src/utils/index.d.ts +12 -0
  174. package/dist/types/src/utils/index.d.ts.map +1 -0
  175. package/dist/types/src/utils/pathCurrency.d.ts +5 -0
  176. package/dist/types/src/utils/pathCurrency.d.ts.map +1 -0
  177. package/dist/types/src/utils/positionManagerAbi.d.ts +103 -0
  178. package/dist/types/src/utils/positionManagerAbi.d.ts.map +1 -0
  179. package/dist/types/src/utils/priceTickConversions.d.ts +21 -0
  180. package/dist/types/src/utils/priceTickConversions.d.ts.map +1 -0
  181. package/dist/types/src/utils/sortsBefore.d.ts +3 -0
  182. package/dist/types/src/utils/sortsBefore.d.ts.map +1 -0
  183. package/dist/types/src/utils/v4BaseActionsParser.d.ts +50 -0
  184. package/dist/types/src/utils/v4BaseActionsParser.d.ts.map +1 -0
  185. package/dist/types/src/utils/v4Planner.d.ts +72 -0
  186. package/dist/types/src/utils/v4Planner.d.ts.map +1 -0
  187. package/dist/types/src/utils/v4PositionPlanner.d.ts +14 -0
  188. package/dist/types/src/utils/v4PositionPlanner.d.ts.map +1 -0
  189. package/package.json +28 -46
  190. package/dist/index.js +0 -8
  191. package/dist/tokenizeAddresses.d.ts +0 -25
  192. package/dist/v4-sdk.cjs.development.js +0 -3633
  193. package/dist/v4-sdk.cjs.development.js.map +0 -1
  194. package/dist/v4-sdk.cjs.production.min.js +0 -2
  195. package/dist/v4-sdk.cjs.production.min.js.map +0 -1
  196. package/dist/v4-sdk.esm.js +0 -3597
  197. package/dist/v4-sdk.esm.js.map +0 -1
@@ -0,0 +1,220 @@
1
+ import { Currency, Percent, Price, CurrencyAmount, TradeType } from '@kittycorn-labs/sdk-core';
2
+ import { Pool } from './pool';
3
+ import { Route } from './route';
4
+ /**
5
+ * Trades comparator, an extension of the input output comparator that also considers other dimensions of the trade in ranking them
6
+ * @template TInput The input currency, either Ether or an ERC-20
7
+ * @template TOutput The output currency, either Ether or an ERC-20
8
+ * @template TTradeType The trade type, either exact input or exact output
9
+ * @param a The first trade to compare
10
+ * @param b The second trade to compare
11
+ * @returns A sorted ordering for two neighboring elements in a trade array
12
+ */
13
+ export declare function tradeComparator<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType>(a: Trade<TInput, TOutput, TTradeType>, b: Trade<TInput, TOutput, TTradeType>): number;
14
+ export interface BestTradeOptions {
15
+ maxNumResults?: number;
16
+ maxHops?: number;
17
+ }
18
+ /**
19
+ * Represents a trade executed against a set of routes where some percentage of the input is
20
+ * split across each route.
21
+ *
22
+ * Each route has its own set of pools. Pools can not be re-used across routes.
23
+ *
24
+ * Does not account for slippage, i.e., changes in price environment that can occur between
25
+ * the time the trade is submitted and when it is executed.
26
+ * @template TInput The input currency, either Ether or an ERC-20
27
+ * @template TOutput The output currency, either Ether or an ERC-20
28
+ * @template TTradeType The trade type, either exact input or exact output
29
+ */
30
+ export declare class Trade<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType> {
31
+ /**
32
+ * @deprecated Deprecated in favor of 'swaps' property. If the trade consists of multiple routes
33
+ * this will return an error.
34
+ *
35
+ * When the trade consists of just a single route, this returns the route of the trade,
36
+ * i.e. which pools the trade goes through.
37
+ */
38
+ get route(): Route<TInput, TOutput>;
39
+ /**
40
+ * The swaps of the trade, i.e. which routes and how much is swapped in each that
41
+ * make up the trade.
42
+ */
43
+ readonly swaps: {
44
+ route: Route<TInput, TOutput>;
45
+ inputAmount: CurrencyAmount<TInput>;
46
+ outputAmount: CurrencyAmount<TOutput>;
47
+ }[];
48
+ /**
49
+ * The type of the trade, either exact in or exact out.
50
+ */
51
+ readonly tradeType: TTradeType;
52
+ /**
53
+ * The cached result of the input amount computation
54
+ * @private
55
+ */
56
+ private _inputAmount;
57
+ /**
58
+ * The input amount for the trade assuming no slippage.
59
+ */
60
+ get inputAmount(): CurrencyAmount<TInput>;
61
+ /**
62
+ * The cached result of the output amount computation
63
+ * @private
64
+ */
65
+ private _outputAmount;
66
+ /**
67
+ * The output amount for the trade assuming no slippage.
68
+ */
69
+ get outputAmount(): CurrencyAmount<TOutput>;
70
+ /**
71
+ * The cached result of the computed execution price
72
+ * @private
73
+ */
74
+ private _executionPrice;
75
+ /**
76
+ * The price expressed in terms of output amount/input amount.
77
+ */
78
+ get executionPrice(): Price<TInput, TOutput>;
79
+ /**
80
+ * The cached result of the price impact computation
81
+ * @private
82
+ */
83
+ private _priceImpact;
84
+ /**
85
+ * Returns the percent difference between the route's mid price and the price impact
86
+ */
87
+ get priceImpact(): Percent;
88
+ /**
89
+ * Constructs an exact in trade with the given amount in and route
90
+ * @template TInput The input currency, either Ether or an ERC-20
91
+ * @template TOutput The output currency, either Ether or an ERC-20
92
+ * @param route The route of the exact in trade
93
+ * @param amountIn The amount being passed in
94
+ * @returns The exact in trade
95
+ */
96
+ static exactIn<TInput extends Currency, TOutput extends Currency>(route: Route<TInput, TOutput>, amountIn: CurrencyAmount<TInput>): Promise<Trade<TInput, TOutput, TradeType.EXACT_INPUT>>;
97
+ /**
98
+ * Constructs an exact out trade with the given amount out and route
99
+ * @template TInput The input currency, either Ether or an ERC-20
100
+ * @template TOutput The output currency, either Ether or an ERC-20
101
+ * @param route The route of the exact out trade
102
+ * @param amountOut The amount returned by the trade
103
+ * @returns The exact out trade
104
+ */
105
+ static exactOut<TInput extends Currency, TOutput extends Currency>(route: Route<TInput, TOutput>, amountOut: CurrencyAmount<TOutput>): Promise<Trade<TInput, TOutput, TradeType.EXACT_OUTPUT>>;
106
+ /**
107
+ * Constructs a trade by simulating swaps through the given route
108
+ * @template TInput The input currency, either Ether or an ERC-20.
109
+ * @template TOutput The output currency, either Ether or an ERC-20.
110
+ * @template TTradeType The type of the trade, either exact in or exact out.
111
+ * @param route route to swap through
112
+ * @param amount the amount specified, either input or output, depending on tradeType
113
+ * @param tradeType whether the trade is an exact input or exact output swap
114
+ * @returns The route
115
+ */
116
+ static fromRoute<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType>(route: Route<TInput, TOutput>, amount: TTradeType extends TradeType.EXACT_INPUT ? CurrencyAmount<TInput> : CurrencyAmount<TOutput>, tradeType: TTradeType): Promise<Trade<TInput, TOutput, TTradeType>>;
117
+ /**
118
+ * Constructs a trade from routes by simulating swaps
119
+ *
120
+ * @template TInput The input currency, either Ether or an ERC-20.
121
+ * @template TOutput The output currency, either Ether or an ERC-20.
122
+ * @template TTradeType The type of the trade, either exact in or exact out.
123
+ * @param routes the routes to swap through and how much of the amount should be routed through each
124
+ * @param tradeType whether the trade is an exact input or exact output swap
125
+ * @returns The trade
126
+ */
127
+ static fromRoutes<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType>(routes: {
128
+ amount: TTradeType extends TradeType.EXACT_INPUT ? CurrencyAmount<TInput> : CurrencyAmount<TOutput>;
129
+ route: Route<TInput, TOutput>;
130
+ }[], tradeType: TTradeType): Promise<Trade<TInput, TOutput, TTradeType>>;
131
+ /**
132
+ * Creates a trade without computing the result of swapping through the route. Useful when you have simulated the trade
133
+ * elsewhere and do not have any tick data
134
+ * @template TInput The input currency, either Ether or an ERC-20
135
+ * @template TOutput The output currency, either Ether or an ERC-20
136
+ * @template TTradeType The type of the trade, either exact in or exact out
137
+ * @param constructorArguments The arguments passed to the trade constructor
138
+ * @returns The unchecked trade
139
+ */
140
+ static createUncheckedTrade<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType>(constructorArguments: {
141
+ route: Route<TInput, TOutput>;
142
+ inputAmount: CurrencyAmount<TInput>;
143
+ outputAmount: CurrencyAmount<TOutput>;
144
+ tradeType: TTradeType;
145
+ }): Trade<TInput, TOutput, TTradeType>;
146
+ /**
147
+ * Creates a trade without computing the result of swapping through the routes. Useful when you have simulated the trade
148
+ * elsewhere and do not have any tick data
149
+ * @template TInput The input currency, either Ether or an ERC-20
150
+ * @template TOutput The output currency, either Ether or an ERC-20
151
+ * @template TTradeType The type of the trade, either exact in or exact out
152
+ * @param constructorArguments The arguments passed to the trade constructor
153
+ * @returns The unchecked trade
154
+ */
155
+ static createUncheckedTradeWithMultipleRoutes<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType>(constructorArguments: {
156
+ routes: {
157
+ route: Route<TInput, TOutput>;
158
+ inputAmount: CurrencyAmount<TInput>;
159
+ outputAmount: CurrencyAmount<TOutput>;
160
+ }[];
161
+ tradeType: TTradeType;
162
+ }): Trade<TInput, TOutput, TTradeType>;
163
+ /**
164
+ * Construct a trade by passing in the pre-computed property values
165
+ * @param routes The routes through which the trade occurs
166
+ * @param tradeType The type of trade, exact input or exact output
167
+ */
168
+ private constructor();
169
+ /**
170
+ * Get the minimum amount that must be received from this trade for the given slippage tolerance
171
+ * @param slippageTolerance The tolerance of unfavorable slippage from the execution price of this trade
172
+ * @returns The amount out
173
+ */
174
+ minimumAmountOut(slippageTolerance: Percent, amountOut?: CurrencyAmount<TOutput>): CurrencyAmount<TOutput>;
175
+ /**
176
+ * Get the maximum amount in that can be spent via this trade for the given slippage tolerance
177
+ * @param slippageTolerance The tolerance of unfavorable slippage from the execution price of this trade
178
+ * @returns The amount in
179
+ */
180
+ maximumAmountIn(slippageTolerance: Percent, amountIn?: CurrencyAmount<TInput>): CurrencyAmount<TInput>;
181
+ /**
182
+ * Return the execution price after accounting for slippage tolerance
183
+ * @param slippageTolerance the allowed tolerated slippage
184
+ * @returns The execution price
185
+ */
186
+ worstExecutionPrice(slippageTolerance: Percent): Price<TInput, TOutput>;
187
+ /**
188
+ * Given a list of pools, and a fixed amount in, returns the top `maxNumResults` trades that go from an input currency
189
+ * amount to an output currency, making at most `maxHops` hops.
190
+ * Note this does not consider aggregation, as routes are linear. It's possible a better route exists by splitting
191
+ * the amount in among multiple routes.
192
+ * @param pools the pools to consider in finding the best trade
193
+ * @param nextAmountIn exact amount of input currency to spend
194
+ * @param currencyOut the desired currency out
195
+ * @param maxNumResults maximum number of results to return
196
+ * @param maxHops maximum number of hops a returned trade can make, e.g. 1 hop goes through a single pool
197
+ * @param currentPools used in recursion; the current list of pools
198
+ * @param currencyAmountIn used in recursion; the original value of the currencyAmountIn parameter
199
+ * @param bestTrades used in recursion; the current list of best trades
200
+ * @returns The exact in trade
201
+ */
202
+ static bestTradeExactIn<TInput extends Currency, TOutput extends Currency>(pools: Pool[], currencyAmountIn: CurrencyAmount<TInput>, currencyOut: TOutput, { maxNumResults, maxHops }?: BestTradeOptions, currentPools?: Pool[], nextAmountIn?: CurrencyAmount<Currency>, bestTrades?: Trade<TInput, TOutput, TradeType.EXACT_INPUT>[]): Promise<Trade<TInput, TOutput, TradeType.EXACT_INPUT>[]>;
203
+ /**
204
+ * similar to the above method but instead targets a fixed output amount
205
+ * given a list of pools, and a fixed amount out, returns the top `maxNumResults` trades that go from an input currency
206
+ * to an output currency amount, making at most `maxHops` hops
207
+ * note this does not consider aggregation, as routes are linear. it's possible a better route exists by splitting
208
+ * the amount in among multiple routes.
209
+ * @param pools the pools to consider in finding the best trade
210
+ * @param currencyIn the currency to spend
211
+ * @param currencyAmountOut the desired currency amount out
212
+ * @param nextAmountOut the exact amount of currency out
213
+ * @param maxNumResults maximum number of results to return
214
+ * @param maxHops maximum number of hops a returned trade can make, e.g. 1 hop goes through a single pool
215
+ * @param currentPools used in recursion; the current list of pools
216
+ * @param bestTrades used in recursion; the current list of best trades
217
+ * @returns The exact out trade
218
+ */
219
+ static bestTradeExactOut<TInput extends Currency, TOutput extends Currency>(pools: Pool[], currencyIn: TInput, currencyAmountOut: CurrencyAmount<TOutput>, { maxNumResults, maxHops }?: BestTradeOptions, currentPools?: Pool[], nextAmountOut?: CurrencyAmount<Currency>, bestTrades?: Trade<TInput, TOutput, TradeType.EXACT_OUTPUT>[]): Promise<Trade<TInput, TOutput, TradeType.EXACT_OUTPUT>[]>;
220
+ }
@@ -0,0 +1,435 @@
1
+ import { isTokenizeConversion } from '../tokenize.js';
2
+ import { Fraction, Percent, Price, sortedInsert, CurrencyAmount, TradeType } from '@kittycorn-labs/sdk-core';
3
+ import JSBI from 'jsbi';
4
+ import invariant from 'tiny-invariant';
5
+ import { ONE, ZERO } from '../internalConstants.js';
6
+ import { Pool } from './pool.js';
7
+ import { Route } from './route.js';
8
+ import { amountWithPathCurrency } from '../utils/pathCurrency.js';
9
+ /**
10
+ * Trades comparator, an extension of the input output comparator that also considers other dimensions of the trade in ranking them
11
+ * @template TInput The input currency, either Ether or an ERC-20
12
+ * @template TOutput The output currency, either Ether or an ERC-20
13
+ * @template TTradeType The trade type, either exact input or exact output
14
+ * @param a The first trade to compare
15
+ * @param b The second trade to compare
16
+ * @returns A sorted ordering for two neighboring elements in a trade array
17
+ */
18
+ export function tradeComparator(a, b) {
19
+ // must have same input and output currency for comparison
20
+ invariant(a.inputAmount.currency.equals(b.inputAmount.currency), 'INPUT_CURRENCY');
21
+ invariant(a.outputAmount.currency.equals(b.outputAmount.currency), 'OUTPUT_CURRENCY');
22
+ if (a.outputAmount.equalTo(b.outputAmount)) {
23
+ if (a.inputAmount.equalTo(b.inputAmount)) {
24
+ // consider the number of hops since each hop costs gas
25
+ const aHops = a.swaps.reduce((total, cur) => total + cur.route.currencyPath.length, 0);
26
+ const bHops = b.swaps.reduce((total, cur) => total + cur.route.currencyPath.length, 0);
27
+ return aHops - bHops;
28
+ }
29
+ // trade A requires less input than trade B, so A should come first
30
+ if (a.inputAmount.lessThan(b.inputAmount)) {
31
+ return -1;
32
+ }
33
+ else {
34
+ return 1;
35
+ }
36
+ }
37
+ else {
38
+ // tradeA has less output than trade B, so should come second
39
+ if (a.outputAmount.lessThan(b.outputAmount)) {
40
+ return 1;
41
+ }
42
+ else {
43
+ return -1;
44
+ }
45
+ }
46
+ }
47
+ /**
48
+ * Represents a trade executed against a set of routes where some percentage of the input is
49
+ * split across each route.
50
+ *
51
+ * Each route has its own set of pools. Pools can not be re-used across routes.
52
+ *
53
+ * Does not account for slippage, i.e., changes in price environment that can occur between
54
+ * the time the trade is submitted and when it is executed.
55
+ * @template TInput The input currency, either Ether or an ERC-20
56
+ * @template TOutput The output currency, either Ether or an ERC-20
57
+ * @template TTradeType The trade type, either exact input or exact output
58
+ */
59
+ export class Trade {
60
+ /**
61
+ * @deprecated Deprecated in favor of 'swaps' property. If the trade consists of multiple routes
62
+ * this will return an error.
63
+ *
64
+ * When the trade consists of just a single route, this returns the route of the trade,
65
+ * i.e. which pools the trade goes through.
66
+ */
67
+ get route() {
68
+ invariant(this.swaps.length === 1, 'MULTIPLE_ROUTES');
69
+ return this.swaps[0].route;
70
+ }
71
+ /**
72
+ * The input amount for the trade assuming no slippage.
73
+ */
74
+ get inputAmount() {
75
+ if (this._inputAmount) {
76
+ return this._inputAmount;
77
+ }
78
+ const inputCurrency = this.swaps[0].inputAmount.currency;
79
+ const totalInputFromRoutes = this.swaps
80
+ .map(({ inputAmount }) => inputAmount)
81
+ .reduce((total, cur) => total.add(cur), CurrencyAmount.fromRawAmount(inputCurrency, 0));
82
+ this._inputAmount = totalInputFromRoutes;
83
+ return this._inputAmount;
84
+ }
85
+ /**
86
+ * The output amount for the trade assuming no slippage.
87
+ */
88
+ get outputAmount() {
89
+ if (this._outputAmount) {
90
+ return this._outputAmount;
91
+ }
92
+ const outputCurrency = this.swaps[0].outputAmount.currency;
93
+ const totalOutputFromRoutes = this.swaps
94
+ .map(({ outputAmount }) => outputAmount)
95
+ .reduce((total, cur) => total.add(cur), CurrencyAmount.fromRawAmount(outputCurrency, 0));
96
+ this._outputAmount = totalOutputFromRoutes;
97
+ return this._outputAmount;
98
+ }
99
+ /**
100
+ * The price expressed in terms of output amount/input amount.
101
+ */
102
+ get executionPrice() {
103
+ var _a;
104
+ return ((_a = this._executionPrice) !== null && _a !== void 0 ? _a : (this._executionPrice = new Price(this.inputAmount.currency, this.outputAmount.currency, this.inputAmount.quotient, this.outputAmount.quotient)));
105
+ }
106
+ /**
107
+ * Returns the percent difference between the route's mid price and the price impact
108
+ */
109
+ get priceImpact() {
110
+ if (this._priceImpact) {
111
+ return this._priceImpact;
112
+ }
113
+ let spotOutputAmount = CurrencyAmount.fromRawAmount(this.outputAmount.currency, 0);
114
+ for (const { route, inputAmount } of this.swaps) {
115
+ const midPrice = route.midPrice;
116
+ spotOutputAmount = spotOutputAmount.add(midPrice.quote(inputAmount));
117
+ }
118
+ const priceImpact = spotOutputAmount.subtract(this.outputAmount).divide(spotOutputAmount);
119
+ this._priceImpact = new Percent(priceImpact.numerator, priceImpact.denominator);
120
+ return this._priceImpact;
121
+ }
122
+ /**
123
+ * Constructs an exact in trade with the given amount in and route
124
+ * @template TInput The input currency, either Ether or an ERC-20
125
+ * @template TOutput The output currency, either Ether or an ERC-20
126
+ * @param route The route of the exact in trade
127
+ * @param amountIn The amount being passed in
128
+ * @returns The exact in trade
129
+ */
130
+ static async exactIn(route, amountIn) {
131
+ return Trade.fromRoute(route, amountIn, TradeType.EXACT_INPUT);
132
+ }
133
+ /**
134
+ * Constructs an exact out trade with the given amount out and route
135
+ * @template TInput The input currency, either Ether or an ERC-20
136
+ * @template TOutput The output currency, either Ether or an ERC-20
137
+ * @param route The route of the exact out trade
138
+ * @param amountOut The amount returned by the trade
139
+ * @returns The exact out trade
140
+ */
141
+ static async exactOut(route, amountOut) {
142
+ return Trade.fromRoute(route, amountOut, TradeType.EXACT_OUTPUT);
143
+ }
144
+ /**
145
+ * Constructs a trade by simulating swaps through the given route
146
+ * @template TInput The input currency, either Ether or an ERC-20.
147
+ * @template TOutput The output currency, either Ether or an ERC-20.
148
+ * @template TTradeType The type of the trade, either exact in or exact out.
149
+ * @param route route to swap through
150
+ * @param amount the amount specified, either input or output, depending on tradeType
151
+ * @param tradeType whether the trade is an exact input or exact output swap
152
+ * @returns The route
153
+ */
154
+ static async fromRoute(route, amount, tradeType) {
155
+ var _a;
156
+ let inputAmount;
157
+ let outputAmount;
158
+ if (tradeType === TradeType.EXACT_INPUT) {
159
+ invariant(amount.currency.equals(route.input), 'INPUT');
160
+ // Account for trades that wrap/unwrap as a first step
161
+ let tokenAmount = amountWithPathCurrency(amount, route.pools[0]);
162
+ for (let i = 0; i < route.pools.length; i++) {
163
+ const pool = route.pools[i];
164
+ [tokenAmount] = await pool.getOutputAmount(tokenAmount);
165
+ }
166
+ inputAmount = CurrencyAmount.fromFractionalAmount(route.input, amount.numerator, amount.denominator);
167
+ outputAmount = CurrencyAmount.fromFractionalAmount(route.output, tokenAmount.numerator, tokenAmount.denominator);
168
+ }
169
+ else {
170
+ invariant(amount.currency.equals(route.output), 'OUTPUT');
171
+ // Account for trades that wrap/unwrap as a last step
172
+ let tokenAmount = amountWithPathCurrency(amount, route.pools[route.pools.length - 1]);
173
+ for (let i = route.pools.length - 1; i >= 0; i--) {
174
+ const pool = route.pools[i];
175
+ [tokenAmount] = await pool.getInputAmount(tokenAmount);
176
+ // Special case: if this is the last pool (first in backward iteration) and it's an ETH-WETH pool
177
+ // with ETH as the route output, we need to convert the WETH amount back to ETH
178
+ // so the next pool in the iteration can work with ETH
179
+ // and vice versa if the route output is WETH
180
+ if (i === route.pools.length - 1) {
181
+ // Check if this is an ETH-WETH pool
182
+ const isEthWethPool = pool.currency1.equals(pool.currency0.wrapped);
183
+ if (isEthWethPool) {
184
+ if (route.output.isNative && ((_a = route.pools[i - 1]) === null || _a === void 0 ? void 0 : _a.currency0.isNative)) {
185
+ // Convert WETH amount to ETH for the next pool
186
+ tokenAmount = CurrencyAmount.fromFractionalAmount(pool.currency0, // native currency
187
+ tokenAmount.numerator, tokenAmount.denominator);
188
+ }
189
+ else if (route.output.equals(pool.currency1) &&
190
+ route.pools[i - 1] &&
191
+ !route.pools[i - 1].currency0.isNative) {
192
+ // Convert ETH amount to WETH for the next pool
193
+ tokenAmount = CurrencyAmount.fromFractionalAmount(pool.currency1, // wrapped currency
194
+ tokenAmount.numerator, tokenAmount.denominator);
195
+ }
196
+ }
197
+ }
198
+ }
199
+ inputAmount = CurrencyAmount.fromFractionalAmount(route.input, tokenAmount.numerator, tokenAmount.denominator);
200
+ outputAmount = CurrencyAmount.fromFractionalAmount(route.output, amount.numerator, amount.denominator);
201
+ }
202
+ return new Trade({
203
+ routes: [{ inputAmount, outputAmount, route }],
204
+ tradeType,
205
+ });
206
+ }
207
+ /**
208
+ * Constructs a trade from routes by simulating swaps
209
+ *
210
+ * @template TInput The input currency, either Ether or an ERC-20.
211
+ * @template TOutput The output currency, either Ether or an ERC-20.
212
+ * @template TTradeType The type of the trade, either exact in or exact out.
213
+ * @param routes the routes to swap through and how much of the amount should be routed through each
214
+ * @param tradeType whether the trade is an exact input or exact output swap
215
+ * @returns The trade
216
+ */
217
+ static async fromRoutes(routes, tradeType) {
218
+ const swaps = await Promise.all(routes.map(async ({ amount, route }) => {
219
+ const trade = await Trade.fromRoute(route, amount, tradeType);
220
+ return trade.swaps[0];
221
+ }));
222
+ return new Trade({
223
+ routes: swaps,
224
+ tradeType,
225
+ });
226
+ }
227
+ /**
228
+ * Creates a trade without computing the result of swapping through the route. Useful when you have simulated the trade
229
+ * elsewhere and do not have any tick data
230
+ * @template TInput The input currency, either Ether or an ERC-20
231
+ * @template TOutput The output currency, either Ether or an ERC-20
232
+ * @template TTradeType The type of the trade, either exact in or exact out
233
+ * @param constructorArguments The arguments passed to the trade constructor
234
+ * @returns The unchecked trade
235
+ */
236
+ static createUncheckedTrade(constructorArguments) {
237
+ return new Trade({
238
+ ...constructorArguments,
239
+ routes: [
240
+ {
241
+ inputAmount: constructorArguments.inputAmount,
242
+ outputAmount: constructorArguments.outputAmount,
243
+ route: constructorArguments.route,
244
+ },
245
+ ],
246
+ });
247
+ }
248
+ /**
249
+ * Creates a trade without computing the result of swapping through the routes. Useful when you have simulated the trade
250
+ * elsewhere and do not have any tick data
251
+ * @template TInput The input currency, either Ether or an ERC-20
252
+ * @template TOutput The output currency, either Ether or an ERC-20
253
+ * @template TTradeType The type of the trade, either exact in or exact out
254
+ * @param constructorArguments The arguments passed to the trade constructor
255
+ * @returns The unchecked trade
256
+ */
257
+ static createUncheckedTradeWithMultipleRoutes(constructorArguments) {
258
+ return new Trade(constructorArguments);
259
+ }
260
+ /**
261
+ * Construct a trade by passing in the pre-computed property values
262
+ * @param routes The routes through which the trade occurs
263
+ * @param tradeType The type of trade, exact input or exact output
264
+ */
265
+ constructor({ routes, tradeType, }) {
266
+ const inputCurrency = routes[0].inputAmount.currency;
267
+ const outputCurrency = routes[0].outputAmount.currency;
268
+ invariant(routes.every(({ route }) => inputCurrency.equals(route.input)), 'INPUT_CURRENCY_MATCH');
269
+ invariant(routes.every(({ route }) => outputCurrency.equals(route.output)), 'OUTPUT_CURRENCY_MATCH');
270
+ const numPools = routes.map(({ route }) => route.pools.filter(pool => !isTokenizeConversion(pool)).length).reduce((total, cur) => total + cur, 0);
271
+ const poolIDSet = new Set();
272
+ for (const { route } of routes) {
273
+ for (const pool of route.pools) {
274
+ if (!isTokenizeConversion(pool))
275
+ poolIDSet.add(Pool.getPoolId(pool.currency0, pool.currency1, pool.fee, pool.tickSpacing, pool.hooks));
276
+ }
277
+ }
278
+ invariant(numPools === poolIDSet.size, 'POOLS_DUPLICATED');
279
+ this.swaps = routes;
280
+ this.tradeType = tradeType;
281
+ }
282
+ /**
283
+ * Get the minimum amount that must be received from this trade for the given slippage tolerance
284
+ * @param slippageTolerance The tolerance of unfavorable slippage from the execution price of this trade
285
+ * @returns The amount out
286
+ */
287
+ minimumAmountOut(slippageTolerance, amountOut = this.outputAmount) {
288
+ invariant(!slippageTolerance.lessThan(ZERO), 'SLIPPAGE_TOLERANCE');
289
+ if (this.tradeType === TradeType.EXACT_OUTPUT) {
290
+ return amountOut;
291
+ }
292
+ else {
293
+ const slippageAdjustedAmountOut = new Fraction(ONE)
294
+ .subtract(slippageTolerance)
295
+ .multiply(amountOut.quotient).quotient;
296
+ const clampedAmount = JSBI.greaterThan(slippageAdjustedAmountOut, JSBI.BigInt(0))
297
+ ? slippageAdjustedAmountOut
298
+ : JSBI.BigInt(0);
299
+ return CurrencyAmount.fromRawAmount(amountOut.currency, clampedAmount);
300
+ }
301
+ }
302
+ /**
303
+ * Get the maximum amount in that can be spent via this trade for the given slippage tolerance
304
+ * @param slippageTolerance The tolerance of unfavorable slippage from the execution price of this trade
305
+ * @returns The amount in
306
+ */
307
+ maximumAmountIn(slippageTolerance, amountIn = this.inputAmount) {
308
+ invariant(!slippageTolerance.lessThan(ZERO), 'SLIPPAGE_TOLERANCE');
309
+ if (this.tradeType === TradeType.EXACT_INPUT) {
310
+ return amountIn;
311
+ }
312
+ else {
313
+ const slippageAdjustedAmountIn = new Fraction(ONE).add(slippageTolerance).multiply(amountIn.quotient).quotient;
314
+ return CurrencyAmount.fromRawAmount(amountIn.currency, slippageAdjustedAmountIn);
315
+ }
316
+ }
317
+ /**
318
+ * Return the execution price after accounting for slippage tolerance
319
+ * @param slippageTolerance the allowed tolerated slippage
320
+ * @returns The execution price
321
+ */
322
+ worstExecutionPrice(slippageTolerance) {
323
+ return new Price(this.inputAmount.currency, this.outputAmount.currency, this.maximumAmountIn(slippageTolerance).quotient, this.minimumAmountOut(slippageTolerance).quotient);
324
+ }
325
+ /**
326
+ * Given a list of pools, and a fixed amount in, returns the top `maxNumResults` trades that go from an input currency
327
+ * amount to an output currency, making at most `maxHops` hops.
328
+ * Note this does not consider aggregation, as routes are linear. It's possible a better route exists by splitting
329
+ * the amount in among multiple routes.
330
+ * @param pools the pools to consider in finding the best trade
331
+ * @param nextAmountIn exact amount of input currency to spend
332
+ * @param currencyOut the desired currency out
333
+ * @param maxNumResults maximum number of results to return
334
+ * @param maxHops maximum number of hops a returned trade can make, e.g. 1 hop goes through a single pool
335
+ * @param currentPools used in recursion; the current list of pools
336
+ * @param currencyAmountIn used in recursion; the original value of the currencyAmountIn parameter
337
+ * @param bestTrades used in recursion; the current list of best trades
338
+ * @returns The exact in trade
339
+ */
340
+ static async bestTradeExactIn(pools, currencyAmountIn, currencyOut, { maxNumResults = 3, maxHops = 3 } = {},
341
+ // used in recursion.
342
+ currentPools = [], nextAmountIn = currencyAmountIn, bestTrades = []) {
343
+ invariant(pools.length > 0, 'POOLS');
344
+ invariant(maxHops > 0, 'MAX_HOPS');
345
+ invariant(currencyAmountIn === nextAmountIn || currentPools.length > 0, 'INVALID_RECURSION');
346
+ const amountIn = nextAmountIn;
347
+ for (let i = 0; i < pools.length; i++) {
348
+ const pool = pools[i];
349
+ // pool irrelevant
350
+ if (!pool.currency0.equals(amountIn.currency) && !pool.currency1.equals(amountIn.currency))
351
+ continue;
352
+ let amountOut;
353
+ try {
354
+ ;
355
+ [amountOut] = await pool.getOutputAmount(amountIn);
356
+ }
357
+ catch (error) {
358
+ // input too low
359
+ if (error.isInsufficientInputAmountError) {
360
+ continue;
361
+ }
362
+ throw error;
363
+ }
364
+ // we have arrived at the output currency, so this is the final trade of one of the paths
365
+ if (amountOut.currency.equals(currencyOut)) {
366
+ sortedInsert(bestTrades, await Trade.fromRoute(new Route([...currentPools, pool], currencyAmountIn.currency, currencyOut), currencyAmountIn, TradeType.EXACT_INPUT), maxNumResults, tradeComparator);
367
+ }
368
+ else if (maxHops > 1 && pools.length > 1) {
369
+ const poolsExcludingThisPool = pools.slice(0, i).concat(pools.slice(i + 1, pools.length));
370
+ // otherwise, consider all the other paths that lead from this currency as long as we have not exceeded maxHops
371
+ await Trade.bestTradeExactIn(poolsExcludingThisPool, currencyAmountIn, currencyOut, {
372
+ maxNumResults,
373
+ maxHops: maxHops - 1,
374
+ }, [...currentPools, pool], amountOut, bestTrades);
375
+ }
376
+ }
377
+ return bestTrades;
378
+ }
379
+ /**
380
+ * similar to the above method but instead targets a fixed output amount
381
+ * given a list of pools, and a fixed amount out, returns the top `maxNumResults` trades that go from an input currency
382
+ * to an output currency amount, making at most `maxHops` hops
383
+ * note this does not consider aggregation, as routes are linear. it's possible a better route exists by splitting
384
+ * the amount in among multiple routes.
385
+ * @param pools the pools to consider in finding the best trade
386
+ * @param currencyIn the currency to spend
387
+ * @param currencyAmountOut the desired currency amount out
388
+ * @param nextAmountOut the exact amount of currency out
389
+ * @param maxNumResults maximum number of results to return
390
+ * @param maxHops maximum number of hops a returned trade can make, e.g. 1 hop goes through a single pool
391
+ * @param currentPools used in recursion; the current list of pools
392
+ * @param bestTrades used in recursion; the current list of best trades
393
+ * @returns The exact out trade
394
+ */
395
+ static async bestTradeExactOut(pools, currencyIn, currencyAmountOut, { maxNumResults = 3, maxHops = 3 } = {},
396
+ // used in recursion.
397
+ currentPools = [], nextAmountOut = currencyAmountOut, bestTrades = []) {
398
+ invariant(pools.length > 0, 'POOLS');
399
+ invariant(maxHops > 0, 'MAX_HOPS');
400
+ invariant(currencyAmountOut === nextAmountOut || currentPools.length > 0, 'INVALID_RECURSION');
401
+ const amountOut = nextAmountOut;
402
+ for (let i = 0; i < pools.length; i++) {
403
+ const pool = pools[i];
404
+ // pool irrelevant
405
+ if (!pool.currency0.equals(amountOut.currency) && !pool.currency1.equals(amountOut.currency))
406
+ continue;
407
+ let amountIn;
408
+ try {
409
+ ;
410
+ [amountIn] = await pool.getInputAmount(amountOut);
411
+ }
412
+ catch (error) {
413
+ // not enough liquidity in this pool
414
+ if (error.isInsufficientReservesError) {
415
+ continue;
416
+ }
417
+ throw error;
418
+ }
419
+ // we have arrived at the input currency, so this is the first trade of one of the paths
420
+ if (amountIn.currency.equals(currencyIn)) {
421
+ sortedInsert(bestTrades, await Trade.fromRoute(new Route([pool, ...currentPools], currencyIn, currencyAmountOut.currency), currencyAmountOut, TradeType.EXACT_OUTPUT), maxNumResults, tradeComparator);
422
+ }
423
+ else if (maxHops > 1 && pools.length > 1) {
424
+ const poolsExcludingThisPool = pools.slice(0, i).concat(pools.slice(i + 1, pools.length));
425
+ // otherwise, consider all the other paths that arrive at this currency as long as we have not exceeded maxHops
426
+ await Trade.bestTradeExactOut(poolsExcludingThisPool, currencyIn, currencyAmountOut, {
427
+ maxNumResults,
428
+ maxHops: maxHops - 1,
429
+ }, [pool, ...currentPools], amountIn, bestTrades);
430
+ }
431
+ }
432
+ return bestTrades;
433
+ }
434
+ }
435
+ //# sourceMappingURL=trade.js.map