@fuel-ts/account 0.96.0 → 0.96.1

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.
@@ -1199,6 +1199,17 @@ var IsUserAccountDocument = gql`
1199
1199
  }
1200
1200
  }
1201
1201
  `;
1202
+ var GetConsensusParametersVersionDocument = gql`
1203
+ query getConsensusParametersVersion {
1204
+ chain {
1205
+ latestBlock {
1206
+ header {
1207
+ consensusParametersVersion
1208
+ }
1209
+ }
1210
+ }
1211
+ }
1212
+ `;
1202
1213
  var SubmitAndAwaitDocument = gql`
1203
1214
  subscription submitAndAwait($encodedTransaction: HexString!) {
1204
1215
  submitAndAwait(tx: $encodedTransaction) {
@@ -1318,6 +1329,9 @@ function getSdk(requester) {
1318
1329
  isUserAccount(variables, options) {
1319
1330
  return requester(IsUserAccountDocument, variables, options);
1320
1331
  },
1332
+ getConsensusParametersVersion(variables, options) {
1333
+ return requester(GetConsensusParametersVersionDocument, variables, options);
1334
+ },
1321
1335
  submitAndAwait(variables, options) {
1322
1336
  return requester(SubmitAndAwaitDocument, variables, options);
1323
1337
  },
@@ -4523,6 +4537,7 @@ var RESOURCES_PAGE_SIZE_LIMIT = 512;
4523
4537
  var TRANSACTIONS_PAGE_SIZE_LIMIT = 60;
4524
4538
  var BLOCKS_PAGE_SIZE_LIMIT = 5;
4525
4539
  var DEFAULT_RESOURCE_CACHE_TTL = 2e4;
4540
+ var GAS_USED_MODIFIER = 1.2;
4526
4541
  var processGqlChain = (chain) => {
4527
4542
  const { name, daHeight, consensusParameters } = chain;
4528
4543
  const {
@@ -4598,6 +4613,8 @@ var _Provider = class {
4598
4613
  __publicField(this, "url");
4599
4614
  /** @hidden */
4600
4615
  __publicField(this, "urlWithoutAuth");
4616
+ /** @hidden */
4617
+ __publicField(this, "consensusParametersTimestamp");
4601
4618
  __publicField(this, "options", {
4602
4619
  timeout: void 0,
4603
4620
  resourceCacheTTL: void 0,
@@ -4750,16 +4767,19 @@ var _Provider = class {
4750
4767
  }
4751
4768
  /**
4752
4769
  * Return the chain and node information.
4753
- *
4770
+ * @param ignoreCache - If true, ignores the cache and re-fetch configs.
4754
4771
  * @returns A promise that resolves to the Chain and NodeInfo.
4755
4772
  */
4756
- async fetchChainAndNodeInfo() {
4773
+ async fetchChainAndNodeInfo(ignoreCache = false) {
4757
4774
  let nodeInfo;
4758
4775
  let chain;
4759
4776
  try {
4777
+ if (ignoreCache) {
4778
+ throw new Error(`Jumps to the catch block andre-fetch`);
4779
+ }
4760
4780
  nodeInfo = this.getNode();
4761
4781
  chain = this.getChain();
4762
- } catch (error) {
4782
+ } catch (_err) {
4763
4783
  const data = await this.operations.getChainAndNodeInfo();
4764
4784
  nodeInfo = {
4765
4785
  maxDepth: bn17(data.nodeInfo.maxDepth),
@@ -4772,6 +4792,7 @@ var _Provider = class {
4772
4792
  chain = processGqlChain(data.chain);
4773
4793
  _Provider.chainInfoCache[this.urlWithoutAuth] = chain;
4774
4794
  _Provider.nodeInfoCache[this.urlWithoutAuth] = nodeInfo;
4795
+ this.consensusParametersTimestamp = Date.now();
4775
4796
  }
4776
4797
  return {
4777
4798
  chain,
@@ -4921,18 +4942,25 @@ Supported fuel-core version: ${supportedVersion}.`
4921
4942
  } = this.getChain();
4922
4943
  return baseAssetId;
4923
4944
  }
4924
- validateTransaction(tx, consensusParameters) {
4925
- const { maxOutputs, maxInputs } = consensusParameters.txParameters;
4945
+ /**
4946
+ * @hidden
4947
+ */
4948
+ validateTransaction(tx) {
4949
+ const {
4950
+ consensusParameters: {
4951
+ txParameters: { maxInputs, maxOutputs }
4952
+ }
4953
+ } = this.getChain();
4926
4954
  if (bn17(tx.inputs.length).gt(maxInputs)) {
4927
4955
  throw new FuelError17(
4928
4956
  ErrorCode14.MAX_INPUTS_EXCEEDED,
4929
- "The transaction exceeds the maximum allowed number of inputs."
4957
+ `The transaction exceeds the maximum allowed number of inputs. Tx inputs: ${tx.inputs.length}, max inputs: ${maxInputs}`
4930
4958
  );
4931
4959
  }
4932
4960
  if (bn17(tx.outputs.length).gt(maxOutputs)) {
4933
4961
  throw new FuelError17(
4934
4962
  ErrorCode14.MAX_OUTPUTS_EXCEEDED,
4935
- "The transaction exceeds the maximum allowed number of outputs."
4963
+ `The transaction exceeds the maximum allowed number of outputs. Tx outputs: ${tx.outputs.length}, max outputs: ${maxOutputs}`
4936
4964
  );
4937
4965
  }
4938
4966
  }
@@ -4951,8 +4979,7 @@ Supported fuel-core version: ${supportedVersion}.`
4951
4979
  if (estimateTxDependencies) {
4952
4980
  await this.estimateTxDependencies(transactionRequest);
4953
4981
  }
4954
- const { consensusParameters } = this.getChain();
4955
- this.validateTransaction(transactionRequest, consensusParameters);
4982
+ this.validateTransaction(transactionRequest);
4956
4983
  const encodedTransaction = hexlify17(transactionRequest.toTransactionBytes());
4957
4984
  let abis;
4958
4985
  if (isTransactionTypeScript(transactionRequest)) {
@@ -5040,6 +5067,7 @@ Supported fuel-core version: ${supportedVersion}.`
5040
5067
  const missingContractIds = [];
5041
5068
  let outputVariables = 0;
5042
5069
  let dryRunStatus;
5070
+ this.validateTransaction(transactionRequest);
5043
5071
  for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
5044
5072
  const {
5045
5073
  dryRun: [{ receipts: rawReceipts, status }]
@@ -5162,6 +5190,27 @@ Supported fuel-core version: ${supportedVersion}.`
5162
5190
  });
5163
5191
  return results;
5164
5192
  }
5193
+ async autoRefetchConfigs() {
5194
+ const now = Date.now();
5195
+ const diff = now - (this.consensusParametersTimestamp ?? 0);
5196
+ if (diff < 6e4) {
5197
+ return;
5198
+ }
5199
+ const chainInfo = this.getChain();
5200
+ const {
5201
+ consensusParameters: { version: previous }
5202
+ } = chainInfo;
5203
+ const {
5204
+ chain: {
5205
+ latestBlock: {
5206
+ header: { consensusParametersVersion: current }
5207
+ }
5208
+ }
5209
+ } = await this.operations.getConsensusParametersVersion();
5210
+ if (previous !== current) {
5211
+ await this.fetchChainAndNodeInfo(true);
5212
+ }
5213
+ }
5165
5214
  /**
5166
5215
  * Estimates the transaction gas and fee based on the provided transaction request.
5167
5216
  * @param transactionRequest - The transaction request object.
@@ -5170,6 +5219,7 @@ Supported fuel-core version: ${supportedVersion}.`
5170
5219
  async estimateTxGasAndFee(params) {
5171
5220
  const { transactionRequest } = params;
5172
5221
  let { gasPrice } = params;
5222
+ await this.autoRefetchConfigs();
5173
5223
  const chainInfo = this.getChain();
5174
5224
  const { gasPriceFactor, maxGasPerTx } = this.getGasConfig();
5175
5225
  const minGas = transactionRequest.calculateMinGas(chainInfo);
@@ -5283,7 +5333,9 @@ Supported fuel-core version: ${supportedVersion}.`
5283
5333
  if (dryRunStatus && "reason" in dryRunStatus) {
5284
5334
  throw this.extractDryRunError(txRequestClone, receipts, dryRunStatus);
5285
5335
  }
5286
- gasUsed = getGasUsedFromReceipts(receipts);
5336
+ const { maxGasPerTx } = this.getGasConfig();
5337
+ const pristineGasUsed = getGasUsedFromReceipts(receipts);
5338
+ gasUsed = bn17(pristineGasUsed.muln(GAS_USED_MODIFIER)).max(maxGasPerTx.sub(minGas));
5287
5339
  txRequestClone.gasLimit = gasUsed;
5288
5340
  ({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
5289
5341
  transactionRequest: txRequestClone,
@@ -6876,6 +6928,7 @@ var Account = class extends AbstractAccount {
6876
6928
  `The account ${this.address} does not have enough base asset funds to cover the transaction execution.`
6877
6929
  );
6878
6930
  }
6931
+ this.provider.validateTransaction(request);
6879
6932
  request.updatePredicateGasUsed(estimatedPredicates);
6880
6933
  const requestToReestimate = clone9(request);
6881
6934
  if (addedSignatures) {