@fuel-ts/account 0.0.0-rc-2238-20240514192918 → 0.0.0-rc-2143-20240514195947

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.

@@ -29470,7 +29470,7 @@ spurious results.`);
29470
29470
  // ../versions/dist/index.mjs
29471
29471
  function getBuiltinVersions() {
29472
29472
  return {
29473
- FORC: "0.58.0",
29473
+ FORC: "0.56.1",
29474
29474
  FUEL_CORE: "0.26.0",
29475
29475
  FUELS: "0.85.0"
29476
29476
  };
@@ -31092,6 +31092,19 @@ This unreleased fuel-core build may include features and updates not yet support
31092
31092
  __defNormalProp4(obj, typeof key !== "symbol" ? key + "" : key, value);
31093
31093
  return value;
31094
31094
  };
31095
+ var __accessCheck2 = (obj, member, msg) => {
31096
+ if (!member.has(obj))
31097
+ throw TypeError("Cannot " + msg);
31098
+ };
31099
+ var __privateAdd2 = (obj, member, value) => {
31100
+ if (member.has(obj))
31101
+ throw TypeError("Cannot add the same private member more than once");
31102
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
31103
+ };
31104
+ var __privateMethod2 = (obj, member, method) => {
31105
+ __accessCheck2(obj, member, "access private method");
31106
+ return method;
31107
+ };
31095
31108
  var Coder = class {
31096
31109
  name;
31097
31110
  type;
@@ -31123,6 +31136,7 @@ This unreleased fuel-core build may include features and updates not yet support
31123
31136
  var enumRegEx = /^enum (?<name>\w+)$/;
31124
31137
  var tupleRegEx = /^\((?<items>.*)\)$/;
31125
31138
  var genericRegEx = /^generic (?<name>\w+)$/;
31139
+ var ENCODING_V0 = "0";
31126
31140
  var ENCODING_V1 = "1";
31127
31141
  var WORD_SIZE = 8;
31128
31142
  var BYTES_32 = 32;
@@ -31133,6 +31147,10 @@ This unreleased fuel-core build may include features and updates not yet support
31133
31147
  var TX_LEN = WORD_SIZE * 4;
31134
31148
  var TX_POINTER_LEN = WORD_SIZE * 2;
31135
31149
  var MAX_BYTES = 2 ** 32 - 1;
31150
+ var calculateVmTxMemory = ({ maxInputs }) => BYTES_32 + // Tx ID
31151
+ ASSET_ID_LEN + // Base asset ID
31152
+ // Asset ID/Balance coin input pairs
31153
+ maxInputs * (ASSET_ID_LEN + WORD_SIZE) + WORD_SIZE;
31136
31154
  var SCRIPT_FIXED_SIZE = WORD_SIZE + // Identifier
31137
31155
  WORD_SIZE + // Gas limit
31138
31156
  WORD_SIZE + // Script size
@@ -31163,6 +31181,125 @@ This unreleased fuel-core build may include features and updates not yet support
31163
31181
  WORD_SIZE + // Predicate size
31164
31182
  WORD_SIZE + // Predicate data size
31165
31183
  WORD_SIZE;
31184
+ var encodedLengths = {
31185
+ u64: WORD_SIZE,
31186
+ u256: WORD_SIZE * 4
31187
+ };
31188
+ var BigNumberCoder = class extends Coder {
31189
+ constructor(baseType) {
31190
+ super("bigNumber", baseType, encodedLengths[baseType]);
31191
+ }
31192
+ encode(value) {
31193
+ let bytes2;
31194
+ try {
31195
+ bytes2 = toBytes2(value, this.encodedLength);
31196
+ } catch (error) {
31197
+ throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.type}.`);
31198
+ }
31199
+ return bytes2;
31200
+ }
31201
+ decode(data, offset) {
31202
+ if (data.length < this.encodedLength) {
31203
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid ${this.type} data size.`);
31204
+ }
31205
+ let bytes2 = data.slice(offset, offset + this.encodedLength);
31206
+ bytes2 = bytes2.slice(0, this.encodedLength);
31207
+ if (bytes2.length !== this.encodedLength) {
31208
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid ${this.type} byte data size.`);
31209
+ }
31210
+ return [bn(bytes2), offset + this.encodedLength];
31211
+ }
31212
+ };
31213
+ var VEC_PROPERTY_SPACE = 3;
31214
+ var BASE_VECTOR_OFFSET = VEC_PROPERTY_SPACE * WORD_SIZE;
31215
+ var RAW_SLICE_PROPERTY_SPACE = 2;
31216
+ var BASE_RAW_SLICE_OFFSET = RAW_SLICE_PROPERTY_SPACE * WORD_SIZE;
31217
+ function concatWithDynamicData(items) {
31218
+ const topLevelData = {};
31219
+ let totalIndex = 0;
31220
+ const objects = items.map((item) => {
31221
+ const dynamicData = item.dynamicData;
31222
+ if (dynamicData) {
31223
+ Object.entries(dynamicData).forEach(([pointerIndex, vData]) => {
31224
+ topLevelData[parseInt(pointerIndex, 10) + totalIndex] = vData;
31225
+ });
31226
+ }
31227
+ const byteArray = arrayify(item);
31228
+ totalIndex += byteArray.byteLength / WORD_SIZE;
31229
+ return byteArray;
31230
+ });
31231
+ const length = objects.reduce((accum, item) => accum + item.length, 0);
31232
+ const result = new Uint8Array(length);
31233
+ objects.reduce((offset, object) => {
31234
+ result.set(object, offset);
31235
+ return offset + object.length;
31236
+ }, 0);
31237
+ if (Object.keys(topLevelData).length) {
31238
+ result.dynamicData = topLevelData;
31239
+ }
31240
+ return result;
31241
+ }
31242
+ function unpackDynamicData(results, baseOffset, dataOffset) {
31243
+ if (!results.dynamicData) {
31244
+ return concat([results]);
31245
+ }
31246
+ let cumulativeDynamicByteLength = 0;
31247
+ let updatedResults = results;
31248
+ Object.entries(results.dynamicData).forEach(([pointerIndex, vData]) => {
31249
+ const pointerOffset = parseInt(pointerIndex, 10) * WORD_SIZE;
31250
+ const adjustedValue = new BigNumberCoder("u64").encode(
31251
+ dataOffset + baseOffset + cumulativeDynamicByteLength
31252
+ );
31253
+ updatedResults.set(adjustedValue, pointerOffset);
31254
+ const dataToAppend = vData.dynamicData ? (
31255
+ // unpack child dynamic data
31256
+ unpackDynamicData(
31257
+ vData,
31258
+ baseOffset,
31259
+ dataOffset + vData.byteLength + cumulativeDynamicByteLength
31260
+ )
31261
+ ) : vData;
31262
+ updatedResults = concat([updatedResults, dataToAppend]);
31263
+ cumulativeDynamicByteLength += dataToAppend.byteLength;
31264
+ });
31265
+ return updatedResults;
31266
+ }
31267
+ var chunkByLength = (data, length = WORD_SIZE) => {
31268
+ const chunks = [];
31269
+ let offset = 0;
31270
+ let chunk = data.slice(offset, offset + length);
31271
+ while (chunk.length) {
31272
+ chunks.push(chunk);
31273
+ offset += length;
31274
+ chunk = data.slice(offset, offset + length);
31275
+ }
31276
+ return chunks;
31277
+ };
31278
+ var isPointerType = (type3) => {
31279
+ switch (type3) {
31280
+ case "u8":
31281
+ case "u16":
31282
+ case "u32":
31283
+ case "u64":
31284
+ case "bool": {
31285
+ return false;
31286
+ }
31287
+ default: {
31288
+ return true;
31289
+ }
31290
+ }
31291
+ };
31292
+ var isHeapType = (type3) => type3 === VEC_CODER_TYPE || type3 === BYTES_CODER_TYPE || type3 === STD_STRING_CODER_TYPE;
31293
+ var isMultipleOfWordSize = (length) => length % WORD_SIZE === 0;
31294
+ var getWordSizePadding = (length) => WORD_SIZE - length % WORD_SIZE;
31295
+ var rightPadToWordSize = (encoded) => {
31296
+ if (isMultipleOfWordSize(encoded.length)) {
31297
+ return encoded;
31298
+ }
31299
+ const padding = new Uint8Array(WORD_SIZE - encoded.length % WORD_SIZE);
31300
+ return concatBytes2([encoded, padding]);
31301
+ };
31302
+ var isUint8Array = (value) => value instanceof Uint8Array;
31166
31303
  var ArrayCoder = class extends Coder {
31167
31304
  coder;
31168
31305
  length;
@@ -31178,7 +31315,7 @@ This unreleased fuel-core build may include features and updates not yet support
31178
31315
  if (this.length !== value.length) {
31179
31316
  throw new FuelError(ErrorCode.ENCODE_ERROR, `Types/values length mismatch.`);
31180
31317
  }
31181
- return concat(Array.from(value).map((v) => this.coder.encode(v)));
31318
+ return concatWithDynamicData(Array.from(value).map((v) => this.coder.encode(v)));
31182
31319
  }
31183
31320
  decode(data, offset) {
31184
31321
  if (data.length < this.encodedLength || data.length > MAX_BYTES) {
@@ -31255,42 +31392,16 @@ This unreleased fuel-core build may include features and updates not yet support
31255
31392
  return [toHex(bytes2, this.encodedLength), offset + this.encodedLength];
31256
31393
  }
31257
31394
  };
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
- };
31287
31395
  var BooleanCoder = class extends Coder {
31396
+ paddingLength;
31288
31397
  options;
31289
31398
  constructor(options = {
31290
- padToWordSize: false
31399
+ isSmallBytes: false,
31400
+ isRightPadded: false
31291
31401
  }) {
31292
- const encodedLength = options.padToWordSize ? WORD_SIZE : 1;
31293
- super("boolean", "boolean", encodedLength);
31402
+ const paddingLength = options.isSmallBytes ? 1 : 8;
31403
+ super("boolean", "boolean", paddingLength);
31404
+ this.paddingLength = paddingLength;
31294
31405
  this.options = options;
31295
31406
  }
31296
31407
  encode(value) {
@@ -31298,45 +31409,73 @@ This unreleased fuel-core build may include features and updates not yet support
31298
31409
  if (!isTrueBool) {
31299
31410
  throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid boolean value.`);
31300
31411
  }
31301
- return toBytes2(value ? 1 : 0, this.encodedLength);
31412
+ const output2 = toBytes2(value ? 1 : 0, this.paddingLength);
31413
+ if (this.options.isRightPadded) {
31414
+ return output2.reverse();
31415
+ }
31416
+ return output2;
31302
31417
  }
31303
31418
  decode(data, offset) {
31304
- if (data.length < this.encodedLength) {
31419
+ if (data.length < this.paddingLength) {
31305
31420
  throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid boolean data size.`);
31306
31421
  }
31307
- const bytes2 = bn(data.slice(offset, offset + this.encodedLength));
31308
- if (bytes2.isZero()) {
31309
- return [false, offset + this.encodedLength];
31422
+ let bytes2;
31423
+ if (this.options.isRightPadded) {
31424
+ bytes2 = data.slice(offset, offset + 1);
31425
+ } else {
31426
+ bytes2 = data.slice(offset, offset + this.paddingLength);
31310
31427
  }
31311
- if (!bytes2.eq(bn(1))) {
31428
+ const decodedValue = bn(bytes2);
31429
+ if (decodedValue.isZero()) {
31430
+ return [false, offset + this.paddingLength];
31431
+ }
31432
+ if (!decodedValue.eq(bn(1))) {
31312
31433
  throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid boolean value.`);
31313
31434
  }
31314
- return [true, offset + this.encodedLength];
31435
+ return [true, offset + this.paddingLength];
31315
31436
  }
31316
31437
  };
31438
+ var _getPaddedData;
31439
+ var getPaddedData_fn;
31317
31440
  var ByteCoder = class extends Coder {
31318
31441
  constructor() {
31319
- super("struct", "struct Bytes", WORD_SIZE);
31442
+ super("struct", "struct Bytes", BASE_VECTOR_OFFSET);
31443
+ __privateAdd2(this, _getPaddedData);
31320
31444
  }
31321
31445
  encode(value) {
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]);
31446
+ const parts = [];
31447
+ const pointer = new BigNumberCoder("u64").encode(BASE_VECTOR_OFFSET);
31448
+ const data = __privateMethod2(this, _getPaddedData, getPaddedData_fn).call(this, value);
31449
+ pointer.dynamicData = {
31450
+ 0: concatWithDynamicData([data])
31451
+ };
31452
+ parts.push(pointer);
31453
+ parts.push(new BigNumberCoder("u64").encode(data.byteLength));
31454
+ parts.push(new BigNumberCoder("u64").encode(value.length));
31455
+ return concatWithDynamicData(parts);
31325
31456
  }
31326
31457
  decode(data, offset) {
31327
- if (data.length < WORD_SIZE) {
31458
+ if (data.length < BASE_VECTOR_OFFSET) {
31328
31459
  throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid byte data size.`);
31329
31460
  }
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) {
31461
+ const len = data.slice(16, 24);
31462
+ const encodedLength = bn(new BigNumberCoder("u64").decode(len, 0)[0]).toNumber();
31463
+ const byteData = data.slice(BASE_VECTOR_OFFSET, BASE_VECTOR_OFFSET + encodedLength);
31464
+ if (byteData.length !== encodedLength) {
31335
31465
  throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid bytes byte data size.`);
31336
31466
  }
31337
- return [dataBytes, offsetAndLength + length];
31467
+ return [byteData, offset + BASE_VECTOR_OFFSET];
31338
31468
  }
31339
31469
  };
31470
+ _getPaddedData = /* @__PURE__ */ new WeakSet();
31471
+ getPaddedData_fn = function(value) {
31472
+ const data = value instanceof Uint8Array ? [value] : [new Uint8Array(value)];
31473
+ const paddingLength = (WORD_SIZE - value.length % WORD_SIZE) % WORD_SIZE;
31474
+ if (paddingLength) {
31475
+ data.push(new Uint8Array(paddingLength));
31476
+ }
31477
+ return concat(data);
31478
+ };
31340
31479
  __publicField4(ByteCoder, "memorySize", 1);
31341
31480
  var isFullyNativeEnum = (enumCoders) => Object.values(enumCoders).every(
31342
31481
  // @ts-expect-error complicated types
@@ -31380,7 +31519,8 @@ This unreleased fuel-core build may include features and updates not yet support
31380
31519
  const valueCoder = this.coders[caseKey];
31381
31520
  const caseIndex = Object.keys(this.coders).indexOf(caseKey);
31382
31521
  const encodedValue = valueCoder.encode(value[caseKey]);
31383
- return new Uint8Array([...this.#caseIndexCoder.encode(caseIndex), ...encodedValue]);
31522
+ const padding = new Uint8Array(this.#encodedValueSize - valueCoder.encodedLength);
31523
+ return concatWithDynamicData([this.#caseIndexCoder.encode(caseIndex), padding, encodedValue]);
31384
31524
  }
31385
31525
  #decodeNativeEnum(caseKey, newOffset) {
31386
31526
  return [caseKey, newOffset];
@@ -31389,8 +31529,10 @@ This unreleased fuel-core build may include features and updates not yet support
31389
31529
  if (data.length < this.#encodedValueSize) {
31390
31530
  throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid enum data size.`);
31391
31531
  }
31392
- const caseBytes = new BigNumberCoder("u64").decode(data, offset)[0];
31393
- const caseIndex = toNumber(caseBytes);
31532
+ let newOffset = offset;
31533
+ let decoded;
31534
+ [decoded, newOffset] = new BigNumberCoder("u64").decode(data, newOffset);
31535
+ const caseIndex = toNumber(decoded);
31394
31536
  const caseKey = Object.keys(this.coders)[caseIndex];
31395
31537
  if (!caseKey) {
31396
31538
  throw new FuelError(
@@ -31399,35 +31541,67 @@ This unreleased fuel-core build may include features and updates not yet support
31399
31541
  );
31400
31542
  }
31401
31543
  const valueCoder = this.coders[caseKey];
31402
- const offsetAndCase = offset + WORD_SIZE;
31403
- const [decoded, newOffset] = valueCoder.decode(data, offsetAndCase);
31544
+ const padding = this.#encodedValueSize - valueCoder.encodedLength;
31545
+ newOffset += padding;
31546
+ [decoded, newOffset] = valueCoder.decode(data, newOffset);
31404
31547
  if (isFullyNativeEnum(this.coders)) {
31405
31548
  return this.#decodeNativeEnum(caseKey, newOffset);
31406
31549
  }
31407
31550
  return [{ [caseKey]: decoded }, newOffset];
31408
31551
  }
31409
31552
  };
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}`);
31553
+ var OptionCoder = class extends EnumCoder {
31554
+ encode(value) {
31555
+ const result = super.encode(this.toSwayOption(value));
31556
+ return result;
31557
+ }
31558
+ toSwayOption(input) {
31559
+ if (input !== void 0) {
31560
+ return { Some: input };
31561
+ }
31562
+ return { None: [] };
31563
+ }
31564
+ decode(data, offset) {
31565
+ if (data.length < this.encodedLength) {
31566
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid option data size.`);
31567
+ }
31568
+ const [decoded, newOffset] = super.decode(data, offset);
31569
+ return [this.toOption(decoded), newOffset];
31570
+ }
31571
+ toOption(output2) {
31572
+ if (output2 && "Some" in output2) {
31573
+ return output2.Some;
31574
+ }
31575
+ return void 0;
31420
31576
  }
31421
31577
  };
31422
31578
  var NumberCoder = class extends Coder {
31579
+ // This is to align the bits to the total bytes
31580
+ // See https://github.com/FuelLabs/fuel-specs/blob/master/specs/protocol/abi.md#unsigned-integers
31581
+ length;
31582
+ paddingLength;
31423
31583
  baseType;
31424
31584
  options;
31425
31585
  constructor(baseType, options = {
31426
- padToWordSize: false
31586
+ isSmallBytes: false,
31587
+ isRightPadded: false
31427
31588
  }) {
31428
- const length = options.padToWordSize ? WORD_SIZE : getLength(baseType);
31429
- super("number", baseType, length);
31589
+ const paddingLength = options.isSmallBytes && baseType === "u8" ? 1 : 8;
31590
+ super("number", baseType, paddingLength);
31430
31591
  this.baseType = baseType;
31592
+ switch (baseType) {
31593
+ case "u8":
31594
+ this.length = 1;
31595
+ break;
31596
+ case "u16":
31597
+ this.length = 2;
31598
+ break;
31599
+ case "u32":
31600
+ default:
31601
+ this.length = 4;
31602
+ break;
31603
+ }
31604
+ this.paddingLength = paddingLength;
31431
31605
  this.options = options;
31432
31606
  }
31433
31607
  encode(value) {
@@ -31437,97 +31611,778 @@ This unreleased fuel-core build may include features and updates not yet support
31437
31611
  } catch (error) {
31438
31612
  throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.baseType}.`);
31439
31613
  }
31440
- if (bytes2.length > this.encodedLength) {
31614
+ if (bytes2.length > this.length) {
31441
31615
  throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.baseType}, too many bytes.`);
31442
31616
  }
31443
- return toBytes2(bytes2, this.encodedLength);
31444
- }
31445
- decode(data, offset) {
31446
- if (data.length < this.encodedLength) {
31447
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid number data size.`);
31448
- }
31449
- const bytes2 = data.slice(offset, offset + this.encodedLength);
31450
- if (bytes2.length !== this.encodedLength) {
31451
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid number byte data size.`);
31617
+ const output2 = toBytes2(bytes2, this.paddingLength);
31618
+ if (this.baseType !== "u8") {
31619
+ return output2;
31452
31620
  }
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;
31621
+ return this.options.isRightPadded ? output2.reverse() : output2;
31460
31622
  }
31461
- toSwayOption(input) {
31462
- if (input !== void 0) {
31463
- return { Some: input };
31623
+ decodeU8(data, offset) {
31624
+ let bytes2;
31625
+ if (this.options.isRightPadded) {
31626
+ bytes2 = data.slice(offset, offset + 1);
31627
+ } else {
31628
+ bytes2 = data.slice(offset, offset + this.paddingLength);
31629
+ bytes2 = bytes2.slice(this.paddingLength - this.length, this.paddingLength);
31464
31630
  }
31465
- return { None: [] };
31631
+ return [toNumber(bytes2), offset + this.paddingLength];
31466
31632
  }
31467
31633
  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;
31634
+ if (data.length < this.paddingLength) {
31635
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid number data size.`);
31474
31636
  }
31475
- return void 0;
31637
+ if (this.baseType === "u8") {
31638
+ return this.decodeU8(data, offset);
31639
+ }
31640
+ let bytes2 = data.slice(offset, offset + this.paddingLength);
31641
+ bytes2 = bytes2.slice(8 - this.length, 8);
31642
+ if (bytes2.length !== this.paddingLength - (this.paddingLength - this.length)) {
31643
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid number byte data size.`);
31644
+ }
31645
+ return [toNumber(bytes2), offset + 8];
31476
31646
  }
31477
31647
  };
31478
31648
  var RawSliceCoder = class extends Coder {
31479
31649
  constructor() {
31480
- super("raw untyped slice", "raw untyped slice", WORD_SIZE);
31650
+ super("raw untyped slice", "raw untyped slice", BASE_RAW_SLICE_OFFSET);
31481
31651
  }
31482
31652
  encode(value) {
31483
31653
  if (!Array.isArray(value)) {
31484
31654
  throw new FuelError(ErrorCode.ENCODE_ERROR, `Expected array value.`);
31485
31655
  }
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]);
31656
+ const parts = [];
31657
+ const coder = new NumberCoder("u8", { isSmallBytes: true });
31658
+ const pointer = new BigNumberCoder("u64").encode(
31659
+ BASE_RAW_SLICE_OFFSET
31660
+ );
31661
+ pointer.dynamicData = {
31662
+ 0: concatWithDynamicData(value.map((v) => coder.encode(v)))
31663
+ };
31664
+ parts.push(pointer);
31665
+ parts.push(new BigNumberCoder("u64").encode(value.length));
31666
+ return concatWithDynamicData(parts);
31490
31667
  }
31491
31668
  decode(data, offset) {
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);
31669
+ const dataBytes = data.slice(offset);
31670
+ const internalCoder = new ArrayCoder(
31671
+ new NumberCoder("u8", { isSmallBytes: true }),
31672
+ dataBytes.length
31673
+ );
31503
31674
  const [decodedValue] = internalCoder.decode(dataBytes, 0);
31504
- return [decodedValue, offsetAndLength + length];
31675
+ return [decodedValue, offset + dataBytes.length];
31505
31676
  }
31506
31677
  };
31678
+ var _getPaddedData2;
31679
+ var getPaddedData_fn2;
31507
31680
  var StdStringCoder = class extends Coder {
31508
31681
  constructor() {
31509
- super("struct", "struct String", WORD_SIZE);
31682
+ super("struct", "struct String", 1);
31683
+ __privateAdd2(this, _getPaddedData2);
31510
31684
  }
31511
31685
  encode(value) {
31512
- const bytes2 = toUtf8Bytes(value);
31513
- const lengthBytes = new BigNumberCoder("u64").encode(value.length);
31514
- return new Uint8Array([...lengthBytes, ...bytes2]);
31686
+ const parts = [];
31687
+ const pointer = new BigNumberCoder("u64").encode(BASE_VECTOR_OFFSET);
31688
+ const data = __privateMethod2(this, _getPaddedData2, getPaddedData_fn2).call(this, value);
31689
+ pointer.dynamicData = {
31690
+ 0: concatWithDynamicData([data])
31691
+ };
31692
+ parts.push(pointer);
31693
+ parts.push(new BigNumberCoder("u64").encode(data.byteLength));
31694
+ parts.push(new BigNumberCoder("u64").encode(value.length));
31695
+ return concatWithDynamicData(parts);
31515
31696
  }
31516
31697
  decode(data, offset) {
31517
31698
  if (data.length < this.encodedLength) {
31518
31699
  throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid std string data size.`);
31519
31700
  }
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) {
31701
+ const len = data.slice(16, 24);
31702
+ const encodedLength = bn(new BigNumberCoder("u64").decode(len, 0)[0]).toNumber();
31703
+ const byteData = data.slice(BASE_VECTOR_OFFSET, BASE_VECTOR_OFFSET + encodedLength);
31704
+ if (byteData.length !== encodedLength) {
31525
31705
  throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid std string byte data size.`);
31526
31706
  }
31527
- return [toUtf8String(dataBytes), offsetAndLength + length];
31707
+ const value = toUtf8String(byteData);
31708
+ return [value, offset + BASE_VECTOR_OFFSET];
31528
31709
  }
31529
31710
  };
31711
+ _getPaddedData2 = /* @__PURE__ */ new WeakSet();
31712
+ getPaddedData_fn2 = function(value) {
31713
+ const data = [toUtf8Bytes(value)];
31714
+ const paddingLength = (WORD_SIZE - value.length % WORD_SIZE) % WORD_SIZE;
31715
+ if (paddingLength) {
31716
+ data.push(new Uint8Array(paddingLength));
31717
+ }
31718
+ return concat(data);
31719
+ };
31530
31720
  __publicField4(StdStringCoder, "memorySize", 1);
31721
+ var StringCoder = class extends Coder {
31722
+ length;
31723
+ #paddingLength;
31724
+ constructor(length) {
31725
+ let paddingLength = (8 - length) % 8;
31726
+ paddingLength = paddingLength < 0 ? paddingLength + 8 : paddingLength;
31727
+ super("string", `str[${length}]`, length + paddingLength);
31728
+ this.length = length;
31729
+ this.#paddingLength = paddingLength;
31730
+ }
31731
+ encode(value) {
31732
+ if (this.length !== value.length) {
31733
+ throw new FuelError(ErrorCode.ENCODE_ERROR, `Value length mismatch during encode.`);
31734
+ }
31735
+ const encoded = toUtf8Bytes(value);
31736
+ const padding = new Uint8Array(this.#paddingLength);
31737
+ return concat([encoded, padding]);
31738
+ }
31739
+ decode(data, offset) {
31740
+ if (data.length < this.encodedLength) {
31741
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid string data size.`);
31742
+ }
31743
+ const bytes2 = data.slice(offset, offset + this.length);
31744
+ if (bytes2.length !== this.length) {
31745
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid string byte data size.`);
31746
+ }
31747
+ const value = toUtf8String(bytes2);
31748
+ const padding = this.#paddingLength;
31749
+ return [value, offset + this.length + padding];
31750
+ }
31751
+ };
31752
+ var StructCoder = class extends Coder {
31753
+ name;
31754
+ coders;
31755
+ constructor(name, coders) {
31756
+ const encodedLength = Object.values(coders).reduce(
31757
+ (acc, coder) => acc + coder.encodedLength,
31758
+ 0
31759
+ );
31760
+ super("struct", `struct ${name}`, encodedLength);
31761
+ this.name = name;
31762
+ this.coders = coders;
31763
+ }
31764
+ encode(value) {
31765
+ const encodedFields = Object.keys(this.coders).map((fieldName) => {
31766
+ const fieldCoder = this.coders[fieldName];
31767
+ const fieldValue = value[fieldName];
31768
+ if (!(fieldCoder instanceof OptionCoder) && fieldValue == null) {
31769
+ throw new FuelError(
31770
+ ErrorCode.ENCODE_ERROR,
31771
+ `Invalid ${this.type}. Field "${fieldName}" not present.`
31772
+ );
31773
+ }
31774
+ const encoded = fieldCoder.encode(fieldValue);
31775
+ if (!isMultipleOfWordSize(encoded.length)) {
31776
+ return rightPadToWordSize(encoded);
31777
+ }
31778
+ return encoded;
31779
+ });
31780
+ return concatWithDynamicData([concatWithDynamicData(encodedFields)]);
31781
+ }
31782
+ decode(data, offset) {
31783
+ if (data.length < this.encodedLength) {
31784
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid struct data size.`);
31785
+ }
31786
+ let newOffset = offset;
31787
+ const decodedValue = Object.keys(this.coders).reduce((obj, fieldName) => {
31788
+ const fieldCoder = this.coders[fieldName];
31789
+ let decoded;
31790
+ [decoded, newOffset] = fieldCoder.decode(data, newOffset);
31791
+ if (!isMultipleOfWordSize(newOffset)) {
31792
+ newOffset += getWordSizePadding(newOffset);
31793
+ }
31794
+ obj[fieldName] = decoded;
31795
+ return obj;
31796
+ }, {});
31797
+ return [decodedValue, newOffset];
31798
+ }
31799
+ };
31800
+ var TupleCoder = class extends Coder {
31801
+ coders;
31802
+ constructor(coders) {
31803
+ const encodedLength = coders.reduce((acc, coder) => acc + coder.encodedLength, 0);
31804
+ super("tuple", `(${coders.map((coder) => coder.type).join(", ")})`, encodedLength);
31805
+ this.coders = coders;
31806
+ }
31807
+ encode(value) {
31808
+ if (this.coders.length !== value.length) {
31809
+ throw new FuelError(ErrorCode.ENCODE_ERROR, `Types/values length mismatch.`);
31810
+ }
31811
+ return concatWithDynamicData(
31812
+ this.coders.map((coder, i) => {
31813
+ const encoded = coder.encode(value[i]);
31814
+ if (!isMultipleOfWordSize(encoded.length)) {
31815
+ return rightPadToWordSize(encoded);
31816
+ }
31817
+ return encoded;
31818
+ })
31819
+ );
31820
+ }
31821
+ decode(data, offset) {
31822
+ if (data.length < this.encodedLength) {
31823
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid tuple data size.`);
31824
+ }
31825
+ let newOffset = offset;
31826
+ const decodedValue = this.coders.map((coder) => {
31827
+ let decoded;
31828
+ [decoded, newOffset] = coder.decode(data, newOffset);
31829
+ if (!isMultipleOfWordSize(newOffset)) {
31830
+ newOffset += getWordSizePadding(newOffset);
31831
+ }
31832
+ return decoded;
31833
+ });
31834
+ return [decodedValue, newOffset];
31835
+ }
31836
+ };
31837
+ var VecCoder = class extends Coder {
31838
+ coder;
31839
+ constructor(coder) {
31840
+ super("struct", `struct Vec`, coder.encodedLength + BASE_VECTOR_OFFSET);
31841
+ this.coder = coder;
31842
+ }
31843
+ encode(value) {
31844
+ if (!Array.isArray(value) && !isUint8Array(value)) {
31845
+ throw new FuelError(
31846
+ ErrorCode.ENCODE_ERROR,
31847
+ `Expected array value, or a Uint8Array. You can use arrayify to convert a value to a Uint8Array.`
31848
+ );
31849
+ }
31850
+ const parts = [];
31851
+ const pointer = new BigNumberCoder("u64").encode(BASE_VECTOR_OFFSET);
31852
+ pointer.dynamicData = {
31853
+ 0: concatWithDynamicData(Array.from(value).map((v) => this.coder.encode(v)))
31854
+ };
31855
+ parts.push(pointer);
31856
+ parts.push(new BigNumberCoder("u64").encode(value.length));
31857
+ parts.push(new BigNumberCoder("u64").encode(value.length));
31858
+ return concatWithDynamicData(parts);
31859
+ }
31860
+ decode(data, offset) {
31861
+ if (data.length < BASE_VECTOR_OFFSET || data.length > MAX_BYTES) {
31862
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid vec data size.`);
31863
+ }
31864
+ const len = data.slice(16, 24);
31865
+ const encodedLength = bn(new BigNumberCoder("u64").decode(len, 0)[0]).toNumber();
31866
+ const vectorRawDataLength = encodedLength * this.coder.encodedLength;
31867
+ const vectorRawData = data.slice(BASE_VECTOR_OFFSET, BASE_VECTOR_OFFSET + vectorRawDataLength);
31868
+ if (vectorRawData.length !== vectorRawDataLength) {
31869
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid vec byte data size.`);
31870
+ }
31871
+ return [
31872
+ chunkByLength(vectorRawData, this.coder.encodedLength).map(
31873
+ (chunk) => this.coder.decode(chunk, 0)[0]
31874
+ ),
31875
+ offset + BASE_VECTOR_OFFSET
31876
+ ];
31877
+ }
31878
+ };
31879
+ var getEncodingVersion = (encoding) => {
31880
+ switch (encoding) {
31881
+ case void 0:
31882
+ case ENCODING_V0:
31883
+ return ENCODING_V0;
31884
+ case ENCODING_V1:
31885
+ return ENCODING_V1;
31886
+ default:
31887
+ throw new FuelError(
31888
+ ErrorCode.UNSUPPORTED_ENCODING_VERSION,
31889
+ `Encoding version '${encoding}' is unsupported.`
31890
+ );
31891
+ }
31892
+ };
31893
+ var findFunctionByName = (abi, name) => {
31894
+ const fn = abi.functions.find((f2) => f2.name === name);
31895
+ if (!fn) {
31896
+ throw new FuelError(
31897
+ ErrorCode.FUNCTION_NOT_FOUND,
31898
+ `Function with name '${name}' doesn't exist in the ABI`
31899
+ );
31900
+ }
31901
+ return fn;
31902
+ };
31903
+ var findTypeById = (abi, typeId) => {
31904
+ const type3 = abi.types.find((t) => t.typeId === typeId);
31905
+ if (!type3) {
31906
+ throw new FuelError(
31907
+ ErrorCode.TYPE_NOT_FOUND,
31908
+ `Type with typeId '${typeId}' doesn't exist in the ABI.`
31909
+ );
31910
+ }
31911
+ return type3;
31912
+ };
31913
+ var findNonEmptyInputs = (abi, inputs) => inputs.filter((input) => findTypeById(abi, input.type).type !== "()");
31914
+ var findVectorBufferArgument = (components) => {
31915
+ const bufferComponent = components.find((c) => c.name === "buf");
31916
+ const bufferTypeArgument = bufferComponent?.originalTypeArguments?.[0];
31917
+ if (!bufferComponent || !bufferTypeArgument) {
31918
+ throw new FuelError(
31919
+ ErrorCode.INVALID_COMPONENT,
31920
+ `The Vec type provided is missing or has a malformed 'buf' component.`
31921
+ );
31922
+ }
31923
+ return bufferTypeArgument;
31924
+ };
31925
+ var ResolvedAbiType = class {
31926
+ abi;
31927
+ name;
31928
+ type;
31929
+ originalTypeArguments;
31930
+ components;
31931
+ constructor(abi, argument) {
31932
+ this.abi = abi;
31933
+ this.name = argument.name;
31934
+ const type3 = findTypeById(abi, argument.type);
31935
+ this.type = type3.type;
31936
+ this.originalTypeArguments = argument.typeArguments;
31937
+ this.components = ResolvedAbiType.getResolvedGenericComponents(
31938
+ abi,
31939
+ argument,
31940
+ type3.components,
31941
+ type3.typeParameters ?? ResolvedAbiType.getImplicitGenericTypeParameters(abi, type3.components)
31942
+ );
31943
+ }
31944
+ static getResolvedGenericComponents(abi, arg, components, typeParameters) {
31945
+ if (components === null) {
31946
+ return null;
31947
+ }
31948
+ if (typeParameters === null || typeParameters.length === 0) {
31949
+ return components.map((c) => new ResolvedAbiType(abi, c));
31950
+ }
31951
+ const typeParametersAndArgsMap = typeParameters.reduce(
31952
+ (obj, typeParameter, typeParameterIndex) => {
31953
+ const o = { ...obj };
31954
+ o[typeParameter] = structuredClone(
31955
+ arg.typeArguments?.[typeParameterIndex]
31956
+ );
31957
+ return o;
31958
+ },
31959
+ {}
31960
+ );
31961
+ const resolvedComponents = this.resolveGenericArgTypes(
31962
+ abi,
31963
+ components,
31964
+ typeParametersAndArgsMap
31965
+ );
31966
+ return resolvedComponents.map((c) => new ResolvedAbiType(abi, c));
31967
+ }
31968
+ static resolveGenericArgTypes(abi, args, typeParametersAndArgsMap) {
31969
+ return args.map((arg) => {
31970
+ if (typeParametersAndArgsMap[arg.type] !== void 0) {
31971
+ return {
31972
+ ...typeParametersAndArgsMap[arg.type],
31973
+ name: arg.name
31974
+ };
31975
+ }
31976
+ if (arg.typeArguments) {
31977
+ return {
31978
+ ...structuredClone(arg),
31979
+ typeArguments: this.resolveGenericArgTypes(
31980
+ abi,
31981
+ arg.typeArguments,
31982
+ typeParametersAndArgsMap
31983
+ )
31984
+ };
31985
+ }
31986
+ const argType = findTypeById(abi, arg.type);
31987
+ const implicitTypeParameters = this.getImplicitGenericTypeParameters(abi, argType.components);
31988
+ if (implicitTypeParameters && implicitTypeParameters.length > 0) {
31989
+ return {
31990
+ ...structuredClone(arg),
31991
+ typeArguments: implicitTypeParameters.map((itp) => typeParametersAndArgsMap[itp])
31992
+ };
31993
+ }
31994
+ return arg;
31995
+ });
31996
+ }
31997
+ static getImplicitGenericTypeParameters(abi, args, implicitGenericParametersParam) {
31998
+ if (!Array.isArray(args)) {
31999
+ return null;
32000
+ }
32001
+ const implicitGenericParameters = implicitGenericParametersParam ?? [];
32002
+ args.forEach((a) => {
32003
+ const argType = findTypeById(abi, a.type);
32004
+ if (genericRegEx.test(argType.type)) {
32005
+ implicitGenericParameters.push(argType.typeId);
32006
+ return;
32007
+ }
32008
+ if (!Array.isArray(a.typeArguments)) {
32009
+ return;
32010
+ }
32011
+ this.getImplicitGenericTypeParameters(abi, a.typeArguments, implicitGenericParameters);
32012
+ });
32013
+ return implicitGenericParameters.length > 0 ? implicitGenericParameters : null;
32014
+ }
32015
+ getSignature() {
32016
+ const prefix = this.getArgSignaturePrefix();
32017
+ const content = this.getArgSignatureContent();
32018
+ return `${prefix}${content}`;
32019
+ }
32020
+ getArgSignaturePrefix() {
32021
+ const structMatch = structRegEx.test(this.type);
32022
+ if (structMatch) {
32023
+ return "s";
32024
+ }
32025
+ const arrayMatch = arrayRegEx.test(this.type);
32026
+ if (arrayMatch) {
32027
+ return "a";
32028
+ }
32029
+ const enumMatch = enumRegEx.test(this.type);
32030
+ if (enumMatch) {
32031
+ return "e";
32032
+ }
32033
+ return "";
32034
+ }
32035
+ getArgSignatureContent() {
32036
+ if (this.type === "raw untyped ptr") {
32037
+ return "rawptr";
32038
+ }
32039
+ if (this.type === "raw untyped slice") {
32040
+ return "rawslice";
32041
+ }
32042
+ const strMatch = stringRegEx.exec(this.type)?.groups;
32043
+ if (strMatch) {
32044
+ return `str[${strMatch.length}]`;
32045
+ }
32046
+ if (this.components === null) {
32047
+ return this.type;
32048
+ }
32049
+ const arrayMatch = arrayRegEx.exec(this.type)?.groups;
32050
+ if (arrayMatch) {
32051
+ return `[${this.components[0].getSignature()};${arrayMatch.length}]`;
32052
+ }
32053
+ const typeArgumentsSignature = this.originalTypeArguments !== null ? `<${this.originalTypeArguments.map((a) => new ResolvedAbiType(this.abi, a).getSignature()).join(",")}>` : "";
32054
+ const componentsSignature = `(${this.components.map((c) => c.getSignature()).join(",")})`;
32055
+ return `${typeArgumentsSignature}${componentsSignature}`;
32056
+ }
32057
+ };
32058
+ function getCoders(components, options) {
32059
+ const { getCoder: getCoder3 } = options;
32060
+ return components.reduce((obj, component) => {
32061
+ const o = obj;
32062
+ o[component.name] = getCoder3(component, options);
32063
+ return o;
32064
+ }, {});
32065
+ }
32066
+ var getCoder = (resolvedAbiType, options) => {
32067
+ switch (resolvedAbiType.type) {
32068
+ case U8_CODER_TYPE:
32069
+ case U16_CODER_TYPE:
32070
+ case U32_CODER_TYPE:
32071
+ return new NumberCoder(resolvedAbiType.type, options);
32072
+ case U64_CODER_TYPE:
32073
+ case RAW_PTR_CODER_TYPE:
32074
+ return new BigNumberCoder("u64");
32075
+ case U256_CODER_TYPE:
32076
+ return new BigNumberCoder("u256");
32077
+ case RAW_SLICE_CODER_TYPE:
32078
+ return new RawSliceCoder();
32079
+ case BOOL_CODER_TYPE:
32080
+ return new BooleanCoder(options);
32081
+ case B256_CODER_TYPE:
32082
+ return new B256Coder();
32083
+ case B512_CODER_TYPE:
32084
+ return new B512Coder();
32085
+ case BYTES_CODER_TYPE:
32086
+ return new ByteCoder();
32087
+ case STD_STRING_CODER_TYPE:
32088
+ return new StdStringCoder();
32089
+ default:
32090
+ break;
32091
+ }
32092
+ const stringMatch = stringRegEx.exec(resolvedAbiType.type)?.groups;
32093
+ if (stringMatch) {
32094
+ const length = parseInt(stringMatch.length, 10);
32095
+ return new StringCoder(length);
32096
+ }
32097
+ const components = resolvedAbiType.components;
32098
+ const arrayMatch = arrayRegEx.exec(resolvedAbiType.type)?.groups;
32099
+ if (arrayMatch) {
32100
+ const length = parseInt(arrayMatch.length, 10);
32101
+ const arg = components[0];
32102
+ if (!arg) {
32103
+ throw new FuelError(
32104
+ ErrorCode.INVALID_COMPONENT,
32105
+ `The provided Array type is missing an item of 'component'.`
32106
+ );
32107
+ }
32108
+ const arrayElementCoder = getCoder(arg, { isSmallBytes: true });
32109
+ return new ArrayCoder(arrayElementCoder, length);
32110
+ }
32111
+ if (resolvedAbiType.type === VEC_CODER_TYPE) {
32112
+ const arg = findVectorBufferArgument(components);
32113
+ const argType = new ResolvedAbiType(resolvedAbiType.abi, arg);
32114
+ const itemCoder = getCoder(argType, { isSmallBytes: true, encoding: ENCODING_V0 });
32115
+ return new VecCoder(itemCoder);
32116
+ }
32117
+ const structMatch = structRegEx.exec(resolvedAbiType.type)?.groups;
32118
+ if (structMatch) {
32119
+ const coders = getCoders(components, { isRightPadded: true, getCoder });
32120
+ return new StructCoder(structMatch.name, coders);
32121
+ }
32122
+ const enumMatch = enumRegEx.exec(resolvedAbiType.type)?.groups;
32123
+ if (enumMatch) {
32124
+ const coders = getCoders(components, { getCoder });
32125
+ const isOptionEnum = resolvedAbiType.type === OPTION_CODER_TYPE;
32126
+ if (isOptionEnum) {
32127
+ return new OptionCoder(enumMatch.name, coders);
32128
+ }
32129
+ return new EnumCoder(enumMatch.name, coders);
32130
+ }
32131
+ const tupleMatch = tupleRegEx.exec(resolvedAbiType.type)?.groups;
32132
+ if (tupleMatch) {
32133
+ const coders = components.map(
32134
+ (component) => getCoder(component, { isRightPadded: true, encoding: ENCODING_V0 })
32135
+ );
32136
+ return new TupleCoder(coders);
32137
+ }
32138
+ if (resolvedAbiType.type === STR_SLICE_CODER_TYPE) {
32139
+ throw new FuelError(
32140
+ ErrorCode.INVALID_DATA,
32141
+ "String slices can not be decoded from logs. Convert the slice to `str[N]` with `__to_str_array`"
32142
+ );
32143
+ }
32144
+ throw new FuelError(
32145
+ ErrorCode.CODER_NOT_FOUND,
32146
+ `Coder not found: ${JSON.stringify(resolvedAbiType)}.`
32147
+ );
32148
+ };
32149
+ var BooleanCoder2 = class extends Coder {
32150
+ constructor() {
32151
+ super("boolean", "boolean", 1);
32152
+ }
32153
+ encode(value) {
32154
+ const isTrueBool = value === true || value === false;
32155
+ if (!isTrueBool) {
32156
+ throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid boolean value.`);
32157
+ }
32158
+ return toBytes2(value ? 1 : 0, this.encodedLength);
32159
+ }
32160
+ decode(data, offset) {
32161
+ if (data.length < this.encodedLength) {
32162
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid boolean data size.`);
32163
+ }
32164
+ const bytes2 = bn(data.slice(offset, offset + this.encodedLength));
32165
+ if (bytes2.isZero()) {
32166
+ return [false, offset + this.encodedLength];
32167
+ }
32168
+ if (!bytes2.eq(bn(1))) {
32169
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid boolean value.`);
32170
+ }
32171
+ return [true, offset + this.encodedLength];
32172
+ }
32173
+ };
32174
+ var ByteCoder2 = class extends Coder {
32175
+ constructor() {
32176
+ super("struct", "struct Bytes", WORD_SIZE);
32177
+ }
32178
+ encode(value) {
32179
+ const bytes2 = value instanceof Uint8Array ? value : new Uint8Array(value);
32180
+ const lengthBytes = new BigNumberCoder("u64").encode(bytes2.length);
32181
+ return new Uint8Array([...lengthBytes, ...bytes2]);
32182
+ }
32183
+ decode(data, offset) {
32184
+ if (data.length < WORD_SIZE) {
32185
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid byte data size.`);
32186
+ }
32187
+ const offsetAndLength = offset + WORD_SIZE;
32188
+ const lengthBytes = data.slice(offset, offsetAndLength);
32189
+ const length = bn(new BigNumberCoder("u64").decode(lengthBytes, 0)[0]).toNumber();
32190
+ const dataBytes = data.slice(offsetAndLength, offsetAndLength + length);
32191
+ if (dataBytes.length !== length) {
32192
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid bytes byte data size.`);
32193
+ }
32194
+ return [dataBytes, offsetAndLength + length];
32195
+ }
32196
+ };
32197
+ __publicField4(ByteCoder2, "memorySize", 1);
32198
+ var isFullyNativeEnum2 = (enumCoders) => Object.values(enumCoders).every(
32199
+ // @ts-expect-error complicated types
32200
+ ({ type: type3, coders }) => type3 === "()" && JSON.stringify(coders) === JSON.stringify([])
32201
+ );
32202
+ var EnumCoder2 = class extends Coder {
32203
+ name;
32204
+ coders;
32205
+ #caseIndexCoder;
32206
+ #encodedValueSize;
32207
+ constructor(name, coders) {
32208
+ const caseIndexCoder = new BigNumberCoder("u64");
32209
+ const encodedValueSize = Object.values(coders).reduce(
32210
+ (max, coder) => Math.max(max, coder.encodedLength),
32211
+ 0
32212
+ );
32213
+ super(`enum ${name}`, `enum ${name}`, caseIndexCoder.encodedLength + encodedValueSize);
32214
+ this.name = name;
32215
+ this.coders = coders;
32216
+ this.#caseIndexCoder = caseIndexCoder;
32217
+ this.#encodedValueSize = encodedValueSize;
32218
+ }
32219
+ #encodeNativeEnum(value) {
32220
+ const valueCoder = this.coders[value];
32221
+ const encodedValue = valueCoder.encode([]);
32222
+ const caseIndex = Object.keys(this.coders).indexOf(value);
32223
+ const padding = new Uint8Array(this.#encodedValueSize - valueCoder.encodedLength);
32224
+ return concat([this.#caseIndexCoder.encode(caseIndex), padding, encodedValue]);
32225
+ }
32226
+ encode(value) {
32227
+ if (typeof value === "string" && this.coders[value]) {
32228
+ return this.#encodeNativeEnum(value);
32229
+ }
32230
+ const [caseKey, ...empty] = Object.keys(value);
32231
+ if (!caseKey) {
32232
+ throw new FuelError(ErrorCode.INVALID_DECODE_VALUE, "A field for the case must be provided.");
32233
+ }
32234
+ if (empty.length !== 0) {
32235
+ throw new FuelError(ErrorCode.INVALID_DECODE_VALUE, "Only one field must be provided.");
32236
+ }
32237
+ const valueCoder = this.coders[caseKey];
32238
+ const caseIndex = Object.keys(this.coders).indexOf(caseKey);
32239
+ const encodedValue = valueCoder.encode(value[caseKey]);
32240
+ return new Uint8Array([...this.#caseIndexCoder.encode(caseIndex), ...encodedValue]);
32241
+ }
32242
+ #decodeNativeEnum(caseKey, newOffset) {
32243
+ return [caseKey, newOffset];
32244
+ }
32245
+ decode(data, offset) {
32246
+ if (data.length < this.#encodedValueSize) {
32247
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid enum data size.`);
32248
+ }
32249
+ const caseBytes = new BigNumberCoder("u64").decode(data, offset)[0];
32250
+ const caseIndex = toNumber(caseBytes);
32251
+ const caseKey = Object.keys(this.coders)[caseIndex];
32252
+ if (!caseKey) {
32253
+ throw new FuelError(
32254
+ ErrorCode.INVALID_DECODE_VALUE,
32255
+ `Invalid caseIndex "${caseIndex}". Valid cases: ${Object.keys(this.coders)}.`
32256
+ );
32257
+ }
32258
+ const valueCoder = this.coders[caseKey];
32259
+ const offsetAndCase = offset + WORD_SIZE;
32260
+ const [decoded, newOffset] = valueCoder.decode(data, offsetAndCase);
32261
+ if (isFullyNativeEnum2(this.coders)) {
32262
+ return this.#decodeNativeEnum(caseKey, newOffset);
32263
+ }
32264
+ return [{ [caseKey]: decoded }, newOffset];
32265
+ }
32266
+ };
32267
+ var getLength = (baseType) => {
32268
+ switch (baseType) {
32269
+ case "u8":
32270
+ return 1;
32271
+ case "u16":
32272
+ return 2;
32273
+ case "u32":
32274
+ return 4;
32275
+ default:
32276
+ throw new FuelError(ErrorCode.TYPE_NOT_SUPPORTED, `Invalid number type: ${baseType}`);
32277
+ }
32278
+ };
32279
+ var NumberCoder2 = class extends Coder {
32280
+ length;
32281
+ baseType;
32282
+ constructor(baseType) {
32283
+ const length = getLength(baseType);
32284
+ super("number", baseType, length);
32285
+ this.baseType = baseType;
32286
+ this.length = length;
32287
+ }
32288
+ encode(value) {
32289
+ let bytes2;
32290
+ try {
32291
+ bytes2 = toBytes2(value);
32292
+ } catch (error) {
32293
+ throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.baseType}.`);
32294
+ }
32295
+ if (bytes2.length > this.length) {
32296
+ throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.baseType}, too many bytes.`);
32297
+ }
32298
+ return toBytes2(bytes2, this.length);
32299
+ }
32300
+ decode(data, offset) {
32301
+ if (data.length < this.encodedLength) {
32302
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid number data size.`);
32303
+ }
32304
+ const bytes2 = data.slice(offset, offset + this.length);
32305
+ if (bytes2.length !== this.encodedLength) {
32306
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid number byte data size.`);
32307
+ }
32308
+ return [toNumber(bytes2), offset + this.length];
32309
+ }
32310
+ };
32311
+ var OptionCoder2 = class extends EnumCoder2 {
32312
+ encode(value) {
32313
+ const result = super.encode(this.toSwayOption(value));
32314
+ return result;
32315
+ }
32316
+ toSwayOption(input) {
32317
+ if (input !== void 0) {
32318
+ return { Some: input };
32319
+ }
32320
+ return { None: [] };
32321
+ }
32322
+ decode(data, offset) {
32323
+ const [decoded, newOffset] = super.decode(data, offset);
32324
+ return [this.toOption(decoded), newOffset];
32325
+ }
32326
+ toOption(output2) {
32327
+ if (output2 && "Some" in output2) {
32328
+ return output2.Some;
32329
+ }
32330
+ return void 0;
32331
+ }
32332
+ };
32333
+ var RawSliceCoder2 = class extends Coder {
32334
+ constructor() {
32335
+ super("raw untyped slice", "raw untyped slice", WORD_SIZE);
32336
+ }
32337
+ encode(value) {
32338
+ if (!Array.isArray(value)) {
32339
+ throw new FuelError(ErrorCode.ENCODE_ERROR, `Expected array value.`);
32340
+ }
32341
+ const internalCoder = new ArrayCoder(new NumberCoder2("u8"), value.length);
32342
+ const bytes2 = internalCoder.encode(value);
32343
+ const lengthBytes = new BigNumberCoder("u64").encode(bytes2.length);
32344
+ return new Uint8Array([...lengthBytes, ...bytes2]);
32345
+ }
32346
+ decode(data, offset) {
32347
+ if (data.length < this.encodedLength) {
32348
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid raw slice data size.`);
32349
+ }
32350
+ const offsetAndLength = offset + WORD_SIZE;
32351
+ const lengthBytes = data.slice(offset, offsetAndLength);
32352
+ const length = bn(new BigNumberCoder("u64").decode(lengthBytes, 0)[0]).toNumber();
32353
+ const dataBytes = data.slice(offsetAndLength, offsetAndLength + length);
32354
+ if (dataBytes.length !== length) {
32355
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid raw slice byte data size.`);
32356
+ }
32357
+ const internalCoder = new ArrayCoder(new NumberCoder2("u8"), length);
32358
+ const [decodedValue] = internalCoder.decode(dataBytes, 0);
32359
+ return [decodedValue, offsetAndLength + length];
32360
+ }
32361
+ };
32362
+ var StdStringCoder2 = class extends Coder {
32363
+ constructor() {
32364
+ super("struct", "struct String", WORD_SIZE);
32365
+ }
32366
+ encode(value) {
32367
+ const bytes2 = toUtf8Bytes(value);
32368
+ const lengthBytes = new BigNumberCoder("u64").encode(value.length);
32369
+ return new Uint8Array([...lengthBytes, ...bytes2]);
32370
+ }
32371
+ decode(data, offset) {
32372
+ if (data.length < this.encodedLength) {
32373
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid std string data size.`);
32374
+ }
32375
+ const offsetAndLength = offset + WORD_SIZE;
32376
+ const lengthBytes = data.slice(offset, offsetAndLength);
32377
+ const length = bn(new BigNumberCoder("u64").decode(lengthBytes, 0)[0]).toNumber();
32378
+ const dataBytes = data.slice(offsetAndLength, offsetAndLength + length);
32379
+ if (dataBytes.length !== length) {
32380
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid std string byte data size.`);
32381
+ }
32382
+ return [toUtf8String(dataBytes), offsetAndLength + length];
32383
+ }
32384
+ };
32385
+ __publicField4(StdStringCoder2, "memorySize", 1);
31531
32386
  var StrSliceCoder = class extends Coder {
31532
32387
  constructor() {
31533
32388
  super("strSlice", "str", WORD_SIZE);
@@ -31552,7 +32407,7 @@ This unreleased fuel-core build may include features and updates not yet support
31552
32407
  }
31553
32408
  };
31554
32409
  __publicField4(StrSliceCoder, "memorySize", 1);
31555
- var StringCoder = class extends Coder {
32410
+ var StringCoder2 = class extends Coder {
31556
32411
  constructor(length) {
31557
32412
  super("string", `str[${length}]`, length);
31558
32413
  }
@@ -31573,7 +32428,7 @@ This unreleased fuel-core build may include features and updates not yet support
31573
32428
  return [toUtf8String(bytes2), offset + this.encodedLength];
31574
32429
  }
31575
32430
  };
31576
- var StructCoder = class extends Coder {
32431
+ var StructCoder2 = class extends Coder {
31577
32432
  name;
31578
32433
  coders;
31579
32434
  constructor(name, coders) {
@@ -31590,7 +32445,7 @@ This unreleased fuel-core build may include features and updates not yet support
31590
32445
  Object.keys(this.coders).map((fieldName) => {
31591
32446
  const fieldCoder = this.coders[fieldName];
31592
32447
  const fieldValue = value[fieldName];
31593
- if (!(fieldCoder instanceof OptionCoder) && fieldValue == null) {
32448
+ if (!(fieldCoder instanceof OptionCoder2) && fieldValue == null) {
31594
32449
  throw new FuelError(
31595
32450
  ErrorCode.ENCODE_ERROR,
31596
32451
  `Invalid ${this.type}. Field "${fieldName}" not present.`
@@ -31615,7 +32470,7 @@ This unreleased fuel-core build may include features and updates not yet support
31615
32470
  return [decodedValue, newOffset];
31616
32471
  }
31617
32472
  };
31618
- var TupleCoder = class extends Coder {
32473
+ var TupleCoder2 = class extends Coder {
31619
32474
  coders;
31620
32475
  constructor(coders) {
31621
32476
  const encodedLength = coders.reduce((acc, coder) => acc + coder.encodedLength, 0);
@@ -31641,14 +32496,13 @@ This unreleased fuel-core build may include features and updates not yet support
31641
32496
  return [decodedValue, newOffset];
31642
32497
  }
31643
32498
  };
31644
- var isUint8Array = (value) => value instanceof Uint8Array;
31645
- var VecCoder = class extends Coder {
32499
+ var VecCoder2 = class extends Coder {
31646
32500
  coder;
31647
32501
  #isOptionVec;
31648
32502
  constructor(coder) {
31649
32503
  super("struct", `struct Vec`, coder.encodedLength + WORD_SIZE);
31650
32504
  this.coder = coder;
31651
- this.#isOptionVec = this.coder instanceof OptionCoder;
32505
+ this.#isOptionVec = this.coder instanceof OptionCoder2;
31652
32506
  }
31653
32507
  encode(value) {
31654
32508
  if (!Array.isArray(value) && !isUint8Array(value)) {
@@ -31687,214 +32541,29 @@ This unreleased fuel-core build may include features and updates not yet support
31687
32541
  return [chunks, newOffset];
31688
32542
  }
31689
32543
  };
31690
- var getEncodingVersion = (encoding) => {
31691
- switch (encoding) {
31692
- case void 0:
31693
- case ENCODING_V1:
31694
- return ENCODING_V1;
31695
- default:
31696
- throw new FuelError(
31697
- ErrorCode.UNSUPPORTED_ENCODING_VERSION,
31698
- `Encoding version '${encoding}' is unsupported.`
31699
- );
31700
- }
31701
- };
31702
- var findFunctionByName = (abi, name) => {
31703
- const fn = abi.functions.find((f2) => f2.name === name);
31704
- if (!fn) {
31705
- throw new FuelError(
31706
- ErrorCode.FUNCTION_NOT_FOUND,
31707
- `Function with name '${name}' doesn't exist in the ABI`
31708
- );
31709
- }
31710
- return fn;
31711
- };
31712
- var findTypeById = (abi, typeId) => {
31713
- const type3 = abi.types.find((t) => t.typeId === typeId);
31714
- if (!type3) {
31715
- throw new FuelError(
31716
- ErrorCode.TYPE_NOT_FOUND,
31717
- `Type with typeId '${typeId}' doesn't exist in the ABI.`
31718
- );
31719
- }
31720
- return type3;
31721
- };
31722
- var findNonEmptyInputs = (abi, inputs) => inputs.filter((input) => findTypeById(abi, input.type).type !== "()");
31723
- var findVectorBufferArgument = (components) => {
31724
- const bufferComponent = components.find((c) => c.name === "buf");
31725
- const bufferTypeArgument = bufferComponent?.originalTypeArguments?.[0];
31726
- if (!bufferComponent || !bufferTypeArgument) {
31727
- throw new FuelError(
31728
- ErrorCode.INVALID_COMPONENT,
31729
- `The Vec type provided is missing or has a malformed 'buf' component.`
31730
- );
31731
- }
31732
- return bufferTypeArgument;
31733
- };
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
- );
31752
- }
31753
- static getResolvedGenericComponents(abi, arg, components, typeParameters) {
31754
- if (components === null) {
31755
- return null;
31756
- }
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));
31776
- }
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;
31809
- }
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);
31821
- });
31822
- return implicitGenericParameters.length > 0 ? implicitGenericParameters : null;
31823
- }
31824
- getSignature() {
31825
- const prefix = this.getArgSignaturePrefix();
31826
- const content = this.getArgSignatureContent();
31827
- return `${prefix}${content}`;
31828
- }
31829
- getArgSignaturePrefix() {
31830
- const structMatch = structRegEx.test(this.type);
31831
- if (structMatch) {
31832
- return "s";
31833
- }
31834
- const arrayMatch = arrayRegEx.test(this.type);
31835
- if (arrayMatch) {
31836
- return "a";
31837
- }
31838
- const enumMatch = enumRegEx.test(this.type);
31839
- if (enumMatch) {
31840
- return "e";
31841
- }
31842
- return "";
31843
- }
31844
- getArgSignatureContent() {
31845
- if (this.type === "raw untyped ptr") {
31846
- return "rawptr";
31847
- }
31848
- if (this.type === "raw untyped slice") {
31849
- return "rawslice";
31850
- }
31851
- const strMatch = stringRegEx.exec(this.type)?.groups;
31852
- if (strMatch) {
31853
- return `str[${strMatch.length}]`;
31854
- }
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}`;
31865
- }
31866
- };
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) => {
32544
+ var getCoder2 = (resolvedAbiType, _options) => {
31876
32545
  switch (resolvedAbiType.type) {
31877
32546
  case U8_CODER_TYPE:
31878
32547
  case U16_CODER_TYPE:
31879
32548
  case U32_CODER_TYPE:
31880
- return new NumberCoder(resolvedAbiType.type);
32549
+ return new NumberCoder2(resolvedAbiType.type);
31881
32550
  case U64_CODER_TYPE:
31882
32551
  case RAW_PTR_CODER_TYPE:
31883
32552
  return new BigNumberCoder("u64");
31884
32553
  case U256_CODER_TYPE:
31885
32554
  return new BigNumberCoder("u256");
31886
32555
  case RAW_SLICE_CODER_TYPE:
31887
- return new RawSliceCoder();
32556
+ return new RawSliceCoder2();
31888
32557
  case BOOL_CODER_TYPE:
31889
- return new BooleanCoder();
32558
+ return new BooleanCoder2();
31890
32559
  case B256_CODER_TYPE:
31891
32560
  return new B256Coder();
31892
32561
  case B512_CODER_TYPE:
31893
32562
  return new B512Coder();
31894
32563
  case BYTES_CODER_TYPE:
31895
- return new ByteCoder();
32564
+ return new ByteCoder2();
31896
32565
  case STD_STRING_CODER_TYPE:
31897
- return new StdStringCoder();
32566
+ return new StdStringCoder2();
31898
32567
  case STR_SLICE_CODER_TYPE:
31899
32568
  return new StrSliceCoder();
31900
32569
  default:
@@ -31903,7 +32572,7 @@ This unreleased fuel-core build may include features and updates not yet support
31903
32572
  const stringMatch = stringRegEx.exec(resolvedAbiType.type)?.groups;
31904
32573
  if (stringMatch) {
31905
32574
  const length = parseInt(stringMatch.length, 10);
31906
- return new StringCoder(length);
32575
+ return new StringCoder2(length);
31907
32576
  }
31908
32577
  const components = resolvedAbiType.components;
31909
32578
  const arrayMatch = arrayRegEx.exec(resolvedAbiType.type)?.groups;
@@ -31916,42 +32585,46 @@ This unreleased fuel-core build may include features and updates not yet support
31916
32585
  `The provided Array type is missing an item of 'component'.`
31917
32586
  );
31918
32587
  }
31919
- const arrayElementCoder = getCoder(arg);
32588
+ const arrayElementCoder = getCoder2(arg, { isSmallBytes: true });
31920
32589
  return new ArrayCoder(arrayElementCoder, length);
31921
32590
  }
31922
32591
  if (resolvedAbiType.type === VEC_CODER_TYPE) {
31923
32592
  const arg = findVectorBufferArgument(components);
31924
32593
  const argType = new ResolvedAbiType(resolvedAbiType.abi, arg);
31925
- const itemCoder = getCoder(argType, { encoding: ENCODING_V1 });
31926
- return new VecCoder(itemCoder);
32594
+ const itemCoder = getCoder2(argType, { isSmallBytes: true, encoding: ENCODING_V0 });
32595
+ return new VecCoder2(itemCoder);
31927
32596
  }
31928
32597
  const structMatch = structRegEx.exec(resolvedAbiType.type)?.groups;
31929
32598
  if (structMatch) {
31930
- const coders = getCoders(components, { getCoder });
31931
- return new StructCoder(structMatch.name, coders);
32599
+ const coders = getCoders(components, { isRightPadded: true, getCoder: getCoder2 });
32600
+ return new StructCoder2(structMatch.name, coders);
31932
32601
  }
31933
32602
  const enumMatch = enumRegEx.exec(resolvedAbiType.type)?.groups;
31934
32603
  if (enumMatch) {
31935
- const coders = getCoders(components, { getCoder });
32604
+ const coders = getCoders(components, { getCoder: getCoder2 });
31936
32605
  const isOptionEnum = resolvedAbiType.type === OPTION_CODER_TYPE;
31937
32606
  if (isOptionEnum) {
31938
- return new OptionCoder(enumMatch.name, coders);
32607
+ return new OptionCoder2(enumMatch.name, coders);
31939
32608
  }
31940
- return new EnumCoder(enumMatch.name, coders);
32609
+ return new EnumCoder2(enumMatch.name, coders);
31941
32610
  }
31942
32611
  const tupleMatch = tupleRegEx.exec(resolvedAbiType.type)?.groups;
31943
32612
  if (tupleMatch) {
31944
- const coders = components.map((component) => getCoder(component, { encoding: ENCODING_V1 }));
31945
- return new TupleCoder(coders);
32613
+ const coders = components.map(
32614
+ (component) => getCoder2(component, { isRightPadded: true, encoding: ENCODING_V0 })
32615
+ );
32616
+ return new TupleCoder2(coders);
31946
32617
  }
31947
32618
  throw new FuelError(
31948
32619
  ErrorCode.CODER_NOT_FOUND,
31949
32620
  `Coder not found: ${JSON.stringify(resolvedAbiType)}.`
31950
32621
  );
31951
32622
  };
31952
- function getCoderForEncoding(encoding = ENCODING_V1) {
32623
+ function getCoderForEncoding(encoding = ENCODING_V0) {
31953
32624
  switch (encoding) {
31954
32625
  case ENCODING_V1:
32626
+ return getCoder2;
32627
+ case ENCODING_V0:
31955
32628
  return getCoder;
31956
32629
  default:
31957
32630
  throw new FuelError(
@@ -31962,7 +32635,7 @@ This unreleased fuel-core build may include features and updates not yet support
31962
32635
  }
31963
32636
  var AbiCoder = class {
31964
32637
  static getCoder(abi, argument, options = {
31965
- padToWordSize: false
32638
+ isSmallBytes: false
31966
32639
  }) {
31967
32640
  const resolvedAbiType = new ResolvedAbiType(abi, argument);
31968
32641
  return getCoderForEncoding(options.encoding)(resolvedAbiType, options);
@@ -31982,6 +32655,8 @@ This unreleased fuel-core build may include features and updates not yet support
31982
32655
  name;
31983
32656
  jsonFn;
31984
32657
  attributes;
32658
+ isInputDataPointer;
32659
+ outputMetadata;
31985
32660
  jsonAbi;
31986
32661
  constructor(jsonAbi, name) {
31987
32662
  this.jsonAbi = jsonAbi;
@@ -31989,8 +32664,13 @@ This unreleased fuel-core build may include features and updates not yet support
31989
32664
  this.name = name;
31990
32665
  this.signature = FunctionFragment.getSignature(this.jsonAbi, this.jsonFn);
31991
32666
  this.selector = FunctionFragment.getFunctionSelector(this.signature);
31992
- this.selectorBytes = new StdStringCoder().encode(name);
32667
+ this.selectorBytes = new StdStringCoder2().encode(name);
31993
32668
  this.encoding = getEncodingVersion(jsonAbi.encoding);
32669
+ this.isInputDataPointer = this.#isInputDataPointer();
32670
+ this.outputMetadata = {
32671
+ isHeapType: this.#isOutputDataHeap(),
32672
+ encodedLength: this.#getOutputEncodedLength()
32673
+ };
31994
32674
  this.attributes = this.jsonFn.attributes ?? [];
31995
32675
  }
31996
32676
  static getSignature(abi, fn) {
@@ -32003,7 +32683,29 @@ This unreleased fuel-core build may include features and updates not yet support
32003
32683
  const hashedFunctionSignature = sha2562(bufferFromString2(functionSignature, "utf-8"));
32004
32684
  return bn(hashedFunctionSignature.slice(0, 10)).toHex(8);
32005
32685
  }
32006
- encodeArguments(values) {
32686
+ #isInputDataPointer() {
32687
+ const inputTypes = this.jsonFn.inputs.map((i) => findTypeById(this.jsonAbi, i.type));
32688
+ return this.jsonFn.inputs.length > 1 || isPointerType(inputTypes[0]?.type || "");
32689
+ }
32690
+ #isOutputDataHeap() {
32691
+ const outputType = findTypeById(this.jsonAbi, this.jsonFn.output.type);
32692
+ return isHeapType(outputType?.type || "");
32693
+ }
32694
+ #getOutputEncodedLength() {
32695
+ try {
32696
+ const heapCoder = AbiCoder.getCoder(this.jsonAbi, this.jsonFn.output);
32697
+ if (heapCoder instanceof VecCoder) {
32698
+ return heapCoder.coder.encodedLength;
32699
+ }
32700
+ if (heapCoder instanceof ByteCoder) {
32701
+ return ByteCoder.memorySize;
32702
+ }
32703
+ return heapCoder.encodedLength;
32704
+ } catch (e) {
32705
+ return 0;
32706
+ }
32707
+ }
32708
+ encodeArguments(values, offset = 0) {
32007
32709
  FunctionFragment.verifyArgsAndInputsAlign(values, this.jsonFn.inputs, this.jsonAbi);
32008
32710
  const shallowCopyValues = values.slice();
32009
32711
  const nonEmptyInputs = findNonEmptyInputs(this.jsonAbi, this.jsonFn.inputs);
@@ -32013,10 +32715,15 @@ This unreleased fuel-core build may include features and updates not yet support
32013
32715
  }
32014
32716
  const coders = nonEmptyInputs.map(
32015
32717
  (t) => AbiCoder.getCoder(this.jsonAbi, t, {
32718
+ isRightPadded: nonEmptyInputs.length > 1,
32016
32719
  encoding: this.encoding
32017
32720
  })
32018
32721
  );
32019
- return new TupleCoder(coders).encode(shallowCopyValues);
32722
+ if (this.encoding === ENCODING_V1) {
32723
+ return new TupleCoder2(coders).encode(shallowCopyValues);
32724
+ }
32725
+ const results = new TupleCoder(coders).encode(shallowCopyValues);
32726
+ return unpackDynamicData(results, offset, results.byteLength);
32020
32727
  }
32021
32728
  static verifyArgsAndInputsAlign(args, inputs, abi) {
32022
32729
  if (args.length === inputs.length) {
@@ -32125,9 +32832,9 @@ This unreleased fuel-core build may include features and updates not yet support
32125
32832
  const fragment = typeof functionFragment === "string" ? this.getFunction(functionFragment) : functionFragment;
32126
32833
  return fragment.decodeArguments(data);
32127
32834
  }
32128
- encodeFunctionData(functionFragment, values) {
32835
+ encodeFunctionData(functionFragment, values, offset = 0) {
32129
32836
  const fragment = typeof functionFragment === "string" ? this.getFunction(functionFragment) : functionFragment;
32130
- return fragment.encodeArguments(values);
32837
+ return fragment.encodeArguments(values, offset);
32131
32838
  }
32132
32839
  // Decode the result of a function call
32133
32840
  decodeFunctionResult(functionFragment, data) {
@@ -32155,7 +32862,9 @@ This unreleased fuel-core build may include features and updates not yet support
32155
32862
  );
32156
32863
  }
32157
32864
  return AbiCoder.encode(this.jsonAbi, configurable.configurableType, value, {
32158
- encoding: this.encoding
32865
+ isRightPadded: true,
32866
+ // TODO: Review support for configurables in v1 encoding when it becomes available
32867
+ encoding: ENCODING_V0
32159
32868
  });
32160
32869
  }
32161
32870
  getTypeById(typeId) {
@@ -32205,8 +32914,8 @@ This unreleased fuel-core build may include features and updates not yet support
32205
32914
  var TxPointerCoder = class extends StructCoder {
32206
32915
  constructor() {
32207
32916
  super("TxPointer", {
32208
- blockHeight: new NumberCoder("u32", { padToWordSize: true }),
32209
- txIndex: new NumberCoder("u16", { padToWordSize: true })
32917
+ blockHeight: new NumberCoder("u32"),
32918
+ txIndex: new NumberCoder("u16")
32210
32919
  });
32211
32920
  }
32212
32921
  };
@@ -32223,12 +32932,12 @@ This unreleased fuel-core build may include features and updates not yet support
32223
32932
  encode(value) {
32224
32933
  const parts = [];
32225
32934
  parts.push(new B256Coder().encode(value.txID));
32226
- parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.outputIndex));
32935
+ parts.push(new NumberCoder("u16").encode(value.outputIndex));
32227
32936
  parts.push(new B256Coder().encode(value.owner));
32228
32937
  parts.push(new BigNumberCoder("u64").encode(value.amount));
32229
32938
  parts.push(new B256Coder().encode(value.assetId));
32230
32939
  parts.push(new TxPointerCoder().encode(value.txPointer));
32231
- parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.witnessIndex));
32940
+ parts.push(new NumberCoder("u16").encode(value.witnessIndex));
32232
32941
  parts.push(new BigNumberCoder("u64").encode(value.predicateGasUsed));
32233
32942
  parts.push(new BigNumberCoder("u64").encode(value.predicateLength));
32234
32943
  parts.push(new BigNumberCoder("u64").encode(value.predicateDataLength));
@@ -32243,7 +32952,7 @@ This unreleased fuel-core build may include features and updates not yet support
32243
32952
  let o = offset;
32244
32953
  [decoded, o] = new B256Coder().decode(data, o);
32245
32954
  const txID = decoded;
32246
- [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
32955
+ [decoded, o] = new NumberCoder("u16").decode(data, o);
32247
32956
  const outputIndex = decoded;
32248
32957
  [decoded, o] = new B256Coder().decode(data, o);
32249
32958
  const owner = decoded;
@@ -32253,7 +32962,7 @@ This unreleased fuel-core build may include features and updates not yet support
32253
32962
  const assetId = decoded;
32254
32963
  [decoded, o] = new TxPointerCoder().decode(data, o);
32255
32964
  const txPointer = decoded;
32256
- [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
32965
+ [decoded, o] = new NumberCoder("u16").decode(data, o);
32257
32966
  const witnessIndex = Number(decoded);
32258
32967
  [decoded, o] = new BigNumberCoder("u64").decode(data, o);
32259
32968
  const predicateGasUsed = decoded;
@@ -32292,7 +33001,7 @@ This unreleased fuel-core build may include features and updates not yet support
32292
33001
  encode(value) {
32293
33002
  const parts = [];
32294
33003
  parts.push(new B256Coder().encode(value.txID));
32295
- parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.outputIndex));
33004
+ parts.push(new NumberCoder("u16").encode(value.outputIndex));
32296
33005
  parts.push(new B256Coder().encode(value.balanceRoot));
32297
33006
  parts.push(new B256Coder().encode(value.stateRoot));
32298
33007
  parts.push(new TxPointerCoder().encode(value.txPointer));
@@ -32304,7 +33013,7 @@ This unreleased fuel-core build may include features and updates not yet support
32304
33013
  let o = offset;
32305
33014
  [decoded, o] = new B256Coder().decode(data, o);
32306
33015
  const txID = decoded;
32307
- [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
33016
+ [decoded, o] = new NumberCoder("u16").decode(data, o);
32308
33017
  const outputIndex = decoded;
32309
33018
  [decoded, o] = new B256Coder().decode(data, o);
32310
33019
  const balanceRoot = decoded;
@@ -32353,7 +33062,7 @@ This unreleased fuel-core build may include features and updates not yet support
32353
33062
  parts.push(new ByteArrayCoder(32).encode(value.recipient));
32354
33063
  parts.push(new BigNumberCoder("u64").encode(value.amount));
32355
33064
  parts.push(new ByteArrayCoder(32).encode(value.nonce));
32356
- parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.witnessIndex));
33065
+ parts.push(new NumberCoder("u16").encode(value.witnessIndex));
32357
33066
  parts.push(new BigNumberCoder("u64").encode(value.predicateGasUsed));
32358
33067
  parts.push(new BigNumberCoder("u64").encode(data.length));
32359
33068
  parts.push(new BigNumberCoder("u64").encode(value.predicateLength));
@@ -32382,11 +33091,11 @@ This unreleased fuel-core build may include features and updates not yet support
32382
33091
  const amount = decoded;
32383
33092
  [decoded, o] = new B256Coder().decode(data, o);
32384
33093
  const nonce = decoded;
32385
- [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
33094
+ [decoded, o] = new NumberCoder("u16").decode(data, o);
32386
33095
  const witnessIndex = Number(decoded);
32387
33096
  [decoded, o] = new BigNumberCoder("u64").decode(data, o);
32388
33097
  const predicateGasUsed = decoded;
32389
- [decoded, o] = new NumberCoder("u32", { padToWordSize: true }).decode(data, o);
33098
+ [decoded, o] = new NumberCoder("u32").decode(data, o);
32390
33099
  const dataLength2 = decoded;
32391
33100
  [decoded, o] = new BigNumberCoder("u64").decode(data, o);
32392
33101
  const predicateLength = decoded;
@@ -32424,7 +33133,7 @@ This unreleased fuel-core build may include features and updates not yet support
32424
33133
  }
32425
33134
  encode(value) {
32426
33135
  const parts = [];
32427
- parts.push(new NumberCoder("u8", { padToWordSize: true }).encode(value.type));
33136
+ parts.push(new NumberCoder("u8").encode(value.type));
32428
33137
  const { type: type3 } = value;
32429
33138
  switch (type3) {
32430
33139
  case 0: {
@@ -32451,7 +33160,7 @@ This unreleased fuel-core build may include features and updates not yet support
32451
33160
  decode(data, offset) {
32452
33161
  let decoded;
32453
33162
  let o = offset;
32454
- [decoded, o] = new NumberCoder("u8", { padToWordSize: true }).decode(data, o);
33163
+ [decoded, o] = new NumberCoder("u8").decode(data, o);
32455
33164
  const type3 = decoded;
32456
33165
  switch (type3) {
32457
33166
  case 0: {
@@ -32520,7 +33229,7 @@ This unreleased fuel-core build may include features and updates not yet support
32520
33229
  }
32521
33230
  encode(value) {
32522
33231
  const parts = [];
32523
- parts.push(new NumberCoder("u8", { padToWordSize: true }).encode(value.inputIndex));
33232
+ parts.push(new NumberCoder("u8").encode(value.inputIndex));
32524
33233
  parts.push(new B256Coder().encode(value.balanceRoot));
32525
33234
  parts.push(new B256Coder().encode(value.stateRoot));
32526
33235
  return concat(parts);
@@ -32528,7 +33237,7 @@ This unreleased fuel-core build may include features and updates not yet support
32528
33237
  decode(data, offset) {
32529
33238
  let decoded;
32530
33239
  let o = offset;
32531
- [decoded, o] = new NumberCoder("u8", { padToWordSize: true }).decode(data, o);
33240
+ [decoded, o] = new NumberCoder("u8").decode(data, o);
32532
33241
  const inputIndex = decoded;
32533
33242
  [decoded, o] = new B256Coder().decode(data, o);
32534
33243
  const balanceRoot = decoded;
@@ -32640,7 +33349,7 @@ This unreleased fuel-core build may include features and updates not yet support
32640
33349
  }
32641
33350
  encode(value) {
32642
33351
  const parts = [];
32643
- parts.push(new NumberCoder("u8", { padToWordSize: true }).encode(value.type));
33352
+ parts.push(new NumberCoder("u8").encode(value.type));
32644
33353
  const { type: type3 } = value;
32645
33354
  switch (type3) {
32646
33355
  case 0: {
@@ -32675,7 +33384,7 @@ This unreleased fuel-core build may include features and updates not yet support
32675
33384
  decode(data, offset) {
32676
33385
  let decoded;
32677
33386
  let o = offset;
32678
- [decoded, o] = new NumberCoder("u8", { padToWordSize: true }).decode(data, o);
33387
+ [decoded, o] = new NumberCoder("u8").decode(data, o);
32679
33388
  const type3 = decoded;
32680
33389
  switch (type3) {
32681
33390
  case 0: {
@@ -32743,7 +33452,7 @@ This unreleased fuel-core build may include features and updates not yet support
32743
33452
  parts.push(new BigNumberCoder("u64").encode(data));
32744
33453
  break;
32745
33454
  case 4:
32746
- parts.push(new NumberCoder("u32", { padToWordSize: true }).encode(data));
33455
+ parts.push(new NumberCoder("u32").encode(data));
32747
33456
  break;
32748
33457
  default: {
32749
33458
  throw new FuelError(ErrorCode.INVALID_POLICY_TYPE, `Invalid policy type: ${type3}`);
@@ -32766,10 +33475,7 @@ This unreleased fuel-core build may include features and updates not yet support
32766
33475
  policies.push({ type: 2, data: witnessLimit });
32767
33476
  }
32768
33477
  if (policyTypes & 4) {
32769
- const [maturity, nextOffset] = new NumberCoder("u32", { padToWordSize: true }).decode(
32770
- data,
32771
- o
32772
- );
33478
+ const [maturity, nextOffset] = new NumberCoder("u32").decode(data, o);
32773
33479
  o = nextOffset;
32774
33480
  policies.push({ type: 4, data: maturity });
32775
33481
  }
@@ -32816,7 +33522,7 @@ This unreleased fuel-core build may include features and updates not yet support
32816
33522
  parts.push(new B256Coder().encode(value.recipient));
32817
33523
  parts.push(new BigNumberCoder("u64").encode(value.amount));
32818
33524
  parts.push(new B256Coder().encode(value.nonce));
32819
- parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.data.length));
33525
+ parts.push(new NumberCoder("u16").encode(value.data.length));
32820
33526
  parts.push(new B256Coder().encode(value.digest));
32821
33527
  parts.push(new ByteArrayCoder(value.data.length).encode(value.data));
32822
33528
  return concat(parts);
@@ -32832,7 +33538,7 @@ This unreleased fuel-core build may include features and updates not yet support
32832
33538
  const amount = decoded;
32833
33539
  [decoded, o] = new B256Coder().decode(data, o);
32834
33540
  const nonce = decoded;
32835
- [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
33541
+ [decoded, o] = new NumberCoder("u16").decode(data, o);
32836
33542
  const len = decoded;
32837
33543
  [decoded, o] = new B256Coder().decode(data, o);
32838
33544
  const digest = decoded;
@@ -32956,11 +33662,11 @@ This unreleased fuel-core build may include features and updates not yet support
32956
33662
  encode(upgradePurposeType) {
32957
33663
  const parts = [];
32958
33664
  const { type: type3 } = upgradePurposeType;
32959
- parts.push(new NumberCoder("u8", { padToWordSize: true }).encode(type3));
33665
+ parts.push(new NumberCoder("u8").encode(type3));
32960
33666
  switch (type3) {
32961
33667
  case 0: {
32962
33668
  const data = upgradePurposeType.data;
32963
- parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(data.witnessIndex));
33669
+ parts.push(new NumberCoder("u16").encode(data.witnessIndex));
32964
33670
  parts.push(new B256Coder().encode(data.checksum));
32965
33671
  break;
32966
33672
  }
@@ -32981,11 +33687,11 @@ This unreleased fuel-core build may include features and updates not yet support
32981
33687
  decode(data, offset) {
32982
33688
  let o = offset;
32983
33689
  let decoded;
32984
- [decoded, o] = new NumberCoder("u8", { padToWordSize: true }).decode(data, o);
33690
+ [decoded, o] = new NumberCoder("u8").decode(data, o);
32985
33691
  const type3 = decoded;
32986
33692
  switch (type3) {
32987
33693
  case 0: {
32988
- [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
33694
+ [decoded, o] = new NumberCoder("u16").decode(data, o);
32989
33695
  const witnessIndex = decoded;
32990
33696
  [decoded, o] = new B256Coder().decode(data, o);
32991
33697
  const checksum = decoded;
@@ -33016,14 +33722,14 @@ This unreleased fuel-core build may include features and updates not yet support
33016
33722
  }
33017
33723
  encode(value) {
33018
33724
  const parts = [];
33019
- parts.push(new NumberCoder("u32", { padToWordSize: true }).encode(value.dataLength));
33725
+ parts.push(new NumberCoder("u32").encode(value.dataLength));
33020
33726
  parts.push(new ByteArrayCoder(value.dataLength).encode(value.data));
33021
33727
  return concat(parts);
33022
33728
  }
33023
33729
  decode(data, offset) {
33024
33730
  let decoded;
33025
33731
  let o = offset;
33026
- [decoded, o] = new NumberCoder("u32", { padToWordSize: true }).decode(data, o);
33732
+ [decoded, o] = new NumberCoder("u32").decode(data, o);
33027
33733
  const dataLength2 = decoded;
33028
33734
  [decoded, o] = new ByteArrayCoder(dataLength2).decode(data, o);
33029
33735
  const witnessData = decoded;
@@ -33054,10 +33760,10 @@ This unreleased fuel-core build may include features and updates not yet support
33054
33760
  parts.push(new B256Coder().encode(value.receiptsRoot));
33055
33761
  parts.push(new BigNumberCoder("u64").encode(value.scriptLength));
33056
33762
  parts.push(new BigNumberCoder("u64").encode(value.scriptDataLength));
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));
33763
+ parts.push(new NumberCoder("u32").encode(value.policyTypes));
33764
+ parts.push(new NumberCoder("u16").encode(value.inputsCount));
33765
+ parts.push(new NumberCoder("u16").encode(value.outputsCount));
33766
+ parts.push(new NumberCoder("u16").encode(value.witnessesCount));
33061
33767
  parts.push(new ByteArrayCoder(value.scriptLength.toNumber()).encode(value.script));
33062
33768
  parts.push(new ByteArrayCoder(value.scriptDataLength.toNumber()).encode(value.scriptData));
33063
33769
  parts.push(new PoliciesCoder().encode(value.policies));
@@ -33077,13 +33783,13 @@ This unreleased fuel-core build may include features and updates not yet support
33077
33783
  const scriptLength = decoded;
33078
33784
  [decoded, o] = new BigNumberCoder("u64").decode(data, o);
33079
33785
  const scriptDataLength = decoded;
33080
- [decoded, o] = new NumberCoder("u32", { padToWordSize: true }).decode(data, o);
33786
+ [decoded, o] = new NumberCoder("u32").decode(data, o);
33081
33787
  const policyTypes = decoded;
33082
- [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
33788
+ [decoded, o] = new NumberCoder("u16").decode(data, o);
33083
33789
  const inputsCount = decoded;
33084
- [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
33790
+ [decoded, o] = new NumberCoder("u16").decode(data, o);
33085
33791
  const outputsCount = decoded;
33086
- [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
33792
+ [decoded, o] = new NumberCoder("u16").decode(data, o);
33087
33793
  const witnessesCount = decoded;
33088
33794
  [decoded, o] = new ByteArrayCoder(scriptLength.toNumber()).decode(data, o);
33089
33795
  const script = decoded;
@@ -33125,13 +33831,13 @@ This unreleased fuel-core build may include features and updates not yet support
33125
33831
  }
33126
33832
  encode(value) {
33127
33833
  const parts = [];
33128
- parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.bytecodeWitnessIndex));
33834
+ parts.push(new NumberCoder("u16").encode(value.bytecodeWitnessIndex));
33129
33835
  parts.push(new B256Coder().encode(value.salt));
33130
33836
  parts.push(new BigNumberCoder("u64").encode(value.storageSlotsCount));
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));
33837
+ parts.push(new NumberCoder("u32").encode(value.policyTypes));
33838
+ parts.push(new NumberCoder("u16").encode(value.inputsCount));
33839
+ parts.push(new NumberCoder("u16").encode(value.outputsCount));
33840
+ parts.push(new NumberCoder("u16").encode(value.witnessesCount));
33135
33841
  parts.push(
33136
33842
  new ArrayCoder(new StorageSlotCoder(), value.storageSlotsCount.toNumber()).encode(
33137
33843
  value.storageSlots
@@ -33146,19 +33852,19 @@ This unreleased fuel-core build may include features and updates not yet support
33146
33852
  decode(data, offset) {
33147
33853
  let decoded;
33148
33854
  let o = offset;
33149
- [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
33855
+ [decoded, o] = new NumberCoder("u16").decode(data, o);
33150
33856
  const bytecodeWitnessIndex = decoded;
33151
33857
  [decoded, o] = new B256Coder().decode(data, o);
33152
33858
  const salt = decoded;
33153
33859
  [decoded, o] = new BigNumberCoder("u64").decode(data, o);
33154
33860
  const storageSlotsCount = decoded;
33155
- [decoded, o] = new NumberCoder("u32", { padToWordSize: true }).decode(data, o);
33861
+ [decoded, o] = new NumberCoder("u32").decode(data, o);
33156
33862
  const policyTypes = decoded;
33157
- [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
33863
+ [decoded, o] = new NumberCoder("u16").decode(data, o);
33158
33864
  const inputsCount = decoded;
33159
- [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
33865
+ [decoded, o] = new NumberCoder("u16").decode(data, o);
33160
33866
  const outputsCount = decoded;
33161
- [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
33867
+ [decoded, o] = new NumberCoder("u16").decode(data, o);
33162
33868
  const witnessesCount = decoded;
33163
33869
  [decoded, o] = new ArrayCoder(new StorageSlotCoder(), storageSlotsCount.toNumber()).decode(
33164
33870
  data,
@@ -33372,7 +34078,7 @@ This unreleased fuel-core build may include features and updates not yet support
33372
34078
  }
33373
34079
  encode(value) {
33374
34080
  const parts = [];
33375
- parts.push(new NumberCoder("u8", { padToWordSize: true }).encode(value.type));
34081
+ parts.push(new NumberCoder("u8").encode(value.type));
33376
34082
  const { type: type3 } = value;
33377
34083
  switch (value.type) {
33378
34084
  case 0: {
@@ -33415,7 +34121,7 @@ This unreleased fuel-core build may include features and updates not yet support
33415
34121
  decode(data, offset) {
33416
34122
  let decoded;
33417
34123
  let o = offset;
33418
- [decoded, o] = new NumberCoder("u8", { padToWordSize: true }).decode(data, o);
34124
+ [decoded, o] = new NumberCoder("u8").decode(data, o);
33419
34125
  const type3 = decoded;
33420
34126
  switch (type3) {
33421
34127
  case 0: {
@@ -39142,6 +39848,15 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
39142
39848
  }
39143
39849
  });
39144
39850
  }
39851
+ shiftPredicateData() {
39852
+ this.inputs.forEach((input) => {
39853
+ if ("predicateData" in input && "padPredicateData" in input && typeof input.padPredicateData === "function") {
39854
+ input.predicateData = input.padPredicateData(
39855
+ BaseTransactionRequest.getPolicyMeta(this).policies.length
39856
+ );
39857
+ }
39858
+ });
39859
+ }
39145
39860
  };
39146
39861
 
39147
39862
  // src/providers/transaction-request/hash-transaction.ts
@@ -39606,27 +40321,37 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
39606
40321
  };
39607
40322
 
39608
40323
  // src/providers/transaction-summary/call.ts
39609
- var getFunctionCall = ({ abi, receipt }) => {
40324
+ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
39610
40325
  const abiInterface = new Interface(abi);
39611
40326
  const callFunctionSelector = receipt.param1.toHex(8);
39612
40327
  const functionFragment = abiInterface.getFunction(callFunctionSelector);
39613
40328
  const inputs = functionFragment.jsonFn.inputs;
39614
- const encodedArgs = receipt.param2.toHex();
40329
+ let encodedArgs;
40330
+ if (functionFragment.isInputDataPointer) {
40331
+ if (rawPayload) {
40332
+ const argsOffset = bn(receipt.param2).sub(calculateVmTxMemory({ maxInputs: maxInputs.toNumber() })).toNumber();
40333
+ encodedArgs = `0x${rawPayload.slice(2).slice(argsOffset * 2)}`;
40334
+ }
40335
+ } else {
40336
+ encodedArgs = receipt.param2.toHex();
40337
+ }
39615
40338
  let argumentsProvided;
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
- }, {});
40339
+ if (encodedArgs) {
40340
+ const data = functionFragment.decodeArguments(encodedArgs);
40341
+ if (data) {
40342
+ argumentsProvided = inputs.reduce((prev, input, index) => {
40343
+ const value = data[index];
40344
+ const name = input.name;
40345
+ if (name) {
40346
+ return {
40347
+ ...prev,
40348
+ // reparse to remove bn
40349
+ [name]: JSON.parse(JSON.stringify(value))
40350
+ };
40351
+ }
40352
+ return prev;
40353
+ }, {});
40354
+ }
39630
40355
  }
39631
40356
  const call = {
39632
40357
  functionSignature: functionFragment.signature,
@@ -42123,6 +42848,7 @@ Supported fuel-core version: ${supportedVersion}.`
42123
42848
  cacheRequestInputsResourcesFromOwner(request.inputs, this.address)
42124
42849
  );
42125
42850
  request.addResources(resources);
42851
+ request.shiftPredicateData();
42126
42852
  request.updatePredicateGasUsed(estimatedPredicates);
42127
42853
  const requestToReestimate2 = clone_default(request);
42128
42854
  if (addedSignatures) {
@@ -42154,6 +42880,7 @@ Supported fuel-core version: ${supportedVersion}.`
42154
42880
  }
42155
42881
  fundingAttempts += 1;
42156
42882
  }
42883
+ request.shiftPredicateData();
42157
42884
  request.updatePredicateGasUsed(estimatedPredicates);
42158
42885
  const requestToReestimate = clone_default(request);
42159
42886
  if (addedSignatures) {
@@ -47227,6 +47954,7 @@ Supported fuel-core version: ${supportedVersion}.`
47227
47954
  */
47228
47955
  populateTransactionPredicateData(transactionRequestLike) {
47229
47956
  const request = transactionRequestify(transactionRequestLike);
47957
+ const { policies } = BaseTransactionRequest.getPolicyMeta(request);
47230
47958
  const placeholderIndex = this.getIndexFromPlaceholderWitness(request);
47231
47959
  if (placeholderIndex !== -1) {
47232
47960
  request.removeWitness(placeholderIndex);
@@ -47234,7 +47962,7 @@ Supported fuel-core version: ${supportedVersion}.`
47234
47962
  request.inputs.filter(isRequestInputResource).forEach((input) => {
47235
47963
  if (isRequestInputResourceFromOwner(input, this.address)) {
47236
47964
  input.predicate = hexlify(this.bytes);
47237
- input.predicateData = hexlify(this.getPredicateData());
47965
+ input.predicateData = hexlify(this.getPredicateData(policies.length));
47238
47966
  input.witnessIndex = 0;
47239
47967
  }
47240
47968
  });
@@ -47260,12 +47988,17 @@ Supported fuel-core version: ${supportedVersion}.`
47260
47988
  const transactionRequest = transactionRequestify(transactionRequestLike);
47261
47989
  return super.simulateTransaction(transactionRequest, { estimateTxDependencies: false });
47262
47990
  }
47263
- getPredicateData() {
47991
+ getPredicateData(policiesLength) {
47264
47992
  if (!this.predicateData.length) {
47265
47993
  return new Uint8Array();
47266
47994
  }
47267
47995
  const mainFn = this.interface?.functions.main;
47268
- return mainFn?.encodeArguments(this.predicateData) || new Uint8Array();
47996
+ const paddedCode = new ByteArrayCoder(this.bytes.length).encode(this.bytes);
47997
+ const VM_TX_MEMORY = calculateVmTxMemory({
47998
+ maxInputs: this.provider.getChain().consensusParameters.txParameters.maxInputs.toNumber()
47999
+ });
48000
+ const OFFSET = VM_TX_MEMORY + SCRIPT_FIXED_SIZE + INPUT_COIN_FIXED_SIZE + WORD_SIZE + paddedCode.byteLength + policiesLength * WORD_SIZE;
48001
+ return mainFn?.encodeArguments(this.predicateData, OFFSET) || new Uint8Array();
47269
48002
  }
47270
48003
  /**
47271
48004
  * Processes the predicate data and returns the altered bytecode and interface.
@@ -47314,7 +48047,8 @@ Supported fuel-core version: ${supportedVersion}.`
47314
48047
  );
47315
48048
  return resources.map((resource) => ({
47316
48049
  ...resource,
47317
- predicate: hexlify(this.bytes)
48050
+ predicate: hexlify(this.bytes),
48051
+ padPredicateData: (policiesLength) => hexlify(this.getPredicateData(policiesLength))
47318
48052
  }));
47319
48053
  }
47320
48054
  /**