@fuel-ts/account 0.0.0-rc-2130-20240422142413 → 0.0.0-rc-2021-20240422173414

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 (55) 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/hdwallet/hdwallet.d.ts.map +1 -1
  12. package/dist/index.global.js +3380 -1998
  13. package/dist/index.global.js.map +1 -1
  14. package/dist/index.js +786 -518
  15. package/dist/index.js.map +1 -1
  16. package/dist/index.mjs +663 -396
  17. package/dist/index.mjs.map +1 -1
  18. package/dist/mnemonic/mnemonic.d.ts.map +1 -1
  19. package/dist/predicate/predicate.d.ts +10 -2
  20. package/dist/predicate/predicate.d.ts.map +1 -1
  21. package/dist/providers/__generated__/operations.d.ts +906 -324
  22. package/dist/providers/__generated__/operations.d.ts.map +1 -1
  23. package/dist/providers/coin-quantity.d.ts +1 -1
  24. package/dist/providers/coin-quantity.d.ts.map +1 -1
  25. package/dist/providers/coin.d.ts +4 -2
  26. package/dist/providers/coin.d.ts.map +1 -1
  27. package/dist/providers/message.d.ts +7 -1
  28. package/dist/providers/message.d.ts.map +1 -1
  29. package/dist/providers/provider.d.ts +46 -27
  30. package/dist/providers/provider.d.ts.map +1 -1
  31. package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
  32. package/dist/providers/transaction-request/input.d.ts +2 -2
  33. package/dist/providers/transaction-request/input.d.ts.map +1 -1
  34. package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
  35. package/dist/providers/transaction-request/transaction-request.d.ts +8 -25
  36. package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
  37. package/dist/providers/transaction-request/utils.d.ts +3 -0
  38. package/dist/providers/transaction-request/utils.d.ts.map +1 -1
  39. package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
  40. package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts +2 -0
  41. package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
  42. package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts +3 -2
  43. package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts.map +1 -1
  44. package/dist/providers/transaction-summary/get-transaction-summary.d.ts.map +1 -1
  45. package/dist/providers/utils/gas.d.ts +8 -2
  46. package/dist/providers/utils/gas.d.ts.map +1 -1
  47. package/dist/test-utils/launchNode.d.ts.map +1 -1
  48. package/dist/test-utils.global.js +4111 -2491
  49. package/dist/test-utils.global.js.map +1 -1
  50. package/dist/test-utils.js +765 -515
  51. package/dist/test-utils.js.map +1 -1
  52. package/dist/test-utils.mjs +655 -405
  53. package/dist/test-utils.mjs.map +1 -1
  54. package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
  55. package/package.json +17 -16
package/dist/index.js CHANGED
@@ -95,7 +95,7 @@ __export(src_exports, {
95
95
  WalletLocked: () => WalletLocked,
96
96
  WalletManager: () => WalletManager,
97
97
  WalletUnlocked: () => WalletUnlocked,
98
- addAmountToAsset: () => addAmountToAsset,
98
+ addAmountToCoinQuantities: () => addAmountToCoinQuantities,
99
99
  addOperation: () => addOperation,
100
100
  assemblePanicError: () => assemblePanicError,
101
101
  assembleReceiptByType: () => assembleReceiptByType,
@@ -104,9 +104,10 @@ __export(src_exports, {
104
104
  assets: () => assets,
105
105
  buildBlockExplorerUrl: () => buildBlockExplorerUrl,
106
106
  cacheFor: () => cacheFor,
107
+ cacheTxInputsFromOwner: () => cacheTxInputsFromOwner,
108
+ calculateGasFee: () => calculateGasFee,
107
109
  calculateMetadataGasForTxCreate: () => calculateMetadataGasForTxCreate,
108
110
  calculateMetadataGasForTxScript: () => calculateMetadataGasForTxScript,
109
- calculatePriceWithFactor: () => calculatePriceWithFactor,
110
111
  calculateTransactionFee: () => calculateTransactionFee,
111
112
  coinQuantityfy: () => coinQuantityfy,
112
113
  deferPromise: () => deferPromise,
@@ -187,8 +188,9 @@ var import_address4 = require("@fuel-ts/address");
187
188
  var import_configs12 = require("@fuel-ts/address/configs");
188
189
  var import_errors16 = require("@fuel-ts/errors");
189
190
  var import_interfaces = require("@fuel-ts/interfaces");
190
- var import_math18 = require("@fuel-ts/math");
191
- var import_utils28 = require("@fuel-ts/utils");
191
+ var import_math19 = require("@fuel-ts/math");
192
+ var import_utils27 = require("@fuel-ts/utils");
193
+ var import_ramda4 = require("ramda");
192
194
 
193
195
  // src/providers/coin-quantity.ts
194
196
  var import_configs = require("@fuel-ts/address/configs");
@@ -197,24 +199,24 @@ var import_utils = require("@fuel-ts/utils");
197
199
  var coinQuantityfy = (coinQuantityLike) => {
198
200
  let assetId;
199
201
  let amount;
200
- let max2;
202
+ let max;
201
203
  if (Array.isArray(coinQuantityLike)) {
202
204
  amount = coinQuantityLike[0];
203
205
  assetId = coinQuantityLike[1] ?? import_configs.BaseAssetId;
204
- max2 = coinQuantityLike[2] ?? void 0;
206
+ max = coinQuantityLike[2] ?? void 0;
205
207
  } else {
206
208
  amount = coinQuantityLike.amount;
207
209
  assetId = coinQuantityLike.assetId ?? import_configs.BaseAssetId;
208
- max2 = coinQuantityLike.max ?? void 0;
210
+ max = coinQuantityLike.max ?? void 0;
209
211
  }
210
212
  const bnAmount = (0, import_math.bn)(amount);
211
213
  return {
212
214
  assetId: (0, import_utils.hexlify)(assetId),
213
215
  amount: bnAmount.lt(1) ? (0, import_math.bn)(1) : bnAmount,
214
- max: max2 ? (0, import_math.bn)(max2) : void 0
216
+ max: max ? (0, import_math.bn)(max) : void 0
215
217
  };
216
218
  };
217
- var addAmountToAsset = (params) => {
219
+ var addAmountToCoinQuantities = (params) => {
218
220
  const { amount, assetId } = params;
219
221
  const coinQuantities = [...params.coinQuantities];
220
222
  const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
@@ -229,11 +231,12 @@ var addAmountToAsset = (params) => {
229
231
  // src/providers/provider.ts
230
232
  var import_address3 = require("@fuel-ts/address");
231
233
  var import_errors14 = require("@fuel-ts/errors");
232
- var import_math15 = require("@fuel-ts/math");
233
- var import_transactions18 = require("@fuel-ts/transactions");
234
- var import_utils23 = require("@fuel-ts/utils");
234
+ var import_math16 = require("@fuel-ts/math");
235
+ var import_transactions19 = require("@fuel-ts/transactions");
236
+ var import_utils22 = require("@fuel-ts/utils");
235
237
  var import_versions = require("@fuel-ts/versions");
236
- var import_utils24 = require("@noble/curves/abstract/utils");
238
+ var import_utils23 = require("@noble/curves/abstract/utils");
239
+ var import_ethers = require("ethers");
237
240
  var import_graphql_request = require("graphql-request");
238
241
  var import_ramda3 = require("ramda");
239
242
 
@@ -241,14 +244,10 @@ var import_ramda3 = require("ramda");
241
244
  var import_graphql_tag = __toESM(require("graphql-tag"));
242
245
  var ReceiptFragmentFragmentDoc = import_graphql_tag.default`
243
246
  fragment receiptFragment on Receipt {
244
- contract {
245
- id
246
- }
247
+ id
247
248
  pc
248
249
  is
249
- to {
250
- id
251
- }
250
+ to
252
251
  toAddress
253
252
  amount
254
253
  assetId
@@ -286,10 +285,16 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
286
285
  id
287
286
  }
288
287
  time
288
+ receipts {
289
+ ...receiptFragment
290
+ }
289
291
  programState {
290
292
  returnType
291
293
  data
292
294
  }
295
+ receipts {
296
+ ...receiptFragment
297
+ }
293
298
  }
294
299
  ... on FailureStatus {
295
300
  block {
@@ -297,26 +302,24 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
297
302
  }
298
303
  time
299
304
  reason
305
+ receipts {
306
+ ...receiptFragment
307
+ }
300
308
  }
301
309
  ... on SqueezedOutStatus {
302
310
  reason
303
311
  }
304
312
  }
305
- `;
313
+ ${ReceiptFragmentFragmentDoc}`;
306
314
  var TransactionFragmentFragmentDoc = import_graphql_tag.default`
307
315
  fragment transactionFragment on Transaction {
308
316
  id
309
317
  rawPayload
310
- gasPrice
311
- receipts {
312
- ...receiptFragment
313
- }
314
318
  status {
315
319
  ...transactionStatusFragment
316
320
  }
317
321
  }
318
- ${ReceiptFragmentFragmentDoc}
319
- ${TransactionStatusFragmentFragmentDoc}`;
322
+ ${TransactionStatusFragmentFragmentDoc}`;
320
323
  var InputEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.default`
321
324
  fragment inputEstimatePredicatesFragment on Input {
322
325
  ... on InputCoin {
@@ -334,6 +337,46 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.defaul
334
337
  }
335
338
  }
336
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}`;
337
380
  var CoinFragmentFragmentDoc = import_graphql_tag.default`
338
381
  fragment coinFragment on Coin {
339
382
  __typename
@@ -341,7 +384,6 @@ var CoinFragmentFragmentDoc = import_graphql_tag.default`
341
384
  owner
342
385
  amount
343
386
  assetId
344
- maturity
345
387
  blockCreated
346
388
  txCreatedIdx
347
389
  }
@@ -380,26 +422,32 @@ var MessageProofFragmentFragmentDoc = import_graphql_tag.default`
380
422
  messageBlockHeader {
381
423
  id
382
424
  daHeight
425
+ consensusParametersVersion
426
+ stateTransitionBytecodeVersion
383
427
  transactionsCount
428
+ messageReceiptCount
384
429
  transactionsRoot
430
+ messageOutboxRoot
431
+ eventInboxRoot
385
432
  height
386
433
  prevRoot
387
434
  time
388
435
  applicationHash
389
- messageReceiptRoot
390
- messageReceiptCount
391
436
  }
392
437
  commitBlockHeader {
393
438
  id
394
439
  daHeight
440
+ consensusParametersVersion
441
+ stateTransitionBytecodeVersion
395
442
  transactionsCount
443
+ messageReceiptCount
396
444
  transactionsRoot
445
+ messageOutboxRoot
446
+ eventInboxRoot
397
447
  height
398
448
  prevRoot
399
449
  time
400
450
  applicationHash
401
- messageReceiptRoot
402
- messageReceiptCount
403
451
  }
404
452
  sender
405
453
  recipient
@@ -418,8 +466,8 @@ var BalanceFragmentFragmentDoc = import_graphql_tag.default`
418
466
  var BlockFragmentFragmentDoc = import_graphql_tag.default`
419
467
  fragment blockFragment on Block {
420
468
  id
469
+ height
421
470
  header {
422
- height
423
471
  time
424
472
  }
425
473
  transactions {
@@ -477,6 +525,11 @@ var DependentCostFragmentFragmentDoc = import_graphql_tag.default`
477
525
  `;
478
526
  var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
479
527
  fragment GasCostsFragment on GasCosts {
528
+ version {
529
+ ... on Version {
530
+ value
531
+ }
532
+ }
480
533
  add
481
534
  addi
482
535
  aloc
@@ -489,7 +542,6 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
489
542
  cb
490
543
  cfei
491
544
  cfsi
492
- croo
493
545
  div
494
546
  divi
495
547
  ecr1
@@ -572,6 +624,9 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
572
624
  ccp {
573
625
  ...DependentCostFragment
574
626
  }
627
+ croo {
628
+ ...DependentCostFragment
629
+ }
575
630
  csiz {
576
631
  ...DependentCostFragment
577
632
  }
@@ -631,6 +686,11 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
631
686
  ${DependentCostFragmentFragmentDoc}`;
632
687
  var ConsensusParametersFragmentFragmentDoc = import_graphql_tag.default`
633
688
  fragment consensusParametersFragment on ConsensusParameters {
689
+ version {
690
+ ... on Version {
691
+ value
692
+ }
693
+ }
634
694
  txParams {
635
695
  ...TxParametersFragment
636
696
  }
@@ -690,18 +750,9 @@ var NodeInfoFragmentFragmentDoc = import_graphql_tag.default`
690
750
  fragment nodeInfoFragment on NodeInfo {
691
751
  utxoValidation
692
752
  vmBacktrace
693
- minGasPrice
694
753
  maxTx
695
754
  maxDepth
696
755
  nodeVersion
697
- peers {
698
- id
699
- addresses
700
- clientVersion
701
- blockHeight
702
- lastHeartbeatMs
703
- appScore
704
- }
705
756
  }
706
757
  `;
707
758
  var GetVersionDocument = import_graphql_tag.default`
@@ -736,13 +787,9 @@ var GetTransactionWithReceiptsDocument = import_graphql_tag.default`
736
787
  query getTransactionWithReceipts($transactionId: TransactionId!) {
737
788
  transaction(id: $transactionId) {
738
789
  ...transactionFragment
739
- receipts {
740
- ...receiptFragment
741
- }
742
790
  }
743
791
  }
744
- ${TransactionFragmentFragmentDoc}
745
- ${ReceiptFragmentFragmentDoc}`;
792
+ ${TransactionFragmentFragmentDoc}`;
746
793
  var GetTransactionsDocument = import_graphql_tag.default`
747
794
  query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
748
795
  transactions(after: $after, before: $before, first: $first, last: $last) {
@@ -870,6 +917,20 @@ var GetBalanceDocument = import_graphql_tag.default`
870
917
  }
871
918
  }
872
919
  ${BalanceFragmentFragmentDoc}`;
920
+ var GetLatestGasPriceDocument = import_graphql_tag.default`
921
+ query getLatestGasPrice {
922
+ latestGasPrice {
923
+ gasPrice
924
+ }
925
+ }
926
+ `;
927
+ var EstimateGasPriceDocument = import_graphql_tag.default`
928
+ query estimateGasPrice($blockHorizon: U32!) {
929
+ estimateGasPrice(blockHorizon: $blockHorizon) {
930
+ gasPrice
931
+ }
932
+ }
933
+ `;
873
934
  var GetBalancesDocument = import_graphql_tag.default`
874
935
  query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
875
936
  balances(
@@ -924,12 +985,12 @@ var GetMessageStatusDocument = import_graphql_tag.default`
924
985
  }
925
986
  `;
926
987
  var DryRunDocument = import_graphql_tag.default`
927
- mutation dryRun($encodedTransaction: HexString!, $utxoValidation: Boolean) {
928
- dryRun(tx: $encodedTransaction, utxoValidation: $utxoValidation) {
929
- ...receiptFragment
988
+ mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean) {
989
+ dryRun(txs: $encodedTransactions, utxoValidation: $utxoValidation) {
990
+ ...dryRunTransactionExecutionStatusFragment
930
991
  }
931
992
  }
932
- ${ReceiptFragmentFragmentDoc}`;
993
+ ${DryRunTransactionExecutionStatusFragmentFragmentDoc}`;
933
994
  var SubmitDocument = import_graphql_tag.default`
934
995
  mutation submit($encodedTransaction: HexString!) {
935
996
  submit(tx: $encodedTransaction) {
@@ -1012,6 +1073,12 @@ function getSdk(requester) {
1012
1073
  getBalance(variables, options) {
1013
1074
  return requester(GetBalanceDocument, variables, options);
1014
1075
  },
1076
+ getLatestGasPrice(variables, options) {
1077
+ return requester(GetLatestGasPriceDocument, variables, options);
1078
+ },
1079
+ estimateGasPrice(variables, options) {
1080
+ return requester(EstimateGasPriceDocument, variables, options);
1081
+ },
1015
1082
  getBalances(variables, options) {
1016
1083
  return requester(GetBalancesDocument, variables, options);
1017
1084
  },
@@ -1205,10 +1272,9 @@ var inputify = (value) => {
1205
1272
  txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
1206
1273
  },
1207
1274
  witnessIndex: value.witnessIndex,
1208
- maturity: value.maturity ?? 0,
1209
1275
  predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
1210
- predicateLength: predicate.length,
1211
- predicateDataLength: predicateData.length,
1276
+ predicateLength: (0, import_math2.bn)(predicate.length),
1277
+ predicateDataLength: (0, import_math2.bn)(predicateData.length),
1212
1278
  predicate: (0, import_utils3.hexlify)(predicate),
1213
1279
  predicateData: (0, import_utils3.hexlify)(predicateData)
1214
1280
  };
@@ -1239,8 +1305,8 @@ var inputify = (value) => {
1239
1305
  nonce: (0, import_utils3.hexlify)(value.nonce),
1240
1306
  witnessIndex: value.witnessIndex,
1241
1307
  predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
1242
- predicateLength: predicate.length,
1243
- predicateDataLength: predicateData.length,
1308
+ predicateLength: (0, import_math2.bn)(predicate.length),
1309
+ predicateDataLength: (0, import_math2.bn)(predicateData.length),
1244
1310
  predicate: (0, import_utils3.hexlify)(predicate),
1245
1311
  predicateData: (0, import_utils3.hexlify)(predicateData),
1246
1312
  data: (0, import_utils3.hexlify)(data),
@@ -1359,8 +1425,8 @@ function assembleReceiptByType(receipt) {
1359
1425
  case "CALL" /* Call */: {
1360
1426
  const callReceipt = {
1361
1427
  type: import_transactions3.ReceiptType.Call,
1362
- from: hexOrZero(receipt.contract?.id),
1363
- to: hexOrZero(receipt?.to?.id),
1428
+ from: hexOrZero(receipt.id || receipt.contractId),
1429
+ to: hexOrZero(receipt?.to),
1364
1430
  amount: (0, import_math4.bn)(receipt.amount),
1365
1431
  assetId: hexOrZero(receipt.assetId),
1366
1432
  gas: (0, import_math4.bn)(receipt.gas),
@@ -1374,7 +1440,7 @@ function assembleReceiptByType(receipt) {
1374
1440
  case "RETURN" /* Return */: {
1375
1441
  const returnReceipt = {
1376
1442
  type: import_transactions3.ReceiptType.Return,
1377
- id: hexOrZero(receipt.contract?.id),
1443
+ id: hexOrZero(receipt.id || receipt.contractId),
1378
1444
  val: (0, import_math4.bn)(receipt.val),
1379
1445
  pc: (0, import_math4.bn)(receipt.pc),
1380
1446
  is: (0, import_math4.bn)(receipt.is)
@@ -1384,7 +1450,7 @@ function assembleReceiptByType(receipt) {
1384
1450
  case "RETURN_DATA" /* ReturnData */: {
1385
1451
  const returnDataReceipt = {
1386
1452
  type: import_transactions3.ReceiptType.ReturnData,
1387
- id: hexOrZero(receipt.contract?.id),
1453
+ id: hexOrZero(receipt.id || receipt.contractId),
1388
1454
  ptr: (0, import_math4.bn)(receipt.ptr),
1389
1455
  len: (0, import_math4.bn)(receipt.len),
1390
1456
  digest: hexOrZero(receipt.digest),
@@ -1396,7 +1462,7 @@ function assembleReceiptByType(receipt) {
1396
1462
  case "PANIC" /* Panic */: {
1397
1463
  const panicReceipt = {
1398
1464
  type: import_transactions3.ReceiptType.Panic,
1399
- id: hexOrZero(receipt.contract?.id),
1465
+ id: hexOrZero(receipt.id),
1400
1466
  reason: (0, import_math4.bn)(receipt.reason),
1401
1467
  pc: (0, import_math4.bn)(receipt.pc),
1402
1468
  is: (0, import_math4.bn)(receipt.is),
@@ -1407,7 +1473,7 @@ function assembleReceiptByType(receipt) {
1407
1473
  case "REVERT" /* Revert */: {
1408
1474
  const revertReceipt = {
1409
1475
  type: import_transactions3.ReceiptType.Revert,
1410
- id: hexOrZero(receipt.contract?.id),
1476
+ id: hexOrZero(receipt.id || receipt.contractId),
1411
1477
  val: (0, import_math4.bn)(receipt.ra),
1412
1478
  pc: (0, import_math4.bn)(receipt.pc),
1413
1479
  is: (0, import_math4.bn)(receipt.is)
@@ -1417,7 +1483,7 @@ function assembleReceiptByType(receipt) {
1417
1483
  case "LOG" /* Log */: {
1418
1484
  const logReceipt = {
1419
1485
  type: import_transactions3.ReceiptType.Log,
1420
- id: hexOrZero(receipt.contract?.id),
1486
+ id: hexOrZero(receipt.id || receipt.contractId),
1421
1487
  val0: (0, import_math4.bn)(receipt.ra),
1422
1488
  val1: (0, import_math4.bn)(receipt.rb),
1423
1489
  val2: (0, import_math4.bn)(receipt.rc),
@@ -1430,7 +1496,7 @@ function assembleReceiptByType(receipt) {
1430
1496
  case "LOG_DATA" /* LogData */: {
1431
1497
  const logDataReceipt = {
1432
1498
  type: import_transactions3.ReceiptType.LogData,
1433
- id: hexOrZero(receipt.contract?.id),
1499
+ id: hexOrZero(receipt.id || receipt.contractId),
1434
1500
  val0: (0, import_math4.bn)(receipt.ra),
1435
1501
  val1: (0, import_math4.bn)(receipt.rb),
1436
1502
  ptr: (0, import_math4.bn)(receipt.ptr),
@@ -1444,8 +1510,8 @@ function assembleReceiptByType(receipt) {
1444
1510
  case "TRANSFER" /* Transfer */: {
1445
1511
  const transferReceipt = {
1446
1512
  type: import_transactions3.ReceiptType.Transfer,
1447
- from: hexOrZero(receipt.contract?.id),
1448
- to: hexOrZero(receipt.toAddress || receipt?.to?.id),
1513
+ from: hexOrZero(receipt.id || receipt.contractId),
1514
+ to: hexOrZero(receipt.toAddress || receipt?.to),
1449
1515
  amount: (0, import_math4.bn)(receipt.amount),
1450
1516
  assetId: hexOrZero(receipt.assetId),
1451
1517
  pc: (0, import_math4.bn)(receipt.pc),
@@ -1456,8 +1522,8 @@ function assembleReceiptByType(receipt) {
1456
1522
  case "TRANSFER_OUT" /* TransferOut */: {
1457
1523
  const transferOutReceipt = {
1458
1524
  type: import_transactions3.ReceiptType.TransferOut,
1459
- from: hexOrZero(receipt.contract?.id),
1460
- to: hexOrZero(receipt.toAddress || receipt.to?.id),
1525
+ from: hexOrZero(receipt.id || receipt.contractId),
1526
+ to: hexOrZero(receipt.toAddress || receipt.to),
1461
1527
  amount: (0, import_math4.bn)(receipt.amount),
1462
1528
  assetId: hexOrZero(receipt.assetId),
1463
1529
  pc: (0, import_math4.bn)(receipt.pc),
@@ -1500,7 +1566,7 @@ function assembleReceiptByType(receipt) {
1500
1566
  return receiptMessageOut;
1501
1567
  }
1502
1568
  case "MINT" /* Mint */: {
1503
- const contractId = hexOrZero(receipt.contract?.id);
1569
+ const contractId = hexOrZero(receipt.id || receipt.contractId);
1504
1570
  const subId = hexOrZero(receipt.subId);
1505
1571
  const assetId = import_transactions3.ReceiptMintCoder.getAssetId(contractId, subId);
1506
1572
  const mintReceipt = {
@@ -1515,7 +1581,7 @@ function assembleReceiptByType(receipt) {
1515
1581
  return mintReceipt;
1516
1582
  }
1517
1583
  case "BURN" /* Burn */: {
1518
- const contractId = hexOrZero(receipt.contract?.id);
1584
+ const contractId = hexOrZero(receipt.id || receipt.contractId);
1519
1585
  const subId = hexOrZero(receipt.subId);
1520
1586
  const assetId = import_transactions3.ReceiptBurnCoder.getAssetId(contractId, subId);
1521
1587
  const burnReceipt = {
@@ -1600,7 +1666,6 @@ var buildBlockExplorerUrl = (options = {}) => {
1600
1666
  var import_math5 = require("@fuel-ts/math");
1601
1667
  var import_transactions4 = require("@fuel-ts/transactions");
1602
1668
  var import_utils6 = require("@fuel-ts/utils");
1603
- var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => (0, import_math5.bn)(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
1604
1669
  var getGasUsedFromReceipts = (receipts) => {
1605
1670
  const scriptResult = receipts.filter(
1606
1671
  (receipt) => receipt.type === import_transactions4.ReceiptType.ScriptResult
@@ -1621,18 +1686,28 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
1621
1686
  }
1622
1687
  function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
1623
1688
  const witnessCache = [];
1624
- const totalGas = inputs.reduce((total, input) => {
1689
+ const chargeableInputs = inputs.filter((input) => {
1690
+ const isCoinOrMessage = "owner" in input || "sender" in input;
1691
+ if (isCoinOrMessage) {
1692
+ if ("predicate" in input && input.predicate && input.predicate !== "0x") {
1693
+ return true;
1694
+ }
1695
+ if (!witnessCache.includes(input.witnessIndex)) {
1696
+ witnessCache.push(input.witnessIndex);
1697
+ return true;
1698
+ }
1699
+ }
1700
+ return false;
1701
+ });
1702
+ const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
1703
+ const totalGas = chargeableInputs.reduce((total, input) => {
1625
1704
  if ("predicate" in input && input.predicate && input.predicate !== "0x") {
1626
1705
  return total.add(
1627
- resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization).add(resolveGasDependentCosts((0, import_utils6.arrayify)(input.predicate).length, gasCosts.contractRoot)).add((0, import_math5.bn)(input.predicateGasUsed))
1706
+ vmInitializationCost.add(resolveGasDependentCosts((0, import_utils6.arrayify)(input.predicate).length, gasCosts.contractRoot)).add((0, import_math5.bn)(input.predicateGasUsed))
1628
1707
  );
1629
1708
  }
1630
- if ("witnessIndex" in input && !witnessCache.includes(input.witnessIndex)) {
1631
- witnessCache.push(input.witnessIndex);
1632
- return total.add(gasCosts.ecr1);
1633
- }
1634
- return total;
1635
- }, (0, import_math5.bn)());
1709
+ return total.add(gasCosts.ecr1);
1710
+ }, (0, import_math5.bn)(0));
1636
1711
  return totalGas;
1637
1712
  }
1638
1713
  function getMinGas(params) {
@@ -1644,12 +1719,20 @@ function getMinGas(params) {
1644
1719
  return minGas;
1645
1720
  }
1646
1721
  function getMaxGas(params) {
1647
- const { gasPerByte, witnessesLength, witnessLimit, minGas, gasLimit = (0, import_math5.bn)(0) } = params;
1722
+ const {
1723
+ gasPerByte,
1724
+ witnessesLength,
1725
+ witnessLimit,
1726
+ minGas,
1727
+ gasLimit = (0, import_math5.bn)(0),
1728
+ maxGasPerTx
1729
+ } = params;
1648
1730
  let remainingAllowedWitnessGas = (0, import_math5.bn)(0);
1649
1731
  if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
1650
1732
  remainingAllowedWitnessGas = (0, import_math5.bn)(witnessLimit).sub(witnessesLength).mul(gasPerByte);
1651
1733
  }
1652
- return remainingAllowedWitnessGas.add(minGas).add(gasLimit);
1734
+ const maxGas = remainingAllowedWitnessGas.add(minGas).add(gasLimit);
1735
+ return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
1653
1736
  }
1654
1737
  function calculateMetadataGasForTxCreate({
1655
1738
  gasCosts,
@@ -1671,6 +1754,10 @@ function calculateMetadataGasForTxScript({
1671
1754
  }) {
1672
1755
  return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
1673
1756
  }
1757
+ var calculateGasFee = (params) => {
1758
+ const { gas, gasPrice, priceFactor, tip } = params;
1759
+ return gas.mul(gasPrice).div(priceFactor).add(tip);
1760
+ };
1674
1761
 
1675
1762
  // src/providers/utils/json.ts
1676
1763
  var import_utils7 = require("@fuel-ts/utils");
@@ -1819,7 +1906,7 @@ var witnessify = (value) => {
1819
1906
  // src/providers/transaction-request/transaction-request.ts
1820
1907
  var BaseTransactionRequest = class {
1821
1908
  /** Gas price for transaction */
1822
- gasPrice;
1909
+ tip;
1823
1910
  /** Block until which tx cannot be included */
1824
1911
  maturity;
1825
1912
  /** The maximum fee payable by this transaction using BASE_ASSET. */
@@ -1838,7 +1925,7 @@ var BaseTransactionRequest = class {
1838
1925
  * @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
1839
1926
  */
1840
1927
  constructor({
1841
- gasPrice,
1928
+ tip,
1842
1929
  maturity,
1843
1930
  maxFee,
1844
1931
  witnessLimit,
@@ -1846,7 +1933,7 @@ var BaseTransactionRequest = class {
1846
1933
  outputs,
1847
1934
  witnesses
1848
1935
  } = {}) {
1849
- this.gasPrice = (0, import_math7.bn)(gasPrice);
1936
+ this.tip = (0, import_math7.bn)(tip);
1850
1937
  this.maturity = maturity ?? 0;
1851
1938
  this.witnessLimit = witnessLimit ? (0, import_math7.bn)(witnessLimit) : void 0;
1852
1939
  this.maxFee = maxFee ? (0, import_math7.bn)(maxFee) : void 0;
@@ -1857,9 +1944,9 @@ var BaseTransactionRequest = class {
1857
1944
  static getPolicyMeta(req) {
1858
1945
  let policyTypes = 0;
1859
1946
  const policies = [];
1860
- if (req.gasPrice) {
1861
- policyTypes += import_transactions6.PolicyType.GasPrice;
1862
- policies.push({ data: req.gasPrice, type: import_transactions6.PolicyType.GasPrice });
1947
+ if (req.tip) {
1948
+ policyTypes += import_transactions6.PolicyType.Tip;
1949
+ policies.push({ data: req.tip, type: import_transactions6.PolicyType.Tip });
1863
1950
  }
1864
1951
  if (req.witnessLimit) {
1865
1952
  policyTypes += import_transactions6.PolicyType.WitnessLimit;
@@ -2046,10 +2133,10 @@ var BaseTransactionRequest = class {
2046
2133
  * @param predicate - Predicate bytes.
2047
2134
  * @param predicateData - Predicate data bytes.
2048
2135
  */
2049
- addCoinInput(coin, predicate) {
2136
+ addCoinInput(coin) {
2050
2137
  const { assetId, owner, amount } = coin;
2051
2138
  let witnessIndex;
2052
- if (predicate) {
2139
+ if (coin.predicate) {
2053
2140
  witnessIndex = 0;
2054
2141
  } else {
2055
2142
  witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
@@ -2064,8 +2151,7 @@ var BaseTransactionRequest = class {
2064
2151
  amount,
2065
2152
  assetId,
2066
2153
  txPointer: "0x00000000000000000000000000000000",
2067
- witnessIndex,
2068
- predicate: predicate?.bytes
2154
+ witnessIndex
2069
2155
  };
2070
2156
  this.pushInput(input);
2071
2157
  this.addChangeOutput(owner, assetId);
@@ -2078,11 +2164,11 @@ var BaseTransactionRequest = class {
2078
2164
  * @param predicate - Predicate bytes.
2079
2165
  * @param predicateData - Predicate data bytes.
2080
2166
  */
2081
- addMessageInput(message, predicate) {
2167
+ addMessageInput(message) {
2082
2168
  const { recipient, sender, amount } = message;
2083
2169
  const assetId = import_configs7.BaseAssetId;
2084
2170
  let witnessIndex;
2085
- if (predicate) {
2171
+ if (message.predicate) {
2086
2172
  witnessIndex = 0;
2087
2173
  } else {
2088
2174
  witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
@@ -2096,8 +2182,7 @@ var BaseTransactionRequest = class {
2096
2182
  sender: sender.toB256(),
2097
2183
  recipient: recipient.toB256(),
2098
2184
  amount,
2099
- witnessIndex,
2100
- predicate: predicate?.bytes
2185
+ witnessIndex
2101
2186
  };
2102
2187
  this.pushInput(input);
2103
2188
  this.addChangeOutput(recipient, assetId);
@@ -2128,32 +2213,6 @@ var BaseTransactionRequest = class {
2128
2213
  resources.forEach((resource) => this.addResource(resource));
2129
2214
  return this;
2130
2215
  }
2131
- /**
2132
- * Adds multiple resources to the transaction by adding coin/message inputs and change
2133
- * outputs from the related assetIds.
2134
- *
2135
- * @param resources - The resources to add.
2136
- * @returns This transaction.
2137
- */
2138
- addPredicateResource(resource, predicate) {
2139
- if (isCoin(resource)) {
2140
- this.addCoinInput(resource, predicate);
2141
- } else {
2142
- this.addMessageInput(resource, predicate);
2143
- }
2144
- return this;
2145
- }
2146
- /**
2147
- * Adds multiple predicate coin/message inputs to the transaction and change outputs
2148
- * from the related assetIds.
2149
- *
2150
- * @param resources - The resources to add.
2151
- * @returns This transaction.
2152
- */
2153
- addPredicateResources(resources, predicate) {
2154
- resources.forEach((resource) => this.addPredicateResource(resource, predicate));
2155
- return this;
2156
- }
2157
2216
  /**
2158
2217
  * Adds a coin output to the transaction.
2159
2218
  *
@@ -2233,7 +2292,7 @@ var BaseTransactionRequest = class {
2233
2292
  }
2234
2293
  calculateMaxGas(chainInfo, minGas) {
2235
2294
  const { consensusParameters } = chainInfo;
2236
- const { gasPerByte } = consensusParameters;
2295
+ const { gasPerByte, maxGasPerTx } = consensusParameters;
2237
2296
  const witnessesLength = this.toTransaction().witnesses.reduce(
2238
2297
  (acc, wit) => acc + wit.dataLength,
2239
2298
  0
@@ -2242,7 +2301,8 @@ var BaseTransactionRequest = class {
2242
2301
  gasPerByte,
2243
2302
  minGas,
2244
2303
  witnessesLength,
2245
- witnessLimit: this.witnessLimit
2304
+ witnessLimit: this.witnessLimit,
2305
+ maxGasPerTx
2246
2306
  });
2247
2307
  }
2248
2308
  /**
@@ -2260,17 +2320,20 @@ var BaseTransactionRequest = class {
2260
2320
  });
2261
2321
  const updateAssetInput = (assetId, quantity) => {
2262
2322
  const assetInput = findAssetInput(assetId);
2323
+ let usedQuantity = quantity;
2324
+ if (assetId === import_configs7.BaseAssetId) {
2325
+ usedQuantity = (0, import_math7.bn)("1000000000000000000");
2326
+ }
2263
2327
  if (assetInput && "assetId" in assetInput) {
2264
2328
  assetInput.id = (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN));
2265
- assetInput.amount = quantity;
2329
+ assetInput.amount = usedQuantity;
2266
2330
  } else {
2267
2331
  this.addResources([
2268
2332
  {
2269
2333
  id: (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN)),
2270
- amount: quantity,
2334
+ amount: usedQuantity,
2271
2335
  assetId,
2272
2336
  owner: resourcesOwner || import_address.Address.fromRandom(),
2273
- maturity: 0,
2274
2337
  blockCreated: (0, import_math7.bn)(1),
2275
2338
  txCreatedIdx: (0, import_math7.bn)(1)
2276
2339
  }
@@ -2302,7 +2365,7 @@ var BaseTransactionRequest = class {
2302
2365
  toJSON() {
2303
2366
  return normalizeJSON(this);
2304
2367
  }
2305
- updatePredicateInputs(inputs) {
2368
+ updatePredicateGasUsed(inputs) {
2306
2369
  this.inputs.forEach((i) => {
2307
2370
  let correspondingInput;
2308
2371
  switch (i.type) {
@@ -2324,6 +2387,15 @@ var BaseTransactionRequest = class {
2324
2387
  }
2325
2388
  });
2326
2389
  }
2390
+ shiftPredicateData() {
2391
+ this.inputs.forEach((input) => {
2392
+ if ("predicateData" in input && "paddPredicateData" in input && typeof input.paddPredicateData === "function") {
2393
+ input.predicateData = input.paddPredicateData(
2394
+ BaseTransactionRequest.getPolicyMeta(this).policies.length
2395
+ );
2396
+ }
2397
+ });
2398
+ }
2327
2399
  };
2328
2400
 
2329
2401
  // src/providers/transaction-request/create-transaction-request.ts
@@ -2470,9 +2542,8 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2470
2542
  return {
2471
2543
  type: import_transactions8.TransactionType.Create,
2472
2544
  ...baseTransaction,
2473
- bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
2474
2545
  bytecodeWitnessIndex,
2475
- storageSlotsCount: storageSlots.length,
2546
+ storageSlotsCount: (0, import_math9.bn)(storageSlots.length),
2476
2547
  salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs9.ZeroBytes32,
2477
2548
  storageSlots
2478
2549
  };
@@ -2595,8 +2666,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2595
2666
  type: import_transactions9.TransactionType.Script,
2596
2667
  scriptGasLimit: this.gasLimit,
2597
2668
  ...super.getBaseTransaction(),
2598
- scriptLength: script.length,
2599
- scriptDataLength: scriptData.length,
2669
+ scriptLength: (0, import_math10.bn)(script.length),
2670
+ scriptDataLength: (0, import_math10.bn)(scriptData.length),
2600
2671
  receiptsRoot: import_configs10.ZeroBytes32,
2601
2672
  script: (0, import_utils15.hexlify)(script),
2602
2673
  scriptData: (0, import_utils15.hexlify)(scriptData)
@@ -2660,7 +2731,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2660
2731
  }
2661
2732
  calculateMaxGas(chainInfo, minGas) {
2662
2733
  const { consensusParameters } = chainInfo;
2663
- const { gasPerByte } = consensusParameters;
2734
+ const { gasPerByte, maxGasPerTx } = consensusParameters;
2664
2735
  const witnessesLength = this.toTransaction().witnesses.reduce(
2665
2736
  (acc, wit) => acc + wit.dataLength,
2666
2737
  0
@@ -2670,7 +2741,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2670
2741
  minGas,
2671
2742
  witnessesLength,
2672
2743
  witnessLimit: this.witnessLimit,
2673
- gasLimit: this.gasLimit
2744
+ gasLimit: this.gasLimit,
2745
+ maxGasPerTx
2674
2746
  });
2675
2747
  }
2676
2748
  /**
@@ -2745,15 +2817,32 @@ var transactionRequestify = (obj) => {
2745
2817
  }
2746
2818
  }
2747
2819
  };
2820
+ var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
2821
+ (acc, input) => {
2822
+ if (input.type === import_transactions10.InputType.Coin && input.owner === owner) {
2823
+ acc.utxos.push(input.id);
2824
+ }
2825
+ if (input.type === import_transactions10.InputType.Message && input.recipient === owner) {
2826
+ acc.messages.push(input.nonce);
2827
+ }
2828
+ return acc;
2829
+ },
2830
+ {
2831
+ utxos: [],
2832
+ messages: []
2833
+ }
2834
+ );
2748
2835
 
2749
2836
  // src/providers/transaction-response/transaction-response.ts
2750
2837
  var import_errors13 = require("@fuel-ts/errors");
2751
- var import_math14 = require("@fuel-ts/math");
2752
- var import_transactions17 = require("@fuel-ts/transactions");
2753
- var import_utils21 = require("@fuel-ts/utils");
2838
+ var import_math15 = require("@fuel-ts/math");
2839
+ var import_transactions18 = require("@fuel-ts/transactions");
2840
+ var import_utils20 = require("@fuel-ts/utils");
2754
2841
 
2755
2842
  // src/providers/transaction-summary/assemble-transaction-summary.ts
2756
- var import_utils19 = require("@fuel-ts/utils");
2843
+ var import_math14 = require("@fuel-ts/math");
2844
+ var import_transactions16 = require("@fuel-ts/transactions");
2845
+ var import_utils18 = require("@fuel-ts/utils");
2757
2846
 
2758
2847
  // src/providers/transaction-summary/calculate-transaction-fee.ts
2759
2848
  var import_math11 = require("@fuel-ts/math");
@@ -2761,9 +2850,10 @@ var import_transactions11 = require("@fuel-ts/transactions");
2761
2850
  var import_utils16 = require("@fuel-ts/utils");
2762
2851
  var calculateTransactionFee = (params) => {
2763
2852
  const {
2764
- gasUsed,
2853
+ gasPrice,
2765
2854
  rawPayload,
2766
- consensusParameters: { gasCosts, feeParams }
2855
+ tip,
2856
+ consensusParameters: { gasCosts, feeParams, maxGasPerTx }
2767
2857
  } = params;
2768
2858
  const gasPerByte = (0, import_math11.bn)(feeParams.gasPerByte);
2769
2859
  const gasPriceFactor = (0, import_math11.bn)(feeParams.gasPriceFactor);
@@ -2773,8 +2863,7 @@ var calculateTransactionFee = (params) => {
2773
2863
  return {
2774
2864
  fee: (0, import_math11.bn)(0),
2775
2865
  minFee: (0, import_math11.bn)(0),
2776
- maxFee: (0, import_math11.bn)(0),
2777
- feeFromGasUsed: (0, import_math11.bn)(0)
2866
+ maxFee: (0, import_math11.bn)(0)
2778
2867
  };
2779
2868
  }
2780
2869
  const { type, witnesses, inputs, policies } = transaction;
@@ -2806,7 +2895,6 @@ var calculateTransactionFee = (params) => {
2806
2895
  metadataGas,
2807
2896
  txBytesSize: transactionBytes.length
2808
2897
  });
2809
- const gasPrice = (0, import_math11.bn)(policies.find((policy) => policy.type === import_transactions11.PolicyType.GasPrice)?.data);
2810
2898
  const witnessLimit = policies.find((policy) => policy.type === import_transactions11.PolicyType.WitnessLimit)?.data;
2811
2899
  const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
2812
2900
  const maxGas = getMaxGas({
@@ -2814,17 +2902,25 @@ var calculateTransactionFee = (params) => {
2814
2902
  minGas,
2815
2903
  witnessesLength,
2816
2904
  gasLimit,
2817
- witnessLimit
2905
+ witnessLimit,
2906
+ maxGasPerTx
2907
+ });
2908
+ const minFee = calculateGasFee({
2909
+ gasPrice,
2910
+ gas: minGas,
2911
+ priceFactor: gasPriceFactor,
2912
+ tip
2913
+ });
2914
+ const maxFee = calculateGasFee({
2915
+ gasPrice,
2916
+ gas: maxGas,
2917
+ priceFactor: gasPriceFactor,
2918
+ tip
2818
2919
  });
2819
- const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
2820
- const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
2821
- const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
2822
- const fee = minFee.add(feeFromGasUsed);
2823
2920
  return {
2824
- fee,
2825
2921
  minFee,
2826
2922
  maxFee,
2827
- feeFromGasUsed
2923
+ fee: maxFee
2828
2924
  };
2829
2925
  };
2830
2926
 
@@ -3438,10 +3534,12 @@ function assembleTransactionSummary(params) {
3438
3534
  gqlTransactionStatus,
3439
3535
  abiMap = {},
3440
3536
  maxInputs,
3441
- gasCosts
3537
+ gasCosts,
3538
+ maxGasPerTx,
3539
+ gasPrice
3442
3540
  } = params;
3443
3541
  const gasUsed = getGasUsedFromReceipts(receipts);
3444
- const rawPayload = (0, import_utils19.hexlify)(transactionBytes);
3542
+ const rawPayload = (0, import_utils18.hexlify)(transactionBytes);
3445
3543
  const operations = getOperations({
3446
3544
  transactionType: transaction.type,
3447
3545
  inputs: transaction.inputs || [],
@@ -3452,11 +3550,14 @@ function assembleTransactionSummary(params) {
3452
3550
  maxInputs
3453
3551
  });
3454
3552
  const typeName = getTransactionTypeName(transaction.type);
3553
+ const tip = (0, import_math14.bn)(transaction.policies?.find((policy) => policy.type === import_transactions16.PolicyType.Tip)?.data);
3455
3554
  const { fee } = calculateTransactionFee({
3456
- gasUsed,
3555
+ gasPrice,
3457
3556
  rawPayload,
3557
+ tip,
3458
3558
  consensusParameters: {
3459
3559
  gasCosts,
3560
+ maxGasPerTx,
3460
3561
  feeParams: {
3461
3562
  gasPerByte,
3462
3563
  gasPriceFactor
@@ -3468,7 +3569,7 @@ function assembleTransactionSummary(params) {
3468
3569
  const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
3469
3570
  let date;
3470
3571
  if (time) {
3471
- date = import_utils19.DateTime.fromTai64(time);
3572
+ date = import_utils18.DateTime.fromTai64(time);
3472
3573
  }
3473
3574
  const transactionSummary = {
3474
3575
  id,
@@ -3496,12 +3597,12 @@ function assembleTransactionSummary(params) {
3496
3597
 
3497
3598
  // src/providers/transaction-response/getDecodedLogs.ts
3498
3599
  var import_abi_coder5 = require("@fuel-ts/abi-coder");
3499
- var import_transactions16 = require("@fuel-ts/transactions");
3600
+ var import_transactions17 = require("@fuel-ts/transactions");
3500
3601
  function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
3501
3602
  return receipts.reduce((logs, receipt) => {
3502
- if (receipt.type === import_transactions16.ReceiptType.LogData || receipt.type === import_transactions16.ReceiptType.Log) {
3603
+ if (receipt.type === import_transactions17.ReceiptType.LogData || receipt.type === import_transactions17.ReceiptType.Log) {
3503
3604
  const interfaceToUse = new import_abi_coder5.Interface(externalAbis[receipt.id] || mainAbi);
3504
- const data = receipt.type === import_transactions16.ReceiptType.Log ? new import_abi_coder5.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
3605
+ const data = receipt.type === import_transactions17.ReceiptType.Log ? new import_abi_coder5.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
3505
3606
  const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
3506
3607
  logs.push(decodedLog);
3507
3608
  }
@@ -3516,7 +3617,7 @@ var TransactionResponse = class {
3516
3617
  /** Current provider */
3517
3618
  provider;
3518
3619
  /** Gas used on the transaction */
3519
- gasUsed = (0, import_math14.bn)(0);
3620
+ gasUsed = (0, import_math15.bn)(0);
3520
3621
  /** The graphql Transaction with receipts object. */
3521
3622
  gqlTransaction;
3522
3623
  abis;
@@ -3574,8 +3675,8 @@ var TransactionResponse = class {
3574
3675
  * @returns The decoded transaction.
3575
3676
  */
3576
3677
  decodeTransaction(transactionWithReceipts) {
3577
- return new import_transactions17.TransactionCoder().decode(
3578
- (0, import_utils21.arrayify)(transactionWithReceipts.rawPayload),
3678
+ return new import_transactions18.TransactionCoder().decode(
3679
+ (0, import_utils20.arrayify)(transactionWithReceipts.rawPayload),
3579
3680
  0
3580
3681
  )?.[0];
3581
3682
  }
@@ -3594,20 +3695,27 @@ var TransactionResponse = class {
3594
3695
  const decodedTransaction = this.decodeTransaction(
3595
3696
  transaction
3596
3697
  );
3597
- const receipts = transaction.receipts?.map(processGqlReceipt) || [];
3598
- const { gasPerByte, gasPriceFactor, gasCosts } = this.provider.getGasConfig();
3698
+ let txReceipts = [];
3699
+ if (transaction?.status && "receipts" in transaction.status) {
3700
+ txReceipts = transaction.status.receipts;
3701
+ }
3702
+ const receipts = txReceipts.map(processGqlReceipt) || [];
3703
+ const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
3704
+ const gasPrice = await this.provider.getLatestGasPrice();
3599
3705
  const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
3600
3706
  const transactionSummary = assembleTransactionSummary({
3601
3707
  id: this.id,
3602
3708
  receipts,
3603
3709
  transaction: decodedTransaction,
3604
- transactionBytes: (0, import_utils21.arrayify)(transaction.rawPayload),
3710
+ transactionBytes: (0, import_utils20.arrayify)(transaction.rawPayload),
3605
3711
  gqlTransactionStatus: transaction.status,
3606
3712
  gasPerByte,
3607
3713
  gasPriceFactor,
3608
3714
  abiMap: contractsAbiMap,
3609
3715
  maxInputs,
3610
- gasCosts
3716
+ gasCosts,
3717
+ maxGasPerTx,
3718
+ gasPrice
3611
3719
  });
3612
3720
  return transactionSummary;
3613
3721
  }
@@ -3734,29 +3842,29 @@ var processGqlChain = (chain) => {
3734
3842
  const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
3735
3843
  return {
3736
3844
  name,
3737
- baseChainHeight: (0, import_math15.bn)(daHeight),
3845
+ baseChainHeight: (0, import_math16.bn)(daHeight),
3738
3846
  consensusParameters: {
3739
- contractMaxSize: (0, import_math15.bn)(contractParams.contractMaxSize),
3740
- maxInputs: (0, import_math15.bn)(txParams.maxInputs),
3741
- maxOutputs: (0, import_math15.bn)(txParams.maxOutputs),
3742
- maxWitnesses: (0, import_math15.bn)(txParams.maxWitnesses),
3743
- maxGasPerTx: (0, import_math15.bn)(txParams.maxGasPerTx),
3744
- maxScriptLength: (0, import_math15.bn)(scriptParams.maxScriptLength),
3745
- maxScriptDataLength: (0, import_math15.bn)(scriptParams.maxScriptDataLength),
3746
- maxStorageSlots: (0, import_math15.bn)(contractParams.maxStorageSlots),
3747
- maxPredicateLength: (0, import_math15.bn)(predicateParams.maxPredicateLength),
3748
- maxPredicateDataLength: (0, import_math15.bn)(predicateParams.maxPredicateDataLength),
3749
- maxGasPerPredicate: (0, import_math15.bn)(predicateParams.maxGasPerPredicate),
3750
- gasPriceFactor: (0, import_math15.bn)(feeParams.gasPriceFactor),
3751
- gasPerByte: (0, import_math15.bn)(feeParams.gasPerByte),
3752
- maxMessageDataLength: (0, import_math15.bn)(predicateParams.maxMessageDataLength),
3753
- chainId: (0, import_math15.bn)(consensusParameters.chainId),
3847
+ contractMaxSize: (0, import_math16.bn)(contractParams.contractMaxSize),
3848
+ maxInputs: (0, import_math16.bn)(txParams.maxInputs),
3849
+ maxOutputs: (0, import_math16.bn)(txParams.maxOutputs),
3850
+ maxWitnesses: (0, import_math16.bn)(txParams.maxWitnesses),
3851
+ maxGasPerTx: (0, import_math16.bn)(txParams.maxGasPerTx),
3852
+ maxScriptLength: (0, import_math16.bn)(scriptParams.maxScriptLength),
3853
+ maxScriptDataLength: (0, import_math16.bn)(scriptParams.maxScriptDataLength),
3854
+ maxStorageSlots: (0, import_math16.bn)(contractParams.maxStorageSlots),
3855
+ maxPredicateLength: (0, import_math16.bn)(predicateParams.maxPredicateLength),
3856
+ maxPredicateDataLength: (0, import_math16.bn)(predicateParams.maxPredicateDataLength),
3857
+ maxGasPerPredicate: (0, import_math16.bn)(predicateParams.maxGasPerPredicate),
3858
+ gasPriceFactor: (0, import_math16.bn)(feeParams.gasPriceFactor),
3859
+ gasPerByte: (0, import_math16.bn)(feeParams.gasPerByte),
3860
+ maxMessageDataLength: (0, import_math16.bn)(predicateParams.maxMessageDataLength),
3861
+ chainId: (0, import_math16.bn)(consensusParameters.chainId),
3754
3862
  gasCosts
3755
3863
  },
3756
3864
  gasCosts,
3757
3865
  latestBlock: {
3758
3866
  id: latestBlock.id,
3759
- height: (0, import_math15.bn)(latestBlock.header.height),
3867
+ height: (0, import_math16.bn)(latestBlock.height),
3760
3868
  time: latestBlock.header.time,
3761
3869
  transactions: latestBlock.transactions.map((i) => ({
3762
3870
  id: i.id
@@ -3850,10 +3958,8 @@ var _Provider = class {
3850
3958
  * Returns some helpful parameters related to gas fees.
3851
3959
  */
3852
3960
  getGasConfig() {
3853
- const { minGasPrice } = this.getNode();
3854
3961
  const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
3855
3962
  return {
3856
- minGasPrice,
3857
3963
  maxGasPerTx,
3858
3964
  maxGasPerPredicate,
3859
3965
  gasPriceFactor,
@@ -3929,6 +4035,21 @@ var _Provider = class {
3929
4035
  } = await this.operations.getVersion();
3930
4036
  return nodeVersion;
3931
4037
  }
4038
+ /**
4039
+ * @hidden
4040
+ *
4041
+ * Returns the network configuration of the connected Fuel node.
4042
+ *
4043
+ * @returns A promise that resolves to the network configuration object
4044
+ */
4045
+ async getNetwork() {
4046
+ const {
4047
+ name,
4048
+ consensusParameters: { chainId }
4049
+ } = await this.getChain();
4050
+ const network = new import_ethers.Network(name, chainId.toNumber());
4051
+ return Promise.resolve(network);
4052
+ }
3932
4053
  /**
3933
4054
  * Returns the block number.
3934
4055
  *
@@ -3936,7 +4057,7 @@ var _Provider = class {
3936
4057
  */
3937
4058
  async getBlockNumber() {
3938
4059
  const { chain } = await this.operations.getChain();
3939
- return (0, import_math15.bn)(chain.latestBlock.header.height, 10);
4060
+ return (0, import_math16.bn)(chain.latestBlock.height, 10);
3940
4061
  }
3941
4062
  /**
3942
4063
  * Returns the chain information.
@@ -3946,13 +4067,11 @@ var _Provider = class {
3946
4067
  async fetchNode() {
3947
4068
  const { nodeInfo } = await this.operations.getNodeInfo();
3948
4069
  const processedNodeInfo = {
3949
- maxDepth: (0, import_math15.bn)(nodeInfo.maxDepth),
3950
- maxTx: (0, import_math15.bn)(nodeInfo.maxTx),
3951
- minGasPrice: (0, import_math15.bn)(nodeInfo.minGasPrice),
4070
+ maxDepth: (0, import_math16.bn)(nodeInfo.maxDepth),
4071
+ maxTx: (0, import_math16.bn)(nodeInfo.maxTx),
3952
4072
  nodeVersion: nodeInfo.nodeVersion,
3953
4073
  utxoValidation: nodeInfo.utxoValidation,
3954
- vmBacktrace: nodeInfo.vmBacktrace,
3955
- peers: nodeInfo.peers
4074
+ vmBacktrace: nodeInfo.vmBacktrace
3956
4075
  };
3957
4076
  _Provider.nodeInfoCache[this.url] = processedNodeInfo;
3958
4077
  return processedNodeInfo;
@@ -3994,9 +4113,9 @@ var _Provider = class {
3994
4113
  if (estimateTxDependencies) {
3995
4114
  await this.estimateTxDependencies(transactionRequest);
3996
4115
  }
3997
- const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
4116
+ const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
3998
4117
  let abis;
3999
- if (transactionRequest.type === import_transactions18.TransactionType.Script) {
4118
+ if (transactionRequest.type === import_transactions19.TransactionType.Script) {
4000
4119
  abis = transactionRequest.abis;
4001
4120
  }
4002
4121
  if (awaitExecution) {
@@ -4037,15 +4156,14 @@ var _Provider = class {
4037
4156
  if (estimateTxDependencies) {
4038
4157
  return this.estimateTxDependencies(transactionRequest);
4039
4158
  }
4040
- const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
4041
- const { dryRun: gqlReceipts } = await this.operations.dryRun({
4042
- encodedTransaction,
4159
+ const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
4160
+ const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4161
+ encodedTransactions: encodedTransaction,
4043
4162
  utxoValidation: utxoValidation || false
4044
4163
  });
4045
- const receipts = gqlReceipts.map(processGqlReceipt);
4046
- return {
4047
- receipts
4048
- };
4164
+ const [{ receipts: rawReceipts, status }] = dryRunStatuses;
4165
+ const receipts = rawReceipts.map(processGqlReceipt);
4166
+ return { receipts, dryrunStatus: status };
4049
4167
  }
4050
4168
  /**
4051
4169
  * Verifies whether enough gas is available to complete transaction.
@@ -4056,13 +4174,13 @@ var _Provider = class {
4056
4174
  async estimatePredicates(transactionRequest) {
4057
4175
  const shouldEstimatePredicates = Boolean(
4058
4176
  transactionRequest.inputs.find(
4059
- (input) => "predicate" in input && input.predicate && !(0, import_utils24.equalBytes)((0, import_utils23.arrayify)(input.predicate), (0, import_utils23.arrayify)("0x")) && new import_math15.BN(input.predicateGasUsed).isZero()
4177
+ (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()
4060
4178
  )
4061
4179
  );
4062
4180
  if (!shouldEstimatePredicates) {
4063
4181
  return transactionRequest;
4064
4182
  }
4065
- const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
4183
+ const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
4066
4184
  const response = await this.operations.estimatePredicates({
4067
4185
  encodedTransaction
4068
4186
  });
@@ -4071,7 +4189,7 @@ var _Provider = class {
4071
4189
  } = response;
4072
4190
  if (inputs) {
4073
4191
  inputs.forEach((input, index) => {
4074
- if ("predicateGasUsed" in input && (0, import_math15.bn)(input.predicateGasUsed).gt(0)) {
4192
+ if ("predicateGasUsed" in input && (0, import_math16.bn)(input.predicateGasUsed).gt(0)) {
4075
4193
  transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
4076
4194
  }
4077
4195
  });
@@ -4084,31 +4202,31 @@ var _Provider = class {
4084
4202
  * If there are missing variable outputs,
4085
4203
  * `addVariableOutputs` is called on the transaction.
4086
4204
  *
4087
- * @privateRemarks
4088
- * TODO: Investigate support for missing contract IDs
4089
- * TODO: Add support for missing output messages
4090
4205
  *
4091
4206
  * @param transactionRequest - The transaction request object.
4092
4207
  * @returns A promise.
4093
4208
  */
4094
4209
  async estimateTxDependencies(transactionRequest) {
4095
- if (transactionRequest.type === import_transactions18.TransactionType.Create) {
4210
+ if (transactionRequest.type === import_transactions19.TransactionType.Create) {
4096
4211
  return {
4097
4212
  receipts: [],
4098
4213
  outputVariables: 0,
4099
4214
  missingContractIds: []
4100
4215
  };
4101
4216
  }
4102
- await this.estimatePredicates(transactionRequest);
4103
4217
  let receipts = [];
4104
4218
  const missingContractIds = [];
4105
4219
  let outputVariables = 0;
4220
+ let dryrunStatus;
4106
4221
  for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
4107
- const { dryRun: gqlReceipts } = await this.operations.dryRun({
4108
- encodedTransaction: (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes()),
4222
+ const {
4223
+ dryRun: [{ receipts: rawReceipts, status }]
4224
+ } = await this.operations.dryRun({
4225
+ encodedTransactions: [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())],
4109
4226
  utxoValidation: false
4110
4227
  });
4111
- receipts = gqlReceipts.map(processGqlReceipt);
4228
+ receipts = rawReceipts.map(processGqlReceipt);
4229
+ dryrunStatus = status;
4112
4230
  const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
4113
4231
  const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
4114
4232
  if (hasMissingOutputs) {
@@ -4118,6 +4236,10 @@ var _Provider = class {
4118
4236
  transactionRequest.addContractInputAndOutput(import_address3.Address.fromString(contractId));
4119
4237
  missingContractIds.push(contractId);
4120
4238
  });
4239
+ const { maxFee } = await this.estimateTxGasAndFee({
4240
+ transactionRequest
4241
+ });
4242
+ transactionRequest.maxFee = maxFee;
4121
4243
  } else {
4122
4244
  break;
4123
4245
  }
@@ -4125,37 +4247,139 @@ var _Provider = class {
4125
4247
  return {
4126
4248
  receipts,
4127
4249
  outputVariables,
4128
- missingContractIds
4250
+ missingContractIds,
4251
+ dryrunStatus
4129
4252
  };
4130
4253
  }
4254
+ /**
4255
+ * Dry runs multiple transactions and checks for missing dependencies in batches.
4256
+ *
4257
+ * Transactions are dry run in batches. After each dry run, transactions requiring
4258
+ * further modifications are identified. The method iteratively updates these transactions
4259
+ * and performs subsequent dry runs until all dependencies for each transaction are satisfied.
4260
+ *
4261
+ * @param transactionRequests - Array of transaction request objects.
4262
+ * @returns A promise that resolves to an array of results for each transaction.
4263
+ */
4264
+ async estimateMultipleTxDependencies(transactionRequests) {
4265
+ const results = transactionRequests.map(() => ({
4266
+ receipts: [],
4267
+ outputVariables: 0,
4268
+ missingContractIds: [],
4269
+ dryrunStatus: void 0
4270
+ }));
4271
+ const allRequests = (0, import_ramda3.clone)(transactionRequests);
4272
+ const serializedTransactionsMap = /* @__PURE__ */ new Map();
4273
+ allRequests.forEach((req, index) => {
4274
+ if (req.type === import_transactions19.TransactionType.Script) {
4275
+ serializedTransactionsMap.set(index, (0, import_utils22.hexlify)(req.toTransactionBytes()));
4276
+ }
4277
+ });
4278
+ let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
4279
+ let attempt = 0;
4280
+ while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
4281
+ const encodedTransactions = transactionsToProcess.map(
4282
+ (index) => serializedTransactionsMap.get(index)
4283
+ );
4284
+ const dryRunResults = await this.operations.dryRun({
4285
+ encodedTransactions,
4286
+ utxoValidation: false
4287
+ });
4288
+ const nextRoundTransactions = [];
4289
+ for (let i = 0; i < dryRunResults.dryRun.length; i++) {
4290
+ const currentResultIndex = transactionsToProcess[i];
4291
+ const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
4292
+ results[currentResultIndex].receipts = rawReceipts.map(processGqlReceipt);
4293
+ results[currentResultIndex].dryrunStatus = status;
4294
+ const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
4295
+ results[currentResultIndex].receipts
4296
+ );
4297
+ const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
4298
+ const requestToProcess = allRequests[currentResultIndex];
4299
+ if (hasMissingOutputs && requestToProcess?.type === import_transactions19.TransactionType.Script) {
4300
+ results[currentResultIndex].outputVariables += missingOutputVariables.length;
4301
+ requestToProcess.addVariableOutputs(missingOutputVariables.length);
4302
+ missingOutputContractIds.forEach(({ contractId }) => {
4303
+ requestToProcess.addContractInputAndOutput(import_address3.Address.fromString(contractId));
4304
+ results[currentResultIndex].missingContractIds.push(contractId);
4305
+ });
4306
+ const { maxFee } = await this.estimateTxGasAndFee({
4307
+ transactionRequest: requestToProcess
4308
+ });
4309
+ requestToProcess.maxFee = maxFee;
4310
+ serializedTransactionsMap.set(
4311
+ currentResultIndex,
4312
+ (0, import_utils22.hexlify)(requestToProcess.toTransactionBytes())
4313
+ );
4314
+ nextRoundTransactions.push(currentResultIndex);
4315
+ allRequests[currentResultIndex] = requestToProcess;
4316
+ }
4317
+ }
4318
+ transactionsToProcess = nextRoundTransactions;
4319
+ attempt += 1;
4320
+ }
4321
+ return results;
4322
+ }
4323
+ async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
4324
+ if (estimateTxDependencies) {
4325
+ return this.estimateMultipleTxDependencies(transactionRequests);
4326
+ }
4327
+ const encodedTransactions = transactionRequests.map((tx) => (0, import_utils22.hexlify)(tx.toTransactionBytes()));
4328
+ const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4329
+ encodedTransactions,
4330
+ utxoValidation: utxoValidation || false
4331
+ });
4332
+ const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
4333
+ const receipts = rawReceipts.map(processGqlReceipt);
4334
+ return { receipts, dryrunStatus: status };
4335
+ });
4336
+ return results;
4337
+ }
4131
4338
  /**
4132
4339
  * Estimates the transaction gas and fee based on the provided transaction request.
4133
4340
  * @param transactionRequest - The transaction request object.
4134
4341
  * @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
4135
4342
  */
4136
- estimateTxGasAndFee(params) {
4343
+ async estimateTxGasAndFee(params) {
4137
4344
  const { transactionRequest } = params;
4138
- const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
4345
+ let { gasPrice } = params;
4139
4346
  const chainInfo = this.getChain();
4140
- const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
4141
- transactionRequest.gasPrice = gasPrice;
4347
+ const { gasPriceFactor, maxGasPerTx } = this.getGasConfig();
4142
4348
  const minGas = transactionRequest.calculateMinGas(chainInfo);
4143
- const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
4144
- if (transactionRequest.type === import_transactions18.TransactionType.Script) {
4349
+ if (!gasPrice) {
4350
+ gasPrice = await this.estimateGasPrice(10);
4351
+ }
4352
+ const minFee = calculateGasFee({
4353
+ gasPrice: (0, import_math16.bn)(gasPrice),
4354
+ gas: minGas,
4355
+ priceFactor: gasPriceFactor,
4356
+ tip: transactionRequest.tip
4357
+ }).add(1);
4358
+ let gasLimit = (0, import_math16.bn)(0);
4359
+ if (transactionRequest.type === import_transactions19.TransactionType.Script) {
4360
+ gasLimit = transactionRequest.gasLimit;
4145
4361
  if (transactionRequest.gasLimit.eq(0)) {
4146
4362
  transactionRequest.gasLimit = minGas;
4147
4363
  transactionRequest.gasLimit = maxGasPerTx.sub(
4148
4364
  transactionRequest.calculateMaxGas(chainInfo, minGas)
4149
4365
  );
4366
+ gasLimit = transactionRequest.gasLimit;
4150
4367
  }
4151
4368
  }
4152
4369
  const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
4153
- const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
4370
+ const maxFee = calculateGasFee({
4371
+ gasPrice: (0, import_math16.bn)(gasPrice),
4372
+ gas: maxGas,
4373
+ priceFactor: gasPriceFactor,
4374
+ tip: transactionRequest.tip
4375
+ }).add(1);
4154
4376
  return {
4155
4377
  minGas,
4156
4378
  minFee,
4157
4379
  maxGas,
4158
- maxFee
4380
+ maxFee,
4381
+ gasPrice,
4382
+ gasLimit
4159
4383
  };
4160
4384
  }
4161
4385
  /**
@@ -4173,15 +4397,17 @@ var _Provider = class {
4173
4397
  if (estimateTxDependencies) {
4174
4398
  return this.estimateTxDependencies(transactionRequest);
4175
4399
  }
4176
- const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
4177
- const { dryRun: gqlReceipts } = await this.operations.dryRun({
4178
- encodedTransaction,
4400
+ const encodedTransactions = [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())];
4401
+ const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4402
+ encodedTransactions,
4179
4403
  utxoValidation: true
4180
4404
  });
4181
- const receipts = gqlReceipts.map(processGqlReceipt);
4182
- return {
4183
- receipts
4184
- };
4405
+ const callResult = dryRunStatuses.map((dryRunStatus) => {
4406
+ const { id, receipts, status } = dryRunStatus;
4407
+ const processedReceipts = receipts.map(processGqlReceipt);
4408
+ return { id, receipts: processedReceipts, status };
4409
+ });
4410
+ return { receipts: callResult[0].receipts };
4185
4411
  }
4186
4412
  /**
4187
4413
  * Returns a transaction cost to enable user
@@ -4198,77 +4424,79 @@ var _Provider = class {
4198
4424
  * @param tolerance - The tolerance to add on top of the gasUsed.
4199
4425
  * @returns A promise that resolves to the transaction cost object.
4200
4426
  */
4201
- async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
4202
- estimateTxDependencies = true,
4203
- estimatePredicates = true,
4204
- resourcesOwner,
4205
- signatureCallback
4206
- } = {}) {
4427
+ async getTransactionCost(transactionRequestLike, { resourcesOwner, signatureCallback, quantitiesToContract = [] } = {}) {
4207
4428
  const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
4208
- const { minGasPrice } = this.getGasConfig();
4209
- const setGasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
4210
- const isScriptTransaction = txRequestClone.type === import_transactions18.TransactionType.Script;
4429
+ const isScriptTransaction = txRequestClone.type === import_transactions19.TransactionType.Script;
4211
4430
  const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
4212
- const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
4431
+ const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
4213
4432
  txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
4433
+ txRequestClone.maxFee = (0, import_math16.bn)(0);
4214
4434
  if (isScriptTransaction) {
4215
- txRequestClone.gasLimit = (0, import_math15.bn)(0);
4435
+ txRequestClone.gasLimit = (0, import_math16.bn)(0);
4216
4436
  }
4217
- if (estimatePredicates) {
4218
- if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
4219
- resourcesOwner.populateTransactionPredicateData(txRequestClone);
4220
- }
4221
- await this.estimatePredicates(txRequestClone);
4437
+ if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
4438
+ resourcesOwner.populateTransactionPredicateData(txRequestClone);
4222
4439
  }
4440
+ const signedRequest = (0, import_ramda3.clone)(txRequestClone);
4441
+ let addedSignatures = 0;
4223
4442
  if (signatureCallback && isScriptTransaction) {
4224
- await signatureCallback(txRequestClone);
4443
+ const lengthBefore = signedRequest.witnesses.length;
4444
+ await signatureCallback(signedRequest);
4445
+ addedSignatures = signedRequest.witnesses.length - lengthBefore;
4225
4446
  }
4226
- let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
4227
- transactionRequest: txRequestClone
4447
+ await this.estimatePredicates(signedRequest);
4448
+ let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
4449
+ transactionRequest: signedRequest
4228
4450
  });
4229
4451
  let receipts = [];
4230
4452
  let missingContractIds = [];
4231
4453
  let outputVariables = 0;
4232
- let gasUsed = (0, import_math15.bn)(0);
4233
- if (isScriptTransaction && estimateTxDependencies) {
4234
- txRequestClone.gasPrice = (0, import_math15.bn)(0);
4454
+ let gasUsed = (0, import_math16.bn)(0);
4455
+ txRequestClone.updatePredicateGasUsed(signedRequest.inputs);
4456
+ txRequestClone.maxFee = maxFee;
4457
+ if (isScriptTransaction) {
4458
+ txRequestClone.gasLimit = gasLimit;
4459
+ if (signatureCallback) {
4460
+ await signatureCallback(txRequestClone);
4461
+ }
4235
4462
  const result = await this.estimateTxDependencies(txRequestClone);
4236
4463
  receipts = result.receipts;
4237
4464
  outputVariables = result.outputVariables;
4238
4465
  missingContractIds = result.missingContractIds;
4239
4466
  gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
4240
4467
  txRequestClone.gasLimit = gasUsed;
4241
- txRequestClone.gasPrice = setGasPrice;
4242
- ({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
4243
- transactionRequest: txRequestClone
4468
+ ({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
4469
+ transactionRequest: txRequestClone,
4470
+ gasPrice
4244
4471
  }));
4245
4472
  }
4246
4473
  return {
4247
4474
  requiredQuantities: allQuantities,
4248
4475
  receipts,
4249
4476
  gasUsed,
4250
- minGasPrice,
4251
- gasPrice: setGasPrice,
4477
+ gasPrice,
4252
4478
  minGas,
4253
4479
  maxGas,
4254
4480
  minFee,
4255
4481
  maxFee,
4256
- estimatedInputs: txRequestClone.inputs,
4257
4482
  outputVariables,
4258
- missingContractIds
4483
+ missingContractIds,
4484
+ addedSignatures,
4485
+ estimatedPredicates: txRequestClone.inputs
4259
4486
  };
4260
4487
  }
4261
- async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
4488
+ async getResourcesForTransaction(owner, transactionRequestLike, quantitiesToContract = []) {
4262
4489
  const ownerAddress = import_address3.Address.fromAddressOrString(owner);
4263
4490
  const transactionRequest = transactionRequestify((0, import_ramda3.clone)(transactionRequestLike));
4264
- const transactionCost = await this.getTransactionCost(transactionRequest, forwardingQuantities);
4491
+ const transactionCost = await this.getTransactionCost(transactionRequest, {
4492
+ quantitiesToContract
4493
+ });
4265
4494
  transactionRequest.addResources(
4266
4495
  await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
4267
4496
  );
4268
- const { requiredQuantities, ...txCost } = await this.getTransactionCost(
4269
- transactionRequest,
4270
- forwardingQuantities
4271
- );
4497
+ const { requiredQuantities, ...txCost } = await this.getTransactionCost(transactionRequest, {
4498
+ quantitiesToContract
4499
+ });
4272
4500
  const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
4273
4501
  return {
4274
4502
  resources,
@@ -4284,17 +4512,16 @@ var _Provider = class {
4284
4512
  const result = await this.operations.getCoins({
4285
4513
  first: 10,
4286
4514
  ...paginationArgs,
4287
- filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils23.hexlify)(assetId) }
4515
+ filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils22.hexlify)(assetId) }
4288
4516
  });
4289
4517
  const coins = result.coins.edges.map((edge) => edge.node);
4290
4518
  return coins.map((coin) => ({
4291
4519
  id: coin.utxoId,
4292
4520
  assetId: coin.assetId,
4293
- amount: (0, import_math15.bn)(coin.amount),
4521
+ amount: (0, import_math16.bn)(coin.amount),
4294
4522
  owner: import_address3.Address.fromAddressOrString(coin.owner),
4295
- maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
4296
- blockCreated: (0, import_math15.bn)(coin.blockCreated),
4297
- txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
4523
+ blockCreated: (0, import_math16.bn)(coin.blockCreated),
4524
+ txCreatedIdx: (0, import_math16.bn)(coin.txCreatedIdx)
4298
4525
  }));
4299
4526
  }
4300
4527
  /**
@@ -4308,19 +4535,19 @@ var _Provider = class {
4308
4535
  async getResourcesToSpend(owner, quantities, excludedIds) {
4309
4536
  const ownerAddress = import_address3.Address.fromAddressOrString(owner);
4310
4537
  const excludeInput = {
4311
- messages: excludedIds?.messages?.map((nonce) => (0, import_utils23.hexlify)(nonce)) || [],
4312
- utxos: excludedIds?.utxos?.map((id) => (0, import_utils23.hexlify)(id)) || []
4538
+ messages: excludedIds?.messages?.map((nonce) => (0, import_utils22.hexlify)(nonce)) || [],
4539
+ utxos: excludedIds?.utxos?.map((id) => (0, import_utils22.hexlify)(id)) || []
4313
4540
  };
4314
4541
  if (this.cache) {
4315
4542
  const uniqueUtxos = new Set(
4316
- excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils23.hexlify)(id)))
4543
+ excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils22.hexlify)(id)))
4317
4544
  );
4318
4545
  excludeInput.utxos = Array.from(uniqueUtxos);
4319
4546
  }
4320
4547
  const coinsQuery = {
4321
4548
  owner: ownerAddress.toB256(),
4322
4549
  queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
4323
- assetId: (0, import_utils23.hexlify)(assetId),
4550
+ assetId: (0, import_utils22.hexlify)(assetId),
4324
4551
  amount: amount.toString(10),
4325
4552
  max: maxPerAsset ? maxPerAsset.toString(10) : void 0
4326
4553
  })),
@@ -4331,9 +4558,9 @@ var _Provider = class {
4331
4558
  switch (coin.__typename) {
4332
4559
  case "MessageCoin":
4333
4560
  return {
4334
- amount: (0, import_math15.bn)(coin.amount),
4561
+ amount: (0, import_math16.bn)(coin.amount),
4335
4562
  assetId: coin.assetId,
4336
- daHeight: (0, import_math15.bn)(coin.daHeight),
4563
+ daHeight: (0, import_math16.bn)(coin.daHeight),
4337
4564
  sender: import_address3.Address.fromAddressOrString(coin.sender),
4338
4565
  recipient: import_address3.Address.fromAddressOrString(coin.recipient),
4339
4566
  nonce: coin.nonce
@@ -4341,12 +4568,11 @@ var _Provider = class {
4341
4568
  case "Coin":
4342
4569
  return {
4343
4570
  id: coin.utxoId,
4344
- amount: (0, import_math15.bn)(coin.amount),
4571
+ amount: (0, import_math16.bn)(coin.amount),
4345
4572
  assetId: coin.assetId,
4346
4573
  owner: import_address3.Address.fromAddressOrString(coin.owner),
4347
- maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
4348
- blockCreated: (0, import_math15.bn)(coin.blockCreated),
4349
- txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
4574
+ blockCreated: (0, import_math16.bn)(coin.blockCreated),
4575
+ txCreatedIdx: (0, import_math16.bn)(coin.txCreatedIdx)
4350
4576
  };
4351
4577
  default:
4352
4578
  return null;
@@ -4363,13 +4589,13 @@ var _Provider = class {
4363
4589
  async getBlock(idOrHeight) {
4364
4590
  let variables;
4365
4591
  if (typeof idOrHeight === "number") {
4366
- variables = { height: (0, import_math15.bn)(idOrHeight).toString(10) };
4592
+ variables = { height: (0, import_math16.bn)(idOrHeight).toString(10) };
4367
4593
  } else if (idOrHeight === "latest") {
4368
4594
  variables = { height: (await this.getBlockNumber()).toString(10) };
4369
4595
  } else if (idOrHeight.length === 66) {
4370
4596
  variables = { blockId: idOrHeight };
4371
4597
  } else {
4372
- variables = { blockId: (0, import_math15.bn)(idOrHeight).toString(10) };
4598
+ variables = { blockId: (0, import_math16.bn)(idOrHeight).toString(10) };
4373
4599
  }
4374
4600
  const { block } = await this.operations.getBlock(variables);
4375
4601
  if (!block) {
@@ -4377,7 +4603,7 @@ var _Provider = class {
4377
4603
  }
4378
4604
  return {
4379
4605
  id: block.id,
4380
- height: (0, import_math15.bn)(block.header.height),
4606
+ height: (0, import_math16.bn)(block.height),
4381
4607
  time: block.header.time,
4382
4608
  transactionIds: block.transactions.map((tx) => tx.id)
4383
4609
  };
@@ -4392,7 +4618,7 @@ var _Provider = class {
4392
4618
  const { blocks: fetchedData } = await this.operations.getBlocks(params);
4393
4619
  const blocks = fetchedData.edges.map(({ node: block }) => ({
4394
4620
  id: block.id,
4395
- height: (0, import_math15.bn)(block.header.height),
4621
+ height: (0, import_math16.bn)(block.height),
4396
4622
  time: block.header.time,
4397
4623
  transactionIds: block.transactions.map((tx) => tx.id)
4398
4624
  }));
@@ -4407,7 +4633,7 @@ var _Provider = class {
4407
4633
  async getBlockWithTransactions(idOrHeight) {
4408
4634
  let variables;
4409
4635
  if (typeof idOrHeight === "number") {
4410
- variables = { blockHeight: (0, import_math15.bn)(idOrHeight).toString(10) };
4636
+ variables = { blockHeight: (0, import_math16.bn)(idOrHeight).toString(10) };
4411
4637
  } else if (idOrHeight === "latest") {
4412
4638
  variables = { blockHeight: (await this.getBlockNumber()).toString() };
4413
4639
  } else {
@@ -4419,11 +4645,11 @@ var _Provider = class {
4419
4645
  }
4420
4646
  return {
4421
4647
  id: block.id,
4422
- height: (0, import_math15.bn)(block.header.height, 10),
4648
+ height: (0, import_math16.bn)(block.height, 10),
4423
4649
  time: block.header.time,
4424
4650
  transactionIds: block.transactions.map((tx) => tx.id),
4425
4651
  transactions: block.transactions.map(
4426
- (tx) => new import_transactions18.TransactionCoder().decode((0, import_utils23.arrayify)(tx.rawPayload), 0)?.[0]
4652
+ (tx) => new import_transactions19.TransactionCoder().decode((0, import_utils22.arrayify)(tx.rawPayload), 0)?.[0]
4427
4653
  )
4428
4654
  };
4429
4655
  }
@@ -4438,8 +4664,8 @@ var _Provider = class {
4438
4664
  if (!transaction) {
4439
4665
  return null;
4440
4666
  }
4441
- return new import_transactions18.TransactionCoder().decode(
4442
- (0, import_utils23.arrayify)(transaction.rawPayload),
4667
+ return new import_transactions19.TransactionCoder().decode(
4668
+ (0, import_utils22.arrayify)(transaction.rawPayload),
4443
4669
  0
4444
4670
  )?.[0];
4445
4671
  }
@@ -4466,9 +4692,9 @@ var _Provider = class {
4466
4692
  async getContractBalance(contractId, assetId) {
4467
4693
  const { contractBalance } = await this.operations.getContractBalance({
4468
4694
  contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
4469
- asset: (0, import_utils23.hexlify)(assetId)
4695
+ asset: (0, import_utils22.hexlify)(assetId)
4470
4696
  });
4471
- return (0, import_math15.bn)(contractBalance.amount, 10);
4697
+ return (0, import_math16.bn)(contractBalance.amount, 10);
4472
4698
  }
4473
4699
  /**
4474
4700
  * Returns the balance for the given owner for the given asset ID.
@@ -4480,9 +4706,9 @@ var _Provider = class {
4480
4706
  async getBalance(owner, assetId) {
4481
4707
  const { balance } = await this.operations.getBalance({
4482
4708
  owner: import_address3.Address.fromAddressOrString(owner).toB256(),
4483
- assetId: (0, import_utils23.hexlify)(assetId)
4709
+ assetId: (0, import_utils22.hexlify)(assetId)
4484
4710
  });
4485
- return (0, import_math15.bn)(balance.amount, 10);
4711
+ return (0, import_math16.bn)(balance.amount, 10);
4486
4712
  }
4487
4713
  /**
4488
4714
  * Returns balances for the given owner.
@@ -4500,7 +4726,7 @@ var _Provider = class {
4500
4726
  const balances = result.balances.edges.map((edge) => edge.node);
4501
4727
  return balances.map((balance) => ({
4502
4728
  assetId: balance.assetId,
4503
- amount: (0, import_math15.bn)(balance.amount)
4729
+ amount: (0, import_math16.bn)(balance.amount)
4504
4730
  }));
4505
4731
  }
4506
4732
  /**
@@ -4518,19 +4744,19 @@ var _Provider = class {
4518
4744
  });
4519
4745
  const messages = result.messages.edges.map((edge) => edge.node);
4520
4746
  return messages.map((message) => ({
4521
- messageId: import_transactions18.InputMessageCoder.getMessageId({
4747
+ messageId: import_transactions19.InputMessageCoder.getMessageId({
4522
4748
  sender: message.sender,
4523
4749
  recipient: message.recipient,
4524
4750
  nonce: message.nonce,
4525
- amount: (0, import_math15.bn)(message.amount),
4751
+ amount: (0, import_math16.bn)(message.amount),
4526
4752
  data: message.data
4527
4753
  }),
4528
4754
  sender: import_address3.Address.fromAddressOrString(message.sender),
4529
4755
  recipient: import_address3.Address.fromAddressOrString(message.recipient),
4530
4756
  nonce: message.nonce,
4531
- amount: (0, import_math15.bn)(message.amount),
4532
- data: import_transactions18.InputMessageCoder.decodeData(message.data),
4533
- daHeight: (0, import_math15.bn)(message.daHeight)
4757
+ amount: (0, import_math16.bn)(message.amount),
4758
+ data: import_transactions19.InputMessageCoder.decodeData(message.data),
4759
+ daHeight: (0, import_math16.bn)(message.daHeight)
4534
4760
  }));
4535
4761
  }
4536
4762
  /**
@@ -4583,44 +4809,60 @@ var _Provider = class {
4583
4809
  } = result.messageProof;
4584
4810
  return {
4585
4811
  messageProof: {
4586
- proofIndex: (0, import_math15.bn)(messageProof.proofIndex),
4812
+ proofIndex: (0, import_math16.bn)(messageProof.proofIndex),
4587
4813
  proofSet: messageProof.proofSet
4588
4814
  },
4589
4815
  blockProof: {
4590
- proofIndex: (0, import_math15.bn)(blockProof.proofIndex),
4816
+ proofIndex: (0, import_math16.bn)(blockProof.proofIndex),
4591
4817
  proofSet: blockProof.proofSet
4592
4818
  },
4593
4819
  messageBlockHeader: {
4594
4820
  id: messageBlockHeader.id,
4595
- daHeight: (0, import_math15.bn)(messageBlockHeader.daHeight),
4596
- transactionsCount: (0, import_math15.bn)(messageBlockHeader.transactionsCount),
4821
+ daHeight: (0, import_math16.bn)(messageBlockHeader.daHeight),
4822
+ transactionsCount: (0, import_math16.bn)(messageBlockHeader.transactionsCount),
4597
4823
  transactionsRoot: messageBlockHeader.transactionsRoot,
4598
- height: (0, import_math15.bn)(messageBlockHeader.height),
4824
+ height: (0, import_math16.bn)(messageBlockHeader.height),
4599
4825
  prevRoot: messageBlockHeader.prevRoot,
4600
4826
  time: messageBlockHeader.time,
4601
4827
  applicationHash: messageBlockHeader.applicationHash,
4602
- messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
4603
- messageReceiptCount: (0, import_math15.bn)(messageBlockHeader.messageReceiptCount)
4828
+ messageReceiptCount: (0, import_math16.bn)(messageBlockHeader.messageReceiptCount),
4829
+ messageOutboxRoot: messageBlockHeader.messageOutboxRoot,
4830
+ consensusParametersVersion: messageBlockHeader.consensusParametersVersion,
4831
+ eventInboxRoot: messageBlockHeader.eventInboxRoot,
4832
+ stateTransitionBytecodeVersion: messageBlockHeader.stateTransitionBytecodeVersion
4604
4833
  },
4605
4834
  commitBlockHeader: {
4606
4835
  id: commitBlockHeader.id,
4607
- daHeight: (0, import_math15.bn)(commitBlockHeader.daHeight),
4608
- transactionsCount: (0, import_math15.bn)(commitBlockHeader.transactionsCount),
4836
+ daHeight: (0, import_math16.bn)(commitBlockHeader.daHeight),
4837
+ transactionsCount: (0, import_math16.bn)(commitBlockHeader.transactionsCount),
4609
4838
  transactionsRoot: commitBlockHeader.transactionsRoot,
4610
- height: (0, import_math15.bn)(commitBlockHeader.height),
4839
+ height: (0, import_math16.bn)(commitBlockHeader.height),
4611
4840
  prevRoot: commitBlockHeader.prevRoot,
4612
4841
  time: commitBlockHeader.time,
4613
4842
  applicationHash: commitBlockHeader.applicationHash,
4614
- messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
4615
- messageReceiptCount: (0, import_math15.bn)(commitBlockHeader.messageReceiptCount)
4843
+ messageReceiptCount: (0, import_math16.bn)(commitBlockHeader.messageReceiptCount),
4844
+ messageOutboxRoot: commitBlockHeader.messageOutboxRoot,
4845
+ consensusParametersVersion: commitBlockHeader.consensusParametersVersion,
4846
+ eventInboxRoot: commitBlockHeader.eventInboxRoot,
4847
+ stateTransitionBytecodeVersion: commitBlockHeader.stateTransitionBytecodeVersion
4616
4848
  },
4617
4849
  sender: import_address3.Address.fromAddressOrString(sender),
4618
4850
  recipient: import_address3.Address.fromAddressOrString(recipient),
4619
4851
  nonce,
4620
- amount: (0, import_math15.bn)(amount),
4852
+ amount: (0, import_math16.bn)(amount),
4621
4853
  data
4622
4854
  };
4623
4855
  }
4856
+ async getLatestGasPrice() {
4857
+ const { latestGasPrice } = await this.operations.getLatestGasPrice();
4858
+ return (0, import_math16.bn)(latestGasPrice.gasPrice);
4859
+ }
4860
+ async estimateGasPrice(blockHorizon) {
4861
+ const { estimateGasPrice } = await this.operations.estimateGasPrice({
4862
+ blockHorizon: String(blockHorizon)
4863
+ });
4864
+ return (0, import_math16.bn)(estimateGasPrice.gasPrice);
4865
+ }
4624
4866
  /**
4625
4867
  * Returns Message Proof for given transaction id and the message id from MessageOut receipt.
4626
4868
  *
@@ -4640,10 +4882,10 @@ var _Provider = class {
4640
4882
  */
4641
4883
  async produceBlocks(amount, startTime) {
4642
4884
  const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
4643
- blocksToProduce: (0, import_math15.bn)(amount).toString(10),
4644
- startTimestamp: startTime ? import_utils23.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
4885
+ blocksToProduce: (0, import_math16.bn)(amount).toString(10),
4886
+ startTimestamp: startTime ? import_utils22.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
4645
4887
  });
4646
- return (0, import_math15.bn)(latestBlockHeight);
4888
+ return (0, import_math16.bn)(latestBlockHeight);
4647
4889
  }
4648
4890
  // eslint-disable-next-line @typescript-eslint/require-await
4649
4891
  async getTransactionResponse(transactionId) {
@@ -4657,7 +4899,7 @@ cacheInputs_fn = function(inputs) {
4657
4899
  return;
4658
4900
  }
4659
4901
  inputs.forEach((input) => {
4660
- if (input.type === import_transactions18.InputType.Coin) {
4902
+ if (input.type === import_transactions19.InputType.Coin) {
4661
4903
  this.cache?.set(input.id);
4662
4904
  }
4663
4905
  });
@@ -4667,9 +4909,9 @@ __publicField(Provider, "nodeInfoCache", {});
4667
4909
 
4668
4910
  // src/providers/transaction-summary/get-transaction-summary.ts
4669
4911
  var import_errors15 = require("@fuel-ts/errors");
4670
- var import_math16 = require("@fuel-ts/math");
4671
- var import_transactions19 = require("@fuel-ts/transactions");
4672
- var import_utils26 = require("@fuel-ts/utils");
4912
+ var import_math17 = require("@fuel-ts/math");
4913
+ var import_transactions20 = require("@fuel-ts/transactions");
4914
+ var import_utils25 = require("@fuel-ts/utils");
4673
4915
  async function getTransactionSummary(params) {
4674
4916
  const { id, provider, abiMap } = params;
4675
4917
  const { transaction: gqlTransaction } = await provider.operations.getTransactionWithReceipts({
@@ -4681,25 +4923,32 @@ async function getTransactionSummary(params) {
4681
4923
  `Transaction not found for given id: ${id}.`
4682
4924
  );
4683
4925
  }
4684
- const [decodedTransaction] = new import_transactions19.TransactionCoder().decode(
4685
- (0, import_utils26.arrayify)(gqlTransaction.rawPayload),
4926
+ const [decodedTransaction] = new import_transactions20.TransactionCoder().decode(
4927
+ (0, import_utils25.arrayify)(gqlTransaction.rawPayload),
4686
4928
  0
4687
4929
  );
4688
- const receipts = gqlTransaction.receipts?.map(processGqlReceipt) || [];
4930
+ let txReceipts = [];
4931
+ if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
4932
+ txReceipts = gqlTransaction.status.receipts;
4933
+ }
4934
+ const receipts = txReceipts.map(processGqlReceipt);
4689
4935
  const {
4690
- consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
4936
+ consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts, maxGasPerTx }
4691
4937
  } = provider.getChain();
4938
+ const gasPrice = await provider.getLatestGasPrice();
4692
4939
  const transactionInfo = assembleTransactionSummary({
4693
4940
  id: gqlTransaction.id,
4694
4941
  receipts,
4695
4942
  transaction: decodedTransaction,
4696
- transactionBytes: (0, import_utils26.arrayify)(gqlTransaction.rawPayload),
4943
+ transactionBytes: (0, import_utils25.arrayify)(gqlTransaction.rawPayload),
4697
4944
  gqlTransactionStatus: gqlTransaction.status,
4698
- gasPerByte: (0, import_math16.bn)(gasPerByte),
4699
- gasPriceFactor: (0, import_math16.bn)(gasPriceFactor),
4945
+ gasPerByte: (0, import_math17.bn)(gasPerByte),
4946
+ gasPriceFactor: (0, import_math17.bn)(gasPriceFactor),
4700
4947
  abiMap,
4701
4948
  maxInputs,
4702
- gasCosts
4949
+ gasCosts,
4950
+ maxGasPerTx,
4951
+ gasPrice
4703
4952
  });
4704
4953
  return {
4705
4954
  gqlTransaction,
@@ -4709,10 +4958,11 @@ async function getTransactionSummary(params) {
4709
4958
  async function getTransactionSummaryFromRequest(params) {
4710
4959
  const { provider, transactionRequest, abiMap } = params;
4711
4960
  const { receipts } = await provider.call(transactionRequest);
4712
- const { gasPerByte, gasPriceFactor, gasCosts } = provider.getGasConfig();
4961
+ const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = provider.getGasConfig();
4713
4962
  const maxInputs = provider.getChain().consensusParameters.maxInputs;
4714
4963
  const transaction = transactionRequest.toTransaction();
4715
4964
  const transactionBytes = transactionRequest.toTransactionBytes();
4965
+ const gasPrice = await provider.getLatestGasPrice();
4716
4966
  const transactionSummary = assembleTransactionSummary({
4717
4967
  receipts,
4718
4968
  transaction,
@@ -4721,7 +4971,9 @@ async function getTransactionSummaryFromRequest(params) {
4721
4971
  gasPerByte,
4722
4972
  gasPriceFactor,
4723
4973
  maxInputs,
4724
- gasCosts
4974
+ gasCosts,
4975
+ maxGasPerTx,
4976
+ gasPrice
4725
4977
  });
4726
4978
  return transactionSummary;
4727
4979
  }
@@ -4730,24 +4982,31 @@ async function getTransactionsSummaries(params) {
4730
4982
  const { transactionsByOwner } = await provider.operations.getTransactionsByOwner(filters);
4731
4983
  const { edges, pageInfo } = transactionsByOwner;
4732
4984
  const {
4733
- consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
4985
+ consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts, maxGasPerTx }
4734
4986
  } = provider.getChain();
4987
+ const gasPrice = await provider.getLatestGasPrice();
4735
4988
  const transactions = edges.map((edge) => {
4736
4989
  const { node: gqlTransaction } = edge;
4737
- const { id, rawPayload, receipts: gqlReceipts, status } = gqlTransaction;
4738
- const [decodedTransaction] = new import_transactions19.TransactionCoder().decode((0, import_utils26.arrayify)(rawPayload), 0);
4739
- const receipts = gqlReceipts?.map(processGqlReceipt) || [];
4990
+ const { id, rawPayload, status } = gqlTransaction;
4991
+ const [decodedTransaction] = new import_transactions20.TransactionCoder().decode((0, import_utils25.arrayify)(rawPayload), 0);
4992
+ let txReceipts = [];
4993
+ if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
4994
+ txReceipts = gqlTransaction.status.receipts;
4995
+ }
4996
+ const receipts = txReceipts.map(processGqlReceipt);
4740
4997
  const transactionSummary = assembleTransactionSummary({
4741
4998
  id,
4742
4999
  receipts,
4743
5000
  transaction: decodedTransaction,
4744
- transactionBytes: (0, import_utils26.arrayify)(rawPayload),
5001
+ transactionBytes: (0, import_utils25.arrayify)(rawPayload),
4745
5002
  gqlTransactionStatus: status,
4746
5003
  abiMap,
4747
5004
  gasPerByte,
4748
5005
  gasPriceFactor,
4749
5006
  maxInputs,
4750
- gasCosts
5007
+ gasCosts,
5008
+ maxGasPerTx,
5009
+ gasPrice
4751
5010
  });
4752
5011
  const output = {
4753
5012
  gqlTransaction,
@@ -4884,17 +5143,17 @@ var assets = [
4884
5143
 
4885
5144
  // src/utils/formatTransferToContractScriptData.ts
4886
5145
  var import_abi_coder6 = require("@fuel-ts/abi-coder");
4887
- var import_math17 = require("@fuel-ts/math");
4888
- var import_utils27 = require("@fuel-ts/utils");
5146
+ var import_math18 = require("@fuel-ts/math");
5147
+ var import_utils26 = require("@fuel-ts/utils");
4889
5148
  var asm = __toESM(require("@fuels/vm-asm"));
4890
5149
  var formatTransferToContractScriptData = (params) => {
4891
5150
  const { assetId, amountToTransfer, hexlifiedContractId } = params;
4892
5151
  const numberCoder = new import_abi_coder6.BigNumberCoder("u64");
4893
- const encoded = numberCoder.encode(new import_math17.BN(amountToTransfer).toNumber());
5152
+ const encoded = numberCoder.encode(new import_math18.BN(amountToTransfer).toNumber());
4894
5153
  const scriptData = Uint8Array.from([
4895
- ...(0, import_utils27.arrayify)(hexlifiedContractId),
5154
+ ...(0, import_utils26.arrayify)(hexlifiedContractId),
4896
5155
  ...encoded,
4897
- ...(0, import_utils27.arrayify)(assetId)
5156
+ ...(0, import_utils26.arrayify)(assetId)
4898
5157
  ]);
4899
5158
  return scriptData;
4900
5159
  };
@@ -5079,36 +5338,33 @@ var Account = class extends import_interfaces.AbstractAccount {
5079
5338
  * @param fee - The estimated transaction fee.
5080
5339
  * @returns A promise that resolves when the resources are added to the transaction.
5081
5340
  */
5082
- async fund(request, coinQuantities, fee) {
5083
- const updatedQuantities = addAmountToAsset({
5084
- amount: (0, import_math18.bn)(fee),
5341
+ async fund(request, params) {
5342
+ const { addedSignatures, estimatedPredicates, maxFee: fee, requiredQuantities } = params;
5343
+ const txRequest = request;
5344
+ const requiredQuantitiesWithFee = addAmountToCoinQuantities({
5345
+ amount: (0, import_math19.bn)(fee),
5085
5346
  assetId: import_configs12.BaseAssetId,
5086
- coinQuantities
5347
+ coinQuantities: requiredQuantities
5087
5348
  });
5088
5349
  const quantitiesDict = {};
5089
- updatedQuantities.forEach(({ amount, assetId }) => {
5350
+ requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
5090
5351
  quantitiesDict[assetId] = {
5091
5352
  required: amount,
5092
- owned: (0, import_math18.bn)(0)
5353
+ owned: (0, import_math19.bn)(0)
5093
5354
  };
5094
5355
  });
5095
- const cachedUtxos = [];
5096
- const cachedMessages = [];
5097
- const owner = this.address.toB256();
5098
- request.inputs.forEach((input) => {
5356
+ txRequest.inputs.forEach((input) => {
5099
5357
  const isResource = "amount" in input;
5100
5358
  if (isResource) {
5101
5359
  const isCoin2 = "owner" in input;
5102
5360
  if (isCoin2) {
5103
5361
  const assetId = String(input.assetId);
5104
- if (input.owner === owner && quantitiesDict[assetId]) {
5105
- const amount = (0, import_math18.bn)(input.amount);
5362
+ if (quantitiesDict[assetId]) {
5363
+ const amount = (0, import_math19.bn)(input.amount);
5106
5364
  quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
5107
- cachedUtxos.push(input.id);
5108
5365
  }
5109
- } else if (input.recipient === owner && input.amount && quantitiesDict[import_configs12.BaseAssetId]) {
5366
+ } else if (input.amount && quantitiesDict[import_configs12.BaseAssetId]) {
5110
5367
  quantitiesDict[import_configs12.BaseAssetId].owned = quantitiesDict[import_configs12.BaseAssetId].owned.add(input.amount);
5111
- cachedMessages.push(input.nonce);
5112
5368
  }
5113
5369
  }
5114
5370
  });
@@ -5123,12 +5379,23 @@ var Account = class extends import_interfaces.AbstractAccount {
5123
5379
  });
5124
5380
  const needsToBeFunded = missingQuantities.length;
5125
5381
  if (needsToBeFunded) {
5126
- const resources = await this.getResourcesToSpend(missingQuantities, {
5127
- messages: cachedMessages,
5128
- utxos: cachedUtxos
5129
- });
5130
- request.addResources(resources);
5382
+ const excludedIds = cacheTxInputsFromOwner(txRequest.inputs, this.address.toB256());
5383
+ const resources = await this.getResourcesToSpend(missingQuantities, excludedIds);
5384
+ txRequest.addResources(resources);
5385
+ }
5386
+ txRequest.shiftPredicateData();
5387
+ txRequest.updatePredicateGasUsed(estimatedPredicates);
5388
+ const requestToBeReEstimate = (0, import_ramda4.clone)(txRequest);
5389
+ if (addedSignatures) {
5390
+ Array.from({ length: addedSignatures }).forEach(
5391
+ () => requestToBeReEstimate.addEmptyWitness()
5392
+ );
5131
5393
  }
5394
+ const { maxFee } = await this.provider.estimateTxGasAndFee({
5395
+ transactionRequest: requestToBeReEstimate
5396
+ });
5397
+ txRequest.maxFee = maxFee;
5398
+ return txRequest;
5132
5399
  }
5133
5400
  /**
5134
5401
  * A helper that creates a transfer transaction request and returns it.
@@ -5136,28 +5403,25 @@ var Account = class extends import_interfaces.AbstractAccount {
5136
5403
  * @param destination - The address of the destination.
5137
5404
  * @param amount - The amount of coins to transfer.
5138
5405
  * @param assetId - The asset ID of the coins to transfer.
5139
- * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
5406
+ * @param txParams - The transaction parameters (gasLimit, tip, maturity, maxFee, witnessLimit).
5140
5407
  * @returns A promise that resolves to the prepared transaction request.
5141
5408
  */
5142
5409
  async createTransfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
5143
- const { minGasPrice } = this.provider.getGasConfig();
5144
- const params = { gasPrice: minGasPrice, ...txParams };
5145
- const request = new ScriptTransactionRequest(params);
5410
+ const request = new ScriptTransactionRequest(txParams);
5146
5411
  request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetId);
5147
- const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
5412
+ const txCost = await this.provider.getTransactionCost(request, {
5148
5413
  estimateTxDependencies: true,
5149
5414
  resourcesOwner: this
5150
5415
  });
5151
- request.gasPrice = (0, import_math18.bn)(txParams.gasPrice ?? minGasPrice);
5152
- request.gasLimit = (0, import_math18.bn)(txParams.gasLimit ?? gasUsed);
5153
- this.validateGas({
5154
- gasUsed,
5155
- gasPrice: request.gasPrice,
5156
- gasLimit: request.gasLimit,
5157
- minGasPrice
5158
- });
5159
- await this.fund(request, requiredQuantities, maxFee);
5160
- request.updatePredicateInputs(estimatedInputs);
5416
+ if ("gasLimit" in txParams) {
5417
+ this.validateGas({
5418
+ gasUsed: txCost.gasUsed,
5419
+ gasLimit: request.gasLimit
5420
+ });
5421
+ }
5422
+ request.gasLimit = txCost.gasUsed;
5423
+ request.maxFee = txCost.maxFee;
5424
+ await this.fund(request, txCost);
5161
5425
  return request;
5162
5426
  }
5163
5427
  /**
@@ -5170,7 +5434,7 @@ var Account = class extends import_interfaces.AbstractAccount {
5170
5434
  * @returns A promise that resolves to the transaction response.
5171
5435
  */
5172
5436
  async transfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
5173
- if ((0, import_math18.bn)(amount).lte(0)) {
5437
+ if ((0, import_math19.bn)(amount).lte(0)) {
5174
5438
  throw new import_errors16.FuelError(
5175
5439
  import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
5176
5440
  "Transfer amount must be a positive number."
@@ -5189,38 +5453,37 @@ var Account = class extends import_interfaces.AbstractAccount {
5189
5453
  * @returns A promise that resolves to the transaction response.
5190
5454
  */
5191
5455
  async transferToContract(contractId, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
5192
- if ((0, import_math18.bn)(amount).lte(0)) {
5456
+ if ((0, import_math19.bn)(amount).lte(0)) {
5193
5457
  throw new import_errors16.FuelError(
5194
5458
  import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
5195
5459
  "Transfer amount must be a positive number."
5196
5460
  );
5197
5461
  }
5198
5462
  const contractAddress = import_address4.Address.fromAddressOrString(contractId);
5199
- const { minGasPrice } = this.provider.getGasConfig();
5200
- const params = { gasPrice: minGasPrice, ...txParams };
5201
5463
  const { script, scriptData } = await assembleTransferToContractScript({
5202
5464
  hexlifiedContractId: contractAddress.toB256(),
5203
- amountToTransfer: (0, import_math18.bn)(amount),
5465
+ amountToTransfer: (0, import_math19.bn)(amount),
5204
5466
  assetId
5205
5467
  });
5206
5468
  const request = new ScriptTransactionRequest({
5207
- ...params,
5469
+ ...txParams,
5208
5470
  script,
5209
5471
  scriptData
5210
5472
  });
5211
5473
  request.addContractInputAndOutput(contractAddress);
5212
- const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
5213
- request,
5214
- [{ amount: (0, import_math18.bn)(amount), assetId: String(assetId) }]
5215
- );
5216
- request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
5217
- this.validateGas({
5218
- gasUsed,
5219
- gasPrice: request.gasPrice,
5220
- gasLimit: request.gasLimit,
5221
- minGasPrice
5474
+ const txCost = await this.provider.getTransactionCost(request, {
5475
+ resourcesOwner: this,
5476
+ quantitiesToContract: [{ amount: (0, import_math19.bn)(amount), assetId: String(assetId) }]
5222
5477
  });
5223
- await this.fund(request, requiredQuantities, maxFee);
5478
+ if (txParams.gasLimit) {
5479
+ this.validateGas({
5480
+ gasUsed: txCost.gasUsed,
5481
+ gasLimit: request.gasLimit
5482
+ });
5483
+ }
5484
+ request.gasLimit = txCost.gasUsed;
5485
+ request.maxFee = txCost.maxFee;
5486
+ await this.fund(request, txCost);
5224
5487
  return this.sendTransaction(request);
5225
5488
  }
5226
5489
  /**
@@ -5232,34 +5495,31 @@ var Account = class extends import_interfaces.AbstractAccount {
5232
5495
  * @returns A promise that resolves to the transaction response.
5233
5496
  */
5234
5497
  async withdrawToBaseLayer(recipient, amount, txParams = {}) {
5235
- const { minGasPrice } = this.provider.getGasConfig();
5236
5498
  const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
5237
- const recipientDataArray = (0, import_utils28.arrayify)(
5499
+ const recipientDataArray = (0, import_utils27.arrayify)(
5238
5500
  "0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
5239
5501
  );
5240
- const amountDataArray = (0, import_utils28.arrayify)(
5241
- "0x".concat((0, import_math18.bn)(amount).toHex().substring(2).padStart(16, "0"))
5502
+ const amountDataArray = (0, import_utils27.arrayify)(
5503
+ "0x".concat((0, import_math19.bn)(amount).toHex().substring(2).padStart(16, "0"))
5242
5504
  );
5243
5505
  const script = new Uint8Array([
5244
- ...(0, import_utils28.arrayify)(withdrawScript.bytes),
5506
+ ...(0, import_utils27.arrayify)(withdrawScript.bytes),
5245
5507
  ...recipientDataArray,
5246
5508
  ...amountDataArray
5247
5509
  ]);
5248
- const params = { script, gasPrice: minGasPrice, ...txParams };
5510
+ const params = { script, ...txParams };
5249
5511
  const request = new ScriptTransactionRequest(params);
5250
- const forwardingQuantities = [{ amount: (0, import_math18.bn)(amount), assetId: import_configs12.BaseAssetId }];
5251
- const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
5252
- request,
5253
- forwardingQuantities
5254
- );
5255
- request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
5256
- this.validateGas({
5257
- gasUsed,
5258
- gasPrice: request.gasPrice,
5259
- gasLimit: request.gasLimit,
5260
- minGasPrice
5261
- });
5262
- await this.fund(request, requiredQuantities, maxFee);
5512
+ const quantitiesToContract = [{ amount: (0, import_math19.bn)(amount), assetId: import_configs12.BaseAssetId }];
5513
+ const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
5514
+ if (txParams.gasLimit) {
5515
+ this.validateGas({
5516
+ gasUsed: txCost.gasUsed,
5517
+ gasLimit: request.gasLimit
5518
+ });
5519
+ }
5520
+ request.maxFee = txCost.maxFee;
5521
+ request.gasLimit = txCost.gasUsed;
5522
+ await this.fund(request, txCost);
5263
5523
  return this.sendTransaction(request);
5264
5524
  }
5265
5525
  async signMessage(message) {
@@ -5317,18 +5577,7 @@ var Account = class extends import_interfaces.AbstractAccount {
5317
5577
  }
5318
5578
  return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
5319
5579
  }
5320
- validateGas({
5321
- gasUsed,
5322
- gasPrice,
5323
- gasLimit,
5324
- minGasPrice
5325
- }) {
5326
- if (minGasPrice.gt(gasPrice)) {
5327
- throw new import_errors16.FuelError(
5328
- import_errors16.ErrorCode.GAS_PRICE_TOO_LOW,
5329
- `Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
5330
- );
5331
- }
5580
+ validateGas({ gasUsed, gasLimit }) {
5332
5581
  if (gasUsed.gt(gasLimit)) {
5333
5582
  throw new import_errors16.FuelError(
5334
5583
  import_errors16.ErrorCode.GAS_LIMIT_TOO_LOW,
@@ -5340,14 +5589,14 @@ var Account = class extends import_interfaces.AbstractAccount {
5340
5589
 
5341
5590
  // src/wallet/base-wallet-unlocked.ts
5342
5591
  var import_hasher3 = require("@fuel-ts/hasher");
5343
- var import_utils31 = require("@fuel-ts/utils");
5592
+ var import_utils30 = require("@fuel-ts/utils");
5344
5593
 
5345
5594
  // src/signer/signer.ts
5346
5595
  var import_address5 = require("@fuel-ts/address");
5347
5596
  var import_crypto2 = require("@fuel-ts/crypto");
5348
5597
  var import_hasher2 = require("@fuel-ts/hasher");
5349
- var import_math19 = require("@fuel-ts/math");
5350
- var import_utils29 = require("@fuel-ts/utils");
5598
+ var import_math20 = require("@fuel-ts/math");
5599
+ var import_utils28 = require("@fuel-ts/utils");
5351
5600
  var import_secp256k1 = require("@noble/curves/secp256k1");
5352
5601
  var Signer = class {
5353
5602
  address;
@@ -5366,10 +5615,10 @@ var Signer = class {
5366
5615
  privateKey = `0x${privateKey}`;
5367
5616
  }
5368
5617
  }
5369
- const privateKeyBytes = (0, import_math19.toBytes)(privateKey, 32);
5370
- this.privateKey = (0, import_utils29.hexlify)(privateKeyBytes);
5371
- this.publicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
5372
- this.compressedPublicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
5618
+ const privateKeyBytes = (0, import_math20.toBytes)(privateKey, 32);
5619
+ this.privateKey = (0, import_utils28.hexlify)(privateKeyBytes);
5620
+ this.publicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
5621
+ this.compressedPublicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
5373
5622
  this.address = import_address5.Address.fromPublicKey(this.publicKey);
5374
5623
  }
5375
5624
  /**
@@ -5383,11 +5632,11 @@ var Signer = class {
5383
5632
  * @returns hashed signature
5384
5633
  */
5385
5634
  sign(data) {
5386
- const signature = import_secp256k1.secp256k1.sign((0, import_utils29.arrayify)(data), (0, import_utils29.arrayify)(this.privateKey));
5387
- const r = (0, import_math19.toBytes)(`0x${signature.r.toString(16)}`, 32);
5388
- const s = (0, import_math19.toBytes)(`0x${signature.s.toString(16)}`, 32);
5635
+ const signature = import_secp256k1.secp256k1.sign((0, import_utils28.arrayify)(data), (0, import_utils28.arrayify)(this.privateKey));
5636
+ const r = (0, import_math20.toBytes)(`0x${signature.r.toString(16)}`, 32);
5637
+ const s = (0, import_math20.toBytes)(`0x${signature.s.toString(16)}`, 32);
5389
5638
  s[0] |= (signature.recovery || 0) << 7;
5390
- return (0, import_utils29.hexlify)((0, import_utils29.concat)([r, s]));
5639
+ return (0, import_utils28.hexlify)((0, import_utils28.concat)([r, s]));
5391
5640
  }
5392
5641
  /**
5393
5642
  * Add point on the current elliptic curve
@@ -5396,8 +5645,8 @@ var Signer = class {
5396
5645
  * @returns compressed point on the curve
5397
5646
  */
5398
5647
  addPoint(point) {
5399
- const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(this.compressedPublicKey));
5400
- const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(point));
5648
+ const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(this.compressedPublicKey));
5649
+ const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(point));
5401
5650
  const result = p0.add(p1);
5402
5651
  return `0x${result.toHex(true)}`;
5403
5652
  }
@@ -5409,16 +5658,16 @@ var Signer = class {
5409
5658
  * @returns public key from signature from the
5410
5659
  */
5411
5660
  static recoverPublicKey(data, signature) {
5412
- const signedMessageBytes = (0, import_utils29.arrayify)(signature);
5661
+ const signedMessageBytes = (0, import_utils28.arrayify)(signature);
5413
5662
  const r = signedMessageBytes.slice(0, 32);
5414
5663
  const s = signedMessageBytes.slice(32, 64);
5415
5664
  const recoveryParam = (s[0] & 128) >> 7;
5416
5665
  s[0] &= 127;
5417
- const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils29.hexlify)(r)), BigInt((0, import_utils29.hexlify)(s))).addRecoveryBit(
5666
+ const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils28.hexlify)(r)), BigInt((0, import_utils28.hexlify)(s))).addRecoveryBit(
5418
5667
  recoveryParam
5419
5668
  );
5420
- const publicKey = sig.recoverPublicKey((0, import_utils29.arrayify)(data)).toRawBytes(false).slice(1);
5421
- return (0, import_utils29.hexlify)(publicKey);
5669
+ const publicKey = sig.recoverPublicKey((0, import_utils28.arrayify)(data)).toRawBytes(false).slice(1);
5670
+ return (0, import_utils28.hexlify)(publicKey);
5422
5671
  }
5423
5672
  /**
5424
5673
  * Recover the address from a signature performed with [`sign`](#sign).
@@ -5437,7 +5686,7 @@ var Signer = class {
5437
5686
  * @returns random 32-byte hashed
5438
5687
  */
5439
5688
  static generatePrivateKey(entropy) {
5440
- return entropy ? (0, import_hasher2.hash)((0, import_utils29.concat)([(0, import_crypto2.randomBytes)(32), (0, import_utils29.arrayify)(entropy)])) : (0, import_crypto2.randomBytes)(32);
5689
+ return entropy ? (0, import_hasher2.hash)((0, import_utils28.concat)([(0, import_crypto2.randomBytes)(32), (0, import_utils28.arrayify)(entropy)])) : (0, import_crypto2.randomBytes)(32);
5441
5690
  }
5442
5691
  /**
5443
5692
  * Extended publicKey from a compact publicKey
@@ -5446,8 +5695,8 @@ var Signer = class {
5446
5695
  * @returns extended publicKey
5447
5696
  */
5448
5697
  static extendPublicKey(publicKey) {
5449
- const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(publicKey));
5450
- return (0, import_utils29.hexlify)(point.toRawBytes(false).slice(1));
5698
+ const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(publicKey));
5699
+ return (0, import_utils28.hexlify)(point.toRawBytes(false).slice(1));
5451
5700
  }
5452
5701
  };
5453
5702
 
@@ -5455,7 +5704,7 @@ var Signer = class {
5455
5704
  var import_address6 = require("@fuel-ts/address");
5456
5705
  var import_crypto3 = require("@fuel-ts/crypto");
5457
5706
  var import_errors17 = require("@fuel-ts/errors");
5458
- var import_utils30 = require("@fuel-ts/utils");
5707
+ var import_utils29 = require("@fuel-ts/utils");
5459
5708
  var import_uuid = require("uuid");
5460
5709
  var DEFAULT_KDF_PARAMS_LOG_N = 13;
5461
5710
  var DEFAULT_KDF_PARAMS_R = 8;
@@ -5538,7 +5787,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
5538
5787
  );
5539
5788
  }
5540
5789
  const buffer = await (0, import_crypto3.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
5541
- const privateKey = (0, import_utils30.hexlify)(buffer);
5790
+ const privateKey = (0, import_utils29.hexlify)(buffer);
5542
5791
  return privateKey;
5543
5792
  }
5544
5793
 
@@ -5583,7 +5832,7 @@ var BaseWalletUnlocked = class extends Account {
5583
5832
  */
5584
5833
  async signMessage(message) {
5585
5834
  const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
5586
- return (0, import_utils31.hexlify)(signedMessage);
5835
+ return (0, import_utils30.hexlify)(signedMessage);
5587
5836
  }
5588
5837
  /**
5589
5838
  * Signs a transaction with the wallet's private key.
@@ -5596,7 +5845,7 @@ var BaseWalletUnlocked = class extends Account {
5596
5845
  const chainId = this.provider.getChainId();
5597
5846
  const hashedTransaction = transactionRequest.getTransactionId(chainId);
5598
5847
  const signature = await this.signer().sign(hashedTransaction);
5599
- return (0, import_utils31.hexlify)(signature);
5848
+ return (0, import_utils30.hexlify)(signature);
5600
5849
  }
5601
5850
  /**
5602
5851
  * Populates a transaction with the witnesses signature.
@@ -5616,7 +5865,7 @@ var BaseWalletUnlocked = class extends Account {
5616
5865
  * @param transactionRequestLike - The transaction request to send.
5617
5866
  * @returns A promise that resolves to the TransactionResponse object.
5618
5867
  */
5619
- async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
5868
+ async sendTransaction(transactionRequestLike, { estimateTxDependencies = false, awaitExecution } = {}) {
5620
5869
  const transactionRequest = transactionRequestify(transactionRequestLike);
5621
5870
  if (estimateTxDependencies) {
5622
5871
  await this.provider.estimateTxDependencies(transactionRequest);
@@ -5655,17 +5904,18 @@ var BaseWalletUnlocked = class extends Account {
5655
5904
  __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
5656
5905
 
5657
5906
  // src/hdwallet/hdwallet.ts
5658
- var import_crypto5 = require("@fuel-ts/crypto");
5659
5907
  var import_errors20 = require("@fuel-ts/errors");
5660
5908
  var import_hasher6 = require("@fuel-ts/hasher");
5661
- var import_math20 = require("@fuel-ts/math");
5662
- var import_utils35 = require("@fuel-ts/utils");
5909
+ var import_math21 = require("@fuel-ts/math");
5910
+ var import_utils34 = require("@fuel-ts/utils");
5911
+ var import_ethers3 = require("ethers");
5663
5912
 
5664
5913
  // src/mnemonic/mnemonic.ts
5665
5914
  var import_crypto4 = require("@fuel-ts/crypto");
5666
5915
  var import_errors19 = require("@fuel-ts/errors");
5667
5916
  var import_hasher5 = require("@fuel-ts/hasher");
5668
- var import_utils33 = require("@fuel-ts/utils");
5917
+ var import_utils32 = require("@fuel-ts/utils");
5918
+ var import_ethers2 = require("ethers");
5669
5919
 
5670
5920
  // src/wordlists/words/english.ts
5671
5921
  var english = [
@@ -7728,7 +7978,7 @@ var Language = /* @__PURE__ */ ((Language2) => {
7728
7978
  // src/mnemonic/utils.ts
7729
7979
  var import_errors18 = require("@fuel-ts/errors");
7730
7980
  var import_hasher4 = require("@fuel-ts/hasher");
7731
- var import_utils32 = require("@fuel-ts/utils");
7981
+ var import_utils31 = require("@fuel-ts/utils");
7732
7982
  function toUtf8Bytes(stri) {
7733
7983
  const str = stri.normalize("NFKD");
7734
7984
  const result = [];
@@ -7795,14 +8045,14 @@ function entropyToMnemonicIndices(entropy) {
7795
8045
  }
7796
8046
  }
7797
8047
  const checksumBits = entropy.length / 4;
7798
- const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
8048
+ const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
7799
8049
  indices[indices.length - 1] <<= checksumBits;
7800
8050
  indices[indices.length - 1] |= checksum >> 8 - checksumBits;
7801
8051
  return indices;
7802
8052
  }
7803
8053
  function mnemonicWordsToEntropy(words, wordlist) {
7804
8054
  const size = Math.ceil(11 * words.length / 8);
7805
- const entropy = (0, import_utils32.arrayify)(new Uint8Array(size));
8055
+ const entropy = (0, import_utils31.arrayify)(new Uint8Array(size));
7806
8056
  let offset = 0;
7807
8057
  for (let i = 0; i < words.length; i += 1) {
7808
8058
  const index = wordlist.indexOf(words[i].normalize("NFKD"));
@@ -7822,7 +8072,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
7822
8072
  const entropyBits = 32 * words.length / 3;
7823
8073
  const checksumBits = words.length / 3;
7824
8074
  const checksumMask = getUpperMask(checksumBits);
7825
- const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
8075
+ const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
7826
8076
  if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
7827
8077
  throw new import_errors18.FuelError(
7828
8078
  import_errors18.ErrorCode.INVALID_CHECKSUM,
@@ -7897,7 +8147,7 @@ var Mnemonic = class {
7897
8147
  static mnemonicToEntropy(phrase, wordlist = english) {
7898
8148
  const words = getWords(phrase);
7899
8149
  assertMnemonic(words);
7900
- return (0, import_utils33.hexlify)(mnemonicWordsToEntropy(words, wordlist));
8150
+ return (0, import_utils32.hexlify)(mnemonicWordsToEntropy(words, wordlist));
7901
8151
  }
7902
8152
  /**
7903
8153
  * @param entropy - Entropy source to the mnemonic phrase.
@@ -7905,7 +8155,7 @@ var Mnemonic = class {
7905
8155
  * @returns 64-byte array contains privateKey and chainCode as described on BIP39
7906
8156
  */
7907
8157
  static entropyToMnemonic(entropy, wordlist = english) {
7908
- const entropyBytes = (0, import_utils33.arrayify)(entropy);
8158
+ const entropyBytes = (0, import_utils32.arrayify)(entropy);
7909
8159
  assertWordList(wordlist);
7910
8160
  assertEntropy(entropyBytes);
7911
8161
  return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
@@ -7919,7 +8169,7 @@ var Mnemonic = class {
7919
8169
  assertMnemonic(getWords(phrase));
7920
8170
  const phraseBytes = toUtf8Bytes(getPhrase(phrase));
7921
8171
  const salt = toUtf8Bytes(`mnemonic${passphrase}`);
7922
- return (0, import_crypto4.pbkdf2)(phraseBytes, salt, 2048, 64, "sha512");
8172
+ return (0, import_ethers2.pbkdf2)(phraseBytes, salt, 2048, 64, "sha512");
7923
8173
  }
7924
8174
  /**
7925
8175
  * @param phrase - Mnemonic phrase composed by words from the provided wordlist
@@ -7974,14 +8224,14 @@ var Mnemonic = class {
7974
8224
  * @returns 64-byte array contains privateKey and chainCode as described on BIP39
7975
8225
  */
7976
8226
  static masterKeysFromSeed(seed) {
7977
- const seedArray = (0, import_utils33.arrayify)(seed);
8227
+ const seedArray = (0, import_utils32.arrayify)(seed);
7978
8228
  if (seedArray.length < 16 || seedArray.length > 64) {
7979
8229
  throw new import_errors19.FuelError(
7980
8230
  import_errors19.ErrorCode.INVALID_SEED,
7981
8231
  `Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
7982
8232
  );
7983
8233
  }
7984
- return (0, import_utils33.arrayify)((0, import_crypto4.computeHmac)("sha512", MasterSecret, seedArray));
8234
+ return (0, import_utils32.arrayify)((0, import_ethers2.computeHmac)("sha512", MasterSecret, seedArray));
7985
8235
  }
7986
8236
  /**
7987
8237
  * Get the extendKey as defined on BIP-32 from the provided seed
@@ -7992,22 +8242,22 @@ var Mnemonic = class {
7992
8242
  */
7993
8243
  static seedToExtendedKey(seed, testnet = false) {
7994
8244
  const masterKey = Mnemonic.masterKeysFromSeed(seed);
7995
- const prefix = (0, import_utils33.arrayify)(testnet ? TestnetPRV : MainnetPRV);
8245
+ const prefix = (0, import_utils32.arrayify)(testnet ? TestnetPRV : MainnetPRV);
7996
8246
  const depth = "0x00";
7997
8247
  const fingerprint = "0x00000000";
7998
8248
  const index = "0x00000000";
7999
8249
  const chainCode = masterKey.slice(32);
8000
8250
  const privateKey = masterKey.slice(0, 32);
8001
- const extendedKey = (0, import_utils33.concat)([
8251
+ const extendedKey = (0, import_utils32.concat)([
8002
8252
  prefix,
8003
8253
  depth,
8004
8254
  fingerprint,
8005
8255
  index,
8006
8256
  chainCode,
8007
- (0, import_utils33.concat)(["0x00", privateKey])
8257
+ (0, import_utils32.concat)(["0x00", privateKey])
8008
8258
  ]);
8009
- const checksum = (0, import_utils33.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
8010
- return (0, import_utils33.encodeBase58)((0, import_utils33.concat)([extendedKey, checksum]));
8259
+ const checksum = (0, import_ethers2.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
8260
+ return (0, import_ethers2.encodeBase58)((0, import_utils32.concat)([extendedKey, checksum]));
8011
8261
  }
8012
8262
  /**
8013
8263
  * Create a new mnemonic using a randomly generated number as entropy.
@@ -8022,7 +8272,7 @@ var Mnemonic = class {
8022
8272
  * @returns A randomly generated mnemonic
8023
8273
  */
8024
8274
  static generate(size = 32, extraEntropy = "") {
8025
- const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils33.concat)([(0, import_crypto4.randomBytes)(size), (0, import_utils33.arrayify)(extraEntropy)])) : (0, import_crypto4.randomBytes)(size);
8275
+ const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils32.concat)([(0, import_crypto4.randomBytes)(size), (0, import_utils32.arrayify)(extraEntropy)])) : (0, import_crypto4.randomBytes)(size);
8026
8276
  return Mnemonic.entropyToMnemonic(entropy);
8027
8277
  }
8028
8278
  };
@@ -8030,12 +8280,12 @@ var mnemonic_default = Mnemonic;
8030
8280
 
8031
8281
  // src/hdwallet/hdwallet.ts
8032
8282
  var HARDENED_INDEX = 2147483648;
8033
- var MainnetPRV2 = (0, import_utils35.hexlify)("0x0488ade4");
8034
- var MainnetPUB = (0, import_utils35.hexlify)("0x0488b21e");
8035
- var TestnetPRV2 = (0, import_utils35.hexlify)("0x04358394");
8036
- var TestnetPUB = (0, import_utils35.hexlify)("0x043587cf");
8283
+ var MainnetPRV2 = (0, import_utils34.hexlify)("0x0488ade4");
8284
+ var MainnetPUB = (0, import_utils34.hexlify)("0x0488b21e");
8285
+ var TestnetPRV2 = (0, import_utils34.hexlify)("0x04358394");
8286
+ var TestnetPUB = (0, import_utils34.hexlify)("0x043587cf");
8037
8287
  function base58check(data) {
8038
- return (0, import_utils35.encodeBase58)((0, import_utils35.concat)([data, (0, import_utils35.dataSlice)((0, import_hasher6.sha256)((0, import_hasher6.sha256)(data)), 0, 4)]));
8288
+ 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)]));
8039
8289
  }
8040
8290
  function getExtendedKeyPrefix(isPublic = false, testnet = false) {
8041
8291
  if (isPublic) {
@@ -8044,11 +8294,11 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
8044
8294
  return testnet ? TestnetPRV2 : MainnetPRV2;
8045
8295
  }
8046
8296
  function isPublicExtendedKey(extendedKey) {
8047
- return [MainnetPUB, TestnetPUB].includes((0, import_utils35.hexlify)(extendedKey.slice(0, 4)));
8297
+ return [MainnetPUB, TestnetPUB].includes((0, import_utils34.hexlify)(extendedKey.slice(0, 4)));
8048
8298
  }
8049
8299
  function isValidExtendedKey(extendedKey) {
8050
8300
  return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
8051
- (0, import_utils35.hexlify)(extendedKey.slice(0, 4))
8301
+ (0, import_utils34.hexlify)(extendedKey.slice(0, 4))
8052
8302
  );
8053
8303
  }
8054
8304
  function parsePath(path, depth = 0) {
@@ -8066,8 +8316,8 @@ function parsePath(path, depth = 0) {
8066
8316
  var HDWallet = class {
8067
8317
  depth = 0;
8068
8318
  index = 0;
8069
- fingerprint = (0, import_utils35.hexlify)("0x00000000");
8070
- parentFingerprint = (0, import_utils35.hexlify)("0x00000000");
8319
+ fingerprint = (0, import_utils34.hexlify)("0x00000000");
8320
+ parentFingerprint = (0, import_utils34.hexlify)("0x00000000");
8071
8321
  privateKey;
8072
8322
  publicKey;
8073
8323
  chainCode;
@@ -8079,8 +8329,8 @@ var HDWallet = class {
8079
8329
  constructor(config) {
8080
8330
  if (config.privateKey) {
8081
8331
  const signer = new Signer(config.privateKey);
8082
- this.publicKey = (0, import_utils35.hexlify)(signer.compressedPublicKey);
8083
- this.privateKey = (0, import_utils35.hexlify)(config.privateKey);
8332
+ this.publicKey = (0, import_utils34.hexlify)(signer.compressedPublicKey);
8333
+ this.privateKey = (0, import_utils34.hexlify)(config.privateKey);
8084
8334
  } else {
8085
8335
  if (!config.publicKey) {
8086
8336
  throw new import_errors20.FuelError(
@@ -8088,10 +8338,10 @@ var HDWallet = class {
8088
8338
  "Both public and private Key cannot be missing. At least one should be provided."
8089
8339
  );
8090
8340
  }
8091
- this.publicKey = (0, import_utils35.hexlify)(config.publicKey);
8341
+ this.publicKey = (0, import_utils34.hexlify)(config.publicKey);
8092
8342
  }
8093
8343
  this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
8094
- this.fingerprint = (0, import_utils35.dataSlice)((0, import_crypto5.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
8344
+ this.fingerprint = (0, import_ethers3.dataSlice)((0, import_ethers3.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
8095
8345
  this.depth = config.depth || this.depth;
8096
8346
  this.index = config.index || this.index;
8097
8347
  this.chainCode = config.chainCode;
@@ -8107,9 +8357,9 @@ var HDWallet = class {
8107
8357
  * @returns A new instance of HDWallet on the derived index
8108
8358
  */
8109
8359
  deriveIndex(index) {
8110
- const privateKey = this.privateKey && (0, import_utils35.arrayify)(this.privateKey);
8111
- const publicKey = (0, import_utils35.arrayify)(this.publicKey);
8112
- const chainCode = (0, import_utils35.arrayify)(this.chainCode);
8360
+ const privateKey = this.privateKey && (0, import_utils34.arrayify)(this.privateKey);
8361
+ const publicKey = (0, import_utils34.arrayify)(this.publicKey);
8362
+ const chainCode = (0, import_utils34.arrayify)(this.chainCode);
8113
8363
  const data = new Uint8Array(37);
8114
8364
  if (index & HARDENED_INDEX) {
8115
8365
  if (!privateKey) {
@@ -8120,15 +8370,15 @@ var HDWallet = class {
8120
8370
  }
8121
8371
  data.set(privateKey, 1);
8122
8372
  } else {
8123
- data.set((0, import_utils35.arrayify)(this.publicKey));
8373
+ data.set((0, import_utils34.arrayify)(this.publicKey));
8124
8374
  }
8125
- data.set((0, import_math20.toBytes)(index, 4), 33);
8126
- const bytes = (0, import_utils35.arrayify)((0, import_crypto5.computeHmac)("sha512", chainCode, data));
8375
+ data.set((0, import_math21.toBytes)(index, 4), 33);
8376
+ const bytes = (0, import_utils34.arrayify)((0, import_ethers3.computeHmac)("sha512", chainCode, data));
8127
8377
  const IL = bytes.slice(0, 32);
8128
8378
  const IR = bytes.slice(32);
8129
8379
  if (privateKey) {
8130
8380
  const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
8131
- const ki = (0, import_math20.bn)(IL).add(privateKey).mod(N).toBytes(32);
8381
+ const ki = (0, import_math21.bn)(IL).add(privateKey).mod(N).toBytes(32);
8132
8382
  return new HDWallet({
8133
8383
  privateKey: ki,
8134
8384
  chainCode: IR,
@@ -8137,7 +8387,7 @@ var HDWallet = class {
8137
8387
  parentFingerprint: this.fingerprint
8138
8388
  });
8139
8389
  }
8140
- const signer = new Signer((0, import_utils35.hexlify)(IL));
8390
+ const signer = new Signer((0, import_utils34.hexlify)(IL));
8141
8391
  const Ki = signer.addPoint(publicKey);
8142
8392
  return new HDWallet({
8143
8393
  publicKey: Ki,
@@ -8172,12 +8422,12 @@ var HDWallet = class {
8172
8422
  );
8173
8423
  }
8174
8424
  const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
8175
- const depth = (0, import_utils35.hexlify)(Uint8Array.from([this.depth]));
8425
+ const depth = (0, import_utils34.hexlify)(Uint8Array.from([this.depth]));
8176
8426
  const parentFingerprint = this.parentFingerprint;
8177
- const index = (0, import_math20.toHex)(this.index, 4);
8427
+ const index = (0, import_math21.toHex)(this.index, 4);
8178
8428
  const chainCode = this.chainCode;
8179
- const key = this.privateKey != null && !isPublic ? (0, import_utils35.concat)(["0x00", this.privateKey]) : this.publicKey;
8180
- const extendedKey = (0, import_utils35.arrayify)((0, import_utils35.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
8429
+ const key = this.privateKey != null && !isPublic ? (0, import_utils34.concat)(["0x00", this.privateKey]) : this.publicKey;
8430
+ const extendedKey = (0, import_utils34.arrayify)((0, import_utils34.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
8181
8431
  return base58check(extendedKey);
8182
8432
  }
8183
8433
  /**
@@ -8189,14 +8439,13 @@ var HDWallet = class {
8189
8439
  static fromSeed(seed) {
8190
8440
  const masterKey = mnemonic_default.masterKeysFromSeed(seed);
8191
8441
  return new HDWallet({
8192
- chainCode: (0, import_utils35.arrayify)(masterKey.slice(32)),
8193
- privateKey: (0, import_utils35.arrayify)(masterKey.slice(0, 32))
8442
+ chainCode: (0, import_utils34.arrayify)(masterKey.slice(32)),
8443
+ privateKey: (0, import_utils34.arrayify)(masterKey.slice(0, 32))
8194
8444
  });
8195
8445
  }
8196
8446
  static fromExtendedKey(extendedKey) {
8197
- let decoded = (0, import_math20.toHex)((0, import_utils35.decodeBase58)(extendedKey));
8198
- decoded = `${decoded.substring(0, 2)}0${decoded.substring(2)}`;
8199
- const bytes = (0, import_utils35.arrayify)(decoded);
8447
+ const decoded = (0, import_ethers3.toBeHex)((0, import_ethers3.decodeBase58)(extendedKey));
8448
+ const bytes = (0, import_utils34.arrayify)(decoded);
8200
8449
  const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
8201
8450
  if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
8202
8451
  throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
@@ -8205,9 +8454,9 @@ var HDWallet = class {
8205
8454
  throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
8206
8455
  }
8207
8456
  const depth = bytes[4];
8208
- const parentFingerprint = (0, import_utils35.hexlify)(bytes.slice(5, 9));
8209
- const index = parseInt((0, import_utils35.hexlify)(bytes.slice(9, 13)).substring(2), 16);
8210
- const chainCode = (0, import_utils35.hexlify)(bytes.slice(13, 45));
8457
+ const parentFingerprint = (0, import_utils34.hexlify)(bytes.slice(5, 9));
8458
+ const index = parseInt((0, import_utils34.hexlify)(bytes.slice(9, 13)).substring(2), 16);
8459
+ const chainCode = (0, import_utils34.hexlify)(bytes.slice(13, 45));
8211
8460
  const key = bytes.slice(45, 78);
8212
8461
  if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
8213
8462
  throw new import_errors20.FuelError(
@@ -8395,7 +8644,7 @@ __publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
8395
8644
 
8396
8645
  // src/wallet-manager/wallet-manager.ts
8397
8646
  var import_address9 = require("@fuel-ts/address");
8398
- var import_crypto6 = require("@fuel-ts/crypto");
8647
+ var import_crypto5 = require("@fuel-ts/crypto");
8399
8648
  var import_errors23 = require("@fuel-ts/errors");
8400
8649
  var import_events = require("events");
8401
8650
 
@@ -8723,7 +8972,7 @@ var _WalletManager = class extends import_events.EventEmitter {
8723
8972
  await assert(!__privateGet(this, _isLocked), ERROR_MESSAGES.wallet_not_unlocked);
8724
8973
  const data = await this.storage.getItem(this.STORAGE_KEY);
8725
8974
  if (data) {
8726
- const state = await (0, import_crypto6.decrypt)(__privateGet(this, _passphrase), JSON.parse(data));
8975
+ const state = await (0, import_crypto5.decrypt)(__privateGet(this, _passphrase), JSON.parse(data));
8727
8976
  __privateSet(this, _vaults, __privateMethod(this, _deserializeVaults, deserializeVaults_fn).call(this, state.vaults));
8728
8977
  }
8729
8978
  }
@@ -8732,7 +8981,7 @@ var _WalletManager = class extends import_events.EventEmitter {
8732
8981
  */
8733
8982
  async saveState() {
8734
8983
  await assert(!__privateGet(this, _isLocked), ERROR_MESSAGES.wallet_not_unlocked);
8735
- const encryptedData = await (0, import_crypto6.encrypt)(__privateGet(this, _passphrase), {
8984
+ const encryptedData = await (0, import_crypto5.encrypt)(__privateGet(this, _passphrase), {
8736
8985
  vaults: __privateMethod(this, _serializeVaults, serializeVaults_fn).call(this, __privateGet(this, _vaults))
8737
8986
  });
8738
8987
  await this.storage.setItem(this.STORAGE_KEY, JSON.stringify(encryptedData));
@@ -8812,19 +9061,19 @@ var import_abi_coder7 = require("@fuel-ts/abi-coder");
8812
9061
  var import_address10 = require("@fuel-ts/address");
8813
9062
  var import_configs13 = require("@fuel-ts/address/configs");
8814
9063
  var import_errors25 = require("@fuel-ts/errors");
8815
- var import_transactions20 = require("@fuel-ts/transactions");
8816
- var import_utils37 = require("@fuel-ts/utils");
9064
+ var import_transactions21 = require("@fuel-ts/transactions");
9065
+ var import_utils36 = require("@fuel-ts/utils");
8817
9066
 
8818
9067
  // src/predicate/utils/getPredicateRoot.ts
8819
9068
  var import_hasher7 = require("@fuel-ts/hasher");
8820
9069
  var import_merkle = require("@fuel-ts/merkle");
8821
- var import_utils36 = require("@fuel-ts/utils");
9070
+ var import_utils35 = require("@fuel-ts/utils");
8822
9071
  var getPredicateRoot = (bytecode) => {
8823
9072
  const chunkSize = 16 * 1024;
8824
- const bytes = (0, import_utils36.arrayify)(bytecode);
8825
- const chunks = (0, import_utils36.chunkAndPadBytes)(bytes, chunkSize);
8826
- const codeRoot = (0, import_merkle.calcRoot)(chunks.map((c) => (0, import_utils36.hexlify)(c)));
8827
- const predicateRoot = (0, import_hasher7.hash)((0, import_utils36.concat)(["0x4655454C", codeRoot]));
9073
+ const bytes = (0, import_utils35.arrayify)(bytecode);
9074
+ const chunks = (0, import_utils35.chunkAndPadBytes)(bytes, chunkSize);
9075
+ const codeRoot = (0, import_merkle.calcRoot)(chunks.map((c) => (0, import_utils35.hexlify)(c)));
9076
+ const predicateRoot = (0, import_hasher7.hash)((0, import_utils35.concat)(["0x4655454C", codeRoot]));
8828
9077
  return predicateRoot;
8829
9078
  };
8830
9079
 
@@ -8872,9 +9121,9 @@ var Predicate = class extends Account {
8872
9121
  const request = transactionRequestify(transactionRequestLike);
8873
9122
  const { policies } = BaseTransactionRequest.getPolicyMeta(request);
8874
9123
  request.inputs?.forEach((input) => {
8875
- if (input.type === import_transactions20.InputType.Coin && (0, import_utils37.hexlify)(input.owner) === this.address.toB256()) {
8876
- input.predicate = this.bytes;
8877
- input.predicateData = this.getPredicateData(policies.length);
9124
+ if (input.type === import_transactions21.InputType.Coin && (0, import_utils36.hexlify)(input.owner) === this.address.toB256()) {
9125
+ input.predicate = (0, import_utils36.hexlify)(this.bytes);
9126
+ input.predicateData = (0, import_utils36.hexlify)(this.getPredicateData(policies.length));
8878
9127
  }
8879
9128
  });
8880
9129
  return request;
@@ -8889,8 +9138,7 @@ var Predicate = class extends Account {
8889
9138
  * @returns A promise that resolves to the prepared transaction request.
8890
9139
  */
8891
9140
  async createTransfer(destination, amount, assetId = import_configs13.BaseAssetId, txParams = {}) {
8892
- const request = await super.createTransfer(destination, amount, assetId, txParams);
8893
- return this.populateTransactionPredicateData(request);
9141
+ return super.createTransfer(destination, amount, assetId, txParams);
8894
9142
  }
8895
9143
  /**
8896
9144
  * Sends a transaction with the populated predicate data.
@@ -8898,9 +9146,9 @@ var Predicate = class extends Account {
8898
9146
  * @param transactionRequestLike - The transaction request-like object.
8899
9147
  * @returns A promise that resolves to the transaction response.
8900
9148
  */
8901
- sendTransaction(transactionRequestLike, options) {
8902
- const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
8903
- return super.sendTransaction(transactionRequest, options);
9149
+ sendTransaction(transactionRequestLike) {
9150
+ const transactionRequest = transactionRequestify(transactionRequestLike);
9151
+ return super.sendTransaction(transactionRequest, { estimateTxDependencies: false });
8904
9152
  }
8905
9153
  /**
8906
9154
  * Simulates a transaction with the populated predicate data.
@@ -8909,15 +9157,15 @@ var Predicate = class extends Account {
8909
9157
  * @returns A promise that resolves to the call result.
8910
9158
  */
8911
9159
  simulateTransaction(transactionRequestLike) {
8912
- const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
8913
- return super.simulateTransaction(transactionRequest);
9160
+ const transactionRequest = transactionRequestify(transactionRequestLike);
9161
+ return super.simulateTransaction(transactionRequest, { estimateTxDependencies: false });
8914
9162
  }
8915
9163
  getPredicateData(policiesLength) {
8916
9164
  if (!this.predicateData.length) {
8917
9165
  return new Uint8Array();
8918
9166
  }
8919
9167
  const mainFn = this.interface?.functions.main;
8920
- const paddedCode = new import_transactions20.ByteArrayCoder(this.bytes.length).encode(this.bytes);
9168
+ const paddedCode = new import_transactions21.ByteArrayCoder(this.bytes.length).encode(this.bytes);
8921
9169
  const VM_TX_MEMORY = (0, import_abi_coder7.calculateVmTxMemory)({
8922
9170
  maxInputs: this.provider.getChain().consensusParameters.maxInputs.toNumber()
8923
9171
  });
@@ -8933,7 +9181,7 @@ var Predicate = class extends Account {
8933
9181
  * @returns An object containing the new predicate bytes and interface.
8934
9182
  */
8935
9183
  static processPredicateData(bytes, jsonAbi, configurableConstants) {
8936
- let predicateBytes = (0, import_utils37.arrayify)(bytes);
9184
+ let predicateBytes = (0, import_utils36.arrayify)(bytes);
8937
9185
  let abiInterface;
8938
9186
  if (jsonAbi) {
8939
9187
  abiInterface = new import_abi_coder7.Interface(jsonAbi);
@@ -8956,6 +9204,25 @@ var Predicate = class extends Account {
8956
9204
  predicateInterface: abiInterface
8957
9205
  };
8958
9206
  }
9207
+ /**
9208
+ * Retrieves resources satisfying the spend query for the account.
9209
+ *
9210
+ * @param quantities - IDs of coins to exclude.
9211
+ * @param excludedIds - IDs of resources to be excluded from the query.
9212
+ * @returns A promise that resolves to an array of Resources.
9213
+ */
9214
+ async getResourcesToSpend(quantities, excludedIds) {
9215
+ const resources = await this.provider.getResourcesToSpend(
9216
+ this.address,
9217
+ quantities,
9218
+ excludedIds
9219
+ );
9220
+ return resources.map((resource) => ({
9221
+ ...resource,
9222
+ predicate: (0, import_utils36.hexlify)(this.bytes),
9223
+ paddPredicateData: (policiesLength) => (0, import_utils36.hexlify)(this.getPredicateData(policiesLength))
9224
+ }));
9225
+ }
8959
9226
  /**
8960
9227
  * Sets the configurable constants for the predicate.
8961
9228
  *
@@ -9705,7 +9972,7 @@ __publicField(Fuel, "defaultConfig", {});
9705
9972
  WalletLocked,
9706
9973
  WalletManager,
9707
9974
  WalletUnlocked,
9708
- addAmountToAsset,
9975
+ addAmountToCoinQuantities,
9709
9976
  addOperation,
9710
9977
  assemblePanicError,
9711
9978
  assembleReceiptByType,
@@ -9714,9 +9981,10 @@ __publicField(Fuel, "defaultConfig", {});
9714
9981
  assets,
9715
9982
  buildBlockExplorerUrl,
9716
9983
  cacheFor,
9984
+ cacheTxInputsFromOwner,
9985
+ calculateGasFee,
9717
9986
  calculateMetadataGasForTxCreate,
9718
9987
  calculateMetadataGasForTxScript,
9719
- calculatePriceWithFactor,
9720
9988
  calculateTransactionFee,
9721
9989
  coinQuantityfy,
9722
9990
  deferPromise,