@fuel-ts/account 0.79.0 → 0.80.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.

Potentially problematic release.


This version of @fuel-ts/account might be problematic. Click here for more details.

@@ -25,9 +25,9 @@ import { hexlify as hexlify15 } from "@fuel-ts/utils";
25
25
  // src/account.ts
26
26
  import { Address as Address3 } from "@fuel-ts/address";
27
27
  import { BaseAssetId as BaseAssetId3 } from "@fuel-ts/address/configs";
28
- import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
28
+ import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
29
29
  import { AbstractAccount } from "@fuel-ts/interfaces";
30
- import { bn as bn16 } from "@fuel-ts/math";
30
+ import { bn as bn17 } from "@fuel-ts/math";
31
31
  import { arrayify as arrayify14 } from "@fuel-ts/utils";
32
32
 
33
33
  // src/providers/coin-quantity.ts
@@ -68,8 +68,8 @@ var addAmountToAsset = (params) => {
68
68
 
69
69
  // src/providers/provider.ts
70
70
  import { Address as Address2 } from "@fuel-ts/address";
71
- import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
72
- import { BN, bn as bn14, max } from "@fuel-ts/math";
71
+ import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
72
+ import { BN, bn as bn15, max } from "@fuel-ts/math";
73
73
  import {
74
74
  InputType as InputType6,
75
75
  TransactionType as TransactionType8,
@@ -1018,6 +1018,7 @@ var MemoryCache = class {
1018
1018
  };
1019
1019
 
1020
1020
  // src/providers/transaction-request/input.ts
1021
+ import { BYTES_32, UTXO_ID_LEN } from "@fuel-ts/abi-coder";
1021
1022
  import { ZeroBytes32 } from "@fuel-ts/address/configs";
1022
1023
  import { ErrorCode as ErrorCode3, FuelError as FuelError3 } from "@fuel-ts/errors";
1023
1024
  import { bn as bn2, toNumber } from "@fuel-ts/math";
@@ -1031,8 +1032,8 @@ var inputify = (value) => {
1031
1032
  const predicateData = arrayify(value.predicateData ?? "0x");
1032
1033
  return {
1033
1034
  type: InputType.Coin,
1034
- txID: hexlify3(arrayify(value.id).slice(0, 32)),
1035
- outputIndex: arrayify(value.id)[32],
1035
+ txID: hexlify3(arrayify(value.id).slice(0, BYTES_32)),
1036
+ outputIndex: toNumber(arrayify(value.id).slice(BYTES_32, UTXO_ID_LEN)),
1036
1037
  owner: hexlify3(value.owner),
1037
1038
  amount: bn2(value.amount),
1038
1039
  assetId: hexlify3(value.assetId),
@@ -1150,9 +1151,11 @@ var outputify = (value) => {
1150
1151
  };
1151
1152
 
1152
1153
  // src/providers/transaction-request/transaction-request.ts
1154
+ import { UTXO_ID_LEN as UTXO_ID_LEN2 } from "@fuel-ts/abi-coder";
1153
1155
  import { Address, addressify } from "@fuel-ts/address";
1154
1156
  import { BaseAssetId as BaseAssetId2, ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
1155
- import { bn as bn6 } from "@fuel-ts/math";
1157
+ import { randomBytes } from "@fuel-ts/crypto";
1158
+ import { bn as bn7 } from "@fuel-ts/math";
1156
1159
  import {
1157
1160
  PolicyType,
1158
1161
  TransactionCoder,
@@ -1495,6 +1498,86 @@ function sleep(time) {
1495
1498
  });
1496
1499
  }
1497
1500
 
1501
+ // src/providers/utils/extract-tx-error.ts
1502
+ import { ErrorCode as ErrorCode7, FuelError as FuelError7 } from "@fuel-ts/errors";
1503
+ import { bn as bn6 } from "@fuel-ts/math";
1504
+ import { ReceiptType as ReceiptType3 } from "@fuel-ts/transactions";
1505
+ import {
1506
+ FAILED_REQUIRE_SIGNAL,
1507
+ FAILED_ASSERT_EQ_SIGNAL,
1508
+ FAILED_ASSERT_NE_SIGNAL,
1509
+ FAILED_ASSERT_SIGNAL,
1510
+ FAILED_TRANSFER_TO_ADDRESS_SIGNAL as FAILED_TRANSFER_TO_ADDRESS_SIGNAL2,
1511
+ PANIC_REASONS,
1512
+ PANIC_DOC_URL
1513
+ } from "@fuel-ts/transactions/configs";
1514
+ var assemblePanicError = (status) => {
1515
+ let errorMessage = `The transaction reverted with reason: "${status.reason}".`;
1516
+ const reason = status.reason;
1517
+ if (PANIC_REASONS.includes(status.reason)) {
1518
+ errorMessage = `${errorMessage}
1519
+
1520
+ You can read more about this error at:
1521
+
1522
+ ${PANIC_DOC_URL}#variant.${status.reason}`;
1523
+ }
1524
+ return { errorMessage, reason };
1525
+ };
1526
+ var stringify = (obj) => JSON.stringify(obj, null, 2);
1527
+ var assembleRevertError = (receipts, logs) => {
1528
+ let errorMessage = "The transaction reverted with an unknown reason.";
1529
+ const revertReceipt = receipts.find(({ type }) => type === ReceiptType3.Revert);
1530
+ let reason = "";
1531
+ if (revertReceipt) {
1532
+ const reasonHex = bn6(revertReceipt.val).toHex();
1533
+ switch (reasonHex) {
1534
+ case FAILED_REQUIRE_SIGNAL: {
1535
+ reason = "require";
1536
+ errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(logs[0]) : "an error."}.`;
1537
+ break;
1538
+ }
1539
+ case FAILED_ASSERT_EQ_SIGNAL: {
1540
+ const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
1541
+ reason = "assert_eq";
1542
+ errorMessage = `The transaction reverted because of an "assert_eq" statement${sufix}`;
1543
+ break;
1544
+ }
1545
+ case FAILED_ASSERT_NE_SIGNAL: {
1546
+ const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
1547
+ reason = "assert_ne";
1548
+ errorMessage = `The transaction reverted because of an "assert_ne" statement${sufix}`;
1549
+ break;
1550
+ }
1551
+ case FAILED_ASSERT_SIGNAL:
1552
+ reason = "assert";
1553
+ errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
1554
+ break;
1555
+ case FAILED_TRANSFER_TO_ADDRESS_SIGNAL2:
1556
+ reason = "MissingOutputChange";
1557
+ errorMessage = `The transaction reverted because it's missing an "OutputChange".`;
1558
+ break;
1559
+ default:
1560
+ reason = "unknown";
1561
+ errorMessage = `The transaction reverted with an unknown reason: ${revertReceipt.val}`;
1562
+ }
1563
+ }
1564
+ return { errorMessage, reason };
1565
+ };
1566
+ var extractTxError = (params) => {
1567
+ const { receipts, status, logs } = params;
1568
+ const isPanic = receipts.some(({ type }) => type === ReceiptType3.Panic);
1569
+ const isRevert = receipts.some(({ type }) => type === ReceiptType3.Revert);
1570
+ const { errorMessage, reason } = status?.type === "FailureStatus" && isPanic ? assemblePanicError(status) : assembleRevertError(receipts, logs);
1571
+ const metadata = {
1572
+ logs,
1573
+ receipts,
1574
+ panic: isPanic,
1575
+ revert: isRevert,
1576
+ reason
1577
+ };
1578
+ return new FuelError7(ErrorCode7.SCRIPT_REVERTED, errorMessage, metadata);
1579
+ };
1580
+
1498
1581
  // src/providers/transaction-request/errors.ts
1499
1582
  var NoWitnessAtIndexError = class extends Error {
1500
1583
  constructor(index) {
@@ -1545,10 +1628,10 @@ var BaseTransactionRequest = class {
1545
1628
  outputs,
1546
1629
  witnesses
1547
1630
  } = {}) {
1548
- this.gasPrice = bn6(gasPrice);
1631
+ this.gasPrice = bn7(gasPrice);
1549
1632
  this.maturity = maturity ?? 0;
1550
- this.witnessLimit = witnessLimit ? bn6(witnessLimit) : void 0;
1551
- this.maxFee = maxFee ? bn6(maxFee) : void 0;
1633
+ this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
1634
+ this.maxFee = maxFee ? bn7(maxFee) : void 0;
1552
1635
  this.inputs = inputs ?? [];
1553
1636
  this.outputs = outputs ?? [];
1554
1637
  this.witnesses = witnesses ?? [];
@@ -1764,8 +1847,7 @@ var BaseTransactionRequest = class {
1764
1847
  assetId,
1765
1848
  txPointer: "0x00000000000000000000000000000000",
1766
1849
  witnessIndex,
1767
- predicate: predicate?.bytes,
1768
- predicateData: predicate?.predicateDataBytes
1850
+ predicate: predicate?.bytes
1769
1851
  };
1770
1852
  this.pushInput(input);
1771
1853
  this.addChangeOutput(owner, assetId);
@@ -1797,8 +1879,7 @@ var BaseTransactionRequest = class {
1797
1879
  recipient: recipient.toB256(),
1798
1880
  amount,
1799
1881
  witnessIndex,
1800
- predicate: predicate?.bytes,
1801
- predicateData: predicate?.predicateDataBytes
1882
+ predicate: predicate?.bytes
1802
1883
  };
1803
1884
  this.pushInput(input);
1804
1885
  this.addChangeOutput(recipient, assetId);
@@ -1953,12 +2034,6 @@ var BaseTransactionRequest = class {
1953
2034
  * @param quantities - CoinQuantity Array.
1954
2035
  */
1955
2036
  fundWithFakeUtxos(quantities, resourcesOwner) {
1956
- let idCounter = 0;
1957
- const generateId = () => {
1958
- const counterString = String(idCounter++);
1959
- const id = ZeroBytes324.slice(0, -counterString.length).concat(counterString);
1960
- return id;
1961
- };
1962
2037
  const findAssetInput = (assetId) => this.inputs.find((input) => {
1963
2038
  if ("assetId" in input) {
1964
2039
  return input.assetId === assetId;
@@ -1968,23 +2043,23 @@ var BaseTransactionRequest = class {
1968
2043
  const updateAssetInput = (assetId, quantity) => {
1969
2044
  const assetInput = findAssetInput(assetId);
1970
2045
  if (assetInput && "assetId" in assetInput) {
1971
- assetInput.id = generateId();
2046
+ assetInput.id = hexlify7(randomBytes(UTXO_ID_LEN2));
1972
2047
  assetInput.amount = quantity;
1973
2048
  } else {
1974
2049
  this.addResources([
1975
2050
  {
1976
- id: generateId(),
2051
+ id: hexlify7(randomBytes(UTXO_ID_LEN2)),
1977
2052
  amount: quantity,
1978
2053
  assetId,
1979
2054
  owner: resourcesOwner || Address.fromRandom(),
1980
2055
  maturity: 0,
1981
- blockCreated: bn6(1),
1982
- txCreatedIdx: bn6(1)
2056
+ blockCreated: bn7(1),
2057
+ txCreatedIdx: bn7(1)
1983
2058
  }
1984
2059
  ]);
1985
2060
  }
1986
2061
  };
1987
- updateAssetInput(BaseAssetId2, bn6(1e11));
2062
+ updateAssetInput(BaseAssetId2, bn7(1e11));
1988
2063
  quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
1989
2064
  }
1990
2065
  /**
@@ -1995,7 +2070,7 @@ var BaseTransactionRequest = class {
1995
2070
  */
1996
2071
  getCoinOutputsQuantities() {
1997
2072
  const coinsQuantities = this.getCoinOutputs().map(({ amount, assetId }) => ({
1998
- amount: bn6(amount),
2073
+ amount: bn7(amount),
1999
2074
  assetId: assetId.toString()
2000
2075
  }));
2001
2076
  return coinsQuantities;
@@ -2024,7 +2099,7 @@ var BaseTransactionRequest = class {
2024
2099
  default:
2025
2100
  return;
2026
2101
  }
2027
- if (correspondingInput && "predicateGasUsed" in correspondingInput && bn6(correspondingInput.predicateGasUsed).gt(0)) {
2102
+ if (correspondingInput && "predicateGasUsed" in correspondingInput && bn7(correspondingInput.predicateGasUsed).gt(0)) {
2028
2103
  i.predicate = correspondingInput.predicate;
2029
2104
  i.predicateData = correspondingInput.predicateData;
2030
2105
  i.predicateGasUsed = correspondingInput.predicateGasUsed;
@@ -2035,14 +2110,14 @@ var BaseTransactionRequest = class {
2035
2110
 
2036
2111
  // src/providers/transaction-request/create-transaction-request.ts
2037
2112
  import { ZeroBytes32 as ZeroBytes326 } from "@fuel-ts/address/configs";
2038
- import { bn as bn8 } from "@fuel-ts/math";
2113
+ import { bn as bn9 } from "@fuel-ts/math";
2039
2114
  import { TransactionType as TransactionType3, OutputType as OutputType4 } from "@fuel-ts/transactions";
2040
2115
  import { arrayify as arrayify6, hexlify as hexlify9 } from "@fuel-ts/utils";
2041
2116
 
2042
2117
  // src/providers/transaction-request/hash-transaction.ts
2043
2118
  import { ZeroBytes32 as ZeroBytes325 } from "@fuel-ts/address/configs";
2044
2119
  import { uint64ToBytesBE, sha256 } from "@fuel-ts/hasher";
2045
- import { bn as bn7 } from "@fuel-ts/math";
2120
+ import { bn as bn8 } from "@fuel-ts/math";
2046
2121
  import { TransactionType as TransactionType2, InputType as InputType3, OutputType as OutputType3, TransactionCoder as TransactionCoder2 } from "@fuel-ts/transactions";
2047
2122
  import { concat as concat2 } from "@fuel-ts/utils";
2048
2123
  import { clone as clone2 } from "ramda";
@@ -2059,11 +2134,11 @@ function hashTransaction(transactionRequest, chainId) {
2059
2134
  blockHeight: 0,
2060
2135
  txIndex: 0
2061
2136
  };
2062
- inputClone.predicateGasUsed = bn7(0);
2137
+ inputClone.predicateGasUsed = bn8(0);
2063
2138
  return inputClone;
2064
2139
  }
2065
2140
  case InputType3.Message: {
2066
- inputClone.predicateGasUsed = bn7(0);
2141
+ inputClone.predicateGasUsed = bn8(0);
2067
2142
  return inputClone;
2068
2143
  }
2069
2144
  case InputType3.Contract: {
@@ -2090,12 +2165,12 @@ function hashTransaction(transactionRequest, chainId) {
2090
2165
  return outputClone;
2091
2166
  }
2092
2167
  case OutputType3.Change: {
2093
- outputClone.amount = bn7(0);
2168
+ outputClone.amount = bn8(0);
2094
2169
  return outputClone;
2095
2170
  }
2096
2171
  case OutputType3.Variable: {
2097
2172
  outputClone.to = ZeroBytes325;
2098
- outputClone.amount = bn7(0);
2173
+ outputClone.amount = bn8(0);
2099
2174
  outputClone.assetId = ZeroBytes325;
2100
2175
  return outputClone;
2101
2176
  }
@@ -2219,7 +2294,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2219
2294
  }
2220
2295
  metadataGas(gasCosts) {
2221
2296
  return calculateMetadataGasForTxCreate({
2222
- contractBytesSize: bn8(arrayify6(this.witnesses[this.bytecodeWitnessIndex] || "0x").length),
2297
+ contractBytesSize: bn9(arrayify6(this.witnesses[this.bytecodeWitnessIndex] || "0x").length),
2223
2298
  gasCosts,
2224
2299
  stateRootSize: this.storageSlots.length,
2225
2300
  txBytesSize: this.byteSize()
@@ -2231,7 +2306,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2231
2306
  import { Interface } from "@fuel-ts/abi-coder";
2232
2307
  import { addressify as addressify2 } from "@fuel-ts/address";
2233
2308
  import { ZeroBytes32 as ZeroBytes327 } from "@fuel-ts/address/configs";
2234
- import { bn as bn9 } from "@fuel-ts/math";
2309
+ import { bn as bn10 } from "@fuel-ts/math";
2235
2310
  import { InputType as InputType4, OutputType as OutputType5, TransactionType as TransactionType4 } from "@fuel-ts/transactions";
2236
2311
  import { arrayify as arrayify8, hexlify as hexlify10 } from "@fuel-ts/utils";
2237
2312
 
@@ -2285,7 +2360,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2285
2360
  */
2286
2361
  constructor({ script, scriptData, gasLimit, ...rest } = {}) {
2287
2362
  super(rest);
2288
- this.gasLimit = bn9(gasLimit);
2363
+ this.gasLimit = bn10(gasLimit);
2289
2364
  this.script = arrayify8(script ?? returnZeroScript.bytes);
2290
2365
  this.scriptData = arrayify8(scriptData ?? returnZeroScript.encodeScriptData());
2291
2366
  this.abis = rest.abis;
@@ -2433,7 +2508,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2433
2508
  };
2434
2509
 
2435
2510
  // src/providers/transaction-request/utils.ts
2436
- import { ErrorCode as ErrorCode7, FuelError as FuelError7 } from "@fuel-ts/errors";
2511
+ import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
2437
2512
  import { TransactionType as TransactionType5 } from "@fuel-ts/transactions";
2438
2513
  var transactionRequestify = (obj) => {
2439
2514
  if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
@@ -2448,14 +2523,14 @@ var transactionRequestify = (obj) => {
2448
2523
  return CreateTransactionRequest.from(obj);
2449
2524
  }
2450
2525
  default: {
2451
- throw new FuelError7(ErrorCode7.INVALID_TRANSACTION_TYPE, `Invalid transaction type: ${type}.`);
2526
+ throw new FuelError8(ErrorCode8.INVALID_TRANSACTION_TYPE, `Invalid transaction type: ${type}.`);
2452
2527
  }
2453
2528
  }
2454
2529
  };
2455
2530
 
2456
2531
  // src/providers/transaction-response/transaction-response.ts
2457
- import { ErrorCode as ErrorCode11, FuelError as FuelError11 } from "@fuel-ts/errors";
2458
- import { bn as bn13 } from "@fuel-ts/math";
2532
+ import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
2533
+ import { bn as bn14 } from "@fuel-ts/math";
2459
2534
  import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
2460
2535
  import { arrayify as arrayify10 } from "@fuel-ts/utils";
2461
2536
 
@@ -2463,7 +2538,7 @@ import { arrayify as arrayify10 } from "@fuel-ts/utils";
2463
2538
  import { DateTime, hexlify as hexlify11 } from "@fuel-ts/utils";
2464
2539
 
2465
2540
  // src/providers/transaction-summary/calculate-transaction-fee.ts
2466
- import { bn as bn10 } from "@fuel-ts/math";
2541
+ import { bn as bn11 } from "@fuel-ts/math";
2467
2542
  import { PolicyType as PolicyType2, TransactionCoder as TransactionCoder3, TransactionType as TransactionType6 } from "@fuel-ts/transactions";
2468
2543
  import { arrayify as arrayify9 } from "@fuel-ts/utils";
2469
2544
  var calculateTransactionFee = (params) => {
@@ -2472,24 +2547,24 @@ var calculateTransactionFee = (params) => {
2472
2547
  rawPayload,
2473
2548
  consensusParameters: { gasCosts, feeParams }
2474
2549
  } = params;
2475
- const gasPerByte = bn10(feeParams.gasPerByte);
2476
- const gasPriceFactor = bn10(feeParams.gasPriceFactor);
2550
+ const gasPerByte = bn11(feeParams.gasPerByte);
2551
+ const gasPriceFactor = bn11(feeParams.gasPriceFactor);
2477
2552
  const transactionBytes = arrayify9(rawPayload);
2478
2553
  const [transaction] = new TransactionCoder3().decode(transactionBytes, 0);
2479
2554
  if (transaction.type === TransactionType6.Mint) {
2480
2555
  return {
2481
- fee: bn10(0),
2482
- minFee: bn10(0),
2483
- maxFee: bn10(0),
2484
- feeFromGasUsed: bn10(0)
2556
+ fee: bn11(0),
2557
+ minFee: bn11(0),
2558
+ maxFee: bn11(0),
2559
+ feeFromGasUsed: bn11(0)
2485
2560
  };
2486
2561
  }
2487
2562
  const { type, witnesses, inputs, policies } = transaction;
2488
- let metadataGas = bn10(0);
2489
- let gasLimit = bn10(0);
2563
+ let metadataGas = bn11(0);
2564
+ let gasLimit = bn11(0);
2490
2565
  if (type === TransactionType6.Create) {
2491
2566
  const { bytecodeWitnessIndex, storageSlots } = transaction;
2492
- const contractBytesSize = bn10(arrayify9(witnesses[bytecodeWitnessIndex].data).length);
2567
+ const contractBytesSize = bn11(arrayify9(witnesses[bytecodeWitnessIndex].data).length);
2493
2568
  metadataGas = calculateMetadataGasForTxCreate({
2494
2569
  contractBytesSize,
2495
2570
  gasCosts,
@@ -2508,12 +2583,12 @@ var calculateTransactionFee = (params) => {
2508
2583
  }
2509
2584
  const minGas = getMinGas({
2510
2585
  gasCosts,
2511
- gasPerByte: bn10(gasPerByte),
2586
+ gasPerByte: bn11(gasPerByte),
2512
2587
  inputs,
2513
2588
  metadataGas,
2514
2589
  txBytesSize: transactionBytes.length
2515
2590
  });
2516
- const gasPrice = bn10(policies.find((policy) => policy.type === PolicyType2.GasPrice)?.data);
2591
+ const gasPrice = bn11(policies.find((policy) => policy.type === PolicyType2.GasPrice)?.data);
2517
2592
  const witnessLimit = policies.find((policy) => policy.type === PolicyType2.WitnessLimit)?.data;
2518
2593
  const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
2519
2594
  const maxGas = getMaxGas({
@@ -2537,13 +2612,13 @@ var calculateTransactionFee = (params) => {
2537
2612
 
2538
2613
  // src/providers/transaction-summary/operations.ts
2539
2614
  import { ZeroBytes32 as ZeroBytes328 } from "@fuel-ts/address/configs";
2540
- import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
2541
- import { bn as bn12 } from "@fuel-ts/math";
2542
- import { ReceiptType as ReceiptType3, TransactionType as TransactionType7 } from "@fuel-ts/transactions";
2615
+ import { ErrorCode as ErrorCode10, FuelError as FuelError10 } from "@fuel-ts/errors";
2616
+ import { bn as bn13 } from "@fuel-ts/math";
2617
+ import { ReceiptType as ReceiptType4, TransactionType as TransactionType7 } from "@fuel-ts/transactions";
2543
2618
 
2544
2619
  // src/providers/transaction-summary/call.ts
2545
2620
  import { Interface as Interface2, calculateVmTxMemory } from "@fuel-ts/abi-coder";
2546
- import { bn as bn11 } from "@fuel-ts/math";
2621
+ import { bn as bn12 } from "@fuel-ts/math";
2547
2622
  var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
2548
2623
  const abiInterface = new Interface2(abi);
2549
2624
  const callFunctionSelector = receipt.param1.toHex(8);
@@ -2552,7 +2627,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
2552
2627
  let encodedArgs;
2553
2628
  if (functionFragment.isInputDataPointer) {
2554
2629
  if (rawPayload) {
2555
- const argsOffset = bn11(receipt.param2).sub(calculateVmTxMemory({ maxInputs: maxInputs.toNumber() })).toNumber();
2630
+ const argsOffset = bn12(receipt.param2).sub(calculateVmTxMemory({ maxInputs: maxInputs.toNumber() })).toNumber();
2556
2631
  encodedArgs = `0x${rawPayload.slice(2).slice(argsOffset * 2)}`;
2557
2632
  }
2558
2633
  } else {
@@ -2586,7 +2661,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
2586
2661
  };
2587
2662
 
2588
2663
  // src/providers/transaction-summary/input.ts
2589
- import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
2664
+ import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
2590
2665
  import { InputType as InputType5 } from "@fuel-ts/transactions";
2591
2666
  function getInputsByTypes(inputs, types) {
2592
2667
  return inputs.filter((i) => types.includes(i.type));
@@ -2624,8 +2699,8 @@ function getInputContractFromIndex(inputs, inputIndex) {
2624
2699
  return void 0;
2625
2700
  }
2626
2701
  if (contractInput.type !== InputType5.Contract) {
2627
- throw new FuelError8(
2628
- ErrorCode8.INVALID_TRANSACTION_INPUT,
2702
+ throw new FuelError9(
2703
+ ErrorCode9.INVALID_TRANSACTION_INPUT,
2629
2704
  `Contract input should be of type 'contract'.`
2630
2705
  );
2631
2706
  }
@@ -2672,8 +2747,8 @@ function getTransactionTypeName(transactionType) {
2672
2747
  case TransactionType7.Script:
2673
2748
  return "Script" /* Script */;
2674
2749
  default:
2675
- throw new FuelError9(
2676
- ErrorCode9.INVALID_TRANSACTION_TYPE,
2750
+ throw new FuelError10(
2751
+ ErrorCode10.INVALID_TRANSACTION_TYPE,
2677
2752
  `Invalid transaction type: ${transactionType}.`
2678
2753
  );
2679
2754
  }
@@ -2692,10 +2767,10 @@ function isTypeScript(transactionType) {
2692
2767
  return isType(transactionType, "Script" /* Script */);
2693
2768
  }
2694
2769
  function getReceiptsCall(receipts) {
2695
- return getReceiptsByType(receipts, ReceiptType3.Call);
2770
+ return getReceiptsByType(receipts, ReceiptType4.Call);
2696
2771
  }
2697
2772
  function getReceiptsMessageOut(receipts) {
2698
- return getReceiptsByType(receipts, ReceiptType3.MessageOut);
2773
+ return getReceiptsByType(receipts, ReceiptType4.MessageOut);
2699
2774
  }
2700
2775
  var mergeAssets = (op1, op2) => {
2701
2776
  const assets1 = op1.assetsSent || [];
@@ -2708,7 +2783,7 @@ var mergeAssets = (op1, op2) => {
2708
2783
  if (!matchingAsset) {
2709
2784
  return asset1;
2710
2785
  }
2711
- const mergedAmount = bn12(asset1.amount).add(matchingAsset.amount);
2786
+ const mergedAmount = bn13(asset1.amount).add(matchingAsset.amount);
2712
2787
  return { ...asset1, amount: mergedAmount };
2713
2788
  });
2714
2789
  return mergedAssets.concat(filteredAssets);
@@ -2891,11 +2966,11 @@ function getTransferOperations({
2891
2966
  });
2892
2967
  const transferReceipts = getReceiptsByType(
2893
2968
  receipts,
2894
- ReceiptType3.Transfer
2969
+ ReceiptType4.Transfer
2895
2970
  );
2896
2971
  const transferOutReceipts = getReceiptsByType(
2897
2972
  receipts,
2898
- ReceiptType3.TransferOut
2973
+ ReceiptType4.TransferOut
2899
2974
  );
2900
2975
  [...transferReceipts, ...transferOutReceipts].forEach((receipt) => {
2901
2976
  const operation = extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs);
@@ -2980,17 +3055,17 @@ function getOperations({
2980
3055
  }
2981
3056
 
2982
3057
  // src/providers/transaction-summary/receipt.ts
2983
- import { ReceiptType as ReceiptType4 } from "@fuel-ts/transactions";
3058
+ import { ReceiptType as ReceiptType5 } from "@fuel-ts/transactions";
2984
3059
  var processGqlReceipt = (gqlReceipt) => {
2985
3060
  const receipt = assembleReceiptByType(gqlReceipt);
2986
3061
  switch (receipt.type) {
2987
- case ReceiptType4.ReturnData: {
3062
+ case ReceiptType5.ReturnData: {
2988
3063
  return {
2989
3064
  ...receipt,
2990
3065
  data: gqlReceipt.data || "0x"
2991
3066
  };
2992
3067
  }
2993
- case ReceiptType4.LogData: {
3068
+ case ReceiptType5.LogData: {
2994
3069
  return {
2995
3070
  ...receipt,
2996
3071
  data: gqlReceipt.data || "0x"
@@ -3003,7 +3078,7 @@ var processGqlReceipt = (gqlReceipt) => {
3003
3078
  var extractMintedAssetsFromReceipts = (receipts) => {
3004
3079
  const mintedAssets = [];
3005
3080
  receipts.forEach((receipt) => {
3006
- if (receipt.type === ReceiptType4.Mint) {
3081
+ if (receipt.type === ReceiptType5.Mint) {
3007
3082
  mintedAssets.push({
3008
3083
  subId: receipt.subId,
3009
3084
  contractId: receipt.contractId,
@@ -3017,7 +3092,7 @@ var extractMintedAssetsFromReceipts = (receipts) => {
3017
3092
  var extractBurnedAssetsFromReceipts = (receipts) => {
3018
3093
  const burnedAssets = [];
3019
3094
  receipts.forEach((receipt) => {
3020
- if (receipt.type === ReceiptType4.Burn) {
3095
+ if (receipt.type === ReceiptType5.Burn) {
3021
3096
  burnedAssets.push({
3022
3097
  subId: receipt.subId,
3023
3098
  contractId: receipt.contractId,
@@ -3030,7 +3105,7 @@ var extractBurnedAssetsFromReceipts = (receipts) => {
3030
3105
  };
3031
3106
 
3032
3107
  // src/providers/transaction-summary/status.ts
3033
- import { ErrorCode as ErrorCode10, FuelError as FuelError10 } from "@fuel-ts/errors";
3108
+ import { ErrorCode as ErrorCode11, FuelError as FuelError11 } from "@fuel-ts/errors";
3034
3109
  var getTransactionStatusName = (gqlStatus) => {
3035
3110
  switch (gqlStatus) {
3036
3111
  case "FailureStatus":
@@ -3042,8 +3117,8 @@ var getTransactionStatusName = (gqlStatus) => {
3042
3117
  case "SqueezedOutStatus":
3043
3118
  return "squeezedout" /* squeezedout */;
3044
3119
  default:
3045
- throw new FuelError10(
3046
- ErrorCode10.INVALID_TRANSACTION_STATUS,
3120
+ throw new FuelError11(
3121
+ ErrorCode11.INVALID_TRANSACTION_STATUS,
3047
3122
  `Invalid transaction status: ${gqlStatus}.`
3048
3123
  );
3049
3124
  }
@@ -3156,12 +3231,12 @@ function assembleTransactionSummary(params) {
3156
3231
 
3157
3232
  // src/providers/transaction-response/getDecodedLogs.ts
3158
3233
  import { Interface as Interface3, BigNumberCoder } from "@fuel-ts/abi-coder";
3159
- import { ReceiptType as ReceiptType5 } from "@fuel-ts/transactions";
3234
+ import { ReceiptType as ReceiptType6 } from "@fuel-ts/transactions";
3160
3235
  function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
3161
3236
  return receipts.reduce((logs, receipt) => {
3162
- if (receipt.type === ReceiptType5.LogData || receipt.type === ReceiptType5.Log) {
3237
+ if (receipt.type === ReceiptType6.LogData || receipt.type === ReceiptType6.Log) {
3163
3238
  const interfaceToUse = new Interface3(externalAbis[receipt.id] || mainAbi);
3164
- const data = receipt.type === ReceiptType5.Log ? new BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
3239
+ const data = receipt.type === ReceiptType6.Log ? new BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
3165
3240
  const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
3166
3241
  logs.push(decodedLog);
3167
3242
  }
@@ -3176,7 +3251,7 @@ var TransactionResponse = class {
3176
3251
  /** Current provider */
3177
3252
  provider;
3178
3253
  /** Gas used on the transaction */
3179
- gasUsed = bn13(0);
3254
+ gasUsed = bn14(0);
3180
3255
  /** The graphql Transaction with receipts object. */
3181
3256
  gqlTransaction;
3182
3257
  abis;
@@ -3281,8 +3356,8 @@ var TransactionResponse = class {
3281
3356
  });
3282
3357
  for await (const { statusChange } of subscription) {
3283
3358
  if (statusChange.type === "SqueezedOutStatus") {
3284
- throw new FuelError11(
3285
- ErrorCode11.TRANSACTION_SQUEEZED_OUT,
3359
+ throw new FuelError12(
3360
+ ErrorCode12.TRANSACTION_SQUEEZED_OUT,
3286
3361
  `Transaction Squeezed Out with reason: ${statusChange.reason}`
3287
3362
  );
3288
3363
  }
@@ -3304,14 +3379,26 @@ var TransactionResponse = class {
3304
3379
  gqlTransaction: this.gqlTransaction,
3305
3380
  ...transactionSummary
3306
3381
  };
3382
+ let logs = [];
3307
3383
  if (this.abis) {
3308
- const logs = getDecodedLogs(
3384
+ logs = getDecodedLogs(
3309
3385
  transactionSummary.receipts,
3310
3386
  this.abis.main,
3311
3387
  this.abis.otherContractsAbis
3312
3388
  );
3313
3389
  transactionResult.logs = logs;
3314
3390
  }
3391
+ if (transactionResult.isStatusFailure) {
3392
+ const {
3393
+ receipts,
3394
+ gqlTransaction: { status }
3395
+ } = transactionResult;
3396
+ throw extractTxError({
3397
+ receipts,
3398
+ status,
3399
+ logs
3400
+ });
3401
+ }
3315
3402
  return transactionResult;
3316
3403
  }
3317
3404
  /**
@@ -3320,14 +3407,7 @@ var TransactionResponse = class {
3320
3407
  * @param contractsAbiMap - The contracts ABI map.
3321
3408
  */
3322
3409
  async wait(contractsAbiMap) {
3323
- const result = await this.waitForResult(contractsAbiMap);
3324
- if (result.isStatusFailure) {
3325
- throw new FuelError11(
3326
- ErrorCode11.TRANSACTION_FAILED,
3327
- `Transaction failed: ${result.gqlTransaction.status.reason}`
3328
- );
3329
- }
3330
- return result;
3410
+ return this.waitForResult(contractsAbiMap);
3331
3411
  }
3332
3412
  };
3333
3413
 
@@ -3389,29 +3469,29 @@ var processGqlChain = (chain) => {
3389
3469
  const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
3390
3470
  return {
3391
3471
  name,
3392
- baseChainHeight: bn14(daHeight),
3472
+ baseChainHeight: bn15(daHeight),
3393
3473
  consensusParameters: {
3394
- contractMaxSize: bn14(contractParams.contractMaxSize),
3395
- maxInputs: bn14(txParams.maxInputs),
3396
- maxOutputs: bn14(txParams.maxOutputs),
3397
- maxWitnesses: bn14(txParams.maxWitnesses),
3398
- maxGasPerTx: bn14(txParams.maxGasPerTx),
3399
- maxScriptLength: bn14(scriptParams.maxScriptLength),
3400
- maxScriptDataLength: bn14(scriptParams.maxScriptDataLength),
3401
- maxStorageSlots: bn14(contractParams.maxStorageSlots),
3402
- maxPredicateLength: bn14(predicateParams.maxPredicateLength),
3403
- maxPredicateDataLength: bn14(predicateParams.maxPredicateDataLength),
3404
- maxGasPerPredicate: bn14(predicateParams.maxGasPerPredicate),
3405
- gasPriceFactor: bn14(feeParams.gasPriceFactor),
3406
- gasPerByte: bn14(feeParams.gasPerByte),
3407
- maxMessageDataLength: bn14(predicateParams.maxMessageDataLength),
3408
- chainId: bn14(consensusParameters.chainId),
3474
+ contractMaxSize: bn15(contractParams.contractMaxSize),
3475
+ maxInputs: bn15(txParams.maxInputs),
3476
+ maxOutputs: bn15(txParams.maxOutputs),
3477
+ maxWitnesses: bn15(txParams.maxWitnesses),
3478
+ maxGasPerTx: bn15(txParams.maxGasPerTx),
3479
+ maxScriptLength: bn15(scriptParams.maxScriptLength),
3480
+ maxScriptDataLength: bn15(scriptParams.maxScriptDataLength),
3481
+ maxStorageSlots: bn15(contractParams.maxStorageSlots),
3482
+ maxPredicateLength: bn15(predicateParams.maxPredicateLength),
3483
+ maxPredicateDataLength: bn15(predicateParams.maxPredicateDataLength),
3484
+ maxGasPerPredicate: bn15(predicateParams.maxGasPerPredicate),
3485
+ gasPriceFactor: bn15(feeParams.gasPriceFactor),
3486
+ gasPerByte: bn15(feeParams.gasPerByte),
3487
+ maxMessageDataLength: bn15(predicateParams.maxMessageDataLength),
3488
+ chainId: bn15(consensusParameters.chainId),
3409
3489
  gasCosts
3410
3490
  },
3411
3491
  gasCosts,
3412
3492
  latestBlock: {
3413
3493
  id: latestBlock.id,
3414
- height: bn14(latestBlock.header.height),
3494
+ height: bn15(latestBlock.header.height),
3415
3495
  time: latestBlock.header.time,
3416
3496
  transactions: latestBlock.transactions.map((i) => ({
3417
3497
  id: i.id
@@ -3481,8 +3561,8 @@ var _Provider = class {
3481
3561
  getChain() {
3482
3562
  const chain = _Provider.chainInfoCache[this.url];
3483
3563
  if (!chain) {
3484
- throw new FuelError12(
3485
- ErrorCode12.CHAIN_INFO_CACHE_EMPTY,
3564
+ throw new FuelError13(
3565
+ ErrorCode13.CHAIN_INFO_CACHE_EMPTY,
3486
3566
  "Chain info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
3487
3567
  );
3488
3568
  }
@@ -3494,8 +3574,8 @@ var _Provider = class {
3494
3574
  getNode() {
3495
3575
  const node = _Provider.nodeInfoCache[this.url];
3496
3576
  if (!node) {
3497
- throw new FuelError12(
3498
- ErrorCode12.NODE_INFO_CACHE_EMPTY,
3577
+ throw new FuelError13(
3578
+ ErrorCode13.NODE_INFO_CACHE_EMPTY,
3499
3579
  "Node info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
3500
3580
  );
3501
3581
  }
@@ -3542,8 +3622,8 @@ var _Provider = class {
3542
3622
  static ensureClientVersionIsSupported(nodeInfo) {
3543
3623
  const { isMajorSupported, isMinorSupported, supportedVersion } = checkFuelCoreVersionCompatibility(nodeInfo.nodeVersion);
3544
3624
  if (!isMajorSupported || !isMinorSupported) {
3545
- throw new FuelError12(
3546
- FuelError12.CODES.UNSUPPORTED_FUEL_CLIENT_VERSION,
3625
+ throw new FuelError13(
3626
+ FuelError13.CODES.UNSUPPORTED_FUEL_CLIENT_VERSION,
3547
3627
  `Fuel client version: ${nodeInfo.nodeVersion}, Supported version: ${supportedVersion}`
3548
3628
  );
3549
3629
  }
@@ -3606,7 +3686,7 @@ var _Provider = class {
3606
3686
  */
3607
3687
  async getBlockNumber() {
3608
3688
  const { chain } = await this.operations.getChain();
3609
- return bn14(chain.latestBlock.header.height, 10);
3689
+ return bn15(chain.latestBlock.header.height, 10);
3610
3690
  }
3611
3691
  /**
3612
3692
  * Returns the chain information.
@@ -3616,9 +3696,9 @@ var _Provider = class {
3616
3696
  async fetchNode() {
3617
3697
  const { nodeInfo } = await this.operations.getNodeInfo();
3618
3698
  const processedNodeInfo = {
3619
- maxDepth: bn14(nodeInfo.maxDepth),
3620
- maxTx: bn14(nodeInfo.maxTx),
3621
- minGasPrice: bn14(nodeInfo.minGasPrice),
3699
+ maxDepth: bn15(nodeInfo.maxDepth),
3700
+ maxTx: bn15(nodeInfo.maxTx),
3701
+ minGasPrice: bn15(nodeInfo.minGasPrice),
3622
3702
  nodeVersion: nodeInfo.nodeVersion,
3623
3703
  utxoValidation: nodeInfo.utxoValidation,
3624
3704
  vmBacktrace: nodeInfo.vmBacktrace,
@@ -3673,8 +3753,8 @@ var _Provider = class {
3673
3753
  const subscription = this.operations.submitAndAwait({ encodedTransaction });
3674
3754
  for await (const { submitAndAwait } of subscription) {
3675
3755
  if (submitAndAwait.type === "SqueezedOutStatus") {
3676
- throw new FuelError12(
3677
- ErrorCode12.TRANSACTION_SQUEEZED_OUT,
3756
+ throw new FuelError13(
3757
+ ErrorCode13.TRANSACTION_SQUEEZED_OUT,
3678
3758
  `Transaction Squeezed Out with reason: ${submitAndAwait.reason}`
3679
3759
  );
3680
3760
  }
@@ -3741,7 +3821,7 @@ var _Provider = class {
3741
3821
  } = response;
3742
3822
  if (inputs) {
3743
3823
  inputs.forEach((input, index) => {
3744
- if ("predicateGasUsed" in input && bn14(input.predicateGasUsed).gt(0)) {
3824
+ if ("predicateGasUsed" in input && bn15(input.predicateGasUsed).gt(0)) {
3745
3825
  transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
3746
3826
  }
3747
3827
  });
@@ -3798,6 +3878,36 @@ var _Provider = class {
3798
3878
  missingContractIds
3799
3879
  };
3800
3880
  }
3881
+ /**
3882
+ * Estimates the transaction gas and fee based on the provided transaction request.
3883
+ * @param transactionRequest - The transaction request object.
3884
+ * @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
3885
+ */
3886
+ estimateTxGasAndFee(params) {
3887
+ const { transactionRequest } = params;
3888
+ const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
3889
+ const chainInfo = this.getChain();
3890
+ const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
3891
+ transactionRequest.gasPrice = gasPrice;
3892
+ const minGas = transactionRequest.calculateMinGas(chainInfo);
3893
+ const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
3894
+ if (transactionRequest.type === TransactionType8.Script) {
3895
+ if (transactionRequest.gasLimit.eq(0)) {
3896
+ transactionRequest.gasLimit = minGas;
3897
+ transactionRequest.gasLimit = maxGasPerTx.sub(
3898
+ transactionRequest.calculateMaxGas(chainInfo, minGas)
3899
+ );
3900
+ }
3901
+ }
3902
+ const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
3903
+ const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
3904
+ return {
3905
+ minGas,
3906
+ minFee,
3907
+ maxGas,
3908
+ maxFee
3909
+ };
3910
+ }
3801
3911
  /**
3802
3912
  * Executes a signed transaction without applying the states changes
3803
3913
  * on the chain.
@@ -3845,17 +3955,16 @@ var _Provider = class {
3845
3955
  signatureCallback
3846
3956
  } = {}) {
3847
3957
  const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
3848
- const chainInfo = this.getChain();
3849
- const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
3850
- const gasPrice = max(txRequestClone.gasPrice, minGasPrice);
3958
+ const { minGasPrice } = this.getGasConfig();
3959
+ const setGasPrice = max(txRequestClone.gasPrice, minGasPrice);
3851
3960
  const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
3852
3961
  const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
3853
3962
  const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
3854
3963
  txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
3964
+ if (isScriptTransaction) {
3965
+ txRequestClone.gasLimit = bn15(0);
3966
+ }
3855
3967
  if (estimatePredicates) {
3856
- if (isScriptTransaction) {
3857
- txRequestClone.gasLimit = bn14(0);
3858
- }
3859
3968
  if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
3860
3969
  resourcesOwner.populateTransactionPredicateData(txRequestClone);
3861
3970
  }
@@ -3864,36 +3973,34 @@ var _Provider = class {
3864
3973
  if (signatureCallback && isScriptTransaction) {
3865
3974
  await signatureCallback(txRequestClone);
3866
3975
  }
3867
- const minGas = txRequestClone.calculateMinGas(chainInfo);
3868
- const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
3976
+ let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
3977
+ transactionRequest: txRequestClone
3978
+ });
3869
3979
  let receipts = [];
3870
3980
  let missingContractIds = [];
3871
3981
  let outputVariables = 0;
3982
+ let gasUsed = bn15(0);
3872
3983
  if (isScriptTransaction && estimateTxDependencies) {
3873
- txRequestClone.gasPrice = bn14(0);
3874
- txRequestClone.gasLimit = bn14(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
3984
+ txRequestClone.gasPrice = bn15(0);
3875
3985
  const result = await this.estimateTxDependencies(txRequestClone);
3876
3986
  receipts = result.receipts;
3877
3987
  outputVariables = result.outputVariables;
3878
3988
  missingContractIds = result.missingContractIds;
3989
+ gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
3990
+ txRequestClone.gasLimit = gasUsed;
3991
+ txRequestClone.gasPrice = setGasPrice;
3992
+ ({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
3993
+ transactionRequest: txRequestClone
3994
+ }));
3879
3995
  }
3880
- const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
3881
- const usedFee = calculatePriceWithFactor(
3882
- gasUsed,
3883
- gasPrice,
3884
- gasPriceFactor
3885
- ).normalizeZeroToOne();
3886
- const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
3887
- const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
3888
3996
  return {
3889
3997
  requiredQuantities: allQuantities,
3890
3998
  receipts,
3891
3999
  gasUsed,
3892
4000
  minGasPrice,
3893
- gasPrice,
4001
+ gasPrice: setGasPrice,
3894
4002
  minGas,
3895
4003
  maxGas,
3896
- usedFee,
3897
4004
  minFee,
3898
4005
  maxFee,
3899
4006
  estimatedInputs: txRequestClone.inputs,
@@ -3933,11 +4040,11 @@ var _Provider = class {
3933
4040
  return coins.map((coin) => ({
3934
4041
  id: coin.utxoId,
3935
4042
  assetId: coin.assetId,
3936
- amount: bn14(coin.amount),
4043
+ amount: bn15(coin.amount),
3937
4044
  owner: Address2.fromAddressOrString(coin.owner),
3938
- maturity: bn14(coin.maturity).toNumber(),
3939
- blockCreated: bn14(coin.blockCreated),
3940
- txCreatedIdx: bn14(coin.txCreatedIdx)
4045
+ maturity: bn15(coin.maturity).toNumber(),
4046
+ blockCreated: bn15(coin.blockCreated),
4047
+ txCreatedIdx: bn15(coin.txCreatedIdx)
3941
4048
  }));
3942
4049
  }
3943
4050
  /**
@@ -3974,9 +4081,9 @@ var _Provider = class {
3974
4081
  switch (coin.__typename) {
3975
4082
  case "MessageCoin":
3976
4083
  return {
3977
- amount: bn14(coin.amount),
4084
+ amount: bn15(coin.amount),
3978
4085
  assetId: coin.assetId,
3979
- daHeight: bn14(coin.daHeight),
4086
+ daHeight: bn15(coin.daHeight),
3980
4087
  sender: Address2.fromAddressOrString(coin.sender),
3981
4088
  recipient: Address2.fromAddressOrString(coin.recipient),
3982
4089
  nonce: coin.nonce
@@ -3984,12 +4091,12 @@ var _Provider = class {
3984
4091
  case "Coin":
3985
4092
  return {
3986
4093
  id: coin.utxoId,
3987
- amount: bn14(coin.amount),
4094
+ amount: bn15(coin.amount),
3988
4095
  assetId: coin.assetId,
3989
4096
  owner: Address2.fromAddressOrString(coin.owner),
3990
- maturity: bn14(coin.maturity).toNumber(),
3991
- blockCreated: bn14(coin.blockCreated),
3992
- txCreatedIdx: bn14(coin.txCreatedIdx)
4097
+ maturity: bn15(coin.maturity).toNumber(),
4098
+ blockCreated: bn15(coin.blockCreated),
4099
+ txCreatedIdx: bn15(coin.txCreatedIdx)
3993
4100
  };
3994
4101
  default:
3995
4102
  return null;
@@ -4006,13 +4113,13 @@ var _Provider = class {
4006
4113
  async getBlock(idOrHeight) {
4007
4114
  let variables;
4008
4115
  if (typeof idOrHeight === "number") {
4009
- variables = { height: bn14(idOrHeight).toString(10) };
4116
+ variables = { height: bn15(idOrHeight).toString(10) };
4010
4117
  } else if (idOrHeight === "latest") {
4011
4118
  variables = { height: (await this.getBlockNumber()).toString(10) };
4012
4119
  } else if (idOrHeight.length === 66) {
4013
4120
  variables = { blockId: idOrHeight };
4014
4121
  } else {
4015
- variables = { blockId: bn14(idOrHeight).toString(10) };
4122
+ variables = { blockId: bn15(idOrHeight).toString(10) };
4016
4123
  }
4017
4124
  const { block } = await this.operations.getBlock(variables);
4018
4125
  if (!block) {
@@ -4020,7 +4127,7 @@ var _Provider = class {
4020
4127
  }
4021
4128
  return {
4022
4129
  id: block.id,
4023
- height: bn14(block.header.height),
4130
+ height: bn15(block.header.height),
4024
4131
  time: block.header.time,
4025
4132
  transactionIds: block.transactions.map((tx) => tx.id)
4026
4133
  };
@@ -4035,7 +4142,7 @@ var _Provider = class {
4035
4142
  const { blocks: fetchedData } = await this.operations.getBlocks(params);
4036
4143
  const blocks = fetchedData.edges.map(({ node: block }) => ({
4037
4144
  id: block.id,
4038
- height: bn14(block.header.height),
4145
+ height: bn15(block.header.height),
4039
4146
  time: block.header.time,
4040
4147
  transactionIds: block.transactions.map((tx) => tx.id)
4041
4148
  }));
@@ -4050,7 +4157,7 @@ var _Provider = class {
4050
4157
  async getBlockWithTransactions(idOrHeight) {
4051
4158
  let variables;
4052
4159
  if (typeof idOrHeight === "number") {
4053
- variables = { blockHeight: bn14(idOrHeight).toString(10) };
4160
+ variables = { blockHeight: bn15(idOrHeight).toString(10) };
4054
4161
  } else if (idOrHeight === "latest") {
4055
4162
  variables = { blockHeight: (await this.getBlockNumber()).toString() };
4056
4163
  } else {
@@ -4062,7 +4169,7 @@ var _Provider = class {
4062
4169
  }
4063
4170
  return {
4064
4171
  id: block.id,
4065
- height: bn14(block.header.height, 10),
4172
+ height: bn15(block.header.height, 10),
4066
4173
  time: block.header.time,
4067
4174
  transactionIds: block.transactions.map((tx) => tx.id),
4068
4175
  transactions: block.transactions.map(
@@ -4111,7 +4218,7 @@ var _Provider = class {
4111
4218
  contract: Address2.fromAddressOrString(contractId).toB256(),
4112
4219
  asset: hexlify12(assetId)
4113
4220
  });
4114
- return bn14(contractBalance.amount, 10);
4221
+ return bn15(contractBalance.amount, 10);
4115
4222
  }
4116
4223
  /**
4117
4224
  * Returns the balance for the given owner for the given asset ID.
@@ -4125,7 +4232,7 @@ var _Provider = class {
4125
4232
  owner: Address2.fromAddressOrString(owner).toB256(),
4126
4233
  assetId: hexlify12(assetId)
4127
4234
  });
4128
- return bn14(balance.amount, 10);
4235
+ return bn15(balance.amount, 10);
4129
4236
  }
4130
4237
  /**
4131
4238
  * Returns balances for the given owner.
@@ -4143,7 +4250,7 @@ var _Provider = class {
4143
4250
  const balances = result.balances.edges.map((edge) => edge.node);
4144
4251
  return balances.map((balance) => ({
4145
4252
  assetId: balance.assetId,
4146
- amount: bn14(balance.amount)
4253
+ amount: bn15(balance.amount)
4147
4254
  }));
4148
4255
  }
4149
4256
  /**
@@ -4165,15 +4272,15 @@ var _Provider = class {
4165
4272
  sender: message.sender,
4166
4273
  recipient: message.recipient,
4167
4274
  nonce: message.nonce,
4168
- amount: bn14(message.amount),
4275
+ amount: bn15(message.amount),
4169
4276
  data: message.data
4170
4277
  }),
4171
4278
  sender: Address2.fromAddressOrString(message.sender),
4172
4279
  recipient: Address2.fromAddressOrString(message.recipient),
4173
4280
  nonce: message.nonce,
4174
- amount: bn14(message.amount),
4281
+ amount: bn15(message.amount),
4175
4282
  data: InputMessageCoder.decodeData(message.data),
4176
- daHeight: bn14(message.daHeight)
4283
+ daHeight: bn15(message.daHeight)
4177
4284
  }));
4178
4285
  }
4179
4286
  /**
@@ -4191,8 +4298,8 @@ var _Provider = class {
4191
4298
  nonce
4192
4299
  };
4193
4300
  if (commitBlockId && commitBlockHeight) {
4194
- throw new FuelError12(
4195
- ErrorCode12.INVALID_INPUT_PARAMETERS,
4301
+ throw new FuelError13(
4302
+ ErrorCode13.INVALID_INPUT_PARAMETERS,
4196
4303
  "commitBlockId and commitBlockHeight cannot be used together"
4197
4304
  );
4198
4305
  }
@@ -4226,41 +4333,41 @@ var _Provider = class {
4226
4333
  } = result.messageProof;
4227
4334
  return {
4228
4335
  messageProof: {
4229
- proofIndex: bn14(messageProof.proofIndex),
4336
+ proofIndex: bn15(messageProof.proofIndex),
4230
4337
  proofSet: messageProof.proofSet
4231
4338
  },
4232
4339
  blockProof: {
4233
- proofIndex: bn14(blockProof.proofIndex),
4340
+ proofIndex: bn15(blockProof.proofIndex),
4234
4341
  proofSet: blockProof.proofSet
4235
4342
  },
4236
4343
  messageBlockHeader: {
4237
4344
  id: messageBlockHeader.id,
4238
- daHeight: bn14(messageBlockHeader.daHeight),
4239
- transactionsCount: bn14(messageBlockHeader.transactionsCount),
4345
+ daHeight: bn15(messageBlockHeader.daHeight),
4346
+ transactionsCount: bn15(messageBlockHeader.transactionsCount),
4240
4347
  transactionsRoot: messageBlockHeader.transactionsRoot,
4241
- height: bn14(messageBlockHeader.height),
4348
+ height: bn15(messageBlockHeader.height),
4242
4349
  prevRoot: messageBlockHeader.prevRoot,
4243
4350
  time: messageBlockHeader.time,
4244
4351
  applicationHash: messageBlockHeader.applicationHash,
4245
4352
  messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
4246
- messageReceiptCount: bn14(messageBlockHeader.messageReceiptCount)
4353
+ messageReceiptCount: bn15(messageBlockHeader.messageReceiptCount)
4247
4354
  },
4248
4355
  commitBlockHeader: {
4249
4356
  id: commitBlockHeader.id,
4250
- daHeight: bn14(commitBlockHeader.daHeight),
4251
- transactionsCount: bn14(commitBlockHeader.transactionsCount),
4357
+ daHeight: bn15(commitBlockHeader.daHeight),
4358
+ transactionsCount: bn15(commitBlockHeader.transactionsCount),
4252
4359
  transactionsRoot: commitBlockHeader.transactionsRoot,
4253
- height: bn14(commitBlockHeader.height),
4360
+ height: bn15(commitBlockHeader.height),
4254
4361
  prevRoot: commitBlockHeader.prevRoot,
4255
4362
  time: commitBlockHeader.time,
4256
4363
  applicationHash: commitBlockHeader.applicationHash,
4257
4364
  messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
4258
- messageReceiptCount: bn14(commitBlockHeader.messageReceiptCount)
4365
+ messageReceiptCount: bn15(commitBlockHeader.messageReceiptCount)
4259
4366
  },
4260
4367
  sender: Address2.fromAddressOrString(sender),
4261
4368
  recipient: Address2.fromAddressOrString(recipient),
4262
4369
  nonce,
4263
- amount: bn14(amount),
4370
+ amount: bn15(amount),
4264
4371
  data
4265
4372
  };
4266
4373
  }
@@ -4283,10 +4390,10 @@ var _Provider = class {
4283
4390
  */
4284
4391
  async produceBlocks(amount, startTime) {
4285
4392
  const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
4286
- blocksToProduce: bn14(amount).toString(10),
4393
+ blocksToProduce: bn15(amount).toString(10),
4287
4394
  startTimestamp: startTime ? DateTime2.fromUnixMilliseconds(startTime).toTai64() : void 0
4288
4395
  });
4289
- return bn14(latestBlockHeight);
4396
+ return bn15(latestBlockHeight);
4290
4397
  }
4291
4398
  // eslint-disable-next-line @typescript-eslint/require-await
4292
4399
  async getTransactionResponse(transactionId) {
@@ -4309,8 +4416,8 @@ __publicField(Provider, "chainInfoCache", {});
4309
4416
  __publicField(Provider, "nodeInfoCache", {});
4310
4417
 
4311
4418
  // src/providers/transaction-summary/get-transaction-summary.ts
4312
- import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
4313
- import { bn as bn15 } from "@fuel-ts/math";
4419
+ import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
4420
+ import { bn as bn16 } from "@fuel-ts/math";
4314
4421
  import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
4315
4422
  import { arrayify as arrayify12 } from "@fuel-ts/utils";
4316
4423
 
@@ -4427,7 +4534,7 @@ var Account = class extends AbstractAccount {
4427
4534
  */
4428
4535
  get provider() {
4429
4536
  if (!this._provider) {
4430
- throw new FuelError14(ErrorCode14.MISSING_PROVIDER, "Provider not set");
4537
+ throw new FuelError15(ErrorCode15.MISSING_PROVIDER, "Provider not set");
4431
4538
  }
4432
4539
  return this._provider;
4433
4540
  }
@@ -4479,8 +4586,8 @@ var Account = class extends AbstractAccount {
4479
4586
  if (!hasNextPage) {
4480
4587
  break;
4481
4588
  }
4482
- throw new FuelError14(
4483
- ErrorCode14.NOT_SUPPORTED,
4589
+ throw new FuelError15(
4590
+ ErrorCode15.NOT_SUPPORTED,
4484
4591
  `Wallets containing more than ${pageSize} coins exceed the current supported limit.`
4485
4592
  );
4486
4593
  }
@@ -4505,8 +4612,8 @@ var Account = class extends AbstractAccount {
4505
4612
  if (!hasNextPage) {
4506
4613
  break;
4507
4614
  }
4508
- throw new FuelError14(
4509
- ErrorCode14.NOT_SUPPORTED,
4615
+ throw new FuelError15(
4616
+ ErrorCode15.NOT_SUPPORTED,
4510
4617
  `Wallets containing more than ${pageSize} messages exceed the current supported limit.`
4511
4618
  );
4512
4619
  }
@@ -4541,8 +4648,8 @@ var Account = class extends AbstractAccount {
4541
4648
  if (!hasNextPage) {
4542
4649
  break;
4543
4650
  }
4544
- throw new FuelError14(
4545
- ErrorCode14.NOT_SUPPORTED,
4651
+ throw new FuelError15(
4652
+ ErrorCode15.NOT_SUPPORTED,
4546
4653
  `Wallets containing more than ${pageSize} balances exceed the current supported limit.`
4547
4654
  );
4548
4655
  }
@@ -4558,7 +4665,7 @@ var Account = class extends AbstractAccount {
4558
4665
  */
4559
4666
  async fund(request, coinQuantities, fee) {
4560
4667
  const updatedQuantities = addAmountToAsset({
4561
- amount: bn16(fee),
4668
+ amount: bn17(fee),
4562
4669
  assetId: BaseAssetId3,
4563
4670
  coinQuantities
4564
4671
  });
@@ -4566,7 +4673,7 @@ var Account = class extends AbstractAccount {
4566
4673
  updatedQuantities.forEach(({ amount, assetId }) => {
4567
4674
  quantitiesDict[assetId] = {
4568
4675
  required: amount,
4569
- owned: bn16(0)
4676
+ owned: bn17(0)
4570
4677
  };
4571
4678
  });
4572
4679
  const cachedUtxos = [];
@@ -4579,7 +4686,7 @@ var Account = class extends AbstractAccount {
4579
4686
  if (isCoin2) {
4580
4687
  const assetId = String(input.assetId);
4581
4688
  if (input.owner === owner && quantitiesDict[assetId]) {
4582
- const amount = bn16(input.amount);
4689
+ const amount = bn17(input.amount);
4583
4690
  quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
4584
4691
  cachedUtxos.push(input.id);
4585
4692
  }
@@ -4625,8 +4732,8 @@ var Account = class extends AbstractAccount {
4625
4732
  estimateTxDependencies: true,
4626
4733
  resourcesOwner: this
4627
4734
  });
4628
- request.gasPrice = bn16(txParams.gasPrice ?? minGasPrice);
4629
- request.gasLimit = bn16(txParams.gasLimit ?? gasUsed);
4735
+ request.gasPrice = bn17(txParams.gasPrice ?? minGasPrice);
4736
+ request.gasLimit = bn17(txParams.gasLimit ?? gasUsed);
4630
4737
  this.validateGas({
4631
4738
  gasUsed,
4632
4739
  gasPrice: request.gasPrice,
@@ -4647,9 +4754,9 @@ var Account = class extends AbstractAccount {
4647
4754
  * @returns A promise that resolves to the transaction response.
4648
4755
  */
4649
4756
  async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
4650
- if (bn16(amount).lte(0)) {
4651
- throw new FuelError14(
4652
- ErrorCode14.INVALID_TRANSFER_AMOUNT,
4757
+ if (bn17(amount).lte(0)) {
4758
+ throw new FuelError15(
4759
+ ErrorCode15.INVALID_TRANSFER_AMOUNT,
4653
4760
  "Transfer amount must be a positive number."
4654
4761
  );
4655
4762
  }
@@ -4666,9 +4773,9 @@ var Account = class extends AbstractAccount {
4666
4773
  * @returns A promise that resolves to the transaction response.
4667
4774
  */
4668
4775
  async transferToContract(contractId, amount, assetId = BaseAssetId3, txParams = {}) {
4669
- if (bn16(amount).lte(0)) {
4670
- throw new FuelError14(
4671
- ErrorCode14.INVALID_TRANSFER_AMOUNT,
4776
+ if (bn17(amount).lte(0)) {
4777
+ throw new FuelError15(
4778
+ ErrorCode15.INVALID_TRANSFER_AMOUNT,
4672
4779
  "Transfer amount must be a positive number."
4673
4780
  );
4674
4781
  }
@@ -4677,7 +4784,7 @@ var Account = class extends AbstractAccount {
4677
4784
  const params = { gasPrice: minGasPrice, ...txParams };
4678
4785
  const { script, scriptData } = await assembleTransferToContractScript({
4679
4786
  hexlifiedContractId: contractAddress.toB256(),
4680
- amountToTransfer: bn16(amount),
4787
+ amountToTransfer: bn17(amount),
4681
4788
  assetId
4682
4789
  });
4683
4790
  const request = new ScriptTransactionRequest({
@@ -4688,9 +4795,9 @@ var Account = class extends AbstractAccount {
4688
4795
  request.addContractInputAndOutput(contractAddress);
4689
4796
  const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
4690
4797
  request,
4691
- [{ amount: bn16(amount), assetId: String(assetId) }]
4798
+ [{ amount: bn17(amount), assetId: String(assetId) }]
4692
4799
  );
4693
- request.gasLimit = bn16(params.gasLimit ?? gasUsed);
4800
+ request.gasLimit = bn17(params.gasLimit ?? gasUsed);
4694
4801
  this.validateGas({
4695
4802
  gasUsed,
4696
4803
  gasPrice: request.gasPrice,
@@ -4715,7 +4822,7 @@ var Account = class extends AbstractAccount {
4715
4822
  "0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
4716
4823
  );
4717
4824
  const amountDataArray = arrayify14(
4718
- "0x".concat(bn16(amount).toHex().substring(2).padStart(16, "0"))
4825
+ "0x".concat(bn17(amount).toHex().substring(2).padStart(16, "0"))
4719
4826
  );
4720
4827
  const script = new Uint8Array([
4721
4828
  ...arrayify14(withdrawScript.bytes),
@@ -4724,12 +4831,12 @@ var Account = class extends AbstractAccount {
4724
4831
  ]);
4725
4832
  const params = { script, gasPrice: minGasPrice, ...txParams };
4726
4833
  const request = new ScriptTransactionRequest(params);
4727
- const forwardingQuantities = [{ amount: bn16(amount), assetId: BaseAssetId3 }];
4834
+ const forwardingQuantities = [{ amount: bn17(amount), assetId: BaseAssetId3 }];
4728
4835
  const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
4729
4836
  request,
4730
4837
  forwardingQuantities
4731
4838
  );
4732
- request.gasLimit = bn16(params.gasLimit ?? gasUsed);
4839
+ request.gasLimit = bn17(params.gasLimit ?? gasUsed);
4733
4840
  this.validateGas({
4734
4841
  gasUsed,
4735
4842
  gasPrice: request.gasPrice,
@@ -4741,7 +4848,7 @@ var Account = class extends AbstractAccount {
4741
4848
  }
4742
4849
  async signMessage(message) {
4743
4850
  if (!this._connector) {
4744
- throw new FuelError14(ErrorCode14.MISSING_CONNECTOR, "A connector is required to sign messages.");
4851
+ throw new FuelError15(ErrorCode15.MISSING_CONNECTOR, "A connector is required to sign messages.");
4745
4852
  }
4746
4853
  return this._connector.signMessage(this.address.toString(), message);
4747
4854
  }
@@ -4753,8 +4860,8 @@ var Account = class extends AbstractAccount {
4753
4860
  */
4754
4861
  async signTransaction(transactionRequestLike) {
4755
4862
  if (!this._connector) {
4756
- throw new FuelError14(
4757
- ErrorCode14.MISSING_CONNECTOR,
4863
+ throw new FuelError15(
4864
+ ErrorCode15.MISSING_CONNECTOR,
4758
4865
  "A connector is required to sign transactions."
4759
4866
  );
4760
4867
  }
@@ -4801,14 +4908,14 @@ var Account = class extends AbstractAccount {
4801
4908
  minGasPrice
4802
4909
  }) {
4803
4910
  if (minGasPrice.gt(gasPrice)) {
4804
- throw new FuelError14(
4805
- ErrorCode14.GAS_PRICE_TOO_LOW,
4911
+ throw new FuelError15(
4912
+ ErrorCode15.GAS_PRICE_TOO_LOW,
4806
4913
  `Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
4807
4914
  );
4808
4915
  }
4809
4916
  if (gasUsed.gt(gasLimit)) {
4810
- throw new FuelError14(
4811
- ErrorCode14.GAS_LIMIT_TOO_LOW,
4917
+ throw new FuelError15(
4918
+ ErrorCode15.GAS_LIMIT_TOO_LOW,
4812
4919
  `Gas limit '${gasLimit}' is lower than the required: '${gasUsed}'.`
4813
4920
  );
4814
4921
  }
@@ -4817,7 +4924,7 @@ var Account = class extends AbstractAccount {
4817
4924
 
4818
4925
  // src/signer/signer.ts
4819
4926
  import { Address as Address4 } from "@fuel-ts/address";
4820
- import { randomBytes } from "@fuel-ts/crypto";
4927
+ import { randomBytes as randomBytes2 } from "@fuel-ts/crypto";
4821
4928
  import { hash } from "@fuel-ts/hasher";
4822
4929
  import { toBytes } from "@fuel-ts/math";
4823
4930
  import { hexlify as hexlify13, concat as concat3, arrayify as arrayify15 } from "@fuel-ts/utils";
@@ -4910,7 +5017,7 @@ var Signer = class {
4910
5017
  * @returns random 32-byte hashed
4911
5018
  */
4912
5019
  static generatePrivateKey(entropy) {
4913
- return entropy ? hash(concat3([randomBytes(32), arrayify15(entropy)])) : randomBytes(32);
5020
+ return entropy ? hash(concat3([randomBytes2(32), arrayify15(entropy)])) : randomBytes2(32);
4914
5021
  }
4915
5022
  /**
4916
5023
  * Extended publicKey from a compact publicKey
@@ -4929,13 +5036,13 @@ import { Address as Address5 } from "@fuel-ts/address";
4929
5036
  import {
4930
5037
  bufferFromString,
4931
5038
  keccak256,
4932
- randomBytes as randomBytes2,
5039
+ randomBytes as randomBytes3,
4933
5040
  scrypt,
4934
5041
  stringFromBuffer,
4935
5042
  decryptJsonWalletData,
4936
5043
  encryptJsonWalletData
4937
5044
  } from "@fuel-ts/crypto";
4938
- import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
5045
+ import { ErrorCode as ErrorCode16, FuelError as FuelError16 } from "@fuel-ts/errors";
4939
5046
  import { hexlify as hexlify14 } from "@fuel-ts/utils";
4940
5047
  import { v4 as uuidv4 } from "uuid";
4941
5048
  var DEFAULT_KDF_PARAMS_LOG_N = 13;
@@ -4952,7 +5059,7 @@ var removeHexPrefix = (hexString) => {
4952
5059
  async function encryptKeystoreWallet(privateKey, address, password) {
4953
5060
  const privateKeyBuffer = bufferFromString(removeHexPrefix(privateKey), "hex");
4954
5061
  const ownerAddress = Address5.fromAddressOrString(address);
4955
- const salt = randomBytes2(DEFAULT_KEY_SIZE);
5062
+ const salt = randomBytes3(DEFAULT_KEY_SIZE);
4956
5063
  const key = scrypt({
4957
5064
  password: bufferFromString(password),
4958
5065
  salt,
@@ -4961,7 +5068,7 @@ async function encryptKeystoreWallet(privateKey, address, password) {
4961
5068
  r: DEFAULT_KDF_PARAMS_R,
4962
5069
  p: DEFAULT_KDF_PARAMS_P
4963
5070
  });
4964
- const iv = randomBytes2(DEFAULT_IV_SIZE);
5071
+ const iv = randomBytes3(DEFAULT_IV_SIZE);
4965
5072
  const ciphertext = await encryptJsonWalletData(privateKeyBuffer, key, iv);
4966
5073
  const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertext]);
4967
5074
  const macHashUint8Array = keccak256(data);
@@ -5013,8 +5120,8 @@ async function decryptKeystoreWallet(jsonWallet, password) {
5013
5120
  const macHashUint8Array = keccak256(data);
5014
5121
  const macHash = stringFromBuffer(macHashUint8Array, "hex");
5015
5122
  if (mac !== macHash) {
5016
- throw new FuelError15(
5017
- ErrorCode15.INVALID_PASSWORD,
5123
+ throw new FuelError16(
5124
+ ErrorCode16.INVALID_PASSWORD,
5018
5125
  "Failed to decrypt the keystore wallet, the provided password is incorrect."
5019
5126
  );
5020
5127
  }
@@ -5136,15 +5243,15 @@ var BaseWalletUnlocked = class extends Account {
5136
5243
  __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
5137
5244
 
5138
5245
  // src/hdwallet/hdwallet.ts
5139
- import { ErrorCode as ErrorCode18, FuelError as FuelError18 } from "@fuel-ts/errors";
5246
+ import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
5140
5247
  import { sha256 as sha2564 } from "@fuel-ts/hasher";
5141
- import { bn as bn17, toBytes as toBytes2, toHex } from "@fuel-ts/math";
5248
+ import { bn as bn18, toBytes as toBytes2, toHex } from "@fuel-ts/math";
5142
5249
  import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
5143
5250
  import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
5144
5251
 
5145
5252
  // src/mnemonic/mnemonic.ts
5146
- import { randomBytes as randomBytes3 } from "@fuel-ts/crypto";
5147
- import { ErrorCode as ErrorCode17, FuelError as FuelError17 } from "@fuel-ts/errors";
5253
+ import { randomBytes as randomBytes4 } from "@fuel-ts/crypto";
5254
+ import { ErrorCode as ErrorCode18, FuelError as FuelError18 } from "@fuel-ts/errors";
5148
5255
  import { sha256 as sha2563 } from "@fuel-ts/hasher";
5149
5256
  import { arrayify as arrayify17, hexlify as hexlify16, concat as concat4 } from "@fuel-ts/utils";
5150
5257
  import { dataSlice, pbkdf2, computeHmac, encodeBase58 } from "ethers";
@@ -7202,7 +7309,7 @@ var english = [
7202
7309
  ];
7203
7310
 
7204
7311
  // src/mnemonic/utils.ts
7205
- import { ErrorCode as ErrorCode16, FuelError as FuelError16 } from "@fuel-ts/errors";
7312
+ import { ErrorCode as ErrorCode17, FuelError as FuelError17 } from "@fuel-ts/errors";
7206
7313
  import { sha256 as sha2562 } from "@fuel-ts/hasher";
7207
7314
  import { arrayify as arrayify16 } from "@fuel-ts/utils";
7208
7315
  function toUtf8Bytes(stri) {
@@ -7219,8 +7326,8 @@ function toUtf8Bytes(stri) {
7219
7326
  i += 1;
7220
7327
  const c2 = str.charCodeAt(i);
7221
7328
  if (i >= str.length || (c2 & 64512) !== 56320) {
7222
- throw new FuelError16(
7223
- ErrorCode16.INVALID_INPUT_PARAMETERS,
7329
+ throw new FuelError17(
7330
+ ErrorCode17.INVALID_INPUT_PARAMETERS,
7224
7331
  "Invalid UTF-8 in the input string."
7225
7332
  );
7226
7333
  }
@@ -7283,8 +7390,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
7283
7390
  for (let i = 0; i < words.length; i += 1) {
7284
7391
  const index = wordlist.indexOf(words[i].normalize("NFKD"));
7285
7392
  if (index === -1) {
7286
- throw new FuelError16(
7287
- ErrorCode16.INVALID_MNEMONIC,
7393
+ throw new FuelError17(
7394
+ ErrorCode17.INVALID_MNEMONIC,
7288
7395
  `Invalid mnemonic: the word '${words[i]}' is not found in the provided wordlist.`
7289
7396
  );
7290
7397
  }
@@ -7300,8 +7407,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
7300
7407
  const checksumMask = getUpperMask(checksumBits);
7301
7408
  const checksum = arrayify16(sha2562(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
7302
7409
  if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
7303
- throw new FuelError16(
7304
- ErrorCode16.INVALID_CHECKSUM,
7410
+ throw new FuelError17(
7411
+ ErrorCode17.INVALID_CHECKSUM,
7305
7412
  "Checksum validation failed for the provided mnemonic."
7306
7413
  );
7307
7414
  }
@@ -7315,16 +7422,16 @@ var TestnetPRV = "0x04358394";
7315
7422
  var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
7316
7423
  function assertWordList(wordlist) {
7317
7424
  if (wordlist.length !== 2048) {
7318
- throw new FuelError17(
7319
- ErrorCode17.INVALID_WORD_LIST,
7425
+ throw new FuelError18(
7426
+ ErrorCode18.INVALID_WORD_LIST,
7320
7427
  `Expected word list length of 2048, but got ${wordlist.length}.`
7321
7428
  );
7322
7429
  }
7323
7430
  }
7324
7431
  function assertEntropy(entropy) {
7325
7432
  if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {
7326
- throw new FuelError17(
7327
- ErrorCode17.INVALID_ENTROPY,
7433
+ throw new FuelError18(
7434
+ ErrorCode18.INVALID_ENTROPY,
7328
7435
  `Entropy should be between 16 and 32 bytes and a multiple of 4, but got ${entropy.length} bytes.`
7329
7436
  );
7330
7437
  }
@@ -7334,7 +7441,7 @@ function assertMnemonic(words) {
7334
7441
  const errorMsg = `Invalid mnemonic size. Expected one of [${MNEMONIC_SIZES.join(
7335
7442
  ", "
7336
7443
  )}] words, but got ${words.length}.`;
7337
- throw new FuelError17(ErrorCode17.INVALID_MNEMONIC, errorMsg);
7444
+ throw new FuelError18(ErrorCode18.INVALID_MNEMONIC, errorMsg);
7338
7445
  }
7339
7446
  }
7340
7447
  var Mnemonic = class {
@@ -7452,8 +7559,8 @@ var Mnemonic = class {
7452
7559
  static masterKeysFromSeed(seed) {
7453
7560
  const seedArray = arrayify17(seed);
7454
7561
  if (seedArray.length < 16 || seedArray.length > 64) {
7455
- throw new FuelError17(
7456
- ErrorCode17.INVALID_SEED,
7562
+ throw new FuelError18(
7563
+ ErrorCode18.INVALID_SEED,
7457
7564
  `Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
7458
7565
  );
7459
7566
  }
@@ -7498,7 +7605,7 @@ var Mnemonic = class {
7498
7605
  * @returns A randomly generated mnemonic
7499
7606
  */
7500
7607
  static generate(size = 32, extraEntropy = "") {
7501
- const entropy = extraEntropy ? sha2563(concat4([randomBytes3(size), arrayify17(extraEntropy)])) : randomBytes3(size);
7608
+ const entropy = extraEntropy ? sha2563(concat4([randomBytes4(size), arrayify17(extraEntropy)])) : randomBytes4(size);
7502
7609
  return Mnemonic.entropyToMnemonic(entropy);
7503
7610
  }
7504
7611
  };
@@ -7530,7 +7637,7 @@ function isValidExtendedKey(extendedKey) {
7530
7637
  function parsePath(path2, depth = 0) {
7531
7638
  const components = path2.split("/");
7532
7639
  if (components.length === 0 || components[0] === "m" && depth !== 0) {
7533
- throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, `invalid path - ${path2}`);
7640
+ throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, `invalid path - ${path2}`);
7534
7641
  }
7535
7642
  if (components[0] === "m") {
7536
7643
  components.shift();
@@ -7559,8 +7666,8 @@ var HDWallet = class {
7559
7666
  this.privateKey = hexlify17(config.privateKey);
7560
7667
  } else {
7561
7668
  if (!config.publicKey) {
7562
- throw new FuelError18(
7563
- ErrorCode18.HD_WALLET_ERROR,
7669
+ throw new FuelError19(
7670
+ ErrorCode19.HD_WALLET_ERROR,
7564
7671
  "Both public and private Key cannot be missing. At least one should be provided."
7565
7672
  );
7566
7673
  }
@@ -7589,8 +7696,8 @@ var HDWallet = class {
7589
7696
  const data = new Uint8Array(37);
7590
7697
  if (index & HARDENED_INDEX) {
7591
7698
  if (!privateKey) {
7592
- throw new FuelError18(
7593
- ErrorCode18.HD_WALLET_ERROR,
7699
+ throw new FuelError19(
7700
+ ErrorCode19.HD_WALLET_ERROR,
7594
7701
  "Cannot derive a hardened index without a private Key."
7595
7702
  );
7596
7703
  }
@@ -7604,7 +7711,7 @@ var HDWallet = class {
7604
7711
  const IR = bytes.slice(32);
7605
7712
  if (privateKey) {
7606
7713
  const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
7607
- const ki = bn17(IL).add(privateKey).mod(N).toBytes(32);
7714
+ const ki = bn18(IL).add(privateKey).mod(N).toBytes(32);
7608
7715
  return new HDWallet({
7609
7716
  privateKey: ki,
7610
7717
  chainCode: IR,
@@ -7642,8 +7749,8 @@ var HDWallet = class {
7642
7749
  */
7643
7750
  toExtendedKey(isPublic = false, testnet = false) {
7644
7751
  if (this.depth >= 256) {
7645
- throw new FuelError18(
7646
- ErrorCode18.HD_WALLET_ERROR,
7752
+ throw new FuelError19(
7753
+ ErrorCode19.HD_WALLET_ERROR,
7647
7754
  `Exceeded max depth of 255. Current depth: ${this.depth}.`
7648
7755
  );
7649
7756
  }
@@ -7674,10 +7781,10 @@ var HDWallet = class {
7674
7781
  const bytes = arrayify18(decoded);
7675
7782
  const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
7676
7783
  if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
7677
- throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
7784
+ throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
7678
7785
  }
7679
7786
  if (!validChecksum) {
7680
- throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
7787
+ throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
7681
7788
  }
7682
7789
  const depth = bytes[4];
7683
7790
  const parentFingerprint = hexlify17(bytes.slice(5, 9));
@@ -7685,14 +7792,14 @@ var HDWallet = class {
7685
7792
  const chainCode = hexlify17(bytes.slice(13, 45));
7686
7793
  const key = bytes.slice(45, 78);
7687
7794
  if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
7688
- throw new FuelError18(
7689
- ErrorCode18.HD_WALLET_ERROR,
7795
+ throw new FuelError19(
7796
+ ErrorCode19.HD_WALLET_ERROR,
7690
7797
  "Inconsistency detected: Depth is zero but fingerprint/index is non-zero."
7691
7798
  );
7692
7799
  }
7693
7800
  if (isPublicExtendedKey(bytes)) {
7694
7801
  if (key[0] !== 3) {
7695
- throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, "Invalid public extended key.");
7802
+ throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, "Invalid public extended key.");
7696
7803
  }
7697
7804
  return new HDWallet({
7698
7805
  publicKey: key,
@@ -7703,7 +7810,7 @@ var HDWallet = class {
7703
7810
  });
7704
7811
  }
7705
7812
  if (key[0] !== 0) {
7706
- throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, "Invalid private extended key.");
7813
+ throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, "Invalid private extended key.");
7707
7814
  }
7708
7815
  return new HDWallet({
7709
7816
  privateKey: key.slice(1),
@@ -7869,10 +7976,10 @@ __publicField(Wallet, "fromExtendedKey", WalletUnlocked.fromExtendedKey);
7869
7976
  __publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
7870
7977
 
7871
7978
  // src/test-utils/seedTestWallet.ts
7872
- import { randomBytes as randomBytes4 } from "@fuel-ts/crypto";
7979
+ import { randomBytes as randomBytes5 } from "@fuel-ts/crypto";
7873
7980
  var seedTestWallet = async (wallet, quantities) => {
7874
7981
  const genesisWallet = new WalletUnlocked(
7875
- process.env.GENESIS_SECRET || randomBytes4(32),
7982
+ process.env.GENESIS_SECRET || randomBytes5(32),
7876
7983
  wallet.provider
7877
7984
  );
7878
7985
  const resources = await genesisWallet.getResourcesToSpend(quantities);