@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.

package/dist/index.mjs CHANGED
@@ -29,12 +29,14 @@ var __privateMethod = (obj, member, method) => {
29
29
 
30
30
  // src/account.ts
31
31
  import { Address as Address3 } from "@fuel-ts/address";
32
+ import { BaseAssetId as BaseAssetId3 } from "@fuel-ts/address/configs";
32
33
  import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
33
34
  import { AbstractAccount } from "@fuel-ts/interfaces";
34
35
  import { bn as bn16 } from "@fuel-ts/math";
35
36
  import { arrayify as arrayify14 } from "@fuel-ts/utils";
36
37
 
37
38
  // src/providers/coin-quantity.ts
39
+ import { BaseAssetId } from "@fuel-ts/address/configs";
38
40
  import { bn } from "@fuel-ts/math";
39
41
  import { hexlify } from "@fuel-ts/utils";
40
42
  var coinQuantityfy = (coinQuantityLike) => {
@@ -43,11 +45,11 @@ var coinQuantityfy = (coinQuantityLike) => {
43
45
  let max2;
44
46
  if (Array.isArray(coinQuantityLike)) {
45
47
  amount = coinQuantityLike[0];
46
- assetId = coinQuantityLike[1];
47
- max2 = coinQuantityLike[2];
48
+ assetId = coinQuantityLike[1] ?? BaseAssetId;
49
+ max2 = coinQuantityLike[2] ?? void 0;
48
50
  } else {
49
51
  amount = coinQuantityLike.amount;
50
- assetId = coinQuantityLike.assetId;
52
+ assetId = coinQuantityLike.assetId ?? BaseAssetId;
51
53
  max2 = coinQuantityLike.max ?? void 0;
52
54
  }
53
55
  const bnAmount = bn(amount);
@@ -1154,7 +1156,7 @@ var outputify = (value) => {
1154
1156
 
1155
1157
  // src/providers/transaction-request/transaction-request.ts
1156
1158
  import { Address, addressify } from "@fuel-ts/address";
1157
- import { ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
1159
+ import { BaseAssetId as BaseAssetId2, ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
1158
1160
  import { bn as bn6 } from "@fuel-ts/math";
1159
1161
  import {
1160
1162
  PolicyType,
@@ -1608,8 +1610,6 @@ var BaseTransactionRequest = class {
1608
1610
  outputs = [];
1609
1611
  /** List of witnesses */
1610
1612
  witnesses = [];
1611
- /** Base asset ID - should be fetched from the chain */
1612
- baseAssetId = ZeroBytes324;
1613
1613
  /**
1614
1614
  * Constructor for initializing a base transaction request.
1615
1615
  *
@@ -1622,8 +1622,7 @@ var BaseTransactionRequest = class {
1622
1622
  witnessLimit,
1623
1623
  inputs,
1624
1624
  outputs,
1625
- witnesses,
1626
- baseAssetId
1625
+ witnesses
1627
1626
  } = {}) {
1628
1627
  this.gasPrice = bn6(gasPrice);
1629
1628
  this.maturity = maturity ?? 0;
@@ -1632,7 +1631,6 @@ var BaseTransactionRequest = class {
1632
1631
  this.inputs = inputs ?? [];
1633
1632
  this.outputs = outputs ?? [];
1634
1633
  this.witnesses = witnesses ?? [];
1635
- this.baseAssetId = baseAssetId ?? ZeroBytes324;
1636
1634
  }
1637
1635
  static getPolicyMeta(req) {
1638
1636
  let policyTypes = 0;
@@ -1857,9 +1855,11 @@ var BaseTransactionRequest = class {
1857
1855
  *
1858
1856
  * @param message - Message resource.
1859
1857
  * @param predicate - Predicate bytes.
1858
+ * @param predicateData - Predicate data bytes.
1860
1859
  */
1861
1860
  addMessageInput(message, predicate) {
1862
1861
  const { recipient, sender, amount } = message;
1862
+ const assetId = BaseAssetId2;
1863
1863
  let witnessIndex;
1864
1864
  if (predicate) {
1865
1865
  witnessIndex = 0;
@@ -1880,7 +1880,7 @@ var BaseTransactionRequest = class {
1880
1880
  predicateData: predicate?.predicateDataBytes
1881
1881
  };
1882
1882
  this.pushInput(input);
1883
- this.addChangeOutput(recipient, this.baseAssetId);
1883
+ this.addChangeOutput(recipient, assetId);
1884
1884
  }
1885
1885
  /**
1886
1886
  * Adds a single resource to the transaction by adding a coin/message input and a
@@ -1941,12 +1941,12 @@ var BaseTransactionRequest = class {
1941
1941
  * @param amount - Amount of coin.
1942
1942
  * @param assetId - Asset ID of coin.
1943
1943
  */
1944
- addCoinOutput(to, amount, assetId) {
1944
+ addCoinOutput(to, amount, assetId = BaseAssetId2) {
1945
1945
  this.pushOutput({
1946
1946
  type: OutputType2.Coin,
1947
1947
  to: addressify(to).toB256(),
1948
1948
  amount,
1949
- assetId: assetId ?? this.baseAssetId
1949
+ assetId
1950
1950
  });
1951
1951
  return this;
1952
1952
  }
@@ -1973,7 +1973,7 @@ var BaseTransactionRequest = class {
1973
1973
  * @param to - Address of the owner.
1974
1974
  * @param assetId - Asset ID of coin.
1975
1975
  */
1976
- addChangeOutput(to, assetId) {
1976
+ addChangeOutput(to, assetId = BaseAssetId2) {
1977
1977
  const changeOutput = this.getChangeOutputs().find(
1978
1978
  (output) => hexlify7(output.assetId) === assetId
1979
1979
  );
@@ -1981,7 +1981,7 @@ var BaseTransactionRequest = class {
1981
1981
  this.pushOutput({
1982
1982
  type: OutputType2.Change,
1983
1983
  to: addressify(to).toB256(),
1984
- assetId: assetId ?? this.baseAssetId
1984
+ assetId
1985
1985
  });
1986
1986
  }
1987
1987
  }
@@ -2063,7 +2063,7 @@ var BaseTransactionRequest = class {
2063
2063
  ]);
2064
2064
  }
2065
2065
  };
2066
- updateAssetInput(this.baseAssetId, bn6(1e11));
2066
+ updateAssetInput(BaseAssetId2, bn6(1e11));
2067
2067
  quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
2068
2068
  }
2069
2069
  /**
@@ -3532,7 +3532,6 @@ var processGqlChain = (chain) => {
3532
3532
  gasPerByte: bn14(feeParams.gasPerByte),
3533
3533
  maxMessageDataLength: bn14(predicateParams.maxMessageDataLength),
3534
3534
  chainId: bn14(consensusParameters.chainId),
3535
- baseAssetId: consensusParameters.baseAssetId,
3536
3535
  gasCosts
3537
3536
  },
3538
3537
  gasCosts,
@@ -3775,17 +3774,6 @@ var _Provider = class {
3775
3774
  } = this.getChain();
3776
3775
  return chainId.toNumber();
3777
3776
  }
3778
- /**
3779
- * Returns the base asset ID
3780
- *
3781
- * @returns A promise that resolves to the base asset ID
3782
- */
3783
- getBaseAssetId() {
3784
- const {
3785
- consensusParameters: { baseAssetId }
3786
- } = this.getChain();
3787
- return baseAssetId;
3788
- }
3789
3777
  /**
3790
3778
  * Submits a transaction to the chain to be executed.
3791
3779
  *
@@ -4822,9 +4810,8 @@ var Account = class extends AbstractAccount {
4822
4810
  * @param assetId - The asset ID to check the balance for.
4823
4811
  * @returns A promise that resolves to the balance amount.
4824
4812
  */
4825
- async getBalance(assetId) {
4826
- const assetIdToFetch = assetId ?? this.provider.getBaseAssetId();
4827
- const amount = await this.provider.getBalance(this.address, assetIdToFetch);
4813
+ async getBalance(assetId = BaseAssetId3) {
4814
+ const amount = await this.provider.getBalance(this.address, assetId);
4828
4815
  return amount;
4829
4816
  }
4830
4817
  /**
@@ -4862,10 +4849,9 @@ var Account = class extends AbstractAccount {
4862
4849
  * @returns A promise that resolves when the resources are added to the transaction.
4863
4850
  */
4864
4851
  async fund(request, coinQuantities, fee) {
4865
- const baseAssetId = this.provider.getBaseAssetId();
4866
4852
  const updatedQuantities = addAmountToAsset({
4867
4853
  amount: bn16(fee),
4868
- assetId: baseAssetId,
4854
+ assetId: BaseAssetId3,
4869
4855
  coinQuantities
4870
4856
  });
4871
4857
  const quantitiesDict = {};
@@ -4889,8 +4875,8 @@ var Account = class extends AbstractAccount {
4889
4875
  quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
4890
4876
  cachedUtxos.push(input.id);
4891
4877
  }
4892
- } else if (input.recipient === owner && input.amount && quantitiesDict[baseAssetId]) {
4893
- quantitiesDict[baseAssetId].owned = quantitiesDict[baseAssetId].owned.add(input.amount);
4878
+ } else if (input.recipient === owner && input.amount && quantitiesDict[BaseAssetId3]) {
4879
+ quantitiesDict[BaseAssetId3].owned = quantitiesDict[BaseAssetId3].owned.add(input.amount);
4894
4880
  cachedMessages.push(input.nonce);
4895
4881
  }
4896
4882
  }
@@ -4922,12 +4908,11 @@ var Account = class extends AbstractAccount {
4922
4908
  * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
4923
4909
  * @returns A promise that resolves to the prepared transaction request.
4924
4910
  */
4925
- async createTransfer(destination, amount, assetId, txParams = {}) {
4911
+ async createTransfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
4926
4912
  const { minGasPrice } = this.provider.getGasConfig();
4927
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
4928
4913
  const params = { gasPrice: minGasPrice, ...txParams };
4929
4914
  const request = new ScriptTransactionRequest(params);
4930
- request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetIdToTransfer);
4915
+ request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetId);
4931
4916
  const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
4932
4917
  estimateTxDependencies: true,
4933
4918
  resourcesOwner: this
@@ -4953,15 +4938,14 @@ var Account = class extends AbstractAccount {
4953
4938
  * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
4954
4939
  * @returns A promise that resolves to the transaction response.
4955
4940
  */
4956
- async transfer(destination, amount, assetId, txParams = {}) {
4941
+ async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
4957
4942
  if (bn16(amount).lte(0)) {
4958
4943
  throw new FuelError14(
4959
4944
  ErrorCode14.INVALID_TRANSFER_AMOUNT,
4960
4945
  "Transfer amount must be a positive number."
4961
4946
  );
4962
4947
  }
4963
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
4964
- const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
4948
+ const request = await this.createTransfer(destination, amount, assetId, txParams);
4965
4949
  return this.sendTransaction(request, { estimateTxDependencies: false });
4966
4950
  }
4967
4951
  /**
@@ -4973,7 +4957,7 @@ var Account = class extends AbstractAccount {
4973
4957
  * @param txParams - The optional transaction parameters.
4974
4958
  * @returns A promise that resolves to the transaction response.
4975
4959
  */
4976
- async transferToContract(contractId, amount, assetId, txParams = {}) {
4960
+ async transferToContract(contractId, amount, assetId = BaseAssetId3, txParams = {}) {
4977
4961
  if (bn16(amount).lte(0)) {
4978
4962
  throw new FuelError14(
4979
4963
  ErrorCode14.INVALID_TRANSFER_AMOUNT,
@@ -4982,12 +4966,11 @@ var Account = class extends AbstractAccount {
4982
4966
  }
4983
4967
  const contractAddress = Address3.fromAddressOrString(contractId);
4984
4968
  const { minGasPrice } = this.provider.getGasConfig();
4985
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
4986
4969
  const params = { gasPrice: minGasPrice, ...txParams };
4987
4970
  const { script, scriptData } = await assembleTransferToContractScript({
4988
4971
  hexlifiedContractId: contractAddress.toB256(),
4989
4972
  amountToTransfer: bn16(amount),
4990
- assetId: assetIdToTransfer
4973
+ assetId
4991
4974
  });
4992
4975
  const request = new ScriptTransactionRequest({
4993
4976
  ...params,
@@ -4997,7 +4980,7 @@ var Account = class extends AbstractAccount {
4997
4980
  request.addContractInputAndOutput(contractAddress);
4998
4981
  const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
4999
4982
  request,
5000
- [{ amount: bn16(amount), assetId: String(assetIdToTransfer) }]
4983
+ [{ amount: bn16(amount), assetId: String(assetId) }]
5001
4984
  );
5002
4985
  request.gasLimit = bn16(params.gasLimit ?? gasUsed);
5003
4986
  this.validateGas({
@@ -5019,7 +5002,6 @@ var Account = class extends AbstractAccount {
5019
5002
  */
5020
5003
  async withdrawToBaseLayer(recipient, amount, txParams = {}) {
5021
5004
  const { minGasPrice } = this.provider.getGasConfig();
5022
- const baseAssetId = this.provider.getBaseAssetId();
5023
5005
  const recipientAddress = Address3.fromAddressOrString(recipient);
5024
5006
  const recipientDataArray = arrayify14(
5025
5007
  "0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
@@ -5034,7 +5016,7 @@ var Account = class extends AbstractAccount {
5034
5016
  ]);
5035
5017
  const params = { script, gasPrice: minGasPrice, ...txParams };
5036
5018
  const request = new ScriptTransactionRequest(params);
5037
- const forwardingQuantities = [{ amount: bn16(amount), assetId: baseAssetId }];
5019
+ const forwardingQuantities = [{ amount: bn16(amount), assetId: BaseAssetId3 }];
5038
5020
  const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
5039
5021
  request,
5040
5022
  forwardingQuantities
@@ -8611,6 +8593,7 @@ import {
8611
8593
  SCRIPT_FIXED_SIZE
8612
8594
  } from "@fuel-ts/abi-coder";
8613
8595
  import { Address as Address9 } from "@fuel-ts/address";
8596
+ import { BaseAssetId as BaseAssetId4 } from "@fuel-ts/address/configs";
8614
8597
  import { ErrorCode as ErrorCode23, FuelError as FuelError23 } from "@fuel-ts/errors";
8615
8598
  import { ByteArrayCoder, InputType as InputType7 } from "@fuel-ts/transactions";
8616
8599
  import { arrayify as arrayify20, hexlify as hexlify19 } from "@fuel-ts/utils";
@@ -8689,9 +8672,8 @@ var Predicate = class extends Account {
8689
8672
  * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
8690
8673
  * @returns A promise that resolves to the prepared transaction request.
8691
8674
  */
8692
- async createTransfer(destination, amount, assetId, txParams = {}) {
8693
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
8694
- const request = await super.createTransfer(destination, amount, assetIdToTransfer, txParams);
8675
+ async createTransfer(destination, amount, assetId = BaseAssetId4, txParams = {}) {
8676
+ const request = await super.createTransfer(destination, amount, assetId, txParams);
8695
8677
  return this.populateTransactionPredicateData(request);
8696
8678
  }
8697
8679
  /**