@fuel-ts/account 0.0.0-rc-2143-20240514211533 → 0.0.0-rc-2238-20240514214137

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.56.1",
29473
+ FORC: "0.58.0",
29474
29474
  FUEL_CORE: "0.26.0",
29475
29475
  FUELS: "0.85.0"
29476
29476
  };
@@ -30899,19 +30899,6 @@ This unreleased fuel-core build may include features and updates not yet support
30899
30899
  __defNormalProp4(obj, typeof key !== "symbol" ? key + "" : key, value);
30900
30900
  return value;
30901
30901
  };
30902
- var __accessCheck2 = (obj, member, msg) => {
30903
- if (!member.has(obj))
30904
- throw TypeError("Cannot " + msg);
30905
- };
30906
- var __privateAdd2 = (obj, member, value) => {
30907
- if (member.has(obj))
30908
- throw TypeError("Cannot add the same private member more than once");
30909
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
30910
- };
30911
- var __privateMethod2 = (obj, member, method) => {
30912
- __accessCheck2(obj, member, "access private method");
30913
- return method;
30914
- };
30915
30902
  var Coder = class {
30916
30903
  name;
30917
30904
  type;
@@ -30943,7 +30930,6 @@ This unreleased fuel-core build may include features and updates not yet support
30943
30930
  var enumRegEx = /^enum (?<name>\w+)$/;
30944
30931
  var tupleRegEx = /^\((?<items>.*)\)$/;
30945
30932
  var genericRegEx = /^generic (?<name>\w+)$/;
30946
- var ENCODING_V0 = "0";
30947
30933
  var ENCODING_V1 = "1";
30948
30934
  var WORD_SIZE = 8;
30949
30935
  var BYTES_32 = 32;
@@ -30954,10 +30940,6 @@ This unreleased fuel-core build may include features and updates not yet support
30954
30940
  var TX_LEN = WORD_SIZE * 4;
30955
30941
  var TX_POINTER_LEN = WORD_SIZE * 2;
30956
30942
  var MAX_BYTES = 2 ** 32 - 1;
30957
- var calculateVmTxMemory = ({ maxInputs }) => BYTES_32 + // Tx ID
30958
- ASSET_ID_LEN + // Base asset ID
30959
- // Asset ID/Balance coin input pairs
30960
- maxInputs * (ASSET_ID_LEN + WORD_SIZE) + WORD_SIZE;
30961
30943
  var SCRIPT_FIXED_SIZE = WORD_SIZE + // Identifier
30962
30944
  WORD_SIZE + // Gas limit
30963
30945
  WORD_SIZE + // Script size
@@ -30988,125 +30970,6 @@ This unreleased fuel-core build may include features and updates not yet support
30988
30970
  WORD_SIZE + // Predicate size
30989
30971
  WORD_SIZE + // Predicate data size
30990
30972
  WORD_SIZE;
30991
- var encodedLengths = {
30992
- u64: WORD_SIZE,
30993
- u256: WORD_SIZE * 4
30994
- };
30995
- var BigNumberCoder = class extends Coder {
30996
- constructor(baseType) {
30997
- super("bigNumber", baseType, encodedLengths[baseType]);
30998
- }
30999
- encode(value) {
31000
- let bytes2;
31001
- try {
31002
- bytes2 = toBytes2(value, this.encodedLength);
31003
- } catch (error) {
31004
- throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.type}.`);
31005
- }
31006
- return bytes2;
31007
- }
31008
- decode(data, offset) {
31009
- if (data.length < this.encodedLength) {
31010
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid ${this.type} data size.`);
31011
- }
31012
- let bytes2 = data.slice(offset, offset + this.encodedLength);
31013
- bytes2 = bytes2.slice(0, this.encodedLength);
31014
- if (bytes2.length !== this.encodedLength) {
31015
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid ${this.type} byte data size.`);
31016
- }
31017
- return [bn(bytes2), offset + this.encodedLength];
31018
- }
31019
- };
31020
- var VEC_PROPERTY_SPACE = 3;
31021
- var BASE_VECTOR_OFFSET = VEC_PROPERTY_SPACE * WORD_SIZE;
31022
- var RAW_SLICE_PROPERTY_SPACE = 2;
31023
- var BASE_RAW_SLICE_OFFSET = RAW_SLICE_PROPERTY_SPACE * WORD_SIZE;
31024
- function concatWithDynamicData(items) {
31025
- const topLevelData = {};
31026
- let totalIndex = 0;
31027
- const objects = items.map((item) => {
31028
- const dynamicData = item.dynamicData;
31029
- if (dynamicData) {
31030
- Object.entries(dynamicData).forEach(([pointerIndex, vData]) => {
31031
- topLevelData[parseInt(pointerIndex, 10) + totalIndex] = vData;
31032
- });
31033
- }
31034
- const byteArray = arrayify(item);
31035
- totalIndex += byteArray.byteLength / WORD_SIZE;
31036
- return byteArray;
31037
- });
31038
- const length = objects.reduce((accum, item) => accum + item.length, 0);
31039
- const result = new Uint8Array(length);
31040
- objects.reduce((offset, object) => {
31041
- result.set(object, offset);
31042
- return offset + object.length;
31043
- }, 0);
31044
- if (Object.keys(topLevelData).length) {
31045
- result.dynamicData = topLevelData;
31046
- }
31047
- return result;
31048
- }
31049
- function unpackDynamicData(results, baseOffset, dataOffset) {
31050
- if (!results.dynamicData) {
31051
- return concat([results]);
31052
- }
31053
- let cumulativeDynamicByteLength = 0;
31054
- let updatedResults = results;
31055
- Object.entries(results.dynamicData).forEach(([pointerIndex, vData]) => {
31056
- const pointerOffset = parseInt(pointerIndex, 10) * WORD_SIZE;
31057
- const adjustedValue = new BigNumberCoder("u64").encode(
31058
- dataOffset + baseOffset + cumulativeDynamicByteLength
31059
- );
31060
- updatedResults.set(adjustedValue, pointerOffset);
31061
- const dataToAppend = vData.dynamicData ? (
31062
- // unpack child dynamic data
31063
- unpackDynamicData(
31064
- vData,
31065
- baseOffset,
31066
- dataOffset + vData.byteLength + cumulativeDynamicByteLength
31067
- )
31068
- ) : vData;
31069
- updatedResults = concat([updatedResults, dataToAppend]);
31070
- cumulativeDynamicByteLength += dataToAppend.byteLength;
31071
- });
31072
- return updatedResults;
31073
- }
31074
- var chunkByLength = (data, length = WORD_SIZE) => {
31075
- const chunks = [];
31076
- let offset = 0;
31077
- let chunk = data.slice(offset, offset + length);
31078
- while (chunk.length) {
31079
- chunks.push(chunk);
31080
- offset += length;
31081
- chunk = data.slice(offset, offset + length);
31082
- }
31083
- return chunks;
31084
- };
31085
- var isPointerType = (type3) => {
31086
- switch (type3) {
31087
- case "u8":
31088
- case "u16":
31089
- case "u32":
31090
- case "u64":
31091
- case "bool": {
31092
- return false;
31093
- }
31094
- default: {
31095
- return true;
31096
- }
31097
- }
31098
- };
31099
- var isHeapType = (type3) => type3 === VEC_CODER_TYPE || type3 === BYTES_CODER_TYPE || type3 === STD_STRING_CODER_TYPE;
31100
- var isMultipleOfWordSize = (length) => length % WORD_SIZE === 0;
31101
- var getWordSizePadding = (length) => WORD_SIZE - length % WORD_SIZE;
31102
- var rightPadToWordSize = (encoded) => {
31103
- if (isMultipleOfWordSize(encoded.length)) {
31104
- return encoded;
31105
- }
31106
- const padding = new Uint8Array(WORD_SIZE - encoded.length % WORD_SIZE);
31107
- return concatBytes2([encoded, padding]);
31108
- };
31109
- var isUint8Array = (value) => value instanceof Uint8Array;
31110
30973
  var ArrayCoder = class extends Coder {
31111
30974
  coder;
31112
30975
  length;
@@ -31122,7 +30985,7 @@ This unreleased fuel-core build may include features and updates not yet support
31122
30985
  if (this.length !== value.length) {
31123
30986
  throw new FuelError(ErrorCode.ENCODE_ERROR, `Types/values length mismatch.`);
31124
30987
  }
31125
- return concatWithDynamicData(Array.from(value).map((v) => this.coder.encode(v)));
30988
+ return concat(Array.from(value).map((v) => this.coder.encode(v)));
31126
30989
  }
31127
30990
  decode(data, offset) {
31128
30991
  if (data.length < this.encodedLength || data.length > MAX_BYTES) {
@@ -31199,16 +31062,42 @@ This unreleased fuel-core build may include features and updates not yet support
31199
31062
  return [toHex(bytes2, this.encodedLength), offset + this.encodedLength];
31200
31063
  }
31201
31064
  };
31065
+ var encodedLengths = {
31066
+ u64: WORD_SIZE,
31067
+ u256: WORD_SIZE * 4
31068
+ };
31069
+ var BigNumberCoder = class extends Coder {
31070
+ constructor(baseType) {
31071
+ super("bigNumber", baseType, encodedLengths[baseType]);
31072
+ }
31073
+ encode(value) {
31074
+ let bytes2;
31075
+ try {
31076
+ bytes2 = toBytes2(value, this.encodedLength);
31077
+ } catch (error) {
31078
+ throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.type}.`);
31079
+ }
31080
+ return bytes2;
31081
+ }
31082
+ decode(data, offset) {
31083
+ if (data.length < this.encodedLength) {
31084
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid ${this.type} data size.`);
31085
+ }
31086
+ let bytes2 = data.slice(offset, offset + this.encodedLength);
31087
+ bytes2 = bytes2.slice(0, this.encodedLength);
31088
+ if (bytes2.length !== this.encodedLength) {
31089
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid ${this.type} byte data size.`);
31090
+ }
31091
+ return [bn(bytes2), offset + this.encodedLength];
31092
+ }
31093
+ };
31202
31094
  var BooleanCoder = class extends Coder {
31203
- paddingLength;
31204
31095
  options;
31205
31096
  constructor(options = {
31206
- isSmallBytes: false,
31207
- isRightPadded: false
31097
+ padToWordSize: false
31208
31098
  }) {
31209
- const paddingLength = options.isSmallBytes ? 1 : 8;
31210
- super("boolean", "boolean", paddingLength);
31211
- this.paddingLength = paddingLength;
31099
+ const encodedLength = options.padToWordSize ? WORD_SIZE : 1;
31100
+ super("boolean", "boolean", encodedLength);
31212
31101
  this.options = options;
31213
31102
  }
31214
31103
  encode(value) {
@@ -31216,73 +31105,45 @@ This unreleased fuel-core build may include features and updates not yet support
31216
31105
  if (!isTrueBool) {
31217
31106
  throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid boolean value.`);
31218
31107
  }
31219
- const output2 = toBytes2(value ? 1 : 0, this.paddingLength);
31220
- if (this.options.isRightPadded) {
31221
- return output2.reverse();
31222
- }
31223
- return output2;
31108
+ return toBytes2(value ? 1 : 0, this.encodedLength);
31224
31109
  }
31225
31110
  decode(data, offset) {
31226
- if (data.length < this.paddingLength) {
31111
+ if (data.length < this.encodedLength) {
31227
31112
  throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid boolean data size.`);
31228
31113
  }
31229
- let bytes2;
31230
- if (this.options.isRightPadded) {
31231
- bytes2 = data.slice(offset, offset + 1);
31232
- } else {
31233
- bytes2 = data.slice(offset, offset + this.paddingLength);
31234
- }
31235
- const decodedValue = bn(bytes2);
31236
- if (decodedValue.isZero()) {
31237
- return [false, offset + this.paddingLength];
31114
+ const bytes2 = bn(data.slice(offset, offset + this.encodedLength));
31115
+ if (bytes2.isZero()) {
31116
+ return [false, offset + this.encodedLength];
31238
31117
  }
31239
- if (!decodedValue.eq(bn(1))) {
31118
+ if (!bytes2.eq(bn(1))) {
31240
31119
  throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid boolean value.`);
31241
31120
  }
31242
- return [true, offset + this.paddingLength];
31121
+ return [true, offset + this.encodedLength];
31243
31122
  }
31244
31123
  };
31245
- var _getPaddedData;
31246
- var getPaddedData_fn;
31247
31124
  var ByteCoder = class extends Coder {
31248
31125
  constructor() {
31249
- super("struct", "struct Bytes", BASE_VECTOR_OFFSET);
31250
- __privateAdd2(this, _getPaddedData);
31126
+ super("struct", "struct Bytes", WORD_SIZE);
31251
31127
  }
31252
31128
  encode(value) {
31253
- const parts = [];
31254
- const pointer = new BigNumberCoder("u64").encode(BASE_VECTOR_OFFSET);
31255
- const data = __privateMethod2(this, _getPaddedData, getPaddedData_fn).call(this, value);
31256
- pointer.dynamicData = {
31257
- 0: concatWithDynamicData([data])
31258
- };
31259
- parts.push(pointer);
31260
- parts.push(new BigNumberCoder("u64").encode(data.byteLength));
31261
- parts.push(new BigNumberCoder("u64").encode(value.length));
31262
- return concatWithDynamicData(parts);
31129
+ const bytes2 = value instanceof Uint8Array ? value : new Uint8Array(value);
31130
+ const lengthBytes = new BigNumberCoder("u64").encode(bytes2.length);
31131
+ return new Uint8Array([...lengthBytes, ...bytes2]);
31263
31132
  }
31264
31133
  decode(data, offset) {
31265
- if (data.length < BASE_VECTOR_OFFSET) {
31134
+ if (data.length < WORD_SIZE) {
31266
31135
  throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid byte data size.`);
31267
31136
  }
31268
- const len = data.slice(16, 24);
31269
- const encodedLength = bn(new BigNumberCoder("u64").decode(len, 0)[0]).toNumber();
31270
- const byteData = data.slice(BASE_VECTOR_OFFSET, BASE_VECTOR_OFFSET + encodedLength);
31271
- if (byteData.length !== encodedLength) {
31137
+ const offsetAndLength = offset + WORD_SIZE;
31138
+ const lengthBytes = data.slice(offset, offsetAndLength);
31139
+ const length = bn(new BigNumberCoder("u64").decode(lengthBytes, 0)[0]).toNumber();
31140
+ const dataBytes = data.slice(offsetAndLength, offsetAndLength + length);
31141
+ if (dataBytes.length !== length) {
31272
31142
  throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid bytes byte data size.`);
31273
31143
  }
31274
- return [byteData, offset + BASE_VECTOR_OFFSET];
31144
+ return [dataBytes, offsetAndLength + length];
31275
31145
  }
31276
31146
  };
31277
- _getPaddedData = /* @__PURE__ */ new WeakSet();
31278
- getPaddedData_fn = function(value) {
31279
- const data = value instanceof Uint8Array ? [value] : [new Uint8Array(value)];
31280
- const paddingLength = (WORD_SIZE - value.length % WORD_SIZE) % WORD_SIZE;
31281
- if (paddingLength) {
31282
- data.push(new Uint8Array(paddingLength));
31283
- }
31284
- return concat(data);
31285
- };
31286
31147
  __publicField4(ByteCoder, "memorySize", 1);
31287
31148
  var isFullyNativeEnum = (enumCoders) => Object.values(enumCoders).every(
31288
31149
  // @ts-expect-error complicated types
@@ -31326,8 +31187,7 @@ This unreleased fuel-core build may include features and updates not yet support
31326
31187
  const valueCoder = this.coders[caseKey];
31327
31188
  const caseIndex = Object.keys(this.coders).indexOf(caseKey);
31328
31189
  const encodedValue = valueCoder.encode(value[caseKey]);
31329
- const padding = new Uint8Array(this.#encodedValueSize - valueCoder.encodedLength);
31330
- return concatWithDynamicData([this.#caseIndexCoder.encode(caseIndex), padding, encodedValue]);
31190
+ return new Uint8Array([...this.#caseIndexCoder.encode(caseIndex), ...encodedValue]);
31331
31191
  }
31332
31192
  #decodeNativeEnum(caseKey, newOffset) {
31333
31193
  return [caseKey, newOffset];
@@ -31336,10 +31196,8 @@ This unreleased fuel-core build may include features and updates not yet support
31336
31196
  if (data.length < this.#encodedValueSize) {
31337
31197
  throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid enum data size.`);
31338
31198
  }
31339
- let newOffset = offset;
31340
- let decoded;
31341
- [decoded, newOffset] = new BigNumberCoder("u64").decode(data, newOffset);
31342
- const caseIndex = toNumber(decoded);
31199
+ const caseBytes = new BigNumberCoder("u64").decode(data, offset)[0];
31200
+ const caseIndex = toNumber(caseBytes);
31343
31201
  const caseKey = Object.keys(this.coders)[caseIndex];
31344
31202
  if (!caseKey) {
31345
31203
  throw new FuelError(
@@ -31348,67 +31206,35 @@ This unreleased fuel-core build may include features and updates not yet support
31348
31206
  );
31349
31207
  }
31350
31208
  const valueCoder = this.coders[caseKey];
31351
- const padding = this.#encodedValueSize - valueCoder.encodedLength;
31352
- newOffset += padding;
31353
- [decoded, newOffset] = valueCoder.decode(data, newOffset);
31209
+ const offsetAndCase = offset + WORD_SIZE;
31210
+ const [decoded, newOffset] = valueCoder.decode(data, offsetAndCase);
31354
31211
  if (isFullyNativeEnum(this.coders)) {
31355
31212
  return this.#decodeNativeEnum(caseKey, newOffset);
31356
31213
  }
31357
31214
  return [{ [caseKey]: decoded }, newOffset];
31358
31215
  }
31359
31216
  };
31360
- var OptionCoder = class extends EnumCoder {
31361
- encode(value) {
31362
- const result = super.encode(this.toSwayOption(value));
31363
- return result;
31364
- }
31365
- toSwayOption(input) {
31366
- if (input !== void 0) {
31367
- return { Some: input };
31368
- }
31369
- return { None: [] };
31370
- }
31371
- decode(data, offset) {
31372
- if (data.length < this.encodedLength) {
31373
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid option data size.`);
31374
- }
31375
- const [decoded, newOffset] = super.decode(data, offset);
31376
- return [this.toOption(decoded), newOffset];
31377
- }
31378
- toOption(output2) {
31379
- if (output2 && "Some" in output2) {
31380
- return output2.Some;
31381
- }
31382
- return void 0;
31217
+ var getLength = (baseType) => {
31218
+ switch (baseType) {
31219
+ case "u8":
31220
+ return 1;
31221
+ case "u16":
31222
+ return 2;
31223
+ case "u32":
31224
+ return 4;
31225
+ default:
31226
+ throw new FuelError(ErrorCode.TYPE_NOT_SUPPORTED, `Invalid number type: ${baseType}`);
31383
31227
  }
31384
31228
  };
31385
31229
  var NumberCoder = class extends Coder {
31386
- // This is to align the bits to the total bytes
31387
- // See https://github.com/FuelLabs/fuel-specs/blob/master/specs/protocol/abi.md#unsigned-integers
31388
- length;
31389
- paddingLength;
31390
31230
  baseType;
31391
31231
  options;
31392
31232
  constructor(baseType, options = {
31393
- isSmallBytes: false,
31394
- isRightPadded: false
31233
+ padToWordSize: false
31395
31234
  }) {
31396
- const paddingLength = options.isSmallBytes && baseType === "u8" ? 1 : 8;
31397
- super("number", baseType, paddingLength);
31235
+ const length = options.padToWordSize ? WORD_SIZE : getLength(baseType);
31236
+ super("number", baseType, length);
31398
31237
  this.baseType = baseType;
31399
- switch (baseType) {
31400
- case "u8":
31401
- this.length = 1;
31402
- break;
31403
- case "u16":
31404
- this.length = 2;
31405
- break;
31406
- case "u32":
31407
- default:
31408
- this.length = 4;
31409
- break;
31410
- }
31411
- this.paddingLength = paddingLength;
31412
31238
  this.options = options;
31413
31239
  }
31414
31240
  encode(value) {
@@ -31418,778 +31244,97 @@ This unreleased fuel-core build may include features and updates not yet support
31418
31244
  } catch (error) {
31419
31245
  throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.baseType}.`);
31420
31246
  }
31421
- if (bytes2.length > this.length) {
31247
+ if (bytes2.length > this.encodedLength) {
31422
31248
  throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.baseType}, too many bytes.`);
31423
31249
  }
31424
- const output2 = toBytes2(bytes2, this.paddingLength);
31425
- if (this.baseType !== "u8") {
31426
- return output2;
31427
- }
31428
- return this.options.isRightPadded ? output2.reverse() : output2;
31429
- }
31430
- decodeU8(data, offset) {
31431
- let bytes2;
31432
- if (this.options.isRightPadded) {
31433
- bytes2 = data.slice(offset, offset + 1);
31434
- } else {
31435
- bytes2 = data.slice(offset, offset + this.paddingLength);
31436
- bytes2 = bytes2.slice(this.paddingLength - this.length, this.paddingLength);
31437
- }
31438
- return [toNumber(bytes2), offset + this.paddingLength];
31250
+ return toBytes2(bytes2, this.encodedLength);
31439
31251
  }
31440
31252
  decode(data, offset) {
31441
- if (data.length < this.paddingLength) {
31253
+ if (data.length < this.encodedLength) {
31442
31254
  throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid number data size.`);
31443
31255
  }
31444
- if (this.baseType === "u8") {
31445
- return this.decodeU8(data, offset);
31446
- }
31447
- let bytes2 = data.slice(offset, offset + this.paddingLength);
31448
- bytes2 = bytes2.slice(8 - this.length, 8);
31449
- if (bytes2.length !== this.paddingLength - (this.paddingLength - this.length)) {
31256
+ const bytes2 = data.slice(offset, offset + this.encodedLength);
31257
+ if (bytes2.length !== this.encodedLength) {
31450
31258
  throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid number byte data size.`);
31451
31259
  }
31452
- return [toNumber(bytes2), offset + 8];
31260
+ return [toNumber(bytes2), offset + this.encodedLength];
31261
+ }
31262
+ };
31263
+ var OptionCoder = class extends EnumCoder {
31264
+ encode(value) {
31265
+ const result = super.encode(this.toSwayOption(value));
31266
+ return result;
31267
+ }
31268
+ toSwayOption(input) {
31269
+ if (input !== void 0) {
31270
+ return { Some: input };
31271
+ }
31272
+ return { None: [] };
31273
+ }
31274
+ decode(data, offset) {
31275
+ const [decoded, newOffset] = super.decode(data, offset);
31276
+ return [this.toOption(decoded), newOffset];
31277
+ }
31278
+ toOption(output2) {
31279
+ if (output2 && "Some" in output2) {
31280
+ return output2.Some;
31281
+ }
31282
+ return void 0;
31453
31283
  }
31454
31284
  };
31455
31285
  var RawSliceCoder = class extends Coder {
31456
31286
  constructor() {
31457
- super("raw untyped slice", "raw untyped slice", BASE_RAW_SLICE_OFFSET);
31287
+ super("raw untyped slice", "raw untyped slice", WORD_SIZE);
31458
31288
  }
31459
31289
  encode(value) {
31460
31290
  if (!Array.isArray(value)) {
31461
31291
  throw new FuelError(ErrorCode.ENCODE_ERROR, `Expected array value.`);
31462
31292
  }
31463
- const parts = [];
31464
- const coder = new NumberCoder("u8", { isSmallBytes: true });
31465
- const pointer = new BigNumberCoder("u64").encode(
31466
- BASE_RAW_SLICE_OFFSET
31467
- );
31468
- pointer.dynamicData = {
31469
- 0: concatWithDynamicData(value.map((v) => coder.encode(v)))
31470
- };
31471
- parts.push(pointer);
31472
- parts.push(new BigNumberCoder("u64").encode(value.length));
31473
- return concatWithDynamicData(parts);
31293
+ const internalCoder = new ArrayCoder(new NumberCoder("u8"), value.length);
31294
+ const bytes2 = internalCoder.encode(value);
31295
+ const lengthBytes = new BigNumberCoder("u64").encode(bytes2.length);
31296
+ return new Uint8Array([...lengthBytes, ...bytes2]);
31474
31297
  }
31475
31298
  decode(data, offset) {
31476
- const dataBytes = data.slice(offset);
31477
- const internalCoder = new ArrayCoder(
31478
- new NumberCoder("u8", { isSmallBytes: true }),
31479
- dataBytes.length
31480
- );
31299
+ if (data.length < this.encodedLength) {
31300
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid raw slice data size.`);
31301
+ }
31302
+ const offsetAndLength = offset + WORD_SIZE;
31303
+ const lengthBytes = data.slice(offset, offsetAndLength);
31304
+ const length = bn(new BigNumberCoder("u64").decode(lengthBytes, 0)[0]).toNumber();
31305
+ const dataBytes = data.slice(offsetAndLength, offsetAndLength + length);
31306
+ if (dataBytes.length !== length) {
31307
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid raw slice byte data size.`);
31308
+ }
31309
+ const internalCoder = new ArrayCoder(new NumberCoder("u8"), length);
31481
31310
  const [decodedValue] = internalCoder.decode(dataBytes, 0);
31482
- return [decodedValue, offset + dataBytes.length];
31311
+ return [decodedValue, offsetAndLength + length];
31483
31312
  }
31484
31313
  };
31485
- var _getPaddedData2;
31486
- var getPaddedData_fn2;
31487
31314
  var StdStringCoder = class extends Coder {
31488
31315
  constructor() {
31489
- super("struct", "struct String", 1);
31490
- __privateAdd2(this, _getPaddedData2);
31316
+ super("struct", "struct String", WORD_SIZE);
31491
31317
  }
31492
31318
  encode(value) {
31493
- const parts = [];
31494
- const pointer = new BigNumberCoder("u64").encode(BASE_VECTOR_OFFSET);
31495
- const data = __privateMethod2(this, _getPaddedData2, getPaddedData_fn2).call(this, value);
31496
- pointer.dynamicData = {
31497
- 0: concatWithDynamicData([data])
31498
- };
31499
- parts.push(pointer);
31500
- parts.push(new BigNumberCoder("u64").encode(data.byteLength));
31501
- parts.push(new BigNumberCoder("u64").encode(value.length));
31502
- return concatWithDynamicData(parts);
31319
+ const bytes2 = toUtf8Bytes(value);
31320
+ const lengthBytes = new BigNumberCoder("u64").encode(value.length);
31321
+ return new Uint8Array([...lengthBytes, ...bytes2]);
31503
31322
  }
31504
31323
  decode(data, offset) {
31505
31324
  if (data.length < this.encodedLength) {
31506
31325
  throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid std string data size.`);
31507
31326
  }
31508
- const len = data.slice(16, 24);
31509
- const encodedLength = bn(new BigNumberCoder("u64").decode(len, 0)[0]).toNumber();
31510
- const byteData = data.slice(BASE_VECTOR_OFFSET, BASE_VECTOR_OFFSET + encodedLength);
31511
- if (byteData.length !== encodedLength) {
31327
+ const offsetAndLength = offset + WORD_SIZE;
31328
+ const lengthBytes = data.slice(offset, offsetAndLength);
31329
+ const length = bn(new BigNumberCoder("u64").decode(lengthBytes, 0)[0]).toNumber();
31330
+ const dataBytes = data.slice(offsetAndLength, offsetAndLength + length);
31331
+ if (dataBytes.length !== length) {
31512
31332
  throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid std string byte data size.`);
31513
31333
  }
31514
- const value = toUtf8String(byteData);
31515
- return [value, offset + BASE_VECTOR_OFFSET];
31334
+ return [toUtf8String(dataBytes), offsetAndLength + length];
31516
31335
  }
31517
31336
  };
31518
- _getPaddedData2 = /* @__PURE__ */ new WeakSet();
31519
- getPaddedData_fn2 = function(value) {
31520
- const data = [toUtf8Bytes(value)];
31521
- const paddingLength = (WORD_SIZE - value.length % WORD_SIZE) % WORD_SIZE;
31522
- if (paddingLength) {
31523
- data.push(new Uint8Array(paddingLength));
31524
- }
31525
- return concat(data);
31526
- };
31527
31337
  __publicField4(StdStringCoder, "memorySize", 1);
31528
- var StringCoder = class extends Coder {
31529
- length;
31530
- #paddingLength;
31531
- constructor(length) {
31532
- let paddingLength = (8 - length) % 8;
31533
- paddingLength = paddingLength < 0 ? paddingLength + 8 : paddingLength;
31534
- super("string", `str[${length}]`, length + paddingLength);
31535
- this.length = length;
31536
- this.#paddingLength = paddingLength;
31537
- }
31538
- encode(value) {
31539
- if (this.length !== value.length) {
31540
- throw new FuelError(ErrorCode.ENCODE_ERROR, `Value length mismatch during encode.`);
31541
- }
31542
- const encoded = toUtf8Bytes(value);
31543
- const padding = new Uint8Array(this.#paddingLength);
31544
- return concat([encoded, padding]);
31545
- }
31546
- decode(data, offset) {
31547
- if (data.length < this.encodedLength) {
31548
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid string data size.`);
31549
- }
31550
- const bytes2 = data.slice(offset, offset + this.length);
31551
- if (bytes2.length !== this.length) {
31552
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid string byte data size.`);
31553
- }
31554
- const value = toUtf8String(bytes2);
31555
- const padding = this.#paddingLength;
31556
- return [value, offset + this.length + padding];
31557
- }
31558
- };
31559
- var StructCoder = class extends Coder {
31560
- name;
31561
- coders;
31562
- constructor(name, coders) {
31563
- const encodedLength = Object.values(coders).reduce(
31564
- (acc, coder) => acc + coder.encodedLength,
31565
- 0
31566
- );
31567
- super("struct", `struct ${name}`, encodedLength);
31568
- this.name = name;
31569
- this.coders = coders;
31570
- }
31571
- encode(value) {
31572
- const encodedFields = Object.keys(this.coders).map((fieldName) => {
31573
- const fieldCoder = this.coders[fieldName];
31574
- const fieldValue = value[fieldName];
31575
- if (!(fieldCoder instanceof OptionCoder) && fieldValue == null) {
31576
- throw new FuelError(
31577
- ErrorCode.ENCODE_ERROR,
31578
- `Invalid ${this.type}. Field "${fieldName}" not present.`
31579
- );
31580
- }
31581
- const encoded = fieldCoder.encode(fieldValue);
31582
- if (!isMultipleOfWordSize(encoded.length)) {
31583
- return rightPadToWordSize(encoded);
31584
- }
31585
- return encoded;
31586
- });
31587
- return concatWithDynamicData([concatWithDynamicData(encodedFields)]);
31588
- }
31589
- decode(data, offset) {
31590
- if (data.length < this.encodedLength) {
31591
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid struct data size.`);
31592
- }
31593
- let newOffset = offset;
31594
- const decodedValue = Object.keys(this.coders).reduce((obj, fieldName) => {
31595
- const fieldCoder = this.coders[fieldName];
31596
- let decoded;
31597
- [decoded, newOffset] = fieldCoder.decode(data, newOffset);
31598
- if (!isMultipleOfWordSize(newOffset)) {
31599
- newOffset += getWordSizePadding(newOffset);
31600
- }
31601
- obj[fieldName] = decoded;
31602
- return obj;
31603
- }, {});
31604
- return [decodedValue, newOffset];
31605
- }
31606
- };
31607
- var TupleCoder = class extends Coder {
31608
- coders;
31609
- constructor(coders) {
31610
- const encodedLength = coders.reduce((acc, coder) => acc + coder.encodedLength, 0);
31611
- super("tuple", `(${coders.map((coder) => coder.type).join(", ")})`, encodedLength);
31612
- this.coders = coders;
31613
- }
31614
- encode(value) {
31615
- if (this.coders.length !== value.length) {
31616
- throw new FuelError(ErrorCode.ENCODE_ERROR, `Types/values length mismatch.`);
31617
- }
31618
- return concatWithDynamicData(
31619
- this.coders.map((coder, i) => {
31620
- const encoded = coder.encode(value[i]);
31621
- if (!isMultipleOfWordSize(encoded.length)) {
31622
- return rightPadToWordSize(encoded);
31623
- }
31624
- return encoded;
31625
- })
31626
- );
31627
- }
31628
- decode(data, offset) {
31629
- if (data.length < this.encodedLength) {
31630
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid tuple data size.`);
31631
- }
31632
- let newOffset = offset;
31633
- const decodedValue = this.coders.map((coder) => {
31634
- let decoded;
31635
- [decoded, newOffset] = coder.decode(data, newOffset);
31636
- if (!isMultipleOfWordSize(newOffset)) {
31637
- newOffset += getWordSizePadding(newOffset);
31638
- }
31639
- return decoded;
31640
- });
31641
- return [decodedValue, newOffset];
31642
- }
31643
- };
31644
- var VecCoder = class extends Coder {
31645
- coder;
31646
- constructor(coder) {
31647
- super("struct", `struct Vec`, coder.encodedLength + BASE_VECTOR_OFFSET);
31648
- this.coder = coder;
31649
- }
31650
- encode(value) {
31651
- if (!Array.isArray(value) && !isUint8Array(value)) {
31652
- throw new FuelError(
31653
- ErrorCode.ENCODE_ERROR,
31654
- `Expected array value, or a Uint8Array. You can use arrayify to convert a value to a Uint8Array.`
31655
- );
31656
- }
31657
- const parts = [];
31658
- const pointer = new BigNumberCoder("u64").encode(BASE_VECTOR_OFFSET);
31659
- pointer.dynamicData = {
31660
- 0: concatWithDynamicData(Array.from(value).map((v) => this.coder.encode(v)))
31661
- };
31662
- parts.push(pointer);
31663
- parts.push(new BigNumberCoder("u64").encode(value.length));
31664
- parts.push(new BigNumberCoder("u64").encode(value.length));
31665
- return concatWithDynamicData(parts);
31666
- }
31667
- decode(data, offset) {
31668
- if (data.length < BASE_VECTOR_OFFSET || data.length > MAX_BYTES) {
31669
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid vec data size.`);
31670
- }
31671
- const len = data.slice(16, 24);
31672
- const encodedLength = bn(new BigNumberCoder("u64").decode(len, 0)[0]).toNumber();
31673
- const vectorRawDataLength = encodedLength * this.coder.encodedLength;
31674
- const vectorRawData = data.slice(BASE_VECTOR_OFFSET, BASE_VECTOR_OFFSET + vectorRawDataLength);
31675
- if (vectorRawData.length !== vectorRawDataLength) {
31676
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid vec byte data size.`);
31677
- }
31678
- return [
31679
- chunkByLength(vectorRawData, this.coder.encodedLength).map(
31680
- (chunk) => this.coder.decode(chunk, 0)[0]
31681
- ),
31682
- offset + BASE_VECTOR_OFFSET
31683
- ];
31684
- }
31685
- };
31686
- var getEncodingVersion = (encoding) => {
31687
- switch (encoding) {
31688
- case void 0:
31689
- case ENCODING_V0:
31690
- return ENCODING_V0;
31691
- case ENCODING_V1:
31692
- return ENCODING_V1;
31693
- default:
31694
- throw new FuelError(
31695
- ErrorCode.UNSUPPORTED_ENCODING_VERSION,
31696
- `Encoding version '${encoding}' is unsupported.`
31697
- );
31698
- }
31699
- };
31700
- var findFunctionByName = (abi, name) => {
31701
- const fn = abi.functions.find((f2) => f2.name === name);
31702
- if (!fn) {
31703
- throw new FuelError(
31704
- ErrorCode.FUNCTION_NOT_FOUND,
31705
- `Function with name '${name}' doesn't exist in the ABI`
31706
- );
31707
- }
31708
- return fn;
31709
- };
31710
- var findTypeById = (abi, typeId) => {
31711
- const type3 = abi.types.find((t) => t.typeId === typeId);
31712
- if (!type3) {
31713
- throw new FuelError(
31714
- ErrorCode.TYPE_NOT_FOUND,
31715
- `Type with typeId '${typeId}' doesn't exist in the ABI.`
31716
- );
31717
- }
31718
- return type3;
31719
- };
31720
- var findNonEmptyInputs = (abi, inputs) => inputs.filter((input) => findTypeById(abi, input.type).type !== "()");
31721
- var findVectorBufferArgument = (components) => {
31722
- const bufferComponent = components.find((c) => c.name === "buf");
31723
- const bufferTypeArgument = bufferComponent?.originalTypeArguments?.[0];
31724
- if (!bufferComponent || !bufferTypeArgument) {
31725
- throw new FuelError(
31726
- ErrorCode.INVALID_COMPONENT,
31727
- `The Vec type provided is missing or has a malformed 'buf' component.`
31728
- );
31729
- }
31730
- return bufferTypeArgument;
31731
- };
31732
- var ResolvedAbiType = class {
31733
- abi;
31734
- name;
31735
- type;
31736
- originalTypeArguments;
31737
- components;
31738
- constructor(abi, argument) {
31739
- this.abi = abi;
31740
- this.name = argument.name;
31741
- const type3 = findTypeById(abi, argument.type);
31742
- this.type = type3.type;
31743
- this.originalTypeArguments = argument.typeArguments;
31744
- this.components = ResolvedAbiType.getResolvedGenericComponents(
31745
- abi,
31746
- argument,
31747
- type3.components,
31748
- type3.typeParameters ?? ResolvedAbiType.getImplicitGenericTypeParameters(abi, type3.components)
31749
- );
31750
- }
31751
- static getResolvedGenericComponents(abi, arg, components, typeParameters) {
31752
- if (components === null) {
31753
- return null;
31754
- }
31755
- if (typeParameters === null || typeParameters.length === 0) {
31756
- return components.map((c) => new ResolvedAbiType(abi, c));
31757
- }
31758
- const typeParametersAndArgsMap = typeParameters.reduce(
31759
- (obj, typeParameter, typeParameterIndex) => {
31760
- const o = { ...obj };
31761
- o[typeParameter] = structuredClone(
31762
- arg.typeArguments?.[typeParameterIndex]
31763
- );
31764
- return o;
31765
- },
31766
- {}
31767
- );
31768
- const resolvedComponents = this.resolveGenericArgTypes(
31769
- abi,
31770
- components,
31771
- typeParametersAndArgsMap
31772
- );
31773
- return resolvedComponents.map((c) => new ResolvedAbiType(abi, c));
31774
- }
31775
- static resolveGenericArgTypes(abi, args, typeParametersAndArgsMap) {
31776
- return args.map((arg) => {
31777
- if (typeParametersAndArgsMap[arg.type] !== void 0) {
31778
- return {
31779
- ...typeParametersAndArgsMap[arg.type],
31780
- name: arg.name
31781
- };
31782
- }
31783
- if (arg.typeArguments) {
31784
- return {
31785
- ...structuredClone(arg),
31786
- typeArguments: this.resolveGenericArgTypes(
31787
- abi,
31788
- arg.typeArguments,
31789
- typeParametersAndArgsMap
31790
- )
31791
- };
31792
- }
31793
- const argType = findTypeById(abi, arg.type);
31794
- const implicitTypeParameters = this.getImplicitGenericTypeParameters(abi, argType.components);
31795
- if (implicitTypeParameters && implicitTypeParameters.length > 0) {
31796
- return {
31797
- ...structuredClone(arg),
31798
- typeArguments: implicitTypeParameters.map((itp) => typeParametersAndArgsMap[itp])
31799
- };
31800
- }
31801
- return arg;
31802
- });
31803
- }
31804
- static getImplicitGenericTypeParameters(abi, args, implicitGenericParametersParam) {
31805
- if (!Array.isArray(args)) {
31806
- return null;
31807
- }
31808
- const implicitGenericParameters = implicitGenericParametersParam ?? [];
31809
- args.forEach((a) => {
31810
- const argType = findTypeById(abi, a.type);
31811
- if (genericRegEx.test(argType.type)) {
31812
- implicitGenericParameters.push(argType.typeId);
31813
- return;
31814
- }
31815
- if (!Array.isArray(a.typeArguments)) {
31816
- return;
31817
- }
31818
- this.getImplicitGenericTypeParameters(abi, a.typeArguments, implicitGenericParameters);
31819
- });
31820
- return implicitGenericParameters.length > 0 ? implicitGenericParameters : null;
31821
- }
31822
- getSignature() {
31823
- const prefix = this.getArgSignaturePrefix();
31824
- const content = this.getArgSignatureContent();
31825
- return `${prefix}${content}`;
31826
- }
31827
- getArgSignaturePrefix() {
31828
- const structMatch = structRegEx.test(this.type);
31829
- if (structMatch) {
31830
- return "s";
31831
- }
31832
- const arrayMatch = arrayRegEx.test(this.type);
31833
- if (arrayMatch) {
31834
- return "a";
31835
- }
31836
- const enumMatch = enumRegEx.test(this.type);
31837
- if (enumMatch) {
31838
- return "e";
31839
- }
31840
- return "";
31841
- }
31842
- getArgSignatureContent() {
31843
- if (this.type === "raw untyped ptr") {
31844
- return "rawptr";
31845
- }
31846
- if (this.type === "raw untyped slice") {
31847
- return "rawslice";
31848
- }
31849
- const strMatch = stringRegEx.exec(this.type)?.groups;
31850
- if (strMatch) {
31851
- return `str[${strMatch.length}]`;
31852
- }
31853
- if (this.components === null) {
31854
- return this.type;
31855
- }
31856
- const arrayMatch = arrayRegEx.exec(this.type)?.groups;
31857
- if (arrayMatch) {
31858
- return `[${this.components[0].getSignature()};${arrayMatch.length}]`;
31859
- }
31860
- const typeArgumentsSignature = this.originalTypeArguments !== null ? `<${this.originalTypeArguments.map((a) => new ResolvedAbiType(this.abi, a).getSignature()).join(",")}>` : "";
31861
- const componentsSignature = `(${this.components.map((c) => c.getSignature()).join(",")})`;
31862
- return `${typeArgumentsSignature}${componentsSignature}`;
31863
- }
31864
- };
31865
- function getCoders(components, options) {
31866
- const { getCoder: getCoder3 } = options;
31867
- return components.reduce((obj, component) => {
31868
- const o = obj;
31869
- o[component.name] = getCoder3(component, options);
31870
- return o;
31871
- }, {});
31872
- }
31873
- var getCoder = (resolvedAbiType, options) => {
31874
- switch (resolvedAbiType.type) {
31875
- case U8_CODER_TYPE:
31876
- case U16_CODER_TYPE:
31877
- case U32_CODER_TYPE:
31878
- return new NumberCoder(resolvedAbiType.type, options);
31879
- case U64_CODER_TYPE:
31880
- case RAW_PTR_CODER_TYPE:
31881
- return new BigNumberCoder("u64");
31882
- case U256_CODER_TYPE:
31883
- return new BigNumberCoder("u256");
31884
- case RAW_SLICE_CODER_TYPE:
31885
- return new RawSliceCoder();
31886
- case BOOL_CODER_TYPE:
31887
- return new BooleanCoder(options);
31888
- case B256_CODER_TYPE:
31889
- return new B256Coder();
31890
- case B512_CODER_TYPE:
31891
- return new B512Coder();
31892
- case BYTES_CODER_TYPE:
31893
- return new ByteCoder();
31894
- case STD_STRING_CODER_TYPE:
31895
- return new StdStringCoder();
31896
- default:
31897
- break;
31898
- }
31899
- const stringMatch = stringRegEx.exec(resolvedAbiType.type)?.groups;
31900
- if (stringMatch) {
31901
- const length = parseInt(stringMatch.length, 10);
31902
- return new StringCoder(length);
31903
- }
31904
- const components = resolvedAbiType.components;
31905
- const arrayMatch = arrayRegEx.exec(resolvedAbiType.type)?.groups;
31906
- if (arrayMatch) {
31907
- const length = parseInt(arrayMatch.length, 10);
31908
- const arg = components[0];
31909
- if (!arg) {
31910
- throw new FuelError(
31911
- ErrorCode.INVALID_COMPONENT,
31912
- `The provided Array type is missing an item of 'component'.`
31913
- );
31914
- }
31915
- const arrayElementCoder = getCoder(arg, { isSmallBytes: true });
31916
- return new ArrayCoder(arrayElementCoder, length);
31917
- }
31918
- if (resolvedAbiType.type === VEC_CODER_TYPE) {
31919
- const arg = findVectorBufferArgument(components);
31920
- const argType = new ResolvedAbiType(resolvedAbiType.abi, arg);
31921
- const itemCoder = getCoder(argType, { isSmallBytes: true, encoding: ENCODING_V0 });
31922
- return new VecCoder(itemCoder);
31923
- }
31924
- const structMatch = structRegEx.exec(resolvedAbiType.type)?.groups;
31925
- if (structMatch) {
31926
- const coders = getCoders(components, { isRightPadded: true, getCoder });
31927
- return new StructCoder(structMatch.name, coders);
31928
- }
31929
- const enumMatch = enumRegEx.exec(resolvedAbiType.type)?.groups;
31930
- if (enumMatch) {
31931
- const coders = getCoders(components, { getCoder });
31932
- const isOptionEnum = resolvedAbiType.type === OPTION_CODER_TYPE;
31933
- if (isOptionEnum) {
31934
- return new OptionCoder(enumMatch.name, coders);
31935
- }
31936
- return new EnumCoder(enumMatch.name, coders);
31937
- }
31938
- const tupleMatch = tupleRegEx.exec(resolvedAbiType.type)?.groups;
31939
- if (tupleMatch) {
31940
- const coders = components.map(
31941
- (component) => getCoder(component, { isRightPadded: true, encoding: ENCODING_V0 })
31942
- );
31943
- return new TupleCoder(coders);
31944
- }
31945
- if (resolvedAbiType.type === STR_SLICE_CODER_TYPE) {
31946
- throw new FuelError(
31947
- ErrorCode.INVALID_DATA,
31948
- "String slices can not be decoded from logs. Convert the slice to `str[N]` with `__to_str_array`"
31949
- );
31950
- }
31951
- throw new FuelError(
31952
- ErrorCode.CODER_NOT_FOUND,
31953
- `Coder not found: ${JSON.stringify(resolvedAbiType)}.`
31954
- );
31955
- };
31956
- var BooleanCoder2 = class extends Coder {
31957
- constructor() {
31958
- super("boolean", "boolean", 1);
31959
- }
31960
- encode(value) {
31961
- const isTrueBool = value === true || value === false;
31962
- if (!isTrueBool) {
31963
- throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid boolean value.`);
31964
- }
31965
- return toBytes2(value ? 1 : 0, this.encodedLength);
31966
- }
31967
- decode(data, offset) {
31968
- if (data.length < this.encodedLength) {
31969
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid boolean data size.`);
31970
- }
31971
- const bytes2 = bn(data.slice(offset, offset + this.encodedLength));
31972
- if (bytes2.isZero()) {
31973
- return [false, offset + this.encodedLength];
31974
- }
31975
- if (!bytes2.eq(bn(1))) {
31976
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid boolean value.`);
31977
- }
31978
- return [true, offset + this.encodedLength];
31979
- }
31980
- };
31981
- var ByteCoder2 = class extends Coder {
31982
- constructor() {
31983
- super("struct", "struct Bytes", WORD_SIZE);
31984
- }
31985
- encode(value) {
31986
- const bytes2 = value instanceof Uint8Array ? value : new Uint8Array(value);
31987
- const lengthBytes = new BigNumberCoder("u64").encode(bytes2.length);
31988
- return new Uint8Array([...lengthBytes, ...bytes2]);
31989
- }
31990
- decode(data, offset) {
31991
- if (data.length < WORD_SIZE) {
31992
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid byte data size.`);
31993
- }
31994
- const offsetAndLength = offset + WORD_SIZE;
31995
- const lengthBytes = data.slice(offset, offsetAndLength);
31996
- const length = bn(new BigNumberCoder("u64").decode(lengthBytes, 0)[0]).toNumber();
31997
- const dataBytes = data.slice(offsetAndLength, offsetAndLength + length);
31998
- if (dataBytes.length !== length) {
31999
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid bytes byte data size.`);
32000
- }
32001
- return [dataBytes, offsetAndLength + length];
32002
- }
32003
- };
32004
- __publicField4(ByteCoder2, "memorySize", 1);
32005
- var isFullyNativeEnum2 = (enumCoders) => Object.values(enumCoders).every(
32006
- // @ts-expect-error complicated types
32007
- ({ type: type3, coders }) => type3 === "()" && JSON.stringify(coders) === JSON.stringify([])
32008
- );
32009
- var EnumCoder2 = class extends Coder {
32010
- name;
32011
- coders;
32012
- #caseIndexCoder;
32013
- #encodedValueSize;
32014
- constructor(name, coders) {
32015
- const caseIndexCoder = new BigNumberCoder("u64");
32016
- const encodedValueSize = Object.values(coders).reduce(
32017
- (max, coder) => Math.max(max, coder.encodedLength),
32018
- 0
32019
- );
32020
- super(`enum ${name}`, `enum ${name}`, caseIndexCoder.encodedLength + encodedValueSize);
32021
- this.name = name;
32022
- this.coders = coders;
32023
- this.#caseIndexCoder = caseIndexCoder;
32024
- this.#encodedValueSize = encodedValueSize;
32025
- }
32026
- #encodeNativeEnum(value) {
32027
- const valueCoder = this.coders[value];
32028
- const encodedValue = valueCoder.encode([]);
32029
- const caseIndex = Object.keys(this.coders).indexOf(value);
32030
- const padding = new Uint8Array(this.#encodedValueSize - valueCoder.encodedLength);
32031
- return concat([this.#caseIndexCoder.encode(caseIndex), padding, encodedValue]);
32032
- }
32033
- encode(value) {
32034
- if (typeof value === "string" && this.coders[value]) {
32035
- return this.#encodeNativeEnum(value);
32036
- }
32037
- const [caseKey, ...empty] = Object.keys(value);
32038
- if (!caseKey) {
32039
- throw new FuelError(ErrorCode.INVALID_DECODE_VALUE, "A field for the case must be provided.");
32040
- }
32041
- if (empty.length !== 0) {
32042
- throw new FuelError(ErrorCode.INVALID_DECODE_VALUE, "Only one field must be provided.");
32043
- }
32044
- const valueCoder = this.coders[caseKey];
32045
- const caseIndex = Object.keys(this.coders).indexOf(caseKey);
32046
- const encodedValue = valueCoder.encode(value[caseKey]);
32047
- return new Uint8Array([...this.#caseIndexCoder.encode(caseIndex), ...encodedValue]);
32048
- }
32049
- #decodeNativeEnum(caseKey, newOffset) {
32050
- return [caseKey, newOffset];
32051
- }
32052
- decode(data, offset) {
32053
- if (data.length < this.#encodedValueSize) {
32054
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid enum data size.`);
32055
- }
32056
- const caseBytes = new BigNumberCoder("u64").decode(data, offset)[0];
32057
- const caseIndex = toNumber(caseBytes);
32058
- const caseKey = Object.keys(this.coders)[caseIndex];
32059
- if (!caseKey) {
32060
- throw new FuelError(
32061
- ErrorCode.INVALID_DECODE_VALUE,
32062
- `Invalid caseIndex "${caseIndex}". Valid cases: ${Object.keys(this.coders)}.`
32063
- );
32064
- }
32065
- const valueCoder = this.coders[caseKey];
32066
- const offsetAndCase = offset + WORD_SIZE;
32067
- const [decoded, newOffset] = valueCoder.decode(data, offsetAndCase);
32068
- if (isFullyNativeEnum2(this.coders)) {
32069
- return this.#decodeNativeEnum(caseKey, newOffset);
32070
- }
32071
- return [{ [caseKey]: decoded }, newOffset];
32072
- }
32073
- };
32074
- var getLength = (baseType) => {
32075
- switch (baseType) {
32076
- case "u8":
32077
- return 1;
32078
- case "u16":
32079
- return 2;
32080
- case "u32":
32081
- return 4;
32082
- default:
32083
- throw new FuelError(ErrorCode.TYPE_NOT_SUPPORTED, `Invalid number type: ${baseType}`);
32084
- }
32085
- };
32086
- var NumberCoder2 = class extends Coder {
32087
- length;
32088
- baseType;
32089
- constructor(baseType) {
32090
- const length = getLength(baseType);
32091
- super("number", baseType, length);
32092
- this.baseType = baseType;
32093
- this.length = length;
32094
- }
32095
- encode(value) {
32096
- let bytes2;
32097
- try {
32098
- bytes2 = toBytes2(value);
32099
- } catch (error) {
32100
- throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.baseType}.`);
32101
- }
32102
- if (bytes2.length > this.length) {
32103
- throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.baseType}, too many bytes.`);
32104
- }
32105
- return toBytes2(bytes2, this.length);
32106
- }
32107
- decode(data, offset) {
32108
- if (data.length < this.encodedLength) {
32109
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid number data size.`);
32110
- }
32111
- const bytes2 = data.slice(offset, offset + this.length);
32112
- if (bytes2.length !== this.encodedLength) {
32113
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid number byte data size.`);
32114
- }
32115
- return [toNumber(bytes2), offset + this.length];
32116
- }
32117
- };
32118
- var OptionCoder2 = class extends EnumCoder2 {
32119
- encode(value) {
32120
- const result = super.encode(this.toSwayOption(value));
32121
- return result;
32122
- }
32123
- toSwayOption(input) {
32124
- if (input !== void 0) {
32125
- return { Some: input };
32126
- }
32127
- return { None: [] };
32128
- }
32129
- decode(data, offset) {
32130
- const [decoded, newOffset] = super.decode(data, offset);
32131
- return [this.toOption(decoded), newOffset];
32132
- }
32133
- toOption(output2) {
32134
- if (output2 && "Some" in output2) {
32135
- return output2.Some;
32136
- }
32137
- return void 0;
32138
- }
32139
- };
32140
- var RawSliceCoder2 = class extends Coder {
32141
- constructor() {
32142
- super("raw untyped slice", "raw untyped slice", WORD_SIZE);
32143
- }
32144
- encode(value) {
32145
- if (!Array.isArray(value)) {
32146
- throw new FuelError(ErrorCode.ENCODE_ERROR, `Expected array value.`);
32147
- }
32148
- const internalCoder = new ArrayCoder(new NumberCoder2("u8"), value.length);
32149
- const bytes2 = internalCoder.encode(value);
32150
- const lengthBytes = new BigNumberCoder("u64").encode(bytes2.length);
32151
- return new Uint8Array([...lengthBytes, ...bytes2]);
32152
- }
32153
- decode(data, offset) {
32154
- if (data.length < this.encodedLength) {
32155
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid raw slice data size.`);
32156
- }
32157
- const offsetAndLength = offset + WORD_SIZE;
32158
- const lengthBytes = data.slice(offset, offsetAndLength);
32159
- const length = bn(new BigNumberCoder("u64").decode(lengthBytes, 0)[0]).toNumber();
32160
- const dataBytes = data.slice(offsetAndLength, offsetAndLength + length);
32161
- if (dataBytes.length !== length) {
32162
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid raw slice byte data size.`);
32163
- }
32164
- const internalCoder = new ArrayCoder(new NumberCoder2("u8"), length);
32165
- const [decodedValue] = internalCoder.decode(dataBytes, 0);
32166
- return [decodedValue, offsetAndLength + length];
32167
- }
32168
- };
32169
- var StdStringCoder2 = class extends Coder {
32170
- constructor() {
32171
- super("struct", "struct String", WORD_SIZE);
32172
- }
32173
- encode(value) {
32174
- const bytes2 = toUtf8Bytes(value);
32175
- const lengthBytes = new BigNumberCoder("u64").encode(value.length);
32176
- return new Uint8Array([...lengthBytes, ...bytes2]);
32177
- }
32178
- decode(data, offset) {
32179
- if (data.length < this.encodedLength) {
32180
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid std string data size.`);
32181
- }
32182
- const offsetAndLength = offset + WORD_SIZE;
32183
- const lengthBytes = data.slice(offset, offsetAndLength);
32184
- const length = bn(new BigNumberCoder("u64").decode(lengthBytes, 0)[0]).toNumber();
32185
- const dataBytes = data.slice(offsetAndLength, offsetAndLength + length);
32186
- if (dataBytes.length !== length) {
32187
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid std string byte data size.`);
32188
- }
32189
- return [toUtf8String(dataBytes), offsetAndLength + length];
32190
- }
32191
- };
32192
- __publicField4(StdStringCoder2, "memorySize", 1);
32193
31338
  var StrSliceCoder = class extends Coder {
32194
31339
  constructor() {
32195
31340
  super("strSlice", "str", WORD_SIZE);
@@ -32214,7 +31359,7 @@ This unreleased fuel-core build may include features and updates not yet support
32214
31359
  }
32215
31360
  };
32216
31361
  __publicField4(StrSliceCoder, "memorySize", 1);
32217
- var StringCoder2 = class extends Coder {
31362
+ var StringCoder = class extends Coder {
32218
31363
  constructor(length) {
32219
31364
  super("string", `str[${length}]`, length);
32220
31365
  }
@@ -32235,7 +31380,7 @@ This unreleased fuel-core build may include features and updates not yet support
32235
31380
  return [toUtf8String(bytes2), offset + this.encodedLength];
32236
31381
  }
32237
31382
  };
32238
- var StructCoder2 = class extends Coder {
31383
+ var StructCoder = class extends Coder {
32239
31384
  name;
32240
31385
  coders;
32241
31386
  constructor(name, coders) {
@@ -32252,7 +31397,7 @@ This unreleased fuel-core build may include features and updates not yet support
32252
31397
  Object.keys(this.coders).map((fieldName) => {
32253
31398
  const fieldCoder = this.coders[fieldName];
32254
31399
  const fieldValue = value[fieldName];
32255
- if (!(fieldCoder instanceof OptionCoder2) && fieldValue == null) {
31400
+ if (!(fieldCoder instanceof OptionCoder) && fieldValue == null) {
32256
31401
  throw new FuelError(
32257
31402
  ErrorCode.ENCODE_ERROR,
32258
31403
  `Invalid ${this.type}. Field "${fieldName}" not present.`
@@ -32277,7 +31422,7 @@ This unreleased fuel-core build may include features and updates not yet support
32277
31422
  return [decodedValue, newOffset];
32278
31423
  }
32279
31424
  };
32280
- var TupleCoder2 = class extends Coder {
31425
+ var TupleCoder = class extends Coder {
32281
31426
  coders;
32282
31427
  constructor(coders) {
32283
31428
  const encodedLength = coders.reduce((acc, coder) => acc + coder.encodedLength, 0);
@@ -32303,13 +31448,14 @@ This unreleased fuel-core build may include features and updates not yet support
32303
31448
  return [decodedValue, newOffset];
32304
31449
  }
32305
31450
  };
32306
- var VecCoder2 = class extends Coder {
31451
+ var isUint8Array = (value) => value instanceof Uint8Array;
31452
+ var VecCoder = class extends Coder {
32307
31453
  coder;
32308
31454
  #isOptionVec;
32309
31455
  constructor(coder) {
32310
31456
  super("struct", `struct Vec`, coder.encodedLength + WORD_SIZE);
32311
31457
  this.coder = coder;
32312
- this.#isOptionVec = this.coder instanceof OptionCoder2;
31458
+ this.#isOptionVec = this.coder instanceof OptionCoder;
32313
31459
  }
32314
31460
  encode(value) {
32315
31461
  if (!Array.isArray(value) && !isUint8Array(value)) {
@@ -32348,29 +31494,214 @@ This unreleased fuel-core build may include features and updates not yet support
32348
31494
  return [chunks, newOffset];
32349
31495
  }
32350
31496
  };
32351
- var getCoder2 = (resolvedAbiType, _options) => {
31497
+ var getEncodingVersion = (encoding) => {
31498
+ switch (encoding) {
31499
+ case void 0:
31500
+ case ENCODING_V1:
31501
+ return ENCODING_V1;
31502
+ default:
31503
+ throw new FuelError(
31504
+ ErrorCode.UNSUPPORTED_ENCODING_VERSION,
31505
+ `Encoding version '${encoding}' is unsupported.`
31506
+ );
31507
+ }
31508
+ };
31509
+ var findFunctionByName = (abi, name) => {
31510
+ const fn = abi.functions.find((f2) => f2.name === name);
31511
+ if (!fn) {
31512
+ throw new FuelError(
31513
+ ErrorCode.FUNCTION_NOT_FOUND,
31514
+ `Function with name '${name}' doesn't exist in the ABI`
31515
+ );
31516
+ }
31517
+ return fn;
31518
+ };
31519
+ var findTypeById = (abi, typeId) => {
31520
+ const type3 = abi.types.find((t) => t.typeId === typeId);
31521
+ if (!type3) {
31522
+ throw new FuelError(
31523
+ ErrorCode.TYPE_NOT_FOUND,
31524
+ `Type with typeId '${typeId}' doesn't exist in the ABI.`
31525
+ );
31526
+ }
31527
+ return type3;
31528
+ };
31529
+ var findNonEmptyInputs = (abi, inputs) => inputs.filter((input) => findTypeById(abi, input.type).type !== "()");
31530
+ var findVectorBufferArgument = (components) => {
31531
+ const bufferComponent = components.find((c) => c.name === "buf");
31532
+ const bufferTypeArgument = bufferComponent?.originalTypeArguments?.[0];
31533
+ if (!bufferComponent || !bufferTypeArgument) {
31534
+ throw new FuelError(
31535
+ ErrorCode.INVALID_COMPONENT,
31536
+ `The Vec type provided is missing or has a malformed 'buf' component.`
31537
+ );
31538
+ }
31539
+ return bufferTypeArgument;
31540
+ };
31541
+ var ResolvedAbiType = class {
31542
+ abi;
31543
+ name;
31544
+ type;
31545
+ originalTypeArguments;
31546
+ components;
31547
+ constructor(abi, argument) {
31548
+ this.abi = abi;
31549
+ this.name = argument.name;
31550
+ const type3 = findTypeById(abi, argument.type);
31551
+ this.type = type3.type;
31552
+ this.originalTypeArguments = argument.typeArguments;
31553
+ this.components = ResolvedAbiType.getResolvedGenericComponents(
31554
+ abi,
31555
+ argument,
31556
+ type3.components,
31557
+ type3.typeParameters ?? ResolvedAbiType.getImplicitGenericTypeParameters(abi, type3.components)
31558
+ );
31559
+ }
31560
+ static getResolvedGenericComponents(abi, arg, components, typeParameters) {
31561
+ if (components === null) {
31562
+ return null;
31563
+ }
31564
+ if (typeParameters === null || typeParameters.length === 0) {
31565
+ return components.map((c) => new ResolvedAbiType(abi, c));
31566
+ }
31567
+ const typeParametersAndArgsMap = typeParameters.reduce(
31568
+ (obj, typeParameter, typeParameterIndex) => {
31569
+ const o = { ...obj };
31570
+ o[typeParameter] = structuredClone(
31571
+ arg.typeArguments?.[typeParameterIndex]
31572
+ );
31573
+ return o;
31574
+ },
31575
+ {}
31576
+ );
31577
+ const resolvedComponents = this.resolveGenericArgTypes(
31578
+ abi,
31579
+ components,
31580
+ typeParametersAndArgsMap
31581
+ );
31582
+ return resolvedComponents.map((c) => new ResolvedAbiType(abi, c));
31583
+ }
31584
+ static resolveGenericArgTypes(abi, args, typeParametersAndArgsMap) {
31585
+ return args.map((arg) => {
31586
+ if (typeParametersAndArgsMap[arg.type] !== void 0) {
31587
+ return {
31588
+ ...typeParametersAndArgsMap[arg.type],
31589
+ name: arg.name
31590
+ };
31591
+ }
31592
+ if (arg.typeArguments) {
31593
+ return {
31594
+ ...structuredClone(arg),
31595
+ typeArguments: this.resolveGenericArgTypes(
31596
+ abi,
31597
+ arg.typeArguments,
31598
+ typeParametersAndArgsMap
31599
+ )
31600
+ };
31601
+ }
31602
+ const argType = findTypeById(abi, arg.type);
31603
+ const implicitTypeParameters = this.getImplicitGenericTypeParameters(abi, argType.components);
31604
+ if (implicitTypeParameters && implicitTypeParameters.length > 0) {
31605
+ return {
31606
+ ...structuredClone(arg),
31607
+ typeArguments: implicitTypeParameters.map((itp) => typeParametersAndArgsMap[itp])
31608
+ };
31609
+ }
31610
+ return arg;
31611
+ });
31612
+ }
31613
+ static getImplicitGenericTypeParameters(abi, args, implicitGenericParametersParam) {
31614
+ if (!Array.isArray(args)) {
31615
+ return null;
31616
+ }
31617
+ const implicitGenericParameters = implicitGenericParametersParam ?? [];
31618
+ args.forEach((a) => {
31619
+ const argType = findTypeById(abi, a.type);
31620
+ if (genericRegEx.test(argType.type)) {
31621
+ implicitGenericParameters.push(argType.typeId);
31622
+ return;
31623
+ }
31624
+ if (!Array.isArray(a.typeArguments)) {
31625
+ return;
31626
+ }
31627
+ this.getImplicitGenericTypeParameters(abi, a.typeArguments, implicitGenericParameters);
31628
+ });
31629
+ return implicitGenericParameters.length > 0 ? implicitGenericParameters : null;
31630
+ }
31631
+ getSignature() {
31632
+ const prefix = this.getArgSignaturePrefix();
31633
+ const content = this.getArgSignatureContent();
31634
+ return `${prefix}${content}`;
31635
+ }
31636
+ getArgSignaturePrefix() {
31637
+ const structMatch = structRegEx.test(this.type);
31638
+ if (structMatch) {
31639
+ return "s";
31640
+ }
31641
+ const arrayMatch = arrayRegEx.test(this.type);
31642
+ if (arrayMatch) {
31643
+ return "a";
31644
+ }
31645
+ const enumMatch = enumRegEx.test(this.type);
31646
+ if (enumMatch) {
31647
+ return "e";
31648
+ }
31649
+ return "";
31650
+ }
31651
+ getArgSignatureContent() {
31652
+ if (this.type === "raw untyped ptr") {
31653
+ return "rawptr";
31654
+ }
31655
+ if (this.type === "raw untyped slice") {
31656
+ return "rawslice";
31657
+ }
31658
+ const strMatch = stringRegEx.exec(this.type)?.groups;
31659
+ if (strMatch) {
31660
+ return `str[${strMatch.length}]`;
31661
+ }
31662
+ if (this.components === null) {
31663
+ return this.type;
31664
+ }
31665
+ const arrayMatch = arrayRegEx.exec(this.type)?.groups;
31666
+ if (arrayMatch) {
31667
+ return `[${this.components[0].getSignature()};${arrayMatch.length}]`;
31668
+ }
31669
+ const typeArgumentsSignature = this.originalTypeArguments !== null ? `<${this.originalTypeArguments.map((a) => new ResolvedAbiType(this.abi, a).getSignature()).join(",")}>` : "";
31670
+ const componentsSignature = `(${this.components.map((c) => c.getSignature()).join(",")})`;
31671
+ return `${typeArgumentsSignature}${componentsSignature}`;
31672
+ }
31673
+ };
31674
+ function getCoders(components, options) {
31675
+ const { getCoder: getCoder2 } = options;
31676
+ return components.reduce((obj, component) => {
31677
+ const o = obj;
31678
+ o[component.name] = getCoder2(component, options);
31679
+ return o;
31680
+ }, {});
31681
+ }
31682
+ var getCoder = (resolvedAbiType, _options) => {
32352
31683
  switch (resolvedAbiType.type) {
32353
31684
  case U8_CODER_TYPE:
32354
31685
  case U16_CODER_TYPE:
32355
31686
  case U32_CODER_TYPE:
32356
- return new NumberCoder2(resolvedAbiType.type);
31687
+ return new NumberCoder(resolvedAbiType.type);
32357
31688
  case U64_CODER_TYPE:
32358
31689
  case RAW_PTR_CODER_TYPE:
32359
31690
  return new BigNumberCoder("u64");
32360
31691
  case U256_CODER_TYPE:
32361
31692
  return new BigNumberCoder("u256");
32362
31693
  case RAW_SLICE_CODER_TYPE:
32363
- return new RawSliceCoder2();
31694
+ return new RawSliceCoder();
32364
31695
  case BOOL_CODER_TYPE:
32365
- return new BooleanCoder2();
31696
+ return new BooleanCoder();
32366
31697
  case B256_CODER_TYPE:
32367
31698
  return new B256Coder();
32368
31699
  case B512_CODER_TYPE:
32369
31700
  return new B512Coder();
32370
31701
  case BYTES_CODER_TYPE:
32371
- return new ByteCoder2();
31702
+ return new ByteCoder();
32372
31703
  case STD_STRING_CODER_TYPE:
32373
- return new StdStringCoder2();
31704
+ return new StdStringCoder();
32374
31705
  case STR_SLICE_CODER_TYPE:
32375
31706
  return new StrSliceCoder();
32376
31707
  default:
@@ -32379,7 +31710,7 @@ This unreleased fuel-core build may include features and updates not yet support
32379
31710
  const stringMatch = stringRegEx.exec(resolvedAbiType.type)?.groups;
32380
31711
  if (stringMatch) {
32381
31712
  const length = parseInt(stringMatch.length, 10);
32382
- return new StringCoder2(length);
31713
+ return new StringCoder(length);
32383
31714
  }
32384
31715
  const components = resolvedAbiType.components;
32385
31716
  const arrayMatch = arrayRegEx.exec(resolvedAbiType.type)?.groups;
@@ -32392,46 +31723,42 @@ This unreleased fuel-core build may include features and updates not yet support
32392
31723
  `The provided Array type is missing an item of 'component'.`
32393
31724
  );
32394
31725
  }
32395
- const arrayElementCoder = getCoder2(arg, { isSmallBytes: true });
31726
+ const arrayElementCoder = getCoder(arg);
32396
31727
  return new ArrayCoder(arrayElementCoder, length);
32397
31728
  }
32398
31729
  if (resolvedAbiType.type === VEC_CODER_TYPE) {
32399
31730
  const arg = findVectorBufferArgument(components);
32400
31731
  const argType = new ResolvedAbiType(resolvedAbiType.abi, arg);
32401
- const itemCoder = getCoder2(argType, { isSmallBytes: true, encoding: ENCODING_V0 });
32402
- return new VecCoder2(itemCoder);
31732
+ const itemCoder = getCoder(argType, { encoding: ENCODING_V1 });
31733
+ return new VecCoder(itemCoder);
32403
31734
  }
32404
31735
  const structMatch = structRegEx.exec(resolvedAbiType.type)?.groups;
32405
31736
  if (structMatch) {
32406
- const coders = getCoders(components, { isRightPadded: true, getCoder: getCoder2 });
32407
- return new StructCoder2(structMatch.name, coders);
31737
+ const coders = getCoders(components, { getCoder });
31738
+ return new StructCoder(structMatch.name, coders);
32408
31739
  }
32409
31740
  const enumMatch = enumRegEx.exec(resolvedAbiType.type)?.groups;
32410
31741
  if (enumMatch) {
32411
- const coders = getCoders(components, { getCoder: getCoder2 });
31742
+ const coders = getCoders(components, { getCoder });
32412
31743
  const isOptionEnum = resolvedAbiType.type === OPTION_CODER_TYPE;
32413
31744
  if (isOptionEnum) {
32414
- return new OptionCoder2(enumMatch.name, coders);
31745
+ return new OptionCoder(enumMatch.name, coders);
32415
31746
  }
32416
- return new EnumCoder2(enumMatch.name, coders);
31747
+ return new EnumCoder(enumMatch.name, coders);
32417
31748
  }
32418
31749
  const tupleMatch = tupleRegEx.exec(resolvedAbiType.type)?.groups;
32419
31750
  if (tupleMatch) {
32420
- const coders = components.map(
32421
- (component) => getCoder2(component, { isRightPadded: true, encoding: ENCODING_V0 })
32422
- );
32423
- return new TupleCoder2(coders);
31751
+ const coders = components.map((component) => getCoder(component, { encoding: ENCODING_V1 }));
31752
+ return new TupleCoder(coders);
32424
31753
  }
32425
31754
  throw new FuelError(
32426
31755
  ErrorCode.CODER_NOT_FOUND,
32427
31756
  `Coder not found: ${JSON.stringify(resolvedAbiType)}.`
32428
31757
  );
32429
31758
  };
32430
- function getCoderForEncoding(encoding = ENCODING_V0) {
31759
+ function getCoderForEncoding(encoding = ENCODING_V1) {
32431
31760
  switch (encoding) {
32432
31761
  case ENCODING_V1:
32433
- return getCoder2;
32434
- case ENCODING_V0:
32435
31762
  return getCoder;
32436
31763
  default:
32437
31764
  throw new FuelError(
@@ -32442,7 +31769,7 @@ This unreleased fuel-core build may include features and updates not yet support
32442
31769
  }
32443
31770
  var AbiCoder = class {
32444
31771
  static getCoder(abi, argument, options = {
32445
- isSmallBytes: false
31772
+ padToWordSize: false
32446
31773
  }) {
32447
31774
  const resolvedAbiType = new ResolvedAbiType(abi, argument);
32448
31775
  return getCoderForEncoding(options.encoding)(resolvedAbiType, options);
@@ -32462,8 +31789,6 @@ This unreleased fuel-core build may include features and updates not yet support
32462
31789
  name;
32463
31790
  jsonFn;
32464
31791
  attributes;
32465
- isInputDataPointer;
32466
- outputMetadata;
32467
31792
  jsonAbi;
32468
31793
  constructor(jsonAbi, name) {
32469
31794
  this.jsonAbi = jsonAbi;
@@ -32471,13 +31796,8 @@ This unreleased fuel-core build may include features and updates not yet support
32471
31796
  this.name = name;
32472
31797
  this.signature = FunctionFragment.getSignature(this.jsonAbi, this.jsonFn);
32473
31798
  this.selector = FunctionFragment.getFunctionSelector(this.signature);
32474
- this.selectorBytes = new StdStringCoder2().encode(name);
31799
+ this.selectorBytes = new StdStringCoder().encode(name);
32475
31800
  this.encoding = getEncodingVersion(jsonAbi.encoding);
32476
- this.isInputDataPointer = this.#isInputDataPointer();
32477
- this.outputMetadata = {
32478
- isHeapType: this.#isOutputDataHeap(),
32479
- encodedLength: this.#getOutputEncodedLength()
32480
- };
32481
31801
  this.attributes = this.jsonFn.attributes ?? [];
32482
31802
  }
32483
31803
  static getSignature(abi, fn) {
@@ -32490,29 +31810,7 @@ This unreleased fuel-core build may include features and updates not yet support
32490
31810
  const hashedFunctionSignature = sha2562(bufferFromString2(functionSignature, "utf-8"));
32491
31811
  return bn(hashedFunctionSignature.slice(0, 10)).toHex(8);
32492
31812
  }
32493
- #isInputDataPointer() {
32494
- const inputTypes = this.jsonFn.inputs.map((i) => findTypeById(this.jsonAbi, i.type));
32495
- return this.jsonFn.inputs.length > 1 || isPointerType(inputTypes[0]?.type || "");
32496
- }
32497
- #isOutputDataHeap() {
32498
- const outputType = findTypeById(this.jsonAbi, this.jsonFn.output.type);
32499
- return isHeapType(outputType?.type || "");
32500
- }
32501
- #getOutputEncodedLength() {
32502
- try {
32503
- const heapCoder = AbiCoder.getCoder(this.jsonAbi, this.jsonFn.output);
32504
- if (heapCoder instanceof VecCoder) {
32505
- return heapCoder.coder.encodedLength;
32506
- }
32507
- if (heapCoder instanceof ByteCoder) {
32508
- return ByteCoder.memorySize;
32509
- }
32510
- return heapCoder.encodedLength;
32511
- } catch (e) {
32512
- return 0;
32513
- }
32514
- }
32515
- encodeArguments(values, offset = 0) {
31813
+ encodeArguments(values) {
32516
31814
  FunctionFragment.verifyArgsAndInputsAlign(values, this.jsonFn.inputs, this.jsonAbi);
32517
31815
  const shallowCopyValues = values.slice();
32518
31816
  const nonEmptyInputs = findNonEmptyInputs(this.jsonAbi, this.jsonFn.inputs);
@@ -32522,15 +31820,10 @@ This unreleased fuel-core build may include features and updates not yet support
32522
31820
  }
32523
31821
  const coders = nonEmptyInputs.map(
32524
31822
  (t) => AbiCoder.getCoder(this.jsonAbi, t, {
32525
- isRightPadded: nonEmptyInputs.length > 1,
32526
31823
  encoding: this.encoding
32527
31824
  })
32528
31825
  );
32529
- if (this.encoding === ENCODING_V1) {
32530
- return new TupleCoder2(coders).encode(shallowCopyValues);
32531
- }
32532
- const results = new TupleCoder(coders).encode(shallowCopyValues);
32533
- return unpackDynamicData(results, offset, results.byteLength);
31826
+ return new TupleCoder(coders).encode(shallowCopyValues);
32534
31827
  }
32535
31828
  static verifyArgsAndInputsAlign(args, inputs, abi) {
32536
31829
  if (args.length === inputs.length) {
@@ -32639,9 +31932,9 @@ This unreleased fuel-core build may include features and updates not yet support
32639
31932
  const fragment = typeof functionFragment === "string" ? this.getFunction(functionFragment) : functionFragment;
32640
31933
  return fragment.decodeArguments(data);
32641
31934
  }
32642
- encodeFunctionData(functionFragment, values, offset = 0) {
31935
+ encodeFunctionData(functionFragment, values) {
32643
31936
  const fragment = typeof functionFragment === "string" ? this.getFunction(functionFragment) : functionFragment;
32644
- return fragment.encodeArguments(values, offset);
31937
+ return fragment.encodeArguments(values);
32645
31938
  }
32646
31939
  // Decode the result of a function call
32647
31940
  decodeFunctionResult(functionFragment, data) {
@@ -32669,9 +31962,7 @@ This unreleased fuel-core build may include features and updates not yet support
32669
31962
  );
32670
31963
  }
32671
31964
  return AbiCoder.encode(this.jsonAbi, configurable.configurableType, value, {
32672
- isRightPadded: true,
32673
- // TODO: Review support for configurables in v1 encoding when it becomes available
32674
- encoding: ENCODING_V0
31965
+ encoding: this.encoding
32675
31966
  });
32676
31967
  }
32677
31968
  getTypeById(typeId) {
@@ -32721,8 +32012,8 @@ This unreleased fuel-core build may include features and updates not yet support
32721
32012
  var TxPointerCoder = class extends StructCoder {
32722
32013
  constructor() {
32723
32014
  super("TxPointer", {
32724
- blockHeight: new NumberCoder("u32"),
32725
- txIndex: new NumberCoder("u16")
32015
+ blockHeight: new NumberCoder("u32", { padToWordSize: true }),
32016
+ txIndex: new NumberCoder("u16", { padToWordSize: true })
32726
32017
  });
32727
32018
  }
32728
32019
  };
@@ -32739,12 +32030,12 @@ This unreleased fuel-core build may include features and updates not yet support
32739
32030
  encode(value) {
32740
32031
  const parts = [];
32741
32032
  parts.push(new B256Coder().encode(value.txID));
32742
- parts.push(new NumberCoder("u16").encode(value.outputIndex));
32033
+ parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.outputIndex));
32743
32034
  parts.push(new B256Coder().encode(value.owner));
32744
32035
  parts.push(new BigNumberCoder("u64").encode(value.amount));
32745
32036
  parts.push(new B256Coder().encode(value.assetId));
32746
32037
  parts.push(new TxPointerCoder().encode(value.txPointer));
32747
- parts.push(new NumberCoder("u16").encode(value.witnessIndex));
32038
+ parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.witnessIndex));
32748
32039
  parts.push(new BigNumberCoder("u64").encode(value.predicateGasUsed));
32749
32040
  parts.push(new BigNumberCoder("u64").encode(value.predicateLength));
32750
32041
  parts.push(new BigNumberCoder("u64").encode(value.predicateDataLength));
@@ -32759,7 +32050,7 @@ This unreleased fuel-core build may include features and updates not yet support
32759
32050
  let o = offset;
32760
32051
  [decoded, o] = new B256Coder().decode(data, o);
32761
32052
  const txID = decoded;
32762
- [decoded, o] = new NumberCoder("u16").decode(data, o);
32053
+ [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
32763
32054
  const outputIndex = decoded;
32764
32055
  [decoded, o] = new B256Coder().decode(data, o);
32765
32056
  const owner = decoded;
@@ -32769,7 +32060,7 @@ This unreleased fuel-core build may include features and updates not yet support
32769
32060
  const assetId = decoded;
32770
32061
  [decoded, o] = new TxPointerCoder().decode(data, o);
32771
32062
  const txPointer = decoded;
32772
- [decoded, o] = new NumberCoder("u16").decode(data, o);
32063
+ [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
32773
32064
  const witnessIndex = Number(decoded);
32774
32065
  [decoded, o] = new BigNumberCoder("u64").decode(data, o);
32775
32066
  const predicateGasUsed = decoded;
@@ -32808,7 +32099,7 @@ This unreleased fuel-core build may include features and updates not yet support
32808
32099
  encode(value) {
32809
32100
  const parts = [];
32810
32101
  parts.push(new B256Coder().encode(value.txID));
32811
- parts.push(new NumberCoder("u16").encode(value.outputIndex));
32102
+ parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.outputIndex));
32812
32103
  parts.push(new B256Coder().encode(value.balanceRoot));
32813
32104
  parts.push(new B256Coder().encode(value.stateRoot));
32814
32105
  parts.push(new TxPointerCoder().encode(value.txPointer));
@@ -32820,7 +32111,7 @@ This unreleased fuel-core build may include features and updates not yet support
32820
32111
  let o = offset;
32821
32112
  [decoded, o] = new B256Coder().decode(data, o);
32822
32113
  const txID = decoded;
32823
- [decoded, o] = new NumberCoder("u16").decode(data, o);
32114
+ [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
32824
32115
  const outputIndex = decoded;
32825
32116
  [decoded, o] = new B256Coder().decode(data, o);
32826
32117
  const balanceRoot = decoded;
@@ -32869,7 +32160,7 @@ This unreleased fuel-core build may include features and updates not yet support
32869
32160
  parts.push(new ByteArrayCoder(32).encode(value.recipient));
32870
32161
  parts.push(new BigNumberCoder("u64").encode(value.amount));
32871
32162
  parts.push(new ByteArrayCoder(32).encode(value.nonce));
32872
- parts.push(new NumberCoder("u16").encode(value.witnessIndex));
32163
+ parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.witnessIndex));
32873
32164
  parts.push(new BigNumberCoder("u64").encode(value.predicateGasUsed));
32874
32165
  parts.push(new BigNumberCoder("u64").encode(data.length));
32875
32166
  parts.push(new BigNumberCoder("u64").encode(value.predicateLength));
@@ -32898,11 +32189,11 @@ This unreleased fuel-core build may include features and updates not yet support
32898
32189
  const amount = decoded;
32899
32190
  [decoded, o] = new B256Coder().decode(data, o);
32900
32191
  const nonce = decoded;
32901
- [decoded, o] = new NumberCoder("u16").decode(data, o);
32192
+ [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
32902
32193
  const witnessIndex = Number(decoded);
32903
32194
  [decoded, o] = new BigNumberCoder("u64").decode(data, o);
32904
32195
  const predicateGasUsed = decoded;
32905
- [decoded, o] = new NumberCoder("u32").decode(data, o);
32196
+ [decoded, o] = new NumberCoder("u32", { padToWordSize: true }).decode(data, o);
32906
32197
  const dataLength = decoded;
32907
32198
  [decoded, o] = new BigNumberCoder("u64").decode(data, o);
32908
32199
  const predicateLength = decoded;
@@ -32940,7 +32231,7 @@ This unreleased fuel-core build may include features and updates not yet support
32940
32231
  }
32941
32232
  encode(value) {
32942
32233
  const parts = [];
32943
- parts.push(new NumberCoder("u8").encode(value.type));
32234
+ parts.push(new NumberCoder("u8", { padToWordSize: true }).encode(value.type));
32944
32235
  const { type: type3 } = value;
32945
32236
  switch (type3) {
32946
32237
  case 0: {
@@ -32967,7 +32258,7 @@ This unreleased fuel-core build may include features and updates not yet support
32967
32258
  decode(data, offset) {
32968
32259
  let decoded;
32969
32260
  let o = offset;
32970
- [decoded, o] = new NumberCoder("u8").decode(data, o);
32261
+ [decoded, o] = new NumberCoder("u8", { padToWordSize: true }).decode(data, o);
32971
32262
  const type3 = decoded;
32972
32263
  switch (type3) {
32973
32264
  case 0: {
@@ -33036,7 +32327,7 @@ This unreleased fuel-core build may include features and updates not yet support
33036
32327
  }
33037
32328
  encode(value) {
33038
32329
  const parts = [];
33039
- parts.push(new NumberCoder("u8").encode(value.inputIndex));
32330
+ parts.push(new NumberCoder("u8", { padToWordSize: true }).encode(value.inputIndex));
33040
32331
  parts.push(new B256Coder().encode(value.balanceRoot));
33041
32332
  parts.push(new B256Coder().encode(value.stateRoot));
33042
32333
  return concat(parts);
@@ -33044,7 +32335,7 @@ This unreleased fuel-core build may include features and updates not yet support
33044
32335
  decode(data, offset) {
33045
32336
  let decoded;
33046
32337
  let o = offset;
33047
- [decoded, o] = new NumberCoder("u8").decode(data, o);
32338
+ [decoded, o] = new NumberCoder("u8", { padToWordSize: true }).decode(data, o);
33048
32339
  const inputIndex = decoded;
33049
32340
  [decoded, o] = new B256Coder().decode(data, o);
33050
32341
  const balanceRoot = decoded;
@@ -33156,7 +32447,7 @@ This unreleased fuel-core build may include features and updates not yet support
33156
32447
  }
33157
32448
  encode(value) {
33158
32449
  const parts = [];
33159
- parts.push(new NumberCoder("u8").encode(value.type));
32450
+ parts.push(new NumberCoder("u8", { padToWordSize: true }).encode(value.type));
33160
32451
  const { type: type3 } = value;
33161
32452
  switch (type3) {
33162
32453
  case 0: {
@@ -33191,7 +32482,7 @@ This unreleased fuel-core build may include features and updates not yet support
33191
32482
  decode(data, offset) {
33192
32483
  let decoded;
33193
32484
  let o = offset;
33194
- [decoded, o] = new NumberCoder("u8").decode(data, o);
32485
+ [decoded, o] = new NumberCoder("u8", { padToWordSize: true }).decode(data, o);
33195
32486
  const type3 = decoded;
33196
32487
  switch (type3) {
33197
32488
  case 0: {
@@ -33259,7 +32550,7 @@ This unreleased fuel-core build may include features and updates not yet support
33259
32550
  parts.push(new BigNumberCoder("u64").encode(data));
33260
32551
  break;
33261
32552
  case 4:
33262
- parts.push(new NumberCoder("u32").encode(data));
32553
+ parts.push(new NumberCoder("u32", { padToWordSize: true }).encode(data));
33263
32554
  break;
33264
32555
  default: {
33265
32556
  throw new FuelError(ErrorCode.INVALID_POLICY_TYPE, `Invalid policy type: ${type3}`);
@@ -33282,7 +32573,10 @@ This unreleased fuel-core build may include features and updates not yet support
33282
32573
  policies.push({ type: 2, data: witnessLimit });
33283
32574
  }
33284
32575
  if (policyTypes & 4) {
33285
- const [maturity, nextOffset] = new NumberCoder("u32").decode(data, o);
32576
+ const [maturity, nextOffset] = new NumberCoder("u32", { padToWordSize: true }).decode(
32577
+ data,
32578
+ o
32579
+ );
33286
32580
  o = nextOffset;
33287
32581
  policies.push({ type: 4, data: maturity });
33288
32582
  }
@@ -33329,7 +32623,7 @@ This unreleased fuel-core build may include features and updates not yet support
33329
32623
  parts.push(new B256Coder().encode(value.recipient));
33330
32624
  parts.push(new BigNumberCoder("u64").encode(value.amount));
33331
32625
  parts.push(new B256Coder().encode(value.nonce));
33332
- parts.push(new NumberCoder("u16").encode(value.data.length));
32626
+ parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.data.length));
33333
32627
  parts.push(new B256Coder().encode(value.digest));
33334
32628
  parts.push(new ByteArrayCoder(value.data.length).encode(value.data));
33335
32629
  return concat(parts);
@@ -33345,7 +32639,7 @@ This unreleased fuel-core build may include features and updates not yet support
33345
32639
  const amount = decoded;
33346
32640
  [decoded, o] = new B256Coder().decode(data, o);
33347
32641
  const nonce = decoded;
33348
- [decoded, o] = new NumberCoder("u16").decode(data, o);
32642
+ [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
33349
32643
  const len = decoded;
33350
32644
  [decoded, o] = new B256Coder().decode(data, o);
33351
32645
  const digest = decoded;
@@ -33469,11 +32763,11 @@ This unreleased fuel-core build may include features and updates not yet support
33469
32763
  encode(upgradePurposeType) {
33470
32764
  const parts = [];
33471
32765
  const { type: type3 } = upgradePurposeType;
33472
- parts.push(new NumberCoder("u8").encode(type3));
32766
+ parts.push(new NumberCoder("u8", { padToWordSize: true }).encode(type3));
33473
32767
  switch (type3) {
33474
32768
  case 0: {
33475
32769
  const data = upgradePurposeType.data;
33476
- parts.push(new NumberCoder("u16").encode(data.witnessIndex));
32770
+ parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(data.witnessIndex));
33477
32771
  parts.push(new B256Coder().encode(data.checksum));
33478
32772
  break;
33479
32773
  }
@@ -33494,11 +32788,11 @@ This unreleased fuel-core build may include features and updates not yet support
33494
32788
  decode(data, offset) {
33495
32789
  let o = offset;
33496
32790
  let decoded;
33497
- [decoded, o] = new NumberCoder("u8").decode(data, o);
32791
+ [decoded, o] = new NumberCoder("u8", { padToWordSize: true }).decode(data, o);
33498
32792
  const type3 = decoded;
33499
32793
  switch (type3) {
33500
32794
  case 0: {
33501
- [decoded, o] = new NumberCoder("u16").decode(data, o);
32795
+ [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
33502
32796
  const witnessIndex = decoded;
33503
32797
  [decoded, o] = new B256Coder().decode(data, o);
33504
32798
  const checksum = decoded;
@@ -33529,14 +32823,14 @@ This unreleased fuel-core build may include features and updates not yet support
33529
32823
  }
33530
32824
  encode(value) {
33531
32825
  const parts = [];
33532
- parts.push(new NumberCoder("u32").encode(value.dataLength));
32826
+ parts.push(new NumberCoder("u32", { padToWordSize: true }).encode(value.dataLength));
33533
32827
  parts.push(new ByteArrayCoder(value.dataLength).encode(value.data));
33534
32828
  return concat(parts);
33535
32829
  }
33536
32830
  decode(data, offset) {
33537
32831
  let decoded;
33538
32832
  let o = offset;
33539
- [decoded, o] = new NumberCoder("u32").decode(data, o);
32833
+ [decoded, o] = new NumberCoder("u32", { padToWordSize: true }).decode(data, o);
33540
32834
  const dataLength = decoded;
33541
32835
  [decoded, o] = new ByteArrayCoder(dataLength).decode(data, o);
33542
32836
  const witnessData = decoded;
@@ -33567,10 +32861,10 @@ This unreleased fuel-core build may include features and updates not yet support
33567
32861
  parts.push(new B256Coder().encode(value.receiptsRoot));
33568
32862
  parts.push(new BigNumberCoder("u64").encode(value.scriptLength));
33569
32863
  parts.push(new BigNumberCoder("u64").encode(value.scriptDataLength));
33570
- parts.push(new NumberCoder("u32").encode(value.policyTypes));
33571
- parts.push(new NumberCoder("u16").encode(value.inputsCount));
33572
- parts.push(new NumberCoder("u16").encode(value.outputsCount));
33573
- parts.push(new NumberCoder("u16").encode(value.witnessesCount));
32864
+ parts.push(new NumberCoder("u32", { padToWordSize: true }).encode(value.policyTypes));
32865
+ parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.inputsCount));
32866
+ parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.outputsCount));
32867
+ parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.witnessesCount));
33574
32868
  parts.push(new ByteArrayCoder(value.scriptLength.toNumber()).encode(value.script));
33575
32869
  parts.push(new ByteArrayCoder(value.scriptDataLength.toNumber()).encode(value.scriptData));
33576
32870
  parts.push(new PoliciesCoder().encode(value.policies));
@@ -33590,13 +32884,13 @@ This unreleased fuel-core build may include features and updates not yet support
33590
32884
  const scriptLength = decoded;
33591
32885
  [decoded, o] = new BigNumberCoder("u64").decode(data, o);
33592
32886
  const scriptDataLength = decoded;
33593
- [decoded, o] = new NumberCoder("u32").decode(data, o);
32887
+ [decoded, o] = new NumberCoder("u32", { padToWordSize: true }).decode(data, o);
33594
32888
  const policyTypes = decoded;
33595
- [decoded, o] = new NumberCoder("u16").decode(data, o);
32889
+ [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
33596
32890
  const inputsCount = decoded;
33597
- [decoded, o] = new NumberCoder("u16").decode(data, o);
32891
+ [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
33598
32892
  const outputsCount = decoded;
33599
- [decoded, o] = new NumberCoder("u16").decode(data, o);
32893
+ [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
33600
32894
  const witnessesCount = decoded;
33601
32895
  [decoded, o] = new ByteArrayCoder(scriptLength.toNumber()).decode(data, o);
33602
32896
  const script = decoded;
@@ -33638,13 +32932,13 @@ This unreleased fuel-core build may include features and updates not yet support
33638
32932
  }
33639
32933
  encode(value) {
33640
32934
  const parts = [];
33641
- parts.push(new NumberCoder("u16").encode(value.bytecodeWitnessIndex));
32935
+ parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.bytecodeWitnessIndex));
33642
32936
  parts.push(new B256Coder().encode(value.salt));
33643
32937
  parts.push(new BigNumberCoder("u64").encode(value.storageSlotsCount));
33644
- parts.push(new NumberCoder("u32").encode(value.policyTypes));
33645
- parts.push(new NumberCoder("u16").encode(value.inputsCount));
33646
- parts.push(new NumberCoder("u16").encode(value.outputsCount));
33647
- parts.push(new NumberCoder("u16").encode(value.witnessesCount));
32938
+ parts.push(new NumberCoder("u32", { padToWordSize: true }).encode(value.policyTypes));
32939
+ parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.inputsCount));
32940
+ parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.outputsCount));
32941
+ parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.witnessesCount));
33648
32942
  parts.push(
33649
32943
  new ArrayCoder(new StorageSlotCoder(), value.storageSlotsCount.toNumber()).encode(
33650
32944
  value.storageSlots
@@ -33659,19 +32953,19 @@ This unreleased fuel-core build may include features and updates not yet support
33659
32953
  decode(data, offset) {
33660
32954
  let decoded;
33661
32955
  let o = offset;
33662
- [decoded, o] = new NumberCoder("u16").decode(data, o);
32956
+ [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
33663
32957
  const bytecodeWitnessIndex = decoded;
33664
32958
  [decoded, o] = new B256Coder().decode(data, o);
33665
32959
  const salt = decoded;
33666
32960
  [decoded, o] = new BigNumberCoder("u64").decode(data, o);
33667
32961
  const storageSlotsCount = decoded;
33668
- [decoded, o] = new NumberCoder("u32").decode(data, o);
32962
+ [decoded, o] = new NumberCoder("u32", { padToWordSize: true }).decode(data, o);
33669
32963
  const policyTypes = decoded;
33670
- [decoded, o] = new NumberCoder("u16").decode(data, o);
32964
+ [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
33671
32965
  const inputsCount = decoded;
33672
- [decoded, o] = new NumberCoder("u16").decode(data, o);
32966
+ [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
33673
32967
  const outputsCount = decoded;
33674
- [decoded, o] = new NumberCoder("u16").decode(data, o);
32968
+ [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
33675
32969
  const witnessesCount = decoded;
33676
32970
  [decoded, o] = new ArrayCoder(new StorageSlotCoder(), storageSlotsCount.toNumber()).decode(
33677
32971
  data,
@@ -33885,7 +33179,7 @@ This unreleased fuel-core build may include features and updates not yet support
33885
33179
  }
33886
33180
  encode(value) {
33887
33181
  const parts = [];
33888
- parts.push(new NumberCoder("u8").encode(value.type));
33182
+ parts.push(new NumberCoder("u8", { padToWordSize: true }).encode(value.type));
33889
33183
  const { type: type3 } = value;
33890
33184
  switch (value.type) {
33891
33185
  case 0: {
@@ -33928,7 +33222,7 @@ This unreleased fuel-core build may include features and updates not yet support
33928
33222
  decode(data, offset) {
33929
33223
  let decoded;
33930
33224
  let o = offset;
33931
- [decoded, o] = new NumberCoder("u8").decode(data, o);
33225
+ [decoded, o] = new NumberCoder("u8", { padToWordSize: true }).decode(data, o);
33932
33226
  const type3 = decoded;
33933
33227
  switch (type3) {
33934
33228
  case 0: {
@@ -39655,15 +38949,6 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
39655
38949
  }
39656
38950
  });
39657
38951
  }
39658
- shiftPredicateData() {
39659
- this.inputs.forEach((input) => {
39660
- if ("predicateData" in input && "padPredicateData" in input && typeof input.padPredicateData === "function") {
39661
- input.predicateData = input.padPredicateData(
39662
- BaseTransactionRequest.getPolicyMeta(this).policies.length
39663
- );
39664
- }
39665
- });
39666
- }
39667
38952
  };
39668
38953
 
39669
38954
  // src/providers/transaction-request/hash-transaction.ts
@@ -40128,37 +39413,27 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
40128
39413
  };
40129
39414
 
40130
39415
  // src/providers/transaction-summary/call.ts
40131
- var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
39416
+ var getFunctionCall = ({ abi, receipt }) => {
40132
39417
  const abiInterface = new Interface(abi);
40133
39418
  const callFunctionSelector = receipt.param1.toHex(8);
40134
39419
  const functionFragment = abiInterface.getFunction(callFunctionSelector);
40135
39420
  const inputs = functionFragment.jsonFn.inputs;
40136
- let encodedArgs;
40137
- if (functionFragment.isInputDataPointer) {
40138
- if (rawPayload) {
40139
- const argsOffset = bn(receipt.param2).sub(calculateVmTxMemory({ maxInputs: maxInputs.toNumber() })).toNumber();
40140
- encodedArgs = `0x${rawPayload.slice(2).slice(argsOffset * 2)}`;
40141
- }
40142
- } else {
40143
- encodedArgs = receipt.param2.toHex();
40144
- }
39421
+ const encodedArgs = receipt.param2.toHex();
40145
39422
  let argumentsProvided;
40146
- if (encodedArgs) {
40147
- const data = functionFragment.decodeArguments(encodedArgs);
40148
- if (data) {
40149
- argumentsProvided = inputs.reduce((prev, input, index) => {
40150
- const value = data[index];
40151
- const name = input.name;
40152
- if (name) {
40153
- return {
40154
- ...prev,
40155
- // reparse to remove bn
40156
- [name]: JSON.parse(JSON.stringify(value))
40157
- };
40158
- }
40159
- return prev;
40160
- }, {});
40161
- }
39423
+ const data = functionFragment.decodeArguments(encodedArgs);
39424
+ if (data) {
39425
+ argumentsProvided = inputs.reduce((prev, input, index) => {
39426
+ const value = data[index];
39427
+ const name = input.name;
39428
+ if (name) {
39429
+ return {
39430
+ ...prev,
39431
+ // reparse to remove bn
39432
+ [name]: JSON.parse(JSON.stringify(value))
39433
+ };
39434
+ }
39435
+ return prev;
39436
+ }, {});
40162
39437
  }
40163
39438
  const call = {
40164
39439
  functionSignature: functionFragment.signature,
@@ -42655,7 +41930,6 @@ Supported fuel-core version: ${supportedVersion}.`
42655
41930
  cacheRequestInputsResourcesFromOwner(request.inputs, this.address)
42656
41931
  );
42657
41932
  request.addResources(resources);
42658
- request.shiftPredicateData();
42659
41933
  request.updatePredicateGasUsed(estimatedPredicates);
42660
41934
  const requestToReestimate2 = clone_default(request);
42661
41935
  if (addedSignatures) {
@@ -42687,7 +41961,6 @@ Supported fuel-core version: ${supportedVersion}.`
42687
41961
  }
42688
41962
  fundingAttempts += 1;
42689
41963
  }
42690
- request.shiftPredicateData();
42691
41964
  request.updatePredicateGasUsed(estimatedPredicates);
42692
41965
  const requestToReestimate = clone_default(request);
42693
41966
  if (addedSignatures) {
@@ -47729,7 +47002,6 @@ Supported fuel-core version: ${supportedVersion}.`
47729
47002
  */
47730
47003
  populateTransactionPredicateData(transactionRequestLike) {
47731
47004
  const request = transactionRequestify(transactionRequestLike);
47732
- const { policies } = BaseTransactionRequest.getPolicyMeta(request);
47733
47005
  const placeholderIndex = this.getIndexFromPlaceholderWitness(request);
47734
47006
  if (placeholderIndex !== -1) {
47735
47007
  request.removeWitness(placeholderIndex);
@@ -47737,7 +47009,7 @@ Supported fuel-core version: ${supportedVersion}.`
47737
47009
  request.inputs.filter(isRequestInputResource).forEach((input) => {
47738
47010
  if (isRequestInputResourceFromOwner(input, this.address)) {
47739
47011
  input.predicate = hexlify(this.bytes);
47740
- input.predicateData = hexlify(this.getPredicateData(policies.length));
47012
+ input.predicateData = hexlify(this.getPredicateData());
47741
47013
  input.witnessIndex = 0;
47742
47014
  }
47743
47015
  });
@@ -47763,17 +47035,12 @@ Supported fuel-core version: ${supportedVersion}.`
47763
47035
  const transactionRequest = transactionRequestify(transactionRequestLike);
47764
47036
  return super.simulateTransaction(transactionRequest, { estimateTxDependencies: false });
47765
47037
  }
47766
- getPredicateData(policiesLength) {
47038
+ getPredicateData() {
47767
47039
  if (!this.predicateData.length) {
47768
47040
  return new Uint8Array();
47769
47041
  }
47770
47042
  const mainFn = this.interface?.functions.main;
47771
- const paddedCode = new ByteArrayCoder(this.bytes.length).encode(this.bytes);
47772
- const VM_TX_MEMORY = calculateVmTxMemory({
47773
- maxInputs: this.provider.getChain().consensusParameters.txParameters.maxInputs.toNumber()
47774
- });
47775
- const OFFSET = VM_TX_MEMORY + SCRIPT_FIXED_SIZE + INPUT_COIN_FIXED_SIZE + WORD_SIZE + paddedCode.byteLength + policiesLength * WORD_SIZE;
47776
- return mainFn?.encodeArguments(this.predicateData, OFFSET) || new Uint8Array();
47043
+ return mainFn?.encodeArguments(this.predicateData) || new Uint8Array();
47777
47044
  }
47778
47045
  /**
47779
47046
  * Processes the predicate data and returns the altered bytecode and interface.
@@ -47822,8 +47089,7 @@ Supported fuel-core version: ${supportedVersion}.`
47822
47089
  );
47823
47090
  return resources.map((resource) => ({
47824
47091
  ...resource,
47825
- predicate: hexlify(this.bytes),
47826
- padPredicateData: (policiesLength) => hexlify(this.getPredicateData(policiesLength))
47092
+ predicate: hexlify(this.bytes)
47827
47093
  }));
47828
47094
  }
47829
47095
  /**