@fuel-ts/account 0.0.0-rc-1976-20240411153008 → 0.0.0-rc-2037-20240411163513

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 (33) hide show
  1. package/dist/account.d.ts.map +1 -1
  2. package/dist/index.global.js +120 -131
  3. package/dist/index.global.js.map +1 -1
  4. package/dist/index.js +197 -204
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +125 -132
  7. package/dist/index.mjs.map +1 -1
  8. package/dist/predicate/predicate.d.ts +9 -1
  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 +13 -9
  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/input.d.ts.map +1 -1
  21. package/dist/providers/transaction-request/script-transaction-request.d.ts +1 -1
  22. package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
  23. package/dist/providers/transaction-request/transaction-request.d.ts +4 -25
  24. package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
  25. package/dist/test-utils/launchNode.d.ts.map +1 -1
  26. package/dist/test-utils/seedTestWallet.d.ts.map +1 -1
  27. package/dist/test-utils.global.js +108 -137
  28. package/dist/test-utils.global.js.map +1 -1
  29. package/dist/test-utils.js +179 -204
  30. package/dist/test-utils.js.map +1 -1
  31. package/dist/test-utils.mjs +112 -137
  32. package/dist/test-utils.mjs.map +1 -1
  33. package/package.json +16 -16
@@ -24,12 +24,14 @@ import { hexlify as hexlify15 } from "@fuel-ts/utils";
24
24
 
25
25
  // src/account.ts
26
26
  import { Address as Address3 } from "@fuel-ts/address";
27
+ import { BaseAssetId as BaseAssetId3 } from "@fuel-ts/address/configs";
27
28
  import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
28
29
  import { AbstractAccount } from "@fuel-ts/interfaces";
29
30
  import { bn as bn17 } from "@fuel-ts/math";
30
31
  import { arrayify as arrayify14 } from "@fuel-ts/utils";
31
32
 
32
33
  // src/providers/coin-quantity.ts
34
+ import { BaseAssetId } from "@fuel-ts/address/configs";
33
35
  import { bn } from "@fuel-ts/math";
34
36
  import { hexlify } from "@fuel-ts/utils";
35
37
  var coinQuantityfy = (coinQuantityLike) => {
@@ -38,11 +40,11 @@ var coinQuantityfy = (coinQuantityLike) => {
38
40
  let max2;
39
41
  if (Array.isArray(coinQuantityLike)) {
40
42
  amount = coinQuantityLike[0];
41
- assetId = coinQuantityLike[1];
42
- max2 = coinQuantityLike[2];
43
+ assetId = coinQuantityLike[1] ?? BaseAssetId;
44
+ max2 = coinQuantityLike[2] ?? void 0;
43
45
  } else {
44
46
  amount = coinQuantityLike.amount;
45
- assetId = coinQuantityLike.assetId;
47
+ assetId = coinQuantityLike.assetId ?? BaseAssetId;
46
48
  max2 = coinQuantityLike.max ?? void 0;
47
49
  }
48
50
  const bnAmount = bn(amount);
@@ -1016,6 +1018,7 @@ var MemoryCache = class {
1016
1018
  };
1017
1019
 
1018
1020
  // src/providers/transaction-request/input.ts
1021
+ import { BYTES_32, UTXO_ID_LEN } from "@fuel-ts/abi-coder";
1019
1022
  import { ZeroBytes32 } from "@fuel-ts/address/configs";
1020
1023
  import { ErrorCode as ErrorCode3, FuelError as FuelError3 } from "@fuel-ts/errors";
1021
1024
  import { bn as bn2, toNumber } from "@fuel-ts/math";
@@ -1029,8 +1032,8 @@ var inputify = (value) => {
1029
1032
  const predicateData = arrayify(value.predicateData ?? "0x");
1030
1033
  return {
1031
1034
  type: InputType.Coin,
1032
- txID: hexlify3(arrayify(value.id).slice(0, 32)),
1033
- outputIndex: arrayify(value.id)[32],
1035
+ txID: hexlify3(arrayify(value.id).slice(0, BYTES_32)),
1036
+ outputIndex: toNumber(arrayify(value.id).slice(BYTES_32, UTXO_ID_LEN)),
1034
1037
  owner: hexlify3(value.owner),
1035
1038
  amount: bn2(value.amount),
1036
1039
  assetId: hexlify3(value.assetId),
@@ -1148,8 +1151,10 @@ var outputify = (value) => {
1148
1151
  };
1149
1152
 
1150
1153
  // src/providers/transaction-request/transaction-request.ts
1154
+ import { UTXO_ID_LEN as UTXO_ID_LEN2 } from "@fuel-ts/abi-coder";
1151
1155
  import { Address, addressify } from "@fuel-ts/address";
1152
- import { ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
1156
+ import { BaseAssetId as BaseAssetId2, ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
1157
+ import { randomBytes } from "@fuel-ts/crypto";
1153
1158
  import { bn as bn7 } from "@fuel-ts/math";
1154
1159
  import {
1155
1160
  PolicyType,
@@ -1609,8 +1614,6 @@ var BaseTransactionRequest = class {
1609
1614
  outputs = [];
1610
1615
  /** List of witnesses */
1611
1616
  witnesses = [];
1612
- /** Base asset ID - should be fetched from the chain */
1613
- baseAssetId;
1614
1617
  /**
1615
1618
  * Constructor for initializing a base transaction request.
1616
1619
  *
@@ -1623,9 +1626,8 @@ var BaseTransactionRequest = class {
1623
1626
  witnessLimit,
1624
1627
  inputs,
1625
1628
  outputs,
1626
- witnesses,
1627
- baseAssetId
1628
- }) {
1629
+ witnesses
1630
+ } = {}) {
1629
1631
  this.gasPrice = bn7(gasPrice);
1630
1632
  this.maturity = maturity ?? 0;
1631
1633
  this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
@@ -1633,7 +1635,6 @@ var BaseTransactionRequest = class {
1633
1635
  this.inputs = inputs ?? [];
1634
1636
  this.outputs = outputs ?? [];
1635
1637
  this.witnesses = witnesses ?? [];
1636
- this.baseAssetId = baseAssetId;
1637
1638
  }
1638
1639
  static getPolicyMeta(req) {
1639
1640
  let policyTypes = 0;
@@ -1827,8 +1828,8 @@ var BaseTransactionRequest = class {
1827
1828
  * @param predicate - Predicate bytes.
1828
1829
  * @param predicateData - Predicate data bytes.
1829
1830
  */
1830
- addCoinInput(coin, predicate) {
1831
- const { assetId, owner, amount } = coin;
1831
+ addCoinInput(coin) {
1832
+ const { assetId, owner, amount, id, predicate } = coin;
1832
1833
  let witnessIndex;
1833
1834
  if (predicate) {
1834
1835
  witnessIndex = 0;
@@ -1839,14 +1840,14 @@ var BaseTransactionRequest = class {
1839
1840
  }
1840
1841
  }
1841
1842
  const input = {
1842
- ...coin,
1843
+ id,
1843
1844
  type: InputType2.Coin,
1844
1845
  owner: owner.toB256(),
1845
1846
  amount,
1846
1847
  assetId,
1847
1848
  txPointer: "0x00000000000000000000000000000000",
1848
1849
  witnessIndex,
1849
- predicate: predicate?.bytes
1850
+ predicate
1850
1851
  };
1851
1852
  this.pushInput(input);
1852
1853
  this.addChangeOutput(owner, assetId);
@@ -1857,9 +1858,11 @@ var BaseTransactionRequest = class {
1857
1858
  *
1858
1859
  * @param message - Message resource.
1859
1860
  * @param predicate - Predicate bytes.
1861
+ * @param predicateData - Predicate data bytes.
1860
1862
  */
1861
- addMessageInput(message, predicate) {
1862
- const { recipient, sender, amount } = message;
1863
+ addMessageInput(message) {
1864
+ const { recipient, sender, amount, predicate, nonce } = message;
1865
+ const assetId = BaseAssetId2;
1863
1866
  let witnessIndex;
1864
1867
  if (predicate) {
1865
1868
  witnessIndex = 0;
@@ -1870,16 +1873,16 @@ var BaseTransactionRequest = class {
1870
1873
  }
1871
1874
  }
1872
1875
  const input = {
1873
- ...message,
1876
+ nonce,
1874
1877
  type: InputType2.Message,
1875
1878
  sender: sender.toB256(),
1876
1879
  recipient: recipient.toB256(),
1877
1880
  amount,
1878
1881
  witnessIndex,
1879
- predicate: predicate?.bytes
1882
+ predicate
1880
1883
  };
1881
1884
  this.pushInput(input);
1882
- this.addChangeOutput(recipient, this.baseAssetId);
1885
+ this.addChangeOutput(recipient, assetId);
1883
1886
  }
1884
1887
  /**
1885
1888
  * Adds a single resource to the transaction by adding a coin/message input and a
@@ -1907,32 +1910,6 @@ var BaseTransactionRequest = class {
1907
1910
  resources.forEach((resource) => this.addResource(resource));
1908
1911
  return this;
1909
1912
  }
1910
- /**
1911
- * Adds multiple resources to the transaction by adding coin/message inputs and change
1912
- * outputs from the related assetIds.
1913
- *
1914
- * @param resources - The resources to add.
1915
- * @returns This transaction.
1916
- */
1917
- addPredicateResource(resource, predicate) {
1918
- if (isCoin(resource)) {
1919
- this.addCoinInput(resource, predicate);
1920
- } else {
1921
- this.addMessageInput(resource, predicate);
1922
- }
1923
- return this;
1924
- }
1925
- /**
1926
- * Adds multiple predicate coin/message inputs to the transaction and change outputs
1927
- * from the related assetIds.
1928
- *
1929
- * @param resources - The resources to add.
1930
- * @returns This transaction.
1931
- */
1932
- addPredicateResources(resources, predicate) {
1933
- resources.forEach((resource) => this.addPredicateResource(resource, predicate));
1934
- return this;
1935
- }
1936
1913
  /**
1937
1914
  * Adds a coin output to the transaction.
1938
1915
  *
@@ -1940,12 +1917,12 @@ var BaseTransactionRequest = class {
1940
1917
  * @param amount - Amount of coin.
1941
1918
  * @param assetId - Asset ID of coin.
1942
1919
  */
1943
- addCoinOutput(to, amount, assetId) {
1920
+ addCoinOutput(to, amount, assetId = BaseAssetId2) {
1944
1921
  this.pushOutput({
1945
1922
  type: OutputType2.Coin,
1946
1923
  to: addressify(to).toB256(),
1947
1924
  amount,
1948
- assetId: assetId ?? this.baseAssetId
1925
+ assetId
1949
1926
  });
1950
1927
  return this;
1951
1928
  }
@@ -1972,7 +1949,7 @@ var BaseTransactionRequest = class {
1972
1949
  * @param to - Address of the owner.
1973
1950
  * @param assetId - Asset ID of coin.
1974
1951
  */
1975
- addChangeOutput(to, assetId) {
1952
+ addChangeOutput(to, assetId = BaseAssetId2) {
1976
1953
  const changeOutput = this.getChangeOutputs().find(
1977
1954
  (output) => hexlify7(output.assetId) === assetId
1978
1955
  );
@@ -1980,7 +1957,7 @@ var BaseTransactionRequest = class {
1980
1957
  this.pushOutput({
1981
1958
  type: OutputType2.Change,
1982
1959
  to: addressify(to).toB256(),
1983
- assetId: assetId ?? this.baseAssetId
1960
+ assetId
1984
1961
  });
1985
1962
  }
1986
1963
  }
@@ -2031,12 +2008,6 @@ var BaseTransactionRequest = class {
2031
2008
  * @param quantities - CoinQuantity Array.
2032
2009
  */
2033
2010
  fundWithFakeUtxos(quantities, resourcesOwner) {
2034
- let idCounter = 0;
2035
- const generateId = () => {
2036
- const counterString = String(idCounter++);
2037
- const id = ZeroBytes324.slice(0, -counterString.length).concat(counterString);
2038
- return id;
2039
- };
2040
2011
  const findAssetInput = (assetId) => this.inputs.find((input) => {
2041
2012
  if ("assetId" in input) {
2042
2013
  return input.assetId === assetId;
@@ -2046,12 +2017,12 @@ var BaseTransactionRequest = class {
2046
2017
  const updateAssetInput = (assetId, quantity) => {
2047
2018
  const assetInput = findAssetInput(assetId);
2048
2019
  if (assetInput && "assetId" in assetInput) {
2049
- assetInput.id = generateId();
2020
+ assetInput.id = hexlify7(randomBytes(UTXO_ID_LEN2));
2050
2021
  assetInput.amount = quantity;
2051
2022
  } else {
2052
2023
  this.addResources([
2053
2024
  {
2054
- id: generateId(),
2025
+ id: hexlify7(randomBytes(UTXO_ID_LEN2)),
2055
2026
  amount: quantity,
2056
2027
  assetId,
2057
2028
  owner: resourcesOwner || Address.fromRandom(),
@@ -2062,7 +2033,7 @@ var BaseTransactionRequest = class {
2062
2033
  ]);
2063
2034
  }
2064
2035
  };
2065
- updateAssetInput(this.baseAssetId, bn7(1e11));
2036
+ updateAssetInput(BaseAssetId2, bn7(1e11));
2066
2037
  quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
2067
2038
  }
2068
2039
  /**
@@ -2232,7 +2203,12 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2232
2203
  *
2233
2204
  * @param createTransactionRequestLike - The initial values for the instance
2234
2205
  */
2235
- constructor({ bytecodeWitnessIndex, salt, storageSlots, ...rest }) {
2206
+ constructor({
2207
+ bytecodeWitnessIndex,
2208
+ salt,
2209
+ storageSlots,
2210
+ ...rest
2211
+ } = {}) {
2236
2212
  super(rest);
2237
2213
  this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
2238
2214
  this.salt = hexlify9(salt ?? ZeroBytes326);
@@ -2356,7 +2332,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2356
2332
  *
2357
2333
  * @param scriptTransactionRequestLike - The initial values for the instance.
2358
2334
  */
2359
- constructor({ script, scriptData, gasLimit, ...rest }) {
2335
+ constructor({ script, scriptData, gasLimit, ...rest } = {}) {
2360
2336
  super(rest);
2361
2337
  this.gasLimit = bn10(gasLimit);
2362
2338
  this.script = arrayify8(script ?? returnZeroScript.bytes);
@@ -3484,7 +3460,6 @@ var processGqlChain = (chain) => {
3484
3460
  gasPerByte: bn15(feeParams.gasPerByte),
3485
3461
  maxMessageDataLength: bn15(predicateParams.maxMessageDataLength),
3486
3462
  chainId: bn15(consensusParameters.chainId),
3487
- baseAssetId: consensusParameters.baseAssetId,
3488
3463
  gasCosts
3489
3464
  },
3490
3465
  gasCosts,
@@ -3727,17 +3702,6 @@ var _Provider = class {
3727
3702
  } = this.getChain();
3728
3703
  return chainId.toNumber();
3729
3704
  }
3730
- /**
3731
- * Returns the base asset ID
3732
- *
3733
- * @returns A promise that resolves to the base asset ID
3734
- */
3735
- getBaseAssetId() {
3736
- const {
3737
- consensusParameters: { baseAssetId }
3738
- } = this.getChain();
3739
- return baseAssetId;
3740
- }
3741
3705
  /**
3742
3706
  * Submits a transaction to the chain to be executed.
3743
3707
  *
@@ -3888,6 +3852,36 @@ var _Provider = class {
3888
3852
  missingContractIds
3889
3853
  };
3890
3854
  }
3855
+ /**
3856
+ * Estimates the transaction gas and fee based on the provided transaction request.
3857
+ * @param transactionRequest - The transaction request object.
3858
+ * @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
3859
+ */
3860
+ estimateTxGasAndFee(params) {
3861
+ const { transactionRequest } = params;
3862
+ const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
3863
+ const chainInfo = this.getChain();
3864
+ const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
3865
+ transactionRequest.gasPrice = gasPrice;
3866
+ const minGas = transactionRequest.calculateMinGas(chainInfo);
3867
+ const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
3868
+ if (transactionRequest.type === TransactionType8.Script) {
3869
+ if (transactionRequest.gasLimit.eq(0)) {
3870
+ transactionRequest.gasLimit = minGas;
3871
+ transactionRequest.gasLimit = maxGasPerTx.sub(
3872
+ transactionRequest.calculateMaxGas(chainInfo, minGas)
3873
+ );
3874
+ }
3875
+ }
3876
+ const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
3877
+ const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
3878
+ return {
3879
+ minGas,
3880
+ minFee,
3881
+ maxGas,
3882
+ maxFee
3883
+ };
3884
+ }
3891
3885
  /**
3892
3886
  * Executes a signed transaction without applying the states changes
3893
3887
  * on the chain.
@@ -3935,17 +3929,16 @@ var _Provider = class {
3935
3929
  signatureCallback
3936
3930
  } = {}) {
3937
3931
  const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
3938
- const chainInfo = this.getChain();
3939
- const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
3940
- const gasPrice = max(txRequestClone.gasPrice, minGasPrice);
3932
+ const { minGasPrice } = this.getGasConfig();
3933
+ const setGasPrice = max(txRequestClone.gasPrice, minGasPrice);
3941
3934
  const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
3942
3935
  const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
3943
3936
  const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
3944
3937
  txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
3938
+ if (isScriptTransaction) {
3939
+ txRequestClone.gasLimit = bn15(0);
3940
+ }
3945
3941
  if (estimatePredicates) {
3946
- if (isScriptTransaction) {
3947
- txRequestClone.gasLimit = bn15(0);
3948
- }
3949
3942
  if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
3950
3943
  resourcesOwner.populateTransactionPredicateData(txRequestClone);
3951
3944
  }
@@ -3954,36 +3947,34 @@ var _Provider = class {
3954
3947
  if (signatureCallback && isScriptTransaction) {
3955
3948
  await signatureCallback(txRequestClone);
3956
3949
  }
3957
- const minGas = txRequestClone.calculateMinGas(chainInfo);
3958
- const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
3950
+ let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
3951
+ transactionRequest: txRequestClone
3952
+ });
3959
3953
  let receipts = [];
3960
3954
  let missingContractIds = [];
3961
3955
  let outputVariables = 0;
3956
+ let gasUsed = bn15(0);
3962
3957
  if (isScriptTransaction && estimateTxDependencies) {
3963
3958
  txRequestClone.gasPrice = bn15(0);
3964
- txRequestClone.gasLimit = bn15(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
3965
3959
  const result = await this.estimateTxDependencies(txRequestClone);
3966
3960
  receipts = result.receipts;
3967
3961
  outputVariables = result.outputVariables;
3968
3962
  missingContractIds = result.missingContractIds;
3963
+ gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
3964
+ txRequestClone.gasLimit = gasUsed;
3965
+ txRequestClone.gasPrice = setGasPrice;
3966
+ ({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
3967
+ transactionRequest: txRequestClone
3968
+ }));
3969
3969
  }
3970
- const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
3971
- const usedFee = calculatePriceWithFactor(
3972
- gasUsed,
3973
- gasPrice,
3974
- gasPriceFactor
3975
- ).normalizeZeroToOne();
3976
- const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
3977
- const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
3978
3970
  return {
3979
3971
  requiredQuantities: allQuantities,
3980
3972
  receipts,
3981
3973
  gasUsed,
3982
3974
  minGasPrice,
3983
- gasPrice,
3975
+ gasPrice: setGasPrice,
3984
3976
  minGas,
3985
3977
  maxGas,
3986
- usedFee,
3987
3978
  minFee,
3988
3979
  maxFee,
3989
3980
  estimatedInputs: txRequestClone.inputs,
@@ -4608,9 +4599,8 @@ var Account = class extends AbstractAccount {
4608
4599
  * @param assetId - The asset ID to check the balance for.
4609
4600
  * @returns A promise that resolves to the balance amount.
4610
4601
  */
4611
- async getBalance(assetId) {
4612
- const assetIdToFetch = assetId ?? this.provider.getBaseAssetId();
4613
- const amount = await this.provider.getBalance(this.address, assetIdToFetch);
4602
+ async getBalance(assetId = BaseAssetId3) {
4603
+ const amount = await this.provider.getBalance(this.address, assetId);
4614
4604
  return amount;
4615
4605
  }
4616
4606
  /**
@@ -4648,10 +4638,9 @@ var Account = class extends AbstractAccount {
4648
4638
  * @returns A promise that resolves when the resources are added to the transaction.
4649
4639
  */
4650
4640
  async fund(request, coinQuantities, fee) {
4651
- const baseAssetId = this.provider.getBaseAssetId();
4652
4641
  const updatedQuantities = addAmountToAsset({
4653
4642
  amount: bn17(fee),
4654
- assetId: baseAssetId,
4643
+ assetId: BaseAssetId3,
4655
4644
  coinQuantities
4656
4645
  });
4657
4646
  const quantitiesDict = {};
@@ -4675,8 +4664,8 @@ var Account = class extends AbstractAccount {
4675
4664
  quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
4676
4665
  cachedUtxos.push(input.id);
4677
4666
  }
4678
- } else if (input.recipient === owner && input.amount && quantitiesDict[baseAssetId]) {
4679
- quantitiesDict[baseAssetId].owned = quantitiesDict[baseAssetId].owned.add(input.amount);
4667
+ } else if (input.recipient === owner && input.amount && quantitiesDict[BaseAssetId3]) {
4668
+ quantitiesDict[BaseAssetId3].owned = quantitiesDict[BaseAssetId3].owned.add(input.amount);
4680
4669
  cachedMessages.push(input.nonce);
4681
4670
  }
4682
4671
  }
@@ -4708,13 +4697,11 @@ var Account = class extends AbstractAccount {
4708
4697
  * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
4709
4698
  * @returns A promise that resolves to the prepared transaction request.
4710
4699
  */
4711
- async createTransfer(destination, amount, assetId, txParams = {}) {
4700
+ async createTransfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
4712
4701
  const { minGasPrice } = this.provider.getGasConfig();
4713
- const baseAssetId = this.provider.getBaseAssetId();
4714
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
4715
- const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
4702
+ const params = { gasPrice: minGasPrice, ...txParams };
4716
4703
  const request = new ScriptTransactionRequest(params);
4717
- request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetIdToTransfer);
4704
+ request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetId);
4718
4705
  const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
4719
4706
  estimateTxDependencies: true,
4720
4707
  resourcesOwner: this
@@ -4740,15 +4727,14 @@ var Account = class extends AbstractAccount {
4740
4727
  * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
4741
4728
  * @returns A promise that resolves to the transaction response.
4742
4729
  */
4743
- async transfer(destination, amount, assetId, txParams = {}) {
4730
+ async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
4744
4731
  if (bn17(amount).lte(0)) {
4745
4732
  throw new FuelError15(
4746
4733
  ErrorCode15.INVALID_TRANSFER_AMOUNT,
4747
4734
  "Transfer amount must be a positive number."
4748
4735
  );
4749
4736
  }
4750
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
4751
- const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
4737
+ const request = await this.createTransfer(destination, amount, assetId, txParams);
4752
4738
  return this.sendTransaction(request, { estimateTxDependencies: false });
4753
4739
  }
4754
4740
  /**
@@ -4760,7 +4746,7 @@ var Account = class extends AbstractAccount {
4760
4746
  * @param txParams - The optional transaction parameters.
4761
4747
  * @returns A promise that resolves to the transaction response.
4762
4748
  */
4763
- async transferToContract(contractId, amount, assetId, txParams = {}) {
4749
+ async transferToContract(contractId, amount, assetId = BaseAssetId3, txParams = {}) {
4764
4750
  if (bn17(amount).lte(0)) {
4765
4751
  throw new FuelError15(
4766
4752
  ErrorCode15.INVALID_TRANSFER_AMOUNT,
@@ -4769,13 +4755,11 @@ var Account = class extends AbstractAccount {
4769
4755
  }
4770
4756
  const contractAddress = Address3.fromAddressOrString(contractId);
4771
4757
  const { minGasPrice } = this.provider.getGasConfig();
4772
- const baseAssetId = this.provider.getBaseAssetId();
4773
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
4774
- const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
4758
+ const params = { gasPrice: minGasPrice, ...txParams };
4775
4759
  const { script, scriptData } = await assembleTransferToContractScript({
4776
4760
  hexlifiedContractId: contractAddress.toB256(),
4777
4761
  amountToTransfer: bn17(amount),
4778
- assetId: assetIdToTransfer
4762
+ assetId
4779
4763
  });
4780
4764
  const request = new ScriptTransactionRequest({
4781
4765
  ...params,
@@ -4785,7 +4769,7 @@ var Account = class extends AbstractAccount {
4785
4769
  request.addContractInputAndOutput(contractAddress);
4786
4770
  const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
4787
4771
  request,
4788
- [{ amount: bn17(amount), assetId: String(assetIdToTransfer) }]
4772
+ [{ amount: bn17(amount), assetId: String(assetId) }]
4789
4773
  );
4790
4774
  request.gasLimit = bn17(params.gasLimit ?? gasUsed);
4791
4775
  this.validateGas({
@@ -4807,7 +4791,6 @@ var Account = class extends AbstractAccount {
4807
4791
  */
4808
4792
  async withdrawToBaseLayer(recipient, amount, txParams = {}) {
4809
4793
  const { minGasPrice } = this.provider.getGasConfig();
4810
- const baseAssetId = this.provider.getBaseAssetId();
4811
4794
  const recipientAddress = Address3.fromAddressOrString(recipient);
4812
4795
  const recipientDataArray = arrayify14(
4813
4796
  "0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
@@ -4820,14 +4803,9 @@ var Account = class extends AbstractAccount {
4820
4803
  ...recipientDataArray,
4821
4804
  ...amountDataArray
4822
4805
  ]);
4823
- const params = {
4824
- script,
4825
- gasPrice: minGasPrice,
4826
- baseAssetId,
4827
- ...txParams
4828
- };
4806
+ const params = { script, gasPrice: minGasPrice, ...txParams };
4829
4807
  const request = new ScriptTransactionRequest(params);
4830
- const forwardingQuantities = [{ amount: bn17(amount), assetId: baseAssetId }];
4808
+ const forwardingQuantities = [{ amount: bn17(amount), assetId: BaseAssetId3 }];
4831
4809
  const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
4832
4810
  request,
4833
4811
  forwardingQuantities
@@ -4920,7 +4898,7 @@ var Account = class extends AbstractAccount {
4920
4898
 
4921
4899
  // src/signer/signer.ts
4922
4900
  import { Address as Address4 } from "@fuel-ts/address";
4923
- import { randomBytes } from "@fuel-ts/crypto";
4901
+ import { randomBytes as randomBytes2 } from "@fuel-ts/crypto";
4924
4902
  import { hash } from "@fuel-ts/hasher";
4925
4903
  import { toBytes } from "@fuel-ts/math";
4926
4904
  import { hexlify as hexlify13, concat as concat3, arrayify as arrayify15 } from "@fuel-ts/utils";
@@ -5013,7 +4991,7 @@ var Signer = class {
5013
4991
  * @returns random 32-byte hashed
5014
4992
  */
5015
4993
  static generatePrivateKey(entropy) {
5016
- return entropy ? hash(concat3([randomBytes(32), arrayify15(entropy)])) : randomBytes(32);
4994
+ return entropy ? hash(concat3([randomBytes2(32), arrayify15(entropy)])) : randomBytes2(32);
5017
4995
  }
5018
4996
  /**
5019
4997
  * Extended publicKey from a compact publicKey
@@ -5032,7 +5010,7 @@ import { Address as Address5 } from "@fuel-ts/address";
5032
5010
  import {
5033
5011
  bufferFromString,
5034
5012
  keccak256,
5035
- randomBytes as randomBytes2,
5013
+ randomBytes as randomBytes3,
5036
5014
  scrypt,
5037
5015
  stringFromBuffer,
5038
5016
  decryptJsonWalletData,
@@ -5055,7 +5033,7 @@ var removeHexPrefix = (hexString) => {
5055
5033
  async function encryptKeystoreWallet(privateKey, address, password) {
5056
5034
  const privateKeyBuffer = bufferFromString(removeHexPrefix(privateKey), "hex");
5057
5035
  const ownerAddress = Address5.fromAddressOrString(address);
5058
- const salt = randomBytes2(DEFAULT_KEY_SIZE);
5036
+ const salt = randomBytes3(DEFAULT_KEY_SIZE);
5059
5037
  const key = scrypt({
5060
5038
  password: bufferFromString(password),
5061
5039
  salt,
@@ -5064,7 +5042,7 @@ async function encryptKeystoreWallet(privateKey, address, password) {
5064
5042
  r: DEFAULT_KDF_PARAMS_R,
5065
5043
  p: DEFAULT_KDF_PARAMS_P
5066
5044
  });
5067
- const iv = randomBytes2(DEFAULT_IV_SIZE);
5045
+ const iv = randomBytes3(DEFAULT_IV_SIZE);
5068
5046
  const ciphertext = await encryptJsonWalletData(privateKeyBuffer, key, iv);
5069
5047
  const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertext]);
5070
5048
  const macHashUint8Array = keccak256(data);
@@ -5246,7 +5224,7 @@ import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from
5246
5224
  import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
5247
5225
 
5248
5226
  // src/mnemonic/mnemonic.ts
5249
- import { randomBytes as randomBytes3 } from "@fuel-ts/crypto";
5227
+ import { randomBytes as randomBytes4 } from "@fuel-ts/crypto";
5250
5228
  import { ErrorCode as ErrorCode18, FuelError as FuelError18 } from "@fuel-ts/errors";
5251
5229
  import { sha256 as sha2563 } from "@fuel-ts/hasher";
5252
5230
  import { arrayify as arrayify17, hexlify as hexlify16, concat as concat4 } from "@fuel-ts/utils";
@@ -7601,7 +7579,7 @@ var Mnemonic = class {
7601
7579
  * @returns A randomly generated mnemonic
7602
7580
  */
7603
7581
  static generate(size = 32, extraEntropy = "") {
7604
- const entropy = extraEntropy ? sha2563(concat4([randomBytes3(size), arrayify17(extraEntropy)])) : randomBytes3(size);
7582
+ const entropy = extraEntropy ? sha2563(concat4([randomBytes4(size), arrayify17(extraEntropy)])) : randomBytes4(size);
7605
7583
  return Mnemonic.entropyToMnemonic(entropy);
7606
7584
  }
7607
7585
  };
@@ -7972,17 +7950,15 @@ __publicField(Wallet, "fromExtendedKey", WalletUnlocked.fromExtendedKey);
7972
7950
  __publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
7973
7951
 
7974
7952
  // src/test-utils/seedTestWallet.ts
7975
- import { randomBytes as randomBytes4 } from "@fuel-ts/crypto";
7953
+ import { randomBytes as randomBytes5 } from "@fuel-ts/crypto";
7976
7954
  var seedTestWallet = async (wallet, quantities) => {
7977
7955
  const genesisWallet = new WalletUnlocked(
7978
- process.env.GENESIS_SECRET || randomBytes4(32),
7956
+ process.env.GENESIS_SECRET || randomBytes5(32),
7979
7957
  wallet.provider
7980
7958
  );
7981
7959
  const resources = await genesisWallet.getResourcesToSpend(quantities);
7982
7960
  const { minGasPrice } = genesisWallet.provider.getGasConfig();
7983
- const baseAssetId = genesisWallet.provider.getBaseAssetId();
7984
7961
  const request = new ScriptTransactionRequest({
7985
- baseAssetId,
7986
7962
  gasLimit: 1e4,
7987
7963
  gasPrice: minGasPrice
7988
7964
  });
@@ -8001,7 +7977,7 @@ var generateTestWallet = async (provider, quantities) => {
8001
7977
  };
8002
7978
 
8003
7979
  // src/test-utils/launchNode.ts
8004
- import { ZeroBytes32 as ZeroBytes329 } from "@fuel-ts/address/configs";
7980
+ import { BaseAssetId as BaseAssetId4 } from "@fuel-ts/address/configs";
8005
7981
  import { toHex as toHex2 } from "@fuel-ts/math";
8006
7982
  import { defaultChainConfig, defaultConsensusKey, hexlify as hexlify18 } from "@fuel-ts/utils";
8007
7983
  import { findBinPath } from "@fuel-ts/utils/cli-utils";
@@ -8101,7 +8077,7 @@ var launchNode = async ({
8101
8077
  {
8102
8078
  owner: signer.address.toHexString(),
8103
8079
  amount: toHex2(1e9),
8104
- asset_id: defaultChainConfig?.consensus_parameters?.base_asset_id ?? ZeroBytes329
8080
+ asset_id: BaseAssetId4
8105
8081
  }
8106
8082
  ]
8107
8083
  }
@@ -8167,10 +8143,9 @@ var launchNode = async ({
8167
8143
  })
8168
8144
  );
8169
8145
  var generateWallets = async (count, provider) => {
8170
- const baseAssetId = provider.getBaseAssetId();
8171
8146
  const wallets = [];
8172
8147
  for (let i = 0; i < count; i += 1) {
8173
- const wallet = await generateTestWallet(provider, [[1e3, baseAssetId]]);
8148
+ const wallet = await generateTestWallet(provider, [[1e3, BaseAssetId4]]);
8174
8149
  wallets.push(wallet);
8175
8150
  }
8176
8151
  return wallets;