@fuel-ts/account 0.101.2 → 0.101.3

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.
Files changed (36) hide show
  1. package/dist/account.d.ts +45 -14
  2. package/dist/account.d.ts.map +1 -1
  3. package/dist/connectors/fuel-connector.d.ts +8 -0
  4. package/dist/connectors/fuel-connector.d.ts.map +1 -1
  5. package/dist/connectors/types/connector-types.d.ts +4 -2
  6. package/dist/connectors/types/connector-types.d.ts.map +1 -1
  7. package/dist/connectors/types/events.d.ts +6 -1
  8. package/dist/connectors/types/events.d.ts.map +1 -1
  9. package/dist/index.d.ts +1 -0
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.global.js +538 -101
  12. package/dist/index.global.js.map +1 -1
  13. package/dist/index.js +598 -250
  14. package/dist/index.js.map +1 -1
  15. package/dist/index.mjs +583 -238
  16. package/dist/index.mjs.map +1 -1
  17. package/dist/providers/provider.d.ts.map +1 -1
  18. package/dist/providers/transaction-request/script-transaction-request.d.ts +2 -1
  19. package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
  20. package/dist/providers/transaction-response/transaction-response.d.ts +23 -4
  21. package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
  22. package/dist/providers/utils/extract-tx-error.d.ts.map +1 -1
  23. package/dist/providers/utils/handle-gql-error-message.d.ts.map +1 -1
  24. package/dist/providers/utils/transaction-response-serialization.d.ts.map +1 -1
  25. package/dist/test-utils/launchNode.d.ts.map +1 -1
  26. package/dist/test-utils.global.js +465 -101
  27. package/dist/test-utils.global.js.map +1 -1
  28. package/dist/test-utils.js +525 -198
  29. package/dist/test-utils.js.map +1 -1
  30. package/dist/test-utils.mjs +515 -188
  31. package/dist/test-utils.mjs.map +1 -1
  32. package/dist/types.d.ts +1 -1
  33. package/dist/types.d.ts.map +1 -1
  34. package/dist/utils/consolidate-coins.d.ts +43 -0
  35. package/dist/utils/consolidate-coins.d.ts.map +1 -0
  36. package/package.json +14 -14
@@ -255,8 +255,9 @@ var launchNode = /* @__PURE__ */ __name(async ({
255
255
  "--consensus-key",
256
256
  "--db-type",
257
257
  "--poa-instant",
258
+ "--native-executor-version",
258
259
  "--min-gas-price",
259
- "--native-executor-version"
260
+ "--starting-gas-price"
260
261
  ]);
261
262
  const snapshotDir = getFlagValueFromArgs(args, "--snapshot");
262
263
  const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || import_utils2.defaultConsensusKey;
@@ -406,7 +407,7 @@ var launchNode = /* @__PURE__ */ __name(async ({
406
407
 
407
408
  // src/test-utils/setup-test-provider-and-wallets.ts
408
409
  var import_utils47 = require("@fuel-ts/utils");
409
- var import_ramda10 = require("ramda");
410
+ var import_ramda11 = require("ramda");
410
411
 
411
412
  // src/providers/coin-quantity.ts
412
413
  var import_math2 = require("@fuel-ts/math");
@@ -1847,8 +1848,11 @@ var import_graphql = require("graphql");
1847
1848
 
1848
1849
  // src/providers/utils/handle-gql-error-message.ts
1849
1850
  var import_errors3 = require("@fuel-ts/errors");
1851
+ var ASSET_ID_REGEX = /[0-9a-fA-F]{32,64}/g;
1850
1852
  var gqlErrorMessage = {
1851
1853
  RPC_CONSISTENCY: /The required fuel block height is higher than the current block height. Required: \d+, Current: \d+/,
1854
+ INSUFFICIENT_FUNDS: /the target cannot be met due to insufficient coins available for [0-9a-fA-F]{32,64}. Collected: \d+/,
1855
+ MAX_COINS_REACHED: /the target for [0-9a-fA-F]{32,64} cannot be met due to exceeding the \d+ coin limit. Collected: \d+./,
1852
1856
  NOT_ENOUGH_COINS_MAX_COINS: /the target cannot be met due to no coins available or exceeding the \d+ coin limit./,
1853
1857
  ASSET_NOT_FOUND: /resource was not found in table/,
1854
1858
  MULTIPLE_CHANGE_POLICIES: /The asset ([a-fA-F0-9]{64}) has multiple change policies/,
@@ -1864,6 +1868,46 @@ var mapGqlErrorMessage = /* @__PURE__ */ __name((error) => {
1864
1868
  error
1865
1869
  );
1866
1870
  }
1871
+ if (gqlErrorMessage.MAX_COINS_REACHED.test(error.message)) {
1872
+ const matches = error.message.match(ASSET_ID_REGEX);
1873
+ const assetId = matches ? `0x${matches[0]}` : null;
1874
+ const owner = matches ? `0x${matches[1]}` : null;
1875
+ let suffix = "";
1876
+ if (assetId) {
1877
+ suffix += `
1878
+ Asset ID: '${assetId}'.`;
1879
+ }
1880
+ if (owner) {
1881
+ suffix += `
1882
+ Owner: '${owner}'.`;
1883
+ }
1884
+ return new import_errors3.FuelError(
1885
+ import_errors3.ErrorCode.MAX_COINS_REACHED,
1886
+ `You have too many small value coins - consider combining UTXOs.${suffix}`,
1887
+ { assetId, owner },
1888
+ error
1889
+ );
1890
+ }
1891
+ if (gqlErrorMessage.INSUFFICIENT_FUNDS.test(error.message)) {
1892
+ const matches = error.message.match(ASSET_ID_REGEX);
1893
+ const assetId = matches ? `0x${matches[0]}` : null;
1894
+ const owner = matches ? `0x${matches[1]}` : null;
1895
+ let suffix = "";
1896
+ if (assetId) {
1897
+ suffix += `
1898
+ Asset ID: '${assetId}'.`;
1899
+ }
1900
+ if (owner) {
1901
+ suffix += `
1902
+ Owner: '${owner}'.`;
1903
+ }
1904
+ return new import_errors3.FuelError(
1905
+ import_errors3.ErrorCode.INSUFFICIENT_FUNDS,
1906
+ `Insufficient funds.${suffix}`,
1907
+ { assetId, owner },
1908
+ error
1909
+ );
1910
+ }
1867
1911
  if (gqlErrorMessage.MULTIPLE_CHANGE_POLICIES.test(error.message)) {
1868
1912
  const match = error.message.match(/asset ([a-fA-F0-9]{64})/);
1869
1913
  const assetId = match?.[1] || "";
@@ -2946,6 +2990,7 @@ This error originated at ${JSON.stringify(pos, null, 2)}` : "";
2946
2990
  }
2947
2991
  return new import_errors9.FuelError(import_errors9.ErrorCode.SCRIPT_REVERTED, errorMessage, {
2948
2992
  ...metadata,
2993
+ abiError,
2949
2994
  reason
2950
2995
  });
2951
2996
  }
@@ -3968,11 +4013,15 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
3968
4013
  * @deprecated Use `provider.assembleTx` instead.
3969
4014
  * Check the migration guide https://docs.fuel.network/guide/assembling-transactions/migration-guide.html for more information.
3970
4015
  */
3971
- async estimateAndFund(account, { signatureCallback, quantities = [] } = {}) {
4016
+ async estimateAndFund(account, {
4017
+ signatureCallback,
4018
+ quantities = [],
4019
+ skipAutoConsolidation
4020
+ } = {}) {
3972
4021
  const txCost = await account.getTransactionCost(this, { signatureCallback, quantities });
3973
4022
  this.maxFee = txCost.maxFee;
3974
4023
  this.gasLimit = txCost.gasUsed;
3975
- await account.fund(this, txCost);
4024
+ await account.fund(this, txCost, { skipAutoConsolidation });
3976
4025
  return this;
3977
4026
  }
3978
4027
  /**
@@ -5536,25 +5585,6 @@ __name(getAllDecodedLogs, "getAllDecodedLogs");
5536
5585
 
5537
5586
  // src/providers/transaction-response/transaction-response.ts
5538
5587
  var TransactionResponse = class _TransactionResponse {
5539
- /**
5540
- * Constructor for `TransactionResponse`.
5541
- *
5542
- * @param tx - The transaction ID or TransactionRequest.
5543
- * @param provider - The provider.
5544
- */
5545
- constructor(tx, provider, chainId, abis, submitTxSubscription) {
5546
- this.submitTxSubscription = submitTxSubscription;
5547
- if (typeof tx === "string") {
5548
- this.id = tx;
5549
- } else {
5550
- this.id = tx.getTransactionId(chainId);
5551
- this.request = tx;
5552
- }
5553
- this.provider = provider;
5554
- this.abis = abis;
5555
- this.waitForResult = this.waitForResult.bind(this);
5556
- this.waitForPreConfirmation = this.waitForPreConfirmation.bind(this);
5557
- }
5558
5588
  static {
5559
5589
  __name(this, "TransactionResponse");
5560
5590
  }
@@ -5569,9 +5599,42 @@ var TransactionResponse = class _TransactionResponse {
5569
5599
  request;
5570
5600
  status;
5571
5601
  abis;
5602
+ submitTxSubscription;
5572
5603
  preConfirmationStatus;
5573
5604
  waitingForStreamData = false;
5574
5605
  statusResolvers = /* @__PURE__ */ new Map();
5606
+ /**
5607
+ * Constructor for `TransactionResponse`.
5608
+ */
5609
+ constructor(constructorParams, provider, chainId, abis, submitTxSubscription) {
5610
+ let tx;
5611
+ let _provider;
5612
+ let _chainId;
5613
+ let _abis;
5614
+ if (typeof constructorParams === "object" && "provider" in constructorParams && arguments.length === 1) {
5615
+ tx = constructorParams.transactionRequestOrId;
5616
+ _provider = constructorParams.provider;
5617
+ _chainId = constructorParams.chainId;
5618
+ _abis = constructorParams.abis;
5619
+ this.submitTxSubscription = constructorParams.submitAndAwaitSubscription;
5620
+ } else {
5621
+ tx = constructorParams;
5622
+ _provider = provider;
5623
+ _chainId = chainId;
5624
+ _abis = abis;
5625
+ this.submitTxSubscription = submitTxSubscription;
5626
+ }
5627
+ if (typeof tx === "string") {
5628
+ this.id = tx;
5629
+ } else {
5630
+ this.id = tx.getTransactionId(_chainId);
5631
+ this.request = tx;
5632
+ }
5633
+ this.provider = _provider;
5634
+ this.abis = _abis;
5635
+ this.waitForResult = this.waitForResult.bind(this);
5636
+ this.waitForPreConfirmation = this.waitForPreConfirmation.bind(this);
5637
+ }
5575
5638
  /**
5576
5639
  * Async constructor for `TransactionResponse`. This method can be used to create
5577
5640
  * an instance of `TransactionResponse` and wait for the transaction to be fetched
@@ -6088,7 +6151,15 @@ var Provider = class _Provider {
6088
6151
  if (_Provider.ENABLE_RPC_CONSISTENCY && _Provider.hasWriteOperationHappened(url)) {
6089
6152
  _Provider.applyBlockHeight(fullRequest, url);
6090
6153
  }
6091
- return _Provider.fetchAndProcessBlockHeight(url, fullRequest, options);
6154
+ const response = await _Provider.fetchAndProcessBlockHeight(url, fullRequest, options);
6155
+ if (response.body === null) {
6156
+ throw new import_errors21.FuelError(
6157
+ import_errors21.ErrorCode.RESPONSE_BODY_EMPTY,
6158
+ "The response from the server is missing the body",
6159
+ { timestamp: (/* @__PURE__ */ new Date()).toISOString(), request, response }
6160
+ );
6161
+ }
6162
+ return response;
6092
6163
  }, retryOptions);
6093
6164
  }
6094
6165
  static applyBlockHeight(request, url) {
@@ -6111,13 +6182,15 @@ var Provider = class _Provider {
6111
6182
  baseDelay: 500
6112
6183
  };
6113
6184
  for (let retriesLeft = retryOptions.maxRetries; retriesLeft > 0; --retriesLeft) {
6114
- const { extensions } = await parseGraphqlResponse({
6115
- response,
6116
- isSubscription: url.endsWith("-sub")
6117
- });
6118
- _Provider.setCurrentBlockHeight(url, extensions?.current_fuel_block_height);
6119
- if (!extensions?.fuel_block_height_precondition_failed) {
6120
- break;
6185
+ if (response.body) {
6186
+ const { extensions } = await parseGraphqlResponse({
6187
+ response,
6188
+ isSubscription: url.endsWith("-sub")
6189
+ });
6190
+ _Provider.setCurrentBlockHeight(url, extensions?.current_fuel_block_height);
6191
+ if (!extensions?.fuel_block_height_precondition_failed) {
6192
+ break;
6193
+ }
6121
6194
  }
6122
6195
  const retryAttempt = retryOptions.maxRetries - retriesLeft + 1;
6123
6196
  const sleepTime = getWaitDelay(retryOptions, retryAttempt);
@@ -6540,7 +6613,13 @@ var Provider = class _Provider {
6540
6613
  transactionRequest.getTransactionId(await this.getChainId())
6541
6614
  );
6542
6615
  const chainId = await this.getChainId();
6543
- return new TransactionResponse(transactionRequest, this, chainId, abis, subscription);
6616
+ return new TransactionResponse({
6617
+ transactionRequestOrId: transactionRequest,
6618
+ provider: this,
6619
+ chainId,
6620
+ abis,
6621
+ submitAndAwaitSubscription: subscription
6622
+ });
6544
6623
  }
6545
6624
  /**
6546
6625
  * Executes a transaction without actually submitting it to the chain.
@@ -7635,7 +7714,11 @@ var Provider = class _Provider {
7635
7714
  */
7636
7715
  async getTransactionResponse(transactionId) {
7637
7716
  const chainId = await this.getChainId();
7638
- return new TransactionResponse(transactionId, this, chainId);
7717
+ return new TransactionResponse({
7718
+ transactionRequestOrId: transactionId,
7719
+ provider: this,
7720
+ chainId
7721
+ });
7639
7722
  }
7640
7723
  /**
7641
7724
  * Returns Message for given nonce.
@@ -7806,8 +7889,8 @@ var TestAssetId = class _TestAssetId {
7806
7889
 
7807
7890
  // src/test-utils/wallet-config.ts
7808
7891
  var import_crypto9 = require("@fuel-ts/crypto");
7809
- var import_errors28 = require("@fuel-ts/errors");
7810
- var import_math25 = require("@fuel-ts/math");
7892
+ var import_errors29 = require("@fuel-ts/errors");
7893
+ var import_math26 = require("@fuel-ts/math");
7811
7894
  var import_utils46 = require("@fuel-ts/utils");
7812
7895
 
7813
7896
  // src/wallet/base-wallet-unlocked.ts
@@ -7816,13 +7899,13 @@ var import_utils41 = require("@fuel-ts/utils");
7816
7899
 
7817
7900
  // src/account.ts
7818
7901
  var import_abi_coder10 = require("@fuel-ts/abi-coder");
7819
- var import_address6 = require("@fuel-ts/address");
7902
+ var import_address7 = require("@fuel-ts/address");
7820
7903
  var import_crypto5 = require("@fuel-ts/crypto");
7821
- var import_errors23 = require("@fuel-ts/errors");
7822
- var import_math23 = require("@fuel-ts/math");
7823
- var import_transactions28 = require("@fuel-ts/transactions");
7904
+ var import_errors24 = require("@fuel-ts/errors");
7905
+ var import_math24 = require("@fuel-ts/math");
7906
+ var import_transactions29 = require("@fuel-ts/transactions");
7824
7907
  var import_utils39 = require("@fuel-ts/utils");
7825
- var import_ramda9 = require("ramda");
7908
+ var import_ramda10 = require("ramda");
7826
7909
 
7827
7910
  // src/types.ts
7828
7911
  var AbstractAccount = class {
@@ -7831,9 +7914,157 @@ var AbstractAccount = class {
7831
7914
  }
7832
7915
  };
7833
7916
 
7917
+ // src/utils/consolidate-coins.ts
7918
+ var import_address5 = require("@fuel-ts/address");
7919
+ var import_errors23 = require("@fuel-ts/errors");
7920
+ var import_math23 = require("@fuel-ts/math");
7921
+ var import_transactions28 = require("@fuel-ts/transactions");
7922
+ var import_ramda9 = require("ramda");
7923
+ var CONSOLIDATABLE_ERROR_CODES = [import_errors23.ErrorCode.MAX_COINS_REACHED];
7924
+ var consolidateCoinsIfRequired = /* @__PURE__ */ __name(async (opts) => {
7925
+ const { error: errorUnknown, account, skipAutoConsolidation = false } = opts;
7926
+ if (skipAutoConsolidation) {
7927
+ return false;
7928
+ }
7929
+ const error = import_errors23.FuelError.parse(errorUnknown);
7930
+ if (CONSOLIDATABLE_ERROR_CODES.includes(error.code)) {
7931
+ const { assetId, owner } = error.metadata;
7932
+ return account.startConsolidation({
7933
+ owner,
7934
+ assetId
7935
+ });
7936
+ }
7937
+ return false;
7938
+ }, "consolidateCoinsIfRequired");
7939
+ var getAllCoins = /* @__PURE__ */ __name(async (account, assetId) => {
7940
+ const all = [];
7941
+ let hasNextPage = true;
7942
+ let after;
7943
+ while (hasNextPage) {
7944
+ const { coins, pageInfo } = await account.getCoins(assetId, { after });
7945
+ all.push(...coins);
7946
+ after = coins.pop()?.id;
7947
+ hasNextPage = pageInfo.hasNextPage;
7948
+ }
7949
+ return { coins: all };
7950
+ }, "getAllCoins");
7951
+ var sortCoins = /* @__PURE__ */ __name(({ coins }) => coins.sort((a, b) => b.amount.cmp(a.amount)), "sortCoins");
7952
+ var createOuputCoin = /* @__PURE__ */ __name((opts) => {
7953
+ const { transactionId, outputs, baseAssetId } = opts;
7954
+ const outputChangeIndex = outputs.findIndex(
7955
+ (output) => output.type === import_transactions28.OutputType.Change && output.assetId === baseAssetId
7956
+ );
7957
+ if (outputChangeIndex === -1) {
7958
+ throw new import_errors23.FuelError(import_errors23.ErrorCode.UNKNOWN, "No change output found");
7959
+ }
7960
+ const outputCoin = outputs[outputChangeIndex];
7961
+ const outputIndexPadded = Number(outputChangeIndex).toString().padStart(4, "0");
7962
+ return {
7963
+ id: `${transactionId}${outputIndexPadded}`,
7964
+ assetId: outputCoin.assetId,
7965
+ amount: outputCoin.amount,
7966
+ owner: new import_address5.Address(outputCoin.to),
7967
+ blockCreated: (0, import_math23.bn)(0),
7968
+ txCreatedIdx: (0, import_math23.bn)(0)
7969
+ };
7970
+ }, "createOuputCoin");
7971
+ var consolidateCoins = /* @__PURE__ */ __name(async ({
7972
+ account,
7973
+ assetId
7974
+ }) => {
7975
+ const chainInfo = await account.provider.getChain();
7976
+ const chainId = chainInfo.consensusParameters.chainId.toNumber();
7977
+ const gasPrice = await account.provider.estimateGasPrice(10);
7978
+ const maxInputs = chainInfo.consensusParameters.txParameters.maxInputs.toNumber();
7979
+ const baseAssetId = await account.provider.getBaseAssetId();
7980
+ const isBaseAsset = assetId === baseAssetId;
7981
+ const batchSize = maxInputs;
7982
+ const numberOfFundingCoins = maxInputs;
7983
+ let funding = [];
7984
+ let dust = [];
7985
+ if (isBaseAsset) {
7986
+ const coins = await getAllCoins(account, baseAssetId).then(sortCoins);
7987
+ funding = coins.slice(0, numberOfFundingCoins);
7988
+ dust = coins.slice(numberOfFundingCoins);
7989
+ } else {
7990
+ funding = await getAllCoins(account, baseAssetId).then(sortCoins).then((coins) => coins.slice(0, numberOfFundingCoins));
7991
+ dust = await getAllCoins(account, assetId).then(({ coins }) => coins);
7992
+ }
7993
+ if (funding.length === 0) {
7994
+ throw new import_errors23.FuelError(
7995
+ import_errors23.ErrorCode.INSUFFICIENT_FUNDS,
7996
+ `Insufficient funds to consolidate.
7997
+ Asset ID: ${baseAssetId}
7998
+ Owner: ${account.address.toB256()}`
7999
+ );
8000
+ }
8001
+ const batches = [
8002
+ ...(0, import_ramda9.splitEvery)(batchSize, funding),
8003
+ // We leave one coin for the funding coin
8004
+ ...(0, import_ramda9.splitEvery)(batchSize - 1, dust)
8005
+ ];
8006
+ const txs = batches.map((batch) => {
8007
+ const request = new ScriptTransactionRequest({
8008
+ scriptData: "0x"
8009
+ });
8010
+ request.addResources(batch);
8011
+ return request;
8012
+ });
8013
+ const submitAll = /* @__PURE__ */ __name(async (opts = {}) => {
8014
+ const txResponses = [];
8015
+ let previousTx;
8016
+ for (let i = 0; i < txs.length; i++) {
8017
+ let currentTx = txs[i];
8018
+ const step = i + 1;
8019
+ if (previousTx) {
8020
+ const coin = createOuputCoin({
8021
+ transactionId: previousTx.transactionId,
8022
+ outputs: previousTx.outputs,
8023
+ baseAssetId
8024
+ });
8025
+ currentTx.addResource(coin);
8026
+ }
8027
+ if ("populateTransactionPredicateData" in account && typeof account.populateTransactionPredicateData === "function") {
8028
+ currentTx = account.populateTransactionPredicateData(currentTx);
8029
+ currentTx = await account.provider.estimatePredicates(currentTx);
8030
+ }
8031
+ const fee = calculateGasFee({
8032
+ gasPrice,
8033
+ gas: currentTx.calculateMinGas(chainInfo),
8034
+ priceFactor: chainInfo.consensusParameters.feeParameters.gasPriceFactor,
8035
+ tip: currentTx.tip
8036
+ });
8037
+ currentTx.maxFee = fee;
8038
+ currentTx.gasLimit = (0, import_math23.bn)(1e3);
8039
+ opts.onTransactionStart?.({
8040
+ tx: currentTx,
8041
+ step,
8042
+ assetId,
8043
+ transactionId: currentTx.getTransactionId(chainId)
8044
+ });
8045
+ const response = await account.sendTransaction(currentTx);
8046
+ const result = await response.waitForResult();
8047
+ txResponses.push(result);
8048
+ previousTx = {
8049
+ transactionId: response.id,
8050
+ outputs: result.transaction.outputs
8051
+ };
8052
+ }
8053
+ return {
8054
+ txResponses,
8055
+ errors: []
8056
+ };
8057
+ }, "submitAll");
8058
+ return {
8059
+ txs,
8060
+ totalFeeCost: txs.reduce((acc, request) => acc.add(request.maxFee), (0, import_math23.bn)(0)),
8061
+ submitAll
8062
+ };
8063
+ }, "consolidateCoins");
8064
+
7834
8065
  // src/utils/formatTransferToContractScriptData.ts
7835
8066
  var import_abi_coder9 = require("@fuel-ts/abi-coder");
7836
- var import_address5 = require("@fuel-ts/address");
8067
+ var import_address6 = require("@fuel-ts/address");
7837
8068
  var import_utils38 = require("@fuel-ts/utils");
7838
8069
  var asm = __toESM(require("@fuels/vm-asm"));
7839
8070
  var formatTransferToContractScriptData = /* @__PURE__ */ __name((transferParams) => {
@@ -7841,7 +8072,7 @@ var formatTransferToContractScriptData = /* @__PURE__ */ __name((transferParams)
7841
8072
  return transferParams.reduce((acc, transferParam) => {
7842
8073
  const { assetId, amount, contractId } = transferParam;
7843
8074
  const encoded = numberCoder.encode(amount);
7844
- const scriptData = (0, import_utils38.concat)([new import_address5.Address(contractId).toBytes(), encoded, (0, import_utils38.arrayify)(assetId)]);
8075
+ const scriptData = (0, import_utils38.concat)([new import_address6.Address(contractId).toBytes(), encoded, (0, import_utils38.arrayify)(assetId)]);
7845
8076
  return (0, import_utils38.concat)([acc, scriptData]);
7846
8077
  }, new Uint8Array());
7847
8078
  }, "formatTransferToContractScriptData");
@@ -7912,7 +8143,7 @@ var Account = class extends AbstractAccount {
7912
8143
  super();
7913
8144
  this._provider = provider;
7914
8145
  this._connector = connector;
7915
- this.address = new import_address6.Address(address);
8146
+ this.address = new import_address7.Address(address);
7916
8147
  }
7917
8148
  /**
7918
8149
  * The provider used to interact with the network.
@@ -7923,7 +8154,7 @@ var Account = class extends AbstractAccount {
7923
8154
  */
7924
8155
  get provider() {
7925
8156
  if (!this._provider) {
7926
- throw new import_errors23.FuelError(import_errors23.ErrorCode.MISSING_PROVIDER, "Provider not set");
8157
+ throw new import_errors24.FuelError(import_errors24.ErrorCode.MISSING_PROVIDER, "Provider not set");
7927
8158
  }
7928
8159
  return this._provider;
7929
8160
  }
@@ -7950,10 +8181,24 @@ var Account = class extends AbstractAccount {
7950
8181
  *
7951
8182
  * @param quantities - Quantities of resources to be obtained.
7952
8183
  * @param resourcesIdsToIgnore - IDs of resources to be excluded from the query (optional).
8184
+ * @param skipAutoConsolidation - Whether to skip the automatic consolidatation of coins process (optional).
7953
8185
  * @returns A promise that resolves to an array of Resources.
7954
8186
  */
7955
- async getResourcesToSpend(quantities, resourcesIdsToIgnore) {
7956
- return this.provider.getResourcesToSpend(this.address, quantities, resourcesIdsToIgnore);
8187
+ async getResourcesToSpend(quantities, resourcesIdsToIgnore, { skipAutoConsolidation } = {}) {
8188
+ const getResourcesToSpend = /* @__PURE__ */ __name(() => this.provider.getResourcesToSpend(this.address, quantities, resourcesIdsToIgnore), "getResourcesToSpend");
8189
+ try {
8190
+ return await getResourcesToSpend();
8191
+ } catch (error) {
8192
+ const shouldRetry = await consolidateCoinsIfRequired({
8193
+ error,
8194
+ account: this,
8195
+ skipAutoConsolidation
8196
+ });
8197
+ if (!shouldRetry) {
8198
+ throw error;
8199
+ }
8200
+ return await getResourcesToSpend();
8201
+ }
7957
8202
  }
7958
8203
  /**
7959
8204
  * Retrieves coins owned by the account.
@@ -8002,7 +8247,7 @@ var Account = class extends AbstractAccount {
8002
8247
  * @deprecated Use provider.assembleTx instead
8003
8248
  * Check the migration guide https://docs.fuel.network/docs/fuels-ts/transactions/assemble-tx-migration-guide/ for more information.
8004
8249
  */
8005
- async fund(request, params) {
8250
+ async fund(request, params, { skipAutoConsolidation } = {}) {
8006
8251
  const {
8007
8252
  addedSignatures,
8008
8253
  estimatedPredicates,
@@ -8014,9 +8259,9 @@ var Account = class extends AbstractAccount {
8014
8259
  const chainId = await this.provider.getChainId();
8015
8260
  const fee = request.maxFee;
8016
8261
  const baseAssetId = await this.provider.getBaseAssetId();
8017
- const requiredInBaseAsset = requiredQuantities.find((quantity) => quantity.assetId === baseAssetId)?.amount || (0, import_math23.bn)(0);
8262
+ const requiredInBaseAsset = requiredQuantities.find((quantity) => quantity.assetId === baseAssetId)?.amount || (0, import_math24.bn)(0);
8018
8263
  const requiredQuantitiesWithFee = addAmountToCoinQuantities({
8019
- amount: (0, import_math23.bn)(fee),
8264
+ amount: (0, import_math24.bn)(fee),
8020
8265
  assetId: baseAssetId,
8021
8266
  coinQuantities: requiredQuantities
8022
8267
  });
@@ -8024,7 +8269,7 @@ var Account = class extends AbstractAccount {
8024
8269
  requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
8025
8270
  quantitiesDict[assetId] = {
8026
8271
  required: amount,
8027
- owned: (0, import_math23.bn)(0)
8272
+ owned: (0, import_math24.bn)(0)
8028
8273
  };
8029
8274
  });
8030
8275
  request.inputs.filter(isRequestInputResource).forEach((input) => {
@@ -8048,11 +8293,12 @@ var Account = class extends AbstractAccount {
8048
8293
  while (needsToBeFunded && fundingAttempts < MAX_FUNDING_ATTEMPTS) {
8049
8294
  const resources = await this.getResourcesToSpend(
8050
8295
  missingQuantities,
8051
- cacheRequestInputsResourcesFromOwner(request.inputs, this.address)
8296
+ cacheRequestInputsResourcesFromOwner(request.inputs, this.address),
8297
+ { skipAutoConsolidation }
8052
8298
  );
8053
8299
  request.addResources(resources);
8054
8300
  request.updatePredicateGasUsed(estimatedPredicates);
8055
- const requestToReestimate2 = (0, import_ramda9.clone)(request);
8301
+ const requestToReestimate2 = (0, import_ramda10.clone)(request);
8056
8302
  if (addedSignatures) {
8057
8303
  Array.from({ length: addedSignatures }).forEach(
8058
8304
  () => requestToReestimate2.addEmptyWitness()
@@ -8085,15 +8331,15 @@ var Account = class extends AbstractAccount {
8085
8331
  fundingAttempts += 1;
8086
8332
  }
8087
8333
  if (needsToBeFunded) {
8088
- throw new import_errors23.FuelError(
8089
- import_errors23.ErrorCode.INSUFFICIENT_FUNDS_OR_MAX_COINS,
8334
+ throw new import_errors24.FuelError(
8335
+ import_errors24.ErrorCode.INSUFFICIENT_FUNDS,
8090
8336
  `The account ${this.address} does not have enough base asset funds to cover the transaction execution.`
8091
8337
  );
8092
8338
  }
8093
8339
  request.updateState(chainId, "funded", transactionSummary);
8094
8340
  await this.provider.validateTransaction(request);
8095
8341
  request.updatePredicateGasUsed(estimatedPredicates);
8096
- const requestToReestimate = (0, import_ramda9.clone)(request);
8342
+ const requestToReestimate = (0, import_ramda10.clone)(request);
8097
8343
  if (addedSignatures) {
8098
8344
  Array.from({ length: addedSignatures }).forEach(() => requestToReestimate.addEmptyWitness());
8099
8345
  }
@@ -8114,16 +8360,20 @@ var Account = class extends AbstractAccount {
8114
8360
  * @param amount - The amount of coins to transfer.
8115
8361
  * @param assetId - The asset ID of the coins to transfer (optional).
8116
8362
  * @param txParams - The transaction parameters (optional).
8363
+ * @param skipAutoConsolidation - Whether to skip the automatic consolidatation of coins process (optional).
8117
8364
  * @returns A promise that resolves to the prepared transaction request.
8118
8365
  */
8119
- async createTransfer(destination, amount, assetId, txParams = {}) {
8366
+ async createTransfer(destination, amount, assetId, txParams = {}, { skipAutoConsolidation } = {}) {
8120
8367
  let request = new ScriptTransactionRequest(txParams);
8121
8368
  request = this.addTransfer(request, {
8122
8369
  destination,
8123
8370
  amount,
8124
8371
  assetId: assetId || await this.provider.getBaseAssetId()
8125
8372
  });
8126
- const { gasPrice, transactionRequest } = await this.assembleTx(request);
8373
+ const { gasPrice, transactionRequest } = await this.assembleTx({
8374
+ transactionRequest: request,
8375
+ skipAutoConsolidation
8376
+ });
8127
8377
  request = await setAndValidateGasAndFeeForAssembledTx({
8128
8378
  gasPrice,
8129
8379
  provider: this.provider,
@@ -8140,10 +8390,13 @@ var Account = class extends AbstractAccount {
8140
8390
  * @param amount - The amount of coins to transfer.
8141
8391
  * @param assetId - The asset ID of the coins to transfer (optional).
8142
8392
  * @param txParams - The transaction parameters (optional).
8393
+ * @param skipAutoConsolidation - Whether to skip the automatic consolidatation of coins process (optional).
8143
8394
  * @returns A promise that resolves to the transaction response.
8144
8395
  */
8145
- async transfer(destination, amount, assetId, txParams = {}) {
8146
- const request = await this.createTransfer(destination, amount, assetId, txParams);
8396
+ async transfer(destination, amount, assetId, txParams = {}, { skipAutoConsolidation } = {}) {
8397
+ const request = await this.createTransfer(destination, amount, assetId, txParams, {
8398
+ skipAutoConsolidation
8399
+ });
8147
8400
  return this.sendTransaction(request, { estimateTxDependencies: false });
8148
8401
  }
8149
8402
  /**
@@ -8151,12 +8404,16 @@ var Account = class extends AbstractAccount {
8151
8404
  *
8152
8405
  * @param transferParams - An array of `TransferParams` objects representing the transfers to be made.
8153
8406
  * @param txParams - Optional transaction parameters.
8407
+ * @param skipAutoConsolidation - Whether to skip the automatic consolidatation of coins process (optional).
8154
8408
  * @returns A promise that resolves to a `TransactionResponse` object representing the transaction result.
8155
8409
  */
8156
- async batchTransfer(transferParams, txParams = {}) {
8410
+ async batchTransfer(transferParams, txParams = {}, { skipAutoConsolidation } = {}) {
8157
8411
  let request = new ScriptTransactionRequest(txParams);
8158
8412
  request = this.addBatchTransfer(request, transferParams);
8159
- const { gasPrice, transactionRequest } = await this.assembleTx(request);
8413
+ const { gasPrice, transactionRequest } = await this.assembleTx({
8414
+ transactionRequest: request,
8415
+ skipAutoConsolidation
8416
+ });
8160
8417
  request = await setAndValidateGasAndFeeForAssembledTx({
8161
8418
  gasPrice,
8162
8419
  provider: this.provider,
@@ -8176,7 +8433,7 @@ var Account = class extends AbstractAccount {
8176
8433
  addTransfer(request, transferParams) {
8177
8434
  const { destination, amount, assetId } = transferParams;
8178
8435
  this.validateTransferAmount(amount);
8179
- request.addCoinOutput(new import_address6.Address(destination), amount, assetId);
8436
+ request.addCoinOutput(new import_address7.Address(destination), amount, assetId);
8180
8437
  return request;
8181
8438
  }
8182
8439
  /**
@@ -8203,24 +8460,27 @@ var Account = class extends AbstractAccount {
8203
8460
  * @param amount - The amount of coins to transfer.
8204
8461
  * @param assetId - The asset ID of the coins to transfer (optional).
8205
8462
  * @param txParams - The transaction parameters (optional).
8463
+ * @param skipAutoConsolidation - Whether to skip the automatic consolidatation of coins process (optional).
8206
8464
  * @returns A promise that resolves to the transaction response.
8207
8465
  */
8208
- async transferToContract(contractId, amount, assetId, txParams = {}) {
8209
- return this.batchTransferToContracts([{ amount, assetId, contractId }], txParams);
8466
+ async transferToContract(contractId, amount, assetId, txParams = {}, { skipAutoConsolidation } = {}) {
8467
+ return this.batchTransferToContracts([{ amount, assetId, contractId }], txParams, {
8468
+ skipAutoConsolidation
8469
+ });
8210
8470
  }
8211
- async batchTransferToContracts(contractTransferParams, txParams = {}) {
8471
+ async batchTransferToContracts(contractTransferParams, txParams = {}, { skipAutoConsolidation } = {}) {
8212
8472
  let request = new ScriptTransactionRequest({
8213
8473
  ...txParams
8214
8474
  });
8215
8475
  const quantities = [];
8216
8476
  const defaultAssetId = await this.provider.getBaseAssetId();
8217
8477
  const transferParams = contractTransferParams.map((transferParam) => {
8218
- const amount = (0, import_math23.bn)(transferParam.amount);
8219
- const contractAddress = new import_address6.Address(transferParam.contractId);
8478
+ const amount = (0, import_math24.bn)(transferParam.amount);
8479
+ const contractAddress = new import_address7.Address(transferParam.contractId);
8220
8480
  const assetId = transferParam.assetId ? (0, import_utils39.hexlify)(transferParam.assetId) : defaultAssetId;
8221
8481
  if (amount.lte(0)) {
8222
- throw new import_errors23.FuelError(
8223
- import_errors23.ErrorCode.INVALID_TRANSFER_AMOUNT,
8482
+ throw new import_errors24.FuelError(
8483
+ import_errors24.ErrorCode.INVALID_TRANSFER_AMOUNT,
8224
8484
  "Transfer amount must be a positive number."
8225
8485
  );
8226
8486
  }
@@ -8235,7 +8495,11 @@ var Account = class extends AbstractAccount {
8235
8495
  const { script, scriptData } = await assembleTransferToContractScript(transferParams);
8236
8496
  request.script = script;
8237
8497
  request.scriptData = scriptData;
8238
- const { gasPrice, transactionRequest } = await this.assembleTx(request, quantities);
8498
+ const { gasPrice, transactionRequest } = await this.assembleTx({
8499
+ transactionRequest: request,
8500
+ quantities,
8501
+ skipAutoConsolidation
8502
+ });
8239
8503
  request = await setAndValidateGasAndFeeForAssembledTx({
8240
8504
  gasPrice,
8241
8505
  provider: this.provider,
@@ -8251,15 +8515,16 @@ var Account = class extends AbstractAccount {
8251
8515
  * @param recipient - Address of the recipient on the base chain.
8252
8516
  * @param amount - Amount of base asset.
8253
8517
  * @param txParams - The transaction parameters (optional).
8518
+ * @param skipAutoConsolidation - Whether to skip the automatic consolidatation of coins process (optional).
8254
8519
  * @returns A promise that resolves to the transaction response.
8255
8520
  */
8256
- async withdrawToBaseLayer(recipient, amount, txParams = {}) {
8257
- const recipientAddress = new import_address6.Address(recipient);
8521
+ async withdrawToBaseLayer(recipient, amount, txParams = {}, { skipAutoConsolidation } = {}) {
8522
+ const recipientAddress = new import_address7.Address(recipient);
8258
8523
  const recipientDataArray = (0, import_utils39.arrayify)(
8259
8524
  "0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
8260
8525
  );
8261
8526
  const amountDataArray = (0, import_utils39.arrayify)(
8262
- "0x".concat((0, import_math23.bn)(amount).toHex().substring(2).padStart(16, "0"))
8527
+ "0x".concat((0, import_math24.bn)(amount).toHex().substring(2).padStart(16, "0"))
8263
8528
  );
8264
8529
  const script = new Uint8Array([
8265
8530
  ...(0, import_utils39.arrayify)(withdrawScript.bytes),
@@ -8269,8 +8534,12 @@ var Account = class extends AbstractAccount {
8269
8534
  const params = { script, ...txParams };
8270
8535
  const baseAssetId = await this.provider.getBaseAssetId();
8271
8536
  let request = new ScriptTransactionRequest(params);
8272
- const quantities = [{ amount: (0, import_math23.bn)(amount), assetId: baseAssetId }];
8273
- const { gasPrice, transactionRequest } = await this.assembleTx(request, quantities);
8537
+ const quantities = [{ amount: (0, import_math24.bn)(amount), assetId: baseAssetId }];
8538
+ const { gasPrice, transactionRequest } = await this.assembleTx({
8539
+ transactionRequest: request,
8540
+ quantities,
8541
+ skipAutoConsolidation
8542
+ });
8274
8543
  request = await setAndValidateGasAndFeeForAssembledTx({
8275
8544
  gasPrice,
8276
8545
  provider: this.provider,
@@ -8280,6 +8549,25 @@ var Account = class extends AbstractAccount {
8280
8549
  });
8281
8550
  return this.sendTransaction(request);
8282
8551
  }
8552
+ /**
8553
+ * Start the consolidation process
8554
+ *
8555
+ * @param owner - The B256 address of the owner.
8556
+ * @param assetId - The asset ID that requires consolidation.
8557
+ */
8558
+ async startConsolidation(opts) {
8559
+ if (this._connector) {
8560
+ await this._connector.startConsolidation(opts);
8561
+ return false;
8562
+ }
8563
+ const { owner, assetId } = opts;
8564
+ if (owner !== this.address.toB256()) {
8565
+ return false;
8566
+ }
8567
+ const { submitAll } = await consolidateCoins({ account: this, assetId });
8568
+ await submitAll();
8569
+ return true;
8570
+ }
8283
8571
  /**
8284
8572
  * Consolidates base asset UTXOs into fewer, larger ones.
8285
8573
  *
@@ -8299,6 +8587,7 @@ var Account = class extends AbstractAccount {
8299
8587
  const isBaseAsset = baseAssetId === assetId;
8300
8588
  let submitAll;
8301
8589
  const consolidationParams = {
8590
+ assetId,
8302
8591
  coins,
8303
8592
  mode: params.mode,
8304
8593
  outputNum: params.outputNum
@@ -8306,10 +8595,7 @@ var Account = class extends AbstractAccount {
8306
8595
  if (isBaseAsset) {
8307
8596
  ({ submitAll } = await this.assembleBaseAssetConsolidationTxs(consolidationParams));
8308
8597
  } else {
8309
- throw new import_errors23.FuelError(
8310
- import_errors23.ErrorCode.UNSUPPORTED_FEATURE,
8311
- "Consolidation for non-base assets is not supported yet."
8312
- );
8598
+ ({ submitAll } = await this.assembleNonBaseAssetConsolidationTxs(consolidationParams));
8313
8599
  }
8314
8600
  return submitAll();
8315
8601
  }
@@ -8330,7 +8616,7 @@ var Account = class extends AbstractAccount {
8330
8616
  this.validateConsolidationTxsCoins(coins, baseAssetId);
8331
8617
  const chainInfo = await this.provider.getChain();
8332
8618
  const maxInputsNumber = chainInfo.consensusParameters.txParameters.maxInputs.toNumber();
8333
- let totalFeeCost = (0, import_math23.bn)(0);
8619
+ let totalFeeCost = (0, import_math24.bn)(0);
8334
8620
  const txs = [];
8335
8621
  const coinsBatches = splitCoinsIntoBatches(coins, maxInputsNumber);
8336
8622
  const gasPrice = await this.provider.estimateGasPrice(10);
@@ -8354,10 +8640,10 @@ var Account = class extends AbstractAccount {
8354
8640
  });
8355
8641
  request.maxFee = fee;
8356
8642
  if (consolidateMoreThanOneCoin) {
8357
- const total = request.inputs.filter(isRequestInputCoin).reduce((acc, input) => acc.add(input.amount), (0, import_math23.bn)(0));
8643
+ const total = request.inputs.filter(isRequestInputCoin).reduce((acc, input) => acc.add(input.amount), (0, import_math24.bn)(0));
8358
8644
  const amountPerNewUtxo = total.div(outputNum + 1);
8359
8645
  request.outputs.forEach((output) => {
8360
- if (output.type === import_transactions28.OutputType.Coin) {
8646
+ if (output.type === import_transactions29.OutputType.Coin) {
8361
8647
  output.amount = amountPerNewUtxo;
8362
8648
  }
8363
8649
  });
@@ -8368,6 +8654,70 @@ var Account = class extends AbstractAccount {
8368
8654
  const submitAll = this.prepareSubmitAll({ txs, mode });
8369
8655
  return { txs, totalFeeCost, submitAll };
8370
8656
  }
8657
+ async assembleNonBaseAssetConsolidationTxs(params) {
8658
+ const { assetId, coins, mode = "parallel", outputNum = 1 } = params;
8659
+ this.validateConsolidationTxsCoins(coins, assetId);
8660
+ const chainInfo = await this.provider.getChain();
8661
+ const maxInputsNumber = chainInfo.consensusParameters.txParameters.maxInputs.toNumber();
8662
+ const baseAssetId = chainInfo.consensusParameters.baseAssetId;
8663
+ const { coins: baseAssetCoins } = await this.provider.getCoins(this.address, baseAssetId);
8664
+ let totalFeeCost = (0, import_math24.bn)(0);
8665
+ const txs = [];
8666
+ const gasPrice = await this.provider.estimateGasPrice(10);
8667
+ const consolidateMoreThanOneCoin = outputNum > 1;
8668
+ const assetCoinBatches = splitCoinsIntoBatches(coins, maxInputsNumber);
8669
+ assetCoinBatches.filter((batch) => batch.length > 1).forEach((coinBatch) => {
8670
+ const request = new ScriptTransactionRequest({
8671
+ script: "0x"
8672
+ });
8673
+ request.addResources(coinBatch);
8674
+ if (consolidateMoreThanOneCoin) {
8675
+ Array.from({ length: outputNum - 1 }).forEach(() => {
8676
+ request.addCoinOutput(this.address, 0, assetId);
8677
+ });
8678
+ }
8679
+ const minGas = request.calculateMinGas(chainInfo);
8680
+ const fee = calculateGasFee({
8681
+ gasPrice,
8682
+ gas: minGas,
8683
+ priceFactor: chainInfo.consensusParameters.feeParameters.gasPriceFactor,
8684
+ tip: request.tip
8685
+ });
8686
+ request.maxFee = fee;
8687
+ if (consolidateMoreThanOneCoin) {
8688
+ const total = request.inputs.filter(isRequestInputCoin).reduce((acc, input) => acc.add(input.amount), (0, import_math24.bn)(0));
8689
+ const amountPerNewUtxo = total.div(outputNum + 1);
8690
+ request.outputs.forEach((output) => {
8691
+ if (output.type === import_transactions29.OutputType.Coin) {
8692
+ output.amount = amountPerNewUtxo;
8693
+ }
8694
+ });
8695
+ }
8696
+ totalFeeCost = totalFeeCost.add(fee);
8697
+ const baseAssetResources = [];
8698
+ let fundingFeeTotal = (0, import_math24.bn)(0);
8699
+ while (fundingFeeTotal.lt(fee)) {
8700
+ const baseAssetCoin = baseAssetCoins.pop();
8701
+ if (!baseAssetCoin) {
8702
+ break;
8703
+ }
8704
+ baseAssetResources.push(baseAssetCoin);
8705
+ fundingFeeTotal = fundingFeeTotal.add(baseAssetCoin.amount);
8706
+ }
8707
+ const { inputs } = request;
8708
+ request.inputs = inputs.slice(0, maxInputsNumber - baseAssetResources.length);
8709
+ const removedCoins = coinBatch.slice(maxInputsNumber - baseAssetResources.length);
8710
+ request.addResources(baseAssetResources);
8711
+ const lastCoinBatch = assetCoinBatches[assetCoinBatches.length - 1];
8712
+ lastCoinBatch.push(...removedCoins);
8713
+ if (lastCoinBatch.length > maxInputsNumber) {
8714
+ assetCoinBatches.push(lastCoinBatch.slice(maxInputsNumber));
8715
+ }
8716
+ txs.push(request);
8717
+ });
8718
+ const submitAll = this.prepareSubmitAll({ txs, mode });
8719
+ return { txs, totalFeeCost, submitAll };
8720
+ }
8371
8721
  /**
8372
8722
  * Prepares a function to submit all transactions either sequentially or in parallel.
8373
8723
  *
@@ -8422,13 +8772,13 @@ var Account = class extends AbstractAccount {
8422
8772
  * Check the migration guide https://docs.fuel.network/docs/fuels-ts/transactions/assemble-tx-migration-guide/ for more information.
8423
8773
  */
8424
8774
  async getTransactionCost(transactionRequestLike, { signatureCallback, quantities = [], gasPrice } = {}) {
8425
- const txRequestClone = (0, import_ramda9.clone)(transactionRequestify(transactionRequestLike));
8775
+ const txRequestClone = (0, import_ramda10.clone)(transactionRequestify(transactionRequestLike));
8426
8776
  const baseAssetId = await this.provider.getBaseAssetId();
8427
8777
  const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
8428
8778
  const requiredQuantities = mergeQuantities(coinOutputsQuantities, quantities);
8429
- const transactionFeeForDryRun = [{ assetId: baseAssetId, amount: (0, import_math23.bn)("100000000000000000") }];
8779
+ const transactionFeeForDryRun = [{ assetId: baseAssetId, amount: (0, import_math24.bn)("100000000000000000") }];
8430
8780
  const findAssetInput = /* @__PURE__ */ __name((assetId) => txRequestClone.inputs.find((input) => {
8431
- if (input.type === import_transactions28.InputType.Coin) {
8781
+ if (input.type === import_transactions29.InputType.Coin) {
8432
8782
  return input.assetId === assetId;
8433
8783
  }
8434
8784
  if (isRequestInputMessageWithoutData(input)) {
@@ -8474,7 +8824,7 @@ var Account = class extends AbstractAccount {
8474
8824
  */
8475
8825
  async signMessage(message) {
8476
8826
  if (!this._connector) {
8477
- throw new import_errors23.FuelError(import_errors23.ErrorCode.MISSING_CONNECTOR, "A connector is required to sign messages.");
8827
+ throw new import_errors24.FuelError(import_errors24.ErrorCode.MISSING_CONNECTOR, "A connector is required to sign messages.");
8478
8828
  }
8479
8829
  return this._connector.signMessage(this.address.toString(), message);
8480
8830
  }
@@ -8486,8 +8836,8 @@ var Account = class extends AbstractAccount {
8486
8836
  */
8487
8837
  async signTransaction(transactionRequestLike, connectorOptions = {}) {
8488
8838
  if (!this._connector) {
8489
- throw new import_errors23.FuelError(
8490
- import_errors23.ErrorCode.MISSING_CONNECTOR,
8839
+ throw new import_errors24.FuelError(
8840
+ import_errors24.ErrorCode.MISSING_CONNECTOR,
8491
8841
  "A connector is required to sign transactions."
8492
8842
  );
8493
8843
  }
@@ -8554,8 +8904,8 @@ var Account = class extends AbstractAccount {
8554
8904
  return coins.map((coin) => ({
8555
8905
  id: (0, import_utils39.hexlify)((0, import_crypto5.randomBytes)(import_abi_coder10.UTXO_ID_LEN)),
8556
8906
  owner: this.address,
8557
- blockCreated: (0, import_math23.bn)(1),
8558
- txCreatedIdx: (0, import_math23.bn)(1),
8907
+ blockCreated: (0, import_math24.bn)(1),
8908
+ txCreatedIdx: (0, import_math24.bn)(1),
8559
8909
  ...coin
8560
8910
  }));
8561
8911
  }
@@ -8582,73 +8932,50 @@ var Account = class extends AbstractAccount {
8582
8932
  } : void 0;
8583
8933
  }
8584
8934
  /** @hidden * */
8585
- async assembleTx(transactionRequest, quantities = []) {
8586
- const outputQuantities = transactionRequest.outputs.filter((o) => o.type === import_transactions28.OutputType.Coin).map(({ amount, assetId }) => ({ assetId: String(assetId), amount: (0, import_math23.bn)(amount) }));
8587
- transactionRequest.gasLimit = (0, import_math23.bn)(0);
8588
- transactionRequest.maxFee = (0, import_math23.bn)(0);
8589
- const { assembledRequest, gasPrice } = await this.provider.assembleTx({
8590
- request: transactionRequest,
8591
- accountCoinQuantities: mergeQuantities(outputQuantities, quantities),
8592
- feePayerAccount: this
8593
- });
8594
- return { transactionRequest: assembledRequest, gasPrice };
8935
+ async assembleTx(opts) {
8936
+ const { transactionRequest, quantities = [], skipAutoConsolidation } = opts;
8937
+ const outputQuantities = transactionRequest.outputs.filter((o) => o.type === import_transactions29.OutputType.Coin).map(({ amount, assetId }) => ({ assetId: String(assetId), amount: (0, import_math24.bn)(amount) }));
8938
+ transactionRequest.gasLimit = (0, import_math24.bn)(0);
8939
+ transactionRequest.maxFee = (0, import_math24.bn)(0);
8940
+ const assembleTx = /* @__PURE__ */ __name(async () => {
8941
+ const { assembledRequest, gasPrice } = await this.provider.assembleTx({
8942
+ request: transactionRequest,
8943
+ accountCoinQuantities: mergeQuantities(outputQuantities, quantities),
8944
+ feePayerAccount: this
8945
+ });
8946
+ return { transactionRequest: assembledRequest, gasPrice };
8947
+ }, "assembleTx");
8948
+ try {
8949
+ return await assembleTx();
8950
+ } catch (error) {
8951
+ const shouldRetry = await consolidateCoinsIfRequired({
8952
+ error,
8953
+ account: this,
8954
+ skipAutoConsolidation
8955
+ });
8956
+ if (!shouldRetry) {
8957
+ throw error;
8958
+ }
8959
+ return await assembleTx();
8960
+ }
8595
8961
  }
8596
8962
  /** @hidden * */
8597
8963
  validateTransferAmount(amount) {
8598
- if ((0, import_math23.bn)(amount).lte(0)) {
8599
- throw new import_errors23.FuelError(
8600
- import_errors23.ErrorCode.INVALID_TRANSFER_AMOUNT,
8964
+ if ((0, import_math24.bn)(amount).lte(0)) {
8965
+ throw new import_errors24.FuelError(
8966
+ import_errors24.ErrorCode.INVALID_TRANSFER_AMOUNT,
8601
8967
  "Transfer amount must be a positive number."
8602
8968
  );
8603
8969
  }
8604
8970
  }
8605
8971
  /** @hidden * */
8606
- async estimateAndFundTransaction(transactionRequest, txParams, costParams) {
8607
- let request = transactionRequest;
8608
- const txCost = await this.getTransactionCost(request, costParams);
8609
- request = this.validateGasLimitAndMaxFee({
8610
- transactionRequest: request,
8611
- gasUsed: txCost.gasUsed,
8612
- maxFee: txCost.maxFee,
8613
- txParams
8614
- });
8615
- request = await this.fund(request, txCost);
8616
- return request;
8617
- }
8618
- /** @hidden * */
8619
- validateGasLimitAndMaxFee({
8620
- gasUsed,
8621
- maxFee,
8622
- transactionRequest,
8623
- txParams: { gasLimit: setGasLimit, maxFee: setMaxFee }
8624
- }) {
8625
- const request = transactionRequestify(transactionRequest);
8626
- if (!(0, import_utils39.isDefined)(setGasLimit)) {
8627
- request.gasLimit = gasUsed;
8628
- } else if (gasUsed.gt(setGasLimit)) {
8629
- throw new import_errors23.FuelError(
8630
- import_errors23.ErrorCode.GAS_LIMIT_TOO_LOW,
8631
- `Gas limit '${setGasLimit}' is lower than the required: '${gasUsed}'.`
8632
- );
8633
- }
8634
- if (!(0, import_utils39.isDefined)(setMaxFee)) {
8635
- request.maxFee = maxFee;
8636
- } else if (maxFee.gt(setMaxFee)) {
8637
- throw new import_errors23.FuelError(
8638
- import_errors23.ErrorCode.MAX_FEE_TOO_LOW,
8639
- `Max fee '${setMaxFee}' is lower than the required: '${maxFee}'.`
8640
- );
8641
- }
8642
- return request;
8643
- }
8644
- /** @hidden * */
8645
8972
  validateConsolidationTxsCoins(coins, assetId) {
8646
8973
  if (coins.length <= 1) {
8647
- throw new import_errors23.FuelError(import_errors23.ErrorCode.NO_COINS_TO_CONSOLIDATE, "No coins to consolidate.");
8974
+ throw new import_errors24.FuelError(import_errors24.ErrorCode.NO_COINS_TO_CONSOLIDATE, "No coins to consolidate.");
8648
8975
  }
8649
8976
  if (!coins.every((c) => c.assetId === assetId)) {
8650
- throw new import_errors23.FuelError(
8651
- import_errors23.ErrorCode.COINS_ASSET_ID_MISMATCH,
8977
+ throw new import_errors24.FuelError(
8978
+ import_errors24.ErrorCode.COINS_ASSET_ID_MISMATCH,
8652
8979
  "All coins to consolidate must be from the same asset id."
8653
8980
  );
8654
8981
  }
@@ -8673,9 +9000,9 @@ var Account = class extends AbstractAccount {
8673
9000
  };
8674
9001
 
8675
9002
  // src/wallet/keystore-wallet.ts
8676
- var import_address7 = require("@fuel-ts/address");
9003
+ var import_address8 = require("@fuel-ts/address");
8677
9004
  var import_crypto6 = require("@fuel-ts/crypto");
8678
- var import_errors24 = require("@fuel-ts/errors");
9005
+ var import_errors25 = require("@fuel-ts/errors");
8679
9006
  var import_utils40 = require("@fuel-ts/utils");
8680
9007
  var DEFAULT_KDF_PARAMS_LOG_N = 13;
8681
9008
  var DEFAULT_KDF_PARAMS_R = 8;
@@ -8690,7 +9017,7 @@ var removeHexPrefix = /* @__PURE__ */ __name((hexString) => {
8690
9017
  }, "removeHexPrefix");
8691
9018
  async function encryptKeystoreWallet(privateKey, address, password) {
8692
9019
  const privateKeyBuffer = (0, import_crypto6.bufferFromString)(removeHexPrefix(privateKey), "hex");
8693
- const ownerAddress = new import_address7.Address(address);
9020
+ const ownerAddress = new import_address8.Address(address);
8694
9021
  const salt = (0, import_crypto6.randomBytes)(DEFAULT_KEY_SIZE);
8695
9022
  const key = (0, import_crypto6.scrypt)({
8696
9023
  password: (0, import_crypto6.bufferFromString)(password),
@@ -8753,8 +9080,8 @@ async function decryptKeystoreWallet(jsonWallet, password) {
8753
9080
  const macHashUint8Array = (0, import_crypto6.keccak256)(data);
8754
9081
  const macHash = (0, import_crypto6.stringFromBuffer)(macHashUint8Array, "hex");
8755
9082
  if (mac !== macHash) {
8756
- throw new import_errors24.FuelError(
8757
- import_errors24.ErrorCode.INVALID_PASSWORD,
9083
+ throw new import_errors25.FuelError(
9084
+ import_errors25.ErrorCode.INVALID_PASSWORD,
8758
9085
  "Failed to decrypt the keystore wallet, the provided password is incorrect."
8759
9086
  );
8760
9087
  }
@@ -8893,14 +9220,14 @@ var BaseWalletUnlocked = class extends Account {
8893
9220
 
8894
9221
  // src/hdwallet/hdwallet.ts
8895
9222
  var import_crypto8 = require("@fuel-ts/crypto");
8896
- var import_errors27 = require("@fuel-ts/errors");
9223
+ var import_errors28 = require("@fuel-ts/errors");
8897
9224
  var import_hasher7 = require("@fuel-ts/hasher");
8898
- var import_math24 = require("@fuel-ts/math");
9225
+ var import_math25 = require("@fuel-ts/math");
8899
9226
  var import_utils45 = require("@fuel-ts/utils");
8900
9227
 
8901
9228
  // src/mnemonic/mnemonic.ts
8902
9229
  var import_crypto7 = require("@fuel-ts/crypto");
8903
- var import_errors26 = require("@fuel-ts/errors");
9230
+ var import_errors27 = require("@fuel-ts/errors");
8904
9231
  var import_hasher6 = require("@fuel-ts/hasher");
8905
9232
  var import_utils43 = require("@fuel-ts/utils");
8906
9233
 
@@ -10957,7 +11284,7 @@ var english = [
10957
11284
  ];
10958
11285
 
10959
11286
  // src/mnemonic/utils.ts
10960
- var import_errors25 = require("@fuel-ts/errors");
11287
+ var import_errors26 = require("@fuel-ts/errors");
10961
11288
  var import_hasher5 = require("@fuel-ts/hasher");
10962
11289
  var import_utils42 = require("@fuel-ts/utils");
10963
11290
  function getLowerMask(bits) {
@@ -11011,8 +11338,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
11011
11338
  for (let i = 0; i < words.length; i += 1) {
11012
11339
  const index = wordlist.indexOf(words[i].normalize("NFKD"));
11013
11340
  if (index === -1) {
11014
- throw new import_errors25.FuelError(
11015
- import_errors25.ErrorCode.INVALID_MNEMONIC,
11341
+ throw new import_errors26.FuelError(
11342
+ import_errors26.ErrorCode.INVALID_MNEMONIC,
11016
11343
  `Invalid mnemonic: the word '${words[i]}' is not found in the provided wordlist.`
11017
11344
  );
11018
11345
  }
@@ -11028,8 +11355,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
11028
11355
  const checksumMask = getUpperMask(checksumBits);
11029
11356
  const checksum = (0, import_utils42.arrayify)((0, import_hasher5.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
11030
11357
  if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
11031
- throw new import_errors25.FuelError(
11032
- import_errors25.ErrorCode.INVALID_CHECKSUM,
11358
+ throw new import_errors26.FuelError(
11359
+ import_errors26.ErrorCode.INVALID_CHECKSUM,
11033
11360
  "Checksum validation failed for the provided mnemonic."
11034
11361
  );
11035
11362
  }
@@ -11044,8 +11371,8 @@ var TestnetPRV = "0x04358394";
11044
11371
  var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
11045
11372
  function assertWordList(wordlist) {
11046
11373
  if (wordlist.length !== 2048) {
11047
- throw new import_errors26.FuelError(
11048
- import_errors26.ErrorCode.INVALID_WORD_LIST,
11374
+ throw new import_errors27.FuelError(
11375
+ import_errors27.ErrorCode.INVALID_WORD_LIST,
11049
11376
  `Expected word list length of 2048, but got ${wordlist.length}.`
11050
11377
  );
11051
11378
  }
@@ -11053,8 +11380,8 @@ function assertWordList(wordlist) {
11053
11380
  __name(assertWordList, "assertWordList");
11054
11381
  function assertEntropy(entropy) {
11055
11382
  if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {
11056
- throw new import_errors26.FuelError(
11057
- import_errors26.ErrorCode.INVALID_ENTROPY,
11383
+ throw new import_errors27.FuelError(
11384
+ import_errors27.ErrorCode.INVALID_ENTROPY,
11058
11385
  `Entropy should be between 16 and 32 bytes and a multiple of 4, but got ${entropy.length} bytes.`
11059
11386
  );
11060
11387
  }
@@ -11065,7 +11392,7 @@ function assertMnemonic(words) {
11065
11392
  const errorMsg = `Invalid mnemonic size. Expected one of [${MNEMONIC_SIZES.join(
11066
11393
  ", "
11067
11394
  )}] words, but got ${words.length}.`;
11068
- throw new import_errors26.FuelError(import_errors26.ErrorCode.INVALID_MNEMONIC, errorMsg);
11395
+ throw new import_errors27.FuelError(import_errors27.ErrorCode.INVALID_MNEMONIC, errorMsg);
11069
11396
  }
11070
11397
  }
11071
11398
  __name(assertMnemonic, "assertMnemonic");
@@ -11187,8 +11514,8 @@ var Mnemonic = class _Mnemonic {
11187
11514
  static masterKeysFromSeed(seed) {
11188
11515
  const seedArray = (0, import_utils43.arrayify)(seed);
11189
11516
  if (seedArray.length < 16 || seedArray.length > 64) {
11190
- throw new import_errors26.FuelError(
11191
- import_errors26.ErrorCode.INVALID_SEED,
11517
+ throw new import_errors27.FuelError(
11518
+ import_errors27.ErrorCode.INVALID_SEED,
11192
11519
  `Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
11193
11520
  );
11194
11521
  }
@@ -11269,7 +11596,7 @@ __name(isValidExtendedKey, "isValidExtendedKey");
11269
11596
  function parsePath(path2, depth = 0) {
11270
11597
  const components = path2.split("/");
11271
11598
  if (components.length === 0 || components[0] === "m" && depth !== 0) {
11272
- throw new import_errors27.FuelError(import_errors27.ErrorCode.HD_WALLET_ERROR, `invalid path - ${path2}`);
11599
+ throw new import_errors28.FuelError(import_errors28.ErrorCode.HD_WALLET_ERROR, `invalid path - ${path2}`);
11273
11600
  }
11274
11601
  if (components[0] === "m") {
11275
11602
  components.shift();
@@ -11302,8 +11629,8 @@ var HDWallet = class _HDWallet {
11302
11629
  this.privateKey = (0, import_utils45.hexlify)(config.privateKey);
11303
11630
  } else {
11304
11631
  if (!config.publicKey) {
11305
- throw new import_errors27.FuelError(
11306
- import_errors27.ErrorCode.HD_WALLET_ERROR,
11632
+ throw new import_errors28.FuelError(
11633
+ import_errors28.ErrorCode.HD_WALLET_ERROR,
11307
11634
  "Both public and private Key cannot be missing. At least one should be provided."
11308
11635
  );
11309
11636
  }
@@ -11332,8 +11659,8 @@ var HDWallet = class _HDWallet {
11332
11659
  const data = new Uint8Array(37);
11333
11660
  if (index & HARDENED_INDEX) {
11334
11661
  if (!privateKey) {
11335
- throw new import_errors27.FuelError(
11336
- import_errors27.ErrorCode.HD_WALLET_ERROR,
11662
+ throw new import_errors28.FuelError(
11663
+ import_errors28.ErrorCode.HD_WALLET_ERROR,
11337
11664
  "Cannot derive a hardened index without a private Key."
11338
11665
  );
11339
11666
  }
@@ -11341,13 +11668,13 @@ var HDWallet = class _HDWallet {
11341
11668
  } else {
11342
11669
  data.set((0, import_utils45.arrayify)(this.publicKey));
11343
11670
  }
11344
- data.set((0, import_math24.toBytes)(index, 4), 33);
11671
+ data.set((0, import_math25.toBytes)(index, 4), 33);
11345
11672
  const bytes = (0, import_utils45.arrayify)((0, import_crypto8.computeHmac)("sha512", chainCode, data));
11346
11673
  const IL = bytes.slice(0, 32);
11347
11674
  const IR = bytes.slice(32);
11348
11675
  if (privateKey) {
11349
11676
  const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
11350
- const ki = (0, import_math24.bn)(IL).add(privateKey).mod(N).toBytes(32);
11677
+ const ki = (0, import_math25.bn)(IL).add(privateKey).mod(N).toBytes(32);
11351
11678
  return new _HDWallet({
11352
11679
  privateKey: ki,
11353
11680
  chainCode: IR,
@@ -11385,15 +11712,15 @@ var HDWallet = class _HDWallet {
11385
11712
  */
11386
11713
  toExtendedKey(isPublic = false, testnet = false) {
11387
11714
  if (this.depth >= 256) {
11388
- throw new import_errors27.FuelError(
11389
- import_errors27.ErrorCode.HD_WALLET_ERROR,
11715
+ throw new import_errors28.FuelError(
11716
+ import_errors28.ErrorCode.HD_WALLET_ERROR,
11390
11717
  `Exceeded max depth of 255. Current depth: ${this.depth}.`
11391
11718
  );
11392
11719
  }
11393
11720
  const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
11394
11721
  const depth = (0, import_utils45.hexlify)(Uint8Array.from([this.depth]));
11395
11722
  const parentFingerprint = this.parentFingerprint;
11396
- const index = (0, import_math24.toHex)(this.index, 4);
11723
+ const index = (0, import_math25.toHex)(this.index, 4);
11397
11724
  const chainCode = this.chainCode;
11398
11725
  const key = this.privateKey != null && !isPublic ? (0, import_utils45.concat)(["0x00", this.privateKey]) : this.publicKey;
11399
11726
  const extendedKey = (0, import_utils45.arrayify)((0, import_utils45.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
@@ -11413,14 +11740,14 @@ var HDWallet = class _HDWallet {
11413
11740
  });
11414
11741
  }
11415
11742
  static fromExtendedKey(extendedKey) {
11416
- const decoded = (0, import_utils45.hexlify)((0, import_math24.toBytes)((0, import_utils45.decodeBase58)(extendedKey)));
11743
+ const decoded = (0, import_utils45.hexlify)((0, import_math25.toBytes)((0, import_utils45.decodeBase58)(extendedKey)));
11417
11744
  const bytes = (0, import_utils45.arrayify)(decoded);
11418
11745
  const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
11419
11746
  if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
11420
- throw new import_errors27.FuelError(import_errors27.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
11747
+ throw new import_errors28.FuelError(import_errors28.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
11421
11748
  }
11422
11749
  if (!validChecksum) {
11423
- throw new import_errors27.FuelError(import_errors27.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
11750
+ throw new import_errors28.FuelError(import_errors28.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
11424
11751
  }
11425
11752
  const depth = bytes[4];
11426
11753
  const parentFingerprint = (0, import_utils45.hexlify)(bytes.slice(5, 9));
@@ -11428,14 +11755,14 @@ var HDWallet = class _HDWallet {
11428
11755
  const chainCode = (0, import_utils45.hexlify)(bytes.slice(13, 45));
11429
11756
  const key = bytes.slice(45, 78);
11430
11757
  if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
11431
- throw new import_errors27.FuelError(
11432
- import_errors27.ErrorCode.HD_WALLET_ERROR,
11758
+ throw new import_errors28.FuelError(
11759
+ import_errors28.ErrorCode.HD_WALLET_ERROR,
11433
11760
  "Inconsistency detected: Depth is zero but fingerprint/index is non-zero."
11434
11761
  );
11435
11762
  }
11436
11763
  if (isPublicExtendedKey(bytes)) {
11437
11764
  if (key[0] !== 3) {
11438
- throw new import_errors27.FuelError(import_errors27.ErrorCode.HD_WALLET_ERROR, "Invalid public extended key.");
11765
+ throw new import_errors28.FuelError(import_errors28.ErrorCode.HD_WALLET_ERROR, "Invalid public extended key.");
11439
11766
  }
11440
11767
  return new _HDWallet({
11441
11768
  publicKey: key,
@@ -11446,7 +11773,7 @@ var HDWallet = class _HDWallet {
11446
11773
  });
11447
11774
  }
11448
11775
  if (key[0] !== 0) {
11449
- throw new import_errors27.FuelError(import_errors27.ErrorCode.HD_WALLET_ERROR, "Invalid private extended key.");
11776
+ throw new import_errors28.FuelError(import_errors28.ErrorCode.HD_WALLET_ERROR, "Invalid private extended key.");
11450
11777
  }
11451
11778
  return new _HDWallet({
11452
11779
  privateKey: key.slice(1),
@@ -11682,7 +12009,7 @@ var WalletsConfig = class _WalletsConfig {
11682
12009
  assetIds.forEach((assetId) => {
11683
12010
  for (let index = 0; index < coinsPerAsset; index++) {
11684
12011
  coins.push({
11685
- amount: (0, import_math25.bn)(amountPerCoin).toString(),
12012
+ amount: (0, import_math26.bn)(amountPerCoin).toString(),
11686
12013
  asset_id: assetId,
11687
12014
  owner: walletAddress,
11688
12015
  tx_pointer_block_height: 0,
@@ -11702,26 +12029,26 @@ var WalletsConfig = class _WalletsConfig {
11702
12029
  amountPerCoin
11703
12030
  }) {
11704
12031
  if (Array.isArray(wallets) && wallets.length === 0 || typeof wallets === "number" && wallets <= 0) {
11705
- throw new import_errors28.FuelError(
11706
- import_errors28.FuelError.CODES.INVALID_INPUT_PARAMETERS,
12032
+ throw new import_errors29.FuelError(
12033
+ import_errors29.FuelError.CODES.INVALID_INPUT_PARAMETERS,
11707
12034
  "Number of wallets must be greater than zero."
11708
12035
  );
11709
12036
  }
11710
12037
  if (Array.isArray(assets) && assets.length === 0 || typeof assets === "number" && assets <= 0) {
11711
- throw new import_errors28.FuelError(
11712
- import_errors28.FuelError.CODES.INVALID_INPUT_PARAMETERS,
12038
+ throw new import_errors29.FuelError(
12039
+ import_errors29.FuelError.CODES.INVALID_INPUT_PARAMETERS,
11713
12040
  "Number of assets per wallet must be greater than zero."
11714
12041
  );
11715
12042
  }
11716
12043
  if (coinsPerAsset <= 0) {
11717
- throw new import_errors28.FuelError(
11718
- import_errors28.FuelError.CODES.INVALID_INPUT_PARAMETERS,
12044
+ throw new import_errors29.FuelError(
12045
+ import_errors29.FuelError.CODES.INVALID_INPUT_PARAMETERS,
11719
12046
  "Number of coins per asset must be greater than zero."
11720
12047
  );
11721
12048
  }
11722
- if ((0, import_math25.bn)(amountPerCoin).lt(0)) {
11723
- throw new import_errors28.FuelError(
11724
- import_errors28.FuelError.CODES.INVALID_INPUT_PARAMETERS,
12049
+ if ((0, import_math26.bn)(amountPerCoin).lt(0)) {
12050
+ throw new import_errors29.FuelError(
12051
+ import_errors29.FuelError.CODES.INVALID_INPUT_PARAMETERS,
11725
12052
  "Amount per coin must be greater than or equal to zero."
11726
12053
  );
11727
12054
  }
@@ -11753,7 +12080,7 @@ async function setupTestProviderAndWallets({
11753
12080
  const launchNodeOptions = {
11754
12081
  loggingEnabled: false,
11755
12082
  ...nodeOptions,
11756
- snapshotConfig: (0, import_ramda10.mergeDeepRight)(
12083
+ snapshotConfig: (0, import_ramda11.mergeDeepRight)(
11757
12084
  import_utils47.defaultSnapshotConfigs,
11758
12085
  walletsConfig.apply(nodeOptions?.snapshotConfig)
11759
12086
  ),
@@ -11797,9 +12124,9 @@ async function setupTestProviderAndWallets({
11797
12124
  __name(setupTestProviderAndWallets, "setupTestProviderAndWallets");
11798
12125
 
11799
12126
  // src/test-utils/test-message.ts
11800
- var import_address8 = require("@fuel-ts/address");
12127
+ var import_address9 = require("@fuel-ts/address");
11801
12128
  var import_crypto10 = require("@fuel-ts/crypto");
11802
- var import_math26 = require("@fuel-ts/math");
12129
+ var import_math27 = require("@fuel-ts/math");
11803
12130
  var import_utils48 = require("@fuel-ts/utils");
11804
12131
  var TestMessage = class {
11805
12132
  static {
@@ -11818,8 +12145,8 @@ var TestMessage = class {
11818
12145
  * It can also be used standalone and passed into the initial state of a chain via the `.toChainMessage` method.
11819
12146
  */
11820
12147
  constructor({
11821
- sender = import_address8.Address.fromRandom(),
11822
- recipient = import_address8.Address.fromRandom(),
12148
+ sender = import_address9.Address.fromRandom(),
12149
+ recipient = import_address9.Address.fromRandom(),
11823
12150
  nonce = (0, import_utils48.hexlify)((0, import_crypto10.randomBytes)(32)),
11824
12151
  amount = 1e6,
11825
12152
  data = "",
@@ -11839,7 +12166,7 @@ var TestMessage = class {
11839
12166
  sender: this.sender.toB256(),
11840
12167
  recipient: recipient?.toB256() ?? this.recipient.toB256(),
11841
12168
  nonce: this.nonce,
11842
- amount: (0, import_math26.bn)(this.amount).toNumber(),
12169
+ amount: (0, import_math27.bn)(this.amount).toNumber(),
11843
12170
  data,
11844
12171
  da_height: this.da_height
11845
12172
  };