@fuel-ts/account 0.0.0-pr-2143-20240514195938 → 0.0.0-pr-2328-20240517121917

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of @fuel-ts/account might be problematic. Click here for more details.

Files changed (45) hide show
  1. package/dist/account.d.ts.map +1 -1
  2. package/dist/configs.d.ts +1 -1
  3. package/dist/configs.d.ts.map +1 -1
  4. package/dist/configs.global.js +1 -1
  5. package/dist/configs.global.js.map +1 -1
  6. package/dist/configs.js +5 -5
  7. package/dist/configs.js.map +1 -1
  8. package/dist/configs.mjs +3 -3
  9. package/dist/configs.mjs.map +1 -1
  10. package/dist/index.global.js +627 -1542
  11. package/dist/index.global.js.map +1 -1
  12. package/dist/index.js +153 -197
  13. package/dist/index.js.map +1 -1
  14. package/dist/index.mjs +143 -193
  15. package/dist/index.mjs.map +1 -1
  16. package/dist/mnemonic/mnemonic.d.ts.map +1 -1
  17. package/dist/mnemonic/utils.d.ts +0 -1
  18. package/dist/mnemonic/utils.d.ts.map +1 -1
  19. package/dist/predicate/predicate.d.ts.map +1 -1
  20. package/dist/providers/__generated__/operations.d.ts +8 -0
  21. package/dist/providers/__generated__/operations.d.ts.map +1 -1
  22. package/dist/providers/coin.d.ts +0 -1
  23. package/dist/providers/coin.d.ts.map +1 -1
  24. package/dist/providers/message.d.ts +0 -1
  25. package/dist/providers/message.d.ts.map +1 -1
  26. package/dist/providers/provider.d.ts +4 -1
  27. package/dist/providers/provider.d.ts.map +1 -1
  28. package/dist/providers/transaction-request/input.d.ts +0 -2
  29. package/dist/providers/transaction-request/input.d.ts.map +1 -1
  30. package/dist/providers/transaction-request/transaction-request.d.ts +0 -1
  31. package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
  32. package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
  33. package/dist/providers/transaction-summary/call.d.ts +1 -1
  34. package/dist/providers/transaction-summary/call.d.ts.map +1 -1
  35. package/dist/providers/utils/extract-tx-error.d.ts +2 -4
  36. package/dist/providers/utils/extract-tx-error.d.ts.map +1 -1
  37. package/dist/test-utils/launchNode.d.ts +2 -4
  38. package/dist/test-utils/launchNode.d.ts.map +1 -1
  39. package/dist/test-utils.global.js +734 -3868
  40. package/dist/test-utils.global.js.map +1 -1
  41. package/dist/test-utils.js +147 -184
  42. package/dist/test-utils.js.map +1 -1
  43. package/dist/test-utils.mjs +136 -173
  44. package/dist/test-utils.mjs.map +1 -1
  45. package/package.json +15 -15
@@ -73,7 +73,7 @@
73
73
  "../../node_modules/.pnpm/bn.js@5.2.1/node_modules/bn.js/lib/bn.js"(exports, module) {
74
74
  (function(module2, exports2) {
75
75
  "use strict";
76
- function assert3(val, msg) {
76
+ function assert2(val, msg) {
77
77
  if (!val)
78
78
  throw new Error(msg || "Assertion failed");
79
79
  }
@@ -143,7 +143,7 @@
143
143
  if (base === "hex") {
144
144
  base = 16;
145
145
  }
146
- assert3(base === (base | 0) && base >= 2 && base <= 36);
146
+ assert2(base === (base | 0) && base >= 2 && base <= 36);
147
147
  number2 = number2.toString().replace(/\s+/g, "");
148
148
  var start = 0;
149
149
  if (number2[0] === "-") {
@@ -176,7 +176,7 @@
176
176
  ];
177
177
  this.length = 2;
178
178
  } else {
179
- assert3(number2 < 9007199254740992);
179
+ assert2(number2 < 9007199254740992);
180
180
  this.words = [
181
181
  number2 & 67108863,
182
182
  number2 / 67108864 & 67108863,
@@ -189,7 +189,7 @@
189
189
  this._initArray(this.toArray(), base, endian);
190
190
  };
191
191
  BN2.prototype._initArray = function _initArray(number2, base, endian) {
192
- assert3(typeof number2.length === "number");
192
+ assert2(typeof number2.length === "number");
193
193
  if (number2.length <= 0) {
194
194
  this.words = [0];
195
195
  this.length = 1;
@@ -236,7 +236,7 @@
236
236
  } else if (c >= 97 && c <= 102) {
237
237
  return c - 87;
238
238
  } else {
239
- assert3(false, "Invalid character in " + string);
239
+ assert2(false, "Invalid character in " + string);
240
240
  }
241
241
  }
242
242
  function parseHexByte(string, lowerBound, index) {
@@ -297,7 +297,7 @@
297
297
  } else {
298
298
  b = c;
299
299
  }
300
- assert3(c >= 0 && b < mul, "Invalid character");
300
+ assert2(c >= 0 && b < mul, "Invalid character");
301
301
  r += b;
302
302
  }
303
303
  return r;
@@ -557,16 +557,16 @@
557
557
  }
558
558
  return out;
559
559
  }
560
- assert3(false, "Base should be between 2 and 36");
560
+ assert2(false, "Base should be between 2 and 36");
561
561
  };
562
- BN2.prototype.toNumber = function toNumber3() {
562
+ BN2.prototype.toNumber = function toNumber2() {
563
563
  var ret2 = this.words[0];
564
564
  if (this.length === 2) {
565
565
  ret2 += this.words[1] * 67108864;
566
566
  } else if (this.length === 3 && this.words[2] === 1) {
567
567
  ret2 += 4503599627370496 + this.words[1] * 67108864;
568
568
  } else if (this.length > 2) {
569
- assert3(false, "Number can only safely store up to 53 bits");
569
+ assert2(false, "Number can only safely store up to 53 bits");
570
570
  }
571
571
  return this.negative !== 0 ? -ret2 : ret2;
572
572
  };
@@ -591,8 +591,8 @@
591
591
  this._strip();
592
592
  var byteLength = this.byteLength();
593
593
  var reqLength = length || Math.max(1, byteLength);
594
- assert3(byteLength <= reqLength, "byte array longer than desired length");
595
- assert3(reqLength > 0, "Requested array length <= 0");
594
+ assert2(byteLength <= reqLength, "byte array longer than desired length");
595
+ assert2(reqLength > 0, "Requested array length <= 0");
596
596
  var res = allocate(ArrayType, reqLength);
597
597
  var postfix = endian === "le" ? "LE" : "BE";
598
598
  this["_toArrayLike" + postfix](res, byteLength);
@@ -740,13 +740,13 @@
740
740
  BN2.prototype.byteLength = function byteLength() {
741
741
  return Math.ceil(this.bitLength() / 8);
742
742
  };
743
- BN2.prototype.toTwos = function toTwos2(width) {
743
+ BN2.prototype.toTwos = function toTwos(width) {
744
744
  if (this.negative !== 0) {
745
745
  return this.abs().inotn(width).iaddn(1);
746
746
  }
747
747
  return this.clone();
748
748
  };
749
- BN2.prototype.fromTwos = function fromTwos2(width) {
749
+ BN2.prototype.fromTwos = function fromTwos(width) {
750
750
  if (this.testn(width - 1)) {
751
751
  return this.notn(width).iaddn(1).ineg();
752
752
  }
@@ -774,7 +774,7 @@
774
774
  return this._strip();
775
775
  };
776
776
  BN2.prototype.ior = function ior(num) {
777
- assert3((this.negative | num.negative) === 0);
777
+ assert2((this.negative | num.negative) === 0);
778
778
  return this.iuor(num);
779
779
  };
780
780
  BN2.prototype.or = function or(num) {
@@ -801,7 +801,7 @@
801
801
  return this._strip();
802
802
  };
803
803
  BN2.prototype.iand = function iand(num) {
804
- assert3((this.negative | num.negative) === 0);
804
+ assert2((this.negative | num.negative) === 0);
805
805
  return this.iuand(num);
806
806
  };
807
807
  BN2.prototype.and = function and(num) {
@@ -836,7 +836,7 @@
836
836
  return this._strip();
837
837
  };
838
838
  BN2.prototype.ixor = function ixor(num) {
839
- assert3((this.negative | num.negative) === 0);
839
+ assert2((this.negative | num.negative) === 0);
840
840
  return this.iuxor(num);
841
841
  };
842
842
  BN2.prototype.xor = function xor(num) {
@@ -850,7 +850,7 @@
850
850
  return num.clone().iuxor(this);
851
851
  };
852
852
  BN2.prototype.inotn = function inotn(width) {
853
- assert3(typeof width === "number" && width >= 0);
853
+ assert2(typeof width === "number" && width >= 0);
854
854
  var bytesNeeded = Math.ceil(width / 26) | 0;
855
855
  var bitsLeft = width % 26;
856
856
  this._expand(bytesNeeded);
@@ -869,7 +869,7 @@
869
869
  return this.clone().inotn(width);
870
870
  };
871
871
  BN2.prototype.setn = function setn(bit, val) {
872
- assert3(typeof bit === "number" && bit >= 0);
872
+ assert2(typeof bit === "number" && bit >= 0);
873
873
  var off = bit / 26 | 0;
874
874
  var wbit = bit % 26;
875
875
  this._expand(off + 1);
@@ -1735,8 +1735,8 @@
1735
1735
  for (i = 2 * len; i < N; ++i) {
1736
1736
  rws[i] = 0;
1737
1737
  }
1738
- assert3(carry === 0);
1739
- assert3((carry & ~8191) === 0);
1738
+ assert2(carry === 0);
1739
+ assert2((carry & ~8191) === 0);
1740
1740
  };
1741
1741
  FFTM.prototype.stub = function stub(N) {
1742
1742
  var ph = new Array(N);
@@ -1791,8 +1791,8 @@
1791
1791
  var isNegNum = num < 0;
1792
1792
  if (isNegNum)
1793
1793
  num = -num;
1794
- assert3(typeof num === "number");
1795
- assert3(num < 67108864);
1794
+ assert2(typeof num === "number");
1795
+ assert2(num < 67108864);
1796
1796
  var carry = 0;
1797
1797
  for (var i = 0; i < this.length; i++) {
1798
1798
  var w = (this.words[i] | 0) * num;
@@ -1836,7 +1836,7 @@
1836
1836
  return res;
1837
1837
  };
1838
1838
  BN2.prototype.iushln = function iushln(bits) {
1839
- assert3(typeof bits === "number" && bits >= 0);
1839
+ assert2(typeof bits === "number" && bits >= 0);
1840
1840
  var r = bits % 26;
1841
1841
  var s = (bits - r) / 26;
1842
1842
  var carryMask = 67108863 >>> 26 - r << 26 - r;
@@ -1866,11 +1866,11 @@
1866
1866
  return this._strip();
1867
1867
  };
1868
1868
  BN2.prototype.ishln = function ishln(bits) {
1869
- assert3(this.negative === 0);
1869
+ assert2(this.negative === 0);
1870
1870
  return this.iushln(bits);
1871
1871
  };
1872
1872
  BN2.prototype.iushrn = function iushrn(bits, hint, extended) {
1873
- assert3(typeof bits === "number" && bits >= 0);
1873
+ assert2(typeof bits === "number" && bits >= 0);
1874
1874
  var h;
1875
1875
  if (hint) {
1876
1876
  h = (hint - hint % 26) / 26;
@@ -1879,7 +1879,7 @@
1879
1879
  }
1880
1880
  var r = bits % 26;
1881
1881
  var s = Math.min((bits - r) / 26, this.length);
1882
- var mask2 = 67108863 ^ 67108863 >>> r << r;
1882
+ var mask = 67108863 ^ 67108863 >>> r << r;
1883
1883
  var maskedWords = extended;
1884
1884
  h -= s;
1885
1885
  h = Math.max(0, h);
@@ -1903,7 +1903,7 @@
1903
1903
  for (i = this.length - 1; i >= 0 && (carry !== 0 || i >= h); i--) {
1904
1904
  var word = this.words[i] | 0;
1905
1905
  this.words[i] = carry << 26 - r | word >>> r;
1906
- carry = word & mask2;
1906
+ carry = word & mask;
1907
1907
  }
1908
1908
  if (maskedWords && carry !== 0) {
1909
1909
  maskedWords.words[maskedWords.length++] = carry;
@@ -1915,7 +1915,7 @@
1915
1915
  return this._strip();
1916
1916
  };
1917
1917
  BN2.prototype.ishrn = function ishrn(bits, hint, extended) {
1918
- assert3(this.negative === 0);
1918
+ assert2(this.negative === 0);
1919
1919
  return this.iushrn(bits, hint, extended);
1920
1920
  };
1921
1921
  BN2.prototype.shln = function shln(bits) {
@@ -1931,7 +1931,7 @@
1931
1931
  return this.clone().iushrn(bits);
1932
1932
  };
1933
1933
  BN2.prototype.testn = function testn(bit) {
1934
- assert3(typeof bit === "number" && bit >= 0);
1934
+ assert2(typeof bit === "number" && bit >= 0);
1935
1935
  var r = bit % 26;
1936
1936
  var s = (bit - r) / 26;
1937
1937
  var q = 1 << r;
@@ -1941,10 +1941,10 @@
1941
1941
  return !!(w & q);
1942
1942
  };
1943
1943
  BN2.prototype.imaskn = function imaskn(bits) {
1944
- assert3(typeof bits === "number" && bits >= 0);
1944
+ assert2(typeof bits === "number" && bits >= 0);
1945
1945
  var r = bits % 26;
1946
1946
  var s = (bits - r) / 26;
1947
- assert3(this.negative === 0, "imaskn works only with positive numbers");
1947
+ assert2(this.negative === 0, "imaskn works only with positive numbers");
1948
1948
  if (this.length <= s) {
1949
1949
  return this;
1950
1950
  }
@@ -1953,8 +1953,8 @@
1953
1953
  }
1954
1954
  this.length = Math.min(s, this.length);
1955
1955
  if (r !== 0) {
1956
- var mask2 = 67108863 ^ 67108863 >>> r << r;
1957
- this.words[this.length - 1] &= mask2;
1956
+ var mask = 67108863 ^ 67108863 >>> r << r;
1957
+ this.words[this.length - 1] &= mask;
1958
1958
  }
1959
1959
  return this._strip();
1960
1960
  };
@@ -1962,8 +1962,8 @@
1962
1962
  return this.clone().imaskn(bits);
1963
1963
  };
1964
1964
  BN2.prototype.iaddn = function iaddn(num) {
1965
- assert3(typeof num === "number");
1966
- assert3(num < 67108864);
1965
+ assert2(typeof num === "number");
1966
+ assert2(num < 67108864);
1967
1967
  if (num < 0)
1968
1968
  return this.isubn(-num);
1969
1969
  if (this.negative !== 0) {
@@ -1993,8 +1993,8 @@
1993
1993
  return this;
1994
1994
  };
1995
1995
  BN2.prototype.isubn = function isubn(num) {
1996
- assert3(typeof num === "number");
1997
- assert3(num < 67108864);
1996
+ assert2(typeof num === "number");
1997
+ assert2(num < 67108864);
1998
1998
  if (num < 0)
1999
1999
  return this.iaddn(-num);
2000
2000
  if (this.negative !== 0) {
@@ -2048,7 +2048,7 @@
2048
2048
  }
2049
2049
  if (carry === 0)
2050
2050
  return this._strip();
2051
- assert3(carry === -1);
2051
+ assert2(carry === -1);
2052
2052
  carry = 0;
2053
2053
  for (i = 0; i < this.length; i++) {
2054
2054
  w = -(this.words[i] | 0) + carry;
@@ -2116,7 +2116,7 @@
2116
2116
  };
2117
2117
  };
2118
2118
  BN2.prototype.divmod = function divmod(num, mode, positive) {
2119
- assert3(!num.isZero());
2119
+ assert2(!num.isZero());
2120
2120
  if (this.isZero()) {
2121
2121
  return {
2122
2122
  div: new BN2(0),
@@ -2214,7 +2214,7 @@
2214
2214
  var isNegNum = num < 0;
2215
2215
  if (isNegNum)
2216
2216
  num = -num;
2217
- assert3(num <= 67108863);
2217
+ assert2(num <= 67108863);
2218
2218
  var p = (1 << 26) % num;
2219
2219
  var acc = 0;
2220
2220
  for (var i = this.length - 1; i >= 0; i--) {
@@ -2229,7 +2229,7 @@
2229
2229
  var isNegNum = num < 0;
2230
2230
  if (isNegNum)
2231
2231
  num = -num;
2232
- assert3(num <= 67108863);
2232
+ assert2(num <= 67108863);
2233
2233
  var carry = 0;
2234
2234
  for (var i = this.length - 1; i >= 0; i--) {
2235
2235
  var w = (this.words[i] | 0) + carry * 67108864;
@@ -2243,8 +2243,8 @@
2243
2243
  return this.clone().idivn(num);
2244
2244
  };
2245
2245
  BN2.prototype.egcd = function egcd(p) {
2246
- assert3(p.negative === 0);
2247
- assert3(!p.isZero());
2246
+ assert2(p.negative === 0);
2247
+ assert2(!p.isZero());
2248
2248
  var x = this;
2249
2249
  var y = p.clone();
2250
2250
  if (x.negative !== 0) {
@@ -2308,8 +2308,8 @@
2308
2308
  };
2309
2309
  };
2310
2310
  BN2.prototype._invmp = function _invmp(p) {
2311
- assert3(p.negative === 0);
2312
- assert3(!p.isZero());
2311
+ assert2(p.negative === 0);
2312
+ assert2(!p.isZero());
2313
2313
  var a = this;
2314
2314
  var b = p.clone();
2315
2315
  if (a.negative !== 0) {
@@ -2407,7 +2407,7 @@
2407
2407
  return this.words[0] & num;
2408
2408
  };
2409
2409
  BN2.prototype.bincn = function bincn(bit) {
2410
- assert3(typeof bit === "number");
2410
+ assert2(typeof bit === "number");
2411
2411
  var r = bit % 26;
2412
2412
  var s = (bit - r) / 26;
2413
2413
  var q = 1 << r;
@@ -2447,7 +2447,7 @@
2447
2447
  if (negative) {
2448
2448
  num = -num;
2449
2449
  }
2450
- assert3(num <= 67108863, "Number is too big");
2450
+ assert2(num <= 67108863, "Number is too big");
2451
2451
  var w = this.words[0] | 0;
2452
2452
  res = w === num ? 0 : w < num ? -1 : 1;
2453
2453
  }
@@ -2519,12 +2519,12 @@
2519
2519
  return new Red(num);
2520
2520
  };
2521
2521
  BN2.prototype.toRed = function toRed(ctx) {
2522
- assert3(!this.red, "Already a number in reduction context");
2523
- assert3(this.negative === 0, "red works only with positives");
2522
+ assert2(!this.red, "Already a number in reduction context");
2523
+ assert2(this.negative === 0, "red works only with positives");
2524
2524
  return ctx.convertTo(this)._forceRed(ctx);
2525
2525
  };
2526
2526
  BN2.prototype.fromRed = function fromRed() {
2527
- assert3(this.red, "fromRed works only with numbers in reduction context");
2527
+ assert2(this.red, "fromRed works only with numbers in reduction context");
2528
2528
  return this.red.convertFrom(this);
2529
2529
  };
2530
2530
  BN2.prototype._forceRed = function _forceRed(ctx) {
@@ -2532,66 +2532,66 @@
2532
2532
  return this;
2533
2533
  };
2534
2534
  BN2.prototype.forceRed = function forceRed(ctx) {
2535
- assert3(!this.red, "Already a number in reduction context");
2535
+ assert2(!this.red, "Already a number in reduction context");
2536
2536
  return this._forceRed(ctx);
2537
2537
  };
2538
2538
  BN2.prototype.redAdd = function redAdd(num) {
2539
- assert3(this.red, "redAdd works only with red numbers");
2539
+ assert2(this.red, "redAdd works only with red numbers");
2540
2540
  return this.red.add(this, num);
2541
2541
  };
2542
2542
  BN2.prototype.redIAdd = function redIAdd(num) {
2543
- assert3(this.red, "redIAdd works only with red numbers");
2543
+ assert2(this.red, "redIAdd works only with red numbers");
2544
2544
  return this.red.iadd(this, num);
2545
2545
  };
2546
2546
  BN2.prototype.redSub = function redSub(num) {
2547
- assert3(this.red, "redSub works only with red numbers");
2547
+ assert2(this.red, "redSub works only with red numbers");
2548
2548
  return this.red.sub(this, num);
2549
2549
  };
2550
2550
  BN2.prototype.redISub = function redISub(num) {
2551
- assert3(this.red, "redISub works only with red numbers");
2551
+ assert2(this.red, "redISub works only with red numbers");
2552
2552
  return this.red.isub(this, num);
2553
2553
  };
2554
2554
  BN2.prototype.redShl = function redShl(num) {
2555
- assert3(this.red, "redShl works only with red numbers");
2555
+ assert2(this.red, "redShl works only with red numbers");
2556
2556
  return this.red.shl(this, num);
2557
2557
  };
2558
2558
  BN2.prototype.redMul = function redMul(num) {
2559
- assert3(this.red, "redMul works only with red numbers");
2559
+ assert2(this.red, "redMul works only with red numbers");
2560
2560
  this.red._verify2(this, num);
2561
2561
  return this.red.mul(this, num);
2562
2562
  };
2563
2563
  BN2.prototype.redIMul = function redIMul(num) {
2564
- assert3(this.red, "redMul works only with red numbers");
2564
+ assert2(this.red, "redMul works only with red numbers");
2565
2565
  this.red._verify2(this, num);
2566
2566
  return this.red.imul(this, num);
2567
2567
  };
2568
2568
  BN2.prototype.redSqr = function redSqr() {
2569
- assert3(this.red, "redSqr works only with red numbers");
2569
+ assert2(this.red, "redSqr works only with red numbers");
2570
2570
  this.red._verify1(this);
2571
2571
  return this.red.sqr(this);
2572
2572
  };
2573
2573
  BN2.prototype.redISqr = function redISqr() {
2574
- assert3(this.red, "redISqr works only with red numbers");
2574
+ assert2(this.red, "redISqr works only with red numbers");
2575
2575
  this.red._verify1(this);
2576
2576
  return this.red.isqr(this);
2577
2577
  };
2578
2578
  BN2.prototype.redSqrt = function redSqrt() {
2579
- assert3(this.red, "redSqrt works only with red numbers");
2579
+ assert2(this.red, "redSqrt works only with red numbers");
2580
2580
  this.red._verify1(this);
2581
2581
  return this.red.sqrt(this);
2582
2582
  };
2583
2583
  BN2.prototype.redInvm = function redInvm() {
2584
- assert3(this.red, "redInvm works only with red numbers");
2584
+ assert2(this.red, "redInvm works only with red numbers");
2585
2585
  this.red._verify1(this);
2586
2586
  return this.red.invm(this);
2587
2587
  };
2588
2588
  BN2.prototype.redNeg = function redNeg() {
2589
- assert3(this.red, "redNeg works only with red numbers");
2589
+ assert2(this.red, "redNeg works only with red numbers");
2590
2590
  this.red._verify1(this);
2591
2591
  return this.red.neg(this);
2592
2592
  };
2593
2593
  BN2.prototype.redPow = function redPow(num) {
2594
- assert3(this.red && !num.red, "redPow(normalNum)");
2594
+ assert2(this.red && !num.red, "redPow(normalNum)");
2595
2595
  this.red._verify1(this);
2596
2596
  return this.red.pow(this, num);
2597
2597
  };
@@ -2652,7 +2652,7 @@
2652
2652
  }
2653
2653
  inherits(K256, MPrime);
2654
2654
  K256.prototype.split = function split2(input, output2) {
2655
- var mask2 = 4194303;
2655
+ var mask = 4194303;
2656
2656
  var outLen = Math.min(input.length, 9);
2657
2657
  for (var i = 0; i < outLen; i++) {
2658
2658
  output2.words[i] = input.words[i];
@@ -2664,10 +2664,10 @@
2664
2664
  return;
2665
2665
  }
2666
2666
  var prev = input.words[9];
2667
- output2.words[output2.length++] = prev & mask2;
2667
+ output2.words[output2.length++] = prev & mask;
2668
2668
  for (i = 10; i < input.length; i++) {
2669
2669
  var next = input.words[i] | 0;
2670
- input.words[i - 10] = (next & mask2) << 4 | prev >>> 22;
2670
+ input.words[i - 10] = (next & mask) << 4 | prev >>> 22;
2671
2671
  prev = next;
2672
2672
  }
2673
2673
  prev >>>= 22;
@@ -2759,18 +2759,18 @@
2759
2759
  this.m = prime.p;
2760
2760
  this.prime = prime;
2761
2761
  } else {
2762
- assert3(m.gtn(1), "modulus must be greater than 1");
2762
+ assert2(m.gtn(1), "modulus must be greater than 1");
2763
2763
  this.m = m;
2764
2764
  this.prime = null;
2765
2765
  }
2766
2766
  }
2767
2767
  Red.prototype._verify1 = function _verify1(a) {
2768
- assert3(a.negative === 0, "red works only with positives");
2769
- assert3(a.red, "red works only with red numbers");
2768
+ assert2(a.negative === 0, "red works only with positives");
2769
+ assert2(a.red, "red works only with red numbers");
2770
2770
  };
2771
2771
  Red.prototype._verify2 = function _verify2(a, b) {
2772
- assert3((a.negative | b.negative) === 0, "red works only with positives");
2773
- assert3(
2772
+ assert2((a.negative | b.negative) === 0, "red works only with positives");
2773
+ assert2(
2774
2774
  a.red && a.red === b.red,
2775
2775
  "red works only with red numbers"
2776
2776
  );
@@ -2841,7 +2841,7 @@
2841
2841
  if (a.isZero())
2842
2842
  return a.clone();
2843
2843
  var mod3 = this.m.andln(3);
2844
- assert3(mod3 % 2 === 1);
2844
+ assert2(mod3 % 2 === 1);
2845
2845
  if (mod3 === 3) {
2846
2846
  var pow3 = this.m.add(new BN2(1)).iushrn(2);
2847
2847
  return this.pow(a, pow3);
@@ -2852,7 +2852,7 @@
2852
2852
  s++;
2853
2853
  q.iushrn(1);
2854
2854
  }
2855
- assert3(!q.isZero());
2855
+ assert2(!q.isZero());
2856
2856
  var one = new BN2(1).toRed(this);
2857
2857
  var nOne = one.redNeg();
2858
2858
  var lpow = this.m.subn(1).iushrn(1);
@@ -2870,7 +2870,7 @@
2870
2870
  for (var i = 0; tmp.cmp(one) !== 0; i++) {
2871
2871
  tmp = tmp.redSqr();
2872
2872
  }
2873
- assert3(i < m);
2873
+ assert2(i < m);
2874
2874
  var b = this.pow(c, new BN2(1).iushln(m - i - 1));
2875
2875
  r = r.redMul(b);
2876
2876
  c = b.redSqr();
@@ -29470,13 +29470,13 @@ 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
- FUELS: "0.85.0"
29475
+ FUELS: "0.87.0"
29476
29476
  };
29477
29477
  }
29478
- function parseVersion(version2) {
29479
- const [major, minor, patch] = version2.split(".").map((v) => parseInt(v, 10));
29478
+ function parseVersion(version) {
29479
+ const [major, minor, patch] = version.split(".").map((v) => parseInt(v, 10));
29480
29480
  return { major, minor, patch };
29481
29481
  }
29482
29482
  function versionDiffs(version1, version2) {
@@ -30036,6 +30036,123 @@ This unreleased fuel-core build may include features and updates not yet support
30036
30036
  }
30037
30037
  return hexlify(bytes2.slice(start == null ? 0 : start, end == null ? bytes2.length : end));
30038
30038
  }
30039
+ function toUtf8Bytes(stri, form = true) {
30040
+ let str = stri;
30041
+ if (form) {
30042
+ str = stri.normalize("NFC");
30043
+ }
30044
+ const result = [];
30045
+ for (let i = 0; i < str.length; i += 1) {
30046
+ const c = str.charCodeAt(i);
30047
+ if (c < 128) {
30048
+ result.push(c);
30049
+ } else if (c < 2048) {
30050
+ result.push(c >> 6 | 192);
30051
+ result.push(c & 63 | 128);
30052
+ } else if ((c & 64512) === 55296) {
30053
+ i += 1;
30054
+ const c2 = str.charCodeAt(i);
30055
+ if (i >= str.length || (c2 & 64512) !== 56320) {
30056
+ throw new FuelError(
30057
+ ErrorCode.INVALID_INPUT_PARAMETERS,
30058
+ "Invalid UTF-8 in the input string."
30059
+ );
30060
+ }
30061
+ const pair = 65536 + ((c & 1023) << 10) + (c2 & 1023);
30062
+ result.push(pair >> 18 | 240);
30063
+ result.push(pair >> 12 & 63 | 128);
30064
+ result.push(pair >> 6 & 63 | 128);
30065
+ result.push(pair & 63 | 128);
30066
+ } else {
30067
+ result.push(c >> 12 | 224);
30068
+ result.push(c >> 6 & 63 | 128);
30069
+ result.push(c & 63 | 128);
30070
+ }
30071
+ }
30072
+ return new Uint8Array(result);
30073
+ }
30074
+ function onError(reason, offset, bytes2, output2, badCodepoint) {
30075
+ console.log(`invalid codepoint at offset ${offset}; ${reason}, bytes: ${bytes2}`);
30076
+ return offset;
30077
+ }
30078
+ function helper(codePoints) {
30079
+ return codePoints.map((codePoint) => {
30080
+ if (codePoint <= 65535) {
30081
+ return String.fromCharCode(codePoint);
30082
+ }
30083
+ codePoint -= 65536;
30084
+ return String.fromCharCode(
30085
+ (codePoint >> 10 & 1023) + 55296,
30086
+ (codePoint & 1023) + 56320
30087
+ );
30088
+ }).join("");
30089
+ }
30090
+ function getUtf8CodePoints(_bytes) {
30091
+ const bytes2 = arrayify(_bytes, "bytes");
30092
+ const result = [];
30093
+ let i = 0;
30094
+ while (i < bytes2.length) {
30095
+ const c = bytes2[i++];
30096
+ if (c >> 7 === 0) {
30097
+ result.push(c);
30098
+ continue;
30099
+ }
30100
+ let extraLength = null;
30101
+ let overlongMask = null;
30102
+ if ((c & 224) === 192) {
30103
+ extraLength = 1;
30104
+ overlongMask = 127;
30105
+ } else if ((c & 240) === 224) {
30106
+ extraLength = 2;
30107
+ overlongMask = 2047;
30108
+ } else if ((c & 248) === 240) {
30109
+ extraLength = 3;
30110
+ overlongMask = 65535;
30111
+ } else {
30112
+ if ((c & 192) === 128) {
30113
+ i += onError("UNEXPECTED_CONTINUE", i - 1, bytes2, result);
30114
+ } else {
30115
+ i += onError("BAD_PREFIX", i - 1, bytes2, result);
30116
+ }
30117
+ continue;
30118
+ }
30119
+ if (i - 1 + extraLength >= bytes2.length) {
30120
+ i += onError("OVERRUN", i - 1, bytes2, result);
30121
+ continue;
30122
+ }
30123
+ let res = c & (1 << 8 - extraLength - 1) - 1;
30124
+ for (let j = 0; j < extraLength; j++) {
30125
+ const nextChar = bytes2[i];
30126
+ if ((nextChar & 192) !== 128) {
30127
+ i += onError("MISSING_CONTINUE", i, bytes2, result);
30128
+ res = null;
30129
+ break;
30130
+ }
30131
+ res = res << 6 | nextChar & 63;
30132
+ i++;
30133
+ }
30134
+ if (res === null) {
30135
+ continue;
30136
+ }
30137
+ if (res > 1114111) {
30138
+ i += onError("OUT_OF_RANGE", i - 1 - extraLength, bytes2, result, res);
30139
+ continue;
30140
+ }
30141
+ if (res >= 55296 && res <= 57343) {
30142
+ i += onError("UTF16_SURROGATE", i - 1 - extraLength, bytes2, result, res);
30143
+ continue;
30144
+ }
30145
+ if (res <= overlongMask) {
30146
+ i += onError("OVERLONG", i - 1 - extraLength, bytes2, result, res);
30147
+ continue;
30148
+ }
30149
+ result.push(res);
30150
+ }
30151
+ return result;
30152
+ }
30153
+ function toUtf8String(bytes2) {
30154
+ return helper(getUtf8CodePoints(bytes2));
30155
+ }
30039
30156
 
30040
30157
  // ../../node_modules/.pnpm/@noble+hashes@1.3.3/node_modules/@noble/hashes/esm/ripemd160.js
30041
30158
  var Rho = /* @__PURE__ */ new Uint8Array([7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8]);
@@ -30147,13 +30264,13 @@ This unreleased fuel-core build may include features and updates not yet support
30147
30264
  };
30148
30265
  var keccak256 = (data) => keccak_256(data);
30149
30266
  var locked = false;
30150
- var helper = (data) => ripemd160(data);
30151
- var ripemd = helper;
30267
+ var helper2 = (data) => ripemd160(data);
30268
+ var ripemd = helper2;
30152
30269
  function ripemd1602(_data) {
30153
30270
  const data = arrayify(_data, "data");
30154
30271
  return ripemd(data);
30155
30272
  }
30156
- ripemd1602._ = helper;
30273
+ ripemd1602._ = helper2;
30157
30274
  ripemd1602.lock = () => {
30158
30275
  locked = true;
30159
30276
  };
@@ -30757,316 +30874,6 @@ This unreleased fuel-core build may include features and updates not yet support
30757
30874
  return coinQuantities;
30758
30875
  };
30759
30876
 
30760
- // ../../node_modules/.pnpm/ethers@6.7.1/node_modules/ethers/lib.esm/_version.js
30761
- var version = "6.7.1";
30762
-
30763
- // ../../node_modules/.pnpm/ethers@6.7.1/node_modules/ethers/lib.esm/utils/properties.js
30764
- function checkType(value, type3, name) {
30765
- const types = type3.split("|").map((t) => t.trim());
30766
- for (let i = 0; i < types.length; i++) {
30767
- switch (type3) {
30768
- case "any":
30769
- return;
30770
- case "bigint":
30771
- case "boolean":
30772
- case "number":
30773
- case "string":
30774
- if (typeof value === type3) {
30775
- return;
30776
- }
30777
- }
30778
- }
30779
- const error = new Error(`invalid value for type ${type3}`);
30780
- error.code = "INVALID_ARGUMENT";
30781
- error.argument = `value.${name}`;
30782
- error.value = value;
30783
- throw error;
30784
- }
30785
- function defineProperties(target, values, types) {
30786
- for (let key in values) {
30787
- let value = values[key];
30788
- const type3 = types ? types[key] : null;
30789
- if (type3) {
30790
- checkType(value, type3, key);
30791
- }
30792
- Object.defineProperty(target, key, { enumerable: true, value, writable: false });
30793
- }
30794
- }
30795
-
30796
- // ../../node_modules/.pnpm/ethers@6.7.1/node_modules/ethers/lib.esm/utils/errors.js
30797
- function stringify(value) {
30798
- if (value == null) {
30799
- return "null";
30800
- }
30801
- if (Array.isArray(value)) {
30802
- return "[ " + value.map(stringify).join(", ") + " ]";
30803
- }
30804
- if (value instanceof Uint8Array) {
30805
- const HEX = "0123456789abcdef";
30806
- let result = "0x";
30807
- for (let i = 0; i < value.length; i++) {
30808
- result += HEX[value[i] >> 4];
30809
- result += HEX[value[i] & 15];
30810
- }
30811
- return result;
30812
- }
30813
- if (typeof value === "object" && typeof value.toJSON === "function") {
30814
- return stringify(value.toJSON());
30815
- }
30816
- switch (typeof value) {
30817
- case "boolean":
30818
- case "symbol":
30819
- return value.toString();
30820
- case "bigint":
30821
- return BigInt(value).toString();
30822
- case "number":
30823
- return value.toString();
30824
- case "string":
30825
- return JSON.stringify(value);
30826
- case "object": {
30827
- const keys = Object.keys(value);
30828
- keys.sort();
30829
- return "{ " + keys.map((k) => `${stringify(k)}: ${stringify(value[k])}`).join(", ") + " }";
30830
- }
30831
- }
30832
- return `[ COULD NOT SERIALIZE ]`;
30833
- }
30834
- function makeError(message, code, info) {
30835
- {
30836
- const details = [];
30837
- if (info) {
30838
- if ("message" in info || "code" in info || "name" in info) {
30839
- throw new Error(`value will overwrite populated values: ${stringify(info)}`);
30840
- }
30841
- for (const key in info) {
30842
- const value = info[key];
30843
- details.push(key + "=" + stringify(value));
30844
- }
30845
- }
30846
- details.push(`code=${code}`);
30847
- details.push(`version=${version}`);
30848
- if (details.length) {
30849
- message += " (" + details.join(", ") + ")";
30850
- }
30851
- }
30852
- let error;
30853
- switch (code) {
30854
- case "INVALID_ARGUMENT":
30855
- error = new TypeError(message);
30856
- break;
30857
- case "NUMERIC_FAULT":
30858
- case "BUFFER_OVERRUN":
30859
- error = new RangeError(message);
30860
- break;
30861
- default:
30862
- error = new Error(message);
30863
- }
30864
- defineProperties(error, { code });
30865
- if (info) {
30866
- Object.assign(error, info);
30867
- }
30868
- return error;
30869
- }
30870
- function assert(check, message, code, info) {
30871
- if (!check) {
30872
- throw makeError(message, code, info);
30873
- }
30874
- }
30875
- function assertArgument(check, message, name, value) {
30876
- assert(check, message, "INVALID_ARGUMENT", { argument: name, value });
30877
- }
30878
- var _normalizeForms = ["NFD", "NFC", "NFKD", "NFKC"].reduce((accum, form) => {
30879
- try {
30880
- if ("test".normalize(form) !== "test") {
30881
- throw new Error("bad");
30882
- }
30883
- ;
30884
- if (form === "NFD") {
30885
- const check = String.fromCharCode(233).normalize("NFD");
30886
- const expected = String.fromCharCode(101, 769);
30887
- if (check !== expected) {
30888
- throw new Error("broken");
30889
- }
30890
- }
30891
- accum.push(form);
30892
- } catch (error) {
30893
- }
30894
- return accum;
30895
- }, []);
30896
- function assertNormalize(form) {
30897
- assert(_normalizeForms.indexOf(form) >= 0, "platform missing String.prototype.normalize", "UNSUPPORTED_OPERATION", {
30898
- operation: "String.prototype.normalize",
30899
- info: { form }
30900
- });
30901
- }
30902
-
30903
- // ../../node_modules/.pnpm/ethers@6.7.1/node_modules/ethers/lib.esm/utils/data.js
30904
- function _getBytes(value, name, copy) {
30905
- if (value instanceof Uint8Array) {
30906
- if (copy) {
30907
- return new Uint8Array(value);
30908
- }
30909
- return value;
30910
- }
30911
- if (typeof value === "string" && value.match(/^0x([0-9a-f][0-9a-f])*$/i)) {
30912
- const result = new Uint8Array((value.length - 2) / 2);
30913
- let offset = 2;
30914
- for (let i = 0; i < result.length; i++) {
30915
- result[i] = parseInt(value.substring(offset, offset + 2), 16);
30916
- offset += 2;
30917
- }
30918
- return result;
30919
- }
30920
- assertArgument(false, "invalid BytesLike value", name || "value", value);
30921
- }
30922
- function getBytes(value, name) {
30923
- return _getBytes(value, name, false);
30924
- }
30925
-
30926
- // ../../node_modules/.pnpm/ethers@6.7.1/node_modules/ethers/lib.esm/utils/utf8.js
30927
- function errorFunc(reason, offset, bytes2, output2, badCodepoint) {
30928
- assertArgument(false, `invalid codepoint at offset ${offset}; ${reason}`, "bytes", bytes2);
30929
- }
30930
- function ignoreFunc(reason, offset, bytes2, output2, badCodepoint) {
30931
- if (reason === "BAD_PREFIX" || reason === "UNEXPECTED_CONTINUE") {
30932
- let i = 0;
30933
- for (let o = offset + 1; o < bytes2.length; o++) {
30934
- if (bytes2[o] >> 6 !== 2) {
30935
- break;
30936
- }
30937
- i++;
30938
- }
30939
- return i;
30940
- }
30941
- if (reason === "OVERRUN") {
30942
- return bytes2.length - offset - 1;
30943
- }
30944
- return 0;
30945
- }
30946
- function replaceFunc(reason, offset, bytes2, output2, badCodepoint) {
30947
- if (reason === "OVERLONG") {
30948
- assertArgument(typeof badCodepoint === "number", "invalid bad code point for replacement", "badCodepoint", badCodepoint);
30949
- output2.push(badCodepoint);
30950
- return 0;
30951
- }
30952
- output2.push(65533);
30953
- return ignoreFunc(reason, offset, bytes2, output2, badCodepoint);
30954
- }
30955
- var Utf8ErrorFuncs = Object.freeze({
30956
- error: errorFunc,
30957
- ignore: ignoreFunc,
30958
- replace: replaceFunc
30959
- });
30960
- function getUtf8CodePoints(_bytes, onError) {
30961
- if (onError == null) {
30962
- onError = Utf8ErrorFuncs.error;
30963
- }
30964
- const bytes2 = getBytes(_bytes, "bytes");
30965
- const result = [];
30966
- let i = 0;
30967
- while (i < bytes2.length) {
30968
- const c = bytes2[i++];
30969
- if (c >> 7 === 0) {
30970
- result.push(c);
30971
- continue;
30972
- }
30973
- let extraLength = null;
30974
- let overlongMask = null;
30975
- if ((c & 224) === 192) {
30976
- extraLength = 1;
30977
- overlongMask = 127;
30978
- } else if ((c & 240) === 224) {
30979
- extraLength = 2;
30980
- overlongMask = 2047;
30981
- } else if ((c & 248) === 240) {
30982
- extraLength = 3;
30983
- overlongMask = 65535;
30984
- } else {
30985
- if ((c & 192) === 128) {
30986
- i += onError("UNEXPECTED_CONTINUE", i - 1, bytes2, result);
30987
- } else {
30988
- i += onError("BAD_PREFIX", i - 1, bytes2, result);
30989
- }
30990
- continue;
30991
- }
30992
- if (i - 1 + extraLength >= bytes2.length) {
30993
- i += onError("OVERRUN", i - 1, bytes2, result);
30994
- continue;
30995
- }
30996
- let res = c & (1 << 8 - extraLength - 1) - 1;
30997
- for (let j = 0; j < extraLength; j++) {
30998
- let nextChar = bytes2[i];
30999
- if ((nextChar & 192) != 128) {
31000
- i += onError("MISSING_CONTINUE", i, bytes2, result);
31001
- res = null;
31002
- break;
31003
- }
31004
- ;
31005
- res = res << 6 | nextChar & 63;
31006
- i++;
31007
- }
31008
- if (res === null) {
31009
- continue;
31010
- }
31011
- if (res > 1114111) {
31012
- i += onError("OUT_OF_RANGE", i - 1 - extraLength, bytes2, result, res);
31013
- continue;
31014
- }
31015
- if (res >= 55296 && res <= 57343) {
31016
- i += onError("UTF16_SURROGATE", i - 1 - extraLength, bytes2, result, res);
31017
- continue;
31018
- }
31019
- if (res <= overlongMask) {
31020
- i += onError("OVERLONG", i - 1 - extraLength, bytes2, result, res);
31021
- continue;
31022
- }
31023
- result.push(res);
31024
- }
31025
- return result;
31026
- }
31027
- function toUtf8Bytes(str, form) {
31028
- if (form != null) {
31029
- assertNormalize(form);
31030
- str = str.normalize(form);
31031
- }
31032
- let result = [];
31033
- for (let i = 0; i < str.length; i++) {
31034
- const c = str.charCodeAt(i);
31035
- if (c < 128) {
31036
- result.push(c);
31037
- } else if (c < 2048) {
31038
- result.push(c >> 6 | 192);
31039
- result.push(c & 63 | 128);
31040
- } else if ((c & 64512) == 55296) {
31041
- i++;
31042
- const c2 = str.charCodeAt(i);
31043
- assertArgument(i < str.length && (c2 & 64512) === 56320, "invalid surrogate pair", "str", str);
31044
- const pair = 65536 + ((c & 1023) << 10) + (c2 & 1023);
31045
- result.push(pair >> 18 | 240);
31046
- result.push(pair >> 12 & 63 | 128);
31047
- result.push(pair >> 6 & 63 | 128);
31048
- result.push(pair & 63 | 128);
31049
- } else {
31050
- result.push(c >> 12 | 224);
31051
- result.push(c >> 6 & 63 | 128);
31052
- result.push(c & 63 | 128);
31053
- }
31054
- }
31055
- return new Uint8Array(result);
31056
- }
31057
- function _toUtf8String(codePoints) {
31058
- return codePoints.map((codePoint) => {
31059
- if (codePoint <= 65535) {
31060
- return String.fromCharCode(codePoint);
31061
- }
31062
- codePoint -= 65536;
31063
- return String.fromCharCode((codePoint >> 10 & 1023) + 55296, (codePoint & 1023) + 56320);
31064
- }).join("");
31065
- }
31066
- function toUtf8String(bytes2, onError) {
31067
- return _toUtf8String(getUtf8CodePoints(bytes2, onError));
31068
- }
31069
-
31070
30877
  // ../hasher/dist/index.mjs
31071
30878
  function sha2562(data) {
31072
30879
  return hexlify(sha256(arrayify(data)));
@@ -31092,19 +30899,6 @@ This unreleased fuel-core build may include features and updates not yet support
31092
30899
  __defNormalProp4(obj, typeof key !== "symbol" ? key + "" : key, value);
31093
30900
  return value;
31094
30901
  };
31095
- var __accessCheck2 = (obj, member, msg) => {
31096
- if (!member.has(obj))
31097
- throw TypeError("Cannot " + msg);
31098
- };
31099
- var __privateAdd2 = (obj, member, value) => {
31100
- if (member.has(obj))
31101
- throw TypeError("Cannot add the same private member more than once");
31102
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
31103
- };
31104
- var __privateMethod2 = (obj, member, method) => {
31105
- __accessCheck2(obj, member, "access private method");
31106
- return method;
31107
- };
31108
30902
  var Coder = class {
31109
30903
  name;
31110
30904
  type;
@@ -31136,7 +30930,6 @@ This unreleased fuel-core build may include features and updates not yet support
31136
30930
  var enumRegEx = /^enum (?<name>\w+)$/;
31137
30931
  var tupleRegEx = /^\((?<items>.*)\)$/;
31138
30932
  var genericRegEx = /^generic (?<name>\w+)$/;
31139
- var ENCODING_V0 = "0";
31140
30933
  var ENCODING_V1 = "1";
31141
30934
  var WORD_SIZE = 8;
31142
30935
  var BYTES_32 = 32;
@@ -31147,10 +30940,6 @@ This unreleased fuel-core build may include features and updates not yet support
31147
30940
  var TX_LEN = WORD_SIZE * 4;
31148
30941
  var TX_POINTER_LEN = WORD_SIZE * 2;
31149
30942
  var MAX_BYTES = 2 ** 32 - 1;
31150
- var calculateVmTxMemory = ({ maxInputs }) => BYTES_32 + // Tx ID
31151
- ASSET_ID_LEN + // Base asset ID
31152
- // Asset ID/Balance coin input pairs
31153
- maxInputs * (ASSET_ID_LEN + WORD_SIZE) + WORD_SIZE;
31154
30943
  var SCRIPT_FIXED_SIZE = WORD_SIZE + // Identifier
31155
30944
  WORD_SIZE + // Gas limit
31156
30945
  WORD_SIZE + // Script size
@@ -31181,132 +30970,34 @@ This unreleased fuel-core build may include features and updates not yet support
31181
30970
  WORD_SIZE + // Predicate size
31182
30971
  WORD_SIZE + // Predicate data size
31183
30972
  WORD_SIZE;
31184
- var encodedLengths = {
31185
- u64: WORD_SIZE,
31186
- u256: WORD_SIZE * 4
31187
- };
31188
- var BigNumberCoder = class extends Coder {
31189
- constructor(baseType) {
31190
- super("bigNumber", baseType, encodedLengths[baseType]);
31191
- }
31192
- encode(value) {
31193
- let bytes2;
31194
- try {
31195
- bytes2 = toBytes2(value, this.encodedLength);
31196
- } catch (error) {
31197
- throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.type}.`);
31198
- }
31199
- return bytes2;
31200
- }
31201
- decode(data, offset) {
31202
- if (data.length < this.encodedLength) {
31203
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid ${this.type} data size.`);
31204
- }
31205
- let bytes2 = data.slice(offset, offset + this.encodedLength);
31206
- bytes2 = bytes2.slice(0, this.encodedLength);
31207
- if (bytes2.length !== this.encodedLength) {
31208
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid ${this.type} byte data size.`);
31209
- }
31210
- return [bn(bytes2), offset + this.encodedLength];
31211
- }
31212
- };
31213
- var VEC_PROPERTY_SPACE = 3;
31214
- var BASE_VECTOR_OFFSET = VEC_PROPERTY_SPACE * WORD_SIZE;
31215
- var RAW_SLICE_PROPERTY_SPACE = 2;
31216
- var BASE_RAW_SLICE_OFFSET = RAW_SLICE_PROPERTY_SPACE * WORD_SIZE;
31217
- function concatWithDynamicData(items) {
31218
- const topLevelData = {};
31219
- let totalIndex = 0;
31220
- const objects = items.map((item) => {
31221
- const dynamicData = item.dynamicData;
31222
- if (dynamicData) {
31223
- Object.entries(dynamicData).forEach(([pointerIndex, vData]) => {
31224
- topLevelData[parseInt(pointerIndex, 10) + totalIndex] = vData;
31225
- });
31226
- }
31227
- const byteArray = arrayify(item);
31228
- totalIndex += byteArray.byteLength / WORD_SIZE;
31229
- return byteArray;
31230
- });
31231
- const length = objects.reduce((accum, item) => accum + item.length, 0);
31232
- const result = new Uint8Array(length);
31233
- objects.reduce((offset, object) => {
31234
- result.set(object, offset);
31235
- return offset + object.length;
31236
- }, 0);
31237
- if (Object.keys(topLevelData).length) {
31238
- result.dynamicData = topLevelData;
31239
- }
31240
- return result;
31241
- }
31242
- function unpackDynamicData(results, baseOffset, dataOffset) {
31243
- if (!results.dynamicData) {
31244
- return concat([results]);
31245
- }
31246
- let cumulativeDynamicByteLength = 0;
31247
- let updatedResults = results;
31248
- Object.entries(results.dynamicData).forEach(([pointerIndex, vData]) => {
31249
- const pointerOffset = parseInt(pointerIndex, 10) * WORD_SIZE;
31250
- const adjustedValue = new BigNumberCoder("u64").encode(
31251
- dataOffset + baseOffset + cumulativeDynamicByteLength
31252
- );
31253
- updatedResults.set(adjustedValue, pointerOffset);
31254
- const dataToAppend = vData.dynamicData ? (
31255
- // unpack child dynamic data
31256
- unpackDynamicData(
31257
- vData,
31258
- baseOffset,
31259
- dataOffset + vData.byteLength + cumulativeDynamicByteLength
31260
- )
31261
- ) : vData;
31262
- updatedResults = concat([updatedResults, dataToAppend]);
31263
- cumulativeDynamicByteLength += dataToAppend.byteLength;
31264
- });
31265
- return updatedResults;
31266
- }
31267
- var chunkByLength = (data, length = WORD_SIZE) => {
31268
- const chunks = [];
31269
- let offset = 0;
31270
- let chunk = data.slice(offset, offset + length);
31271
- while (chunk.length) {
31272
- chunks.push(chunk);
31273
- offset += length;
31274
- chunk = data.slice(offset, offset + length);
31275
- }
31276
- return chunks;
31277
- };
31278
- var isPointerType = (type3) => {
31279
- switch (type3) {
31280
- case "u8":
31281
- case "u16":
31282
- case "u32":
31283
- case "u64":
31284
- case "bool": {
31285
- return false;
30973
+ var isUint8Array = (value) => value instanceof Uint8Array;
30974
+ var hasNestedOption = (coders) => {
30975
+ const array = Array.isArray(coders) ? coders : Object.values(coders);
30976
+ for (const node of array) {
30977
+ if (node.type === OPTION_CODER_TYPE) {
30978
+ return true;
31286
30979
  }
31287
- default: {
30980
+ if ("coder" in node && node.coder.type === OPTION_CODER_TYPE) {
31288
30981
  return true;
31289
30982
  }
30983
+ if ("coders" in node) {
30984
+ const child = hasNestedOption(node.coders);
30985
+ if (child) {
30986
+ return true;
30987
+ }
30988
+ }
31290
30989
  }
30990
+ return false;
31291
30991
  };
31292
- var isHeapType = (type3) => type3 === VEC_CODER_TYPE || type3 === BYTES_CODER_TYPE || type3 === STD_STRING_CODER_TYPE;
31293
- var isMultipleOfWordSize = (length) => length % WORD_SIZE === 0;
31294
- var getWordSizePadding = (length) => WORD_SIZE - length % WORD_SIZE;
31295
- var rightPadToWordSize = (encoded) => {
31296
- if (isMultipleOfWordSize(encoded.length)) {
31297
- return encoded;
31298
- }
31299
- const padding = new Uint8Array(WORD_SIZE - encoded.length % WORD_SIZE);
31300
- return concatBytes2([encoded, padding]);
31301
- };
31302
- var isUint8Array = (value) => value instanceof Uint8Array;
31303
30992
  var ArrayCoder = class extends Coder {
31304
30993
  coder;
31305
30994
  length;
30995
+ #hasNestedOption;
31306
30996
  constructor(coder, length) {
31307
30997
  super("array", `[${coder.type}; ${length}]`, length * coder.encodedLength);
31308
30998
  this.coder = coder;
31309
30999
  this.length = length;
31000
+ this.#hasNestedOption = hasNestedOption([coder]);
31310
31001
  }
31311
31002
  encode(value) {
31312
31003
  if (!Array.isArray(value)) {
@@ -31315,10 +31006,10 @@ This unreleased fuel-core build may include features and updates not yet support
31315
31006
  if (this.length !== value.length) {
31316
31007
  throw new FuelError(ErrorCode.ENCODE_ERROR, `Types/values length mismatch.`);
31317
31008
  }
31318
- return concatWithDynamicData(Array.from(value).map((v) => this.coder.encode(v)));
31009
+ return concat(Array.from(value).map((v) => this.coder.encode(v)));
31319
31010
  }
31320
31011
  decode(data, offset) {
31321
- if (data.length < this.encodedLength || data.length > MAX_BYTES) {
31012
+ if (!this.#hasNestedOption && data.length < this.encodedLength || data.length > MAX_BYTES) {
31322
31013
  throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid array data size.`);
31323
31014
  }
31324
31015
  let newOffset = offset;
@@ -31392,763 +31083,43 @@ This unreleased fuel-core build may include features and updates not yet support
31392
31083
  return [toHex(bytes2, this.encodedLength), offset + this.encodedLength];
31393
31084
  }
31394
31085
  };
31395
- var BooleanCoder = class extends Coder {
31396
- paddingLength;
31397
- options;
31398
- constructor(options = {
31399
- isSmallBytes: false,
31400
- isRightPadded: false
31401
- }) {
31402
- const paddingLength = options.isSmallBytes ? 1 : 8;
31403
- super("boolean", "boolean", paddingLength);
31404
- this.paddingLength = paddingLength;
31405
- this.options = options;
31406
- }
31407
- encode(value) {
31408
- const isTrueBool = value === true || value === false;
31409
- if (!isTrueBool) {
31410
- throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid boolean value.`);
31411
- }
31412
- const output2 = toBytes2(value ? 1 : 0, this.paddingLength);
31413
- if (this.options.isRightPadded) {
31414
- return output2.reverse();
31415
- }
31416
- return output2;
31417
- }
31418
- decode(data, offset) {
31419
- if (data.length < this.paddingLength) {
31420
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid boolean data size.`);
31421
- }
31422
- let bytes2;
31423
- if (this.options.isRightPadded) {
31424
- bytes2 = data.slice(offset, offset + 1);
31425
- } else {
31426
- bytes2 = data.slice(offset, offset + this.paddingLength);
31427
- }
31428
- const decodedValue = bn(bytes2);
31429
- if (decodedValue.isZero()) {
31430
- return [false, offset + this.paddingLength];
31431
- }
31432
- if (!decodedValue.eq(bn(1))) {
31433
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid boolean value.`);
31434
- }
31435
- return [true, offset + this.paddingLength];
31436
- }
31437
- };
31438
- var _getPaddedData;
31439
- var getPaddedData_fn;
31440
- var ByteCoder = class extends Coder {
31441
- constructor() {
31442
- super("struct", "struct Bytes", BASE_VECTOR_OFFSET);
31443
- __privateAdd2(this, _getPaddedData);
31444
- }
31445
- encode(value) {
31446
- const parts = [];
31447
- const pointer = new BigNumberCoder("u64").encode(BASE_VECTOR_OFFSET);
31448
- const data = __privateMethod2(this, _getPaddedData, getPaddedData_fn).call(this, value);
31449
- pointer.dynamicData = {
31450
- 0: concatWithDynamicData([data])
31451
- };
31452
- parts.push(pointer);
31453
- parts.push(new BigNumberCoder("u64").encode(data.byteLength));
31454
- parts.push(new BigNumberCoder("u64").encode(value.length));
31455
- return concatWithDynamicData(parts);
31456
- }
31457
- decode(data, offset) {
31458
- if (data.length < BASE_VECTOR_OFFSET) {
31459
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid byte data size.`);
31460
- }
31461
- const len = data.slice(16, 24);
31462
- const encodedLength = bn(new BigNumberCoder("u64").decode(len, 0)[0]).toNumber();
31463
- const byteData = data.slice(BASE_VECTOR_OFFSET, BASE_VECTOR_OFFSET + encodedLength);
31464
- if (byteData.length !== encodedLength) {
31465
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid bytes byte data size.`);
31466
- }
31467
- return [byteData, offset + BASE_VECTOR_OFFSET];
31468
- }
31469
- };
31470
- _getPaddedData = /* @__PURE__ */ new WeakSet();
31471
- getPaddedData_fn = function(value) {
31472
- const data = value instanceof Uint8Array ? [value] : [new Uint8Array(value)];
31473
- const paddingLength = (WORD_SIZE - value.length % WORD_SIZE) % WORD_SIZE;
31474
- if (paddingLength) {
31475
- data.push(new Uint8Array(paddingLength));
31476
- }
31477
- return concat(data);
31478
- };
31479
- __publicField4(ByteCoder, "memorySize", 1);
31480
- var isFullyNativeEnum = (enumCoders) => Object.values(enumCoders).every(
31481
- // @ts-expect-error complicated types
31482
- ({ type: type3, coders }) => type3 === "()" && JSON.stringify(coders) === JSON.stringify([])
31483
- );
31484
- var EnumCoder = class extends Coder {
31485
- name;
31486
- coders;
31487
- #caseIndexCoder;
31488
- #encodedValueSize;
31489
- constructor(name, coders) {
31490
- const caseIndexCoder = new BigNumberCoder("u64");
31491
- const encodedValueSize = Object.values(coders).reduce(
31492
- (max, coder) => Math.max(max, coder.encodedLength),
31493
- 0
31494
- );
31495
- super(`enum ${name}`, `enum ${name}`, caseIndexCoder.encodedLength + encodedValueSize);
31496
- this.name = name;
31497
- this.coders = coders;
31498
- this.#caseIndexCoder = caseIndexCoder;
31499
- this.#encodedValueSize = encodedValueSize;
31500
- }
31501
- #encodeNativeEnum(value) {
31502
- const valueCoder = this.coders[value];
31503
- const encodedValue = valueCoder.encode([]);
31504
- const caseIndex = Object.keys(this.coders).indexOf(value);
31505
- const padding = new Uint8Array(this.#encodedValueSize - valueCoder.encodedLength);
31506
- return concat([this.#caseIndexCoder.encode(caseIndex), padding, encodedValue]);
31507
- }
31508
- encode(value) {
31509
- if (typeof value === "string" && this.coders[value]) {
31510
- return this.#encodeNativeEnum(value);
31511
- }
31512
- const [caseKey, ...empty] = Object.keys(value);
31513
- if (!caseKey) {
31514
- throw new FuelError(ErrorCode.INVALID_DECODE_VALUE, "A field for the case must be provided.");
31515
- }
31516
- if (empty.length !== 0) {
31517
- throw new FuelError(ErrorCode.INVALID_DECODE_VALUE, "Only one field must be provided.");
31518
- }
31519
- const valueCoder = this.coders[caseKey];
31520
- const caseIndex = Object.keys(this.coders).indexOf(caseKey);
31521
- const encodedValue = valueCoder.encode(value[caseKey]);
31522
- const padding = new Uint8Array(this.#encodedValueSize - valueCoder.encodedLength);
31523
- return concatWithDynamicData([this.#caseIndexCoder.encode(caseIndex), padding, encodedValue]);
31524
- }
31525
- #decodeNativeEnum(caseKey, newOffset) {
31526
- return [caseKey, newOffset];
31527
- }
31528
- decode(data, offset) {
31529
- if (data.length < this.#encodedValueSize) {
31530
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid enum data size.`);
31531
- }
31532
- let newOffset = offset;
31533
- let decoded;
31534
- [decoded, newOffset] = new BigNumberCoder("u64").decode(data, newOffset);
31535
- const caseIndex = toNumber(decoded);
31536
- const caseKey = Object.keys(this.coders)[caseIndex];
31537
- if (!caseKey) {
31538
- throw new FuelError(
31539
- ErrorCode.INVALID_DECODE_VALUE,
31540
- `Invalid caseIndex "${caseIndex}". Valid cases: ${Object.keys(this.coders)}.`
31541
- );
31542
- }
31543
- const valueCoder = this.coders[caseKey];
31544
- const padding = this.#encodedValueSize - valueCoder.encodedLength;
31545
- newOffset += padding;
31546
- [decoded, newOffset] = valueCoder.decode(data, newOffset);
31547
- if (isFullyNativeEnum(this.coders)) {
31548
- return this.#decodeNativeEnum(caseKey, newOffset);
31549
- }
31550
- return [{ [caseKey]: decoded }, newOffset];
31551
- }
31552
- };
31553
- var OptionCoder = class extends EnumCoder {
31554
- encode(value) {
31555
- const result = super.encode(this.toSwayOption(value));
31556
- return result;
31557
- }
31558
- toSwayOption(input) {
31559
- if (input !== void 0) {
31560
- return { Some: input };
31561
- }
31562
- return { None: [] };
31563
- }
31564
- decode(data, offset) {
31565
- if (data.length < this.encodedLength) {
31566
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid option data size.`);
31567
- }
31568
- const [decoded, newOffset] = super.decode(data, offset);
31569
- return [this.toOption(decoded), newOffset];
31570
- }
31571
- toOption(output2) {
31572
- if (output2 && "Some" in output2) {
31573
- return output2.Some;
31574
- }
31575
- return void 0;
31576
- }
31086
+ var encodedLengths = {
31087
+ u64: WORD_SIZE,
31088
+ u256: WORD_SIZE * 4
31577
31089
  };
31578
- var NumberCoder = class extends Coder {
31579
- // This is to align the bits to the total bytes
31580
- // See https://github.com/FuelLabs/fuel-specs/blob/master/specs/protocol/abi.md#unsigned-integers
31581
- length;
31582
- paddingLength;
31583
- baseType;
31584
- options;
31585
- constructor(baseType, options = {
31586
- isSmallBytes: false,
31587
- isRightPadded: false
31588
- }) {
31589
- const paddingLength = options.isSmallBytes && baseType === "u8" ? 1 : 8;
31590
- super("number", baseType, paddingLength);
31591
- this.baseType = baseType;
31592
- switch (baseType) {
31593
- case "u8":
31594
- this.length = 1;
31595
- break;
31596
- case "u16":
31597
- this.length = 2;
31598
- break;
31599
- case "u32":
31600
- default:
31601
- this.length = 4;
31602
- break;
31603
- }
31604
- this.paddingLength = paddingLength;
31605
- this.options = options;
31090
+ var BigNumberCoder = class extends Coder {
31091
+ constructor(baseType) {
31092
+ super("bigNumber", baseType, encodedLengths[baseType]);
31606
31093
  }
31607
31094
  encode(value) {
31608
31095
  let bytes2;
31609
31096
  try {
31610
- bytes2 = toBytes2(value);
31097
+ bytes2 = toBytes2(value, this.encodedLength);
31611
31098
  } catch (error) {
31612
- throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.baseType}.`);
31613
- }
31614
- if (bytes2.length > this.length) {
31615
- throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.baseType}, too many bytes.`);
31616
- }
31617
- const output2 = toBytes2(bytes2, this.paddingLength);
31618
- if (this.baseType !== "u8") {
31619
- return output2;
31620
- }
31621
- return this.options.isRightPadded ? output2.reverse() : output2;
31622
- }
31623
- decodeU8(data, offset) {
31624
- let bytes2;
31625
- if (this.options.isRightPadded) {
31626
- bytes2 = data.slice(offset, offset + 1);
31627
- } else {
31628
- bytes2 = data.slice(offset, offset + this.paddingLength);
31629
- bytes2 = bytes2.slice(this.paddingLength - this.length, this.paddingLength);
31630
- }
31631
- return [toNumber(bytes2), offset + this.paddingLength];
31632
- }
31633
- decode(data, offset) {
31634
- if (data.length < this.paddingLength) {
31635
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid number data size.`);
31636
- }
31637
- if (this.baseType === "u8") {
31638
- return this.decodeU8(data, offset);
31639
- }
31640
- let bytes2 = data.slice(offset, offset + this.paddingLength);
31641
- bytes2 = bytes2.slice(8 - this.length, 8);
31642
- if (bytes2.length !== this.paddingLength - (this.paddingLength - this.length)) {
31643
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid number byte data size.`);
31644
- }
31645
- return [toNumber(bytes2), offset + 8];
31646
- }
31647
- };
31648
- var RawSliceCoder = class extends Coder {
31649
- constructor() {
31650
- super("raw untyped slice", "raw untyped slice", BASE_RAW_SLICE_OFFSET);
31651
- }
31652
- encode(value) {
31653
- if (!Array.isArray(value)) {
31654
- throw new FuelError(ErrorCode.ENCODE_ERROR, `Expected array value.`);
31655
- }
31656
- const parts = [];
31657
- const coder = new NumberCoder("u8", { isSmallBytes: true });
31658
- const pointer = new BigNumberCoder("u64").encode(
31659
- BASE_RAW_SLICE_OFFSET
31660
- );
31661
- pointer.dynamicData = {
31662
- 0: concatWithDynamicData(value.map((v) => coder.encode(v)))
31663
- };
31664
- parts.push(pointer);
31665
- parts.push(new BigNumberCoder("u64").encode(value.length));
31666
- return concatWithDynamicData(parts);
31667
- }
31668
- decode(data, offset) {
31669
- const dataBytes = data.slice(offset);
31670
- const internalCoder = new ArrayCoder(
31671
- new NumberCoder("u8", { isSmallBytes: true }),
31672
- dataBytes.length
31673
- );
31674
- const [decodedValue] = internalCoder.decode(dataBytes, 0);
31675
- return [decodedValue, offset + dataBytes.length];
31676
- }
31677
- };
31678
- var _getPaddedData2;
31679
- var getPaddedData_fn2;
31680
- var StdStringCoder = class extends Coder {
31681
- constructor() {
31682
- super("struct", "struct String", 1);
31683
- __privateAdd2(this, _getPaddedData2);
31684
- }
31685
- encode(value) {
31686
- const parts = [];
31687
- const pointer = new BigNumberCoder("u64").encode(BASE_VECTOR_OFFSET);
31688
- const data = __privateMethod2(this, _getPaddedData2, getPaddedData_fn2).call(this, value);
31689
- pointer.dynamicData = {
31690
- 0: concatWithDynamicData([data])
31691
- };
31692
- parts.push(pointer);
31693
- parts.push(new BigNumberCoder("u64").encode(data.byteLength));
31694
- parts.push(new BigNumberCoder("u64").encode(value.length));
31695
- return concatWithDynamicData(parts);
31696
- }
31697
- decode(data, offset) {
31698
- if (data.length < this.encodedLength) {
31699
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid std string data size.`);
31700
- }
31701
- const len = data.slice(16, 24);
31702
- const encodedLength = bn(new BigNumberCoder("u64").decode(len, 0)[0]).toNumber();
31703
- const byteData = data.slice(BASE_VECTOR_OFFSET, BASE_VECTOR_OFFSET + encodedLength);
31704
- if (byteData.length !== encodedLength) {
31705
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid std string byte data size.`);
31706
- }
31707
- const value = toUtf8String(byteData);
31708
- return [value, offset + BASE_VECTOR_OFFSET];
31709
- }
31710
- };
31711
- _getPaddedData2 = /* @__PURE__ */ new WeakSet();
31712
- getPaddedData_fn2 = function(value) {
31713
- const data = [toUtf8Bytes(value)];
31714
- const paddingLength = (WORD_SIZE - value.length % WORD_SIZE) % WORD_SIZE;
31715
- if (paddingLength) {
31716
- data.push(new Uint8Array(paddingLength));
31717
- }
31718
- return concat(data);
31719
- };
31720
- __publicField4(StdStringCoder, "memorySize", 1);
31721
- var StringCoder = class extends Coder {
31722
- length;
31723
- #paddingLength;
31724
- constructor(length) {
31725
- let paddingLength = (8 - length) % 8;
31726
- paddingLength = paddingLength < 0 ? paddingLength + 8 : paddingLength;
31727
- super("string", `str[${length}]`, length + paddingLength);
31728
- this.length = length;
31729
- this.#paddingLength = paddingLength;
31730
- }
31731
- encode(value) {
31732
- if (this.length !== value.length) {
31733
- throw new FuelError(ErrorCode.ENCODE_ERROR, `Value length mismatch during encode.`);
31734
- }
31735
- const encoded = toUtf8Bytes(value);
31736
- const padding = new Uint8Array(this.#paddingLength);
31737
- return concat([encoded, padding]);
31738
- }
31739
- decode(data, offset) {
31740
- if (data.length < this.encodedLength) {
31741
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid string data size.`);
31742
- }
31743
- const bytes2 = data.slice(offset, offset + this.length);
31744
- if (bytes2.length !== this.length) {
31745
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid string byte data size.`);
31746
- }
31747
- const value = toUtf8String(bytes2);
31748
- const padding = this.#paddingLength;
31749
- return [value, offset + this.length + padding];
31750
- }
31751
- };
31752
- var StructCoder = class extends Coder {
31753
- name;
31754
- coders;
31755
- constructor(name, coders) {
31756
- const encodedLength = Object.values(coders).reduce(
31757
- (acc, coder) => acc + coder.encodedLength,
31758
- 0
31759
- );
31760
- super("struct", `struct ${name}`, encodedLength);
31761
- this.name = name;
31762
- this.coders = coders;
31763
- }
31764
- encode(value) {
31765
- const encodedFields = Object.keys(this.coders).map((fieldName) => {
31766
- const fieldCoder = this.coders[fieldName];
31767
- const fieldValue = value[fieldName];
31768
- if (!(fieldCoder instanceof OptionCoder) && fieldValue == null) {
31769
- throw new FuelError(
31770
- ErrorCode.ENCODE_ERROR,
31771
- `Invalid ${this.type}. Field "${fieldName}" not present.`
31772
- );
31773
- }
31774
- const encoded = fieldCoder.encode(fieldValue);
31775
- if (!isMultipleOfWordSize(encoded.length)) {
31776
- return rightPadToWordSize(encoded);
31777
- }
31778
- return encoded;
31779
- });
31780
- return concatWithDynamicData([concatWithDynamicData(encodedFields)]);
31781
- }
31782
- decode(data, offset) {
31783
- if (data.length < this.encodedLength) {
31784
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid struct data size.`);
31785
- }
31786
- let newOffset = offset;
31787
- const decodedValue = Object.keys(this.coders).reduce((obj, fieldName) => {
31788
- const fieldCoder = this.coders[fieldName];
31789
- let decoded;
31790
- [decoded, newOffset] = fieldCoder.decode(data, newOffset);
31791
- if (!isMultipleOfWordSize(newOffset)) {
31792
- newOffset += getWordSizePadding(newOffset);
31793
- }
31794
- obj[fieldName] = decoded;
31795
- return obj;
31796
- }, {});
31797
- return [decodedValue, newOffset];
31798
- }
31799
- };
31800
- var TupleCoder = class extends Coder {
31801
- coders;
31802
- constructor(coders) {
31803
- const encodedLength = coders.reduce((acc, coder) => acc + coder.encodedLength, 0);
31804
- super("tuple", `(${coders.map((coder) => coder.type).join(", ")})`, encodedLength);
31805
- this.coders = coders;
31806
- }
31807
- encode(value) {
31808
- if (this.coders.length !== value.length) {
31809
- throw new FuelError(ErrorCode.ENCODE_ERROR, `Types/values length mismatch.`);
31099
+ throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.type}.`);
31810
31100
  }
31811
- return concatWithDynamicData(
31812
- this.coders.map((coder, i) => {
31813
- const encoded = coder.encode(value[i]);
31814
- if (!isMultipleOfWordSize(encoded.length)) {
31815
- return rightPadToWordSize(encoded);
31816
- }
31817
- return encoded;
31818
- })
31819
- );
31101
+ return bytes2;
31820
31102
  }
31821
31103
  decode(data, offset) {
31822
31104
  if (data.length < this.encodedLength) {
31823
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid tuple data size.`);
31824
- }
31825
- let newOffset = offset;
31826
- const decodedValue = this.coders.map((coder) => {
31827
- let decoded;
31828
- [decoded, newOffset] = coder.decode(data, newOffset);
31829
- if (!isMultipleOfWordSize(newOffset)) {
31830
- newOffset += getWordSizePadding(newOffset);
31831
- }
31832
- return decoded;
31833
- });
31834
- return [decodedValue, newOffset];
31835
- }
31836
- };
31837
- var VecCoder = class extends Coder {
31838
- coder;
31839
- constructor(coder) {
31840
- super("struct", `struct Vec`, coder.encodedLength + BASE_VECTOR_OFFSET);
31841
- this.coder = coder;
31842
- }
31843
- encode(value) {
31844
- if (!Array.isArray(value) && !isUint8Array(value)) {
31845
- throw new FuelError(
31846
- ErrorCode.ENCODE_ERROR,
31847
- `Expected array value, or a Uint8Array. You can use arrayify to convert a value to a Uint8Array.`
31848
- );
31849
- }
31850
- const parts = [];
31851
- const pointer = new BigNumberCoder("u64").encode(BASE_VECTOR_OFFSET);
31852
- pointer.dynamicData = {
31853
- 0: concatWithDynamicData(Array.from(value).map((v) => this.coder.encode(v)))
31854
- };
31855
- parts.push(pointer);
31856
- parts.push(new BigNumberCoder("u64").encode(value.length));
31857
- parts.push(new BigNumberCoder("u64").encode(value.length));
31858
- return concatWithDynamicData(parts);
31859
- }
31860
- decode(data, offset) {
31861
- if (data.length < BASE_VECTOR_OFFSET || data.length > MAX_BYTES) {
31862
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid vec data size.`);
31863
- }
31864
- const len = data.slice(16, 24);
31865
- const encodedLength = bn(new BigNumberCoder("u64").decode(len, 0)[0]).toNumber();
31866
- const vectorRawDataLength = encodedLength * this.coder.encodedLength;
31867
- const vectorRawData = data.slice(BASE_VECTOR_OFFSET, BASE_VECTOR_OFFSET + vectorRawDataLength);
31868
- if (vectorRawData.length !== vectorRawDataLength) {
31869
- throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid vec byte data size.`);
31870
- }
31871
- return [
31872
- chunkByLength(vectorRawData, this.coder.encodedLength).map(
31873
- (chunk) => this.coder.decode(chunk, 0)[0]
31874
- ),
31875
- offset + BASE_VECTOR_OFFSET
31876
- ];
31877
- }
31878
- };
31879
- var getEncodingVersion = (encoding) => {
31880
- switch (encoding) {
31881
- case void 0:
31882
- case ENCODING_V0:
31883
- return ENCODING_V0;
31884
- case ENCODING_V1:
31885
- return ENCODING_V1;
31886
- default:
31887
- throw new FuelError(
31888
- ErrorCode.UNSUPPORTED_ENCODING_VERSION,
31889
- `Encoding version '${encoding}' is unsupported.`
31890
- );
31891
- }
31892
- };
31893
- var findFunctionByName = (abi, name) => {
31894
- const fn = abi.functions.find((f2) => f2.name === name);
31895
- if (!fn) {
31896
- throw new FuelError(
31897
- ErrorCode.FUNCTION_NOT_FOUND,
31898
- `Function with name '${name}' doesn't exist in the ABI`
31899
- );
31900
- }
31901
- return fn;
31902
- };
31903
- var findTypeById = (abi, typeId) => {
31904
- const type3 = abi.types.find((t) => t.typeId === typeId);
31905
- if (!type3) {
31906
- throw new FuelError(
31907
- ErrorCode.TYPE_NOT_FOUND,
31908
- `Type with typeId '${typeId}' doesn't exist in the ABI.`
31909
- );
31910
- }
31911
- return type3;
31912
- };
31913
- var findNonEmptyInputs = (abi, inputs) => inputs.filter((input) => findTypeById(abi, input.type).type !== "()");
31914
- var findVectorBufferArgument = (components) => {
31915
- const bufferComponent = components.find((c) => c.name === "buf");
31916
- const bufferTypeArgument = bufferComponent?.originalTypeArguments?.[0];
31917
- if (!bufferComponent || !bufferTypeArgument) {
31918
- throw new FuelError(
31919
- ErrorCode.INVALID_COMPONENT,
31920
- `The Vec type provided is missing or has a malformed 'buf' component.`
31921
- );
31922
- }
31923
- return bufferTypeArgument;
31924
- };
31925
- var ResolvedAbiType = class {
31926
- abi;
31927
- name;
31928
- type;
31929
- originalTypeArguments;
31930
- components;
31931
- constructor(abi, argument) {
31932
- this.abi = abi;
31933
- this.name = argument.name;
31934
- const type3 = findTypeById(abi, argument.type);
31935
- this.type = type3.type;
31936
- this.originalTypeArguments = argument.typeArguments;
31937
- this.components = ResolvedAbiType.getResolvedGenericComponents(
31938
- abi,
31939
- argument,
31940
- type3.components,
31941
- type3.typeParameters ?? ResolvedAbiType.getImplicitGenericTypeParameters(abi, type3.components)
31942
- );
31943
- }
31944
- static getResolvedGenericComponents(abi, arg, components, typeParameters) {
31945
- if (components === null) {
31946
- return null;
31947
- }
31948
- if (typeParameters === null || typeParameters.length === 0) {
31949
- return components.map((c) => new ResolvedAbiType(abi, c));
31950
- }
31951
- const typeParametersAndArgsMap = typeParameters.reduce(
31952
- (obj, typeParameter, typeParameterIndex) => {
31953
- const o = { ...obj };
31954
- o[typeParameter] = structuredClone(
31955
- arg.typeArguments?.[typeParameterIndex]
31956
- );
31957
- return o;
31958
- },
31959
- {}
31960
- );
31961
- const resolvedComponents = this.resolveGenericArgTypes(
31962
- abi,
31963
- components,
31964
- typeParametersAndArgsMap
31965
- );
31966
- return resolvedComponents.map((c) => new ResolvedAbiType(abi, c));
31967
- }
31968
- static resolveGenericArgTypes(abi, args, typeParametersAndArgsMap) {
31969
- return args.map((arg) => {
31970
- if (typeParametersAndArgsMap[arg.type] !== void 0) {
31971
- return {
31972
- ...typeParametersAndArgsMap[arg.type],
31973
- name: arg.name
31974
- };
31975
- }
31976
- if (arg.typeArguments) {
31977
- return {
31978
- ...structuredClone(arg),
31979
- typeArguments: this.resolveGenericArgTypes(
31980
- abi,
31981
- arg.typeArguments,
31982
- typeParametersAndArgsMap
31983
- )
31984
- };
31985
- }
31986
- const argType = findTypeById(abi, arg.type);
31987
- const implicitTypeParameters = this.getImplicitGenericTypeParameters(abi, argType.components);
31988
- if (implicitTypeParameters && implicitTypeParameters.length > 0) {
31989
- return {
31990
- ...structuredClone(arg),
31991
- typeArguments: implicitTypeParameters.map((itp) => typeParametersAndArgsMap[itp])
31992
- };
31993
- }
31994
- return arg;
31995
- });
31996
- }
31997
- static getImplicitGenericTypeParameters(abi, args, implicitGenericParametersParam) {
31998
- if (!Array.isArray(args)) {
31999
- return null;
32000
- }
32001
- const implicitGenericParameters = implicitGenericParametersParam ?? [];
32002
- args.forEach((a) => {
32003
- const argType = findTypeById(abi, a.type);
32004
- if (genericRegEx.test(argType.type)) {
32005
- implicitGenericParameters.push(argType.typeId);
32006
- return;
32007
- }
32008
- if (!Array.isArray(a.typeArguments)) {
32009
- return;
32010
- }
32011
- this.getImplicitGenericTypeParameters(abi, a.typeArguments, implicitGenericParameters);
32012
- });
32013
- return implicitGenericParameters.length > 0 ? implicitGenericParameters : null;
32014
- }
32015
- getSignature() {
32016
- const prefix = this.getArgSignaturePrefix();
32017
- const content = this.getArgSignatureContent();
32018
- return `${prefix}${content}`;
32019
- }
32020
- getArgSignaturePrefix() {
32021
- const structMatch = structRegEx.test(this.type);
32022
- if (structMatch) {
32023
- return "s";
32024
- }
32025
- const arrayMatch = arrayRegEx.test(this.type);
32026
- if (arrayMatch) {
32027
- return "a";
32028
- }
32029
- const enumMatch = enumRegEx.test(this.type);
32030
- if (enumMatch) {
32031
- return "e";
32032
- }
32033
- return "";
32034
- }
32035
- getArgSignatureContent() {
32036
- if (this.type === "raw untyped ptr") {
32037
- return "rawptr";
32038
- }
32039
- if (this.type === "raw untyped slice") {
32040
- return "rawslice";
32041
- }
32042
- const strMatch = stringRegEx.exec(this.type)?.groups;
32043
- if (strMatch) {
32044
- return `str[${strMatch.length}]`;
32045
- }
32046
- if (this.components === null) {
32047
- return this.type;
32048
- }
32049
- const arrayMatch = arrayRegEx.exec(this.type)?.groups;
32050
- if (arrayMatch) {
32051
- return `[${this.components[0].getSignature()};${arrayMatch.length}]`;
32052
- }
32053
- const typeArgumentsSignature = this.originalTypeArguments !== null ? `<${this.originalTypeArguments.map((a) => new ResolvedAbiType(this.abi, a).getSignature()).join(",")}>` : "";
32054
- const componentsSignature = `(${this.components.map((c) => c.getSignature()).join(",")})`;
32055
- return `${typeArgumentsSignature}${componentsSignature}`;
32056
- }
32057
- };
32058
- function getCoders(components, options) {
32059
- const { getCoder: getCoder3 } = options;
32060
- return components.reduce((obj, component) => {
32061
- const o = obj;
32062
- o[component.name] = getCoder3(component, options);
32063
- return o;
32064
- }, {});
32065
- }
32066
- var getCoder = (resolvedAbiType, options) => {
32067
- switch (resolvedAbiType.type) {
32068
- case U8_CODER_TYPE:
32069
- case U16_CODER_TYPE:
32070
- case U32_CODER_TYPE:
32071
- return new NumberCoder(resolvedAbiType.type, options);
32072
- case U64_CODER_TYPE:
32073
- case RAW_PTR_CODER_TYPE:
32074
- return new BigNumberCoder("u64");
32075
- case U256_CODER_TYPE:
32076
- return new BigNumberCoder("u256");
32077
- case RAW_SLICE_CODER_TYPE:
32078
- return new RawSliceCoder();
32079
- case BOOL_CODER_TYPE:
32080
- return new BooleanCoder(options);
32081
- case B256_CODER_TYPE:
32082
- return new B256Coder();
32083
- case B512_CODER_TYPE:
32084
- return new B512Coder();
32085
- case BYTES_CODER_TYPE:
32086
- return new ByteCoder();
32087
- case STD_STRING_CODER_TYPE:
32088
- return new StdStringCoder();
32089
- default:
32090
- break;
32091
- }
32092
- const stringMatch = stringRegEx.exec(resolvedAbiType.type)?.groups;
32093
- if (stringMatch) {
32094
- const length = parseInt(stringMatch.length, 10);
32095
- return new StringCoder(length);
32096
- }
32097
- const components = resolvedAbiType.components;
32098
- const arrayMatch = arrayRegEx.exec(resolvedAbiType.type)?.groups;
32099
- if (arrayMatch) {
32100
- const length = parseInt(arrayMatch.length, 10);
32101
- const arg = components[0];
32102
- if (!arg) {
32103
- throw new FuelError(
32104
- ErrorCode.INVALID_COMPONENT,
32105
- `The provided Array type is missing an item of 'component'.`
32106
- );
31105
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid ${this.type} data size.`);
32107
31106
  }
32108
- const arrayElementCoder = getCoder(arg, { isSmallBytes: true });
32109
- return new ArrayCoder(arrayElementCoder, length);
32110
- }
32111
- if (resolvedAbiType.type === VEC_CODER_TYPE) {
32112
- const arg = findVectorBufferArgument(components);
32113
- const argType = new ResolvedAbiType(resolvedAbiType.abi, arg);
32114
- const itemCoder = getCoder(argType, { isSmallBytes: true, encoding: ENCODING_V0 });
32115
- return new VecCoder(itemCoder);
32116
- }
32117
- const structMatch = structRegEx.exec(resolvedAbiType.type)?.groups;
32118
- if (structMatch) {
32119
- const coders = getCoders(components, { isRightPadded: true, getCoder });
32120
- return new StructCoder(structMatch.name, coders);
32121
- }
32122
- const enumMatch = enumRegEx.exec(resolvedAbiType.type)?.groups;
32123
- if (enumMatch) {
32124
- const coders = getCoders(components, { getCoder });
32125
- const isOptionEnum = resolvedAbiType.type === OPTION_CODER_TYPE;
32126
- if (isOptionEnum) {
32127
- return new OptionCoder(enumMatch.name, coders);
31107
+ let bytes2 = data.slice(offset, offset + this.encodedLength);
31108
+ bytes2 = bytes2.slice(0, this.encodedLength);
31109
+ if (bytes2.length !== this.encodedLength) {
31110
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid ${this.type} byte data size.`);
32128
31111
  }
32129
- return new EnumCoder(enumMatch.name, coders);
32130
- }
32131
- const tupleMatch = tupleRegEx.exec(resolvedAbiType.type)?.groups;
32132
- if (tupleMatch) {
32133
- const coders = components.map(
32134
- (component) => getCoder(component, { isRightPadded: true, encoding: ENCODING_V0 })
32135
- );
32136
- return new TupleCoder(coders);
32137
- }
32138
- if (resolvedAbiType.type === STR_SLICE_CODER_TYPE) {
32139
- throw new FuelError(
32140
- ErrorCode.INVALID_DATA,
32141
- "String slices can not be decoded from logs. Convert the slice to `str[N]` with `__to_str_array`"
32142
- );
31112
+ return [bn(bytes2), offset + this.encodedLength];
32143
31113
  }
32144
- throw new FuelError(
32145
- ErrorCode.CODER_NOT_FOUND,
32146
- `Coder not found: ${JSON.stringify(resolvedAbiType)}.`
32147
- );
32148
31114
  };
32149
- var BooleanCoder2 = class extends Coder {
32150
- constructor() {
32151
- super("boolean", "boolean", 1);
31115
+ var BooleanCoder = class extends Coder {
31116
+ options;
31117
+ constructor(options = {
31118
+ padToWordSize: false
31119
+ }) {
31120
+ const encodedLength = options.padToWordSize ? WORD_SIZE : 1;
31121
+ super("boolean", "boolean", encodedLength);
31122
+ this.options = options;
32152
31123
  }
32153
31124
  encode(value) {
32154
31125
  const isTrueBool = value === true || value === false;
@@ -32171,7 +31142,7 @@ This unreleased fuel-core build may include features and updates not yet support
32171
31142
  return [true, offset + this.encodedLength];
32172
31143
  }
32173
31144
  };
32174
- var ByteCoder2 = class extends Coder {
31145
+ var ByteCoder = class extends Coder {
32175
31146
  constructor() {
32176
31147
  super("struct", "struct Bytes", WORD_SIZE);
32177
31148
  }
@@ -32194,16 +31165,17 @@ This unreleased fuel-core build may include features and updates not yet support
32194
31165
  return [dataBytes, offsetAndLength + length];
32195
31166
  }
32196
31167
  };
32197
- __publicField4(ByteCoder2, "memorySize", 1);
32198
- var isFullyNativeEnum2 = (enumCoders) => Object.values(enumCoders).every(
31168
+ __publicField4(ByteCoder, "memorySize", 1);
31169
+ var isFullyNativeEnum = (enumCoders) => Object.values(enumCoders).every(
32199
31170
  // @ts-expect-error complicated types
32200
31171
  ({ type: type3, coders }) => type3 === "()" && JSON.stringify(coders) === JSON.stringify([])
32201
31172
  );
32202
- var EnumCoder2 = class extends Coder {
31173
+ var EnumCoder = class extends Coder {
32203
31174
  name;
32204
31175
  coders;
32205
31176
  #caseIndexCoder;
32206
31177
  #encodedValueSize;
31178
+ #hasNestedOption;
32207
31179
  constructor(name, coders) {
32208
31180
  const caseIndexCoder = new BigNumberCoder("u64");
32209
31181
  const encodedValueSize = Object.values(coders).reduce(
@@ -32215,6 +31187,7 @@ This unreleased fuel-core build may include features and updates not yet support
32215
31187
  this.coders = coders;
32216
31188
  this.#caseIndexCoder = caseIndexCoder;
32217
31189
  this.#encodedValueSize = encodedValueSize;
31190
+ this.#hasNestedOption = hasNestedOption(coders);
32218
31191
  }
32219
31192
  #encodeNativeEnum(value) {
32220
31193
  const valueCoder = this.coders[value];
@@ -32243,7 +31216,7 @@ This unreleased fuel-core build may include features and updates not yet support
32243
31216
  return [caseKey, newOffset];
32244
31217
  }
32245
31218
  decode(data, offset) {
32246
- if (data.length < this.#encodedValueSize) {
31219
+ if (!this.#hasNestedOption && data.length < this.#encodedValueSize) {
32247
31220
  throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid enum data size.`);
32248
31221
  }
32249
31222
  const caseBytes = new BigNumberCoder("u64").decode(data, offset)[0];
@@ -32258,7 +31231,7 @@ This unreleased fuel-core build may include features and updates not yet support
32258
31231
  const valueCoder = this.coders[caseKey];
32259
31232
  const offsetAndCase = offset + WORD_SIZE;
32260
31233
  const [decoded, newOffset] = valueCoder.decode(data, offsetAndCase);
32261
- if (isFullyNativeEnum2(this.coders)) {
31234
+ if (isFullyNativeEnum(this.coders)) {
32262
31235
  return this.#decodeNativeEnum(caseKey, newOffset);
32263
31236
  }
32264
31237
  return [{ [caseKey]: decoded }, newOffset];
@@ -32276,14 +31249,16 @@ This unreleased fuel-core build may include features and updates not yet support
32276
31249
  throw new FuelError(ErrorCode.TYPE_NOT_SUPPORTED, `Invalid number type: ${baseType}`);
32277
31250
  }
32278
31251
  };
32279
- var NumberCoder2 = class extends Coder {
32280
- length;
31252
+ var NumberCoder = class extends Coder {
32281
31253
  baseType;
32282
- constructor(baseType) {
32283
- const length = getLength(baseType);
31254
+ options;
31255
+ constructor(baseType, options = {
31256
+ padToWordSize: false
31257
+ }) {
31258
+ const length = options.padToWordSize ? WORD_SIZE : getLength(baseType);
32284
31259
  super("number", baseType, length);
32285
31260
  this.baseType = baseType;
32286
- this.length = length;
31261
+ this.options = options;
32287
31262
  }
32288
31263
  encode(value) {
32289
31264
  let bytes2;
@@ -32292,23 +31267,23 @@ This unreleased fuel-core build may include features and updates not yet support
32292
31267
  } catch (error) {
32293
31268
  throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.baseType}.`);
32294
31269
  }
32295
- if (bytes2.length > this.length) {
31270
+ if (bytes2.length > this.encodedLength) {
32296
31271
  throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.baseType}, too many bytes.`);
32297
31272
  }
32298
- return toBytes2(bytes2, this.length);
31273
+ return toBytes2(bytes2, this.encodedLength);
32299
31274
  }
32300
31275
  decode(data, offset) {
32301
31276
  if (data.length < this.encodedLength) {
32302
31277
  throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid number data size.`);
32303
31278
  }
32304
- const bytes2 = data.slice(offset, offset + this.length);
31279
+ const bytes2 = data.slice(offset, offset + this.encodedLength);
32305
31280
  if (bytes2.length !== this.encodedLength) {
32306
31281
  throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid number byte data size.`);
32307
31282
  }
32308
- return [toNumber(bytes2), offset + this.length];
31283
+ return [toNumber(bytes2), offset + this.encodedLength];
32309
31284
  }
32310
31285
  };
32311
- var OptionCoder2 = class extends EnumCoder2 {
31286
+ var OptionCoder = class extends EnumCoder {
32312
31287
  encode(value) {
32313
31288
  const result = super.encode(this.toSwayOption(value));
32314
31289
  return result;
@@ -32330,7 +31305,7 @@ This unreleased fuel-core build may include features and updates not yet support
32330
31305
  return void 0;
32331
31306
  }
32332
31307
  };
32333
- var RawSliceCoder2 = class extends Coder {
31308
+ var RawSliceCoder = class extends Coder {
32334
31309
  constructor() {
32335
31310
  super("raw untyped slice", "raw untyped slice", WORD_SIZE);
32336
31311
  }
@@ -32338,7 +31313,7 @@ This unreleased fuel-core build may include features and updates not yet support
32338
31313
  if (!Array.isArray(value)) {
32339
31314
  throw new FuelError(ErrorCode.ENCODE_ERROR, `Expected array value.`);
32340
31315
  }
32341
- const internalCoder = new ArrayCoder(new NumberCoder2("u8"), value.length);
31316
+ const internalCoder = new ArrayCoder(new NumberCoder("u8"), value.length);
32342
31317
  const bytes2 = internalCoder.encode(value);
32343
31318
  const lengthBytes = new BigNumberCoder("u64").encode(bytes2.length);
32344
31319
  return new Uint8Array([...lengthBytes, ...bytes2]);
@@ -32354,12 +31329,12 @@ This unreleased fuel-core build may include features and updates not yet support
32354
31329
  if (dataBytes.length !== length) {
32355
31330
  throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid raw slice byte data size.`);
32356
31331
  }
32357
- const internalCoder = new ArrayCoder(new NumberCoder2("u8"), length);
31332
+ const internalCoder = new ArrayCoder(new NumberCoder("u8"), length);
32358
31333
  const [decodedValue] = internalCoder.decode(dataBytes, 0);
32359
31334
  return [decodedValue, offsetAndLength + length];
32360
31335
  }
32361
31336
  };
32362
- var StdStringCoder2 = class extends Coder {
31337
+ var StdStringCoder = class extends Coder {
32363
31338
  constructor() {
32364
31339
  super("struct", "struct String", WORD_SIZE);
32365
31340
  }
@@ -32382,7 +31357,7 @@ This unreleased fuel-core build may include features and updates not yet support
32382
31357
  return [toUtf8String(dataBytes), offsetAndLength + length];
32383
31358
  }
32384
31359
  };
32385
- __publicField4(StdStringCoder2, "memorySize", 1);
31360
+ __publicField4(StdStringCoder, "memorySize", 1);
32386
31361
  var StrSliceCoder = class extends Coder {
32387
31362
  constructor() {
32388
31363
  super("strSlice", "str", WORD_SIZE);
@@ -32407,7 +31382,7 @@ This unreleased fuel-core build may include features and updates not yet support
32407
31382
  }
32408
31383
  };
32409
31384
  __publicField4(StrSliceCoder, "memorySize", 1);
32410
- var StringCoder2 = class extends Coder {
31385
+ var StringCoder = class extends Coder {
32411
31386
  constructor(length) {
32412
31387
  super("string", `str[${length}]`, length);
32413
31388
  }
@@ -32428,9 +31403,10 @@ This unreleased fuel-core build may include features and updates not yet support
32428
31403
  return [toUtf8String(bytes2), offset + this.encodedLength];
32429
31404
  }
32430
31405
  };
32431
- var StructCoder2 = class extends Coder {
31406
+ var StructCoder = class extends Coder {
32432
31407
  name;
32433
31408
  coders;
31409
+ #hasNestedOption;
32434
31410
  constructor(name, coders) {
32435
31411
  const encodedLength = Object.values(coders).reduce(
32436
31412
  (acc, coder) => acc + coder.encodedLength,
@@ -32439,13 +31415,14 @@ This unreleased fuel-core build may include features and updates not yet support
32439
31415
  super("struct", `struct ${name}`, encodedLength);
32440
31416
  this.name = name;
32441
31417
  this.coders = coders;
31418
+ this.#hasNestedOption = hasNestedOption(coders);
32442
31419
  }
32443
31420
  encode(value) {
32444
31421
  return concatBytes2(
32445
31422
  Object.keys(this.coders).map((fieldName) => {
32446
31423
  const fieldCoder = this.coders[fieldName];
32447
31424
  const fieldValue = value[fieldName];
32448
- if (!(fieldCoder instanceof OptionCoder2) && fieldValue == null) {
31425
+ if (!(fieldCoder instanceof OptionCoder) && fieldValue == null) {
32449
31426
  throw new FuelError(
32450
31427
  ErrorCode.ENCODE_ERROR,
32451
31428
  `Invalid ${this.type}. Field "${fieldName}" not present.`
@@ -32456,7 +31433,7 @@ This unreleased fuel-core build may include features and updates not yet support
32456
31433
  );
32457
31434
  }
32458
31435
  decode(data, offset) {
32459
- if (data.length < this.encodedLength) {
31436
+ if (!this.#hasNestedOption && data.length < this.encodedLength) {
32460
31437
  throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid struct data size.`);
32461
31438
  }
32462
31439
  let newOffset = offset;
@@ -32470,12 +31447,14 @@ This unreleased fuel-core build may include features and updates not yet support
32470
31447
  return [decodedValue, newOffset];
32471
31448
  }
32472
31449
  };
32473
- var TupleCoder2 = class extends Coder {
31450
+ var TupleCoder = class extends Coder {
32474
31451
  coders;
31452
+ #hasNestedOption;
32475
31453
  constructor(coders) {
32476
31454
  const encodedLength = coders.reduce((acc, coder) => acc + coder.encodedLength, 0);
32477
31455
  super("tuple", `(${coders.map((coder) => coder.type).join(", ")})`, encodedLength);
32478
31456
  this.coders = coders;
31457
+ this.#hasNestedOption = hasNestedOption(coders);
32479
31458
  }
32480
31459
  encode(value) {
32481
31460
  if (this.coders.length !== value.length) {
@@ -32484,7 +31463,7 @@ This unreleased fuel-core build may include features and updates not yet support
32484
31463
  return concatBytes2(this.coders.map((coder, i) => coder.encode(value[i])));
32485
31464
  }
32486
31465
  decode(data, offset) {
32487
- if (data.length < this.encodedLength) {
31466
+ if (!this.#hasNestedOption && data.length < this.encodedLength) {
32488
31467
  throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid tuple data size.`);
32489
31468
  }
32490
31469
  let newOffset = offset;
@@ -32496,13 +31475,13 @@ This unreleased fuel-core build may include features and updates not yet support
32496
31475
  return [decodedValue, newOffset];
32497
31476
  }
32498
31477
  };
32499
- var VecCoder2 = class extends Coder {
31478
+ var VecCoder = class extends Coder {
32500
31479
  coder;
32501
- #isOptionVec;
31480
+ #hasNestedOption;
32502
31481
  constructor(coder) {
32503
31482
  super("struct", `struct Vec`, coder.encodedLength + WORD_SIZE);
32504
31483
  this.coder = coder;
32505
- this.#isOptionVec = this.coder instanceof OptionCoder2;
31484
+ this.#hasNestedOption = hasNestedOption([coder]);
32506
31485
  }
32507
31486
  encode(value) {
32508
31487
  if (!Array.isArray(value) && !isUint8Array(value)) {
@@ -32520,15 +31499,15 @@ This unreleased fuel-core build may include features and updates not yet support
32520
31499
  return new Uint8Array([...lengthBytes, ...concatBytes2(bytes2)]);
32521
31500
  }
32522
31501
  decode(data, offset) {
32523
- if (!this.#isOptionVec && (data.length < this.encodedLength || data.length > MAX_BYTES)) {
31502
+ if (!this.#hasNestedOption && data.length < this.encodedLength || data.length > MAX_BYTES) {
32524
31503
  throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid vec data size.`);
32525
31504
  }
32526
31505
  const offsetAndLength = offset + WORD_SIZE;
32527
31506
  const lengthBytes = data.slice(offset, offsetAndLength);
32528
31507
  const length = bn(new BigNumberCoder("u64").decode(lengthBytes, 0)[0]).toNumber();
32529
- const dataLength2 = length * this.coder.encodedLength;
32530
- const dataBytes = data.slice(offsetAndLength, offsetAndLength + dataLength2);
32531
- if (!this.#isOptionVec && dataBytes.length !== dataLength2) {
31508
+ const dataLength = length * this.coder.encodedLength;
31509
+ const dataBytes = data.slice(offsetAndLength, offsetAndLength + dataLength);
31510
+ if (!this.#hasNestedOption && dataBytes.length !== dataLength) {
32532
31511
  throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid vec byte data size.`);
32533
31512
  }
32534
31513
  let newOffset = offsetAndLength;
@@ -32541,29 +31520,214 @@ This unreleased fuel-core build may include features and updates not yet support
32541
31520
  return [chunks, newOffset];
32542
31521
  }
32543
31522
  };
32544
- var getCoder2 = (resolvedAbiType, _options) => {
31523
+ var getEncodingVersion = (encoding) => {
31524
+ switch (encoding) {
31525
+ case void 0:
31526
+ case ENCODING_V1:
31527
+ return ENCODING_V1;
31528
+ default:
31529
+ throw new FuelError(
31530
+ ErrorCode.UNSUPPORTED_ENCODING_VERSION,
31531
+ `Encoding version '${encoding}' is unsupported.`
31532
+ );
31533
+ }
31534
+ };
31535
+ var findFunctionByName = (abi, name) => {
31536
+ const fn = abi.functions.find((f2) => f2.name === name);
31537
+ if (!fn) {
31538
+ throw new FuelError(
31539
+ ErrorCode.FUNCTION_NOT_FOUND,
31540
+ `Function with name '${name}' doesn't exist in the ABI`
31541
+ );
31542
+ }
31543
+ return fn;
31544
+ };
31545
+ var findTypeById = (abi, typeId) => {
31546
+ const type3 = abi.types.find((t) => t.typeId === typeId);
31547
+ if (!type3) {
31548
+ throw new FuelError(
31549
+ ErrorCode.TYPE_NOT_FOUND,
31550
+ `Type with typeId '${typeId}' doesn't exist in the ABI.`
31551
+ );
31552
+ }
31553
+ return type3;
31554
+ };
31555
+ var findNonEmptyInputs = (abi, inputs) => inputs.filter((input) => findTypeById(abi, input.type).type !== "()");
31556
+ var findVectorBufferArgument = (components) => {
31557
+ const bufferComponent = components.find((c) => c.name === "buf");
31558
+ const bufferTypeArgument = bufferComponent?.originalTypeArguments?.[0];
31559
+ if (!bufferComponent || !bufferTypeArgument) {
31560
+ throw new FuelError(
31561
+ ErrorCode.INVALID_COMPONENT,
31562
+ `The Vec type provided is missing or has a malformed 'buf' component.`
31563
+ );
31564
+ }
31565
+ return bufferTypeArgument;
31566
+ };
31567
+ var ResolvedAbiType = class {
31568
+ abi;
31569
+ name;
31570
+ type;
31571
+ originalTypeArguments;
31572
+ components;
31573
+ constructor(abi, argument) {
31574
+ this.abi = abi;
31575
+ this.name = argument.name;
31576
+ const type3 = findTypeById(abi, argument.type);
31577
+ this.type = type3.type;
31578
+ this.originalTypeArguments = argument.typeArguments;
31579
+ this.components = ResolvedAbiType.getResolvedGenericComponents(
31580
+ abi,
31581
+ argument,
31582
+ type3.components,
31583
+ type3.typeParameters ?? ResolvedAbiType.getImplicitGenericTypeParameters(abi, type3.components)
31584
+ );
31585
+ }
31586
+ static getResolvedGenericComponents(abi, arg, components, typeParameters) {
31587
+ if (components === null) {
31588
+ return null;
31589
+ }
31590
+ if (typeParameters === null || typeParameters.length === 0) {
31591
+ return components.map((c) => new ResolvedAbiType(abi, c));
31592
+ }
31593
+ const typeParametersAndArgsMap = typeParameters.reduce(
31594
+ (obj, typeParameter, typeParameterIndex) => {
31595
+ const o = { ...obj };
31596
+ o[typeParameter] = structuredClone(
31597
+ arg.typeArguments?.[typeParameterIndex]
31598
+ );
31599
+ return o;
31600
+ },
31601
+ {}
31602
+ );
31603
+ const resolvedComponents = this.resolveGenericArgTypes(
31604
+ abi,
31605
+ components,
31606
+ typeParametersAndArgsMap
31607
+ );
31608
+ return resolvedComponents.map((c) => new ResolvedAbiType(abi, c));
31609
+ }
31610
+ static resolveGenericArgTypes(abi, args, typeParametersAndArgsMap) {
31611
+ return args.map((arg) => {
31612
+ if (typeParametersAndArgsMap[arg.type] !== void 0) {
31613
+ return {
31614
+ ...typeParametersAndArgsMap[arg.type],
31615
+ name: arg.name
31616
+ };
31617
+ }
31618
+ if (arg.typeArguments) {
31619
+ return {
31620
+ ...structuredClone(arg),
31621
+ typeArguments: this.resolveGenericArgTypes(
31622
+ abi,
31623
+ arg.typeArguments,
31624
+ typeParametersAndArgsMap
31625
+ )
31626
+ };
31627
+ }
31628
+ const argType = findTypeById(abi, arg.type);
31629
+ const implicitTypeParameters = this.getImplicitGenericTypeParameters(abi, argType.components);
31630
+ if (implicitTypeParameters && implicitTypeParameters.length > 0) {
31631
+ return {
31632
+ ...structuredClone(arg),
31633
+ typeArguments: implicitTypeParameters.map((itp) => typeParametersAndArgsMap[itp])
31634
+ };
31635
+ }
31636
+ return arg;
31637
+ });
31638
+ }
31639
+ static getImplicitGenericTypeParameters(abi, args, implicitGenericParametersParam) {
31640
+ if (!Array.isArray(args)) {
31641
+ return null;
31642
+ }
31643
+ const implicitGenericParameters = implicitGenericParametersParam ?? [];
31644
+ args.forEach((a) => {
31645
+ const argType = findTypeById(abi, a.type);
31646
+ if (genericRegEx.test(argType.type)) {
31647
+ implicitGenericParameters.push(argType.typeId);
31648
+ return;
31649
+ }
31650
+ if (!Array.isArray(a.typeArguments)) {
31651
+ return;
31652
+ }
31653
+ this.getImplicitGenericTypeParameters(abi, a.typeArguments, implicitGenericParameters);
31654
+ });
31655
+ return implicitGenericParameters.length > 0 ? implicitGenericParameters : null;
31656
+ }
31657
+ getSignature() {
31658
+ const prefix = this.getArgSignaturePrefix();
31659
+ const content = this.getArgSignatureContent();
31660
+ return `${prefix}${content}`;
31661
+ }
31662
+ getArgSignaturePrefix() {
31663
+ const structMatch = structRegEx.test(this.type);
31664
+ if (structMatch) {
31665
+ return "s";
31666
+ }
31667
+ const arrayMatch = arrayRegEx.test(this.type);
31668
+ if (arrayMatch) {
31669
+ return "a";
31670
+ }
31671
+ const enumMatch = enumRegEx.test(this.type);
31672
+ if (enumMatch) {
31673
+ return "e";
31674
+ }
31675
+ return "";
31676
+ }
31677
+ getArgSignatureContent() {
31678
+ if (this.type === "raw untyped ptr") {
31679
+ return "rawptr";
31680
+ }
31681
+ if (this.type === "raw untyped slice") {
31682
+ return "rawslice";
31683
+ }
31684
+ const strMatch = stringRegEx.exec(this.type)?.groups;
31685
+ if (strMatch) {
31686
+ return `str[${strMatch.length}]`;
31687
+ }
31688
+ if (this.components === null) {
31689
+ return this.type;
31690
+ }
31691
+ const arrayMatch = arrayRegEx.exec(this.type)?.groups;
31692
+ if (arrayMatch) {
31693
+ return `[${this.components[0].getSignature()};${arrayMatch.length}]`;
31694
+ }
31695
+ const typeArgumentsSignature = this.originalTypeArguments !== null ? `<${this.originalTypeArguments.map((a) => new ResolvedAbiType(this.abi, a).getSignature()).join(",")}>` : "";
31696
+ const componentsSignature = `(${this.components.map((c) => c.getSignature()).join(",")})`;
31697
+ return `${typeArgumentsSignature}${componentsSignature}`;
31698
+ }
31699
+ };
31700
+ function getCoders(components, options) {
31701
+ const { getCoder: getCoder2 } = options;
31702
+ return components.reduce((obj, component) => {
31703
+ const o = obj;
31704
+ o[component.name] = getCoder2(component, options);
31705
+ return o;
31706
+ }, {});
31707
+ }
31708
+ var getCoder = (resolvedAbiType, _options) => {
32545
31709
  switch (resolvedAbiType.type) {
32546
31710
  case U8_CODER_TYPE:
32547
31711
  case U16_CODER_TYPE:
32548
31712
  case U32_CODER_TYPE:
32549
- return new NumberCoder2(resolvedAbiType.type);
31713
+ return new NumberCoder(resolvedAbiType.type);
32550
31714
  case U64_CODER_TYPE:
32551
31715
  case RAW_PTR_CODER_TYPE:
32552
31716
  return new BigNumberCoder("u64");
32553
31717
  case U256_CODER_TYPE:
32554
31718
  return new BigNumberCoder("u256");
32555
31719
  case RAW_SLICE_CODER_TYPE:
32556
- return new RawSliceCoder2();
31720
+ return new RawSliceCoder();
32557
31721
  case BOOL_CODER_TYPE:
32558
- return new BooleanCoder2();
31722
+ return new BooleanCoder();
32559
31723
  case B256_CODER_TYPE:
32560
31724
  return new B256Coder();
32561
31725
  case B512_CODER_TYPE:
32562
31726
  return new B512Coder();
32563
31727
  case BYTES_CODER_TYPE:
32564
- return new ByteCoder2();
31728
+ return new ByteCoder();
32565
31729
  case STD_STRING_CODER_TYPE:
32566
- return new StdStringCoder2();
31730
+ return new StdStringCoder();
32567
31731
  case STR_SLICE_CODER_TYPE:
32568
31732
  return new StrSliceCoder();
32569
31733
  default:
@@ -32572,7 +31736,7 @@ This unreleased fuel-core build may include features and updates not yet support
32572
31736
  const stringMatch = stringRegEx.exec(resolvedAbiType.type)?.groups;
32573
31737
  if (stringMatch) {
32574
31738
  const length = parseInt(stringMatch.length, 10);
32575
- return new StringCoder2(length);
31739
+ return new StringCoder(length);
32576
31740
  }
32577
31741
  const components = resolvedAbiType.components;
32578
31742
  const arrayMatch = arrayRegEx.exec(resolvedAbiType.type)?.groups;
@@ -32585,46 +31749,42 @@ This unreleased fuel-core build may include features and updates not yet support
32585
31749
  `The provided Array type is missing an item of 'component'.`
32586
31750
  );
32587
31751
  }
32588
- const arrayElementCoder = getCoder2(arg, { isSmallBytes: true });
31752
+ const arrayElementCoder = getCoder(arg);
32589
31753
  return new ArrayCoder(arrayElementCoder, length);
32590
31754
  }
32591
31755
  if (resolvedAbiType.type === VEC_CODER_TYPE) {
32592
31756
  const arg = findVectorBufferArgument(components);
32593
31757
  const argType = new ResolvedAbiType(resolvedAbiType.abi, arg);
32594
- const itemCoder = getCoder2(argType, { isSmallBytes: true, encoding: ENCODING_V0 });
32595
- return new VecCoder2(itemCoder);
31758
+ const itemCoder = getCoder(argType, { encoding: ENCODING_V1 });
31759
+ return new VecCoder(itemCoder);
32596
31760
  }
32597
31761
  const structMatch = structRegEx.exec(resolvedAbiType.type)?.groups;
32598
31762
  if (structMatch) {
32599
- const coders = getCoders(components, { isRightPadded: true, getCoder: getCoder2 });
32600
- return new StructCoder2(structMatch.name, coders);
31763
+ const coders = getCoders(components, { getCoder });
31764
+ return new StructCoder(structMatch.name, coders);
32601
31765
  }
32602
31766
  const enumMatch = enumRegEx.exec(resolvedAbiType.type)?.groups;
32603
31767
  if (enumMatch) {
32604
- const coders = getCoders(components, { getCoder: getCoder2 });
31768
+ const coders = getCoders(components, { getCoder });
32605
31769
  const isOptionEnum = resolvedAbiType.type === OPTION_CODER_TYPE;
32606
31770
  if (isOptionEnum) {
32607
- return new OptionCoder2(enumMatch.name, coders);
31771
+ return new OptionCoder(enumMatch.name, coders);
32608
31772
  }
32609
- return new EnumCoder2(enumMatch.name, coders);
31773
+ return new EnumCoder(enumMatch.name, coders);
32610
31774
  }
32611
31775
  const tupleMatch = tupleRegEx.exec(resolvedAbiType.type)?.groups;
32612
31776
  if (tupleMatch) {
32613
- const coders = components.map(
32614
- (component) => getCoder2(component, { isRightPadded: true, encoding: ENCODING_V0 })
32615
- );
32616
- return new TupleCoder2(coders);
31777
+ const coders = components.map((component) => getCoder(component, { encoding: ENCODING_V1 }));
31778
+ return new TupleCoder(coders);
32617
31779
  }
32618
31780
  throw new FuelError(
32619
31781
  ErrorCode.CODER_NOT_FOUND,
32620
31782
  `Coder not found: ${JSON.stringify(resolvedAbiType)}.`
32621
31783
  );
32622
31784
  };
32623
- function getCoderForEncoding(encoding = ENCODING_V0) {
31785
+ function getCoderForEncoding(encoding = ENCODING_V1) {
32624
31786
  switch (encoding) {
32625
31787
  case ENCODING_V1:
32626
- return getCoder2;
32627
- case ENCODING_V0:
32628
31788
  return getCoder;
32629
31789
  default:
32630
31790
  throw new FuelError(
@@ -32635,7 +31795,7 @@ This unreleased fuel-core build may include features and updates not yet support
32635
31795
  }
32636
31796
  var AbiCoder = class {
32637
31797
  static getCoder(abi, argument, options = {
32638
- isSmallBytes: false
31798
+ padToWordSize: false
32639
31799
  }) {
32640
31800
  const resolvedAbiType = new ResolvedAbiType(abi, argument);
32641
31801
  return getCoderForEncoding(options.encoding)(resolvedAbiType, options);
@@ -32655,8 +31815,6 @@ This unreleased fuel-core build may include features and updates not yet support
32655
31815
  name;
32656
31816
  jsonFn;
32657
31817
  attributes;
32658
- isInputDataPointer;
32659
- outputMetadata;
32660
31818
  jsonAbi;
32661
31819
  constructor(jsonAbi, name) {
32662
31820
  this.jsonAbi = jsonAbi;
@@ -32664,13 +31822,8 @@ This unreleased fuel-core build may include features and updates not yet support
32664
31822
  this.name = name;
32665
31823
  this.signature = FunctionFragment.getSignature(this.jsonAbi, this.jsonFn);
32666
31824
  this.selector = FunctionFragment.getFunctionSelector(this.signature);
32667
- this.selectorBytes = new StdStringCoder2().encode(name);
31825
+ this.selectorBytes = new StdStringCoder().encode(name);
32668
31826
  this.encoding = getEncodingVersion(jsonAbi.encoding);
32669
- this.isInputDataPointer = this.#isInputDataPointer();
32670
- this.outputMetadata = {
32671
- isHeapType: this.#isOutputDataHeap(),
32672
- encodedLength: this.#getOutputEncodedLength()
32673
- };
32674
31827
  this.attributes = this.jsonFn.attributes ?? [];
32675
31828
  }
32676
31829
  static getSignature(abi, fn) {
@@ -32683,29 +31836,7 @@ This unreleased fuel-core build may include features and updates not yet support
32683
31836
  const hashedFunctionSignature = sha2562(bufferFromString2(functionSignature, "utf-8"));
32684
31837
  return bn(hashedFunctionSignature.slice(0, 10)).toHex(8);
32685
31838
  }
32686
- #isInputDataPointer() {
32687
- const inputTypes = this.jsonFn.inputs.map((i) => findTypeById(this.jsonAbi, i.type));
32688
- return this.jsonFn.inputs.length > 1 || isPointerType(inputTypes[0]?.type || "");
32689
- }
32690
- #isOutputDataHeap() {
32691
- const outputType = findTypeById(this.jsonAbi, this.jsonFn.output.type);
32692
- return isHeapType(outputType?.type || "");
32693
- }
32694
- #getOutputEncodedLength() {
32695
- try {
32696
- const heapCoder = AbiCoder.getCoder(this.jsonAbi, this.jsonFn.output);
32697
- if (heapCoder instanceof VecCoder) {
32698
- return heapCoder.coder.encodedLength;
32699
- }
32700
- if (heapCoder instanceof ByteCoder) {
32701
- return ByteCoder.memorySize;
32702
- }
32703
- return heapCoder.encodedLength;
32704
- } catch (e) {
32705
- return 0;
32706
- }
32707
- }
32708
- encodeArguments(values, offset = 0) {
31839
+ encodeArguments(values) {
32709
31840
  FunctionFragment.verifyArgsAndInputsAlign(values, this.jsonFn.inputs, this.jsonAbi);
32710
31841
  const shallowCopyValues = values.slice();
32711
31842
  const nonEmptyInputs = findNonEmptyInputs(this.jsonAbi, this.jsonFn.inputs);
@@ -32715,15 +31846,10 @@ This unreleased fuel-core build may include features and updates not yet support
32715
31846
  }
32716
31847
  const coders = nonEmptyInputs.map(
32717
31848
  (t) => AbiCoder.getCoder(this.jsonAbi, t, {
32718
- isRightPadded: nonEmptyInputs.length > 1,
32719
31849
  encoding: this.encoding
32720
31850
  })
32721
31851
  );
32722
- if (this.encoding === ENCODING_V1) {
32723
- return new TupleCoder2(coders).encode(shallowCopyValues);
32724
- }
32725
- const results = new TupleCoder(coders).encode(shallowCopyValues);
32726
- return unpackDynamicData(results, offset, results.byteLength);
31852
+ return new TupleCoder(coders).encode(shallowCopyValues);
32727
31853
  }
32728
31854
  static verifyArgsAndInputsAlign(args, inputs, abi) {
32729
31855
  if (args.length === inputs.length) {
@@ -32832,9 +31958,9 @@ This unreleased fuel-core build may include features and updates not yet support
32832
31958
  const fragment = typeof functionFragment === "string" ? this.getFunction(functionFragment) : functionFragment;
32833
31959
  return fragment.decodeArguments(data);
32834
31960
  }
32835
- encodeFunctionData(functionFragment, values, offset = 0) {
31961
+ encodeFunctionData(functionFragment, values) {
32836
31962
  const fragment = typeof functionFragment === "string" ? this.getFunction(functionFragment) : functionFragment;
32837
- return fragment.encodeArguments(values, offset);
31963
+ return fragment.encodeArguments(values);
32838
31964
  }
32839
31965
  // Decode the result of a function call
32840
31966
  decodeFunctionResult(functionFragment, data) {
@@ -32862,9 +31988,7 @@ This unreleased fuel-core build may include features and updates not yet support
32862
31988
  );
32863
31989
  }
32864
31990
  return AbiCoder.encode(this.jsonAbi, configurable.configurableType, value, {
32865
- isRightPadded: true,
32866
- // TODO: Review support for configurables in v1 encoding when it becomes available
32867
- encoding: ENCODING_V0
31991
+ encoding: this.encoding
32868
31992
  });
32869
31993
  }
32870
31994
  getTypeById(typeId) {
@@ -32914,8 +32038,8 @@ This unreleased fuel-core build may include features and updates not yet support
32914
32038
  var TxPointerCoder = class extends StructCoder {
32915
32039
  constructor() {
32916
32040
  super("TxPointer", {
32917
- blockHeight: new NumberCoder("u32"),
32918
- txIndex: new NumberCoder("u16")
32041
+ blockHeight: new NumberCoder("u32", { padToWordSize: true }),
32042
+ txIndex: new NumberCoder("u16", { padToWordSize: true })
32919
32043
  });
32920
32044
  }
32921
32045
  };
@@ -32932,12 +32056,12 @@ This unreleased fuel-core build may include features and updates not yet support
32932
32056
  encode(value) {
32933
32057
  const parts = [];
32934
32058
  parts.push(new B256Coder().encode(value.txID));
32935
- parts.push(new NumberCoder("u16").encode(value.outputIndex));
32059
+ parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.outputIndex));
32936
32060
  parts.push(new B256Coder().encode(value.owner));
32937
32061
  parts.push(new BigNumberCoder("u64").encode(value.amount));
32938
32062
  parts.push(new B256Coder().encode(value.assetId));
32939
32063
  parts.push(new TxPointerCoder().encode(value.txPointer));
32940
- parts.push(new NumberCoder("u16").encode(value.witnessIndex));
32064
+ parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.witnessIndex));
32941
32065
  parts.push(new BigNumberCoder("u64").encode(value.predicateGasUsed));
32942
32066
  parts.push(new BigNumberCoder("u64").encode(value.predicateLength));
32943
32067
  parts.push(new BigNumberCoder("u64").encode(value.predicateDataLength));
@@ -32952,7 +32076,7 @@ This unreleased fuel-core build may include features and updates not yet support
32952
32076
  let o = offset;
32953
32077
  [decoded, o] = new B256Coder().decode(data, o);
32954
32078
  const txID = decoded;
32955
- [decoded, o] = new NumberCoder("u16").decode(data, o);
32079
+ [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
32956
32080
  const outputIndex = decoded;
32957
32081
  [decoded, o] = new B256Coder().decode(data, o);
32958
32082
  const owner = decoded;
@@ -32962,7 +32086,7 @@ This unreleased fuel-core build may include features and updates not yet support
32962
32086
  const assetId = decoded;
32963
32087
  [decoded, o] = new TxPointerCoder().decode(data, o);
32964
32088
  const txPointer = decoded;
32965
- [decoded, o] = new NumberCoder("u16").decode(data, o);
32089
+ [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
32966
32090
  const witnessIndex = Number(decoded);
32967
32091
  [decoded, o] = new BigNumberCoder("u64").decode(data, o);
32968
32092
  const predicateGasUsed = decoded;
@@ -33001,7 +32125,7 @@ This unreleased fuel-core build may include features and updates not yet support
33001
32125
  encode(value) {
33002
32126
  const parts = [];
33003
32127
  parts.push(new B256Coder().encode(value.txID));
33004
- parts.push(new NumberCoder("u16").encode(value.outputIndex));
32128
+ parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.outputIndex));
33005
32129
  parts.push(new B256Coder().encode(value.balanceRoot));
33006
32130
  parts.push(new B256Coder().encode(value.stateRoot));
33007
32131
  parts.push(new TxPointerCoder().encode(value.txPointer));
@@ -33013,7 +32137,7 @@ This unreleased fuel-core build may include features and updates not yet support
33013
32137
  let o = offset;
33014
32138
  [decoded, o] = new B256Coder().decode(data, o);
33015
32139
  const txID = decoded;
33016
- [decoded, o] = new NumberCoder("u16").decode(data, o);
32140
+ [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
33017
32141
  const outputIndex = decoded;
33018
32142
  [decoded, o] = new B256Coder().decode(data, o);
33019
32143
  const balanceRoot = decoded;
@@ -33052,8 +32176,8 @@ This unreleased fuel-core build may include features and updates not yet support
33052
32176
  }
33053
32177
  static encodeData(messageData) {
33054
32178
  const bytes2 = arrayify(messageData || "0x");
33055
- const dataLength2 = bytes2.length;
33056
- return new ByteArrayCoder(dataLength2).encode(bytes2);
32179
+ const dataLength = bytes2.length;
32180
+ return new ByteArrayCoder(dataLength).encode(bytes2);
33057
32181
  }
33058
32182
  encode(value) {
33059
32183
  const parts = [];
@@ -33062,7 +32186,7 @@ This unreleased fuel-core build may include features and updates not yet support
33062
32186
  parts.push(new ByteArrayCoder(32).encode(value.recipient));
33063
32187
  parts.push(new BigNumberCoder("u64").encode(value.amount));
33064
32188
  parts.push(new ByteArrayCoder(32).encode(value.nonce));
33065
- parts.push(new NumberCoder("u16").encode(value.witnessIndex));
32189
+ parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.witnessIndex));
33066
32190
  parts.push(new BigNumberCoder("u64").encode(value.predicateGasUsed));
33067
32191
  parts.push(new BigNumberCoder("u64").encode(data.length));
33068
32192
  parts.push(new BigNumberCoder("u64").encode(value.predicateLength));
@@ -33076,8 +32200,8 @@ This unreleased fuel-core build may include features and updates not yet support
33076
32200
  }
33077
32201
  static decodeData(messageData) {
33078
32202
  const bytes2 = arrayify(messageData);
33079
- const dataLength2 = bytes2.length;
33080
- const [data] = new ByteArrayCoder(dataLength2).decode(bytes2, 0);
32203
+ const dataLength = bytes2.length;
32204
+ const [data] = new ByteArrayCoder(dataLength).decode(bytes2, 0);
33081
32205
  return arrayify(data);
33082
32206
  }
33083
32207
  decode(data, offset) {
@@ -33091,17 +32215,17 @@ This unreleased fuel-core build may include features and updates not yet support
33091
32215
  const amount = decoded;
33092
32216
  [decoded, o] = new B256Coder().decode(data, o);
33093
32217
  const nonce = decoded;
33094
- [decoded, o] = new NumberCoder("u16").decode(data, o);
32218
+ [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
33095
32219
  const witnessIndex = Number(decoded);
33096
32220
  [decoded, o] = new BigNumberCoder("u64").decode(data, o);
33097
32221
  const predicateGasUsed = decoded;
33098
- [decoded, o] = new NumberCoder("u32").decode(data, o);
33099
- const dataLength2 = decoded;
32222
+ [decoded, o] = new NumberCoder("u32", { padToWordSize: true }).decode(data, o);
32223
+ const dataLength = decoded;
33100
32224
  [decoded, o] = new BigNumberCoder("u64").decode(data, o);
33101
32225
  const predicateLength = decoded;
33102
32226
  [decoded, o] = new BigNumberCoder("u64").decode(data, o);
33103
32227
  const predicateDataLength = decoded;
33104
- [decoded, o] = new ByteArrayCoder(dataLength2).decode(data, o);
32228
+ [decoded, o] = new ByteArrayCoder(dataLength).decode(data, o);
33105
32229
  const messageData = decoded;
33106
32230
  [decoded, o] = new ByteArrayCoder(predicateLength.toNumber()).decode(data, o);
33107
32231
  const predicate = decoded;
@@ -33116,7 +32240,7 @@ This unreleased fuel-core build may include features and updates not yet support
33116
32240
  witnessIndex,
33117
32241
  nonce,
33118
32242
  predicateGasUsed,
33119
- dataLength: dataLength2,
32243
+ dataLength,
33120
32244
  predicateLength,
33121
32245
  predicateDataLength,
33122
32246
  data: messageData,
@@ -33133,7 +32257,7 @@ This unreleased fuel-core build may include features and updates not yet support
33133
32257
  }
33134
32258
  encode(value) {
33135
32259
  const parts = [];
33136
- parts.push(new NumberCoder("u8").encode(value.type));
32260
+ parts.push(new NumberCoder("u8", { padToWordSize: true }).encode(value.type));
33137
32261
  const { type: type3 } = value;
33138
32262
  switch (type3) {
33139
32263
  case 0: {
@@ -33160,7 +32284,7 @@ This unreleased fuel-core build may include features and updates not yet support
33160
32284
  decode(data, offset) {
33161
32285
  let decoded;
33162
32286
  let o = offset;
33163
- [decoded, o] = new NumberCoder("u8").decode(data, o);
32287
+ [decoded, o] = new NumberCoder("u8", { padToWordSize: true }).decode(data, o);
33164
32288
  const type3 = decoded;
33165
32289
  switch (type3) {
33166
32290
  case 0: {
@@ -33229,7 +32353,7 @@ This unreleased fuel-core build may include features and updates not yet support
33229
32353
  }
33230
32354
  encode(value) {
33231
32355
  const parts = [];
33232
- parts.push(new NumberCoder("u8").encode(value.inputIndex));
32356
+ parts.push(new NumberCoder("u8", { padToWordSize: true }).encode(value.inputIndex));
33233
32357
  parts.push(new B256Coder().encode(value.balanceRoot));
33234
32358
  parts.push(new B256Coder().encode(value.stateRoot));
33235
32359
  return concat(parts);
@@ -33237,7 +32361,7 @@ This unreleased fuel-core build may include features and updates not yet support
33237
32361
  decode(data, offset) {
33238
32362
  let decoded;
33239
32363
  let o = offset;
33240
- [decoded, o] = new NumberCoder("u8").decode(data, o);
32364
+ [decoded, o] = new NumberCoder("u8", { padToWordSize: true }).decode(data, o);
33241
32365
  const inputIndex = decoded;
33242
32366
  [decoded, o] = new B256Coder().decode(data, o);
33243
32367
  const balanceRoot = decoded;
@@ -33349,7 +32473,7 @@ This unreleased fuel-core build may include features and updates not yet support
33349
32473
  }
33350
32474
  encode(value) {
33351
32475
  const parts = [];
33352
- parts.push(new NumberCoder("u8").encode(value.type));
32476
+ parts.push(new NumberCoder("u8", { padToWordSize: true }).encode(value.type));
33353
32477
  const { type: type3 } = value;
33354
32478
  switch (type3) {
33355
32479
  case 0: {
@@ -33384,7 +32508,7 @@ This unreleased fuel-core build may include features and updates not yet support
33384
32508
  decode(data, offset) {
33385
32509
  let decoded;
33386
32510
  let o = offset;
33387
- [decoded, o] = new NumberCoder("u8").decode(data, o);
32511
+ [decoded, o] = new NumberCoder("u8", { padToWordSize: true }).decode(data, o);
33388
32512
  const type3 = decoded;
33389
32513
  switch (type3) {
33390
32514
  case 0: {
@@ -33452,7 +32576,7 @@ This unreleased fuel-core build may include features and updates not yet support
33452
32576
  parts.push(new BigNumberCoder("u64").encode(data));
33453
32577
  break;
33454
32578
  case 4:
33455
- parts.push(new NumberCoder("u32").encode(data));
32579
+ parts.push(new NumberCoder("u32", { padToWordSize: true }).encode(data));
33456
32580
  break;
33457
32581
  default: {
33458
32582
  throw new FuelError(ErrorCode.INVALID_POLICY_TYPE, `Invalid policy type: ${type3}`);
@@ -33475,7 +32599,10 @@ This unreleased fuel-core build may include features and updates not yet support
33475
32599
  policies.push({ type: 2, data: witnessLimit });
33476
32600
  }
33477
32601
  if (policyTypes & 4) {
33478
- const [maturity, nextOffset] = new NumberCoder("u32").decode(data, o);
32602
+ const [maturity, nextOffset] = new NumberCoder("u32", { padToWordSize: true }).decode(
32603
+ data,
32604
+ o
32605
+ );
33479
32606
  o = nextOffset;
33480
32607
  policies.push({ type: 4, data: maturity });
33481
32608
  }
@@ -33522,7 +32649,7 @@ This unreleased fuel-core build may include features and updates not yet support
33522
32649
  parts.push(new B256Coder().encode(value.recipient));
33523
32650
  parts.push(new BigNumberCoder("u64").encode(value.amount));
33524
32651
  parts.push(new B256Coder().encode(value.nonce));
33525
- parts.push(new NumberCoder("u16").encode(value.data.length));
32652
+ parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.data.length));
33526
32653
  parts.push(new B256Coder().encode(value.digest));
33527
32654
  parts.push(new ByteArrayCoder(value.data.length).encode(value.data));
33528
32655
  return concat(parts);
@@ -33538,7 +32665,7 @@ This unreleased fuel-core build may include features and updates not yet support
33538
32665
  const amount = decoded;
33539
32666
  [decoded, o] = new B256Coder().decode(data, o);
33540
32667
  const nonce = decoded;
33541
- [decoded, o] = new NumberCoder("u16").decode(data, o);
32668
+ [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
33542
32669
  const len = decoded;
33543
32670
  [decoded, o] = new B256Coder().decode(data, o);
33544
32671
  const digest = decoded;
@@ -33662,11 +32789,11 @@ This unreleased fuel-core build may include features and updates not yet support
33662
32789
  encode(upgradePurposeType) {
33663
32790
  const parts = [];
33664
32791
  const { type: type3 } = upgradePurposeType;
33665
- parts.push(new NumberCoder("u8").encode(type3));
32792
+ parts.push(new NumberCoder("u8", { padToWordSize: true }).encode(type3));
33666
32793
  switch (type3) {
33667
32794
  case 0: {
33668
32795
  const data = upgradePurposeType.data;
33669
- parts.push(new NumberCoder("u16").encode(data.witnessIndex));
32796
+ parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(data.witnessIndex));
33670
32797
  parts.push(new B256Coder().encode(data.checksum));
33671
32798
  break;
33672
32799
  }
@@ -33687,11 +32814,11 @@ This unreleased fuel-core build may include features and updates not yet support
33687
32814
  decode(data, offset) {
33688
32815
  let o = offset;
33689
32816
  let decoded;
33690
- [decoded, o] = new NumberCoder("u8").decode(data, o);
32817
+ [decoded, o] = new NumberCoder("u8", { padToWordSize: true }).decode(data, o);
33691
32818
  const type3 = decoded;
33692
32819
  switch (type3) {
33693
32820
  case 0: {
33694
- [decoded, o] = new NumberCoder("u16").decode(data, o);
32821
+ [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
33695
32822
  const witnessIndex = decoded;
33696
32823
  [decoded, o] = new B256Coder().decode(data, o);
33697
32824
  const checksum = decoded;
@@ -33722,20 +32849,20 @@ This unreleased fuel-core build may include features and updates not yet support
33722
32849
  }
33723
32850
  encode(value) {
33724
32851
  const parts = [];
33725
- parts.push(new NumberCoder("u32").encode(value.dataLength));
32852
+ parts.push(new NumberCoder("u32", { padToWordSize: true }).encode(value.dataLength));
33726
32853
  parts.push(new ByteArrayCoder(value.dataLength).encode(value.data));
33727
32854
  return concat(parts);
33728
32855
  }
33729
32856
  decode(data, offset) {
33730
32857
  let decoded;
33731
32858
  let o = offset;
33732
- [decoded, o] = new NumberCoder("u32").decode(data, o);
33733
- const dataLength2 = decoded;
33734
- [decoded, o] = new ByteArrayCoder(dataLength2).decode(data, o);
32859
+ [decoded, o] = new NumberCoder("u32", { padToWordSize: true }).decode(data, o);
32860
+ const dataLength = decoded;
32861
+ [decoded, o] = new ByteArrayCoder(dataLength).decode(data, o);
33735
32862
  const witnessData = decoded;
33736
32863
  return [
33737
32864
  {
33738
- dataLength: dataLength2,
32865
+ dataLength,
33739
32866
  data: witnessData
33740
32867
  },
33741
32868
  o
@@ -33760,10 +32887,10 @@ This unreleased fuel-core build may include features and updates not yet support
33760
32887
  parts.push(new B256Coder().encode(value.receiptsRoot));
33761
32888
  parts.push(new BigNumberCoder("u64").encode(value.scriptLength));
33762
32889
  parts.push(new BigNumberCoder("u64").encode(value.scriptDataLength));
33763
- parts.push(new NumberCoder("u32").encode(value.policyTypes));
33764
- parts.push(new NumberCoder("u16").encode(value.inputsCount));
33765
- parts.push(new NumberCoder("u16").encode(value.outputsCount));
33766
- parts.push(new NumberCoder("u16").encode(value.witnessesCount));
32890
+ parts.push(new NumberCoder("u32", { padToWordSize: true }).encode(value.policyTypes));
32891
+ parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.inputsCount));
32892
+ parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.outputsCount));
32893
+ parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.witnessesCount));
33767
32894
  parts.push(new ByteArrayCoder(value.scriptLength.toNumber()).encode(value.script));
33768
32895
  parts.push(new ByteArrayCoder(value.scriptDataLength.toNumber()).encode(value.scriptData));
33769
32896
  parts.push(new PoliciesCoder().encode(value.policies));
@@ -33783,13 +32910,13 @@ This unreleased fuel-core build may include features and updates not yet support
33783
32910
  const scriptLength = decoded;
33784
32911
  [decoded, o] = new BigNumberCoder("u64").decode(data, o);
33785
32912
  const scriptDataLength = decoded;
33786
- [decoded, o] = new NumberCoder("u32").decode(data, o);
32913
+ [decoded, o] = new NumberCoder("u32", { padToWordSize: true }).decode(data, o);
33787
32914
  const policyTypes = decoded;
33788
- [decoded, o] = new NumberCoder("u16").decode(data, o);
32915
+ [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
33789
32916
  const inputsCount = decoded;
33790
- [decoded, o] = new NumberCoder("u16").decode(data, o);
32917
+ [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
33791
32918
  const outputsCount = decoded;
33792
- [decoded, o] = new NumberCoder("u16").decode(data, o);
32919
+ [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
33793
32920
  const witnessesCount = decoded;
33794
32921
  [decoded, o] = new ByteArrayCoder(scriptLength.toNumber()).decode(data, o);
33795
32922
  const script = decoded;
@@ -33831,13 +32958,13 @@ This unreleased fuel-core build may include features and updates not yet support
33831
32958
  }
33832
32959
  encode(value) {
33833
32960
  const parts = [];
33834
- parts.push(new NumberCoder("u16").encode(value.bytecodeWitnessIndex));
32961
+ parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.bytecodeWitnessIndex));
33835
32962
  parts.push(new B256Coder().encode(value.salt));
33836
32963
  parts.push(new BigNumberCoder("u64").encode(value.storageSlotsCount));
33837
- parts.push(new NumberCoder("u32").encode(value.policyTypes));
33838
- parts.push(new NumberCoder("u16").encode(value.inputsCount));
33839
- parts.push(new NumberCoder("u16").encode(value.outputsCount));
33840
- parts.push(new NumberCoder("u16").encode(value.witnessesCount));
32964
+ parts.push(new NumberCoder("u32", { padToWordSize: true }).encode(value.policyTypes));
32965
+ parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.inputsCount));
32966
+ parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.outputsCount));
32967
+ parts.push(new NumberCoder("u16", { padToWordSize: true }).encode(value.witnessesCount));
33841
32968
  parts.push(
33842
32969
  new ArrayCoder(new StorageSlotCoder(), value.storageSlotsCount.toNumber()).encode(
33843
32970
  value.storageSlots
@@ -33852,19 +32979,19 @@ This unreleased fuel-core build may include features and updates not yet support
33852
32979
  decode(data, offset) {
33853
32980
  let decoded;
33854
32981
  let o = offset;
33855
- [decoded, o] = new NumberCoder("u16").decode(data, o);
32982
+ [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
33856
32983
  const bytecodeWitnessIndex = decoded;
33857
32984
  [decoded, o] = new B256Coder().decode(data, o);
33858
32985
  const salt = decoded;
33859
32986
  [decoded, o] = new BigNumberCoder("u64").decode(data, o);
33860
32987
  const storageSlotsCount = decoded;
33861
- [decoded, o] = new NumberCoder("u32").decode(data, o);
32988
+ [decoded, o] = new NumberCoder("u32", { padToWordSize: true }).decode(data, o);
33862
32989
  const policyTypes = decoded;
33863
- [decoded, o] = new NumberCoder("u16").decode(data, o);
32990
+ [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
33864
32991
  const inputsCount = decoded;
33865
- [decoded, o] = new NumberCoder("u16").decode(data, o);
32992
+ [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
33866
32993
  const outputsCount = decoded;
33867
- [decoded, o] = new NumberCoder("u16").decode(data, o);
32994
+ [decoded, o] = new NumberCoder("u16", { padToWordSize: true }).decode(data, o);
33868
32995
  const witnessesCount = decoded;
33869
32996
  [decoded, o] = new ArrayCoder(new StorageSlotCoder(), storageSlotsCount.toNumber()).decode(
33870
32997
  data,
@@ -34078,7 +33205,7 @@ This unreleased fuel-core build may include features and updates not yet support
34078
33205
  }
34079
33206
  encode(value) {
34080
33207
  const parts = [];
34081
- parts.push(new NumberCoder("u8").encode(value.type));
33208
+ parts.push(new NumberCoder("u8", { padToWordSize: true }).encode(value.type));
34082
33209
  const { type: type3 } = value;
34083
33210
  switch (value.type) {
34084
33211
  case 0: {
@@ -34121,7 +33248,7 @@ This unreleased fuel-core build may include features and updates not yet support
34121
33248
  decode(data, offset) {
34122
33249
  let decoded;
34123
33250
  let o = offset;
34124
- [decoded, o] = new NumberCoder("u8").decode(data, o);
33251
+ [decoded, o] = new NumberCoder("u8", { padToWordSize: true }).decode(data, o);
34125
33252
  const type3 = decoded;
34126
33253
  switch (type3) {
34127
33254
  case 0: {
@@ -37689,6 +36816,7 @@ ${SqueezedOutStatusFragmentDoc}`;
37689
36816
  ${InputEstimatePredicatesFragmentDoc}`;
37690
36817
  var DryRunFailureStatusFragmentDoc = lib_default2`
37691
36818
  fragment dryRunFailureStatusFragment on DryRunFailureStatus {
36819
+ type: __typename
37692
36820
  totalGas
37693
36821
  totalFee
37694
36822
  reason
@@ -37700,6 +36828,7 @@ ${SqueezedOutStatusFragmentDoc}`;
37700
36828
  `;
37701
36829
  var DryRunSuccessStatusFragmentDoc = lib_default2`
37702
36830
  fragment dryRunSuccessStatusFragment on DryRunSuccessStatus {
36831
+ type: __typename
37703
36832
  totalGas
37704
36833
  totalFee
37705
36834
  programState {
@@ -39208,19 +38337,18 @@ ${MessageCoinFragmentDoc}`;
39208
38337
  }
39209
38338
 
39210
38339
  // src/providers/utils/extract-tx-error.ts
39211
- var assemblePanicError = (status) => {
39212
- let errorMessage = `The transaction reverted with reason: "${status.reason}".`;
39213
- const reason = status.reason;
39214
- if (PANIC_REASONS.includes(status.reason)) {
38340
+ var assemblePanicError = (statusReason) => {
38341
+ let errorMessage = `The transaction reverted with reason: "${statusReason}".`;
38342
+ if (PANIC_REASONS.includes(statusReason)) {
39215
38343
  errorMessage = `${errorMessage}
39216
38344
 
39217
38345
  You can read more about this error at:
39218
38346
 
39219
- ${PANIC_DOC_URL}#variant.${status.reason}`;
38347
+ ${PANIC_DOC_URL}#variant.${statusReason}`;
39220
38348
  }
39221
- return { errorMessage, reason };
38349
+ return { errorMessage, reason: statusReason };
39222
38350
  };
39223
- var stringify2 = (obj) => JSON.stringify(obj, null, 2);
38351
+ var stringify = (obj) => JSON.stringify(obj, null, 2);
39224
38352
  var assembleRevertError = (receipts, logs) => {
39225
38353
  let errorMessage = "The transaction reverted with an unknown reason.";
39226
38354
  const revertReceipt = receipts.find(({ type: type3 }) => type3 === ReceiptType.Revert);
@@ -39230,17 +38358,17 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
39230
38358
  switch (reasonHex) {
39231
38359
  case FAILED_REQUIRE_SIGNAL: {
39232
38360
  reason = "require";
39233
- errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify2(logs[0]) : "an error."}.`;
38361
+ errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(logs[0]) : "an error."}.`;
39234
38362
  break;
39235
38363
  }
39236
38364
  case FAILED_ASSERT_EQ_SIGNAL: {
39237
- const sufix = logs.length >= 2 ? ` comparing ${stringify2(logs[1])} and ${stringify2(logs[0])}.` : ".";
38365
+ const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
39238
38366
  reason = "assert_eq";
39239
38367
  errorMessage = `The transaction reverted because of an "assert_eq" statement${sufix}`;
39240
38368
  break;
39241
38369
  }
39242
38370
  case FAILED_ASSERT_NE_SIGNAL: {
39243
- const sufix = logs.length >= 2 ? ` comparing ${stringify2(logs[1])} and ${stringify2(logs[0])}.` : ".";
38371
+ const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
39244
38372
  reason = "assert_ne";
39245
38373
  errorMessage = `The transaction reverted because of an "assert_ne" statement${sufix}`;
39246
38374
  break;
@@ -39261,10 +38389,10 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
39261
38389
  return { errorMessage, reason };
39262
38390
  };
39263
38391
  var extractTxError = (params) => {
39264
- const { receipts, status, logs } = params;
38392
+ const { receipts, statusReason, logs } = params;
39265
38393
  const isPanic = receipts.some(({ type: type3 }) => type3 === ReceiptType.Panic);
39266
38394
  const isRevert = receipts.some(({ type: type3 }) => type3 === ReceiptType.Revert);
39267
- const { errorMessage, reason } = status?.type === "FailureStatus" && isPanic ? assemblePanicError(status) : assembleRevertError(receipts, logs);
38395
+ const { errorMessage, reason } = isPanic ? assemblePanicError(statusReason) : assembleRevertError(receipts, logs);
39268
38396
  const metadata = {
39269
38397
  logs,
39270
38398
  receipts,
@@ -39848,15 +38976,6 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
39848
38976
  }
39849
38977
  });
39850
38978
  }
39851
- shiftPredicateData() {
39852
- this.inputs.forEach((input) => {
39853
- if ("predicateData" in input && "padPredicateData" in input && typeof input.padPredicateData === "function") {
39854
- input.predicateData = input.padPredicateData(
39855
- BaseTransactionRequest.getPolicyMeta(this).policies.length
39856
- );
39857
- }
39858
- });
39859
- }
39860
38979
  };
39861
38980
 
39862
38981
  // src/providers/transaction-request/hash-transaction.ts
@@ -40321,37 +39440,27 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
40321
39440
  };
40322
39441
 
40323
39442
  // src/providers/transaction-summary/call.ts
40324
- var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
39443
+ var getFunctionCall = ({ abi, receipt }) => {
40325
39444
  const abiInterface = new Interface(abi);
40326
39445
  const callFunctionSelector = receipt.param1.toHex(8);
40327
39446
  const functionFragment = abiInterface.getFunction(callFunctionSelector);
40328
39447
  const inputs = functionFragment.jsonFn.inputs;
40329
- let encodedArgs;
40330
- if (functionFragment.isInputDataPointer) {
40331
- if (rawPayload) {
40332
- const argsOffset = bn(receipt.param2).sub(calculateVmTxMemory({ maxInputs: maxInputs.toNumber() })).toNumber();
40333
- encodedArgs = `0x${rawPayload.slice(2).slice(argsOffset * 2)}`;
40334
- }
40335
- } else {
40336
- encodedArgs = receipt.param2.toHex();
40337
- }
39448
+ const encodedArgs = receipt.param2.toHex();
40338
39449
  let argumentsProvided;
40339
- if (encodedArgs) {
40340
- const data = functionFragment.decodeArguments(encodedArgs);
40341
- if (data) {
40342
- argumentsProvided = inputs.reduce((prev, input, index) => {
40343
- const value = data[index];
40344
- const name = input.name;
40345
- if (name) {
40346
- return {
40347
- ...prev,
40348
- // reparse to remove bn
40349
- [name]: JSON.parse(JSON.stringify(value))
40350
- };
40351
- }
40352
- return prev;
40353
- }, {});
40354
- }
39450
+ const data = functionFragment.decodeArguments(encodedArgs);
39451
+ if (data) {
39452
+ argumentsProvided = inputs.reduce((prev, input, index) => {
39453
+ const value = data[index];
39454
+ const name = input.name;
39455
+ if (name) {
39456
+ return {
39457
+ ...prev,
39458
+ // reparse to remove bn
39459
+ [name]: JSON.parse(JSON.stringify(value))
39460
+ };
39461
+ }
39462
+ return prev;
39463
+ }, {});
40355
39464
  }
40356
39465
  const call = {
40357
39466
  functionSignature: functionFragment.signature,
@@ -41162,14 +40271,12 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
41162
40271
  );
41163
40272
  transactionResult.logs = logs;
41164
40273
  }
41165
- if (transactionResult.isStatusFailure) {
41166
- const {
41167
- receipts,
41168
- gqlTransaction: { status }
41169
- } = transactionResult;
40274
+ const { gqlTransaction, receipts } = transactionResult;
40275
+ if (gqlTransaction.status?.type === "FailureStatus") {
40276
+ const { reason } = gqlTransaction.status;
41170
40277
  throw extractTxError({
41171
40278
  receipts,
41172
- status,
40279
+ statusReason: reason,
41173
40280
  logs
41174
40281
  });
41175
40282
  }
@@ -41248,13 +40355,13 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
41248
40355
  gasCosts,
41249
40356
  baseAssetId,
41250
40357
  chainId,
41251
- version: version2
40358
+ version
41252
40359
  } = consensusParameters;
41253
40360
  return {
41254
40361
  name,
41255
40362
  baseChainHeight: bn(daHeight),
41256
40363
  consensusParameters: {
41257
- version: version2,
40364
+ version,
41258
40365
  chainId: bn(chainId),
41259
40366
  baseAssetId,
41260
40367
  feeParameters: {
@@ -41901,7 +41008,10 @@ Supported fuel-core version: ${supportedVersion}.`
41901
41008
  await signatureCallback(txRequestClone);
41902
41009
  }
41903
41010
  ({ receipts, missingContractIds, outputVariables, dryRunStatus } = await this.estimateTxDependencies(txRequestClone));
41904
- gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
41011
+ if (dryRunStatus && "reason" in dryRunStatus) {
41012
+ throw this.extractDryRunError(txRequestClone, receipts, dryRunStatus);
41013
+ }
41014
+ gasUsed = getGasUsedFromReceipts(receipts);
41905
41015
  txRequestClone.gasLimit = gasUsed;
41906
41016
  ({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
41907
41017
  transactionRequest: txRequestClone,
@@ -42353,6 +41463,22 @@ Supported fuel-core version: ${supportedVersion}.`
42353
41463
  }
42354
41464
  return relayedTransactionStatus;
42355
41465
  }
41466
+ extractDryRunError(transactionRequest, receipts, dryRunStatus) {
41467
+ const status = dryRunStatus;
41468
+ let logs = [];
41469
+ if (transactionRequest.abis) {
41470
+ logs = getDecodedLogs(
41471
+ receipts,
41472
+ transactionRequest.abis.main,
41473
+ transactionRequest.abis.otherContractsAbis
41474
+ );
41475
+ }
41476
+ return extractTxError({
41477
+ logs,
41478
+ receipts,
41479
+ statusReason: status.reason
41480
+ });
41481
+ }
42356
41482
  };
42357
41483
  var Provider = _Provider;
42358
41484
  _cacheInputs = new WeakSet();
@@ -42504,7 +41630,7 @@ Supported fuel-core version: ${supportedVersion}.`
42504
41630
  return CHAIN_IDS.eth.sepolia;
42505
41631
  }
42506
41632
  if (networkType === "fuel") {
42507
- return CHAIN_IDS.fuel.beta5;
41633
+ return CHAIN_IDS.fuel.devnet;
42508
41634
  }
42509
41635
  return void 0;
42510
41636
  };
@@ -42848,7 +41974,6 @@ Supported fuel-core version: ${supportedVersion}.`
42848
41974
  cacheRequestInputsResourcesFromOwner(request.inputs, this.address)
42849
41975
  );
42850
41976
  request.addResources(resources);
42851
- request.shiftPredicateData();
42852
41977
  request.updatePredicateGasUsed(estimatedPredicates);
42853
41978
  const requestToReestimate2 = clone_default(request);
42854
41979
  if (addedSignatures) {
@@ -42880,7 +42005,6 @@ Supported fuel-core version: ${supportedVersion}.`
42880
42005
  }
42881
42006
  fundingAttempts += 1;
42882
42007
  }
42883
- request.shiftPredicateData();
42884
42008
  request.updatePredicateGasUsed(estimatedPredicates);
42885
42009
  const requestToReestimate = clone_default(request);
42886
42010
  if (addedSignatures) {
@@ -43430,12 +42554,12 @@ Supported fuel-core version: ${supportedVersion}.`
43430
42554
  const { windows, windowSize } = opts(W);
43431
42555
  let p = c.ZERO;
43432
42556
  let f2 = c.BASE;
43433
- const mask2 = BigInt(2 ** W - 1);
42557
+ const mask = BigInt(2 ** W - 1);
43434
42558
  const maxNumber = 2 ** W;
43435
42559
  const shiftBy = BigInt(W);
43436
42560
  for (let window2 = 0; window2 < windows; window2++) {
43437
42561
  const offset = window2 * windowSize;
43438
- let wbits = Number(n & mask2);
42562
+ let wbits = Number(n & mask);
43439
42563
  n >>= shiftBy;
43440
42564
  if (wbits > windowSize) {
43441
42565
  wbits -= maxNumber;
@@ -46776,38 +45900,6 @@ Supported fuel-core version: ${supportedVersion}.`
46776
45900
  })(Language || {});
46777
45901
 
46778
45902
  // src/mnemonic/utils.ts
46779
- function toUtf8Bytes2(stri) {
46780
- const str = stri.normalize("NFKD");
46781
- const result = [];
46782
- for (let i = 0; i < str.length; i += 1) {
46783
- const c = str.charCodeAt(i);
46784
- if (c < 128) {
46785
- result.push(c);
46786
- } else if (c < 2048) {
46787
- result.push(c >> 6 | 192);
46788
- result.push(c & 63 | 128);
46789
- } else if ((c & 64512) === 55296) {
46790
- i += 1;
46791
- const c2 = str.charCodeAt(i);
46792
- if (i >= str.length || (c2 & 64512) !== 56320) {
46793
- throw new FuelError(
46794
- ErrorCode.INVALID_INPUT_PARAMETERS,
46795
- "Invalid UTF-8 in the input string."
46796
- );
46797
- }
46798
- const pair = 65536 + ((c & 1023) << 10) + (c2 & 1023);
46799
- result.push(pair >> 18 | 240);
46800
- result.push(pair >> 12 & 63 | 128);
46801
- result.push(pair >> 6 & 63 | 128);
46802
- result.push(pair & 63 | 128);
46803
- } else {
46804
- result.push(c >> 12 | 224);
46805
- result.push(c >> 6 & 63 | 128);
46806
- result.push(c & 63 | 128);
46807
- }
46808
- }
46809
- return Uint8Array.from(result);
46810
- }
46811
45903
  function getLowerMask(bits) {
46812
45904
  return (1 << bits) - 1;
46813
45905
  }
@@ -46880,7 +45972,7 @@ Supported fuel-core version: ${supportedVersion}.`
46880
45972
  }
46881
45973
 
46882
45974
  // src/mnemonic/mnemonic.ts
46883
- var MasterSecret = toUtf8Bytes2("Bitcoin seed");
45975
+ var MasterSecret = toUtf8Bytes("Bitcoin seed");
46884
45976
  var MainnetPRV = "0x0488ade4";
46885
45977
  var TestnetPRV = "0x04358394";
46886
45978
  var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
@@ -46964,8 +46056,8 @@ Supported fuel-core version: ${supportedVersion}.`
46964
46056
  */
46965
46057
  static mnemonicToSeed(phrase, passphrase = "") {
46966
46058
  assertMnemonic(getWords(phrase));
46967
- const phraseBytes = toUtf8Bytes2(getPhrase(phrase));
46968
- const salt = toUtf8Bytes2(`mnemonic${passphrase}`);
46059
+ const phraseBytes = toUtf8Bytes(getPhrase(phrase));
46060
+ const salt = toUtf8Bytes(`mnemonic${passphrase}`);
46969
46061
  return pbkdf222(phraseBytes, salt, 2048, 64, "sha512");
46970
46062
  }
46971
46063
  /**
@@ -47593,7 +46685,7 @@ Supported fuel-core version: ${supportedVersion}.`
47593
46685
  wallet_not_unlocked: "The wallet is currently locked.",
47594
46686
  passphrase_not_match: "The provided passphrase did not match the expected value."
47595
46687
  };
47596
- function assert2(condition, message) {
46688
+ function assert(condition, message) {
47597
46689
  if (!condition) {
47598
46690
  throw new FuelError(ErrorCode.WALLET_MANAGER_ERROR, message);
47599
46691
  }
@@ -47636,9 +46728,9 @@ Supported fuel-core version: ${supportedVersion}.`
47636
46728
  * the format of the return depends on the Vault type.
47637
46729
  */
47638
46730
  exportVault(vaultId) {
47639
- assert2(!__privateGet(this, _isLocked), ERROR_MESSAGES.wallet_not_unlocked);
46731
+ assert(!__privateGet(this, _isLocked), ERROR_MESSAGES.wallet_not_unlocked);
47640
46732
  const vaultState = __privateGet(this, _vaults).find((_, idx) => idx === vaultId);
47641
- assert2(vaultState, ERROR_MESSAGES.vault_not_found);
46733
+ assert(vaultState, ERROR_MESSAGES.vault_not_found);
47642
46734
  return vaultState.vault.serialize();
47643
46735
  }
47644
46736
  /**
@@ -47667,7 +46759,7 @@ Supported fuel-core version: ${supportedVersion}.`
47667
46759
  const vaultState = __privateGet(this, _vaults).find(
47668
46760
  (vs) => vs.vault.getAccounts().find((a) => a.address.equals(ownerAddress))
47669
46761
  );
47670
- assert2(vaultState, ERROR_MESSAGES.address_not_found);
46762
+ assert(vaultState, ERROR_MESSAGES.address_not_found);
47671
46763
  return vaultState.vault.getWallet(ownerAddress);
47672
46764
  }
47673
46765
  /**
@@ -47675,11 +46767,11 @@ Supported fuel-core version: ${supportedVersion}.`
47675
46767
  */
47676
46768
  exportPrivateKey(address) {
47677
46769
  const ownerAddress = Address.fromAddressOrString(address);
47678
- assert2(!__privateGet(this, _isLocked), ERROR_MESSAGES.wallet_not_unlocked);
46770
+ assert(!__privateGet(this, _isLocked), ERROR_MESSAGES.wallet_not_unlocked);
47679
46771
  const vaultState = __privateGet(this, _vaults).find(
47680
46772
  (vs) => vs.vault.getAccounts().find((a) => a.address.equals(ownerAddress))
47681
46773
  );
47682
- assert2(vaultState, ERROR_MESSAGES.address_not_found);
46774
+ assert(vaultState, ERROR_MESSAGES.address_not_found);
47683
46775
  return vaultState.vault.exportAccount(ownerAddress);
47684
46776
  }
47685
46777
  /**
@@ -47689,7 +46781,7 @@ Supported fuel-core version: ${supportedVersion}.`
47689
46781
  async addAccount(options) {
47690
46782
  await this.loadState();
47691
46783
  const vaultState = __privateGet(this, _vaults)[options?.vaultId || 0];
47692
- await assert2(vaultState, ERROR_MESSAGES.vault_not_found);
46784
+ await assert(vaultState, ERROR_MESSAGES.vault_not_found);
47693
46785
  const account = vaultState.vault.addAccount();
47694
46786
  await this.saveState();
47695
46787
  return account;
@@ -47759,7 +46851,7 @@ Supported fuel-core version: ${supportedVersion}.`
47759
46851
  * Retrieve and decrypt WalletManager state from storage
47760
46852
  */
47761
46853
  async loadState() {
47762
- await assert2(!__privateGet(this, _isLocked), ERROR_MESSAGES.wallet_not_unlocked);
46854
+ await assert(!__privateGet(this, _isLocked), ERROR_MESSAGES.wallet_not_unlocked);
47763
46855
  const data = await this.storage.getItem(this.STORAGE_KEY);
47764
46856
  if (data) {
47765
46857
  const state = await decrypt2(__privateGet(this, _passphrase), JSON.parse(data));
@@ -47770,7 +46862,7 @@ Supported fuel-core version: ${supportedVersion}.`
47770
46862
  * Store encrypted WalletManager state on storage
47771
46863
  */
47772
46864
  async saveState() {
47773
- await assert2(!__privateGet(this, _isLocked), ERROR_MESSAGES.wallet_not_unlocked);
46865
+ await assert(!__privateGet(this, _isLocked), ERROR_MESSAGES.wallet_not_unlocked);
47774
46866
  const encryptedData = await encrypt2(__privateGet(this, _passphrase), {
47775
46867
  vaults: __privateMethod(this, _serializeVaults, serializeVaults_fn).call(this, __privateGet(this, _vaults))
47776
46868
  });
@@ -47782,7 +46874,7 @@ Supported fuel-core version: ${supportedVersion}.`
47782
46874
  */
47783
46875
  getVaultClass(type3) {
47784
46876
  const VaultClass = _WalletManager.Vaults.find((v) => v.type === type3);
47785
- assert2(VaultClass, ERROR_MESSAGES.invalid_vault_type);
46877
+ assert(VaultClass, ERROR_MESSAGES.invalid_vault_type);
47786
46878
  return VaultClass;
47787
46879
  }
47788
46880
  };
@@ -47954,7 +47046,6 @@ Supported fuel-core version: ${supportedVersion}.`
47954
47046
  */
47955
47047
  populateTransactionPredicateData(transactionRequestLike) {
47956
47048
  const request = transactionRequestify(transactionRequestLike);
47957
- const { policies } = BaseTransactionRequest.getPolicyMeta(request);
47958
47049
  const placeholderIndex = this.getIndexFromPlaceholderWitness(request);
47959
47050
  if (placeholderIndex !== -1) {
47960
47051
  request.removeWitness(placeholderIndex);
@@ -47962,7 +47053,7 @@ Supported fuel-core version: ${supportedVersion}.`
47962
47053
  request.inputs.filter(isRequestInputResource).forEach((input) => {
47963
47054
  if (isRequestInputResourceFromOwner(input, this.address)) {
47964
47055
  input.predicate = hexlify(this.bytes);
47965
- input.predicateData = hexlify(this.getPredicateData(policies.length));
47056
+ input.predicateData = hexlify(this.getPredicateData());
47966
47057
  input.witnessIndex = 0;
47967
47058
  }
47968
47059
  });
@@ -47988,17 +47079,12 @@ Supported fuel-core version: ${supportedVersion}.`
47988
47079
  const transactionRequest = transactionRequestify(transactionRequestLike);
47989
47080
  return super.simulateTransaction(transactionRequest, { estimateTxDependencies: false });
47990
47081
  }
47991
- getPredicateData(policiesLength) {
47082
+ getPredicateData() {
47992
47083
  if (!this.predicateData.length) {
47993
47084
  return new Uint8Array();
47994
47085
  }
47995
47086
  const mainFn = this.interface?.functions.main;
47996
- const paddedCode = new ByteArrayCoder(this.bytes.length).encode(this.bytes);
47997
- const VM_TX_MEMORY = calculateVmTxMemory({
47998
- maxInputs: this.provider.getChain().consensusParameters.txParameters.maxInputs.toNumber()
47999
- });
48000
- const OFFSET = VM_TX_MEMORY + SCRIPT_FIXED_SIZE + INPUT_COIN_FIXED_SIZE + WORD_SIZE + paddedCode.byteLength + policiesLength * WORD_SIZE;
48001
- return mainFn?.encodeArguments(this.predicateData, OFFSET) || new Uint8Array();
47087
+ return mainFn?.encodeArguments(this.predicateData) || new Uint8Array();
48002
47088
  }
48003
47089
  /**
48004
47090
  * Processes the predicate data and returns the altered bytecode and interface.
@@ -48047,8 +47133,7 @@ Supported fuel-core version: ${supportedVersion}.`
48047
47133
  );
48048
47134
  return resources.map((resource) => ({
48049
47135
  ...resource,
48050
- predicate: hexlify(this.bytes),
48051
- padPredicateData: (policiesLength) => hexlify(this.getPredicateData(policiesLength))
47136
+ predicate: hexlify(this.bytes)
48052
47137
  }));
48053
47138
  }
48054
47139
  /**