@fuel-ts/account 0.0.0-rc-2034-20240410182856 → 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.
- package/dist/index.global.js +56 -89
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +93 -128
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +59 -94
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts +9 -1
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/coin.d.ts +2 -1
- package/dist/providers/coin.d.ts.map +1 -1
- package/dist/providers/message.d.ts +1 -0
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +2 -13
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/input.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +2 -20
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/test-utils.global.js +43 -91
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +75 -125
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +46 -96
- package/dist/test-utils.mjs.map +1 -1
- package/package.json +16 -16
package/dist/index.global.js
CHANGED
@@ -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;
|
@@ -38864,8 +38863,8 @@ ${MessageCoinFragmentFragmentDoc}`;
|
|
38864
38863
|
const predicateData = arrayify(value.predicateData ?? "0x");
|
38865
38864
|
return {
|
38866
38865
|
type: InputType.Coin,
|
38867
|
-
txID: hexlify(arrayify(value.id).slice(0,
|
38868
|
-
outputIndex:
|
38866
|
+
txID: hexlify(arrayify(value.id).slice(0, 32)),
|
38867
|
+
outputIndex: arrayify(value.id)[32],
|
38869
38868
|
owner: hexlify(value.owner),
|
38870
38869
|
amount: bn(value.amount),
|
38871
38870
|
assetId: hexlify(value.assetId),
|
@@ -39745,8 +39744,8 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
|
|
39745
39744
|
* @param predicate - Predicate bytes.
|
39746
39745
|
* @param predicateData - Predicate data bytes.
|
39747
39746
|
*/
|
39748
|
-
addCoinInput(coin
|
39749
|
-
const { assetId, owner, amount } = coin;
|
39747
|
+
addCoinInput(coin) {
|
39748
|
+
const { assetId, owner, amount, id, predicate } = coin;
|
39750
39749
|
let witnessIndex;
|
39751
39750
|
if (predicate) {
|
39752
39751
|
witnessIndex = 0;
|
@@ -39757,14 +39756,14 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
|
|
39757
39756
|
}
|
39758
39757
|
}
|
39759
39758
|
const input = {
|
39760
|
-
|
39759
|
+
id,
|
39761
39760
|
type: InputType.Coin,
|
39762
39761
|
owner: owner.toB256(),
|
39763
39762
|
amount,
|
39764
39763
|
assetId,
|
39765
39764
|
txPointer: "0x00000000000000000000000000000000",
|
39766
39765
|
witnessIndex,
|
39767
|
-
predicate
|
39766
|
+
predicate
|
39768
39767
|
};
|
39769
39768
|
this.pushInput(input);
|
39770
39769
|
this.addChangeOutput(owner, assetId);
|
@@ -39777,8 +39776,8 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
|
|
39777
39776
|
* @param predicate - Predicate bytes.
|
39778
39777
|
* @param predicateData - Predicate data bytes.
|
39779
39778
|
*/
|
39780
|
-
addMessageInput(message
|
39781
|
-
const { recipient, sender, amount } = message;
|
39779
|
+
addMessageInput(message) {
|
39780
|
+
const { recipient, sender, amount, predicate, nonce } = message;
|
39782
39781
|
const assetId = BaseAssetId;
|
39783
39782
|
let witnessIndex;
|
39784
39783
|
if (predicate) {
|
@@ -39790,13 +39789,13 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
|
|
39790
39789
|
}
|
39791
39790
|
}
|
39792
39791
|
const input = {
|
39793
|
-
|
39792
|
+
nonce,
|
39794
39793
|
type: InputType.Message,
|
39795
39794
|
sender: sender.toB256(),
|
39796
39795
|
recipient: recipient.toB256(),
|
39797
39796
|
amount,
|
39798
39797
|
witnessIndex,
|
39799
|
-
predicate
|
39798
|
+
predicate
|
39800
39799
|
};
|
39801
39800
|
this.pushInput(input);
|
39802
39801
|
this.addChangeOutput(recipient, assetId);
|
@@ -39827,32 +39826,6 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
|
|
39827
39826
|
resources.forEach((resource) => this.addResource(resource));
|
39828
39827
|
return this;
|
39829
39828
|
}
|
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
|
-
}
|
39856
39829
|
/**
|
39857
39830
|
* Adds a coin output to the transaction.
|
39858
39831
|
*
|
@@ -39951,6 +39924,12 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
|
|
39951
39924
|
* @param quantities - CoinQuantity Array.
|
39952
39925
|
*/
|
39953
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
|
+
};
|
39954
39933
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
39955
39934
|
if ("assetId" in input) {
|
39956
39935
|
return input.assetId === assetId;
|
@@ -39960,12 +39939,12 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
|
|
39960
39939
|
const updateAssetInput = (assetId, quantity) => {
|
39961
39940
|
const assetInput = findAssetInput(assetId);
|
39962
39941
|
if (assetInput && "assetId" in assetInput) {
|
39963
|
-
assetInput.id =
|
39942
|
+
assetInput.id = generateId();
|
39964
39943
|
assetInput.amount = quantity;
|
39965
39944
|
} else {
|
39966
39945
|
this.addResources([
|
39967
39946
|
{
|
39968
|
-
id:
|
39947
|
+
id: generateId(),
|
39969
39948
|
amount: quantity,
|
39970
39949
|
assetId,
|
39971
39950
|
owner: resourcesOwner || Address.fromRandom(),
|
@@ -41791,36 +41770,6 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
|
|
41791
41770
|
missingContractIds
|
41792
41771
|
};
|
41793
41772
|
}
|
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
|
-
}
|
41824
41773
|
/**
|
41825
41774
|
* Executes a signed transaction without applying the states changes
|
41826
41775
|
* on the chain.
|
@@ -41868,16 +41817,17 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
|
|
41868
41817
|
signatureCallback
|
41869
41818
|
} = {}) {
|
41870
41819
|
const txRequestClone = clone_default(transactionRequestify(transactionRequestLike));
|
41871
|
-
const
|
41872
|
-
const
|
41820
|
+
const chainInfo = this.getChain();
|
41821
|
+
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
41822
|
+
const gasPrice = max(txRequestClone.gasPrice, minGasPrice);
|
41873
41823
|
const isScriptTransaction = txRequestClone.type === TransactionType.Script;
|
41874
41824
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
41875
41825
|
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
41876
41826
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
41877
|
-
if (isScriptTransaction) {
|
41878
|
-
txRequestClone.gasLimit = bn(0);
|
41879
|
-
}
|
41880
41827
|
if (estimatePredicates) {
|
41828
|
+
if (isScriptTransaction) {
|
41829
|
+
txRequestClone.gasLimit = bn(0);
|
41830
|
+
}
|
41881
41831
|
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
41882
41832
|
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
41883
41833
|
}
|
@@ -41886,34 +41836,36 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
|
|
41886
41836
|
if (signatureCallback && isScriptTransaction) {
|
41887
41837
|
await signatureCallback(txRequestClone);
|
41888
41838
|
}
|
41889
|
-
|
41890
|
-
|
41891
|
-
});
|
41839
|
+
const minGas = txRequestClone.calculateMinGas(chainInfo);
|
41840
|
+
const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
|
41892
41841
|
let receipts = [];
|
41893
41842
|
let missingContractIds = [];
|
41894
41843
|
let outputVariables = 0;
|
41895
|
-
let gasUsed = bn(0);
|
41896
41844
|
if (isScriptTransaction && estimateTxDependencies) {
|
41897
41845
|
txRequestClone.gasPrice = bn(0);
|
41846
|
+
txRequestClone.gasLimit = bn(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
|
41898
41847
|
const result = await this.estimateTxDependencies(txRequestClone);
|
41899
41848
|
receipts = result.receipts;
|
41900
41849
|
outputVariables = result.outputVariables;
|
41901
41850
|
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
|
-
}));
|
41908
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();
|
41909
41860
|
return {
|
41910
41861
|
requiredQuantities: allQuantities,
|
41911
41862
|
receipts,
|
41912
41863
|
gasUsed,
|
41913
41864
|
minGasPrice,
|
41914
|
-
gasPrice
|
41865
|
+
gasPrice,
|
41915
41866
|
minGas,
|
41916
41867
|
maxGas,
|
41868
|
+
usedFee,
|
41917
41869
|
minFee,
|
41918
41870
|
maxFee,
|
41919
41871
|
estimatedInputs: txRequestClone.inputs,
|
@@ -44367,12 +44319,12 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
|
|
44367
44319
|
};
|
44368
44320
|
|
44369
44321
|
// ../../node_modules/.pnpm/uuid@9.0.0/node_modules/uuid/dist/esm-node/rng.js
|
44370
|
-
var
|
44322
|
+
var import_crypto15 = __toESM(__require("crypto"));
|
44371
44323
|
var rnds8Pool = new Uint8Array(256);
|
44372
44324
|
var poolPtr = rnds8Pool.length;
|
44373
44325
|
function rng() {
|
44374
44326
|
if (poolPtr > rnds8Pool.length - 16) {
|
44375
|
-
|
44327
|
+
import_crypto15.default.randomFillSync(rnds8Pool);
|
44376
44328
|
poolPtr = 0;
|
44377
44329
|
}
|
44378
44330
|
return rnds8Pool.slice(poolPtr, poolPtr += 16);
|
@@ -44388,9 +44340,9 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
|
|
44388
44340
|
}
|
44389
44341
|
|
44390
44342
|
// ../../node_modules/.pnpm/uuid@9.0.0/node_modules/uuid/dist/esm-node/native.js
|
44391
|
-
var
|
44343
|
+
var import_crypto16 = __toESM(__require("crypto"));
|
44392
44344
|
var native_default = {
|
44393
|
-
randomUUID:
|
44345
|
+
randomUUID: import_crypto16.default.randomUUID
|
44394
44346
|
};
|
44395
44347
|
|
44396
44348
|
// ../../node_modules/.pnpm/uuid@9.0.0/node_modules/uuid/dist/esm-node/v4.js
|
@@ -47853,6 +47805,7 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
|
|
47853
47805
|
if (input.type === InputType.Coin && hexlify(input.owner) === this.address.toB256()) {
|
47854
47806
|
input.predicate = this.bytes;
|
47855
47807
|
input.predicateData = this.getPredicateData(policies.length);
|
47808
|
+
input.witnessIndex = 0;
|
47856
47809
|
}
|
47857
47810
|
});
|
47858
47811
|
return request;
|
@@ -47890,6 +47843,20 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
|
|
47890
47843
|
const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
|
47891
47844
|
return super.simulateTransaction(transactionRequest);
|
47892
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
|
+
}
|
47893
47860
|
getPredicateData(policiesLength) {
|
47894
47861
|
if (!this.predicateData.length) {
|
47895
47862
|
return new Uint8Array();
|