@fuel-ts/account 0.0.0-pr-1788-20240222094224 → 0.0.0-pr-1864-20240312141036

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 (58) hide show
  1. package/dist/account.d.ts.map +1 -1
  2. package/dist/connectors/fuel-connector.d.ts +2 -1
  3. package/dist/connectors/fuel-connector.d.ts.map +1 -1
  4. package/dist/connectors/types/data-type.d.ts +0 -8
  5. package/dist/connectors/types/data-type.d.ts.map +1 -1
  6. package/dist/connectors/types/events.d.ts +2 -36
  7. package/dist/connectors/types/events.d.ts.map +1 -1
  8. package/dist/connectors/types/index.d.ts +0 -2
  9. package/dist/connectors/types/index.d.ts.map +1 -1
  10. package/dist/hdwallet/hdwallet.d.ts.map +1 -1
  11. package/dist/index.global.js +1524 -2888
  12. package/dist/index.global.js.map +1 -1
  13. package/dist/index.js +234 -243
  14. package/dist/index.js.map +1 -1
  15. package/dist/index.mjs +287 -298
  16. package/dist/index.mjs.map +1 -1
  17. package/dist/mnemonic/mnemonic.d.ts.map +1 -1
  18. package/dist/mnemonic/utils.d.ts.map +1 -1
  19. package/dist/predicate/predicate.d.ts +16 -15
  20. package/dist/predicate/predicate.d.ts.map +1 -1
  21. package/dist/providers/__generated__/operations.d.ts +47 -38
  22. package/dist/providers/__generated__/operations.d.ts.map +1 -1
  23. package/dist/providers/fuel-graphql-subscriber.d.ts +13 -3
  24. package/dist/providers/fuel-graphql-subscriber.d.ts.map +1 -1
  25. package/dist/providers/provider.d.ts +28 -12
  26. package/dist/providers/provider.d.ts.map +1 -1
  27. package/dist/providers/transaction-request/hash-transaction.d.ts.map +1 -1
  28. package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
  29. package/dist/providers/transaction-response/getDecodedLogs.d.ts.map +1 -1
  30. package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
  31. package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
  32. package/dist/providers/transaction-summary/index.d.ts +0 -1
  33. package/dist/providers/transaction-summary/index.d.ts.map +1 -1
  34. package/dist/providers/transaction-summary/operations.d.ts +0 -2
  35. package/dist/providers/transaction-summary/operations.d.ts.map +1 -1
  36. package/dist/providers/transaction-summary/output.d.ts +2 -2
  37. package/dist/providers/transaction-summary/output.d.ts.map +1 -1
  38. package/dist/providers/transaction-summary/types.d.ts +0 -1
  39. package/dist/providers/transaction-summary/types.d.ts.map +1 -1
  40. package/dist/providers/utils/index.d.ts +0 -1
  41. package/dist/providers/utils/index.d.ts.map +1 -1
  42. package/dist/test-utils.global.js +1498 -2850
  43. package/dist/test-utils.global.js.map +1 -1
  44. package/dist/test-utils.js +211 -199
  45. package/dist/test-utils.js.map +1 -1
  46. package/dist/test-utils.mjs +244 -240
  47. package/dist/test-utils.mjs.map +1 -1
  48. package/package.json +16 -16
  49. package/dist/connectors/types/asset.d.ts +0 -2
  50. package/dist/connectors/types/asset.d.ts.map +0 -1
  51. package/dist/connectors/types/constants.d.ts +0 -7
  52. package/dist/connectors/types/constants.d.ts.map +0 -1
  53. package/dist/connectors/types/message.d.ts +0 -15
  54. package/dist/connectors/types/message.d.ts.map +0 -1
  55. package/dist/providers/transaction-summary/date.d.ts +0 -3
  56. package/dist/providers/transaction-summary/date.d.ts.map +0 -1
  57. package/dist/providers/utils/time.d.ts +0 -40
  58. package/dist/providers/utils/time.d.ts.map +0 -1
@@ -62,7 +62,7 @@ var import_utils30 = require("@fuel-ts/utils");
62
62
 
63
63
  // src/account.ts
64
64
  var import_address4 = require("@fuel-ts/address");
65
- var import_configs10 = require("@fuel-ts/address/configs");
65
+ var import_configs11 = require("@fuel-ts/address/configs");
66
66
  var import_errors15 = require("@fuel-ts/errors");
67
67
  var import_interfaces = require("@fuel-ts/interfaces");
68
68
  var import_math17 = require("@fuel-ts/math");
@@ -112,7 +112,7 @@ var import_transactions17 = require("@fuel-ts/transactions");
112
112
  var import_utils22 = require("@fuel-ts/utils");
113
113
  var import_versions = require("@fuel-ts/versions");
114
114
  var import_utils23 = require("@noble/curves/abstract/utils");
115
- var import_ethers2 = require("ethers");
115
+ var import_ethers = require("ethers");
116
116
  var import_graphql_request = require("graphql-request");
117
117
  var import_ramda3 = require("ramda");
118
118
 
@@ -177,6 +177,9 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
177
177
  time
178
178
  reason
179
179
  }
180
+ ... on SqueezedOutStatus {
181
+ reason
182
+ }
180
183
  }
181
184
  `;
182
185
  var TransactionFragmentFragmentDoc = import_graphql_tag.default`
@@ -921,67 +924,72 @@ function getSdk(requester) {
921
924
  // src/providers/fuel-graphql-subscriber.ts
922
925
  var import_errors = require("@fuel-ts/errors");
923
926
  var import_graphql = require("graphql");
924
- var _FuelSubscriptionStream = class {
925
- readable;
926
- writable;
927
- readableStreamController;
928
- constructor() {
929
- this.readable = new ReadableStream({
930
- start: (controller) => {
931
- this.readableStreamController = controller;
932
- }
933
- });
934
- this.writable = new WritableStream({
935
- write: (bytes) => {
936
- const text = _FuelSubscriptionStream.textDecoder.decode(bytes);
937
- if (text.startsWith("data:")) {
938
- const { data, errors } = JSON.parse(text.split("data:")[1]);
939
- if (Array.isArray(errors)) {
940
- this.readableStreamController.enqueue(
941
- new import_errors.FuelError(
942
- import_errors.FuelError.CODES.INVALID_REQUEST,
943
- errors.map((err) => err.message).join("\n\n")
944
- )
945
- );
946
- } else {
947
- this.readableStreamController.enqueue(data);
948
- }
949
- }
927
+ var _FuelGraphqlSubscriber = class {
928
+ constructor(options) {
929
+ this.options = options;
930
+ }
931
+ stream;
932
+ async setStream() {
933
+ const { url, query, variables, fetchFn } = this.options;
934
+ const response = await fetchFn(`${url}-sub`, {
935
+ method: "POST",
936
+ body: JSON.stringify({
937
+ query: (0, import_graphql.print)(query),
938
+ variables
939
+ }),
940
+ headers: {
941
+ "Content-Type": "application/json",
942
+ Accept: "text/event-stream"
950
943
  }
951
944
  });
945
+ this.stream = response.body.getReader();
952
946
  }
953
- };
954
- var FuelSubscriptionStream = _FuelSubscriptionStream;
955
- __publicField(FuelSubscriptionStream, "textDecoder", new TextDecoder());
956
- async function* fuelGraphQLSubscriber({
957
- url,
958
- variables,
959
- query,
960
- fetchFn
961
- }) {
962
- const response = await fetchFn(`${url}-sub`, {
963
- method: "POST",
964
- body: JSON.stringify({
965
- query: (0, import_graphql.print)(query),
966
- variables
967
- }),
968
- headers: {
969
- "Content-Type": "application/json",
970
- Accept: "text/event-stream"
971
- }
972
- });
973
- const subscriptionStreamReader = response.body.pipeThrough(new FuelSubscriptionStream()).getReader();
974
- while (true) {
975
- const { value, done } = await subscriptionStreamReader.read();
976
- if (value instanceof import_errors.FuelError) {
977
- throw value;
947
+ async next() {
948
+ if (!this.stream) {
949
+ await this.setStream();
978
950
  }
979
- yield value;
980
- if (done) {
981
- break;
951
+ while (true) {
952
+ const { value, done } = await this.stream.read();
953
+ if (done) {
954
+ return { value, done };
955
+ }
956
+ const text = _FuelGraphqlSubscriber.textDecoder.decode(value);
957
+ if (!text.startsWith("data:")) {
958
+ continue;
959
+ }
960
+ let data;
961
+ let errors;
962
+ try {
963
+ ({ data, errors } = JSON.parse(text.replace(/^data:/, "")));
964
+ } catch (e) {
965
+ throw new import_errors.FuelError(
966
+ import_errors.ErrorCode.STREAM_PARSING_ERROR,
967
+ `Error while parsing stream data response: ${text}`
968
+ );
969
+ }
970
+ if (Array.isArray(errors)) {
971
+ throw new import_errors.FuelError(
972
+ import_errors.FuelError.CODES.INVALID_REQUEST,
973
+ errors.map((err) => err.message).join("\n\n")
974
+ );
975
+ }
976
+ return { value: data, done: false };
982
977
  }
983
978
  }
984
- }
979
+ /**
980
+ * Gets called when `break` is called in a `for-await-of` loop.
981
+ */
982
+ async return() {
983
+ await this.stream.cancel();
984
+ this.stream.releaseLock();
985
+ return { done: true, value: void 0 };
986
+ }
987
+ [Symbol.asyncIterator]() {
988
+ return this;
989
+ }
990
+ };
991
+ var FuelGraphqlSubscriber = _FuelGraphqlSubscriber;
992
+ __publicField(FuelGraphqlSubscriber, "textDecoder", new TextDecoder());
985
993
 
986
994
  // src/providers/memory-cache.ts
987
995
  var import_errors2 = require("@fuel-ts/errors");
@@ -1509,9 +1517,6 @@ function sleep(time) {
1509
1517
  });
1510
1518
  }
1511
1519
 
1512
- // src/providers/utils/time.ts
1513
- var fromUnixToTai64 = (unixTimestampMs) => (BigInt(unixTimestampMs) + BigInt(2 ** 62) + BigInt(10)).toString();
1514
-
1515
1520
  // src/providers/transaction-request/errors.ts
1516
1521
  var NoWitnessAtIndexError = class extends Error {
1517
1522
  constructor(index) {
@@ -1753,7 +1758,7 @@ var BaseTransactionRequest = class {
1753
1758
  txPointer: "0x00000000000000000000000000000000",
1754
1759
  witnessIndex,
1755
1760
  predicate: predicate?.bytes,
1756
- predicateData: predicate?.predicateData
1761
+ predicateData: predicate?.predicateDataBytes
1757
1762
  };
1758
1763
  this.pushInput(input);
1759
1764
  this.addChangeOutput(owner, assetId);
@@ -1786,7 +1791,7 @@ var BaseTransactionRequest = class {
1786
1791
  amount,
1787
1792
  witnessIndex,
1788
1793
  predicate: predicate?.bytes,
1789
- predicateData: predicate?.predicateData
1794
+ predicateData: predicate?.predicateDataBytes
1790
1795
  };
1791
1796
  this.pushInput(input);
1792
1797
  this.addChangeOutput(recipient, assetId);
@@ -2001,8 +2006,6 @@ var BaseTransactionRequest = class {
2001
2006
  this.inputs.forEach((i) => {
2002
2007
  let correspondingInput;
2003
2008
  switch (i.type) {
2004
- case import_transactions5.InputType.Contract:
2005
- return;
2006
2009
  case import_transactions5.InputType.Coin:
2007
2010
  correspondingInput = inputs.find((x) => x.type === import_transactions5.InputType.Coin && x.owner === i.owner);
2008
2011
  break;
@@ -2012,7 +2015,7 @@ var BaseTransactionRequest = class {
2012
2015
  );
2013
2016
  break;
2014
2017
  default:
2015
- break;
2018
+ return;
2016
2019
  }
2017
2020
  if (correspondingInput && "predicateGasUsed" in correspondingInput && (0, import_math6.bn)(correspondingInput.predicateGasUsed).gt(0)) {
2018
2021
  i.predicate = correspondingInput.predicate;
@@ -2035,7 +2038,6 @@ var import_hasher = require("@fuel-ts/hasher");
2035
2038
  var import_math7 = require("@fuel-ts/math");
2036
2039
  var import_transactions6 = require("@fuel-ts/transactions");
2037
2040
  var import_utils11 = require("@fuel-ts/utils");
2038
- var import_ethers = require("ethers");
2039
2041
  var import_ramda2 = require("ramda");
2040
2042
  function hashTransaction(transactionRequest, chainId) {
2041
2043
  const transaction = transactionRequest.toTransaction();
@@ -2098,7 +2100,7 @@ function hashTransaction(transactionRequest, chainId) {
2098
2100
  transaction.witnesses = [];
2099
2101
  const chainIdBytes = (0, import_hasher.uint64ToBytesBE)(chainId);
2100
2102
  const concatenatedData = (0, import_utils11.concat)([chainIdBytes, new import_transactions6.TransactionCoder().encode(transaction)]);
2101
- return (0, import_ethers.sha256)(concatenatedData);
2103
+ return (0, import_hasher.sha256)(concatenatedData);
2102
2104
  }
2103
2105
 
2104
2106
  // src/providers/transaction-request/storage-slot.ts
@@ -2524,14 +2526,8 @@ var calculateTransactionFee = (params) => {
2524
2526
  };
2525
2527
  };
2526
2528
 
2527
- // src/providers/transaction-summary/date.ts
2528
- var import_tai64 = require("tai64");
2529
- var fromTai64ToDate = (tai64Timestamp) => {
2530
- const timestamp = import_tai64.TAI64.fromString(tai64Timestamp, 10).toUnix();
2531
- return new Date(timestamp * 1e3);
2532
- };
2533
-
2534
2529
  // src/providers/transaction-summary/operations.ts
2530
+ var import_configs10 = require("@fuel-ts/address/configs");
2535
2531
  var import_errors10 = require("@fuel-ts/errors");
2536
2532
  var import_math12 = require("@fuel-ts/math");
2537
2533
  var import_transactions13 = require("@fuel-ts/transactions");
@@ -2728,36 +2724,6 @@ function addOperation(operations, toAdd) {
2728
2724
  }
2729
2725
  return allOperations;
2730
2726
  }
2731
- function getReceiptsTransferOut(receipts) {
2732
- return getReceiptsByType(receipts, import_transactions13.ReceiptType.TransferOut);
2733
- }
2734
- function getContractTransferOperations({ receipts }) {
2735
- const transferOutReceipts = getReceiptsTransferOut(receipts);
2736
- const contractTransferOperations = transferOutReceipts.reduce(
2737
- (prevContractTransferOps, receipt) => {
2738
- const newContractTransferOps = addOperation(prevContractTransferOps, {
2739
- name: "Contract transfer" /* contractTransfer */,
2740
- from: {
2741
- type: 0 /* contract */,
2742
- address: receipt.from
2743
- },
2744
- to: {
2745
- type: 1 /* account */,
2746
- address: receipt.to
2747
- },
2748
- assetsSent: [
2749
- {
2750
- amount: receipt.amount,
2751
- assetId: receipt.assetId
2752
- }
2753
- ]
2754
- });
2755
- return newContractTransferOps;
2756
- },
2757
- []
2758
- );
2759
- return contractTransferOperations;
2760
- }
2761
2727
  function getWithdrawFromFuelOperations({
2762
2728
  inputs,
2763
2729
  receipts
@@ -2855,70 +2821,77 @@ function getContractCallOperations({
2855
2821
  }, []);
2856
2822
  return contractCallOperations;
2857
2823
  }
2824
+ function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs) {
2825
+ const { to: toAddress, assetId, amount } = receipt;
2826
+ let { from: fromAddress } = receipt;
2827
+ const toType = contractInputs.some((input) => input.contractID === toAddress) ? 0 /* contract */ : 1 /* account */;
2828
+ if (import_configs10.ZeroBytes32 === fromAddress) {
2829
+ const change = changeOutputs.find((output) => output.assetId === assetId);
2830
+ fromAddress = change?.to || fromAddress;
2831
+ }
2832
+ const fromType = contractInputs.some((input) => input.contractID === fromAddress) ? 0 /* contract */ : 1 /* account */;
2833
+ return {
2834
+ name: "Transfer asset" /* transfer */,
2835
+ from: {
2836
+ type: fromType,
2837
+ address: fromAddress
2838
+ },
2839
+ to: {
2840
+ type: toType,
2841
+ address: toAddress
2842
+ },
2843
+ assetsSent: [
2844
+ {
2845
+ assetId: assetId.toString(),
2846
+ amount
2847
+ }
2848
+ ]
2849
+ };
2850
+ }
2858
2851
  function getTransferOperations({
2859
2852
  inputs,
2860
2853
  outputs,
2861
2854
  receipts
2862
2855
  }) {
2856
+ let operations = [];
2863
2857
  const coinOutputs = getOutputsCoin(outputs);
2864
- const [transferReceipt] = getReceiptsByType(
2858
+ const contractInputs = getInputsContract(inputs);
2859
+ const changeOutputs = getOutputsChange(outputs);
2860
+ coinOutputs.forEach((output) => {
2861
+ const { amount, assetId, to } = output;
2862
+ const changeOutput = changeOutputs.find((change) => change.assetId === assetId);
2863
+ if (changeOutput) {
2864
+ operations = addOperation(operations, {
2865
+ name: "Transfer asset" /* transfer */,
2866
+ from: {
2867
+ type: 1 /* account */,
2868
+ address: changeOutput.to
2869
+ },
2870
+ to: {
2871
+ type: 1 /* account */,
2872
+ address: to
2873
+ },
2874
+ assetsSent: [
2875
+ {
2876
+ assetId,
2877
+ amount
2878
+ }
2879
+ ]
2880
+ });
2881
+ }
2882
+ });
2883
+ const transferReceipts = getReceiptsByType(
2865
2884
  receipts,
2866
2885
  import_transactions13.ReceiptType.Transfer
2867
2886
  );
2868
- let operations = [];
2869
- if (transferReceipt) {
2870
- const changeOutputs = getOutputsChange(outputs);
2871
- changeOutputs.forEach((output) => {
2872
- const { assetId } = output;
2873
- const [contractInput] = getInputsContract(inputs);
2874
- const utxo = getInputFromAssetId(inputs, assetId);
2875
- if (utxo && contractInput) {
2876
- const inputAddress = getInputAccountAddress(utxo);
2877
- operations = addOperation(operations, {
2878
- name: "Transfer asset" /* transfer */,
2879
- from: {
2880
- type: 1 /* account */,
2881
- address: inputAddress
2882
- },
2883
- to: {
2884
- type: 0 /* contract */,
2885
- address: contractInput.contractID
2886
- },
2887
- assetsSent: [
2888
- {
2889
- assetId: assetId.toString(),
2890
- amount: transferReceipt.amount
2891
- }
2892
- ]
2893
- });
2894
- }
2895
- });
2896
- } else {
2897
- coinOutputs.forEach((output) => {
2898
- const input = getInputFromAssetId(inputs, output.assetId);
2899
- if (input) {
2900
- const inputAddress = getInputAccountAddress(input);
2901
- const operationToAdd = {
2902
- name: "Transfer asset" /* transfer */,
2903
- from: {
2904
- type: 1 /* account */,
2905
- address: inputAddress
2906
- },
2907
- to: {
2908
- type: 1 /* account */,
2909
- address: output.to.toString()
2910
- },
2911
- assetsSent: [
2912
- {
2913
- assetId: output.assetId.toString(),
2914
- amount: output.amount
2915
- }
2916
- ]
2917
- };
2918
- operations = addOperation(operations, operationToAdd);
2919
- }
2920
- });
2921
- }
2887
+ const transferOutReceipts = getReceiptsByType(
2888
+ receipts,
2889
+ import_transactions13.ReceiptType.TransferOut
2890
+ );
2891
+ [...transferReceipts, ...transferOutReceipts].forEach((receipt) => {
2892
+ const operation = extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs);
2893
+ operations = addOperation(operations, operation);
2894
+ });
2922
2895
  return operations;
2923
2896
  }
2924
2897
  function getPayProducerOperations(outputs) {
@@ -2991,7 +2964,6 @@ function getOperations({
2991
2964
  rawPayload,
2992
2965
  maxInputs
2993
2966
  }),
2994
- ...getContractTransferOperations({ receipts }),
2995
2967
  ...getWithdrawFromFuelOperations({ inputs, receipts })
2996
2968
  ];
2997
2969
  }
@@ -3147,7 +3119,7 @@ function assembleTransactionSummary(params) {
3147
3119
  const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
3148
3120
  let date;
3149
3121
  if (time) {
3150
- date = fromTai64ToDate(time);
3122
+ date = import_utils19.DateTime.fromTai64(time);
3151
3123
  }
3152
3124
  const transactionSummary = {
3153
3125
  id,
@@ -3282,6 +3254,12 @@ var TransactionResponse = class {
3282
3254
  transactionId: this.id
3283
3255
  });
3284
3256
  for await (const { statusChange } of subscription) {
3257
+ if (statusChange.type === "SqueezedOutStatus") {
3258
+ throw new import_errors12.FuelError(
3259
+ import_errors12.ErrorCode.TRANSACTION_SQUEEZED_OUT,
3260
+ `Transaction Squeezed Out with reason: ${statusChange.reason}`
3261
+ );
3262
+ }
3285
3263
  if (statusChange.type !== "SubmittedStatus") {
3286
3264
  break;
3287
3265
  }
@@ -3446,14 +3424,15 @@ var _Provider = class {
3446
3424
  }
3447
3425
  static getFetchFn(options) {
3448
3426
  const { retryOptions, timeout } = options;
3449
- return autoRetryFetch((...args) => {
3450
- if (options.fetch) {
3451
- return options.fetch(...args);
3452
- }
3427
+ return autoRetryFetch(async (...args) => {
3453
3428
  const url = args[0];
3454
3429
  const request = args[1];
3455
3430
  const signal = timeout ? AbortSignal.timeout(timeout) : void 0;
3456
- return fetch(url, { ...request, signal });
3431
+ let fullRequest = { ...request, signal };
3432
+ if (options.requestMiddleware) {
3433
+ fullRequest = await options.requestMiddleware(fullRequest);
3434
+ }
3435
+ return options.fetch ? options.fetch(url, fullRequest, options) : fetch(url, fullRequest);
3457
3436
  }, retryOptions);
3458
3437
  }
3459
3438
  /**
@@ -3553,7 +3532,7 @@ var _Provider = class {
3553
3532
  const opDefinition = query.definitions.find((x) => x.kind === "OperationDefinition");
3554
3533
  const isSubscription = opDefinition?.operation === "subscription";
3555
3534
  if (isSubscription) {
3556
- return fuelGraphQLSubscriber({
3535
+ return new FuelGraphqlSubscriber({
3557
3536
  url: this.url,
3558
3537
  query,
3559
3538
  fetchFn: (url, requestInit) => fetchFn(url, requestInit, this.options),
@@ -3587,7 +3566,7 @@ var _Provider = class {
3587
3566
  name,
3588
3567
  consensusParameters: { chainId }
3589
3568
  } = await this.getChain();
3590
- const network = new import_ethers2.Network(name, chainId.toNumber());
3569
+ const network = new import_ethers.Network(name, chainId.toNumber());
3591
3570
  return Promise.resolve(network);
3592
3571
  }
3593
3572
  /**
@@ -3659,6 +3638,12 @@ var _Provider = class {
3659
3638
  if (awaitExecution) {
3660
3639
  const subscription = this.operations.submitAndAwait({ encodedTransaction });
3661
3640
  for await (const { submitAndAwait } of subscription) {
3641
+ if (submitAndAwait.type === "SqueezedOutStatus") {
3642
+ throw new import_errors13.FuelError(
3643
+ import_errors13.ErrorCode.TRANSACTION_SQUEEZED_OUT,
3644
+ `Transaction Squeezed Out with reason: ${submitAndAwait.reason}`
3645
+ );
3646
+ }
3662
3647
  if (submitAndAwait.type !== "SubmittedStatus") {
3663
3648
  break;
3664
3649
  }
@@ -3745,11 +3730,15 @@ var _Provider = class {
3745
3730
  async estimateTxDependencies(transactionRequest) {
3746
3731
  if (transactionRequest.type === import_transactions17.TransactionType.Create) {
3747
3732
  return {
3748
- receipts: []
3733
+ receipts: [],
3734
+ outputVariables: 0,
3735
+ missingContractIds: []
3749
3736
  };
3750
3737
  }
3751
3738
  await this.estimatePredicates(transactionRequest);
3752
3739
  let receipts = [];
3740
+ const missingContractIds = [];
3741
+ let outputVariables = 0;
3753
3742
  for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
3754
3743
  const { dryRun: gqlReceipts } = await this.operations.dryRun({
3755
3744
  encodedTransaction: (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes()),
@@ -3759,16 +3748,20 @@ var _Provider = class {
3759
3748
  const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
3760
3749
  const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
3761
3750
  if (hasMissingOutputs) {
3751
+ outputVariables += missingOutputVariables.length;
3762
3752
  transactionRequest.addVariableOutputs(missingOutputVariables.length);
3763
3753
  missingOutputContractIds.forEach(({ contractId }) => {
3764
3754
  transactionRequest.addContractInputAndOutput(import_address3.Address.fromString(contractId));
3755
+ missingContractIds.push(contractId);
3765
3756
  });
3766
3757
  } else {
3767
3758
  break;
3768
3759
  }
3769
3760
  }
3770
3761
  return {
3771
- receipts
3762
+ receipts,
3763
+ outputVariables,
3764
+ missingContractIds
3772
3765
  };
3773
3766
  }
3774
3767
  /**
@@ -3836,11 +3829,15 @@ var _Provider = class {
3836
3829
  const minGas = txRequestClone.calculateMinGas(chainInfo);
3837
3830
  const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
3838
3831
  let receipts = [];
3832
+ let missingContractIds = [];
3833
+ let outputVariables = 0;
3839
3834
  if (isScriptTransaction && estimateTxDependencies) {
3840
3835
  txRequestClone.gasPrice = (0, import_math14.bn)(0);
3841
3836
  txRequestClone.gasLimit = (0, import_math14.bn)(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
3842
3837
  const result = await this.estimateTxDependencies(txRequestClone);
3843
3838
  receipts = result.receipts;
3839
+ outputVariables = result.outputVariables;
3840
+ missingContractIds = result.missingContractIds;
3844
3841
  }
3845
3842
  const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
3846
3843
  const usedFee = calculatePriceWithFactor(
@@ -3862,7 +3859,8 @@ var _Provider = class {
3862
3859
  minFee,
3863
3860
  maxFee,
3864
3861
  estimatedInputs: txRequestClone.inputs,
3865
- estimatedOutputs: txRequestClone.outputs
3862
+ outputVariables,
3863
+ missingContractIds
3866
3864
  };
3867
3865
  }
3868
3866
  async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
@@ -4242,13 +4240,13 @@ var _Provider = class {
4242
4240
  * Lets you produce blocks with custom timestamps and the block number of the last block produced.
4243
4241
  *
4244
4242
  * @param amount - The amount of blocks to produce
4245
- * @param startTime - The UNIX timestamp to set for the first produced block
4243
+ * @param startTime - The UNIX timestamp (milliseconds) to set for the first produced block
4246
4244
  * @returns A promise that resolves to the block number of the last produced block.
4247
4245
  */
4248
4246
  async produceBlocks(amount, startTime) {
4249
4247
  const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
4250
4248
  blocksToProduce: (0, import_math14.bn)(amount).toString(10),
4251
- startTimestamp: startTime ? fromUnixToTai64(startTime) : void 0
4249
+ startTimestamp: startTime ? import_utils22.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
4252
4250
  });
4253
4251
  return (0, import_math14.bn)(latestBlockHeight);
4254
4252
  }
@@ -4330,7 +4328,7 @@ var import_utils26 = require("@fuel-ts/utils");
4330
4328
  var asm = __toESM(require("@fuels/vm-asm"));
4331
4329
  var formatTransferToContractScriptData = (params) => {
4332
4330
  const { assetId, amountToTransfer, hexlifiedContractId } = params;
4333
- const numberCoder = new import_abi_coder4.U64Coder();
4331
+ const numberCoder = new import_abi_coder4.BigNumberCoder("u64");
4334
4332
  const encoded = numberCoder.encode(new import_math16.BN(amountToTransfer).toNumber());
4335
4333
  const scriptData = Uint8Array.from([
4336
4334
  ...(0, import_utils26.arrayify)(hexlifiedContractId),
@@ -4482,7 +4480,7 @@ var Account = class extends import_interfaces.AbstractAccount {
4482
4480
  * @param assetId - The asset ID to check the balance for.
4483
4481
  * @returns A promise that resolves to the balance amount.
4484
4482
  */
4485
- async getBalance(assetId = import_configs10.BaseAssetId) {
4483
+ async getBalance(assetId = import_configs11.BaseAssetId) {
4486
4484
  const amount = await this.provider.getBalance(this.address, assetId);
4487
4485
  return amount;
4488
4486
  }
@@ -4523,7 +4521,7 @@ var Account = class extends import_interfaces.AbstractAccount {
4523
4521
  async fund(request, coinQuantities, fee) {
4524
4522
  const updatedQuantities = addAmountToAsset({
4525
4523
  amount: (0, import_math17.bn)(fee),
4526
- assetId: import_configs10.BaseAssetId,
4524
+ assetId: import_configs11.BaseAssetId,
4527
4525
  coinQuantities
4528
4526
  });
4529
4527
  const quantitiesDict = {};
@@ -4547,8 +4545,8 @@ var Account = class extends import_interfaces.AbstractAccount {
4547
4545
  quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
4548
4546
  cachedUtxos.push(input.id);
4549
4547
  }
4550
- } else if (input.recipient === owner && input.amount && quantitiesDict[import_configs10.BaseAssetId]) {
4551
- quantitiesDict[import_configs10.BaseAssetId].owned = quantitiesDict[import_configs10.BaseAssetId].owned.add(input.amount);
4548
+ } else if (input.recipient === owner && input.amount && quantitiesDict[import_configs11.BaseAssetId]) {
4549
+ quantitiesDict[import_configs11.BaseAssetId].owned = quantitiesDict[import_configs11.BaseAssetId].owned.add(input.amount);
4552
4550
  cachedMessages.push(input.nonce);
4553
4551
  }
4554
4552
  }
@@ -4580,7 +4578,7 @@ var Account = class extends import_interfaces.AbstractAccount {
4580
4578
  * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
4581
4579
  * @returns A promise that resolves to the prepared transaction request.
4582
4580
  */
4583
- async createTransfer(destination, amount, assetId = import_configs10.BaseAssetId, txParams = {}) {
4581
+ async createTransfer(destination, amount, assetId = import_configs11.BaseAssetId, txParams = {}) {
4584
4582
  const { minGasPrice } = this.provider.getGasConfig();
4585
4583
  const params = { gasPrice: minGasPrice, ...txParams };
4586
4584
  const request = new ScriptTransactionRequest(params);
@@ -4610,7 +4608,13 @@ var Account = class extends import_interfaces.AbstractAccount {
4610
4608
  * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
4611
4609
  * @returns A promise that resolves to the transaction response.
4612
4610
  */
4613
- async transfer(destination, amount, assetId = import_configs10.BaseAssetId, txParams = {}) {
4611
+ async transfer(destination, amount, assetId = import_configs11.BaseAssetId, txParams = {}) {
4612
+ if ((0, import_math17.bn)(amount).lte(0)) {
4613
+ throw new import_errors15.FuelError(
4614
+ import_errors15.ErrorCode.INVALID_TRANSFER_AMOUNT,
4615
+ "Transfer amount must be a positive number."
4616
+ );
4617
+ }
4614
4618
  const request = await this.createTransfer(destination, amount, assetId, txParams);
4615
4619
  return this.sendTransaction(request, { estimateTxDependencies: false });
4616
4620
  }
@@ -4623,7 +4627,13 @@ var Account = class extends import_interfaces.AbstractAccount {
4623
4627
  * @param txParams - The optional transaction parameters.
4624
4628
  * @returns A promise that resolves to the transaction response.
4625
4629
  */
4626
- async transferToContract(contractId, amount, assetId = import_configs10.BaseAssetId, txParams = {}) {
4630
+ async transferToContract(contractId, amount, assetId = import_configs11.BaseAssetId, txParams = {}) {
4631
+ if ((0, import_math17.bn)(amount).lte(0)) {
4632
+ throw new import_errors15.FuelError(
4633
+ import_errors15.ErrorCode.INVALID_TRANSFER_AMOUNT,
4634
+ "Transfer amount must be a positive number."
4635
+ );
4636
+ }
4627
4637
  const contractAddress = import_address4.Address.fromAddressOrString(contractId);
4628
4638
  const { minGasPrice } = this.provider.getGasConfig();
4629
4639
  const params = { gasPrice: minGasPrice, ...txParams };
@@ -4676,7 +4686,7 @@ var Account = class extends import_interfaces.AbstractAccount {
4676
4686
  ]);
4677
4687
  const params = { script, gasPrice: minGasPrice, ...txParams };
4678
4688
  const request = new ScriptTransactionRequest(params);
4679
- const forwardingQuantities = [{ amount: (0, import_math17.bn)(amount), assetId: import_configs10.BaseAssetId }];
4689
+ const forwardingQuantities = [{ amount: (0, import_math17.bn)(amount), assetId: import_configs11.BaseAssetId }];
4680
4690
  const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
4681
4691
  request,
4682
4692
  forwardingQuantities
@@ -5066,15 +5076,17 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
5066
5076
 
5067
5077
  // src/hdwallet/hdwallet.ts
5068
5078
  var import_errors19 = require("@fuel-ts/errors");
5079
+ var import_hasher6 = require("@fuel-ts/hasher");
5069
5080
  var import_math19 = require("@fuel-ts/math");
5070
5081
  var import_utils34 = require("@fuel-ts/utils");
5071
- var import_ethers5 = require("ethers");
5082
+ var import_ethers3 = require("ethers");
5072
5083
 
5073
5084
  // src/mnemonic/mnemonic.ts
5074
5085
  var import_crypto3 = require("@fuel-ts/crypto");
5075
5086
  var import_errors18 = require("@fuel-ts/errors");
5087
+ var import_hasher5 = require("@fuel-ts/hasher");
5076
5088
  var import_utils32 = require("@fuel-ts/utils");
5077
- var import_ethers4 = require("ethers");
5089
+ var import_ethers2 = require("ethers");
5078
5090
 
5079
5091
  // src/wordlists/words/english.ts
5080
5092
  var english = [
@@ -7130,8 +7142,8 @@ var english = [
7130
7142
 
7131
7143
  // src/mnemonic/utils.ts
7132
7144
  var import_errors17 = require("@fuel-ts/errors");
7145
+ var import_hasher4 = require("@fuel-ts/hasher");
7133
7146
  var import_utils31 = require("@fuel-ts/utils");
7134
- var import_ethers3 = require("ethers");
7135
7147
  function toUtf8Bytes(stri) {
7136
7148
  const str = stri.normalize("NFKD");
7137
7149
  const result = [];
@@ -7198,7 +7210,7 @@ function entropyToMnemonicIndices(entropy) {
7198
7210
  }
7199
7211
  }
7200
7212
  const checksumBits = entropy.length / 4;
7201
- const checksum = (0, import_utils31.arrayify)((0, import_ethers3.sha256)(entropy))[0] & getUpperMask(checksumBits);
7213
+ const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
7202
7214
  indices[indices.length - 1] <<= checksumBits;
7203
7215
  indices[indices.length - 1] |= checksum >> 8 - checksumBits;
7204
7216
  return indices;
@@ -7225,7 +7237,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
7225
7237
  const entropyBits = 32 * words.length / 3;
7226
7238
  const checksumBits = words.length / 3;
7227
7239
  const checksumMask = getUpperMask(checksumBits);
7228
- const checksum = (0, import_utils31.arrayify)((0, import_ethers3.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
7240
+ const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
7229
7241
  if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
7230
7242
  throw new import_errors17.FuelError(
7231
7243
  import_errors17.ErrorCode.INVALID_CHECKSUM,
@@ -7322,7 +7334,7 @@ var Mnemonic = class {
7322
7334
  assertMnemonic(getWords(phrase));
7323
7335
  const phraseBytes = toUtf8Bytes(getPhrase(phrase));
7324
7336
  const salt = toUtf8Bytes(`mnemonic${passphrase}`);
7325
- return (0, import_ethers4.pbkdf2)(phraseBytes, salt, 2048, 64, "sha512");
7337
+ return (0, import_ethers2.pbkdf2)(phraseBytes, salt, 2048, 64, "sha512");
7326
7338
  }
7327
7339
  /**
7328
7340
  * @param phrase - Mnemonic phrase composed by words from the provided wordlist
@@ -7384,7 +7396,7 @@ var Mnemonic = class {
7384
7396
  `Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
7385
7397
  );
7386
7398
  }
7387
- return (0, import_utils32.arrayify)((0, import_ethers4.computeHmac)("sha512", MasterSecret, seedArray));
7399
+ return (0, import_utils32.arrayify)((0, import_ethers2.computeHmac)("sha512", MasterSecret, seedArray));
7388
7400
  }
7389
7401
  /**
7390
7402
  * Get the extendKey as defined on BIP-32 from the provided seed
@@ -7409,8 +7421,8 @@ var Mnemonic = class {
7409
7421
  chainCode,
7410
7422
  (0, import_utils32.concat)(["0x00", privateKey])
7411
7423
  ]);
7412
- const checksum = (0, import_ethers4.dataSlice)((0, import_ethers4.sha256)((0, import_ethers4.sha256)(extendedKey)), 0, 4);
7413
- return (0, import_ethers4.encodeBase58)((0, import_utils32.concat)([extendedKey, checksum]));
7424
+ const checksum = (0, import_ethers2.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
7425
+ return (0, import_ethers2.encodeBase58)((0, import_utils32.concat)([extendedKey, checksum]));
7414
7426
  }
7415
7427
  /**
7416
7428
  * Create a new mnemonic using a randomly generated number as entropy.
@@ -7425,7 +7437,7 @@ var Mnemonic = class {
7425
7437
  * @returns A randomly generated mnemonic
7426
7438
  */
7427
7439
  static generate(size = 32, extraEntropy = "") {
7428
- const entropy = extraEntropy ? (0, import_ethers4.sha256)((0, import_utils32.concat)([(0, import_crypto3.randomBytes)(size), (0, import_utils32.arrayify)(extraEntropy)])) : (0, import_crypto3.randomBytes)(size);
7440
+ const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils32.concat)([(0, import_crypto3.randomBytes)(size), (0, import_utils32.arrayify)(extraEntropy)])) : (0, import_crypto3.randomBytes)(size);
7429
7441
  return Mnemonic.entropyToMnemonic(entropy);
7430
7442
  }
7431
7443
  };
@@ -7438,7 +7450,7 @@ var MainnetPUB = (0, import_utils34.hexlify)("0x0488b21e");
7438
7450
  var TestnetPRV2 = (0, import_utils34.hexlify)("0x04358394");
7439
7451
  var TestnetPUB = (0, import_utils34.hexlify)("0x043587cf");
7440
7452
  function base58check(data) {
7441
- return (0, import_ethers5.encodeBase58)((0, import_utils34.concat)([data, (0, import_ethers5.dataSlice)((0, import_ethers5.sha256)((0, import_ethers5.sha256)(data)), 0, 4)]));
7453
+ return (0, import_ethers3.encodeBase58)((0, import_utils34.concat)([data, (0, import_ethers3.dataSlice)((0, import_hasher6.sha256)((0, import_hasher6.sha256)(data)), 0, 4)]));
7442
7454
  }
7443
7455
  function getExtendedKeyPrefix(isPublic = false, testnet = false) {
7444
7456
  if (isPublic) {
@@ -7494,7 +7506,7 @@ var HDWallet = class {
7494
7506
  this.publicKey = (0, import_utils34.hexlify)(config.publicKey);
7495
7507
  }
7496
7508
  this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
7497
- this.fingerprint = (0, import_ethers5.dataSlice)((0, import_ethers5.ripemd160)((0, import_ethers5.sha256)(this.publicKey)), 0, 4);
7509
+ this.fingerprint = (0, import_ethers3.dataSlice)((0, import_ethers3.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
7498
7510
  this.depth = config.depth || this.depth;
7499
7511
  this.index = config.index || this.index;
7500
7512
  this.chainCode = config.chainCode;
@@ -7526,7 +7538,7 @@ var HDWallet = class {
7526
7538
  data.set((0, import_utils34.arrayify)(this.publicKey));
7527
7539
  }
7528
7540
  data.set((0, import_math19.toBytes)(index, 4), 33);
7529
- const bytes = (0, import_utils34.arrayify)((0, import_ethers5.computeHmac)("sha512", chainCode, data));
7541
+ const bytes = (0, import_utils34.arrayify)((0, import_ethers3.computeHmac)("sha512", chainCode, data));
7530
7542
  const IL = bytes.slice(0, 32);
7531
7543
  const IR = bytes.slice(32);
7532
7544
  if (privateKey) {
@@ -7597,7 +7609,7 @@ var HDWallet = class {
7597
7609
  });
7598
7610
  }
7599
7611
  static fromExtendedKey(extendedKey) {
7600
- const decoded = (0, import_ethers5.toBeHex)((0, import_ethers5.decodeBase58)(extendedKey));
7612
+ const decoded = (0, import_ethers3.toBeHex)((0, import_ethers3.decodeBase58)(extendedKey));
7601
7613
  const bytes = (0, import_utils34.arrayify)(decoded);
7602
7614
  const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
7603
7615
  if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
@@ -7823,7 +7835,7 @@ var generateTestWallet = async (provider, quantities) => {
7823
7835
  };
7824
7836
 
7825
7837
  // src/test-utils/launchNode.ts
7826
- var import_configs11 = require("@fuel-ts/address/configs");
7838
+ var import_configs12 = require("@fuel-ts/address/configs");
7827
7839
  var import_math20 = require("@fuel-ts/math");
7828
7840
  var import_utils35 = require("@fuel-ts/utils");
7829
7841
  var import_cli_utils = require("@fuel-ts/utils/cli-utils");
@@ -7923,7 +7935,7 @@ var launchNode = async ({
7923
7935
  {
7924
7936
  owner: signer.address.toHexString(),
7925
7937
  amount: (0, import_math20.toHex)(1e9),
7926
- asset_id: import_configs11.BaseAssetId
7938
+ asset_id: import_configs12.BaseAssetId
7927
7939
  }
7928
7940
  ]
7929
7941
  }
@@ -7991,7 +8003,7 @@ var launchNode = async ({
7991
8003
  var generateWallets = async (count, provider) => {
7992
8004
  const wallets = [];
7993
8005
  for (let i = 0; i < count; i += 1) {
7994
- const wallet = await generateTestWallet(provider, [[1e3, import_configs11.BaseAssetId]]);
8006
+ const wallet = await generateTestWallet(provider, [[1e3, import_configs12.BaseAssetId]]);
7995
8007
  wallets.push(wallet);
7996
8008
  }
7997
8009
  return wallets;