@fuel-ts/account 0.0.0-rc-2037-20240418195040 → 0.0.0-rc-2021-20240418195117

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 (66) hide show
  1. package/README.md +1 -1
  2. package/dist/account.d.ts +5 -4
  3. package/dist/account.d.ts.map +1 -1
  4. package/dist/configs.d.ts.map +1 -1
  5. package/dist/configs.global.js +1 -1
  6. package/dist/configs.global.js.map +1 -1
  7. package/dist/configs.js +1 -1
  8. package/dist/configs.js.map +1 -1
  9. package/dist/configs.mjs +1 -1
  10. package/dist/configs.mjs.map +1 -1
  11. package/dist/index.global.js +797 -596
  12. package/dist/index.global.js.map +1 -1
  13. package/dist/index.js +825 -633
  14. package/dist/index.js.map +1 -1
  15. package/dist/index.mjs +648 -451
  16. package/dist/index.mjs.map +1 -1
  17. package/dist/predicate/predicate.d.ts +11 -18
  18. package/dist/predicate/predicate.d.ts.map +1 -1
  19. package/dist/providers/__generated__/operations.d.ts +906 -324
  20. package/dist/providers/__generated__/operations.d.ts.map +1 -1
  21. package/dist/providers/coin-quantity.d.ts +1 -1
  22. package/dist/providers/coin-quantity.d.ts.map +1 -1
  23. package/dist/providers/coin.d.ts +2 -1
  24. package/dist/providers/coin.d.ts.map +1 -1
  25. package/dist/providers/message.d.ts +6 -1
  26. package/dist/providers/message.d.ts.map +1 -1
  27. package/dist/providers/provider.d.ts +37 -27
  28. package/dist/providers/provider.d.ts.map +1 -1
  29. package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
  30. package/dist/providers/transaction-request/index.d.ts +0 -1
  31. package/dist/providers/transaction-request/index.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 +6 -7
  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/index.d.ts +0 -1
  48. package/dist/test-utils/index.d.ts.map +1 -1
  49. package/dist/test-utils/launchNode.d.ts.map +1 -1
  50. package/dist/test-utils/seedTestWallet.d.ts +1 -1
  51. package/dist/test-utils/seedTestWallet.d.ts.map +1 -1
  52. package/dist/test-utils.global.js +1547 -1085
  53. package/dist/test-utils.global.js.map +1 -1
  54. package/dist/test-utils.js +804 -608
  55. package/dist/test-utils.js.map +1 -1
  56. package/dist/test-utils.mjs +641 -442
  57. package/dist/test-utils.mjs.map +1 -1
  58. package/dist/wallet/base-wallet-unlocked.d.ts +2 -2
  59. package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
  60. package/package.json +16 -16
  61. package/dist/providers/transaction-request/helpers.d.ts +0 -10
  62. package/dist/providers/transaction-request/helpers.d.ts.map +0 -1
  63. package/dist/test-utils/resources.d.ts +0 -4
  64. package/dist/test-utils/resources.d.ts.map +0 -1
  65. package/dist/test-utils/transactionRequest.d.ts +0 -5
  66. package/dist/test-utils/transactionRequest.d.ts.map +0 -1
package/dist/index.js CHANGED
@@ -88,14 +88,14 @@ __export(src_exports, {
88
88
  StorageAbstract: () => StorageAbstract,
89
89
  TransactionResponse: () => TransactionResponse,
90
90
  TransactionStatus: () => TransactionStatus,
91
- TransactionType: () => import_transactions7.TransactionType,
91
+ TransactionType: () => import_transactions6.TransactionType,
92
92
  TransactionTypeName: () => TransactionTypeName,
93
93
  Vault: () => Vault,
94
94
  Wallet: () => Wallet,
95
95
  WalletLocked: () => WalletLocked,
96
96
  WalletManager: () => WalletManager,
97
97
  WalletUnlocked: () => WalletUnlocked,
98
- addAmountToAsset: () => addAmountToAsset,
98
+ addAmountToCoinQuantities: () => addAmountToCoinQuantities,
99
99
  addOperation: () => addOperation,
100
100
  assemblePanicError: () => assemblePanicError,
101
101
  assembleReceiptByType: () => assembleReceiptByType,
@@ -104,10 +104,10 @@ __export(src_exports, {
104
104
  assets: () => assets,
105
105
  buildBlockExplorerUrl: () => buildBlockExplorerUrl,
106
106
  cacheFor: () => cacheFor,
107
- cacheResources: () => cacheResources,
107
+ cacheTxInputsFromOwner: () => cacheTxInputsFromOwner,
108
+ calculateGasFee: () => calculateGasFee,
108
109
  calculateMetadataGasForTxCreate: () => calculateMetadataGasForTxCreate,
109
110
  calculateMetadataGasForTxScript: () => calculateMetadataGasForTxScript,
110
- calculatePriceWithFactor: () => calculatePriceWithFactor,
111
111
  calculateTransactionFee: () => calculateTransactionFee,
112
112
  coinQuantityfy: () => coinQuantityfy,
113
113
  deferPromise: () => deferPromise,
@@ -151,7 +151,6 @@ __export(src_exports, {
151
151
  getReceiptsMessageOut: () => getReceiptsMessageOut,
152
152
  getReceiptsTransferOut: () => getReceiptsTransferOut,
153
153
  getReceiptsWithMissingData: () => getReceiptsWithMissingData,
154
- getRequestInputResourceOwner: () => getRequestInputResourceOwner,
155
154
  getTransactionStatusName: () => getTransactionStatusName,
156
155
  getTransactionSummary: () => getTransactionSummary,
157
156
  getTransactionSummaryFromRequest: () => getTransactionSummaryFromRequest,
@@ -165,10 +164,6 @@ __export(src_exports, {
165
164
  isMessage: () => isMessage,
166
165
  isRawCoin: () => isRawCoin,
167
166
  isRawMessage: () => isRawMessage,
168
- isRequestInputCoin: () => isRequestInputCoin,
169
- isRequestInputMessage: () => isRequestInputMessage,
170
- isRequestInputResource: () => isRequestInputResource,
171
- isRequestInputResourceFromOwner: () => isRequestInputResourceFromOwner,
172
167
  isType: () => isType,
173
168
  isTypeCreate: () => isTypeCreate,
174
169
  isTypeMint: () => isTypeMint,
@@ -193,8 +188,9 @@ var import_address4 = require("@fuel-ts/address");
193
188
  var import_configs12 = require("@fuel-ts/address/configs");
194
189
  var import_errors16 = require("@fuel-ts/errors");
195
190
  var import_interfaces = require("@fuel-ts/interfaces");
196
- var import_math18 = require("@fuel-ts/math");
197
- 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");
198
194
 
199
195
  // src/providers/coin-quantity.ts
200
196
  var import_configs = require("@fuel-ts/address/configs");
@@ -203,24 +199,24 @@ var import_utils = require("@fuel-ts/utils");
203
199
  var coinQuantityfy = (coinQuantityLike) => {
204
200
  let assetId;
205
201
  let amount;
206
- let max2;
202
+ let max;
207
203
  if (Array.isArray(coinQuantityLike)) {
208
204
  amount = coinQuantityLike[0];
209
205
  assetId = coinQuantityLike[1] ?? import_configs.BaseAssetId;
210
- max2 = coinQuantityLike[2] ?? void 0;
206
+ max = coinQuantityLike[2] ?? void 0;
211
207
  } else {
212
208
  amount = coinQuantityLike.amount;
213
209
  assetId = coinQuantityLike.assetId ?? import_configs.BaseAssetId;
214
- max2 = coinQuantityLike.max ?? void 0;
210
+ max = coinQuantityLike.max ?? void 0;
215
211
  }
216
212
  const bnAmount = (0, import_math.bn)(amount);
217
213
  return {
218
214
  assetId: (0, import_utils.hexlify)(assetId),
219
215
  amount: bnAmount.lt(1) ? (0, import_math.bn)(1) : bnAmount,
220
- max: max2 ? (0, import_math.bn)(max2) : void 0
216
+ max: max ? (0, import_math.bn)(max) : void 0
221
217
  };
222
218
  };
223
- var addAmountToAsset = (params) => {
219
+ var addAmountToCoinQuantities = (params) => {
224
220
  const { amount, assetId } = params;
225
221
  const coinQuantities = [...params.coinQuantities];
226
222
  const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
@@ -235,11 +231,11 @@ var addAmountToAsset = (params) => {
235
231
  // src/providers/provider.ts
236
232
  var import_address3 = require("@fuel-ts/address");
237
233
  var import_errors14 = require("@fuel-ts/errors");
238
- var import_math15 = require("@fuel-ts/math");
234
+ var import_math16 = require("@fuel-ts/math");
239
235
  var import_transactions19 = require("@fuel-ts/transactions");
240
- var import_utils23 = require("@fuel-ts/utils");
236
+ var import_utils22 = require("@fuel-ts/utils");
241
237
  var import_versions = require("@fuel-ts/versions");
242
- var import_utils24 = require("@noble/curves/abstract/utils");
238
+ var import_utils23 = require("@noble/curves/abstract/utils");
243
239
  var import_ethers = require("ethers");
244
240
  var import_graphql_request = require("graphql-request");
245
241
  var import_ramda3 = require("ramda");
@@ -248,14 +244,10 @@ var import_ramda3 = require("ramda");
248
244
  var import_graphql_tag = __toESM(require("graphql-tag"));
249
245
  var ReceiptFragmentFragmentDoc = import_graphql_tag.default`
250
246
  fragment receiptFragment on Receipt {
251
- contract {
252
- id
253
- }
247
+ id
254
248
  pc
255
249
  is
256
- to {
257
- id
258
- }
250
+ to
259
251
  toAddress
260
252
  amount
261
253
  assetId
@@ -293,10 +285,16 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
293
285
  id
294
286
  }
295
287
  time
288
+ receipts {
289
+ ...receiptFragment
290
+ }
296
291
  programState {
297
292
  returnType
298
293
  data
299
294
  }
295
+ receipts {
296
+ ...receiptFragment
297
+ }
300
298
  }
301
299
  ... on FailureStatus {
302
300
  block {
@@ -304,26 +302,24 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
304
302
  }
305
303
  time
306
304
  reason
305
+ receipts {
306
+ ...receiptFragment
307
+ }
307
308
  }
308
309
  ... on SqueezedOutStatus {
309
310
  reason
310
311
  }
311
312
  }
312
- `;
313
+ ${ReceiptFragmentFragmentDoc}`;
313
314
  var TransactionFragmentFragmentDoc = import_graphql_tag.default`
314
315
  fragment transactionFragment on Transaction {
315
316
  id
316
317
  rawPayload
317
- gasPrice
318
- receipts {
319
- ...receiptFragment
320
- }
321
318
  status {
322
319
  ...transactionStatusFragment
323
320
  }
324
321
  }
325
- ${ReceiptFragmentFragmentDoc}
326
- ${TransactionStatusFragmentFragmentDoc}`;
322
+ ${TransactionStatusFragmentFragmentDoc}`;
327
323
  var InputEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.default`
328
324
  fragment inputEstimatePredicatesFragment on Input {
329
325
  ... on InputCoin {
@@ -341,6 +337,46 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.defaul
341
337
  }
342
338
  }
343
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}`;
344
380
  var CoinFragmentFragmentDoc = import_graphql_tag.default`
345
381
  fragment coinFragment on Coin {
346
382
  __typename
@@ -348,7 +384,6 @@ var CoinFragmentFragmentDoc = import_graphql_tag.default`
348
384
  owner
349
385
  amount
350
386
  assetId
351
- maturity
352
387
  blockCreated
353
388
  txCreatedIdx
354
389
  }
@@ -387,26 +422,32 @@ var MessageProofFragmentFragmentDoc = import_graphql_tag.default`
387
422
  messageBlockHeader {
388
423
  id
389
424
  daHeight
425
+ consensusParametersVersion
426
+ stateTransitionBytecodeVersion
390
427
  transactionsCount
428
+ messageReceiptCount
391
429
  transactionsRoot
430
+ messageOutboxRoot
431
+ eventInboxRoot
392
432
  height
393
433
  prevRoot
394
434
  time
395
435
  applicationHash
396
- messageReceiptRoot
397
- messageReceiptCount
398
436
  }
399
437
  commitBlockHeader {
400
438
  id
401
439
  daHeight
440
+ consensusParametersVersion
441
+ stateTransitionBytecodeVersion
402
442
  transactionsCount
443
+ messageReceiptCount
403
444
  transactionsRoot
445
+ messageOutboxRoot
446
+ eventInboxRoot
404
447
  height
405
448
  prevRoot
406
449
  time
407
450
  applicationHash
408
- messageReceiptRoot
409
- messageReceiptCount
410
451
  }
411
452
  sender
412
453
  recipient
@@ -425,8 +466,8 @@ var BalanceFragmentFragmentDoc = import_graphql_tag.default`
425
466
  var BlockFragmentFragmentDoc = import_graphql_tag.default`
426
467
  fragment blockFragment on Block {
427
468
  id
469
+ height
428
470
  header {
429
- height
430
471
  time
431
472
  }
432
473
  transactions {
@@ -484,6 +525,11 @@ var DependentCostFragmentFragmentDoc = import_graphql_tag.default`
484
525
  `;
485
526
  var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
486
527
  fragment GasCostsFragment on GasCosts {
528
+ version {
529
+ ... on Version {
530
+ value
531
+ }
532
+ }
487
533
  add
488
534
  addi
489
535
  aloc
@@ -496,7 +542,6 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
496
542
  cb
497
543
  cfei
498
544
  cfsi
499
- croo
500
545
  div
501
546
  divi
502
547
  ecr1
@@ -579,6 +624,9 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
579
624
  ccp {
580
625
  ...DependentCostFragment
581
626
  }
627
+ croo {
628
+ ...DependentCostFragment
629
+ }
582
630
  csiz {
583
631
  ...DependentCostFragment
584
632
  }
@@ -638,6 +686,11 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
638
686
  ${DependentCostFragmentFragmentDoc}`;
639
687
  var ConsensusParametersFragmentFragmentDoc = import_graphql_tag.default`
640
688
  fragment consensusParametersFragment on ConsensusParameters {
689
+ version {
690
+ ... on Version {
691
+ value
692
+ }
693
+ }
641
694
  txParams {
642
695
  ...TxParametersFragment
643
696
  }
@@ -697,18 +750,9 @@ var NodeInfoFragmentFragmentDoc = import_graphql_tag.default`
697
750
  fragment nodeInfoFragment on NodeInfo {
698
751
  utxoValidation
699
752
  vmBacktrace
700
- minGasPrice
701
753
  maxTx
702
754
  maxDepth
703
755
  nodeVersion
704
- peers {
705
- id
706
- addresses
707
- clientVersion
708
- blockHeight
709
- lastHeartbeatMs
710
- appScore
711
- }
712
756
  }
713
757
  `;
714
758
  var GetVersionDocument = import_graphql_tag.default`
@@ -743,13 +787,9 @@ var GetTransactionWithReceiptsDocument = import_graphql_tag.default`
743
787
  query getTransactionWithReceipts($transactionId: TransactionId!) {
744
788
  transaction(id: $transactionId) {
745
789
  ...transactionFragment
746
- receipts {
747
- ...receiptFragment
748
- }
749
790
  }
750
791
  }
751
- ${TransactionFragmentFragmentDoc}
752
- ${ReceiptFragmentFragmentDoc}`;
792
+ ${TransactionFragmentFragmentDoc}`;
753
793
  var GetTransactionsDocument = import_graphql_tag.default`
754
794
  query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
755
795
  transactions(after: $after, before: $before, first: $first, last: $last) {
@@ -877,6 +917,20 @@ var GetBalanceDocument = import_graphql_tag.default`
877
917
  }
878
918
  }
879
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
+ `;
880
934
  var GetBalancesDocument = import_graphql_tag.default`
881
935
  query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
882
936
  balances(
@@ -931,12 +985,12 @@ var GetMessageStatusDocument = import_graphql_tag.default`
931
985
  }
932
986
  `;
933
987
  var DryRunDocument = import_graphql_tag.default`
934
- mutation dryRun($encodedTransaction: HexString!, $utxoValidation: Boolean) {
935
- dryRun(tx: $encodedTransaction, utxoValidation: $utxoValidation) {
936
- ...receiptFragment
988
+ mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean) {
989
+ dryRun(txs: $encodedTransactions, utxoValidation: $utxoValidation) {
990
+ ...dryRunTransactionExecutionStatusFragment
937
991
  }
938
992
  }
939
- ${ReceiptFragmentFragmentDoc}`;
993
+ ${DryRunTransactionExecutionStatusFragmentFragmentDoc}`;
940
994
  var SubmitDocument = import_graphql_tag.default`
941
995
  mutation submit($encodedTransaction: HexString!) {
942
996
  submit(tx: $encodedTransaction) {
@@ -1019,6 +1073,12 @@ function getSdk(requester) {
1019
1073
  getBalance(variables, options) {
1020
1074
  return requester(GetBalanceDocument, variables, options);
1021
1075
  },
1076
+ getLatestGasPrice(variables, options) {
1077
+ return requester(GetLatestGasPriceDocument, variables, options);
1078
+ },
1079
+ estimateGasPrice(variables, options) {
1080
+ return requester(EstimateGasPriceDocument, variables, options);
1081
+ },
1022
1082
  getBalances(variables, options) {
1023
1083
  return requester(GetBalancesDocument, variables, options);
1024
1084
  },
@@ -1212,10 +1272,9 @@ var inputify = (value) => {
1212
1272
  txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
1213
1273
  },
1214
1274
  witnessIndex: value.witnessIndex,
1215
- maturity: value.maturity ?? 0,
1216
1275
  predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
1217
- predicateLength: predicate.length,
1218
- predicateDataLength: predicateData.length,
1276
+ predicateLength: (0, import_math2.bn)(predicate.length),
1277
+ predicateDataLength: (0, import_math2.bn)(predicateData.length),
1219
1278
  predicate: (0, import_utils3.hexlify)(predicate),
1220
1279
  predicateData: (0, import_utils3.hexlify)(predicateData)
1221
1280
  };
@@ -1246,8 +1305,8 @@ var inputify = (value) => {
1246
1305
  nonce: (0, import_utils3.hexlify)(value.nonce),
1247
1306
  witnessIndex: value.witnessIndex,
1248
1307
  predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
1249
- predicateLength: predicate.length,
1250
- predicateDataLength: predicateData.length,
1308
+ predicateLength: (0, import_math2.bn)(predicate.length),
1309
+ predicateDataLength: (0, import_math2.bn)(predicateData.length),
1251
1310
  predicate: (0, import_utils3.hexlify)(predicate),
1252
1311
  predicateData: (0, import_utils3.hexlify)(predicateData),
1253
1312
  data: (0, import_utils3.hexlify)(data),
@@ -1326,7 +1385,7 @@ var import_address = require("@fuel-ts/address");
1326
1385
  var import_configs7 = require("@fuel-ts/address/configs");
1327
1386
  var import_crypto = require("@fuel-ts/crypto");
1328
1387
  var import_math7 = require("@fuel-ts/math");
1329
- var import_transactions7 = require("@fuel-ts/transactions");
1388
+ var import_transactions6 = require("@fuel-ts/transactions");
1330
1389
  var import_utils9 = require("@fuel-ts/utils");
1331
1390
 
1332
1391
  // src/providers/resource.ts
@@ -1366,8 +1425,8 @@ function assembleReceiptByType(receipt) {
1366
1425
  case "CALL" /* Call */: {
1367
1426
  const callReceipt = {
1368
1427
  type: import_transactions3.ReceiptType.Call,
1369
- from: hexOrZero(receipt.contract?.id),
1370
- to: hexOrZero(receipt?.to?.id),
1428
+ from: hexOrZero(receipt.id || receipt.contractId),
1429
+ to: hexOrZero(receipt?.to),
1371
1430
  amount: (0, import_math4.bn)(receipt.amount),
1372
1431
  assetId: hexOrZero(receipt.assetId),
1373
1432
  gas: (0, import_math4.bn)(receipt.gas),
@@ -1381,7 +1440,7 @@ function assembleReceiptByType(receipt) {
1381
1440
  case "RETURN" /* Return */: {
1382
1441
  const returnReceipt = {
1383
1442
  type: import_transactions3.ReceiptType.Return,
1384
- id: hexOrZero(receipt.contract?.id),
1443
+ id: hexOrZero(receipt.id || receipt.contractId),
1385
1444
  val: (0, import_math4.bn)(receipt.val),
1386
1445
  pc: (0, import_math4.bn)(receipt.pc),
1387
1446
  is: (0, import_math4.bn)(receipt.is)
@@ -1391,7 +1450,7 @@ function assembleReceiptByType(receipt) {
1391
1450
  case "RETURN_DATA" /* ReturnData */: {
1392
1451
  const returnDataReceipt = {
1393
1452
  type: import_transactions3.ReceiptType.ReturnData,
1394
- id: hexOrZero(receipt.contract?.id),
1453
+ id: hexOrZero(receipt.id || receipt.contractId),
1395
1454
  ptr: (0, import_math4.bn)(receipt.ptr),
1396
1455
  len: (0, import_math4.bn)(receipt.len),
1397
1456
  digest: hexOrZero(receipt.digest),
@@ -1403,7 +1462,7 @@ function assembleReceiptByType(receipt) {
1403
1462
  case "PANIC" /* Panic */: {
1404
1463
  const panicReceipt = {
1405
1464
  type: import_transactions3.ReceiptType.Panic,
1406
- id: hexOrZero(receipt.contract?.id),
1465
+ id: hexOrZero(receipt.id),
1407
1466
  reason: (0, import_math4.bn)(receipt.reason),
1408
1467
  pc: (0, import_math4.bn)(receipt.pc),
1409
1468
  is: (0, import_math4.bn)(receipt.is),
@@ -1414,7 +1473,7 @@ function assembleReceiptByType(receipt) {
1414
1473
  case "REVERT" /* Revert */: {
1415
1474
  const revertReceipt = {
1416
1475
  type: import_transactions3.ReceiptType.Revert,
1417
- id: hexOrZero(receipt.contract?.id),
1476
+ id: hexOrZero(receipt.id || receipt.contractId),
1418
1477
  val: (0, import_math4.bn)(receipt.ra),
1419
1478
  pc: (0, import_math4.bn)(receipt.pc),
1420
1479
  is: (0, import_math4.bn)(receipt.is)
@@ -1424,7 +1483,7 @@ function assembleReceiptByType(receipt) {
1424
1483
  case "LOG" /* Log */: {
1425
1484
  const logReceipt = {
1426
1485
  type: import_transactions3.ReceiptType.Log,
1427
- id: hexOrZero(receipt.contract?.id),
1486
+ id: hexOrZero(receipt.id || receipt.contractId),
1428
1487
  val0: (0, import_math4.bn)(receipt.ra),
1429
1488
  val1: (0, import_math4.bn)(receipt.rb),
1430
1489
  val2: (0, import_math4.bn)(receipt.rc),
@@ -1437,7 +1496,7 @@ function assembleReceiptByType(receipt) {
1437
1496
  case "LOG_DATA" /* LogData */: {
1438
1497
  const logDataReceipt = {
1439
1498
  type: import_transactions3.ReceiptType.LogData,
1440
- id: hexOrZero(receipt.contract?.id),
1499
+ id: hexOrZero(receipt.id || receipt.contractId),
1441
1500
  val0: (0, import_math4.bn)(receipt.ra),
1442
1501
  val1: (0, import_math4.bn)(receipt.rb),
1443
1502
  ptr: (0, import_math4.bn)(receipt.ptr),
@@ -1451,8 +1510,8 @@ function assembleReceiptByType(receipt) {
1451
1510
  case "TRANSFER" /* Transfer */: {
1452
1511
  const transferReceipt = {
1453
1512
  type: import_transactions3.ReceiptType.Transfer,
1454
- from: hexOrZero(receipt.contract?.id),
1455
- to: hexOrZero(receipt.toAddress || receipt?.to?.id),
1513
+ from: hexOrZero(receipt.id || receipt.contractId),
1514
+ to: hexOrZero(receipt.toAddress || receipt?.to),
1456
1515
  amount: (0, import_math4.bn)(receipt.amount),
1457
1516
  assetId: hexOrZero(receipt.assetId),
1458
1517
  pc: (0, import_math4.bn)(receipt.pc),
@@ -1463,8 +1522,8 @@ function assembleReceiptByType(receipt) {
1463
1522
  case "TRANSFER_OUT" /* TransferOut */: {
1464
1523
  const transferOutReceipt = {
1465
1524
  type: import_transactions3.ReceiptType.TransferOut,
1466
- from: hexOrZero(receipt.contract?.id),
1467
- to: hexOrZero(receipt.toAddress || receipt.to?.id),
1525
+ from: hexOrZero(receipt.id || receipt.contractId),
1526
+ to: hexOrZero(receipt.toAddress || receipt.to),
1468
1527
  amount: (0, import_math4.bn)(receipt.amount),
1469
1528
  assetId: hexOrZero(receipt.assetId),
1470
1529
  pc: (0, import_math4.bn)(receipt.pc),
@@ -1507,7 +1566,7 @@ function assembleReceiptByType(receipt) {
1507
1566
  return receiptMessageOut;
1508
1567
  }
1509
1568
  case "MINT" /* Mint */: {
1510
- const contractId = hexOrZero(receipt.contract?.id);
1569
+ const contractId = hexOrZero(receipt.id || receipt.contractId);
1511
1570
  const subId = hexOrZero(receipt.subId);
1512
1571
  const assetId = import_transactions3.ReceiptMintCoder.getAssetId(contractId, subId);
1513
1572
  const mintReceipt = {
@@ -1522,7 +1581,7 @@ function assembleReceiptByType(receipt) {
1522
1581
  return mintReceipt;
1523
1582
  }
1524
1583
  case "BURN" /* Burn */: {
1525
- const contractId = hexOrZero(receipt.contract?.id);
1584
+ const contractId = hexOrZero(receipt.id || receipt.contractId);
1526
1585
  const subId = hexOrZero(receipt.subId);
1527
1586
  const assetId = import_transactions3.ReceiptBurnCoder.getAssetId(contractId, subId);
1528
1587
  const burnReceipt = {
@@ -1607,7 +1666,6 @@ var buildBlockExplorerUrl = (options = {}) => {
1607
1666
  var import_math5 = require("@fuel-ts/math");
1608
1667
  var import_transactions4 = require("@fuel-ts/transactions");
1609
1668
  var import_utils6 = require("@fuel-ts/utils");
1610
- var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => (0, import_math5.bn)(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
1611
1669
  var getGasUsedFromReceipts = (receipts) => {
1612
1670
  const scriptResult = receipts.filter(
1613
1671
  (receipt) => receipt.type === import_transactions4.ReceiptType.ScriptResult
@@ -1628,18 +1686,28 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
1628
1686
  }
1629
1687
  function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
1630
1688
  const witnessCache = [];
1631
- 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) => {
1632
1704
  if ("predicate" in input && input.predicate && input.predicate !== "0x") {
1633
1705
  return total.add(
1634
- 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))
1635
1707
  );
1636
1708
  }
1637
- if ("witnessIndex" in input && !witnessCache.includes(input.witnessIndex)) {
1638
- witnessCache.push(input.witnessIndex);
1639
- return total.add(gasCosts.ecr1);
1640
- }
1641
- return total;
1642
- }, (0, import_math5.bn)());
1709
+ return total.add(gasCosts.ecr1);
1710
+ }, (0, import_math5.bn)(0));
1643
1711
  return totalGas;
1644
1712
  }
1645
1713
  function getMinGas(params) {
@@ -1651,12 +1719,20 @@ function getMinGas(params) {
1651
1719
  return minGas;
1652
1720
  }
1653
1721
  function getMaxGas(params) {
1654
- 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;
1655
1730
  let remainingAllowedWitnessGas = (0, import_math5.bn)(0);
1656
1731
  if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
1657
1732
  remainingAllowedWitnessGas = (0, import_math5.bn)(witnessLimit).sub(witnessesLength).mul(gasPerByte);
1658
1733
  }
1659
- return remainingAllowedWitnessGas.add(minGas).add(gasLimit);
1734
+ const maxGas = remainingAllowedWitnessGas.add(minGas).add(gasLimit);
1735
+ return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
1660
1736
  }
1661
1737
  function calculateMetadataGasForTxCreate({
1662
1738
  gasCosts,
@@ -1678,6 +1754,10 @@ function calculateMetadataGasForTxScript({
1678
1754
  }) {
1679
1755
  return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
1680
1756
  }
1757
+ var calculateGasFee = (params) => {
1758
+ const { gas, gasPrice, priceFactor, tip } = params;
1759
+ return gas.mul(gasPrice).div(priceFactor).add(tip);
1760
+ };
1681
1761
 
1682
1762
  // src/providers/utils/json.ts
1683
1763
  var import_utils7 = require("@fuel-ts/utils");
@@ -1813,28 +1893,6 @@ var NoWitnessByOwnerError = class extends Error {
1813
1893
  name = "NoWitnessByOwnerError";
1814
1894
  };
1815
1895
 
1816
- // src/providers/transaction-request/helpers.ts
1817
- var import_transactions6 = require("@fuel-ts/transactions");
1818
- var isRequestInputCoin = (input) => input.type === import_transactions6.InputType.Coin;
1819
- var isRequestInputMessage = (input) => input.type === import_transactions6.InputType.Message;
1820
- var isRequestInputResource = (input) => isRequestInputCoin(input) || isRequestInputMessage(input);
1821
- var getRequestInputResourceOwner = (input) => isRequestInputCoin(input) ? input.owner : input.recipient;
1822
- var isRequestInputResourceFromOwner = (input, owner) => getRequestInputResourceOwner(input) === owner.toB256();
1823
- var cacheResources = (resources) => resources.reduce(
1824
- (cache2, resource) => {
1825
- if (isCoin(resource)) {
1826
- cache2.utxos.push(resource.id);
1827
- } else {
1828
- cache2.messages.push(resource.nonce);
1829
- }
1830
- return cache2;
1831
- },
1832
- {
1833
- utxos: [],
1834
- messages: []
1835
- }
1836
- );
1837
-
1838
1896
  // src/providers/transaction-request/witness.ts
1839
1897
  var import_utils8 = require("@fuel-ts/utils");
1840
1898
  var witnessify = (value) => {
@@ -1848,7 +1906,7 @@ var witnessify = (value) => {
1848
1906
  // src/providers/transaction-request/transaction-request.ts
1849
1907
  var BaseTransactionRequest = class {
1850
1908
  /** Gas price for transaction */
1851
- gasPrice;
1909
+ tip;
1852
1910
  /** Block until which tx cannot be included */
1853
1911
  maturity;
1854
1912
  /** The maximum fee payable by this transaction using BASE_ASSET. */
@@ -1867,7 +1925,7 @@ var BaseTransactionRequest = class {
1867
1925
  * @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
1868
1926
  */
1869
1927
  constructor({
1870
- gasPrice,
1928
+ tip,
1871
1929
  maturity,
1872
1930
  maxFee,
1873
1931
  witnessLimit,
@@ -1875,7 +1933,7 @@ var BaseTransactionRequest = class {
1875
1933
  outputs,
1876
1934
  witnesses
1877
1935
  } = {}) {
1878
- this.gasPrice = (0, import_math7.bn)(gasPrice);
1936
+ this.tip = (0, import_math7.bn)(tip);
1879
1937
  this.maturity = maturity ?? 0;
1880
1938
  this.witnessLimit = witnessLimit ? (0, import_math7.bn)(witnessLimit) : void 0;
1881
1939
  this.maxFee = maxFee ? (0, import_math7.bn)(maxFee) : void 0;
@@ -1886,21 +1944,21 @@ var BaseTransactionRequest = class {
1886
1944
  static getPolicyMeta(req) {
1887
1945
  let policyTypes = 0;
1888
1946
  const policies = [];
1889
- if (req.gasPrice) {
1890
- policyTypes += import_transactions7.PolicyType.GasPrice;
1891
- policies.push({ data: req.gasPrice, type: import_transactions7.PolicyType.GasPrice });
1947
+ if (req.tip) {
1948
+ policyTypes += import_transactions6.PolicyType.Tip;
1949
+ policies.push({ data: req.tip, type: import_transactions6.PolicyType.Tip });
1892
1950
  }
1893
1951
  if (req.witnessLimit) {
1894
- policyTypes += import_transactions7.PolicyType.WitnessLimit;
1895
- policies.push({ data: req.witnessLimit, type: import_transactions7.PolicyType.WitnessLimit });
1952
+ policyTypes += import_transactions6.PolicyType.WitnessLimit;
1953
+ policies.push({ data: req.witnessLimit, type: import_transactions6.PolicyType.WitnessLimit });
1896
1954
  }
1897
1955
  if (req.maturity > 0) {
1898
- policyTypes += import_transactions7.PolicyType.Maturity;
1899
- policies.push({ data: req.maturity, type: import_transactions7.PolicyType.Maturity });
1956
+ policyTypes += import_transactions6.PolicyType.Maturity;
1957
+ policies.push({ data: req.maturity, type: import_transactions6.PolicyType.Maturity });
1900
1958
  }
1901
1959
  if (req.maxFee) {
1902
- policyTypes += import_transactions7.PolicyType.MaxFee;
1903
- policies.push({ data: req.maxFee, type: import_transactions7.PolicyType.MaxFee });
1960
+ policyTypes += import_transactions6.PolicyType.MaxFee;
1961
+ policies.push({ data: req.maxFee, type: import_transactions6.PolicyType.MaxFee });
1904
1962
  }
1905
1963
  return {
1906
1964
  policyTypes,
@@ -1934,7 +1992,7 @@ var BaseTransactionRequest = class {
1934
1992
  * @returns The transaction bytes.
1935
1993
  */
1936
1994
  toTransactionBytes() {
1937
- return new import_transactions7.TransactionCoder().encode(this.toTransaction());
1995
+ return new import_transactions6.TransactionCoder().encode(this.toTransaction());
1938
1996
  }
1939
1997
  /**
1940
1998
  * @hidden
@@ -2025,7 +2083,7 @@ var BaseTransactionRequest = class {
2025
2083
  */
2026
2084
  getCoinInputs() {
2027
2085
  return this.inputs.filter(
2028
- (input) => input.type === import_transactions7.InputType.Coin
2086
+ (input) => input.type === import_transactions6.InputType.Coin
2029
2087
  );
2030
2088
  }
2031
2089
  /**
@@ -2035,7 +2093,7 @@ var BaseTransactionRequest = class {
2035
2093
  */
2036
2094
  getCoinOutputs() {
2037
2095
  return this.outputs.filter(
2038
- (output) => output.type === import_transactions7.OutputType.Coin
2096
+ (output) => output.type === import_transactions6.OutputType.Coin
2039
2097
  );
2040
2098
  }
2041
2099
  /**
@@ -2045,7 +2103,7 @@ var BaseTransactionRequest = class {
2045
2103
  */
2046
2104
  getChangeOutputs() {
2047
2105
  return this.outputs.filter(
2048
- (output) => output.type === import_transactions7.OutputType.Change
2106
+ (output) => output.type === import_transactions6.OutputType.Change
2049
2107
  );
2050
2108
  }
2051
2109
  /**
@@ -2057,9 +2115,9 @@ var BaseTransactionRequest = class {
2057
2115
  const ownerAddress = (0, import_address.addressify)(owner);
2058
2116
  const found = this.inputs.find((input) => {
2059
2117
  switch (input.type) {
2060
- case import_transactions7.InputType.Coin:
2118
+ case import_transactions6.InputType.Coin:
2061
2119
  return (0, import_utils9.hexlify)(input.owner) === ownerAddress.toB256();
2062
- case import_transactions7.InputType.Message:
2120
+ case import_transactions6.InputType.Message:
2063
2121
  return (0, import_utils9.hexlify)(input.recipient) === ownerAddress.toB256();
2064
2122
  default:
2065
2123
  return false;
@@ -2076,9 +2134,9 @@ var BaseTransactionRequest = class {
2076
2134
  * @param predicateData - Predicate data bytes.
2077
2135
  */
2078
2136
  addCoinInput(coin) {
2079
- const { assetId, owner, amount, id, predicate } = coin;
2137
+ const { assetId, owner, amount } = coin;
2080
2138
  let witnessIndex;
2081
- if (predicate) {
2139
+ if (coin.predicate) {
2082
2140
  witnessIndex = 0;
2083
2141
  } else {
2084
2142
  witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
@@ -2087,14 +2145,13 @@ var BaseTransactionRequest = class {
2087
2145
  }
2088
2146
  }
2089
2147
  const input = {
2090
- id,
2091
- type: import_transactions7.InputType.Coin,
2148
+ ...coin,
2149
+ type: import_transactions6.InputType.Coin,
2092
2150
  owner: owner.toB256(),
2093
2151
  amount,
2094
2152
  assetId,
2095
2153
  txPointer: "0x00000000000000000000000000000000",
2096
- witnessIndex,
2097
- predicate
2154
+ witnessIndex
2098
2155
  };
2099
2156
  this.pushInput(input);
2100
2157
  this.addChangeOutput(owner, assetId);
@@ -2108,10 +2165,10 @@ var BaseTransactionRequest = class {
2108
2165
  * @param predicateData - Predicate data bytes.
2109
2166
  */
2110
2167
  addMessageInput(message) {
2111
- const { recipient, sender, amount, predicate, nonce } = message;
2168
+ const { recipient, sender, amount } = message;
2112
2169
  const assetId = import_configs7.BaseAssetId;
2113
2170
  let witnessIndex;
2114
- if (predicate) {
2171
+ if (message.predicate) {
2115
2172
  witnessIndex = 0;
2116
2173
  } else {
2117
2174
  witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
@@ -2120,13 +2177,12 @@ var BaseTransactionRequest = class {
2120
2177
  }
2121
2178
  }
2122
2179
  const input = {
2123
- nonce,
2124
- type: import_transactions7.InputType.Message,
2180
+ ...message,
2181
+ type: import_transactions6.InputType.Message,
2125
2182
  sender: sender.toB256(),
2126
2183
  recipient: recipient.toB256(),
2127
2184
  amount,
2128
- witnessIndex,
2129
- predicate
2185
+ witnessIndex
2130
2186
  };
2131
2187
  this.pushInput(input);
2132
2188
  this.addChangeOutput(recipient, assetId);
@@ -2166,7 +2222,7 @@ var BaseTransactionRequest = class {
2166
2222
  */
2167
2223
  addCoinOutput(to, amount, assetId = import_configs7.BaseAssetId) {
2168
2224
  this.pushOutput({
2169
- type: import_transactions7.OutputType.Coin,
2225
+ type: import_transactions6.OutputType.Coin,
2170
2226
  to: (0, import_address.addressify)(to).toB256(),
2171
2227
  amount,
2172
2228
  assetId
@@ -2182,7 +2238,7 @@ var BaseTransactionRequest = class {
2182
2238
  addCoinOutputs(to, quantities) {
2183
2239
  quantities.map(coinQuantityfy).forEach((quantity) => {
2184
2240
  this.pushOutput({
2185
- type: import_transactions7.OutputType.Coin,
2241
+ type: import_transactions6.OutputType.Coin,
2186
2242
  to: (0, import_address.addressify)(to).toB256(),
2187
2243
  amount: quantity.amount,
2188
2244
  assetId: quantity.assetId
@@ -2202,7 +2258,7 @@ var BaseTransactionRequest = class {
2202
2258
  );
2203
2259
  if (!changeOutput) {
2204
2260
  this.pushOutput({
2205
- type: import_transactions7.OutputType.Change,
2261
+ type: import_transactions6.OutputType.Change,
2206
2262
  to: (0, import_address.addressify)(to).toB256(),
2207
2263
  assetId
2208
2264
  });
@@ -2236,7 +2292,7 @@ var BaseTransactionRequest = class {
2236
2292
  }
2237
2293
  calculateMaxGas(chainInfo, minGas) {
2238
2294
  const { consensusParameters } = chainInfo;
2239
- const { gasPerByte } = consensusParameters;
2295
+ const { gasPerByte, maxGasPerTx } = consensusParameters;
2240
2296
  const witnessesLength = this.toTransaction().witnesses.reduce(
2241
2297
  (acc, wit) => acc + wit.dataLength,
2242
2298
  0
@@ -2245,7 +2301,8 @@ var BaseTransactionRequest = class {
2245
2301
  gasPerByte,
2246
2302
  minGas,
2247
2303
  witnessesLength,
2248
- witnessLimit: this.witnessLimit
2304
+ witnessLimit: this.witnessLimit,
2305
+ maxGasPerTx
2249
2306
  });
2250
2307
  }
2251
2308
  /**
@@ -2263,17 +2320,20 @@ var BaseTransactionRequest = class {
2263
2320
  });
2264
2321
  const updateAssetInput = (assetId, quantity) => {
2265
2322
  const assetInput = findAssetInput(assetId);
2323
+ let usedQuantity = quantity;
2324
+ if (assetId === import_configs7.BaseAssetId) {
2325
+ usedQuantity = (0, import_math7.bn)("1000000000000000000");
2326
+ }
2266
2327
  if (assetInput && "assetId" in assetInput) {
2267
2328
  assetInput.id = (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN));
2268
- assetInput.amount = quantity;
2329
+ assetInput.amount = usedQuantity;
2269
2330
  } else {
2270
2331
  this.addResources([
2271
2332
  {
2272
2333
  id: (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN)),
2273
- amount: quantity,
2334
+ amount: usedQuantity,
2274
2335
  assetId,
2275
2336
  owner: resourcesOwner || import_address.Address.fromRandom(),
2276
- maturity: 0,
2277
2337
  blockCreated: (0, import_math7.bn)(1),
2278
2338
  txCreatedIdx: (0, import_math7.bn)(1)
2279
2339
  }
@@ -2305,20 +2365,16 @@ var BaseTransactionRequest = class {
2305
2365
  toJSON() {
2306
2366
  return normalizeJSON(this);
2307
2367
  }
2308
- removeWitness(index) {
2309
- this.witnesses.splice(index, 1);
2310
- this.adjustWitnessIndexes(index);
2311
- }
2312
- updatePredicateInputs(inputs) {
2368
+ updatePredicateGasUsed(inputs) {
2313
2369
  this.inputs.forEach((i) => {
2314
2370
  let correspondingInput;
2315
2371
  switch (i.type) {
2316
- case import_transactions7.InputType.Coin:
2317
- correspondingInput = inputs.find((x) => x.type === import_transactions7.InputType.Coin && x.owner === i.owner);
2372
+ case import_transactions6.InputType.Coin:
2373
+ correspondingInput = inputs.find((x) => x.type === import_transactions6.InputType.Coin && x.owner === i.owner);
2318
2374
  break;
2319
- case import_transactions7.InputType.Message:
2375
+ case import_transactions6.InputType.Message:
2320
2376
  correspondingInput = inputs.find(
2321
- (x) => x.type === import_transactions7.InputType.Message && x.sender === i.sender
2377
+ (x) => x.type === import_transactions6.InputType.Message && x.sender === i.sender
2322
2378
  );
2323
2379
  break;
2324
2380
  default:
@@ -2331,10 +2387,12 @@ var BaseTransactionRequest = class {
2331
2387
  }
2332
2388
  });
2333
2389
  }
2334
- adjustWitnessIndexes(removedIndex) {
2335
- this.inputs.filter(isRequestInputResource).forEach((input) => {
2336
- if (input.witnessIndex > removedIndex) {
2337
- input.witnessIndex -= 1;
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
+ );
2338
2396
  }
2339
2397
  });
2340
2398
  }
@@ -2343,25 +2401,25 @@ var BaseTransactionRequest = class {
2343
2401
  // src/providers/transaction-request/create-transaction-request.ts
2344
2402
  var import_configs9 = require("@fuel-ts/address/configs");
2345
2403
  var import_math9 = require("@fuel-ts/math");
2346
- var import_transactions9 = require("@fuel-ts/transactions");
2404
+ var import_transactions8 = require("@fuel-ts/transactions");
2347
2405
  var import_utils13 = require("@fuel-ts/utils");
2348
2406
 
2349
2407
  // src/providers/transaction-request/hash-transaction.ts
2350
2408
  var import_configs8 = require("@fuel-ts/address/configs");
2351
2409
  var import_hasher = require("@fuel-ts/hasher");
2352
2410
  var import_math8 = require("@fuel-ts/math");
2353
- var import_transactions8 = require("@fuel-ts/transactions");
2411
+ var import_transactions7 = require("@fuel-ts/transactions");
2354
2412
  var import_utils11 = require("@fuel-ts/utils");
2355
2413
  var import_ramda2 = require("ramda");
2356
2414
  function hashTransaction(transactionRequest, chainId) {
2357
2415
  const transaction = transactionRequest.toTransaction();
2358
- if (transaction.type === import_transactions8.TransactionType.Script) {
2416
+ if (transaction.type === import_transactions7.TransactionType.Script) {
2359
2417
  transaction.receiptsRoot = import_configs8.ZeroBytes32;
2360
2418
  }
2361
2419
  transaction.inputs = transaction.inputs.map((input) => {
2362
2420
  const inputClone = (0, import_ramda2.clone)(input);
2363
2421
  switch (inputClone.type) {
2364
- case import_transactions8.InputType.Coin: {
2422
+ case import_transactions7.InputType.Coin: {
2365
2423
  inputClone.txPointer = {
2366
2424
  blockHeight: 0,
2367
2425
  txIndex: 0
@@ -2369,11 +2427,11 @@ function hashTransaction(transactionRequest, chainId) {
2369
2427
  inputClone.predicateGasUsed = (0, import_math8.bn)(0);
2370
2428
  return inputClone;
2371
2429
  }
2372
- case import_transactions8.InputType.Message: {
2430
+ case import_transactions7.InputType.Message: {
2373
2431
  inputClone.predicateGasUsed = (0, import_math8.bn)(0);
2374
2432
  return inputClone;
2375
2433
  }
2376
- case import_transactions8.InputType.Contract: {
2434
+ case import_transactions7.InputType.Contract: {
2377
2435
  inputClone.txPointer = {
2378
2436
  blockHeight: 0,
2379
2437
  txIndex: 0
@@ -2391,16 +2449,16 @@ function hashTransaction(transactionRequest, chainId) {
2391
2449
  transaction.outputs = transaction.outputs.map((output) => {
2392
2450
  const outputClone = (0, import_ramda2.clone)(output);
2393
2451
  switch (outputClone.type) {
2394
- case import_transactions8.OutputType.Contract: {
2452
+ case import_transactions7.OutputType.Contract: {
2395
2453
  outputClone.balanceRoot = import_configs8.ZeroBytes32;
2396
2454
  outputClone.stateRoot = import_configs8.ZeroBytes32;
2397
2455
  return outputClone;
2398
2456
  }
2399
- case import_transactions8.OutputType.Change: {
2457
+ case import_transactions7.OutputType.Change: {
2400
2458
  outputClone.amount = (0, import_math8.bn)(0);
2401
2459
  return outputClone;
2402
2460
  }
2403
- case import_transactions8.OutputType.Variable: {
2461
+ case import_transactions7.OutputType.Variable: {
2404
2462
  outputClone.to = import_configs8.ZeroBytes32;
2405
2463
  outputClone.amount = (0, import_math8.bn)(0);
2406
2464
  outputClone.assetId = import_configs8.ZeroBytes32;
@@ -2413,7 +2471,7 @@ function hashTransaction(transactionRequest, chainId) {
2413
2471
  transaction.witnessesCount = 0;
2414
2472
  transaction.witnesses = [];
2415
2473
  const chainIdBytes = (0, import_hasher.uint64ToBytesBE)(chainId);
2416
- const concatenatedData = (0, import_utils11.concat)([chainIdBytes, new import_transactions8.TransactionCoder().encode(transaction)]);
2474
+ const concatenatedData = (0, import_utils11.concat)([chainIdBytes, new import_transactions7.TransactionCoder().encode(transaction)]);
2417
2475
  return (0, import_hasher.sha256)(concatenatedData);
2418
2476
  }
2419
2477
 
@@ -2449,7 +2507,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2449
2507
  return new this(obj);
2450
2508
  }
2451
2509
  /** Type of the transaction */
2452
- type = import_transactions9.TransactionType.Create;
2510
+ type = import_transactions8.TransactionType.Create;
2453
2511
  /** Witness index of contract bytecode to create */
2454
2512
  bytecodeWitnessIndex;
2455
2513
  /** Salt */
@@ -2482,11 +2540,10 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2482
2540
  const bytecodeWitnessIndex = this.bytecodeWitnessIndex;
2483
2541
  const storageSlots = this.storageSlots?.map(storageSlotify) ?? [];
2484
2542
  return {
2485
- type: import_transactions9.TransactionType.Create,
2543
+ type: import_transactions8.TransactionType.Create,
2486
2544
  ...baseTransaction,
2487
- bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
2488
2545
  bytecodeWitnessIndex,
2489
- storageSlotsCount: storageSlots.length,
2546
+ storageSlotsCount: (0, import_math9.bn)(storageSlots.length),
2490
2547
  salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs9.ZeroBytes32,
2491
2548
  storageSlots
2492
2549
  };
@@ -2498,7 +2555,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2498
2555
  */
2499
2556
  getContractCreatedOutputs() {
2500
2557
  return this.outputs.filter(
2501
- (output) => output.type === import_transactions9.OutputType.ContractCreated
2558
+ (output) => output.type === import_transactions8.OutputType.ContractCreated
2502
2559
  );
2503
2560
  }
2504
2561
  /**
@@ -2519,7 +2576,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2519
2576
  */
2520
2577
  addContractCreatedOutput(contractId, stateRoot) {
2521
2578
  this.pushOutput({
2522
- type: import_transactions9.OutputType.ContractCreated,
2579
+ type: import_transactions8.OutputType.ContractCreated,
2523
2580
  contractId,
2524
2581
  stateRoot
2525
2582
  });
@@ -2539,7 +2596,7 @@ var import_abi_coder3 = require("@fuel-ts/abi-coder");
2539
2596
  var import_address2 = require("@fuel-ts/address");
2540
2597
  var import_configs10 = require("@fuel-ts/address/configs");
2541
2598
  var import_math10 = require("@fuel-ts/math");
2542
- var import_transactions10 = require("@fuel-ts/transactions");
2599
+ var import_transactions9 = require("@fuel-ts/transactions");
2543
2600
  var import_utils15 = require("@fuel-ts/utils");
2544
2601
 
2545
2602
  // src/providers/transaction-request/scripts.ts
@@ -2577,7 +2634,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2577
2634
  return new this(obj);
2578
2635
  }
2579
2636
  /** Type of the transaction */
2580
- type = import_transactions10.TransactionType.Script;
2637
+ type = import_transactions9.TransactionType.Script;
2581
2638
  /** Gas limit for transaction */
2582
2639
  gasLimit;
2583
2640
  /** Script to execute */
@@ -2606,11 +2663,11 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2606
2663
  const script = (0, import_utils15.arrayify)(this.script ?? "0x");
2607
2664
  const scriptData = (0, import_utils15.arrayify)(this.scriptData ?? "0x");
2608
2665
  return {
2609
- type: import_transactions10.TransactionType.Script,
2666
+ type: import_transactions9.TransactionType.Script,
2610
2667
  scriptGasLimit: this.gasLimit,
2611
2668
  ...super.getBaseTransaction(),
2612
- scriptLength: script.length,
2613
- scriptDataLength: scriptData.length,
2669
+ scriptLength: (0, import_math10.bn)(script.length),
2670
+ scriptDataLength: (0, import_math10.bn)(scriptData.length),
2614
2671
  receiptsRoot: import_configs10.ZeroBytes32,
2615
2672
  script: (0, import_utils15.hexlify)(script),
2616
2673
  scriptData: (0, import_utils15.hexlify)(scriptData)
@@ -2623,7 +2680,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2623
2680
  */
2624
2681
  getContractInputs() {
2625
2682
  return this.inputs.filter(
2626
- (input) => input.type === import_transactions10.InputType.Contract
2683
+ (input) => input.type === import_transactions9.InputType.Contract
2627
2684
  );
2628
2685
  }
2629
2686
  /**
@@ -2633,7 +2690,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2633
2690
  */
2634
2691
  getContractOutputs() {
2635
2692
  return this.outputs.filter(
2636
- (output) => output.type === import_transactions10.OutputType.Contract
2693
+ (output) => output.type === import_transactions9.OutputType.Contract
2637
2694
  );
2638
2695
  }
2639
2696
  /**
@@ -2643,7 +2700,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2643
2700
  */
2644
2701
  getVariableOutputs() {
2645
2702
  return this.outputs.filter(
2646
- (output) => output.type === import_transactions10.OutputType.Variable
2703
+ (output) => output.type === import_transactions9.OutputType.Variable
2647
2704
  );
2648
2705
  }
2649
2706
  /**
@@ -2666,7 +2723,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2666
2723
  let outputsNumber = numberOfVariables;
2667
2724
  while (outputsNumber) {
2668
2725
  this.pushOutput({
2669
- type: import_transactions10.OutputType.Variable
2726
+ type: import_transactions9.OutputType.Variable
2670
2727
  });
2671
2728
  outputsNumber -= 1;
2672
2729
  }
@@ -2674,7 +2731,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2674
2731
  }
2675
2732
  calculateMaxGas(chainInfo, minGas) {
2676
2733
  const { consensusParameters } = chainInfo;
2677
- const { gasPerByte } = consensusParameters;
2734
+ const { gasPerByte, maxGasPerTx } = consensusParameters;
2678
2735
  const witnessesLength = this.toTransaction().witnesses.reduce(
2679
2736
  (acc, wit) => acc + wit.dataLength,
2680
2737
  0
@@ -2684,7 +2741,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2684
2741
  minGas,
2685
2742
  witnessesLength,
2686
2743
  witnessLimit: this.witnessLimit,
2687
- gasLimit: this.gasLimit
2744
+ gasLimit: this.gasLimit,
2745
+ maxGasPerTx
2688
2746
  });
2689
2747
  }
2690
2748
  /**
@@ -2699,12 +2757,12 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2699
2757
  return this;
2700
2758
  }
2701
2759
  const inputIndex = super.pushInput({
2702
- type: import_transactions10.InputType.Contract,
2760
+ type: import_transactions9.InputType.Contract,
2703
2761
  contractId: contractAddress.toB256(),
2704
2762
  txPointer: "0x00000000000000000000000000000000"
2705
2763
  });
2706
2764
  this.pushOutput({
2707
- type: import_transactions10.OutputType.Contract,
2765
+ type: import_transactions9.OutputType.Contract,
2708
2766
  inputIndex
2709
2767
  });
2710
2768
  return this;
@@ -2741,17 +2799,17 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2741
2799
 
2742
2800
  // src/providers/transaction-request/utils.ts
2743
2801
  var import_errors9 = require("@fuel-ts/errors");
2744
- var import_transactions11 = require("@fuel-ts/transactions");
2802
+ var import_transactions10 = require("@fuel-ts/transactions");
2745
2803
  var transactionRequestify = (obj) => {
2746
2804
  if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
2747
2805
  return obj;
2748
2806
  }
2749
2807
  const { type } = obj;
2750
2808
  switch (obj.type) {
2751
- case import_transactions11.TransactionType.Script: {
2809
+ case import_transactions10.TransactionType.Script: {
2752
2810
  return ScriptTransactionRequest.from(obj);
2753
2811
  }
2754
- case import_transactions11.TransactionType.Create: {
2812
+ case import_transactions10.TransactionType.Create: {
2755
2813
  return CreateTransactionRequest.from(obj);
2756
2814
  }
2757
2815
  default: {
@@ -2759,42 +2817,59 @@ var transactionRequestify = (obj) => {
2759
2817
  }
2760
2818
  }
2761
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
+ );
2762
2835
 
2763
2836
  // src/providers/transaction-response/transaction-response.ts
2764
2837
  var import_errors13 = require("@fuel-ts/errors");
2765
- var import_math14 = require("@fuel-ts/math");
2838
+ var import_math15 = require("@fuel-ts/math");
2766
2839
  var import_transactions18 = require("@fuel-ts/transactions");
2767
- var import_utils21 = require("@fuel-ts/utils");
2840
+ var import_utils20 = require("@fuel-ts/utils");
2768
2841
 
2769
2842
  // src/providers/transaction-summary/assemble-transaction-summary.ts
2770
- 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");
2771
2846
 
2772
2847
  // src/providers/transaction-summary/calculate-transaction-fee.ts
2773
2848
  var import_math11 = require("@fuel-ts/math");
2774
- var import_transactions12 = require("@fuel-ts/transactions");
2849
+ var import_transactions11 = require("@fuel-ts/transactions");
2775
2850
  var import_utils16 = require("@fuel-ts/utils");
2776
2851
  var calculateTransactionFee = (params) => {
2777
2852
  const {
2778
- gasUsed,
2853
+ gasPrice,
2779
2854
  rawPayload,
2780
- consensusParameters: { gasCosts, feeParams }
2855
+ tip,
2856
+ consensusParameters: { gasCosts, feeParams, maxGasPerTx }
2781
2857
  } = params;
2782
2858
  const gasPerByte = (0, import_math11.bn)(feeParams.gasPerByte);
2783
2859
  const gasPriceFactor = (0, import_math11.bn)(feeParams.gasPriceFactor);
2784
2860
  const transactionBytes = (0, import_utils16.arrayify)(rawPayload);
2785
- const [transaction] = new import_transactions12.TransactionCoder().decode(transactionBytes, 0);
2786
- if (transaction.type === import_transactions12.TransactionType.Mint) {
2861
+ const [transaction] = new import_transactions11.TransactionCoder().decode(transactionBytes, 0);
2862
+ if (transaction.type === import_transactions11.TransactionType.Mint) {
2787
2863
  return {
2788
2864
  fee: (0, import_math11.bn)(0),
2789
2865
  minFee: (0, import_math11.bn)(0),
2790
- maxFee: (0, import_math11.bn)(0),
2791
- feeFromGasUsed: (0, import_math11.bn)(0)
2866
+ maxFee: (0, import_math11.bn)(0)
2792
2867
  };
2793
2868
  }
2794
2869
  const { type, witnesses, inputs, policies } = transaction;
2795
2870
  let metadataGas = (0, import_math11.bn)(0);
2796
2871
  let gasLimit = (0, import_math11.bn)(0);
2797
- if (type === import_transactions12.TransactionType.Create) {
2872
+ if (type === import_transactions11.TransactionType.Create) {
2798
2873
  const { bytecodeWitnessIndex, storageSlots } = transaction;
2799
2874
  const contractBytesSize = (0, import_math11.bn)((0, import_utils16.arrayify)(witnesses[bytecodeWitnessIndex].data).length);
2800
2875
  metadataGas = calculateMetadataGasForTxCreate({
@@ -2820,25 +2895,32 @@ var calculateTransactionFee = (params) => {
2820
2895
  metadataGas,
2821
2896
  txBytesSize: transactionBytes.length
2822
2897
  });
2823
- const gasPrice = (0, import_math11.bn)(policies.find((policy) => policy.type === import_transactions12.PolicyType.GasPrice)?.data);
2824
- const witnessLimit = policies.find((policy) => policy.type === import_transactions12.PolicyType.WitnessLimit)?.data;
2898
+ const witnessLimit = policies.find((policy) => policy.type === import_transactions11.PolicyType.WitnessLimit)?.data;
2825
2899
  const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
2826
2900
  const maxGas = getMaxGas({
2827
2901
  gasPerByte,
2828
2902
  minGas,
2829
2903
  witnessesLength,
2830
2904
  gasLimit,
2831
- 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
2832
2919
  });
2833
- const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
2834
- const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
2835
- const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
2836
- const fee = minFee.add(feeFromGasUsed);
2837
2920
  return {
2838
- fee,
2839
2921
  minFee,
2840
2922
  maxFee,
2841
- feeFromGasUsed
2923
+ fee: maxFee
2842
2924
  };
2843
2925
  };
2844
2926
 
@@ -2846,7 +2928,7 @@ var calculateTransactionFee = (params) => {
2846
2928
  var import_configs11 = require("@fuel-ts/address/configs");
2847
2929
  var import_errors11 = require("@fuel-ts/errors");
2848
2930
  var import_math13 = require("@fuel-ts/math");
2849
- var import_transactions15 = require("@fuel-ts/transactions");
2931
+ var import_transactions14 = require("@fuel-ts/transactions");
2850
2932
 
2851
2933
  // src/providers/transaction-summary/call.ts
2852
2934
  var import_abi_coder4 = require("@fuel-ts/abi-coder");
@@ -2894,7 +2976,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
2894
2976
 
2895
2977
  // src/providers/transaction-summary/input.ts
2896
2978
  var import_errors10 = require("@fuel-ts/errors");
2897
- var import_transactions13 = require("@fuel-ts/transactions");
2979
+ var import_transactions12 = require("@fuel-ts/transactions");
2898
2980
  function getInputsByTypes(inputs, types) {
2899
2981
  return inputs.filter((i) => types.includes(i.type));
2900
2982
  }
@@ -2902,16 +2984,16 @@ function getInputsByType(inputs, type) {
2902
2984
  return inputs.filter((i) => i.type === type);
2903
2985
  }
2904
2986
  function getInputsCoin(inputs) {
2905
- return getInputsByType(inputs, import_transactions13.InputType.Coin);
2987
+ return getInputsByType(inputs, import_transactions12.InputType.Coin);
2906
2988
  }
2907
2989
  function getInputsMessage(inputs) {
2908
- return getInputsByType(inputs, import_transactions13.InputType.Message);
2990
+ return getInputsByType(inputs, import_transactions12.InputType.Message);
2909
2991
  }
2910
2992
  function getInputsCoinAndMessage(inputs) {
2911
- return getInputsByTypes(inputs, [import_transactions13.InputType.Coin, import_transactions13.InputType.Message]);
2993
+ return getInputsByTypes(inputs, [import_transactions12.InputType.Coin, import_transactions12.InputType.Message]);
2912
2994
  }
2913
2995
  function getInputsContract(inputs) {
2914
- return getInputsByType(inputs, import_transactions13.InputType.Contract);
2996
+ return getInputsByType(inputs, import_transactions12.InputType.Contract);
2915
2997
  }
2916
2998
  function getInputFromAssetId(inputs, assetId) {
2917
2999
  const coinInputs = getInputsCoin(inputs);
@@ -2930,7 +3012,7 @@ function getInputContractFromIndex(inputs, inputIndex) {
2930
3012
  if (!contractInput) {
2931
3013
  return void 0;
2932
3014
  }
2933
- if (contractInput.type !== import_transactions13.InputType.Contract) {
3015
+ if (contractInput.type !== import_transactions12.InputType.Contract) {
2934
3016
  throw new import_errors10.FuelError(
2935
3017
  import_errors10.ErrorCode.INVALID_TRANSACTION_INPUT,
2936
3018
  `Contract input should be of type 'contract'.`
@@ -2939,34 +3021,34 @@ function getInputContractFromIndex(inputs, inputIndex) {
2939
3021
  return contractInput;
2940
3022
  }
2941
3023
  function getInputAccountAddress(input) {
2942
- if (input.type === import_transactions13.InputType.Coin) {
3024
+ if (input.type === import_transactions12.InputType.Coin) {
2943
3025
  return input.owner.toString();
2944
3026
  }
2945
- if (input.type === import_transactions13.InputType.Message) {
3027
+ if (input.type === import_transactions12.InputType.Message) {
2946
3028
  return input.recipient.toString();
2947
3029
  }
2948
3030
  return "";
2949
3031
  }
2950
3032
 
2951
3033
  // src/providers/transaction-summary/output.ts
2952
- var import_transactions14 = require("@fuel-ts/transactions");
3034
+ var import_transactions13 = require("@fuel-ts/transactions");
2953
3035
  function getOutputsByType(outputs, type) {
2954
3036
  return outputs.filter((o) => o.type === type);
2955
3037
  }
2956
3038
  function getOutputsContractCreated(outputs) {
2957
- return getOutputsByType(outputs, import_transactions14.OutputType.ContractCreated);
3039
+ return getOutputsByType(outputs, import_transactions13.OutputType.ContractCreated);
2958
3040
  }
2959
3041
  function getOutputsCoin(outputs) {
2960
- return getOutputsByType(outputs, import_transactions14.OutputType.Coin);
3042
+ return getOutputsByType(outputs, import_transactions13.OutputType.Coin);
2961
3043
  }
2962
3044
  function getOutputsChange(outputs) {
2963
- return getOutputsByType(outputs, import_transactions14.OutputType.Change);
3045
+ return getOutputsByType(outputs, import_transactions13.OutputType.Change);
2964
3046
  }
2965
3047
  function getOutputsContract(outputs) {
2966
- return getOutputsByType(outputs, import_transactions14.OutputType.Contract);
3048
+ return getOutputsByType(outputs, import_transactions13.OutputType.Contract);
2967
3049
  }
2968
3050
  function getOutputsVariable(outputs) {
2969
- return getOutputsByType(outputs, import_transactions14.OutputType.Variable);
3051
+ return getOutputsByType(outputs, import_transactions13.OutputType.Variable);
2970
3052
  }
2971
3053
 
2972
3054
  // src/providers/transaction-summary/types.ts
@@ -3013,11 +3095,11 @@ function getReceiptsByType(receipts, type) {
3013
3095
  }
3014
3096
  function getTransactionTypeName(transactionType) {
3015
3097
  switch (transactionType) {
3016
- case import_transactions15.TransactionType.Mint:
3098
+ case import_transactions14.TransactionType.Mint:
3017
3099
  return "Mint" /* Mint */;
3018
- case import_transactions15.TransactionType.Create:
3100
+ case import_transactions14.TransactionType.Create:
3019
3101
  return "Create" /* Create */;
3020
- case import_transactions15.TransactionType.Script:
3102
+ case import_transactions14.TransactionType.Script:
3021
3103
  return "Script" /* Script */;
3022
3104
  default:
3023
3105
  throw new import_errors11.FuelError(
@@ -3043,10 +3125,10 @@ function hasSameAssetId(a) {
3043
3125
  return (b) => a.assetId === b.assetId;
3044
3126
  }
3045
3127
  function getReceiptsCall(receipts) {
3046
- return getReceiptsByType(receipts, import_transactions15.ReceiptType.Call);
3128
+ return getReceiptsByType(receipts, import_transactions14.ReceiptType.Call);
3047
3129
  }
3048
3130
  function getReceiptsMessageOut(receipts) {
3049
- return getReceiptsByType(receipts, import_transactions15.ReceiptType.MessageOut);
3131
+ return getReceiptsByType(receipts, import_transactions14.ReceiptType.MessageOut);
3050
3132
  }
3051
3133
  var mergeAssets = (op1, op2) => {
3052
3134
  const assets1 = op1.assetsSent || [];
@@ -3085,7 +3167,7 @@ function addOperation(operations, toAdd) {
3085
3167
  return allOperations;
3086
3168
  }
3087
3169
  function getReceiptsTransferOut(receipts) {
3088
- return getReceiptsByType(receipts, import_transactions15.ReceiptType.TransferOut);
3170
+ return getReceiptsByType(receipts, import_transactions14.ReceiptType.TransferOut);
3089
3171
  }
3090
3172
  function getWithdrawFromFuelOperations({
3091
3173
  inputs,
@@ -3245,11 +3327,11 @@ function getTransferOperations({
3245
3327
  });
3246
3328
  const transferReceipts = getReceiptsByType(
3247
3329
  receipts,
3248
- import_transactions15.ReceiptType.Transfer
3330
+ import_transactions14.ReceiptType.Transfer
3249
3331
  );
3250
3332
  const transferOutReceipts = getReceiptsByType(
3251
3333
  receipts,
3252
- import_transactions15.ReceiptType.TransferOut
3334
+ import_transactions14.ReceiptType.TransferOut
3253
3335
  );
3254
3336
  [...transferReceipts, ...transferOutReceipts].forEach((receipt) => {
3255
3337
  const operation = extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs);
@@ -3334,17 +3416,17 @@ function getOperations({
3334
3416
  }
3335
3417
 
3336
3418
  // src/providers/transaction-summary/receipt.ts
3337
- var import_transactions16 = require("@fuel-ts/transactions");
3419
+ var import_transactions15 = require("@fuel-ts/transactions");
3338
3420
  var processGqlReceipt = (gqlReceipt) => {
3339
3421
  const receipt = assembleReceiptByType(gqlReceipt);
3340
3422
  switch (receipt.type) {
3341
- case import_transactions16.ReceiptType.ReturnData: {
3423
+ case import_transactions15.ReceiptType.ReturnData: {
3342
3424
  return {
3343
3425
  ...receipt,
3344
3426
  data: gqlReceipt.data || "0x"
3345
3427
  };
3346
3428
  }
3347
- case import_transactions16.ReceiptType.LogData: {
3429
+ case import_transactions15.ReceiptType.LogData: {
3348
3430
  return {
3349
3431
  ...receipt,
3350
3432
  data: gqlReceipt.data || "0x"
@@ -3357,7 +3439,7 @@ var processGqlReceipt = (gqlReceipt) => {
3357
3439
  var extractMintedAssetsFromReceipts = (receipts) => {
3358
3440
  const mintedAssets = [];
3359
3441
  receipts.forEach((receipt) => {
3360
- if (receipt.type === import_transactions16.ReceiptType.Mint) {
3442
+ if (receipt.type === import_transactions15.ReceiptType.Mint) {
3361
3443
  mintedAssets.push({
3362
3444
  subId: receipt.subId,
3363
3445
  contractId: receipt.contractId,
@@ -3371,7 +3453,7 @@ var extractMintedAssetsFromReceipts = (receipts) => {
3371
3453
  var extractBurnedAssetsFromReceipts = (receipts) => {
3372
3454
  const burnedAssets = [];
3373
3455
  receipts.forEach((receipt) => {
3374
- if (receipt.type === import_transactions16.ReceiptType.Burn) {
3456
+ if (receipt.type === import_transactions15.ReceiptType.Burn) {
3375
3457
  burnedAssets.push({
3376
3458
  subId: receipt.subId,
3377
3459
  contractId: receipt.contractId,
@@ -3452,10 +3534,12 @@ function assembleTransactionSummary(params) {
3452
3534
  gqlTransactionStatus,
3453
3535
  abiMap = {},
3454
3536
  maxInputs,
3455
- gasCosts
3537
+ gasCosts,
3538
+ maxGasPerTx,
3539
+ gasPrice
3456
3540
  } = params;
3457
3541
  const gasUsed = getGasUsedFromReceipts(receipts);
3458
- const rawPayload = (0, import_utils19.hexlify)(transactionBytes);
3542
+ const rawPayload = (0, import_utils18.hexlify)(transactionBytes);
3459
3543
  const operations = getOperations({
3460
3544
  transactionType: transaction.type,
3461
3545
  inputs: transaction.inputs || [],
@@ -3466,11 +3550,14 @@ function assembleTransactionSummary(params) {
3466
3550
  maxInputs
3467
3551
  });
3468
3552
  const typeName = getTransactionTypeName(transaction.type);
3553
+ const tip = (0, import_math14.bn)(transaction.policies?.find((policy) => policy.type === import_transactions16.PolicyType.Tip)?.data);
3469
3554
  const { fee } = calculateTransactionFee({
3470
- gasUsed,
3555
+ gasPrice,
3471
3556
  rawPayload,
3557
+ tip,
3472
3558
  consensusParameters: {
3473
3559
  gasCosts,
3560
+ maxGasPerTx,
3474
3561
  feeParams: {
3475
3562
  gasPerByte,
3476
3563
  gasPriceFactor
@@ -3482,7 +3569,7 @@ function assembleTransactionSummary(params) {
3482
3569
  const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
3483
3570
  let date;
3484
3571
  if (time) {
3485
- date = import_utils19.DateTime.fromTai64(time);
3572
+ date = import_utils18.DateTime.fromTai64(time);
3486
3573
  }
3487
3574
  const transactionSummary = {
3488
3575
  id,
@@ -3530,7 +3617,7 @@ var TransactionResponse = class {
3530
3617
  /** Current provider */
3531
3618
  provider;
3532
3619
  /** Gas used on the transaction */
3533
- gasUsed = (0, import_math14.bn)(0);
3620
+ gasUsed = (0, import_math15.bn)(0);
3534
3621
  /** The graphql Transaction with receipts object. */
3535
3622
  gqlTransaction;
3536
3623
  abis;
@@ -3589,7 +3676,7 @@ var TransactionResponse = class {
3589
3676
  */
3590
3677
  decodeTransaction(transactionWithReceipts) {
3591
3678
  return new import_transactions18.TransactionCoder().decode(
3592
- (0, import_utils21.arrayify)(transactionWithReceipts.rawPayload),
3679
+ (0, import_utils20.arrayify)(transactionWithReceipts.rawPayload),
3593
3680
  0
3594
3681
  )?.[0];
3595
3682
  }
@@ -3608,20 +3695,27 @@ var TransactionResponse = class {
3608
3695
  const decodedTransaction = this.decodeTransaction(
3609
3696
  transaction
3610
3697
  );
3611
- const receipts = transaction.receipts?.map(processGqlReceipt) || [];
3612
- 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();
3613
3705
  const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
3614
3706
  const transactionSummary = assembleTransactionSummary({
3615
3707
  id: this.id,
3616
3708
  receipts,
3617
3709
  transaction: decodedTransaction,
3618
- transactionBytes: (0, import_utils21.arrayify)(transaction.rawPayload),
3710
+ transactionBytes: (0, import_utils20.arrayify)(transaction.rawPayload),
3619
3711
  gqlTransactionStatus: transaction.status,
3620
3712
  gasPerByte,
3621
3713
  gasPriceFactor,
3622
3714
  abiMap: contractsAbiMap,
3623
3715
  maxInputs,
3624
- gasCosts
3716
+ gasCosts,
3717
+ maxGasPerTx,
3718
+ gasPrice
3625
3719
  });
3626
3720
  return transactionSummary;
3627
3721
  }
@@ -3748,29 +3842,29 @@ var processGqlChain = (chain) => {
3748
3842
  const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
3749
3843
  return {
3750
3844
  name,
3751
- baseChainHeight: (0, import_math15.bn)(daHeight),
3845
+ baseChainHeight: (0, import_math16.bn)(daHeight),
3752
3846
  consensusParameters: {
3753
- contractMaxSize: (0, import_math15.bn)(contractParams.contractMaxSize),
3754
- maxInputs: (0, import_math15.bn)(txParams.maxInputs),
3755
- maxOutputs: (0, import_math15.bn)(txParams.maxOutputs),
3756
- maxWitnesses: (0, import_math15.bn)(txParams.maxWitnesses),
3757
- maxGasPerTx: (0, import_math15.bn)(txParams.maxGasPerTx),
3758
- maxScriptLength: (0, import_math15.bn)(scriptParams.maxScriptLength),
3759
- maxScriptDataLength: (0, import_math15.bn)(scriptParams.maxScriptDataLength),
3760
- maxStorageSlots: (0, import_math15.bn)(contractParams.maxStorageSlots),
3761
- maxPredicateLength: (0, import_math15.bn)(predicateParams.maxPredicateLength),
3762
- maxPredicateDataLength: (0, import_math15.bn)(predicateParams.maxPredicateDataLength),
3763
- maxGasPerPredicate: (0, import_math15.bn)(predicateParams.maxGasPerPredicate),
3764
- gasPriceFactor: (0, import_math15.bn)(feeParams.gasPriceFactor),
3765
- gasPerByte: (0, import_math15.bn)(feeParams.gasPerByte),
3766
- maxMessageDataLength: (0, import_math15.bn)(predicateParams.maxMessageDataLength),
3767
- 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),
3768
3862
  gasCosts
3769
3863
  },
3770
3864
  gasCosts,
3771
3865
  latestBlock: {
3772
3866
  id: latestBlock.id,
3773
- height: (0, import_math15.bn)(latestBlock.header.height),
3867
+ height: (0, import_math16.bn)(latestBlock.height),
3774
3868
  time: latestBlock.header.time,
3775
3869
  transactions: latestBlock.transactions.map((i) => ({
3776
3870
  id: i.id
@@ -3864,10 +3958,8 @@ var _Provider = class {
3864
3958
  * Returns some helpful parameters related to gas fees.
3865
3959
  */
3866
3960
  getGasConfig() {
3867
- const { minGasPrice } = this.getNode();
3868
3961
  const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
3869
3962
  return {
3870
- minGasPrice,
3871
3963
  maxGasPerTx,
3872
3964
  maxGasPerPredicate,
3873
3965
  gasPriceFactor,
@@ -3965,7 +4057,7 @@ var _Provider = class {
3965
4057
  */
3966
4058
  async getBlockNumber() {
3967
4059
  const { chain } = await this.operations.getChain();
3968
- return (0, import_math15.bn)(chain.latestBlock.header.height, 10);
4060
+ return (0, import_math16.bn)(chain.latestBlock.height, 10);
3969
4061
  }
3970
4062
  /**
3971
4063
  * Returns the chain information.
@@ -3975,13 +4067,11 @@ var _Provider = class {
3975
4067
  async fetchNode() {
3976
4068
  const { nodeInfo } = await this.operations.getNodeInfo();
3977
4069
  const processedNodeInfo = {
3978
- maxDepth: (0, import_math15.bn)(nodeInfo.maxDepth),
3979
- maxTx: (0, import_math15.bn)(nodeInfo.maxTx),
3980
- minGasPrice: (0, import_math15.bn)(nodeInfo.minGasPrice),
4070
+ maxDepth: (0, import_math16.bn)(nodeInfo.maxDepth),
4071
+ maxTx: (0, import_math16.bn)(nodeInfo.maxTx),
3981
4072
  nodeVersion: nodeInfo.nodeVersion,
3982
4073
  utxoValidation: nodeInfo.utxoValidation,
3983
- vmBacktrace: nodeInfo.vmBacktrace,
3984
- peers: nodeInfo.peers
4074
+ vmBacktrace: nodeInfo.vmBacktrace
3985
4075
  };
3986
4076
  _Provider.nodeInfoCache[this.url] = processedNodeInfo;
3987
4077
  return processedNodeInfo;
@@ -4023,7 +4113,7 @@ var _Provider = class {
4023
4113
  if (estimateTxDependencies) {
4024
4114
  await this.estimateTxDependencies(transactionRequest);
4025
4115
  }
4026
- const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
4116
+ const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
4027
4117
  let abis;
4028
4118
  if (transactionRequest.type === import_transactions19.TransactionType.Script) {
4029
4119
  abis = transactionRequest.abis;
@@ -4066,15 +4156,14 @@ var _Provider = class {
4066
4156
  if (estimateTxDependencies) {
4067
4157
  return this.estimateTxDependencies(transactionRequest);
4068
4158
  }
4069
- const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
4070
- const { dryRun: gqlReceipts } = await this.operations.dryRun({
4071
- encodedTransaction,
4159
+ const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
4160
+ const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4161
+ encodedTransactions: encodedTransaction,
4072
4162
  utxoValidation: utxoValidation || false
4073
4163
  });
4074
- const receipts = gqlReceipts.map(processGqlReceipt);
4075
- return {
4076
- receipts
4077
- };
4164
+ const [{ receipts: rawReceipts, status }] = dryRunStatuses;
4165
+ const receipts = rawReceipts.map(processGqlReceipt);
4166
+ return { receipts, dryrunStatus: status };
4078
4167
  }
4079
4168
  /**
4080
4169
  * Verifies whether enough gas is available to complete transaction.
@@ -4085,13 +4174,13 @@ var _Provider = class {
4085
4174
  async estimatePredicates(transactionRequest) {
4086
4175
  const shouldEstimatePredicates = Boolean(
4087
4176
  transactionRequest.inputs.find(
4088
- (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()
4089
4178
  )
4090
4179
  );
4091
4180
  if (!shouldEstimatePredicates) {
4092
4181
  return transactionRequest;
4093
4182
  }
4094
- const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
4183
+ const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
4095
4184
  const response = await this.operations.estimatePredicates({
4096
4185
  encodedTransaction
4097
4186
  });
@@ -4100,7 +4189,7 @@ var _Provider = class {
4100
4189
  } = response;
4101
4190
  if (inputs) {
4102
4191
  inputs.forEach((input, index) => {
4103
- 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)) {
4104
4193
  transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
4105
4194
  }
4106
4195
  });
@@ -4113,9 +4202,6 @@ var _Provider = class {
4113
4202
  * If there are missing variable outputs,
4114
4203
  * `addVariableOutputs` is called on the transaction.
4115
4204
  *
4116
- * @privateRemarks
4117
- * TODO: Investigate support for missing contract IDs
4118
- * TODO: Add support for missing output messages
4119
4205
  *
4120
4206
  * @param transactionRequest - The transaction request object.
4121
4207
  * @returns A promise.
@@ -4128,16 +4214,19 @@ var _Provider = class {
4128
4214
  missingContractIds: []
4129
4215
  };
4130
4216
  }
4131
- await this.estimatePredicates(transactionRequest);
4132
4217
  let receipts = [];
4133
4218
  const missingContractIds = [];
4134
4219
  let outputVariables = 0;
4220
+ let dryrunStatus;
4135
4221
  for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
4136
- const { dryRun: gqlReceipts } = await this.operations.dryRun({
4137
- 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())],
4138
4226
  utxoValidation: false
4139
4227
  });
4140
- receipts = gqlReceipts.map(processGqlReceipt);
4228
+ receipts = rawReceipts.map(processGqlReceipt);
4229
+ dryrunStatus = status;
4141
4230
  const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
4142
4231
  const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
4143
4232
  if (hasMissingOutputs) {
@@ -4147,6 +4236,10 @@ var _Provider = class {
4147
4236
  transactionRequest.addContractInputAndOutput(import_address3.Address.fromString(contractId));
4148
4237
  missingContractIds.push(contractId);
4149
4238
  });
4239
+ const { maxFee } = await this.estimateTxGasAndFee({
4240
+ transactionRequest
4241
+ });
4242
+ transactionRequest.maxFee = maxFee;
4150
4243
  } else {
4151
4244
  break;
4152
4245
  }
@@ -4154,37 +4247,139 @@ var _Provider = class {
4154
4247
  return {
4155
4248
  receipts,
4156
4249
  outputVariables,
4157
- missingContractIds
4250
+ missingContractIds,
4251
+ dryrunStatus
4158
4252
  };
4159
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
+ }
4160
4338
  /**
4161
4339
  * Estimates the transaction gas and fee based on the provided transaction request.
4162
4340
  * @param transactionRequest - The transaction request object.
4163
4341
  * @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
4164
4342
  */
4165
- estimateTxGasAndFee(params) {
4343
+ async estimateTxGasAndFee(params) {
4166
4344
  const { transactionRequest } = params;
4167
- const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
4345
+ let { gasPrice } = params;
4168
4346
  const chainInfo = this.getChain();
4169
- const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
4170
- transactionRequest.gasPrice = gasPrice;
4347
+ const { gasPriceFactor, maxGasPerTx } = this.getGasConfig();
4171
4348
  const minGas = transactionRequest.calculateMinGas(chainInfo);
4172
- const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
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);
4173
4359
  if (transactionRequest.type === import_transactions19.TransactionType.Script) {
4360
+ gasLimit = transactionRequest.gasLimit;
4174
4361
  if (transactionRequest.gasLimit.eq(0)) {
4175
4362
  transactionRequest.gasLimit = minGas;
4176
4363
  transactionRequest.gasLimit = maxGasPerTx.sub(
4177
4364
  transactionRequest.calculateMaxGas(chainInfo, minGas)
4178
4365
  );
4366
+ gasLimit = transactionRequest.gasLimit;
4179
4367
  }
4180
4368
  }
4181
4369
  const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
4182
- 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);
4183
4376
  return {
4184
4377
  minGas,
4185
4378
  minFee,
4186
4379
  maxGas,
4187
- maxFee
4380
+ maxFee,
4381
+ gasPrice,
4382
+ gasLimit
4188
4383
  };
4189
4384
  }
4190
4385
  /**
@@ -4202,15 +4397,17 @@ var _Provider = class {
4202
4397
  if (estimateTxDependencies) {
4203
4398
  return this.estimateTxDependencies(transactionRequest);
4204
4399
  }
4205
- const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
4206
- const { dryRun: gqlReceipts } = await this.operations.dryRun({
4207
- encodedTransaction,
4400
+ const encodedTransactions = [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())];
4401
+ const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4402
+ encodedTransactions,
4208
4403
  utxoValidation: true
4209
4404
  });
4210
- const receipts = gqlReceipts.map(processGqlReceipt);
4211
- return {
4212
- receipts
4213
- };
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 };
4214
4411
  }
4215
4412
  /**
4216
4413
  * Returns a transaction cost to enable user
@@ -4227,77 +4424,79 @@ var _Provider = class {
4227
4424
  * @param tolerance - The tolerance to add on top of the gasUsed.
4228
4425
  * @returns A promise that resolves to the transaction cost object.
4229
4426
  */
4230
- async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
4231
- estimateTxDependencies = true,
4232
- estimatePredicates = true,
4233
- resourcesOwner,
4234
- signatureCallback
4235
- } = {}) {
4427
+ async getTransactionCost(transactionRequestLike, { resourcesOwner, signatureCallback, quantitiesToContract = [] } = {}) {
4236
4428
  const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
4237
- const { minGasPrice } = this.getGasConfig();
4238
- const setGasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
4239
4429
  const isScriptTransaction = txRequestClone.type === import_transactions19.TransactionType.Script;
4240
4430
  const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
4241
- const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
4431
+ const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
4242
4432
  txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
4433
+ txRequestClone.maxFee = (0, import_math16.bn)(0);
4243
4434
  if (isScriptTransaction) {
4244
- txRequestClone.gasLimit = (0, import_math15.bn)(0);
4435
+ txRequestClone.gasLimit = (0, import_math16.bn)(0);
4245
4436
  }
4246
- if (estimatePredicates) {
4247
- if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
4248
- resourcesOwner.populateTransactionPredicateData(txRequestClone);
4249
- }
4250
- await this.estimatePredicates(txRequestClone);
4437
+ if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
4438
+ resourcesOwner.populateTransactionPredicateData(txRequestClone);
4251
4439
  }
4440
+ const signedRequest = (0, import_ramda3.clone)(txRequestClone);
4441
+ let addedSignatures = 0;
4252
4442
  if (signatureCallback && isScriptTransaction) {
4253
- await signatureCallback(txRequestClone);
4443
+ const lengthBefore = signedRequest.witnesses.length;
4444
+ await signatureCallback(signedRequest);
4445
+ addedSignatures = signedRequest.witnesses.length - lengthBefore;
4254
4446
  }
4255
- let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
4256
- transactionRequest: txRequestClone
4447
+ await this.estimatePredicates(signedRequest);
4448
+ let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
4449
+ transactionRequest: signedRequest
4257
4450
  });
4258
4451
  let receipts = [];
4259
4452
  let missingContractIds = [];
4260
4453
  let outputVariables = 0;
4261
- let gasUsed = (0, import_math15.bn)(0);
4262
- if (isScriptTransaction && estimateTxDependencies) {
4263
- 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
+ }
4264
4462
  const result = await this.estimateTxDependencies(txRequestClone);
4265
4463
  receipts = result.receipts;
4266
4464
  outputVariables = result.outputVariables;
4267
4465
  missingContractIds = result.missingContractIds;
4268
4466
  gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
4269
4467
  txRequestClone.gasLimit = gasUsed;
4270
- txRequestClone.gasPrice = setGasPrice;
4271
- ({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
4272
- transactionRequest: txRequestClone
4468
+ ({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
4469
+ transactionRequest: txRequestClone,
4470
+ gasPrice
4273
4471
  }));
4274
4472
  }
4275
4473
  return {
4276
4474
  requiredQuantities: allQuantities,
4277
4475
  receipts,
4278
4476
  gasUsed,
4279
- minGasPrice,
4280
- gasPrice: setGasPrice,
4477
+ gasPrice,
4281
4478
  minGas,
4282
4479
  maxGas,
4283
4480
  minFee,
4284
4481
  maxFee,
4285
- estimatedInputs: txRequestClone.inputs,
4286
4482
  outputVariables,
4287
- missingContractIds
4483
+ missingContractIds,
4484
+ addedSignatures,
4485
+ estimatedPredicates: txRequestClone.inputs
4288
4486
  };
4289
4487
  }
4290
- async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
4488
+ async getResourcesForTransaction(owner, transactionRequestLike, quantitiesToContract = []) {
4291
4489
  const ownerAddress = import_address3.Address.fromAddressOrString(owner);
4292
4490
  const transactionRequest = transactionRequestify((0, import_ramda3.clone)(transactionRequestLike));
4293
- const transactionCost = await this.getTransactionCost(transactionRequest, forwardingQuantities);
4491
+ const transactionCost = await this.getTransactionCost(transactionRequest, {
4492
+ quantitiesToContract
4493
+ });
4294
4494
  transactionRequest.addResources(
4295
4495
  await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
4296
4496
  );
4297
- const { requiredQuantities, ...txCost } = await this.getTransactionCost(
4298
- transactionRequest,
4299
- forwardingQuantities
4300
- );
4497
+ const { requiredQuantities, ...txCost } = await this.getTransactionCost(transactionRequest, {
4498
+ quantitiesToContract
4499
+ });
4301
4500
  const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
4302
4501
  return {
4303
4502
  resources,
@@ -4313,17 +4512,16 @@ var _Provider = class {
4313
4512
  const result = await this.operations.getCoins({
4314
4513
  first: 10,
4315
4514
  ...paginationArgs,
4316
- filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils23.hexlify)(assetId) }
4515
+ filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils22.hexlify)(assetId) }
4317
4516
  });
4318
4517
  const coins = result.coins.edges.map((edge) => edge.node);
4319
4518
  return coins.map((coin) => ({
4320
4519
  id: coin.utxoId,
4321
4520
  assetId: coin.assetId,
4322
- amount: (0, import_math15.bn)(coin.amount),
4521
+ amount: (0, import_math16.bn)(coin.amount),
4323
4522
  owner: import_address3.Address.fromAddressOrString(coin.owner),
4324
- maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
4325
- blockCreated: (0, import_math15.bn)(coin.blockCreated),
4326
- txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
4523
+ blockCreated: (0, import_math16.bn)(coin.blockCreated),
4524
+ txCreatedIdx: (0, import_math16.bn)(coin.txCreatedIdx)
4327
4525
  }));
4328
4526
  }
4329
4527
  /**
@@ -4337,19 +4535,19 @@ var _Provider = class {
4337
4535
  async getResourcesToSpend(owner, quantities, excludedIds) {
4338
4536
  const ownerAddress = import_address3.Address.fromAddressOrString(owner);
4339
4537
  const excludeInput = {
4340
- messages: excludedIds?.messages?.map((nonce) => (0, import_utils23.hexlify)(nonce)) || [],
4341
- 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)) || []
4342
4540
  };
4343
4541
  if (this.cache) {
4344
4542
  const uniqueUtxos = new Set(
4345
- 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)))
4346
4544
  );
4347
4545
  excludeInput.utxos = Array.from(uniqueUtxos);
4348
4546
  }
4349
4547
  const coinsQuery = {
4350
4548
  owner: ownerAddress.toB256(),
4351
4549
  queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
4352
- assetId: (0, import_utils23.hexlify)(assetId),
4550
+ assetId: (0, import_utils22.hexlify)(assetId),
4353
4551
  amount: amount.toString(10),
4354
4552
  max: maxPerAsset ? maxPerAsset.toString(10) : void 0
4355
4553
  })),
@@ -4360,9 +4558,9 @@ var _Provider = class {
4360
4558
  switch (coin.__typename) {
4361
4559
  case "MessageCoin":
4362
4560
  return {
4363
- amount: (0, import_math15.bn)(coin.amount),
4561
+ amount: (0, import_math16.bn)(coin.amount),
4364
4562
  assetId: coin.assetId,
4365
- daHeight: (0, import_math15.bn)(coin.daHeight),
4563
+ daHeight: (0, import_math16.bn)(coin.daHeight),
4366
4564
  sender: import_address3.Address.fromAddressOrString(coin.sender),
4367
4565
  recipient: import_address3.Address.fromAddressOrString(coin.recipient),
4368
4566
  nonce: coin.nonce
@@ -4370,12 +4568,11 @@ var _Provider = class {
4370
4568
  case "Coin":
4371
4569
  return {
4372
4570
  id: coin.utxoId,
4373
- amount: (0, import_math15.bn)(coin.amount),
4571
+ amount: (0, import_math16.bn)(coin.amount),
4374
4572
  assetId: coin.assetId,
4375
4573
  owner: import_address3.Address.fromAddressOrString(coin.owner),
4376
- maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
4377
- blockCreated: (0, import_math15.bn)(coin.blockCreated),
4378
- txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
4574
+ blockCreated: (0, import_math16.bn)(coin.blockCreated),
4575
+ txCreatedIdx: (0, import_math16.bn)(coin.txCreatedIdx)
4379
4576
  };
4380
4577
  default:
4381
4578
  return null;
@@ -4392,13 +4589,13 @@ var _Provider = class {
4392
4589
  async getBlock(idOrHeight) {
4393
4590
  let variables;
4394
4591
  if (typeof idOrHeight === "number") {
4395
- variables = { height: (0, import_math15.bn)(idOrHeight).toString(10) };
4592
+ variables = { height: (0, import_math16.bn)(idOrHeight).toString(10) };
4396
4593
  } else if (idOrHeight === "latest") {
4397
4594
  variables = { height: (await this.getBlockNumber()).toString(10) };
4398
4595
  } else if (idOrHeight.length === 66) {
4399
4596
  variables = { blockId: idOrHeight };
4400
4597
  } else {
4401
- variables = { blockId: (0, import_math15.bn)(idOrHeight).toString(10) };
4598
+ variables = { blockId: (0, import_math16.bn)(idOrHeight).toString(10) };
4402
4599
  }
4403
4600
  const { block } = await this.operations.getBlock(variables);
4404
4601
  if (!block) {
@@ -4406,7 +4603,7 @@ var _Provider = class {
4406
4603
  }
4407
4604
  return {
4408
4605
  id: block.id,
4409
- height: (0, import_math15.bn)(block.header.height),
4606
+ height: (0, import_math16.bn)(block.height),
4410
4607
  time: block.header.time,
4411
4608
  transactionIds: block.transactions.map((tx) => tx.id)
4412
4609
  };
@@ -4421,7 +4618,7 @@ var _Provider = class {
4421
4618
  const { blocks: fetchedData } = await this.operations.getBlocks(params);
4422
4619
  const blocks = fetchedData.edges.map(({ node: block }) => ({
4423
4620
  id: block.id,
4424
- height: (0, import_math15.bn)(block.header.height),
4621
+ height: (0, import_math16.bn)(block.height),
4425
4622
  time: block.header.time,
4426
4623
  transactionIds: block.transactions.map((tx) => tx.id)
4427
4624
  }));
@@ -4436,7 +4633,7 @@ var _Provider = class {
4436
4633
  async getBlockWithTransactions(idOrHeight) {
4437
4634
  let variables;
4438
4635
  if (typeof idOrHeight === "number") {
4439
- variables = { blockHeight: (0, import_math15.bn)(idOrHeight).toString(10) };
4636
+ variables = { blockHeight: (0, import_math16.bn)(idOrHeight).toString(10) };
4440
4637
  } else if (idOrHeight === "latest") {
4441
4638
  variables = { blockHeight: (await this.getBlockNumber()).toString() };
4442
4639
  } else {
@@ -4448,11 +4645,11 @@ var _Provider = class {
4448
4645
  }
4449
4646
  return {
4450
4647
  id: block.id,
4451
- height: (0, import_math15.bn)(block.header.height, 10),
4648
+ height: (0, import_math16.bn)(block.height, 10),
4452
4649
  time: block.header.time,
4453
4650
  transactionIds: block.transactions.map((tx) => tx.id),
4454
4651
  transactions: block.transactions.map(
4455
- (tx) => new import_transactions19.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]
4456
4653
  )
4457
4654
  };
4458
4655
  }
@@ -4468,7 +4665,7 @@ var _Provider = class {
4468
4665
  return null;
4469
4666
  }
4470
4667
  return new import_transactions19.TransactionCoder().decode(
4471
- (0, import_utils23.arrayify)(transaction.rawPayload),
4668
+ (0, import_utils22.arrayify)(transaction.rawPayload),
4472
4669
  0
4473
4670
  )?.[0];
4474
4671
  }
@@ -4495,9 +4692,9 @@ var _Provider = class {
4495
4692
  async getContractBalance(contractId, assetId) {
4496
4693
  const { contractBalance } = await this.operations.getContractBalance({
4497
4694
  contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
4498
- asset: (0, import_utils23.hexlify)(assetId)
4695
+ asset: (0, import_utils22.hexlify)(assetId)
4499
4696
  });
4500
- return (0, import_math15.bn)(contractBalance.amount, 10);
4697
+ return (0, import_math16.bn)(contractBalance.amount, 10);
4501
4698
  }
4502
4699
  /**
4503
4700
  * Returns the balance for the given owner for the given asset ID.
@@ -4509,9 +4706,9 @@ var _Provider = class {
4509
4706
  async getBalance(owner, assetId) {
4510
4707
  const { balance } = await this.operations.getBalance({
4511
4708
  owner: import_address3.Address.fromAddressOrString(owner).toB256(),
4512
- assetId: (0, import_utils23.hexlify)(assetId)
4709
+ assetId: (0, import_utils22.hexlify)(assetId)
4513
4710
  });
4514
- return (0, import_math15.bn)(balance.amount, 10);
4711
+ return (0, import_math16.bn)(balance.amount, 10);
4515
4712
  }
4516
4713
  /**
4517
4714
  * Returns balances for the given owner.
@@ -4529,7 +4726,7 @@ var _Provider = class {
4529
4726
  const balances = result.balances.edges.map((edge) => edge.node);
4530
4727
  return balances.map((balance) => ({
4531
4728
  assetId: balance.assetId,
4532
- amount: (0, import_math15.bn)(balance.amount)
4729
+ amount: (0, import_math16.bn)(balance.amount)
4533
4730
  }));
4534
4731
  }
4535
4732
  /**
@@ -4551,15 +4748,15 @@ var _Provider = class {
4551
4748
  sender: message.sender,
4552
4749
  recipient: message.recipient,
4553
4750
  nonce: message.nonce,
4554
- amount: (0, import_math15.bn)(message.amount),
4751
+ amount: (0, import_math16.bn)(message.amount),
4555
4752
  data: message.data
4556
4753
  }),
4557
4754
  sender: import_address3.Address.fromAddressOrString(message.sender),
4558
4755
  recipient: import_address3.Address.fromAddressOrString(message.recipient),
4559
4756
  nonce: message.nonce,
4560
- amount: (0, import_math15.bn)(message.amount),
4757
+ amount: (0, import_math16.bn)(message.amount),
4561
4758
  data: import_transactions19.InputMessageCoder.decodeData(message.data),
4562
- daHeight: (0, import_math15.bn)(message.daHeight)
4759
+ daHeight: (0, import_math16.bn)(message.daHeight)
4563
4760
  }));
4564
4761
  }
4565
4762
  /**
@@ -4612,44 +4809,60 @@ var _Provider = class {
4612
4809
  } = result.messageProof;
4613
4810
  return {
4614
4811
  messageProof: {
4615
- proofIndex: (0, import_math15.bn)(messageProof.proofIndex),
4812
+ proofIndex: (0, import_math16.bn)(messageProof.proofIndex),
4616
4813
  proofSet: messageProof.proofSet
4617
4814
  },
4618
4815
  blockProof: {
4619
- proofIndex: (0, import_math15.bn)(blockProof.proofIndex),
4816
+ proofIndex: (0, import_math16.bn)(blockProof.proofIndex),
4620
4817
  proofSet: blockProof.proofSet
4621
4818
  },
4622
4819
  messageBlockHeader: {
4623
4820
  id: messageBlockHeader.id,
4624
- daHeight: (0, import_math15.bn)(messageBlockHeader.daHeight),
4625
- transactionsCount: (0, import_math15.bn)(messageBlockHeader.transactionsCount),
4821
+ daHeight: (0, import_math16.bn)(messageBlockHeader.daHeight),
4822
+ transactionsCount: (0, import_math16.bn)(messageBlockHeader.transactionsCount),
4626
4823
  transactionsRoot: messageBlockHeader.transactionsRoot,
4627
- height: (0, import_math15.bn)(messageBlockHeader.height),
4824
+ height: (0, import_math16.bn)(messageBlockHeader.height),
4628
4825
  prevRoot: messageBlockHeader.prevRoot,
4629
4826
  time: messageBlockHeader.time,
4630
4827
  applicationHash: messageBlockHeader.applicationHash,
4631
- messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
4632
- 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
4633
4833
  },
4634
4834
  commitBlockHeader: {
4635
4835
  id: commitBlockHeader.id,
4636
- daHeight: (0, import_math15.bn)(commitBlockHeader.daHeight),
4637
- transactionsCount: (0, import_math15.bn)(commitBlockHeader.transactionsCount),
4836
+ daHeight: (0, import_math16.bn)(commitBlockHeader.daHeight),
4837
+ transactionsCount: (0, import_math16.bn)(commitBlockHeader.transactionsCount),
4638
4838
  transactionsRoot: commitBlockHeader.transactionsRoot,
4639
- height: (0, import_math15.bn)(commitBlockHeader.height),
4839
+ height: (0, import_math16.bn)(commitBlockHeader.height),
4640
4840
  prevRoot: commitBlockHeader.prevRoot,
4641
4841
  time: commitBlockHeader.time,
4642
4842
  applicationHash: commitBlockHeader.applicationHash,
4643
- messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
4644
- 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
4645
4848
  },
4646
4849
  sender: import_address3.Address.fromAddressOrString(sender),
4647
4850
  recipient: import_address3.Address.fromAddressOrString(recipient),
4648
4851
  nonce,
4649
- amount: (0, import_math15.bn)(amount),
4852
+ amount: (0, import_math16.bn)(amount),
4650
4853
  data
4651
4854
  };
4652
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
+ }
4653
4866
  /**
4654
4867
  * Returns Message Proof for given transaction id and the message id from MessageOut receipt.
4655
4868
  *
@@ -4669,10 +4882,10 @@ var _Provider = class {
4669
4882
  */
4670
4883
  async produceBlocks(amount, startTime) {
4671
4884
  const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
4672
- blocksToProduce: (0, import_math15.bn)(amount).toString(10),
4673
- 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
4674
4887
  });
4675
- return (0, import_math15.bn)(latestBlockHeight);
4888
+ return (0, import_math16.bn)(latestBlockHeight);
4676
4889
  }
4677
4890
  // eslint-disable-next-line @typescript-eslint/require-await
4678
4891
  async getTransactionResponse(transactionId) {
@@ -4696,9 +4909,9 @@ __publicField(Provider, "nodeInfoCache", {});
4696
4909
 
4697
4910
  // src/providers/transaction-summary/get-transaction-summary.ts
4698
4911
  var import_errors15 = require("@fuel-ts/errors");
4699
- var import_math16 = require("@fuel-ts/math");
4912
+ var import_math17 = require("@fuel-ts/math");
4700
4913
  var import_transactions20 = require("@fuel-ts/transactions");
4701
- var import_utils26 = require("@fuel-ts/utils");
4914
+ var import_utils25 = require("@fuel-ts/utils");
4702
4915
  async function getTransactionSummary(params) {
4703
4916
  const { id, provider, abiMap } = params;
4704
4917
  const { transaction: gqlTransaction } = await provider.operations.getTransactionWithReceipts({
@@ -4711,24 +4924,31 @@ async function getTransactionSummary(params) {
4711
4924
  );
4712
4925
  }
4713
4926
  const [decodedTransaction] = new import_transactions20.TransactionCoder().decode(
4714
- (0, import_utils26.arrayify)(gqlTransaction.rawPayload),
4927
+ (0, import_utils25.arrayify)(gqlTransaction.rawPayload),
4715
4928
  0
4716
4929
  );
4717
- 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);
4718
4935
  const {
4719
- consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
4936
+ consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts, maxGasPerTx }
4720
4937
  } = provider.getChain();
4938
+ const gasPrice = await provider.getLatestGasPrice();
4721
4939
  const transactionInfo = assembleTransactionSummary({
4722
4940
  id: gqlTransaction.id,
4723
4941
  receipts,
4724
4942
  transaction: decodedTransaction,
4725
- transactionBytes: (0, import_utils26.arrayify)(gqlTransaction.rawPayload),
4943
+ transactionBytes: (0, import_utils25.arrayify)(gqlTransaction.rawPayload),
4726
4944
  gqlTransactionStatus: gqlTransaction.status,
4727
- gasPerByte: (0, import_math16.bn)(gasPerByte),
4728
- gasPriceFactor: (0, import_math16.bn)(gasPriceFactor),
4945
+ gasPerByte: (0, import_math17.bn)(gasPerByte),
4946
+ gasPriceFactor: (0, import_math17.bn)(gasPriceFactor),
4729
4947
  abiMap,
4730
4948
  maxInputs,
4731
- gasCosts
4949
+ gasCosts,
4950
+ maxGasPerTx,
4951
+ gasPrice
4732
4952
  });
4733
4953
  return {
4734
4954
  gqlTransaction,
@@ -4738,10 +4958,11 @@ async function getTransactionSummary(params) {
4738
4958
  async function getTransactionSummaryFromRequest(params) {
4739
4959
  const { provider, transactionRequest, abiMap } = params;
4740
4960
  const { receipts } = await provider.call(transactionRequest);
4741
- const { gasPerByte, gasPriceFactor, gasCosts } = provider.getGasConfig();
4961
+ const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = provider.getGasConfig();
4742
4962
  const maxInputs = provider.getChain().consensusParameters.maxInputs;
4743
4963
  const transaction = transactionRequest.toTransaction();
4744
4964
  const transactionBytes = transactionRequest.toTransactionBytes();
4965
+ const gasPrice = await provider.getLatestGasPrice();
4745
4966
  const transactionSummary = assembleTransactionSummary({
4746
4967
  receipts,
4747
4968
  transaction,
@@ -4750,7 +4971,9 @@ async function getTransactionSummaryFromRequest(params) {
4750
4971
  gasPerByte,
4751
4972
  gasPriceFactor,
4752
4973
  maxInputs,
4753
- gasCosts
4974
+ gasCosts,
4975
+ maxGasPerTx,
4976
+ gasPrice
4754
4977
  });
4755
4978
  return transactionSummary;
4756
4979
  }
@@ -4759,24 +4982,31 @@ async function getTransactionsSummaries(params) {
4759
4982
  const { transactionsByOwner } = await provider.operations.getTransactionsByOwner(filters);
4760
4983
  const { edges, pageInfo } = transactionsByOwner;
4761
4984
  const {
4762
- consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
4985
+ consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts, maxGasPerTx }
4763
4986
  } = provider.getChain();
4987
+ const gasPrice = await provider.getLatestGasPrice();
4764
4988
  const transactions = edges.map((edge) => {
4765
4989
  const { node: gqlTransaction } = edge;
4766
- const { id, rawPayload, receipts: gqlReceipts, status } = gqlTransaction;
4767
- const [decodedTransaction] = new import_transactions20.TransactionCoder().decode((0, import_utils26.arrayify)(rawPayload), 0);
4768
- 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);
4769
4997
  const transactionSummary = assembleTransactionSummary({
4770
4998
  id,
4771
4999
  receipts,
4772
5000
  transaction: decodedTransaction,
4773
- transactionBytes: (0, import_utils26.arrayify)(rawPayload),
5001
+ transactionBytes: (0, import_utils25.arrayify)(rawPayload),
4774
5002
  gqlTransactionStatus: status,
4775
5003
  abiMap,
4776
5004
  gasPerByte,
4777
5005
  gasPriceFactor,
4778
5006
  maxInputs,
4779
- gasCosts
5007
+ gasCosts,
5008
+ maxGasPerTx,
5009
+ gasPrice
4780
5010
  });
4781
5011
  const output = {
4782
5012
  gqlTransaction,
@@ -4913,17 +5143,17 @@ var assets = [
4913
5143
 
4914
5144
  // src/utils/formatTransferToContractScriptData.ts
4915
5145
  var import_abi_coder6 = require("@fuel-ts/abi-coder");
4916
- var import_math17 = require("@fuel-ts/math");
4917
- var import_utils27 = require("@fuel-ts/utils");
5146
+ var import_math18 = require("@fuel-ts/math");
5147
+ var import_utils26 = require("@fuel-ts/utils");
4918
5148
  var asm = __toESM(require("@fuels/vm-asm"));
4919
5149
  var formatTransferToContractScriptData = (params) => {
4920
5150
  const { assetId, amountToTransfer, hexlifiedContractId } = params;
4921
5151
  const numberCoder = new import_abi_coder6.BigNumberCoder("u64");
4922
- const encoded = numberCoder.encode(new import_math17.BN(amountToTransfer).toNumber());
5152
+ const encoded = numberCoder.encode(new import_math18.BN(amountToTransfer).toNumber());
4923
5153
  const scriptData = Uint8Array.from([
4924
- ...(0, import_utils27.arrayify)(hexlifiedContractId),
5154
+ ...(0, import_utils26.arrayify)(hexlifiedContractId),
4925
5155
  ...encoded,
4926
- ...(0, import_utils27.arrayify)(assetId)
5156
+ ...(0, import_utils26.arrayify)(assetId)
4927
5157
  ]);
4928
5158
  return scriptData;
4929
5159
  };
@@ -5108,36 +5338,33 @@ var Account = class extends import_interfaces.AbstractAccount {
5108
5338
  * @param fee - The estimated transaction fee.
5109
5339
  * @returns A promise that resolves when the resources are added to the transaction.
5110
5340
  */
5111
- async fund(request, coinQuantities, fee) {
5112
- const updatedQuantities = addAmountToAsset({
5113
- 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),
5114
5346
  assetId: import_configs12.BaseAssetId,
5115
- coinQuantities
5347
+ coinQuantities: requiredQuantities
5116
5348
  });
5117
5349
  const quantitiesDict = {};
5118
- updatedQuantities.forEach(({ amount, assetId }) => {
5350
+ requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
5119
5351
  quantitiesDict[assetId] = {
5120
5352
  required: amount,
5121
- owned: (0, import_math18.bn)(0)
5353
+ owned: (0, import_math19.bn)(0)
5122
5354
  };
5123
5355
  });
5124
- const cachedUtxos = [];
5125
- const cachedMessages = [];
5126
- const owner = this.address.toB256();
5127
- request.inputs.forEach((input) => {
5356
+ txRequest.inputs.forEach((input) => {
5128
5357
  const isResource = "amount" in input;
5129
5358
  if (isResource) {
5130
5359
  const isCoin2 = "owner" in input;
5131
5360
  if (isCoin2) {
5132
5361
  const assetId = String(input.assetId);
5133
- if (input.owner === owner && quantitiesDict[assetId]) {
5134
- const amount = (0, import_math18.bn)(input.amount);
5362
+ if (quantitiesDict[assetId]) {
5363
+ const amount = (0, import_math19.bn)(input.amount);
5135
5364
  quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
5136
- cachedUtxos.push(input.id);
5137
5365
  }
5138
- } else if (input.recipient === owner && input.amount && quantitiesDict[import_configs12.BaseAssetId]) {
5366
+ } else if (input.amount && quantitiesDict[import_configs12.BaseAssetId]) {
5139
5367
  quantitiesDict[import_configs12.BaseAssetId].owned = quantitiesDict[import_configs12.BaseAssetId].owned.add(input.amount);
5140
- cachedMessages.push(input.nonce);
5141
5368
  }
5142
5369
  }
5143
5370
  });
@@ -5152,12 +5379,23 @@ var Account = class extends import_interfaces.AbstractAccount {
5152
5379
  });
5153
5380
  const needsToBeFunded = missingQuantities.length;
5154
5381
  if (needsToBeFunded) {
5155
- const resources = await this.getResourcesToSpend(missingQuantities, {
5156
- messages: cachedMessages,
5157
- utxos: cachedUtxos
5158
- });
5159
- 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
+ );
5160
5393
  }
5394
+ const { maxFee } = await this.provider.estimateTxGasAndFee({
5395
+ transactionRequest: requestToBeReEstimate
5396
+ });
5397
+ txRequest.maxFee = maxFee;
5398
+ return txRequest;
5161
5399
  }
5162
5400
  /**
5163
5401
  * A helper that creates a transfer transaction request and returns it.
@@ -5165,28 +5403,25 @@ var Account = class extends import_interfaces.AbstractAccount {
5165
5403
  * @param destination - The address of the destination.
5166
5404
  * @param amount - The amount of coins to transfer.
5167
5405
  * @param assetId - The asset ID of the coins to transfer.
5168
- * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
5406
+ * @param txParams - The transaction parameters (gasLimit, tip, maturity, maxFee, witnessLimit).
5169
5407
  * @returns A promise that resolves to the prepared transaction request.
5170
5408
  */
5171
5409
  async createTransfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
5172
- const { minGasPrice } = this.provider.getGasConfig();
5173
- const params = { gasPrice: minGasPrice, ...txParams };
5174
- const request = new ScriptTransactionRequest(params);
5410
+ const request = new ScriptTransactionRequest(txParams);
5175
5411
  request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetId);
5176
- const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
5412
+ const txCost = await this.provider.getTransactionCost(request, {
5177
5413
  estimateTxDependencies: true,
5178
5414
  resourcesOwner: this
5179
5415
  });
5180
- request.gasPrice = (0, import_math18.bn)(txParams.gasPrice ?? minGasPrice);
5181
- request.gasLimit = (0, import_math18.bn)(txParams.gasLimit ?? gasUsed);
5182
- this.validateGas({
5183
- gasUsed,
5184
- gasPrice: request.gasPrice,
5185
- gasLimit: request.gasLimit,
5186
- minGasPrice
5187
- });
5188
- await this.fund(request, requiredQuantities, maxFee);
5189
- 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);
5190
5425
  return request;
5191
5426
  }
5192
5427
  /**
@@ -5199,7 +5434,7 @@ var Account = class extends import_interfaces.AbstractAccount {
5199
5434
  * @returns A promise that resolves to the transaction response.
5200
5435
  */
5201
5436
  async transfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
5202
- if ((0, import_math18.bn)(amount).lte(0)) {
5437
+ if ((0, import_math19.bn)(amount).lte(0)) {
5203
5438
  throw new import_errors16.FuelError(
5204
5439
  import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
5205
5440
  "Transfer amount must be a positive number."
@@ -5218,38 +5453,37 @@ var Account = class extends import_interfaces.AbstractAccount {
5218
5453
  * @returns A promise that resolves to the transaction response.
5219
5454
  */
5220
5455
  async transferToContract(contractId, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
5221
- if ((0, import_math18.bn)(amount).lte(0)) {
5456
+ if ((0, import_math19.bn)(amount).lte(0)) {
5222
5457
  throw new import_errors16.FuelError(
5223
5458
  import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
5224
5459
  "Transfer amount must be a positive number."
5225
5460
  );
5226
5461
  }
5227
5462
  const contractAddress = import_address4.Address.fromAddressOrString(contractId);
5228
- const { minGasPrice } = this.provider.getGasConfig();
5229
- const params = { gasPrice: minGasPrice, ...txParams };
5230
5463
  const { script, scriptData } = await assembleTransferToContractScript({
5231
5464
  hexlifiedContractId: contractAddress.toB256(),
5232
- amountToTransfer: (0, import_math18.bn)(amount),
5465
+ amountToTransfer: (0, import_math19.bn)(amount),
5233
5466
  assetId
5234
5467
  });
5235
5468
  const request = new ScriptTransactionRequest({
5236
- ...params,
5469
+ ...txParams,
5237
5470
  script,
5238
5471
  scriptData
5239
5472
  });
5240
5473
  request.addContractInputAndOutput(contractAddress);
5241
- const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
5242
- request,
5243
- [{ amount: (0, import_math18.bn)(amount), assetId: String(assetId) }]
5244
- );
5245
- request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
5246
- this.validateGas({
5247
- gasUsed,
5248
- gasPrice: request.gasPrice,
5249
- gasLimit: request.gasLimit,
5250
- minGasPrice
5474
+ const txCost = await this.provider.getTransactionCost(request, {
5475
+ resourcesOwner: this,
5476
+ quantitiesToContract: [{ amount: (0, import_math19.bn)(amount), assetId: String(assetId) }]
5251
5477
  });
5252
- 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);
5253
5487
  return this.sendTransaction(request);
5254
5488
  }
5255
5489
  /**
@@ -5261,34 +5495,31 @@ var Account = class extends import_interfaces.AbstractAccount {
5261
5495
  * @returns A promise that resolves to the transaction response.
5262
5496
  */
5263
5497
  async withdrawToBaseLayer(recipient, amount, txParams = {}) {
5264
- const { minGasPrice } = this.provider.getGasConfig();
5265
5498
  const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
5266
- const recipientDataArray = (0, import_utils28.arrayify)(
5499
+ const recipientDataArray = (0, import_utils27.arrayify)(
5267
5500
  "0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
5268
5501
  );
5269
- const amountDataArray = (0, import_utils28.arrayify)(
5270
- "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"))
5271
5504
  );
5272
5505
  const script = new Uint8Array([
5273
- ...(0, import_utils28.arrayify)(withdrawScript.bytes),
5506
+ ...(0, import_utils27.arrayify)(withdrawScript.bytes),
5274
5507
  ...recipientDataArray,
5275
5508
  ...amountDataArray
5276
5509
  ]);
5277
- const params = { script, gasPrice: minGasPrice, ...txParams };
5510
+ const params = { script, ...txParams };
5278
5511
  const request = new ScriptTransactionRequest(params);
5279
- const forwardingQuantities = [{ amount: (0, import_math18.bn)(amount), assetId: import_configs12.BaseAssetId }];
5280
- const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
5281
- request,
5282
- forwardingQuantities
5283
- );
5284
- request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
5285
- this.validateGas({
5286
- gasUsed,
5287
- gasPrice: request.gasPrice,
5288
- gasLimit: request.gasLimit,
5289
- minGasPrice
5290
- });
5291
- 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);
5292
5523
  return this.sendTransaction(request);
5293
5524
  }
5294
5525
  async signMessage(message) {
@@ -5346,18 +5577,7 @@ var Account = class extends import_interfaces.AbstractAccount {
5346
5577
  }
5347
5578
  return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
5348
5579
  }
5349
- validateGas({
5350
- gasUsed,
5351
- gasPrice,
5352
- gasLimit,
5353
- minGasPrice
5354
- }) {
5355
- if (minGasPrice.gt(gasPrice)) {
5356
- throw new import_errors16.FuelError(
5357
- import_errors16.ErrorCode.GAS_PRICE_TOO_LOW,
5358
- `Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
5359
- );
5360
- }
5580
+ validateGas({ gasUsed, gasLimit }) {
5361
5581
  if (gasUsed.gt(gasLimit)) {
5362
5582
  throw new import_errors16.FuelError(
5363
5583
  import_errors16.ErrorCode.GAS_LIMIT_TOO_LOW,
@@ -5369,14 +5589,14 @@ var Account = class extends import_interfaces.AbstractAccount {
5369
5589
 
5370
5590
  // src/wallet/base-wallet-unlocked.ts
5371
5591
  var import_hasher3 = require("@fuel-ts/hasher");
5372
- var import_utils31 = require("@fuel-ts/utils");
5592
+ var import_utils30 = require("@fuel-ts/utils");
5373
5593
 
5374
5594
  // src/signer/signer.ts
5375
5595
  var import_address5 = require("@fuel-ts/address");
5376
5596
  var import_crypto2 = require("@fuel-ts/crypto");
5377
5597
  var import_hasher2 = require("@fuel-ts/hasher");
5378
- var import_math19 = require("@fuel-ts/math");
5379
- var import_utils29 = require("@fuel-ts/utils");
5598
+ var import_math20 = require("@fuel-ts/math");
5599
+ var import_utils28 = require("@fuel-ts/utils");
5380
5600
  var import_secp256k1 = require("@noble/curves/secp256k1");
5381
5601
  var Signer = class {
5382
5602
  address;
@@ -5395,10 +5615,10 @@ var Signer = class {
5395
5615
  privateKey = `0x${privateKey}`;
5396
5616
  }
5397
5617
  }
5398
- const privateKeyBytes = (0, import_math19.toBytes)(privateKey, 32);
5399
- this.privateKey = (0, import_utils29.hexlify)(privateKeyBytes);
5400
- this.publicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
5401
- 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));
5402
5622
  this.address = import_address5.Address.fromPublicKey(this.publicKey);
5403
5623
  }
5404
5624
  /**
@@ -5412,11 +5632,11 @@ var Signer = class {
5412
5632
  * @returns hashed signature
5413
5633
  */
5414
5634
  sign(data) {
5415
- const signature = import_secp256k1.secp256k1.sign((0, import_utils29.arrayify)(data), (0, import_utils29.arrayify)(this.privateKey));
5416
- const r = (0, import_math19.toBytes)(`0x${signature.r.toString(16)}`, 32);
5417
- 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);
5418
5638
  s[0] |= (signature.recovery || 0) << 7;
5419
- return (0, import_utils29.hexlify)((0, import_utils29.concat)([r, s]));
5639
+ return (0, import_utils28.hexlify)((0, import_utils28.concat)([r, s]));
5420
5640
  }
5421
5641
  /**
5422
5642
  * Add point on the current elliptic curve
@@ -5425,8 +5645,8 @@ var Signer = class {
5425
5645
  * @returns compressed point on the curve
5426
5646
  */
5427
5647
  addPoint(point) {
5428
- const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(this.compressedPublicKey));
5429
- 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));
5430
5650
  const result = p0.add(p1);
5431
5651
  return `0x${result.toHex(true)}`;
5432
5652
  }
@@ -5438,16 +5658,16 @@ var Signer = class {
5438
5658
  * @returns public key from signature from the
5439
5659
  */
5440
5660
  static recoverPublicKey(data, signature) {
5441
- const signedMessageBytes = (0, import_utils29.arrayify)(signature);
5661
+ const signedMessageBytes = (0, import_utils28.arrayify)(signature);
5442
5662
  const r = signedMessageBytes.slice(0, 32);
5443
5663
  const s = signedMessageBytes.slice(32, 64);
5444
5664
  const recoveryParam = (s[0] & 128) >> 7;
5445
5665
  s[0] &= 127;
5446
- 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(
5447
5667
  recoveryParam
5448
5668
  );
5449
- const publicKey = sig.recoverPublicKey((0, import_utils29.arrayify)(data)).toRawBytes(false).slice(1);
5450
- 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);
5451
5671
  }
5452
5672
  /**
5453
5673
  * Recover the address from a signature performed with [`sign`](#sign).
@@ -5466,7 +5686,7 @@ var Signer = class {
5466
5686
  * @returns random 32-byte hashed
5467
5687
  */
5468
5688
  static generatePrivateKey(entropy) {
5469
- 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);
5470
5690
  }
5471
5691
  /**
5472
5692
  * Extended publicKey from a compact publicKey
@@ -5475,8 +5695,8 @@ var Signer = class {
5475
5695
  * @returns extended publicKey
5476
5696
  */
5477
5697
  static extendPublicKey(publicKey) {
5478
- const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(publicKey));
5479
- 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));
5480
5700
  }
5481
5701
  };
5482
5702
 
@@ -5484,7 +5704,7 @@ var Signer = class {
5484
5704
  var import_address6 = require("@fuel-ts/address");
5485
5705
  var import_crypto3 = require("@fuel-ts/crypto");
5486
5706
  var import_errors17 = require("@fuel-ts/errors");
5487
- var import_utils30 = require("@fuel-ts/utils");
5707
+ var import_utils29 = require("@fuel-ts/utils");
5488
5708
  var import_uuid = require("uuid");
5489
5709
  var DEFAULT_KDF_PARAMS_LOG_N = 13;
5490
5710
  var DEFAULT_KDF_PARAMS_R = 8;
@@ -5567,7 +5787,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
5567
5787
  );
5568
5788
  }
5569
5789
  const buffer = await (0, import_crypto3.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
5570
- const privateKey = (0, import_utils30.hexlify)(buffer);
5790
+ const privateKey = (0, import_utils29.hexlify)(buffer);
5571
5791
  return privateKey;
5572
5792
  }
5573
5793
 
@@ -5612,7 +5832,7 @@ var BaseWalletUnlocked = class extends Account {
5612
5832
  */
5613
5833
  async signMessage(message) {
5614
5834
  const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
5615
- return (0, import_utils31.hexlify)(signedMessage);
5835
+ return (0, import_utils30.hexlify)(signedMessage);
5616
5836
  }
5617
5837
  /**
5618
5838
  * Signs a transaction with the wallet's private key.
@@ -5625,7 +5845,7 @@ var BaseWalletUnlocked = class extends Account {
5625
5845
  const chainId = this.provider.getChainId();
5626
5846
  const hashedTransaction = transactionRequest.getTransactionId(chainId);
5627
5847
  const signature = await this.signer().sign(hashedTransaction);
5628
- return (0, import_utils31.hexlify)(signature);
5848
+ return (0, import_utils30.hexlify)(signature);
5629
5849
  }
5630
5850
  /**
5631
5851
  * Populates a transaction with the witnesses signature.
@@ -5645,7 +5865,7 @@ var BaseWalletUnlocked = class extends Account {
5645
5865
  * @param transactionRequestLike - The transaction request to send.
5646
5866
  * @returns A promise that resolves to the TransactionResponse object.
5647
5867
  */
5648
- async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
5868
+ async sendTransaction(transactionRequestLike, { estimateTxDependencies = false, awaitExecution } = {}) {
5649
5869
  const transactionRequest = transactionRequestify(transactionRequestLike);
5650
5870
  if (estimateTxDependencies) {
5651
5871
  await this.provider.estimateTxDependencies(transactionRequest);
@@ -5686,15 +5906,15 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
5686
5906
  // src/hdwallet/hdwallet.ts
5687
5907
  var import_errors20 = require("@fuel-ts/errors");
5688
5908
  var import_hasher6 = require("@fuel-ts/hasher");
5689
- var import_math20 = require("@fuel-ts/math");
5690
- var import_utils35 = require("@fuel-ts/utils");
5909
+ var import_math21 = require("@fuel-ts/math");
5910
+ var import_utils34 = require("@fuel-ts/utils");
5691
5911
  var import_ethers3 = require("ethers");
5692
5912
 
5693
5913
  // src/mnemonic/mnemonic.ts
5694
5914
  var import_crypto4 = require("@fuel-ts/crypto");
5695
5915
  var import_errors19 = require("@fuel-ts/errors");
5696
5916
  var import_hasher5 = require("@fuel-ts/hasher");
5697
- var import_utils33 = require("@fuel-ts/utils");
5917
+ var import_utils32 = require("@fuel-ts/utils");
5698
5918
  var import_ethers2 = require("ethers");
5699
5919
 
5700
5920
  // src/wordlists/words/english.ts
@@ -7758,7 +7978,7 @@ var Language = /* @__PURE__ */ ((Language2) => {
7758
7978
  // src/mnemonic/utils.ts
7759
7979
  var import_errors18 = require("@fuel-ts/errors");
7760
7980
  var import_hasher4 = require("@fuel-ts/hasher");
7761
- var import_utils32 = require("@fuel-ts/utils");
7981
+ var import_utils31 = require("@fuel-ts/utils");
7762
7982
  function toUtf8Bytes(stri) {
7763
7983
  const str = stri.normalize("NFKD");
7764
7984
  const result = [];
@@ -7825,14 +8045,14 @@ function entropyToMnemonicIndices(entropy) {
7825
8045
  }
7826
8046
  }
7827
8047
  const checksumBits = entropy.length / 4;
7828
- 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);
7829
8049
  indices[indices.length - 1] <<= checksumBits;
7830
8050
  indices[indices.length - 1] |= checksum >> 8 - checksumBits;
7831
8051
  return indices;
7832
8052
  }
7833
8053
  function mnemonicWordsToEntropy(words, wordlist) {
7834
8054
  const size = Math.ceil(11 * words.length / 8);
7835
- const entropy = (0, import_utils32.arrayify)(new Uint8Array(size));
8055
+ const entropy = (0, import_utils31.arrayify)(new Uint8Array(size));
7836
8056
  let offset = 0;
7837
8057
  for (let i = 0; i < words.length; i += 1) {
7838
8058
  const index = wordlist.indexOf(words[i].normalize("NFKD"));
@@ -7852,7 +8072,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
7852
8072
  const entropyBits = 32 * words.length / 3;
7853
8073
  const checksumBits = words.length / 3;
7854
8074
  const checksumMask = getUpperMask(checksumBits);
7855
- 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;
7856
8076
  if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
7857
8077
  throw new import_errors18.FuelError(
7858
8078
  import_errors18.ErrorCode.INVALID_CHECKSUM,
@@ -7927,7 +8147,7 @@ var Mnemonic = class {
7927
8147
  static mnemonicToEntropy(phrase, wordlist = english) {
7928
8148
  const words = getWords(phrase);
7929
8149
  assertMnemonic(words);
7930
- return (0, import_utils33.hexlify)(mnemonicWordsToEntropy(words, wordlist));
8150
+ return (0, import_utils32.hexlify)(mnemonicWordsToEntropy(words, wordlist));
7931
8151
  }
7932
8152
  /**
7933
8153
  * @param entropy - Entropy source to the mnemonic phrase.
@@ -7935,7 +8155,7 @@ var Mnemonic = class {
7935
8155
  * @returns 64-byte array contains privateKey and chainCode as described on BIP39
7936
8156
  */
7937
8157
  static entropyToMnemonic(entropy, wordlist = english) {
7938
- const entropyBytes = (0, import_utils33.arrayify)(entropy);
8158
+ const entropyBytes = (0, import_utils32.arrayify)(entropy);
7939
8159
  assertWordList(wordlist);
7940
8160
  assertEntropy(entropyBytes);
7941
8161
  return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
@@ -8004,14 +8224,14 @@ var Mnemonic = class {
8004
8224
  * @returns 64-byte array contains privateKey and chainCode as described on BIP39
8005
8225
  */
8006
8226
  static masterKeysFromSeed(seed) {
8007
- const seedArray = (0, import_utils33.arrayify)(seed);
8227
+ const seedArray = (0, import_utils32.arrayify)(seed);
8008
8228
  if (seedArray.length < 16 || seedArray.length > 64) {
8009
8229
  throw new import_errors19.FuelError(
8010
8230
  import_errors19.ErrorCode.INVALID_SEED,
8011
8231
  `Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
8012
8232
  );
8013
8233
  }
8014
- return (0, import_utils33.arrayify)((0, import_ethers2.computeHmac)("sha512", MasterSecret, seedArray));
8234
+ return (0, import_utils32.arrayify)((0, import_ethers2.computeHmac)("sha512", MasterSecret, seedArray));
8015
8235
  }
8016
8236
  /**
8017
8237
  * Get the extendKey as defined on BIP-32 from the provided seed
@@ -8022,22 +8242,22 @@ var Mnemonic = class {
8022
8242
  */
8023
8243
  static seedToExtendedKey(seed, testnet = false) {
8024
8244
  const masterKey = Mnemonic.masterKeysFromSeed(seed);
8025
- const prefix = (0, import_utils33.arrayify)(testnet ? TestnetPRV : MainnetPRV);
8245
+ const prefix = (0, import_utils32.arrayify)(testnet ? TestnetPRV : MainnetPRV);
8026
8246
  const depth = "0x00";
8027
8247
  const fingerprint = "0x00000000";
8028
8248
  const index = "0x00000000";
8029
8249
  const chainCode = masterKey.slice(32);
8030
8250
  const privateKey = masterKey.slice(0, 32);
8031
- const extendedKey = (0, import_utils33.concat)([
8251
+ const extendedKey = (0, import_utils32.concat)([
8032
8252
  prefix,
8033
8253
  depth,
8034
8254
  fingerprint,
8035
8255
  index,
8036
8256
  chainCode,
8037
- (0, import_utils33.concat)(["0x00", privateKey])
8257
+ (0, import_utils32.concat)(["0x00", privateKey])
8038
8258
  ]);
8039
8259
  const checksum = (0, import_ethers2.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
8040
- return (0, import_ethers2.encodeBase58)((0, import_utils33.concat)([extendedKey, checksum]));
8260
+ return (0, import_ethers2.encodeBase58)((0, import_utils32.concat)([extendedKey, checksum]));
8041
8261
  }
8042
8262
  /**
8043
8263
  * Create a new mnemonic using a randomly generated number as entropy.
@@ -8052,7 +8272,7 @@ var Mnemonic = class {
8052
8272
  * @returns A randomly generated mnemonic
8053
8273
  */
8054
8274
  static generate(size = 32, extraEntropy = "") {
8055
- 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);
8056
8276
  return Mnemonic.entropyToMnemonic(entropy);
8057
8277
  }
8058
8278
  };
@@ -8060,12 +8280,12 @@ var mnemonic_default = Mnemonic;
8060
8280
 
8061
8281
  // src/hdwallet/hdwallet.ts
8062
8282
  var HARDENED_INDEX = 2147483648;
8063
- var MainnetPRV2 = (0, import_utils35.hexlify)("0x0488ade4");
8064
- var MainnetPUB = (0, import_utils35.hexlify)("0x0488b21e");
8065
- var TestnetPRV2 = (0, import_utils35.hexlify)("0x04358394");
8066
- 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");
8067
8287
  function base58check(data) {
8068
- return (0, import_ethers3.encodeBase58)((0, import_utils35.concat)([data, (0, import_ethers3.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)]));
8069
8289
  }
8070
8290
  function getExtendedKeyPrefix(isPublic = false, testnet = false) {
8071
8291
  if (isPublic) {
@@ -8074,11 +8294,11 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
8074
8294
  return testnet ? TestnetPRV2 : MainnetPRV2;
8075
8295
  }
8076
8296
  function isPublicExtendedKey(extendedKey) {
8077
- 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)));
8078
8298
  }
8079
8299
  function isValidExtendedKey(extendedKey) {
8080
8300
  return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
8081
- (0, import_utils35.hexlify)(extendedKey.slice(0, 4))
8301
+ (0, import_utils34.hexlify)(extendedKey.slice(0, 4))
8082
8302
  );
8083
8303
  }
8084
8304
  function parsePath(path, depth = 0) {
@@ -8096,8 +8316,8 @@ function parsePath(path, depth = 0) {
8096
8316
  var HDWallet = class {
8097
8317
  depth = 0;
8098
8318
  index = 0;
8099
- fingerprint = (0, import_utils35.hexlify)("0x00000000");
8100
- parentFingerprint = (0, import_utils35.hexlify)("0x00000000");
8319
+ fingerprint = (0, import_utils34.hexlify)("0x00000000");
8320
+ parentFingerprint = (0, import_utils34.hexlify)("0x00000000");
8101
8321
  privateKey;
8102
8322
  publicKey;
8103
8323
  chainCode;
@@ -8109,8 +8329,8 @@ var HDWallet = class {
8109
8329
  constructor(config) {
8110
8330
  if (config.privateKey) {
8111
8331
  const signer = new Signer(config.privateKey);
8112
- this.publicKey = (0, import_utils35.hexlify)(signer.compressedPublicKey);
8113
- 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);
8114
8334
  } else {
8115
8335
  if (!config.publicKey) {
8116
8336
  throw new import_errors20.FuelError(
@@ -8118,7 +8338,7 @@ var HDWallet = class {
8118
8338
  "Both public and private Key cannot be missing. At least one should be provided."
8119
8339
  );
8120
8340
  }
8121
- this.publicKey = (0, import_utils35.hexlify)(config.publicKey);
8341
+ this.publicKey = (0, import_utils34.hexlify)(config.publicKey);
8122
8342
  }
8123
8343
  this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
8124
8344
  this.fingerprint = (0, import_ethers3.dataSlice)((0, import_ethers3.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
@@ -8137,9 +8357,9 @@ var HDWallet = class {
8137
8357
  * @returns A new instance of HDWallet on the derived index
8138
8358
  */
8139
8359
  deriveIndex(index) {
8140
- const privateKey = this.privateKey && (0, import_utils35.arrayify)(this.privateKey);
8141
- const publicKey = (0, import_utils35.arrayify)(this.publicKey);
8142
- 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);
8143
8363
  const data = new Uint8Array(37);
8144
8364
  if (index & HARDENED_INDEX) {
8145
8365
  if (!privateKey) {
@@ -8150,15 +8370,15 @@ var HDWallet = class {
8150
8370
  }
8151
8371
  data.set(privateKey, 1);
8152
8372
  } else {
8153
- data.set((0, import_utils35.arrayify)(this.publicKey));
8373
+ data.set((0, import_utils34.arrayify)(this.publicKey));
8154
8374
  }
8155
- data.set((0, import_math20.toBytes)(index, 4), 33);
8156
- const bytes = (0, import_utils35.arrayify)((0, import_ethers3.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));
8157
8377
  const IL = bytes.slice(0, 32);
8158
8378
  const IR = bytes.slice(32);
8159
8379
  if (privateKey) {
8160
8380
  const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
8161
- 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);
8162
8382
  return new HDWallet({
8163
8383
  privateKey: ki,
8164
8384
  chainCode: IR,
@@ -8167,7 +8387,7 @@ var HDWallet = class {
8167
8387
  parentFingerprint: this.fingerprint
8168
8388
  });
8169
8389
  }
8170
- const signer = new Signer((0, import_utils35.hexlify)(IL));
8390
+ const signer = new Signer((0, import_utils34.hexlify)(IL));
8171
8391
  const Ki = signer.addPoint(publicKey);
8172
8392
  return new HDWallet({
8173
8393
  publicKey: Ki,
@@ -8202,12 +8422,12 @@ var HDWallet = class {
8202
8422
  );
8203
8423
  }
8204
8424
  const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
8205
- const depth = (0, import_utils35.hexlify)(Uint8Array.from([this.depth]));
8425
+ const depth = (0, import_utils34.hexlify)(Uint8Array.from([this.depth]));
8206
8426
  const parentFingerprint = this.parentFingerprint;
8207
- const index = (0, import_math20.toHex)(this.index, 4);
8427
+ const index = (0, import_math21.toHex)(this.index, 4);
8208
8428
  const chainCode = this.chainCode;
8209
- const key = this.privateKey != null && !isPublic ? (0, import_utils35.concat)(["0x00", this.privateKey]) : this.publicKey;
8210
- 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]));
8211
8431
  return base58check(extendedKey);
8212
8432
  }
8213
8433
  /**
@@ -8219,13 +8439,13 @@ var HDWallet = class {
8219
8439
  static fromSeed(seed) {
8220
8440
  const masterKey = mnemonic_default.masterKeysFromSeed(seed);
8221
8441
  return new HDWallet({
8222
- chainCode: (0, import_utils35.arrayify)(masterKey.slice(32)),
8223
- 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))
8224
8444
  });
8225
8445
  }
8226
8446
  static fromExtendedKey(extendedKey) {
8227
8447
  const decoded = (0, import_ethers3.toBeHex)((0, import_ethers3.decodeBase58)(extendedKey));
8228
- const bytes = (0, import_utils35.arrayify)(decoded);
8448
+ const bytes = (0, import_utils34.arrayify)(decoded);
8229
8449
  const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
8230
8450
  if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
8231
8451
  throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
@@ -8234,9 +8454,9 @@ var HDWallet = class {
8234
8454
  throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
8235
8455
  }
8236
8456
  const depth = bytes[4];
8237
- const parentFingerprint = (0, import_utils35.hexlify)(bytes.slice(5, 9));
8238
- const index = parseInt((0, import_utils35.hexlify)(bytes.slice(9, 13)).substring(2), 16);
8239
- 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));
8240
8460
  const key = bytes.slice(45, 78);
8241
8461
  if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
8242
8462
  throw new import_errors20.FuelError(
@@ -8842,18 +9062,18 @@ var import_address10 = require("@fuel-ts/address");
8842
9062
  var import_configs13 = require("@fuel-ts/address/configs");
8843
9063
  var import_errors25 = require("@fuel-ts/errors");
8844
9064
  var import_transactions21 = require("@fuel-ts/transactions");
8845
- var import_utils37 = require("@fuel-ts/utils");
9065
+ var import_utils36 = require("@fuel-ts/utils");
8846
9066
 
8847
9067
  // src/predicate/utils/getPredicateRoot.ts
8848
9068
  var import_hasher7 = require("@fuel-ts/hasher");
8849
9069
  var import_merkle = require("@fuel-ts/merkle");
8850
- var import_utils36 = require("@fuel-ts/utils");
9070
+ var import_utils35 = require("@fuel-ts/utils");
8851
9071
  var getPredicateRoot = (bytecode) => {
8852
9072
  const chunkSize = 16 * 1024;
8853
- const bytes = (0, import_utils36.arrayify)(bytecode);
8854
- const chunks = (0, import_utils36.chunkAndPadBytes)(bytes, chunkSize);
8855
- const codeRoot = (0, import_merkle.calcRoot)(chunks.map((c) => (0, import_utils36.hexlify)(c)));
8856
- 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]));
8857
9077
  return predicateRoot;
8858
9078
  };
8859
9079
 
@@ -8900,15 +9120,10 @@ var Predicate = class extends Account {
8900
9120
  populateTransactionPredicateData(transactionRequestLike) {
8901
9121
  const request = transactionRequestify(transactionRequestLike);
8902
9122
  const { policies } = BaseTransactionRequest.getPolicyMeta(request);
8903
- const placeholderIndex = this.getIndexFromPlaceholderWitness(request);
8904
- if (placeholderIndex !== -1) {
8905
- request.removeWitness(placeholderIndex);
8906
- }
8907
- request.inputs.filter(isRequestInputResource).forEach((input) => {
8908
- if (isRequestInputResourceFromOwner(input, this.address)) {
8909
- input.predicate = this.bytes;
8910
- input.predicateData = this.getPredicateData(policies.length);
8911
- input.witnessIndex = 0;
9123
+ request.inputs?.forEach((input) => {
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));
8912
9127
  }
8913
9128
  });
8914
9129
  return request;
@@ -8923,8 +9138,7 @@ var Predicate = class extends Account {
8923
9138
  * @returns A promise that resolves to the prepared transaction request.
8924
9139
  */
8925
9140
  async createTransfer(destination, amount, assetId = import_configs13.BaseAssetId, txParams = {}) {
8926
- const request = await super.createTransfer(destination, amount, assetId, txParams);
8927
- return this.populateTransactionPredicateData(request);
9141
+ return super.createTransfer(destination, amount, assetId, txParams);
8928
9142
  }
8929
9143
  /**
8930
9144
  * Sends a transaction with the populated predicate data.
@@ -8932,9 +9146,9 @@ var Predicate = class extends Account {
8932
9146
  * @param transactionRequestLike - The transaction request-like object.
8933
9147
  * @returns A promise that resolves to the transaction response.
8934
9148
  */
8935
- sendTransaction(transactionRequestLike, options) {
8936
- const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
8937
- return super.sendTransaction(transactionRequest, options);
9149
+ sendTransaction(transactionRequestLike) {
9150
+ const transactionRequest = transactionRequestify(transactionRequestLike);
9151
+ return super.sendTransaction(transactionRequest, { estimateTxDependencies: false });
8938
9152
  }
8939
9153
  /**
8940
9154
  * Simulates a transaction with the populated predicate data.
@@ -8943,22 +9157,8 @@ var Predicate = class extends Account {
8943
9157
  * @returns A promise that resolves to the call result.
8944
9158
  */
8945
9159
  simulateTransaction(transactionRequestLike) {
8946
- const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
8947
- return super.simulateTransaction(transactionRequest);
8948
- }
8949
- /**
8950
- * Retrieves resources satisfying the spend query for the account.
8951
- *
8952
- * @param quantities - Coins to retrieve.
8953
- * @param excludedIds - IDs of resources to be excluded from the query.
8954
- * @returns A promise that resolves to an array of Resources.
8955
- */
8956
- async getResourcesToSpend(quantities, excludedIds) {
8957
- const resources = await super.getResourcesToSpend(quantities, excludedIds);
8958
- return resources.map((resource) => ({
8959
- ...resource,
8960
- predicate: (0, import_utils37.hexlify)(this.bytes)
8961
- }));
9160
+ const transactionRequest = transactionRequestify(transactionRequestLike);
9161
+ return super.simulateTransaction(transactionRequest, { estimateTxDependencies: false });
8962
9162
  }
8963
9163
  getPredicateData(policiesLength) {
8964
9164
  if (!this.predicateData.length) {
@@ -8981,7 +9181,7 @@ var Predicate = class extends Account {
8981
9181
  * @returns An object containing the new predicate bytes and interface.
8982
9182
  */
8983
9183
  static processPredicateData(bytes, jsonAbi, configurableConstants) {
8984
- let predicateBytes = (0, import_utils37.arrayify)(bytes);
9184
+ let predicateBytes = (0, import_utils36.arrayify)(bytes);
8985
9185
  let abiInterface;
8986
9186
  if (jsonAbi) {
8987
9187
  abiInterface = new import_abi_coder7.Interface(jsonAbi);
@@ -9004,6 +9204,25 @@ var Predicate = class extends Account {
9004
9204
  predicateInterface: abiInterface
9005
9205
  };
9006
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
+ }
9007
9226
  /**
9008
9227
  * Sets the configurable constants for the predicate.
9009
9228
  *
@@ -9039,28 +9258,6 @@ var Predicate = class extends Account {
9039
9258
  }
9040
9259
  return mutatedBytes;
9041
9260
  }
9042
- /**
9043
- * Returns the index of the witness placeholder that was added to this predicate.
9044
- * If no witness placeholder was added, it returns -1.
9045
- * @param request - The transaction request.
9046
- * @returns The index of the witness placeholder, or -1 if there is no witness placeholder.
9047
- */
9048
- getIndexFromPlaceholderWitness(request) {
9049
- const predicateInputs = request.inputs.filter(isRequestInputResource).filter((input) => isRequestInputResourceFromOwner(input, this.address));
9050
- let index = -1;
9051
- const hasEmptyPredicateInputs = predicateInputs.find((input) => !input.predicate);
9052
- if (hasEmptyPredicateInputs) {
9053
- index = hasEmptyPredicateInputs.witnessIndex;
9054
- const allInputsAreEmpty = predicateInputs.every((input) => !input.predicate);
9055
- if (!allInputsAreEmpty) {
9056
- const wasFilledInputAddedFirst = !!predicateInputs[0]?.predicate;
9057
- if (wasFilledInputAddedFirst) {
9058
- index = -1;
9059
- }
9060
- }
9061
- }
9062
- return index;
9063
- }
9064
9261
  };
9065
9262
 
9066
9263
  // src/connectors/fuel.ts
@@ -9775,7 +9972,7 @@ __publicField(Fuel, "defaultConfig", {});
9775
9972
  WalletLocked,
9776
9973
  WalletManager,
9777
9974
  WalletUnlocked,
9778
- addAmountToAsset,
9975
+ addAmountToCoinQuantities,
9779
9976
  addOperation,
9780
9977
  assemblePanicError,
9781
9978
  assembleReceiptByType,
@@ -9784,10 +9981,10 @@ __publicField(Fuel, "defaultConfig", {});
9784
9981
  assets,
9785
9982
  buildBlockExplorerUrl,
9786
9983
  cacheFor,
9787
- cacheResources,
9984
+ cacheTxInputsFromOwner,
9985
+ calculateGasFee,
9788
9986
  calculateMetadataGasForTxCreate,
9789
9987
  calculateMetadataGasForTxScript,
9790
- calculatePriceWithFactor,
9791
9988
  calculateTransactionFee,
9792
9989
  coinQuantityfy,
9793
9990
  deferPromise,
@@ -9831,7 +10028,6 @@ __publicField(Fuel, "defaultConfig", {});
9831
10028
  getReceiptsMessageOut,
9832
10029
  getReceiptsTransferOut,
9833
10030
  getReceiptsWithMissingData,
9834
- getRequestInputResourceOwner,
9835
10031
  getTransactionStatusName,
9836
10032
  getTransactionSummary,
9837
10033
  getTransactionSummaryFromRequest,
@@ -9845,10 +10041,6 @@ __publicField(Fuel, "defaultConfig", {});
9845
10041
  isMessage,
9846
10042
  isRawCoin,
9847
10043
  isRawMessage,
9848
- isRequestInputCoin,
9849
- isRequestInputMessage,
9850
- isRequestInputResource,
9851
- isRequestInputResourceFromOwner,
9852
10044
  isType,
9853
10045
  isTypeCreate,
9854
10046
  isTypeMint,