@fuel-ts/account 0.0.0-rc-1976-20240411153008 → 0.0.0-rc-2037-20240411163513
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 +120 -131
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +197 -204
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +125 -132
- 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-quantity.d.ts +2 -2
- package/dist/providers/coin-quantity.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 +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 +4 -25
- 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 +108 -137
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +179 -204
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +112 -137
- package/dist/test-utils.mjs.map +1 -1
- package/package.json +16 -16
package/dist/index.mjs
CHANGED
@@ -29,12 +29,14 @@ var __privateMethod = (obj, member, method) => {
|
|
29
29
|
|
30
30
|
// src/account.ts
|
31
31
|
import { Address as Address3 } from "@fuel-ts/address";
|
32
|
+
import { BaseAssetId as BaseAssetId3 } from "@fuel-ts/address/configs";
|
32
33
|
import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
|
33
34
|
import { AbstractAccount } from "@fuel-ts/interfaces";
|
34
35
|
import { bn as bn17 } from "@fuel-ts/math";
|
35
36
|
import { arrayify as arrayify14 } from "@fuel-ts/utils";
|
36
37
|
|
37
38
|
// src/providers/coin-quantity.ts
|
39
|
+
import { BaseAssetId } from "@fuel-ts/address/configs";
|
38
40
|
import { bn } from "@fuel-ts/math";
|
39
41
|
import { hexlify } from "@fuel-ts/utils";
|
40
42
|
var coinQuantityfy = (coinQuantityLike) => {
|
@@ -43,11 +45,11 @@ var coinQuantityfy = (coinQuantityLike) => {
|
|
43
45
|
let max2;
|
44
46
|
if (Array.isArray(coinQuantityLike)) {
|
45
47
|
amount = coinQuantityLike[0];
|
46
|
-
assetId = coinQuantityLike[1];
|
47
|
-
max2 = coinQuantityLike[2];
|
48
|
+
assetId = coinQuantityLike[1] ?? BaseAssetId;
|
49
|
+
max2 = coinQuantityLike[2] ?? void 0;
|
48
50
|
} else {
|
49
51
|
amount = coinQuantityLike.amount;
|
50
|
-
assetId = coinQuantityLike.assetId;
|
52
|
+
assetId = coinQuantityLike.assetId ?? BaseAssetId;
|
51
53
|
max2 = coinQuantityLike.max ?? void 0;
|
52
54
|
}
|
53
55
|
const bnAmount = bn(amount);
|
@@ -1021,6 +1023,7 @@ var MemoryCache = class {
|
|
1021
1023
|
};
|
1022
1024
|
|
1023
1025
|
// src/providers/transaction-request/input.ts
|
1026
|
+
import { BYTES_32, UTXO_ID_LEN } from "@fuel-ts/abi-coder";
|
1024
1027
|
import { ZeroBytes32 } from "@fuel-ts/address/configs";
|
1025
1028
|
import { ErrorCode as ErrorCode3, FuelError as FuelError3 } from "@fuel-ts/errors";
|
1026
1029
|
import { bn as bn2, toNumber } from "@fuel-ts/math";
|
@@ -1034,8 +1037,8 @@ var inputify = (value) => {
|
|
1034
1037
|
const predicateData = arrayify(value.predicateData ?? "0x");
|
1035
1038
|
return {
|
1036
1039
|
type: InputType.Coin,
|
1037
|
-
txID: hexlify3(arrayify(value.id).slice(0,
|
1038
|
-
outputIndex: arrayify(value.id)
|
1040
|
+
txID: hexlify3(arrayify(value.id).slice(0, BYTES_32)),
|
1041
|
+
outputIndex: toNumber(arrayify(value.id).slice(BYTES_32, UTXO_ID_LEN)),
|
1039
1042
|
owner: hexlify3(value.owner),
|
1040
1043
|
amount: bn2(value.amount),
|
1041
1044
|
assetId: hexlify3(value.assetId),
|
@@ -1153,8 +1156,10 @@ var outputify = (value) => {
|
|
1153
1156
|
};
|
1154
1157
|
|
1155
1158
|
// src/providers/transaction-request/transaction-request.ts
|
1159
|
+
import { UTXO_ID_LEN as UTXO_ID_LEN2 } from "@fuel-ts/abi-coder";
|
1156
1160
|
import { Address, addressify } from "@fuel-ts/address";
|
1157
|
-
import { ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1161
|
+
import { BaseAssetId as BaseAssetId2, ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1162
|
+
import { randomBytes } from "@fuel-ts/crypto";
|
1158
1163
|
import { bn as bn7 } from "@fuel-ts/math";
|
1159
1164
|
import {
|
1160
1165
|
PolicyType,
|
@@ -1688,8 +1693,6 @@ var BaseTransactionRequest = class {
|
|
1688
1693
|
outputs = [];
|
1689
1694
|
/** List of witnesses */
|
1690
1695
|
witnesses = [];
|
1691
|
-
/** Base asset ID - should be fetched from the chain */
|
1692
|
-
baseAssetId;
|
1693
1696
|
/**
|
1694
1697
|
* Constructor for initializing a base transaction request.
|
1695
1698
|
*
|
@@ -1702,9 +1705,8 @@ var BaseTransactionRequest = class {
|
|
1702
1705
|
witnessLimit,
|
1703
1706
|
inputs,
|
1704
1707
|
outputs,
|
1705
|
-
witnesses
|
1706
|
-
|
1707
|
-
}) {
|
1708
|
+
witnesses
|
1709
|
+
} = {}) {
|
1708
1710
|
this.gasPrice = bn7(gasPrice);
|
1709
1711
|
this.maturity = maturity ?? 0;
|
1710
1712
|
this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
|
@@ -1712,7 +1714,6 @@ var BaseTransactionRequest = class {
|
|
1712
1714
|
this.inputs = inputs ?? [];
|
1713
1715
|
this.outputs = outputs ?? [];
|
1714
1716
|
this.witnesses = witnesses ?? [];
|
1715
|
-
this.baseAssetId = baseAssetId;
|
1716
1717
|
}
|
1717
1718
|
static getPolicyMeta(req) {
|
1718
1719
|
let policyTypes = 0;
|
@@ -1906,8 +1907,8 @@ var BaseTransactionRequest = class {
|
|
1906
1907
|
* @param predicate - Predicate bytes.
|
1907
1908
|
* @param predicateData - Predicate data bytes.
|
1908
1909
|
*/
|
1909
|
-
addCoinInput(coin
|
1910
|
-
const { assetId, owner, amount } = coin;
|
1910
|
+
addCoinInput(coin) {
|
1911
|
+
const { assetId, owner, amount, id, predicate } = coin;
|
1911
1912
|
let witnessIndex;
|
1912
1913
|
if (predicate) {
|
1913
1914
|
witnessIndex = 0;
|
@@ -1918,14 +1919,14 @@ var BaseTransactionRequest = class {
|
|
1918
1919
|
}
|
1919
1920
|
}
|
1920
1921
|
const input = {
|
1921
|
-
|
1922
|
+
id,
|
1922
1923
|
type: InputType2.Coin,
|
1923
1924
|
owner: owner.toB256(),
|
1924
1925
|
amount,
|
1925
1926
|
assetId,
|
1926
1927
|
txPointer: "0x00000000000000000000000000000000",
|
1927
1928
|
witnessIndex,
|
1928
|
-
predicate
|
1929
|
+
predicate
|
1929
1930
|
};
|
1930
1931
|
this.pushInput(input);
|
1931
1932
|
this.addChangeOutput(owner, assetId);
|
@@ -1936,9 +1937,11 @@ var BaseTransactionRequest = class {
|
|
1936
1937
|
*
|
1937
1938
|
* @param message - Message resource.
|
1938
1939
|
* @param predicate - Predicate bytes.
|
1940
|
+
* @param predicateData - Predicate data bytes.
|
1939
1941
|
*/
|
1940
|
-
addMessageInput(message
|
1941
|
-
const { recipient, sender, amount } = message;
|
1942
|
+
addMessageInput(message) {
|
1943
|
+
const { recipient, sender, amount, predicate, nonce } = message;
|
1944
|
+
const assetId = BaseAssetId2;
|
1942
1945
|
let witnessIndex;
|
1943
1946
|
if (predicate) {
|
1944
1947
|
witnessIndex = 0;
|
@@ -1949,16 +1952,16 @@ var BaseTransactionRequest = class {
|
|
1949
1952
|
}
|
1950
1953
|
}
|
1951
1954
|
const input = {
|
1952
|
-
|
1955
|
+
nonce,
|
1953
1956
|
type: InputType2.Message,
|
1954
1957
|
sender: sender.toB256(),
|
1955
1958
|
recipient: recipient.toB256(),
|
1956
1959
|
amount,
|
1957
1960
|
witnessIndex,
|
1958
|
-
predicate
|
1961
|
+
predicate
|
1959
1962
|
};
|
1960
1963
|
this.pushInput(input);
|
1961
|
-
this.addChangeOutput(recipient,
|
1964
|
+
this.addChangeOutput(recipient, assetId);
|
1962
1965
|
}
|
1963
1966
|
/**
|
1964
1967
|
* Adds a single resource to the transaction by adding a coin/message input and a
|
@@ -1986,32 +1989,6 @@ var BaseTransactionRequest = class {
|
|
1986
1989
|
resources.forEach((resource) => this.addResource(resource));
|
1987
1990
|
return this;
|
1988
1991
|
}
|
1989
|
-
/**
|
1990
|
-
* Adds multiple resources to the transaction by adding coin/message inputs and change
|
1991
|
-
* outputs from the related assetIds.
|
1992
|
-
*
|
1993
|
-
* @param resources - The resources to add.
|
1994
|
-
* @returns This transaction.
|
1995
|
-
*/
|
1996
|
-
addPredicateResource(resource, predicate) {
|
1997
|
-
if (isCoin(resource)) {
|
1998
|
-
this.addCoinInput(resource, predicate);
|
1999
|
-
} else {
|
2000
|
-
this.addMessageInput(resource, predicate);
|
2001
|
-
}
|
2002
|
-
return this;
|
2003
|
-
}
|
2004
|
-
/**
|
2005
|
-
* Adds multiple predicate coin/message inputs to the transaction and change outputs
|
2006
|
-
* from the related assetIds.
|
2007
|
-
*
|
2008
|
-
* @param resources - The resources to add.
|
2009
|
-
* @returns This transaction.
|
2010
|
-
*/
|
2011
|
-
addPredicateResources(resources, predicate) {
|
2012
|
-
resources.forEach((resource) => this.addPredicateResource(resource, predicate));
|
2013
|
-
return this;
|
2014
|
-
}
|
2015
1992
|
/**
|
2016
1993
|
* Adds a coin output to the transaction.
|
2017
1994
|
*
|
@@ -2019,12 +1996,12 @@ var BaseTransactionRequest = class {
|
|
2019
1996
|
* @param amount - Amount of coin.
|
2020
1997
|
* @param assetId - Asset ID of coin.
|
2021
1998
|
*/
|
2022
|
-
addCoinOutput(to, amount, assetId) {
|
1999
|
+
addCoinOutput(to, amount, assetId = BaseAssetId2) {
|
2023
2000
|
this.pushOutput({
|
2024
2001
|
type: OutputType2.Coin,
|
2025
2002
|
to: addressify(to).toB256(),
|
2026
2003
|
amount,
|
2027
|
-
assetId
|
2004
|
+
assetId
|
2028
2005
|
});
|
2029
2006
|
return this;
|
2030
2007
|
}
|
@@ -2051,7 +2028,7 @@ var BaseTransactionRequest = class {
|
|
2051
2028
|
* @param to - Address of the owner.
|
2052
2029
|
* @param assetId - Asset ID of coin.
|
2053
2030
|
*/
|
2054
|
-
addChangeOutput(to, assetId) {
|
2031
|
+
addChangeOutput(to, assetId = BaseAssetId2) {
|
2055
2032
|
const changeOutput = this.getChangeOutputs().find(
|
2056
2033
|
(output) => hexlify7(output.assetId) === assetId
|
2057
2034
|
);
|
@@ -2059,7 +2036,7 @@ var BaseTransactionRequest = class {
|
|
2059
2036
|
this.pushOutput({
|
2060
2037
|
type: OutputType2.Change,
|
2061
2038
|
to: addressify(to).toB256(),
|
2062
|
-
assetId
|
2039
|
+
assetId
|
2063
2040
|
});
|
2064
2041
|
}
|
2065
2042
|
}
|
@@ -2110,12 +2087,6 @@ var BaseTransactionRequest = class {
|
|
2110
2087
|
* @param quantities - CoinQuantity Array.
|
2111
2088
|
*/
|
2112
2089
|
fundWithFakeUtxos(quantities, resourcesOwner) {
|
2113
|
-
let idCounter = 0;
|
2114
|
-
const generateId = () => {
|
2115
|
-
const counterString = String(idCounter++);
|
2116
|
-
const id = ZeroBytes324.slice(0, -counterString.length).concat(counterString);
|
2117
|
-
return id;
|
2118
|
-
};
|
2119
2090
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
2120
2091
|
if ("assetId" in input) {
|
2121
2092
|
return input.assetId === assetId;
|
@@ -2125,12 +2096,12 @@ var BaseTransactionRequest = class {
|
|
2125
2096
|
const updateAssetInput = (assetId, quantity) => {
|
2126
2097
|
const assetInput = findAssetInput(assetId);
|
2127
2098
|
if (assetInput && "assetId" in assetInput) {
|
2128
|
-
assetInput.id =
|
2099
|
+
assetInput.id = hexlify7(randomBytes(UTXO_ID_LEN2));
|
2129
2100
|
assetInput.amount = quantity;
|
2130
2101
|
} else {
|
2131
2102
|
this.addResources([
|
2132
2103
|
{
|
2133
|
-
id:
|
2104
|
+
id: hexlify7(randomBytes(UTXO_ID_LEN2)),
|
2134
2105
|
amount: quantity,
|
2135
2106
|
assetId,
|
2136
2107
|
owner: resourcesOwner || Address.fromRandom(),
|
@@ -2141,7 +2112,7 @@ var BaseTransactionRequest = class {
|
|
2141
2112
|
]);
|
2142
2113
|
}
|
2143
2114
|
};
|
2144
|
-
updateAssetInput(
|
2115
|
+
updateAssetInput(BaseAssetId2, bn7(1e11));
|
2145
2116
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2146
2117
|
}
|
2147
2118
|
/**
|
@@ -2311,7 +2282,12 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2311
2282
|
*
|
2312
2283
|
* @param createTransactionRequestLike - The initial values for the instance
|
2313
2284
|
*/
|
2314
|
-
constructor({
|
2285
|
+
constructor({
|
2286
|
+
bytecodeWitnessIndex,
|
2287
|
+
salt,
|
2288
|
+
storageSlots,
|
2289
|
+
...rest
|
2290
|
+
} = {}) {
|
2315
2291
|
super(rest);
|
2316
2292
|
this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
|
2317
2293
|
this.salt = hexlify9(salt ?? ZeroBytes326);
|
@@ -2435,7 +2411,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2435
2411
|
*
|
2436
2412
|
* @param scriptTransactionRequestLike - The initial values for the instance.
|
2437
2413
|
*/
|
2438
|
-
constructor({ script, scriptData, gasLimit, ...rest }) {
|
2414
|
+
constructor({ script, scriptData, gasLimit, ...rest } = {}) {
|
2439
2415
|
super(rest);
|
2440
2416
|
this.gasLimit = bn10(gasLimit);
|
2441
2417
|
this.script = arrayify8(script ?? returnZeroScript.bytes);
|
@@ -3610,7 +3586,6 @@ var processGqlChain = (chain) => {
|
|
3610
3586
|
gasPerByte: bn15(feeParams.gasPerByte),
|
3611
3587
|
maxMessageDataLength: bn15(predicateParams.maxMessageDataLength),
|
3612
3588
|
chainId: bn15(consensusParameters.chainId),
|
3613
|
-
baseAssetId: consensusParameters.baseAssetId,
|
3614
3589
|
gasCosts
|
3615
3590
|
},
|
3616
3591
|
gasCosts,
|
@@ -3853,17 +3828,6 @@ var _Provider = class {
|
|
3853
3828
|
} = this.getChain();
|
3854
3829
|
return chainId.toNumber();
|
3855
3830
|
}
|
3856
|
-
/**
|
3857
|
-
* Returns the base asset ID
|
3858
|
-
*
|
3859
|
-
* @returns A promise that resolves to the base asset ID
|
3860
|
-
*/
|
3861
|
-
getBaseAssetId() {
|
3862
|
-
const {
|
3863
|
-
consensusParameters: { baseAssetId }
|
3864
|
-
} = this.getChain();
|
3865
|
-
return baseAssetId;
|
3866
|
-
}
|
3867
3831
|
/**
|
3868
3832
|
* Submits a transaction to the chain to be executed.
|
3869
3833
|
*
|
@@ -4014,6 +3978,36 @@ var _Provider = class {
|
|
4014
3978
|
missingContractIds
|
4015
3979
|
};
|
4016
3980
|
}
|
3981
|
+
/**
|
3982
|
+
* Estimates the transaction gas and fee based on the provided transaction request.
|
3983
|
+
* @param transactionRequest - The transaction request object.
|
3984
|
+
* @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
|
3985
|
+
*/
|
3986
|
+
estimateTxGasAndFee(params) {
|
3987
|
+
const { transactionRequest } = params;
|
3988
|
+
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
3989
|
+
const chainInfo = this.getChain();
|
3990
|
+
const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
|
3991
|
+
transactionRequest.gasPrice = gasPrice;
|
3992
|
+
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
3993
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3994
|
+
if (transactionRequest.type === TransactionType8.Script) {
|
3995
|
+
if (transactionRequest.gasLimit.eq(0)) {
|
3996
|
+
transactionRequest.gasLimit = minGas;
|
3997
|
+
transactionRequest.gasLimit = maxGasPerTx.sub(
|
3998
|
+
transactionRequest.calculateMaxGas(chainInfo, minGas)
|
3999
|
+
);
|
4000
|
+
}
|
4001
|
+
}
|
4002
|
+
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4003
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4004
|
+
return {
|
4005
|
+
minGas,
|
4006
|
+
minFee,
|
4007
|
+
maxGas,
|
4008
|
+
maxFee
|
4009
|
+
};
|
4010
|
+
}
|
4017
4011
|
/**
|
4018
4012
|
* Executes a signed transaction without applying the states changes
|
4019
4013
|
* on the chain.
|
@@ -4061,17 +4055,16 @@ var _Provider = class {
|
|
4061
4055
|
signatureCallback
|
4062
4056
|
} = {}) {
|
4063
4057
|
const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
|
4064
|
-
const
|
4065
|
-
const
|
4066
|
-
const gasPrice = max(txRequestClone.gasPrice, minGasPrice);
|
4058
|
+
const { minGasPrice } = this.getGasConfig();
|
4059
|
+
const setGasPrice = max(txRequestClone.gasPrice, minGasPrice);
|
4067
4060
|
const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
|
4068
4061
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
4069
4062
|
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
4070
4063
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4064
|
+
if (isScriptTransaction) {
|
4065
|
+
txRequestClone.gasLimit = bn15(0);
|
4066
|
+
}
|
4071
4067
|
if (estimatePredicates) {
|
4072
|
-
if (isScriptTransaction) {
|
4073
|
-
txRequestClone.gasLimit = bn15(0);
|
4074
|
-
}
|
4075
4068
|
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4076
4069
|
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
4077
4070
|
}
|
@@ -4080,36 +4073,34 @@ var _Provider = class {
|
|
4080
4073
|
if (signatureCallback && isScriptTransaction) {
|
4081
4074
|
await signatureCallback(txRequestClone);
|
4082
4075
|
}
|
4083
|
-
|
4084
|
-
|
4076
|
+
let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
4077
|
+
transactionRequest: txRequestClone
|
4078
|
+
});
|
4085
4079
|
let receipts = [];
|
4086
4080
|
let missingContractIds = [];
|
4087
4081
|
let outputVariables = 0;
|
4082
|
+
let gasUsed = bn15(0);
|
4088
4083
|
if (isScriptTransaction && estimateTxDependencies) {
|
4089
4084
|
txRequestClone.gasPrice = bn15(0);
|
4090
|
-
txRequestClone.gasLimit = bn15(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
|
4091
4085
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4092
4086
|
receipts = result.receipts;
|
4093
4087
|
outputVariables = result.outputVariables;
|
4094
4088
|
missingContractIds = result.missingContractIds;
|
4089
|
+
gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
|
4090
|
+
txRequestClone.gasLimit = gasUsed;
|
4091
|
+
txRequestClone.gasPrice = setGasPrice;
|
4092
|
+
({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
4093
|
+
transactionRequest: txRequestClone
|
4094
|
+
}));
|
4095
4095
|
}
|
4096
|
-
const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
|
4097
|
-
const usedFee = calculatePriceWithFactor(
|
4098
|
-
gasUsed,
|
4099
|
-
gasPrice,
|
4100
|
-
gasPriceFactor
|
4101
|
-
).normalizeZeroToOne();
|
4102
|
-
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4103
|
-
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4104
4096
|
return {
|
4105
4097
|
requiredQuantities: allQuantities,
|
4106
4098
|
receipts,
|
4107
4099
|
gasUsed,
|
4108
4100
|
minGasPrice,
|
4109
|
-
gasPrice,
|
4101
|
+
gasPrice: setGasPrice,
|
4110
4102
|
minGas,
|
4111
4103
|
maxGas,
|
4112
|
-
usedFee,
|
4113
4104
|
minFee,
|
4114
4105
|
maxFee,
|
4115
4106
|
estimatedInputs: txRequestClone.inputs,
|
@@ -4900,9 +4891,8 @@ var Account = class extends AbstractAccount {
|
|
4900
4891
|
* @param assetId - The asset ID to check the balance for.
|
4901
4892
|
* @returns A promise that resolves to the balance amount.
|
4902
4893
|
*/
|
4903
|
-
async getBalance(assetId) {
|
4904
|
-
const
|
4905
|
-
const amount = await this.provider.getBalance(this.address, assetIdToFetch);
|
4894
|
+
async getBalance(assetId = BaseAssetId3) {
|
4895
|
+
const amount = await this.provider.getBalance(this.address, assetId);
|
4906
4896
|
return amount;
|
4907
4897
|
}
|
4908
4898
|
/**
|
@@ -4940,10 +4930,9 @@ var Account = class extends AbstractAccount {
|
|
4940
4930
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4941
4931
|
*/
|
4942
4932
|
async fund(request, coinQuantities, fee) {
|
4943
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
4944
4933
|
const updatedQuantities = addAmountToAsset({
|
4945
4934
|
amount: bn17(fee),
|
4946
|
-
assetId:
|
4935
|
+
assetId: BaseAssetId3,
|
4947
4936
|
coinQuantities
|
4948
4937
|
});
|
4949
4938
|
const quantitiesDict = {};
|
@@ -4967,8 +4956,8 @@ var Account = class extends AbstractAccount {
|
|
4967
4956
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4968
4957
|
cachedUtxos.push(input.id);
|
4969
4958
|
}
|
4970
|
-
} else if (input.recipient === owner && input.amount && quantitiesDict[
|
4971
|
-
quantitiesDict[
|
4959
|
+
} else if (input.recipient === owner && input.amount && quantitiesDict[BaseAssetId3]) {
|
4960
|
+
quantitiesDict[BaseAssetId3].owned = quantitiesDict[BaseAssetId3].owned.add(input.amount);
|
4972
4961
|
cachedMessages.push(input.nonce);
|
4973
4962
|
}
|
4974
4963
|
}
|
@@ -5000,13 +4989,11 @@ var Account = class extends AbstractAccount {
|
|
5000
4989
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
5001
4990
|
* @returns A promise that resolves to the prepared transaction request.
|
5002
4991
|
*/
|
5003
|
-
async createTransfer(destination, amount, assetId, txParams = {}) {
|
4992
|
+
async createTransfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
5004
4993
|
const { minGasPrice } = this.provider.getGasConfig();
|
5005
|
-
const
|
5006
|
-
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
5007
|
-
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
4994
|
+
const params = { gasPrice: minGasPrice, ...txParams };
|
5008
4995
|
const request = new ScriptTransactionRequest(params);
|
5009
|
-
request.addCoinOutput(Address3.fromAddressOrString(destination), amount,
|
4996
|
+
request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetId);
|
5010
4997
|
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
5011
4998
|
estimateTxDependencies: true,
|
5012
4999
|
resourcesOwner: this
|
@@ -5032,15 +5019,14 @@ var Account = class extends AbstractAccount {
|
|
5032
5019
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
5033
5020
|
* @returns A promise that resolves to the transaction response.
|
5034
5021
|
*/
|
5035
|
-
async transfer(destination, amount, assetId, txParams = {}) {
|
5022
|
+
async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
5036
5023
|
if (bn17(amount).lte(0)) {
|
5037
5024
|
throw new FuelError15(
|
5038
5025
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
5039
5026
|
"Transfer amount must be a positive number."
|
5040
5027
|
);
|
5041
5028
|
}
|
5042
|
-
const
|
5043
|
-
const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
5029
|
+
const request = await this.createTransfer(destination, amount, assetId, txParams);
|
5044
5030
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
5045
5031
|
}
|
5046
5032
|
/**
|
@@ -5052,7 +5038,7 @@ var Account = class extends AbstractAccount {
|
|
5052
5038
|
* @param txParams - The optional transaction parameters.
|
5053
5039
|
* @returns A promise that resolves to the transaction response.
|
5054
5040
|
*/
|
5055
|
-
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
5041
|
+
async transferToContract(contractId, amount, assetId = BaseAssetId3, txParams = {}) {
|
5056
5042
|
if (bn17(amount).lte(0)) {
|
5057
5043
|
throw new FuelError15(
|
5058
5044
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
@@ -5061,13 +5047,11 @@ var Account = class extends AbstractAccount {
|
|
5061
5047
|
}
|
5062
5048
|
const contractAddress = Address3.fromAddressOrString(contractId);
|
5063
5049
|
const { minGasPrice } = this.provider.getGasConfig();
|
5064
|
-
const
|
5065
|
-
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
5066
|
-
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
5050
|
+
const params = { gasPrice: minGasPrice, ...txParams };
|
5067
5051
|
const { script, scriptData } = await assembleTransferToContractScript({
|
5068
5052
|
hexlifiedContractId: contractAddress.toB256(),
|
5069
5053
|
amountToTransfer: bn17(amount),
|
5070
|
-
assetId
|
5054
|
+
assetId
|
5071
5055
|
});
|
5072
5056
|
const request = new ScriptTransactionRequest({
|
5073
5057
|
...params,
|
@@ -5077,7 +5061,7 @@ var Account = class extends AbstractAccount {
|
|
5077
5061
|
request.addContractInputAndOutput(contractAddress);
|
5078
5062
|
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
5079
5063
|
request,
|
5080
|
-
[{ amount: bn17(amount), assetId: String(
|
5064
|
+
[{ amount: bn17(amount), assetId: String(assetId) }]
|
5081
5065
|
);
|
5082
5066
|
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
5083
5067
|
this.validateGas({
|
@@ -5099,7 +5083,6 @@ var Account = class extends AbstractAccount {
|
|
5099
5083
|
*/
|
5100
5084
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
5101
5085
|
const { minGasPrice } = this.provider.getGasConfig();
|
5102
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
5103
5086
|
const recipientAddress = Address3.fromAddressOrString(recipient);
|
5104
5087
|
const recipientDataArray = arrayify14(
|
5105
5088
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
@@ -5112,14 +5095,9 @@ var Account = class extends AbstractAccount {
|
|
5112
5095
|
...recipientDataArray,
|
5113
5096
|
...amountDataArray
|
5114
5097
|
]);
|
5115
|
-
const params = {
|
5116
|
-
script,
|
5117
|
-
gasPrice: minGasPrice,
|
5118
|
-
baseAssetId,
|
5119
|
-
...txParams
|
5120
|
-
};
|
5098
|
+
const params = { script, gasPrice: minGasPrice, ...txParams };
|
5121
5099
|
const request = new ScriptTransactionRequest(params);
|
5122
|
-
const forwardingQuantities = [{ amount: bn17(amount), assetId:
|
5100
|
+
const forwardingQuantities = [{ amount: bn17(amount), assetId: BaseAssetId3 }];
|
5123
5101
|
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
5124
5102
|
request,
|
5125
5103
|
forwardingQuantities
|
@@ -5216,7 +5194,7 @@ import { hexlify as hexlify15 } from "@fuel-ts/utils";
|
|
5216
5194
|
|
5217
5195
|
// src/signer/signer.ts
|
5218
5196
|
import { Address as Address4 } from "@fuel-ts/address";
|
5219
|
-
import { randomBytes } from "@fuel-ts/crypto";
|
5197
|
+
import { randomBytes as randomBytes2 } from "@fuel-ts/crypto";
|
5220
5198
|
import { hash } from "@fuel-ts/hasher";
|
5221
5199
|
import { toBytes } from "@fuel-ts/math";
|
5222
5200
|
import { hexlify as hexlify13, concat as concat3, arrayify as arrayify15 } from "@fuel-ts/utils";
|
@@ -5309,7 +5287,7 @@ var Signer = class {
|
|
5309
5287
|
* @returns random 32-byte hashed
|
5310
5288
|
*/
|
5311
5289
|
static generatePrivateKey(entropy) {
|
5312
|
-
return entropy ? hash(concat3([
|
5290
|
+
return entropy ? hash(concat3([randomBytes2(32), arrayify15(entropy)])) : randomBytes2(32);
|
5313
5291
|
}
|
5314
5292
|
/**
|
5315
5293
|
* Extended publicKey from a compact publicKey
|
@@ -5328,7 +5306,7 @@ import { Address as Address5 } from "@fuel-ts/address";
|
|
5328
5306
|
import {
|
5329
5307
|
bufferFromString,
|
5330
5308
|
keccak256,
|
5331
|
-
randomBytes as
|
5309
|
+
randomBytes as randomBytes3,
|
5332
5310
|
scrypt,
|
5333
5311
|
stringFromBuffer,
|
5334
5312
|
decryptJsonWalletData,
|
@@ -5351,7 +5329,7 @@ var removeHexPrefix = (hexString) => {
|
|
5351
5329
|
async function encryptKeystoreWallet(privateKey, address, password) {
|
5352
5330
|
const privateKeyBuffer = bufferFromString(removeHexPrefix(privateKey), "hex");
|
5353
5331
|
const ownerAddress = Address5.fromAddressOrString(address);
|
5354
|
-
const salt =
|
5332
|
+
const salt = randomBytes3(DEFAULT_KEY_SIZE);
|
5355
5333
|
const key = scrypt({
|
5356
5334
|
password: bufferFromString(password),
|
5357
5335
|
salt,
|
@@ -5360,7 +5338,7 @@ async function encryptKeystoreWallet(privateKey, address, password) {
|
|
5360
5338
|
r: DEFAULT_KDF_PARAMS_R,
|
5361
5339
|
p: DEFAULT_KDF_PARAMS_P
|
5362
5340
|
});
|
5363
|
-
const iv =
|
5341
|
+
const iv = randomBytes3(DEFAULT_IV_SIZE);
|
5364
5342
|
const ciphertext = await encryptJsonWalletData(privateKeyBuffer, key, iv);
|
5365
5343
|
const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertext]);
|
5366
5344
|
const macHashUint8Array = keccak256(data);
|
@@ -5542,7 +5520,7 @@ import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from
|
|
5542
5520
|
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5543
5521
|
|
5544
5522
|
// src/mnemonic/mnemonic.ts
|
5545
|
-
import { randomBytes as
|
5523
|
+
import { randomBytes as randomBytes4 } from "@fuel-ts/crypto";
|
5546
5524
|
import { ErrorCode as ErrorCode18, FuelError as FuelError18 } from "@fuel-ts/errors";
|
5547
5525
|
import { sha256 as sha2563 } from "@fuel-ts/hasher";
|
5548
5526
|
import { arrayify as arrayify17, hexlify as hexlify16, concat as concat4 } from "@fuel-ts/utils";
|
@@ -7903,7 +7881,7 @@ var Mnemonic = class {
|
|
7903
7881
|
* @returns A randomly generated mnemonic
|
7904
7882
|
*/
|
7905
7883
|
static generate(size = 32, extraEntropy = "") {
|
7906
|
-
const entropy = extraEntropy ? sha2563(concat4([
|
7884
|
+
const entropy = extraEntropy ? sha2563(concat4([randomBytes4(size), arrayify17(extraEntropy)])) : randomBytes4(size);
|
7907
7885
|
return Mnemonic.entropyToMnemonic(entropy);
|
7908
7886
|
}
|
7909
7887
|
};
|
@@ -8696,6 +8674,7 @@ import {
|
|
8696
8674
|
SCRIPT_FIXED_SIZE
|
8697
8675
|
} from "@fuel-ts/abi-coder";
|
8698
8676
|
import { Address as Address9 } from "@fuel-ts/address";
|
8677
|
+
import { BaseAssetId as BaseAssetId4 } from "@fuel-ts/address/configs";
|
8699
8678
|
import { ErrorCode as ErrorCode24, FuelError as FuelError24 } from "@fuel-ts/errors";
|
8700
8679
|
import { ByteArrayCoder, InputType as InputType7 } from "@fuel-ts/transactions";
|
8701
8680
|
import { arrayify as arrayify20, hexlify as hexlify19 } from "@fuel-ts/utils";
|
@@ -8760,6 +8739,7 @@ var Predicate = class extends Account {
|
|
8760
8739
|
if (input.type === InputType7.Coin && hexlify19(input.owner) === this.address.toB256()) {
|
8761
8740
|
input.predicate = this.bytes;
|
8762
8741
|
input.predicateData = this.getPredicateData(policies.length);
|
8742
|
+
input.witnessIndex = 0;
|
8763
8743
|
}
|
8764
8744
|
});
|
8765
8745
|
return request;
|
@@ -8773,9 +8753,8 @@ var Predicate = class extends Account {
|
|
8773
8753
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
8774
8754
|
* @returns A promise that resolves to the prepared transaction request.
|
8775
8755
|
*/
|
8776
|
-
async createTransfer(destination, amount, assetId, txParams = {}) {
|
8777
|
-
const
|
8778
|
-
const request = await super.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
8756
|
+
async createTransfer(destination, amount, assetId = BaseAssetId4, txParams = {}) {
|
8757
|
+
const request = await super.createTransfer(destination, amount, assetId, txParams);
|
8779
8758
|
return this.populateTransactionPredicateData(request);
|
8780
8759
|
}
|
8781
8760
|
/**
|
@@ -8798,6 +8777,20 @@ var Predicate = class extends Account {
|
|
8798
8777
|
const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
|
8799
8778
|
return super.simulateTransaction(transactionRequest);
|
8800
8779
|
}
|
8780
|
+
/**
|
8781
|
+
* Retrieves resources satisfying the spend query for the account.
|
8782
|
+
*
|
8783
|
+
* @param quantities - IDs of coins to exclude.
|
8784
|
+
* @param excludedIds - IDs of resources to be excluded from the query.
|
8785
|
+
* @returns A promise that resolves to an array of Resources.
|
8786
|
+
*/
|
8787
|
+
async getResourcesToSpend(quantities, excludedIds) {
|
8788
|
+
const resources = await super.getResourcesToSpend(quantities, excludedIds);
|
8789
|
+
return resources.map((resource) => ({
|
8790
|
+
...resource,
|
8791
|
+
predicate: hexlify19(this.bytes)
|
8792
|
+
}));
|
8793
|
+
}
|
8801
8794
|
getPredicateData(policiesLength) {
|
8802
8795
|
if (!this.predicateData.length) {
|
8803
8796
|
return new Uint8Array();
|