ault-sdk-ts 0.15.0 → 0.16.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.js CHANGED
@@ -5,7 +5,7 @@ var __export = (target, all) => {
5
5
  };
6
6
 
7
7
  // src/core/user-agent.ts
8
- var SDK_VERSION = "0.15.0";
8
+ var SDK_VERSION = "0.16.1";
9
9
  var USER_AGENT = `ault-sdk-ts/${SDK_VERSION}`;
10
10
  function isServerRuntime() {
11
11
  if (typeof document !== "undefined") return false;
@@ -21590,6 +21590,14 @@ function compareBytes(a, b) {
21590
21590
  return a.length - b.length;
21591
21591
  }
21592
21592
 
21593
+ // src/rest/market-id.ts
21594
+ var MARKET_ID_HEX_RE = /^(0[xX])?([0-9a-fA-F]{2})+$/;
21595
+ function marketIdToBase64(marketId) {
21596
+ if (marketId instanceof MarketId) return marketId.toBase64();
21597
+ if (typeof marketId !== "string") return bytesToBase64(marketId);
21598
+ return MARKET_ID_HEX_RE.test(marketId) ? MarketId.fromHex(marketId).toBase64() : marketId;
21599
+ }
21600
+
21593
21601
  // src/proto/gen/ault/clob/v1/query.ts
21594
21602
  import { BinaryReader as BinaryReader45, BinaryWriter as BinaryWriter45 } from "@bufbuild/protobuf/wire";
21595
21603
 
@@ -22580,9 +22588,6 @@ function normalizeOrderId(orderId) {
22580
22588
  if (typeof orderId !== "string") return bytesToBase64(orderId);
22581
22589
  return ORDER_ID_HEX_RE.test(orderId) ? OrderId.fromHex(orderId).toBase64() : orderId;
22582
22590
  }
22583
- function normalizeMarketId(marketId) {
22584
- return typeof marketId === "string" ? marketId : bytesToBase64(marketId);
22585
- }
22586
22591
  var LIMIT_TYPE_URL = "/ault.clob.v1.MsgPlaceLimitOrder";
22587
22592
  var MARKET_TYPE_URL = "/ault.clob.v1.MsgPlaceMarketOrder";
22588
22593
  var OPTION_CODECS = {
@@ -22674,7 +22679,7 @@ function createClobApi(context) {
22674
22679
  },
22675
22680
  async getOrders(params = {}) {
22676
22681
  const query = buildQuery({
22677
- market_id: params.marketId ? normalizeMarketId(params.marketId) : void 0,
22682
+ market_id: params.marketId ? marketIdToBase64(params.marketId) : void 0,
22678
22683
  ...params.pagination
22679
22684
  });
22680
22685
  return fetchProtoJson(
@@ -25101,10 +25106,6 @@ function isSet46(value) {
25101
25106
  }
25102
25107
 
25103
25108
  // src/rest/margin.ts
25104
- function marketIdParam(marketId) {
25105
- if (marketId instanceof MarketId) return marketId.toBase64();
25106
- return typeof marketId === "string" ? marketId : bytesToBase64(marketId);
25107
- }
25108
25109
  var enc2 = encodeURIComponent;
25109
25110
  function createMarginApi(context) {
25110
25111
  return {
@@ -25121,7 +25122,7 @@ function createMarginApi(context) {
25121
25122
  },
25122
25123
  async getMarginAccount(owner, marketId) {
25123
25124
  const query = buildQuery({
25124
- market_id: marketId === void 0 ? void 0 : marketIdParam(marketId)
25125
+ market_id: marketId === void 0 ? void 0 : marketIdToBase64(marketId)
25125
25126
  });
25126
25127
  return fetchProtoJson(
25127
25128
  context,
@@ -25511,9 +25512,6 @@ function isSet48(value) {
25511
25512
  }
25512
25513
 
25513
25514
  // src/rest/market.ts
25514
- function normalizeMarketId2(marketId) {
25515
- return typeof marketId === "string" ? marketId : bytesToBase64(marketId);
25516
- }
25517
25515
  function createMarketApi(context) {
25518
25516
  return {
25519
25517
  async getParams() {
@@ -25526,7 +25524,7 @@ function createMarketApi(context) {
25526
25524
  async getMarket(marketId) {
25527
25525
  return fetchProtoJson(
25528
25526
  context,
25529
- `/ault/market/v1/markets/${encodeURIComponent(normalizeMarketId2(marketId))}`,
25527
+ `/ault/market/v1/markets/${encodeURIComponent(marketIdToBase64(marketId))}`,
25530
25528
  QueryMarketResponse
25531
25529
  );
25532
25530
  }
@@ -28741,10 +28739,6 @@ function isSet53(value) {
28741
28739
  }
28742
28740
 
28743
28741
  // src/rest/perpetual.ts
28744
- function normalizeMarketId3(marketId) {
28745
- if (marketId instanceof MarketId) return marketId.toBase64();
28746
- return typeof marketId === "string" ? marketId : bytesToBase64(marketId);
28747
- }
28748
28742
  function createPerpetualApi(context) {
28749
28743
  return {
28750
28744
  async getParams() {
@@ -28759,7 +28753,7 @@ function createPerpetualApi(context) {
28759
28753
  },
28760
28754
  async getAccount(owner, marketId) {
28761
28755
  const query = buildQuery({
28762
- market_id: marketId === void 0 ? void 0 : normalizeMarketId3(marketId)
28756
+ market_id: marketId === void 0 ? void 0 : marketIdToBase64(marketId)
28763
28757
  });
28764
28758
  return fetchProtoJson(
28765
28759
  context,
@@ -28768,7 +28762,7 @@ function createPerpetualApi(context) {
28768
28762
  );
28769
28763
  },
28770
28764
  async getPosition(owner, marketId, cross) {
28771
- const query = buildQuery({ market_id: normalizeMarketId3(marketId), cross });
28765
+ const query = buildQuery({ market_id: marketIdToBase64(marketId), cross });
28772
28766
  return fetchProtoJson(
28773
28767
  context,
28774
28768
  `/ault/perpetual/v1/position/${encodeURIComponent(normalizeAddress(owner))}${query}`,
@@ -28777,7 +28771,7 @@ function createPerpetualApi(context) {
28777
28771
  },
28778
28772
  async getAccountRisk(owner, marketId) {
28779
28773
  const query = buildQuery({
28780
- market_id: marketId === void 0 ? void 0 : normalizeMarketId3(marketId)
28774
+ market_id: marketId === void 0 ? void 0 : marketIdToBase64(marketId)
28781
28775
  });
28782
28776
  return fetchProtoJson(
28783
28777
  context,
@@ -28786,11 +28780,11 @@ function createPerpetualApi(context) {
28786
28780
  );
28787
28781
  },
28788
28782
  async getFunding(marketId) {
28789
- const query = buildQuery({ market_id: normalizeMarketId3(marketId) });
28783
+ const query = buildQuery({ market_id: marketIdToBase64(marketId) });
28790
28784
  return fetchProtoJson(context, `/ault/perpetual/v1/funding${query}`, QueryFundingResponse);
28791
28785
  },
28792
28786
  async getPrices(marketId) {
28793
- const id = encodeURIComponent(normalizeMarketId3(marketId));
28787
+ const id = encodeURIComponent(marketIdToBase64(marketId));
28794
28788
  return fetchProtoJson(
28795
28789
  context,
28796
28790
  `/ault/perpetual/v1/markets/${id}/prices`,
@@ -28798,7 +28792,7 @@ function createPerpetualApi(context) {
28798
28792
  );
28799
28793
  },
28800
28794
  async getImpactPrices(marketId) {
28801
- const id = encodeURIComponent(normalizeMarketId3(marketId));
28795
+ const id = encodeURIComponent(marketIdToBase64(marketId));
28802
28796
  return fetchProtoJson(
28803
28797
  context,
28804
28798
  `/ault/perpetual/v1/markets/${id}/impact_prices`,
@@ -29532,7 +29526,7 @@ function createRewardApi(context) {
29532
29526
  );
29533
29527
  },
29534
29528
  async getDeployerShare(marketId) {
29535
- const encoded = typeof marketId === "string" ? marketId : bytesToBase64(marketId);
29529
+ const encoded = marketIdToBase64(marketId);
29536
29530
  return fetchProtoJson(
29537
29531
  context,
29538
29532
  `/ault/reward/v1/deployer_share/${encodeURIComponent(encoded)}`,
@@ -39132,6 +39126,45 @@ function entryPrice(netBase, netQuote) {
39132
39126
  return formatDec(divRoundHalfAway(absDec(parseDec(netQuote)), absDec(base)));
39133
39127
  }
39134
39128
 
39129
+ // src/perp/tick.ts
39130
+ function checkPrecision(tickPrecision) {
39131
+ if (!Number.isInteger(tickPrecision) || tickPrecision <= 0) {
39132
+ throw new Error(`tickPrecision must be a positive integer, got ${tickPrecision}`);
39133
+ }
39134
+ }
39135
+ function positive(price) {
39136
+ const scaled = parseDec(price);
39137
+ if (scaled <= 0n) {
39138
+ throw new Error(`price must be positive, got ${price}`);
39139
+ }
39140
+ return scaled;
39141
+ }
39142
+ function step(scaled, tickPrecision) {
39143
+ const exponent = scaled.toString().length - 1 - tickPrecision;
39144
+ return exponent > 0 ? 10n ** BigInt(exponent) : 1n;
39145
+ }
39146
+ function tickSizeAt(price, tickPrecision) {
39147
+ checkPrecision(tickPrecision);
39148
+ return formatDec(step(positive(price), tickPrecision));
39149
+ }
39150
+ function isTickPrice(price, tickPrecision) {
39151
+ checkPrecision(tickPrecision);
39152
+ const scaled = positive(price);
39153
+ return scaled % step(scaled, tickPrecision) === 0n;
39154
+ }
39155
+ function floorTickPrice(price, tickPrecision) {
39156
+ checkPrecision(tickPrecision);
39157
+ const scaled = positive(price);
39158
+ return formatDec(scaled - scaled % step(scaled, tickPrecision));
39159
+ }
39160
+ function ceilTickPrice(price, tickPrecision) {
39161
+ checkPrecision(tickPrecision);
39162
+ const scaled = positive(price);
39163
+ const size = step(scaled, tickPrecision);
39164
+ const remainder = scaled % size;
39165
+ return formatDec(remainder === 0n ? scaled : scaled - remainder + size);
39166
+ }
39167
+
39135
39168
  // src/perp/orders.ts
39136
39169
  function iocLimitPrice(input) {
39137
39170
  const opposite = input.side === "buy" ? input.bestAsk : input.bestBid;
@@ -39139,11 +39172,6 @@ function iocLimitPrice(input) {
39139
39172
  if (reference === void 0 || reference === null || reference === "") {
39140
39173
  throw new Error(`no ${input.side === "buy" ? "ask" : "bid"} price to reference`);
39141
39174
  }
39142
- if (!Number.isInteger(input.priceDecimals) || input.priceDecimals < 0 || input.priceDecimals > 18) {
39143
- throw new Error(
39144
- `priceDecimals must be an integer between 0 and 18, got ${input.priceDecimals}`
39145
- );
39146
- }
39147
39175
  const ref = parseDec(reference);
39148
39176
  if (ref <= 0n) {
39149
39177
  throw new Error(`reference price must be positive, got ${reference}`);
@@ -39157,16 +39185,12 @@ function iocLimitPrice(input) {
39157
39185
  throw new Error(`slippage ${input.slippage} leaves no positive sell price`);
39158
39186
  }
39159
39187
  const raw = mulBank(ref, factor);
39160
- const tick = 10n ** BigInt(18 - input.priceDecimals);
39161
- const remainder = raw % tick;
39162
- let rounded = raw - remainder;
39163
- if (remainder !== 0n && input.side === "buy") {
39164
- rounded += tick;
39165
- }
39166
- if (rounded <= 0n) {
39167
- throw new Error("rounded IOC price is not positive; lower the slippage");
39188
+ if (raw <= 0n) {
39189
+ throw new Error("IOC price is not positive; lower the slippage");
39168
39190
  }
39169
- return { price: formatDec(rounded), referencePrice: formatDec(ref) };
39191
+ const price = formatDec(raw);
39192
+ const rounded = input.side === "buy" ? ceilTickPrice(price, input.tickPrecision) : floorTickPrice(price, input.tickPrecision);
39193
+ return { price: rounded, referencePrice: formatDec(ref) };
39170
39194
  }
39171
39195
 
39172
39196
  // src/rest/types.ts
@@ -42318,6 +42342,7 @@ export {
42318
42342
  buildSetMarginConfigMsg,
42319
42343
  buildWithdrawMarginMsg,
42320
42344
  bytesToBase64,
42345
+ ceilTickPrice,
42321
42346
  collectPages,
42322
42347
  computeEvmFeesPerGas,
42323
42348
  computeFeeFreeGas,
@@ -42383,6 +42408,7 @@ export {
42383
42408
  fetchManifest,
42384
42409
  fetchProtoJson,
42385
42410
  fetchWithRetry,
42411
+ floorTickPrice,
42386
42412
  formatDec,
42387
42413
  fundingRate,
42388
42414
  getBalanceResponseFreeRegExpOne,
@@ -42469,6 +42495,7 @@ export {
42469
42495
  isAultSigner,
42470
42496
  isMarginAccountAddress,
42471
42497
  isPerpAccountAddress,
42498
+ isTickPrice,
42472
42499
  isValidAultAddress,
42473
42500
  isValidEvmAddress,
42474
42501
  isValidValidatorAddress,
@@ -42639,6 +42666,7 @@ export {
42639
42666
  signAndBroadcastEip712,
42640
42667
  simulateTx,
42641
42668
  stripEip712Domain,
42669
+ tickSizeAt,
42642
42670
  toViemChain,
42643
42671
  tpSlLegs,
42644
42672
  unrealizedPnl,