@fuel-ts/account 0.0.0-rc-1976-20240424150847 → 0.0.0-rc-2143-20240424152333

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);
@@ -1165,7 +1167,7 @@ var outputify = (value) => {
1165
1167
  // src/providers/transaction-request/transaction-request.ts
1166
1168
  import { UTXO_ID_LEN as UTXO_ID_LEN2 } from "@fuel-ts/abi-coder";
1167
1169
  import { Address, addressify } from "@fuel-ts/address";
1168
- import { ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
1170
+ import { BaseAssetId as BaseAssetId2, ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
1169
1171
  import { randomBytes } from "@fuel-ts/crypto";
1170
1172
  import { bn as bn7 } from "@fuel-ts/math";
1171
1173
  import {
@@ -1940,13 +1942,15 @@ var BaseTransactionRequest = class {
1940
1942
  }
1941
1943
  /**
1942
1944
  * Adds a single message input to the transaction and a change output for the
1943
- * asset against the message
1945
+ * baseAssetId, if one it was not added yet.
1944
1946
  *
1945
1947
  * @param message - Message resource.
1946
1948
  * @param predicate - Predicate bytes.
1949
+ * @param predicateData - Predicate data bytes.
1947
1950
  */
1948
1951
  addMessageInput(message, predicate) {
1949
- const { recipient, sender, amount, assetId } = message;
1952
+ const { recipient, sender, amount } = message;
1953
+ const assetId = BaseAssetId2;
1950
1954
  let witnessIndex;
1951
1955
  if (predicate) {
1952
1956
  witnessIndex = 0;
@@ -2027,7 +2031,7 @@ var BaseTransactionRequest = class {
2027
2031
  * @param amount - Amount of coin.
2028
2032
  * @param assetId - Asset ID of coin.
2029
2033
  */
2030
- addCoinOutput(to, amount, assetId) {
2034
+ addCoinOutput(to, amount, assetId = BaseAssetId2) {
2031
2035
  this.pushOutput({
2032
2036
  type: OutputType2.Coin,
2033
2037
  to: addressify(to).toB256(),
@@ -2059,7 +2063,7 @@ var BaseTransactionRequest = class {
2059
2063
  * @param to - Address of the owner.
2060
2064
  * @param assetId - Asset ID of coin.
2061
2065
  */
2062
- addChangeOutput(to, assetId) {
2066
+ addChangeOutput(to, assetId = BaseAssetId2) {
2063
2067
  const changeOutput = this.getChangeOutputs().find(
2064
2068
  (output) => hexlify7(output.assetId) === assetId
2065
2069
  );
@@ -2116,9 +2120,8 @@ var BaseTransactionRequest = class {
2116
2120
  * quantities array.
2117
2121
  *
2118
2122
  * @param quantities - CoinQuantity Array.
2119
- * @param baseAssetId - The base asset to fund the transaction.
2120
2123
  */
2121
- fundWithFakeUtxos(quantities, baseAssetId, resourcesOwner) {
2124
+ fundWithFakeUtxos(quantities, resourcesOwner) {
2122
2125
  const findAssetInput = (assetId) => this.inputs.find((input) => {
2123
2126
  if ("assetId" in input) {
2124
2127
  return input.assetId === assetId;
@@ -2144,7 +2147,7 @@ var BaseTransactionRequest = class {
2144
2147
  ]);
2145
2148
  }
2146
2149
  };
2147
- updateAssetInput(baseAssetId, bn7(1e11));
2150
+ updateAssetInput(BaseAssetId2, bn7(1e11));
2148
2151
  quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
2149
2152
  }
2150
2153
  /**
@@ -2314,7 +2317,12 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2314
2317
  *
2315
2318
  * @param createTransactionRequestLike - The initial values for the instance
2316
2319
  */
2317
- constructor({ bytecodeWitnessIndex, salt, storageSlots, ...rest }) {
2320
+ constructor({
2321
+ bytecodeWitnessIndex,
2322
+ salt,
2323
+ storageSlots,
2324
+ ...rest
2325
+ } = {}) {
2318
2326
  super(rest);
2319
2327
  this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
2320
2328
  this.salt = hexlify9(salt ?? ZeroBytes326);
@@ -3575,7 +3583,7 @@ function autoRetryFetch(fetchFn, options, retryAttemptNum = 0) {
3575
3583
  }
3576
3584
 
3577
3585
  // src/providers/utils/merge-quantities.ts
3578
- var mergeQuantities = (...coinQuantities) => {
3586
+ var mergeQuantities = (arr1, arr2) => {
3579
3587
  const resultMap = {};
3580
3588
  function addToMap({ amount, assetId }) {
3581
3589
  if (resultMap[assetId]) {
@@ -3584,7 +3592,8 @@ var mergeQuantities = (...coinQuantities) => {
3584
3592
  resultMap[assetId] = amount;
3585
3593
  }
3586
3594
  }
3587
- coinQuantities.forEach((arr) => arr.forEach(addToMap));
3595
+ arr1.forEach(addToMap);
3596
+ arr2.forEach(addToMap);
3588
3597
  return Object.entries(resultMap).map(([assetId, amount]) => ({ assetId, amount }));
3589
3598
  };
3590
3599
 
@@ -3612,7 +3621,6 @@ var processGqlChain = (chain) => {
3612
3621
  gasPerByte: bn15(feeParams.gasPerByte),
3613
3622
  maxMessageDataLength: bn15(predicateParams.maxMessageDataLength),
3614
3623
  chainId: bn15(consensusParameters.chainId),
3615
- baseAssetId: consensusParameters.baseAssetId,
3616
3624
  gasCosts
3617
3625
  },
3618
3626
  gasCosts,
@@ -3855,17 +3863,6 @@ var _Provider = class {
3855
3863
  } = this.getChain();
3856
3864
  return chainId.toNumber();
3857
3865
  }
3858
- /**
3859
- * Returns the base asset ID
3860
- *
3861
- * @returns A promise that resolves to the base asset ID
3862
- */
3863
- getBaseAssetId() {
3864
- const {
3865
- consensusParameters: { baseAssetId }
3866
- } = this.getChain();
3867
- return baseAssetId;
3868
- }
3869
3866
  /**
3870
3867
  * Submits a transaction to the chain to be executed.
3871
3868
  *
@@ -4096,10 +4093,9 @@ var _Provider = class {
4096
4093
  const { minGasPrice } = this.getGasConfig();
4097
4094
  const setGasPrice = max(txRequestClone.gasPrice, minGasPrice);
4098
4095
  const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
4099
- const baseAssetId = this.getBaseAssetId();
4100
4096
  const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
4101
4097
  const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
4102
- txRequestClone.fundWithFakeUtxos(allQuantities, baseAssetId, resourcesOwner?.address);
4098
+ txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
4103
4099
  if (isScriptTransaction) {
4104
4100
  txRequestClone.gasLimit = bn15(0);
4105
4101
  }
@@ -4930,9 +4926,8 @@ var Account = class extends AbstractAccount {
4930
4926
  * @param assetId - The asset ID to check the balance for.
4931
4927
  * @returns A promise that resolves to the balance amount.
4932
4928
  */
4933
- async getBalance(assetId) {
4934
- const assetIdToFetch = assetId ?? this.provider.getBaseAssetId();
4935
- const amount = await this.provider.getBalance(this.address, assetIdToFetch);
4929
+ async getBalance(assetId = BaseAssetId3) {
4930
+ const amount = await this.provider.getBalance(this.address, assetId);
4936
4931
  return amount;
4937
4932
  }
4938
4933
  /**
@@ -4970,10 +4965,9 @@ var Account = class extends AbstractAccount {
4970
4965
  * @returns A promise that resolves when the resources are added to the transaction.
4971
4966
  */
4972
4967
  async fund(request, coinQuantities, fee) {
4973
- const baseAssetId = this.provider.getBaseAssetId();
4974
4968
  const updatedQuantities = addAmountToAsset({
4975
4969
  amount: bn17(fee),
4976
- assetId: baseAssetId,
4970
+ assetId: BaseAssetId3,
4977
4971
  coinQuantities
4978
4972
  });
4979
4973
  const quantitiesDict = {};
@@ -4997,8 +4991,8 @@ var Account = class extends AbstractAccount {
4997
4991
  quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
4998
4992
  cachedUtxos.push(input.id);
4999
4993
  }
5000
- } else if (input.recipient === owner && input.amount && quantitiesDict[baseAssetId]) {
5001
- quantitiesDict[baseAssetId].owned = quantitiesDict[baseAssetId].owned.add(input.amount);
4994
+ } else if (input.recipient === owner && input.amount && quantitiesDict[BaseAssetId3]) {
4995
+ quantitiesDict[BaseAssetId3].owned = quantitiesDict[BaseAssetId3].owned.add(input.amount);
5002
4996
  cachedMessages.push(input.nonce);
5003
4997
  }
5004
4998
  }
@@ -5030,13 +5024,11 @@ var Account = class extends AbstractAccount {
5030
5024
  * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
5031
5025
  * @returns A promise that resolves to the prepared transaction request.
5032
5026
  */
5033
- async createTransfer(destination, amount, assetId, txParams = {}) {
5027
+ async createTransfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
5034
5028
  const { minGasPrice } = this.provider.getGasConfig();
5035
- const baseAssetId = this.provider.getBaseAssetId();
5036
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
5037
- const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
5029
+ const params = { gasPrice: minGasPrice, ...txParams };
5038
5030
  const request = new ScriptTransactionRequest(params);
5039
- request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetIdToTransfer);
5031
+ request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetId);
5040
5032
  const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
5041
5033
  estimateTxDependencies: true,
5042
5034
  resourcesOwner: this
@@ -5062,15 +5054,14 @@ var Account = class extends AbstractAccount {
5062
5054
  * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
5063
5055
  * @returns A promise that resolves to the transaction response.
5064
5056
  */
5065
- async transfer(destination, amount, assetId, txParams = {}) {
5057
+ async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
5066
5058
  if (bn17(amount).lte(0)) {
5067
5059
  throw new FuelError15(
5068
5060
  ErrorCode15.INVALID_TRANSFER_AMOUNT,
5069
5061
  "Transfer amount must be a positive number."
5070
5062
  );
5071
5063
  }
5072
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
5073
- const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
5064
+ const request = await this.createTransfer(destination, amount, assetId, txParams);
5074
5065
  return this.sendTransaction(request, { estimateTxDependencies: false });
5075
5066
  }
5076
5067
  /**
@@ -5082,7 +5073,7 @@ var Account = class extends AbstractAccount {
5082
5073
  * @param txParams - The optional transaction parameters.
5083
5074
  * @returns A promise that resolves to the transaction response.
5084
5075
  */
5085
- async transferToContract(contractId, amount, assetId, txParams = {}) {
5076
+ async transferToContract(contractId, amount, assetId = BaseAssetId3, txParams = {}) {
5086
5077
  if (bn17(amount).lte(0)) {
5087
5078
  throw new FuelError15(
5088
5079
  ErrorCode15.INVALID_TRANSFER_AMOUNT,
@@ -5091,13 +5082,11 @@ var Account = class extends AbstractAccount {
5091
5082
  }
5092
5083
  const contractAddress = Address3.fromAddressOrString(contractId);
5093
5084
  const { minGasPrice } = this.provider.getGasConfig();
5094
- const baseAssetId = this.provider.getBaseAssetId();
5095
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
5096
- const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
5085
+ const params = { gasPrice: minGasPrice, ...txParams };
5097
5086
  const { script, scriptData } = await assembleTransferToContractScript({
5098
5087
  hexlifiedContractId: contractAddress.toB256(),
5099
5088
  amountToTransfer: bn17(amount),
5100
- assetId: assetIdToTransfer
5089
+ assetId
5101
5090
  });
5102
5091
  const request = new ScriptTransactionRequest({
5103
5092
  ...params,
@@ -5107,7 +5096,7 @@ var Account = class extends AbstractAccount {
5107
5096
  request.addContractInputAndOutput(contractAddress);
5108
5097
  const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
5109
5098
  request,
5110
- [{ amount: bn17(amount), assetId: String(assetIdToTransfer) }]
5099
+ [{ amount: bn17(amount), assetId: String(assetId) }]
5111
5100
  );
5112
5101
  request.gasLimit = bn17(params.gasLimit ?? gasUsed);
5113
5102
  this.validateGas({
@@ -5129,7 +5118,6 @@ var Account = class extends AbstractAccount {
5129
5118
  */
5130
5119
  async withdrawToBaseLayer(recipient, amount, txParams = {}) {
5131
5120
  const { minGasPrice } = this.provider.getGasConfig();
5132
- const baseAssetId = this.provider.getBaseAssetId();
5133
5121
  const recipientAddress = Address3.fromAddressOrString(recipient);
5134
5122
  const recipientDataArray = arrayify14(
5135
5123
  "0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
@@ -5142,13 +5130,9 @@ var Account = class extends AbstractAccount {
5142
5130
  ...recipientDataArray,
5143
5131
  ...amountDataArray
5144
5132
  ]);
5145
- const params = {
5146
- script,
5147
- gasPrice: minGasPrice,
5148
- ...txParams
5149
- };
5133
+ const params = { script, gasPrice: minGasPrice, ...txParams };
5150
5134
  const request = new ScriptTransactionRequest(params);
5151
- const forwardingQuantities = [{ amount: bn17(amount), assetId: baseAssetId }];
5135
+ const forwardingQuantities = [{ amount: bn17(amount), assetId: BaseAssetId3 }];
5152
5136
  const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
5153
5137
  request,
5154
5138
  forwardingQuantities
@@ -8725,6 +8709,7 @@ import {
8725
8709
  SCRIPT_FIXED_SIZE
8726
8710
  } from "@fuel-ts/abi-coder";
8727
8711
  import { Address as Address9 } from "@fuel-ts/address";
8712
+ import { BaseAssetId as BaseAssetId4 } from "@fuel-ts/address/configs";
8728
8713
  import { ErrorCode as ErrorCode24, FuelError as FuelError24 } from "@fuel-ts/errors";
8729
8714
  import { ByteArrayCoder, InputType as InputType7 } from "@fuel-ts/transactions";
8730
8715
  import { arrayify as arrayify20, hexlify as hexlify19 } from "@fuel-ts/utils";
@@ -8802,9 +8787,8 @@ var Predicate = class extends Account {
8802
8787
  * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
8803
8788
  * @returns A promise that resolves to the prepared transaction request.
8804
8789
  */
8805
- async createTransfer(destination, amount, assetId, txParams = {}) {
8806
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
8807
- const request = await super.createTransfer(destination, amount, assetIdToTransfer, txParams);
8790
+ async createTransfer(destination, amount, assetId = BaseAssetId4, txParams = {}) {
8791
+ const request = await super.createTransfer(destination, amount, assetId, txParams);
8808
8792
  return this.populateTransactionPredicateData(request);
8809
8793
  }
8810
8794
  /**