@fuel-ts/account 0.0.0-rc-1976-20240404073406 → 0.0.0-rc-1764-20240404125616

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 (57) hide show
  1. package/README.md +1 -1
  2. package/dist/account.d.ts +5 -4
  3. package/dist/account.d.ts.map +1 -1
  4. package/dist/configs.d.ts.map +1 -1
  5. package/dist/configs.global.js +1 -1
  6. package/dist/configs.global.js.map +1 -1
  7. package/dist/configs.js +1 -1
  8. package/dist/configs.js.map +1 -1
  9. package/dist/configs.mjs +1 -1
  10. package/dist/configs.mjs.map +1 -1
  11. package/dist/index.global.js +912 -544
  12. package/dist/index.global.js.map +1 -1
  13. package/dist/index.js +1032 -714
  14. package/dist/index.js.map +1 -1
  15. package/dist/index.mjs +909 -587
  16. package/dist/index.mjs.map +1 -1
  17. package/dist/predicate/predicate.d.ts +10 -2
  18. package/dist/predicate/predicate.d.ts.map +1 -1
  19. package/dist/providers/__generated__/operations.d.ts +822 -303
  20. package/dist/providers/__generated__/operations.d.ts.map +1 -1
  21. package/dist/providers/coin-quantity.d.ts +3 -3
  22. package/dist/providers/coin-quantity.d.ts.map +1 -1
  23. package/dist/providers/coin.d.ts +4 -2
  24. package/dist/providers/coin.d.ts.map +1 -1
  25. package/dist/providers/fuel-graphql-subscriber.d.ts.map +1 -1
  26. package/dist/providers/message.d.ts +3 -0
  27. package/dist/providers/message.d.ts.map +1 -1
  28. package/dist/providers/provider.d.ts +44 -31
  29. package/dist/providers/provider.d.ts.map +1 -1
  30. package/dist/providers/transaction-request/input.d.ts +2 -2
  31. package/dist/providers/transaction-request/input.d.ts.map +1 -1
  32. package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
  33. package/dist/providers/transaction-request/transaction-request.d.ts +9 -29
  34. package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
  35. package/dist/providers/transaction-request/utils.d.ts +3 -0
  36. package/dist/providers/transaction-request/utils.d.ts.map +1 -1
  37. package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
  38. package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts +2 -0
  39. package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
  40. package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts +3 -2
  41. package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts.map +1 -1
  42. package/dist/providers/transaction-summary/get-transaction-summary.d.ts.map +1 -1
  43. package/dist/providers/utils/extract-tx-error.d.ts +36 -0
  44. package/dist/providers/utils/extract-tx-error.d.ts.map +1 -0
  45. package/dist/providers/utils/gas.d.ts +8 -2
  46. package/dist/providers/utils/gas.d.ts.map +1 -1
  47. package/dist/providers/utils/index.d.ts +1 -0
  48. package/dist/providers/utils/index.d.ts.map +1 -1
  49. package/dist/test-utils/launchNode.d.ts.map +1 -1
  50. package/dist/test-utils.global.js +871 -540
  51. package/dist/test-utils.global.js.map +1 -1
  52. package/dist/test-utils.js +944 -671
  53. package/dist/test-utils.js.map +1 -1
  54. package/dist/test-utils.mjs +832 -551
  55. package/dist/test-utils.mjs.map +1 -1
  56. package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
  57. package/package.json +17 -17
package/dist/index.js CHANGED
@@ -88,23 +88,26 @@ __export(src_exports, {
88
88
  StorageAbstract: () => StorageAbstract,
89
89
  TransactionResponse: () => TransactionResponse,
90
90
  TransactionStatus: () => TransactionStatus,
91
- TransactionType: () => import_transactions5.TransactionType,
91
+ TransactionType: () => import_transactions6.TransactionType,
92
92
  TransactionTypeName: () => TransactionTypeName,
93
93
  Vault: () => Vault,
94
94
  Wallet: () => Wallet,
95
95
  WalletLocked: () => WalletLocked,
96
96
  WalletManager: () => WalletManager,
97
97
  WalletUnlocked: () => WalletUnlocked,
98
- addAmountToAsset: () => addAmountToAsset,
98
+ addAmountToCoinQuantities: () => addAmountToCoinQuantities,
99
99
  addOperation: () => addOperation,
100
+ assemblePanicError: () => assemblePanicError,
100
101
  assembleReceiptByType: () => assembleReceiptByType,
102
+ assembleRevertError: () => assembleRevertError,
101
103
  assembleTransactionSummary: () => assembleTransactionSummary,
102
104
  assets: () => assets,
103
105
  buildBlockExplorerUrl: () => buildBlockExplorerUrl,
104
106
  cacheFor: () => cacheFor,
107
+ cacheTxInputsFromOwner: () => cacheTxInputsFromOwner,
108
+ calculateGasFee: () => calculateGasFee,
105
109
  calculateMetadataGasForTxCreate: () => calculateMetadataGasForTxCreate,
106
110
  calculateMetadataGasForTxScript: () => calculateMetadataGasForTxScript,
107
- calculatePriceWithFactor: () => calculatePriceWithFactor,
108
111
  calculateTransactionFee: () => calculateTransactionFee,
109
112
  coinQuantityfy: () => coinQuantityfy,
110
113
  deferPromise: () => deferPromise,
@@ -112,6 +115,7 @@ __export(src_exports, {
112
115
  english: () => english,
113
116
  extractBurnedAssetsFromReceipts: () => extractBurnedAssetsFromReceipts,
114
117
  extractMintedAssetsFromReceipts: () => extractMintedAssetsFromReceipts,
118
+ extractTxError: () => extractTxError,
115
119
  gasUsedByInputs: () => gasUsedByInputs,
116
120
  getAssetEth: () => getAssetEth,
117
121
  getAssetFuel: () => getAssetFuel,
@@ -181,35 +185,38 @@ module.exports = __toCommonJS(src_exports);
181
185
 
182
186
  // src/account.ts
183
187
  var import_address4 = require("@fuel-ts/address");
184
- var import_errors15 = require("@fuel-ts/errors");
188
+ var import_configs12 = require("@fuel-ts/address/configs");
189
+ var import_errors16 = require("@fuel-ts/errors");
185
190
  var import_interfaces = require("@fuel-ts/interfaces");
186
- var import_math17 = require("@fuel-ts/math");
191
+ var import_math19 = require("@fuel-ts/math");
187
192
  var import_utils27 = require("@fuel-ts/utils");
193
+ var import_ramda4 = require("ramda");
188
194
 
189
195
  // src/providers/coin-quantity.ts
196
+ var import_configs = require("@fuel-ts/address/configs");
190
197
  var import_math = require("@fuel-ts/math");
191
198
  var import_utils = require("@fuel-ts/utils");
192
199
  var coinQuantityfy = (coinQuantityLike) => {
193
200
  let assetId;
194
201
  let amount;
195
- let max2;
202
+ let max;
196
203
  if (Array.isArray(coinQuantityLike)) {
197
204
  amount = coinQuantityLike[0];
198
- assetId = coinQuantityLike[1];
199
- max2 = coinQuantityLike[2];
205
+ assetId = coinQuantityLike[1] ?? import_configs.BaseAssetId;
206
+ max = coinQuantityLike[2] ?? void 0;
200
207
  } else {
201
208
  amount = coinQuantityLike.amount;
202
- assetId = coinQuantityLike.assetId;
203
- max2 = coinQuantityLike.max ?? void 0;
209
+ assetId = coinQuantityLike.assetId ?? import_configs.BaseAssetId;
210
+ max = coinQuantityLike.max ?? void 0;
204
211
  }
205
212
  const bnAmount = (0, import_math.bn)(amount);
206
213
  return {
207
214
  assetId: (0, import_utils.hexlify)(assetId),
208
215
  amount: bnAmount.lt(1) ? (0, import_math.bn)(1) : bnAmount,
209
- max: max2 ? (0, import_math.bn)(max2) : void 0
216
+ max: max ? (0, import_math.bn)(max) : void 0
210
217
  };
211
218
  };
212
- var addAmountToAsset = (params) => {
219
+ var addAmountToCoinQuantities = (params) => {
213
220
  const { amount, assetId } = params;
214
221
  const coinQuantities = [...params.coinQuantities];
215
222
  const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
@@ -223,13 +230,13 @@ var addAmountToAsset = (params) => {
223
230
 
224
231
  // src/providers/provider.ts
225
232
  var import_address3 = require("@fuel-ts/address");
226
- var import_errors13 = require("@fuel-ts/errors");
227
- var import_math14 = require("@fuel-ts/math");
228
- var import_transactions17 = require("@fuel-ts/transactions");
233
+ var import_errors14 = require("@fuel-ts/errors");
234
+ var import_math16 = require("@fuel-ts/math");
235
+ var import_transactions19 = require("@fuel-ts/transactions");
229
236
  var import_utils22 = require("@fuel-ts/utils");
230
237
  var import_versions = require("@fuel-ts/versions");
231
238
  var import_utils23 = require("@noble/curves/abstract/utils");
232
- var import_ethers = require("ethers");
239
+ var import_ethers2 = require("ethers");
233
240
  var import_graphql_request = require("graphql-request");
234
241
  var import_ramda3 = require("ramda");
235
242
 
@@ -237,14 +244,10 @@ var import_ramda3 = require("ramda");
237
244
  var import_graphql_tag = __toESM(require("graphql-tag"));
238
245
  var ReceiptFragmentFragmentDoc = import_graphql_tag.default`
239
246
  fragment receiptFragment on Receipt {
240
- contract {
241
- id
242
- }
247
+ id
243
248
  pc
244
249
  is
245
- to {
246
- id
247
- }
250
+ to
248
251
  toAddress
249
252
  amount
250
253
  assetId
@@ -282,10 +285,16 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
282
285
  id
283
286
  }
284
287
  time
288
+ receipts {
289
+ ...receiptFragment
290
+ }
285
291
  programState {
286
292
  returnType
287
293
  data
288
294
  }
295
+ receipts {
296
+ ...receiptFragment
297
+ }
289
298
  }
290
299
  ... on FailureStatus {
291
300
  block {
@@ -293,26 +302,24 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
293
302
  }
294
303
  time
295
304
  reason
305
+ receipts {
306
+ ...receiptFragment
307
+ }
296
308
  }
297
309
  ... on SqueezedOutStatus {
298
310
  reason
299
311
  }
300
312
  }
301
- `;
313
+ ${ReceiptFragmentFragmentDoc}`;
302
314
  var TransactionFragmentFragmentDoc = import_graphql_tag.default`
303
315
  fragment transactionFragment on Transaction {
304
316
  id
305
317
  rawPayload
306
- gasPrice
307
- receipts {
308
- ...receiptFragment
309
- }
310
318
  status {
311
319
  ...transactionStatusFragment
312
320
  }
313
321
  }
314
- ${ReceiptFragmentFragmentDoc}
315
- ${TransactionStatusFragmentFragmentDoc}`;
322
+ ${TransactionStatusFragmentFragmentDoc}`;
316
323
  var InputEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.default`
317
324
  fragment inputEstimatePredicatesFragment on Input {
318
325
  ... on InputCoin {
@@ -330,6 +337,46 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.defaul
330
337
  }
331
338
  }
332
339
  ${InputEstimatePredicatesFragmentFragmentDoc}`;
340
+ var DryRunFailureStatusFragmentFragmentDoc = import_graphql_tag.default`
341
+ fragment dryRunFailureStatusFragment on DryRunFailureStatus {
342
+ reason
343
+ programState {
344
+ returnType
345
+ data
346
+ }
347
+ }
348
+ `;
349
+ var DryRunSuccessStatusFragmentFragmentDoc = import_graphql_tag.default`
350
+ fragment dryRunSuccessStatusFragment on DryRunSuccessStatus {
351
+ programState {
352
+ returnType
353
+ data
354
+ }
355
+ }
356
+ `;
357
+ var DryRunTransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
358
+ fragment dryRunTransactionStatusFragment on DryRunTransactionStatus {
359
+ ... on DryRunFailureStatus {
360
+ ...dryRunFailureStatusFragment
361
+ }
362
+ ... on DryRunSuccessStatus {
363
+ ...dryRunSuccessStatusFragment
364
+ }
365
+ }
366
+ ${DryRunFailureStatusFragmentFragmentDoc}
367
+ ${DryRunSuccessStatusFragmentFragmentDoc}`;
368
+ var DryRunTransactionExecutionStatusFragmentFragmentDoc = import_graphql_tag.default`
369
+ fragment dryRunTransactionExecutionStatusFragment on DryRunTransactionExecutionStatus {
370
+ id
371
+ status {
372
+ ...dryRunTransactionStatusFragment
373
+ }
374
+ receipts {
375
+ ...receiptFragment
376
+ }
377
+ }
378
+ ${DryRunTransactionStatusFragmentFragmentDoc}
379
+ ${ReceiptFragmentFragmentDoc}`;
333
380
  var CoinFragmentFragmentDoc = import_graphql_tag.default`
334
381
  fragment coinFragment on Coin {
335
382
  __typename
@@ -337,7 +384,6 @@ var CoinFragmentFragmentDoc = import_graphql_tag.default`
337
384
  owner
338
385
  amount
339
386
  assetId
340
- maturity
341
387
  blockCreated
342
388
  txCreatedIdx
343
389
  }
@@ -414,8 +460,8 @@ var BalanceFragmentFragmentDoc = import_graphql_tag.default`
414
460
  var BlockFragmentFragmentDoc = import_graphql_tag.default`
415
461
  fragment blockFragment on Block {
416
462
  id
463
+ height
417
464
  header {
418
- height
419
465
  time
420
466
  }
421
467
  transactions {
@@ -485,7 +531,6 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
485
531
  cb
486
532
  cfei
487
533
  cfsi
488
- croo
489
534
  div
490
535
  divi
491
536
  ecr1
@@ -568,6 +613,9 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
568
613
  ccp {
569
614
  ...DependentCostFragment
570
615
  }
616
+ croo {
617
+ ...DependentCostFragment
618
+ }
571
619
  csiz {
572
620
  ...DependentCostFragment
573
621
  }
@@ -690,14 +738,6 @@ var NodeInfoFragmentFragmentDoc = import_graphql_tag.default`
690
738
  maxTx
691
739
  maxDepth
692
740
  nodeVersion
693
- peers {
694
- id
695
- addresses
696
- clientVersion
697
- blockHeight
698
- lastHeartbeatMs
699
- appScore
700
- }
701
741
  }
702
742
  `;
703
743
  var GetVersionDocument = import_graphql_tag.default`
@@ -732,13 +772,9 @@ var GetTransactionWithReceiptsDocument = import_graphql_tag.default`
732
772
  query getTransactionWithReceipts($transactionId: TransactionId!) {
733
773
  transaction(id: $transactionId) {
734
774
  ...transactionFragment
735
- receipts {
736
- ...receiptFragment
737
- }
738
775
  }
739
776
  }
740
- ${TransactionFragmentFragmentDoc}
741
- ${ReceiptFragmentFragmentDoc}`;
777
+ ${TransactionFragmentFragmentDoc}`;
742
778
  var GetTransactionsDocument = import_graphql_tag.default`
743
779
  query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
744
780
  transactions(after: $after, before: $before, first: $first, last: $last) {
@@ -866,6 +902,20 @@ var GetBalanceDocument = import_graphql_tag.default`
866
902
  }
867
903
  }
868
904
  ${BalanceFragmentFragmentDoc}`;
905
+ var GetLatestGasPriceDocument = import_graphql_tag.default`
906
+ query getLatestGasPrice {
907
+ latestGasPrice {
908
+ gasPrice
909
+ }
910
+ }
911
+ `;
912
+ var EstimateGasPriceDocument = import_graphql_tag.default`
913
+ query estimateGasPrice($blockHorizon: U32!) {
914
+ estimateGasPrice(blockHorizon: $blockHorizon) {
915
+ gasPrice
916
+ }
917
+ }
918
+ `;
869
919
  var GetBalancesDocument = import_graphql_tag.default`
870
920
  query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
871
921
  balances(
@@ -920,12 +970,12 @@ var GetMessageStatusDocument = import_graphql_tag.default`
920
970
  }
921
971
  `;
922
972
  var DryRunDocument = import_graphql_tag.default`
923
- mutation dryRun($encodedTransaction: HexString!, $utxoValidation: Boolean) {
924
- dryRun(tx: $encodedTransaction, utxoValidation: $utxoValidation) {
925
- ...receiptFragment
973
+ mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean) {
974
+ dryRun(txs: $encodedTransactions, utxoValidation: $utxoValidation) {
975
+ ...dryRunTransactionExecutionStatusFragment
926
976
  }
927
977
  }
928
- ${ReceiptFragmentFragmentDoc}`;
978
+ ${DryRunTransactionExecutionStatusFragmentFragmentDoc}`;
929
979
  var SubmitDocument = import_graphql_tag.default`
930
980
  mutation submit($encodedTransaction: HexString!) {
931
981
  submit(tx: $encodedTransaction) {
@@ -1008,6 +1058,12 @@ function getSdk(requester) {
1008
1058
  getBalance(variables, options) {
1009
1059
  return requester(GetBalanceDocument, variables, options);
1010
1060
  },
1061
+ getLatestGasPrice(variables, options) {
1062
+ return requester(GetLatestGasPriceDocument, variables, options);
1063
+ },
1064
+ estimateGasPrice(variables, options) {
1065
+ return requester(EstimateGasPriceDocument, variables, options);
1066
+ },
1011
1067
  getBalances(variables, options) {
1012
1068
  return requester(GetBalancesDocument, variables, options);
1013
1069
  },
@@ -1168,7 +1224,7 @@ var MemoryCache = class {
1168
1224
  };
1169
1225
 
1170
1226
  // src/providers/transaction-request/input.ts
1171
- var import_configs = require("@fuel-ts/address/configs");
1227
+ var import_configs2 = require("@fuel-ts/address/configs");
1172
1228
  var import_errors3 = require("@fuel-ts/errors");
1173
1229
  var import_math2 = require("@fuel-ts/math");
1174
1230
  var import_transactions = require("@fuel-ts/transactions");
@@ -1191,7 +1247,6 @@ var inputify = (value) => {
1191
1247
  txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
1192
1248
  },
1193
1249
  witnessIndex: value.witnessIndex,
1194
- maturity: value.maturity ?? 0,
1195
1250
  predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
1196
1251
  predicateLength: predicate.length,
1197
1252
  predicateDataLength: predicateData.length,
@@ -1202,10 +1257,10 @@ var inputify = (value) => {
1202
1257
  case import_transactions.InputType.Contract: {
1203
1258
  return {
1204
1259
  type: import_transactions.InputType.Contract,
1205
- txID: import_configs.ZeroBytes32,
1260
+ txID: import_configs2.ZeroBytes32,
1206
1261
  outputIndex: 0,
1207
- balanceRoot: import_configs.ZeroBytes32,
1208
- stateRoot: import_configs.ZeroBytes32,
1262
+ balanceRoot: import_configs2.ZeroBytes32,
1263
+ stateRoot: import_configs2.ZeroBytes32,
1209
1264
  txPointer: {
1210
1265
  blockHeight: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(0, 8)),
1211
1266
  txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
@@ -1243,7 +1298,7 @@ var inputify = (value) => {
1243
1298
  };
1244
1299
 
1245
1300
  // src/providers/transaction-request/output.ts
1246
- var import_configs2 = require("@fuel-ts/address/configs");
1301
+ var import_configs3 = require("@fuel-ts/address/configs");
1247
1302
  var import_errors4 = require("@fuel-ts/errors");
1248
1303
  var import_math3 = require("@fuel-ts/math");
1249
1304
  var import_transactions2 = require("@fuel-ts/transactions");
@@ -1263,8 +1318,8 @@ var outputify = (value) => {
1263
1318
  return {
1264
1319
  type: import_transactions2.OutputType.Contract,
1265
1320
  inputIndex: value.inputIndex,
1266
- balanceRoot: import_configs2.ZeroBytes32,
1267
- stateRoot: import_configs2.ZeroBytes32
1321
+ balanceRoot: import_configs3.ZeroBytes32,
1322
+ stateRoot: import_configs3.ZeroBytes32
1268
1323
  };
1269
1324
  }
1270
1325
  case import_transactions2.OutputType.Change: {
@@ -1278,9 +1333,9 @@ var outputify = (value) => {
1278
1333
  case import_transactions2.OutputType.Variable: {
1279
1334
  return {
1280
1335
  type: import_transactions2.OutputType.Variable,
1281
- to: import_configs2.ZeroBytes32,
1336
+ to: import_configs3.ZeroBytes32,
1282
1337
  amount: (0, import_math3.bn)(0),
1283
- assetId: import_configs2.ZeroBytes32
1338
+ assetId: import_configs3.ZeroBytes32
1284
1339
  };
1285
1340
  }
1286
1341
  case import_transactions2.OutputType.ContractCreated: {
@@ -1301,10 +1356,11 @@ var outputify = (value) => {
1301
1356
 
1302
1357
  // src/providers/transaction-request/transaction-request.ts
1303
1358
  var import_address = require("@fuel-ts/address");
1304
- var import_configs5 = require("@fuel-ts/address/configs");
1305
- var import_math6 = require("@fuel-ts/math");
1306
- var import_transactions5 = require("@fuel-ts/transactions");
1359
+ var import_configs7 = require("@fuel-ts/address/configs");
1360
+ var import_math7 = require("@fuel-ts/math");
1361
+ var import_transactions6 = require("@fuel-ts/transactions");
1307
1362
  var import_utils9 = require("@fuel-ts/utils");
1363
+ var import_ethers = require("ethers");
1308
1364
 
1309
1365
  // src/providers/resource.ts
1310
1366
  var isRawCoin = (resource) => "utxoId" in resource;
@@ -1313,13 +1369,13 @@ var isCoin = (resource) => "id" in resource;
1313
1369
  var isMessage = (resource) => "recipient" in resource;
1314
1370
 
1315
1371
  // src/providers/utils/receipts.ts
1316
- var import_configs3 = require("@fuel-ts/address/configs");
1372
+ var import_configs4 = require("@fuel-ts/address/configs");
1317
1373
  var import_errors5 = require("@fuel-ts/errors");
1318
1374
  var import_math4 = require("@fuel-ts/math");
1319
1375
  var import_transactions3 = require("@fuel-ts/transactions");
1320
- var import_configs4 = require("@fuel-ts/transactions/configs");
1376
+ var import_configs5 = require("@fuel-ts/transactions/configs");
1321
1377
  var import_utils5 = require("@fuel-ts/utils");
1322
- var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions3.ReceiptType.Revert && receipt.val.toString("hex") === import_configs4.FAILED_TRANSFER_TO_ADDRESS_SIGNAL;
1378
+ var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions3.ReceiptType.Revert && receipt.val.toString("hex") === import_configs5.FAILED_TRANSFER_TO_ADDRESS_SIGNAL;
1323
1379
  var doesReceiptHaveMissingContractId = (receipt) => receipt.type === import_transactions3.ReceiptType.Panic && receipt.contractId !== "0x0000000000000000000000000000000000000000000000000000000000000000";
1324
1380
  var getReceiptsWithMissingData = (receipts) => receipts.reduce(
1325
1381
  (memo, receipt) => {
@@ -1336,15 +1392,15 @@ var getReceiptsWithMissingData = (receipts) => receipts.reduce(
1336
1392
  missingOutputContractIds: []
1337
1393
  }
1338
1394
  );
1339
- var hexOrZero = (hex) => hex || import_configs3.ZeroBytes32;
1395
+ var hexOrZero = (hex) => hex || import_configs4.ZeroBytes32;
1340
1396
  function assembleReceiptByType(receipt) {
1341
1397
  const { receiptType } = receipt;
1342
1398
  switch (receiptType) {
1343
1399
  case "CALL" /* Call */: {
1344
1400
  const callReceipt = {
1345
1401
  type: import_transactions3.ReceiptType.Call,
1346
- from: hexOrZero(receipt.contract?.id),
1347
- to: hexOrZero(receipt?.to?.id),
1402
+ from: hexOrZero(receipt.id || receipt.contractId),
1403
+ to: hexOrZero(receipt?.to),
1348
1404
  amount: (0, import_math4.bn)(receipt.amount),
1349
1405
  assetId: hexOrZero(receipt.assetId),
1350
1406
  gas: (0, import_math4.bn)(receipt.gas),
@@ -1358,7 +1414,7 @@ function assembleReceiptByType(receipt) {
1358
1414
  case "RETURN" /* Return */: {
1359
1415
  const returnReceipt = {
1360
1416
  type: import_transactions3.ReceiptType.Return,
1361
- id: hexOrZero(receipt.contract?.id),
1417
+ id: hexOrZero(receipt.id || receipt.contractId),
1362
1418
  val: (0, import_math4.bn)(receipt.val),
1363
1419
  pc: (0, import_math4.bn)(receipt.pc),
1364
1420
  is: (0, import_math4.bn)(receipt.is)
@@ -1368,7 +1424,7 @@ function assembleReceiptByType(receipt) {
1368
1424
  case "RETURN_DATA" /* ReturnData */: {
1369
1425
  const returnDataReceipt = {
1370
1426
  type: import_transactions3.ReceiptType.ReturnData,
1371
- id: hexOrZero(receipt.contract?.id),
1427
+ id: hexOrZero(receipt.id || receipt.contractId),
1372
1428
  ptr: (0, import_math4.bn)(receipt.ptr),
1373
1429
  len: (0, import_math4.bn)(receipt.len),
1374
1430
  digest: hexOrZero(receipt.digest),
@@ -1380,7 +1436,7 @@ function assembleReceiptByType(receipt) {
1380
1436
  case "PANIC" /* Panic */: {
1381
1437
  const panicReceipt = {
1382
1438
  type: import_transactions3.ReceiptType.Panic,
1383
- id: hexOrZero(receipt.contract?.id),
1439
+ id: hexOrZero(receipt.id),
1384
1440
  reason: (0, import_math4.bn)(receipt.reason),
1385
1441
  pc: (0, import_math4.bn)(receipt.pc),
1386
1442
  is: (0, import_math4.bn)(receipt.is),
@@ -1391,7 +1447,7 @@ function assembleReceiptByType(receipt) {
1391
1447
  case "REVERT" /* Revert */: {
1392
1448
  const revertReceipt = {
1393
1449
  type: import_transactions3.ReceiptType.Revert,
1394
- id: hexOrZero(receipt.contract?.id),
1450
+ id: hexOrZero(receipt.id || receipt.contractId),
1395
1451
  val: (0, import_math4.bn)(receipt.ra),
1396
1452
  pc: (0, import_math4.bn)(receipt.pc),
1397
1453
  is: (0, import_math4.bn)(receipt.is)
@@ -1401,7 +1457,7 @@ function assembleReceiptByType(receipt) {
1401
1457
  case "LOG" /* Log */: {
1402
1458
  const logReceipt = {
1403
1459
  type: import_transactions3.ReceiptType.Log,
1404
- id: hexOrZero(receipt.contract?.id),
1460
+ id: hexOrZero(receipt.id || receipt.contractId),
1405
1461
  val0: (0, import_math4.bn)(receipt.ra),
1406
1462
  val1: (0, import_math4.bn)(receipt.rb),
1407
1463
  val2: (0, import_math4.bn)(receipt.rc),
@@ -1414,7 +1470,7 @@ function assembleReceiptByType(receipt) {
1414
1470
  case "LOG_DATA" /* LogData */: {
1415
1471
  const logDataReceipt = {
1416
1472
  type: import_transactions3.ReceiptType.LogData,
1417
- id: hexOrZero(receipt.contract?.id),
1473
+ id: hexOrZero(receipt.id || receipt.contractId),
1418
1474
  val0: (0, import_math4.bn)(receipt.ra),
1419
1475
  val1: (0, import_math4.bn)(receipt.rb),
1420
1476
  ptr: (0, import_math4.bn)(receipt.ptr),
@@ -1428,8 +1484,8 @@ function assembleReceiptByType(receipt) {
1428
1484
  case "TRANSFER" /* Transfer */: {
1429
1485
  const transferReceipt = {
1430
1486
  type: import_transactions3.ReceiptType.Transfer,
1431
- from: hexOrZero(receipt.contract?.id),
1432
- to: hexOrZero(receipt.toAddress || receipt?.to?.id),
1487
+ from: hexOrZero(receipt.id || receipt.contractId),
1488
+ to: hexOrZero(receipt.toAddress || receipt?.to),
1433
1489
  amount: (0, import_math4.bn)(receipt.amount),
1434
1490
  assetId: hexOrZero(receipt.assetId),
1435
1491
  pc: (0, import_math4.bn)(receipt.pc),
@@ -1440,8 +1496,8 @@ function assembleReceiptByType(receipt) {
1440
1496
  case "TRANSFER_OUT" /* TransferOut */: {
1441
1497
  const transferOutReceipt = {
1442
1498
  type: import_transactions3.ReceiptType.TransferOut,
1443
- from: hexOrZero(receipt.contract?.id),
1444
- to: hexOrZero(receipt.toAddress || receipt.to?.id),
1499
+ from: hexOrZero(receipt.id || receipt.contractId),
1500
+ to: hexOrZero(receipt.toAddress || receipt.to),
1445
1501
  amount: (0, import_math4.bn)(receipt.amount),
1446
1502
  assetId: hexOrZero(receipt.assetId),
1447
1503
  pc: (0, import_math4.bn)(receipt.pc),
@@ -1484,7 +1540,7 @@ function assembleReceiptByType(receipt) {
1484
1540
  return receiptMessageOut;
1485
1541
  }
1486
1542
  case "MINT" /* Mint */: {
1487
- const contractId = hexOrZero(receipt.contract?.id);
1543
+ const contractId = hexOrZero(receipt.id || receipt.contractId);
1488
1544
  const subId = hexOrZero(receipt.subId);
1489
1545
  const assetId = import_transactions3.ReceiptMintCoder.getAssetId(contractId, subId);
1490
1546
  const mintReceipt = {
@@ -1499,7 +1555,7 @@ function assembleReceiptByType(receipt) {
1499
1555
  return mintReceipt;
1500
1556
  }
1501
1557
  case "BURN" /* Burn */: {
1502
- const contractId = hexOrZero(receipt.contract?.id);
1558
+ const contractId = hexOrZero(receipt.id || receipt.contractId);
1503
1559
  const subId = hexOrZero(receipt.subId);
1504
1560
  const assetId = import_transactions3.ReceiptBurnCoder.getAssetId(contractId, subId);
1505
1561
  const burnReceipt = {
@@ -1584,7 +1640,6 @@ var buildBlockExplorerUrl = (options = {}) => {
1584
1640
  var import_math5 = require("@fuel-ts/math");
1585
1641
  var import_transactions4 = require("@fuel-ts/transactions");
1586
1642
  var import_utils6 = require("@fuel-ts/utils");
1587
- var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => (0, import_math5.bn)(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
1588
1643
  var getGasUsedFromReceipts = (receipts) => {
1589
1644
  const scriptResult = receipts.filter(
1590
1645
  (receipt) => receipt.type === import_transactions4.ReceiptType.ScriptResult
@@ -1605,18 +1660,28 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
1605
1660
  }
1606
1661
  function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
1607
1662
  const witnessCache = [];
1608
- const totalGas = inputs.reduce((total, input) => {
1663
+ const chargeableInputs = inputs.filter((input) => {
1664
+ const isCoinOrMessage = "owner" in input || "sender" in input;
1665
+ if (isCoinOrMessage) {
1666
+ if ("predicate" in input && input.predicate && input.predicate !== "0x") {
1667
+ return true;
1668
+ }
1669
+ if (!witnessCache.includes(input.witnessIndex)) {
1670
+ witnessCache.push(input.witnessIndex);
1671
+ return true;
1672
+ }
1673
+ }
1674
+ return false;
1675
+ });
1676
+ const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
1677
+ const totalGas = chargeableInputs.reduce((total, input) => {
1609
1678
  if ("predicate" in input && input.predicate && input.predicate !== "0x") {
1610
1679
  return total.add(
1611
- resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization).add(resolveGasDependentCosts((0, import_utils6.arrayify)(input.predicate).length, gasCosts.contractRoot)).add((0, import_math5.bn)(input.predicateGasUsed))
1680
+ vmInitializationCost.add(resolveGasDependentCosts((0, import_utils6.arrayify)(input.predicate).length, gasCosts.contractRoot)).add((0, import_math5.bn)(input.predicateGasUsed))
1612
1681
  );
1613
1682
  }
1614
- if ("witnessIndex" in input && !witnessCache.includes(input.witnessIndex)) {
1615
- witnessCache.push(input.witnessIndex);
1616
- return total.add(gasCosts.ecr1);
1617
- }
1618
- return total;
1619
- }, (0, import_math5.bn)());
1683
+ return total.add(gasCosts.ecr1);
1684
+ }, (0, import_math5.bn)(0));
1620
1685
  return totalGas;
1621
1686
  }
1622
1687
  function getMinGas(params) {
@@ -1628,12 +1693,20 @@ function getMinGas(params) {
1628
1693
  return minGas;
1629
1694
  }
1630
1695
  function getMaxGas(params) {
1631
- const { gasPerByte, witnessesLength, witnessLimit, minGas, gasLimit = (0, import_math5.bn)(0) } = params;
1696
+ const {
1697
+ gasPerByte,
1698
+ witnessesLength,
1699
+ witnessLimit,
1700
+ minGas,
1701
+ gasLimit = (0, import_math5.bn)(0),
1702
+ maxGasPerTx
1703
+ } = params;
1632
1704
  let remainingAllowedWitnessGas = (0, import_math5.bn)(0);
1633
1705
  if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
1634
1706
  remainingAllowedWitnessGas = (0, import_math5.bn)(witnessLimit).sub(witnessesLength).mul(gasPerByte);
1635
1707
  }
1636
- return remainingAllowedWitnessGas.add(minGas).add(gasLimit);
1708
+ const maxGas = remainingAllowedWitnessGas.add(minGas).add(gasLimit);
1709
+ return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
1637
1710
  }
1638
1711
  function calculateMetadataGasForTxCreate({
1639
1712
  gasCosts,
@@ -1655,6 +1728,10 @@ function calculateMetadataGasForTxScript({
1655
1728
  }) {
1656
1729
  return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
1657
1730
  }
1731
+ var calculateGasFee = (params) => {
1732
+ const { gas, gasPrice, priceFactor, tip } = params;
1733
+ return gas.mul(gasPrice).div(priceFactor).add(tip);
1734
+ };
1658
1735
 
1659
1736
  // src/providers/utils/json.ts
1660
1737
  var import_utils7 = require("@fuel-ts/utils");
@@ -1696,6 +1773,78 @@ function sleep(time) {
1696
1773
  });
1697
1774
  }
1698
1775
 
1776
+ // src/providers/utils/extract-tx-error.ts
1777
+ var import_errors7 = require("@fuel-ts/errors");
1778
+ var import_math6 = require("@fuel-ts/math");
1779
+ var import_transactions5 = require("@fuel-ts/transactions");
1780
+ var import_configs6 = require("@fuel-ts/transactions/configs");
1781
+ var assemblePanicError = (status) => {
1782
+ let errorMessage = `The transaction reverted with reason: "${status.reason}".`;
1783
+ const reason = status.reason;
1784
+ if (import_configs6.PANIC_REASONS.includes(status.reason)) {
1785
+ errorMessage = `${errorMessage}
1786
+
1787
+ You can read more about this error at:
1788
+
1789
+ ${import_configs6.PANIC_DOC_URL}#variant.${status.reason}`;
1790
+ }
1791
+ return { errorMessage, reason };
1792
+ };
1793
+ var stringify = (obj) => JSON.stringify(obj, null, 2);
1794
+ var assembleRevertError = (receipts, logs) => {
1795
+ let errorMessage = "The transaction reverted with an unknown reason.";
1796
+ const revertReceipt = receipts.find(({ type }) => type === import_transactions5.ReceiptType.Revert);
1797
+ let reason = "";
1798
+ if (revertReceipt) {
1799
+ const reasonHex = (0, import_math6.bn)(revertReceipt.val).toHex();
1800
+ switch (reasonHex) {
1801
+ case import_configs6.FAILED_REQUIRE_SIGNAL: {
1802
+ reason = "require";
1803
+ errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(logs[0]) : "an error."}.`;
1804
+ break;
1805
+ }
1806
+ case import_configs6.FAILED_ASSERT_EQ_SIGNAL: {
1807
+ const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
1808
+ reason = "assert_eq";
1809
+ errorMessage = `The transaction reverted because of an "assert_eq" statement${sufix}`;
1810
+ break;
1811
+ }
1812
+ case import_configs6.FAILED_ASSERT_NE_SIGNAL: {
1813
+ const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
1814
+ reason = "assert_ne";
1815
+ errorMessage = `The transaction reverted because of an "assert_ne" statement${sufix}`;
1816
+ break;
1817
+ }
1818
+ case import_configs6.FAILED_ASSERT_SIGNAL:
1819
+ reason = "assert";
1820
+ errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
1821
+ break;
1822
+ case import_configs6.FAILED_TRANSFER_TO_ADDRESS_SIGNAL:
1823
+ reason = "MissingOutputChange";
1824
+ errorMessage = `The transaction reverted because it's missing an "OutputChange".`;
1825
+ break;
1826
+ default:
1827
+ reason = "unknown";
1828
+ errorMessage = `The transaction reverted with an unknown reason: ${revertReceipt.val}`;
1829
+ }
1830
+ }
1831
+ return { errorMessage, reason };
1832
+ };
1833
+ var extractTxError = (params) => {
1834
+ const { receipts, status, logs } = params;
1835
+ const isPanic = receipts.some(({ type }) => type === import_transactions5.ReceiptType.Panic);
1836
+ const isRevert = receipts.some(({ type }) => type === import_transactions5.ReceiptType.Revert);
1837
+ const { errorMessage, reason } = status?.type === "FailureStatus" && isPanic ? assemblePanicError(status) : assembleRevertError(receipts, logs);
1838
+ const metadata = {
1839
+ logs,
1840
+ receipts,
1841
+ panic: isPanic,
1842
+ revert: isRevert,
1843
+ reason
1844
+ };
1845
+ return new import_errors7.FuelError(import_errors7.ErrorCode.SCRIPT_REVERTED, errorMessage, metadata);
1846
+ };
1847
+
1699
1848
  // src/providers/transaction-request/errors.ts
1700
1849
  var ChangeOutputCollisionError = class extends Error {
1701
1850
  name = "ChangeOutputCollisionError";
@@ -1731,7 +1880,7 @@ var witnessify = (value) => {
1731
1880
  // src/providers/transaction-request/transaction-request.ts
1732
1881
  var BaseTransactionRequest = class {
1733
1882
  /** Gas price for transaction */
1734
- gasPrice;
1883
+ tip;
1735
1884
  /** Block until which tx cannot be included */
1736
1885
  maturity;
1737
1886
  /** The maximum fee payable by this transaction using BASE_ASSET. */
@@ -1744,50 +1893,46 @@ var BaseTransactionRequest = class {
1744
1893
  outputs = [];
1745
1894
  /** List of witnesses */
1746
1895
  witnesses = [];
1747
- /** Base asset ID - should be fetched from the chain */
1748
- baseAssetId = import_configs5.ZeroBytes32;
1749
1896
  /**
1750
1897
  * Constructor for initializing a base transaction request.
1751
1898
  *
1752
1899
  * @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
1753
1900
  */
1754
1901
  constructor({
1755
- gasPrice,
1902
+ tip,
1756
1903
  maturity,
1757
1904
  maxFee,
1758
1905
  witnessLimit,
1759
1906
  inputs,
1760
1907
  outputs,
1761
- witnesses,
1762
- baseAssetId
1908
+ witnesses
1763
1909
  } = {}) {
1764
- this.gasPrice = (0, import_math6.bn)(gasPrice);
1910
+ this.tip = (0, import_math7.bn)(tip);
1765
1911
  this.maturity = maturity ?? 0;
1766
- this.witnessLimit = witnessLimit ? (0, import_math6.bn)(witnessLimit) : void 0;
1767
- this.maxFee = maxFee ? (0, import_math6.bn)(maxFee) : void 0;
1912
+ this.witnessLimit = witnessLimit ? (0, import_math7.bn)(witnessLimit) : void 0;
1913
+ this.maxFee = maxFee ? (0, import_math7.bn)(maxFee) : void 0;
1768
1914
  this.inputs = inputs ?? [];
1769
1915
  this.outputs = outputs ?? [];
1770
1916
  this.witnesses = witnesses ?? [];
1771
- this.baseAssetId = baseAssetId ?? import_configs5.ZeroBytes32;
1772
1917
  }
1773
1918
  static getPolicyMeta(req) {
1774
1919
  let policyTypes = 0;
1775
1920
  const policies = [];
1776
- if (req.gasPrice) {
1777
- policyTypes += import_transactions5.PolicyType.GasPrice;
1778
- policies.push({ data: req.gasPrice, type: import_transactions5.PolicyType.GasPrice });
1921
+ if (req.tip) {
1922
+ policyTypes += import_transactions6.PolicyType.Tip;
1923
+ policies.push({ data: req.tip, type: import_transactions6.PolicyType.Tip });
1779
1924
  }
1780
1925
  if (req.witnessLimit) {
1781
- policyTypes += import_transactions5.PolicyType.WitnessLimit;
1782
- policies.push({ data: req.witnessLimit, type: import_transactions5.PolicyType.WitnessLimit });
1926
+ policyTypes += import_transactions6.PolicyType.WitnessLimit;
1927
+ policies.push({ data: req.witnessLimit, type: import_transactions6.PolicyType.WitnessLimit });
1783
1928
  }
1784
1929
  if (req.maturity > 0) {
1785
- policyTypes += import_transactions5.PolicyType.Maturity;
1786
- policies.push({ data: req.maturity, type: import_transactions5.PolicyType.Maturity });
1930
+ policyTypes += import_transactions6.PolicyType.Maturity;
1931
+ policies.push({ data: req.maturity, type: import_transactions6.PolicyType.Maturity });
1787
1932
  }
1788
1933
  if (req.maxFee) {
1789
- policyTypes += import_transactions5.PolicyType.MaxFee;
1790
- policies.push({ data: req.maxFee, type: import_transactions5.PolicyType.MaxFee });
1934
+ policyTypes += import_transactions6.PolicyType.MaxFee;
1935
+ policies.push({ data: req.maxFee, type: import_transactions6.PolicyType.MaxFee });
1791
1936
  }
1792
1937
  return {
1793
1938
  policyTypes,
@@ -1821,7 +1966,7 @@ var BaseTransactionRequest = class {
1821
1966
  * @returns The transaction bytes.
1822
1967
  */
1823
1968
  toTransactionBytes() {
1824
- return new import_transactions5.TransactionCoder().encode(this.toTransaction());
1969
+ return new import_transactions6.TransactionCoder().encode(this.toTransaction());
1825
1970
  }
1826
1971
  /**
1827
1972
  * @hidden
@@ -1861,7 +2006,7 @@ var BaseTransactionRequest = class {
1861
2006
  * @returns The index of the created witness.
1862
2007
  */
1863
2008
  addEmptyWitness() {
1864
- this.addWitness((0, import_utils9.concat)([import_configs5.ZeroBytes32, import_configs5.ZeroBytes32]));
2009
+ this.addWitness((0, import_utils9.concat)([import_configs7.ZeroBytes32, import_configs7.ZeroBytes32]));
1865
2010
  return this.witnesses.length - 1;
1866
2011
  }
1867
2012
  /**
@@ -1912,7 +2057,7 @@ var BaseTransactionRequest = class {
1912
2057
  */
1913
2058
  getCoinInputs() {
1914
2059
  return this.inputs.filter(
1915
- (input) => input.type === import_transactions5.InputType.Coin
2060
+ (input) => input.type === import_transactions6.InputType.Coin
1916
2061
  );
1917
2062
  }
1918
2063
  /**
@@ -1922,7 +2067,7 @@ var BaseTransactionRequest = class {
1922
2067
  */
1923
2068
  getCoinOutputs() {
1924
2069
  return this.outputs.filter(
1925
- (output) => output.type === import_transactions5.OutputType.Coin
2070
+ (output) => output.type === import_transactions6.OutputType.Coin
1926
2071
  );
1927
2072
  }
1928
2073
  /**
@@ -1932,7 +2077,7 @@ var BaseTransactionRequest = class {
1932
2077
  */
1933
2078
  getChangeOutputs() {
1934
2079
  return this.outputs.filter(
1935
- (output) => output.type === import_transactions5.OutputType.Change
2080
+ (output) => output.type === import_transactions6.OutputType.Change
1936
2081
  );
1937
2082
  }
1938
2083
  /**
@@ -1944,9 +2089,9 @@ var BaseTransactionRequest = class {
1944
2089
  const ownerAddress = (0, import_address.addressify)(owner);
1945
2090
  const found = this.inputs.find((input) => {
1946
2091
  switch (input.type) {
1947
- case import_transactions5.InputType.Coin:
2092
+ case import_transactions6.InputType.Coin:
1948
2093
  return (0, import_utils9.hexlify)(input.owner) === ownerAddress.toB256();
1949
- case import_transactions5.InputType.Message:
2094
+ case import_transactions6.InputType.Message:
1950
2095
  return (0, import_utils9.hexlify)(input.recipient) === ownerAddress.toB256();
1951
2096
  default:
1952
2097
  return false;
@@ -1962,10 +2107,10 @@ var BaseTransactionRequest = class {
1962
2107
  * @param predicate - Predicate bytes.
1963
2108
  * @param predicateData - Predicate data bytes.
1964
2109
  */
1965
- addCoinInput(coin, predicate) {
2110
+ addCoinInput(coin) {
1966
2111
  const { assetId, owner, amount } = coin;
1967
2112
  let witnessIndex;
1968
- if (predicate) {
2113
+ if (coin.predicate) {
1969
2114
  witnessIndex = 0;
1970
2115
  } else {
1971
2116
  witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
@@ -1975,14 +2120,12 @@ var BaseTransactionRequest = class {
1975
2120
  }
1976
2121
  const input = {
1977
2122
  ...coin,
1978
- type: import_transactions5.InputType.Coin,
2123
+ type: import_transactions6.InputType.Coin,
1979
2124
  owner: owner.toB256(),
1980
2125
  amount,
1981
2126
  assetId,
1982
2127
  txPointer: "0x00000000000000000000000000000000",
1983
- witnessIndex,
1984
- predicate: predicate?.bytes,
1985
- predicateData: predicate?.predicateDataBytes
2128
+ witnessIndex
1986
2129
  };
1987
2130
  this.pushInput(input);
1988
2131
  this.addChangeOutput(owner, assetId);
@@ -1993,11 +2136,13 @@ var BaseTransactionRequest = class {
1993
2136
  *
1994
2137
  * @param message - Message resource.
1995
2138
  * @param predicate - Predicate bytes.
2139
+ * @param predicateData - Predicate data bytes.
1996
2140
  */
1997
- addMessageInput(message, predicate) {
2141
+ addMessageInput(message) {
1998
2142
  const { recipient, sender, amount } = message;
2143
+ const assetId = import_configs7.BaseAssetId;
1999
2144
  let witnessIndex;
2000
- if (predicate) {
2145
+ if (message.predicate) {
2001
2146
  witnessIndex = 0;
2002
2147
  } else {
2003
2148
  witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
@@ -2007,16 +2152,14 @@ var BaseTransactionRequest = class {
2007
2152
  }
2008
2153
  const input = {
2009
2154
  ...message,
2010
- type: import_transactions5.InputType.Message,
2155
+ type: import_transactions6.InputType.Message,
2011
2156
  sender: sender.toB256(),
2012
2157
  recipient: recipient.toB256(),
2013
2158
  amount,
2014
- witnessIndex,
2015
- predicate: predicate?.bytes,
2016
- predicateData: predicate?.predicateDataBytes
2159
+ witnessIndex
2017
2160
  };
2018
2161
  this.pushInput(input);
2019
- this.addChangeOutput(recipient, this.baseAssetId);
2162
+ this.addChangeOutput(recipient, assetId);
2020
2163
  }
2021
2164
  /**
2022
2165
  * Adds a single resource to the transaction by adding a coin/message input and a
@@ -2044,32 +2187,6 @@ var BaseTransactionRequest = class {
2044
2187
  resources.forEach((resource) => this.addResource(resource));
2045
2188
  return this;
2046
2189
  }
2047
- /**
2048
- * Adds multiple resources to the transaction by adding coin/message inputs and change
2049
- * outputs from the related assetIds.
2050
- *
2051
- * @param resources - The resources to add.
2052
- * @returns This transaction.
2053
- */
2054
- addPredicateResource(resource, predicate) {
2055
- if (isCoin(resource)) {
2056
- this.addCoinInput(resource, predicate);
2057
- } else {
2058
- this.addMessageInput(resource, predicate);
2059
- }
2060
- return this;
2061
- }
2062
- /**
2063
- * Adds multiple predicate coin/message inputs to the transaction and change outputs
2064
- * from the related assetIds.
2065
- *
2066
- * @param resources - The resources to add.
2067
- * @returns This transaction.
2068
- */
2069
- addPredicateResources(resources, predicate) {
2070
- resources.forEach((resource) => this.addPredicateResource(resource, predicate));
2071
- return this;
2072
- }
2073
2190
  /**
2074
2191
  * Adds a coin output to the transaction.
2075
2192
  *
@@ -2077,12 +2194,12 @@ var BaseTransactionRequest = class {
2077
2194
  * @param amount - Amount of coin.
2078
2195
  * @param assetId - Asset ID of coin.
2079
2196
  */
2080
- addCoinOutput(to, amount, assetId) {
2197
+ addCoinOutput(to, amount, assetId = import_configs7.BaseAssetId) {
2081
2198
  this.pushOutput({
2082
- type: import_transactions5.OutputType.Coin,
2199
+ type: import_transactions6.OutputType.Coin,
2083
2200
  to: (0, import_address.addressify)(to).toB256(),
2084
2201
  amount,
2085
- assetId: assetId ?? this.baseAssetId
2202
+ assetId
2086
2203
  });
2087
2204
  return this;
2088
2205
  }
@@ -2095,7 +2212,7 @@ var BaseTransactionRequest = class {
2095
2212
  addCoinOutputs(to, quantities) {
2096
2213
  quantities.map(coinQuantityfy).forEach((quantity) => {
2097
2214
  this.pushOutput({
2098
- type: import_transactions5.OutputType.Coin,
2215
+ type: import_transactions6.OutputType.Coin,
2099
2216
  to: (0, import_address.addressify)(to).toB256(),
2100
2217
  amount: quantity.amount,
2101
2218
  assetId: quantity.assetId
@@ -2109,15 +2226,15 @@ var BaseTransactionRequest = class {
2109
2226
  * @param to - Address of the owner.
2110
2227
  * @param assetId - Asset ID of coin.
2111
2228
  */
2112
- addChangeOutput(to, assetId) {
2229
+ addChangeOutput(to, assetId = import_configs7.BaseAssetId) {
2113
2230
  const changeOutput = this.getChangeOutputs().find(
2114
2231
  (output) => (0, import_utils9.hexlify)(output.assetId) === assetId
2115
2232
  );
2116
2233
  if (!changeOutput) {
2117
2234
  this.pushOutput({
2118
- type: import_transactions5.OutputType.Change,
2235
+ type: import_transactions6.OutputType.Change,
2119
2236
  to: (0, import_address.addressify)(to).toB256(),
2120
- assetId: assetId ?? this.baseAssetId
2237
+ assetId
2121
2238
  });
2122
2239
  }
2123
2240
  }
@@ -2149,7 +2266,7 @@ var BaseTransactionRequest = class {
2149
2266
  }
2150
2267
  calculateMaxGas(chainInfo, minGas) {
2151
2268
  const { consensusParameters } = chainInfo;
2152
- const { gasPerByte } = consensusParameters;
2269
+ const { gasPerByte, maxGasPerTx } = consensusParameters;
2153
2270
  const witnessesLength = this.toTransaction().witnesses.reduce(
2154
2271
  (acc, wit) => acc + wit.dataLength,
2155
2272
  0
@@ -2158,7 +2275,8 @@ var BaseTransactionRequest = class {
2158
2275
  gasPerByte,
2159
2276
  minGas,
2160
2277
  witnessesLength,
2161
- witnessLimit: this.witnessLimit
2278
+ witnessLimit: this.witnessLimit,
2279
+ maxGasPerTx
2162
2280
  });
2163
2281
  }
2164
2282
  /**
@@ -2168,12 +2286,6 @@ var BaseTransactionRequest = class {
2168
2286
  * @param quantities - CoinQuantity Array.
2169
2287
  */
2170
2288
  fundWithFakeUtxos(quantities, resourcesOwner) {
2171
- let idCounter = 0;
2172
- const generateId = () => {
2173
- const counterString = String(idCounter++);
2174
- const id = import_configs5.ZeroBytes32.slice(0, -counterString.length).concat(counterString);
2175
- return id;
2176
- };
2177
2289
  const findAssetInput = (assetId) => this.inputs.find((input) => {
2178
2290
  if ("assetId" in input) {
2179
2291
  return input.assetId === assetId;
@@ -2182,24 +2294,27 @@ var BaseTransactionRequest = class {
2182
2294
  });
2183
2295
  const updateAssetInput = (assetId, quantity) => {
2184
2296
  const assetInput = findAssetInput(assetId);
2297
+ let usedQuantity = quantity;
2298
+ if (assetId === import_configs7.BaseAssetId) {
2299
+ usedQuantity = (0, import_math7.bn)("1000000000000000000");
2300
+ }
2185
2301
  if (assetInput && "assetId" in assetInput) {
2186
- assetInput.id = generateId();
2187
- assetInput.amount = quantity;
2302
+ assetInput.id = (0, import_utils9.hexlify)((0, import_ethers.randomBytes)(33));
2303
+ assetInput.amount = usedQuantity;
2188
2304
  } else {
2189
2305
  this.addResources([
2190
2306
  {
2191
- id: generateId(),
2192
- amount: quantity,
2307
+ id: (0, import_utils9.hexlify)((0, import_ethers.randomBytes)(33)),
2308
+ amount: usedQuantity,
2193
2309
  assetId,
2194
2310
  owner: resourcesOwner || import_address.Address.fromRandom(),
2195
- maturity: 0,
2196
- blockCreated: (0, import_math6.bn)(1),
2197
- txCreatedIdx: (0, import_math6.bn)(1)
2311
+ blockCreated: (0, import_math7.bn)(1),
2312
+ txCreatedIdx: (0, import_math7.bn)(1)
2198
2313
  }
2199
2314
  ]);
2200
2315
  }
2201
2316
  };
2202
- updateAssetInput(this.baseAssetId, (0, import_math6.bn)(1e11));
2317
+ updateAssetInput(import_configs7.BaseAssetId, (0, import_math7.bn)(1e11));
2203
2318
  quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
2204
2319
  }
2205
2320
  /**
@@ -2210,7 +2325,7 @@ var BaseTransactionRequest = class {
2210
2325
  */
2211
2326
  getCoinOutputsQuantities() {
2212
2327
  const coinsQuantities = this.getCoinOutputs().map(({ amount, assetId }) => ({
2213
- amount: (0, import_math6.bn)(amount),
2328
+ amount: (0, import_math7.bn)(amount),
2214
2329
  assetId: assetId.toString()
2215
2330
  }));
2216
2331
  return coinsQuantities;
@@ -2224,72 +2339,81 @@ var BaseTransactionRequest = class {
2224
2339
  toJSON() {
2225
2340
  return normalizeJSON(this);
2226
2341
  }
2227
- updatePredicateInputs(inputs) {
2342
+ updatePredicateGasUsed(inputs) {
2228
2343
  this.inputs.forEach((i) => {
2229
2344
  let correspondingInput;
2230
2345
  switch (i.type) {
2231
- case import_transactions5.InputType.Coin:
2232
- correspondingInput = inputs.find((x) => x.type === import_transactions5.InputType.Coin && x.owner === i.owner);
2346
+ case import_transactions6.InputType.Coin:
2347
+ correspondingInput = inputs.find((x) => x.type === import_transactions6.InputType.Coin && x.owner === i.owner);
2233
2348
  break;
2234
- case import_transactions5.InputType.Message:
2349
+ case import_transactions6.InputType.Message:
2235
2350
  correspondingInput = inputs.find(
2236
- (x) => x.type === import_transactions5.InputType.Message && x.sender === i.sender
2351
+ (x) => x.type === import_transactions6.InputType.Message && x.sender === i.sender
2237
2352
  );
2238
2353
  break;
2239
2354
  default:
2240
2355
  return;
2241
2356
  }
2242
- if (correspondingInput && "predicateGasUsed" in correspondingInput && (0, import_math6.bn)(correspondingInput.predicateGasUsed).gt(0)) {
2357
+ if (correspondingInput && "predicateGasUsed" in correspondingInput && (0, import_math7.bn)(correspondingInput.predicateGasUsed).gt(0)) {
2243
2358
  i.predicate = correspondingInput.predicate;
2244
2359
  i.predicateData = correspondingInput.predicateData;
2245
2360
  i.predicateGasUsed = correspondingInput.predicateGasUsed;
2246
2361
  }
2247
2362
  });
2248
2363
  }
2364
+ shiftPredicateData() {
2365
+ this.inputs.forEach((input) => {
2366
+ if ("predicateData" in input && "paddPredicateData" in input && typeof input.paddPredicateData === "function") {
2367
+ input.predicateData = input.paddPredicateData(
2368
+ BaseTransactionRequest.getPolicyMeta(this).policies.length
2369
+ );
2370
+ }
2371
+ });
2372
+ }
2249
2373
  };
2250
2374
 
2251
2375
  // src/providers/transaction-request/create-transaction-request.ts
2252
- var import_configs7 = require("@fuel-ts/address/configs");
2253
- var import_math8 = require("@fuel-ts/math");
2254
- var import_transactions7 = require("@fuel-ts/transactions");
2376
+ var import_configs9 = require("@fuel-ts/address/configs");
2377
+ var import_math9 = require("@fuel-ts/math");
2378
+ var import_transactions8 = require("@fuel-ts/transactions");
2255
2379
  var import_utils13 = require("@fuel-ts/utils");
2256
2380
 
2257
2381
  // src/providers/transaction-request/hash-transaction.ts
2258
- var import_configs6 = require("@fuel-ts/address/configs");
2382
+ var import_configs8 = require("@fuel-ts/address/configs");
2259
2383
  var import_hasher = require("@fuel-ts/hasher");
2260
- var import_math7 = require("@fuel-ts/math");
2261
- var import_transactions6 = require("@fuel-ts/transactions");
2384
+ var import_math8 = require("@fuel-ts/math");
2385
+ var import_transactions7 = require("@fuel-ts/transactions");
2262
2386
  var import_utils11 = require("@fuel-ts/utils");
2263
2387
  var import_ramda2 = require("ramda");
2264
2388
  function hashTransaction(transactionRequest, chainId) {
2265
2389
  const transaction = transactionRequest.toTransaction();
2266
- if (transaction.type === import_transactions6.TransactionType.Script) {
2267
- transaction.receiptsRoot = import_configs6.ZeroBytes32;
2390
+ if (transaction.type === import_transactions7.TransactionType.Script) {
2391
+ transaction.receiptsRoot = import_configs8.ZeroBytes32;
2268
2392
  }
2269
2393
  transaction.inputs = transaction.inputs.map((input) => {
2270
2394
  const inputClone = (0, import_ramda2.clone)(input);
2271
2395
  switch (inputClone.type) {
2272
- case import_transactions6.InputType.Coin: {
2396
+ case import_transactions7.InputType.Coin: {
2273
2397
  inputClone.txPointer = {
2274
2398
  blockHeight: 0,
2275
2399
  txIndex: 0
2276
2400
  };
2277
- inputClone.predicateGasUsed = (0, import_math7.bn)(0);
2401
+ inputClone.predicateGasUsed = (0, import_math8.bn)(0);
2278
2402
  return inputClone;
2279
2403
  }
2280
- case import_transactions6.InputType.Message: {
2281
- inputClone.predicateGasUsed = (0, import_math7.bn)(0);
2404
+ case import_transactions7.InputType.Message: {
2405
+ inputClone.predicateGasUsed = (0, import_math8.bn)(0);
2282
2406
  return inputClone;
2283
2407
  }
2284
- case import_transactions6.InputType.Contract: {
2408
+ case import_transactions7.InputType.Contract: {
2285
2409
  inputClone.txPointer = {
2286
2410
  blockHeight: 0,
2287
2411
  txIndex: 0
2288
2412
  };
2289
- inputClone.txID = import_configs6.ZeroBytes32;
2413
+ inputClone.txID = import_configs8.ZeroBytes32;
2290
2414
  inputClone.outputIndex = 0;
2291
- inputClone.balanceRoot = import_configs6.ZeroBytes32;
2292
- inputClone.stateRoot = import_configs6.ZeroBytes32;
2415
+ inputClone.balanceRoot = import_configs8.ZeroBytes32;
2416
+ inputClone.stateRoot = import_configs8.ZeroBytes32;
2293
2417
  return inputClone;
2294
2418
  }
2295
2419
  default:
@@ -2299,19 +2423,19 @@ function hashTransaction(transactionRequest, chainId) {
2299
2423
  transaction.outputs = transaction.outputs.map((output) => {
2300
2424
  const outputClone = (0, import_ramda2.clone)(output);
2301
2425
  switch (outputClone.type) {
2302
- case import_transactions6.OutputType.Contract: {
2303
- outputClone.balanceRoot = import_configs6.ZeroBytes32;
2304
- outputClone.stateRoot = import_configs6.ZeroBytes32;
2426
+ case import_transactions7.OutputType.Contract: {
2427
+ outputClone.balanceRoot = import_configs8.ZeroBytes32;
2428
+ outputClone.stateRoot = import_configs8.ZeroBytes32;
2305
2429
  return outputClone;
2306
2430
  }
2307
- case import_transactions6.OutputType.Change: {
2308
- outputClone.amount = (0, import_math7.bn)(0);
2431
+ case import_transactions7.OutputType.Change: {
2432
+ outputClone.amount = (0, import_math8.bn)(0);
2309
2433
  return outputClone;
2310
2434
  }
2311
- case import_transactions6.OutputType.Variable: {
2312
- outputClone.to = import_configs6.ZeroBytes32;
2313
- outputClone.amount = (0, import_math7.bn)(0);
2314
- outputClone.assetId = import_configs6.ZeroBytes32;
2435
+ case import_transactions7.OutputType.Variable: {
2436
+ outputClone.to = import_configs8.ZeroBytes32;
2437
+ outputClone.amount = (0, import_math8.bn)(0);
2438
+ outputClone.assetId = import_configs8.ZeroBytes32;
2315
2439
  return outputClone;
2316
2440
  }
2317
2441
  default:
@@ -2321,7 +2445,7 @@ function hashTransaction(transactionRequest, chainId) {
2321
2445
  transaction.witnessesCount = 0;
2322
2446
  transaction.witnesses = [];
2323
2447
  const chainIdBytes = (0, import_hasher.uint64ToBytesBE)(chainId);
2324
- const concatenatedData = (0, import_utils11.concat)([chainIdBytes, new import_transactions6.TransactionCoder().encode(transaction)]);
2448
+ const concatenatedData = (0, import_utils11.concat)([chainIdBytes, new import_transactions7.TransactionCoder().encode(transaction)]);
2325
2449
  return (0, import_hasher.sha256)(concatenatedData);
2326
2450
  }
2327
2451
 
@@ -2357,7 +2481,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2357
2481
  return new this(obj);
2358
2482
  }
2359
2483
  /** Type of the transaction */
2360
- type = import_transactions7.TransactionType.Create;
2484
+ type = import_transactions8.TransactionType.Create;
2361
2485
  /** Witness index of contract bytecode to create */
2362
2486
  bytecodeWitnessIndex;
2363
2487
  /** Salt */
@@ -2377,7 +2501,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2377
2501
  } = {}) {
2378
2502
  super(rest);
2379
2503
  this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
2380
- this.salt = (0, import_utils13.hexlify)(salt ?? import_configs7.ZeroBytes32);
2504
+ this.salt = (0, import_utils13.hexlify)(salt ?? import_configs9.ZeroBytes32);
2381
2505
  this.storageSlots = [...storageSlots ?? []];
2382
2506
  }
2383
2507
  /**
@@ -2390,12 +2514,12 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2390
2514
  const bytecodeWitnessIndex = this.bytecodeWitnessIndex;
2391
2515
  const storageSlots = this.storageSlots?.map(storageSlotify) ?? [];
2392
2516
  return {
2393
- type: import_transactions7.TransactionType.Create,
2517
+ type: import_transactions8.TransactionType.Create,
2394
2518
  ...baseTransaction,
2395
2519
  bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
2396
2520
  bytecodeWitnessIndex,
2397
2521
  storageSlotsCount: storageSlots.length,
2398
- salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs7.ZeroBytes32,
2522
+ salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs9.ZeroBytes32,
2399
2523
  storageSlots
2400
2524
  };
2401
2525
  }
@@ -2406,7 +2530,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2406
2530
  */
2407
2531
  getContractCreatedOutputs() {
2408
2532
  return this.outputs.filter(
2409
- (output) => output.type === import_transactions7.OutputType.ContractCreated
2533
+ (output) => output.type === import_transactions8.OutputType.ContractCreated
2410
2534
  );
2411
2535
  }
2412
2536
  /**
@@ -2427,14 +2551,14 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2427
2551
  */
2428
2552
  addContractCreatedOutput(contractId, stateRoot) {
2429
2553
  this.pushOutput({
2430
- type: import_transactions7.OutputType.ContractCreated,
2554
+ type: import_transactions8.OutputType.ContractCreated,
2431
2555
  contractId,
2432
2556
  stateRoot
2433
2557
  });
2434
2558
  }
2435
2559
  metadataGas(gasCosts) {
2436
2560
  return calculateMetadataGasForTxCreate({
2437
- contractBytesSize: (0, import_math8.bn)((0, import_utils13.arrayify)(this.witnesses[this.bytecodeWitnessIndex] || "0x").length),
2561
+ contractBytesSize: (0, import_math9.bn)((0, import_utils13.arrayify)(this.witnesses[this.bytecodeWitnessIndex] || "0x").length),
2438
2562
  gasCosts,
2439
2563
  stateRootSize: this.storageSlots.length,
2440
2564
  txBytesSize: this.byteSize()
@@ -2445,9 +2569,9 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2445
2569
  // src/providers/transaction-request/script-transaction-request.ts
2446
2570
  var import_abi_coder = require("@fuel-ts/abi-coder");
2447
2571
  var import_address2 = require("@fuel-ts/address");
2448
- var import_configs8 = require("@fuel-ts/address/configs");
2449
- var import_math9 = require("@fuel-ts/math");
2450
- var import_transactions8 = require("@fuel-ts/transactions");
2572
+ var import_configs10 = require("@fuel-ts/address/configs");
2573
+ var import_math10 = require("@fuel-ts/math");
2574
+ var import_transactions9 = require("@fuel-ts/transactions");
2451
2575
  var import_utils15 = require("@fuel-ts/utils");
2452
2576
 
2453
2577
  // src/providers/transaction-request/scripts.ts
@@ -2485,7 +2609,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2485
2609
  return new this(obj);
2486
2610
  }
2487
2611
  /** Type of the transaction */
2488
- type = import_transactions8.TransactionType.Script;
2612
+ type = import_transactions9.TransactionType.Script;
2489
2613
  /** Gas limit for transaction */
2490
2614
  gasLimit;
2491
2615
  /** Script to execute */
@@ -2500,7 +2624,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2500
2624
  */
2501
2625
  constructor({ script, scriptData, gasLimit, ...rest } = {}) {
2502
2626
  super(rest);
2503
- this.gasLimit = (0, import_math9.bn)(gasLimit);
2627
+ this.gasLimit = (0, import_math10.bn)(gasLimit);
2504
2628
  this.script = (0, import_utils15.arrayify)(script ?? returnZeroScript.bytes);
2505
2629
  this.scriptData = (0, import_utils15.arrayify)(scriptData ?? returnZeroScript.encodeScriptData());
2506
2630
  this.abis = rest.abis;
@@ -2514,12 +2638,12 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2514
2638
  const script = (0, import_utils15.arrayify)(this.script ?? "0x");
2515
2639
  const scriptData = (0, import_utils15.arrayify)(this.scriptData ?? "0x");
2516
2640
  return {
2517
- type: import_transactions8.TransactionType.Script,
2641
+ type: import_transactions9.TransactionType.Script,
2518
2642
  scriptGasLimit: this.gasLimit,
2519
2643
  ...super.getBaseTransaction(),
2520
2644
  scriptLength: script.length,
2521
2645
  scriptDataLength: scriptData.length,
2522
- receiptsRoot: import_configs8.ZeroBytes32,
2646
+ receiptsRoot: import_configs10.ZeroBytes32,
2523
2647
  script: (0, import_utils15.hexlify)(script),
2524
2648
  scriptData: (0, import_utils15.hexlify)(scriptData)
2525
2649
  };
@@ -2531,7 +2655,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2531
2655
  */
2532
2656
  getContractInputs() {
2533
2657
  return this.inputs.filter(
2534
- (input) => input.type === import_transactions8.InputType.Contract
2658
+ (input) => input.type === import_transactions9.InputType.Contract
2535
2659
  );
2536
2660
  }
2537
2661
  /**
@@ -2541,7 +2665,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2541
2665
  */
2542
2666
  getContractOutputs() {
2543
2667
  return this.outputs.filter(
2544
- (output) => output.type === import_transactions8.OutputType.Contract
2668
+ (output) => output.type === import_transactions9.OutputType.Contract
2545
2669
  );
2546
2670
  }
2547
2671
  /**
@@ -2551,7 +2675,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2551
2675
  */
2552
2676
  getVariableOutputs() {
2553
2677
  return this.outputs.filter(
2554
- (output) => output.type === import_transactions8.OutputType.Variable
2678
+ (output) => output.type === import_transactions9.OutputType.Variable
2555
2679
  );
2556
2680
  }
2557
2681
  /**
@@ -2574,7 +2698,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2574
2698
  let outputsNumber = numberOfVariables;
2575
2699
  while (outputsNumber) {
2576
2700
  this.pushOutput({
2577
- type: import_transactions8.OutputType.Variable
2701
+ type: import_transactions9.OutputType.Variable
2578
2702
  });
2579
2703
  outputsNumber -= 1;
2580
2704
  }
@@ -2582,7 +2706,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2582
2706
  }
2583
2707
  calculateMaxGas(chainInfo, minGas) {
2584
2708
  const { consensusParameters } = chainInfo;
2585
- const { gasPerByte } = consensusParameters;
2709
+ const { gasPerByte, maxGasPerTx } = consensusParameters;
2586
2710
  const witnessesLength = this.toTransaction().witnesses.reduce(
2587
2711
  (acc, wit) => acc + wit.dataLength,
2588
2712
  0
@@ -2592,7 +2716,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2592
2716
  minGas,
2593
2717
  witnessesLength,
2594
2718
  witnessLimit: this.witnessLimit,
2595
- gasLimit: this.gasLimit
2719
+ gasLimit: this.gasLimit,
2720
+ maxGasPerTx
2596
2721
  });
2597
2722
  }
2598
2723
  /**
@@ -2607,12 +2732,12 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2607
2732
  return this;
2608
2733
  }
2609
2734
  const inputIndex = super.pushInput({
2610
- type: import_transactions8.InputType.Contract,
2735
+ type: import_transactions9.InputType.Contract,
2611
2736
  contractId: contractAddress.toB256(),
2612
2737
  txPointer: "0x00000000000000000000000000000000"
2613
2738
  });
2614
2739
  this.pushOutput({
2615
- type: import_transactions8.OutputType.Contract,
2740
+ type: import_transactions9.OutputType.Contract,
2616
2741
  inputIndex
2617
2742
  });
2618
2743
  return this;
@@ -2648,63 +2773,80 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2648
2773
  };
2649
2774
 
2650
2775
  // src/providers/transaction-request/utils.ts
2651
- var import_errors8 = require("@fuel-ts/errors");
2652
- var import_transactions9 = require("@fuel-ts/transactions");
2776
+ var import_errors9 = require("@fuel-ts/errors");
2777
+ var import_transactions10 = require("@fuel-ts/transactions");
2653
2778
  var transactionRequestify = (obj) => {
2654
2779
  if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
2655
2780
  return obj;
2656
2781
  }
2657
2782
  const { type } = obj;
2658
2783
  switch (obj.type) {
2659
- case import_transactions9.TransactionType.Script: {
2784
+ case import_transactions10.TransactionType.Script: {
2660
2785
  return ScriptTransactionRequest.from(obj);
2661
2786
  }
2662
- case import_transactions9.TransactionType.Create: {
2787
+ case import_transactions10.TransactionType.Create: {
2663
2788
  return CreateTransactionRequest.from(obj);
2664
2789
  }
2665
2790
  default: {
2666
- throw new import_errors8.FuelError(import_errors8.ErrorCode.INVALID_TRANSACTION_TYPE, `Invalid transaction type: ${type}.`);
2791
+ throw new import_errors9.FuelError(import_errors9.ErrorCode.INVALID_TRANSACTION_TYPE, `Invalid transaction type: ${type}.`);
2667
2792
  }
2668
2793
  }
2669
2794
  };
2795
+ var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
2796
+ (acc, input) => {
2797
+ if (input.type === import_transactions10.InputType.Coin && input.owner === owner) {
2798
+ acc.utxos.push(input.id);
2799
+ }
2800
+ if (input.type === import_transactions10.InputType.Message && input.recipient === owner) {
2801
+ acc.messages.push(input.nonce);
2802
+ }
2803
+ return acc;
2804
+ },
2805
+ {
2806
+ utxos: [],
2807
+ messages: []
2808
+ }
2809
+ );
2670
2810
 
2671
2811
  // src/providers/transaction-response/transaction-response.ts
2672
- var import_errors12 = require("@fuel-ts/errors");
2673
- var import_math13 = require("@fuel-ts/math");
2674
- var import_transactions16 = require("@fuel-ts/transactions");
2675
- var import_utils21 = require("@fuel-ts/utils");
2812
+ var import_errors13 = require("@fuel-ts/errors");
2813
+ var import_math15 = require("@fuel-ts/math");
2814
+ var import_transactions18 = require("@fuel-ts/transactions");
2815
+ var import_utils20 = require("@fuel-ts/utils");
2676
2816
 
2677
2817
  // src/providers/transaction-summary/assemble-transaction-summary.ts
2678
- var import_utils19 = require("@fuel-ts/utils");
2818
+ var import_math14 = require("@fuel-ts/math");
2819
+ var import_transactions16 = require("@fuel-ts/transactions");
2820
+ var import_utils18 = require("@fuel-ts/utils");
2679
2821
 
2680
2822
  // src/providers/transaction-summary/calculate-transaction-fee.ts
2681
- var import_math10 = require("@fuel-ts/math");
2682
- var import_transactions10 = require("@fuel-ts/transactions");
2823
+ var import_math11 = require("@fuel-ts/math");
2824
+ var import_transactions11 = require("@fuel-ts/transactions");
2683
2825
  var import_utils16 = require("@fuel-ts/utils");
2684
2826
  var calculateTransactionFee = (params) => {
2685
2827
  const {
2686
- gasUsed,
2828
+ gasPrice,
2687
2829
  rawPayload,
2688
- consensusParameters: { gasCosts, feeParams }
2830
+ tip,
2831
+ consensusParameters: { gasCosts, feeParams, maxGasPerTx }
2689
2832
  } = params;
2690
- const gasPerByte = (0, import_math10.bn)(feeParams.gasPerByte);
2691
- const gasPriceFactor = (0, import_math10.bn)(feeParams.gasPriceFactor);
2833
+ const gasPerByte = (0, import_math11.bn)(feeParams.gasPerByte);
2834
+ const gasPriceFactor = (0, import_math11.bn)(feeParams.gasPriceFactor);
2692
2835
  const transactionBytes = (0, import_utils16.arrayify)(rawPayload);
2693
- const [transaction] = new import_transactions10.TransactionCoder().decode(transactionBytes, 0);
2694
- if (transaction.type === import_transactions10.TransactionType.Mint) {
2836
+ const [transaction] = new import_transactions11.TransactionCoder().decode(transactionBytes, 0);
2837
+ if (transaction.type === import_transactions11.TransactionType.Mint) {
2695
2838
  return {
2696
- fee: (0, import_math10.bn)(0),
2697
- minFee: (0, import_math10.bn)(0),
2698
- maxFee: (0, import_math10.bn)(0),
2699
- feeFromGasUsed: (0, import_math10.bn)(0)
2839
+ fee: (0, import_math11.bn)(0),
2840
+ minFee: (0, import_math11.bn)(0),
2841
+ maxFee: (0, import_math11.bn)(0)
2700
2842
  };
2701
2843
  }
2702
2844
  const { type, witnesses, inputs, policies } = transaction;
2703
- let metadataGas = (0, import_math10.bn)(0);
2704
- let gasLimit = (0, import_math10.bn)(0);
2705
- if (type === import_transactions10.TransactionType.Create) {
2845
+ let metadataGas = (0, import_math11.bn)(0);
2846
+ let gasLimit = (0, import_math11.bn)(0);
2847
+ if (type === import_transactions11.TransactionType.Create) {
2706
2848
  const { bytecodeWitnessIndex, storageSlots } = transaction;
2707
- const contractBytesSize = (0, import_math10.bn)((0, import_utils16.arrayify)(witnesses[bytecodeWitnessIndex].data).length);
2849
+ const contractBytesSize = (0, import_math11.bn)((0, import_utils16.arrayify)(witnesses[bytecodeWitnessIndex].data).length);
2708
2850
  metadataGas = calculateMetadataGasForTxCreate({
2709
2851
  contractBytesSize,
2710
2852
  gasCosts,
@@ -2723,42 +2865,49 @@ var calculateTransactionFee = (params) => {
2723
2865
  }
2724
2866
  const minGas = getMinGas({
2725
2867
  gasCosts,
2726
- gasPerByte: (0, import_math10.bn)(gasPerByte),
2868
+ gasPerByte: (0, import_math11.bn)(gasPerByte),
2727
2869
  inputs,
2728
2870
  metadataGas,
2729
2871
  txBytesSize: transactionBytes.length
2730
2872
  });
2731
- const gasPrice = (0, import_math10.bn)(policies.find((policy) => policy.type === import_transactions10.PolicyType.GasPrice)?.data);
2732
- const witnessLimit = policies.find((policy) => policy.type === import_transactions10.PolicyType.WitnessLimit)?.data;
2873
+ const witnessLimit = policies.find((policy) => policy.type === import_transactions11.PolicyType.WitnessLimit)?.data;
2733
2874
  const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
2734
2875
  const maxGas = getMaxGas({
2735
2876
  gasPerByte,
2736
2877
  minGas,
2737
2878
  witnessesLength,
2738
2879
  gasLimit,
2739
- witnessLimit
2880
+ witnessLimit,
2881
+ maxGasPerTx
2882
+ });
2883
+ const minFee = calculateGasFee({
2884
+ gasPrice,
2885
+ gas: minGas,
2886
+ priceFactor: gasPriceFactor,
2887
+ tip
2888
+ });
2889
+ const maxFee = calculateGasFee({
2890
+ gasPrice,
2891
+ gas: maxGas,
2892
+ priceFactor: gasPriceFactor,
2893
+ tip
2740
2894
  });
2741
- const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
2742
- const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
2743
- const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
2744
- const fee = minFee.add(feeFromGasUsed);
2745
2895
  return {
2746
- fee,
2747
2896
  minFee,
2748
2897
  maxFee,
2749
- feeFromGasUsed
2898
+ fee: maxFee
2750
2899
  };
2751
2900
  };
2752
2901
 
2753
2902
  // src/providers/transaction-summary/operations.ts
2754
- var import_configs9 = require("@fuel-ts/address/configs");
2755
- var import_errors10 = require("@fuel-ts/errors");
2756
- var import_math12 = require("@fuel-ts/math");
2757
- var import_transactions13 = require("@fuel-ts/transactions");
2903
+ var import_configs11 = require("@fuel-ts/address/configs");
2904
+ var import_errors11 = require("@fuel-ts/errors");
2905
+ var import_math13 = require("@fuel-ts/math");
2906
+ var import_transactions14 = require("@fuel-ts/transactions");
2758
2907
 
2759
2908
  // src/providers/transaction-summary/call.ts
2760
2909
  var import_abi_coder2 = require("@fuel-ts/abi-coder");
2761
- var import_math11 = require("@fuel-ts/math");
2910
+ var import_math12 = require("@fuel-ts/math");
2762
2911
  var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
2763
2912
  const abiInterface = new import_abi_coder2.Interface(abi);
2764
2913
  const callFunctionSelector = receipt.param1.toHex(8);
@@ -2767,7 +2916,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
2767
2916
  let encodedArgs;
2768
2917
  if (functionFragment.isInputDataPointer) {
2769
2918
  if (rawPayload) {
2770
- const argsOffset = (0, import_math11.bn)(receipt.param2).sub((0, import_abi_coder2.calculateVmTxMemory)({ maxInputs: maxInputs.toNumber() })).toNumber();
2919
+ const argsOffset = (0, import_math12.bn)(receipt.param2).sub((0, import_abi_coder2.calculateVmTxMemory)({ maxInputs: maxInputs.toNumber() })).toNumber();
2771
2920
  encodedArgs = `0x${rawPayload.slice(2).slice(argsOffset * 2)}`;
2772
2921
  }
2773
2922
  } else {
@@ -2801,8 +2950,8 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
2801
2950
  };
2802
2951
 
2803
2952
  // src/providers/transaction-summary/input.ts
2804
- var import_errors9 = require("@fuel-ts/errors");
2805
- var import_transactions11 = require("@fuel-ts/transactions");
2953
+ var import_errors10 = require("@fuel-ts/errors");
2954
+ var import_transactions12 = require("@fuel-ts/transactions");
2806
2955
  function getInputsByTypes(inputs, types) {
2807
2956
  return inputs.filter((i) => types.includes(i.type));
2808
2957
  }
@@ -2810,16 +2959,16 @@ function getInputsByType(inputs, type) {
2810
2959
  return inputs.filter((i) => i.type === type);
2811
2960
  }
2812
2961
  function getInputsCoin(inputs) {
2813
- return getInputsByType(inputs, import_transactions11.InputType.Coin);
2962
+ return getInputsByType(inputs, import_transactions12.InputType.Coin);
2814
2963
  }
2815
2964
  function getInputsMessage(inputs) {
2816
- return getInputsByType(inputs, import_transactions11.InputType.Message);
2965
+ return getInputsByType(inputs, import_transactions12.InputType.Message);
2817
2966
  }
2818
2967
  function getInputsCoinAndMessage(inputs) {
2819
- return getInputsByTypes(inputs, [import_transactions11.InputType.Coin, import_transactions11.InputType.Message]);
2968
+ return getInputsByTypes(inputs, [import_transactions12.InputType.Coin, import_transactions12.InputType.Message]);
2820
2969
  }
2821
2970
  function getInputsContract(inputs) {
2822
- return getInputsByType(inputs, import_transactions11.InputType.Contract);
2971
+ return getInputsByType(inputs, import_transactions12.InputType.Contract);
2823
2972
  }
2824
2973
  function getInputFromAssetId(inputs, assetId) {
2825
2974
  const coinInputs = getInputsCoin(inputs);
@@ -2838,43 +2987,43 @@ function getInputContractFromIndex(inputs, inputIndex) {
2838
2987
  if (!contractInput) {
2839
2988
  return void 0;
2840
2989
  }
2841
- if (contractInput.type !== import_transactions11.InputType.Contract) {
2842
- throw new import_errors9.FuelError(
2843
- import_errors9.ErrorCode.INVALID_TRANSACTION_INPUT,
2990
+ if (contractInput.type !== import_transactions12.InputType.Contract) {
2991
+ throw new import_errors10.FuelError(
2992
+ import_errors10.ErrorCode.INVALID_TRANSACTION_INPUT,
2844
2993
  `Contract input should be of type 'contract'.`
2845
2994
  );
2846
2995
  }
2847
2996
  return contractInput;
2848
2997
  }
2849
2998
  function getInputAccountAddress(input) {
2850
- if (input.type === import_transactions11.InputType.Coin) {
2999
+ if (input.type === import_transactions12.InputType.Coin) {
2851
3000
  return input.owner.toString();
2852
3001
  }
2853
- if (input.type === import_transactions11.InputType.Message) {
3002
+ if (input.type === import_transactions12.InputType.Message) {
2854
3003
  return input.recipient.toString();
2855
3004
  }
2856
3005
  return "";
2857
3006
  }
2858
3007
 
2859
3008
  // src/providers/transaction-summary/output.ts
2860
- var import_transactions12 = require("@fuel-ts/transactions");
3009
+ var import_transactions13 = require("@fuel-ts/transactions");
2861
3010
  function getOutputsByType(outputs, type) {
2862
3011
  return outputs.filter((o) => o.type === type);
2863
3012
  }
2864
3013
  function getOutputsContractCreated(outputs) {
2865
- return getOutputsByType(outputs, import_transactions12.OutputType.ContractCreated);
3014
+ return getOutputsByType(outputs, import_transactions13.OutputType.ContractCreated);
2866
3015
  }
2867
3016
  function getOutputsCoin(outputs) {
2868
- return getOutputsByType(outputs, import_transactions12.OutputType.Coin);
3017
+ return getOutputsByType(outputs, import_transactions13.OutputType.Coin);
2869
3018
  }
2870
3019
  function getOutputsChange(outputs) {
2871
- return getOutputsByType(outputs, import_transactions12.OutputType.Change);
3020
+ return getOutputsByType(outputs, import_transactions13.OutputType.Change);
2872
3021
  }
2873
3022
  function getOutputsContract(outputs) {
2874
- return getOutputsByType(outputs, import_transactions12.OutputType.Contract);
3023
+ return getOutputsByType(outputs, import_transactions13.OutputType.Contract);
2875
3024
  }
2876
3025
  function getOutputsVariable(outputs) {
2877
- return getOutputsByType(outputs, import_transactions12.OutputType.Variable);
3026
+ return getOutputsByType(outputs, import_transactions13.OutputType.Variable);
2878
3027
  }
2879
3028
 
2880
3029
  // src/providers/transaction-summary/types.ts
@@ -2921,15 +3070,15 @@ function getReceiptsByType(receipts, type) {
2921
3070
  }
2922
3071
  function getTransactionTypeName(transactionType) {
2923
3072
  switch (transactionType) {
2924
- case import_transactions13.TransactionType.Mint:
3073
+ case import_transactions14.TransactionType.Mint:
2925
3074
  return "Mint" /* Mint */;
2926
- case import_transactions13.TransactionType.Create:
3075
+ case import_transactions14.TransactionType.Create:
2927
3076
  return "Create" /* Create */;
2928
- case import_transactions13.TransactionType.Script:
3077
+ case import_transactions14.TransactionType.Script:
2929
3078
  return "Script" /* Script */;
2930
3079
  default:
2931
- throw new import_errors10.FuelError(
2932
- import_errors10.ErrorCode.INVALID_TRANSACTION_TYPE,
3080
+ throw new import_errors11.FuelError(
3081
+ import_errors11.ErrorCode.INVALID_TRANSACTION_TYPE,
2933
3082
  `Invalid transaction type: ${transactionType}.`
2934
3083
  );
2935
3084
  }
@@ -2951,10 +3100,10 @@ function hasSameAssetId(a) {
2951
3100
  return (b) => a.assetId === b.assetId;
2952
3101
  }
2953
3102
  function getReceiptsCall(receipts) {
2954
- return getReceiptsByType(receipts, import_transactions13.ReceiptType.Call);
3103
+ return getReceiptsByType(receipts, import_transactions14.ReceiptType.Call);
2955
3104
  }
2956
3105
  function getReceiptsMessageOut(receipts) {
2957
- return getReceiptsByType(receipts, import_transactions13.ReceiptType.MessageOut);
3106
+ return getReceiptsByType(receipts, import_transactions14.ReceiptType.MessageOut);
2958
3107
  }
2959
3108
  var mergeAssets = (op1, op2) => {
2960
3109
  const assets1 = op1.assetsSent || [];
@@ -2967,7 +3116,7 @@ var mergeAssets = (op1, op2) => {
2967
3116
  if (!matchingAsset) {
2968
3117
  return asset1;
2969
3118
  }
2970
- const mergedAmount = (0, import_math12.bn)(asset1.amount).add(matchingAsset.amount);
3119
+ const mergedAmount = (0, import_math13.bn)(asset1.amount).add(matchingAsset.amount);
2971
3120
  return { ...asset1, amount: mergedAmount };
2972
3121
  });
2973
3122
  return mergedAssets.concat(filteredAssets);
@@ -2993,7 +3142,7 @@ function addOperation(operations, toAdd) {
2993
3142
  return allOperations;
2994
3143
  }
2995
3144
  function getReceiptsTransferOut(receipts) {
2996
- return getReceiptsByType(receipts, import_transactions13.ReceiptType.TransferOut);
3145
+ return getReceiptsByType(receipts, import_transactions14.ReceiptType.TransferOut);
2997
3146
  }
2998
3147
  function getWithdrawFromFuelOperations({
2999
3148
  inputs,
@@ -3096,7 +3245,7 @@ function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutp
3096
3245
  const { to: toAddress, assetId, amount } = receipt;
3097
3246
  let { from: fromAddress } = receipt;
3098
3247
  const toType = contractInputs.some((input) => input.contractID === toAddress) ? 0 /* contract */ : 1 /* account */;
3099
- if (import_configs9.ZeroBytes32 === fromAddress) {
3248
+ if (import_configs11.ZeroBytes32 === fromAddress) {
3100
3249
  const change = changeOutputs.find((output) => output.assetId === assetId);
3101
3250
  fromAddress = change?.to || fromAddress;
3102
3251
  }
@@ -3153,11 +3302,11 @@ function getTransferOperations({
3153
3302
  });
3154
3303
  const transferReceipts = getReceiptsByType(
3155
3304
  receipts,
3156
- import_transactions13.ReceiptType.Transfer
3305
+ import_transactions14.ReceiptType.Transfer
3157
3306
  );
3158
3307
  const transferOutReceipts = getReceiptsByType(
3159
3308
  receipts,
3160
- import_transactions13.ReceiptType.TransferOut
3309
+ import_transactions14.ReceiptType.TransferOut
3161
3310
  );
3162
3311
  [...transferReceipts, ...transferOutReceipts].forEach((receipt) => {
3163
3312
  const operation = extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs);
@@ -3242,17 +3391,17 @@ function getOperations({
3242
3391
  }
3243
3392
 
3244
3393
  // src/providers/transaction-summary/receipt.ts
3245
- var import_transactions14 = require("@fuel-ts/transactions");
3394
+ var import_transactions15 = require("@fuel-ts/transactions");
3246
3395
  var processGqlReceipt = (gqlReceipt) => {
3247
3396
  const receipt = assembleReceiptByType(gqlReceipt);
3248
3397
  switch (receipt.type) {
3249
- case import_transactions14.ReceiptType.ReturnData: {
3398
+ case import_transactions15.ReceiptType.ReturnData: {
3250
3399
  return {
3251
3400
  ...receipt,
3252
3401
  data: gqlReceipt.data || "0x"
3253
3402
  };
3254
3403
  }
3255
- case import_transactions14.ReceiptType.LogData: {
3404
+ case import_transactions15.ReceiptType.LogData: {
3256
3405
  return {
3257
3406
  ...receipt,
3258
3407
  data: gqlReceipt.data || "0x"
@@ -3265,7 +3414,7 @@ var processGqlReceipt = (gqlReceipt) => {
3265
3414
  var extractMintedAssetsFromReceipts = (receipts) => {
3266
3415
  const mintedAssets = [];
3267
3416
  receipts.forEach((receipt) => {
3268
- if (receipt.type === import_transactions14.ReceiptType.Mint) {
3417
+ if (receipt.type === import_transactions15.ReceiptType.Mint) {
3269
3418
  mintedAssets.push({
3270
3419
  subId: receipt.subId,
3271
3420
  contractId: receipt.contractId,
@@ -3279,7 +3428,7 @@ var extractMintedAssetsFromReceipts = (receipts) => {
3279
3428
  var extractBurnedAssetsFromReceipts = (receipts) => {
3280
3429
  const burnedAssets = [];
3281
3430
  receipts.forEach((receipt) => {
3282
- if (receipt.type === import_transactions14.ReceiptType.Burn) {
3431
+ if (receipt.type === import_transactions15.ReceiptType.Burn) {
3283
3432
  burnedAssets.push({
3284
3433
  subId: receipt.subId,
3285
3434
  contractId: receipt.contractId,
@@ -3292,7 +3441,7 @@ var extractBurnedAssetsFromReceipts = (receipts) => {
3292
3441
  };
3293
3442
 
3294
3443
  // src/providers/transaction-summary/status.ts
3295
- var import_errors11 = require("@fuel-ts/errors");
3444
+ var import_errors12 = require("@fuel-ts/errors");
3296
3445
  var getTransactionStatusName = (gqlStatus) => {
3297
3446
  switch (gqlStatus) {
3298
3447
  case "FailureStatus":
@@ -3304,8 +3453,8 @@ var getTransactionStatusName = (gqlStatus) => {
3304
3453
  case "SqueezedOutStatus":
3305
3454
  return "squeezedout" /* squeezedout */;
3306
3455
  default:
3307
- throw new import_errors11.FuelError(
3308
- import_errors11.ErrorCode.INVALID_TRANSACTION_STATUS,
3456
+ throw new import_errors12.FuelError(
3457
+ import_errors12.ErrorCode.INVALID_TRANSACTION_STATUS,
3309
3458
  `Invalid transaction status: ${gqlStatus}.`
3310
3459
  );
3311
3460
  }
@@ -3360,10 +3509,12 @@ function assembleTransactionSummary(params) {
3360
3509
  gqlTransactionStatus,
3361
3510
  abiMap = {},
3362
3511
  maxInputs,
3363
- gasCosts
3512
+ gasCosts,
3513
+ maxGasPerTx,
3514
+ gasPrice
3364
3515
  } = params;
3365
3516
  const gasUsed = getGasUsedFromReceipts(receipts);
3366
- const rawPayload = (0, import_utils19.hexlify)(transactionBytes);
3517
+ const rawPayload = (0, import_utils18.hexlify)(transactionBytes);
3367
3518
  const operations = getOperations({
3368
3519
  transactionType: transaction.type,
3369
3520
  inputs: transaction.inputs || [],
@@ -3374,11 +3525,14 @@ function assembleTransactionSummary(params) {
3374
3525
  maxInputs
3375
3526
  });
3376
3527
  const typeName = getTransactionTypeName(transaction.type);
3528
+ const tip = (0, import_math14.bn)(transaction.policies?.find((policy) => policy.type === import_transactions16.PolicyType.Tip)?.data);
3377
3529
  const { fee } = calculateTransactionFee({
3378
- gasUsed,
3530
+ gasPrice,
3379
3531
  rawPayload,
3532
+ tip,
3380
3533
  consensusParameters: {
3381
3534
  gasCosts,
3535
+ maxGasPerTx,
3382
3536
  feeParams: {
3383
3537
  gasPerByte,
3384
3538
  gasPriceFactor
@@ -3390,7 +3544,7 @@ function assembleTransactionSummary(params) {
3390
3544
  const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
3391
3545
  let date;
3392
3546
  if (time) {
3393
- date = import_utils19.DateTime.fromTai64(time);
3547
+ date = import_utils18.DateTime.fromTai64(time);
3394
3548
  }
3395
3549
  const transactionSummary = {
3396
3550
  id,
@@ -3418,12 +3572,12 @@ function assembleTransactionSummary(params) {
3418
3572
 
3419
3573
  // src/providers/transaction-response/getDecodedLogs.ts
3420
3574
  var import_abi_coder3 = require("@fuel-ts/abi-coder");
3421
- var import_transactions15 = require("@fuel-ts/transactions");
3575
+ var import_transactions17 = require("@fuel-ts/transactions");
3422
3576
  function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
3423
3577
  return receipts.reduce((logs, receipt) => {
3424
- if (receipt.type === import_transactions15.ReceiptType.LogData || receipt.type === import_transactions15.ReceiptType.Log) {
3578
+ if (receipt.type === import_transactions17.ReceiptType.LogData || receipt.type === import_transactions17.ReceiptType.Log) {
3425
3579
  const interfaceToUse = new import_abi_coder3.Interface(externalAbis[receipt.id] || mainAbi);
3426
- const data = receipt.type === import_transactions15.ReceiptType.Log ? new import_abi_coder3.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
3580
+ const data = receipt.type === import_transactions17.ReceiptType.Log ? new import_abi_coder3.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
3427
3581
  const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
3428
3582
  logs.push(decodedLog);
3429
3583
  }
@@ -3438,7 +3592,7 @@ var TransactionResponse = class {
3438
3592
  /** Current provider */
3439
3593
  provider;
3440
3594
  /** Gas used on the transaction */
3441
- gasUsed = (0, import_math13.bn)(0);
3595
+ gasUsed = (0, import_math15.bn)(0);
3442
3596
  /** The graphql Transaction with receipts object. */
3443
3597
  gqlTransaction;
3444
3598
  abis;
@@ -3496,8 +3650,8 @@ var TransactionResponse = class {
3496
3650
  * @returns The decoded transaction.
3497
3651
  */
3498
3652
  decodeTransaction(transactionWithReceipts) {
3499
- return new import_transactions16.TransactionCoder().decode(
3500
- (0, import_utils21.arrayify)(transactionWithReceipts.rawPayload),
3653
+ return new import_transactions18.TransactionCoder().decode(
3654
+ (0, import_utils20.arrayify)(transactionWithReceipts.rawPayload),
3501
3655
  0
3502
3656
  )?.[0];
3503
3657
  }
@@ -3516,20 +3670,27 @@ var TransactionResponse = class {
3516
3670
  const decodedTransaction = this.decodeTransaction(
3517
3671
  transaction
3518
3672
  );
3519
- const receipts = transaction.receipts?.map(processGqlReceipt) || [];
3520
- const { gasPerByte, gasPriceFactor, gasCosts } = this.provider.getGasConfig();
3673
+ let txReceipts = [];
3674
+ if (transaction?.status && "receipts" in transaction.status) {
3675
+ txReceipts = transaction.status.receipts;
3676
+ }
3677
+ const receipts = txReceipts.map(processGqlReceipt) || [];
3678
+ const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
3679
+ const gasPrice = await this.provider.getLatestGasPrice();
3521
3680
  const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
3522
3681
  const transactionSummary = assembleTransactionSummary({
3523
3682
  id: this.id,
3524
3683
  receipts,
3525
3684
  transaction: decodedTransaction,
3526
- transactionBytes: (0, import_utils21.arrayify)(transaction.rawPayload),
3685
+ transactionBytes: (0, import_utils20.arrayify)(transaction.rawPayload),
3527
3686
  gqlTransactionStatus: transaction.status,
3528
3687
  gasPerByte,
3529
3688
  gasPriceFactor,
3530
3689
  abiMap: contractsAbiMap,
3531
3690
  maxInputs,
3532
- gasCosts
3691
+ gasCosts,
3692
+ maxGasPerTx,
3693
+ gasPrice
3533
3694
  });
3534
3695
  return transactionSummary;
3535
3696
  }
@@ -3543,8 +3704,8 @@ var TransactionResponse = class {
3543
3704
  });
3544
3705
  for await (const { statusChange } of subscription) {
3545
3706
  if (statusChange.type === "SqueezedOutStatus") {
3546
- throw new import_errors12.FuelError(
3547
- import_errors12.ErrorCode.TRANSACTION_SQUEEZED_OUT,
3707
+ throw new import_errors13.FuelError(
3708
+ import_errors13.ErrorCode.TRANSACTION_SQUEEZED_OUT,
3548
3709
  `Transaction Squeezed Out with reason: ${statusChange.reason}`
3549
3710
  );
3550
3711
  }
@@ -3566,14 +3727,26 @@ var TransactionResponse = class {
3566
3727
  gqlTransaction: this.gqlTransaction,
3567
3728
  ...transactionSummary
3568
3729
  };
3730
+ let logs = [];
3569
3731
  if (this.abis) {
3570
- const logs = getDecodedLogs(
3732
+ logs = getDecodedLogs(
3571
3733
  transactionSummary.receipts,
3572
3734
  this.abis.main,
3573
3735
  this.abis.otherContractsAbis
3574
3736
  );
3575
3737
  transactionResult.logs = logs;
3576
3738
  }
3739
+ if (transactionResult.isStatusFailure) {
3740
+ const {
3741
+ receipts,
3742
+ gqlTransaction: { status }
3743
+ } = transactionResult;
3744
+ throw extractTxError({
3745
+ receipts,
3746
+ status,
3747
+ logs
3748
+ });
3749
+ }
3577
3750
  return transactionResult;
3578
3751
  }
3579
3752
  /**
@@ -3582,14 +3755,7 @@ var TransactionResponse = class {
3582
3755
  * @param contractsAbiMap - The contracts ABI map.
3583
3756
  */
3584
3757
  async wait(contractsAbiMap) {
3585
- const result = await this.waitForResult(contractsAbiMap);
3586
- if (result.isStatusFailure) {
3587
- throw new import_errors12.FuelError(
3588
- import_errors12.ErrorCode.TRANSACTION_FAILED,
3589
- `Transaction failed: ${result.gqlTransaction.status.reason}`
3590
- );
3591
- }
3592
- return result;
3758
+ return this.waitForResult(contractsAbiMap);
3593
3759
  }
3594
3760
  };
3595
3761
 
@@ -3651,30 +3817,29 @@ var processGqlChain = (chain) => {
3651
3817
  const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
3652
3818
  return {
3653
3819
  name,
3654
- baseChainHeight: (0, import_math14.bn)(daHeight),
3820
+ baseChainHeight: (0, import_math16.bn)(daHeight),
3655
3821
  consensusParameters: {
3656
- contractMaxSize: (0, import_math14.bn)(contractParams.contractMaxSize),
3657
- maxInputs: (0, import_math14.bn)(txParams.maxInputs),
3658
- maxOutputs: (0, import_math14.bn)(txParams.maxOutputs),
3659
- maxWitnesses: (0, import_math14.bn)(txParams.maxWitnesses),
3660
- maxGasPerTx: (0, import_math14.bn)(txParams.maxGasPerTx),
3661
- maxScriptLength: (0, import_math14.bn)(scriptParams.maxScriptLength),
3662
- maxScriptDataLength: (0, import_math14.bn)(scriptParams.maxScriptDataLength),
3663
- maxStorageSlots: (0, import_math14.bn)(contractParams.maxStorageSlots),
3664
- maxPredicateLength: (0, import_math14.bn)(predicateParams.maxPredicateLength),
3665
- maxPredicateDataLength: (0, import_math14.bn)(predicateParams.maxPredicateDataLength),
3666
- maxGasPerPredicate: (0, import_math14.bn)(predicateParams.maxGasPerPredicate),
3667
- gasPriceFactor: (0, import_math14.bn)(feeParams.gasPriceFactor),
3668
- gasPerByte: (0, import_math14.bn)(feeParams.gasPerByte),
3669
- maxMessageDataLength: (0, import_math14.bn)(predicateParams.maxMessageDataLength),
3670
- chainId: (0, import_math14.bn)(consensusParameters.chainId),
3671
- baseAssetId: consensusParameters.baseAssetId,
3822
+ contractMaxSize: (0, import_math16.bn)(contractParams.contractMaxSize),
3823
+ maxInputs: (0, import_math16.bn)(txParams.maxInputs),
3824
+ maxOutputs: (0, import_math16.bn)(txParams.maxOutputs),
3825
+ maxWitnesses: (0, import_math16.bn)(txParams.maxWitnesses),
3826
+ maxGasPerTx: (0, import_math16.bn)(txParams.maxGasPerTx),
3827
+ maxScriptLength: (0, import_math16.bn)(scriptParams.maxScriptLength),
3828
+ maxScriptDataLength: (0, import_math16.bn)(scriptParams.maxScriptDataLength),
3829
+ maxStorageSlots: (0, import_math16.bn)(contractParams.maxStorageSlots),
3830
+ maxPredicateLength: (0, import_math16.bn)(predicateParams.maxPredicateLength),
3831
+ maxPredicateDataLength: (0, import_math16.bn)(predicateParams.maxPredicateDataLength),
3832
+ maxGasPerPredicate: (0, import_math16.bn)(predicateParams.maxGasPerPredicate),
3833
+ gasPriceFactor: (0, import_math16.bn)(feeParams.gasPriceFactor),
3834
+ gasPerByte: (0, import_math16.bn)(feeParams.gasPerByte),
3835
+ maxMessageDataLength: (0, import_math16.bn)(predicateParams.maxMessageDataLength),
3836
+ chainId: (0, import_math16.bn)(consensusParameters.chainId),
3672
3837
  gasCosts
3673
3838
  },
3674
3839
  gasCosts,
3675
3840
  latestBlock: {
3676
3841
  id: latestBlock.id,
3677
- height: (0, import_math14.bn)(latestBlock.header.height),
3842
+ height: (0, import_math16.bn)(latestBlock.height),
3678
3843
  time: latestBlock.header.time,
3679
3844
  transactions: latestBlock.transactions.map((i) => ({
3680
3845
  id: i.id
@@ -3744,8 +3909,8 @@ var _Provider = class {
3744
3909
  getChain() {
3745
3910
  const chain = _Provider.chainInfoCache[this.url];
3746
3911
  if (!chain) {
3747
- throw new import_errors13.FuelError(
3748
- import_errors13.ErrorCode.CHAIN_INFO_CACHE_EMPTY,
3912
+ throw new import_errors14.FuelError(
3913
+ import_errors14.ErrorCode.CHAIN_INFO_CACHE_EMPTY,
3749
3914
  "Chain info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
3750
3915
  );
3751
3916
  }
@@ -3757,8 +3922,8 @@ var _Provider = class {
3757
3922
  getNode() {
3758
3923
  const node = _Provider.nodeInfoCache[this.url];
3759
3924
  if (!node) {
3760
- throw new import_errors13.FuelError(
3761
- import_errors13.ErrorCode.NODE_INFO_CACHE_EMPTY,
3925
+ throw new import_errors14.FuelError(
3926
+ import_errors14.ErrorCode.NODE_INFO_CACHE_EMPTY,
3762
3927
  "Node info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
3763
3928
  );
3764
3929
  }
@@ -3805,8 +3970,8 @@ var _Provider = class {
3805
3970
  static ensureClientVersionIsSupported(nodeInfo) {
3806
3971
  const { isMajorSupported, isMinorSupported, supportedVersion } = (0, import_versions.checkFuelCoreVersionCompatibility)(nodeInfo.nodeVersion);
3807
3972
  if (!isMajorSupported || !isMinorSupported) {
3808
- throw new import_errors13.FuelError(
3809
- import_errors13.FuelError.CODES.UNSUPPORTED_FUEL_CLIENT_VERSION,
3973
+ throw new import_errors14.FuelError(
3974
+ import_errors14.FuelError.CODES.UNSUPPORTED_FUEL_CLIENT_VERSION,
3810
3975
  `Fuel client version: ${nodeInfo.nodeVersion}, Supported version: ${supportedVersion}`
3811
3976
  );
3812
3977
  }
@@ -3859,7 +4024,7 @@ var _Provider = class {
3859
4024
  name,
3860
4025
  consensusParameters: { chainId }
3861
4026
  } = await this.getChain();
3862
- const network = new import_ethers.Network(name, chainId.toNumber());
4027
+ const network = new import_ethers2.Network(name, chainId.toNumber());
3863
4028
  return Promise.resolve(network);
3864
4029
  }
3865
4030
  /**
@@ -3869,7 +4034,7 @@ var _Provider = class {
3869
4034
  */
3870
4035
  async getBlockNumber() {
3871
4036
  const { chain } = await this.operations.getChain();
3872
- return (0, import_math14.bn)(chain.latestBlock.header.height, 10);
4037
+ return (0, import_math16.bn)(chain.latestBlock.height, 10);
3873
4038
  }
3874
4039
  /**
3875
4040
  * Returns the chain information.
@@ -3879,13 +4044,12 @@ var _Provider = class {
3879
4044
  async fetchNode() {
3880
4045
  const { nodeInfo } = await this.operations.getNodeInfo();
3881
4046
  const processedNodeInfo = {
3882
- maxDepth: (0, import_math14.bn)(nodeInfo.maxDepth),
3883
- maxTx: (0, import_math14.bn)(nodeInfo.maxTx),
3884
- minGasPrice: (0, import_math14.bn)(nodeInfo.minGasPrice),
4047
+ maxDepth: (0, import_math16.bn)(nodeInfo.maxDepth),
4048
+ maxTx: (0, import_math16.bn)(nodeInfo.maxTx),
4049
+ minGasPrice: (0, import_math16.bn)(nodeInfo.minGasPrice),
3885
4050
  nodeVersion: nodeInfo.nodeVersion,
3886
4051
  utxoValidation: nodeInfo.utxoValidation,
3887
- vmBacktrace: nodeInfo.vmBacktrace,
3888
- peers: nodeInfo.peers
4052
+ vmBacktrace: nodeInfo.vmBacktrace
3889
4053
  };
3890
4054
  _Provider.nodeInfoCache[this.url] = processedNodeInfo;
3891
4055
  return processedNodeInfo;
@@ -3911,17 +4075,6 @@ var _Provider = class {
3911
4075
  } = this.getChain();
3912
4076
  return chainId.toNumber();
3913
4077
  }
3914
- /**
3915
- * Returns the base asset ID
3916
- *
3917
- * @returns A promise that resolves to the base asset ID
3918
- */
3919
- getBaseAssetId() {
3920
- const {
3921
- consensusParameters: { baseAssetId }
3922
- } = this.getChain();
3923
- return baseAssetId;
3924
- }
3925
4078
  /**
3926
4079
  * Submits a transaction to the chain to be executed.
3927
4080
  *
@@ -3940,15 +4093,15 @@ var _Provider = class {
3940
4093
  }
3941
4094
  const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
3942
4095
  let abis;
3943
- if (transactionRequest.type === import_transactions17.TransactionType.Script) {
4096
+ if (transactionRequest.type === import_transactions19.TransactionType.Script) {
3944
4097
  abis = transactionRequest.abis;
3945
4098
  }
3946
4099
  if (awaitExecution) {
3947
4100
  const subscription = this.operations.submitAndAwait({ encodedTransaction });
3948
4101
  for await (const { submitAndAwait } of subscription) {
3949
4102
  if (submitAndAwait.type === "SqueezedOutStatus") {
3950
- throw new import_errors13.FuelError(
3951
- import_errors13.ErrorCode.TRANSACTION_SQUEEZED_OUT,
4103
+ throw new import_errors14.FuelError(
4104
+ import_errors14.ErrorCode.TRANSACTION_SQUEEZED_OUT,
3952
4105
  `Transaction Squeezed Out with reason: ${submitAndAwait.reason}`
3953
4106
  );
3954
4107
  }
@@ -3982,14 +4135,13 @@ var _Provider = class {
3982
4135
  return this.estimateTxDependencies(transactionRequest);
3983
4136
  }
3984
4137
  const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
3985
- const { dryRun: gqlReceipts } = await this.operations.dryRun({
3986
- encodedTransaction,
4138
+ const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4139
+ encodedTransactions: encodedTransaction,
3987
4140
  utxoValidation: utxoValidation || false
3988
4141
  });
3989
- const receipts = gqlReceipts.map(processGqlReceipt);
3990
- return {
3991
- receipts
3992
- };
4142
+ const [{ receipts: rawReceipts, status }] = dryRunStatuses;
4143
+ const receipts = rawReceipts.map(processGqlReceipt);
4144
+ return { receipts, dryrunStatus: status };
3993
4145
  }
3994
4146
  /**
3995
4147
  * Verifies whether enough gas is available to complete transaction.
@@ -4000,7 +4152,7 @@ var _Provider = class {
4000
4152
  async estimatePredicates(transactionRequest) {
4001
4153
  const shouldEstimatePredicates = Boolean(
4002
4154
  transactionRequest.inputs.find(
4003
- (input) => "predicate" in input && input.predicate && !(0, import_utils23.equalBytes)((0, import_utils22.arrayify)(input.predicate), (0, import_utils22.arrayify)("0x")) && new import_math14.BN(input.predicateGasUsed).isZero()
4155
+ (input) => "predicate" in input && input.predicate && !(0, import_utils23.equalBytes)((0, import_utils22.arrayify)(input.predicate), (0, import_utils22.arrayify)("0x")) && new import_math16.BN(input.predicateGasUsed).isZero()
4004
4156
  )
4005
4157
  );
4006
4158
  if (!shouldEstimatePredicates) {
@@ -4015,7 +4167,7 @@ var _Provider = class {
4015
4167
  } = response;
4016
4168
  if (inputs) {
4017
4169
  inputs.forEach((input, index) => {
4018
- if ("predicateGasUsed" in input && (0, import_math14.bn)(input.predicateGasUsed).gt(0)) {
4170
+ if ("predicateGasUsed" in input && (0, import_math16.bn)(input.predicateGasUsed).gt(0)) {
4019
4171
  transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
4020
4172
  }
4021
4173
  });
@@ -4028,31 +4180,31 @@ var _Provider = class {
4028
4180
  * If there are missing variable outputs,
4029
4181
  * `addVariableOutputs` is called on the transaction.
4030
4182
  *
4031
- * @privateRemarks
4032
- * TODO: Investigate support for missing contract IDs
4033
- * TODO: Add support for missing output messages
4034
4183
  *
4035
4184
  * @param transactionRequest - The transaction request object.
4036
4185
  * @returns A promise.
4037
4186
  */
4038
4187
  async estimateTxDependencies(transactionRequest) {
4039
- if (transactionRequest.type === import_transactions17.TransactionType.Create) {
4188
+ if (transactionRequest.type === import_transactions19.TransactionType.Create) {
4040
4189
  return {
4041
4190
  receipts: [],
4042
4191
  outputVariables: 0,
4043
4192
  missingContractIds: []
4044
4193
  };
4045
4194
  }
4046
- await this.estimatePredicates(transactionRequest);
4047
4195
  let receipts = [];
4048
4196
  const missingContractIds = [];
4049
4197
  let outputVariables = 0;
4198
+ let dryrunStatus;
4050
4199
  for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
4051
- const { dryRun: gqlReceipts } = await this.operations.dryRun({
4052
- encodedTransaction: (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes()),
4200
+ const {
4201
+ dryRun: [{ receipts: rawReceipts, status }]
4202
+ } = await this.operations.dryRun({
4203
+ encodedTransactions: [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())],
4053
4204
  utxoValidation: false
4054
4205
  });
4055
- receipts = gqlReceipts.map(processGqlReceipt);
4206
+ receipts = rawReceipts.map(processGqlReceipt);
4207
+ dryrunStatus = status;
4056
4208
  const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
4057
4209
  const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
4058
4210
  if (hasMissingOutputs) {
@@ -4062,6 +4214,11 @@ var _Provider = class {
4062
4214
  transactionRequest.addContractInputAndOutput(import_address3.Address.fromString(contractId));
4063
4215
  missingContractIds.push(contractId);
4064
4216
  });
4217
+ const { maxFee } = await this.estimateTxGasAndFee({
4218
+ transactionRequest,
4219
+ optimizeGas: false
4220
+ });
4221
+ transactionRequest.maxFee = maxFee;
4065
4222
  } else {
4066
4223
  break;
4067
4224
  }
@@ -4069,7 +4226,133 @@ var _Provider = class {
4069
4226
  return {
4070
4227
  receipts,
4071
4228
  outputVariables,
4072
- missingContractIds
4229
+ missingContractIds,
4230
+ dryrunStatus
4231
+ };
4232
+ }
4233
+ /**
4234
+ * Dry runs multiple transactions and checks for missing dependencies in batches.
4235
+ *
4236
+ * Transactions are dry run in batches. After each dry run, transactions requiring
4237
+ * further modifications are identified. The method iteratively updates these transactions
4238
+ * and performs subsequent dry runs until all dependencies for each transaction are satisfied.
4239
+ *
4240
+ * @param transactionRequests - Array of transaction request objects.
4241
+ * @returns A promise that resolves to an array of results for each transaction.
4242
+ */
4243
+ async estimateMultipleTxDependencies(transactionRequests) {
4244
+ const results = transactionRequests.map(() => ({
4245
+ receipts: [],
4246
+ outputVariables: 0,
4247
+ missingContractIds: [],
4248
+ dryrunStatus: void 0
4249
+ }));
4250
+ const allRequests = (0, import_ramda3.clone)(transactionRequests);
4251
+ const serializedTransactionsMap = /* @__PURE__ */ new Map();
4252
+ allRequests.forEach((req, index) => {
4253
+ if (req.type === import_transactions19.TransactionType.Script) {
4254
+ serializedTransactionsMap.set(index, (0, import_utils22.hexlify)(req.toTransactionBytes()));
4255
+ }
4256
+ });
4257
+ let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
4258
+ let attempt = 0;
4259
+ while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
4260
+ const encodedTransactions = transactionsToProcess.map(
4261
+ (index) => serializedTransactionsMap.get(index)
4262
+ );
4263
+ const dryRunResults = await this.operations.dryRun({
4264
+ encodedTransactions,
4265
+ utxoValidation: false
4266
+ });
4267
+ const nextRoundTransactions = [];
4268
+ for (let i = 0; i < dryRunResults.dryRun.length; i++) {
4269
+ const currentResultIndex = transactionsToProcess[i];
4270
+ const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
4271
+ results[currentResultIndex].receipts = rawReceipts.map(processGqlReceipt);
4272
+ results[currentResultIndex].dryrunStatus = status;
4273
+ const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
4274
+ results[currentResultIndex].receipts
4275
+ );
4276
+ const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
4277
+ const requestToProcess = allRequests[currentResultIndex];
4278
+ if (hasMissingOutputs && requestToProcess?.type === import_transactions19.TransactionType.Script) {
4279
+ results[currentResultIndex].outputVariables += missingOutputVariables.length;
4280
+ requestToProcess.addVariableOutputs(missingOutputVariables.length);
4281
+ missingOutputContractIds.forEach(({ contractId }) => {
4282
+ requestToProcess.addContractInputAndOutput(import_address3.Address.fromString(contractId));
4283
+ results[currentResultIndex].missingContractIds.push(contractId);
4284
+ });
4285
+ const { maxFee } = await this.estimateTxGasAndFee({
4286
+ transactionRequest: requestToProcess,
4287
+ optimizeGas: false
4288
+ });
4289
+ requestToProcess.maxFee = maxFee;
4290
+ serializedTransactionsMap.set(
4291
+ currentResultIndex,
4292
+ (0, import_utils22.hexlify)(requestToProcess.toTransactionBytes())
4293
+ );
4294
+ nextRoundTransactions.push(currentResultIndex);
4295
+ allRequests[currentResultIndex] = requestToProcess;
4296
+ }
4297
+ }
4298
+ transactionsToProcess = nextRoundTransactions;
4299
+ attempt += 1;
4300
+ }
4301
+ return results;
4302
+ }
4303
+ async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
4304
+ if (estimateTxDependencies) {
4305
+ return this.estimateMultipleTxDependencies(transactionRequests);
4306
+ }
4307
+ const encodedTransactions = transactionRequests.map((tx) => (0, import_utils22.hexlify)(tx.toTransactionBytes()));
4308
+ const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4309
+ encodedTransactions,
4310
+ utxoValidation: utxoValidation || false
4311
+ });
4312
+ const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
4313
+ const receipts = rawReceipts.map(processGqlReceipt);
4314
+ return { receipts, dryrunStatus: status };
4315
+ });
4316
+ return results;
4317
+ }
4318
+ async estimateTxGasAndFee(params) {
4319
+ const { transactionRequest, totalGasUsedByPredicates = (0, import_math16.bn)(0), optimizeGas = true } = params;
4320
+ let { gasPrice } = params;
4321
+ const chainInfo = this.getChain();
4322
+ const { gasPriceFactor } = this.getGasConfig();
4323
+ const minGas = transactionRequest.calculateMinGas(chainInfo);
4324
+ if (!gasPrice) {
4325
+ gasPrice = await this.estimateGasPrice(10);
4326
+ }
4327
+ const shouldSetGaslimit = transactionRequest.type === import_transactions19.TransactionType.Script && !optimizeGas;
4328
+ const minFee = calculateGasFee({
4329
+ gasPrice: (0, import_math16.bn)(gasPrice),
4330
+ gas: minGas,
4331
+ priceFactor: gasPriceFactor,
4332
+ tip: transactionRequest.tip
4333
+ }).add(1);
4334
+ if (shouldSetGaslimit) {
4335
+ transactionRequest.gasLimit = chainInfo.consensusParameters.maxGasPerTx.sub(
4336
+ minGas.add(totalGasUsedByPredicates)
4337
+ );
4338
+ }
4339
+ let maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
4340
+ const maxFee = calculateGasFee({
4341
+ gasPrice: (0, import_math16.bn)(gasPrice),
4342
+ gas: maxGas,
4343
+ priceFactor: gasPriceFactor,
4344
+ tip: transactionRequest.tip
4345
+ }).add(1);
4346
+ if (shouldSetGaslimit) {
4347
+ maxGas = chainInfo.consensusParameters.maxGasPerTx.sub(maxFee);
4348
+ transactionRequest.gasLimit = maxGas;
4349
+ }
4350
+ return {
4351
+ minGas,
4352
+ minFee,
4353
+ maxGas,
4354
+ maxFee,
4355
+ gasPrice
4073
4356
  };
4074
4357
  }
4075
4358
  /**
@@ -4087,15 +4370,17 @@ var _Provider = class {
4087
4370
  if (estimateTxDependencies) {
4088
4371
  return this.estimateTxDependencies(transactionRequest);
4089
4372
  }
4090
- const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
4091
- const { dryRun: gqlReceipts } = await this.operations.dryRun({
4092
- encodedTransaction,
4373
+ const encodedTransactions = [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())];
4374
+ const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4375
+ encodedTransactions,
4093
4376
  utxoValidation: true
4094
4377
  });
4095
- const receipts = gqlReceipts.map(processGqlReceipt);
4096
- return {
4097
- receipts
4098
- };
4378
+ const callResult = dryRunStatuses.map((dryRunStatus) => {
4379
+ const { id, receipts, status } = dryRunStatus;
4380
+ const processedReceipts = receipts.map(processGqlReceipt);
4381
+ return { id, receipts: processedReceipts, status };
4382
+ });
4383
+ return { receipts: callResult[0].receipts };
4099
4384
  }
4100
4385
  /**
4101
4386
  * Returns a transaction cost to enable user
@@ -4112,80 +4397,80 @@ var _Provider = class {
4112
4397
  * @param tolerance - The tolerance to add on top of the gasUsed.
4113
4398
  * @returns A promise that resolves to the transaction cost object.
4114
4399
  */
4115
- async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
4116
- estimateTxDependencies = true,
4117
- estimatePredicates = true,
4118
- resourcesOwner,
4119
- signatureCallback
4120
- } = {}) {
4400
+ async getTransactionCost(transactionRequestLike, { resourcesOwner, signatureCallback, quantitiesToContract = [] } = {}) {
4121
4401
  const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
4122
- const chainInfo = this.getChain();
4123
- const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
4124
- const gasPrice = (0, import_math14.max)(txRequestClone.gasPrice, minGasPrice);
4125
- const isScriptTransaction = txRequestClone.type === import_transactions17.TransactionType.Script;
4402
+ const isScriptTransaction = txRequestClone.type === import_transactions19.TransactionType.Script;
4126
4403
  const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
4127
- const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
4404
+ const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
4128
4405
  txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
4129
- if (estimatePredicates) {
4130
- if (isScriptTransaction) {
4131
- txRequestClone.gasLimit = (0, import_math14.bn)(0);
4132
- }
4133
- if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
4134
- resourcesOwner.populateTransactionPredicateData(txRequestClone);
4135
- }
4136
- await this.estimatePredicates(txRequestClone);
4406
+ txRequestClone.maxFee = (0, import_math16.bn)(0);
4407
+ if (isScriptTransaction) {
4408
+ txRequestClone.gasLimit = (0, import_math16.bn)(0);
4137
4409
  }
4138
- if (signatureCallback && isScriptTransaction) {
4139
- await signatureCallback(txRequestClone);
4410
+ if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
4411
+ resourcesOwner.populateTransactionPredicateData(txRequestClone);
4140
4412
  }
4141
- const minGas = txRequestClone.calculateMinGas(chainInfo);
4142
- const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
4413
+ const signedRequest = (0, import_ramda3.clone)(txRequestClone);
4414
+ let addedSignatures = 0;
4415
+ if (signatureCallback && isScriptTransaction) {
4416
+ const lengthBefore = signedRequest.witnesses.length;
4417
+ await signatureCallback(signedRequest);
4418
+ addedSignatures = signedRequest.witnesses.length - lengthBefore;
4419
+ }
4420
+ await this.estimatePredicates(signedRequest);
4421
+ let { maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
4422
+ transactionRequest: signedRequest,
4423
+ optimizeGas: false
4424
+ });
4425
+ txRequestClone.maxFee = maxFee;
4143
4426
  let receipts = [];
4144
4427
  let missingContractIds = [];
4145
4428
  let outputVariables = 0;
4146
- if (isScriptTransaction && estimateTxDependencies) {
4147
- txRequestClone.gasPrice = (0, import_math14.bn)(0);
4148
- txRequestClone.gasLimit = (0, import_math14.bn)(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
4429
+ let gasUsed = (0, import_math16.bn)(0);
4430
+ txRequestClone.updatePredicateGasUsed(signedRequest.inputs);
4431
+ if (isScriptTransaction) {
4432
+ if (signatureCallback) {
4433
+ await signatureCallback(txRequestClone);
4434
+ }
4435
+ txRequestClone.gasLimit = maxGas;
4149
4436
  const result = await this.estimateTxDependencies(txRequestClone);
4150
4437
  receipts = result.receipts;
4151
4438
  outputVariables = result.outputVariables;
4152
4439
  missingContractIds = result.missingContractIds;
4440
+ gasUsed = getGasUsedFromReceipts(receipts);
4441
+ txRequestClone.gasLimit = gasUsed;
4442
+ ({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
4443
+ transactionRequest: txRequestClone,
4444
+ gasPrice
4445
+ }));
4153
4446
  }
4154
- const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
4155
- const usedFee = calculatePriceWithFactor(
4156
- gasUsed,
4157
- gasPrice,
4158
- gasPriceFactor
4159
- ).normalizeZeroToOne();
4160
- const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
4161
- const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
4162
4447
  return {
4163
4448
  requiredQuantities: allQuantities,
4164
4449
  receipts,
4165
4450
  gasUsed,
4166
- minGasPrice,
4167
4451
  gasPrice,
4168
4452
  minGas,
4169
4453
  maxGas,
4170
- usedFee,
4171
4454
  minFee,
4172
4455
  maxFee,
4173
- estimatedInputs: txRequestClone.inputs,
4174
4456
  outputVariables,
4175
- missingContractIds
4457
+ missingContractIds,
4458
+ addedSignatures,
4459
+ estimatedPredicates: txRequestClone.inputs
4176
4460
  };
4177
4461
  }
4178
- async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
4462
+ async getResourcesForTransaction(owner, transactionRequestLike, quantitiesToContract = []) {
4179
4463
  const ownerAddress = import_address3.Address.fromAddressOrString(owner);
4180
4464
  const transactionRequest = transactionRequestify((0, import_ramda3.clone)(transactionRequestLike));
4181
- const transactionCost = await this.getTransactionCost(transactionRequest, forwardingQuantities);
4465
+ const transactionCost = await this.getTransactionCost(transactionRequest, {
4466
+ quantitiesToContract
4467
+ });
4182
4468
  transactionRequest.addResources(
4183
4469
  await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
4184
4470
  );
4185
- const { requiredQuantities, ...txCost } = await this.getTransactionCost(
4186
- transactionRequest,
4187
- forwardingQuantities
4188
- );
4471
+ const { requiredQuantities, ...txCost } = await this.getTransactionCost(transactionRequest, {
4472
+ quantitiesToContract
4473
+ });
4189
4474
  const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
4190
4475
  return {
4191
4476
  resources,
@@ -4207,11 +4492,10 @@ var _Provider = class {
4207
4492
  return coins.map((coin) => ({
4208
4493
  id: coin.utxoId,
4209
4494
  assetId: coin.assetId,
4210
- amount: (0, import_math14.bn)(coin.amount),
4495
+ amount: (0, import_math16.bn)(coin.amount),
4211
4496
  owner: import_address3.Address.fromAddressOrString(coin.owner),
4212
- maturity: (0, import_math14.bn)(coin.maturity).toNumber(),
4213
- blockCreated: (0, import_math14.bn)(coin.blockCreated),
4214
- txCreatedIdx: (0, import_math14.bn)(coin.txCreatedIdx)
4497
+ blockCreated: (0, import_math16.bn)(coin.blockCreated),
4498
+ txCreatedIdx: (0, import_math16.bn)(coin.txCreatedIdx)
4215
4499
  }));
4216
4500
  }
4217
4501
  /**
@@ -4248,9 +4532,9 @@ var _Provider = class {
4248
4532
  switch (coin.__typename) {
4249
4533
  case "MessageCoin":
4250
4534
  return {
4251
- amount: (0, import_math14.bn)(coin.amount),
4535
+ amount: (0, import_math16.bn)(coin.amount),
4252
4536
  assetId: coin.assetId,
4253
- daHeight: (0, import_math14.bn)(coin.daHeight),
4537
+ daHeight: (0, import_math16.bn)(coin.daHeight),
4254
4538
  sender: import_address3.Address.fromAddressOrString(coin.sender),
4255
4539
  recipient: import_address3.Address.fromAddressOrString(coin.recipient),
4256
4540
  nonce: coin.nonce
@@ -4258,12 +4542,11 @@ var _Provider = class {
4258
4542
  case "Coin":
4259
4543
  return {
4260
4544
  id: coin.utxoId,
4261
- amount: (0, import_math14.bn)(coin.amount),
4545
+ amount: (0, import_math16.bn)(coin.amount),
4262
4546
  assetId: coin.assetId,
4263
4547
  owner: import_address3.Address.fromAddressOrString(coin.owner),
4264
- maturity: (0, import_math14.bn)(coin.maturity).toNumber(),
4265
- blockCreated: (0, import_math14.bn)(coin.blockCreated),
4266
- txCreatedIdx: (0, import_math14.bn)(coin.txCreatedIdx)
4548
+ blockCreated: (0, import_math16.bn)(coin.blockCreated),
4549
+ txCreatedIdx: (0, import_math16.bn)(coin.txCreatedIdx)
4267
4550
  };
4268
4551
  default:
4269
4552
  return null;
@@ -4280,13 +4563,13 @@ var _Provider = class {
4280
4563
  async getBlock(idOrHeight) {
4281
4564
  let variables;
4282
4565
  if (typeof idOrHeight === "number") {
4283
- variables = { height: (0, import_math14.bn)(idOrHeight).toString(10) };
4566
+ variables = { height: (0, import_math16.bn)(idOrHeight).toString(10) };
4284
4567
  } else if (idOrHeight === "latest") {
4285
4568
  variables = { height: (await this.getBlockNumber()).toString(10) };
4286
4569
  } else if (idOrHeight.length === 66) {
4287
4570
  variables = { blockId: idOrHeight };
4288
4571
  } else {
4289
- variables = { blockId: (0, import_math14.bn)(idOrHeight).toString(10) };
4572
+ variables = { blockId: (0, import_math16.bn)(idOrHeight).toString(10) };
4290
4573
  }
4291
4574
  const { block } = await this.operations.getBlock(variables);
4292
4575
  if (!block) {
@@ -4294,7 +4577,7 @@ var _Provider = class {
4294
4577
  }
4295
4578
  return {
4296
4579
  id: block.id,
4297
- height: (0, import_math14.bn)(block.header.height),
4580
+ height: (0, import_math16.bn)(block.height),
4298
4581
  time: block.header.time,
4299
4582
  transactionIds: block.transactions.map((tx) => tx.id)
4300
4583
  };
@@ -4309,7 +4592,7 @@ var _Provider = class {
4309
4592
  const { blocks: fetchedData } = await this.operations.getBlocks(params);
4310
4593
  const blocks = fetchedData.edges.map(({ node: block }) => ({
4311
4594
  id: block.id,
4312
- height: (0, import_math14.bn)(block.header.height),
4595
+ height: (0, import_math16.bn)(block.height),
4313
4596
  time: block.header.time,
4314
4597
  transactionIds: block.transactions.map((tx) => tx.id)
4315
4598
  }));
@@ -4324,7 +4607,7 @@ var _Provider = class {
4324
4607
  async getBlockWithTransactions(idOrHeight) {
4325
4608
  let variables;
4326
4609
  if (typeof idOrHeight === "number") {
4327
- variables = { blockHeight: (0, import_math14.bn)(idOrHeight).toString(10) };
4610
+ variables = { blockHeight: (0, import_math16.bn)(idOrHeight).toString(10) };
4328
4611
  } else if (idOrHeight === "latest") {
4329
4612
  variables = { blockHeight: (await this.getBlockNumber()).toString() };
4330
4613
  } else {
@@ -4336,11 +4619,11 @@ var _Provider = class {
4336
4619
  }
4337
4620
  return {
4338
4621
  id: block.id,
4339
- height: (0, import_math14.bn)(block.header.height, 10),
4622
+ height: (0, import_math16.bn)(block.height, 10),
4340
4623
  time: block.header.time,
4341
4624
  transactionIds: block.transactions.map((tx) => tx.id),
4342
4625
  transactions: block.transactions.map(
4343
- (tx) => new import_transactions17.TransactionCoder().decode((0, import_utils22.arrayify)(tx.rawPayload), 0)?.[0]
4626
+ (tx) => new import_transactions19.TransactionCoder().decode((0, import_utils22.arrayify)(tx.rawPayload), 0)?.[0]
4344
4627
  )
4345
4628
  };
4346
4629
  }
@@ -4355,7 +4638,7 @@ var _Provider = class {
4355
4638
  if (!transaction) {
4356
4639
  return null;
4357
4640
  }
4358
- return new import_transactions17.TransactionCoder().decode(
4641
+ return new import_transactions19.TransactionCoder().decode(
4359
4642
  (0, import_utils22.arrayify)(transaction.rawPayload),
4360
4643
  0
4361
4644
  )?.[0];
@@ -4385,7 +4668,7 @@ var _Provider = class {
4385
4668
  contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
4386
4669
  asset: (0, import_utils22.hexlify)(assetId)
4387
4670
  });
4388
- return (0, import_math14.bn)(contractBalance.amount, 10);
4671
+ return (0, import_math16.bn)(contractBalance.amount, 10);
4389
4672
  }
4390
4673
  /**
4391
4674
  * Returns the balance for the given owner for the given asset ID.
@@ -4399,7 +4682,7 @@ var _Provider = class {
4399
4682
  owner: import_address3.Address.fromAddressOrString(owner).toB256(),
4400
4683
  assetId: (0, import_utils22.hexlify)(assetId)
4401
4684
  });
4402
- return (0, import_math14.bn)(balance.amount, 10);
4685
+ return (0, import_math16.bn)(balance.amount, 10);
4403
4686
  }
4404
4687
  /**
4405
4688
  * Returns balances for the given owner.
@@ -4417,7 +4700,7 @@ var _Provider = class {
4417
4700
  const balances = result.balances.edges.map((edge) => edge.node);
4418
4701
  return balances.map((balance) => ({
4419
4702
  assetId: balance.assetId,
4420
- amount: (0, import_math14.bn)(balance.amount)
4703
+ amount: (0, import_math16.bn)(balance.amount)
4421
4704
  }));
4422
4705
  }
4423
4706
  /**
@@ -4435,19 +4718,19 @@ var _Provider = class {
4435
4718
  });
4436
4719
  const messages = result.messages.edges.map((edge) => edge.node);
4437
4720
  return messages.map((message) => ({
4438
- messageId: import_transactions17.InputMessageCoder.getMessageId({
4721
+ messageId: import_transactions19.InputMessageCoder.getMessageId({
4439
4722
  sender: message.sender,
4440
4723
  recipient: message.recipient,
4441
4724
  nonce: message.nonce,
4442
- amount: (0, import_math14.bn)(message.amount),
4725
+ amount: (0, import_math16.bn)(message.amount),
4443
4726
  data: message.data
4444
4727
  }),
4445
4728
  sender: import_address3.Address.fromAddressOrString(message.sender),
4446
4729
  recipient: import_address3.Address.fromAddressOrString(message.recipient),
4447
4730
  nonce: message.nonce,
4448
- amount: (0, import_math14.bn)(message.amount),
4449
- data: import_transactions17.InputMessageCoder.decodeData(message.data),
4450
- daHeight: (0, import_math14.bn)(message.daHeight)
4731
+ amount: (0, import_math16.bn)(message.amount),
4732
+ data: import_transactions19.InputMessageCoder.decodeData(message.data),
4733
+ daHeight: (0, import_math16.bn)(message.daHeight)
4451
4734
  }));
4452
4735
  }
4453
4736
  /**
@@ -4465,8 +4748,8 @@ var _Provider = class {
4465
4748
  nonce
4466
4749
  };
4467
4750
  if (commitBlockId && commitBlockHeight) {
4468
- throw new import_errors13.FuelError(
4469
- import_errors13.ErrorCode.INVALID_INPUT_PARAMETERS,
4751
+ throw new import_errors14.FuelError(
4752
+ import_errors14.ErrorCode.INVALID_INPUT_PARAMETERS,
4470
4753
  "commitBlockId and commitBlockHeight cannot be used together"
4471
4754
  );
4472
4755
  }
@@ -4500,44 +4783,54 @@ var _Provider = class {
4500
4783
  } = result.messageProof;
4501
4784
  return {
4502
4785
  messageProof: {
4503
- proofIndex: (0, import_math14.bn)(messageProof.proofIndex),
4786
+ proofIndex: (0, import_math16.bn)(messageProof.proofIndex),
4504
4787
  proofSet: messageProof.proofSet
4505
4788
  },
4506
4789
  blockProof: {
4507
- proofIndex: (0, import_math14.bn)(blockProof.proofIndex),
4790
+ proofIndex: (0, import_math16.bn)(blockProof.proofIndex),
4508
4791
  proofSet: blockProof.proofSet
4509
4792
  },
4510
4793
  messageBlockHeader: {
4511
4794
  id: messageBlockHeader.id,
4512
- daHeight: (0, import_math14.bn)(messageBlockHeader.daHeight),
4513
- transactionsCount: (0, import_math14.bn)(messageBlockHeader.transactionsCount),
4795
+ daHeight: (0, import_math16.bn)(messageBlockHeader.daHeight),
4796
+ transactionsCount: (0, import_math16.bn)(messageBlockHeader.transactionsCount),
4514
4797
  transactionsRoot: messageBlockHeader.transactionsRoot,
4515
- height: (0, import_math14.bn)(messageBlockHeader.height),
4798
+ height: (0, import_math16.bn)(messageBlockHeader.height),
4516
4799
  prevRoot: messageBlockHeader.prevRoot,
4517
4800
  time: messageBlockHeader.time,
4518
4801
  applicationHash: messageBlockHeader.applicationHash,
4519
4802
  messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
4520
- messageReceiptCount: (0, import_math14.bn)(messageBlockHeader.messageReceiptCount)
4803
+ messageReceiptCount: (0, import_math16.bn)(messageBlockHeader.messageReceiptCount)
4521
4804
  },
4522
4805
  commitBlockHeader: {
4523
4806
  id: commitBlockHeader.id,
4524
- daHeight: (0, import_math14.bn)(commitBlockHeader.daHeight),
4525
- transactionsCount: (0, import_math14.bn)(commitBlockHeader.transactionsCount),
4807
+ daHeight: (0, import_math16.bn)(commitBlockHeader.daHeight),
4808
+ transactionsCount: (0, import_math16.bn)(commitBlockHeader.transactionsCount),
4526
4809
  transactionsRoot: commitBlockHeader.transactionsRoot,
4527
- height: (0, import_math14.bn)(commitBlockHeader.height),
4810
+ height: (0, import_math16.bn)(commitBlockHeader.height),
4528
4811
  prevRoot: commitBlockHeader.prevRoot,
4529
4812
  time: commitBlockHeader.time,
4530
4813
  applicationHash: commitBlockHeader.applicationHash,
4531
4814
  messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
4532
- messageReceiptCount: (0, import_math14.bn)(commitBlockHeader.messageReceiptCount)
4815
+ messageReceiptCount: (0, import_math16.bn)(commitBlockHeader.messageReceiptCount)
4533
4816
  },
4534
4817
  sender: import_address3.Address.fromAddressOrString(sender),
4535
4818
  recipient: import_address3.Address.fromAddressOrString(recipient),
4536
4819
  nonce,
4537
- amount: (0, import_math14.bn)(amount),
4820
+ amount: (0, import_math16.bn)(amount),
4538
4821
  data
4539
4822
  };
4540
4823
  }
4824
+ async getLatestGasPrice() {
4825
+ const { latestGasPrice } = await this.operations.getLatestGasPrice();
4826
+ return (0, import_math16.bn)(latestGasPrice.gasPrice);
4827
+ }
4828
+ async estimateGasPrice(blockHorizon) {
4829
+ const { estimateGasPrice } = await this.operations.estimateGasPrice({
4830
+ blockHorizon: String(blockHorizon)
4831
+ });
4832
+ return (0, import_math16.bn)(estimateGasPrice.gasPrice);
4833
+ }
4541
4834
  /**
4542
4835
  * Returns Message Proof for given transaction id and the message id from MessageOut receipt.
4543
4836
  *
@@ -4557,10 +4850,10 @@ var _Provider = class {
4557
4850
  */
4558
4851
  async produceBlocks(amount, startTime) {
4559
4852
  const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
4560
- blocksToProduce: (0, import_math14.bn)(amount).toString(10),
4853
+ blocksToProduce: (0, import_math16.bn)(amount).toString(10),
4561
4854
  startTimestamp: startTime ? import_utils22.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
4562
4855
  });
4563
- return (0, import_math14.bn)(latestBlockHeight);
4856
+ return (0, import_math16.bn)(latestBlockHeight);
4564
4857
  }
4565
4858
  // eslint-disable-next-line @typescript-eslint/require-await
4566
4859
  async getTransactionResponse(transactionId) {
@@ -4574,7 +4867,7 @@ cacheInputs_fn = function(inputs) {
4574
4867
  return;
4575
4868
  }
4576
4869
  inputs.forEach((input) => {
4577
- if (input.type === import_transactions17.InputType.Coin) {
4870
+ if (input.type === import_transactions19.InputType.Coin) {
4578
4871
  this.cache?.set(input.id);
4579
4872
  }
4580
4873
  });
@@ -4583,9 +4876,9 @@ __publicField(Provider, "chainInfoCache", {});
4583
4876
  __publicField(Provider, "nodeInfoCache", {});
4584
4877
 
4585
4878
  // src/providers/transaction-summary/get-transaction-summary.ts
4586
- var import_errors14 = require("@fuel-ts/errors");
4587
- var import_math15 = require("@fuel-ts/math");
4588
- var import_transactions18 = require("@fuel-ts/transactions");
4879
+ var import_errors15 = require("@fuel-ts/errors");
4880
+ var import_math17 = require("@fuel-ts/math");
4881
+ var import_transactions20 = require("@fuel-ts/transactions");
4589
4882
  var import_utils25 = require("@fuel-ts/utils");
4590
4883
  async function getTransactionSummary(params) {
4591
4884
  const { id, provider, abiMap } = params;
@@ -4593,30 +4886,37 @@ async function getTransactionSummary(params) {
4593
4886
  transactionId: id
4594
4887
  });
4595
4888
  if (!gqlTransaction) {
4596
- throw new import_errors14.FuelError(
4597
- import_errors14.ErrorCode.TRANSACTION_NOT_FOUND,
4889
+ throw new import_errors15.FuelError(
4890
+ import_errors15.ErrorCode.TRANSACTION_NOT_FOUND,
4598
4891
  `Transaction not found for given id: ${id}.`
4599
4892
  );
4600
4893
  }
4601
- const [decodedTransaction] = new import_transactions18.TransactionCoder().decode(
4894
+ const [decodedTransaction] = new import_transactions20.TransactionCoder().decode(
4602
4895
  (0, import_utils25.arrayify)(gqlTransaction.rawPayload),
4603
4896
  0
4604
4897
  );
4605
- const receipts = gqlTransaction.receipts?.map(processGqlReceipt) || [];
4898
+ let txReceipts = [];
4899
+ if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
4900
+ txReceipts = gqlTransaction.status.receipts;
4901
+ }
4902
+ const receipts = txReceipts.map(processGqlReceipt);
4606
4903
  const {
4607
- consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
4904
+ consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts, maxGasPerTx }
4608
4905
  } = provider.getChain();
4906
+ const gasPrice = await provider.getLatestGasPrice();
4609
4907
  const transactionInfo = assembleTransactionSummary({
4610
4908
  id: gqlTransaction.id,
4611
4909
  receipts,
4612
4910
  transaction: decodedTransaction,
4613
4911
  transactionBytes: (0, import_utils25.arrayify)(gqlTransaction.rawPayload),
4614
4912
  gqlTransactionStatus: gqlTransaction.status,
4615
- gasPerByte: (0, import_math15.bn)(gasPerByte),
4616
- gasPriceFactor: (0, import_math15.bn)(gasPriceFactor),
4913
+ gasPerByte: (0, import_math17.bn)(gasPerByte),
4914
+ gasPriceFactor: (0, import_math17.bn)(gasPriceFactor),
4617
4915
  abiMap,
4618
4916
  maxInputs,
4619
- gasCosts
4917
+ gasCosts,
4918
+ maxGasPerTx,
4919
+ gasPrice
4620
4920
  });
4621
4921
  return {
4622
4922
  gqlTransaction,
@@ -4626,10 +4926,11 @@ async function getTransactionSummary(params) {
4626
4926
  async function getTransactionSummaryFromRequest(params) {
4627
4927
  const { provider, transactionRequest, abiMap } = params;
4628
4928
  const { receipts } = await provider.call(transactionRequest);
4629
- const { gasPerByte, gasPriceFactor, gasCosts } = provider.getGasConfig();
4929
+ const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = provider.getGasConfig();
4630
4930
  const maxInputs = provider.getChain().consensusParameters.maxInputs;
4631
4931
  const transaction = transactionRequest.toTransaction();
4632
4932
  const transactionBytes = transactionRequest.toTransactionBytes();
4933
+ const gasPrice = await provider.getLatestGasPrice();
4633
4934
  const transactionSummary = assembleTransactionSummary({
4634
4935
  receipts,
4635
4936
  transaction,
@@ -4638,7 +4939,9 @@ async function getTransactionSummaryFromRequest(params) {
4638
4939
  gasPerByte,
4639
4940
  gasPriceFactor,
4640
4941
  maxInputs,
4641
- gasCosts
4942
+ gasCosts,
4943
+ maxGasPerTx,
4944
+ gasPrice
4642
4945
  });
4643
4946
  return transactionSummary;
4644
4947
  }
@@ -4647,13 +4950,18 @@ async function getTransactionsSummaries(params) {
4647
4950
  const { transactionsByOwner } = await provider.operations.getTransactionsByOwner(filters);
4648
4951
  const { edges, pageInfo } = transactionsByOwner;
4649
4952
  const {
4650
- consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
4953
+ consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts, maxGasPerTx }
4651
4954
  } = provider.getChain();
4955
+ const gasPrice = await provider.getLatestGasPrice();
4652
4956
  const transactions = edges.map((edge) => {
4653
4957
  const { node: gqlTransaction } = edge;
4654
- const { id, rawPayload, receipts: gqlReceipts, status } = gqlTransaction;
4655
- const [decodedTransaction] = new import_transactions18.TransactionCoder().decode((0, import_utils25.arrayify)(rawPayload), 0);
4656
- const receipts = gqlReceipts?.map(processGqlReceipt) || [];
4958
+ const { id, rawPayload, status } = gqlTransaction;
4959
+ const [decodedTransaction] = new import_transactions20.TransactionCoder().decode((0, import_utils25.arrayify)(rawPayload), 0);
4960
+ let txReceipts = [];
4961
+ if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
4962
+ txReceipts = gqlTransaction.status.receipts;
4963
+ }
4964
+ const receipts = txReceipts.map(processGqlReceipt);
4657
4965
  const transactionSummary = assembleTransactionSummary({
4658
4966
  id,
4659
4967
  receipts,
@@ -4664,7 +4972,9 @@ async function getTransactionsSummaries(params) {
4664
4972
  gasPerByte,
4665
4973
  gasPriceFactor,
4666
4974
  maxInputs,
4667
- gasCosts
4975
+ gasCosts,
4976
+ maxGasPerTx,
4977
+ gasPrice
4668
4978
  });
4669
4979
  const output = {
4670
4980
  gqlTransaction,
@@ -4801,13 +5111,13 @@ var assets = [
4801
5111
 
4802
5112
  // src/utils/formatTransferToContractScriptData.ts
4803
5113
  var import_abi_coder4 = require("@fuel-ts/abi-coder");
4804
- var import_math16 = require("@fuel-ts/math");
5114
+ var import_math18 = require("@fuel-ts/math");
4805
5115
  var import_utils26 = require("@fuel-ts/utils");
4806
5116
  var asm = __toESM(require("@fuels/vm-asm"));
4807
5117
  var formatTransferToContractScriptData = (params) => {
4808
5118
  const { assetId, amountToTransfer, hexlifiedContractId } = params;
4809
5119
  const numberCoder = new import_abi_coder4.BigNumberCoder("u64");
4810
- const encoded = numberCoder.encode(new import_math16.BN(amountToTransfer).toNumber());
5120
+ const encoded = numberCoder.encode(new import_math18.BN(amountToTransfer).toNumber());
4811
5121
  const scriptData = Uint8Array.from([
4812
5122
  ...(0, import_utils26.arrayify)(hexlifiedContractId),
4813
5123
  ...encoded,
@@ -4867,7 +5177,7 @@ var Account = class extends import_interfaces.AbstractAccount {
4867
5177
  */
4868
5178
  get provider() {
4869
5179
  if (!this._provider) {
4870
- throw new import_errors15.FuelError(import_errors15.ErrorCode.MISSING_PROVIDER, "Provider not set");
5180
+ throw new import_errors16.FuelError(import_errors16.ErrorCode.MISSING_PROVIDER, "Provider not set");
4871
5181
  }
4872
5182
  return this._provider;
4873
5183
  }
@@ -4919,8 +5229,8 @@ var Account = class extends import_interfaces.AbstractAccount {
4919
5229
  if (!hasNextPage) {
4920
5230
  break;
4921
5231
  }
4922
- throw new import_errors15.FuelError(
4923
- import_errors15.ErrorCode.NOT_SUPPORTED,
5232
+ throw new import_errors16.FuelError(
5233
+ import_errors16.ErrorCode.NOT_SUPPORTED,
4924
5234
  `Wallets containing more than ${pageSize} coins exceed the current supported limit.`
4925
5235
  );
4926
5236
  }
@@ -4945,8 +5255,8 @@ var Account = class extends import_interfaces.AbstractAccount {
4945
5255
  if (!hasNextPage) {
4946
5256
  break;
4947
5257
  }
4948
- throw new import_errors15.FuelError(
4949
- import_errors15.ErrorCode.NOT_SUPPORTED,
5258
+ throw new import_errors16.FuelError(
5259
+ import_errors16.ErrorCode.NOT_SUPPORTED,
4950
5260
  `Wallets containing more than ${pageSize} messages exceed the current supported limit.`
4951
5261
  );
4952
5262
  }
@@ -4958,9 +5268,8 @@ var Account = class extends import_interfaces.AbstractAccount {
4958
5268
  * @param assetId - The asset ID to check the balance for.
4959
5269
  * @returns A promise that resolves to the balance amount.
4960
5270
  */
4961
- async getBalance(assetId) {
4962
- const assetIdToFetch = assetId ?? this.provider.getBaseAssetId();
4963
- const amount = await this.provider.getBalance(this.address, assetIdToFetch);
5271
+ async getBalance(assetId = import_configs12.BaseAssetId) {
5272
+ const amount = await this.provider.getBalance(this.address, assetId);
4964
5273
  return amount;
4965
5274
  }
4966
5275
  /**
@@ -4982,8 +5291,8 @@ var Account = class extends import_interfaces.AbstractAccount {
4982
5291
  if (!hasNextPage) {
4983
5292
  break;
4984
5293
  }
4985
- throw new import_errors15.FuelError(
4986
- import_errors15.ErrorCode.NOT_SUPPORTED,
5294
+ throw new import_errors16.FuelError(
5295
+ import_errors16.ErrorCode.NOT_SUPPORTED,
4987
5296
  `Wallets containing more than ${pageSize} balances exceed the current supported limit.`
4988
5297
  );
4989
5298
  }
@@ -4997,37 +5306,33 @@ var Account = class extends import_interfaces.AbstractAccount {
4997
5306
  * @param fee - The estimated transaction fee.
4998
5307
  * @returns A promise that resolves when the resources are added to the transaction.
4999
5308
  */
5000
- async fund(request, coinQuantities, fee) {
5001
- const baseAssetId = this.provider.getBaseAssetId();
5002
- const updatedQuantities = addAmountToAsset({
5003
- amount: (0, import_math17.bn)(fee),
5004
- assetId: baseAssetId,
5005
- coinQuantities
5309
+ async fund(request, params) {
5310
+ const { addedSignatures, estimatedPredicates, maxFee: fee, requiredQuantities } = params;
5311
+ const txRequest = request;
5312
+ const requiredQuantitiesWithFee = addAmountToCoinQuantities({
5313
+ amount: (0, import_math19.bn)(fee),
5314
+ assetId: import_configs12.BaseAssetId,
5315
+ coinQuantities: requiredQuantities
5006
5316
  });
5007
5317
  const quantitiesDict = {};
5008
- updatedQuantities.forEach(({ amount, assetId }) => {
5318
+ requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
5009
5319
  quantitiesDict[assetId] = {
5010
5320
  required: amount,
5011
- owned: (0, import_math17.bn)(0)
5321
+ owned: (0, import_math19.bn)(0)
5012
5322
  };
5013
5323
  });
5014
- const cachedUtxos = [];
5015
- const cachedMessages = [];
5016
- const owner = this.address.toB256();
5017
- request.inputs.forEach((input) => {
5324
+ txRequest.inputs.forEach((input) => {
5018
5325
  const isResource = "amount" in input;
5019
5326
  if (isResource) {
5020
5327
  const isCoin2 = "owner" in input;
5021
5328
  if (isCoin2) {
5022
5329
  const assetId = String(input.assetId);
5023
- if (input.owner === owner && quantitiesDict[assetId]) {
5024
- const amount = (0, import_math17.bn)(input.amount);
5330
+ if (quantitiesDict[assetId]) {
5331
+ const amount = (0, import_math19.bn)(input.amount);
5025
5332
  quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
5026
- cachedUtxos.push(input.id);
5027
5333
  }
5028
- } else if (input.recipient === owner && input.amount && quantitiesDict[baseAssetId]) {
5029
- quantitiesDict[baseAssetId].owned = quantitiesDict[baseAssetId].owned.add(input.amount);
5030
- cachedMessages.push(input.nonce);
5334
+ } else if (input.amount && quantitiesDict[import_configs12.BaseAssetId]) {
5335
+ quantitiesDict[import_configs12.BaseAssetId].owned = quantitiesDict[import_configs12.BaseAssetId].owned.add(input.amount);
5031
5336
  }
5032
5337
  }
5033
5338
  });
@@ -5042,12 +5347,23 @@ var Account = class extends import_interfaces.AbstractAccount {
5042
5347
  });
5043
5348
  const needsToBeFunded = missingQuantities.length;
5044
5349
  if (needsToBeFunded) {
5045
- const resources = await this.getResourcesToSpend(missingQuantities, {
5046
- messages: cachedMessages,
5047
- utxos: cachedUtxos
5048
- });
5049
- request.addResources(resources);
5350
+ const excludedIds = cacheTxInputsFromOwner(txRequest.inputs, this.address.toString());
5351
+ const resources = await this.getResourcesToSpend(missingQuantities, excludedIds);
5352
+ txRequest.addResources(resources);
5353
+ }
5354
+ txRequest.shiftPredicateData();
5355
+ txRequest.updatePredicateGasUsed(estimatedPredicates);
5356
+ const requestToBeReEstimate = (0, import_ramda4.clone)(txRequest);
5357
+ if (addedSignatures) {
5358
+ Array.from({ length: addedSignatures }).forEach(
5359
+ () => requestToBeReEstimate.addEmptyWitness()
5360
+ );
5050
5361
  }
5362
+ const { maxFee } = await this.provider.estimateTxGasAndFee({
5363
+ transactionRequest: requestToBeReEstimate
5364
+ });
5365
+ txRequest.maxFee = maxFee;
5366
+ return txRequest;
5051
5367
  }
5052
5368
  /**
5053
5369
  * A helper that creates a transfer transaction request and returns it.
@@ -5055,29 +5371,25 @@ var Account = class extends import_interfaces.AbstractAccount {
5055
5371
  * @param destination - The address of the destination.
5056
5372
  * @param amount - The amount of coins to transfer.
5057
5373
  * @param assetId - The asset ID of the coins to transfer.
5058
- * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
5374
+ * @param txParams - The transaction parameters (gasLimit, tip, maturity, maxFee, witnessLimit).
5059
5375
  * @returns A promise that resolves to the prepared transaction request.
5060
5376
  */
5061
- async createTransfer(destination, amount, assetId, txParams = {}) {
5062
- const { minGasPrice } = this.provider.getGasConfig();
5063
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
5064
- const params = { gasPrice: minGasPrice, ...txParams };
5065
- const request = new ScriptTransactionRequest(params);
5066
- request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetIdToTransfer);
5067
- const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
5377
+ async createTransfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
5378
+ const request = new ScriptTransactionRequest(txParams);
5379
+ request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetId);
5380
+ const txCost = await this.provider.getTransactionCost(request, {
5068
5381
  estimateTxDependencies: true,
5069
5382
  resourcesOwner: this
5070
5383
  });
5071
- request.gasPrice = (0, import_math17.bn)(txParams.gasPrice ?? minGasPrice);
5072
- request.gasLimit = (0, import_math17.bn)(txParams.gasLimit ?? gasUsed);
5073
- this.validateGas({
5074
- gasUsed,
5075
- gasPrice: request.gasPrice,
5076
- gasLimit: request.gasLimit,
5077
- minGasPrice
5078
- });
5079
- await this.fund(request, requiredQuantities, maxFee);
5080
- request.updatePredicateInputs(estimatedInputs);
5384
+ if ("gasLimit" in txParams) {
5385
+ this.validateGas({
5386
+ gasUsed: txCost.gasUsed,
5387
+ gasLimit: request.gasLimit
5388
+ });
5389
+ }
5390
+ request.gasLimit = txCost.gasUsed;
5391
+ request.maxFee = txCost.maxFee;
5392
+ await this.fund(request, txCost);
5081
5393
  return request;
5082
5394
  }
5083
5395
  /**
@@ -5089,15 +5401,14 @@ var Account = class extends import_interfaces.AbstractAccount {
5089
5401
  * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
5090
5402
  * @returns A promise that resolves to the transaction response.
5091
5403
  */
5092
- async transfer(destination, amount, assetId, txParams = {}) {
5093
- if ((0, import_math17.bn)(amount).lte(0)) {
5094
- throw new import_errors15.FuelError(
5095
- import_errors15.ErrorCode.INVALID_TRANSFER_AMOUNT,
5404
+ async transfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
5405
+ if ((0, import_math19.bn)(amount).lte(0)) {
5406
+ throw new import_errors16.FuelError(
5407
+ import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
5096
5408
  "Transfer amount must be a positive number."
5097
5409
  );
5098
5410
  }
5099
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
5100
- const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
5411
+ const request = await this.createTransfer(destination, amount, assetId, txParams);
5101
5412
  return this.sendTransaction(request, { estimateTxDependencies: false });
5102
5413
  }
5103
5414
  /**
@@ -5109,40 +5420,38 @@ var Account = class extends import_interfaces.AbstractAccount {
5109
5420
  * @param txParams - The optional transaction parameters.
5110
5421
  * @returns A promise that resolves to the transaction response.
5111
5422
  */
5112
- async transferToContract(contractId, amount, assetId, txParams = {}) {
5113
- if ((0, import_math17.bn)(amount).lte(0)) {
5114
- throw new import_errors15.FuelError(
5115
- import_errors15.ErrorCode.INVALID_TRANSFER_AMOUNT,
5423
+ async transferToContract(contractId, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
5424
+ if ((0, import_math19.bn)(amount).lte(0)) {
5425
+ throw new import_errors16.FuelError(
5426
+ import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
5116
5427
  "Transfer amount must be a positive number."
5117
5428
  );
5118
5429
  }
5119
5430
  const contractAddress = import_address4.Address.fromAddressOrString(contractId);
5120
- const { minGasPrice } = this.provider.getGasConfig();
5121
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
5122
- const params = { gasPrice: minGasPrice, ...txParams };
5123
5431
  const { script, scriptData } = await assembleTransferToContractScript({
5124
5432
  hexlifiedContractId: contractAddress.toB256(),
5125
- amountToTransfer: (0, import_math17.bn)(amount),
5126
- assetId: assetIdToTransfer
5433
+ amountToTransfer: (0, import_math19.bn)(amount),
5434
+ assetId
5127
5435
  });
5128
5436
  const request = new ScriptTransactionRequest({
5129
- ...params,
5437
+ ...txParams,
5130
5438
  script,
5131
5439
  scriptData
5132
5440
  });
5133
5441
  request.addContractInputAndOutput(contractAddress);
5134
- const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
5135
- request,
5136
- [{ amount: (0, import_math17.bn)(amount), assetId: String(assetIdToTransfer) }]
5137
- );
5138
- request.gasLimit = (0, import_math17.bn)(params.gasLimit ?? gasUsed);
5139
- this.validateGas({
5140
- gasUsed,
5141
- gasPrice: request.gasPrice,
5142
- gasLimit: request.gasLimit,
5143
- minGasPrice
5442
+ const txCost = await this.provider.getTransactionCost(request, {
5443
+ resourcesOwner: this,
5444
+ quantitiesToContract: [{ amount: (0, import_math19.bn)(amount), assetId: String(assetId) }]
5144
5445
  });
5145
- await this.fund(request, requiredQuantities, maxFee);
5446
+ if (txParams.gasLimit) {
5447
+ this.validateGas({
5448
+ gasUsed: txCost.gasUsed,
5449
+ gasLimit: request.gasLimit
5450
+ });
5451
+ }
5452
+ request.gasLimit = txCost.gasUsed;
5453
+ request.maxFee = txCost.maxFee;
5454
+ await this.fund(request, txCost);
5146
5455
  return this.sendTransaction(request);
5147
5456
  }
5148
5457
  /**
@@ -5154,40 +5463,36 @@ var Account = class extends import_interfaces.AbstractAccount {
5154
5463
  * @returns A promise that resolves to the transaction response.
5155
5464
  */
5156
5465
  async withdrawToBaseLayer(recipient, amount, txParams = {}) {
5157
- const { minGasPrice } = this.provider.getGasConfig();
5158
- const baseAssetId = this.provider.getBaseAssetId();
5159
5466
  const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
5160
5467
  const recipientDataArray = (0, import_utils27.arrayify)(
5161
5468
  "0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
5162
5469
  );
5163
5470
  const amountDataArray = (0, import_utils27.arrayify)(
5164
- "0x".concat((0, import_math17.bn)(amount).toHex().substring(2).padStart(16, "0"))
5471
+ "0x".concat((0, import_math19.bn)(amount).toHex().substring(2).padStart(16, "0"))
5165
5472
  );
5166
5473
  const script = new Uint8Array([
5167
5474
  ...(0, import_utils27.arrayify)(withdrawScript.bytes),
5168
5475
  ...recipientDataArray,
5169
5476
  ...amountDataArray
5170
5477
  ]);
5171
- const params = { script, gasPrice: minGasPrice, ...txParams };
5478
+ const params = { script, ...txParams };
5172
5479
  const request = new ScriptTransactionRequest(params);
5173
- const forwardingQuantities = [{ amount: (0, import_math17.bn)(amount), assetId: baseAssetId }];
5174
- const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
5175
- request,
5176
- forwardingQuantities
5177
- );
5178
- request.gasLimit = (0, import_math17.bn)(params.gasLimit ?? gasUsed);
5179
- this.validateGas({
5180
- gasUsed,
5181
- gasPrice: request.gasPrice,
5182
- gasLimit: request.gasLimit,
5183
- minGasPrice
5184
- });
5185
- await this.fund(request, requiredQuantities, maxFee);
5480
+ const quantitiesToContract = [{ amount: (0, import_math19.bn)(amount), assetId: import_configs12.BaseAssetId }];
5481
+ const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
5482
+ if (txParams.gasLimit) {
5483
+ this.validateGas({
5484
+ gasUsed: txCost.gasUsed,
5485
+ gasLimit: request.gasLimit
5486
+ });
5487
+ }
5488
+ request.maxFee = txCost.maxFee;
5489
+ request.gasLimit = txCost.gasUsed;
5490
+ await this.fund(request, txCost);
5186
5491
  return this.sendTransaction(request);
5187
5492
  }
5188
5493
  async signMessage(message) {
5189
5494
  if (!this._connector) {
5190
- throw new import_errors15.FuelError(import_errors15.ErrorCode.MISSING_CONNECTOR, "A connector is required to sign messages.");
5495
+ throw new import_errors16.FuelError(import_errors16.ErrorCode.MISSING_CONNECTOR, "A connector is required to sign messages.");
5191
5496
  }
5192
5497
  return this._connector.signMessage(this.address.toString(), message);
5193
5498
  }
@@ -5199,8 +5504,8 @@ var Account = class extends import_interfaces.AbstractAccount {
5199
5504
  */
5200
5505
  async signTransaction(transactionRequestLike) {
5201
5506
  if (!this._connector) {
5202
- throw new import_errors15.FuelError(
5203
- import_errors15.ErrorCode.MISSING_CONNECTOR,
5507
+ throw new import_errors16.FuelError(
5508
+ import_errors16.ErrorCode.MISSING_CONNECTOR,
5204
5509
  "A connector is required to sign transactions."
5205
5510
  );
5206
5511
  }
@@ -5240,21 +5545,10 @@ var Account = class extends import_interfaces.AbstractAccount {
5240
5545
  }
5241
5546
  return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
5242
5547
  }
5243
- validateGas({
5244
- gasUsed,
5245
- gasPrice,
5246
- gasLimit,
5247
- minGasPrice
5248
- }) {
5249
- if (minGasPrice.gt(gasPrice)) {
5250
- throw new import_errors15.FuelError(
5251
- import_errors15.ErrorCode.GAS_PRICE_TOO_LOW,
5252
- `Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
5253
- );
5254
- }
5548
+ validateGas({ gasUsed, gasLimit }) {
5255
5549
  if (gasUsed.gt(gasLimit)) {
5256
- throw new import_errors15.FuelError(
5257
- import_errors15.ErrorCode.GAS_LIMIT_TOO_LOW,
5550
+ throw new import_errors16.FuelError(
5551
+ import_errors16.ErrorCode.GAS_LIMIT_TOO_LOW,
5258
5552
  `Gas limit '${gasLimit}' is lower than the required: '${gasUsed}'.`
5259
5553
  );
5260
5554
  }
@@ -5269,7 +5563,7 @@ var import_utils30 = require("@fuel-ts/utils");
5269
5563
  var import_address5 = require("@fuel-ts/address");
5270
5564
  var import_crypto = require("@fuel-ts/crypto");
5271
5565
  var import_hasher2 = require("@fuel-ts/hasher");
5272
- var import_math18 = require("@fuel-ts/math");
5566
+ var import_math20 = require("@fuel-ts/math");
5273
5567
  var import_utils28 = require("@fuel-ts/utils");
5274
5568
  var import_secp256k1 = require("@noble/curves/secp256k1");
5275
5569
  var Signer = class {
@@ -5289,7 +5583,7 @@ var Signer = class {
5289
5583
  privateKey = `0x${privateKey}`;
5290
5584
  }
5291
5585
  }
5292
- const privateKeyBytes = (0, import_math18.toBytes)(privateKey, 32);
5586
+ const privateKeyBytes = (0, import_math20.toBytes)(privateKey, 32);
5293
5587
  this.privateKey = (0, import_utils28.hexlify)(privateKeyBytes);
5294
5588
  this.publicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
5295
5589
  this.compressedPublicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
@@ -5307,8 +5601,8 @@ var Signer = class {
5307
5601
  */
5308
5602
  sign(data) {
5309
5603
  const signature = import_secp256k1.secp256k1.sign((0, import_utils28.arrayify)(data), (0, import_utils28.arrayify)(this.privateKey));
5310
- const r = (0, import_math18.toBytes)(`0x${signature.r.toString(16)}`, 32);
5311
- const s = (0, import_math18.toBytes)(`0x${signature.s.toString(16)}`, 32);
5604
+ const r = (0, import_math20.toBytes)(`0x${signature.r.toString(16)}`, 32);
5605
+ const s = (0, import_math20.toBytes)(`0x${signature.s.toString(16)}`, 32);
5312
5606
  s[0] |= (signature.recovery || 0) << 7;
5313
5607
  return (0, import_utils28.hexlify)((0, import_utils28.concat)([r, s]));
5314
5608
  }
@@ -5377,7 +5671,7 @@ var Signer = class {
5377
5671
  // src/wallet/keystore-wallet.ts
5378
5672
  var import_address6 = require("@fuel-ts/address");
5379
5673
  var import_crypto2 = require("@fuel-ts/crypto");
5380
- var import_errors16 = require("@fuel-ts/errors");
5674
+ var import_errors17 = require("@fuel-ts/errors");
5381
5675
  var import_utils29 = require("@fuel-ts/utils");
5382
5676
  var import_uuid = require("uuid");
5383
5677
  var DEFAULT_KDF_PARAMS_LOG_N = 13;
@@ -5455,8 +5749,8 @@ async function decryptKeystoreWallet(jsonWallet, password) {
5455
5749
  const macHashUint8Array = (0, import_crypto2.keccak256)(data);
5456
5750
  const macHash = (0, import_crypto2.stringFromBuffer)(macHashUint8Array, "hex");
5457
5751
  if (mac !== macHash) {
5458
- throw new import_errors16.FuelError(
5459
- import_errors16.ErrorCode.INVALID_PASSWORD,
5752
+ throw new import_errors17.FuelError(
5753
+ import_errors17.ErrorCode.INVALID_PASSWORD,
5460
5754
  "Failed to decrypt the keystore wallet, the provided password is incorrect."
5461
5755
  );
5462
5756
  }
@@ -5539,7 +5833,7 @@ var BaseWalletUnlocked = class extends Account {
5539
5833
  * @param transactionRequestLike - The transaction request to send.
5540
5834
  * @returns A promise that resolves to the TransactionResponse object.
5541
5835
  */
5542
- async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
5836
+ async sendTransaction(transactionRequestLike, { estimateTxDependencies = false, awaitExecution } = {}) {
5543
5837
  const transactionRequest = transactionRequestify(transactionRequestLike);
5544
5838
  if (estimateTxDependencies) {
5545
5839
  await this.provider.estimateTxDependencies(transactionRequest);
@@ -5578,18 +5872,18 @@ var BaseWalletUnlocked = class extends Account {
5578
5872
  __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
5579
5873
 
5580
5874
  // src/hdwallet/hdwallet.ts
5581
- var import_errors19 = require("@fuel-ts/errors");
5875
+ var import_errors20 = require("@fuel-ts/errors");
5582
5876
  var import_hasher6 = require("@fuel-ts/hasher");
5583
- var import_math19 = require("@fuel-ts/math");
5877
+ var import_math21 = require("@fuel-ts/math");
5584
5878
  var import_utils34 = require("@fuel-ts/utils");
5585
- var import_ethers3 = require("ethers");
5879
+ var import_ethers4 = require("ethers");
5586
5880
 
5587
5881
  // src/mnemonic/mnemonic.ts
5588
5882
  var import_crypto3 = require("@fuel-ts/crypto");
5589
- var import_errors18 = require("@fuel-ts/errors");
5883
+ var import_errors19 = require("@fuel-ts/errors");
5590
5884
  var import_hasher5 = require("@fuel-ts/hasher");
5591
5885
  var import_utils32 = require("@fuel-ts/utils");
5592
- var import_ethers2 = require("ethers");
5886
+ var import_ethers3 = require("ethers");
5593
5887
 
5594
5888
  // src/wordlists/words/english.ts
5595
5889
  var english = [
@@ -7650,7 +7944,7 @@ var Language = /* @__PURE__ */ ((Language2) => {
7650
7944
  })(Language || {});
7651
7945
 
7652
7946
  // src/mnemonic/utils.ts
7653
- var import_errors17 = require("@fuel-ts/errors");
7947
+ var import_errors18 = require("@fuel-ts/errors");
7654
7948
  var import_hasher4 = require("@fuel-ts/hasher");
7655
7949
  var import_utils31 = require("@fuel-ts/utils");
7656
7950
  function toUtf8Bytes(stri) {
@@ -7667,8 +7961,8 @@ function toUtf8Bytes(stri) {
7667
7961
  i += 1;
7668
7962
  const c2 = str.charCodeAt(i);
7669
7963
  if (i >= str.length || (c2 & 64512) !== 56320) {
7670
- throw new import_errors17.FuelError(
7671
- import_errors17.ErrorCode.INVALID_INPUT_PARAMETERS,
7964
+ throw new import_errors18.FuelError(
7965
+ import_errors18.ErrorCode.INVALID_INPUT_PARAMETERS,
7672
7966
  "Invalid UTF-8 in the input string."
7673
7967
  );
7674
7968
  }
@@ -7731,8 +8025,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
7731
8025
  for (let i = 0; i < words.length; i += 1) {
7732
8026
  const index = wordlist.indexOf(words[i].normalize("NFKD"));
7733
8027
  if (index === -1) {
7734
- throw new import_errors17.FuelError(
7735
- import_errors17.ErrorCode.INVALID_MNEMONIC,
8028
+ throw new import_errors18.FuelError(
8029
+ import_errors18.ErrorCode.INVALID_MNEMONIC,
7736
8030
  `Invalid mnemonic: the word '${words[i]}' is not found in the provided wordlist.`
7737
8031
  );
7738
8032
  }
@@ -7748,8 +8042,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
7748
8042
  const checksumMask = getUpperMask(checksumBits);
7749
8043
  const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
7750
8044
  if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
7751
- throw new import_errors17.FuelError(
7752
- import_errors17.ErrorCode.INVALID_CHECKSUM,
8045
+ throw new import_errors18.FuelError(
8046
+ import_errors18.ErrorCode.INVALID_CHECKSUM,
7753
8047
  "Checksum validation failed for the provided mnemonic."
7754
8048
  );
7755
8049
  }
@@ -7763,16 +8057,16 @@ var TestnetPRV = "0x04358394";
7763
8057
  var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
7764
8058
  function assertWordList(wordlist) {
7765
8059
  if (wordlist.length !== 2048) {
7766
- throw new import_errors18.FuelError(
7767
- import_errors18.ErrorCode.INVALID_WORD_LIST,
8060
+ throw new import_errors19.FuelError(
8061
+ import_errors19.ErrorCode.INVALID_WORD_LIST,
7768
8062
  `Expected word list length of 2048, but got ${wordlist.length}.`
7769
8063
  );
7770
8064
  }
7771
8065
  }
7772
8066
  function assertEntropy(entropy) {
7773
8067
  if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {
7774
- throw new import_errors18.FuelError(
7775
- import_errors18.ErrorCode.INVALID_ENTROPY,
8068
+ throw new import_errors19.FuelError(
8069
+ import_errors19.ErrorCode.INVALID_ENTROPY,
7776
8070
  `Entropy should be between 16 and 32 bytes and a multiple of 4, but got ${entropy.length} bytes.`
7777
8071
  );
7778
8072
  }
@@ -7782,7 +8076,7 @@ function assertMnemonic(words) {
7782
8076
  const errorMsg = `Invalid mnemonic size. Expected one of [${MNEMONIC_SIZES.join(
7783
8077
  ", "
7784
8078
  )}] words, but got ${words.length}.`;
7785
- throw new import_errors18.FuelError(import_errors18.ErrorCode.INVALID_MNEMONIC, errorMsg);
8079
+ throw new import_errors19.FuelError(import_errors19.ErrorCode.INVALID_MNEMONIC, errorMsg);
7786
8080
  }
7787
8081
  }
7788
8082
  var Mnemonic = class {
@@ -7843,7 +8137,7 @@ var Mnemonic = class {
7843
8137
  assertMnemonic(getWords(phrase));
7844
8138
  const phraseBytes = toUtf8Bytes(getPhrase(phrase));
7845
8139
  const salt = toUtf8Bytes(`mnemonic${passphrase}`);
7846
- return (0, import_ethers2.pbkdf2)(phraseBytes, salt, 2048, 64, "sha512");
8140
+ return (0, import_ethers3.pbkdf2)(phraseBytes, salt, 2048, 64, "sha512");
7847
8141
  }
7848
8142
  /**
7849
8143
  * @param phrase - Mnemonic phrase composed by words from the provided wordlist
@@ -7900,12 +8194,12 @@ var Mnemonic = class {
7900
8194
  static masterKeysFromSeed(seed) {
7901
8195
  const seedArray = (0, import_utils32.arrayify)(seed);
7902
8196
  if (seedArray.length < 16 || seedArray.length > 64) {
7903
- throw new import_errors18.FuelError(
7904
- import_errors18.ErrorCode.INVALID_SEED,
8197
+ throw new import_errors19.FuelError(
8198
+ import_errors19.ErrorCode.INVALID_SEED,
7905
8199
  `Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
7906
8200
  );
7907
8201
  }
7908
- return (0, import_utils32.arrayify)((0, import_ethers2.computeHmac)("sha512", MasterSecret, seedArray));
8202
+ return (0, import_utils32.arrayify)((0, import_ethers3.computeHmac)("sha512", MasterSecret, seedArray));
7909
8203
  }
7910
8204
  /**
7911
8205
  * Get the extendKey as defined on BIP-32 from the provided seed
@@ -7930,8 +8224,8 @@ var Mnemonic = class {
7930
8224
  chainCode,
7931
8225
  (0, import_utils32.concat)(["0x00", privateKey])
7932
8226
  ]);
7933
- const checksum = (0, import_ethers2.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
7934
- return (0, import_ethers2.encodeBase58)((0, import_utils32.concat)([extendedKey, checksum]));
8227
+ const checksum = (0, import_ethers3.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
8228
+ return (0, import_ethers3.encodeBase58)((0, import_utils32.concat)([extendedKey, checksum]));
7935
8229
  }
7936
8230
  /**
7937
8231
  * Create a new mnemonic using a randomly generated number as entropy.
@@ -7959,7 +8253,7 @@ var MainnetPUB = (0, import_utils34.hexlify)("0x0488b21e");
7959
8253
  var TestnetPRV2 = (0, import_utils34.hexlify)("0x04358394");
7960
8254
  var TestnetPUB = (0, import_utils34.hexlify)("0x043587cf");
7961
8255
  function base58check(data) {
7962
- return (0, import_ethers3.encodeBase58)((0, import_utils34.concat)([data, (0, import_ethers3.dataSlice)((0, import_hasher6.sha256)((0, import_hasher6.sha256)(data)), 0, 4)]));
8256
+ return (0, import_ethers4.encodeBase58)((0, import_utils34.concat)([data, (0, import_ethers4.dataSlice)((0, import_hasher6.sha256)((0, import_hasher6.sha256)(data)), 0, 4)]));
7963
8257
  }
7964
8258
  function getExtendedKeyPrefix(isPublic = false, testnet = false) {
7965
8259
  if (isPublic) {
@@ -7978,7 +8272,7 @@ function isValidExtendedKey(extendedKey) {
7978
8272
  function parsePath(path, depth = 0) {
7979
8273
  const components = path.split("/");
7980
8274
  if (components.length === 0 || components[0] === "m" && depth !== 0) {
7981
- throw new import_errors19.FuelError(import_errors19.ErrorCode.HD_WALLET_ERROR, `invalid path - ${path}`);
8275
+ throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, `invalid path - ${path}`);
7982
8276
  }
7983
8277
  if (components[0] === "m") {
7984
8278
  components.shift();
@@ -8007,15 +8301,15 @@ var HDWallet = class {
8007
8301
  this.privateKey = (0, import_utils34.hexlify)(config.privateKey);
8008
8302
  } else {
8009
8303
  if (!config.publicKey) {
8010
- throw new import_errors19.FuelError(
8011
- import_errors19.ErrorCode.HD_WALLET_ERROR,
8304
+ throw new import_errors20.FuelError(
8305
+ import_errors20.ErrorCode.HD_WALLET_ERROR,
8012
8306
  "Both public and private Key cannot be missing. At least one should be provided."
8013
8307
  );
8014
8308
  }
8015
8309
  this.publicKey = (0, import_utils34.hexlify)(config.publicKey);
8016
8310
  }
8017
8311
  this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
8018
- this.fingerprint = (0, import_ethers3.dataSlice)((0, import_ethers3.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
8312
+ this.fingerprint = (0, import_ethers4.dataSlice)((0, import_ethers4.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
8019
8313
  this.depth = config.depth || this.depth;
8020
8314
  this.index = config.index || this.index;
8021
8315
  this.chainCode = config.chainCode;
@@ -8037,8 +8331,8 @@ var HDWallet = class {
8037
8331
  const data = new Uint8Array(37);
8038
8332
  if (index & HARDENED_INDEX) {
8039
8333
  if (!privateKey) {
8040
- throw new import_errors19.FuelError(
8041
- import_errors19.ErrorCode.HD_WALLET_ERROR,
8334
+ throw new import_errors20.FuelError(
8335
+ import_errors20.ErrorCode.HD_WALLET_ERROR,
8042
8336
  "Cannot derive a hardened index without a private Key."
8043
8337
  );
8044
8338
  }
@@ -8046,13 +8340,13 @@ var HDWallet = class {
8046
8340
  } else {
8047
8341
  data.set((0, import_utils34.arrayify)(this.publicKey));
8048
8342
  }
8049
- data.set((0, import_math19.toBytes)(index, 4), 33);
8050
- const bytes = (0, import_utils34.arrayify)((0, import_ethers3.computeHmac)("sha512", chainCode, data));
8343
+ data.set((0, import_math21.toBytes)(index, 4), 33);
8344
+ const bytes = (0, import_utils34.arrayify)((0, import_ethers4.computeHmac)("sha512", chainCode, data));
8051
8345
  const IL = bytes.slice(0, 32);
8052
8346
  const IR = bytes.slice(32);
8053
8347
  if (privateKey) {
8054
8348
  const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
8055
- const ki = (0, import_math19.bn)(IL).add(privateKey).mod(N).toBytes(32);
8349
+ const ki = (0, import_math21.bn)(IL).add(privateKey).mod(N).toBytes(32);
8056
8350
  return new HDWallet({
8057
8351
  privateKey: ki,
8058
8352
  chainCode: IR,
@@ -8090,15 +8384,15 @@ var HDWallet = class {
8090
8384
  */
8091
8385
  toExtendedKey(isPublic = false, testnet = false) {
8092
8386
  if (this.depth >= 256) {
8093
- throw new import_errors19.FuelError(
8094
- import_errors19.ErrorCode.HD_WALLET_ERROR,
8387
+ throw new import_errors20.FuelError(
8388
+ import_errors20.ErrorCode.HD_WALLET_ERROR,
8095
8389
  `Exceeded max depth of 255. Current depth: ${this.depth}.`
8096
8390
  );
8097
8391
  }
8098
8392
  const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
8099
8393
  const depth = (0, import_utils34.hexlify)(Uint8Array.from([this.depth]));
8100
8394
  const parentFingerprint = this.parentFingerprint;
8101
- const index = (0, import_math19.toHex)(this.index, 4);
8395
+ const index = (0, import_math21.toHex)(this.index, 4);
8102
8396
  const chainCode = this.chainCode;
8103
8397
  const key = this.privateKey != null && !isPublic ? (0, import_utils34.concat)(["0x00", this.privateKey]) : this.publicKey;
8104
8398
  const extendedKey = (0, import_utils34.arrayify)((0, import_utils34.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
@@ -8118,14 +8412,14 @@ var HDWallet = class {
8118
8412
  });
8119
8413
  }
8120
8414
  static fromExtendedKey(extendedKey) {
8121
- const decoded = (0, import_ethers3.toBeHex)((0, import_ethers3.decodeBase58)(extendedKey));
8415
+ const decoded = (0, import_ethers4.toBeHex)((0, import_ethers4.decodeBase58)(extendedKey));
8122
8416
  const bytes = (0, import_utils34.arrayify)(decoded);
8123
8417
  const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
8124
8418
  if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
8125
- throw new import_errors19.FuelError(import_errors19.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
8419
+ throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
8126
8420
  }
8127
8421
  if (!validChecksum) {
8128
- throw new import_errors19.FuelError(import_errors19.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
8422
+ throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
8129
8423
  }
8130
8424
  const depth = bytes[4];
8131
8425
  const parentFingerprint = (0, import_utils34.hexlify)(bytes.slice(5, 9));
@@ -8133,14 +8427,14 @@ var HDWallet = class {
8133
8427
  const chainCode = (0, import_utils34.hexlify)(bytes.slice(13, 45));
8134
8428
  const key = bytes.slice(45, 78);
8135
8429
  if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
8136
- throw new import_errors19.FuelError(
8137
- import_errors19.ErrorCode.HD_WALLET_ERROR,
8430
+ throw new import_errors20.FuelError(
8431
+ import_errors20.ErrorCode.HD_WALLET_ERROR,
8138
8432
  "Inconsistency detected: Depth is zero but fingerprint/index is non-zero."
8139
8433
  );
8140
8434
  }
8141
8435
  if (isPublicExtendedKey(bytes)) {
8142
8436
  if (key[0] !== 3) {
8143
- throw new import_errors19.FuelError(import_errors19.ErrorCode.HD_WALLET_ERROR, "Invalid public extended key.");
8437
+ throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Invalid public extended key.");
8144
8438
  }
8145
8439
  return new HDWallet({
8146
8440
  publicKey: key,
@@ -8151,7 +8445,7 @@ var HDWallet = class {
8151
8445
  });
8152
8446
  }
8153
8447
  if (key[0] !== 0) {
8154
- throw new import_errors19.FuelError(import_errors19.ErrorCode.HD_WALLET_ERROR, "Invalid private extended key.");
8448
+ throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Invalid private extended key.");
8155
8449
  }
8156
8450
  return new HDWallet({
8157
8451
  privateKey: key.slice(1),
@@ -8319,7 +8613,7 @@ __publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
8319
8613
  // src/wallet-manager/wallet-manager.ts
8320
8614
  var import_address9 = require("@fuel-ts/address");
8321
8615
  var import_crypto4 = require("@fuel-ts/crypto");
8322
- var import_errors22 = require("@fuel-ts/errors");
8616
+ var import_errors23 = require("@fuel-ts/errors");
8323
8617
  var import_events = require("events");
8324
8618
 
8325
8619
  // src/wallet-manager/storages/memory-storage.ts
@@ -8342,7 +8636,7 @@ var MemoryStorage = class {
8342
8636
 
8343
8637
  // src/wallet-manager/vaults/mnemonic-vault.ts
8344
8638
  var import_address7 = require("@fuel-ts/address");
8345
- var import_errors20 = require("@fuel-ts/errors");
8639
+ var import_errors21 = require("@fuel-ts/errors");
8346
8640
  var _secret;
8347
8641
  var MnemonicVault = class {
8348
8642
  constructor(options) {
@@ -8398,8 +8692,8 @@ var MnemonicVault = class {
8398
8692
  }
8399
8693
  numberOfAccounts += 1;
8400
8694
  } while (numberOfAccounts < this.numberOfAccounts);
8401
- throw new import_errors20.FuelError(
8402
- import_errors20.ErrorCode.WALLET_MANAGER_ERROR,
8695
+ throw new import_errors21.FuelError(
8696
+ import_errors21.ErrorCode.WALLET_MANAGER_ERROR,
8403
8697
  `Account with address '${address}' not found in derived wallets.`
8404
8698
  );
8405
8699
  }
@@ -8413,7 +8707,7 @@ __publicField(MnemonicVault, "type", "mnemonic");
8413
8707
 
8414
8708
  // src/wallet-manager/vaults/privatekey-vault.ts
8415
8709
  var import_address8 = require("@fuel-ts/address");
8416
- var import_errors21 = require("@fuel-ts/errors");
8710
+ var import_errors22 = require("@fuel-ts/errors");
8417
8711
  var _privateKeys;
8418
8712
  var PrivateKeyVault = class {
8419
8713
  /**
@@ -8454,8 +8748,8 @@ var PrivateKeyVault = class {
8454
8748
  (pk) => Wallet.fromPrivateKey(pk).address.equals(ownerAddress)
8455
8749
  );
8456
8750
  if (!privateKey) {
8457
- throw new import_errors21.FuelError(
8458
- import_errors21.ErrorCode.WALLET_MANAGER_ERROR,
8751
+ throw new import_errors22.FuelError(
8752
+ import_errors22.ErrorCode.WALLET_MANAGER_ERROR,
8459
8753
  `No private key found for address '${address}'.`
8460
8754
  );
8461
8755
  }
@@ -8479,7 +8773,7 @@ var ERROR_MESSAGES = {
8479
8773
  };
8480
8774
  function assert(condition, message) {
8481
8775
  if (!condition) {
8482
- throw new import_errors22.FuelError(import_errors22.ErrorCode.WALLET_MANAGER_ERROR, message);
8776
+ throw new import_errors23.FuelError(import_errors23.ErrorCode.WALLET_MANAGER_ERROR, message);
8483
8777
  }
8484
8778
  }
8485
8779
  var _vaults, _passphrase, _isLocked, _serializeVaults, serializeVaults_fn, _deserializeVaults, deserializeVaults_fn;
@@ -8705,25 +8999,25 @@ deserializeVaults_fn = function(vaults) {
8705
8999
  __publicField(WalletManager, "Vaults", [MnemonicVault, PrivateKeyVault]);
8706
9000
 
8707
9001
  // src/wallet-manager/types.ts
8708
- var import_errors23 = require("@fuel-ts/errors");
9002
+ var import_errors24 = require("@fuel-ts/errors");
8709
9003
  var Vault = class {
8710
9004
  constructor(_options) {
8711
- throw new import_errors23.FuelError(import_errors23.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
9005
+ throw new import_errors24.FuelError(import_errors24.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
8712
9006
  }
8713
9007
  serialize() {
8714
- throw new import_errors23.FuelError(import_errors23.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
9008
+ throw new import_errors24.FuelError(import_errors24.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
8715
9009
  }
8716
9010
  getAccounts() {
8717
- throw new import_errors23.FuelError(import_errors23.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
9011
+ throw new import_errors24.FuelError(import_errors24.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
8718
9012
  }
8719
9013
  addAccount() {
8720
- throw new import_errors23.FuelError(import_errors23.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
9014
+ throw new import_errors24.FuelError(import_errors24.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
8721
9015
  }
8722
9016
  exportAccount(_address) {
8723
- throw new import_errors23.FuelError(import_errors23.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
9017
+ throw new import_errors24.FuelError(import_errors24.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
8724
9018
  }
8725
9019
  getWallet(_address) {
8726
- throw new import_errors23.FuelError(import_errors23.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
9020
+ throw new import_errors24.FuelError(import_errors24.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
8727
9021
  }
8728
9022
  };
8729
9023
  __publicField(Vault, "type");
@@ -8733,8 +9027,9 @@ var StorageAbstract = class {
8733
9027
  // src/predicate/predicate.ts
8734
9028
  var import_abi_coder5 = require("@fuel-ts/abi-coder");
8735
9029
  var import_address10 = require("@fuel-ts/address");
8736
- var import_errors24 = require("@fuel-ts/errors");
8737
- var import_transactions19 = require("@fuel-ts/transactions");
9030
+ var import_configs13 = require("@fuel-ts/address/configs");
9031
+ var import_errors25 = require("@fuel-ts/errors");
9032
+ var import_transactions21 = require("@fuel-ts/transactions");
8738
9033
  var import_utils36 = require("@fuel-ts/utils");
8739
9034
 
8740
9035
  // src/predicate/utils/getPredicateRoot.ts
@@ -8783,6 +9078,7 @@ var Predicate = class extends Account {
8783
9078
  this.interface = predicateInterface;
8784
9079
  if (inputData !== void 0 && inputData.length > 0) {
8785
9080
  this.predicateData = inputData;
9081
+ this.predicateDataBytes = this.getPredicateData(0);
8786
9082
  }
8787
9083
  }
8788
9084
  /**
@@ -8795,9 +9091,9 @@ var Predicate = class extends Account {
8795
9091
  const request = transactionRequestify(transactionRequestLike);
8796
9092
  const { policies } = BaseTransactionRequest.getPolicyMeta(request);
8797
9093
  request.inputs?.forEach((input) => {
8798
- if (input.type === import_transactions19.InputType.Coin && (0, import_utils36.hexlify)(input.owner) === this.address.toB256()) {
8799
- input.predicate = this.bytes;
8800
- input.predicateData = this.getPredicateData(policies.length);
9094
+ if (input.type === import_transactions21.InputType.Coin && (0, import_utils36.hexlify)(input.owner) === this.address.toB256()) {
9095
+ input.predicate = (0, import_utils36.hexlify)(this.bytes);
9096
+ input.predicateData = (0, import_utils36.hexlify)(this.getPredicateData(policies.length));
8801
9097
  }
8802
9098
  });
8803
9099
  return request;
@@ -8811,10 +9107,8 @@ var Predicate = class extends Account {
8811
9107
  * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
8812
9108
  * @returns A promise that resolves to the prepared transaction request.
8813
9109
  */
8814
- async createTransfer(destination, amount, assetId, txParams = {}) {
8815
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
8816
- const request = await super.createTransfer(destination, amount, assetIdToTransfer, txParams);
8817
- return this.populateTransactionPredicateData(request);
9110
+ async createTransfer(destination, amount, assetId = import_configs13.BaseAssetId, txParams = {}) {
9111
+ return super.createTransfer(destination, amount, assetId, txParams);
8818
9112
  }
8819
9113
  /**
8820
9114
  * Sends a transaction with the populated predicate data.
@@ -8822,9 +9116,9 @@ var Predicate = class extends Account {
8822
9116
  * @param transactionRequestLike - The transaction request-like object.
8823
9117
  * @returns A promise that resolves to the transaction response.
8824
9118
  */
8825
- sendTransaction(transactionRequestLike, options) {
8826
- const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
8827
- return super.sendTransaction(transactionRequest, options);
9119
+ sendTransaction(transactionRequestLike) {
9120
+ const transactionRequest = transactionRequestify(transactionRequestLike);
9121
+ return super.sendTransaction(transactionRequest, { estimateTxDependencies: false });
8828
9122
  }
8829
9123
  /**
8830
9124
  * Simulates a transaction with the populated predicate data.
@@ -8833,15 +9127,15 @@ var Predicate = class extends Account {
8833
9127
  * @returns A promise that resolves to the call result.
8834
9128
  */
8835
9129
  simulateTransaction(transactionRequestLike) {
8836
- const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
8837
- return super.simulateTransaction(transactionRequest);
9130
+ const transactionRequest = transactionRequestify(transactionRequestLike);
9131
+ return super.simulateTransaction(transactionRequest, { estimateTxDependencies: false });
8838
9132
  }
8839
9133
  getPredicateData(policiesLength) {
8840
9134
  if (!this.predicateData.length) {
8841
9135
  return new Uint8Array();
8842
9136
  }
8843
9137
  const mainFn = this.interface?.functions.main;
8844
- const paddedCode = new import_transactions19.ByteArrayCoder(this.bytes.length).encode(this.bytes);
9138
+ const paddedCode = new import_transactions21.ByteArrayCoder(this.bytes.length).encode(this.bytes);
8845
9139
  const VM_TX_MEMORY = (0, import_abi_coder5.calculateVmTxMemory)({
8846
9140
  maxInputs: this.provider.getChain().consensusParameters.maxInputs.toNumber()
8847
9141
  });
@@ -8862,8 +9156,8 @@ var Predicate = class extends Account {
8862
9156
  if (jsonAbi) {
8863
9157
  abiInterface = new import_abi_coder5.Interface(jsonAbi);
8864
9158
  if (abiInterface.functions.main === void 0) {
8865
- throw new import_errors24.FuelError(
8866
- import_errors24.ErrorCode.ABI_MAIN_METHOD_MISSING,
9159
+ throw new import_errors25.FuelError(
9160
+ import_errors25.ErrorCode.ABI_MAIN_METHOD_MISSING,
8867
9161
  'Cannot use ABI without "main" function.'
8868
9162
  );
8869
9163
  }
@@ -8880,6 +9174,26 @@ var Predicate = class extends Account {
8880
9174
  predicateInterface: abiInterface
8881
9175
  };
8882
9176
  }
9177
+ /**
9178
+ * Retrieves resources satisfying the spend query for the account.
9179
+ *
9180
+ * @param quantities - IDs of coins to exclude.
9181
+ * @param excludedIds - IDs of resources to be excluded from the query.
9182
+ * @returns A promise that resolves to an array of Resources.
9183
+ */
9184
+ async getResourcesToSpend(quantities, excludedIds) {
9185
+ const resources = await this.provider.getResourcesToSpend(
9186
+ this.address,
9187
+ quantities,
9188
+ excludedIds
9189
+ );
9190
+ return resources.map((resource) => ({
9191
+ ...resource,
9192
+ predicate: (0, import_utils36.hexlify)(this.bytes),
9193
+ predicateData: (0, import_utils36.hexlify)(this.predicateDataBytes),
9194
+ paddPredicateData: (policiesLength) => (0, import_utils36.hexlify)(this.getPredicateData(policiesLength))
9195
+ }));
9196
+ }
8883
9197
  /**
8884
9198
  * Sets the configurable constants for the predicate.
8885
9199
  *
@@ -8908,8 +9222,8 @@ var Predicate = class extends Account {
8908
9222
  mutatedBytes.set(encoded, offset);
8909
9223
  });
8910
9224
  } catch (err) {
8911
- throw new import_errors24.FuelError(
8912
- import_errors24.ErrorCode.INVALID_CONFIGURABLE_CONSTANTS,
9225
+ throw new import_errors25.FuelError(
9226
+ import_errors25.ErrorCode.INVALID_CONFIGURABLE_CONSTANTS,
8913
9227
  `Error setting configurable constants: ${err.message}.`
8914
9228
  );
8915
9229
  }
@@ -8918,7 +9232,7 @@ var Predicate = class extends Account {
8918
9232
  };
8919
9233
 
8920
9234
  // src/connectors/fuel.ts
8921
- var import_errors25 = require("@fuel-ts/errors");
9235
+ var import_errors26 = require("@fuel-ts/errors");
8922
9236
 
8923
9237
  // src/connectors/fuel-connector.ts
8924
9238
  var import_events2 = require("events");
@@ -9551,7 +9865,7 @@ var _Fuel = class extends FuelConnector {
9551
9865
  const currentNetwork = await this.currentNetwork();
9552
9866
  provider = await Provider.create(currentNetwork.url);
9553
9867
  } else {
9554
- throw new import_errors25.FuelError(import_errors25.ErrorCode.INVALID_PROVIDER, "Provider is not valid.");
9868
+ throw new import_errors26.FuelError(import_errors26.ErrorCode.INVALID_PROVIDER, "Provider is not valid.");
9555
9869
  }
9556
9870
  return provider;
9557
9871
  }
@@ -9629,16 +9943,19 @@ __publicField(Fuel, "defaultConfig", {});
9629
9943
  WalletLocked,
9630
9944
  WalletManager,
9631
9945
  WalletUnlocked,
9632
- addAmountToAsset,
9946
+ addAmountToCoinQuantities,
9633
9947
  addOperation,
9948
+ assemblePanicError,
9634
9949
  assembleReceiptByType,
9950
+ assembleRevertError,
9635
9951
  assembleTransactionSummary,
9636
9952
  assets,
9637
9953
  buildBlockExplorerUrl,
9638
9954
  cacheFor,
9955
+ cacheTxInputsFromOwner,
9956
+ calculateGasFee,
9639
9957
  calculateMetadataGasForTxCreate,
9640
9958
  calculateMetadataGasForTxScript,
9641
- calculatePriceWithFactor,
9642
9959
  calculateTransactionFee,
9643
9960
  coinQuantityfy,
9644
9961
  deferPromise,
@@ -9646,6 +9963,7 @@ __publicField(Fuel, "defaultConfig", {});
9646
9963
  english,
9647
9964
  extractBurnedAssetsFromReceipts,
9648
9965
  extractMintedAssetsFromReceipts,
9966
+ extractTxError,
9649
9967
  gasUsedByInputs,
9650
9968
  getAssetEth,
9651
9969
  getAssetFuel,