@fuel-ts/account 0.0.0-rc-1976-20240411153008 → 0.0.0-rc-2037-20240411163513

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

Potentially problematic release.


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

Files changed (33) hide show
  1. package/dist/account.d.ts.map +1 -1
  2. package/dist/index.global.js +120 -131
  3. package/dist/index.global.js.map +1 -1
  4. package/dist/index.js +197 -204
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +125 -132
  7. package/dist/index.mjs.map +1 -1
  8. package/dist/predicate/predicate.d.ts +9 -1
  9. package/dist/predicate/predicate.d.ts.map +1 -1
  10. package/dist/providers/coin-quantity.d.ts +2 -2
  11. package/dist/providers/coin-quantity.d.ts.map +1 -1
  12. package/dist/providers/coin.d.ts +2 -1
  13. package/dist/providers/coin.d.ts.map +1 -1
  14. package/dist/providers/message.d.ts +1 -0
  15. package/dist/providers/message.d.ts.map +1 -1
  16. package/dist/providers/provider.d.ts +13 -9
  17. package/dist/providers/provider.d.ts.map +1 -1
  18. package/dist/providers/transaction-request/create-transaction-request.d.ts +1 -1
  19. package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
  20. package/dist/providers/transaction-request/input.d.ts.map +1 -1
  21. package/dist/providers/transaction-request/script-transaction-request.d.ts +1 -1
  22. package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
  23. package/dist/providers/transaction-request/transaction-request.d.ts +4 -25
  24. package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
  25. package/dist/test-utils/launchNode.d.ts.map +1 -1
  26. package/dist/test-utils/seedTestWallet.d.ts.map +1 -1
  27. package/dist/test-utils.global.js +108 -137
  28. package/dist/test-utils.global.js.map +1 -1
  29. package/dist/test-utils.js +179 -204
  30. package/dist/test-utils.js.map +1 -1
  31. package/dist/test-utils.mjs +112 -137
  32. package/dist/test-utils.mjs.map +1 -1
  33. 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,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
  /**
@@ -2037,8 +2038,8 @@ var BaseTransactionRequest = class {
2037
2038
  * @param predicate - Predicate bytes.
2038
2039
  * @param predicateData - Predicate data bytes.
2039
2040
  */
2040
- addCoinInput(coin, predicate) {
2041
- const { assetId, owner, amount } = coin;
2041
+ addCoinInput(coin) {
2042
+ const { assetId, owner, amount, id, predicate } = coin;
2042
2043
  let witnessIndex;
2043
2044
  if (predicate) {
2044
2045
  witnessIndex = 0;
@@ -2049,14 +2050,14 @@ var BaseTransactionRequest = class {
2049
2050
  }
2050
2051
  }
2051
2052
  const input = {
2052
- ...coin,
2053
+ id,
2053
2054
  type: import_transactions6.InputType.Coin,
2054
2055
  owner: owner.toB256(),
2055
2056
  amount,
2056
2057
  assetId,
2057
2058
  txPointer: "0x00000000000000000000000000000000",
2058
2059
  witnessIndex,
2059
- predicate: predicate?.bytes
2060
+ predicate
2060
2061
  };
2061
2062
  this.pushInput(input);
2062
2063
  this.addChangeOutput(owner, assetId);
@@ -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
- addMessageInput(message, predicate) {
2072
- const { recipient, sender, amount } = message;
2073
+ addMessageInput(message) {
2074
+ const { recipient, sender, amount, predicate, nonce } = message;
2075
+ const assetId = import_configs7.BaseAssetId;
2073
2076
  let witnessIndex;
2074
2077
  if (predicate) {
2075
2078
  witnessIndex = 0;
@@ -2080,16 +2083,16 @@ var BaseTransactionRequest = class {
2080
2083
  }
2081
2084
  }
2082
2085
  const input = {
2083
- ...message,
2086
+ nonce,
2084
2087
  type: import_transactions6.InputType.Message,
2085
2088
  sender: sender.toB256(),
2086
2089
  recipient: recipient.toB256(),
2087
2090
  amount,
2088
2091
  witnessIndex,
2089
- predicate: predicate?.bytes
2092
+ predicate
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
@@ -2117,32 +2120,6 @@ var BaseTransactionRequest = class {
2117
2120
  resources.forEach((resource) => this.addResource(resource));
2118
2121
  return this;
2119
2122
  }
2120
- /**
2121
- * Adds multiple resources to the transaction by adding coin/message inputs and change
2122
- * outputs from the related assetIds.
2123
- *
2124
- * @param resources - The resources to add.
2125
- * @returns This transaction.
2126
- */
2127
- addPredicateResource(resource, predicate) {
2128
- if (isCoin(resource)) {
2129
- this.addCoinInput(resource, predicate);
2130
- } else {
2131
- this.addMessageInput(resource, predicate);
2132
- }
2133
- return this;
2134
- }
2135
- /**
2136
- * Adds multiple predicate coin/message inputs to the transaction and change outputs
2137
- * from the related assetIds.
2138
- *
2139
- * @param resources - The resources to add.
2140
- * @returns This transaction.
2141
- */
2142
- addPredicateResources(resources, predicate) {
2143
- resources.forEach((resource) => this.addPredicateResource(resource, predicate));
2144
- return this;
2145
- }
2146
2123
  /**
2147
2124
  * Adds a coin output to the transaction.
2148
2125
  *
@@ -2150,12 +2127,12 @@ var BaseTransactionRequest = class {
2150
2127
  * @param amount - Amount of coin.
2151
2128
  * @param assetId - Asset ID of coin.
2152
2129
  */
2153
- addCoinOutput(to, amount, assetId) {
2130
+ addCoinOutput(to, amount, assetId = import_configs7.BaseAssetId) {
2154
2131
  this.pushOutput({
2155
2132
  type: import_transactions6.OutputType.Coin,
2156
2133
  to: (0, import_address.addressify)(to).toB256(),
2157
2134
  amount,
2158
- assetId: assetId ?? this.baseAssetId
2135
+ assetId
2159
2136
  });
2160
2137
  return this;
2161
2138
  }
@@ -2182,7 +2159,7 @@ var BaseTransactionRequest = class {
2182
2159
  * @param to - Address of the owner.
2183
2160
  * @param assetId - Asset ID of coin.
2184
2161
  */
2185
- addChangeOutput(to, assetId) {
2162
+ addChangeOutput(to, assetId = import_configs7.BaseAssetId) {
2186
2163
  const changeOutput = this.getChangeOutputs().find(
2187
2164
  (output) => (0, import_utils9.hexlify)(output.assetId) === assetId
2188
2165
  );
@@ -2190,7 +2167,7 @@ var BaseTransactionRequest = class {
2190
2167
  this.pushOutput({
2191
2168
  type: import_transactions6.OutputType.Change,
2192
2169
  to: (0, import_address.addressify)(to).toB256(),
2193
- assetId: assetId ?? this.baseAssetId
2170
+ assetId
2194
2171
  });
2195
2172
  }
2196
2173
  }
@@ -2241,12 +2218,6 @@ var BaseTransactionRequest = class {
2241
2218
  * @param quantities - CoinQuantity Array.
2242
2219
  */
2243
2220
  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
2221
  const findAssetInput = (assetId) => this.inputs.find((input) => {
2251
2222
  if ("assetId" in input) {
2252
2223
  return input.assetId === assetId;
@@ -2256,12 +2227,12 @@ var BaseTransactionRequest = class {
2256
2227
  const updateAssetInput = (assetId, quantity) => {
2257
2228
  const assetInput = findAssetInput(assetId);
2258
2229
  if (assetInput && "assetId" in assetInput) {
2259
- assetInput.id = generateId();
2230
+ assetInput.id = (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN));
2260
2231
  assetInput.amount = quantity;
2261
2232
  } else {
2262
2233
  this.addResources([
2263
2234
  {
2264
- id: generateId(),
2235
+ id: (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN)),
2265
2236
  amount: quantity,
2266
2237
  assetId,
2267
2238
  owner: resourcesOwner || import_address.Address.fromRandom(),
@@ -2272,7 +2243,7 @@ var BaseTransactionRequest = class {
2272
2243
  ]);
2273
2244
  }
2274
2245
  };
2275
- updateAssetInput(this.baseAssetId, (0, import_math7.bn)(1e11));
2246
+ updateAssetInput(import_configs7.BaseAssetId, (0, import_math7.bn)(1e11));
2276
2247
  quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
2277
2248
  }
2278
2249
  /**
@@ -2322,13 +2293,13 @@ var BaseTransactionRequest = class {
2322
2293
  };
2323
2294
 
2324
2295
  // src/providers/transaction-request/create-transaction-request.ts
2325
- var import_configs8 = require("@fuel-ts/address/configs");
2296
+ var import_configs9 = require("@fuel-ts/address/configs");
2326
2297
  var import_math9 = require("@fuel-ts/math");
2327
2298
  var import_transactions8 = require("@fuel-ts/transactions");
2328
2299
  var import_utils13 = require("@fuel-ts/utils");
2329
2300
 
2330
2301
  // src/providers/transaction-request/hash-transaction.ts
2331
- var import_configs7 = require("@fuel-ts/address/configs");
2302
+ var import_configs8 = require("@fuel-ts/address/configs");
2332
2303
  var import_hasher = require("@fuel-ts/hasher");
2333
2304
  var import_math8 = require("@fuel-ts/math");
2334
2305
  var import_transactions7 = require("@fuel-ts/transactions");
@@ -2337,7 +2308,7 @@ var import_ramda2 = require("ramda");
2337
2308
  function hashTransaction(transactionRequest, chainId) {
2338
2309
  const transaction = transactionRequest.toTransaction();
2339
2310
  if (transaction.type === import_transactions7.TransactionType.Script) {
2340
- transaction.receiptsRoot = import_configs7.ZeroBytes32;
2311
+ transaction.receiptsRoot = import_configs8.ZeroBytes32;
2341
2312
  }
2342
2313
  transaction.inputs = transaction.inputs.map((input) => {
2343
2314
  const inputClone = (0, import_ramda2.clone)(input);
@@ -2359,10 +2330,10 @@ function hashTransaction(transactionRequest, chainId) {
2359
2330
  blockHeight: 0,
2360
2331
  txIndex: 0
2361
2332
  };
2362
- inputClone.txID = import_configs7.ZeroBytes32;
2333
+ inputClone.txID = import_configs8.ZeroBytes32;
2363
2334
  inputClone.outputIndex = 0;
2364
- inputClone.balanceRoot = import_configs7.ZeroBytes32;
2365
- inputClone.stateRoot = import_configs7.ZeroBytes32;
2335
+ inputClone.balanceRoot = import_configs8.ZeroBytes32;
2336
+ inputClone.stateRoot = import_configs8.ZeroBytes32;
2366
2337
  return inputClone;
2367
2338
  }
2368
2339
  default:
@@ -2373,8 +2344,8 @@ function hashTransaction(transactionRequest, chainId) {
2373
2344
  const outputClone = (0, import_ramda2.clone)(output);
2374
2345
  switch (outputClone.type) {
2375
2346
  case import_transactions7.OutputType.Contract: {
2376
- outputClone.balanceRoot = import_configs7.ZeroBytes32;
2377
- outputClone.stateRoot = import_configs7.ZeroBytes32;
2347
+ outputClone.balanceRoot = import_configs8.ZeroBytes32;
2348
+ outputClone.stateRoot = import_configs8.ZeroBytes32;
2378
2349
  return outputClone;
2379
2350
  }
2380
2351
  case import_transactions7.OutputType.Change: {
@@ -2382,9 +2353,9 @@ function hashTransaction(transactionRequest, chainId) {
2382
2353
  return outputClone;
2383
2354
  }
2384
2355
  case import_transactions7.OutputType.Variable: {
2385
- outputClone.to = import_configs7.ZeroBytes32;
2356
+ outputClone.to = import_configs8.ZeroBytes32;
2386
2357
  outputClone.amount = (0, import_math8.bn)(0);
2387
- outputClone.assetId = import_configs7.ZeroBytes32;
2358
+ outputClone.assetId = import_configs8.ZeroBytes32;
2388
2359
  return outputClone;
2389
2360
  }
2390
2361
  default:
@@ -2442,10 +2413,15 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2442
2413
  *
2443
2414
  * @param createTransactionRequestLike - The initial values for the instance
2444
2415
  */
2445
- constructor({ bytecodeWitnessIndex, salt, storageSlots, ...rest }) {
2416
+ constructor({
2417
+ bytecodeWitnessIndex,
2418
+ salt,
2419
+ storageSlots,
2420
+ ...rest
2421
+ } = {}) {
2446
2422
  super(rest);
2447
2423
  this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
2448
- this.salt = (0, import_utils13.hexlify)(salt ?? import_configs8.ZeroBytes32);
2424
+ this.salt = (0, import_utils13.hexlify)(salt ?? import_configs9.ZeroBytes32);
2449
2425
  this.storageSlots = [...storageSlots ?? []];
2450
2426
  }
2451
2427
  /**
@@ -2463,7 +2439,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2463
2439
  bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
2464
2440
  bytecodeWitnessIndex,
2465
2441
  storageSlotsCount: storageSlots.length,
2466
- salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs8.ZeroBytes32,
2442
+ salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs9.ZeroBytes32,
2467
2443
  storageSlots
2468
2444
  };
2469
2445
  }
@@ -2511,9 +2487,9 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2511
2487
  };
2512
2488
 
2513
2489
  // src/providers/transaction-request/script-transaction-request.ts
2514
- var import_abi_coder = require("@fuel-ts/abi-coder");
2490
+ var import_abi_coder3 = require("@fuel-ts/abi-coder");
2515
2491
  var import_address2 = require("@fuel-ts/address");
2516
- var import_configs9 = require("@fuel-ts/address/configs");
2492
+ var import_configs10 = require("@fuel-ts/address/configs");
2517
2493
  var import_math10 = require("@fuel-ts/math");
2518
2494
  var import_transactions9 = require("@fuel-ts/transactions");
2519
2495
  var import_utils15 = require("@fuel-ts/utils");
@@ -2566,7 +2542,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2566
2542
  *
2567
2543
  * @param scriptTransactionRequestLike - The initial values for the instance.
2568
2544
  */
2569
- constructor({ script, scriptData, gasLimit, ...rest }) {
2545
+ constructor({ script, scriptData, gasLimit, ...rest } = {}) {
2570
2546
  super(rest);
2571
2547
  this.gasLimit = (0, import_math10.bn)(gasLimit);
2572
2548
  this.script = (0, import_utils15.arrayify)(script ?? returnZeroScript.bytes);
@@ -2587,7 +2563,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2587
2563
  ...super.getBaseTransaction(),
2588
2564
  scriptLength: script.length,
2589
2565
  scriptDataLength: scriptData.length,
2590
- receiptsRoot: import_configs9.ZeroBytes32,
2566
+ receiptsRoot: import_configs10.ZeroBytes32,
2591
2567
  script: (0, import_utils15.hexlify)(script),
2592
2568
  scriptData: (0, import_utils15.hexlify)(scriptData)
2593
2569
  };
@@ -2703,7 +2679,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2703
2679
  * @returns The current instance of the `ScriptTransactionRequest`.
2704
2680
  */
2705
2681
  setData(abi, args) {
2706
- const abiInterface = new import_abi_coder.Interface(abi);
2682
+ const abiInterface = new import_abi_coder3.Interface(abi);
2707
2683
  this.scriptData = abiInterface.functions.main.encodeArguments(args);
2708
2684
  return this;
2709
2685
  }
@@ -2819,23 +2795,23 @@ var calculateTransactionFee = (params) => {
2819
2795
  };
2820
2796
 
2821
2797
  // src/providers/transaction-summary/operations.ts
2822
- var import_configs10 = require("@fuel-ts/address/configs");
2798
+ var import_configs11 = require("@fuel-ts/address/configs");
2823
2799
  var import_errors11 = require("@fuel-ts/errors");
2824
2800
  var import_math13 = require("@fuel-ts/math");
2825
2801
  var import_transactions14 = require("@fuel-ts/transactions");
2826
2802
 
2827
2803
  // src/providers/transaction-summary/call.ts
2828
- var import_abi_coder2 = require("@fuel-ts/abi-coder");
2804
+ var import_abi_coder4 = require("@fuel-ts/abi-coder");
2829
2805
  var import_math12 = require("@fuel-ts/math");
2830
2806
  var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
2831
- const abiInterface = new import_abi_coder2.Interface(abi);
2807
+ const abiInterface = new import_abi_coder4.Interface(abi);
2832
2808
  const callFunctionSelector = receipt.param1.toHex(8);
2833
2809
  const functionFragment = abiInterface.getFunction(callFunctionSelector);
2834
2810
  const inputs = functionFragment.jsonFn.inputs;
2835
2811
  let encodedArgs;
2836
2812
  if (functionFragment.isInputDataPointer) {
2837
2813
  if (rawPayload) {
2838
- const argsOffset = (0, import_math12.bn)(receipt.param2).sub((0, import_abi_coder2.calculateVmTxMemory)({ maxInputs: maxInputs.toNumber() })).toNumber();
2814
+ const argsOffset = (0, import_math12.bn)(receipt.param2).sub((0, import_abi_coder4.calculateVmTxMemory)({ maxInputs: maxInputs.toNumber() })).toNumber();
2839
2815
  encodedArgs = `0x${rawPayload.slice(2).slice(argsOffset * 2)}`;
2840
2816
  }
2841
2817
  } else {
@@ -3164,7 +3140,7 @@ function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutp
3164
3140
  const { to: toAddress, assetId, amount } = receipt;
3165
3141
  let { from: fromAddress } = receipt;
3166
3142
  const toType = contractInputs.some((input) => input.contractID === toAddress) ? 0 /* contract */ : 1 /* account */;
3167
- if (import_configs10.ZeroBytes32 === fromAddress) {
3143
+ if (import_configs11.ZeroBytes32 === fromAddress) {
3168
3144
  const change = changeOutputs.find((output) => output.assetId === assetId);
3169
3145
  fromAddress = change?.to || fromAddress;
3170
3146
  }
@@ -3485,13 +3461,13 @@ function assembleTransactionSummary(params) {
3485
3461
  }
3486
3462
 
3487
3463
  // src/providers/transaction-response/getDecodedLogs.ts
3488
- var import_abi_coder3 = require("@fuel-ts/abi-coder");
3464
+ var import_abi_coder5 = require("@fuel-ts/abi-coder");
3489
3465
  var import_transactions16 = require("@fuel-ts/transactions");
3490
3466
  function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
3491
3467
  return receipts.reduce((logs, receipt) => {
3492
3468
  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;
3469
+ const interfaceToUse = new import_abi_coder5.Interface(externalAbis[receipt.id] || mainAbi);
3470
+ const data = receipt.type === import_transactions16.ReceiptType.Log ? new import_abi_coder5.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
3495
3471
  const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
3496
3472
  logs.push(decodedLog);
3497
3473
  }
@@ -3741,7 +3717,6 @@ var processGqlChain = (chain) => {
3741
3717
  gasPerByte: (0, import_math15.bn)(feeParams.gasPerByte),
3742
3718
  maxMessageDataLength: (0, import_math15.bn)(predicateParams.maxMessageDataLength),
3743
3719
  chainId: (0, import_math15.bn)(consensusParameters.chainId),
3744
- baseAssetId: consensusParameters.baseAssetId,
3745
3720
  gasCosts
3746
3721
  },
3747
3722
  gasCosts,
@@ -3984,17 +3959,6 @@ var _Provider = class {
3984
3959
  } = this.getChain();
3985
3960
  return chainId.toNumber();
3986
3961
  }
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
3962
  /**
3999
3963
  * Submits a transaction to the chain to be executed.
4000
3964
  *
@@ -4145,6 +4109,36 @@ var _Provider = class {
4145
4109
  missingContractIds
4146
4110
  };
4147
4111
  }
4112
+ /**
4113
+ * Estimates the transaction gas and fee based on the provided transaction request.
4114
+ * @param transactionRequest - The transaction request object.
4115
+ * @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
4116
+ */
4117
+ estimateTxGasAndFee(params) {
4118
+ const { transactionRequest } = params;
4119
+ const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
4120
+ const chainInfo = this.getChain();
4121
+ const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
4122
+ transactionRequest.gasPrice = gasPrice;
4123
+ const minGas = transactionRequest.calculateMinGas(chainInfo);
4124
+ const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
4125
+ if (transactionRequest.type === import_transactions18.TransactionType.Script) {
4126
+ if (transactionRequest.gasLimit.eq(0)) {
4127
+ transactionRequest.gasLimit = minGas;
4128
+ transactionRequest.gasLimit = maxGasPerTx.sub(
4129
+ transactionRequest.calculateMaxGas(chainInfo, minGas)
4130
+ );
4131
+ }
4132
+ }
4133
+ const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
4134
+ const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
4135
+ return {
4136
+ minGas,
4137
+ minFee,
4138
+ maxGas,
4139
+ maxFee
4140
+ };
4141
+ }
4148
4142
  /**
4149
4143
  * Executes a signed transaction without applying the states changes
4150
4144
  * on the chain.
@@ -4192,17 +4186,16 @@ var _Provider = class {
4192
4186
  signatureCallback
4193
4187
  } = {}) {
4194
4188
  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);
4189
+ const { minGasPrice } = this.getGasConfig();
4190
+ const setGasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
4198
4191
  const isScriptTransaction = txRequestClone.type === import_transactions18.TransactionType.Script;
4199
4192
  const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
4200
4193
  const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
4201
4194
  txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
4195
+ if (isScriptTransaction) {
4196
+ txRequestClone.gasLimit = (0, import_math15.bn)(0);
4197
+ }
4202
4198
  if (estimatePredicates) {
4203
- if (isScriptTransaction) {
4204
- txRequestClone.gasLimit = (0, import_math15.bn)(0);
4205
- }
4206
4199
  if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
4207
4200
  resourcesOwner.populateTransactionPredicateData(txRequestClone);
4208
4201
  }
@@ -4211,36 +4204,34 @@ var _Provider = class {
4211
4204
  if (signatureCallback && isScriptTransaction) {
4212
4205
  await signatureCallback(txRequestClone);
4213
4206
  }
4214
- const minGas = txRequestClone.calculateMinGas(chainInfo);
4215
- const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
4207
+ let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
4208
+ transactionRequest: txRequestClone
4209
+ });
4216
4210
  let receipts = [];
4217
4211
  let missingContractIds = [];
4218
4212
  let outputVariables = 0;
4213
+ let gasUsed = (0, import_math15.bn)(0);
4219
4214
  if (isScriptTransaction && estimateTxDependencies) {
4220
4215
  txRequestClone.gasPrice = (0, import_math15.bn)(0);
4221
- txRequestClone.gasLimit = (0, import_math15.bn)(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
4222
4216
  const result = await this.estimateTxDependencies(txRequestClone);
4223
4217
  receipts = result.receipts;
4224
4218
  outputVariables = result.outputVariables;
4225
4219
  missingContractIds = result.missingContractIds;
4220
+ gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
4221
+ txRequestClone.gasLimit = gasUsed;
4222
+ txRequestClone.gasPrice = setGasPrice;
4223
+ ({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
4224
+ transactionRequest: txRequestClone
4225
+ }));
4226
4226
  }
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
4227
  return {
4236
4228
  requiredQuantities: allQuantities,
4237
4229
  receipts,
4238
4230
  gasUsed,
4239
4231
  minGasPrice,
4240
- gasPrice,
4232
+ gasPrice: setGasPrice,
4241
4233
  minGas,
4242
4234
  maxGas,
4243
- usedFee,
4244
4235
  minFee,
4245
4236
  maxFee,
4246
4237
  estimatedInputs: txRequestClone.inputs,
@@ -4873,13 +4864,13 @@ var assets = [
4873
4864
  ];
4874
4865
 
4875
4866
  // src/utils/formatTransferToContractScriptData.ts
4876
- var import_abi_coder4 = require("@fuel-ts/abi-coder");
4867
+ var import_abi_coder6 = require("@fuel-ts/abi-coder");
4877
4868
  var import_math17 = require("@fuel-ts/math");
4878
4869
  var import_utils27 = require("@fuel-ts/utils");
4879
4870
  var asm = __toESM(require("@fuels/vm-asm"));
4880
4871
  var formatTransferToContractScriptData = (params) => {
4881
4872
  const { assetId, amountToTransfer, hexlifiedContractId } = params;
4882
- const numberCoder = new import_abi_coder4.BigNumberCoder("u64");
4873
+ const numberCoder = new import_abi_coder6.BigNumberCoder("u64");
4883
4874
  const encoded = numberCoder.encode(new import_math17.BN(amountToTransfer).toNumber());
4884
4875
  const scriptData = Uint8Array.from([
4885
4876
  ...(0, import_utils27.arrayify)(hexlifiedContractId),
@@ -5031,9 +5022,8 @@ var Account = class extends import_interfaces.AbstractAccount {
5031
5022
  * @param assetId - The asset ID to check the balance for.
5032
5023
  * @returns A promise that resolves to the balance amount.
5033
5024
  */
5034
- async getBalance(assetId) {
5035
- const assetIdToFetch = assetId ?? this.provider.getBaseAssetId();
5036
- const amount = await this.provider.getBalance(this.address, assetIdToFetch);
5025
+ async getBalance(assetId = import_configs12.BaseAssetId) {
5026
+ const amount = await this.provider.getBalance(this.address, assetId);
5037
5027
  return amount;
5038
5028
  }
5039
5029
  /**
@@ -5071,10 +5061,9 @@ var Account = class extends import_interfaces.AbstractAccount {
5071
5061
  * @returns A promise that resolves when the resources are added to the transaction.
5072
5062
  */
5073
5063
  async fund(request, coinQuantities, fee) {
5074
- const baseAssetId = this.provider.getBaseAssetId();
5075
5064
  const updatedQuantities = addAmountToAsset({
5076
5065
  amount: (0, import_math18.bn)(fee),
5077
- assetId: baseAssetId,
5066
+ assetId: import_configs12.BaseAssetId,
5078
5067
  coinQuantities
5079
5068
  });
5080
5069
  const quantitiesDict = {};
@@ -5098,8 +5087,8 @@ var Account = class extends import_interfaces.AbstractAccount {
5098
5087
  quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
5099
5088
  cachedUtxos.push(input.id);
5100
5089
  }
5101
- } else if (input.recipient === owner && input.amount && quantitiesDict[baseAssetId]) {
5102
- quantitiesDict[baseAssetId].owned = quantitiesDict[baseAssetId].owned.add(input.amount);
5090
+ } else if (input.recipient === owner && input.amount && quantitiesDict[import_configs12.BaseAssetId]) {
5091
+ quantitiesDict[import_configs12.BaseAssetId].owned = quantitiesDict[import_configs12.BaseAssetId].owned.add(input.amount);
5103
5092
  cachedMessages.push(input.nonce);
5104
5093
  }
5105
5094
  }
@@ -5131,13 +5120,11 @@ var Account = class extends import_interfaces.AbstractAccount {
5131
5120
  * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
5132
5121
  * @returns A promise that resolves to the prepared transaction request.
5133
5122
  */
5134
- async createTransfer(destination, amount, assetId, txParams = {}) {
5123
+ async createTransfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
5135
5124
  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 };
5125
+ const params = { gasPrice: minGasPrice, ...txParams };
5139
5126
  const request = new ScriptTransactionRequest(params);
5140
- request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetIdToTransfer);
5127
+ request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetId);
5141
5128
  const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
5142
5129
  estimateTxDependencies: true,
5143
5130
  resourcesOwner: this
@@ -5163,15 +5150,14 @@ var Account = class extends import_interfaces.AbstractAccount {
5163
5150
  * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
5164
5151
  * @returns A promise that resolves to the transaction response.
5165
5152
  */
5166
- async transfer(destination, amount, assetId, txParams = {}) {
5153
+ async transfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
5167
5154
  if ((0, import_math18.bn)(amount).lte(0)) {
5168
5155
  throw new import_errors16.FuelError(
5169
5156
  import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
5170
5157
  "Transfer amount must be a positive number."
5171
5158
  );
5172
5159
  }
5173
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
5174
- const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
5160
+ const request = await this.createTransfer(destination, amount, assetId, txParams);
5175
5161
  return this.sendTransaction(request, { estimateTxDependencies: false });
5176
5162
  }
5177
5163
  /**
@@ -5183,7 +5169,7 @@ var Account = class extends import_interfaces.AbstractAccount {
5183
5169
  * @param txParams - The optional transaction parameters.
5184
5170
  * @returns A promise that resolves to the transaction response.
5185
5171
  */
5186
- async transferToContract(contractId, amount, assetId, txParams = {}) {
5172
+ async transferToContract(contractId, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
5187
5173
  if ((0, import_math18.bn)(amount).lte(0)) {
5188
5174
  throw new import_errors16.FuelError(
5189
5175
  import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
@@ -5192,13 +5178,11 @@ var Account = class extends import_interfaces.AbstractAccount {
5192
5178
  }
5193
5179
  const contractAddress = import_address4.Address.fromAddressOrString(contractId);
5194
5180
  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 };
5181
+ const params = { gasPrice: minGasPrice, ...txParams };
5198
5182
  const { script, scriptData } = await assembleTransferToContractScript({
5199
5183
  hexlifiedContractId: contractAddress.toB256(),
5200
5184
  amountToTransfer: (0, import_math18.bn)(amount),
5201
- assetId: assetIdToTransfer
5185
+ assetId
5202
5186
  });
5203
5187
  const request = new ScriptTransactionRequest({
5204
5188
  ...params,
@@ -5208,7 +5192,7 @@ var Account = class extends import_interfaces.AbstractAccount {
5208
5192
  request.addContractInputAndOutput(contractAddress);
5209
5193
  const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
5210
5194
  request,
5211
- [{ amount: (0, import_math18.bn)(amount), assetId: String(assetIdToTransfer) }]
5195
+ [{ amount: (0, import_math18.bn)(amount), assetId: String(assetId) }]
5212
5196
  );
5213
5197
  request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
5214
5198
  this.validateGas({
@@ -5230,7 +5214,6 @@ var Account = class extends import_interfaces.AbstractAccount {
5230
5214
  */
5231
5215
  async withdrawToBaseLayer(recipient, amount, txParams = {}) {
5232
5216
  const { minGasPrice } = this.provider.getGasConfig();
5233
- const baseAssetId = this.provider.getBaseAssetId();
5234
5217
  const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
5235
5218
  const recipientDataArray = (0, import_utils28.arrayify)(
5236
5219
  "0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
@@ -5243,14 +5226,9 @@ var Account = class extends import_interfaces.AbstractAccount {
5243
5226
  ...recipientDataArray,
5244
5227
  ...amountDataArray
5245
5228
  ]);
5246
- const params = {
5247
- script,
5248
- gasPrice: minGasPrice,
5249
- baseAssetId,
5250
- ...txParams
5251
- };
5229
+ const params = { script, gasPrice: minGasPrice, ...txParams };
5252
5230
  const request = new ScriptTransactionRequest(params);
5253
- const forwardingQuantities = [{ amount: (0, import_math18.bn)(amount), assetId: baseAssetId }];
5231
+ const forwardingQuantities = [{ amount: (0, import_math18.bn)(amount), assetId: import_configs12.BaseAssetId }];
5254
5232
  const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
5255
5233
  request,
5256
5234
  forwardingQuantities
@@ -5347,7 +5325,7 @@ var import_utils31 = require("@fuel-ts/utils");
5347
5325
 
5348
5326
  // src/signer/signer.ts
5349
5327
  var import_address5 = require("@fuel-ts/address");
5350
- var import_crypto = require("@fuel-ts/crypto");
5328
+ var import_crypto2 = require("@fuel-ts/crypto");
5351
5329
  var import_hasher2 = require("@fuel-ts/hasher");
5352
5330
  var import_math19 = require("@fuel-ts/math");
5353
5331
  var import_utils29 = require("@fuel-ts/utils");
@@ -5440,7 +5418,7 @@ var Signer = class {
5440
5418
  * @returns random 32-byte hashed
5441
5419
  */
5442
5420
  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);
5421
+ 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
5422
  }
5445
5423
  /**
5446
5424
  * Extended publicKey from a compact publicKey
@@ -5456,7 +5434,7 @@ var Signer = class {
5456
5434
 
5457
5435
  // src/wallet/keystore-wallet.ts
5458
5436
  var import_address6 = require("@fuel-ts/address");
5459
- var import_crypto2 = require("@fuel-ts/crypto");
5437
+ var import_crypto3 = require("@fuel-ts/crypto");
5460
5438
  var import_errors17 = require("@fuel-ts/errors");
5461
5439
  var import_utils30 = require("@fuel-ts/utils");
5462
5440
  var import_uuid = require("uuid");
@@ -5472,22 +5450,22 @@ var removeHexPrefix = (hexString) => {
5472
5450
  return hexString;
5473
5451
  };
5474
5452
  async function encryptKeystoreWallet(privateKey, address, password) {
5475
- const privateKeyBuffer = (0, import_crypto2.bufferFromString)(removeHexPrefix(privateKey), "hex");
5453
+ const privateKeyBuffer = (0, import_crypto3.bufferFromString)(removeHexPrefix(privateKey), "hex");
5476
5454
  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),
5455
+ const salt = (0, import_crypto3.randomBytes)(DEFAULT_KEY_SIZE);
5456
+ const key = (0, import_crypto3.scrypt)({
5457
+ password: (0, import_crypto3.bufferFromString)(password),
5480
5458
  salt,
5481
5459
  dklen: DEFAULT_KEY_SIZE,
5482
5460
  n: 2 ** DEFAULT_KDF_PARAMS_LOG_N,
5483
5461
  r: DEFAULT_KDF_PARAMS_R,
5484
5462
  p: DEFAULT_KDF_PARAMS_P
5485
5463
  });
5486
- const iv = (0, import_crypto2.randomBytes)(DEFAULT_IV_SIZE);
5487
- const ciphertext = await (0, import_crypto2.encryptJsonWalletData)(privateKeyBuffer, key, iv);
5464
+ const iv = (0, import_crypto3.randomBytes)(DEFAULT_IV_SIZE);
5465
+ const ciphertext = await (0, import_crypto3.encryptJsonWalletData)(privateKeyBuffer, key, iv);
5488
5466
  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");
5467
+ const macHashUint8Array = (0, import_crypto3.keccak256)(data);
5468
+ const mac = (0, import_crypto3.stringFromBuffer)(macHashUint8Array, "hex");
5491
5469
  const keystore = {
5492
5470
  id: (0, import_uuid.v4)(),
5493
5471
  version: 3,
@@ -5495,15 +5473,15 @@ async function encryptKeystoreWallet(privateKey, address, password) {
5495
5473
  crypto: {
5496
5474
  cipher: "aes-128-ctr",
5497
5475
  mac,
5498
- cipherparams: { iv: (0, import_crypto2.stringFromBuffer)(iv, "hex") },
5499
- ciphertext: (0, import_crypto2.stringFromBuffer)(ciphertext, "hex"),
5476
+ cipherparams: { iv: (0, import_crypto3.stringFromBuffer)(iv, "hex") },
5477
+ ciphertext: (0, import_crypto3.stringFromBuffer)(ciphertext, "hex"),
5500
5478
  kdf: "scrypt",
5501
5479
  kdfparams: {
5502
5480
  dklen: DEFAULT_KEY_SIZE,
5503
5481
  n: 2 ** DEFAULT_KDF_PARAMS_LOG_N,
5504
5482
  p: DEFAULT_KDF_PARAMS_P,
5505
5483
  r: DEFAULT_KDF_PARAMS_R,
5506
- salt: (0, import_crypto2.stringFromBuffer)(salt, "hex")
5484
+ salt: (0, import_crypto3.stringFromBuffer)(salt, "hex")
5507
5485
  }
5508
5486
  }
5509
5487
  };
@@ -5519,11 +5497,11 @@ async function decryptKeystoreWallet(jsonWallet, password) {
5519
5497
  kdfparams: { dklen, n, r, p, salt }
5520
5498
  }
5521
5499
  } = 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)({
5500
+ const ciphertextBuffer = (0, import_crypto3.bufferFromString)(ciphertext, "hex");
5501
+ const ivBuffer = (0, import_crypto3.bufferFromString)(iv, "hex");
5502
+ const saltBuffer = (0, import_crypto3.bufferFromString)(salt, "hex");
5503
+ const passwordBuffer = (0, import_crypto3.bufferFromString)(password);
5504
+ const key = (0, import_crypto3.scrypt)({
5527
5505
  password: passwordBuffer,
5528
5506
  salt: saltBuffer,
5529
5507
  n,
@@ -5532,15 +5510,15 @@ async function decryptKeystoreWallet(jsonWallet, password) {
5532
5510
  dklen
5533
5511
  });
5534
5512
  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");
5513
+ const macHashUint8Array = (0, import_crypto3.keccak256)(data);
5514
+ const macHash = (0, import_crypto3.stringFromBuffer)(macHashUint8Array, "hex");
5537
5515
  if (mac !== macHash) {
5538
5516
  throw new import_errors17.FuelError(
5539
5517
  import_errors17.ErrorCode.INVALID_PASSWORD,
5540
5518
  "Failed to decrypt the keystore wallet, the provided password is incorrect."
5541
5519
  );
5542
5520
  }
5543
- const buffer = await (0, import_crypto2.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
5521
+ const buffer = await (0, import_crypto3.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
5544
5522
  const privateKey = (0, import_utils30.hexlify)(buffer);
5545
5523
  return privateKey;
5546
5524
  }
@@ -5665,7 +5643,7 @@ var import_utils35 = require("@fuel-ts/utils");
5665
5643
  var import_ethers3 = require("ethers");
5666
5644
 
5667
5645
  // src/mnemonic/mnemonic.ts
5668
- var import_crypto3 = require("@fuel-ts/crypto");
5646
+ var import_crypto4 = require("@fuel-ts/crypto");
5669
5647
  var import_errors19 = require("@fuel-ts/errors");
5670
5648
  var import_hasher5 = require("@fuel-ts/hasher");
5671
5649
  var import_utils33 = require("@fuel-ts/utils");
@@ -8026,7 +8004,7 @@ var Mnemonic = class {
8026
8004
  * @returns A randomly generated mnemonic
8027
8005
  */
8028
8006
  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);
8007
+ 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
8008
  return Mnemonic.entropyToMnemonic(entropy);
8031
8009
  }
8032
8010
  };
@@ -8398,7 +8376,7 @@ __publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
8398
8376
 
8399
8377
  // src/wallet-manager/wallet-manager.ts
8400
8378
  var import_address9 = require("@fuel-ts/address");
8401
- var import_crypto4 = require("@fuel-ts/crypto");
8379
+ var import_crypto5 = require("@fuel-ts/crypto");
8402
8380
  var import_errors23 = require("@fuel-ts/errors");
8403
8381
  var import_events = require("events");
8404
8382
 
@@ -8726,7 +8704,7 @@ var _WalletManager = class extends import_events.EventEmitter {
8726
8704
  await assert(!__privateGet(this, _isLocked), ERROR_MESSAGES.wallet_not_unlocked);
8727
8705
  const data = await this.storage.getItem(this.STORAGE_KEY);
8728
8706
  if (data) {
8729
- const state = await (0, import_crypto4.decrypt)(__privateGet(this, _passphrase), JSON.parse(data));
8707
+ const state = await (0, import_crypto5.decrypt)(__privateGet(this, _passphrase), JSON.parse(data));
8730
8708
  __privateSet(this, _vaults, __privateMethod(this, _deserializeVaults, deserializeVaults_fn).call(this, state.vaults));
8731
8709
  }
8732
8710
  }
@@ -8735,7 +8713,7 @@ var _WalletManager = class extends import_events.EventEmitter {
8735
8713
  */
8736
8714
  async saveState() {
8737
8715
  await assert(!__privateGet(this, _isLocked), ERROR_MESSAGES.wallet_not_unlocked);
8738
- const encryptedData = await (0, import_crypto4.encrypt)(__privateGet(this, _passphrase), {
8716
+ const encryptedData = await (0, import_crypto5.encrypt)(__privateGet(this, _passphrase), {
8739
8717
  vaults: __privateMethod(this, _serializeVaults, serializeVaults_fn).call(this, __privateGet(this, _vaults))
8740
8718
  });
8741
8719
  await this.storage.setItem(this.STORAGE_KEY, JSON.stringify(encryptedData));
@@ -8811,8 +8789,9 @@ var StorageAbstract = class {
8811
8789
  };
8812
8790
 
8813
8791
  // src/predicate/predicate.ts
8814
- var import_abi_coder5 = require("@fuel-ts/abi-coder");
8792
+ var import_abi_coder7 = require("@fuel-ts/abi-coder");
8815
8793
  var import_address10 = require("@fuel-ts/address");
8794
+ var import_configs13 = require("@fuel-ts/address/configs");
8816
8795
  var import_errors25 = require("@fuel-ts/errors");
8817
8796
  var import_transactions20 = require("@fuel-ts/transactions");
8818
8797
  var import_utils37 = require("@fuel-ts/utils");
@@ -8877,6 +8856,7 @@ var Predicate = class extends Account {
8877
8856
  if (input.type === import_transactions20.InputType.Coin && (0, import_utils37.hexlify)(input.owner) === this.address.toB256()) {
8878
8857
  input.predicate = this.bytes;
8879
8858
  input.predicateData = this.getPredicateData(policies.length);
8859
+ input.witnessIndex = 0;
8880
8860
  }
8881
8861
  });
8882
8862
  return request;
@@ -8890,9 +8870,8 @@ var Predicate = class extends Account {
8890
8870
  * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
8891
8871
  * @returns A promise that resolves to the prepared transaction request.
8892
8872
  */
8893
- async createTransfer(destination, amount, assetId, txParams = {}) {
8894
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
8895
- const request = await super.createTransfer(destination, amount, assetIdToTransfer, txParams);
8873
+ async createTransfer(destination, amount, assetId = import_configs13.BaseAssetId, txParams = {}) {
8874
+ const request = await super.createTransfer(destination, amount, assetId, txParams);
8896
8875
  return this.populateTransactionPredicateData(request);
8897
8876
  }
8898
8877
  /**
@@ -8915,16 +8894,30 @@ var Predicate = class extends Account {
8915
8894
  const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
8916
8895
  return super.simulateTransaction(transactionRequest);
8917
8896
  }
8897
+ /**
8898
+ * Retrieves resources satisfying the spend query for the account.
8899
+ *
8900
+ * @param quantities - IDs of coins to exclude.
8901
+ * @param excludedIds - IDs of resources to be excluded from the query.
8902
+ * @returns A promise that resolves to an array of Resources.
8903
+ */
8904
+ async getResourcesToSpend(quantities, excludedIds) {
8905
+ const resources = await super.getResourcesToSpend(quantities, excludedIds);
8906
+ return resources.map((resource) => ({
8907
+ ...resource,
8908
+ predicate: (0, import_utils37.hexlify)(this.bytes)
8909
+ }));
8910
+ }
8918
8911
  getPredicateData(policiesLength) {
8919
8912
  if (!this.predicateData.length) {
8920
8913
  return new Uint8Array();
8921
8914
  }
8922
8915
  const mainFn = this.interface?.functions.main;
8923
8916
  const paddedCode = new import_transactions20.ByteArrayCoder(this.bytes.length).encode(this.bytes);
8924
- const VM_TX_MEMORY = (0, import_abi_coder5.calculateVmTxMemory)({
8917
+ const VM_TX_MEMORY = (0, import_abi_coder7.calculateVmTxMemory)({
8925
8918
  maxInputs: this.provider.getChain().consensusParameters.maxInputs.toNumber()
8926
8919
  });
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;
8920
+ 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
8921
  return mainFn?.encodeArguments(this.predicateData, OFFSET) || new Uint8Array();
8929
8922
  }
8930
8923
  /**
@@ -8939,7 +8932,7 @@ var Predicate = class extends Account {
8939
8932
  let predicateBytes = (0, import_utils37.arrayify)(bytes);
8940
8933
  let abiInterface;
8941
8934
  if (jsonAbi) {
8942
- abiInterface = new import_abi_coder5.Interface(jsonAbi);
8935
+ abiInterface = new import_abi_coder7.Interface(jsonAbi);
8943
8936
  if (abiInterface.functions.main === void 0) {
8944
8937
  throw new import_errors25.FuelError(
8945
8938
  import_errors25.ErrorCode.ABI_MAIN_METHOD_MISSING,