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

Files changed (34) hide show
  1. package/dist/configs.d.ts +1 -0
  2. package/dist/configs.d.ts.map +1 -1
  3. package/dist/configs.global.js +1 -0
  4. package/dist/configs.global.js.map +1 -1
  5. package/dist/configs.js +3 -0
  6. package/dist/configs.js.map +1 -1
  7. package/dist/configs.mjs +2 -0
  8. package/dist/configs.mjs.map +1 -1
  9. package/dist/index.global.js +382 -192
  10. package/dist/index.global.js.map +1 -1
  11. package/dist/index.js +667 -554
  12. package/dist/index.js.map +1 -1
  13. package/dist/index.mjs +416 -298
  14. package/dist/index.mjs.map +1 -1
  15. package/dist/predicate/predicate.d.ts +0 -1
  16. package/dist/predicate/predicate.d.ts.map +1 -1
  17. package/dist/providers/fuel-graphql-subscriber.d.ts +2 -0
  18. package/dist/providers/fuel-graphql-subscriber.d.ts.map +1 -1
  19. package/dist/providers/provider.d.ts +13 -2
  20. package/dist/providers/provider.d.ts.map +1 -1
  21. package/dist/providers/transaction-request/input.d.ts.map +1 -1
  22. package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
  23. package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
  24. package/dist/providers/utils/extract-tx-error.d.ts +36 -0
  25. package/dist/providers/utils/extract-tx-error.d.ts.map +1 -0
  26. package/dist/providers/utils/index.d.ts +1 -0
  27. package/dist/providers/utils/index.d.ts.map +1 -1
  28. package/dist/test-utils.global.js +384 -193
  29. package/dist/test-utils.global.js.map +1 -1
  30. package/dist/test-utils.js +624 -516
  31. package/dist/test-utils.js.map +1 -1
  32. package/dist/test-utils.mjs +388 -272
  33. package/dist/test-utils.mjs.map +1 -1
  34. package/package.json +21 -26
@@ -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,
@@ -911,36 +911,45 @@ var _FuelGraphqlSubscriber = class {
911
911
  });
912
912
  this.stream = response.body.getReader();
913
913
  }
914
+ events = [];
915
+ parsingLeftover = "";
914
916
  async next() {
915
917
  if (!this.stream) {
916
918
  await this.setStream();
917
919
  }
918
920
  while (true) {
921
+ if (this.events.length > 0) {
922
+ const { data, errors } = this.events.shift();
923
+ if (Array.isArray(errors)) {
924
+ throw new FuelError(
925
+ FuelError.CODES.INVALID_REQUEST,
926
+ errors.map((err) => err.message).join("\n\n")
927
+ );
928
+ }
929
+ return { value: data, done: false };
930
+ }
919
931
  const { value, done } = await this.stream.read();
920
932
  if (done) {
921
933
  return { value, done };
922
934
  }
923
- const text = _FuelGraphqlSubscriber.textDecoder.decode(value);
924
- if (!text.startsWith("data:")) {
935
+ const decoded = _FuelGraphqlSubscriber.textDecoder.decode(value).replace(":keep-alive-text\n\n", "");
936
+ if (decoded === "") {
925
937
  continue;
926
938
  }
927
- let data;
928
- let errors;
929
- try {
930
- ({ data, errors } = JSON.parse(text.replace(/^data:/, "")));
931
- } catch (e) {
932
- throw new FuelError(
933
- ErrorCode.STREAM_PARSING_ERROR,
934
- `Error while parsing stream data response: ${text}`
935
- );
936
- }
937
- if (Array.isArray(errors)) {
938
- throw new FuelError(
939
- FuelError.CODES.INVALID_REQUEST,
940
- errors.map((err) => err.message).join("\n\n")
941
- );
942
- }
943
- return { value: data, done: false };
939
+ const text = `${this.parsingLeftover}${decoded}`;
940
+ const regex = /data:.*\n\n/g;
941
+ const matches = [...text.matchAll(regex)].flatMap((match) => match);
942
+ matches.forEach((match) => {
943
+ try {
944
+ this.events.push(JSON.parse(match.replace(/^data:/, "")));
945
+ } catch (e) {
946
+ throw new FuelError(
947
+ ErrorCode.STREAM_PARSING_ERROR,
948
+ `Error while parsing stream data response: ${text}`
949
+ );
950
+ }
951
+ });
952
+ this.parsingLeftover = text.replace(matches.join(), "");
944
953
  }
945
954
  }
946
955
  /**
@@ -1018,6 +1027,7 @@ var MemoryCache = class {
1018
1027
  };
1019
1028
 
1020
1029
  // src/providers/transaction-request/input.ts
1030
+ import { BYTES_32, UTXO_ID_LEN } from "@fuel-ts/abi-coder";
1021
1031
  import { ZeroBytes32 } from "@fuel-ts/address/configs";
1022
1032
  import { ErrorCode as ErrorCode3, FuelError as FuelError3 } from "@fuel-ts/errors";
1023
1033
  import { bn as bn2, toNumber } from "@fuel-ts/math";
@@ -1031,8 +1041,8 @@ var inputify = (value) => {
1031
1041
  const predicateData = arrayify(value.predicateData ?? "0x");
1032
1042
  return {
1033
1043
  type: InputType.Coin,
1034
- txID: hexlify3(arrayify(value.id).slice(0, 32)),
1035
- outputIndex: arrayify(value.id)[32],
1044
+ txID: hexlify3(arrayify(value.id).slice(0, BYTES_32)),
1045
+ outputIndex: toNumber(arrayify(value.id).slice(BYTES_32, UTXO_ID_LEN)),
1036
1046
  owner: hexlify3(value.owner),
1037
1047
  amount: bn2(value.amount),
1038
1048
  assetId: hexlify3(value.assetId),
@@ -1150,9 +1160,11 @@ var outputify = (value) => {
1150
1160
  };
1151
1161
 
1152
1162
  // src/providers/transaction-request/transaction-request.ts
1163
+ import { UTXO_ID_LEN as UTXO_ID_LEN2 } from "@fuel-ts/abi-coder";
1153
1164
  import { Address, addressify } from "@fuel-ts/address";
1154
1165
  import { BaseAssetId as BaseAssetId2, ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
1155
- import { bn as bn6 } from "@fuel-ts/math";
1166
+ import { randomBytes } from "@fuel-ts/crypto";
1167
+ import { bn as bn7 } from "@fuel-ts/math";
1156
1168
  import {
1157
1169
  PolicyType,
1158
1170
  TransactionCoder,
@@ -1495,6 +1507,86 @@ function sleep(time) {
1495
1507
  });
1496
1508
  }
1497
1509
 
1510
+ // src/providers/utils/extract-tx-error.ts
1511
+ import { ErrorCode as ErrorCode7, FuelError as FuelError7 } from "@fuel-ts/errors";
1512
+ import { bn as bn6 } from "@fuel-ts/math";
1513
+ import { ReceiptType as ReceiptType3 } from "@fuel-ts/transactions";
1514
+ import {
1515
+ FAILED_REQUIRE_SIGNAL,
1516
+ FAILED_ASSERT_EQ_SIGNAL,
1517
+ FAILED_ASSERT_NE_SIGNAL,
1518
+ FAILED_ASSERT_SIGNAL,
1519
+ FAILED_TRANSFER_TO_ADDRESS_SIGNAL as FAILED_TRANSFER_TO_ADDRESS_SIGNAL2,
1520
+ PANIC_REASONS,
1521
+ PANIC_DOC_URL
1522
+ } from "@fuel-ts/transactions/configs";
1523
+ var assemblePanicError = (status) => {
1524
+ let errorMessage = `The transaction reverted with reason: "${status.reason}".`;
1525
+ const reason = status.reason;
1526
+ if (PANIC_REASONS.includes(status.reason)) {
1527
+ errorMessage = `${errorMessage}
1528
+
1529
+ You can read more about this error at:
1530
+
1531
+ ${PANIC_DOC_URL}#variant.${status.reason}`;
1532
+ }
1533
+ return { errorMessage, reason };
1534
+ };
1535
+ var stringify = (obj) => JSON.stringify(obj, null, 2);
1536
+ var assembleRevertError = (receipts, logs) => {
1537
+ let errorMessage = "The transaction reverted with an unknown reason.";
1538
+ const revertReceipt = receipts.find(({ type }) => type === ReceiptType3.Revert);
1539
+ let reason = "";
1540
+ if (revertReceipt) {
1541
+ const reasonHex = bn6(revertReceipt.val).toHex();
1542
+ switch (reasonHex) {
1543
+ case FAILED_REQUIRE_SIGNAL: {
1544
+ reason = "require";
1545
+ errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(logs[0]) : "an error."}.`;
1546
+ break;
1547
+ }
1548
+ case FAILED_ASSERT_EQ_SIGNAL: {
1549
+ const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
1550
+ reason = "assert_eq";
1551
+ errorMessage = `The transaction reverted because of an "assert_eq" statement${sufix}`;
1552
+ break;
1553
+ }
1554
+ case FAILED_ASSERT_NE_SIGNAL: {
1555
+ const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
1556
+ reason = "assert_ne";
1557
+ errorMessage = `The transaction reverted because of an "assert_ne" statement${sufix}`;
1558
+ break;
1559
+ }
1560
+ case FAILED_ASSERT_SIGNAL:
1561
+ reason = "assert";
1562
+ errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
1563
+ break;
1564
+ case FAILED_TRANSFER_TO_ADDRESS_SIGNAL2:
1565
+ reason = "MissingOutputChange";
1566
+ errorMessage = `The transaction reverted because it's missing an "OutputChange".`;
1567
+ break;
1568
+ default:
1569
+ reason = "unknown";
1570
+ errorMessage = `The transaction reverted with an unknown reason: ${revertReceipt.val}`;
1571
+ }
1572
+ }
1573
+ return { errorMessage, reason };
1574
+ };
1575
+ var extractTxError = (params) => {
1576
+ const { receipts, status, logs } = params;
1577
+ const isPanic = receipts.some(({ type }) => type === ReceiptType3.Panic);
1578
+ const isRevert = receipts.some(({ type }) => type === ReceiptType3.Revert);
1579
+ const { errorMessage, reason } = status?.type === "FailureStatus" && isPanic ? assemblePanicError(status) : assembleRevertError(receipts, logs);
1580
+ const metadata = {
1581
+ logs,
1582
+ receipts,
1583
+ panic: isPanic,
1584
+ revert: isRevert,
1585
+ reason
1586
+ };
1587
+ return new FuelError7(ErrorCode7.SCRIPT_REVERTED, errorMessage, metadata);
1588
+ };
1589
+
1498
1590
  // src/providers/transaction-request/errors.ts
1499
1591
  var NoWitnessAtIndexError = class extends Error {
1500
1592
  constructor(index) {
@@ -1545,10 +1637,10 @@ var BaseTransactionRequest = class {
1545
1637
  outputs,
1546
1638
  witnesses
1547
1639
  } = {}) {
1548
- this.gasPrice = bn6(gasPrice);
1640
+ this.gasPrice = bn7(gasPrice);
1549
1641
  this.maturity = maturity ?? 0;
1550
- this.witnessLimit = witnessLimit ? bn6(witnessLimit) : void 0;
1551
- this.maxFee = maxFee ? bn6(maxFee) : void 0;
1642
+ this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
1643
+ this.maxFee = maxFee ? bn7(maxFee) : void 0;
1552
1644
  this.inputs = inputs ?? [];
1553
1645
  this.outputs = outputs ?? [];
1554
1646
  this.witnesses = witnesses ?? [];
@@ -1764,8 +1856,7 @@ var BaseTransactionRequest = class {
1764
1856
  assetId,
1765
1857
  txPointer: "0x00000000000000000000000000000000",
1766
1858
  witnessIndex,
1767
- predicate: predicate?.bytes,
1768
- predicateData: predicate?.predicateDataBytes
1859
+ predicate: predicate?.bytes
1769
1860
  };
1770
1861
  this.pushInput(input);
1771
1862
  this.addChangeOutput(owner, assetId);
@@ -1797,8 +1888,7 @@ var BaseTransactionRequest = class {
1797
1888
  recipient: recipient.toB256(),
1798
1889
  amount,
1799
1890
  witnessIndex,
1800
- predicate: predicate?.bytes,
1801
- predicateData: predicate?.predicateDataBytes
1891
+ predicate: predicate?.bytes
1802
1892
  };
1803
1893
  this.pushInput(input);
1804
1894
  this.addChangeOutput(recipient, assetId);
@@ -1953,12 +2043,6 @@ var BaseTransactionRequest = class {
1953
2043
  * @param quantities - CoinQuantity Array.
1954
2044
  */
1955
2045
  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
2046
  const findAssetInput = (assetId) => this.inputs.find((input) => {
1963
2047
  if ("assetId" in input) {
1964
2048
  return input.assetId === assetId;
@@ -1968,23 +2052,23 @@ var BaseTransactionRequest = class {
1968
2052
  const updateAssetInput = (assetId, quantity) => {
1969
2053
  const assetInput = findAssetInput(assetId);
1970
2054
  if (assetInput && "assetId" in assetInput) {
1971
- assetInput.id = generateId();
2055
+ assetInput.id = hexlify7(randomBytes(UTXO_ID_LEN2));
1972
2056
  assetInput.amount = quantity;
1973
2057
  } else {
1974
2058
  this.addResources([
1975
2059
  {
1976
- id: generateId(),
2060
+ id: hexlify7(randomBytes(UTXO_ID_LEN2)),
1977
2061
  amount: quantity,
1978
2062
  assetId,
1979
2063
  owner: resourcesOwner || Address.fromRandom(),
1980
2064
  maturity: 0,
1981
- blockCreated: bn6(1),
1982
- txCreatedIdx: bn6(1)
2065
+ blockCreated: bn7(1),
2066
+ txCreatedIdx: bn7(1)
1983
2067
  }
1984
2068
  ]);
1985
2069
  }
1986
2070
  };
1987
- updateAssetInput(BaseAssetId2, bn6(1e11));
2071
+ updateAssetInput(BaseAssetId2, bn7(1e11));
1988
2072
  quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
1989
2073
  }
1990
2074
  /**
@@ -1995,7 +2079,7 @@ var BaseTransactionRequest = class {
1995
2079
  */
1996
2080
  getCoinOutputsQuantities() {
1997
2081
  const coinsQuantities = this.getCoinOutputs().map(({ amount, assetId }) => ({
1998
- amount: bn6(amount),
2082
+ amount: bn7(amount),
1999
2083
  assetId: assetId.toString()
2000
2084
  }));
2001
2085
  return coinsQuantities;
@@ -2024,7 +2108,7 @@ var BaseTransactionRequest = class {
2024
2108
  default:
2025
2109
  return;
2026
2110
  }
2027
- if (correspondingInput && "predicateGasUsed" in correspondingInput && bn6(correspondingInput.predicateGasUsed).gt(0)) {
2111
+ if (correspondingInput && "predicateGasUsed" in correspondingInput && bn7(correspondingInput.predicateGasUsed).gt(0)) {
2028
2112
  i.predicate = correspondingInput.predicate;
2029
2113
  i.predicateData = correspondingInput.predicateData;
2030
2114
  i.predicateGasUsed = correspondingInput.predicateGasUsed;
@@ -2035,14 +2119,14 @@ var BaseTransactionRequest = class {
2035
2119
 
2036
2120
  // src/providers/transaction-request/create-transaction-request.ts
2037
2121
  import { ZeroBytes32 as ZeroBytes326 } from "@fuel-ts/address/configs";
2038
- import { bn as bn8 } from "@fuel-ts/math";
2122
+ import { bn as bn9 } from "@fuel-ts/math";
2039
2123
  import { TransactionType as TransactionType3, OutputType as OutputType4 } from "@fuel-ts/transactions";
2040
2124
  import { arrayify as arrayify6, hexlify as hexlify9 } from "@fuel-ts/utils";
2041
2125
 
2042
2126
  // src/providers/transaction-request/hash-transaction.ts
2043
2127
  import { ZeroBytes32 as ZeroBytes325 } from "@fuel-ts/address/configs";
2044
2128
  import { uint64ToBytesBE, sha256 } from "@fuel-ts/hasher";
2045
- import { bn as bn7 } from "@fuel-ts/math";
2129
+ import { bn as bn8 } from "@fuel-ts/math";
2046
2130
  import { TransactionType as TransactionType2, InputType as InputType3, OutputType as OutputType3, TransactionCoder as TransactionCoder2 } from "@fuel-ts/transactions";
2047
2131
  import { concat as concat2 } from "@fuel-ts/utils";
2048
2132
  import { clone as clone2 } from "ramda";
@@ -2059,11 +2143,11 @@ function hashTransaction(transactionRequest, chainId) {
2059
2143
  blockHeight: 0,
2060
2144
  txIndex: 0
2061
2145
  };
2062
- inputClone.predicateGasUsed = bn7(0);
2146
+ inputClone.predicateGasUsed = bn8(0);
2063
2147
  return inputClone;
2064
2148
  }
2065
2149
  case InputType3.Message: {
2066
- inputClone.predicateGasUsed = bn7(0);
2150
+ inputClone.predicateGasUsed = bn8(0);
2067
2151
  return inputClone;
2068
2152
  }
2069
2153
  case InputType3.Contract: {
@@ -2090,12 +2174,12 @@ function hashTransaction(transactionRequest, chainId) {
2090
2174
  return outputClone;
2091
2175
  }
2092
2176
  case OutputType3.Change: {
2093
- outputClone.amount = bn7(0);
2177
+ outputClone.amount = bn8(0);
2094
2178
  return outputClone;
2095
2179
  }
2096
2180
  case OutputType3.Variable: {
2097
2181
  outputClone.to = ZeroBytes325;
2098
- outputClone.amount = bn7(0);
2182
+ outputClone.amount = bn8(0);
2099
2183
  outputClone.assetId = ZeroBytes325;
2100
2184
  return outputClone;
2101
2185
  }
@@ -2219,7 +2303,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2219
2303
  }
2220
2304
  metadataGas(gasCosts) {
2221
2305
  return calculateMetadataGasForTxCreate({
2222
- contractBytesSize: bn8(arrayify6(this.witnesses[this.bytecodeWitnessIndex] || "0x").length),
2306
+ contractBytesSize: bn9(arrayify6(this.witnesses[this.bytecodeWitnessIndex] || "0x").length),
2223
2307
  gasCosts,
2224
2308
  stateRootSize: this.storageSlots.length,
2225
2309
  txBytesSize: this.byteSize()
@@ -2231,7 +2315,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2231
2315
  import { Interface } from "@fuel-ts/abi-coder";
2232
2316
  import { addressify as addressify2 } from "@fuel-ts/address";
2233
2317
  import { ZeroBytes32 as ZeroBytes327 } from "@fuel-ts/address/configs";
2234
- import { bn as bn9 } from "@fuel-ts/math";
2318
+ import { bn as bn10 } from "@fuel-ts/math";
2235
2319
  import { InputType as InputType4, OutputType as OutputType5, TransactionType as TransactionType4 } from "@fuel-ts/transactions";
2236
2320
  import { arrayify as arrayify8, hexlify as hexlify10 } from "@fuel-ts/utils";
2237
2321
 
@@ -2285,7 +2369,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2285
2369
  */
2286
2370
  constructor({ script, scriptData, gasLimit, ...rest } = {}) {
2287
2371
  super(rest);
2288
- this.gasLimit = bn9(gasLimit);
2372
+ this.gasLimit = bn10(gasLimit);
2289
2373
  this.script = arrayify8(script ?? returnZeroScript.bytes);
2290
2374
  this.scriptData = arrayify8(scriptData ?? returnZeroScript.encodeScriptData());
2291
2375
  this.abis = rest.abis;
@@ -2433,7 +2517,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2433
2517
  };
2434
2518
 
2435
2519
  // src/providers/transaction-request/utils.ts
2436
- import { ErrorCode as ErrorCode7, FuelError as FuelError7 } from "@fuel-ts/errors";
2520
+ import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
2437
2521
  import { TransactionType as TransactionType5 } from "@fuel-ts/transactions";
2438
2522
  var transactionRequestify = (obj) => {
2439
2523
  if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
@@ -2448,14 +2532,14 @@ var transactionRequestify = (obj) => {
2448
2532
  return CreateTransactionRequest.from(obj);
2449
2533
  }
2450
2534
  default: {
2451
- throw new FuelError7(ErrorCode7.INVALID_TRANSACTION_TYPE, `Invalid transaction type: ${type}.`);
2535
+ throw new FuelError8(ErrorCode8.INVALID_TRANSACTION_TYPE, `Invalid transaction type: ${type}.`);
2452
2536
  }
2453
2537
  }
2454
2538
  };
2455
2539
 
2456
2540
  // 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";
2541
+ import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
2542
+ import { bn as bn14 } from "@fuel-ts/math";
2459
2543
  import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
2460
2544
  import { arrayify as arrayify10 } from "@fuel-ts/utils";
2461
2545
 
@@ -2463,7 +2547,7 @@ import { arrayify as arrayify10 } from "@fuel-ts/utils";
2463
2547
  import { DateTime, hexlify as hexlify11 } from "@fuel-ts/utils";
2464
2548
 
2465
2549
  // src/providers/transaction-summary/calculate-transaction-fee.ts
2466
- import { bn as bn10 } from "@fuel-ts/math";
2550
+ import { bn as bn11 } from "@fuel-ts/math";
2467
2551
  import { PolicyType as PolicyType2, TransactionCoder as TransactionCoder3, TransactionType as TransactionType6 } from "@fuel-ts/transactions";
2468
2552
  import { arrayify as arrayify9 } from "@fuel-ts/utils";
2469
2553
  var calculateTransactionFee = (params) => {
@@ -2472,24 +2556,24 @@ var calculateTransactionFee = (params) => {
2472
2556
  rawPayload,
2473
2557
  consensusParameters: { gasCosts, feeParams }
2474
2558
  } = params;
2475
- const gasPerByte = bn10(feeParams.gasPerByte);
2476
- const gasPriceFactor = bn10(feeParams.gasPriceFactor);
2559
+ const gasPerByte = bn11(feeParams.gasPerByte);
2560
+ const gasPriceFactor = bn11(feeParams.gasPriceFactor);
2477
2561
  const transactionBytes = arrayify9(rawPayload);
2478
2562
  const [transaction] = new TransactionCoder3().decode(transactionBytes, 0);
2479
2563
  if (transaction.type === TransactionType6.Mint) {
2480
2564
  return {
2481
- fee: bn10(0),
2482
- minFee: bn10(0),
2483
- maxFee: bn10(0),
2484
- feeFromGasUsed: bn10(0)
2565
+ fee: bn11(0),
2566
+ minFee: bn11(0),
2567
+ maxFee: bn11(0),
2568
+ feeFromGasUsed: bn11(0)
2485
2569
  };
2486
2570
  }
2487
2571
  const { type, witnesses, inputs, policies } = transaction;
2488
- let metadataGas = bn10(0);
2489
- let gasLimit = bn10(0);
2572
+ let metadataGas = bn11(0);
2573
+ let gasLimit = bn11(0);
2490
2574
  if (type === TransactionType6.Create) {
2491
2575
  const { bytecodeWitnessIndex, storageSlots } = transaction;
2492
- const contractBytesSize = bn10(arrayify9(witnesses[bytecodeWitnessIndex].data).length);
2576
+ const contractBytesSize = bn11(arrayify9(witnesses[bytecodeWitnessIndex].data).length);
2493
2577
  metadataGas = calculateMetadataGasForTxCreate({
2494
2578
  contractBytesSize,
2495
2579
  gasCosts,
@@ -2508,12 +2592,12 @@ var calculateTransactionFee = (params) => {
2508
2592
  }
2509
2593
  const minGas = getMinGas({
2510
2594
  gasCosts,
2511
- gasPerByte: bn10(gasPerByte),
2595
+ gasPerByte: bn11(gasPerByte),
2512
2596
  inputs,
2513
2597
  metadataGas,
2514
2598
  txBytesSize: transactionBytes.length
2515
2599
  });
2516
- const gasPrice = bn10(policies.find((policy) => policy.type === PolicyType2.GasPrice)?.data);
2600
+ const gasPrice = bn11(policies.find((policy) => policy.type === PolicyType2.GasPrice)?.data);
2517
2601
  const witnessLimit = policies.find((policy) => policy.type === PolicyType2.WitnessLimit)?.data;
2518
2602
  const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
2519
2603
  const maxGas = getMaxGas({
@@ -2537,13 +2621,13 @@ var calculateTransactionFee = (params) => {
2537
2621
 
2538
2622
  // src/providers/transaction-summary/operations.ts
2539
2623
  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";
2624
+ import { ErrorCode as ErrorCode10, FuelError as FuelError10 } from "@fuel-ts/errors";
2625
+ import { bn as bn13 } from "@fuel-ts/math";
2626
+ import { ReceiptType as ReceiptType4, TransactionType as TransactionType7 } from "@fuel-ts/transactions";
2543
2627
 
2544
2628
  // src/providers/transaction-summary/call.ts
2545
2629
  import { Interface as Interface2, calculateVmTxMemory } from "@fuel-ts/abi-coder";
2546
- import { bn as bn11 } from "@fuel-ts/math";
2630
+ import { bn as bn12 } from "@fuel-ts/math";
2547
2631
  var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
2548
2632
  const abiInterface = new Interface2(abi);
2549
2633
  const callFunctionSelector = receipt.param1.toHex(8);
@@ -2552,7 +2636,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
2552
2636
  let encodedArgs;
2553
2637
  if (functionFragment.isInputDataPointer) {
2554
2638
  if (rawPayload) {
2555
- const argsOffset = bn11(receipt.param2).sub(calculateVmTxMemory({ maxInputs: maxInputs.toNumber() })).toNumber();
2639
+ const argsOffset = bn12(receipt.param2).sub(calculateVmTxMemory({ maxInputs: maxInputs.toNumber() })).toNumber();
2556
2640
  encodedArgs = `0x${rawPayload.slice(2).slice(argsOffset * 2)}`;
2557
2641
  }
2558
2642
  } else {
@@ -2586,7 +2670,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
2586
2670
  };
2587
2671
 
2588
2672
  // src/providers/transaction-summary/input.ts
2589
- import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
2673
+ import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
2590
2674
  import { InputType as InputType5 } from "@fuel-ts/transactions";
2591
2675
  function getInputsByTypes(inputs, types) {
2592
2676
  return inputs.filter((i) => types.includes(i.type));
@@ -2624,8 +2708,8 @@ function getInputContractFromIndex(inputs, inputIndex) {
2624
2708
  return void 0;
2625
2709
  }
2626
2710
  if (contractInput.type !== InputType5.Contract) {
2627
- throw new FuelError8(
2628
- ErrorCode8.INVALID_TRANSACTION_INPUT,
2711
+ throw new FuelError9(
2712
+ ErrorCode9.INVALID_TRANSACTION_INPUT,
2629
2713
  `Contract input should be of type 'contract'.`
2630
2714
  );
2631
2715
  }
@@ -2672,8 +2756,8 @@ function getTransactionTypeName(transactionType) {
2672
2756
  case TransactionType7.Script:
2673
2757
  return "Script" /* Script */;
2674
2758
  default:
2675
- throw new FuelError9(
2676
- ErrorCode9.INVALID_TRANSACTION_TYPE,
2759
+ throw new FuelError10(
2760
+ ErrorCode10.INVALID_TRANSACTION_TYPE,
2677
2761
  `Invalid transaction type: ${transactionType}.`
2678
2762
  );
2679
2763
  }
@@ -2692,10 +2776,10 @@ function isTypeScript(transactionType) {
2692
2776
  return isType(transactionType, "Script" /* Script */);
2693
2777
  }
2694
2778
  function getReceiptsCall(receipts) {
2695
- return getReceiptsByType(receipts, ReceiptType3.Call);
2779
+ return getReceiptsByType(receipts, ReceiptType4.Call);
2696
2780
  }
2697
2781
  function getReceiptsMessageOut(receipts) {
2698
- return getReceiptsByType(receipts, ReceiptType3.MessageOut);
2782
+ return getReceiptsByType(receipts, ReceiptType4.MessageOut);
2699
2783
  }
2700
2784
  var mergeAssets = (op1, op2) => {
2701
2785
  const assets1 = op1.assetsSent || [];
@@ -2708,7 +2792,7 @@ var mergeAssets = (op1, op2) => {
2708
2792
  if (!matchingAsset) {
2709
2793
  return asset1;
2710
2794
  }
2711
- const mergedAmount = bn12(asset1.amount).add(matchingAsset.amount);
2795
+ const mergedAmount = bn13(asset1.amount).add(matchingAsset.amount);
2712
2796
  return { ...asset1, amount: mergedAmount };
2713
2797
  });
2714
2798
  return mergedAssets.concat(filteredAssets);
@@ -2891,11 +2975,11 @@ function getTransferOperations({
2891
2975
  });
2892
2976
  const transferReceipts = getReceiptsByType(
2893
2977
  receipts,
2894
- ReceiptType3.Transfer
2978
+ ReceiptType4.Transfer
2895
2979
  );
2896
2980
  const transferOutReceipts = getReceiptsByType(
2897
2981
  receipts,
2898
- ReceiptType3.TransferOut
2982
+ ReceiptType4.TransferOut
2899
2983
  );
2900
2984
  [...transferReceipts, ...transferOutReceipts].forEach((receipt) => {
2901
2985
  const operation = extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs);
@@ -2980,17 +3064,17 @@ function getOperations({
2980
3064
  }
2981
3065
 
2982
3066
  // src/providers/transaction-summary/receipt.ts
2983
- import { ReceiptType as ReceiptType4 } from "@fuel-ts/transactions";
3067
+ import { ReceiptType as ReceiptType5 } from "@fuel-ts/transactions";
2984
3068
  var processGqlReceipt = (gqlReceipt) => {
2985
3069
  const receipt = assembleReceiptByType(gqlReceipt);
2986
3070
  switch (receipt.type) {
2987
- case ReceiptType4.ReturnData: {
3071
+ case ReceiptType5.ReturnData: {
2988
3072
  return {
2989
3073
  ...receipt,
2990
3074
  data: gqlReceipt.data || "0x"
2991
3075
  };
2992
3076
  }
2993
- case ReceiptType4.LogData: {
3077
+ case ReceiptType5.LogData: {
2994
3078
  return {
2995
3079
  ...receipt,
2996
3080
  data: gqlReceipt.data || "0x"
@@ -3003,7 +3087,7 @@ var processGqlReceipt = (gqlReceipt) => {
3003
3087
  var extractMintedAssetsFromReceipts = (receipts) => {
3004
3088
  const mintedAssets = [];
3005
3089
  receipts.forEach((receipt) => {
3006
- if (receipt.type === ReceiptType4.Mint) {
3090
+ if (receipt.type === ReceiptType5.Mint) {
3007
3091
  mintedAssets.push({
3008
3092
  subId: receipt.subId,
3009
3093
  contractId: receipt.contractId,
@@ -3017,7 +3101,7 @@ var extractMintedAssetsFromReceipts = (receipts) => {
3017
3101
  var extractBurnedAssetsFromReceipts = (receipts) => {
3018
3102
  const burnedAssets = [];
3019
3103
  receipts.forEach((receipt) => {
3020
- if (receipt.type === ReceiptType4.Burn) {
3104
+ if (receipt.type === ReceiptType5.Burn) {
3021
3105
  burnedAssets.push({
3022
3106
  subId: receipt.subId,
3023
3107
  contractId: receipt.contractId,
@@ -3030,7 +3114,7 @@ var extractBurnedAssetsFromReceipts = (receipts) => {
3030
3114
  };
3031
3115
 
3032
3116
  // src/providers/transaction-summary/status.ts
3033
- import { ErrorCode as ErrorCode10, FuelError as FuelError10 } from "@fuel-ts/errors";
3117
+ import { ErrorCode as ErrorCode11, FuelError as FuelError11 } from "@fuel-ts/errors";
3034
3118
  var getTransactionStatusName = (gqlStatus) => {
3035
3119
  switch (gqlStatus) {
3036
3120
  case "FailureStatus":
@@ -3042,8 +3126,8 @@ var getTransactionStatusName = (gqlStatus) => {
3042
3126
  case "SqueezedOutStatus":
3043
3127
  return "squeezedout" /* squeezedout */;
3044
3128
  default:
3045
- throw new FuelError10(
3046
- ErrorCode10.INVALID_TRANSACTION_STATUS,
3129
+ throw new FuelError11(
3130
+ ErrorCode11.INVALID_TRANSACTION_STATUS,
3047
3131
  `Invalid transaction status: ${gqlStatus}.`
3048
3132
  );
3049
3133
  }
@@ -3156,12 +3240,12 @@ function assembleTransactionSummary(params) {
3156
3240
 
3157
3241
  // src/providers/transaction-response/getDecodedLogs.ts
3158
3242
  import { Interface as Interface3, BigNumberCoder } from "@fuel-ts/abi-coder";
3159
- import { ReceiptType as ReceiptType5 } from "@fuel-ts/transactions";
3243
+ import { ReceiptType as ReceiptType6 } from "@fuel-ts/transactions";
3160
3244
  function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
3161
3245
  return receipts.reduce((logs, receipt) => {
3162
- if (receipt.type === ReceiptType5.LogData || receipt.type === ReceiptType5.Log) {
3246
+ if (receipt.type === ReceiptType6.LogData || receipt.type === ReceiptType6.Log) {
3163
3247
  const interfaceToUse = new Interface3(externalAbis[receipt.id] || mainAbi);
3164
- const data = receipt.type === ReceiptType5.Log ? new BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
3248
+ const data = receipt.type === ReceiptType6.Log ? new BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
3165
3249
  const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
3166
3250
  logs.push(decodedLog);
3167
3251
  }
@@ -3176,7 +3260,7 @@ var TransactionResponse = class {
3176
3260
  /** Current provider */
3177
3261
  provider;
3178
3262
  /** Gas used on the transaction */
3179
- gasUsed = bn13(0);
3263
+ gasUsed = bn14(0);
3180
3264
  /** The graphql Transaction with receipts object. */
3181
3265
  gqlTransaction;
3182
3266
  abis;
@@ -3281,8 +3365,8 @@ var TransactionResponse = class {
3281
3365
  });
3282
3366
  for await (const { statusChange } of subscription) {
3283
3367
  if (statusChange.type === "SqueezedOutStatus") {
3284
- throw new FuelError11(
3285
- ErrorCode11.TRANSACTION_SQUEEZED_OUT,
3368
+ throw new FuelError12(
3369
+ ErrorCode12.TRANSACTION_SQUEEZED_OUT,
3286
3370
  `Transaction Squeezed Out with reason: ${statusChange.reason}`
3287
3371
  );
3288
3372
  }
@@ -3304,14 +3388,26 @@ var TransactionResponse = class {
3304
3388
  gqlTransaction: this.gqlTransaction,
3305
3389
  ...transactionSummary
3306
3390
  };
3391
+ let logs = [];
3307
3392
  if (this.abis) {
3308
- const logs = getDecodedLogs(
3393
+ logs = getDecodedLogs(
3309
3394
  transactionSummary.receipts,
3310
3395
  this.abis.main,
3311
3396
  this.abis.otherContractsAbis
3312
3397
  );
3313
3398
  transactionResult.logs = logs;
3314
3399
  }
3400
+ if (transactionResult.isStatusFailure) {
3401
+ const {
3402
+ receipts,
3403
+ gqlTransaction: { status }
3404
+ } = transactionResult;
3405
+ throw extractTxError({
3406
+ receipts,
3407
+ status,
3408
+ logs
3409
+ });
3410
+ }
3315
3411
  return transactionResult;
3316
3412
  }
3317
3413
  /**
@@ -3320,14 +3416,7 @@ var TransactionResponse = class {
3320
3416
  * @param contractsAbiMap - The contracts ABI map.
3321
3417
  */
3322
3418
  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;
3419
+ return this.waitForResult(contractsAbiMap);
3331
3420
  }
3332
3421
  };
3333
3422
 
@@ -3389,29 +3478,29 @@ var processGqlChain = (chain) => {
3389
3478
  const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
3390
3479
  return {
3391
3480
  name,
3392
- baseChainHeight: bn14(daHeight),
3481
+ baseChainHeight: bn15(daHeight),
3393
3482
  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),
3483
+ contractMaxSize: bn15(contractParams.contractMaxSize),
3484
+ maxInputs: bn15(txParams.maxInputs),
3485
+ maxOutputs: bn15(txParams.maxOutputs),
3486
+ maxWitnesses: bn15(txParams.maxWitnesses),
3487
+ maxGasPerTx: bn15(txParams.maxGasPerTx),
3488
+ maxScriptLength: bn15(scriptParams.maxScriptLength),
3489
+ maxScriptDataLength: bn15(scriptParams.maxScriptDataLength),
3490
+ maxStorageSlots: bn15(contractParams.maxStorageSlots),
3491
+ maxPredicateLength: bn15(predicateParams.maxPredicateLength),
3492
+ maxPredicateDataLength: bn15(predicateParams.maxPredicateDataLength),
3493
+ maxGasPerPredicate: bn15(predicateParams.maxGasPerPredicate),
3494
+ gasPriceFactor: bn15(feeParams.gasPriceFactor),
3495
+ gasPerByte: bn15(feeParams.gasPerByte),
3496
+ maxMessageDataLength: bn15(predicateParams.maxMessageDataLength),
3497
+ chainId: bn15(consensusParameters.chainId),
3409
3498
  gasCosts
3410
3499
  },
3411
3500
  gasCosts,
3412
3501
  latestBlock: {
3413
3502
  id: latestBlock.id,
3414
- height: bn14(latestBlock.header.height),
3503
+ height: bn15(latestBlock.header.height),
3415
3504
  time: latestBlock.header.time,
3416
3505
  transactions: latestBlock.transactions.map((i) => ({
3417
3506
  id: i.id
@@ -3481,8 +3570,8 @@ var _Provider = class {
3481
3570
  getChain() {
3482
3571
  const chain = _Provider.chainInfoCache[this.url];
3483
3572
  if (!chain) {
3484
- throw new FuelError12(
3485
- ErrorCode12.CHAIN_INFO_CACHE_EMPTY,
3573
+ throw new FuelError13(
3574
+ ErrorCode13.CHAIN_INFO_CACHE_EMPTY,
3486
3575
  "Chain info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
3487
3576
  );
3488
3577
  }
@@ -3494,8 +3583,8 @@ var _Provider = class {
3494
3583
  getNode() {
3495
3584
  const node = _Provider.nodeInfoCache[this.url];
3496
3585
  if (!node) {
3497
- throw new FuelError12(
3498
- ErrorCode12.NODE_INFO_CACHE_EMPTY,
3586
+ throw new FuelError13(
3587
+ ErrorCode13.NODE_INFO_CACHE_EMPTY,
3499
3588
  "Node info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
3500
3589
  );
3501
3590
  }
@@ -3542,8 +3631,8 @@ var _Provider = class {
3542
3631
  static ensureClientVersionIsSupported(nodeInfo) {
3543
3632
  const { isMajorSupported, isMinorSupported, supportedVersion } = checkFuelCoreVersionCompatibility(nodeInfo.nodeVersion);
3544
3633
  if (!isMajorSupported || !isMinorSupported) {
3545
- throw new FuelError12(
3546
- FuelError12.CODES.UNSUPPORTED_FUEL_CLIENT_VERSION,
3634
+ throw new FuelError13(
3635
+ FuelError13.CODES.UNSUPPORTED_FUEL_CLIENT_VERSION,
3547
3636
  `Fuel client version: ${nodeInfo.nodeVersion}, Supported version: ${supportedVersion}`
3548
3637
  );
3549
3638
  }
@@ -3606,7 +3695,7 @@ var _Provider = class {
3606
3695
  */
3607
3696
  async getBlockNumber() {
3608
3697
  const { chain } = await this.operations.getChain();
3609
- return bn14(chain.latestBlock.header.height, 10);
3698
+ return bn15(chain.latestBlock.header.height, 10);
3610
3699
  }
3611
3700
  /**
3612
3701
  * Returns the chain information.
@@ -3616,9 +3705,9 @@ var _Provider = class {
3616
3705
  async fetchNode() {
3617
3706
  const { nodeInfo } = await this.operations.getNodeInfo();
3618
3707
  const processedNodeInfo = {
3619
- maxDepth: bn14(nodeInfo.maxDepth),
3620
- maxTx: bn14(nodeInfo.maxTx),
3621
- minGasPrice: bn14(nodeInfo.minGasPrice),
3708
+ maxDepth: bn15(nodeInfo.maxDepth),
3709
+ maxTx: bn15(nodeInfo.maxTx),
3710
+ minGasPrice: bn15(nodeInfo.minGasPrice),
3622
3711
  nodeVersion: nodeInfo.nodeVersion,
3623
3712
  utxoValidation: nodeInfo.utxoValidation,
3624
3713
  vmBacktrace: nodeInfo.vmBacktrace,
@@ -3673,8 +3762,8 @@ var _Provider = class {
3673
3762
  const subscription = this.operations.submitAndAwait({ encodedTransaction });
3674
3763
  for await (const { submitAndAwait } of subscription) {
3675
3764
  if (submitAndAwait.type === "SqueezedOutStatus") {
3676
- throw new FuelError12(
3677
- ErrorCode12.TRANSACTION_SQUEEZED_OUT,
3765
+ throw new FuelError13(
3766
+ ErrorCode13.TRANSACTION_SQUEEZED_OUT,
3678
3767
  `Transaction Squeezed Out with reason: ${submitAndAwait.reason}`
3679
3768
  );
3680
3769
  }
@@ -3741,7 +3830,7 @@ var _Provider = class {
3741
3830
  } = response;
3742
3831
  if (inputs) {
3743
3832
  inputs.forEach((input, index) => {
3744
- if ("predicateGasUsed" in input && bn14(input.predicateGasUsed).gt(0)) {
3833
+ if ("predicateGasUsed" in input && bn15(input.predicateGasUsed).gt(0)) {
3745
3834
  transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
3746
3835
  }
3747
3836
  });
@@ -3798,6 +3887,36 @@ var _Provider = class {
3798
3887
  missingContractIds
3799
3888
  };
3800
3889
  }
3890
+ /**
3891
+ * Estimates the transaction gas and fee based on the provided transaction request.
3892
+ * @param transactionRequest - The transaction request object.
3893
+ * @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
3894
+ */
3895
+ estimateTxGasAndFee(params) {
3896
+ const { transactionRequest } = params;
3897
+ const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
3898
+ const chainInfo = this.getChain();
3899
+ const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
3900
+ transactionRequest.gasPrice = gasPrice;
3901
+ const minGas = transactionRequest.calculateMinGas(chainInfo);
3902
+ const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
3903
+ if (transactionRequest.type === TransactionType8.Script) {
3904
+ if (transactionRequest.gasLimit.eq(0)) {
3905
+ transactionRequest.gasLimit = minGas;
3906
+ transactionRequest.gasLimit = maxGasPerTx.sub(
3907
+ transactionRequest.calculateMaxGas(chainInfo, minGas)
3908
+ );
3909
+ }
3910
+ }
3911
+ const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
3912
+ const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
3913
+ return {
3914
+ minGas,
3915
+ minFee,
3916
+ maxGas,
3917
+ maxFee
3918
+ };
3919
+ }
3801
3920
  /**
3802
3921
  * Executes a signed transaction without applying the states changes
3803
3922
  * on the chain.
@@ -3845,17 +3964,16 @@ var _Provider = class {
3845
3964
  signatureCallback
3846
3965
  } = {}) {
3847
3966
  const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
3848
- const chainInfo = this.getChain();
3849
- const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
3850
- const gasPrice = max(txRequestClone.gasPrice, minGasPrice);
3967
+ const { minGasPrice } = this.getGasConfig();
3968
+ const setGasPrice = max(txRequestClone.gasPrice, minGasPrice);
3851
3969
  const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
3852
3970
  const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
3853
3971
  const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
3854
3972
  txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
3973
+ if (isScriptTransaction) {
3974
+ txRequestClone.gasLimit = bn15(0);
3975
+ }
3855
3976
  if (estimatePredicates) {
3856
- if (isScriptTransaction) {
3857
- txRequestClone.gasLimit = bn14(0);
3858
- }
3859
3977
  if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
3860
3978
  resourcesOwner.populateTransactionPredicateData(txRequestClone);
3861
3979
  }
@@ -3864,36 +3982,34 @@ var _Provider = class {
3864
3982
  if (signatureCallback && isScriptTransaction) {
3865
3983
  await signatureCallback(txRequestClone);
3866
3984
  }
3867
- const minGas = txRequestClone.calculateMinGas(chainInfo);
3868
- const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
3985
+ let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
3986
+ transactionRequest: txRequestClone
3987
+ });
3869
3988
  let receipts = [];
3870
3989
  let missingContractIds = [];
3871
3990
  let outputVariables = 0;
3991
+ let gasUsed = bn15(0);
3872
3992
  if (isScriptTransaction && estimateTxDependencies) {
3873
- txRequestClone.gasPrice = bn14(0);
3874
- txRequestClone.gasLimit = bn14(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
3993
+ txRequestClone.gasPrice = bn15(0);
3875
3994
  const result = await this.estimateTxDependencies(txRequestClone);
3876
3995
  receipts = result.receipts;
3877
3996
  outputVariables = result.outputVariables;
3878
3997
  missingContractIds = result.missingContractIds;
3998
+ gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
3999
+ txRequestClone.gasLimit = gasUsed;
4000
+ txRequestClone.gasPrice = setGasPrice;
4001
+ ({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
4002
+ transactionRequest: txRequestClone
4003
+ }));
3879
4004
  }
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
4005
  return {
3889
4006
  requiredQuantities: allQuantities,
3890
4007
  receipts,
3891
4008
  gasUsed,
3892
4009
  minGasPrice,
3893
- gasPrice,
4010
+ gasPrice: setGasPrice,
3894
4011
  minGas,
3895
4012
  maxGas,
3896
- usedFee,
3897
4013
  minFee,
3898
4014
  maxFee,
3899
4015
  estimatedInputs: txRequestClone.inputs,
@@ -3933,11 +4049,11 @@ var _Provider = class {
3933
4049
  return coins.map((coin) => ({
3934
4050
  id: coin.utxoId,
3935
4051
  assetId: coin.assetId,
3936
- amount: bn14(coin.amount),
4052
+ amount: bn15(coin.amount),
3937
4053
  owner: Address2.fromAddressOrString(coin.owner),
3938
- maturity: bn14(coin.maturity).toNumber(),
3939
- blockCreated: bn14(coin.blockCreated),
3940
- txCreatedIdx: bn14(coin.txCreatedIdx)
4054
+ maturity: bn15(coin.maturity).toNumber(),
4055
+ blockCreated: bn15(coin.blockCreated),
4056
+ txCreatedIdx: bn15(coin.txCreatedIdx)
3941
4057
  }));
3942
4058
  }
3943
4059
  /**
@@ -3974,9 +4090,9 @@ var _Provider = class {
3974
4090
  switch (coin.__typename) {
3975
4091
  case "MessageCoin":
3976
4092
  return {
3977
- amount: bn14(coin.amount),
4093
+ amount: bn15(coin.amount),
3978
4094
  assetId: coin.assetId,
3979
- daHeight: bn14(coin.daHeight),
4095
+ daHeight: bn15(coin.daHeight),
3980
4096
  sender: Address2.fromAddressOrString(coin.sender),
3981
4097
  recipient: Address2.fromAddressOrString(coin.recipient),
3982
4098
  nonce: coin.nonce
@@ -3984,12 +4100,12 @@ var _Provider = class {
3984
4100
  case "Coin":
3985
4101
  return {
3986
4102
  id: coin.utxoId,
3987
- amount: bn14(coin.amount),
4103
+ amount: bn15(coin.amount),
3988
4104
  assetId: coin.assetId,
3989
4105
  owner: Address2.fromAddressOrString(coin.owner),
3990
- maturity: bn14(coin.maturity).toNumber(),
3991
- blockCreated: bn14(coin.blockCreated),
3992
- txCreatedIdx: bn14(coin.txCreatedIdx)
4106
+ maturity: bn15(coin.maturity).toNumber(),
4107
+ blockCreated: bn15(coin.blockCreated),
4108
+ txCreatedIdx: bn15(coin.txCreatedIdx)
3993
4109
  };
3994
4110
  default:
3995
4111
  return null;
@@ -4006,13 +4122,13 @@ var _Provider = class {
4006
4122
  async getBlock(idOrHeight) {
4007
4123
  let variables;
4008
4124
  if (typeof idOrHeight === "number") {
4009
- variables = { height: bn14(idOrHeight).toString(10) };
4125
+ variables = { height: bn15(idOrHeight).toString(10) };
4010
4126
  } else if (idOrHeight === "latest") {
4011
4127
  variables = { height: (await this.getBlockNumber()).toString(10) };
4012
4128
  } else if (idOrHeight.length === 66) {
4013
4129
  variables = { blockId: idOrHeight };
4014
4130
  } else {
4015
- variables = { blockId: bn14(idOrHeight).toString(10) };
4131
+ variables = { blockId: bn15(idOrHeight).toString(10) };
4016
4132
  }
4017
4133
  const { block } = await this.operations.getBlock(variables);
4018
4134
  if (!block) {
@@ -4020,7 +4136,7 @@ var _Provider = class {
4020
4136
  }
4021
4137
  return {
4022
4138
  id: block.id,
4023
- height: bn14(block.header.height),
4139
+ height: bn15(block.header.height),
4024
4140
  time: block.header.time,
4025
4141
  transactionIds: block.transactions.map((tx) => tx.id)
4026
4142
  };
@@ -4035,7 +4151,7 @@ var _Provider = class {
4035
4151
  const { blocks: fetchedData } = await this.operations.getBlocks(params);
4036
4152
  const blocks = fetchedData.edges.map(({ node: block }) => ({
4037
4153
  id: block.id,
4038
- height: bn14(block.header.height),
4154
+ height: bn15(block.header.height),
4039
4155
  time: block.header.time,
4040
4156
  transactionIds: block.transactions.map((tx) => tx.id)
4041
4157
  }));
@@ -4050,7 +4166,7 @@ var _Provider = class {
4050
4166
  async getBlockWithTransactions(idOrHeight) {
4051
4167
  let variables;
4052
4168
  if (typeof idOrHeight === "number") {
4053
- variables = { blockHeight: bn14(idOrHeight).toString(10) };
4169
+ variables = { blockHeight: bn15(idOrHeight).toString(10) };
4054
4170
  } else if (idOrHeight === "latest") {
4055
4171
  variables = { blockHeight: (await this.getBlockNumber()).toString() };
4056
4172
  } else {
@@ -4062,7 +4178,7 @@ var _Provider = class {
4062
4178
  }
4063
4179
  return {
4064
4180
  id: block.id,
4065
- height: bn14(block.header.height, 10),
4181
+ height: bn15(block.header.height, 10),
4066
4182
  time: block.header.time,
4067
4183
  transactionIds: block.transactions.map((tx) => tx.id),
4068
4184
  transactions: block.transactions.map(
@@ -4111,7 +4227,7 @@ var _Provider = class {
4111
4227
  contract: Address2.fromAddressOrString(contractId).toB256(),
4112
4228
  asset: hexlify12(assetId)
4113
4229
  });
4114
- return bn14(contractBalance.amount, 10);
4230
+ return bn15(contractBalance.amount, 10);
4115
4231
  }
4116
4232
  /**
4117
4233
  * Returns the balance for the given owner for the given asset ID.
@@ -4125,7 +4241,7 @@ var _Provider = class {
4125
4241
  owner: Address2.fromAddressOrString(owner).toB256(),
4126
4242
  assetId: hexlify12(assetId)
4127
4243
  });
4128
- return bn14(balance.amount, 10);
4244
+ return bn15(balance.amount, 10);
4129
4245
  }
4130
4246
  /**
4131
4247
  * Returns balances for the given owner.
@@ -4143,7 +4259,7 @@ var _Provider = class {
4143
4259
  const balances = result.balances.edges.map((edge) => edge.node);
4144
4260
  return balances.map((balance) => ({
4145
4261
  assetId: balance.assetId,
4146
- amount: bn14(balance.amount)
4262
+ amount: bn15(balance.amount)
4147
4263
  }));
4148
4264
  }
4149
4265
  /**
@@ -4165,15 +4281,15 @@ var _Provider = class {
4165
4281
  sender: message.sender,
4166
4282
  recipient: message.recipient,
4167
4283
  nonce: message.nonce,
4168
- amount: bn14(message.amount),
4284
+ amount: bn15(message.amount),
4169
4285
  data: message.data
4170
4286
  }),
4171
4287
  sender: Address2.fromAddressOrString(message.sender),
4172
4288
  recipient: Address2.fromAddressOrString(message.recipient),
4173
4289
  nonce: message.nonce,
4174
- amount: bn14(message.amount),
4290
+ amount: bn15(message.amount),
4175
4291
  data: InputMessageCoder.decodeData(message.data),
4176
- daHeight: bn14(message.daHeight)
4292
+ daHeight: bn15(message.daHeight)
4177
4293
  }));
4178
4294
  }
4179
4295
  /**
@@ -4191,8 +4307,8 @@ var _Provider = class {
4191
4307
  nonce
4192
4308
  };
4193
4309
  if (commitBlockId && commitBlockHeight) {
4194
- throw new FuelError12(
4195
- ErrorCode12.INVALID_INPUT_PARAMETERS,
4310
+ throw new FuelError13(
4311
+ ErrorCode13.INVALID_INPUT_PARAMETERS,
4196
4312
  "commitBlockId and commitBlockHeight cannot be used together"
4197
4313
  );
4198
4314
  }
@@ -4226,41 +4342,41 @@ var _Provider = class {
4226
4342
  } = result.messageProof;
4227
4343
  return {
4228
4344
  messageProof: {
4229
- proofIndex: bn14(messageProof.proofIndex),
4345
+ proofIndex: bn15(messageProof.proofIndex),
4230
4346
  proofSet: messageProof.proofSet
4231
4347
  },
4232
4348
  blockProof: {
4233
- proofIndex: bn14(blockProof.proofIndex),
4349
+ proofIndex: bn15(blockProof.proofIndex),
4234
4350
  proofSet: blockProof.proofSet
4235
4351
  },
4236
4352
  messageBlockHeader: {
4237
4353
  id: messageBlockHeader.id,
4238
- daHeight: bn14(messageBlockHeader.daHeight),
4239
- transactionsCount: bn14(messageBlockHeader.transactionsCount),
4354
+ daHeight: bn15(messageBlockHeader.daHeight),
4355
+ transactionsCount: bn15(messageBlockHeader.transactionsCount),
4240
4356
  transactionsRoot: messageBlockHeader.transactionsRoot,
4241
- height: bn14(messageBlockHeader.height),
4357
+ height: bn15(messageBlockHeader.height),
4242
4358
  prevRoot: messageBlockHeader.prevRoot,
4243
4359
  time: messageBlockHeader.time,
4244
4360
  applicationHash: messageBlockHeader.applicationHash,
4245
4361
  messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
4246
- messageReceiptCount: bn14(messageBlockHeader.messageReceiptCount)
4362
+ messageReceiptCount: bn15(messageBlockHeader.messageReceiptCount)
4247
4363
  },
4248
4364
  commitBlockHeader: {
4249
4365
  id: commitBlockHeader.id,
4250
- daHeight: bn14(commitBlockHeader.daHeight),
4251
- transactionsCount: bn14(commitBlockHeader.transactionsCount),
4366
+ daHeight: bn15(commitBlockHeader.daHeight),
4367
+ transactionsCount: bn15(commitBlockHeader.transactionsCount),
4252
4368
  transactionsRoot: commitBlockHeader.transactionsRoot,
4253
- height: bn14(commitBlockHeader.height),
4369
+ height: bn15(commitBlockHeader.height),
4254
4370
  prevRoot: commitBlockHeader.prevRoot,
4255
4371
  time: commitBlockHeader.time,
4256
4372
  applicationHash: commitBlockHeader.applicationHash,
4257
4373
  messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
4258
- messageReceiptCount: bn14(commitBlockHeader.messageReceiptCount)
4374
+ messageReceiptCount: bn15(commitBlockHeader.messageReceiptCount)
4259
4375
  },
4260
4376
  sender: Address2.fromAddressOrString(sender),
4261
4377
  recipient: Address2.fromAddressOrString(recipient),
4262
4378
  nonce,
4263
- amount: bn14(amount),
4379
+ amount: bn15(amount),
4264
4380
  data
4265
4381
  };
4266
4382
  }
@@ -4283,10 +4399,10 @@ var _Provider = class {
4283
4399
  */
4284
4400
  async produceBlocks(amount, startTime) {
4285
4401
  const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
4286
- blocksToProduce: bn14(amount).toString(10),
4402
+ blocksToProduce: bn15(amount).toString(10),
4287
4403
  startTimestamp: startTime ? DateTime2.fromUnixMilliseconds(startTime).toTai64() : void 0
4288
4404
  });
4289
- return bn14(latestBlockHeight);
4405
+ return bn15(latestBlockHeight);
4290
4406
  }
4291
4407
  // eslint-disable-next-line @typescript-eslint/require-await
4292
4408
  async getTransactionResponse(transactionId) {
@@ -4309,8 +4425,8 @@ __publicField(Provider, "chainInfoCache", {});
4309
4425
  __publicField(Provider, "nodeInfoCache", {});
4310
4426
 
4311
4427
  // 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";
4428
+ import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
4429
+ import { bn as bn16 } from "@fuel-ts/math";
4314
4430
  import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
4315
4431
  import { arrayify as arrayify12 } from "@fuel-ts/utils";
4316
4432
 
@@ -4427,7 +4543,7 @@ var Account = class extends AbstractAccount {
4427
4543
  */
4428
4544
  get provider() {
4429
4545
  if (!this._provider) {
4430
- throw new FuelError14(ErrorCode14.MISSING_PROVIDER, "Provider not set");
4546
+ throw new FuelError15(ErrorCode15.MISSING_PROVIDER, "Provider not set");
4431
4547
  }
4432
4548
  return this._provider;
4433
4549
  }
@@ -4479,8 +4595,8 @@ var Account = class extends AbstractAccount {
4479
4595
  if (!hasNextPage) {
4480
4596
  break;
4481
4597
  }
4482
- throw new FuelError14(
4483
- ErrorCode14.NOT_SUPPORTED,
4598
+ throw new FuelError15(
4599
+ ErrorCode15.NOT_SUPPORTED,
4484
4600
  `Wallets containing more than ${pageSize} coins exceed the current supported limit.`
4485
4601
  );
4486
4602
  }
@@ -4505,8 +4621,8 @@ var Account = class extends AbstractAccount {
4505
4621
  if (!hasNextPage) {
4506
4622
  break;
4507
4623
  }
4508
- throw new FuelError14(
4509
- ErrorCode14.NOT_SUPPORTED,
4624
+ throw new FuelError15(
4625
+ ErrorCode15.NOT_SUPPORTED,
4510
4626
  `Wallets containing more than ${pageSize} messages exceed the current supported limit.`
4511
4627
  );
4512
4628
  }
@@ -4541,8 +4657,8 @@ var Account = class extends AbstractAccount {
4541
4657
  if (!hasNextPage) {
4542
4658
  break;
4543
4659
  }
4544
- throw new FuelError14(
4545
- ErrorCode14.NOT_SUPPORTED,
4660
+ throw new FuelError15(
4661
+ ErrorCode15.NOT_SUPPORTED,
4546
4662
  `Wallets containing more than ${pageSize} balances exceed the current supported limit.`
4547
4663
  );
4548
4664
  }
@@ -4558,7 +4674,7 @@ var Account = class extends AbstractAccount {
4558
4674
  */
4559
4675
  async fund(request, coinQuantities, fee) {
4560
4676
  const updatedQuantities = addAmountToAsset({
4561
- amount: bn16(fee),
4677
+ amount: bn17(fee),
4562
4678
  assetId: BaseAssetId3,
4563
4679
  coinQuantities
4564
4680
  });
@@ -4566,7 +4682,7 @@ var Account = class extends AbstractAccount {
4566
4682
  updatedQuantities.forEach(({ amount, assetId }) => {
4567
4683
  quantitiesDict[assetId] = {
4568
4684
  required: amount,
4569
- owned: bn16(0)
4685
+ owned: bn17(0)
4570
4686
  };
4571
4687
  });
4572
4688
  const cachedUtxos = [];
@@ -4579,7 +4695,7 @@ var Account = class extends AbstractAccount {
4579
4695
  if (isCoin2) {
4580
4696
  const assetId = String(input.assetId);
4581
4697
  if (input.owner === owner && quantitiesDict[assetId]) {
4582
- const amount = bn16(input.amount);
4698
+ const amount = bn17(input.amount);
4583
4699
  quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
4584
4700
  cachedUtxos.push(input.id);
4585
4701
  }
@@ -4625,8 +4741,8 @@ var Account = class extends AbstractAccount {
4625
4741
  estimateTxDependencies: true,
4626
4742
  resourcesOwner: this
4627
4743
  });
4628
- request.gasPrice = bn16(txParams.gasPrice ?? minGasPrice);
4629
- request.gasLimit = bn16(txParams.gasLimit ?? gasUsed);
4744
+ request.gasPrice = bn17(txParams.gasPrice ?? minGasPrice);
4745
+ request.gasLimit = bn17(txParams.gasLimit ?? gasUsed);
4630
4746
  this.validateGas({
4631
4747
  gasUsed,
4632
4748
  gasPrice: request.gasPrice,
@@ -4647,9 +4763,9 @@ var Account = class extends AbstractAccount {
4647
4763
  * @returns A promise that resolves to the transaction response.
4648
4764
  */
4649
4765
  async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
4650
- if (bn16(amount).lte(0)) {
4651
- throw new FuelError14(
4652
- ErrorCode14.INVALID_TRANSFER_AMOUNT,
4766
+ if (bn17(amount).lte(0)) {
4767
+ throw new FuelError15(
4768
+ ErrorCode15.INVALID_TRANSFER_AMOUNT,
4653
4769
  "Transfer amount must be a positive number."
4654
4770
  );
4655
4771
  }
@@ -4666,9 +4782,9 @@ var Account = class extends AbstractAccount {
4666
4782
  * @returns A promise that resolves to the transaction response.
4667
4783
  */
4668
4784
  async transferToContract(contractId, amount, assetId = BaseAssetId3, txParams = {}) {
4669
- if (bn16(amount).lte(0)) {
4670
- throw new FuelError14(
4671
- ErrorCode14.INVALID_TRANSFER_AMOUNT,
4785
+ if (bn17(amount).lte(0)) {
4786
+ throw new FuelError15(
4787
+ ErrorCode15.INVALID_TRANSFER_AMOUNT,
4672
4788
  "Transfer amount must be a positive number."
4673
4789
  );
4674
4790
  }
@@ -4677,7 +4793,7 @@ var Account = class extends AbstractAccount {
4677
4793
  const params = { gasPrice: minGasPrice, ...txParams };
4678
4794
  const { script, scriptData } = await assembleTransferToContractScript({
4679
4795
  hexlifiedContractId: contractAddress.toB256(),
4680
- amountToTransfer: bn16(amount),
4796
+ amountToTransfer: bn17(amount),
4681
4797
  assetId
4682
4798
  });
4683
4799
  const request = new ScriptTransactionRequest({
@@ -4688,9 +4804,9 @@ var Account = class extends AbstractAccount {
4688
4804
  request.addContractInputAndOutput(contractAddress);
4689
4805
  const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
4690
4806
  request,
4691
- [{ amount: bn16(amount), assetId: String(assetId) }]
4807
+ [{ amount: bn17(amount), assetId: String(assetId) }]
4692
4808
  );
4693
- request.gasLimit = bn16(params.gasLimit ?? gasUsed);
4809
+ request.gasLimit = bn17(params.gasLimit ?? gasUsed);
4694
4810
  this.validateGas({
4695
4811
  gasUsed,
4696
4812
  gasPrice: request.gasPrice,
@@ -4715,7 +4831,7 @@ var Account = class extends AbstractAccount {
4715
4831
  "0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
4716
4832
  );
4717
4833
  const amountDataArray = arrayify14(
4718
- "0x".concat(bn16(amount).toHex().substring(2).padStart(16, "0"))
4834
+ "0x".concat(bn17(amount).toHex().substring(2).padStart(16, "0"))
4719
4835
  );
4720
4836
  const script = new Uint8Array([
4721
4837
  ...arrayify14(withdrawScript.bytes),
@@ -4724,12 +4840,12 @@ var Account = class extends AbstractAccount {
4724
4840
  ]);
4725
4841
  const params = { script, gasPrice: minGasPrice, ...txParams };
4726
4842
  const request = new ScriptTransactionRequest(params);
4727
- const forwardingQuantities = [{ amount: bn16(amount), assetId: BaseAssetId3 }];
4843
+ const forwardingQuantities = [{ amount: bn17(amount), assetId: BaseAssetId3 }];
4728
4844
  const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
4729
4845
  request,
4730
4846
  forwardingQuantities
4731
4847
  );
4732
- request.gasLimit = bn16(params.gasLimit ?? gasUsed);
4848
+ request.gasLimit = bn17(params.gasLimit ?? gasUsed);
4733
4849
  this.validateGas({
4734
4850
  gasUsed,
4735
4851
  gasPrice: request.gasPrice,
@@ -4741,7 +4857,7 @@ var Account = class extends AbstractAccount {
4741
4857
  }
4742
4858
  async signMessage(message) {
4743
4859
  if (!this._connector) {
4744
- throw new FuelError14(ErrorCode14.MISSING_CONNECTOR, "A connector is required to sign messages.");
4860
+ throw new FuelError15(ErrorCode15.MISSING_CONNECTOR, "A connector is required to sign messages.");
4745
4861
  }
4746
4862
  return this._connector.signMessage(this.address.toString(), message);
4747
4863
  }
@@ -4753,8 +4869,8 @@ var Account = class extends AbstractAccount {
4753
4869
  */
4754
4870
  async signTransaction(transactionRequestLike) {
4755
4871
  if (!this._connector) {
4756
- throw new FuelError14(
4757
- ErrorCode14.MISSING_CONNECTOR,
4872
+ throw new FuelError15(
4873
+ ErrorCode15.MISSING_CONNECTOR,
4758
4874
  "A connector is required to sign transactions."
4759
4875
  );
4760
4876
  }
@@ -4801,14 +4917,14 @@ var Account = class extends AbstractAccount {
4801
4917
  minGasPrice
4802
4918
  }) {
4803
4919
  if (minGasPrice.gt(gasPrice)) {
4804
- throw new FuelError14(
4805
- ErrorCode14.GAS_PRICE_TOO_LOW,
4920
+ throw new FuelError15(
4921
+ ErrorCode15.GAS_PRICE_TOO_LOW,
4806
4922
  `Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
4807
4923
  );
4808
4924
  }
4809
4925
  if (gasUsed.gt(gasLimit)) {
4810
- throw new FuelError14(
4811
- ErrorCode14.GAS_LIMIT_TOO_LOW,
4926
+ throw new FuelError15(
4927
+ ErrorCode15.GAS_LIMIT_TOO_LOW,
4812
4928
  `Gas limit '${gasLimit}' is lower than the required: '${gasUsed}'.`
4813
4929
  );
4814
4930
  }
@@ -4817,7 +4933,7 @@ var Account = class extends AbstractAccount {
4817
4933
 
4818
4934
  // src/signer/signer.ts
4819
4935
  import { Address as Address4 } from "@fuel-ts/address";
4820
- import { randomBytes } from "@fuel-ts/crypto";
4936
+ import { randomBytes as randomBytes2 } from "@fuel-ts/crypto";
4821
4937
  import { hash } from "@fuel-ts/hasher";
4822
4938
  import { toBytes } from "@fuel-ts/math";
4823
4939
  import { hexlify as hexlify13, concat as concat3, arrayify as arrayify15 } from "@fuel-ts/utils";
@@ -4910,7 +5026,7 @@ var Signer = class {
4910
5026
  * @returns random 32-byte hashed
4911
5027
  */
4912
5028
  static generatePrivateKey(entropy) {
4913
- return entropy ? hash(concat3([randomBytes(32), arrayify15(entropy)])) : randomBytes(32);
5029
+ return entropy ? hash(concat3([randomBytes2(32), arrayify15(entropy)])) : randomBytes2(32);
4914
5030
  }
4915
5031
  /**
4916
5032
  * Extended publicKey from a compact publicKey
@@ -4929,13 +5045,13 @@ import { Address as Address5 } from "@fuel-ts/address";
4929
5045
  import {
4930
5046
  bufferFromString,
4931
5047
  keccak256,
4932
- randomBytes as randomBytes2,
5048
+ randomBytes as randomBytes3,
4933
5049
  scrypt,
4934
5050
  stringFromBuffer,
4935
5051
  decryptJsonWalletData,
4936
5052
  encryptJsonWalletData
4937
5053
  } from "@fuel-ts/crypto";
4938
- import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
5054
+ import { ErrorCode as ErrorCode16, FuelError as FuelError16 } from "@fuel-ts/errors";
4939
5055
  import { hexlify as hexlify14 } from "@fuel-ts/utils";
4940
5056
  import { v4 as uuidv4 } from "uuid";
4941
5057
  var DEFAULT_KDF_PARAMS_LOG_N = 13;
@@ -4952,7 +5068,7 @@ var removeHexPrefix = (hexString) => {
4952
5068
  async function encryptKeystoreWallet(privateKey, address, password) {
4953
5069
  const privateKeyBuffer = bufferFromString(removeHexPrefix(privateKey), "hex");
4954
5070
  const ownerAddress = Address5.fromAddressOrString(address);
4955
- const salt = randomBytes2(DEFAULT_KEY_SIZE);
5071
+ const salt = randomBytes3(DEFAULT_KEY_SIZE);
4956
5072
  const key = scrypt({
4957
5073
  password: bufferFromString(password),
4958
5074
  salt,
@@ -4961,7 +5077,7 @@ async function encryptKeystoreWallet(privateKey, address, password) {
4961
5077
  r: DEFAULT_KDF_PARAMS_R,
4962
5078
  p: DEFAULT_KDF_PARAMS_P
4963
5079
  });
4964
- const iv = randomBytes2(DEFAULT_IV_SIZE);
5080
+ const iv = randomBytes3(DEFAULT_IV_SIZE);
4965
5081
  const ciphertext = await encryptJsonWalletData(privateKeyBuffer, key, iv);
4966
5082
  const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertext]);
4967
5083
  const macHashUint8Array = keccak256(data);
@@ -5013,8 +5129,8 @@ async function decryptKeystoreWallet(jsonWallet, password) {
5013
5129
  const macHashUint8Array = keccak256(data);
5014
5130
  const macHash = stringFromBuffer(macHashUint8Array, "hex");
5015
5131
  if (mac !== macHash) {
5016
- throw new FuelError15(
5017
- ErrorCode15.INVALID_PASSWORD,
5132
+ throw new FuelError16(
5133
+ ErrorCode16.INVALID_PASSWORD,
5018
5134
  "Failed to decrypt the keystore wallet, the provided password is incorrect."
5019
5135
  );
5020
5136
  }
@@ -5136,15 +5252,15 @@ var BaseWalletUnlocked = class extends Account {
5136
5252
  __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
5137
5253
 
5138
5254
  // src/hdwallet/hdwallet.ts
5139
- import { ErrorCode as ErrorCode18, FuelError as FuelError18 } from "@fuel-ts/errors";
5255
+ import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
5140
5256
  import { sha256 as sha2564 } from "@fuel-ts/hasher";
5141
- import { bn as bn17, toBytes as toBytes2, toHex } from "@fuel-ts/math";
5257
+ import { bn as bn18, toBytes as toBytes2, toHex } from "@fuel-ts/math";
5142
5258
  import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
5143
5259
  import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
5144
5260
 
5145
5261
  // 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";
5262
+ import { randomBytes as randomBytes4 } from "@fuel-ts/crypto";
5263
+ import { ErrorCode as ErrorCode18, FuelError as FuelError18 } from "@fuel-ts/errors";
5148
5264
  import { sha256 as sha2563 } from "@fuel-ts/hasher";
5149
5265
  import { arrayify as arrayify17, hexlify as hexlify16, concat as concat4 } from "@fuel-ts/utils";
5150
5266
  import { dataSlice, pbkdf2, computeHmac, encodeBase58 } from "ethers";
@@ -7202,7 +7318,7 @@ var english = [
7202
7318
  ];
7203
7319
 
7204
7320
  // src/mnemonic/utils.ts
7205
- import { ErrorCode as ErrorCode16, FuelError as FuelError16 } from "@fuel-ts/errors";
7321
+ import { ErrorCode as ErrorCode17, FuelError as FuelError17 } from "@fuel-ts/errors";
7206
7322
  import { sha256 as sha2562 } from "@fuel-ts/hasher";
7207
7323
  import { arrayify as arrayify16 } from "@fuel-ts/utils";
7208
7324
  function toUtf8Bytes(stri) {
@@ -7219,8 +7335,8 @@ function toUtf8Bytes(stri) {
7219
7335
  i += 1;
7220
7336
  const c2 = str.charCodeAt(i);
7221
7337
  if (i >= str.length || (c2 & 64512) !== 56320) {
7222
- throw new FuelError16(
7223
- ErrorCode16.INVALID_INPUT_PARAMETERS,
7338
+ throw new FuelError17(
7339
+ ErrorCode17.INVALID_INPUT_PARAMETERS,
7224
7340
  "Invalid UTF-8 in the input string."
7225
7341
  );
7226
7342
  }
@@ -7283,8 +7399,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
7283
7399
  for (let i = 0; i < words.length; i += 1) {
7284
7400
  const index = wordlist.indexOf(words[i].normalize("NFKD"));
7285
7401
  if (index === -1) {
7286
- throw new FuelError16(
7287
- ErrorCode16.INVALID_MNEMONIC,
7402
+ throw new FuelError17(
7403
+ ErrorCode17.INVALID_MNEMONIC,
7288
7404
  `Invalid mnemonic: the word '${words[i]}' is not found in the provided wordlist.`
7289
7405
  );
7290
7406
  }
@@ -7300,8 +7416,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
7300
7416
  const checksumMask = getUpperMask(checksumBits);
7301
7417
  const checksum = arrayify16(sha2562(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
7302
7418
  if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
7303
- throw new FuelError16(
7304
- ErrorCode16.INVALID_CHECKSUM,
7419
+ throw new FuelError17(
7420
+ ErrorCode17.INVALID_CHECKSUM,
7305
7421
  "Checksum validation failed for the provided mnemonic."
7306
7422
  );
7307
7423
  }
@@ -7315,16 +7431,16 @@ var TestnetPRV = "0x04358394";
7315
7431
  var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
7316
7432
  function assertWordList(wordlist) {
7317
7433
  if (wordlist.length !== 2048) {
7318
- throw new FuelError17(
7319
- ErrorCode17.INVALID_WORD_LIST,
7434
+ throw new FuelError18(
7435
+ ErrorCode18.INVALID_WORD_LIST,
7320
7436
  `Expected word list length of 2048, but got ${wordlist.length}.`
7321
7437
  );
7322
7438
  }
7323
7439
  }
7324
7440
  function assertEntropy(entropy) {
7325
7441
  if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {
7326
- throw new FuelError17(
7327
- ErrorCode17.INVALID_ENTROPY,
7442
+ throw new FuelError18(
7443
+ ErrorCode18.INVALID_ENTROPY,
7328
7444
  `Entropy should be between 16 and 32 bytes and a multiple of 4, but got ${entropy.length} bytes.`
7329
7445
  );
7330
7446
  }
@@ -7334,7 +7450,7 @@ function assertMnemonic(words) {
7334
7450
  const errorMsg = `Invalid mnemonic size. Expected one of [${MNEMONIC_SIZES.join(
7335
7451
  ", "
7336
7452
  )}] words, but got ${words.length}.`;
7337
- throw new FuelError17(ErrorCode17.INVALID_MNEMONIC, errorMsg);
7453
+ throw new FuelError18(ErrorCode18.INVALID_MNEMONIC, errorMsg);
7338
7454
  }
7339
7455
  }
7340
7456
  var Mnemonic = class {
@@ -7452,8 +7568,8 @@ var Mnemonic = class {
7452
7568
  static masterKeysFromSeed(seed) {
7453
7569
  const seedArray = arrayify17(seed);
7454
7570
  if (seedArray.length < 16 || seedArray.length > 64) {
7455
- throw new FuelError17(
7456
- ErrorCode17.INVALID_SEED,
7571
+ throw new FuelError18(
7572
+ ErrorCode18.INVALID_SEED,
7457
7573
  `Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
7458
7574
  );
7459
7575
  }
@@ -7498,7 +7614,7 @@ var Mnemonic = class {
7498
7614
  * @returns A randomly generated mnemonic
7499
7615
  */
7500
7616
  static generate(size = 32, extraEntropy = "") {
7501
- const entropy = extraEntropy ? sha2563(concat4([randomBytes3(size), arrayify17(extraEntropy)])) : randomBytes3(size);
7617
+ const entropy = extraEntropy ? sha2563(concat4([randomBytes4(size), arrayify17(extraEntropy)])) : randomBytes4(size);
7502
7618
  return Mnemonic.entropyToMnemonic(entropy);
7503
7619
  }
7504
7620
  };
@@ -7530,7 +7646,7 @@ function isValidExtendedKey(extendedKey) {
7530
7646
  function parsePath(path2, depth = 0) {
7531
7647
  const components = path2.split("/");
7532
7648
  if (components.length === 0 || components[0] === "m" && depth !== 0) {
7533
- throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, `invalid path - ${path2}`);
7649
+ throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, `invalid path - ${path2}`);
7534
7650
  }
7535
7651
  if (components[0] === "m") {
7536
7652
  components.shift();
@@ -7559,8 +7675,8 @@ var HDWallet = class {
7559
7675
  this.privateKey = hexlify17(config.privateKey);
7560
7676
  } else {
7561
7677
  if (!config.publicKey) {
7562
- throw new FuelError18(
7563
- ErrorCode18.HD_WALLET_ERROR,
7678
+ throw new FuelError19(
7679
+ ErrorCode19.HD_WALLET_ERROR,
7564
7680
  "Both public and private Key cannot be missing. At least one should be provided."
7565
7681
  );
7566
7682
  }
@@ -7589,8 +7705,8 @@ var HDWallet = class {
7589
7705
  const data = new Uint8Array(37);
7590
7706
  if (index & HARDENED_INDEX) {
7591
7707
  if (!privateKey) {
7592
- throw new FuelError18(
7593
- ErrorCode18.HD_WALLET_ERROR,
7708
+ throw new FuelError19(
7709
+ ErrorCode19.HD_WALLET_ERROR,
7594
7710
  "Cannot derive a hardened index without a private Key."
7595
7711
  );
7596
7712
  }
@@ -7604,7 +7720,7 @@ var HDWallet = class {
7604
7720
  const IR = bytes.slice(32);
7605
7721
  if (privateKey) {
7606
7722
  const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
7607
- const ki = bn17(IL).add(privateKey).mod(N).toBytes(32);
7723
+ const ki = bn18(IL).add(privateKey).mod(N).toBytes(32);
7608
7724
  return new HDWallet({
7609
7725
  privateKey: ki,
7610
7726
  chainCode: IR,
@@ -7642,8 +7758,8 @@ var HDWallet = class {
7642
7758
  */
7643
7759
  toExtendedKey(isPublic = false, testnet = false) {
7644
7760
  if (this.depth >= 256) {
7645
- throw new FuelError18(
7646
- ErrorCode18.HD_WALLET_ERROR,
7761
+ throw new FuelError19(
7762
+ ErrorCode19.HD_WALLET_ERROR,
7647
7763
  `Exceeded max depth of 255. Current depth: ${this.depth}.`
7648
7764
  );
7649
7765
  }
@@ -7674,10 +7790,10 @@ var HDWallet = class {
7674
7790
  const bytes = arrayify18(decoded);
7675
7791
  const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
7676
7792
  if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
7677
- throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
7793
+ throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
7678
7794
  }
7679
7795
  if (!validChecksum) {
7680
- throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
7796
+ throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
7681
7797
  }
7682
7798
  const depth = bytes[4];
7683
7799
  const parentFingerprint = hexlify17(bytes.slice(5, 9));
@@ -7685,14 +7801,14 @@ var HDWallet = class {
7685
7801
  const chainCode = hexlify17(bytes.slice(13, 45));
7686
7802
  const key = bytes.slice(45, 78);
7687
7803
  if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
7688
- throw new FuelError18(
7689
- ErrorCode18.HD_WALLET_ERROR,
7804
+ throw new FuelError19(
7805
+ ErrorCode19.HD_WALLET_ERROR,
7690
7806
  "Inconsistency detected: Depth is zero but fingerprint/index is non-zero."
7691
7807
  );
7692
7808
  }
7693
7809
  if (isPublicExtendedKey(bytes)) {
7694
7810
  if (key[0] !== 3) {
7695
- throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, "Invalid public extended key.");
7811
+ throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, "Invalid public extended key.");
7696
7812
  }
7697
7813
  return new HDWallet({
7698
7814
  publicKey: key,
@@ -7703,7 +7819,7 @@ var HDWallet = class {
7703
7819
  });
7704
7820
  }
7705
7821
  if (key[0] !== 0) {
7706
- throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, "Invalid private extended key.");
7822
+ throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, "Invalid private extended key.");
7707
7823
  }
7708
7824
  return new HDWallet({
7709
7825
  privateKey: key.slice(1),
@@ -7869,10 +7985,10 @@ __publicField(Wallet, "fromExtendedKey", WalletUnlocked.fromExtendedKey);
7869
7985
  __publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
7870
7986
 
7871
7987
  // src/test-utils/seedTestWallet.ts
7872
- import { randomBytes as randomBytes4 } from "@fuel-ts/crypto";
7988
+ import { randomBytes as randomBytes5 } from "@fuel-ts/crypto";
7873
7989
  var seedTestWallet = async (wallet, quantities) => {
7874
7990
  const genesisWallet = new WalletUnlocked(
7875
- process.env.GENESIS_SECRET || randomBytes4(32),
7991
+ process.env.GENESIS_SECRET || randomBytes5(32),
7876
7992
  wallet.provider
7877
7993
  );
7878
7994
  const resources = await genesisWallet.getResourcesToSpend(quantities);