@fuel-ts/account 0.0.0-rc-1976-20240418175539 → 0.0.0-rc-2037-20240418195040

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/index.global.js +125 -100
  3. package/dist/index.global.js.map +1 -1
  4. package/dist/index.js +281 -241
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +160 -126
  7. package/dist/index.mjs.map +1 -1
  8. package/dist/predicate/predicate.d.ts +17 -2
  9. package/dist/predicate/predicate.d.ts.map +1 -1
  10. package/dist/providers/coin-quantity.d.ts +2 -2
  11. package/dist/providers/coin-quantity.d.ts.map +1 -1
  12. package/dist/providers/coin.d.ts +2 -1
  13. package/dist/providers/coin.d.ts.map +1 -1
  14. package/dist/providers/message.d.ts +1 -0
  15. package/dist/providers/message.d.ts.map +1 -1
  16. package/dist/providers/provider.d.ts +0 -7
  17. package/dist/providers/provider.d.ts.map +1 -1
  18. package/dist/providers/transaction-request/create-transaction-request.d.ts +1 -1
  19. package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
  20. package/dist/providers/transaction-request/helpers.d.ts +10 -0
  21. package/dist/providers/transaction-request/helpers.d.ts.map +1 -0
  22. package/dist/providers/transaction-request/index.d.ts +1 -0
  23. package/dist/providers/transaction-request/index.d.ts.map +1 -1
  24. package/dist/providers/transaction-request/script-transaction-request.d.ts +1 -1
  25. package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
  26. package/dist/providers/transaction-request/transaction-request.d.ts +6 -25
  27. package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
  28. package/dist/test-utils/index.d.ts +1 -0
  29. package/dist/test-utils/index.d.ts.map +1 -1
  30. package/dist/test-utils/launchNode.d.ts.map +1 -1
  31. package/dist/test-utils/resources.d.ts +4 -0
  32. package/dist/test-utils/resources.d.ts.map +1 -0
  33. package/dist/test-utils/seedTestWallet.d.ts +1 -1
  34. package/dist/test-utils/seedTestWallet.d.ts.map +1 -1
  35. package/dist/test-utils/transactionRequest.d.ts +5 -0
  36. package/dist/test-utils/transactionRequest.d.ts.map +1 -0
  37. package/dist/test-utils.global.js +104 -105
  38. package/dist/test-utils.global.js.map +1 -1
  39. package/dist/test-utils.js +253 -238
  40. package/dist/test-utils.js.map +1 -1
  41. package/dist/test-utils.mjs +141 -129
  42. package/dist/test-utils.mjs.map +1 -1
  43. package/dist/wallet/base-wallet-unlocked.d.ts +2 -2
  44. package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
  45. package/package.json +15 -15
package/dist/index.mjs CHANGED
@@ -29,12 +29,14 @@ var __privateMethod = (obj, member, method) => {
29
29
 
30
30
  // src/account.ts
31
31
  import { Address as Address3 } from "@fuel-ts/address";
32
+ import { BaseAssetId as BaseAssetId3 } from "@fuel-ts/address/configs";
32
33
  import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
33
34
  import { AbstractAccount } from "@fuel-ts/interfaces";
34
35
  import { bn as bn17 } from "@fuel-ts/math";
35
36
  import { arrayify as arrayify14 } from "@fuel-ts/utils";
36
37
 
37
38
  // src/providers/coin-quantity.ts
39
+ import { BaseAssetId } from "@fuel-ts/address/configs";
38
40
  import { bn } from "@fuel-ts/math";
39
41
  import { hexlify } from "@fuel-ts/utils";
40
42
  var coinQuantityfy = (coinQuantityLike) => {
@@ -43,11 +45,11 @@ var coinQuantityfy = (coinQuantityLike) => {
43
45
  let max2;
44
46
  if (Array.isArray(coinQuantityLike)) {
45
47
  amount = coinQuantityLike[0];
46
- assetId = coinQuantityLike[1];
47
- max2 = coinQuantityLike[2];
48
+ assetId = coinQuantityLike[1] ?? BaseAssetId;
49
+ max2 = coinQuantityLike[2] ?? void 0;
48
50
  } else {
49
51
  amount = coinQuantityLike.amount;
50
- assetId = coinQuantityLike.assetId;
52
+ assetId = coinQuantityLike.assetId ?? BaseAssetId;
51
53
  max2 = coinQuantityLike.max ?? void 0;
52
54
  }
53
55
  const bnAmount = bn(amount);
@@ -74,7 +76,7 @@ import { Address as Address2 } from "@fuel-ts/address";
74
76
  import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
75
77
  import { BN, bn as bn15, max } from "@fuel-ts/math";
76
78
  import {
77
- InputType as InputType6,
79
+ InputType as InputType7,
78
80
  TransactionType as TransactionType8,
79
81
  InputMessageCoder,
80
82
  TransactionCoder as TransactionCoder5
@@ -1165,13 +1167,13 @@ var outputify = (value) => {
1165
1167
  // src/providers/transaction-request/transaction-request.ts
1166
1168
  import { UTXO_ID_LEN as UTXO_ID_LEN2 } from "@fuel-ts/abi-coder";
1167
1169
  import { Address, addressify } from "@fuel-ts/address";
1168
- import { ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
1170
+ import { BaseAssetId as BaseAssetId2, ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
1169
1171
  import { randomBytes } from "@fuel-ts/crypto";
1170
1172
  import { bn as bn7 } from "@fuel-ts/math";
1171
1173
  import {
1172
1174
  PolicyType,
1173
1175
  TransactionCoder,
1174
- InputType as InputType2,
1176
+ InputType as InputType3,
1175
1177
  OutputType as OutputType2,
1176
1178
  TransactionType
1177
1179
  } from "@fuel-ts/transactions";
@@ -1674,6 +1676,28 @@ var NoWitnessByOwnerError = class extends Error {
1674
1676
  name = "NoWitnessByOwnerError";
1675
1677
  };
1676
1678
 
1679
+ // src/providers/transaction-request/helpers.ts
1680
+ import { InputType as InputType2 } from "@fuel-ts/transactions";
1681
+ var isRequestInputCoin = (input) => input.type === InputType2.Coin;
1682
+ var isRequestInputMessage = (input) => input.type === InputType2.Message;
1683
+ var isRequestInputResource = (input) => isRequestInputCoin(input) || isRequestInputMessage(input);
1684
+ var getRequestInputResourceOwner = (input) => isRequestInputCoin(input) ? input.owner : input.recipient;
1685
+ var isRequestInputResourceFromOwner = (input, owner) => getRequestInputResourceOwner(input) === owner.toB256();
1686
+ var cacheResources = (resources) => resources.reduce(
1687
+ (cache2, resource) => {
1688
+ if (isCoin(resource)) {
1689
+ cache2.utxos.push(resource.id);
1690
+ } else {
1691
+ cache2.messages.push(resource.nonce);
1692
+ }
1693
+ return cache2;
1694
+ },
1695
+ {
1696
+ utxos: [],
1697
+ messages: []
1698
+ }
1699
+ );
1700
+
1677
1701
  // src/providers/transaction-request/witness.ts
1678
1702
  import { arrayify as arrayify4, hexlify as hexlify6 } from "@fuel-ts/utils";
1679
1703
  var witnessify = (value) => {
@@ -1700,8 +1724,6 @@ var BaseTransactionRequest = class {
1700
1724
  outputs = [];
1701
1725
  /** List of witnesses */
1702
1726
  witnesses = [];
1703
- /** Base asset ID - should be fetched from the chain */
1704
- baseAssetId;
1705
1727
  /**
1706
1728
  * Constructor for initializing a base transaction request.
1707
1729
  *
@@ -1714,9 +1736,8 @@ var BaseTransactionRequest = class {
1714
1736
  witnessLimit,
1715
1737
  inputs,
1716
1738
  outputs,
1717
- witnesses,
1718
- baseAssetId
1719
- }) {
1739
+ witnesses
1740
+ } = {}) {
1720
1741
  this.gasPrice = bn7(gasPrice);
1721
1742
  this.maturity = maturity ?? 0;
1722
1743
  this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
@@ -1724,7 +1745,6 @@ var BaseTransactionRequest = class {
1724
1745
  this.inputs = inputs ?? [];
1725
1746
  this.outputs = outputs ?? [];
1726
1747
  this.witnesses = witnesses ?? [];
1727
- this.baseAssetId = baseAssetId;
1728
1748
  }
1729
1749
  static getPolicyMeta(req) {
1730
1750
  let policyTypes = 0;
@@ -1868,7 +1888,7 @@ var BaseTransactionRequest = class {
1868
1888
  */
1869
1889
  getCoinInputs() {
1870
1890
  return this.inputs.filter(
1871
- (input) => input.type === InputType2.Coin
1891
+ (input) => input.type === InputType3.Coin
1872
1892
  );
1873
1893
  }
1874
1894
  /**
@@ -1900,9 +1920,9 @@ var BaseTransactionRequest = class {
1900
1920
  const ownerAddress = addressify(owner);
1901
1921
  const found = this.inputs.find((input) => {
1902
1922
  switch (input.type) {
1903
- case InputType2.Coin:
1923
+ case InputType3.Coin:
1904
1924
  return hexlify7(input.owner) === ownerAddress.toB256();
1905
- case InputType2.Message:
1925
+ case InputType3.Message:
1906
1926
  return hexlify7(input.recipient) === ownerAddress.toB256();
1907
1927
  default:
1908
1928
  return false;
@@ -1918,8 +1938,8 @@ var BaseTransactionRequest = class {
1918
1938
  * @param predicate - Predicate bytes.
1919
1939
  * @param predicateData - Predicate data bytes.
1920
1940
  */
1921
- addCoinInput(coin, predicate) {
1922
- const { assetId, owner, amount } = coin;
1941
+ addCoinInput(coin) {
1942
+ const { assetId, owner, amount, id, predicate } = coin;
1923
1943
  let witnessIndex;
1924
1944
  if (predicate) {
1925
1945
  witnessIndex = 0;
@@ -1930,14 +1950,14 @@ var BaseTransactionRequest = class {
1930
1950
  }
1931
1951
  }
1932
1952
  const input = {
1933
- ...coin,
1934
- type: InputType2.Coin,
1953
+ id,
1954
+ type: InputType3.Coin,
1935
1955
  owner: owner.toB256(),
1936
1956
  amount,
1937
1957
  assetId,
1938
1958
  txPointer: "0x00000000000000000000000000000000",
1939
1959
  witnessIndex,
1940
- predicate: predicate?.bytes
1960
+ predicate
1941
1961
  };
1942
1962
  this.pushInput(input);
1943
1963
  this.addChangeOutput(owner, assetId);
@@ -1948,9 +1968,11 @@ var BaseTransactionRequest = class {
1948
1968
  *
1949
1969
  * @param message - Message resource.
1950
1970
  * @param predicate - Predicate bytes.
1971
+ * @param predicateData - Predicate data bytes.
1951
1972
  */
1952
- addMessageInput(message, predicate) {
1953
- const { recipient, sender, amount } = message;
1973
+ addMessageInput(message) {
1974
+ const { recipient, sender, amount, predicate, nonce } = message;
1975
+ const assetId = BaseAssetId2;
1954
1976
  let witnessIndex;
1955
1977
  if (predicate) {
1956
1978
  witnessIndex = 0;
@@ -1961,16 +1983,16 @@ var BaseTransactionRequest = class {
1961
1983
  }
1962
1984
  }
1963
1985
  const input = {
1964
- ...message,
1965
- type: InputType2.Message,
1986
+ nonce,
1987
+ type: InputType3.Message,
1966
1988
  sender: sender.toB256(),
1967
1989
  recipient: recipient.toB256(),
1968
1990
  amount,
1969
1991
  witnessIndex,
1970
- predicate: predicate?.bytes
1992
+ predicate
1971
1993
  };
1972
1994
  this.pushInput(input);
1973
- this.addChangeOutput(recipient, this.baseAssetId);
1995
+ this.addChangeOutput(recipient, assetId);
1974
1996
  }
1975
1997
  /**
1976
1998
  * Adds a single resource to the transaction by adding a coin/message input and a
@@ -1998,32 +2020,6 @@ var BaseTransactionRequest = class {
1998
2020
  resources.forEach((resource) => this.addResource(resource));
1999
2021
  return this;
2000
2022
  }
2001
- /**
2002
- * Adds multiple resources to the transaction by adding coin/message inputs and change
2003
- * outputs from the related assetIds.
2004
- *
2005
- * @param resources - The resources to add.
2006
- * @returns This transaction.
2007
- */
2008
- addPredicateResource(resource, predicate) {
2009
- if (isCoin(resource)) {
2010
- this.addCoinInput(resource, predicate);
2011
- } else {
2012
- this.addMessageInput(resource, predicate);
2013
- }
2014
- return this;
2015
- }
2016
- /**
2017
- * Adds multiple predicate coin/message inputs to the transaction and change outputs
2018
- * from the related assetIds.
2019
- *
2020
- * @param resources - The resources to add.
2021
- * @returns This transaction.
2022
- */
2023
- addPredicateResources(resources, predicate) {
2024
- resources.forEach((resource) => this.addPredicateResource(resource, predicate));
2025
- return this;
2026
- }
2027
2023
  /**
2028
2024
  * Adds a coin output to the transaction.
2029
2025
  *
@@ -2031,12 +2027,12 @@ var BaseTransactionRequest = class {
2031
2027
  * @param amount - Amount of coin.
2032
2028
  * @param assetId - Asset ID of coin.
2033
2029
  */
2034
- addCoinOutput(to, amount, assetId) {
2030
+ addCoinOutput(to, amount, assetId = BaseAssetId2) {
2035
2031
  this.pushOutput({
2036
2032
  type: OutputType2.Coin,
2037
2033
  to: addressify(to).toB256(),
2038
2034
  amount,
2039
- assetId: assetId ?? this.baseAssetId
2035
+ assetId
2040
2036
  });
2041
2037
  return this;
2042
2038
  }
@@ -2063,7 +2059,7 @@ var BaseTransactionRequest = class {
2063
2059
  * @param to - Address of the owner.
2064
2060
  * @param assetId - Asset ID of coin.
2065
2061
  */
2066
- addChangeOutput(to, assetId) {
2062
+ addChangeOutput(to, assetId = BaseAssetId2) {
2067
2063
  const changeOutput = this.getChangeOutputs().find(
2068
2064
  (output) => hexlify7(output.assetId) === assetId
2069
2065
  );
@@ -2071,7 +2067,7 @@ var BaseTransactionRequest = class {
2071
2067
  this.pushOutput({
2072
2068
  type: OutputType2.Change,
2073
2069
  to: addressify(to).toB256(),
2074
- assetId: assetId ?? this.baseAssetId
2070
+ assetId
2075
2071
  });
2076
2072
  }
2077
2073
  }
@@ -2147,7 +2143,7 @@ var BaseTransactionRequest = class {
2147
2143
  ]);
2148
2144
  }
2149
2145
  };
2150
- updateAssetInput(this.baseAssetId, bn7(1e11));
2146
+ updateAssetInput(BaseAssetId2, bn7(1e11));
2151
2147
  quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
2152
2148
  }
2153
2149
  /**
@@ -2172,16 +2168,20 @@ var BaseTransactionRequest = class {
2172
2168
  toJSON() {
2173
2169
  return normalizeJSON(this);
2174
2170
  }
2171
+ removeWitness(index) {
2172
+ this.witnesses.splice(index, 1);
2173
+ this.adjustWitnessIndexes(index);
2174
+ }
2175
2175
  updatePredicateInputs(inputs) {
2176
2176
  this.inputs.forEach((i) => {
2177
2177
  let correspondingInput;
2178
2178
  switch (i.type) {
2179
- case InputType2.Coin:
2180
- correspondingInput = inputs.find((x) => x.type === InputType2.Coin && x.owner === i.owner);
2179
+ case InputType3.Coin:
2180
+ correspondingInput = inputs.find((x) => x.type === InputType3.Coin && x.owner === i.owner);
2181
2181
  break;
2182
- case InputType2.Message:
2182
+ case InputType3.Message:
2183
2183
  correspondingInput = inputs.find(
2184
- (x) => x.type === InputType2.Message && x.sender === i.sender
2184
+ (x) => x.type === InputType3.Message && x.sender === i.sender
2185
2185
  );
2186
2186
  break;
2187
2187
  default:
@@ -2194,6 +2194,13 @@ var BaseTransactionRequest = class {
2194
2194
  }
2195
2195
  });
2196
2196
  }
2197
+ adjustWitnessIndexes(removedIndex) {
2198
+ this.inputs.filter(isRequestInputResource).forEach((input) => {
2199
+ if (input.witnessIndex > removedIndex) {
2200
+ input.witnessIndex -= 1;
2201
+ }
2202
+ });
2203
+ }
2197
2204
  };
2198
2205
 
2199
2206
  // src/providers/transaction-request/create-transaction-request.ts
@@ -2206,7 +2213,7 @@ import { arrayify as arrayify6, hexlify as hexlify9 } from "@fuel-ts/utils";
2206
2213
  import { ZeroBytes32 as ZeroBytes325 } from "@fuel-ts/address/configs";
2207
2214
  import { uint64ToBytesBE, sha256 } from "@fuel-ts/hasher";
2208
2215
  import { bn as bn8 } from "@fuel-ts/math";
2209
- import { TransactionType as TransactionType2, InputType as InputType3, OutputType as OutputType3, TransactionCoder as TransactionCoder2 } from "@fuel-ts/transactions";
2216
+ import { TransactionType as TransactionType2, InputType as InputType4, OutputType as OutputType3, TransactionCoder as TransactionCoder2 } from "@fuel-ts/transactions";
2210
2217
  import { concat as concat2 } from "@fuel-ts/utils";
2211
2218
  import { clone as clone2 } from "ramda";
2212
2219
  function hashTransaction(transactionRequest, chainId) {
@@ -2217,7 +2224,7 @@ function hashTransaction(transactionRequest, chainId) {
2217
2224
  transaction.inputs = transaction.inputs.map((input) => {
2218
2225
  const inputClone = clone2(input);
2219
2226
  switch (inputClone.type) {
2220
- case InputType3.Coin: {
2227
+ case InputType4.Coin: {
2221
2228
  inputClone.txPointer = {
2222
2229
  blockHeight: 0,
2223
2230
  txIndex: 0
@@ -2225,11 +2232,11 @@ function hashTransaction(transactionRequest, chainId) {
2225
2232
  inputClone.predicateGasUsed = bn8(0);
2226
2233
  return inputClone;
2227
2234
  }
2228
- case InputType3.Message: {
2235
+ case InputType4.Message: {
2229
2236
  inputClone.predicateGasUsed = bn8(0);
2230
2237
  return inputClone;
2231
2238
  }
2232
- case InputType3.Contract: {
2239
+ case InputType4.Contract: {
2233
2240
  inputClone.txPointer = {
2234
2241
  blockHeight: 0,
2235
2242
  txIndex: 0
@@ -2317,7 +2324,12 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2317
2324
  *
2318
2325
  * @param createTransactionRequestLike - The initial values for the instance
2319
2326
  */
2320
- constructor({ bytecodeWitnessIndex, salt, storageSlots, ...rest }) {
2327
+ constructor({
2328
+ bytecodeWitnessIndex,
2329
+ salt,
2330
+ storageSlots,
2331
+ ...rest
2332
+ } = {}) {
2321
2333
  super(rest);
2322
2334
  this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
2323
2335
  this.salt = hexlify9(salt ?? ZeroBytes326);
@@ -2390,7 +2402,7 @@ import { Interface } from "@fuel-ts/abi-coder";
2390
2402
  import { addressify as addressify2 } from "@fuel-ts/address";
2391
2403
  import { ZeroBytes32 as ZeroBytes327 } from "@fuel-ts/address/configs";
2392
2404
  import { bn as bn10 } from "@fuel-ts/math";
2393
- import { InputType as InputType4, OutputType as OutputType5, TransactionType as TransactionType4 } from "@fuel-ts/transactions";
2405
+ import { InputType as InputType5, OutputType as OutputType5, TransactionType as TransactionType4 } from "@fuel-ts/transactions";
2394
2406
  import { arrayify as arrayify8, hexlify as hexlify10 } from "@fuel-ts/utils";
2395
2407
 
2396
2408
  // src/providers/transaction-request/scripts.ts
@@ -2441,7 +2453,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2441
2453
  *
2442
2454
  * @param scriptTransactionRequestLike - The initial values for the instance.
2443
2455
  */
2444
- constructor({ script, scriptData, gasLimit, ...rest }) {
2456
+ constructor({ script, scriptData, gasLimit, ...rest } = {}) {
2445
2457
  super(rest);
2446
2458
  this.gasLimit = bn10(gasLimit);
2447
2459
  this.script = arrayify8(script ?? returnZeroScript.bytes);
@@ -2474,7 +2486,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2474
2486
  */
2475
2487
  getContractInputs() {
2476
2488
  return this.inputs.filter(
2477
- (input) => input.type === InputType4.Contract
2489
+ (input) => input.type === InputType5.Contract
2478
2490
  );
2479
2491
  }
2480
2492
  /**
@@ -2550,7 +2562,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2550
2562
  return this;
2551
2563
  }
2552
2564
  const inputIndex = super.pushInput({
2553
- type: InputType4.Contract,
2565
+ type: InputType5.Contract,
2554
2566
  contractId: contractAddress.toB256(),
2555
2567
  txPointer: "0x00000000000000000000000000000000"
2556
2568
  });
@@ -2745,7 +2757,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
2745
2757
 
2746
2758
  // src/providers/transaction-summary/input.ts
2747
2759
  import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
2748
- import { InputType as InputType5 } from "@fuel-ts/transactions";
2760
+ import { InputType as InputType6 } from "@fuel-ts/transactions";
2749
2761
  function getInputsByTypes(inputs, types) {
2750
2762
  return inputs.filter((i) => types.includes(i.type));
2751
2763
  }
@@ -2753,16 +2765,16 @@ function getInputsByType(inputs, type) {
2753
2765
  return inputs.filter((i) => i.type === type);
2754
2766
  }
2755
2767
  function getInputsCoin(inputs) {
2756
- return getInputsByType(inputs, InputType5.Coin);
2768
+ return getInputsByType(inputs, InputType6.Coin);
2757
2769
  }
2758
2770
  function getInputsMessage(inputs) {
2759
- return getInputsByType(inputs, InputType5.Message);
2771
+ return getInputsByType(inputs, InputType6.Message);
2760
2772
  }
2761
2773
  function getInputsCoinAndMessage(inputs) {
2762
- return getInputsByTypes(inputs, [InputType5.Coin, InputType5.Message]);
2774
+ return getInputsByTypes(inputs, [InputType6.Coin, InputType6.Message]);
2763
2775
  }
2764
2776
  function getInputsContract(inputs) {
2765
- return getInputsByType(inputs, InputType5.Contract);
2777
+ return getInputsByType(inputs, InputType6.Contract);
2766
2778
  }
2767
2779
  function getInputFromAssetId(inputs, assetId) {
2768
2780
  const coinInputs = getInputsCoin(inputs);
@@ -2781,7 +2793,7 @@ function getInputContractFromIndex(inputs, inputIndex) {
2781
2793
  if (!contractInput) {
2782
2794
  return void 0;
2783
2795
  }
2784
- if (contractInput.type !== InputType5.Contract) {
2796
+ if (contractInput.type !== InputType6.Contract) {
2785
2797
  throw new FuelError9(
2786
2798
  ErrorCode9.INVALID_TRANSACTION_INPUT,
2787
2799
  `Contract input should be of type 'contract'.`
@@ -2790,10 +2802,10 @@ function getInputContractFromIndex(inputs, inputIndex) {
2790
2802
  return contractInput;
2791
2803
  }
2792
2804
  function getInputAccountAddress(input) {
2793
- if (input.type === InputType5.Coin) {
2805
+ if (input.type === InputType6.Coin) {
2794
2806
  return input.owner.toString();
2795
2807
  }
2796
- if (input.type === InputType5.Message) {
2808
+ if (input.type === InputType6.Message) {
2797
2809
  return input.recipient.toString();
2798
2810
  }
2799
2811
  return "";
@@ -3616,7 +3628,6 @@ var processGqlChain = (chain) => {
3616
3628
  gasPerByte: bn15(feeParams.gasPerByte),
3617
3629
  maxMessageDataLength: bn15(predicateParams.maxMessageDataLength),
3618
3630
  chainId: bn15(consensusParameters.chainId),
3619
- baseAssetId: consensusParameters.baseAssetId,
3620
3631
  gasCosts
3621
3632
  },
3622
3633
  gasCosts,
@@ -3859,17 +3870,6 @@ var _Provider = class {
3859
3870
  } = this.getChain();
3860
3871
  return chainId.toNumber();
3861
3872
  }
3862
- /**
3863
- * Returns the base asset ID
3864
- *
3865
- * @returns A promise that resolves to the base asset ID
3866
- */
3867
- getBaseAssetId() {
3868
- const {
3869
- consensusParameters: { baseAssetId }
3870
- } = this.getChain();
3871
- return baseAssetId;
3872
- }
3873
3873
  /**
3874
3874
  * Submits a transaction to the chain to be executed.
3875
3875
  *
@@ -4549,7 +4549,7 @@ cacheInputs_fn = function(inputs) {
4549
4549
  return;
4550
4550
  }
4551
4551
  inputs.forEach((input) => {
4552
- if (input.type === InputType6.Coin) {
4552
+ if (input.type === InputType7.Coin) {
4553
4553
  this.cache?.set(input.id);
4554
4554
  }
4555
4555
  });
@@ -4933,9 +4933,8 @@ var Account = class extends AbstractAccount {
4933
4933
  * @param assetId - The asset ID to check the balance for.
4934
4934
  * @returns A promise that resolves to the balance amount.
4935
4935
  */
4936
- async getBalance(assetId) {
4937
- const assetIdToFetch = assetId ?? this.provider.getBaseAssetId();
4938
- const amount = await this.provider.getBalance(this.address, assetIdToFetch);
4936
+ async getBalance(assetId = BaseAssetId3) {
4937
+ const amount = await this.provider.getBalance(this.address, assetId);
4939
4938
  return amount;
4940
4939
  }
4941
4940
  /**
@@ -4973,10 +4972,9 @@ var Account = class extends AbstractAccount {
4973
4972
  * @returns A promise that resolves when the resources are added to the transaction.
4974
4973
  */
4975
4974
  async fund(request, coinQuantities, fee) {
4976
- const baseAssetId = this.provider.getBaseAssetId();
4977
4975
  const updatedQuantities = addAmountToAsset({
4978
4976
  amount: bn17(fee),
4979
- assetId: baseAssetId,
4977
+ assetId: BaseAssetId3,
4980
4978
  coinQuantities
4981
4979
  });
4982
4980
  const quantitiesDict = {};
@@ -5000,8 +4998,8 @@ var Account = class extends AbstractAccount {
5000
4998
  quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
5001
4999
  cachedUtxos.push(input.id);
5002
5000
  }
5003
- } else if (input.recipient === owner && input.amount && quantitiesDict[baseAssetId]) {
5004
- quantitiesDict[baseAssetId].owned = quantitiesDict[baseAssetId].owned.add(input.amount);
5001
+ } else if (input.recipient === owner && input.amount && quantitiesDict[BaseAssetId3]) {
5002
+ quantitiesDict[BaseAssetId3].owned = quantitiesDict[BaseAssetId3].owned.add(input.amount);
5005
5003
  cachedMessages.push(input.nonce);
5006
5004
  }
5007
5005
  }
@@ -5033,13 +5031,11 @@ var Account = class extends AbstractAccount {
5033
5031
  * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
5034
5032
  * @returns A promise that resolves to the prepared transaction request.
5035
5033
  */
5036
- async createTransfer(destination, amount, assetId, txParams = {}) {
5034
+ async createTransfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
5037
5035
  const { minGasPrice } = this.provider.getGasConfig();
5038
- const baseAssetId = this.provider.getBaseAssetId();
5039
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
5040
- const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
5036
+ const params = { gasPrice: minGasPrice, ...txParams };
5041
5037
  const request = new ScriptTransactionRequest(params);
5042
- request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetIdToTransfer);
5038
+ request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetId);
5043
5039
  const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
5044
5040
  estimateTxDependencies: true,
5045
5041
  resourcesOwner: this
@@ -5065,15 +5061,14 @@ var Account = class extends AbstractAccount {
5065
5061
  * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
5066
5062
  * @returns A promise that resolves to the transaction response.
5067
5063
  */
5068
- async transfer(destination, amount, assetId, txParams = {}) {
5064
+ async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
5069
5065
  if (bn17(amount).lte(0)) {
5070
5066
  throw new FuelError15(
5071
5067
  ErrorCode15.INVALID_TRANSFER_AMOUNT,
5072
5068
  "Transfer amount must be a positive number."
5073
5069
  );
5074
5070
  }
5075
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
5076
- const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
5071
+ const request = await this.createTransfer(destination, amount, assetId, txParams);
5077
5072
  return this.sendTransaction(request, { estimateTxDependencies: false });
5078
5073
  }
5079
5074
  /**
@@ -5085,7 +5080,7 @@ var Account = class extends AbstractAccount {
5085
5080
  * @param txParams - The optional transaction parameters.
5086
5081
  * @returns A promise that resolves to the transaction response.
5087
5082
  */
5088
- async transferToContract(contractId, amount, assetId, txParams = {}) {
5083
+ async transferToContract(contractId, amount, assetId = BaseAssetId3, txParams = {}) {
5089
5084
  if (bn17(amount).lte(0)) {
5090
5085
  throw new FuelError15(
5091
5086
  ErrorCode15.INVALID_TRANSFER_AMOUNT,
@@ -5094,13 +5089,11 @@ var Account = class extends AbstractAccount {
5094
5089
  }
5095
5090
  const contractAddress = Address3.fromAddressOrString(contractId);
5096
5091
  const { minGasPrice } = this.provider.getGasConfig();
5097
- const baseAssetId = this.provider.getBaseAssetId();
5098
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
5099
- const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
5092
+ const params = { gasPrice: minGasPrice, ...txParams };
5100
5093
  const { script, scriptData } = await assembleTransferToContractScript({
5101
5094
  hexlifiedContractId: contractAddress.toB256(),
5102
5095
  amountToTransfer: bn17(amount),
5103
- assetId: assetIdToTransfer
5096
+ assetId
5104
5097
  });
5105
5098
  const request = new ScriptTransactionRequest({
5106
5099
  ...params,
@@ -5110,7 +5103,7 @@ var Account = class extends AbstractAccount {
5110
5103
  request.addContractInputAndOutput(contractAddress);
5111
5104
  const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
5112
5105
  request,
5113
- [{ amount: bn17(amount), assetId: String(assetIdToTransfer) }]
5106
+ [{ amount: bn17(amount), assetId: String(assetId) }]
5114
5107
  );
5115
5108
  request.gasLimit = bn17(params.gasLimit ?? gasUsed);
5116
5109
  this.validateGas({
@@ -5132,7 +5125,6 @@ var Account = class extends AbstractAccount {
5132
5125
  */
5133
5126
  async withdrawToBaseLayer(recipient, amount, txParams = {}) {
5134
5127
  const { minGasPrice } = this.provider.getGasConfig();
5135
- const baseAssetId = this.provider.getBaseAssetId();
5136
5128
  const recipientAddress = Address3.fromAddressOrString(recipient);
5137
5129
  const recipientDataArray = arrayify14(
5138
5130
  "0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
@@ -5145,14 +5137,9 @@ var Account = class extends AbstractAccount {
5145
5137
  ...recipientDataArray,
5146
5138
  ...amountDataArray
5147
5139
  ]);
5148
- const params = {
5149
- script,
5150
- gasPrice: minGasPrice,
5151
- baseAssetId,
5152
- ...txParams
5153
- };
5140
+ const params = { script, gasPrice: minGasPrice, ...txParams };
5154
5141
  const request = new ScriptTransactionRequest(params);
5155
- const forwardingQuantities = [{ amount: bn17(amount), assetId: baseAssetId }];
5142
+ const forwardingQuantities = [{ amount: bn17(amount), assetId: BaseAssetId3 }];
5156
5143
  const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
5157
5144
  request,
5158
5145
  forwardingQuantities
@@ -8729,8 +8716,9 @@ import {
8729
8716
  SCRIPT_FIXED_SIZE
8730
8717
  } from "@fuel-ts/abi-coder";
8731
8718
  import { Address as Address9 } from "@fuel-ts/address";
8719
+ import { BaseAssetId as BaseAssetId4 } from "@fuel-ts/address/configs";
8732
8720
  import { ErrorCode as ErrorCode24, FuelError as FuelError24 } from "@fuel-ts/errors";
8733
- import { ByteArrayCoder, InputType as InputType7 } from "@fuel-ts/transactions";
8721
+ import { ByteArrayCoder } from "@fuel-ts/transactions";
8734
8722
  import { arrayify as arrayify20, hexlify as hexlify19 } from "@fuel-ts/utils";
8735
8723
 
8736
8724
  // src/predicate/utils/getPredicateRoot.ts
@@ -8789,10 +8777,15 @@ var Predicate = class extends Account {
8789
8777
  populateTransactionPredicateData(transactionRequestLike) {
8790
8778
  const request = transactionRequestify(transactionRequestLike);
8791
8779
  const { policies } = BaseTransactionRequest.getPolicyMeta(request);
8792
- request.inputs?.forEach((input) => {
8793
- if (input.type === InputType7.Coin && hexlify19(input.owner) === this.address.toB256()) {
8780
+ const placeholderIndex = this.getIndexFromPlaceholderWitness(request);
8781
+ if (placeholderIndex !== -1) {
8782
+ request.removeWitness(placeholderIndex);
8783
+ }
8784
+ request.inputs.filter(isRequestInputResource).forEach((input) => {
8785
+ if (isRequestInputResourceFromOwner(input, this.address)) {
8794
8786
  input.predicate = this.bytes;
8795
8787
  input.predicateData = this.getPredicateData(policies.length);
8788
+ input.witnessIndex = 0;
8796
8789
  }
8797
8790
  });
8798
8791
  return request;
@@ -8806,9 +8799,8 @@ var Predicate = class extends Account {
8806
8799
  * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
8807
8800
  * @returns A promise that resolves to the prepared transaction request.
8808
8801
  */
8809
- async createTransfer(destination, amount, assetId, txParams = {}) {
8810
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
8811
- const request = await super.createTransfer(destination, amount, assetIdToTransfer, txParams);
8802
+ async createTransfer(destination, amount, assetId = BaseAssetId4, txParams = {}) {
8803
+ const request = await super.createTransfer(destination, amount, assetId, txParams);
8812
8804
  return this.populateTransactionPredicateData(request);
8813
8805
  }
8814
8806
  /**
@@ -8831,6 +8823,20 @@ var Predicate = class extends Account {
8831
8823
  const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
8832
8824
  return super.simulateTransaction(transactionRequest);
8833
8825
  }
8826
+ /**
8827
+ * Retrieves resources satisfying the spend query for the account.
8828
+ *
8829
+ * @param quantities - Coins to retrieve.
8830
+ * @param excludedIds - IDs of resources to be excluded from the query.
8831
+ * @returns A promise that resolves to an array of Resources.
8832
+ */
8833
+ async getResourcesToSpend(quantities, excludedIds) {
8834
+ const resources = await super.getResourcesToSpend(quantities, excludedIds);
8835
+ return resources.map((resource) => ({
8836
+ ...resource,
8837
+ predicate: hexlify19(this.bytes)
8838
+ }));
8839
+ }
8834
8840
  getPredicateData(policiesLength) {
8835
8841
  if (!this.predicateData.length) {
8836
8842
  return new Uint8Array();
@@ -8910,6 +8916,28 @@ var Predicate = class extends Account {
8910
8916
  }
8911
8917
  return mutatedBytes;
8912
8918
  }
8919
+ /**
8920
+ * Returns the index of the witness placeholder that was added to this predicate.
8921
+ * If no witness placeholder was added, it returns -1.
8922
+ * @param request - The transaction request.
8923
+ * @returns The index of the witness placeholder, or -1 if there is no witness placeholder.
8924
+ */
8925
+ getIndexFromPlaceholderWitness(request) {
8926
+ const predicateInputs = request.inputs.filter(isRequestInputResource).filter((input) => isRequestInputResourceFromOwner(input, this.address));
8927
+ let index = -1;
8928
+ const hasEmptyPredicateInputs = predicateInputs.find((input) => !input.predicate);
8929
+ if (hasEmptyPredicateInputs) {
8930
+ index = hasEmptyPredicateInputs.witnessIndex;
8931
+ const allInputsAreEmpty = predicateInputs.every((input) => !input.predicate);
8932
+ if (!allInputsAreEmpty) {
8933
+ const wasFilledInputAddedFirst = !!predicateInputs[0]?.predicate;
8934
+ if (wasFilledInputAddedFirst) {
8935
+ index = -1;
8936
+ }
8937
+ }
8938
+ }
8939
+ return index;
8940
+ }
8913
8941
  };
8914
8942
 
8915
8943
  // src/connectors/fuel.ts
@@ -9632,6 +9660,7 @@ export {
9632
9660
  assets,
9633
9661
  buildBlockExplorerUrl,
9634
9662
  cacheFor,
9663
+ cacheResources,
9635
9664
  calculateMetadataGasForTxCreate,
9636
9665
  calculateMetadataGasForTxScript,
9637
9666
  calculatePriceWithFactor,
@@ -9678,6 +9707,7 @@ export {
9678
9707
  getReceiptsMessageOut,
9679
9708
  getReceiptsTransferOut,
9680
9709
  getReceiptsWithMissingData,
9710
+ getRequestInputResourceOwner,
9681
9711
  getTransactionStatusName,
9682
9712
  getTransactionSummary,
9683
9713
  getTransactionSummaryFromRequest,
@@ -9691,6 +9721,10 @@ export {
9691
9721
  isMessage,
9692
9722
  isRawCoin,
9693
9723
  isRawMessage,
9724
+ isRequestInputCoin,
9725
+ isRequestInputMessage,
9726
+ isRequestInputResource,
9727
+ isRequestInputResourceFromOwner,
9694
9728
  isType,
9695
9729
  isTypeCreate,
9696
9730
  isTypeMint,