@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
@@ -17991,7 +17991,7 @@
17991
17991
  return {
17992
17992
  FUEL_CORE: "0.43.1",
17993
17993
  FORC: "0.68.7",
17994
- FUELS: "0.101.2"
17994
+ FUELS: "0.101.3"
17995
17995
  };
17996
17996
  }
17997
17997
  __name(getBuiltinVersions, "getBuiltinVersions");
@@ -18104,6 +18104,7 @@ This unreleased fuel-core build may include features and updates not yet support
18104
18104
  ErrorCode2["CONNECTION_REFUSED"] = "connection-refused";
18105
18105
  ErrorCode2["INVALID_URL"] = "invalid-url";
18106
18106
  ErrorCode2["UNSUPPORTED_FEATURE"] = "unsupported-feature";
18107
+ ErrorCode2["RESPONSE_BODY_EMPTY"] = "response-body-empty";
18107
18108
  ErrorCode2["INVALID_PUBLIC_KEY"] = "invalid-public-key";
18108
18109
  ErrorCode2["WALLET_MANAGER_ERROR"] = "wallet-manager-error";
18109
18110
  ErrorCode2["HD_WALLET_ERROR"] = "hd-wallet-error";
@@ -18122,6 +18123,8 @@ This unreleased fuel-core build may include features and updates not yet support
18122
18123
  ErrorCode2["INVALID_REQUEST"] = "invalid-request";
18123
18124
  ErrorCode2["INVALID_TRANSFER_AMOUNT"] = "invalid-transfer-amount";
18124
18125
  ErrorCode2["INSUFFICIENT_FUNDS_OR_MAX_COINS"] = "not-enough-funds-or-max-coins-reached";
18126
+ ErrorCode2["INSUFFICIENT_FUNDS"] = "not-enough-funds";
18127
+ ErrorCode2["MAX_COINS_REACHED"] = "max-coins-reached";
18125
18128
  ErrorCode2["INVALID_CREDENTIALS"] = "invalid-credentials";
18126
18129
  ErrorCode2["HASHER_LOCKED"] = "hasher-locked";
18127
18130
  ErrorCode2["GAS_PRICE_TOO_LOW"] = "gas-price-too-low";
@@ -18155,6 +18158,7 @@ This unreleased fuel-core build may include features and updates not yet support
18155
18158
  ErrorCode2["INVALID_PASSWORD"] = "invalid-password";
18156
18159
  ErrorCode2["ACCOUNT_REQUIRED"] = "account-required";
18157
18160
  ErrorCode2["UNLOCKED_WALLET_REQUIRED"] = "unlocked-wallet-required";
18161
+ ErrorCode2["UNABLE_TO_CONSOLIDATE_COINS"] = "unable-to-consolidate-coins";
18158
18162
  ErrorCode2["NO_COINS_TO_CONSOLIDATE"] = "no-coins-to-consolidate";
18159
18163
  ErrorCode2["COINS_ASSET_ID_MISMATCH"] = "coins-asset-id-mismatch";
18160
18164
  ErrorCode2["ASSET_NOT_FOUND"] = "asset-not-found";
@@ -18196,7 +18200,7 @@ This unreleased fuel-core build may include features and updates not yet support
18196
18200
  `Unknown error code: ${error2.code}. Accepted codes: ${enumValues.join(", ")}.`
18197
18201
  );
18198
18202
  }
18199
- return new _FuelError(error2.code, error2.message);
18203
+ return new _FuelError(error2.code, error2.message, error2.metadata, error2.rawError);
18200
18204
  }
18201
18205
  code;
18202
18206
  constructor(code, message, metadata = {}, rawError = null) {
@@ -23127,6 +23131,69 @@ If you are attempting to transform a hex value, please make sure it is being pas
23127
23131
  }
23128
23132
  __name(_curry1, "_curry1");
23129
23133
 
23134
+ // ../../node_modules/.pnpm/ramda@0.30.1/node_modules/ramda/es/internal/_curry2.js
23135
+ function _curry2(fn) {
23136
+ return /* @__PURE__ */ __name(function f2(a, b) {
23137
+ switch (arguments.length) {
23138
+ case 0:
23139
+ return f2;
23140
+ case 1:
23141
+ return _isPlaceholder(a) ? f2 : _curry1(function(_b) {
23142
+ return fn(a, _b);
23143
+ });
23144
+ default:
23145
+ return _isPlaceholder(a) && _isPlaceholder(b) ? f2 : _isPlaceholder(a) ? _curry1(function(_a) {
23146
+ return fn(_a, b);
23147
+ }) : _isPlaceholder(b) ? _curry1(function(_b) {
23148
+ return fn(a, _b);
23149
+ }) : fn(a, b);
23150
+ }
23151
+ }, "f2");
23152
+ }
23153
+ __name(_curry2, "_curry2");
23154
+
23155
+ // ../../node_modules/.pnpm/ramda@0.30.1/node_modules/ramda/es/internal/_curry3.js
23156
+ function _curry3(fn) {
23157
+ return /* @__PURE__ */ __name(function f3(a, b, c) {
23158
+ switch (arguments.length) {
23159
+ case 0:
23160
+ return f3;
23161
+ case 1:
23162
+ return _isPlaceholder(a) ? f3 : _curry2(function(_b, _c) {
23163
+ return fn(a, _b, _c);
23164
+ });
23165
+ case 2:
23166
+ return _isPlaceholder(a) && _isPlaceholder(b) ? f3 : _isPlaceholder(a) ? _curry2(function(_a, _c) {
23167
+ return fn(_a, b, _c);
23168
+ }) : _isPlaceholder(b) ? _curry2(function(_b, _c) {
23169
+ return fn(a, _b, _c);
23170
+ }) : _curry1(function(_c) {
23171
+ return fn(a, b, _c);
23172
+ });
23173
+ default:
23174
+ return _isPlaceholder(a) && _isPlaceholder(b) && _isPlaceholder(c) ? f3 : _isPlaceholder(a) && _isPlaceholder(b) ? _curry2(function(_a, _b) {
23175
+ return fn(_a, _b, c);
23176
+ }) : _isPlaceholder(a) && _isPlaceholder(c) ? _curry2(function(_a, _c) {
23177
+ return fn(_a, b, _c);
23178
+ }) : _isPlaceholder(b) && _isPlaceholder(c) ? _curry2(function(_b, _c) {
23179
+ return fn(a, _b, _c);
23180
+ }) : _isPlaceholder(a) ? _curry1(function(_a) {
23181
+ return fn(_a, b, c);
23182
+ }) : _isPlaceholder(b) ? _curry1(function(_b) {
23183
+ return fn(a, _b, c);
23184
+ }) : _isPlaceholder(c) ? _curry1(function(_c) {
23185
+ return fn(a, b, _c);
23186
+ }) : fn(a, b, c);
23187
+ }
23188
+ }, "f3");
23189
+ }
23190
+ __name(_curry3, "_curry3");
23191
+
23192
+ // ../../node_modules/.pnpm/ramda@0.30.1/node_modules/ramda/es/internal/_isArray.js
23193
+ var isArray_default = Array.isArray || /* @__PURE__ */ __name(function _isArray(val) {
23194
+ return val != null && val.length >= 0 && Object.prototype.toString.call(val) === "[object Array]";
23195
+ }, "_isArray");
23196
+
23130
23197
  // ../../node_modules/.pnpm/ramda@0.30.1/node_modules/ramda/es/type.js
23131
23198
  var type = /* @__PURE__ */ _curry1(/* @__PURE__ */ __name(function type2(val) {
23132
23199
  return val === null ? "Null" : val === void 0 ? "Undefined" : Object.prototype.toString.call(val).slice(8, -1);
@@ -23245,6 +23312,39 @@ If you are attempting to transform a hex value, please make sure it is being pas
23245
23312
  }, "clone"));
23246
23313
  var clone_default = clone;
23247
23314
 
23315
+ // ../../node_modules/.pnpm/ramda@0.30.1/node_modules/ramda/es/internal/_checkForMethod.js
23316
+ function _checkForMethod(methodname, fn) {
23317
+ return function() {
23318
+ var length = arguments.length;
23319
+ if (length === 0) {
23320
+ return fn();
23321
+ }
23322
+ var obj = arguments[length - 1];
23323
+ return isArray_default(obj) || typeof obj[methodname] !== "function" ? fn.apply(this, arguments) : obj[methodname].apply(obj, Array.prototype.slice.call(arguments, 0, length - 1));
23324
+ };
23325
+ }
23326
+ __name(_checkForMethod, "_checkForMethod");
23327
+
23328
+ // ../../node_modules/.pnpm/ramda@0.30.1/node_modules/ramda/es/slice.js
23329
+ var slice = /* @__PURE__ */ _curry3(/* @__PURE__ */ _checkForMethod("slice", /* @__PURE__ */ __name(function slice2(fromIndex, toIndex, list) {
23330
+ return Array.prototype.slice.call(list, fromIndex, toIndex);
23331
+ }, "slice")));
23332
+ var slice_default = slice;
23333
+
23334
+ // ../../node_modules/.pnpm/ramda@0.30.1/node_modules/ramda/es/splitEvery.js
23335
+ var splitEvery = /* @__PURE__ */ _curry2(/* @__PURE__ */ __name(function splitEvery2(n, list) {
23336
+ if (n <= 0) {
23337
+ throw new Error("First argument to splitEvery must be a positive integer");
23338
+ }
23339
+ var result = [];
23340
+ var idx = 0;
23341
+ while (idx < list.length) {
23342
+ result.push(slice_default(idx, idx += n, list));
23343
+ }
23344
+ return result;
23345
+ }, "splitEvery"));
23346
+ var splitEvery_default = splitEvery;
23347
+
23248
23348
  // src/providers/coin-quantity.ts
23249
23349
  var coinQuantityfy = /* @__PURE__ */ __name((coinQuantityLike) => {
23250
23350
  let assetId;
@@ -28503,8 +28603,11 @@ ${DryRunSuccessAssembleTxFragmentDoc}`;
28503
28603
  }, "setAndValidateGasAndFeeForAssembledTx");
28504
28604
 
28505
28605
  // src/providers/utils/handle-gql-error-message.ts
28606
+ var ASSET_ID_REGEX = /[0-9a-fA-F]{32,64}/g;
28506
28607
  var gqlErrorMessage = {
28507
28608
  RPC_CONSISTENCY: /The required fuel block height is higher than the current block height. Required: \d+, Current: \d+/,
28609
+ INSUFFICIENT_FUNDS: /the target cannot be met due to insufficient coins available for [0-9a-fA-F]{32,64}. Collected: \d+/,
28610
+ MAX_COINS_REACHED: /the target for [0-9a-fA-F]{32,64} cannot be met due to exceeding the \d+ coin limit. Collected: \d+./,
28508
28611
  NOT_ENOUGH_COINS_MAX_COINS: /the target cannot be met due to no coins available or exceeding the \d+ coin limit./,
28509
28612
  ASSET_NOT_FOUND: /resource was not found in table/,
28510
28613
  MULTIPLE_CHANGE_POLICIES: /The asset ([a-fA-F0-9]{64}) has multiple change policies/,
@@ -28520,6 +28623,46 @@ ${DryRunSuccessAssembleTxFragmentDoc}`;
28520
28623
  error2
28521
28624
  );
28522
28625
  }
28626
+ if (gqlErrorMessage.MAX_COINS_REACHED.test(error2.message)) {
28627
+ const matches = error2.message.match(ASSET_ID_REGEX);
28628
+ const assetId = matches ? `0x${matches[0]}` : null;
28629
+ const owner = matches ? `0x${matches[1]}` : null;
28630
+ let suffix = "";
28631
+ if (assetId) {
28632
+ suffix += `
28633
+ Asset ID: '${assetId}'.`;
28634
+ }
28635
+ if (owner) {
28636
+ suffix += `
28637
+ Owner: '${owner}'.`;
28638
+ }
28639
+ return new FuelError(
28640
+ ErrorCode.MAX_COINS_REACHED,
28641
+ `You have too many small value coins - consider combining UTXOs.${suffix}`,
28642
+ { assetId, owner },
28643
+ error2
28644
+ );
28645
+ }
28646
+ if (gqlErrorMessage.INSUFFICIENT_FUNDS.test(error2.message)) {
28647
+ const matches = error2.message.match(ASSET_ID_REGEX);
28648
+ const assetId = matches ? `0x${matches[0]}` : null;
28649
+ const owner = matches ? `0x${matches[1]}` : null;
28650
+ let suffix = "";
28651
+ if (assetId) {
28652
+ suffix += `
28653
+ Asset ID: '${assetId}'.`;
28654
+ }
28655
+ if (owner) {
28656
+ suffix += `
28657
+ Owner: '${owner}'.`;
28658
+ }
28659
+ return new FuelError(
28660
+ ErrorCode.INSUFFICIENT_FUNDS,
28661
+ `Insufficient funds.${suffix}`,
28662
+ { assetId, owner },
28663
+ error2
28664
+ );
28665
+ }
28523
28666
  if (gqlErrorMessage.MULTIPLE_CHANGE_POLICIES.test(error2.message)) {
28524
28667
  const match = error2.message.match(/asset ([a-fA-F0-9]{64})/);
28525
28668
  const assetId = match?.[1] || "";
@@ -29713,6 +29856,7 @@ This error originated at ${JSON.stringify(pos, null, 2)}` : "";
29713
29856
  }
29714
29857
  return new FuelError(ErrorCode.SCRIPT_REVERTED, errorMessage, {
29715
29858
  ...metadata,
29859
+ abiError,
29716
29860
  reason
29717
29861
  });
29718
29862
  }
@@ -30735,11 +30879,15 @@ This error originated at ${JSON.stringify(pos, null, 2)}` : "";
30735
30879
  * @deprecated Use `provider.assembleTx` instead.
30736
30880
  * Check the migration guide https://docs.fuel.network/guide/assembling-transactions/migration-guide.html for more information.
30737
30881
  */
30738
- async estimateAndFund(account, { signatureCallback, quantities = [] } = {}) {
30882
+ async estimateAndFund(account, {
30883
+ signatureCallback,
30884
+ quantities = [],
30885
+ skipAutoConsolidation
30886
+ } = {}) {
30739
30887
  const txCost = await account.getTransactionCost(this, { signatureCallback, quantities });
30740
30888
  this.maxFee = txCost.maxFee;
30741
30889
  this.gasLimit = txCost.gasUsed;
30742
- await account.fund(this, txCost);
30890
+ await account.fund(this, txCost, { skipAutoConsolidation });
30743
30891
  return this;
30744
30892
  }
30745
30893
  /**
@@ -32321,25 +32469,6 @@ This error originated at ${JSON.stringify(pos, null, 2)}` : "";
32321
32469
 
32322
32470
  // src/providers/transaction-response/transaction-response.ts
32323
32471
  var TransactionResponse = class _TransactionResponse {
32324
- /**
32325
- * Constructor for `TransactionResponse`.
32326
- *
32327
- * @param tx - The transaction ID or TransactionRequest.
32328
- * @param provider - The provider.
32329
- */
32330
- constructor(tx, provider, chainId, abis, submitTxSubscription) {
32331
- this.submitTxSubscription = submitTxSubscription;
32332
- if (typeof tx === "string") {
32333
- this.id = tx;
32334
- } else {
32335
- this.id = tx.getTransactionId(chainId);
32336
- this.request = tx;
32337
- }
32338
- this.provider = provider;
32339
- this.abis = abis;
32340
- this.waitForResult = this.waitForResult.bind(this);
32341
- this.waitForPreConfirmation = this.waitForPreConfirmation.bind(this);
32342
- }
32343
32472
  static {
32344
32473
  __name(this, "TransactionResponse");
32345
32474
  }
@@ -32354,9 +32483,42 @@ This error originated at ${JSON.stringify(pos, null, 2)}` : "";
32354
32483
  request;
32355
32484
  status;
32356
32485
  abis;
32486
+ submitTxSubscription;
32357
32487
  preConfirmationStatus;
32358
32488
  waitingForStreamData = false;
32359
32489
  statusResolvers = /* @__PURE__ */ new Map();
32490
+ /**
32491
+ * Constructor for `TransactionResponse`.
32492
+ */
32493
+ constructor(constructorParams, provider, chainId, abis, submitTxSubscription) {
32494
+ let tx;
32495
+ let _provider;
32496
+ let _chainId;
32497
+ let _abis;
32498
+ if (typeof constructorParams === "object" && "provider" in constructorParams && arguments.length === 1) {
32499
+ tx = constructorParams.transactionRequestOrId;
32500
+ _provider = constructorParams.provider;
32501
+ _chainId = constructorParams.chainId;
32502
+ _abis = constructorParams.abis;
32503
+ this.submitTxSubscription = constructorParams.submitAndAwaitSubscription;
32504
+ } else {
32505
+ tx = constructorParams;
32506
+ _provider = provider;
32507
+ _chainId = chainId;
32508
+ _abis = abis;
32509
+ this.submitTxSubscription = submitTxSubscription;
32510
+ }
32511
+ if (typeof tx === "string") {
32512
+ this.id = tx;
32513
+ } else {
32514
+ this.id = tx.getTransactionId(_chainId);
32515
+ this.request = tx;
32516
+ }
32517
+ this.provider = _provider;
32518
+ this.abis = _abis;
32519
+ this.waitForResult = this.waitForResult.bind(this);
32520
+ this.waitForPreConfirmation = this.waitForPreConfirmation.bind(this);
32521
+ }
32360
32522
  /**
32361
32523
  * Async constructor for `TransactionResponse`. This method can be used to create
32362
32524
  * an instance of `TransactionResponse` and wait for the transaction to be fetched
@@ -32891,7 +33053,15 @@ This error originated at ${JSON.stringify(pos, null, 2)}` : "";
32891
33053
  if (_Provider.ENABLE_RPC_CONSISTENCY && _Provider.hasWriteOperationHappened(url)) {
32892
33054
  _Provider.applyBlockHeight(fullRequest, url);
32893
33055
  }
32894
- return _Provider.fetchAndProcessBlockHeight(url, fullRequest, options);
33056
+ const response = await _Provider.fetchAndProcessBlockHeight(url, fullRequest, options);
33057
+ if (response.body === null) {
33058
+ throw new FuelError(
33059
+ ErrorCode.RESPONSE_BODY_EMPTY,
33060
+ "The response from the server is missing the body",
33061
+ { timestamp: (/* @__PURE__ */ new Date()).toISOString(), request: request2, response }
33062
+ );
33063
+ }
33064
+ return response;
32895
33065
  }, retryOptions);
32896
33066
  }
32897
33067
  static applyBlockHeight(request2, url) {
@@ -32914,13 +33084,15 @@ This error originated at ${JSON.stringify(pos, null, 2)}` : "";
32914
33084
  baseDelay: 500
32915
33085
  };
32916
33086
  for (let retriesLeft = retryOptions.maxRetries; retriesLeft > 0; --retriesLeft) {
32917
- const { extensions } = await parseGraphqlResponse({
32918
- response,
32919
- isSubscription: url.endsWith("-sub")
32920
- });
32921
- _Provider.setCurrentBlockHeight(url, extensions?.current_fuel_block_height);
32922
- if (!extensions?.fuel_block_height_precondition_failed) {
32923
- break;
33087
+ if (response.body) {
33088
+ const { extensions } = await parseGraphqlResponse({
33089
+ response,
33090
+ isSubscription: url.endsWith("-sub")
33091
+ });
33092
+ _Provider.setCurrentBlockHeight(url, extensions?.current_fuel_block_height);
33093
+ if (!extensions?.fuel_block_height_precondition_failed) {
33094
+ break;
33095
+ }
32924
33096
  }
32925
33097
  const retryAttempt = retryOptions.maxRetries - retriesLeft + 1;
32926
33098
  const sleepTime = getWaitDelay(retryOptions, retryAttempt);
@@ -33343,7 +33515,13 @@ This error originated at ${JSON.stringify(pos, null, 2)}` : "";
33343
33515
  transactionRequest.getTransactionId(await this.getChainId())
33344
33516
  );
33345
33517
  const chainId = await this.getChainId();
33346
- return new TransactionResponse(transactionRequest, this, chainId, abis, subscription);
33518
+ return new TransactionResponse({
33519
+ transactionRequestOrId: transactionRequest,
33520
+ provider: this,
33521
+ chainId,
33522
+ abis,
33523
+ submitAndAwaitSubscription: subscription
33524
+ });
33347
33525
  }
33348
33526
  /**
33349
33527
  * Executes a transaction without actually submitting it to the chain.
@@ -34438,7 +34616,11 @@ This error originated at ${JSON.stringify(pos, null, 2)}` : "";
34438
34616
  */
34439
34617
  async getTransactionResponse(transactionId) {
34440
34618
  const chainId = await this.getChainId();
34441
- return new TransactionResponse(transactionId, this, chainId);
34619
+ return new TransactionResponse({
34620
+ transactionRequestOrId: transactionId,
34621
+ provider: this,
34622
+ chainId
34623
+ });
34442
34624
  }
34443
34625
  /**
34444
34626
  * Returns Message for given nonce.
@@ -34762,7 +34944,12 @@ This error originated at ${JSON.stringify(pos, null, 2)}` : "";
34762
34944
  } = json;
34763
34945
  const provider = new Provider(providerUrl, { cache: providerCache });
34764
34946
  const { chainId } = providerCache.chain.consensusParameters;
34765
- const response = new TransactionResponse(id, provider, Number(chainId), abis);
34947
+ const response = new TransactionResponse({
34948
+ transactionRequestOrId: id,
34949
+ provider,
34950
+ chainId: Number(chainId),
34951
+ abis
34952
+ });
34766
34953
  if (requestJson) {
34767
34954
  response.request = transactionRequestify(JSON.parse(requestJson));
34768
34955
  }
@@ -34779,6 +34966,149 @@ This error originated at ${JSON.stringify(pos, null, 2)}` : "";
34779
34966
  }
34780
34967
  };
34781
34968
 
34969
+ // src/utils/consolidate-coins.ts
34970
+ var CONSOLIDATABLE_ERROR_CODES = [ErrorCode.MAX_COINS_REACHED];
34971
+ var consolidateCoinsIfRequired = /* @__PURE__ */ __name(async (opts) => {
34972
+ const { error: errorUnknown, account, skipAutoConsolidation = false } = opts;
34973
+ if (skipAutoConsolidation) {
34974
+ return false;
34975
+ }
34976
+ const error2 = FuelError.parse(errorUnknown);
34977
+ if (CONSOLIDATABLE_ERROR_CODES.includes(error2.code)) {
34978
+ const { assetId, owner } = error2.metadata;
34979
+ return account.startConsolidation({
34980
+ owner,
34981
+ assetId
34982
+ });
34983
+ }
34984
+ return false;
34985
+ }, "consolidateCoinsIfRequired");
34986
+ var getAllCoins = /* @__PURE__ */ __name(async (account, assetId) => {
34987
+ const all = [];
34988
+ let hasNextPage = true;
34989
+ let after;
34990
+ while (hasNextPage) {
34991
+ const { coins, pageInfo } = await account.getCoins(assetId, { after });
34992
+ all.push(...coins);
34993
+ after = coins.pop()?.id;
34994
+ hasNextPage = pageInfo.hasNextPage;
34995
+ }
34996
+ return { coins: all };
34997
+ }, "getAllCoins");
34998
+ var sortCoins = /* @__PURE__ */ __name(({ coins }) => coins.sort((a, b) => b.amount.cmp(a.amount)), "sortCoins");
34999
+ var createOuputCoin = /* @__PURE__ */ __name((opts) => {
35000
+ const { transactionId, outputs, baseAssetId } = opts;
35001
+ const outputChangeIndex = outputs.findIndex(
35002
+ (output) => output.type === OutputType.Change && output.assetId === baseAssetId
35003
+ );
35004
+ if (outputChangeIndex === -1) {
35005
+ throw new FuelError(ErrorCode.UNKNOWN, "No change output found");
35006
+ }
35007
+ const outputCoin = outputs[outputChangeIndex];
35008
+ const outputIndexPadded = Number(outputChangeIndex).toString().padStart(4, "0");
35009
+ return {
35010
+ id: `${transactionId}${outputIndexPadded}`,
35011
+ assetId: outputCoin.assetId,
35012
+ amount: outputCoin.amount,
35013
+ owner: new Address(outputCoin.to),
35014
+ blockCreated: bn(0),
35015
+ txCreatedIdx: bn(0)
35016
+ };
35017
+ }, "createOuputCoin");
35018
+ var consolidateCoins = /* @__PURE__ */ __name(async ({
35019
+ account,
35020
+ assetId
35021
+ }) => {
35022
+ const chainInfo = await account.provider.getChain();
35023
+ const chainId = chainInfo.consensusParameters.chainId.toNumber();
35024
+ const gasPrice = await account.provider.estimateGasPrice(10);
35025
+ const maxInputs = chainInfo.consensusParameters.txParameters.maxInputs.toNumber();
35026
+ const baseAssetId = await account.provider.getBaseAssetId();
35027
+ const isBaseAsset = assetId === baseAssetId;
35028
+ const batchSize = maxInputs;
35029
+ const numberOfFundingCoins = maxInputs;
35030
+ let funding = [];
35031
+ let dust = [];
35032
+ if (isBaseAsset) {
35033
+ const coins = await getAllCoins(account, baseAssetId).then(sortCoins);
35034
+ funding = coins.slice(0, numberOfFundingCoins);
35035
+ dust = coins.slice(numberOfFundingCoins);
35036
+ } else {
35037
+ funding = await getAllCoins(account, baseAssetId).then(sortCoins).then((coins) => coins.slice(0, numberOfFundingCoins));
35038
+ dust = await getAllCoins(account, assetId).then(({ coins }) => coins);
35039
+ }
35040
+ if (funding.length === 0) {
35041
+ throw new FuelError(
35042
+ ErrorCode.INSUFFICIENT_FUNDS,
35043
+ `Insufficient funds to consolidate.
35044
+ Asset ID: ${baseAssetId}
35045
+ Owner: ${account.address.toB256()}`
35046
+ );
35047
+ }
35048
+ const batches = [
35049
+ ...splitEvery_default(batchSize, funding),
35050
+ // We leave one coin for the funding coin
35051
+ ...splitEvery_default(batchSize - 1, dust)
35052
+ ];
35053
+ const txs = batches.map((batch) => {
35054
+ const request2 = new ScriptTransactionRequest({
35055
+ scriptData: "0x"
35056
+ });
35057
+ request2.addResources(batch);
35058
+ return request2;
35059
+ });
35060
+ const submitAll = /* @__PURE__ */ __name(async (opts = {}) => {
35061
+ const txResponses = [];
35062
+ let previousTx;
35063
+ for (let i = 0; i < txs.length; i++) {
35064
+ let currentTx = txs[i];
35065
+ const step = i + 1;
35066
+ if (previousTx) {
35067
+ const coin = createOuputCoin({
35068
+ transactionId: previousTx.transactionId,
35069
+ outputs: previousTx.outputs,
35070
+ baseAssetId
35071
+ });
35072
+ currentTx.addResource(coin);
35073
+ }
35074
+ if ("populateTransactionPredicateData" in account && typeof account.populateTransactionPredicateData === "function") {
35075
+ currentTx = account.populateTransactionPredicateData(currentTx);
35076
+ currentTx = await account.provider.estimatePredicates(currentTx);
35077
+ }
35078
+ const fee = calculateGasFee({
35079
+ gasPrice,
35080
+ gas: currentTx.calculateMinGas(chainInfo),
35081
+ priceFactor: chainInfo.consensusParameters.feeParameters.gasPriceFactor,
35082
+ tip: currentTx.tip
35083
+ });
35084
+ currentTx.maxFee = fee;
35085
+ currentTx.gasLimit = bn(1e3);
35086
+ opts.onTransactionStart?.({
35087
+ tx: currentTx,
35088
+ step,
35089
+ assetId,
35090
+ transactionId: currentTx.getTransactionId(chainId)
35091
+ });
35092
+ const response = await account.sendTransaction(currentTx);
35093
+ const result = await response.waitForResult();
35094
+ txResponses.push(result);
35095
+ previousTx = {
35096
+ transactionId: response.id,
35097
+ outputs: result.transaction.outputs
35098
+ };
35099
+ }
35100
+ return {
35101
+ txResponses,
35102
+ errors: []
35103
+ };
35104
+ }, "submitAll");
35105
+ return {
35106
+ txs,
35107
+ totalFeeCost: txs.reduce((acc, request2) => acc.add(request2.maxFee), bn(0)),
35108
+ submitAll
35109
+ };
35110
+ }, "consolidateCoins");
35111
+
34782
35112
  // src/utils/formatTransferToContractScriptData.ts
34783
35113
  var asm = __toESM(require_node());
34784
35114
  var formatTransferToContractScriptData = /* @__PURE__ */ __name((transferParams) => {
@@ -34895,10 +35225,24 @@ This error originated at ${JSON.stringify(pos, null, 2)}` : "";
34895
35225
  *
34896
35226
  * @param quantities - Quantities of resources to be obtained.
34897
35227
  * @param resourcesIdsToIgnore - IDs of resources to be excluded from the query (optional).
35228
+ * @param skipAutoConsolidation - Whether to skip the automatic consolidatation of coins process (optional).
34898
35229
  * @returns A promise that resolves to an array of Resources.
34899
35230
  */
34900
- async getResourcesToSpend(quantities, resourcesIdsToIgnore) {
34901
- return this.provider.getResourcesToSpend(this.address, quantities, resourcesIdsToIgnore);
35231
+ async getResourcesToSpend(quantities, resourcesIdsToIgnore, { skipAutoConsolidation } = {}) {
35232
+ const getResourcesToSpend = /* @__PURE__ */ __name(() => this.provider.getResourcesToSpend(this.address, quantities, resourcesIdsToIgnore), "getResourcesToSpend");
35233
+ try {
35234
+ return await getResourcesToSpend();
35235
+ } catch (error2) {
35236
+ const shouldRetry = await consolidateCoinsIfRequired({
35237
+ error: error2,
35238
+ account: this,
35239
+ skipAutoConsolidation
35240
+ });
35241
+ if (!shouldRetry) {
35242
+ throw error2;
35243
+ }
35244
+ return await getResourcesToSpend();
35245
+ }
34902
35246
  }
34903
35247
  /**
34904
35248
  * Retrieves coins owned by the account.
@@ -34947,7 +35291,7 @@ This error originated at ${JSON.stringify(pos, null, 2)}` : "";
34947
35291
  * @deprecated Use provider.assembleTx instead
34948
35292
  * Check the migration guide https://docs.fuel.network/docs/fuels-ts/transactions/assemble-tx-migration-guide/ for more information.
34949
35293
  */
34950
- async fund(request2, params) {
35294
+ async fund(request2, params, { skipAutoConsolidation } = {}) {
34951
35295
  const {
34952
35296
  addedSignatures,
34953
35297
  estimatedPredicates,
@@ -34993,7 +35337,8 @@ This error originated at ${JSON.stringify(pos, null, 2)}` : "";
34993
35337
  while (needsToBeFunded && fundingAttempts < MAX_FUNDING_ATTEMPTS) {
34994
35338
  const resources = await this.getResourcesToSpend(
34995
35339
  missingQuantities,
34996
- cacheRequestInputsResourcesFromOwner(request2.inputs, this.address)
35340
+ cacheRequestInputsResourcesFromOwner(request2.inputs, this.address),
35341
+ { skipAutoConsolidation }
34997
35342
  );
34998
35343
  request2.addResources(resources);
34999
35344
  request2.updatePredicateGasUsed(estimatedPredicates);
@@ -35031,7 +35376,7 @@ This error originated at ${JSON.stringify(pos, null, 2)}` : "";
35031
35376
  }
35032
35377
  if (needsToBeFunded) {
35033
35378
  throw new FuelError(
35034
- ErrorCode.INSUFFICIENT_FUNDS_OR_MAX_COINS,
35379
+ ErrorCode.INSUFFICIENT_FUNDS,
35035
35380
  `The account ${this.address} does not have enough base asset funds to cover the transaction execution.`
35036
35381
  );
35037
35382
  }
@@ -35059,16 +35404,20 @@ This error originated at ${JSON.stringify(pos, null, 2)}` : "";
35059
35404
  * @param amount - The amount of coins to transfer.
35060
35405
  * @param assetId - The asset ID of the coins to transfer (optional).
35061
35406
  * @param txParams - The transaction parameters (optional).
35407
+ * @param skipAutoConsolidation - Whether to skip the automatic consolidatation of coins process (optional).
35062
35408
  * @returns A promise that resolves to the prepared transaction request.
35063
35409
  */
35064
- async createTransfer(destination, amount, assetId, txParams = {}) {
35410
+ async createTransfer(destination, amount, assetId, txParams = {}, { skipAutoConsolidation } = {}) {
35065
35411
  let request2 = new ScriptTransactionRequest(txParams);
35066
35412
  request2 = this.addTransfer(request2, {
35067
35413
  destination,
35068
35414
  amount,
35069
35415
  assetId: assetId || await this.provider.getBaseAssetId()
35070
35416
  });
35071
- const { gasPrice, transactionRequest } = await this.assembleTx(request2);
35417
+ const { gasPrice, transactionRequest } = await this.assembleTx({
35418
+ transactionRequest: request2,
35419
+ skipAutoConsolidation
35420
+ });
35072
35421
  request2 = await setAndValidateGasAndFeeForAssembledTx({
35073
35422
  gasPrice,
35074
35423
  provider: this.provider,
@@ -35085,10 +35434,13 @@ This error originated at ${JSON.stringify(pos, null, 2)}` : "";
35085
35434
  * @param amount - The amount of coins to transfer.
35086
35435
  * @param assetId - The asset ID of the coins to transfer (optional).
35087
35436
  * @param txParams - The transaction parameters (optional).
35437
+ * @param skipAutoConsolidation - Whether to skip the automatic consolidatation of coins process (optional).
35088
35438
  * @returns A promise that resolves to the transaction response.
35089
35439
  */
35090
- async transfer(destination, amount, assetId, txParams = {}) {
35091
- const request2 = await this.createTransfer(destination, amount, assetId, txParams);
35440
+ async transfer(destination, amount, assetId, txParams = {}, { skipAutoConsolidation } = {}) {
35441
+ const request2 = await this.createTransfer(destination, amount, assetId, txParams, {
35442
+ skipAutoConsolidation
35443
+ });
35092
35444
  return this.sendTransaction(request2, { estimateTxDependencies: false });
35093
35445
  }
35094
35446
  /**
@@ -35096,12 +35448,16 @@ This error originated at ${JSON.stringify(pos, null, 2)}` : "";
35096
35448
  *
35097
35449
  * @param transferParams - An array of `TransferParams` objects representing the transfers to be made.
35098
35450
  * @param txParams - Optional transaction parameters.
35451
+ * @param skipAutoConsolidation - Whether to skip the automatic consolidatation of coins process (optional).
35099
35452
  * @returns A promise that resolves to a `TransactionResponse` object representing the transaction result.
35100
35453
  */
35101
- async batchTransfer(transferParams, txParams = {}) {
35454
+ async batchTransfer(transferParams, txParams = {}, { skipAutoConsolidation } = {}) {
35102
35455
  let request2 = new ScriptTransactionRequest(txParams);
35103
35456
  request2 = this.addBatchTransfer(request2, transferParams);
35104
- const { gasPrice, transactionRequest } = await this.assembleTx(request2);
35457
+ const { gasPrice, transactionRequest } = await this.assembleTx({
35458
+ transactionRequest: request2,
35459
+ skipAutoConsolidation
35460
+ });
35105
35461
  request2 = await setAndValidateGasAndFeeForAssembledTx({
35106
35462
  gasPrice,
35107
35463
  provider: this.provider,
@@ -35148,12 +35504,15 @@ This error originated at ${JSON.stringify(pos, null, 2)}` : "";
35148
35504
  * @param amount - The amount of coins to transfer.
35149
35505
  * @param assetId - The asset ID of the coins to transfer (optional).
35150
35506
  * @param txParams - The transaction parameters (optional).
35507
+ * @param skipAutoConsolidation - Whether to skip the automatic consolidatation of coins process (optional).
35151
35508
  * @returns A promise that resolves to the transaction response.
35152
35509
  */
35153
- async transferToContract(contractId, amount, assetId, txParams = {}) {
35154
- return this.batchTransferToContracts([{ amount, assetId, contractId }], txParams);
35510
+ async transferToContract(contractId, amount, assetId, txParams = {}, { skipAutoConsolidation } = {}) {
35511
+ return this.batchTransferToContracts([{ amount, assetId, contractId }], txParams, {
35512
+ skipAutoConsolidation
35513
+ });
35155
35514
  }
35156
- async batchTransferToContracts(contractTransferParams, txParams = {}) {
35515
+ async batchTransferToContracts(contractTransferParams, txParams = {}, { skipAutoConsolidation } = {}) {
35157
35516
  let request2 = new ScriptTransactionRequest({
35158
35517
  ...txParams
35159
35518
  });
@@ -35180,7 +35539,11 @@ This error originated at ${JSON.stringify(pos, null, 2)}` : "";
35180
35539
  const { script, scriptData } = await assembleTransferToContractScript(transferParams);
35181
35540
  request2.script = script;
35182
35541
  request2.scriptData = scriptData;
35183
- const { gasPrice, transactionRequest } = await this.assembleTx(request2, quantities);
35542
+ const { gasPrice, transactionRequest } = await this.assembleTx({
35543
+ transactionRequest: request2,
35544
+ quantities,
35545
+ skipAutoConsolidation
35546
+ });
35184
35547
  request2 = await setAndValidateGasAndFeeForAssembledTx({
35185
35548
  gasPrice,
35186
35549
  provider: this.provider,
@@ -35196,9 +35559,10 @@ This error originated at ${JSON.stringify(pos, null, 2)}` : "";
35196
35559
  * @param recipient - Address of the recipient on the base chain.
35197
35560
  * @param amount - Amount of base asset.
35198
35561
  * @param txParams - The transaction parameters (optional).
35562
+ * @param skipAutoConsolidation - Whether to skip the automatic consolidatation of coins process (optional).
35199
35563
  * @returns A promise that resolves to the transaction response.
35200
35564
  */
35201
- async withdrawToBaseLayer(recipient, amount, txParams = {}) {
35565
+ async withdrawToBaseLayer(recipient, amount, txParams = {}, { skipAutoConsolidation } = {}) {
35202
35566
  const recipientAddress = new Address(recipient);
35203
35567
  const recipientDataArray = arrayify(
35204
35568
  "0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
@@ -35215,7 +35579,11 @@ This error originated at ${JSON.stringify(pos, null, 2)}` : "";
35215
35579
  const baseAssetId = await this.provider.getBaseAssetId();
35216
35580
  let request2 = new ScriptTransactionRequest(params);
35217
35581
  const quantities = [{ amount: bn(amount), assetId: baseAssetId }];
35218
- const { gasPrice, transactionRequest } = await this.assembleTx(request2, quantities);
35582
+ const { gasPrice, transactionRequest } = await this.assembleTx({
35583
+ transactionRequest: request2,
35584
+ quantities,
35585
+ skipAutoConsolidation
35586
+ });
35219
35587
  request2 = await setAndValidateGasAndFeeForAssembledTx({
35220
35588
  gasPrice,
35221
35589
  provider: this.provider,
@@ -35225,6 +35593,25 @@ This error originated at ${JSON.stringify(pos, null, 2)}` : "";
35225
35593
  });
35226
35594
  return this.sendTransaction(request2);
35227
35595
  }
35596
+ /**
35597
+ * Start the consolidation process
35598
+ *
35599
+ * @param owner - The B256 address of the owner.
35600
+ * @param assetId - The asset ID that requires consolidation.
35601
+ */
35602
+ async startConsolidation(opts) {
35603
+ if (this._connector) {
35604
+ await this._connector.startConsolidation(opts);
35605
+ return false;
35606
+ }
35607
+ const { owner, assetId } = opts;
35608
+ if (owner !== this.address.toB256()) {
35609
+ return false;
35610
+ }
35611
+ const { submitAll } = await consolidateCoins({ account: this, assetId });
35612
+ await submitAll();
35613
+ return true;
35614
+ }
35228
35615
  /**
35229
35616
  * Consolidates base asset UTXOs into fewer, larger ones.
35230
35617
  *
@@ -35244,6 +35631,7 @@ This error originated at ${JSON.stringify(pos, null, 2)}` : "";
35244
35631
  const isBaseAsset = baseAssetId === assetId;
35245
35632
  let submitAll;
35246
35633
  const consolidationParams = {
35634
+ assetId,
35247
35635
  coins,
35248
35636
  mode: params.mode,
35249
35637
  outputNum: params.outputNum
@@ -35251,10 +35639,7 @@ This error originated at ${JSON.stringify(pos, null, 2)}` : "";
35251
35639
  if (isBaseAsset) {
35252
35640
  ({ submitAll } = await this.assembleBaseAssetConsolidationTxs(consolidationParams));
35253
35641
  } else {
35254
- throw new FuelError(
35255
- ErrorCode.UNSUPPORTED_FEATURE,
35256
- "Consolidation for non-base assets is not supported yet."
35257
- );
35642
+ ({ submitAll } = await this.assembleNonBaseAssetConsolidationTxs(consolidationParams));
35258
35643
  }
35259
35644
  return submitAll();
35260
35645
  }
@@ -35313,6 +35698,70 @@ This error originated at ${JSON.stringify(pos, null, 2)}` : "";
35313
35698
  const submitAll = this.prepareSubmitAll({ txs, mode });
35314
35699
  return { txs, totalFeeCost, submitAll };
35315
35700
  }
35701
+ async assembleNonBaseAssetConsolidationTxs(params) {
35702
+ const { assetId, coins, mode = "parallel", outputNum = 1 } = params;
35703
+ this.validateConsolidationTxsCoins(coins, assetId);
35704
+ const chainInfo = await this.provider.getChain();
35705
+ const maxInputsNumber = chainInfo.consensusParameters.txParameters.maxInputs.toNumber();
35706
+ const baseAssetId = chainInfo.consensusParameters.baseAssetId;
35707
+ const { coins: baseAssetCoins } = await this.provider.getCoins(this.address, baseAssetId);
35708
+ let totalFeeCost = bn(0);
35709
+ const txs = [];
35710
+ const gasPrice = await this.provider.estimateGasPrice(10);
35711
+ const consolidateMoreThanOneCoin = outputNum > 1;
35712
+ const assetCoinBatches = splitCoinsIntoBatches(coins, maxInputsNumber);
35713
+ assetCoinBatches.filter((batch) => batch.length > 1).forEach((coinBatch) => {
35714
+ const request2 = new ScriptTransactionRequest({
35715
+ script: "0x"
35716
+ });
35717
+ request2.addResources(coinBatch);
35718
+ if (consolidateMoreThanOneCoin) {
35719
+ Array.from({ length: outputNum - 1 }).forEach(() => {
35720
+ request2.addCoinOutput(this.address, 0, assetId);
35721
+ });
35722
+ }
35723
+ const minGas = request2.calculateMinGas(chainInfo);
35724
+ const fee = calculateGasFee({
35725
+ gasPrice,
35726
+ gas: minGas,
35727
+ priceFactor: chainInfo.consensusParameters.feeParameters.gasPriceFactor,
35728
+ tip: request2.tip
35729
+ });
35730
+ request2.maxFee = fee;
35731
+ if (consolidateMoreThanOneCoin) {
35732
+ const total = request2.inputs.filter(isRequestInputCoin).reduce((acc, input) => acc.add(input.amount), bn(0));
35733
+ const amountPerNewUtxo = total.div(outputNum + 1);
35734
+ request2.outputs.forEach((output) => {
35735
+ if (output.type === OutputType.Coin) {
35736
+ output.amount = amountPerNewUtxo;
35737
+ }
35738
+ });
35739
+ }
35740
+ totalFeeCost = totalFeeCost.add(fee);
35741
+ const baseAssetResources = [];
35742
+ let fundingFeeTotal = bn(0);
35743
+ while (fundingFeeTotal.lt(fee)) {
35744
+ const baseAssetCoin = baseAssetCoins.pop();
35745
+ if (!baseAssetCoin) {
35746
+ break;
35747
+ }
35748
+ baseAssetResources.push(baseAssetCoin);
35749
+ fundingFeeTotal = fundingFeeTotal.add(baseAssetCoin.amount);
35750
+ }
35751
+ const { inputs } = request2;
35752
+ request2.inputs = inputs.slice(0, maxInputsNumber - baseAssetResources.length);
35753
+ const removedCoins = coinBatch.slice(maxInputsNumber - baseAssetResources.length);
35754
+ request2.addResources(baseAssetResources);
35755
+ const lastCoinBatch = assetCoinBatches[assetCoinBatches.length - 1];
35756
+ lastCoinBatch.push(...removedCoins);
35757
+ if (lastCoinBatch.length > maxInputsNumber) {
35758
+ assetCoinBatches.push(lastCoinBatch.slice(maxInputsNumber));
35759
+ }
35760
+ txs.push(request2);
35761
+ });
35762
+ const submitAll = this.prepareSubmitAll({ txs, mode });
35763
+ return { txs, totalFeeCost, submitAll };
35764
+ }
35316
35765
  /**
35317
35766
  * Prepares a function to submit all transactions either sequentially or in parallel.
35318
35767
  *
@@ -35527,16 +35976,32 @@ This error originated at ${JSON.stringify(pos, null, 2)}` : "";
35527
35976
  } : void 0;
35528
35977
  }
35529
35978
  /** @hidden * */
35530
- async assembleTx(transactionRequest, quantities = []) {
35979
+ async assembleTx(opts) {
35980
+ const { transactionRequest, quantities = [], skipAutoConsolidation } = opts;
35531
35981
  const outputQuantities = transactionRequest.outputs.filter((o) => o.type === OutputType.Coin).map(({ amount, assetId }) => ({ assetId: String(assetId), amount: bn(amount) }));
35532
35982
  transactionRequest.gasLimit = bn(0);
35533
35983
  transactionRequest.maxFee = bn(0);
35534
- const { assembledRequest, gasPrice } = await this.provider.assembleTx({
35535
- request: transactionRequest,
35536
- accountCoinQuantities: mergeQuantities(outputQuantities, quantities),
35537
- feePayerAccount: this
35538
- });
35539
- return { transactionRequest: assembledRequest, gasPrice };
35984
+ const assembleTx = /* @__PURE__ */ __name(async () => {
35985
+ const { assembledRequest, gasPrice } = await this.provider.assembleTx({
35986
+ request: transactionRequest,
35987
+ accountCoinQuantities: mergeQuantities(outputQuantities, quantities),
35988
+ feePayerAccount: this
35989
+ });
35990
+ return { transactionRequest: assembledRequest, gasPrice };
35991
+ }, "assembleTx");
35992
+ try {
35993
+ return await assembleTx();
35994
+ } catch (error2) {
35995
+ const shouldRetry = await consolidateCoinsIfRequired({
35996
+ error: error2,
35997
+ account: this,
35998
+ skipAutoConsolidation
35999
+ });
36000
+ if (!shouldRetry) {
36001
+ throw error2;
36002
+ }
36003
+ return await assembleTx();
36004
+ }
35540
36005
  }
35541
36006
  /** @hidden * */
35542
36007
  validateTransferAmount(amount) {
@@ -35548,45 +36013,6 @@ This error originated at ${JSON.stringify(pos, null, 2)}` : "";
35548
36013
  }
35549
36014
  }
35550
36015
  /** @hidden * */
35551
- async estimateAndFundTransaction(transactionRequest, txParams, costParams) {
35552
- let request2 = transactionRequest;
35553
- const txCost = await this.getTransactionCost(request2, costParams);
35554
- request2 = this.validateGasLimitAndMaxFee({
35555
- transactionRequest: request2,
35556
- gasUsed: txCost.gasUsed,
35557
- maxFee: txCost.maxFee,
35558
- txParams
35559
- });
35560
- request2 = await this.fund(request2, txCost);
35561
- return request2;
35562
- }
35563
- /** @hidden * */
35564
- validateGasLimitAndMaxFee({
35565
- gasUsed,
35566
- maxFee,
35567
- transactionRequest,
35568
- txParams: { gasLimit: setGasLimit, maxFee: setMaxFee }
35569
- }) {
35570
- const request2 = transactionRequestify(transactionRequest);
35571
- if (!isDefined(setGasLimit)) {
35572
- request2.gasLimit = gasUsed;
35573
- } else if (gasUsed.gt(setGasLimit)) {
35574
- throw new FuelError(
35575
- ErrorCode.GAS_LIMIT_TOO_LOW,
35576
- `Gas limit '${setGasLimit}' is lower than the required: '${gasUsed}'.`
35577
- );
35578
- }
35579
- if (!isDefined(setMaxFee)) {
35580
- request2.maxFee = maxFee;
35581
- } else if (maxFee.gt(setMaxFee)) {
35582
- throw new FuelError(
35583
- ErrorCode.MAX_FEE_TOO_LOW,
35584
- `Max fee '${setMaxFee}' is lower than the required: '${maxFee}'.`
35585
- );
35586
- }
35587
- return request2;
35588
- }
35589
- /** @hidden * */
35590
36016
  validateConsolidationTxsCoins(coins, assetId) {
35591
36017
  if (coins.length <= 1) {
35592
36018
  throw new FuelError(ErrorCode.NO_COINS_TO_CONSOLIDATE, "No coins to consolidate.");
@@ -41827,6 +42253,7 @@ This error originated at ${JSON.stringify(pos, null, 2)}` : "";
41827
42253
  FuelConnectorMethods2["addABI"] = "addABI";
41828
42254
  FuelConnectorMethods2["getABI"] = "getABI";
41829
42255
  FuelConnectorMethods2["hasABI"] = "hasABI";
42256
+ FuelConnectorMethods2["startConsolidation"] = "startConsolidation";
41830
42257
  return FuelConnectorMethods2;
41831
42258
  })(FuelConnectorMethods || {});
41832
42259
  var FuelConnectorEventTypes = /* @__PURE__ */ ((FuelConnectorEventTypes2) => {
@@ -41839,6 +42266,7 @@ This error originated at ${JSON.stringify(pos, null, 2)}` : "";
41839
42266
  FuelConnectorEventTypes2["currentNetwork"] = "currentNetwork";
41840
42267
  FuelConnectorEventTypes2["assets"] = "assets";
41841
42268
  FuelConnectorEventTypes2["abis"] = "abis";
42269
+ FuelConnectorEventTypes2["consolidateCoins"] = "consolidateCoins";
41842
42270
  return FuelConnectorEventTypes2;
41843
42271
  })(FuelConnectorEventTypes || {});
41844
42272
  var FuelConnectorEventType = "FuelConnector";
@@ -42088,6 +42516,15 @@ This error originated at ${JSON.stringify(pos, null, 2)}` : "";
42088
42516
  async hasABI(_id) {
42089
42517
  throw new FuelError(FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
42090
42518
  }
42519
+ /**
42520
+ * Start the consolidation of coins process
42521
+ *
42522
+ * @param owner - The B256 address of the owner.
42523
+ * @param assetId - The asset ID that requires consolidation.
42524
+ */
42525
+ async startConsolidation(_opts) {
42526
+ throw new FuelError(FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
42527
+ }
42091
42528
  /**
42092
42529
  * Event listener for the connector.
42093
42530
  *