@fuel-ts/account 0.0.0-rc-1976-20240410144111 → 0.0.0-rc-2034-20240410182856

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of @fuel-ts/account might be problematic. Click here for more details.

package/dist/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,7 +1173,8 @@ var MemoryCache = class {
1171
1173
  };
1172
1174
 
1173
1175
  // src/providers/transaction-request/input.ts
1174
- var import_configs = require("@fuel-ts/address/configs");
1176
+ var import_abi_coder = require("@fuel-ts/abi-coder");
1177
+ var import_configs2 = require("@fuel-ts/address/configs");
1175
1178
  var import_errors3 = require("@fuel-ts/errors");
1176
1179
  var import_math2 = require("@fuel-ts/math");
1177
1180
  var import_transactions = require("@fuel-ts/transactions");
@@ -1184,8 +1187,8 @@ var inputify = (value) => {
1184
1187
  const predicateData = (0, import_utils3.arrayify)(value.predicateData ?? "0x");
1185
1188
  return {
1186
1189
  type: import_transactions.InputType.Coin,
1187
- txID: (0, import_utils3.hexlify)((0, import_utils3.arrayify)(value.id).slice(0, 32)),
1188
- outputIndex: (0, import_utils3.arrayify)(value.id)[32],
1190
+ txID: (0, import_utils3.hexlify)((0, import_utils3.arrayify)(value.id).slice(0, import_abi_coder.BYTES_32)),
1191
+ outputIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.id).slice(import_abi_coder.BYTES_32, import_abi_coder.UTXO_ID_LEN)),
1189
1192
  owner: (0, import_utils3.hexlify)(value.owner),
1190
1193
  amount: (0, import_math2.bn)(value.amount),
1191
1194
  assetId: (0, import_utils3.hexlify)(value.assetId),
@@ -1205,10 +1208,10 @@ var inputify = (value) => {
1205
1208
  case import_transactions.InputType.Contract: {
1206
1209
  return {
1207
1210
  type: import_transactions.InputType.Contract,
1208
- txID: import_configs.ZeroBytes32,
1211
+ txID: import_configs2.ZeroBytes32,
1209
1212
  outputIndex: 0,
1210
- balanceRoot: import_configs.ZeroBytes32,
1211
- stateRoot: import_configs.ZeroBytes32,
1213
+ balanceRoot: import_configs2.ZeroBytes32,
1214
+ stateRoot: import_configs2.ZeroBytes32,
1212
1215
  txPointer: {
1213
1216
  blockHeight: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(0, 8)),
1214
1217
  txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
@@ -1246,7 +1249,7 @@ var inputify = (value) => {
1246
1249
  };
1247
1250
 
1248
1251
  // src/providers/transaction-request/output.ts
1249
- var import_configs2 = require("@fuel-ts/address/configs");
1252
+ var import_configs3 = require("@fuel-ts/address/configs");
1250
1253
  var import_errors4 = require("@fuel-ts/errors");
1251
1254
  var import_math3 = require("@fuel-ts/math");
1252
1255
  var import_transactions2 = require("@fuel-ts/transactions");
@@ -1266,8 +1269,8 @@ var outputify = (value) => {
1266
1269
  return {
1267
1270
  type: import_transactions2.OutputType.Contract,
1268
1271
  inputIndex: value.inputIndex,
1269
- balanceRoot: import_configs2.ZeroBytes32,
1270
- stateRoot: import_configs2.ZeroBytes32
1272
+ balanceRoot: import_configs3.ZeroBytes32,
1273
+ stateRoot: import_configs3.ZeroBytes32
1271
1274
  };
1272
1275
  }
1273
1276
  case import_transactions2.OutputType.Change: {
@@ -1281,9 +1284,9 @@ var outputify = (value) => {
1281
1284
  case import_transactions2.OutputType.Variable: {
1282
1285
  return {
1283
1286
  type: import_transactions2.OutputType.Variable,
1284
- to: import_configs2.ZeroBytes32,
1287
+ to: import_configs3.ZeroBytes32,
1285
1288
  amount: (0, import_math3.bn)(0),
1286
- assetId: import_configs2.ZeroBytes32
1289
+ assetId: import_configs3.ZeroBytes32
1287
1290
  };
1288
1291
  }
1289
1292
  case import_transactions2.OutputType.ContractCreated: {
@@ -1303,8 +1306,10 @@ var outputify = (value) => {
1303
1306
  };
1304
1307
 
1305
1308
  // src/providers/transaction-request/transaction-request.ts
1309
+ var import_abi_coder2 = require("@fuel-ts/abi-coder");
1306
1310
  var import_address = require("@fuel-ts/address");
1307
- var import_configs6 = require("@fuel-ts/address/configs");
1311
+ var import_configs7 = require("@fuel-ts/address/configs");
1312
+ var import_crypto = require("@fuel-ts/crypto");
1308
1313
  var import_math7 = require("@fuel-ts/math");
1309
1314
  var import_transactions6 = require("@fuel-ts/transactions");
1310
1315
  var import_utils9 = require("@fuel-ts/utils");
@@ -1316,13 +1321,13 @@ var isCoin = (resource) => "id" in resource;
1316
1321
  var isMessage = (resource) => "recipient" in resource;
1317
1322
 
1318
1323
  // src/providers/utils/receipts.ts
1319
- var import_configs3 = require("@fuel-ts/address/configs");
1324
+ var import_configs4 = require("@fuel-ts/address/configs");
1320
1325
  var import_errors5 = require("@fuel-ts/errors");
1321
1326
  var import_math4 = require("@fuel-ts/math");
1322
1327
  var import_transactions3 = require("@fuel-ts/transactions");
1323
- var import_configs4 = require("@fuel-ts/transactions/configs");
1328
+ var import_configs5 = require("@fuel-ts/transactions/configs");
1324
1329
  var import_utils5 = require("@fuel-ts/utils");
1325
- var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions3.ReceiptType.Revert && receipt.val.toString("hex") === import_configs4.FAILED_TRANSFER_TO_ADDRESS_SIGNAL;
1330
+ var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions3.ReceiptType.Revert && receipt.val.toString("hex") === import_configs5.FAILED_TRANSFER_TO_ADDRESS_SIGNAL;
1326
1331
  var doesReceiptHaveMissingContractId = (receipt) => receipt.type === import_transactions3.ReceiptType.Panic && receipt.contractId !== "0x0000000000000000000000000000000000000000000000000000000000000000";
1327
1332
  var getReceiptsWithMissingData = (receipts) => receipts.reduce(
1328
1333
  (memo, receipt) => {
@@ -1339,7 +1344,7 @@ var getReceiptsWithMissingData = (receipts) => receipts.reduce(
1339
1344
  missingOutputContractIds: []
1340
1345
  }
1341
1346
  );
1342
- var hexOrZero = (hex) => hex || import_configs3.ZeroBytes32;
1347
+ var hexOrZero = (hex) => hex || import_configs4.ZeroBytes32;
1343
1348
  function assembleReceiptByType(receipt) {
1344
1349
  const { receiptType } = receipt;
1345
1350
  switch (receiptType) {
@@ -1703,16 +1708,16 @@ function sleep(time) {
1703
1708
  var import_errors7 = require("@fuel-ts/errors");
1704
1709
  var import_math6 = require("@fuel-ts/math");
1705
1710
  var import_transactions5 = require("@fuel-ts/transactions");
1706
- var import_configs5 = require("@fuel-ts/transactions/configs");
1711
+ var import_configs6 = require("@fuel-ts/transactions/configs");
1707
1712
  var assemblePanicError = (status) => {
1708
1713
  let errorMessage = `The transaction reverted with reason: "${status.reason}".`;
1709
1714
  const reason = status.reason;
1710
- if (import_configs5.PANIC_REASONS.includes(status.reason)) {
1715
+ if (import_configs6.PANIC_REASONS.includes(status.reason)) {
1711
1716
  errorMessage = `${errorMessage}
1712
1717
 
1713
1718
  You can read more about this error at:
1714
1719
 
1715
- ${import_configs5.PANIC_DOC_URL}#variant.${status.reason}`;
1720
+ ${import_configs6.PANIC_DOC_URL}#variant.${status.reason}`;
1716
1721
  }
1717
1722
  return { errorMessage, reason };
1718
1723
  };
@@ -1724,28 +1729,28 @@ var assembleRevertError = (receipts, logs) => {
1724
1729
  if (revertReceipt) {
1725
1730
  const reasonHex = (0, import_math6.bn)(revertReceipt.val).toHex();
1726
1731
  switch (reasonHex) {
1727
- case import_configs5.FAILED_REQUIRE_SIGNAL: {
1732
+ case import_configs6.FAILED_REQUIRE_SIGNAL: {
1728
1733
  reason = "require";
1729
1734
  errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(logs[0]) : "an error."}.`;
1730
1735
  break;
1731
1736
  }
1732
- case import_configs5.FAILED_ASSERT_EQ_SIGNAL: {
1737
+ case import_configs6.FAILED_ASSERT_EQ_SIGNAL: {
1733
1738
  const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
1734
1739
  reason = "assert_eq";
1735
1740
  errorMessage = `The transaction reverted because of an "assert_eq" statement${sufix}`;
1736
1741
  break;
1737
1742
  }
1738
- case import_configs5.FAILED_ASSERT_NE_SIGNAL: {
1743
+ case import_configs6.FAILED_ASSERT_NE_SIGNAL: {
1739
1744
  const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
1740
1745
  reason = "assert_ne";
1741
1746
  errorMessage = `The transaction reverted because of an "assert_ne" statement${sufix}`;
1742
1747
  break;
1743
1748
  }
1744
- case import_configs5.FAILED_ASSERT_SIGNAL:
1749
+ case import_configs6.FAILED_ASSERT_SIGNAL:
1745
1750
  reason = "assert";
1746
1751
  errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
1747
1752
  break;
1748
- case import_configs5.FAILED_TRANSFER_TO_ADDRESS_SIGNAL:
1753
+ case import_configs6.FAILED_TRANSFER_TO_ADDRESS_SIGNAL:
1749
1754
  reason = "MissingOutputChange";
1750
1755
  errorMessage = `The transaction reverted because it's missing an "OutputChange".`;
1751
1756
  break;
@@ -1819,8 +1824,6 @@ var BaseTransactionRequest = class {
1819
1824
  outputs = [];
1820
1825
  /** List of witnesses */
1821
1826
  witnesses = [];
1822
- /** Base asset ID - should be fetched from the chain */
1823
- baseAssetId;
1824
1827
  /**
1825
1828
  * Constructor for initializing a base transaction request.
1826
1829
  *
@@ -1833,9 +1836,8 @@ var BaseTransactionRequest = class {
1833
1836
  witnessLimit,
1834
1837
  inputs,
1835
1838
  outputs,
1836
- witnesses,
1837
- baseAssetId
1838
- }) {
1839
+ witnesses
1840
+ } = {}) {
1839
1841
  this.gasPrice = (0, import_math7.bn)(gasPrice);
1840
1842
  this.maturity = maturity ?? 0;
1841
1843
  this.witnessLimit = witnessLimit ? (0, import_math7.bn)(witnessLimit) : void 0;
@@ -1843,7 +1845,6 @@ var BaseTransactionRequest = class {
1843
1845
  this.inputs = inputs ?? [];
1844
1846
  this.outputs = outputs ?? [];
1845
1847
  this.witnesses = witnesses ?? [];
1846
- this.baseAssetId = baseAssetId;
1847
1848
  }
1848
1849
  static getPolicyMeta(req) {
1849
1850
  let policyTypes = 0;
@@ -1936,7 +1937,7 @@ var BaseTransactionRequest = class {
1936
1937
  * @returns The index of the created witness.
1937
1938
  */
1938
1939
  addEmptyWitness() {
1939
- this.addWitness((0, import_utils9.concat)([import_configs6.ZeroBytes32, import_configs6.ZeroBytes32]));
1940
+ this.addWitness((0, import_utils9.concat)([import_configs7.ZeroBytes32, import_configs7.ZeroBytes32]));
1940
1941
  return this.witnesses.length - 1;
1941
1942
  }
1942
1943
  /**
@@ -2067,9 +2068,11 @@ var BaseTransactionRequest = class {
2067
2068
  *
2068
2069
  * @param message - Message resource.
2069
2070
  * @param predicate - Predicate bytes.
2071
+ * @param predicateData - Predicate data bytes.
2070
2072
  */
2071
2073
  addMessageInput(message, predicate) {
2072
2074
  const { recipient, sender, amount } = message;
2075
+ const assetId = import_configs7.BaseAssetId;
2073
2076
  let witnessIndex;
2074
2077
  if (predicate) {
2075
2078
  witnessIndex = 0;
@@ -2089,7 +2092,7 @@ var BaseTransactionRequest = class {
2089
2092
  predicate: predicate?.bytes
2090
2093
  };
2091
2094
  this.pushInput(input);
2092
- this.addChangeOutput(recipient, this.baseAssetId);
2095
+ this.addChangeOutput(recipient, assetId);
2093
2096
  }
2094
2097
  /**
2095
2098
  * Adds a single resource to the transaction by adding a coin/message input and a
@@ -2150,12 +2153,12 @@ var BaseTransactionRequest = class {
2150
2153
  * @param amount - Amount of coin.
2151
2154
  * @param assetId - Asset ID of coin.
2152
2155
  */
2153
- addCoinOutput(to, amount, assetId) {
2156
+ addCoinOutput(to, amount, assetId = import_configs7.BaseAssetId) {
2154
2157
  this.pushOutput({
2155
2158
  type: import_transactions6.OutputType.Coin,
2156
2159
  to: (0, import_address.addressify)(to).toB256(),
2157
2160
  amount,
2158
- assetId: assetId ?? this.baseAssetId
2161
+ assetId
2159
2162
  });
2160
2163
  return this;
2161
2164
  }
@@ -2182,7 +2185,7 @@ var BaseTransactionRequest = class {
2182
2185
  * @param to - Address of the owner.
2183
2186
  * @param assetId - Asset ID of coin.
2184
2187
  */
2185
- addChangeOutput(to, assetId) {
2188
+ addChangeOutput(to, assetId = import_configs7.BaseAssetId) {
2186
2189
  const changeOutput = this.getChangeOutputs().find(
2187
2190
  (output) => (0, import_utils9.hexlify)(output.assetId) === assetId
2188
2191
  );
@@ -2190,7 +2193,7 @@ var BaseTransactionRequest = class {
2190
2193
  this.pushOutput({
2191
2194
  type: import_transactions6.OutputType.Change,
2192
2195
  to: (0, import_address.addressify)(to).toB256(),
2193
- assetId: assetId ?? this.baseAssetId
2196
+ assetId
2194
2197
  });
2195
2198
  }
2196
2199
  }
@@ -2241,12 +2244,6 @@ var BaseTransactionRequest = class {
2241
2244
  * @param quantities - CoinQuantity Array.
2242
2245
  */
2243
2246
  fundWithFakeUtxos(quantities, resourcesOwner) {
2244
- let idCounter = 0;
2245
- const generateId = () => {
2246
- const counterString = String(idCounter++);
2247
- const id = import_configs6.ZeroBytes32.slice(0, -counterString.length).concat(counterString);
2248
- return id;
2249
- };
2250
2247
  const findAssetInput = (assetId) => this.inputs.find((input) => {
2251
2248
  if ("assetId" in input) {
2252
2249
  return input.assetId === assetId;
@@ -2256,12 +2253,12 @@ var BaseTransactionRequest = class {
2256
2253
  const updateAssetInput = (assetId, quantity) => {
2257
2254
  const assetInput = findAssetInput(assetId);
2258
2255
  if (assetInput && "assetId" in assetInput) {
2259
- assetInput.id = generateId();
2256
+ assetInput.id = (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN));
2260
2257
  assetInput.amount = quantity;
2261
2258
  } else {
2262
2259
  this.addResources([
2263
2260
  {
2264
- id: generateId(),
2261
+ id: (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN)),
2265
2262
  amount: quantity,
2266
2263
  assetId,
2267
2264
  owner: resourcesOwner || import_address.Address.fromRandom(),
@@ -2272,7 +2269,7 @@ var BaseTransactionRequest = class {
2272
2269
  ]);
2273
2270
  }
2274
2271
  };
2275
- updateAssetInput(this.baseAssetId, (0, import_math7.bn)(1e11));
2272
+ updateAssetInput(import_configs7.BaseAssetId, (0, import_math7.bn)(1e11));
2276
2273
  quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
2277
2274
  }
2278
2275
  /**
@@ -2322,13 +2319,13 @@ var BaseTransactionRequest = class {
2322
2319
  };
2323
2320
 
2324
2321
  // src/providers/transaction-request/create-transaction-request.ts
2325
- var import_configs8 = require("@fuel-ts/address/configs");
2322
+ var import_configs9 = require("@fuel-ts/address/configs");
2326
2323
  var import_math9 = require("@fuel-ts/math");
2327
2324
  var import_transactions8 = require("@fuel-ts/transactions");
2328
2325
  var import_utils13 = require("@fuel-ts/utils");
2329
2326
 
2330
2327
  // src/providers/transaction-request/hash-transaction.ts
2331
- var import_configs7 = require("@fuel-ts/address/configs");
2328
+ var import_configs8 = require("@fuel-ts/address/configs");
2332
2329
  var import_hasher = require("@fuel-ts/hasher");
2333
2330
  var import_math8 = require("@fuel-ts/math");
2334
2331
  var import_transactions7 = require("@fuel-ts/transactions");
@@ -2337,7 +2334,7 @@ var import_ramda2 = require("ramda");
2337
2334
  function hashTransaction(transactionRequest, chainId) {
2338
2335
  const transaction = transactionRequest.toTransaction();
2339
2336
  if (transaction.type === import_transactions7.TransactionType.Script) {
2340
- transaction.receiptsRoot = import_configs7.ZeroBytes32;
2337
+ transaction.receiptsRoot = import_configs8.ZeroBytes32;
2341
2338
  }
2342
2339
  transaction.inputs = transaction.inputs.map((input) => {
2343
2340
  const inputClone = (0, import_ramda2.clone)(input);
@@ -2359,10 +2356,10 @@ function hashTransaction(transactionRequest, chainId) {
2359
2356
  blockHeight: 0,
2360
2357
  txIndex: 0
2361
2358
  };
2362
- inputClone.txID = import_configs7.ZeroBytes32;
2359
+ inputClone.txID = import_configs8.ZeroBytes32;
2363
2360
  inputClone.outputIndex = 0;
2364
- inputClone.balanceRoot = import_configs7.ZeroBytes32;
2365
- inputClone.stateRoot = import_configs7.ZeroBytes32;
2361
+ inputClone.balanceRoot = import_configs8.ZeroBytes32;
2362
+ inputClone.stateRoot = import_configs8.ZeroBytes32;
2366
2363
  return inputClone;
2367
2364
  }
2368
2365
  default:
@@ -2373,8 +2370,8 @@ function hashTransaction(transactionRequest, chainId) {
2373
2370
  const outputClone = (0, import_ramda2.clone)(output);
2374
2371
  switch (outputClone.type) {
2375
2372
  case import_transactions7.OutputType.Contract: {
2376
- outputClone.balanceRoot = import_configs7.ZeroBytes32;
2377
- outputClone.stateRoot = import_configs7.ZeroBytes32;
2373
+ outputClone.balanceRoot = import_configs8.ZeroBytes32;
2374
+ outputClone.stateRoot = import_configs8.ZeroBytes32;
2378
2375
  return outputClone;
2379
2376
  }
2380
2377
  case import_transactions7.OutputType.Change: {
@@ -2382,9 +2379,9 @@ function hashTransaction(transactionRequest, chainId) {
2382
2379
  return outputClone;
2383
2380
  }
2384
2381
  case import_transactions7.OutputType.Variable: {
2385
- outputClone.to = import_configs7.ZeroBytes32;
2382
+ outputClone.to = import_configs8.ZeroBytes32;
2386
2383
  outputClone.amount = (0, import_math8.bn)(0);
2387
- outputClone.assetId = import_configs7.ZeroBytes32;
2384
+ outputClone.assetId = import_configs8.ZeroBytes32;
2388
2385
  return outputClone;
2389
2386
  }
2390
2387
  default:
@@ -2442,10 +2439,15 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2442
2439
  *
2443
2440
  * @param createTransactionRequestLike - The initial values for the instance
2444
2441
  */
2445
- constructor({ bytecodeWitnessIndex, salt, storageSlots, ...rest }) {
2442
+ constructor({
2443
+ bytecodeWitnessIndex,
2444
+ salt,
2445
+ storageSlots,
2446
+ ...rest
2447
+ } = {}) {
2446
2448
  super(rest);
2447
2449
  this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
2448
- this.salt = (0, import_utils13.hexlify)(salt ?? import_configs8.ZeroBytes32);
2450
+ this.salt = (0, import_utils13.hexlify)(salt ?? import_configs9.ZeroBytes32);
2449
2451
  this.storageSlots = [...storageSlots ?? []];
2450
2452
  }
2451
2453
  /**
@@ -2463,7 +2465,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2463
2465
  bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
2464
2466
  bytecodeWitnessIndex,
2465
2467
  storageSlotsCount: storageSlots.length,
2466
- salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs8.ZeroBytes32,
2468
+ salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs9.ZeroBytes32,
2467
2469
  storageSlots
2468
2470
  };
2469
2471
  }
@@ -2511,9 +2513,9 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2511
2513
  };
2512
2514
 
2513
2515
  // src/providers/transaction-request/script-transaction-request.ts
2514
- var import_abi_coder = require("@fuel-ts/abi-coder");
2516
+ var import_abi_coder3 = require("@fuel-ts/abi-coder");
2515
2517
  var import_address2 = require("@fuel-ts/address");
2516
- var import_configs9 = require("@fuel-ts/address/configs");
2518
+ var import_configs10 = require("@fuel-ts/address/configs");
2517
2519
  var import_math10 = require("@fuel-ts/math");
2518
2520
  var import_transactions9 = require("@fuel-ts/transactions");
2519
2521
  var import_utils15 = require("@fuel-ts/utils");
@@ -2566,7 +2568,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2566
2568
  *
2567
2569
  * @param scriptTransactionRequestLike - The initial values for the instance.
2568
2570
  */
2569
- constructor({ script, scriptData, gasLimit, ...rest }) {
2571
+ constructor({ script, scriptData, gasLimit, ...rest } = {}) {
2570
2572
  super(rest);
2571
2573
  this.gasLimit = (0, import_math10.bn)(gasLimit);
2572
2574
  this.script = (0, import_utils15.arrayify)(script ?? returnZeroScript.bytes);
@@ -2587,7 +2589,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2587
2589
  ...super.getBaseTransaction(),
2588
2590
  scriptLength: script.length,
2589
2591
  scriptDataLength: scriptData.length,
2590
- receiptsRoot: import_configs9.ZeroBytes32,
2592
+ receiptsRoot: import_configs10.ZeroBytes32,
2591
2593
  script: (0, import_utils15.hexlify)(script),
2592
2594
  scriptData: (0, import_utils15.hexlify)(scriptData)
2593
2595
  };
@@ -2703,7 +2705,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2703
2705
  * @returns The current instance of the `ScriptTransactionRequest`.
2704
2706
  */
2705
2707
  setData(abi, args) {
2706
- const abiInterface = new import_abi_coder.Interface(abi);
2708
+ const abiInterface = new import_abi_coder3.Interface(abi);
2707
2709
  this.scriptData = abiInterface.functions.main.encodeArguments(args);
2708
2710
  return this;
2709
2711
  }
@@ -2819,23 +2821,23 @@ var calculateTransactionFee = (params) => {
2819
2821
  };
2820
2822
 
2821
2823
  // src/providers/transaction-summary/operations.ts
2822
- var import_configs10 = require("@fuel-ts/address/configs");
2824
+ var import_configs11 = require("@fuel-ts/address/configs");
2823
2825
  var import_errors11 = require("@fuel-ts/errors");
2824
2826
  var import_math13 = require("@fuel-ts/math");
2825
2827
  var import_transactions14 = require("@fuel-ts/transactions");
2826
2828
 
2827
2829
  // src/providers/transaction-summary/call.ts
2828
- var import_abi_coder2 = require("@fuel-ts/abi-coder");
2830
+ var import_abi_coder4 = require("@fuel-ts/abi-coder");
2829
2831
  var import_math12 = require("@fuel-ts/math");
2830
2832
  var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
2831
- const abiInterface = new import_abi_coder2.Interface(abi);
2833
+ const abiInterface = new import_abi_coder4.Interface(abi);
2832
2834
  const callFunctionSelector = receipt.param1.toHex(8);
2833
2835
  const functionFragment = abiInterface.getFunction(callFunctionSelector);
2834
2836
  const inputs = functionFragment.jsonFn.inputs;
2835
2837
  let encodedArgs;
2836
2838
  if (functionFragment.isInputDataPointer) {
2837
2839
  if (rawPayload) {
2838
- const argsOffset = (0, import_math12.bn)(receipt.param2).sub((0, import_abi_coder2.calculateVmTxMemory)({ maxInputs: maxInputs.toNumber() })).toNumber();
2840
+ const argsOffset = (0, import_math12.bn)(receipt.param2).sub((0, import_abi_coder4.calculateVmTxMemory)({ maxInputs: maxInputs.toNumber() })).toNumber();
2839
2841
  encodedArgs = `0x${rawPayload.slice(2).slice(argsOffset * 2)}`;
2840
2842
  }
2841
2843
  } else {
@@ -3164,7 +3166,7 @@ function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutp
3164
3166
  const { to: toAddress, assetId, amount } = receipt;
3165
3167
  let { from: fromAddress } = receipt;
3166
3168
  const toType = contractInputs.some((input) => input.contractID === toAddress) ? 0 /* contract */ : 1 /* account */;
3167
- if (import_configs10.ZeroBytes32 === fromAddress) {
3169
+ if (import_configs11.ZeroBytes32 === fromAddress) {
3168
3170
  const change = changeOutputs.find((output) => output.assetId === assetId);
3169
3171
  fromAddress = change?.to || fromAddress;
3170
3172
  }
@@ -3485,13 +3487,13 @@ function assembleTransactionSummary(params) {
3485
3487
  }
3486
3488
 
3487
3489
  // src/providers/transaction-response/getDecodedLogs.ts
3488
- var import_abi_coder3 = require("@fuel-ts/abi-coder");
3490
+ var import_abi_coder5 = require("@fuel-ts/abi-coder");
3489
3491
  var import_transactions16 = require("@fuel-ts/transactions");
3490
3492
  function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
3491
3493
  return receipts.reduce((logs, receipt) => {
3492
3494
  if (receipt.type === import_transactions16.ReceiptType.LogData || receipt.type === import_transactions16.ReceiptType.Log) {
3493
- const interfaceToUse = new import_abi_coder3.Interface(externalAbis[receipt.id] || mainAbi);
3494
- const data = receipt.type === import_transactions16.ReceiptType.Log ? new import_abi_coder3.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
3495
+ const interfaceToUse = new import_abi_coder5.Interface(externalAbis[receipt.id] || mainAbi);
3496
+ const data = receipt.type === import_transactions16.ReceiptType.Log ? new import_abi_coder5.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
3495
3497
  const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
3496
3498
  logs.push(decodedLog);
3497
3499
  }
@@ -3741,7 +3743,6 @@ var processGqlChain = (chain) => {
3741
3743
  gasPerByte: (0, import_math15.bn)(feeParams.gasPerByte),
3742
3744
  maxMessageDataLength: (0, import_math15.bn)(predicateParams.maxMessageDataLength),
3743
3745
  chainId: (0, import_math15.bn)(consensusParameters.chainId),
3744
- baseAssetId: consensusParameters.baseAssetId,
3745
3746
  gasCosts
3746
3747
  },
3747
3748
  gasCosts,
@@ -3984,17 +3985,6 @@ var _Provider = class {
3984
3985
  } = this.getChain();
3985
3986
  return chainId.toNumber();
3986
3987
  }
3987
- /**
3988
- * Returns the base asset ID
3989
- *
3990
- * @returns A promise that resolves to the base asset ID
3991
- */
3992
- getBaseAssetId() {
3993
- const {
3994
- consensusParameters: { baseAssetId }
3995
- } = this.getChain();
3996
- return baseAssetId;
3997
- }
3998
3988
  /**
3999
3989
  * Submits a transaction to the chain to be executed.
4000
3990
  *
@@ -4145,6 +4135,36 @@ var _Provider = class {
4145
4135
  missingContractIds
4146
4136
  };
4147
4137
  }
4138
+ /**
4139
+ * Estimates the transaction gas and fee based on the provided transaction request.
4140
+ * @param transactionRequest - The transaction request object.
4141
+ * @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
4142
+ */
4143
+ estimateTxGasAndFee(params) {
4144
+ const { transactionRequest } = params;
4145
+ const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
4146
+ const chainInfo = this.getChain();
4147
+ const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
4148
+ transactionRequest.gasPrice = gasPrice;
4149
+ const minGas = transactionRequest.calculateMinGas(chainInfo);
4150
+ const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
4151
+ if (transactionRequest.type === import_transactions18.TransactionType.Script) {
4152
+ if (transactionRequest.gasLimit.eq(0)) {
4153
+ transactionRequest.gasLimit = minGas;
4154
+ transactionRequest.gasLimit = maxGasPerTx.sub(
4155
+ transactionRequest.calculateMaxGas(chainInfo, minGas)
4156
+ );
4157
+ }
4158
+ }
4159
+ const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
4160
+ const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
4161
+ return {
4162
+ minGas,
4163
+ minFee,
4164
+ maxGas,
4165
+ maxFee
4166
+ };
4167
+ }
4148
4168
  /**
4149
4169
  * Executes a signed transaction without applying the states changes
4150
4170
  * on the chain.
@@ -4192,17 +4212,16 @@ var _Provider = class {
4192
4212
  signatureCallback
4193
4213
  } = {}) {
4194
4214
  const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
4195
- const chainInfo = this.getChain();
4196
- const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
4197
- const gasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
4215
+ const { minGasPrice } = this.getGasConfig();
4216
+ const setGasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
4198
4217
  const isScriptTransaction = txRequestClone.type === import_transactions18.TransactionType.Script;
4199
4218
  const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
4200
4219
  const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
4201
4220
  txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
4221
+ if (isScriptTransaction) {
4222
+ txRequestClone.gasLimit = (0, import_math15.bn)(0);
4223
+ }
4202
4224
  if (estimatePredicates) {
4203
- if (isScriptTransaction) {
4204
- txRequestClone.gasLimit = (0, import_math15.bn)(0);
4205
- }
4206
4225
  if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
4207
4226
  resourcesOwner.populateTransactionPredicateData(txRequestClone);
4208
4227
  }
@@ -4211,36 +4230,34 @@ var _Provider = class {
4211
4230
  if (signatureCallback && isScriptTransaction) {
4212
4231
  await signatureCallback(txRequestClone);
4213
4232
  }
4214
- const minGas = txRequestClone.calculateMinGas(chainInfo);
4215
- const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
4233
+ let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
4234
+ transactionRequest: txRequestClone
4235
+ });
4216
4236
  let receipts = [];
4217
4237
  let missingContractIds = [];
4218
4238
  let outputVariables = 0;
4239
+ let gasUsed = (0, import_math15.bn)(0);
4219
4240
  if (isScriptTransaction && estimateTxDependencies) {
4220
4241
  txRequestClone.gasPrice = (0, import_math15.bn)(0);
4221
- txRequestClone.gasLimit = (0, import_math15.bn)(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
4222
4242
  const result = await this.estimateTxDependencies(txRequestClone);
4223
4243
  receipts = result.receipts;
4224
4244
  outputVariables = result.outputVariables;
4225
4245
  missingContractIds = result.missingContractIds;
4246
+ gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
4247
+ txRequestClone.gasLimit = gasUsed;
4248
+ txRequestClone.gasPrice = setGasPrice;
4249
+ ({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
4250
+ transactionRequest: txRequestClone
4251
+ }));
4226
4252
  }
4227
- const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
4228
- const usedFee = calculatePriceWithFactor(
4229
- gasUsed,
4230
- gasPrice,
4231
- gasPriceFactor
4232
- ).normalizeZeroToOne();
4233
- const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
4234
- const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
4235
4253
  return {
4236
4254
  requiredQuantities: allQuantities,
4237
4255
  receipts,
4238
4256
  gasUsed,
4239
4257
  minGasPrice,
4240
- gasPrice,
4258
+ gasPrice: setGasPrice,
4241
4259
  minGas,
4242
4260
  maxGas,
4243
- usedFee,
4244
4261
  minFee,
4245
4262
  maxFee,
4246
4263
  estimatedInputs: txRequestClone.inputs,
@@ -4873,13 +4890,13 @@ var assets = [
4873
4890
  ];
4874
4891
 
4875
4892
  // src/utils/formatTransferToContractScriptData.ts
4876
- var import_abi_coder4 = require("@fuel-ts/abi-coder");
4893
+ var import_abi_coder6 = require("@fuel-ts/abi-coder");
4877
4894
  var import_math17 = require("@fuel-ts/math");
4878
4895
  var import_utils27 = require("@fuel-ts/utils");
4879
4896
  var asm = __toESM(require("@fuels/vm-asm"));
4880
4897
  var formatTransferToContractScriptData = (params) => {
4881
4898
  const { assetId, amountToTransfer, hexlifiedContractId } = params;
4882
- const numberCoder = new import_abi_coder4.BigNumberCoder("u64");
4899
+ const numberCoder = new import_abi_coder6.BigNumberCoder("u64");
4883
4900
  const encoded = numberCoder.encode(new import_math17.BN(amountToTransfer).toNumber());
4884
4901
  const scriptData = Uint8Array.from([
4885
4902
  ...(0, import_utils27.arrayify)(hexlifiedContractId),
@@ -5031,9 +5048,8 @@ var Account = class extends import_interfaces.AbstractAccount {
5031
5048
  * @param assetId - The asset ID to check the balance for.
5032
5049
  * @returns A promise that resolves to the balance amount.
5033
5050
  */
5034
- async getBalance(assetId) {
5035
- const assetIdToFetch = assetId ?? this.provider.getBaseAssetId();
5036
- const amount = await this.provider.getBalance(this.address, assetIdToFetch);
5051
+ async getBalance(assetId = import_configs12.BaseAssetId) {
5052
+ const amount = await this.provider.getBalance(this.address, assetId);
5037
5053
  return amount;
5038
5054
  }
5039
5055
  /**
@@ -5071,10 +5087,9 @@ var Account = class extends import_interfaces.AbstractAccount {
5071
5087
  * @returns A promise that resolves when the resources are added to the transaction.
5072
5088
  */
5073
5089
  async fund(request, coinQuantities, fee) {
5074
- const baseAssetId = this.provider.getBaseAssetId();
5075
5090
  const updatedQuantities = addAmountToAsset({
5076
5091
  amount: (0, import_math18.bn)(fee),
5077
- assetId: baseAssetId,
5092
+ assetId: import_configs12.BaseAssetId,
5078
5093
  coinQuantities
5079
5094
  });
5080
5095
  const quantitiesDict = {};
@@ -5098,8 +5113,8 @@ var Account = class extends import_interfaces.AbstractAccount {
5098
5113
  quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
5099
5114
  cachedUtxos.push(input.id);
5100
5115
  }
5101
- } else if (input.recipient === owner && input.amount && quantitiesDict[baseAssetId]) {
5102
- quantitiesDict[baseAssetId].owned = quantitiesDict[baseAssetId].owned.add(input.amount);
5116
+ } else if (input.recipient === owner && input.amount && quantitiesDict[import_configs12.BaseAssetId]) {
5117
+ quantitiesDict[import_configs12.BaseAssetId].owned = quantitiesDict[import_configs12.BaseAssetId].owned.add(input.amount);
5103
5118
  cachedMessages.push(input.nonce);
5104
5119
  }
5105
5120
  }
@@ -5131,13 +5146,11 @@ var Account = class extends import_interfaces.AbstractAccount {
5131
5146
  * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
5132
5147
  * @returns A promise that resolves to the prepared transaction request.
5133
5148
  */
5134
- async createTransfer(destination, amount, assetId, txParams = {}) {
5149
+ async createTransfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
5135
5150
  const { minGasPrice } = this.provider.getGasConfig();
5136
- const baseAssetId = this.provider.getBaseAssetId();
5137
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
5138
- const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
5151
+ const params = { gasPrice: minGasPrice, ...txParams };
5139
5152
  const request = new ScriptTransactionRequest(params);
5140
- request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetIdToTransfer);
5153
+ request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetId);
5141
5154
  const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
5142
5155
  estimateTxDependencies: true,
5143
5156
  resourcesOwner: this
@@ -5163,15 +5176,14 @@ var Account = class extends import_interfaces.AbstractAccount {
5163
5176
  * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
5164
5177
  * @returns A promise that resolves to the transaction response.
5165
5178
  */
5166
- async transfer(destination, amount, assetId, txParams = {}) {
5179
+ async transfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
5167
5180
  if ((0, import_math18.bn)(amount).lte(0)) {
5168
5181
  throw new import_errors16.FuelError(
5169
5182
  import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
5170
5183
  "Transfer amount must be a positive number."
5171
5184
  );
5172
5185
  }
5173
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
5174
- const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
5186
+ const request = await this.createTransfer(destination, amount, assetId, txParams);
5175
5187
  return this.sendTransaction(request, { estimateTxDependencies: false });
5176
5188
  }
5177
5189
  /**
@@ -5183,7 +5195,7 @@ var Account = class extends import_interfaces.AbstractAccount {
5183
5195
  * @param txParams - The optional transaction parameters.
5184
5196
  * @returns A promise that resolves to the transaction response.
5185
5197
  */
5186
- async transferToContract(contractId, amount, assetId, txParams = {}) {
5198
+ async transferToContract(contractId, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
5187
5199
  if ((0, import_math18.bn)(amount).lte(0)) {
5188
5200
  throw new import_errors16.FuelError(
5189
5201
  import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
@@ -5192,13 +5204,11 @@ var Account = class extends import_interfaces.AbstractAccount {
5192
5204
  }
5193
5205
  const contractAddress = import_address4.Address.fromAddressOrString(contractId);
5194
5206
  const { minGasPrice } = this.provider.getGasConfig();
5195
- const baseAssetId = this.provider.getBaseAssetId();
5196
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
5197
- const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
5207
+ const params = { gasPrice: minGasPrice, ...txParams };
5198
5208
  const { script, scriptData } = await assembleTransferToContractScript({
5199
5209
  hexlifiedContractId: contractAddress.toB256(),
5200
5210
  amountToTransfer: (0, import_math18.bn)(amount),
5201
- assetId: assetIdToTransfer
5211
+ assetId
5202
5212
  });
5203
5213
  const request = new ScriptTransactionRequest({
5204
5214
  ...params,
@@ -5208,7 +5218,7 @@ var Account = class extends import_interfaces.AbstractAccount {
5208
5218
  request.addContractInputAndOutput(contractAddress);
5209
5219
  const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
5210
5220
  request,
5211
- [{ amount: (0, import_math18.bn)(amount), assetId: String(assetIdToTransfer) }]
5221
+ [{ amount: (0, import_math18.bn)(amount), assetId: String(assetId) }]
5212
5222
  );
5213
5223
  request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
5214
5224
  this.validateGas({
@@ -5230,7 +5240,6 @@ var Account = class extends import_interfaces.AbstractAccount {
5230
5240
  */
5231
5241
  async withdrawToBaseLayer(recipient, amount, txParams = {}) {
5232
5242
  const { minGasPrice } = this.provider.getGasConfig();
5233
- const baseAssetId = this.provider.getBaseAssetId();
5234
5243
  const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
5235
5244
  const recipientDataArray = (0, import_utils28.arrayify)(
5236
5245
  "0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
@@ -5243,14 +5252,9 @@ var Account = class extends import_interfaces.AbstractAccount {
5243
5252
  ...recipientDataArray,
5244
5253
  ...amountDataArray
5245
5254
  ]);
5246
- const params = {
5247
- script,
5248
- gasPrice: minGasPrice,
5249
- baseAssetId,
5250
- ...txParams
5251
- };
5255
+ const params = { script, gasPrice: minGasPrice, ...txParams };
5252
5256
  const request = new ScriptTransactionRequest(params);
5253
- const forwardingQuantities = [{ amount: (0, import_math18.bn)(amount), assetId: baseAssetId }];
5257
+ const forwardingQuantities = [{ amount: (0, import_math18.bn)(amount), assetId: import_configs12.BaseAssetId }];
5254
5258
  const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
5255
5259
  request,
5256
5260
  forwardingQuantities
@@ -5347,7 +5351,7 @@ var import_utils31 = require("@fuel-ts/utils");
5347
5351
 
5348
5352
  // src/signer/signer.ts
5349
5353
  var import_address5 = require("@fuel-ts/address");
5350
- var import_crypto = require("@fuel-ts/crypto");
5354
+ var import_crypto2 = require("@fuel-ts/crypto");
5351
5355
  var import_hasher2 = require("@fuel-ts/hasher");
5352
5356
  var import_math19 = require("@fuel-ts/math");
5353
5357
  var import_utils29 = require("@fuel-ts/utils");
@@ -5440,7 +5444,7 @@ var Signer = class {
5440
5444
  * @returns random 32-byte hashed
5441
5445
  */
5442
5446
  static generatePrivateKey(entropy) {
5443
- 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);
5447
+ 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);
5444
5448
  }
5445
5449
  /**
5446
5450
  * Extended publicKey from a compact publicKey
@@ -5456,7 +5460,7 @@ var Signer = class {
5456
5460
 
5457
5461
  // src/wallet/keystore-wallet.ts
5458
5462
  var import_address6 = require("@fuel-ts/address");
5459
- var import_crypto2 = require("@fuel-ts/crypto");
5463
+ var import_crypto3 = require("@fuel-ts/crypto");
5460
5464
  var import_errors17 = require("@fuel-ts/errors");
5461
5465
  var import_utils30 = require("@fuel-ts/utils");
5462
5466
  var import_uuid = require("uuid");
@@ -5472,22 +5476,22 @@ var removeHexPrefix = (hexString) => {
5472
5476
  return hexString;
5473
5477
  };
5474
5478
  async function encryptKeystoreWallet(privateKey, address, password) {
5475
- const privateKeyBuffer = (0, import_crypto2.bufferFromString)(removeHexPrefix(privateKey), "hex");
5479
+ const privateKeyBuffer = (0, import_crypto3.bufferFromString)(removeHexPrefix(privateKey), "hex");
5476
5480
  const ownerAddress = import_address6.Address.fromAddressOrString(address);
5477
- const salt = (0, import_crypto2.randomBytes)(DEFAULT_KEY_SIZE);
5478
- const key = (0, import_crypto2.scrypt)({
5479
- password: (0, import_crypto2.bufferFromString)(password),
5481
+ const salt = (0, import_crypto3.randomBytes)(DEFAULT_KEY_SIZE);
5482
+ const key = (0, import_crypto3.scrypt)({
5483
+ password: (0, import_crypto3.bufferFromString)(password),
5480
5484
  salt,
5481
5485
  dklen: DEFAULT_KEY_SIZE,
5482
5486
  n: 2 ** DEFAULT_KDF_PARAMS_LOG_N,
5483
5487
  r: DEFAULT_KDF_PARAMS_R,
5484
5488
  p: DEFAULT_KDF_PARAMS_P
5485
5489
  });
5486
- const iv = (0, import_crypto2.randomBytes)(DEFAULT_IV_SIZE);
5487
- const ciphertext = await (0, import_crypto2.encryptJsonWalletData)(privateKeyBuffer, key, iv);
5490
+ const iv = (0, import_crypto3.randomBytes)(DEFAULT_IV_SIZE);
5491
+ const ciphertext = await (0, import_crypto3.encryptJsonWalletData)(privateKeyBuffer, key, iv);
5488
5492
  const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertext]);
5489
- const macHashUint8Array = (0, import_crypto2.keccak256)(data);
5490
- const mac = (0, import_crypto2.stringFromBuffer)(macHashUint8Array, "hex");
5493
+ const macHashUint8Array = (0, import_crypto3.keccak256)(data);
5494
+ const mac = (0, import_crypto3.stringFromBuffer)(macHashUint8Array, "hex");
5491
5495
  const keystore = {
5492
5496
  id: (0, import_uuid.v4)(),
5493
5497
  version: 3,
@@ -5495,15 +5499,15 @@ async function encryptKeystoreWallet(privateKey, address, password) {
5495
5499
  crypto: {
5496
5500
  cipher: "aes-128-ctr",
5497
5501
  mac,
5498
- cipherparams: { iv: (0, import_crypto2.stringFromBuffer)(iv, "hex") },
5499
- ciphertext: (0, import_crypto2.stringFromBuffer)(ciphertext, "hex"),
5502
+ cipherparams: { iv: (0, import_crypto3.stringFromBuffer)(iv, "hex") },
5503
+ ciphertext: (0, import_crypto3.stringFromBuffer)(ciphertext, "hex"),
5500
5504
  kdf: "scrypt",
5501
5505
  kdfparams: {
5502
5506
  dklen: DEFAULT_KEY_SIZE,
5503
5507
  n: 2 ** DEFAULT_KDF_PARAMS_LOG_N,
5504
5508
  p: DEFAULT_KDF_PARAMS_P,
5505
5509
  r: DEFAULT_KDF_PARAMS_R,
5506
- salt: (0, import_crypto2.stringFromBuffer)(salt, "hex")
5510
+ salt: (0, import_crypto3.stringFromBuffer)(salt, "hex")
5507
5511
  }
5508
5512
  }
5509
5513
  };
@@ -5519,11 +5523,11 @@ async function decryptKeystoreWallet(jsonWallet, password) {
5519
5523
  kdfparams: { dklen, n, r, p, salt }
5520
5524
  }
5521
5525
  } = keystoreWallet;
5522
- const ciphertextBuffer = (0, import_crypto2.bufferFromString)(ciphertext, "hex");
5523
- const ivBuffer = (0, import_crypto2.bufferFromString)(iv, "hex");
5524
- const saltBuffer = (0, import_crypto2.bufferFromString)(salt, "hex");
5525
- const passwordBuffer = (0, import_crypto2.bufferFromString)(password);
5526
- const key = (0, import_crypto2.scrypt)({
5526
+ const ciphertextBuffer = (0, import_crypto3.bufferFromString)(ciphertext, "hex");
5527
+ const ivBuffer = (0, import_crypto3.bufferFromString)(iv, "hex");
5528
+ const saltBuffer = (0, import_crypto3.bufferFromString)(salt, "hex");
5529
+ const passwordBuffer = (0, import_crypto3.bufferFromString)(password);
5530
+ const key = (0, import_crypto3.scrypt)({
5527
5531
  password: passwordBuffer,
5528
5532
  salt: saltBuffer,
5529
5533
  n,
@@ -5532,15 +5536,15 @@ async function decryptKeystoreWallet(jsonWallet, password) {
5532
5536
  dklen
5533
5537
  });
5534
5538
  const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertextBuffer]);
5535
- const macHashUint8Array = (0, import_crypto2.keccak256)(data);
5536
- const macHash = (0, import_crypto2.stringFromBuffer)(macHashUint8Array, "hex");
5539
+ const macHashUint8Array = (0, import_crypto3.keccak256)(data);
5540
+ const macHash = (0, import_crypto3.stringFromBuffer)(macHashUint8Array, "hex");
5537
5541
  if (mac !== macHash) {
5538
5542
  throw new import_errors17.FuelError(
5539
5543
  import_errors17.ErrorCode.INVALID_PASSWORD,
5540
5544
  "Failed to decrypt the keystore wallet, the provided password is incorrect."
5541
5545
  );
5542
5546
  }
5543
- const buffer = await (0, import_crypto2.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
5547
+ const buffer = await (0, import_crypto3.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
5544
5548
  const privateKey = (0, import_utils30.hexlify)(buffer);
5545
5549
  return privateKey;
5546
5550
  }
@@ -5665,7 +5669,7 @@ var import_utils35 = require("@fuel-ts/utils");
5665
5669
  var import_ethers3 = require("ethers");
5666
5670
 
5667
5671
  // src/mnemonic/mnemonic.ts
5668
- var import_crypto3 = require("@fuel-ts/crypto");
5672
+ var import_crypto4 = require("@fuel-ts/crypto");
5669
5673
  var import_errors19 = require("@fuel-ts/errors");
5670
5674
  var import_hasher5 = require("@fuel-ts/hasher");
5671
5675
  var import_utils33 = require("@fuel-ts/utils");
@@ -8026,7 +8030,7 @@ var Mnemonic = class {
8026
8030
  * @returns A randomly generated mnemonic
8027
8031
  */
8028
8032
  static generate(size = 32, extraEntropy = "") {
8029
- 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);
8033
+ 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);
8030
8034
  return Mnemonic.entropyToMnemonic(entropy);
8031
8035
  }
8032
8036
  };
@@ -8398,7 +8402,7 @@ __publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
8398
8402
 
8399
8403
  // src/wallet-manager/wallet-manager.ts
8400
8404
  var import_address9 = require("@fuel-ts/address");
8401
- var import_crypto4 = require("@fuel-ts/crypto");
8405
+ var import_crypto5 = require("@fuel-ts/crypto");
8402
8406
  var import_errors23 = require("@fuel-ts/errors");
8403
8407
  var import_events = require("events");
8404
8408
 
@@ -8726,7 +8730,7 @@ var _WalletManager = class extends import_events.EventEmitter {
8726
8730
  await assert(!__privateGet(this, _isLocked), ERROR_MESSAGES.wallet_not_unlocked);
8727
8731
  const data = await this.storage.getItem(this.STORAGE_KEY);
8728
8732
  if (data) {
8729
- const state = await (0, import_crypto4.decrypt)(__privateGet(this, _passphrase), JSON.parse(data));
8733
+ const state = await (0, import_crypto5.decrypt)(__privateGet(this, _passphrase), JSON.parse(data));
8730
8734
  __privateSet(this, _vaults, __privateMethod(this, _deserializeVaults, deserializeVaults_fn).call(this, state.vaults));
8731
8735
  }
8732
8736
  }
@@ -8735,7 +8739,7 @@ var _WalletManager = class extends import_events.EventEmitter {
8735
8739
  */
8736
8740
  async saveState() {
8737
8741
  await assert(!__privateGet(this, _isLocked), ERROR_MESSAGES.wallet_not_unlocked);
8738
- const encryptedData = await (0, import_crypto4.encrypt)(__privateGet(this, _passphrase), {
8742
+ const encryptedData = await (0, import_crypto5.encrypt)(__privateGet(this, _passphrase), {
8739
8743
  vaults: __privateMethod(this, _serializeVaults, serializeVaults_fn).call(this, __privateGet(this, _vaults))
8740
8744
  });
8741
8745
  await this.storage.setItem(this.STORAGE_KEY, JSON.stringify(encryptedData));
@@ -8811,8 +8815,9 @@ var StorageAbstract = class {
8811
8815
  };
8812
8816
 
8813
8817
  // src/predicate/predicate.ts
8814
- var import_abi_coder5 = require("@fuel-ts/abi-coder");
8818
+ var import_abi_coder7 = require("@fuel-ts/abi-coder");
8815
8819
  var import_address10 = require("@fuel-ts/address");
8820
+ var import_configs13 = require("@fuel-ts/address/configs");
8816
8821
  var import_errors25 = require("@fuel-ts/errors");
8817
8822
  var import_transactions20 = require("@fuel-ts/transactions");
8818
8823
  var import_utils37 = require("@fuel-ts/utils");
@@ -8890,9 +8895,8 @@ var Predicate = class extends Account {
8890
8895
  * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
8891
8896
  * @returns A promise that resolves to the prepared transaction request.
8892
8897
  */
8893
- async createTransfer(destination, amount, assetId, txParams = {}) {
8894
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
8895
- const request = await super.createTransfer(destination, amount, assetIdToTransfer, txParams);
8898
+ async createTransfer(destination, amount, assetId = import_configs13.BaseAssetId, txParams = {}) {
8899
+ const request = await super.createTransfer(destination, amount, assetId, txParams);
8896
8900
  return this.populateTransactionPredicateData(request);
8897
8901
  }
8898
8902
  /**
@@ -8921,10 +8925,10 @@ var Predicate = class extends Account {
8921
8925
  }
8922
8926
  const mainFn = this.interface?.functions.main;
8923
8927
  const paddedCode = new import_transactions20.ByteArrayCoder(this.bytes.length).encode(this.bytes);
8924
- const VM_TX_MEMORY = (0, import_abi_coder5.calculateVmTxMemory)({
8928
+ const VM_TX_MEMORY = (0, import_abi_coder7.calculateVmTxMemory)({
8925
8929
  maxInputs: this.provider.getChain().consensusParameters.maxInputs.toNumber()
8926
8930
  });
8927
- 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;
8931
+ const OFFSET = VM_TX_MEMORY + import_abi_coder7.SCRIPT_FIXED_SIZE + import_abi_coder7.INPUT_COIN_FIXED_SIZE + import_abi_coder7.WORD_SIZE + paddedCode.byteLength + policiesLength * import_abi_coder7.WORD_SIZE;
8928
8932
  return mainFn?.encodeArguments(this.predicateData, OFFSET) || new Uint8Array();
8929
8933
  }
8930
8934
  /**
@@ -8939,7 +8943,7 @@ var Predicate = class extends Account {
8939
8943
  let predicateBytes = (0, import_utils37.arrayify)(bytes);
8940
8944
  let abiInterface;
8941
8945
  if (jsonAbi) {
8942
- abiInterface = new import_abi_coder5.Interface(jsonAbi);
8946
+ abiInterface = new import_abi_coder7.Interface(jsonAbi);
8943
8947
  if (abiInterface.functions.main === void 0) {
8944
8948
  throw new import_errors25.FuelError(
8945
8949
  import_errors25.ErrorCode.ABI_MAIN_METHOD_MISSING,