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

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