@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/test-utils.js
CHANGED
@@ -62,12 +62,14 @@ var import_utils31 = require("@fuel-ts/utils");
|
|
62
62
|
|
63
63
|
// src/account.ts
|
64
64
|
var import_address4 = require("@fuel-ts/address");
|
65
|
+
var import_configs12 = require("@fuel-ts/address/configs");
|
65
66
|
var import_errors16 = require("@fuel-ts/errors");
|
66
67
|
var import_interfaces = require("@fuel-ts/interfaces");
|
67
68
|
var import_math18 = require("@fuel-ts/math");
|
68
69
|
var import_utils28 = require("@fuel-ts/utils");
|
69
70
|
|
70
71
|
// src/providers/coin-quantity.ts
|
72
|
+
var import_configs = require("@fuel-ts/address/configs");
|
71
73
|
var import_math = require("@fuel-ts/math");
|
72
74
|
var import_utils = require("@fuel-ts/utils");
|
73
75
|
var coinQuantityfy = (coinQuantityLike) => {
|
@@ -76,11 +78,11 @@ var coinQuantityfy = (coinQuantityLike) => {
|
|
76
78
|
let max2;
|
77
79
|
if (Array.isArray(coinQuantityLike)) {
|
78
80
|
amount = coinQuantityLike[0];
|
79
|
-
assetId = coinQuantityLike[1];
|
80
|
-
max2 = coinQuantityLike[2];
|
81
|
+
assetId = coinQuantityLike[1] ?? import_configs.BaseAssetId;
|
82
|
+
max2 = coinQuantityLike[2] ?? void 0;
|
81
83
|
} else {
|
82
84
|
amount = coinQuantityLike.amount;
|
83
|
-
assetId = coinQuantityLike.assetId;
|
85
|
+
assetId = coinQuantityLike.assetId ?? import_configs.BaseAssetId;
|
84
86
|
max2 = coinQuantityLike.max ?? void 0;
|
85
87
|
}
|
86
88
|
const bnAmount = (0, import_math.bn)(amount);
|
@@ -1049,7 +1051,8 @@ var MemoryCache = class {
|
|
1049
1051
|
};
|
1050
1052
|
|
1051
1053
|
// src/providers/transaction-request/input.ts
|
1052
|
-
var
|
1054
|
+
var import_abi_coder = require("@fuel-ts/abi-coder");
|
1055
|
+
var import_configs2 = require("@fuel-ts/address/configs");
|
1053
1056
|
var import_errors3 = require("@fuel-ts/errors");
|
1054
1057
|
var import_math2 = require("@fuel-ts/math");
|
1055
1058
|
var import_transactions = require("@fuel-ts/transactions");
|
@@ -1062,8 +1065,8 @@ var inputify = (value) => {
|
|
1062
1065
|
const predicateData = (0, import_utils3.arrayify)(value.predicateData ?? "0x");
|
1063
1066
|
return {
|
1064
1067
|
type: import_transactions.InputType.Coin,
|
1065
|
-
txID: (0, import_utils3.hexlify)((0, import_utils3.arrayify)(value.id).slice(0,
|
1066
|
-
outputIndex: (0, import_utils3.arrayify)(value.id)
|
1068
|
+
txID: (0, import_utils3.hexlify)((0, import_utils3.arrayify)(value.id).slice(0, import_abi_coder.BYTES_32)),
|
1069
|
+
outputIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.id).slice(import_abi_coder.BYTES_32, import_abi_coder.UTXO_ID_LEN)),
|
1067
1070
|
owner: (0, import_utils3.hexlify)(value.owner),
|
1068
1071
|
amount: (0, import_math2.bn)(value.amount),
|
1069
1072
|
assetId: (0, import_utils3.hexlify)(value.assetId),
|
@@ -1083,10 +1086,10 @@ var inputify = (value) => {
|
|
1083
1086
|
case import_transactions.InputType.Contract: {
|
1084
1087
|
return {
|
1085
1088
|
type: import_transactions.InputType.Contract,
|
1086
|
-
txID:
|
1089
|
+
txID: import_configs2.ZeroBytes32,
|
1087
1090
|
outputIndex: 0,
|
1088
|
-
balanceRoot:
|
1089
|
-
stateRoot:
|
1091
|
+
balanceRoot: import_configs2.ZeroBytes32,
|
1092
|
+
stateRoot: import_configs2.ZeroBytes32,
|
1090
1093
|
txPointer: {
|
1091
1094
|
blockHeight: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(0, 8)),
|
1092
1095
|
txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
|
@@ -1124,7 +1127,7 @@ var inputify = (value) => {
|
|
1124
1127
|
};
|
1125
1128
|
|
1126
1129
|
// src/providers/transaction-request/output.ts
|
1127
|
-
var
|
1130
|
+
var import_configs3 = require("@fuel-ts/address/configs");
|
1128
1131
|
var import_errors4 = require("@fuel-ts/errors");
|
1129
1132
|
var import_math3 = require("@fuel-ts/math");
|
1130
1133
|
var import_transactions2 = require("@fuel-ts/transactions");
|
@@ -1144,8 +1147,8 @@ var outputify = (value) => {
|
|
1144
1147
|
return {
|
1145
1148
|
type: import_transactions2.OutputType.Contract,
|
1146
1149
|
inputIndex: value.inputIndex,
|
1147
|
-
balanceRoot:
|
1148
|
-
stateRoot:
|
1150
|
+
balanceRoot: import_configs3.ZeroBytes32,
|
1151
|
+
stateRoot: import_configs3.ZeroBytes32
|
1149
1152
|
};
|
1150
1153
|
}
|
1151
1154
|
case import_transactions2.OutputType.Change: {
|
@@ -1159,9 +1162,9 @@ var outputify = (value) => {
|
|
1159
1162
|
case import_transactions2.OutputType.Variable: {
|
1160
1163
|
return {
|
1161
1164
|
type: import_transactions2.OutputType.Variable,
|
1162
|
-
to:
|
1165
|
+
to: import_configs3.ZeroBytes32,
|
1163
1166
|
amount: (0, import_math3.bn)(0),
|
1164
|
-
assetId:
|
1167
|
+
assetId: import_configs3.ZeroBytes32
|
1165
1168
|
};
|
1166
1169
|
}
|
1167
1170
|
case import_transactions2.OutputType.ContractCreated: {
|
@@ -1181,8 +1184,10 @@ var outputify = (value) => {
|
|
1181
1184
|
};
|
1182
1185
|
|
1183
1186
|
// src/providers/transaction-request/transaction-request.ts
|
1187
|
+
var import_abi_coder2 = require("@fuel-ts/abi-coder");
|
1184
1188
|
var import_address = require("@fuel-ts/address");
|
1185
|
-
var
|
1189
|
+
var import_configs7 = require("@fuel-ts/address/configs");
|
1190
|
+
var import_crypto = require("@fuel-ts/crypto");
|
1186
1191
|
var import_math7 = require("@fuel-ts/math");
|
1187
1192
|
var import_transactions6 = require("@fuel-ts/transactions");
|
1188
1193
|
var import_utils9 = require("@fuel-ts/utils");
|
@@ -1191,13 +1196,13 @@ var import_utils9 = require("@fuel-ts/utils");
|
|
1191
1196
|
var isCoin = (resource) => "id" in resource;
|
1192
1197
|
|
1193
1198
|
// src/providers/utils/receipts.ts
|
1194
|
-
var
|
1199
|
+
var import_configs4 = require("@fuel-ts/address/configs");
|
1195
1200
|
var import_errors5 = require("@fuel-ts/errors");
|
1196
1201
|
var import_math4 = require("@fuel-ts/math");
|
1197
1202
|
var import_transactions3 = require("@fuel-ts/transactions");
|
1198
|
-
var
|
1203
|
+
var import_configs5 = require("@fuel-ts/transactions/configs");
|
1199
1204
|
var import_utils5 = require("@fuel-ts/utils");
|
1200
|
-
var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions3.ReceiptType.Revert && receipt.val.toString("hex") ===
|
1205
|
+
var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions3.ReceiptType.Revert && receipt.val.toString("hex") === import_configs5.FAILED_TRANSFER_TO_ADDRESS_SIGNAL;
|
1201
1206
|
var doesReceiptHaveMissingContractId = (receipt) => receipt.type === import_transactions3.ReceiptType.Panic && receipt.contractId !== "0x0000000000000000000000000000000000000000000000000000000000000000";
|
1202
1207
|
var getReceiptsWithMissingData = (receipts) => receipts.reduce(
|
1203
1208
|
(memo, receipt) => {
|
@@ -1214,7 +1219,7 @@ var getReceiptsWithMissingData = (receipts) => receipts.reduce(
|
|
1214
1219
|
missingOutputContractIds: []
|
1215
1220
|
}
|
1216
1221
|
);
|
1217
|
-
var hexOrZero = (hex) => hex ||
|
1222
|
+
var hexOrZero = (hex) => hex || import_configs4.ZeroBytes32;
|
1218
1223
|
function assembleReceiptByType(receipt) {
|
1219
1224
|
const { receiptType } = receipt;
|
1220
1225
|
switch (receiptType) {
|
@@ -1519,16 +1524,16 @@ function sleep(time) {
|
|
1519
1524
|
var import_errors7 = require("@fuel-ts/errors");
|
1520
1525
|
var import_math6 = require("@fuel-ts/math");
|
1521
1526
|
var import_transactions5 = require("@fuel-ts/transactions");
|
1522
|
-
var
|
1527
|
+
var import_configs6 = require("@fuel-ts/transactions/configs");
|
1523
1528
|
var assemblePanicError = (status) => {
|
1524
1529
|
let errorMessage = `The transaction reverted with reason: "${status.reason}".`;
|
1525
1530
|
const reason = status.reason;
|
1526
|
-
if (
|
1531
|
+
if (import_configs6.PANIC_REASONS.includes(status.reason)) {
|
1527
1532
|
errorMessage = `${errorMessage}
|
1528
1533
|
|
1529
1534
|
You can read more about this error at:
|
1530
1535
|
|
1531
|
-
${
|
1536
|
+
${import_configs6.PANIC_DOC_URL}#variant.${status.reason}`;
|
1532
1537
|
}
|
1533
1538
|
return { errorMessage, reason };
|
1534
1539
|
};
|
@@ -1540,28 +1545,28 @@ var assembleRevertError = (receipts, logs) => {
|
|
1540
1545
|
if (revertReceipt) {
|
1541
1546
|
const reasonHex = (0, import_math6.bn)(revertReceipt.val).toHex();
|
1542
1547
|
switch (reasonHex) {
|
1543
|
-
case
|
1548
|
+
case import_configs6.FAILED_REQUIRE_SIGNAL: {
|
1544
1549
|
reason = "require";
|
1545
1550
|
errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(logs[0]) : "an error."}.`;
|
1546
1551
|
break;
|
1547
1552
|
}
|
1548
|
-
case
|
1553
|
+
case import_configs6.FAILED_ASSERT_EQ_SIGNAL: {
|
1549
1554
|
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1550
1555
|
reason = "assert_eq";
|
1551
1556
|
errorMessage = `The transaction reverted because of an "assert_eq" statement${sufix}`;
|
1552
1557
|
break;
|
1553
1558
|
}
|
1554
|
-
case
|
1559
|
+
case import_configs6.FAILED_ASSERT_NE_SIGNAL: {
|
1555
1560
|
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1556
1561
|
reason = "assert_ne";
|
1557
1562
|
errorMessage = `The transaction reverted because of an "assert_ne" statement${sufix}`;
|
1558
1563
|
break;
|
1559
1564
|
}
|
1560
|
-
case
|
1565
|
+
case import_configs6.FAILED_ASSERT_SIGNAL:
|
1561
1566
|
reason = "assert";
|
1562
1567
|
errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
|
1563
1568
|
break;
|
1564
|
-
case
|
1569
|
+
case import_configs6.FAILED_TRANSFER_TO_ADDRESS_SIGNAL:
|
1565
1570
|
reason = "MissingOutputChange";
|
1566
1571
|
errorMessage = `The transaction reverted because it's missing an "OutputChange".`;
|
1567
1572
|
break;
|
@@ -1623,8 +1628,6 @@ var BaseTransactionRequest = class {
|
|
1623
1628
|
outputs = [];
|
1624
1629
|
/** List of witnesses */
|
1625
1630
|
witnesses = [];
|
1626
|
-
/** Base asset ID - should be fetched from the chain */
|
1627
|
-
baseAssetId;
|
1628
1631
|
/**
|
1629
1632
|
* Constructor for initializing a base transaction request.
|
1630
1633
|
*
|
@@ -1637,9 +1640,8 @@ var BaseTransactionRequest = class {
|
|
1637
1640
|
witnessLimit,
|
1638
1641
|
inputs,
|
1639
1642
|
outputs,
|
1640
|
-
witnesses
|
1641
|
-
|
1642
|
-
}) {
|
1643
|
+
witnesses
|
1644
|
+
} = {}) {
|
1643
1645
|
this.gasPrice = (0, import_math7.bn)(gasPrice);
|
1644
1646
|
this.maturity = maturity ?? 0;
|
1645
1647
|
this.witnessLimit = witnessLimit ? (0, import_math7.bn)(witnessLimit) : void 0;
|
@@ -1647,7 +1649,6 @@ var BaseTransactionRequest = class {
|
|
1647
1649
|
this.inputs = inputs ?? [];
|
1648
1650
|
this.outputs = outputs ?? [];
|
1649
1651
|
this.witnesses = witnesses ?? [];
|
1650
|
-
this.baseAssetId = baseAssetId;
|
1651
1652
|
}
|
1652
1653
|
static getPolicyMeta(req) {
|
1653
1654
|
let policyTypes = 0;
|
@@ -1740,7 +1741,7 @@ var BaseTransactionRequest = class {
|
|
1740
1741
|
* @returns The index of the created witness.
|
1741
1742
|
*/
|
1742
1743
|
addEmptyWitness() {
|
1743
|
-
this.addWitness((0, import_utils9.concat)([
|
1744
|
+
this.addWitness((0, import_utils9.concat)([import_configs7.ZeroBytes32, import_configs7.ZeroBytes32]));
|
1744
1745
|
return this.witnesses.length - 1;
|
1745
1746
|
}
|
1746
1747
|
/**
|
@@ -1841,8 +1842,8 @@ var BaseTransactionRequest = class {
|
|
1841
1842
|
* @param predicate - Predicate bytes.
|
1842
1843
|
* @param predicateData - Predicate data bytes.
|
1843
1844
|
*/
|
1844
|
-
addCoinInput(coin
|
1845
|
-
const { assetId, owner, amount } = coin;
|
1845
|
+
addCoinInput(coin) {
|
1846
|
+
const { assetId, owner, amount, id, predicate } = coin;
|
1846
1847
|
let witnessIndex;
|
1847
1848
|
if (predicate) {
|
1848
1849
|
witnessIndex = 0;
|
@@ -1853,14 +1854,14 @@ var BaseTransactionRequest = class {
|
|
1853
1854
|
}
|
1854
1855
|
}
|
1855
1856
|
const input = {
|
1856
|
-
|
1857
|
+
id,
|
1857
1858
|
type: import_transactions6.InputType.Coin,
|
1858
1859
|
owner: owner.toB256(),
|
1859
1860
|
amount,
|
1860
1861
|
assetId,
|
1861
1862
|
txPointer: "0x00000000000000000000000000000000",
|
1862
1863
|
witnessIndex,
|
1863
|
-
predicate
|
1864
|
+
predicate
|
1864
1865
|
};
|
1865
1866
|
this.pushInput(input);
|
1866
1867
|
this.addChangeOutput(owner, assetId);
|
@@ -1871,9 +1872,11 @@ var BaseTransactionRequest = class {
|
|
1871
1872
|
*
|
1872
1873
|
* @param message - Message resource.
|
1873
1874
|
* @param predicate - Predicate bytes.
|
1875
|
+
* @param predicateData - Predicate data bytes.
|
1874
1876
|
*/
|
1875
|
-
addMessageInput(message
|
1876
|
-
const { recipient, sender, amount } = message;
|
1877
|
+
addMessageInput(message) {
|
1878
|
+
const { recipient, sender, amount, predicate, nonce } = message;
|
1879
|
+
const assetId = import_configs7.BaseAssetId;
|
1877
1880
|
let witnessIndex;
|
1878
1881
|
if (predicate) {
|
1879
1882
|
witnessIndex = 0;
|
@@ -1884,16 +1887,16 @@ var BaseTransactionRequest = class {
|
|
1884
1887
|
}
|
1885
1888
|
}
|
1886
1889
|
const input = {
|
1887
|
-
|
1890
|
+
nonce,
|
1888
1891
|
type: import_transactions6.InputType.Message,
|
1889
1892
|
sender: sender.toB256(),
|
1890
1893
|
recipient: recipient.toB256(),
|
1891
1894
|
amount,
|
1892
1895
|
witnessIndex,
|
1893
|
-
predicate
|
1896
|
+
predicate
|
1894
1897
|
};
|
1895
1898
|
this.pushInput(input);
|
1896
|
-
this.addChangeOutput(recipient,
|
1899
|
+
this.addChangeOutput(recipient, assetId);
|
1897
1900
|
}
|
1898
1901
|
/**
|
1899
1902
|
* Adds a single resource to the transaction by adding a coin/message input and a
|
@@ -1921,32 +1924,6 @@ var BaseTransactionRequest = class {
|
|
1921
1924
|
resources.forEach((resource) => this.addResource(resource));
|
1922
1925
|
return this;
|
1923
1926
|
}
|
1924
|
-
/**
|
1925
|
-
* Adds multiple resources to the transaction by adding coin/message inputs and change
|
1926
|
-
* outputs from the related assetIds.
|
1927
|
-
*
|
1928
|
-
* @param resources - The resources to add.
|
1929
|
-
* @returns This transaction.
|
1930
|
-
*/
|
1931
|
-
addPredicateResource(resource, predicate) {
|
1932
|
-
if (isCoin(resource)) {
|
1933
|
-
this.addCoinInput(resource, predicate);
|
1934
|
-
} else {
|
1935
|
-
this.addMessageInput(resource, predicate);
|
1936
|
-
}
|
1937
|
-
return this;
|
1938
|
-
}
|
1939
|
-
/**
|
1940
|
-
* Adds multiple predicate coin/message inputs to the transaction and change outputs
|
1941
|
-
* from the related assetIds.
|
1942
|
-
*
|
1943
|
-
* @param resources - The resources to add.
|
1944
|
-
* @returns This transaction.
|
1945
|
-
*/
|
1946
|
-
addPredicateResources(resources, predicate) {
|
1947
|
-
resources.forEach((resource) => this.addPredicateResource(resource, predicate));
|
1948
|
-
return this;
|
1949
|
-
}
|
1950
1927
|
/**
|
1951
1928
|
* Adds a coin output to the transaction.
|
1952
1929
|
*
|
@@ -1954,12 +1931,12 @@ var BaseTransactionRequest = class {
|
|
1954
1931
|
* @param amount - Amount of coin.
|
1955
1932
|
* @param assetId - Asset ID of coin.
|
1956
1933
|
*/
|
1957
|
-
addCoinOutput(to, amount, assetId) {
|
1934
|
+
addCoinOutput(to, amount, assetId = import_configs7.BaseAssetId) {
|
1958
1935
|
this.pushOutput({
|
1959
1936
|
type: import_transactions6.OutputType.Coin,
|
1960
1937
|
to: (0, import_address.addressify)(to).toB256(),
|
1961
1938
|
amount,
|
1962
|
-
assetId
|
1939
|
+
assetId
|
1963
1940
|
});
|
1964
1941
|
return this;
|
1965
1942
|
}
|
@@ -1986,7 +1963,7 @@ var BaseTransactionRequest = class {
|
|
1986
1963
|
* @param to - Address of the owner.
|
1987
1964
|
* @param assetId - Asset ID of coin.
|
1988
1965
|
*/
|
1989
|
-
addChangeOutput(to, assetId) {
|
1966
|
+
addChangeOutput(to, assetId = import_configs7.BaseAssetId) {
|
1990
1967
|
const changeOutput = this.getChangeOutputs().find(
|
1991
1968
|
(output) => (0, import_utils9.hexlify)(output.assetId) === assetId
|
1992
1969
|
);
|
@@ -1994,7 +1971,7 @@ var BaseTransactionRequest = class {
|
|
1994
1971
|
this.pushOutput({
|
1995
1972
|
type: import_transactions6.OutputType.Change,
|
1996
1973
|
to: (0, import_address.addressify)(to).toB256(),
|
1997
|
-
assetId
|
1974
|
+
assetId
|
1998
1975
|
});
|
1999
1976
|
}
|
2000
1977
|
}
|
@@ -2045,12 +2022,6 @@ var BaseTransactionRequest = class {
|
|
2045
2022
|
* @param quantities - CoinQuantity Array.
|
2046
2023
|
*/
|
2047
2024
|
fundWithFakeUtxos(quantities, resourcesOwner) {
|
2048
|
-
let idCounter = 0;
|
2049
|
-
const generateId = () => {
|
2050
|
-
const counterString = String(idCounter++);
|
2051
|
-
const id = import_configs6.ZeroBytes32.slice(0, -counterString.length).concat(counterString);
|
2052
|
-
return id;
|
2053
|
-
};
|
2054
2025
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
2055
2026
|
if ("assetId" in input) {
|
2056
2027
|
return input.assetId === assetId;
|
@@ -2060,12 +2031,12 @@ var BaseTransactionRequest = class {
|
|
2060
2031
|
const updateAssetInput = (assetId, quantity) => {
|
2061
2032
|
const assetInput = findAssetInput(assetId);
|
2062
2033
|
if (assetInput && "assetId" in assetInput) {
|
2063
|
-
assetInput.id =
|
2034
|
+
assetInput.id = (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN));
|
2064
2035
|
assetInput.amount = quantity;
|
2065
2036
|
} else {
|
2066
2037
|
this.addResources([
|
2067
2038
|
{
|
2068
|
-
id:
|
2039
|
+
id: (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN)),
|
2069
2040
|
amount: quantity,
|
2070
2041
|
assetId,
|
2071
2042
|
owner: resourcesOwner || import_address.Address.fromRandom(),
|
@@ -2076,7 +2047,7 @@ var BaseTransactionRequest = class {
|
|
2076
2047
|
]);
|
2077
2048
|
}
|
2078
2049
|
};
|
2079
|
-
updateAssetInput(
|
2050
|
+
updateAssetInput(import_configs7.BaseAssetId, (0, import_math7.bn)(1e11));
|
2080
2051
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2081
2052
|
}
|
2082
2053
|
/**
|
@@ -2126,13 +2097,13 @@ var BaseTransactionRequest = class {
|
|
2126
2097
|
};
|
2127
2098
|
|
2128
2099
|
// src/providers/transaction-request/create-transaction-request.ts
|
2129
|
-
var
|
2100
|
+
var import_configs9 = require("@fuel-ts/address/configs");
|
2130
2101
|
var import_math9 = require("@fuel-ts/math");
|
2131
2102
|
var import_transactions8 = require("@fuel-ts/transactions");
|
2132
2103
|
var import_utils13 = require("@fuel-ts/utils");
|
2133
2104
|
|
2134
2105
|
// src/providers/transaction-request/hash-transaction.ts
|
2135
|
-
var
|
2106
|
+
var import_configs8 = require("@fuel-ts/address/configs");
|
2136
2107
|
var import_hasher = require("@fuel-ts/hasher");
|
2137
2108
|
var import_math8 = require("@fuel-ts/math");
|
2138
2109
|
var import_transactions7 = require("@fuel-ts/transactions");
|
@@ -2141,7 +2112,7 @@ var import_ramda2 = require("ramda");
|
|
2141
2112
|
function hashTransaction(transactionRequest, chainId) {
|
2142
2113
|
const transaction = transactionRequest.toTransaction();
|
2143
2114
|
if (transaction.type === import_transactions7.TransactionType.Script) {
|
2144
|
-
transaction.receiptsRoot =
|
2115
|
+
transaction.receiptsRoot = import_configs8.ZeroBytes32;
|
2145
2116
|
}
|
2146
2117
|
transaction.inputs = transaction.inputs.map((input) => {
|
2147
2118
|
const inputClone = (0, import_ramda2.clone)(input);
|
@@ -2163,10 +2134,10 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2163
2134
|
blockHeight: 0,
|
2164
2135
|
txIndex: 0
|
2165
2136
|
};
|
2166
|
-
inputClone.txID =
|
2137
|
+
inputClone.txID = import_configs8.ZeroBytes32;
|
2167
2138
|
inputClone.outputIndex = 0;
|
2168
|
-
inputClone.balanceRoot =
|
2169
|
-
inputClone.stateRoot =
|
2139
|
+
inputClone.balanceRoot = import_configs8.ZeroBytes32;
|
2140
|
+
inputClone.stateRoot = import_configs8.ZeroBytes32;
|
2170
2141
|
return inputClone;
|
2171
2142
|
}
|
2172
2143
|
default:
|
@@ -2177,8 +2148,8 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2177
2148
|
const outputClone = (0, import_ramda2.clone)(output);
|
2178
2149
|
switch (outputClone.type) {
|
2179
2150
|
case import_transactions7.OutputType.Contract: {
|
2180
|
-
outputClone.balanceRoot =
|
2181
|
-
outputClone.stateRoot =
|
2151
|
+
outputClone.balanceRoot = import_configs8.ZeroBytes32;
|
2152
|
+
outputClone.stateRoot = import_configs8.ZeroBytes32;
|
2182
2153
|
return outputClone;
|
2183
2154
|
}
|
2184
2155
|
case import_transactions7.OutputType.Change: {
|
@@ -2186,9 +2157,9 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2186
2157
|
return outputClone;
|
2187
2158
|
}
|
2188
2159
|
case import_transactions7.OutputType.Variable: {
|
2189
|
-
outputClone.to =
|
2160
|
+
outputClone.to = import_configs8.ZeroBytes32;
|
2190
2161
|
outputClone.amount = (0, import_math8.bn)(0);
|
2191
|
-
outputClone.assetId =
|
2162
|
+
outputClone.assetId = import_configs8.ZeroBytes32;
|
2192
2163
|
return outputClone;
|
2193
2164
|
}
|
2194
2165
|
default:
|
@@ -2246,10 +2217,15 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2246
2217
|
*
|
2247
2218
|
* @param createTransactionRequestLike - The initial values for the instance
|
2248
2219
|
*/
|
2249
|
-
constructor({
|
2220
|
+
constructor({
|
2221
|
+
bytecodeWitnessIndex,
|
2222
|
+
salt,
|
2223
|
+
storageSlots,
|
2224
|
+
...rest
|
2225
|
+
} = {}) {
|
2250
2226
|
super(rest);
|
2251
2227
|
this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
|
2252
|
-
this.salt = (0, import_utils13.hexlify)(salt ??
|
2228
|
+
this.salt = (0, import_utils13.hexlify)(salt ?? import_configs9.ZeroBytes32);
|
2253
2229
|
this.storageSlots = [...storageSlots ?? []];
|
2254
2230
|
}
|
2255
2231
|
/**
|
@@ -2267,7 +2243,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2267
2243
|
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2268
2244
|
bytecodeWitnessIndex,
|
2269
2245
|
storageSlotsCount: storageSlots.length,
|
2270
|
-
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) :
|
2246
|
+
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs9.ZeroBytes32,
|
2271
2247
|
storageSlots
|
2272
2248
|
};
|
2273
2249
|
}
|
@@ -2315,9 +2291,9 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2315
2291
|
};
|
2316
2292
|
|
2317
2293
|
// src/providers/transaction-request/script-transaction-request.ts
|
2318
|
-
var
|
2294
|
+
var import_abi_coder3 = require("@fuel-ts/abi-coder");
|
2319
2295
|
var import_address2 = require("@fuel-ts/address");
|
2320
|
-
var
|
2296
|
+
var import_configs10 = require("@fuel-ts/address/configs");
|
2321
2297
|
var import_math10 = require("@fuel-ts/math");
|
2322
2298
|
var import_transactions9 = require("@fuel-ts/transactions");
|
2323
2299
|
var import_utils15 = require("@fuel-ts/utils");
|
@@ -2370,7 +2346,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2370
2346
|
*
|
2371
2347
|
* @param scriptTransactionRequestLike - The initial values for the instance.
|
2372
2348
|
*/
|
2373
|
-
constructor({ script, scriptData, gasLimit, ...rest }) {
|
2349
|
+
constructor({ script, scriptData, gasLimit, ...rest } = {}) {
|
2374
2350
|
super(rest);
|
2375
2351
|
this.gasLimit = (0, import_math10.bn)(gasLimit);
|
2376
2352
|
this.script = (0, import_utils15.arrayify)(script ?? returnZeroScript.bytes);
|
@@ -2391,7 +2367,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2391
2367
|
...super.getBaseTransaction(),
|
2392
2368
|
scriptLength: script.length,
|
2393
2369
|
scriptDataLength: scriptData.length,
|
2394
|
-
receiptsRoot:
|
2370
|
+
receiptsRoot: import_configs10.ZeroBytes32,
|
2395
2371
|
script: (0, import_utils15.hexlify)(script),
|
2396
2372
|
scriptData: (0, import_utils15.hexlify)(scriptData)
|
2397
2373
|
};
|
@@ -2507,7 +2483,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2507
2483
|
* @returns The current instance of the `ScriptTransactionRequest`.
|
2508
2484
|
*/
|
2509
2485
|
setData(abi, args) {
|
2510
|
-
const abiInterface = new
|
2486
|
+
const abiInterface = new import_abi_coder3.Interface(abi);
|
2511
2487
|
this.scriptData = abiInterface.functions.main.encodeArguments(args);
|
2512
2488
|
return this;
|
2513
2489
|
}
|
@@ -2623,23 +2599,23 @@ var calculateTransactionFee = (params) => {
|
|
2623
2599
|
};
|
2624
2600
|
|
2625
2601
|
// src/providers/transaction-summary/operations.ts
|
2626
|
-
var
|
2602
|
+
var import_configs11 = require("@fuel-ts/address/configs");
|
2627
2603
|
var import_errors11 = require("@fuel-ts/errors");
|
2628
2604
|
var import_math13 = require("@fuel-ts/math");
|
2629
2605
|
var import_transactions14 = require("@fuel-ts/transactions");
|
2630
2606
|
|
2631
2607
|
// src/providers/transaction-summary/call.ts
|
2632
|
-
var
|
2608
|
+
var import_abi_coder4 = require("@fuel-ts/abi-coder");
|
2633
2609
|
var import_math12 = require("@fuel-ts/math");
|
2634
2610
|
var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
2635
|
-
const abiInterface = new
|
2611
|
+
const abiInterface = new import_abi_coder4.Interface(abi);
|
2636
2612
|
const callFunctionSelector = receipt.param1.toHex(8);
|
2637
2613
|
const functionFragment = abiInterface.getFunction(callFunctionSelector);
|
2638
2614
|
const inputs = functionFragment.jsonFn.inputs;
|
2639
2615
|
let encodedArgs;
|
2640
2616
|
if (functionFragment.isInputDataPointer) {
|
2641
2617
|
if (rawPayload) {
|
2642
|
-
const argsOffset = (0, import_math12.bn)(receipt.param2).sub((0,
|
2618
|
+
const argsOffset = (0, import_math12.bn)(receipt.param2).sub((0, import_abi_coder4.calculateVmTxMemory)({ maxInputs: maxInputs.toNumber() })).toNumber();
|
2643
2619
|
encodedArgs = `0x${rawPayload.slice(2).slice(argsOffset * 2)}`;
|
2644
2620
|
}
|
2645
2621
|
} else {
|
@@ -2921,7 +2897,7 @@ function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutp
|
|
2921
2897
|
const { to: toAddress, assetId, amount } = receipt;
|
2922
2898
|
let { from: fromAddress } = receipt;
|
2923
2899
|
const toType = contractInputs.some((input) => input.contractID === toAddress) ? 0 /* contract */ : 1 /* account */;
|
2924
|
-
if (
|
2900
|
+
if (import_configs11.ZeroBytes32 === fromAddress) {
|
2925
2901
|
const change = changeOutputs.find((output) => output.assetId === assetId);
|
2926
2902
|
fromAddress = change?.to || fromAddress;
|
2927
2903
|
}
|
@@ -3242,13 +3218,13 @@ function assembleTransactionSummary(params) {
|
|
3242
3218
|
}
|
3243
3219
|
|
3244
3220
|
// src/providers/transaction-response/getDecodedLogs.ts
|
3245
|
-
var
|
3221
|
+
var import_abi_coder5 = require("@fuel-ts/abi-coder");
|
3246
3222
|
var import_transactions16 = require("@fuel-ts/transactions");
|
3247
3223
|
function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
3248
3224
|
return receipts.reduce((logs, receipt) => {
|
3249
3225
|
if (receipt.type === import_transactions16.ReceiptType.LogData || receipt.type === import_transactions16.ReceiptType.Log) {
|
3250
|
-
const interfaceToUse = new
|
3251
|
-
const data = receipt.type === import_transactions16.ReceiptType.Log ? new
|
3226
|
+
const interfaceToUse = new import_abi_coder5.Interface(externalAbis[receipt.id] || mainAbi);
|
3227
|
+
const data = receipt.type === import_transactions16.ReceiptType.Log ? new import_abi_coder5.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
|
3252
3228
|
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
|
3253
3229
|
logs.push(decodedLog);
|
3254
3230
|
}
|
@@ -3498,7 +3474,6 @@ var processGqlChain = (chain) => {
|
|
3498
3474
|
gasPerByte: (0, import_math15.bn)(feeParams.gasPerByte),
|
3499
3475
|
maxMessageDataLength: (0, import_math15.bn)(predicateParams.maxMessageDataLength),
|
3500
3476
|
chainId: (0, import_math15.bn)(consensusParameters.chainId),
|
3501
|
-
baseAssetId: consensusParameters.baseAssetId,
|
3502
3477
|
gasCosts
|
3503
3478
|
},
|
3504
3479
|
gasCosts,
|
@@ -3741,17 +3716,6 @@ var _Provider = class {
|
|
3741
3716
|
} = this.getChain();
|
3742
3717
|
return chainId.toNumber();
|
3743
3718
|
}
|
3744
|
-
/**
|
3745
|
-
* Returns the base asset ID
|
3746
|
-
*
|
3747
|
-
* @returns A promise that resolves to the base asset ID
|
3748
|
-
*/
|
3749
|
-
getBaseAssetId() {
|
3750
|
-
const {
|
3751
|
-
consensusParameters: { baseAssetId }
|
3752
|
-
} = this.getChain();
|
3753
|
-
return baseAssetId;
|
3754
|
-
}
|
3755
3719
|
/**
|
3756
3720
|
* Submits a transaction to the chain to be executed.
|
3757
3721
|
*
|
@@ -3902,6 +3866,36 @@ var _Provider = class {
|
|
3902
3866
|
missingContractIds
|
3903
3867
|
};
|
3904
3868
|
}
|
3869
|
+
/**
|
3870
|
+
* Estimates the transaction gas and fee based on the provided transaction request.
|
3871
|
+
* @param transactionRequest - The transaction request object.
|
3872
|
+
* @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
|
3873
|
+
*/
|
3874
|
+
estimateTxGasAndFee(params) {
|
3875
|
+
const { transactionRequest } = params;
|
3876
|
+
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
3877
|
+
const chainInfo = this.getChain();
|
3878
|
+
const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
|
3879
|
+
transactionRequest.gasPrice = gasPrice;
|
3880
|
+
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
3881
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3882
|
+
if (transactionRequest.type === import_transactions18.TransactionType.Script) {
|
3883
|
+
if (transactionRequest.gasLimit.eq(0)) {
|
3884
|
+
transactionRequest.gasLimit = minGas;
|
3885
|
+
transactionRequest.gasLimit = maxGasPerTx.sub(
|
3886
|
+
transactionRequest.calculateMaxGas(chainInfo, minGas)
|
3887
|
+
);
|
3888
|
+
}
|
3889
|
+
}
|
3890
|
+
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
3891
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3892
|
+
return {
|
3893
|
+
minGas,
|
3894
|
+
minFee,
|
3895
|
+
maxGas,
|
3896
|
+
maxFee
|
3897
|
+
};
|
3898
|
+
}
|
3905
3899
|
/**
|
3906
3900
|
* Executes a signed transaction without applying the states changes
|
3907
3901
|
* on the chain.
|
@@ -3949,17 +3943,16 @@ var _Provider = class {
|
|
3949
3943
|
signatureCallback
|
3950
3944
|
} = {}) {
|
3951
3945
|
const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
|
3952
|
-
const
|
3953
|
-
const
|
3954
|
-
const gasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
|
3946
|
+
const { minGasPrice } = this.getGasConfig();
|
3947
|
+
const setGasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
|
3955
3948
|
const isScriptTransaction = txRequestClone.type === import_transactions18.TransactionType.Script;
|
3956
3949
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
3957
3950
|
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
3958
3951
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
3952
|
+
if (isScriptTransaction) {
|
3953
|
+
txRequestClone.gasLimit = (0, import_math15.bn)(0);
|
3954
|
+
}
|
3959
3955
|
if (estimatePredicates) {
|
3960
|
-
if (isScriptTransaction) {
|
3961
|
-
txRequestClone.gasLimit = (0, import_math15.bn)(0);
|
3962
|
-
}
|
3963
3956
|
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
3964
3957
|
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3965
3958
|
}
|
@@ -3968,36 +3961,34 @@ var _Provider = class {
|
|
3968
3961
|
if (signatureCallback && isScriptTransaction) {
|
3969
3962
|
await signatureCallback(txRequestClone);
|
3970
3963
|
}
|
3971
|
-
|
3972
|
-
|
3964
|
+
let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
3965
|
+
transactionRequest: txRequestClone
|
3966
|
+
});
|
3973
3967
|
let receipts = [];
|
3974
3968
|
let missingContractIds = [];
|
3975
3969
|
let outputVariables = 0;
|
3970
|
+
let gasUsed = (0, import_math15.bn)(0);
|
3976
3971
|
if (isScriptTransaction && estimateTxDependencies) {
|
3977
3972
|
txRequestClone.gasPrice = (0, import_math15.bn)(0);
|
3978
|
-
txRequestClone.gasLimit = (0, import_math15.bn)(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
|
3979
3973
|
const result = await this.estimateTxDependencies(txRequestClone);
|
3980
3974
|
receipts = result.receipts;
|
3981
3975
|
outputVariables = result.outputVariables;
|
3982
3976
|
missingContractIds = result.missingContractIds;
|
3977
|
+
gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
|
3978
|
+
txRequestClone.gasLimit = gasUsed;
|
3979
|
+
txRequestClone.gasPrice = setGasPrice;
|
3980
|
+
({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
3981
|
+
transactionRequest: txRequestClone
|
3982
|
+
}));
|
3983
3983
|
}
|
3984
|
-
const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
|
3985
|
-
const usedFee = calculatePriceWithFactor(
|
3986
|
-
gasUsed,
|
3987
|
-
gasPrice,
|
3988
|
-
gasPriceFactor
|
3989
|
-
).normalizeZeroToOne();
|
3990
|
-
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3991
|
-
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3992
3984
|
return {
|
3993
3985
|
requiredQuantities: allQuantities,
|
3994
3986
|
receipts,
|
3995
3987
|
gasUsed,
|
3996
3988
|
minGasPrice,
|
3997
|
-
gasPrice,
|
3989
|
+
gasPrice: setGasPrice,
|
3998
3990
|
minGas,
|
3999
3991
|
maxGas,
|
4000
|
-
usedFee,
|
4001
3992
|
minFee,
|
4002
3993
|
maxFee,
|
4003
3994
|
estimatedInputs: txRequestClone.inputs,
|
@@ -4464,13 +4455,13 @@ var assets = [
|
|
4464
4455
|
];
|
4465
4456
|
|
4466
4457
|
// src/utils/formatTransferToContractScriptData.ts
|
4467
|
-
var
|
4458
|
+
var import_abi_coder6 = require("@fuel-ts/abi-coder");
|
4468
4459
|
var import_math17 = require("@fuel-ts/math");
|
4469
4460
|
var import_utils27 = require("@fuel-ts/utils");
|
4470
4461
|
var asm = __toESM(require("@fuels/vm-asm"));
|
4471
4462
|
var formatTransferToContractScriptData = (params) => {
|
4472
4463
|
const { assetId, amountToTransfer, hexlifiedContractId } = params;
|
4473
|
-
const numberCoder = new
|
4464
|
+
const numberCoder = new import_abi_coder6.BigNumberCoder("u64");
|
4474
4465
|
const encoded = numberCoder.encode(new import_math17.BN(amountToTransfer).toNumber());
|
4475
4466
|
const scriptData = Uint8Array.from([
|
4476
4467
|
...(0, import_utils27.arrayify)(hexlifiedContractId),
|
@@ -4622,9 +4613,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4622
4613
|
* @param assetId - The asset ID to check the balance for.
|
4623
4614
|
* @returns A promise that resolves to the balance amount.
|
4624
4615
|
*/
|
4625
|
-
async getBalance(assetId) {
|
4626
|
-
const
|
4627
|
-
const amount = await this.provider.getBalance(this.address, assetIdToFetch);
|
4616
|
+
async getBalance(assetId = import_configs12.BaseAssetId) {
|
4617
|
+
const amount = await this.provider.getBalance(this.address, assetId);
|
4628
4618
|
return amount;
|
4629
4619
|
}
|
4630
4620
|
/**
|
@@ -4662,10 +4652,9 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4662
4652
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4663
4653
|
*/
|
4664
4654
|
async fund(request, coinQuantities, fee) {
|
4665
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
4666
4655
|
const updatedQuantities = addAmountToAsset({
|
4667
4656
|
amount: (0, import_math18.bn)(fee),
|
4668
|
-
assetId:
|
4657
|
+
assetId: import_configs12.BaseAssetId,
|
4669
4658
|
coinQuantities
|
4670
4659
|
});
|
4671
4660
|
const quantitiesDict = {};
|
@@ -4689,8 +4678,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4689
4678
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4690
4679
|
cachedUtxos.push(input.id);
|
4691
4680
|
}
|
4692
|
-
} else if (input.recipient === owner && input.amount && quantitiesDict[
|
4693
|
-
quantitiesDict[
|
4681
|
+
} else if (input.recipient === owner && input.amount && quantitiesDict[import_configs12.BaseAssetId]) {
|
4682
|
+
quantitiesDict[import_configs12.BaseAssetId].owned = quantitiesDict[import_configs12.BaseAssetId].owned.add(input.amount);
|
4694
4683
|
cachedMessages.push(input.nonce);
|
4695
4684
|
}
|
4696
4685
|
}
|
@@ -4722,13 +4711,11 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4722
4711
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4723
4712
|
* @returns A promise that resolves to the prepared transaction request.
|
4724
4713
|
*/
|
4725
|
-
async createTransfer(destination, amount, assetId, txParams = {}) {
|
4714
|
+
async createTransfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
4726
4715
|
const { minGasPrice } = this.provider.getGasConfig();
|
4727
|
-
const
|
4728
|
-
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4729
|
-
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
4716
|
+
const params = { gasPrice: minGasPrice, ...txParams };
|
4730
4717
|
const request = new ScriptTransactionRequest(params);
|
4731
|
-
request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount,
|
4718
|
+
request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetId);
|
4732
4719
|
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
4733
4720
|
estimateTxDependencies: true,
|
4734
4721
|
resourcesOwner: this
|
@@ -4754,15 +4741,14 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4754
4741
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4755
4742
|
* @returns A promise that resolves to the transaction response.
|
4756
4743
|
*/
|
4757
|
-
async transfer(destination, amount, assetId, txParams = {}) {
|
4744
|
+
async transfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
4758
4745
|
if ((0, import_math18.bn)(amount).lte(0)) {
|
4759
4746
|
throw new import_errors16.FuelError(
|
4760
4747
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
4761
4748
|
"Transfer amount must be a positive number."
|
4762
4749
|
);
|
4763
4750
|
}
|
4764
|
-
const
|
4765
|
-
const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
4751
|
+
const request = await this.createTransfer(destination, amount, assetId, txParams);
|
4766
4752
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
4767
4753
|
}
|
4768
4754
|
/**
|
@@ -4774,7 +4760,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4774
4760
|
* @param txParams - The optional transaction parameters.
|
4775
4761
|
* @returns A promise that resolves to the transaction response.
|
4776
4762
|
*/
|
4777
|
-
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
4763
|
+
async transferToContract(contractId, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
4778
4764
|
if ((0, import_math18.bn)(amount).lte(0)) {
|
4779
4765
|
throw new import_errors16.FuelError(
|
4780
4766
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
@@ -4783,13 +4769,11 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4783
4769
|
}
|
4784
4770
|
const contractAddress = import_address4.Address.fromAddressOrString(contractId);
|
4785
4771
|
const { minGasPrice } = this.provider.getGasConfig();
|
4786
|
-
const
|
4787
|
-
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4788
|
-
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
4772
|
+
const params = { gasPrice: minGasPrice, ...txParams };
|
4789
4773
|
const { script, scriptData } = await assembleTransferToContractScript({
|
4790
4774
|
hexlifiedContractId: contractAddress.toB256(),
|
4791
4775
|
amountToTransfer: (0, import_math18.bn)(amount),
|
4792
|
-
assetId
|
4776
|
+
assetId
|
4793
4777
|
});
|
4794
4778
|
const request = new ScriptTransactionRequest({
|
4795
4779
|
...params,
|
@@ -4799,7 +4783,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4799
4783
|
request.addContractInputAndOutput(contractAddress);
|
4800
4784
|
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
4801
4785
|
request,
|
4802
|
-
[{ amount: (0, import_math18.bn)(amount), assetId: String(
|
4786
|
+
[{ amount: (0, import_math18.bn)(amount), assetId: String(assetId) }]
|
4803
4787
|
);
|
4804
4788
|
request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
|
4805
4789
|
this.validateGas({
|
@@ -4821,7 +4805,6 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4821
4805
|
*/
|
4822
4806
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
4823
4807
|
const { minGasPrice } = this.provider.getGasConfig();
|
4824
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
4825
4808
|
const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
|
4826
4809
|
const recipientDataArray = (0, import_utils28.arrayify)(
|
4827
4810
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
@@ -4834,14 +4817,9 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4834
4817
|
...recipientDataArray,
|
4835
4818
|
...amountDataArray
|
4836
4819
|
]);
|
4837
|
-
const params = {
|
4838
|
-
script,
|
4839
|
-
gasPrice: minGasPrice,
|
4840
|
-
baseAssetId,
|
4841
|
-
...txParams
|
4842
|
-
};
|
4820
|
+
const params = { script, gasPrice: minGasPrice, ...txParams };
|
4843
4821
|
const request = new ScriptTransactionRequest(params);
|
4844
|
-
const forwardingQuantities = [{ amount: (0, import_math18.bn)(amount), assetId:
|
4822
|
+
const forwardingQuantities = [{ amount: (0, import_math18.bn)(amount), assetId: import_configs12.BaseAssetId }];
|
4845
4823
|
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
4846
4824
|
request,
|
4847
4825
|
forwardingQuantities
|
@@ -4934,7 +4912,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4934
4912
|
|
4935
4913
|
// src/signer/signer.ts
|
4936
4914
|
var import_address5 = require("@fuel-ts/address");
|
4937
|
-
var
|
4915
|
+
var import_crypto2 = require("@fuel-ts/crypto");
|
4938
4916
|
var import_hasher2 = require("@fuel-ts/hasher");
|
4939
4917
|
var import_math19 = require("@fuel-ts/math");
|
4940
4918
|
var import_utils29 = require("@fuel-ts/utils");
|
@@ -5027,7 +5005,7 @@ var Signer = class {
|
|
5027
5005
|
* @returns random 32-byte hashed
|
5028
5006
|
*/
|
5029
5007
|
static generatePrivateKey(entropy) {
|
5030
|
-
return entropy ? (0, import_hasher2.hash)((0, import_utils29.concat)([(0,
|
5008
|
+
return entropy ? (0, import_hasher2.hash)((0, import_utils29.concat)([(0, import_crypto2.randomBytes)(32), (0, import_utils29.arrayify)(entropy)])) : (0, import_crypto2.randomBytes)(32);
|
5031
5009
|
}
|
5032
5010
|
/**
|
5033
5011
|
* Extended publicKey from a compact publicKey
|
@@ -5043,7 +5021,7 @@ var Signer = class {
|
|
5043
5021
|
|
5044
5022
|
// src/wallet/keystore-wallet.ts
|
5045
5023
|
var import_address6 = require("@fuel-ts/address");
|
5046
|
-
var
|
5024
|
+
var import_crypto3 = require("@fuel-ts/crypto");
|
5047
5025
|
var import_errors17 = require("@fuel-ts/errors");
|
5048
5026
|
var import_utils30 = require("@fuel-ts/utils");
|
5049
5027
|
var import_uuid = require("uuid");
|
@@ -5059,22 +5037,22 @@ var removeHexPrefix = (hexString) => {
|
|
5059
5037
|
return hexString;
|
5060
5038
|
};
|
5061
5039
|
async function encryptKeystoreWallet(privateKey, address, password) {
|
5062
|
-
const privateKeyBuffer = (0,
|
5040
|
+
const privateKeyBuffer = (0, import_crypto3.bufferFromString)(removeHexPrefix(privateKey), "hex");
|
5063
5041
|
const ownerAddress = import_address6.Address.fromAddressOrString(address);
|
5064
|
-
const salt = (0,
|
5065
|
-
const key = (0,
|
5066
|
-
password: (0,
|
5042
|
+
const salt = (0, import_crypto3.randomBytes)(DEFAULT_KEY_SIZE);
|
5043
|
+
const key = (0, import_crypto3.scrypt)({
|
5044
|
+
password: (0, import_crypto3.bufferFromString)(password),
|
5067
5045
|
salt,
|
5068
5046
|
dklen: DEFAULT_KEY_SIZE,
|
5069
5047
|
n: 2 ** DEFAULT_KDF_PARAMS_LOG_N,
|
5070
5048
|
r: DEFAULT_KDF_PARAMS_R,
|
5071
5049
|
p: DEFAULT_KDF_PARAMS_P
|
5072
5050
|
});
|
5073
|
-
const iv = (0,
|
5074
|
-
const ciphertext = await (0,
|
5051
|
+
const iv = (0, import_crypto3.randomBytes)(DEFAULT_IV_SIZE);
|
5052
|
+
const ciphertext = await (0, import_crypto3.encryptJsonWalletData)(privateKeyBuffer, key, iv);
|
5075
5053
|
const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertext]);
|
5076
|
-
const macHashUint8Array = (0,
|
5077
|
-
const mac = (0,
|
5054
|
+
const macHashUint8Array = (0, import_crypto3.keccak256)(data);
|
5055
|
+
const mac = (0, import_crypto3.stringFromBuffer)(macHashUint8Array, "hex");
|
5078
5056
|
const keystore = {
|
5079
5057
|
id: (0, import_uuid.v4)(),
|
5080
5058
|
version: 3,
|
@@ -5082,15 +5060,15 @@ async function encryptKeystoreWallet(privateKey, address, password) {
|
|
5082
5060
|
crypto: {
|
5083
5061
|
cipher: "aes-128-ctr",
|
5084
5062
|
mac,
|
5085
|
-
cipherparams: { iv: (0,
|
5086
|
-
ciphertext: (0,
|
5063
|
+
cipherparams: { iv: (0, import_crypto3.stringFromBuffer)(iv, "hex") },
|
5064
|
+
ciphertext: (0, import_crypto3.stringFromBuffer)(ciphertext, "hex"),
|
5087
5065
|
kdf: "scrypt",
|
5088
5066
|
kdfparams: {
|
5089
5067
|
dklen: DEFAULT_KEY_SIZE,
|
5090
5068
|
n: 2 ** DEFAULT_KDF_PARAMS_LOG_N,
|
5091
5069
|
p: DEFAULT_KDF_PARAMS_P,
|
5092
5070
|
r: DEFAULT_KDF_PARAMS_R,
|
5093
|
-
salt: (0,
|
5071
|
+
salt: (0, import_crypto3.stringFromBuffer)(salt, "hex")
|
5094
5072
|
}
|
5095
5073
|
}
|
5096
5074
|
};
|
@@ -5106,11 +5084,11 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5106
5084
|
kdfparams: { dklen, n, r, p, salt }
|
5107
5085
|
}
|
5108
5086
|
} = keystoreWallet;
|
5109
|
-
const ciphertextBuffer = (0,
|
5110
|
-
const ivBuffer = (0,
|
5111
|
-
const saltBuffer = (0,
|
5112
|
-
const passwordBuffer = (0,
|
5113
|
-
const key = (0,
|
5087
|
+
const ciphertextBuffer = (0, import_crypto3.bufferFromString)(ciphertext, "hex");
|
5088
|
+
const ivBuffer = (0, import_crypto3.bufferFromString)(iv, "hex");
|
5089
|
+
const saltBuffer = (0, import_crypto3.bufferFromString)(salt, "hex");
|
5090
|
+
const passwordBuffer = (0, import_crypto3.bufferFromString)(password);
|
5091
|
+
const key = (0, import_crypto3.scrypt)({
|
5114
5092
|
password: passwordBuffer,
|
5115
5093
|
salt: saltBuffer,
|
5116
5094
|
n,
|
@@ -5119,15 +5097,15 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5119
5097
|
dklen
|
5120
5098
|
});
|
5121
5099
|
const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertextBuffer]);
|
5122
|
-
const macHashUint8Array = (0,
|
5123
|
-
const macHash = (0,
|
5100
|
+
const macHashUint8Array = (0, import_crypto3.keccak256)(data);
|
5101
|
+
const macHash = (0, import_crypto3.stringFromBuffer)(macHashUint8Array, "hex");
|
5124
5102
|
if (mac !== macHash) {
|
5125
5103
|
throw new import_errors17.FuelError(
|
5126
5104
|
import_errors17.ErrorCode.INVALID_PASSWORD,
|
5127
5105
|
"Failed to decrypt the keystore wallet, the provided password is incorrect."
|
5128
5106
|
);
|
5129
5107
|
}
|
5130
|
-
const buffer = await (0,
|
5108
|
+
const buffer = await (0, import_crypto3.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
|
5131
5109
|
const privateKey = (0, import_utils30.hexlify)(buffer);
|
5132
5110
|
return privateKey;
|
5133
5111
|
}
|
@@ -5252,7 +5230,7 @@ var import_utils35 = require("@fuel-ts/utils");
|
|
5252
5230
|
var import_ethers3 = require("ethers");
|
5253
5231
|
|
5254
5232
|
// src/mnemonic/mnemonic.ts
|
5255
|
-
var
|
5233
|
+
var import_crypto4 = require("@fuel-ts/crypto");
|
5256
5234
|
var import_errors19 = require("@fuel-ts/errors");
|
5257
5235
|
var import_hasher5 = require("@fuel-ts/hasher");
|
5258
5236
|
var import_utils33 = require("@fuel-ts/utils");
|
@@ -7607,7 +7585,7 @@ var Mnemonic = class {
|
|
7607
7585
|
* @returns A randomly generated mnemonic
|
7608
7586
|
*/
|
7609
7587
|
static generate(size = 32, extraEntropy = "") {
|
7610
|
-
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils33.concat)([(0,
|
7588
|
+
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils33.concat)([(0, import_crypto4.randomBytes)(size), (0, import_utils33.arrayify)(extraEntropy)])) : (0, import_crypto4.randomBytes)(size);
|
7611
7589
|
return Mnemonic.entropyToMnemonic(entropy);
|
7612
7590
|
}
|
7613
7591
|
};
|
@@ -7978,17 +7956,15 @@ __publicField(Wallet, "fromExtendedKey", WalletUnlocked.fromExtendedKey);
|
|
7978
7956
|
__publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
|
7979
7957
|
|
7980
7958
|
// src/test-utils/seedTestWallet.ts
|
7981
|
-
var
|
7959
|
+
var import_crypto5 = require("@fuel-ts/crypto");
|
7982
7960
|
var seedTestWallet = async (wallet, quantities) => {
|
7983
7961
|
const genesisWallet = new WalletUnlocked(
|
7984
|
-
process.env.GENESIS_SECRET || (0,
|
7962
|
+
process.env.GENESIS_SECRET || (0, import_crypto5.randomBytes)(32),
|
7985
7963
|
wallet.provider
|
7986
7964
|
);
|
7987
7965
|
const resources = await genesisWallet.getResourcesToSpend(quantities);
|
7988
7966
|
const { minGasPrice } = genesisWallet.provider.getGasConfig();
|
7989
|
-
const baseAssetId = genesisWallet.provider.getBaseAssetId();
|
7990
7967
|
const request = new ScriptTransactionRequest({
|
7991
|
-
baseAssetId,
|
7992
7968
|
gasLimit: 1e4,
|
7993
7969
|
gasPrice: minGasPrice
|
7994
7970
|
});
|
@@ -8007,12 +7983,12 @@ var generateTestWallet = async (provider, quantities) => {
|
|
8007
7983
|
};
|
8008
7984
|
|
8009
7985
|
// src/test-utils/launchNode.ts
|
8010
|
-
var
|
7986
|
+
var import_configs13 = require("@fuel-ts/address/configs");
|
8011
7987
|
var import_math21 = require("@fuel-ts/math");
|
8012
7988
|
var import_utils36 = require("@fuel-ts/utils");
|
8013
7989
|
var import_cli_utils = require("@fuel-ts/utils/cli-utils");
|
8014
7990
|
var import_child_process = require("child_process");
|
8015
|
-
var
|
7991
|
+
var import_crypto6 = require("crypto");
|
8016
7992
|
var import_fs = require("fs");
|
8017
7993
|
var import_os = __toESM(require("os"));
|
8018
7994
|
var import_path = __toESM(require("path"));
|
@@ -8084,7 +8060,7 @@ var launchNode = async ({
|
|
8084
8060
|
})).toString();
|
8085
8061
|
let chainConfigPathToUse;
|
8086
8062
|
const prefix = basePath || import_os.default.tmpdir();
|
8087
|
-
const suffix = basePath ? "" : (0,
|
8063
|
+
const suffix = basePath ? "" : (0, import_crypto6.randomUUID)();
|
8088
8064
|
const tempDirPath = import_path.default.join(prefix, ".fuels", suffix);
|
8089
8065
|
if (chainConfigPath) {
|
8090
8066
|
chainConfigPathToUse = chainConfigPath;
|
@@ -8107,7 +8083,7 @@ var launchNode = async ({
|
|
8107
8083
|
{
|
8108
8084
|
owner: signer.address.toHexString(),
|
8109
8085
|
amount: (0, import_math21.toHex)(1e9),
|
8110
|
-
asset_id:
|
8086
|
+
asset_id: import_configs13.BaseAssetId
|
8111
8087
|
}
|
8112
8088
|
]
|
8113
8089
|
}
|
@@ -8173,10 +8149,9 @@ var launchNode = async ({
|
|
8173
8149
|
})
|
8174
8150
|
);
|
8175
8151
|
var generateWallets = async (count, provider) => {
|
8176
|
-
const baseAssetId = provider.getBaseAssetId();
|
8177
8152
|
const wallets = [];
|
8178
8153
|
for (let i = 0; i < count; i += 1) {
|
8179
|
-
const wallet = await generateTestWallet(provider, [[1e3,
|
8154
|
+
const wallet = await generateTestWallet(provider, [[1e3, import_configs13.BaseAssetId]]);
|
8180
8155
|
wallets.push(wallet);
|
8181
8156
|
}
|
8182
8157
|
return wallets;
|