@fuel-ts/account 0.0.0-rc-1976-20240417161625 → 0.0.0-rc-2037-20240417202046

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 +124 -100
  3. package/dist/index.global.js.map +1 -1
  4. package/dist/index.js +280 -241
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +159 -126
  7. package/dist/index.mjs.map +1 -1
  8. package/dist/predicate/predicate.d.ts +11 -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,33 @@ 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) => {
1685
+ if (isRequestInputCoin(input)) {
1686
+ return input.owner;
1687
+ }
1688
+ return input.recipient;
1689
+ };
1690
+ var isRequestInputResourceFromOwner = (input, owner) => getRequestInputResourceOwner(input) === owner.toB256();
1691
+ var cacheResources = (resources) => resources.reduce(
1692
+ (cache2, resource) => {
1693
+ if (isCoin(resource)) {
1694
+ cache2.utxos.push(resource.id);
1695
+ } else {
1696
+ cache2.messages.push(resource.nonce);
1697
+ }
1698
+ return cache2;
1699
+ },
1700
+ {
1701
+ utxos: [],
1702
+ messages: []
1703
+ }
1704
+ );
1705
+
1677
1706
  // src/providers/transaction-request/witness.ts
1678
1707
  import { arrayify as arrayify4, hexlify as hexlify6 } from "@fuel-ts/utils";
1679
1708
  var witnessify = (value) => {
@@ -1700,8 +1729,6 @@ var BaseTransactionRequest = class {
1700
1729
  outputs = [];
1701
1730
  /** List of witnesses */
1702
1731
  witnesses = [];
1703
- /** Base asset ID - should be fetched from the chain */
1704
- baseAssetId;
1705
1732
  /**
1706
1733
  * Constructor for initializing a base transaction request.
1707
1734
  *
@@ -1714,9 +1741,8 @@ var BaseTransactionRequest = class {
1714
1741
  witnessLimit,
1715
1742
  inputs,
1716
1743
  outputs,
1717
- witnesses,
1718
- baseAssetId
1719
- }) {
1744
+ witnesses
1745
+ } = {}) {
1720
1746
  this.gasPrice = bn7(gasPrice);
1721
1747
  this.maturity = maturity ?? 0;
1722
1748
  this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
@@ -1724,7 +1750,6 @@ var BaseTransactionRequest = class {
1724
1750
  this.inputs = inputs ?? [];
1725
1751
  this.outputs = outputs ?? [];
1726
1752
  this.witnesses = witnesses ?? [];
1727
- this.baseAssetId = baseAssetId;
1728
1753
  }
1729
1754
  static getPolicyMeta(req) {
1730
1755
  let policyTypes = 0;
@@ -1868,7 +1893,7 @@ var BaseTransactionRequest = class {
1868
1893
  */
1869
1894
  getCoinInputs() {
1870
1895
  return this.inputs.filter(
1871
- (input) => input.type === InputType2.Coin
1896
+ (input) => input.type === InputType3.Coin
1872
1897
  );
1873
1898
  }
1874
1899
  /**
@@ -1900,9 +1925,9 @@ var BaseTransactionRequest = class {
1900
1925
  const ownerAddress = addressify(owner);
1901
1926
  const found = this.inputs.find((input) => {
1902
1927
  switch (input.type) {
1903
- case InputType2.Coin:
1928
+ case InputType3.Coin:
1904
1929
  return hexlify7(input.owner) === ownerAddress.toB256();
1905
- case InputType2.Message:
1930
+ case InputType3.Message:
1906
1931
  return hexlify7(input.recipient) === ownerAddress.toB256();
1907
1932
  default:
1908
1933
  return false;
@@ -1918,8 +1943,8 @@ var BaseTransactionRequest = class {
1918
1943
  * @param predicate - Predicate bytes.
1919
1944
  * @param predicateData - Predicate data bytes.
1920
1945
  */
1921
- addCoinInput(coin, predicate) {
1922
- const { assetId, owner, amount } = coin;
1946
+ addCoinInput(coin) {
1947
+ const { assetId, owner, amount, id, predicate } = coin;
1923
1948
  let witnessIndex;
1924
1949
  if (predicate) {
1925
1950
  witnessIndex = 0;
@@ -1930,14 +1955,14 @@ var BaseTransactionRequest = class {
1930
1955
  }
1931
1956
  }
1932
1957
  const input = {
1933
- ...coin,
1934
- type: InputType2.Coin,
1958
+ id,
1959
+ type: InputType3.Coin,
1935
1960
  owner: owner.toB256(),
1936
1961
  amount,
1937
1962
  assetId,
1938
1963
  txPointer: "0x00000000000000000000000000000000",
1939
1964
  witnessIndex,
1940
- predicate: predicate?.bytes
1965
+ predicate
1941
1966
  };
1942
1967
  this.pushInput(input);
1943
1968
  this.addChangeOutput(owner, assetId);
@@ -1948,9 +1973,11 @@ var BaseTransactionRequest = class {
1948
1973
  *
1949
1974
  * @param message - Message resource.
1950
1975
  * @param predicate - Predicate bytes.
1976
+ * @param predicateData - Predicate data bytes.
1951
1977
  */
1952
- addMessageInput(message, predicate) {
1953
- const { recipient, sender, amount } = message;
1978
+ addMessageInput(message) {
1979
+ const { recipient, sender, amount, predicate, nonce } = message;
1980
+ const assetId = BaseAssetId2;
1954
1981
  let witnessIndex;
1955
1982
  if (predicate) {
1956
1983
  witnessIndex = 0;
@@ -1961,16 +1988,16 @@ var BaseTransactionRequest = class {
1961
1988
  }
1962
1989
  }
1963
1990
  const input = {
1964
- ...message,
1965
- type: InputType2.Message,
1991
+ nonce,
1992
+ type: InputType3.Message,
1966
1993
  sender: sender.toB256(),
1967
1994
  recipient: recipient.toB256(),
1968
1995
  amount,
1969
1996
  witnessIndex,
1970
- predicate: predicate?.bytes
1997
+ predicate
1971
1998
  };
1972
1999
  this.pushInput(input);
1973
- this.addChangeOutput(recipient, this.baseAssetId);
2000
+ this.addChangeOutput(recipient, assetId);
1974
2001
  }
1975
2002
  /**
1976
2003
  * Adds a single resource to the transaction by adding a coin/message input and a
@@ -1998,32 +2025,6 @@ var BaseTransactionRequest = class {
1998
2025
  resources.forEach((resource) => this.addResource(resource));
1999
2026
  return this;
2000
2027
  }
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
2028
  /**
2028
2029
  * Adds a coin output to the transaction.
2029
2030
  *
@@ -2031,12 +2032,12 @@ var BaseTransactionRequest = class {
2031
2032
  * @param amount - Amount of coin.
2032
2033
  * @param assetId - Asset ID of coin.
2033
2034
  */
2034
- addCoinOutput(to, amount, assetId) {
2035
+ addCoinOutput(to, amount, assetId = BaseAssetId2) {
2035
2036
  this.pushOutput({
2036
2037
  type: OutputType2.Coin,
2037
2038
  to: addressify(to).toB256(),
2038
2039
  amount,
2039
- assetId: assetId ?? this.baseAssetId
2040
+ assetId
2040
2041
  });
2041
2042
  return this;
2042
2043
  }
@@ -2063,7 +2064,7 @@ var BaseTransactionRequest = class {
2063
2064
  * @param to - Address of the owner.
2064
2065
  * @param assetId - Asset ID of coin.
2065
2066
  */
2066
- addChangeOutput(to, assetId) {
2067
+ addChangeOutput(to, assetId = BaseAssetId2) {
2067
2068
  const changeOutput = this.getChangeOutputs().find(
2068
2069
  (output) => hexlify7(output.assetId) === assetId
2069
2070
  );
@@ -2071,7 +2072,7 @@ var BaseTransactionRequest = class {
2071
2072
  this.pushOutput({
2072
2073
  type: OutputType2.Change,
2073
2074
  to: addressify(to).toB256(),
2074
- assetId: assetId ?? this.baseAssetId
2075
+ assetId
2075
2076
  });
2076
2077
  }
2077
2078
  }
@@ -2147,7 +2148,7 @@ var BaseTransactionRequest = class {
2147
2148
  ]);
2148
2149
  }
2149
2150
  };
2150
- updateAssetInput(this.baseAssetId, bn7(1e11));
2151
+ updateAssetInput(BaseAssetId2, bn7(1e11));
2151
2152
  quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
2152
2153
  }
2153
2154
  /**
@@ -2172,16 +2173,20 @@ var BaseTransactionRequest = class {
2172
2173
  toJSON() {
2173
2174
  return normalizeJSON(this);
2174
2175
  }
2176
+ removeWitness(index) {
2177
+ this.witnesses.splice(index, 1);
2178
+ this.adjustWitnessIndexes(index);
2179
+ }
2175
2180
  updatePredicateInputs(inputs) {
2176
2181
  this.inputs.forEach((i) => {
2177
2182
  let correspondingInput;
2178
2183
  switch (i.type) {
2179
- case InputType2.Coin:
2180
- correspondingInput = inputs.find((x) => x.type === InputType2.Coin && x.owner === i.owner);
2184
+ case InputType3.Coin:
2185
+ correspondingInput = inputs.find((x) => x.type === InputType3.Coin && x.owner === i.owner);
2181
2186
  break;
2182
- case InputType2.Message:
2187
+ case InputType3.Message:
2183
2188
  correspondingInput = inputs.find(
2184
- (x) => x.type === InputType2.Message && x.sender === i.sender
2189
+ (x) => x.type === InputType3.Message && x.sender === i.sender
2185
2190
  );
2186
2191
  break;
2187
2192
  default:
@@ -2194,6 +2199,13 @@ var BaseTransactionRequest = class {
2194
2199
  }
2195
2200
  });
2196
2201
  }
2202
+ adjustWitnessIndexes(removedIndex) {
2203
+ this.inputs.filter(isRequestInputResource).forEach((input) => {
2204
+ if (input.witnessIndex > removedIndex) {
2205
+ input.witnessIndex -= 1;
2206
+ }
2207
+ });
2208
+ }
2197
2209
  };
2198
2210
 
2199
2211
  // src/providers/transaction-request/create-transaction-request.ts
@@ -2206,7 +2218,7 @@ import { arrayify as arrayify6, hexlify as hexlify9 } from "@fuel-ts/utils";
2206
2218
  import { ZeroBytes32 as ZeroBytes325 } from "@fuel-ts/address/configs";
2207
2219
  import { uint64ToBytesBE, sha256 } from "@fuel-ts/hasher";
2208
2220
  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";
2221
+ import { TransactionType as TransactionType2, InputType as InputType4, OutputType as OutputType3, TransactionCoder as TransactionCoder2 } from "@fuel-ts/transactions";
2210
2222
  import { concat as concat2 } from "@fuel-ts/utils";
2211
2223
  import { clone as clone2 } from "ramda";
2212
2224
  function hashTransaction(transactionRequest, chainId) {
@@ -2217,7 +2229,7 @@ function hashTransaction(transactionRequest, chainId) {
2217
2229
  transaction.inputs = transaction.inputs.map((input) => {
2218
2230
  const inputClone = clone2(input);
2219
2231
  switch (inputClone.type) {
2220
- case InputType3.Coin: {
2232
+ case InputType4.Coin: {
2221
2233
  inputClone.txPointer = {
2222
2234
  blockHeight: 0,
2223
2235
  txIndex: 0
@@ -2225,11 +2237,11 @@ function hashTransaction(transactionRequest, chainId) {
2225
2237
  inputClone.predicateGasUsed = bn8(0);
2226
2238
  return inputClone;
2227
2239
  }
2228
- case InputType3.Message: {
2240
+ case InputType4.Message: {
2229
2241
  inputClone.predicateGasUsed = bn8(0);
2230
2242
  return inputClone;
2231
2243
  }
2232
- case InputType3.Contract: {
2244
+ case InputType4.Contract: {
2233
2245
  inputClone.txPointer = {
2234
2246
  blockHeight: 0,
2235
2247
  txIndex: 0
@@ -2317,7 +2329,12 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2317
2329
  *
2318
2330
  * @param createTransactionRequestLike - The initial values for the instance
2319
2331
  */
2320
- constructor({ bytecodeWitnessIndex, salt, storageSlots, ...rest }) {
2332
+ constructor({
2333
+ bytecodeWitnessIndex,
2334
+ salt,
2335
+ storageSlots,
2336
+ ...rest
2337
+ } = {}) {
2321
2338
  super(rest);
2322
2339
  this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
2323
2340
  this.salt = hexlify9(salt ?? ZeroBytes326);
@@ -2390,7 +2407,7 @@ import { Interface } from "@fuel-ts/abi-coder";
2390
2407
  import { addressify as addressify2 } from "@fuel-ts/address";
2391
2408
  import { ZeroBytes32 as ZeroBytes327 } from "@fuel-ts/address/configs";
2392
2409
  import { bn as bn10 } from "@fuel-ts/math";
2393
- import { InputType as InputType4, OutputType as OutputType5, TransactionType as TransactionType4 } from "@fuel-ts/transactions";
2410
+ import { InputType as InputType5, OutputType as OutputType5, TransactionType as TransactionType4 } from "@fuel-ts/transactions";
2394
2411
  import { arrayify as arrayify8, hexlify as hexlify10 } from "@fuel-ts/utils";
2395
2412
 
2396
2413
  // src/providers/transaction-request/scripts.ts
@@ -2441,7 +2458,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2441
2458
  *
2442
2459
  * @param scriptTransactionRequestLike - The initial values for the instance.
2443
2460
  */
2444
- constructor({ script, scriptData, gasLimit, ...rest }) {
2461
+ constructor({ script, scriptData, gasLimit, ...rest } = {}) {
2445
2462
  super(rest);
2446
2463
  this.gasLimit = bn10(gasLimit);
2447
2464
  this.script = arrayify8(script ?? returnZeroScript.bytes);
@@ -2474,7 +2491,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2474
2491
  */
2475
2492
  getContractInputs() {
2476
2493
  return this.inputs.filter(
2477
- (input) => input.type === InputType4.Contract
2494
+ (input) => input.type === InputType5.Contract
2478
2495
  );
2479
2496
  }
2480
2497
  /**
@@ -2550,7 +2567,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2550
2567
  return this;
2551
2568
  }
2552
2569
  const inputIndex = super.pushInput({
2553
- type: InputType4.Contract,
2570
+ type: InputType5.Contract,
2554
2571
  contractId: contractAddress.toB256(),
2555
2572
  txPointer: "0x00000000000000000000000000000000"
2556
2573
  });
@@ -2745,7 +2762,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
2745
2762
 
2746
2763
  // src/providers/transaction-summary/input.ts
2747
2764
  import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
2748
- import { InputType as InputType5 } from "@fuel-ts/transactions";
2765
+ import { InputType as InputType6 } from "@fuel-ts/transactions";
2749
2766
  function getInputsByTypes(inputs, types) {
2750
2767
  return inputs.filter((i) => types.includes(i.type));
2751
2768
  }
@@ -2753,16 +2770,16 @@ function getInputsByType(inputs, type) {
2753
2770
  return inputs.filter((i) => i.type === type);
2754
2771
  }
2755
2772
  function getInputsCoin(inputs) {
2756
- return getInputsByType(inputs, InputType5.Coin);
2773
+ return getInputsByType(inputs, InputType6.Coin);
2757
2774
  }
2758
2775
  function getInputsMessage(inputs) {
2759
- return getInputsByType(inputs, InputType5.Message);
2776
+ return getInputsByType(inputs, InputType6.Message);
2760
2777
  }
2761
2778
  function getInputsCoinAndMessage(inputs) {
2762
- return getInputsByTypes(inputs, [InputType5.Coin, InputType5.Message]);
2779
+ return getInputsByTypes(inputs, [InputType6.Coin, InputType6.Message]);
2763
2780
  }
2764
2781
  function getInputsContract(inputs) {
2765
- return getInputsByType(inputs, InputType5.Contract);
2782
+ return getInputsByType(inputs, InputType6.Contract);
2766
2783
  }
2767
2784
  function getInputFromAssetId(inputs, assetId) {
2768
2785
  const coinInputs = getInputsCoin(inputs);
@@ -2781,7 +2798,7 @@ function getInputContractFromIndex(inputs, inputIndex) {
2781
2798
  if (!contractInput) {
2782
2799
  return void 0;
2783
2800
  }
2784
- if (contractInput.type !== InputType5.Contract) {
2801
+ if (contractInput.type !== InputType6.Contract) {
2785
2802
  throw new FuelError9(
2786
2803
  ErrorCode9.INVALID_TRANSACTION_INPUT,
2787
2804
  `Contract input should be of type 'contract'.`
@@ -2790,10 +2807,10 @@ function getInputContractFromIndex(inputs, inputIndex) {
2790
2807
  return contractInput;
2791
2808
  }
2792
2809
  function getInputAccountAddress(input) {
2793
- if (input.type === InputType5.Coin) {
2810
+ if (input.type === InputType6.Coin) {
2794
2811
  return input.owner.toString();
2795
2812
  }
2796
- if (input.type === InputType5.Message) {
2813
+ if (input.type === InputType6.Message) {
2797
2814
  return input.recipient.toString();
2798
2815
  }
2799
2816
  return "";
@@ -3616,7 +3633,6 @@ var processGqlChain = (chain) => {
3616
3633
  gasPerByte: bn15(feeParams.gasPerByte),
3617
3634
  maxMessageDataLength: bn15(predicateParams.maxMessageDataLength),
3618
3635
  chainId: bn15(consensusParameters.chainId),
3619
- baseAssetId: consensusParameters.baseAssetId,
3620
3636
  gasCosts
3621
3637
  },
3622
3638
  gasCosts,
@@ -3859,17 +3875,6 @@ var _Provider = class {
3859
3875
  } = this.getChain();
3860
3876
  return chainId.toNumber();
3861
3877
  }
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
3878
  /**
3874
3879
  * Submits a transaction to the chain to be executed.
3875
3880
  *
@@ -4549,7 +4554,7 @@ cacheInputs_fn = function(inputs) {
4549
4554
  return;
4550
4555
  }
4551
4556
  inputs.forEach((input) => {
4552
- if (input.type === InputType6.Coin) {
4557
+ if (input.type === InputType7.Coin) {
4553
4558
  this.cache?.set(input.id);
4554
4559
  }
4555
4560
  });
@@ -4933,9 +4938,8 @@ var Account = class extends AbstractAccount {
4933
4938
  * @param assetId - The asset ID to check the balance for.
4934
4939
  * @returns A promise that resolves to the balance amount.
4935
4940
  */
4936
- async getBalance(assetId) {
4937
- const assetIdToFetch = assetId ?? this.provider.getBaseAssetId();
4938
- const amount = await this.provider.getBalance(this.address, assetIdToFetch);
4941
+ async getBalance(assetId = BaseAssetId3) {
4942
+ const amount = await this.provider.getBalance(this.address, assetId);
4939
4943
  return amount;
4940
4944
  }
4941
4945
  /**
@@ -4973,10 +4977,9 @@ var Account = class extends AbstractAccount {
4973
4977
  * @returns A promise that resolves when the resources are added to the transaction.
4974
4978
  */
4975
4979
  async fund(request, coinQuantities, fee) {
4976
- const baseAssetId = this.provider.getBaseAssetId();
4977
4980
  const updatedQuantities = addAmountToAsset({
4978
4981
  amount: bn17(fee),
4979
- assetId: baseAssetId,
4982
+ assetId: BaseAssetId3,
4980
4983
  coinQuantities
4981
4984
  });
4982
4985
  const quantitiesDict = {};
@@ -5000,8 +5003,8 @@ var Account = class extends AbstractAccount {
5000
5003
  quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
5001
5004
  cachedUtxos.push(input.id);
5002
5005
  }
5003
- } else if (input.recipient === owner && input.amount && quantitiesDict[baseAssetId]) {
5004
- quantitiesDict[baseAssetId].owned = quantitiesDict[baseAssetId].owned.add(input.amount);
5006
+ } else if (input.recipient === owner && input.amount && quantitiesDict[BaseAssetId3]) {
5007
+ quantitiesDict[BaseAssetId3].owned = quantitiesDict[BaseAssetId3].owned.add(input.amount);
5005
5008
  cachedMessages.push(input.nonce);
5006
5009
  }
5007
5010
  }
@@ -5033,13 +5036,11 @@ var Account = class extends AbstractAccount {
5033
5036
  * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
5034
5037
  * @returns A promise that resolves to the prepared transaction request.
5035
5038
  */
5036
- async createTransfer(destination, amount, assetId, txParams = {}) {
5039
+ async createTransfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
5037
5040
  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 };
5041
+ const params = { gasPrice: minGasPrice, ...txParams };
5041
5042
  const request = new ScriptTransactionRequest(params);
5042
- request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetIdToTransfer);
5043
+ request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetId);
5043
5044
  const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
5044
5045
  estimateTxDependencies: true,
5045
5046
  resourcesOwner: this
@@ -5065,15 +5066,14 @@ var Account = class extends AbstractAccount {
5065
5066
  * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
5066
5067
  * @returns A promise that resolves to the transaction response.
5067
5068
  */
5068
- async transfer(destination, amount, assetId, txParams = {}) {
5069
+ async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
5069
5070
  if (bn17(amount).lte(0)) {
5070
5071
  throw new FuelError15(
5071
5072
  ErrorCode15.INVALID_TRANSFER_AMOUNT,
5072
5073
  "Transfer amount must be a positive number."
5073
5074
  );
5074
5075
  }
5075
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
5076
- const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
5076
+ const request = await this.createTransfer(destination, amount, assetId, txParams);
5077
5077
  return this.sendTransaction(request, { estimateTxDependencies: false });
5078
5078
  }
5079
5079
  /**
@@ -5085,7 +5085,7 @@ var Account = class extends AbstractAccount {
5085
5085
  * @param txParams - The optional transaction parameters.
5086
5086
  * @returns A promise that resolves to the transaction response.
5087
5087
  */
5088
- async transferToContract(contractId, amount, assetId, txParams = {}) {
5088
+ async transferToContract(contractId, amount, assetId = BaseAssetId3, txParams = {}) {
5089
5089
  if (bn17(amount).lte(0)) {
5090
5090
  throw new FuelError15(
5091
5091
  ErrorCode15.INVALID_TRANSFER_AMOUNT,
@@ -5094,13 +5094,11 @@ var Account = class extends AbstractAccount {
5094
5094
  }
5095
5095
  const contractAddress = Address3.fromAddressOrString(contractId);
5096
5096
  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 };
5097
+ const params = { gasPrice: minGasPrice, ...txParams };
5100
5098
  const { script, scriptData } = await assembleTransferToContractScript({
5101
5099
  hexlifiedContractId: contractAddress.toB256(),
5102
5100
  amountToTransfer: bn17(amount),
5103
- assetId: assetIdToTransfer
5101
+ assetId
5104
5102
  });
5105
5103
  const request = new ScriptTransactionRequest({
5106
5104
  ...params,
@@ -5110,7 +5108,7 @@ var Account = class extends AbstractAccount {
5110
5108
  request.addContractInputAndOutput(contractAddress);
5111
5109
  const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
5112
5110
  request,
5113
- [{ amount: bn17(amount), assetId: String(assetIdToTransfer) }]
5111
+ [{ amount: bn17(amount), assetId: String(assetId) }]
5114
5112
  );
5115
5113
  request.gasLimit = bn17(params.gasLimit ?? gasUsed);
5116
5114
  this.validateGas({
@@ -5132,7 +5130,6 @@ var Account = class extends AbstractAccount {
5132
5130
  */
5133
5131
  async withdrawToBaseLayer(recipient, amount, txParams = {}) {
5134
5132
  const { minGasPrice } = this.provider.getGasConfig();
5135
- const baseAssetId = this.provider.getBaseAssetId();
5136
5133
  const recipientAddress = Address3.fromAddressOrString(recipient);
5137
5134
  const recipientDataArray = arrayify14(
5138
5135
  "0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
@@ -5145,14 +5142,9 @@ var Account = class extends AbstractAccount {
5145
5142
  ...recipientDataArray,
5146
5143
  ...amountDataArray
5147
5144
  ]);
5148
- const params = {
5149
- script,
5150
- gasPrice: minGasPrice,
5151
- baseAssetId,
5152
- ...txParams
5153
- };
5145
+ const params = { script, gasPrice: minGasPrice, ...txParams };
5154
5146
  const request = new ScriptTransactionRequest(params);
5155
- const forwardingQuantities = [{ amount: bn17(amount), assetId: baseAssetId }];
5147
+ const forwardingQuantities = [{ amount: bn17(amount), assetId: BaseAssetId3 }];
5156
5148
  const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
5157
5149
  request,
5158
5150
  forwardingQuantities
@@ -8729,8 +8721,9 @@ import {
8729
8721
  SCRIPT_FIXED_SIZE
8730
8722
  } from "@fuel-ts/abi-coder";
8731
8723
  import { Address as Address9 } from "@fuel-ts/address";
8724
+ import { BaseAssetId as BaseAssetId4 } from "@fuel-ts/address/configs";
8732
8725
  import { ErrorCode as ErrorCode24, FuelError as FuelError24 } from "@fuel-ts/errors";
8733
- import { ByteArrayCoder, InputType as InputType7 } from "@fuel-ts/transactions";
8726
+ import { ByteArrayCoder } from "@fuel-ts/transactions";
8734
8727
  import { arrayify as arrayify20, hexlify as hexlify19 } from "@fuel-ts/utils";
8735
8728
 
8736
8729
  // src/predicate/utils/getPredicateRoot.ts
@@ -8789,10 +8782,15 @@ var Predicate = class extends Account {
8789
8782
  populateTransactionPredicateData(transactionRequestLike) {
8790
8783
  const request = transactionRequestify(transactionRequestLike);
8791
8784
  const { policies } = BaseTransactionRequest.getPolicyMeta(request);
8792
- request.inputs?.forEach((input) => {
8793
- if (input.type === InputType7.Coin && hexlify19(input.owner) === this.address.toB256()) {
8785
+ const placeholderIndex = this.getIndexFromPlaceholderWitness(request);
8786
+ if (placeholderIndex !== -1) {
8787
+ request.removeWitness(placeholderIndex);
8788
+ }
8789
+ request.inputs.filter(isRequestInputResource).forEach((input) => {
8790
+ if (isRequestInputResourceFromOwner(input, this.address)) {
8794
8791
  input.predicate = this.bytes;
8795
8792
  input.predicateData = this.getPredicateData(policies.length);
8793
+ input.witnessIndex = 0;
8796
8794
  }
8797
8795
  });
8798
8796
  return request;
@@ -8806,9 +8804,8 @@ var Predicate = class extends Account {
8806
8804
  * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
8807
8805
  * @returns A promise that resolves to the prepared transaction request.
8808
8806
  */
8809
- async createTransfer(destination, amount, assetId, txParams = {}) {
8810
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
8811
- const request = await super.createTransfer(destination, amount, assetIdToTransfer, txParams);
8807
+ async createTransfer(destination, amount, assetId = BaseAssetId4, txParams = {}) {
8808
+ const request = await super.createTransfer(destination, amount, assetId, txParams);
8812
8809
  return this.populateTransactionPredicateData(request);
8813
8810
  }
8814
8811
  /**
@@ -8831,6 +8828,20 @@ var Predicate = class extends Account {
8831
8828
  const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
8832
8829
  return super.simulateTransaction(transactionRequest);
8833
8830
  }
8831
+ /**
8832
+ * Retrieves resources satisfying the spend query for the account.
8833
+ *
8834
+ * @param quantities - IDs of coins to exclude.
8835
+ * @param excludedIds - IDs of resources to be excluded from the query.
8836
+ * @returns A promise that resolves to an array of Resources.
8837
+ */
8838
+ async getResourcesToSpend(quantities, excludedIds) {
8839
+ const resources = await super.getResourcesToSpend(quantities, excludedIds);
8840
+ return resources.map((resource) => ({
8841
+ ...resource,
8842
+ predicate: hexlify19(this.bytes)
8843
+ }));
8844
+ }
8834
8845
  getPredicateData(policiesLength) {
8835
8846
  if (!this.predicateData.length) {
8836
8847
  return new Uint8Array();
@@ -8910,6 +8921,22 @@ var Predicate = class extends Account {
8910
8921
  }
8911
8922
  return mutatedBytes;
8912
8923
  }
8924
+ getIndexFromPlaceholderWitness(request) {
8925
+ const predicateInputs = request.inputs.filter(isRequestInputResource).filter((input) => isRequestInputResourceFromOwner(input, this.address));
8926
+ let index = -1;
8927
+ const hasEmptyPredicateInputs = predicateInputs.find((input) => !input.predicate);
8928
+ if (hasEmptyPredicateInputs) {
8929
+ index = hasEmptyPredicateInputs.witnessIndex;
8930
+ const allInputsAreEmpty = predicateInputs.every((input) => !input.predicate);
8931
+ if (!allInputsAreEmpty) {
8932
+ const wasFilledInputAddedFirst = !!predicateInputs[0]?.predicate;
8933
+ if (wasFilledInputAddedFirst) {
8934
+ index = -1;
8935
+ }
8936
+ }
8937
+ }
8938
+ return index;
8939
+ }
8913
8940
  };
8914
8941
 
8915
8942
  // src/connectors/fuel.ts
@@ -9632,6 +9659,7 @@ export {
9632
9659
  assets,
9633
9660
  buildBlockExplorerUrl,
9634
9661
  cacheFor,
9662
+ cacheResources,
9635
9663
  calculateMetadataGasForTxCreate,
9636
9664
  calculateMetadataGasForTxScript,
9637
9665
  calculatePriceWithFactor,
@@ -9678,6 +9706,7 @@ export {
9678
9706
  getReceiptsMessageOut,
9679
9707
  getReceiptsTransferOut,
9680
9708
  getReceiptsWithMissingData,
9709
+ getRequestInputResourceOwner,
9681
9710
  getTransactionStatusName,
9682
9711
  getTransactionSummary,
9683
9712
  getTransactionSummaryFromRequest,
@@ -9691,6 +9720,10 @@ export {
9691
9720
  isMessage,
9692
9721
  isRawCoin,
9693
9722
  isRawMessage,
9723
+ isRequestInputCoin,
9724
+ isRequestInputMessage,
9725
+ isRequestInputResource,
9726
+ isRequestInputResourceFromOwner,
9694
9727
  isType,
9695
9728
  isTypeCreate,
9696
9729
  isTypeMint,