@gala-chain/gswap-sdk 0.0.0-preview → 0.0.1

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.d.cts CHANGED
@@ -908,7 +908,22 @@ declare class GSwapSDKError extends Error {
908
908
  static noPoolAvailableError(tokenIn: GalaChainTokenClassKey | string, tokenOut: GalaChainTokenClassKey | string, fee?: number): GSwapSDKError;
909
909
  }
910
910
 
911
+ declare function stringifyTokenClassKey(tokenClassKey: GalaChainTokenClassKey | string, separator?: string): string;
912
+ declare function parseTokenClassKey(tokenClassKey: string | GalaChainTokenClassKey): GalaChainTokenClassKey;
911
913
  declare function compareTokens(first: GalaChainTokenClassKey | string, second: GalaChainTokenClassKey | string): number;
914
+ declare function getTokenOrdering<TAttributesType = undefined>(first: GalaChainTokenClassKey | string, second: GalaChainTokenClassKey | string, assertCorrectness: boolean, token1Data?: TAttributesType, token2Data?: TAttributesType): {
915
+ token0: string | GalaChainTokenClassKey;
916
+ token1: string | GalaChainTokenClassKey;
917
+ zeroForOne: true;
918
+ token0Attributes: TAttributesType | undefined;
919
+ token1Attributes: TAttributesType | undefined;
920
+ } | {
921
+ token0: string | GalaChainTokenClassKey;
922
+ token1: string | GalaChainTokenClassKey;
923
+ zeroForOne: false;
924
+ token0Attributes: TAttributesType | undefined;
925
+ token1Attributes: TAttributesType | undefined;
926
+ };
912
927
 
913
928
  declare function validateNumericAmount(amount: NumericAmount, parameterName: string, allowZero?: boolean): void;
914
929
  declare function validatePriceValues(spotPrice: NumericAmount, lowerPrice: NumericAmount, upperPrice: NumericAmount): void;
@@ -918,4 +933,4 @@ declare function validateFee(fee: number): void;
918
933
  declare function validateTickSpacing(tickSpacing: number): void;
919
934
  declare function validateWalletAddress(address?: string): asserts address is string;
920
935
 
921
- export { Assets, Bundler, type BundlerRequest, type BundlerResponse, EventSocketClient, Events, FEE_TIER, GSwap, GSwapSDKError, type GalaChainSigner, type GalaChainTokenClassKey, GalaWalletSigner, type GetPoolDataRawResponse, type GetPoolDataResponse, type GetPositionResult, type GetQuoteResult, type GetUserAssetsResult, type GetUserPositionsResult, type NumericAmount, PendingTransaction, Pools, Positions, type Price, type PriceIn, PrivateKeySigner, type QuoteExactAmountRawResponse, type QuoteExactAmountResponse, Quoting, type SqrtPrice, type SqrtPriceIn, Swaps, TradeEventEmitter, type TransactionPendingResponse, type UserAsset, compareTokens, validateFee, validateNumericAmount, validatePriceValues, validateTickRange, validateTickSpacing, validateTokenDecimals, validateWalletAddress };
936
+ export { Assets, Bundler, type BundlerRequest, type BundlerResponse, EventSocketClient, Events, FEE_TIER, GSwap, GSwapSDKError, type GalaChainSigner, type GalaChainTokenClassKey, GalaWalletSigner, type GetPoolDataRawResponse, type GetPoolDataResponse, type GetPositionResult, type GetQuoteResult, type GetUserAssetsResult, type GetUserPositionsResult, type NumericAmount, PendingTransaction, Pools, Positions, type Price, type PriceIn, PrivateKeySigner, type QuoteExactAmountRawResponse, type QuoteExactAmountResponse, Quoting, type SqrtPrice, type SqrtPriceIn, Swaps, TradeEventEmitter, type TransactionPendingResponse, type UserAsset, compareTokens, getTokenOrdering, parseTokenClassKey, stringifyTokenClassKey, validateFee, validateNumericAmount, validatePriceValues, validateTickRange, validateTickSpacing, validateTokenDecimals, validateWalletAddress };
package/dist/index.d.ts CHANGED
@@ -908,7 +908,22 @@ declare class GSwapSDKError extends Error {
908
908
  static noPoolAvailableError(tokenIn: GalaChainTokenClassKey | string, tokenOut: GalaChainTokenClassKey | string, fee?: number): GSwapSDKError;
909
909
  }
910
910
 
911
+ declare function stringifyTokenClassKey(tokenClassKey: GalaChainTokenClassKey | string, separator?: string): string;
912
+ declare function parseTokenClassKey(tokenClassKey: string | GalaChainTokenClassKey): GalaChainTokenClassKey;
911
913
  declare function compareTokens(first: GalaChainTokenClassKey | string, second: GalaChainTokenClassKey | string): number;
914
+ declare function getTokenOrdering<TAttributesType = undefined>(first: GalaChainTokenClassKey | string, second: GalaChainTokenClassKey | string, assertCorrectness: boolean, token1Data?: TAttributesType, token2Data?: TAttributesType): {
915
+ token0: string | GalaChainTokenClassKey;
916
+ token1: string | GalaChainTokenClassKey;
917
+ zeroForOne: true;
918
+ token0Attributes: TAttributesType | undefined;
919
+ token1Attributes: TAttributesType | undefined;
920
+ } | {
921
+ token0: string | GalaChainTokenClassKey;
922
+ token1: string | GalaChainTokenClassKey;
923
+ zeroForOne: false;
924
+ token0Attributes: TAttributesType | undefined;
925
+ token1Attributes: TAttributesType | undefined;
926
+ };
912
927
 
913
928
  declare function validateNumericAmount(amount: NumericAmount, parameterName: string, allowZero?: boolean): void;
914
929
  declare function validatePriceValues(spotPrice: NumericAmount, lowerPrice: NumericAmount, upperPrice: NumericAmount): void;
@@ -918,4 +933,4 @@ declare function validateFee(fee: number): void;
918
933
  declare function validateTickSpacing(tickSpacing: number): void;
919
934
  declare function validateWalletAddress(address?: string): asserts address is string;
920
935
 
921
- export { Assets, Bundler, type BundlerRequest, type BundlerResponse, EventSocketClient, Events, FEE_TIER, GSwap, GSwapSDKError, type GalaChainSigner, type GalaChainTokenClassKey, GalaWalletSigner, type GetPoolDataRawResponse, type GetPoolDataResponse, type GetPositionResult, type GetQuoteResult, type GetUserAssetsResult, type GetUserPositionsResult, type NumericAmount, PendingTransaction, Pools, Positions, type Price, type PriceIn, PrivateKeySigner, type QuoteExactAmountRawResponse, type QuoteExactAmountResponse, Quoting, type SqrtPrice, type SqrtPriceIn, Swaps, TradeEventEmitter, type TransactionPendingResponse, type UserAsset, compareTokens, validateFee, validateNumericAmount, validatePriceValues, validateTickRange, validateTickSpacing, validateTokenDecimals, validateWalletAddress };
936
+ export { Assets, Bundler, type BundlerRequest, type BundlerResponse, EventSocketClient, Events, FEE_TIER, GSwap, GSwapSDKError, type GalaChainSigner, type GalaChainTokenClassKey, GalaWalletSigner, type GetPoolDataRawResponse, type GetPoolDataResponse, type GetPositionResult, type GetQuoteResult, type GetUserAssetsResult, type GetUserPositionsResult, type NumericAmount, PendingTransaction, Pools, Positions, type Price, type PriceIn, PrivateKeySigner, type QuoteExactAmountRawResponse, type QuoteExactAmountResponse, Quoting, type SqrtPrice, type SqrtPriceIn, Swaps, TradeEventEmitter, type TransactionPendingResponse, type UserAsset, compareTokens, getTokenOrdering, parseTokenClassKey, stringifyTokenClassKey, validateFee, validateNumericAmount, validatePriceValues, validateTickRange, validateTickSpacing, validateTokenDecimals, validateWalletAddress };
package/dist/index.js CHANGED
@@ -46,6 +46,9 @@ __export(index_exports, {
46
46
  Swaps: () => Swaps,
47
47
  TradeEventEmitter: () => TradeEventEmitter,
48
48
  compareTokens: () => compareTokens,
49
+ getTokenOrdering: () => getTokenOrdering,
50
+ parseTokenClassKey: () => parseTokenClassKey,
51
+ stringifyTokenClassKey: () => stringifyTokenClassKey,
49
52
  validateFee: () => validateFee,
50
53
  validateNumericAmount: () => validateNumericAmount,
51
54
  validatePriceValues: () => validatePriceValues,
@@ -339,7 +342,7 @@ var import_crypto = __toESM(require("crypto"), 1);
339
342
 
340
343
  // src/utils/debug.ts
341
344
  var import_debug = __toESM(require("debug"), 1);
342
- var debugLog = (0, import_debug.default)("GALASWAP_DEX");
345
+ var debugLog = (0, import_debug.default)("GSWAP_SDK");
343
346
 
344
347
  // src/classes/event_socket_client.ts
345
348
  var import_events = require("events");
@@ -736,8 +739,6 @@ function parseTokenClassKey(tokenClassKey) {
736
739
  additionalKey
737
740
  };
738
741
  }
739
-
740
- // src/utils/token_ordering.ts
741
742
  function compareTokens(first, second) {
742
743
  return stringifyTokenClassKey(first).localeCompare(stringifyTokenClassKey(second));
743
744
  }
@@ -976,7 +977,7 @@ var Positions = class {
976
977
  * ```
977
978
  */
978
979
  async addLiquidityByTicks(args) {
979
- var _a, _b, _c, _d, _e;
980
+ var _a;
980
981
  const walletAddress = args.walletAddress ?? ((_a = this.options) == null ? void 0 : _a.walletAddress);
981
982
  validateWalletAddress(walletAddress);
982
983
  validateFee(args.fee);
@@ -1001,10 +1002,10 @@ var Positions = class {
1001
1002
  owner: args.walletAddress,
1002
1003
  tickLower: args.tickLower,
1003
1004
  tickUpper: args.tickUpper,
1004
- amount0Desired: (_b = ordering == null ? void 0 : ordering.token0Attributes) == null ? void 0 : _b[0],
1005
- amount1Desired: (_c = ordering == null ? void 0 : ordering.token1Attributes) == null ? void 0 : _c[0],
1006
- amount0Min: (_d = ordering == null ? void 0 : ordering.token0Attributes) == null ? void 0 : _d[1],
1007
- amount1Min: (_e = ordering == null ? void 0 : ordering.token1Attributes) == null ? void 0 : _e[1],
1005
+ amount0Desired: (0, import_bignumber3.default)(ordering.token0Attributes[0]).toFixed(),
1006
+ amount1Desired: (0, import_bignumber3.default)(ordering.token1Attributes[0]).toFixed(),
1007
+ amount0Min: (0, import_bignumber3.default)(ordering.token0Attributes[1]).toFixed(),
1008
+ amount1Min: (0, import_bignumber3.default)(ordering.token1Attributes[1]).toFixed(),
1008
1009
  positionId: args.positionId
1009
1010
  };
1010
1011
  const token0StringKey = stringifyTokenClassKey(ordering.token0, "$");
@@ -1179,7 +1180,7 @@ var Positions = class {
1179
1180
  fee: args.fee,
1180
1181
  tickLower: args.tickLower,
1181
1182
  tickUpper: args.tickUpper,
1182
- amount: args.amount.toString(),
1183
+ amount: (0, import_bignumber3.default)(args.amount).toFixed(),
1183
1184
  amount0Min: ((_b = ordering == null ? void 0 : ordering.token0Attributes) == null ? void 0 : _b[0]) || "0",
1184
1185
  amount1Min: ((_c = ordering == null ? void 0 : ordering.token1Attributes) == null ? void 0 : _c[0]) || "0",
1185
1186
  positionId: args.positionId
@@ -1233,7 +1234,7 @@ var Positions = class {
1233
1234
  * ```
1234
1235
  */
1235
1236
  async collectPositionFees(args) {
1236
- var _a, _b, _c;
1237
+ var _a;
1237
1238
  const walletAddress = args.walletAddress ?? ((_a = this.options) == null ? void 0 : _a.walletAddress);
1238
1239
  validateWalletAddress(walletAddress);
1239
1240
  validateFee(args.fee);
@@ -1253,8 +1254,8 @@ var Positions = class {
1253
1254
  token0: ordering.token0,
1254
1255
  token1: ordering.token1,
1255
1256
  fee: args.fee,
1256
- amount0Requested: (_b = ordering == null ? void 0 : ordering.token0Attributes) == null ? void 0 : _b[0],
1257
- amount1Requested: (_c = ordering == null ? void 0 : ordering.token1Attributes) == null ? void 0 : _c[0],
1257
+ amount0Requested: (0, import_bignumber3.default)(ordering.token0Attributes[0]).toFixed(),
1258
+ amount1Requested: (0, import_bignumber3.default)(ordering.token1Attributes[0]).toFixed(),
1258
1259
  tickLower: args.tickLower,
1259
1260
  tickUpper: args.tickUpper,
1260
1261
  positionId: args.positionId
@@ -1293,7 +1294,8 @@ var Positions = class {
1293
1294
  bnUpperPrice = bnUpperPrice.isFinite() ? bnUpperPrice : (0, import_bignumber3.default)(1e18);
1294
1295
  const liquidityAmount = bnTokenAmount.times(10 ** (tokenDecimals - otherTokenDecimals)).times(bnSpotPrice.sqrt()).times(bnUpperPrice.sqrt()).div(bnUpperPrice.sqrt().minus(bnSpotPrice.sqrt()));
1295
1296
  const yAmount = (0, import_bignumber3.default)(liquidityAmount).times(bnSpotPrice.sqrt().minus(bnLowerPrice.sqrt()));
1296
- return yAmount.div((0, import_bignumber3.default)(10).pow(tokenDecimals - otherTokenDecimals));
1297
+ const untruncated = yAmount.div((0, import_bignumber3.default)(10).pow(tokenDecimals - otherTokenDecimals));
1298
+ return (0, import_bignumber3.default)(untruncated.toFixed(otherTokenDecimals, import_bignumber3.default.ROUND_DOWN));
1297
1299
  }
1298
1300
  async sendUserPositionsRequest(endpoint, body) {
1299
1301
  const responseBody = await this.httpClient.sendPostRequest(this.gatewayBaseUrl, this.dexContractBasePath, endpoint, body);
@@ -1409,7 +1411,7 @@ var Quoting = class {
1409
1411
  const tokenInClass = parseTokenClassKey(tokenIn);
1410
1412
  const tokenOutClass = parseTokenClassKey(tokenOut);
1411
1413
  const ordering = getTokenOrdering(tokenInClass, tokenOutClass, false);
1412
- const formattedAmount = isExactInput ? amount.toString() : (0, import_bignumber4.default)(amount).multipliedBy(-1).toString();
1414
+ const formattedAmount = isExactInput ? (0, import_bignumber4.default)(amount).toFixed() : (0, import_bignumber4.default)(amount).multipliedBy(-1).toFixed();
1413
1415
  const response = await this.sendQuoteRequest("/QuoteExactAmount", {
1414
1416
  ...ordering,
1415
1417
  fee,
@@ -1512,9 +1514,9 @@ var Swaps = class {
1512
1514
  }
1513
1515
  const ordering = getTokenOrdering(tokenIn, tokenOut, false);
1514
1516
  const zeroForOne = stringifyTokenClassKey(tokenIn) === stringifyTokenClassKey(ordering.token0);
1515
- const rawAmount = "exactIn" in amount ? amount.exactIn.toString() : (0, import_bignumber5.default)(amount.exactOut).multipliedBy(-1).toString();
1516
- const rawAmountOutMinimum = "exactIn" in amount ? ((_b = amount.amountOutMinimum) == null ? void 0 : _b.toString()) ? (0, import_bignumber5.default)(amount.amountOutMinimum).multipliedBy(-1).toString() : void 0 : (0, import_bignumber5.default)(amount.exactOut ?? 0).multipliedBy(-1).toString();
1517
- const rawAmountInMaximum = "exactIn" in amount ? amount.exactIn.toString() : amount.amountInMaximum ? amount.amountInMaximum.toString() : void 0;
1517
+ const rawAmount = "exactIn" in amount ? (0, import_bignumber5.default)(amount.exactIn).toFixed() : (0, import_bignumber5.default)(amount.exactOut).multipliedBy(-1).toFixed();
1518
+ const rawAmountOutMinimum = "exactIn" in amount ? ((_b = amount.amountOutMinimum) == null ? void 0 : _b.toString()) ? (0, import_bignumber5.default)(amount.amountOutMinimum).multipliedBy(-1).toFixed() : void 0 : (0, import_bignumber5.default)(amount.exactOut ?? 0).multipliedBy(-1).toFixed();
1519
+ const rawAmountInMaximum = "exactIn" in amount ? (0, import_bignumber5.default)(amount.exactIn).toFixed() : amount.amountInMaximum ? (0, import_bignumber5.default)(amount.amountInMaximum).toFixed() : void 0;
1518
1520
  const toSign = {
1519
1521
  token0: parseTokenClassKey(ordering.token0),
1520
1522
  token1: parseTokenClassKey(ordering.token1),
@@ -1655,12 +1657,12 @@ var GSwap = class {
1655
1657
  */
1656
1658
  constructor(options) {
1657
1659
  var _a;
1658
- this.gatewayBaseUrl = ((_a = options == null ? void 0 : options.gatewayBaseUrl) == null ? void 0 : _a.replace(/\/$/, "")) ?? "https://galachain-gateway-chain-platform-stage-chain-platform-eks.stage.galachain.com";
1660
+ this.gatewayBaseUrl = ((_a = options == null ? void 0 : options.gatewayBaseUrl) == null ? void 0 : _a.replace(/\/$/, "")) ?? "https://gateway-mainnet.galachain.com";
1659
1661
  this.dexContractBasePath = (options == null ? void 0 : options.dexContractBasePath) ?? "/api/asset/dexv3-contract";
1660
1662
  this.tokenContractBasePath = (options == null ? void 0 : options.tokenContractBasePath) ?? "/api/asset/token-contract";
1661
- this.bundlerBaseUrl = (options == null ? void 0 : options.bundlerBaseUrl) ?? "https://bundle-backend-test1.defi.gala.com";
1663
+ this.bundlerBaseUrl = (options == null ? void 0 : options.bundlerBaseUrl) ?? "https://bundle-backend-prod1.defi.gala.com";
1662
1664
  this.bundlingAPIBasePath = (options == null ? void 0 : options.bundlingAPIBasePath) ?? "/bundle";
1663
- this.dexBackendBaseUrl = (options == null ? void 0 : options.dexBackendBaseUrl) ?? "https://dex-backend-dev1.defi.gala.com";
1665
+ this.dexBackendBaseUrl = (options == null ? void 0 : options.dexBackendBaseUrl) ?? "https://dex-backend-prod1.defi.gala.com";
1664
1666
  this.signer = options == null ? void 0 : options.signer;
1665
1667
  this.transactionWaitTimeoutMs = (options == null ? void 0 : options.transactionWaitTimeoutMs) ?? 3e5;
1666
1668
  this.httpRequestor = (options == null ? void 0 : options.httpRequestor) ?? fetch.bind(globalThis);
@@ -1801,6 +1803,9 @@ var GalaWalletSigner = class _GalaWalletSigner {
1801
1803
  Swaps,
1802
1804
  TradeEventEmitter,
1803
1805
  compareTokens,
1806
+ getTokenOrdering,
1807
+ parseTokenClassKey,
1808
+ stringifyTokenClassKey,
1804
1809
  validateFee,
1805
1810
  validateNumericAmount,
1806
1811
  validatePriceValues,