@argonprotocol/mainchain 1.3.10 → 1.3.12

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/lib/index.cjs CHANGED
@@ -208,7 +208,12 @@ var TxResult = (_class = class {
208
208
  }
209
209
  }
210
210
  if (encounteredError) {
211
- const error = dispatchErrorToExtrinsicError(this.client, encounteredError, batchErrorIndex);
211
+ const error = dispatchErrorToExtrinsicError(
212
+ this.client,
213
+ encounteredError,
214
+ batchErrorIndex,
215
+ this.finalFee
216
+ );
212
217
  this.reject(error);
213
218
  } else {
214
219
  this.inBlockResolve(new Uint8Array(status.asInBlock));
@@ -281,11 +286,12 @@ function dispatchErrorToString(client, error) {
281
286
  return message;
282
287
  }
283
288
  var ExtrinsicError2 = class extends Error {
284
- constructor(errorCode, details, batchInterruptedIndex) {
289
+ constructor(errorCode, details, batchInterruptedIndex, txFee = 0n) {
285
290
  super(errorCode);
286
291
  this.errorCode = errorCode;
287
292
  this.details = details;
288
293
  this.batchInterruptedIndex = batchInterruptedIndex;
294
+ this.txFee = txFee;
289
295
  }
290
296
  toString() {
291
297
  if (this.batchInterruptedIndex !== void 0) {
@@ -294,13 +300,13 @@ var ExtrinsicError2 = class extends Error {
294
300
  return `${this.errorCode} ${_nullishCoalesce(this.details, () => ( ""))}`;
295
301
  }
296
302
  };
297
- function dispatchErrorToExtrinsicError(client, error, batchInterruptedIndex) {
303
+ function dispatchErrorToExtrinsicError(client, error, batchInterruptedIndex, txFee) {
298
304
  if (error.isModule) {
299
305
  const decoded = client.registry.findMetaError(error.asModule);
300
306
  const { docs, name, section } = decoded;
301
- return new ExtrinsicError2(`${section}.${name}`, docs.join(" "), batchInterruptedIndex);
307
+ return new ExtrinsicError2(`${section}.${name}`, docs.join(" "), batchInterruptedIndex, txFee);
302
308
  }
303
- return new ExtrinsicError2(error.toString(), void 0, batchInterruptedIndex);
309
+ return new ExtrinsicError2(error.toString(), void 0, batchInterruptedIndex, txFee);
304
310
  }
305
311
  function checkForExtrinsicSuccess(events, client) {
306
312
  return new Promise((resolve, reject) => {
@@ -844,12 +850,7 @@ var BitcoinLocks = class {
844
850
  unavailableBalance: securityFee + (_nullishCoalesce(args.reducedBalanceBy, () => ( 0n))),
845
851
  includeExistentialDeposit: true
846
852
  });
847
- if (!canAfford) {
848
- throw new Error(
849
- `Insufficient funds to initialize lock. Available: ${formatArgons(availableBalance)}, Required: ${satoshis}`
850
- );
851
- }
852
- return { tx, securityFee, txFee };
853
+ return { tx, securityFee, txFee, canAfford, availableBalance, txFeePlusTip: txFee + tip };
853
854
  }
854
855
  async getBitcoinLockFromTxResult(txResult) {
855
856
  const client = this.client;
@@ -868,7 +869,12 @@ var BitcoinLocks = class {
868
869
  async initializeLock(args) {
869
870
  const { argonKeyring, tip = 0n, txProgressCallback } = args;
870
871
  const client = this.client;
871
- const { tx, securityFee } = await this.createInitializeLockTx(args);
872
+ const { tx, securityFee, canAfford, txFeePlusTip } = await this.createInitializeLockTx(args);
873
+ if (!canAfford) {
874
+ throw new Error(
875
+ `Insufficient funds to initialize bitcoin lock. Required security fee: ${formatArgons(securityFee)}, Tx fee plus tip: ${formatArgons(txFeePlusTip)}`
876
+ );
877
+ }
872
878
  const submitter = new TxSubmitter(client, tx, argonKeyring);
873
879
  const txResult = await submitter.submit({
874
880
  waitForBlock: true,
@@ -895,7 +901,7 @@ var BitcoinLocks = class {
895
901
  priceIndex,
896
902
  releaseRequest: { bitcoinNetworkFee, toScriptPubkey },
897
903
  argonKeyring,
898
- tip,
904
+ tip = 0n,
899
905
  txProgressCallback
900
906
  } = args;
901
907
  if (!toScriptPubkey.startsWith("0x")) {
@@ -913,7 +919,7 @@ var BitcoinLocks = class {
913
919
  });
914
920
  if (!canAfford.canAfford) {
915
921
  throw new Error(
916
- `Insufficient funds to release lock. Available: ${formatArgons(canAfford.availableBalance)}, Required: ${formatArgons(redemptionPrice)}`
922
+ `Insufficient funds to release lock. Available: ${formatArgons(canAfford.availableBalance)}, Required: ${formatArgons(redemptionPrice + canAfford.txFee + tip)}`
917
923
  );
918
924
  }
919
925
  const txResult = await submitter.submit({