ault-sdk-ts 0.15.0 → 0.16.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/README.md CHANGED
@@ -367,13 +367,15 @@ an immediate-or-cancel limit priced through the book:
367
367
  ```typescript
368
368
  import { iocLimitPrice } from "ault-sdk-ts";
369
369
 
370
- const book = await client._lowLevel.rest.dex.getPerpOrderbook(marketIdHex, { depth: 5 });
370
+ const dex = client._lowLevel.rest.dex;
371
+ const { data: market } = await dex.getPerpMarket(marketIdHex);
372
+ const book = await dex.getPerpOrderbook(marketIdHex, { depth: 5 });
371
373
  const { price } = iocLimitPrice({
372
374
  side: "buy",
373
375
  bestAsk: book.data.asks[0]?.[0],
374
376
  bestBid: book.data.bids[0]?.[0],
375
377
  slippage: "0.005",
376
- priceDecimals: 2,
378
+ tickPrecision: market.tickPrecision,
377
379
  });
378
380
  await client.placeLimitOrder({
379
381
  marketId,
@@ -386,6 +388,12 @@ await client.placeLimitOrder({
386
388
  });
387
389
  ```
388
390
 
391
+ `tickPrecision` is a count of significant digits. At precision 6 a price has
392
+ at most 7 of them, so the step is 0.01 around 76,000 and 0.1 from 100,000 up.
393
+ Limit prices you build yourself have to sit on the same grid.
394
+ `floorTickPrice`, `ceilTickPrice`, `isTickPrice` and `tickSizeAt` follow the
395
+ chain's rules, on spot markets as well as perpetuals.
396
+
389
397
  Collateral lives in a per-owner cross account in the chain's single
390
398
  collateral denom; isolated markets get their own derived account. Margin mode
391
399
  and leverage are set per market and cannot change while a position or resting
package/dist/index.cjs CHANGED
@@ -299,6 +299,7 @@ __export(index_exports, {
299
299
  buildSetMarginConfigMsg: () => buildSetMarginConfigMsg,
300
300
  buildWithdrawMarginMsg: () => buildWithdrawMarginMsg,
301
301
  bytesToBase64: () => bytesToBase64,
302
+ ceilTickPrice: () => ceilTickPrice,
302
303
  collectPages: () => collectPages,
303
304
  computeEvmFeesPerGas: () => computeEvmFeesPerGas,
304
305
  computeFeeFreeGas: () => computeFeeFreeGas,
@@ -364,6 +365,7 @@ __export(index_exports, {
364
365
  fetchManifest: () => fetchManifest,
365
366
  fetchProtoJson: () => fetchProtoJson,
366
367
  fetchWithRetry: () => fetchWithRetry,
368
+ floorTickPrice: () => floorTickPrice,
367
369
  formatDec: () => formatDec,
368
370
  fundingRate: () => fundingRate,
369
371
  getBalanceResponseFreeRegExpOne: () => getBalanceResponseFreeRegExpOne,
@@ -450,6 +452,7 @@ __export(index_exports, {
450
452
  isAultSigner: () => isAultSigner,
451
453
  isMarginAccountAddress: () => isMarginAccountAddress,
452
454
  isPerpAccountAddress: () => isPerpAccountAddress,
455
+ isTickPrice: () => isTickPrice,
453
456
  isValidAultAddress: () => isValidAultAddress,
454
457
  isValidEvmAddress: () => isValidEvmAddress,
455
458
  isValidValidatorAddress: () => isValidValidatorAddress,
@@ -620,6 +623,7 @@ __export(index_exports, {
620
623
  signAndBroadcastEip712: () => signAndBroadcastEip712,
621
624
  simulateTx: () => simulateTx,
622
625
  stripEip712Domain: () => stripEip712Domain,
626
+ tickSizeAt: () => tickSizeAt,
623
627
  toViemChain: () => toViemChain,
624
628
  tpSlLegs: () => tpSlLegs,
625
629
  unrealizedPnl: () => unrealizedPnl,
@@ -631,7 +635,7 @@ __export(index_exports, {
631
635
  module.exports = __toCommonJS(index_exports);
632
636
 
633
637
  // src/core/user-agent.ts
634
- var SDK_VERSION = "0.15.0";
638
+ var SDK_VERSION = "0.16.0";
635
639
  var USER_AGENT = `ault-sdk-ts/${SDK_VERSION}`;
636
640
  function isServerRuntime() {
637
641
  if (typeof document !== "undefined") return false;
@@ -39758,6 +39762,45 @@ function entryPrice(netBase, netQuote) {
39758
39762
  return formatDec(divRoundHalfAway(absDec(parseDec(netQuote)), absDec(base)));
39759
39763
  }
39760
39764
 
39765
+ // src/perp/tick.ts
39766
+ function checkPrecision(tickPrecision) {
39767
+ if (!Number.isInteger(tickPrecision) || tickPrecision <= 0) {
39768
+ throw new Error(`tickPrecision must be a positive integer, got ${tickPrecision}`);
39769
+ }
39770
+ }
39771
+ function positive(price) {
39772
+ const scaled = parseDec(price);
39773
+ if (scaled <= 0n) {
39774
+ throw new Error(`price must be positive, got ${price}`);
39775
+ }
39776
+ return scaled;
39777
+ }
39778
+ function step(scaled, tickPrecision) {
39779
+ const exponent = scaled.toString().length - 1 - tickPrecision;
39780
+ return exponent > 0 ? 10n ** BigInt(exponent) : 1n;
39781
+ }
39782
+ function tickSizeAt(price, tickPrecision) {
39783
+ checkPrecision(tickPrecision);
39784
+ return formatDec(step(positive(price), tickPrecision));
39785
+ }
39786
+ function isTickPrice(price, tickPrecision) {
39787
+ checkPrecision(tickPrecision);
39788
+ const scaled = positive(price);
39789
+ return scaled % step(scaled, tickPrecision) === 0n;
39790
+ }
39791
+ function floorTickPrice(price, tickPrecision) {
39792
+ checkPrecision(tickPrecision);
39793
+ const scaled = positive(price);
39794
+ return formatDec(scaled - scaled % step(scaled, tickPrecision));
39795
+ }
39796
+ function ceilTickPrice(price, tickPrecision) {
39797
+ checkPrecision(tickPrecision);
39798
+ const scaled = positive(price);
39799
+ const size = step(scaled, tickPrecision);
39800
+ const remainder = scaled % size;
39801
+ return formatDec(remainder === 0n ? scaled : scaled - remainder + size);
39802
+ }
39803
+
39761
39804
  // src/perp/orders.ts
39762
39805
  function iocLimitPrice(input) {
39763
39806
  const opposite = input.side === "buy" ? input.bestAsk : input.bestBid;
@@ -39765,11 +39808,6 @@ function iocLimitPrice(input) {
39765
39808
  if (reference === void 0 || reference === null || reference === "") {
39766
39809
  throw new Error(`no ${input.side === "buy" ? "ask" : "bid"} price to reference`);
39767
39810
  }
39768
- if (!Number.isInteger(input.priceDecimals) || input.priceDecimals < 0 || input.priceDecimals > 18) {
39769
- throw new Error(
39770
- `priceDecimals must be an integer between 0 and 18, got ${input.priceDecimals}`
39771
- );
39772
- }
39773
39811
  const ref = parseDec(reference);
39774
39812
  if (ref <= 0n) {
39775
39813
  throw new Error(`reference price must be positive, got ${reference}`);
@@ -39783,16 +39821,12 @@ function iocLimitPrice(input) {
39783
39821
  throw new Error(`slippage ${input.slippage} leaves no positive sell price`);
39784
39822
  }
39785
39823
  const raw = mulBank(ref, factor);
39786
- const tick = 10n ** BigInt(18 - input.priceDecimals);
39787
- const remainder = raw % tick;
39788
- let rounded = raw - remainder;
39789
- if (remainder !== 0n && input.side === "buy") {
39790
- rounded += tick;
39791
- }
39792
- if (rounded <= 0n) {
39793
- throw new Error("rounded IOC price is not positive; lower the slippage");
39824
+ if (raw <= 0n) {
39825
+ throw new Error("IOC price is not positive; lower the slippage");
39794
39826
  }
39795
- return { price: formatDec(rounded), referencePrice: formatDec(ref) };
39827
+ const price = formatDec(raw);
39828
+ const rounded = input.side === "buy" ? ceilTickPrice(price, input.tickPrecision) : floorTickPrice(price, input.tickPrecision);
39829
+ return { price: rounded, referencePrice: formatDec(ref) };
39796
39830
  }
39797
39831
 
39798
39832
  // src/rest/types.ts
@@ -42945,6 +42979,7 @@ function createDexWs(url, options) {
42945
42979
  buildSetMarginConfigMsg,
42946
42980
  buildWithdrawMarginMsg,
42947
42981
  bytesToBase64,
42982
+ ceilTickPrice,
42948
42983
  collectPages,
42949
42984
  computeEvmFeesPerGas,
42950
42985
  computeFeeFreeGas,
@@ -43010,6 +43045,7 @@ function createDexWs(url, options) {
43010
43045
  fetchManifest,
43011
43046
  fetchProtoJson,
43012
43047
  fetchWithRetry,
43048
+ floorTickPrice,
43013
43049
  formatDec,
43014
43050
  fundingRate,
43015
43051
  getBalanceResponseFreeRegExpOne,
@@ -43096,6 +43132,7 @@ function createDexWs(url, options) {
43096
43132
  isAultSigner,
43097
43133
  isMarginAccountAddress,
43098
43134
  isPerpAccountAddress,
43135
+ isTickPrice,
43099
43136
  isValidAultAddress,
43100
43137
  isValidEvmAddress,
43101
43138
  isValidValidatorAddress,
@@ -43266,6 +43303,7 @@ function createDexWs(url, options) {
43266
43303
  signAndBroadcastEip712,
43267
43304
  simulateTx,
43268
43305
  stripEip712Domain,
43306
+ tickSizeAt,
43269
43307
  toViemChain,
43270
43308
  tpSlLegs,
43271
43309
  unrealizedPnl,