@fuel-ts/account 0.0.0-rc-1976-20240415093634 → 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.

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 ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
33
34
  import { AbstractAccount } from "@fuel-ts/interfaces";
34
35
  import { bn as bn17 } 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);
@@ -1156,7 +1158,7 @@ var outputify = (value) => {
1156
1158
  // src/providers/transaction-request/transaction-request.ts
1157
1159
  import { UTXO_ID_LEN as UTXO_ID_LEN2 } from "@fuel-ts/abi-coder";
1158
1160
  import { Address, addressify } from "@fuel-ts/address";
1159
- import { ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
1161
+ import { BaseAssetId as BaseAssetId2, ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
1160
1162
  import { randomBytes } from "@fuel-ts/crypto";
1161
1163
  import { bn as bn7 } from "@fuel-ts/math";
1162
1164
  import {
@@ -1691,8 +1693,6 @@ var BaseTransactionRequest = class {
1691
1693
  outputs = [];
1692
1694
  /** List of witnesses */
1693
1695
  witnesses = [];
1694
- /** Base asset ID - should be fetched from the chain */
1695
- baseAssetId;
1696
1696
  /**
1697
1697
  * Constructor for initializing a base transaction request.
1698
1698
  *
@@ -1705,9 +1705,8 @@ var BaseTransactionRequest = class {
1705
1705
  witnessLimit,
1706
1706
  inputs,
1707
1707
  outputs,
1708
- witnesses,
1709
- baseAssetId
1710
- }) {
1708
+ witnesses
1709
+ } = {}) {
1711
1710
  this.gasPrice = bn7(gasPrice);
1712
1711
  this.maturity = maturity ?? 0;
1713
1712
  this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
@@ -1715,7 +1714,6 @@ var BaseTransactionRequest = class {
1715
1714
  this.inputs = inputs ?? [];
1716
1715
  this.outputs = outputs ?? [];
1717
1716
  this.witnesses = witnesses ?? [];
1718
- this.baseAssetId = baseAssetId;
1719
1717
  }
1720
1718
  static getPolicyMeta(req) {
1721
1719
  let policyTypes = 0;
@@ -1939,9 +1937,11 @@ var BaseTransactionRequest = class {
1939
1937
  *
1940
1938
  * @param message - Message resource.
1941
1939
  * @param predicate - Predicate bytes.
1940
+ * @param predicateData - Predicate data bytes.
1942
1941
  */
1943
1942
  addMessageInput(message, predicate) {
1944
1943
  const { recipient, sender, amount } = message;
1944
+ const assetId = BaseAssetId2;
1945
1945
  let witnessIndex;
1946
1946
  if (predicate) {
1947
1947
  witnessIndex = 0;
@@ -1961,7 +1961,7 @@ var BaseTransactionRequest = class {
1961
1961
  predicate: predicate?.bytes
1962
1962
  };
1963
1963
  this.pushInput(input);
1964
- this.addChangeOutput(recipient, this.baseAssetId);
1964
+ this.addChangeOutput(recipient, assetId);
1965
1965
  }
1966
1966
  /**
1967
1967
  * Adds a single resource to the transaction by adding a coin/message input and a
@@ -2022,12 +2022,12 @@ var BaseTransactionRequest = class {
2022
2022
  * @param amount - Amount of coin.
2023
2023
  * @param assetId - Asset ID of coin.
2024
2024
  */
2025
- addCoinOutput(to, amount, assetId) {
2025
+ addCoinOutput(to, amount, assetId = BaseAssetId2) {
2026
2026
  this.pushOutput({
2027
2027
  type: OutputType2.Coin,
2028
2028
  to: addressify(to).toB256(),
2029
2029
  amount,
2030
- assetId: assetId ?? this.baseAssetId
2030
+ assetId
2031
2031
  });
2032
2032
  return this;
2033
2033
  }
@@ -2054,7 +2054,7 @@ var BaseTransactionRequest = class {
2054
2054
  * @param to - Address of the owner.
2055
2055
  * @param assetId - Asset ID of coin.
2056
2056
  */
2057
- addChangeOutput(to, assetId) {
2057
+ addChangeOutput(to, assetId = BaseAssetId2) {
2058
2058
  const changeOutput = this.getChangeOutputs().find(
2059
2059
  (output) => hexlify7(output.assetId) === assetId
2060
2060
  );
@@ -2062,7 +2062,7 @@ var BaseTransactionRequest = class {
2062
2062
  this.pushOutput({
2063
2063
  type: OutputType2.Change,
2064
2064
  to: addressify(to).toB256(),
2065
- assetId: assetId ?? this.baseAssetId
2065
+ assetId
2066
2066
  });
2067
2067
  }
2068
2068
  }
@@ -2138,7 +2138,7 @@ var BaseTransactionRequest = class {
2138
2138
  ]);
2139
2139
  }
2140
2140
  };
2141
- updateAssetInput(this.baseAssetId, bn7(1e11));
2141
+ updateAssetInput(BaseAssetId2, bn7(1e11));
2142
2142
  quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
2143
2143
  }
2144
2144
  /**
@@ -2308,7 +2308,12 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2308
2308
  *
2309
2309
  * @param createTransactionRequestLike - The initial values for the instance
2310
2310
  */
2311
- constructor({ bytecodeWitnessIndex, salt, storageSlots, ...rest }) {
2311
+ constructor({
2312
+ bytecodeWitnessIndex,
2313
+ salt,
2314
+ storageSlots,
2315
+ ...rest
2316
+ } = {}) {
2312
2317
  super(rest);
2313
2318
  this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
2314
2319
  this.salt = hexlify9(salt ?? ZeroBytes326);
@@ -2432,7 +2437,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2432
2437
  *
2433
2438
  * @param scriptTransactionRequestLike - The initial values for the instance.
2434
2439
  */
2435
- constructor({ script, scriptData, gasLimit, ...rest }) {
2440
+ constructor({ script, scriptData, gasLimit, ...rest } = {}) {
2436
2441
  super(rest);
2437
2442
  this.gasLimit = bn10(gasLimit);
2438
2443
  this.script = arrayify8(script ?? returnZeroScript.bytes);
@@ -3607,7 +3612,6 @@ var processGqlChain = (chain) => {
3607
3612
  gasPerByte: bn15(feeParams.gasPerByte),
3608
3613
  maxMessageDataLength: bn15(predicateParams.maxMessageDataLength),
3609
3614
  chainId: bn15(consensusParameters.chainId),
3610
- baseAssetId: consensusParameters.baseAssetId,
3611
3615
  gasCosts
3612
3616
  },
3613
3617
  gasCosts,
@@ -3850,17 +3854,6 @@ var _Provider = class {
3850
3854
  } = this.getChain();
3851
3855
  return chainId.toNumber();
3852
3856
  }
3853
- /**
3854
- * Returns the base asset ID
3855
- *
3856
- * @returns A promise that resolves to the base asset ID
3857
- */
3858
- getBaseAssetId() {
3859
- const {
3860
- consensusParameters: { baseAssetId }
3861
- } = this.getChain();
3862
- return baseAssetId;
3863
- }
3864
3857
  /**
3865
3858
  * Submits a transaction to the chain to be executed.
3866
3859
  *
@@ -4924,9 +4917,8 @@ var Account = class extends AbstractAccount {
4924
4917
  * @param assetId - The asset ID to check the balance for.
4925
4918
  * @returns A promise that resolves to the balance amount.
4926
4919
  */
4927
- async getBalance(assetId) {
4928
- const assetIdToFetch = assetId ?? this.provider.getBaseAssetId();
4929
- const amount = await this.provider.getBalance(this.address, assetIdToFetch);
4920
+ async getBalance(assetId = BaseAssetId3) {
4921
+ const amount = await this.provider.getBalance(this.address, assetId);
4930
4922
  return amount;
4931
4923
  }
4932
4924
  /**
@@ -4964,10 +4956,9 @@ var Account = class extends AbstractAccount {
4964
4956
  * @returns A promise that resolves when the resources are added to the transaction.
4965
4957
  */
4966
4958
  async fund(request, coinQuantities, fee) {
4967
- const baseAssetId = this.provider.getBaseAssetId();
4968
4959
  const updatedQuantities = addAmountToAsset({
4969
4960
  amount: bn17(fee),
4970
- assetId: baseAssetId,
4961
+ assetId: BaseAssetId3,
4971
4962
  coinQuantities
4972
4963
  });
4973
4964
  const quantitiesDict = {};
@@ -4991,8 +4982,8 @@ var Account = class extends AbstractAccount {
4991
4982
  quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
4992
4983
  cachedUtxos.push(input.id);
4993
4984
  }
4994
- } else if (input.recipient === owner && input.amount && quantitiesDict[baseAssetId]) {
4995
- quantitiesDict[baseAssetId].owned = quantitiesDict[baseAssetId].owned.add(input.amount);
4985
+ } else if (input.recipient === owner && input.amount && quantitiesDict[BaseAssetId3]) {
4986
+ quantitiesDict[BaseAssetId3].owned = quantitiesDict[BaseAssetId3].owned.add(input.amount);
4996
4987
  cachedMessages.push(input.nonce);
4997
4988
  }
4998
4989
  }
@@ -5024,13 +5015,11 @@ var Account = class extends AbstractAccount {
5024
5015
  * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
5025
5016
  * @returns A promise that resolves to the prepared transaction request.
5026
5017
  */
5027
- async createTransfer(destination, amount, assetId, txParams = {}) {
5018
+ async createTransfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
5028
5019
  const { minGasPrice } = this.provider.getGasConfig();
5029
- const baseAssetId = this.provider.getBaseAssetId();
5030
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
5031
- const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
5020
+ const params = { gasPrice: minGasPrice, ...txParams };
5032
5021
  const request = new ScriptTransactionRequest(params);
5033
- request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetIdToTransfer);
5022
+ request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetId);
5034
5023
  const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
5035
5024
  estimateTxDependencies: true,
5036
5025
  resourcesOwner: this
@@ -5056,15 +5045,14 @@ var Account = class extends AbstractAccount {
5056
5045
  * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
5057
5046
  * @returns A promise that resolves to the transaction response.
5058
5047
  */
5059
- async transfer(destination, amount, assetId, txParams = {}) {
5048
+ async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
5060
5049
  if (bn17(amount).lte(0)) {
5061
5050
  throw new FuelError15(
5062
5051
  ErrorCode15.INVALID_TRANSFER_AMOUNT,
5063
5052
  "Transfer amount must be a positive number."
5064
5053
  );
5065
5054
  }
5066
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
5067
- const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
5055
+ const request = await this.createTransfer(destination, amount, assetId, txParams);
5068
5056
  return this.sendTransaction(request, { estimateTxDependencies: false });
5069
5057
  }
5070
5058
  /**
@@ -5076,7 +5064,7 @@ var Account = class extends AbstractAccount {
5076
5064
  * @param txParams - The optional transaction parameters.
5077
5065
  * @returns A promise that resolves to the transaction response.
5078
5066
  */
5079
- async transferToContract(contractId, amount, assetId, txParams = {}) {
5067
+ async transferToContract(contractId, amount, assetId = BaseAssetId3, txParams = {}) {
5080
5068
  if (bn17(amount).lte(0)) {
5081
5069
  throw new FuelError15(
5082
5070
  ErrorCode15.INVALID_TRANSFER_AMOUNT,
@@ -5085,13 +5073,11 @@ var Account = class extends AbstractAccount {
5085
5073
  }
5086
5074
  const contractAddress = Address3.fromAddressOrString(contractId);
5087
5075
  const { minGasPrice } = this.provider.getGasConfig();
5088
- const baseAssetId = this.provider.getBaseAssetId();
5089
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
5090
- const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
5076
+ const params = { gasPrice: minGasPrice, ...txParams };
5091
5077
  const { script, scriptData } = await assembleTransferToContractScript({
5092
5078
  hexlifiedContractId: contractAddress.toB256(),
5093
5079
  amountToTransfer: bn17(amount),
5094
- assetId: assetIdToTransfer
5080
+ assetId
5095
5081
  });
5096
5082
  const request = new ScriptTransactionRequest({
5097
5083
  ...params,
@@ -5101,7 +5087,7 @@ var Account = class extends AbstractAccount {
5101
5087
  request.addContractInputAndOutput(contractAddress);
5102
5088
  const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
5103
5089
  request,
5104
- [{ amount: bn17(amount), assetId: String(assetIdToTransfer) }]
5090
+ [{ amount: bn17(amount), assetId: String(assetId) }]
5105
5091
  );
5106
5092
  request.gasLimit = bn17(params.gasLimit ?? gasUsed);
5107
5093
  this.validateGas({
@@ -5123,7 +5109,6 @@ var Account = class extends AbstractAccount {
5123
5109
  */
5124
5110
  async withdrawToBaseLayer(recipient, amount, txParams = {}) {
5125
5111
  const { minGasPrice } = this.provider.getGasConfig();
5126
- const baseAssetId = this.provider.getBaseAssetId();
5127
5112
  const recipientAddress = Address3.fromAddressOrString(recipient);
5128
5113
  const recipientDataArray = arrayify14(
5129
5114
  "0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
@@ -5136,14 +5121,9 @@ var Account = class extends AbstractAccount {
5136
5121
  ...recipientDataArray,
5137
5122
  ...amountDataArray
5138
5123
  ]);
5139
- const params = {
5140
- script,
5141
- gasPrice: minGasPrice,
5142
- baseAssetId,
5143
- ...txParams
5144
- };
5124
+ const params = { script, gasPrice: minGasPrice, ...txParams };
5145
5125
  const request = new ScriptTransactionRequest(params);
5146
- const forwardingQuantities = [{ amount: bn17(amount), assetId: baseAssetId }];
5126
+ const forwardingQuantities = [{ amount: bn17(amount), assetId: BaseAssetId3 }];
5147
5127
  const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
5148
5128
  request,
5149
5129
  forwardingQuantities
@@ -8720,6 +8700,7 @@ import {
8720
8700
  SCRIPT_FIXED_SIZE
8721
8701
  } from "@fuel-ts/abi-coder";
8722
8702
  import { Address as Address9 } from "@fuel-ts/address";
8703
+ import { BaseAssetId as BaseAssetId4 } from "@fuel-ts/address/configs";
8723
8704
  import { ErrorCode as ErrorCode24, FuelError as FuelError24 } from "@fuel-ts/errors";
8724
8705
  import { ByteArrayCoder, InputType as InputType7 } from "@fuel-ts/transactions";
8725
8706
  import { arrayify as arrayify20, hexlify as hexlify19 } from "@fuel-ts/utils";
@@ -8797,9 +8778,8 @@ var Predicate = class extends Account {
8797
8778
  * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
8798
8779
  * @returns A promise that resolves to the prepared transaction request.
8799
8780
  */
8800
- async createTransfer(destination, amount, assetId, txParams = {}) {
8801
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
8802
- const request = await super.createTransfer(destination, amount, assetIdToTransfer, txParams);
8781
+ async createTransfer(destination, amount, assetId = BaseAssetId4, txParams = {}) {
8782
+ const request = await super.createTransfer(destination, amount, assetId, txParams);
8803
8783
  return this.populateTransactionPredicateData(request);
8804
8784
  }
8805
8785
  /**