@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.
@@ -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(Object.assign(Object.assign({ id: this.id, owner: this.owner, pool: this.pool, tickLower: this.tickLower, tickUpper: this.tickUpper }, this.mintAmounts), { useFullPrecision: false, feeGrowthInsideALastX64: this.feeGrowthInsideALastX64, feeGrowthInsideBLastX64: this.feeGrowthInsideBLastX64, feesA: this.feesA, feesB: this.feesB }));
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
- return __awaiter(this, void 0, void 0, function* () {
366
- const { liquidity, tickLower, tickUpper, feeGrowthInsideALastX64, feeGrowthInsideBLastX64, pool } = this;
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);
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, jsbi_1.default.add(tokensOwedA, this.feesA)),
383
- feesB: fractions_1.CurrencyAmount.fromRawAmount(this.pool.tokenB, jsbi_1.default.add(tokensOwedB, this.feesB))
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;
@@ -242,13 +242,16 @@ class Trade {
242
242
  * @returns The unchecked trade
243
243
  */
244
244
  static createUncheckedTrade(constructorArguments) {
245
- return new Trade(Object.assign(Object.assign({}, constructorArguments), { routes: [
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alcorexchange/alcor-swap-sdk",
3
- "version": "1.0.29",
3
+ "version": "1.0.31",
4
4
  "description": "",
5
5
  "main": "build/index.js",
6
6
  "scripts": {
@@ -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
package/tsconfig.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "target": "es2016",
3
+ "target": "es2019",
4
4
  "lib": [
5
5
  "es6"
6
6
  ],