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.
package/dist/index.js CHANGED
@@ -135,6 +135,50 @@ var WebSocketError = class extends Error {
135
135
  this.reason = reason;
136
136
  }
137
137
  };
138
+ var TxError = class extends Error {
139
+ constructor(params, message) {
140
+ super(message ?? formatTxErrorMessage(params));
141
+ this.name = "TxError";
142
+ this.txHash = params.txHash;
143
+ this.code = params.code;
144
+ this.rawLog = params.rawLog;
145
+ this.confirmed = params.confirmed;
146
+ }
147
+ };
148
+ var TxNotConfirmedError = class extends TxError {
149
+ constructor(params) {
150
+ super(
151
+ params,
152
+ params.rawLog ?? `Transaction ${params.txHash} was not confirmed before the deadline elapsed.`
153
+ );
154
+ this.name = "TxNotConfirmedError";
155
+ }
156
+ };
157
+ var TxConfirmationUnavailableError = class extends TxError {
158
+ constructor(params) {
159
+ super(
160
+ params,
161
+ params.rawLog ?? `Transaction ${params.txHash} was broadcast but the confirmation endpoint was unavailable.`
162
+ );
163
+ this.name = "TxConfirmationUnavailableError";
164
+ }
165
+ };
166
+ function formatTxErrorMessage(params) {
167
+ const head = `Transaction ${params.txHash} failed (code ${params.code})`;
168
+ return params.rawLog ? `${head}: ${params.rawLog}` : `${head}.`;
169
+ }
170
+ var WithdrawRewardsPartialError = class extends Error {
171
+ constructor(params) {
172
+ const completed = params.partialResults.length;
173
+ super(
174
+ `withdrawRewards failed at validator ${params.failedValidatorAddress}: ${params.cause.message} (${completed} validator(s) committed before the failure)`
175
+ );
176
+ this.name = "WithdrawRewardsPartialError";
177
+ this.failedValidatorAddress = params.failedValidatorAddress;
178
+ this.partialResults = params.partialResults;
179
+ this.cause = params.cause;
180
+ }
181
+ };
138
182
 
139
183
  // src/core/http.ts
140
184
  var DEFAULT_OPTIONS = {
@@ -21141,12 +21185,12 @@ async function signAndBroadcastEip712({
21141
21185
  const txHash = normalizeTxHash(result.tx_response.txhash);
21142
21186
  if (result.tx_response.code !== 0) {
21143
21187
  clearCachedSequence(cache);
21144
- return {
21188
+ throw new TxError({
21145
21189
  txHash,
21146
21190
  code: result.tx_response.code,
21147
21191
  rawLog: result.tx_response.raw_log,
21148
21192
  confirmed: true
21149
- };
21193
+ });
21150
21194
  }
21151
21195
  const deliverResult = await pollTxInclusion(
21152
21196
  network,
@@ -21163,18 +21207,34 @@ async function signAndBroadcastEip712({
21163
21207
  }
21164
21208
  }
21165
21209
  if (deliverResult.confirmed === void 0) {
21166
- return {
21210
+ throw new TxConfirmationUnavailableError({
21167
21211
  txHash,
21168
- code: result.tx_response.code,
21212
+ code: deliverResult.code,
21169
21213
  rawLog: deliverResult.rawLog ?? result.tx_response.raw_log,
21170
21214
  confirmed: void 0
21171
- };
21215
+ });
21216
+ }
21217
+ if (deliverResult.confirmed === false) {
21218
+ throw new TxNotConfirmedError({
21219
+ txHash,
21220
+ code: deliverResult.code,
21221
+ rawLog: deliverResult.rawLog,
21222
+ confirmed: false
21223
+ });
21224
+ }
21225
+ if (deliverResult.code !== 0) {
21226
+ throw new TxError({
21227
+ txHash,
21228
+ code: deliverResult.code,
21229
+ rawLog: deliverResult.rawLog,
21230
+ confirmed: true
21231
+ });
21172
21232
  }
21173
21233
  return {
21174
21234
  txHash,
21175
- code: deliverResult.code,
21235
+ code: 0,
21176
21236
  rawLog: deliverResult.rawLog,
21177
- confirmed: deliverResult.confirmed
21237
+ confirmed: true
21178
21238
  };
21179
21239
  }
21180
21240
 
@@ -22374,13 +22434,35 @@ function createStakingTxApi({ signerAddress, exec }) {
22374
22434
  if (validatorAddresses.length === 0) {
22375
22435
  throw new Error("validatorAddresses must include at least one validator address.");
22376
22436
  }
22377
- const msgs = validatorAddresses.map(
22378
- (validatorAddress) => msg.distribution.withdrawDelegatorReward({
22379
- delegatorAddress: signerAddress,
22380
- validatorAddress: assertValidatorAddress(validatorAddress)
22381
- })
22382
- );
22383
- return exec(msgs, { gasLimit, feeAmount, memo, confirmationTimeoutMs });
22437
+ const normalized = validatorAddresses.map(assertValidatorAddress);
22438
+ const results = [];
22439
+ const partial = [];
22440
+ for (let i = 0; i < normalized.length; i++) {
22441
+ const validatorAddress = normalized[i];
22442
+ try {
22443
+ const result = await exec(
22444
+ [
22445
+ msg.distribution.withdrawDelegatorReward({
22446
+ delegatorAddress: signerAddress,
22447
+ validatorAddress
22448
+ })
22449
+ ],
22450
+ { gasLimit, feeAmount, memo, confirmationTimeoutMs }
22451
+ );
22452
+ results.push(result);
22453
+ partial.push({ txHash: result.txHash, validatorAddress });
22454
+ } catch (error) {
22455
+ if (partial.length > 0) {
22456
+ throw new WithdrawRewardsPartialError({
22457
+ failedValidatorAddress: validatorAddress,
22458
+ partialResults: partial,
22459
+ cause: error instanceof Error ? error : new Error(String(error))
22460
+ });
22461
+ }
22462
+ throw error;
22463
+ }
22464
+ }
22465
+ return results;
22384
22466
  }
22385
22467
  };
22386
22468
  }
@@ -22493,10 +22575,10 @@ function createTxExecutor(options) {
22493
22575
  });
22494
22576
  return {
22495
22577
  txHash: result.txHash,
22496
- code: result.code,
22578
+ code: 0,
22497
22579
  rawLog: result.rawLog,
22498
- confirmed: result.confirmed,
22499
- success: result.code === 0 && result.confirmed === true
22580
+ confirmed: true,
22581
+ success: true
22500
22582
  };
22501
22583
  };
22502
22584
  }
@@ -22666,12 +22748,12 @@ async function signAndBroadcastAgentTx({
22666
22748
  );
22667
22749
  const txHash = normalizeTxHash(result.tx_response.txhash);
22668
22750
  if (result.tx_response.code !== 0) {
22669
- return {
22751
+ throw new TxError({
22670
22752
  txHash,
22671
22753
  code: result.tx_response.code,
22672
22754
  rawLog: result.tx_response.raw_log,
22673
22755
  confirmed: true
22674
- };
22756
+ });
22675
22757
  }
22676
22758
  const deliverResult = await pollTxInclusion(
22677
22759
  network,
@@ -22681,18 +22763,34 @@ async function signAndBroadcastAgentTx({
22681
22763
  confirmationTimeoutMs
22682
22764
  );
22683
22765
  if (deliverResult.confirmed === void 0) {
22684
- return {
22766
+ throw new TxConfirmationUnavailableError({
22685
22767
  txHash,
22686
- code: result.tx_response.code,
22768
+ code: deliverResult.code,
22687
22769
  rawLog: deliverResult.rawLog ?? result.tx_response.raw_log,
22688
22770
  confirmed: void 0
22689
- };
22771
+ });
22772
+ }
22773
+ if (deliverResult.confirmed === false) {
22774
+ throw new TxNotConfirmedError({
22775
+ txHash,
22776
+ code: deliverResult.code,
22777
+ rawLog: deliverResult.rawLog,
22778
+ confirmed: false
22779
+ });
22780
+ }
22781
+ if (deliverResult.code !== 0) {
22782
+ throw new TxError({
22783
+ txHash,
22784
+ code: deliverResult.code,
22785
+ rawLog: deliverResult.rawLog,
22786
+ confirmed: true
22787
+ });
22690
22788
  }
22691
22789
  return {
22692
22790
  txHash,
22693
- code: deliverResult.code,
22791
+ code: 0,
22694
22792
  rawLog: deliverResult.rawLog,
22695
- confirmed: deliverResult.confirmed
22793
+ confirmed: true
22696
22794
  };
22697
22795
  }
22698
22796
 
@@ -22725,10 +22823,10 @@ function createAgentTxExecutor(options) {
22725
22823
  });
22726
22824
  return {
22727
22825
  txHash: result.txHash,
22728
- code: result.code,
22826
+ code: 0,
22729
22827
  rawLog: result.rawLog,
22730
- confirmed: result.confirmed,
22731
- success: result.code === 0 && result.confirmed === true
22828
+ confirmed: true,
22829
+ success: true
22732
22830
  };
22733
22831
  };
22734
22832
  }
@@ -23454,7 +23552,7 @@ function createDexWs(url, options) {
23454
23552
  }
23455
23553
 
23456
23554
  // src/index.ts
23457
- var SDK_VERSION = "0.0.2-alpha.13";
23555
+ var SDK_VERSION = "0.0.2-alpha.14";
23458
23556
  export {
23459
23557
  AGENT_DEFAULTS,
23460
23558
  AULT_SIGNER_MARKER,
@@ -23532,8 +23630,12 @@ export {
23532
23630
  TIMING_CONSTANTS,
23533
23631
  TX_BASE_FIELDS,
23534
23632
  TimeoutError,
23633
+ TxConfirmationUnavailableError,
23634
+ TxError,
23635
+ TxNotConfirmedError,
23535
23636
  BondStatus as ValidatorStatus,
23536
23637
  WebSocketError,
23638
+ WithdrawRewardsPartialError,
23537
23639
  _resetIndexingCache,
23538
23640
  addressEquals,
23539
23641
  assertValidatorAddress,