@fuel-ts/account 0.0.0-rc-2034-20240411123358 → 0.0.0-rc-2037-20240411135757

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,7 +31605,6 @@ 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;
31609
31608
  var ASSET_ID_LEN = BYTES_32;
31610
31609
  var ADDRESS_LEN = BYTES_32;
31611
31610
  var NONCE_LEN = BYTES_32;
@@ -38874,8 +38873,8 @@ ${MessageCoinFragmentFragmentDoc}`;
38874
38873
  const predicateData = arrayify(value.predicateData ?? "0x");
38875
38874
  return {
38876
38875
  type: InputType.Coin,
38877
- txID: hexlify(arrayify(value.id).slice(0, BYTES_32)),
38878
- outputIndex: toNumber2(arrayify(value.id).slice(BYTES_32, UTXO_ID_LEN)),
38876
+ txID: hexlify(arrayify(value.id).slice(0, 32)),
38877
+ outputIndex: arrayify(value.id)[32],
38879
38878
  owner: hexlify(value.owner),
38880
38879
  amount: bn(value.amount),
38881
38880
  assetId: hexlify(value.assetId),
@@ -39755,8 +39754,8 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
39755
39754
  * @param predicate - Predicate bytes.
39756
39755
  * @param predicateData - Predicate data bytes.
39757
39756
  */
39758
- addCoinInput(coin, predicate) {
39759
- const { assetId, owner, amount } = coin;
39757
+ addCoinInput(coin) {
39758
+ const { assetId, owner, amount, id, predicate } = coin;
39760
39759
  let witnessIndex;
39761
39760
  if (predicate) {
39762
39761
  witnessIndex = 0;
@@ -39767,14 +39766,14 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
39767
39766
  }
39768
39767
  }
39769
39768
  const input = {
39770
- ...coin,
39769
+ id,
39771
39770
  type: InputType.Coin,
39772
39771
  owner: owner.toB256(),
39773
39772
  amount,
39774
39773
  assetId,
39775
39774
  txPointer: "0x00000000000000000000000000000000",
39776
39775
  witnessIndex,
39777
- predicate: predicate?.bytes
39776
+ predicate
39778
39777
  };
39779
39778
  this.pushInput(input);
39780
39779
  this.addChangeOutput(owner, assetId);
@@ -39787,8 +39786,8 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
39787
39786
  * @param predicate - Predicate bytes.
39788
39787
  * @param predicateData - Predicate data bytes.
39789
39788
  */
39790
- addMessageInput(message, predicate) {
39791
- const { recipient, sender, amount } = message;
39789
+ addMessageInput(message) {
39790
+ const { recipient, sender, amount, predicate, nonce } = message;
39792
39791
  const assetId = BaseAssetId;
39793
39792
  let witnessIndex;
39794
39793
  if (predicate) {
@@ -39800,13 +39799,13 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
39800
39799
  }
39801
39800
  }
39802
39801
  const input = {
39803
- ...message,
39802
+ nonce,
39804
39803
  type: InputType.Message,
39805
39804
  sender: sender.toB256(),
39806
39805
  recipient: recipient.toB256(),
39807
39806
  amount,
39808
39807
  witnessIndex,
39809
- predicate: predicate?.bytes
39808
+ predicate
39810
39809
  };
39811
39810
  this.pushInput(input);
39812
39811
  this.addChangeOutput(recipient, assetId);
@@ -39837,32 +39836,6 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
39837
39836
  resources.forEach((resource) => this.addResource(resource));
39838
39837
  return this;
39839
39838
  }
39840
- /**
39841
- * Adds multiple resources to the transaction by adding coin/message inputs and change
39842
- * outputs from the related assetIds.
39843
- *
39844
- * @param resources - The resources to add.
39845
- * @returns This transaction.
39846
- */
39847
- addPredicateResource(resource, predicate) {
39848
- if (isCoin(resource)) {
39849
- this.addCoinInput(resource, predicate);
39850
- } else {
39851
- this.addMessageInput(resource, predicate);
39852
- }
39853
- return this;
39854
- }
39855
- /**
39856
- * Adds multiple predicate coin/message inputs to the transaction and change outputs
39857
- * from the related assetIds.
39858
- *
39859
- * @param resources - The resources to add.
39860
- * @returns This transaction.
39861
- */
39862
- addPredicateResources(resources, predicate) {
39863
- resources.forEach((resource) => this.addPredicateResource(resource, predicate));
39864
- return this;
39865
- }
39866
39839
  /**
39867
39840
  * Adds a coin output to the transaction.
39868
39841
  *
@@ -39961,6 +39934,12 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
39961
39934
  * @param quantities - CoinQuantity Array.
39962
39935
  */
39963
39936
  fundWithFakeUtxos(quantities, resourcesOwner) {
39937
+ let idCounter = 0;
39938
+ const generateId = () => {
39939
+ const counterString = String(idCounter++);
39940
+ const id = ZeroBytes32.slice(0, -counterString.length).concat(counterString);
39941
+ return id;
39942
+ };
39964
39943
  const findAssetInput = (assetId) => this.inputs.find((input) => {
39965
39944
  if ("assetId" in input) {
39966
39945
  return input.assetId === assetId;
@@ -39970,12 +39949,12 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
39970
39949
  const updateAssetInput = (assetId, quantity) => {
39971
39950
  const assetInput = findAssetInput(assetId);
39972
39951
  if (assetInput && "assetId" in assetInput) {
39973
- assetInput.id = hexlify(randomBytes22(UTXO_ID_LEN));
39952
+ assetInput.id = generateId();
39974
39953
  assetInput.amount = quantity;
39975
39954
  } else {
39976
39955
  this.addResources([
39977
39956
  {
39978
- id: hexlify(randomBytes22(UTXO_ID_LEN)),
39957
+ id: generateId(),
39979
39958
  amount: quantity,
39980
39959
  assetId,
39981
39960
  owner: resourcesOwner || Address.fromRandom(),
@@ -41801,36 +41780,6 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
41801
41780
  missingContractIds
41802
41781
  };
41803
41782
  }
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
- }
41834
41783
  /**
41835
41784
  * Executes a signed transaction without applying the states changes
41836
41785
  * on the chain.
@@ -41878,16 +41827,17 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
41878
41827
  signatureCallback
41879
41828
  } = {}) {
41880
41829
  const txRequestClone = clone_default(transactionRequestify(transactionRequestLike));
41881
- const { minGasPrice } = this.getGasConfig();
41882
- const setGasPrice = max(txRequestClone.gasPrice, minGasPrice);
41830
+ const chainInfo = this.getChain();
41831
+ const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
41832
+ const gasPrice = max(txRequestClone.gasPrice, minGasPrice);
41883
41833
  const isScriptTransaction = txRequestClone.type === TransactionType.Script;
41884
41834
  const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
41885
41835
  const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
41886
41836
  txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
41887
- if (isScriptTransaction) {
41888
- txRequestClone.gasLimit = bn(0);
41889
- }
41890
41837
  if (estimatePredicates) {
41838
+ if (isScriptTransaction) {
41839
+ txRequestClone.gasLimit = bn(0);
41840
+ }
41891
41841
  if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
41892
41842
  resourcesOwner.populateTransactionPredicateData(txRequestClone);
41893
41843
  }
@@ -41896,34 +41846,36 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
41896
41846
  if (signatureCallback && isScriptTransaction) {
41897
41847
  await signatureCallback(txRequestClone);
41898
41848
  }
41899
- let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
41900
- transactionRequest: txRequestClone
41901
- });
41849
+ const minGas = txRequestClone.calculateMinGas(chainInfo);
41850
+ const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
41902
41851
  let receipts = [];
41903
41852
  let missingContractIds = [];
41904
41853
  let outputVariables = 0;
41905
- let gasUsed = bn(0);
41906
41854
  if (isScriptTransaction && estimateTxDependencies) {
41907
41855
  txRequestClone.gasPrice = bn(0);
41856
+ txRequestClone.gasLimit = bn(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
41908
41857
  const result = await this.estimateTxDependencies(txRequestClone);
41909
41858
  receipts = result.receipts;
41910
41859
  outputVariables = result.outputVariables;
41911
41860
  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
- }));
41918
41861
  }
41862
+ const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
41863
+ const usedFee = calculatePriceWithFactor(
41864
+ gasUsed,
41865
+ gasPrice,
41866
+ gasPriceFactor
41867
+ ).normalizeZeroToOne();
41868
+ const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
41869
+ const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
41919
41870
  return {
41920
41871
  requiredQuantities: allQuantities,
41921
41872
  receipts,
41922
41873
  gasUsed,
41923
41874
  minGasPrice,
41924
- gasPrice: setGasPrice,
41875
+ gasPrice,
41925
41876
  minGas,
41926
41877
  maxGas,
41878
+ usedFee,
41927
41879
  minFee,
41928
41880
  maxFee,
41929
41881
  estimatedInputs: txRequestClone.inputs,
@@ -44377,12 +44329,12 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
44377
44329
  };
44378
44330
 
44379
44331
  // ../../node_modules/.pnpm/uuid@9.0.0/node_modules/uuid/dist/esm-node/rng.js
44380
- var import_crypto16 = __toESM(__require("crypto"));
44332
+ var import_crypto15 = __toESM(__require("crypto"));
44381
44333
  var rnds8Pool = new Uint8Array(256);
44382
44334
  var poolPtr = rnds8Pool.length;
44383
44335
  function rng() {
44384
44336
  if (poolPtr > rnds8Pool.length - 16) {
44385
- import_crypto16.default.randomFillSync(rnds8Pool);
44337
+ import_crypto15.default.randomFillSync(rnds8Pool);
44386
44338
  poolPtr = 0;
44387
44339
  }
44388
44340
  return rnds8Pool.slice(poolPtr, poolPtr += 16);
@@ -44398,9 +44350,9 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
44398
44350
  }
44399
44351
 
44400
44352
  // ../../node_modules/.pnpm/uuid@9.0.0/node_modules/uuid/dist/esm-node/native.js
44401
- var import_crypto17 = __toESM(__require("crypto"));
44353
+ var import_crypto16 = __toESM(__require("crypto"));
44402
44354
  var native_default = {
44403
- randomUUID: import_crypto17.default.randomUUID
44355
+ randomUUID: import_crypto16.default.randomUUID
44404
44356
  };
44405
44357
 
44406
44358
  // ../../node_modules/.pnpm/uuid@9.0.0/node_modules/uuid/dist/esm-node/v4.js
@@ -47863,6 +47815,7 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
47863
47815
  if (input.type === InputType.Coin && hexlify(input.owner) === this.address.toB256()) {
47864
47816
  input.predicate = this.bytes;
47865
47817
  input.predicateData = this.getPredicateData(policies.length);
47818
+ input.witnessIndex = 0;
47866
47819
  }
47867
47820
  });
47868
47821
  return request;
@@ -47900,6 +47853,20 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
47900
47853
  const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
47901
47854
  return super.simulateTransaction(transactionRequest);
47902
47855
  }
47856
+ /**
47857
+ * Retrieves resources satisfying the spend query for the account.
47858
+ *
47859
+ * @param quantities - IDs of coins to exclude.
47860
+ * @param excludedIds - IDs of resources to be excluded from the query.
47861
+ * @returns A promise that resolves to an array of Resources.
47862
+ */
47863
+ async getResourcesToSpend(quantities, excludedIds) {
47864
+ const resources = await super.getResourcesToSpend(quantities, excludedIds);
47865
+ return resources.map((resource) => ({
47866
+ ...resource,
47867
+ predicate: hexlify(this.bytes)
47868
+ }));
47869
+ }
47903
47870
  getPredicateData(policiesLength) {
47904
47871
  if (!this.predicateData.length) {
47905
47872
  return new Uint8Array();