@fuel-ts/account 0.92.1 → 0.93.0

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.
@@ -2758,7 +2758,10 @@ var transactionRequestify = (obj) => {
2758
2758
  return CreateTransactionRequest.from(obj);
2759
2759
  }
2760
2760
  default: {
2761
- throw new import_errors9.FuelError(import_errors9.ErrorCode.INVALID_TRANSACTION_TYPE, `Invalid transaction type: ${type}.`);
2761
+ throw new import_errors9.FuelError(
2762
+ import_errors9.ErrorCode.UNSUPPORTED_TRANSACTION_TYPE,
2763
+ `Unsupported transaction type: ${type}.`
2764
+ );
2762
2765
  }
2763
2766
  }
2764
2767
  };
@@ -2971,8 +2974,8 @@ function getTransactionTypeName(transactionType) {
2971
2974
  return "Script" /* Script */;
2972
2975
  default:
2973
2976
  throw new import_errors11.FuelError(
2974
- import_errors11.ErrorCode.INVALID_TRANSACTION_TYPE,
2975
- `Invalid transaction type: ${transactionType}.`
2977
+ import_errors11.ErrorCode.UNSUPPORTED_TRANSACTION_TYPE,
2978
+ `Unsupported transaction type: ${transactionType}.`
2976
2979
  );
2977
2980
  }
2978
2981
  }
@@ -3720,24 +3723,11 @@ function autoRetryFetch(fetchFn, options, retryAttemptNum = 0) {
3720
3723
  };
3721
3724
  }
3722
3725
 
3723
- // src/providers/utils/merge-quantities.ts
3724
- var mergeQuantities = (...coinQuantities) => {
3725
- const resultMap = {};
3726
- function addToMap({ amount, assetId }) {
3727
- if (resultMap[assetId]) {
3728
- resultMap[assetId] = resultMap[assetId].add(amount);
3729
- } else {
3730
- resultMap[assetId] = amount;
3731
- }
3732
- }
3733
- coinQuantities.forEach((arr) => arr.forEach(addToMap));
3734
- return Object.entries(resultMap).map(([assetId, amount]) => ({ assetId, amount }));
3735
- };
3736
-
3737
3726
  // src/providers/provider.ts
3738
3727
  var MAX_RETRIES = 10;
3739
3728
  var RESOURCES_PAGE_SIZE_LIMIT = 512;
3740
3729
  var BLOCKS_PAGE_SIZE_LIMIT = 5;
3730
+ var DEFAULT_UTXOS_CACHE_TTL = 2e4;
3741
3731
  var processGqlChain = (chain) => {
3742
3732
  const { name, daHeight, consensusParameters, latestBlock } = chain;
3743
3733
  const {
@@ -3827,7 +3817,16 @@ var _Provider = class {
3827
3817
  this.options = { ...this.options, ...options };
3828
3818
  this.url = url;
3829
3819
  this.operations = this.createOperations();
3830
- this.cache = options.cacheUtxo ? new MemoryCache(options.cacheUtxo) : void 0;
3820
+ const { cacheUtxo } = this.options;
3821
+ if ((0, import_utils23.isDefined)(cacheUtxo)) {
3822
+ if (cacheUtxo !== -1) {
3823
+ this.cache = new MemoryCache(cacheUtxo);
3824
+ } else {
3825
+ this.cache = void 0;
3826
+ }
3827
+ } else {
3828
+ this.cache = new MemoryCache(DEFAULT_UTXOS_CACHE_TTL);
3829
+ }
3831
3830
  }
3832
3831
  /** @hidden */
3833
3832
  static clearChainAndNodeCaches() {
@@ -4069,9 +4068,8 @@ Supported fuel-core version: ${supportedVersion}.`
4069
4068
  * @returns A promise that resolves to the transaction response object.
4070
4069
  */
4071
4070
  // #region Provider-sendTransaction
4072
- async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution = false } = {}) {
4071
+ async sendTransaction(transactionRequestLike, { estimateTxDependencies = true } = {}) {
4073
4072
  const transactionRequest = transactionRequestify(transactionRequestLike);
4074
- __privateMethod(this, _cacheInputs, cacheInputs_fn).call(this, transactionRequest.inputs);
4075
4073
  if (estimateTxDependencies) {
4076
4074
  await this.estimateTxDependencies(transactionRequest);
4077
4075
  }
@@ -4080,27 +4078,10 @@ Supported fuel-core version: ${supportedVersion}.`
4080
4078
  if (transactionRequest.type === import_transactions20.TransactionType.Script) {
4081
4079
  abis = transactionRequest.abis;
4082
4080
  }
4083
- if (awaitExecution) {
4084
- const subscription = this.operations.submitAndAwait({ encodedTransaction });
4085
- for await (const { submitAndAwait } of subscription) {
4086
- if (submitAndAwait.type === "SqueezedOutStatus") {
4087
- throw new import_errors14.FuelError(
4088
- import_errors14.ErrorCode.TRANSACTION_SQUEEZED_OUT,
4089
- `Transaction Squeezed Out with reason: ${submitAndAwait.reason}`
4090
- );
4091
- }
4092
- if (submitAndAwait.type !== "SubmittedStatus") {
4093
- break;
4094
- }
4095
- }
4096
- const transactionId2 = transactionRequest.getTransactionId(this.getChainId());
4097
- const response = new TransactionResponse(transactionId2, this, abis);
4098
- await response.fetch();
4099
- return response;
4100
- }
4101
4081
  const {
4102
4082
  submit: { id: transactionId }
4103
4083
  } = await this.operations.submit({ encodedTransaction });
4084
+ __privateMethod(this, _cacheInputs, cacheInputs_fn).call(this, transactionRequest.inputs);
4104
4085
  return new TransactionResponse(transactionId, this, abis);
4105
4086
  }
4106
4087
  /**
@@ -4379,6 +4360,8 @@ Supported fuel-core version: ${supportedVersion}.`
4379
4360
  return { receipts: callResult[0].receipts };
4380
4361
  }
4381
4362
  /**
4363
+ * @hidden
4364
+ *
4382
4365
  * Returns a transaction cost to enable user
4383
4366
  * to set gasLimit and also reserve balance amounts
4384
4367
  * on the transaction.
@@ -4388,20 +4371,13 @@ Supported fuel-core version: ${supportedVersion}.`
4388
4371
  *
4389
4372
  * @returns A promise that resolves to the transaction cost object.
4390
4373
  */
4391
- async getTransactionCost(transactionRequestLike, { resourcesOwner, signatureCallback, quantitiesToContract = [] } = {}) {
4374
+ async getTransactionCost(transactionRequestLike, { signatureCallback } = {}) {
4392
4375
  const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
4393
4376
  const isScriptTransaction = txRequestClone.type === import_transactions20.TransactionType.Script;
4394
- const baseAssetId = this.getBaseAssetId();
4395
4377
  const updateMaxFee = txRequestClone.maxFee.eq(0);
4396
- const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
4397
- const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
4398
- txRequestClone.fundWithFakeUtxos(allQuantities, baseAssetId, resourcesOwner?.address);
4399
4378
  if (isScriptTransaction) {
4400
4379
  txRequestClone.gasLimit = (0, import_math17.bn)(0);
4401
4380
  }
4402
- if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
4403
- resourcesOwner.populateTransactionPredicateData(txRequestClone);
4404
- }
4405
4381
  const signedRequest = (0, import_ramda3.clone)(txRequestClone);
4406
4382
  let addedSignatures = 0;
4407
4383
  if (signatureCallback && isScriptTransaction) {
@@ -4437,7 +4413,6 @@ Supported fuel-core version: ${supportedVersion}.`
4437
4413
  }));
4438
4414
  }
4439
4415
  return {
4440
- requiredQuantities: allQuantities,
4441
4416
  receipts,
4442
4417
  gasUsed,
4443
4418
  gasPrice,
@@ -4453,34 +4428,6 @@ Supported fuel-core version: ${supportedVersion}.`
4453
4428
  updateMaxFee
4454
4429
  };
4455
4430
  }
4456
- /**
4457
- * Get the required quantities and associated resources for a transaction.
4458
- *
4459
- * @param owner - address to add resources from.
4460
- * @param transactionRequestLike - transaction request to populate resources for.
4461
- * @param quantitiesToContract - quantities for the contract (optional).
4462
- *
4463
- * @returns a promise resolving to the required quantities for the transaction.
4464
- */
4465
- async getResourcesForTransaction(owner, transactionRequestLike, quantitiesToContract = []) {
4466
- const ownerAddress = import_address3.Address.fromAddressOrString(owner);
4467
- const transactionRequest = transactionRequestify((0, import_ramda3.clone)(transactionRequestLike));
4468
- const transactionCost = await this.getTransactionCost(transactionRequest, {
4469
- quantitiesToContract
4470
- });
4471
- transactionRequest.addResources(
4472
- await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
4473
- );
4474
- const { requiredQuantities, ...txCost } = await this.getTransactionCost(transactionRequest, {
4475
- quantitiesToContract
4476
- });
4477
- const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
4478
- return {
4479
- resources,
4480
- requiredQuantities,
4481
- ...txCost
4482
- };
4483
- }
4484
4431
  /**
4485
4432
  * Returns coins for the given owner.
4486
4433
  *
@@ -5109,6 +5056,20 @@ var rawAssets = [
5109
5056
  ];
5110
5057
  var assets = resolveIconPaths(rawAssets, fuelAssetsBaseUrl);
5111
5058
 
5059
+ // src/providers/utils/merge-quantities.ts
5060
+ var mergeQuantities = (...coinQuantities) => {
5061
+ const resultMap = {};
5062
+ function addToMap({ amount, assetId }) {
5063
+ if (resultMap[assetId]) {
5064
+ resultMap[assetId] = resultMap[assetId].add(amount);
5065
+ } else {
5066
+ resultMap[assetId] = amount;
5067
+ }
5068
+ }
5069
+ coinQuantities.forEach((arr) => arr.forEach(addToMap));
5070
+ return Object.entries(resultMap).map(([assetId, amount]) => ({ assetId, amount }));
5071
+ };
5072
+
5112
5073
  // src/utils/formatTransferToContractScriptData.ts
5113
5074
  var import_abi_coder6 = require("@fuel-ts/abi-coder");
5114
5075
  var import_math19 = require("@fuel-ts/math");
@@ -5449,9 +5410,8 @@ var Account = class extends import_interfaces.AbstractAccount {
5449
5410
  scriptData
5450
5411
  });
5451
5412
  request.addContractInputAndOutput(contractAddress);
5452
- const txCost = await this.provider.getTransactionCost(request, {
5453
- resourcesOwner: this,
5454
- quantitiesToContract: [{ amount: (0, import_math20.bn)(amount), assetId: String(assetIdToTransfer) }]
5413
+ const txCost = await this.getTransactionCost(request, {
5414
+ quantities: [{ amount: (0, import_math20.bn)(amount), assetId: String(assetIdToTransfer) }]
5455
5415
  });
5456
5416
  request = this.validateGasLimitAndMaxFee({
5457
5417
  transactionRequest: request,
@@ -5486,8 +5446,8 @@ var Account = class extends import_interfaces.AbstractAccount {
5486
5446
  const params = { script, ...txParams };
5487
5447
  const baseAssetId = this.provider.getBaseAssetId();
5488
5448
  let request = new ScriptTransactionRequest(params);
5489
- const quantitiesToContract = [{ amount: (0, import_math20.bn)(amount), assetId: baseAssetId }];
5490
- const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
5449
+ const quantities = [{ amount: (0, import_math20.bn)(amount), assetId: baseAssetId }];
5450
+ const txCost = await this.getTransactionCost(request, { quantities });
5491
5451
  request = this.validateGasLimitAndMaxFee({
5492
5452
  transactionRequest: request,
5493
5453
  gasUsed: txCost.gasUsed,
@@ -5497,6 +5457,34 @@ var Account = class extends import_interfaces.AbstractAccount {
5497
5457
  await this.fund(request, txCost);
5498
5458
  return this.sendTransaction(request);
5499
5459
  }
5460
+ /**
5461
+ * Returns a transaction cost to enable user
5462
+ * to set gasLimit and also reserve balance amounts
5463
+ * on the transaction.
5464
+ *
5465
+ * @param transactionRequestLike - The transaction request object.
5466
+ * @param transactionCostParams - The transaction cost parameters (optional).
5467
+ *
5468
+ * @returns A promise that resolves to the transaction cost object.
5469
+ */
5470
+ async getTransactionCost(transactionRequestLike, { signatureCallback, quantities = [] } = {}) {
5471
+ const txRequestClone = (0, import_ramda4.clone)(transactionRequestify(transactionRequestLike));
5472
+ const baseAssetId = this.provider.getBaseAssetId();
5473
+ const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
5474
+ const requiredQuantities = mergeQuantities(coinOutputsQuantities, quantities);
5475
+ const transactionFeeForDryRun = [{ assetId: baseAssetId, amount: (0, import_math20.bn)("100000000000000000") }];
5476
+ const resources = this.generateFakeResources(
5477
+ mergeQuantities(requiredQuantities, transactionFeeForDryRun)
5478
+ );
5479
+ txRequestClone.addResources(resources);
5480
+ const txCost = await this.provider.getTransactionCost(txRequestClone, {
5481
+ signatureCallback
5482
+ });
5483
+ return {
5484
+ ...txCost,
5485
+ requiredQuantities
5486
+ };
5487
+ }
5500
5488
  /**
5501
5489
  * Sign a message from the account via the connector.
5502
5490
  *
@@ -5533,7 +5521,7 @@ var Account = class extends import_interfaces.AbstractAccount {
5533
5521
  * @param sendTransactionParams - The provider send transaction parameters (optional).
5534
5522
  * @returns A promise that resolves to the transaction response.
5535
5523
  */
5536
- async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
5524
+ async sendTransaction(transactionRequestLike, { estimateTxDependencies = true } = {}) {
5537
5525
  if (this._connector) {
5538
5526
  return this.provider.getTransactionResponse(
5539
5527
  await this._connector.sendTransaction(this.address.toString(), transactionRequestLike)
@@ -5544,7 +5532,6 @@ var Account = class extends import_interfaces.AbstractAccount {
5544
5532
  await this.provider.estimateTxDependencies(transactionRequest);
5545
5533
  }
5546
5534
  return this.provider.sendTransaction(transactionRequest, {
5547
- awaitExecution,
5548
5535
  estimateTxDependencies: false
5549
5536
  });
5550
5537
  }
@@ -5589,9 +5576,7 @@ var Account = class extends import_interfaces.AbstractAccount {
5589
5576
  /** @hidden * */
5590
5577
  async estimateAndFundTransaction(transactionRequest, txParams) {
5591
5578
  let request = transactionRequest;
5592
- const txCost = await this.provider.getTransactionCost(request, {
5593
- resourcesOwner: this
5594
- });
5579
+ const txCost = await this.getTransactionCost(request);
5595
5580
  request = this.validateGasLimitAndMaxFee({
5596
5581
  transactionRequest: request,
5597
5582
  gasUsed: txCost.gasUsed,
@@ -5902,17 +5887,16 @@ var BaseWalletUnlocked = class extends Account {
5902
5887
  *
5903
5888
  * @param transactionRequestLike - The transaction request to send.
5904
5889
  * @param estimateTxDependencies - Whether to estimate the transaction dependencies.
5905
- * @param awaitExecution - Whether to wait for the transaction to be executed.
5906
5890
  * @returns A promise that resolves to the TransactionResponse object.
5907
5891
  */
5908
- async sendTransaction(transactionRequestLike, { estimateTxDependencies = false, awaitExecution } = {}) {
5892
+ async sendTransaction(transactionRequestLike, { estimateTxDependencies = false } = {}) {
5909
5893
  const transactionRequest = transactionRequestify(transactionRequestLike);
5910
5894
  if (estimateTxDependencies) {
5911
5895
  await this.provider.estimateTxDependencies(transactionRequest);
5912
5896
  }
5913
5897
  return this.provider.sendTransaction(
5914
5898
  await this.populateTransactionWitnessesSignature(transactionRequest),
5915
- { awaitExecution, estimateTxDependencies: false }
5899
+ { estimateTxDependencies: false }
5916
5900
  );
5917
5901
  }
5918
5902
  /**
@@ -8663,11 +8647,12 @@ var seedTestWallet = async (wallet, quantities, utxosAmount = 1) => {
8663
8647
  }
8664
8648
  })
8665
8649
  );
8666
- const txCost = await genesisWallet.provider.getTransactionCost(request);
8650
+ const txCost = await genesisWallet.getTransactionCost(request);
8667
8651
  request.gasLimit = txCost.gasUsed;
8668
8652
  request.maxFee = txCost.maxFee;
8669
8653
  await genesisWallet.fund(request, txCost);
8670
- await genesisWallet.sendTransaction(request, { awaitExecution: true });
8654
+ const submit = await genesisWallet.sendTransaction(request);
8655
+ await submit.waitForResult();
8671
8656
  };
8672
8657
 
8673
8658
  // src/test-utils/generateTestWallet.ts
@@ -8755,7 +8740,9 @@ var launchNode = async ({
8755
8740
  "--snapshot",
8756
8741
  "--consensus-key",
8757
8742
  "--db-type",
8758
- "--poa-instant"
8743
+ "--poa-instant",
8744
+ "--min-gas-price",
8745
+ "--native-executor-version"
8759
8746
  ]);
8760
8747
  const snapshotDir = getFlagValueFromArgs(args, "--snapshot");
8761
8748
  const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || import_utils37.defaultConsensusKey;
@@ -8764,6 +8751,7 @@ var launchNode = async ({
8764
8751
  const poaInstantFlagValue = getFlagValueFromArgs(args, "--poa-instant");
8765
8752
  const poaInstant = poaInstantFlagValue === "true" || poaInstantFlagValue === void 0;
8766
8753
  const nativeExecutorVersion = getFlagValueFromArgs(args, "--native-executor-version") || "0";
8754
+ const minGasPrice = getFlagValueFromArgs(args, "--min-gas-price") || "1";
8767
8755
  const graphQLStartSubstring = "Binding GraphQL provider to";
8768
8756
  const command = fuelCorePath || "fuel-core";
8769
8757
  const ipToUse = ip || "0.0.0.0";
@@ -8802,7 +8790,7 @@ var launchNode = async ({
8802
8790
  ["--ip", ipToUse],
8803
8791
  ["--port", portToUse],
8804
8792
  useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDir],
8805
- ["--min-gas-price", "1"],
8793
+ ["--min-gas-price", minGasPrice],
8806
8794
  poaInstant ? ["--poa-instant", "true"] : [],
8807
8795
  ["--native-executor-version", nativeExecutorVersion],
8808
8796
  ["--consensus-key", consensusKey],
@@ -8893,10 +8881,11 @@ var generateWallets = async (count, provider) => {
8893
8881
  };
8894
8882
  var launchNodeAndGetWallets = async ({
8895
8883
  launchNodeOptions,
8884
+ providerOptions,
8896
8885
  walletCount = 10
8897
8886
  } = {}) => {
8898
8887
  const { cleanup: closeNode, ip, port } = await launchNode(launchNodeOptions || {});
8899
- const provider = await Provider.create(`http://${ip}:${port}/v1/graphql`);
8888
+ const provider = await Provider.create(`http://${ip}:${port}/v1/graphql`, providerOptions);
8900
8889
  const wallets = await generateWallets(walletCount, provider);
8901
8890
  const cleanup = () => {
8902
8891
  closeNode();