@fuel-ts/account 0.0.0-rc-1356-20240514125020 → 0.0.0-rc-2238-20240514153703

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 (42) hide show
  1. package/dist/account.d.ts.map +1 -1
  2. package/dist/index.global.js +432 -1164
  3. package/dist/index.global.js.map +1 -1
  4. package/dist/index.js +234 -254
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +118 -145
  7. package/dist/index.mjs.map +1 -1
  8. package/dist/predicate/predicate.d.ts.map +1 -1
  9. package/dist/providers/coin.d.ts +0 -1
  10. package/dist/providers/coin.d.ts.map +1 -1
  11. package/dist/providers/message.d.ts +0 -1
  12. package/dist/providers/message.d.ts.map +1 -1
  13. package/dist/providers/transaction-request/input.d.ts +0 -2
  14. package/dist/providers/transaction-request/input.d.ts.map +1 -1
  15. package/dist/providers/transaction-request/transaction-request.d.ts +0 -1
  16. package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
  17. package/dist/providers/transaction-summary/call.d.ts +1 -1
  18. package/dist/providers/transaction-summary/call.d.ts.map +1 -1
  19. package/dist/providers/utils/auto-retry-fetch.d.ts.map +1 -1
  20. package/dist/providers/utils/index.d.ts +1 -0
  21. package/dist/providers/utils/index.d.ts.map +1 -1
  22. package/dist/providers/utils/sleep.d.ts +3 -0
  23. package/dist/providers/utils/sleep.d.ts.map +1 -0
  24. package/dist/test-utils/index.d.ts +0 -4
  25. package/dist/test-utils/index.d.ts.map +1 -1
  26. package/dist/test-utils/launchNode.d.ts +1 -8
  27. package/dist/test-utils/launchNode.d.ts.map +1 -1
  28. package/dist/test-utils.global.js +428 -1475
  29. package/dist/test-utils.global.js.map +1 -1
  30. package/dist/test-utils.js +272 -523
  31. package/dist/test-utils.js.map +1 -1
  32. package/dist/test-utils.mjs +166 -413
  33. package/dist/test-utils.mjs.map +1 -1
  34. package/package.json +15 -16
  35. package/dist/test-utils/asset-id.d.ts +0 -8
  36. package/dist/test-utils/asset-id.d.ts.map +0 -1
  37. package/dist/test-utils/setup-test-provider-and-wallets.d.ts +0 -33
  38. package/dist/test-utils/setup-test-provider-and-wallets.d.ts.map +0 -1
  39. package/dist/test-utils/test-message.d.ts +0 -28
  40. package/dist/test-utils/test-message.d.ts.map +0 -1
  41. package/dist/test-utils/wallet-config.d.ts +0 -49
  42. package/dist/test-utils/wallet-config.d.ts.map +0 -1
@@ -29470,7 +29470,7 @@ spurious results.`);
29470
29470
  // ../versions/dist/index.mjs
29471
29471
  function getBuiltinVersions() {
29472
29472
  return {
29473
- FORC: "0.56.1",
29473
+ FORC: "0.58.0",
29474
29474
  FUEL_CORE: "0.26.0",
29475
29475
  FUELS: "0.85.0"
29476
29476
  };
@@ -29985,13 +29985,6 @@ This unreleased fuel-core build may include features and updates not yet support
29985
29985
  };
29986
29986
  var DateTime = _DateTime;
29987
29987
  __publicField3(DateTime, "TAI64_NULL", "");
29988
- function sleep(time) {
29989
- return new Promise((resolve) => {
29990
- setTimeout(() => {
29991
- resolve(true);
29992
- }, time);
29993
- });
29994
- }
29995
29988
  function isDefined(value) {
29996
29989
  return value !== void 0;
29997
29990
  }
@@ -31099,19 +31092,6 @@ This unreleased fuel-core build may include features and updates not yet support
31099
31092
  __defNormalProp4(obj, typeof key !== "symbol" ? key + "" : key, value);
31100
31093
  return value;
31101
31094
  };
31102
- var __accessCheck2 = (obj, member, msg) => {
31103
- if (!member.has(obj))
31104
- throw TypeError("Cannot " + msg);
31105
- };
31106
- var __privateAdd2 = (obj, member, value) => {
31107
- if (member.has(obj))
31108
- throw TypeError("Cannot add the same private member more than once");
31109
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
31110
- };
31111
- var __privateMethod2 = (obj, member, method) => {
31112
- __accessCheck2(obj, member, "access private method");
31113
- return method;
31114
- };
31115
31095
  var Coder = class {
31116
31096
  name;
31117
31097
  type;
@@ -31143,7 +31123,6 @@ This unreleased fuel-core build may include features and updates not yet support
31143
31123
  var enumRegEx = /^enum (?<name>\w+)$/;
31144
31124
  var tupleRegEx = /^\((?<items>.*)\)$/;
31145
31125
  var genericRegEx = /^generic (?<name>\w+)$/;
31146
- var ENCODING_V0 = "0";
31147
31126
  var ENCODING_V1 = "1";
31148
31127
  var WORD_SIZE = 8;
31149
31128
  var BYTES_32 = 32;
@@ -31154,10 +31133,6 @@ This unreleased fuel-core build may include features and updates not yet support
31154
31133
  var TX_LEN = WORD_SIZE * 4;
31155
31134
  var TX_POINTER_LEN = WORD_SIZE * 2;
31156
31135
  var MAX_BYTES = 2 ** 32 - 1;
31157
- var calculateVmTxMemory = ({ maxInputs }) => BYTES_32 + // Tx ID
31158
- ASSET_ID_LEN + // Base asset ID
31159
- // Asset ID/Balance coin input pairs
31160
- maxInputs * (ASSET_ID_LEN + WORD_SIZE) + WORD_SIZE;
31161
31136
  var SCRIPT_FIXED_SIZE = WORD_SIZE + // Identifier
31162
31137
  WORD_SIZE + // Gas limit
31163
31138
  WORD_SIZE + // Script size
@@ -31188,125 +31163,6 @@ This unreleased fuel-core build may include features and updates not yet support
31188
31163
  WORD_SIZE + // Predicate size
31189
31164
  WORD_SIZE + // Predicate data size
31190
31165
  WORD_SIZE;
31191
- var encodedLengths = {
31192
- u64: WORD_SIZE,
31193
- u256: WORD_SIZE * 4
31194
- };
31195
- var BigNumberCoder = class extends Coder {
31196
- constructor(baseType) {
31197
- super("bigNumber", baseType, encodedLengths[baseType]);
31198
- }
31199
- encode(value) {
31200
- let bytes2;
31201
- try {
31202
- bytes2 = toBytes2(value, this.encodedLength);
31203
- } catch (error) {
31204
- throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.type}.`);
31205
- }
31206
- return bytes2;
31207
- }
31208
- decode(data, offset) {
31209
- if (data.length < this.encodedLength) {
31210
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid ${this.type} data size.`);
31211
- }
31212
- let bytes2 = data.slice(offset, offset + this.encodedLength);
31213
- bytes2 = bytes2.slice(0, this.encodedLength);
31214
- if (bytes2.length !== this.encodedLength) {
31215
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid ${this.type} byte data size.`);
31216
- }
31217
- return [bn(bytes2), offset + this.encodedLength];
31218
- }
31219
- };
31220
- var VEC_PROPERTY_SPACE = 3;
31221
- var BASE_VECTOR_OFFSET = VEC_PROPERTY_SPACE * WORD_SIZE;
31222
- var RAW_SLICE_PROPERTY_SPACE = 2;
31223
- var BASE_RAW_SLICE_OFFSET = RAW_SLICE_PROPERTY_SPACE * WORD_SIZE;
31224
- function concatWithDynamicData(items) {
31225
- const topLevelData = {};
31226
- let totalIndex = 0;
31227
- const objects = items.map((item) => {
31228
- const dynamicData = item.dynamicData;
31229
- if (dynamicData) {
31230
- Object.entries(dynamicData).forEach(([pointerIndex, vData]) => {
31231
- topLevelData[parseInt(pointerIndex, 10) + totalIndex] = vData;
31232
- });
31233
- }
31234
- const byteArray = arrayify(item);
31235
- totalIndex += byteArray.byteLength / WORD_SIZE;
31236
- return byteArray;
31237
- });
31238
- const length = objects.reduce((accum, item) => accum + item.length, 0);
31239
- const result = new Uint8Array(length);
31240
- objects.reduce((offset, object) => {
31241
- result.set(object, offset);
31242
- return offset + object.length;
31243
- }, 0);
31244
- if (Object.keys(topLevelData).length) {
31245
- result.dynamicData = topLevelData;
31246
- }
31247
- return result;
31248
- }
31249
- function unpackDynamicData(results, baseOffset, dataOffset) {
31250
- if (!results.dynamicData) {
31251
- return concat([results]);
31252
- }
31253
- let cumulativeDynamicByteLength = 0;
31254
- let updatedResults = results;
31255
- Object.entries(results.dynamicData).forEach(([pointerIndex, vData]) => {
31256
- const pointerOffset = parseInt(pointerIndex, 10) * WORD_SIZE;
31257
- const adjustedValue = new BigNumberCoder("u64").encode(
31258
- dataOffset + baseOffset + cumulativeDynamicByteLength
31259
- );
31260
- updatedResults.set(adjustedValue, pointerOffset);
31261
- const dataToAppend = vData.dynamicData ? (
31262
- // unpack child dynamic data
31263
- unpackDynamicData(
31264
- vData,
31265
- baseOffset,
31266
- dataOffset + vData.byteLength + cumulativeDynamicByteLength
31267
- )
31268
- ) : vData;
31269
- updatedResults = concat([updatedResults, dataToAppend]);
31270
- cumulativeDynamicByteLength += dataToAppend.byteLength;
31271
- });
31272
- return updatedResults;
31273
- }
31274
- var chunkByLength = (data, length = WORD_SIZE) => {
31275
- const chunks = [];
31276
- let offset = 0;
31277
- let chunk = data.slice(offset, offset + length);
31278
- while (chunk.length) {
31279
- chunks.push(chunk);
31280
- offset += length;
31281
- chunk = data.slice(offset, offset + length);
31282
- }
31283
- return chunks;
31284
- };
31285
- var isPointerType = (type3) => {
31286
- switch (type3) {
31287
- case "u8":
31288
- case "u16":
31289
- case "u32":
31290
- case "u64":
31291
- case "bool": {
31292
- return false;
31293
- }
31294
- default: {
31295
- return true;
31296
- }
31297
- }
31298
- };
31299
- var isHeapType = (type3) => type3 === VEC_CODER_TYPE || type3 === BYTES_CODER_TYPE || type3 === STD_STRING_CODER_TYPE;
31300
- var isMultipleOfWordSize = (length) => length % WORD_SIZE === 0;
31301
- var getWordSizePadding = (length) => WORD_SIZE - length % WORD_SIZE;
31302
- var rightPadToWordSize = (encoded) => {
31303
- if (isMultipleOfWordSize(encoded.length)) {
31304
- return encoded;
31305
- }
31306
- const padding = new Uint8Array(WORD_SIZE - encoded.length % WORD_SIZE);
31307
- return concatBytes2([encoded, padding]);
31308
- };
31309
- var isUint8Array = (value) => value instanceof Uint8Array;
31310
31166
  var ArrayCoder = class extends Coder {
31311
31167
  coder;
31312
31168
  length;
@@ -31322,7 +31178,7 @@ This unreleased fuel-core build may include features and updates not yet support
31322
31178
  if (this.length !== value.length) {
31323
31179
  throw new FuelError(ErrorCode.ENCODE_ERROR, `Types/values length mismatch.`);
31324
31180
  }
31325
- return concatWithDynamicData(Array.from(value).map((v) => this.coder.encode(v)));
31181
+ return concat(Array.from(value).map((v) => this.coder.encode(v)));
31326
31182
  }
31327
31183
  decode(data, offset) {
31328
31184
  if (data.length < this.encodedLength || data.length > MAX_BYTES) {
@@ -31399,16 +31255,42 @@ This unreleased fuel-core build may include features and updates not yet support
31399
31255
  return [toHex(bytes2, this.encodedLength), offset + this.encodedLength];
31400
31256
  }
31401
31257
  };
31258
+ var encodedLengths = {
31259
+ u64: WORD_SIZE,
31260
+ u256: WORD_SIZE * 4
31261
+ };
31262
+ var BigNumberCoder = class extends Coder {
31263
+ constructor(baseType) {
31264
+ super("bigNumber", baseType, encodedLengths[baseType]);
31265
+ }
31266
+ encode(value) {
31267
+ let bytes2;
31268
+ try {
31269
+ bytes2 = toBytes2(value, this.encodedLength);
31270
+ } catch (error) {
31271
+ throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.type}.`);
31272
+ }
31273
+ return bytes2;
31274
+ }
31275
+ decode(data, offset) {
31276
+ if (data.length < this.encodedLength) {
31277
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid ${this.type} data size.`);
31278
+ }
31279
+ let bytes2 = data.slice(offset, offset + this.encodedLength);
31280
+ bytes2 = bytes2.slice(0, this.encodedLength);
31281
+ if (bytes2.length !== this.encodedLength) {
31282
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid ${this.type} byte data size.`);
31283
+ }
31284
+ return [bn(bytes2), offset + this.encodedLength];
31285
+ }
31286
+ };
31402
31287
  var BooleanCoder = class extends Coder {
31403
- paddingLength;
31404
31288
  options;
31405
31289
  constructor(options = {
31406
- isSmallBytes: false,
31407
- isRightPadded: false
31290
+ padToWordSize: false
31408
31291
  }) {
31409
- const paddingLength = options.isSmallBytes ? 1 : 8;
31410
- super("boolean", "boolean", paddingLength);
31411
- this.paddingLength = paddingLength;
31292
+ const encodedLength = options.padToWordSize ? WORD_SIZE : 1;
31293
+ super("boolean", "boolean", encodedLength);
31412
31294
  this.options = options;
31413
31295
  }
31414
31296
  encode(value) {
@@ -31416,73 +31298,45 @@ This unreleased fuel-core build may include features and updates not yet support
31416
31298
  if (!isTrueBool) {
31417
31299
  throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid boolean value.`);
31418
31300
  }
31419
- const output2 = toBytes2(value ? 1 : 0, this.paddingLength);
31420
- if (this.options.isRightPadded) {
31421
- return output2.reverse();
31422
- }
31423
- return output2;
31301
+ return toBytes2(value ? 1 : 0, this.encodedLength);
31424
31302
  }
31425
31303
  decode(data, offset) {
31426
- if (data.length < this.paddingLength) {
31304
+ if (data.length < this.encodedLength) {
31427
31305
  throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid boolean data size.`);
31428
31306
  }
31429
- let bytes2;
31430
- if (this.options.isRightPadded) {
31431
- bytes2 = data.slice(offset, offset + 1);
31432
- } else {
31433
- bytes2 = data.slice(offset, offset + this.paddingLength);
31434
- }
31435
- const decodedValue = bn(bytes2);
31436
- if (decodedValue.isZero()) {
31437
- return [false, offset + this.paddingLength];
31307
+ const bytes2 = bn(data.slice(offset, offset + this.encodedLength));
31308
+ if (bytes2.isZero()) {
31309
+ return [false, offset + this.encodedLength];
31438
31310
  }
31439
- if (!decodedValue.eq(bn(1))) {
31311
+ if (!bytes2.eq(bn(1))) {
31440
31312
  throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid boolean value.`);
31441
31313
  }
31442
- return [true, offset + this.paddingLength];
31314
+ return [true, offset + this.encodedLength];
31443
31315
  }
31444
31316
  };
31445
- var _getPaddedData;
31446
- var getPaddedData_fn;
31447
31317
  var ByteCoder = class extends Coder {
31448
31318
  constructor() {
31449
- super("struct", "struct Bytes", BASE_VECTOR_OFFSET);
31450
- __privateAdd2(this, _getPaddedData);
31319
+ super("struct", "struct Bytes", WORD_SIZE);
31451
31320
  }
31452
31321
  encode(value) {
31453
- const parts = [];
31454
- const pointer = new BigNumberCoder("u64").encode(BASE_VECTOR_OFFSET);
31455
- const data = __privateMethod2(this, _getPaddedData, getPaddedData_fn).call(this, value);
31456
- pointer.dynamicData = {
31457
- 0: concatWithDynamicData([data])
31458
- };
31459
- parts.push(pointer);
31460
- parts.push(new BigNumberCoder("u64").encode(data.byteLength));
31461
- parts.push(new BigNumberCoder("u64").encode(value.length));
31462
- return concatWithDynamicData(parts);
31322
+ const bytes2 = value instanceof Uint8Array ? value : new Uint8Array(value);
31323
+ const lengthBytes = new BigNumberCoder("u64").encode(bytes2.length);
31324
+ return new Uint8Array([...lengthBytes, ...bytes2]);
31463
31325
  }
31464
31326
  decode(data, offset) {
31465
- if (data.length < BASE_VECTOR_OFFSET) {
31327
+ if (data.length < WORD_SIZE) {
31466
31328
  throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid byte data size.`);
31467
31329
  }
31468
- const len = data.slice(16, 24);
31469
- const encodedLength = bn(new BigNumberCoder("u64").decode(len, 0)[0]).toNumber();
31470
- const byteData = data.slice(BASE_VECTOR_OFFSET, BASE_VECTOR_OFFSET + encodedLength);
31471
- if (byteData.length !== encodedLength) {
31330
+ const offsetAndLength = offset + WORD_SIZE;
31331
+ const lengthBytes = data.slice(offset, offsetAndLength);
31332
+ const length = bn(new BigNumberCoder("u64").decode(lengthBytes, 0)[0]).toNumber();
31333
+ const dataBytes = data.slice(offsetAndLength, offsetAndLength + length);
31334
+ if (dataBytes.length !== length) {
31472
31335
  throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid bytes byte data size.`);
31473
31336
  }
31474
- return [byteData, offset + BASE_VECTOR_OFFSET];
31337
+ return [dataBytes, offsetAndLength + length];
31475
31338
  }
31476
31339
  };
31477
- _getPaddedData = /* @__PURE__ */ new WeakSet();
31478
- getPaddedData_fn = function(value) {
31479
- const data = value instanceof Uint8Array ? [value] : [new Uint8Array(value)];
31480
- const paddingLength = (WORD_SIZE - value.length % WORD_SIZE) % WORD_SIZE;
31481
- if (paddingLength) {
31482
- data.push(new Uint8Array(paddingLength));
31483
- }
31484
- return concat(data);
31485
- };
31486
31340
  __publicField4(ByteCoder, "memorySize", 1);
31487
31341
  var isFullyNativeEnum = (enumCoders) => Object.values(enumCoders).every(
31488
31342
  // @ts-expect-error complicated types
@@ -31526,8 +31380,7 @@ This unreleased fuel-core build may include features and updates not yet support
31526
31380
  const valueCoder = this.coders[caseKey];
31527
31381
  const caseIndex = Object.keys(this.coders).indexOf(caseKey);
31528
31382
  const encodedValue = valueCoder.encode(value[caseKey]);
31529
- const padding = new Uint8Array(this.#encodedValueSize - valueCoder.encodedLength);
31530
- return concatWithDynamicData([this.#caseIndexCoder.encode(caseIndex), padding, encodedValue]);
31383
+ return new Uint8Array([...this.#caseIndexCoder.encode(caseIndex), ...encodedValue]);
31531
31384
  }
31532
31385
  #decodeNativeEnum(caseKey, newOffset) {
31533
31386
  return [caseKey, newOffset];
@@ -31536,10 +31389,8 @@ This unreleased fuel-core build may include features and updates not yet support
31536
31389
  if (data.length < this.#encodedValueSize) {
31537
31390
  throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid enum data size.`);
31538
31391
  }
31539
- let newOffset = offset;
31540
- let decoded;
31541
- [decoded, newOffset] = new BigNumberCoder("u64").decode(data, newOffset);
31542
- const caseIndex = toNumber(decoded);
31392
+ const caseBytes = new BigNumberCoder("u64").decode(data, offset)[0];
31393
+ const caseIndex = toNumber(caseBytes);
31543
31394
  const caseKey = Object.keys(this.coders)[caseIndex];
31544
31395
  if (!caseKey) {
31545
31396
  throw new FuelError(
@@ -31548,67 +31399,35 @@ This unreleased fuel-core build may include features and updates not yet support
31548
31399
  );
31549
31400
  }
31550
31401
  const valueCoder = this.coders[caseKey];
31551
- const padding = this.#encodedValueSize - valueCoder.encodedLength;
31552
- newOffset += padding;
31553
- [decoded, newOffset] = valueCoder.decode(data, newOffset);
31402
+ const offsetAndCase = offset + WORD_SIZE;
31403
+ const [decoded, newOffset] = valueCoder.decode(data, offsetAndCase);
31554
31404
  if (isFullyNativeEnum(this.coders)) {
31555
31405
  return this.#decodeNativeEnum(caseKey, newOffset);
31556
31406
  }
31557
31407
  return [{ [caseKey]: decoded }, newOffset];
31558
31408
  }
31559
31409
  };
31560
- var OptionCoder = class extends EnumCoder {
31561
- encode(value) {
31562
- const result = super.encode(this.toSwayOption(value));
31563
- return result;
31564
- }
31565
- toSwayOption(input) {
31566
- if (input !== void 0) {
31567
- return { Some: input };
31568
- }
31569
- return { None: [] };
31570
- }
31571
- decode(data, offset) {
31572
- if (data.length < this.encodedLength) {
31573
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid option data size.`);
31574
- }
31575
- const [decoded, newOffset] = super.decode(data, offset);
31576
- return [this.toOption(decoded), newOffset];
31577
- }
31578
- toOption(output2) {
31579
- if (output2 && "Some" in output2) {
31580
- return output2.Some;
31581
- }
31582
- return void 0;
31410
+ var getLength = (baseType) => {
31411
+ switch (baseType) {
31412
+ case "u8":
31413
+ return 1;
31414
+ case "u16":
31415
+ return 2;
31416
+ case "u32":
31417
+ return 4;
31418
+ default:
31419
+ throw new FuelError(ErrorCode.TYPE_NOT_SUPPORTED, `Invalid number type: ${baseType}`);
31583
31420
  }
31584
31421
  };
31585
31422
  var NumberCoder = class extends Coder {
31586
- // This is to align the bits to the total bytes
31587
- // See https://github.com/FuelLabs/fuel-specs/blob/master/specs/protocol/abi.md#unsigned-integers
31588
- length;
31589
- paddingLength;
31590
31423
  baseType;
31591
31424
  options;
31592
31425
  constructor(baseType, options = {
31593
- isSmallBytes: false,
31594
- isRightPadded: false
31426
+ padToWordSize: false
31595
31427
  }) {
31596
- const paddingLength = options.isSmallBytes && baseType === "u8" ? 1 : 8;
31597
- super("number", baseType, paddingLength);
31428
+ const length = options.padToWordSize ? WORD_SIZE : getLength(baseType);
31429
+ super("number", baseType, length);
31598
31430
  this.baseType = baseType;
31599
- switch (baseType) {
31600
- case "u8":
31601
- this.length = 1;
31602
- break;
31603
- case "u16":
31604
- this.length = 2;
31605
- break;
31606
- case "u32":
31607
- default:
31608
- this.length = 4;
31609
- break;
31610
- }
31611
- this.paddingLength = paddingLength;
31612
31431
  this.options = options;
31613
31432
  }
31614
31433
  encode(value) {
@@ -31618,142 +31437,140 @@ This unreleased fuel-core build may include features and updates not yet support
31618
31437
  } catch (error) {
31619
31438
  throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.baseType}.`);
31620
31439
  }
31621
- if (bytes2.length > this.length) {
31440
+ if (bytes2.length > this.encodedLength) {
31622
31441
  throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.baseType}, too many bytes.`);
31623
31442
  }
31624
- const output2 = toBytes2(bytes2, this.paddingLength);
31625
- if (this.baseType !== "u8") {
31626
- return output2;
31627
- }
31628
- return this.options.isRightPadded ? output2.reverse() : output2;
31629
- }
31630
- decodeU8(data, offset) {
31631
- let bytes2;
31632
- if (this.options.isRightPadded) {
31633
- bytes2 = data.slice(offset, offset + 1);
31634
- } else {
31635
- bytes2 = data.slice(offset, offset + this.paddingLength);
31636
- bytes2 = bytes2.slice(this.paddingLength - this.length, this.paddingLength);
31637
- }
31638
- return [toNumber(bytes2), offset + this.paddingLength];
31443
+ return toBytes2(bytes2, this.encodedLength);
31639
31444
  }
31640
31445
  decode(data, offset) {
31641
- if (data.length < this.paddingLength) {
31446
+ if (data.length < this.encodedLength) {
31642
31447
  throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid number data size.`);
31643
31448
  }
31644
- if (this.baseType === "u8") {
31645
- return this.decodeU8(data, offset);
31646
- }
31647
- let bytes2 = data.slice(offset, offset + this.paddingLength);
31648
- bytes2 = bytes2.slice(8 - this.length, 8);
31649
- if (bytes2.length !== this.paddingLength - (this.paddingLength - this.length)) {
31449
+ const bytes2 = data.slice(offset, offset + this.encodedLength);
31450
+ if (bytes2.length !== this.encodedLength) {
31650
31451
  throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid number byte data size.`);
31651
31452
  }
31652
- return [toNumber(bytes2), offset + 8];
31453
+ return [toNumber(bytes2), offset + this.encodedLength];
31454
+ }
31455
+ };
31456
+ var OptionCoder = class extends EnumCoder {
31457
+ encode(value) {
31458
+ const result = super.encode(this.toSwayOption(value));
31459
+ return result;
31460
+ }
31461
+ toSwayOption(input) {
31462
+ if (input !== void 0) {
31463
+ return { Some: input };
31464
+ }
31465
+ return { None: [] };
31466
+ }
31467
+ decode(data, offset) {
31468
+ const [decoded, newOffset] = super.decode(data, offset);
31469
+ return [this.toOption(decoded), newOffset];
31470
+ }
31471
+ toOption(output2) {
31472
+ if (output2 && "Some" in output2) {
31473
+ return output2.Some;
31474
+ }
31475
+ return void 0;
31653
31476
  }
31654
31477
  };
31655
31478
  var RawSliceCoder = class extends Coder {
31656
31479
  constructor() {
31657
- super("raw untyped slice", "raw untyped slice", BASE_RAW_SLICE_OFFSET);
31480
+ super("raw untyped slice", "raw untyped slice", WORD_SIZE);
31658
31481
  }
31659
31482
  encode(value) {
31660
31483
  if (!Array.isArray(value)) {
31661
31484
  throw new FuelError(ErrorCode.ENCODE_ERROR, `Expected array value.`);
31662
31485
  }
31663
- const parts = [];
31664
- const coder = new NumberCoder("u8", { isSmallBytes: true });
31665
- const pointer = new BigNumberCoder("u64").encode(
31666
- BASE_RAW_SLICE_OFFSET
31667
- );
31668
- pointer.dynamicData = {
31669
- 0: concatWithDynamicData(value.map((v) => coder.encode(v)))
31670
- };
31671
- parts.push(pointer);
31672
- parts.push(new BigNumberCoder("u64").encode(value.length));
31673
- return concatWithDynamicData(parts);
31486
+ const internalCoder = new ArrayCoder(new NumberCoder("u8"), value.length);
31487
+ const bytes2 = internalCoder.encode(value);
31488
+ const lengthBytes = new BigNumberCoder("u64").encode(bytes2.length);
31489
+ return new Uint8Array([...lengthBytes, ...bytes2]);
31674
31490
  }
31675
31491
  decode(data, offset) {
31676
- const dataBytes = data.slice(offset);
31677
- const internalCoder = new ArrayCoder(
31678
- new NumberCoder("u8", { isSmallBytes: true }),
31679
- dataBytes.length
31680
- );
31492
+ if (data.length < this.encodedLength) {
31493
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid raw slice data size.`);
31494
+ }
31495
+ const offsetAndLength = offset + WORD_SIZE;
31496
+ const lengthBytes = data.slice(offset, offsetAndLength);
31497
+ const length = bn(new BigNumberCoder("u64").decode(lengthBytes, 0)[0]).toNumber();
31498
+ const dataBytes = data.slice(offsetAndLength, offsetAndLength + length);
31499
+ if (dataBytes.length !== length) {
31500
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid raw slice byte data size.`);
31501
+ }
31502
+ const internalCoder = new ArrayCoder(new NumberCoder("u8"), length);
31681
31503
  const [decodedValue] = internalCoder.decode(dataBytes, 0);
31682
- return [decodedValue, offset + dataBytes.length];
31504
+ return [decodedValue, offsetAndLength + length];
31683
31505
  }
31684
31506
  };
31685
- var _getPaddedData2;
31686
- var getPaddedData_fn2;
31687
31507
  var StdStringCoder = class extends Coder {
31688
31508
  constructor() {
31689
- super("struct", "struct String", 1);
31690
- __privateAdd2(this, _getPaddedData2);
31509
+ super("struct", "struct String", WORD_SIZE);
31691
31510
  }
31692
31511
  encode(value) {
31693
- const parts = [];
31694
- const pointer = new BigNumberCoder("u64").encode(BASE_VECTOR_OFFSET);
31695
- const data = __privateMethod2(this, _getPaddedData2, getPaddedData_fn2).call(this, value);
31696
- pointer.dynamicData = {
31697
- 0: concatWithDynamicData([data])
31698
- };
31699
- parts.push(pointer);
31700
- parts.push(new BigNumberCoder("u64").encode(data.byteLength));
31701
- parts.push(new BigNumberCoder("u64").encode(value.length));
31702
- return concatWithDynamicData(parts);
31512
+ const bytes2 = toUtf8Bytes(value);
31513
+ const lengthBytes = new BigNumberCoder("u64").encode(value.length);
31514
+ return new Uint8Array([...lengthBytes, ...bytes2]);
31703
31515
  }
31704
31516
  decode(data, offset) {
31705
31517
  if (data.length < this.encodedLength) {
31706
31518
  throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid std string data size.`);
31707
31519
  }
31708
- const len = data.slice(16, 24);
31709
- const encodedLength = bn(new BigNumberCoder("u64").decode(len, 0)[0]).toNumber();
31710
- const byteData = data.slice(BASE_VECTOR_OFFSET, BASE_VECTOR_OFFSET + encodedLength);
31711
- if (byteData.length !== encodedLength) {
31520
+ const offsetAndLength = offset + WORD_SIZE;
31521
+ const lengthBytes = data.slice(offset, offsetAndLength);
31522
+ const length = bn(new BigNumberCoder("u64").decode(lengthBytes, 0)[0]).toNumber();
31523
+ const dataBytes = data.slice(offsetAndLength, offsetAndLength + length);
31524
+ if (dataBytes.length !== length) {
31712
31525
  throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid std string byte data size.`);
31713
31526
  }
31714
- const value = toUtf8String(byteData);
31715
- return [value, offset + BASE_VECTOR_OFFSET];
31527
+ return [toUtf8String(dataBytes), offsetAndLength + length];
31716
31528
  }
31717
31529
  };
31718
- _getPaddedData2 = /* @__PURE__ */ new WeakSet();
31719
- getPaddedData_fn2 = function(value) {
31720
- const data = [toUtf8Bytes(value)];
31721
- const paddingLength = (WORD_SIZE - value.length % WORD_SIZE) % WORD_SIZE;
31722
- if (paddingLength) {
31723
- data.push(new Uint8Array(paddingLength));
31724
- }
31725
- return concat(data);
31726
- };
31727
31530
  __publicField4(StdStringCoder, "memorySize", 1);
31728
- var StringCoder = class extends Coder {
31729
- length;
31730
- #paddingLength;
31731
- constructor(length) {
31732
- let paddingLength = (8 - length) % 8;
31733
- paddingLength = paddingLength < 0 ? paddingLength + 8 : paddingLength;
31734
- super("string", `str[${length}]`, length + paddingLength);
31735
- this.length = length;
31736
- this.#paddingLength = paddingLength;
31531
+ var StrSliceCoder = class extends Coder {
31532
+ constructor() {
31533
+ super("strSlice", "str", WORD_SIZE);
31737
31534
  }
31738
31535
  encode(value) {
31739
- if (this.length !== value.length) {
31740
- throw new FuelError(ErrorCode.ENCODE_ERROR, `Value length mismatch during encode.`);
31741
- }
31742
- const encoded = toUtf8Bytes(value);
31743
- const padding = new Uint8Array(this.#paddingLength);
31744
- return concat([encoded, padding]);
31536
+ const bytes2 = toUtf8Bytes(value);
31537
+ const lengthBytes = new BigNumberCoder("u64").encode(value.length);
31538
+ return new Uint8Array([...lengthBytes, ...bytes2]);
31539
+ }
31540
+ decode(data, offset) {
31541
+ if (data.length < this.encodedLength) {
31542
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid string slice data size.`);
31543
+ }
31544
+ const offsetAndLength = offset + WORD_SIZE;
31545
+ const lengthBytes = data.slice(offset, offsetAndLength);
31546
+ const length = bn(new BigNumberCoder("u64").decode(lengthBytes, 0)[0]).toNumber();
31547
+ const bytes2 = data.slice(offsetAndLength, offsetAndLength + length);
31548
+ if (bytes2.length !== length) {
31549
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid string slice byte data size.`);
31550
+ }
31551
+ return [toUtf8String(bytes2), offsetAndLength + length];
31552
+ }
31553
+ };
31554
+ __publicField4(StrSliceCoder, "memorySize", 1);
31555
+ var StringCoder = class extends Coder {
31556
+ constructor(length) {
31557
+ super("string", `str[${length}]`, length);
31558
+ }
31559
+ encode(value) {
31560
+ if (value.length !== this.encodedLength) {
31561
+ throw new FuelError(ErrorCode.ENCODE_ERROR, `Value length mismatch during encode.`);
31562
+ }
31563
+ return toUtf8Bytes(value);
31745
31564
  }
31746
31565
  decode(data, offset) {
31747
31566
  if (data.length < this.encodedLength) {
31748
31567
  throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid string data size.`);
31749
31568
  }
31750
- const bytes2 = data.slice(offset, offset + this.length);
31751
- if (bytes2.length !== this.length) {
31569
+ const bytes2 = data.slice(offset, offset + this.encodedLength);
31570
+ if (bytes2.length !== this.encodedLength) {
31752
31571
  throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid string byte data size.`);
31753
31572
  }
31754
- const value = toUtf8String(bytes2);
31755
- const padding = this.#paddingLength;
31756
- return [value, offset + this.length + padding];
31573
+ return [toUtf8String(bytes2), offset + this.encodedLength];
31757
31574
  }
31758
31575
  };
31759
31576
  var StructCoder = class extends Coder {
@@ -31769,22 +31586,19 @@ This unreleased fuel-core build may include features and updates not yet support
31769
31586
  this.coders = coders;
31770
31587
  }
31771
31588
  encode(value) {
31772
- const encodedFields = Object.keys(this.coders).map((fieldName) => {
31773
- const fieldCoder = this.coders[fieldName];
31774
- const fieldValue = value[fieldName];
31775
- if (!(fieldCoder instanceof OptionCoder) && fieldValue == null) {
31776
- throw new FuelError(
31777
- ErrorCode.ENCODE_ERROR,
31778
- `Invalid ${this.type}. Field "${fieldName}" not present.`
31779
- );
31780
- }
31781
- const encoded = fieldCoder.encode(fieldValue);
31782
- if (!isMultipleOfWordSize(encoded.length)) {
31783
- return rightPadToWordSize(encoded);
31784
- }
31785
- return encoded;
31786
- });
31787
- return concatWithDynamicData([concatWithDynamicData(encodedFields)]);
31589
+ return concatBytes2(
31590
+ Object.keys(this.coders).map((fieldName) => {
31591
+ const fieldCoder = this.coders[fieldName];
31592
+ const fieldValue = value[fieldName];
31593
+ if (!(fieldCoder instanceof OptionCoder) && fieldValue == null) {
31594
+ throw new FuelError(
31595
+ ErrorCode.ENCODE_ERROR,
31596
+ `Invalid ${this.type}. Field "${fieldName}" not present.`
31597
+ );
31598
+ }
31599
+ return fieldCoder.encode(fieldValue);
31600
+ })
31601
+ );
31788
31602
  }
31789
31603
  decode(data, offset) {
31790
31604
  if (data.length < this.encodedLength) {
@@ -31795,9 +31609,6 @@ This unreleased fuel-core build may include features and updates not yet support
31795
31609
  const fieldCoder = this.coders[fieldName];
31796
31610
  let decoded;
31797
31611
  [decoded, newOffset] = fieldCoder.decode(data, newOffset);
31798
- if (!isMultipleOfWordSize(newOffset)) {
31799
- newOffset += getWordSizePadding(newOffset);
31800
- }
31801
31612
  obj[fieldName] = decoded;
31802
31613
  return obj;
31803
31614
  }, {});
@@ -31815,15 +31626,7 @@ This unreleased fuel-core build may include features and updates not yet support
31815
31626
  if (this.coders.length !== value.length) {
31816
31627
  throw new FuelError(ErrorCode.ENCODE_ERROR, `Types/values length mismatch.`);
31817
31628
  }
31818
- return concatWithDynamicData(
31819
- this.coders.map((coder, i) => {
31820
- const encoded = coder.encode(value[i]);
31821
- if (!isMultipleOfWordSize(encoded.length)) {
31822
- return rightPadToWordSize(encoded);
31823
- }
31824
- return encoded;
31825
- })
31826
- );
31629
+ return concatBytes2(this.coders.map((coder, i) => coder.encode(value[i])));
31827
31630
  }
31828
31631
  decode(data, offset) {
31829
31632
  if (data.length < this.encodedLength) {
@@ -31833,19 +31636,19 @@ This unreleased fuel-core build may include features and updates not yet support
31833
31636
  const decodedValue = this.coders.map((coder) => {
31834
31637
  let decoded;
31835
31638
  [decoded, newOffset] = coder.decode(data, newOffset);
31836
- if (!isMultipleOfWordSize(newOffset)) {
31837
- newOffset += getWordSizePadding(newOffset);
31838
- }
31839
31639
  return decoded;
31840
31640
  });
31841
31641
  return [decodedValue, newOffset];
31842
31642
  }
31843
31643
  };
31644
+ var isUint8Array = (value) => value instanceof Uint8Array;
31844
31645
  var VecCoder = class extends Coder {
31845
31646
  coder;
31647
+ #isOptionVec;
31846
31648
  constructor(coder) {
31847
- super("struct", `struct Vec`, coder.encodedLength + BASE_VECTOR_OFFSET);
31649
+ super("struct", `struct Vec`, coder.encodedLength + WORD_SIZE);
31848
31650
  this.coder = coder;
31651
+ this.#isOptionVec = this.coder instanceof OptionCoder;
31849
31652
  }
31850
31653
  encode(value) {
31851
31654
  if (!Array.isArray(value) && !isUint8Array(value)) {
@@ -31854,40 +31657,39 @@ This unreleased fuel-core build may include features and updates not yet support
31854
31657
  `Expected array value, or a Uint8Array. You can use arrayify to convert a value to a Uint8Array.`
31855
31658
  );
31856
31659
  }
31857
- const parts = [];
31858
- const pointer = new BigNumberCoder("u64").encode(BASE_VECTOR_OFFSET);
31859
- pointer.dynamicData = {
31860
- 0: concatWithDynamicData(Array.from(value).map((v) => this.coder.encode(v)))
31861
- };
31862
- parts.push(pointer);
31863
- parts.push(new BigNumberCoder("u64").encode(value.length));
31864
- parts.push(new BigNumberCoder("u64").encode(value.length));
31865
- return concatWithDynamicData(parts);
31660
+ const lengthCoder = new BigNumberCoder("u64");
31661
+ if (isUint8Array(value)) {
31662
+ return new Uint8Array([...lengthCoder.encode(value.length), ...value]);
31663
+ }
31664
+ const bytes2 = value.map((v) => this.coder.encode(v));
31665
+ const lengthBytes = lengthCoder.encode(value.length);
31666
+ return new Uint8Array([...lengthBytes, ...concatBytes2(bytes2)]);
31866
31667
  }
31867
31668
  decode(data, offset) {
31868
- if (data.length < BASE_VECTOR_OFFSET || data.length > MAX_BYTES) {
31669
+ if (!this.#isOptionVec && (data.length < this.encodedLength || data.length > MAX_BYTES)) {
31869
31670
  throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid vec data size.`);
31870
31671
  }
31871
- const len = data.slice(16, 24);
31872
- const encodedLength = bn(new BigNumberCoder("u64").decode(len, 0)[0]).toNumber();
31873
- const vectorRawDataLength = encodedLength * this.coder.encodedLength;
31874
- const vectorRawData = data.slice(BASE_VECTOR_OFFSET, BASE_VECTOR_OFFSET + vectorRawDataLength);
31875
- if (vectorRawData.length !== vectorRawDataLength) {
31672
+ const offsetAndLength = offset + WORD_SIZE;
31673
+ const lengthBytes = data.slice(offset, offsetAndLength);
31674
+ const length = bn(new BigNumberCoder("u64").decode(lengthBytes, 0)[0]).toNumber();
31675
+ const dataLength2 = length * this.coder.encodedLength;
31676
+ const dataBytes = data.slice(offsetAndLength, offsetAndLength + dataLength2);
31677
+ if (!this.#isOptionVec && dataBytes.length !== dataLength2) {
31876
31678
  throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid vec byte data size.`);
31877
31679
  }
31878
- return [
31879
- chunkByLength(vectorRawData, this.coder.encodedLength).map(
31880
- (chunk) => this.coder.decode(chunk, 0)[0]
31881
- ),
31882
- offset + BASE_VECTOR_OFFSET
31883
- ];
31680
+ let newOffset = offsetAndLength;
31681
+ const chunks = [];
31682
+ for (let i = 0; i < length; i++) {
31683
+ const [decoded, optionOffset] = this.coder.decode(data, newOffset);
31684
+ chunks.push(decoded);
31685
+ newOffset = optionOffset;
31686
+ }
31687
+ return [chunks, newOffset];
31884
31688
  }
31885
31689
  };
31886
31690
  var getEncodingVersion = (encoding) => {
31887
31691
  switch (encoding) {
31888
31692
  case void 0:
31889
- case ENCODING_V0:
31890
- return ENCODING_V0;
31891
31693
  case ENCODING_V1:
31892
31694
  return ENCODING_V1;
31893
31695
  default:
@@ -31924,653 +31726,175 @@ This unreleased fuel-core build may include features and updates not yet support
31924
31726
  if (!bufferComponent || !bufferTypeArgument) {
31925
31727
  throw new FuelError(
31926
31728
  ErrorCode.INVALID_COMPONENT,
31927
- `The Vec type provided is missing or has a malformed 'buf' component.`
31928
- );
31929
- }
31930
- return bufferTypeArgument;
31931
- };
31932
- var ResolvedAbiType = class {
31933
- abi;
31934
- name;
31935
- type;
31936
- originalTypeArguments;
31937
- components;
31938
- constructor(abi, argument) {
31939
- this.abi = abi;
31940
- this.name = argument.name;
31941
- const type3 = findTypeById(abi, argument.type);
31942
- this.type = type3.type;
31943
- this.originalTypeArguments = argument.typeArguments;
31944
- this.components = ResolvedAbiType.getResolvedGenericComponents(
31945
- abi,
31946
- argument,
31947
- type3.components,
31948
- type3.typeParameters ?? ResolvedAbiType.getImplicitGenericTypeParameters(abi, type3.components)
31949
- );
31950
- }
31951
- static getResolvedGenericComponents(abi, arg, components, typeParameters) {
31952
- if (components === null) {
31953
- return null;
31954
- }
31955
- if (typeParameters === null || typeParameters.length === 0) {
31956
- return components.map((c) => new ResolvedAbiType(abi, c));
31957
- }
31958
- const typeParametersAndArgsMap = typeParameters.reduce(
31959
- (obj, typeParameter, typeParameterIndex) => {
31960
- const o = { ...obj };
31961
- o[typeParameter] = structuredClone(
31962
- arg.typeArguments?.[typeParameterIndex]
31963
- );
31964
- return o;
31965
- },
31966
- {}
31967
- );
31968
- const resolvedComponents = this.resolveGenericArgTypes(
31969
- abi,
31970
- components,
31971
- typeParametersAndArgsMap
31972
- );
31973
- return resolvedComponents.map((c) => new ResolvedAbiType(abi, c));
31974
- }
31975
- static resolveGenericArgTypes(abi, args, typeParametersAndArgsMap) {
31976
- return args.map((arg) => {
31977
- if (typeParametersAndArgsMap[arg.type] !== void 0) {
31978
- return {
31979
- ...typeParametersAndArgsMap[arg.type],
31980
- name: arg.name
31981
- };
31982
- }
31983
- if (arg.typeArguments) {
31984
- return {
31985
- ...structuredClone(arg),
31986
- typeArguments: this.resolveGenericArgTypes(
31987
- abi,
31988
- arg.typeArguments,
31989
- typeParametersAndArgsMap
31990
- )
31991
- };
31992
- }
31993
- const argType = findTypeById(abi, arg.type);
31994
- const implicitTypeParameters = this.getImplicitGenericTypeParameters(abi, argType.components);
31995
- if (implicitTypeParameters && implicitTypeParameters.length > 0) {
31996
- return {
31997
- ...structuredClone(arg),
31998
- typeArguments: implicitTypeParameters.map((itp) => typeParametersAndArgsMap[itp])
31999
- };
32000
- }
32001
- return arg;
32002
- });
32003
- }
32004
- static getImplicitGenericTypeParameters(abi, args, implicitGenericParametersParam) {
32005
- if (!Array.isArray(args)) {
32006
- return null;
32007
- }
32008
- const implicitGenericParameters = implicitGenericParametersParam ?? [];
32009
- args.forEach((a) => {
32010
- const argType = findTypeById(abi, a.type);
32011
- if (genericRegEx.test(argType.type)) {
32012
- implicitGenericParameters.push(argType.typeId);
32013
- return;
32014
- }
32015
- if (!Array.isArray(a.typeArguments)) {
32016
- return;
32017
- }
32018
- this.getImplicitGenericTypeParameters(abi, a.typeArguments, implicitGenericParameters);
32019
- });
32020
- return implicitGenericParameters.length > 0 ? implicitGenericParameters : null;
32021
- }
32022
- getSignature() {
32023
- const prefix = this.getArgSignaturePrefix();
32024
- const content = this.getArgSignatureContent();
32025
- return `${prefix}${content}`;
32026
- }
32027
- getArgSignaturePrefix() {
32028
- const structMatch = structRegEx.test(this.type);
32029
- if (structMatch) {
32030
- return "s";
32031
- }
32032
- const arrayMatch = arrayRegEx.test(this.type);
32033
- if (arrayMatch) {
32034
- return "a";
32035
- }
32036
- const enumMatch = enumRegEx.test(this.type);
32037
- if (enumMatch) {
32038
- return "e";
32039
- }
32040
- return "";
32041
- }
32042
- getArgSignatureContent() {
32043
- if (this.type === "raw untyped ptr") {
32044
- return "rawptr";
32045
- }
32046
- if (this.type === "raw untyped slice") {
32047
- return "rawslice";
32048
- }
32049
- const strMatch = stringRegEx.exec(this.type)?.groups;
32050
- if (strMatch) {
32051
- return `str[${strMatch.length}]`;
32052
- }
32053
- if (this.components === null) {
32054
- return this.type;
32055
- }
32056
- const arrayMatch = arrayRegEx.exec(this.type)?.groups;
32057
- if (arrayMatch) {
32058
- return `[${this.components[0].getSignature()};${arrayMatch.length}]`;
32059
- }
32060
- const typeArgumentsSignature = this.originalTypeArguments !== null ? `<${this.originalTypeArguments.map((a) => new ResolvedAbiType(this.abi, a).getSignature()).join(",")}>` : "";
32061
- const componentsSignature = `(${this.components.map((c) => c.getSignature()).join(",")})`;
32062
- return `${typeArgumentsSignature}${componentsSignature}`;
32063
- }
32064
- };
32065
- function getCoders(components, options) {
32066
- const { getCoder: getCoder3 } = options;
32067
- return components.reduce((obj, component) => {
32068
- const o = obj;
32069
- o[component.name] = getCoder3(component, options);
32070
- return o;
32071
- }, {});
32072
- }
32073
- var getCoder = (resolvedAbiType, options) => {
32074
- switch (resolvedAbiType.type) {
32075
- case U8_CODER_TYPE:
32076
- case U16_CODER_TYPE:
32077
- case U32_CODER_TYPE:
32078
- return new NumberCoder(resolvedAbiType.type, options);
32079
- case U64_CODER_TYPE:
32080
- case RAW_PTR_CODER_TYPE:
32081
- return new BigNumberCoder("u64");
32082
- case U256_CODER_TYPE:
32083
- return new BigNumberCoder("u256");
32084
- case RAW_SLICE_CODER_TYPE:
32085
- return new RawSliceCoder();
32086
- case BOOL_CODER_TYPE:
32087
- return new BooleanCoder(options);
32088
- case B256_CODER_TYPE:
32089
- return new B256Coder();
32090
- case B512_CODER_TYPE:
32091
- return new B512Coder();
32092
- case BYTES_CODER_TYPE:
32093
- return new ByteCoder();
32094
- case STD_STRING_CODER_TYPE:
32095
- return new StdStringCoder();
32096
- default:
32097
- break;
32098
- }
32099
- const stringMatch = stringRegEx.exec(resolvedAbiType.type)?.groups;
32100
- if (stringMatch) {
32101
- const length = parseInt(stringMatch.length, 10);
32102
- return new StringCoder(length);
32103
- }
32104
- const components = resolvedAbiType.components;
32105
- const arrayMatch = arrayRegEx.exec(resolvedAbiType.type)?.groups;
32106
- if (arrayMatch) {
32107
- const length = parseInt(arrayMatch.length, 10);
32108
- const arg = components[0];
32109
- if (!arg) {
32110
- throw new FuelError(
32111
- ErrorCode.INVALID_COMPONENT,
32112
- `The provided Array type is missing an item of 'component'.`
32113
- );
32114
- }
32115
- const arrayElementCoder = getCoder(arg, { isSmallBytes: true });
32116
- return new ArrayCoder(arrayElementCoder, length);
32117
- }
32118
- if (resolvedAbiType.type === VEC_CODER_TYPE) {
32119
- const arg = findVectorBufferArgument(components);
32120
- const argType = new ResolvedAbiType(resolvedAbiType.abi, arg);
32121
- const itemCoder = getCoder(argType, { isSmallBytes: true, encoding: ENCODING_V0 });
32122
- return new VecCoder(itemCoder);
32123
- }
32124
- const structMatch = structRegEx.exec(resolvedAbiType.type)?.groups;
32125
- if (structMatch) {
32126
- const coders = getCoders(components, { isRightPadded: true, getCoder });
32127
- return new StructCoder(structMatch.name, coders);
32128
- }
32129
- const enumMatch = enumRegEx.exec(resolvedAbiType.type)?.groups;
32130
- if (enumMatch) {
32131
- const coders = getCoders(components, { getCoder });
32132
- const isOptionEnum = resolvedAbiType.type === OPTION_CODER_TYPE;
32133
- if (isOptionEnum) {
32134
- return new OptionCoder(enumMatch.name, coders);
32135
- }
32136
- return new EnumCoder(enumMatch.name, coders);
32137
- }
32138
- const tupleMatch = tupleRegEx.exec(resolvedAbiType.type)?.groups;
32139
- if (tupleMatch) {
32140
- const coders = components.map(
32141
- (component) => getCoder(component, { isRightPadded: true, encoding: ENCODING_V0 })
32142
- );
32143
- return new TupleCoder(coders);
32144
- }
32145
- if (resolvedAbiType.type === STR_SLICE_CODER_TYPE) {
32146
- throw new FuelError(
32147
- ErrorCode.INVALID_DATA,
32148
- "String slices can not be decoded from logs. Convert the slice to `str[N]` with `__to_str_array`"
32149
- );
32150
- }
32151
- throw new FuelError(
32152
- ErrorCode.CODER_NOT_FOUND,
32153
- `Coder not found: ${JSON.stringify(resolvedAbiType)}.`
32154
- );
32155
- };
32156
- var BooleanCoder2 = class extends Coder {
32157
- constructor() {
32158
- super("boolean", "boolean", 1);
32159
- }
32160
- encode(value) {
32161
- const isTrueBool = value === true || value === false;
32162
- if (!isTrueBool) {
32163
- throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid boolean value.`);
32164
- }
32165
- return toBytes2(value ? 1 : 0, this.encodedLength);
32166
- }
32167
- decode(data, offset) {
32168
- if (data.length < this.encodedLength) {
32169
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid boolean data size.`);
32170
- }
32171
- const bytes2 = bn(data.slice(offset, offset + this.encodedLength));
32172
- if (bytes2.isZero()) {
32173
- return [false, offset + this.encodedLength];
32174
- }
32175
- if (!bytes2.eq(bn(1))) {
32176
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid boolean value.`);
32177
- }
32178
- return [true, offset + this.encodedLength];
32179
- }
32180
- };
32181
- var ByteCoder2 = class extends Coder {
32182
- constructor() {
32183
- super("struct", "struct Bytes", WORD_SIZE);
32184
- }
32185
- encode(value) {
32186
- const bytes2 = value instanceof Uint8Array ? value : new Uint8Array(value);
32187
- const lengthBytes = new BigNumberCoder("u64").encode(bytes2.length);
32188
- return new Uint8Array([...lengthBytes, ...bytes2]);
32189
- }
32190
- decode(data, offset) {
32191
- if (data.length < WORD_SIZE) {
32192
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid byte data size.`);
32193
- }
32194
- const offsetAndLength = offset + WORD_SIZE;
32195
- const lengthBytes = data.slice(offset, offsetAndLength);
32196
- const length = bn(new BigNumberCoder("u64").decode(lengthBytes, 0)[0]).toNumber();
32197
- const dataBytes = data.slice(offsetAndLength, offsetAndLength + length);
32198
- if (dataBytes.length !== length) {
32199
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid bytes byte data size.`);
32200
- }
32201
- return [dataBytes, offsetAndLength + length];
32202
- }
32203
- };
32204
- __publicField4(ByteCoder2, "memorySize", 1);
32205
- var isFullyNativeEnum2 = (enumCoders) => Object.values(enumCoders).every(
32206
- // @ts-expect-error complicated types
32207
- ({ type: type3, coders }) => type3 === "()" && JSON.stringify(coders) === JSON.stringify([])
32208
- );
32209
- var EnumCoder2 = class extends Coder {
32210
- name;
32211
- coders;
32212
- #caseIndexCoder;
32213
- #encodedValueSize;
32214
- constructor(name, coders) {
32215
- const caseIndexCoder = new BigNumberCoder("u64");
32216
- const encodedValueSize = Object.values(coders).reduce(
32217
- (max, coder) => Math.max(max, coder.encodedLength),
32218
- 0
32219
- );
32220
- super(`enum ${name}`, `enum ${name}`, caseIndexCoder.encodedLength + encodedValueSize);
32221
- this.name = name;
32222
- this.coders = coders;
32223
- this.#caseIndexCoder = caseIndexCoder;
32224
- this.#encodedValueSize = encodedValueSize;
32225
- }
32226
- #encodeNativeEnum(value) {
32227
- const valueCoder = this.coders[value];
32228
- const encodedValue = valueCoder.encode([]);
32229
- const caseIndex = Object.keys(this.coders).indexOf(value);
32230
- const padding = new Uint8Array(this.#encodedValueSize - valueCoder.encodedLength);
32231
- return concat([this.#caseIndexCoder.encode(caseIndex), padding, encodedValue]);
32232
- }
32233
- encode(value) {
32234
- if (typeof value === "string" && this.coders[value]) {
32235
- return this.#encodeNativeEnum(value);
32236
- }
32237
- const [caseKey, ...empty] = Object.keys(value);
32238
- if (!caseKey) {
32239
- throw new FuelError(ErrorCode.INVALID_DECODE_VALUE, "A field for the case must be provided.");
32240
- }
32241
- if (empty.length !== 0) {
32242
- throw new FuelError(ErrorCode.INVALID_DECODE_VALUE, "Only one field must be provided.");
32243
- }
32244
- const valueCoder = this.coders[caseKey];
32245
- const caseIndex = Object.keys(this.coders).indexOf(caseKey);
32246
- const encodedValue = valueCoder.encode(value[caseKey]);
32247
- return new Uint8Array([...this.#caseIndexCoder.encode(caseIndex), ...encodedValue]);
32248
- }
32249
- #decodeNativeEnum(caseKey, newOffset) {
32250
- return [caseKey, newOffset];
32251
- }
32252
- decode(data, offset) {
32253
- if (data.length < this.#encodedValueSize) {
32254
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid enum data size.`);
32255
- }
32256
- const caseBytes = new BigNumberCoder("u64").decode(data, offset)[0];
32257
- const caseIndex = toNumber(caseBytes);
32258
- const caseKey = Object.keys(this.coders)[caseIndex];
32259
- if (!caseKey) {
32260
- throw new FuelError(
32261
- ErrorCode.INVALID_DECODE_VALUE,
32262
- `Invalid caseIndex "${caseIndex}". Valid cases: ${Object.keys(this.coders)}.`
32263
- );
32264
- }
32265
- const valueCoder = this.coders[caseKey];
32266
- const offsetAndCase = offset + WORD_SIZE;
32267
- const [decoded, newOffset] = valueCoder.decode(data, offsetAndCase);
32268
- if (isFullyNativeEnum2(this.coders)) {
32269
- return this.#decodeNativeEnum(caseKey, newOffset);
32270
- }
32271
- return [{ [caseKey]: decoded }, newOffset];
32272
- }
32273
- };
32274
- var getLength = (baseType) => {
32275
- switch (baseType) {
32276
- case "u8":
32277
- return 1;
32278
- case "u16":
32279
- return 2;
32280
- case "u32":
32281
- return 4;
32282
- default:
32283
- throw new FuelError(ErrorCode.TYPE_NOT_SUPPORTED, `Invalid number type: ${baseType}`);
32284
- }
32285
- };
32286
- var NumberCoder2 = class extends Coder {
32287
- length;
32288
- baseType;
32289
- constructor(baseType) {
32290
- const length = getLength(baseType);
32291
- super("number", baseType, length);
32292
- this.baseType = baseType;
32293
- this.length = length;
32294
- }
32295
- encode(value) {
32296
- let bytes2;
32297
- try {
32298
- bytes2 = toBytes2(value);
32299
- } catch (error) {
32300
- throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.baseType}.`);
32301
- }
32302
- if (bytes2.length > this.length) {
32303
- throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.baseType}, too many bytes.`);
32304
- }
32305
- return toBytes2(bytes2, this.length);
32306
- }
32307
- decode(data, offset) {
32308
- if (data.length < this.encodedLength) {
32309
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid number data size.`);
32310
- }
32311
- const bytes2 = data.slice(offset, offset + this.length);
32312
- if (bytes2.length !== this.encodedLength) {
32313
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid number byte data size.`);
32314
- }
32315
- return [toNumber(bytes2), offset + this.length];
32316
- }
32317
- };
32318
- var OptionCoder2 = class extends EnumCoder2 {
32319
- encode(value) {
32320
- const result = super.encode(this.toSwayOption(value));
32321
- return result;
32322
- }
32323
- toSwayOption(input) {
32324
- if (input !== void 0) {
32325
- return { Some: input };
32326
- }
32327
- return { None: [] };
32328
- }
32329
- decode(data, offset) {
32330
- const [decoded, newOffset] = super.decode(data, offset);
32331
- return [this.toOption(decoded), newOffset];
32332
- }
32333
- toOption(output2) {
32334
- if (output2 && "Some" in output2) {
32335
- return output2.Some;
32336
- }
32337
- return void 0;
32338
- }
32339
- };
32340
- var RawSliceCoder2 = class extends Coder {
32341
- constructor() {
32342
- super("raw untyped slice", "raw untyped slice", WORD_SIZE);
32343
- }
32344
- encode(value) {
32345
- if (!Array.isArray(value)) {
32346
- throw new FuelError(ErrorCode.ENCODE_ERROR, `Expected array value.`);
32347
- }
32348
- const internalCoder = new ArrayCoder(new NumberCoder2("u8"), value.length);
32349
- const bytes2 = internalCoder.encode(value);
32350
- const lengthBytes = new BigNumberCoder("u64").encode(bytes2.length);
32351
- return new Uint8Array([...lengthBytes, ...bytes2]);
32352
- }
32353
- decode(data, offset) {
32354
- if (data.length < this.encodedLength) {
32355
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid raw slice data size.`);
32356
- }
32357
- const offsetAndLength = offset + WORD_SIZE;
32358
- const lengthBytes = data.slice(offset, offsetAndLength);
32359
- const length = bn(new BigNumberCoder("u64").decode(lengthBytes, 0)[0]).toNumber();
32360
- const dataBytes = data.slice(offsetAndLength, offsetAndLength + length);
32361
- if (dataBytes.length !== length) {
32362
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid raw slice byte data size.`);
32363
- }
32364
- const internalCoder = new ArrayCoder(new NumberCoder2("u8"), length);
32365
- const [decodedValue] = internalCoder.decode(dataBytes, 0);
32366
- return [decodedValue, offsetAndLength + length];
32367
- }
32368
- };
32369
- var StdStringCoder2 = class extends Coder {
32370
- constructor() {
32371
- super("struct", "struct String", WORD_SIZE);
32372
- }
32373
- encode(value) {
32374
- const bytes2 = toUtf8Bytes(value);
32375
- const lengthBytes = new BigNumberCoder("u64").encode(value.length);
32376
- return new Uint8Array([...lengthBytes, ...bytes2]);
32377
- }
32378
- decode(data, offset) {
32379
- if (data.length < this.encodedLength) {
32380
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid std string data size.`);
32381
- }
32382
- const offsetAndLength = offset + WORD_SIZE;
32383
- const lengthBytes = data.slice(offset, offsetAndLength);
32384
- const length = bn(new BigNumberCoder("u64").decode(lengthBytes, 0)[0]).toNumber();
32385
- const dataBytes = data.slice(offsetAndLength, offsetAndLength + length);
32386
- if (dataBytes.length !== length) {
32387
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid std string byte data size.`);
32388
- }
32389
- return [toUtf8String(dataBytes), offsetAndLength + length];
32390
- }
32391
- };
32392
- __publicField4(StdStringCoder2, "memorySize", 1);
32393
- var StrSliceCoder = class extends Coder {
32394
- constructor() {
32395
- super("strSlice", "str", WORD_SIZE);
32396
- }
32397
- encode(value) {
32398
- const bytes2 = toUtf8Bytes(value);
32399
- const lengthBytes = new BigNumberCoder("u64").encode(value.length);
32400
- return new Uint8Array([...lengthBytes, ...bytes2]);
32401
- }
32402
- decode(data, offset) {
32403
- if (data.length < this.encodedLength) {
32404
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid string slice data size.`);
32405
- }
32406
- const offsetAndLength = offset + WORD_SIZE;
32407
- const lengthBytes = data.slice(offset, offsetAndLength);
32408
- const length = bn(new BigNumberCoder("u64").decode(lengthBytes, 0)[0]).toNumber();
32409
- const bytes2 = data.slice(offsetAndLength, offsetAndLength + length);
32410
- if (bytes2.length !== length) {
32411
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid string slice byte data size.`);
32412
- }
32413
- return [toUtf8String(bytes2), offsetAndLength + length];
32414
- }
32415
- };
32416
- __publicField4(StrSliceCoder, "memorySize", 1);
32417
- var StringCoder2 = class extends Coder {
32418
- constructor(length) {
32419
- super("string", `str[${length}]`, length);
32420
- }
32421
- encode(value) {
32422
- if (value.length !== this.encodedLength) {
32423
- throw new FuelError(ErrorCode.ENCODE_ERROR, `Value length mismatch during encode.`);
32424
- }
32425
- return toUtf8Bytes(value);
32426
- }
32427
- decode(data, offset) {
32428
- if (data.length < this.encodedLength) {
32429
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid string data size.`);
32430
- }
32431
- const bytes2 = data.slice(offset, offset + this.encodedLength);
32432
- if (bytes2.length !== this.encodedLength) {
32433
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid string byte data size.`);
32434
- }
32435
- return [toUtf8String(bytes2), offset + this.encodedLength];
32436
- }
32437
- };
32438
- var StructCoder2 = class extends Coder {
32439
- name;
32440
- coders;
32441
- constructor(name, coders) {
32442
- const encodedLength = Object.values(coders).reduce(
32443
- (acc, coder) => acc + coder.encodedLength,
32444
- 0
32445
- );
32446
- super("struct", `struct ${name}`, encodedLength);
32447
- this.name = name;
32448
- this.coders = coders;
32449
- }
32450
- encode(value) {
32451
- return concatBytes2(
32452
- Object.keys(this.coders).map((fieldName) => {
32453
- const fieldCoder = this.coders[fieldName];
32454
- const fieldValue = value[fieldName];
32455
- if (!(fieldCoder instanceof OptionCoder2) && fieldValue == null) {
32456
- throw new FuelError(
32457
- ErrorCode.ENCODE_ERROR,
32458
- `Invalid ${this.type}. Field "${fieldName}" not present.`
32459
- );
32460
- }
32461
- return fieldCoder.encode(fieldValue);
32462
- })
32463
- );
32464
- }
32465
- decode(data, offset) {
32466
- if (data.length < this.encodedLength) {
32467
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid struct data size.`);
32468
- }
32469
- let newOffset = offset;
32470
- const decodedValue = Object.keys(this.coders).reduce((obj, fieldName) => {
32471
- const fieldCoder = this.coders[fieldName];
32472
- let decoded;
32473
- [decoded, newOffset] = fieldCoder.decode(data, newOffset);
32474
- obj[fieldName] = decoded;
32475
- return obj;
32476
- }, {});
32477
- return [decodedValue, newOffset];
31729
+ `The Vec type provided is missing or has a malformed 'buf' component.`
31730
+ );
32478
31731
  }
31732
+ return bufferTypeArgument;
32479
31733
  };
32480
- var TupleCoder2 = class extends Coder {
32481
- coders;
32482
- constructor(coders) {
32483
- const encodedLength = coders.reduce((acc, coder) => acc + coder.encodedLength, 0);
32484
- super("tuple", `(${coders.map((coder) => coder.type).join(", ")})`, encodedLength);
32485
- this.coders = coders;
31734
+ var ResolvedAbiType = class {
31735
+ abi;
31736
+ name;
31737
+ type;
31738
+ originalTypeArguments;
31739
+ components;
31740
+ constructor(abi, argument) {
31741
+ this.abi = abi;
31742
+ this.name = argument.name;
31743
+ const type3 = findTypeById(abi, argument.type);
31744
+ this.type = type3.type;
31745
+ this.originalTypeArguments = argument.typeArguments;
31746
+ this.components = ResolvedAbiType.getResolvedGenericComponents(
31747
+ abi,
31748
+ argument,
31749
+ type3.components,
31750
+ type3.typeParameters ?? ResolvedAbiType.getImplicitGenericTypeParameters(abi, type3.components)
31751
+ );
32486
31752
  }
32487
- encode(value) {
32488
- if (this.coders.length !== value.length) {
32489
- throw new FuelError(ErrorCode.ENCODE_ERROR, `Types/values length mismatch.`);
31753
+ static getResolvedGenericComponents(abi, arg, components, typeParameters) {
31754
+ if (components === null) {
31755
+ return null;
32490
31756
  }
32491
- return concatBytes2(this.coders.map((coder, i) => coder.encode(value[i])));
31757
+ if (typeParameters === null || typeParameters.length === 0) {
31758
+ return components.map((c) => new ResolvedAbiType(abi, c));
31759
+ }
31760
+ const typeParametersAndArgsMap = typeParameters.reduce(
31761
+ (obj, typeParameter, typeParameterIndex) => {
31762
+ const o = { ...obj };
31763
+ o[typeParameter] = structuredClone(
31764
+ arg.typeArguments?.[typeParameterIndex]
31765
+ );
31766
+ return o;
31767
+ },
31768
+ {}
31769
+ );
31770
+ const resolvedComponents = this.resolveGenericArgTypes(
31771
+ abi,
31772
+ components,
31773
+ typeParametersAndArgsMap
31774
+ );
31775
+ return resolvedComponents.map((c) => new ResolvedAbiType(abi, c));
32492
31776
  }
32493
- decode(data, offset) {
32494
- if (data.length < this.encodedLength) {
32495
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid tuple data size.`);
31777
+ static resolveGenericArgTypes(abi, args, typeParametersAndArgsMap) {
31778
+ return args.map((arg) => {
31779
+ if (typeParametersAndArgsMap[arg.type] !== void 0) {
31780
+ return {
31781
+ ...typeParametersAndArgsMap[arg.type],
31782
+ name: arg.name
31783
+ };
31784
+ }
31785
+ if (arg.typeArguments) {
31786
+ return {
31787
+ ...structuredClone(arg),
31788
+ typeArguments: this.resolveGenericArgTypes(
31789
+ abi,
31790
+ arg.typeArguments,
31791
+ typeParametersAndArgsMap
31792
+ )
31793
+ };
31794
+ }
31795
+ const argType = findTypeById(abi, arg.type);
31796
+ const implicitTypeParameters = this.getImplicitGenericTypeParameters(abi, argType.components);
31797
+ if (implicitTypeParameters && implicitTypeParameters.length > 0) {
31798
+ return {
31799
+ ...structuredClone(arg),
31800
+ typeArguments: implicitTypeParameters.map((itp) => typeParametersAndArgsMap[itp])
31801
+ };
31802
+ }
31803
+ return arg;
31804
+ });
31805
+ }
31806
+ static getImplicitGenericTypeParameters(abi, args, implicitGenericParametersParam) {
31807
+ if (!Array.isArray(args)) {
31808
+ return null;
32496
31809
  }
32497
- let newOffset = offset;
32498
- const decodedValue = this.coders.map((coder) => {
32499
- let decoded;
32500
- [decoded, newOffset] = coder.decode(data, newOffset);
32501
- return decoded;
31810
+ const implicitGenericParameters = implicitGenericParametersParam ?? [];
31811
+ args.forEach((a) => {
31812
+ const argType = findTypeById(abi, a.type);
31813
+ if (genericRegEx.test(argType.type)) {
31814
+ implicitGenericParameters.push(argType.typeId);
31815
+ return;
31816
+ }
31817
+ if (!Array.isArray(a.typeArguments)) {
31818
+ return;
31819
+ }
31820
+ this.getImplicitGenericTypeParameters(abi, a.typeArguments, implicitGenericParameters);
32502
31821
  });
32503
- return [decodedValue, newOffset];
31822
+ return implicitGenericParameters.length > 0 ? implicitGenericParameters : null;
32504
31823
  }
32505
- };
32506
- var VecCoder2 = class extends Coder {
32507
- coder;
32508
- #isOptionVec;
32509
- constructor(coder) {
32510
- super("struct", `struct Vec`, coder.encodedLength + WORD_SIZE);
32511
- this.coder = coder;
32512
- this.#isOptionVec = this.coder instanceof OptionCoder2;
31824
+ getSignature() {
31825
+ const prefix = this.getArgSignaturePrefix();
31826
+ const content = this.getArgSignatureContent();
31827
+ return `${prefix}${content}`;
32513
31828
  }
32514
- encode(value) {
32515
- if (!Array.isArray(value) && !isUint8Array(value)) {
32516
- throw new FuelError(
32517
- ErrorCode.ENCODE_ERROR,
32518
- `Expected array value, or a Uint8Array. You can use arrayify to convert a value to a Uint8Array.`
32519
- );
31829
+ getArgSignaturePrefix() {
31830
+ const structMatch = structRegEx.test(this.type);
31831
+ if (structMatch) {
31832
+ return "s";
32520
31833
  }
32521
- const lengthCoder = new BigNumberCoder("u64");
32522
- if (isUint8Array(value)) {
32523
- return new Uint8Array([...lengthCoder.encode(value.length), ...value]);
31834
+ const arrayMatch = arrayRegEx.test(this.type);
31835
+ if (arrayMatch) {
31836
+ return "a";
32524
31837
  }
32525
- const bytes2 = value.map((v) => this.coder.encode(v));
32526
- const lengthBytes = lengthCoder.encode(value.length);
32527
- return new Uint8Array([...lengthBytes, ...concatBytes2(bytes2)]);
31838
+ const enumMatch = enumRegEx.test(this.type);
31839
+ if (enumMatch) {
31840
+ return "e";
31841
+ }
31842
+ return "";
32528
31843
  }
32529
- decode(data, offset) {
32530
- if (!this.#isOptionVec && (data.length < this.encodedLength || data.length > MAX_BYTES)) {
32531
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid vec data size.`);
31844
+ getArgSignatureContent() {
31845
+ if (this.type === "raw untyped ptr") {
31846
+ return "rawptr";
32532
31847
  }
32533
- const offsetAndLength = offset + WORD_SIZE;
32534
- const lengthBytes = data.slice(offset, offsetAndLength);
32535
- const length = bn(new BigNumberCoder("u64").decode(lengthBytes, 0)[0]).toNumber();
32536
- const dataLength2 = length * this.coder.encodedLength;
32537
- const dataBytes = data.slice(offsetAndLength, offsetAndLength + dataLength2);
32538
- if (!this.#isOptionVec && dataBytes.length !== dataLength2) {
32539
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid vec byte data size.`);
31848
+ if (this.type === "raw untyped slice") {
31849
+ return "rawslice";
32540
31850
  }
32541
- let newOffset = offsetAndLength;
32542
- const chunks = [];
32543
- for (let i = 0; i < length; i++) {
32544
- const [decoded, optionOffset] = this.coder.decode(data, newOffset);
32545
- chunks.push(decoded);
32546
- newOffset = optionOffset;
31851
+ const strMatch = stringRegEx.exec(this.type)?.groups;
31852
+ if (strMatch) {
31853
+ return `str[${strMatch.length}]`;
32547
31854
  }
32548
- return [chunks, newOffset];
31855
+ if (this.components === null) {
31856
+ return this.type;
31857
+ }
31858
+ const arrayMatch = arrayRegEx.exec(this.type)?.groups;
31859
+ if (arrayMatch) {
31860
+ return `[${this.components[0].getSignature()};${arrayMatch.length}]`;
31861
+ }
31862
+ const typeArgumentsSignature = this.originalTypeArguments !== null ? `<${this.originalTypeArguments.map((a) => new ResolvedAbiType(this.abi, a).getSignature()).join(",")}>` : "";
31863
+ const componentsSignature = `(${this.components.map((c) => c.getSignature()).join(",")})`;
31864
+ return `${typeArgumentsSignature}${componentsSignature}`;
32549
31865
  }
32550
31866
  };
32551
- var getCoder2 = (resolvedAbiType, _options) => {
31867
+ function getCoders(components, options) {
31868
+ const { getCoder: getCoder2 } = options;
31869
+ return components.reduce((obj, component) => {
31870
+ const o = obj;
31871
+ o[component.name] = getCoder2(component, options);
31872
+ return o;
31873
+ }, {});
31874
+ }
31875
+ var getCoder = (resolvedAbiType, _options) => {
32552
31876
  switch (resolvedAbiType.type) {
32553
31877
  case U8_CODER_TYPE:
32554
31878
  case U16_CODER_TYPE:
32555
31879
  case U32_CODER_TYPE:
32556
- return new NumberCoder2(resolvedAbiType.type);
31880
+ return new NumberCoder(resolvedAbiType.type);
32557
31881
  case U64_CODER_TYPE:
32558
31882
  case RAW_PTR_CODER_TYPE:
32559
31883
  return new BigNumberCoder("u64");
32560
31884
  case U256_CODER_TYPE:
32561
31885
  return new BigNumberCoder("u256");
32562
31886
  case RAW_SLICE_CODER_TYPE:
32563
- return new RawSliceCoder2();
31887
+ return new RawSliceCoder();
32564
31888
  case BOOL_CODER_TYPE:
32565
- return new BooleanCoder2();
31889
+ return new BooleanCoder();
32566
31890
  case B256_CODER_TYPE:
32567
31891
  return new B256Coder();
32568
31892
  case B512_CODER_TYPE:
32569
31893
  return new B512Coder();
32570
31894
  case BYTES_CODER_TYPE:
32571
- return new ByteCoder2();
31895
+ return new ByteCoder();
32572
31896
  case STD_STRING_CODER_TYPE:
32573
- return new StdStringCoder2();
31897
+ return new StdStringCoder();
32574
31898
  case STR_SLICE_CODER_TYPE:
32575
31899
  return new StrSliceCoder();
32576
31900
  default:
@@ -32579,7 +31903,7 @@ This unreleased fuel-core build may include features and updates not yet support
32579
31903
  const stringMatch = stringRegEx.exec(resolvedAbiType.type)?.groups;
32580
31904
  if (stringMatch) {
32581
31905
  const length = parseInt(stringMatch.length, 10);
32582
- return new StringCoder2(length);
31906
+ return new StringCoder(length);
32583
31907
  }
32584
31908
  const components = resolvedAbiType.components;
32585
31909
  const arrayMatch = arrayRegEx.exec(resolvedAbiType.type)?.groups;
@@ -32592,46 +31916,42 @@ This unreleased fuel-core build may include features and updates not yet support
32592
31916
  `The provided Array type is missing an item of 'component'.`
32593
31917
  );
32594
31918
  }
32595
- const arrayElementCoder = getCoder2(arg, { isSmallBytes: true });
31919
+ const arrayElementCoder = getCoder(arg);
32596
31920
  return new ArrayCoder(arrayElementCoder, length);
32597
31921
  }
32598
31922
  if (resolvedAbiType.type === VEC_CODER_TYPE) {
32599
31923
  const arg = findVectorBufferArgument(components);
32600
31924
  const argType = new ResolvedAbiType(resolvedAbiType.abi, arg);
32601
- const itemCoder = getCoder2(argType, { isSmallBytes: true, encoding: ENCODING_V0 });
32602
- return new VecCoder2(itemCoder);
31925
+ const itemCoder = getCoder(argType, { encoding: ENCODING_V1 });
31926
+ return new VecCoder(itemCoder);
32603
31927
  }
32604
31928
  const structMatch = structRegEx.exec(resolvedAbiType.type)?.groups;
32605
31929
  if (structMatch) {
32606
- const coders = getCoders(components, { isRightPadded: true, getCoder: getCoder2 });
32607
- return new StructCoder2(structMatch.name, coders);
31930
+ const coders = getCoders(components, { getCoder });
31931
+ return new StructCoder(structMatch.name, coders);
32608
31932
  }
32609
31933
  const enumMatch = enumRegEx.exec(resolvedAbiType.type)?.groups;
32610
31934
  if (enumMatch) {
32611
- const coders = getCoders(components, { getCoder: getCoder2 });
31935
+ const coders = getCoders(components, { getCoder });
32612
31936
  const isOptionEnum = resolvedAbiType.type === OPTION_CODER_TYPE;
32613
31937
  if (isOptionEnum) {
32614
- return new OptionCoder2(enumMatch.name, coders);
31938
+ return new OptionCoder(enumMatch.name, coders);
32615
31939
  }
32616
- return new EnumCoder2(enumMatch.name, coders);
31940
+ return new EnumCoder(enumMatch.name, coders);
32617
31941
  }
32618
31942
  const tupleMatch = tupleRegEx.exec(resolvedAbiType.type)?.groups;
32619
31943
  if (tupleMatch) {
32620
- const coders = components.map(
32621
- (component) => getCoder2(component, { isRightPadded: true, encoding: ENCODING_V0 })
32622
- );
32623
- return new TupleCoder2(coders);
31944
+ const coders = components.map((component) => getCoder(component, { encoding: ENCODING_V1 }));
31945
+ return new TupleCoder(coders);
32624
31946
  }
32625
31947
  throw new FuelError(
32626
31948
  ErrorCode.CODER_NOT_FOUND,
32627
31949
  `Coder not found: ${JSON.stringify(resolvedAbiType)}.`
32628
31950
  );
32629
31951
  };
32630
- function getCoderForEncoding(encoding = ENCODING_V0) {
31952
+ function getCoderForEncoding(encoding = ENCODING_V1) {
32631
31953
  switch (encoding) {
32632
31954
  case ENCODING_V1:
32633
- return getCoder2;
32634
- case ENCODING_V0:
32635
31955
  return getCoder;
32636
31956
  default:
32637
31957
  throw new FuelError(
@@ -32642,7 +31962,7 @@ This unreleased fuel-core build may include features and updates not yet support
32642
31962
  }
32643
31963
  var AbiCoder = class {
32644
31964
  static getCoder(abi, argument, options = {
32645
- isSmallBytes: false
31965
+ padToWordSize: false
32646
31966
  }) {
32647
31967
  const resolvedAbiType = new ResolvedAbiType(abi, argument);
32648
31968
  return getCoderForEncoding(options.encoding)(resolvedAbiType, options);
@@ -32662,8 +31982,6 @@ This unreleased fuel-core build may include features and updates not yet support
32662
31982
  name;
32663
31983
  jsonFn;
32664
31984
  attributes;
32665
- isInputDataPointer;
32666
- outputMetadata;
32667
31985
  jsonAbi;
32668
31986
  constructor(jsonAbi, name) {
32669
31987
  this.jsonAbi = jsonAbi;
@@ -32671,13 +31989,8 @@ This unreleased fuel-core build may include features and updates not yet support
32671
31989
  this.name = name;
32672
31990
  this.signature = FunctionFragment.getSignature(this.jsonAbi, this.jsonFn);
32673
31991
  this.selector = FunctionFragment.getFunctionSelector(this.signature);
32674
- this.selectorBytes = new StdStringCoder2().encode(name);
31992
+ this.selectorBytes = new StdStringCoder().encode(name);
32675
31993
  this.encoding = getEncodingVersion(jsonAbi.encoding);
32676
- this.isInputDataPointer = this.#isInputDataPointer();
32677
- this.outputMetadata = {
32678
- isHeapType: this.#isOutputDataHeap(),
32679
- encodedLength: this.#getOutputEncodedLength()
32680
- };
32681
31994
  this.attributes = this.jsonFn.attributes ?? [];
32682
31995
  }
32683
31996
  static getSignature(abi, fn) {
@@ -32690,29 +32003,7 @@ This unreleased fuel-core build may include features and updates not yet support
32690
32003
  const hashedFunctionSignature = sha2562(bufferFromString2(functionSignature, "utf-8"));
32691
32004
  return bn(hashedFunctionSignature.slice(0, 10)).toHex(8);
32692
32005
  }
32693
- #isInputDataPointer() {
32694
- const inputTypes = this.jsonFn.inputs.map((i) => findTypeById(this.jsonAbi, i.type));
32695
- return this.jsonFn.inputs.length > 1 || isPointerType(inputTypes[0]?.type || "");
32696
- }
32697
- #isOutputDataHeap() {
32698
- const outputType = findTypeById(this.jsonAbi, this.jsonFn.output.type);
32699
- return isHeapType(outputType?.type || "");
32700
- }
32701
- #getOutputEncodedLength() {
32702
- try {
32703
- const heapCoder = AbiCoder.getCoder(this.jsonAbi, this.jsonFn.output);
32704
- if (heapCoder instanceof VecCoder) {
32705
- return heapCoder.coder.encodedLength;
32706
- }
32707
- if (heapCoder instanceof ByteCoder) {
32708
- return ByteCoder.memorySize;
32709
- }
32710
- return heapCoder.encodedLength;
32711
- } catch (e) {
32712
- return 0;
32713
- }
32714
- }
32715
- encodeArguments(values, offset = 0) {
32006
+ encodeArguments(values) {
32716
32007
  FunctionFragment.verifyArgsAndInputsAlign(values, this.jsonFn.inputs, this.jsonAbi);
32717
32008
  const shallowCopyValues = values.slice();
32718
32009
  const nonEmptyInputs = findNonEmptyInputs(this.jsonAbi, this.jsonFn.inputs);
@@ -32722,15 +32013,10 @@ This unreleased fuel-core build may include features and updates not yet support
32722
32013
  }
32723
32014
  const coders = nonEmptyInputs.map(
32724
32015
  (t) => AbiCoder.getCoder(this.jsonAbi, t, {
32725
- isRightPadded: nonEmptyInputs.length > 1,
32726
32016
  encoding: this.encoding
32727
32017
  })
32728
32018
  );
32729
- if (this.encoding === ENCODING_V1) {
32730
- return new TupleCoder2(coders).encode(shallowCopyValues);
32731
- }
32732
- const results = new TupleCoder(coders).encode(shallowCopyValues);
32733
- return unpackDynamicData(results, offset, results.byteLength);
32019
+ return new TupleCoder(coders).encode(shallowCopyValues);
32734
32020
  }
32735
32021
  static verifyArgsAndInputsAlign(args, inputs, abi) {
32736
32022
  if (args.length === inputs.length) {
@@ -32839,9 +32125,9 @@ This unreleased fuel-core build may include features and updates not yet support
32839
32125
  const fragment = typeof functionFragment === "string" ? this.getFunction(functionFragment) : functionFragment;
32840
32126
  return fragment.decodeArguments(data);
32841
32127
  }
32842
- encodeFunctionData(functionFragment, values, offset = 0) {
32128
+ encodeFunctionData(functionFragment, values) {
32843
32129
  const fragment = typeof functionFragment === "string" ? this.getFunction(functionFragment) : functionFragment;
32844
- return fragment.encodeArguments(values, offset);
32130
+ return fragment.encodeArguments(values);
32845
32131
  }
32846
32132
  // Decode the result of a function call
32847
32133
  decodeFunctionResult(functionFragment, data) {
@@ -32869,9 +32155,7 @@ This unreleased fuel-core build may include features and updates not yet support
32869
32155
  );
32870
32156
  }
32871
32157
  return AbiCoder.encode(this.jsonAbi, configurable.configurableType, value, {
32872
- isRightPadded: true,
32873
- // TODO: Review support for configurables in v1 encoding when it becomes available
32874
- encoding: ENCODING_V0
32158
+ encoding: this.encoding
32875
32159
  });
32876
32160
  }
32877
32161
  getTypeById(typeId) {
@@ -32921,8 +32205,8 @@ This unreleased fuel-core build may include features and updates not yet support
32921
32205
  var TxPointerCoder = class extends StructCoder {
32922
32206
  constructor() {
32923
32207
  super("TxPointer", {
32924
- blockHeight: new NumberCoder("u32"),
32925
- txIndex: new NumberCoder("u16")
32208
+ blockHeight: new NumberCoder("u32", { padToWordSize: true }),
32209
+ txIndex: new NumberCoder("u16", { padToWordSize: true })
32926
32210
  });
32927
32211
  }
32928
32212
  };
@@ -32939,12 +32223,12 @@ This unreleased fuel-core build may include features and updates not yet support
32939
32223
  encode(value) {
32940
32224
  const parts = [];
32941
32225
  parts.push(new B256Coder().encode(value.txID));
32942
- parts.push(new NumberCoder("u16").encode(value.outputIndex));
32226
+ parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.outputIndex));
32943
32227
  parts.push(new B256Coder().encode(value.owner));
32944
32228
  parts.push(new BigNumberCoder("u64").encode(value.amount));
32945
32229
  parts.push(new B256Coder().encode(value.assetId));
32946
32230
  parts.push(new TxPointerCoder().encode(value.txPointer));
32947
- parts.push(new NumberCoder("u16").encode(value.witnessIndex));
32231
+ parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.witnessIndex));
32948
32232
  parts.push(new BigNumberCoder("u64").encode(value.predicateGasUsed));
32949
32233
  parts.push(new BigNumberCoder("u64").encode(value.predicateLength));
32950
32234
  parts.push(new BigNumberCoder("u64").encode(value.predicateDataLength));
@@ -32959,7 +32243,7 @@ This unreleased fuel-core build may include features and updates not yet support
32959
32243
  let o = offset;
32960
32244
  [decoded, o] = new B256Coder().decode(data, o);
32961
32245
  const txID = decoded;
32962
- [decoded, o] = new NumberCoder("u16").decode(data, o);
32246
+ [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
32963
32247
  const outputIndex = decoded;
32964
32248
  [decoded, o] = new B256Coder().decode(data, o);
32965
32249
  const owner = decoded;
@@ -32969,7 +32253,7 @@ This unreleased fuel-core build may include features and updates not yet support
32969
32253
  const assetId = decoded;
32970
32254
  [decoded, o] = new TxPointerCoder().decode(data, o);
32971
32255
  const txPointer = decoded;
32972
- [decoded, o] = new NumberCoder("u16").decode(data, o);
32256
+ [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
32973
32257
  const witnessIndex = Number(decoded);
32974
32258
  [decoded, o] = new BigNumberCoder("u64").decode(data, o);
32975
32259
  const predicateGasUsed = decoded;
@@ -33008,7 +32292,7 @@ This unreleased fuel-core build may include features and updates not yet support
33008
32292
  encode(value) {
33009
32293
  const parts = [];
33010
32294
  parts.push(new B256Coder().encode(value.txID));
33011
- parts.push(new NumberCoder("u16").encode(value.outputIndex));
32295
+ parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.outputIndex));
33012
32296
  parts.push(new B256Coder().encode(value.balanceRoot));
33013
32297
  parts.push(new B256Coder().encode(value.stateRoot));
33014
32298
  parts.push(new TxPointerCoder().encode(value.txPointer));
@@ -33020,7 +32304,7 @@ This unreleased fuel-core build may include features and updates not yet support
33020
32304
  let o = offset;
33021
32305
  [decoded, o] = new B256Coder().decode(data, o);
33022
32306
  const txID = decoded;
33023
- [decoded, o] = new NumberCoder("u16").decode(data, o);
32307
+ [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
33024
32308
  const outputIndex = decoded;
33025
32309
  [decoded, o] = new B256Coder().decode(data, o);
33026
32310
  const balanceRoot = decoded;
@@ -33069,7 +32353,7 @@ This unreleased fuel-core build may include features and updates not yet support
33069
32353
  parts.push(new ByteArrayCoder(32).encode(value.recipient));
33070
32354
  parts.push(new BigNumberCoder("u64").encode(value.amount));
33071
32355
  parts.push(new ByteArrayCoder(32).encode(value.nonce));
33072
- parts.push(new NumberCoder("u16").encode(value.witnessIndex));
32356
+ parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.witnessIndex));
33073
32357
  parts.push(new BigNumberCoder("u64").encode(value.predicateGasUsed));
33074
32358
  parts.push(new BigNumberCoder("u64").encode(data.length));
33075
32359
  parts.push(new BigNumberCoder("u64").encode(value.predicateLength));
@@ -33098,11 +32382,11 @@ This unreleased fuel-core build may include features and updates not yet support
33098
32382
  const amount = decoded;
33099
32383
  [decoded, o] = new B256Coder().decode(data, o);
33100
32384
  const nonce = decoded;
33101
- [decoded, o] = new NumberCoder("u16").decode(data, o);
32385
+ [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
33102
32386
  const witnessIndex = Number(decoded);
33103
32387
  [decoded, o] = new BigNumberCoder("u64").decode(data, o);
33104
32388
  const predicateGasUsed = decoded;
33105
- [decoded, o] = new NumberCoder("u32").decode(data, o);
32389
+ [decoded, o] = new NumberCoder("u32", { padToWordSize: true }).decode(data, o);
33106
32390
  const dataLength2 = decoded;
33107
32391
  [decoded, o] = new BigNumberCoder("u64").decode(data, o);
33108
32392
  const predicateLength = decoded;
@@ -33140,7 +32424,7 @@ This unreleased fuel-core build may include features and updates not yet support
33140
32424
  }
33141
32425
  encode(value) {
33142
32426
  const parts = [];
33143
- parts.push(new NumberCoder("u8").encode(value.type));
32427
+ parts.push(new NumberCoder("u8", { padToWordSize: true }).encode(value.type));
33144
32428
  const { type: type3 } = value;
33145
32429
  switch (type3) {
33146
32430
  case 0: {
@@ -33167,7 +32451,7 @@ This unreleased fuel-core build may include features and updates not yet support
33167
32451
  decode(data, offset) {
33168
32452
  let decoded;
33169
32453
  let o = offset;
33170
- [decoded, o] = new NumberCoder("u8").decode(data, o);
32454
+ [decoded, o] = new NumberCoder("u8", { padToWordSize: true }).decode(data, o);
33171
32455
  const type3 = decoded;
33172
32456
  switch (type3) {
33173
32457
  case 0: {
@@ -33236,7 +32520,7 @@ This unreleased fuel-core build may include features and updates not yet support
33236
32520
  }
33237
32521
  encode(value) {
33238
32522
  const parts = [];
33239
- parts.push(new NumberCoder("u8").encode(value.inputIndex));
32523
+ parts.push(new NumberCoder("u8", { padToWordSize: true }).encode(value.inputIndex));
33240
32524
  parts.push(new B256Coder().encode(value.balanceRoot));
33241
32525
  parts.push(new B256Coder().encode(value.stateRoot));
33242
32526
  return concat(parts);
@@ -33244,7 +32528,7 @@ This unreleased fuel-core build may include features and updates not yet support
33244
32528
  decode(data, offset) {
33245
32529
  let decoded;
33246
32530
  let o = offset;
33247
- [decoded, o] = new NumberCoder("u8").decode(data, o);
32531
+ [decoded, o] = new NumberCoder("u8", { padToWordSize: true }).decode(data, o);
33248
32532
  const inputIndex = decoded;
33249
32533
  [decoded, o] = new B256Coder().decode(data, o);
33250
32534
  const balanceRoot = decoded;
@@ -33356,7 +32640,7 @@ This unreleased fuel-core build may include features and updates not yet support
33356
32640
  }
33357
32641
  encode(value) {
33358
32642
  const parts = [];
33359
- parts.push(new NumberCoder("u8").encode(value.type));
32643
+ parts.push(new NumberCoder("u8", { padToWordSize: true }).encode(value.type));
33360
32644
  const { type: type3 } = value;
33361
32645
  switch (type3) {
33362
32646
  case 0: {
@@ -33391,7 +32675,7 @@ This unreleased fuel-core build may include features and updates not yet support
33391
32675
  decode(data, offset) {
33392
32676
  let decoded;
33393
32677
  let o = offset;
33394
- [decoded, o] = new NumberCoder("u8").decode(data, o);
32678
+ [decoded, o] = new NumberCoder("u8", { padToWordSize: true }).decode(data, o);
33395
32679
  const type3 = decoded;
33396
32680
  switch (type3) {
33397
32681
  case 0: {
@@ -33459,7 +32743,7 @@ This unreleased fuel-core build may include features and updates not yet support
33459
32743
  parts.push(new BigNumberCoder("u64").encode(data));
33460
32744
  break;
33461
32745
  case 4:
33462
- parts.push(new NumberCoder("u32").encode(data));
32746
+ parts.push(new NumberCoder("u32", { padToWordSize: true }).encode(data));
33463
32747
  break;
33464
32748
  default: {
33465
32749
  throw new FuelError(ErrorCode.INVALID_POLICY_TYPE, `Invalid policy type: ${type3}`);
@@ -33482,7 +32766,10 @@ This unreleased fuel-core build may include features and updates not yet support
33482
32766
  policies.push({ type: 2, data: witnessLimit });
33483
32767
  }
33484
32768
  if (policyTypes & 4) {
33485
- const [maturity, nextOffset] = new NumberCoder("u32").decode(data, o);
32769
+ const [maturity, nextOffset] = new NumberCoder("u32", { padToWordSize: true }).decode(
32770
+ data,
32771
+ o
32772
+ );
33486
32773
  o = nextOffset;
33487
32774
  policies.push({ type: 4, data: maturity });
33488
32775
  }
@@ -33529,7 +32816,7 @@ This unreleased fuel-core build may include features and updates not yet support
33529
32816
  parts.push(new B256Coder().encode(value.recipient));
33530
32817
  parts.push(new BigNumberCoder("u64").encode(value.amount));
33531
32818
  parts.push(new B256Coder().encode(value.nonce));
33532
- parts.push(new NumberCoder("u16").encode(value.data.length));
32819
+ parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.data.length));
33533
32820
  parts.push(new B256Coder().encode(value.digest));
33534
32821
  parts.push(new ByteArrayCoder(value.data.length).encode(value.data));
33535
32822
  return concat(parts);
@@ -33545,7 +32832,7 @@ This unreleased fuel-core build may include features and updates not yet support
33545
32832
  const amount = decoded;
33546
32833
  [decoded, o] = new B256Coder().decode(data, o);
33547
32834
  const nonce = decoded;
33548
- [decoded, o] = new NumberCoder("u16").decode(data, o);
32835
+ [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
33549
32836
  const len = decoded;
33550
32837
  [decoded, o] = new B256Coder().decode(data, o);
33551
32838
  const digest = decoded;
@@ -33669,11 +32956,11 @@ This unreleased fuel-core build may include features and updates not yet support
33669
32956
  encode(upgradePurposeType) {
33670
32957
  const parts = [];
33671
32958
  const { type: type3 } = upgradePurposeType;
33672
- parts.push(new NumberCoder("u8").encode(type3));
32959
+ parts.push(new NumberCoder("u8", { padToWordSize: true }).encode(type3));
33673
32960
  switch (type3) {
33674
32961
  case 0: {
33675
32962
  const data = upgradePurposeType.data;
33676
- parts.push(new NumberCoder("u16").encode(data.witnessIndex));
32963
+ parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(data.witnessIndex));
33677
32964
  parts.push(new B256Coder().encode(data.checksum));
33678
32965
  break;
33679
32966
  }
@@ -33694,11 +32981,11 @@ This unreleased fuel-core build may include features and updates not yet support
33694
32981
  decode(data, offset) {
33695
32982
  let o = offset;
33696
32983
  let decoded;
33697
- [decoded, o] = new NumberCoder("u8").decode(data, o);
32984
+ [decoded, o] = new NumberCoder("u8", { padToWordSize: true }).decode(data, o);
33698
32985
  const type3 = decoded;
33699
32986
  switch (type3) {
33700
32987
  case 0: {
33701
- [decoded, o] = new NumberCoder("u16").decode(data, o);
32988
+ [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
33702
32989
  const witnessIndex = decoded;
33703
32990
  [decoded, o] = new B256Coder().decode(data, o);
33704
32991
  const checksum = decoded;
@@ -33729,14 +33016,14 @@ This unreleased fuel-core build may include features and updates not yet support
33729
33016
  }
33730
33017
  encode(value) {
33731
33018
  const parts = [];
33732
- parts.push(new NumberCoder("u32").encode(value.dataLength));
33019
+ parts.push(new NumberCoder("u32", { padToWordSize: true }).encode(value.dataLength));
33733
33020
  parts.push(new ByteArrayCoder(value.dataLength).encode(value.data));
33734
33021
  return concat(parts);
33735
33022
  }
33736
33023
  decode(data, offset) {
33737
33024
  let decoded;
33738
33025
  let o = offset;
33739
- [decoded, o] = new NumberCoder("u32").decode(data, o);
33026
+ [decoded, o] = new NumberCoder("u32", { padToWordSize: true }).decode(data, o);
33740
33027
  const dataLength2 = decoded;
33741
33028
  [decoded, o] = new ByteArrayCoder(dataLength2).decode(data, o);
33742
33029
  const witnessData = decoded;
@@ -33767,10 +33054,10 @@ This unreleased fuel-core build may include features and updates not yet support
33767
33054
  parts.push(new B256Coder().encode(value.receiptsRoot));
33768
33055
  parts.push(new BigNumberCoder("u64").encode(value.scriptLength));
33769
33056
  parts.push(new BigNumberCoder("u64").encode(value.scriptDataLength));
33770
- parts.push(new NumberCoder("u32").encode(value.policyTypes));
33771
- parts.push(new NumberCoder("u16").encode(value.inputsCount));
33772
- parts.push(new NumberCoder("u16").encode(value.outputsCount));
33773
- parts.push(new NumberCoder("u16").encode(value.witnessesCount));
33057
+ parts.push(new NumberCoder("u32", { padToWordSize: true }).encode(value.policyTypes));
33058
+ parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.inputsCount));
33059
+ parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.outputsCount));
33060
+ parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.witnessesCount));
33774
33061
  parts.push(new ByteArrayCoder(value.scriptLength.toNumber()).encode(value.script));
33775
33062
  parts.push(new ByteArrayCoder(value.scriptDataLength.toNumber()).encode(value.scriptData));
33776
33063
  parts.push(new PoliciesCoder().encode(value.policies));
@@ -33790,13 +33077,13 @@ This unreleased fuel-core build may include features and updates not yet support
33790
33077
  const scriptLength = decoded;
33791
33078
  [decoded, o] = new BigNumberCoder("u64").decode(data, o);
33792
33079
  const scriptDataLength = decoded;
33793
- [decoded, o] = new NumberCoder("u32").decode(data, o);
33080
+ [decoded, o] = new NumberCoder("u32", { padToWordSize: true }).decode(data, o);
33794
33081
  const policyTypes = decoded;
33795
- [decoded, o] = new NumberCoder("u16").decode(data, o);
33082
+ [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
33796
33083
  const inputsCount = decoded;
33797
- [decoded, o] = new NumberCoder("u16").decode(data, o);
33084
+ [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
33798
33085
  const outputsCount = decoded;
33799
- [decoded, o] = new NumberCoder("u16").decode(data, o);
33086
+ [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
33800
33087
  const witnessesCount = decoded;
33801
33088
  [decoded, o] = new ByteArrayCoder(scriptLength.toNumber()).decode(data, o);
33802
33089
  const script = decoded;
@@ -33838,13 +33125,13 @@ This unreleased fuel-core build may include features and updates not yet support
33838
33125
  }
33839
33126
  encode(value) {
33840
33127
  const parts = [];
33841
- parts.push(new NumberCoder("u16").encode(value.bytecodeWitnessIndex));
33128
+ parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.bytecodeWitnessIndex));
33842
33129
  parts.push(new B256Coder().encode(value.salt));
33843
33130
  parts.push(new BigNumberCoder("u64").encode(value.storageSlotsCount));
33844
- parts.push(new NumberCoder("u32").encode(value.policyTypes));
33845
- parts.push(new NumberCoder("u16").encode(value.inputsCount));
33846
- parts.push(new NumberCoder("u16").encode(value.outputsCount));
33847
- parts.push(new NumberCoder("u16").encode(value.witnessesCount));
33131
+ parts.push(new NumberCoder("u32", { padToWordSize: true }).encode(value.policyTypes));
33132
+ parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.inputsCount));
33133
+ parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.outputsCount));
33134
+ parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.witnessesCount));
33848
33135
  parts.push(
33849
33136
  new ArrayCoder(new StorageSlotCoder(), value.storageSlotsCount.toNumber()).encode(
33850
33137
  value.storageSlots
@@ -33859,19 +33146,19 @@ This unreleased fuel-core build may include features and updates not yet support
33859
33146
  decode(data, offset) {
33860
33147
  let decoded;
33861
33148
  let o = offset;
33862
- [decoded, o] = new NumberCoder("u16").decode(data, o);
33149
+ [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
33863
33150
  const bytecodeWitnessIndex = decoded;
33864
33151
  [decoded, o] = new B256Coder().decode(data, o);
33865
33152
  const salt = decoded;
33866
33153
  [decoded, o] = new BigNumberCoder("u64").decode(data, o);
33867
33154
  const storageSlotsCount = decoded;
33868
- [decoded, o] = new NumberCoder("u32").decode(data, o);
33155
+ [decoded, o] = new NumberCoder("u32", { padToWordSize: true }).decode(data, o);
33869
33156
  const policyTypes = decoded;
33870
- [decoded, o] = new NumberCoder("u16").decode(data, o);
33157
+ [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
33871
33158
  const inputsCount = decoded;
33872
- [decoded, o] = new NumberCoder("u16").decode(data, o);
33159
+ [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
33873
33160
  const outputsCount = decoded;
33874
- [decoded, o] = new NumberCoder("u16").decode(data, o);
33161
+ [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
33875
33162
  const witnessesCount = decoded;
33876
33163
  [decoded, o] = new ArrayCoder(new StorageSlotCoder(), storageSlotsCount.toNumber()).decode(
33877
33164
  data,
@@ -34085,7 +33372,7 @@ This unreleased fuel-core build may include features and updates not yet support
34085
33372
  }
34086
33373
  encode(value) {
34087
33374
  const parts = [];
34088
- parts.push(new NumberCoder("u8").encode(value.type));
33375
+ parts.push(new NumberCoder("u8", { padToWordSize: true }).encode(value.type));
34089
33376
  const { type: type3 } = value;
34090
33377
  switch (value.type) {
34091
33378
  case 0: {
@@ -34128,7 +33415,7 @@ This unreleased fuel-core build may include features and updates not yet support
34128
33415
  decode(data, offset) {
34129
33416
  let decoded;
34130
33417
  let o = offset;
34131
- [decoded, o] = new NumberCoder("u8").decode(data, o);
33418
+ [decoded, o] = new NumberCoder("u8", { padToWordSize: true }).decode(data, o);
34132
33419
  const type3 = decoded;
34133
33420
  switch (type3) {
34134
33421
  case 0: {
@@ -39205,6 +38492,15 @@ ${MessageCoinFragmentDoc}`;
39205
38492
  return normalize2(clone_default(root));
39206
38493
  }
39207
38494
 
38495
+ // src/providers/utils/sleep.ts
38496
+ function sleep(time) {
38497
+ return new Promise((resolve) => {
38498
+ setTimeout(() => {
38499
+ resolve(true);
38500
+ }, time);
38501
+ });
38502
+ }
38503
+
39208
38504
  // src/providers/utils/extract-tx-error.ts
39209
38505
  var assemblePanicError = (status) => {
39210
38506
  let errorMessage = `The transaction reverted with reason: "${status.reason}".`;
@@ -39846,15 +39142,6 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
39846
39142
  }
39847
39143
  });
39848
39144
  }
39849
- shiftPredicateData() {
39850
- this.inputs.forEach((input) => {
39851
- if ("predicateData" in input && "padPredicateData" in input && typeof input.padPredicateData === "function") {
39852
- input.predicateData = input.padPredicateData(
39853
- BaseTransactionRequest.getPolicyMeta(this).policies.length
39854
- );
39855
- }
39856
- });
39857
- }
39858
39145
  };
39859
39146
 
39860
39147
  // src/providers/transaction-request/hash-transaction.ts
@@ -40319,37 +39606,27 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
40319
39606
  };
40320
39607
 
40321
39608
  // src/providers/transaction-summary/call.ts
40322
- var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
39609
+ var getFunctionCall = ({ abi, receipt }) => {
40323
39610
  const abiInterface = new Interface(abi);
40324
39611
  const callFunctionSelector = receipt.param1.toHex(8);
40325
39612
  const functionFragment = abiInterface.getFunction(callFunctionSelector);
40326
39613
  const inputs = functionFragment.jsonFn.inputs;
40327
- let encodedArgs;
40328
- if (functionFragment.isInputDataPointer) {
40329
- if (rawPayload) {
40330
- const argsOffset = bn(receipt.param2).sub(calculateVmTxMemory({ maxInputs: maxInputs.toNumber() })).toNumber();
40331
- encodedArgs = `0x${rawPayload.slice(2).slice(argsOffset * 2)}`;
40332
- }
40333
- } else {
40334
- encodedArgs = receipt.param2.toHex();
40335
- }
39614
+ const encodedArgs = receipt.param2.toHex();
40336
39615
  let argumentsProvided;
40337
- if (encodedArgs) {
40338
- const data = functionFragment.decodeArguments(encodedArgs);
40339
- if (data) {
40340
- argumentsProvided = inputs.reduce((prev, input, index) => {
40341
- const value = data[index];
40342
- const name = input.name;
40343
- if (name) {
40344
- return {
40345
- ...prev,
40346
- // reparse to remove bn
40347
- [name]: JSON.parse(JSON.stringify(value))
40348
- };
40349
- }
40350
- return prev;
40351
- }, {});
40352
- }
39616
+ const data = functionFragment.decodeArguments(encodedArgs);
39617
+ if (data) {
39618
+ argumentsProvided = inputs.reduce((prev, input, index) => {
39619
+ const value = data[index];
39620
+ const name = input.name;
39621
+ if (name) {
39622
+ return {
39623
+ ...prev,
39624
+ // reparse to remove bn
39625
+ [name]: JSON.parse(JSON.stringify(value))
39626
+ };
39627
+ }
39628
+ return prev;
39629
+ }, {});
40353
39630
  }
40354
39631
  const call = {
40355
39632
  functionSignature: functionFragment.signature,
@@ -42846,7 +42123,6 @@ Supported fuel-core version: ${supportedVersion}.`
42846
42123
  cacheRequestInputsResourcesFromOwner(request.inputs, this.address)
42847
42124
  );
42848
42125
  request.addResources(resources);
42849
- request.shiftPredicateData();
42850
42126
  request.updatePredicateGasUsed(estimatedPredicates);
42851
42127
  const requestToReestimate2 = clone_default(request);
42852
42128
  if (addedSignatures) {
@@ -42878,7 +42154,6 @@ Supported fuel-core version: ${supportedVersion}.`
42878
42154
  }
42879
42155
  fundingAttempts += 1;
42880
42156
  }
42881
- request.shiftPredicateData();
42882
42157
  request.updatePredicateGasUsed(estimatedPredicates);
42883
42158
  const requestToReestimate = clone_default(request);
42884
42159
  if (addedSignatures) {
@@ -47952,7 +47227,6 @@ Supported fuel-core version: ${supportedVersion}.`
47952
47227
  */
47953
47228
  populateTransactionPredicateData(transactionRequestLike) {
47954
47229
  const request = transactionRequestify(transactionRequestLike);
47955
- const { policies } = BaseTransactionRequest.getPolicyMeta(request);
47956
47230
  const placeholderIndex = this.getIndexFromPlaceholderWitness(request);
47957
47231
  if (placeholderIndex !== -1) {
47958
47232
  request.removeWitness(placeholderIndex);
@@ -47960,7 +47234,7 @@ Supported fuel-core version: ${supportedVersion}.`
47960
47234
  request.inputs.filter(isRequestInputResource).forEach((input) => {
47961
47235
  if (isRequestInputResourceFromOwner(input, this.address)) {
47962
47236
  input.predicate = hexlify(this.bytes);
47963
- input.predicateData = hexlify(this.getPredicateData(policies.length));
47237
+ input.predicateData = hexlify(this.getPredicateData());
47964
47238
  input.witnessIndex = 0;
47965
47239
  }
47966
47240
  });
@@ -47986,17 +47260,12 @@ Supported fuel-core version: ${supportedVersion}.`
47986
47260
  const transactionRequest = transactionRequestify(transactionRequestLike);
47987
47261
  return super.simulateTransaction(transactionRequest, { estimateTxDependencies: false });
47988
47262
  }
47989
- getPredicateData(policiesLength) {
47263
+ getPredicateData() {
47990
47264
  if (!this.predicateData.length) {
47991
47265
  return new Uint8Array();
47992
47266
  }
47993
47267
  const mainFn = this.interface?.functions.main;
47994
- const paddedCode = new ByteArrayCoder(this.bytes.length).encode(this.bytes);
47995
- const VM_TX_MEMORY = calculateVmTxMemory({
47996
- maxInputs: this.provider.getChain().consensusParameters.txParameters.maxInputs.toNumber()
47997
- });
47998
- const OFFSET = VM_TX_MEMORY + SCRIPT_FIXED_SIZE + INPUT_COIN_FIXED_SIZE + WORD_SIZE + paddedCode.byteLength + policiesLength * WORD_SIZE;
47999
- return mainFn?.encodeArguments(this.predicateData, OFFSET) || new Uint8Array();
47268
+ return mainFn?.encodeArguments(this.predicateData) || new Uint8Array();
48000
47269
  }
48001
47270
  /**
48002
47271
  * Processes the predicate data and returns the altered bytecode and interface.
@@ -48045,8 +47314,7 @@ Supported fuel-core version: ${supportedVersion}.`
48045
47314
  );
48046
47315
  return resources.map((resource) => ({
48047
47316
  ...resource,
48048
- predicate: hexlify(this.bytes),
48049
- padPredicateData: (policiesLength) => hexlify(this.getPredicateData(policiesLength))
47317
+ predicate: hexlify(this.bytes)
48050
47318
  }));
48051
47319
  }
48052
47320
  /**