@fuel-ts/account 0.78.0 → 0.80.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of @fuel-ts/account might be problematic. Click here for more details.

Files changed (39) hide show
  1. package/dist/configs.d.ts +1 -0
  2. package/dist/configs.d.ts.map +1 -1
  3. package/dist/configs.global.js +1 -0
  4. package/dist/configs.global.js.map +1 -1
  5. package/dist/configs.js +3 -0
  6. package/dist/configs.js.map +1 -1
  7. package/dist/configs.mjs +2 -0
  8. package/dist/configs.mjs.map +1 -1
  9. package/dist/index.global.js +388 -210
  10. package/dist/index.global.js.map +1 -1
  11. package/dist/index.js +668 -550
  12. package/dist/index.js.map +1 -1
  13. package/dist/index.mjs +422 -299
  14. package/dist/index.mjs.map +1 -1
  15. package/dist/predicate/predicate.d.ts +0 -1
  16. package/dist/predicate/predicate.d.ts.map +1 -1
  17. package/dist/providers/provider.d.ts +13 -2
  18. package/dist/providers/provider.d.ts.map +1 -1
  19. package/dist/providers/transaction-request/input.d.ts.map +1 -1
  20. package/dist/providers/transaction-request/script-transaction-request.d.ts +3 -0
  21. package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
  22. package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
  23. package/dist/providers/transaction-request/types.d.ts +5 -0
  24. package/dist/providers/transaction-request/types.d.ts.map +1 -1
  25. package/dist/providers/transaction-response/getDecodedLogs.d.ts +2 -2
  26. package/dist/providers/transaction-response/getDecodedLogs.d.ts.map +1 -1
  27. package/dist/providers/transaction-response/transaction-response.d.ts +5 -2
  28. package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
  29. package/dist/providers/utils/extract-tx-error.d.ts +36 -0
  30. package/dist/providers/utils/extract-tx-error.d.ts.map +1 -0
  31. package/dist/providers/utils/index.d.ts +1 -0
  32. package/dist/providers/utils/index.d.ts.map +1 -1
  33. package/dist/test-utils.global.js +390 -196
  34. package/dist/test-utils.global.js.map +1 -1
  35. package/dist/test-utils.js +625 -499
  36. package/dist/test-utils.js.map +1 -1
  37. package/dist/test-utils.mjs +392 -258
  38. package/dist/test-utils.mjs.map +1 -1
  39. package/package.json +16 -16
@@ -28952,9 +28952,9 @@ spurious results.`);
28952
28952
  // ../versions/dist/index.mjs
28953
28953
  function getBuiltinVersions() {
28954
28954
  return {
28955
- FORC: "0.51.1",
28955
+ FORC: "0.49.3",
28956
28956
  FUEL_CORE: "0.22.1",
28957
- FUELS: "0.78.0"
28957
+ FUELS: "0.80.0"
28958
28958
  };
28959
28959
  }
28960
28960
  function parseVersion(version2) {
@@ -29013,9 +29013,9 @@ This unreleased fuel-core build may include features and updates not yet support
29013
29013
  ErrorCode2["ABI_TYPES_AND_VALUES_MISMATCH"] = "abi-types-and-values-mismatch";
29014
29014
  ErrorCode2["ABI_MAIN_METHOD_MISSING"] = "abi-main-method-missing";
29015
29015
  ErrorCode2["INVALID_COMPONENT"] = "invalid-component";
29016
- ErrorCode2["FRAGMENT_NOT_FOUND"] = "fragment-not-found";
29017
29016
  ErrorCode2["CONFIGURABLE_NOT_FOUND"] = "configurable-not-found";
29018
29017
  ErrorCode2["TYPE_NOT_FOUND"] = "type-not-found";
29018
+ ErrorCode2["LOG_TYPE_NOT_FOUND"] = "log-type-not-found";
29019
29019
  ErrorCode2["TYPE_NOT_SUPPORTED"] = "type-not-supported";
29020
29020
  ErrorCode2["INVALID_DECODE_VALUE"] = "invalid-decode-value";
29021
29021
  ErrorCode2["JSON_ABI_ERROR"] = "json-abi-error";
@@ -29028,14 +29028,12 @@ This unreleased fuel-core build may include features and updates not yet support
29028
29028
  ErrorCode2["INVALID_BECH32_ADDRESS"] = "invalid-bech32-address";
29029
29029
  ErrorCode2["INVALID_EVM_ADDRESS"] = "invalid-evm-address";
29030
29030
  ErrorCode2["INVALID_B256_ADDRESS"] = "invalid-b256-address";
29031
- ErrorCode2["INVALID_URL"] = "invalid-url";
29032
29031
  ErrorCode2["CHAIN_INFO_CACHE_EMPTY"] = "chain-info-cache-empty";
29033
29032
  ErrorCode2["NODE_INFO_CACHE_EMPTY"] = "node-info-cache-empty";
29034
29033
  ErrorCode2["MISSING_PROVIDER"] = "missing-provider";
29035
29034
  ErrorCode2["INVALID_PROVIDER"] = "invalid-provider";
29036
29035
  ErrorCode2["CONNECTION_REFUSED"] = "connection-refused";
29037
29036
  ErrorCode2["INVALID_PUBLIC_KEY"] = "invalid-public-key";
29038
- ErrorCode2["INSUFFICIENT_BALANCE"] = "insufficient-balance";
29039
29037
  ErrorCode2["WALLET_MANAGER_ERROR"] = "wallet-manager-error";
29040
29038
  ErrorCode2["HD_WALLET_ERROR"] = "hd-wallet-error";
29041
29039
  ErrorCode2["MISSING_CONNECTOR"] = "missing-connector";
@@ -29052,7 +29050,6 @@ This unreleased fuel-core build may include features and updates not yet support
29052
29050
  ErrorCode2["ELEMENT_NOT_FOUND"] = "element-not-found";
29053
29051
  ErrorCode2["MISSING_REQUIRED_PARAMETER"] = "missing-required-parameter";
29054
29052
  ErrorCode2["INVALID_REQUEST"] = "invalid-request";
29055
- ErrorCode2["UNEXPECTED_HEX_VALUE"] = "unexpected-hex-value";
29056
29053
  ErrorCode2["INVALID_TRANSFER_AMOUNT"] = "invalid-transfer-amount";
29057
29054
  ErrorCode2["GAS_PRICE_TOO_LOW"] = "gas-price-too-low";
29058
29055
  ErrorCode2["GAS_LIMIT_TOO_LOW"] = "gas-limit-too-low";
@@ -29076,7 +29073,6 @@ This unreleased fuel-core build may include features and updates not yet support
29076
29073
  ErrorCode2["INVALID_PASSWORD"] = "invalid-password";
29077
29074
  ErrorCode2["ACCOUNT_REQUIRED"] = "account-required";
29078
29075
  ErrorCode2["UNLOCKED_WALLET_REQUIRED"] = "unlocked-wallet-required";
29079
- ErrorCode2["LATEST_BLOCK_UNAVAILABLE"] = "latest-block-unavailable";
29080
29076
  ErrorCode2["ERROR_BUILDING_BLOCK_EXPLORER_URL"] = "error-building-block-explorer-url";
29081
29077
  ErrorCode2["UNSUPPORTED_FUEL_CLIENT_VERSION"] = "unsupported-fuel-client-version";
29082
29078
  ErrorCode2["VITEPRESS_PLUGIN_ERROR"] = "vitepress-plugin-error";
@@ -29088,6 +29084,7 @@ This unreleased fuel-core build may include features and updates not yet support
29088
29084
  })(ErrorCode || {});
29089
29085
  var _FuelError = class extends Error {
29090
29086
  VERSIONS = versions;
29087
+ metadata;
29091
29088
  static parse(e) {
29092
29089
  const error = e;
29093
29090
  if (error.code === void 0) {
@@ -29107,14 +29104,15 @@ This unreleased fuel-core build may include features and updates not yet support
29107
29104
  return new _FuelError(error.code, error.message);
29108
29105
  }
29109
29106
  code;
29110
- constructor(code, message) {
29107
+ constructor(code, message, metadata = {}) {
29111
29108
  super(message);
29112
29109
  this.code = code;
29113
29110
  this.name = "FuelError";
29111
+ this.metadata = metadata;
29114
29112
  }
29115
29113
  toObject() {
29116
- const { code, name, message, VERSIONS } = this;
29117
- return { code, name, message, VERSIONS };
29114
+ const { code, name, message, metadata, VERSIONS } = this;
29115
+ return { code, name, message, metadata, VERSIONS };
29118
29116
  }
29119
29117
  };
29120
29118
  var FuelError = _FuelError;
@@ -31282,7 +31280,7 @@ This unreleased fuel-core build may include features and updates not yet support
31282
31280
  var import_bn = __toESM(require_bn(), 1);
31283
31281
  var DEFAULT_PRECISION = 9;
31284
31282
  var DEFAULT_MIN_PRECISION = 3;
31285
- var DECIMAL_UNITS = 9;
31283
+ var DEFAULT_DECIMAL_UNITS = 9;
31286
31284
  function toFixed(value, options) {
31287
31285
  const { precision = DEFAULT_PRECISION, minPrecision = DEFAULT_MIN_PRECISION } = options || {};
31288
31286
  const [valueUnits = "0", valueDecimals = "0"] = String(value || "0.0").split(".");
@@ -31348,7 +31346,7 @@ This unreleased fuel-core build may include features and updates not yet support
31348
31346
  }
31349
31347
  format(options) {
31350
31348
  const {
31351
- units = DECIMAL_UNITS,
31349
+ units = DEFAULT_DECIMAL_UNITS,
31352
31350
  precision = DEFAULT_PRECISION,
31353
31351
  minPrecision = DEFAULT_MIN_PRECISION
31354
31352
  } = options || {};
@@ -31364,7 +31362,7 @@ This unreleased fuel-core build may include features and updates not yet support
31364
31362
  }
31365
31363
  return formattedFixed;
31366
31364
  }
31367
- formatUnits(units = DECIMAL_UNITS) {
31365
+ formatUnits(units = DEFAULT_DECIMAL_UNITS) {
31368
31366
  const valueUnits = this.toString().slice(0, units * -1);
31369
31367
  const valueDecimals = this.toString().slice(units * -1);
31370
31368
  const length = valueDecimals.length;
@@ -31473,7 +31471,7 @@ This unreleased fuel-core build may include features and updates not yet support
31473
31471
  // END ANCHOR: OVERRIDES to avoid losing references
31474
31472
  };
31475
31473
  var bn = (value, base, endian) => new BN(value, base, endian);
31476
- bn.parseUnits = (value, units = DECIMAL_UNITS) => {
31474
+ bn.parseUnits = (value, units = DEFAULT_DECIMAL_UNITS) => {
31477
31475
  const valueToParse = value === "." ? "0." : value;
31478
31476
  const [valueUnits = "0", valueDecimals = "0"] = valueToParse.split(".");
31479
31477
  const length = valueDecimals.length;
@@ -31607,6 +31605,7 @@ This unreleased fuel-core build may include features and updates not yet support
31607
31605
  var ENCODING_V1 = "1";
31608
31606
  var WORD_SIZE = 8;
31609
31607
  var BYTES_32 = 32;
31608
+ var UTXO_ID_LEN = BYTES_32 + 1;
31610
31609
  var ASSET_ID_LEN = BYTES_32;
31611
31610
  var ADDRESS_LEN = BYTES_32;
31612
31611
  var NONCE_LEN = BYTES_32;
@@ -31757,15 +31756,6 @@ This unreleased fuel-core build may include features and updates not yet support
31757
31756
  }
31758
31757
  };
31759
31758
  var isHeapType = (type3) => type3 === VEC_CODER_TYPE || type3 === BYTES_CODER_TYPE || type3 === STD_STRING_CODER_TYPE;
31760
- function findOrThrow(arr, predicate, throwFn = () => {
31761
- throw new FuelError(ErrorCode.ELEMENT_NOT_FOUND, "Element not found in the array.");
31762
- }) {
31763
- const found = arr.find(predicate);
31764
- if (found === void 0) {
31765
- throwFn();
31766
- }
31767
- return found;
31768
- }
31769
31759
  var isMultipleOfWordSize = (length) => length % WORD_SIZE === 0;
31770
31760
  var getWordSizePadding = (length) => WORD_SIZE - length % WORD_SIZE;
31771
31761
  var rightPadToWordSize = (encoded) => {
@@ -31775,6 +31765,7 @@ This unreleased fuel-core build may include features and updates not yet support
31775
31765
  const padding = new Uint8Array(WORD_SIZE - encoded.length % WORD_SIZE);
31776
31766
  return concatBytes2([encoded, padding]);
31777
31767
  };
31768
+ var isUint8Array = (value) => value instanceof Uint8Array;
31778
31769
  var ArrayCoder = class extends Coder {
31779
31770
  coder;
31780
31771
  length;
@@ -31918,9 +31909,6 @@ This unreleased fuel-core build may include features and updates not yet support
31918
31909
  __privateAdd2(this, _getPaddedData);
31919
31910
  }
31920
31911
  encode(value) {
31921
- if (!Array.isArray(value)) {
31922
- throw new FuelError(ErrorCode.ENCODE_ERROR, `Expected array value.`);
31923
- }
31924
31912
  const parts = [];
31925
31913
  const pointer = new BigNumberCoder("u64").encode(BASE_VECTOR_OFFSET);
31926
31914
  const data = __privateMethod2(this, _getPaddedData, getPaddedData_fn).call(this, value);
@@ -31947,7 +31935,7 @@ This unreleased fuel-core build may include features and updates not yet support
31947
31935
  };
31948
31936
  _getPaddedData = /* @__PURE__ */ new WeakSet();
31949
31937
  getPaddedData_fn = function(value) {
31950
- const data = [Uint8Array.from(value)];
31938
+ const data = value instanceof Uint8Array ? [value] : [new Uint8Array(value)];
31951
31939
  const paddingLength = (WORD_SIZE - value.length % WORD_SIZE) % WORD_SIZE;
31952
31940
  if (paddingLength) {
31953
31941
  data.push(new Uint8Array(paddingLength));
@@ -31970,7 +31958,7 @@ This unreleased fuel-core build may include features and updates not yet support
31970
31958
  (max2, coder) => Math.max(max2, coder.encodedLength),
31971
31959
  0
31972
31960
  );
31973
- super("enum", `enum ${name}`, caseIndexCoder.encodedLength + encodedValueSize);
31961
+ super(`enum ${name}`, `enum ${name}`, caseIndexCoder.encodedLength + encodedValueSize);
31974
31962
  this.name = name;
31975
31963
  this.coders = coders;
31976
31964
  this.#caseIndexCoder = caseIndexCoder;
@@ -32040,7 +32028,7 @@ This unreleased fuel-core build may include features and updates not yet support
32040
32028
  return { None: [] };
32041
32029
  }
32042
32030
  decode(data, offset) {
32043
- if (data.length < this.encodedLength - 1) {
32031
+ if (data.length < this.encodedLength) {
32044
32032
  throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid option data size.`);
32045
32033
  }
32046
32034
  const [decoded, newOffset] = super.decode(data, offset);
@@ -32319,8 +32307,11 @@ This unreleased fuel-core build may include features and updates not yet support
32319
32307
  this.coder = coder;
32320
32308
  }
32321
32309
  encode(value) {
32322
- if (!Array.isArray(value)) {
32323
- throw new FuelError(ErrorCode.ENCODE_ERROR, `Expected array value.`);
32310
+ if (!Array.isArray(value) && !isUint8Array(value)) {
32311
+ throw new FuelError(
32312
+ ErrorCode.ENCODE_ERROR,
32313
+ `Expected array value, or a Uint8Array. You can use arrayify to convert a value to a Uint8Array.`
32314
+ );
32324
32315
  }
32325
32316
  const parts = [];
32326
32317
  const pointer = new BigNumberCoder("u64").encode(BASE_VECTOR_OFFSET);
@@ -32351,6 +32342,38 @@ This unreleased fuel-core build may include features and updates not yet support
32351
32342
  ];
32352
32343
  }
32353
32344
  };
32345
+ var findFunctionByName = (abi, name) => {
32346
+ const fn = abi.functions.find((f2) => f2.name === name);
32347
+ if (!fn) {
32348
+ throw new FuelError(
32349
+ ErrorCode.FUNCTION_NOT_FOUND,
32350
+ `Function with name '${name}' doesn't exist in the ABI`
32351
+ );
32352
+ }
32353
+ return fn;
32354
+ };
32355
+ var findTypeById = (abi, typeId) => {
32356
+ const type3 = abi.types.find((t) => t.typeId === typeId);
32357
+ if (!type3) {
32358
+ throw new FuelError(
32359
+ ErrorCode.TYPE_NOT_FOUND,
32360
+ `Type with typeId '${typeId}' doesn't exist in the ABI.`
32361
+ );
32362
+ }
32363
+ return type3;
32364
+ };
32365
+ var findNonEmptyInputs = (abi, inputs) => inputs.filter((input) => findTypeById(abi, input.type).type !== "()");
32366
+ var findVectorBufferArgument = (components) => {
32367
+ const bufferComponent = components.find((c) => c.name === "buf");
32368
+ const bufferTypeArgument = bufferComponent?.originalTypeArguments?.[0];
32369
+ if (!bufferComponent || !bufferTypeArgument) {
32370
+ throw new FuelError(
32371
+ ErrorCode.INVALID_COMPONENT,
32372
+ `The Vec type provided is missing or has a malformed 'buf' component.`
32373
+ );
32374
+ }
32375
+ return bufferTypeArgument;
32376
+ };
32354
32377
  var ResolvedAbiType = class {
32355
32378
  abi;
32356
32379
  name;
@@ -32359,20 +32382,8 @@ This unreleased fuel-core build may include features and updates not yet support
32359
32382
  components;
32360
32383
  constructor(abi, argument) {
32361
32384
  this.abi = abi;
32362
- const type3 = findOrThrow(
32363
- abi.types,
32364
- (t) => t.typeId === argument.type,
32365
- () => {
32366
- throw new FuelError(
32367
- ErrorCode.TYPE_NOT_FOUND,
32368
- `Type does not exist in the provided abi: ${JSON.stringify({
32369
- argument,
32370
- abi: this.abi
32371
- })}`
32372
- );
32373
- }
32374
- );
32375
32385
  this.name = argument.name;
32386
+ const type3 = findTypeById(abi, argument.type);
32376
32387
  this.type = type3.type;
32377
32388
  this.originalTypeArguments = argument.typeArguments;
32378
32389
  this.components = ResolvedAbiType.getResolvedGenericComponents(
@@ -32424,7 +32435,7 @@ This unreleased fuel-core build may include features and updates not yet support
32424
32435
  )
32425
32436
  };
32426
32437
  }
32427
- const argType = findOrThrow(abi.types, (t) => t.typeId === arg.type);
32438
+ const argType = findTypeById(abi, arg.type);
32428
32439
  const implicitTypeParameters = this.getImplicitGenericTypeParameters(abi, argType.components);
32429
32440
  if (implicitTypeParameters && implicitTypeParameters.length > 0) {
32430
32441
  return {
@@ -32441,7 +32452,7 @@ This unreleased fuel-core build may include features and updates not yet support
32441
32452
  }
32442
32453
  const implicitGenericParameters = implicitGenericParametersParam ?? [];
32443
32454
  args.forEach((a) => {
32444
- const argType = findOrThrow(abi.types, (t) => t.typeId === a.type);
32455
+ const argType = findTypeById(abi, a.type);
32445
32456
  if (genericRegEx.test(argType.type)) {
32446
32457
  implicitGenericParameters.push(argType.typeId);
32447
32458
  return;
@@ -32550,13 +32561,7 @@ This unreleased fuel-core build may include features and updates not yet support
32550
32561
  return new ArrayCoder(arrayElementCoder, length);
32551
32562
  }
32552
32563
  if (resolvedAbiType.type === VEC_CODER_TYPE) {
32553
- const arg = findOrThrow(components, (c) => c.name === "buf").originalTypeArguments?.[0];
32554
- if (!arg) {
32555
- throw new FuelError(
32556
- ErrorCode.INVALID_COMPONENT,
32557
- `The provided Vec type is missing the 'type argument'.`
32558
- );
32559
- }
32564
+ const arg = findVectorBufferArgument(components);
32560
32565
  const argType = new ResolvedAbiType(resolvedAbiType.abi, arg);
32561
32566
  const itemCoder = getCoder(argType, { isSmallBytes: true, encoding: ENCODING_V0 });
32562
32567
  return new VecCoder(itemCoder);
@@ -32623,11 +32628,8 @@ This unreleased fuel-core build may include features and updates not yet support
32623
32628
  super("struct", "struct Bytes", WORD_SIZE);
32624
32629
  }
32625
32630
  encode(value) {
32626
- if (!Array.isArray(value)) {
32627
- throw new FuelError(ErrorCode.ENCODE_ERROR, `Expected array value.`);
32628
- }
32629
- const bytes3 = new Uint8Array(value);
32630
- const lengthBytes = new BigNumberCoder("u64").encode(value.length);
32631
+ const bytes3 = value instanceof Uint8Array ? value : new Uint8Array(value);
32632
+ const lengthBytes = new BigNumberCoder("u64").encode(bytes3.length);
32631
32633
  return new Uint8Array([...lengthBytes, ...bytes3]);
32632
32634
  }
32633
32635
  decode(data, offset) {
@@ -32660,7 +32662,7 @@ This unreleased fuel-core build may include features and updates not yet support
32660
32662
  (max2, coder) => Math.max(max2, coder.encodedLength),
32661
32663
  0
32662
32664
  );
32663
- super("enum", `enum ${name}`, caseIndexCoder.encodedLength + encodedValueSize);
32665
+ super(`enum ${name}`, `enum ${name}`, caseIndexCoder.encodedLength + encodedValueSize);
32664
32666
  this.name = name;
32665
32667
  this.coders = coders;
32666
32668
  this.#caseIndexCoder = caseIndexCoder;
@@ -32758,6 +32760,28 @@ This unreleased fuel-core build may include features and updates not yet support
32758
32760
  return [toNumber2(bytes3), offset + this.length];
32759
32761
  }
32760
32762
  };
32763
+ var OptionCoder2 = class extends EnumCoder2 {
32764
+ encode(value) {
32765
+ const result = super.encode(this.toSwayOption(value));
32766
+ return result;
32767
+ }
32768
+ toSwayOption(input) {
32769
+ if (input !== void 0) {
32770
+ return { Some: input };
32771
+ }
32772
+ return { None: [] };
32773
+ }
32774
+ decode(data, offset) {
32775
+ const [decoded, newOffset] = super.decode(data, offset);
32776
+ return [this.toOption(decoded), newOffset];
32777
+ }
32778
+ toOption(output3) {
32779
+ if (output3 && "Some" in output3) {
32780
+ return output3.Some;
32781
+ }
32782
+ return void 0;
32783
+ }
32784
+ };
32761
32785
  var RawSliceCoder2 = class extends Coder {
32762
32786
  constructor() {
32763
32787
  super("raw untyped slice", "raw untyped slice", WORD_SIZE);
@@ -32811,6 +32835,30 @@ This unreleased fuel-core build may include features and updates not yet support
32811
32835
  }
32812
32836
  };
32813
32837
  __publicField4(StdStringCoder2, "memorySize", 1);
32838
+ var StrSliceCoder = class extends Coder {
32839
+ constructor() {
32840
+ super("strSlice", "str", WORD_SIZE);
32841
+ }
32842
+ encode(value) {
32843
+ const bytes3 = toUtf8Bytes(value);
32844
+ const lengthBytes = new BigNumberCoder("u64").encode(value.length);
32845
+ return new Uint8Array([...lengthBytes, ...bytes3]);
32846
+ }
32847
+ decode(data, offset) {
32848
+ if (data.length < this.encodedLength) {
32849
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid string slice data size.`);
32850
+ }
32851
+ const offsetAndLength = offset + WORD_SIZE;
32852
+ const lengthBytes = data.slice(offset, offsetAndLength);
32853
+ const length = bn(new BigNumberCoder("u64").decode(lengthBytes, 0)[0]).toNumber();
32854
+ const bytes3 = data.slice(offsetAndLength, offsetAndLength + length);
32855
+ if (bytes3.length !== length) {
32856
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid string slice byte data size.`);
32857
+ }
32858
+ return [toUtf8String(bytes3), offsetAndLength + length];
32859
+ }
32860
+ };
32861
+ __publicField4(StrSliceCoder, "memorySize", 1);
32814
32862
  var StringCoder2 = class extends Coder {
32815
32863
  constructor(length) {
32816
32864
  super("string", `str[${length}]`, length);
@@ -32849,7 +32897,7 @@ This unreleased fuel-core build may include features and updates not yet support
32849
32897
  Object.keys(this.coders).map((fieldName) => {
32850
32898
  const fieldCoder = this.coders[fieldName];
32851
32899
  const fieldValue = value[fieldName];
32852
- if (!(fieldCoder instanceof OptionCoder) && fieldValue == null) {
32900
+ if (!(fieldCoder instanceof OptionCoder2) && fieldValue == null) {
32853
32901
  throw new FuelError(
32854
32902
  ErrorCode.ENCODE_ERROR,
32855
32903
  `Invalid ${this.type}. Field "${fieldName}" not present.`
@@ -32957,6 +33005,8 @@ This unreleased fuel-core build may include features and updates not yet support
32957
33005
  return new ByteCoder2();
32958
33006
  case STD_STRING_CODER_TYPE:
32959
33007
  return new StdStringCoder2();
33008
+ case STR_SLICE_CODER_TYPE:
33009
+ return new StrSliceCoder();
32960
33010
  default:
32961
33011
  break;
32962
33012
  }
@@ -32980,13 +33030,7 @@ This unreleased fuel-core build may include features and updates not yet support
32980
33030
  return new ArrayCoder(arrayElementCoder, length);
32981
33031
  }
32982
33032
  if (resolvedAbiType.type === VEC_CODER_TYPE) {
32983
- const arg = findOrThrow(components, (c) => c.name === "buf").originalTypeArguments?.[0];
32984
- if (!arg) {
32985
- throw new FuelError(
32986
- ErrorCode.INVALID_COMPONENT,
32987
- `The provided Vec type is missing the 'type argument'.`
32988
- );
32989
- }
33033
+ const arg = findVectorBufferArgument(components);
32990
33034
  const argType = new ResolvedAbiType(resolvedAbiType.abi, arg);
32991
33035
  const itemCoder = getCoder2(argType, { isSmallBytes: true, encoding: ENCODING_V0 });
32992
33036
  return new VecCoder2(itemCoder);
@@ -33001,7 +33045,7 @@ This unreleased fuel-core build may include features and updates not yet support
33001
33045
  const coders = getCoders(components, { getCoder: getCoder2 });
33002
33046
  const isOptionEnum = resolvedAbiType.type === OPTION_CODER_TYPE;
33003
33047
  if (isOptionEnum) {
33004
- return new OptionCoder(enumMatch.name, coders);
33048
+ return new OptionCoder2(enumMatch.name, coders);
33005
33049
  }
33006
33050
  return new EnumCoder2(enumMatch.name, coders);
33007
33051
  }
@@ -33012,12 +33056,6 @@ This unreleased fuel-core build may include features and updates not yet support
33012
33056
  );
33013
33057
  return new TupleCoder2(coders);
33014
33058
  }
33015
- if (resolvedAbiType.type === STR_SLICE_CODER_TYPE) {
33016
- throw new FuelError(
33017
- ErrorCode.INVALID_DATA,
33018
- "String slices can not be decoded from logs. Convert the slice to `str[N]` with `__to_str_array`"
33019
- );
33020
- }
33021
33059
  throw new FuelError(
33022
33060
  ErrorCode.CODER_NOT_FOUND,
33023
33061
  `Coder not found: ${JSON.stringify(resolvedAbiType)}.`
@@ -33053,6 +33091,8 @@ This unreleased fuel-core build may include features and updates not yet support
33053
33091
  var FunctionFragment = class {
33054
33092
  signature;
33055
33093
  selector;
33094
+ selectorBytes;
33095
+ encoding;
33056
33096
  name;
33057
33097
  jsonFn;
33058
33098
  attributes;
@@ -33061,10 +33101,12 @@ This unreleased fuel-core build may include features and updates not yet support
33061
33101
  jsonAbi;
33062
33102
  constructor(jsonAbi, name) {
33063
33103
  this.jsonAbi = jsonAbi;
33064
- this.jsonFn = findOrThrow(this.jsonAbi.functions, (f2) => f2.name === name);
33104
+ this.jsonFn = findFunctionByName(this.jsonAbi, name);
33065
33105
  this.name = name;
33066
33106
  this.signature = FunctionFragment.getSignature(this.jsonAbi, this.jsonFn);
33067
33107
  this.selector = FunctionFragment.getFunctionSelector(this.signature);
33108
+ this.selectorBytes = new StdStringCoder2().encode(name);
33109
+ this.encoding = this.jsonAbi.encoding ?? ENCODING_V0;
33068
33110
  this.isInputDataPointer = this.#isInputDataPointer();
33069
33111
  this.outputMetadata = {
33070
33112
  isHeapType: this.#isOutputDataHeap(),
@@ -33083,13 +33125,11 @@ This unreleased fuel-core build may include features and updates not yet support
33083
33125
  return bn(hashedFunctionSignature.slice(0, 10)).toHex(8);
33084
33126
  }
33085
33127
  #isInputDataPointer() {
33086
- const inputTypes = this.jsonFn.inputs.map(
33087
- (i) => this.jsonAbi.types.find((t) => t.typeId === i.type)
33088
- );
33128
+ const inputTypes = this.jsonFn.inputs.map((i) => findTypeById(this.jsonAbi, i.type));
33089
33129
  return this.jsonFn.inputs.length > 1 || isPointerType(inputTypes[0]?.type || "");
33090
33130
  }
33091
33131
  #isOutputDataHeap() {
33092
- const outputType = findOrThrow(this.jsonAbi.types, (t) => t.typeId === this.jsonFn.output.type);
33132
+ const outputType = findTypeById(this.jsonAbi, this.jsonFn.output.type);
33093
33133
  return isHeapType(outputType?.type || "");
33094
33134
  }
33095
33135
  #getOutputEncodedLength() {
@@ -33109,27 +33149,28 @@ This unreleased fuel-core build may include features and updates not yet support
33109
33149
  encodeArguments(values, offset = 0) {
33110
33150
  FunctionFragment.verifyArgsAndInputsAlign(values, this.jsonFn.inputs, this.jsonAbi);
33111
33151
  const shallowCopyValues = values.slice();
33112
- const nonEmptyInputs = this.jsonFn.inputs.filter(
33113
- (x) => findOrThrow(this.jsonAbi.types, (t) => t.typeId === x.type).type !== "()"
33114
- );
33152
+ const nonEmptyInputs = findNonEmptyInputs(this.jsonAbi, this.jsonFn.inputs);
33115
33153
  if (Array.isArray(values) && nonEmptyInputs.length !== values.length) {
33116
33154
  shallowCopyValues.length = this.jsonFn.inputs.length;
33117
33155
  shallowCopyValues.fill(void 0, values.length);
33118
33156
  }
33119
33157
  const coders = nonEmptyInputs.map(
33120
33158
  (t) => AbiCoder.getCoder(this.jsonAbi, t, {
33121
- isRightPadded: nonEmptyInputs.length > 1
33159
+ isRightPadded: nonEmptyInputs.length > 1,
33160
+ encoding: this.encoding
33122
33161
  })
33123
33162
  );
33124
- const coder = new TupleCoder(coders);
33125
- const results = coder.encode(shallowCopyValues);
33163
+ if (this.encoding === ENCODING_V1) {
33164
+ return new TupleCoder2(coders).encode(shallowCopyValues);
33165
+ }
33166
+ const results = new TupleCoder(coders).encode(shallowCopyValues);
33126
33167
  return unpackDynamicData(results, offset, results.byteLength);
33127
33168
  }
33128
33169
  static verifyArgsAndInputsAlign(args, inputs, abi) {
33129
33170
  if (args.length === inputs.length) {
33130
33171
  return;
33131
33172
  }
33132
- const inputTypes = inputs.map((i) => findOrThrow(abi.types, (t) => t.typeId === i.type));
33173
+ const inputTypes = inputs.map((input) => findTypeById(abi, input.type));
33133
33174
  const optionalInputs = inputTypes.filter(
33134
33175
  (x) => x.type === OPTION_CODER_TYPE || x.type === "()"
33135
33176
  );
@@ -33144,9 +33185,7 @@ This unreleased fuel-core build may include features and updates not yet support
33144
33185
  }
33145
33186
  decodeArguments(data) {
33146
33187
  const bytes3 = arrayify(data);
33147
- const nonEmptyInputs = this.jsonFn.inputs.filter(
33148
- (x) => findOrThrow(this.jsonAbi.types, (t) => t.typeId === x.type).type !== "()"
33149
- );
33188
+ const nonEmptyInputs = findNonEmptyInputs(this.jsonAbi, this.jsonFn.inputs);
33150
33189
  if (nonEmptyInputs.length === 0) {
33151
33190
  if (bytes3.length === 0) {
33152
33191
  return void 0;
@@ -33169,7 +33208,7 @@ This unreleased fuel-core build may include features and updates not yet support
33169
33208
  }
33170
33209
  const result = nonEmptyInputs.reduce(
33171
33210
  (obj, input) => {
33172
- const coder = AbiCoder.getCoder(this.jsonAbi, input);
33211
+ const coder = AbiCoder.getCoder(this.jsonAbi, input, { encoding: this.encoding });
33173
33212
  const [decodedValue, decodedValueByteSize] = coder.decode(bytes3, obj.offset);
33174
33213
  return {
33175
33214
  decoded: [...obj.decoded, decodedValue],
@@ -33181,33 +33220,32 @@ This unreleased fuel-core build may include features and updates not yet support
33181
33220
  return result.decoded;
33182
33221
  }
33183
33222
  decodeOutput(data) {
33184
- const outputAbiType = findOrThrow(
33185
- this.jsonAbi.types,
33186
- (t) => t.typeId === this.jsonFn.output.type
33187
- );
33223
+ const outputAbiType = findTypeById(this.jsonAbi, this.jsonFn.output.type);
33188
33224
  if (outputAbiType.type === "()") {
33189
33225
  return [void 0, 0];
33190
33226
  }
33191
33227
  const bytes3 = arrayify(data);
33192
- const coder = AbiCoder.getCoder(this.jsonAbi, this.jsonFn.output);
33228
+ const coder = AbiCoder.getCoder(this.jsonAbi, this.jsonFn.output, {
33229
+ encoding: this.encoding
33230
+ });
33193
33231
  return coder.decode(bytes3, 0);
33194
33232
  }
33233
+ /**
33234
+ * Checks if the function is read-only i.e. it only reads from storage, does not write to it.
33235
+ *
33236
+ * @returns True if the function is read-only or pure, false otherwise.
33237
+ */
33238
+ isReadOnly() {
33239
+ const storageAttribute = this.attributes.find((attr) => attr.name === "storage");
33240
+ return !storageAttribute?.arguments.includes("write");
33241
+ }
33195
33242
  };
33196
33243
  var Interface = class {
33197
33244
  functions;
33198
33245
  configurables;
33199
- /*
33200
- TODO: Refactor so that there's no need for externalLoggedTypes
33201
-
33202
- This is dedicated to external contracts added via `<base-invocation-scope.ts>.addContracts()` method.
33203
- This is used to decode logs from contracts other than the main contract
33204
- we're interacting with.
33205
- */
33206
- externalLoggedTypes;
33207
33246
  jsonAbi;
33208
33247
  constructor(jsonAbi) {
33209
33248
  this.jsonAbi = jsonAbi;
33210
- this.externalLoggedTypes = {};
33211
33249
  this.functions = Object.fromEntries(
33212
33250
  this.jsonAbi.functions.map((x) => [x.name, new FunctionFragment(this.jsonAbi, x.name)])
33213
33251
  );
@@ -33231,16 +33269,10 @@ This unreleased fuel-core build may include features and updates not yet support
33231
33269
  }
33232
33270
  decodeFunctionData(functionFragment, data) {
33233
33271
  const fragment = typeof functionFragment === "string" ? this.getFunction(functionFragment) : functionFragment;
33234
- if (!fragment) {
33235
- throw new FuelError(ErrorCode.FRAGMENT_NOT_FOUND, "Fragment not found.");
33236
- }
33237
33272
  return fragment.decodeArguments(data);
33238
33273
  }
33239
33274
  encodeFunctionData(functionFragment, values, offset = 0) {
33240
33275
  const fragment = typeof functionFragment === "string" ? this.getFunction(functionFragment) : functionFragment;
33241
- if (!fragment) {
33242
- throw new FuelError(ErrorCode.FRAGMENT_NOT_FOUND, "Fragment not found.");
33243
- }
33244
33276
  return fragment.encodeArguments(values, offset);
33245
33277
  }
33246
33278
  // Decode the result of a function call
@@ -33248,46 +33280,34 @@ This unreleased fuel-core build may include features and updates not yet support
33248
33280
  const fragment = typeof functionFragment === "string" ? this.getFunction(functionFragment) : functionFragment;
33249
33281
  return fragment.decodeOutput(data);
33250
33282
  }
33251
- decodeLog(data, logId, receiptId) {
33252
- const isExternalLoggedType = this.externalLoggedTypes[receiptId];
33253
- if (isExternalLoggedType) {
33254
- const externalInterface = this.externalLoggedTypes[receiptId];
33255
- return externalInterface.decodeLog(data, logId, receiptId);
33283
+ decodeLog(data, logId) {
33284
+ const loggedType = this.jsonAbi.loggedTypes.find((type3) => type3.logId === logId);
33285
+ if (!loggedType) {
33286
+ throw new FuelError(
33287
+ ErrorCode.LOG_TYPE_NOT_FOUND,
33288
+ `Log type with logId '${logId}' doesn't exist in the ABI.`
33289
+ );
33256
33290
  }
33257
- const { loggedType } = findOrThrow(this.jsonAbi.loggedTypes, (type3) => type3.logId === logId);
33258
- return AbiCoder.decode(this.jsonAbi, loggedType, arrayify(data), 0, {
33291
+ return AbiCoder.decode(this.jsonAbi, loggedType.loggedType, arrayify(data), 0, {
33259
33292
  encoding: this.jsonAbi.encoding
33260
33293
  });
33261
33294
  }
33262
- updateExternalLoggedTypes(id, loggedTypes) {
33263
- this.externalLoggedTypes[id] = loggedTypes;
33264
- }
33265
33295
  encodeConfigurable(name, value) {
33266
- const configurable = findOrThrow(
33267
- this.jsonAbi.configurables,
33268
- (c) => c.name === name,
33269
- () => {
33270
- throw new FuelError(
33271
- ErrorCode.CONFIGURABLE_NOT_FOUND,
33272
- `A configurable with the '${name}' was not found in the ABI.`
33273
- );
33274
- }
33275
- );
33296
+ const configurable = this.jsonAbi.configurables.find((c) => c.name === name);
33297
+ if (!configurable) {
33298
+ throw new FuelError(
33299
+ ErrorCode.CONFIGURABLE_NOT_FOUND,
33300
+ `A configurable with the '${name}' was not found in the ABI.`
33301
+ );
33302
+ }
33276
33303
  return AbiCoder.encode(this.jsonAbi, configurable.configurableType, value, {
33277
- isRightPadded: true
33304
+ isRightPadded: true,
33305
+ // TODO: Review support for configurables in v1 encoding when it becomes available
33306
+ encoding: ENCODING_V0
33278
33307
  });
33279
33308
  }
33280
33309
  getTypeById(typeId) {
33281
- return findOrThrow(
33282
- this.jsonAbi.types,
33283
- (t) => t.typeId === typeId,
33284
- () => {
33285
- throw new FuelError(
33286
- ErrorCode.TYPE_NOT_FOUND,
33287
- `Type with typeId '${typeId}' doesn't exist in the ABI.`
33288
- );
33289
- }
33290
- );
33310
+ return findTypeById(this.jsonAbi, typeId);
33291
33311
  }
33292
33312
  };
33293
33313
 
@@ -33977,7 +33997,7 @@ This unreleased fuel-core build may include features and updates not yet support
33977
33997
  return [receiptMessageOut, o];
33978
33998
  }
33979
33999
  };
33980
- var getAssetId = (contractId, subId) => {
34000
+ var getMintedAssetId = (contractId, subId) => {
33981
34001
  const contractIdBytes = arrayify(contractId);
33982
34002
  const subIdBytes = arrayify(subId);
33983
34003
  return sha2563(concat([contractIdBytes, subIdBytes]));
@@ -33987,7 +34007,7 @@ This unreleased fuel-core build may include features and updates not yet support
33987
34007
  super("ReceiptMint", "struct ReceiptMint", 0);
33988
34008
  }
33989
34009
  static getAssetId(contractId, subId) {
33990
- return getAssetId(contractId, subId);
34010
+ return getMintedAssetId(contractId, subId);
33991
34011
  }
33992
34012
  encode(value) {
33993
34013
  const parts = [];
@@ -34029,7 +34049,7 @@ This unreleased fuel-core build may include features and updates not yet support
34029
34049
  super("ReceiptBurn", "struct ReceiptBurn", 0);
34030
34050
  }
34031
34051
  static getAssetId(contractId, subId) {
34032
- return getAssetId(contractId, subId);
34052
+ return getMintedAssetId(contractId, subId);
34033
34053
  }
34034
34054
  encode(value) {
34035
34055
  const parts = [];
@@ -38854,8 +38874,8 @@ ${MessageCoinFragmentFragmentDoc}`;
38854
38874
  const predicateData = arrayify(value.predicateData ?? "0x");
38855
38875
  return {
38856
38876
  type: InputType.Coin,
38857
- txID: hexlify(arrayify(value.id).slice(0, 32)),
38858
- outputIndex: arrayify(value.id)[32],
38877
+ txID: hexlify(arrayify(value.id).slice(0, BYTES_32)),
38878
+ outputIndex: toNumber2(arrayify(value.id).slice(BYTES_32, UTXO_ID_LEN)),
38859
38879
  owner: hexlify(value.owner),
38860
38880
  amount: bn(value.amount),
38861
38881
  assetId: hexlify(value.assetId),
@@ -38979,7 +38999,60 @@ ${MessageCoinFragmentFragmentDoc}`;
38979
38999
  var MAX_SCRIPT_DATA_LENGTH = 1024 * 1024 * 1024;
38980
39000
  var MAX_PREDICATE_LENGTH = 1024 * 1024;
38981
39001
  var MAX_PREDICATE_DATA_LENGTH = 1024 * 1024;
39002
+ var FAILED_REQUIRE_SIGNAL = "0xffffffffffff0000";
38982
39003
  var FAILED_TRANSFER_TO_ADDRESS_SIGNAL = "0xffffffffffff0001";
39004
+ var FAILED_ASSERT_EQ_SIGNAL = "0xffffffffffff0003";
39005
+ var FAILED_ASSERT_SIGNAL = "0xffffffffffff0004";
39006
+ var FAILED_ASSERT_NE_SIGNAL = "0xffffffffffff0005";
39007
+ var PANIC_REASONS = [
39008
+ "UnknownPanicReason",
39009
+ "Revert",
39010
+ "OutOfGas",
39011
+ "TransactionValidity",
39012
+ "MemoryOverflow",
39013
+ "ArithmeticOverflow",
39014
+ "ContractNotFound",
39015
+ "MemoryOwnership",
39016
+ "NotEnoughBalance",
39017
+ "ExpectedInternalContext",
39018
+ "AssetIdNotFound",
39019
+ "InputNotFound",
39020
+ "OutputNotFound",
39021
+ "WitnessNotFound",
39022
+ "TransactionMaturity",
39023
+ "InvalidMetadataIdentifier",
39024
+ "MalformedCallStructure",
39025
+ "ReservedRegisterNotWritable",
39026
+ "InvalidFlags",
39027
+ "InvalidImmediateValue",
39028
+ "ExpectedCoinInput",
39029
+ "EcalError",
39030
+ "MemoryWriteOverlap",
39031
+ "ContractNotInInputs",
39032
+ "InternalBalanceOverflow",
39033
+ "ContractMaxSize",
39034
+ "ExpectedUnallocatedStack",
39035
+ "MaxStaticContractsReached",
39036
+ "TransferAmountCannotBeZero",
39037
+ "ExpectedOutputVariable",
39038
+ "ExpectedParentInternalContext",
39039
+ "PredicateReturnedNonOne",
39040
+ "ContractIdAlreadyDeployed",
39041
+ "ContractMismatch",
39042
+ "MessageDataTooLong",
39043
+ "ArithmeticError",
39044
+ "ContractInstructionNotAllowed",
39045
+ "TransferZeroCoins",
39046
+ "InvalidInstruction",
39047
+ "MemoryNotExecutable",
39048
+ "PolicyIsNotSet",
39049
+ "PolicyNotFound",
39050
+ "TooManyReceipts",
39051
+ "BalanceOverflow",
39052
+ "InvalidBlockHeight",
39053
+ "TooManySlots"
39054
+ ];
39055
+ var PANIC_DOC_URL = "https://docs.rs/fuel-asm/latest/fuel_asm/enum.PanicReason.html";
38983
39056
 
38984
39057
  // src/providers/utils/receipts.ts
38985
39058
  var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === ReceiptType.Revert && receipt.val.toString("hex") === FAILED_TRANSFER_TO_ADDRESS_SIGNAL;
@@ -39353,6 +39426,74 @@ ${MessageCoinFragmentFragmentDoc}`;
39353
39426
  });
39354
39427
  }
39355
39428
 
39429
+ // src/providers/utils/extract-tx-error.ts
39430
+ var assemblePanicError = (status) => {
39431
+ let errorMessage = `The transaction reverted with reason: "${status.reason}".`;
39432
+ const reason = status.reason;
39433
+ if (PANIC_REASONS.includes(status.reason)) {
39434
+ errorMessage = `${errorMessage}
39435
+
39436
+ You can read more about this error at:
39437
+
39438
+ ${PANIC_DOC_URL}#variant.${status.reason}`;
39439
+ }
39440
+ return { errorMessage, reason };
39441
+ };
39442
+ var stringify2 = (obj) => JSON.stringify(obj, null, 2);
39443
+ var assembleRevertError = (receipts, logs) => {
39444
+ let errorMessage = "The transaction reverted with an unknown reason.";
39445
+ const revertReceipt = receipts.find(({ type: type3 }) => type3 === ReceiptType.Revert);
39446
+ let reason = "";
39447
+ if (revertReceipt) {
39448
+ const reasonHex = bn(revertReceipt.val).toHex();
39449
+ switch (reasonHex) {
39450
+ case FAILED_REQUIRE_SIGNAL: {
39451
+ reason = "require";
39452
+ errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify2(logs[0]) : "an error."}.`;
39453
+ break;
39454
+ }
39455
+ case FAILED_ASSERT_EQ_SIGNAL: {
39456
+ const sufix = logs.length >= 2 ? ` comparing ${stringify2(logs[1])} and ${stringify2(logs[0])}.` : ".";
39457
+ reason = "assert_eq";
39458
+ errorMessage = `The transaction reverted because of an "assert_eq" statement${sufix}`;
39459
+ break;
39460
+ }
39461
+ case FAILED_ASSERT_NE_SIGNAL: {
39462
+ const sufix = logs.length >= 2 ? ` comparing ${stringify2(logs[1])} and ${stringify2(logs[0])}.` : ".";
39463
+ reason = "assert_ne";
39464
+ errorMessage = `The transaction reverted because of an "assert_ne" statement${sufix}`;
39465
+ break;
39466
+ }
39467
+ case FAILED_ASSERT_SIGNAL:
39468
+ reason = "assert";
39469
+ errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
39470
+ break;
39471
+ case FAILED_TRANSFER_TO_ADDRESS_SIGNAL:
39472
+ reason = "MissingOutputChange";
39473
+ errorMessage = `The transaction reverted because it's missing an "OutputChange".`;
39474
+ break;
39475
+ default:
39476
+ reason = "unknown";
39477
+ errorMessage = `The transaction reverted with an unknown reason: ${revertReceipt.val}`;
39478
+ }
39479
+ }
39480
+ return { errorMessage, reason };
39481
+ };
39482
+ var extractTxError = (params) => {
39483
+ const { receipts, status, logs } = params;
39484
+ const isPanic = receipts.some(({ type: type3 }) => type3 === ReceiptType.Panic);
39485
+ const isRevert = receipts.some(({ type: type3 }) => type3 === ReceiptType.Revert);
39486
+ const { errorMessage, reason } = status?.type === "FailureStatus" && isPanic ? assemblePanicError(status) : assembleRevertError(receipts, logs);
39487
+ const metadata = {
39488
+ logs,
39489
+ receipts,
39490
+ panic: isPanic,
39491
+ revert: isRevert,
39492
+ reason
39493
+ };
39494
+ return new FuelError(ErrorCode.SCRIPT_REVERTED, errorMessage, metadata);
39495
+ };
39496
+
39356
39497
  // src/providers/transaction-request/errors.ts
39357
39498
  var ChangeOutputCollisionError = class extends Error {
39358
39499
  name = "ChangeOutputCollisionError";
@@ -39633,8 +39774,7 @@ ${MessageCoinFragmentFragmentDoc}`;
39633
39774
  assetId,
39634
39775
  txPointer: "0x00000000000000000000000000000000",
39635
39776
  witnessIndex,
39636
- predicate: predicate?.bytes,
39637
- predicateData: predicate?.predicateDataBytes
39777
+ predicate: predicate?.bytes
39638
39778
  };
39639
39779
  this.pushInput(input);
39640
39780
  this.addChangeOutput(owner, assetId);
@@ -39666,8 +39806,7 @@ ${MessageCoinFragmentFragmentDoc}`;
39666
39806
  recipient: recipient.toB256(),
39667
39807
  amount,
39668
39808
  witnessIndex,
39669
- predicate: predicate?.bytes,
39670
- predicateData: predicate?.predicateDataBytes
39809
+ predicate: predicate?.bytes
39671
39810
  };
39672
39811
  this.pushInput(input);
39673
39812
  this.addChangeOutput(recipient, assetId);
@@ -39822,12 +39961,6 @@ ${MessageCoinFragmentFragmentDoc}`;
39822
39961
  * @param quantities - CoinQuantity Array.
39823
39962
  */
39824
39963
  fundWithFakeUtxos(quantities, resourcesOwner) {
39825
- let idCounter = 0;
39826
- const generateId = () => {
39827
- const counterString = String(idCounter++);
39828
- const id = ZeroBytes32.slice(0, -counterString.length).concat(counterString);
39829
- return id;
39830
- };
39831
39964
  const findAssetInput = (assetId) => this.inputs.find((input) => {
39832
39965
  if ("assetId" in input) {
39833
39966
  return input.assetId === assetId;
@@ -39837,12 +39970,12 @@ ${MessageCoinFragmentFragmentDoc}`;
39837
39970
  const updateAssetInput = (assetId, quantity) => {
39838
39971
  const assetInput = findAssetInput(assetId);
39839
39972
  if (assetInput && "assetId" in assetInput) {
39840
- assetInput.id = generateId();
39973
+ assetInput.id = hexlify(randomBytes22(UTXO_ID_LEN));
39841
39974
  assetInput.amount = quantity;
39842
39975
  } else {
39843
39976
  this.addResources([
39844
39977
  {
39845
- id: generateId(),
39978
+ id: hexlify(randomBytes22(UTXO_ID_LEN)),
39846
39979
  amount: quantity,
39847
39980
  assetId,
39848
39981
  owner: resourcesOwner || Address.fromRandom(),
@@ -40124,6 +40257,7 @@ ${MessageCoinFragmentFragmentDoc}`;
40124
40257
  script;
40125
40258
  /** Script input data (parameters) */
40126
40259
  scriptData;
40260
+ abis;
40127
40261
  /**
40128
40262
  * Constructor for `ScriptTransactionRequest`.
40129
40263
  *
@@ -40134,6 +40268,7 @@ ${MessageCoinFragmentFragmentDoc}`;
40134
40268
  this.gasLimit = bn(gasLimit);
40135
40269
  this.script = arrayify(script ?? returnZeroScript.bytes);
40136
40270
  this.scriptData = arrayify(scriptData ?? returnZeroScript.encodeScriptData());
40271
+ this.abis = rest.abis;
40137
40272
  }
40138
40273
  /**
40139
40274
  * Converts the transaction request to a `TransactionScript`.
@@ -41019,6 +41154,19 @@ ${MessageCoinFragmentFragmentDoc}`;
41019
41154
  return transactionSummary;
41020
41155
  }
41021
41156
 
41157
+ // src/providers/transaction-response/getDecodedLogs.ts
41158
+ function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
41159
+ return receipts.reduce((logs, receipt) => {
41160
+ if (receipt.type === ReceiptType.LogData || receipt.type === ReceiptType.Log) {
41161
+ const interfaceToUse = new Interface(externalAbis[receipt.id] || mainAbi);
41162
+ const data = receipt.type === ReceiptType.Log ? new BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
41163
+ const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
41164
+ logs.push(decodedLog);
41165
+ }
41166
+ return logs;
41167
+ }, []);
41168
+ }
41169
+
41022
41170
  // src/providers/transaction-response/transaction-response.ts
41023
41171
  var TransactionResponse2 = class {
41024
41172
  /** Transaction ID */
@@ -41029,15 +41177,17 @@ ${MessageCoinFragmentFragmentDoc}`;
41029
41177
  gasUsed = bn(0);
41030
41178
  /** The graphql Transaction with receipts object. */
41031
41179
  gqlTransaction;
41180
+ abis;
41032
41181
  /**
41033
41182
  * Constructor for `TransactionResponse`.
41034
41183
  *
41035
41184
  * @param id - The transaction ID.
41036
41185
  * @param provider - The provider.
41037
41186
  */
41038
- constructor(id, provider) {
41187
+ constructor(id, provider, abis) {
41039
41188
  this.id = id;
41040
41189
  this.provider = provider;
41190
+ this.abis = abis;
41041
41191
  }
41042
41192
  /**
41043
41193
  * Async constructor for `TransactionResponse`. This method can be used to create
@@ -41047,8 +41197,8 @@ ${MessageCoinFragmentFragmentDoc}`;
41047
41197
  * @param id - The transaction ID.
41048
41198
  * @param provider - The provider.
41049
41199
  */
41050
- static async create(id, provider) {
41051
- const response = new TransactionResponse2(id, provider);
41200
+ static async create(id, provider, abis) {
41201
+ const response = new TransactionResponse2(id, provider, abis);
41052
41202
  await response.fetch();
41053
41203
  return response;
41054
41204
  }
@@ -41152,6 +41302,26 @@ ${MessageCoinFragmentFragmentDoc}`;
41152
41302
  gqlTransaction: this.gqlTransaction,
41153
41303
  ...transactionSummary
41154
41304
  };
41305
+ let logs = [];
41306
+ if (this.abis) {
41307
+ logs = getDecodedLogs(
41308
+ transactionSummary.receipts,
41309
+ this.abis.main,
41310
+ this.abis.otherContractsAbis
41311
+ );
41312
+ transactionResult.logs = logs;
41313
+ }
41314
+ if (transactionResult.isStatusFailure) {
41315
+ const {
41316
+ receipts,
41317
+ gqlTransaction: { status }
41318
+ } = transactionResult;
41319
+ throw extractTxError({
41320
+ receipts,
41321
+ status,
41322
+ logs
41323
+ });
41324
+ }
41155
41325
  return transactionResult;
41156
41326
  }
41157
41327
  /**
@@ -41160,32 +41330,10 @@ ${MessageCoinFragmentFragmentDoc}`;
41160
41330
  * @param contractsAbiMap - The contracts ABI map.
41161
41331
  */
41162
41332
  async wait(contractsAbiMap) {
41163
- const result = await this.waitForResult(contractsAbiMap);
41164
- if (result.isStatusFailure) {
41165
- throw new FuelError(
41166
- ErrorCode.TRANSACTION_FAILED,
41167
- `Transaction failed: ${result.gqlTransaction.status.reason}`
41168
- );
41169
- }
41170
- return result;
41333
+ return this.waitForResult(contractsAbiMap);
41171
41334
  }
41172
41335
  };
41173
41336
 
41174
- // src/providers/transaction-response/getDecodedLogs.ts
41175
- function getDecodedLogs(receipts, abiInterface) {
41176
- return receipts.reduce((logs, r) => {
41177
- if (r.type === ReceiptType.LogData) {
41178
- logs.push(abiInterface.decodeLog(r.data, r.val1.toNumber(), r.id)[0]);
41179
- }
41180
- if (r.type === ReceiptType.Log) {
41181
- logs.push(
41182
- abiInterface.decodeLog(new BigNumberCoder("u64").encode(r.val0), r.val1.toNumber(), r.id)[0]
41183
- );
41184
- }
41185
- return logs;
41186
- }, []);
41187
- }
41188
-
41189
41337
  // src/providers/utils/auto-retry-fetch.ts
41190
41338
  function getWaitDelay(options, retryAttemptNum) {
41191
41339
  const duration = options.baseDelay ?? 150;
@@ -41520,6 +41668,10 @@ ${MessageCoinFragmentFragmentDoc}`;
41520
41668
  await this.estimateTxDependencies(transactionRequest);
41521
41669
  }
41522
41670
  const encodedTransaction = hexlify(transactionRequest.toTransactionBytes());
41671
+ let abis;
41672
+ if (transactionRequest.type === TransactionType.Script) {
41673
+ abis = transactionRequest.abis;
41674
+ }
41523
41675
  if (awaitExecution) {
41524
41676
  const subscription = this.operations.submitAndAwait({ encodedTransaction });
41525
41677
  for await (const { submitAndAwait } of subscription) {
@@ -41534,14 +41686,14 @@ ${MessageCoinFragmentFragmentDoc}`;
41534
41686
  }
41535
41687
  }
41536
41688
  const transactionId2 = transactionRequest.getTransactionId(this.getChainId());
41537
- const response = new TransactionResponse2(transactionId2, this);
41689
+ const response = new TransactionResponse2(transactionId2, this, abis);
41538
41690
  await response.fetch();
41539
41691
  return response;
41540
41692
  }
41541
41693
  const {
41542
41694
  submit: { id: transactionId }
41543
41695
  } = await this.operations.submit({ encodedTransaction });
41544
- return new TransactionResponse2(transactionId, this);
41696
+ return new TransactionResponse2(transactionId, this, abis);
41545
41697
  }
41546
41698
  /**
41547
41699
  * Executes a transaction without actually submitting it to the chain.
@@ -41649,6 +41801,36 @@ ${MessageCoinFragmentFragmentDoc}`;
41649
41801
  missingContractIds
41650
41802
  };
41651
41803
  }
41804
+ /**
41805
+ * Estimates the transaction gas and fee based on the provided transaction request.
41806
+ * @param transactionRequest - The transaction request object.
41807
+ * @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
41808
+ */
41809
+ estimateTxGasAndFee(params) {
41810
+ const { transactionRequest } = params;
41811
+ const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
41812
+ const chainInfo = this.getChain();
41813
+ const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
41814
+ transactionRequest.gasPrice = gasPrice;
41815
+ const minGas = transactionRequest.calculateMinGas(chainInfo);
41816
+ const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
41817
+ if (transactionRequest.type === TransactionType.Script) {
41818
+ if (transactionRequest.gasLimit.eq(0)) {
41819
+ transactionRequest.gasLimit = minGas;
41820
+ transactionRequest.gasLimit = maxGasPerTx.sub(
41821
+ transactionRequest.calculateMaxGas(chainInfo, minGas)
41822
+ );
41823
+ }
41824
+ }
41825
+ const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
41826
+ const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
41827
+ return {
41828
+ minGas,
41829
+ minFee,
41830
+ maxGas,
41831
+ maxFee
41832
+ };
41833
+ }
41652
41834
  /**
41653
41835
  * Executes a signed transaction without applying the states changes
41654
41836
  * on the chain.
@@ -41696,17 +41878,16 @@ ${MessageCoinFragmentFragmentDoc}`;
41696
41878
  signatureCallback
41697
41879
  } = {}) {
41698
41880
  const txRequestClone = clone_default(transactionRequestify(transactionRequestLike));
41699
- const chainInfo = this.getChain();
41700
- const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
41701
- const gasPrice = max(txRequestClone.gasPrice, minGasPrice);
41881
+ const { minGasPrice } = this.getGasConfig();
41882
+ const setGasPrice = max(txRequestClone.gasPrice, minGasPrice);
41702
41883
  const isScriptTransaction = txRequestClone.type === TransactionType.Script;
41703
41884
  const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
41704
41885
  const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
41705
41886
  txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
41887
+ if (isScriptTransaction) {
41888
+ txRequestClone.gasLimit = bn(0);
41889
+ }
41706
41890
  if (estimatePredicates) {
41707
- if (isScriptTransaction) {
41708
- txRequestClone.gasLimit = bn(0);
41709
- }
41710
41891
  if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
41711
41892
  resourcesOwner.populateTransactionPredicateData(txRequestClone);
41712
41893
  }
@@ -41715,36 +41896,34 @@ ${MessageCoinFragmentFragmentDoc}`;
41715
41896
  if (signatureCallback && isScriptTransaction) {
41716
41897
  await signatureCallback(txRequestClone);
41717
41898
  }
41718
- const minGas = txRequestClone.calculateMinGas(chainInfo);
41719
- const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
41899
+ let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
41900
+ transactionRequest: txRequestClone
41901
+ });
41720
41902
  let receipts = [];
41721
41903
  let missingContractIds = [];
41722
41904
  let outputVariables = 0;
41905
+ let gasUsed = bn(0);
41723
41906
  if (isScriptTransaction && estimateTxDependencies) {
41724
41907
  txRequestClone.gasPrice = bn(0);
41725
- txRequestClone.gasLimit = bn(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
41726
41908
  const result = await this.estimateTxDependencies(txRequestClone);
41727
41909
  receipts = result.receipts;
41728
41910
  outputVariables = result.outputVariables;
41729
41911
  missingContractIds = result.missingContractIds;
41912
+ gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
41913
+ txRequestClone.gasLimit = gasUsed;
41914
+ txRequestClone.gasPrice = setGasPrice;
41915
+ ({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
41916
+ transactionRequest: txRequestClone
41917
+ }));
41730
41918
  }
41731
- const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
41732
- const usedFee = calculatePriceWithFactor(
41733
- gasUsed,
41734
- gasPrice,
41735
- gasPriceFactor
41736
- ).normalizeZeroToOne();
41737
- const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
41738
- const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
41739
41919
  return {
41740
41920
  requiredQuantities: allQuantities,
41741
41921
  receipts,
41742
41922
  gasUsed,
41743
41923
  minGasPrice,
41744
- gasPrice,
41924
+ gasPrice: setGasPrice,
41745
41925
  minGas,
41746
41926
  maxGas,
41747
- usedFee,
41748
41927
  minFee,
41749
41928
  maxFee,
41750
41929
  estimatedInputs: txRequestClone.inputs,
@@ -44198,12 +44377,12 @@ ${MessageCoinFragmentFragmentDoc}`;
44198
44377
  };
44199
44378
 
44200
44379
  // ../../node_modules/.pnpm/uuid@9.0.0/node_modules/uuid/dist/esm-node/rng.js
44201
- var import_crypto15 = __toESM(__require("crypto"));
44380
+ var import_crypto16 = __toESM(__require("crypto"));
44202
44381
  var rnds8Pool = new Uint8Array(256);
44203
44382
  var poolPtr = rnds8Pool.length;
44204
44383
  function rng() {
44205
44384
  if (poolPtr > rnds8Pool.length - 16) {
44206
- import_crypto15.default.randomFillSync(rnds8Pool);
44385
+ import_crypto16.default.randomFillSync(rnds8Pool);
44207
44386
  poolPtr = 0;
44208
44387
  }
44209
44388
  return rnds8Pool.slice(poolPtr, poolPtr += 16);
@@ -44219,9 +44398,9 @@ ${MessageCoinFragmentFragmentDoc}`;
44219
44398
  }
44220
44399
 
44221
44400
  // ../../node_modules/.pnpm/uuid@9.0.0/node_modules/uuid/dist/esm-node/native.js
44222
- var import_crypto16 = __toESM(__require("crypto"));
44401
+ var import_crypto17 = __toESM(__require("crypto"));
44223
44402
  var native_default = {
44224
- randomUUID: import_crypto16.default.randomUUID
44403
+ randomUUID: import_crypto17.default.randomUUID
44225
44404
  };
44226
44405
 
44227
44406
  // ../../node_modules/.pnpm/uuid@9.0.0/node_modules/uuid/dist/esm-node/v4.js
@@ -47640,7 +47819,6 @@ ${MessageCoinFragmentFragmentDoc}`;
47640
47819
  // src/predicate/predicate.ts
47641
47820
  var Predicate = class extends Account {
47642
47821
  bytes;
47643
- predicateDataBytes = Uint8Array.from([]);
47644
47822
  predicateData = [];
47645
47823
  interface;
47646
47824
  /**