@fuel-ts/account 0.101.1 → 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 (41) 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 +723 -164
  12. package/dist/index.global.js.map +1 -1
  13. package/dist/index.js +936 -471
  14. package/dist/index.js.map +1 -1
  15. package/dist/index.mjs +856 -394
  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/transaction-summary/call.d.ts +4 -7
  23. package/dist/providers/transaction-summary/call.d.ts.map +1 -1
  24. package/dist/providers/transaction-summary/operations.d.ts +1 -1
  25. package/dist/providers/transaction-summary/operations.d.ts.map +1 -1
  26. package/dist/providers/utils/extract-tx-error.d.ts +10 -1
  27. package/dist/providers/utils/extract-tx-error.d.ts.map +1 -1
  28. package/dist/providers/utils/handle-gql-error-message.d.ts.map +1 -1
  29. package/dist/providers/utils/transaction-response-serialization.d.ts.map +1 -1
  30. package/dist/test-utils/launchNode.d.ts.map +1 -1
  31. package/dist/test-utils.global.js +650 -164
  32. package/dist/test-utils.global.js.map +1 -1
  33. package/dist/test-utils.js +823 -381
  34. package/dist/test-utils.js.map +1 -1
  35. package/dist/test-utils.mjs +751 -308
  36. package/dist/test-utils.mjs.map +1 -1
  37. package/dist/types.d.ts +1 -1
  38. package/dist/types.d.ts.map +1 -1
  39. package/dist/utils/consolidate-coins.d.ts +43 -0
  40. package/dist/utils/consolidate-coins.d.ts.map +1 -0
  41. package/package.json +15 -15
package/dist/index.mjs CHANGED
@@ -705,12 +705,12 @@ var getAssetsByOwner = /* @__PURE__ */ __name(async (opts) => {
705
705
 
706
706
  // src/account.ts
707
707
  import { UTXO_ID_LEN as UTXO_ID_LEN3 } from "@fuel-ts/abi-coder";
708
- import { Address as Address4 } from "@fuel-ts/address";
708
+ import { Address as Address5 } from "@fuel-ts/address";
709
709
  import { randomBytes as randomBytes2 } from "@fuel-ts/crypto";
710
- import { ErrorCode as ErrorCode19, FuelError as FuelError21 } from "@fuel-ts/errors";
711
- import { bn as bn21 } from "@fuel-ts/math";
712
- import { InputType as InputType8, OutputType as OutputType9 } from "@fuel-ts/transactions";
713
- import { arrayify as arrayify16, hexlify as hexlify18, isDefined as isDefined4 } from "@fuel-ts/utils";
710
+ import { ErrorCode as ErrorCode20, FuelError as FuelError22 } from "@fuel-ts/errors";
711
+ import { bn as bn22 } from "@fuel-ts/math";
712
+ import { InputType as InputType8, OutputType as OutputType10 } from "@fuel-ts/transactions";
713
+ import { arrayify as arrayify17, hexlify as hexlify18, isDefined as isDefined4 } from "@fuel-ts/utils";
714
714
  import { clone as clone9 } from "ramda";
715
715
 
716
716
  // src/providers/coin-quantity.ts
@@ -751,8 +751,8 @@ var addAmountToCoinQuantities = /* @__PURE__ */ __name((params) => {
751
751
  import { Address as Address2, isB256 } from "@fuel-ts/address";
752
752
  import { ErrorCode as ErrorCode17, FuelError as FuelError19 } from "@fuel-ts/errors";
753
753
  import { bn as bn18 } from "@fuel-ts/math";
754
- import { InputMessageCoder as InputMessageCoder2, TransactionCoder as TransactionCoder6, TransactionType as TransactionType11 } from "@fuel-ts/transactions";
755
- import { arrayify as arrayify12, hexlify as hexlify17, DateTime as DateTime2, isDefined as isDefined3, sleep as sleep2 } from "@fuel-ts/utils";
754
+ import { InputMessageCoder as InputMessageCoder2, TransactionCoder as TransactionCoder7, TransactionType as TransactionType11 } from "@fuel-ts/transactions";
755
+ import { arrayify as arrayify13, hexlify as hexlify17, DateTime as DateTime2, isDefined as isDefined3, sleep as sleep2 } from "@fuel-ts/utils";
756
756
  import { checkFuelCoreVersionCompatibility, versions } from "@fuel-ts/versions";
757
757
  import { GraphQLClient } from "graphql-request";
758
758
  import gql2 from "graphql-tag";
@@ -2152,8 +2152,11 @@ import { print } from "graphql";
2152
2152
 
2153
2153
  // src/providers/utils/handle-gql-error-message.ts
2154
2154
  import { ErrorCode as ErrorCode2, FuelError as FuelError2 } from "@fuel-ts/errors";
2155
+ var ASSET_ID_REGEX = /[0-9a-fA-F]{32,64}/g;
2155
2156
  var gqlErrorMessage = {
2156
2157
  RPC_CONSISTENCY: /The required fuel block height is higher than the current block height. Required: \d+, Current: \d+/,
2158
+ INSUFFICIENT_FUNDS: /the target cannot be met due to insufficient coins available for [0-9a-fA-F]{32,64}. Collected: \d+/,
2159
+ MAX_COINS_REACHED: /the target for [0-9a-fA-F]{32,64} cannot be met due to exceeding the \d+ coin limit. Collected: \d+./,
2157
2160
  NOT_ENOUGH_COINS_MAX_COINS: /the target cannot be met due to no coins available or exceeding the \d+ coin limit./,
2158
2161
  ASSET_NOT_FOUND: /resource was not found in table/,
2159
2162
  MULTIPLE_CHANGE_POLICIES: /The asset ([a-fA-F0-9]{64}) has multiple change policies/,
@@ -2169,6 +2172,46 @@ var mapGqlErrorMessage = /* @__PURE__ */ __name((error) => {
2169
2172
  error
2170
2173
  );
2171
2174
  }
2175
+ if (gqlErrorMessage.MAX_COINS_REACHED.test(error.message)) {
2176
+ const matches = error.message.match(ASSET_ID_REGEX);
2177
+ const assetId = matches ? `0x${matches[0]}` : null;
2178
+ const owner = matches ? `0x${matches[1]}` : null;
2179
+ let suffix = "";
2180
+ if (assetId) {
2181
+ suffix += `
2182
+ Asset ID: '${assetId}'.`;
2183
+ }
2184
+ if (owner) {
2185
+ suffix += `
2186
+ Owner: '${owner}'.`;
2187
+ }
2188
+ return new FuelError2(
2189
+ ErrorCode2.MAX_COINS_REACHED,
2190
+ `You have too many small value coins - consider combining UTXOs.${suffix}`,
2191
+ { assetId, owner },
2192
+ error
2193
+ );
2194
+ }
2195
+ if (gqlErrorMessage.INSUFFICIENT_FUNDS.test(error.message)) {
2196
+ const matches = error.message.match(ASSET_ID_REGEX);
2197
+ const assetId = matches ? `0x${matches[0]}` : null;
2198
+ const owner = matches ? `0x${matches[1]}` : null;
2199
+ let suffix = "";
2200
+ if (assetId) {
2201
+ suffix += `
2202
+ Asset ID: '${assetId}'.`;
2203
+ }
2204
+ if (owner) {
2205
+ suffix += `
2206
+ Owner: '${owner}'.`;
2207
+ }
2208
+ return new FuelError2(
2209
+ ErrorCode2.INSUFFICIENT_FUNDS,
2210
+ `Insufficient funds.${suffix}`,
2211
+ { assetId, owner },
2212
+ error
2213
+ );
2214
+ }
2172
2215
  if (gqlErrorMessage.MULTIPLE_CHANGE_POLICIES.test(error.message)) {
2173
2216
  const match = error.message.match(/asset ([a-fA-F0-9]{64})/);
2174
2217
  const assetId = match?.[1] || "";
@@ -3262,7 +3305,8 @@ import {
3262
3305
  FAILED_ASSERT_SIGNAL,
3263
3306
  FAILED_TRANSFER_TO_ADDRESS_SIGNAL as FAILED_TRANSFER_TO_ADDRESS_SIGNAL2,
3264
3307
  PANIC_REASONS,
3265
- PANIC_DOC_URL
3308
+ PANIC_DOC_URL,
3309
+ SwaySignalErrors
3266
3310
  } from "@fuel-ts/transactions/configs";
3267
3311
  var assemblePanicError = /* @__PURE__ */ __name((statusReason, metadata) => {
3268
3312
  let errorMessage = `The transaction reverted with reason: "${statusReason}".`;
@@ -3279,58 +3323,98 @@ ${PANIC_DOC_URL}#variant.${statusReason}`;
3279
3323
  });
3280
3324
  }, "assemblePanicError");
3281
3325
  var stringify = /* @__PURE__ */ __name((obj) => JSON.stringify(obj, null, 2), "stringify");
3282
- var assembleRevertError = /* @__PURE__ */ __name((receipts, logs, metadata) => {
3326
+ var assembleSignalErrorMessage = /* @__PURE__ */ __name((reasonHex, logs, metadata) => {
3283
3327
  let errorMessage = "The transaction reverted with an unknown reason.";
3284
- const revertReceipt = receipts.find(({ type }) => type === ReceiptType4.Revert);
3285
3328
  let reason = "";
3286
- if (revertReceipt) {
3287
- const reasonHex = bn7(revertReceipt.val).toHex();
3288
- const lastLog = logs[logs.length - 1];
3289
- const lastButOneLog = logs[logs.length - 2];
3290
- switch (reasonHex) {
3291
- case FAILED_REQUIRE_SIGNAL: {
3292
- reason = "require";
3293
- errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(lastLog) : "an error."}.`;
3294
- break;
3295
- }
3296
- case FAILED_ASSERT_EQ_SIGNAL: {
3297
- const suffix = logs.length >= 2 ? ` comparing ${stringify(lastLog)} and ${stringify(lastButOneLog)}.` : ".";
3298
- reason = "assert_eq";
3299
- errorMessage = `The transaction reverted because of an "assert_eq" statement${suffix}`;
3300
- break;
3301
- }
3302
- case FAILED_ASSERT_NE_SIGNAL: {
3303
- const suffix = logs.length >= 2 ? ` comparing ${stringify(lastButOneLog)} and ${stringify(lastLog)}.` : ".";
3304
- reason = "assert_ne";
3305
- errorMessage = `The transaction reverted because of an "assert_ne" statement${suffix}`;
3306
- break;
3307
- }
3308
- case FAILED_ASSERT_SIGNAL:
3309
- reason = "assert";
3310
- errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
3311
- break;
3312
- case FAILED_TRANSFER_TO_ADDRESS_SIGNAL2:
3313
- reason = "MissingOutputVariable";
3314
- errorMessage = `The transaction reverted because it's missing an "OutputVariable".`;
3315
- break;
3316
- default:
3317
- throw new FuelError8(
3318
- ErrorCode8.UNKNOWN,
3319
- `The transaction reverted with an unknown reason: ${revertReceipt.val}`,
3320
- {
3321
- ...metadata,
3322
- reason: "unknown"
3323
- }
3324
- );
3329
+ const lastLog = logs[logs.length - 1];
3330
+ const lastButOneLog = logs[logs.length - 2];
3331
+ switch (reasonHex) {
3332
+ case FAILED_REQUIRE_SIGNAL: {
3333
+ reason = "require";
3334
+ errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(lastLog) : "an error."}.`;
3335
+ break;
3325
3336
  }
3337
+ case FAILED_ASSERT_EQ_SIGNAL: {
3338
+ const suffix = logs.length >= 2 ? ` comparing ${stringify(lastLog)} and ${stringify(lastButOneLog)}.` : ".";
3339
+ reason = "assert_eq";
3340
+ errorMessage = `The transaction reverted because of an "assert_eq" statement${suffix}`;
3341
+ break;
3342
+ }
3343
+ case FAILED_ASSERT_NE_SIGNAL: {
3344
+ const suffix = logs.length >= 2 ? ` comparing ${stringify(lastButOneLog)} and ${stringify(lastLog)}.` : ".";
3345
+ reason = "assert_ne";
3346
+ errorMessage = `The transaction reverted because of an "assert_ne" statement${suffix}`;
3347
+ break;
3348
+ }
3349
+ case FAILED_ASSERT_SIGNAL:
3350
+ reason = "assert";
3351
+ errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
3352
+ break;
3353
+ case FAILED_TRANSFER_TO_ADDRESS_SIGNAL2:
3354
+ reason = "MissingOutputVariable";
3355
+ errorMessage = `The transaction reverted because it's missing an "OutputVariable".`;
3356
+ break;
3357
+ default:
3358
+ reason = `revert_with_log`;
3359
+ errorMessage = `The transaction reverted because a "revert_with_log" statement has thrown ${logs.length ? stringify(lastLog) : "an error."}.`;
3360
+ break;
3326
3361
  }
3327
3362
  return new FuelError8(ErrorCode8.SCRIPT_REVERTED, errorMessage, {
3328
3363
  ...metadata,
3329
3364
  reason
3330
3365
  });
3366
+ }, "assembleSignalErrorMessage");
3367
+ function buildAbiErrorMessage(abiError, logs, metadata, reason) {
3368
+ const { pos, msg } = abiError;
3369
+ let errorMessage = "";
3370
+ const positionMessage = pos ? `
3371
+
3372
+ This error originated at ${JSON.stringify(pos, null, 2)}` : "";
3373
+ if (msg) {
3374
+ errorMessage = `A sway "panic" expression was invoked with the message: "${msg}".${positionMessage}`;
3375
+ } else {
3376
+ const value = logs[logs.length - 1];
3377
+ errorMessage = `A sway "panic" expression was invoked with the value: ${JSON.stringify(value)}.${positionMessage}`;
3378
+ }
3379
+ return new FuelError8(ErrorCode8.SCRIPT_REVERTED, errorMessage, {
3380
+ ...metadata,
3381
+ abiError,
3382
+ reason
3383
+ });
3384
+ }
3385
+ __name(buildAbiErrorMessage, "buildAbiErrorMessage");
3386
+ function findErrorInAbis(statusReason, abis = []) {
3387
+ for (const abi of abis) {
3388
+ if (abi.errorCodes?.[statusReason]) {
3389
+ return abi.errorCodes[statusReason];
3390
+ }
3391
+ }
3392
+ return void 0;
3393
+ }
3394
+ __name(findErrorInAbis, "findErrorInAbis");
3395
+ var assembleRevertError = /* @__PURE__ */ __name((_receipts, logs, metadata, statusReason, abis) => {
3396
+ const match = statusReason.match(/Revert\((\d+)\)/);
3397
+ const reason = match?.[1] ?? statusReason;
3398
+ const reasonHex = bn7(reason).toHex();
3399
+ if (Object.values(SwaySignalErrors).includes(reasonHex)) {
3400
+ return assembleSignalErrorMessage(reasonHex, logs, metadata);
3401
+ }
3402
+ let abiError;
3403
+ if (abis) {
3404
+ const abisArr = [abis.main, ...Object.values(abis.otherContractsAbis)];
3405
+ abiError = findErrorInAbis(reason, abisArr);
3406
+ }
3407
+ if (abiError) {
3408
+ return buildAbiErrorMessage(abiError, logs, metadata, reason);
3409
+ }
3410
+ const errorMessage = `The transaction reverted with reason: ${reason}.`;
3411
+ return new FuelError8(ErrorCode8.SCRIPT_REVERTED, errorMessage, {
3412
+ ...metadata,
3413
+ reason
3414
+ });
3331
3415
  }, "assembleRevertError");
3332
3416
  var extractTxError = /* @__PURE__ */ __name((params) => {
3333
- const { receipts, statusReason, logs, groupedLogs } = params;
3417
+ const { receipts, statusReason, logs, groupedLogs, abis } = params;
3334
3418
  const isPanic = receipts.some(({ type }) => type === ReceiptType4.Panic);
3335
3419
  const isRevert = receipts.some(({ type }) => type === ReceiptType4.Revert);
3336
3420
  const metadata = {
@@ -3344,7 +3428,7 @@ var extractTxError = /* @__PURE__ */ __name((params) => {
3344
3428
  if (isPanic) {
3345
3429
  return assemblePanicError(statusReason, metadata);
3346
3430
  }
3347
- return assembleRevertError(receipts, logs, metadata);
3431
+ return assembleRevertError(receipts, logs, metadata, statusReason, abis);
3348
3432
  }, "extractTxError");
3349
3433
 
3350
3434
  // src/providers/utils/merge-quantities.ts
@@ -4349,11 +4433,15 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
4349
4433
  * @deprecated Use `provider.assembleTx` instead.
4350
4434
  * Check the migration guide https://docs.fuel.network/guide/assembling-transactions/migration-guide.html for more information.
4351
4435
  */
4352
- async estimateAndFund(account, { signatureCallback, quantities = [] } = {}) {
4436
+ async estimateAndFund(account, {
4437
+ signatureCallback,
4438
+ quantities = [],
4439
+ skipAutoConsolidation
4440
+ } = {}) {
4353
4441
  const txCost = await account.getTransactionCost(this, { signatureCallback, quantities });
4354
4442
  this.maxFee = txCost.maxFee;
4355
4443
  this.gasLimit = txCost.gasUsed;
4356
- await account.fund(this, txCost);
4444
+ await account.fund(this, txCost, { skipAutoConsolidation });
4357
4445
  return this;
4358
4446
  }
4359
4447
  /**
@@ -4932,12 +5020,12 @@ var ResourceCache = class {
4932
5020
  // src/providers/transaction-response/transaction-response.ts
4933
5021
  import { ErrorCode as ErrorCode15, FuelError as FuelError17 } from "@fuel-ts/errors";
4934
5022
  import { bn as bn17 } from "@fuel-ts/math";
4935
- import { TransactionCoder as TransactionCoder5, TxPointerCoder } from "@fuel-ts/transactions";
4936
- import { arrayify as arrayify11 } from "@fuel-ts/utils";
5023
+ import { TransactionCoder as TransactionCoder6, TxPointerCoder } from "@fuel-ts/transactions";
5024
+ import { arrayify as arrayify12 } from "@fuel-ts/utils";
4937
5025
 
4938
5026
  // src/providers/transaction-summary/assemble-transaction-summary.ts
4939
5027
  import { bn as bn16 } from "@fuel-ts/math";
4940
- import { PolicyType as PolicyType3, TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
5028
+ import { PolicyType as PolicyType3, TransactionCoder as TransactionCoder5 } from "@fuel-ts/transactions";
4941
5029
  import { DateTime, hexlify as hexlify16 } from "@fuel-ts/utils";
4942
5030
 
4943
5031
  // src/providers/transaction-summary/calculate-tx-fee-for-summary.ts
@@ -5009,8 +5097,47 @@ var calculateTXFeeForSummary = /* @__PURE__ */ __name((params) => {
5009
5097
  // src/providers/transaction-summary/operations.ts
5010
5098
  import { ZeroBytes32 as ZeroBytes329 } from "@fuel-ts/address/configs";
5011
5099
  import { ErrorCode as ErrorCode13, FuelError as FuelError15 } from "@fuel-ts/errors";
5012
- import { bn as bn14 } from "@fuel-ts/math";
5013
- import { ReceiptType as ReceiptType5, TransactionType as TransactionType10 } from "@fuel-ts/transactions";
5100
+ import { bn as bn14, toBytes } from "@fuel-ts/math";
5101
+ import { ReceiptType as ReceiptType5, TransactionCoder as TransactionCoder4, TransactionType as TransactionType10 } from "@fuel-ts/transactions";
5102
+ import { arrayify as arrayify11, concat as concat3 } from "@fuel-ts/utils";
5103
+
5104
+ // src/providers/transaction-summary/call.ts
5105
+ import { StdStringCoder } from "@fuel-ts/abi-coder";
5106
+ import { Interface as Interface2 } from "@fuel-ts/abi-coder";
5107
+ var getFunctionCall = /* @__PURE__ */ __name(({
5108
+ abi,
5109
+ receipt,
5110
+ offset,
5111
+ scriptData
5112
+ }) => {
5113
+ const [functionSelector, argumentsOffset] = new StdStringCoder().decode(scriptData, offset);
5114
+ const abiInterface = new Interface2(abi);
5115
+ const functionFragment = abiInterface.getFunction(functionSelector);
5116
+ const inputs = functionFragment.jsonFn.inputs;
5117
+ let argumentsProvided;
5118
+ if (inputs.length) {
5119
+ const functionArgsBytes = scriptData.slice(argumentsOffset);
5120
+ const decodedArguments = functionFragment.decodeArguments(functionArgsBytes);
5121
+ argumentsProvided = inputs.reduce((prev, input, index) => {
5122
+ const value = decodedArguments?.[index];
5123
+ const name = input.name;
5124
+ if (name) {
5125
+ return {
5126
+ ...prev,
5127
+ // reparse to remove bn
5128
+ [name]: JSON.parse(JSON.stringify(value))
5129
+ };
5130
+ }
5131
+ return prev;
5132
+ }, {});
5133
+ }
5134
+ return {
5135
+ functionSignature: functionFragment.signature,
5136
+ functionName: functionFragment.name,
5137
+ argumentsProvided,
5138
+ ...receipt.amount?.isZero() ? {} : { amount: receipt.amount, assetId: receipt.assetId }
5139
+ };
5140
+ }, "getFunctionCall");
5014
5141
 
5015
5142
  // src/providers/transaction-summary/input.ts
5016
5143
  import { ErrorCode as ErrorCode12, FuelError as FuelError14 } from "@fuel-ts/errors";
@@ -5345,12 +5472,45 @@ function getWithdrawFromFuelOperations({
5345
5472
  return withdrawFromFuelOperations;
5346
5473
  }
5347
5474
  __name(getWithdrawFromFuelOperations, "getWithdrawFromFuelOperations");
5348
- function getContractCalls(contractInput, abiMap, _receipt, _rawPayload, _maxInputs) {
5349
- const abi = abiMap?.[contractInput.contractID];
5350
- if (!abi) {
5351
- return [];
5475
+ function findBytesSegmentIndex(whole, segment) {
5476
+ for (let i = 0; i <= whole.length - segment.length; i++) {
5477
+ let match = true;
5478
+ for (let j = 0; j < segment.length; j++) {
5479
+ if (whole[i + j] !== segment[j]) {
5480
+ match = false;
5481
+ break;
5482
+ }
5483
+ }
5484
+ if (match) {
5485
+ return i;
5486
+ }
5352
5487
  }
5353
- return [];
5488
+ return -1;
5489
+ }
5490
+ __name(findBytesSegmentIndex, "findBytesSegmentIndex");
5491
+ function getContractCalls(contractInput, abiMap, receipt, scriptData) {
5492
+ const calls = [];
5493
+ const abi = abiMap?.[contractInput.contractID];
5494
+ if (!abi || !scriptData) {
5495
+ return calls;
5496
+ }
5497
+ const bytesSegment = concat3([
5498
+ arrayify11(receipt.to),
5499
+ // Contract ID (32 bytes)
5500
+ toBytes(receipt.param1.toHex(), 8),
5501
+ // Function selector offset (8 bytes)
5502
+ toBytes(receipt.param2.toHex(), 8)
5503
+ // Function args offset (8 bytes)
5504
+ ]);
5505
+ const segmentIndex = findBytesSegmentIndex(scriptData, bytesSegment);
5506
+ const canDecodeFunctionCall = segmentIndex !== -1;
5507
+ if (!canDecodeFunctionCall) {
5508
+ return calls;
5509
+ }
5510
+ const offset = segmentIndex + bytesSegment.length;
5511
+ const call = getFunctionCall({ abi, receipt, offset, scriptData });
5512
+ calls.push(call);
5513
+ return calls;
5354
5514
  }
5355
5515
  __name(getContractCalls, "getContractCalls");
5356
5516
  function getAssetsSent(receipt) {
@@ -5362,14 +5522,14 @@ function getAssetsSent(receipt) {
5362
5522
  ];
5363
5523
  }
5364
5524
  __name(getAssetsSent, "getAssetsSent");
5365
- function processCallReceipt(receipt, contractInput, inputs, abiMap, rawPayload, maxInputs, baseAssetId) {
5525
+ function processCallReceipt(receipt, contractInput, inputs, abiMap, scriptData, baseAssetId) {
5366
5526
  const assetId = receipt.assetId === ZeroBytes329 ? baseAssetId : receipt.assetId;
5367
5527
  const input = getInputFromAssetId(inputs, assetId, assetId === baseAssetId);
5368
5528
  if (!input) {
5369
5529
  return [];
5370
5530
  }
5371
5531
  const inputAddress = getInputAccountAddress(input);
5372
- const calls = getContractCalls(contractInput, abiMap, receipt, rawPayload, maxInputs);
5532
+ const calls = getContractCalls(contractInput, abiMap, receipt, scriptData);
5373
5533
  return [
5374
5534
  {
5375
5535
  name: "Contract call" /* contractCall */,
@@ -5394,7 +5554,6 @@ function getContractCallOperations({
5394
5554
  receipts,
5395
5555
  abiMap,
5396
5556
  rawPayload,
5397
- maxInputs,
5398
5557
  baseAssetId
5399
5558
  }) {
5400
5559
  const contractCallReceipts = getReceiptsCall(receipts);
@@ -5404,16 +5563,15 @@ function getContractCallOperations({
5404
5563
  if (!contractInput) {
5405
5564
  return [];
5406
5565
  }
5566
+ let scriptData;
5567
+ if (rawPayload) {
5568
+ const [transaction] = new TransactionCoder4().decode(arrayify11(rawPayload), 0);
5569
+ if (transaction.type === TransactionType10.Script) {
5570
+ scriptData = arrayify11(transaction.scriptData);
5571
+ }
5572
+ }
5407
5573
  return contractCallReceipts.filter((receipt) => receipt.to === contractInput.contractID).flatMap(
5408
- (receipt) => processCallReceipt(
5409
- receipt,
5410
- contractInput,
5411
- inputs,
5412
- abiMap,
5413
- rawPayload,
5414
- maxInputs,
5415
- baseAssetId
5416
- )
5574
+ (receipt) => processCallReceipt(receipt, contractInput, inputs, abiMap, scriptData, baseAssetId)
5417
5575
  );
5418
5576
  });
5419
5577
  }
@@ -5830,7 +5988,7 @@ function assemblePreConfirmationTransactionSummary(params) {
5830
5988
  type = getTransactionTypeName(transaction.type);
5831
5989
  tip = bn16(transaction.policies?.find((policy) => policy.type === PolicyType3.Tip)?.data);
5832
5990
  if (receipts) {
5833
- const rawPayload = hexlify16(new TransactionCoder4().encode(transaction));
5991
+ const rawPayload = hexlify16(new TransactionCoder5().encode(transaction));
5834
5992
  operations = getOperations({
5835
5993
  transactionType: transaction.type,
5836
5994
  inputs: transaction.inputs || [],
@@ -5876,7 +6034,7 @@ function assemblePreConfirmationTransactionSummary(params) {
5876
6034
  __name(assemblePreConfirmationTransactionSummary, "assemblePreConfirmationTransactionSummary");
5877
6035
 
5878
6036
  // src/providers/transaction-response/getAllDecodedLogs.ts
5879
- import { Interface as Interface2, BigNumberCoder } from "@fuel-ts/abi-coder";
6037
+ import { Interface as Interface3, BigNumberCoder } from "@fuel-ts/abi-coder";
5880
6038
  import { ZeroBytes32 as ZeroBytes3210 } from "@fuel-ts/address/configs";
5881
6039
  import { ReceiptType as ReceiptType7 } from "@fuel-ts/transactions";
5882
6040
  function getAllDecodedLogs(opts) {
@@ -5896,7 +6054,7 @@ function getAllDecodedLogs(opts) {
5896
6054
  const isLogFromMainAbi = receipt.id === ZeroBytes3210 || mainContract === receipt.id;
5897
6055
  const isDecodable = isLogFromMainAbi || externalAbis[receipt.id];
5898
6056
  if (isDecodable) {
5899
- const interfaceToUse = isLogFromMainAbi ? new Interface2(mainAbi) : new Interface2(externalAbis[receipt.id]);
6057
+ const interfaceToUse = isLogFromMainAbi ? new Interface3(mainAbi) : new Interface3(externalAbis[receipt.id]);
5900
6058
  const data = receipt.type === ReceiptType7.Log ? new BigNumberCoder("u64").encode(receipt.ra) : receipt.data;
5901
6059
  const [decodedLog] = interfaceToUse.decodeLog(data, receipt.rb.toString());
5902
6060
  logs.push(decodedLog);
@@ -5912,25 +6070,6 @@ __name(getAllDecodedLogs, "getAllDecodedLogs");
5912
6070
 
5913
6071
  // src/providers/transaction-response/transaction-response.ts
5914
6072
  var TransactionResponse = class _TransactionResponse {
5915
- /**
5916
- * Constructor for `TransactionResponse`.
5917
- *
5918
- * @param tx - The transaction ID or TransactionRequest.
5919
- * @param provider - The provider.
5920
- */
5921
- constructor(tx, provider, chainId, abis, submitTxSubscription) {
5922
- this.submitTxSubscription = submitTxSubscription;
5923
- if (typeof tx === "string") {
5924
- this.id = tx;
5925
- } else {
5926
- this.id = tx.getTransactionId(chainId);
5927
- this.request = tx;
5928
- }
5929
- this.provider = provider;
5930
- this.abis = abis;
5931
- this.waitForResult = this.waitForResult.bind(this);
5932
- this.waitForPreConfirmation = this.waitForPreConfirmation.bind(this);
5933
- }
5934
6073
  static {
5935
6074
  __name(this, "TransactionResponse");
5936
6075
  }
@@ -5945,9 +6084,42 @@ var TransactionResponse = class _TransactionResponse {
5945
6084
  request;
5946
6085
  status;
5947
6086
  abis;
6087
+ submitTxSubscription;
5948
6088
  preConfirmationStatus;
5949
6089
  waitingForStreamData = false;
5950
6090
  statusResolvers = /* @__PURE__ */ new Map();
6091
+ /**
6092
+ * Constructor for `TransactionResponse`.
6093
+ */
6094
+ constructor(constructorParams, provider, chainId, abis, submitTxSubscription) {
6095
+ let tx;
6096
+ let _provider;
6097
+ let _chainId;
6098
+ let _abis;
6099
+ if (typeof constructorParams === "object" && "provider" in constructorParams && arguments.length === 1) {
6100
+ tx = constructorParams.transactionRequestOrId;
6101
+ _provider = constructorParams.provider;
6102
+ _chainId = constructorParams.chainId;
6103
+ _abis = constructorParams.abis;
6104
+ this.submitTxSubscription = constructorParams.submitAndAwaitSubscription;
6105
+ } else {
6106
+ tx = constructorParams;
6107
+ _provider = provider;
6108
+ _chainId = chainId;
6109
+ _abis = abis;
6110
+ this.submitTxSubscription = submitTxSubscription;
6111
+ }
6112
+ if (typeof tx === "string") {
6113
+ this.id = tx;
6114
+ } else {
6115
+ this.id = tx.getTransactionId(_chainId);
6116
+ this.request = tx;
6117
+ }
6118
+ this.provider = _provider;
6119
+ this.abis = _abis;
6120
+ this.waitForResult = this.waitForResult.bind(this);
6121
+ this.waitForPreConfirmation = this.waitForPreConfirmation.bind(this);
6122
+ }
5951
6123
  /**
5952
6124
  * Async constructor for `TransactionResponse`. This method can be used to create
5953
6125
  * an instance of `TransactionResponse` and wait for the transaction to be fetched
@@ -5996,8 +6168,8 @@ var TransactionResponse = class _TransactionResponse {
5996
6168
  }
5997
6169
  const gqlTransaction = this.gqlTransaction ?? await this.fetch();
5998
6170
  const { rawPayload } = gqlTransaction;
5999
- const bytes = arrayify11(rawPayload);
6000
- const [tx] = new TransactionCoder5().decode(bytes, 0);
6171
+ const bytes = arrayify12(rawPayload);
6172
+ const [tx] = new TransactionCoder6().decode(bytes, 0);
6001
6173
  return {
6002
6174
  tx,
6003
6175
  bytes
@@ -6184,6 +6356,7 @@ var TransactionResponse = class _TransactionResponse {
6184
6356
  ...transactionSummary
6185
6357
  };
6186
6358
  let { logs, groupedLogs } = { logs: [], groupedLogs: {} };
6359
+ let abis;
6187
6360
  if (this.abis) {
6188
6361
  ({ logs, groupedLogs } = getAllDecodedLogs({
6189
6362
  receipts: transactionSummary.receipts,
@@ -6192,6 +6365,7 @@ var TransactionResponse = class _TransactionResponse {
6192
6365
  }));
6193
6366
  transactionResult.logs = logs;
6194
6367
  transactionResult.groupedLogs = groupedLogs;
6368
+ abis = this.abis;
6195
6369
  }
6196
6370
  const { receipts } = transactionResult;
6197
6371
  const status = this.getTransactionStatus();
@@ -6201,7 +6375,8 @@ var TransactionResponse = class _TransactionResponse {
6201
6375
  receipts,
6202
6376
  statusReason: reason,
6203
6377
  logs,
6204
- groupedLogs
6378
+ groupedLogs,
6379
+ abis
6205
6380
  });
6206
6381
  }
6207
6382
  return transactionResult;
@@ -6263,7 +6438,7 @@ var TransactionResponse = class _TransactionResponse {
6263
6438
  };
6264
6439
 
6265
6440
  // src/providers/transaction-response/getDecodedLogs.ts
6266
- import { Interface as Interface3, BigNumberCoder as BigNumberCoder2 } from "@fuel-ts/abi-coder";
6441
+ import { Interface as Interface4, BigNumberCoder as BigNumberCoder2 } from "@fuel-ts/abi-coder";
6267
6442
  import { ZeroBytes32 as ZeroBytes3211 } from "@fuel-ts/address/configs";
6268
6443
  import { ReceiptType as ReceiptType8 } from "@fuel-ts/transactions";
6269
6444
  function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
@@ -6279,7 +6454,7 @@ function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
6279
6454
  const isLogFromMainAbi = receipt.id === ZeroBytes3211 || mainContract === receipt.id;
6280
6455
  const isDecodable = isLogFromMainAbi || externalAbis[receipt.id];
6281
6456
  if (isDecodable) {
6282
- const interfaceToUse = isLogFromMainAbi ? new Interface3(mainAbi) : new Interface3(externalAbis[receipt.id]);
6457
+ const interfaceToUse = isLogFromMainAbi ? new Interface4(mainAbi) : new Interface4(externalAbis[receipt.id]);
6283
6458
  const data = receipt.type === ReceiptType8.Log ? new BigNumberCoder2("u64").encode(receipt.ra) : receipt.data;
6284
6459
  const [decodedLog] = interfaceToUse.decodeLog(data, receipt.rb.toString());
6285
6460
  logs.push(decodedLog);
@@ -6484,7 +6659,15 @@ var Provider = class _Provider {
6484
6659
  if (_Provider.ENABLE_RPC_CONSISTENCY && _Provider.hasWriteOperationHappened(url)) {
6485
6660
  _Provider.applyBlockHeight(fullRequest, url);
6486
6661
  }
6487
- return _Provider.fetchAndProcessBlockHeight(url, fullRequest, options);
6662
+ const response = await _Provider.fetchAndProcessBlockHeight(url, fullRequest, options);
6663
+ if (response.body === null) {
6664
+ throw new FuelError19(
6665
+ ErrorCode17.RESPONSE_BODY_EMPTY,
6666
+ "The response from the server is missing the body",
6667
+ { timestamp: (/* @__PURE__ */ new Date()).toISOString(), request: request2, response }
6668
+ );
6669
+ }
6670
+ return response;
6488
6671
  }, retryOptions);
6489
6672
  }
6490
6673
  static applyBlockHeight(request2, url) {
@@ -6507,13 +6690,15 @@ var Provider = class _Provider {
6507
6690
  baseDelay: 500
6508
6691
  };
6509
6692
  for (let retriesLeft = retryOptions.maxRetries; retriesLeft > 0; --retriesLeft) {
6510
- const { extensions } = await parseGraphqlResponse({
6511
- response,
6512
- isSubscription: url.endsWith("-sub")
6513
- });
6514
- _Provider.setCurrentBlockHeight(url, extensions?.current_fuel_block_height);
6515
- if (!extensions?.fuel_block_height_precondition_failed) {
6516
- break;
6693
+ if (response.body) {
6694
+ const { extensions } = await parseGraphqlResponse({
6695
+ response,
6696
+ isSubscription: url.endsWith("-sub")
6697
+ });
6698
+ _Provider.setCurrentBlockHeight(url, extensions?.current_fuel_block_height);
6699
+ if (!extensions?.fuel_block_height_precondition_failed) {
6700
+ break;
6701
+ }
6517
6702
  }
6518
6703
  const retryAttempt = retryOptions.maxRetries - retriesLeft + 1;
6519
6704
  const sleepTime = getWaitDelay(retryOptions, retryAttempt);
@@ -6936,7 +7121,13 @@ var Provider = class _Provider {
6936
7121
  transactionRequest.getTransactionId(await this.getChainId())
6937
7122
  );
6938
7123
  const chainId = await this.getChainId();
6939
- return new TransactionResponse(transactionRequest, this, chainId, abis, subscription);
7124
+ return new TransactionResponse({
7125
+ transactionRequestOrId: transactionRequest,
7126
+ provider: this,
7127
+ chainId,
7128
+ abis,
7129
+ submitAndAwaitSubscription: subscription
7130
+ });
6940
7131
  }
6941
7132
  /**
6942
7133
  * Executes a transaction without actually submitting it to the chain.
@@ -7666,7 +7857,7 @@ var Provider = class _Provider {
7666
7857
  },
7667
7858
  transactionIds: block.transactions.map((tx) => tx.id),
7668
7859
  transactions: block.transactions.map(
7669
- (tx) => new TransactionCoder6().decode(arrayify12(tx.rawPayload), 0)?.[0]
7860
+ (tx) => new TransactionCoder7().decode(arrayify13(tx.rawPayload), 0)?.[0]
7670
7861
  )
7671
7862
  };
7672
7863
  }
@@ -7682,8 +7873,8 @@ var Provider = class _Provider {
7682
7873
  return null;
7683
7874
  }
7684
7875
  try {
7685
- return new TransactionCoder6().decode(
7686
- arrayify12(transaction.rawPayload),
7876
+ return new TransactionCoder7().decode(
7877
+ arrayify13(transaction.rawPayload),
7687
7878
  0
7688
7879
  )?.[0];
7689
7880
  } catch (error) {
@@ -7708,10 +7899,10 @@ var Provider = class _Provider {
7708
7899
  paginationLimit: TRANSACTIONS_PAGE_SIZE_LIMIT
7709
7900
  })
7710
7901
  });
7711
- const coder = new TransactionCoder6();
7902
+ const coder = new TransactionCoder7();
7712
7903
  const transactions = edges.map(({ node: { rawPayload } }) => {
7713
7904
  try {
7714
- return coder.decode(arrayify12(rawPayload), 0)[0];
7905
+ return coder.decode(arrayify13(rawPayload), 0)[0];
7715
7906
  } catch (error) {
7716
7907
  if (error instanceof FuelError19 && error.code === ErrorCode17.UNSUPPORTED_TRANSACTION_TYPE) {
7717
7908
  console.warn("Unsupported transaction type encountered");
@@ -8031,7 +8222,11 @@ var Provider = class _Provider {
8031
8222
  */
8032
8223
  async getTransactionResponse(transactionId) {
8033
8224
  const chainId = await this.getChainId();
8034
- return new TransactionResponse(transactionId, this, chainId);
8225
+ return new TransactionResponse({
8226
+ transactionRequestOrId: transactionId,
8227
+ provider: this,
8228
+ chainId
8229
+ });
8035
8230
  }
8036
8231
  /**
8037
8232
  * Returns Message for given nonce.
@@ -8082,18 +8277,21 @@ var Provider = class _Provider {
8082
8277
  extractDryRunError(transactionRequest, receipts, reason) {
8083
8278
  let logs = [];
8084
8279
  let groupedLogs = {};
8280
+ let abis;
8085
8281
  if (transactionRequest.type === TransactionType11.Script && transactionRequest.abis) {
8086
8282
  ({ logs, groupedLogs } = getAllDecodedLogs({
8087
8283
  receipts,
8088
8284
  mainAbi: transactionRequest.abis.main,
8089
8285
  externalAbis: transactionRequest.abis.otherContractsAbis
8090
8286
  }));
8287
+ abis = transactionRequest.abis;
8091
8288
  }
8092
8289
  return extractTxError({
8093
8290
  logs,
8094
8291
  groupedLogs,
8095
8292
  receipts,
8096
- statusReason: reason
8293
+ statusReason: reason,
8294
+ abis
8097
8295
  });
8098
8296
  }
8099
8297
  /**
@@ -8164,8 +8362,8 @@ var Provider = class _Provider {
8164
8362
  // src/providers/transaction-summary/get-transaction-summary.ts
8165
8363
  import { ErrorCode as ErrorCode18, FuelError as FuelError20 } from "@fuel-ts/errors";
8166
8364
  import { bn as bn19 } from "@fuel-ts/math";
8167
- import { TransactionCoder as TransactionCoder7 } from "@fuel-ts/transactions";
8168
- import { arrayify as arrayify13 } from "@fuel-ts/utils";
8365
+ import { TransactionCoder as TransactionCoder8 } from "@fuel-ts/transactions";
8366
+ import { arrayify as arrayify14 } from "@fuel-ts/utils";
8169
8367
  async function getTransactionSummary(params) {
8170
8368
  const { id, provider, abiMap } = params;
8171
8369
  const { transaction: gqlTransaction } = await provider.operations.getTransactionWithReceipts({
@@ -8177,8 +8375,8 @@ async function getTransactionSummary(params) {
8177
8375
  `Transaction not found for given id: ${id}.`
8178
8376
  );
8179
8377
  }
8180
- const [decodedTransaction] = new TransactionCoder7().decode(
8181
- arrayify13(gqlTransaction.rawPayload),
8378
+ const [decodedTransaction] = new TransactionCoder8().decode(
8379
+ arrayify14(gqlTransaction.rawPayload),
8182
8380
  0
8183
8381
  );
8184
8382
  let txReceipts = [];
@@ -8200,7 +8398,7 @@ async function getTransactionSummary(params) {
8200
8398
  id: gqlTransaction.id,
8201
8399
  receipts,
8202
8400
  transaction: decodedTransaction,
8203
- transactionBytes: arrayify13(gqlTransaction.rawPayload),
8401
+ transactionBytes: arrayify14(gqlTransaction.rawPayload),
8204
8402
  gqlTransactionStatus: gqlTransaction.status,
8205
8403
  gasPerByte: bn19(gasPerByte),
8206
8404
  gasPriceFactor: bn19(gasPriceFactor),
@@ -8266,7 +8464,7 @@ async function getTransactionsSummaries(params) {
8266
8464
  const transactions = edges.map((edge) => {
8267
8465
  const { node: gqlTransaction } = edge;
8268
8466
  const { id, rawPayload, status } = gqlTransaction;
8269
- const [decodedTransaction] = new TransactionCoder7().decode(arrayify13(rawPayload), 0);
8467
+ const [decodedTransaction] = new TransactionCoder8().decode(arrayify14(rawPayload), 0);
8270
8468
  let txReceipts = [];
8271
8469
  if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
8272
8470
  txReceipts = gqlTransaction.status.receipts;
@@ -8276,7 +8474,7 @@ async function getTransactionsSummaries(params) {
8276
8474
  id,
8277
8475
  receipts,
8278
8476
  transaction: decodedTransaction,
8279
- transactionBytes: arrayify13(rawPayload),
8477
+ transactionBytes: arrayify14(rawPayload),
8280
8478
  gqlTransactionStatus: status,
8281
8479
  abiMap,
8282
8480
  gasPerByte,
@@ -8301,8 +8499,8 @@ __name(getTransactionsSummaries, "getTransactionsSummaries");
8301
8499
 
8302
8500
  // src/providers/transaction-summary/assemble-transaction-summary-from-serialized.ts
8303
8501
  import { bn as bn20 } from "@fuel-ts/math";
8304
- import { TransactionCoder as TransactionCoder8 } from "@fuel-ts/transactions";
8305
- import { arrayify as arrayify14 } from "@fuel-ts/utils";
8502
+ import { TransactionCoder as TransactionCoder9 } from "@fuel-ts/transactions";
8503
+ import { arrayify as arrayify15 } from "@fuel-ts/utils";
8306
8504
  var assembleTransactionSummaryFromJson = /* @__PURE__ */ __name(async (opts) => {
8307
8505
  const { provider, transactionSummary } = opts;
8308
8506
  const { id, transactionBytes, gasPrice, receipts } = transactionSummary;
@@ -8314,8 +8512,8 @@ var assembleTransactionSummaryFromJson = /* @__PURE__ */ __name(async (opts) =>
8314
8512
  gasCosts
8315
8513
  }
8316
8514
  } = await provider.getChain();
8317
- const deserializedTransactionBytes = arrayify14(transactionBytes);
8318
- const [transaction] = new TransactionCoder8().decode(deserializedTransactionBytes, 0);
8515
+ const deserializedTransactionBytes = arrayify15(transactionBytes);
8516
+ const [transaction] = new TransactionCoder9().decode(deserializedTransactionBytes, 0);
8319
8517
  return assembleTransactionSummary({
8320
8518
  id,
8321
8519
  transaction,
@@ -8359,7 +8557,12 @@ var deserializeTransactionResponseJson = /* @__PURE__ */ __name((json) => {
8359
8557
  } = json;
8360
8558
  const provider = new Provider(providerUrl, { cache: providerCache });
8361
8559
  const { chainId } = providerCache.chain.consensusParameters;
8362
- const response = new TransactionResponse(id, provider, Number(chainId), abis);
8560
+ const response = new TransactionResponse({
8561
+ transactionRequestOrId: id,
8562
+ provider,
8563
+ chainId: Number(chainId),
8564
+ abis
8565
+ });
8363
8566
  if (requestJson) {
8364
8567
  response.request = transactionRequestify(JSON.parse(requestJson));
8365
8568
  }
@@ -8376,18 +8579,166 @@ var AbstractAccount = class {
8376
8579
  }
8377
8580
  };
8378
8581
 
8582
+ // src/utils/consolidate-coins.ts
8583
+ import { Address as Address3 } from "@fuel-ts/address";
8584
+ import { ErrorCode as ErrorCode19, FuelError as FuelError21 } from "@fuel-ts/errors";
8585
+ import { bn as bn21 } from "@fuel-ts/math";
8586
+ import { OutputType as OutputType9 } from "@fuel-ts/transactions";
8587
+ import { splitEvery } from "ramda";
8588
+ var CONSOLIDATABLE_ERROR_CODES = [ErrorCode19.MAX_COINS_REACHED];
8589
+ var consolidateCoinsIfRequired = /* @__PURE__ */ __name(async (opts) => {
8590
+ const { error: errorUnknown, account, skipAutoConsolidation = false } = opts;
8591
+ if (skipAutoConsolidation) {
8592
+ return false;
8593
+ }
8594
+ const error = FuelError21.parse(errorUnknown);
8595
+ if (CONSOLIDATABLE_ERROR_CODES.includes(error.code)) {
8596
+ const { assetId, owner } = error.metadata;
8597
+ return account.startConsolidation({
8598
+ owner,
8599
+ assetId
8600
+ });
8601
+ }
8602
+ return false;
8603
+ }, "consolidateCoinsIfRequired");
8604
+ var getAllCoins = /* @__PURE__ */ __name(async (account, assetId) => {
8605
+ const all = [];
8606
+ let hasNextPage = true;
8607
+ let after;
8608
+ while (hasNextPage) {
8609
+ const { coins, pageInfo } = await account.getCoins(assetId, { after });
8610
+ all.push(...coins);
8611
+ after = coins.pop()?.id;
8612
+ hasNextPage = pageInfo.hasNextPage;
8613
+ }
8614
+ return { coins: all };
8615
+ }, "getAllCoins");
8616
+ var sortCoins = /* @__PURE__ */ __name(({ coins }) => coins.sort((a, b) => b.amount.cmp(a.amount)), "sortCoins");
8617
+ var createOuputCoin = /* @__PURE__ */ __name((opts) => {
8618
+ const { transactionId, outputs, baseAssetId } = opts;
8619
+ const outputChangeIndex = outputs.findIndex(
8620
+ (output) => output.type === OutputType9.Change && output.assetId === baseAssetId
8621
+ );
8622
+ if (outputChangeIndex === -1) {
8623
+ throw new FuelError21(ErrorCode19.UNKNOWN, "No change output found");
8624
+ }
8625
+ const outputCoin = outputs[outputChangeIndex];
8626
+ const outputIndexPadded = Number(outputChangeIndex).toString().padStart(4, "0");
8627
+ return {
8628
+ id: `${transactionId}${outputIndexPadded}`,
8629
+ assetId: outputCoin.assetId,
8630
+ amount: outputCoin.amount,
8631
+ owner: new Address3(outputCoin.to),
8632
+ blockCreated: bn21(0),
8633
+ txCreatedIdx: bn21(0)
8634
+ };
8635
+ }, "createOuputCoin");
8636
+ var consolidateCoins = /* @__PURE__ */ __name(async ({
8637
+ account,
8638
+ assetId
8639
+ }) => {
8640
+ const chainInfo = await account.provider.getChain();
8641
+ const chainId = chainInfo.consensusParameters.chainId.toNumber();
8642
+ const gasPrice = await account.provider.estimateGasPrice(10);
8643
+ const maxInputs = chainInfo.consensusParameters.txParameters.maxInputs.toNumber();
8644
+ const baseAssetId = await account.provider.getBaseAssetId();
8645
+ const isBaseAsset = assetId === baseAssetId;
8646
+ const batchSize = maxInputs;
8647
+ const numberOfFundingCoins = maxInputs;
8648
+ let funding = [];
8649
+ let dust = [];
8650
+ if (isBaseAsset) {
8651
+ const coins = await getAllCoins(account, baseAssetId).then(sortCoins);
8652
+ funding = coins.slice(0, numberOfFundingCoins);
8653
+ dust = coins.slice(numberOfFundingCoins);
8654
+ } else {
8655
+ funding = await getAllCoins(account, baseAssetId).then(sortCoins).then((coins) => coins.slice(0, numberOfFundingCoins));
8656
+ dust = await getAllCoins(account, assetId).then(({ coins }) => coins);
8657
+ }
8658
+ if (funding.length === 0) {
8659
+ throw new FuelError21(
8660
+ ErrorCode19.INSUFFICIENT_FUNDS,
8661
+ `Insufficient funds to consolidate.
8662
+ Asset ID: ${baseAssetId}
8663
+ Owner: ${account.address.toB256()}`
8664
+ );
8665
+ }
8666
+ const batches = [
8667
+ ...splitEvery(batchSize, funding),
8668
+ // We leave one coin for the funding coin
8669
+ ...splitEvery(batchSize - 1, dust)
8670
+ ];
8671
+ const txs = batches.map((batch) => {
8672
+ const request2 = new ScriptTransactionRequest({
8673
+ scriptData: "0x"
8674
+ });
8675
+ request2.addResources(batch);
8676
+ return request2;
8677
+ });
8678
+ const submitAll = /* @__PURE__ */ __name(async (opts = {}) => {
8679
+ const txResponses = [];
8680
+ let previousTx;
8681
+ for (let i = 0; i < txs.length; i++) {
8682
+ let currentTx = txs[i];
8683
+ const step = i + 1;
8684
+ if (previousTx) {
8685
+ const coin = createOuputCoin({
8686
+ transactionId: previousTx.transactionId,
8687
+ outputs: previousTx.outputs,
8688
+ baseAssetId
8689
+ });
8690
+ currentTx.addResource(coin);
8691
+ }
8692
+ if ("populateTransactionPredicateData" in account && typeof account.populateTransactionPredicateData === "function") {
8693
+ currentTx = account.populateTransactionPredicateData(currentTx);
8694
+ currentTx = await account.provider.estimatePredicates(currentTx);
8695
+ }
8696
+ const fee = calculateGasFee({
8697
+ gasPrice,
8698
+ gas: currentTx.calculateMinGas(chainInfo),
8699
+ priceFactor: chainInfo.consensusParameters.feeParameters.gasPriceFactor,
8700
+ tip: currentTx.tip
8701
+ });
8702
+ currentTx.maxFee = fee;
8703
+ currentTx.gasLimit = bn21(1e3);
8704
+ opts.onTransactionStart?.({
8705
+ tx: currentTx,
8706
+ step,
8707
+ assetId,
8708
+ transactionId: currentTx.getTransactionId(chainId)
8709
+ });
8710
+ const response = await account.sendTransaction(currentTx);
8711
+ const result = await response.waitForResult();
8712
+ txResponses.push(result);
8713
+ previousTx = {
8714
+ transactionId: response.id,
8715
+ outputs: result.transaction.outputs
8716
+ };
8717
+ }
8718
+ return {
8719
+ txResponses,
8720
+ errors: []
8721
+ };
8722
+ }, "submitAll");
8723
+ return {
8724
+ txs,
8725
+ totalFeeCost: txs.reduce((acc, request2) => acc.add(request2.maxFee), bn21(0)),
8726
+ submitAll
8727
+ };
8728
+ }, "consolidateCoins");
8729
+
8379
8730
  // src/utils/formatTransferToContractScriptData.ts
8380
8731
  import { ASSET_ID_LEN, BigNumberCoder as BigNumberCoder3, CONTRACT_ID_LEN, WORD_SIZE } from "@fuel-ts/abi-coder";
8381
- import { Address as Address3 } from "@fuel-ts/address";
8382
- import { arrayify as arrayify15, concat as concat3 } from "@fuel-ts/utils";
8732
+ import { Address as Address4 } from "@fuel-ts/address";
8733
+ import { arrayify as arrayify16, concat as concat4 } from "@fuel-ts/utils";
8383
8734
  import * as asm from "@fuels/vm-asm";
8384
8735
  var formatTransferToContractScriptData = /* @__PURE__ */ __name((transferParams) => {
8385
8736
  const numberCoder = new BigNumberCoder3("u64");
8386
8737
  return transferParams.reduce((acc, transferParam) => {
8387
8738
  const { assetId, amount, contractId } = transferParam;
8388
8739
  const encoded = numberCoder.encode(amount);
8389
- const scriptData = concat3([new Address3(contractId).toBytes(), encoded, arrayify15(assetId)]);
8390
- return concat3([acc, scriptData]);
8740
+ const scriptData = concat4([new Address4(contractId).toBytes(), encoded, arrayify16(assetId)]);
8741
+ return concat4([acc, scriptData]);
8391
8742
  }, new Uint8Array());
8392
8743
  }, "formatTransferToContractScriptData");
8393
8744
  var assembleTransferToContractScript = /* @__PURE__ */ __name(async (transferParams) => {
@@ -8396,7 +8747,7 @@ var assembleTransferToContractScript = /* @__PURE__ */ __name(async (transferPar
8396
8747
  let script = new Uint8Array();
8397
8748
  transferParams.forEach((_, i) => {
8398
8749
  const offset = (CONTRACT_ID_LEN + WORD_SIZE + ASSET_ID_LEN) * i;
8399
- script = concat3([
8750
+ script = concat4([
8400
8751
  script,
8401
8752
  // Load ScriptData into register 0x10.
8402
8753
  asm.gtf(16, 0, asm.GTFArgs.ScriptData).to_bytes(),
@@ -8412,7 +8763,7 @@ var assembleTransferToContractScript = /* @__PURE__ */ __name(async (transferPar
8412
8763
  asm.tr(17, 19, 20).to_bytes()
8413
8764
  ]);
8414
8765
  });
8415
- script = concat3([script, asm.ret(1).to_bytes()]);
8766
+ script = concat4([script, asm.ret(1).to_bytes()]);
8416
8767
  return { script, scriptData };
8417
8768
  }, "assembleTransferToContractScript");
8418
8769
 
@@ -8457,7 +8808,7 @@ var Account = class extends AbstractAccount {
8457
8808
  super();
8458
8809
  this._provider = provider;
8459
8810
  this._connector = connector;
8460
- this.address = new Address4(address);
8811
+ this.address = new Address5(address);
8461
8812
  }
8462
8813
  /**
8463
8814
  * The provider used to interact with the network.
@@ -8468,7 +8819,7 @@ var Account = class extends AbstractAccount {
8468
8819
  */
8469
8820
  get provider() {
8470
8821
  if (!this._provider) {
8471
- throw new FuelError21(ErrorCode19.MISSING_PROVIDER, "Provider not set");
8822
+ throw new FuelError22(ErrorCode20.MISSING_PROVIDER, "Provider not set");
8472
8823
  }
8473
8824
  return this._provider;
8474
8825
  }
@@ -8495,10 +8846,24 @@ var Account = class extends AbstractAccount {
8495
8846
  *
8496
8847
  * @param quantities - Quantities of resources to be obtained.
8497
8848
  * @param resourcesIdsToIgnore - IDs of resources to be excluded from the query (optional).
8849
+ * @param skipAutoConsolidation - Whether to skip the automatic consolidatation of coins process (optional).
8498
8850
  * @returns A promise that resolves to an array of Resources.
8499
8851
  */
8500
- async getResourcesToSpend(quantities, resourcesIdsToIgnore) {
8501
- return this.provider.getResourcesToSpend(this.address, quantities, resourcesIdsToIgnore);
8852
+ async getResourcesToSpend(quantities, resourcesIdsToIgnore, { skipAutoConsolidation } = {}) {
8853
+ const getResourcesToSpend = /* @__PURE__ */ __name(() => this.provider.getResourcesToSpend(this.address, quantities, resourcesIdsToIgnore), "getResourcesToSpend");
8854
+ try {
8855
+ return await getResourcesToSpend();
8856
+ } catch (error) {
8857
+ const shouldRetry = await consolidateCoinsIfRequired({
8858
+ error,
8859
+ account: this,
8860
+ skipAutoConsolidation
8861
+ });
8862
+ if (!shouldRetry) {
8863
+ throw error;
8864
+ }
8865
+ return await getResourcesToSpend();
8866
+ }
8502
8867
  }
8503
8868
  /**
8504
8869
  * Retrieves coins owned by the account.
@@ -8547,7 +8912,7 @@ var Account = class extends AbstractAccount {
8547
8912
  * @deprecated Use provider.assembleTx instead
8548
8913
  * Check the migration guide https://docs.fuel.network/docs/fuels-ts/transactions/assemble-tx-migration-guide/ for more information.
8549
8914
  */
8550
- async fund(request2, params) {
8915
+ async fund(request2, params, { skipAutoConsolidation } = {}) {
8551
8916
  const {
8552
8917
  addedSignatures,
8553
8918
  estimatedPredicates,
@@ -8559,9 +8924,9 @@ var Account = class extends AbstractAccount {
8559
8924
  const chainId = await this.provider.getChainId();
8560
8925
  const fee = request2.maxFee;
8561
8926
  const baseAssetId = await this.provider.getBaseAssetId();
8562
- const requiredInBaseAsset = requiredQuantities.find((quantity) => quantity.assetId === baseAssetId)?.amount || bn21(0);
8927
+ const requiredInBaseAsset = requiredQuantities.find((quantity) => quantity.assetId === baseAssetId)?.amount || bn22(0);
8563
8928
  const requiredQuantitiesWithFee = addAmountToCoinQuantities({
8564
- amount: bn21(fee),
8929
+ amount: bn22(fee),
8565
8930
  assetId: baseAssetId,
8566
8931
  coinQuantities: requiredQuantities
8567
8932
  });
@@ -8569,7 +8934,7 @@ var Account = class extends AbstractAccount {
8569
8934
  requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
8570
8935
  quantitiesDict[assetId] = {
8571
8936
  required: amount,
8572
- owned: bn21(0)
8937
+ owned: bn22(0)
8573
8938
  };
8574
8939
  });
8575
8940
  request2.inputs.filter(isRequestInputResource).forEach((input) => {
@@ -8593,7 +8958,8 @@ var Account = class extends AbstractAccount {
8593
8958
  while (needsToBeFunded && fundingAttempts < MAX_FUNDING_ATTEMPTS) {
8594
8959
  const resources = await this.getResourcesToSpend(
8595
8960
  missingQuantities,
8596
- cacheRequestInputsResourcesFromOwner(request2.inputs, this.address)
8961
+ cacheRequestInputsResourcesFromOwner(request2.inputs, this.address),
8962
+ { skipAutoConsolidation }
8597
8963
  );
8598
8964
  request2.addResources(resources);
8599
8965
  request2.updatePredicateGasUsed(estimatedPredicates);
@@ -8630,8 +8996,8 @@ var Account = class extends AbstractAccount {
8630
8996
  fundingAttempts += 1;
8631
8997
  }
8632
8998
  if (needsToBeFunded) {
8633
- throw new FuelError21(
8634
- ErrorCode19.INSUFFICIENT_FUNDS_OR_MAX_COINS,
8999
+ throw new FuelError22(
9000
+ ErrorCode20.INSUFFICIENT_FUNDS,
8635
9001
  `The account ${this.address} does not have enough base asset funds to cover the transaction execution.`
8636
9002
  );
8637
9003
  }
@@ -8659,16 +9025,20 @@ var Account = class extends AbstractAccount {
8659
9025
  * @param amount - The amount of coins to transfer.
8660
9026
  * @param assetId - The asset ID of the coins to transfer (optional).
8661
9027
  * @param txParams - The transaction parameters (optional).
9028
+ * @param skipAutoConsolidation - Whether to skip the automatic consolidatation of coins process (optional).
8662
9029
  * @returns A promise that resolves to the prepared transaction request.
8663
9030
  */
8664
- async createTransfer(destination, amount, assetId, txParams = {}) {
9031
+ async createTransfer(destination, amount, assetId, txParams = {}, { skipAutoConsolidation } = {}) {
8665
9032
  let request2 = new ScriptTransactionRequest(txParams);
8666
9033
  request2 = this.addTransfer(request2, {
8667
9034
  destination,
8668
9035
  amount,
8669
9036
  assetId: assetId || await this.provider.getBaseAssetId()
8670
9037
  });
8671
- const { gasPrice, transactionRequest } = await this.assembleTx(request2);
9038
+ const { gasPrice, transactionRequest } = await this.assembleTx({
9039
+ transactionRequest: request2,
9040
+ skipAutoConsolidation
9041
+ });
8672
9042
  request2 = await setAndValidateGasAndFeeForAssembledTx({
8673
9043
  gasPrice,
8674
9044
  provider: this.provider,
@@ -8685,10 +9055,13 @@ var Account = class extends AbstractAccount {
8685
9055
  * @param amount - The amount of coins to transfer.
8686
9056
  * @param assetId - The asset ID of the coins to transfer (optional).
8687
9057
  * @param txParams - The transaction parameters (optional).
9058
+ * @param skipAutoConsolidation - Whether to skip the automatic consolidatation of coins process (optional).
8688
9059
  * @returns A promise that resolves to the transaction response.
8689
9060
  */
8690
- async transfer(destination, amount, assetId, txParams = {}) {
8691
- const request2 = await this.createTransfer(destination, amount, assetId, txParams);
9061
+ async transfer(destination, amount, assetId, txParams = {}, { skipAutoConsolidation } = {}) {
9062
+ const request2 = await this.createTransfer(destination, amount, assetId, txParams, {
9063
+ skipAutoConsolidation
9064
+ });
8692
9065
  return this.sendTransaction(request2, { estimateTxDependencies: false });
8693
9066
  }
8694
9067
  /**
@@ -8696,12 +9069,16 @@ var Account = class extends AbstractAccount {
8696
9069
  *
8697
9070
  * @param transferParams - An array of `TransferParams` objects representing the transfers to be made.
8698
9071
  * @param txParams - Optional transaction parameters.
9072
+ * @param skipAutoConsolidation - Whether to skip the automatic consolidatation of coins process (optional).
8699
9073
  * @returns A promise that resolves to a `TransactionResponse` object representing the transaction result.
8700
9074
  */
8701
- async batchTransfer(transferParams, txParams = {}) {
9075
+ async batchTransfer(transferParams, txParams = {}, { skipAutoConsolidation } = {}) {
8702
9076
  let request2 = new ScriptTransactionRequest(txParams);
8703
9077
  request2 = this.addBatchTransfer(request2, transferParams);
8704
- const { gasPrice, transactionRequest } = await this.assembleTx(request2);
9078
+ const { gasPrice, transactionRequest } = await this.assembleTx({
9079
+ transactionRequest: request2,
9080
+ skipAutoConsolidation
9081
+ });
8705
9082
  request2 = await setAndValidateGasAndFeeForAssembledTx({
8706
9083
  gasPrice,
8707
9084
  provider: this.provider,
@@ -8721,7 +9098,7 @@ var Account = class extends AbstractAccount {
8721
9098
  addTransfer(request2, transferParams) {
8722
9099
  const { destination, amount, assetId } = transferParams;
8723
9100
  this.validateTransferAmount(amount);
8724
- request2.addCoinOutput(new Address4(destination), amount, assetId);
9101
+ request2.addCoinOutput(new Address5(destination), amount, assetId);
8725
9102
  return request2;
8726
9103
  }
8727
9104
  /**
@@ -8748,24 +9125,27 @@ var Account = class extends AbstractAccount {
8748
9125
  * @param amount - The amount of coins to transfer.
8749
9126
  * @param assetId - The asset ID of the coins to transfer (optional).
8750
9127
  * @param txParams - The transaction parameters (optional).
9128
+ * @param skipAutoConsolidation - Whether to skip the automatic consolidatation of coins process (optional).
8751
9129
  * @returns A promise that resolves to the transaction response.
8752
9130
  */
8753
- async transferToContract(contractId, amount, assetId, txParams = {}) {
8754
- return this.batchTransferToContracts([{ amount, assetId, contractId }], txParams);
9131
+ async transferToContract(contractId, amount, assetId, txParams = {}, { skipAutoConsolidation } = {}) {
9132
+ return this.batchTransferToContracts([{ amount, assetId, contractId }], txParams, {
9133
+ skipAutoConsolidation
9134
+ });
8755
9135
  }
8756
- async batchTransferToContracts(contractTransferParams, txParams = {}) {
9136
+ async batchTransferToContracts(contractTransferParams, txParams = {}, { skipAutoConsolidation } = {}) {
8757
9137
  let request2 = new ScriptTransactionRequest({
8758
9138
  ...txParams
8759
9139
  });
8760
9140
  const quantities = [];
8761
9141
  const defaultAssetId = await this.provider.getBaseAssetId();
8762
9142
  const transferParams = contractTransferParams.map((transferParam) => {
8763
- const amount = bn21(transferParam.amount);
8764
- const contractAddress = new Address4(transferParam.contractId);
9143
+ const amount = bn22(transferParam.amount);
9144
+ const contractAddress = new Address5(transferParam.contractId);
8765
9145
  const assetId = transferParam.assetId ? hexlify18(transferParam.assetId) : defaultAssetId;
8766
9146
  if (amount.lte(0)) {
8767
- throw new FuelError21(
8768
- ErrorCode19.INVALID_TRANSFER_AMOUNT,
9147
+ throw new FuelError22(
9148
+ ErrorCode20.INVALID_TRANSFER_AMOUNT,
8769
9149
  "Transfer amount must be a positive number."
8770
9150
  );
8771
9151
  }
@@ -8780,7 +9160,11 @@ var Account = class extends AbstractAccount {
8780
9160
  const { script, scriptData } = await assembleTransferToContractScript(transferParams);
8781
9161
  request2.script = script;
8782
9162
  request2.scriptData = scriptData;
8783
- const { gasPrice, transactionRequest } = await this.assembleTx(request2, quantities);
9163
+ const { gasPrice, transactionRequest } = await this.assembleTx({
9164
+ transactionRequest: request2,
9165
+ quantities,
9166
+ skipAutoConsolidation
9167
+ });
8784
9168
  request2 = await setAndValidateGasAndFeeForAssembledTx({
8785
9169
  gasPrice,
8786
9170
  provider: this.provider,
@@ -8796,26 +9180,31 @@ var Account = class extends AbstractAccount {
8796
9180
  * @param recipient - Address of the recipient on the base chain.
8797
9181
  * @param amount - Amount of base asset.
8798
9182
  * @param txParams - The transaction parameters (optional).
9183
+ * @param skipAutoConsolidation - Whether to skip the automatic consolidatation of coins process (optional).
8799
9184
  * @returns A promise that resolves to the transaction response.
8800
9185
  */
8801
- async withdrawToBaseLayer(recipient, amount, txParams = {}) {
8802
- const recipientAddress = new Address4(recipient);
8803
- const recipientDataArray = arrayify16(
9186
+ async withdrawToBaseLayer(recipient, amount, txParams = {}, { skipAutoConsolidation } = {}) {
9187
+ const recipientAddress = new Address5(recipient);
9188
+ const recipientDataArray = arrayify17(
8804
9189
  "0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
8805
9190
  );
8806
- const amountDataArray = arrayify16(
8807
- "0x".concat(bn21(amount).toHex().substring(2).padStart(16, "0"))
9191
+ const amountDataArray = arrayify17(
9192
+ "0x".concat(bn22(amount).toHex().substring(2).padStart(16, "0"))
8808
9193
  );
8809
9194
  const script = new Uint8Array([
8810
- ...arrayify16(withdrawScript.bytes),
9195
+ ...arrayify17(withdrawScript.bytes),
8811
9196
  ...recipientDataArray,
8812
9197
  ...amountDataArray
8813
9198
  ]);
8814
9199
  const params = { script, ...txParams };
8815
9200
  const baseAssetId = await this.provider.getBaseAssetId();
8816
9201
  let request2 = new ScriptTransactionRequest(params);
8817
- const quantities = [{ amount: bn21(amount), assetId: baseAssetId }];
8818
- const { gasPrice, transactionRequest } = await this.assembleTx(request2, quantities);
9202
+ const quantities = [{ amount: bn22(amount), assetId: baseAssetId }];
9203
+ const { gasPrice, transactionRequest } = await this.assembleTx({
9204
+ transactionRequest: request2,
9205
+ quantities,
9206
+ skipAutoConsolidation
9207
+ });
8819
9208
  request2 = await setAndValidateGasAndFeeForAssembledTx({
8820
9209
  gasPrice,
8821
9210
  provider: this.provider,
@@ -8825,6 +9214,25 @@ var Account = class extends AbstractAccount {
8825
9214
  });
8826
9215
  return this.sendTransaction(request2);
8827
9216
  }
9217
+ /**
9218
+ * Start the consolidation process
9219
+ *
9220
+ * @param owner - The B256 address of the owner.
9221
+ * @param assetId - The asset ID that requires consolidation.
9222
+ */
9223
+ async startConsolidation(opts) {
9224
+ if (this._connector) {
9225
+ await this._connector.startConsolidation(opts);
9226
+ return false;
9227
+ }
9228
+ const { owner, assetId } = opts;
9229
+ if (owner !== this.address.toB256()) {
9230
+ return false;
9231
+ }
9232
+ const { submitAll } = await consolidateCoins({ account: this, assetId });
9233
+ await submitAll();
9234
+ return true;
9235
+ }
8828
9236
  /**
8829
9237
  * Consolidates base asset UTXOs into fewer, larger ones.
8830
9238
  *
@@ -8844,6 +9252,7 @@ var Account = class extends AbstractAccount {
8844
9252
  const isBaseAsset = baseAssetId === assetId;
8845
9253
  let submitAll;
8846
9254
  const consolidationParams = {
9255
+ assetId,
8847
9256
  coins,
8848
9257
  mode: params.mode,
8849
9258
  outputNum: params.outputNum
@@ -8851,10 +9260,7 @@ var Account = class extends AbstractAccount {
8851
9260
  if (isBaseAsset) {
8852
9261
  ({ submitAll } = await this.assembleBaseAssetConsolidationTxs(consolidationParams));
8853
9262
  } else {
8854
- throw new FuelError21(
8855
- ErrorCode19.UNSUPPORTED_FEATURE,
8856
- "Consolidation for non-base assets is not supported yet."
8857
- );
9263
+ ({ submitAll } = await this.assembleNonBaseAssetConsolidationTxs(consolidationParams));
8858
9264
  }
8859
9265
  return submitAll();
8860
9266
  }
@@ -8875,7 +9281,7 @@ var Account = class extends AbstractAccount {
8875
9281
  this.validateConsolidationTxsCoins(coins, baseAssetId);
8876
9282
  const chainInfo = await this.provider.getChain();
8877
9283
  const maxInputsNumber = chainInfo.consensusParameters.txParameters.maxInputs.toNumber();
8878
- let totalFeeCost = bn21(0);
9284
+ let totalFeeCost = bn22(0);
8879
9285
  const txs = [];
8880
9286
  const coinsBatches = splitCoinsIntoBatches(coins, maxInputsNumber);
8881
9287
  const gasPrice = await this.provider.estimateGasPrice(10);
@@ -8899,10 +9305,10 @@ var Account = class extends AbstractAccount {
8899
9305
  });
8900
9306
  request2.maxFee = fee;
8901
9307
  if (consolidateMoreThanOneCoin) {
8902
- const total = request2.inputs.filter(isRequestInputCoin).reduce((acc, input) => acc.add(input.amount), bn21(0));
9308
+ const total = request2.inputs.filter(isRequestInputCoin).reduce((acc, input) => acc.add(input.amount), bn22(0));
8903
9309
  const amountPerNewUtxo = total.div(outputNum + 1);
8904
9310
  request2.outputs.forEach((output) => {
8905
- if (output.type === OutputType9.Coin) {
9311
+ if (output.type === OutputType10.Coin) {
8906
9312
  output.amount = amountPerNewUtxo;
8907
9313
  }
8908
9314
  });
@@ -8913,6 +9319,70 @@ var Account = class extends AbstractAccount {
8913
9319
  const submitAll = this.prepareSubmitAll({ txs, mode });
8914
9320
  return { txs, totalFeeCost, submitAll };
8915
9321
  }
9322
+ async assembleNonBaseAssetConsolidationTxs(params) {
9323
+ const { assetId, coins, mode = "parallel", outputNum = 1 } = params;
9324
+ this.validateConsolidationTxsCoins(coins, assetId);
9325
+ const chainInfo = await this.provider.getChain();
9326
+ const maxInputsNumber = chainInfo.consensusParameters.txParameters.maxInputs.toNumber();
9327
+ const baseAssetId = chainInfo.consensusParameters.baseAssetId;
9328
+ const { coins: baseAssetCoins } = await this.provider.getCoins(this.address, baseAssetId);
9329
+ let totalFeeCost = bn22(0);
9330
+ const txs = [];
9331
+ const gasPrice = await this.provider.estimateGasPrice(10);
9332
+ const consolidateMoreThanOneCoin = outputNum > 1;
9333
+ const assetCoinBatches = splitCoinsIntoBatches(coins, maxInputsNumber);
9334
+ assetCoinBatches.filter((batch) => batch.length > 1).forEach((coinBatch) => {
9335
+ const request2 = new ScriptTransactionRequest({
9336
+ script: "0x"
9337
+ });
9338
+ request2.addResources(coinBatch);
9339
+ if (consolidateMoreThanOneCoin) {
9340
+ Array.from({ length: outputNum - 1 }).forEach(() => {
9341
+ request2.addCoinOutput(this.address, 0, assetId);
9342
+ });
9343
+ }
9344
+ const minGas = request2.calculateMinGas(chainInfo);
9345
+ const fee = calculateGasFee({
9346
+ gasPrice,
9347
+ gas: minGas,
9348
+ priceFactor: chainInfo.consensusParameters.feeParameters.gasPriceFactor,
9349
+ tip: request2.tip
9350
+ });
9351
+ request2.maxFee = fee;
9352
+ if (consolidateMoreThanOneCoin) {
9353
+ const total = request2.inputs.filter(isRequestInputCoin).reduce((acc, input) => acc.add(input.amount), bn22(0));
9354
+ const amountPerNewUtxo = total.div(outputNum + 1);
9355
+ request2.outputs.forEach((output) => {
9356
+ if (output.type === OutputType10.Coin) {
9357
+ output.amount = amountPerNewUtxo;
9358
+ }
9359
+ });
9360
+ }
9361
+ totalFeeCost = totalFeeCost.add(fee);
9362
+ const baseAssetResources = [];
9363
+ let fundingFeeTotal = bn22(0);
9364
+ while (fundingFeeTotal.lt(fee)) {
9365
+ const baseAssetCoin = baseAssetCoins.pop();
9366
+ if (!baseAssetCoin) {
9367
+ break;
9368
+ }
9369
+ baseAssetResources.push(baseAssetCoin);
9370
+ fundingFeeTotal = fundingFeeTotal.add(baseAssetCoin.amount);
9371
+ }
9372
+ const { inputs } = request2;
9373
+ request2.inputs = inputs.slice(0, maxInputsNumber - baseAssetResources.length);
9374
+ const removedCoins = coinBatch.slice(maxInputsNumber - baseAssetResources.length);
9375
+ request2.addResources(baseAssetResources);
9376
+ const lastCoinBatch = assetCoinBatches[assetCoinBatches.length - 1];
9377
+ lastCoinBatch.push(...removedCoins);
9378
+ if (lastCoinBatch.length > maxInputsNumber) {
9379
+ assetCoinBatches.push(lastCoinBatch.slice(maxInputsNumber));
9380
+ }
9381
+ txs.push(request2);
9382
+ });
9383
+ const submitAll = this.prepareSubmitAll({ txs, mode });
9384
+ return { txs, totalFeeCost, submitAll };
9385
+ }
8916
9386
  /**
8917
9387
  * Prepares a function to submit all transactions either sequentially or in parallel.
8918
9388
  *
@@ -8971,7 +9441,7 @@ var Account = class extends AbstractAccount {
8971
9441
  const baseAssetId = await this.provider.getBaseAssetId();
8972
9442
  const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
8973
9443
  const requiredQuantities = mergeQuantities(coinOutputsQuantities, quantities);
8974
- const transactionFeeForDryRun = [{ assetId: baseAssetId, amount: bn21("100000000000000000") }];
9444
+ const transactionFeeForDryRun = [{ assetId: baseAssetId, amount: bn22("100000000000000000") }];
8975
9445
  const findAssetInput = /* @__PURE__ */ __name((assetId) => txRequestClone.inputs.find((input) => {
8976
9446
  if (input.type === InputType8.Coin) {
8977
9447
  return input.assetId === assetId;
@@ -9019,7 +9489,7 @@ var Account = class extends AbstractAccount {
9019
9489
  */
9020
9490
  async signMessage(message) {
9021
9491
  if (!this._connector) {
9022
- throw new FuelError21(ErrorCode19.MISSING_CONNECTOR, "A connector is required to sign messages.");
9492
+ throw new FuelError22(ErrorCode20.MISSING_CONNECTOR, "A connector is required to sign messages.");
9023
9493
  }
9024
9494
  return this._connector.signMessage(this.address.toString(), message);
9025
9495
  }
@@ -9031,8 +9501,8 @@ var Account = class extends AbstractAccount {
9031
9501
  */
9032
9502
  async signTransaction(transactionRequestLike, connectorOptions = {}) {
9033
9503
  if (!this._connector) {
9034
- throw new FuelError21(
9035
- ErrorCode19.MISSING_CONNECTOR,
9504
+ throw new FuelError22(
9505
+ ErrorCode20.MISSING_CONNECTOR,
9036
9506
  "A connector is required to sign transactions."
9037
9507
  );
9038
9508
  }
@@ -9099,8 +9569,8 @@ var Account = class extends AbstractAccount {
9099
9569
  return coins.map((coin) => ({
9100
9570
  id: hexlify18(randomBytes2(UTXO_ID_LEN3)),
9101
9571
  owner: this.address,
9102
- blockCreated: bn21(1),
9103
- txCreatedIdx: bn21(1),
9572
+ blockCreated: bn22(1),
9573
+ txCreatedIdx: bn22(1),
9104
9574
  ...coin
9105
9575
  }));
9106
9576
  }
@@ -9127,73 +9597,50 @@ var Account = class extends AbstractAccount {
9127
9597
  } : void 0;
9128
9598
  }
9129
9599
  /** @hidden * */
9130
- async assembleTx(transactionRequest, quantities = []) {
9131
- const outputQuantities = transactionRequest.outputs.filter((o) => o.type === OutputType9.Coin).map(({ amount, assetId }) => ({ assetId: String(assetId), amount: bn21(amount) }));
9132
- transactionRequest.gasLimit = bn21(0);
9133
- transactionRequest.maxFee = bn21(0);
9134
- const { assembledRequest, gasPrice } = await this.provider.assembleTx({
9135
- request: transactionRequest,
9136
- accountCoinQuantities: mergeQuantities(outputQuantities, quantities),
9137
- feePayerAccount: this
9138
- });
9139
- return { transactionRequest: assembledRequest, gasPrice };
9600
+ async assembleTx(opts) {
9601
+ const { transactionRequest, quantities = [], skipAutoConsolidation } = opts;
9602
+ const outputQuantities = transactionRequest.outputs.filter((o) => o.type === OutputType10.Coin).map(({ amount, assetId }) => ({ assetId: String(assetId), amount: bn22(amount) }));
9603
+ transactionRequest.gasLimit = bn22(0);
9604
+ transactionRequest.maxFee = bn22(0);
9605
+ const assembleTx = /* @__PURE__ */ __name(async () => {
9606
+ const { assembledRequest, gasPrice } = await this.provider.assembleTx({
9607
+ request: transactionRequest,
9608
+ accountCoinQuantities: mergeQuantities(outputQuantities, quantities),
9609
+ feePayerAccount: this
9610
+ });
9611
+ return { transactionRequest: assembledRequest, gasPrice };
9612
+ }, "assembleTx");
9613
+ try {
9614
+ return await assembleTx();
9615
+ } catch (error) {
9616
+ const shouldRetry = await consolidateCoinsIfRequired({
9617
+ error,
9618
+ account: this,
9619
+ skipAutoConsolidation
9620
+ });
9621
+ if (!shouldRetry) {
9622
+ throw error;
9623
+ }
9624
+ return await assembleTx();
9625
+ }
9140
9626
  }
9141
9627
  /** @hidden * */
9142
9628
  validateTransferAmount(amount) {
9143
- if (bn21(amount).lte(0)) {
9144
- throw new FuelError21(
9145
- ErrorCode19.INVALID_TRANSFER_AMOUNT,
9629
+ if (bn22(amount).lte(0)) {
9630
+ throw new FuelError22(
9631
+ ErrorCode20.INVALID_TRANSFER_AMOUNT,
9146
9632
  "Transfer amount must be a positive number."
9147
9633
  );
9148
9634
  }
9149
9635
  }
9150
9636
  /** @hidden * */
9151
- async estimateAndFundTransaction(transactionRequest, txParams, costParams) {
9152
- let request2 = transactionRequest;
9153
- const txCost = await this.getTransactionCost(request2, costParams);
9154
- request2 = this.validateGasLimitAndMaxFee({
9155
- transactionRequest: request2,
9156
- gasUsed: txCost.gasUsed,
9157
- maxFee: txCost.maxFee,
9158
- txParams
9159
- });
9160
- request2 = await this.fund(request2, txCost);
9161
- return request2;
9162
- }
9163
- /** @hidden * */
9164
- validateGasLimitAndMaxFee({
9165
- gasUsed,
9166
- maxFee,
9167
- transactionRequest,
9168
- txParams: { gasLimit: setGasLimit, maxFee: setMaxFee }
9169
- }) {
9170
- const request2 = transactionRequestify(transactionRequest);
9171
- if (!isDefined4(setGasLimit)) {
9172
- request2.gasLimit = gasUsed;
9173
- } else if (gasUsed.gt(setGasLimit)) {
9174
- throw new FuelError21(
9175
- ErrorCode19.GAS_LIMIT_TOO_LOW,
9176
- `Gas limit '${setGasLimit}' is lower than the required: '${gasUsed}'.`
9177
- );
9178
- }
9179
- if (!isDefined4(setMaxFee)) {
9180
- request2.maxFee = maxFee;
9181
- } else if (maxFee.gt(setMaxFee)) {
9182
- throw new FuelError21(
9183
- ErrorCode19.MAX_FEE_TOO_LOW,
9184
- `Max fee '${setMaxFee}' is lower than the required: '${maxFee}'.`
9185
- );
9186
- }
9187
- return request2;
9188
- }
9189
- /** @hidden * */
9190
9637
  validateConsolidationTxsCoins(coins, assetId) {
9191
9638
  if (coins.length <= 1) {
9192
- throw new FuelError21(ErrorCode19.NO_COINS_TO_CONSOLIDATE, "No coins to consolidate.");
9639
+ throw new FuelError22(ErrorCode20.NO_COINS_TO_CONSOLIDATE, "No coins to consolidate.");
9193
9640
  }
9194
9641
  if (!coins.every((c) => c.assetId === assetId)) {
9195
- throw new FuelError21(
9196
- ErrorCode19.COINS_ASSET_ID_MISMATCH,
9642
+ throw new FuelError22(
9643
+ ErrorCode20.COINS_ASSET_ID_MISMATCH,
9197
9644
  "All coins to consolidate must be from the same asset id."
9198
9645
  );
9199
9646
  }
@@ -9222,11 +9669,11 @@ import { hashMessage } from "@fuel-ts/hasher";
9222
9669
  import { hexlify as hexlify21 } from "@fuel-ts/utils";
9223
9670
 
9224
9671
  // src/signer/signer.ts
9225
- import { Address as Address5 } from "@fuel-ts/address";
9672
+ import { Address as Address6 } from "@fuel-ts/address";
9226
9673
  import { randomBytes as randomBytes3 } from "@fuel-ts/crypto";
9227
9674
  import { hash as hash2 } from "@fuel-ts/hasher";
9228
- import { toBytes } from "@fuel-ts/math";
9229
- import { hexlify as hexlify19, concat as concat4, arrayify as arrayify17 } from "@fuel-ts/utils";
9675
+ import { toBytes as toBytes2 } from "@fuel-ts/math";
9676
+ import { hexlify as hexlify19, concat as concat5, arrayify as arrayify18 } from "@fuel-ts/utils";
9230
9677
  import { secp256k1 } from "@noble/curves/secp256k1";
9231
9678
  var Signer = class _Signer {
9232
9679
  static {
@@ -9248,11 +9695,11 @@ var Signer = class _Signer {
9248
9695
  privateKey = `0x${privateKey}`;
9249
9696
  }
9250
9697
  }
9251
- const privateKeyBytes = toBytes(privateKey, 32);
9698
+ const privateKeyBytes = toBytes2(privateKey, 32);
9252
9699
  this.privateKey = hexlify19(privateKeyBytes);
9253
9700
  this.publicKey = hexlify19(secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
9254
9701
  this.compressedPublicKey = hexlify19(secp256k1.getPublicKey(privateKeyBytes, true));
9255
- this.address = new Address5(this.publicKey);
9702
+ this.address = new Address6(this.publicKey);
9256
9703
  }
9257
9704
  /**
9258
9705
  * Sign data using the Signer instance
@@ -9265,11 +9712,11 @@ var Signer = class _Signer {
9265
9712
  * @returns hashed signature
9266
9713
  */
9267
9714
  sign(data) {
9268
- const signature = secp256k1.sign(arrayify17(data), arrayify17(this.privateKey));
9269
- const r = toBytes(`0x${signature.r.toString(16)}`, 32);
9270
- const s = toBytes(`0x${signature.s.toString(16)}`, 32);
9715
+ const signature = secp256k1.sign(arrayify18(data), arrayify18(this.privateKey));
9716
+ const r = toBytes2(`0x${signature.r.toString(16)}`, 32);
9717
+ const s = toBytes2(`0x${signature.s.toString(16)}`, 32);
9271
9718
  s[0] |= (signature.recovery || 0) << 7;
9272
- return hexlify19(concat4([r, s]));
9719
+ return hexlify19(concat5([r, s]));
9273
9720
  }
9274
9721
  /**
9275
9722
  * Add point on the current elliptic curve
@@ -9278,8 +9725,8 @@ var Signer = class _Signer {
9278
9725
  * @returns compressed point on the curve
9279
9726
  */
9280
9727
  addPoint(point) {
9281
- const p0 = secp256k1.ProjectivePoint.fromHex(arrayify17(this.compressedPublicKey));
9282
- const p1 = secp256k1.ProjectivePoint.fromHex(arrayify17(point));
9728
+ const p0 = secp256k1.ProjectivePoint.fromHex(arrayify18(this.compressedPublicKey));
9729
+ const p1 = secp256k1.ProjectivePoint.fromHex(arrayify18(point));
9283
9730
  const result = p0.add(p1);
9284
9731
  return `0x${result.toHex(true)}`;
9285
9732
  }
@@ -9291,7 +9738,7 @@ var Signer = class _Signer {
9291
9738
  * @returns public key from signature from the
9292
9739
  */
9293
9740
  static recoverPublicKey(data, signature) {
9294
- const signedMessageBytes = arrayify17(signature);
9741
+ const signedMessageBytes = arrayify18(signature);
9295
9742
  const r = signedMessageBytes.slice(0, 32);
9296
9743
  const s = signedMessageBytes.slice(32, 64);
9297
9744
  const recoveryParam = (s[0] & 128) >> 7;
@@ -9299,7 +9746,7 @@ var Signer = class _Signer {
9299
9746
  const sig = new secp256k1.Signature(BigInt(hexlify19(r)), BigInt(hexlify19(s))).addRecoveryBit(
9300
9747
  recoveryParam
9301
9748
  );
9302
- const publicKey = sig.recoverPublicKey(arrayify17(data)).toRawBytes(false).slice(1);
9749
+ const publicKey = sig.recoverPublicKey(arrayify18(data)).toRawBytes(false).slice(1);
9303
9750
  return hexlify19(publicKey);
9304
9751
  }
9305
9752
  /**
@@ -9310,7 +9757,7 @@ var Signer = class _Signer {
9310
9757
  * @returns Address from signature
9311
9758
  */
9312
9759
  static recoverAddress(data, signature) {
9313
- return new Address5(_Signer.recoverPublicKey(data, signature));
9760
+ return new Address6(_Signer.recoverPublicKey(data, signature));
9314
9761
  }
9315
9762
  /**
9316
9763
  * Generate a random privateKey
@@ -9319,7 +9766,7 @@ var Signer = class _Signer {
9319
9766
  * @returns random 32-byte hashed
9320
9767
  */
9321
9768
  static generatePrivateKey(entropy) {
9322
- return entropy ? hash2(concat4([randomBytes3(32), arrayify17(entropy)])) : randomBytes3(32);
9769
+ return entropy ? hash2(concat5([randomBytes3(32), arrayify18(entropy)])) : randomBytes3(32);
9323
9770
  }
9324
9771
  /**
9325
9772
  * Extended publicKey from a compact publicKey
@@ -9328,13 +9775,13 @@ var Signer = class _Signer {
9328
9775
  * @returns extended publicKey
9329
9776
  */
9330
9777
  static extendPublicKey(publicKey) {
9331
- const point = secp256k1.ProjectivePoint.fromHex(arrayify17(publicKey));
9778
+ const point = secp256k1.ProjectivePoint.fromHex(arrayify18(publicKey));
9332
9779
  return hexlify19(point.toRawBytes(false).slice(1));
9333
9780
  }
9334
9781
  };
9335
9782
 
9336
9783
  // src/wallet/keystore-wallet.ts
9337
- import { Address as Address6 } from "@fuel-ts/address";
9784
+ import { Address as Address7 } from "@fuel-ts/address";
9338
9785
  import {
9339
9786
  bufferFromString,
9340
9787
  keccak256,
@@ -9345,7 +9792,7 @@ import {
9345
9792
  encryptJsonWalletData,
9346
9793
  randomUUID
9347
9794
  } from "@fuel-ts/crypto";
9348
- import { ErrorCode as ErrorCode20, FuelError as FuelError22 } from "@fuel-ts/errors";
9795
+ import { ErrorCode as ErrorCode21, FuelError as FuelError23 } from "@fuel-ts/errors";
9349
9796
  import { hexlify as hexlify20 } from "@fuel-ts/utils";
9350
9797
  var DEFAULT_KDF_PARAMS_LOG_N = 13;
9351
9798
  var DEFAULT_KDF_PARAMS_R = 8;
@@ -9360,7 +9807,7 @@ var removeHexPrefix = /* @__PURE__ */ __name((hexString) => {
9360
9807
  }, "removeHexPrefix");
9361
9808
  async function encryptKeystoreWallet(privateKey, address, password) {
9362
9809
  const privateKeyBuffer = bufferFromString(removeHexPrefix(privateKey), "hex");
9363
- const ownerAddress = new Address6(address);
9810
+ const ownerAddress = new Address7(address);
9364
9811
  const salt = randomBytes4(DEFAULT_KEY_SIZE);
9365
9812
  const key = scrypt({
9366
9813
  password: bufferFromString(password),
@@ -9423,8 +9870,8 @@ async function decryptKeystoreWallet(jsonWallet, password) {
9423
9870
  const macHashUint8Array = keccak256(data);
9424
9871
  const macHash = stringFromBuffer(macHashUint8Array, "hex");
9425
9872
  if (mac !== macHash) {
9426
- throw new FuelError22(
9427
- ErrorCode20.INVALID_PASSWORD,
9873
+ throw new FuelError23(
9874
+ ErrorCode21.INVALID_PASSWORD,
9428
9875
  "Failed to decrypt the keystore wallet, the provided password is incorrect."
9429
9876
  );
9430
9877
  }
@@ -9563,16 +10010,16 @@ var BaseWalletUnlocked = class extends Account {
9563
10010
 
9564
10011
  // src/hdwallet/hdwallet.ts
9565
10012
  import { computeHmac as computeHmac2, ripemd160 } from "@fuel-ts/crypto";
9566
- import { ErrorCode as ErrorCode23, FuelError as FuelError25 } from "@fuel-ts/errors";
10013
+ import { ErrorCode as ErrorCode24, FuelError as FuelError26 } from "@fuel-ts/errors";
9567
10014
  import { sha256 as sha2564 } from "@fuel-ts/hasher";
9568
- import { bn as bn22, toBytes as toBytes2, toHex } from "@fuel-ts/math";
9569
- import { arrayify as arrayify20, hexlify as hexlify23, concat as concat6, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58 } from "@fuel-ts/utils";
10015
+ import { bn as bn23, toBytes as toBytes3, toHex } from "@fuel-ts/math";
10016
+ import { arrayify as arrayify21, hexlify as hexlify23, concat as concat7, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58 } from "@fuel-ts/utils";
9570
10017
 
9571
10018
  // src/mnemonic/mnemonic.ts
9572
10019
  import { randomBytes as randomBytes5, pbkdf2, computeHmac } from "@fuel-ts/crypto";
9573
- import { ErrorCode as ErrorCode22, FuelError as FuelError24 } from "@fuel-ts/errors";
10020
+ import { ErrorCode as ErrorCode23, FuelError as FuelError25 } from "@fuel-ts/errors";
9574
10021
  import { sha256 as sha2563 } from "@fuel-ts/hasher";
9575
- import { arrayify as arrayify19, hexlify as hexlify22, concat as concat5, dataSlice, encodeBase58, toUtf8Bytes } from "@fuel-ts/utils";
10022
+ import { arrayify as arrayify20, hexlify as hexlify22, concat as concat6, dataSlice, encodeBase58, toUtf8Bytes } from "@fuel-ts/utils";
9576
10023
 
9577
10024
  // src/wordlists/words/english.ts
9578
10025
  var english = [
@@ -11633,9 +12080,9 @@ var Language = /* @__PURE__ */ ((Language2) => {
11633
12080
  })(Language || {});
11634
12081
 
11635
12082
  // src/mnemonic/utils.ts
11636
- import { ErrorCode as ErrorCode21, FuelError as FuelError23 } from "@fuel-ts/errors";
12083
+ import { ErrorCode as ErrorCode22, FuelError as FuelError24 } from "@fuel-ts/errors";
11637
12084
  import { sha256 as sha2562 } from "@fuel-ts/hasher";
11638
- import { arrayify as arrayify18 } from "@fuel-ts/utils";
12085
+ import { arrayify as arrayify19 } from "@fuel-ts/utils";
11639
12086
  function getLowerMask(bits) {
11640
12087
  return (1 << bits) - 1;
11641
12088
  }
@@ -11674,7 +12121,7 @@ function entropyToMnemonicIndices(entropy) {
11674
12121
  }
11675
12122
  }
11676
12123
  const checksumBits = entropy.length / 4;
11677
- const checksum = arrayify18(sha2562(entropy))[0] & getUpperMask(checksumBits);
12124
+ const checksum = arrayify19(sha2562(entropy))[0] & getUpperMask(checksumBits);
11678
12125
  indices[indices.length - 1] <<= checksumBits;
11679
12126
  indices[indices.length - 1] |= checksum >> 8 - checksumBits;
11680
12127
  return indices;
@@ -11682,13 +12129,13 @@ function entropyToMnemonicIndices(entropy) {
11682
12129
  __name(entropyToMnemonicIndices, "entropyToMnemonicIndices");
11683
12130
  function mnemonicWordsToEntropy(words, wordlist) {
11684
12131
  const size = Math.ceil(11 * words.length / 8);
11685
- const entropy = arrayify18(new Uint8Array(size));
12132
+ const entropy = arrayify19(new Uint8Array(size));
11686
12133
  let offset = 0;
11687
12134
  for (let i = 0; i < words.length; i += 1) {
11688
12135
  const index = wordlist.indexOf(words[i].normalize("NFKD"));
11689
12136
  if (index === -1) {
11690
- throw new FuelError23(
11691
- ErrorCode21.INVALID_MNEMONIC,
12137
+ throw new FuelError24(
12138
+ ErrorCode22.INVALID_MNEMONIC,
11692
12139
  `Invalid mnemonic: the word '${words[i]}' is not found in the provided wordlist.`
11693
12140
  );
11694
12141
  }
@@ -11702,10 +12149,10 @@ function mnemonicWordsToEntropy(words, wordlist) {
11702
12149
  const entropyBits = 32 * words.length / 3;
11703
12150
  const checksumBits = words.length / 3;
11704
12151
  const checksumMask = getUpperMask(checksumBits);
11705
- const checksum = arrayify18(sha2562(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
12152
+ const checksum = arrayify19(sha2562(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
11706
12153
  if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
11707
- throw new FuelError23(
11708
- ErrorCode21.INVALID_CHECKSUM,
12154
+ throw new FuelError24(
12155
+ ErrorCode22.INVALID_CHECKSUM,
11709
12156
  "Checksum validation failed for the provided mnemonic."
11710
12157
  );
11711
12158
  }
@@ -11720,8 +12167,8 @@ var TestnetPRV = "0x04358394";
11720
12167
  var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
11721
12168
  function assertWordList(wordlist) {
11722
12169
  if (wordlist.length !== 2048) {
11723
- throw new FuelError24(
11724
- ErrorCode22.INVALID_WORD_LIST,
12170
+ throw new FuelError25(
12171
+ ErrorCode23.INVALID_WORD_LIST,
11725
12172
  `Expected word list length of 2048, but got ${wordlist.length}.`
11726
12173
  );
11727
12174
  }
@@ -11729,8 +12176,8 @@ function assertWordList(wordlist) {
11729
12176
  __name(assertWordList, "assertWordList");
11730
12177
  function assertEntropy(entropy) {
11731
12178
  if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {
11732
- throw new FuelError24(
11733
- ErrorCode22.INVALID_ENTROPY,
12179
+ throw new FuelError25(
12180
+ ErrorCode23.INVALID_ENTROPY,
11734
12181
  `Entropy should be between 16 and 32 bytes and a multiple of 4, but got ${entropy.length} bytes.`
11735
12182
  );
11736
12183
  }
@@ -11741,7 +12188,7 @@ function assertMnemonic(words) {
11741
12188
  const errorMsg = `Invalid mnemonic size. Expected one of [${MNEMONIC_SIZES.join(
11742
12189
  ", "
11743
12190
  )}] words, but got ${words.length}.`;
11744
- throw new FuelError24(ErrorCode22.INVALID_MNEMONIC, errorMsg);
12191
+ throw new FuelError25(ErrorCode23.INVALID_MNEMONIC, errorMsg);
11745
12192
  }
11746
12193
  }
11747
12194
  __name(assertMnemonic, "assertMnemonic");
@@ -11792,7 +12239,7 @@ var Mnemonic = class _Mnemonic {
11792
12239
  * @returns 64-byte array contains privateKey and chainCode as described on BIP39
11793
12240
  */
11794
12241
  static entropyToMnemonic(entropy, wordlist = english) {
11795
- const entropyBytes = arrayify19(entropy);
12242
+ const entropyBytes = arrayify20(entropy);
11796
12243
  assertWordList(wordlist);
11797
12244
  assertEntropy(entropyBytes);
11798
12245
  return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
@@ -11861,14 +12308,14 @@ var Mnemonic = class _Mnemonic {
11861
12308
  * @returns 64-byte array contains privateKey and chainCode as described on BIP39
11862
12309
  */
11863
12310
  static masterKeysFromSeed(seed) {
11864
- const seedArray = arrayify19(seed);
12311
+ const seedArray = arrayify20(seed);
11865
12312
  if (seedArray.length < 16 || seedArray.length > 64) {
11866
- throw new FuelError24(
11867
- ErrorCode22.INVALID_SEED,
12313
+ throw new FuelError25(
12314
+ ErrorCode23.INVALID_SEED,
11868
12315
  `Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
11869
12316
  );
11870
12317
  }
11871
- return arrayify19(computeHmac("sha512", MasterSecret, seedArray));
12318
+ return arrayify20(computeHmac("sha512", MasterSecret, seedArray));
11872
12319
  }
11873
12320
  /**
11874
12321
  * Get the extendKey as defined on BIP-32 from the provided seed
@@ -11879,22 +12326,22 @@ var Mnemonic = class _Mnemonic {
11879
12326
  */
11880
12327
  static seedToExtendedKey(seed, testnet = false) {
11881
12328
  const masterKey = _Mnemonic.masterKeysFromSeed(seed);
11882
- const prefix = arrayify19(testnet ? TestnetPRV : MainnetPRV);
12329
+ const prefix = arrayify20(testnet ? TestnetPRV : MainnetPRV);
11883
12330
  const depth = "0x00";
11884
12331
  const fingerprint = "0x00000000";
11885
12332
  const index = "0x00000000";
11886
12333
  const chainCode = masterKey.slice(32);
11887
12334
  const privateKey = masterKey.slice(0, 32);
11888
- const extendedKey = concat5([
12335
+ const extendedKey = concat6([
11889
12336
  prefix,
11890
12337
  depth,
11891
12338
  fingerprint,
11892
12339
  index,
11893
12340
  chainCode,
11894
- concat5(["0x00", privateKey])
12341
+ concat6(["0x00", privateKey])
11895
12342
  ]);
11896
12343
  const checksum = dataSlice(sha2563(sha2563(extendedKey)), 0, 4);
11897
- return encodeBase58(concat5([extendedKey, checksum]));
12344
+ return encodeBase58(concat6([extendedKey, checksum]));
11898
12345
  }
11899
12346
  /**
11900
12347
  * Create a new mnemonic using a randomly generated number as entropy.
@@ -11909,7 +12356,7 @@ var Mnemonic = class _Mnemonic {
11909
12356
  * @returns A randomly generated mnemonic
11910
12357
  */
11911
12358
  static generate(size = 32, extraEntropy = "") {
11912
- const entropy = extraEntropy ? sha2563(concat5([randomBytes5(size), arrayify19(extraEntropy)])) : randomBytes5(size);
12359
+ const entropy = extraEntropy ? sha2563(concat6([randomBytes5(size), arrayify20(extraEntropy)])) : randomBytes5(size);
11913
12360
  return _Mnemonic.entropyToMnemonic(entropy);
11914
12361
  }
11915
12362
  };
@@ -11922,7 +12369,7 @@ var MainnetPUB = hexlify23("0x0488b21e");
11922
12369
  var TestnetPRV2 = hexlify23("0x04358394");
11923
12370
  var TestnetPUB = hexlify23("0x043587cf");
11924
12371
  function base58check(data) {
11925
- return encodeBase582(concat6([data, dataSlice2(sha2564(sha2564(data)), 0, 4)]));
12372
+ return encodeBase582(concat7([data, dataSlice2(sha2564(sha2564(data)), 0, 4)]));
11926
12373
  }
11927
12374
  __name(base58check, "base58check");
11928
12375
  function getExtendedKeyPrefix(isPublic = false, testnet = false) {
@@ -11945,7 +12392,7 @@ __name(isValidExtendedKey, "isValidExtendedKey");
11945
12392
  function parsePath(path, depth = 0) {
11946
12393
  const components = path.split("/");
11947
12394
  if (components.length === 0 || components[0] === "m" && depth !== 0) {
11948
- throw new FuelError25(ErrorCode23.HD_WALLET_ERROR, `invalid path - ${path}`);
12395
+ throw new FuelError26(ErrorCode24.HD_WALLET_ERROR, `invalid path - ${path}`);
11949
12396
  }
11950
12397
  if (components[0] === "m") {
11951
12398
  components.shift();
@@ -11978,8 +12425,8 @@ var HDWallet = class _HDWallet {
11978
12425
  this.privateKey = hexlify23(config.privateKey);
11979
12426
  } else {
11980
12427
  if (!config.publicKey) {
11981
- throw new FuelError25(
11982
- ErrorCode23.HD_WALLET_ERROR,
12428
+ throw new FuelError26(
12429
+ ErrorCode24.HD_WALLET_ERROR,
11983
12430
  "Both public and private Key cannot be missing. At least one should be provided."
11984
12431
  );
11985
12432
  }
@@ -12002,28 +12449,28 @@ var HDWallet = class _HDWallet {
12002
12449
  * @returns A new instance of HDWallet on the derived index
12003
12450
  */
12004
12451
  deriveIndex(index) {
12005
- const privateKey = this.privateKey && arrayify20(this.privateKey);
12006
- const publicKey = arrayify20(this.publicKey);
12007
- const chainCode = arrayify20(this.chainCode);
12452
+ const privateKey = this.privateKey && arrayify21(this.privateKey);
12453
+ const publicKey = arrayify21(this.publicKey);
12454
+ const chainCode = arrayify21(this.chainCode);
12008
12455
  const data = new Uint8Array(37);
12009
12456
  if (index & HARDENED_INDEX) {
12010
12457
  if (!privateKey) {
12011
- throw new FuelError25(
12012
- ErrorCode23.HD_WALLET_ERROR,
12458
+ throw new FuelError26(
12459
+ ErrorCode24.HD_WALLET_ERROR,
12013
12460
  "Cannot derive a hardened index without a private Key."
12014
12461
  );
12015
12462
  }
12016
12463
  data.set(privateKey, 1);
12017
12464
  } else {
12018
- data.set(arrayify20(this.publicKey));
12465
+ data.set(arrayify21(this.publicKey));
12019
12466
  }
12020
- data.set(toBytes2(index, 4), 33);
12021
- const bytes = arrayify20(computeHmac2("sha512", chainCode, data));
12467
+ data.set(toBytes3(index, 4), 33);
12468
+ const bytes = arrayify21(computeHmac2("sha512", chainCode, data));
12022
12469
  const IL = bytes.slice(0, 32);
12023
12470
  const IR = bytes.slice(32);
12024
12471
  if (privateKey) {
12025
12472
  const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
12026
- const ki = bn22(IL).add(privateKey).mod(N).toBytes(32);
12473
+ const ki = bn23(IL).add(privateKey).mod(N).toBytes(32);
12027
12474
  return new _HDWallet({
12028
12475
  privateKey: ki,
12029
12476
  chainCode: IR,
@@ -12061,8 +12508,8 @@ var HDWallet = class _HDWallet {
12061
12508
  */
12062
12509
  toExtendedKey(isPublic = false, testnet = false) {
12063
12510
  if (this.depth >= 256) {
12064
- throw new FuelError25(
12065
- ErrorCode23.HD_WALLET_ERROR,
12511
+ throw new FuelError26(
12512
+ ErrorCode24.HD_WALLET_ERROR,
12066
12513
  `Exceeded max depth of 255. Current depth: ${this.depth}.`
12067
12514
  );
12068
12515
  }
@@ -12071,8 +12518,8 @@ var HDWallet = class _HDWallet {
12071
12518
  const parentFingerprint = this.parentFingerprint;
12072
12519
  const index = toHex(this.index, 4);
12073
12520
  const chainCode = this.chainCode;
12074
- const key = this.privateKey != null && !isPublic ? concat6(["0x00", this.privateKey]) : this.publicKey;
12075
- const extendedKey = arrayify20(concat6([prefix, depth, parentFingerprint, index, chainCode, key]));
12521
+ const key = this.privateKey != null && !isPublic ? concat7(["0x00", this.privateKey]) : this.publicKey;
12522
+ const extendedKey = arrayify21(concat7([prefix, depth, parentFingerprint, index, chainCode, key]));
12076
12523
  return base58check(extendedKey);
12077
12524
  }
12078
12525
  /**
@@ -12084,19 +12531,19 @@ var HDWallet = class _HDWallet {
12084
12531
  static fromSeed(seed) {
12085
12532
  const masterKey = mnemonic_default.masterKeysFromSeed(seed);
12086
12533
  return new _HDWallet({
12087
- chainCode: arrayify20(masterKey.slice(32)),
12088
- privateKey: arrayify20(masterKey.slice(0, 32))
12534
+ chainCode: arrayify21(masterKey.slice(32)),
12535
+ privateKey: arrayify21(masterKey.slice(0, 32))
12089
12536
  });
12090
12537
  }
12091
12538
  static fromExtendedKey(extendedKey) {
12092
- const decoded = hexlify23(toBytes2(decodeBase58(extendedKey)));
12093
- const bytes = arrayify20(decoded);
12539
+ const decoded = hexlify23(toBytes3(decodeBase58(extendedKey)));
12540
+ const bytes = arrayify21(decoded);
12094
12541
  const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
12095
12542
  if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
12096
- throw new FuelError25(ErrorCode23.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
12543
+ throw new FuelError26(ErrorCode24.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
12097
12544
  }
12098
12545
  if (!validChecksum) {
12099
- throw new FuelError25(ErrorCode23.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
12546
+ throw new FuelError26(ErrorCode24.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
12100
12547
  }
12101
12548
  const depth = bytes[4];
12102
12549
  const parentFingerprint = hexlify23(bytes.slice(5, 9));
@@ -12104,14 +12551,14 @@ var HDWallet = class _HDWallet {
12104
12551
  const chainCode = hexlify23(bytes.slice(13, 45));
12105
12552
  const key = bytes.slice(45, 78);
12106
12553
  if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
12107
- throw new FuelError25(
12108
- ErrorCode23.HD_WALLET_ERROR,
12554
+ throw new FuelError26(
12555
+ ErrorCode24.HD_WALLET_ERROR,
12109
12556
  "Inconsistency detected: Depth is zero but fingerprint/index is non-zero."
12110
12557
  );
12111
12558
  }
12112
12559
  if (isPublicExtendedKey(bytes)) {
12113
12560
  if (key[0] !== 3) {
12114
- throw new FuelError25(ErrorCode23.HD_WALLET_ERROR, "Invalid public extended key.");
12561
+ throw new FuelError26(ErrorCode24.HD_WALLET_ERROR, "Invalid public extended key.");
12115
12562
  }
12116
12563
  return new _HDWallet({
12117
12564
  publicKey: key,
@@ -12122,7 +12569,7 @@ var HDWallet = class _HDWallet {
12122
12569
  });
12123
12570
  }
12124
12571
  if (key[0] !== 0) {
12125
- throw new FuelError25(ErrorCode23.HD_WALLET_ERROR, "Invalid private extended key.");
12572
+ throw new FuelError26(ErrorCode24.HD_WALLET_ERROR, "Invalid private extended key.");
12126
12573
  }
12127
12574
  return new _HDWallet({
12128
12575
  privateKey: key.slice(1),
@@ -12297,9 +12744,9 @@ var Wallet = class {
12297
12744
  };
12298
12745
 
12299
12746
  // src/wallet-manager/wallet-manager.ts
12300
- import { Address as Address9 } from "@fuel-ts/address";
12747
+ import { Address as Address10 } from "@fuel-ts/address";
12301
12748
  import { encrypt, decrypt } from "@fuel-ts/crypto";
12302
- import { ErrorCode as ErrorCode26, FuelError as FuelError28 } from "@fuel-ts/errors";
12749
+ import { ErrorCode as ErrorCode27, FuelError as FuelError29 } from "@fuel-ts/errors";
12303
12750
  import { EventEmitter } from "events";
12304
12751
 
12305
12752
  // src/wallet-manager/storages/memory-storage.ts
@@ -12324,8 +12771,8 @@ var MemoryStorage = class {
12324
12771
  };
12325
12772
 
12326
12773
  // src/wallet-manager/vaults/mnemonic-vault.ts
12327
- import { Address as Address7 } from "@fuel-ts/address";
12328
- import { ErrorCode as ErrorCode24, FuelError as FuelError26 } from "@fuel-ts/errors";
12774
+ import { Address as Address8 } from "@fuel-ts/address";
12775
+ import { ErrorCode as ErrorCode25, FuelError as FuelError27 } from "@fuel-ts/errors";
12329
12776
  var MnemonicVault = class {
12330
12777
  static {
12331
12778
  __name(this, "MnemonicVault");
@@ -12376,7 +12823,7 @@ var MnemonicVault = class {
12376
12823
  }
12377
12824
  exportAccount(address) {
12378
12825
  let numberOfAccounts = 0;
12379
- const ownerAddress = new Address7(address);
12826
+ const ownerAddress = new Address8(address);
12380
12827
  do {
12381
12828
  const wallet = Wallet.fromMnemonic(this.#secret, this.getDerivePath(numberOfAccounts));
12382
12829
  if (wallet.address.equals(ownerAddress)) {
@@ -12384,8 +12831,8 @@ var MnemonicVault = class {
12384
12831
  }
12385
12832
  numberOfAccounts += 1;
12386
12833
  } while (numberOfAccounts < this.numberOfAccounts);
12387
- throw new FuelError26(
12388
- ErrorCode24.WALLET_MANAGER_ERROR,
12834
+ throw new FuelError27(
12835
+ ErrorCode25.WALLET_MANAGER_ERROR,
12389
12836
  `Account with address '${address}' not found in derived wallets.`
12390
12837
  );
12391
12838
  }
@@ -12396,8 +12843,8 @@ var MnemonicVault = class {
12396
12843
  };
12397
12844
 
12398
12845
  // src/wallet-manager/vaults/privatekey-vault.ts
12399
- import { Address as Address8 } from "@fuel-ts/address";
12400
- import { ErrorCode as ErrorCode25, FuelError as FuelError27 } from "@fuel-ts/errors";
12846
+ import { Address as Address9 } from "@fuel-ts/address";
12847
+ import { ErrorCode as ErrorCode26, FuelError as FuelError28 } from "@fuel-ts/errors";
12401
12848
  var PrivateKeyVault = class {
12402
12849
  static {
12403
12850
  __name(this, "PrivateKeyVault");
@@ -12436,13 +12883,13 @@ var PrivateKeyVault = class {
12436
12883
  return this.getPublicAccount(wallet.privateKey);
12437
12884
  }
12438
12885
  exportAccount(address) {
12439
- const ownerAddress = new Address8(address);
12886
+ const ownerAddress = new Address9(address);
12440
12887
  const privateKey = this.#privateKeys.find(
12441
12888
  (pk) => Wallet.fromPrivateKey(pk).address.equals(ownerAddress)
12442
12889
  );
12443
12890
  if (!privateKey) {
12444
- throw new FuelError27(
12445
- ErrorCode25.WALLET_MANAGER_ERROR,
12891
+ throw new FuelError28(
12892
+ ErrorCode26.WALLET_MANAGER_ERROR,
12446
12893
  `No private key found for address '${address}'.`
12447
12894
  );
12448
12895
  }
@@ -12464,7 +12911,7 @@ var ERROR_MESSAGES = {
12464
12911
  };
12465
12912
  function assert(condition, message) {
12466
12913
  if (!condition) {
12467
- throw new FuelError28(ErrorCode26.WALLET_MANAGER_ERROR, message);
12914
+ throw new FuelError29(ErrorCode27.WALLET_MANAGER_ERROR, message);
12468
12915
  }
12469
12916
  }
12470
12917
  __name(assert, "assert");
@@ -12533,7 +12980,7 @@ var WalletManager = class _WalletManager extends EventEmitter {
12533
12980
  * Create a Wallet instance for the specific account
12534
12981
  */
12535
12982
  getWallet(address) {
12536
- const ownerAddress = new Address9(address);
12983
+ const ownerAddress = new Address10(address);
12537
12984
  const vaultState = this.#vaults.find(
12538
12985
  (vs) => vs.vault.getAccounts().find((a) => a.address.equals(ownerAddress))
12539
12986
  );
@@ -12544,7 +12991,7 @@ var WalletManager = class _WalletManager extends EventEmitter {
12544
12991
  * Export specific account privateKey
12545
12992
  */
12546
12993
  exportPrivateKey(address) {
12547
- const ownerAddress = new Address9(address);
12994
+ const ownerAddress = new Address10(address);
12548
12995
  assert(!this.#isLocked, ERROR_MESSAGES.wallet_not_unlocked);
12549
12996
  const vaultState = this.#vaults.find(
12550
12997
  (vs) => vs.vault.getAccounts().find((a) => a.address.equals(ownerAddress))
@@ -12685,29 +13132,29 @@ var WalletManager = class _WalletManager extends EventEmitter {
12685
13132
  };
12686
13133
 
12687
13134
  // src/wallet-manager/types.ts
12688
- import { ErrorCode as ErrorCode27, FuelError as FuelError29 } from "@fuel-ts/errors";
13135
+ import { ErrorCode as ErrorCode28, FuelError as FuelError30 } from "@fuel-ts/errors";
12689
13136
  var Vault = class {
12690
13137
  static {
12691
13138
  __name(this, "Vault");
12692
13139
  }
12693
13140
  static type;
12694
13141
  constructor(_options) {
12695
- throw new FuelError29(ErrorCode27.NOT_IMPLEMENTED, "Not implemented.");
13142
+ throw new FuelError30(ErrorCode28.NOT_IMPLEMENTED, "Not implemented.");
12696
13143
  }
12697
13144
  serialize() {
12698
- throw new FuelError29(ErrorCode27.NOT_IMPLEMENTED, "Not implemented.");
13145
+ throw new FuelError30(ErrorCode28.NOT_IMPLEMENTED, "Not implemented.");
12699
13146
  }
12700
13147
  getAccounts() {
12701
- throw new FuelError29(ErrorCode27.NOT_IMPLEMENTED, "Not implemented.");
13148
+ throw new FuelError30(ErrorCode28.NOT_IMPLEMENTED, "Not implemented.");
12702
13149
  }
12703
13150
  addAccount() {
12704
- throw new FuelError29(ErrorCode27.NOT_IMPLEMENTED, "Not implemented.");
13151
+ throw new FuelError30(ErrorCode28.NOT_IMPLEMENTED, "Not implemented.");
12705
13152
  }
12706
13153
  exportAccount(_address) {
12707
- throw new FuelError29(ErrorCode27.NOT_IMPLEMENTED, "Not implemented.");
13154
+ throw new FuelError30(ErrorCode28.NOT_IMPLEMENTED, "Not implemented.");
12708
13155
  }
12709
13156
  getWallet(_address) {
12710
- throw new FuelError29(ErrorCode27.NOT_IMPLEMENTED, "Not implemented.");
13157
+ throw new FuelError30(ErrorCode28.NOT_IMPLEMENTED, "Not implemented.");
12711
13158
  }
12712
13159
  };
12713
13160
  var StorageAbstract = class {
@@ -12717,19 +13164,19 @@ var StorageAbstract = class {
12717
13164
  };
12718
13165
 
12719
13166
  // src/predicate/predicate.ts
12720
- import { Interface as Interface4 } from "@fuel-ts/abi-coder";
12721
- import { Address as Address10 } from "@fuel-ts/address";
12722
- import { ErrorCode as ErrorCode29, FuelError as FuelError31 } from "@fuel-ts/errors";
12723
- import { arrayify as arrayify23, hexlify as hexlify25 } from "@fuel-ts/utils";
13167
+ import { Interface as Interface5 } from "@fuel-ts/abi-coder";
13168
+ import { Address as Address11 } from "@fuel-ts/address";
13169
+ import { ErrorCode as ErrorCode30, FuelError as FuelError32 } from "@fuel-ts/errors";
13170
+ import { arrayify as arrayify24, hexlify as hexlify25 } from "@fuel-ts/utils";
12724
13171
 
12725
13172
  // src/utils/deployScriptOrPredicate.ts
12726
- import { FuelError as FuelError30, ErrorCode as ErrorCode28 } from "@fuel-ts/errors";
12727
- import { arrayify as arrayify21 } from "@fuel-ts/utils";
13173
+ import { FuelError as FuelError31, ErrorCode as ErrorCode29 } from "@fuel-ts/errors";
13174
+ import { arrayify as arrayify22 } from "@fuel-ts/utils";
12728
13175
 
12729
13176
  // src/utils/predicate-script-loader-instructions.ts
12730
13177
  import { BigNumberCoder as BigNumberCoder4 } from "@fuel-ts/abi-coder";
12731
13178
  import { sha256 as sha2565 } from "@fuel-ts/hasher";
12732
- import { concat as concat7 } from "@fuel-ts/utils";
13179
+ import { concat as concat8 } from "@fuel-ts/utils";
12733
13180
  import * as asm2 from "@fuels/vm-asm";
12734
13181
  var BLOB_ID_SIZE = 32;
12735
13182
  var REG_ADDRESS_OF_DATA_AFTER_CODE = 16;
@@ -12855,7 +13302,7 @@ function getPredicateScriptLoaderInstructions(originalBinary, blobId) {
12855
13302
  ...dataSectionLenBytes
12856
13303
  ]);
12857
13304
  return {
12858
- loaderBytecode: concat7([loaderBytecode2, configurableSection]),
13305
+ loaderBytecode: concat8([loaderBytecode2, configurableSection]),
12859
13306
  blobOffset: loaderBytecode2.length
12860
13307
  };
12861
13308
  }
@@ -12899,8 +13346,8 @@ async function deployScriptOrPredicate({
12899
13346
  abi,
12900
13347
  loaderInstanceCallback
12901
13348
  }) {
12902
- const blobId = getBytecodeId(arrayify21(bytecode));
12903
- const configurableOffset = getBytecodeConfigurableOffset(arrayify21(bytecode));
13349
+ const blobId = getBytecodeId(arrayify22(bytecode));
13350
+ const configurableOffset = getBytecodeConfigurableOffset(arrayify22(bytecode));
12904
13351
  const byteCodeWithoutConfigurableSection = bytecode.slice(0, configurableOffset);
12905
13352
  const blobTxRequest = new BlobTransactionRequest({
12906
13353
  blobId,
@@ -12908,8 +13355,8 @@ async function deployScriptOrPredicate({
12908
13355
  witnesses: [byteCodeWithoutConfigurableSection]
12909
13356
  });
12910
13357
  const { loaderBytecode, blobOffset } = getPredicateScriptLoaderInstructions(
12911
- arrayify21(bytecode),
12912
- arrayify21(blobId)
13358
+ arrayify22(bytecode),
13359
+ arrayify22(blobId)
12913
13360
  );
12914
13361
  const newConfigurableOffsetDiff = byteCodeWithoutConfigurableSection.length - (blobOffset || 0);
12915
13362
  const newAbi = adjustConfigurableOffsets(abi, newConfigurableOffsetDiff);
@@ -12930,7 +13377,7 @@ async function deployScriptOrPredicate({
12930
13377
  throw new Error();
12931
13378
  }
12932
13379
  } catch (err) {
12933
- throw new FuelError30(ErrorCode28.TRANSACTION_FAILED, "Failed to deploy predicate chunk");
13380
+ throw new FuelError31(ErrorCode29.TRANSACTION_FAILED, "Failed to deploy predicate chunk");
12934
13381
  }
12935
13382
  return loaderInstance;
12936
13383
  }, "waitForResult");
@@ -12944,13 +13391,13 @@ __name(deployScriptOrPredicate, "deployScriptOrPredicate");
12944
13391
  // src/predicate/utils/getPredicateRoot.ts
12945
13392
  import { hash as hash3 } from "@fuel-ts/hasher";
12946
13393
  import { calcRoot } from "@fuel-ts/merkle";
12947
- import { chunkAndPadBytes, hexlify as hexlify24, concat as concat8, arrayify as arrayify22 } from "@fuel-ts/utils";
13394
+ import { chunkAndPadBytes, hexlify as hexlify24, concat as concat9, arrayify as arrayify23 } from "@fuel-ts/utils";
12948
13395
  var getPredicateRoot = /* @__PURE__ */ __name((bytecode) => {
12949
13396
  const chunkSize = 16 * 1024;
12950
- const bytes = arrayify22(bytecode);
13397
+ const bytes = arrayify23(bytecode);
12951
13398
  const chunks = chunkAndPadBytes(bytes, chunkSize);
12952
13399
  const codeRoot = calcRoot(chunks.map((c) => hexlify24(c)));
12953
- const predicateRoot = hash3(concat8(["0x4655454C", codeRoot]));
13400
+ const predicateRoot = hash3(concat9(["0x4655454C", codeRoot]));
12954
13401
  return predicateRoot;
12955
13402
  }, "getPredicateRoot");
12956
13403
 
@@ -12985,9 +13432,9 @@ var Predicate = class _Predicate extends Account {
12985
13432
  abi,
12986
13433
  configurableConstants
12987
13434
  );
12988
- const address = new Address10(getPredicateRoot(predicateBytes));
13435
+ const address = new Address11(getPredicateRoot(predicateBytes));
12989
13436
  super(address, provider);
12990
- this.initialBytecode = arrayify23(bytecode);
13437
+ this.initialBytecode = arrayify24(bytecode);
12991
13438
  this.bytes = predicateBytes;
12992
13439
  this.interface = predicateInterface;
12993
13440
  this.configurableConstants = configurableConstants;
@@ -13079,11 +13526,11 @@ var Predicate = class _Predicate extends Account {
13079
13526
  * @returns An object containing the new predicate bytes and interface.
13080
13527
  */
13081
13528
  static processPredicateData(bytes, jsonAbi, configurableConstants) {
13082
- let predicateBytes = arrayify23(bytes);
13083
- const abiInterface = new Interface4(jsonAbi);
13529
+ let predicateBytes = arrayify24(bytes);
13530
+ const abiInterface = new Interface5(jsonAbi);
13084
13531
  if (abiInterface.functions.main === void 0) {
13085
- throw new FuelError31(
13086
- ErrorCode29.ABI_MAIN_METHOD_MISSING,
13532
+ throw new FuelError32(
13533
+ ErrorCode30.ABI_MAIN_METHOD_MISSING,
13087
13534
  'Cannot use ABI without "main" function.'
13088
13535
  );
13089
13536
  }
@@ -13143,15 +13590,15 @@ var Predicate = class _Predicate extends Account {
13143
13590
  const mutatedBytes = bytes;
13144
13591
  try {
13145
13592
  if (Object.keys(abiInterface.configurables).length === 0) {
13146
- throw new FuelError31(
13147
- ErrorCode29.INVALID_CONFIGURABLE_CONSTANTS,
13593
+ throw new FuelError32(
13594
+ ErrorCode30.INVALID_CONFIGURABLE_CONSTANTS,
13148
13595
  "Predicate has no configurable constants to be set"
13149
13596
  );
13150
13597
  }
13151
13598
  Object.entries(configurableConstants).forEach(([key, value]) => {
13152
13599
  if (!abiInterface?.configurables[key]) {
13153
- throw new FuelError31(
13154
- ErrorCode29.CONFIGURABLE_NOT_FOUND,
13600
+ throw new FuelError32(
13601
+ ErrorCode30.CONFIGURABLE_NOT_FOUND,
13155
13602
  `No configurable constant named '${key}' found in the Predicate`
13156
13603
  );
13157
13604
  }
@@ -13160,8 +13607,8 @@ var Predicate = class _Predicate extends Account {
13160
13607
  mutatedBytes.set(encoded, offset);
13161
13608
  });
13162
13609
  } catch (err) {
13163
- throw new FuelError31(
13164
- ErrorCode29.INVALID_CONFIGURABLE_CONSTANTS,
13610
+ throw new FuelError32(
13611
+ ErrorCode30.INVALID_CONFIGURABLE_CONSTANTS,
13165
13612
  `Error setting configurable constants: ${err.message}.`
13166
13613
  );
13167
13614
  }
@@ -13214,10 +13661,10 @@ var Predicate = class _Predicate extends Account {
13214
13661
  };
13215
13662
 
13216
13663
  // src/connectors/fuel.ts
13217
- import { ErrorCode as ErrorCode30, FuelError as FuelError34 } from "@fuel-ts/errors";
13664
+ import { ErrorCode as ErrorCode31, FuelError as FuelError35 } from "@fuel-ts/errors";
13218
13665
 
13219
13666
  // src/connectors/fuel-connector.ts
13220
- import { FuelError as FuelError32 } from "@fuel-ts/errors";
13667
+ import { FuelError as FuelError33 } from "@fuel-ts/errors";
13221
13668
  import { EventEmitter as EventEmitter2 } from "events";
13222
13669
 
13223
13670
  // src/connectors/types/connector-types.ts
@@ -13242,6 +13689,7 @@ var FuelConnectorMethods = /* @__PURE__ */ ((FuelConnectorMethods2) => {
13242
13689
  FuelConnectorMethods2["addABI"] = "addABI";
13243
13690
  FuelConnectorMethods2["getABI"] = "getABI";
13244
13691
  FuelConnectorMethods2["hasABI"] = "hasABI";
13692
+ FuelConnectorMethods2["startConsolidation"] = "startConsolidation";
13245
13693
  return FuelConnectorMethods2;
13246
13694
  })(FuelConnectorMethods || {});
13247
13695
  var FuelConnectorEventTypes = /* @__PURE__ */ ((FuelConnectorEventTypes2) => {
@@ -13254,6 +13702,7 @@ var FuelConnectorEventTypes = /* @__PURE__ */ ((FuelConnectorEventTypes2) => {
13254
13702
  FuelConnectorEventTypes2["currentNetwork"] = "currentNetwork";
13255
13703
  FuelConnectorEventTypes2["assets"] = "assets";
13256
13704
  FuelConnectorEventTypes2["abis"] = "abis";
13705
+ FuelConnectorEventTypes2["consolidateCoins"] = "consolidateCoins";
13257
13706
  return FuelConnectorEventTypes2;
13258
13707
  })(FuelConnectorEventTypes || {});
13259
13708
  var FuelConnectorEventType = "FuelConnector";
@@ -13299,7 +13748,7 @@ var FuelConnector = class extends EventEmitter2 {
13299
13748
  * @returns Always true.
13300
13749
  */
13301
13750
  async ping() {
13302
- throw new FuelError32(FuelError32.CODES.NOT_IMPLEMENTED, "Method not implemented.");
13751
+ throw new FuelError33(FuelError33.CODES.NOT_IMPLEMENTED, "Method not implemented.");
13303
13752
  }
13304
13753
  /**
13305
13754
  * Should return the current version of the connector
@@ -13308,7 +13757,7 @@ var FuelConnector = class extends EventEmitter2 {
13308
13757
  * @returns boolean - connection status.
13309
13758
  */
13310
13759
  async version() {
13311
- throw new FuelError32(FuelError32.CODES.NOT_IMPLEMENTED, "Method not implemented.");
13760
+ throw new FuelError33(FuelError33.CODES.NOT_IMPLEMENTED, "Method not implemented.");
13312
13761
  }
13313
13762
  /**
13314
13763
  * Should return true if the connector is connected
@@ -13317,7 +13766,7 @@ var FuelConnector = class extends EventEmitter2 {
13317
13766
  * @returns The connection status.
13318
13767
  */
13319
13768
  async isConnected() {
13320
- throw new FuelError32(FuelError32.CODES.NOT_IMPLEMENTED, "Method not implemented.");
13769
+ throw new FuelError33(FuelError33.CODES.NOT_IMPLEMENTED, "Method not implemented.");
13321
13770
  }
13322
13771
  /**
13323
13772
  * Should return all the accounts authorized for the
@@ -13326,7 +13775,7 @@ var FuelConnector = class extends EventEmitter2 {
13326
13775
  * @returns The accounts addresses strings
13327
13776
  */
13328
13777
  async accounts() {
13329
- throw new FuelError32(FuelError32.CODES.NOT_IMPLEMENTED, "Method not implemented.");
13778
+ throw new FuelError33(FuelError33.CODES.NOT_IMPLEMENTED, "Method not implemented.");
13330
13779
  }
13331
13780
  /**
13332
13781
  * Should start the connection process and return
@@ -13338,7 +13787,7 @@ var FuelConnector = class extends EventEmitter2 {
13338
13787
  * @returns boolean - connection status.
13339
13788
  */
13340
13789
  async connect() {
13341
- throw new FuelError32(FuelError32.CODES.NOT_IMPLEMENTED, "Method not implemented.");
13790
+ throw new FuelError33(FuelError33.CODES.NOT_IMPLEMENTED, "Method not implemented.");
13342
13791
  }
13343
13792
  /**
13344
13793
  * Should disconnect the current connection and
@@ -13348,7 +13797,7 @@ var FuelConnector = class extends EventEmitter2 {
13348
13797
  * @returns The connection status.
13349
13798
  */
13350
13799
  async disconnect() {
13351
- throw new FuelError32(FuelError32.CODES.NOT_IMPLEMENTED, "Method not implemented.");
13800
+ throw new FuelError33(FuelError33.CODES.NOT_IMPLEMENTED, "Method not implemented.");
13352
13801
  }
13353
13802
  /**
13354
13803
  * Should start the sign message process and return
@@ -13360,7 +13809,7 @@ var FuelConnector = class extends EventEmitter2 {
13360
13809
  * @returns Message signature
13361
13810
  */
13362
13811
  async signMessage(_address, _message) {
13363
- throw new FuelError32(FuelError32.CODES.NOT_IMPLEMENTED, "Method not implemented.");
13812
+ throw new FuelError33(FuelError33.CODES.NOT_IMPLEMENTED, "Method not implemented.");
13364
13813
  }
13365
13814
  /**
13366
13815
  * Should start the sign transaction process and return
@@ -13372,7 +13821,7 @@ var FuelConnector = class extends EventEmitter2 {
13372
13821
  * @returns Transaction signature
13373
13822
  */
13374
13823
  async signTransaction(_address, _transaction, _params) {
13375
- throw new FuelError32(FuelError32.CODES.NOT_IMPLEMENTED, "Method not implemented.");
13824
+ throw new FuelError33(FuelError33.CODES.NOT_IMPLEMENTED, "Method not implemented.");
13376
13825
  }
13377
13826
  /**
13378
13827
  * Should start the send transaction process and return
@@ -13388,7 +13837,7 @@ var FuelConnector = class extends EventEmitter2 {
13388
13837
  * @returns The transaction id or transaction response
13389
13838
  */
13390
13839
  async sendTransaction(_address, _transaction, _params) {
13391
- throw new FuelError32(FuelError32.CODES.NOT_IMPLEMENTED, "Method not implemented.");
13840
+ throw new FuelError33(FuelError33.CODES.NOT_IMPLEMENTED, "Method not implemented.");
13392
13841
  }
13393
13842
  /**
13394
13843
  * Should return the current account selected inside the connector, if the account
@@ -13399,7 +13848,7 @@ var FuelConnector = class extends EventEmitter2 {
13399
13848
  * @returns The current account selected otherwise null.
13400
13849
  */
13401
13850
  async currentAccount() {
13402
- throw new FuelError32(FuelError32.CODES.NOT_IMPLEMENTED, "Method not implemented.");
13851
+ throw new FuelError33(FuelError33.CODES.NOT_IMPLEMENTED, "Method not implemented.");
13403
13852
  }
13404
13853
  /**
13405
13854
  * Should add the assets metadata to the connector and return true if the asset
@@ -13413,7 +13862,7 @@ var FuelConnector = class extends EventEmitter2 {
13413
13862
  * @returns True if the asset was added successfully
13414
13863
  */
13415
13864
  async addAssets(_assets) {
13416
- throw new FuelError32(FuelError32.CODES.NOT_IMPLEMENTED, "Method not implemented.");
13865
+ throw new FuelError33(FuelError33.CODES.NOT_IMPLEMENTED, "Method not implemented.");
13417
13866
  }
13418
13867
  /**
13419
13868
  * Should add the asset metadata to the connector and return true if the asset
@@ -13427,7 +13876,7 @@ var FuelConnector = class extends EventEmitter2 {
13427
13876
  * @returns True if the asset was added successfully
13428
13877
  */
13429
13878
  async addAsset(_asset) {
13430
- throw new FuelError32(FuelError32.CODES.NOT_IMPLEMENTED, "Method not implemented.");
13879
+ throw new FuelError33(FuelError33.CODES.NOT_IMPLEMENTED, "Method not implemented.");
13431
13880
  }
13432
13881
  /**
13433
13882
  * Should return all the assets added to the connector. If a connection is already established.
@@ -13435,7 +13884,7 @@ var FuelConnector = class extends EventEmitter2 {
13435
13884
  * @returns Array of assets metadata from the connector vinculated to the all accounts from a specific Wallet.
13436
13885
  */
13437
13886
  async assets() {
13438
- throw new FuelError32(FuelError32.CODES.NOT_IMPLEMENTED, "Method not implemented.");
13887
+ throw new FuelError33(FuelError33.CODES.NOT_IMPLEMENTED, "Method not implemented.");
13439
13888
  }
13440
13889
  /**
13441
13890
  * Should start the add network process and return true if the network was added successfully.
@@ -13446,7 +13895,7 @@ var FuelConnector = class extends EventEmitter2 {
13446
13895
  * @returns Return true if the network was added successfully
13447
13896
  */
13448
13897
  async addNetwork(_networkUrl) {
13449
- throw new FuelError32(FuelError32.CODES.NOT_IMPLEMENTED, "Method not implemented.");
13898
+ throw new FuelError33(FuelError33.CODES.NOT_IMPLEMENTED, "Method not implemented.");
13450
13899
  }
13451
13900
  /**
13452
13901
  * Should start the select network process and return true if the network has change successfully.
@@ -13457,7 +13906,7 @@ var FuelConnector = class extends EventEmitter2 {
13457
13906
  * @returns Return true if the network was added successfully
13458
13907
  */
13459
13908
  async selectNetwork(_network) {
13460
- throw new FuelError32(FuelError32.CODES.NOT_IMPLEMENTED, "Method not implemented.");
13909
+ throw new FuelError33(FuelError33.CODES.NOT_IMPLEMENTED, "Method not implemented.");
13461
13910
  }
13462
13911
  /**
13463
13912
  * Should return all the networks available from the connector. If the connection is already established.
@@ -13465,7 +13914,7 @@ var FuelConnector = class extends EventEmitter2 {
13465
13914
  * @returns Return all the networks added to the connector.
13466
13915
  */
13467
13916
  async networks() {
13468
- throw new FuelError32(FuelError32.CODES.NOT_IMPLEMENTED, "Method not implemented.");
13917
+ throw new FuelError33(FuelError33.CODES.NOT_IMPLEMENTED, "Method not implemented.");
13469
13918
  }
13470
13919
  /**
13471
13920
  * Should return the current network selected inside the connector. Even if the connection is not established.
@@ -13473,7 +13922,7 @@ var FuelConnector = class extends EventEmitter2 {
13473
13922
  * @returns Return the current network selected inside the connector.
13474
13923
  */
13475
13924
  async currentNetwork() {
13476
- throw new FuelError32(FuelError32.CODES.NOT_IMPLEMENTED, "Method not implemented.");
13925
+ throw new FuelError33(FuelError33.CODES.NOT_IMPLEMENTED, "Method not implemented.");
13477
13926
  }
13478
13927
  /**
13479
13928
  * Should add the ABI to the connector and return true if the ABI was added successfully.
@@ -13483,7 +13932,7 @@ var FuelConnector = class extends EventEmitter2 {
13483
13932
  * @returns Return true if the ABI was added successfully.
13484
13933
  */
13485
13934
  async addABI(_contractId, _abi) {
13486
- throw new FuelError32(FuelError32.CODES.NOT_IMPLEMENTED, "Method not implemented.");
13935
+ throw new FuelError33(FuelError33.CODES.NOT_IMPLEMENTED, "Method not implemented.");
13487
13936
  }
13488
13937
  /**
13489
13938
  * Should return the ABI from the connector vinculated to the all accounts from a specific Wallet.
@@ -13492,7 +13941,7 @@ var FuelConnector = class extends EventEmitter2 {
13492
13941
  * @returns The ABI if it exists, otherwise return null.
13493
13942
  */
13494
13943
  async getABI(_id) {
13495
- throw new FuelError32(FuelError32.CODES.NOT_IMPLEMENTED, "Method not implemented.");
13944
+ throw new FuelError33(FuelError33.CODES.NOT_IMPLEMENTED, "Method not implemented.");
13496
13945
  }
13497
13946
  /**
13498
13947
  * Should return true if the abi exists in the connector vinculated to the all accounts from a specific Wallet.
@@ -13501,7 +13950,16 @@ var FuelConnector = class extends EventEmitter2 {
13501
13950
  * @returns Returns true if the abi exists or false if not.
13502
13951
  */
13503
13952
  async hasABI(_id) {
13504
- throw new FuelError32(FuelError32.CODES.NOT_IMPLEMENTED, "Method not implemented.");
13953
+ throw new FuelError33(FuelError33.CODES.NOT_IMPLEMENTED, "Method not implemented.");
13954
+ }
13955
+ /**
13956
+ * Start the consolidation of coins process
13957
+ *
13958
+ * @param owner - The B256 address of the owner.
13959
+ * @param assetId - The asset ID that requires consolidation.
13960
+ */
13961
+ async startConsolidation(_opts) {
13962
+ throw new FuelError33(FuelError33.CODES.NOT_IMPLEMENTED, "Method not implemented.");
13505
13963
  }
13506
13964
  /**
13507
13965
  * Event listener for the connector.
@@ -13547,7 +14005,7 @@ function dispatchFuelConnectorEvent(connector) {
13547
14005
  __name(dispatchFuelConnectorEvent, "dispatchFuelConnectorEvent");
13548
14006
 
13549
14007
  // src/connectors/utils/promises.ts
13550
- import { FuelError as FuelError33 } from "@fuel-ts/errors";
14008
+ import { FuelError as FuelError34 } from "@fuel-ts/errors";
13551
14009
  function deferPromise() {
13552
14010
  const defer = {};
13553
14011
  defer.promise = new Promise((resolve, reject) => {
@@ -13560,7 +14018,7 @@ __name(deferPromise, "deferPromise");
13560
14018
  async function withTimeout(promise, timeout = 1050) {
13561
14019
  const timeoutPromise = new Promise((resolve, reject) => {
13562
14020
  setTimeout(() => {
13563
- reject(new FuelError33(FuelError33.CODES.TIMEOUT_EXCEEDED, "Promise timed out"));
14021
+ reject(new FuelError34(FuelError34.CODES.TIMEOUT_EXCEEDED, "Promise timed out"));
13564
14022
  }, timeout);
13565
14023
  });
13566
14024
  return Promise.race([timeoutPromise, promise]);
@@ -13601,7 +14059,7 @@ var Fuel = class _Fuel extends FuelConnector {
13601
14059
  this._targetUnsubscribe = this.setupConnectorListener();
13602
14060
  await connectResponse;
13603
14061
  } catch (error) {
13604
- throw new FuelError34(ErrorCode30.INVALID_PROVIDER, "Error initializing Fuel Connector");
14062
+ throw new FuelError35(ErrorCode31.INVALID_PROVIDER, "Error initializing Fuel Connector");
13605
14063
  }
13606
14064
  }
13607
14065
  async init() {
@@ -13667,8 +14125,8 @@ var Fuel = class _Fuel extends FuelConnector {
13667
14125
  const hasConnector = await this.hasConnector();
13668
14126
  await this.pingConnector();
13669
14127
  if (!this._currentConnector || !hasConnector) {
13670
- throw new FuelError34(
13671
- ErrorCode30.MISSING_CONNECTOR,
14128
+ throw new FuelError35(
14129
+ ErrorCode31.MISSING_CONNECTOR,
13672
14130
  `No connector selected for calling ${method}. Use hasConnector before executing other methods.`
13673
14131
  );
13674
14132
  }
@@ -13732,7 +14190,7 @@ var Fuel = class _Fuel extends FuelConnector {
13732
14190
  cacheTime: PING_CACHE_TIME
13733
14191
  })();
13734
14192
  } catch {
13735
- throw new FuelError34(ErrorCode30.INVALID_PROVIDER, "Current connector is not available.");
14193
+ throw new FuelError35(ErrorCode31.INVALID_PROVIDER, "Current connector is not available.");
13736
14194
  }
13737
14195
  }
13738
14196
  /**
@@ -13881,7 +14339,7 @@ var Fuel = class _Fuel extends FuelConnector {
13881
14339
  const currentNetwork = await this.currentNetwork();
13882
14340
  provider = new Provider(currentNetwork.url);
13883
14341
  } else {
13884
- throw new FuelError34(ErrorCode30.INVALID_PROVIDER, "Provider is not valid.");
14342
+ throw new FuelError35(ErrorCode31.INVALID_PROVIDER, "Provider is not valid.");
13885
14343
  }
13886
14344
  return provider;
13887
14345
  }
@@ -13974,6 +14432,7 @@ export {
13974
14432
  assemblePreConfirmationTransactionSummary,
13975
14433
  assembleReceiptByType,
13976
14434
  assembleRevertError,
14435
+ assembleSignalErrorMessage,
13977
14436
  assembleTransactionSummary,
13978
14437
  assembleTransactionSummaryFromJson,
13979
14438
  assets,
@@ -13990,6 +14449,8 @@ export {
13990
14449
  calculateMinGasForTxUpload,
13991
14450
  calculateTXFeeForSummary,
13992
14451
  coinQuantityfy,
14452
+ consolidateCoins,
14453
+ consolidateCoinsIfRequired,
13993
14454
  deferPromise,
13994
14455
  deployScriptOrPredicate,
13995
14456
  deserializeChain,
@@ -14008,6 +14469,7 @@ export {
14008
14469
  extractTxError,
14009
14470
  fuelAssetsBaseUrl,
14010
14471
  gasUsedByInputs,
14472
+ getAllCoins,
14011
14473
  getAllDecodedLogs,
14012
14474
  getAssetAmountInRequestInputs,
14013
14475
  getAssetById,