@fuel-ts/account 0.0.0-rc-2021-20240423152230 → 0.0.0-rc-2037-20240423161807

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 +604 -829
  12. package/dist/index.global.js.map +1 -1
  13. package/dist/index.js +641 -857
  14. package/dist/index.js.map +1 -1
  15. package/dist/index.mjs +459 -680
  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 +327 -821
  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 +11 -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 +1082 -1547
  59. package/dist/test-utils.global.js.map +1 -1
  60. package/dist/test-utils.js +618 -839
  61. package/dist/test-utils.js.map +1 -1
  62. package/dist/test-utils.mjs +450 -674
  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,51 +235,27 @@ 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");
242
246
 
243
247
  // src/providers/__generated__/operations.ts
244
248
  var import_graphql_tag = __toESM(require("graphql-tag"));
245
- var TransactionStatusSubscriptionFragmentFragmentDoc = import_graphql_tag.default`
246
- fragment transactionStatusSubscriptionFragment on TransactionStatus {
247
- type: __typename
248
- ... on SubmittedStatus {
249
- time
250
- }
251
- ... on SuccessStatus {
252
- block {
253
- id
254
- }
255
- time
256
- programState {
257
- returnType
258
- data
259
- }
260
- }
261
- ... on FailureStatus {
262
- block {
263
- id
264
- }
265
- time
266
- reason
267
- }
268
- ... on SqueezedOutStatus {
269
- reason
270
- }
271
- }
272
- `;
273
249
  var ReceiptFragmentFragmentDoc = import_graphql_tag.default`
274
250
  fragment receiptFragment on Receipt {
275
- id
251
+ contract {
252
+ id
253
+ }
276
254
  pc
277
255
  is
278
- to
256
+ to {
257
+ id
258
+ }
279
259
  toAddress
280
260
  amount
281
261
  assetId
@@ -313,16 +293,10 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
313
293
  id
314
294
  }
315
295
  time
316
- receipts {
317
- ...receiptFragment
318
- }
319
296
  programState {
320
297
  returnType
321
298
  data
322
299
  }
323
- receipts {
324
- ...receiptFragment
325
- }
326
300
  }
327
301
  ... on FailureStatus {
328
302
  block {
@@ -330,24 +304,26 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
330
304
  }
331
305
  time
332
306
  reason
333
- receipts {
334
- ...receiptFragment
335
- }
336
307
  }
337
308
  ... on SqueezedOutStatus {
338
309
  reason
339
310
  }
340
311
  }
341
- ${ReceiptFragmentFragmentDoc}`;
312
+ `;
342
313
  var TransactionFragmentFragmentDoc = import_graphql_tag.default`
343
314
  fragment transactionFragment on Transaction {
344
315
  id
345
316
  rawPayload
317
+ gasPrice
318
+ receipts {
319
+ ...receiptFragment
320
+ }
346
321
  status {
347
322
  ...transactionStatusFragment
348
323
  }
349
324
  }
350
- ${TransactionStatusFragmentFragmentDoc}`;
325
+ ${ReceiptFragmentFragmentDoc}
326
+ ${TransactionStatusFragmentFragmentDoc}`;
351
327
  var InputEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.default`
352
328
  fragment inputEstimatePredicatesFragment on Input {
353
329
  ... on InputCoin {
@@ -365,46 +341,6 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.defaul
365
341
  }
366
342
  }
367
343
  ${InputEstimatePredicatesFragmentFragmentDoc}`;
368
- var DryRunFailureStatusFragmentFragmentDoc = import_graphql_tag.default`
369
- fragment dryRunFailureStatusFragment on DryRunFailureStatus {
370
- reason
371
- programState {
372
- returnType
373
- data
374
- }
375
- }
376
- `;
377
- var DryRunSuccessStatusFragmentFragmentDoc = import_graphql_tag.default`
378
- fragment dryRunSuccessStatusFragment on DryRunSuccessStatus {
379
- programState {
380
- returnType
381
- data
382
- }
383
- }
384
- `;
385
- var DryRunTransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
386
- fragment dryRunTransactionStatusFragment on DryRunTransactionStatus {
387
- ... on DryRunFailureStatus {
388
- ...dryRunFailureStatusFragment
389
- }
390
- ... on DryRunSuccessStatus {
391
- ...dryRunSuccessStatusFragment
392
- }
393
- }
394
- ${DryRunFailureStatusFragmentFragmentDoc}
395
- ${DryRunSuccessStatusFragmentFragmentDoc}`;
396
- var DryRunTransactionExecutionStatusFragmentFragmentDoc = import_graphql_tag.default`
397
- fragment dryRunTransactionExecutionStatusFragment on DryRunTransactionExecutionStatus {
398
- id
399
- status {
400
- ...dryRunTransactionStatusFragment
401
- }
402
- receipts {
403
- ...receiptFragment
404
- }
405
- }
406
- ${DryRunTransactionStatusFragmentFragmentDoc}
407
- ${ReceiptFragmentFragmentDoc}`;
408
344
  var CoinFragmentFragmentDoc = import_graphql_tag.default`
409
345
  fragment coinFragment on Coin {
410
346
  __typename
@@ -412,6 +348,7 @@ var CoinFragmentFragmentDoc = import_graphql_tag.default`
412
348
  owner
413
349
  amount
414
350
  assetId
351
+ maturity
415
352
  blockCreated
416
353
  txCreatedIdx
417
354
  }
@@ -450,32 +387,26 @@ var MessageProofFragmentFragmentDoc = import_graphql_tag.default`
450
387
  messageBlockHeader {
451
388
  id
452
389
  daHeight
453
- consensusParametersVersion
454
- stateTransitionBytecodeVersion
455
390
  transactionsCount
456
- messageReceiptCount
457
391
  transactionsRoot
458
- messageOutboxRoot
459
- eventInboxRoot
460
392
  height
461
393
  prevRoot
462
394
  time
463
395
  applicationHash
396
+ messageReceiptRoot
397
+ messageReceiptCount
464
398
  }
465
399
  commitBlockHeader {
466
400
  id
467
401
  daHeight
468
- consensusParametersVersion
469
- stateTransitionBytecodeVersion
470
402
  transactionsCount
471
- messageReceiptCount
472
403
  transactionsRoot
473
- messageOutboxRoot
474
- eventInboxRoot
475
404
  height
476
405
  prevRoot
477
406
  time
478
407
  applicationHash
408
+ messageReceiptRoot
409
+ messageReceiptCount
479
410
  }
480
411
  sender
481
412
  recipient
@@ -494,8 +425,8 @@ var BalanceFragmentFragmentDoc = import_graphql_tag.default`
494
425
  var BlockFragmentFragmentDoc = import_graphql_tag.default`
495
426
  fragment blockFragment on Block {
496
427
  id
497
- height
498
428
  header {
429
+ height
499
430
  time
500
431
  }
501
432
  transactions {
@@ -553,11 +484,6 @@ var DependentCostFragmentFragmentDoc = import_graphql_tag.default`
553
484
  `;
554
485
  var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
555
486
  fragment GasCostsFragment on GasCosts {
556
- version {
557
- ... on Version {
558
- value
559
- }
560
- }
561
487
  add
562
488
  addi
563
489
  aloc
@@ -570,6 +496,7 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
570
496
  cb
571
497
  cfei
572
498
  cfsi
499
+ croo
573
500
  div
574
501
  divi
575
502
  ecr1
@@ -652,9 +579,6 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
652
579
  ccp {
653
580
  ...DependentCostFragment
654
581
  }
655
- croo {
656
- ...DependentCostFragment
657
- }
658
582
  csiz {
659
583
  ...DependentCostFragment
660
584
  }
@@ -714,11 +638,6 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
714
638
  ${DependentCostFragmentFragmentDoc}`;
715
639
  var ConsensusParametersFragmentFragmentDoc = import_graphql_tag.default`
716
640
  fragment consensusParametersFragment on ConsensusParameters {
717
- version {
718
- ... on Version {
719
- value
720
- }
721
- }
722
641
  txParams {
723
642
  ...TxParametersFragment
724
643
  }
@@ -778,9 +697,18 @@ var NodeInfoFragmentFragmentDoc = import_graphql_tag.default`
778
697
  fragment nodeInfoFragment on NodeInfo {
779
698
  utxoValidation
780
699
  vmBacktrace
700
+ minGasPrice
781
701
  maxTx
782
702
  maxDepth
783
703
  nodeVersion
704
+ peers {
705
+ id
706
+ addresses
707
+ clientVersion
708
+ blockHeight
709
+ lastHeartbeatMs
710
+ appScore
711
+ }
784
712
  }
785
713
  `;
786
714
  var GetVersionDocument = import_graphql_tag.default`
@@ -815,9 +743,13 @@ var GetTransactionWithReceiptsDocument = import_graphql_tag.default`
815
743
  query getTransactionWithReceipts($transactionId: TransactionId!) {
816
744
  transaction(id: $transactionId) {
817
745
  ...transactionFragment
746
+ receipts {
747
+ ...receiptFragment
748
+ }
818
749
  }
819
750
  }
820
- ${TransactionFragmentFragmentDoc}`;
751
+ ${TransactionFragmentFragmentDoc}
752
+ ${ReceiptFragmentFragmentDoc}`;
821
753
  var GetTransactionsDocument = import_graphql_tag.default`
822
754
  query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
823
755
  transactions(after: $after, before: $before, first: $first, last: $last) {
@@ -945,20 +877,6 @@ var GetBalanceDocument = import_graphql_tag.default`
945
877
  }
946
878
  }
947
879
  ${BalanceFragmentFragmentDoc}`;
948
- var GetLatestGasPriceDocument = import_graphql_tag.default`
949
- query getLatestGasPrice {
950
- latestGasPrice {
951
- gasPrice
952
- }
953
- }
954
- `;
955
- var EstimateGasPriceDocument = import_graphql_tag.default`
956
- query estimateGasPrice($blockHorizon: U32!) {
957
- estimateGasPrice(blockHorizon: $blockHorizon) {
958
- gasPrice
959
- }
960
- }
961
- `;
962
880
  var GetBalancesDocument = import_graphql_tag.default`
963
881
  query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
964
882
  balances(
@@ -1013,12 +931,12 @@ var GetMessageStatusDocument = import_graphql_tag.default`
1013
931
  }
1014
932
  `;
1015
933
  var DryRunDocument = import_graphql_tag.default`
1016
- mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean) {
1017
- dryRun(txs: $encodedTransactions, utxoValidation: $utxoValidation) {
1018
- ...dryRunTransactionExecutionStatusFragment
934
+ mutation dryRun($encodedTransaction: HexString!, $utxoValidation: Boolean) {
935
+ dryRun(tx: $encodedTransaction, utxoValidation: $utxoValidation) {
936
+ ...receiptFragment
1019
937
  }
1020
938
  }
1021
- ${DryRunTransactionExecutionStatusFragmentFragmentDoc}`;
939
+ ${ReceiptFragmentFragmentDoc}`;
1022
940
  var SubmitDocument = import_graphql_tag.default`
1023
941
  mutation submit($encodedTransaction: HexString!) {
1024
942
  submit(tx: $encodedTransaction) {
@@ -1037,17 +955,17 @@ var ProduceBlocksDocument = import_graphql_tag.default`
1037
955
  var SubmitAndAwaitDocument = import_graphql_tag.default`
1038
956
  subscription submitAndAwait($encodedTransaction: HexString!) {
1039
957
  submitAndAwait(tx: $encodedTransaction) {
1040
- ...transactionStatusSubscriptionFragment
958
+ ...transactionStatusFragment
1041
959
  }
1042
960
  }
1043
- ${TransactionStatusSubscriptionFragmentFragmentDoc}`;
961
+ ${TransactionStatusFragmentFragmentDoc}`;
1044
962
  var StatusChangeDocument = import_graphql_tag.default`
1045
963
  subscription statusChange($transactionId: TransactionId!) {
1046
964
  statusChange(id: $transactionId) {
1047
- ...transactionStatusSubscriptionFragment
965
+ ...transactionStatusFragment
1048
966
  }
1049
967
  }
1050
- ${TransactionStatusSubscriptionFragmentFragmentDoc}`;
968
+ ${TransactionStatusFragmentFragmentDoc}`;
1051
969
  function getSdk(requester) {
1052
970
  return {
1053
971
  getVersion(variables, options) {
@@ -1101,12 +1019,6 @@ function getSdk(requester) {
1101
1019
  getBalance(variables, options) {
1102
1020
  return requester(GetBalanceDocument, variables, options);
1103
1021
  },
1104
- getLatestGasPrice(variables, options) {
1105
- return requester(GetLatestGasPriceDocument, variables, options);
1106
- },
1107
- estimateGasPrice(variables, options) {
1108
- return requester(EstimateGasPriceDocument, variables, options);
1109
- },
1110
1022
  getBalances(variables, options) {
1111
1023
  return requester(GetBalancesDocument, variables, options);
1112
1024
  },
@@ -1300,9 +1212,10 @@ var inputify = (value) => {
1300
1212
  txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
1301
1213
  },
1302
1214
  witnessIndex: value.witnessIndex,
1215
+ maturity: value.maturity ?? 0,
1303
1216
  predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
1304
- predicateLength: (0, import_math2.bn)(predicate.length),
1305
- predicateDataLength: (0, import_math2.bn)(predicateData.length),
1217
+ predicateLength: predicate.length,
1218
+ predicateDataLength: predicateData.length,
1306
1219
  predicate: (0, import_utils3.hexlify)(predicate),
1307
1220
  predicateData: (0, import_utils3.hexlify)(predicateData)
1308
1221
  };
@@ -1333,8 +1246,8 @@ var inputify = (value) => {
1333
1246
  nonce: (0, import_utils3.hexlify)(value.nonce),
1334
1247
  witnessIndex: value.witnessIndex,
1335
1248
  predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
1336
- predicateLength: (0, import_math2.bn)(predicate.length),
1337
- predicateDataLength: (0, import_math2.bn)(predicateData.length),
1249
+ predicateLength: predicate.length,
1250
+ predicateDataLength: predicateData.length,
1338
1251
  predicate: (0, import_utils3.hexlify)(predicate),
1339
1252
  predicateData: (0, import_utils3.hexlify)(predicateData),
1340
1253
  data: (0, import_utils3.hexlify)(data),
@@ -1413,7 +1326,7 @@ var import_address = require("@fuel-ts/address");
1413
1326
  var import_configs7 = require("@fuel-ts/address/configs");
1414
1327
  var import_crypto = require("@fuel-ts/crypto");
1415
1328
  var import_math7 = require("@fuel-ts/math");
1416
- var import_transactions6 = require("@fuel-ts/transactions");
1329
+ var import_transactions7 = require("@fuel-ts/transactions");
1417
1330
  var import_utils9 = require("@fuel-ts/utils");
1418
1331
 
1419
1332
  // src/providers/resource.ts
@@ -1453,8 +1366,8 @@ function assembleReceiptByType(receipt) {
1453
1366
  case "CALL" /* Call */: {
1454
1367
  const callReceipt = {
1455
1368
  type: import_transactions3.ReceiptType.Call,
1456
- from: hexOrZero(receipt.id || receipt.contractId),
1457
- to: hexOrZero(receipt?.to),
1369
+ from: hexOrZero(receipt.contract?.id),
1370
+ to: hexOrZero(receipt?.to?.id),
1458
1371
  amount: (0, import_math4.bn)(receipt.amount),
1459
1372
  assetId: hexOrZero(receipt.assetId),
1460
1373
  gas: (0, import_math4.bn)(receipt.gas),
@@ -1468,7 +1381,7 @@ function assembleReceiptByType(receipt) {
1468
1381
  case "RETURN" /* Return */: {
1469
1382
  const returnReceipt = {
1470
1383
  type: import_transactions3.ReceiptType.Return,
1471
- id: hexOrZero(receipt.id || receipt.contractId),
1384
+ id: hexOrZero(receipt.contract?.id),
1472
1385
  val: (0, import_math4.bn)(receipt.val),
1473
1386
  pc: (0, import_math4.bn)(receipt.pc),
1474
1387
  is: (0, import_math4.bn)(receipt.is)
@@ -1478,7 +1391,7 @@ function assembleReceiptByType(receipt) {
1478
1391
  case "RETURN_DATA" /* ReturnData */: {
1479
1392
  const returnDataReceipt = {
1480
1393
  type: import_transactions3.ReceiptType.ReturnData,
1481
- id: hexOrZero(receipt.id || receipt.contractId),
1394
+ id: hexOrZero(receipt.contract?.id),
1482
1395
  ptr: (0, import_math4.bn)(receipt.ptr),
1483
1396
  len: (0, import_math4.bn)(receipt.len),
1484
1397
  digest: hexOrZero(receipt.digest),
@@ -1490,7 +1403,7 @@ function assembleReceiptByType(receipt) {
1490
1403
  case "PANIC" /* Panic */: {
1491
1404
  const panicReceipt = {
1492
1405
  type: import_transactions3.ReceiptType.Panic,
1493
- id: hexOrZero(receipt.id),
1406
+ id: hexOrZero(receipt.contract?.id),
1494
1407
  reason: (0, import_math4.bn)(receipt.reason),
1495
1408
  pc: (0, import_math4.bn)(receipt.pc),
1496
1409
  is: (0, import_math4.bn)(receipt.is),
@@ -1501,7 +1414,7 @@ function assembleReceiptByType(receipt) {
1501
1414
  case "REVERT" /* Revert */: {
1502
1415
  const revertReceipt = {
1503
1416
  type: import_transactions3.ReceiptType.Revert,
1504
- id: hexOrZero(receipt.id || receipt.contractId),
1417
+ id: hexOrZero(receipt.contract?.id),
1505
1418
  val: (0, import_math4.bn)(receipt.ra),
1506
1419
  pc: (0, import_math4.bn)(receipt.pc),
1507
1420
  is: (0, import_math4.bn)(receipt.is)
@@ -1511,7 +1424,7 @@ function assembleReceiptByType(receipt) {
1511
1424
  case "LOG" /* Log */: {
1512
1425
  const logReceipt = {
1513
1426
  type: import_transactions3.ReceiptType.Log,
1514
- id: hexOrZero(receipt.id || receipt.contractId),
1427
+ id: hexOrZero(receipt.contract?.id),
1515
1428
  val0: (0, import_math4.bn)(receipt.ra),
1516
1429
  val1: (0, import_math4.bn)(receipt.rb),
1517
1430
  val2: (0, import_math4.bn)(receipt.rc),
@@ -1524,7 +1437,7 @@ function assembleReceiptByType(receipt) {
1524
1437
  case "LOG_DATA" /* LogData */: {
1525
1438
  const logDataReceipt = {
1526
1439
  type: import_transactions3.ReceiptType.LogData,
1527
- id: hexOrZero(receipt.id || receipt.contractId),
1440
+ id: hexOrZero(receipt.contract?.id),
1528
1441
  val0: (0, import_math4.bn)(receipt.ra),
1529
1442
  val1: (0, import_math4.bn)(receipt.rb),
1530
1443
  ptr: (0, import_math4.bn)(receipt.ptr),
@@ -1538,8 +1451,8 @@ function assembleReceiptByType(receipt) {
1538
1451
  case "TRANSFER" /* Transfer */: {
1539
1452
  const transferReceipt = {
1540
1453
  type: import_transactions3.ReceiptType.Transfer,
1541
- from: hexOrZero(receipt.id || receipt.contractId),
1542
- to: hexOrZero(receipt.toAddress || receipt?.to),
1454
+ from: hexOrZero(receipt.contract?.id),
1455
+ to: hexOrZero(receipt.toAddress || receipt?.to?.id),
1543
1456
  amount: (0, import_math4.bn)(receipt.amount),
1544
1457
  assetId: hexOrZero(receipt.assetId),
1545
1458
  pc: (0, import_math4.bn)(receipt.pc),
@@ -1550,8 +1463,8 @@ function assembleReceiptByType(receipt) {
1550
1463
  case "TRANSFER_OUT" /* TransferOut */: {
1551
1464
  const transferOutReceipt = {
1552
1465
  type: import_transactions3.ReceiptType.TransferOut,
1553
- from: hexOrZero(receipt.id || receipt.contractId),
1554
- to: hexOrZero(receipt.toAddress || receipt.to),
1466
+ from: hexOrZero(receipt.contract?.id),
1467
+ to: hexOrZero(receipt.toAddress || receipt.to?.id),
1555
1468
  amount: (0, import_math4.bn)(receipt.amount),
1556
1469
  assetId: hexOrZero(receipt.assetId),
1557
1470
  pc: (0, import_math4.bn)(receipt.pc),
@@ -1594,7 +1507,7 @@ function assembleReceiptByType(receipt) {
1594
1507
  return receiptMessageOut;
1595
1508
  }
1596
1509
  case "MINT" /* Mint */: {
1597
- const contractId = hexOrZero(receipt.id || receipt.contractId);
1510
+ const contractId = hexOrZero(receipt.contract?.id);
1598
1511
  const subId = hexOrZero(receipt.subId);
1599
1512
  const assetId = import_transactions3.ReceiptMintCoder.getAssetId(contractId, subId);
1600
1513
  const mintReceipt = {
@@ -1609,7 +1522,7 @@ function assembleReceiptByType(receipt) {
1609
1522
  return mintReceipt;
1610
1523
  }
1611
1524
  case "BURN" /* Burn */: {
1612
- const contractId = hexOrZero(receipt.id || receipt.contractId);
1525
+ const contractId = hexOrZero(receipt.contract?.id);
1613
1526
  const subId = hexOrZero(receipt.subId);
1614
1527
  const assetId = import_transactions3.ReceiptBurnCoder.getAssetId(contractId, subId);
1615
1528
  const burnReceipt = {
@@ -1694,6 +1607,7 @@ var buildBlockExplorerUrl = (options = {}) => {
1694
1607
  var import_math5 = require("@fuel-ts/math");
1695
1608
  var import_transactions4 = require("@fuel-ts/transactions");
1696
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()));
1697
1611
  var getGasUsedFromReceipts = (receipts) => {
1698
1612
  const scriptResult = receipts.filter(
1699
1613
  (receipt) => receipt.type === import_transactions4.ReceiptType.ScriptResult
@@ -1714,28 +1628,18 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
1714
1628
  }
1715
1629
  function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
1716
1630
  const witnessCache = [];
1717
- const chargeableInputs = inputs.filter((input) => {
1718
- const isCoinOrMessage = "owner" in input || "sender" in input;
1719
- if (isCoinOrMessage) {
1720
- if ("predicate" in input && input.predicate && input.predicate !== "0x") {
1721
- return true;
1722
- }
1723
- if (!witnessCache.includes(input.witnessIndex)) {
1724
- witnessCache.push(input.witnessIndex);
1725
- return true;
1726
- }
1727
- }
1728
- return false;
1729
- });
1730
- const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
1731
- const totalGas = chargeableInputs.reduce((total, input) => {
1631
+ const totalGas = inputs.reduce((total, input) => {
1732
1632
  if ("predicate" in input && input.predicate && input.predicate !== "0x") {
1733
1633
  return total.add(
1734
- 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))
1735
1635
  );
1736
1636
  }
1737
- return total.add(gasCosts.ecr1);
1738
- }, (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)());
1739
1643
  return totalGas;
1740
1644
  }
1741
1645
  function getMinGas(params) {
@@ -1747,20 +1651,12 @@ function getMinGas(params) {
1747
1651
  return minGas;
1748
1652
  }
1749
1653
  function getMaxGas(params) {
1750
- const {
1751
- gasPerByte,
1752
- witnessesLength,
1753
- witnessLimit,
1754
- minGas,
1755
- gasLimit = (0, import_math5.bn)(0),
1756
- maxGasPerTx
1757
- } = params;
1654
+ const { gasPerByte, witnessesLength, witnessLimit, minGas, gasLimit = (0, import_math5.bn)(0) } = params;
1758
1655
  let remainingAllowedWitnessGas = (0, import_math5.bn)(0);
1759
1656
  if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
1760
1657
  remainingAllowedWitnessGas = (0, import_math5.bn)(witnessLimit).sub(witnessesLength).mul(gasPerByte);
1761
1658
  }
1762
- const maxGas = remainingAllowedWitnessGas.add(minGas).add(gasLimit);
1763
- return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
1659
+ return remainingAllowedWitnessGas.add(minGas).add(gasLimit);
1764
1660
  }
1765
1661
  function calculateMetadataGasForTxCreate({
1766
1662
  gasCosts,
@@ -1782,10 +1678,6 @@ function calculateMetadataGasForTxScript({
1782
1678
  }) {
1783
1679
  return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
1784
1680
  }
1785
- var calculateGasFee = (params) => {
1786
- const { gas, gasPrice, priceFactor, tip } = params;
1787
- return gas.mul(gasPrice).div(priceFactor).add(tip);
1788
- };
1789
1681
 
1790
1682
  // src/providers/utils/json.ts
1791
1683
  var import_utils7 = require("@fuel-ts/utils");
@@ -1921,6 +1813,28 @@ var NoWitnessByOwnerError = class extends Error {
1921
1813
  name = "NoWitnessByOwnerError";
1922
1814
  };
1923
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
+
1924
1838
  // src/providers/transaction-request/witness.ts
1925
1839
  var import_utils8 = require("@fuel-ts/utils");
1926
1840
  var witnessify = (value) => {
@@ -1934,7 +1848,7 @@ var witnessify = (value) => {
1934
1848
  // src/providers/transaction-request/transaction-request.ts
1935
1849
  var BaseTransactionRequest = class {
1936
1850
  /** Gas price for transaction */
1937
- tip;
1851
+ gasPrice;
1938
1852
  /** Block until which tx cannot be included */
1939
1853
  maturity;
1940
1854
  /** The maximum fee payable by this transaction using BASE_ASSET. */
@@ -1953,7 +1867,7 @@ var BaseTransactionRequest = class {
1953
1867
  * @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
1954
1868
  */
1955
1869
  constructor({
1956
- tip,
1870
+ gasPrice,
1957
1871
  maturity,
1958
1872
  maxFee,
1959
1873
  witnessLimit,
@@ -1961,7 +1875,7 @@ var BaseTransactionRequest = class {
1961
1875
  outputs,
1962
1876
  witnesses
1963
1877
  } = {}) {
1964
- this.tip = (0, import_math7.bn)(tip);
1878
+ this.gasPrice = (0, import_math7.bn)(gasPrice);
1965
1879
  this.maturity = maturity ?? 0;
1966
1880
  this.witnessLimit = witnessLimit ? (0, import_math7.bn)(witnessLimit) : void 0;
1967
1881
  this.maxFee = maxFee ? (0, import_math7.bn)(maxFee) : void 0;
@@ -1972,21 +1886,21 @@ var BaseTransactionRequest = class {
1972
1886
  static getPolicyMeta(req) {
1973
1887
  let policyTypes = 0;
1974
1888
  const policies = [];
1975
- if (req.tip) {
1976
- policyTypes += import_transactions6.PolicyType.Tip;
1977
- 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 });
1978
1892
  }
1979
1893
  if (req.witnessLimit) {
1980
- policyTypes += import_transactions6.PolicyType.WitnessLimit;
1981
- 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 });
1982
1896
  }
1983
1897
  if (req.maturity > 0) {
1984
- policyTypes += import_transactions6.PolicyType.Maturity;
1985
- 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 });
1986
1900
  }
1987
1901
  if (req.maxFee) {
1988
- policyTypes += import_transactions6.PolicyType.MaxFee;
1989
- 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 });
1990
1904
  }
1991
1905
  return {
1992
1906
  policyTypes,
@@ -2020,7 +1934,7 @@ var BaseTransactionRequest = class {
2020
1934
  * @returns The transaction bytes.
2021
1935
  */
2022
1936
  toTransactionBytes() {
2023
- return new import_transactions6.TransactionCoder().encode(this.toTransaction());
1937
+ return new import_transactions7.TransactionCoder().encode(this.toTransaction());
2024
1938
  }
2025
1939
  /**
2026
1940
  * @hidden
@@ -2111,7 +2025,7 @@ var BaseTransactionRequest = class {
2111
2025
  */
2112
2026
  getCoinInputs() {
2113
2027
  return this.inputs.filter(
2114
- (input) => input.type === import_transactions6.InputType.Coin
2028
+ (input) => input.type === import_transactions7.InputType.Coin
2115
2029
  );
2116
2030
  }
2117
2031
  /**
@@ -2121,7 +2035,7 @@ var BaseTransactionRequest = class {
2121
2035
  */
2122
2036
  getCoinOutputs() {
2123
2037
  return this.outputs.filter(
2124
- (output) => output.type === import_transactions6.OutputType.Coin
2038
+ (output) => output.type === import_transactions7.OutputType.Coin
2125
2039
  );
2126
2040
  }
2127
2041
  /**
@@ -2131,7 +2045,7 @@ var BaseTransactionRequest = class {
2131
2045
  */
2132
2046
  getChangeOutputs() {
2133
2047
  return this.outputs.filter(
2134
- (output) => output.type === import_transactions6.OutputType.Change
2048
+ (output) => output.type === import_transactions7.OutputType.Change
2135
2049
  );
2136
2050
  }
2137
2051
  /**
@@ -2143,9 +2057,9 @@ var BaseTransactionRequest = class {
2143
2057
  const ownerAddress = (0, import_address.addressify)(owner);
2144
2058
  const found = this.inputs.find((input) => {
2145
2059
  switch (input.type) {
2146
- case import_transactions6.InputType.Coin:
2060
+ case import_transactions7.InputType.Coin:
2147
2061
  return (0, import_utils9.hexlify)(input.owner) === ownerAddress.toB256();
2148
- case import_transactions6.InputType.Message:
2062
+ case import_transactions7.InputType.Message:
2149
2063
  return (0, import_utils9.hexlify)(input.recipient) === ownerAddress.toB256();
2150
2064
  default:
2151
2065
  return false;
@@ -2158,11 +2072,13 @@ var BaseTransactionRequest = class {
2158
2072
  * assetId, if one it was not added yet.
2159
2073
  *
2160
2074
  * @param coin - Coin resource.
2075
+ * @param predicate - Predicate bytes.
2076
+ * @param predicateData - Predicate data bytes.
2161
2077
  */
2162
2078
  addCoinInput(coin) {
2163
- const { assetId, owner, amount } = coin;
2079
+ const { assetId, owner, amount, id, predicate } = coin;
2164
2080
  let witnessIndex;
2165
- if (coin.predicate) {
2081
+ if (predicate) {
2166
2082
  witnessIndex = 0;
2167
2083
  } else {
2168
2084
  witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
@@ -2171,13 +2087,14 @@ var BaseTransactionRequest = class {
2171
2087
  }
2172
2088
  }
2173
2089
  const input = {
2174
- ...coin,
2175
- type: import_transactions6.InputType.Coin,
2090
+ id,
2091
+ type: import_transactions7.InputType.Coin,
2176
2092
  owner: owner.toB256(),
2177
2093
  amount,
2178
2094
  assetId,
2179
2095
  txPointer: "0x00000000000000000000000000000000",
2180
- witnessIndex
2096
+ witnessIndex,
2097
+ predicate
2181
2098
  };
2182
2099
  this.pushInput(input);
2183
2100
  this.addChangeOutput(owner, assetId);
@@ -2187,12 +2104,14 @@ var BaseTransactionRequest = class {
2187
2104
  * baseAssetId, if one it was not added yet.
2188
2105
  *
2189
2106
  * @param message - Message resource.
2107
+ * @param predicate - Predicate bytes.
2108
+ * @param predicateData - Predicate data bytes.
2190
2109
  */
2191
2110
  addMessageInput(message) {
2192
- const { recipient, sender, amount } = message;
2111
+ const { recipient, sender, amount, predicate, nonce } = message;
2193
2112
  const assetId = import_configs7.BaseAssetId;
2194
2113
  let witnessIndex;
2195
- if (message.predicate) {
2114
+ if (predicate) {
2196
2115
  witnessIndex = 0;
2197
2116
  } else {
2198
2117
  witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
@@ -2201,12 +2120,13 @@ var BaseTransactionRequest = class {
2201
2120
  }
2202
2121
  }
2203
2122
  const input = {
2204
- ...message,
2205
- type: import_transactions6.InputType.Message,
2123
+ nonce,
2124
+ type: import_transactions7.InputType.Message,
2206
2125
  sender: sender.toB256(),
2207
2126
  recipient: recipient.toB256(),
2208
2127
  amount,
2209
- witnessIndex
2128
+ witnessIndex,
2129
+ predicate
2210
2130
  };
2211
2131
  this.pushInput(input);
2212
2132
  this.addChangeOutput(recipient, assetId);
@@ -2246,7 +2166,7 @@ var BaseTransactionRequest = class {
2246
2166
  */
2247
2167
  addCoinOutput(to, amount, assetId = import_configs7.BaseAssetId) {
2248
2168
  this.pushOutput({
2249
- type: import_transactions6.OutputType.Coin,
2169
+ type: import_transactions7.OutputType.Coin,
2250
2170
  to: (0, import_address.addressify)(to).toB256(),
2251
2171
  amount,
2252
2172
  assetId
@@ -2262,7 +2182,7 @@ var BaseTransactionRequest = class {
2262
2182
  addCoinOutputs(to, quantities) {
2263
2183
  quantities.map(coinQuantityfy).forEach((quantity) => {
2264
2184
  this.pushOutput({
2265
- type: import_transactions6.OutputType.Coin,
2185
+ type: import_transactions7.OutputType.Coin,
2266
2186
  to: (0, import_address.addressify)(to).toB256(),
2267
2187
  amount: quantity.amount,
2268
2188
  assetId: quantity.assetId
@@ -2282,7 +2202,7 @@ var BaseTransactionRequest = class {
2282
2202
  );
2283
2203
  if (!changeOutput) {
2284
2204
  this.pushOutput({
2285
- type: import_transactions6.OutputType.Change,
2205
+ type: import_transactions7.OutputType.Change,
2286
2206
  to: (0, import_address.addressify)(to).toB256(),
2287
2207
  assetId
2288
2208
  });
@@ -2316,7 +2236,7 @@ var BaseTransactionRequest = class {
2316
2236
  }
2317
2237
  calculateMaxGas(chainInfo, minGas) {
2318
2238
  const { consensusParameters } = chainInfo;
2319
- const { gasPerByte, maxGasPerTx } = consensusParameters;
2239
+ const { gasPerByte } = consensusParameters;
2320
2240
  const witnessesLength = this.toTransaction().witnesses.reduce(
2321
2241
  (acc, wit) => acc + wit.dataLength,
2322
2242
  0
@@ -2325,8 +2245,7 @@ var BaseTransactionRequest = class {
2325
2245
  gasPerByte,
2326
2246
  minGas,
2327
2247
  witnessesLength,
2328
- witnessLimit: this.witnessLimit,
2329
- maxGasPerTx
2248
+ witnessLimit: this.witnessLimit
2330
2249
  });
2331
2250
  }
2332
2251
  /**
@@ -2344,20 +2263,17 @@ var BaseTransactionRequest = class {
2344
2263
  });
2345
2264
  const updateAssetInput = (assetId, quantity) => {
2346
2265
  const assetInput = findAssetInput(assetId);
2347
- let usedQuantity = quantity;
2348
- if (assetId === import_configs7.BaseAssetId) {
2349
- usedQuantity = (0, import_math7.bn)("1000000000000000000");
2350
- }
2351
2266
  if (assetInput && "assetId" in assetInput) {
2352
2267
  assetInput.id = (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN));
2353
- assetInput.amount = usedQuantity;
2268
+ assetInput.amount = quantity;
2354
2269
  } else {
2355
2270
  this.addResources([
2356
2271
  {
2357
2272
  id: (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN)),
2358
- amount: usedQuantity,
2273
+ amount: quantity,
2359
2274
  assetId,
2360
2275
  owner: resourcesOwner || import_address.Address.fromRandom(),
2276
+ maturity: 0,
2361
2277
  blockCreated: (0, import_math7.bn)(1),
2362
2278
  txCreatedIdx: (0, import_math7.bn)(1)
2363
2279
  }
@@ -2389,16 +2305,20 @@ var BaseTransactionRequest = class {
2389
2305
  toJSON() {
2390
2306
  return normalizeJSON(this);
2391
2307
  }
2392
- updatePredicateGasUsed(inputs) {
2308
+ removeWitness(index) {
2309
+ this.witnesses.splice(index, 1);
2310
+ this.adjustWitnessIndexes(index);
2311
+ }
2312
+ updatePredicateInputs(inputs) {
2393
2313
  this.inputs.forEach((i) => {
2394
2314
  let correspondingInput;
2395
2315
  switch (i.type) {
2396
- case import_transactions6.InputType.Coin:
2397
- 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);
2398
2318
  break;
2399
- case import_transactions6.InputType.Message:
2319
+ case import_transactions7.InputType.Message:
2400
2320
  correspondingInput = inputs.find(
2401
- (x) => x.type === import_transactions6.InputType.Message && x.sender === i.sender
2321
+ (x) => x.type === import_transactions7.InputType.Message && x.sender === i.sender
2402
2322
  );
2403
2323
  break;
2404
2324
  default:
@@ -2411,12 +2331,10 @@ var BaseTransactionRequest = class {
2411
2331
  }
2412
2332
  });
2413
2333
  }
2414
- shiftPredicateData() {
2415
- this.inputs.forEach((input) => {
2416
- if ("predicateData" in input && "paddPredicateData" in input && typeof input.paddPredicateData === "function") {
2417
- input.predicateData = input.paddPredicateData(
2418
- BaseTransactionRequest.getPolicyMeta(this).policies.length
2419
- );
2334
+ adjustWitnessIndexes(removedIndex) {
2335
+ this.inputs.filter(isRequestInputResource).forEach((input) => {
2336
+ if (input.witnessIndex > removedIndex) {
2337
+ input.witnessIndex -= 1;
2420
2338
  }
2421
2339
  });
2422
2340
  }
@@ -2425,25 +2343,25 @@ var BaseTransactionRequest = class {
2425
2343
  // src/providers/transaction-request/create-transaction-request.ts
2426
2344
  var import_configs9 = require("@fuel-ts/address/configs");
2427
2345
  var import_math9 = require("@fuel-ts/math");
2428
- var import_transactions8 = require("@fuel-ts/transactions");
2346
+ var import_transactions9 = require("@fuel-ts/transactions");
2429
2347
  var import_utils13 = require("@fuel-ts/utils");
2430
2348
 
2431
2349
  // src/providers/transaction-request/hash-transaction.ts
2432
2350
  var import_configs8 = require("@fuel-ts/address/configs");
2433
2351
  var import_hasher = require("@fuel-ts/hasher");
2434
2352
  var import_math8 = require("@fuel-ts/math");
2435
- var import_transactions7 = require("@fuel-ts/transactions");
2353
+ var import_transactions8 = require("@fuel-ts/transactions");
2436
2354
  var import_utils11 = require("@fuel-ts/utils");
2437
2355
  var import_ramda2 = require("ramda");
2438
2356
  function hashTransaction(transactionRequest, chainId) {
2439
2357
  const transaction = transactionRequest.toTransaction();
2440
- if (transaction.type === import_transactions7.TransactionType.Script) {
2358
+ if (transaction.type === import_transactions8.TransactionType.Script) {
2441
2359
  transaction.receiptsRoot = import_configs8.ZeroBytes32;
2442
2360
  }
2443
2361
  transaction.inputs = transaction.inputs.map((input) => {
2444
2362
  const inputClone = (0, import_ramda2.clone)(input);
2445
2363
  switch (inputClone.type) {
2446
- case import_transactions7.InputType.Coin: {
2364
+ case import_transactions8.InputType.Coin: {
2447
2365
  inputClone.txPointer = {
2448
2366
  blockHeight: 0,
2449
2367
  txIndex: 0
@@ -2451,11 +2369,11 @@ function hashTransaction(transactionRequest, chainId) {
2451
2369
  inputClone.predicateGasUsed = (0, import_math8.bn)(0);
2452
2370
  return inputClone;
2453
2371
  }
2454
- case import_transactions7.InputType.Message: {
2372
+ case import_transactions8.InputType.Message: {
2455
2373
  inputClone.predicateGasUsed = (0, import_math8.bn)(0);
2456
2374
  return inputClone;
2457
2375
  }
2458
- case import_transactions7.InputType.Contract: {
2376
+ case import_transactions8.InputType.Contract: {
2459
2377
  inputClone.txPointer = {
2460
2378
  blockHeight: 0,
2461
2379
  txIndex: 0
@@ -2473,16 +2391,16 @@ function hashTransaction(transactionRequest, chainId) {
2473
2391
  transaction.outputs = transaction.outputs.map((output) => {
2474
2392
  const outputClone = (0, import_ramda2.clone)(output);
2475
2393
  switch (outputClone.type) {
2476
- case import_transactions7.OutputType.Contract: {
2394
+ case import_transactions8.OutputType.Contract: {
2477
2395
  outputClone.balanceRoot = import_configs8.ZeroBytes32;
2478
2396
  outputClone.stateRoot = import_configs8.ZeroBytes32;
2479
2397
  return outputClone;
2480
2398
  }
2481
- case import_transactions7.OutputType.Change: {
2399
+ case import_transactions8.OutputType.Change: {
2482
2400
  outputClone.amount = (0, import_math8.bn)(0);
2483
2401
  return outputClone;
2484
2402
  }
2485
- case import_transactions7.OutputType.Variable: {
2403
+ case import_transactions8.OutputType.Variable: {
2486
2404
  outputClone.to = import_configs8.ZeroBytes32;
2487
2405
  outputClone.amount = (0, import_math8.bn)(0);
2488
2406
  outputClone.assetId = import_configs8.ZeroBytes32;
@@ -2495,7 +2413,7 @@ function hashTransaction(transactionRequest, chainId) {
2495
2413
  transaction.witnessesCount = 0;
2496
2414
  transaction.witnesses = [];
2497
2415
  const chainIdBytes = (0, import_hasher.uint64ToBytesBE)(chainId);
2498
- 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)]);
2499
2417
  return (0, import_hasher.sha256)(concatenatedData);
2500
2418
  }
2501
2419
 
@@ -2531,7 +2449,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2531
2449
  return new this(obj);
2532
2450
  }
2533
2451
  /** Type of the transaction */
2534
- type = import_transactions8.TransactionType.Create;
2452
+ type = import_transactions9.TransactionType.Create;
2535
2453
  /** Witness index of contract bytecode to create */
2536
2454
  bytecodeWitnessIndex;
2537
2455
  /** Salt */
@@ -2564,10 +2482,11 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2564
2482
  const bytecodeWitnessIndex = this.bytecodeWitnessIndex;
2565
2483
  const storageSlots = this.storageSlots?.map(storageSlotify) ?? [];
2566
2484
  return {
2567
- type: import_transactions8.TransactionType.Create,
2485
+ type: import_transactions9.TransactionType.Create,
2568
2486
  ...baseTransaction,
2487
+ bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
2569
2488
  bytecodeWitnessIndex,
2570
- storageSlotsCount: (0, import_math9.bn)(storageSlots.length),
2489
+ storageSlotsCount: storageSlots.length,
2571
2490
  salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs9.ZeroBytes32,
2572
2491
  storageSlots
2573
2492
  };
@@ -2579,7 +2498,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2579
2498
  */
2580
2499
  getContractCreatedOutputs() {
2581
2500
  return this.outputs.filter(
2582
- (output) => output.type === import_transactions8.OutputType.ContractCreated
2501
+ (output) => output.type === import_transactions9.OutputType.ContractCreated
2583
2502
  );
2584
2503
  }
2585
2504
  /**
@@ -2600,7 +2519,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2600
2519
  */
2601
2520
  addContractCreatedOutput(contractId, stateRoot) {
2602
2521
  this.pushOutput({
2603
- type: import_transactions8.OutputType.ContractCreated,
2522
+ type: import_transactions9.OutputType.ContractCreated,
2604
2523
  contractId,
2605
2524
  stateRoot
2606
2525
  });
@@ -2620,7 +2539,7 @@ var import_abi_coder3 = require("@fuel-ts/abi-coder");
2620
2539
  var import_address2 = require("@fuel-ts/address");
2621
2540
  var import_configs10 = require("@fuel-ts/address/configs");
2622
2541
  var import_math10 = require("@fuel-ts/math");
2623
- var import_transactions9 = require("@fuel-ts/transactions");
2542
+ var import_transactions10 = require("@fuel-ts/transactions");
2624
2543
  var import_utils15 = require("@fuel-ts/utils");
2625
2544
 
2626
2545
  // src/providers/transaction-request/scripts.ts
@@ -2658,7 +2577,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2658
2577
  return new this(obj);
2659
2578
  }
2660
2579
  /** Type of the transaction */
2661
- type = import_transactions9.TransactionType.Script;
2580
+ type = import_transactions10.TransactionType.Script;
2662
2581
  /** Gas limit for transaction */
2663
2582
  gasLimit;
2664
2583
  /** Script to execute */
@@ -2687,11 +2606,11 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2687
2606
  const script = (0, import_utils15.arrayify)(this.script ?? "0x");
2688
2607
  const scriptData = (0, import_utils15.arrayify)(this.scriptData ?? "0x");
2689
2608
  return {
2690
- type: import_transactions9.TransactionType.Script,
2609
+ type: import_transactions10.TransactionType.Script,
2691
2610
  scriptGasLimit: this.gasLimit,
2692
2611
  ...super.getBaseTransaction(),
2693
- scriptLength: (0, import_math10.bn)(script.length),
2694
- scriptDataLength: (0, import_math10.bn)(scriptData.length),
2612
+ scriptLength: script.length,
2613
+ scriptDataLength: scriptData.length,
2695
2614
  receiptsRoot: import_configs10.ZeroBytes32,
2696
2615
  script: (0, import_utils15.hexlify)(script),
2697
2616
  scriptData: (0, import_utils15.hexlify)(scriptData)
@@ -2704,7 +2623,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2704
2623
  */
2705
2624
  getContractInputs() {
2706
2625
  return this.inputs.filter(
2707
- (input) => input.type === import_transactions9.InputType.Contract
2626
+ (input) => input.type === import_transactions10.InputType.Contract
2708
2627
  );
2709
2628
  }
2710
2629
  /**
@@ -2714,7 +2633,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2714
2633
  */
2715
2634
  getContractOutputs() {
2716
2635
  return this.outputs.filter(
2717
- (output) => output.type === import_transactions9.OutputType.Contract
2636
+ (output) => output.type === import_transactions10.OutputType.Contract
2718
2637
  );
2719
2638
  }
2720
2639
  /**
@@ -2724,7 +2643,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2724
2643
  */
2725
2644
  getVariableOutputs() {
2726
2645
  return this.outputs.filter(
2727
- (output) => output.type === import_transactions9.OutputType.Variable
2646
+ (output) => output.type === import_transactions10.OutputType.Variable
2728
2647
  );
2729
2648
  }
2730
2649
  /**
@@ -2747,7 +2666,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2747
2666
  let outputsNumber = numberOfVariables;
2748
2667
  while (outputsNumber) {
2749
2668
  this.pushOutput({
2750
- type: import_transactions9.OutputType.Variable
2669
+ type: import_transactions10.OutputType.Variable
2751
2670
  });
2752
2671
  outputsNumber -= 1;
2753
2672
  }
@@ -2755,7 +2674,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2755
2674
  }
2756
2675
  calculateMaxGas(chainInfo, minGas) {
2757
2676
  const { consensusParameters } = chainInfo;
2758
- const { gasPerByte, maxGasPerTx } = consensusParameters;
2677
+ const { gasPerByte } = consensusParameters;
2759
2678
  const witnessesLength = this.toTransaction().witnesses.reduce(
2760
2679
  (acc, wit) => acc + wit.dataLength,
2761
2680
  0
@@ -2765,8 +2684,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2765
2684
  minGas,
2766
2685
  witnessesLength,
2767
2686
  witnessLimit: this.witnessLimit,
2768
- gasLimit: this.gasLimit,
2769
- maxGasPerTx
2687
+ gasLimit: this.gasLimit
2770
2688
  });
2771
2689
  }
2772
2690
  /**
@@ -2781,12 +2699,12 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2781
2699
  return this;
2782
2700
  }
2783
2701
  const inputIndex = super.pushInput({
2784
- type: import_transactions9.InputType.Contract,
2702
+ type: import_transactions10.InputType.Contract,
2785
2703
  contractId: contractAddress.toB256(),
2786
2704
  txPointer: "0x00000000000000000000000000000000"
2787
2705
  });
2788
2706
  this.pushOutput({
2789
- type: import_transactions9.OutputType.Contract,
2707
+ type: import_transactions10.OutputType.Contract,
2790
2708
  inputIndex
2791
2709
  });
2792
2710
  return this;
@@ -2823,17 +2741,17 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2823
2741
 
2824
2742
  // src/providers/transaction-request/utils.ts
2825
2743
  var import_errors9 = require("@fuel-ts/errors");
2826
- var import_transactions10 = require("@fuel-ts/transactions");
2744
+ var import_transactions11 = require("@fuel-ts/transactions");
2827
2745
  var transactionRequestify = (obj) => {
2828
2746
  if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
2829
2747
  return obj;
2830
2748
  }
2831
2749
  const { type } = obj;
2832
2750
  switch (obj.type) {
2833
- case import_transactions10.TransactionType.Script: {
2751
+ case import_transactions11.TransactionType.Script: {
2834
2752
  return ScriptTransactionRequest.from(obj);
2835
2753
  }
2836
- case import_transactions10.TransactionType.Create: {
2754
+ case import_transactions11.TransactionType.Create: {
2837
2755
  return CreateTransactionRequest.from(obj);
2838
2756
  }
2839
2757
  default: {
@@ -2841,59 +2759,42 @@ var transactionRequestify = (obj) => {
2841
2759
  }
2842
2760
  }
2843
2761
  };
2844
- var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
2845
- (acc, input) => {
2846
- if (input.type === import_transactions10.InputType.Coin && input.owner === owner) {
2847
- acc.utxos.push(input.id);
2848
- }
2849
- if (input.type === import_transactions10.InputType.Message && input.recipient === owner) {
2850
- acc.messages.push(input.nonce);
2851
- }
2852
- return acc;
2853
- },
2854
- {
2855
- utxos: [],
2856
- messages: []
2857
- }
2858
- );
2859
2762
 
2860
2763
  // src/providers/transaction-response/transaction-response.ts
2861
2764
  var import_errors13 = require("@fuel-ts/errors");
2862
- var import_math15 = require("@fuel-ts/math");
2765
+ var import_math14 = require("@fuel-ts/math");
2863
2766
  var import_transactions18 = require("@fuel-ts/transactions");
2864
- var import_utils20 = require("@fuel-ts/utils");
2767
+ var import_utils21 = require("@fuel-ts/utils");
2865
2768
 
2866
2769
  // src/providers/transaction-summary/assemble-transaction-summary.ts
2867
- var import_math14 = require("@fuel-ts/math");
2868
- var import_transactions16 = require("@fuel-ts/transactions");
2869
- var import_utils18 = require("@fuel-ts/utils");
2770
+ var import_utils19 = require("@fuel-ts/utils");
2870
2771
 
2871
2772
  // src/providers/transaction-summary/calculate-transaction-fee.ts
2872
2773
  var import_math11 = require("@fuel-ts/math");
2873
- var import_transactions11 = require("@fuel-ts/transactions");
2774
+ var import_transactions12 = require("@fuel-ts/transactions");
2874
2775
  var import_utils16 = require("@fuel-ts/utils");
2875
2776
  var calculateTransactionFee = (params) => {
2876
2777
  const {
2877
- gasPrice,
2778
+ gasUsed,
2878
2779
  rawPayload,
2879
- tip,
2880
- consensusParameters: { gasCosts, feeParams, maxGasPerTx }
2780
+ consensusParameters: { gasCosts, feeParams }
2881
2781
  } = params;
2882
2782
  const gasPerByte = (0, import_math11.bn)(feeParams.gasPerByte);
2883
2783
  const gasPriceFactor = (0, import_math11.bn)(feeParams.gasPriceFactor);
2884
2784
  const transactionBytes = (0, import_utils16.arrayify)(rawPayload);
2885
- const [transaction] = new import_transactions11.TransactionCoder().decode(transactionBytes, 0);
2886
- 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) {
2887
2787
  return {
2888
2788
  fee: (0, import_math11.bn)(0),
2889
2789
  minFee: (0, import_math11.bn)(0),
2890
- maxFee: (0, import_math11.bn)(0)
2790
+ maxFee: (0, import_math11.bn)(0),
2791
+ feeFromGasUsed: (0, import_math11.bn)(0)
2891
2792
  };
2892
2793
  }
2893
2794
  const { type, witnesses, inputs, policies } = transaction;
2894
2795
  let metadataGas = (0, import_math11.bn)(0);
2895
2796
  let gasLimit = (0, import_math11.bn)(0);
2896
- if (type === import_transactions11.TransactionType.Create) {
2797
+ if (type === import_transactions12.TransactionType.Create) {
2897
2798
  const { bytecodeWitnessIndex, storageSlots } = transaction;
2898
2799
  const contractBytesSize = (0, import_math11.bn)((0, import_utils16.arrayify)(witnesses[bytecodeWitnessIndex].data).length);
2899
2800
  metadataGas = calculateMetadataGasForTxCreate({
@@ -2919,32 +2820,25 @@ var calculateTransactionFee = (params) => {
2919
2820
  metadataGas,
2920
2821
  txBytesSize: transactionBytes.length
2921
2822
  });
2922
- 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;
2923
2825
  const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
2924
2826
  const maxGas = getMaxGas({
2925
2827
  gasPerByte,
2926
2828
  minGas,
2927
2829
  witnessesLength,
2928
2830
  gasLimit,
2929
- witnessLimit,
2930
- maxGasPerTx
2931
- });
2932
- const minFee = calculateGasFee({
2933
- gasPrice,
2934
- gas: minGas,
2935
- priceFactor: gasPriceFactor,
2936
- tip
2937
- });
2938
- const maxFee = calculateGasFee({
2939
- gasPrice,
2940
- gas: maxGas,
2941
- priceFactor: gasPriceFactor,
2942
- tip
2831
+ witnessLimit
2943
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);
2944
2837
  return {
2838
+ fee,
2945
2839
  minFee,
2946
2840
  maxFee,
2947
- fee: maxFee
2841
+ feeFromGasUsed
2948
2842
  };
2949
2843
  };
2950
2844
 
@@ -2952,7 +2846,7 @@ var calculateTransactionFee = (params) => {
2952
2846
  var import_configs11 = require("@fuel-ts/address/configs");
2953
2847
  var import_errors11 = require("@fuel-ts/errors");
2954
2848
  var import_math13 = require("@fuel-ts/math");
2955
- var import_transactions14 = require("@fuel-ts/transactions");
2849
+ var import_transactions15 = require("@fuel-ts/transactions");
2956
2850
 
2957
2851
  // src/providers/transaction-summary/call.ts
2958
2852
  var import_abi_coder4 = require("@fuel-ts/abi-coder");
@@ -3000,7 +2894,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
3000
2894
 
3001
2895
  // src/providers/transaction-summary/input.ts
3002
2896
  var import_errors10 = require("@fuel-ts/errors");
3003
- var import_transactions12 = require("@fuel-ts/transactions");
2897
+ var import_transactions13 = require("@fuel-ts/transactions");
3004
2898
  function getInputsByTypes(inputs, types) {
3005
2899
  return inputs.filter((i) => types.includes(i.type));
3006
2900
  }
@@ -3008,16 +2902,16 @@ function getInputsByType(inputs, type) {
3008
2902
  return inputs.filter((i) => i.type === type);
3009
2903
  }
3010
2904
  function getInputsCoin(inputs) {
3011
- return getInputsByType(inputs, import_transactions12.InputType.Coin);
2905
+ return getInputsByType(inputs, import_transactions13.InputType.Coin);
3012
2906
  }
3013
2907
  function getInputsMessage(inputs) {
3014
- return getInputsByType(inputs, import_transactions12.InputType.Message);
2908
+ return getInputsByType(inputs, import_transactions13.InputType.Message);
3015
2909
  }
3016
2910
  function getInputsCoinAndMessage(inputs) {
3017
- return getInputsByTypes(inputs, [import_transactions12.InputType.Coin, import_transactions12.InputType.Message]);
2911
+ return getInputsByTypes(inputs, [import_transactions13.InputType.Coin, import_transactions13.InputType.Message]);
3018
2912
  }
3019
2913
  function getInputsContract(inputs) {
3020
- return getInputsByType(inputs, import_transactions12.InputType.Contract);
2914
+ return getInputsByType(inputs, import_transactions13.InputType.Contract);
3021
2915
  }
3022
2916
  function getInputFromAssetId(inputs, assetId) {
3023
2917
  const coinInputs = getInputsCoin(inputs);
@@ -3036,7 +2930,7 @@ function getInputContractFromIndex(inputs, inputIndex) {
3036
2930
  if (!contractInput) {
3037
2931
  return void 0;
3038
2932
  }
3039
- if (contractInput.type !== import_transactions12.InputType.Contract) {
2933
+ if (contractInput.type !== import_transactions13.InputType.Contract) {
3040
2934
  throw new import_errors10.FuelError(
3041
2935
  import_errors10.ErrorCode.INVALID_TRANSACTION_INPUT,
3042
2936
  `Contract input should be of type 'contract'.`
@@ -3045,34 +2939,34 @@ function getInputContractFromIndex(inputs, inputIndex) {
3045
2939
  return contractInput;
3046
2940
  }
3047
2941
  function getInputAccountAddress(input) {
3048
- if (input.type === import_transactions12.InputType.Coin) {
2942
+ if (input.type === import_transactions13.InputType.Coin) {
3049
2943
  return input.owner.toString();
3050
2944
  }
3051
- if (input.type === import_transactions12.InputType.Message) {
2945
+ if (input.type === import_transactions13.InputType.Message) {
3052
2946
  return input.recipient.toString();
3053
2947
  }
3054
2948
  return "";
3055
2949
  }
3056
2950
 
3057
2951
  // src/providers/transaction-summary/output.ts
3058
- var import_transactions13 = require("@fuel-ts/transactions");
2952
+ var import_transactions14 = require("@fuel-ts/transactions");
3059
2953
  function getOutputsByType(outputs, type) {
3060
2954
  return outputs.filter((o) => o.type === type);
3061
2955
  }
3062
2956
  function getOutputsContractCreated(outputs) {
3063
- return getOutputsByType(outputs, import_transactions13.OutputType.ContractCreated);
2957
+ return getOutputsByType(outputs, import_transactions14.OutputType.ContractCreated);
3064
2958
  }
3065
2959
  function getOutputsCoin(outputs) {
3066
- return getOutputsByType(outputs, import_transactions13.OutputType.Coin);
2960
+ return getOutputsByType(outputs, import_transactions14.OutputType.Coin);
3067
2961
  }
3068
2962
  function getOutputsChange(outputs) {
3069
- return getOutputsByType(outputs, import_transactions13.OutputType.Change);
2963
+ return getOutputsByType(outputs, import_transactions14.OutputType.Change);
3070
2964
  }
3071
2965
  function getOutputsContract(outputs) {
3072
- return getOutputsByType(outputs, import_transactions13.OutputType.Contract);
2966
+ return getOutputsByType(outputs, import_transactions14.OutputType.Contract);
3073
2967
  }
3074
2968
  function getOutputsVariable(outputs) {
3075
- return getOutputsByType(outputs, import_transactions13.OutputType.Variable);
2969
+ return getOutputsByType(outputs, import_transactions14.OutputType.Variable);
3076
2970
  }
3077
2971
 
3078
2972
  // src/providers/transaction-summary/types.ts
@@ -3119,11 +3013,11 @@ function getReceiptsByType(receipts, type) {
3119
3013
  }
3120
3014
  function getTransactionTypeName(transactionType) {
3121
3015
  switch (transactionType) {
3122
- case import_transactions14.TransactionType.Mint:
3016
+ case import_transactions15.TransactionType.Mint:
3123
3017
  return "Mint" /* Mint */;
3124
- case import_transactions14.TransactionType.Create:
3018
+ case import_transactions15.TransactionType.Create:
3125
3019
  return "Create" /* Create */;
3126
- case import_transactions14.TransactionType.Script:
3020
+ case import_transactions15.TransactionType.Script:
3127
3021
  return "Script" /* Script */;
3128
3022
  default:
3129
3023
  throw new import_errors11.FuelError(
@@ -3149,10 +3043,10 @@ function hasSameAssetId(a) {
3149
3043
  return (b) => a.assetId === b.assetId;
3150
3044
  }
3151
3045
  function getReceiptsCall(receipts) {
3152
- return getReceiptsByType(receipts, import_transactions14.ReceiptType.Call);
3046
+ return getReceiptsByType(receipts, import_transactions15.ReceiptType.Call);
3153
3047
  }
3154
3048
  function getReceiptsMessageOut(receipts) {
3155
- return getReceiptsByType(receipts, import_transactions14.ReceiptType.MessageOut);
3049
+ return getReceiptsByType(receipts, import_transactions15.ReceiptType.MessageOut);
3156
3050
  }
3157
3051
  var mergeAssets = (op1, op2) => {
3158
3052
  const assets1 = op1.assetsSent || [];
@@ -3191,7 +3085,7 @@ function addOperation(operations, toAdd) {
3191
3085
  return allOperations;
3192
3086
  }
3193
3087
  function getReceiptsTransferOut(receipts) {
3194
- return getReceiptsByType(receipts, import_transactions14.ReceiptType.TransferOut);
3088
+ return getReceiptsByType(receipts, import_transactions15.ReceiptType.TransferOut);
3195
3089
  }
3196
3090
  function getWithdrawFromFuelOperations({
3197
3091
  inputs,
@@ -3351,11 +3245,11 @@ function getTransferOperations({
3351
3245
  });
3352
3246
  const transferReceipts = getReceiptsByType(
3353
3247
  receipts,
3354
- import_transactions14.ReceiptType.Transfer
3248
+ import_transactions15.ReceiptType.Transfer
3355
3249
  );
3356
3250
  const transferOutReceipts = getReceiptsByType(
3357
3251
  receipts,
3358
- import_transactions14.ReceiptType.TransferOut
3252
+ import_transactions15.ReceiptType.TransferOut
3359
3253
  );
3360
3254
  [...transferReceipts, ...transferOutReceipts].forEach((receipt) => {
3361
3255
  const operation = extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs);
@@ -3440,17 +3334,17 @@ function getOperations({
3440
3334
  }
3441
3335
 
3442
3336
  // src/providers/transaction-summary/receipt.ts
3443
- var import_transactions15 = require("@fuel-ts/transactions");
3337
+ var import_transactions16 = require("@fuel-ts/transactions");
3444
3338
  var processGqlReceipt = (gqlReceipt) => {
3445
3339
  const receipt = assembleReceiptByType(gqlReceipt);
3446
3340
  switch (receipt.type) {
3447
- case import_transactions15.ReceiptType.ReturnData: {
3341
+ case import_transactions16.ReceiptType.ReturnData: {
3448
3342
  return {
3449
3343
  ...receipt,
3450
3344
  data: gqlReceipt.data || "0x"
3451
3345
  };
3452
3346
  }
3453
- case import_transactions15.ReceiptType.LogData: {
3347
+ case import_transactions16.ReceiptType.LogData: {
3454
3348
  return {
3455
3349
  ...receipt,
3456
3350
  data: gqlReceipt.data || "0x"
@@ -3463,7 +3357,7 @@ var processGqlReceipt = (gqlReceipt) => {
3463
3357
  var extractMintedAssetsFromReceipts = (receipts) => {
3464
3358
  const mintedAssets = [];
3465
3359
  receipts.forEach((receipt) => {
3466
- if (receipt.type === import_transactions15.ReceiptType.Mint) {
3360
+ if (receipt.type === import_transactions16.ReceiptType.Mint) {
3467
3361
  mintedAssets.push({
3468
3362
  subId: receipt.subId,
3469
3363
  contractId: receipt.contractId,
@@ -3477,7 +3371,7 @@ var extractMintedAssetsFromReceipts = (receipts) => {
3477
3371
  var extractBurnedAssetsFromReceipts = (receipts) => {
3478
3372
  const burnedAssets = [];
3479
3373
  receipts.forEach((receipt) => {
3480
- if (receipt.type === import_transactions15.ReceiptType.Burn) {
3374
+ if (receipt.type === import_transactions16.ReceiptType.Burn) {
3481
3375
  burnedAssets.push({
3482
3376
  subId: receipt.subId,
3483
3377
  contractId: receipt.contractId,
@@ -3558,12 +3452,10 @@ function assembleTransactionSummary(params) {
3558
3452
  gqlTransactionStatus,
3559
3453
  abiMap = {},
3560
3454
  maxInputs,
3561
- gasCosts,
3562
- maxGasPerTx,
3563
- gasPrice
3455
+ gasCosts
3564
3456
  } = params;
3565
3457
  const gasUsed = getGasUsedFromReceipts(receipts);
3566
- const rawPayload = (0, import_utils18.hexlify)(transactionBytes);
3458
+ const rawPayload = (0, import_utils19.hexlify)(transactionBytes);
3567
3459
  const operations = getOperations({
3568
3460
  transactionType: transaction.type,
3569
3461
  inputs: transaction.inputs || [],
@@ -3574,14 +3466,11 @@ function assembleTransactionSummary(params) {
3574
3466
  maxInputs
3575
3467
  });
3576
3468
  const typeName = getTransactionTypeName(transaction.type);
3577
- const tip = (0, import_math14.bn)(transaction.policies?.find((policy) => policy.type === import_transactions16.PolicyType.Tip)?.data);
3578
3469
  const { fee } = calculateTransactionFee({
3579
- gasPrice,
3470
+ gasUsed,
3580
3471
  rawPayload,
3581
- tip,
3582
3472
  consensusParameters: {
3583
3473
  gasCosts,
3584
- maxGasPerTx,
3585
3474
  feeParams: {
3586
3475
  gasPerByte,
3587
3476
  gasPriceFactor
@@ -3593,7 +3482,7 @@ function assembleTransactionSummary(params) {
3593
3482
  const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
3594
3483
  let date;
3595
3484
  if (time) {
3596
- date = import_utils18.DateTime.fromTai64(time);
3485
+ date = import_utils19.DateTime.fromTai64(time);
3597
3486
  }
3598
3487
  const transactionSummary = {
3599
3488
  id,
@@ -3641,7 +3530,7 @@ var TransactionResponse = class {
3641
3530
  /** Current provider */
3642
3531
  provider;
3643
3532
  /** Gas used on the transaction */
3644
- gasUsed = (0, import_math15.bn)(0);
3533
+ gasUsed = (0, import_math14.bn)(0);
3645
3534
  /** The graphql Transaction with receipts object. */
3646
3535
  gqlTransaction;
3647
3536
  abis;
@@ -3700,7 +3589,7 @@ var TransactionResponse = class {
3700
3589
  */
3701
3590
  decodeTransaction(transactionWithReceipts) {
3702
3591
  return new import_transactions18.TransactionCoder().decode(
3703
- (0, import_utils20.arrayify)(transactionWithReceipts.rawPayload),
3592
+ (0, import_utils21.arrayify)(transactionWithReceipts.rawPayload),
3704
3593
  0
3705
3594
  )?.[0];
3706
3595
  }
@@ -3719,27 +3608,20 @@ var TransactionResponse = class {
3719
3608
  const decodedTransaction = this.decodeTransaction(
3720
3609
  transaction
3721
3610
  );
3722
- let txReceipts = [];
3723
- if (transaction?.status && "receipts" in transaction.status) {
3724
- txReceipts = transaction.status.receipts;
3725
- }
3726
- const receipts = txReceipts.map(processGqlReceipt) || [];
3727
- const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
3728
- const gasPrice = await this.provider.getLatestGasPrice();
3611
+ const receipts = transaction.receipts?.map(processGqlReceipt) || [];
3612
+ const { gasPerByte, gasPriceFactor, gasCosts } = this.provider.getGasConfig();
3729
3613
  const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
3730
3614
  const transactionSummary = assembleTransactionSummary({
3731
3615
  id: this.id,
3732
3616
  receipts,
3733
3617
  transaction: decodedTransaction,
3734
- transactionBytes: (0, import_utils20.arrayify)(transaction.rawPayload),
3618
+ transactionBytes: (0, import_utils21.arrayify)(transaction.rawPayload),
3735
3619
  gqlTransactionStatus: transaction.status,
3736
3620
  gasPerByte,
3737
3621
  gasPriceFactor,
3738
3622
  abiMap: contractsAbiMap,
3739
3623
  maxInputs,
3740
- gasCosts,
3741
- maxGasPerTx,
3742
- gasPrice
3624
+ gasCosts
3743
3625
  });
3744
3626
  return transactionSummary;
3745
3627
  }
@@ -3866,29 +3748,29 @@ var processGqlChain = (chain) => {
3866
3748
  const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
3867
3749
  return {
3868
3750
  name,
3869
- baseChainHeight: (0, import_math16.bn)(daHeight),
3751
+ baseChainHeight: (0, import_math15.bn)(daHeight),
3870
3752
  consensusParameters: {
3871
- contractMaxSize: (0, import_math16.bn)(contractParams.contractMaxSize),
3872
- maxInputs: (0, import_math16.bn)(txParams.maxInputs),
3873
- maxOutputs: (0, import_math16.bn)(txParams.maxOutputs),
3874
- maxWitnesses: (0, import_math16.bn)(txParams.maxWitnesses),
3875
- maxGasPerTx: (0, import_math16.bn)(txParams.maxGasPerTx),
3876
- maxScriptLength: (0, import_math16.bn)(scriptParams.maxScriptLength),
3877
- maxScriptDataLength: (0, import_math16.bn)(scriptParams.maxScriptDataLength),
3878
- maxStorageSlots: (0, import_math16.bn)(contractParams.maxStorageSlots),
3879
- maxPredicateLength: (0, import_math16.bn)(predicateParams.maxPredicateLength),
3880
- maxPredicateDataLength: (0, import_math16.bn)(predicateParams.maxPredicateDataLength),
3881
- maxGasPerPredicate: (0, import_math16.bn)(predicateParams.maxGasPerPredicate),
3882
- gasPriceFactor: (0, import_math16.bn)(feeParams.gasPriceFactor),
3883
- gasPerByte: (0, import_math16.bn)(feeParams.gasPerByte),
3884
- maxMessageDataLength: (0, import_math16.bn)(predicateParams.maxMessageDataLength),
3885
- 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),
3886
3768
  gasCosts
3887
3769
  },
3888
3770
  gasCosts,
3889
3771
  latestBlock: {
3890
3772
  id: latestBlock.id,
3891
- height: (0, import_math16.bn)(latestBlock.height),
3773
+ height: (0, import_math15.bn)(latestBlock.header.height),
3892
3774
  time: latestBlock.header.time,
3893
3775
  transactions: latestBlock.transactions.map((i) => ({
3894
3776
  id: i.id
@@ -3982,8 +3864,10 @@ var _Provider = class {
3982
3864
  * Returns some helpful parameters related to gas fees.
3983
3865
  */
3984
3866
  getGasConfig() {
3867
+ const { minGasPrice } = this.getNode();
3985
3868
  const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
3986
3869
  return {
3870
+ minGasPrice,
3987
3871
  maxGasPerTx,
3988
3872
  maxGasPerPredicate,
3989
3873
  gasPriceFactor,
@@ -4081,7 +3965,7 @@ var _Provider = class {
4081
3965
  */
4082
3966
  async getBlockNumber() {
4083
3967
  const { chain } = await this.operations.getChain();
4084
- return (0, import_math16.bn)(chain.latestBlock.height, 10);
3968
+ return (0, import_math15.bn)(chain.latestBlock.header.height, 10);
4085
3969
  }
4086
3970
  /**
4087
3971
  * Returns the chain information.
@@ -4091,11 +3975,13 @@ var _Provider = class {
4091
3975
  async fetchNode() {
4092
3976
  const { nodeInfo } = await this.operations.getNodeInfo();
4093
3977
  const processedNodeInfo = {
4094
- maxDepth: (0, import_math16.bn)(nodeInfo.maxDepth),
4095
- 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),
4096
3981
  nodeVersion: nodeInfo.nodeVersion,
4097
3982
  utxoValidation: nodeInfo.utxoValidation,
4098
- vmBacktrace: nodeInfo.vmBacktrace
3983
+ vmBacktrace: nodeInfo.vmBacktrace,
3984
+ peers: nodeInfo.peers
4099
3985
  };
4100
3986
  _Provider.nodeInfoCache[this.url] = processedNodeInfo;
4101
3987
  return processedNodeInfo;
@@ -4137,7 +4023,7 @@ var _Provider = class {
4137
4023
  if (estimateTxDependencies) {
4138
4024
  await this.estimateTxDependencies(transactionRequest);
4139
4025
  }
4140
- const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
4026
+ const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
4141
4027
  let abis;
4142
4028
  if (transactionRequest.type === import_transactions19.TransactionType.Script) {
4143
4029
  abis = transactionRequest.abis;
@@ -4180,14 +4066,15 @@ var _Provider = class {
4180
4066
  if (estimateTxDependencies) {
4181
4067
  return this.estimateTxDependencies(transactionRequest);
4182
4068
  }
4183
- const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
4184
- const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4185
- encodedTransactions: encodedTransaction,
4069
+ const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
4070
+ const { dryRun: gqlReceipts } = await this.operations.dryRun({
4071
+ encodedTransaction,
4186
4072
  utxoValidation: utxoValidation || false
4187
4073
  });
4188
- const [{ receipts: rawReceipts, status }] = dryRunStatuses;
4189
- const receipts = rawReceipts.map(processGqlReceipt);
4190
- return { receipts, dryrunStatus: status };
4074
+ const receipts = gqlReceipts.map(processGqlReceipt);
4075
+ return {
4076
+ receipts
4077
+ };
4191
4078
  }
4192
4079
  /**
4193
4080
  * Verifies whether enough gas is available to complete transaction.
@@ -4198,13 +4085,13 @@ var _Provider = class {
4198
4085
  async estimatePredicates(transactionRequest) {
4199
4086
  const shouldEstimatePredicates = Boolean(
4200
4087
  transactionRequest.inputs.find(
4201
- (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()
4202
4089
  )
4203
4090
  );
4204
4091
  if (!shouldEstimatePredicates) {
4205
4092
  return transactionRequest;
4206
4093
  }
4207
- const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
4094
+ const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
4208
4095
  const response = await this.operations.estimatePredicates({
4209
4096
  encodedTransaction
4210
4097
  });
@@ -4213,7 +4100,7 @@ var _Provider = class {
4213
4100
  } = response;
4214
4101
  if (inputs) {
4215
4102
  inputs.forEach((input, index) => {
4216
- 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)) {
4217
4104
  transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
4218
4105
  }
4219
4106
  });
@@ -4226,6 +4113,9 @@ var _Provider = class {
4226
4113
  * If there are missing variable outputs,
4227
4114
  * `addVariableOutputs` is called on the transaction.
4228
4115
  *
4116
+ * @privateRemarks
4117
+ * TODO: Investigate support for missing contract IDs
4118
+ * TODO: Add support for missing output messages
4229
4119
  *
4230
4120
  * @param transactionRequest - The transaction request object.
4231
4121
  * @returns A promise.
@@ -4238,19 +4128,16 @@ var _Provider = class {
4238
4128
  missingContractIds: []
4239
4129
  };
4240
4130
  }
4131
+ await this.estimatePredicates(transactionRequest);
4241
4132
  let receipts = [];
4242
4133
  const missingContractIds = [];
4243
4134
  let outputVariables = 0;
4244
- let dryrunStatus;
4245
4135
  for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
4246
- const {
4247
- dryRun: [{ receipts: rawReceipts, status }]
4248
- } = await this.operations.dryRun({
4249
- encodedTransactions: [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())],
4136
+ const { dryRun: gqlReceipts } = await this.operations.dryRun({
4137
+ encodedTransaction: (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes()),
4250
4138
  utxoValidation: false
4251
4139
  });
4252
- receipts = rawReceipts.map(processGqlReceipt);
4253
- dryrunStatus = status;
4140
+ receipts = gqlReceipts.map(processGqlReceipt);
4254
4141
  const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
4255
4142
  const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
4256
4143
  if (hasMissingOutputs) {
@@ -4260,10 +4147,6 @@ var _Provider = class {
4260
4147
  transactionRequest.addContractInputAndOutput(import_address3.Address.fromString(contractId));
4261
4148
  missingContractIds.push(contractId);
4262
4149
  });
4263
- const { maxFee } = await this.estimateTxGasAndFee({
4264
- transactionRequest
4265
- });
4266
- transactionRequest.maxFee = maxFee;
4267
4150
  } else {
4268
4151
  break;
4269
4152
  }
@@ -4271,139 +4154,37 @@ var _Provider = class {
4271
4154
  return {
4272
4155
  receipts,
4273
4156
  outputVariables,
4274
- missingContractIds,
4275
- dryrunStatus
4157
+ missingContractIds
4276
4158
  };
4277
4159
  }
4278
- /**
4279
- * Dry runs multiple transactions and checks for missing dependencies in batches.
4280
- *
4281
- * Transactions are dry run in batches. After each dry run, transactions requiring
4282
- * further modifications are identified. The method iteratively updates these transactions
4283
- * and performs subsequent dry runs until all dependencies for each transaction are satisfied.
4284
- *
4285
- * @param transactionRequests - Array of transaction request objects.
4286
- * @returns A promise that resolves to an array of results for each transaction.
4287
- */
4288
- async estimateMultipleTxDependencies(transactionRequests) {
4289
- const results = transactionRequests.map(() => ({
4290
- receipts: [],
4291
- outputVariables: 0,
4292
- missingContractIds: [],
4293
- dryrunStatus: void 0
4294
- }));
4295
- const allRequests = (0, import_ramda3.clone)(transactionRequests);
4296
- const serializedTransactionsMap = /* @__PURE__ */ new Map();
4297
- allRequests.forEach((req, index) => {
4298
- if (req.type === import_transactions19.TransactionType.Script) {
4299
- serializedTransactionsMap.set(index, (0, import_utils22.hexlify)(req.toTransactionBytes()));
4300
- }
4301
- });
4302
- let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
4303
- let attempt = 0;
4304
- while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
4305
- const encodedTransactions = transactionsToProcess.map(
4306
- (index) => serializedTransactionsMap.get(index)
4307
- );
4308
- const dryRunResults = await this.operations.dryRun({
4309
- encodedTransactions,
4310
- utxoValidation: false
4311
- });
4312
- const nextRoundTransactions = [];
4313
- for (let i = 0; i < dryRunResults.dryRun.length; i++) {
4314
- const currentResultIndex = transactionsToProcess[i];
4315
- const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
4316
- results[currentResultIndex].receipts = rawReceipts.map(processGqlReceipt);
4317
- results[currentResultIndex].dryrunStatus = status;
4318
- const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
4319
- results[currentResultIndex].receipts
4320
- );
4321
- const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
4322
- const requestToProcess = allRequests[currentResultIndex];
4323
- if (hasMissingOutputs && requestToProcess?.type === import_transactions19.TransactionType.Script) {
4324
- results[currentResultIndex].outputVariables += missingOutputVariables.length;
4325
- requestToProcess.addVariableOutputs(missingOutputVariables.length);
4326
- missingOutputContractIds.forEach(({ contractId }) => {
4327
- requestToProcess.addContractInputAndOutput(import_address3.Address.fromString(contractId));
4328
- results[currentResultIndex].missingContractIds.push(contractId);
4329
- });
4330
- const { maxFee } = await this.estimateTxGasAndFee({
4331
- transactionRequest: requestToProcess
4332
- });
4333
- requestToProcess.maxFee = maxFee;
4334
- serializedTransactionsMap.set(
4335
- currentResultIndex,
4336
- (0, import_utils22.hexlify)(requestToProcess.toTransactionBytes())
4337
- );
4338
- nextRoundTransactions.push(currentResultIndex);
4339
- allRequests[currentResultIndex] = requestToProcess;
4340
- }
4341
- }
4342
- transactionsToProcess = nextRoundTransactions;
4343
- attempt += 1;
4344
- }
4345
- return results;
4346
- }
4347
- async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
4348
- if (estimateTxDependencies) {
4349
- return this.estimateMultipleTxDependencies(transactionRequests);
4350
- }
4351
- const encodedTransactions = transactionRequests.map((tx) => (0, import_utils22.hexlify)(tx.toTransactionBytes()));
4352
- const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4353
- encodedTransactions,
4354
- utxoValidation: utxoValidation || false
4355
- });
4356
- const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
4357
- const receipts = rawReceipts.map(processGqlReceipt);
4358
- return { receipts, dryrunStatus: status };
4359
- });
4360
- return results;
4361
- }
4362
4160
  /**
4363
4161
  * Estimates the transaction gas and fee based on the provided transaction request.
4364
4162
  * @param transactionRequest - The transaction request object.
4365
4163
  * @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
4366
4164
  */
4367
- async estimateTxGasAndFee(params) {
4165
+ estimateTxGasAndFee(params) {
4368
4166
  const { transactionRequest } = params;
4369
- let { gasPrice } = params;
4167
+ const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
4370
4168
  const chainInfo = this.getChain();
4371
- const { gasPriceFactor, maxGasPerTx } = this.getGasConfig();
4169
+ const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
4170
+ transactionRequest.gasPrice = gasPrice;
4372
4171
  const minGas = transactionRequest.calculateMinGas(chainInfo);
4373
- if (!gasPrice) {
4374
- gasPrice = await this.estimateGasPrice(10);
4375
- }
4376
- const minFee = calculateGasFee({
4377
- gasPrice: (0, import_math16.bn)(gasPrice),
4378
- gas: minGas,
4379
- priceFactor: gasPriceFactor,
4380
- tip: transactionRequest.tip
4381
- }).add(1);
4382
- let gasLimit = (0, import_math16.bn)(0);
4172
+ const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
4383
4173
  if (transactionRequest.type === import_transactions19.TransactionType.Script) {
4384
- gasLimit = transactionRequest.gasLimit;
4385
4174
  if (transactionRequest.gasLimit.eq(0)) {
4386
4175
  transactionRequest.gasLimit = minGas;
4387
4176
  transactionRequest.gasLimit = maxGasPerTx.sub(
4388
4177
  transactionRequest.calculateMaxGas(chainInfo, minGas)
4389
4178
  );
4390
- gasLimit = transactionRequest.gasLimit;
4391
4179
  }
4392
4180
  }
4393
4181
  const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
4394
- const maxFee = calculateGasFee({
4395
- gasPrice: (0, import_math16.bn)(gasPrice),
4396
- gas: maxGas,
4397
- priceFactor: gasPriceFactor,
4398
- tip: transactionRequest.tip
4399
- }).add(1);
4182
+ const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
4400
4183
  return {
4401
4184
  minGas,
4402
4185
  minFee,
4403
4186
  maxGas,
4404
- maxFee,
4405
- gasPrice,
4406
- gasLimit
4187
+ maxFee
4407
4188
  };
4408
4189
  }
4409
4190
  /**
@@ -4421,17 +4202,15 @@ var _Provider = class {
4421
4202
  if (estimateTxDependencies) {
4422
4203
  return this.estimateTxDependencies(transactionRequest);
4423
4204
  }
4424
- const encodedTransactions = [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())];
4425
- const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4426
- encodedTransactions,
4205
+ const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
4206
+ const { dryRun: gqlReceipts } = await this.operations.dryRun({
4207
+ encodedTransaction,
4427
4208
  utxoValidation: true
4428
4209
  });
4429
- const callResult = dryRunStatuses.map((dryRunStatus) => {
4430
- const { id, receipts, status } = dryRunStatus;
4431
- const processedReceipts = receipts.map(processGqlReceipt);
4432
- return { id, receipts: processedReceipts, status };
4433
- });
4434
- return { receipts: callResult[0].receipts };
4210
+ const receipts = gqlReceipts.map(processGqlReceipt);
4211
+ return {
4212
+ receipts
4213
+ };
4435
4214
  }
4436
4215
  /**
4437
4216
  * Returns a transaction cost to enable user
@@ -4448,79 +4227,77 @@ var _Provider = class {
4448
4227
  * @param tolerance - The tolerance to add on top of the gasUsed.
4449
4228
  * @returns A promise that resolves to the transaction cost object.
4450
4229
  */
4451
- async getTransactionCost(transactionRequestLike, { resourcesOwner, signatureCallback, quantitiesToContract = [] } = {}) {
4230
+ async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
4231
+ estimateTxDependencies = true,
4232
+ estimatePredicates = true,
4233
+ resourcesOwner,
4234
+ signatureCallback
4235
+ } = {}) {
4452
4236
  const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
4237
+ const { minGasPrice } = this.getGasConfig();
4238
+ const setGasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
4453
4239
  const isScriptTransaction = txRequestClone.type === import_transactions19.TransactionType.Script;
4454
4240
  const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
4455
- const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
4241
+ const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
4456
4242
  txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
4457
- txRequestClone.maxFee = (0, import_math16.bn)(0);
4458
4243
  if (isScriptTransaction) {
4459
- txRequestClone.gasLimit = (0, import_math16.bn)(0);
4244
+ txRequestClone.gasLimit = (0, import_math15.bn)(0);
4460
4245
  }
4461
- if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
4462
- resourcesOwner.populateTransactionPredicateData(txRequestClone);
4246
+ if (estimatePredicates) {
4247
+ if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
4248
+ resourcesOwner.populateTransactionPredicateData(txRequestClone);
4249
+ }
4250
+ await this.estimatePredicates(txRequestClone);
4463
4251
  }
4464
- const signedRequest = (0, import_ramda3.clone)(txRequestClone);
4465
- let addedSignatures = 0;
4466
4252
  if (signatureCallback && isScriptTransaction) {
4467
- const lengthBefore = signedRequest.witnesses.length;
4468
- await signatureCallback(signedRequest);
4469
- addedSignatures = signedRequest.witnesses.length - lengthBefore;
4253
+ await signatureCallback(txRequestClone);
4470
4254
  }
4471
- await this.estimatePredicates(signedRequest);
4472
- let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
4473
- transactionRequest: signedRequest
4255
+ let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
4256
+ transactionRequest: txRequestClone
4474
4257
  });
4475
4258
  let receipts = [];
4476
4259
  let missingContractIds = [];
4477
4260
  let outputVariables = 0;
4478
- let gasUsed = (0, import_math16.bn)(0);
4479
- txRequestClone.updatePredicateGasUsed(signedRequest.inputs);
4480
- txRequestClone.maxFee = maxFee;
4481
- if (isScriptTransaction) {
4482
- txRequestClone.gasLimit = gasLimit;
4483
- if (signatureCallback) {
4484
- await signatureCallback(txRequestClone);
4485
- }
4261
+ let gasUsed = (0, import_math15.bn)(0);
4262
+ if (isScriptTransaction && estimateTxDependencies) {
4263
+ txRequestClone.gasPrice = (0, import_math15.bn)(0);
4486
4264
  const result = await this.estimateTxDependencies(txRequestClone);
4487
4265
  receipts = result.receipts;
4488
4266
  outputVariables = result.outputVariables;
4489
4267
  missingContractIds = result.missingContractIds;
4490
4268
  gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
4491
4269
  txRequestClone.gasLimit = gasUsed;
4492
- ({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
4493
- transactionRequest: txRequestClone,
4494
- gasPrice
4270
+ txRequestClone.gasPrice = setGasPrice;
4271
+ ({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
4272
+ transactionRequest: txRequestClone
4495
4273
  }));
4496
4274
  }
4497
4275
  return {
4498
4276
  requiredQuantities: allQuantities,
4499
4277
  receipts,
4500
4278
  gasUsed,
4501
- gasPrice,
4279
+ minGasPrice,
4280
+ gasPrice: setGasPrice,
4502
4281
  minGas,
4503
4282
  maxGas,
4504
4283
  minFee,
4505
4284
  maxFee,
4285
+ estimatedInputs: txRequestClone.inputs,
4506
4286
  outputVariables,
4507
- missingContractIds,
4508
- addedSignatures,
4509
- estimatedPredicates: txRequestClone.inputs
4287
+ missingContractIds
4510
4288
  };
4511
4289
  }
4512
- async getResourcesForTransaction(owner, transactionRequestLike, quantitiesToContract = []) {
4290
+ async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
4513
4291
  const ownerAddress = import_address3.Address.fromAddressOrString(owner);
4514
4292
  const transactionRequest = transactionRequestify((0, import_ramda3.clone)(transactionRequestLike));
4515
- const transactionCost = await this.getTransactionCost(transactionRequest, {
4516
- quantitiesToContract
4517
- });
4293
+ const transactionCost = await this.getTransactionCost(transactionRequest, forwardingQuantities);
4518
4294
  transactionRequest.addResources(
4519
4295
  await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
4520
4296
  );
4521
- const { requiredQuantities, ...txCost } = await this.getTransactionCost(transactionRequest, {
4522
- quantitiesToContract
4523
- });
4297
+ const { requiredQuantities, ...txCost } = await this.getTransactionCost(
4298
+ transactionRequest,
4299
+ forwardingQuantities
4300
+ );
4524
4301
  const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
4525
4302
  return {
4526
4303
  resources,
@@ -4536,16 +4313,17 @@ var _Provider = class {
4536
4313
  const result = await this.operations.getCoins({
4537
4314
  first: 10,
4538
4315
  ...paginationArgs,
4539
- filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils22.hexlify)(assetId) }
4316
+ filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils23.hexlify)(assetId) }
4540
4317
  });
4541
4318
  const coins = result.coins.edges.map((edge) => edge.node);
4542
4319
  return coins.map((coin) => ({
4543
4320
  id: coin.utxoId,
4544
4321
  assetId: coin.assetId,
4545
- amount: (0, import_math16.bn)(coin.amount),
4322
+ amount: (0, import_math15.bn)(coin.amount),
4546
4323
  owner: import_address3.Address.fromAddressOrString(coin.owner),
4547
- blockCreated: (0, import_math16.bn)(coin.blockCreated),
4548
- 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)
4549
4327
  }));
4550
4328
  }
4551
4329
  /**
@@ -4559,19 +4337,19 @@ var _Provider = class {
4559
4337
  async getResourcesToSpend(owner, quantities, excludedIds) {
4560
4338
  const ownerAddress = import_address3.Address.fromAddressOrString(owner);
4561
4339
  const excludeInput = {
4562
- messages: excludedIds?.messages?.map((nonce) => (0, import_utils22.hexlify)(nonce)) || [],
4563
- 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)) || []
4564
4342
  };
4565
4343
  if (this.cache) {
4566
4344
  const uniqueUtxos = new Set(
4567
- 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)))
4568
4346
  );
4569
4347
  excludeInput.utxos = Array.from(uniqueUtxos);
4570
4348
  }
4571
4349
  const coinsQuery = {
4572
4350
  owner: ownerAddress.toB256(),
4573
4351
  queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
4574
- assetId: (0, import_utils22.hexlify)(assetId),
4352
+ assetId: (0, import_utils23.hexlify)(assetId),
4575
4353
  amount: amount.toString(10),
4576
4354
  max: maxPerAsset ? maxPerAsset.toString(10) : void 0
4577
4355
  })),
@@ -4582,9 +4360,9 @@ var _Provider = class {
4582
4360
  switch (coin.__typename) {
4583
4361
  case "MessageCoin":
4584
4362
  return {
4585
- amount: (0, import_math16.bn)(coin.amount),
4363
+ amount: (0, import_math15.bn)(coin.amount),
4586
4364
  assetId: coin.assetId,
4587
- daHeight: (0, import_math16.bn)(coin.daHeight),
4365
+ daHeight: (0, import_math15.bn)(coin.daHeight),
4588
4366
  sender: import_address3.Address.fromAddressOrString(coin.sender),
4589
4367
  recipient: import_address3.Address.fromAddressOrString(coin.recipient),
4590
4368
  nonce: coin.nonce
@@ -4592,11 +4370,12 @@ var _Provider = class {
4592
4370
  case "Coin":
4593
4371
  return {
4594
4372
  id: coin.utxoId,
4595
- amount: (0, import_math16.bn)(coin.amount),
4373
+ amount: (0, import_math15.bn)(coin.amount),
4596
4374
  assetId: coin.assetId,
4597
4375
  owner: import_address3.Address.fromAddressOrString(coin.owner),
4598
- blockCreated: (0, import_math16.bn)(coin.blockCreated),
4599
- 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)
4600
4379
  };
4601
4380
  default:
4602
4381
  return null;
@@ -4613,13 +4392,13 @@ var _Provider = class {
4613
4392
  async getBlock(idOrHeight) {
4614
4393
  let variables;
4615
4394
  if (typeof idOrHeight === "number") {
4616
- variables = { height: (0, import_math16.bn)(idOrHeight).toString(10) };
4395
+ variables = { height: (0, import_math15.bn)(idOrHeight).toString(10) };
4617
4396
  } else if (idOrHeight === "latest") {
4618
4397
  variables = { height: (await this.getBlockNumber()).toString(10) };
4619
4398
  } else if (idOrHeight.length === 66) {
4620
4399
  variables = { blockId: idOrHeight };
4621
4400
  } else {
4622
- variables = { blockId: (0, import_math16.bn)(idOrHeight).toString(10) };
4401
+ variables = { blockId: (0, import_math15.bn)(idOrHeight).toString(10) };
4623
4402
  }
4624
4403
  const { block } = await this.operations.getBlock(variables);
4625
4404
  if (!block) {
@@ -4627,7 +4406,7 @@ var _Provider = class {
4627
4406
  }
4628
4407
  return {
4629
4408
  id: block.id,
4630
- height: (0, import_math16.bn)(block.height),
4409
+ height: (0, import_math15.bn)(block.header.height),
4631
4410
  time: block.header.time,
4632
4411
  transactionIds: block.transactions.map((tx) => tx.id)
4633
4412
  };
@@ -4642,7 +4421,7 @@ var _Provider = class {
4642
4421
  const { blocks: fetchedData } = await this.operations.getBlocks(params);
4643
4422
  const blocks = fetchedData.edges.map(({ node: block }) => ({
4644
4423
  id: block.id,
4645
- height: (0, import_math16.bn)(block.height),
4424
+ height: (0, import_math15.bn)(block.header.height),
4646
4425
  time: block.header.time,
4647
4426
  transactionIds: block.transactions.map((tx) => tx.id)
4648
4427
  }));
@@ -4657,7 +4436,7 @@ var _Provider = class {
4657
4436
  async getBlockWithTransactions(idOrHeight) {
4658
4437
  let variables;
4659
4438
  if (typeof idOrHeight === "number") {
4660
- variables = { blockHeight: (0, import_math16.bn)(idOrHeight).toString(10) };
4439
+ variables = { blockHeight: (0, import_math15.bn)(idOrHeight).toString(10) };
4661
4440
  } else if (idOrHeight === "latest") {
4662
4441
  variables = { blockHeight: (await this.getBlockNumber()).toString() };
4663
4442
  } else {
@@ -4669,11 +4448,11 @@ var _Provider = class {
4669
4448
  }
4670
4449
  return {
4671
4450
  id: block.id,
4672
- height: (0, import_math16.bn)(block.height, 10),
4451
+ height: (0, import_math15.bn)(block.header.height, 10),
4673
4452
  time: block.header.time,
4674
4453
  transactionIds: block.transactions.map((tx) => tx.id),
4675
4454
  transactions: block.transactions.map(
4676
- (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]
4677
4456
  )
4678
4457
  };
4679
4458
  }
@@ -4689,7 +4468,7 @@ var _Provider = class {
4689
4468
  return null;
4690
4469
  }
4691
4470
  return new import_transactions19.TransactionCoder().decode(
4692
- (0, import_utils22.arrayify)(transaction.rawPayload),
4471
+ (0, import_utils23.arrayify)(transaction.rawPayload),
4693
4472
  0
4694
4473
  )?.[0];
4695
4474
  }
@@ -4716,9 +4495,9 @@ var _Provider = class {
4716
4495
  async getContractBalance(contractId, assetId) {
4717
4496
  const { contractBalance } = await this.operations.getContractBalance({
4718
4497
  contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
4719
- asset: (0, import_utils22.hexlify)(assetId)
4498
+ asset: (0, import_utils23.hexlify)(assetId)
4720
4499
  });
4721
- return (0, import_math16.bn)(contractBalance.amount, 10);
4500
+ return (0, import_math15.bn)(contractBalance.amount, 10);
4722
4501
  }
4723
4502
  /**
4724
4503
  * Returns the balance for the given owner for the given asset ID.
@@ -4730,9 +4509,9 @@ var _Provider = class {
4730
4509
  async getBalance(owner, assetId) {
4731
4510
  const { balance } = await this.operations.getBalance({
4732
4511
  owner: import_address3.Address.fromAddressOrString(owner).toB256(),
4733
- assetId: (0, import_utils22.hexlify)(assetId)
4512
+ assetId: (0, import_utils23.hexlify)(assetId)
4734
4513
  });
4735
- return (0, import_math16.bn)(balance.amount, 10);
4514
+ return (0, import_math15.bn)(balance.amount, 10);
4736
4515
  }
4737
4516
  /**
4738
4517
  * Returns balances for the given owner.
@@ -4750,7 +4529,7 @@ var _Provider = class {
4750
4529
  const balances = result.balances.edges.map((edge) => edge.node);
4751
4530
  return balances.map((balance) => ({
4752
4531
  assetId: balance.assetId,
4753
- amount: (0, import_math16.bn)(balance.amount)
4532
+ amount: (0, import_math15.bn)(balance.amount)
4754
4533
  }));
4755
4534
  }
4756
4535
  /**
@@ -4772,15 +4551,15 @@ var _Provider = class {
4772
4551
  sender: message.sender,
4773
4552
  recipient: message.recipient,
4774
4553
  nonce: message.nonce,
4775
- amount: (0, import_math16.bn)(message.amount),
4554
+ amount: (0, import_math15.bn)(message.amount),
4776
4555
  data: message.data
4777
4556
  }),
4778
4557
  sender: import_address3.Address.fromAddressOrString(message.sender),
4779
4558
  recipient: import_address3.Address.fromAddressOrString(message.recipient),
4780
4559
  nonce: message.nonce,
4781
- amount: (0, import_math16.bn)(message.amount),
4560
+ amount: (0, import_math15.bn)(message.amount),
4782
4561
  data: import_transactions19.InputMessageCoder.decodeData(message.data),
4783
- daHeight: (0, import_math16.bn)(message.daHeight)
4562
+ daHeight: (0, import_math15.bn)(message.daHeight)
4784
4563
  }));
4785
4564
  }
4786
4565
  /**
@@ -4833,60 +4612,44 @@ var _Provider = class {
4833
4612
  } = result.messageProof;
4834
4613
  return {
4835
4614
  messageProof: {
4836
- proofIndex: (0, import_math16.bn)(messageProof.proofIndex),
4615
+ proofIndex: (0, import_math15.bn)(messageProof.proofIndex),
4837
4616
  proofSet: messageProof.proofSet
4838
4617
  },
4839
4618
  blockProof: {
4840
- proofIndex: (0, import_math16.bn)(blockProof.proofIndex),
4619
+ proofIndex: (0, import_math15.bn)(blockProof.proofIndex),
4841
4620
  proofSet: blockProof.proofSet
4842
4621
  },
4843
4622
  messageBlockHeader: {
4844
4623
  id: messageBlockHeader.id,
4845
- daHeight: (0, import_math16.bn)(messageBlockHeader.daHeight),
4846
- transactionsCount: (0, import_math16.bn)(messageBlockHeader.transactionsCount),
4624
+ daHeight: (0, import_math15.bn)(messageBlockHeader.daHeight),
4625
+ transactionsCount: (0, import_math15.bn)(messageBlockHeader.transactionsCount),
4847
4626
  transactionsRoot: messageBlockHeader.transactionsRoot,
4848
- height: (0, import_math16.bn)(messageBlockHeader.height),
4627
+ height: (0, import_math15.bn)(messageBlockHeader.height),
4849
4628
  prevRoot: messageBlockHeader.prevRoot,
4850
4629
  time: messageBlockHeader.time,
4851
4630
  applicationHash: messageBlockHeader.applicationHash,
4852
- messageReceiptCount: (0, import_math16.bn)(messageBlockHeader.messageReceiptCount),
4853
- messageOutboxRoot: messageBlockHeader.messageOutboxRoot,
4854
- consensusParametersVersion: messageBlockHeader.consensusParametersVersion,
4855
- eventInboxRoot: messageBlockHeader.eventInboxRoot,
4856
- stateTransitionBytecodeVersion: messageBlockHeader.stateTransitionBytecodeVersion
4631
+ messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
4632
+ messageReceiptCount: (0, import_math15.bn)(messageBlockHeader.messageReceiptCount)
4857
4633
  },
4858
4634
  commitBlockHeader: {
4859
4635
  id: commitBlockHeader.id,
4860
- daHeight: (0, import_math16.bn)(commitBlockHeader.daHeight),
4861
- transactionsCount: (0, import_math16.bn)(commitBlockHeader.transactionsCount),
4636
+ daHeight: (0, import_math15.bn)(commitBlockHeader.daHeight),
4637
+ transactionsCount: (0, import_math15.bn)(commitBlockHeader.transactionsCount),
4862
4638
  transactionsRoot: commitBlockHeader.transactionsRoot,
4863
- height: (0, import_math16.bn)(commitBlockHeader.height),
4639
+ height: (0, import_math15.bn)(commitBlockHeader.height),
4864
4640
  prevRoot: commitBlockHeader.prevRoot,
4865
4641
  time: commitBlockHeader.time,
4866
4642
  applicationHash: commitBlockHeader.applicationHash,
4867
- messageReceiptCount: (0, import_math16.bn)(commitBlockHeader.messageReceiptCount),
4868
- messageOutboxRoot: commitBlockHeader.messageOutboxRoot,
4869
- consensusParametersVersion: commitBlockHeader.consensusParametersVersion,
4870
- eventInboxRoot: commitBlockHeader.eventInboxRoot,
4871
- stateTransitionBytecodeVersion: commitBlockHeader.stateTransitionBytecodeVersion
4643
+ messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
4644
+ messageReceiptCount: (0, import_math15.bn)(commitBlockHeader.messageReceiptCount)
4872
4645
  },
4873
4646
  sender: import_address3.Address.fromAddressOrString(sender),
4874
4647
  recipient: import_address3.Address.fromAddressOrString(recipient),
4875
4648
  nonce,
4876
- amount: (0, import_math16.bn)(amount),
4649
+ amount: (0, import_math15.bn)(amount),
4877
4650
  data
4878
4651
  };
4879
4652
  }
4880
- async getLatestGasPrice() {
4881
- const { latestGasPrice } = await this.operations.getLatestGasPrice();
4882
- return (0, import_math16.bn)(latestGasPrice.gasPrice);
4883
- }
4884
- async estimateGasPrice(blockHorizon) {
4885
- const { estimateGasPrice } = await this.operations.estimateGasPrice({
4886
- blockHorizon: String(blockHorizon)
4887
- });
4888
- return (0, import_math16.bn)(estimateGasPrice.gasPrice);
4889
- }
4890
4653
  /**
4891
4654
  * Returns Message Proof for given transaction id and the message id from MessageOut receipt.
4892
4655
  *
@@ -4906,10 +4669,10 @@ var _Provider = class {
4906
4669
  */
4907
4670
  async produceBlocks(amount, startTime) {
4908
4671
  const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
4909
- blocksToProduce: (0, import_math16.bn)(amount).toString(10),
4910
- 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
4911
4674
  });
4912
- return (0, import_math16.bn)(latestBlockHeight);
4675
+ return (0, import_math15.bn)(latestBlockHeight);
4913
4676
  }
4914
4677
  // eslint-disable-next-line @typescript-eslint/require-await
4915
4678
  async getTransactionResponse(transactionId) {
@@ -4933,9 +4696,9 @@ __publicField(Provider, "nodeInfoCache", {});
4933
4696
 
4934
4697
  // src/providers/transaction-summary/get-transaction-summary.ts
4935
4698
  var import_errors15 = require("@fuel-ts/errors");
4936
- var import_math17 = require("@fuel-ts/math");
4699
+ var import_math16 = require("@fuel-ts/math");
4937
4700
  var import_transactions20 = require("@fuel-ts/transactions");
4938
- var import_utils25 = require("@fuel-ts/utils");
4701
+ var import_utils26 = require("@fuel-ts/utils");
4939
4702
  async function getTransactionSummary(params) {
4940
4703
  const { id, provider, abiMap } = params;
4941
4704
  const { transaction: gqlTransaction } = await provider.operations.getTransactionWithReceipts({
@@ -4948,31 +4711,24 @@ async function getTransactionSummary(params) {
4948
4711
  );
4949
4712
  }
4950
4713
  const [decodedTransaction] = new import_transactions20.TransactionCoder().decode(
4951
- (0, import_utils25.arrayify)(gqlTransaction.rawPayload),
4714
+ (0, import_utils26.arrayify)(gqlTransaction.rawPayload),
4952
4715
  0
4953
4716
  );
4954
- let txReceipts = [];
4955
- if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
4956
- txReceipts = gqlTransaction.status.receipts;
4957
- }
4958
- const receipts = txReceipts.map(processGqlReceipt);
4717
+ const receipts = gqlTransaction.receipts?.map(processGqlReceipt) || [];
4959
4718
  const {
4960
- consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts, maxGasPerTx }
4719
+ consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
4961
4720
  } = provider.getChain();
4962
- const gasPrice = await provider.getLatestGasPrice();
4963
4721
  const transactionInfo = assembleTransactionSummary({
4964
4722
  id: gqlTransaction.id,
4965
4723
  receipts,
4966
4724
  transaction: decodedTransaction,
4967
- transactionBytes: (0, import_utils25.arrayify)(gqlTransaction.rawPayload),
4725
+ transactionBytes: (0, import_utils26.arrayify)(gqlTransaction.rawPayload),
4968
4726
  gqlTransactionStatus: gqlTransaction.status,
4969
- gasPerByte: (0, import_math17.bn)(gasPerByte),
4970
- gasPriceFactor: (0, import_math17.bn)(gasPriceFactor),
4727
+ gasPerByte: (0, import_math16.bn)(gasPerByte),
4728
+ gasPriceFactor: (0, import_math16.bn)(gasPriceFactor),
4971
4729
  abiMap,
4972
4730
  maxInputs,
4973
- gasCosts,
4974
- maxGasPerTx,
4975
- gasPrice
4731
+ gasCosts
4976
4732
  });
4977
4733
  return {
4978
4734
  gqlTransaction,
@@ -4982,11 +4738,10 @@ async function getTransactionSummary(params) {
4982
4738
  async function getTransactionSummaryFromRequest(params) {
4983
4739
  const { provider, transactionRequest, abiMap } = params;
4984
4740
  const { receipts } = await provider.call(transactionRequest);
4985
- const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = provider.getGasConfig();
4741
+ const { gasPerByte, gasPriceFactor, gasCosts } = provider.getGasConfig();
4986
4742
  const maxInputs = provider.getChain().consensusParameters.maxInputs;
4987
4743
  const transaction = transactionRequest.toTransaction();
4988
4744
  const transactionBytes = transactionRequest.toTransactionBytes();
4989
- const gasPrice = await provider.getLatestGasPrice();
4990
4745
  const transactionSummary = assembleTransactionSummary({
4991
4746
  receipts,
4992
4747
  transaction,
@@ -4995,9 +4750,7 @@ async function getTransactionSummaryFromRequest(params) {
4995
4750
  gasPerByte,
4996
4751
  gasPriceFactor,
4997
4752
  maxInputs,
4998
- gasCosts,
4999
- maxGasPerTx,
5000
- gasPrice
4753
+ gasCosts
5001
4754
  });
5002
4755
  return transactionSummary;
5003
4756
  }
@@ -5006,31 +4759,24 @@ async function getTransactionsSummaries(params) {
5006
4759
  const { transactionsByOwner } = await provider.operations.getTransactionsByOwner(filters);
5007
4760
  const { edges, pageInfo } = transactionsByOwner;
5008
4761
  const {
5009
- consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts, maxGasPerTx }
4762
+ consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
5010
4763
  } = provider.getChain();
5011
- const gasPrice = await provider.getLatestGasPrice();
5012
4764
  const transactions = edges.map((edge) => {
5013
4765
  const { node: gqlTransaction } = edge;
5014
- const { id, rawPayload, status } = gqlTransaction;
5015
- const [decodedTransaction] = new import_transactions20.TransactionCoder().decode((0, import_utils25.arrayify)(rawPayload), 0);
5016
- let txReceipts = [];
5017
- if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
5018
- txReceipts = gqlTransaction.status.receipts;
5019
- }
5020
- 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) || [];
5021
4769
  const transactionSummary = assembleTransactionSummary({
5022
4770
  id,
5023
4771
  receipts,
5024
4772
  transaction: decodedTransaction,
5025
- transactionBytes: (0, import_utils25.arrayify)(rawPayload),
4773
+ transactionBytes: (0, import_utils26.arrayify)(rawPayload),
5026
4774
  gqlTransactionStatus: status,
5027
4775
  abiMap,
5028
4776
  gasPerByte,
5029
4777
  gasPriceFactor,
5030
4778
  maxInputs,
5031
- gasCosts,
5032
- maxGasPerTx,
5033
- gasPrice
4779
+ gasCosts
5034
4780
  });
5035
4781
  const output = {
5036
4782
  gqlTransaction,
@@ -5167,17 +4913,17 @@ var assets = [
5167
4913
 
5168
4914
  // src/utils/formatTransferToContractScriptData.ts
5169
4915
  var import_abi_coder6 = require("@fuel-ts/abi-coder");
5170
- var import_math18 = require("@fuel-ts/math");
5171
- var import_utils26 = require("@fuel-ts/utils");
4916
+ var import_math17 = require("@fuel-ts/math");
4917
+ var import_utils27 = require("@fuel-ts/utils");
5172
4918
  var asm = __toESM(require("@fuels/vm-asm"));
5173
4919
  var formatTransferToContractScriptData = (params) => {
5174
4920
  const { assetId, amountToTransfer, hexlifiedContractId } = params;
5175
4921
  const numberCoder = new import_abi_coder6.BigNumberCoder("u64");
5176
- const encoded = numberCoder.encode(new import_math18.BN(amountToTransfer).toNumber());
4922
+ const encoded = numberCoder.encode(new import_math17.BN(amountToTransfer).toNumber());
5177
4923
  const scriptData = Uint8Array.from([
5178
- ...(0, import_utils26.arrayify)(hexlifiedContractId),
4924
+ ...(0, import_utils27.arrayify)(hexlifiedContractId),
5179
4925
  ...encoded,
5180
- ...(0, import_utils26.arrayify)(assetId)
4926
+ ...(0, import_utils27.arrayify)(assetId)
5181
4927
  ]);
5182
4928
  return scriptData;
5183
4929
  };
@@ -5362,33 +5108,36 @@ var Account = class extends import_interfaces.AbstractAccount {
5362
5108
  * @param fee - The estimated transaction fee.
5363
5109
  * @returns A promise that resolves when the resources are added to the transaction.
5364
5110
  */
5365
- async fund(request, params) {
5366
- const { addedSignatures, estimatedPredicates, maxFee: fee, requiredQuantities } = params;
5367
- const txRequest = request;
5368
- const requiredQuantitiesWithFee = addAmountToCoinQuantities({
5369
- amount: (0, import_math19.bn)(fee),
5111
+ async fund(request, coinQuantities, fee) {
5112
+ const updatedQuantities = addAmountToAsset({
5113
+ amount: (0, import_math18.bn)(fee),
5370
5114
  assetId: import_configs12.BaseAssetId,
5371
- coinQuantities: requiredQuantities
5115
+ coinQuantities
5372
5116
  });
5373
5117
  const quantitiesDict = {};
5374
- requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
5118
+ updatedQuantities.forEach(({ amount, assetId }) => {
5375
5119
  quantitiesDict[assetId] = {
5376
5120
  required: amount,
5377
- owned: (0, import_math19.bn)(0)
5121
+ owned: (0, import_math18.bn)(0)
5378
5122
  };
5379
5123
  });
5380
- txRequest.inputs.forEach((input) => {
5124
+ const cachedUtxos = [];
5125
+ const cachedMessages = [];
5126
+ const owner = this.address.toB256();
5127
+ request.inputs.forEach((input) => {
5381
5128
  const isResource = "amount" in input;
5382
5129
  if (isResource) {
5383
5130
  const isCoin2 = "owner" in input;
5384
5131
  if (isCoin2) {
5385
5132
  const assetId = String(input.assetId);
5386
- if (quantitiesDict[assetId]) {
5387
- const amount = (0, import_math19.bn)(input.amount);
5133
+ if (input.owner === owner && quantitiesDict[assetId]) {
5134
+ const amount = (0, import_math18.bn)(input.amount);
5388
5135
  quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
5136
+ cachedUtxos.push(input.id);
5389
5137
  }
5390
- } else if (input.amount && quantitiesDict[import_configs12.BaseAssetId]) {
5138
+ } else if (input.recipient === owner && input.amount && quantitiesDict[import_configs12.BaseAssetId]) {
5391
5139
  quantitiesDict[import_configs12.BaseAssetId].owned = quantitiesDict[import_configs12.BaseAssetId].owned.add(input.amount);
5140
+ cachedMessages.push(input.nonce);
5392
5141
  }
5393
5142
  }
5394
5143
  });
@@ -5403,23 +5152,12 @@ var Account = class extends import_interfaces.AbstractAccount {
5403
5152
  });
5404
5153
  const needsToBeFunded = missingQuantities.length;
5405
5154
  if (needsToBeFunded) {
5406
- const excludedIds = cacheTxInputsFromOwner(txRequest.inputs, this.address.toB256());
5407
- const resources = await this.getResourcesToSpend(missingQuantities, excludedIds);
5408
- txRequest.addResources(resources);
5409
- }
5410
- txRequest.shiftPredicateData();
5411
- txRequest.updatePredicateGasUsed(estimatedPredicates);
5412
- const requestToBeReEstimate = (0, import_ramda4.clone)(txRequest);
5413
- if (addedSignatures) {
5414
- Array.from({ length: addedSignatures }).forEach(
5415
- () => requestToBeReEstimate.addEmptyWitness()
5416
- );
5155
+ const resources = await this.getResourcesToSpend(missingQuantities, {
5156
+ messages: cachedMessages,
5157
+ utxos: cachedUtxos
5158
+ });
5159
+ request.addResources(resources);
5417
5160
  }
5418
- const { maxFee } = await this.provider.estimateTxGasAndFee({
5419
- transactionRequest: requestToBeReEstimate
5420
- });
5421
- txRequest.maxFee = maxFee;
5422
- return txRequest;
5423
5161
  }
5424
5162
  /**
5425
5163
  * A helper that creates a transfer transaction request and returns it.
@@ -5427,25 +5165,28 @@ var Account = class extends import_interfaces.AbstractAccount {
5427
5165
  * @param destination - The address of the destination.
5428
5166
  * @param amount - The amount of coins to transfer.
5429
5167
  * @param assetId - The asset ID of the coins to transfer.
5430
- * @param txParams - The transaction parameters (gasLimit, tip, maturity, maxFee, witnessLimit).
5168
+ * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
5431
5169
  * @returns A promise that resolves to the prepared transaction request.
5432
5170
  */
5433
5171
  async createTransfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
5434
- const request = new ScriptTransactionRequest(txParams);
5172
+ const { minGasPrice } = this.provider.getGasConfig();
5173
+ const params = { gasPrice: minGasPrice, ...txParams };
5174
+ const request = new ScriptTransactionRequest(params);
5435
5175
  request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetId);
5436
- const txCost = await this.provider.getTransactionCost(request, {
5176
+ const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
5437
5177
  estimateTxDependencies: true,
5438
5178
  resourcesOwner: this
5439
5179
  });
5440
- if ("gasLimit" in txParams) {
5441
- this.validateGas({
5442
- gasUsed: txCost.gasUsed,
5443
- gasLimit: request.gasLimit
5444
- });
5445
- }
5446
- request.gasLimit = txCost.gasUsed;
5447
- request.maxFee = txCost.maxFee;
5448
- 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);
5449
5190
  return request;
5450
5191
  }
5451
5192
  /**
@@ -5458,7 +5199,7 @@ var Account = class extends import_interfaces.AbstractAccount {
5458
5199
  * @returns A promise that resolves to the transaction response.
5459
5200
  */
5460
5201
  async transfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
5461
- if ((0, import_math19.bn)(amount).lte(0)) {
5202
+ if ((0, import_math18.bn)(amount).lte(0)) {
5462
5203
  throw new import_errors16.FuelError(
5463
5204
  import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
5464
5205
  "Transfer amount must be a positive number."
@@ -5477,37 +5218,38 @@ var Account = class extends import_interfaces.AbstractAccount {
5477
5218
  * @returns A promise that resolves to the transaction response.
5478
5219
  */
5479
5220
  async transferToContract(contractId, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
5480
- if ((0, import_math19.bn)(amount).lte(0)) {
5221
+ if ((0, import_math18.bn)(amount).lte(0)) {
5481
5222
  throw new import_errors16.FuelError(
5482
5223
  import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
5483
5224
  "Transfer amount must be a positive number."
5484
5225
  );
5485
5226
  }
5486
5227
  const contractAddress = import_address4.Address.fromAddressOrString(contractId);
5228
+ const { minGasPrice } = this.provider.getGasConfig();
5229
+ const params = { gasPrice: minGasPrice, ...txParams };
5487
5230
  const { script, scriptData } = await assembleTransferToContractScript({
5488
5231
  hexlifiedContractId: contractAddress.toB256(),
5489
- amountToTransfer: (0, import_math19.bn)(amount),
5232
+ amountToTransfer: (0, import_math18.bn)(amount),
5490
5233
  assetId
5491
5234
  });
5492
5235
  const request = new ScriptTransactionRequest({
5493
- ...txParams,
5236
+ ...params,
5494
5237
  script,
5495
5238
  scriptData
5496
5239
  });
5497
5240
  request.addContractInputAndOutput(contractAddress);
5498
- const txCost = await this.provider.getTransactionCost(request, {
5499
- resourcesOwner: this,
5500
- 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
5501
5251
  });
5502
- if (txParams.gasLimit) {
5503
- this.validateGas({
5504
- gasUsed: txCost.gasUsed,
5505
- gasLimit: request.gasLimit
5506
- });
5507
- }
5508
- request.gasLimit = txCost.gasUsed;
5509
- request.maxFee = txCost.maxFee;
5510
- await this.fund(request, txCost);
5252
+ await this.fund(request, requiredQuantities, maxFee);
5511
5253
  return this.sendTransaction(request);
5512
5254
  }
5513
5255
  /**
@@ -5519,31 +5261,34 @@ var Account = class extends import_interfaces.AbstractAccount {
5519
5261
  * @returns A promise that resolves to the transaction response.
5520
5262
  */
5521
5263
  async withdrawToBaseLayer(recipient, amount, txParams = {}) {
5264
+ const { minGasPrice } = this.provider.getGasConfig();
5522
5265
  const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
5523
- const recipientDataArray = (0, import_utils27.arrayify)(
5266
+ const recipientDataArray = (0, import_utils28.arrayify)(
5524
5267
  "0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
5525
5268
  );
5526
- const amountDataArray = (0, import_utils27.arrayify)(
5527
- "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"))
5528
5271
  );
5529
5272
  const script = new Uint8Array([
5530
- ...(0, import_utils27.arrayify)(withdrawScript.bytes),
5273
+ ...(0, import_utils28.arrayify)(withdrawScript.bytes),
5531
5274
  ...recipientDataArray,
5532
5275
  ...amountDataArray
5533
5276
  ]);
5534
- const params = { script, ...txParams };
5277
+ const params = { script, gasPrice: minGasPrice, ...txParams };
5535
5278
  const request = new ScriptTransactionRequest(params);
5536
- const quantitiesToContract = [{ amount: (0, import_math19.bn)(amount), assetId: import_configs12.BaseAssetId }];
5537
- const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
5538
- if (txParams.gasLimit) {
5539
- this.validateGas({
5540
- gasUsed: txCost.gasUsed,
5541
- gasLimit: request.gasLimit
5542
- });
5543
- }
5544
- request.maxFee = txCost.maxFee;
5545
- request.gasLimit = txCost.gasUsed;
5546
- 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);
5547
5292
  return this.sendTransaction(request);
5548
5293
  }
5549
5294
  async signMessage(message) {
@@ -5601,7 +5346,18 @@ var Account = class extends import_interfaces.AbstractAccount {
5601
5346
  }
5602
5347
  return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
5603
5348
  }
5604
- 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
+ }
5605
5361
  if (gasUsed.gt(gasLimit)) {
5606
5362
  throw new import_errors16.FuelError(
5607
5363
  import_errors16.ErrorCode.GAS_LIMIT_TOO_LOW,
@@ -5613,14 +5369,14 @@ var Account = class extends import_interfaces.AbstractAccount {
5613
5369
 
5614
5370
  // src/wallet/base-wallet-unlocked.ts
5615
5371
  var import_hasher3 = require("@fuel-ts/hasher");
5616
- var import_utils30 = require("@fuel-ts/utils");
5372
+ var import_utils31 = require("@fuel-ts/utils");
5617
5373
 
5618
5374
  // src/signer/signer.ts
5619
5375
  var import_address5 = require("@fuel-ts/address");
5620
5376
  var import_crypto2 = require("@fuel-ts/crypto");
5621
5377
  var import_hasher2 = require("@fuel-ts/hasher");
5622
- var import_math20 = require("@fuel-ts/math");
5623
- var import_utils28 = require("@fuel-ts/utils");
5378
+ var import_math19 = require("@fuel-ts/math");
5379
+ var import_utils29 = require("@fuel-ts/utils");
5624
5380
  var import_secp256k1 = require("@noble/curves/secp256k1");
5625
5381
  var Signer = class {
5626
5382
  address;
@@ -5639,10 +5395,10 @@ var Signer = class {
5639
5395
  privateKey = `0x${privateKey}`;
5640
5396
  }
5641
5397
  }
5642
- const privateKeyBytes = (0, import_math20.toBytes)(privateKey, 32);
5643
- this.privateKey = (0, import_utils28.hexlify)(privateKeyBytes);
5644
- this.publicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
5645
- 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));
5646
5402
  this.address = import_address5.Address.fromPublicKey(this.publicKey);
5647
5403
  }
5648
5404
  /**
@@ -5656,11 +5412,11 @@ var Signer = class {
5656
5412
  * @returns hashed signature
5657
5413
  */
5658
5414
  sign(data) {
5659
- const signature = import_secp256k1.secp256k1.sign((0, import_utils28.arrayify)(data), (0, import_utils28.arrayify)(this.privateKey));
5660
- const r = (0, import_math20.toBytes)(`0x${signature.r.toString(16)}`, 32);
5661
- 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);
5662
5418
  s[0] |= (signature.recovery || 0) << 7;
5663
- return (0, import_utils28.hexlify)((0, import_utils28.concat)([r, s]));
5419
+ return (0, import_utils29.hexlify)((0, import_utils29.concat)([r, s]));
5664
5420
  }
5665
5421
  /**
5666
5422
  * Add point on the current elliptic curve
@@ -5669,8 +5425,8 @@ var Signer = class {
5669
5425
  * @returns compressed point on the curve
5670
5426
  */
5671
5427
  addPoint(point) {
5672
- const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(this.compressedPublicKey));
5673
- 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));
5674
5430
  const result = p0.add(p1);
5675
5431
  return `0x${result.toHex(true)}`;
5676
5432
  }
@@ -5682,16 +5438,16 @@ var Signer = class {
5682
5438
  * @returns public key from signature from the
5683
5439
  */
5684
5440
  static recoverPublicKey(data, signature) {
5685
- const signedMessageBytes = (0, import_utils28.arrayify)(signature);
5441
+ const signedMessageBytes = (0, import_utils29.arrayify)(signature);
5686
5442
  const r = signedMessageBytes.slice(0, 32);
5687
5443
  const s = signedMessageBytes.slice(32, 64);
5688
5444
  const recoveryParam = (s[0] & 128) >> 7;
5689
5445
  s[0] &= 127;
5690
- 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(
5691
5447
  recoveryParam
5692
5448
  );
5693
- const publicKey = sig.recoverPublicKey((0, import_utils28.arrayify)(data)).toRawBytes(false).slice(1);
5694
- 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);
5695
5451
  }
5696
5452
  /**
5697
5453
  * Recover the address from a signature performed with [`sign`](#sign).
@@ -5710,7 +5466,7 @@ var Signer = class {
5710
5466
  * @returns random 32-byte hashed
5711
5467
  */
5712
5468
  static generatePrivateKey(entropy) {
5713
- 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);
5714
5470
  }
5715
5471
  /**
5716
5472
  * Extended publicKey from a compact publicKey
@@ -5719,8 +5475,8 @@ var Signer = class {
5719
5475
  * @returns extended publicKey
5720
5476
  */
5721
5477
  static extendPublicKey(publicKey) {
5722
- const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(publicKey));
5723
- 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));
5724
5480
  }
5725
5481
  };
5726
5482
 
@@ -5728,7 +5484,7 @@ var Signer = class {
5728
5484
  var import_address6 = require("@fuel-ts/address");
5729
5485
  var import_crypto3 = require("@fuel-ts/crypto");
5730
5486
  var import_errors17 = require("@fuel-ts/errors");
5731
- var import_utils29 = require("@fuel-ts/utils");
5487
+ var import_utils30 = require("@fuel-ts/utils");
5732
5488
  var import_uuid = require("uuid");
5733
5489
  var DEFAULT_KDF_PARAMS_LOG_N = 13;
5734
5490
  var DEFAULT_KDF_PARAMS_R = 8;
@@ -5811,7 +5567,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
5811
5567
  );
5812
5568
  }
5813
5569
  const buffer = await (0, import_crypto3.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
5814
- const privateKey = (0, import_utils29.hexlify)(buffer);
5570
+ const privateKey = (0, import_utils30.hexlify)(buffer);
5815
5571
  return privateKey;
5816
5572
  }
5817
5573
 
@@ -5856,7 +5612,7 @@ var BaseWalletUnlocked = class extends Account {
5856
5612
  */
5857
5613
  async signMessage(message) {
5858
5614
  const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
5859
- return (0, import_utils30.hexlify)(signedMessage);
5615
+ return (0, import_utils31.hexlify)(signedMessage);
5860
5616
  }
5861
5617
  /**
5862
5618
  * Signs a transaction with the wallet's private key.
@@ -5869,7 +5625,7 @@ var BaseWalletUnlocked = class extends Account {
5869
5625
  const chainId = this.provider.getChainId();
5870
5626
  const hashedTransaction = transactionRequest.getTransactionId(chainId);
5871
5627
  const signature = await this.signer().sign(hashedTransaction);
5872
- return (0, import_utils30.hexlify)(signature);
5628
+ return (0, import_utils31.hexlify)(signature);
5873
5629
  }
5874
5630
  /**
5875
5631
  * Populates a transaction with the witnesses signature.
@@ -5889,7 +5645,7 @@ var BaseWalletUnlocked = class extends Account {
5889
5645
  * @param transactionRequestLike - The transaction request to send.
5890
5646
  * @returns A promise that resolves to the TransactionResponse object.
5891
5647
  */
5892
- async sendTransaction(transactionRequestLike, { estimateTxDependencies = false, awaitExecution } = {}) {
5648
+ async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
5893
5649
  const transactionRequest = transactionRequestify(transactionRequestLike);
5894
5650
  if (estimateTxDependencies) {
5895
5651
  await this.provider.estimateTxDependencies(transactionRequest);
@@ -5930,15 +5686,15 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
5930
5686
  // src/hdwallet/hdwallet.ts
5931
5687
  var import_errors20 = require("@fuel-ts/errors");
5932
5688
  var import_hasher6 = require("@fuel-ts/hasher");
5933
- var import_math21 = require("@fuel-ts/math");
5934
- var import_utils34 = require("@fuel-ts/utils");
5689
+ var import_math20 = require("@fuel-ts/math");
5690
+ var import_utils35 = require("@fuel-ts/utils");
5935
5691
  var import_ethers3 = require("ethers");
5936
5692
 
5937
5693
  // src/mnemonic/mnemonic.ts
5938
5694
  var import_crypto4 = require("@fuel-ts/crypto");
5939
5695
  var import_errors19 = require("@fuel-ts/errors");
5940
5696
  var import_hasher5 = require("@fuel-ts/hasher");
5941
- var import_utils32 = require("@fuel-ts/utils");
5697
+ var import_utils33 = require("@fuel-ts/utils");
5942
5698
  var import_ethers2 = require("ethers");
5943
5699
 
5944
5700
  // src/wordlists/words/english.ts
@@ -8002,7 +7758,7 @@ var Language = /* @__PURE__ */ ((Language2) => {
8002
7758
  // src/mnemonic/utils.ts
8003
7759
  var import_errors18 = require("@fuel-ts/errors");
8004
7760
  var import_hasher4 = require("@fuel-ts/hasher");
8005
- var import_utils31 = require("@fuel-ts/utils");
7761
+ var import_utils32 = require("@fuel-ts/utils");
8006
7762
  function toUtf8Bytes(stri) {
8007
7763
  const str = stri.normalize("NFKD");
8008
7764
  const result = [];
@@ -8069,14 +7825,14 @@ function entropyToMnemonicIndices(entropy) {
8069
7825
  }
8070
7826
  }
8071
7827
  const checksumBits = entropy.length / 4;
8072
- 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);
8073
7829
  indices[indices.length - 1] <<= checksumBits;
8074
7830
  indices[indices.length - 1] |= checksum >> 8 - checksumBits;
8075
7831
  return indices;
8076
7832
  }
8077
7833
  function mnemonicWordsToEntropy(words, wordlist) {
8078
7834
  const size = Math.ceil(11 * words.length / 8);
8079
- const entropy = (0, import_utils31.arrayify)(new Uint8Array(size));
7835
+ const entropy = (0, import_utils32.arrayify)(new Uint8Array(size));
8080
7836
  let offset = 0;
8081
7837
  for (let i = 0; i < words.length; i += 1) {
8082
7838
  const index = wordlist.indexOf(words[i].normalize("NFKD"));
@@ -8096,7 +7852,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
8096
7852
  const entropyBits = 32 * words.length / 3;
8097
7853
  const checksumBits = words.length / 3;
8098
7854
  const checksumMask = getUpperMask(checksumBits);
8099
- 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;
8100
7856
  if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
8101
7857
  throw new import_errors18.FuelError(
8102
7858
  import_errors18.ErrorCode.INVALID_CHECKSUM,
@@ -8171,7 +7927,7 @@ var Mnemonic = class {
8171
7927
  static mnemonicToEntropy(phrase, wordlist = english) {
8172
7928
  const words = getWords(phrase);
8173
7929
  assertMnemonic(words);
8174
- return (0, import_utils32.hexlify)(mnemonicWordsToEntropy(words, wordlist));
7930
+ return (0, import_utils33.hexlify)(mnemonicWordsToEntropy(words, wordlist));
8175
7931
  }
8176
7932
  /**
8177
7933
  * @param entropy - Entropy source to the mnemonic phrase.
@@ -8179,7 +7935,7 @@ var Mnemonic = class {
8179
7935
  * @returns 64-byte array contains privateKey and chainCode as described on BIP39
8180
7936
  */
8181
7937
  static entropyToMnemonic(entropy, wordlist = english) {
8182
- const entropyBytes = (0, import_utils32.arrayify)(entropy);
7938
+ const entropyBytes = (0, import_utils33.arrayify)(entropy);
8183
7939
  assertWordList(wordlist);
8184
7940
  assertEntropy(entropyBytes);
8185
7941
  return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
@@ -8248,14 +8004,14 @@ var Mnemonic = class {
8248
8004
  * @returns 64-byte array contains privateKey and chainCode as described on BIP39
8249
8005
  */
8250
8006
  static masterKeysFromSeed(seed) {
8251
- const seedArray = (0, import_utils32.arrayify)(seed);
8007
+ const seedArray = (0, import_utils33.arrayify)(seed);
8252
8008
  if (seedArray.length < 16 || seedArray.length > 64) {
8253
8009
  throw new import_errors19.FuelError(
8254
8010
  import_errors19.ErrorCode.INVALID_SEED,
8255
8011
  `Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
8256
8012
  );
8257
8013
  }
8258
- 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));
8259
8015
  }
8260
8016
  /**
8261
8017
  * Get the extendKey as defined on BIP-32 from the provided seed
@@ -8266,22 +8022,22 @@ var Mnemonic = class {
8266
8022
  */
8267
8023
  static seedToExtendedKey(seed, testnet = false) {
8268
8024
  const masterKey = Mnemonic.masterKeysFromSeed(seed);
8269
- const prefix = (0, import_utils32.arrayify)(testnet ? TestnetPRV : MainnetPRV);
8025
+ const prefix = (0, import_utils33.arrayify)(testnet ? TestnetPRV : MainnetPRV);
8270
8026
  const depth = "0x00";
8271
8027
  const fingerprint = "0x00000000";
8272
8028
  const index = "0x00000000";
8273
8029
  const chainCode = masterKey.slice(32);
8274
8030
  const privateKey = masterKey.slice(0, 32);
8275
- const extendedKey = (0, import_utils32.concat)([
8031
+ const extendedKey = (0, import_utils33.concat)([
8276
8032
  prefix,
8277
8033
  depth,
8278
8034
  fingerprint,
8279
8035
  index,
8280
8036
  chainCode,
8281
- (0, import_utils32.concat)(["0x00", privateKey])
8037
+ (0, import_utils33.concat)(["0x00", privateKey])
8282
8038
  ]);
8283
8039
  const checksum = (0, import_ethers2.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
8284
- return (0, import_ethers2.encodeBase58)((0, import_utils32.concat)([extendedKey, checksum]));
8040
+ return (0, import_ethers2.encodeBase58)((0, import_utils33.concat)([extendedKey, checksum]));
8285
8041
  }
8286
8042
  /**
8287
8043
  * Create a new mnemonic using a randomly generated number as entropy.
@@ -8296,7 +8052,7 @@ var Mnemonic = class {
8296
8052
  * @returns A randomly generated mnemonic
8297
8053
  */
8298
8054
  static generate(size = 32, extraEntropy = "") {
8299
- 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);
8300
8056
  return Mnemonic.entropyToMnemonic(entropy);
8301
8057
  }
8302
8058
  };
@@ -8304,12 +8060,12 @@ var mnemonic_default = Mnemonic;
8304
8060
 
8305
8061
  // src/hdwallet/hdwallet.ts
8306
8062
  var HARDENED_INDEX = 2147483648;
8307
- var MainnetPRV2 = (0, import_utils34.hexlify)("0x0488ade4");
8308
- var MainnetPUB = (0, import_utils34.hexlify)("0x0488b21e");
8309
- var TestnetPRV2 = (0, import_utils34.hexlify)("0x04358394");
8310
- 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");
8311
8067
  function base58check(data) {
8312
- 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)]));
8313
8069
  }
8314
8070
  function getExtendedKeyPrefix(isPublic = false, testnet = false) {
8315
8071
  if (isPublic) {
@@ -8318,11 +8074,11 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
8318
8074
  return testnet ? TestnetPRV2 : MainnetPRV2;
8319
8075
  }
8320
8076
  function isPublicExtendedKey(extendedKey) {
8321
- 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)));
8322
8078
  }
8323
8079
  function isValidExtendedKey(extendedKey) {
8324
8080
  return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
8325
- (0, import_utils34.hexlify)(extendedKey.slice(0, 4))
8081
+ (0, import_utils35.hexlify)(extendedKey.slice(0, 4))
8326
8082
  );
8327
8083
  }
8328
8084
  function parsePath(path, depth = 0) {
@@ -8340,8 +8096,8 @@ function parsePath(path, depth = 0) {
8340
8096
  var HDWallet = class {
8341
8097
  depth = 0;
8342
8098
  index = 0;
8343
- fingerprint = (0, import_utils34.hexlify)("0x00000000");
8344
- parentFingerprint = (0, import_utils34.hexlify)("0x00000000");
8099
+ fingerprint = (0, import_utils35.hexlify)("0x00000000");
8100
+ parentFingerprint = (0, import_utils35.hexlify)("0x00000000");
8345
8101
  privateKey;
8346
8102
  publicKey;
8347
8103
  chainCode;
@@ -8353,8 +8109,8 @@ var HDWallet = class {
8353
8109
  constructor(config) {
8354
8110
  if (config.privateKey) {
8355
8111
  const signer = new Signer(config.privateKey);
8356
- this.publicKey = (0, import_utils34.hexlify)(signer.compressedPublicKey);
8357
- 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);
8358
8114
  } else {
8359
8115
  if (!config.publicKey) {
8360
8116
  throw new import_errors20.FuelError(
@@ -8362,7 +8118,7 @@ var HDWallet = class {
8362
8118
  "Both public and private Key cannot be missing. At least one should be provided."
8363
8119
  );
8364
8120
  }
8365
- this.publicKey = (0, import_utils34.hexlify)(config.publicKey);
8121
+ this.publicKey = (0, import_utils35.hexlify)(config.publicKey);
8366
8122
  }
8367
8123
  this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
8368
8124
  this.fingerprint = (0, import_ethers3.dataSlice)((0, import_ethers3.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
@@ -8381,9 +8137,9 @@ var HDWallet = class {
8381
8137
  * @returns A new instance of HDWallet on the derived index
8382
8138
  */
8383
8139
  deriveIndex(index) {
8384
- const privateKey = this.privateKey && (0, import_utils34.arrayify)(this.privateKey);
8385
- const publicKey = (0, import_utils34.arrayify)(this.publicKey);
8386
- 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);
8387
8143
  const data = new Uint8Array(37);
8388
8144
  if (index & HARDENED_INDEX) {
8389
8145
  if (!privateKey) {
@@ -8394,15 +8150,15 @@ var HDWallet = class {
8394
8150
  }
8395
8151
  data.set(privateKey, 1);
8396
8152
  } else {
8397
- data.set((0, import_utils34.arrayify)(this.publicKey));
8153
+ data.set((0, import_utils35.arrayify)(this.publicKey));
8398
8154
  }
8399
- data.set((0, import_math21.toBytes)(index, 4), 33);
8400
- 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));
8401
8157
  const IL = bytes.slice(0, 32);
8402
8158
  const IR = bytes.slice(32);
8403
8159
  if (privateKey) {
8404
8160
  const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
8405
- 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);
8406
8162
  return new HDWallet({
8407
8163
  privateKey: ki,
8408
8164
  chainCode: IR,
@@ -8411,7 +8167,7 @@ var HDWallet = class {
8411
8167
  parentFingerprint: this.fingerprint
8412
8168
  });
8413
8169
  }
8414
- const signer = new Signer((0, import_utils34.hexlify)(IL));
8170
+ const signer = new Signer((0, import_utils35.hexlify)(IL));
8415
8171
  const Ki = signer.addPoint(publicKey);
8416
8172
  return new HDWallet({
8417
8173
  publicKey: Ki,
@@ -8446,12 +8202,12 @@ var HDWallet = class {
8446
8202
  );
8447
8203
  }
8448
8204
  const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
8449
- const depth = (0, import_utils34.hexlify)(Uint8Array.from([this.depth]));
8205
+ const depth = (0, import_utils35.hexlify)(Uint8Array.from([this.depth]));
8450
8206
  const parentFingerprint = this.parentFingerprint;
8451
- const index = (0, import_math21.toHex)(this.index, 4);
8207
+ const index = (0, import_math20.toHex)(this.index, 4);
8452
8208
  const chainCode = this.chainCode;
8453
- const key = this.privateKey != null && !isPublic ? (0, import_utils34.concat)(["0x00", this.privateKey]) : this.publicKey;
8454
- 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]));
8455
8211
  return base58check(extendedKey);
8456
8212
  }
8457
8213
  /**
@@ -8463,13 +8219,13 @@ var HDWallet = class {
8463
8219
  static fromSeed(seed) {
8464
8220
  const masterKey = mnemonic_default.masterKeysFromSeed(seed);
8465
8221
  return new HDWallet({
8466
- chainCode: (0, import_utils34.arrayify)(masterKey.slice(32)),
8467
- 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))
8468
8224
  });
8469
8225
  }
8470
8226
  static fromExtendedKey(extendedKey) {
8471
8227
  const decoded = (0, import_ethers3.toBeHex)((0, import_ethers3.decodeBase58)(extendedKey));
8472
- const bytes = (0, import_utils34.arrayify)(decoded);
8228
+ const bytes = (0, import_utils35.arrayify)(decoded);
8473
8229
  const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
8474
8230
  if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
8475
8231
  throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
@@ -8478,9 +8234,9 @@ var HDWallet = class {
8478
8234
  throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
8479
8235
  }
8480
8236
  const depth = bytes[4];
8481
- const parentFingerprint = (0, import_utils34.hexlify)(bytes.slice(5, 9));
8482
- const index = parseInt((0, import_utils34.hexlify)(bytes.slice(9, 13)).substring(2), 16);
8483
- 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));
8484
8240
  const key = bytes.slice(45, 78);
8485
8241
  if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
8486
8242
  throw new import_errors20.FuelError(
@@ -9086,18 +8842,18 @@ var import_address10 = require("@fuel-ts/address");
9086
8842
  var import_configs13 = require("@fuel-ts/address/configs");
9087
8843
  var import_errors25 = require("@fuel-ts/errors");
9088
8844
  var import_transactions21 = require("@fuel-ts/transactions");
9089
- var import_utils36 = require("@fuel-ts/utils");
8845
+ var import_utils37 = require("@fuel-ts/utils");
9090
8846
 
9091
8847
  // src/predicate/utils/getPredicateRoot.ts
9092
8848
  var import_hasher7 = require("@fuel-ts/hasher");
9093
8849
  var import_merkle = require("@fuel-ts/merkle");
9094
- var import_utils35 = require("@fuel-ts/utils");
8850
+ var import_utils36 = require("@fuel-ts/utils");
9095
8851
  var getPredicateRoot = (bytecode) => {
9096
8852
  const chunkSize = 16 * 1024;
9097
- const bytes = (0, import_utils35.arrayify)(bytecode);
9098
- const chunks = (0, import_utils35.chunkAndPadBytes)(bytes, chunkSize);
9099
- const codeRoot = (0, import_merkle.calcRoot)(chunks.map((c) => (0, import_utils35.hexlify)(c)));
9100
- 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]));
9101
8857
  return predicateRoot;
9102
8858
  };
9103
8859
 
@@ -9144,10 +8900,15 @@ var Predicate = class extends Account {
9144
8900
  populateTransactionPredicateData(transactionRequestLike) {
9145
8901
  const request = transactionRequestify(transactionRequestLike);
9146
8902
  const { policies } = BaseTransactionRequest.getPolicyMeta(request);
9147
- request.inputs?.forEach((input) => {
9148
- if (input.type === import_transactions21.InputType.Coin && (0, import_utils36.hexlify)(input.owner) === this.address.toB256()) {
9149
- input.predicate = (0, import_utils36.hexlify)(this.bytes);
9150
- 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;
9151
8912
  }
9152
8913
  });
9153
8914
  return request;
@@ -9162,7 +8923,8 @@ var Predicate = class extends Account {
9162
8923
  * @returns A promise that resolves to the prepared transaction request.
9163
8924
  */
9164
8925
  async createTransfer(destination, amount, assetId = import_configs13.BaseAssetId, txParams = {}) {
9165
- return super.createTransfer(destination, amount, assetId, txParams);
8926
+ const request = await super.createTransfer(destination, amount, assetId, txParams);
8927
+ return this.populateTransactionPredicateData(request);
9166
8928
  }
9167
8929
  /**
9168
8930
  * Sends a transaction with the populated predicate data.
@@ -9170,9 +8932,9 @@ var Predicate = class extends Account {
9170
8932
  * @param transactionRequestLike - The transaction request-like object.
9171
8933
  * @returns A promise that resolves to the transaction response.
9172
8934
  */
9173
- sendTransaction(transactionRequestLike) {
9174
- const transactionRequest = transactionRequestify(transactionRequestLike);
9175
- return super.sendTransaction(transactionRequest, { estimateTxDependencies: false });
8935
+ sendTransaction(transactionRequestLike, options) {
8936
+ const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
8937
+ return super.sendTransaction(transactionRequest, options);
9176
8938
  }
9177
8939
  /**
9178
8940
  * Simulates a transaction with the populated predicate data.
@@ -9181,8 +8943,22 @@ var Predicate = class extends Account {
9181
8943
  * @returns A promise that resolves to the call result.
9182
8944
  */
9183
8945
  simulateTransaction(transactionRequestLike) {
9184
- const transactionRequest = transactionRequestify(transactionRequestLike);
9185
- 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
+ }));
9186
8962
  }
9187
8963
  getPredicateData(policiesLength) {
9188
8964
  if (!this.predicateData.length) {
@@ -9205,7 +8981,7 @@ var Predicate = class extends Account {
9205
8981
  * @returns An object containing the new predicate bytes and interface.
9206
8982
  */
9207
8983
  static processPredicateData(bytes, jsonAbi, configurableConstants) {
9208
- let predicateBytes = (0, import_utils36.arrayify)(bytes);
8984
+ let predicateBytes = (0, import_utils37.arrayify)(bytes);
9209
8985
  let abiInterface;
9210
8986
  if (jsonAbi) {
9211
8987
  abiInterface = new import_abi_coder7.Interface(jsonAbi);
@@ -9228,25 +9004,6 @@ var Predicate = class extends Account {
9228
9004
  predicateInterface: abiInterface
9229
9005
  };
9230
9006
  }
9231
- /**
9232
- * Retrieves resources satisfying the spend query for the account.
9233
- *
9234
- * @param quantities - IDs of coins to exclude.
9235
- * @param excludedIds - IDs of resources to be excluded from the query.
9236
- * @returns A promise that resolves to an array of Resources.
9237
- */
9238
- async getResourcesToSpend(quantities, excludedIds) {
9239
- const resources = await this.provider.getResourcesToSpend(
9240
- this.address,
9241
- quantities,
9242
- excludedIds
9243
- );
9244
- return resources.map((resource) => ({
9245
- ...resource,
9246
- predicate: (0, import_utils36.hexlify)(this.bytes),
9247
- paddPredicateData: (policiesLength) => (0, import_utils36.hexlify)(this.getPredicateData(policiesLength))
9248
- }));
9249
- }
9250
9007
  /**
9251
9008
  * Sets the configurable constants for the predicate.
9252
9009
  *
@@ -9282,6 +9039,28 @@ var Predicate = class extends Account {
9282
9039
  }
9283
9040
  return mutatedBytes;
9284
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
+ }
9285
9064
  };
9286
9065
 
9287
9066
  // src/connectors/fuel.ts
@@ -9996,7 +9775,7 @@ __publicField(Fuel, "defaultConfig", {});
9996
9775
  WalletLocked,
9997
9776
  WalletManager,
9998
9777
  WalletUnlocked,
9999
- addAmountToCoinQuantities,
9778
+ addAmountToAsset,
10000
9779
  addOperation,
10001
9780
  assemblePanicError,
10002
9781
  assembleReceiptByType,
@@ -10005,10 +9784,10 @@ __publicField(Fuel, "defaultConfig", {});
10005
9784
  assets,
10006
9785
  buildBlockExplorerUrl,
10007
9786
  cacheFor,
10008
- cacheTxInputsFromOwner,
10009
- calculateGasFee,
9787
+ cacheResources,
10010
9788
  calculateMetadataGasForTxCreate,
10011
9789
  calculateMetadataGasForTxScript,
9790
+ calculatePriceWithFactor,
10012
9791
  calculateTransactionFee,
10013
9792
  coinQuantityfy,
10014
9793
  deferPromise,
@@ -10052,6 +9831,7 @@ __publicField(Fuel, "defaultConfig", {});
10052
9831
  getReceiptsMessageOut,
10053
9832
  getReceiptsTransferOut,
10054
9833
  getReceiptsWithMissingData,
9834
+ getRequestInputResourceOwner,
10055
9835
  getTransactionStatusName,
10056
9836
  getTransactionSummary,
10057
9837
  getTransactionSummaryFromRequest,
@@ -10065,6 +9845,10 @@ __publicField(Fuel, "defaultConfig", {});
10065
9845
  isMessage,
10066
9846
  isRawCoin,
10067
9847
  isRawMessage,
9848
+ isRequestInputCoin,
9849
+ isRequestInputMessage,
9850
+ isRequestInputResource,
9851
+ isRequestInputResourceFromOwner,
10068
9852
  isType,
10069
9853
  isTypeCreate,
10070
9854
  isTypeMint,