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

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.

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