@alcorexchange/alcor-swap-sdk 1.0.24 → 1.0.26
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/build/entities/pool.d.ts +2 -2
- package/build/entities/pool.js +109 -124
- package/build/entities/position.js +10 -2
- package/build/entities/tickDataProvider.d.ts +4 -4
- package/build/entities/tickDataProvider.js +2 -15
- package/build/entities/tickListDataProvider.d.ts +2 -2
- package/build/entities/tickListDataProvider.js +2 -15
- package/build/entities/trade.d.ts +6 -39
- package/build/entities/trade.js +81 -226
- package/examples/getTrateRoute.ts +4 -1
- package/package.json +1 -1
- package/src/entities/pool.ts +11 -11
- package/src/entities/position.ts +13 -2
- package/src/entities/tickDataProvider.ts +5 -5
- package/src/entities/tickListDataProvider.ts +4 -4
- package/src/entities/trade.ts +18 -190
- package/test/tickDataProvider.test.ts +1 -1
package/build/entities/pool.d.ts
CHANGED
|
@@ -69,14 +69,14 @@ export declare class Pool {
|
|
|
69
69
|
* @param sqrtPriceLimitX64 The Q64.96 sqrt price limit
|
|
70
70
|
* @returns The output amount and the pool with updated state
|
|
71
71
|
*/
|
|
72
|
-
getOutputAmount(inputAmount: CurrencyAmount<Token>, sqrtPriceLimitX64?: JSBI):
|
|
72
|
+
getOutputAmount(inputAmount: CurrencyAmount<Token>, sqrtPriceLimitX64?: JSBI): [CurrencyAmount<Token>, Pool];
|
|
73
73
|
/**
|
|
74
74
|
* Given a desired output amount of a token, return the computed input amount and a pool with state updated after the trade
|
|
75
75
|
* @param outputAmount the output amount for which to quote the input amount
|
|
76
76
|
* @param sqrtPriceLimitX64 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this value after the swap. If one for zero, the price cannot be greater than this value after the swap
|
|
77
77
|
* @returns The input amount and the pool with updated state
|
|
78
78
|
*/
|
|
79
|
-
getInputAmount(outputAmount: CurrencyAmount<Token>, sqrtPriceLimitX64?: JSBI):
|
|
79
|
+
getInputAmount(outputAmount: CurrencyAmount<Token>, sqrtPriceLimitX64?: JSBI): [CurrencyAmount<Token>, Pool];
|
|
80
80
|
/**
|
|
81
81
|
* Executes a swap
|
|
82
82
|
* @param zeroForOne Whether the amount in is tokenA or tokenB
|
package/build/entities/pool.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -100,27 +91,25 @@ class Pool {
|
|
|
100
91
|
* @returns The output amount and the pool with updated state
|
|
101
92
|
*/
|
|
102
93
|
getOutputAmount(inputAmount, sqrtPriceLimitX64) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
];
|
|
123
|
-
});
|
|
94
|
+
(0, tiny_invariant_1.default)(this.involvesToken(inputAmount.currency), "TOKEN");
|
|
95
|
+
const zeroForOne = inputAmount.currency.equals(this.tokenA);
|
|
96
|
+
const { amountCalculated: outputAmount, sqrtPriceX64, liquidity, tickCurrent, } = this.swap(zeroForOne, inputAmount.quotient, sqrtPriceLimitX64);
|
|
97
|
+
const outputToken = zeroForOne ? this.tokenB : this.tokenA;
|
|
98
|
+
return [
|
|
99
|
+
fractions_1.CurrencyAmount.fromRawAmount(outputToken, jsbi_1.default.multiply(outputAmount, internalConstants_2.NEGATIVE_ONE)),
|
|
100
|
+
new Pool({
|
|
101
|
+
id: this.id,
|
|
102
|
+
tokenA: this.tokenA,
|
|
103
|
+
tokenB: this.tokenB,
|
|
104
|
+
fee: this.fee,
|
|
105
|
+
sqrtPriceX64,
|
|
106
|
+
liquidity,
|
|
107
|
+
tickCurrent,
|
|
108
|
+
ticks: this.tickDataProvider,
|
|
109
|
+
feeGrowthGlobalAX64: this.feeGrowthGlobalAX64,
|
|
110
|
+
feeGrowthGlobalBX64: this.feeGrowthGlobalBX64,
|
|
111
|
+
})
|
|
112
|
+
];
|
|
124
113
|
}
|
|
125
114
|
/**
|
|
126
115
|
* Given a desired output amount of a token, return the computed input amount and a pool with state updated after the trade
|
|
@@ -129,26 +118,24 @@ class Pool {
|
|
|
129
118
|
* @returns The input amount and the pool with updated state
|
|
130
119
|
*/
|
|
131
120
|
getInputAmount(outputAmount, sqrtPriceLimitX64) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
];
|
|
151
|
-
});
|
|
121
|
+
const zeroForOne = outputAmount.currency.equals(this.tokenB);
|
|
122
|
+
const { amountCalculated: inputAmount, sqrtPriceX64, liquidity, tickCurrent, } = this.swap(zeroForOne, jsbi_1.default.multiply(outputAmount.quotient, internalConstants_2.NEGATIVE_ONE), sqrtPriceLimitX64);
|
|
123
|
+
const inputToken = zeroForOne ? this.tokenA : this.tokenB;
|
|
124
|
+
return [
|
|
125
|
+
fractions_1.CurrencyAmount.fromRawAmount(inputToken, inputAmount),
|
|
126
|
+
new Pool({
|
|
127
|
+
id: this.id,
|
|
128
|
+
tokenA: this.tokenA,
|
|
129
|
+
tokenB: this.tokenB,
|
|
130
|
+
fee: this.fee,
|
|
131
|
+
sqrtPriceX64,
|
|
132
|
+
liquidity,
|
|
133
|
+
tickCurrent,
|
|
134
|
+
ticks: this.tickDataProvider,
|
|
135
|
+
feeGrowthGlobalAX64: this.feeGrowthGlobalAX64,
|
|
136
|
+
feeGrowthGlobalBX64: this.feeGrowthGlobalBX64,
|
|
137
|
+
}),
|
|
138
|
+
];
|
|
152
139
|
}
|
|
153
140
|
/**
|
|
154
141
|
* Executes a swap
|
|
@@ -161,85 +148,83 @@ class Pool {
|
|
|
161
148
|
* @returns tickCurrent
|
|
162
149
|
*/
|
|
163
150
|
swap(zeroForOne, amountSpecified, sqrtPriceLimitX64) {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
151
|
+
if (!sqrtPriceLimitX64)
|
|
152
|
+
sqrtPriceLimitX64 = zeroForOne
|
|
153
|
+
? jsbi_1.default.add(tickMath_1.TickMath.MIN_SQRT_RATIO, internalConstants_2.ONE)
|
|
154
|
+
: jsbi_1.default.subtract(tickMath_1.TickMath.MAX_SQRT_RATIO, internalConstants_2.ONE);
|
|
155
|
+
if (zeroForOne) {
|
|
156
|
+
(0, tiny_invariant_1.default)(jsbi_1.default.greaterThan(sqrtPriceLimitX64, tickMath_1.TickMath.MIN_SQRT_RATIO), "RATIO_MIN");
|
|
157
|
+
(0, tiny_invariant_1.default)(jsbi_1.default.lessThan(sqrtPriceLimitX64, this.sqrtPriceX64), "RATIO_CURRENT");
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
(0, tiny_invariant_1.default)(jsbi_1.default.lessThan(sqrtPriceLimitX64, tickMath_1.TickMath.MAX_SQRT_RATIO), "RATIO_MAX");
|
|
161
|
+
(0, tiny_invariant_1.default)(jsbi_1.default.greaterThan(sqrtPriceLimitX64, this.sqrtPriceX64), "RATIO_CURRENT");
|
|
162
|
+
}
|
|
163
|
+
const exactInput = jsbi_1.default.greaterThanOrEqual(amountSpecified, internalConstants_2.ZERO);
|
|
164
|
+
// keep track of swap state
|
|
165
|
+
const state = {
|
|
166
|
+
amountSpecifiedRemaining: amountSpecified,
|
|
167
|
+
amountCalculated: internalConstants_2.ZERO,
|
|
168
|
+
sqrtPriceX64: this.sqrtPriceX64,
|
|
169
|
+
tick: this.tickCurrent,
|
|
170
|
+
liquidity: this.liquidity,
|
|
171
|
+
};
|
|
172
|
+
// start swap while loop
|
|
173
|
+
while (jsbi_1.default.notEqual(state.amountSpecifiedRemaining, internalConstants_2.ZERO) &&
|
|
174
|
+
state.sqrtPriceX64 != sqrtPriceLimitX64) {
|
|
175
|
+
const step = {};
|
|
176
|
+
step.sqrtPriceStartX64 = state.sqrtPriceX64;
|
|
177
|
+
// because each iteration of the while loop rounds, we can't optimize this code (relative to the smart contract)
|
|
178
|
+
// by simply traversing to the next available tick, we instead need to exactly replicate
|
|
179
|
+
// tickBitmap.nextInitializedTickWithinOneWord
|
|
180
|
+
[step.tickNext, step.initialized] =
|
|
181
|
+
this.tickDataProvider.nextInitializedTickWithinOneWord(state.tick, zeroForOne, this.tickSpacing);
|
|
182
|
+
if (step.tickNext < tickMath_1.TickMath.MIN_TICK) {
|
|
183
|
+
step.tickNext = tickMath_1.TickMath.MIN_TICK;
|
|
184
|
+
}
|
|
185
|
+
else if (step.tickNext > tickMath_1.TickMath.MAX_TICK) {
|
|
186
|
+
step.tickNext = tickMath_1.TickMath.MAX_TICK;
|
|
187
|
+
}
|
|
188
|
+
step.sqrtPriceNextX64 = tickMath_1.TickMath.getSqrtRatioAtTick(step.tickNext);
|
|
189
|
+
[state.sqrtPriceX64, step.amountIn, step.amountOut, step.feeAmount] =
|
|
190
|
+
swapMath_1.SwapMath.computeSwapStep(state.sqrtPriceX64, (zeroForOne
|
|
191
|
+
? jsbi_1.default.lessThan(step.sqrtPriceNextX64, sqrtPriceLimitX64)
|
|
192
|
+
: jsbi_1.default.greaterThan(step.sqrtPriceNextX64, sqrtPriceLimitX64))
|
|
193
|
+
? sqrtPriceLimitX64
|
|
194
|
+
: step.sqrtPriceNextX64, state.liquidity, state.amountSpecifiedRemaining, this.fee);
|
|
195
|
+
if (exactInput) {
|
|
196
|
+
state.amountSpecifiedRemaining = jsbi_1.default.subtract(state.amountSpecifiedRemaining, jsbi_1.default.add(step.amountIn, step.feeAmount));
|
|
197
|
+
state.amountCalculated = jsbi_1.default.subtract(state.amountCalculated, step.amountOut);
|
|
172
198
|
}
|
|
173
199
|
else {
|
|
174
|
-
|
|
175
|
-
|
|
200
|
+
state.amountSpecifiedRemaining = jsbi_1.default.add(state.amountSpecifiedRemaining, step.amountOut);
|
|
201
|
+
state.amountCalculated = jsbi_1.default.add(state.amountCalculated, jsbi_1.default.add(step.amountIn, step.feeAmount));
|
|
176
202
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
while (jsbi_1.default.notEqual(state.amountSpecifiedRemaining, internalConstants_2.ZERO) &&
|
|
188
|
-
state.sqrtPriceX64 != sqrtPriceLimitX64) {
|
|
189
|
-
const step = {};
|
|
190
|
-
step.sqrtPriceStartX64 = state.sqrtPriceX64;
|
|
191
|
-
// because each iteration of the while loop rounds, we can't optimize this code (relative to the smart contract)
|
|
192
|
-
// by simply traversing to the next available tick, we instead need to exactly replicate
|
|
193
|
-
// tickBitmap.nextInitializedTickWithinOneWord
|
|
194
|
-
[step.tickNext, step.initialized] =
|
|
195
|
-
yield this.tickDataProvider.nextInitializedTickWithinOneWord(state.tick, zeroForOne, this.tickSpacing);
|
|
196
|
-
if (step.tickNext < tickMath_1.TickMath.MIN_TICK) {
|
|
197
|
-
step.tickNext = tickMath_1.TickMath.MIN_TICK;
|
|
198
|
-
}
|
|
199
|
-
else if (step.tickNext > tickMath_1.TickMath.MAX_TICK) {
|
|
200
|
-
step.tickNext = tickMath_1.TickMath.MAX_TICK;
|
|
201
|
-
}
|
|
202
|
-
step.sqrtPriceNextX64 = tickMath_1.TickMath.getSqrtRatioAtTick(step.tickNext);
|
|
203
|
-
[state.sqrtPriceX64, step.amountIn, step.amountOut, step.feeAmount] =
|
|
204
|
-
swapMath_1.SwapMath.computeSwapStep(state.sqrtPriceX64, (zeroForOne
|
|
205
|
-
? jsbi_1.default.lessThan(step.sqrtPriceNextX64, sqrtPriceLimitX64)
|
|
206
|
-
: jsbi_1.default.greaterThan(step.sqrtPriceNextX64, sqrtPriceLimitX64))
|
|
207
|
-
? sqrtPriceLimitX64
|
|
208
|
-
: step.sqrtPriceNextX64, state.liquidity, state.amountSpecifiedRemaining, this.fee);
|
|
209
|
-
if (exactInput) {
|
|
210
|
-
state.amountSpecifiedRemaining = jsbi_1.default.subtract(state.amountSpecifiedRemaining, jsbi_1.default.add(step.amountIn, step.feeAmount));
|
|
211
|
-
state.amountCalculated = jsbi_1.default.subtract(state.amountCalculated, step.amountOut);
|
|
212
|
-
}
|
|
213
|
-
else {
|
|
214
|
-
state.amountSpecifiedRemaining = jsbi_1.default.add(state.amountSpecifiedRemaining, step.amountOut);
|
|
215
|
-
state.amountCalculated = jsbi_1.default.add(state.amountCalculated, jsbi_1.default.add(step.amountIn, step.feeAmount));
|
|
216
|
-
}
|
|
217
|
-
// TODO
|
|
218
|
-
if (jsbi_1.default.equal(state.sqrtPriceX64, step.sqrtPriceNextX64)) {
|
|
219
|
-
// if the tick is initialized, run the tick transition
|
|
220
|
-
if (step.initialized) {
|
|
221
|
-
let liquidityNet = jsbi_1.default.BigInt((yield this.tickDataProvider.getTick(step.tickNext)).liquidityNet);
|
|
222
|
-
// if we're moving leftward, we interpret liquidityNet as the opposite sign
|
|
223
|
-
// safe because liquidityNet cannot be type(int128).min
|
|
224
|
-
if (zeroForOne)
|
|
225
|
-
liquidityNet = jsbi_1.default.multiply(liquidityNet, internalConstants_2.NEGATIVE_ONE);
|
|
226
|
-
state.liquidity = liquidityMath_1.LiquidityMath.addDelta(state.liquidity, liquidityNet);
|
|
227
|
-
}
|
|
228
|
-
state.tick = zeroForOne ? step.tickNext - 1 : step.tickNext;
|
|
229
|
-
}
|
|
230
|
-
else if (jsbi_1.default.notEqual(state.sqrtPriceX64, step.sqrtPriceStartX64)) {
|
|
231
|
-
// updated comparison function
|
|
232
|
-
// recompute unless we're on a lower tick boundary (i.e. already transitioned ticks), and haven't moved
|
|
233
|
-
state.tick = tickMath_1.TickMath.getTickAtSqrtRatio(state.sqrtPriceX64);
|
|
203
|
+
// TODO
|
|
204
|
+
if (jsbi_1.default.equal(state.sqrtPriceX64, step.sqrtPriceNextX64)) {
|
|
205
|
+
// if the tick is initialized, run the tick transition
|
|
206
|
+
if (step.initialized) {
|
|
207
|
+
let liquidityNet = jsbi_1.default.BigInt((this.tickDataProvider.getTick(step.tickNext)).liquidityNet);
|
|
208
|
+
// if we're moving leftward, we interpret liquidityNet as the opposite sign
|
|
209
|
+
// safe because liquidityNet cannot be type(int128).min
|
|
210
|
+
if (zeroForOne)
|
|
211
|
+
liquidityNet = jsbi_1.default.multiply(liquidityNet, internalConstants_2.NEGATIVE_ONE);
|
|
212
|
+
state.liquidity = liquidityMath_1.LiquidityMath.addDelta(state.liquidity, liquidityNet);
|
|
234
213
|
}
|
|
214
|
+
state.tick = zeroForOne ? step.tickNext - 1 : step.tickNext;
|
|
215
|
+
}
|
|
216
|
+
else if (jsbi_1.default.notEqual(state.sqrtPriceX64, step.sqrtPriceStartX64)) {
|
|
217
|
+
// updated comparison function
|
|
218
|
+
// recompute unless we're on a lower tick boundary (i.e. already transitioned ticks), and haven't moved
|
|
219
|
+
state.tick = tickMath_1.TickMath.getTickAtSqrtRatio(state.sqrtPriceX64);
|
|
235
220
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
}
|
|
221
|
+
}
|
|
222
|
+
return {
|
|
223
|
+
amountCalculated: state.amountCalculated,
|
|
224
|
+
sqrtPriceX64: state.sqrtPriceX64,
|
|
225
|
+
liquidity: state.liquidity,
|
|
226
|
+
tickCurrent: state.tick,
|
|
227
|
+
};
|
|
243
228
|
}
|
|
244
229
|
get tickSpacing() {
|
|
245
230
|
return internalConstants_1.TICK_SPACINGS[this.fee];
|
|
@@ -364,8 +364,16 @@ class Position {
|
|
|
364
364
|
getFees() {
|
|
365
365
|
return __awaiter(this, void 0, void 0, function* () {
|
|
366
366
|
const { liquidity, tickLower, tickUpper, feeGrowthInsideALastX64, feeGrowthInsideBLastX64, pool } = this;
|
|
367
|
-
|
|
368
|
-
|
|
367
|
+
if (jsbi_1.default.equal(liquidity, internalConstants_2.ZERO) &&
|
|
368
|
+
jsbi_1.default.equal(this.feesA, internalConstants_2.ZERO) &&
|
|
369
|
+
jsbi_1.default.equal(this.feesB, internalConstants_2.ZERO)) {
|
|
370
|
+
return {
|
|
371
|
+
feesA: fractions_1.CurrencyAmount.fromRawAmount(this.pool.tokenA, internalConstants_2.ZERO),
|
|
372
|
+
feesB: fractions_1.CurrencyAmount.fromRawAmount(this.pool.tokenB, internalConstants_2.ZERO)
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
const lower = this.pool.tickDataProvider.getTick(tickLower);
|
|
376
|
+
const upper = this.pool.tickDataProvider.getTick(tickUpper);
|
|
369
377
|
const { feeGrowthGlobalAX64, feeGrowthGlobalBX64 } = pool;
|
|
370
378
|
const [feeGrowthInsideAX64, feeGrowthInsideBX64] = utils_1.TickLibrary.getFeeGrowthInside(lower, upper, tickLower, tickUpper, pool.tickCurrent, feeGrowthGlobalAX64, feeGrowthGlobalBX64);
|
|
371
379
|
const tokensOwedA = jsbi_1.default.divide(jsbi_1.default.multiply((0, utils_1.subIn128)(feeGrowthInsideAX64, feeGrowthInsideALastX64), liquidity), internalConstants_1.Q64);
|
|
@@ -7,14 +7,14 @@ export interface TickDataProvider {
|
|
|
7
7
|
* Return information corresponding to a specific tick
|
|
8
8
|
* @param tick the tick to load
|
|
9
9
|
*/
|
|
10
|
-
getTick(tick: number):
|
|
10
|
+
getTick(tick: number): Tick;
|
|
11
11
|
/**
|
|
12
12
|
* Return the next tick that is initialized within a single word
|
|
13
13
|
* @param tick The current tick
|
|
14
14
|
* @param lte Whether the next tick should be lte the current tick
|
|
15
15
|
* @param tickSpacing The tick spacing of the pool
|
|
16
16
|
*/
|
|
17
|
-
nextInitializedTickWithinOneWord(tick: number, lte: boolean, tickSpacing: number):
|
|
17
|
+
nextInitializedTickWithinOneWord(tick: number, lte: boolean, tickSpacing: number): [number, boolean];
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
20
|
* This tick data provider does not know how to fetch any tick data. It throws whenever it is required. Useful if you
|
|
@@ -22,6 +22,6 @@ export interface TickDataProvider {
|
|
|
22
22
|
*/
|
|
23
23
|
export declare class NoTickDataProvider implements TickDataProvider {
|
|
24
24
|
private static ERROR_MESSAGE;
|
|
25
|
-
getTick(_tick: number):
|
|
26
|
-
nextInitializedTickWithinOneWord(_tick: number, _lte: boolean, _tickSpacing: number):
|
|
25
|
+
getTick(_tick: number): Tick;
|
|
26
|
+
nextInitializedTickWithinOneWord(_tick: number, _lte: boolean, _tickSpacing: number): [number, boolean];
|
|
27
27
|
}
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.NoTickDataProvider = void 0;
|
|
13
4
|
/**
|
|
@@ -16,14 +7,10 @@ exports.NoTickDataProvider = void 0;
|
|
|
16
7
|
*/
|
|
17
8
|
class NoTickDataProvider {
|
|
18
9
|
getTick(_tick) {
|
|
19
|
-
|
|
20
|
-
throw new Error(NoTickDataProvider.ERROR_MESSAGE);
|
|
21
|
-
});
|
|
10
|
+
throw new Error(NoTickDataProvider.ERROR_MESSAGE);
|
|
22
11
|
}
|
|
23
12
|
nextInitializedTickWithinOneWord(_tick, _lte, _tickSpacing) {
|
|
24
|
-
|
|
25
|
-
throw new Error(NoTickDataProvider.ERROR_MESSAGE);
|
|
26
|
-
});
|
|
13
|
+
throw new Error(NoTickDataProvider.ERROR_MESSAGE);
|
|
27
14
|
}
|
|
28
15
|
}
|
|
29
16
|
exports.NoTickDataProvider = NoTickDataProvider;
|
|
@@ -6,6 +6,6 @@ import { TickDataProvider } from "./tickDataProvider";
|
|
|
6
6
|
export declare class TickListDataProvider implements TickDataProvider {
|
|
7
7
|
private ticks;
|
|
8
8
|
constructor(ticks: (Tick | TickConstructorArgs)[], tickSpacing: number);
|
|
9
|
-
getTick(tick: number):
|
|
10
|
-
nextInitializedTickWithinOneWord(tick: number, lte: boolean, tickSpacing: number):
|
|
9
|
+
getTick(tick: number): Tick;
|
|
10
|
+
nextInitializedTickWithinOneWord(tick: number, lte: boolean, tickSpacing: number): [number, boolean];
|
|
11
11
|
}
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.TickListDataProvider = void 0;
|
|
13
4
|
const tickList_1 = require("../utils/tickList");
|
|
@@ -22,14 +13,10 @@ class TickListDataProvider {
|
|
|
22
13
|
this.ticks = ticksMapped;
|
|
23
14
|
}
|
|
24
15
|
getTick(tick) {
|
|
25
|
-
return
|
|
26
|
-
return tickList_1.TickList.getTick(this.ticks, tick);
|
|
27
|
-
});
|
|
16
|
+
return tickList_1.TickList.getTick(this.ticks, tick);
|
|
28
17
|
}
|
|
29
18
|
nextInitializedTickWithinOneWord(tick, lte, tickSpacing) {
|
|
30
|
-
return
|
|
31
|
-
return tickList_1.TickList.nextInitializedTickWithinOneWord(this.ticks, tick, lte, tickSpacing);
|
|
32
|
-
});
|
|
19
|
+
return tickList_1.TickList.nextInitializedTickWithinOneWord(this.ticks, tick, lte, tickSpacing);
|
|
33
20
|
}
|
|
34
21
|
}
|
|
35
22
|
exports.TickListDataProvider = TickListDataProvider;
|
|
@@ -95,7 +95,7 @@ export declare class Trade<TInput extends Currency, TOutput extends Currency, TT
|
|
|
95
95
|
* @param amountIn The amount being passed in
|
|
96
96
|
* @returns The exact in trade
|
|
97
97
|
*/
|
|
98
|
-
static exactIn<TInput extends Currency, TOutput extends Currency>(route: Route<TInput, TOutput>, amountIn: CurrencyAmount<TInput>):
|
|
98
|
+
static exactIn<TInput extends Currency, TOutput extends Currency>(route: Route<TInput, TOutput>, amountIn: CurrencyAmount<TInput>): Trade<TInput, TOutput, TradeType.EXACT_INPUT>;
|
|
99
99
|
/**
|
|
100
100
|
* Constructs an exact out trade with the given amount out and route
|
|
101
101
|
* @template TInput The input token, either Ether or an ERC-20
|
|
@@ -104,7 +104,7 @@ export declare class Trade<TInput extends Currency, TOutput extends Currency, TT
|
|
|
104
104
|
* @param amountOut The amount returned by the trade
|
|
105
105
|
* @returns The exact out trade
|
|
106
106
|
*/
|
|
107
|
-
static exactOut<TInput extends Currency, TOutput extends Currency>(route: Route<TInput, TOutput>, amountOut: CurrencyAmount<TOutput>):
|
|
107
|
+
static exactOut<TInput extends Currency, TOutput extends Currency>(route: Route<TInput, TOutput>, amountOut: CurrencyAmount<TOutput>): Trade<TInput, TOutput, TradeType.EXACT_OUTPUT>;
|
|
108
108
|
/**
|
|
109
109
|
* Constructs a trade by simulating swaps through the given route
|
|
110
110
|
* @template TInput The input token, either Ether or an ERC-20.
|
|
@@ -115,7 +115,7 @@ export declare class Trade<TInput extends Currency, TOutput extends Currency, TT
|
|
|
115
115
|
* @param tradeType whether the trade is an exact input or exact output swap
|
|
116
116
|
* @returns The route
|
|
117
117
|
*/
|
|
118
|
-
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):
|
|
118
|
+
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): Trade<TInput, TOutput, TTradeType>;
|
|
119
119
|
/**
|
|
120
120
|
* Constructs a trade from routes by simulating swaps
|
|
121
121
|
*
|
|
@@ -129,7 +129,7 @@ export declare class Trade<TInput extends Currency, TOutput extends Currency, TT
|
|
|
129
129
|
static fromRoutes<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType>(routes: {
|
|
130
130
|
amount: TTradeType extends TradeType.EXACT_INPUT ? CurrencyAmount<TInput> : CurrencyAmount<TOutput>;
|
|
131
131
|
route: Route<TInput, TOutput>;
|
|
132
|
-
}[], tradeType: TTradeType):
|
|
132
|
+
}[], tradeType: TTradeType): Trade<TInput, TOutput, TTradeType>;
|
|
133
133
|
/**
|
|
134
134
|
* Creates a trade without computing the result of swapping through the route. Useful when you have simulated the trade
|
|
135
135
|
* elsewhere and do not have any tick data
|
|
@@ -186,39 +186,6 @@ export declare class Trade<TInput extends Currency, TOutput extends Currency, TT
|
|
|
186
186
|
* @returns The execution price
|
|
187
187
|
*/
|
|
188
188
|
worstExecutionPrice(slippageTolerance: Percent): Price<TInput, TOutput>;
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
* amount to an output token, making at most `maxHops` hops.
|
|
192
|
-
* Note this does not consider aggregation, as routes are linear. It's possible a better route exists by splitting
|
|
193
|
-
* the amount in among multiple routes.
|
|
194
|
-
* @param pools the pools to consider in finding the best trade
|
|
195
|
-
* @param nextAmountIn exact amount of input currency to spend
|
|
196
|
-
* @param currencyOut the desired currency out
|
|
197
|
-
* @param maxNumResults maximum number of results to return
|
|
198
|
-
* @param maxHops maximum number of hops a returned trade can make, e.g. 1 hop goes through a single pool
|
|
199
|
-
* @param currentPools used in recursion; the current list of pools
|
|
200
|
-
* @param currencyAmountIn used in recursion; the original value of the currencyAmountIn parameter
|
|
201
|
-
* @param bestTrades used in recursion; the current list of best trades
|
|
202
|
-
* @returns The exact in trade
|
|
203
|
-
*/
|
|
204
|
-
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>[]>;
|
|
205
|
-
/**
|
|
206
|
-
* similar to the above method but instead targets a fixed output amount
|
|
207
|
-
* given a list of pools, and a fixed amount out, returns the top `maxNumResults` trades that go from an input token
|
|
208
|
-
* to an output token amount, making at most `maxHops` hops
|
|
209
|
-
* note this does not consider aggregation, as routes are linear. it's possible a better route exists by splitting
|
|
210
|
-
* the amount in among multiple routes.
|
|
211
|
-
* @param pools the pools to consider in finding the best trade
|
|
212
|
-
* @param currencyIn the currency to spend
|
|
213
|
-
* @param currencyAmountOut the desired currency amount out
|
|
214
|
-
* @param nextAmountOut the exact amount of currency out
|
|
215
|
-
* @param maxNumResults maximum number of results to return
|
|
216
|
-
* @param maxHops maximum number of hops a returned trade can make, e.g. 1 hop goes through a single pool
|
|
217
|
-
* @param currentPools used in recursion; the current list of pools
|
|
218
|
-
* @param bestTrades used in recursion; the current list of best trades
|
|
219
|
-
* @returns The exact out trade
|
|
220
|
-
*/
|
|
221
|
-
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>[]>;
|
|
222
|
-
static bestTradeExactIn2<TInput extends Currency, TOutput extends Currency>(routes: Route<TInput, TOutput>[], pools: Pool[], currencyAmountIn: CurrencyAmount<TInput>, maxNumResults?: number): Promise<Trade<TInput, TOutput, TradeType.EXACT_INPUT>[]>;
|
|
223
|
-
static bestTradeExactOut2<TInput extends Currency, TOutput extends Currency>(routes: Route<TInput, TOutput>[], pools: Pool[], currencyAmountOut: CurrencyAmount<TOutput>, maxNumResults?: number): Promise<Trade<TInput, TOutput, TradeType.EXACT_OUTPUT>[]>;
|
|
189
|
+
static bestTradeExactIn<TInput extends Currency, TOutput extends Currency>(routes: Route<TInput, TOutput>[], pools: Pool[], currencyAmountIn: CurrencyAmount<TInput>, maxNumResults?: number): Trade<TInput, TOutput, TradeType.EXACT_INPUT>[];
|
|
190
|
+
static bestTradeExactOut<TInput extends Currency, TOutput extends Currency>(routes: Route<TInput, TOutput>[], pools: Pool[], currencyAmountOut: CurrencyAmount<TOutput>, maxNumResults?: number): Trade<TInput, TOutput, TradeType.EXACT_OUTPUT>[];
|
|
224
191
|
}
|