ault-sdk-ts 0.16.0 → 0.17.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
@@ -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,6 +366,7 @@ 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
372
  const dex = client._lowLevel.rest.dex;
@@ -381,7 +383,7 @@ await client.placeLimitOrder({
381
383
  marketId,
382
384
  isBuy: true,
383
385
  price,
384
- quantity: "1",
386
+ quantity: parseUnits("0.01", 18).toString(), // 0.01 BTC
385
387
  deadline: new Date(Date.now() + 60_000),
386
388
  timeInForce: "ioc",
387
389
  reduceOnly: false,
@@ -400,10 +402,12 @@ and leverage are set per market and cannot change while a position or resting
400
402
  order exists:
401
403
 
402
404
  ```typescript
403
- 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() });
404
407
  await client.setMarginConfig({ marketId, leverage: 10, cross: true });
405
- await client.modifyPositionMargin({ marketId, marginDelta: "-500000" }); // isolated only
406
- 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() });
407
411
  ```
408
412
 
409
413
  A perpetual TWAP (`placeTwapOrder` with `reduceOnly`) is sized in base and
@@ -431,8 +435,9 @@ move the signer's own funds, so they are wallet-signed only (never by an
431
435
  agent).
432
436
 
433
437
  ```typescript
434
- const usdc = { denom: "erc20:0xd157...", amount: "1000000000" }; // base units
435
- 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
436
441
 
437
442
  await client.lendingSupply({ poolId: 1, coin: usdc }); // earns the supply rate
438
443
  await client.lendingSupplyCollateral({ poolId: 1, coin: weth }); // backs borrows, earns nothing
@@ -470,6 +475,7 @@ account per market, both derived from the owner's address, and their
470
475
  collateral and debt live in the margin Lending pool.
471
476
 
472
477
  ```typescript
478
+ import { parseUnits } from "viem";
473
479
  import { marginAccountAddress } from "ault-sdk-ts";
474
480
 
475
481
  // Fund the isolated account of a market (omit marketId for the cross account).
@@ -481,7 +487,7 @@ await client.placeLimitOrder({
481
487
  marketId,
482
488
  isBuy: true,
483
489
  price: "3500",
484
- quantity: "0.5",
490
+ quantity: parseUnits("0.5", 18).toString(),
485
491
  deadline: new Date(Date.now() + 3_600_000),
486
492
  margin: { autoBorrow: true },
487
493
  });
@@ -492,7 +498,7 @@ await client.placeLimitOrder({
492
498
  marketId,
493
499
  isBuy: false,
494
500
  price: "3600",
495
- quantity: "0.5",
501
+ quantity: parseUnits("0.5", 18).toString(),
496
502
  deadline: new Date(Date.now() + 3_600_000),
497
503
  margin: { autoRepay: true },
498
504
  });
@@ -606,6 +612,8 @@ of vault:
606
612
  Parent vaults belong to x/gov, so only a governance proposal can create one.
607
613
 
608
614
  ```typescript
615
+ import { parseUnits } from "viem";
616
+
609
617
  const lendingVault = client.attachVaultManager({ vaultAddress, agentPrivateKey: managerKey });
610
618
  await lendingVault.reallocateVault({ sourcePoolId: 1, destinationPoolId: 2, amount: usdc });
611
619
 
@@ -616,7 +624,13 @@ const parent = client.attachVaultManager({
616
624
  });
617
625
  await parent.transferChildVault({ childVault, amount: usdc, isDeposit: true });
618
626
  const child = client.attachVaultManager({ vaultAddress: childVault, agentPrivateKey: managerKey });
619
- 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
+ });
620
634
  ```
621
635
 
622
636
  Status changes and config updates come from the vault's owner, not its
@@ -1004,7 +1018,7 @@ interface TxResult {
1004
1018
  txHash: string; // Transaction hash
1005
1019
  code: number; // Result code (0 = success)
1006
1020
  rawLog?: string; // Raw log from transaction
1007
- confirmed?: boolean; // true = DeliverTx observed; false = broadcast-only or poll timeout; undefined = confirmation lookup unavailable
1021
+ confirmed?: boolean; // true = DeliverTx observed; false = broadcast-only or poll timeout; undefined = outcome unknown
1008
1022
  success: boolean; // True only when DeliverTx success was confirmed
1009
1023
  }
1010
1024
  ```
@@ -1084,18 +1098,32 @@ await client.updateOperatorInfo({
1084
1098
 
1085
1099
  ### Market And CLOB Transactions
1086
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
+
1087
1112
  ```typescript
1113
+ import { parseUnits } from "viem";
1088
1114
  import { base64ToBytes } from "ault-sdk-ts";
1089
1115
 
1090
1116
  const marketId = base64ToBytes("base64MarketId...");
1117
+ const units = (amount: string) => parseUnits(amount, 18).toString();
1091
1118
 
1092
1119
  // Place a limit order (broadcast-only: returns once CheckTx accepts it).
1120
+ // 100 base at 1.5 is a notional of 150 quote.
1093
1121
  await client.placeLimitOrder({
1094
1122
  marketId,
1095
1123
  isBuy: true,
1096
1124
  price: "1.5",
1097
- quantity: "100",
1098
- lifespan: { seconds: 3600n, nanos: 0 }, // 1 hour
1125
+ quantity: units("100"),
1126
+ deadline: new Date(Date.now() + 3_600_000), // 1 hour
1099
1127
  });
1100
1128
 
1101
1129
  // Pass `wait: true` to poll for DeliverTx and read back the order ID.
@@ -1103,17 +1131,17 @@ const placed = await client.placeLimitOrder({
1103
1131
  marketId,
1104
1132
  isBuy: true,
1105
1133
  price: "1.5",
1106
- quantity: "100",
1107
- lifespan: { seconds: 3600n, nanos: 0 },
1134
+ quantity: units("100"),
1135
+ deadline: new Date(Date.now() + 3_600_000),
1108
1136
  wait: true,
1109
1137
  });
1110
1138
  console.log(placed.orderId);
1111
1139
 
1112
- // Place a market order
1140
+ // Place a market order: buy with 100 quote.
1113
1141
  await client.placeMarketOrder({
1114
1142
  marketId,
1115
1143
  isBuy: true,
1116
- deposit: "100",
1144
+ deposit: units("100"),
1117
1145
  });
1118
1146
 
1119
1147
  // Cancel specific orders. With `wait: true` the result lists which IDs
@@ -1129,7 +1157,7 @@ const withCloid = await client.placeLimitOrder({
1129
1157
  marketId,
1130
1158
  isBuy: true,
1131
1159
  price: "1.5",
1132
- quantity: "100",
1160
+ quantity: units("100"),
1133
1161
  deadline: new Date(Date.now() + 3600_000),
1134
1162
  cloid,
1135
1163
  wait: true,
@@ -1247,7 +1275,7 @@ const placed = await client.asAgent!.placeLimitOrder({
1247
1275
  isBuy: true,
1248
1276
  price: "1.0",
1249
1277
  quantity: "1000000000000000000",
1250
- lifespan: { seconds: 3600n, nanos: 0 },
1278
+ deadline: new Date(Date.now() + 3_600_000),
1251
1279
  wait: true,
1252
1280
  });
1253
1281
  console.log(placed.orderId);
@@ -1267,7 +1295,7 @@ await client.asAgent!.placeScaleOrder({
1267
1295
  highPrice: "1.1",
1268
1296
  totalQuantity: "10000000000000000000",
1269
1297
  weights: [3333, 3334, 3333],
1270
- lifespan: { seconds: 3600n, nanos: 0 },
1298
+ deadline: new Date(Date.now() + 3_600_000),
1271
1299
  });
1272
1300
  ```
1273
1301
 
@@ -1327,7 +1355,7 @@ Note: `pnpm gen:eip712` also reads Cosmos SDK protos (staking/distribution) and
1327
1355
  ## Error Handling
1328
1356
 
1329
1357
  ```typescript
1330
- import { ApiError, NetworkError, TimeoutError } from "ault-sdk-ts";
1358
+ import { ApiError, NetworkError, TimeoutError, TxConfirmationUnavailableError } from "ault-sdk-ts";
1331
1359
 
1332
1360
  try {
1333
1361
  const result = await client.transferLicense({ licenseId: 1, to: "0x..." });
@@ -1343,7 +1371,9 @@ try {
1343
1371
  console.error(`Transaction failed: ${result.rawLog}`);
1344
1372
  }
1345
1373
  } catch (error) {
1346
- if (error instanceof ApiError) {
1374
+ if (error instanceof TxConfirmationUnavailableError) {
1375
+ console.warn(`Outcome unknown, look the transaction up first: ${error.txHash}`);
1376
+ } else if (error instanceof ApiError) {
1347
1377
  console.error(`API Error (${error.status}): ${error.message}`);
1348
1378
  } else if (error instanceof NetworkError) {
1349
1379
  console.error(`Network Error: ${error.message}`);
@@ -1353,6 +1383,13 @@ try {
1353
1383
  }
1354
1384
  ```
1355
1385
 
1386
+ A send can also end with the outcome unknown. If the broadcast response is lost
1387
+ or unreadable, or the node cannot answer the confirmation lookup, the SDK
1388
+ throws `TxConfirmationUnavailableError`. The chain may have accepted the
1389
+ transaction, so look it up by `error.txHash` before you sign and send it again.
1390
+ A `TxNotConfirmedError` means the broadcast was accepted but the transaction
1391
+ did not show up in a block before the timeout.
1392
+
1356
1393
  ## Advanced Usage
1357
1394
 
1358
1395
  For advanced use cases, you can access the low-level client:
@@ -1,6 +1,6 @@
1
1
  import { type AccountCache } from "../eip712/sign-and-broadcast";
2
2
  import type { AnyEip712Msg } from "../eip712/builder";
3
- import { type FetchFn, type FetchWithRetryOptions } from "../core/http";
3
+ import type { FetchFn, FetchWithRetryOptions } from "../core/http";
4
4
  import type { NetworkConfig } from "../core/network";
5
5
  export declare const AGENT_DEFAULTS: {
6
6
  readonly GAS_LIMIT: "186000";
@@ -22,7 +22,7 @@ export interface TxErrorParams {
22
22
  /**
23
23
  * - `true` -- chain returned a definitive non-zero code (CheckTx or DeliverTx).
24
24
  * - `false` -- broadcast accepted but inclusion never observed within the timeout.
25
- * - `undefined` -- broadcast accepted but the confirmation lookup endpoint failed.
25
+ * - `undefined` -- broadcast or confirmation response unavailable; acceptance is unknown.
26
26
  */
27
27
  confirmed: boolean | undefined;
28
28
  }
@@ -60,8 +60,9 @@ export declare class TxNotConfirmedError extends TxError {
60
60
  constructor(params: TxErrorParams);
61
61
  }
62
62
  /**
63
- * Thrown when a tx was broadcast but the confirmation lookup endpoint was
64
- * unreachable or returned an unrecognized payload. Distinct from
63
+ * Thrown when the signed broadcast response or the confirmation lookup was
64
+ * unavailable or returned an unrecognized payload. The tx may or may not have
65
+ * been accepted; `txHash` is always set so it can be looked up. Distinct from
65
66
  * `TxNotConfirmedError` so callers can distinguish "still pending" from
66
67
  * "we cannot tell at all".
67
68
  */
@@ -15,6 +15,21 @@ export interface AccountCache {
15
15
  nextSequence: string | null;
16
16
  }
17
17
  export declare function createAccountCache(): AccountCache;
18
+ /**
19
+ * Posts signed tx bytes and returns the CheckTx result.
20
+ *
21
+ * The request is never retried: once the bytes are signed, a lost or
22
+ * unreadable response does not mean the chain rejected them. Any failure to
23
+ * get a recognizable response throws `TxConfirmationUnavailableError` carrying
24
+ * the hash computed from the signed bytes, so the caller can look the tx up.
25
+ *
26
+ * @internal
27
+ */
28
+ export declare function broadcastSignedTx(network: NetworkConfig, txRawBytes: Uint8Array, fetchFn?: FetchFn, fetchOptions?: FetchWithRetryOptions): Promise<{
29
+ txHash: string;
30
+ code: number;
31
+ rawLog?: string;
32
+ }>;
18
33
  /** @internal Retained for compatibility; polling is now stateless. */
19
34
  export declare function _resetIndexingCache(): void;
20
35
  /**
package/dist/index.cjs CHANGED
@@ -281,6 +281,7 @@ __export(index_exports, {
281
281
  aultToEvm: () => aultToEvm,
282
282
  averagePremium: () => averagePremium,
283
283
  base64ToBytes: () => base64ToBytes,
284
+ broadcastSignedTx: () => broadcastSignedTx,
284
285
  buildBorrowMarginMsg: () => buildBorrowMarginMsg,
285
286
  buildConditionalOrderMsg: () => buildConditionalOrderMsg,
286
287
  buildDepositMarginMsg: () => buildDepositMarginMsg,
@@ -635,7 +636,7 @@ __export(index_exports, {
635
636
  module.exports = __toCommonJS(index_exports);
636
637
 
637
638
  // src/core/user-agent.ts
638
- var SDK_VERSION = "0.16.0";
639
+ var SDK_VERSION = "0.17.0";
639
640
  var USER_AGENT = `ault-sdk-ts/${SDK_VERSION}`;
640
641
  function isServerRuntime() {
641
642
  if (typeof document !== "undefined") return false;
@@ -22220,6 +22221,14 @@ function compareBytes(a, b) {
22220
22221
  return a.length - b.length;
22221
22222
  }
22222
22223
 
22224
+ // src/rest/market-id.ts
22225
+ var MARKET_ID_HEX_RE = /^(0[xX])?([0-9a-fA-F]{2})+$/;
22226
+ function marketIdToBase64(marketId) {
22227
+ if (marketId instanceof MarketId) return marketId.toBase64();
22228
+ if (typeof marketId !== "string") return bytesToBase64(marketId);
22229
+ return MARKET_ID_HEX_RE.test(marketId) ? MarketId.fromHex(marketId).toBase64() : marketId;
22230
+ }
22231
+
22223
22232
  // src/proto/gen/ault/clob/v1/query.ts
22224
22233
  var import_wire45 = require("@bufbuild/protobuf/wire");
22225
22234
 
@@ -23210,9 +23219,6 @@ function normalizeOrderId(orderId) {
23210
23219
  if (typeof orderId !== "string") return bytesToBase64(orderId);
23211
23220
  return ORDER_ID_HEX_RE.test(orderId) ? OrderId.fromHex(orderId).toBase64() : orderId;
23212
23221
  }
23213
- function normalizeMarketId(marketId) {
23214
- return typeof marketId === "string" ? marketId : bytesToBase64(marketId);
23215
- }
23216
23222
  var LIMIT_TYPE_URL = "/ault.clob.v1.MsgPlaceLimitOrder";
23217
23223
  var MARKET_TYPE_URL = "/ault.clob.v1.MsgPlaceMarketOrder";
23218
23224
  var OPTION_CODECS = {
@@ -23304,7 +23310,7 @@ function createClobApi(context) {
23304
23310
  },
23305
23311
  async getOrders(params = {}) {
23306
23312
  const query = buildQuery({
23307
- market_id: params.marketId ? normalizeMarketId(params.marketId) : void 0,
23313
+ market_id: params.marketId ? marketIdToBase64(params.marketId) : void 0,
23308
23314
  ...params.pagination
23309
23315
  });
23310
23316
  return fetchProtoJson(
@@ -25731,10 +25737,6 @@ function isSet46(value) {
25731
25737
  }
25732
25738
 
25733
25739
  // src/rest/margin.ts
25734
- function marketIdParam(marketId) {
25735
- if (marketId instanceof MarketId) return marketId.toBase64();
25736
- return typeof marketId === "string" ? marketId : bytesToBase64(marketId);
25737
- }
25738
25740
  var enc2 = encodeURIComponent;
25739
25741
  function createMarginApi(context) {
25740
25742
  return {
@@ -25751,7 +25753,7 @@ function createMarginApi(context) {
25751
25753
  },
25752
25754
  async getMarginAccount(owner, marketId) {
25753
25755
  const query = buildQuery({
25754
- market_id: marketId === void 0 ? void 0 : marketIdParam(marketId)
25756
+ market_id: marketId === void 0 ? void 0 : marketIdToBase64(marketId)
25755
25757
  });
25756
25758
  return fetchProtoJson(
25757
25759
  context,
@@ -26141,9 +26143,6 @@ function isSet48(value) {
26141
26143
  }
26142
26144
 
26143
26145
  // src/rest/market.ts
26144
- function normalizeMarketId2(marketId) {
26145
- return typeof marketId === "string" ? marketId : bytesToBase64(marketId);
26146
- }
26147
26146
  function createMarketApi(context) {
26148
26147
  return {
26149
26148
  async getParams() {
@@ -26156,7 +26155,7 @@ function createMarketApi(context) {
26156
26155
  async getMarket(marketId) {
26157
26156
  return fetchProtoJson(
26158
26157
  context,
26159
- `/ault/market/v1/markets/${encodeURIComponent(normalizeMarketId2(marketId))}`,
26158
+ `/ault/market/v1/markets/${encodeURIComponent(marketIdToBase64(marketId))}`,
26160
26159
  QueryMarketResponse
26161
26160
  );
26162
26161
  }
@@ -29371,10 +29370,6 @@ function isSet53(value) {
29371
29370
  }
29372
29371
 
29373
29372
  // src/rest/perpetual.ts
29374
- function normalizeMarketId3(marketId) {
29375
- if (marketId instanceof MarketId) return marketId.toBase64();
29376
- return typeof marketId === "string" ? marketId : bytesToBase64(marketId);
29377
- }
29378
29373
  function createPerpetualApi(context) {
29379
29374
  return {
29380
29375
  async getParams() {
@@ -29389,7 +29384,7 @@ function createPerpetualApi(context) {
29389
29384
  },
29390
29385
  async getAccount(owner, marketId) {
29391
29386
  const query = buildQuery({
29392
- market_id: marketId === void 0 ? void 0 : normalizeMarketId3(marketId)
29387
+ market_id: marketId === void 0 ? void 0 : marketIdToBase64(marketId)
29393
29388
  });
29394
29389
  return fetchProtoJson(
29395
29390
  context,
@@ -29398,7 +29393,7 @@ function createPerpetualApi(context) {
29398
29393
  );
29399
29394
  },
29400
29395
  async getPosition(owner, marketId, cross) {
29401
- const query = buildQuery({ market_id: normalizeMarketId3(marketId), cross });
29396
+ const query = buildQuery({ market_id: marketIdToBase64(marketId), cross });
29402
29397
  return fetchProtoJson(
29403
29398
  context,
29404
29399
  `/ault/perpetual/v1/position/${encodeURIComponent(normalizeAddress(owner))}${query}`,
@@ -29407,7 +29402,7 @@ function createPerpetualApi(context) {
29407
29402
  },
29408
29403
  async getAccountRisk(owner, marketId) {
29409
29404
  const query = buildQuery({
29410
- market_id: marketId === void 0 ? void 0 : normalizeMarketId3(marketId)
29405
+ market_id: marketId === void 0 ? void 0 : marketIdToBase64(marketId)
29411
29406
  });
29412
29407
  return fetchProtoJson(
29413
29408
  context,
@@ -29416,11 +29411,11 @@ function createPerpetualApi(context) {
29416
29411
  );
29417
29412
  },
29418
29413
  async getFunding(marketId) {
29419
- const query = buildQuery({ market_id: normalizeMarketId3(marketId) });
29414
+ const query = buildQuery({ market_id: marketIdToBase64(marketId) });
29420
29415
  return fetchProtoJson(context, `/ault/perpetual/v1/funding${query}`, QueryFundingResponse);
29421
29416
  },
29422
29417
  async getPrices(marketId) {
29423
- const id = encodeURIComponent(normalizeMarketId3(marketId));
29418
+ const id = encodeURIComponent(marketIdToBase64(marketId));
29424
29419
  return fetchProtoJson(
29425
29420
  context,
29426
29421
  `/ault/perpetual/v1/markets/${id}/prices`,
@@ -29428,7 +29423,7 @@ function createPerpetualApi(context) {
29428
29423
  );
29429
29424
  },
29430
29425
  async getImpactPrices(marketId) {
29431
- const id = encodeURIComponent(normalizeMarketId3(marketId));
29426
+ const id = encodeURIComponent(marketIdToBase64(marketId));
29432
29427
  return fetchProtoJson(
29433
29428
  context,
29434
29429
  `/ault/perpetual/v1/markets/${id}/impact_prices`,
@@ -30162,7 +30157,7 @@ function createRewardApi(context) {
30162
30157
  );
30163
30158
  },
30164
30159
  async getDeployerShare(marketId) {
30165
- const encoded = typeof marketId === "string" ? marketId : bytesToBase64(marketId);
30160
+ const encoded = marketIdToBase64(marketId);
30166
30161
  return fetchProtoJson(
30167
30162
  context,
30168
30163
  `/ault/reward/v1/deployer_share/${encodeURIComponent(encoded)}`,
@@ -35599,6 +35594,34 @@ function getConfirmationUnavailableLog(txHash, error) {
35599
35594
  }
35600
35595
  return `Transaction ${txHash} was broadcast but could not be confirmed.`;
35601
35596
  }
35597
+ async function broadcastSignedTx(network, txRawBytes, fetchFn, fetchOptions) {
35598
+ const txHash = normalizeTxHash((0, import_viem5.sha256)(txRawBytes));
35599
+ try {
35600
+ const result = await postJson(
35601
+ `${network.restUrl}/cosmos/tx/v1beta1/txs`,
35602
+ { tx_bytes: bytesToBase64(txRawBytes), mode: "BROADCAST_MODE_SYNC" },
35603
+ { ...fetchOptions, retries: 0 },
35604
+ fetchFn
35605
+ );
35606
+ const response = result?.tx_response;
35607
+ const code = response?.code;
35608
+ const rawHash = response?.txhash;
35609
+ if (typeof code !== "number" || !Number.isSafeInteger(code) || code < 0 || typeof rawHash !== "string" || !rawHash) {
35610
+ throw new Error("Unrecognized broadcast response");
35611
+ }
35612
+ if (normalizeTxHash(rawHash) !== txHash) {
35613
+ throw new Error("Broadcast response is for a different transaction");
35614
+ }
35615
+ return { txHash, code, rawLog: response?.raw_log };
35616
+ } catch (error) {
35617
+ throw new TxConfirmationUnavailableError({
35618
+ txHash,
35619
+ code: -1,
35620
+ rawLog: error instanceof Error ? error.message : "Broadcast response unavailable",
35621
+ confirmed: void 0
35622
+ });
35623
+ }
35624
+ }
35602
35625
  function _resetIndexingCache() {
35603
35626
  }
35604
35627
  async function pollTxInclusion(network, txHash, fetchFn, fetchOptions, timeoutMs = TIMING_CONSTANTS.TX_POLL_TIMEOUT_MS, intervalMs = 1500) {
@@ -35615,7 +35638,8 @@ async function pollTxInclusion(network, txHash, fetchFn, fetchOptions, timeoutMs
35615
35638
  { ...fetchOptions, retries: 0, timeout: perRequestTimeout },
35616
35639
  fetchFn
35617
35640
  );
35618
- if (typeof result.tx_response?.code !== "number") {
35641
+ const receipt = result?.tx_response;
35642
+ if (!receipt || !Number.isSafeInteger(receipt.code) || receipt.code < 0 || typeof receipt.txhash !== "string" || normalizeTxHash(receipt.txhash) !== normalizeTxHash(txHash) || typeof receipt.height !== "string" || !/^\d+$/.test(receipt.height) || BigInt(receipt.height) <= 0n) {
35619
35643
  return {
35620
35644
  code: -1,
35621
35645
  rawLog: `Transaction ${txHash} was broadcast but the confirmation response was invalid.`,
@@ -35623,9 +35647,9 @@ async function pollTxInclusion(network, txHash, fetchFn, fetchOptions, timeoutMs
35623
35647
  };
35624
35648
  }
35625
35649
  return {
35626
- code: result.tx_response.code,
35627
- rawLog: result.tx_response.raw_log,
35628
- data: result.tx_response.data,
35650
+ code: receipt.code,
35651
+ rawLog: receipt.raw_log,
35652
+ data: receipt.data,
35629
35653
  confirmed: true
35630
35654
  };
35631
35655
  } catch (error) {
@@ -35783,26 +35807,20 @@ async function signAndBroadcastEip712({
35783
35807
  authInfoBytes,
35784
35808
  signatures: [sigWithoutRecovery]
35785
35809
  });
35786
- const txBytesBase64 = bytesToBase64(txRawBytes);
35787
- let result;
35810
+ let checkTx;
35788
35811
  try {
35789
- result = await postJson(
35790
- `${network.restUrl}/cosmos/tx/v1beta1/txs`,
35791
- { tx_bytes: txBytesBase64, mode: "BROADCAST_MODE_SYNC" },
35792
- { ...fetchOptions, retries: 0 },
35793
- fetchFn
35794
- );
35812
+ checkTx = await broadcastSignedTx(network, txRawBytes, fetchFn, fetchOptions);
35795
35813
  } catch (error) {
35796
35814
  clearCachedSequence(cache);
35797
35815
  throw error;
35798
35816
  }
35799
- const txHash = normalizeTxHash(result.tx_response.txhash);
35800
- if (result.tx_response.code !== 0) {
35817
+ const { txHash } = checkTx;
35818
+ if (checkTx.code !== 0) {
35801
35819
  clearCachedSequence(cache);
35802
35820
  throw new TxError({
35803
35821
  txHash,
35804
- code: result.tx_response.code,
35805
- rawLog: result.tx_response.raw_log,
35822
+ code: checkTx.code,
35823
+ rawLog: checkTx.rawLog,
35806
35824
  confirmed: true
35807
35825
  });
35808
35826
  }
@@ -35811,7 +35829,7 @@ async function signAndBroadcastEip712({
35811
35829
  return {
35812
35830
  txHash,
35813
35831
  code: 0,
35814
- rawLog: result.tx_response.raw_log,
35832
+ rawLog: checkTx.rawLog,
35815
35833
  confirmed: false
35816
35834
  };
35817
35835
  }
@@ -35833,7 +35851,7 @@ async function signAndBroadcastEip712({
35833
35851
  throw new TxConfirmationUnavailableError({
35834
35852
  txHash,
35835
35853
  code: deliverResult.code,
35836
- rawLog: deliverResult.rawLog ?? result.tx_response.raw_log,
35854
+ rawLog: deliverResult.rawLog ?? checkTx.rawLog,
35837
35855
  confirmed: void 0
35838
35856
  });
35839
35857
  }
@@ -38860,19 +38878,13 @@ async function signAndBroadcastAgentTx({
38860
38878
  authInfoBytes,
38861
38879
  signatures: [signatureBytes]
38862
38880
  });
38863
- const txBytesBase64 = bytesToBase64(txRawBytes);
38864
- const result = await postJson(
38865
- `${network.restUrl}/cosmos/tx/v1beta1/txs`,
38866
- { tx_bytes: txBytesBase64, mode: "BROADCAST_MODE_SYNC" },
38867
- fetchOptions,
38868
- fetchFn
38869
- );
38870
- const txHash = normalizeTxHash(result.tx_response.txhash);
38871
- if (result.tx_response.code !== 0) {
38881
+ const checkTx = await broadcastSignedTx(network, txRawBytes, fetchFn, fetchOptions);
38882
+ const { txHash } = checkTx;
38883
+ if (checkTx.code !== 0) {
38872
38884
  throw new TxError({
38873
38885
  txHash,
38874
- code: result.tx_response.code,
38875
- rawLog: result.tx_response.raw_log,
38886
+ code: checkTx.code,
38887
+ rawLog: checkTx.rawLog,
38876
38888
  confirmed: true
38877
38889
  });
38878
38890
  }
@@ -38880,7 +38892,7 @@ async function signAndBroadcastAgentTx({
38880
38892
  return {
38881
38893
  txHash,
38882
38894
  code: 0,
38883
- rawLog: result.tx_response.raw_log,
38895
+ rawLog: checkTx.rawLog,
38884
38896
  confirmed: false
38885
38897
  };
38886
38898
  }
@@ -38895,7 +38907,7 @@ async function signAndBroadcastAgentTx({
38895
38907
  throw new TxConfirmationUnavailableError({
38896
38908
  txHash,
38897
38909
  code: deliverResult.code,
38898
- rawLog: deliverResult.rawLog ?? result.tx_response.raw_log,
38910
+ rawLog: deliverResult.rawLog ?? checkTx.rawLog,
38899
38911
  confirmed: void 0
38900
38912
  });
38901
38913
  }
@@ -42961,6 +42973,7 @@ function createDexWs(url, options) {
42961
42973
  aultToEvm,
42962
42974
  averagePremium,
42963
42975
  base64ToBytes,
42976
+ broadcastSignedTx,
42964
42977
  buildBorrowMarginMsg,
42965
42978
  buildConditionalOrderMsg,
42966
42979
  buildDepositMarginMsg,