@fuel-ts/account 0.0.0-rc-1976-20240424151753 → 0.0.0-rc-2143-20240424152333

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.

@@ -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);
@@ -1160,7 +1162,7 @@ var outputify = (value) => {
1160
1162
  // src/providers/transaction-request/transaction-request.ts
1161
1163
  import { UTXO_ID_LEN as UTXO_ID_LEN2 } from "@fuel-ts/abi-coder";
1162
1164
  import { Address, addressify } from "@fuel-ts/address";
1163
- import { ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
1165
+ import { BaseAssetId as BaseAssetId2, ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
1164
1166
  import { randomBytes } from "@fuel-ts/crypto";
1165
1167
  import { bn as bn7 } from "@fuel-ts/math";
1166
1168
  import {
@@ -1861,13 +1863,15 @@ var BaseTransactionRequest = class {
1861
1863
  }
1862
1864
  /**
1863
1865
  * Adds a single message input to the transaction and a change output for the
1864
- * asset against the message
1866
+ * baseAssetId, if one it was not added yet.
1865
1867
  *
1866
1868
  * @param message - Message resource.
1867
1869
  * @param predicate - Predicate bytes.
1870
+ * @param predicateData - Predicate data bytes.
1868
1871
  */
1869
1872
  addMessageInput(message, predicate) {
1870
- const { recipient, sender, amount, assetId } = message;
1873
+ const { recipient, sender, amount } = message;
1874
+ const assetId = BaseAssetId2;
1871
1875
  let witnessIndex;
1872
1876
  if (predicate) {
1873
1877
  witnessIndex = 0;
@@ -1948,7 +1952,7 @@ var BaseTransactionRequest = class {
1948
1952
  * @param amount - Amount of coin.
1949
1953
  * @param assetId - Asset ID of coin.
1950
1954
  */
1951
- addCoinOutput(to, amount, assetId) {
1955
+ addCoinOutput(to, amount, assetId = BaseAssetId2) {
1952
1956
  this.pushOutput({
1953
1957
  type: OutputType2.Coin,
1954
1958
  to: addressify(to).toB256(),
@@ -1980,7 +1984,7 @@ var BaseTransactionRequest = class {
1980
1984
  * @param to - Address of the owner.
1981
1985
  * @param assetId - Asset ID of coin.
1982
1986
  */
1983
- addChangeOutput(to, assetId) {
1987
+ addChangeOutput(to, assetId = BaseAssetId2) {
1984
1988
  const changeOutput = this.getChangeOutputs().find(
1985
1989
  (output) => hexlify7(output.assetId) === assetId
1986
1990
  );
@@ -2037,9 +2041,8 @@ var BaseTransactionRequest = class {
2037
2041
  * quantities array.
2038
2042
  *
2039
2043
  * @param quantities - CoinQuantity Array.
2040
- * @param baseAssetId - The base asset to fund the transaction.
2041
2044
  */
2042
- fundWithFakeUtxos(quantities, baseAssetId, resourcesOwner) {
2045
+ fundWithFakeUtxos(quantities, resourcesOwner) {
2043
2046
  const findAssetInput = (assetId) => this.inputs.find((input) => {
2044
2047
  if ("assetId" in input) {
2045
2048
  return input.assetId === assetId;
@@ -2065,7 +2068,7 @@ var BaseTransactionRequest = class {
2065
2068
  ]);
2066
2069
  }
2067
2070
  };
2068
- updateAssetInput(baseAssetId, bn7(1e11));
2071
+ updateAssetInput(BaseAssetId2, bn7(1e11));
2069
2072
  quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
2070
2073
  }
2071
2074
  /**
@@ -2235,7 +2238,12 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2235
2238
  *
2236
2239
  * @param createTransactionRequestLike - The initial values for the instance
2237
2240
  */
2238
- constructor({ bytecodeWitnessIndex, salt, storageSlots, ...rest }) {
2241
+ constructor({
2242
+ bytecodeWitnessIndex,
2243
+ salt,
2244
+ storageSlots,
2245
+ ...rest
2246
+ } = {}) {
2239
2247
  super(rest);
2240
2248
  this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
2241
2249
  this.salt = hexlify9(salt ?? ZeroBytes326);
@@ -3449,7 +3457,7 @@ function autoRetryFetch(fetchFn, options, retryAttemptNum = 0) {
3449
3457
  }
3450
3458
 
3451
3459
  // src/providers/utils/merge-quantities.ts
3452
- var mergeQuantities = (...coinQuantities) => {
3460
+ var mergeQuantities = (arr1, arr2) => {
3453
3461
  const resultMap = {};
3454
3462
  function addToMap({ amount, assetId }) {
3455
3463
  if (resultMap[assetId]) {
@@ -3458,7 +3466,8 @@ var mergeQuantities = (...coinQuantities) => {
3458
3466
  resultMap[assetId] = amount;
3459
3467
  }
3460
3468
  }
3461
- coinQuantities.forEach((arr) => arr.forEach(addToMap));
3469
+ arr1.forEach(addToMap);
3470
+ arr2.forEach(addToMap);
3462
3471
  return Object.entries(resultMap).map(([assetId, amount]) => ({ assetId, amount }));
3463
3472
  };
3464
3473
 
@@ -3486,7 +3495,6 @@ var processGqlChain = (chain) => {
3486
3495
  gasPerByte: bn15(feeParams.gasPerByte),
3487
3496
  maxMessageDataLength: bn15(predicateParams.maxMessageDataLength),
3488
3497
  chainId: bn15(consensusParameters.chainId),
3489
- baseAssetId: consensusParameters.baseAssetId,
3490
3498
  gasCosts
3491
3499
  },
3492
3500
  gasCosts,
@@ -3729,17 +3737,6 @@ var _Provider = class {
3729
3737
  } = this.getChain();
3730
3738
  return chainId.toNumber();
3731
3739
  }
3732
- /**
3733
- * Returns the base asset ID
3734
- *
3735
- * @returns A promise that resolves to the base asset ID
3736
- */
3737
- getBaseAssetId() {
3738
- const {
3739
- consensusParameters: { baseAssetId }
3740
- } = this.getChain();
3741
- return baseAssetId;
3742
- }
3743
3740
  /**
3744
3741
  * Submits a transaction to the chain to be executed.
3745
3742
  *
@@ -3970,10 +3967,9 @@ var _Provider = class {
3970
3967
  const { minGasPrice } = this.getGasConfig();
3971
3968
  const setGasPrice = max(txRequestClone.gasPrice, minGasPrice);
3972
3969
  const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
3973
- const baseAssetId = this.getBaseAssetId();
3974
3970
  const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
3975
3971
  const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
3976
- txRequestClone.fundWithFakeUtxos(allQuantities, baseAssetId, resourcesOwner?.address);
3972
+ txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
3977
3973
  if (isScriptTransaction) {
3978
3974
  txRequestClone.gasLimit = bn15(0);
3979
3975
  }
@@ -4638,9 +4634,8 @@ var Account = class extends AbstractAccount {
4638
4634
  * @param assetId - The asset ID to check the balance for.
4639
4635
  * @returns A promise that resolves to the balance amount.
4640
4636
  */
4641
- async getBalance(assetId) {
4642
- const assetIdToFetch = assetId ?? this.provider.getBaseAssetId();
4643
- const amount = await this.provider.getBalance(this.address, assetIdToFetch);
4637
+ async getBalance(assetId = BaseAssetId3) {
4638
+ const amount = await this.provider.getBalance(this.address, assetId);
4644
4639
  return amount;
4645
4640
  }
4646
4641
  /**
@@ -4678,10 +4673,9 @@ var Account = class extends AbstractAccount {
4678
4673
  * @returns A promise that resolves when the resources are added to the transaction.
4679
4674
  */
4680
4675
  async fund(request, coinQuantities, fee) {
4681
- const baseAssetId = this.provider.getBaseAssetId();
4682
4676
  const updatedQuantities = addAmountToAsset({
4683
4677
  amount: bn17(fee),
4684
- assetId: baseAssetId,
4678
+ assetId: BaseAssetId3,
4685
4679
  coinQuantities
4686
4680
  });
4687
4681
  const quantitiesDict = {};
@@ -4705,8 +4699,8 @@ var Account = class extends AbstractAccount {
4705
4699
  quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
4706
4700
  cachedUtxos.push(input.id);
4707
4701
  }
4708
- } else if (input.recipient === owner && input.amount && quantitiesDict[baseAssetId]) {
4709
- quantitiesDict[baseAssetId].owned = quantitiesDict[baseAssetId].owned.add(input.amount);
4702
+ } else if (input.recipient === owner && input.amount && quantitiesDict[BaseAssetId3]) {
4703
+ quantitiesDict[BaseAssetId3].owned = quantitiesDict[BaseAssetId3].owned.add(input.amount);
4710
4704
  cachedMessages.push(input.nonce);
4711
4705
  }
4712
4706
  }
@@ -4738,12 +4732,11 @@ var Account = class extends AbstractAccount {
4738
4732
  * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
4739
4733
  * @returns A promise that resolves to the prepared transaction request.
4740
4734
  */
4741
- async createTransfer(destination, amount, assetId, txParams = {}) {
4735
+ async createTransfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
4742
4736
  const { minGasPrice } = this.provider.getGasConfig();
4743
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
4744
4737
  const params = { gasPrice: minGasPrice, ...txParams };
4745
4738
  const request = new ScriptTransactionRequest(params);
4746
- request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetIdToTransfer);
4739
+ request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetId);
4747
4740
  const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
4748
4741
  estimateTxDependencies: true,
4749
4742
  resourcesOwner: this
@@ -4769,15 +4762,14 @@ var Account = class extends AbstractAccount {
4769
4762
  * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
4770
4763
  * @returns A promise that resolves to the transaction response.
4771
4764
  */
4772
- async transfer(destination, amount, assetId, txParams = {}) {
4765
+ async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
4773
4766
  if (bn17(amount).lte(0)) {
4774
4767
  throw new FuelError15(
4775
4768
  ErrorCode15.INVALID_TRANSFER_AMOUNT,
4776
4769
  "Transfer amount must be a positive number."
4777
4770
  );
4778
4771
  }
4779
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
4780
- const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
4772
+ const request = await this.createTransfer(destination, amount, assetId, txParams);
4781
4773
  return this.sendTransaction(request, { estimateTxDependencies: false });
4782
4774
  }
4783
4775
  /**
@@ -4789,7 +4781,7 @@ var Account = class extends AbstractAccount {
4789
4781
  * @param txParams - The optional transaction parameters.
4790
4782
  * @returns A promise that resolves to the transaction response.
4791
4783
  */
4792
- async transferToContract(contractId, amount, assetId, txParams = {}) {
4784
+ async transferToContract(contractId, amount, assetId = BaseAssetId3, txParams = {}) {
4793
4785
  if (bn17(amount).lte(0)) {
4794
4786
  throw new FuelError15(
4795
4787
  ErrorCode15.INVALID_TRANSFER_AMOUNT,
@@ -4798,12 +4790,11 @@ var Account = class extends AbstractAccount {
4798
4790
  }
4799
4791
  const contractAddress = Address3.fromAddressOrString(contractId);
4800
4792
  const { minGasPrice } = this.provider.getGasConfig();
4801
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
4802
4793
  const params = { gasPrice: minGasPrice, ...txParams };
4803
4794
  const { script, scriptData } = await assembleTransferToContractScript({
4804
4795
  hexlifiedContractId: contractAddress.toB256(),
4805
4796
  amountToTransfer: bn17(amount),
4806
- assetId: assetIdToTransfer
4797
+ assetId
4807
4798
  });
4808
4799
  const request = new ScriptTransactionRequest({
4809
4800
  ...params,
@@ -4813,7 +4804,7 @@ var Account = class extends AbstractAccount {
4813
4804
  request.addContractInputAndOutput(contractAddress);
4814
4805
  const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
4815
4806
  request,
4816
- [{ amount: bn17(amount), assetId: String(assetIdToTransfer) }]
4807
+ [{ amount: bn17(amount), assetId: String(assetId) }]
4817
4808
  );
4818
4809
  request.gasLimit = bn17(params.gasLimit ?? gasUsed);
4819
4810
  this.validateGas({
@@ -4835,7 +4826,6 @@ var Account = class extends AbstractAccount {
4835
4826
  */
4836
4827
  async withdrawToBaseLayer(recipient, amount, txParams = {}) {
4837
4828
  const { minGasPrice } = this.provider.getGasConfig();
4838
- const baseAssetId = this.provider.getBaseAssetId();
4839
4829
  const recipientAddress = Address3.fromAddressOrString(recipient);
4840
4830
  const recipientDataArray = arrayify14(
4841
4831
  "0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
@@ -4848,13 +4838,9 @@ var Account = class extends AbstractAccount {
4848
4838
  ...recipientDataArray,
4849
4839
  ...amountDataArray
4850
4840
  ]);
4851
- const params = {
4852
- script,
4853
- gasPrice: minGasPrice,
4854
- ...txParams
4855
- };
4841
+ const params = { script, gasPrice: minGasPrice, ...txParams };
4856
4842
  const request = new ScriptTransactionRequest(params);
4857
- const forwardingQuantities = [{ amount: bn17(amount), assetId: baseAssetId }];
4843
+ const forwardingQuantities = [{ amount: bn17(amount), assetId: BaseAssetId3 }];
4858
4844
  const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
4859
4845
  request,
4860
4846
  forwardingQuantities
@@ -8026,7 +8012,7 @@ var generateTestWallet = async (provider, quantities) => {
8026
8012
  };
8027
8013
 
8028
8014
  // src/test-utils/launchNode.ts
8029
- import { ZeroBytes32 as ZeroBytes329 } from "@fuel-ts/address/configs";
8015
+ import { BaseAssetId as BaseAssetId4 } from "@fuel-ts/address/configs";
8030
8016
  import { toHex as toHex2 } from "@fuel-ts/math";
8031
8017
  import { defaultChainConfig, defaultConsensusKey, hexlify as hexlify18 } from "@fuel-ts/utils";
8032
8018
  import { findBinPath } from "@fuel-ts/utils/cli-utils";
@@ -8072,6 +8058,7 @@ var launchNode = async ({
8072
8058
  ip,
8073
8059
  port,
8074
8060
  args = [],
8061
+ fuelCorePath = void 0,
8075
8062
  useSystemFuelCore = false,
8076
8063
  loggingEnabled = true,
8077
8064
  debugEnabled = false,
@@ -8092,7 +8079,7 @@ var launchNode = async ({
8092
8079
  const poaInstantFlagValue = getFlagValueFromArgs(args, "--poa-instant");
8093
8080
  const poaInstant = poaInstantFlagValue === "true" || poaInstantFlagValue === void 0;
8094
8081
  const graphQLStartSubstring = "Binding GraphQL provider to";
8095
- const binPath = findBinPath("fuels-core", __dirname);
8082
+ const binPath = fuelCorePath ?? findBinPath("fuels-core", __dirname);
8096
8083
  const command = useSystemFuelCore ? "fuel-core" : binPath;
8097
8084
  const ipToUse = ip || "0.0.0.0";
8098
8085
  const portToUse = port || (await getPortPromise({
@@ -8126,7 +8113,7 @@ var launchNode = async ({
8126
8113
  {
8127
8114
  owner: signer.address.toHexString(),
8128
8115
  amount: toHex2(1e9),
8129
- asset_id: defaultChainConfig?.consensus_parameters?.base_asset_id ?? ZeroBytes329
8116
+ asset_id: BaseAssetId4
8130
8117
  }
8131
8118
  ]
8132
8119
  }
@@ -8192,10 +8179,9 @@ var launchNode = async ({
8192
8179
  })
8193
8180
  );
8194
8181
  var generateWallets = async (count, provider) => {
8195
- const baseAssetId = provider.getBaseAssetId();
8196
8182
  const wallets = [];
8197
8183
  for (let i = 0; i < count; i += 1) {
8198
- const wallet = await generateTestWallet(provider, [[1e3, baseAssetId]]);
8184
+ const wallet = await generateTestWallet(provider, [[1e3, BaseAssetId4]]);
8199
8185
  wallets.push(wallet);
8200
8186
  }
8201
8187
  return wallets;