@fuel-ts/account 0.0.0-rc-2037-20240411020051 → 0.0.0-rc-2034-20240411020813

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;
@@ -38863,8 +38864,8 @@ ${MessageCoinFragmentFragmentDoc}`;
38863
38864
  const predicateData = arrayify(value.predicateData ?? "0x");
38864
38865
  return {
38865
38866
  type: InputType.Coin,
38866
- txID: hexlify(arrayify(value.id).slice(0, 32)),
38867
- outputIndex: arrayify(value.id)[32],
38867
+ txID: hexlify(arrayify(value.id).slice(0, BYTES_32)),
38868
+ outputIndex: toNumber2(arrayify(value.id).slice(BYTES_32, UTXO_ID_LEN)),
38868
38869
  owner: hexlify(value.owner),
38869
38870
  amount: bn(value.amount),
38870
38871
  assetId: hexlify(value.assetId),
@@ -39744,8 +39745,8 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
39744
39745
  * @param predicate - Predicate bytes.
39745
39746
  * @param predicateData - Predicate data bytes.
39746
39747
  */
39747
- addCoinInput(coin) {
39748
- const { assetId, owner, amount, id, predicate } = coin;
39748
+ addCoinInput(coin, predicate) {
39749
+ const { assetId, owner, amount } = coin;
39749
39750
  let witnessIndex;
39750
39751
  if (predicate) {
39751
39752
  witnessIndex = 0;
@@ -39756,14 +39757,14 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
39756
39757
  }
39757
39758
  }
39758
39759
  const input = {
39759
- id,
39760
+ ...coin,
39760
39761
  type: InputType.Coin,
39761
39762
  owner: owner.toB256(),
39762
39763
  amount,
39763
39764
  assetId,
39764
39765
  txPointer: "0x00000000000000000000000000000000",
39765
39766
  witnessIndex,
39766
- predicate
39767
+ predicate: predicate?.bytes
39767
39768
  };
39768
39769
  this.pushInput(input);
39769
39770
  this.addChangeOutput(owner, assetId);
@@ -39776,8 +39777,8 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
39776
39777
  * @param predicate - Predicate bytes.
39777
39778
  * @param predicateData - Predicate data bytes.
39778
39779
  */
39779
- addMessageInput(message) {
39780
- const { recipient, sender, amount, predicate, nonce } = message;
39780
+ addMessageInput(message, predicate) {
39781
+ const { recipient, sender, amount } = message;
39781
39782
  const assetId = BaseAssetId;
39782
39783
  let witnessIndex;
39783
39784
  if (predicate) {
@@ -39789,13 +39790,13 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
39789
39790
  }
39790
39791
  }
39791
39792
  const input = {
39792
- nonce,
39793
+ ...message,
39793
39794
  type: InputType.Message,
39794
39795
  sender: sender.toB256(),
39795
39796
  recipient: recipient.toB256(),
39796
39797
  amount,
39797
39798
  witnessIndex,
39798
- predicate
39799
+ predicate: predicate?.bytes
39799
39800
  };
39800
39801
  this.pushInput(input);
39801
39802
  this.addChangeOutput(recipient, assetId);
@@ -39826,6 +39827,32 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
39826
39827
  resources.forEach((resource) => this.addResource(resource));
39827
39828
  return this;
39828
39829
  }
39830
+ /**
39831
+ * Adds multiple resources to the transaction by adding coin/message inputs and change
39832
+ * outputs from the related assetIds.
39833
+ *
39834
+ * @param resources - The resources to add.
39835
+ * @returns This transaction.
39836
+ */
39837
+ addPredicateResource(resource, predicate) {
39838
+ if (isCoin(resource)) {
39839
+ this.addCoinInput(resource, predicate);
39840
+ } else {
39841
+ this.addMessageInput(resource, predicate);
39842
+ }
39843
+ return this;
39844
+ }
39845
+ /**
39846
+ * Adds multiple predicate coin/message inputs to the transaction and change outputs
39847
+ * from the related assetIds.
39848
+ *
39849
+ * @param resources - The resources to add.
39850
+ * @returns This transaction.
39851
+ */
39852
+ addPredicateResources(resources, predicate) {
39853
+ resources.forEach((resource) => this.addPredicateResource(resource, predicate));
39854
+ return this;
39855
+ }
39829
39856
  /**
39830
39857
  * Adds a coin output to the transaction.
39831
39858
  *
@@ -39924,12 +39951,6 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
39924
39951
  * @param quantities - CoinQuantity Array.
39925
39952
  */
39926
39953
  fundWithFakeUtxos(quantities, resourcesOwner) {
39927
- let idCounter = 0;
39928
- const generateId = () => {
39929
- const counterString = String(idCounter++);
39930
- const id = ZeroBytes32.slice(0, -counterString.length).concat(counterString);
39931
- return id;
39932
- };
39933
39954
  const findAssetInput = (assetId) => this.inputs.find((input) => {
39934
39955
  if ("assetId" in input) {
39935
39956
  return input.assetId === assetId;
@@ -39939,12 +39960,12 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
39939
39960
  const updateAssetInput = (assetId, quantity) => {
39940
39961
  const assetInput = findAssetInput(assetId);
39941
39962
  if (assetInput && "assetId" in assetInput) {
39942
- assetInput.id = generateId();
39963
+ assetInput.id = hexlify(randomBytes22(UTXO_ID_LEN));
39943
39964
  assetInput.amount = quantity;
39944
39965
  } else {
39945
39966
  this.addResources([
39946
39967
  {
39947
- id: generateId(),
39968
+ id: hexlify(randomBytes22(UTXO_ID_LEN)),
39948
39969
  amount: quantity,
39949
39970
  assetId,
39950
39971
  owner: resourcesOwner || Address.fromRandom(),
@@ -41770,6 +41791,36 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
41770
41791
  missingContractIds
41771
41792
  };
41772
41793
  }
41794
+ /**
41795
+ * Estimates the transaction gas and fee based on the provided transaction request.
41796
+ * @param transactionRequest - The transaction request object.
41797
+ * @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
41798
+ */
41799
+ estimateTxGasAndFee(params) {
41800
+ const { transactionRequest } = params;
41801
+ const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
41802
+ const chainInfo = this.getChain();
41803
+ const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
41804
+ transactionRequest.gasPrice = gasPrice;
41805
+ const minGas = transactionRequest.calculateMinGas(chainInfo);
41806
+ const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
41807
+ if (transactionRequest.type === TransactionType.Script) {
41808
+ if (transactionRequest.gasLimit.eq(0)) {
41809
+ transactionRequest.gasLimit = minGas;
41810
+ transactionRequest.gasLimit = maxGasPerTx.sub(
41811
+ transactionRequest.calculateMaxGas(chainInfo, minGas)
41812
+ );
41813
+ }
41814
+ }
41815
+ const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
41816
+ const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
41817
+ return {
41818
+ minGas,
41819
+ minFee,
41820
+ maxGas,
41821
+ maxFee
41822
+ };
41823
+ }
41773
41824
  /**
41774
41825
  * Executes a signed transaction without applying the states changes
41775
41826
  * on the chain.
@@ -41817,17 +41868,16 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
41817
41868
  signatureCallback
41818
41869
  } = {}) {
41819
41870
  const txRequestClone = clone_default(transactionRequestify(transactionRequestLike));
41820
- const chainInfo = this.getChain();
41821
- const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
41822
- const gasPrice = max(txRequestClone.gasPrice, minGasPrice);
41871
+ const { minGasPrice } = this.getGasConfig();
41872
+ const setGasPrice = max(txRequestClone.gasPrice, minGasPrice);
41823
41873
  const isScriptTransaction = txRequestClone.type === TransactionType.Script;
41824
41874
  const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
41825
41875
  const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
41826
41876
  txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
41877
+ if (isScriptTransaction) {
41878
+ txRequestClone.gasLimit = bn(0);
41879
+ }
41827
41880
  if (estimatePredicates) {
41828
- if (isScriptTransaction) {
41829
- txRequestClone.gasLimit = bn(0);
41830
- }
41831
41881
  if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
41832
41882
  resourcesOwner.populateTransactionPredicateData(txRequestClone);
41833
41883
  }
@@ -41836,36 +41886,34 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
41836
41886
  if (signatureCallback && isScriptTransaction) {
41837
41887
  await signatureCallback(txRequestClone);
41838
41888
  }
41839
- const minGas = txRequestClone.calculateMinGas(chainInfo);
41840
- const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
41889
+ let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
41890
+ transactionRequest: txRequestClone
41891
+ });
41841
41892
  let receipts = [];
41842
41893
  let missingContractIds = [];
41843
41894
  let outputVariables = 0;
41895
+ let gasUsed = bn(0);
41844
41896
  if (isScriptTransaction && estimateTxDependencies) {
41845
41897
  txRequestClone.gasPrice = bn(0);
41846
- txRequestClone.gasLimit = bn(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
41847
41898
  const result = await this.estimateTxDependencies(txRequestClone);
41848
41899
  receipts = result.receipts;
41849
41900
  outputVariables = result.outputVariables;
41850
41901
  missingContractIds = result.missingContractIds;
41902
+ gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
41903
+ txRequestClone.gasLimit = gasUsed;
41904
+ txRequestClone.gasPrice = setGasPrice;
41905
+ ({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
41906
+ transactionRequest: txRequestClone
41907
+ }));
41851
41908
  }
41852
- const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
41853
- const usedFee = calculatePriceWithFactor(
41854
- gasUsed,
41855
- gasPrice,
41856
- gasPriceFactor
41857
- ).normalizeZeroToOne();
41858
- const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
41859
- const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
41860
41909
  return {
41861
41910
  requiredQuantities: allQuantities,
41862
41911
  receipts,
41863
41912
  gasUsed,
41864
41913
  minGasPrice,
41865
- gasPrice,
41914
+ gasPrice: setGasPrice,
41866
41915
  minGas,
41867
41916
  maxGas,
41868
- usedFee,
41869
41917
  minFee,
41870
41918
  maxFee,
41871
41919
  estimatedInputs: txRequestClone.inputs,
@@ -44319,12 +44367,12 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
44319
44367
  };
44320
44368
 
44321
44369
  // ../../node_modules/.pnpm/uuid@9.0.0/node_modules/uuid/dist/esm-node/rng.js
44322
- var import_crypto15 = __toESM(__require("crypto"));
44370
+ var import_crypto16 = __toESM(__require("crypto"));
44323
44371
  var rnds8Pool = new Uint8Array(256);
44324
44372
  var poolPtr = rnds8Pool.length;
44325
44373
  function rng() {
44326
44374
  if (poolPtr > rnds8Pool.length - 16) {
44327
- import_crypto15.default.randomFillSync(rnds8Pool);
44375
+ import_crypto16.default.randomFillSync(rnds8Pool);
44328
44376
  poolPtr = 0;
44329
44377
  }
44330
44378
  return rnds8Pool.slice(poolPtr, poolPtr += 16);
@@ -44340,9 +44388,9 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
44340
44388
  }
44341
44389
 
44342
44390
  // ../../node_modules/.pnpm/uuid@9.0.0/node_modules/uuid/dist/esm-node/native.js
44343
- var import_crypto16 = __toESM(__require("crypto"));
44391
+ var import_crypto17 = __toESM(__require("crypto"));
44344
44392
  var native_default = {
44345
- randomUUID: import_crypto16.default.randomUUID
44393
+ randomUUID: import_crypto17.default.randomUUID
44346
44394
  };
44347
44395
 
44348
44396
  // ../../node_modules/.pnpm/uuid@9.0.0/node_modules/uuid/dist/esm-node/v4.js
@@ -47805,7 +47853,6 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
47805
47853
  if (input.type === InputType.Coin && hexlify(input.owner) === this.address.toB256()) {
47806
47854
  input.predicate = this.bytes;
47807
47855
  input.predicateData = this.getPredicateData(policies.length);
47808
- input.witnessIndex = 0;
47809
47856
  }
47810
47857
  });
47811
47858
  return request;
@@ -47843,20 +47890,6 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
47843
47890
  const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
47844
47891
  return super.simulateTransaction(transactionRequest);
47845
47892
  }
47846
- /**
47847
- * Retrieves resources satisfying the spend query for the account.
47848
- *
47849
- * @param quantities - IDs of coins to exclude.
47850
- * @param excludedIds - IDs of resources to be excluded from the query.
47851
- * @returns A promise that resolves to an array of Resources.
47852
- */
47853
- async getResourcesToSpend(quantities, excludedIds) {
47854
- const resources = await super.getResourcesToSpend(quantities, excludedIds);
47855
- return resources.map((resource) => ({
47856
- ...resource,
47857
- predicate: hexlify(this.bytes)
47858
- }));
47859
- }
47860
47893
  getPredicateData(policiesLength) {
47861
47894
  if (!this.predicateData.length) {
47862
47895
  return new Uint8Array();