@fuel-ts/account 0.0.0-rc-1976-20240410144111 → 0.0.0-rc-2034-20240410182856
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/account.d.ts.map +1 -1
- package/dist/index.global.js +97 -97
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +174 -170
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +102 -98
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/coin-quantity.d.ts +2 -2
- package/dist/providers/coin-quantity.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +13 -9
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/input.d.ts.map +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +2 -5
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils/seedTestWallet.d.ts.map +1 -1
- package/dist/test-utils.global.js +100 -103
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +171 -170
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +104 -103
- package/dist/test-utils.mjs.map +1 -1
- package/package.json +16 -16
package/dist/test-utils.mjs
CHANGED
@@ -24,12 +24,14 @@ import { hexlify as hexlify15 } from "@fuel-ts/utils";
|
|
24
24
|
|
25
25
|
// src/account.ts
|
26
26
|
import { Address as Address3 } from "@fuel-ts/address";
|
27
|
+
import { BaseAssetId as BaseAssetId3 } from "@fuel-ts/address/configs";
|
27
28
|
import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
|
28
29
|
import { AbstractAccount } from "@fuel-ts/interfaces";
|
29
30
|
import { bn as bn17 } from "@fuel-ts/math";
|
30
31
|
import { arrayify as arrayify14 } from "@fuel-ts/utils";
|
31
32
|
|
32
33
|
// src/providers/coin-quantity.ts
|
34
|
+
import { BaseAssetId } from "@fuel-ts/address/configs";
|
33
35
|
import { bn } from "@fuel-ts/math";
|
34
36
|
import { hexlify } from "@fuel-ts/utils";
|
35
37
|
var coinQuantityfy = (coinQuantityLike) => {
|
@@ -38,11 +40,11 @@ var coinQuantityfy = (coinQuantityLike) => {
|
|
38
40
|
let max2;
|
39
41
|
if (Array.isArray(coinQuantityLike)) {
|
40
42
|
amount = coinQuantityLike[0];
|
41
|
-
assetId = coinQuantityLike[1];
|
42
|
-
max2 = coinQuantityLike[2];
|
43
|
+
assetId = coinQuantityLike[1] ?? BaseAssetId;
|
44
|
+
max2 = coinQuantityLike[2] ?? void 0;
|
43
45
|
} else {
|
44
46
|
amount = coinQuantityLike.amount;
|
45
|
-
assetId = coinQuantityLike.assetId;
|
47
|
+
assetId = coinQuantityLike.assetId ?? BaseAssetId;
|
46
48
|
max2 = coinQuantityLike.max ?? void 0;
|
47
49
|
}
|
48
50
|
const bnAmount = bn(amount);
|
@@ -1016,6 +1018,7 @@ var MemoryCache = class {
|
|
1016
1018
|
};
|
1017
1019
|
|
1018
1020
|
// src/providers/transaction-request/input.ts
|
1021
|
+
import { BYTES_32, UTXO_ID_LEN } from "@fuel-ts/abi-coder";
|
1019
1022
|
import { ZeroBytes32 } from "@fuel-ts/address/configs";
|
1020
1023
|
import { ErrorCode as ErrorCode3, FuelError as FuelError3 } from "@fuel-ts/errors";
|
1021
1024
|
import { bn as bn2, toNumber } from "@fuel-ts/math";
|
@@ -1029,8 +1032,8 @@ var inputify = (value) => {
|
|
1029
1032
|
const predicateData = arrayify(value.predicateData ?? "0x");
|
1030
1033
|
return {
|
1031
1034
|
type: InputType.Coin,
|
1032
|
-
txID: hexlify3(arrayify(value.id).slice(0,
|
1033
|
-
outputIndex: arrayify(value.id)
|
1035
|
+
txID: hexlify3(arrayify(value.id).slice(0, BYTES_32)),
|
1036
|
+
outputIndex: toNumber(arrayify(value.id).slice(BYTES_32, UTXO_ID_LEN)),
|
1034
1037
|
owner: hexlify3(value.owner),
|
1035
1038
|
amount: bn2(value.amount),
|
1036
1039
|
assetId: hexlify3(value.assetId),
|
@@ -1148,8 +1151,10 @@ var outputify = (value) => {
|
|
1148
1151
|
};
|
1149
1152
|
|
1150
1153
|
// src/providers/transaction-request/transaction-request.ts
|
1154
|
+
import { UTXO_ID_LEN as UTXO_ID_LEN2 } from "@fuel-ts/abi-coder";
|
1151
1155
|
import { Address, addressify } from "@fuel-ts/address";
|
1152
|
-
import { ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1156
|
+
import { BaseAssetId as BaseAssetId2, ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1157
|
+
import { randomBytes } from "@fuel-ts/crypto";
|
1153
1158
|
import { bn as bn7 } from "@fuel-ts/math";
|
1154
1159
|
import {
|
1155
1160
|
PolicyType,
|
@@ -1609,8 +1614,6 @@ var BaseTransactionRequest = class {
|
|
1609
1614
|
outputs = [];
|
1610
1615
|
/** List of witnesses */
|
1611
1616
|
witnesses = [];
|
1612
|
-
/** Base asset ID - should be fetched from the chain */
|
1613
|
-
baseAssetId;
|
1614
1617
|
/**
|
1615
1618
|
* Constructor for initializing a base transaction request.
|
1616
1619
|
*
|
@@ -1623,9 +1626,8 @@ var BaseTransactionRequest = class {
|
|
1623
1626
|
witnessLimit,
|
1624
1627
|
inputs,
|
1625
1628
|
outputs,
|
1626
|
-
witnesses
|
1627
|
-
|
1628
|
-
}) {
|
1629
|
+
witnesses
|
1630
|
+
} = {}) {
|
1629
1631
|
this.gasPrice = bn7(gasPrice);
|
1630
1632
|
this.maturity = maturity ?? 0;
|
1631
1633
|
this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
|
@@ -1633,7 +1635,6 @@ var BaseTransactionRequest = class {
|
|
1633
1635
|
this.inputs = inputs ?? [];
|
1634
1636
|
this.outputs = outputs ?? [];
|
1635
1637
|
this.witnesses = witnesses ?? [];
|
1636
|
-
this.baseAssetId = baseAssetId;
|
1637
1638
|
}
|
1638
1639
|
static getPolicyMeta(req) {
|
1639
1640
|
let policyTypes = 0;
|
@@ -1857,9 +1858,11 @@ var BaseTransactionRequest = class {
|
|
1857
1858
|
*
|
1858
1859
|
* @param message - Message resource.
|
1859
1860
|
* @param predicate - Predicate bytes.
|
1861
|
+
* @param predicateData - Predicate data bytes.
|
1860
1862
|
*/
|
1861
1863
|
addMessageInput(message, predicate) {
|
1862
1864
|
const { recipient, sender, amount } = message;
|
1865
|
+
const assetId = BaseAssetId2;
|
1863
1866
|
let witnessIndex;
|
1864
1867
|
if (predicate) {
|
1865
1868
|
witnessIndex = 0;
|
@@ -1879,7 +1882,7 @@ var BaseTransactionRequest = class {
|
|
1879
1882
|
predicate: predicate?.bytes
|
1880
1883
|
};
|
1881
1884
|
this.pushInput(input);
|
1882
|
-
this.addChangeOutput(recipient,
|
1885
|
+
this.addChangeOutput(recipient, assetId);
|
1883
1886
|
}
|
1884
1887
|
/**
|
1885
1888
|
* Adds a single resource to the transaction by adding a coin/message input and a
|
@@ -1940,12 +1943,12 @@ var BaseTransactionRequest = class {
|
|
1940
1943
|
* @param amount - Amount of coin.
|
1941
1944
|
* @param assetId - Asset ID of coin.
|
1942
1945
|
*/
|
1943
|
-
addCoinOutput(to, amount, assetId) {
|
1946
|
+
addCoinOutput(to, amount, assetId = BaseAssetId2) {
|
1944
1947
|
this.pushOutput({
|
1945
1948
|
type: OutputType2.Coin,
|
1946
1949
|
to: addressify(to).toB256(),
|
1947
1950
|
amount,
|
1948
|
-
assetId
|
1951
|
+
assetId
|
1949
1952
|
});
|
1950
1953
|
return this;
|
1951
1954
|
}
|
@@ -1972,7 +1975,7 @@ var BaseTransactionRequest = class {
|
|
1972
1975
|
* @param to - Address of the owner.
|
1973
1976
|
* @param assetId - Asset ID of coin.
|
1974
1977
|
*/
|
1975
|
-
addChangeOutput(to, assetId) {
|
1978
|
+
addChangeOutput(to, assetId = BaseAssetId2) {
|
1976
1979
|
const changeOutput = this.getChangeOutputs().find(
|
1977
1980
|
(output) => hexlify7(output.assetId) === assetId
|
1978
1981
|
);
|
@@ -1980,7 +1983,7 @@ var BaseTransactionRequest = class {
|
|
1980
1983
|
this.pushOutput({
|
1981
1984
|
type: OutputType2.Change,
|
1982
1985
|
to: addressify(to).toB256(),
|
1983
|
-
assetId
|
1986
|
+
assetId
|
1984
1987
|
});
|
1985
1988
|
}
|
1986
1989
|
}
|
@@ -2031,12 +2034,6 @@ var BaseTransactionRequest = class {
|
|
2031
2034
|
* @param quantities - CoinQuantity Array.
|
2032
2035
|
*/
|
2033
2036
|
fundWithFakeUtxos(quantities, resourcesOwner) {
|
2034
|
-
let idCounter = 0;
|
2035
|
-
const generateId = () => {
|
2036
|
-
const counterString = String(idCounter++);
|
2037
|
-
const id = ZeroBytes324.slice(0, -counterString.length).concat(counterString);
|
2038
|
-
return id;
|
2039
|
-
};
|
2040
2037
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
2041
2038
|
if ("assetId" in input) {
|
2042
2039
|
return input.assetId === assetId;
|
@@ -2046,12 +2043,12 @@ var BaseTransactionRequest = class {
|
|
2046
2043
|
const updateAssetInput = (assetId, quantity) => {
|
2047
2044
|
const assetInput = findAssetInput(assetId);
|
2048
2045
|
if (assetInput && "assetId" in assetInput) {
|
2049
|
-
assetInput.id =
|
2046
|
+
assetInput.id = hexlify7(randomBytes(UTXO_ID_LEN2));
|
2050
2047
|
assetInput.amount = quantity;
|
2051
2048
|
} else {
|
2052
2049
|
this.addResources([
|
2053
2050
|
{
|
2054
|
-
id:
|
2051
|
+
id: hexlify7(randomBytes(UTXO_ID_LEN2)),
|
2055
2052
|
amount: quantity,
|
2056
2053
|
assetId,
|
2057
2054
|
owner: resourcesOwner || Address.fromRandom(),
|
@@ -2062,7 +2059,7 @@ var BaseTransactionRequest = class {
|
|
2062
2059
|
]);
|
2063
2060
|
}
|
2064
2061
|
};
|
2065
|
-
updateAssetInput(
|
2062
|
+
updateAssetInput(BaseAssetId2, bn7(1e11));
|
2066
2063
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2067
2064
|
}
|
2068
2065
|
/**
|
@@ -2232,7 +2229,12 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2232
2229
|
*
|
2233
2230
|
* @param createTransactionRequestLike - The initial values for the instance
|
2234
2231
|
*/
|
2235
|
-
constructor({
|
2232
|
+
constructor({
|
2233
|
+
bytecodeWitnessIndex,
|
2234
|
+
salt,
|
2235
|
+
storageSlots,
|
2236
|
+
...rest
|
2237
|
+
} = {}) {
|
2236
2238
|
super(rest);
|
2237
2239
|
this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
|
2238
2240
|
this.salt = hexlify9(salt ?? ZeroBytes326);
|
@@ -2356,7 +2358,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2356
2358
|
*
|
2357
2359
|
* @param scriptTransactionRequestLike - The initial values for the instance.
|
2358
2360
|
*/
|
2359
|
-
constructor({ script, scriptData, gasLimit, ...rest }) {
|
2361
|
+
constructor({ script, scriptData, gasLimit, ...rest } = {}) {
|
2360
2362
|
super(rest);
|
2361
2363
|
this.gasLimit = bn10(gasLimit);
|
2362
2364
|
this.script = arrayify8(script ?? returnZeroScript.bytes);
|
@@ -3484,7 +3486,6 @@ var processGqlChain = (chain) => {
|
|
3484
3486
|
gasPerByte: bn15(feeParams.gasPerByte),
|
3485
3487
|
maxMessageDataLength: bn15(predicateParams.maxMessageDataLength),
|
3486
3488
|
chainId: bn15(consensusParameters.chainId),
|
3487
|
-
baseAssetId: consensusParameters.baseAssetId,
|
3488
3489
|
gasCosts
|
3489
3490
|
},
|
3490
3491
|
gasCosts,
|
@@ -3727,17 +3728,6 @@ var _Provider = class {
|
|
3727
3728
|
} = this.getChain();
|
3728
3729
|
return chainId.toNumber();
|
3729
3730
|
}
|
3730
|
-
/**
|
3731
|
-
* Returns the base asset ID
|
3732
|
-
*
|
3733
|
-
* @returns A promise that resolves to the base asset ID
|
3734
|
-
*/
|
3735
|
-
getBaseAssetId() {
|
3736
|
-
const {
|
3737
|
-
consensusParameters: { baseAssetId }
|
3738
|
-
} = this.getChain();
|
3739
|
-
return baseAssetId;
|
3740
|
-
}
|
3741
3731
|
/**
|
3742
3732
|
* Submits a transaction to the chain to be executed.
|
3743
3733
|
*
|
@@ -3888,6 +3878,36 @@ var _Provider = class {
|
|
3888
3878
|
missingContractIds
|
3889
3879
|
};
|
3890
3880
|
}
|
3881
|
+
/**
|
3882
|
+
* Estimates the transaction gas and fee based on the provided transaction request.
|
3883
|
+
* @param transactionRequest - The transaction request object.
|
3884
|
+
* @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
|
3885
|
+
*/
|
3886
|
+
estimateTxGasAndFee(params) {
|
3887
|
+
const { transactionRequest } = params;
|
3888
|
+
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
3889
|
+
const chainInfo = this.getChain();
|
3890
|
+
const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
|
3891
|
+
transactionRequest.gasPrice = gasPrice;
|
3892
|
+
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
3893
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3894
|
+
if (transactionRequest.type === TransactionType8.Script) {
|
3895
|
+
if (transactionRequest.gasLimit.eq(0)) {
|
3896
|
+
transactionRequest.gasLimit = minGas;
|
3897
|
+
transactionRequest.gasLimit = maxGasPerTx.sub(
|
3898
|
+
transactionRequest.calculateMaxGas(chainInfo, minGas)
|
3899
|
+
);
|
3900
|
+
}
|
3901
|
+
}
|
3902
|
+
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
3903
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3904
|
+
return {
|
3905
|
+
minGas,
|
3906
|
+
minFee,
|
3907
|
+
maxGas,
|
3908
|
+
maxFee
|
3909
|
+
};
|
3910
|
+
}
|
3891
3911
|
/**
|
3892
3912
|
* Executes a signed transaction without applying the states changes
|
3893
3913
|
* on the chain.
|
@@ -3935,17 +3955,16 @@ var _Provider = class {
|
|
3935
3955
|
signatureCallback
|
3936
3956
|
} = {}) {
|
3937
3957
|
const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
|
3938
|
-
const
|
3939
|
-
const
|
3940
|
-
const gasPrice = max(txRequestClone.gasPrice, minGasPrice);
|
3958
|
+
const { minGasPrice } = this.getGasConfig();
|
3959
|
+
const setGasPrice = max(txRequestClone.gasPrice, minGasPrice);
|
3941
3960
|
const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
|
3942
3961
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
3943
3962
|
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
3944
3963
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
3964
|
+
if (isScriptTransaction) {
|
3965
|
+
txRequestClone.gasLimit = bn15(0);
|
3966
|
+
}
|
3945
3967
|
if (estimatePredicates) {
|
3946
|
-
if (isScriptTransaction) {
|
3947
|
-
txRequestClone.gasLimit = bn15(0);
|
3948
|
-
}
|
3949
3968
|
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
3950
3969
|
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3951
3970
|
}
|
@@ -3954,36 +3973,34 @@ var _Provider = class {
|
|
3954
3973
|
if (signatureCallback && isScriptTransaction) {
|
3955
3974
|
await signatureCallback(txRequestClone);
|
3956
3975
|
}
|
3957
|
-
|
3958
|
-
|
3976
|
+
let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
3977
|
+
transactionRequest: txRequestClone
|
3978
|
+
});
|
3959
3979
|
let receipts = [];
|
3960
3980
|
let missingContractIds = [];
|
3961
3981
|
let outputVariables = 0;
|
3982
|
+
let gasUsed = bn15(0);
|
3962
3983
|
if (isScriptTransaction && estimateTxDependencies) {
|
3963
3984
|
txRequestClone.gasPrice = bn15(0);
|
3964
|
-
txRequestClone.gasLimit = bn15(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
|
3965
3985
|
const result = await this.estimateTxDependencies(txRequestClone);
|
3966
3986
|
receipts = result.receipts;
|
3967
3987
|
outputVariables = result.outputVariables;
|
3968
3988
|
missingContractIds = result.missingContractIds;
|
3989
|
+
gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
|
3990
|
+
txRequestClone.gasLimit = gasUsed;
|
3991
|
+
txRequestClone.gasPrice = setGasPrice;
|
3992
|
+
({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
3993
|
+
transactionRequest: txRequestClone
|
3994
|
+
}));
|
3969
3995
|
}
|
3970
|
-
const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
|
3971
|
-
const usedFee = calculatePriceWithFactor(
|
3972
|
-
gasUsed,
|
3973
|
-
gasPrice,
|
3974
|
-
gasPriceFactor
|
3975
|
-
).normalizeZeroToOne();
|
3976
|
-
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3977
|
-
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3978
3996
|
return {
|
3979
3997
|
requiredQuantities: allQuantities,
|
3980
3998
|
receipts,
|
3981
3999
|
gasUsed,
|
3982
4000
|
minGasPrice,
|
3983
|
-
gasPrice,
|
4001
|
+
gasPrice: setGasPrice,
|
3984
4002
|
minGas,
|
3985
4003
|
maxGas,
|
3986
|
-
usedFee,
|
3987
4004
|
minFee,
|
3988
4005
|
maxFee,
|
3989
4006
|
estimatedInputs: txRequestClone.inputs,
|
@@ -4608,9 +4625,8 @@ var Account = class extends AbstractAccount {
|
|
4608
4625
|
* @param assetId - The asset ID to check the balance for.
|
4609
4626
|
* @returns A promise that resolves to the balance amount.
|
4610
4627
|
*/
|
4611
|
-
async getBalance(assetId) {
|
4612
|
-
const
|
4613
|
-
const amount = await this.provider.getBalance(this.address, assetIdToFetch);
|
4628
|
+
async getBalance(assetId = BaseAssetId3) {
|
4629
|
+
const amount = await this.provider.getBalance(this.address, assetId);
|
4614
4630
|
return amount;
|
4615
4631
|
}
|
4616
4632
|
/**
|
@@ -4648,10 +4664,9 @@ var Account = class extends AbstractAccount {
|
|
4648
4664
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4649
4665
|
*/
|
4650
4666
|
async fund(request, coinQuantities, fee) {
|
4651
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
4652
4667
|
const updatedQuantities = addAmountToAsset({
|
4653
4668
|
amount: bn17(fee),
|
4654
|
-
assetId:
|
4669
|
+
assetId: BaseAssetId3,
|
4655
4670
|
coinQuantities
|
4656
4671
|
});
|
4657
4672
|
const quantitiesDict = {};
|
@@ -4675,8 +4690,8 @@ var Account = class extends AbstractAccount {
|
|
4675
4690
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4676
4691
|
cachedUtxos.push(input.id);
|
4677
4692
|
}
|
4678
|
-
} else if (input.recipient === owner && input.amount && quantitiesDict[
|
4679
|
-
quantitiesDict[
|
4693
|
+
} else if (input.recipient === owner && input.amount && quantitiesDict[BaseAssetId3]) {
|
4694
|
+
quantitiesDict[BaseAssetId3].owned = quantitiesDict[BaseAssetId3].owned.add(input.amount);
|
4680
4695
|
cachedMessages.push(input.nonce);
|
4681
4696
|
}
|
4682
4697
|
}
|
@@ -4708,13 +4723,11 @@ var Account = class extends AbstractAccount {
|
|
4708
4723
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4709
4724
|
* @returns A promise that resolves to the prepared transaction request.
|
4710
4725
|
*/
|
4711
|
-
async createTransfer(destination, amount, assetId, txParams = {}) {
|
4726
|
+
async createTransfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
4712
4727
|
const { minGasPrice } = this.provider.getGasConfig();
|
4713
|
-
const
|
4714
|
-
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4715
|
-
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
4728
|
+
const params = { gasPrice: minGasPrice, ...txParams };
|
4716
4729
|
const request = new ScriptTransactionRequest(params);
|
4717
|
-
request.addCoinOutput(Address3.fromAddressOrString(destination), amount,
|
4730
|
+
request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetId);
|
4718
4731
|
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
4719
4732
|
estimateTxDependencies: true,
|
4720
4733
|
resourcesOwner: this
|
@@ -4740,15 +4753,14 @@ var Account = class extends AbstractAccount {
|
|
4740
4753
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4741
4754
|
* @returns A promise that resolves to the transaction response.
|
4742
4755
|
*/
|
4743
|
-
async transfer(destination, amount, assetId, txParams = {}) {
|
4756
|
+
async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
4744
4757
|
if (bn17(amount).lte(0)) {
|
4745
4758
|
throw new FuelError15(
|
4746
4759
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
4747
4760
|
"Transfer amount must be a positive number."
|
4748
4761
|
);
|
4749
4762
|
}
|
4750
|
-
const
|
4751
|
-
const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
4763
|
+
const request = await this.createTransfer(destination, amount, assetId, txParams);
|
4752
4764
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
4753
4765
|
}
|
4754
4766
|
/**
|
@@ -4760,7 +4772,7 @@ var Account = class extends AbstractAccount {
|
|
4760
4772
|
* @param txParams - The optional transaction parameters.
|
4761
4773
|
* @returns A promise that resolves to the transaction response.
|
4762
4774
|
*/
|
4763
|
-
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
4775
|
+
async transferToContract(contractId, amount, assetId = BaseAssetId3, txParams = {}) {
|
4764
4776
|
if (bn17(amount).lte(0)) {
|
4765
4777
|
throw new FuelError15(
|
4766
4778
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
@@ -4769,13 +4781,11 @@ var Account = class extends AbstractAccount {
|
|
4769
4781
|
}
|
4770
4782
|
const contractAddress = Address3.fromAddressOrString(contractId);
|
4771
4783
|
const { minGasPrice } = this.provider.getGasConfig();
|
4772
|
-
const
|
4773
|
-
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4774
|
-
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
4784
|
+
const params = { gasPrice: minGasPrice, ...txParams };
|
4775
4785
|
const { script, scriptData } = await assembleTransferToContractScript({
|
4776
4786
|
hexlifiedContractId: contractAddress.toB256(),
|
4777
4787
|
amountToTransfer: bn17(amount),
|
4778
|
-
assetId
|
4788
|
+
assetId
|
4779
4789
|
});
|
4780
4790
|
const request = new ScriptTransactionRequest({
|
4781
4791
|
...params,
|
@@ -4785,7 +4795,7 @@ var Account = class extends AbstractAccount {
|
|
4785
4795
|
request.addContractInputAndOutput(contractAddress);
|
4786
4796
|
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
4787
4797
|
request,
|
4788
|
-
[{ amount: bn17(amount), assetId: String(
|
4798
|
+
[{ amount: bn17(amount), assetId: String(assetId) }]
|
4789
4799
|
);
|
4790
4800
|
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
4791
4801
|
this.validateGas({
|
@@ -4807,7 +4817,6 @@ var Account = class extends AbstractAccount {
|
|
4807
4817
|
*/
|
4808
4818
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
4809
4819
|
const { minGasPrice } = this.provider.getGasConfig();
|
4810
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
4811
4820
|
const recipientAddress = Address3.fromAddressOrString(recipient);
|
4812
4821
|
const recipientDataArray = arrayify14(
|
4813
4822
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
@@ -4820,14 +4829,9 @@ var Account = class extends AbstractAccount {
|
|
4820
4829
|
...recipientDataArray,
|
4821
4830
|
...amountDataArray
|
4822
4831
|
]);
|
4823
|
-
const params = {
|
4824
|
-
script,
|
4825
|
-
gasPrice: minGasPrice,
|
4826
|
-
baseAssetId,
|
4827
|
-
...txParams
|
4828
|
-
};
|
4832
|
+
const params = { script, gasPrice: minGasPrice, ...txParams };
|
4829
4833
|
const request = new ScriptTransactionRequest(params);
|
4830
|
-
const forwardingQuantities = [{ amount: bn17(amount), assetId:
|
4834
|
+
const forwardingQuantities = [{ amount: bn17(amount), assetId: BaseAssetId3 }];
|
4831
4835
|
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
4832
4836
|
request,
|
4833
4837
|
forwardingQuantities
|
@@ -4920,7 +4924,7 @@ var Account = class extends AbstractAccount {
|
|
4920
4924
|
|
4921
4925
|
// src/signer/signer.ts
|
4922
4926
|
import { Address as Address4 } from "@fuel-ts/address";
|
4923
|
-
import { randomBytes } from "@fuel-ts/crypto";
|
4927
|
+
import { randomBytes as randomBytes2 } from "@fuel-ts/crypto";
|
4924
4928
|
import { hash } from "@fuel-ts/hasher";
|
4925
4929
|
import { toBytes } from "@fuel-ts/math";
|
4926
4930
|
import { hexlify as hexlify13, concat as concat3, arrayify as arrayify15 } from "@fuel-ts/utils";
|
@@ -5013,7 +5017,7 @@ var Signer = class {
|
|
5013
5017
|
* @returns random 32-byte hashed
|
5014
5018
|
*/
|
5015
5019
|
static generatePrivateKey(entropy) {
|
5016
|
-
return entropy ? hash(concat3([
|
5020
|
+
return entropy ? hash(concat3([randomBytes2(32), arrayify15(entropy)])) : randomBytes2(32);
|
5017
5021
|
}
|
5018
5022
|
/**
|
5019
5023
|
* Extended publicKey from a compact publicKey
|
@@ -5032,7 +5036,7 @@ import { Address as Address5 } from "@fuel-ts/address";
|
|
5032
5036
|
import {
|
5033
5037
|
bufferFromString,
|
5034
5038
|
keccak256,
|
5035
|
-
randomBytes as
|
5039
|
+
randomBytes as randomBytes3,
|
5036
5040
|
scrypt,
|
5037
5041
|
stringFromBuffer,
|
5038
5042
|
decryptJsonWalletData,
|
@@ -5055,7 +5059,7 @@ var removeHexPrefix = (hexString) => {
|
|
5055
5059
|
async function encryptKeystoreWallet(privateKey, address, password) {
|
5056
5060
|
const privateKeyBuffer = bufferFromString(removeHexPrefix(privateKey), "hex");
|
5057
5061
|
const ownerAddress = Address5.fromAddressOrString(address);
|
5058
|
-
const salt =
|
5062
|
+
const salt = randomBytes3(DEFAULT_KEY_SIZE);
|
5059
5063
|
const key = scrypt({
|
5060
5064
|
password: bufferFromString(password),
|
5061
5065
|
salt,
|
@@ -5064,7 +5068,7 @@ async function encryptKeystoreWallet(privateKey, address, password) {
|
|
5064
5068
|
r: DEFAULT_KDF_PARAMS_R,
|
5065
5069
|
p: DEFAULT_KDF_PARAMS_P
|
5066
5070
|
});
|
5067
|
-
const iv =
|
5071
|
+
const iv = randomBytes3(DEFAULT_IV_SIZE);
|
5068
5072
|
const ciphertext = await encryptJsonWalletData(privateKeyBuffer, key, iv);
|
5069
5073
|
const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertext]);
|
5070
5074
|
const macHashUint8Array = keccak256(data);
|
@@ -5246,7 +5250,7 @@ import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from
|
|
5246
5250
|
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5247
5251
|
|
5248
5252
|
// src/mnemonic/mnemonic.ts
|
5249
|
-
import { randomBytes as
|
5253
|
+
import { randomBytes as randomBytes4 } from "@fuel-ts/crypto";
|
5250
5254
|
import { ErrorCode as ErrorCode18, FuelError as FuelError18 } from "@fuel-ts/errors";
|
5251
5255
|
import { sha256 as sha2563 } from "@fuel-ts/hasher";
|
5252
5256
|
import { arrayify as arrayify17, hexlify as hexlify16, concat as concat4 } from "@fuel-ts/utils";
|
@@ -7601,7 +7605,7 @@ var Mnemonic = class {
|
|
7601
7605
|
* @returns A randomly generated mnemonic
|
7602
7606
|
*/
|
7603
7607
|
static generate(size = 32, extraEntropy = "") {
|
7604
|
-
const entropy = extraEntropy ? sha2563(concat4([
|
7608
|
+
const entropy = extraEntropy ? sha2563(concat4([randomBytes4(size), arrayify17(extraEntropy)])) : randomBytes4(size);
|
7605
7609
|
return Mnemonic.entropyToMnemonic(entropy);
|
7606
7610
|
}
|
7607
7611
|
};
|
@@ -7972,17 +7976,15 @@ __publicField(Wallet, "fromExtendedKey", WalletUnlocked.fromExtendedKey);
|
|
7972
7976
|
__publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
|
7973
7977
|
|
7974
7978
|
// src/test-utils/seedTestWallet.ts
|
7975
|
-
import { randomBytes as
|
7979
|
+
import { randomBytes as randomBytes5 } from "@fuel-ts/crypto";
|
7976
7980
|
var seedTestWallet = async (wallet, quantities) => {
|
7977
7981
|
const genesisWallet = new WalletUnlocked(
|
7978
|
-
process.env.GENESIS_SECRET ||
|
7982
|
+
process.env.GENESIS_SECRET || randomBytes5(32),
|
7979
7983
|
wallet.provider
|
7980
7984
|
);
|
7981
7985
|
const resources = await genesisWallet.getResourcesToSpend(quantities);
|
7982
7986
|
const { minGasPrice } = genesisWallet.provider.getGasConfig();
|
7983
|
-
const baseAssetId = genesisWallet.provider.getBaseAssetId();
|
7984
7987
|
const request = new ScriptTransactionRequest({
|
7985
|
-
baseAssetId,
|
7986
7988
|
gasLimit: 1e4,
|
7987
7989
|
gasPrice: minGasPrice
|
7988
7990
|
});
|
@@ -8001,7 +8003,7 @@ var generateTestWallet = async (provider, quantities) => {
|
|
8001
8003
|
};
|
8002
8004
|
|
8003
8005
|
// src/test-utils/launchNode.ts
|
8004
|
-
import {
|
8006
|
+
import { BaseAssetId as BaseAssetId4 } from "@fuel-ts/address/configs";
|
8005
8007
|
import { toHex as toHex2 } from "@fuel-ts/math";
|
8006
8008
|
import { defaultChainConfig, defaultConsensusKey, hexlify as hexlify18 } from "@fuel-ts/utils";
|
8007
8009
|
import { findBinPath } from "@fuel-ts/utils/cli-utils";
|
@@ -8101,7 +8103,7 @@ var launchNode = async ({
|
|
8101
8103
|
{
|
8102
8104
|
owner: signer.address.toHexString(),
|
8103
8105
|
amount: toHex2(1e9),
|
8104
|
-
asset_id:
|
8106
|
+
asset_id: BaseAssetId4
|
8105
8107
|
}
|
8106
8108
|
]
|
8107
8109
|
}
|
@@ -8167,10 +8169,9 @@ var launchNode = async ({
|
|
8167
8169
|
})
|
8168
8170
|
);
|
8169
8171
|
var generateWallets = async (count, provider) => {
|
8170
|
-
const baseAssetId = provider.getBaseAssetId();
|
8171
8172
|
const wallets = [];
|
8172
8173
|
for (let i = 0; i < count; i += 1) {
|
8173
|
-
const wallet = await generateTestWallet(provider, [[1e3,
|
8174
|
+
const wallet = await generateTestWallet(provider, [[1e3, BaseAssetId4]]);
|
8174
8175
|
wallets.push(wallet);
|
8175
8176
|
}
|
8176
8177
|
return wallets;
|