@fuel-ts/account 0.82.0 → 0.84.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 (76) hide show
  1. package/README.md +18 -15
  2. package/dist/account.d.ts +8 -7
  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 +2445 -2185
  12. package/dist/index.global.js.map +1 -1
  13. package/dist/index.js +1074 -667
  14. package/dist/index.js.map +1 -1
  15. package/dist/index.mjs +909 -505
  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 +950 -376
  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 +9 -3
  26. package/dist/providers/message.d.ts.map +1 -1
  27. package/dist/providers/provider.d.ts +72 -54
  28. package/dist/providers/provider.d.ts.map +1 -1
  29. package/dist/providers/resource.d.ts +0 -1
  30. package/dist/providers/resource.d.ts.map +1 -1
  31. package/dist/providers/transaction-request/create-transaction-request.d.ts +1 -1
  32. package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
  33. package/dist/providers/transaction-request/helpers.d.ts +8 -0
  34. package/dist/providers/transaction-request/helpers.d.ts.map +1 -0
  35. package/dist/providers/transaction-request/input.d.ts +2 -2
  36. package/dist/providers/transaction-request/input.d.ts.map +1 -1
  37. package/dist/providers/transaction-request/script-transaction-request.d.ts +2 -3
  38. package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
  39. package/dist/providers/transaction-request/transaction-request.d.ts +17 -38
  40. package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
  41. package/dist/providers/transaction-request/utils.d.ts +4 -0
  42. package/dist/providers/transaction-request/utils.d.ts.map +1 -1
  43. package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
  44. package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts +4 -2
  45. package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
  46. package/dist/providers/transaction-summary/calculate-tx-fee-for-summary.d.ts +20 -0
  47. package/dist/providers/transaction-summary/calculate-tx-fee-for-summary.d.ts.map +1 -0
  48. package/dist/providers/transaction-summary/get-transaction-summary.d.ts.map +1 -1
  49. package/dist/providers/transaction-summary/index.d.ts +1 -1
  50. package/dist/providers/transaction-summary/index.d.ts.map +1 -1
  51. package/dist/providers/transaction-summary/operations.d.ts +4 -0
  52. package/dist/providers/transaction-summary/operations.d.ts.map +1 -1
  53. package/dist/providers/transaction-summary/status.d.ts +5 -1
  54. package/dist/providers/transaction-summary/status.d.ts.map +1 -1
  55. package/dist/providers/transaction-summary/types.d.ts +6 -1
  56. package/dist/providers/transaction-summary/types.d.ts.map +1 -1
  57. package/dist/providers/utils/gas.d.ts +14 -7
  58. package/dist/providers/utils/gas.d.ts.map +1 -1
  59. package/dist/providers/utils/merge-quantities.d.ts +1 -1
  60. package/dist/providers/utils/merge-quantities.d.ts.map +1 -1
  61. package/dist/test-utils/launchNode.d.ts +1 -1
  62. package/dist/test-utils/launchNode.d.ts.map +1 -1
  63. package/dist/test-utils/resources.d.ts +4 -0
  64. package/dist/test-utils/resources.d.ts.map +1 -0
  65. package/dist/test-utils/transactionRequest.d.ts +5 -0
  66. package/dist/test-utils/transactionRequest.d.ts.map +1 -0
  67. package/dist/test-utils.global.js +3171 -2680
  68. package/dist/test-utils.global.js.map +1 -1
  69. package/dist/test-utils.js +1046 -655
  70. package/dist/test-utils.js.map +1 -1
  71. package/dist/test-utils.mjs +896 -505
  72. package/dist/test-utils.mjs.map +1 -1
  73. package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
  74. package/package.json +18 -18
  75. package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts +0 -21
  76. package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts.map +0 -1
@@ -58,41 +58,40 @@ module.exports = __toCommonJS(test_utils_exports);
58
58
 
59
59
  // src/wallet/base-wallet-unlocked.ts
60
60
  var import_hasher3 = require("@fuel-ts/hasher");
61
- var import_utils31 = require("@fuel-ts/utils");
61
+ var import_utils30 = require("@fuel-ts/utils");
62
62
 
63
63
  // src/account.ts
64
64
  var import_address4 = require("@fuel-ts/address");
65
- var import_configs12 = require("@fuel-ts/address/configs");
66
65
  var import_errors16 = require("@fuel-ts/errors");
67
66
  var import_interfaces = require("@fuel-ts/interfaces");
68
- var import_math18 = require("@fuel-ts/math");
69
- var import_utils28 = require("@fuel-ts/utils");
67
+ var import_math21 = require("@fuel-ts/math");
68
+ var import_utils27 = require("@fuel-ts/utils");
69
+ var import_ramda4 = require("ramda");
70
70
 
71
71
  // src/providers/coin-quantity.ts
72
- var import_configs = require("@fuel-ts/address/configs");
73
72
  var import_math = require("@fuel-ts/math");
74
73
  var import_utils = require("@fuel-ts/utils");
75
74
  var coinQuantityfy = (coinQuantityLike) => {
76
75
  let assetId;
77
76
  let amount;
78
- let max2;
77
+ let max;
79
78
  if (Array.isArray(coinQuantityLike)) {
80
79
  amount = coinQuantityLike[0];
81
- assetId = coinQuantityLike[1] ?? import_configs.BaseAssetId;
82
- max2 = coinQuantityLike[2] ?? void 0;
80
+ assetId = coinQuantityLike[1];
81
+ max = coinQuantityLike[2] ?? void 0;
83
82
  } else {
84
83
  amount = coinQuantityLike.amount;
85
- assetId = coinQuantityLike.assetId ?? import_configs.BaseAssetId;
86
- max2 = coinQuantityLike.max ?? void 0;
84
+ assetId = coinQuantityLike.assetId;
85
+ max = coinQuantityLike.max ?? void 0;
87
86
  }
88
87
  const bnAmount = (0, import_math.bn)(amount);
89
88
  return {
90
89
  assetId: (0, import_utils.hexlify)(assetId),
91
90
  amount: bnAmount.lt(1) ? (0, import_math.bn)(1) : bnAmount,
92
- max: max2 ? (0, import_math.bn)(max2) : void 0
91
+ max: max ? (0, import_math.bn)(max) : void 0
93
92
  };
94
93
  };
95
- var addAmountToAsset = (params) => {
94
+ var addAmountToCoinQuantities = (params) => {
96
95
  const { amount, assetId } = params;
97
96
  const coinQuantities = [...params.coinQuantities];
98
97
  const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
@@ -107,27 +106,30 @@ var addAmountToAsset = (params) => {
107
106
  // src/providers/provider.ts
108
107
  var import_address3 = require("@fuel-ts/address");
109
108
  var import_errors14 = require("@fuel-ts/errors");
110
- var import_math15 = require("@fuel-ts/math");
111
- var import_transactions18 = require("@fuel-ts/transactions");
112
- var import_utils23 = require("@fuel-ts/utils");
109
+ var import_math17 = require("@fuel-ts/math");
110
+ var import_transactions19 = require("@fuel-ts/transactions");
111
+ var import_utils22 = require("@fuel-ts/utils");
113
112
  var import_versions = require("@fuel-ts/versions");
114
- var import_utils24 = require("@noble/curves/abstract/utils");
115
- var import_ethers = require("ethers");
113
+ var import_utils23 = require("@noble/curves/abstract/utils");
116
114
  var import_graphql_request = require("graphql-request");
117
115
  var import_ramda3 = require("ramda");
118
116
 
119
117
  // src/providers/__generated__/operations.ts
120
118
  var import_graphql_tag = __toESM(require("graphql-tag"));
119
+ var TransactionStatusSubscriptionFragmentFragmentDoc = import_graphql_tag.default`
120
+ fragment transactionStatusSubscriptionFragment on TransactionStatus {
121
+ type: __typename
122
+ ... on SqueezedOutStatus {
123
+ reason
124
+ }
125
+ }
126
+ `;
121
127
  var ReceiptFragmentFragmentDoc = import_graphql_tag.default`
122
128
  fragment receiptFragment on Receipt {
123
- contract {
124
- id
125
- }
129
+ id
126
130
  pc
127
131
  is
128
- to {
129
- id
130
- }
132
+ to
131
133
  toAddress
132
134
  amount
133
135
  assetId
@@ -169,33 +171,38 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
169
171
  returnType
170
172
  data
171
173
  }
174
+ receipts {
175
+ ...receiptFragment
176
+ }
177
+ totalGas
178
+ totalFee
172
179
  }
173
180
  ... on FailureStatus {
174
181
  block {
175
182
  id
176
183
  }
184
+ totalGas
185
+ totalFee
177
186
  time
178
187
  reason
188
+ receipts {
189
+ ...receiptFragment
190
+ }
179
191
  }
180
192
  ... on SqueezedOutStatus {
181
193
  reason
182
194
  }
183
195
  }
184
- `;
196
+ ${ReceiptFragmentFragmentDoc}`;
185
197
  var TransactionFragmentFragmentDoc = import_graphql_tag.default`
186
198
  fragment transactionFragment on Transaction {
187
199
  id
188
200
  rawPayload
189
- gasPrice
190
- receipts {
191
- ...receiptFragment
192
- }
193
201
  status {
194
202
  ...transactionStatusFragment
195
203
  }
196
204
  }
197
- ${ReceiptFragmentFragmentDoc}
198
- ${TransactionStatusFragmentFragmentDoc}`;
205
+ ${TransactionStatusFragmentFragmentDoc}`;
199
206
  var InputEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.default`
200
207
  fragment inputEstimatePredicatesFragment on Input {
201
208
  ... on InputCoin {
@@ -213,6 +220,50 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.defaul
213
220
  }
214
221
  }
215
222
  ${InputEstimatePredicatesFragmentFragmentDoc}`;
223
+ var DryRunFailureStatusFragmentFragmentDoc = import_graphql_tag.default`
224
+ fragment dryRunFailureStatusFragment on DryRunFailureStatus {
225
+ totalGas
226
+ totalFee
227
+ reason
228
+ programState {
229
+ returnType
230
+ data
231
+ }
232
+ }
233
+ `;
234
+ var DryRunSuccessStatusFragmentFragmentDoc = import_graphql_tag.default`
235
+ fragment dryRunSuccessStatusFragment on DryRunSuccessStatus {
236
+ totalGas
237
+ totalFee
238
+ programState {
239
+ returnType
240
+ data
241
+ }
242
+ }
243
+ `;
244
+ var DryRunTransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
245
+ fragment dryRunTransactionStatusFragment on DryRunTransactionStatus {
246
+ ... on DryRunFailureStatus {
247
+ ...dryRunFailureStatusFragment
248
+ }
249
+ ... on DryRunSuccessStatus {
250
+ ...dryRunSuccessStatusFragment
251
+ }
252
+ }
253
+ ${DryRunFailureStatusFragmentFragmentDoc}
254
+ ${DryRunSuccessStatusFragmentFragmentDoc}`;
255
+ var DryRunTransactionExecutionStatusFragmentFragmentDoc = import_graphql_tag.default`
256
+ fragment dryRunTransactionExecutionStatusFragment on DryRunTransactionExecutionStatus {
257
+ id
258
+ status {
259
+ ...dryRunTransactionStatusFragment
260
+ }
261
+ receipts {
262
+ ...receiptFragment
263
+ }
264
+ }
265
+ ${DryRunTransactionStatusFragmentFragmentDoc}
266
+ ${ReceiptFragmentFragmentDoc}`;
216
267
  var CoinFragmentFragmentDoc = import_graphql_tag.default`
217
268
  fragment coinFragment on Coin {
218
269
  __typename
@@ -220,7 +271,6 @@ var CoinFragmentFragmentDoc = import_graphql_tag.default`
220
271
  owner
221
272
  amount
222
273
  assetId
223
- maturity
224
274
  blockCreated
225
275
  txCreatedIdx
226
276
  }
@@ -259,26 +309,32 @@ var MessageProofFragmentFragmentDoc = import_graphql_tag.default`
259
309
  messageBlockHeader {
260
310
  id
261
311
  daHeight
312
+ consensusParametersVersion
313
+ stateTransitionBytecodeVersion
262
314
  transactionsCount
315
+ messageReceiptCount
263
316
  transactionsRoot
317
+ messageOutboxRoot
318
+ eventInboxRoot
264
319
  height
265
320
  prevRoot
266
321
  time
267
322
  applicationHash
268
- messageReceiptRoot
269
- messageReceiptCount
270
323
  }
271
324
  commitBlockHeader {
272
325
  id
273
326
  daHeight
327
+ consensusParametersVersion
328
+ stateTransitionBytecodeVersion
274
329
  transactionsCount
330
+ messageReceiptCount
275
331
  transactionsRoot
332
+ messageOutboxRoot
333
+ eventInboxRoot
276
334
  height
277
335
  prevRoot
278
336
  time
279
337
  applicationHash
280
- messageReceiptRoot
281
- messageReceiptCount
282
338
  }
283
339
  sender
284
340
  recipient
@@ -297,8 +353,8 @@ var BalanceFragmentFragmentDoc = import_graphql_tag.default`
297
353
  var BlockFragmentFragmentDoc = import_graphql_tag.default`
298
354
  fragment blockFragment on Block {
299
355
  id
356
+ height
300
357
  header {
301
- height
302
358
  time
303
359
  }
304
360
  transactions {
@@ -308,15 +364,18 @@ var BlockFragmentFragmentDoc = import_graphql_tag.default`
308
364
  `;
309
365
  var TxParametersFragmentFragmentDoc = import_graphql_tag.default`
310
366
  fragment TxParametersFragment on TxParameters {
367
+ version
311
368
  maxInputs
312
369
  maxOutputs
313
370
  maxWitnesses
314
371
  maxGasPerTx
315
372
  maxSize
373
+ maxBytecodeSubsections
316
374
  }
317
375
  `;
318
376
  var PredicateParametersFragmentFragmentDoc = import_graphql_tag.default`
319
377
  fragment PredicateParametersFragment on PredicateParameters {
378
+ version
320
379
  maxPredicateLength
321
380
  maxPredicateDataLength
322
381
  maxGasPerPredicate
@@ -325,18 +384,21 @@ var PredicateParametersFragmentFragmentDoc = import_graphql_tag.default`
325
384
  `;
326
385
  var ScriptParametersFragmentFragmentDoc = import_graphql_tag.default`
327
386
  fragment ScriptParametersFragment on ScriptParameters {
387
+ version
328
388
  maxScriptLength
329
389
  maxScriptDataLength
330
390
  }
331
391
  `;
332
392
  var ContractParametersFragmentFragmentDoc = import_graphql_tag.default`
333
393
  fragment ContractParametersFragment on ContractParameters {
394
+ version
334
395
  contractMaxSize
335
396
  maxStorageSlots
336
397
  }
337
398
  `;
338
399
  var FeeParametersFragmentFragmentDoc = import_graphql_tag.default`
339
400
  fragment FeeParametersFragment on FeeParameters {
401
+ version
340
402
  gasPriceFactor
341
403
  gasPerByte
342
404
  }
@@ -356,6 +418,7 @@ var DependentCostFragmentFragmentDoc = import_graphql_tag.default`
356
418
  `;
357
419
  var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
358
420
  fragment GasCostsFragment on GasCosts {
421
+ version
359
422
  add
360
423
  addi
361
424
  aloc
@@ -368,7 +431,6 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
368
431
  cb
369
432
  cfei
370
433
  cfsi
371
- croo
372
434
  div
373
435
  divi
374
436
  ecr1
@@ -451,6 +513,9 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
451
513
  ccp {
452
514
  ...DependentCostFragment
453
515
  }
516
+ croo {
517
+ ...DependentCostFragment
518
+ }
454
519
  csiz {
455
520
  ...DependentCostFragment
456
521
  }
@@ -510,6 +575,7 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
510
575
  ${DependentCostFragmentFragmentDoc}`;
511
576
  var ConsensusParametersFragmentFragmentDoc = import_graphql_tag.default`
512
577
  fragment consensusParametersFragment on ConsensusParameters {
578
+ version
513
579
  txParams {
514
580
  ...TxParametersFragment
515
581
  }
@@ -569,17 +635,16 @@ var NodeInfoFragmentFragmentDoc = import_graphql_tag.default`
569
635
  fragment nodeInfoFragment on NodeInfo {
570
636
  utxoValidation
571
637
  vmBacktrace
572
- minGasPrice
573
638
  maxTx
574
639
  maxDepth
575
640
  nodeVersion
576
- peers {
577
- id
578
- addresses
579
- clientVersion
641
+ }
642
+ `;
643
+ var RelayedTransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
644
+ fragment relayedTransactionStatusFragment on RelayedTransactionStatus {
645
+ ... on RelayedTransactionFailed {
580
646
  blockHeight
581
- lastHeartbeatMs
582
- appScore
647
+ failure
583
648
  }
584
649
  }
585
650
  `;
@@ -615,13 +680,9 @@ var GetTransactionWithReceiptsDocument = import_graphql_tag.default`
615
680
  query getTransactionWithReceipts($transactionId: TransactionId!) {
616
681
  transaction(id: $transactionId) {
617
682
  ...transactionFragment
618
- receipts {
619
- ...receiptFragment
620
- }
621
683
  }
622
684
  }
623
- ${TransactionFragmentFragmentDoc}
624
- ${ReceiptFragmentFragmentDoc}`;
685
+ ${TransactionFragmentFragmentDoc}`;
625
686
  var GetTransactionsDocument = import_graphql_tag.default`
626
687
  query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
627
688
  transactions(after: $after, before: $before, first: $first, last: $last) {
@@ -749,6 +810,20 @@ var GetBalanceDocument = import_graphql_tag.default`
749
810
  }
750
811
  }
751
812
  ${BalanceFragmentFragmentDoc}`;
813
+ var GetLatestGasPriceDocument = import_graphql_tag.default`
814
+ query getLatestGasPrice {
815
+ latestGasPrice {
816
+ gasPrice
817
+ }
818
+ }
819
+ `;
820
+ var EstimateGasPriceDocument = import_graphql_tag.default`
821
+ query estimateGasPrice($blockHorizon: U32!) {
822
+ estimateGasPrice(blockHorizon: $blockHorizon) {
823
+ gasPrice
824
+ }
825
+ }
826
+ `;
752
827
  var GetBalancesDocument = import_graphql_tag.default`
753
828
  query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
754
829
  balances(
@@ -802,13 +877,20 @@ var GetMessageStatusDocument = import_graphql_tag.default`
802
877
  }
803
878
  }
804
879
  `;
880
+ var GetRelayedTransactionStatusDocument = import_graphql_tag.default`
881
+ query getRelayedTransactionStatus($relayedTransactionId: RelayedTransactionId!) {
882
+ relayedTransactionStatus(id: $relayedTransactionId) {
883
+ ...relayedTransactionStatusFragment
884
+ }
885
+ }
886
+ ${RelayedTransactionStatusFragmentFragmentDoc}`;
805
887
  var DryRunDocument = import_graphql_tag.default`
806
- mutation dryRun($encodedTransaction: HexString!, $utxoValidation: Boolean) {
807
- dryRun(tx: $encodedTransaction, utxoValidation: $utxoValidation) {
808
- ...receiptFragment
888
+ mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean) {
889
+ dryRun(txs: $encodedTransactions, utxoValidation: $utxoValidation) {
890
+ ...dryRunTransactionExecutionStatusFragment
809
891
  }
810
892
  }
811
- ${ReceiptFragmentFragmentDoc}`;
893
+ ${DryRunTransactionExecutionStatusFragmentFragmentDoc}`;
812
894
  var SubmitDocument = import_graphql_tag.default`
813
895
  mutation submit($encodedTransaction: HexString!) {
814
896
  submit(tx: $encodedTransaction) {
@@ -824,20 +906,27 @@ var ProduceBlocksDocument = import_graphql_tag.default`
824
906
  )
825
907
  }
826
908
  `;
909
+ var GetMessageByNonceDocument = import_graphql_tag.default`
910
+ query getMessageByNonce($nonce: Nonce!) {
911
+ message(nonce: $nonce) {
912
+ ...messageFragment
913
+ }
914
+ }
915
+ ${MessageFragmentFragmentDoc}`;
827
916
  var SubmitAndAwaitDocument = import_graphql_tag.default`
828
917
  subscription submitAndAwait($encodedTransaction: HexString!) {
829
918
  submitAndAwait(tx: $encodedTransaction) {
830
- ...transactionStatusFragment
919
+ ...transactionStatusSubscriptionFragment
831
920
  }
832
921
  }
833
- ${TransactionStatusFragmentFragmentDoc}`;
922
+ ${TransactionStatusSubscriptionFragmentFragmentDoc}`;
834
923
  var StatusChangeDocument = import_graphql_tag.default`
835
924
  subscription statusChange($transactionId: TransactionId!) {
836
925
  statusChange(id: $transactionId) {
837
- ...transactionStatusFragment
926
+ ...transactionStatusSubscriptionFragment
838
927
  }
839
928
  }
840
- ${TransactionStatusFragmentFragmentDoc}`;
929
+ ${TransactionStatusSubscriptionFragmentFragmentDoc}`;
841
930
  function getSdk(requester) {
842
931
  return {
843
932
  getVersion(variables, options) {
@@ -891,6 +980,12 @@ function getSdk(requester) {
891
980
  getBalance(variables, options) {
892
981
  return requester(GetBalanceDocument, variables, options);
893
982
  },
983
+ getLatestGasPrice(variables, options) {
984
+ return requester(GetLatestGasPriceDocument, variables, options);
985
+ },
986
+ estimateGasPrice(variables, options) {
987
+ return requester(EstimateGasPriceDocument, variables, options);
988
+ },
894
989
  getBalances(variables, options) {
895
990
  return requester(GetBalancesDocument, variables, options);
896
991
  },
@@ -903,6 +998,9 @@ function getSdk(requester) {
903
998
  getMessageStatus(variables, options) {
904
999
  return requester(GetMessageStatusDocument, variables, options);
905
1000
  },
1001
+ getRelayedTransactionStatus(variables, options) {
1002
+ return requester(GetRelayedTransactionStatusDocument, variables, options);
1003
+ },
906
1004
  dryRun(variables, options) {
907
1005
  return requester(DryRunDocument, variables, options);
908
1006
  },
@@ -912,6 +1010,9 @@ function getSdk(requester) {
912
1010
  produceBlocks(variables, options) {
913
1011
  return requester(ProduceBlocksDocument, variables, options);
914
1012
  },
1013
+ getMessageByNonce(variables, options) {
1014
+ return requester(GetMessageByNonceDocument, variables, options);
1015
+ },
915
1016
  submitAndAwait(variables, options) {
916
1017
  return requester(SubmitAndAwaitDocument, variables, options);
917
1018
  },
@@ -1061,7 +1162,7 @@ var MemoryCache = class {
1061
1162
 
1062
1163
  // src/providers/transaction-request/input.ts
1063
1164
  var import_abi_coder = require("@fuel-ts/abi-coder");
1064
- var import_configs2 = require("@fuel-ts/address/configs");
1165
+ var import_configs = require("@fuel-ts/address/configs");
1065
1166
  var import_errors3 = require("@fuel-ts/errors");
1066
1167
  var import_math2 = require("@fuel-ts/math");
1067
1168
  var import_transactions = require("@fuel-ts/transactions");
@@ -1084,10 +1185,9 @@ var inputify = (value) => {
1084
1185
  txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
1085
1186
  },
1086
1187
  witnessIndex: value.witnessIndex,
1087
- maturity: value.maturity ?? 0,
1088
1188
  predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
1089
- predicateLength: predicate.length,
1090
- predicateDataLength: predicateData.length,
1189
+ predicateLength: (0, import_math2.bn)(predicate.length),
1190
+ predicateDataLength: (0, import_math2.bn)(predicateData.length),
1091
1191
  predicate: (0, import_utils3.hexlify)(predicate),
1092
1192
  predicateData: (0, import_utils3.hexlify)(predicateData)
1093
1193
  };
@@ -1095,10 +1195,10 @@ var inputify = (value) => {
1095
1195
  case import_transactions.InputType.Contract: {
1096
1196
  return {
1097
1197
  type: import_transactions.InputType.Contract,
1098
- txID: import_configs2.ZeroBytes32,
1198
+ txID: import_configs.ZeroBytes32,
1099
1199
  outputIndex: 0,
1100
- balanceRoot: import_configs2.ZeroBytes32,
1101
- stateRoot: import_configs2.ZeroBytes32,
1200
+ balanceRoot: import_configs.ZeroBytes32,
1201
+ stateRoot: import_configs.ZeroBytes32,
1102
1202
  txPointer: {
1103
1203
  blockHeight: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(0, 8)),
1104
1204
  txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
@@ -1118,8 +1218,8 @@ var inputify = (value) => {
1118
1218
  nonce: (0, import_utils3.hexlify)(value.nonce),
1119
1219
  witnessIndex: value.witnessIndex,
1120
1220
  predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
1121
- predicateLength: predicate.length,
1122
- predicateDataLength: predicateData.length,
1221
+ predicateLength: (0, import_math2.bn)(predicate.length),
1222
+ predicateDataLength: (0, import_math2.bn)(predicateData.length),
1123
1223
  predicate: (0, import_utils3.hexlify)(predicate),
1124
1224
  predicateData: (0, import_utils3.hexlify)(predicateData),
1125
1225
  data: (0, import_utils3.hexlify)(data),
@@ -1136,7 +1236,7 @@ var inputify = (value) => {
1136
1236
  };
1137
1237
 
1138
1238
  // src/providers/transaction-request/output.ts
1139
- var import_configs3 = require("@fuel-ts/address/configs");
1239
+ var import_configs2 = require("@fuel-ts/address/configs");
1140
1240
  var import_errors4 = require("@fuel-ts/errors");
1141
1241
  var import_math3 = require("@fuel-ts/math");
1142
1242
  var import_transactions2 = require("@fuel-ts/transactions");
@@ -1156,8 +1256,8 @@ var outputify = (value) => {
1156
1256
  return {
1157
1257
  type: import_transactions2.OutputType.Contract,
1158
1258
  inputIndex: value.inputIndex,
1159
- balanceRoot: import_configs3.ZeroBytes32,
1160
- stateRoot: import_configs3.ZeroBytes32
1259
+ balanceRoot: import_configs2.ZeroBytes32,
1260
+ stateRoot: import_configs2.ZeroBytes32
1161
1261
  };
1162
1262
  }
1163
1263
  case import_transactions2.OutputType.Change: {
@@ -1171,9 +1271,9 @@ var outputify = (value) => {
1171
1271
  case import_transactions2.OutputType.Variable: {
1172
1272
  return {
1173
1273
  type: import_transactions2.OutputType.Variable,
1174
- to: import_configs3.ZeroBytes32,
1274
+ to: import_configs2.ZeroBytes32,
1175
1275
  amount: (0, import_math3.bn)(0),
1176
- assetId: import_configs3.ZeroBytes32
1276
+ assetId: import_configs2.ZeroBytes32
1177
1277
  };
1178
1278
  }
1179
1279
  case import_transactions2.OutputType.ContractCreated: {
@@ -1195,7 +1295,7 @@ var outputify = (value) => {
1195
1295
  // src/providers/transaction-request/transaction-request.ts
1196
1296
  var import_abi_coder2 = require("@fuel-ts/abi-coder");
1197
1297
  var import_address = require("@fuel-ts/address");
1198
- var import_configs7 = require("@fuel-ts/address/configs");
1298
+ var import_configs6 = require("@fuel-ts/address/configs");
1199
1299
  var import_crypto = require("@fuel-ts/crypto");
1200
1300
  var import_math7 = require("@fuel-ts/math");
1201
1301
  var import_transactions6 = require("@fuel-ts/transactions");
@@ -1205,13 +1305,13 @@ var import_utils9 = require("@fuel-ts/utils");
1205
1305
  var isCoin = (resource) => "id" in resource;
1206
1306
 
1207
1307
  // src/providers/utils/receipts.ts
1208
- var import_configs4 = require("@fuel-ts/address/configs");
1308
+ var import_configs3 = require("@fuel-ts/address/configs");
1209
1309
  var import_errors5 = require("@fuel-ts/errors");
1210
1310
  var import_math4 = require("@fuel-ts/math");
1211
1311
  var import_transactions3 = require("@fuel-ts/transactions");
1212
- var import_configs5 = require("@fuel-ts/transactions/configs");
1312
+ var import_configs4 = require("@fuel-ts/transactions/configs");
1213
1313
  var import_utils5 = require("@fuel-ts/utils");
1214
- var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions3.ReceiptType.Revert && receipt.val.toString("hex") === import_configs5.FAILED_TRANSFER_TO_ADDRESS_SIGNAL;
1314
+ var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions3.ReceiptType.Revert && receipt.val.toString("hex") === import_configs4.FAILED_TRANSFER_TO_ADDRESS_SIGNAL;
1215
1315
  var doesReceiptHaveMissingContractId = (receipt) => receipt.type === import_transactions3.ReceiptType.Panic && receipt.contractId !== "0x0000000000000000000000000000000000000000000000000000000000000000";
1216
1316
  var getReceiptsWithMissingData = (receipts) => receipts.reduce(
1217
1317
  (memo, receipt) => {
@@ -1228,15 +1328,15 @@ var getReceiptsWithMissingData = (receipts) => receipts.reduce(
1228
1328
  missingOutputContractIds: []
1229
1329
  }
1230
1330
  );
1231
- var hexOrZero = (hex) => hex || import_configs4.ZeroBytes32;
1331
+ var hexOrZero = (hex) => hex || import_configs3.ZeroBytes32;
1232
1332
  function assembleReceiptByType(receipt) {
1233
1333
  const { receiptType } = receipt;
1234
1334
  switch (receiptType) {
1235
1335
  case "CALL" /* Call */: {
1236
1336
  const callReceipt = {
1237
1337
  type: import_transactions3.ReceiptType.Call,
1238
- from: hexOrZero(receipt.contract?.id),
1239
- to: hexOrZero(receipt?.to?.id),
1338
+ from: hexOrZero(receipt.id || receipt.contractId),
1339
+ to: hexOrZero(receipt?.to),
1240
1340
  amount: (0, import_math4.bn)(receipt.amount),
1241
1341
  assetId: hexOrZero(receipt.assetId),
1242
1342
  gas: (0, import_math4.bn)(receipt.gas),
@@ -1250,7 +1350,7 @@ function assembleReceiptByType(receipt) {
1250
1350
  case "RETURN" /* Return */: {
1251
1351
  const returnReceipt = {
1252
1352
  type: import_transactions3.ReceiptType.Return,
1253
- id: hexOrZero(receipt.contract?.id),
1353
+ id: hexOrZero(receipt.id || receipt.contractId),
1254
1354
  val: (0, import_math4.bn)(receipt.val),
1255
1355
  pc: (0, import_math4.bn)(receipt.pc),
1256
1356
  is: (0, import_math4.bn)(receipt.is)
@@ -1260,7 +1360,7 @@ function assembleReceiptByType(receipt) {
1260
1360
  case "RETURN_DATA" /* ReturnData */: {
1261
1361
  const returnDataReceipt = {
1262
1362
  type: import_transactions3.ReceiptType.ReturnData,
1263
- id: hexOrZero(receipt.contract?.id),
1363
+ id: hexOrZero(receipt.id || receipt.contractId),
1264
1364
  ptr: (0, import_math4.bn)(receipt.ptr),
1265
1365
  len: (0, import_math4.bn)(receipt.len),
1266
1366
  digest: hexOrZero(receipt.digest),
@@ -1272,7 +1372,7 @@ function assembleReceiptByType(receipt) {
1272
1372
  case "PANIC" /* Panic */: {
1273
1373
  const panicReceipt = {
1274
1374
  type: import_transactions3.ReceiptType.Panic,
1275
- id: hexOrZero(receipt.contract?.id),
1375
+ id: hexOrZero(receipt.id),
1276
1376
  reason: (0, import_math4.bn)(receipt.reason),
1277
1377
  pc: (0, import_math4.bn)(receipt.pc),
1278
1378
  is: (0, import_math4.bn)(receipt.is),
@@ -1283,7 +1383,7 @@ function assembleReceiptByType(receipt) {
1283
1383
  case "REVERT" /* Revert */: {
1284
1384
  const revertReceipt = {
1285
1385
  type: import_transactions3.ReceiptType.Revert,
1286
- id: hexOrZero(receipt.contract?.id),
1386
+ id: hexOrZero(receipt.id || receipt.contractId),
1287
1387
  val: (0, import_math4.bn)(receipt.ra),
1288
1388
  pc: (0, import_math4.bn)(receipt.pc),
1289
1389
  is: (0, import_math4.bn)(receipt.is)
@@ -1293,7 +1393,7 @@ function assembleReceiptByType(receipt) {
1293
1393
  case "LOG" /* Log */: {
1294
1394
  const logReceipt = {
1295
1395
  type: import_transactions3.ReceiptType.Log,
1296
- id: hexOrZero(receipt.contract?.id),
1396
+ id: hexOrZero(receipt.id || receipt.contractId),
1297
1397
  val0: (0, import_math4.bn)(receipt.ra),
1298
1398
  val1: (0, import_math4.bn)(receipt.rb),
1299
1399
  val2: (0, import_math4.bn)(receipt.rc),
@@ -1306,7 +1406,7 @@ function assembleReceiptByType(receipt) {
1306
1406
  case "LOG_DATA" /* LogData */: {
1307
1407
  const logDataReceipt = {
1308
1408
  type: import_transactions3.ReceiptType.LogData,
1309
- id: hexOrZero(receipt.contract?.id),
1409
+ id: hexOrZero(receipt.id || receipt.contractId),
1310
1410
  val0: (0, import_math4.bn)(receipt.ra),
1311
1411
  val1: (0, import_math4.bn)(receipt.rb),
1312
1412
  ptr: (0, import_math4.bn)(receipt.ptr),
@@ -1320,8 +1420,8 @@ function assembleReceiptByType(receipt) {
1320
1420
  case "TRANSFER" /* Transfer */: {
1321
1421
  const transferReceipt = {
1322
1422
  type: import_transactions3.ReceiptType.Transfer,
1323
- from: hexOrZero(receipt.contract?.id),
1324
- to: hexOrZero(receipt.toAddress || receipt?.to?.id),
1423
+ from: hexOrZero(receipt.id || receipt.contractId),
1424
+ to: hexOrZero(receipt.toAddress || receipt?.to),
1325
1425
  amount: (0, import_math4.bn)(receipt.amount),
1326
1426
  assetId: hexOrZero(receipt.assetId),
1327
1427
  pc: (0, import_math4.bn)(receipt.pc),
@@ -1332,8 +1432,8 @@ function assembleReceiptByType(receipt) {
1332
1432
  case "TRANSFER_OUT" /* TransferOut */: {
1333
1433
  const transferOutReceipt = {
1334
1434
  type: import_transactions3.ReceiptType.TransferOut,
1335
- from: hexOrZero(receipt.contract?.id),
1336
- to: hexOrZero(receipt.toAddress || receipt.to?.id),
1435
+ from: hexOrZero(receipt.id || receipt.contractId),
1436
+ to: hexOrZero(receipt.toAddress || receipt.to),
1337
1437
  amount: (0, import_math4.bn)(receipt.amount),
1338
1438
  assetId: hexOrZero(receipt.assetId),
1339
1439
  pc: (0, import_math4.bn)(receipt.pc),
@@ -1376,7 +1476,7 @@ function assembleReceiptByType(receipt) {
1376
1476
  return receiptMessageOut;
1377
1477
  }
1378
1478
  case "MINT" /* Mint */: {
1379
- const contractId = hexOrZero(receipt.contract?.id);
1479
+ const contractId = hexOrZero(receipt.id || receipt.contractId);
1380
1480
  const subId = hexOrZero(receipt.subId);
1381
1481
  const assetId = import_transactions3.ReceiptMintCoder.getAssetId(contractId, subId);
1382
1482
  const mintReceipt = {
@@ -1391,7 +1491,7 @@ function assembleReceiptByType(receipt) {
1391
1491
  return mintReceipt;
1392
1492
  }
1393
1493
  case "BURN" /* Burn */: {
1394
- const contractId = hexOrZero(receipt.contract?.id);
1494
+ const contractId = hexOrZero(receipt.id || receipt.contractId);
1395
1495
  const subId = hexOrZero(receipt.subId);
1396
1496
  const assetId = import_transactions3.ReceiptBurnCoder.getAssetId(contractId, subId);
1397
1497
  const burnReceipt = {
@@ -1417,7 +1517,6 @@ var import_errors6 = require("@fuel-ts/errors");
1417
1517
  var import_math5 = require("@fuel-ts/math");
1418
1518
  var import_transactions4 = require("@fuel-ts/transactions");
1419
1519
  var import_utils6 = require("@fuel-ts/utils");
1420
- var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => (0, import_math5.bn)(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
1421
1520
  var getGasUsedFromReceipts = (receipts) => {
1422
1521
  const scriptResult = receipts.filter(
1423
1522
  (receipt) => receipt.type === import_transactions4.ReceiptType.ScriptResult
@@ -1438,18 +1537,28 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
1438
1537
  }
1439
1538
  function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
1440
1539
  const witnessCache = [];
1441
- const totalGas = inputs.reduce((total, input) => {
1540
+ const chargeableInputs = inputs.filter((input) => {
1541
+ const isCoinOrMessage = "owner" in input || "sender" in input;
1542
+ if (isCoinOrMessage) {
1543
+ if ("predicate" in input && input.predicate && input.predicate !== "0x") {
1544
+ return true;
1545
+ }
1546
+ if (!witnessCache.includes(input.witnessIndex)) {
1547
+ witnessCache.push(input.witnessIndex);
1548
+ return true;
1549
+ }
1550
+ }
1551
+ return false;
1552
+ });
1553
+ const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
1554
+ const totalGas = chargeableInputs.reduce((total, input) => {
1442
1555
  if ("predicate" in input && input.predicate && input.predicate !== "0x") {
1443
1556
  return total.add(
1444
- resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization).add(resolveGasDependentCosts((0, import_utils6.arrayify)(input.predicate).length, gasCosts.contractRoot)).add((0, import_math5.bn)(input.predicateGasUsed))
1557
+ vmInitializationCost.add(resolveGasDependentCosts((0, import_utils6.arrayify)(input.predicate).length, gasCosts.contractRoot)).add((0, import_math5.bn)(input.predicateGasUsed))
1445
1558
  );
1446
1559
  }
1447
- if ("witnessIndex" in input && !witnessCache.includes(input.witnessIndex)) {
1448
- witnessCache.push(input.witnessIndex);
1449
- return total.add(gasCosts.ecr1);
1450
- }
1451
- return total;
1452
- }, (0, import_math5.bn)());
1560
+ return total.add(gasCosts.ecr1);
1561
+ }, (0, import_math5.bn)(0));
1453
1562
  return totalGas;
1454
1563
  }
1455
1564
  function getMinGas(params) {
@@ -1461,12 +1570,20 @@ function getMinGas(params) {
1461
1570
  return minGas;
1462
1571
  }
1463
1572
  function getMaxGas(params) {
1464
- const { gasPerByte, witnessesLength, witnessLimit, minGas, gasLimit = (0, import_math5.bn)(0) } = params;
1573
+ const {
1574
+ gasPerByte,
1575
+ witnessesLength,
1576
+ witnessLimit,
1577
+ minGas,
1578
+ gasLimit = (0, import_math5.bn)(0),
1579
+ maxGasPerTx
1580
+ } = params;
1465
1581
  let remainingAllowedWitnessGas = (0, import_math5.bn)(0);
1466
1582
  if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
1467
1583
  remainingAllowedWitnessGas = (0, import_math5.bn)(witnessLimit).sub(witnessesLength).mul(gasPerByte);
1468
1584
  }
1469
- return remainingAllowedWitnessGas.add(minGas).add(gasLimit);
1585
+ const maxGas = remainingAllowedWitnessGas.add(minGas).add(gasLimit);
1586
+ return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
1470
1587
  }
1471
1588
  function calculateMetadataGasForTxCreate({
1472
1589
  gasCosts,
@@ -1488,6 +1605,10 @@ function calculateMetadataGasForTxScript({
1488
1605
  }) {
1489
1606
  return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
1490
1607
  }
1608
+ var calculateGasFee = (params) => {
1609
+ const { gas, gasPrice, priceFactor, tip } = params;
1610
+ return gas.mul(gasPrice).div(priceFactor).add((0, import_math5.bn)(tip));
1611
+ };
1491
1612
 
1492
1613
  // src/providers/utils/json.ts
1493
1614
  var import_utils7 = require("@fuel-ts/utils");
@@ -1533,16 +1654,16 @@ function sleep(time) {
1533
1654
  var import_errors7 = require("@fuel-ts/errors");
1534
1655
  var import_math6 = require("@fuel-ts/math");
1535
1656
  var import_transactions5 = require("@fuel-ts/transactions");
1536
- var import_configs6 = require("@fuel-ts/transactions/configs");
1657
+ var import_configs5 = require("@fuel-ts/transactions/configs");
1537
1658
  var assemblePanicError = (status) => {
1538
1659
  let errorMessage = `The transaction reverted with reason: "${status.reason}".`;
1539
1660
  const reason = status.reason;
1540
- if (import_configs6.PANIC_REASONS.includes(status.reason)) {
1661
+ if (import_configs5.PANIC_REASONS.includes(status.reason)) {
1541
1662
  errorMessage = `${errorMessage}
1542
1663
 
1543
1664
  You can read more about this error at:
1544
1665
 
1545
- ${import_configs6.PANIC_DOC_URL}#variant.${status.reason}`;
1666
+ ${import_configs5.PANIC_DOC_URL}#variant.${status.reason}`;
1546
1667
  }
1547
1668
  return { errorMessage, reason };
1548
1669
  };
@@ -1554,28 +1675,28 @@ var assembleRevertError = (receipts, logs) => {
1554
1675
  if (revertReceipt) {
1555
1676
  const reasonHex = (0, import_math6.bn)(revertReceipt.val).toHex();
1556
1677
  switch (reasonHex) {
1557
- case import_configs6.FAILED_REQUIRE_SIGNAL: {
1678
+ case import_configs5.FAILED_REQUIRE_SIGNAL: {
1558
1679
  reason = "require";
1559
1680
  errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(logs[0]) : "an error."}.`;
1560
1681
  break;
1561
1682
  }
1562
- case import_configs6.FAILED_ASSERT_EQ_SIGNAL: {
1683
+ case import_configs5.FAILED_ASSERT_EQ_SIGNAL: {
1563
1684
  const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
1564
1685
  reason = "assert_eq";
1565
1686
  errorMessage = `The transaction reverted because of an "assert_eq" statement${sufix}`;
1566
1687
  break;
1567
1688
  }
1568
- case import_configs6.FAILED_ASSERT_NE_SIGNAL: {
1689
+ case import_configs5.FAILED_ASSERT_NE_SIGNAL: {
1569
1690
  const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
1570
1691
  reason = "assert_ne";
1571
1692
  errorMessage = `The transaction reverted because of an "assert_ne" statement${sufix}`;
1572
1693
  break;
1573
1694
  }
1574
- case import_configs6.FAILED_ASSERT_SIGNAL:
1695
+ case import_configs5.FAILED_ASSERT_SIGNAL:
1575
1696
  reason = "assert";
1576
1697
  errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
1577
1698
  break;
1578
- case import_configs6.FAILED_TRANSFER_TO_ADDRESS_SIGNAL:
1699
+ case import_configs5.FAILED_TRANSFER_TO_ADDRESS_SIGNAL:
1579
1700
  reason = "MissingOutputChange";
1580
1701
  errorMessage = `The transaction reverted because it's missing an "OutputChange".`;
1581
1702
  break;
@@ -1624,7 +1745,7 @@ var witnessify = (value) => {
1624
1745
  // src/providers/transaction-request/transaction-request.ts
1625
1746
  var BaseTransactionRequest = class {
1626
1747
  /** Gas price for transaction */
1627
- gasPrice;
1748
+ tip;
1628
1749
  /** Block until which tx cannot be included */
1629
1750
  maturity;
1630
1751
  /** The maximum fee payable by this transaction using BASE_ASSET. */
@@ -1643,7 +1764,7 @@ var BaseTransactionRequest = class {
1643
1764
  * @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
1644
1765
  */
1645
1766
  constructor({
1646
- gasPrice,
1767
+ tip,
1647
1768
  maturity,
1648
1769
  maxFee,
1649
1770
  witnessLimit,
@@ -1651,10 +1772,10 @@ var BaseTransactionRequest = class {
1651
1772
  outputs,
1652
1773
  witnesses
1653
1774
  } = {}) {
1654
- this.gasPrice = (0, import_math7.bn)(gasPrice);
1655
- this.maturity = maturity ?? 0;
1656
- this.witnessLimit = witnessLimit ? (0, import_math7.bn)(witnessLimit) : void 0;
1657
- this.maxFee = maxFee ? (0, import_math7.bn)(maxFee) : void 0;
1775
+ this.tip = tip ? (0, import_math7.bn)(tip) : void 0;
1776
+ this.maturity = maturity && maturity > 0 ? maturity : void 0;
1777
+ this.witnessLimit = (0, import_utils9.isDefined)(witnessLimit) ? (0, import_math7.bn)(witnessLimit) : void 0;
1778
+ this.maxFee = (0, import_math7.bn)(maxFee);
1658
1779
  this.inputs = inputs ?? [];
1659
1780
  this.outputs = outputs ?? [];
1660
1781
  this.witnesses = witnesses ?? [];
@@ -1662,22 +1783,21 @@ var BaseTransactionRequest = class {
1662
1783
  static getPolicyMeta(req) {
1663
1784
  let policyTypes = 0;
1664
1785
  const policies = [];
1665
- if (req.gasPrice) {
1666
- policyTypes += import_transactions6.PolicyType.GasPrice;
1667
- policies.push({ data: req.gasPrice, type: import_transactions6.PolicyType.GasPrice });
1786
+ const { tip, witnessLimit, maturity } = req;
1787
+ if ((0, import_math7.bn)(tip).gt(0)) {
1788
+ policyTypes += import_transactions6.PolicyType.Tip;
1789
+ policies.push({ data: (0, import_math7.bn)(tip), type: import_transactions6.PolicyType.Tip });
1668
1790
  }
1669
- if (req.witnessLimit) {
1791
+ if ((0, import_utils9.isDefined)(witnessLimit) && (0, import_math7.bn)(witnessLimit).gte(0)) {
1670
1792
  policyTypes += import_transactions6.PolicyType.WitnessLimit;
1671
- policies.push({ data: req.witnessLimit, type: import_transactions6.PolicyType.WitnessLimit });
1793
+ policies.push({ data: (0, import_math7.bn)(witnessLimit), type: import_transactions6.PolicyType.WitnessLimit });
1672
1794
  }
1673
- if (req.maturity > 0) {
1795
+ if (maturity && maturity > 0) {
1674
1796
  policyTypes += import_transactions6.PolicyType.Maturity;
1675
- policies.push({ data: req.maturity, type: import_transactions6.PolicyType.Maturity });
1676
- }
1677
- if (req.maxFee) {
1678
- policyTypes += import_transactions6.PolicyType.MaxFee;
1679
- policies.push({ data: req.maxFee, type: import_transactions6.PolicyType.MaxFee });
1797
+ policies.push({ data: maturity, type: import_transactions6.PolicyType.Maturity });
1680
1798
  }
1799
+ policyTypes += import_transactions6.PolicyType.MaxFee;
1800
+ policies.push({ data: req.maxFee, type: import_transactions6.PolicyType.MaxFee });
1681
1801
  return {
1682
1802
  policyTypes,
1683
1803
  policies
@@ -1750,7 +1870,7 @@ var BaseTransactionRequest = class {
1750
1870
  * @returns The index of the created witness.
1751
1871
  */
1752
1872
  addEmptyWitness() {
1753
- this.addWitness((0, import_utils9.concat)([import_configs7.ZeroBytes32, import_configs7.ZeroBytes32]));
1873
+ this.addWitness((0, import_utils9.concat)([import_configs6.ZeroBytes32, import_configs6.ZeroBytes32]));
1754
1874
  return this.witnesses.length - 1;
1755
1875
  }
1756
1876
  /**
@@ -1848,13 +1968,11 @@ var BaseTransactionRequest = class {
1848
1968
  * assetId, if one it was not added yet.
1849
1969
  *
1850
1970
  * @param coin - Coin resource.
1851
- * @param predicate - Predicate bytes.
1852
- * @param predicateData - Predicate data bytes.
1853
1971
  */
1854
- addCoinInput(coin, predicate) {
1972
+ addCoinInput(coin) {
1855
1973
  const { assetId, owner, amount } = coin;
1856
1974
  let witnessIndex;
1857
- if (predicate) {
1975
+ if (coin.predicate) {
1858
1976
  witnessIndex = 0;
1859
1977
  } else {
1860
1978
  witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
@@ -1869,25 +1987,21 @@ var BaseTransactionRequest = class {
1869
1987
  amount,
1870
1988
  assetId,
1871
1989
  txPointer: "0x00000000000000000000000000000000",
1872
- witnessIndex,
1873
- predicate: predicate?.bytes
1990
+ witnessIndex
1874
1991
  };
1875
1992
  this.pushInput(input);
1876
1993
  this.addChangeOutput(owner, assetId);
1877
1994
  }
1878
1995
  /**
1879
1996
  * Adds a single message input to the transaction and a change output for the
1880
- * baseAssetId, if one it was not added yet.
1997
+ * asset against the message
1881
1998
  *
1882
1999
  * @param message - Message resource.
1883
- * @param predicate - Predicate bytes.
1884
- * @param predicateData - Predicate data bytes.
1885
2000
  */
1886
- addMessageInput(message, predicate) {
1887
- const { recipient, sender, amount } = message;
1888
- const assetId = import_configs7.BaseAssetId;
2001
+ addMessageInput(message) {
2002
+ const { recipient, sender, amount, assetId } = message;
1889
2003
  let witnessIndex;
1890
- if (predicate) {
2004
+ if (message.predicate) {
1891
2005
  witnessIndex = 0;
1892
2006
  } else {
1893
2007
  witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
@@ -1901,8 +2015,7 @@ var BaseTransactionRequest = class {
1901
2015
  sender: sender.toB256(),
1902
2016
  recipient: recipient.toB256(),
1903
2017
  amount,
1904
- witnessIndex,
1905
- predicate: predicate?.bytes
2018
+ witnessIndex
1906
2019
  };
1907
2020
  this.pushInput(input);
1908
2021
  this.addChangeOutput(recipient, assetId);
@@ -1933,32 +2046,6 @@ var BaseTransactionRequest = class {
1933
2046
  resources.forEach((resource) => this.addResource(resource));
1934
2047
  return this;
1935
2048
  }
1936
- /**
1937
- * Adds multiple resources to the transaction by adding coin/message inputs and change
1938
- * outputs from the related assetIds.
1939
- *
1940
- * @param resources - The resources to add.
1941
- * @returns This transaction.
1942
- */
1943
- addPredicateResource(resource, predicate) {
1944
- if (isCoin(resource)) {
1945
- this.addCoinInput(resource, predicate);
1946
- } else {
1947
- this.addMessageInput(resource, predicate);
1948
- }
1949
- return this;
1950
- }
1951
- /**
1952
- * Adds multiple predicate coin/message inputs to the transaction and change outputs
1953
- * from the related assetIds.
1954
- *
1955
- * @param resources - The resources to add.
1956
- * @returns This transaction.
1957
- */
1958
- addPredicateResources(resources, predicate) {
1959
- resources.forEach((resource) => this.addPredicateResource(resource, predicate));
1960
- return this;
1961
- }
1962
2049
  /**
1963
2050
  * Adds a coin output to the transaction.
1964
2051
  *
@@ -1966,7 +2053,7 @@ var BaseTransactionRequest = class {
1966
2053
  * @param amount - Amount of coin.
1967
2054
  * @param assetId - Asset ID of coin.
1968
2055
  */
1969
- addCoinOutput(to, amount, assetId = import_configs7.BaseAssetId) {
2056
+ addCoinOutput(to, amount, assetId) {
1970
2057
  this.pushOutput({
1971
2058
  type: import_transactions6.OutputType.Coin,
1972
2059
  to: (0, import_address.addressify)(to).toB256(),
@@ -1998,7 +2085,7 @@ var BaseTransactionRequest = class {
1998
2085
  * @param to - Address of the owner.
1999
2086
  * @param assetId - Asset ID of coin.
2000
2087
  */
2001
- addChangeOutput(to, assetId = import_configs7.BaseAssetId) {
2088
+ addChangeOutput(to, assetId) {
2002
2089
  const changeOutput = this.getChangeOutputs().find(
2003
2090
  (output) => (0, import_utils9.hexlify)(output.assetId) === assetId
2004
2091
  );
@@ -2026,8 +2113,11 @@ var BaseTransactionRequest = class {
2026
2113
  * @hidden
2027
2114
  */
2028
2115
  calculateMinGas(chainInfo) {
2029
- const { gasCosts, consensusParameters } = chainInfo;
2030
- const { gasPerByte } = consensusParameters;
2116
+ const { consensusParameters } = chainInfo;
2117
+ const {
2118
+ gasCosts,
2119
+ feeParameters: { gasPerByte }
2120
+ } = consensusParameters;
2031
2121
  return getMinGas({
2032
2122
  gasPerByte,
2033
2123
  gasCosts,
@@ -2038,7 +2128,10 @@ var BaseTransactionRequest = class {
2038
2128
  }
2039
2129
  calculateMaxGas(chainInfo, minGas) {
2040
2130
  const { consensusParameters } = chainInfo;
2041
- const { gasPerByte } = consensusParameters;
2131
+ const {
2132
+ feeParameters: { gasPerByte },
2133
+ txParameters: { maxGasPerTx }
2134
+ } = consensusParameters;
2042
2135
  const witnessesLength = this.toTransaction().witnesses.reduce(
2043
2136
  (acc, wit) => acc + wit.dataLength,
2044
2137
  0
@@ -2047,7 +2140,8 @@ var BaseTransactionRequest = class {
2047
2140
  gasPerByte,
2048
2141
  minGas,
2049
2142
  witnessesLength,
2050
- witnessLimit: this.witnessLimit
2143
+ witnessLimit: this.witnessLimit,
2144
+ maxGasPerTx
2051
2145
  });
2052
2146
  }
2053
2147
  /**
@@ -2055,8 +2149,9 @@ var BaseTransactionRequest = class {
2055
2149
  * quantities array.
2056
2150
  *
2057
2151
  * @param quantities - CoinQuantity Array.
2152
+ * @param baseAssetId - The base asset to fund the transaction.
2058
2153
  */
2059
- fundWithFakeUtxos(quantities, resourcesOwner) {
2154
+ fundWithFakeUtxos(quantities, baseAssetId, resourcesOwner) {
2060
2155
  const findAssetInput = (assetId) => this.inputs.find((input) => {
2061
2156
  if ("assetId" in input) {
2062
2157
  return input.assetId === assetId;
@@ -2065,24 +2160,27 @@ var BaseTransactionRequest = class {
2065
2160
  });
2066
2161
  const updateAssetInput = (assetId, quantity) => {
2067
2162
  const assetInput = findAssetInput(assetId);
2163
+ let usedQuantity = quantity;
2164
+ if (assetId === baseAssetId) {
2165
+ usedQuantity = (0, import_math7.bn)("1000000000000000000");
2166
+ }
2068
2167
  if (assetInput && "assetId" in assetInput) {
2069
2168
  assetInput.id = (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN));
2070
- assetInput.amount = quantity;
2169
+ assetInput.amount = usedQuantity;
2071
2170
  } else {
2072
2171
  this.addResources([
2073
2172
  {
2074
2173
  id: (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN)),
2075
- amount: quantity,
2174
+ amount: usedQuantity,
2076
2175
  assetId,
2077
2176
  owner: resourcesOwner || import_address.Address.fromRandom(),
2078
- maturity: 0,
2079
2177
  blockCreated: (0, import_math7.bn)(1),
2080
2178
  txCreatedIdx: (0, import_math7.bn)(1)
2081
2179
  }
2082
2180
  ]);
2083
2181
  }
2084
2182
  };
2085
- updateAssetInput(import_configs7.BaseAssetId, (0, import_math7.bn)(1e11));
2183
+ updateAssetInput(baseAssetId, (0, import_math7.bn)(1e11));
2086
2184
  quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
2087
2185
  }
2088
2186
  /**
@@ -2107,7 +2205,7 @@ var BaseTransactionRequest = class {
2107
2205
  toJSON() {
2108
2206
  return normalizeJSON(this);
2109
2207
  }
2110
- updatePredicateInputs(inputs) {
2208
+ updatePredicateGasUsed(inputs) {
2111
2209
  this.inputs.forEach((i) => {
2112
2210
  let correspondingInput;
2113
2211
  switch (i.type) {
@@ -2129,16 +2227,25 @@ var BaseTransactionRequest = class {
2129
2227
  }
2130
2228
  });
2131
2229
  }
2230
+ shiftPredicateData() {
2231
+ this.inputs.forEach((input) => {
2232
+ if ("predicateData" in input && "padPredicateData" in input && typeof input.padPredicateData === "function") {
2233
+ input.predicateData = input.padPredicateData(
2234
+ BaseTransactionRequest.getPolicyMeta(this).policies.length
2235
+ );
2236
+ }
2237
+ });
2238
+ }
2132
2239
  };
2133
2240
 
2134
2241
  // src/providers/transaction-request/create-transaction-request.ts
2135
- var import_configs9 = require("@fuel-ts/address/configs");
2242
+ var import_configs8 = require("@fuel-ts/address/configs");
2136
2243
  var import_math9 = require("@fuel-ts/math");
2137
2244
  var import_transactions8 = require("@fuel-ts/transactions");
2138
2245
  var import_utils13 = require("@fuel-ts/utils");
2139
2246
 
2140
2247
  // src/providers/transaction-request/hash-transaction.ts
2141
- var import_configs8 = require("@fuel-ts/address/configs");
2248
+ var import_configs7 = require("@fuel-ts/address/configs");
2142
2249
  var import_hasher = require("@fuel-ts/hasher");
2143
2250
  var import_math8 = require("@fuel-ts/math");
2144
2251
  var import_transactions7 = require("@fuel-ts/transactions");
@@ -2147,7 +2254,7 @@ var import_ramda2 = require("ramda");
2147
2254
  function hashTransaction(transactionRequest, chainId) {
2148
2255
  const transaction = transactionRequest.toTransaction();
2149
2256
  if (transaction.type === import_transactions7.TransactionType.Script) {
2150
- transaction.receiptsRoot = import_configs8.ZeroBytes32;
2257
+ transaction.receiptsRoot = import_configs7.ZeroBytes32;
2151
2258
  }
2152
2259
  transaction.inputs = transaction.inputs.map((input) => {
2153
2260
  const inputClone = (0, import_ramda2.clone)(input);
@@ -2169,10 +2276,10 @@ function hashTransaction(transactionRequest, chainId) {
2169
2276
  blockHeight: 0,
2170
2277
  txIndex: 0
2171
2278
  };
2172
- inputClone.txID = import_configs8.ZeroBytes32;
2279
+ inputClone.txID = import_configs7.ZeroBytes32;
2173
2280
  inputClone.outputIndex = 0;
2174
- inputClone.balanceRoot = import_configs8.ZeroBytes32;
2175
- inputClone.stateRoot = import_configs8.ZeroBytes32;
2281
+ inputClone.balanceRoot = import_configs7.ZeroBytes32;
2282
+ inputClone.stateRoot = import_configs7.ZeroBytes32;
2176
2283
  return inputClone;
2177
2284
  }
2178
2285
  default:
@@ -2183,8 +2290,8 @@ function hashTransaction(transactionRequest, chainId) {
2183
2290
  const outputClone = (0, import_ramda2.clone)(output);
2184
2291
  switch (outputClone.type) {
2185
2292
  case import_transactions7.OutputType.Contract: {
2186
- outputClone.balanceRoot = import_configs8.ZeroBytes32;
2187
- outputClone.stateRoot = import_configs8.ZeroBytes32;
2293
+ outputClone.balanceRoot = import_configs7.ZeroBytes32;
2294
+ outputClone.stateRoot = import_configs7.ZeroBytes32;
2188
2295
  return outputClone;
2189
2296
  }
2190
2297
  case import_transactions7.OutputType.Change: {
@@ -2192,9 +2299,9 @@ function hashTransaction(transactionRequest, chainId) {
2192
2299
  return outputClone;
2193
2300
  }
2194
2301
  case import_transactions7.OutputType.Variable: {
2195
- outputClone.to = import_configs8.ZeroBytes32;
2302
+ outputClone.to = import_configs7.ZeroBytes32;
2196
2303
  outputClone.amount = (0, import_math8.bn)(0);
2197
- outputClone.assetId = import_configs8.ZeroBytes32;
2304
+ outputClone.assetId = import_configs7.ZeroBytes32;
2198
2305
  return outputClone;
2199
2306
  }
2200
2307
  default:
@@ -2252,15 +2359,10 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2252
2359
  *
2253
2360
  * @param createTransactionRequestLike - The initial values for the instance
2254
2361
  */
2255
- constructor({
2256
- bytecodeWitnessIndex,
2257
- salt,
2258
- storageSlots,
2259
- ...rest
2260
- } = {}) {
2362
+ constructor({ bytecodeWitnessIndex, salt, storageSlots, ...rest }) {
2261
2363
  super(rest);
2262
2364
  this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
2263
- this.salt = (0, import_utils13.hexlify)(salt ?? import_configs9.ZeroBytes32);
2365
+ this.salt = (0, import_utils13.hexlify)(salt ?? import_configs8.ZeroBytes32);
2264
2366
  this.storageSlots = [...storageSlots ?? []];
2265
2367
  }
2266
2368
  /**
@@ -2275,10 +2377,9 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2275
2377
  return {
2276
2378
  type: import_transactions8.TransactionType.Create,
2277
2379
  ...baseTransaction,
2278
- bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
2279
2380
  bytecodeWitnessIndex,
2280
- storageSlotsCount: storageSlots.length,
2281
- salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs9.ZeroBytes32,
2381
+ storageSlotsCount: (0, import_math9.bn)(storageSlots.length),
2382
+ salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs8.ZeroBytes32,
2282
2383
  storageSlots
2283
2384
  };
2284
2385
  }
@@ -2328,7 +2429,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2328
2429
  // src/providers/transaction-request/script-transaction-request.ts
2329
2430
  var import_abi_coder3 = require("@fuel-ts/abi-coder");
2330
2431
  var import_address2 = require("@fuel-ts/address");
2331
- var import_configs10 = require("@fuel-ts/address/configs");
2432
+ var import_configs9 = require("@fuel-ts/address/configs");
2332
2433
  var import_math10 = require("@fuel-ts/math");
2333
2434
  var import_transactions9 = require("@fuel-ts/transactions");
2334
2435
  var import_utils15 = require("@fuel-ts/utils");
@@ -2400,9 +2501,9 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2400
2501
  type: import_transactions9.TransactionType.Script,
2401
2502
  scriptGasLimit: this.gasLimit,
2402
2503
  ...super.getBaseTransaction(),
2403
- scriptLength: script.length,
2404
- scriptDataLength: scriptData.length,
2405
- receiptsRoot: import_configs10.ZeroBytes32,
2504
+ scriptLength: (0, import_math10.bn)(script.length),
2505
+ scriptDataLength: (0, import_math10.bn)(scriptData.length),
2506
+ receiptsRoot: import_configs9.ZeroBytes32,
2406
2507
  script: (0, import_utils15.hexlify)(script),
2407
2508
  scriptData: (0, import_utils15.hexlify)(scriptData)
2408
2509
  };
@@ -2465,7 +2566,10 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2465
2566
  }
2466
2567
  calculateMaxGas(chainInfo, minGas) {
2467
2568
  const { consensusParameters } = chainInfo;
2468
- const { gasPerByte } = consensusParameters;
2569
+ const {
2570
+ feeParameters: { gasPerByte },
2571
+ txParameters: { maxGasPerTx }
2572
+ } = consensusParameters;
2469
2573
  const witnessesLength = this.toTransaction().witnesses.reduce(
2470
2574
  (acc, wit) => acc + wit.dataLength,
2471
2575
  0
@@ -2475,7 +2579,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2475
2579
  minGas,
2476
2580
  witnessesLength,
2477
2581
  witnessLimit: this.witnessLimit,
2478
- gasLimit: this.gasLimit
2582
+ gasLimit: this.gasLimit,
2583
+ maxGasPerTx
2479
2584
  });
2480
2585
  }
2481
2586
  /**
@@ -2550,41 +2655,58 @@ var transactionRequestify = (obj) => {
2550
2655
  }
2551
2656
  }
2552
2657
  };
2658
+ var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
2659
+ (acc, input) => {
2660
+ if (input.type === import_transactions10.InputType.Coin && input.owner === owner.toB256()) {
2661
+ acc.utxos.push(input.id);
2662
+ }
2663
+ if (input.type === import_transactions10.InputType.Message && input.recipient === owner.toB256()) {
2664
+ acc.messages.push(input.nonce);
2665
+ }
2666
+ return acc;
2667
+ },
2668
+ {
2669
+ utxos: [],
2670
+ messages: []
2671
+ }
2672
+ );
2553
2673
 
2554
2674
  // src/providers/transaction-response/transaction-response.ts
2555
2675
  var import_errors13 = require("@fuel-ts/errors");
2556
- var import_math14 = require("@fuel-ts/math");
2557
- var import_transactions17 = require("@fuel-ts/transactions");
2558
- var import_utils21 = require("@fuel-ts/utils");
2676
+ var import_math16 = require("@fuel-ts/math");
2677
+ var import_transactions18 = require("@fuel-ts/transactions");
2678
+ var import_utils20 = require("@fuel-ts/utils");
2559
2679
 
2560
2680
  // src/providers/transaction-summary/assemble-transaction-summary.ts
2561
- var import_utils19 = require("@fuel-ts/utils");
2681
+ var import_math15 = require("@fuel-ts/math");
2682
+ var import_transactions16 = require("@fuel-ts/transactions");
2683
+ var import_utils18 = require("@fuel-ts/utils");
2562
2684
 
2563
- // src/providers/transaction-summary/calculate-transaction-fee.ts
2685
+ // src/providers/transaction-summary/calculate-tx-fee-for-summary.ts
2564
2686
  var import_math11 = require("@fuel-ts/math");
2565
2687
  var import_transactions11 = require("@fuel-ts/transactions");
2566
2688
  var import_utils16 = require("@fuel-ts/utils");
2567
- var calculateTransactionFee = (params) => {
2689
+ var calculateTXFeeForSummary = (params) => {
2568
2690
  const {
2569
- gasUsed,
2691
+ gasPrice,
2570
2692
  rawPayload,
2571
- consensusParameters: { gasCosts, feeParams }
2693
+ tip,
2694
+ totalFee,
2695
+ consensusParameters: { gasCosts, feeParams, maxGasPerTx }
2572
2696
  } = params;
2697
+ if (totalFee) {
2698
+ return totalFee;
2699
+ }
2573
2700
  const gasPerByte = (0, import_math11.bn)(feeParams.gasPerByte);
2574
2701
  const gasPriceFactor = (0, import_math11.bn)(feeParams.gasPriceFactor);
2575
2702
  const transactionBytes = (0, import_utils16.arrayify)(rawPayload);
2576
2703
  const [transaction] = new import_transactions11.TransactionCoder().decode(transactionBytes, 0);
2577
- if (transaction.type === import_transactions11.TransactionType.Mint) {
2578
- return {
2579
- fee: (0, import_math11.bn)(0),
2580
- minFee: (0, import_math11.bn)(0),
2581
- maxFee: (0, import_math11.bn)(0),
2582
- feeFromGasUsed: (0, import_math11.bn)(0)
2583
- };
2584
- }
2585
2704
  const { type, witnesses, inputs, policies } = transaction;
2586
2705
  let metadataGas = (0, import_math11.bn)(0);
2587
2706
  let gasLimit = (0, import_math11.bn)(0);
2707
+ if (type !== import_transactions11.TransactionType.Create && type !== import_transactions11.TransactionType.Script) {
2708
+ return (0, import_math11.bn)(0);
2709
+ }
2588
2710
  if (type === import_transactions11.TransactionType.Create) {
2589
2711
  const { bytecodeWitnessIndex, storageSlots } = transaction;
2590
2712
  const contractBytesSize = (0, import_math11.bn)((0, import_utils16.arrayify)(witnesses[bytecodeWitnessIndex].data).length);
@@ -2611,7 +2733,6 @@ var calculateTransactionFee = (params) => {
2611
2733
  metadataGas,
2612
2734
  txBytesSize: transactionBytes.length
2613
2735
  });
2614
- const gasPrice = (0, import_math11.bn)(policies.find((policy) => policy.type === import_transactions11.PolicyType.GasPrice)?.data);
2615
2736
  const witnessLimit = policies.find((policy) => policy.type === import_transactions11.PolicyType.WitnessLimit)?.data;
2616
2737
  const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
2617
2738
  const maxGas = getMaxGas({
@@ -2619,22 +2740,20 @@ var calculateTransactionFee = (params) => {
2619
2740
  minGas,
2620
2741
  witnessesLength,
2621
2742
  gasLimit,
2622
- witnessLimit
2743
+ witnessLimit,
2744
+ maxGasPerTx
2623
2745
  });
2624
- const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
2625
- const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
2626
- const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
2627
- const fee = minFee.add(feeFromGasUsed);
2628
- return {
2629
- fee,
2630
- minFee,
2631
- maxFee,
2632
- feeFromGasUsed
2633
- };
2746
+ const maxFee = calculateGasFee({
2747
+ gasPrice,
2748
+ gas: maxGas,
2749
+ priceFactor: gasPriceFactor,
2750
+ tip
2751
+ });
2752
+ return maxFee;
2634
2753
  };
2635
2754
 
2636
2755
  // src/providers/transaction-summary/operations.ts
2637
- var import_configs11 = require("@fuel-ts/address/configs");
2756
+ var import_configs10 = require("@fuel-ts/address/configs");
2638
2757
  var import_errors11 = require("@fuel-ts/errors");
2639
2758
  var import_math13 = require("@fuel-ts/math");
2640
2759
  var import_transactions14 = require("@fuel-ts/transactions");
@@ -2789,6 +2908,12 @@ function isTypeCreate(transactionType) {
2789
2908
  function isTypeScript(transactionType) {
2790
2909
  return isType(transactionType, "Script" /* Script */);
2791
2910
  }
2911
+ function isTypeUpgrade(transactionType) {
2912
+ return isType(transactionType, "Upgrade" /* Upgrade */);
2913
+ }
2914
+ function isTypeUpload(transactionType) {
2915
+ return isType(transactionType, "Upload" /* Upload */);
2916
+ }
2792
2917
  function getReceiptsCall(receipts) {
2793
2918
  return getReceiptsByType(receipts, import_transactions14.ReceiptType.Call);
2794
2919
  }
@@ -2932,7 +3057,7 @@ function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutp
2932
3057
  const { to: toAddress, assetId, amount } = receipt;
2933
3058
  let { from: fromAddress } = receipt;
2934
3059
  const toType = contractInputs.some((input) => input.contractID === toAddress) ? 0 /* contract */ : 1 /* account */;
2935
- if (import_configs11.ZeroBytes32 === fromAddress) {
3060
+ if (import_configs10.ZeroBytes32 === fromAddress) {
2936
3061
  const change = changeOutputs.find((output) => output.assetId === assetId);
2937
3062
  fromAddress = change?.to || fromAddress;
2938
3063
  }
@@ -3129,6 +3254,7 @@ var extractBurnedAssetsFromReceipts = (receipts) => {
3129
3254
 
3130
3255
  // src/providers/transaction-summary/status.ts
3131
3256
  var import_errors12 = require("@fuel-ts/errors");
3257
+ var import_math14 = require("@fuel-ts/math");
3132
3258
  var getTransactionStatusName = (gqlStatus) => {
3133
3259
  switch (gqlStatus) {
3134
3260
  case "FailureStatus":
@@ -3150,6 +3276,8 @@ var processGraphqlStatus = (gqlTransactionStatus) => {
3150
3276
  let time;
3151
3277
  let blockId;
3152
3278
  let status;
3279
+ let totalFee;
3280
+ let totalGas;
3153
3281
  let isStatusFailure = false;
3154
3282
  let isStatusSuccess = false;
3155
3283
  let isStatusPending = false;
@@ -3160,11 +3288,15 @@ var processGraphqlStatus = (gqlTransactionStatus) => {
3160
3288
  time = gqlTransactionStatus.time;
3161
3289
  blockId = gqlTransactionStatus.block.id;
3162
3290
  isStatusSuccess = true;
3291
+ totalFee = (0, import_math14.bn)(gqlTransactionStatus.totalFee);
3292
+ totalGas = (0, import_math14.bn)(gqlTransactionStatus.totalGas);
3163
3293
  break;
3164
3294
  case "FailureStatus":
3165
3295
  time = gqlTransactionStatus.time;
3166
3296
  blockId = gqlTransactionStatus.block.id;
3167
3297
  isStatusFailure = true;
3298
+ totalFee = (0, import_math14.bn)(gqlTransactionStatus.totalFee);
3299
+ totalGas = (0, import_math14.bn)(gqlTransactionStatus.totalGas);
3168
3300
  break;
3169
3301
  case "SubmittedStatus":
3170
3302
  time = gqlTransactionStatus.time;
@@ -3177,6 +3309,8 @@ var processGraphqlStatus = (gqlTransactionStatus) => {
3177
3309
  time,
3178
3310
  blockId,
3179
3311
  status,
3312
+ totalFee,
3313
+ totalGas,
3180
3314
  isStatusFailure,
3181
3315
  isStatusSuccess,
3182
3316
  isStatusPending
@@ -3196,10 +3330,12 @@ function assembleTransactionSummary(params) {
3196
3330
  gqlTransactionStatus,
3197
3331
  abiMap = {},
3198
3332
  maxInputs,
3199
- gasCosts
3333
+ gasCosts,
3334
+ maxGasPerTx,
3335
+ gasPrice
3200
3336
  } = params;
3201
3337
  const gasUsed = getGasUsedFromReceipts(receipts);
3202
- const rawPayload = (0, import_utils19.hexlify)(transactionBytes);
3338
+ const rawPayload = (0, import_utils18.hexlify)(transactionBytes);
3203
3339
  const operations = getOperations({
3204
3340
  transactionType: transaction.type,
3205
3341
  inputs: transaction.inputs || [],
@@ -3210,26 +3346,31 @@ function assembleTransactionSummary(params) {
3210
3346
  maxInputs
3211
3347
  });
3212
3348
  const typeName = getTransactionTypeName(transaction.type);
3213
- const { fee } = calculateTransactionFee({
3214
- gasUsed,
3349
+ const tip = (0, import_math15.bn)(transaction.policies?.find((policy) => policy.type === import_transactions16.PolicyType.Tip)?.data);
3350
+ const { isStatusFailure, isStatusPending, isStatusSuccess, blockId, status, time, totalFee } = processGraphqlStatus(gqlTransactionStatus);
3351
+ const fee = calculateTXFeeForSummary({
3352
+ totalFee,
3353
+ gasPrice,
3215
3354
  rawPayload,
3355
+ tip,
3216
3356
  consensusParameters: {
3217
3357
  gasCosts,
3358
+ maxGasPerTx,
3218
3359
  feeParams: {
3219
3360
  gasPerByte,
3220
3361
  gasPriceFactor
3221
3362
  }
3222
3363
  }
3223
3364
  });
3224
- const { isStatusFailure, isStatusPending, isStatusSuccess, blockId, status, time } = processGraphqlStatus(gqlTransactionStatus);
3225
3365
  const mintedAssets = extractMintedAssetsFromReceipts(receipts);
3226
3366
  const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
3227
3367
  let date;
3228
3368
  if (time) {
3229
- date = import_utils19.DateTime.fromTai64(time);
3369
+ date = import_utils18.DateTime.fromTai64(time);
3230
3370
  }
3231
3371
  const transactionSummary = {
3232
3372
  id,
3373
+ tip,
3233
3374
  fee,
3234
3375
  gasUsed,
3235
3376
  operations,
@@ -3243,6 +3384,8 @@ function assembleTransactionSummary(params) {
3243
3384
  isTypeMint: isTypeMint(transaction.type),
3244
3385
  isTypeCreate: isTypeCreate(transaction.type),
3245
3386
  isTypeScript: isTypeScript(transaction.type),
3387
+ isTypeUpgrade: isTypeUpgrade(transaction.type),
3388
+ isTypeUpload: isTypeUpload(transaction.type),
3246
3389
  isStatusFailure,
3247
3390
  isStatusSuccess,
3248
3391
  isStatusPending,
@@ -3254,12 +3397,12 @@ function assembleTransactionSummary(params) {
3254
3397
 
3255
3398
  // src/providers/transaction-response/getDecodedLogs.ts
3256
3399
  var import_abi_coder5 = require("@fuel-ts/abi-coder");
3257
- var import_transactions16 = require("@fuel-ts/transactions");
3400
+ var import_transactions17 = require("@fuel-ts/transactions");
3258
3401
  function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
3259
3402
  return receipts.reduce((logs, receipt) => {
3260
- if (receipt.type === import_transactions16.ReceiptType.LogData || receipt.type === import_transactions16.ReceiptType.Log) {
3403
+ if (receipt.type === import_transactions17.ReceiptType.LogData || receipt.type === import_transactions17.ReceiptType.Log) {
3261
3404
  const interfaceToUse = new import_abi_coder5.Interface(externalAbis[receipt.id] || mainAbi);
3262
- const data = receipt.type === import_transactions16.ReceiptType.Log ? new import_abi_coder5.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
3405
+ const data = receipt.type === import_transactions17.ReceiptType.Log ? new import_abi_coder5.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
3263
3406
  const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
3264
3407
  logs.push(decodedLog);
3265
3408
  }
@@ -3274,7 +3417,7 @@ var TransactionResponse = class {
3274
3417
  /** Current provider */
3275
3418
  provider;
3276
3419
  /** Gas used on the transaction */
3277
- gasUsed = (0, import_math14.bn)(0);
3420
+ gasUsed = (0, import_math16.bn)(0);
3278
3421
  /** The graphql Transaction with receipts object. */
3279
3422
  gqlTransaction;
3280
3423
  abis;
@@ -3332,8 +3475,8 @@ var TransactionResponse = class {
3332
3475
  * @returns The decoded transaction.
3333
3476
  */
3334
3477
  decodeTransaction(transactionWithReceipts) {
3335
- return new import_transactions17.TransactionCoder().decode(
3336
- (0, import_utils21.arrayify)(transactionWithReceipts.rawPayload),
3478
+ return new import_transactions18.TransactionCoder().decode(
3479
+ (0, import_utils20.arrayify)(transactionWithReceipts.rawPayload),
3337
3480
  0
3338
3481
  )?.[0];
3339
3482
  }
@@ -3352,20 +3495,27 @@ var TransactionResponse = class {
3352
3495
  const decodedTransaction = this.decodeTransaction(
3353
3496
  transaction
3354
3497
  );
3355
- const receipts = transaction.receipts?.map(processGqlReceipt) || [];
3356
- const { gasPerByte, gasPriceFactor, gasCosts } = this.provider.getGasConfig();
3357
- const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
3498
+ let txReceipts = [];
3499
+ if (transaction?.status && "receipts" in transaction.status) {
3500
+ txReceipts = transaction.status.receipts;
3501
+ }
3502
+ const receipts = txReceipts.map(processGqlReceipt) || [];
3503
+ const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
3504
+ const gasPrice = await this.provider.getLatestGasPrice();
3505
+ const maxInputs = this.provider.getChain().consensusParameters.txParameters.maxInputs;
3358
3506
  const transactionSummary = assembleTransactionSummary({
3359
3507
  id: this.id,
3360
3508
  receipts,
3361
3509
  transaction: decodedTransaction,
3362
- transactionBytes: (0, import_utils21.arrayify)(transaction.rawPayload),
3510
+ transactionBytes: (0, import_utils20.arrayify)(transaction.rawPayload),
3363
3511
  gqlTransactionStatus: transaction.status,
3364
3512
  gasPerByte,
3365
3513
  gasPriceFactor,
3366
3514
  abiMap: contractsAbiMap,
3367
3515
  maxInputs,
3368
- gasCosts
3516
+ gasCosts,
3517
+ maxGasPerTx,
3518
+ gasPrice
3369
3519
  });
3370
3520
  return transactionSummary;
3371
3521
  }
@@ -3471,7 +3621,7 @@ function autoRetryFetch(fetchFn, options, retryAttemptNum = 0) {
3471
3621
  }
3472
3622
 
3473
3623
  // src/providers/utils/merge-quantities.ts
3474
- var mergeQuantities = (arr1, arr2) => {
3624
+ var mergeQuantities = (...coinQuantities) => {
3475
3625
  const resultMap = {};
3476
3626
  function addToMap({ amount, assetId }) {
3477
3627
  if (resultMap[assetId]) {
@@ -3480,8 +3630,7 @@ var mergeQuantities = (arr1, arr2) => {
3480
3630
  resultMap[assetId] = amount;
3481
3631
  }
3482
3632
  }
3483
- arr1.forEach(addToMap);
3484
- arr2.forEach(addToMap);
3633
+ coinQuantities.forEach((arr) => arr.forEach(addToMap));
3485
3634
  return Object.entries(resultMap).map(([assetId, amount]) => ({ assetId, amount }));
3486
3635
  };
3487
3636
 
@@ -3489,32 +3638,60 @@ var mergeQuantities = (arr1, arr2) => {
3489
3638
  var MAX_RETRIES = 10;
3490
3639
  var processGqlChain = (chain) => {
3491
3640
  const { name, daHeight, consensusParameters, latestBlock } = chain;
3492
- const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
3641
+ const {
3642
+ contractParams,
3643
+ feeParams,
3644
+ predicateParams,
3645
+ scriptParams,
3646
+ txParams,
3647
+ gasCosts,
3648
+ baseAssetId,
3649
+ chainId,
3650
+ version
3651
+ } = consensusParameters;
3493
3652
  return {
3494
3653
  name,
3495
- baseChainHeight: (0, import_math15.bn)(daHeight),
3654
+ baseChainHeight: (0, import_math17.bn)(daHeight),
3496
3655
  consensusParameters: {
3497
- contractMaxSize: (0, import_math15.bn)(contractParams.contractMaxSize),
3498
- maxInputs: (0, import_math15.bn)(txParams.maxInputs),
3499
- maxOutputs: (0, import_math15.bn)(txParams.maxOutputs),
3500
- maxWitnesses: (0, import_math15.bn)(txParams.maxWitnesses),
3501
- maxGasPerTx: (0, import_math15.bn)(txParams.maxGasPerTx),
3502
- maxScriptLength: (0, import_math15.bn)(scriptParams.maxScriptLength),
3503
- maxScriptDataLength: (0, import_math15.bn)(scriptParams.maxScriptDataLength),
3504
- maxStorageSlots: (0, import_math15.bn)(contractParams.maxStorageSlots),
3505
- maxPredicateLength: (0, import_math15.bn)(predicateParams.maxPredicateLength),
3506
- maxPredicateDataLength: (0, import_math15.bn)(predicateParams.maxPredicateDataLength),
3507
- maxGasPerPredicate: (0, import_math15.bn)(predicateParams.maxGasPerPredicate),
3508
- gasPriceFactor: (0, import_math15.bn)(feeParams.gasPriceFactor),
3509
- gasPerByte: (0, import_math15.bn)(feeParams.gasPerByte),
3510
- maxMessageDataLength: (0, import_math15.bn)(predicateParams.maxMessageDataLength),
3511
- chainId: (0, import_math15.bn)(consensusParameters.chainId),
3656
+ version,
3657
+ chainId: (0, import_math17.bn)(chainId),
3658
+ baseAssetId,
3659
+ feeParameters: {
3660
+ version: feeParams.version,
3661
+ gasPerByte: (0, import_math17.bn)(feeParams.gasPerByte),
3662
+ gasPriceFactor: (0, import_math17.bn)(feeParams.gasPriceFactor)
3663
+ },
3664
+ contractParameters: {
3665
+ version: contractParams.version,
3666
+ contractMaxSize: (0, import_math17.bn)(contractParams.contractMaxSize),
3667
+ maxStorageSlots: (0, import_math17.bn)(contractParams.maxStorageSlots)
3668
+ },
3669
+ txParameters: {
3670
+ version: txParams.version,
3671
+ maxInputs: (0, import_math17.bn)(txParams.maxInputs),
3672
+ maxOutputs: (0, import_math17.bn)(txParams.maxOutputs),
3673
+ maxWitnesses: (0, import_math17.bn)(txParams.maxWitnesses),
3674
+ maxGasPerTx: (0, import_math17.bn)(txParams.maxGasPerTx),
3675
+ maxSize: (0, import_math17.bn)(txParams.maxSize),
3676
+ maxBytecodeSubsections: (0, import_math17.bn)(txParams.maxBytecodeSubsections)
3677
+ },
3678
+ predicateParameters: {
3679
+ version: predicateParams.version,
3680
+ maxPredicateLength: (0, import_math17.bn)(predicateParams.maxPredicateLength),
3681
+ maxPredicateDataLength: (0, import_math17.bn)(predicateParams.maxPredicateDataLength),
3682
+ maxGasPerPredicate: (0, import_math17.bn)(predicateParams.maxGasPerPredicate),
3683
+ maxMessageDataLength: (0, import_math17.bn)(predicateParams.maxMessageDataLength)
3684
+ },
3685
+ scriptParameters: {
3686
+ version: scriptParams.version,
3687
+ maxScriptLength: (0, import_math17.bn)(scriptParams.maxScriptLength),
3688
+ maxScriptDataLength: (0, import_math17.bn)(scriptParams.maxScriptDataLength)
3689
+ },
3512
3690
  gasCosts
3513
3691
  },
3514
- gasCosts,
3515
3692
  latestBlock: {
3516
3693
  id: latestBlock.id,
3517
- height: (0, import_math15.bn)(latestBlock.header.height),
3694
+ height: (0, import_math17.bn)(latestBlock.height),
3518
3695
  time: latestBlock.header.time,
3519
3696
  transactions: latestBlock.transactions.map((i) => ({
3520
3697
  id: i.id
@@ -3608,10 +3785,13 @@ var _Provider = class {
3608
3785
  * Returns some helpful parameters related to gas fees.
3609
3786
  */
3610
3787
  getGasConfig() {
3611
- const { minGasPrice } = this.getNode();
3612
- const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
3788
+ const {
3789
+ txParameters: { maxGasPerTx },
3790
+ predicateParameters: { maxGasPerPredicate },
3791
+ feeParameters: { gasPriceFactor, gasPerByte },
3792
+ gasCosts
3793
+ } = this.getChain().consensusParameters;
3613
3794
  return {
3614
- minGasPrice,
3615
3795
  maxGasPerTx,
3616
3796
  maxGasPerPredicate,
3617
3797
  gasPriceFactor,
@@ -3659,7 +3839,18 @@ var _Provider = class {
3659
3839
  createOperations() {
3660
3840
  const fetchFn = _Provider.getFetchFn(this.options);
3661
3841
  const gqlClient = new import_graphql_request.GraphQLClient(this.url, {
3662
- fetch: (url, requestInit) => fetchFn(url, requestInit, this.options)
3842
+ fetch: (url, requestInit) => fetchFn(url, requestInit, this.options),
3843
+ responseMiddleware: (response) => {
3844
+ if ("response" in response) {
3845
+ const graphQlResponse = response.response;
3846
+ if (Array.isArray(graphQlResponse?.errors)) {
3847
+ throw new import_errors14.FuelError(
3848
+ import_errors14.FuelError.CODES.INVALID_REQUEST,
3849
+ graphQlResponse.errors.map((err) => err.message).join("\n\n")
3850
+ );
3851
+ }
3852
+ }
3853
+ }
3663
3854
  });
3664
3855
  const executeQuery = (query, vars) => {
3665
3856
  const opDefinition = query.definitions.find((x) => x.kind === "OperationDefinition");
@@ -3687,21 +3878,6 @@ var _Provider = class {
3687
3878
  } = await this.operations.getVersion();
3688
3879
  return nodeVersion;
3689
3880
  }
3690
- /**
3691
- * @hidden
3692
- *
3693
- * Returns the network configuration of the connected Fuel node.
3694
- *
3695
- * @returns A promise that resolves to the network configuration object
3696
- */
3697
- async getNetwork() {
3698
- const {
3699
- name,
3700
- consensusParameters: { chainId }
3701
- } = await this.getChain();
3702
- const network = new import_ethers.Network(name, chainId.toNumber());
3703
- return Promise.resolve(network);
3704
- }
3705
3881
  /**
3706
3882
  * Returns the block number.
3707
3883
  *
@@ -3709,7 +3885,7 @@ var _Provider = class {
3709
3885
  */
3710
3886
  async getBlockNumber() {
3711
3887
  const { chain } = await this.operations.getChain();
3712
- return (0, import_math15.bn)(chain.latestBlock.header.height, 10);
3888
+ return (0, import_math17.bn)(chain.latestBlock.height, 10);
3713
3889
  }
3714
3890
  /**
3715
3891
  * Returns the chain information.
@@ -3719,13 +3895,11 @@ var _Provider = class {
3719
3895
  async fetchNode() {
3720
3896
  const { nodeInfo } = await this.operations.getNodeInfo();
3721
3897
  const processedNodeInfo = {
3722
- maxDepth: (0, import_math15.bn)(nodeInfo.maxDepth),
3723
- maxTx: (0, import_math15.bn)(nodeInfo.maxTx),
3724
- minGasPrice: (0, import_math15.bn)(nodeInfo.minGasPrice),
3898
+ maxDepth: (0, import_math17.bn)(nodeInfo.maxDepth),
3899
+ maxTx: (0, import_math17.bn)(nodeInfo.maxTx),
3725
3900
  nodeVersion: nodeInfo.nodeVersion,
3726
3901
  utxoValidation: nodeInfo.utxoValidation,
3727
- vmBacktrace: nodeInfo.vmBacktrace,
3728
- peers: nodeInfo.peers
3902
+ vmBacktrace: nodeInfo.vmBacktrace
3729
3903
  };
3730
3904
  _Provider.nodeInfoCache[this.url] = processedNodeInfo;
3731
3905
  return processedNodeInfo;
@@ -3751,6 +3925,17 @@ var _Provider = class {
3751
3925
  } = this.getChain();
3752
3926
  return chainId.toNumber();
3753
3927
  }
3928
+ /**
3929
+ * Returns the base asset ID for the current provider network
3930
+ *
3931
+ * @returns the base asset ID
3932
+ */
3933
+ getBaseAssetId() {
3934
+ const {
3935
+ consensusParameters: { baseAssetId }
3936
+ } = this.getChain();
3937
+ return baseAssetId;
3938
+ }
3754
3939
  /**
3755
3940
  * Submits a transaction to the chain to be executed.
3756
3941
  *
@@ -3767,9 +3952,9 @@ var _Provider = class {
3767
3952
  if (estimateTxDependencies) {
3768
3953
  await this.estimateTxDependencies(transactionRequest);
3769
3954
  }
3770
- const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
3955
+ const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
3771
3956
  let abis;
3772
- if (transactionRequest.type === import_transactions18.TransactionType.Script) {
3957
+ if (transactionRequest.type === import_transactions19.TransactionType.Script) {
3773
3958
  abis = transactionRequest.abis;
3774
3959
  }
3775
3960
  if (awaitExecution) {
@@ -3810,15 +3995,14 @@ var _Provider = class {
3810
3995
  if (estimateTxDependencies) {
3811
3996
  return this.estimateTxDependencies(transactionRequest);
3812
3997
  }
3813
- const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
3814
- const { dryRun: gqlReceipts } = await this.operations.dryRun({
3815
- encodedTransaction,
3998
+ const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
3999
+ const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4000
+ encodedTransactions: encodedTransaction,
3816
4001
  utxoValidation: utxoValidation || false
3817
4002
  });
3818
- const receipts = gqlReceipts.map(processGqlReceipt);
3819
- return {
3820
- receipts
3821
- };
4003
+ const [{ receipts: rawReceipts, status: dryRunStatus }] = dryRunStatuses;
4004
+ const receipts = rawReceipts.map(processGqlReceipt);
4005
+ return { receipts, dryRunStatus };
3822
4006
  }
3823
4007
  /**
3824
4008
  * Verifies whether enough gas is available to complete transaction.
@@ -3829,13 +4013,13 @@ var _Provider = class {
3829
4013
  async estimatePredicates(transactionRequest) {
3830
4014
  const shouldEstimatePredicates = Boolean(
3831
4015
  transactionRequest.inputs.find(
3832
- (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()
4016
+ (input) => "predicate" in input && input.predicate && !(0, import_utils23.equalBytes)((0, import_utils22.arrayify)(input.predicate), (0, import_utils22.arrayify)("0x")) && new import_math17.BN(input.predicateGasUsed).isZero()
3833
4017
  )
3834
4018
  );
3835
4019
  if (!shouldEstimatePredicates) {
3836
4020
  return transactionRequest;
3837
4021
  }
3838
- const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
4022
+ const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
3839
4023
  const response = await this.operations.estimatePredicates({
3840
4024
  encodedTransaction
3841
4025
  });
@@ -3844,7 +4028,7 @@ var _Provider = class {
3844
4028
  } = response;
3845
4029
  if (inputs) {
3846
4030
  inputs.forEach((input, index) => {
3847
- if ("predicateGasUsed" in input && (0, import_math15.bn)(input.predicateGasUsed).gt(0)) {
4031
+ if ("predicateGasUsed" in input && (0, import_math17.bn)(input.predicateGasUsed).gt(0)) {
3848
4032
  transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
3849
4033
  }
3850
4034
  });
@@ -3857,31 +4041,31 @@ var _Provider = class {
3857
4041
  * If there are missing variable outputs,
3858
4042
  * `addVariableOutputs` is called on the transaction.
3859
4043
  *
3860
- * @privateRemarks
3861
- * TODO: Investigate support for missing contract IDs
3862
- * TODO: Add support for missing output messages
3863
4044
  *
3864
4045
  * @param transactionRequest - The transaction request object.
3865
4046
  * @returns A promise.
3866
4047
  */
3867
4048
  async estimateTxDependencies(transactionRequest) {
3868
- if (transactionRequest.type === import_transactions18.TransactionType.Create) {
4049
+ if (transactionRequest.type === import_transactions19.TransactionType.Create) {
3869
4050
  return {
3870
4051
  receipts: [],
3871
4052
  outputVariables: 0,
3872
4053
  missingContractIds: []
3873
4054
  };
3874
4055
  }
3875
- await this.estimatePredicates(transactionRequest);
3876
4056
  let receipts = [];
3877
4057
  const missingContractIds = [];
3878
4058
  let outputVariables = 0;
4059
+ let dryRunStatus;
3879
4060
  for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
3880
- const { dryRun: gqlReceipts } = await this.operations.dryRun({
3881
- encodedTransaction: (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes()),
4061
+ const {
4062
+ dryRun: [{ receipts: rawReceipts, status }]
4063
+ } = await this.operations.dryRun({
4064
+ encodedTransactions: [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())],
3882
4065
  utxoValidation: false
3883
4066
  });
3884
- receipts = gqlReceipts.map(processGqlReceipt);
4067
+ receipts = rawReceipts.map(processGqlReceipt);
4068
+ dryRunStatus = status;
3885
4069
  const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
3886
4070
  const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
3887
4071
  if (hasMissingOutputs) {
@@ -3891,6 +4075,10 @@ var _Provider = class {
3891
4075
  transactionRequest.addContractInputAndOutput(import_address3.Address.fromString(contractId));
3892
4076
  missingContractIds.push(contractId);
3893
4077
  });
4078
+ const { maxFee } = await this.estimateTxGasAndFee({
4079
+ transactionRequest
4080
+ });
4081
+ transactionRequest.maxFee = maxFee;
3894
4082
  } else {
3895
4083
  break;
3896
4084
  }
@@ -3898,37 +4086,136 @@ var _Provider = class {
3898
4086
  return {
3899
4087
  receipts,
3900
4088
  outputVariables,
3901
- missingContractIds
4089
+ missingContractIds,
4090
+ dryRunStatus
3902
4091
  };
3903
4092
  }
4093
+ /**
4094
+ * Dry runs multiple transactions and checks for missing dependencies in batches.
4095
+ *
4096
+ * Transactions are dry run in batches. After each dry run, transactions requiring
4097
+ * further modifications are identified. The method iteratively updates these transactions
4098
+ * and performs subsequent dry runs until all dependencies for each transaction are satisfied.
4099
+ *
4100
+ * @param transactionRequests - Array of transaction request objects.
4101
+ * @returns A promise that resolves to an array of results for each transaction.
4102
+ */
4103
+ async estimateMultipleTxDependencies(transactionRequests) {
4104
+ const results = transactionRequests.map(() => ({
4105
+ receipts: [],
4106
+ outputVariables: 0,
4107
+ missingContractIds: [],
4108
+ dryRunStatus: void 0
4109
+ }));
4110
+ const allRequests = (0, import_ramda3.clone)(transactionRequests);
4111
+ const serializedTransactionsMap = /* @__PURE__ */ new Map();
4112
+ allRequests.forEach((req, index) => {
4113
+ if (req.type === import_transactions19.TransactionType.Script) {
4114
+ serializedTransactionsMap.set(index, (0, import_utils22.hexlify)(req.toTransactionBytes()));
4115
+ }
4116
+ });
4117
+ let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
4118
+ let attempt = 0;
4119
+ while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
4120
+ const encodedTransactions = transactionsToProcess.map(
4121
+ (index) => serializedTransactionsMap.get(index)
4122
+ );
4123
+ const dryRunResults = await this.operations.dryRun({
4124
+ encodedTransactions,
4125
+ utxoValidation: false
4126
+ });
4127
+ const nextRoundTransactions = [];
4128
+ for (let i = 0; i < dryRunResults.dryRun.length; i++) {
4129
+ const requestIdx = transactionsToProcess[i];
4130
+ const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
4131
+ const result = results[requestIdx];
4132
+ result.receipts = rawReceipts.map(processGqlReceipt);
4133
+ result.dryRunStatus = status;
4134
+ const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
4135
+ result.receipts
4136
+ );
4137
+ const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
4138
+ const request = allRequests[requestIdx];
4139
+ if (hasMissingOutputs && request?.type === import_transactions19.TransactionType.Script) {
4140
+ result.outputVariables += missingOutputVariables.length;
4141
+ request.addVariableOutputs(missingOutputVariables.length);
4142
+ missingOutputContractIds.forEach(({ contractId }) => {
4143
+ request.addContractInputAndOutput(import_address3.Address.fromString(contractId));
4144
+ result.missingContractIds.push(contractId);
4145
+ });
4146
+ const { maxFee } = await this.estimateTxGasAndFee({
4147
+ transactionRequest: request
4148
+ });
4149
+ request.maxFee = maxFee;
4150
+ serializedTransactionsMap.set(requestIdx, (0, import_utils22.hexlify)(request.toTransactionBytes()));
4151
+ nextRoundTransactions.push(requestIdx);
4152
+ }
4153
+ }
4154
+ transactionsToProcess = nextRoundTransactions;
4155
+ attempt += 1;
4156
+ }
4157
+ return results;
4158
+ }
4159
+ async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
4160
+ if (estimateTxDependencies) {
4161
+ return this.estimateMultipleTxDependencies(transactionRequests);
4162
+ }
4163
+ const encodedTransactions = transactionRequests.map((tx) => (0, import_utils22.hexlify)(tx.toTransactionBytes()));
4164
+ const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4165
+ encodedTransactions,
4166
+ utxoValidation: utxoValidation || false
4167
+ });
4168
+ const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
4169
+ const receipts = rawReceipts.map(processGqlReceipt);
4170
+ return { receipts, dryRunStatus: status };
4171
+ });
4172
+ return results;
4173
+ }
3904
4174
  /**
3905
4175
  * Estimates the transaction gas and fee based on the provided transaction request.
3906
4176
  * @param transactionRequest - The transaction request object.
3907
4177
  * @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
3908
4178
  */
3909
- estimateTxGasAndFee(params) {
4179
+ async estimateTxGasAndFee(params) {
3910
4180
  const { transactionRequest } = params;
3911
- const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
4181
+ let { gasPrice } = params;
3912
4182
  const chainInfo = this.getChain();
3913
- const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
3914
- transactionRequest.gasPrice = gasPrice;
4183
+ const { gasPriceFactor, maxGasPerTx } = this.getGasConfig();
3915
4184
  const minGas = transactionRequest.calculateMinGas(chainInfo);
3916
- const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
3917
- if (transactionRequest.type === import_transactions18.TransactionType.Script) {
4185
+ if (!gasPrice) {
4186
+ gasPrice = await this.estimateGasPrice(10);
4187
+ }
4188
+ const minFee = calculateGasFee({
4189
+ gasPrice: (0, import_math17.bn)(gasPrice),
4190
+ gas: minGas,
4191
+ priceFactor: gasPriceFactor,
4192
+ tip: transactionRequest.tip
4193
+ }).add(1);
4194
+ let gasLimit = (0, import_math17.bn)(0);
4195
+ if (transactionRequest.type === import_transactions19.TransactionType.Script) {
4196
+ gasLimit = transactionRequest.gasLimit;
3918
4197
  if (transactionRequest.gasLimit.eq(0)) {
3919
4198
  transactionRequest.gasLimit = minGas;
3920
4199
  transactionRequest.gasLimit = maxGasPerTx.sub(
3921
4200
  transactionRequest.calculateMaxGas(chainInfo, minGas)
3922
4201
  );
4202
+ gasLimit = transactionRequest.gasLimit;
3923
4203
  }
3924
4204
  }
3925
4205
  const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
3926
- const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
4206
+ const maxFee = calculateGasFee({
4207
+ gasPrice: (0, import_math17.bn)(gasPrice),
4208
+ gas: maxGas,
4209
+ priceFactor: gasPriceFactor,
4210
+ tip: transactionRequest.tip
4211
+ }).add(1);
3927
4212
  return {
3928
4213
  minGas,
3929
4214
  minFee,
3930
4215
  maxGas,
3931
- maxFee
4216
+ maxFee,
4217
+ gasPrice,
4218
+ gasLimit
3932
4219
  };
3933
4220
  }
3934
4221
  /**
@@ -3946,15 +4233,17 @@ var _Provider = class {
3946
4233
  if (estimateTxDependencies) {
3947
4234
  return this.estimateTxDependencies(transactionRequest);
3948
4235
  }
3949
- const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
3950
- const { dryRun: gqlReceipts } = await this.operations.dryRun({
3951
- encodedTransaction,
4236
+ const encodedTransactions = [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())];
4237
+ const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4238
+ encodedTransactions,
3952
4239
  utxoValidation: true
3953
4240
  });
3954
- const receipts = gqlReceipts.map(processGqlReceipt);
3955
- return {
3956
- receipts
3957
- };
4241
+ const callResult = dryRunStatuses.map((dryRunStatus) => {
4242
+ const { id, receipts, status } = dryRunStatus;
4243
+ const processedReceipts = receipts.map(processGqlReceipt);
4244
+ return { id, receipts: processedReceipts, status };
4245
+ });
4246
+ return { receipts: callResult[0].receipts };
3958
4247
  }
3959
4248
  /**
3960
4249
  * Returns a transaction cost to enable user
@@ -3971,77 +4260,79 @@ var _Provider = class {
3971
4260
  * @param tolerance - The tolerance to add on top of the gasUsed.
3972
4261
  * @returns A promise that resolves to the transaction cost object.
3973
4262
  */
3974
- async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
3975
- estimateTxDependencies = true,
3976
- estimatePredicates = true,
3977
- resourcesOwner,
3978
- signatureCallback
3979
- } = {}) {
4263
+ async getTransactionCost(transactionRequestLike, { resourcesOwner, signatureCallback, quantitiesToContract = [] } = {}) {
3980
4264
  const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
3981
- const { minGasPrice } = this.getGasConfig();
3982
- const setGasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
3983
- const isScriptTransaction = txRequestClone.type === import_transactions18.TransactionType.Script;
4265
+ const isScriptTransaction = txRequestClone.type === import_transactions19.TransactionType.Script;
4266
+ const baseAssetId = this.getBaseAssetId();
3984
4267
  const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
3985
- const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
3986
- txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
4268
+ const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
4269
+ txRequestClone.fundWithFakeUtxos(allQuantities, baseAssetId, resourcesOwner?.address);
4270
+ txRequestClone.maxFee = (0, import_math17.bn)(0);
3987
4271
  if (isScriptTransaction) {
3988
- txRequestClone.gasLimit = (0, import_math15.bn)(0);
4272
+ txRequestClone.gasLimit = (0, import_math17.bn)(0);
3989
4273
  }
3990
- if (estimatePredicates) {
3991
- if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
3992
- resourcesOwner.populateTransactionPredicateData(txRequestClone);
3993
- }
3994
- await this.estimatePredicates(txRequestClone);
4274
+ if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
4275
+ resourcesOwner.populateTransactionPredicateData(txRequestClone);
3995
4276
  }
4277
+ const signedRequest = (0, import_ramda3.clone)(txRequestClone);
4278
+ let addedSignatures = 0;
3996
4279
  if (signatureCallback && isScriptTransaction) {
3997
- await signatureCallback(txRequestClone);
4280
+ const lengthBefore = signedRequest.witnesses.length;
4281
+ await signatureCallback(signedRequest);
4282
+ addedSignatures = signedRequest.witnesses.length - lengthBefore;
3998
4283
  }
3999
- let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
4000
- transactionRequest: txRequestClone
4284
+ await this.estimatePredicates(signedRequest);
4285
+ let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
4286
+ transactionRequest: signedRequest
4001
4287
  });
4002
4288
  let receipts = [];
4289
+ let dryRunStatus;
4003
4290
  let missingContractIds = [];
4004
4291
  let outputVariables = 0;
4005
- let gasUsed = (0, import_math15.bn)(0);
4006
- if (isScriptTransaction && estimateTxDependencies) {
4007
- txRequestClone.gasPrice = (0, import_math15.bn)(0);
4008
- const result = await this.estimateTxDependencies(txRequestClone);
4009
- receipts = result.receipts;
4010
- outputVariables = result.outputVariables;
4011
- missingContractIds = result.missingContractIds;
4292
+ let gasUsed = (0, import_math17.bn)(0);
4293
+ txRequestClone.updatePredicateGasUsed(signedRequest.inputs);
4294
+ txRequestClone.maxFee = maxFee;
4295
+ if (isScriptTransaction) {
4296
+ txRequestClone.gasLimit = gasLimit;
4297
+ if (signatureCallback) {
4298
+ await signatureCallback(txRequestClone);
4299
+ }
4300
+ ({ receipts, missingContractIds, outputVariables, dryRunStatus } = await this.estimateTxDependencies(txRequestClone));
4012
4301
  gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
4013
4302
  txRequestClone.gasLimit = gasUsed;
4014
- txRequestClone.gasPrice = setGasPrice;
4015
- ({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
4016
- transactionRequest: txRequestClone
4303
+ ({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
4304
+ transactionRequest: txRequestClone,
4305
+ gasPrice
4017
4306
  }));
4018
4307
  }
4019
4308
  return {
4020
4309
  requiredQuantities: allQuantities,
4021
4310
  receipts,
4022
4311
  gasUsed,
4023
- minGasPrice,
4024
- gasPrice: setGasPrice,
4312
+ gasPrice,
4025
4313
  minGas,
4026
4314
  maxGas,
4027
4315
  minFee,
4028
4316
  maxFee,
4029
- estimatedInputs: txRequestClone.inputs,
4030
4317
  outputVariables,
4031
- missingContractIds
4318
+ missingContractIds,
4319
+ addedSignatures,
4320
+ estimatedPredicates: txRequestClone.inputs,
4321
+ dryRunStatus
4032
4322
  };
4033
4323
  }
4034
- async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
4324
+ async getResourcesForTransaction(owner, transactionRequestLike, quantitiesToContract = []) {
4035
4325
  const ownerAddress = import_address3.Address.fromAddressOrString(owner);
4036
4326
  const transactionRequest = transactionRequestify((0, import_ramda3.clone)(transactionRequestLike));
4037
- const transactionCost = await this.getTransactionCost(transactionRequest, forwardingQuantities);
4327
+ const transactionCost = await this.getTransactionCost(transactionRequest, {
4328
+ quantitiesToContract
4329
+ });
4038
4330
  transactionRequest.addResources(
4039
4331
  await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
4040
4332
  );
4041
- const { requiredQuantities, ...txCost } = await this.getTransactionCost(
4042
- transactionRequest,
4043
- forwardingQuantities
4044
- );
4333
+ const { requiredQuantities, ...txCost } = await this.getTransactionCost(transactionRequest, {
4334
+ quantitiesToContract
4335
+ });
4045
4336
  const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
4046
4337
  return {
4047
4338
  resources,
@@ -4057,17 +4348,16 @@ var _Provider = class {
4057
4348
  const result = await this.operations.getCoins({
4058
4349
  first: 10,
4059
4350
  ...paginationArgs,
4060
- filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils23.hexlify)(assetId) }
4351
+ filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils22.hexlify)(assetId) }
4061
4352
  });
4062
4353
  const coins = result.coins.edges.map((edge) => edge.node);
4063
4354
  return coins.map((coin) => ({
4064
4355
  id: coin.utxoId,
4065
4356
  assetId: coin.assetId,
4066
- amount: (0, import_math15.bn)(coin.amount),
4357
+ amount: (0, import_math17.bn)(coin.amount),
4067
4358
  owner: import_address3.Address.fromAddressOrString(coin.owner),
4068
- maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
4069
- blockCreated: (0, import_math15.bn)(coin.blockCreated),
4070
- txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
4359
+ blockCreated: (0, import_math17.bn)(coin.blockCreated),
4360
+ txCreatedIdx: (0, import_math17.bn)(coin.txCreatedIdx)
4071
4361
  }));
4072
4362
  }
4073
4363
  /**
@@ -4081,19 +4371,19 @@ var _Provider = class {
4081
4371
  async getResourcesToSpend(owner, quantities, excludedIds) {
4082
4372
  const ownerAddress = import_address3.Address.fromAddressOrString(owner);
4083
4373
  const excludeInput = {
4084
- messages: excludedIds?.messages?.map((nonce) => (0, import_utils23.hexlify)(nonce)) || [],
4085
- utxos: excludedIds?.utxos?.map((id) => (0, import_utils23.hexlify)(id)) || []
4374
+ messages: excludedIds?.messages?.map((nonce) => (0, import_utils22.hexlify)(nonce)) || [],
4375
+ utxos: excludedIds?.utxos?.map((id) => (0, import_utils22.hexlify)(id)) || []
4086
4376
  };
4087
4377
  if (this.cache) {
4088
4378
  const uniqueUtxos = new Set(
4089
- excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils23.hexlify)(id)))
4379
+ excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils22.hexlify)(id)))
4090
4380
  );
4091
4381
  excludeInput.utxos = Array.from(uniqueUtxos);
4092
4382
  }
4093
4383
  const coinsQuery = {
4094
4384
  owner: ownerAddress.toB256(),
4095
4385
  queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
4096
- assetId: (0, import_utils23.hexlify)(assetId),
4386
+ assetId: (0, import_utils22.hexlify)(assetId),
4097
4387
  amount: amount.toString(10),
4098
4388
  max: maxPerAsset ? maxPerAsset.toString(10) : void 0
4099
4389
  })),
@@ -4104,9 +4394,9 @@ var _Provider = class {
4104
4394
  switch (coin.__typename) {
4105
4395
  case "MessageCoin":
4106
4396
  return {
4107
- amount: (0, import_math15.bn)(coin.amount),
4397
+ amount: (0, import_math17.bn)(coin.amount),
4108
4398
  assetId: coin.assetId,
4109
- daHeight: (0, import_math15.bn)(coin.daHeight),
4399
+ daHeight: (0, import_math17.bn)(coin.daHeight),
4110
4400
  sender: import_address3.Address.fromAddressOrString(coin.sender),
4111
4401
  recipient: import_address3.Address.fromAddressOrString(coin.recipient),
4112
4402
  nonce: coin.nonce
@@ -4114,12 +4404,11 @@ var _Provider = class {
4114
4404
  case "Coin":
4115
4405
  return {
4116
4406
  id: coin.utxoId,
4117
- amount: (0, import_math15.bn)(coin.amount),
4407
+ amount: (0, import_math17.bn)(coin.amount),
4118
4408
  assetId: coin.assetId,
4119
4409
  owner: import_address3.Address.fromAddressOrString(coin.owner),
4120
- maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
4121
- blockCreated: (0, import_math15.bn)(coin.blockCreated),
4122
- txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
4410
+ blockCreated: (0, import_math17.bn)(coin.blockCreated),
4411
+ txCreatedIdx: (0, import_math17.bn)(coin.txCreatedIdx)
4123
4412
  };
4124
4413
  default:
4125
4414
  return null;
@@ -4136,13 +4425,13 @@ var _Provider = class {
4136
4425
  async getBlock(idOrHeight) {
4137
4426
  let variables;
4138
4427
  if (typeof idOrHeight === "number") {
4139
- variables = { height: (0, import_math15.bn)(idOrHeight).toString(10) };
4428
+ variables = { height: (0, import_math17.bn)(idOrHeight).toString(10) };
4140
4429
  } else if (idOrHeight === "latest") {
4141
4430
  variables = { height: (await this.getBlockNumber()).toString(10) };
4142
4431
  } else if (idOrHeight.length === 66) {
4143
4432
  variables = { blockId: idOrHeight };
4144
4433
  } else {
4145
- variables = { blockId: (0, import_math15.bn)(idOrHeight).toString(10) };
4434
+ variables = { blockId: (0, import_math17.bn)(idOrHeight).toString(10) };
4146
4435
  }
4147
4436
  const { block } = await this.operations.getBlock(variables);
4148
4437
  if (!block) {
@@ -4150,7 +4439,7 @@ var _Provider = class {
4150
4439
  }
4151
4440
  return {
4152
4441
  id: block.id,
4153
- height: (0, import_math15.bn)(block.header.height),
4442
+ height: (0, import_math17.bn)(block.height),
4154
4443
  time: block.header.time,
4155
4444
  transactionIds: block.transactions.map((tx) => tx.id)
4156
4445
  };
@@ -4165,7 +4454,7 @@ var _Provider = class {
4165
4454
  const { blocks: fetchedData } = await this.operations.getBlocks(params);
4166
4455
  const blocks = fetchedData.edges.map(({ node: block }) => ({
4167
4456
  id: block.id,
4168
- height: (0, import_math15.bn)(block.header.height),
4457
+ height: (0, import_math17.bn)(block.height),
4169
4458
  time: block.header.time,
4170
4459
  transactionIds: block.transactions.map((tx) => tx.id)
4171
4460
  }));
@@ -4180,7 +4469,7 @@ var _Provider = class {
4180
4469
  async getBlockWithTransactions(idOrHeight) {
4181
4470
  let variables;
4182
4471
  if (typeof idOrHeight === "number") {
4183
- variables = { blockHeight: (0, import_math15.bn)(idOrHeight).toString(10) };
4472
+ variables = { blockHeight: (0, import_math17.bn)(idOrHeight).toString(10) };
4184
4473
  } else if (idOrHeight === "latest") {
4185
4474
  variables = { blockHeight: (await this.getBlockNumber()).toString() };
4186
4475
  } else {
@@ -4192,11 +4481,11 @@ var _Provider = class {
4192
4481
  }
4193
4482
  return {
4194
4483
  id: block.id,
4195
- height: (0, import_math15.bn)(block.header.height, 10),
4484
+ height: (0, import_math17.bn)(block.height, 10),
4196
4485
  time: block.header.time,
4197
4486
  transactionIds: block.transactions.map((tx) => tx.id),
4198
4487
  transactions: block.transactions.map(
4199
- (tx) => new import_transactions18.TransactionCoder().decode((0, import_utils23.arrayify)(tx.rawPayload), 0)?.[0]
4488
+ (tx) => new import_transactions19.TransactionCoder().decode((0, import_utils22.arrayify)(tx.rawPayload), 0)?.[0]
4200
4489
  )
4201
4490
  };
4202
4491
  }
@@ -4211,8 +4500,8 @@ var _Provider = class {
4211
4500
  if (!transaction) {
4212
4501
  return null;
4213
4502
  }
4214
- return new import_transactions18.TransactionCoder().decode(
4215
- (0, import_utils23.arrayify)(transaction.rawPayload),
4503
+ return new import_transactions19.TransactionCoder().decode(
4504
+ (0, import_utils22.arrayify)(transaction.rawPayload),
4216
4505
  0
4217
4506
  )?.[0];
4218
4507
  }
@@ -4239,9 +4528,9 @@ var _Provider = class {
4239
4528
  async getContractBalance(contractId, assetId) {
4240
4529
  const { contractBalance } = await this.operations.getContractBalance({
4241
4530
  contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
4242
- asset: (0, import_utils23.hexlify)(assetId)
4531
+ asset: (0, import_utils22.hexlify)(assetId)
4243
4532
  });
4244
- return (0, import_math15.bn)(contractBalance.amount, 10);
4533
+ return (0, import_math17.bn)(contractBalance.amount, 10);
4245
4534
  }
4246
4535
  /**
4247
4536
  * Returns the balance for the given owner for the given asset ID.
@@ -4253,9 +4542,9 @@ var _Provider = class {
4253
4542
  async getBalance(owner, assetId) {
4254
4543
  const { balance } = await this.operations.getBalance({
4255
4544
  owner: import_address3.Address.fromAddressOrString(owner).toB256(),
4256
- assetId: (0, import_utils23.hexlify)(assetId)
4545
+ assetId: (0, import_utils22.hexlify)(assetId)
4257
4546
  });
4258
- return (0, import_math15.bn)(balance.amount, 10);
4547
+ return (0, import_math17.bn)(balance.amount, 10);
4259
4548
  }
4260
4549
  /**
4261
4550
  * Returns balances for the given owner.
@@ -4273,7 +4562,7 @@ var _Provider = class {
4273
4562
  const balances = result.balances.edges.map((edge) => edge.node);
4274
4563
  return balances.map((balance) => ({
4275
4564
  assetId: balance.assetId,
4276
- amount: (0, import_math15.bn)(balance.amount)
4565
+ amount: (0, import_math17.bn)(balance.amount)
4277
4566
  }));
4278
4567
  }
4279
4568
  /**
@@ -4291,19 +4580,19 @@ var _Provider = class {
4291
4580
  });
4292
4581
  const messages = result.messages.edges.map((edge) => edge.node);
4293
4582
  return messages.map((message) => ({
4294
- messageId: import_transactions18.InputMessageCoder.getMessageId({
4583
+ messageId: import_transactions19.InputMessageCoder.getMessageId({
4295
4584
  sender: message.sender,
4296
4585
  recipient: message.recipient,
4297
4586
  nonce: message.nonce,
4298
- amount: (0, import_math15.bn)(message.amount),
4587
+ amount: (0, import_math17.bn)(message.amount),
4299
4588
  data: message.data
4300
4589
  }),
4301
4590
  sender: import_address3.Address.fromAddressOrString(message.sender),
4302
4591
  recipient: import_address3.Address.fromAddressOrString(message.recipient),
4303
4592
  nonce: message.nonce,
4304
- amount: (0, import_math15.bn)(message.amount),
4305
- data: import_transactions18.InputMessageCoder.decodeData(message.data),
4306
- daHeight: (0, import_math15.bn)(message.daHeight)
4593
+ amount: (0, import_math17.bn)(message.amount),
4594
+ data: import_transactions19.InputMessageCoder.decodeData(message.data),
4595
+ daHeight: (0, import_math17.bn)(message.daHeight)
4307
4596
  }));
4308
4597
  }
4309
4598
  /**
@@ -4356,44 +4645,60 @@ var _Provider = class {
4356
4645
  } = result.messageProof;
4357
4646
  return {
4358
4647
  messageProof: {
4359
- proofIndex: (0, import_math15.bn)(messageProof.proofIndex),
4648
+ proofIndex: (0, import_math17.bn)(messageProof.proofIndex),
4360
4649
  proofSet: messageProof.proofSet
4361
4650
  },
4362
4651
  blockProof: {
4363
- proofIndex: (0, import_math15.bn)(blockProof.proofIndex),
4652
+ proofIndex: (0, import_math17.bn)(blockProof.proofIndex),
4364
4653
  proofSet: blockProof.proofSet
4365
4654
  },
4366
4655
  messageBlockHeader: {
4367
4656
  id: messageBlockHeader.id,
4368
- daHeight: (0, import_math15.bn)(messageBlockHeader.daHeight),
4369
- transactionsCount: (0, import_math15.bn)(messageBlockHeader.transactionsCount),
4657
+ daHeight: (0, import_math17.bn)(messageBlockHeader.daHeight),
4658
+ transactionsCount: Number(messageBlockHeader.transactionsCount),
4370
4659
  transactionsRoot: messageBlockHeader.transactionsRoot,
4371
- height: (0, import_math15.bn)(messageBlockHeader.height),
4660
+ height: (0, import_math17.bn)(messageBlockHeader.height),
4372
4661
  prevRoot: messageBlockHeader.prevRoot,
4373
4662
  time: messageBlockHeader.time,
4374
4663
  applicationHash: messageBlockHeader.applicationHash,
4375
- messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
4376
- messageReceiptCount: (0, import_math15.bn)(messageBlockHeader.messageReceiptCount)
4664
+ messageReceiptCount: Number(messageBlockHeader.messageReceiptCount),
4665
+ messageOutboxRoot: messageBlockHeader.messageOutboxRoot,
4666
+ consensusParametersVersion: Number(messageBlockHeader.consensusParametersVersion),
4667
+ eventInboxRoot: messageBlockHeader.eventInboxRoot,
4668
+ stateTransitionBytecodeVersion: Number(messageBlockHeader.stateTransitionBytecodeVersion)
4377
4669
  },
4378
4670
  commitBlockHeader: {
4379
4671
  id: commitBlockHeader.id,
4380
- daHeight: (0, import_math15.bn)(commitBlockHeader.daHeight),
4381
- transactionsCount: (0, import_math15.bn)(commitBlockHeader.transactionsCount),
4672
+ daHeight: (0, import_math17.bn)(commitBlockHeader.daHeight),
4673
+ transactionsCount: Number(commitBlockHeader.transactionsCount),
4382
4674
  transactionsRoot: commitBlockHeader.transactionsRoot,
4383
- height: (0, import_math15.bn)(commitBlockHeader.height),
4675
+ height: (0, import_math17.bn)(commitBlockHeader.height),
4384
4676
  prevRoot: commitBlockHeader.prevRoot,
4385
4677
  time: commitBlockHeader.time,
4386
4678
  applicationHash: commitBlockHeader.applicationHash,
4387
- messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
4388
- messageReceiptCount: (0, import_math15.bn)(commitBlockHeader.messageReceiptCount)
4679
+ messageReceiptCount: Number(commitBlockHeader.messageReceiptCount),
4680
+ messageOutboxRoot: commitBlockHeader.messageOutboxRoot,
4681
+ consensusParametersVersion: Number(commitBlockHeader.consensusParametersVersion),
4682
+ eventInboxRoot: commitBlockHeader.eventInboxRoot,
4683
+ stateTransitionBytecodeVersion: Number(commitBlockHeader.stateTransitionBytecodeVersion)
4389
4684
  },
4390
4685
  sender: import_address3.Address.fromAddressOrString(sender),
4391
4686
  recipient: import_address3.Address.fromAddressOrString(recipient),
4392
4687
  nonce,
4393
- amount: (0, import_math15.bn)(amount),
4688
+ amount: (0, import_math17.bn)(amount),
4394
4689
  data
4395
4690
  };
4396
4691
  }
4692
+ async getLatestGasPrice() {
4693
+ const { latestGasPrice } = await this.operations.getLatestGasPrice();
4694
+ return (0, import_math17.bn)(latestGasPrice.gasPrice);
4695
+ }
4696
+ async estimateGasPrice(blockHorizon) {
4697
+ const { estimateGasPrice } = await this.operations.estimateGasPrice({
4698
+ blockHorizon: String(blockHorizon)
4699
+ });
4700
+ return (0, import_math17.bn)(estimateGasPrice.gasPrice);
4701
+ }
4397
4702
  /**
4398
4703
  * Returns Message Proof for given transaction id and the message id from MessageOut receipt.
4399
4704
  *
@@ -4413,15 +4718,37 @@ var _Provider = class {
4413
4718
  */
4414
4719
  async produceBlocks(amount, startTime) {
4415
4720
  const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
4416
- blocksToProduce: (0, import_math15.bn)(amount).toString(10),
4417
- startTimestamp: startTime ? import_utils23.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
4721
+ blocksToProduce: (0, import_math17.bn)(amount).toString(10),
4722
+ startTimestamp: startTime ? import_utils22.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
4418
4723
  });
4419
- return (0, import_math15.bn)(latestBlockHeight);
4724
+ return (0, import_math17.bn)(latestBlockHeight);
4420
4725
  }
4421
4726
  // eslint-disable-next-line @typescript-eslint/require-await
4422
4727
  async getTransactionResponse(transactionId) {
4423
4728
  return new TransactionResponse(transactionId, this);
4424
4729
  }
4730
+ /**
4731
+ * Returns Message for given nonce.
4732
+ *
4733
+ * @param nonce - The nonce of the message to retrieve.
4734
+ * @returns A promise that resolves to the Message object.
4735
+ */
4736
+ async getMessageByNonce(nonce) {
4737
+ const { message } = await this.operations.getMessageByNonce({ nonce });
4738
+ if (!message) {
4739
+ return null;
4740
+ }
4741
+ return message;
4742
+ }
4743
+ async getRelayedTransactionStatus(relayedTransactionId) {
4744
+ const { relayedTransactionStatus } = await this.operations.getRelayedTransactionStatus({
4745
+ relayedTransactionId
4746
+ });
4747
+ if (!relayedTransactionStatus) {
4748
+ return null;
4749
+ }
4750
+ return relayedTransactionStatus;
4751
+ }
4425
4752
  };
4426
4753
  var Provider = _Provider;
4427
4754
  _cacheInputs = new WeakSet();
@@ -4430,7 +4757,7 @@ cacheInputs_fn = function(inputs) {
4430
4757
  return;
4431
4758
  }
4432
4759
  inputs.forEach((input) => {
4433
- if (input.type === import_transactions18.InputType.Coin) {
4760
+ if (input.type === import_transactions19.InputType.Coin) {
4434
4761
  this.cache?.set(input.id);
4435
4762
  }
4436
4763
  });
@@ -4440,9 +4767,9 @@ __publicField(Provider, "nodeInfoCache", {});
4440
4767
 
4441
4768
  // src/providers/transaction-summary/get-transaction-summary.ts
4442
4769
  var import_errors15 = require("@fuel-ts/errors");
4443
- var import_math16 = require("@fuel-ts/math");
4444
- var import_transactions19 = require("@fuel-ts/transactions");
4445
- var import_utils26 = require("@fuel-ts/utils");
4770
+ var import_math18 = require("@fuel-ts/math");
4771
+ var import_transactions20 = require("@fuel-ts/transactions");
4772
+ var import_utils25 = require("@fuel-ts/utils");
4446
4773
 
4447
4774
  // src/providers/chains.ts
4448
4775
  var CHAIN_IDS = {
@@ -4489,19 +4816,35 @@ var assets = [
4489
4816
  }
4490
4817
  ];
4491
4818
 
4819
+ // src/providers/transaction-request/helpers.ts
4820
+ var import_math19 = require("@fuel-ts/math");
4821
+ var import_transactions21 = require("@fuel-ts/transactions");
4822
+ var isRequestInputCoin = (input) => input.type === import_transactions21.InputType.Coin;
4823
+ var isRequestInputMessage = (input) => input.type === import_transactions21.InputType.Message;
4824
+ var isRequestInputResource = (input) => isRequestInputCoin(input) || isRequestInputMessage(input);
4825
+ var getAssetAmountInRequestInputs = (inputs, assetId, baseAsset) => inputs.filter(isRequestInputResource).reduce((acc, input) => {
4826
+ if (isRequestInputCoin(input) && input.assetId === assetId) {
4827
+ return acc.add(input.amount);
4828
+ }
4829
+ if (isRequestInputMessage(input) && assetId === baseAsset) {
4830
+ return acc.add(input.amount);
4831
+ }
4832
+ return acc;
4833
+ }, (0, import_math19.bn)(0));
4834
+
4492
4835
  // src/utils/formatTransferToContractScriptData.ts
4493
4836
  var import_abi_coder6 = require("@fuel-ts/abi-coder");
4494
- var import_math17 = require("@fuel-ts/math");
4495
- var import_utils27 = require("@fuel-ts/utils");
4837
+ var import_math20 = require("@fuel-ts/math");
4838
+ var import_utils26 = require("@fuel-ts/utils");
4496
4839
  var asm = __toESM(require("@fuels/vm-asm"));
4497
4840
  var formatTransferToContractScriptData = (params) => {
4498
4841
  const { assetId, amountToTransfer, hexlifiedContractId } = params;
4499
4842
  const numberCoder = new import_abi_coder6.BigNumberCoder("u64");
4500
- const encoded = numberCoder.encode(new import_math17.BN(amountToTransfer).toNumber());
4843
+ const encoded = numberCoder.encode(new import_math20.BN(amountToTransfer).toNumber());
4501
4844
  const scriptData = Uint8Array.from([
4502
- ...(0, import_utils27.arrayify)(hexlifiedContractId),
4845
+ ...(0, import_utils26.arrayify)(hexlifiedContractId),
4503
4846
  ...encoded,
4504
- ...(0, import_utils27.arrayify)(assetId)
4847
+ ...(0, import_utils26.arrayify)(assetId)
4505
4848
  ]);
4506
4849
  return scriptData;
4507
4850
  };
@@ -4526,6 +4869,7 @@ var assembleTransferToContractScript = async (params) => {
4526
4869
  };
4527
4870
 
4528
4871
  // src/account.ts
4872
+ var MAX_FUNDING_ATTEMPTS = 2;
4529
4873
  var Account = class extends import_interfaces.AbstractAccount {
4530
4874
  /**
4531
4875
  * The address associated with the account.
@@ -4648,8 +4992,9 @@ var Account = class extends import_interfaces.AbstractAccount {
4648
4992
  * @param assetId - The asset ID to check the balance for.
4649
4993
  * @returns A promise that resolves to the balance amount.
4650
4994
  */
4651
- async getBalance(assetId = import_configs12.BaseAssetId) {
4652
- const amount = await this.provider.getBalance(this.address, assetId);
4995
+ async getBalance(assetId) {
4996
+ const assetIdToFetch = assetId ?? this.provider.getBaseAssetId();
4997
+ const amount = await this.provider.getBalance(this.address, assetIdToFetch);
4653
4998
  return amount;
4654
4999
  }
4655
5000
  /**
@@ -4682,44 +5027,35 @@ var Account = class extends import_interfaces.AbstractAccount {
4682
5027
  * Adds resources to the transaction enough to fund it.
4683
5028
  *
4684
5029
  * @param request - The transaction request.
4685
- * @param coinQuantities - The coin quantities required to execute the transaction.
5030
+ * @param requiredQuantities - The coin quantities required to execute the transaction.
4686
5031
  * @param fee - The estimated transaction fee.
4687
5032
  * @returns A promise that resolves when the resources are added to the transaction.
4688
5033
  */
4689
- async fund(request, coinQuantities, fee) {
4690
- const updatedQuantities = addAmountToAsset({
4691
- amount: (0, import_math18.bn)(fee),
4692
- assetId: import_configs12.BaseAssetId,
4693
- coinQuantities
5034
+ async fund(request, params) {
5035
+ const { addedSignatures, estimatedPredicates, maxFee: fee, requiredQuantities } = params;
5036
+ const baseAssetId = this.provider.getBaseAssetId();
5037
+ const requiredInBaseAsset = requiredQuantities.find((quantity) => quantity.assetId === baseAssetId)?.amount || (0, import_math21.bn)(0);
5038
+ const txRequest = request;
5039
+ const requiredQuantitiesWithFee = addAmountToCoinQuantities({
5040
+ amount: (0, import_math21.bn)(fee),
5041
+ assetId: baseAssetId,
5042
+ coinQuantities: requiredQuantities
4694
5043
  });
4695
5044
  const quantitiesDict = {};
4696
- updatedQuantities.forEach(({ amount, assetId }) => {
5045
+ requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
4697
5046
  quantitiesDict[assetId] = {
4698
5047
  required: amount,
4699
- owned: (0, import_math18.bn)(0)
5048
+ owned: (0, import_math21.bn)(0)
4700
5049
  };
4701
5050
  });
4702
- const cachedUtxos = [];
4703
- const cachedMessages = [];
4704
- const owner = this.address.toB256();
4705
- request.inputs.forEach((input) => {
4706
- const isResource = "amount" in input;
4707
- if (isResource) {
4708
- const isCoin2 = "owner" in input;
4709
- if (isCoin2) {
4710
- const assetId = String(input.assetId);
4711
- if (input.owner === owner && quantitiesDict[assetId]) {
4712
- const amount = (0, import_math18.bn)(input.amount);
4713
- quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
4714
- cachedUtxos.push(input.id);
4715
- }
4716
- } else if (input.recipient === owner && input.amount && quantitiesDict[import_configs12.BaseAssetId]) {
4717
- quantitiesDict[import_configs12.BaseAssetId].owned = quantitiesDict[import_configs12.BaseAssetId].owned.add(input.amount);
4718
- cachedMessages.push(input.nonce);
4719
- }
5051
+ request.inputs.filter(isRequestInputResource).forEach((input) => {
5052
+ const isCoin2 = isRequestInputCoin(input);
5053
+ const assetId = isCoin2 ? String(input.assetId) : baseAssetId;
5054
+ if (quantitiesDict[assetId]) {
5055
+ quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(input.amount);
4720
5056
  }
4721
5057
  });
4722
- const missingQuantities = [];
5058
+ let missingQuantities = [];
4723
5059
  Object.entries(quantitiesDict).forEach(([assetId, { owned, required }]) => {
4724
5060
  if (owned.lt(required)) {
4725
5061
  missingQuantities.push({
@@ -4728,14 +5064,54 @@ var Account = class extends import_interfaces.AbstractAccount {
4728
5064
  });
4729
5065
  }
4730
5066
  });
4731
- const needsToBeFunded = missingQuantities.length;
4732
- if (needsToBeFunded) {
4733
- const resources = await this.getResourcesToSpend(missingQuantities, {
4734
- messages: cachedMessages,
4735
- utxos: cachedUtxos
4736
- });
5067
+ let needsToBeFunded = missingQuantities.length > 0;
5068
+ let fundingAttempts = 0;
5069
+ while (needsToBeFunded && fundingAttempts < MAX_FUNDING_ATTEMPTS) {
5070
+ const resources = await this.getResourcesToSpend(
5071
+ missingQuantities,
5072
+ cacheTxInputsFromOwner(request.inputs, this.address)
5073
+ );
4737
5074
  request.addResources(resources);
5075
+ txRequest.shiftPredicateData();
5076
+ txRequest.updatePredicateGasUsed(estimatedPredicates);
5077
+ const requestToReestimate2 = (0, import_ramda4.clone)(txRequest);
5078
+ if (addedSignatures) {
5079
+ Array.from({ length: addedSignatures }).forEach(
5080
+ () => requestToReestimate2.addEmptyWitness()
5081
+ );
5082
+ }
5083
+ const { maxFee: newFee } = await this.provider.estimateTxGasAndFee({
5084
+ transactionRequest: requestToReestimate2
5085
+ });
5086
+ const totalBaseAssetOnInputs = getAssetAmountInRequestInputs(
5087
+ request.inputs,
5088
+ baseAssetId,
5089
+ baseAssetId
5090
+ );
5091
+ const totalBaseAssetRequiredWithFee = requiredInBaseAsset.add(newFee);
5092
+ if (totalBaseAssetOnInputs.gt(totalBaseAssetRequiredWithFee)) {
5093
+ needsToBeFunded = false;
5094
+ } else {
5095
+ missingQuantities = [
5096
+ {
5097
+ amount: totalBaseAssetRequiredWithFee.sub(totalBaseAssetOnInputs),
5098
+ assetId: baseAssetId
5099
+ }
5100
+ ];
5101
+ }
5102
+ fundingAttempts += 1;
5103
+ }
5104
+ txRequest.shiftPredicateData();
5105
+ txRequest.updatePredicateGasUsed(estimatedPredicates);
5106
+ const requestToReestimate = (0, import_ramda4.clone)(txRequest);
5107
+ if (addedSignatures) {
5108
+ Array.from({ length: addedSignatures }).forEach(() => requestToReestimate.addEmptyWitness());
4738
5109
  }
5110
+ const { maxFee } = await this.provider.estimateTxGasAndFee({
5111
+ transactionRequest: requestToReestimate
5112
+ });
5113
+ txRequest.maxFee = maxFee;
5114
+ return txRequest;
4739
5115
  }
4740
5116
  /**
4741
5117
  * A helper that creates a transfer transaction request and returns it.
@@ -4743,28 +5119,25 @@ var Account = class extends import_interfaces.AbstractAccount {
4743
5119
  * @param destination - The address of the destination.
4744
5120
  * @param amount - The amount of coins to transfer.
4745
5121
  * @param assetId - The asset ID of the coins to transfer.
4746
- * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
5122
+ * @param txParams - The transaction parameters (gasLimit, tip, maturity, maxFee, witnessLimit).
4747
5123
  * @returns A promise that resolves to the prepared transaction request.
4748
5124
  */
4749
- async createTransfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
4750
- const { minGasPrice } = this.provider.getGasConfig();
4751
- const params = { gasPrice: minGasPrice, ...txParams };
4752
- const request = new ScriptTransactionRequest(params);
4753
- request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetId);
4754
- const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
5125
+ async createTransfer(destination, amount, assetId, txParams = {}) {
5126
+ const request = new ScriptTransactionRequest(txParams);
5127
+ const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
5128
+ request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetIdToTransfer);
5129
+ const txCost = await this.provider.getTransactionCost(request, {
4755
5130
  estimateTxDependencies: true,
4756
5131
  resourcesOwner: this
4757
5132
  });
4758
- request.gasPrice = (0, import_math18.bn)(txParams.gasPrice ?? minGasPrice);
4759
- request.gasLimit = (0, import_math18.bn)(txParams.gasLimit ?? gasUsed);
4760
- this.validateGas({
4761
- gasUsed,
4762
- gasPrice: request.gasPrice,
4763
- gasLimit: request.gasLimit,
4764
- minGasPrice
5133
+ this.validateGasLimitAndMaxFee({
5134
+ gasUsed: txCost.gasUsed,
5135
+ maxFee: txCost.maxFee,
5136
+ txParams
4765
5137
  });
4766
- await this.fund(request, requiredQuantities, maxFee);
4767
- request.updatePredicateInputs(estimatedInputs);
5138
+ request.gasLimit = txCost.gasUsed;
5139
+ request.maxFee = txCost.maxFee;
5140
+ await this.fund(request, txCost);
4768
5141
  return request;
4769
5142
  }
4770
5143
  /**
@@ -4773,17 +5146,18 @@ var Account = class extends import_interfaces.AbstractAccount {
4773
5146
  * @param destination - The address of the destination.
4774
5147
  * @param amount - The amount of coins to transfer.
4775
5148
  * @param assetId - The asset ID of the coins to transfer.
4776
- * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
5149
+ * @param txParams - The transaction parameters (gasLimit, maturity).
4777
5150
  * @returns A promise that resolves to the transaction response.
4778
5151
  */
4779
- async transfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
4780
- if ((0, import_math18.bn)(amount).lte(0)) {
5152
+ async transfer(destination, amount, assetId, txParams = {}) {
5153
+ if ((0, import_math21.bn)(amount).lte(0)) {
4781
5154
  throw new import_errors16.FuelError(
4782
5155
  import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
4783
5156
  "Transfer amount must be a positive number."
4784
5157
  );
4785
5158
  }
4786
- const request = await this.createTransfer(destination, amount, assetId, txParams);
5159
+ const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
5160
+ const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
4787
5161
  return this.sendTransaction(request, { estimateTxDependencies: false });
4788
5162
  }
4789
5163
  /**
@@ -4795,39 +5169,38 @@ var Account = class extends import_interfaces.AbstractAccount {
4795
5169
  * @param txParams - The optional transaction parameters.
4796
5170
  * @returns A promise that resolves to the transaction response.
4797
5171
  */
4798
- async transferToContract(contractId, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
4799
- if ((0, import_math18.bn)(amount).lte(0)) {
5172
+ async transferToContract(contractId, amount, assetId, txParams = {}) {
5173
+ if ((0, import_math21.bn)(amount).lte(0)) {
4800
5174
  throw new import_errors16.FuelError(
4801
5175
  import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
4802
5176
  "Transfer amount must be a positive number."
4803
5177
  );
4804
5178
  }
4805
5179
  const contractAddress = import_address4.Address.fromAddressOrString(contractId);
4806
- const { minGasPrice } = this.provider.getGasConfig();
4807
- const params = { gasPrice: minGasPrice, ...txParams };
5180
+ const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
4808
5181
  const { script, scriptData } = await assembleTransferToContractScript({
4809
5182
  hexlifiedContractId: contractAddress.toB256(),
4810
- amountToTransfer: (0, import_math18.bn)(amount),
4811
- assetId
5183
+ amountToTransfer: (0, import_math21.bn)(amount),
5184
+ assetId: assetIdToTransfer
4812
5185
  });
4813
5186
  const request = new ScriptTransactionRequest({
4814
- ...params,
5187
+ ...txParams,
4815
5188
  script,
4816
5189
  scriptData
4817
5190
  });
4818
5191
  request.addContractInputAndOutput(contractAddress);
4819
- const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
4820
- request,
4821
- [{ amount: (0, import_math18.bn)(amount), assetId: String(assetId) }]
4822
- );
4823
- request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
4824
- this.validateGas({
4825
- gasUsed,
4826
- gasPrice: request.gasPrice,
4827
- gasLimit: request.gasLimit,
4828
- minGasPrice
5192
+ const txCost = await this.provider.getTransactionCost(request, {
5193
+ resourcesOwner: this,
5194
+ quantitiesToContract: [{ amount: (0, import_math21.bn)(amount), assetId: String(assetIdToTransfer) }]
4829
5195
  });
4830
- await this.fund(request, requiredQuantities, maxFee);
5196
+ this.validateGasLimitAndMaxFee({
5197
+ gasUsed: txCost.gasUsed,
5198
+ maxFee: txCost.maxFee,
5199
+ txParams
5200
+ });
5201
+ request.gasLimit = txCost.gasUsed;
5202
+ request.maxFee = txCost.maxFee;
5203
+ await this.fund(request, txCost);
4831
5204
  return this.sendTransaction(request);
4832
5205
  }
4833
5206
  /**
@@ -4839,34 +5212,31 @@ var Account = class extends import_interfaces.AbstractAccount {
4839
5212
  * @returns A promise that resolves to the transaction response.
4840
5213
  */
4841
5214
  async withdrawToBaseLayer(recipient, amount, txParams = {}) {
4842
- const { minGasPrice } = this.provider.getGasConfig();
4843
5215
  const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
4844
- const recipientDataArray = (0, import_utils28.arrayify)(
5216
+ const recipientDataArray = (0, import_utils27.arrayify)(
4845
5217
  "0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
4846
5218
  );
4847
- const amountDataArray = (0, import_utils28.arrayify)(
4848
- "0x".concat((0, import_math18.bn)(amount).toHex().substring(2).padStart(16, "0"))
5219
+ const amountDataArray = (0, import_utils27.arrayify)(
5220
+ "0x".concat((0, import_math21.bn)(amount).toHex().substring(2).padStart(16, "0"))
4849
5221
  );
4850
5222
  const script = new Uint8Array([
4851
- ...(0, import_utils28.arrayify)(withdrawScript.bytes),
5223
+ ...(0, import_utils27.arrayify)(withdrawScript.bytes),
4852
5224
  ...recipientDataArray,
4853
5225
  ...amountDataArray
4854
5226
  ]);
4855
- const params = { script, gasPrice: minGasPrice, ...txParams };
5227
+ const params = { script, ...txParams };
5228
+ const baseAssetId = this.provider.getBaseAssetId();
4856
5229
  const request = new ScriptTransactionRequest(params);
4857
- const forwardingQuantities = [{ amount: (0, import_math18.bn)(amount), assetId: import_configs12.BaseAssetId }];
4858
- const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
4859
- request,
4860
- forwardingQuantities
4861
- );
4862
- request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
4863
- this.validateGas({
4864
- gasUsed,
4865
- gasPrice: request.gasPrice,
4866
- gasLimit: request.gasLimit,
4867
- minGasPrice
5230
+ const quantitiesToContract = [{ amount: (0, import_math21.bn)(amount), assetId: baseAssetId }];
5231
+ const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
5232
+ this.validateGasLimitAndMaxFee({
5233
+ gasUsed: txCost.gasUsed,
5234
+ maxFee: txCost.maxFee,
5235
+ txParams
4868
5236
  });
4869
- await this.fund(request, requiredQuantities, maxFee);
5237
+ request.maxFee = txCost.maxFee;
5238
+ request.gasLimit = txCost.gasUsed;
5239
+ await this.fund(request, txCost);
4870
5240
  return this.sendTransaction(request);
4871
5241
  }
4872
5242
  async signMessage(message) {
@@ -4924,22 +5294,21 @@ var Account = class extends import_interfaces.AbstractAccount {
4924
5294
  }
4925
5295
  return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
4926
5296
  }
4927
- validateGas({
5297
+ validateGasLimitAndMaxFee({
5298
+ txParams: { gasLimit: setGasLimit, maxFee: setMaxFee },
4928
5299
  gasUsed,
4929
- gasPrice,
4930
- gasLimit,
4931
- minGasPrice
5300
+ maxFee
4932
5301
  }) {
4933
- if (minGasPrice.gt(gasPrice)) {
5302
+ if ((0, import_utils27.isDefined)(setGasLimit) && gasUsed.gt(setGasLimit)) {
4934
5303
  throw new import_errors16.FuelError(
4935
- import_errors16.ErrorCode.GAS_PRICE_TOO_LOW,
4936
- `Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
5304
+ import_errors16.ErrorCode.GAS_LIMIT_TOO_LOW,
5305
+ `Gas limit '${setGasLimit}' is lower than the required: '${gasUsed}'.`
4937
5306
  );
4938
5307
  }
4939
- if (gasUsed.gt(gasLimit)) {
5308
+ if ((0, import_utils27.isDefined)(setMaxFee) && maxFee.gt(setMaxFee)) {
4940
5309
  throw new import_errors16.FuelError(
4941
- import_errors16.ErrorCode.GAS_LIMIT_TOO_LOW,
4942
- `Gas limit '${gasLimit}' is lower than the required: '${gasUsed}'.`
5310
+ import_errors16.ErrorCode.MAX_FEE_TOO_LOW,
5311
+ `Max fee '${setMaxFee}' is lower than the required: '${maxFee}'.`
4943
5312
  );
4944
5313
  }
4945
5314
  }
@@ -4949,8 +5318,8 @@ var Account = class extends import_interfaces.AbstractAccount {
4949
5318
  var import_address5 = require("@fuel-ts/address");
4950
5319
  var import_crypto2 = require("@fuel-ts/crypto");
4951
5320
  var import_hasher2 = require("@fuel-ts/hasher");
4952
- var import_math19 = require("@fuel-ts/math");
4953
- var import_utils29 = require("@fuel-ts/utils");
5321
+ var import_math22 = require("@fuel-ts/math");
5322
+ var import_utils28 = require("@fuel-ts/utils");
4954
5323
  var import_secp256k1 = require("@noble/curves/secp256k1");
4955
5324
  var Signer = class {
4956
5325
  address;
@@ -4969,10 +5338,10 @@ var Signer = class {
4969
5338
  privateKey = `0x${privateKey}`;
4970
5339
  }
4971
5340
  }
4972
- const privateKeyBytes = (0, import_math19.toBytes)(privateKey, 32);
4973
- this.privateKey = (0, import_utils29.hexlify)(privateKeyBytes);
4974
- this.publicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
4975
- this.compressedPublicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
5341
+ const privateKeyBytes = (0, import_math22.toBytes)(privateKey, 32);
5342
+ this.privateKey = (0, import_utils28.hexlify)(privateKeyBytes);
5343
+ this.publicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
5344
+ this.compressedPublicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
4976
5345
  this.address = import_address5.Address.fromPublicKey(this.publicKey);
4977
5346
  }
4978
5347
  /**
@@ -4986,11 +5355,11 @@ var Signer = class {
4986
5355
  * @returns hashed signature
4987
5356
  */
4988
5357
  sign(data) {
4989
- const signature = import_secp256k1.secp256k1.sign((0, import_utils29.arrayify)(data), (0, import_utils29.arrayify)(this.privateKey));
4990
- const r = (0, import_math19.toBytes)(`0x${signature.r.toString(16)}`, 32);
4991
- const s = (0, import_math19.toBytes)(`0x${signature.s.toString(16)}`, 32);
5358
+ const signature = import_secp256k1.secp256k1.sign((0, import_utils28.arrayify)(data), (0, import_utils28.arrayify)(this.privateKey));
5359
+ const r = (0, import_math22.toBytes)(`0x${signature.r.toString(16)}`, 32);
5360
+ const s = (0, import_math22.toBytes)(`0x${signature.s.toString(16)}`, 32);
4992
5361
  s[0] |= (signature.recovery || 0) << 7;
4993
- return (0, import_utils29.hexlify)((0, import_utils29.concat)([r, s]));
5362
+ return (0, import_utils28.hexlify)((0, import_utils28.concat)([r, s]));
4994
5363
  }
4995
5364
  /**
4996
5365
  * Add point on the current elliptic curve
@@ -4999,8 +5368,8 @@ var Signer = class {
4999
5368
  * @returns compressed point on the curve
5000
5369
  */
5001
5370
  addPoint(point) {
5002
- const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(this.compressedPublicKey));
5003
- const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(point));
5371
+ const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(this.compressedPublicKey));
5372
+ const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(point));
5004
5373
  const result = p0.add(p1);
5005
5374
  return `0x${result.toHex(true)}`;
5006
5375
  }
@@ -5012,16 +5381,16 @@ var Signer = class {
5012
5381
  * @returns public key from signature from the
5013
5382
  */
5014
5383
  static recoverPublicKey(data, signature) {
5015
- const signedMessageBytes = (0, import_utils29.arrayify)(signature);
5384
+ const signedMessageBytes = (0, import_utils28.arrayify)(signature);
5016
5385
  const r = signedMessageBytes.slice(0, 32);
5017
5386
  const s = signedMessageBytes.slice(32, 64);
5018
5387
  const recoveryParam = (s[0] & 128) >> 7;
5019
5388
  s[0] &= 127;
5020
- const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils29.hexlify)(r)), BigInt((0, import_utils29.hexlify)(s))).addRecoveryBit(
5389
+ const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils28.hexlify)(r)), BigInt((0, import_utils28.hexlify)(s))).addRecoveryBit(
5021
5390
  recoveryParam
5022
5391
  );
5023
- const publicKey = sig.recoverPublicKey((0, import_utils29.arrayify)(data)).toRawBytes(false).slice(1);
5024
- return (0, import_utils29.hexlify)(publicKey);
5392
+ const publicKey = sig.recoverPublicKey((0, import_utils28.arrayify)(data)).toRawBytes(false).slice(1);
5393
+ return (0, import_utils28.hexlify)(publicKey);
5025
5394
  }
5026
5395
  /**
5027
5396
  * Recover the address from a signature performed with [`sign`](#sign).
@@ -5040,7 +5409,7 @@ var Signer = class {
5040
5409
  * @returns random 32-byte hashed
5041
5410
  */
5042
5411
  static generatePrivateKey(entropy) {
5043
- 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);
5412
+ 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);
5044
5413
  }
5045
5414
  /**
5046
5415
  * Extended publicKey from a compact publicKey
@@ -5049,8 +5418,8 @@ var Signer = class {
5049
5418
  * @returns extended publicKey
5050
5419
  */
5051
5420
  static extendPublicKey(publicKey) {
5052
- const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(publicKey));
5053
- return (0, import_utils29.hexlify)(point.toRawBytes(false).slice(1));
5421
+ const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(publicKey));
5422
+ return (0, import_utils28.hexlify)(point.toRawBytes(false).slice(1));
5054
5423
  }
5055
5424
  };
5056
5425
 
@@ -5058,7 +5427,7 @@ var Signer = class {
5058
5427
  var import_address6 = require("@fuel-ts/address");
5059
5428
  var import_crypto3 = require("@fuel-ts/crypto");
5060
5429
  var import_errors17 = require("@fuel-ts/errors");
5061
- var import_utils30 = require("@fuel-ts/utils");
5430
+ var import_utils29 = require("@fuel-ts/utils");
5062
5431
  var import_uuid = require("uuid");
5063
5432
  var DEFAULT_KDF_PARAMS_LOG_N = 13;
5064
5433
  var DEFAULT_KDF_PARAMS_R = 8;
@@ -5141,7 +5510,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
5141
5510
  );
5142
5511
  }
5143
5512
  const buffer = await (0, import_crypto3.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
5144
- const privateKey = (0, import_utils30.hexlify)(buffer);
5513
+ const privateKey = (0, import_utils29.hexlify)(buffer);
5145
5514
  return privateKey;
5146
5515
  }
5147
5516
 
@@ -5186,7 +5555,7 @@ var BaseWalletUnlocked = class extends Account {
5186
5555
  */
5187
5556
  async signMessage(message) {
5188
5557
  const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
5189
- return (0, import_utils31.hexlify)(signedMessage);
5558
+ return (0, import_utils30.hexlify)(signedMessage);
5190
5559
  }
5191
5560
  /**
5192
5561
  * Signs a transaction with the wallet's private key.
@@ -5199,7 +5568,7 @@ var BaseWalletUnlocked = class extends Account {
5199
5568
  const chainId = this.provider.getChainId();
5200
5569
  const hashedTransaction = transactionRequest.getTransactionId(chainId);
5201
5570
  const signature = await this.signer().sign(hashedTransaction);
5202
- return (0, import_utils31.hexlify)(signature);
5571
+ return (0, import_utils30.hexlify)(signature);
5203
5572
  }
5204
5573
  /**
5205
5574
  * Populates a transaction with the witnesses signature.
@@ -5219,7 +5588,7 @@ var BaseWalletUnlocked = class extends Account {
5219
5588
  * @param transactionRequestLike - The transaction request to send.
5220
5589
  * @returns A promise that resolves to the TransactionResponse object.
5221
5590
  */
5222
- async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
5591
+ async sendTransaction(transactionRequestLike, { estimateTxDependencies = false, awaitExecution } = {}) {
5223
5592
  const transactionRequest = transactionRequestify(transactionRequestLike);
5224
5593
  if (estimateTxDependencies) {
5225
5594
  await this.provider.estimateTxDependencies(transactionRequest);
@@ -5260,16 +5629,16 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
5260
5629
  // src/hdwallet/hdwallet.ts
5261
5630
  var import_errors20 = require("@fuel-ts/errors");
5262
5631
  var import_hasher6 = require("@fuel-ts/hasher");
5263
- var import_math20 = require("@fuel-ts/math");
5264
- var import_utils35 = require("@fuel-ts/utils");
5265
- var import_ethers3 = require("ethers");
5632
+ var import_math23 = require("@fuel-ts/math");
5633
+ var import_utils34 = require("@fuel-ts/utils");
5634
+ var import_ethers2 = require("ethers");
5266
5635
 
5267
5636
  // src/mnemonic/mnemonic.ts
5268
5637
  var import_crypto4 = require("@fuel-ts/crypto");
5269
5638
  var import_errors19 = require("@fuel-ts/errors");
5270
5639
  var import_hasher5 = require("@fuel-ts/hasher");
5271
- var import_utils33 = require("@fuel-ts/utils");
5272
- var import_ethers2 = require("ethers");
5640
+ var import_utils32 = require("@fuel-ts/utils");
5641
+ var import_ethers = require("ethers");
5273
5642
 
5274
5643
  // src/wordlists/words/english.ts
5275
5644
  var english = [
@@ -7326,7 +7695,7 @@ var english = [
7326
7695
  // src/mnemonic/utils.ts
7327
7696
  var import_errors18 = require("@fuel-ts/errors");
7328
7697
  var import_hasher4 = require("@fuel-ts/hasher");
7329
- var import_utils32 = require("@fuel-ts/utils");
7698
+ var import_utils31 = require("@fuel-ts/utils");
7330
7699
  function toUtf8Bytes(stri) {
7331
7700
  const str = stri.normalize("NFKD");
7332
7701
  const result = [];
@@ -7393,14 +7762,14 @@ function entropyToMnemonicIndices(entropy) {
7393
7762
  }
7394
7763
  }
7395
7764
  const checksumBits = entropy.length / 4;
7396
- const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
7765
+ const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
7397
7766
  indices[indices.length - 1] <<= checksumBits;
7398
7767
  indices[indices.length - 1] |= checksum >> 8 - checksumBits;
7399
7768
  return indices;
7400
7769
  }
7401
7770
  function mnemonicWordsToEntropy(words, wordlist) {
7402
7771
  const size = Math.ceil(11 * words.length / 8);
7403
- const entropy = (0, import_utils32.arrayify)(new Uint8Array(size));
7772
+ const entropy = (0, import_utils31.arrayify)(new Uint8Array(size));
7404
7773
  let offset = 0;
7405
7774
  for (let i = 0; i < words.length; i += 1) {
7406
7775
  const index = wordlist.indexOf(words[i].normalize("NFKD"));
@@ -7420,7 +7789,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
7420
7789
  const entropyBits = 32 * words.length / 3;
7421
7790
  const checksumBits = words.length / 3;
7422
7791
  const checksumMask = getUpperMask(checksumBits);
7423
- const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
7792
+ const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
7424
7793
  if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
7425
7794
  throw new import_errors18.FuelError(
7426
7795
  import_errors18.ErrorCode.INVALID_CHECKSUM,
@@ -7495,7 +7864,7 @@ var Mnemonic = class {
7495
7864
  static mnemonicToEntropy(phrase, wordlist = english) {
7496
7865
  const words = getWords(phrase);
7497
7866
  assertMnemonic(words);
7498
- return (0, import_utils33.hexlify)(mnemonicWordsToEntropy(words, wordlist));
7867
+ return (0, import_utils32.hexlify)(mnemonicWordsToEntropy(words, wordlist));
7499
7868
  }
7500
7869
  /**
7501
7870
  * @param entropy - Entropy source to the mnemonic phrase.
@@ -7503,7 +7872,7 @@ var Mnemonic = class {
7503
7872
  * @returns 64-byte array contains privateKey and chainCode as described on BIP39
7504
7873
  */
7505
7874
  static entropyToMnemonic(entropy, wordlist = english) {
7506
- const entropyBytes = (0, import_utils33.arrayify)(entropy);
7875
+ const entropyBytes = (0, import_utils32.arrayify)(entropy);
7507
7876
  assertWordList(wordlist);
7508
7877
  assertEntropy(entropyBytes);
7509
7878
  return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
@@ -7517,7 +7886,7 @@ var Mnemonic = class {
7517
7886
  assertMnemonic(getWords(phrase));
7518
7887
  const phraseBytes = toUtf8Bytes(getPhrase(phrase));
7519
7888
  const salt = toUtf8Bytes(`mnemonic${passphrase}`);
7520
- return (0, import_ethers2.pbkdf2)(phraseBytes, salt, 2048, 64, "sha512");
7889
+ return (0, import_ethers.pbkdf2)(phraseBytes, salt, 2048, 64, "sha512");
7521
7890
  }
7522
7891
  /**
7523
7892
  * @param phrase - Mnemonic phrase composed by words from the provided wordlist
@@ -7572,14 +7941,14 @@ var Mnemonic = class {
7572
7941
  * @returns 64-byte array contains privateKey and chainCode as described on BIP39
7573
7942
  */
7574
7943
  static masterKeysFromSeed(seed) {
7575
- const seedArray = (0, import_utils33.arrayify)(seed);
7944
+ const seedArray = (0, import_utils32.arrayify)(seed);
7576
7945
  if (seedArray.length < 16 || seedArray.length > 64) {
7577
7946
  throw new import_errors19.FuelError(
7578
7947
  import_errors19.ErrorCode.INVALID_SEED,
7579
7948
  `Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
7580
7949
  );
7581
7950
  }
7582
- return (0, import_utils33.arrayify)((0, import_ethers2.computeHmac)("sha512", MasterSecret, seedArray));
7951
+ return (0, import_utils32.arrayify)((0, import_ethers.computeHmac)("sha512", MasterSecret, seedArray));
7583
7952
  }
7584
7953
  /**
7585
7954
  * Get the extendKey as defined on BIP-32 from the provided seed
@@ -7590,22 +7959,22 @@ var Mnemonic = class {
7590
7959
  */
7591
7960
  static seedToExtendedKey(seed, testnet = false) {
7592
7961
  const masterKey = Mnemonic.masterKeysFromSeed(seed);
7593
- const prefix = (0, import_utils33.arrayify)(testnet ? TestnetPRV : MainnetPRV);
7962
+ const prefix = (0, import_utils32.arrayify)(testnet ? TestnetPRV : MainnetPRV);
7594
7963
  const depth = "0x00";
7595
7964
  const fingerprint = "0x00000000";
7596
7965
  const index = "0x00000000";
7597
7966
  const chainCode = masterKey.slice(32);
7598
7967
  const privateKey = masterKey.slice(0, 32);
7599
- const extendedKey = (0, import_utils33.concat)([
7968
+ const extendedKey = (0, import_utils32.concat)([
7600
7969
  prefix,
7601
7970
  depth,
7602
7971
  fingerprint,
7603
7972
  index,
7604
7973
  chainCode,
7605
- (0, import_utils33.concat)(["0x00", privateKey])
7974
+ (0, import_utils32.concat)(["0x00", privateKey])
7606
7975
  ]);
7607
- const checksum = (0, import_ethers2.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
7608
- return (0, import_ethers2.encodeBase58)((0, import_utils33.concat)([extendedKey, checksum]));
7976
+ const checksum = (0, import_ethers.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
7977
+ return (0, import_ethers.encodeBase58)((0, import_utils32.concat)([extendedKey, checksum]));
7609
7978
  }
7610
7979
  /**
7611
7980
  * Create a new mnemonic using a randomly generated number as entropy.
@@ -7620,7 +7989,7 @@ var Mnemonic = class {
7620
7989
  * @returns A randomly generated mnemonic
7621
7990
  */
7622
7991
  static generate(size = 32, extraEntropy = "") {
7623
- 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);
7992
+ 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);
7624
7993
  return Mnemonic.entropyToMnemonic(entropy);
7625
7994
  }
7626
7995
  };
@@ -7628,12 +7997,12 @@ var mnemonic_default = Mnemonic;
7628
7997
 
7629
7998
  // src/hdwallet/hdwallet.ts
7630
7999
  var HARDENED_INDEX = 2147483648;
7631
- var MainnetPRV2 = (0, import_utils35.hexlify)("0x0488ade4");
7632
- var MainnetPUB = (0, import_utils35.hexlify)("0x0488b21e");
7633
- var TestnetPRV2 = (0, import_utils35.hexlify)("0x04358394");
7634
- var TestnetPUB = (0, import_utils35.hexlify)("0x043587cf");
8000
+ var MainnetPRV2 = (0, import_utils34.hexlify)("0x0488ade4");
8001
+ var MainnetPUB = (0, import_utils34.hexlify)("0x0488b21e");
8002
+ var TestnetPRV2 = (0, import_utils34.hexlify)("0x04358394");
8003
+ var TestnetPUB = (0, import_utils34.hexlify)("0x043587cf");
7635
8004
  function base58check(data) {
7636
- 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)]));
8005
+ return (0, import_ethers2.encodeBase58)((0, import_utils34.concat)([data, (0, import_ethers2.dataSlice)((0, import_hasher6.sha256)((0, import_hasher6.sha256)(data)), 0, 4)]));
7637
8006
  }
7638
8007
  function getExtendedKeyPrefix(isPublic = false, testnet = false) {
7639
8008
  if (isPublic) {
@@ -7642,11 +8011,11 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
7642
8011
  return testnet ? TestnetPRV2 : MainnetPRV2;
7643
8012
  }
7644
8013
  function isPublicExtendedKey(extendedKey) {
7645
- return [MainnetPUB, TestnetPUB].includes((0, import_utils35.hexlify)(extendedKey.slice(0, 4)));
8014
+ return [MainnetPUB, TestnetPUB].includes((0, import_utils34.hexlify)(extendedKey.slice(0, 4)));
7646
8015
  }
7647
8016
  function isValidExtendedKey(extendedKey) {
7648
8017
  return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
7649
- (0, import_utils35.hexlify)(extendedKey.slice(0, 4))
8018
+ (0, import_utils34.hexlify)(extendedKey.slice(0, 4))
7650
8019
  );
7651
8020
  }
7652
8021
  function parsePath(path2, depth = 0) {
@@ -7664,8 +8033,8 @@ function parsePath(path2, depth = 0) {
7664
8033
  var HDWallet = class {
7665
8034
  depth = 0;
7666
8035
  index = 0;
7667
- fingerprint = (0, import_utils35.hexlify)("0x00000000");
7668
- parentFingerprint = (0, import_utils35.hexlify)("0x00000000");
8036
+ fingerprint = (0, import_utils34.hexlify)("0x00000000");
8037
+ parentFingerprint = (0, import_utils34.hexlify)("0x00000000");
7669
8038
  privateKey;
7670
8039
  publicKey;
7671
8040
  chainCode;
@@ -7677,8 +8046,8 @@ var HDWallet = class {
7677
8046
  constructor(config) {
7678
8047
  if (config.privateKey) {
7679
8048
  const signer = new Signer(config.privateKey);
7680
- this.publicKey = (0, import_utils35.hexlify)(signer.compressedPublicKey);
7681
- this.privateKey = (0, import_utils35.hexlify)(config.privateKey);
8049
+ this.publicKey = (0, import_utils34.hexlify)(signer.compressedPublicKey);
8050
+ this.privateKey = (0, import_utils34.hexlify)(config.privateKey);
7682
8051
  } else {
7683
8052
  if (!config.publicKey) {
7684
8053
  throw new import_errors20.FuelError(
@@ -7686,10 +8055,10 @@ var HDWallet = class {
7686
8055
  "Both public and private Key cannot be missing. At least one should be provided."
7687
8056
  );
7688
8057
  }
7689
- this.publicKey = (0, import_utils35.hexlify)(config.publicKey);
8058
+ this.publicKey = (0, import_utils34.hexlify)(config.publicKey);
7690
8059
  }
7691
8060
  this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
7692
- this.fingerprint = (0, import_ethers3.dataSlice)((0, import_ethers3.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
8061
+ this.fingerprint = (0, import_ethers2.dataSlice)((0, import_ethers2.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
7693
8062
  this.depth = config.depth || this.depth;
7694
8063
  this.index = config.index || this.index;
7695
8064
  this.chainCode = config.chainCode;
@@ -7705,9 +8074,9 @@ var HDWallet = class {
7705
8074
  * @returns A new instance of HDWallet on the derived index
7706
8075
  */
7707
8076
  deriveIndex(index) {
7708
- const privateKey = this.privateKey && (0, import_utils35.arrayify)(this.privateKey);
7709
- const publicKey = (0, import_utils35.arrayify)(this.publicKey);
7710
- const chainCode = (0, import_utils35.arrayify)(this.chainCode);
8077
+ const privateKey = this.privateKey && (0, import_utils34.arrayify)(this.privateKey);
8078
+ const publicKey = (0, import_utils34.arrayify)(this.publicKey);
8079
+ const chainCode = (0, import_utils34.arrayify)(this.chainCode);
7711
8080
  const data = new Uint8Array(37);
7712
8081
  if (index & HARDENED_INDEX) {
7713
8082
  if (!privateKey) {
@@ -7718,15 +8087,15 @@ var HDWallet = class {
7718
8087
  }
7719
8088
  data.set(privateKey, 1);
7720
8089
  } else {
7721
- data.set((0, import_utils35.arrayify)(this.publicKey));
8090
+ data.set((0, import_utils34.arrayify)(this.publicKey));
7722
8091
  }
7723
- data.set((0, import_math20.toBytes)(index, 4), 33);
7724
- const bytes = (0, import_utils35.arrayify)((0, import_ethers3.computeHmac)("sha512", chainCode, data));
8092
+ data.set((0, import_math23.toBytes)(index, 4), 33);
8093
+ const bytes = (0, import_utils34.arrayify)((0, import_ethers2.computeHmac)("sha512", chainCode, data));
7725
8094
  const IL = bytes.slice(0, 32);
7726
8095
  const IR = bytes.slice(32);
7727
8096
  if (privateKey) {
7728
8097
  const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
7729
- const ki = (0, import_math20.bn)(IL).add(privateKey).mod(N).toBytes(32);
8098
+ const ki = (0, import_math23.bn)(IL).add(privateKey).mod(N).toBytes(32);
7730
8099
  return new HDWallet({
7731
8100
  privateKey: ki,
7732
8101
  chainCode: IR,
@@ -7735,7 +8104,7 @@ var HDWallet = class {
7735
8104
  parentFingerprint: this.fingerprint
7736
8105
  });
7737
8106
  }
7738
- const signer = new Signer((0, import_utils35.hexlify)(IL));
8107
+ const signer = new Signer((0, import_utils34.hexlify)(IL));
7739
8108
  const Ki = signer.addPoint(publicKey);
7740
8109
  return new HDWallet({
7741
8110
  publicKey: Ki,
@@ -7770,12 +8139,12 @@ var HDWallet = class {
7770
8139
  );
7771
8140
  }
7772
8141
  const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
7773
- const depth = (0, import_utils35.hexlify)(Uint8Array.from([this.depth]));
8142
+ const depth = (0, import_utils34.hexlify)(Uint8Array.from([this.depth]));
7774
8143
  const parentFingerprint = this.parentFingerprint;
7775
- const index = (0, import_math20.toHex)(this.index, 4);
8144
+ const index = (0, import_math23.toHex)(this.index, 4);
7776
8145
  const chainCode = this.chainCode;
7777
- const key = this.privateKey != null && !isPublic ? (0, import_utils35.concat)(["0x00", this.privateKey]) : this.publicKey;
7778
- const extendedKey = (0, import_utils35.arrayify)((0, import_utils35.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
8146
+ const key = this.privateKey != null && !isPublic ? (0, import_utils34.concat)(["0x00", this.privateKey]) : this.publicKey;
8147
+ const extendedKey = (0, import_utils34.arrayify)((0, import_utils34.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
7779
8148
  return base58check(extendedKey);
7780
8149
  }
7781
8150
  /**
@@ -7787,13 +8156,13 @@ var HDWallet = class {
7787
8156
  static fromSeed(seed) {
7788
8157
  const masterKey = mnemonic_default.masterKeysFromSeed(seed);
7789
8158
  return new HDWallet({
7790
- chainCode: (0, import_utils35.arrayify)(masterKey.slice(32)),
7791
- privateKey: (0, import_utils35.arrayify)(masterKey.slice(0, 32))
8159
+ chainCode: (0, import_utils34.arrayify)(masterKey.slice(32)),
8160
+ privateKey: (0, import_utils34.arrayify)(masterKey.slice(0, 32))
7792
8161
  });
7793
8162
  }
7794
8163
  static fromExtendedKey(extendedKey) {
7795
- const decoded = (0, import_ethers3.toBeHex)((0, import_ethers3.decodeBase58)(extendedKey));
7796
- const bytes = (0, import_utils35.arrayify)(decoded);
8164
+ const decoded = (0, import_ethers2.toBeHex)((0, import_ethers2.decodeBase58)(extendedKey));
8165
+ const bytes = (0, import_utils34.arrayify)(decoded);
7797
8166
  const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
7798
8167
  if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
7799
8168
  throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
@@ -7802,9 +8171,9 @@ var HDWallet = class {
7802
8171
  throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
7803
8172
  }
7804
8173
  const depth = bytes[4];
7805
- const parentFingerprint = (0, import_utils35.hexlify)(bytes.slice(5, 9));
7806
- const index = parseInt((0, import_utils35.hexlify)(bytes.slice(9, 13)).substring(2), 16);
7807
- const chainCode = (0, import_utils35.hexlify)(bytes.slice(13, 45));
8174
+ const parentFingerprint = (0, import_utils34.hexlify)(bytes.slice(5, 9));
8175
+ const index = parseInt((0, import_utils34.hexlify)(bytes.slice(9, 13)).substring(2), 16);
8176
+ const chainCode = (0, import_utils34.hexlify)(bytes.slice(13, 45));
7808
8177
  const key = bytes.slice(45, 78);
7809
8178
  if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
7810
8179
  throw new import_errors20.FuelError(
@@ -7997,14 +8366,15 @@ var seedTestWallet = async (wallet, quantities) => {
7997
8366
  process.env.GENESIS_SECRET || (0, import_crypto5.randomBytes)(32),
7998
8367
  wallet.provider
7999
8368
  );
8000
- const resources = await genesisWallet.getResourcesToSpend(quantities);
8001
- const { minGasPrice } = genesisWallet.provider.getGasConfig();
8002
- const request = new ScriptTransactionRequest({
8003
- gasLimit: 1e4,
8004
- gasPrice: minGasPrice
8369
+ const request = new ScriptTransactionRequest();
8370
+ quantities.forEach((quantity) => {
8371
+ const { amount, assetId } = coinQuantityfy(quantity);
8372
+ request.addCoinOutput(wallet.address, amount, assetId);
8005
8373
  });
8006
- request.addResources(resources);
8007
- quantities.map(coinQuantityfy).forEach(({ amount, assetId }) => request.addCoinOutput(wallet.address, amount, assetId));
8374
+ const txCost = await genesisWallet.provider.getTransactionCost(request);
8375
+ request.gasLimit = txCost.gasUsed;
8376
+ request.maxFee = txCost.maxFee;
8377
+ await genesisWallet.fund(request, txCost);
8008
8378
  await genesisWallet.sendTransaction(request, { awaitExecution: true });
8009
8379
  };
8010
8380
 
@@ -8018,12 +8388,12 @@ var generateTestWallet = async (provider, quantities) => {
8018
8388
  };
8019
8389
 
8020
8390
  // src/test-utils/launchNode.ts
8021
- var import_configs13 = require("@fuel-ts/address/configs");
8022
- var import_math21 = require("@fuel-ts/math");
8023
- var import_utils36 = require("@fuel-ts/utils");
8391
+ var import_abi_coder7 = require("@fuel-ts/abi-coder");
8392
+ var import_crypto6 = require("@fuel-ts/crypto");
8393
+ var import_utils35 = require("@fuel-ts/utils");
8024
8394
  var import_cli_utils = require("@fuel-ts/utils/cli-utils");
8025
8395
  var import_child_process = require("child_process");
8026
- var import_crypto6 = require("crypto");
8396
+ var import_crypto7 = require("crypto");
8027
8397
  var import_fs = require("fs");
8028
8398
  var import_os = __toESM(require("os"));
8029
8399
  var import_path = __toESM(require("path"));
@@ -8072,13 +8442,13 @@ var launchNode = async ({
8072
8442
  // eslint-disable-next-line no-async-promise-executor
8073
8443
  new Promise(async (resolve, reject) => {
8074
8444
  const remainingArgs = extractRemainingArgs(args, [
8075
- "--chain",
8445
+ "--snapshot",
8076
8446
  "--consensus-key",
8077
8447
  "--db-type",
8078
8448
  "--poa-instant"
8079
8449
  ]);
8080
- const chainConfigPath = getFlagValueFromArgs(args, "--chain");
8081
- const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || import_utils36.defaultConsensusKey;
8450
+ const snapshotDir = getFlagValueFromArgs(args, "--snapshot");
8451
+ const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || import_utils35.defaultConsensusKey;
8082
8452
  const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
8083
8453
  const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
8084
8454
  const poaInstantFlagValue = getFlagValueFromArgs(args, "--poa-instant");
@@ -8093,39 +8463,59 @@ var launchNode = async ({
8093
8463
  stopPort: 5e3
8094
8464
  // don't try ports above 5000
8095
8465
  })).toString();
8096
- let chainConfigPathToUse;
8466
+ let snapshotDirToUse;
8097
8467
  const prefix = basePath || import_os.default.tmpdir();
8098
- const suffix = basePath ? "" : (0, import_crypto6.randomUUID)();
8099
- const tempDirPath = import_path.default.join(prefix, ".fuels", suffix);
8100
- if (chainConfigPath) {
8101
- chainConfigPathToUse = chainConfigPath;
8468
+ const suffix = basePath ? "" : (0, import_crypto7.randomUUID)();
8469
+ const tempDirPath = import_path.default.join(prefix, ".fuels", suffix, "snapshotDir");
8470
+ if (snapshotDir) {
8471
+ snapshotDirToUse = snapshotDir;
8102
8472
  } else {
8103
8473
  if (!(0, import_fs.existsSync)(tempDirPath)) {
8104
8474
  (0, import_fs.mkdirSync)(tempDirPath, { recursive: true });
8105
8475
  }
8106
- const tempChainConfigFilePath = import_path.default.join(tempDirPath, "chainConfig.json");
8107
- let chainConfig = import_utils36.defaultChainConfig;
8476
+ let { stateConfigJson } = import_utils35.defaultSnapshotConfigs;
8477
+ const { chainConfigJson, metadataJson } = import_utils35.defaultSnapshotConfigs;
8478
+ stateConfigJson = {
8479
+ ...stateConfigJson,
8480
+ coins: [
8481
+ ...stateConfigJson.coins.map((coin) => ({
8482
+ ...coin,
8483
+ amount: "18446744073709551615"
8484
+ }))
8485
+ ],
8486
+ messages: stateConfigJson.messages.map((message) => ({
8487
+ ...message,
8488
+ amount: "18446744073709551615"
8489
+ }))
8490
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
8491
+ };
8108
8492
  if (!process.env.GENESIS_SECRET) {
8109
8493
  const pk = Signer.generatePrivateKey();
8110
8494
  const signer = new Signer(pk);
8111
- process.env.GENESIS_SECRET = (0, import_utils36.hexlify)(pk);
8112
- chainConfig = {
8113
- ...import_utils36.defaultChainConfig,
8114
- initial_state: {
8115
- ...import_utils36.defaultChainConfig.initial_state,
8116
- coins: [
8117
- ...import_utils36.defaultChainConfig.initial_state.coins,
8118
- {
8119
- owner: signer.address.toHexString(),
8120
- amount: (0, import_math21.toHex)(1e9),
8121
- asset_id: import_configs13.BaseAssetId
8122
- }
8123
- ]
8124
- }
8125
- };
8495
+ process.env.GENESIS_SECRET = (0, import_utils35.hexlify)(pk);
8496
+ stateConfigJson.coins.push({
8497
+ tx_id: (0, import_utils35.hexlify)((0, import_crypto6.randomBytes)(import_abi_coder7.UTXO_ID_LEN)),
8498
+ owner: signer.address.toHexString(),
8499
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
8500
+ amount: "18446744073709551615",
8501
+ asset_id: chainConfigJson.consensus_parameters.V1.base_asset_id,
8502
+ output_index: 0,
8503
+ tx_pointer_block_height: 0,
8504
+ tx_pointer_tx_idx: 0
8505
+ });
8126
8506
  }
8127
- (0, import_fs.writeFileSync)(tempChainConfigFilePath, JSON.stringify(chainConfig), "utf8");
8128
- chainConfigPathToUse = tempChainConfigFilePath;
8507
+ let fixedStateConfigJSON = JSON.stringify(stateConfigJson);
8508
+ const regexMakeNumber = /("amount":)"(\d+)"/gm;
8509
+ fixedStateConfigJSON = fixedStateConfigJSON.replace(regexMakeNumber, "$1$2");
8510
+ const chainConfigWritePath = import_path.default.join(tempDirPath, "chainConfig.json");
8511
+ const stateConfigWritePath = import_path.default.join(tempDirPath, "stateConfig.json");
8512
+ const metadataWritePath = import_path.default.join(tempDirPath, "metadata.json");
8513
+ const stateTransitionWritePath = import_path.default.join(tempDirPath, "state_transition_bytecode.wasm");
8514
+ (0, import_fs.writeFileSync)(chainConfigWritePath, JSON.stringify(chainConfigJson), "utf8");
8515
+ (0, import_fs.writeFileSync)(stateConfigWritePath, fixedStateConfigJSON, "utf8");
8516
+ (0, import_fs.writeFileSync)(metadataWritePath, JSON.stringify(metadataJson), "utf8");
8517
+ (0, import_fs.writeFileSync)(stateTransitionWritePath, JSON.stringify(""));
8518
+ snapshotDirToUse = tempDirPath;
8129
8519
  }
8130
8520
  const child = (0, import_child_process.spawn)(
8131
8521
  command,
@@ -8134,10 +8524,10 @@ var launchNode = async ({
8134
8524
  ["--ip", ipToUse],
8135
8525
  ["--port", portToUse],
8136
8526
  useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDirPath],
8137
- ["--min-gas-price", "0"],
8527
+ ["--min-gas-price", "1"],
8138
8528
  poaInstant ? ["--poa-instant", "true"] : [],
8139
8529
  ["--consensus-key", consensusKey],
8140
- ["--chain", chainConfigPathToUse],
8530
+ ["--snapshot", snapshotDirToUse],
8141
8531
  "--vm-backtrace",
8142
8532
  "--utxo-validation",
8143
8533
  "--debug",
@@ -8167,7 +8557,7 @@ var launchNode = async ({
8167
8557
  cleanup: () => killNode(cleanupConfig),
8168
8558
  ip: ipToUse,
8169
8559
  port: portToUse,
8170
- chainConfigPath: chainConfigPathToUse
8560
+ snapshotDir: snapshotDirToUse
8171
8561
  });
8172
8562
  }
8173
8563
  if (/error/i.test(chunk)) {
@@ -8184,9 +8574,10 @@ var launchNode = async ({
8184
8574
  })
8185
8575
  );
8186
8576
  var generateWallets = async (count, provider) => {
8577
+ const baseAssetId = provider.getBaseAssetId();
8187
8578
  const wallets = [];
8188
8579
  for (let i = 0; i < count; i += 1) {
8189
- const wallet = await generateTestWallet(provider, [[1e3, import_configs13.BaseAssetId]]);
8580
+ const wallet = await generateTestWallet(provider, [[1e5, baseAssetId]]);
8190
8581
  wallets.push(wallet);
8191
8582
  }
8192
8583
  return wallets;
@@ -8196,7 +8587,7 @@ var launchNodeAndGetWallets = async ({
8196
8587
  walletCount = 10
8197
8588
  } = {}) => {
8198
8589
  const { cleanup: closeNode, ip, port } = await launchNode(launchNodeOptions || {});
8199
- const provider = await Provider.create(`http://${ip}:${port}/graphql`);
8590
+ const provider = await Provider.create(`http://${ip}:${port}/v1/graphql`);
8200
8591
  const wallets = await generateWallets(walletCount, provider);
8201
8592
  const cleanup = () => {
8202
8593
  closeNode();