ault-sdk-ts 0.0.2-alpha.13 → 0.0.2-alpha.14

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.
@@ -32,7 +32,7 @@ export interface AgentSignAndBroadcastParams {
32
32
  }
33
33
  export declare function signAndBroadcastAgentTx({ network, keyMaterial, masterAddress, msgs, memo, gasLimit, confirmationTimeoutMs, timeoutSeconds, timeoutTimestamp, fetchFn, fetchOptions, cache, }: AgentSignAndBroadcastParams): Promise<{
34
34
  txHash: string;
35
- code: number;
35
+ code: 0;
36
36
  rawLog?: string;
37
- confirmed?: boolean;
37
+ confirmed: true;
38
38
  }>;
@@ -15,3 +15,69 @@ export declare class WebSocketError extends Error {
15
15
  reason?: string;
16
16
  constructor(message: string, code?: number, reason?: string);
17
17
  }
18
+ export interface TxErrorParams {
19
+ txHash: string;
20
+ code: number;
21
+ rawLog?: string;
22
+ /**
23
+ * - `true` -- chain returned a definitive non-zero code (CheckTx or DeliverTx).
24
+ * - `false` -- broadcast accepted but inclusion never observed within the timeout.
25
+ * - `undefined` -- broadcast accepted but the confirmation lookup endpoint failed.
26
+ */
27
+ confirmed: boolean | undefined;
28
+ }
29
+ /**
30
+ * Thrown when a tx broadcast resolves to a definitive on-chain failure
31
+ * (CheckTx or DeliverTx returned a non-zero code). Callers should catch
32
+ * this and surface the failure (e.g. UI toasts).
33
+ */
34
+ export declare class TxError extends Error {
35
+ txHash: string;
36
+ code: number;
37
+ rawLog?: string;
38
+ confirmed: boolean | undefined;
39
+ constructor(params: TxErrorParams, message?: string);
40
+ }
41
+ /**
42
+ * Thrown when a tx was broadcast but block inclusion could not be confirmed
43
+ * within the deadline. The tx may still commit later — callers can re-query
44
+ * by `txHash` to recover the final result.
45
+ */
46
+ export declare class TxNotConfirmedError extends TxError {
47
+ constructor(params: TxErrorParams);
48
+ }
49
+ /**
50
+ * Thrown when a tx was broadcast but the confirmation lookup endpoint was
51
+ * unreachable or returned an unrecognized payload. Distinct from
52
+ * `TxNotConfirmedError` so callers can distinguish "still pending" from
53
+ * "we cannot tell at all".
54
+ */
55
+ export declare class TxConfirmationUnavailableError extends TxError {
56
+ constructor(params: TxErrorParams);
57
+ }
58
+ /**
59
+ * Thrown by `withdrawRewards` when a mid-loop tx fails AFTER one or more
60
+ * validators have already been withdrawn on-chain. Carries the txs that
61
+ * already committed so callers can reconcile the partial state.
62
+ *
63
+ * `cause` is the underlying error for the failed validator — typically a
64
+ * `TxError` (chain rejection) but it can also be a transport-level failure
65
+ * (`NetworkError`, `TimeoutError`, `ApiError`) raised by the broadcast
66
+ * helper before the chain ever sees the tx.
67
+ */
68
+ export declare class WithdrawRewardsPartialError extends Error {
69
+ failedValidatorAddress: string;
70
+ partialResults: ReadonlyArray<{
71
+ txHash: string;
72
+ validatorAddress: string;
73
+ }>;
74
+ cause: Error;
75
+ constructor(params: {
76
+ failedValidatorAddress: string;
77
+ partialResults: ReadonlyArray<{
78
+ txHash: string;
79
+ validatorAddress: string;
80
+ }>;
81
+ cause: Error;
82
+ });
83
+ }
@@ -58,7 +58,7 @@ export interface SignAndBroadcastParams {
58
58
  }
59
59
  export declare function signAndBroadcastEip712({ network, signerAddress, signer, msgs, memo, gasLimit, feeDenom, feeAmount, confirmationTimeoutMs, fetchFn, fetchOptions, cache, feeMarketCache, }: SignAndBroadcastParams): Promise<{
60
60
  txHash: string;
61
- code: number;
61
+ code: 0;
62
62
  rawLog?: string;
63
- confirmed?: boolean;
63
+ confirmed: true;
64
64
  }>;
@@ -366,9 +366,20 @@ export interface StakingTxApi {
366
366
  amount: string;
367
367
  };
368
368
  } & TxOptions): Promise<TxResult>;
369
+ /**
370
+ * Issues one `MsgWithdrawDelegatorReward` per validator as an independent,
371
+ * sequentially signed tx. The chain rejects EIP-712 transactions that pack
372
+ * multiple Cosmos messages (`sdk/18: expected exactly 1 message, got N`),
373
+ * so bundling is unsafe; each validator must travel in its own tx.
374
+ *
375
+ * On full success returns one `TxResult` per validator in the order the
376
+ * caller supplied them. If any tx fails, throws `WithdrawRewardsPartialError`
377
+ * carrying the validator that failed and the txs that already committed.
378
+ * Subsequent validators are not attempted.
379
+ */
369
380
  withdrawRewards(params: {
370
381
  validatorAddresses: string[];
371
- } & TxOptions): Promise<TxResult>;
382
+ } & TxOptions): Promise<TxResult[]>;
372
383
  }
373
384
  export interface TokenRegistryTxApi {
374
385
  enableTokenRegistryTransfers(params?: TxOptions): Promise<TxResult>;
package/dist/index.cjs CHANGED
@@ -106,8 +106,12 @@ __export(index_exports, {
106
106
  TIMING_CONSTANTS: () => TIMING_CONSTANTS,
107
107
  TX_BASE_FIELDS: () => TX_BASE_FIELDS,
108
108
  TimeoutError: () => TimeoutError,
109
+ TxConfirmationUnavailableError: () => TxConfirmationUnavailableError,
110
+ TxError: () => TxError,
111
+ TxNotConfirmedError: () => TxNotConfirmedError,
109
112
  ValidatorStatus: () => BondStatus,
110
113
  WebSocketError: () => WebSocketError,
114
+ WithdrawRewardsPartialError: () => WithdrawRewardsPartialError,
111
115
  _resetIndexingCache: () => _resetIndexingCache,
112
116
  addressEquals: () => addressEquals,
113
117
  assertValidatorAddress: () => assertValidatorAddress,
@@ -370,6 +374,50 @@ var WebSocketError = class extends Error {
370
374
  this.reason = reason;
371
375
  }
372
376
  };
377
+ var TxError = class extends Error {
378
+ constructor(params, message) {
379
+ super(message ?? formatTxErrorMessage(params));
380
+ this.name = "TxError";
381
+ this.txHash = params.txHash;
382
+ this.code = params.code;
383
+ this.rawLog = params.rawLog;
384
+ this.confirmed = params.confirmed;
385
+ }
386
+ };
387
+ var TxNotConfirmedError = class extends TxError {
388
+ constructor(params) {
389
+ super(
390
+ params,
391
+ params.rawLog ?? `Transaction ${params.txHash} was not confirmed before the deadline elapsed.`
392
+ );
393
+ this.name = "TxNotConfirmedError";
394
+ }
395
+ };
396
+ var TxConfirmationUnavailableError = class extends TxError {
397
+ constructor(params) {
398
+ super(
399
+ params,
400
+ params.rawLog ?? `Transaction ${params.txHash} was broadcast but the confirmation endpoint was unavailable.`
401
+ );
402
+ this.name = "TxConfirmationUnavailableError";
403
+ }
404
+ };
405
+ function formatTxErrorMessage(params) {
406
+ const head = `Transaction ${params.txHash} failed (code ${params.code})`;
407
+ return params.rawLog ? `${head}: ${params.rawLog}` : `${head}.`;
408
+ }
409
+ var WithdrawRewardsPartialError = class extends Error {
410
+ constructor(params) {
411
+ const completed = params.partialResults.length;
412
+ super(
413
+ `withdrawRewards failed at validator ${params.failedValidatorAddress}: ${params.cause.message} (${completed} validator(s) committed before the failure)`
414
+ );
415
+ this.name = "WithdrawRewardsPartialError";
416
+ this.failedValidatorAddress = params.failedValidatorAddress;
417
+ this.partialResults = params.partialResults;
418
+ this.cause = params.cause;
419
+ }
420
+ };
373
421
 
374
422
  // src/core/http.ts
375
423
  var DEFAULT_OPTIONS = {
@@ -21376,12 +21424,12 @@ async function signAndBroadcastEip712({
21376
21424
  const txHash = normalizeTxHash(result.tx_response.txhash);
21377
21425
  if (result.tx_response.code !== 0) {
21378
21426
  clearCachedSequence(cache);
21379
- return {
21427
+ throw new TxError({
21380
21428
  txHash,
21381
21429
  code: result.tx_response.code,
21382
21430
  rawLog: result.tx_response.raw_log,
21383
21431
  confirmed: true
21384
- };
21432
+ });
21385
21433
  }
21386
21434
  const deliverResult = await pollTxInclusion(
21387
21435
  network,
@@ -21398,18 +21446,34 @@ async function signAndBroadcastEip712({
21398
21446
  }
21399
21447
  }
21400
21448
  if (deliverResult.confirmed === void 0) {
21401
- return {
21449
+ throw new TxConfirmationUnavailableError({
21402
21450
  txHash,
21403
- code: result.tx_response.code,
21451
+ code: deliverResult.code,
21404
21452
  rawLog: deliverResult.rawLog ?? result.tx_response.raw_log,
21405
21453
  confirmed: void 0
21406
- };
21454
+ });
21455
+ }
21456
+ if (deliverResult.confirmed === false) {
21457
+ throw new TxNotConfirmedError({
21458
+ txHash,
21459
+ code: deliverResult.code,
21460
+ rawLog: deliverResult.rawLog,
21461
+ confirmed: false
21462
+ });
21463
+ }
21464
+ if (deliverResult.code !== 0) {
21465
+ throw new TxError({
21466
+ txHash,
21467
+ code: deliverResult.code,
21468
+ rawLog: deliverResult.rawLog,
21469
+ confirmed: true
21470
+ });
21407
21471
  }
21408
21472
  return {
21409
21473
  txHash,
21410
- code: deliverResult.code,
21474
+ code: 0,
21411
21475
  rawLog: deliverResult.rawLog,
21412
- confirmed: deliverResult.confirmed
21476
+ confirmed: true
21413
21477
  };
21414
21478
  }
21415
21479
 
@@ -22609,13 +22673,35 @@ function createStakingTxApi({ signerAddress, exec }) {
22609
22673
  if (validatorAddresses.length === 0) {
22610
22674
  throw new Error("validatorAddresses must include at least one validator address.");
22611
22675
  }
22612
- const msgs = validatorAddresses.map(
22613
- (validatorAddress) => msg.distribution.withdrawDelegatorReward({
22614
- delegatorAddress: signerAddress,
22615
- validatorAddress: assertValidatorAddress(validatorAddress)
22616
- })
22617
- );
22618
- return exec(msgs, { gasLimit, feeAmount, memo, confirmationTimeoutMs });
22676
+ const normalized = validatorAddresses.map(assertValidatorAddress);
22677
+ const results = [];
22678
+ const partial = [];
22679
+ for (let i = 0; i < normalized.length; i++) {
22680
+ const validatorAddress = normalized[i];
22681
+ try {
22682
+ const result = await exec(
22683
+ [
22684
+ msg.distribution.withdrawDelegatorReward({
22685
+ delegatorAddress: signerAddress,
22686
+ validatorAddress
22687
+ })
22688
+ ],
22689
+ { gasLimit, feeAmount, memo, confirmationTimeoutMs }
22690
+ );
22691
+ results.push(result);
22692
+ partial.push({ txHash: result.txHash, validatorAddress });
22693
+ } catch (error) {
22694
+ if (partial.length > 0) {
22695
+ throw new WithdrawRewardsPartialError({
22696
+ failedValidatorAddress: validatorAddress,
22697
+ partialResults: partial,
22698
+ cause: error instanceof Error ? error : new Error(String(error))
22699
+ });
22700
+ }
22701
+ throw error;
22702
+ }
22703
+ }
22704
+ return results;
22619
22705
  }
22620
22706
  };
22621
22707
  }
@@ -22728,10 +22814,10 @@ function createTxExecutor(options) {
22728
22814
  });
22729
22815
  return {
22730
22816
  txHash: result.txHash,
22731
- code: result.code,
22817
+ code: 0,
22732
22818
  rawLog: result.rawLog,
22733
- confirmed: result.confirmed,
22734
- success: result.code === 0 && result.confirmed === true
22819
+ confirmed: true,
22820
+ success: true
22735
22821
  };
22736
22822
  };
22737
22823
  }
@@ -22901,12 +22987,12 @@ async function signAndBroadcastAgentTx({
22901
22987
  );
22902
22988
  const txHash = normalizeTxHash(result.tx_response.txhash);
22903
22989
  if (result.tx_response.code !== 0) {
22904
- return {
22990
+ throw new TxError({
22905
22991
  txHash,
22906
22992
  code: result.tx_response.code,
22907
22993
  rawLog: result.tx_response.raw_log,
22908
22994
  confirmed: true
22909
- };
22995
+ });
22910
22996
  }
22911
22997
  const deliverResult = await pollTxInclusion(
22912
22998
  network,
@@ -22916,18 +23002,34 @@ async function signAndBroadcastAgentTx({
22916
23002
  confirmationTimeoutMs
22917
23003
  );
22918
23004
  if (deliverResult.confirmed === void 0) {
22919
- return {
23005
+ throw new TxConfirmationUnavailableError({
22920
23006
  txHash,
22921
- code: result.tx_response.code,
23007
+ code: deliverResult.code,
22922
23008
  rawLog: deliverResult.rawLog ?? result.tx_response.raw_log,
22923
23009
  confirmed: void 0
22924
- };
23010
+ });
23011
+ }
23012
+ if (deliverResult.confirmed === false) {
23013
+ throw new TxNotConfirmedError({
23014
+ txHash,
23015
+ code: deliverResult.code,
23016
+ rawLog: deliverResult.rawLog,
23017
+ confirmed: false
23018
+ });
23019
+ }
23020
+ if (deliverResult.code !== 0) {
23021
+ throw new TxError({
23022
+ txHash,
23023
+ code: deliverResult.code,
23024
+ rawLog: deliverResult.rawLog,
23025
+ confirmed: true
23026
+ });
22925
23027
  }
22926
23028
  return {
22927
23029
  txHash,
22928
- code: deliverResult.code,
23030
+ code: 0,
22929
23031
  rawLog: deliverResult.rawLog,
22930
- confirmed: deliverResult.confirmed
23032
+ confirmed: true
22931
23033
  };
22932
23034
  }
22933
23035
 
@@ -22960,10 +23062,10 @@ function createAgentTxExecutor(options) {
22960
23062
  });
22961
23063
  return {
22962
23064
  txHash: result.txHash,
22963
- code: result.code,
23065
+ code: 0,
22964
23066
  rawLog: result.rawLog,
22965
- confirmed: result.confirmed,
22966
- success: result.code === 0 && result.confirmed === true
23067
+ confirmed: true,
23068
+ success: true
22967
23069
  };
22968
23070
  };
22969
23071
  }
@@ -23689,7 +23791,7 @@ function createDexWs(url, options) {
23689
23791
  }
23690
23792
 
23691
23793
  // src/index.ts
23692
- var SDK_VERSION = "0.0.2-alpha.13";
23794
+ var SDK_VERSION = "0.0.2-alpha.14";
23693
23795
  // Annotate the CommonJS export names for ESM import in node:
23694
23796
  0 && (module.exports = {
23695
23797
  AGENT_DEFAULTS,
@@ -23768,8 +23870,12 @@ var SDK_VERSION = "0.0.2-alpha.13";
23768
23870
  TIMING_CONSTANTS,
23769
23871
  TX_BASE_FIELDS,
23770
23872
  TimeoutError,
23873
+ TxConfirmationUnavailableError,
23874
+ TxError,
23875
+ TxNotConfirmedError,
23771
23876
  ValidatorStatus,
23772
23877
  WebSocketError,
23878
+ WithdrawRewardsPartialError,
23773
23879
  _resetIndexingCache,
23774
23880
  addressEquals,
23775
23881
  assertValidatorAddress,