@fuel-ts/account 0.0.0-rc-2045-20240419094011 → 0.0.0-rc-1976-20240419101644

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,14 +24,12 @@ 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";
28
27
  import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
29
28
  import { AbstractAccount } from "@fuel-ts/interfaces";
30
29
  import { bn as bn17 } from "@fuel-ts/math";
31
30
  import { arrayify as arrayify14 } from "@fuel-ts/utils";
32
31
 
33
32
  // src/providers/coin-quantity.ts
34
- import { BaseAssetId } from "@fuel-ts/address/configs";
35
33
  import { bn } from "@fuel-ts/math";
36
34
  import { hexlify } from "@fuel-ts/utils";
37
35
  var coinQuantityfy = (coinQuantityLike) => {
@@ -40,11 +38,11 @@ var coinQuantityfy = (coinQuantityLike) => {
40
38
  let max2;
41
39
  if (Array.isArray(coinQuantityLike)) {
42
40
  amount = coinQuantityLike[0];
43
- assetId = coinQuantityLike[1] ?? BaseAssetId;
44
- max2 = coinQuantityLike[2] ?? void 0;
41
+ assetId = coinQuantityLike[1];
42
+ max2 = coinQuantityLike[2];
45
43
  } else {
46
44
  amount = coinQuantityLike.amount;
47
- assetId = coinQuantityLike.assetId ?? BaseAssetId;
45
+ assetId = coinQuantityLike.assetId;
48
46
  max2 = coinQuantityLike.max ?? void 0;
49
47
  }
50
48
  const bnAmount = bn(amount);
@@ -1162,7 +1160,7 @@ var outputify = (value) => {
1162
1160
  // src/providers/transaction-request/transaction-request.ts
1163
1161
  import { UTXO_ID_LEN as UTXO_ID_LEN2 } from "@fuel-ts/abi-coder";
1164
1162
  import { Address, addressify } from "@fuel-ts/address";
1165
- import { BaseAssetId as BaseAssetId2, ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
1163
+ import { ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
1166
1164
  import { randomBytes } from "@fuel-ts/crypto";
1167
1165
  import { bn as bn7 } from "@fuel-ts/math";
1168
1166
  import {
@@ -1623,6 +1621,8 @@ var BaseTransactionRequest = class {
1623
1621
  outputs = [];
1624
1622
  /** List of witnesses */
1625
1623
  witnesses = [];
1624
+ /** Base asset ID - should be fetched from the chain */
1625
+ baseAssetId;
1626
1626
  /**
1627
1627
  * Constructor for initializing a base transaction request.
1628
1628
  *
@@ -1635,8 +1635,9 @@ var BaseTransactionRequest = class {
1635
1635
  witnessLimit,
1636
1636
  inputs,
1637
1637
  outputs,
1638
- witnesses
1639
- } = {}) {
1638
+ witnesses,
1639
+ baseAssetId
1640
+ }) {
1640
1641
  this.gasPrice = bn7(gasPrice);
1641
1642
  this.maturity = maturity ?? 0;
1642
1643
  this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
@@ -1644,6 +1645,7 @@ var BaseTransactionRequest = class {
1644
1645
  this.inputs = inputs ?? [];
1645
1646
  this.outputs = outputs ?? [];
1646
1647
  this.witnesses = witnesses ?? [];
1648
+ this.baseAssetId = baseAssetId;
1647
1649
  }
1648
1650
  static getPolicyMeta(req) {
1649
1651
  let policyTypes = 0;
@@ -1867,11 +1869,9 @@ var BaseTransactionRequest = class {
1867
1869
  *
1868
1870
  * @param message - Message resource.
1869
1871
  * @param predicate - Predicate bytes.
1870
- * @param predicateData - Predicate data bytes.
1871
1872
  */
1872
1873
  addMessageInput(message, predicate) {
1873
1874
  const { recipient, sender, amount } = message;
1874
- const assetId = BaseAssetId2;
1875
1875
  let witnessIndex;
1876
1876
  if (predicate) {
1877
1877
  witnessIndex = 0;
@@ -1891,7 +1891,7 @@ var BaseTransactionRequest = class {
1891
1891
  predicate: predicate?.bytes
1892
1892
  };
1893
1893
  this.pushInput(input);
1894
- this.addChangeOutput(recipient, assetId);
1894
+ this.addChangeOutput(recipient, this.baseAssetId);
1895
1895
  }
1896
1896
  /**
1897
1897
  * Adds a single resource to the transaction by adding a coin/message input and a
@@ -1952,12 +1952,12 @@ var BaseTransactionRequest = class {
1952
1952
  * @param amount - Amount of coin.
1953
1953
  * @param assetId - Asset ID of coin.
1954
1954
  */
1955
- addCoinOutput(to, amount, assetId = BaseAssetId2) {
1955
+ addCoinOutput(to, amount, assetId) {
1956
1956
  this.pushOutput({
1957
1957
  type: OutputType2.Coin,
1958
1958
  to: addressify(to).toB256(),
1959
1959
  amount,
1960
- assetId
1960
+ assetId: assetId ?? this.baseAssetId
1961
1961
  });
1962
1962
  return this;
1963
1963
  }
@@ -1984,7 +1984,7 @@ var BaseTransactionRequest = class {
1984
1984
  * @param to - Address of the owner.
1985
1985
  * @param assetId - Asset ID of coin.
1986
1986
  */
1987
- addChangeOutput(to, assetId = BaseAssetId2) {
1987
+ addChangeOutput(to, assetId) {
1988
1988
  const changeOutput = this.getChangeOutputs().find(
1989
1989
  (output) => hexlify7(output.assetId) === assetId
1990
1990
  );
@@ -1992,7 +1992,7 @@ var BaseTransactionRequest = class {
1992
1992
  this.pushOutput({
1993
1993
  type: OutputType2.Change,
1994
1994
  to: addressify(to).toB256(),
1995
- assetId
1995
+ assetId: assetId ?? this.baseAssetId
1996
1996
  });
1997
1997
  }
1998
1998
  }
@@ -2068,7 +2068,7 @@ var BaseTransactionRequest = class {
2068
2068
  ]);
2069
2069
  }
2070
2070
  };
2071
- updateAssetInput(BaseAssetId2, bn7(1e11));
2071
+ updateAssetInput(this.baseAssetId, bn7(1e11));
2072
2072
  quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
2073
2073
  }
2074
2074
  /**
@@ -2238,12 +2238,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2238
2238
  *
2239
2239
  * @param createTransactionRequestLike - The initial values for the instance
2240
2240
  */
2241
- constructor({
2242
- bytecodeWitnessIndex,
2243
- salt,
2244
- storageSlots,
2245
- ...rest
2246
- } = {}) {
2241
+ constructor({ bytecodeWitnessIndex, salt, storageSlots, ...rest }) {
2247
2242
  super(rest);
2248
2243
  this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
2249
2244
  this.salt = hexlify9(salt ?? ZeroBytes326);
@@ -2367,7 +2362,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2367
2362
  *
2368
2363
  * @param scriptTransactionRequestLike - The initial values for the instance.
2369
2364
  */
2370
- constructor({ script, scriptData, gasLimit, ...rest } = {}) {
2365
+ constructor({ script, scriptData, gasLimit, ...rest }) {
2371
2366
  super(rest);
2372
2367
  this.gasLimit = bn10(gasLimit);
2373
2368
  this.script = arrayify8(script ?? returnZeroScript.bytes);
@@ -3495,6 +3490,7 @@ var processGqlChain = (chain) => {
3495
3490
  gasPerByte: bn15(feeParams.gasPerByte),
3496
3491
  maxMessageDataLength: bn15(predicateParams.maxMessageDataLength),
3497
3492
  chainId: bn15(consensusParameters.chainId),
3493
+ baseAssetId: consensusParameters.baseAssetId,
3498
3494
  gasCosts
3499
3495
  },
3500
3496
  gasCosts,
@@ -3737,6 +3733,17 @@ var _Provider = class {
3737
3733
  } = this.getChain();
3738
3734
  return chainId.toNumber();
3739
3735
  }
3736
+ /**
3737
+ * Returns the base asset ID
3738
+ *
3739
+ * @returns A promise that resolves to the base asset ID
3740
+ */
3741
+ getBaseAssetId() {
3742
+ const {
3743
+ consensusParameters: { baseAssetId }
3744
+ } = this.getChain();
3745
+ return baseAssetId;
3746
+ }
3740
3747
  /**
3741
3748
  * Submits a transaction to the chain to be executed.
3742
3749
  *
@@ -4634,8 +4641,9 @@ var Account = class extends AbstractAccount {
4634
4641
  * @param assetId - The asset ID to check the balance for.
4635
4642
  * @returns A promise that resolves to the balance amount.
4636
4643
  */
4637
- async getBalance(assetId = BaseAssetId3) {
4638
- const amount = await this.provider.getBalance(this.address, assetId);
4644
+ async getBalance(assetId) {
4645
+ const assetIdToFetch = assetId ?? this.provider.getBaseAssetId();
4646
+ const amount = await this.provider.getBalance(this.address, assetIdToFetch);
4639
4647
  return amount;
4640
4648
  }
4641
4649
  /**
@@ -4673,9 +4681,10 @@ var Account = class extends AbstractAccount {
4673
4681
  * @returns A promise that resolves when the resources are added to the transaction.
4674
4682
  */
4675
4683
  async fund(request, coinQuantities, fee) {
4684
+ const baseAssetId = this.provider.getBaseAssetId();
4676
4685
  const updatedQuantities = addAmountToAsset({
4677
4686
  amount: bn17(fee),
4678
- assetId: BaseAssetId3,
4687
+ assetId: baseAssetId,
4679
4688
  coinQuantities
4680
4689
  });
4681
4690
  const quantitiesDict = {};
@@ -4699,8 +4708,8 @@ var Account = class extends AbstractAccount {
4699
4708
  quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
4700
4709
  cachedUtxos.push(input.id);
4701
4710
  }
4702
- } else if (input.recipient === owner && input.amount && quantitiesDict[BaseAssetId3]) {
4703
- quantitiesDict[BaseAssetId3].owned = quantitiesDict[BaseAssetId3].owned.add(input.amount);
4711
+ } else if (input.recipient === owner && input.amount && quantitiesDict[baseAssetId]) {
4712
+ quantitiesDict[baseAssetId].owned = quantitiesDict[baseAssetId].owned.add(input.amount);
4704
4713
  cachedMessages.push(input.nonce);
4705
4714
  }
4706
4715
  }
@@ -4732,11 +4741,13 @@ var Account = class extends AbstractAccount {
4732
4741
  * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
4733
4742
  * @returns A promise that resolves to the prepared transaction request.
4734
4743
  */
4735
- async createTransfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
4744
+ async createTransfer(destination, amount, assetId, txParams = {}) {
4736
4745
  const { minGasPrice } = this.provider.getGasConfig();
4737
- const params = { gasPrice: minGasPrice, ...txParams };
4746
+ const baseAssetId = this.provider.getBaseAssetId();
4747
+ const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
4748
+ const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
4738
4749
  const request = new ScriptTransactionRequest(params);
4739
- request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetId);
4750
+ request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetIdToTransfer);
4740
4751
  const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
4741
4752
  estimateTxDependencies: true,
4742
4753
  resourcesOwner: this
@@ -4762,14 +4773,15 @@ var Account = class extends AbstractAccount {
4762
4773
  * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
4763
4774
  * @returns A promise that resolves to the transaction response.
4764
4775
  */
4765
- async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
4776
+ async transfer(destination, amount, assetId, txParams = {}) {
4766
4777
  if (bn17(amount).lte(0)) {
4767
4778
  throw new FuelError15(
4768
4779
  ErrorCode15.INVALID_TRANSFER_AMOUNT,
4769
4780
  "Transfer amount must be a positive number."
4770
4781
  );
4771
4782
  }
4772
- const request = await this.createTransfer(destination, amount, assetId, txParams);
4783
+ const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
4784
+ const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
4773
4785
  return this.sendTransaction(request, { estimateTxDependencies: false });
4774
4786
  }
4775
4787
  /**
@@ -4781,7 +4793,7 @@ var Account = class extends AbstractAccount {
4781
4793
  * @param txParams - The optional transaction parameters.
4782
4794
  * @returns A promise that resolves to the transaction response.
4783
4795
  */
4784
- async transferToContract(contractId, amount, assetId = BaseAssetId3, txParams = {}) {
4796
+ async transferToContract(contractId, amount, assetId, txParams = {}) {
4785
4797
  if (bn17(amount).lte(0)) {
4786
4798
  throw new FuelError15(
4787
4799
  ErrorCode15.INVALID_TRANSFER_AMOUNT,
@@ -4790,11 +4802,13 @@ var Account = class extends AbstractAccount {
4790
4802
  }
4791
4803
  const contractAddress = Address3.fromAddressOrString(contractId);
4792
4804
  const { minGasPrice } = this.provider.getGasConfig();
4793
- const params = { gasPrice: minGasPrice, ...txParams };
4805
+ const baseAssetId = this.provider.getBaseAssetId();
4806
+ const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
4807
+ const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
4794
4808
  const { script, scriptData } = await assembleTransferToContractScript({
4795
4809
  hexlifiedContractId: contractAddress.toB256(),
4796
4810
  amountToTransfer: bn17(amount),
4797
- assetId
4811
+ assetId: assetIdToTransfer
4798
4812
  });
4799
4813
  const request = new ScriptTransactionRequest({
4800
4814
  ...params,
@@ -4804,7 +4818,7 @@ var Account = class extends AbstractAccount {
4804
4818
  request.addContractInputAndOutput(contractAddress);
4805
4819
  const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
4806
4820
  request,
4807
- [{ amount: bn17(amount), assetId: String(assetId) }]
4821
+ [{ amount: bn17(amount), assetId: String(assetIdToTransfer) }]
4808
4822
  );
4809
4823
  request.gasLimit = bn17(params.gasLimit ?? gasUsed);
4810
4824
  this.validateGas({
@@ -4826,6 +4840,7 @@ var Account = class extends AbstractAccount {
4826
4840
  */
4827
4841
  async withdrawToBaseLayer(recipient, amount, txParams = {}) {
4828
4842
  const { minGasPrice } = this.provider.getGasConfig();
4843
+ const baseAssetId = this.provider.getBaseAssetId();
4829
4844
  const recipientAddress = Address3.fromAddressOrString(recipient);
4830
4845
  const recipientDataArray = arrayify14(
4831
4846
  "0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
@@ -4838,9 +4853,14 @@ var Account = class extends AbstractAccount {
4838
4853
  ...recipientDataArray,
4839
4854
  ...amountDataArray
4840
4855
  ]);
4841
- const params = { script, gasPrice: minGasPrice, ...txParams };
4856
+ const params = {
4857
+ script,
4858
+ gasPrice: minGasPrice,
4859
+ baseAssetId,
4860
+ ...txParams
4861
+ };
4842
4862
  const request = new ScriptTransactionRequest(params);
4843
- const forwardingQuantities = [{ amount: bn17(amount), assetId: BaseAssetId3 }];
4863
+ const forwardingQuantities = [{ amount: bn17(amount), assetId: baseAssetId }];
4844
4864
  const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
4845
4865
  request,
4846
4866
  forwardingQuantities
@@ -7993,7 +8013,9 @@ var seedTestWallet = async (wallet, quantities) => {
7993
8013
  );
7994
8014
  const resources = await genesisWallet.getResourcesToSpend(quantities);
7995
8015
  const { minGasPrice } = genesisWallet.provider.getGasConfig();
8016
+ const baseAssetId = genesisWallet.provider.getBaseAssetId();
7996
8017
  const request = new ScriptTransactionRequest({
8018
+ baseAssetId,
7997
8019
  gasLimit: 1e4,
7998
8020
  gasPrice: minGasPrice
7999
8021
  });
@@ -8012,7 +8034,7 @@ var generateTestWallet = async (provider, quantities) => {
8012
8034
  };
8013
8035
 
8014
8036
  // src/test-utils/launchNode.ts
8015
- import { BaseAssetId as BaseAssetId4 } from "@fuel-ts/address/configs";
8037
+ import { ZeroBytes32 as ZeroBytes329 } from "@fuel-ts/address/configs";
8016
8038
  import { toHex as toHex2 } from "@fuel-ts/math";
8017
8039
  import { defaultChainConfig, defaultConsensusKey, hexlify as hexlify18 } from "@fuel-ts/utils";
8018
8040
  import { findBinPath } from "@fuel-ts/utils/cli-utils";
@@ -8112,7 +8134,7 @@ var launchNode = async ({
8112
8134
  {
8113
8135
  owner: signer.address.toHexString(),
8114
8136
  amount: toHex2(1e9),
8115
- asset_id: BaseAssetId4
8137
+ asset_id: defaultChainConfig?.consensus_parameters?.base_asset_id ?? ZeroBytes329
8116
8138
  }
8117
8139
  ]
8118
8140
  }
@@ -8178,9 +8200,10 @@ var launchNode = async ({
8178
8200
  })
8179
8201
  );
8180
8202
  var generateWallets = async (count, provider) => {
8203
+ const baseAssetId = provider.getBaseAssetId();
8181
8204
  const wallets = [];
8182
8205
  for (let i = 0; i < count; i += 1) {
8183
- const wallet = await generateTestWallet(provider, [[1e3, BaseAssetId4]]);
8206
+ const wallet = await generateTestWallet(provider, [[1e3, baseAssetId]]);
8184
8207
  wallets.push(wallet);
8185
8208
  }
8186
8209
  return wallets;