@fuel-ts/account 0.0.0-rc-1976-20240415100843 → 0.0.0-rc-2045-20240415152456

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);
@@ -1151,7 +1153,7 @@ var outputify = (value) => {
1151
1153
  // src/providers/transaction-request/transaction-request.ts
1152
1154
  import { UTXO_ID_LEN as UTXO_ID_LEN2 } from "@fuel-ts/abi-coder";
1153
1155
  import { Address, addressify } from "@fuel-ts/address";
1154
- import { ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
1156
+ import { BaseAssetId as BaseAssetId2, ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
1155
1157
  import { randomBytes } from "@fuel-ts/crypto";
1156
1158
  import { bn as bn7 } from "@fuel-ts/math";
1157
1159
  import {
@@ -1612,8 +1614,6 @@ var BaseTransactionRequest = class {
1612
1614
  outputs = [];
1613
1615
  /** List of witnesses */
1614
1616
  witnesses = [];
1615
- /** Base asset ID - should be fetched from the chain */
1616
- baseAssetId;
1617
1617
  /**
1618
1618
  * Constructor for initializing a base transaction request.
1619
1619
  *
@@ -1626,9 +1626,8 @@ var BaseTransactionRequest = class {
1626
1626
  witnessLimit,
1627
1627
  inputs,
1628
1628
  outputs,
1629
- witnesses,
1630
- baseAssetId
1631
- }) {
1629
+ witnesses
1630
+ } = {}) {
1632
1631
  this.gasPrice = bn7(gasPrice);
1633
1632
  this.maturity = maturity ?? 0;
1634
1633
  this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
@@ -1636,7 +1635,6 @@ var BaseTransactionRequest = class {
1636
1635
  this.inputs = inputs ?? [];
1637
1636
  this.outputs = outputs ?? [];
1638
1637
  this.witnesses = witnesses ?? [];
1639
- this.baseAssetId = baseAssetId;
1640
1638
  }
1641
1639
  static getPolicyMeta(req) {
1642
1640
  let policyTypes = 0;
@@ -1860,9 +1858,11 @@ var BaseTransactionRequest = class {
1860
1858
  *
1861
1859
  * @param message - Message resource.
1862
1860
  * @param predicate - Predicate bytes.
1861
+ * @param predicateData - Predicate data bytes.
1863
1862
  */
1864
1863
  addMessageInput(message, predicate) {
1865
1864
  const { recipient, sender, amount } = message;
1865
+ const assetId = BaseAssetId2;
1866
1866
  let witnessIndex;
1867
1867
  if (predicate) {
1868
1868
  witnessIndex = 0;
@@ -1882,7 +1882,7 @@ var BaseTransactionRequest = class {
1882
1882
  predicate: predicate?.bytes
1883
1883
  };
1884
1884
  this.pushInput(input);
1885
- this.addChangeOutput(recipient, this.baseAssetId);
1885
+ this.addChangeOutput(recipient, assetId);
1886
1886
  }
1887
1887
  /**
1888
1888
  * Adds a single resource to the transaction by adding a coin/message input and a
@@ -1943,12 +1943,12 @@ var BaseTransactionRequest = class {
1943
1943
  * @param amount - Amount of coin.
1944
1944
  * @param assetId - Asset ID of coin.
1945
1945
  */
1946
- addCoinOutput(to, amount, assetId) {
1946
+ addCoinOutput(to, amount, assetId = BaseAssetId2) {
1947
1947
  this.pushOutput({
1948
1948
  type: OutputType2.Coin,
1949
1949
  to: addressify(to).toB256(),
1950
1950
  amount,
1951
- assetId: assetId ?? this.baseAssetId
1951
+ assetId
1952
1952
  });
1953
1953
  return this;
1954
1954
  }
@@ -1975,7 +1975,7 @@ var BaseTransactionRequest = class {
1975
1975
  * @param to - Address of the owner.
1976
1976
  * @param assetId - Asset ID of coin.
1977
1977
  */
1978
- addChangeOutput(to, assetId) {
1978
+ addChangeOutput(to, assetId = BaseAssetId2) {
1979
1979
  const changeOutput = this.getChangeOutputs().find(
1980
1980
  (output) => hexlify7(output.assetId) === assetId
1981
1981
  );
@@ -1983,7 +1983,7 @@ var BaseTransactionRequest = class {
1983
1983
  this.pushOutput({
1984
1984
  type: OutputType2.Change,
1985
1985
  to: addressify(to).toB256(),
1986
- assetId: assetId ?? this.baseAssetId
1986
+ assetId
1987
1987
  });
1988
1988
  }
1989
1989
  }
@@ -2059,7 +2059,7 @@ var BaseTransactionRequest = class {
2059
2059
  ]);
2060
2060
  }
2061
2061
  };
2062
- updateAssetInput(this.baseAssetId, bn7(1e11));
2062
+ updateAssetInput(BaseAssetId2, bn7(1e11));
2063
2063
  quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
2064
2064
  }
2065
2065
  /**
@@ -2229,7 +2229,12 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2229
2229
  *
2230
2230
  * @param createTransactionRequestLike - The initial values for the instance
2231
2231
  */
2232
- constructor({ bytecodeWitnessIndex, salt, storageSlots, ...rest }) {
2232
+ constructor({
2233
+ bytecodeWitnessIndex,
2234
+ salt,
2235
+ storageSlots,
2236
+ ...rest
2237
+ } = {}) {
2233
2238
  super(rest);
2234
2239
  this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
2235
2240
  this.salt = hexlify9(salt ?? ZeroBytes326);
@@ -2353,7 +2358,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2353
2358
  *
2354
2359
  * @param scriptTransactionRequestLike - The initial values for the instance.
2355
2360
  */
2356
- constructor({ script, scriptData, gasLimit, ...rest }) {
2361
+ constructor({ script, scriptData, gasLimit, ...rest } = {}) {
2357
2362
  super(rest);
2358
2363
  this.gasLimit = bn10(gasLimit);
2359
2364
  this.script = arrayify8(script ?? returnZeroScript.bytes);
@@ -3481,7 +3486,6 @@ var processGqlChain = (chain) => {
3481
3486
  gasPerByte: bn15(feeParams.gasPerByte),
3482
3487
  maxMessageDataLength: bn15(predicateParams.maxMessageDataLength),
3483
3488
  chainId: bn15(consensusParameters.chainId),
3484
- baseAssetId: consensusParameters.baseAssetId,
3485
3489
  gasCosts
3486
3490
  },
3487
3491
  gasCosts,
@@ -3724,17 +3728,6 @@ var _Provider = class {
3724
3728
  } = this.getChain();
3725
3729
  return chainId.toNumber();
3726
3730
  }
3727
- /**
3728
- * Returns the base asset ID
3729
- *
3730
- * @returns A promise that resolves to the base asset ID
3731
- */
3732
- getBaseAssetId() {
3733
- const {
3734
- consensusParameters: { baseAssetId }
3735
- } = this.getChain();
3736
- return baseAssetId;
3737
- }
3738
3731
  /**
3739
3732
  * Submits a transaction to the chain to be executed.
3740
3733
  *
@@ -4632,9 +4625,8 @@ var Account = class extends AbstractAccount {
4632
4625
  * @param assetId - The asset ID to check the balance for.
4633
4626
  * @returns A promise that resolves to the balance amount.
4634
4627
  */
4635
- async getBalance(assetId) {
4636
- const assetIdToFetch = assetId ?? this.provider.getBaseAssetId();
4637
- const amount = await this.provider.getBalance(this.address, assetIdToFetch);
4628
+ async getBalance(assetId = BaseAssetId3) {
4629
+ const amount = await this.provider.getBalance(this.address, assetId);
4638
4630
  return amount;
4639
4631
  }
4640
4632
  /**
@@ -4672,10 +4664,9 @@ var Account = class extends AbstractAccount {
4672
4664
  * @returns A promise that resolves when the resources are added to the transaction.
4673
4665
  */
4674
4666
  async fund(request, coinQuantities, fee) {
4675
- const baseAssetId = this.provider.getBaseAssetId();
4676
4667
  const updatedQuantities = addAmountToAsset({
4677
4668
  amount: bn17(fee),
4678
- assetId: baseAssetId,
4669
+ assetId: BaseAssetId3,
4679
4670
  coinQuantities
4680
4671
  });
4681
4672
  const quantitiesDict = {};
@@ -4699,8 +4690,8 @@ var Account = class extends AbstractAccount {
4699
4690
  quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
4700
4691
  cachedUtxos.push(input.id);
4701
4692
  }
4702
- } else if (input.recipient === owner && input.amount && quantitiesDict[baseAssetId]) {
4703
- quantitiesDict[baseAssetId].owned = quantitiesDict[baseAssetId].owned.add(input.amount);
4693
+ } else if (input.recipient === owner && input.amount && quantitiesDict[BaseAssetId3]) {
4694
+ quantitiesDict[BaseAssetId3].owned = quantitiesDict[BaseAssetId3].owned.add(input.amount);
4704
4695
  cachedMessages.push(input.nonce);
4705
4696
  }
4706
4697
  }
@@ -4732,13 +4723,11 @@ var Account = class extends AbstractAccount {
4732
4723
  * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
4733
4724
  * @returns A promise that resolves to the prepared transaction request.
4734
4725
  */
4735
- async createTransfer(destination, amount, assetId, txParams = {}) {
4726
+ async createTransfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
4736
4727
  const { minGasPrice } = this.provider.getGasConfig();
4737
- const baseAssetId = this.provider.getBaseAssetId();
4738
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
4739
- const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
4728
+ const params = { gasPrice: minGasPrice, ...txParams };
4740
4729
  const request = new ScriptTransactionRequest(params);
4741
- request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetIdToTransfer);
4730
+ request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetId);
4742
4731
  const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
4743
4732
  estimateTxDependencies: true,
4744
4733
  resourcesOwner: this
@@ -4764,15 +4753,14 @@ var Account = class extends AbstractAccount {
4764
4753
  * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
4765
4754
  * @returns A promise that resolves to the transaction response.
4766
4755
  */
4767
- async transfer(destination, amount, assetId, txParams = {}) {
4756
+ async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
4768
4757
  if (bn17(amount).lte(0)) {
4769
4758
  throw new FuelError15(
4770
4759
  ErrorCode15.INVALID_TRANSFER_AMOUNT,
4771
4760
  "Transfer amount must be a positive number."
4772
4761
  );
4773
4762
  }
4774
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
4775
- const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
4763
+ const request = await this.createTransfer(destination, amount, assetId, txParams);
4776
4764
  return this.sendTransaction(request, { estimateTxDependencies: false });
4777
4765
  }
4778
4766
  /**
@@ -4784,7 +4772,7 @@ var Account = class extends AbstractAccount {
4784
4772
  * @param txParams - The optional transaction parameters.
4785
4773
  * @returns A promise that resolves to the transaction response.
4786
4774
  */
4787
- async transferToContract(contractId, amount, assetId, txParams = {}) {
4775
+ async transferToContract(contractId, amount, assetId = BaseAssetId3, txParams = {}) {
4788
4776
  if (bn17(amount).lte(0)) {
4789
4777
  throw new FuelError15(
4790
4778
  ErrorCode15.INVALID_TRANSFER_AMOUNT,
@@ -4793,13 +4781,11 @@ var Account = class extends AbstractAccount {
4793
4781
  }
4794
4782
  const contractAddress = Address3.fromAddressOrString(contractId);
4795
4783
  const { minGasPrice } = this.provider.getGasConfig();
4796
- const baseAssetId = this.provider.getBaseAssetId();
4797
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
4798
- const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
4784
+ const params = { gasPrice: minGasPrice, ...txParams };
4799
4785
  const { script, scriptData } = await assembleTransferToContractScript({
4800
4786
  hexlifiedContractId: contractAddress.toB256(),
4801
4787
  amountToTransfer: bn17(amount),
4802
- assetId: assetIdToTransfer
4788
+ assetId
4803
4789
  });
4804
4790
  const request = new ScriptTransactionRequest({
4805
4791
  ...params,
@@ -4809,7 +4795,7 @@ var Account = class extends AbstractAccount {
4809
4795
  request.addContractInputAndOutput(contractAddress);
4810
4796
  const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
4811
4797
  request,
4812
- [{ amount: bn17(amount), assetId: String(assetIdToTransfer) }]
4798
+ [{ amount: bn17(amount), assetId: String(assetId) }]
4813
4799
  );
4814
4800
  request.gasLimit = bn17(params.gasLimit ?? gasUsed);
4815
4801
  this.validateGas({
@@ -4831,7 +4817,6 @@ var Account = class extends AbstractAccount {
4831
4817
  */
4832
4818
  async withdrawToBaseLayer(recipient, amount, txParams = {}) {
4833
4819
  const { minGasPrice } = this.provider.getGasConfig();
4834
- const baseAssetId = this.provider.getBaseAssetId();
4835
4820
  const recipientAddress = Address3.fromAddressOrString(recipient);
4836
4821
  const recipientDataArray = arrayify14(
4837
4822
  "0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
@@ -4844,14 +4829,9 @@ var Account = class extends AbstractAccount {
4844
4829
  ...recipientDataArray,
4845
4830
  ...amountDataArray
4846
4831
  ]);
4847
- const params = {
4848
- script,
4849
- gasPrice: minGasPrice,
4850
- baseAssetId,
4851
- ...txParams
4852
- };
4832
+ const params = { script, gasPrice: minGasPrice, ...txParams };
4853
4833
  const request = new ScriptTransactionRequest(params);
4854
- const forwardingQuantities = [{ amount: bn17(amount), assetId: baseAssetId }];
4834
+ const forwardingQuantities = [{ amount: bn17(amount), assetId: BaseAssetId3 }];
4855
4835
  const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
4856
4836
  request,
4857
4837
  forwardingQuantities
@@ -8004,9 +7984,7 @@ var seedTestWallet = async (wallet, quantities) => {
8004
7984
  );
8005
7985
  const resources = await genesisWallet.getResourcesToSpend(quantities);
8006
7986
  const { minGasPrice } = genesisWallet.provider.getGasConfig();
8007
- const baseAssetId = genesisWallet.provider.getBaseAssetId();
8008
7987
  const request = new ScriptTransactionRequest({
8009
- baseAssetId,
8010
7988
  gasLimit: 1e4,
8011
7989
  gasPrice: minGasPrice
8012
7990
  });
@@ -8025,7 +8003,7 @@ var generateTestWallet = async (provider, quantities) => {
8025
8003
  };
8026
8004
 
8027
8005
  // src/test-utils/launchNode.ts
8028
- import { ZeroBytes32 as ZeroBytes329 } from "@fuel-ts/address/configs";
8006
+ import { BaseAssetId as BaseAssetId4 } from "@fuel-ts/address/configs";
8029
8007
  import { toHex as toHex2 } from "@fuel-ts/math";
8030
8008
  import { defaultChainConfig, defaultConsensusKey, hexlify as hexlify18 } from "@fuel-ts/utils";
8031
8009
  import { findBinPath } from "@fuel-ts/utils/cli-utils";
@@ -8125,7 +8103,7 @@ var launchNode = async ({
8125
8103
  {
8126
8104
  owner: signer.address.toHexString(),
8127
8105
  amount: toHex2(1e9),
8128
- asset_id: defaultChainConfig?.consensus_parameters?.base_asset_id ?? ZeroBytes329
8106
+ asset_id: BaseAssetId4
8129
8107
  }
8130
8108
  ]
8131
8109
  }
@@ -8191,10 +8169,9 @@ var launchNode = async ({
8191
8169
  })
8192
8170
  );
8193
8171
  var generateWallets = async (count, provider) => {
8194
- const baseAssetId = provider.getBaseAssetId();
8195
8172
  const wallets = [];
8196
8173
  for (let i = 0; i < count; i += 1) {
8197
- const wallet = await generateTestWallet(provider, [[1e3, baseAssetId]]);
8174
+ const wallet = await generateTestWallet(provider, [[1e3, BaseAssetId4]]);
8198
8175
  wallets.push(wallet);
8199
8176
  }
8200
8177
  return wallets;