@fuel-ts/account 0.0.0-rc-1976-20240415100843 → 0.0.0-rc-2040-20240415161332
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 +75 -119
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +150 -194
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +78 -122
- 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 +2 -20
- 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 +78 -125
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +147 -194
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +80 -127
- package/dist/test-utils.mjs.map +1 -1
- package/package.json +16 -16
package/dist/index.js
CHANGED
@@ -184,12 +184,14 @@ module.exports = __toCommonJS(src_exports);
|
|
184
184
|
|
185
185
|
// src/account.ts
|
186
186
|
var import_address4 = require("@fuel-ts/address");
|
187
|
+
var import_configs12 = require("@fuel-ts/address/configs");
|
187
188
|
var import_errors16 = require("@fuel-ts/errors");
|
188
189
|
var import_interfaces = require("@fuel-ts/interfaces");
|
189
190
|
var import_math18 = require("@fuel-ts/math");
|
190
191
|
var import_utils28 = require("@fuel-ts/utils");
|
191
192
|
|
192
193
|
// src/providers/coin-quantity.ts
|
194
|
+
var import_configs = require("@fuel-ts/address/configs");
|
193
195
|
var import_math = require("@fuel-ts/math");
|
194
196
|
var import_utils = require("@fuel-ts/utils");
|
195
197
|
var coinQuantityfy = (coinQuantityLike) => {
|
@@ -198,11 +200,11 @@ var coinQuantityfy = (coinQuantityLike) => {
|
|
198
200
|
let max2;
|
199
201
|
if (Array.isArray(coinQuantityLike)) {
|
200
202
|
amount = coinQuantityLike[0];
|
201
|
-
assetId = coinQuantityLike[1];
|
202
|
-
max2 = coinQuantityLike[2];
|
203
|
+
assetId = coinQuantityLike[1] ?? import_configs.BaseAssetId;
|
204
|
+
max2 = coinQuantityLike[2] ?? void 0;
|
203
205
|
} else {
|
204
206
|
amount = coinQuantityLike.amount;
|
205
|
-
assetId = coinQuantityLike.assetId;
|
207
|
+
assetId = coinQuantityLike.assetId ?? import_configs.BaseAssetId;
|
206
208
|
max2 = coinQuantityLike.max ?? void 0;
|
207
209
|
}
|
208
210
|
const bnAmount = (0, import_math.bn)(amount);
|
@@ -1171,8 +1173,7 @@ var MemoryCache = class {
|
|
1171
1173
|
};
|
1172
1174
|
|
1173
1175
|
// src/providers/transaction-request/input.ts
|
1174
|
-
var
|
1175
|
-
var import_configs = require("@fuel-ts/address/configs");
|
1176
|
+
var import_configs2 = require("@fuel-ts/address/configs");
|
1176
1177
|
var import_errors3 = require("@fuel-ts/errors");
|
1177
1178
|
var import_math2 = require("@fuel-ts/math");
|
1178
1179
|
var import_transactions = require("@fuel-ts/transactions");
|
@@ -1185,8 +1186,8 @@ var inputify = (value) => {
|
|
1185
1186
|
const predicateData = (0, import_utils3.arrayify)(value.predicateData ?? "0x");
|
1186
1187
|
return {
|
1187
1188
|
type: import_transactions.InputType.Coin,
|
1188
|
-
txID: (0, import_utils3.hexlify)((0, import_utils3.arrayify)(value.id).slice(0,
|
1189
|
-
outputIndex: (0,
|
1189
|
+
txID: (0, import_utils3.hexlify)((0, import_utils3.arrayify)(value.id).slice(0, 32)),
|
1190
|
+
outputIndex: (0, import_utils3.arrayify)(value.id)[32],
|
1190
1191
|
owner: (0, import_utils3.hexlify)(value.owner),
|
1191
1192
|
amount: (0, import_math2.bn)(value.amount),
|
1192
1193
|
assetId: (0, import_utils3.hexlify)(value.assetId),
|
@@ -1206,10 +1207,10 @@ var inputify = (value) => {
|
|
1206
1207
|
case import_transactions.InputType.Contract: {
|
1207
1208
|
return {
|
1208
1209
|
type: import_transactions.InputType.Contract,
|
1209
|
-
txID:
|
1210
|
+
txID: import_configs2.ZeroBytes32,
|
1210
1211
|
outputIndex: 0,
|
1211
|
-
balanceRoot:
|
1212
|
-
stateRoot:
|
1212
|
+
balanceRoot: import_configs2.ZeroBytes32,
|
1213
|
+
stateRoot: import_configs2.ZeroBytes32,
|
1213
1214
|
txPointer: {
|
1214
1215
|
blockHeight: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(0, 8)),
|
1215
1216
|
txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
|
@@ -1247,7 +1248,7 @@ var inputify = (value) => {
|
|
1247
1248
|
};
|
1248
1249
|
|
1249
1250
|
// src/providers/transaction-request/output.ts
|
1250
|
-
var
|
1251
|
+
var import_configs3 = require("@fuel-ts/address/configs");
|
1251
1252
|
var import_errors4 = require("@fuel-ts/errors");
|
1252
1253
|
var import_math3 = require("@fuel-ts/math");
|
1253
1254
|
var import_transactions2 = require("@fuel-ts/transactions");
|
@@ -1267,8 +1268,8 @@ var outputify = (value) => {
|
|
1267
1268
|
return {
|
1268
1269
|
type: import_transactions2.OutputType.Contract,
|
1269
1270
|
inputIndex: value.inputIndex,
|
1270
|
-
balanceRoot:
|
1271
|
-
stateRoot:
|
1271
|
+
balanceRoot: import_configs3.ZeroBytes32,
|
1272
|
+
stateRoot: import_configs3.ZeroBytes32
|
1272
1273
|
};
|
1273
1274
|
}
|
1274
1275
|
case import_transactions2.OutputType.Change: {
|
@@ -1282,9 +1283,9 @@ var outputify = (value) => {
|
|
1282
1283
|
case import_transactions2.OutputType.Variable: {
|
1283
1284
|
return {
|
1284
1285
|
type: import_transactions2.OutputType.Variable,
|
1285
|
-
to:
|
1286
|
+
to: import_configs3.ZeroBytes32,
|
1286
1287
|
amount: (0, import_math3.bn)(0),
|
1287
|
-
assetId:
|
1288
|
+
assetId: import_configs3.ZeroBytes32
|
1288
1289
|
};
|
1289
1290
|
}
|
1290
1291
|
case import_transactions2.OutputType.ContractCreated: {
|
@@ -1304,10 +1305,8 @@ var outputify = (value) => {
|
|
1304
1305
|
};
|
1305
1306
|
|
1306
1307
|
// src/providers/transaction-request/transaction-request.ts
|
1307
|
-
var import_abi_coder2 = require("@fuel-ts/abi-coder");
|
1308
1308
|
var import_address = require("@fuel-ts/address");
|
1309
|
-
var
|
1310
|
-
var import_crypto = require("@fuel-ts/crypto");
|
1309
|
+
var import_configs7 = require("@fuel-ts/address/configs");
|
1311
1310
|
var import_math7 = require("@fuel-ts/math");
|
1312
1311
|
var import_transactions6 = require("@fuel-ts/transactions");
|
1313
1312
|
var import_utils9 = require("@fuel-ts/utils");
|
@@ -1319,13 +1318,13 @@ var isCoin = (resource) => "id" in resource;
|
|
1319
1318
|
var isMessage = (resource) => "recipient" in resource;
|
1320
1319
|
|
1321
1320
|
// src/providers/utils/receipts.ts
|
1322
|
-
var
|
1321
|
+
var import_configs4 = require("@fuel-ts/address/configs");
|
1323
1322
|
var import_errors5 = require("@fuel-ts/errors");
|
1324
1323
|
var import_math4 = require("@fuel-ts/math");
|
1325
1324
|
var import_transactions3 = require("@fuel-ts/transactions");
|
1326
|
-
var
|
1325
|
+
var import_configs5 = require("@fuel-ts/transactions/configs");
|
1327
1326
|
var import_utils5 = require("@fuel-ts/utils");
|
1328
|
-
var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions3.ReceiptType.Revert && receipt.val.toString("hex") ===
|
1327
|
+
var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions3.ReceiptType.Revert && receipt.val.toString("hex") === import_configs5.FAILED_TRANSFER_TO_ADDRESS_SIGNAL;
|
1329
1328
|
var doesReceiptHaveMissingContractId = (receipt) => receipt.type === import_transactions3.ReceiptType.Panic && receipt.contractId !== "0x0000000000000000000000000000000000000000000000000000000000000000";
|
1330
1329
|
var getReceiptsWithMissingData = (receipts) => receipts.reduce(
|
1331
1330
|
(memo, receipt) => {
|
@@ -1342,7 +1341,7 @@ var getReceiptsWithMissingData = (receipts) => receipts.reduce(
|
|
1342
1341
|
missingOutputContractIds: []
|
1343
1342
|
}
|
1344
1343
|
);
|
1345
|
-
var hexOrZero = (hex) => hex ||
|
1344
|
+
var hexOrZero = (hex) => hex || import_configs4.ZeroBytes32;
|
1346
1345
|
function assembleReceiptByType(receipt) {
|
1347
1346
|
const { receiptType } = receipt;
|
1348
1347
|
switch (receiptType) {
|
@@ -1706,16 +1705,16 @@ function sleep(time) {
|
|
1706
1705
|
var import_errors7 = require("@fuel-ts/errors");
|
1707
1706
|
var import_math6 = require("@fuel-ts/math");
|
1708
1707
|
var import_transactions5 = require("@fuel-ts/transactions");
|
1709
|
-
var
|
1708
|
+
var import_configs6 = require("@fuel-ts/transactions/configs");
|
1710
1709
|
var assemblePanicError = (status) => {
|
1711
1710
|
let errorMessage = `The transaction reverted with reason: "${status.reason}".`;
|
1712
1711
|
const reason = status.reason;
|
1713
|
-
if (
|
1712
|
+
if (import_configs6.PANIC_REASONS.includes(status.reason)) {
|
1714
1713
|
errorMessage = `${errorMessage}
|
1715
1714
|
|
1716
1715
|
You can read more about this error at:
|
1717
1716
|
|
1718
|
-
${
|
1717
|
+
${import_configs6.PANIC_DOC_URL}#variant.${status.reason}`;
|
1719
1718
|
}
|
1720
1719
|
return { errorMessage, reason };
|
1721
1720
|
};
|
@@ -1727,28 +1726,28 @@ var assembleRevertError = (receipts, logs) => {
|
|
1727
1726
|
if (revertReceipt) {
|
1728
1727
|
const reasonHex = (0, import_math6.bn)(revertReceipt.val).toHex();
|
1729
1728
|
switch (reasonHex) {
|
1730
|
-
case
|
1729
|
+
case import_configs6.FAILED_REQUIRE_SIGNAL: {
|
1731
1730
|
reason = "require";
|
1732
1731
|
errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(logs[0]) : "an error."}.`;
|
1733
1732
|
break;
|
1734
1733
|
}
|
1735
|
-
case
|
1734
|
+
case import_configs6.FAILED_ASSERT_EQ_SIGNAL: {
|
1736
1735
|
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1737
1736
|
reason = "assert_eq";
|
1738
1737
|
errorMessage = `The transaction reverted because of an "assert_eq" statement${sufix}`;
|
1739
1738
|
break;
|
1740
1739
|
}
|
1741
|
-
case
|
1740
|
+
case import_configs6.FAILED_ASSERT_NE_SIGNAL: {
|
1742
1741
|
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1743
1742
|
reason = "assert_ne";
|
1744
1743
|
errorMessage = `The transaction reverted because of an "assert_ne" statement${sufix}`;
|
1745
1744
|
break;
|
1746
1745
|
}
|
1747
|
-
case
|
1746
|
+
case import_configs6.FAILED_ASSERT_SIGNAL:
|
1748
1747
|
reason = "assert";
|
1749
1748
|
errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
|
1750
1749
|
break;
|
1751
|
-
case
|
1750
|
+
case import_configs6.FAILED_TRANSFER_TO_ADDRESS_SIGNAL:
|
1752
1751
|
reason = "MissingOutputChange";
|
1753
1752
|
errorMessage = `The transaction reverted because it's missing an "OutputChange".`;
|
1754
1753
|
break;
|
@@ -1822,8 +1821,6 @@ var BaseTransactionRequest = class {
|
|
1822
1821
|
outputs = [];
|
1823
1822
|
/** List of witnesses */
|
1824
1823
|
witnesses = [];
|
1825
|
-
/** Base asset ID - should be fetched from the chain */
|
1826
|
-
baseAssetId;
|
1827
1824
|
/**
|
1828
1825
|
* Constructor for initializing a base transaction request.
|
1829
1826
|
*
|
@@ -1836,9 +1833,8 @@ var BaseTransactionRequest = class {
|
|
1836
1833
|
witnessLimit,
|
1837
1834
|
inputs,
|
1838
1835
|
outputs,
|
1839
|
-
witnesses
|
1840
|
-
|
1841
|
-
}) {
|
1836
|
+
witnesses
|
1837
|
+
} = {}) {
|
1842
1838
|
this.gasPrice = (0, import_math7.bn)(gasPrice);
|
1843
1839
|
this.maturity = maturity ?? 0;
|
1844
1840
|
this.witnessLimit = witnessLimit ? (0, import_math7.bn)(witnessLimit) : void 0;
|
@@ -1846,7 +1842,6 @@ var BaseTransactionRequest = class {
|
|
1846
1842
|
this.inputs = inputs ?? [];
|
1847
1843
|
this.outputs = outputs ?? [];
|
1848
1844
|
this.witnesses = witnesses ?? [];
|
1849
|
-
this.baseAssetId = baseAssetId;
|
1850
1845
|
}
|
1851
1846
|
static getPolicyMeta(req) {
|
1852
1847
|
let policyTypes = 0;
|
@@ -1939,7 +1934,7 @@ var BaseTransactionRequest = class {
|
|
1939
1934
|
* @returns The index of the created witness.
|
1940
1935
|
*/
|
1941
1936
|
addEmptyWitness() {
|
1942
|
-
this.addWitness((0, import_utils9.concat)([
|
1937
|
+
this.addWitness((0, import_utils9.concat)([import_configs7.ZeroBytes32, import_configs7.ZeroBytes32]));
|
1943
1938
|
return this.witnesses.length - 1;
|
1944
1939
|
}
|
1945
1940
|
/**
|
@@ -2070,9 +2065,11 @@ var BaseTransactionRequest = class {
|
|
2070
2065
|
*
|
2071
2066
|
* @param message - Message resource.
|
2072
2067
|
* @param predicate - Predicate bytes.
|
2068
|
+
* @param predicateData - Predicate data bytes.
|
2073
2069
|
*/
|
2074
2070
|
addMessageInput(message, predicate) {
|
2075
2071
|
const { recipient, sender, amount } = message;
|
2072
|
+
const assetId = import_configs7.BaseAssetId;
|
2076
2073
|
let witnessIndex;
|
2077
2074
|
if (predicate) {
|
2078
2075
|
witnessIndex = 0;
|
@@ -2092,7 +2089,7 @@ var BaseTransactionRequest = class {
|
|
2092
2089
|
predicate: predicate?.bytes
|
2093
2090
|
};
|
2094
2091
|
this.pushInput(input);
|
2095
|
-
this.addChangeOutput(recipient,
|
2092
|
+
this.addChangeOutput(recipient, assetId);
|
2096
2093
|
}
|
2097
2094
|
/**
|
2098
2095
|
* Adds a single resource to the transaction by adding a coin/message input and a
|
@@ -2153,12 +2150,12 @@ var BaseTransactionRequest = class {
|
|
2153
2150
|
* @param amount - Amount of coin.
|
2154
2151
|
* @param assetId - Asset ID of coin.
|
2155
2152
|
*/
|
2156
|
-
addCoinOutput(to, amount, assetId) {
|
2153
|
+
addCoinOutput(to, amount, assetId = import_configs7.BaseAssetId) {
|
2157
2154
|
this.pushOutput({
|
2158
2155
|
type: import_transactions6.OutputType.Coin,
|
2159
2156
|
to: (0, import_address.addressify)(to).toB256(),
|
2160
2157
|
amount,
|
2161
|
-
assetId
|
2158
|
+
assetId
|
2162
2159
|
});
|
2163
2160
|
return this;
|
2164
2161
|
}
|
@@ -2185,7 +2182,7 @@ var BaseTransactionRequest = class {
|
|
2185
2182
|
* @param to - Address of the owner.
|
2186
2183
|
* @param assetId - Asset ID of coin.
|
2187
2184
|
*/
|
2188
|
-
addChangeOutput(to, assetId) {
|
2185
|
+
addChangeOutput(to, assetId = import_configs7.BaseAssetId) {
|
2189
2186
|
const changeOutput = this.getChangeOutputs().find(
|
2190
2187
|
(output) => (0, import_utils9.hexlify)(output.assetId) === assetId
|
2191
2188
|
);
|
@@ -2193,7 +2190,7 @@ var BaseTransactionRequest = class {
|
|
2193
2190
|
this.pushOutput({
|
2194
2191
|
type: import_transactions6.OutputType.Change,
|
2195
2192
|
to: (0, import_address.addressify)(to).toB256(),
|
2196
|
-
assetId
|
2193
|
+
assetId
|
2197
2194
|
});
|
2198
2195
|
}
|
2199
2196
|
}
|
@@ -2244,6 +2241,12 @@ var BaseTransactionRequest = class {
|
|
2244
2241
|
* @param quantities - CoinQuantity Array.
|
2245
2242
|
*/
|
2246
2243
|
fundWithFakeUtxos(quantities, resourcesOwner) {
|
2244
|
+
let idCounter = 0;
|
2245
|
+
const generateId = () => {
|
2246
|
+
const counterString = String(idCounter++);
|
2247
|
+
const id = import_configs7.ZeroBytes32.slice(0, -counterString.length).concat(counterString);
|
2248
|
+
return id;
|
2249
|
+
};
|
2247
2250
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
2248
2251
|
if ("assetId" in input) {
|
2249
2252
|
return input.assetId === assetId;
|
@@ -2253,12 +2256,12 @@ var BaseTransactionRequest = class {
|
|
2253
2256
|
const updateAssetInput = (assetId, quantity) => {
|
2254
2257
|
const assetInput = findAssetInput(assetId);
|
2255
2258
|
if (assetInput && "assetId" in assetInput) {
|
2256
|
-
assetInput.id = (
|
2259
|
+
assetInput.id = generateId();
|
2257
2260
|
assetInput.amount = quantity;
|
2258
2261
|
} else {
|
2259
2262
|
this.addResources([
|
2260
2263
|
{
|
2261
|
-
id: (
|
2264
|
+
id: generateId(),
|
2262
2265
|
amount: quantity,
|
2263
2266
|
assetId,
|
2264
2267
|
owner: resourcesOwner || import_address.Address.fromRandom(),
|
@@ -2269,7 +2272,7 @@ var BaseTransactionRequest = class {
|
|
2269
2272
|
]);
|
2270
2273
|
}
|
2271
2274
|
};
|
2272
|
-
updateAssetInput(
|
2275
|
+
updateAssetInput(import_configs7.BaseAssetId, (0, import_math7.bn)(1e11));
|
2273
2276
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2274
2277
|
}
|
2275
2278
|
/**
|
@@ -2319,13 +2322,13 @@ var BaseTransactionRequest = class {
|
|
2319
2322
|
};
|
2320
2323
|
|
2321
2324
|
// src/providers/transaction-request/create-transaction-request.ts
|
2322
|
-
var
|
2325
|
+
var import_configs9 = require("@fuel-ts/address/configs");
|
2323
2326
|
var import_math9 = require("@fuel-ts/math");
|
2324
2327
|
var import_transactions8 = require("@fuel-ts/transactions");
|
2325
2328
|
var import_utils13 = require("@fuel-ts/utils");
|
2326
2329
|
|
2327
2330
|
// src/providers/transaction-request/hash-transaction.ts
|
2328
|
-
var
|
2331
|
+
var import_configs8 = require("@fuel-ts/address/configs");
|
2329
2332
|
var import_hasher = require("@fuel-ts/hasher");
|
2330
2333
|
var import_math8 = require("@fuel-ts/math");
|
2331
2334
|
var import_transactions7 = require("@fuel-ts/transactions");
|
@@ -2334,7 +2337,7 @@ var import_ramda2 = require("ramda");
|
|
2334
2337
|
function hashTransaction(transactionRequest, chainId) {
|
2335
2338
|
const transaction = transactionRequest.toTransaction();
|
2336
2339
|
if (transaction.type === import_transactions7.TransactionType.Script) {
|
2337
|
-
transaction.receiptsRoot =
|
2340
|
+
transaction.receiptsRoot = import_configs8.ZeroBytes32;
|
2338
2341
|
}
|
2339
2342
|
transaction.inputs = transaction.inputs.map((input) => {
|
2340
2343
|
const inputClone = (0, import_ramda2.clone)(input);
|
@@ -2356,10 +2359,10 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2356
2359
|
blockHeight: 0,
|
2357
2360
|
txIndex: 0
|
2358
2361
|
};
|
2359
|
-
inputClone.txID =
|
2362
|
+
inputClone.txID = import_configs8.ZeroBytes32;
|
2360
2363
|
inputClone.outputIndex = 0;
|
2361
|
-
inputClone.balanceRoot =
|
2362
|
-
inputClone.stateRoot =
|
2364
|
+
inputClone.balanceRoot = import_configs8.ZeroBytes32;
|
2365
|
+
inputClone.stateRoot = import_configs8.ZeroBytes32;
|
2363
2366
|
return inputClone;
|
2364
2367
|
}
|
2365
2368
|
default:
|
@@ -2370,8 +2373,8 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2370
2373
|
const outputClone = (0, import_ramda2.clone)(output);
|
2371
2374
|
switch (outputClone.type) {
|
2372
2375
|
case import_transactions7.OutputType.Contract: {
|
2373
|
-
outputClone.balanceRoot =
|
2374
|
-
outputClone.stateRoot =
|
2376
|
+
outputClone.balanceRoot = import_configs8.ZeroBytes32;
|
2377
|
+
outputClone.stateRoot = import_configs8.ZeroBytes32;
|
2375
2378
|
return outputClone;
|
2376
2379
|
}
|
2377
2380
|
case import_transactions7.OutputType.Change: {
|
@@ -2379,9 +2382,9 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2379
2382
|
return outputClone;
|
2380
2383
|
}
|
2381
2384
|
case import_transactions7.OutputType.Variable: {
|
2382
|
-
outputClone.to =
|
2385
|
+
outputClone.to = import_configs8.ZeroBytes32;
|
2383
2386
|
outputClone.amount = (0, import_math8.bn)(0);
|
2384
|
-
outputClone.assetId =
|
2387
|
+
outputClone.assetId = import_configs8.ZeroBytes32;
|
2385
2388
|
return outputClone;
|
2386
2389
|
}
|
2387
2390
|
default:
|
@@ -2439,10 +2442,15 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2439
2442
|
*
|
2440
2443
|
* @param createTransactionRequestLike - The initial values for the instance
|
2441
2444
|
*/
|
2442
|
-
constructor({
|
2445
|
+
constructor({
|
2446
|
+
bytecodeWitnessIndex,
|
2447
|
+
salt,
|
2448
|
+
storageSlots,
|
2449
|
+
...rest
|
2450
|
+
} = {}) {
|
2443
2451
|
super(rest);
|
2444
2452
|
this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
|
2445
|
-
this.salt = (0, import_utils13.hexlify)(salt ??
|
2453
|
+
this.salt = (0, import_utils13.hexlify)(salt ?? import_configs9.ZeroBytes32);
|
2446
2454
|
this.storageSlots = [...storageSlots ?? []];
|
2447
2455
|
}
|
2448
2456
|
/**
|
@@ -2460,7 +2468,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2460
2468
|
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2461
2469
|
bytecodeWitnessIndex,
|
2462
2470
|
storageSlotsCount: storageSlots.length,
|
2463
|
-
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) :
|
2471
|
+
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs9.ZeroBytes32,
|
2464
2472
|
storageSlots
|
2465
2473
|
};
|
2466
2474
|
}
|
@@ -2508,9 +2516,9 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2508
2516
|
};
|
2509
2517
|
|
2510
2518
|
// src/providers/transaction-request/script-transaction-request.ts
|
2511
|
-
var
|
2519
|
+
var import_abi_coder = require("@fuel-ts/abi-coder");
|
2512
2520
|
var import_address2 = require("@fuel-ts/address");
|
2513
|
-
var
|
2521
|
+
var import_configs10 = require("@fuel-ts/address/configs");
|
2514
2522
|
var import_math10 = require("@fuel-ts/math");
|
2515
2523
|
var import_transactions9 = require("@fuel-ts/transactions");
|
2516
2524
|
var import_utils15 = require("@fuel-ts/utils");
|
@@ -2563,7 +2571,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2563
2571
|
*
|
2564
2572
|
* @param scriptTransactionRequestLike - The initial values for the instance.
|
2565
2573
|
*/
|
2566
|
-
constructor({ script, scriptData, gasLimit, ...rest }) {
|
2574
|
+
constructor({ script, scriptData, gasLimit, ...rest } = {}) {
|
2567
2575
|
super(rest);
|
2568
2576
|
this.gasLimit = (0, import_math10.bn)(gasLimit);
|
2569
2577
|
this.script = (0, import_utils15.arrayify)(script ?? returnZeroScript.bytes);
|
@@ -2584,7 +2592,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2584
2592
|
...super.getBaseTransaction(),
|
2585
2593
|
scriptLength: script.length,
|
2586
2594
|
scriptDataLength: scriptData.length,
|
2587
|
-
receiptsRoot:
|
2595
|
+
receiptsRoot: import_configs10.ZeroBytes32,
|
2588
2596
|
script: (0, import_utils15.hexlify)(script),
|
2589
2597
|
scriptData: (0, import_utils15.hexlify)(scriptData)
|
2590
2598
|
};
|
@@ -2700,7 +2708,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2700
2708
|
* @returns The current instance of the `ScriptTransactionRequest`.
|
2701
2709
|
*/
|
2702
2710
|
setData(abi, args) {
|
2703
|
-
const abiInterface = new
|
2711
|
+
const abiInterface = new import_abi_coder.Interface(abi);
|
2704
2712
|
this.scriptData = abiInterface.functions.main.encodeArguments(args);
|
2705
2713
|
return this;
|
2706
2714
|
}
|
@@ -2816,23 +2824,23 @@ var calculateTransactionFee = (params) => {
|
|
2816
2824
|
};
|
2817
2825
|
|
2818
2826
|
// src/providers/transaction-summary/operations.ts
|
2819
|
-
var
|
2827
|
+
var import_configs11 = require("@fuel-ts/address/configs");
|
2820
2828
|
var import_errors11 = require("@fuel-ts/errors");
|
2821
2829
|
var import_math13 = require("@fuel-ts/math");
|
2822
2830
|
var import_transactions14 = require("@fuel-ts/transactions");
|
2823
2831
|
|
2824
2832
|
// src/providers/transaction-summary/call.ts
|
2825
|
-
var
|
2833
|
+
var import_abi_coder2 = require("@fuel-ts/abi-coder");
|
2826
2834
|
var import_math12 = require("@fuel-ts/math");
|
2827
2835
|
var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
2828
|
-
const abiInterface = new
|
2836
|
+
const abiInterface = new import_abi_coder2.Interface(abi);
|
2829
2837
|
const callFunctionSelector = receipt.param1.toHex(8);
|
2830
2838
|
const functionFragment = abiInterface.getFunction(callFunctionSelector);
|
2831
2839
|
const inputs = functionFragment.jsonFn.inputs;
|
2832
2840
|
let encodedArgs;
|
2833
2841
|
if (functionFragment.isInputDataPointer) {
|
2834
2842
|
if (rawPayload) {
|
2835
|
-
const argsOffset = (0, import_math12.bn)(receipt.param2).sub((0,
|
2843
|
+
const argsOffset = (0, import_math12.bn)(receipt.param2).sub((0, import_abi_coder2.calculateVmTxMemory)({ maxInputs: maxInputs.toNumber() })).toNumber();
|
2836
2844
|
encodedArgs = `0x${rawPayload.slice(2).slice(argsOffset * 2)}`;
|
2837
2845
|
}
|
2838
2846
|
} else {
|
@@ -3161,7 +3169,7 @@ function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutp
|
|
3161
3169
|
const { to: toAddress, assetId, amount } = receipt;
|
3162
3170
|
let { from: fromAddress } = receipt;
|
3163
3171
|
const toType = contractInputs.some((input) => input.contractID === toAddress) ? 0 /* contract */ : 1 /* account */;
|
3164
|
-
if (
|
3172
|
+
if (import_configs11.ZeroBytes32 === fromAddress) {
|
3165
3173
|
const change = changeOutputs.find((output) => output.assetId === assetId);
|
3166
3174
|
fromAddress = change?.to || fromAddress;
|
3167
3175
|
}
|
@@ -3482,13 +3490,13 @@ function assembleTransactionSummary(params) {
|
|
3482
3490
|
}
|
3483
3491
|
|
3484
3492
|
// src/providers/transaction-response/getDecodedLogs.ts
|
3485
|
-
var
|
3493
|
+
var import_abi_coder3 = require("@fuel-ts/abi-coder");
|
3486
3494
|
var import_transactions16 = require("@fuel-ts/transactions");
|
3487
3495
|
function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
3488
3496
|
return receipts.reduce((logs, receipt) => {
|
3489
3497
|
if (receipt.type === import_transactions16.ReceiptType.LogData || receipt.type === import_transactions16.ReceiptType.Log) {
|
3490
|
-
const interfaceToUse = new
|
3491
|
-
const data = receipt.type === import_transactions16.ReceiptType.Log ? new
|
3498
|
+
const interfaceToUse = new import_abi_coder3.Interface(externalAbis[receipt.id] || mainAbi);
|
3499
|
+
const data = receipt.type === import_transactions16.ReceiptType.Log ? new import_abi_coder3.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
|
3492
3500
|
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
|
3493
3501
|
logs.push(decodedLog);
|
3494
3502
|
}
|
@@ -3738,7 +3746,6 @@ var processGqlChain = (chain) => {
|
|
3738
3746
|
gasPerByte: (0, import_math15.bn)(feeParams.gasPerByte),
|
3739
3747
|
maxMessageDataLength: (0, import_math15.bn)(predicateParams.maxMessageDataLength),
|
3740
3748
|
chainId: (0, import_math15.bn)(consensusParameters.chainId),
|
3741
|
-
baseAssetId: consensusParameters.baseAssetId,
|
3742
3749
|
gasCosts
|
3743
3750
|
},
|
3744
3751
|
gasCosts,
|
@@ -3981,17 +3988,6 @@ var _Provider = class {
|
|
3981
3988
|
} = this.getChain();
|
3982
3989
|
return chainId.toNumber();
|
3983
3990
|
}
|
3984
|
-
/**
|
3985
|
-
* Returns the base asset ID
|
3986
|
-
*
|
3987
|
-
* @returns A promise that resolves to the base asset ID
|
3988
|
-
*/
|
3989
|
-
getBaseAssetId() {
|
3990
|
-
const {
|
3991
|
-
consensusParameters: { baseAssetId }
|
3992
|
-
} = this.getChain();
|
3993
|
-
return baseAssetId;
|
3994
|
-
}
|
3995
3991
|
/**
|
3996
3992
|
* Submits a transaction to the chain to be executed.
|
3997
3993
|
*
|
@@ -4142,36 +4138,6 @@ var _Provider = class {
|
|
4142
4138
|
missingContractIds
|
4143
4139
|
};
|
4144
4140
|
}
|
4145
|
-
/**
|
4146
|
-
* Estimates the transaction gas and fee based on the provided transaction request.
|
4147
|
-
* @param transactionRequest - The transaction request object.
|
4148
|
-
* @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
|
4149
|
-
*/
|
4150
|
-
estimateTxGasAndFee(params) {
|
4151
|
-
const { transactionRequest } = params;
|
4152
|
-
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
4153
|
-
const chainInfo = this.getChain();
|
4154
|
-
const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
|
4155
|
-
transactionRequest.gasPrice = gasPrice;
|
4156
|
-
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
4157
|
-
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4158
|
-
if (transactionRequest.type === import_transactions18.TransactionType.Script) {
|
4159
|
-
if (transactionRequest.gasLimit.eq(0)) {
|
4160
|
-
transactionRequest.gasLimit = minGas;
|
4161
|
-
transactionRequest.gasLimit = maxGasPerTx.sub(
|
4162
|
-
transactionRequest.calculateMaxGas(chainInfo, minGas)
|
4163
|
-
);
|
4164
|
-
}
|
4165
|
-
}
|
4166
|
-
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4167
|
-
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4168
|
-
return {
|
4169
|
-
minGas,
|
4170
|
-
minFee,
|
4171
|
-
maxGas,
|
4172
|
-
maxFee
|
4173
|
-
};
|
4174
|
-
}
|
4175
4141
|
/**
|
4176
4142
|
* Executes a signed transaction without applying the states changes
|
4177
4143
|
* on the chain.
|
@@ -4219,16 +4185,17 @@ var _Provider = class {
|
|
4219
4185
|
signatureCallback
|
4220
4186
|
} = {}) {
|
4221
4187
|
const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
|
4222
|
-
const
|
4223
|
-
const
|
4188
|
+
const chainInfo = this.getChain();
|
4189
|
+
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
4190
|
+
const gasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
|
4224
4191
|
const isScriptTransaction = txRequestClone.type === import_transactions18.TransactionType.Script;
|
4225
4192
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
4226
4193
|
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
4227
4194
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4228
|
-
if (isScriptTransaction) {
|
4229
|
-
txRequestClone.gasLimit = (0, import_math15.bn)(0);
|
4230
|
-
}
|
4231
4195
|
if (estimatePredicates) {
|
4196
|
+
if (isScriptTransaction) {
|
4197
|
+
txRequestClone.gasLimit = (0, import_math15.bn)(0);
|
4198
|
+
}
|
4232
4199
|
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4233
4200
|
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
4234
4201
|
}
|
@@ -4237,34 +4204,36 @@ var _Provider = class {
|
|
4237
4204
|
if (signatureCallback && isScriptTransaction) {
|
4238
4205
|
await signatureCallback(txRequestClone);
|
4239
4206
|
}
|
4240
|
-
|
4241
|
-
|
4242
|
-
});
|
4207
|
+
const minGas = txRequestClone.calculateMinGas(chainInfo);
|
4208
|
+
const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
|
4243
4209
|
let receipts = [];
|
4244
4210
|
let missingContractIds = [];
|
4245
4211
|
let outputVariables = 0;
|
4246
|
-
let gasUsed = (0, import_math15.bn)(0);
|
4247
4212
|
if (isScriptTransaction && estimateTxDependencies) {
|
4248
4213
|
txRequestClone.gasPrice = (0, import_math15.bn)(0);
|
4214
|
+
txRequestClone.gasLimit = (0, import_math15.bn)(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
|
4249
4215
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4250
4216
|
receipts = result.receipts;
|
4251
4217
|
outputVariables = result.outputVariables;
|
4252
4218
|
missingContractIds = result.missingContractIds;
|
4253
|
-
gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
|
4254
|
-
txRequestClone.gasLimit = gasUsed;
|
4255
|
-
txRequestClone.gasPrice = setGasPrice;
|
4256
|
-
({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
4257
|
-
transactionRequest: txRequestClone
|
4258
|
-
}));
|
4259
4219
|
}
|
4220
|
+
const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
|
4221
|
+
const usedFee = calculatePriceWithFactor(
|
4222
|
+
gasUsed,
|
4223
|
+
gasPrice,
|
4224
|
+
gasPriceFactor
|
4225
|
+
).normalizeZeroToOne();
|
4226
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4227
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4260
4228
|
return {
|
4261
4229
|
requiredQuantities: allQuantities,
|
4262
4230
|
receipts,
|
4263
4231
|
gasUsed,
|
4264
4232
|
minGasPrice,
|
4265
|
-
gasPrice
|
4233
|
+
gasPrice,
|
4266
4234
|
minGas,
|
4267
4235
|
maxGas,
|
4236
|
+
usedFee,
|
4268
4237
|
minFee,
|
4269
4238
|
maxFee,
|
4270
4239
|
estimatedInputs: txRequestClone.inputs,
|
@@ -4897,13 +4866,13 @@ var assets = [
|
|
4897
4866
|
];
|
4898
4867
|
|
4899
4868
|
// src/utils/formatTransferToContractScriptData.ts
|
4900
|
-
var
|
4869
|
+
var import_abi_coder4 = require("@fuel-ts/abi-coder");
|
4901
4870
|
var import_math17 = require("@fuel-ts/math");
|
4902
4871
|
var import_utils27 = require("@fuel-ts/utils");
|
4903
4872
|
var asm = __toESM(require("@fuels/vm-asm"));
|
4904
4873
|
var formatTransferToContractScriptData = (params) => {
|
4905
4874
|
const { assetId, amountToTransfer, hexlifiedContractId } = params;
|
4906
|
-
const numberCoder = new
|
4875
|
+
const numberCoder = new import_abi_coder4.BigNumberCoder("u64");
|
4907
4876
|
const encoded = numberCoder.encode(new import_math17.BN(amountToTransfer).toNumber());
|
4908
4877
|
const scriptData = Uint8Array.from([
|
4909
4878
|
...(0, import_utils27.arrayify)(hexlifiedContractId),
|
@@ -5055,9 +5024,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5055
5024
|
* @param assetId - The asset ID to check the balance for.
|
5056
5025
|
* @returns A promise that resolves to the balance amount.
|
5057
5026
|
*/
|
5058
|
-
async getBalance(assetId) {
|
5059
|
-
const
|
5060
|
-
const amount = await this.provider.getBalance(this.address, assetIdToFetch);
|
5027
|
+
async getBalance(assetId = import_configs12.BaseAssetId) {
|
5028
|
+
const amount = await this.provider.getBalance(this.address, assetId);
|
5061
5029
|
return amount;
|
5062
5030
|
}
|
5063
5031
|
/**
|
@@ -5095,10 +5063,9 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5095
5063
|
* @returns A promise that resolves when the resources are added to the transaction.
|
5096
5064
|
*/
|
5097
5065
|
async fund(request, coinQuantities, fee) {
|
5098
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
5099
5066
|
const updatedQuantities = addAmountToAsset({
|
5100
5067
|
amount: (0, import_math18.bn)(fee),
|
5101
|
-
assetId:
|
5068
|
+
assetId: import_configs12.BaseAssetId,
|
5102
5069
|
coinQuantities
|
5103
5070
|
});
|
5104
5071
|
const quantitiesDict = {};
|
@@ -5122,8 +5089,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5122
5089
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
5123
5090
|
cachedUtxos.push(input.id);
|
5124
5091
|
}
|
5125
|
-
} else if (input.recipient === owner && input.amount && quantitiesDict[
|
5126
|
-
quantitiesDict[
|
5092
|
+
} else if (input.recipient === owner && input.amount && quantitiesDict[import_configs12.BaseAssetId]) {
|
5093
|
+
quantitiesDict[import_configs12.BaseAssetId].owned = quantitiesDict[import_configs12.BaseAssetId].owned.add(input.amount);
|
5127
5094
|
cachedMessages.push(input.nonce);
|
5128
5095
|
}
|
5129
5096
|
}
|
@@ -5155,13 +5122,11 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5155
5122
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
5156
5123
|
* @returns A promise that resolves to the prepared transaction request.
|
5157
5124
|
*/
|
5158
|
-
async createTransfer(destination, amount, assetId, txParams = {}) {
|
5125
|
+
async createTransfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
5159
5126
|
const { minGasPrice } = this.provider.getGasConfig();
|
5160
|
-
const
|
5161
|
-
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
5162
|
-
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
5127
|
+
const params = { gasPrice: minGasPrice, ...txParams };
|
5163
5128
|
const request = new ScriptTransactionRequest(params);
|
5164
|
-
request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount,
|
5129
|
+
request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetId);
|
5165
5130
|
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
5166
5131
|
estimateTxDependencies: true,
|
5167
5132
|
resourcesOwner: this
|
@@ -5187,15 +5152,14 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5187
5152
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
5188
5153
|
* @returns A promise that resolves to the transaction response.
|
5189
5154
|
*/
|
5190
|
-
async transfer(destination, amount, assetId, txParams = {}) {
|
5155
|
+
async transfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
5191
5156
|
if ((0, import_math18.bn)(amount).lte(0)) {
|
5192
5157
|
throw new import_errors16.FuelError(
|
5193
5158
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
5194
5159
|
"Transfer amount must be a positive number."
|
5195
5160
|
);
|
5196
5161
|
}
|
5197
|
-
const
|
5198
|
-
const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
5162
|
+
const request = await this.createTransfer(destination, amount, assetId, txParams);
|
5199
5163
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
5200
5164
|
}
|
5201
5165
|
/**
|
@@ -5207,7 +5171,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5207
5171
|
* @param txParams - The optional transaction parameters.
|
5208
5172
|
* @returns A promise that resolves to the transaction response.
|
5209
5173
|
*/
|
5210
|
-
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
5174
|
+
async transferToContract(contractId, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
5211
5175
|
if ((0, import_math18.bn)(amount).lte(0)) {
|
5212
5176
|
throw new import_errors16.FuelError(
|
5213
5177
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
@@ -5216,13 +5180,11 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5216
5180
|
}
|
5217
5181
|
const contractAddress = import_address4.Address.fromAddressOrString(contractId);
|
5218
5182
|
const { minGasPrice } = this.provider.getGasConfig();
|
5219
|
-
const
|
5220
|
-
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
5221
|
-
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
5183
|
+
const params = { gasPrice: minGasPrice, ...txParams };
|
5222
5184
|
const { script, scriptData } = await assembleTransferToContractScript({
|
5223
5185
|
hexlifiedContractId: contractAddress.toB256(),
|
5224
5186
|
amountToTransfer: (0, import_math18.bn)(amount),
|
5225
|
-
assetId
|
5187
|
+
assetId
|
5226
5188
|
});
|
5227
5189
|
const request = new ScriptTransactionRequest({
|
5228
5190
|
...params,
|
@@ -5232,7 +5194,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5232
5194
|
request.addContractInputAndOutput(contractAddress);
|
5233
5195
|
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
5234
5196
|
request,
|
5235
|
-
[{ amount: (0, import_math18.bn)(amount), assetId: String(
|
5197
|
+
[{ amount: (0, import_math18.bn)(amount), assetId: String(assetId) }]
|
5236
5198
|
);
|
5237
5199
|
request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
|
5238
5200
|
this.validateGas({
|
@@ -5254,7 +5216,6 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5254
5216
|
*/
|
5255
5217
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
5256
5218
|
const { minGasPrice } = this.provider.getGasConfig();
|
5257
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
5258
5219
|
const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
|
5259
5220
|
const recipientDataArray = (0, import_utils28.arrayify)(
|
5260
5221
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
@@ -5267,14 +5228,9 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5267
5228
|
...recipientDataArray,
|
5268
5229
|
...amountDataArray
|
5269
5230
|
]);
|
5270
|
-
const params = {
|
5271
|
-
script,
|
5272
|
-
gasPrice: minGasPrice,
|
5273
|
-
baseAssetId,
|
5274
|
-
...txParams
|
5275
|
-
};
|
5231
|
+
const params = { script, gasPrice: minGasPrice, ...txParams };
|
5276
5232
|
const request = new ScriptTransactionRequest(params);
|
5277
|
-
const forwardingQuantities = [{ amount: (0, import_math18.bn)(amount), assetId:
|
5233
|
+
const forwardingQuantities = [{ amount: (0, import_math18.bn)(amount), assetId: import_configs12.BaseAssetId }];
|
5278
5234
|
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
5279
5235
|
request,
|
5280
5236
|
forwardingQuantities
|
@@ -5371,7 +5327,7 @@ var import_utils31 = require("@fuel-ts/utils");
|
|
5371
5327
|
|
5372
5328
|
// src/signer/signer.ts
|
5373
5329
|
var import_address5 = require("@fuel-ts/address");
|
5374
|
-
var
|
5330
|
+
var import_crypto = require("@fuel-ts/crypto");
|
5375
5331
|
var import_hasher2 = require("@fuel-ts/hasher");
|
5376
5332
|
var import_math19 = require("@fuel-ts/math");
|
5377
5333
|
var import_utils29 = require("@fuel-ts/utils");
|
@@ -5464,7 +5420,7 @@ var Signer = class {
|
|
5464
5420
|
* @returns random 32-byte hashed
|
5465
5421
|
*/
|
5466
5422
|
static generatePrivateKey(entropy) {
|
5467
|
-
return entropy ? (0, import_hasher2.hash)((0, import_utils29.concat)([(0,
|
5423
|
+
return entropy ? (0, import_hasher2.hash)((0, import_utils29.concat)([(0, import_crypto.randomBytes)(32), (0, import_utils29.arrayify)(entropy)])) : (0, import_crypto.randomBytes)(32);
|
5468
5424
|
}
|
5469
5425
|
/**
|
5470
5426
|
* Extended publicKey from a compact publicKey
|
@@ -5480,7 +5436,7 @@ var Signer = class {
|
|
5480
5436
|
|
5481
5437
|
// src/wallet/keystore-wallet.ts
|
5482
5438
|
var import_address6 = require("@fuel-ts/address");
|
5483
|
-
var
|
5439
|
+
var import_crypto2 = require("@fuel-ts/crypto");
|
5484
5440
|
var import_errors17 = require("@fuel-ts/errors");
|
5485
5441
|
var import_utils30 = require("@fuel-ts/utils");
|
5486
5442
|
var import_uuid = require("uuid");
|
@@ -5496,22 +5452,22 @@ var removeHexPrefix = (hexString) => {
|
|
5496
5452
|
return hexString;
|
5497
5453
|
};
|
5498
5454
|
async function encryptKeystoreWallet(privateKey, address, password) {
|
5499
|
-
const privateKeyBuffer = (0,
|
5455
|
+
const privateKeyBuffer = (0, import_crypto2.bufferFromString)(removeHexPrefix(privateKey), "hex");
|
5500
5456
|
const ownerAddress = import_address6.Address.fromAddressOrString(address);
|
5501
|
-
const salt = (0,
|
5502
|
-
const key = (0,
|
5503
|
-
password: (0,
|
5457
|
+
const salt = (0, import_crypto2.randomBytes)(DEFAULT_KEY_SIZE);
|
5458
|
+
const key = (0, import_crypto2.scrypt)({
|
5459
|
+
password: (0, import_crypto2.bufferFromString)(password),
|
5504
5460
|
salt,
|
5505
5461
|
dklen: DEFAULT_KEY_SIZE,
|
5506
5462
|
n: 2 ** DEFAULT_KDF_PARAMS_LOG_N,
|
5507
5463
|
r: DEFAULT_KDF_PARAMS_R,
|
5508
5464
|
p: DEFAULT_KDF_PARAMS_P
|
5509
5465
|
});
|
5510
|
-
const iv = (0,
|
5511
|
-
const ciphertext = await (0,
|
5466
|
+
const iv = (0, import_crypto2.randomBytes)(DEFAULT_IV_SIZE);
|
5467
|
+
const ciphertext = await (0, import_crypto2.encryptJsonWalletData)(privateKeyBuffer, key, iv);
|
5512
5468
|
const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertext]);
|
5513
|
-
const macHashUint8Array = (0,
|
5514
|
-
const mac = (0,
|
5469
|
+
const macHashUint8Array = (0, import_crypto2.keccak256)(data);
|
5470
|
+
const mac = (0, import_crypto2.stringFromBuffer)(macHashUint8Array, "hex");
|
5515
5471
|
const keystore = {
|
5516
5472
|
id: (0, import_uuid.v4)(),
|
5517
5473
|
version: 3,
|
@@ -5519,15 +5475,15 @@ async function encryptKeystoreWallet(privateKey, address, password) {
|
|
5519
5475
|
crypto: {
|
5520
5476
|
cipher: "aes-128-ctr",
|
5521
5477
|
mac,
|
5522
|
-
cipherparams: { iv: (0,
|
5523
|
-
ciphertext: (0,
|
5478
|
+
cipherparams: { iv: (0, import_crypto2.stringFromBuffer)(iv, "hex") },
|
5479
|
+
ciphertext: (0, import_crypto2.stringFromBuffer)(ciphertext, "hex"),
|
5524
5480
|
kdf: "scrypt",
|
5525
5481
|
kdfparams: {
|
5526
5482
|
dklen: DEFAULT_KEY_SIZE,
|
5527
5483
|
n: 2 ** DEFAULT_KDF_PARAMS_LOG_N,
|
5528
5484
|
p: DEFAULT_KDF_PARAMS_P,
|
5529
5485
|
r: DEFAULT_KDF_PARAMS_R,
|
5530
|
-
salt: (0,
|
5486
|
+
salt: (0, import_crypto2.stringFromBuffer)(salt, "hex")
|
5531
5487
|
}
|
5532
5488
|
}
|
5533
5489
|
};
|
@@ -5543,11 +5499,11 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5543
5499
|
kdfparams: { dklen, n, r, p, salt }
|
5544
5500
|
}
|
5545
5501
|
} = keystoreWallet;
|
5546
|
-
const ciphertextBuffer = (0,
|
5547
|
-
const ivBuffer = (0,
|
5548
|
-
const saltBuffer = (0,
|
5549
|
-
const passwordBuffer = (0,
|
5550
|
-
const key = (0,
|
5502
|
+
const ciphertextBuffer = (0, import_crypto2.bufferFromString)(ciphertext, "hex");
|
5503
|
+
const ivBuffer = (0, import_crypto2.bufferFromString)(iv, "hex");
|
5504
|
+
const saltBuffer = (0, import_crypto2.bufferFromString)(salt, "hex");
|
5505
|
+
const passwordBuffer = (0, import_crypto2.bufferFromString)(password);
|
5506
|
+
const key = (0, import_crypto2.scrypt)({
|
5551
5507
|
password: passwordBuffer,
|
5552
5508
|
salt: saltBuffer,
|
5553
5509
|
n,
|
@@ -5556,15 +5512,15 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5556
5512
|
dklen
|
5557
5513
|
});
|
5558
5514
|
const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertextBuffer]);
|
5559
|
-
const macHashUint8Array = (0,
|
5560
|
-
const macHash = (0,
|
5515
|
+
const macHashUint8Array = (0, import_crypto2.keccak256)(data);
|
5516
|
+
const macHash = (0, import_crypto2.stringFromBuffer)(macHashUint8Array, "hex");
|
5561
5517
|
if (mac !== macHash) {
|
5562
5518
|
throw new import_errors17.FuelError(
|
5563
5519
|
import_errors17.ErrorCode.INVALID_PASSWORD,
|
5564
5520
|
"Failed to decrypt the keystore wallet, the provided password is incorrect."
|
5565
5521
|
);
|
5566
5522
|
}
|
5567
|
-
const buffer = await (0,
|
5523
|
+
const buffer = await (0, import_crypto2.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
|
5568
5524
|
const privateKey = (0, import_utils30.hexlify)(buffer);
|
5569
5525
|
return privateKey;
|
5570
5526
|
}
|
@@ -5689,7 +5645,7 @@ var import_utils35 = require("@fuel-ts/utils");
|
|
5689
5645
|
var import_ethers3 = require("ethers");
|
5690
5646
|
|
5691
5647
|
// src/mnemonic/mnemonic.ts
|
5692
|
-
var
|
5648
|
+
var import_crypto3 = require("@fuel-ts/crypto");
|
5693
5649
|
var import_errors19 = require("@fuel-ts/errors");
|
5694
5650
|
var import_hasher5 = require("@fuel-ts/hasher");
|
5695
5651
|
var import_utils33 = require("@fuel-ts/utils");
|
@@ -8050,7 +8006,7 @@ var Mnemonic = class {
|
|
8050
8006
|
* @returns A randomly generated mnemonic
|
8051
8007
|
*/
|
8052
8008
|
static generate(size = 32, extraEntropy = "") {
|
8053
|
-
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils33.concat)([(0,
|
8009
|
+
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils33.concat)([(0, import_crypto3.randomBytes)(size), (0, import_utils33.arrayify)(extraEntropy)])) : (0, import_crypto3.randomBytes)(size);
|
8054
8010
|
return Mnemonic.entropyToMnemonic(entropy);
|
8055
8011
|
}
|
8056
8012
|
};
|
@@ -8422,7 +8378,7 @@ __publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
|
|
8422
8378
|
|
8423
8379
|
// src/wallet-manager/wallet-manager.ts
|
8424
8380
|
var import_address9 = require("@fuel-ts/address");
|
8425
|
-
var
|
8381
|
+
var import_crypto4 = require("@fuel-ts/crypto");
|
8426
8382
|
var import_errors23 = require("@fuel-ts/errors");
|
8427
8383
|
var import_events = require("events");
|
8428
8384
|
|
@@ -8750,7 +8706,7 @@ var _WalletManager = class extends import_events.EventEmitter {
|
|
8750
8706
|
await assert(!__privateGet(this, _isLocked), ERROR_MESSAGES.wallet_not_unlocked);
|
8751
8707
|
const data = await this.storage.getItem(this.STORAGE_KEY);
|
8752
8708
|
if (data) {
|
8753
|
-
const state = await (0,
|
8709
|
+
const state = await (0, import_crypto4.decrypt)(__privateGet(this, _passphrase), JSON.parse(data));
|
8754
8710
|
__privateSet(this, _vaults, __privateMethod(this, _deserializeVaults, deserializeVaults_fn).call(this, state.vaults));
|
8755
8711
|
}
|
8756
8712
|
}
|
@@ -8759,7 +8715,7 @@ var _WalletManager = class extends import_events.EventEmitter {
|
|
8759
8715
|
*/
|
8760
8716
|
async saveState() {
|
8761
8717
|
await assert(!__privateGet(this, _isLocked), ERROR_MESSAGES.wallet_not_unlocked);
|
8762
|
-
const encryptedData = await (0,
|
8718
|
+
const encryptedData = await (0, import_crypto4.encrypt)(__privateGet(this, _passphrase), {
|
8763
8719
|
vaults: __privateMethod(this, _serializeVaults, serializeVaults_fn).call(this, __privateGet(this, _vaults))
|
8764
8720
|
});
|
8765
8721
|
await this.storage.setItem(this.STORAGE_KEY, JSON.stringify(encryptedData));
|
@@ -8835,8 +8791,9 @@ var StorageAbstract = class {
|
|
8835
8791
|
};
|
8836
8792
|
|
8837
8793
|
// src/predicate/predicate.ts
|
8838
|
-
var
|
8794
|
+
var import_abi_coder5 = require("@fuel-ts/abi-coder");
|
8839
8795
|
var import_address10 = require("@fuel-ts/address");
|
8796
|
+
var import_configs13 = require("@fuel-ts/address/configs");
|
8840
8797
|
var import_errors25 = require("@fuel-ts/errors");
|
8841
8798
|
var import_transactions20 = require("@fuel-ts/transactions");
|
8842
8799
|
var import_utils37 = require("@fuel-ts/utils");
|
@@ -8914,9 +8871,8 @@ var Predicate = class extends Account {
|
|
8914
8871
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
8915
8872
|
* @returns A promise that resolves to the prepared transaction request.
|
8916
8873
|
*/
|
8917
|
-
async createTransfer(destination, amount, assetId, txParams = {}) {
|
8918
|
-
const
|
8919
|
-
const request = await super.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
8874
|
+
async createTransfer(destination, amount, assetId = import_configs13.BaseAssetId, txParams = {}) {
|
8875
|
+
const request = await super.createTransfer(destination, amount, assetId, txParams);
|
8920
8876
|
return this.populateTransactionPredicateData(request);
|
8921
8877
|
}
|
8922
8878
|
/**
|
@@ -8945,10 +8901,10 @@ var Predicate = class extends Account {
|
|
8945
8901
|
}
|
8946
8902
|
const mainFn = this.interface?.functions.main;
|
8947
8903
|
const paddedCode = new import_transactions20.ByteArrayCoder(this.bytes.length).encode(this.bytes);
|
8948
|
-
const VM_TX_MEMORY = (0,
|
8904
|
+
const VM_TX_MEMORY = (0, import_abi_coder5.calculateVmTxMemory)({
|
8949
8905
|
maxInputs: this.provider.getChain().consensusParameters.maxInputs.toNumber()
|
8950
8906
|
});
|
8951
|
-
const OFFSET = VM_TX_MEMORY +
|
8907
|
+
const OFFSET = VM_TX_MEMORY + import_abi_coder5.SCRIPT_FIXED_SIZE + import_abi_coder5.INPUT_COIN_FIXED_SIZE + import_abi_coder5.WORD_SIZE + paddedCode.byteLength + policiesLength * import_abi_coder5.WORD_SIZE;
|
8952
8908
|
return mainFn?.encodeArguments(this.predicateData, OFFSET) || new Uint8Array();
|
8953
8909
|
}
|
8954
8910
|
/**
|
@@ -8963,7 +8919,7 @@ var Predicate = class extends Account {
|
|
8963
8919
|
let predicateBytes = (0, import_utils37.arrayify)(bytes);
|
8964
8920
|
let abiInterface;
|
8965
8921
|
if (jsonAbi) {
|
8966
|
-
abiInterface = new
|
8922
|
+
abiInterface = new import_abi_coder5.Interface(jsonAbi);
|
8967
8923
|
if (abiInterface.functions.main === void 0) {
|
8968
8924
|
throw new import_errors25.FuelError(
|
8969
8925
|
import_errors25.ErrorCode.ABI_MAIN_METHOD_MISSING,
|