@kittycorn-labs/v2-sdk 1.0.13 → 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 (74) hide show
  1. package/README.md +9 -0
  2. package/dist/{constants.d.ts → cjs/src/constants.d.ts} +19 -19
  3. package/dist/cjs/src/constants.js +23 -0
  4. package/dist/cjs/src/constants.js.map +1 -0
  5. package/dist/{entities → cjs/src/entities}/index.d.ts +3 -3
  6. package/dist/cjs/src/entities/index.js +7 -0
  7. package/dist/cjs/src/entities/index.js.map +1 -0
  8. package/dist/{entities → cjs/src/entities}/pair.d.ts +147 -147
  9. package/dist/cjs/src/entities/pair.js +318 -0
  10. package/dist/cjs/src/entities/pair.js.map +1 -0
  11. package/dist/{entities → cjs/src/entities}/route.d.ts +12 -12
  12. package/dist/cjs/src/entities/route.js +45 -0
  13. package/dist/cjs/src/entities/route.js.map +1 -0
  14. package/dist/{entities → cjs/src/entities}/trade.d.ts +103 -103
  15. package/dist/cjs/src/entities/trade.js +263 -0
  16. package/dist/cjs/src/entities/trade.js.map +1 -0
  17. package/dist/{errors.d.ts → cjs/src/errors.d.ts} +16 -16
  18. package/dist/cjs/src/errors.js +34 -0
  19. package/dist/cjs/src/errors.js.map +1 -0
  20. package/dist/{index.d.ts → cjs/src/index.d.ts} +4 -4
  21. package/dist/cjs/src/index.js +12 -0
  22. package/dist/cjs/src/index.js.map +1 -0
  23. package/dist/{router.d.ts → cjs/src/router.d.ts} +64 -64
  24. package/dist/cjs/src/router.js +94 -0
  25. package/dist/cjs/src/router.js.map +1 -0
  26. package/dist/esm/package.json +1 -0
  27. package/dist/esm/src/constants.d.ts +19 -0
  28. package/dist/esm/src/constants.js +19 -0
  29. package/dist/esm/src/constants.js.map +1 -0
  30. package/dist/esm/src/entities/index.d.ts +3 -0
  31. package/dist/esm/src/entities/index.js +4 -0
  32. package/dist/esm/src/entities/index.js.map +1 -0
  33. package/dist/esm/src/entities/pair.d.ts +147 -0
  34. package/dist/esm/src/entities/pair.js +312 -0
  35. package/dist/esm/src/entities/pair.js.map +1 -0
  36. package/dist/esm/src/entities/route.d.ts +12 -0
  37. package/dist/esm/src/entities/route.js +40 -0
  38. package/dist/esm/src/entities/route.js.map +1 -0
  39. package/dist/esm/src/entities/trade.d.ts +103 -0
  40. package/dist/esm/src/entities/trade.js +256 -0
  41. package/dist/esm/src/entities/trade.js.map +1 -0
  42. package/dist/esm/src/errors.d.ts +16 -0
  43. package/dist/esm/src/errors.js +29 -0
  44. package/dist/esm/src/errors.js.map +1 -0
  45. package/dist/esm/src/index.d.ts +4 -0
  46. package/dist/esm/src/index.js +5 -0
  47. package/dist/esm/src/index.js.map +1 -0
  48. package/dist/esm/src/router.d.ts +64 -0
  49. package/dist/esm/src/router.js +89 -0
  50. package/dist/esm/src/router.js.map +1 -0
  51. package/dist/types/src/constants.d.ts +20 -0
  52. package/dist/types/src/constants.d.ts.map +1 -0
  53. package/dist/types/src/entities/index.d.ts +4 -0
  54. package/dist/types/src/entities/index.d.ts.map +1 -0
  55. package/dist/types/src/entities/pair.d.ts +148 -0
  56. package/dist/types/src/entities/pair.d.ts.map +1 -0
  57. package/dist/types/src/entities/route.d.ts +13 -0
  58. package/dist/types/src/entities/route.d.ts.map +1 -0
  59. package/dist/types/src/entities/trade.d.ts +104 -0
  60. package/dist/types/src/entities/trade.d.ts.map +1 -0
  61. package/dist/types/src/errors.d.ts +17 -0
  62. package/dist/types/src/errors.d.ts.map +1 -0
  63. package/dist/types/src/index.d.ts +5 -0
  64. package/dist/types/src/index.d.ts.map +1 -0
  65. package/dist/types/src/router.d.ts +65 -0
  66. package/dist/types/src/router.d.ts.map +1 -0
  67. package/package.json +23 -34
  68. package/dist/index.js +0 -8
  69. package/dist/v2-sdk.cjs.development.js +0 -897
  70. package/dist/v2-sdk.cjs.development.js.map +0 -1
  71. package/dist/v2-sdk.cjs.production.min.js +0 -2
  72. package/dist/v2-sdk.cjs.production.min.js.map +0 -1
  73. package/dist/v2-sdk.esm.js +0 -880
  74. package/dist/v2-sdk.esm.js.map +0 -1
@@ -0,0 +1,318 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Pair = exports.computePairAddress = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const address_1 = require("@ethersproject/address");
6
+ const bignumber_1 = require("@ethersproject/bignumber");
7
+ const solidity_1 = require("@ethersproject/solidity");
8
+ const sdk_core_1 = require("@kittycorn-labs/sdk-core");
9
+ const jsbi_1 = tslib_1.__importDefault(require("jsbi"));
10
+ const tiny_invariant_1 = tslib_1.__importDefault(require("tiny-invariant"));
11
+ const constants_1 = require("../constants");
12
+ const errors_1 = require("../errors");
13
+ const computePairAddress = ({ factoryAddress, tokenA, tokenB, }) => {
14
+ const [token0, token1] = tokenA.sortsBefore(tokenB) ? [tokenA, tokenB] : [tokenB, tokenA]; // does safety checks
15
+ return (0, address_1.getCreate2Address)(factoryAddress, (0, solidity_1.keccak256)(['bytes'], [(0, solidity_1.pack)(['address', 'address'], [token0.address, token1.address])]), constants_1.INIT_CODE_HASH);
16
+ };
17
+ exports.computePairAddress = computePairAddress;
18
+ class Pair {
19
+ static getAddress(tokenA, tokenB) {
20
+ var _a;
21
+ const factoryAddress = (_a = constants_1.FACTORY_ADDRESS_MAP[tokenA.chainId]) !== null && _a !== void 0 ? _a : constants_1.FACTORY_ADDRESS;
22
+ return (0, exports.computePairAddress)({ factoryAddress, tokenA, tokenB });
23
+ }
24
+ constructor(currencyAmountA, tokenAmountB) {
25
+ const tokenAmounts = currencyAmountA.currency.sortsBefore(tokenAmountB.currency) // does safety checks
26
+ ? [currencyAmountA, tokenAmountB]
27
+ : [tokenAmountB, currencyAmountA];
28
+ this.liquidityToken = new sdk_core_1.Token(tokenAmounts[0].currency.chainId, Pair.getAddress(tokenAmounts[0].currency, tokenAmounts[1].currency), 18, 'UNI-V2', 'Uniswap V2');
29
+ this.tokenAmounts = tokenAmounts;
30
+ }
31
+ /**
32
+ * Returns true if the token is either token0 or token1
33
+ * @param token to check
34
+ */
35
+ involvesToken(token) {
36
+ return token.equals(this.token0) || token.equals(this.token1);
37
+ }
38
+ /**
39
+ * Returns the current mid price of the pair in terms of token0, i.e. the ratio of reserve1 to reserve0
40
+ */
41
+ get token0Price() {
42
+ const result = this.tokenAmounts[1].divide(this.tokenAmounts[0]);
43
+ return new sdk_core_1.Price(this.token0, this.token1, result.denominator, result.numerator);
44
+ }
45
+ /**
46
+ * Returns the current mid price of the pair in terms of token1, i.e. the ratio of reserve0 to reserve1
47
+ */
48
+ get token1Price() {
49
+ const result = this.tokenAmounts[0].divide(this.tokenAmounts[1]);
50
+ return new sdk_core_1.Price(this.token1, this.token0, result.denominator, result.numerator);
51
+ }
52
+ /**
53
+ * Return the price of the given token in terms of the other token in the pair.
54
+ * @param token token to return price of
55
+ */
56
+ priceOf(token) {
57
+ (0, tiny_invariant_1.default)(this.involvesToken(token), 'TOKEN');
58
+ return token.equals(this.token0) ? this.token0Price : this.token1Price;
59
+ }
60
+ /**
61
+ * Returns the chain ID of the tokens in the pair.
62
+ */
63
+ get chainId() {
64
+ return this.token0.chainId;
65
+ }
66
+ get token0() {
67
+ return this.tokenAmounts[0].currency;
68
+ }
69
+ get token1() {
70
+ return this.tokenAmounts[1].currency;
71
+ }
72
+ get reserve0() {
73
+ return this.tokenAmounts[0];
74
+ }
75
+ get reserve1() {
76
+ return this.tokenAmounts[1];
77
+ }
78
+ reserveOf(token) {
79
+ (0, tiny_invariant_1.default)(this.involvesToken(token), 'TOKEN');
80
+ return token.equals(this.token0) ? this.reserve0 : this.reserve1;
81
+ }
82
+ /**
83
+ * getAmountOut is the linear algebra of reserve ratio against amountIn:amountOut.
84
+ * https://ethereum.stackexchange.com/questions/101629/what-is-math-for-uniswap-calculates-the-amountout-and-amountin-why-997-and-1000
85
+ * has the math deduction for the reserve calculation without fee-on-transfer fees.
86
+ *
87
+ * With fee-on-transfer tax, intuitively it's just:
88
+ * inputAmountWithFeeAndTax = 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn
89
+ * = (1 - amountIn.sellFeesBips / 10000) * amountInWithFee
90
+ * where amountInWithFee is the amountIn after taking out the LP fees
91
+ * outputAmountWithTax = amountOut * (1 - amountOut.buyFeesBips / 10000)
92
+ *
93
+ * But we are illustrating the math deduction below to ensure that's the case.
94
+ *
95
+ * before swap A * B = K where A = reserveIn B = reserveOut
96
+ *
97
+ * after swap A' * B' = K where only k is a constant value
98
+ *
99
+ * getAmountOut
100
+ *
101
+ * A' = A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn # here 0.3% is deducted
102
+ * B' = B - amountOut * (1 - amountOut.buyFeesBips / 10000)
103
+ * amountOut = (B - B') / (1 - amountOut.buyFeesBips / 10000) # where A' * B' still is k
104
+ * = (B - K/(A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn))
105
+ * /
106
+ * (1 - amountOut.buyFeesBips / 10000)
107
+ * = (B - AB/(A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn))
108
+ * /
109
+ * (1 - amountOut.buyFeesBips / 10000)
110
+ * = ((BA + B * 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn - AB)/(A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn))
111
+ * /
112
+ * (1 - amountOut.buyFeesBips / 10000)
113
+ * = (B * 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn / (A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn)
114
+ * /
115
+ * (1 - amountOut.buyFeesBips / 10000)
116
+ * amountOut * (1 - amountOut.buyFeesBips / 10000) = (B * 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn
117
+ * /
118
+ * (A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn)
119
+ *
120
+ * outputAmountWithTax = (B * 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn
121
+ * /
122
+ * (A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn)
123
+ * = (B * 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn * 1000
124
+ * /
125
+ * ((A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn) * 1000)
126
+ * = (B * (1 - amountIn.sellFeesBips / 10000) 997 * * amountIn
127
+ * /
128
+ * (1000 * A + (1 - amountIn.sellFeesBips / 10000) * 997 * amountIn)
129
+ * = (B * (1 - amountIn.sellFeesBips / 10000) * inputAmountWithFee)
130
+ * /
131
+ * (1000 * A + (1 - amountIn.sellFeesBips / 10000) * inputAmountWithFee)
132
+ * = (B * inputAmountWithFeeAndTax)
133
+ * /
134
+ * (1000 * A + inputAmountWithFeeAndTax)
135
+ *
136
+ * inputAmountWithFeeAndTax = (1 - amountIn.sellFeesBips / 10000) * inputAmountWithFee
137
+ * outputAmountWithTax = amountOut * (1 - amountOut.buyFeesBips / 10000)
138
+ *
139
+ * @param inputAmount
140
+ * @param calculateFotFees
141
+ */
142
+ getOutputAmount(inputAmount, calculateFotFees = true) {
143
+ (0, tiny_invariant_1.default)(this.involvesToken(inputAmount.currency), 'TOKEN');
144
+ if (jsbi_1.default.equal(this.reserve0.quotient, constants_1.ZERO) || jsbi_1.default.equal(this.reserve1.quotient, constants_1.ZERO)) {
145
+ throw new errors_1.InsufficientReservesError();
146
+ }
147
+ const inputReserve = this.reserveOf(inputAmount.currency);
148
+ const outputReserve = this.reserveOf(inputAmount.currency.equals(this.token0) ? this.token1 : this.token0);
149
+ const percentAfterSellFees = calculateFotFees ? this.derivePercentAfterSellFees(inputAmount) : constants_1.ZERO_PERCENT;
150
+ const inputAmountAfterTax = percentAfterSellFees.greaterThan(constants_1.ZERO_PERCENT)
151
+ ? sdk_core_1.CurrencyAmount.fromRawAmount(inputAmount.currency, percentAfterSellFees.multiply(inputAmount).quotient // fraction.quotient will round down by itself, which is desired
152
+ )
153
+ : inputAmount;
154
+ const inputAmountWithFeeAndAfterTax = jsbi_1.default.multiply(inputAmountAfterTax.quotient, constants_1._997);
155
+ const numerator = jsbi_1.default.multiply(inputAmountWithFeeAndAfterTax, outputReserve.quotient);
156
+ const denominator = jsbi_1.default.add(jsbi_1.default.multiply(inputReserve.quotient, constants_1._1000), inputAmountWithFeeAndAfterTax);
157
+ const outputAmount = sdk_core_1.CurrencyAmount.fromRawAmount(inputAmount.currency.equals(this.token0) ? this.token1 : this.token0, jsbi_1.default.divide(numerator, denominator) // JSBI.divide will round down by itself, which is desired
158
+ );
159
+ if (jsbi_1.default.equal(outputAmount.quotient, constants_1.ZERO)) {
160
+ throw new errors_1.InsufficientInputAmountError();
161
+ }
162
+ const percentAfterBuyFees = calculateFotFees ? this.derivePercentAfterBuyFees(outputAmount) : constants_1.ZERO_PERCENT;
163
+ const outputAmountAfterTax = percentAfterBuyFees.greaterThan(constants_1.ZERO_PERCENT)
164
+ ? sdk_core_1.CurrencyAmount.fromRawAmount(outputAmount.currency, outputAmount.multiply(percentAfterBuyFees).quotient // fraction.quotient will round down by itself, which is desired
165
+ )
166
+ : outputAmount;
167
+ if (jsbi_1.default.equal(outputAmountAfterTax.quotient, constants_1.ZERO)) {
168
+ throw new errors_1.InsufficientInputAmountError();
169
+ }
170
+ return [
171
+ outputAmountAfterTax,
172
+ new Pair(inputReserve.add(inputAmountAfterTax), outputReserve.subtract(outputAmountAfterTax)),
173
+ ];
174
+ }
175
+ /**
176
+ * getAmountIn is the linear algebra of reserve ratio against amountIn:amountOut.
177
+ * https://ethereum.stackexchange.com/questions/101629/what-is-math-for-uniswap-calculates-the-amountout-and-amountin-why-997-and-1000
178
+ * has the math deduction for the reserve calculation without fee-on-transfer fees.
179
+ *
180
+ * With fee-on-transfer fees, intuitively it's just:
181
+ * outputAmountWithTax = amountOut / (1 - amountOut.buyFeesBips / 10000)
182
+ * inputAmountWithTax = amountIn / (1 - amountIn.sellFeesBips / 10000) / 0.997
183
+ *
184
+ * But we are illustrating the math deduction below to ensure that's the case.
185
+ *
186
+ * before swap A * B = K where A = reserveIn B = reserveOut
187
+ *
188
+ * after swap A' * B' = K where only k is a constant value
189
+ *
190
+ * getAmountIn
191
+ *
192
+ * B' = B - amountOut * (1 - amountOut.buyFeesBips / 10000)
193
+ * A' = A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn # here 0.3% is deducted
194
+ * amountIn = (A' - A) / (0.997 * (1 - amountIn.sellFeesBips / 10000))
195
+ * = (K / (B - amountOut / (1 - amountOut.buyFeesBips / 10000)) - A)
196
+ * /
197
+ * (0.997 * (1 - amountIn.sellFeesBips / 10000))
198
+ * = (AB / (B - amountOut / (1 - amountOut.buyFeesBips / 10000)) - A)
199
+ * /
200
+ * (0.997 * (1 - amountIn.sellFeesBips / 10000))
201
+ * = ((AB - AB + A * amountOut / (1 - amountOut.buyFeesBips / 10000)) / (B - amountOut / (1 - amountOut.buyFeesBips / 10000)))
202
+ * /
203
+ * (0.997 * (1 - amountIn.sellFeesBips / 10000))
204
+ * = ((A * amountOut / (1 - amountOut.buyFeesBips / 10000)) / (B - amountOut / (1 - amountOut.buyFeesBips / 10000)))
205
+ * /
206
+ * (0.997 * (1 - amountIn.sellFeesBips / 10000))
207
+ * = ((A * 1000 * amountOut / (1 - amountOut.buyFeesBips / 10000)) / (B - amountOut / (1 - amountOut.buyFeesBips / 10000)))
208
+ * /
209
+ * (997 * (1 - amountIn.sellFeesBips / 10000))
210
+ *
211
+ * outputAmountWithTax = amountOut / (1 - amountOut.buyFeesBips / 10000)
212
+ * inputAmountWithTax = amountIn / (997 * (1 - amountIn.sellFeesBips / 10000))
213
+ * = (A * outputAmountWithTax * 1000) / ((B - outputAmountWithTax) * 997)
214
+ *
215
+ * @param outputAmount
216
+ */
217
+ getInputAmount(outputAmount, calculateFotFees = true) {
218
+ (0, tiny_invariant_1.default)(this.involvesToken(outputAmount.currency), 'TOKEN');
219
+ const percentAfterBuyFees = calculateFotFees ? this.derivePercentAfterBuyFees(outputAmount) : constants_1.ZERO_PERCENT;
220
+ const outputAmountBeforeTax = percentAfterBuyFees.greaterThan(constants_1.ZERO_PERCENT)
221
+ ? sdk_core_1.CurrencyAmount.fromRawAmount(outputAmount.currency, jsbi_1.default.add(outputAmount.divide(percentAfterBuyFees).quotient, constants_1.ONE) // add 1 for rounding up
222
+ )
223
+ : outputAmount;
224
+ if (jsbi_1.default.equal(this.reserve0.quotient, constants_1.ZERO) ||
225
+ jsbi_1.default.equal(this.reserve1.quotient, constants_1.ZERO) ||
226
+ jsbi_1.default.greaterThanOrEqual(outputAmount.quotient, this.reserveOf(outputAmount.currency).quotient) ||
227
+ jsbi_1.default.greaterThanOrEqual(outputAmountBeforeTax.quotient, this.reserveOf(outputAmount.currency).quotient)) {
228
+ throw new errors_1.InsufficientReservesError();
229
+ }
230
+ const outputReserve = this.reserveOf(outputAmount.currency);
231
+ const inputReserve = this.reserveOf(outputAmount.currency.equals(this.token0) ? this.token1 : this.token0);
232
+ const numerator = jsbi_1.default.multiply(jsbi_1.default.multiply(inputReserve.quotient, outputAmountBeforeTax.quotient), constants_1._1000);
233
+ const denominator = jsbi_1.default.multiply(jsbi_1.default.subtract(outputReserve.quotient, outputAmountBeforeTax.quotient), constants_1._997);
234
+ const inputAmount = sdk_core_1.CurrencyAmount.fromRawAmount(outputAmount.currency.equals(this.token0) ? this.token1 : this.token0, jsbi_1.default.add(jsbi_1.default.divide(numerator, denominator), constants_1.ONE) // add 1 here is part of the formula, no rounding needed here, since there will not be decimal at this point
235
+ );
236
+ const percentAfterSellFees = calculateFotFees ? this.derivePercentAfterSellFees(inputAmount) : constants_1.ZERO_PERCENT;
237
+ const inputAmountBeforeTax = percentAfterSellFees.greaterThan(constants_1.ZERO_PERCENT)
238
+ ? sdk_core_1.CurrencyAmount.fromRawAmount(inputAmount.currency, jsbi_1.default.add(inputAmount.divide(percentAfterSellFees).quotient, constants_1.ONE) // add 1 for rounding up
239
+ )
240
+ : inputAmount;
241
+ return [inputAmountBeforeTax, new Pair(inputReserve.add(inputAmount), outputReserve.subtract(outputAmount))];
242
+ }
243
+ getLiquidityMinted(totalSupply, tokenAmountA, tokenAmountB) {
244
+ (0, tiny_invariant_1.default)(totalSupply.currency.equals(this.liquidityToken), 'LIQUIDITY');
245
+ const tokenAmounts = tokenAmountA.currency.sortsBefore(tokenAmountB.currency) // does safety checks
246
+ ? [tokenAmountA, tokenAmountB]
247
+ : [tokenAmountB, tokenAmountA];
248
+ (0, tiny_invariant_1.default)(tokenAmounts[0].currency.equals(this.token0) && tokenAmounts[1].currency.equals(this.token1), 'TOKEN');
249
+ let liquidity;
250
+ if (jsbi_1.default.equal(totalSupply.quotient, constants_1.ZERO)) {
251
+ liquidity = jsbi_1.default.subtract((0, sdk_core_1.sqrt)(jsbi_1.default.multiply(tokenAmounts[0].quotient, tokenAmounts[1].quotient)), constants_1.MINIMUM_LIQUIDITY);
252
+ }
253
+ else {
254
+ const amount0 = jsbi_1.default.divide(jsbi_1.default.multiply(tokenAmounts[0].quotient, totalSupply.quotient), this.reserve0.quotient);
255
+ const amount1 = jsbi_1.default.divide(jsbi_1.default.multiply(tokenAmounts[1].quotient, totalSupply.quotient), this.reserve1.quotient);
256
+ liquidity = jsbi_1.default.lessThanOrEqual(amount0, amount1) ? amount0 : amount1;
257
+ }
258
+ if (!jsbi_1.default.greaterThan(liquidity, constants_1.ZERO)) {
259
+ throw new errors_1.InsufficientInputAmountError();
260
+ }
261
+ return sdk_core_1.CurrencyAmount.fromRawAmount(this.liquidityToken, liquidity);
262
+ }
263
+ getLiquidityValue(token, totalSupply, liquidity, feeOn = false, kLast) {
264
+ (0, tiny_invariant_1.default)(this.involvesToken(token), 'TOKEN');
265
+ (0, tiny_invariant_1.default)(totalSupply.currency.equals(this.liquidityToken), 'TOTAL_SUPPLY');
266
+ (0, tiny_invariant_1.default)(liquidity.currency.equals(this.liquidityToken), 'LIQUIDITY');
267
+ (0, tiny_invariant_1.default)(jsbi_1.default.lessThanOrEqual(liquidity.quotient, totalSupply.quotient), 'LIQUIDITY');
268
+ let totalSupplyAdjusted;
269
+ if (!feeOn) {
270
+ totalSupplyAdjusted = totalSupply;
271
+ }
272
+ else {
273
+ (0, tiny_invariant_1.default)(!!kLast, 'K_LAST');
274
+ const kLastParsed = jsbi_1.default.BigInt(kLast);
275
+ if (!jsbi_1.default.equal(kLastParsed, constants_1.ZERO)) {
276
+ const rootK = (0, sdk_core_1.sqrt)(jsbi_1.default.multiply(this.reserve0.quotient, this.reserve1.quotient));
277
+ const rootKLast = (0, sdk_core_1.sqrt)(kLastParsed);
278
+ if (jsbi_1.default.greaterThan(rootK, rootKLast)) {
279
+ const numerator = jsbi_1.default.multiply(totalSupply.quotient, jsbi_1.default.subtract(rootK, rootKLast));
280
+ const denominator = jsbi_1.default.add(jsbi_1.default.multiply(rootK, constants_1.FIVE), rootKLast);
281
+ const feeLiquidity = jsbi_1.default.divide(numerator, denominator);
282
+ totalSupplyAdjusted = totalSupply.add(sdk_core_1.CurrencyAmount.fromRawAmount(this.liquidityToken, feeLiquidity));
283
+ }
284
+ else {
285
+ totalSupplyAdjusted = totalSupply;
286
+ }
287
+ }
288
+ else {
289
+ totalSupplyAdjusted = totalSupply;
290
+ }
291
+ }
292
+ return sdk_core_1.CurrencyAmount.fromRawAmount(token, jsbi_1.default.divide(jsbi_1.default.multiply(liquidity.quotient, this.reserveOf(token).quotient), totalSupplyAdjusted.quotient));
293
+ }
294
+ derivePercentAfterSellFees(inputAmount) {
295
+ const sellFeeBips = this.token0.wrapped.equals(inputAmount.wrapped.currency)
296
+ ? this.token0.wrapped.sellFeeBps
297
+ : this.token1.wrapped.sellFeeBps;
298
+ if (sellFeeBips === null || sellFeeBips === void 0 ? void 0 : sellFeeBips.gt(bignumber_1.BigNumber.from(0))) {
299
+ return constants_1.ONE_HUNDRED_PERCENT.subtract(new sdk_core_1.Percent(jsbi_1.default.BigInt(sellFeeBips)).divide(constants_1.BASIS_POINTS));
300
+ }
301
+ else {
302
+ return constants_1.ZERO_PERCENT;
303
+ }
304
+ }
305
+ derivePercentAfterBuyFees(outputAmount) {
306
+ const buyFeeBps = this.token0.wrapped.equals(outputAmount.wrapped.currency)
307
+ ? this.token0.wrapped.buyFeeBps
308
+ : this.token1.wrapped.buyFeeBps;
309
+ if (buyFeeBps === null || buyFeeBps === void 0 ? void 0 : buyFeeBps.gt(bignumber_1.BigNumber.from(0))) {
310
+ return constants_1.ONE_HUNDRED_PERCENT.subtract(new sdk_core_1.Percent(jsbi_1.default.BigInt(buyFeeBps)).divide(constants_1.BASIS_POINTS));
311
+ }
312
+ else {
313
+ return constants_1.ZERO_PERCENT;
314
+ }
315
+ }
316
+ }
317
+ exports.Pair = Pair;
318
+ //# sourceMappingURL=pair.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pair.js","sourceRoot":"","sources":["../../../../src/entities/pair.ts"],"names":[],"mappings":";;;;AAAA,oDAA0D;AAC1D,wDAAoD;AACpD,sDAAyD;AACzD,uDAAiG;AACjG,wDAAuB;AACvB,4EAAsC;AAEtC,4CAaqB;AACrB,sCAAmF;AAE5E,MAAM,kBAAkB,GAAG,CAAC,EACjC,cAAc,EACd,MAAM,EACN,MAAM,GAKP,EAAU,EAAE;IACX,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA,CAAC,qBAAqB;IAC/G,OAAO,IAAA,2BAAiB,EACtB,cAAc,EACd,IAAA,oBAAS,EAAC,CAAC,OAAO,CAAC,EAAE,CAAC,IAAA,eAAI,EAAC,CAAC,SAAS,EAAE,SAAS,CAAC,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EACtF,0BAAc,CACf,CAAA;AACH,CAAC,CAAA;AAfY,QAAA,kBAAkB,sBAe9B;AACD,MAAa,IAAI;IAIR,MAAM,CAAC,UAAU,CAAC,MAAa,EAAE,MAAa;;QACn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AAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,QAAQ,CAAC;YAC1E,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU;YAChC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAA;QAClC,IAAI,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,EAAE,CAAC,qBAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE;YACtC,OAAO,+BAAmB,CAAC,QAAQ,CAAC,IAAI,kBAAO,CAAC,cAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,wBAAY,CAAC,CAAC,CAAA;SAChG;aAAM;YACL,OAAO,wBAAY,CAAA;SACpB;IACH,CAAC;IAEO,yBAAyB,CAAC,YAAmC;QACnE,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,QAAQ,CAAC;YACzE,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS;YAC/B,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAA;QACjC,IAAI,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,EAAE,CAAC,qBAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE;YACpC,OAAO,+BAAmB,CAAC,QAAQ,CAAC,IAAI,kBAAO,CAAC,cAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,wBAAY,CAAC,CAAC,CAAA;SAC9F;aAAM;YACL,OAAO,wBAAY,CAAA;SACpB;IACH,CAAC;CACF;AA7WD,oBA6WC"}
@@ -1,12 +1,12 @@
1
- import { Currency, Price, Token } from '@kittycorn-labs/sdk-core';
2
- import { Pair } from './pair';
3
- export declare class Route<TInput extends Currency, TOutput extends Currency> {
4
- readonly pairs: Pair[];
5
- readonly path: Token[];
6
- readonly input: TInput;
7
- readonly output: TOutput;
8
- constructor(pairs: Pair[], input: TInput, output: TOutput);
9
- private _midPrice;
10
- get midPrice(): Price<TInput, TOutput>;
11
- get chainId(): number;
12
- }
1
+ import { Currency, Price, Token } from '@kittycorn-labs/sdk-core';
2
+ import { Pair } from './pair';
3
+ export declare class Route<TInput extends Currency, TOutput extends Currency> {
4
+ readonly pairs: Pair[];
5
+ readonly path: Token[];
6
+ readonly input: TInput;
7
+ readonly output: TOutput;
8
+ constructor(pairs: Pair[], input: TInput, output: TOutput);
9
+ private _midPrice;
10
+ get midPrice(): Price<TInput, TOutput>;
11
+ get chainId(): number;
12
+ }
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Route = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const tiny_invariant_1 = tslib_1.__importDefault(require("tiny-invariant"));
6
+ const sdk_core_1 = require("@kittycorn-labs/sdk-core");
7
+ class Route {
8
+ constructor(pairs, input, output) {
9
+ this._midPrice = null;
10
+ (0, tiny_invariant_1.default)(pairs.length > 0, 'PAIRS');
11
+ const chainId = pairs[0].chainId;
12
+ (0, tiny_invariant_1.default)(pairs.every((pair) => pair.chainId === chainId), 'CHAIN_IDS');
13
+ const wrappedInput = input.wrapped;
14
+ (0, tiny_invariant_1.default)(pairs[0].involvesToken(wrappedInput), 'INPUT');
15
+ (0, tiny_invariant_1.default)(typeof output === 'undefined' || pairs[pairs.length - 1].involvesToken(output.wrapped), 'OUTPUT');
16
+ const path = [wrappedInput];
17
+ for (const [i, pair] of pairs.entries()) {
18
+ const currentInput = path[i];
19
+ (0, tiny_invariant_1.default)(currentInput.equals(pair.token0) || currentInput.equals(pair.token1), 'PATH');
20
+ const output = currentInput.equals(pair.token0) ? pair.token1 : pair.token0;
21
+ path.push(output);
22
+ }
23
+ this.pairs = pairs;
24
+ this.path = path;
25
+ this.input = input;
26
+ this.output = output;
27
+ }
28
+ get midPrice() {
29
+ if (this._midPrice !== null)
30
+ return this._midPrice;
31
+ const prices = [];
32
+ for (const [i, pair] of this.pairs.entries()) {
33
+ prices.push(this.path[i].equals(pair.token0)
34
+ ? new sdk_core_1.Price(pair.reserve0.currency, pair.reserve1.currency, pair.reserve0.quotient, pair.reserve1.quotient)
35
+ : new sdk_core_1.Price(pair.reserve1.currency, pair.reserve0.currency, pair.reserve1.quotient, pair.reserve0.quotient));
36
+ }
37
+ const reduced = prices.slice(1).reduce((accumulator, currentValue) => accumulator.multiply(currentValue), prices[0]);
38
+ return (this._midPrice = new sdk_core_1.Price(this.input, this.output, reduced.denominator, reduced.numerator));
39
+ }
40
+ get chainId() {
41
+ return this.pairs[0].chainId;
42
+ }
43
+ }
44
+ exports.Route = Route;
45
+ //# sourceMappingURL=route.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route.js","sourceRoot":"","sources":["../../../../src/entities/route.ts"],"names":[],"mappings":";;;;AAAA,4EAAsC;AACtC,uDAAiE;AAIjE,MAAa,KAAK;IAMhB,YAAmB,KAAa,EAAE,KAAa,EAAE,MAAe;QA0BxD,cAAS,GAAkC,IAAI,CAAA;QAzBrD,IAAA,wBAAS,EAAC,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,OAAO,CAAC,CAAA;QACpC,MAAM,OAAO,GAAW,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAA;QACxC,IAAA,wBAAS,EACP,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,KAAK,OAAO,CAAC,EAC/C,WAAW,CACZ,CAAA;QAED,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,CAAA;QAClC,IAAA,wBAAS,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC,CAAA;QACxD,IAAA,wBAAS,EAAC,OAAO,MAAM,KAAK,WAAW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,CAAC,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC;gBAC3G,CAAC,CAAC,IAAI,gBAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAC9G,CAAA;SACF;QACD,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,YAAY,EAAE,EAAE,CAAC,WAAW,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;QACpH,OAAO,CAAC,IAAI,CAAC,SAAS,GAAG,IAAI,gBAAK,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,WAAW,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC,CAAA;IACtG,CAAC;IAED,IAAW,OAAO;QAChB,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAA;IAC9B,CAAC;CACF;AAnDD,sBAmDC"}
@@ -1,103 +1,103 @@
1
- import { Currency, CurrencyAmount, Percent, Price, TradeType } from '@kittycorn-labs/sdk-core';
2
- import { Pair } from './pair';
3
- import { Route } from './route';
4
- interface InputOutput<TInput extends Currency, TOutput extends Currency> {
5
- readonly inputAmount: CurrencyAmount<TInput>;
6
- readonly outputAmount: CurrencyAmount<TOutput>;
7
- }
8
- export declare function inputOutputComparator<TInput extends Currency, TOutput extends Currency>(a: InputOutput<TInput, TOutput>, b: InputOutput<TInput, TOutput>): number;
9
- export declare function tradeComparator<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType>(a: Trade<TInput, TOutput, TTradeType>, b: Trade<TInput, TOutput, TTradeType>): number;
10
- export interface BestTradeOptions {
11
- maxNumResults?: number;
12
- maxHops?: number;
13
- }
14
- /**
15
- * Represents a trade executed against a list of pairs.
16
- * Does not account for slippage, i.e. trades that front run this trade and move the price.
17
- */
18
- export declare class Trade<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType> {
19
- /**
20
- * The route of the trade, i.e. which pairs the trade goes through and the input/output currencies.
21
- */
22
- readonly route: Route<TInput, TOutput>;
23
- /**
24
- * The type of the trade, either exact in or exact out.
25
- */
26
- readonly tradeType: TTradeType;
27
- /**
28
- * The input amount for the trade assuming no slippage.
29
- */
30
- readonly inputAmount: CurrencyAmount<TInput>;
31
- /**
32
- * The output amount for the trade assuming no slippage.
33
- */
34
- readonly outputAmount: CurrencyAmount<TOutput>;
35
- /**
36
- * The price expressed in terms of output amount/input amount.
37
- */
38
- readonly executionPrice: Price<TInput, TOutput>;
39
- /**
40
- * The percent difference between the mid price before the trade and the trade execution price.
41
- */
42
- readonly priceImpact: Percent;
43
- /**
44
- * Constructs an exact in trade with the given amount in and route
45
- * @param route route of the exact in trade
46
- * @param amountIn the amount being passed in
47
- */
48
- static exactIn<TInput extends Currency, TOutput extends Currency>(route: Route<TInput, TOutput>, amountIn: CurrencyAmount<TInput>): Trade<TInput, TOutput, TradeType.EXACT_INPUT>;
49
- /**
50
- * Constructs an exact out trade with the given amount out and route
51
- * @param route route of the exact out trade
52
- * @param amountOut the amount returned by the trade
53
- */
54
- static exactOut<TInput extends Currency, TOutput extends Currency>(route: Route<TInput, TOutput>, amountOut: CurrencyAmount<TOutput>): Trade<TInput, TOutput, TradeType.EXACT_OUTPUT>;
55
- constructor(route: Route<TInput, TOutput>, amount: TTradeType extends TradeType.EXACT_INPUT ? CurrencyAmount<TInput> : CurrencyAmount<TOutput>, tradeType: TTradeType);
56
- /**
57
- * Get the minimum amount that must be received from this trade for the given slippage tolerance
58
- * @param slippageTolerance tolerance of unfavorable slippage from the execution price of this trade
59
- */
60
- minimumAmountOut(slippageTolerance: Percent): CurrencyAmount<TOutput>;
61
- /**
62
- * Get the maximum amount in that can be spent via this trade for the given slippage tolerance
63
- * @param slippageTolerance tolerance of unfavorable slippage from the execution price of this trade
64
- */
65
- maximumAmountIn(slippageTolerance: Percent): CurrencyAmount<TInput>;
66
- /**
67
- * Given a list of pairs, and a fixed amount in, returns the top `maxNumResults` trades that go from an input token
68
- * amount to an output token, making at most `maxHops` hops.
69
- * Note this does not consider aggregation, as routes are linear. It's possible a better route exists by splitting
70
- * the amount in among multiple routes.
71
- * @param pairs the pairs to consider in finding the best trade
72
- * @param nextAmountIn exact amount of input currency to spend
73
- * @param currencyOut the desired currency out
74
- * @param maxNumResults maximum number of results to return
75
- * @param maxHops maximum number of hops a returned trade can make, e.g. 1 hop goes through a single pair
76
- * @param currentPairs used in recursion; the current list of pairs
77
- * @param currencyAmountIn used in recursion; the original value of the currencyAmountIn parameter
78
- * @param bestTrades used in recursion; the current list of best trades
79
- */
80
- static bestTradeExactIn<TInput extends Currency, TOutput extends Currency>(pairs: Pair[], currencyAmountIn: CurrencyAmount<TInput>, currencyOut: TOutput, { maxNumResults, maxHops }?: BestTradeOptions, currentPairs?: Pair[], nextAmountIn?: CurrencyAmount<Currency>, bestTrades?: Trade<TInput, TOutput, TradeType.EXACT_INPUT>[]): Trade<TInput, TOutput, TradeType.EXACT_INPUT>[];
81
- /**
82
- * Return the execution price after accounting for slippage tolerance
83
- * @param slippageTolerance the allowed tolerated slippage
84
- */
85
- worstExecutionPrice(slippageTolerance: Percent): Price<TInput, TOutput>;
86
- /**
87
- * similar to the above method but instead targets a fixed output amount
88
- * given a list of pairs, and a fixed amount out, returns the top `maxNumResults` trades that go from an input token
89
- * to an output token amount, making at most `maxHops` hops
90
- * note this does not consider aggregation, as routes are linear. it's possible a better route exists by splitting
91
- * the amount in among multiple routes.
92
- * @param pairs the pairs to consider in finding the best trade
93
- * @param currencyIn the currency to spend
94
- * @param nextAmountOut the exact amount of currency out
95
- * @param maxNumResults maximum number of results to return
96
- * @param maxHops maximum number of hops a returned trade can make, e.g. 1 hop goes through a single pair
97
- * @param currentPairs used in recursion; the current list of pairs
98
- * @param currencyAmountOut used in recursion; the original value of the currencyAmountOut parameter
99
- * @param bestTrades used in recursion; the current list of best trades
100
- */
101
- static bestTradeExactOut<TInput extends Currency, TOutput extends Currency>(pairs: Pair[], currencyIn: TInput, currencyAmountOut: CurrencyAmount<TOutput>, { maxNumResults, maxHops }?: BestTradeOptions, currentPairs?: Pair[], nextAmountOut?: CurrencyAmount<Currency>, bestTrades?: Trade<TInput, TOutput, TradeType.EXACT_OUTPUT>[]): Trade<TInput, TOutput, TradeType.EXACT_OUTPUT>[];
102
- }
103
- export {};
1
+ import { Currency, CurrencyAmount, Percent, Price, TradeType } from '@kittycorn-labs/sdk-core';
2
+ import { Pair } from './pair';
3
+ import { Route } from './route';
4
+ interface InputOutput<TInput extends Currency, TOutput extends Currency> {
5
+ readonly inputAmount: CurrencyAmount<TInput>;
6
+ readonly outputAmount: CurrencyAmount<TOutput>;
7
+ }
8
+ export declare function inputOutputComparator<TInput extends Currency, TOutput extends Currency>(a: InputOutput<TInput, TOutput>, b: InputOutput<TInput, TOutput>): number;
9
+ export declare function tradeComparator<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType>(a: Trade<TInput, TOutput, TTradeType>, b: Trade<TInput, TOutput, TTradeType>): number;
10
+ export interface BestTradeOptions {
11
+ maxNumResults?: number;
12
+ maxHops?: number;
13
+ }
14
+ /**
15
+ * Represents a trade executed against a list of pairs.
16
+ * Does not account for slippage, i.e. trades that front run this trade and move the price.
17
+ */
18
+ export declare class Trade<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType> {
19
+ /**
20
+ * The route of the trade, i.e. which pairs the trade goes through and the input/output currencies.
21
+ */
22
+ readonly route: Route<TInput, TOutput>;
23
+ /**
24
+ * The type of the trade, either exact in or exact out.
25
+ */
26
+ readonly tradeType: TTradeType;
27
+ /**
28
+ * The input amount for the trade assuming no slippage.
29
+ */
30
+ readonly inputAmount: CurrencyAmount<TInput>;
31
+ /**
32
+ * The output amount for the trade assuming no slippage.
33
+ */
34
+ readonly outputAmount: CurrencyAmount<TOutput>;
35
+ /**
36
+ * The price expressed in terms of output amount/input amount.
37
+ */
38
+ readonly executionPrice: Price<TInput, TOutput>;
39
+ /**
40
+ * The percent difference between the mid price before the trade and the trade execution price.
41
+ */
42
+ readonly priceImpact: Percent;
43
+ /**
44
+ * Constructs an exact in trade with the given amount in and route
45
+ * @param route route of the exact in trade
46
+ * @param amountIn the amount being passed in
47
+ */
48
+ static exactIn<TInput extends Currency, TOutput extends Currency>(route: Route<TInput, TOutput>, amountIn: CurrencyAmount<TInput>): Trade<TInput, TOutput, TradeType.EXACT_INPUT>;
49
+ /**
50
+ * Constructs an exact out trade with the given amount out and route
51
+ * @param route route of the exact out trade
52
+ * @param amountOut the amount returned by the trade
53
+ */
54
+ static exactOut<TInput extends Currency, TOutput extends Currency>(route: Route<TInput, TOutput>, amountOut: CurrencyAmount<TOutput>): Trade<TInput, TOutput, TradeType.EXACT_OUTPUT>;
55
+ constructor(route: Route<TInput, TOutput>, amount: TTradeType extends TradeType.EXACT_INPUT ? CurrencyAmount<TInput> : CurrencyAmount<TOutput>, tradeType: TTradeType);
56
+ /**
57
+ * Get the minimum amount that must be received from this trade for the given slippage tolerance
58
+ * @param slippageTolerance tolerance of unfavorable slippage from the execution price of this trade
59
+ */
60
+ minimumAmountOut(slippageTolerance: Percent): CurrencyAmount<TOutput>;
61
+ /**
62
+ * Get the maximum amount in that can be spent via this trade for the given slippage tolerance
63
+ * @param slippageTolerance tolerance of unfavorable slippage from the execution price of this trade
64
+ */
65
+ maximumAmountIn(slippageTolerance: Percent): CurrencyAmount<TInput>;
66
+ /**
67
+ * Given a list of pairs, and a fixed amount in, returns the top `maxNumResults` trades that go from an input token
68
+ * amount to an output token, making at most `maxHops` hops.
69
+ * Note this does not consider aggregation, as routes are linear. It's possible a better route exists by splitting
70
+ * the amount in among multiple routes.
71
+ * @param pairs the pairs to consider in finding the best trade
72
+ * @param nextAmountIn exact amount of input currency to spend
73
+ * @param currencyOut the desired currency out
74
+ * @param maxNumResults maximum number of results to return
75
+ * @param maxHops maximum number of hops a returned trade can make, e.g. 1 hop goes through a single pair
76
+ * @param currentPairs used in recursion; the current list of pairs
77
+ * @param currencyAmountIn used in recursion; the original value of the currencyAmountIn parameter
78
+ * @param bestTrades used in recursion; the current list of best trades
79
+ */
80
+ static bestTradeExactIn<TInput extends Currency, TOutput extends Currency>(pairs: Pair[], currencyAmountIn: CurrencyAmount<TInput>, currencyOut: TOutput, { maxNumResults, maxHops }?: BestTradeOptions, currentPairs?: Pair[], nextAmountIn?: CurrencyAmount<Currency>, bestTrades?: Trade<TInput, TOutput, TradeType.EXACT_INPUT>[]): Trade<TInput, TOutput, TradeType.EXACT_INPUT>[];
81
+ /**
82
+ * Return the execution price after accounting for slippage tolerance
83
+ * @param slippageTolerance the allowed tolerated slippage
84
+ */
85
+ worstExecutionPrice(slippageTolerance: Percent): Price<TInput, TOutput>;
86
+ /**
87
+ * similar to the above method but instead targets a fixed output amount
88
+ * given a list of pairs, and a fixed amount out, returns the top `maxNumResults` trades that go from an input token
89
+ * to an output token amount, making at most `maxHops` hops
90
+ * note this does not consider aggregation, as routes are linear. it's possible a better route exists by splitting
91
+ * the amount in among multiple routes.
92
+ * @param pairs the pairs to consider in finding the best trade
93
+ * @param currencyIn the currency to spend
94
+ * @param nextAmountOut the exact amount of currency out
95
+ * @param maxNumResults maximum number of results to return
96
+ * @param maxHops maximum number of hops a returned trade can make, e.g. 1 hop goes through a single pair
97
+ * @param currentPairs used in recursion; the current list of pairs
98
+ * @param currencyAmountOut used in recursion; the original value of the currencyAmountOut parameter
99
+ * @param bestTrades used in recursion; the current list of best trades
100
+ */
101
+ static bestTradeExactOut<TInput extends Currency, TOutput extends Currency>(pairs: Pair[], currencyIn: TInput, currencyAmountOut: CurrencyAmount<TOutput>, { maxNumResults, maxHops }?: BestTradeOptions, currentPairs?: Pair[], nextAmountOut?: CurrencyAmount<Currency>, bestTrades?: Trade<TInput, TOutput, TradeType.EXACT_OUTPUT>[]): Trade<TInput, TOutput, TradeType.EXACT_OUTPUT>[];
102
+ }
103
+ export {};