@alcorexchange/alcor-swap-sdk 1.0.29 → 1.0.31
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/position.js +31 -30
- package/build/entities/trade.js +8 -2
- package/package.json +1 -1
- package/src/entities/trade.ts +3 -0
- package/tsconfig.json +1 -1
|
@@ -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
|
};
|
|
@@ -158,7 +149,19 @@ class Position {
|
|
|
158
149
|
ticks: this.pool.tickDataProvider
|
|
159
150
|
});
|
|
160
151
|
// because the router is imprecise, we need to calculate the position that will be created (assuming no slippage)
|
|
161
|
-
const positionThatWillBeCreated = Position.fromAmounts(
|
|
152
|
+
const positionThatWillBeCreated = Position.fromAmounts({
|
|
153
|
+
id: this.id,
|
|
154
|
+
owner: this.owner,
|
|
155
|
+
pool: this.pool,
|
|
156
|
+
tickLower: this.tickLower,
|
|
157
|
+
tickUpper: this.tickUpper,
|
|
158
|
+
...this.mintAmounts,
|
|
159
|
+
useFullPrecision: false,
|
|
160
|
+
feeGrowthInsideALastX64: this.feeGrowthInsideALastX64,
|
|
161
|
+
feeGrowthInsideBLastX64: this.feeGrowthInsideBLastX64,
|
|
162
|
+
feesA: this.feesA,
|
|
163
|
+
feesB: this.feesB,
|
|
164
|
+
});
|
|
162
165
|
// we want the smaller amounts...
|
|
163
166
|
// ...which occurs at the upper price for amountA...
|
|
164
167
|
const { amountA } = new Position({
|
|
@@ -361,28 +364,26 @@ class Position {
|
|
|
361
364
|
* Computes a position fees
|
|
362
365
|
* @returns The position
|
|
363
366
|
*/
|
|
364
|
-
getFees() {
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
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);
|
|
377
|
-
const { feeGrowthGlobalAX64, feeGrowthGlobalBX64 } = pool;
|
|
378
|
-
const [feeGrowthInsideAX64, feeGrowthInsideBX64] = utils_1.TickLibrary.getFeeGrowthInside(lower, upper, tickLower, tickUpper, pool.tickCurrent, feeGrowthGlobalAX64, feeGrowthGlobalBX64);
|
|
379
|
-
const tokensOwedA = jsbi_1.default.divide(jsbi_1.default.multiply((0, utils_1.subIn128)(feeGrowthInsideAX64, feeGrowthInsideALastX64), liquidity), internalConstants_1.Q64);
|
|
380
|
-
const tokensOwedB = jsbi_1.default.divide(jsbi_1.default.multiply((0, utils_1.subIn128)(feeGrowthInsideBX64, feeGrowthInsideBLastX64), liquidity), internalConstants_1.Q64);
|
|
367
|
+
async getFees() {
|
|
368
|
+
const { liquidity, tickLower, tickUpper, feeGrowthInsideALastX64, feeGrowthInsideBLastX64, pool } = this;
|
|
369
|
+
if (jsbi_1.default.equal(liquidity, internalConstants_2.ZERO) &&
|
|
370
|
+
jsbi_1.default.equal(this.feesA, internalConstants_2.ZERO) &&
|
|
371
|
+
jsbi_1.default.equal(this.feesB, internalConstants_2.ZERO)) {
|
|
381
372
|
return {
|
|
382
|
-
feesA: fractions_1.CurrencyAmount.fromRawAmount(this.pool.tokenA,
|
|
383
|
-
feesB: fractions_1.CurrencyAmount.fromRawAmount(this.pool.tokenB,
|
|
373
|
+
feesA: fractions_1.CurrencyAmount.fromRawAmount(this.pool.tokenA, internalConstants_2.ZERO),
|
|
374
|
+
feesB: fractions_1.CurrencyAmount.fromRawAmount(this.pool.tokenB, internalConstants_2.ZERO)
|
|
384
375
|
};
|
|
385
|
-
}
|
|
376
|
+
}
|
|
377
|
+
const lower = this.pool.tickDataProvider.getTick(tickLower);
|
|
378
|
+
const upper = this.pool.tickDataProvider.getTick(tickUpper);
|
|
379
|
+
const { feeGrowthGlobalAX64, feeGrowthGlobalBX64 } = pool;
|
|
380
|
+
const [feeGrowthInsideAX64, feeGrowthInsideBX64] = utils_1.TickLibrary.getFeeGrowthInside(lower, upper, tickLower, tickUpper, pool.tickCurrent, feeGrowthGlobalAX64, feeGrowthGlobalBX64);
|
|
381
|
+
const tokensOwedA = jsbi_1.default.divide(jsbi_1.default.multiply((0, utils_1.subIn128)(feeGrowthInsideAX64, feeGrowthInsideALastX64), liquidity), internalConstants_1.Q64);
|
|
382
|
+
const tokensOwedB = jsbi_1.default.divide(jsbi_1.default.multiply((0, utils_1.subIn128)(feeGrowthInsideBX64, feeGrowthInsideBLastX64), liquidity), internalConstants_1.Q64);
|
|
383
|
+
return {
|
|
384
|
+
feesA: fractions_1.CurrencyAmount.fromRawAmount(this.pool.tokenA, jsbi_1.default.add(tokensOwedA, this.feesA)),
|
|
385
|
+
feesB: fractions_1.CurrencyAmount.fromRawAmount(this.pool.tokenB, jsbi_1.default.add(tokensOwedB, this.feesB))
|
|
386
|
+
};
|
|
386
387
|
}
|
|
387
388
|
}
|
|
388
389
|
exports.Position = Position;
|
package/build/entities/trade.js
CHANGED
|
@@ -242,13 +242,16 @@ class Trade {
|
|
|
242
242
|
* @returns The unchecked trade
|
|
243
243
|
*/
|
|
244
244
|
static createUncheckedTrade(constructorArguments) {
|
|
245
|
-
return new Trade(
|
|
245
|
+
return new Trade({
|
|
246
|
+
...constructorArguments,
|
|
247
|
+
routes: [
|
|
246
248
|
{
|
|
247
249
|
inputAmount: constructorArguments.inputAmount,
|
|
248
250
|
outputAmount: constructorArguments.outputAmount,
|
|
249
251
|
route: constructorArguments.route
|
|
250
252
|
}
|
|
251
|
-
]
|
|
253
|
+
]
|
|
254
|
+
});
|
|
252
255
|
}
|
|
253
256
|
/**
|
|
254
257
|
* Creates a trade without computing the result of swapping through the routes. Useful when you have simulated the trade
|
|
@@ -331,6 +334,9 @@ class Trade {
|
|
|
331
334
|
for (const route of routes) {
|
|
332
335
|
const freshPools = route.pools.map(p => {
|
|
333
336
|
const pool = poolsMap.get(p.id);
|
|
337
|
+
if (!pool) {
|
|
338
|
+
console.log('POOL FOR ROUTE NOT FOUND', p, route.pools);
|
|
339
|
+
}
|
|
334
340
|
(0, tiny_invariant_1.default)(pool, 'POOL_FOR_ROUTE');
|
|
335
341
|
// Creating new instance
|
|
336
342
|
return pool_1.Pool.fromBuffer(pool_1.Pool.toBuffer(pool));
|
package/package.json
CHANGED
package/src/entities/trade.ts
CHANGED
|
@@ -495,6 +495,9 @@ export class Trade<TInput extends Currency, TOutput extends Currency, TTradeType
|
|
|
495
495
|
for (const route of routes) {
|
|
496
496
|
const freshPools = route.pools.map(p => {
|
|
497
497
|
const pool = poolsMap.get(p.id)
|
|
498
|
+
if (!pool) {
|
|
499
|
+
console.log('POOL FOR ROUTE NOT FOUND', p, route.pools)
|
|
500
|
+
}
|
|
498
501
|
invariant(pool, 'POOL_FOR_ROUTE')
|
|
499
502
|
|
|
500
503
|
// Creating new instance
|