@fuel-ts/account 0.81.0 → 0.83.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of @fuel-ts/account might be problematic. Click here for more details.

Files changed (57) hide show
  1. package/README.md +3 -3
  2. package/dist/account.d.ts +7 -6
  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 +890 -619
  12. package/dist/index.global.js.map +1 -1
  13. package/dist/index.js +853 -604
  14. package/dist/index.js.map +1 -1
  15. package/dist/index.mjs +696 -448
  16. package/dist/index.mjs.map +1 -1
  17. package/dist/predicate/predicate.d.ts +12 -24
  18. package/dist/predicate/predicate.d.ts.map +1 -1
  19. package/dist/providers/__generated__/operations.d.ts +810 -359
  20. package/dist/providers/__generated__/operations.d.ts.map +1 -1
  21. package/dist/providers/coin-quantity.d.ts +3 -3
  22. package/dist/providers/coin-quantity.d.ts.map +1 -1
  23. package/dist/providers/coin.d.ts +4 -2
  24. package/dist/providers/coin.d.ts.map +1 -1
  25. package/dist/providers/message.d.ts +7 -1
  26. package/dist/providers/message.d.ts.map +1 -1
  27. package/dist/providers/provider.d.ts +44 -27
  28. package/dist/providers/provider.d.ts.map +1 -1
  29. package/dist/providers/transaction-request/create-transaction-request.d.ts +1 -1
  30. package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
  31. package/dist/providers/transaction-request/input.d.ts +2 -2
  32. package/dist/providers/transaction-request/input.d.ts.map +1 -1
  33. package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
  34. package/dist/providers/transaction-request/transaction-request.d.ts +13 -33
  35. package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
  36. package/dist/providers/transaction-request/utils.d.ts +3 -0
  37. package/dist/providers/transaction-request/utils.d.ts.map +1 -1
  38. package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
  39. package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts +2 -0
  40. package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
  41. package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts +3 -2
  42. package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts.map +1 -1
  43. package/dist/providers/transaction-summary/get-transaction-summary.d.ts.map +1 -1
  44. package/dist/providers/utils/gas.d.ts +8 -2
  45. package/dist/providers/utils/gas.d.ts.map +1 -1
  46. package/dist/providers/utils/merge-quantities.d.ts +1 -1
  47. package/dist/providers/utils/merge-quantities.d.ts.map +1 -1
  48. package/dist/test-utils/launchNode.d.ts +1 -1
  49. package/dist/test-utils/launchNode.d.ts.map +1 -1
  50. package/dist/test-utils.global.js +1615 -1114
  51. package/dist/test-utils.global.js.map +1 -1
  52. package/dist/test-utils.js +841 -596
  53. package/dist/test-utils.js.map +1 -1
  54. package/dist/test-utils.mjs +696 -451
  55. package/dist/test-utils.mjs.map +1 -1
  56. package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
  57. package/package.json +16 -16
package/dist/index.js CHANGED
@@ -95,7 +95,7 @@ __export(src_exports, {
95
95
  WalletLocked: () => WalletLocked,
96
96
  WalletManager: () => WalletManager,
97
97
  WalletUnlocked: () => WalletUnlocked,
98
- addAmountToAsset: () => addAmountToAsset,
98
+ addAmountToCoinQuantities: () => addAmountToCoinQuantities,
99
99
  addOperation: () => addOperation,
100
100
  assemblePanicError: () => assemblePanicError,
101
101
  assembleReceiptByType: () => assembleReceiptByType,
@@ -104,9 +104,10 @@ __export(src_exports, {
104
104
  assets: () => assets,
105
105
  buildBlockExplorerUrl: () => buildBlockExplorerUrl,
106
106
  cacheFor: () => cacheFor,
107
+ cacheTxInputsFromOwner: () => cacheTxInputsFromOwner,
108
+ calculateGasFee: () => calculateGasFee,
107
109
  calculateMetadataGasForTxCreate: () => calculateMetadataGasForTxCreate,
108
110
  calculateMetadataGasForTxScript: () => calculateMetadataGasForTxScript,
109
- calculatePriceWithFactor: () => calculatePriceWithFactor,
110
111
  calculateTransactionFee: () => calculateTransactionFee,
111
112
  coinQuantityfy: () => coinQuantityfy,
112
113
  deferPromise: () => deferPromise,
@@ -184,37 +185,36 @@ module.exports = __toCommonJS(src_exports);
184
185
 
185
186
  // src/account.ts
186
187
  var import_address4 = require("@fuel-ts/address");
187
- var import_configs12 = require("@fuel-ts/address/configs");
188
188
  var import_errors16 = require("@fuel-ts/errors");
189
189
  var import_interfaces = require("@fuel-ts/interfaces");
190
- var import_math18 = require("@fuel-ts/math");
191
- var import_utils28 = require("@fuel-ts/utils");
190
+ var import_math19 = require("@fuel-ts/math");
191
+ var import_utils27 = require("@fuel-ts/utils");
192
+ var import_ramda4 = require("ramda");
192
193
 
193
194
  // src/providers/coin-quantity.ts
194
- var import_configs = require("@fuel-ts/address/configs");
195
195
  var import_math = require("@fuel-ts/math");
196
196
  var import_utils = require("@fuel-ts/utils");
197
197
  var coinQuantityfy = (coinQuantityLike) => {
198
198
  let assetId;
199
199
  let amount;
200
- let max2;
200
+ let max;
201
201
  if (Array.isArray(coinQuantityLike)) {
202
202
  amount = coinQuantityLike[0];
203
- assetId = coinQuantityLike[1] ?? import_configs.BaseAssetId;
204
- max2 = coinQuantityLike[2] ?? void 0;
203
+ assetId = coinQuantityLike[1];
204
+ max = coinQuantityLike[2] ?? void 0;
205
205
  } else {
206
206
  amount = coinQuantityLike.amount;
207
- assetId = coinQuantityLike.assetId ?? import_configs.BaseAssetId;
208
- max2 = coinQuantityLike.max ?? void 0;
207
+ assetId = coinQuantityLike.assetId;
208
+ max = coinQuantityLike.max ?? void 0;
209
209
  }
210
210
  const bnAmount = (0, import_math.bn)(amount);
211
211
  return {
212
212
  assetId: (0, import_utils.hexlify)(assetId),
213
213
  amount: bnAmount.lt(1) ? (0, import_math.bn)(1) : bnAmount,
214
- max: max2 ? (0, import_math.bn)(max2) : void 0
214
+ max: max ? (0, import_math.bn)(max) : void 0
215
215
  };
216
216
  };
217
- var addAmountToAsset = (params) => {
217
+ var addAmountToCoinQuantities = (params) => {
218
218
  const { amount, assetId } = params;
219
219
  const coinQuantities = [...params.coinQuantities];
220
220
  const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
@@ -229,27 +229,31 @@ var addAmountToAsset = (params) => {
229
229
  // src/providers/provider.ts
230
230
  var import_address3 = require("@fuel-ts/address");
231
231
  var import_errors14 = require("@fuel-ts/errors");
232
- var import_math15 = require("@fuel-ts/math");
233
- var import_transactions18 = require("@fuel-ts/transactions");
234
- var import_utils23 = require("@fuel-ts/utils");
232
+ var import_math16 = require("@fuel-ts/math");
233
+ var import_transactions19 = require("@fuel-ts/transactions");
234
+ var import_utils22 = require("@fuel-ts/utils");
235
235
  var import_versions = require("@fuel-ts/versions");
236
- var import_utils24 = require("@noble/curves/abstract/utils");
236
+ var import_utils23 = require("@noble/curves/abstract/utils");
237
237
  var import_ethers = require("ethers");
238
238
  var import_graphql_request = require("graphql-request");
239
239
  var import_ramda3 = require("ramda");
240
240
 
241
241
  // src/providers/__generated__/operations.ts
242
242
  var import_graphql_tag = __toESM(require("graphql-tag"));
243
+ var TransactionStatusSubscriptionFragmentFragmentDoc = import_graphql_tag.default`
244
+ fragment transactionStatusSubscriptionFragment on TransactionStatus {
245
+ type: __typename
246
+ ... on SqueezedOutStatus {
247
+ reason
248
+ }
249
+ }
250
+ `;
243
251
  var ReceiptFragmentFragmentDoc = import_graphql_tag.default`
244
252
  fragment receiptFragment on Receipt {
245
- contract {
246
- id
247
- }
253
+ id
248
254
  pc
249
255
  is
250
- to {
251
- id
252
- }
256
+ to
253
257
  toAddress
254
258
  amount
255
259
  assetId
@@ -287,10 +291,16 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
287
291
  id
288
292
  }
289
293
  time
294
+ receipts {
295
+ ...receiptFragment
296
+ }
290
297
  programState {
291
298
  returnType
292
299
  data
293
300
  }
301
+ receipts {
302
+ ...receiptFragment
303
+ }
294
304
  }
295
305
  ... on FailureStatus {
296
306
  block {
@@ -298,26 +308,24 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
298
308
  }
299
309
  time
300
310
  reason
311
+ receipts {
312
+ ...receiptFragment
313
+ }
301
314
  }
302
315
  ... on SqueezedOutStatus {
303
316
  reason
304
317
  }
305
318
  }
306
- `;
319
+ ${ReceiptFragmentFragmentDoc}`;
307
320
  var TransactionFragmentFragmentDoc = import_graphql_tag.default`
308
321
  fragment transactionFragment on Transaction {
309
322
  id
310
323
  rawPayload
311
- gasPrice
312
- receipts {
313
- ...receiptFragment
314
- }
315
324
  status {
316
325
  ...transactionStatusFragment
317
326
  }
318
327
  }
319
- ${ReceiptFragmentFragmentDoc}
320
- ${TransactionStatusFragmentFragmentDoc}`;
328
+ ${TransactionStatusFragmentFragmentDoc}`;
321
329
  var InputEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.default`
322
330
  fragment inputEstimatePredicatesFragment on Input {
323
331
  ... on InputCoin {
@@ -335,6 +343,46 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.defaul
335
343
  }
336
344
  }
337
345
  ${InputEstimatePredicatesFragmentFragmentDoc}`;
346
+ var DryRunFailureStatusFragmentFragmentDoc = import_graphql_tag.default`
347
+ fragment dryRunFailureStatusFragment on DryRunFailureStatus {
348
+ reason
349
+ programState {
350
+ returnType
351
+ data
352
+ }
353
+ }
354
+ `;
355
+ var DryRunSuccessStatusFragmentFragmentDoc = import_graphql_tag.default`
356
+ fragment dryRunSuccessStatusFragment on DryRunSuccessStatus {
357
+ programState {
358
+ returnType
359
+ data
360
+ }
361
+ }
362
+ `;
363
+ var DryRunTransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
364
+ fragment dryRunTransactionStatusFragment on DryRunTransactionStatus {
365
+ ... on DryRunFailureStatus {
366
+ ...dryRunFailureStatusFragment
367
+ }
368
+ ... on DryRunSuccessStatus {
369
+ ...dryRunSuccessStatusFragment
370
+ }
371
+ }
372
+ ${DryRunFailureStatusFragmentFragmentDoc}
373
+ ${DryRunSuccessStatusFragmentFragmentDoc}`;
374
+ var DryRunTransactionExecutionStatusFragmentFragmentDoc = import_graphql_tag.default`
375
+ fragment dryRunTransactionExecutionStatusFragment on DryRunTransactionExecutionStatus {
376
+ id
377
+ status {
378
+ ...dryRunTransactionStatusFragment
379
+ }
380
+ receipts {
381
+ ...receiptFragment
382
+ }
383
+ }
384
+ ${DryRunTransactionStatusFragmentFragmentDoc}
385
+ ${ReceiptFragmentFragmentDoc}`;
338
386
  var CoinFragmentFragmentDoc = import_graphql_tag.default`
339
387
  fragment coinFragment on Coin {
340
388
  __typename
@@ -342,7 +390,6 @@ var CoinFragmentFragmentDoc = import_graphql_tag.default`
342
390
  owner
343
391
  amount
344
392
  assetId
345
- maturity
346
393
  blockCreated
347
394
  txCreatedIdx
348
395
  }
@@ -381,26 +428,32 @@ var MessageProofFragmentFragmentDoc = import_graphql_tag.default`
381
428
  messageBlockHeader {
382
429
  id
383
430
  daHeight
431
+ consensusParametersVersion
432
+ stateTransitionBytecodeVersion
384
433
  transactionsCount
434
+ messageReceiptCount
385
435
  transactionsRoot
436
+ messageOutboxRoot
437
+ eventInboxRoot
386
438
  height
387
439
  prevRoot
388
440
  time
389
441
  applicationHash
390
- messageReceiptRoot
391
- messageReceiptCount
392
442
  }
393
443
  commitBlockHeader {
394
444
  id
395
445
  daHeight
446
+ consensusParametersVersion
447
+ stateTransitionBytecodeVersion
396
448
  transactionsCount
449
+ messageReceiptCount
397
450
  transactionsRoot
451
+ messageOutboxRoot
452
+ eventInboxRoot
398
453
  height
399
454
  prevRoot
400
455
  time
401
456
  applicationHash
402
- messageReceiptRoot
403
- messageReceiptCount
404
457
  }
405
458
  sender
406
459
  recipient
@@ -419,8 +472,8 @@ var BalanceFragmentFragmentDoc = import_graphql_tag.default`
419
472
  var BlockFragmentFragmentDoc = import_graphql_tag.default`
420
473
  fragment blockFragment on Block {
421
474
  id
475
+ height
422
476
  header {
423
- height
424
477
  time
425
478
  }
426
479
  transactions {
@@ -430,6 +483,7 @@ var BlockFragmentFragmentDoc = import_graphql_tag.default`
430
483
  `;
431
484
  var TxParametersFragmentFragmentDoc = import_graphql_tag.default`
432
485
  fragment TxParametersFragment on TxParameters {
486
+ version
433
487
  maxInputs
434
488
  maxOutputs
435
489
  maxWitnesses
@@ -439,6 +493,7 @@ var TxParametersFragmentFragmentDoc = import_graphql_tag.default`
439
493
  `;
440
494
  var PredicateParametersFragmentFragmentDoc = import_graphql_tag.default`
441
495
  fragment PredicateParametersFragment on PredicateParameters {
496
+ version
442
497
  maxPredicateLength
443
498
  maxPredicateDataLength
444
499
  maxGasPerPredicate
@@ -447,18 +502,21 @@ var PredicateParametersFragmentFragmentDoc = import_graphql_tag.default`
447
502
  `;
448
503
  var ScriptParametersFragmentFragmentDoc = import_graphql_tag.default`
449
504
  fragment ScriptParametersFragment on ScriptParameters {
505
+ version
450
506
  maxScriptLength
451
507
  maxScriptDataLength
452
508
  }
453
509
  `;
454
510
  var ContractParametersFragmentFragmentDoc = import_graphql_tag.default`
455
511
  fragment ContractParametersFragment on ContractParameters {
512
+ version
456
513
  contractMaxSize
457
514
  maxStorageSlots
458
515
  }
459
516
  `;
460
517
  var FeeParametersFragmentFragmentDoc = import_graphql_tag.default`
461
518
  fragment FeeParametersFragment on FeeParameters {
519
+ version
462
520
  gasPriceFactor
463
521
  gasPerByte
464
522
  }
@@ -478,6 +536,7 @@ var DependentCostFragmentFragmentDoc = import_graphql_tag.default`
478
536
  `;
479
537
  var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
480
538
  fragment GasCostsFragment on GasCosts {
539
+ version
481
540
  add
482
541
  addi
483
542
  aloc
@@ -490,7 +549,6 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
490
549
  cb
491
550
  cfei
492
551
  cfsi
493
- croo
494
552
  div
495
553
  divi
496
554
  ecr1
@@ -573,6 +631,9 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
573
631
  ccp {
574
632
  ...DependentCostFragment
575
633
  }
634
+ croo {
635
+ ...DependentCostFragment
636
+ }
576
637
  csiz {
577
638
  ...DependentCostFragment
578
639
  }
@@ -632,6 +693,7 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
632
693
  ${DependentCostFragmentFragmentDoc}`;
633
694
  var ConsensusParametersFragmentFragmentDoc = import_graphql_tag.default`
634
695
  fragment consensusParametersFragment on ConsensusParameters {
696
+ version
635
697
  txParams {
636
698
  ...TxParametersFragment
637
699
  }
@@ -691,18 +753,9 @@ var NodeInfoFragmentFragmentDoc = import_graphql_tag.default`
691
753
  fragment nodeInfoFragment on NodeInfo {
692
754
  utxoValidation
693
755
  vmBacktrace
694
- minGasPrice
695
756
  maxTx
696
757
  maxDepth
697
758
  nodeVersion
698
- peers {
699
- id
700
- addresses
701
- clientVersion
702
- blockHeight
703
- lastHeartbeatMs
704
- appScore
705
- }
706
759
  }
707
760
  `;
708
761
  var GetVersionDocument = import_graphql_tag.default`
@@ -737,13 +790,9 @@ var GetTransactionWithReceiptsDocument = import_graphql_tag.default`
737
790
  query getTransactionWithReceipts($transactionId: TransactionId!) {
738
791
  transaction(id: $transactionId) {
739
792
  ...transactionFragment
740
- receipts {
741
- ...receiptFragment
742
- }
743
793
  }
744
794
  }
745
- ${TransactionFragmentFragmentDoc}
746
- ${ReceiptFragmentFragmentDoc}`;
795
+ ${TransactionFragmentFragmentDoc}`;
747
796
  var GetTransactionsDocument = import_graphql_tag.default`
748
797
  query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
749
798
  transactions(after: $after, before: $before, first: $first, last: $last) {
@@ -871,6 +920,20 @@ var GetBalanceDocument = import_graphql_tag.default`
871
920
  }
872
921
  }
873
922
  ${BalanceFragmentFragmentDoc}`;
923
+ var GetLatestGasPriceDocument = import_graphql_tag.default`
924
+ query getLatestGasPrice {
925
+ latestGasPrice {
926
+ gasPrice
927
+ }
928
+ }
929
+ `;
930
+ var EstimateGasPriceDocument = import_graphql_tag.default`
931
+ query estimateGasPrice($blockHorizon: U32!) {
932
+ estimateGasPrice(blockHorizon: $blockHorizon) {
933
+ gasPrice
934
+ }
935
+ }
936
+ `;
874
937
  var GetBalancesDocument = import_graphql_tag.default`
875
938
  query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
876
939
  balances(
@@ -925,12 +988,12 @@ var GetMessageStatusDocument = import_graphql_tag.default`
925
988
  }
926
989
  `;
927
990
  var DryRunDocument = import_graphql_tag.default`
928
- mutation dryRun($encodedTransaction: HexString!, $utxoValidation: Boolean) {
929
- dryRun(tx: $encodedTransaction, utxoValidation: $utxoValidation) {
930
- ...receiptFragment
991
+ mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean) {
992
+ dryRun(txs: $encodedTransactions, utxoValidation: $utxoValidation) {
993
+ ...dryRunTransactionExecutionStatusFragment
931
994
  }
932
995
  }
933
- ${ReceiptFragmentFragmentDoc}`;
996
+ ${DryRunTransactionExecutionStatusFragmentFragmentDoc}`;
934
997
  var SubmitDocument = import_graphql_tag.default`
935
998
  mutation submit($encodedTransaction: HexString!) {
936
999
  submit(tx: $encodedTransaction) {
@@ -949,17 +1012,17 @@ var ProduceBlocksDocument = import_graphql_tag.default`
949
1012
  var SubmitAndAwaitDocument = import_graphql_tag.default`
950
1013
  subscription submitAndAwait($encodedTransaction: HexString!) {
951
1014
  submitAndAwait(tx: $encodedTransaction) {
952
- ...transactionStatusFragment
1015
+ ...transactionStatusSubscriptionFragment
953
1016
  }
954
1017
  }
955
- ${TransactionStatusFragmentFragmentDoc}`;
1018
+ ${TransactionStatusSubscriptionFragmentFragmentDoc}`;
956
1019
  var StatusChangeDocument = import_graphql_tag.default`
957
1020
  subscription statusChange($transactionId: TransactionId!) {
958
1021
  statusChange(id: $transactionId) {
959
- ...transactionStatusFragment
1022
+ ...transactionStatusSubscriptionFragment
960
1023
  }
961
1024
  }
962
- ${TransactionStatusFragmentFragmentDoc}`;
1025
+ ${TransactionStatusSubscriptionFragmentFragmentDoc}`;
963
1026
  function getSdk(requester) {
964
1027
  return {
965
1028
  getVersion(variables, options) {
@@ -1013,6 +1076,12 @@ function getSdk(requester) {
1013
1076
  getBalance(variables, options) {
1014
1077
  return requester(GetBalanceDocument, variables, options);
1015
1078
  },
1079
+ getLatestGasPrice(variables, options) {
1080
+ return requester(GetLatestGasPriceDocument, variables, options);
1081
+ },
1082
+ estimateGasPrice(variables, options) {
1083
+ return requester(EstimateGasPriceDocument, variables, options);
1084
+ },
1016
1085
  getBalances(variables, options) {
1017
1086
  return requester(GetBalancesDocument, variables, options);
1018
1087
  },
@@ -1183,7 +1252,7 @@ var MemoryCache = class {
1183
1252
 
1184
1253
  // src/providers/transaction-request/input.ts
1185
1254
  var import_abi_coder = require("@fuel-ts/abi-coder");
1186
- var import_configs2 = require("@fuel-ts/address/configs");
1255
+ var import_configs = require("@fuel-ts/address/configs");
1187
1256
  var import_errors3 = require("@fuel-ts/errors");
1188
1257
  var import_math2 = require("@fuel-ts/math");
1189
1258
  var import_transactions = require("@fuel-ts/transactions");
@@ -1206,10 +1275,9 @@ var inputify = (value) => {
1206
1275
  txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
1207
1276
  },
1208
1277
  witnessIndex: value.witnessIndex,
1209
- maturity: value.maturity ?? 0,
1210
1278
  predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
1211
- predicateLength: predicate.length,
1212
- predicateDataLength: predicateData.length,
1279
+ predicateLength: (0, import_math2.bn)(predicate.length),
1280
+ predicateDataLength: (0, import_math2.bn)(predicateData.length),
1213
1281
  predicate: (0, import_utils3.hexlify)(predicate),
1214
1282
  predicateData: (0, import_utils3.hexlify)(predicateData)
1215
1283
  };
@@ -1217,10 +1285,10 @@ var inputify = (value) => {
1217
1285
  case import_transactions.InputType.Contract: {
1218
1286
  return {
1219
1287
  type: import_transactions.InputType.Contract,
1220
- txID: import_configs2.ZeroBytes32,
1288
+ txID: import_configs.ZeroBytes32,
1221
1289
  outputIndex: 0,
1222
- balanceRoot: import_configs2.ZeroBytes32,
1223
- stateRoot: import_configs2.ZeroBytes32,
1290
+ balanceRoot: import_configs.ZeroBytes32,
1291
+ stateRoot: import_configs.ZeroBytes32,
1224
1292
  txPointer: {
1225
1293
  blockHeight: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(0, 8)),
1226
1294
  txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
@@ -1240,8 +1308,8 @@ var inputify = (value) => {
1240
1308
  nonce: (0, import_utils3.hexlify)(value.nonce),
1241
1309
  witnessIndex: value.witnessIndex,
1242
1310
  predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
1243
- predicateLength: predicate.length,
1244
- predicateDataLength: predicateData.length,
1311
+ predicateLength: (0, import_math2.bn)(predicate.length),
1312
+ predicateDataLength: (0, import_math2.bn)(predicateData.length),
1245
1313
  predicate: (0, import_utils3.hexlify)(predicate),
1246
1314
  predicateData: (0, import_utils3.hexlify)(predicateData),
1247
1315
  data: (0, import_utils3.hexlify)(data),
@@ -1258,7 +1326,7 @@ var inputify = (value) => {
1258
1326
  };
1259
1327
 
1260
1328
  // src/providers/transaction-request/output.ts
1261
- var import_configs3 = require("@fuel-ts/address/configs");
1329
+ var import_configs2 = require("@fuel-ts/address/configs");
1262
1330
  var import_errors4 = require("@fuel-ts/errors");
1263
1331
  var import_math3 = require("@fuel-ts/math");
1264
1332
  var import_transactions2 = require("@fuel-ts/transactions");
@@ -1278,8 +1346,8 @@ var outputify = (value) => {
1278
1346
  return {
1279
1347
  type: import_transactions2.OutputType.Contract,
1280
1348
  inputIndex: value.inputIndex,
1281
- balanceRoot: import_configs3.ZeroBytes32,
1282
- stateRoot: import_configs3.ZeroBytes32
1349
+ balanceRoot: import_configs2.ZeroBytes32,
1350
+ stateRoot: import_configs2.ZeroBytes32
1283
1351
  };
1284
1352
  }
1285
1353
  case import_transactions2.OutputType.Change: {
@@ -1293,9 +1361,9 @@ var outputify = (value) => {
1293
1361
  case import_transactions2.OutputType.Variable: {
1294
1362
  return {
1295
1363
  type: import_transactions2.OutputType.Variable,
1296
- to: import_configs3.ZeroBytes32,
1364
+ to: import_configs2.ZeroBytes32,
1297
1365
  amount: (0, import_math3.bn)(0),
1298
- assetId: import_configs3.ZeroBytes32
1366
+ assetId: import_configs2.ZeroBytes32
1299
1367
  };
1300
1368
  }
1301
1369
  case import_transactions2.OutputType.ContractCreated: {
@@ -1317,7 +1385,7 @@ var outputify = (value) => {
1317
1385
  // src/providers/transaction-request/transaction-request.ts
1318
1386
  var import_abi_coder2 = require("@fuel-ts/abi-coder");
1319
1387
  var import_address = require("@fuel-ts/address");
1320
- var import_configs7 = require("@fuel-ts/address/configs");
1388
+ var import_configs6 = require("@fuel-ts/address/configs");
1321
1389
  var import_crypto = require("@fuel-ts/crypto");
1322
1390
  var import_math7 = require("@fuel-ts/math");
1323
1391
  var import_transactions6 = require("@fuel-ts/transactions");
@@ -1330,13 +1398,13 @@ var isCoin = (resource) => "id" in resource;
1330
1398
  var isMessage = (resource) => "recipient" in resource;
1331
1399
 
1332
1400
  // src/providers/utils/receipts.ts
1333
- var import_configs4 = require("@fuel-ts/address/configs");
1401
+ var import_configs3 = require("@fuel-ts/address/configs");
1334
1402
  var import_errors5 = require("@fuel-ts/errors");
1335
1403
  var import_math4 = require("@fuel-ts/math");
1336
1404
  var import_transactions3 = require("@fuel-ts/transactions");
1337
- var import_configs5 = require("@fuel-ts/transactions/configs");
1405
+ var import_configs4 = require("@fuel-ts/transactions/configs");
1338
1406
  var import_utils5 = require("@fuel-ts/utils");
1339
- var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions3.ReceiptType.Revert && receipt.val.toString("hex") === import_configs5.FAILED_TRANSFER_TO_ADDRESS_SIGNAL;
1407
+ var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions3.ReceiptType.Revert && receipt.val.toString("hex") === import_configs4.FAILED_TRANSFER_TO_ADDRESS_SIGNAL;
1340
1408
  var doesReceiptHaveMissingContractId = (receipt) => receipt.type === import_transactions3.ReceiptType.Panic && receipt.contractId !== "0x0000000000000000000000000000000000000000000000000000000000000000";
1341
1409
  var getReceiptsWithMissingData = (receipts) => receipts.reduce(
1342
1410
  (memo, receipt) => {
@@ -1353,15 +1421,15 @@ var getReceiptsWithMissingData = (receipts) => receipts.reduce(
1353
1421
  missingOutputContractIds: []
1354
1422
  }
1355
1423
  );
1356
- var hexOrZero = (hex) => hex || import_configs4.ZeroBytes32;
1424
+ var hexOrZero = (hex) => hex || import_configs3.ZeroBytes32;
1357
1425
  function assembleReceiptByType(receipt) {
1358
1426
  const { receiptType } = receipt;
1359
1427
  switch (receiptType) {
1360
1428
  case "CALL" /* Call */: {
1361
1429
  const callReceipt = {
1362
1430
  type: import_transactions3.ReceiptType.Call,
1363
- from: hexOrZero(receipt.contract?.id),
1364
- to: hexOrZero(receipt?.to?.id),
1431
+ from: hexOrZero(receipt.id || receipt.contractId),
1432
+ to: hexOrZero(receipt?.to),
1365
1433
  amount: (0, import_math4.bn)(receipt.amount),
1366
1434
  assetId: hexOrZero(receipt.assetId),
1367
1435
  gas: (0, import_math4.bn)(receipt.gas),
@@ -1375,7 +1443,7 @@ function assembleReceiptByType(receipt) {
1375
1443
  case "RETURN" /* Return */: {
1376
1444
  const returnReceipt = {
1377
1445
  type: import_transactions3.ReceiptType.Return,
1378
- id: hexOrZero(receipt.contract?.id),
1446
+ id: hexOrZero(receipt.id || receipt.contractId),
1379
1447
  val: (0, import_math4.bn)(receipt.val),
1380
1448
  pc: (0, import_math4.bn)(receipt.pc),
1381
1449
  is: (0, import_math4.bn)(receipt.is)
@@ -1385,7 +1453,7 @@ function assembleReceiptByType(receipt) {
1385
1453
  case "RETURN_DATA" /* ReturnData */: {
1386
1454
  const returnDataReceipt = {
1387
1455
  type: import_transactions3.ReceiptType.ReturnData,
1388
- id: hexOrZero(receipt.contract?.id),
1456
+ id: hexOrZero(receipt.id || receipt.contractId),
1389
1457
  ptr: (0, import_math4.bn)(receipt.ptr),
1390
1458
  len: (0, import_math4.bn)(receipt.len),
1391
1459
  digest: hexOrZero(receipt.digest),
@@ -1397,7 +1465,7 @@ function assembleReceiptByType(receipt) {
1397
1465
  case "PANIC" /* Panic */: {
1398
1466
  const panicReceipt = {
1399
1467
  type: import_transactions3.ReceiptType.Panic,
1400
- id: hexOrZero(receipt.contract?.id),
1468
+ id: hexOrZero(receipt.id),
1401
1469
  reason: (0, import_math4.bn)(receipt.reason),
1402
1470
  pc: (0, import_math4.bn)(receipt.pc),
1403
1471
  is: (0, import_math4.bn)(receipt.is),
@@ -1408,7 +1476,7 @@ function assembleReceiptByType(receipt) {
1408
1476
  case "REVERT" /* Revert */: {
1409
1477
  const revertReceipt = {
1410
1478
  type: import_transactions3.ReceiptType.Revert,
1411
- id: hexOrZero(receipt.contract?.id),
1479
+ id: hexOrZero(receipt.id || receipt.contractId),
1412
1480
  val: (0, import_math4.bn)(receipt.ra),
1413
1481
  pc: (0, import_math4.bn)(receipt.pc),
1414
1482
  is: (0, import_math4.bn)(receipt.is)
@@ -1418,7 +1486,7 @@ function assembleReceiptByType(receipt) {
1418
1486
  case "LOG" /* Log */: {
1419
1487
  const logReceipt = {
1420
1488
  type: import_transactions3.ReceiptType.Log,
1421
- id: hexOrZero(receipt.contract?.id),
1489
+ id: hexOrZero(receipt.id || receipt.contractId),
1422
1490
  val0: (0, import_math4.bn)(receipt.ra),
1423
1491
  val1: (0, import_math4.bn)(receipt.rb),
1424
1492
  val2: (0, import_math4.bn)(receipt.rc),
@@ -1431,7 +1499,7 @@ function assembleReceiptByType(receipt) {
1431
1499
  case "LOG_DATA" /* LogData */: {
1432
1500
  const logDataReceipt = {
1433
1501
  type: import_transactions3.ReceiptType.LogData,
1434
- id: hexOrZero(receipt.contract?.id),
1502
+ id: hexOrZero(receipt.id || receipt.contractId),
1435
1503
  val0: (0, import_math4.bn)(receipt.ra),
1436
1504
  val1: (0, import_math4.bn)(receipt.rb),
1437
1505
  ptr: (0, import_math4.bn)(receipt.ptr),
@@ -1445,8 +1513,8 @@ function assembleReceiptByType(receipt) {
1445
1513
  case "TRANSFER" /* Transfer */: {
1446
1514
  const transferReceipt = {
1447
1515
  type: import_transactions3.ReceiptType.Transfer,
1448
- from: hexOrZero(receipt.contract?.id),
1449
- to: hexOrZero(receipt.toAddress || receipt?.to?.id),
1516
+ from: hexOrZero(receipt.id || receipt.contractId),
1517
+ to: hexOrZero(receipt.toAddress || receipt?.to),
1450
1518
  amount: (0, import_math4.bn)(receipt.amount),
1451
1519
  assetId: hexOrZero(receipt.assetId),
1452
1520
  pc: (0, import_math4.bn)(receipt.pc),
@@ -1457,8 +1525,8 @@ function assembleReceiptByType(receipt) {
1457
1525
  case "TRANSFER_OUT" /* TransferOut */: {
1458
1526
  const transferOutReceipt = {
1459
1527
  type: import_transactions3.ReceiptType.TransferOut,
1460
- from: hexOrZero(receipt.contract?.id),
1461
- to: hexOrZero(receipt.toAddress || receipt.to?.id),
1528
+ from: hexOrZero(receipt.id || receipt.contractId),
1529
+ to: hexOrZero(receipt.toAddress || receipt.to),
1462
1530
  amount: (0, import_math4.bn)(receipt.amount),
1463
1531
  assetId: hexOrZero(receipt.assetId),
1464
1532
  pc: (0, import_math4.bn)(receipt.pc),
@@ -1501,7 +1569,7 @@ function assembleReceiptByType(receipt) {
1501
1569
  return receiptMessageOut;
1502
1570
  }
1503
1571
  case "MINT" /* Mint */: {
1504
- const contractId = hexOrZero(receipt.contract?.id);
1572
+ const contractId = hexOrZero(receipt.id || receipt.contractId);
1505
1573
  const subId = hexOrZero(receipt.subId);
1506
1574
  const assetId = import_transactions3.ReceiptMintCoder.getAssetId(contractId, subId);
1507
1575
  const mintReceipt = {
@@ -1516,7 +1584,7 @@ function assembleReceiptByType(receipt) {
1516
1584
  return mintReceipt;
1517
1585
  }
1518
1586
  case "BURN" /* Burn */: {
1519
- const contractId = hexOrZero(receipt.contract?.id);
1587
+ const contractId = hexOrZero(receipt.id || receipt.contractId);
1520
1588
  const subId = hexOrZero(receipt.subId);
1521
1589
  const assetId = import_transactions3.ReceiptBurnCoder.getAssetId(contractId, subId);
1522
1590
  const burnReceipt = {
@@ -1601,7 +1669,6 @@ var buildBlockExplorerUrl = (options = {}) => {
1601
1669
  var import_math5 = require("@fuel-ts/math");
1602
1670
  var import_transactions4 = require("@fuel-ts/transactions");
1603
1671
  var import_utils6 = require("@fuel-ts/utils");
1604
- var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => (0, import_math5.bn)(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
1605
1672
  var getGasUsedFromReceipts = (receipts) => {
1606
1673
  const scriptResult = receipts.filter(
1607
1674
  (receipt) => receipt.type === import_transactions4.ReceiptType.ScriptResult
@@ -1622,18 +1689,28 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
1622
1689
  }
1623
1690
  function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
1624
1691
  const witnessCache = [];
1625
- const totalGas = inputs.reduce((total, input) => {
1692
+ const chargeableInputs = inputs.filter((input) => {
1693
+ const isCoinOrMessage = "owner" in input || "sender" in input;
1694
+ if (isCoinOrMessage) {
1695
+ if ("predicate" in input && input.predicate && input.predicate !== "0x") {
1696
+ return true;
1697
+ }
1698
+ if (!witnessCache.includes(input.witnessIndex)) {
1699
+ witnessCache.push(input.witnessIndex);
1700
+ return true;
1701
+ }
1702
+ }
1703
+ return false;
1704
+ });
1705
+ const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
1706
+ const totalGas = chargeableInputs.reduce((total, input) => {
1626
1707
  if ("predicate" in input && input.predicate && input.predicate !== "0x") {
1627
1708
  return total.add(
1628
- resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization).add(resolveGasDependentCosts((0, import_utils6.arrayify)(input.predicate).length, gasCosts.contractRoot)).add((0, import_math5.bn)(input.predicateGasUsed))
1709
+ vmInitializationCost.add(resolveGasDependentCosts((0, import_utils6.arrayify)(input.predicate).length, gasCosts.contractRoot)).add((0, import_math5.bn)(input.predicateGasUsed))
1629
1710
  );
1630
1711
  }
1631
- if ("witnessIndex" in input && !witnessCache.includes(input.witnessIndex)) {
1632
- witnessCache.push(input.witnessIndex);
1633
- return total.add(gasCosts.ecr1);
1634
- }
1635
- return total;
1636
- }, (0, import_math5.bn)());
1712
+ return total.add(gasCosts.ecr1);
1713
+ }, (0, import_math5.bn)(0));
1637
1714
  return totalGas;
1638
1715
  }
1639
1716
  function getMinGas(params) {
@@ -1645,12 +1722,20 @@ function getMinGas(params) {
1645
1722
  return minGas;
1646
1723
  }
1647
1724
  function getMaxGas(params) {
1648
- const { gasPerByte, witnessesLength, witnessLimit, minGas, gasLimit = (0, import_math5.bn)(0) } = params;
1725
+ const {
1726
+ gasPerByte,
1727
+ witnessesLength,
1728
+ witnessLimit,
1729
+ minGas,
1730
+ gasLimit = (0, import_math5.bn)(0),
1731
+ maxGasPerTx
1732
+ } = params;
1649
1733
  let remainingAllowedWitnessGas = (0, import_math5.bn)(0);
1650
1734
  if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
1651
1735
  remainingAllowedWitnessGas = (0, import_math5.bn)(witnessLimit).sub(witnessesLength).mul(gasPerByte);
1652
1736
  }
1653
- return remainingAllowedWitnessGas.add(minGas).add(gasLimit);
1737
+ const maxGas = remainingAllowedWitnessGas.add(minGas).add(gasLimit);
1738
+ return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
1654
1739
  }
1655
1740
  function calculateMetadataGasForTxCreate({
1656
1741
  gasCosts,
@@ -1672,6 +1757,10 @@ function calculateMetadataGasForTxScript({
1672
1757
  }) {
1673
1758
  return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
1674
1759
  }
1760
+ var calculateGasFee = (params) => {
1761
+ const { gas, gasPrice, priceFactor, tip } = params;
1762
+ return gas.mul(gasPrice).div(priceFactor).add(tip);
1763
+ };
1675
1764
 
1676
1765
  // src/providers/utils/json.ts
1677
1766
  var import_utils7 = require("@fuel-ts/utils");
@@ -1717,16 +1806,16 @@ function sleep(time) {
1717
1806
  var import_errors7 = require("@fuel-ts/errors");
1718
1807
  var import_math6 = require("@fuel-ts/math");
1719
1808
  var import_transactions5 = require("@fuel-ts/transactions");
1720
- var import_configs6 = require("@fuel-ts/transactions/configs");
1809
+ var import_configs5 = require("@fuel-ts/transactions/configs");
1721
1810
  var assemblePanicError = (status) => {
1722
1811
  let errorMessage = `The transaction reverted with reason: "${status.reason}".`;
1723
1812
  const reason = status.reason;
1724
- if (import_configs6.PANIC_REASONS.includes(status.reason)) {
1813
+ if (import_configs5.PANIC_REASONS.includes(status.reason)) {
1725
1814
  errorMessage = `${errorMessage}
1726
1815
 
1727
1816
  You can read more about this error at:
1728
1817
 
1729
- ${import_configs6.PANIC_DOC_URL}#variant.${status.reason}`;
1818
+ ${import_configs5.PANIC_DOC_URL}#variant.${status.reason}`;
1730
1819
  }
1731
1820
  return { errorMessage, reason };
1732
1821
  };
@@ -1738,28 +1827,28 @@ var assembleRevertError = (receipts, logs) => {
1738
1827
  if (revertReceipt) {
1739
1828
  const reasonHex = (0, import_math6.bn)(revertReceipt.val).toHex();
1740
1829
  switch (reasonHex) {
1741
- case import_configs6.FAILED_REQUIRE_SIGNAL: {
1830
+ case import_configs5.FAILED_REQUIRE_SIGNAL: {
1742
1831
  reason = "require";
1743
1832
  errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(logs[0]) : "an error."}.`;
1744
1833
  break;
1745
1834
  }
1746
- case import_configs6.FAILED_ASSERT_EQ_SIGNAL: {
1835
+ case import_configs5.FAILED_ASSERT_EQ_SIGNAL: {
1747
1836
  const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
1748
1837
  reason = "assert_eq";
1749
1838
  errorMessage = `The transaction reverted because of an "assert_eq" statement${sufix}`;
1750
1839
  break;
1751
1840
  }
1752
- case import_configs6.FAILED_ASSERT_NE_SIGNAL: {
1841
+ case import_configs5.FAILED_ASSERT_NE_SIGNAL: {
1753
1842
  const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
1754
1843
  reason = "assert_ne";
1755
1844
  errorMessage = `The transaction reverted because of an "assert_ne" statement${sufix}`;
1756
1845
  break;
1757
1846
  }
1758
- case import_configs6.FAILED_ASSERT_SIGNAL:
1847
+ case import_configs5.FAILED_ASSERT_SIGNAL:
1759
1848
  reason = "assert";
1760
1849
  errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
1761
1850
  break;
1762
- case import_configs6.FAILED_TRANSFER_TO_ADDRESS_SIGNAL:
1851
+ case import_configs5.FAILED_TRANSFER_TO_ADDRESS_SIGNAL:
1763
1852
  reason = "MissingOutputChange";
1764
1853
  errorMessage = `The transaction reverted because it's missing an "OutputChange".`;
1765
1854
  break;
@@ -1820,7 +1909,7 @@ var witnessify = (value) => {
1820
1909
  // src/providers/transaction-request/transaction-request.ts
1821
1910
  var BaseTransactionRequest = class {
1822
1911
  /** Gas price for transaction */
1823
- gasPrice;
1912
+ tip;
1824
1913
  /** Block until which tx cannot be included */
1825
1914
  maturity;
1826
1915
  /** The maximum fee payable by this transaction using BASE_ASSET. */
@@ -1839,7 +1928,7 @@ var BaseTransactionRequest = class {
1839
1928
  * @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
1840
1929
  */
1841
1930
  constructor({
1842
- gasPrice,
1931
+ tip,
1843
1932
  maturity,
1844
1933
  maxFee,
1845
1934
  witnessLimit,
@@ -1847,7 +1936,7 @@ var BaseTransactionRequest = class {
1847
1936
  outputs,
1848
1937
  witnesses
1849
1938
  } = {}) {
1850
- this.gasPrice = (0, import_math7.bn)(gasPrice);
1939
+ this.tip = (0, import_math7.bn)(tip);
1851
1940
  this.maturity = maturity ?? 0;
1852
1941
  this.witnessLimit = witnessLimit ? (0, import_math7.bn)(witnessLimit) : void 0;
1853
1942
  this.maxFee = maxFee ? (0, import_math7.bn)(maxFee) : void 0;
@@ -1858,9 +1947,9 @@ var BaseTransactionRequest = class {
1858
1947
  static getPolicyMeta(req) {
1859
1948
  let policyTypes = 0;
1860
1949
  const policies = [];
1861
- if (req.gasPrice) {
1862
- policyTypes += import_transactions6.PolicyType.GasPrice;
1863
- policies.push({ data: req.gasPrice, type: import_transactions6.PolicyType.GasPrice });
1950
+ if (req.tip) {
1951
+ policyTypes += import_transactions6.PolicyType.Tip;
1952
+ policies.push({ data: req.tip, type: import_transactions6.PolicyType.Tip });
1864
1953
  }
1865
1954
  if (req.witnessLimit) {
1866
1955
  policyTypes += import_transactions6.PolicyType.WitnessLimit;
@@ -1946,7 +2035,7 @@ var BaseTransactionRequest = class {
1946
2035
  * @returns The index of the created witness.
1947
2036
  */
1948
2037
  addEmptyWitness() {
1949
- this.addWitness((0, import_utils9.concat)([import_configs7.ZeroBytes32, import_configs7.ZeroBytes32]));
2038
+ this.addWitness((0, import_utils9.concat)([import_configs6.ZeroBytes32, import_configs6.ZeroBytes32]));
1950
2039
  return this.witnesses.length - 1;
1951
2040
  }
1952
2041
  /**
@@ -2044,13 +2133,11 @@ var BaseTransactionRequest = class {
2044
2133
  * assetId, if one it was not added yet.
2045
2134
  *
2046
2135
  * @param coin - Coin resource.
2047
- * @param predicate - Predicate bytes.
2048
- * @param predicateData - Predicate data bytes.
2049
2136
  */
2050
- addCoinInput(coin, predicate) {
2137
+ addCoinInput(coin) {
2051
2138
  const { assetId, owner, amount } = coin;
2052
2139
  let witnessIndex;
2053
- if (predicate) {
2140
+ if (coin.predicate) {
2054
2141
  witnessIndex = 0;
2055
2142
  } else {
2056
2143
  witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
@@ -2065,25 +2152,21 @@ var BaseTransactionRequest = class {
2065
2152
  amount,
2066
2153
  assetId,
2067
2154
  txPointer: "0x00000000000000000000000000000000",
2068
- witnessIndex,
2069
- predicate: predicate?.bytes
2155
+ witnessIndex
2070
2156
  };
2071
2157
  this.pushInput(input);
2072
2158
  this.addChangeOutput(owner, assetId);
2073
2159
  }
2074
2160
  /**
2075
2161
  * Adds a single message input to the transaction and a change output for the
2076
- * baseAssetId, if one it was not added yet.
2162
+ * asset against the message
2077
2163
  *
2078
2164
  * @param message - Message resource.
2079
- * @param predicate - Predicate bytes.
2080
- * @param predicateData - Predicate data bytes.
2081
2165
  */
2082
- addMessageInput(message, predicate) {
2083
- const { recipient, sender, amount } = message;
2084
- const assetId = import_configs7.BaseAssetId;
2166
+ addMessageInput(message) {
2167
+ const { recipient, sender, amount, assetId } = message;
2085
2168
  let witnessIndex;
2086
- if (predicate) {
2169
+ if (message.predicate) {
2087
2170
  witnessIndex = 0;
2088
2171
  } else {
2089
2172
  witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
@@ -2097,8 +2180,7 @@ var BaseTransactionRequest = class {
2097
2180
  sender: sender.toB256(),
2098
2181
  recipient: recipient.toB256(),
2099
2182
  amount,
2100
- witnessIndex,
2101
- predicate: predicate?.bytes
2183
+ witnessIndex
2102
2184
  };
2103
2185
  this.pushInput(input);
2104
2186
  this.addChangeOutput(recipient, assetId);
@@ -2129,32 +2211,6 @@ var BaseTransactionRequest = class {
2129
2211
  resources.forEach((resource) => this.addResource(resource));
2130
2212
  return this;
2131
2213
  }
2132
- /**
2133
- * Adds multiple resources to the transaction by adding coin/message inputs and change
2134
- * outputs from the related assetIds.
2135
- *
2136
- * @param resources - The resources to add.
2137
- * @returns This transaction.
2138
- */
2139
- addPredicateResource(resource, predicate) {
2140
- if (isCoin(resource)) {
2141
- this.addCoinInput(resource, predicate);
2142
- } else {
2143
- this.addMessageInput(resource, predicate);
2144
- }
2145
- return this;
2146
- }
2147
- /**
2148
- * Adds multiple predicate coin/message inputs to the transaction and change outputs
2149
- * from the related assetIds.
2150
- *
2151
- * @param resources - The resources to add.
2152
- * @returns This transaction.
2153
- */
2154
- addPredicateResources(resources, predicate) {
2155
- resources.forEach((resource) => this.addPredicateResource(resource, predicate));
2156
- return this;
2157
- }
2158
2214
  /**
2159
2215
  * Adds a coin output to the transaction.
2160
2216
  *
@@ -2162,7 +2218,7 @@ var BaseTransactionRequest = class {
2162
2218
  * @param amount - Amount of coin.
2163
2219
  * @param assetId - Asset ID of coin.
2164
2220
  */
2165
- addCoinOutput(to, amount, assetId = import_configs7.BaseAssetId) {
2221
+ addCoinOutput(to, amount, assetId) {
2166
2222
  this.pushOutput({
2167
2223
  type: import_transactions6.OutputType.Coin,
2168
2224
  to: (0, import_address.addressify)(to).toB256(),
@@ -2194,7 +2250,7 @@ var BaseTransactionRequest = class {
2194
2250
  * @param to - Address of the owner.
2195
2251
  * @param assetId - Asset ID of coin.
2196
2252
  */
2197
- addChangeOutput(to, assetId = import_configs7.BaseAssetId) {
2253
+ addChangeOutput(to, assetId) {
2198
2254
  const changeOutput = this.getChangeOutputs().find(
2199
2255
  (output) => (0, import_utils9.hexlify)(output.assetId) === assetId
2200
2256
  );
@@ -2234,7 +2290,7 @@ var BaseTransactionRequest = class {
2234
2290
  }
2235
2291
  calculateMaxGas(chainInfo, minGas) {
2236
2292
  const { consensusParameters } = chainInfo;
2237
- const { gasPerByte } = consensusParameters;
2293
+ const { gasPerByte, maxGasPerTx } = consensusParameters;
2238
2294
  const witnessesLength = this.toTransaction().witnesses.reduce(
2239
2295
  (acc, wit) => acc + wit.dataLength,
2240
2296
  0
@@ -2243,7 +2299,8 @@ var BaseTransactionRequest = class {
2243
2299
  gasPerByte,
2244
2300
  minGas,
2245
2301
  witnessesLength,
2246
- witnessLimit: this.witnessLimit
2302
+ witnessLimit: this.witnessLimit,
2303
+ maxGasPerTx
2247
2304
  });
2248
2305
  }
2249
2306
  /**
@@ -2251,8 +2308,9 @@ var BaseTransactionRequest = class {
2251
2308
  * quantities array.
2252
2309
  *
2253
2310
  * @param quantities - CoinQuantity Array.
2311
+ * @param baseAssetId - The base asset to fund the transaction.
2254
2312
  */
2255
- fundWithFakeUtxos(quantities, resourcesOwner) {
2313
+ fundWithFakeUtxos(quantities, baseAssetId, resourcesOwner) {
2256
2314
  const findAssetInput = (assetId) => this.inputs.find((input) => {
2257
2315
  if ("assetId" in input) {
2258
2316
  return input.assetId === assetId;
@@ -2261,24 +2319,27 @@ var BaseTransactionRequest = class {
2261
2319
  });
2262
2320
  const updateAssetInput = (assetId, quantity) => {
2263
2321
  const assetInput = findAssetInput(assetId);
2322
+ let usedQuantity = quantity;
2323
+ if (assetId === baseAssetId) {
2324
+ usedQuantity = (0, import_math7.bn)("1000000000000000000");
2325
+ }
2264
2326
  if (assetInput && "assetId" in assetInput) {
2265
2327
  assetInput.id = (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN));
2266
- assetInput.amount = quantity;
2328
+ assetInput.amount = usedQuantity;
2267
2329
  } else {
2268
2330
  this.addResources([
2269
2331
  {
2270
2332
  id: (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN)),
2271
- amount: quantity,
2333
+ amount: usedQuantity,
2272
2334
  assetId,
2273
2335
  owner: resourcesOwner || import_address.Address.fromRandom(),
2274
- maturity: 0,
2275
2336
  blockCreated: (0, import_math7.bn)(1),
2276
2337
  txCreatedIdx: (0, import_math7.bn)(1)
2277
2338
  }
2278
2339
  ]);
2279
2340
  }
2280
2341
  };
2281
- updateAssetInput(import_configs7.BaseAssetId, (0, import_math7.bn)(1e11));
2342
+ updateAssetInput(baseAssetId, (0, import_math7.bn)(1e11));
2282
2343
  quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
2283
2344
  }
2284
2345
  /**
@@ -2303,7 +2364,7 @@ var BaseTransactionRequest = class {
2303
2364
  toJSON() {
2304
2365
  return normalizeJSON(this);
2305
2366
  }
2306
- updatePredicateInputs(inputs) {
2367
+ updatePredicateGasUsed(inputs) {
2307
2368
  this.inputs.forEach((i) => {
2308
2369
  let correspondingInput;
2309
2370
  switch (i.type) {
@@ -2325,16 +2386,25 @@ var BaseTransactionRequest = class {
2325
2386
  }
2326
2387
  });
2327
2388
  }
2389
+ shiftPredicateData() {
2390
+ this.inputs.forEach((input) => {
2391
+ if ("predicateData" in input && "padPredicateData" in input && typeof input.padPredicateData === "function") {
2392
+ input.predicateData = input.padPredicateData(
2393
+ BaseTransactionRequest.getPolicyMeta(this).policies.length
2394
+ );
2395
+ }
2396
+ });
2397
+ }
2328
2398
  };
2329
2399
 
2330
2400
  // src/providers/transaction-request/create-transaction-request.ts
2331
- var import_configs9 = require("@fuel-ts/address/configs");
2401
+ var import_configs8 = require("@fuel-ts/address/configs");
2332
2402
  var import_math9 = require("@fuel-ts/math");
2333
2403
  var import_transactions8 = require("@fuel-ts/transactions");
2334
2404
  var import_utils13 = require("@fuel-ts/utils");
2335
2405
 
2336
2406
  // src/providers/transaction-request/hash-transaction.ts
2337
- var import_configs8 = require("@fuel-ts/address/configs");
2407
+ var import_configs7 = require("@fuel-ts/address/configs");
2338
2408
  var import_hasher = require("@fuel-ts/hasher");
2339
2409
  var import_math8 = require("@fuel-ts/math");
2340
2410
  var import_transactions7 = require("@fuel-ts/transactions");
@@ -2343,7 +2413,7 @@ var import_ramda2 = require("ramda");
2343
2413
  function hashTransaction(transactionRequest, chainId) {
2344
2414
  const transaction = transactionRequest.toTransaction();
2345
2415
  if (transaction.type === import_transactions7.TransactionType.Script) {
2346
- transaction.receiptsRoot = import_configs8.ZeroBytes32;
2416
+ transaction.receiptsRoot = import_configs7.ZeroBytes32;
2347
2417
  }
2348
2418
  transaction.inputs = transaction.inputs.map((input) => {
2349
2419
  const inputClone = (0, import_ramda2.clone)(input);
@@ -2365,10 +2435,10 @@ function hashTransaction(transactionRequest, chainId) {
2365
2435
  blockHeight: 0,
2366
2436
  txIndex: 0
2367
2437
  };
2368
- inputClone.txID = import_configs8.ZeroBytes32;
2438
+ inputClone.txID = import_configs7.ZeroBytes32;
2369
2439
  inputClone.outputIndex = 0;
2370
- inputClone.balanceRoot = import_configs8.ZeroBytes32;
2371
- inputClone.stateRoot = import_configs8.ZeroBytes32;
2440
+ inputClone.balanceRoot = import_configs7.ZeroBytes32;
2441
+ inputClone.stateRoot = import_configs7.ZeroBytes32;
2372
2442
  return inputClone;
2373
2443
  }
2374
2444
  default:
@@ -2379,8 +2449,8 @@ function hashTransaction(transactionRequest, chainId) {
2379
2449
  const outputClone = (0, import_ramda2.clone)(output);
2380
2450
  switch (outputClone.type) {
2381
2451
  case import_transactions7.OutputType.Contract: {
2382
- outputClone.balanceRoot = import_configs8.ZeroBytes32;
2383
- outputClone.stateRoot = import_configs8.ZeroBytes32;
2452
+ outputClone.balanceRoot = import_configs7.ZeroBytes32;
2453
+ outputClone.stateRoot = import_configs7.ZeroBytes32;
2384
2454
  return outputClone;
2385
2455
  }
2386
2456
  case import_transactions7.OutputType.Change: {
@@ -2388,9 +2458,9 @@ function hashTransaction(transactionRequest, chainId) {
2388
2458
  return outputClone;
2389
2459
  }
2390
2460
  case import_transactions7.OutputType.Variable: {
2391
- outputClone.to = import_configs8.ZeroBytes32;
2461
+ outputClone.to = import_configs7.ZeroBytes32;
2392
2462
  outputClone.amount = (0, import_math8.bn)(0);
2393
- outputClone.assetId = import_configs8.ZeroBytes32;
2463
+ outputClone.assetId = import_configs7.ZeroBytes32;
2394
2464
  return outputClone;
2395
2465
  }
2396
2466
  default:
@@ -2448,15 +2518,10 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2448
2518
  *
2449
2519
  * @param createTransactionRequestLike - The initial values for the instance
2450
2520
  */
2451
- constructor({
2452
- bytecodeWitnessIndex,
2453
- salt,
2454
- storageSlots,
2455
- ...rest
2456
- } = {}) {
2521
+ constructor({ bytecodeWitnessIndex, salt, storageSlots, ...rest }) {
2457
2522
  super(rest);
2458
2523
  this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
2459
- this.salt = (0, import_utils13.hexlify)(salt ?? import_configs9.ZeroBytes32);
2524
+ this.salt = (0, import_utils13.hexlify)(salt ?? import_configs8.ZeroBytes32);
2460
2525
  this.storageSlots = [...storageSlots ?? []];
2461
2526
  }
2462
2527
  /**
@@ -2471,10 +2536,9 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2471
2536
  return {
2472
2537
  type: import_transactions8.TransactionType.Create,
2473
2538
  ...baseTransaction,
2474
- bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
2475
2539
  bytecodeWitnessIndex,
2476
- storageSlotsCount: storageSlots.length,
2477
- salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs9.ZeroBytes32,
2540
+ storageSlotsCount: (0, import_math9.bn)(storageSlots.length),
2541
+ salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs8.ZeroBytes32,
2478
2542
  storageSlots
2479
2543
  };
2480
2544
  }
@@ -2524,7 +2588,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2524
2588
  // src/providers/transaction-request/script-transaction-request.ts
2525
2589
  var import_abi_coder3 = require("@fuel-ts/abi-coder");
2526
2590
  var import_address2 = require("@fuel-ts/address");
2527
- var import_configs10 = require("@fuel-ts/address/configs");
2591
+ var import_configs9 = require("@fuel-ts/address/configs");
2528
2592
  var import_math10 = require("@fuel-ts/math");
2529
2593
  var import_transactions9 = require("@fuel-ts/transactions");
2530
2594
  var import_utils15 = require("@fuel-ts/utils");
@@ -2596,9 +2660,9 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2596
2660
  type: import_transactions9.TransactionType.Script,
2597
2661
  scriptGasLimit: this.gasLimit,
2598
2662
  ...super.getBaseTransaction(),
2599
- scriptLength: script.length,
2600
- scriptDataLength: scriptData.length,
2601
- receiptsRoot: import_configs10.ZeroBytes32,
2663
+ scriptLength: (0, import_math10.bn)(script.length),
2664
+ scriptDataLength: (0, import_math10.bn)(scriptData.length),
2665
+ receiptsRoot: import_configs9.ZeroBytes32,
2602
2666
  script: (0, import_utils15.hexlify)(script),
2603
2667
  scriptData: (0, import_utils15.hexlify)(scriptData)
2604
2668
  };
@@ -2661,7 +2725,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2661
2725
  }
2662
2726
  calculateMaxGas(chainInfo, minGas) {
2663
2727
  const { consensusParameters } = chainInfo;
2664
- const { gasPerByte } = consensusParameters;
2728
+ const { gasPerByte, maxGasPerTx } = consensusParameters;
2665
2729
  const witnessesLength = this.toTransaction().witnesses.reduce(
2666
2730
  (acc, wit) => acc + wit.dataLength,
2667
2731
  0
@@ -2671,7 +2735,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2671
2735
  minGas,
2672
2736
  witnessesLength,
2673
2737
  witnessLimit: this.witnessLimit,
2674
- gasLimit: this.gasLimit
2738
+ gasLimit: this.gasLimit,
2739
+ maxGasPerTx
2675
2740
  });
2676
2741
  }
2677
2742
  /**
@@ -2746,15 +2811,32 @@ var transactionRequestify = (obj) => {
2746
2811
  }
2747
2812
  }
2748
2813
  };
2814
+ var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
2815
+ (acc, input) => {
2816
+ if (input.type === import_transactions10.InputType.Coin && input.owner === owner) {
2817
+ acc.utxos.push(input.id);
2818
+ }
2819
+ if (input.type === import_transactions10.InputType.Message && input.recipient === owner) {
2820
+ acc.messages.push(input.nonce);
2821
+ }
2822
+ return acc;
2823
+ },
2824
+ {
2825
+ utxos: [],
2826
+ messages: []
2827
+ }
2828
+ );
2749
2829
 
2750
2830
  // src/providers/transaction-response/transaction-response.ts
2751
2831
  var import_errors13 = require("@fuel-ts/errors");
2752
- var import_math14 = require("@fuel-ts/math");
2753
- var import_transactions17 = require("@fuel-ts/transactions");
2754
- var import_utils21 = require("@fuel-ts/utils");
2832
+ var import_math15 = require("@fuel-ts/math");
2833
+ var import_transactions18 = require("@fuel-ts/transactions");
2834
+ var import_utils20 = require("@fuel-ts/utils");
2755
2835
 
2756
2836
  // src/providers/transaction-summary/assemble-transaction-summary.ts
2757
- var import_utils19 = require("@fuel-ts/utils");
2837
+ var import_math14 = require("@fuel-ts/math");
2838
+ var import_transactions16 = require("@fuel-ts/transactions");
2839
+ var import_utils18 = require("@fuel-ts/utils");
2758
2840
 
2759
2841
  // src/providers/transaction-summary/calculate-transaction-fee.ts
2760
2842
  var import_math11 = require("@fuel-ts/math");
@@ -2762,9 +2844,10 @@ var import_transactions11 = require("@fuel-ts/transactions");
2762
2844
  var import_utils16 = require("@fuel-ts/utils");
2763
2845
  var calculateTransactionFee = (params) => {
2764
2846
  const {
2765
- gasUsed,
2847
+ gasPrice,
2766
2848
  rawPayload,
2767
- consensusParameters: { gasCosts, feeParams }
2849
+ tip,
2850
+ consensusParameters: { gasCosts, feeParams, maxGasPerTx }
2768
2851
  } = params;
2769
2852
  const gasPerByte = (0, import_math11.bn)(feeParams.gasPerByte);
2770
2853
  const gasPriceFactor = (0, import_math11.bn)(feeParams.gasPriceFactor);
@@ -2774,8 +2857,7 @@ var calculateTransactionFee = (params) => {
2774
2857
  return {
2775
2858
  fee: (0, import_math11.bn)(0),
2776
2859
  minFee: (0, import_math11.bn)(0),
2777
- maxFee: (0, import_math11.bn)(0),
2778
- feeFromGasUsed: (0, import_math11.bn)(0)
2860
+ maxFee: (0, import_math11.bn)(0)
2779
2861
  };
2780
2862
  }
2781
2863
  const { type, witnesses, inputs, policies } = transaction;
@@ -2807,7 +2889,6 @@ var calculateTransactionFee = (params) => {
2807
2889
  metadataGas,
2808
2890
  txBytesSize: transactionBytes.length
2809
2891
  });
2810
- const gasPrice = (0, import_math11.bn)(policies.find((policy) => policy.type === import_transactions11.PolicyType.GasPrice)?.data);
2811
2892
  const witnessLimit = policies.find((policy) => policy.type === import_transactions11.PolicyType.WitnessLimit)?.data;
2812
2893
  const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
2813
2894
  const maxGas = getMaxGas({
@@ -2815,22 +2896,30 @@ var calculateTransactionFee = (params) => {
2815
2896
  minGas,
2816
2897
  witnessesLength,
2817
2898
  gasLimit,
2818
- witnessLimit
2899
+ witnessLimit,
2900
+ maxGasPerTx
2901
+ });
2902
+ const minFee = calculateGasFee({
2903
+ gasPrice,
2904
+ gas: minGas,
2905
+ priceFactor: gasPriceFactor,
2906
+ tip
2907
+ });
2908
+ const maxFee = calculateGasFee({
2909
+ gasPrice,
2910
+ gas: maxGas,
2911
+ priceFactor: gasPriceFactor,
2912
+ tip
2819
2913
  });
2820
- const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
2821
- const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
2822
- const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
2823
- const fee = minFee.add(feeFromGasUsed);
2824
2914
  return {
2825
- fee,
2826
2915
  minFee,
2827
2916
  maxFee,
2828
- feeFromGasUsed
2917
+ fee: maxFee
2829
2918
  };
2830
2919
  };
2831
2920
 
2832
2921
  // src/providers/transaction-summary/operations.ts
2833
- var import_configs11 = require("@fuel-ts/address/configs");
2922
+ var import_configs10 = require("@fuel-ts/address/configs");
2834
2923
  var import_errors11 = require("@fuel-ts/errors");
2835
2924
  var import_math13 = require("@fuel-ts/math");
2836
2925
  var import_transactions14 = require("@fuel-ts/transactions");
@@ -3175,7 +3264,7 @@ function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutp
3175
3264
  const { to: toAddress, assetId, amount } = receipt;
3176
3265
  let { from: fromAddress } = receipt;
3177
3266
  const toType = contractInputs.some((input) => input.contractID === toAddress) ? 0 /* contract */ : 1 /* account */;
3178
- if (import_configs11.ZeroBytes32 === fromAddress) {
3267
+ if (import_configs10.ZeroBytes32 === fromAddress) {
3179
3268
  const change = changeOutputs.find((output) => output.assetId === assetId);
3180
3269
  fromAddress = change?.to || fromAddress;
3181
3270
  }
@@ -3439,10 +3528,12 @@ function assembleTransactionSummary(params) {
3439
3528
  gqlTransactionStatus,
3440
3529
  abiMap = {},
3441
3530
  maxInputs,
3442
- gasCosts
3531
+ gasCosts,
3532
+ maxGasPerTx,
3533
+ gasPrice
3443
3534
  } = params;
3444
3535
  const gasUsed = getGasUsedFromReceipts(receipts);
3445
- const rawPayload = (0, import_utils19.hexlify)(transactionBytes);
3536
+ const rawPayload = (0, import_utils18.hexlify)(transactionBytes);
3446
3537
  const operations = getOperations({
3447
3538
  transactionType: transaction.type,
3448
3539
  inputs: transaction.inputs || [],
@@ -3453,11 +3544,14 @@ function assembleTransactionSummary(params) {
3453
3544
  maxInputs
3454
3545
  });
3455
3546
  const typeName = getTransactionTypeName(transaction.type);
3547
+ const tip = (0, import_math14.bn)(transaction.policies?.find((policy) => policy.type === import_transactions16.PolicyType.Tip)?.data);
3456
3548
  const { fee } = calculateTransactionFee({
3457
- gasUsed,
3549
+ gasPrice,
3458
3550
  rawPayload,
3551
+ tip,
3459
3552
  consensusParameters: {
3460
3553
  gasCosts,
3554
+ maxGasPerTx,
3461
3555
  feeParams: {
3462
3556
  gasPerByte,
3463
3557
  gasPriceFactor
@@ -3469,7 +3563,7 @@ function assembleTransactionSummary(params) {
3469
3563
  const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
3470
3564
  let date;
3471
3565
  if (time) {
3472
- date = import_utils19.DateTime.fromTai64(time);
3566
+ date = import_utils18.DateTime.fromTai64(time);
3473
3567
  }
3474
3568
  const transactionSummary = {
3475
3569
  id,
@@ -3497,12 +3591,12 @@ function assembleTransactionSummary(params) {
3497
3591
 
3498
3592
  // src/providers/transaction-response/getDecodedLogs.ts
3499
3593
  var import_abi_coder5 = require("@fuel-ts/abi-coder");
3500
- var import_transactions16 = require("@fuel-ts/transactions");
3594
+ var import_transactions17 = require("@fuel-ts/transactions");
3501
3595
  function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
3502
3596
  return receipts.reduce((logs, receipt) => {
3503
- if (receipt.type === import_transactions16.ReceiptType.LogData || receipt.type === import_transactions16.ReceiptType.Log) {
3597
+ if (receipt.type === import_transactions17.ReceiptType.LogData || receipt.type === import_transactions17.ReceiptType.Log) {
3504
3598
  const interfaceToUse = new import_abi_coder5.Interface(externalAbis[receipt.id] || mainAbi);
3505
- const data = receipt.type === import_transactions16.ReceiptType.Log ? new import_abi_coder5.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
3599
+ const data = receipt.type === import_transactions17.ReceiptType.Log ? new import_abi_coder5.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
3506
3600
  const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
3507
3601
  logs.push(decodedLog);
3508
3602
  }
@@ -3517,7 +3611,7 @@ var TransactionResponse = class {
3517
3611
  /** Current provider */
3518
3612
  provider;
3519
3613
  /** Gas used on the transaction */
3520
- gasUsed = (0, import_math14.bn)(0);
3614
+ gasUsed = (0, import_math15.bn)(0);
3521
3615
  /** The graphql Transaction with receipts object. */
3522
3616
  gqlTransaction;
3523
3617
  abis;
@@ -3575,8 +3669,8 @@ var TransactionResponse = class {
3575
3669
  * @returns The decoded transaction.
3576
3670
  */
3577
3671
  decodeTransaction(transactionWithReceipts) {
3578
- return new import_transactions17.TransactionCoder().decode(
3579
- (0, import_utils21.arrayify)(transactionWithReceipts.rawPayload),
3672
+ return new import_transactions18.TransactionCoder().decode(
3673
+ (0, import_utils20.arrayify)(transactionWithReceipts.rawPayload),
3580
3674
  0
3581
3675
  )?.[0];
3582
3676
  }
@@ -3595,20 +3689,27 @@ var TransactionResponse = class {
3595
3689
  const decodedTransaction = this.decodeTransaction(
3596
3690
  transaction
3597
3691
  );
3598
- const receipts = transaction.receipts?.map(processGqlReceipt) || [];
3599
- const { gasPerByte, gasPriceFactor, gasCosts } = this.provider.getGasConfig();
3692
+ let txReceipts = [];
3693
+ if (transaction?.status && "receipts" in transaction.status) {
3694
+ txReceipts = transaction.status.receipts;
3695
+ }
3696
+ const receipts = txReceipts.map(processGqlReceipt) || [];
3697
+ const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
3698
+ const gasPrice = await this.provider.getLatestGasPrice();
3600
3699
  const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
3601
3700
  const transactionSummary = assembleTransactionSummary({
3602
3701
  id: this.id,
3603
3702
  receipts,
3604
3703
  transaction: decodedTransaction,
3605
- transactionBytes: (0, import_utils21.arrayify)(transaction.rawPayload),
3704
+ transactionBytes: (0, import_utils20.arrayify)(transaction.rawPayload),
3606
3705
  gqlTransactionStatus: transaction.status,
3607
3706
  gasPerByte,
3608
3707
  gasPriceFactor,
3609
3708
  abiMap: contractsAbiMap,
3610
3709
  maxInputs,
3611
- gasCosts
3710
+ gasCosts,
3711
+ maxGasPerTx,
3712
+ gasPrice
3612
3713
  });
3613
3714
  return transactionSummary;
3614
3715
  }
@@ -3714,7 +3815,7 @@ function autoRetryFetch(fetchFn, options, retryAttemptNum = 0) {
3714
3815
  }
3715
3816
 
3716
3817
  // src/providers/utils/merge-quantities.ts
3717
- var mergeQuantities = (arr1, arr2) => {
3818
+ var mergeQuantities = (...coinQuantities) => {
3718
3819
  const resultMap = {};
3719
3820
  function addToMap({ amount, assetId }) {
3720
3821
  if (resultMap[assetId]) {
@@ -3723,8 +3824,7 @@ var mergeQuantities = (arr1, arr2) => {
3723
3824
  resultMap[assetId] = amount;
3724
3825
  }
3725
3826
  }
3726
- arr1.forEach(addToMap);
3727
- arr2.forEach(addToMap);
3827
+ coinQuantities.forEach((arr) => arr.forEach(addToMap));
3728
3828
  return Object.entries(resultMap).map(([assetId, amount]) => ({ assetId, amount }));
3729
3829
  };
3730
3830
 
@@ -3735,29 +3835,30 @@ var processGqlChain = (chain) => {
3735
3835
  const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
3736
3836
  return {
3737
3837
  name,
3738
- baseChainHeight: (0, import_math15.bn)(daHeight),
3838
+ baseChainHeight: (0, import_math16.bn)(daHeight),
3739
3839
  consensusParameters: {
3740
- contractMaxSize: (0, import_math15.bn)(contractParams.contractMaxSize),
3741
- maxInputs: (0, import_math15.bn)(txParams.maxInputs),
3742
- maxOutputs: (0, import_math15.bn)(txParams.maxOutputs),
3743
- maxWitnesses: (0, import_math15.bn)(txParams.maxWitnesses),
3744
- maxGasPerTx: (0, import_math15.bn)(txParams.maxGasPerTx),
3745
- maxScriptLength: (0, import_math15.bn)(scriptParams.maxScriptLength),
3746
- maxScriptDataLength: (0, import_math15.bn)(scriptParams.maxScriptDataLength),
3747
- maxStorageSlots: (0, import_math15.bn)(contractParams.maxStorageSlots),
3748
- maxPredicateLength: (0, import_math15.bn)(predicateParams.maxPredicateLength),
3749
- maxPredicateDataLength: (0, import_math15.bn)(predicateParams.maxPredicateDataLength),
3750
- maxGasPerPredicate: (0, import_math15.bn)(predicateParams.maxGasPerPredicate),
3751
- gasPriceFactor: (0, import_math15.bn)(feeParams.gasPriceFactor),
3752
- gasPerByte: (0, import_math15.bn)(feeParams.gasPerByte),
3753
- maxMessageDataLength: (0, import_math15.bn)(predicateParams.maxMessageDataLength),
3754
- chainId: (0, import_math15.bn)(consensusParameters.chainId),
3840
+ contractMaxSize: (0, import_math16.bn)(contractParams.contractMaxSize),
3841
+ maxInputs: (0, import_math16.bn)(txParams.maxInputs),
3842
+ maxOutputs: (0, import_math16.bn)(txParams.maxOutputs),
3843
+ maxWitnesses: (0, import_math16.bn)(txParams.maxWitnesses),
3844
+ maxGasPerTx: (0, import_math16.bn)(txParams.maxGasPerTx),
3845
+ maxScriptLength: (0, import_math16.bn)(scriptParams.maxScriptLength),
3846
+ maxScriptDataLength: (0, import_math16.bn)(scriptParams.maxScriptDataLength),
3847
+ maxStorageSlots: (0, import_math16.bn)(contractParams.maxStorageSlots),
3848
+ maxPredicateLength: (0, import_math16.bn)(predicateParams.maxPredicateLength),
3849
+ maxPredicateDataLength: (0, import_math16.bn)(predicateParams.maxPredicateDataLength),
3850
+ maxGasPerPredicate: (0, import_math16.bn)(predicateParams.maxGasPerPredicate),
3851
+ gasPriceFactor: (0, import_math16.bn)(feeParams.gasPriceFactor),
3852
+ gasPerByte: (0, import_math16.bn)(feeParams.gasPerByte),
3853
+ maxMessageDataLength: (0, import_math16.bn)(predicateParams.maxMessageDataLength),
3854
+ chainId: (0, import_math16.bn)(consensusParameters.chainId),
3855
+ baseAssetId: consensusParameters.baseAssetId,
3755
3856
  gasCosts
3756
3857
  },
3757
3858
  gasCosts,
3758
3859
  latestBlock: {
3759
3860
  id: latestBlock.id,
3760
- height: (0, import_math15.bn)(latestBlock.header.height),
3861
+ height: (0, import_math16.bn)(latestBlock.height),
3761
3862
  time: latestBlock.header.time,
3762
3863
  transactions: latestBlock.transactions.map((i) => ({
3763
3864
  id: i.id
@@ -3851,10 +3952,8 @@ var _Provider = class {
3851
3952
  * Returns some helpful parameters related to gas fees.
3852
3953
  */
3853
3954
  getGasConfig() {
3854
- const { minGasPrice } = this.getNode();
3855
3955
  const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
3856
3956
  return {
3857
- minGasPrice,
3858
3957
  maxGasPerTx,
3859
3958
  maxGasPerPredicate,
3860
3959
  gasPriceFactor,
@@ -3952,7 +4051,7 @@ var _Provider = class {
3952
4051
  */
3953
4052
  async getBlockNumber() {
3954
4053
  const { chain } = await this.operations.getChain();
3955
- return (0, import_math15.bn)(chain.latestBlock.header.height, 10);
4054
+ return (0, import_math16.bn)(chain.latestBlock.height, 10);
3956
4055
  }
3957
4056
  /**
3958
4057
  * Returns the chain information.
@@ -3962,13 +4061,11 @@ var _Provider = class {
3962
4061
  async fetchNode() {
3963
4062
  const { nodeInfo } = await this.operations.getNodeInfo();
3964
4063
  const processedNodeInfo = {
3965
- maxDepth: (0, import_math15.bn)(nodeInfo.maxDepth),
3966
- maxTx: (0, import_math15.bn)(nodeInfo.maxTx),
3967
- minGasPrice: (0, import_math15.bn)(nodeInfo.minGasPrice),
4064
+ maxDepth: (0, import_math16.bn)(nodeInfo.maxDepth),
4065
+ maxTx: (0, import_math16.bn)(nodeInfo.maxTx),
3968
4066
  nodeVersion: nodeInfo.nodeVersion,
3969
4067
  utxoValidation: nodeInfo.utxoValidation,
3970
- vmBacktrace: nodeInfo.vmBacktrace,
3971
- peers: nodeInfo.peers
4068
+ vmBacktrace: nodeInfo.vmBacktrace
3972
4069
  };
3973
4070
  _Provider.nodeInfoCache[this.url] = processedNodeInfo;
3974
4071
  return processedNodeInfo;
@@ -3994,6 +4091,17 @@ var _Provider = class {
3994
4091
  } = this.getChain();
3995
4092
  return chainId.toNumber();
3996
4093
  }
4094
+ /**
4095
+ * Returns the base asset ID for the current provider network
4096
+ *
4097
+ * @returns the base asset ID
4098
+ */
4099
+ getBaseAssetId() {
4100
+ const {
4101
+ consensusParameters: { baseAssetId }
4102
+ } = this.getChain();
4103
+ return baseAssetId;
4104
+ }
3997
4105
  /**
3998
4106
  * Submits a transaction to the chain to be executed.
3999
4107
  *
@@ -4010,9 +4118,9 @@ var _Provider = class {
4010
4118
  if (estimateTxDependencies) {
4011
4119
  await this.estimateTxDependencies(transactionRequest);
4012
4120
  }
4013
- const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
4121
+ const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
4014
4122
  let abis;
4015
- if (transactionRequest.type === import_transactions18.TransactionType.Script) {
4123
+ if (transactionRequest.type === import_transactions19.TransactionType.Script) {
4016
4124
  abis = transactionRequest.abis;
4017
4125
  }
4018
4126
  if (awaitExecution) {
@@ -4053,15 +4161,14 @@ var _Provider = class {
4053
4161
  if (estimateTxDependencies) {
4054
4162
  return this.estimateTxDependencies(transactionRequest);
4055
4163
  }
4056
- const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
4057
- const { dryRun: gqlReceipts } = await this.operations.dryRun({
4058
- encodedTransaction,
4164
+ const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
4165
+ const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4166
+ encodedTransactions: encodedTransaction,
4059
4167
  utxoValidation: utxoValidation || false
4060
4168
  });
4061
- const receipts = gqlReceipts.map(processGqlReceipt);
4062
- return {
4063
- receipts
4064
- };
4169
+ const [{ receipts: rawReceipts, status }] = dryRunStatuses;
4170
+ const receipts = rawReceipts.map(processGqlReceipt);
4171
+ return { receipts, dryrunStatus: status };
4065
4172
  }
4066
4173
  /**
4067
4174
  * Verifies whether enough gas is available to complete transaction.
@@ -4072,13 +4179,13 @@ var _Provider = class {
4072
4179
  async estimatePredicates(transactionRequest) {
4073
4180
  const shouldEstimatePredicates = Boolean(
4074
4181
  transactionRequest.inputs.find(
4075
- (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()
4182
+ (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()
4076
4183
  )
4077
4184
  );
4078
4185
  if (!shouldEstimatePredicates) {
4079
4186
  return transactionRequest;
4080
4187
  }
4081
- const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
4188
+ const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
4082
4189
  const response = await this.operations.estimatePredicates({
4083
4190
  encodedTransaction
4084
4191
  });
@@ -4087,7 +4194,7 @@ var _Provider = class {
4087
4194
  } = response;
4088
4195
  if (inputs) {
4089
4196
  inputs.forEach((input, index) => {
4090
- if ("predicateGasUsed" in input && (0, import_math15.bn)(input.predicateGasUsed).gt(0)) {
4197
+ if ("predicateGasUsed" in input && (0, import_math16.bn)(input.predicateGasUsed).gt(0)) {
4091
4198
  transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
4092
4199
  }
4093
4200
  });
@@ -4100,31 +4207,31 @@ var _Provider = class {
4100
4207
  * If there are missing variable outputs,
4101
4208
  * `addVariableOutputs` is called on the transaction.
4102
4209
  *
4103
- * @privateRemarks
4104
- * TODO: Investigate support for missing contract IDs
4105
- * TODO: Add support for missing output messages
4106
4210
  *
4107
4211
  * @param transactionRequest - The transaction request object.
4108
4212
  * @returns A promise.
4109
4213
  */
4110
4214
  async estimateTxDependencies(transactionRequest) {
4111
- if (transactionRequest.type === import_transactions18.TransactionType.Create) {
4215
+ if (transactionRequest.type === import_transactions19.TransactionType.Create) {
4112
4216
  return {
4113
4217
  receipts: [],
4114
4218
  outputVariables: 0,
4115
4219
  missingContractIds: []
4116
4220
  };
4117
4221
  }
4118
- await this.estimatePredicates(transactionRequest);
4119
4222
  let receipts = [];
4120
4223
  const missingContractIds = [];
4121
4224
  let outputVariables = 0;
4225
+ let dryrunStatus;
4122
4226
  for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
4123
- const { dryRun: gqlReceipts } = await this.operations.dryRun({
4124
- encodedTransaction: (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes()),
4227
+ const {
4228
+ dryRun: [{ receipts: rawReceipts, status }]
4229
+ } = await this.operations.dryRun({
4230
+ encodedTransactions: [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())],
4125
4231
  utxoValidation: false
4126
4232
  });
4127
- receipts = gqlReceipts.map(processGqlReceipt);
4233
+ receipts = rawReceipts.map(processGqlReceipt);
4234
+ dryrunStatus = status;
4128
4235
  const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
4129
4236
  const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
4130
4237
  if (hasMissingOutputs) {
@@ -4134,6 +4241,10 @@ var _Provider = class {
4134
4241
  transactionRequest.addContractInputAndOutput(import_address3.Address.fromString(contractId));
4135
4242
  missingContractIds.push(contractId);
4136
4243
  });
4244
+ const { maxFee } = await this.estimateTxGasAndFee({
4245
+ transactionRequest
4246
+ });
4247
+ transactionRequest.maxFee = maxFee;
4137
4248
  } else {
4138
4249
  break;
4139
4250
  }
@@ -4141,37 +4252,136 @@ var _Provider = class {
4141
4252
  return {
4142
4253
  receipts,
4143
4254
  outputVariables,
4144
- missingContractIds
4255
+ missingContractIds,
4256
+ dryrunStatus
4145
4257
  };
4146
4258
  }
4259
+ /**
4260
+ * Dry runs multiple transactions and checks for missing dependencies in batches.
4261
+ *
4262
+ * Transactions are dry run in batches. After each dry run, transactions requiring
4263
+ * further modifications are identified. The method iteratively updates these transactions
4264
+ * and performs subsequent dry runs until all dependencies for each transaction are satisfied.
4265
+ *
4266
+ * @param transactionRequests - Array of transaction request objects.
4267
+ * @returns A promise that resolves to an array of results for each transaction.
4268
+ */
4269
+ async estimateMultipleTxDependencies(transactionRequests) {
4270
+ const results = transactionRequests.map(() => ({
4271
+ receipts: [],
4272
+ outputVariables: 0,
4273
+ missingContractIds: [],
4274
+ dryrunStatus: void 0
4275
+ }));
4276
+ const allRequests = (0, import_ramda3.clone)(transactionRequests);
4277
+ const serializedTransactionsMap = /* @__PURE__ */ new Map();
4278
+ allRequests.forEach((req, index) => {
4279
+ if (req.type === import_transactions19.TransactionType.Script) {
4280
+ serializedTransactionsMap.set(index, (0, import_utils22.hexlify)(req.toTransactionBytes()));
4281
+ }
4282
+ });
4283
+ let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
4284
+ let attempt = 0;
4285
+ while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
4286
+ const encodedTransactions = transactionsToProcess.map(
4287
+ (index) => serializedTransactionsMap.get(index)
4288
+ );
4289
+ const dryRunResults = await this.operations.dryRun({
4290
+ encodedTransactions,
4291
+ utxoValidation: false
4292
+ });
4293
+ const nextRoundTransactions = [];
4294
+ for (let i = 0; i < dryRunResults.dryRun.length; i++) {
4295
+ const requestIdx = transactionsToProcess[i];
4296
+ const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
4297
+ const result = results[requestIdx];
4298
+ result.receipts = rawReceipts.map(processGqlReceipt);
4299
+ result.dryrunStatus = status;
4300
+ const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
4301
+ result.receipts
4302
+ );
4303
+ const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
4304
+ const request = allRequests[requestIdx];
4305
+ if (hasMissingOutputs && request?.type === import_transactions19.TransactionType.Script) {
4306
+ result.outputVariables += missingOutputVariables.length;
4307
+ request.addVariableOutputs(missingOutputVariables.length);
4308
+ missingOutputContractIds.forEach(({ contractId }) => {
4309
+ request.addContractInputAndOutput(import_address3.Address.fromString(contractId));
4310
+ result.missingContractIds.push(contractId);
4311
+ });
4312
+ const { maxFee } = await this.estimateTxGasAndFee({
4313
+ transactionRequest: request
4314
+ });
4315
+ request.maxFee = maxFee;
4316
+ serializedTransactionsMap.set(requestIdx, (0, import_utils22.hexlify)(request.toTransactionBytes()));
4317
+ nextRoundTransactions.push(requestIdx);
4318
+ }
4319
+ }
4320
+ transactionsToProcess = nextRoundTransactions;
4321
+ attempt += 1;
4322
+ }
4323
+ return results;
4324
+ }
4325
+ async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
4326
+ if (estimateTxDependencies) {
4327
+ return this.estimateMultipleTxDependencies(transactionRequests);
4328
+ }
4329
+ const encodedTransactions = transactionRequests.map((tx) => (0, import_utils22.hexlify)(tx.toTransactionBytes()));
4330
+ const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4331
+ encodedTransactions,
4332
+ utxoValidation: utxoValidation || false
4333
+ });
4334
+ const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
4335
+ const receipts = rawReceipts.map(processGqlReceipt);
4336
+ return { receipts, dryrunStatus: status };
4337
+ });
4338
+ return results;
4339
+ }
4147
4340
  /**
4148
4341
  * Estimates the transaction gas and fee based on the provided transaction request.
4149
4342
  * @param transactionRequest - The transaction request object.
4150
4343
  * @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
4151
4344
  */
4152
- estimateTxGasAndFee(params) {
4345
+ async estimateTxGasAndFee(params) {
4153
4346
  const { transactionRequest } = params;
4154
- const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
4347
+ let { gasPrice } = params;
4155
4348
  const chainInfo = this.getChain();
4156
- const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
4157
- transactionRequest.gasPrice = gasPrice;
4349
+ const { gasPriceFactor, maxGasPerTx } = this.getGasConfig();
4158
4350
  const minGas = transactionRequest.calculateMinGas(chainInfo);
4159
- const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
4160
- if (transactionRequest.type === import_transactions18.TransactionType.Script) {
4351
+ if (!gasPrice) {
4352
+ gasPrice = await this.estimateGasPrice(10);
4353
+ }
4354
+ const minFee = calculateGasFee({
4355
+ gasPrice: (0, import_math16.bn)(gasPrice),
4356
+ gas: minGas,
4357
+ priceFactor: gasPriceFactor,
4358
+ tip: transactionRequest.tip
4359
+ }).add(1);
4360
+ let gasLimit = (0, import_math16.bn)(0);
4361
+ if (transactionRequest.type === import_transactions19.TransactionType.Script) {
4362
+ gasLimit = transactionRequest.gasLimit;
4161
4363
  if (transactionRequest.gasLimit.eq(0)) {
4162
4364
  transactionRequest.gasLimit = minGas;
4163
4365
  transactionRequest.gasLimit = maxGasPerTx.sub(
4164
4366
  transactionRequest.calculateMaxGas(chainInfo, minGas)
4165
4367
  );
4368
+ gasLimit = transactionRequest.gasLimit;
4166
4369
  }
4167
4370
  }
4168
4371
  const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
4169
- const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
4372
+ const maxFee = calculateGasFee({
4373
+ gasPrice: (0, import_math16.bn)(gasPrice),
4374
+ gas: maxGas,
4375
+ priceFactor: gasPriceFactor,
4376
+ tip: transactionRequest.tip
4377
+ }).add(1);
4170
4378
  return {
4171
4379
  minGas,
4172
4380
  minFee,
4173
4381
  maxGas,
4174
- maxFee
4382
+ maxFee,
4383
+ gasPrice,
4384
+ gasLimit
4175
4385
  };
4176
4386
  }
4177
4387
  /**
@@ -4189,15 +4399,17 @@ var _Provider = class {
4189
4399
  if (estimateTxDependencies) {
4190
4400
  return this.estimateTxDependencies(transactionRequest);
4191
4401
  }
4192
- const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
4193
- const { dryRun: gqlReceipts } = await this.operations.dryRun({
4194
- encodedTransaction,
4402
+ const encodedTransactions = [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())];
4403
+ const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4404
+ encodedTransactions,
4195
4405
  utxoValidation: true
4196
4406
  });
4197
- const receipts = gqlReceipts.map(processGqlReceipt);
4198
- return {
4199
- receipts
4200
- };
4407
+ const callResult = dryRunStatuses.map((dryRunStatus) => {
4408
+ const { id, receipts, status } = dryRunStatus;
4409
+ const processedReceipts = receipts.map(processGqlReceipt);
4410
+ return { id, receipts: processedReceipts, status };
4411
+ });
4412
+ return { receipts: callResult[0].receipts };
4201
4413
  }
4202
4414
  /**
4203
4415
  * Returns a transaction cost to enable user
@@ -4214,77 +4426,80 @@ var _Provider = class {
4214
4426
  * @param tolerance - The tolerance to add on top of the gasUsed.
4215
4427
  * @returns A promise that resolves to the transaction cost object.
4216
4428
  */
4217
- async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
4218
- estimateTxDependencies = true,
4219
- estimatePredicates = true,
4220
- resourcesOwner,
4221
- signatureCallback
4222
- } = {}) {
4429
+ async getTransactionCost(transactionRequestLike, { resourcesOwner, signatureCallback, quantitiesToContract = [] } = {}) {
4223
4430
  const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
4224
- const { minGasPrice } = this.getGasConfig();
4225
- const setGasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
4226
- const isScriptTransaction = txRequestClone.type === import_transactions18.TransactionType.Script;
4431
+ const isScriptTransaction = txRequestClone.type === import_transactions19.TransactionType.Script;
4432
+ const baseAssetId = this.getBaseAssetId();
4227
4433
  const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
4228
- const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
4229
- txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
4434
+ const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
4435
+ txRequestClone.fundWithFakeUtxos(allQuantities, baseAssetId, resourcesOwner?.address);
4436
+ txRequestClone.maxFee = (0, import_math16.bn)(0);
4230
4437
  if (isScriptTransaction) {
4231
- txRequestClone.gasLimit = (0, import_math15.bn)(0);
4438
+ txRequestClone.gasLimit = (0, import_math16.bn)(0);
4232
4439
  }
4233
- if (estimatePredicates) {
4234
- if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
4235
- resourcesOwner.populateTransactionPredicateData(txRequestClone);
4236
- }
4237
- await this.estimatePredicates(txRequestClone);
4440
+ if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
4441
+ resourcesOwner.populateTransactionPredicateData(txRequestClone);
4238
4442
  }
4443
+ const signedRequest = (0, import_ramda3.clone)(txRequestClone);
4444
+ let addedSignatures = 0;
4239
4445
  if (signatureCallback && isScriptTransaction) {
4240
- await signatureCallback(txRequestClone);
4446
+ const lengthBefore = signedRequest.witnesses.length;
4447
+ await signatureCallback(signedRequest);
4448
+ addedSignatures = signedRequest.witnesses.length - lengthBefore;
4241
4449
  }
4242
- let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
4243
- transactionRequest: txRequestClone
4450
+ await this.estimatePredicates(signedRequest);
4451
+ let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
4452
+ transactionRequest: signedRequest
4244
4453
  });
4245
4454
  let receipts = [];
4246
4455
  let missingContractIds = [];
4247
4456
  let outputVariables = 0;
4248
- let gasUsed = (0, import_math15.bn)(0);
4249
- if (isScriptTransaction && estimateTxDependencies) {
4250
- txRequestClone.gasPrice = (0, import_math15.bn)(0);
4457
+ let gasUsed = (0, import_math16.bn)(0);
4458
+ txRequestClone.updatePredicateGasUsed(signedRequest.inputs);
4459
+ txRequestClone.maxFee = maxFee;
4460
+ if (isScriptTransaction) {
4461
+ txRequestClone.gasLimit = gasLimit;
4462
+ if (signatureCallback) {
4463
+ await signatureCallback(txRequestClone);
4464
+ }
4251
4465
  const result = await this.estimateTxDependencies(txRequestClone);
4252
4466
  receipts = result.receipts;
4253
4467
  outputVariables = result.outputVariables;
4254
4468
  missingContractIds = result.missingContractIds;
4255
4469
  gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
4256
4470
  txRequestClone.gasLimit = gasUsed;
4257
- txRequestClone.gasPrice = setGasPrice;
4258
- ({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
4259
- transactionRequest: txRequestClone
4471
+ ({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
4472
+ transactionRequest: txRequestClone,
4473
+ gasPrice
4260
4474
  }));
4261
4475
  }
4262
4476
  return {
4263
4477
  requiredQuantities: allQuantities,
4264
4478
  receipts,
4265
4479
  gasUsed,
4266
- minGasPrice,
4267
- gasPrice: setGasPrice,
4480
+ gasPrice,
4268
4481
  minGas,
4269
4482
  maxGas,
4270
4483
  minFee,
4271
4484
  maxFee,
4272
- estimatedInputs: txRequestClone.inputs,
4273
4485
  outputVariables,
4274
- missingContractIds
4486
+ missingContractIds,
4487
+ addedSignatures,
4488
+ estimatedPredicates: txRequestClone.inputs
4275
4489
  };
4276
4490
  }
4277
- async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
4491
+ async getResourcesForTransaction(owner, transactionRequestLike, quantitiesToContract = []) {
4278
4492
  const ownerAddress = import_address3.Address.fromAddressOrString(owner);
4279
4493
  const transactionRequest = transactionRequestify((0, import_ramda3.clone)(transactionRequestLike));
4280
- const transactionCost = await this.getTransactionCost(transactionRequest, forwardingQuantities);
4494
+ const transactionCost = await this.getTransactionCost(transactionRequest, {
4495
+ quantitiesToContract
4496
+ });
4281
4497
  transactionRequest.addResources(
4282
4498
  await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
4283
4499
  );
4284
- const { requiredQuantities, ...txCost } = await this.getTransactionCost(
4285
- transactionRequest,
4286
- forwardingQuantities
4287
- );
4500
+ const { requiredQuantities, ...txCost } = await this.getTransactionCost(transactionRequest, {
4501
+ quantitiesToContract
4502
+ });
4288
4503
  const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
4289
4504
  return {
4290
4505
  resources,
@@ -4300,17 +4515,16 @@ var _Provider = class {
4300
4515
  const result = await this.operations.getCoins({
4301
4516
  first: 10,
4302
4517
  ...paginationArgs,
4303
- filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils23.hexlify)(assetId) }
4518
+ filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils22.hexlify)(assetId) }
4304
4519
  });
4305
4520
  const coins = result.coins.edges.map((edge) => edge.node);
4306
4521
  return coins.map((coin) => ({
4307
4522
  id: coin.utxoId,
4308
4523
  assetId: coin.assetId,
4309
- amount: (0, import_math15.bn)(coin.amount),
4524
+ amount: (0, import_math16.bn)(coin.amount),
4310
4525
  owner: import_address3.Address.fromAddressOrString(coin.owner),
4311
- maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
4312
- blockCreated: (0, import_math15.bn)(coin.blockCreated),
4313
- txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
4526
+ blockCreated: (0, import_math16.bn)(coin.blockCreated),
4527
+ txCreatedIdx: (0, import_math16.bn)(coin.txCreatedIdx)
4314
4528
  }));
4315
4529
  }
4316
4530
  /**
@@ -4324,19 +4538,19 @@ var _Provider = class {
4324
4538
  async getResourcesToSpend(owner, quantities, excludedIds) {
4325
4539
  const ownerAddress = import_address3.Address.fromAddressOrString(owner);
4326
4540
  const excludeInput = {
4327
- messages: excludedIds?.messages?.map((nonce) => (0, import_utils23.hexlify)(nonce)) || [],
4328
- utxos: excludedIds?.utxos?.map((id) => (0, import_utils23.hexlify)(id)) || []
4541
+ messages: excludedIds?.messages?.map((nonce) => (0, import_utils22.hexlify)(nonce)) || [],
4542
+ utxos: excludedIds?.utxos?.map((id) => (0, import_utils22.hexlify)(id)) || []
4329
4543
  };
4330
4544
  if (this.cache) {
4331
4545
  const uniqueUtxos = new Set(
4332
- excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils23.hexlify)(id)))
4546
+ excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils22.hexlify)(id)))
4333
4547
  );
4334
4548
  excludeInput.utxos = Array.from(uniqueUtxos);
4335
4549
  }
4336
4550
  const coinsQuery = {
4337
4551
  owner: ownerAddress.toB256(),
4338
4552
  queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
4339
- assetId: (0, import_utils23.hexlify)(assetId),
4553
+ assetId: (0, import_utils22.hexlify)(assetId),
4340
4554
  amount: amount.toString(10),
4341
4555
  max: maxPerAsset ? maxPerAsset.toString(10) : void 0
4342
4556
  })),
@@ -4347,9 +4561,9 @@ var _Provider = class {
4347
4561
  switch (coin.__typename) {
4348
4562
  case "MessageCoin":
4349
4563
  return {
4350
- amount: (0, import_math15.bn)(coin.amount),
4564
+ amount: (0, import_math16.bn)(coin.amount),
4351
4565
  assetId: coin.assetId,
4352
- daHeight: (0, import_math15.bn)(coin.daHeight),
4566
+ daHeight: (0, import_math16.bn)(coin.daHeight),
4353
4567
  sender: import_address3.Address.fromAddressOrString(coin.sender),
4354
4568
  recipient: import_address3.Address.fromAddressOrString(coin.recipient),
4355
4569
  nonce: coin.nonce
@@ -4357,12 +4571,11 @@ var _Provider = class {
4357
4571
  case "Coin":
4358
4572
  return {
4359
4573
  id: coin.utxoId,
4360
- amount: (0, import_math15.bn)(coin.amount),
4574
+ amount: (0, import_math16.bn)(coin.amount),
4361
4575
  assetId: coin.assetId,
4362
4576
  owner: import_address3.Address.fromAddressOrString(coin.owner),
4363
- maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
4364
- blockCreated: (0, import_math15.bn)(coin.blockCreated),
4365
- txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
4577
+ blockCreated: (0, import_math16.bn)(coin.blockCreated),
4578
+ txCreatedIdx: (0, import_math16.bn)(coin.txCreatedIdx)
4366
4579
  };
4367
4580
  default:
4368
4581
  return null;
@@ -4379,13 +4592,13 @@ var _Provider = class {
4379
4592
  async getBlock(idOrHeight) {
4380
4593
  let variables;
4381
4594
  if (typeof idOrHeight === "number") {
4382
- variables = { height: (0, import_math15.bn)(idOrHeight).toString(10) };
4595
+ variables = { height: (0, import_math16.bn)(idOrHeight).toString(10) };
4383
4596
  } else if (idOrHeight === "latest") {
4384
4597
  variables = { height: (await this.getBlockNumber()).toString(10) };
4385
4598
  } else if (idOrHeight.length === 66) {
4386
4599
  variables = { blockId: idOrHeight };
4387
4600
  } else {
4388
- variables = { blockId: (0, import_math15.bn)(idOrHeight).toString(10) };
4601
+ variables = { blockId: (0, import_math16.bn)(idOrHeight).toString(10) };
4389
4602
  }
4390
4603
  const { block } = await this.operations.getBlock(variables);
4391
4604
  if (!block) {
@@ -4393,7 +4606,7 @@ var _Provider = class {
4393
4606
  }
4394
4607
  return {
4395
4608
  id: block.id,
4396
- height: (0, import_math15.bn)(block.header.height),
4609
+ height: (0, import_math16.bn)(block.height),
4397
4610
  time: block.header.time,
4398
4611
  transactionIds: block.transactions.map((tx) => tx.id)
4399
4612
  };
@@ -4408,7 +4621,7 @@ var _Provider = class {
4408
4621
  const { blocks: fetchedData } = await this.operations.getBlocks(params);
4409
4622
  const blocks = fetchedData.edges.map(({ node: block }) => ({
4410
4623
  id: block.id,
4411
- height: (0, import_math15.bn)(block.header.height),
4624
+ height: (0, import_math16.bn)(block.height),
4412
4625
  time: block.header.time,
4413
4626
  transactionIds: block.transactions.map((tx) => tx.id)
4414
4627
  }));
@@ -4423,7 +4636,7 @@ var _Provider = class {
4423
4636
  async getBlockWithTransactions(idOrHeight) {
4424
4637
  let variables;
4425
4638
  if (typeof idOrHeight === "number") {
4426
- variables = { blockHeight: (0, import_math15.bn)(idOrHeight).toString(10) };
4639
+ variables = { blockHeight: (0, import_math16.bn)(idOrHeight).toString(10) };
4427
4640
  } else if (idOrHeight === "latest") {
4428
4641
  variables = { blockHeight: (await this.getBlockNumber()).toString() };
4429
4642
  } else {
@@ -4435,11 +4648,11 @@ var _Provider = class {
4435
4648
  }
4436
4649
  return {
4437
4650
  id: block.id,
4438
- height: (0, import_math15.bn)(block.header.height, 10),
4651
+ height: (0, import_math16.bn)(block.height, 10),
4439
4652
  time: block.header.time,
4440
4653
  transactionIds: block.transactions.map((tx) => tx.id),
4441
4654
  transactions: block.transactions.map(
4442
- (tx) => new import_transactions18.TransactionCoder().decode((0, import_utils23.arrayify)(tx.rawPayload), 0)?.[0]
4655
+ (tx) => new import_transactions19.TransactionCoder().decode((0, import_utils22.arrayify)(tx.rawPayload), 0)?.[0]
4443
4656
  )
4444
4657
  };
4445
4658
  }
@@ -4454,8 +4667,8 @@ var _Provider = class {
4454
4667
  if (!transaction) {
4455
4668
  return null;
4456
4669
  }
4457
- return new import_transactions18.TransactionCoder().decode(
4458
- (0, import_utils23.arrayify)(transaction.rawPayload),
4670
+ return new import_transactions19.TransactionCoder().decode(
4671
+ (0, import_utils22.arrayify)(transaction.rawPayload),
4459
4672
  0
4460
4673
  )?.[0];
4461
4674
  }
@@ -4482,9 +4695,9 @@ var _Provider = class {
4482
4695
  async getContractBalance(contractId, assetId) {
4483
4696
  const { contractBalance } = await this.operations.getContractBalance({
4484
4697
  contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
4485
- asset: (0, import_utils23.hexlify)(assetId)
4698
+ asset: (0, import_utils22.hexlify)(assetId)
4486
4699
  });
4487
- return (0, import_math15.bn)(contractBalance.amount, 10);
4700
+ return (0, import_math16.bn)(contractBalance.amount, 10);
4488
4701
  }
4489
4702
  /**
4490
4703
  * Returns the balance for the given owner for the given asset ID.
@@ -4496,9 +4709,9 @@ var _Provider = class {
4496
4709
  async getBalance(owner, assetId) {
4497
4710
  const { balance } = await this.operations.getBalance({
4498
4711
  owner: import_address3.Address.fromAddressOrString(owner).toB256(),
4499
- assetId: (0, import_utils23.hexlify)(assetId)
4712
+ assetId: (0, import_utils22.hexlify)(assetId)
4500
4713
  });
4501
- return (0, import_math15.bn)(balance.amount, 10);
4714
+ return (0, import_math16.bn)(balance.amount, 10);
4502
4715
  }
4503
4716
  /**
4504
4717
  * Returns balances for the given owner.
@@ -4516,7 +4729,7 @@ var _Provider = class {
4516
4729
  const balances = result.balances.edges.map((edge) => edge.node);
4517
4730
  return balances.map((balance) => ({
4518
4731
  assetId: balance.assetId,
4519
- amount: (0, import_math15.bn)(balance.amount)
4732
+ amount: (0, import_math16.bn)(balance.amount)
4520
4733
  }));
4521
4734
  }
4522
4735
  /**
@@ -4534,19 +4747,19 @@ var _Provider = class {
4534
4747
  });
4535
4748
  const messages = result.messages.edges.map((edge) => edge.node);
4536
4749
  return messages.map((message) => ({
4537
- messageId: import_transactions18.InputMessageCoder.getMessageId({
4750
+ messageId: import_transactions19.InputMessageCoder.getMessageId({
4538
4751
  sender: message.sender,
4539
4752
  recipient: message.recipient,
4540
4753
  nonce: message.nonce,
4541
- amount: (0, import_math15.bn)(message.amount),
4754
+ amount: (0, import_math16.bn)(message.amount),
4542
4755
  data: message.data
4543
4756
  }),
4544
4757
  sender: import_address3.Address.fromAddressOrString(message.sender),
4545
4758
  recipient: import_address3.Address.fromAddressOrString(message.recipient),
4546
4759
  nonce: message.nonce,
4547
- amount: (0, import_math15.bn)(message.amount),
4548
- data: import_transactions18.InputMessageCoder.decodeData(message.data),
4549
- daHeight: (0, import_math15.bn)(message.daHeight)
4760
+ amount: (0, import_math16.bn)(message.amount),
4761
+ data: import_transactions19.InputMessageCoder.decodeData(message.data),
4762
+ daHeight: (0, import_math16.bn)(message.daHeight)
4550
4763
  }));
4551
4764
  }
4552
4765
  /**
@@ -4599,44 +4812,60 @@ var _Provider = class {
4599
4812
  } = result.messageProof;
4600
4813
  return {
4601
4814
  messageProof: {
4602
- proofIndex: (0, import_math15.bn)(messageProof.proofIndex),
4815
+ proofIndex: (0, import_math16.bn)(messageProof.proofIndex),
4603
4816
  proofSet: messageProof.proofSet
4604
4817
  },
4605
4818
  blockProof: {
4606
- proofIndex: (0, import_math15.bn)(blockProof.proofIndex),
4819
+ proofIndex: (0, import_math16.bn)(blockProof.proofIndex),
4607
4820
  proofSet: blockProof.proofSet
4608
4821
  },
4609
4822
  messageBlockHeader: {
4610
4823
  id: messageBlockHeader.id,
4611
- daHeight: (0, import_math15.bn)(messageBlockHeader.daHeight),
4612
- transactionsCount: (0, import_math15.bn)(messageBlockHeader.transactionsCount),
4824
+ daHeight: (0, import_math16.bn)(messageBlockHeader.daHeight),
4825
+ transactionsCount: (0, import_math16.bn)(messageBlockHeader.transactionsCount),
4613
4826
  transactionsRoot: messageBlockHeader.transactionsRoot,
4614
- height: (0, import_math15.bn)(messageBlockHeader.height),
4827
+ height: (0, import_math16.bn)(messageBlockHeader.height),
4615
4828
  prevRoot: messageBlockHeader.prevRoot,
4616
4829
  time: messageBlockHeader.time,
4617
4830
  applicationHash: messageBlockHeader.applicationHash,
4618
- messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
4619
- messageReceiptCount: (0, import_math15.bn)(messageBlockHeader.messageReceiptCount)
4831
+ messageReceiptCount: (0, import_math16.bn)(messageBlockHeader.messageReceiptCount),
4832
+ messageOutboxRoot: messageBlockHeader.messageOutboxRoot,
4833
+ consensusParametersVersion: messageBlockHeader.consensusParametersVersion,
4834
+ eventInboxRoot: messageBlockHeader.eventInboxRoot,
4835
+ stateTransitionBytecodeVersion: messageBlockHeader.stateTransitionBytecodeVersion
4620
4836
  },
4621
4837
  commitBlockHeader: {
4622
4838
  id: commitBlockHeader.id,
4623
- daHeight: (0, import_math15.bn)(commitBlockHeader.daHeight),
4624
- transactionsCount: (0, import_math15.bn)(commitBlockHeader.transactionsCount),
4839
+ daHeight: (0, import_math16.bn)(commitBlockHeader.daHeight),
4840
+ transactionsCount: (0, import_math16.bn)(commitBlockHeader.transactionsCount),
4625
4841
  transactionsRoot: commitBlockHeader.transactionsRoot,
4626
- height: (0, import_math15.bn)(commitBlockHeader.height),
4842
+ height: (0, import_math16.bn)(commitBlockHeader.height),
4627
4843
  prevRoot: commitBlockHeader.prevRoot,
4628
4844
  time: commitBlockHeader.time,
4629
4845
  applicationHash: commitBlockHeader.applicationHash,
4630
- messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
4631
- messageReceiptCount: (0, import_math15.bn)(commitBlockHeader.messageReceiptCount)
4846
+ messageReceiptCount: (0, import_math16.bn)(commitBlockHeader.messageReceiptCount),
4847
+ messageOutboxRoot: commitBlockHeader.messageOutboxRoot,
4848
+ consensusParametersVersion: commitBlockHeader.consensusParametersVersion,
4849
+ eventInboxRoot: commitBlockHeader.eventInboxRoot,
4850
+ stateTransitionBytecodeVersion: commitBlockHeader.stateTransitionBytecodeVersion
4632
4851
  },
4633
4852
  sender: import_address3.Address.fromAddressOrString(sender),
4634
4853
  recipient: import_address3.Address.fromAddressOrString(recipient),
4635
4854
  nonce,
4636
- amount: (0, import_math15.bn)(amount),
4855
+ amount: (0, import_math16.bn)(amount),
4637
4856
  data
4638
4857
  };
4639
4858
  }
4859
+ async getLatestGasPrice() {
4860
+ const { latestGasPrice } = await this.operations.getLatestGasPrice();
4861
+ return (0, import_math16.bn)(latestGasPrice.gasPrice);
4862
+ }
4863
+ async estimateGasPrice(blockHorizon) {
4864
+ const { estimateGasPrice } = await this.operations.estimateGasPrice({
4865
+ blockHorizon: String(blockHorizon)
4866
+ });
4867
+ return (0, import_math16.bn)(estimateGasPrice.gasPrice);
4868
+ }
4640
4869
  /**
4641
4870
  * Returns Message Proof for given transaction id and the message id from MessageOut receipt.
4642
4871
  *
@@ -4656,10 +4885,10 @@ var _Provider = class {
4656
4885
  */
4657
4886
  async produceBlocks(amount, startTime) {
4658
4887
  const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
4659
- blocksToProduce: (0, import_math15.bn)(amount).toString(10),
4660
- startTimestamp: startTime ? import_utils23.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
4888
+ blocksToProduce: (0, import_math16.bn)(amount).toString(10),
4889
+ startTimestamp: startTime ? import_utils22.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
4661
4890
  });
4662
- return (0, import_math15.bn)(latestBlockHeight);
4891
+ return (0, import_math16.bn)(latestBlockHeight);
4663
4892
  }
4664
4893
  // eslint-disable-next-line @typescript-eslint/require-await
4665
4894
  async getTransactionResponse(transactionId) {
@@ -4673,7 +4902,7 @@ cacheInputs_fn = function(inputs) {
4673
4902
  return;
4674
4903
  }
4675
4904
  inputs.forEach((input) => {
4676
- if (input.type === import_transactions18.InputType.Coin) {
4905
+ if (input.type === import_transactions19.InputType.Coin) {
4677
4906
  this.cache?.set(input.id);
4678
4907
  }
4679
4908
  });
@@ -4683,9 +4912,9 @@ __publicField(Provider, "nodeInfoCache", {});
4683
4912
 
4684
4913
  // src/providers/transaction-summary/get-transaction-summary.ts
4685
4914
  var import_errors15 = require("@fuel-ts/errors");
4686
- var import_math16 = require("@fuel-ts/math");
4687
- var import_transactions19 = require("@fuel-ts/transactions");
4688
- var import_utils26 = require("@fuel-ts/utils");
4915
+ var import_math17 = require("@fuel-ts/math");
4916
+ var import_transactions20 = require("@fuel-ts/transactions");
4917
+ var import_utils25 = require("@fuel-ts/utils");
4689
4918
  async function getTransactionSummary(params) {
4690
4919
  const { id, provider, abiMap } = params;
4691
4920
  const { transaction: gqlTransaction } = await provider.operations.getTransactionWithReceipts({
@@ -4697,25 +4926,32 @@ async function getTransactionSummary(params) {
4697
4926
  `Transaction not found for given id: ${id}.`
4698
4927
  );
4699
4928
  }
4700
- const [decodedTransaction] = new import_transactions19.TransactionCoder().decode(
4701
- (0, import_utils26.arrayify)(gqlTransaction.rawPayload),
4929
+ const [decodedTransaction] = new import_transactions20.TransactionCoder().decode(
4930
+ (0, import_utils25.arrayify)(gqlTransaction.rawPayload),
4702
4931
  0
4703
4932
  );
4704
- const receipts = gqlTransaction.receipts?.map(processGqlReceipt) || [];
4933
+ let txReceipts = [];
4934
+ if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
4935
+ txReceipts = gqlTransaction.status.receipts;
4936
+ }
4937
+ const receipts = txReceipts.map(processGqlReceipt);
4705
4938
  const {
4706
- consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
4939
+ consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts, maxGasPerTx }
4707
4940
  } = provider.getChain();
4941
+ const gasPrice = await provider.getLatestGasPrice();
4708
4942
  const transactionInfo = assembleTransactionSummary({
4709
4943
  id: gqlTransaction.id,
4710
4944
  receipts,
4711
4945
  transaction: decodedTransaction,
4712
- transactionBytes: (0, import_utils26.arrayify)(gqlTransaction.rawPayload),
4946
+ transactionBytes: (0, import_utils25.arrayify)(gqlTransaction.rawPayload),
4713
4947
  gqlTransactionStatus: gqlTransaction.status,
4714
- gasPerByte: (0, import_math16.bn)(gasPerByte),
4715
- gasPriceFactor: (0, import_math16.bn)(gasPriceFactor),
4948
+ gasPerByte: (0, import_math17.bn)(gasPerByte),
4949
+ gasPriceFactor: (0, import_math17.bn)(gasPriceFactor),
4716
4950
  abiMap,
4717
4951
  maxInputs,
4718
- gasCosts
4952
+ gasCosts,
4953
+ maxGasPerTx,
4954
+ gasPrice
4719
4955
  });
4720
4956
  return {
4721
4957
  gqlTransaction,
@@ -4725,10 +4961,11 @@ async function getTransactionSummary(params) {
4725
4961
  async function getTransactionSummaryFromRequest(params) {
4726
4962
  const { provider, transactionRequest, abiMap } = params;
4727
4963
  const { receipts } = await provider.call(transactionRequest);
4728
- const { gasPerByte, gasPriceFactor, gasCosts } = provider.getGasConfig();
4964
+ const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = provider.getGasConfig();
4729
4965
  const maxInputs = provider.getChain().consensusParameters.maxInputs;
4730
4966
  const transaction = transactionRequest.toTransaction();
4731
4967
  const transactionBytes = transactionRequest.toTransactionBytes();
4968
+ const gasPrice = await provider.getLatestGasPrice();
4732
4969
  const transactionSummary = assembleTransactionSummary({
4733
4970
  receipts,
4734
4971
  transaction,
@@ -4737,7 +4974,9 @@ async function getTransactionSummaryFromRequest(params) {
4737
4974
  gasPerByte,
4738
4975
  gasPriceFactor,
4739
4976
  maxInputs,
4740
- gasCosts
4977
+ gasCosts,
4978
+ maxGasPerTx,
4979
+ gasPrice
4741
4980
  });
4742
4981
  return transactionSummary;
4743
4982
  }
@@ -4746,24 +4985,31 @@ async function getTransactionsSummaries(params) {
4746
4985
  const { transactionsByOwner } = await provider.operations.getTransactionsByOwner(filters);
4747
4986
  const { edges, pageInfo } = transactionsByOwner;
4748
4987
  const {
4749
- consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
4988
+ consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts, maxGasPerTx }
4750
4989
  } = provider.getChain();
4990
+ const gasPrice = await provider.getLatestGasPrice();
4751
4991
  const transactions = edges.map((edge) => {
4752
4992
  const { node: gqlTransaction } = edge;
4753
- const { id, rawPayload, receipts: gqlReceipts, status } = gqlTransaction;
4754
- const [decodedTransaction] = new import_transactions19.TransactionCoder().decode((0, import_utils26.arrayify)(rawPayload), 0);
4755
- const receipts = gqlReceipts?.map(processGqlReceipt) || [];
4993
+ const { id, rawPayload, status } = gqlTransaction;
4994
+ const [decodedTransaction] = new import_transactions20.TransactionCoder().decode((0, import_utils25.arrayify)(rawPayload), 0);
4995
+ let txReceipts = [];
4996
+ if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
4997
+ txReceipts = gqlTransaction.status.receipts;
4998
+ }
4999
+ const receipts = txReceipts.map(processGqlReceipt);
4756
5000
  const transactionSummary = assembleTransactionSummary({
4757
5001
  id,
4758
5002
  receipts,
4759
5003
  transaction: decodedTransaction,
4760
- transactionBytes: (0, import_utils26.arrayify)(rawPayload),
5004
+ transactionBytes: (0, import_utils25.arrayify)(rawPayload),
4761
5005
  gqlTransactionStatus: status,
4762
5006
  abiMap,
4763
5007
  gasPerByte,
4764
5008
  gasPriceFactor,
4765
5009
  maxInputs,
4766
- gasCosts
5010
+ gasCosts,
5011
+ maxGasPerTx,
5012
+ gasPrice
4767
5013
  });
4768
5014
  const output = {
4769
5015
  gqlTransaction,
@@ -4900,17 +5146,17 @@ var assets = [
4900
5146
 
4901
5147
  // src/utils/formatTransferToContractScriptData.ts
4902
5148
  var import_abi_coder6 = require("@fuel-ts/abi-coder");
4903
- var import_math17 = require("@fuel-ts/math");
4904
- var import_utils27 = require("@fuel-ts/utils");
5149
+ var import_math18 = require("@fuel-ts/math");
5150
+ var import_utils26 = require("@fuel-ts/utils");
4905
5151
  var asm = __toESM(require("@fuels/vm-asm"));
4906
5152
  var formatTransferToContractScriptData = (params) => {
4907
5153
  const { assetId, amountToTransfer, hexlifiedContractId } = params;
4908
5154
  const numberCoder = new import_abi_coder6.BigNumberCoder("u64");
4909
- const encoded = numberCoder.encode(new import_math17.BN(amountToTransfer).toNumber());
5155
+ const encoded = numberCoder.encode(new import_math18.BN(amountToTransfer).toNumber());
4910
5156
  const scriptData = Uint8Array.from([
4911
- ...(0, import_utils27.arrayify)(hexlifiedContractId),
5157
+ ...(0, import_utils26.arrayify)(hexlifiedContractId),
4912
5158
  ...encoded,
4913
- ...(0, import_utils27.arrayify)(assetId)
5159
+ ...(0, import_utils26.arrayify)(assetId)
4914
5160
  ]);
4915
5161
  return scriptData;
4916
5162
  };
@@ -5057,8 +5303,9 @@ var Account = class extends import_interfaces.AbstractAccount {
5057
5303
  * @param assetId - The asset ID to check the balance for.
5058
5304
  * @returns A promise that resolves to the balance amount.
5059
5305
  */
5060
- async getBalance(assetId = import_configs12.BaseAssetId) {
5061
- const amount = await this.provider.getBalance(this.address, assetId);
5306
+ async getBalance(assetId) {
5307
+ const assetIdToFetch = assetId ?? this.provider.getBaseAssetId();
5308
+ const amount = await this.provider.getBalance(this.address, assetIdToFetch);
5062
5309
  return amount;
5063
5310
  }
5064
5311
  /**
@@ -5095,37 +5342,31 @@ var Account = class extends import_interfaces.AbstractAccount {
5095
5342
  * @param fee - The estimated transaction fee.
5096
5343
  * @returns A promise that resolves when the resources are added to the transaction.
5097
5344
  */
5098
- async fund(request, coinQuantities, fee) {
5099
- const updatedQuantities = addAmountToAsset({
5100
- amount: (0, import_math18.bn)(fee),
5101
- assetId: import_configs12.BaseAssetId,
5102
- coinQuantities
5345
+ async fund(request, params) {
5346
+ const { addedSignatures, estimatedPredicates, maxFee: fee, requiredQuantities } = params;
5347
+ const baseAssetId = this.provider.getBaseAssetId();
5348
+ const txRequest = request;
5349
+ const requiredQuantitiesWithFee = addAmountToCoinQuantities({
5350
+ amount: (0, import_math19.bn)(fee),
5351
+ assetId: baseAssetId,
5352
+ coinQuantities: requiredQuantities
5103
5353
  });
5104
5354
  const quantitiesDict = {};
5105
- updatedQuantities.forEach(({ amount, assetId }) => {
5355
+ requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
5106
5356
  quantitiesDict[assetId] = {
5107
5357
  required: amount,
5108
- owned: (0, import_math18.bn)(0)
5358
+ owned: (0, import_math19.bn)(0)
5109
5359
  };
5110
5360
  });
5111
- const cachedUtxos = [];
5112
- const cachedMessages = [];
5113
- const owner = this.address.toB256();
5114
- request.inputs.forEach((input) => {
5361
+ txRequest.inputs.forEach((input) => {
5115
5362
  const isResource = "amount" in input;
5116
- if (isResource) {
5117
- const isCoin2 = "owner" in input;
5118
- if (isCoin2) {
5119
- const assetId = String(input.assetId);
5120
- if (input.owner === owner && quantitiesDict[assetId]) {
5121
- const amount = (0, import_math18.bn)(input.amount);
5122
- quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
5123
- cachedUtxos.push(input.id);
5124
- }
5125
- } else if (input.recipient === owner && input.amount && quantitiesDict[import_configs12.BaseAssetId]) {
5126
- quantitiesDict[import_configs12.BaseAssetId].owned = quantitiesDict[import_configs12.BaseAssetId].owned.add(input.amount);
5127
- cachedMessages.push(input.nonce);
5128
- }
5363
+ if (!isResource) {
5364
+ return;
5365
+ }
5366
+ const isCoin2 = "owner" in input;
5367
+ const assetId = isCoin2 ? String(input.assetId) : baseAssetId;
5368
+ if (quantitiesDict[assetId]) {
5369
+ quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(input.amount);
5129
5370
  }
5130
5371
  });
5131
5372
  const missingQuantities = [];
@@ -5139,12 +5380,21 @@ var Account = class extends import_interfaces.AbstractAccount {
5139
5380
  });
5140
5381
  const needsToBeFunded = missingQuantities.length;
5141
5382
  if (needsToBeFunded) {
5142
- const resources = await this.getResourcesToSpend(missingQuantities, {
5143
- messages: cachedMessages,
5144
- utxos: cachedUtxos
5145
- });
5146
- request.addResources(resources);
5147
- }
5383
+ const excludedIds = cacheTxInputsFromOwner(txRequest.inputs, this.address.toB256());
5384
+ const resources = await this.getResourcesToSpend(missingQuantities, excludedIds);
5385
+ txRequest.addResources(resources);
5386
+ }
5387
+ txRequest.shiftPredicateData();
5388
+ txRequest.updatePredicateGasUsed(estimatedPredicates);
5389
+ const requestToReestimate = (0, import_ramda4.clone)(txRequest);
5390
+ if (addedSignatures) {
5391
+ Array.from({ length: addedSignatures }).forEach(() => requestToReestimate.addEmptyWitness());
5392
+ }
5393
+ const { maxFee } = await this.provider.estimateTxGasAndFee({
5394
+ transactionRequest: requestToReestimate
5395
+ });
5396
+ txRequest.maxFee = maxFee;
5397
+ return txRequest;
5148
5398
  }
5149
5399
  /**
5150
5400
  * A helper that creates a transfer transaction request and returns it.
@@ -5152,28 +5402,25 @@ var Account = class extends import_interfaces.AbstractAccount {
5152
5402
  * @param destination - The address of the destination.
5153
5403
  * @param amount - The amount of coins to transfer.
5154
5404
  * @param assetId - The asset ID of the coins to transfer.
5155
- * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
5405
+ * @param txParams - The transaction parameters (gasLimit, tip, maturity, maxFee, witnessLimit).
5156
5406
  * @returns A promise that resolves to the prepared transaction request.
5157
5407
  */
5158
- async createTransfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
5159
- const { minGasPrice } = this.provider.getGasConfig();
5160
- const params = { gasPrice: minGasPrice, ...txParams };
5161
- const request = new ScriptTransactionRequest(params);
5162
- request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetId);
5163
- const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
5408
+ async createTransfer(destination, amount, assetId, txParams = {}) {
5409
+ const request = new ScriptTransactionRequest(txParams);
5410
+ const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
5411
+ request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetIdToTransfer);
5412
+ const txCost = await this.provider.getTransactionCost(request, {
5164
5413
  estimateTxDependencies: true,
5165
5414
  resourcesOwner: this
5166
5415
  });
5167
- request.gasPrice = (0, import_math18.bn)(txParams.gasPrice ?? minGasPrice);
5168
- request.gasLimit = (0, import_math18.bn)(txParams.gasLimit ?? gasUsed);
5169
- this.validateGas({
5170
- gasUsed,
5171
- gasPrice: request.gasPrice,
5172
- gasLimit: request.gasLimit,
5173
- minGasPrice
5416
+ this.validateGasLimitAndMaxFee({
5417
+ gasUsed: txCost.gasUsed,
5418
+ maxFee: txCost.maxFee,
5419
+ txParams
5174
5420
  });
5175
- await this.fund(request, requiredQuantities, maxFee);
5176
- request.updatePredicateInputs(estimatedInputs);
5421
+ request.gasLimit = txCost.gasUsed;
5422
+ request.maxFee = txCost.maxFee;
5423
+ await this.fund(request, txCost);
5177
5424
  return request;
5178
5425
  }
5179
5426
  /**
@@ -5182,17 +5429,18 @@ var Account = class extends import_interfaces.AbstractAccount {
5182
5429
  * @param destination - The address of the destination.
5183
5430
  * @param amount - The amount of coins to transfer.
5184
5431
  * @param assetId - The asset ID of the coins to transfer.
5185
- * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
5432
+ * @param txParams - The transaction parameters (gasLimit, maturity).
5186
5433
  * @returns A promise that resolves to the transaction response.
5187
5434
  */
5188
- async transfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
5189
- if ((0, import_math18.bn)(amount).lte(0)) {
5435
+ async transfer(destination, amount, assetId, txParams = {}) {
5436
+ if ((0, import_math19.bn)(amount).lte(0)) {
5190
5437
  throw new import_errors16.FuelError(
5191
5438
  import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
5192
5439
  "Transfer amount must be a positive number."
5193
5440
  );
5194
5441
  }
5195
- const request = await this.createTransfer(destination, amount, assetId, txParams);
5442
+ const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
5443
+ const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
5196
5444
  return this.sendTransaction(request, { estimateTxDependencies: false });
5197
5445
  }
5198
5446
  /**
@@ -5204,39 +5452,38 @@ var Account = class extends import_interfaces.AbstractAccount {
5204
5452
  * @param txParams - The optional transaction parameters.
5205
5453
  * @returns A promise that resolves to the transaction response.
5206
5454
  */
5207
- async transferToContract(contractId, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
5208
- if ((0, import_math18.bn)(amount).lte(0)) {
5455
+ async transferToContract(contractId, amount, assetId, txParams = {}) {
5456
+ if ((0, import_math19.bn)(amount).lte(0)) {
5209
5457
  throw new import_errors16.FuelError(
5210
5458
  import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
5211
5459
  "Transfer amount must be a positive number."
5212
5460
  );
5213
5461
  }
5214
5462
  const contractAddress = import_address4.Address.fromAddressOrString(contractId);
5215
- const { minGasPrice } = this.provider.getGasConfig();
5216
- const params = { gasPrice: minGasPrice, ...txParams };
5463
+ const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
5217
5464
  const { script, scriptData } = await assembleTransferToContractScript({
5218
5465
  hexlifiedContractId: contractAddress.toB256(),
5219
- amountToTransfer: (0, import_math18.bn)(amount),
5220
- assetId
5466
+ amountToTransfer: (0, import_math19.bn)(amount),
5467
+ assetId: assetIdToTransfer
5221
5468
  });
5222
5469
  const request = new ScriptTransactionRequest({
5223
- ...params,
5470
+ ...txParams,
5224
5471
  script,
5225
5472
  scriptData
5226
5473
  });
5227
5474
  request.addContractInputAndOutput(contractAddress);
5228
- const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
5229
- request,
5230
- [{ amount: (0, import_math18.bn)(amount), assetId: String(assetId) }]
5231
- );
5232
- request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
5233
- this.validateGas({
5234
- gasUsed,
5235
- gasPrice: request.gasPrice,
5236
- gasLimit: request.gasLimit,
5237
- minGasPrice
5475
+ const txCost = await this.provider.getTransactionCost(request, {
5476
+ resourcesOwner: this,
5477
+ quantitiesToContract: [{ amount: (0, import_math19.bn)(amount), assetId: String(assetIdToTransfer) }]
5478
+ });
5479
+ this.validateGasLimitAndMaxFee({
5480
+ gasUsed: txCost.gasUsed,
5481
+ maxFee: txCost.maxFee,
5482
+ txParams
5238
5483
  });
5239
- await this.fund(request, requiredQuantities, maxFee);
5484
+ request.gasLimit = txCost.gasUsed;
5485
+ request.maxFee = txCost.maxFee;
5486
+ await this.fund(request, txCost);
5240
5487
  return this.sendTransaction(request);
5241
5488
  }
5242
5489
  /**
@@ -5248,34 +5495,31 @@ var Account = class extends import_interfaces.AbstractAccount {
5248
5495
  * @returns A promise that resolves to the transaction response.
5249
5496
  */
5250
5497
  async withdrawToBaseLayer(recipient, amount, txParams = {}) {
5251
- const { minGasPrice } = this.provider.getGasConfig();
5252
5498
  const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
5253
- const recipientDataArray = (0, import_utils28.arrayify)(
5499
+ const recipientDataArray = (0, import_utils27.arrayify)(
5254
5500
  "0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
5255
5501
  );
5256
- const amountDataArray = (0, import_utils28.arrayify)(
5257
- "0x".concat((0, import_math18.bn)(amount).toHex().substring(2).padStart(16, "0"))
5502
+ const amountDataArray = (0, import_utils27.arrayify)(
5503
+ "0x".concat((0, import_math19.bn)(amount).toHex().substring(2).padStart(16, "0"))
5258
5504
  );
5259
5505
  const script = new Uint8Array([
5260
- ...(0, import_utils28.arrayify)(withdrawScript.bytes),
5506
+ ...(0, import_utils27.arrayify)(withdrawScript.bytes),
5261
5507
  ...recipientDataArray,
5262
5508
  ...amountDataArray
5263
5509
  ]);
5264
- const params = { script, gasPrice: minGasPrice, ...txParams };
5510
+ const params = { script, ...txParams };
5511
+ const baseAssetId = this.provider.getBaseAssetId();
5265
5512
  const request = new ScriptTransactionRequest(params);
5266
- const forwardingQuantities = [{ amount: (0, import_math18.bn)(amount), assetId: import_configs12.BaseAssetId }];
5267
- const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
5268
- request,
5269
- forwardingQuantities
5270
- );
5271
- request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
5272
- this.validateGas({
5273
- gasUsed,
5274
- gasPrice: request.gasPrice,
5275
- gasLimit: request.gasLimit,
5276
- minGasPrice
5513
+ const quantitiesToContract = [{ amount: (0, import_math19.bn)(amount), assetId: baseAssetId }];
5514
+ const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
5515
+ this.validateGasLimitAndMaxFee({
5516
+ gasUsed: txCost.gasUsed,
5517
+ maxFee: txCost.maxFee,
5518
+ txParams
5277
5519
  });
5278
- await this.fund(request, requiredQuantities, maxFee);
5520
+ request.maxFee = txCost.maxFee;
5521
+ request.gasLimit = txCost.gasUsed;
5522
+ await this.fund(request, txCost);
5279
5523
  return this.sendTransaction(request);
5280
5524
  }
5281
5525
  async signMessage(message) {
@@ -5333,22 +5577,21 @@ var Account = class extends import_interfaces.AbstractAccount {
5333
5577
  }
5334
5578
  return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
5335
5579
  }
5336
- validateGas({
5580
+ validateGasLimitAndMaxFee({
5581
+ txParams: { gasLimit: setGasLimit, maxFee: setMaxFee },
5337
5582
  gasUsed,
5338
- gasPrice,
5339
- gasLimit,
5340
- minGasPrice
5583
+ maxFee
5341
5584
  }) {
5342
- if (minGasPrice.gt(gasPrice)) {
5585
+ if ((0, import_utils27.isDefined)(setGasLimit) && gasUsed.gt(setGasLimit)) {
5343
5586
  throw new import_errors16.FuelError(
5344
- import_errors16.ErrorCode.GAS_PRICE_TOO_LOW,
5345
- `Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
5587
+ import_errors16.ErrorCode.GAS_LIMIT_TOO_LOW,
5588
+ `Gas limit '${setGasLimit}' is lower than the required: '${gasUsed}'.`
5346
5589
  );
5347
5590
  }
5348
- if (gasUsed.gt(gasLimit)) {
5591
+ if ((0, import_utils27.isDefined)(setMaxFee) && maxFee.gt(setMaxFee)) {
5349
5592
  throw new import_errors16.FuelError(
5350
- import_errors16.ErrorCode.GAS_LIMIT_TOO_LOW,
5351
- `Gas limit '${gasLimit}' is lower than the required: '${gasUsed}'.`
5593
+ import_errors16.ErrorCode.MAX_FEE_TOO_LOW,
5594
+ `Max fee '${setMaxFee}' is lower than the required: '${maxFee}'.`
5352
5595
  );
5353
5596
  }
5354
5597
  }
@@ -5356,14 +5599,14 @@ var Account = class extends import_interfaces.AbstractAccount {
5356
5599
 
5357
5600
  // src/wallet/base-wallet-unlocked.ts
5358
5601
  var import_hasher3 = require("@fuel-ts/hasher");
5359
- var import_utils31 = require("@fuel-ts/utils");
5602
+ var import_utils30 = require("@fuel-ts/utils");
5360
5603
 
5361
5604
  // src/signer/signer.ts
5362
5605
  var import_address5 = require("@fuel-ts/address");
5363
5606
  var import_crypto2 = require("@fuel-ts/crypto");
5364
5607
  var import_hasher2 = require("@fuel-ts/hasher");
5365
- var import_math19 = require("@fuel-ts/math");
5366
- var import_utils29 = require("@fuel-ts/utils");
5608
+ var import_math20 = require("@fuel-ts/math");
5609
+ var import_utils28 = require("@fuel-ts/utils");
5367
5610
  var import_secp256k1 = require("@noble/curves/secp256k1");
5368
5611
  var Signer = class {
5369
5612
  address;
@@ -5382,10 +5625,10 @@ var Signer = class {
5382
5625
  privateKey = `0x${privateKey}`;
5383
5626
  }
5384
5627
  }
5385
- const privateKeyBytes = (0, import_math19.toBytes)(privateKey, 32);
5386
- this.privateKey = (0, import_utils29.hexlify)(privateKeyBytes);
5387
- this.publicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
5388
- this.compressedPublicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
5628
+ const privateKeyBytes = (0, import_math20.toBytes)(privateKey, 32);
5629
+ this.privateKey = (0, import_utils28.hexlify)(privateKeyBytes);
5630
+ this.publicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
5631
+ this.compressedPublicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
5389
5632
  this.address = import_address5.Address.fromPublicKey(this.publicKey);
5390
5633
  }
5391
5634
  /**
@@ -5399,11 +5642,11 @@ var Signer = class {
5399
5642
  * @returns hashed signature
5400
5643
  */
5401
5644
  sign(data) {
5402
- const signature = import_secp256k1.secp256k1.sign((0, import_utils29.arrayify)(data), (0, import_utils29.arrayify)(this.privateKey));
5403
- const r = (0, import_math19.toBytes)(`0x${signature.r.toString(16)}`, 32);
5404
- const s = (0, import_math19.toBytes)(`0x${signature.s.toString(16)}`, 32);
5645
+ const signature = import_secp256k1.secp256k1.sign((0, import_utils28.arrayify)(data), (0, import_utils28.arrayify)(this.privateKey));
5646
+ const r = (0, import_math20.toBytes)(`0x${signature.r.toString(16)}`, 32);
5647
+ const s = (0, import_math20.toBytes)(`0x${signature.s.toString(16)}`, 32);
5405
5648
  s[0] |= (signature.recovery || 0) << 7;
5406
- return (0, import_utils29.hexlify)((0, import_utils29.concat)([r, s]));
5649
+ return (0, import_utils28.hexlify)((0, import_utils28.concat)([r, s]));
5407
5650
  }
5408
5651
  /**
5409
5652
  * Add point on the current elliptic curve
@@ -5412,8 +5655,8 @@ var Signer = class {
5412
5655
  * @returns compressed point on the curve
5413
5656
  */
5414
5657
  addPoint(point) {
5415
- const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(this.compressedPublicKey));
5416
- const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(point));
5658
+ const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(this.compressedPublicKey));
5659
+ const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(point));
5417
5660
  const result = p0.add(p1);
5418
5661
  return `0x${result.toHex(true)}`;
5419
5662
  }
@@ -5425,16 +5668,16 @@ var Signer = class {
5425
5668
  * @returns public key from signature from the
5426
5669
  */
5427
5670
  static recoverPublicKey(data, signature) {
5428
- const signedMessageBytes = (0, import_utils29.arrayify)(signature);
5671
+ const signedMessageBytes = (0, import_utils28.arrayify)(signature);
5429
5672
  const r = signedMessageBytes.slice(0, 32);
5430
5673
  const s = signedMessageBytes.slice(32, 64);
5431
5674
  const recoveryParam = (s[0] & 128) >> 7;
5432
5675
  s[0] &= 127;
5433
- const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils29.hexlify)(r)), BigInt((0, import_utils29.hexlify)(s))).addRecoveryBit(
5676
+ const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils28.hexlify)(r)), BigInt((0, import_utils28.hexlify)(s))).addRecoveryBit(
5434
5677
  recoveryParam
5435
5678
  );
5436
- const publicKey = sig.recoverPublicKey((0, import_utils29.arrayify)(data)).toRawBytes(false).slice(1);
5437
- return (0, import_utils29.hexlify)(publicKey);
5679
+ const publicKey = sig.recoverPublicKey((0, import_utils28.arrayify)(data)).toRawBytes(false).slice(1);
5680
+ return (0, import_utils28.hexlify)(publicKey);
5438
5681
  }
5439
5682
  /**
5440
5683
  * Recover the address from a signature performed with [`sign`](#sign).
@@ -5453,7 +5696,7 @@ var Signer = class {
5453
5696
  * @returns random 32-byte hashed
5454
5697
  */
5455
5698
  static generatePrivateKey(entropy) {
5456
- 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);
5699
+ 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);
5457
5700
  }
5458
5701
  /**
5459
5702
  * Extended publicKey from a compact publicKey
@@ -5462,8 +5705,8 @@ var Signer = class {
5462
5705
  * @returns extended publicKey
5463
5706
  */
5464
5707
  static extendPublicKey(publicKey) {
5465
- const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(publicKey));
5466
- return (0, import_utils29.hexlify)(point.toRawBytes(false).slice(1));
5708
+ const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(publicKey));
5709
+ return (0, import_utils28.hexlify)(point.toRawBytes(false).slice(1));
5467
5710
  }
5468
5711
  };
5469
5712
 
@@ -5471,7 +5714,7 @@ var Signer = class {
5471
5714
  var import_address6 = require("@fuel-ts/address");
5472
5715
  var import_crypto3 = require("@fuel-ts/crypto");
5473
5716
  var import_errors17 = require("@fuel-ts/errors");
5474
- var import_utils30 = require("@fuel-ts/utils");
5717
+ var import_utils29 = require("@fuel-ts/utils");
5475
5718
  var import_uuid = require("uuid");
5476
5719
  var DEFAULT_KDF_PARAMS_LOG_N = 13;
5477
5720
  var DEFAULT_KDF_PARAMS_R = 8;
@@ -5554,7 +5797,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
5554
5797
  );
5555
5798
  }
5556
5799
  const buffer = await (0, import_crypto3.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
5557
- const privateKey = (0, import_utils30.hexlify)(buffer);
5800
+ const privateKey = (0, import_utils29.hexlify)(buffer);
5558
5801
  return privateKey;
5559
5802
  }
5560
5803
 
@@ -5599,7 +5842,7 @@ var BaseWalletUnlocked = class extends Account {
5599
5842
  */
5600
5843
  async signMessage(message) {
5601
5844
  const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
5602
- return (0, import_utils31.hexlify)(signedMessage);
5845
+ return (0, import_utils30.hexlify)(signedMessage);
5603
5846
  }
5604
5847
  /**
5605
5848
  * Signs a transaction with the wallet's private key.
@@ -5612,7 +5855,7 @@ var BaseWalletUnlocked = class extends Account {
5612
5855
  const chainId = this.provider.getChainId();
5613
5856
  const hashedTransaction = transactionRequest.getTransactionId(chainId);
5614
5857
  const signature = await this.signer().sign(hashedTransaction);
5615
- return (0, import_utils31.hexlify)(signature);
5858
+ return (0, import_utils30.hexlify)(signature);
5616
5859
  }
5617
5860
  /**
5618
5861
  * Populates a transaction with the witnesses signature.
@@ -5632,7 +5875,7 @@ var BaseWalletUnlocked = class extends Account {
5632
5875
  * @param transactionRequestLike - The transaction request to send.
5633
5876
  * @returns A promise that resolves to the TransactionResponse object.
5634
5877
  */
5635
- async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
5878
+ async sendTransaction(transactionRequestLike, { estimateTxDependencies = false, awaitExecution } = {}) {
5636
5879
  const transactionRequest = transactionRequestify(transactionRequestLike);
5637
5880
  if (estimateTxDependencies) {
5638
5881
  await this.provider.estimateTxDependencies(transactionRequest);
@@ -5673,15 +5916,15 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
5673
5916
  // src/hdwallet/hdwallet.ts
5674
5917
  var import_errors20 = require("@fuel-ts/errors");
5675
5918
  var import_hasher6 = require("@fuel-ts/hasher");
5676
- var import_math20 = require("@fuel-ts/math");
5677
- var import_utils35 = require("@fuel-ts/utils");
5919
+ var import_math21 = require("@fuel-ts/math");
5920
+ var import_utils34 = require("@fuel-ts/utils");
5678
5921
  var import_ethers3 = require("ethers");
5679
5922
 
5680
5923
  // src/mnemonic/mnemonic.ts
5681
5924
  var import_crypto4 = require("@fuel-ts/crypto");
5682
5925
  var import_errors19 = require("@fuel-ts/errors");
5683
5926
  var import_hasher5 = require("@fuel-ts/hasher");
5684
- var import_utils33 = require("@fuel-ts/utils");
5927
+ var import_utils32 = require("@fuel-ts/utils");
5685
5928
  var import_ethers2 = require("ethers");
5686
5929
 
5687
5930
  // src/wordlists/words/english.ts
@@ -7745,7 +7988,7 @@ var Language = /* @__PURE__ */ ((Language2) => {
7745
7988
  // src/mnemonic/utils.ts
7746
7989
  var import_errors18 = require("@fuel-ts/errors");
7747
7990
  var import_hasher4 = require("@fuel-ts/hasher");
7748
- var import_utils32 = require("@fuel-ts/utils");
7991
+ var import_utils31 = require("@fuel-ts/utils");
7749
7992
  function toUtf8Bytes(stri) {
7750
7993
  const str = stri.normalize("NFKD");
7751
7994
  const result = [];
@@ -7812,14 +8055,14 @@ function entropyToMnemonicIndices(entropy) {
7812
8055
  }
7813
8056
  }
7814
8057
  const checksumBits = entropy.length / 4;
7815
- const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
8058
+ const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
7816
8059
  indices[indices.length - 1] <<= checksumBits;
7817
8060
  indices[indices.length - 1] |= checksum >> 8 - checksumBits;
7818
8061
  return indices;
7819
8062
  }
7820
8063
  function mnemonicWordsToEntropy(words, wordlist) {
7821
8064
  const size = Math.ceil(11 * words.length / 8);
7822
- const entropy = (0, import_utils32.arrayify)(new Uint8Array(size));
8065
+ const entropy = (0, import_utils31.arrayify)(new Uint8Array(size));
7823
8066
  let offset = 0;
7824
8067
  for (let i = 0; i < words.length; i += 1) {
7825
8068
  const index = wordlist.indexOf(words[i].normalize("NFKD"));
@@ -7839,7 +8082,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
7839
8082
  const entropyBits = 32 * words.length / 3;
7840
8083
  const checksumBits = words.length / 3;
7841
8084
  const checksumMask = getUpperMask(checksumBits);
7842
- const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
8085
+ const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
7843
8086
  if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
7844
8087
  throw new import_errors18.FuelError(
7845
8088
  import_errors18.ErrorCode.INVALID_CHECKSUM,
@@ -7914,7 +8157,7 @@ var Mnemonic = class {
7914
8157
  static mnemonicToEntropy(phrase, wordlist = english) {
7915
8158
  const words = getWords(phrase);
7916
8159
  assertMnemonic(words);
7917
- return (0, import_utils33.hexlify)(mnemonicWordsToEntropy(words, wordlist));
8160
+ return (0, import_utils32.hexlify)(mnemonicWordsToEntropy(words, wordlist));
7918
8161
  }
7919
8162
  /**
7920
8163
  * @param entropy - Entropy source to the mnemonic phrase.
@@ -7922,7 +8165,7 @@ var Mnemonic = class {
7922
8165
  * @returns 64-byte array contains privateKey and chainCode as described on BIP39
7923
8166
  */
7924
8167
  static entropyToMnemonic(entropy, wordlist = english) {
7925
- const entropyBytes = (0, import_utils33.arrayify)(entropy);
8168
+ const entropyBytes = (0, import_utils32.arrayify)(entropy);
7926
8169
  assertWordList(wordlist);
7927
8170
  assertEntropy(entropyBytes);
7928
8171
  return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
@@ -7991,14 +8234,14 @@ var Mnemonic = class {
7991
8234
  * @returns 64-byte array contains privateKey and chainCode as described on BIP39
7992
8235
  */
7993
8236
  static masterKeysFromSeed(seed) {
7994
- const seedArray = (0, import_utils33.arrayify)(seed);
8237
+ const seedArray = (0, import_utils32.arrayify)(seed);
7995
8238
  if (seedArray.length < 16 || seedArray.length > 64) {
7996
8239
  throw new import_errors19.FuelError(
7997
8240
  import_errors19.ErrorCode.INVALID_SEED,
7998
8241
  `Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
7999
8242
  );
8000
8243
  }
8001
- return (0, import_utils33.arrayify)((0, import_ethers2.computeHmac)("sha512", MasterSecret, seedArray));
8244
+ return (0, import_utils32.arrayify)((0, import_ethers2.computeHmac)("sha512", MasterSecret, seedArray));
8002
8245
  }
8003
8246
  /**
8004
8247
  * Get the extendKey as defined on BIP-32 from the provided seed
@@ -8009,22 +8252,22 @@ var Mnemonic = class {
8009
8252
  */
8010
8253
  static seedToExtendedKey(seed, testnet = false) {
8011
8254
  const masterKey = Mnemonic.masterKeysFromSeed(seed);
8012
- const prefix = (0, import_utils33.arrayify)(testnet ? TestnetPRV : MainnetPRV);
8255
+ const prefix = (0, import_utils32.arrayify)(testnet ? TestnetPRV : MainnetPRV);
8013
8256
  const depth = "0x00";
8014
8257
  const fingerprint = "0x00000000";
8015
8258
  const index = "0x00000000";
8016
8259
  const chainCode = masterKey.slice(32);
8017
8260
  const privateKey = masterKey.slice(0, 32);
8018
- const extendedKey = (0, import_utils33.concat)([
8261
+ const extendedKey = (0, import_utils32.concat)([
8019
8262
  prefix,
8020
8263
  depth,
8021
8264
  fingerprint,
8022
8265
  index,
8023
8266
  chainCode,
8024
- (0, import_utils33.concat)(["0x00", privateKey])
8267
+ (0, import_utils32.concat)(["0x00", privateKey])
8025
8268
  ]);
8026
8269
  const checksum = (0, import_ethers2.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
8027
- return (0, import_ethers2.encodeBase58)((0, import_utils33.concat)([extendedKey, checksum]));
8270
+ return (0, import_ethers2.encodeBase58)((0, import_utils32.concat)([extendedKey, checksum]));
8028
8271
  }
8029
8272
  /**
8030
8273
  * Create a new mnemonic using a randomly generated number as entropy.
@@ -8039,7 +8282,7 @@ var Mnemonic = class {
8039
8282
  * @returns A randomly generated mnemonic
8040
8283
  */
8041
8284
  static generate(size = 32, extraEntropy = "") {
8042
- 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);
8285
+ 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);
8043
8286
  return Mnemonic.entropyToMnemonic(entropy);
8044
8287
  }
8045
8288
  };
@@ -8047,12 +8290,12 @@ var mnemonic_default = Mnemonic;
8047
8290
 
8048
8291
  // src/hdwallet/hdwallet.ts
8049
8292
  var HARDENED_INDEX = 2147483648;
8050
- var MainnetPRV2 = (0, import_utils35.hexlify)("0x0488ade4");
8051
- var MainnetPUB = (0, import_utils35.hexlify)("0x0488b21e");
8052
- var TestnetPRV2 = (0, import_utils35.hexlify)("0x04358394");
8053
- var TestnetPUB = (0, import_utils35.hexlify)("0x043587cf");
8293
+ var MainnetPRV2 = (0, import_utils34.hexlify)("0x0488ade4");
8294
+ var MainnetPUB = (0, import_utils34.hexlify)("0x0488b21e");
8295
+ var TestnetPRV2 = (0, import_utils34.hexlify)("0x04358394");
8296
+ var TestnetPUB = (0, import_utils34.hexlify)("0x043587cf");
8054
8297
  function base58check(data) {
8055
- 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)]));
8298
+ 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)]));
8056
8299
  }
8057
8300
  function getExtendedKeyPrefix(isPublic = false, testnet = false) {
8058
8301
  if (isPublic) {
@@ -8061,11 +8304,11 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
8061
8304
  return testnet ? TestnetPRV2 : MainnetPRV2;
8062
8305
  }
8063
8306
  function isPublicExtendedKey(extendedKey) {
8064
- return [MainnetPUB, TestnetPUB].includes((0, import_utils35.hexlify)(extendedKey.slice(0, 4)));
8307
+ return [MainnetPUB, TestnetPUB].includes((0, import_utils34.hexlify)(extendedKey.slice(0, 4)));
8065
8308
  }
8066
8309
  function isValidExtendedKey(extendedKey) {
8067
8310
  return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
8068
- (0, import_utils35.hexlify)(extendedKey.slice(0, 4))
8311
+ (0, import_utils34.hexlify)(extendedKey.slice(0, 4))
8069
8312
  );
8070
8313
  }
8071
8314
  function parsePath(path, depth = 0) {
@@ -8083,8 +8326,8 @@ function parsePath(path, depth = 0) {
8083
8326
  var HDWallet = class {
8084
8327
  depth = 0;
8085
8328
  index = 0;
8086
- fingerprint = (0, import_utils35.hexlify)("0x00000000");
8087
- parentFingerprint = (0, import_utils35.hexlify)("0x00000000");
8329
+ fingerprint = (0, import_utils34.hexlify)("0x00000000");
8330
+ parentFingerprint = (0, import_utils34.hexlify)("0x00000000");
8088
8331
  privateKey;
8089
8332
  publicKey;
8090
8333
  chainCode;
@@ -8096,8 +8339,8 @@ var HDWallet = class {
8096
8339
  constructor(config) {
8097
8340
  if (config.privateKey) {
8098
8341
  const signer = new Signer(config.privateKey);
8099
- this.publicKey = (0, import_utils35.hexlify)(signer.compressedPublicKey);
8100
- this.privateKey = (0, import_utils35.hexlify)(config.privateKey);
8342
+ this.publicKey = (0, import_utils34.hexlify)(signer.compressedPublicKey);
8343
+ this.privateKey = (0, import_utils34.hexlify)(config.privateKey);
8101
8344
  } else {
8102
8345
  if (!config.publicKey) {
8103
8346
  throw new import_errors20.FuelError(
@@ -8105,7 +8348,7 @@ var HDWallet = class {
8105
8348
  "Both public and private Key cannot be missing. At least one should be provided."
8106
8349
  );
8107
8350
  }
8108
- this.publicKey = (0, import_utils35.hexlify)(config.publicKey);
8351
+ this.publicKey = (0, import_utils34.hexlify)(config.publicKey);
8109
8352
  }
8110
8353
  this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
8111
8354
  this.fingerprint = (0, import_ethers3.dataSlice)((0, import_ethers3.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
@@ -8124,9 +8367,9 @@ var HDWallet = class {
8124
8367
  * @returns A new instance of HDWallet on the derived index
8125
8368
  */
8126
8369
  deriveIndex(index) {
8127
- const privateKey = this.privateKey && (0, import_utils35.arrayify)(this.privateKey);
8128
- const publicKey = (0, import_utils35.arrayify)(this.publicKey);
8129
- const chainCode = (0, import_utils35.arrayify)(this.chainCode);
8370
+ const privateKey = this.privateKey && (0, import_utils34.arrayify)(this.privateKey);
8371
+ const publicKey = (0, import_utils34.arrayify)(this.publicKey);
8372
+ const chainCode = (0, import_utils34.arrayify)(this.chainCode);
8130
8373
  const data = new Uint8Array(37);
8131
8374
  if (index & HARDENED_INDEX) {
8132
8375
  if (!privateKey) {
@@ -8137,15 +8380,15 @@ var HDWallet = class {
8137
8380
  }
8138
8381
  data.set(privateKey, 1);
8139
8382
  } else {
8140
- data.set((0, import_utils35.arrayify)(this.publicKey));
8383
+ data.set((0, import_utils34.arrayify)(this.publicKey));
8141
8384
  }
8142
- data.set((0, import_math20.toBytes)(index, 4), 33);
8143
- const bytes = (0, import_utils35.arrayify)((0, import_ethers3.computeHmac)("sha512", chainCode, data));
8385
+ data.set((0, import_math21.toBytes)(index, 4), 33);
8386
+ const bytes = (0, import_utils34.arrayify)((0, import_ethers3.computeHmac)("sha512", chainCode, data));
8144
8387
  const IL = bytes.slice(0, 32);
8145
8388
  const IR = bytes.slice(32);
8146
8389
  if (privateKey) {
8147
8390
  const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
8148
- const ki = (0, import_math20.bn)(IL).add(privateKey).mod(N).toBytes(32);
8391
+ const ki = (0, import_math21.bn)(IL).add(privateKey).mod(N).toBytes(32);
8149
8392
  return new HDWallet({
8150
8393
  privateKey: ki,
8151
8394
  chainCode: IR,
@@ -8154,7 +8397,7 @@ var HDWallet = class {
8154
8397
  parentFingerprint: this.fingerprint
8155
8398
  });
8156
8399
  }
8157
- const signer = new Signer((0, import_utils35.hexlify)(IL));
8400
+ const signer = new Signer((0, import_utils34.hexlify)(IL));
8158
8401
  const Ki = signer.addPoint(publicKey);
8159
8402
  return new HDWallet({
8160
8403
  publicKey: Ki,
@@ -8189,12 +8432,12 @@ var HDWallet = class {
8189
8432
  );
8190
8433
  }
8191
8434
  const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
8192
- const depth = (0, import_utils35.hexlify)(Uint8Array.from([this.depth]));
8435
+ const depth = (0, import_utils34.hexlify)(Uint8Array.from([this.depth]));
8193
8436
  const parentFingerprint = this.parentFingerprint;
8194
- const index = (0, import_math20.toHex)(this.index, 4);
8437
+ const index = (0, import_math21.toHex)(this.index, 4);
8195
8438
  const chainCode = this.chainCode;
8196
- const key = this.privateKey != null && !isPublic ? (0, import_utils35.concat)(["0x00", this.privateKey]) : this.publicKey;
8197
- const extendedKey = (0, import_utils35.arrayify)((0, import_utils35.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
8439
+ const key = this.privateKey != null && !isPublic ? (0, import_utils34.concat)(["0x00", this.privateKey]) : this.publicKey;
8440
+ const extendedKey = (0, import_utils34.arrayify)((0, import_utils34.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
8198
8441
  return base58check(extendedKey);
8199
8442
  }
8200
8443
  /**
@@ -8206,13 +8449,13 @@ var HDWallet = class {
8206
8449
  static fromSeed(seed) {
8207
8450
  const masterKey = mnemonic_default.masterKeysFromSeed(seed);
8208
8451
  return new HDWallet({
8209
- chainCode: (0, import_utils35.arrayify)(masterKey.slice(32)),
8210
- privateKey: (0, import_utils35.arrayify)(masterKey.slice(0, 32))
8452
+ chainCode: (0, import_utils34.arrayify)(masterKey.slice(32)),
8453
+ privateKey: (0, import_utils34.arrayify)(masterKey.slice(0, 32))
8211
8454
  });
8212
8455
  }
8213
8456
  static fromExtendedKey(extendedKey) {
8214
8457
  const decoded = (0, import_ethers3.toBeHex)((0, import_ethers3.decodeBase58)(extendedKey));
8215
- const bytes = (0, import_utils35.arrayify)(decoded);
8458
+ const bytes = (0, import_utils34.arrayify)(decoded);
8216
8459
  const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
8217
8460
  if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
8218
8461
  throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
@@ -8221,9 +8464,9 @@ var HDWallet = class {
8221
8464
  throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
8222
8465
  }
8223
8466
  const depth = bytes[4];
8224
- const parentFingerprint = (0, import_utils35.hexlify)(bytes.slice(5, 9));
8225
- const index = parseInt((0, import_utils35.hexlify)(bytes.slice(9, 13)).substring(2), 16);
8226
- const chainCode = (0, import_utils35.hexlify)(bytes.slice(13, 45));
8467
+ const parentFingerprint = (0, import_utils34.hexlify)(bytes.slice(5, 9));
8468
+ const index = parseInt((0, import_utils34.hexlify)(bytes.slice(9, 13)).substring(2), 16);
8469
+ const chainCode = (0, import_utils34.hexlify)(bytes.slice(13, 45));
8227
8470
  const key = bytes.slice(45, 78);
8228
8471
  if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
8229
8472
  throw new import_errors20.FuelError(
@@ -8826,21 +9069,20 @@ var StorageAbstract = class {
8826
9069
  // src/predicate/predicate.ts
8827
9070
  var import_abi_coder7 = require("@fuel-ts/abi-coder");
8828
9071
  var import_address10 = require("@fuel-ts/address");
8829
- var import_configs13 = require("@fuel-ts/address/configs");
8830
9072
  var import_errors25 = require("@fuel-ts/errors");
8831
- var import_transactions20 = require("@fuel-ts/transactions");
8832
- var import_utils37 = require("@fuel-ts/utils");
9073
+ var import_transactions21 = require("@fuel-ts/transactions");
9074
+ var import_utils36 = require("@fuel-ts/utils");
8833
9075
 
8834
9076
  // src/predicate/utils/getPredicateRoot.ts
8835
9077
  var import_hasher7 = require("@fuel-ts/hasher");
8836
9078
  var import_merkle = require("@fuel-ts/merkle");
8837
- var import_utils36 = require("@fuel-ts/utils");
9079
+ var import_utils35 = require("@fuel-ts/utils");
8838
9080
  var getPredicateRoot = (bytecode) => {
8839
9081
  const chunkSize = 16 * 1024;
8840
- const bytes = (0, import_utils36.arrayify)(bytecode);
8841
- const chunks = (0, import_utils36.chunkAndPadBytes)(bytes, chunkSize);
8842
- const codeRoot = (0, import_merkle.calcRoot)(chunks.map((c) => (0, import_utils36.hexlify)(c)));
8843
- const predicateRoot = (0, import_hasher7.hash)((0, import_utils36.concat)(["0x4655454C", codeRoot]));
9082
+ const bytes = (0, import_utils35.arrayify)(bytecode);
9083
+ const chunks = (0, import_utils35.chunkAndPadBytes)(bytes, chunkSize);
9084
+ const codeRoot = (0, import_merkle.calcRoot)(chunks.map((c) => (0, import_utils35.hexlify)(c)));
9085
+ const predicateRoot = (0, import_hasher7.hash)((0, import_utils35.concat)(["0x4655454C", codeRoot]));
8844
9086
  return predicateRoot;
8845
9087
  };
8846
9088
 
@@ -8888,35 +9130,22 @@ var Predicate = class extends Account {
8888
9130
  const request = transactionRequestify(transactionRequestLike);
8889
9131
  const { policies } = BaseTransactionRequest.getPolicyMeta(request);
8890
9132
  request.inputs?.forEach((input) => {
8891
- if (input.type === import_transactions20.InputType.Coin && (0, import_utils37.hexlify)(input.owner) === this.address.toB256()) {
8892
- input.predicate = this.bytes;
8893
- input.predicateData = this.getPredicateData(policies.length);
9133
+ if (input.type === import_transactions21.InputType.Coin && (0, import_utils36.hexlify)(input.owner) === this.address.toB256()) {
9134
+ input.predicate = (0, import_utils36.hexlify)(this.bytes);
9135
+ input.predicateData = (0, import_utils36.hexlify)(this.getPredicateData(policies.length));
8894
9136
  }
8895
9137
  });
8896
9138
  return request;
8897
9139
  }
8898
- /**
8899
- * A helper that creates a transfer transaction request and returns it.
8900
- *
8901
- * @param destination - The address of the destination.
8902
- * @param amount - The amount of coins to transfer.
8903
- * @param assetId - The asset ID of the coins to transfer.
8904
- * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
8905
- * @returns A promise that resolves to the prepared transaction request.
8906
- */
8907
- async createTransfer(destination, amount, assetId = import_configs13.BaseAssetId, txParams = {}) {
8908
- const request = await super.createTransfer(destination, amount, assetId, txParams);
8909
- return this.populateTransactionPredicateData(request);
8910
- }
8911
9140
  /**
8912
9141
  * Sends a transaction with the populated predicate data.
8913
9142
  *
8914
9143
  * @param transactionRequestLike - The transaction request-like object.
8915
9144
  * @returns A promise that resolves to the transaction response.
8916
9145
  */
8917
- sendTransaction(transactionRequestLike, options) {
8918
- const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
8919
- return super.sendTransaction(transactionRequest, options);
9146
+ sendTransaction(transactionRequestLike) {
9147
+ const transactionRequest = transactionRequestify(transactionRequestLike);
9148
+ return super.sendTransaction(transactionRequest, { estimateTxDependencies: false });
8920
9149
  }
8921
9150
  /**
8922
9151
  * Simulates a transaction with the populated predicate data.
@@ -8925,15 +9154,15 @@ var Predicate = class extends Account {
8925
9154
  * @returns A promise that resolves to the call result.
8926
9155
  */
8927
9156
  simulateTransaction(transactionRequestLike) {
8928
- const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
8929
- return super.simulateTransaction(transactionRequest);
9157
+ const transactionRequest = transactionRequestify(transactionRequestLike);
9158
+ return super.simulateTransaction(transactionRequest, { estimateTxDependencies: false });
8930
9159
  }
8931
9160
  getPredicateData(policiesLength) {
8932
9161
  if (!this.predicateData.length) {
8933
9162
  return new Uint8Array();
8934
9163
  }
8935
9164
  const mainFn = this.interface?.functions.main;
8936
- const paddedCode = new import_transactions20.ByteArrayCoder(this.bytes.length).encode(this.bytes);
9165
+ const paddedCode = new import_transactions21.ByteArrayCoder(this.bytes.length).encode(this.bytes);
8937
9166
  const VM_TX_MEMORY = (0, import_abi_coder7.calculateVmTxMemory)({
8938
9167
  maxInputs: this.provider.getChain().consensusParameters.maxInputs.toNumber()
8939
9168
  });
@@ -8949,7 +9178,7 @@ var Predicate = class extends Account {
8949
9178
  * @returns An object containing the new predicate bytes and interface.
8950
9179
  */
8951
9180
  static processPredicateData(bytes, jsonAbi, configurableConstants) {
8952
- let predicateBytes = (0, import_utils37.arrayify)(bytes);
9181
+ let predicateBytes = (0, import_utils36.arrayify)(bytes);
8953
9182
  let abiInterface;
8954
9183
  if (jsonAbi) {
8955
9184
  abiInterface = new import_abi_coder7.Interface(jsonAbi);
@@ -8972,6 +9201,25 @@ var Predicate = class extends Account {
8972
9201
  predicateInterface: abiInterface
8973
9202
  };
8974
9203
  }
9204
+ /**
9205
+ * Retrieves resources satisfying the spend query for the account.
9206
+ *
9207
+ * @param quantities - IDs of coins to exclude.
9208
+ * @param excludedIds - IDs of resources to be excluded from the query.
9209
+ * @returns A promise that resolves to an array of Resources.
9210
+ */
9211
+ async getResourcesToSpend(quantities, excludedIds) {
9212
+ const resources = await this.provider.getResourcesToSpend(
9213
+ this.address,
9214
+ quantities,
9215
+ excludedIds
9216
+ );
9217
+ return resources.map((resource) => ({
9218
+ ...resource,
9219
+ predicate: (0, import_utils36.hexlify)(this.bytes),
9220
+ padPredicateData: (policiesLength) => (0, import_utils36.hexlify)(this.getPredicateData(policiesLength))
9221
+ }));
9222
+ }
8975
9223
  /**
8976
9224
  * Sets the configurable constants for the predicate.
8977
9225
  *
@@ -9721,7 +9969,7 @@ __publicField(Fuel, "defaultConfig", {});
9721
9969
  WalletLocked,
9722
9970
  WalletManager,
9723
9971
  WalletUnlocked,
9724
- addAmountToAsset,
9972
+ addAmountToCoinQuantities,
9725
9973
  addOperation,
9726
9974
  assemblePanicError,
9727
9975
  assembleReceiptByType,
@@ -9730,9 +9978,10 @@ __publicField(Fuel, "defaultConfig", {});
9730
9978
  assets,
9731
9979
  buildBlockExplorerUrl,
9732
9980
  cacheFor,
9981
+ cacheTxInputsFromOwner,
9982
+ calculateGasFee,
9733
9983
  calculateMetadataGasForTxCreate,
9734
9984
  calculateMetadataGasForTxScript,
9735
- calculatePriceWithFactor,
9736
9985
  calculateTransactionFee,
9737
9986
  coinQuantityfy,
9738
9987
  deferPromise,