@fuel-ts/account 0.0.0-rc-1832-20240402201930 → 0.0.0-rc-1895-20240403004459

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.

@@ -29088,6 +29088,7 @@ This unreleased fuel-core build may include features and updates not yet support
29088
29088
  })(ErrorCode || {});
29089
29089
  var _FuelError = class extends Error {
29090
29090
  VERSIONS = versions;
29091
+ metadata;
29091
29092
  static parse(e) {
29092
29093
  const error = e;
29093
29094
  if (error.code === void 0) {
@@ -29107,14 +29108,15 @@ This unreleased fuel-core build may include features and updates not yet support
29107
29108
  return new _FuelError(error.code, error.message);
29108
29109
  }
29109
29110
  code;
29110
- constructor(code, message) {
29111
+ constructor(code, message, metadata = {}) {
29111
29112
  super(message);
29112
29113
  this.code = code;
29113
29114
  this.name = "FuelError";
29115
+ this.metadata = metadata;
29114
29116
  }
29115
29117
  toObject() {
29116
- const { code, name, message, VERSIONS } = this;
29117
- return { code, name, message, VERSIONS };
29118
+ const { code, name, message, metadata, VERSIONS } = this;
29119
+ return { code, name, message, metadata, VERSIONS };
29118
29120
  }
29119
29121
  };
29120
29122
  var FuelError = _FuelError;
@@ -31918,6 +31920,9 @@ This unreleased fuel-core build may include features and updates not yet support
31918
31920
  __privateAdd2(this, _getPaddedData);
31919
31921
  }
31920
31922
  encode(value) {
31923
+ if (!Array.isArray(value)) {
31924
+ throw new FuelError(ErrorCode.ENCODE_ERROR, `Expected array value.`);
31925
+ }
31921
31926
  const parts = [];
31922
31927
  const pointer = new BigNumberCoder("u64").encode(BASE_VECTOR_OFFSET);
31923
31928
  const data = __privateMethod2(this, _getPaddedData, getPaddedData_fn).call(this, value);
@@ -31944,7 +31949,7 @@ This unreleased fuel-core build may include features and updates not yet support
31944
31949
  };
31945
31950
  _getPaddedData = /* @__PURE__ */ new WeakSet();
31946
31951
  getPaddedData_fn = function(value) {
31947
- const data = value instanceof Uint8Array ? [value] : [new Uint8Array(value)];
31952
+ const data = [Uint8Array.from(value)];
31948
31953
  const paddingLength = (WORD_SIZE - value.length % WORD_SIZE) % WORD_SIZE;
31949
31954
  if (paddingLength) {
31950
31955
  data.push(new Uint8Array(paddingLength));
@@ -32037,7 +32042,7 @@ This unreleased fuel-core build may include features and updates not yet support
32037
32042
  return { None: [] };
32038
32043
  }
32039
32044
  decode(data, offset) {
32040
- if (data.length < this.encodedLength) {
32045
+ if (data.length < this.encodedLength - 1) {
32041
32046
  throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid option data size.`);
32042
32047
  }
32043
32048
  const [decoded, newOffset] = super.decode(data, offset);
@@ -32620,8 +32625,11 @@ This unreleased fuel-core build may include features and updates not yet support
32620
32625
  super("struct", "struct Bytes", WORD_SIZE);
32621
32626
  }
32622
32627
  encode(value) {
32623
- const bytes3 = value instanceof Uint8Array ? value : new Uint8Array(value);
32624
- const lengthBytes = new BigNumberCoder("u64").encode(bytes3.length);
32628
+ if (!Array.isArray(value)) {
32629
+ throw new FuelError(ErrorCode.ENCODE_ERROR, `Expected array value.`);
32630
+ }
32631
+ const bytes3 = new Uint8Array(value);
32632
+ const lengthBytes = new BigNumberCoder("u64").encode(value.length);
32625
32633
  return new Uint8Array([...lengthBytes, ...bytes3]);
32626
32634
  }
32627
32635
  decode(data, offset) {
@@ -32752,28 +32760,6 @@ This unreleased fuel-core build may include features and updates not yet support
32752
32760
  return [toNumber2(bytes3), offset + this.length];
32753
32761
  }
32754
32762
  };
32755
- var OptionCoder2 = class extends EnumCoder2 {
32756
- encode(value) {
32757
- const result = super.encode(this.toSwayOption(value));
32758
- return result;
32759
- }
32760
- toSwayOption(input) {
32761
- if (input !== void 0) {
32762
- return { Some: input };
32763
- }
32764
- return { None: [] };
32765
- }
32766
- decode(data, offset) {
32767
- const [decoded, newOffset] = super.decode(data, offset);
32768
- return [this.toOption(decoded), newOffset];
32769
- }
32770
- toOption(output3) {
32771
- if (output3 && "Some" in output3) {
32772
- return output3.Some;
32773
- }
32774
- return void 0;
32775
- }
32776
- };
32777
32763
  var RawSliceCoder2 = class extends Coder {
32778
32764
  constructor() {
32779
32765
  super("raw untyped slice", "raw untyped slice", WORD_SIZE);
@@ -32827,30 +32813,6 @@ This unreleased fuel-core build may include features and updates not yet support
32827
32813
  }
32828
32814
  };
32829
32815
  __publicField4(StdStringCoder2, "memorySize", 1);
32830
- var StrSliceCoder = class extends Coder {
32831
- constructor() {
32832
- super("strSlice", "str", WORD_SIZE);
32833
- }
32834
- encode(value) {
32835
- const bytes3 = toUtf8Bytes(value);
32836
- const lengthBytes = new BigNumberCoder("u64").encode(value.length);
32837
- return new Uint8Array([...lengthBytes, ...bytes3]);
32838
- }
32839
- decode(data, offset) {
32840
- if (data.length < this.encodedLength) {
32841
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid string slice data size.`);
32842
- }
32843
- const offsetAndLength = offset + WORD_SIZE;
32844
- const lengthBytes = data.slice(offset, offsetAndLength);
32845
- const length = bn(new BigNumberCoder("u64").decode(lengthBytes, 0)[0]).toNumber();
32846
- const bytes3 = data.slice(offsetAndLength, offsetAndLength + length);
32847
- if (bytes3.length !== length) {
32848
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid string slice byte data size.`);
32849
- }
32850
- return [toUtf8String(bytes3), offsetAndLength + length];
32851
- }
32852
- };
32853
- __publicField4(StrSliceCoder, "memorySize", 1);
32854
32816
  var StringCoder2 = class extends Coder {
32855
32817
  constructor(length) {
32856
32818
  super("string", `str[${length}]`, length);
@@ -32889,7 +32851,7 @@ This unreleased fuel-core build may include features and updates not yet support
32889
32851
  Object.keys(this.coders).map((fieldName) => {
32890
32852
  const fieldCoder = this.coders[fieldName];
32891
32853
  const fieldValue = value[fieldName];
32892
- if (!(fieldCoder instanceof OptionCoder2) && fieldValue == null) {
32854
+ if (!(fieldCoder instanceof OptionCoder) && fieldValue == null) {
32893
32855
  throw new FuelError(
32894
32856
  ErrorCode.ENCODE_ERROR,
32895
32857
  `Invalid ${this.type}. Field "${fieldName}" not present.`
@@ -32997,8 +32959,6 @@ This unreleased fuel-core build may include features and updates not yet support
32997
32959
  return new ByteCoder2();
32998
32960
  case STD_STRING_CODER_TYPE:
32999
32961
  return new StdStringCoder2();
33000
- case STR_SLICE_CODER_TYPE:
33001
- return new StrSliceCoder();
33002
32962
  default:
33003
32963
  break;
33004
32964
  }
@@ -33043,7 +33003,7 @@ This unreleased fuel-core build may include features and updates not yet support
33043
33003
  const coders = getCoders(components, { getCoder: getCoder2 });
33044
33004
  const isOptionEnum = resolvedAbiType.type === OPTION_CODER_TYPE;
33045
33005
  if (isOptionEnum) {
33046
- return new OptionCoder2(enumMatch.name, coders);
33006
+ return new OptionCoder(enumMatch.name, coders);
33047
33007
  }
33048
33008
  return new EnumCoder2(enumMatch.name, coders);
33049
33009
  }
@@ -33054,6 +33014,12 @@ This unreleased fuel-core build may include features and updates not yet support
33054
33014
  );
33055
33015
  return new TupleCoder2(coders);
33056
33016
  }
33017
+ if (resolvedAbiType.type === STR_SLICE_CODER_TYPE) {
33018
+ throw new FuelError(
33019
+ ErrorCode.INVALID_DATA,
33020
+ "String slices can not be decoded from logs. Convert the slice to `str[N]` with `__to_str_array`"
33021
+ );
33022
+ }
33057
33023
  throw new FuelError(
33058
33024
  ErrorCode.CODER_NOT_FOUND,
33059
33025
  `Coder not found: ${JSON.stringify(resolvedAbiType)}.`
@@ -33089,8 +33055,6 @@ This unreleased fuel-core build may include features and updates not yet support
33089
33055
  var FunctionFragment = class {
33090
33056
  signature;
33091
33057
  selector;
33092
- selectorBytes;
33093
- encoding;
33094
33058
  name;
33095
33059
  jsonFn;
33096
33060
  attributes;
@@ -33103,8 +33067,6 @@ This unreleased fuel-core build may include features and updates not yet support
33103
33067
  this.name = name;
33104
33068
  this.signature = FunctionFragment.getSignature(this.jsonAbi, this.jsonFn);
33105
33069
  this.selector = FunctionFragment.getFunctionSelector(this.signature);
33106
- this.selectorBytes = new StdStringCoder2().encode(name);
33107
- this.encoding = this.jsonAbi.encoding ?? ENCODING_V0;
33108
33070
  this.isInputDataPointer = this.#isInputDataPointer();
33109
33071
  this.outputMetadata = {
33110
33072
  isHeapType: this.#isOutputDataHeap(),
@@ -33158,14 +33120,11 @@ This unreleased fuel-core build may include features and updates not yet support
33158
33120
  }
33159
33121
  const coders = nonEmptyInputs.map(
33160
33122
  (t) => AbiCoder.getCoder(this.jsonAbi, t, {
33161
- isRightPadded: nonEmptyInputs.length > 1,
33162
- encoding: this.encoding
33123
+ isRightPadded: nonEmptyInputs.length > 1
33163
33124
  })
33164
33125
  );
33165
- if (this.encoding === ENCODING_V1) {
33166
- return new TupleCoder2(coders).encode(shallowCopyValues);
33167
- }
33168
- const results = new TupleCoder(coders).encode(shallowCopyValues);
33126
+ const coder = new TupleCoder(coders);
33127
+ const results = coder.encode(shallowCopyValues);
33169
33128
  return unpackDynamicData(results, offset, results.byteLength);
33170
33129
  }
33171
33130
  static verifyArgsAndInputsAlign(args, inputs, abi) {
@@ -33212,7 +33171,7 @@ This unreleased fuel-core build may include features and updates not yet support
33212
33171
  }
33213
33172
  const result = nonEmptyInputs.reduce(
33214
33173
  (obj, input) => {
33215
- const coder = AbiCoder.getCoder(this.jsonAbi, input, { encoding: this.encoding });
33174
+ const coder = AbiCoder.getCoder(this.jsonAbi, input);
33216
33175
  const [decodedValue, decodedValueByteSize] = coder.decode(bytes3, obj.offset);
33217
33176
  return {
33218
33177
  decoded: [...obj.decoded, decodedValue],
@@ -33232,9 +33191,7 @@ This unreleased fuel-core build may include features and updates not yet support
33232
33191
  return [void 0, 0];
33233
33192
  }
33234
33193
  const bytes3 = arrayify(data);
33235
- const coder = AbiCoder.getCoder(this.jsonAbi, this.jsonFn.output, {
33236
- encoding: this.encoding
33237
- });
33194
+ const coder = AbiCoder.getCoder(this.jsonAbi, this.jsonFn.output);
33238
33195
  return coder.decode(bytes3, 0);
33239
33196
  }
33240
33197
  };
@@ -33302,8 +33259,7 @@ This unreleased fuel-core build may include features and updates not yet support
33302
33259
  }
33303
33260
  );
33304
33261
  return AbiCoder.encode(this.jsonAbi, configurable.configurableType, value, {
33305
- isRightPadded: true,
33306
- encoding: this.jsonAbi.encoding
33262
+ isRightPadded: true
33307
33263
  });
33308
33264
  }
33309
33265
  getTypeById(typeId) {
@@ -39008,7 +38964,60 @@ ${MessageCoinFragmentFragmentDoc}`;
39008
38964
  var MAX_SCRIPT_DATA_LENGTH = 1024 * 1024 * 1024;
39009
38965
  var MAX_PREDICATE_LENGTH = 1024 * 1024;
39010
38966
  var MAX_PREDICATE_DATA_LENGTH = 1024 * 1024;
38967
+ var FAILED_REQUIRE_SIGNAL = "0xffffffffffff0000";
39011
38968
  var FAILED_TRANSFER_TO_ADDRESS_SIGNAL = "0xffffffffffff0001";
38969
+ var FAILED_ASSERT_EQ_SIGNAL = "0xffffffffffff0003";
38970
+ var FAILED_ASSERT_SIGNAL = "0xffffffffffff0004";
38971
+ var FAILED_ASSERT_NE_SIGNAL = "0xffffffffffff0005";
38972
+ var PANIC_REASONS = [
38973
+ "UnknownPanicReason",
38974
+ "Revert",
38975
+ "OutOfGas",
38976
+ "TransactionValidity",
38977
+ "MemoryOverflow",
38978
+ "ArithmeticOverflow",
38979
+ "ContractNotFound",
38980
+ "MemoryOwnership",
38981
+ "NotEnoughBalance",
38982
+ "ExpectedInternalContext",
38983
+ "AssetIdNotFound",
38984
+ "InputNotFound",
38985
+ "OutputNotFound",
38986
+ "WitnessNotFound",
38987
+ "TransactionMaturity",
38988
+ "InvalidMetadataIdentifier",
38989
+ "MalformedCallStructure",
38990
+ "ReservedRegisterNotWritable",
38991
+ "InvalidFlags",
38992
+ "InvalidImmediateValue",
38993
+ "ExpectedCoinInput",
38994
+ "EcalError",
38995
+ "MemoryWriteOverlap",
38996
+ "ContractNotInInputs",
38997
+ "InternalBalanceOverflow",
38998
+ "ContractMaxSize",
38999
+ "ExpectedUnallocatedStack",
39000
+ "MaxStaticContractsReached",
39001
+ "TransferAmountCannotBeZero",
39002
+ "ExpectedOutputVariable",
39003
+ "ExpectedParentInternalContext",
39004
+ "PredicateReturnedNonOne",
39005
+ "ContractIdAlreadyDeployed",
39006
+ "ContractMismatch",
39007
+ "MessageDataTooLong",
39008
+ "ArithmeticError",
39009
+ "ContractInstructionNotAllowed",
39010
+ "TransferZeroCoins",
39011
+ "InvalidInstruction",
39012
+ "MemoryNotExecutable",
39013
+ "PolicyIsNotSet",
39014
+ "PolicyNotFound",
39015
+ "TooManyReceipts",
39016
+ "BalanceOverflow",
39017
+ "InvalidBlockHeight",
39018
+ "TooManySlots"
39019
+ ];
39020
+ var PANIC_DOC_URL = "https://docs.rs/fuel-asm/latest/fuel_asm/enum.PanicReason.html";
39012
39021
 
39013
39022
  // src/providers/utils/receipts.ts
39014
39023
  var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === ReceiptType.Revert && receipt.val.toString("hex") === FAILED_TRANSFER_TO_ADDRESS_SIGNAL;
@@ -39382,6 +39391,74 @@ ${MessageCoinFragmentFragmentDoc}`;
39382
39391
  });
39383
39392
  }
39384
39393
 
39394
+ // src/providers/utils/extract-tx-error.ts
39395
+ var assemblePanicError = (status) => {
39396
+ let errorMessage = `The transaction reverted with reason: "${status.reason}".`;
39397
+ const reason = status.reason;
39398
+ if (PANIC_REASONS.includes(status.reason)) {
39399
+ errorMessage = `${errorMessage}
39400
+
39401
+ You can read more about this error at:
39402
+
39403
+ ${PANIC_DOC_URL}#variant.${status.reason}`;
39404
+ }
39405
+ return { errorMessage, reason };
39406
+ };
39407
+ var stringify2 = (obj) => JSON.stringify(obj, null, 2);
39408
+ var assembleRevertError = (receipts, logs) => {
39409
+ let errorMessage = "The transaction reverted with an unknown reason.";
39410
+ const revertReceipt = receipts.find(({ type: type3 }) => type3 === ReceiptType.Revert);
39411
+ let reason = "";
39412
+ if (revertReceipt) {
39413
+ const reasonHex = bn(revertReceipt.val).toHex();
39414
+ switch (reasonHex) {
39415
+ case FAILED_REQUIRE_SIGNAL: {
39416
+ reason = "require";
39417
+ errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify2(logs[0]) : "an error."}.`;
39418
+ break;
39419
+ }
39420
+ case FAILED_ASSERT_EQ_SIGNAL: {
39421
+ const sufix = logs.length >= 2 ? ` comparing ${stringify2(logs[1])} and ${stringify2(logs[0])}.` : ".";
39422
+ reason = "assert_eq";
39423
+ errorMessage = `The transaction reverted because of an "assert_eq" statement${sufix}`;
39424
+ break;
39425
+ }
39426
+ case FAILED_ASSERT_NE_SIGNAL: {
39427
+ const sufix = logs.length >= 2 ? ` comparing ${stringify2(logs[1])} and ${stringify2(logs[0])}.` : ".";
39428
+ reason = "assert_ne";
39429
+ errorMessage = `The transaction reverted because of an "assert_ne" statement${sufix}`;
39430
+ break;
39431
+ }
39432
+ case FAILED_ASSERT_SIGNAL:
39433
+ reason = "assert";
39434
+ errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
39435
+ break;
39436
+ case FAILED_TRANSFER_TO_ADDRESS_SIGNAL:
39437
+ reason = "MissingOutputChange";
39438
+ errorMessage = `The transaction reverted because it's missing an "OutputChange".`;
39439
+ break;
39440
+ default:
39441
+ reason = "unknown";
39442
+ errorMessage = `The transaction reverted with an unknown reason: ${revertReceipt.val}`;
39443
+ }
39444
+ }
39445
+ return { errorMessage, reason };
39446
+ };
39447
+ var extractTxError = (params) => {
39448
+ const { receipts, status, logs } = params;
39449
+ const isPanic = receipts.some(({ type: type3 }) => type3 === ReceiptType.Panic);
39450
+ const isRevert = receipts.some(({ type: type3 }) => type3 === ReceiptType.Revert);
39451
+ const { errorMessage, reason } = status?.type === "FailureStatus" && isPanic ? assemblePanicError(status) : assembleRevertError(receipts, logs);
39452
+ const metadata = {
39453
+ logs,
39454
+ receipts,
39455
+ panic: isPanic,
39456
+ revert: isRevert,
39457
+ reason
39458
+ };
39459
+ return new FuelError(ErrorCode.SCRIPT_REVERTED, errorMessage, metadata);
39460
+ };
39461
+
39385
39462
  // src/providers/transaction-request/errors.ts
39386
39463
  var ChangeOutputCollisionError = class extends Error {
39387
39464
  name = "ChangeOutputCollisionError";
@@ -41198,14 +41275,26 @@ ${MessageCoinFragmentFragmentDoc}`;
41198
41275
  gqlTransaction: this.gqlTransaction,
41199
41276
  ...transactionSummary
41200
41277
  };
41278
+ let logs = [];
41201
41279
  if (this.abis) {
41202
- const logs = getDecodedLogs(
41280
+ logs = getDecodedLogs(
41203
41281
  transactionSummary.receipts,
41204
41282
  this.abis.main,
41205
41283
  this.abis.otherContractsAbis
41206
41284
  );
41207
41285
  transactionResult.logs = logs;
41208
41286
  }
41287
+ if (transactionResult.isStatusFailure) {
41288
+ const {
41289
+ receipts,
41290
+ gqlTransaction: { status }
41291
+ } = transactionResult;
41292
+ throw extractTxError({
41293
+ receipts,
41294
+ status,
41295
+ logs
41296
+ });
41297
+ }
41209
41298
  return transactionResult;
41210
41299
  }
41211
41300
  /**
@@ -41214,14 +41303,7 @@ ${MessageCoinFragmentFragmentDoc}`;
41214
41303
  * @param contractsAbiMap - The contracts ABI map.
41215
41304
  */
41216
41305
  async wait(contractsAbiMap) {
41217
- const result = await this.waitForResult(contractsAbiMap);
41218
- if (result.isStatusFailure) {
41219
- throw new FuelError(
41220
- ErrorCode.TRANSACTION_FAILED,
41221
- `Transaction failed: ${result.gqlTransaction.status.reason}`
41222
- );
41223
- }
41224
- return result;
41306
+ return this.waitForResult(contractsAbiMap);
41225
41307
  }
41226
41308
  };
41227
41309