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/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.0";
9
9
  var USER_AGENT = `ault-sdk-ts/${SDK_VERSION}`;
10
10
  function isServerRuntime() {
11
11
  if (typeof document !== "undefined") return false;
@@ -39132,6 +39132,45 @@ function entryPrice(netBase, netQuote) {
39132
39132
  return formatDec(divRoundHalfAway(absDec(parseDec(netQuote)), absDec(base)));
39133
39133
  }
39134
39134
 
39135
+ // src/perp/tick.ts
39136
+ function checkPrecision(tickPrecision) {
39137
+ if (!Number.isInteger(tickPrecision) || tickPrecision <= 0) {
39138
+ throw new Error(`tickPrecision must be a positive integer, got ${tickPrecision}`);
39139
+ }
39140
+ }
39141
+ function positive(price) {
39142
+ const scaled = parseDec(price);
39143
+ if (scaled <= 0n) {
39144
+ throw new Error(`price must be positive, got ${price}`);
39145
+ }
39146
+ return scaled;
39147
+ }
39148
+ function step(scaled, tickPrecision) {
39149
+ const exponent = scaled.toString().length - 1 - tickPrecision;
39150
+ return exponent > 0 ? 10n ** BigInt(exponent) : 1n;
39151
+ }
39152
+ function tickSizeAt(price, tickPrecision) {
39153
+ checkPrecision(tickPrecision);
39154
+ return formatDec(step(positive(price), tickPrecision));
39155
+ }
39156
+ function isTickPrice(price, tickPrecision) {
39157
+ checkPrecision(tickPrecision);
39158
+ const scaled = positive(price);
39159
+ return scaled % step(scaled, tickPrecision) === 0n;
39160
+ }
39161
+ function floorTickPrice(price, tickPrecision) {
39162
+ checkPrecision(tickPrecision);
39163
+ const scaled = positive(price);
39164
+ return formatDec(scaled - scaled % step(scaled, tickPrecision));
39165
+ }
39166
+ function ceilTickPrice(price, tickPrecision) {
39167
+ checkPrecision(tickPrecision);
39168
+ const scaled = positive(price);
39169
+ const size = step(scaled, tickPrecision);
39170
+ const remainder = scaled % size;
39171
+ return formatDec(remainder === 0n ? scaled : scaled - remainder + size);
39172
+ }
39173
+
39135
39174
  // src/perp/orders.ts
39136
39175
  function iocLimitPrice(input) {
39137
39176
  const opposite = input.side === "buy" ? input.bestAsk : input.bestBid;
@@ -39139,11 +39178,6 @@ function iocLimitPrice(input) {
39139
39178
  if (reference === void 0 || reference === null || reference === "") {
39140
39179
  throw new Error(`no ${input.side === "buy" ? "ask" : "bid"} price to reference`);
39141
39180
  }
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
39181
  const ref = parseDec(reference);
39148
39182
  if (ref <= 0n) {
39149
39183
  throw new Error(`reference price must be positive, got ${reference}`);
@@ -39157,16 +39191,12 @@ function iocLimitPrice(input) {
39157
39191
  throw new Error(`slippage ${input.slippage} leaves no positive sell price`);
39158
39192
  }
39159
39193
  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");
39194
+ if (raw <= 0n) {
39195
+ throw new Error("IOC price is not positive; lower the slippage");
39168
39196
  }
39169
- return { price: formatDec(rounded), referencePrice: formatDec(ref) };
39197
+ const price = formatDec(raw);
39198
+ const rounded = input.side === "buy" ? ceilTickPrice(price, input.tickPrecision) : floorTickPrice(price, input.tickPrecision);
39199
+ return { price: rounded, referencePrice: formatDec(ref) };
39170
39200
  }
39171
39201
 
39172
39202
  // src/rest/types.ts
@@ -42318,6 +42348,7 @@ export {
42318
42348
  buildSetMarginConfigMsg,
42319
42349
  buildWithdrawMarginMsg,
42320
42350
  bytesToBase64,
42351
+ ceilTickPrice,
42321
42352
  collectPages,
42322
42353
  computeEvmFeesPerGas,
42323
42354
  computeFeeFreeGas,
@@ -42383,6 +42414,7 @@ export {
42383
42414
  fetchManifest,
42384
42415
  fetchProtoJson,
42385
42416
  fetchWithRetry,
42417
+ floorTickPrice,
42386
42418
  formatDec,
42387
42419
  fundingRate,
42388
42420
  getBalanceResponseFreeRegExpOne,
@@ -42469,6 +42501,7 @@ export {
42469
42501
  isAultSigner,
42470
42502
  isMarginAccountAddress,
42471
42503
  isPerpAccountAddress,
42504
+ isTickPrice,
42472
42505
  isValidAultAddress,
42473
42506
  isValidEvmAddress,
42474
42507
  isValidValidatorAddress,
@@ -42639,6 +42672,7 @@ export {
42639
42672
  signAndBroadcastEip712,
42640
42673
  simulateTx,
42641
42674
  stripEip712Domain,
42675
+ tickSizeAt,
42642
42676
  toViemChain,
42643
42677
  tpSlLegs,
42644
42678
  unrealizedPnl,