@fuel-ts/account 0.0.0-rc-2040-20240415161844 → 0.0.0-rc-2034-20240415163000

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.

@@ -31605,6 +31605,7 @@ This unreleased fuel-core build may include features and updates not yet support
31605
31605
  var ENCODING_V1 = "1";
31606
31606
  var WORD_SIZE = 8;
31607
31607
  var BYTES_32 = 32;
31608
+ var UTXO_ID_LEN = BYTES_32 + 1;
31608
31609
  var ASSET_ID_LEN = BYTES_32;
31609
31610
  var ADDRESS_LEN = BYTES_32;
31610
31611
  var NONCE_LEN = BYTES_32;
@@ -38873,8 +38874,8 @@ ${MessageCoinFragmentFragmentDoc}`;
38873
38874
  const predicateData = arrayify(value.predicateData ?? "0x");
38874
38875
  return {
38875
38876
  type: InputType.Coin,
38876
- txID: hexlify(arrayify(value.id).slice(0, 32)),
38877
- outputIndex: arrayify(value.id)[32],
38877
+ txID: hexlify(arrayify(value.id).slice(0, BYTES_32)),
38878
+ outputIndex: toNumber2(arrayify(value.id).slice(BYTES_32, UTXO_ID_LEN)),
38878
38879
  owner: hexlify(value.owner),
38879
38880
  amount: bn(value.amount),
38880
38881
  assetId: hexlify(value.assetId),
@@ -39960,12 +39961,6 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
39960
39961
  * @param quantities - CoinQuantity Array.
39961
39962
  */
39962
39963
  fundWithFakeUtxos(quantities, resourcesOwner) {
39963
- let idCounter = 0;
39964
- const generateId = () => {
39965
- const counterString = String(idCounter++);
39966
- const id = ZeroBytes32.slice(0, -counterString.length).concat(counterString);
39967
- return id;
39968
- };
39969
39964
  const findAssetInput = (assetId) => this.inputs.find((input) => {
39970
39965
  if ("assetId" in input) {
39971
39966
  return input.assetId === assetId;
@@ -39975,12 +39970,12 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
39975
39970
  const updateAssetInput = (assetId, quantity) => {
39976
39971
  const assetInput = findAssetInput(assetId);
39977
39972
  if (assetInput && "assetId" in assetInput) {
39978
- assetInput.id = generateId();
39973
+ assetInput.id = hexlify(randomBytes22(UTXO_ID_LEN));
39979
39974
  assetInput.amount = quantity;
39980
39975
  } else {
39981
39976
  this.addResources([
39982
39977
  {
39983
- id: generateId(),
39978
+ id: hexlify(randomBytes22(UTXO_ID_LEN)),
39984
39979
  amount: quantity,
39985
39980
  assetId,
39986
39981
  owner: resourcesOwner || Address.fromRandom(),
@@ -41806,6 +41801,36 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
41806
41801
  missingContractIds
41807
41802
  };
41808
41803
  }
41804
+ /**
41805
+ * Estimates the transaction gas and fee based on the provided transaction request.
41806
+ * @param transactionRequest - The transaction request object.
41807
+ * @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
41808
+ */
41809
+ estimateTxGasAndFee(params) {
41810
+ const { transactionRequest } = params;
41811
+ const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
41812
+ const chainInfo = this.getChain();
41813
+ const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
41814
+ transactionRequest.gasPrice = gasPrice;
41815
+ const minGas = transactionRequest.calculateMinGas(chainInfo);
41816
+ const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
41817
+ if (transactionRequest.type === TransactionType.Script) {
41818
+ if (transactionRequest.gasLimit.eq(0)) {
41819
+ transactionRequest.gasLimit = minGas;
41820
+ transactionRequest.gasLimit = maxGasPerTx.sub(
41821
+ transactionRequest.calculateMaxGas(chainInfo, minGas)
41822
+ );
41823
+ }
41824
+ }
41825
+ const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
41826
+ const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
41827
+ return {
41828
+ minGas,
41829
+ minFee,
41830
+ maxGas,
41831
+ maxFee
41832
+ };
41833
+ }
41809
41834
  /**
41810
41835
  * Executes a signed transaction without applying the states changes
41811
41836
  * on the chain.
@@ -41853,17 +41878,16 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
41853
41878
  signatureCallback
41854
41879
  } = {}) {
41855
41880
  const txRequestClone = clone_default(transactionRequestify(transactionRequestLike));
41856
- const chainInfo = this.getChain();
41857
- const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
41858
- const gasPrice = max(txRequestClone.gasPrice, minGasPrice);
41881
+ const { minGasPrice } = this.getGasConfig();
41882
+ const setGasPrice = max(txRequestClone.gasPrice, minGasPrice);
41859
41883
  const isScriptTransaction = txRequestClone.type === TransactionType.Script;
41860
41884
  const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
41861
41885
  const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
41862
41886
  txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
41887
+ if (isScriptTransaction) {
41888
+ txRequestClone.gasLimit = bn(0);
41889
+ }
41863
41890
  if (estimatePredicates) {
41864
- if (isScriptTransaction) {
41865
- txRequestClone.gasLimit = bn(0);
41866
- }
41867
41891
  if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
41868
41892
  resourcesOwner.populateTransactionPredicateData(txRequestClone);
41869
41893
  }
@@ -41872,36 +41896,34 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
41872
41896
  if (signatureCallback && isScriptTransaction) {
41873
41897
  await signatureCallback(txRequestClone);
41874
41898
  }
41875
- const minGas = txRequestClone.calculateMinGas(chainInfo);
41876
- const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
41899
+ let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
41900
+ transactionRequest: txRequestClone
41901
+ });
41877
41902
  let receipts = [];
41878
41903
  let missingContractIds = [];
41879
41904
  let outputVariables = 0;
41905
+ let gasUsed = bn(0);
41880
41906
  if (isScriptTransaction && estimateTxDependencies) {
41881
41907
  txRequestClone.gasPrice = bn(0);
41882
- txRequestClone.gasLimit = bn(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
41883
41908
  const result = await this.estimateTxDependencies(txRequestClone);
41884
41909
  receipts = result.receipts;
41885
41910
  outputVariables = result.outputVariables;
41886
41911
  missingContractIds = result.missingContractIds;
41912
+ gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
41913
+ txRequestClone.gasLimit = gasUsed;
41914
+ txRequestClone.gasPrice = setGasPrice;
41915
+ ({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
41916
+ transactionRequest: txRequestClone
41917
+ }));
41887
41918
  }
41888
- const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
41889
- const usedFee = calculatePriceWithFactor(
41890
- gasUsed,
41891
- gasPrice,
41892
- gasPriceFactor
41893
- ).normalizeZeroToOne();
41894
- const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
41895
- const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
41896
41919
  return {
41897
41920
  requiredQuantities: allQuantities,
41898
41921
  receipts,
41899
41922
  gasUsed,
41900
41923
  minGasPrice,
41901
- gasPrice,
41924
+ gasPrice: setGasPrice,
41902
41925
  minGas,
41903
41926
  maxGas,
41904
- usedFee,
41905
41927
  minFee,
41906
41928
  maxFee,
41907
41929
  estimatedInputs: txRequestClone.inputs,
@@ -44355,12 +44377,12 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
44355
44377
  };
44356
44378
 
44357
44379
  // ../../node_modules/.pnpm/uuid@9.0.0/node_modules/uuid/dist/esm-node/rng.js
44358
- var import_crypto15 = __toESM(__require("crypto"));
44380
+ var import_crypto16 = __toESM(__require("crypto"));
44359
44381
  var rnds8Pool = new Uint8Array(256);
44360
44382
  var poolPtr = rnds8Pool.length;
44361
44383
  function rng() {
44362
44384
  if (poolPtr > rnds8Pool.length - 16) {
44363
- import_crypto15.default.randomFillSync(rnds8Pool);
44385
+ import_crypto16.default.randomFillSync(rnds8Pool);
44364
44386
  poolPtr = 0;
44365
44387
  }
44366
44388
  return rnds8Pool.slice(poolPtr, poolPtr += 16);
@@ -44376,9 +44398,9 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
44376
44398
  }
44377
44399
 
44378
44400
  // ../../node_modules/.pnpm/uuid@9.0.0/node_modules/uuid/dist/esm-node/native.js
44379
- var import_crypto16 = __toESM(__require("crypto"));
44401
+ var import_crypto17 = __toESM(__require("crypto"));
44380
44402
  var native_default = {
44381
- randomUUID: import_crypto16.default.randomUUID
44403
+ randomUUID: import_crypto17.default.randomUUID
44382
44404
  };
44383
44405
 
44384
44406
  // ../../node_modules/.pnpm/uuid@9.0.0/node_modules/uuid/dist/esm-node/v4.js