@fuel-ts/account 0.0.0-rc-1832-20240404064601 → 0.0.0-rc-1895-20240404064636

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.

@@ -29083,6 +29083,7 @@ This unreleased fuel-core build may include features and updates not yet support
29083
29083
  })(ErrorCode || {});
29084
29084
  var _FuelError = class extends Error {
29085
29085
  VERSIONS = versions;
29086
+ metadata;
29086
29087
  static parse(e) {
29087
29088
  const error = e;
29088
29089
  if (error.code === void 0) {
@@ -29102,14 +29103,15 @@ This unreleased fuel-core build may include features and updates not yet support
29102
29103
  return new _FuelError(error.code, error.message);
29103
29104
  }
29104
29105
  code;
29105
- constructor(code, message) {
29106
+ constructor(code, message, metadata = {}) {
29106
29107
  super(message);
29107
29108
  this.code = code;
29108
29109
  this.name = "FuelError";
29110
+ this.metadata = metadata;
29109
29111
  }
29110
29112
  toObject() {
29111
- const { code, name, message, VERSIONS } = this;
29112
- return { code, name, message, VERSIONS };
29113
+ const { code, name, message, metadata, VERSIONS } = this;
29114
+ return { code, name, message, metadata, VERSIONS };
29113
29115
  }
29114
29116
  };
29115
29117
  var FuelError = _FuelError;
@@ -31913,6 +31915,9 @@ This unreleased fuel-core build may include features and updates not yet support
31913
31915
  __privateAdd2(this, _getPaddedData);
31914
31916
  }
31915
31917
  encode(value) {
31918
+ if (!Array.isArray(value)) {
31919
+ throw new FuelError(ErrorCode.ENCODE_ERROR, `Expected array value.`);
31920
+ }
31916
31921
  const parts = [];
31917
31922
  const pointer = new BigNumberCoder("u64").encode(BASE_VECTOR_OFFSET);
31918
31923
  const data = __privateMethod2(this, _getPaddedData, getPaddedData_fn).call(this, value);
@@ -31939,7 +31944,7 @@ This unreleased fuel-core build may include features and updates not yet support
31939
31944
  };
31940
31945
  _getPaddedData = /* @__PURE__ */ new WeakSet();
31941
31946
  getPaddedData_fn = function(value) {
31942
- const data = value instanceof Uint8Array ? [value] : [new Uint8Array(value)];
31947
+ const data = [Uint8Array.from(value)];
31943
31948
  const paddingLength = (WORD_SIZE - value.length % WORD_SIZE) % WORD_SIZE;
31944
31949
  if (paddingLength) {
31945
31950
  data.push(new Uint8Array(paddingLength));
@@ -31962,7 +31967,7 @@ This unreleased fuel-core build may include features and updates not yet support
31962
31967
  (max2, coder) => Math.max(max2, coder.encodedLength),
31963
31968
  0
31964
31969
  );
31965
- super(`enum ${name}`, `enum ${name}`, caseIndexCoder.encodedLength + encodedValueSize);
31970
+ super("enum", `enum ${name}`, caseIndexCoder.encodedLength + encodedValueSize);
31966
31971
  this.name = name;
31967
31972
  this.coders = coders;
31968
31973
  this.#caseIndexCoder = caseIndexCoder;
@@ -32032,7 +32037,7 @@ This unreleased fuel-core build may include features and updates not yet support
32032
32037
  return { None: [] };
32033
32038
  }
32034
32039
  decode(data, offset) {
32035
- if (data.length < this.encodedLength) {
32040
+ if (data.length < this.encodedLength - 1) {
32036
32041
  throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid option data size.`);
32037
32042
  }
32038
32043
  const [decoded, newOffset] = super.decode(data, offset);
@@ -32615,8 +32620,11 @@ This unreleased fuel-core build may include features and updates not yet support
32615
32620
  super("struct", "struct Bytes", WORD_SIZE);
32616
32621
  }
32617
32622
  encode(value) {
32618
- const bytes3 = value instanceof Uint8Array ? value : new Uint8Array(value);
32619
- const lengthBytes = new BigNumberCoder("u64").encode(bytes3.length);
32623
+ if (!Array.isArray(value)) {
32624
+ throw new FuelError(ErrorCode.ENCODE_ERROR, `Expected array value.`);
32625
+ }
32626
+ const bytes3 = new Uint8Array(value);
32627
+ const lengthBytes = new BigNumberCoder("u64").encode(value.length);
32620
32628
  return new Uint8Array([...lengthBytes, ...bytes3]);
32621
32629
  }
32622
32630
  decode(data, offset) {
@@ -32649,7 +32657,7 @@ This unreleased fuel-core build may include features and updates not yet support
32649
32657
  (max2, coder) => Math.max(max2, coder.encodedLength),
32650
32658
  0
32651
32659
  );
32652
- super(`enum ${name}`, `enum ${name}`, caseIndexCoder.encodedLength + encodedValueSize);
32660
+ super("enum", `enum ${name}`, caseIndexCoder.encodedLength + encodedValueSize);
32653
32661
  this.name = name;
32654
32662
  this.coders = coders;
32655
32663
  this.#caseIndexCoder = caseIndexCoder;
@@ -32747,28 +32755,6 @@ This unreleased fuel-core build may include features and updates not yet support
32747
32755
  return [toNumber2(bytes3), offset + this.length];
32748
32756
  }
32749
32757
  };
32750
- var OptionCoder2 = class extends EnumCoder2 {
32751
- encode(value) {
32752
- const result = super.encode(this.toSwayOption(value));
32753
- return result;
32754
- }
32755
- toSwayOption(input) {
32756
- if (input !== void 0) {
32757
- return { Some: input };
32758
- }
32759
- return { None: [] };
32760
- }
32761
- decode(data, offset) {
32762
- const [decoded, newOffset] = super.decode(data, offset);
32763
- return [this.toOption(decoded), newOffset];
32764
- }
32765
- toOption(output3) {
32766
- if (output3 && "Some" in output3) {
32767
- return output3.Some;
32768
- }
32769
- return void 0;
32770
- }
32771
- };
32772
32758
  var RawSliceCoder2 = class extends Coder {
32773
32759
  constructor() {
32774
32760
  super("raw untyped slice", "raw untyped slice", WORD_SIZE);
@@ -32822,30 +32808,6 @@ This unreleased fuel-core build may include features and updates not yet support
32822
32808
  }
32823
32809
  };
32824
32810
  __publicField4(StdStringCoder2, "memorySize", 1);
32825
- var StrSliceCoder = class extends Coder {
32826
- constructor() {
32827
- super("strSlice", "str", WORD_SIZE);
32828
- }
32829
- encode(value) {
32830
- const bytes3 = toUtf8Bytes(value);
32831
- const lengthBytes = new BigNumberCoder("u64").encode(value.length);
32832
- return new Uint8Array([...lengthBytes, ...bytes3]);
32833
- }
32834
- decode(data, offset) {
32835
- if (data.length < this.encodedLength) {
32836
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid string slice data size.`);
32837
- }
32838
- const offsetAndLength = offset + WORD_SIZE;
32839
- const lengthBytes = data.slice(offset, offsetAndLength);
32840
- const length = bn(new BigNumberCoder("u64").decode(lengthBytes, 0)[0]).toNumber();
32841
- const bytes3 = data.slice(offsetAndLength, offsetAndLength + length);
32842
- if (bytes3.length !== length) {
32843
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid string slice byte data size.`);
32844
- }
32845
- return [toUtf8String(bytes3), offsetAndLength + length];
32846
- }
32847
- };
32848
- __publicField4(StrSliceCoder, "memorySize", 1);
32849
32811
  var StringCoder2 = class extends Coder {
32850
32812
  constructor(length) {
32851
32813
  super("string", `str[${length}]`, length);
@@ -32884,7 +32846,7 @@ This unreleased fuel-core build may include features and updates not yet support
32884
32846
  Object.keys(this.coders).map((fieldName) => {
32885
32847
  const fieldCoder = this.coders[fieldName];
32886
32848
  const fieldValue = value[fieldName];
32887
- if (!(fieldCoder instanceof OptionCoder2) && fieldValue == null) {
32849
+ if (!(fieldCoder instanceof OptionCoder) && fieldValue == null) {
32888
32850
  throw new FuelError(
32889
32851
  ErrorCode.ENCODE_ERROR,
32890
32852
  `Invalid ${this.type}. Field "${fieldName}" not present.`
@@ -32992,8 +32954,6 @@ This unreleased fuel-core build may include features and updates not yet support
32992
32954
  return new ByteCoder2();
32993
32955
  case STD_STRING_CODER_TYPE:
32994
32956
  return new StdStringCoder2();
32995
- case STR_SLICE_CODER_TYPE:
32996
- return new StrSliceCoder();
32997
32957
  default:
32998
32958
  break;
32999
32959
  }
@@ -33038,7 +32998,7 @@ This unreleased fuel-core build may include features and updates not yet support
33038
32998
  const coders = getCoders(components, { getCoder: getCoder2 });
33039
32999
  const isOptionEnum = resolvedAbiType.type === OPTION_CODER_TYPE;
33040
33000
  if (isOptionEnum) {
33041
- return new OptionCoder2(enumMatch.name, coders);
33001
+ return new OptionCoder(enumMatch.name, coders);
33042
33002
  }
33043
33003
  return new EnumCoder2(enumMatch.name, coders);
33044
33004
  }
@@ -33049,6 +33009,12 @@ This unreleased fuel-core build may include features and updates not yet support
33049
33009
  );
33050
33010
  return new TupleCoder2(coders);
33051
33011
  }
33012
+ if (resolvedAbiType.type === STR_SLICE_CODER_TYPE) {
33013
+ throw new FuelError(
33014
+ ErrorCode.INVALID_DATA,
33015
+ "String slices can not be decoded from logs. Convert the slice to `str[N]` with `__to_str_array`"
33016
+ );
33017
+ }
33052
33018
  throw new FuelError(
33053
33019
  ErrorCode.CODER_NOT_FOUND,
33054
33020
  `Coder not found: ${JSON.stringify(resolvedAbiType)}.`
@@ -33084,8 +33050,6 @@ This unreleased fuel-core build may include features and updates not yet support
33084
33050
  var FunctionFragment = class {
33085
33051
  signature;
33086
33052
  selector;
33087
- selectorBytes;
33088
- encoding;
33089
33053
  name;
33090
33054
  jsonFn;
33091
33055
  attributes;
@@ -33098,8 +33062,6 @@ This unreleased fuel-core build may include features and updates not yet support
33098
33062
  this.name = name;
33099
33063
  this.signature = FunctionFragment.getSignature(this.jsonAbi, this.jsonFn);
33100
33064
  this.selector = FunctionFragment.getFunctionSelector(this.signature);
33101
- this.selectorBytes = new StdStringCoder2().encode(name);
33102
- this.encoding = this.jsonAbi.encoding ?? ENCODING_V0;
33103
33065
  this.isInputDataPointer = this.#isInputDataPointer();
33104
33066
  this.outputMetadata = {
33105
33067
  isHeapType: this.#isOutputDataHeap(),
@@ -33153,14 +33115,11 @@ This unreleased fuel-core build may include features and updates not yet support
33153
33115
  }
33154
33116
  const coders = nonEmptyInputs.map(
33155
33117
  (t) => AbiCoder.getCoder(this.jsonAbi, t, {
33156
- isRightPadded: nonEmptyInputs.length > 1,
33157
- encoding: this.encoding
33118
+ isRightPadded: nonEmptyInputs.length > 1
33158
33119
  })
33159
33120
  );
33160
- if (this.encoding === ENCODING_V1) {
33161
- return new TupleCoder2(coders).encode(shallowCopyValues);
33162
- }
33163
- const results = new TupleCoder(coders).encode(shallowCopyValues);
33121
+ const coder = new TupleCoder(coders);
33122
+ const results = coder.encode(shallowCopyValues);
33164
33123
  return unpackDynamicData(results, offset, results.byteLength);
33165
33124
  }
33166
33125
  static verifyArgsAndInputsAlign(args, inputs, abi) {
@@ -33207,7 +33166,7 @@ This unreleased fuel-core build may include features and updates not yet support
33207
33166
  }
33208
33167
  const result = nonEmptyInputs.reduce(
33209
33168
  (obj, input) => {
33210
- const coder = AbiCoder.getCoder(this.jsonAbi, input, { encoding: this.encoding });
33169
+ const coder = AbiCoder.getCoder(this.jsonAbi, input);
33211
33170
  const [decodedValue, decodedValueByteSize] = coder.decode(bytes3, obj.offset);
33212
33171
  return {
33213
33172
  decoded: [...obj.decoded, decodedValue],
@@ -33227,9 +33186,7 @@ This unreleased fuel-core build may include features and updates not yet support
33227
33186
  return [void 0, 0];
33228
33187
  }
33229
33188
  const bytes3 = arrayify(data);
33230
- const coder = AbiCoder.getCoder(this.jsonAbi, this.jsonFn.output, {
33231
- encoding: this.encoding
33232
- });
33189
+ const coder = AbiCoder.getCoder(this.jsonAbi, this.jsonFn.output);
33233
33190
  return coder.decode(bytes3, 0);
33234
33191
  }
33235
33192
  };
@@ -33291,8 +33248,7 @@ This unreleased fuel-core build may include features and updates not yet support
33291
33248
  }
33292
33249
  );
33293
33250
  return AbiCoder.encode(this.jsonAbi, configurable.configurableType, value, {
33294
- isRightPadded: true,
33295
- encoding: this.jsonAbi.encoding
33251
+ isRightPadded: true
33296
33252
  });
33297
33253
  }
33298
33254
  getTypeById(typeId) {
@@ -38997,7 +38953,60 @@ ${MessageCoinFragmentFragmentDoc}`;
38997
38953
  var MAX_SCRIPT_DATA_LENGTH = 1024 * 1024 * 1024;
38998
38954
  var MAX_PREDICATE_LENGTH = 1024 * 1024;
38999
38955
  var MAX_PREDICATE_DATA_LENGTH = 1024 * 1024;
38956
+ var FAILED_REQUIRE_SIGNAL = "0xffffffffffff0000";
39000
38957
  var FAILED_TRANSFER_TO_ADDRESS_SIGNAL = "0xffffffffffff0001";
38958
+ var FAILED_ASSERT_EQ_SIGNAL = "0xffffffffffff0003";
38959
+ var FAILED_ASSERT_SIGNAL = "0xffffffffffff0004";
38960
+ var FAILED_ASSERT_NE_SIGNAL = "0xffffffffffff0005";
38961
+ var PANIC_REASONS = [
38962
+ "UnknownPanicReason",
38963
+ "Revert",
38964
+ "OutOfGas",
38965
+ "TransactionValidity",
38966
+ "MemoryOverflow",
38967
+ "ArithmeticOverflow",
38968
+ "ContractNotFound",
38969
+ "MemoryOwnership",
38970
+ "NotEnoughBalance",
38971
+ "ExpectedInternalContext",
38972
+ "AssetIdNotFound",
38973
+ "InputNotFound",
38974
+ "OutputNotFound",
38975
+ "WitnessNotFound",
38976
+ "TransactionMaturity",
38977
+ "InvalidMetadataIdentifier",
38978
+ "MalformedCallStructure",
38979
+ "ReservedRegisterNotWritable",
38980
+ "InvalidFlags",
38981
+ "InvalidImmediateValue",
38982
+ "ExpectedCoinInput",
38983
+ "EcalError",
38984
+ "MemoryWriteOverlap",
38985
+ "ContractNotInInputs",
38986
+ "InternalBalanceOverflow",
38987
+ "ContractMaxSize",
38988
+ "ExpectedUnallocatedStack",
38989
+ "MaxStaticContractsReached",
38990
+ "TransferAmountCannotBeZero",
38991
+ "ExpectedOutputVariable",
38992
+ "ExpectedParentInternalContext",
38993
+ "PredicateReturnedNonOne",
38994
+ "ContractIdAlreadyDeployed",
38995
+ "ContractMismatch",
38996
+ "MessageDataTooLong",
38997
+ "ArithmeticError",
38998
+ "ContractInstructionNotAllowed",
38999
+ "TransferZeroCoins",
39000
+ "InvalidInstruction",
39001
+ "MemoryNotExecutable",
39002
+ "PolicyIsNotSet",
39003
+ "PolicyNotFound",
39004
+ "TooManyReceipts",
39005
+ "BalanceOverflow",
39006
+ "InvalidBlockHeight",
39007
+ "TooManySlots"
39008
+ ];
39009
+ var PANIC_DOC_URL = "https://docs.rs/fuel-asm/latest/fuel_asm/enum.PanicReason.html";
39001
39010
 
39002
39011
  // src/providers/utils/receipts.ts
39003
39012
  var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === ReceiptType.Revert && receipt.val.toString("hex") === FAILED_TRANSFER_TO_ADDRESS_SIGNAL;
@@ -39371,6 +39380,74 @@ ${MessageCoinFragmentFragmentDoc}`;
39371
39380
  });
39372
39381
  }
39373
39382
 
39383
+ // src/providers/utils/extract-tx-error.ts
39384
+ var assemblePanicError = (status) => {
39385
+ let errorMessage = `The transaction reverted with reason: "${status.reason}".`;
39386
+ const reason = status.reason;
39387
+ if (PANIC_REASONS.includes(status.reason)) {
39388
+ errorMessage = `${errorMessage}
39389
+
39390
+ You can read more about this error at:
39391
+
39392
+ ${PANIC_DOC_URL}#variant.${status.reason}`;
39393
+ }
39394
+ return { errorMessage, reason };
39395
+ };
39396
+ var stringify2 = (obj) => JSON.stringify(obj, null, 2);
39397
+ var assembleRevertError = (receipts, logs) => {
39398
+ let errorMessage = "The transaction reverted with an unknown reason.";
39399
+ const revertReceipt = receipts.find(({ type: type3 }) => type3 === ReceiptType.Revert);
39400
+ let reason = "";
39401
+ if (revertReceipt) {
39402
+ const reasonHex = bn(revertReceipt.val).toHex();
39403
+ switch (reasonHex) {
39404
+ case FAILED_REQUIRE_SIGNAL: {
39405
+ reason = "require";
39406
+ errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify2(logs[0]) : "an error."}.`;
39407
+ break;
39408
+ }
39409
+ case FAILED_ASSERT_EQ_SIGNAL: {
39410
+ const sufix = logs.length >= 2 ? ` comparing ${stringify2(logs[1])} and ${stringify2(logs[0])}.` : ".";
39411
+ reason = "assert_eq";
39412
+ errorMessage = `The transaction reverted because of an "assert_eq" statement${sufix}`;
39413
+ break;
39414
+ }
39415
+ case FAILED_ASSERT_NE_SIGNAL: {
39416
+ const sufix = logs.length >= 2 ? ` comparing ${stringify2(logs[1])} and ${stringify2(logs[0])}.` : ".";
39417
+ reason = "assert_ne";
39418
+ errorMessage = `The transaction reverted because of an "assert_ne" statement${sufix}`;
39419
+ break;
39420
+ }
39421
+ case FAILED_ASSERT_SIGNAL:
39422
+ reason = "assert";
39423
+ errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
39424
+ break;
39425
+ case FAILED_TRANSFER_TO_ADDRESS_SIGNAL:
39426
+ reason = "MissingOutputChange";
39427
+ errorMessage = `The transaction reverted because it's missing an "OutputChange".`;
39428
+ break;
39429
+ default:
39430
+ reason = "unknown";
39431
+ errorMessage = `The transaction reverted with an unknown reason: ${revertReceipt.val}`;
39432
+ }
39433
+ }
39434
+ return { errorMessage, reason };
39435
+ };
39436
+ var extractTxError = (params) => {
39437
+ const { receipts, status, logs } = params;
39438
+ const isPanic = receipts.some(({ type: type3 }) => type3 === ReceiptType.Panic);
39439
+ const isRevert = receipts.some(({ type: type3 }) => type3 === ReceiptType.Revert);
39440
+ const { errorMessage, reason } = status?.type === "FailureStatus" && isPanic ? assemblePanicError(status) : assembleRevertError(receipts, logs);
39441
+ const metadata = {
39442
+ logs,
39443
+ receipts,
39444
+ panic: isPanic,
39445
+ revert: isRevert,
39446
+ reason
39447
+ };
39448
+ return new FuelError(ErrorCode.SCRIPT_REVERTED, errorMessage, metadata);
39449
+ };
39450
+
39374
39451
  // src/providers/transaction-request/errors.ts
39375
39452
  var ChangeOutputCollisionError = class extends Error {
39376
39453
  name = "ChangeOutputCollisionError";
@@ -41187,14 +41264,26 @@ ${MessageCoinFragmentFragmentDoc}`;
41187
41264
  gqlTransaction: this.gqlTransaction,
41188
41265
  ...transactionSummary
41189
41266
  };
41267
+ let logs = [];
41190
41268
  if (this.abis) {
41191
- const logs = getDecodedLogs(
41269
+ logs = getDecodedLogs(
41192
41270
  transactionSummary.receipts,
41193
41271
  this.abis.main,
41194
41272
  this.abis.otherContractsAbis
41195
41273
  );
41196
41274
  transactionResult.logs = logs;
41197
41275
  }
41276
+ if (transactionResult.isStatusFailure) {
41277
+ const {
41278
+ receipts,
41279
+ gqlTransaction: { status }
41280
+ } = transactionResult;
41281
+ throw extractTxError({
41282
+ receipts,
41283
+ status,
41284
+ logs
41285
+ });
41286
+ }
41198
41287
  return transactionResult;
41199
41288
  }
41200
41289
  /**
@@ -41203,14 +41292,7 @@ ${MessageCoinFragmentFragmentDoc}`;
41203
41292
  * @param contractsAbiMap - The contracts ABI map.
41204
41293
  */
41205
41294
  async wait(contractsAbiMap) {
41206
- const result = await this.waitForResult(contractsAbiMap);
41207
- if (result.isStatusFailure) {
41208
- throw new FuelError(
41209
- ErrorCode.TRANSACTION_FAILED,
41210
- `Transaction failed: ${result.gqlTransaction.status.reason}`
41211
- );
41212
- }
41213
- return result;
41295
+ return this.waitForResult(contractsAbiMap);
41214
41296
  }
41215
41297
  };
41216
41298