@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.
- package/README.md +9 -0
- package/dist/{constants.d.ts → cjs/src/constants.d.ts} +19 -19
- package/dist/cjs/src/constants.js +23 -0
- package/dist/cjs/src/constants.js.map +1 -0
- package/dist/{entities → cjs/src/entities}/index.d.ts +3 -3
- package/dist/cjs/src/entities/index.js +7 -0
- package/dist/cjs/src/entities/index.js.map +1 -0
- package/dist/{entities → cjs/src/entities}/pair.d.ts +147 -147
- package/dist/cjs/src/entities/pair.js +318 -0
- package/dist/cjs/src/entities/pair.js.map +1 -0
- package/dist/{entities → cjs/src/entities}/route.d.ts +12 -12
- package/dist/cjs/src/entities/route.js +45 -0
- package/dist/cjs/src/entities/route.js.map +1 -0
- package/dist/{entities → cjs/src/entities}/trade.d.ts +103 -103
- package/dist/cjs/src/entities/trade.js +263 -0
- package/dist/cjs/src/entities/trade.js.map +1 -0
- package/dist/{errors.d.ts → cjs/src/errors.d.ts} +16 -16
- package/dist/cjs/src/errors.js +34 -0
- package/dist/cjs/src/errors.js.map +1 -0
- package/dist/{index.d.ts → cjs/src/index.d.ts} +4 -4
- package/dist/cjs/src/index.js +12 -0
- package/dist/cjs/src/index.js.map +1 -0
- package/dist/{router.d.ts → cjs/src/router.d.ts} +64 -64
- package/dist/cjs/src/router.js +94 -0
- package/dist/cjs/src/router.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/src/constants.d.ts +19 -0
- package/dist/esm/src/constants.js +19 -0
- package/dist/esm/src/constants.js.map +1 -0
- package/dist/esm/src/entities/index.d.ts +3 -0
- package/dist/esm/src/entities/index.js +4 -0
- package/dist/esm/src/entities/index.js.map +1 -0
- package/dist/esm/src/entities/pair.d.ts +147 -0
- package/dist/esm/src/entities/pair.js +312 -0
- package/dist/esm/src/entities/pair.js.map +1 -0
- package/dist/esm/src/entities/route.d.ts +12 -0
- package/dist/esm/src/entities/route.js +40 -0
- package/dist/esm/src/entities/route.js.map +1 -0
- package/dist/esm/src/entities/trade.d.ts +103 -0
- package/dist/esm/src/entities/trade.js +256 -0
- package/dist/esm/src/entities/trade.js.map +1 -0
- package/dist/esm/src/errors.d.ts +16 -0
- package/dist/esm/src/errors.js +29 -0
- package/dist/esm/src/errors.js.map +1 -0
- package/dist/esm/src/index.d.ts +4 -0
- package/dist/esm/src/index.js +5 -0
- package/dist/esm/src/index.js.map +1 -0
- package/dist/esm/src/router.d.ts +64 -0
- package/dist/esm/src/router.js +89 -0
- package/dist/esm/src/router.js.map +1 -0
- package/dist/types/src/constants.d.ts +20 -0
- package/dist/types/src/constants.d.ts.map +1 -0
- package/dist/types/src/entities/index.d.ts +4 -0
- package/dist/types/src/entities/index.d.ts.map +1 -0
- package/dist/types/src/entities/pair.d.ts +148 -0
- package/dist/types/src/entities/pair.d.ts.map +1 -0
- package/dist/types/src/entities/route.d.ts +13 -0
- package/dist/types/src/entities/route.d.ts.map +1 -0
- package/dist/types/src/entities/trade.d.ts +104 -0
- package/dist/types/src/entities/trade.d.ts.map +1 -0
- package/dist/types/src/errors.d.ts +17 -0
- package/dist/types/src/errors.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +5 -0
- package/dist/types/src/index.d.ts.map +1 -0
- package/dist/types/src/router.d.ts +65 -0
- package/dist/types/src/router.d.ts.map +1 -0
- package/package.json +23 -34
- package/dist/index.js +0 -8
- package/dist/v2-sdk.cjs.development.js +0 -897
- package/dist/v2-sdk.cjs.development.js.map +0 -1
- package/dist/v2-sdk.cjs.production.min.js +0 -2
- package/dist/v2-sdk.cjs.production.min.js.map +0 -1
- package/dist/v2-sdk.esm.js +0 -880
- package/dist/v2-sdk.esm.js.map +0 -1
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Trade = exports.tradeComparator = exports.inputOutputComparator = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const sdk_core_1 = require("@kittycorn-labs/sdk-core");
|
|
6
|
+
const jsbi_1 = tslib_1.__importDefault(require("jsbi"));
|
|
7
|
+
const constants_1 = require("../constants");
|
|
8
|
+
const tiny_invariant_1 = tslib_1.__importDefault(require("tiny-invariant"));
|
|
9
|
+
const route_1 = require("./route");
|
|
10
|
+
// comparator function that allows sorting trades by their output amounts, in decreasing order, and then input amounts
|
|
11
|
+
// in increasing order. i.e. the best trades have the most outputs for the least inputs and are sorted first
|
|
12
|
+
function inputOutputComparator(a, b) {
|
|
13
|
+
// must have same input and output token for comparison
|
|
14
|
+
(0, tiny_invariant_1.default)(a.inputAmount.currency.equals(b.inputAmount.currency), 'INPUT_CURRENCY');
|
|
15
|
+
(0, tiny_invariant_1.default)(a.outputAmount.currency.equals(b.outputAmount.currency), 'OUTPUT_CURRENCY');
|
|
16
|
+
if (a.outputAmount.equalTo(b.outputAmount)) {
|
|
17
|
+
if (a.inputAmount.equalTo(b.inputAmount)) {
|
|
18
|
+
return 0;
|
|
19
|
+
}
|
|
20
|
+
// trade A requires less input than trade B, so A should come first
|
|
21
|
+
if (a.inputAmount.lessThan(b.inputAmount)) {
|
|
22
|
+
return -1;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
return 1;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
// tradeA has less output than trade B, so should come second
|
|
30
|
+
if (a.outputAmount.lessThan(b.outputAmount)) {
|
|
31
|
+
return 1;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
return -1;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.inputOutputComparator = inputOutputComparator;
|
|
39
|
+
// extension of the input output comparator that also considers other dimensions of the trade in ranking them
|
|
40
|
+
function tradeComparator(a, b) {
|
|
41
|
+
const ioComp = inputOutputComparator(a, b);
|
|
42
|
+
if (ioComp !== 0) {
|
|
43
|
+
return ioComp;
|
|
44
|
+
}
|
|
45
|
+
// consider lowest slippage next, since these are less likely to fail
|
|
46
|
+
if (a.priceImpact.lessThan(b.priceImpact)) {
|
|
47
|
+
return -1;
|
|
48
|
+
}
|
|
49
|
+
else if (a.priceImpact.greaterThan(b.priceImpact)) {
|
|
50
|
+
return 1;
|
|
51
|
+
}
|
|
52
|
+
// finally consider the number of hops since each hop costs gas
|
|
53
|
+
return a.route.path.length - b.route.path.length;
|
|
54
|
+
}
|
|
55
|
+
exports.tradeComparator = tradeComparator;
|
|
56
|
+
/**
|
|
57
|
+
* Represents a trade executed against a list of pairs.
|
|
58
|
+
* Does not account for slippage, i.e. trades that front run this trade and move the price.
|
|
59
|
+
*/
|
|
60
|
+
class Trade {
|
|
61
|
+
/**
|
|
62
|
+
* Constructs an exact in trade with the given amount in and route
|
|
63
|
+
* @param route route of the exact in trade
|
|
64
|
+
* @param amountIn the amount being passed in
|
|
65
|
+
*/
|
|
66
|
+
static exactIn(route, amountIn) {
|
|
67
|
+
return new Trade(route, amountIn, sdk_core_1.TradeType.EXACT_INPUT);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Constructs an exact out trade with the given amount out and route
|
|
71
|
+
* @param route route of the exact out trade
|
|
72
|
+
* @param amountOut the amount returned by the trade
|
|
73
|
+
*/
|
|
74
|
+
static exactOut(route, amountOut) {
|
|
75
|
+
return new Trade(route, amountOut, sdk_core_1.TradeType.EXACT_OUTPUT);
|
|
76
|
+
}
|
|
77
|
+
constructor(route, amount, tradeType) {
|
|
78
|
+
this.route = route;
|
|
79
|
+
this.tradeType = tradeType;
|
|
80
|
+
const tokenAmounts = new Array(route.path.length);
|
|
81
|
+
if (tradeType === sdk_core_1.TradeType.EXACT_INPUT) {
|
|
82
|
+
(0, tiny_invariant_1.default)(amount.currency.equals(route.input), 'INPUT');
|
|
83
|
+
tokenAmounts[0] = amount.wrapped;
|
|
84
|
+
for (let i = 0; i < route.path.length - 1; i++) {
|
|
85
|
+
const pair = route.pairs[i];
|
|
86
|
+
const [outputAmount] = pair.getOutputAmount(tokenAmounts[i]);
|
|
87
|
+
tokenAmounts[i + 1] = outputAmount;
|
|
88
|
+
}
|
|
89
|
+
this.inputAmount = sdk_core_1.CurrencyAmount.fromFractionalAmount(route.input, amount.numerator, amount.denominator);
|
|
90
|
+
this.outputAmount = sdk_core_1.CurrencyAmount.fromFractionalAmount(route.output, tokenAmounts[tokenAmounts.length - 1].numerator, tokenAmounts[tokenAmounts.length - 1].denominator);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
(0, tiny_invariant_1.default)(amount.currency.equals(route.output), 'OUTPUT');
|
|
94
|
+
tokenAmounts[tokenAmounts.length - 1] = amount.wrapped;
|
|
95
|
+
for (let i = route.path.length - 1; i > 0; i--) {
|
|
96
|
+
const pair = route.pairs[i - 1];
|
|
97
|
+
const [inputAmount] = pair.getInputAmount(tokenAmounts[i]);
|
|
98
|
+
tokenAmounts[i - 1] = inputAmount;
|
|
99
|
+
}
|
|
100
|
+
this.inputAmount = sdk_core_1.CurrencyAmount.fromFractionalAmount(route.input, tokenAmounts[0].numerator, tokenAmounts[0].denominator);
|
|
101
|
+
this.outputAmount = sdk_core_1.CurrencyAmount.fromFractionalAmount(route.output, amount.numerator, amount.denominator);
|
|
102
|
+
}
|
|
103
|
+
this.executionPrice = new sdk_core_1.Price(this.inputAmount.currency, this.outputAmount.currency, this.inputAmount.quotient, this.outputAmount.quotient);
|
|
104
|
+
this.priceImpact = (0, sdk_core_1.computePriceImpact)(route.midPrice, this.inputAmount, this.outputAmount);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Get the minimum amount that must be received from this trade for the given slippage tolerance
|
|
108
|
+
* @param slippageTolerance tolerance of unfavorable slippage from the execution price of this trade
|
|
109
|
+
*/
|
|
110
|
+
minimumAmountOut(slippageTolerance) {
|
|
111
|
+
(0, tiny_invariant_1.default)(!slippageTolerance.lessThan(constants_1.ZERO), 'SLIPPAGE_TOLERANCE');
|
|
112
|
+
if (this.tradeType === sdk_core_1.TradeType.EXACT_OUTPUT) {
|
|
113
|
+
return this.outputAmount;
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
const slippageAdjustedAmountOut = new sdk_core_1.Fraction(constants_1.ONE)
|
|
117
|
+
.subtract(slippageTolerance)
|
|
118
|
+
.multiply(this.outputAmount.quotient).quotient;
|
|
119
|
+
const clampedAmount = jsbi_1.default.greaterThan(slippageAdjustedAmountOut, jsbi_1.default.BigInt(0))
|
|
120
|
+
? slippageAdjustedAmountOut
|
|
121
|
+
: jsbi_1.default.BigInt(0);
|
|
122
|
+
return sdk_core_1.CurrencyAmount.fromRawAmount(this.outputAmount.currency, clampedAmount);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Get the maximum amount in that can be spent via this trade for the given slippage tolerance
|
|
127
|
+
* @param slippageTolerance tolerance of unfavorable slippage from the execution price of this trade
|
|
128
|
+
*/
|
|
129
|
+
maximumAmountIn(slippageTolerance) {
|
|
130
|
+
(0, tiny_invariant_1.default)(!slippageTolerance.lessThan(constants_1.ZERO), 'SLIPPAGE_TOLERANCE');
|
|
131
|
+
if (this.tradeType === sdk_core_1.TradeType.EXACT_INPUT) {
|
|
132
|
+
return this.inputAmount;
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
const slippageAdjustedAmountIn = new sdk_core_1.Fraction(constants_1.ONE)
|
|
136
|
+
.add(slippageTolerance)
|
|
137
|
+
.multiply(this.inputAmount.quotient).quotient;
|
|
138
|
+
return sdk_core_1.CurrencyAmount.fromRawAmount(this.inputAmount.currency, slippageAdjustedAmountIn);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Given a list of pairs, and a fixed amount in, returns the top `maxNumResults` trades that go from an input token
|
|
143
|
+
* amount to an output token, making at most `maxHops` hops.
|
|
144
|
+
* Note this does not consider aggregation, as routes are linear. It's possible a better route exists by splitting
|
|
145
|
+
* the amount in among multiple routes.
|
|
146
|
+
* @param pairs the pairs to consider in finding the best trade
|
|
147
|
+
* @param nextAmountIn exact amount of input currency to spend
|
|
148
|
+
* @param currencyOut the desired currency out
|
|
149
|
+
* @param maxNumResults maximum number of results to return
|
|
150
|
+
* @param maxHops maximum number of hops a returned trade can make, e.g. 1 hop goes through a single pair
|
|
151
|
+
* @param currentPairs used in recursion; the current list of pairs
|
|
152
|
+
* @param currencyAmountIn used in recursion; the original value of the currencyAmountIn parameter
|
|
153
|
+
* @param bestTrades used in recursion; the current list of best trades
|
|
154
|
+
*/
|
|
155
|
+
static bestTradeExactIn(pairs, currencyAmountIn, currencyOut, { maxNumResults = 3, maxHops = 3 } = {},
|
|
156
|
+
// used in recursion.
|
|
157
|
+
currentPairs = [], nextAmountIn = currencyAmountIn, bestTrades = []) {
|
|
158
|
+
(0, tiny_invariant_1.default)(pairs.length > 0, 'PAIRS');
|
|
159
|
+
(0, tiny_invariant_1.default)(maxHops > 0, 'MAX_HOPS');
|
|
160
|
+
(0, tiny_invariant_1.default)(currencyAmountIn === nextAmountIn || currentPairs.length > 0, 'INVALID_RECURSION');
|
|
161
|
+
const amountIn = nextAmountIn.wrapped;
|
|
162
|
+
const tokenOut = currencyOut.wrapped;
|
|
163
|
+
for (let i = 0; i < pairs.length; i++) {
|
|
164
|
+
const pair = pairs[i];
|
|
165
|
+
// pair irrelevant
|
|
166
|
+
if (!pair.token0.equals(amountIn.currency) && !pair.token1.equals(amountIn.currency))
|
|
167
|
+
continue;
|
|
168
|
+
if (pair.reserve0.equalTo(constants_1.ZERO) || pair.reserve1.equalTo(constants_1.ZERO))
|
|
169
|
+
continue;
|
|
170
|
+
let amountOut;
|
|
171
|
+
try {
|
|
172
|
+
;
|
|
173
|
+
[amountOut] = pair.getOutputAmount(amountIn);
|
|
174
|
+
}
|
|
175
|
+
catch (error) {
|
|
176
|
+
// input too low
|
|
177
|
+
if (error.isInsufficientInputAmountError) {
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
throw error;
|
|
181
|
+
}
|
|
182
|
+
// we have arrived at the output token, so this is the final trade of one of the paths
|
|
183
|
+
if (amountOut.currency.equals(tokenOut)) {
|
|
184
|
+
(0, sdk_core_1.sortedInsert)(bestTrades, new Trade(new route_1.Route([...currentPairs, pair], currencyAmountIn.currency, currencyOut), currencyAmountIn, sdk_core_1.TradeType.EXACT_INPUT), maxNumResults, tradeComparator);
|
|
185
|
+
}
|
|
186
|
+
else if (maxHops > 1 && pairs.length > 1) {
|
|
187
|
+
const pairsExcludingThisPair = pairs.slice(0, i).concat(pairs.slice(i + 1, pairs.length));
|
|
188
|
+
// otherwise, consider all the other paths that lead from this token as long as we have not exceeded maxHops
|
|
189
|
+
Trade.bestTradeExactIn(pairsExcludingThisPair, currencyAmountIn, currencyOut, {
|
|
190
|
+
maxNumResults,
|
|
191
|
+
maxHops: maxHops - 1,
|
|
192
|
+
}, [...currentPairs, pair], amountOut, bestTrades);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return bestTrades;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Return the execution price after accounting for slippage tolerance
|
|
199
|
+
* @param slippageTolerance the allowed tolerated slippage
|
|
200
|
+
*/
|
|
201
|
+
worstExecutionPrice(slippageTolerance) {
|
|
202
|
+
return new sdk_core_1.Price(this.inputAmount.currency, this.outputAmount.currency, this.maximumAmountIn(slippageTolerance).quotient, this.minimumAmountOut(slippageTolerance).quotient);
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* similar to the above method but instead targets a fixed output amount
|
|
206
|
+
* given a list of pairs, and a fixed amount out, returns the top `maxNumResults` trades that go from an input token
|
|
207
|
+
* to an output token amount, making at most `maxHops` hops
|
|
208
|
+
* note this does not consider aggregation, as routes are linear. it's possible a better route exists by splitting
|
|
209
|
+
* the amount in among multiple routes.
|
|
210
|
+
* @param pairs the pairs to consider in finding the best trade
|
|
211
|
+
* @param currencyIn the currency to spend
|
|
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 pair
|
|
215
|
+
* @param currentPairs used in recursion; the current list of pairs
|
|
216
|
+
* @param currencyAmountOut used in recursion; the original value of the currencyAmountOut parameter
|
|
217
|
+
* @param bestTrades used in recursion; the current list of best trades
|
|
218
|
+
*/
|
|
219
|
+
static bestTradeExactOut(pairs, currencyIn, currencyAmountOut, { maxNumResults = 3, maxHops = 3 } = {},
|
|
220
|
+
// used in recursion.
|
|
221
|
+
currentPairs = [], nextAmountOut = currencyAmountOut, bestTrades = []) {
|
|
222
|
+
(0, tiny_invariant_1.default)(pairs.length > 0, 'PAIRS');
|
|
223
|
+
(0, tiny_invariant_1.default)(maxHops > 0, 'MAX_HOPS');
|
|
224
|
+
(0, tiny_invariant_1.default)(currencyAmountOut === nextAmountOut || currentPairs.length > 0, 'INVALID_RECURSION');
|
|
225
|
+
const amountOut = nextAmountOut.wrapped;
|
|
226
|
+
const tokenIn = currencyIn.wrapped;
|
|
227
|
+
for (let i = 0; i < pairs.length; i++) {
|
|
228
|
+
const pair = pairs[i];
|
|
229
|
+
// pair irrelevant
|
|
230
|
+
if (!pair.token0.equals(amountOut.currency) && !pair.token1.equals(amountOut.currency))
|
|
231
|
+
continue;
|
|
232
|
+
if (pair.reserve0.equalTo(constants_1.ZERO) || pair.reserve1.equalTo(constants_1.ZERO))
|
|
233
|
+
continue;
|
|
234
|
+
let amountIn;
|
|
235
|
+
try {
|
|
236
|
+
;
|
|
237
|
+
[amountIn] = pair.getInputAmount(amountOut);
|
|
238
|
+
}
|
|
239
|
+
catch (error) {
|
|
240
|
+
// not enough liquidity in this pair
|
|
241
|
+
if (error.isInsufficientReservesError) {
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
throw error;
|
|
245
|
+
}
|
|
246
|
+
// we have arrived at the input token, so this is the first trade of one of the paths
|
|
247
|
+
if (amountIn.currency.equals(tokenIn)) {
|
|
248
|
+
(0, sdk_core_1.sortedInsert)(bestTrades, new Trade(new route_1.Route([pair, ...currentPairs], currencyIn, currencyAmountOut.currency), currencyAmountOut, sdk_core_1.TradeType.EXACT_OUTPUT), maxNumResults, tradeComparator);
|
|
249
|
+
}
|
|
250
|
+
else if (maxHops > 1 && pairs.length > 1) {
|
|
251
|
+
const pairsExcludingThisPair = pairs.slice(0, i).concat(pairs.slice(i + 1, pairs.length));
|
|
252
|
+
// otherwise, consider all the other paths that arrive at this token as long as we have not exceeded maxHops
|
|
253
|
+
Trade.bestTradeExactOut(pairsExcludingThisPair, currencyIn, currencyAmountOut, {
|
|
254
|
+
maxNumResults,
|
|
255
|
+
maxHops: maxHops - 1,
|
|
256
|
+
}, [pair, ...currentPairs], amountIn, bestTrades);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return bestTrades;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
exports.Trade = Trade;
|
|
263
|
+
//# sourceMappingURL=trade.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trade.js","sourceRoot":"","sources":["../../../../src/entities/trade.ts"],"names":[],"mappings":";;;;AAAA,uDAUiC;AACjC,wDAAuB;AACvB,4CAAwC;AACxC,4EAAsC;AAGtC,mCAA+B;AAQ/B,sHAAsH;AACtH,4GAA4G;AAC5G,SAAgB,qBAAqB,CACnC,CAA+B,EAC/B,CAA+B;IAE/B,uDAAuD;IACvD,IAAA,wBAAS,EAAC,CAAC,CAAC,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE,gBAAgB,CAAC,CAAA;IAClF,IAAA,wBAAS,EAAC,CAAC,CAAC,YAAY,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,YAAY,CAAC,QAAQ,CAAC,EAAE,iBAAiB,CAAC,CAAA;IAC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AE,SAAQ;YAExE,IAAI,QAA+B,CAAA;YACnC,IAAI;gBACF,CAAC;gBAAA,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,CAAA;aAC7C;YAAC,OAAO,KAAK,EAAE;gBACd,oCAAoC;gBACpC,IAAK,KAAa,CAAC,2BAA2B,EAAE;oBAC9C,SAAQ;iBACT;gBACD,MAAM,KAAK,CAAA;aACZ;YACD,qFAAqF;YACrF,IAAI,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE;gBACrC,IAAA,uBAAY,EACV,UAAU,EACV,IAAI,KAAK,CACP,IAAI,aAAK,CAAC,CAAC,IAAI,EAAE,GAAG,YAAY,CAAC,EAAE,UAAU,EAAE,iBAAiB,CAAC,QAAQ,CAAC,EAC1E,iBAAiB,EACjB,oBAAS,CAAC,YAAY,CACvB,EACD,aAAa,EACb,eAAe,CAChB,CAAA;aACF;iBAAM,IAAI,OAAO,GAAG,CAAC,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE;gBAC1C,MAAM,sBAAsB,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAA;gBAEzF,4GAA4G;gBAC5G,KAAK,CAAC,iBAAiB,CACrB,sBAAsB,EACtB,UAAU,EACV,iBAAiB,EACjB;oBACE,aAAa;oBACb,OAAO,EAAE,OAAO,GAAG,CAAC;iBACrB,EACD,CAAC,IAAI,EAAE,GAAG,YAAY,CAAC,EACvB,QAAQ,EACR,UAAU,CACX,CAAA;aACF;SACF;QAED,OAAO,UAAU,CAAA;IACnB,CAAC;CACF;AAjTD,sBAiTC"}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Indicates that the pair has insufficient reserves for a desired output amount. I.e. the amount of output cannot be
|
|
3
|
-
* obtained by sending any amount of input.
|
|
4
|
-
*/
|
|
5
|
-
export declare class InsufficientReservesError extends Error {
|
|
6
|
-
readonly isInsufficientReservesError: true;
|
|
7
|
-
constructor();
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Indicates that the input amount is too small to produce any amount of output. I.e. the amount of input sent is less
|
|
11
|
-
* than the price of a single unit of output after fees.
|
|
12
|
-
*/
|
|
13
|
-
export declare class InsufficientInputAmountError extends Error {
|
|
14
|
-
readonly isInsufficientInputAmountError: true;
|
|
15
|
-
constructor();
|
|
16
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Indicates that the pair has insufficient reserves for a desired output amount. I.e. the amount of output cannot be
|
|
3
|
+
* obtained by sending any amount of input.
|
|
4
|
+
*/
|
|
5
|
+
export declare class InsufficientReservesError extends Error {
|
|
6
|
+
readonly isInsufficientReservesError: true;
|
|
7
|
+
constructor();
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Indicates that the input amount is too small to produce any amount of output. I.e. the amount of input sent is less
|
|
11
|
+
* than the price of a single unit of output after fees.
|
|
12
|
+
*/
|
|
13
|
+
export declare class InsufficientInputAmountError extends Error {
|
|
14
|
+
readonly isInsufficientInputAmountError: true;
|
|
15
|
+
constructor();
|
|
16
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InsufficientInputAmountError = exports.InsufficientReservesError = void 0;
|
|
4
|
+
// see https://stackoverflow.com/a/41102306
|
|
5
|
+
const CAN_SET_PROTOTYPE = 'setPrototypeOf' in Object;
|
|
6
|
+
/**
|
|
7
|
+
* Indicates that the pair has insufficient reserves for a desired output amount. I.e. the amount of output cannot be
|
|
8
|
+
* obtained by sending any amount of input.
|
|
9
|
+
*/
|
|
10
|
+
class InsufficientReservesError extends Error {
|
|
11
|
+
constructor() {
|
|
12
|
+
super();
|
|
13
|
+
this.isInsufficientReservesError = true;
|
|
14
|
+
this.name = this.constructor.name;
|
|
15
|
+
if (CAN_SET_PROTOTYPE)
|
|
16
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.InsufficientReservesError = InsufficientReservesError;
|
|
20
|
+
/**
|
|
21
|
+
* Indicates that the input amount is too small to produce any amount of output. I.e. the amount of input sent is less
|
|
22
|
+
* than the price of a single unit of output after fees.
|
|
23
|
+
*/
|
|
24
|
+
class InsufficientInputAmountError extends Error {
|
|
25
|
+
constructor() {
|
|
26
|
+
super();
|
|
27
|
+
this.isInsufficientInputAmountError = true;
|
|
28
|
+
this.name = this.constructor.name;
|
|
29
|
+
if (CAN_SET_PROTOTYPE)
|
|
30
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.InsufficientInputAmountError = InsufficientInputAmountError;
|
|
34
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/errors.ts"],"names":[],"mappings":";;;AAAA,2CAA2C;AAC3C,MAAM,iBAAiB,GAAG,gBAAgB,IAAI,MAAM,CAAA;AAEpD;;;GAGG;AACH,MAAa,yBAA0B,SAAQ,KAAK;IAGlD;QACE,KAAK,EAAE,CAAA;QAHO,gCAA2B,GAAS,IAAI,CAAA;QAItD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAA;QACjC,IAAI,iBAAiB;YAAE,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;IAC1E,CAAC;CACF;AARD,8DAQC;AAED;;;GAGG;AACH,MAAa,4BAA6B,SAAQ,KAAK;IAGrD;QACE,KAAK,EAAE,CAAA;QAHO,mCAA8B,GAAS,IAAI,CAAA;QAIzD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAA;QACjC,IAAI,iBAAiB;YAAE,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;IAC1E,CAAC;CACF;AARD,oEAQC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { FACTORY_ADDRESS_MAP, INIT_CODE_HASH, MINIMUM_LIQUIDITY } from './constants';
|
|
2
|
-
export * from './errors';
|
|
3
|
-
export * from './entities';
|
|
4
|
-
export * from './router';
|
|
1
|
+
export { FACTORY_ADDRESS_MAP, INIT_CODE_HASH, MINIMUM_LIQUIDITY } from './constants';
|
|
2
|
+
export * from './errors';
|
|
3
|
+
export * from './entities';
|
|
4
|
+
export * from './router';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MINIMUM_LIQUIDITY = exports.INIT_CODE_HASH = exports.FACTORY_ADDRESS_MAP = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
var constants_1 = require("./constants");
|
|
6
|
+
Object.defineProperty(exports, "FACTORY_ADDRESS_MAP", { enumerable: true, get: function () { return constants_1.FACTORY_ADDRESS_MAP; } });
|
|
7
|
+
Object.defineProperty(exports, "INIT_CODE_HASH", { enumerable: true, get: function () { return constants_1.INIT_CODE_HASH; } });
|
|
8
|
+
Object.defineProperty(exports, "MINIMUM_LIQUIDITY", { enumerable: true, get: function () { return constants_1.MINIMUM_LIQUIDITY; } });
|
|
9
|
+
tslib_1.__exportStar(require("./errors"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./entities"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./router"), exports);
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":";;;;AAAA,yCAAoF;AAA3E,gHAAA,mBAAmB,OAAA;AAAE,2GAAA,cAAc,OAAA;AAAE,8GAAA,iBAAiB,OAAA;AAE/D,mDAAwB;AACxB,qDAA0B;AAC1B,mDAAwB"}
|
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
import { Currency, Percent, TradeType } from '@kittycorn-labs/sdk-core';
|
|
2
|
-
import { Trade } from './entities';
|
|
3
|
-
/**
|
|
4
|
-
* Options for producing the arguments to send call to the router.
|
|
5
|
-
*/
|
|
6
|
-
export interface TradeOptions {
|
|
7
|
-
/**
|
|
8
|
-
* How much the execution price is allowed to move unfavorably from the trade execution price.
|
|
9
|
-
*/
|
|
10
|
-
allowedSlippage: Percent;
|
|
11
|
-
/**
|
|
12
|
-
* How long the swap is valid until it expires, in seconds.
|
|
13
|
-
* This will be used to produce a `deadline` parameter which is computed from when the swap call parameters
|
|
14
|
-
* are generated.
|
|
15
|
-
*/
|
|
16
|
-
ttl: number;
|
|
17
|
-
/**
|
|
18
|
-
* The account that should receive the output of the swap.
|
|
19
|
-
*/
|
|
20
|
-
recipient: string;
|
|
21
|
-
/**
|
|
22
|
-
* Whether any of the tokens in the path are fee on transfer tokens, which should be handled with special methods
|
|
23
|
-
*/
|
|
24
|
-
feeOnTransfer?: boolean;
|
|
25
|
-
}
|
|
26
|
-
export interface TradeOptionsDeadline extends Omit<TradeOptions, 'ttl'> {
|
|
27
|
-
/**
|
|
28
|
-
* When the transaction expires.
|
|
29
|
-
* This is an atlernate to specifying the ttl, for when you do not want to use local time.
|
|
30
|
-
*/
|
|
31
|
-
deadline: number;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* The parameters to use in the call to the Uniswap V2 Router to execute a trade.
|
|
35
|
-
*/
|
|
36
|
-
export interface SwapParameters {
|
|
37
|
-
/**
|
|
38
|
-
* The method to call on the Uniswap V2 Router.
|
|
39
|
-
*/
|
|
40
|
-
methodName: string;
|
|
41
|
-
/**
|
|
42
|
-
* The arguments to pass to the method, all hex encoded.
|
|
43
|
-
*/
|
|
44
|
-
args: (string | string[])[];
|
|
45
|
-
/**
|
|
46
|
-
* The amount of wei to send in hex.
|
|
47
|
-
*/
|
|
48
|
-
value: string;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Represents the Uniswap V2 Router, and has static methods for helping execute trades.
|
|
52
|
-
*/
|
|
53
|
-
export declare abstract class Router {
|
|
54
|
-
/**
|
|
55
|
-
* Cannot be constructed.
|
|
56
|
-
*/
|
|
57
|
-
private constructor();
|
|
58
|
-
/**
|
|
59
|
-
* Produces the on-chain method name to call and the hex encoded parameters to pass as arguments for a given trade.
|
|
60
|
-
* @param trade to produce call parameters for
|
|
61
|
-
* @param options options for the call parameters
|
|
62
|
-
*/
|
|
63
|
-
static swapCallParameters(trade: Trade<Currency, Currency, TradeType>, options: TradeOptions | TradeOptionsDeadline): SwapParameters;
|
|
64
|
-
}
|
|
1
|
+
import { Currency, Percent, TradeType } from '@kittycorn-labs/sdk-core';
|
|
2
|
+
import { Trade } from './entities';
|
|
3
|
+
/**
|
|
4
|
+
* Options for producing the arguments to send call to the router.
|
|
5
|
+
*/
|
|
6
|
+
export interface TradeOptions {
|
|
7
|
+
/**
|
|
8
|
+
* How much the execution price is allowed to move unfavorably from the trade execution price.
|
|
9
|
+
*/
|
|
10
|
+
allowedSlippage: Percent;
|
|
11
|
+
/**
|
|
12
|
+
* How long the swap is valid until it expires, in seconds.
|
|
13
|
+
* This will be used to produce a `deadline` parameter which is computed from when the swap call parameters
|
|
14
|
+
* are generated.
|
|
15
|
+
*/
|
|
16
|
+
ttl: number;
|
|
17
|
+
/**
|
|
18
|
+
* The account that should receive the output of the swap.
|
|
19
|
+
*/
|
|
20
|
+
recipient: string;
|
|
21
|
+
/**
|
|
22
|
+
* Whether any of the tokens in the path are fee on transfer tokens, which should be handled with special methods
|
|
23
|
+
*/
|
|
24
|
+
feeOnTransfer?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export interface TradeOptionsDeadline extends Omit<TradeOptions, 'ttl'> {
|
|
27
|
+
/**
|
|
28
|
+
* When the transaction expires.
|
|
29
|
+
* This is an atlernate to specifying the ttl, for when you do not want to use local time.
|
|
30
|
+
*/
|
|
31
|
+
deadline: number;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The parameters to use in the call to the Uniswap V2 Router to execute a trade.
|
|
35
|
+
*/
|
|
36
|
+
export interface SwapParameters {
|
|
37
|
+
/**
|
|
38
|
+
* The method to call on the Uniswap V2 Router.
|
|
39
|
+
*/
|
|
40
|
+
methodName: string;
|
|
41
|
+
/**
|
|
42
|
+
* The arguments to pass to the method, all hex encoded.
|
|
43
|
+
*/
|
|
44
|
+
args: (string | string[])[];
|
|
45
|
+
/**
|
|
46
|
+
* The amount of wei to send in hex.
|
|
47
|
+
*/
|
|
48
|
+
value: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Represents the Uniswap V2 Router, and has static methods for helping execute trades.
|
|
52
|
+
*/
|
|
53
|
+
export declare abstract class Router {
|
|
54
|
+
/**
|
|
55
|
+
* Cannot be constructed.
|
|
56
|
+
*/
|
|
57
|
+
private constructor();
|
|
58
|
+
/**
|
|
59
|
+
* Produces the on-chain method name to call and the hex encoded parameters to pass as arguments for a given trade.
|
|
60
|
+
* @param trade to produce call parameters for
|
|
61
|
+
* @param options options for the call parameters
|
|
62
|
+
*/
|
|
63
|
+
static swapCallParameters(trade: Trade<Currency, Currency, TradeType>, options: TradeOptions | TradeOptionsDeadline): SwapParameters;
|
|
64
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Router = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const sdk_core_1 = require("@kittycorn-labs/sdk-core");
|
|
6
|
+
const tiny_invariant_1 = tslib_1.__importDefault(require("tiny-invariant"));
|
|
7
|
+
function toHex(currencyAmount) {
|
|
8
|
+
return `0x${currencyAmount.quotient.toString(16)}`;
|
|
9
|
+
}
|
|
10
|
+
const ZERO_HEX = '0x0';
|
|
11
|
+
/**
|
|
12
|
+
* Represents the Uniswap V2 Router, and has static methods for helping execute trades.
|
|
13
|
+
*/
|
|
14
|
+
class Router {
|
|
15
|
+
/**
|
|
16
|
+
* Cannot be constructed.
|
|
17
|
+
*/
|
|
18
|
+
constructor() { }
|
|
19
|
+
/**
|
|
20
|
+
* Produces the on-chain method name to call and the hex encoded parameters to pass as arguments for a given trade.
|
|
21
|
+
* @param trade to produce call parameters for
|
|
22
|
+
* @param options options for the call parameters
|
|
23
|
+
*/
|
|
24
|
+
static swapCallParameters(trade, options) {
|
|
25
|
+
const etherIn = trade.inputAmount.currency.isNative;
|
|
26
|
+
const etherOut = trade.outputAmount.currency.isNative;
|
|
27
|
+
// the router does not support both ether in and out
|
|
28
|
+
(0, tiny_invariant_1.default)(!(etherIn && etherOut), 'ETHER_IN_OUT');
|
|
29
|
+
(0, tiny_invariant_1.default)(!('ttl' in options) || options.ttl > 0, 'TTL');
|
|
30
|
+
const to = (0, sdk_core_1.validateAndParseAddress)(options.recipient);
|
|
31
|
+
const amountIn = toHex(trade.maximumAmountIn(options.allowedSlippage));
|
|
32
|
+
const amountOut = toHex(trade.minimumAmountOut(options.allowedSlippage));
|
|
33
|
+
const path = trade.route.path.map((token) => token.address);
|
|
34
|
+
const deadline = 'ttl' in options
|
|
35
|
+
? `0x${(Math.floor(new Date().getTime() / 1000) + options.ttl).toString(16)}`
|
|
36
|
+
: `0x${options.deadline.toString(16)}`;
|
|
37
|
+
const useFeeOnTransfer = Boolean(options.feeOnTransfer);
|
|
38
|
+
let methodName;
|
|
39
|
+
let args;
|
|
40
|
+
let value;
|
|
41
|
+
switch (trade.tradeType) {
|
|
42
|
+
case sdk_core_1.TradeType.EXACT_INPUT:
|
|
43
|
+
if (etherIn) {
|
|
44
|
+
methodName = useFeeOnTransfer ? 'swapExactETHForTokensSupportingFeeOnTransferTokens' : 'swapExactETHForTokens';
|
|
45
|
+
// (uint amountOutMin, address[] calldata path, address to, uint deadline)
|
|
46
|
+
args = [amountOut, path, to, deadline];
|
|
47
|
+
value = amountIn;
|
|
48
|
+
}
|
|
49
|
+
else if (etherOut) {
|
|
50
|
+
methodName = useFeeOnTransfer ? 'swapExactTokensForETHSupportingFeeOnTransferTokens' : 'swapExactTokensForETH';
|
|
51
|
+
// (uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
|
|
52
|
+
args = [amountIn, amountOut, path, to, deadline];
|
|
53
|
+
value = ZERO_HEX;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
methodName = useFeeOnTransfer
|
|
57
|
+
? 'swapExactTokensForTokensSupportingFeeOnTransferTokens'
|
|
58
|
+
: 'swapExactTokensForTokens';
|
|
59
|
+
// (uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
|
|
60
|
+
args = [amountIn, amountOut, path, to, deadline];
|
|
61
|
+
value = ZERO_HEX;
|
|
62
|
+
}
|
|
63
|
+
break;
|
|
64
|
+
case sdk_core_1.TradeType.EXACT_OUTPUT:
|
|
65
|
+
(0, tiny_invariant_1.default)(!useFeeOnTransfer, 'EXACT_OUT_FOT');
|
|
66
|
+
if (etherIn) {
|
|
67
|
+
methodName = 'swapETHForExactTokens';
|
|
68
|
+
// (uint amountOut, address[] calldata path, address to, uint deadline)
|
|
69
|
+
args = [amountOut, path, to, deadline];
|
|
70
|
+
value = amountIn;
|
|
71
|
+
}
|
|
72
|
+
else if (etherOut) {
|
|
73
|
+
methodName = 'swapTokensForExactETH';
|
|
74
|
+
// (uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
|
|
75
|
+
args = [amountOut, amountIn, path, to, deadline];
|
|
76
|
+
value = ZERO_HEX;
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
methodName = 'swapTokensForExactTokens';
|
|
80
|
+
// (uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
|
|
81
|
+
args = [amountOut, amountIn, path, to, deadline];
|
|
82
|
+
value = ZERO_HEX;
|
|
83
|
+
}
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
methodName,
|
|
88
|
+
args,
|
|
89
|
+
value,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
exports.Router = Router;
|
|
94
|
+
//# sourceMappingURL=router.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../../src/router.ts"],"names":[],"mappings":";;;;AAAA,uDAAuH;AAEvH,4EAAsC;AAqDtC,SAAS,KAAK,CAAC,cAAwC;IACrD,OAAO,KAAK,cAAc,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAA;AACpD,CAAC;AAED,MAAM,QAAQ,GAAG,KAAK,CAAA;AAEtB;;GAEG;AACH,MAAsB,MAAM;IAC1B;;OAEG;IACH,gBAAuB,CAAC;IACxB;;;;OAIG;IACI,MAAM,CAAC,kBAAkB,CAC9B,KAA2C,EAC3C,OAA4C;QAE5C,MAAM,OAAO,GAAG,KAAK,CAAC,WAAW,CAAC,QAAQ,CAAC,QAAQ,CAAA;QACnD,MAAM,QAAQ,GAAG,KAAK,CAAC,YAAY,CAAC,QAAQ,CAAC,QAAQ,CAAA;QACrD,oDAAoD;QACpD,IAAA,wBAAS,EAAC,CAAC,CAAC,OAAO,IAAI,QAAQ,CAAC,EAAE,cAAc,CAAC,CAAA;QACjD,IAAA,wBAAS,EAAC,CAAC,CAAC,KAAK,IAAI,OAAO,CAAC,IAAI,OAAO,CAAC,GAAG,GAAG,CAAC,EAAE,KAAK,CAAC,CAAA;QAExD,MAAM,EAAE,GAAW,IAAA,kCAAuB,EAAC,OAAO,CAAC,SAAS,CAAC,CAAA;QAC7D,MAAM,QAAQ,GAAW,KAAK,CAAC,KAAK,CAAC,eAAe,CAA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/sdk-core';
|
|
2
|
+
import JSBI from 'jsbi';
|
|
3
|
+
/**
|
|
4
|
+
* @deprecated use FACTORY_ADDRESS_MAP instead
|
|
5
|
+
*/
|
|
6
|
+
export declare const FACTORY_ADDRESS = "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f";
|
|
7
|
+
export declare const FACTORY_ADDRESS_MAP: {
|
|
8
|
+
[chainId: number]: string;
|
|
9
|
+
};
|
|
10
|
+
export declare const INIT_CODE_HASH = "0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f";
|
|
11
|
+
export declare const MINIMUM_LIQUIDITY: JSBI;
|
|
12
|
+
export declare const ZERO: JSBI;
|
|
13
|
+
export declare const ONE: JSBI;
|
|
14
|
+
export declare const FIVE: JSBI;
|
|
15
|
+
export declare const _997: JSBI;
|
|
16
|
+
export declare const _1000: JSBI;
|
|
17
|
+
export declare const BASIS_POINTS: JSBI;
|
|
18
|
+
export declare const ZERO_PERCENT: Percent;
|
|
19
|
+
export declare const ONE_HUNDRED_PERCENT: Percent;
|