@fuel-ts/account 0.0.0-rc-1976-20240404063407 → 0.0.0-rc-1832-20240404064601

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 ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
28
29
  import { AbstractAccount } from "@fuel-ts/interfaces";
29
30
  import { bn as bn16 } 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);
@@ -1149,7 +1151,7 @@ var outputify = (value) => {
1149
1151
 
1150
1152
  // src/providers/transaction-request/transaction-request.ts
1151
1153
  import { Address, addressify } from "@fuel-ts/address";
1152
- import { ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
1154
+ import { BaseAssetId as BaseAssetId2, ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
1153
1155
  import { bn as bn6 } from "@fuel-ts/math";
1154
1156
  import {
1155
1157
  PolicyType,
@@ -1529,8 +1531,6 @@ var BaseTransactionRequest = class {
1529
1531
  outputs = [];
1530
1532
  /** List of witnesses */
1531
1533
  witnesses = [];
1532
- /** Base asset ID - should be fetched from the chain */
1533
- baseAssetId = ZeroBytes324;
1534
1534
  /**
1535
1535
  * Constructor for initializing a base transaction request.
1536
1536
  *
@@ -1543,8 +1543,7 @@ var BaseTransactionRequest = class {
1543
1543
  witnessLimit,
1544
1544
  inputs,
1545
1545
  outputs,
1546
- witnesses,
1547
- baseAssetId
1546
+ witnesses
1548
1547
  } = {}) {
1549
1548
  this.gasPrice = bn6(gasPrice);
1550
1549
  this.maturity = maturity ?? 0;
@@ -1553,7 +1552,6 @@ var BaseTransactionRequest = class {
1553
1552
  this.inputs = inputs ?? [];
1554
1553
  this.outputs = outputs ?? [];
1555
1554
  this.witnesses = witnesses ?? [];
1556
- this.baseAssetId = baseAssetId ?? ZeroBytes324;
1557
1555
  }
1558
1556
  static getPolicyMeta(req) {
1559
1557
  let policyTypes = 0;
@@ -1778,9 +1776,11 @@ var BaseTransactionRequest = class {
1778
1776
  *
1779
1777
  * @param message - Message resource.
1780
1778
  * @param predicate - Predicate bytes.
1779
+ * @param predicateData - Predicate data bytes.
1781
1780
  */
1782
1781
  addMessageInput(message, predicate) {
1783
1782
  const { recipient, sender, amount } = message;
1783
+ const assetId = BaseAssetId2;
1784
1784
  let witnessIndex;
1785
1785
  if (predicate) {
1786
1786
  witnessIndex = 0;
@@ -1801,7 +1801,7 @@ var BaseTransactionRequest = class {
1801
1801
  predicateData: predicate?.predicateDataBytes
1802
1802
  };
1803
1803
  this.pushInput(input);
1804
- this.addChangeOutput(recipient, this.baseAssetId);
1804
+ this.addChangeOutput(recipient, assetId);
1805
1805
  }
1806
1806
  /**
1807
1807
  * Adds a single resource to the transaction by adding a coin/message input and a
@@ -1862,12 +1862,12 @@ var BaseTransactionRequest = class {
1862
1862
  * @param amount - Amount of coin.
1863
1863
  * @param assetId - Asset ID of coin.
1864
1864
  */
1865
- addCoinOutput(to, amount, assetId) {
1865
+ addCoinOutput(to, amount, assetId = BaseAssetId2) {
1866
1866
  this.pushOutput({
1867
1867
  type: OutputType2.Coin,
1868
1868
  to: addressify(to).toB256(),
1869
1869
  amount,
1870
- assetId: assetId ?? this.baseAssetId
1870
+ assetId
1871
1871
  });
1872
1872
  return this;
1873
1873
  }
@@ -1894,7 +1894,7 @@ var BaseTransactionRequest = class {
1894
1894
  * @param to - Address of the owner.
1895
1895
  * @param assetId - Asset ID of coin.
1896
1896
  */
1897
- addChangeOutput(to, assetId) {
1897
+ addChangeOutput(to, assetId = BaseAssetId2) {
1898
1898
  const changeOutput = this.getChangeOutputs().find(
1899
1899
  (output) => hexlify7(output.assetId) === assetId
1900
1900
  );
@@ -1902,7 +1902,7 @@ var BaseTransactionRequest = class {
1902
1902
  this.pushOutput({
1903
1903
  type: OutputType2.Change,
1904
1904
  to: addressify(to).toB256(),
1905
- assetId: assetId ?? this.baseAssetId
1905
+ assetId
1906
1906
  });
1907
1907
  }
1908
1908
  }
@@ -1984,7 +1984,7 @@ var BaseTransactionRequest = class {
1984
1984
  ]);
1985
1985
  }
1986
1986
  };
1987
- updateAssetInput(this.baseAssetId, bn6(1e11));
1987
+ updateAssetInput(BaseAssetId2, bn6(1e11));
1988
1988
  quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
1989
1989
  }
1990
1990
  /**
@@ -3406,7 +3406,6 @@ var processGqlChain = (chain) => {
3406
3406
  gasPerByte: bn14(feeParams.gasPerByte),
3407
3407
  maxMessageDataLength: bn14(predicateParams.maxMessageDataLength),
3408
3408
  chainId: bn14(consensusParameters.chainId),
3409
- baseAssetId: consensusParameters.baseAssetId,
3410
3409
  gasCosts
3411
3410
  },
3412
3411
  gasCosts,
@@ -3649,17 +3648,6 @@ var _Provider = class {
3649
3648
  } = this.getChain();
3650
3649
  return chainId.toNumber();
3651
3650
  }
3652
- /**
3653
- * Returns the base asset ID
3654
- *
3655
- * @returns A promise that resolves to the base asset ID
3656
- */
3657
- getBaseAssetId() {
3658
- const {
3659
- consensusParameters: { baseAssetId }
3660
- } = this.getChain();
3661
- return baseAssetId;
3662
- }
3663
3651
  /**
3664
3652
  * Submits a transaction to the chain to be executed.
3665
3653
  *
@@ -4530,9 +4518,8 @@ var Account = class extends AbstractAccount {
4530
4518
  * @param assetId - The asset ID to check the balance for.
4531
4519
  * @returns A promise that resolves to the balance amount.
4532
4520
  */
4533
- async getBalance(assetId) {
4534
- const assetIdToFetch = assetId ?? this.provider.getBaseAssetId();
4535
- const amount = await this.provider.getBalance(this.address, assetIdToFetch);
4521
+ async getBalance(assetId = BaseAssetId3) {
4522
+ const amount = await this.provider.getBalance(this.address, assetId);
4536
4523
  return amount;
4537
4524
  }
4538
4525
  /**
@@ -4570,10 +4557,9 @@ var Account = class extends AbstractAccount {
4570
4557
  * @returns A promise that resolves when the resources are added to the transaction.
4571
4558
  */
4572
4559
  async fund(request, coinQuantities, fee) {
4573
- const baseAssetId = this.provider.getBaseAssetId();
4574
4560
  const updatedQuantities = addAmountToAsset({
4575
4561
  amount: bn16(fee),
4576
- assetId: baseAssetId,
4562
+ assetId: BaseAssetId3,
4577
4563
  coinQuantities
4578
4564
  });
4579
4565
  const quantitiesDict = {};
@@ -4597,8 +4583,8 @@ var Account = class extends AbstractAccount {
4597
4583
  quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
4598
4584
  cachedUtxos.push(input.id);
4599
4585
  }
4600
- } else if (input.recipient === owner && input.amount && quantitiesDict[baseAssetId]) {
4601
- quantitiesDict[baseAssetId].owned = quantitiesDict[baseAssetId].owned.add(input.amount);
4586
+ } else if (input.recipient === owner && input.amount && quantitiesDict[BaseAssetId3]) {
4587
+ quantitiesDict[BaseAssetId3].owned = quantitiesDict[BaseAssetId3].owned.add(input.amount);
4602
4588
  cachedMessages.push(input.nonce);
4603
4589
  }
4604
4590
  }
@@ -4630,12 +4616,11 @@ var Account = class extends AbstractAccount {
4630
4616
  * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
4631
4617
  * @returns A promise that resolves to the prepared transaction request.
4632
4618
  */
4633
- async createTransfer(destination, amount, assetId, txParams = {}) {
4619
+ async createTransfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
4634
4620
  const { minGasPrice } = this.provider.getGasConfig();
4635
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
4636
4621
  const params = { gasPrice: minGasPrice, ...txParams };
4637
4622
  const request = new ScriptTransactionRequest(params);
4638
- request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetIdToTransfer);
4623
+ request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetId);
4639
4624
  const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
4640
4625
  estimateTxDependencies: true,
4641
4626
  resourcesOwner: this
@@ -4661,15 +4646,14 @@ var Account = class extends AbstractAccount {
4661
4646
  * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
4662
4647
  * @returns A promise that resolves to the transaction response.
4663
4648
  */
4664
- async transfer(destination, amount, assetId, txParams = {}) {
4649
+ async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
4665
4650
  if (bn16(amount).lte(0)) {
4666
4651
  throw new FuelError14(
4667
4652
  ErrorCode14.INVALID_TRANSFER_AMOUNT,
4668
4653
  "Transfer amount must be a positive number."
4669
4654
  );
4670
4655
  }
4671
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
4672
- const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
4656
+ const request = await this.createTransfer(destination, amount, assetId, txParams);
4673
4657
  return this.sendTransaction(request, { estimateTxDependencies: false });
4674
4658
  }
4675
4659
  /**
@@ -4681,7 +4665,7 @@ var Account = class extends AbstractAccount {
4681
4665
  * @param txParams - The optional transaction parameters.
4682
4666
  * @returns A promise that resolves to the transaction response.
4683
4667
  */
4684
- async transferToContract(contractId, amount, assetId, txParams = {}) {
4668
+ async transferToContract(contractId, amount, assetId = BaseAssetId3, txParams = {}) {
4685
4669
  if (bn16(amount).lte(0)) {
4686
4670
  throw new FuelError14(
4687
4671
  ErrorCode14.INVALID_TRANSFER_AMOUNT,
@@ -4690,12 +4674,11 @@ var Account = class extends AbstractAccount {
4690
4674
  }
4691
4675
  const contractAddress = Address3.fromAddressOrString(contractId);
4692
4676
  const { minGasPrice } = this.provider.getGasConfig();
4693
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
4694
4677
  const params = { gasPrice: minGasPrice, ...txParams };
4695
4678
  const { script, scriptData } = await assembleTransferToContractScript({
4696
4679
  hexlifiedContractId: contractAddress.toB256(),
4697
4680
  amountToTransfer: bn16(amount),
4698
- assetId: assetIdToTransfer
4681
+ assetId
4699
4682
  });
4700
4683
  const request = new ScriptTransactionRequest({
4701
4684
  ...params,
@@ -4705,7 +4688,7 @@ var Account = class extends AbstractAccount {
4705
4688
  request.addContractInputAndOutput(contractAddress);
4706
4689
  const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
4707
4690
  request,
4708
- [{ amount: bn16(amount), assetId: String(assetIdToTransfer) }]
4691
+ [{ amount: bn16(amount), assetId: String(assetId) }]
4709
4692
  );
4710
4693
  request.gasLimit = bn16(params.gasLimit ?? gasUsed);
4711
4694
  this.validateGas({
@@ -4727,7 +4710,6 @@ var Account = class extends AbstractAccount {
4727
4710
  */
4728
4711
  async withdrawToBaseLayer(recipient, amount, txParams = {}) {
4729
4712
  const { minGasPrice } = this.provider.getGasConfig();
4730
- const baseAssetId = this.provider.getBaseAssetId();
4731
4713
  const recipientAddress = Address3.fromAddressOrString(recipient);
4732
4714
  const recipientDataArray = arrayify14(
4733
4715
  "0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
@@ -4742,7 +4724,7 @@ var Account = class extends AbstractAccount {
4742
4724
  ]);
4743
4725
  const params = { script, gasPrice: minGasPrice, ...txParams };
4744
4726
  const request = new ScriptTransactionRequest(params);
4745
- const forwardingQuantities = [{ amount: bn16(amount), assetId: baseAssetId }];
4727
+ const forwardingQuantities = [{ amount: bn16(amount), assetId: BaseAssetId3 }];
4746
4728
  const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
4747
4729
  request,
4748
4730
  forwardingQuantities
@@ -7914,7 +7896,7 @@ var generateTestWallet = async (provider, quantities) => {
7914
7896
  };
7915
7897
 
7916
7898
  // src/test-utils/launchNode.ts
7917
- import { ZeroBytes32 as ZeroBytes329 } from "@fuel-ts/address/configs";
7899
+ import { BaseAssetId as BaseAssetId4 } from "@fuel-ts/address/configs";
7918
7900
  import { toHex as toHex2 } from "@fuel-ts/math";
7919
7901
  import { defaultChainConfig, defaultConsensusKey, hexlify as hexlify18 } from "@fuel-ts/utils";
7920
7902
  import { findBinPath } from "@fuel-ts/utils/cli-utils";
@@ -8014,7 +7996,7 @@ var launchNode = async ({
8014
7996
  {
8015
7997
  owner: signer.address.toHexString(),
8016
7998
  amount: toHex2(1e9),
8017
- asset_id: defaultChainConfig?.consensus_parameters?.base_asset_id ?? ZeroBytes329
7999
+ asset_id: BaseAssetId4
8018
8000
  }
8019
8001
  ]
8020
8002
  }
@@ -8080,10 +8062,9 @@ var launchNode = async ({
8080
8062
  })
8081
8063
  );
8082
8064
  var generateWallets = async (count, provider) => {
8083
- const baseAssetId = provider.getBaseAssetId();
8084
8065
  const wallets = [];
8085
8066
  for (let i = 0; i < count; i += 1) {
8086
- const wallet = await generateTestWallet(provider, [[1e3, baseAssetId]]);
8067
+ const wallet = await generateTestWallet(provider, [[1e3, BaseAssetId4]]);
8087
8068
  wallets.push(wallet);
8088
8069
  }
8089
8070
  return wallets;