@fuel-ts/account 0.79.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.

@@ -28954,7 +28954,7 @@ spurious results.`);
28954
28954
  return {
28955
28955
  FORC: "0.49.3",
28956
28956
  FUEL_CORE: "0.22.1",
28957
- FUELS: "0.79.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,17 +33220,25 @@ 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;
@@ -33222,16 +33269,10 @@ This unreleased fuel-core build may include features and updates not yet support
33222
33269
  }
33223
33270
  decodeFunctionData(functionFragment, data) {
33224
33271
  const fragment = typeof functionFragment === "string" ? this.getFunction(functionFragment) : functionFragment;
33225
- if (!fragment) {
33226
- throw new FuelError(ErrorCode.FRAGMENT_NOT_FOUND, "Fragment not found.");
33227
- }
33228
33272
  return fragment.decodeArguments(data);
33229
33273
  }
33230
33274
  encodeFunctionData(functionFragment, values, offset = 0) {
33231
33275
  const fragment = typeof functionFragment === "string" ? this.getFunction(functionFragment) : functionFragment;
33232
- if (!fragment) {
33233
- throw new FuelError(ErrorCode.FRAGMENT_NOT_FOUND, "Fragment not found.");
33234
- }
33235
33276
  return fragment.encodeArguments(values, offset);
33236
33277
  }
33237
33278
  // Decode the result of a function call
@@ -33240,37 +33281,33 @@ This unreleased fuel-core build may include features and updates not yet support
33240
33281
  return fragment.decodeOutput(data);
33241
33282
  }
33242
33283
  decodeLog(data, logId) {
33243
- const { loggedType } = findOrThrow(this.jsonAbi.loggedTypes, (type3) => type3.logId === logId);
33244
- return AbiCoder.decode(this.jsonAbi, loggedType, arrayify(data), 0, {
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
+ );
33290
+ }
33291
+ return AbiCoder.decode(this.jsonAbi, loggedType.loggedType, arrayify(data), 0, {
33245
33292
  encoding: this.jsonAbi.encoding
33246
33293
  });
33247
33294
  }
33248
33295
  encodeConfigurable(name, value) {
33249
- const configurable = findOrThrow(
33250
- this.jsonAbi.configurables,
33251
- (c) => c.name === name,
33252
- () => {
33253
- throw new FuelError(
33254
- ErrorCode.CONFIGURABLE_NOT_FOUND,
33255
- `A configurable with the '${name}' was not found in the ABI.`
33256
- );
33257
- }
33258
- );
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
+ }
33259
33303
  return AbiCoder.encode(this.jsonAbi, configurable.configurableType, value, {
33260
- isRightPadded: true
33304
+ isRightPadded: true,
33305
+ // TODO: Review support for configurables in v1 encoding when it becomes available
33306
+ encoding: ENCODING_V0
33261
33307
  });
33262
33308
  }
33263
33309
  getTypeById(typeId) {
33264
- return findOrThrow(
33265
- this.jsonAbi.types,
33266
- (t) => t.typeId === typeId,
33267
- () => {
33268
- throw new FuelError(
33269
- ErrorCode.TYPE_NOT_FOUND,
33270
- `Type with typeId '${typeId}' doesn't exist in the ABI.`
33271
- );
33272
- }
33273
- );
33310
+ return findTypeById(this.jsonAbi, typeId);
33274
33311
  }
33275
33312
  };
33276
33313
 
@@ -33960,7 +33997,7 @@ This unreleased fuel-core build may include features and updates not yet support
33960
33997
  return [receiptMessageOut, o];
33961
33998
  }
33962
33999
  };
33963
- var getAssetId = (contractId, subId) => {
34000
+ var getMintedAssetId = (contractId, subId) => {
33964
34001
  const contractIdBytes = arrayify(contractId);
33965
34002
  const subIdBytes = arrayify(subId);
33966
34003
  return sha2563(concat([contractIdBytes, subIdBytes]));
@@ -33970,7 +34007,7 @@ This unreleased fuel-core build may include features and updates not yet support
33970
34007
  super("ReceiptMint", "struct ReceiptMint", 0);
33971
34008
  }
33972
34009
  static getAssetId(contractId, subId) {
33973
- return getAssetId(contractId, subId);
34010
+ return getMintedAssetId(contractId, subId);
33974
34011
  }
33975
34012
  encode(value) {
33976
34013
  const parts = [];
@@ -34012,7 +34049,7 @@ This unreleased fuel-core build may include features and updates not yet support
34012
34049
  super("ReceiptBurn", "struct ReceiptBurn", 0);
34013
34050
  }
34014
34051
  static getAssetId(contractId, subId) {
34015
- return getAssetId(contractId, subId);
34052
+ return getMintedAssetId(contractId, subId);
34016
34053
  }
34017
34054
  encode(value) {
34018
34055
  const parts = [];
@@ -38837,8 +38874,8 @@ ${MessageCoinFragmentFragmentDoc}`;
38837
38874
  const predicateData = arrayify(value.predicateData ?? "0x");
38838
38875
  return {
38839
38876
  type: InputType.Coin,
38840
- txID: hexlify(arrayify(value.id).slice(0, 32)),
38841
- 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)),
38842
38879
  owner: hexlify(value.owner),
38843
38880
  amount: bn(value.amount),
38844
38881
  assetId: hexlify(value.assetId),
@@ -38962,7 +38999,60 @@ ${MessageCoinFragmentFragmentDoc}`;
38962
38999
  var MAX_SCRIPT_DATA_LENGTH = 1024 * 1024 * 1024;
38963
39000
  var MAX_PREDICATE_LENGTH = 1024 * 1024;
38964
39001
  var MAX_PREDICATE_DATA_LENGTH = 1024 * 1024;
39002
+ var FAILED_REQUIRE_SIGNAL = "0xffffffffffff0000";
38965
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";
38966
39056
 
38967
39057
  // src/providers/utils/receipts.ts
38968
39058
  var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === ReceiptType.Revert && receipt.val.toString("hex") === FAILED_TRANSFER_TO_ADDRESS_SIGNAL;
@@ -39336,6 +39426,74 @@ ${MessageCoinFragmentFragmentDoc}`;
39336
39426
  });
39337
39427
  }
39338
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
+
39339
39497
  // src/providers/transaction-request/errors.ts
39340
39498
  var ChangeOutputCollisionError = class extends Error {
39341
39499
  name = "ChangeOutputCollisionError";
@@ -39616,8 +39774,7 @@ ${MessageCoinFragmentFragmentDoc}`;
39616
39774
  assetId,
39617
39775
  txPointer: "0x00000000000000000000000000000000",
39618
39776
  witnessIndex,
39619
- predicate: predicate?.bytes,
39620
- predicateData: predicate?.predicateDataBytes
39777
+ predicate: predicate?.bytes
39621
39778
  };
39622
39779
  this.pushInput(input);
39623
39780
  this.addChangeOutput(owner, assetId);
@@ -39649,8 +39806,7 @@ ${MessageCoinFragmentFragmentDoc}`;
39649
39806
  recipient: recipient.toB256(),
39650
39807
  amount,
39651
39808
  witnessIndex,
39652
- predicate: predicate?.bytes,
39653
- predicateData: predicate?.predicateDataBytes
39809
+ predicate: predicate?.bytes
39654
39810
  };
39655
39811
  this.pushInput(input);
39656
39812
  this.addChangeOutput(recipient, assetId);
@@ -39805,12 +39961,6 @@ ${MessageCoinFragmentFragmentDoc}`;
39805
39961
  * @param quantities - CoinQuantity Array.
39806
39962
  */
39807
39963
  fundWithFakeUtxos(quantities, resourcesOwner) {
39808
- let idCounter = 0;
39809
- const generateId = () => {
39810
- const counterString = String(idCounter++);
39811
- const id = ZeroBytes32.slice(0, -counterString.length).concat(counterString);
39812
- return id;
39813
- };
39814
39964
  const findAssetInput = (assetId) => this.inputs.find((input) => {
39815
39965
  if ("assetId" in input) {
39816
39966
  return input.assetId === assetId;
@@ -39820,12 +39970,12 @@ ${MessageCoinFragmentFragmentDoc}`;
39820
39970
  const updateAssetInput = (assetId, quantity) => {
39821
39971
  const assetInput = findAssetInput(assetId);
39822
39972
  if (assetInput && "assetId" in assetInput) {
39823
- assetInput.id = generateId();
39973
+ assetInput.id = hexlify(randomBytes22(UTXO_ID_LEN));
39824
39974
  assetInput.amount = quantity;
39825
39975
  } else {
39826
39976
  this.addResources([
39827
39977
  {
39828
- id: generateId(),
39978
+ id: hexlify(randomBytes22(UTXO_ID_LEN)),
39829
39979
  amount: quantity,
39830
39980
  assetId,
39831
39981
  owner: resourcesOwner || Address.fromRandom(),
@@ -41152,14 +41302,26 @@ ${MessageCoinFragmentFragmentDoc}`;
41152
41302
  gqlTransaction: this.gqlTransaction,
41153
41303
  ...transactionSummary
41154
41304
  };
41305
+ let logs = [];
41155
41306
  if (this.abis) {
41156
- const logs = getDecodedLogs(
41307
+ logs = getDecodedLogs(
41157
41308
  transactionSummary.receipts,
41158
41309
  this.abis.main,
41159
41310
  this.abis.otherContractsAbis
41160
41311
  );
41161
41312
  transactionResult.logs = logs;
41162
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
+ }
41163
41325
  return transactionResult;
41164
41326
  }
41165
41327
  /**
@@ -41168,14 +41330,7 @@ ${MessageCoinFragmentFragmentDoc}`;
41168
41330
  * @param contractsAbiMap - The contracts ABI map.
41169
41331
  */
41170
41332
  async wait(contractsAbiMap) {
41171
- const result = await this.waitForResult(contractsAbiMap);
41172
- if (result.isStatusFailure) {
41173
- throw new FuelError(
41174
- ErrorCode.TRANSACTION_FAILED,
41175
- `Transaction failed: ${result.gqlTransaction.status.reason}`
41176
- );
41177
- }
41178
- return result;
41333
+ return this.waitForResult(contractsAbiMap);
41179
41334
  }
41180
41335
  };
41181
41336
 
@@ -41646,6 +41801,36 @@ ${MessageCoinFragmentFragmentDoc}`;
41646
41801
  missingContractIds
41647
41802
  };
41648
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
+ }
41649
41834
  /**
41650
41835
  * Executes a signed transaction without applying the states changes
41651
41836
  * on the chain.
@@ -41693,17 +41878,16 @@ ${MessageCoinFragmentFragmentDoc}`;
41693
41878
  signatureCallback
41694
41879
  } = {}) {
41695
41880
  const txRequestClone = clone_default(transactionRequestify(transactionRequestLike));
41696
- const chainInfo = this.getChain();
41697
- const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
41698
- const gasPrice = max(txRequestClone.gasPrice, minGasPrice);
41881
+ const { minGasPrice } = this.getGasConfig();
41882
+ const setGasPrice = max(txRequestClone.gasPrice, minGasPrice);
41699
41883
  const isScriptTransaction = txRequestClone.type === TransactionType.Script;
41700
41884
  const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
41701
41885
  const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
41702
41886
  txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
41887
+ if (isScriptTransaction) {
41888
+ txRequestClone.gasLimit = bn(0);
41889
+ }
41703
41890
  if (estimatePredicates) {
41704
- if (isScriptTransaction) {
41705
- txRequestClone.gasLimit = bn(0);
41706
- }
41707
41891
  if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
41708
41892
  resourcesOwner.populateTransactionPredicateData(txRequestClone);
41709
41893
  }
@@ -41712,36 +41896,34 @@ ${MessageCoinFragmentFragmentDoc}`;
41712
41896
  if (signatureCallback && isScriptTransaction) {
41713
41897
  await signatureCallback(txRequestClone);
41714
41898
  }
41715
- const minGas = txRequestClone.calculateMinGas(chainInfo);
41716
- const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
41899
+ let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
41900
+ transactionRequest: txRequestClone
41901
+ });
41717
41902
  let receipts = [];
41718
41903
  let missingContractIds = [];
41719
41904
  let outputVariables = 0;
41905
+ let gasUsed = bn(0);
41720
41906
  if (isScriptTransaction && estimateTxDependencies) {
41721
41907
  txRequestClone.gasPrice = bn(0);
41722
- txRequestClone.gasLimit = bn(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
41723
41908
  const result = await this.estimateTxDependencies(txRequestClone);
41724
41909
  receipts = result.receipts;
41725
41910
  outputVariables = result.outputVariables;
41726
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
+ }));
41727
41918
  }
41728
- const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
41729
- const usedFee = calculatePriceWithFactor(
41730
- gasUsed,
41731
- gasPrice,
41732
- gasPriceFactor
41733
- ).normalizeZeroToOne();
41734
- const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
41735
- const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
41736
41919
  return {
41737
41920
  requiredQuantities: allQuantities,
41738
41921
  receipts,
41739
41922
  gasUsed,
41740
41923
  minGasPrice,
41741
- gasPrice,
41924
+ gasPrice: setGasPrice,
41742
41925
  minGas,
41743
41926
  maxGas,
41744
- usedFee,
41745
41927
  minFee,
41746
41928
  maxFee,
41747
41929
  estimatedInputs: txRequestClone.inputs,
@@ -44195,12 +44377,12 @@ ${MessageCoinFragmentFragmentDoc}`;
44195
44377
  };
44196
44378
 
44197
44379
  // ../../node_modules/.pnpm/uuid@9.0.0/node_modules/uuid/dist/esm-node/rng.js
44198
- var import_crypto15 = __toESM(__require("crypto"));
44380
+ var import_crypto16 = __toESM(__require("crypto"));
44199
44381
  var rnds8Pool = new Uint8Array(256);
44200
44382
  var poolPtr = rnds8Pool.length;
44201
44383
  function rng() {
44202
44384
  if (poolPtr > rnds8Pool.length - 16) {
44203
- import_crypto15.default.randomFillSync(rnds8Pool);
44385
+ import_crypto16.default.randomFillSync(rnds8Pool);
44204
44386
  poolPtr = 0;
44205
44387
  }
44206
44388
  return rnds8Pool.slice(poolPtr, poolPtr += 16);
@@ -44216,9 +44398,9 @@ ${MessageCoinFragmentFragmentDoc}`;
44216
44398
  }
44217
44399
 
44218
44400
  // ../../node_modules/.pnpm/uuid@9.0.0/node_modules/uuid/dist/esm-node/native.js
44219
- var import_crypto16 = __toESM(__require("crypto"));
44401
+ var import_crypto17 = __toESM(__require("crypto"));
44220
44402
  var native_default = {
44221
- randomUUID: import_crypto16.default.randomUUID
44403
+ randomUUID: import_crypto17.default.randomUUID
44222
44404
  };
44223
44405
 
44224
44406
  // ../../node_modules/.pnpm/uuid@9.0.0/node_modules/uuid/dist/esm-node/v4.js
@@ -47637,7 +47819,6 @@ ${MessageCoinFragmentFragmentDoc}`;
47637
47819
  // src/predicate/predicate.ts
47638
47820
  var Predicate = class extends Account {
47639
47821
  bytes;
47640
- predicateDataBytes = Uint8Array.from([]);
47641
47822
  predicateData = [];
47642
47823
  interface;
47643
47824
  /**