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/README.md CHANGED
@@ -326,10 +326,11 @@ const operators = await client.miner.getOperators();
326
326
  const delegation = await client.miner.getLicenseDelegation("123");
327
327
  const emission = await client.miner.getEmissionInfo();
328
328
 
329
- // Market and CLOB queries
329
+ // Market and CLOB queries. A market id can be bytes, a MarketId, or a hex
330
+ // (as the dex-api returns it, with or without 0x) or base64 string.
330
331
  const markets = await client.market.getMarkets();
331
- const market = await client.market.getMarket(1);
332
- const orders = await client.clob.getOrders({ orderer: client.address, marketId: 1 });
332
+ const market = await client.market.getMarket(marketIdHex);
333
+ const orders = await client.clob.getOrders({ marketId: marketIdHex });
333
334
 
334
335
  // Reward queries
335
336
  const rewardParams = await client.reward.getParams();
@@ -365,37 +366,48 @@ collateral denom. The chain accepts limit orders only, so a "market order" is
365
366
  an immediate-or-cancel limit priced through the book:
366
367
 
367
368
  ```typescript
369
+ import { parseUnits } from "viem";
368
370
  import { iocLimitPrice } from "ault-sdk-ts";
369
371
 
370
- const book = await client._lowLevel.rest.dex.getPerpOrderbook(marketIdHex, { depth: 5 });
372
+ const dex = client._lowLevel.rest.dex;
373
+ const { data: market } = await dex.getPerpMarket(marketIdHex);
374
+ const book = await dex.getPerpOrderbook(marketIdHex, { depth: 5 });
371
375
  const { price } = iocLimitPrice({
372
376
  side: "buy",
373
377
  bestAsk: book.data.asks[0]?.[0],
374
378
  bestBid: book.data.bids[0]?.[0],
375
379
  slippage: "0.005",
376
- priceDecimals: 2,
380
+ tickPrecision: market.tickPrecision,
377
381
  });
378
382
  await client.placeLimitOrder({
379
383
  marketId,
380
384
  isBuy: true,
381
385
  price,
382
- quantity: "1",
386
+ quantity: parseUnits("0.01", 18).toString(), // 0.01 BTC
383
387
  deadline: new Date(Date.now() + 60_000),
384
388
  timeInForce: "ioc",
385
389
  reduceOnly: false,
386
390
  });
387
391
  ```
388
392
 
393
+ `tickPrecision` is a count of significant digits. At precision 6 a price has
394
+ at most 7 of them, so the step is 0.01 around 76,000 and 0.1 from 100,000 up.
395
+ Limit prices you build yourself have to sit on the same grid.
396
+ `floorTickPrice`, `ceilTickPrice`, `isTickPrice` and `tickSizeAt` follow the
397
+ chain's rules, on spot markets as well as perpetuals.
398
+
389
399
  Collateral lives in a per-owner cross account in the chain's single
390
400
  collateral denom; isolated markets get their own derived account. Margin mode
391
401
  and leverage are set per market and cannot change while a position or resting
392
402
  order exists:
393
403
 
394
404
  ```typescript
395
- await client.depositPerpCollateral({ amount: "1000000000" }); // base units
405
+ // Base units with 18 decimals, like every bank denom.
406
+ await client.depositPerpCollateral({ amount: parseUnits("1000", 18).toString() });
396
407
  await client.setMarginConfig({ marketId, leverage: 10, cross: true });
397
- await client.modifyPositionMargin({ marketId, marginDelta: "-500000" }); // isolated only
398
- await client.withdrawPerpCollateral({ amount: "250000000" });
408
+ // Isolated only.
409
+ await client.modifyPositionMargin({ marketId, marginDelta: parseUnits("-50", 18).toString() });
410
+ await client.withdrawPerpCollateral({ amount: parseUnits("250", 18).toString() });
399
411
  ```
400
412
 
401
413
  A perpetual TWAP (`placeTwapOrder` with `reduceOnly`) is sized in base and
@@ -423,8 +435,9 @@ move the signer's own funds, so they are wallet-signed only (never by an
423
435
  agent).
424
436
 
425
437
  ```typescript
426
- const usdc = { denom: "erc20:0xd157...", amount: "1000000000" }; // base units
427
- const weth = { denom: "erc20:0xcC4a...", amount: "500000000000000000" };
438
+ // Bank denoms have 18 decimals, so 1000 USDC is 1000 * 10^18 base units.
439
+ const usdc = { denom: "erc20:0xd157...", amount: "1000000000000000000000" };
440
+ const weth = { denom: "erc20:0xcC4a...", amount: "500000000000000000" }; // 0.5 WETH
428
441
 
429
442
  await client.lendingSupply({ poolId: 1, coin: usdc }); // earns the supply rate
430
443
  await client.lendingSupplyCollateral({ poolId: 1, coin: weth }); // backs borrows, earns nothing
@@ -462,6 +475,7 @@ account per market, both derived from the owner's address, and their
462
475
  collateral and debt live in the margin Lending pool.
463
476
 
464
477
  ```typescript
478
+ import { parseUnits } from "viem";
465
479
  import { marginAccountAddress } from "ault-sdk-ts";
466
480
 
467
481
  // Fund the isolated account of a market (omit marketId for the cross account).
@@ -473,7 +487,7 @@ await client.placeLimitOrder({
473
487
  marketId,
474
488
  isBuy: true,
475
489
  price: "3500",
476
- quantity: "0.5",
490
+ quantity: parseUnits("0.5", 18).toString(),
477
491
  deadline: new Date(Date.now() + 3_600_000),
478
492
  margin: { autoBorrow: true },
479
493
  });
@@ -484,7 +498,7 @@ await client.placeLimitOrder({
484
498
  marketId,
485
499
  isBuy: false,
486
500
  price: "3600",
487
- quantity: "0.5",
501
+ quantity: parseUnits("0.5", 18).toString(),
488
502
  deadline: new Date(Date.now() + 3_600_000),
489
503
  margin: { autoRepay: true },
490
504
  });
@@ -598,6 +612,8 @@ of vault:
598
612
  Parent vaults belong to x/gov, so only a governance proposal can create one.
599
613
 
600
614
  ```typescript
615
+ import { parseUnits } from "viem";
616
+
601
617
  const lendingVault = client.attachVaultManager({ vaultAddress, agentPrivateKey: managerKey });
602
618
  await lendingVault.reallocateVault({ sourcePoolId: 1, destinationPoolId: 2, amount: usdc });
603
619
 
@@ -608,7 +624,13 @@ const parent = client.attachVaultManager({
608
624
  });
609
625
  await parent.transferChildVault({ childVault, amount: usdc, isDeposit: true });
610
626
  const child = client.attachVaultManager({ vaultAddress: childVault, agentPrivateKey: managerKey });
611
- await child.placeLimitOrder({ marketId, isBuy: true, price: "3500", quantity: "1", deadline });
627
+ await child.placeLimitOrder({
628
+ marketId,
629
+ isBuy: true,
630
+ price: "3500",
631
+ quantity: parseUnits("1", 18).toString(),
632
+ deadline,
633
+ });
612
634
  ```
613
635
 
614
636
  Status changes and config updates come from the vault's owner, not its
@@ -1076,18 +1098,32 @@ await client.updateOperatorInfo({
1076
1098
 
1077
1099
  ### Market And CLOB Transactions
1078
1100
 
1101
+ Order amounts are integers in base units. Every bank denom has 18 decimals on
1102
+ the chain, including tokens bridged from 6-decimal ERC20s, so `quantity` and a
1103
+ market order's `deposit` are the token amount times 10^18. `price` is a plain
1104
+ decimal of quote per base. A market order's `deposit` is quote on a buy and
1105
+ base on a sell. The chain rejects an order whose quote notional is below a
1106
+ minimum. On chain v3 that is `min_order_quote_amount` from
1107
+ `client.spot.getParams()` for spot orders and `client.perpetual.getParams()`
1108
+ for perpetual orders. On a chain before v3 (mainnet today) it is in
1109
+ `client.clob.getParams()`. It is currently `10000000000000000000`, or 10 quote
1110
+ tokens, and can change.
1111
+
1079
1112
  ```typescript
1113
+ import { parseUnits } from "viem";
1080
1114
  import { base64ToBytes } from "ault-sdk-ts";
1081
1115
 
1082
1116
  const marketId = base64ToBytes("base64MarketId...");
1117
+ const units = (amount: string) => parseUnits(amount, 18).toString();
1083
1118
 
1084
1119
  // Place a limit order (broadcast-only: returns once CheckTx accepts it).
1120
+ // 100 base at 1.5 is a notional of 150 quote.
1085
1121
  await client.placeLimitOrder({
1086
1122
  marketId,
1087
1123
  isBuy: true,
1088
1124
  price: "1.5",
1089
- quantity: "100",
1090
- lifespan: { seconds: 3600n, nanos: 0 }, // 1 hour
1125
+ quantity: units("100"),
1126
+ deadline: new Date(Date.now() + 3_600_000), // 1 hour
1091
1127
  });
1092
1128
 
1093
1129
  // Pass `wait: true` to poll for DeliverTx and read back the order ID.
@@ -1095,17 +1131,17 @@ const placed = await client.placeLimitOrder({
1095
1131
  marketId,
1096
1132
  isBuy: true,
1097
1133
  price: "1.5",
1098
- quantity: "100",
1099
- lifespan: { seconds: 3600n, nanos: 0 },
1134
+ quantity: units("100"),
1135
+ deadline: new Date(Date.now() + 3_600_000),
1100
1136
  wait: true,
1101
1137
  });
1102
1138
  console.log(placed.orderId);
1103
1139
 
1104
- // Place a market order
1140
+ // Place a market order: buy with 100 quote.
1105
1141
  await client.placeMarketOrder({
1106
1142
  marketId,
1107
1143
  isBuy: true,
1108
- deposit: "100",
1144
+ deposit: units("100"),
1109
1145
  });
1110
1146
 
1111
1147
  // Cancel specific orders. With `wait: true` the result lists which IDs
@@ -1121,7 +1157,7 @@ const withCloid = await client.placeLimitOrder({
1121
1157
  marketId,
1122
1158
  isBuy: true,
1123
1159
  price: "1.5",
1124
- quantity: "100",
1160
+ quantity: units("100"),
1125
1161
  deadline: new Date(Date.now() + 3600_000),
1126
1162
  cloid,
1127
1163
  wait: true,
@@ -1239,7 +1275,7 @@ const placed = await client.asAgent!.placeLimitOrder({
1239
1275
  isBuy: true,
1240
1276
  price: "1.0",
1241
1277
  quantity: "1000000000000000000",
1242
- lifespan: { seconds: 3600n, nanos: 0 },
1278
+ deadline: new Date(Date.now() + 3_600_000),
1243
1279
  wait: true,
1244
1280
  });
1245
1281
  console.log(placed.orderId);
@@ -1259,7 +1295,7 @@ await client.asAgent!.placeScaleOrder({
1259
1295
  highPrice: "1.1",
1260
1296
  totalQuantity: "10000000000000000000",
1261
1297
  weights: [3333, 3334, 3333],
1262
- lifespan: { seconds: 3600n, nanos: 0 },
1298
+ deadline: new Date(Date.now() + 3_600_000),
1263
1299
  });
1264
1300
  ```
1265
1301
 
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.1";
635
639
  var USER_AGENT = `ault-sdk-ts/${SDK_VERSION}`;
636
640
  function isServerRuntime() {
637
641
  if (typeof document !== "undefined") return false;
@@ -22216,6 +22220,14 @@ function compareBytes(a, b) {
22216
22220
  return a.length - b.length;
22217
22221
  }
22218
22222
 
22223
+ // src/rest/market-id.ts
22224
+ var MARKET_ID_HEX_RE = /^(0[xX])?([0-9a-fA-F]{2})+$/;
22225
+ function marketIdToBase64(marketId) {
22226
+ if (marketId instanceof MarketId) return marketId.toBase64();
22227
+ if (typeof marketId !== "string") return bytesToBase64(marketId);
22228
+ return MARKET_ID_HEX_RE.test(marketId) ? MarketId.fromHex(marketId).toBase64() : marketId;
22229
+ }
22230
+
22219
22231
  // src/proto/gen/ault/clob/v1/query.ts
22220
22232
  var import_wire45 = require("@bufbuild/protobuf/wire");
22221
22233
 
@@ -23206,9 +23218,6 @@ function normalizeOrderId(orderId) {
23206
23218
  if (typeof orderId !== "string") return bytesToBase64(orderId);
23207
23219
  return ORDER_ID_HEX_RE.test(orderId) ? OrderId.fromHex(orderId).toBase64() : orderId;
23208
23220
  }
23209
- function normalizeMarketId(marketId) {
23210
- return typeof marketId === "string" ? marketId : bytesToBase64(marketId);
23211
- }
23212
23221
  var LIMIT_TYPE_URL = "/ault.clob.v1.MsgPlaceLimitOrder";
23213
23222
  var MARKET_TYPE_URL = "/ault.clob.v1.MsgPlaceMarketOrder";
23214
23223
  var OPTION_CODECS = {
@@ -23300,7 +23309,7 @@ function createClobApi(context) {
23300
23309
  },
23301
23310
  async getOrders(params = {}) {
23302
23311
  const query = buildQuery({
23303
- market_id: params.marketId ? normalizeMarketId(params.marketId) : void 0,
23312
+ market_id: params.marketId ? marketIdToBase64(params.marketId) : void 0,
23304
23313
  ...params.pagination
23305
23314
  });
23306
23315
  return fetchProtoJson(
@@ -25727,10 +25736,6 @@ function isSet46(value) {
25727
25736
  }
25728
25737
 
25729
25738
  // src/rest/margin.ts
25730
- function marketIdParam(marketId) {
25731
- if (marketId instanceof MarketId) return marketId.toBase64();
25732
- return typeof marketId === "string" ? marketId : bytesToBase64(marketId);
25733
- }
25734
25739
  var enc2 = encodeURIComponent;
25735
25740
  function createMarginApi(context) {
25736
25741
  return {
@@ -25747,7 +25752,7 @@ function createMarginApi(context) {
25747
25752
  },
25748
25753
  async getMarginAccount(owner, marketId) {
25749
25754
  const query = buildQuery({
25750
- market_id: marketId === void 0 ? void 0 : marketIdParam(marketId)
25755
+ market_id: marketId === void 0 ? void 0 : marketIdToBase64(marketId)
25751
25756
  });
25752
25757
  return fetchProtoJson(
25753
25758
  context,
@@ -26137,9 +26142,6 @@ function isSet48(value) {
26137
26142
  }
26138
26143
 
26139
26144
  // src/rest/market.ts
26140
- function normalizeMarketId2(marketId) {
26141
- return typeof marketId === "string" ? marketId : bytesToBase64(marketId);
26142
- }
26143
26145
  function createMarketApi(context) {
26144
26146
  return {
26145
26147
  async getParams() {
@@ -26152,7 +26154,7 @@ function createMarketApi(context) {
26152
26154
  async getMarket(marketId) {
26153
26155
  return fetchProtoJson(
26154
26156
  context,
26155
- `/ault/market/v1/markets/${encodeURIComponent(normalizeMarketId2(marketId))}`,
26157
+ `/ault/market/v1/markets/${encodeURIComponent(marketIdToBase64(marketId))}`,
26156
26158
  QueryMarketResponse
26157
26159
  );
26158
26160
  }
@@ -29367,10 +29369,6 @@ function isSet53(value) {
29367
29369
  }
29368
29370
 
29369
29371
  // src/rest/perpetual.ts
29370
- function normalizeMarketId3(marketId) {
29371
- if (marketId instanceof MarketId) return marketId.toBase64();
29372
- return typeof marketId === "string" ? marketId : bytesToBase64(marketId);
29373
- }
29374
29372
  function createPerpetualApi(context) {
29375
29373
  return {
29376
29374
  async getParams() {
@@ -29385,7 +29383,7 @@ function createPerpetualApi(context) {
29385
29383
  },
29386
29384
  async getAccount(owner, marketId) {
29387
29385
  const query = buildQuery({
29388
- market_id: marketId === void 0 ? void 0 : normalizeMarketId3(marketId)
29386
+ market_id: marketId === void 0 ? void 0 : marketIdToBase64(marketId)
29389
29387
  });
29390
29388
  return fetchProtoJson(
29391
29389
  context,
@@ -29394,7 +29392,7 @@ function createPerpetualApi(context) {
29394
29392
  );
29395
29393
  },
29396
29394
  async getPosition(owner, marketId, cross) {
29397
- const query = buildQuery({ market_id: normalizeMarketId3(marketId), cross });
29395
+ const query = buildQuery({ market_id: marketIdToBase64(marketId), cross });
29398
29396
  return fetchProtoJson(
29399
29397
  context,
29400
29398
  `/ault/perpetual/v1/position/${encodeURIComponent(normalizeAddress(owner))}${query}`,
@@ -29403,7 +29401,7 @@ function createPerpetualApi(context) {
29403
29401
  },
29404
29402
  async getAccountRisk(owner, marketId) {
29405
29403
  const query = buildQuery({
29406
- market_id: marketId === void 0 ? void 0 : normalizeMarketId3(marketId)
29404
+ market_id: marketId === void 0 ? void 0 : marketIdToBase64(marketId)
29407
29405
  });
29408
29406
  return fetchProtoJson(
29409
29407
  context,
@@ -29412,11 +29410,11 @@ function createPerpetualApi(context) {
29412
29410
  );
29413
29411
  },
29414
29412
  async getFunding(marketId) {
29415
- const query = buildQuery({ market_id: normalizeMarketId3(marketId) });
29413
+ const query = buildQuery({ market_id: marketIdToBase64(marketId) });
29416
29414
  return fetchProtoJson(context, `/ault/perpetual/v1/funding${query}`, QueryFundingResponse);
29417
29415
  },
29418
29416
  async getPrices(marketId) {
29419
- const id = encodeURIComponent(normalizeMarketId3(marketId));
29417
+ const id = encodeURIComponent(marketIdToBase64(marketId));
29420
29418
  return fetchProtoJson(
29421
29419
  context,
29422
29420
  `/ault/perpetual/v1/markets/${id}/prices`,
@@ -29424,7 +29422,7 @@ function createPerpetualApi(context) {
29424
29422
  );
29425
29423
  },
29426
29424
  async getImpactPrices(marketId) {
29427
- const id = encodeURIComponent(normalizeMarketId3(marketId));
29425
+ const id = encodeURIComponent(marketIdToBase64(marketId));
29428
29426
  return fetchProtoJson(
29429
29427
  context,
29430
29428
  `/ault/perpetual/v1/markets/${id}/impact_prices`,
@@ -30158,7 +30156,7 @@ function createRewardApi(context) {
30158
30156
  );
30159
30157
  },
30160
30158
  async getDeployerShare(marketId) {
30161
- const encoded = typeof marketId === "string" ? marketId : bytesToBase64(marketId);
30159
+ const encoded = marketIdToBase64(marketId);
30162
30160
  return fetchProtoJson(
30163
30161
  context,
30164
30162
  `/ault/reward/v1/deployer_share/${encodeURIComponent(encoded)}`,
@@ -39758,6 +39756,45 @@ function entryPrice(netBase, netQuote) {
39758
39756
  return formatDec(divRoundHalfAway(absDec(parseDec(netQuote)), absDec(base)));
39759
39757
  }
39760
39758
 
39759
+ // src/perp/tick.ts
39760
+ function checkPrecision(tickPrecision) {
39761
+ if (!Number.isInteger(tickPrecision) || tickPrecision <= 0) {
39762
+ throw new Error(`tickPrecision must be a positive integer, got ${tickPrecision}`);
39763
+ }
39764
+ }
39765
+ function positive(price) {
39766
+ const scaled = parseDec(price);
39767
+ if (scaled <= 0n) {
39768
+ throw new Error(`price must be positive, got ${price}`);
39769
+ }
39770
+ return scaled;
39771
+ }
39772
+ function step(scaled, tickPrecision) {
39773
+ const exponent = scaled.toString().length - 1 - tickPrecision;
39774
+ return exponent > 0 ? 10n ** BigInt(exponent) : 1n;
39775
+ }
39776
+ function tickSizeAt(price, tickPrecision) {
39777
+ checkPrecision(tickPrecision);
39778
+ return formatDec(step(positive(price), tickPrecision));
39779
+ }
39780
+ function isTickPrice(price, tickPrecision) {
39781
+ checkPrecision(tickPrecision);
39782
+ const scaled = positive(price);
39783
+ return scaled % step(scaled, tickPrecision) === 0n;
39784
+ }
39785
+ function floorTickPrice(price, tickPrecision) {
39786
+ checkPrecision(tickPrecision);
39787
+ const scaled = positive(price);
39788
+ return formatDec(scaled - scaled % step(scaled, tickPrecision));
39789
+ }
39790
+ function ceilTickPrice(price, tickPrecision) {
39791
+ checkPrecision(tickPrecision);
39792
+ const scaled = positive(price);
39793
+ const size = step(scaled, tickPrecision);
39794
+ const remainder = scaled % size;
39795
+ return formatDec(remainder === 0n ? scaled : scaled - remainder + size);
39796
+ }
39797
+
39761
39798
  // src/perp/orders.ts
39762
39799
  function iocLimitPrice(input) {
39763
39800
  const opposite = input.side === "buy" ? input.bestAsk : input.bestBid;
@@ -39765,11 +39802,6 @@ function iocLimitPrice(input) {
39765
39802
  if (reference === void 0 || reference === null || reference === "") {
39766
39803
  throw new Error(`no ${input.side === "buy" ? "ask" : "bid"} price to reference`);
39767
39804
  }
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
39805
  const ref = parseDec(reference);
39774
39806
  if (ref <= 0n) {
39775
39807
  throw new Error(`reference price must be positive, got ${reference}`);
@@ -39783,16 +39815,12 @@ function iocLimitPrice(input) {
39783
39815
  throw new Error(`slippage ${input.slippage} leaves no positive sell price`);
39784
39816
  }
39785
39817
  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");
39818
+ if (raw <= 0n) {
39819
+ throw new Error("IOC price is not positive; lower the slippage");
39794
39820
  }
39795
- return { price: formatDec(rounded), referencePrice: formatDec(ref) };
39821
+ const price = formatDec(raw);
39822
+ const rounded = input.side === "buy" ? ceilTickPrice(price, input.tickPrecision) : floorTickPrice(price, input.tickPrecision);
39823
+ return { price: rounded, referencePrice: formatDec(ref) };
39796
39824
  }
39797
39825
 
39798
39826
  // src/rest/types.ts
@@ -42945,6 +42973,7 @@ function createDexWs(url, options) {
42945
42973
  buildSetMarginConfigMsg,
42946
42974
  buildWithdrawMarginMsg,
42947
42975
  bytesToBase64,
42976
+ ceilTickPrice,
42948
42977
  collectPages,
42949
42978
  computeEvmFeesPerGas,
42950
42979
  computeFeeFreeGas,
@@ -43010,6 +43039,7 @@ function createDexWs(url, options) {
43010
43039
  fetchManifest,
43011
43040
  fetchProtoJson,
43012
43041
  fetchWithRetry,
43042
+ floorTickPrice,
43013
43043
  formatDec,
43014
43044
  fundingRate,
43015
43045
  getBalanceResponseFreeRegExpOne,
@@ -43096,6 +43126,7 @@ function createDexWs(url, options) {
43096
43126
  isAultSigner,
43097
43127
  isMarginAccountAddress,
43098
43128
  isPerpAccountAddress,
43129
+ isTickPrice,
43099
43130
  isValidAultAddress,
43100
43131
  isValidEvmAddress,
43101
43132
  isValidValidatorAddress,
@@ -43266,6 +43297,7 @@ function createDexWs(url, options) {
43266
43297
  signAndBroadcastEip712,
43267
43298
  simulateTx,
43268
43299
  stripEip712Domain,
43300
+ tickSizeAt,
43269
43301
  toViemChain,
43270
43302
  tpSlLegs,
43271
43303
  unrealizedPnl,