@gala-chain/gswap-sdk 0.0.0-preview → 0.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/dist/index.mjs CHANGED
@@ -281,7 +281,7 @@ import crypto from "crypto";
281
281
 
282
282
  // src/utils/debug.ts
283
283
  import debug from "debug";
284
- var debugLog = debug("GALASWAP_DEX");
284
+ var debugLog = debug("GSWAP_SDK");
285
285
 
286
286
  // src/classes/event_socket_client.ts
287
287
  import { EventEmitter } from "events";
@@ -678,8 +678,6 @@ function parseTokenClassKey(tokenClassKey) {
678
678
  additionalKey
679
679
  };
680
680
  }
681
-
682
- // src/utils/token_ordering.ts
683
681
  function compareTokens(first, second) {
684
682
  return stringifyTokenClassKey(first).localeCompare(stringifyTokenClassKey(second));
685
683
  }
@@ -918,7 +916,7 @@ var Positions = class {
918
916
  * ```
919
917
  */
920
918
  async addLiquidityByTicks(args) {
921
- var _a, _b, _c, _d, _e;
919
+ var _a;
922
920
  const walletAddress = args.walletAddress ?? ((_a = this.options) == null ? void 0 : _a.walletAddress);
923
921
  validateWalletAddress(walletAddress);
924
922
  validateFee(args.fee);
@@ -943,10 +941,10 @@ var Positions = class {
943
941
  owner: args.walletAddress,
944
942
  tickLower: args.tickLower,
945
943
  tickUpper: args.tickUpper,
946
- amount0Desired: (_b = ordering == null ? void 0 : ordering.token0Attributes) == null ? void 0 : _b[0],
947
- amount1Desired: (_c = ordering == null ? void 0 : ordering.token1Attributes) == null ? void 0 : _c[0],
948
- amount0Min: (_d = ordering == null ? void 0 : ordering.token0Attributes) == null ? void 0 : _d[1],
949
- amount1Min: (_e = ordering == null ? void 0 : ordering.token1Attributes) == null ? void 0 : _e[1],
944
+ amount0Desired: BigNumber3(ordering.token0Attributes[0]).toFixed(),
945
+ amount1Desired: BigNumber3(ordering.token1Attributes[0]).toFixed(),
946
+ amount0Min: BigNumber3(ordering.token0Attributes[1]).toFixed(),
947
+ amount1Min: BigNumber3(ordering.token1Attributes[1]).toFixed(),
950
948
  positionId: args.positionId
951
949
  };
952
950
  const token0StringKey = stringifyTokenClassKey(ordering.token0, "$");
@@ -1121,7 +1119,7 @@ var Positions = class {
1121
1119
  fee: args.fee,
1122
1120
  tickLower: args.tickLower,
1123
1121
  tickUpper: args.tickUpper,
1124
- amount: args.amount.toString(),
1122
+ amount: BigNumber3(args.amount).toFixed(),
1125
1123
  amount0Min: ((_b = ordering == null ? void 0 : ordering.token0Attributes) == null ? void 0 : _b[0]) || "0",
1126
1124
  amount1Min: ((_c = ordering == null ? void 0 : ordering.token1Attributes) == null ? void 0 : _c[0]) || "0",
1127
1125
  positionId: args.positionId
@@ -1175,7 +1173,7 @@ var Positions = class {
1175
1173
  * ```
1176
1174
  */
1177
1175
  async collectPositionFees(args) {
1178
- var _a, _b, _c;
1176
+ var _a;
1179
1177
  const walletAddress = args.walletAddress ?? ((_a = this.options) == null ? void 0 : _a.walletAddress);
1180
1178
  validateWalletAddress(walletAddress);
1181
1179
  validateFee(args.fee);
@@ -1195,8 +1193,8 @@ var Positions = class {
1195
1193
  token0: ordering.token0,
1196
1194
  token1: ordering.token1,
1197
1195
  fee: args.fee,
1198
- amount0Requested: (_b = ordering == null ? void 0 : ordering.token0Attributes) == null ? void 0 : _b[0],
1199
- amount1Requested: (_c = ordering == null ? void 0 : ordering.token1Attributes) == null ? void 0 : _c[0],
1196
+ amount0Requested: BigNumber3(ordering.token0Attributes[0]).toFixed(),
1197
+ amount1Requested: BigNumber3(ordering.token1Attributes[0]).toFixed(),
1200
1198
  tickLower: args.tickLower,
1201
1199
  tickUpper: args.tickUpper,
1202
1200
  positionId: args.positionId
@@ -1235,7 +1233,8 @@ var Positions = class {
1235
1233
  bnUpperPrice = bnUpperPrice.isFinite() ? bnUpperPrice : BigNumber3(1e18);
1236
1234
  const liquidityAmount = bnTokenAmount.times(10 ** (tokenDecimals - otherTokenDecimals)).times(bnSpotPrice.sqrt()).times(bnUpperPrice.sqrt()).div(bnUpperPrice.sqrt().minus(bnSpotPrice.sqrt()));
1237
1235
  const yAmount = BigNumber3(liquidityAmount).times(bnSpotPrice.sqrt().minus(bnLowerPrice.sqrt()));
1238
- return yAmount.div(BigNumber3(10).pow(tokenDecimals - otherTokenDecimals));
1236
+ const untruncated = yAmount.div(BigNumber3(10).pow(tokenDecimals - otherTokenDecimals));
1237
+ return BigNumber3(untruncated.toFixed(otherTokenDecimals, BigNumber3.ROUND_DOWN));
1239
1238
  }
1240
1239
  async sendUserPositionsRequest(endpoint, body) {
1241
1240
  const responseBody = await this.httpClient.sendPostRequest(this.gatewayBaseUrl, this.dexContractBasePath, endpoint, body);
@@ -1351,7 +1350,7 @@ var Quoting = class {
1351
1350
  const tokenInClass = parseTokenClassKey(tokenIn);
1352
1351
  const tokenOutClass = parseTokenClassKey(tokenOut);
1353
1352
  const ordering = getTokenOrdering(tokenInClass, tokenOutClass, false);
1354
- const formattedAmount = isExactInput ? amount.toString() : BigNumber4(amount).multipliedBy(-1).toString();
1353
+ const formattedAmount = isExactInput ? BigNumber4(amount).toFixed() : BigNumber4(amount).multipliedBy(-1).toFixed();
1355
1354
  const response = await this.sendQuoteRequest("/QuoteExactAmount", {
1356
1355
  ...ordering,
1357
1356
  fee,
@@ -1454,9 +1453,9 @@ var Swaps = class {
1454
1453
  }
1455
1454
  const ordering = getTokenOrdering(tokenIn, tokenOut, false);
1456
1455
  const zeroForOne = stringifyTokenClassKey(tokenIn) === stringifyTokenClassKey(ordering.token0);
1457
- const rawAmount = "exactIn" in amount ? amount.exactIn.toString() : BigNumber5(amount.exactOut).multipliedBy(-1).toString();
1458
- const rawAmountOutMinimum = "exactIn" in amount ? ((_b = amount.amountOutMinimum) == null ? void 0 : _b.toString()) ? BigNumber5(amount.amountOutMinimum).multipliedBy(-1).toString() : void 0 : BigNumber5(amount.exactOut ?? 0).multipliedBy(-1).toString();
1459
- const rawAmountInMaximum = "exactIn" in amount ? amount.exactIn.toString() : amount.amountInMaximum ? amount.amountInMaximum.toString() : void 0;
1456
+ const rawAmount = "exactIn" in amount ? BigNumber5(amount.exactIn).toFixed() : BigNumber5(amount.exactOut).multipliedBy(-1).toFixed();
1457
+ const rawAmountOutMinimum = "exactIn" in amount ? ((_b = amount.amountOutMinimum) == null ? void 0 : _b.toString()) ? BigNumber5(amount.amountOutMinimum).multipliedBy(-1).toFixed() : void 0 : BigNumber5(amount.exactOut ?? 0).multipliedBy(-1).toFixed();
1458
+ const rawAmountInMaximum = "exactIn" in amount ? BigNumber5(amount.exactIn).toFixed() : amount.amountInMaximum ? BigNumber5(amount.amountInMaximum).toFixed() : void 0;
1460
1459
  const toSign = {
1461
1460
  token0: parseTokenClassKey(ordering.token0),
1462
1461
  token1: parseTokenClassKey(ordering.token1),
@@ -1742,6 +1741,9 @@ export {
1742
1741
  Swaps,
1743
1742
  TradeEventEmitter,
1744
1743
  compareTokens,
1744
+ getTokenOrdering,
1745
+ parseTokenClassKey,
1746
+ stringifyTokenClassKey,
1745
1747
  validateFee,
1746
1748
  validateNumericAmount,
1747
1749
  validatePriceValues,